Skip to content

Commit 4e6694e

Browse files
authored
Merge pull request #728 from terrestris/fix-cleanup-layer-interaction
Ensure single extent layer and transform interaction
2 parents d6faf7f + 696c57b commit 4e6694e

20 files changed

+113
-100
lines changed

Diff for: .github/workflows/on-pull-request.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
run: npm ci
3434

3535
- name: Run typecheck, lint and tests 🧪
36-
run: npm test
36+
run: npm run check
3737

3838
- name: Build artifacts 🏗️
3939
run: npm run build:docs && npm run build:examples && npm run build:dist

Diff for: .husky/pre-push

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
npm run lint
1+
npm run check

Diff for: eslint.config.mjs

-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ export default tsEslint.config({
1717
'src/**/*.ts',
1818
'spec/**/*.spec.ts'
1919
],
20-
ignores: [
21-
'**/*.spec.ts',
22-
'**/dist/*.js',
23-
'**/jest/__mocks__/*.ts'
24-
],
2520
languageOptions: {
2621
ecmaVersion: 2022,
2722
globals: globals.browser,

Diff for: package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@
2222
],
2323
"scripts": {
2424
"build": "npm run clean && npm run build:dist",
25-
"build:dist": "npm run clean:dist && tsc -p .",
25+
"build:dist": "npm run clean:dist && tsc -p ./tsconfig.build.json",
2626
"build:docs": "npm run clean:docs && typedoc",
2727
"build:examples": "npm run clean:examples && webpack --config webpack.prod.cjs",
2828
"clean": "npm run clean:dist && npm run clean:examples && npm run clean:docs",
29+
"check": "npm run typecheck && npm run lint && npm run test",
2930
"clean:dist": "rimraf ./dist/*",
3031
"clean:docs": "rimraf ./build/docs/*",
3132
"clean:examples": "rimraf ./build/examples/*",
32-
"lint": "eslint -c eslint.config.mjs",
33+
"lint": "eslint -c eslint.config.mjs src/ spec/",
3334
"lint:fix": "npm run lint -- --fix",
3435
"postpublish": "node ./tasks/update-gh-pages.cjs",
3536
"prepare": "husky",
3637
"prepublishOnly": "npm run build:dist && npm run build:docs",
37-
"pretest": "npm run clean:dist && npm run typecheck && npm run lint",
3838
"start": "webpack-dev-server --config webpack.dev.cjs",
39-
"test": "jest --maxWorkers=4 --coverage --config jest.config.cjs",
39+
"test": "jest --maxWorkers=50% --coverage --config jest.config.cjs",
4040
"test:watch": "jest --watchAll --config jest.config.cjs",
4141
"typecheck": "tsc --pretty --noEmit"
4242
},

Diff for: spec/manager/MapFishPrintV2Manager.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import {
44
FetchMock
55
} from 'jest-fetch-mock';
66

7-
import OlMap from 'ol/Map';
87
import OlLayerImage from 'ol/layer/Image';
9-
import OlSourceImageWMS from 'ol/source/ImageWMS';
10-
import OlView from 'ol/View';
118
import OlLayerVector from 'ol/layer/Vector';
9+
import OlMap from 'ol/Map';
10+
import OlSourceImageWMS from 'ol/source/ImageWMS';
1211
import OlSourceVector from 'ol/source/Vector';
13-
14-
import { MapFishPrintV2Manager } from '../../src/index';
12+
import OlView from 'ol/View';
1513

1614
import mockResponse from '../../assets/v2/info.json';
1715

16+
import { MapFishPrintV2Manager } from '../../src/index';
17+
1818
describe('MapFishPrintV2Manager', () => {
1919

2020
const testMap = new OlMap({

Diff for: spec/manager/MapFishPrintV3Manager.spec.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import {
44
FetchMock
55
} from 'jest-fetch-mock';
66

7-
import OlMap from 'ol/Map';
8-
import OlView from 'ol/View';
97
import OlLayerVector from 'ol/layer/Vector';
8+
import OlMap from 'ol/Map';
109
import OlSourceVector from 'ol/source/Vector';
11-
12-
import { MapFishPrintV3Manager, V3CustomMapParams } from '../../src/manager/MapFishPrintV3Manager';
10+
import OlView from 'ol/View';
1311

1412
import printAppsMockResponse from '../../assets/v3/apps.json';
1513
import printCapabilitiesMockResponse from '../../assets/v3/capabilities.json';
14+
import { MapFishPrintV3Manager, V3CustomMapParams } from '../../src/manager/MapFishPrintV3Manager';
1615

1716
describe('MapFishPrintV3Manager', () => {
1817

@@ -80,6 +79,7 @@ describe('MapFishPrintV3Manager', () => {
8079
url: 'https://mock:8080/print/pdf/'
8180
});
8281

82+
// @ts-expect-error protected method
8383
const response = await manager.loadPrintApps();
8484

8585
expect(response).toEqual(printAppsMockResponse);
@@ -96,6 +96,7 @@ describe('MapFishPrintV3Manager', () => {
9696

9797
const printApp = 'default';
9898

99+
// @ts-expect-error protected method
99100
const response = await manager.loadAppCapabilities(printApp);
100101

101102
expect(response.app).toBe(printCapabilitiesMockResponse.app);
@@ -107,6 +108,7 @@ describe('MapFishPrintV3Manager', () => {
107108
map: testMap,
108109
url: 'https://mock:8080/print/pdf/'
109110
});
111+
// @ts-expect-error protected method
110112
expect(manager.getBasePath).not.toBeUndefined();
111113
});
112114
});

Diff for: spec/serializer/MapFishPrintV2VectorSerializer.spec.ts

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import OlLayerVector from 'ol/layer/Vector';
1+
import OlFeature from 'ol/Feature';
2+
import { Geometry } from 'ol/geom';
3+
import OlGeomLineString from 'ol/geom/LineString';
4+
import OlGeomPoint from 'ol/geom/Point';
5+
import OlGeomPolygon from 'ol/geom/Polygon';
26
import OlLayerTile from 'ol/layer/Tile';
3-
import OlSourceVector from 'ol/source/Vector';
7+
import OlLayerVector from 'ol/layer/Vector';
48
import OlSourceOSM from 'ol/source/OSM';
5-
import OlStyleStyle from 'ol/style/Style';
9+
import OlSourceVector from 'ol/source/Vector';
610
import OlStyleCircle from 'ol/style/Circle';
7-
import OlStyleText from 'ol/style/Text';
8-
import OlStyleStroke from 'ol/style/Stroke';
911
import OlStyleFill from 'ol/style/Fill';
10-
import OlFeature from 'ol/Feature';
11-
import OlGeomPoint from 'ol/geom/Point';
12-
import OlGeomLineString from 'ol/geom/LineString';
13-
import OlGeomPolygon from 'ol/geom/Polygon';
12+
import OlStyleStroke from 'ol/style/Stroke';
13+
import OlStyleStyle from 'ol/style/Style';
14+
import OlStyleText from 'ol/style/Text';
1415

1516
import { MapFishPrintV2VectorSerializer } from '../../src/serializer/MapFishPrintV2VectorSerializer';
16-
import { Geometry } from 'ol/geom';
17-
import Feature from 'ol/Feature';
1817

1918
describe('MapFishPrintV2VectorSerializer', () => {
2019
let serializer: MapFishPrintV2VectorSerializer;
@@ -197,7 +196,7 @@ describe('MapFishPrintV2VectorSerializer', () => {
197196
]])
198197
});
199198

200-
const features: Feature<Geometry>[] = [
199+
const features: OlFeature<Geometry>[] = [
201200
pointFeature1,
202201
pointFeature2,
203202
lineFeature,

Diff for: spec/serializer/MapFishPrintV2WMSSerializer.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import OlLayerImage from 'ol/layer/Image';
22
import OlLayerTile from 'ol/layer/Tile';
33
import OlSourceImageWMS from 'ol/source/ImageWMS';
4-
import OlSourceTileWMS from 'ol/source/TileWMS';
54
import OlSourceOSM from 'ol/source/OSM';
5+
import OlSourceTileWMS from 'ol/source/TileWMS';
66

77
import { MapFishPrintV2WMSSerializer } from '../../src/serializer/MapFishPrintV2WMSSerializer';
88

Diff for: spec/serializer/MapFishPrintV3GeoJsonSerializer.spec.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
import OlFeature from 'ol/Feature';
2+
import { Geometry } from 'ol/geom';
3+
import OlGeomLineString from 'ol/geom/LineString';
4+
import OlGeomPoint from 'ol/geom/Point';
5+
import OlGeomPolygon from 'ol/geom/Polygon';
16
import OlLayerImage from 'ol/layer/Image';
27
import OlLayerVector from 'ol/layer/Vector';
38
import OlSourceImageWMS from 'ol/source/ImageWMS';
49
import OlSourceVector from 'ol/source/Vector';
5-
import OlFeature from 'ol/Feature';
6-
import OlGeomPoint from 'ol/geom/Point';
7-
import OlGeomLineString from 'ol/geom/LineString';
8-
import OlGeomPolygon from 'ol/geom/Polygon';
910

1011
import { MapFishPrintV3GeoJsonSerializer } from '../../src/serializer/MapFishPrintV3GeoJsonSerializer';
11-
import { Geometry } from 'ol/geom';
1212

1313
describe('MapFishPrintV3GeoJsonSerializer', () => {
1414
let serializer: MapFishPrintV3GeoJsonSerializer;
@@ -147,8 +147,4 @@ describe('MapFishPrintV3GeoJsonSerializer', () => {
147147
renderAsSvg: false
148148
});
149149
});
150-
151-
it('accepts additional serializer opts', () => {
152-
153-
});
154150
});

Diff for: spec/serializer/MapFishPrintV3TiledWMSSerializer.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import OlLayerTile from 'ol/layer/Tile';
2-
import OlSourceTileWMS from 'ol/source/TileWMS';
32
import OlSourceOSM from 'ol/source/OSM';
3+
import OlSourceTileWMS from 'ol/source/TileWMS';
44

55
import { MapFishPrintV3TiledWMSSerializer } from '../../src/serializer/MapFishPrintV3TiledWMSSerializer';
66

Diff for: spec/serializer/MapFishPrintV3WMTSSerializer.spec.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import OlLayerTile from 'ol/layer/Tile';
22

3-
import { MapFishPrintV3WMTSSerializer } from '../../src/serializer/MapFishPrintV3WMTSSerializer';
43
import OlSourceWMTS from 'ol/source/WMTS';
54
import OlTileGridWMTS from 'ol/tilegrid/WMTS';
65

6+
import { MapFishPrintV3WMTSSerializer } from '../../src/serializer/MapFishPrintV3WMTSSerializer';
7+
78
describe('MapFishPrintV3WMTSSerializer', () => {
89
let serializer: MapFishPrintV3WMTSSerializer;
910

@@ -19,9 +20,13 @@ describe('MapFishPrintV3WMTSSerializer', () => {
1920
const layer = new OlLayerTile({
2021
source: new OlSourceWMTS({
2122
layer: ' test',
22-
matrixSet: undefined,
23+
matrixSet: 'example',
2324
style: 'default',
24-
tileGrid: undefined,
25+
tileGrid: new OlTileGridWMTS({
26+
matrixIds: ['0'],
27+
resolutions: [1000],
28+
origin: [19, 0.9]
29+
})
2530
})
2631
});
2732

Diff for: spec/util/Shared.spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import OlMap from 'ol/Map';
2-
import OlView from 'ol/View';
1+
import OlCollection from 'ol/Collection';
32
import OlInteractionDragRotateAndZoom from 'ol/interaction/DragRotateAndZoom';
4-
import OlLayerVector from 'ol/layer/Vector';
3+
import OlLayerGroup from 'ol/layer/Group';
54
import OlLayerImage from 'ol/layer/Image';
65
import OlLayerTile from 'ol/layer/Tile';
6+
import OlLayerVector from 'ol/layer/Vector';
7+
import OlMap from 'ol/Map';
78
import OlSourceImageWMS from 'ol/source/ImageWMS';
89
import OlSourceTileWMS from 'ol/source/TileWMS';
910
import OlSourceVector from 'ol/source/Vector';
10-
import OlLayerGroup from 'ol/layer/Group';
11-
import OlCollection from 'ol/Collection';
11+
import OlView from 'ol/View';
1212

1313
import { Shared } from '../../src/util/Shared';
1414

@@ -104,7 +104,7 @@ describe('Shared', () => {
104104

105105
const layerArrayReturned = Shared.getMapLayers(map);
106106
expect(layerArrayReturned).toHaveLength(names.length + 1);
107-
for (var i = 0; i < names.length; i++) {
107+
for (let i = 0; i < names.length; i++) {
108108
expect(layerArrayReturned[i + 1].get('name')).toEqual(names[i]);
109109
}
110110
});

Diff for: src/interaction/InteractionTransform.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ export class OlInteractionTransform extends OlInteractionPointer {
356356
this.style[style] = [olstyle];
357357
}
358358

359-
for (let i = 0; i < this.style[style].length; i++) {
360-
const im = this.style[style][i].getImage();
359+
for (const st of this.style[style]) {
360+
const im = st.getImage();
361361
if (im) {
362362
if (style === 'rotate') {
363363
im.getAnchor()[0] = -5;
@@ -366,7 +366,7 @@ export class OlInteractionTransform extends OlInteractionPointer {
366366
im.setScale(1.8);
367367
}
368368
}
369-
const tx = this.style[style][i].getText();
369+
const tx = st.getText();
370370
if (tx) {
371371
if (style === 'rotate') {
372372
tx.setOffsetX(this.isTouch ? 14 : 7);
@@ -376,13 +376,15 @@ export class OlInteractionTransform extends OlInteractionPointer {
376376
}
377377
}
378378
}
379+
379380
this.drawSketch_(false);
380381
}
381382

382383
/**
383384
* Get Feature at pixel
384385
*/
385386
getFeatureAtPixel_(pixel: OlPixel) {
387+
// eslint-disable-next-line @typescript-eslint/no-this-alias
386388
const self = this;
387389
let found: {
388390
feature?: OlFeatureLike;
@@ -416,9 +418,8 @@ export class OlInteractionTransform extends OlInteractionPointer {
416418
// eslint-disable-next-line no-underscore-dangle
417419
if (self.layers_) {
418420
// eslint-disable-next-line no-underscore-dangle
419-
for (let i = 0; i < self.layers_.length; i++) {
420-
// eslint-disable-next-line no-underscore-dangle
421-
if (self.layers_[i] === layer) {
421+
for (const lyr of self.layers_) {
422+
if (lyr === layer) {
422423
found = { feature: feature };
423424
return true;
424425
}

0 commit comments

Comments
 (0)