@geospatial-sdk/openlayers 0.0.5-dev.42 → 0.0.5-dev.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/map/create-map.js +1 -1
- package/lib/map/apply-context-diff.test.ts +5 -5
- package/lib/map/create-map.test.ts +48 -33
- package/lib/map/create-map.ts +1 -1
- package/lib/map/handle-errors.test.ts +6 -6
- package/lib/map/register-events.test.ts +10 -10
- package/lib/map/styles.test.ts +9 -9
- package/package.json +3 -3
package/dist/map/create-map.js
CHANGED
|
@@ -85,7 +85,7 @@ export async function createLayer(layerModel) {
|
|
|
85
85
|
const dimensions = endpoint.getDefaultDimensions(layer.name);
|
|
86
86
|
olLayer.setSource(new WMTS({
|
|
87
87
|
layer: layer.name,
|
|
88
|
-
style: layer.defaultStyle,
|
|
88
|
+
style: layer.defaultStyle || layer.styles[0].name,
|
|
89
89
|
matrixSet: matrixSet.identifier,
|
|
90
90
|
format: resourceUrl.format,
|
|
91
91
|
url: resourceUrl.url,
|
|
@@ -10,12 +10,12 @@ import {
|
|
|
10
10
|
SAMPLE_LAYER3,
|
|
11
11
|
SAMPLE_LAYER4,
|
|
12
12
|
SAMPLE_LAYER5,
|
|
13
|
-
} from "@geospatial-sdk/core/fixtures/map-context.fixtures";
|
|
14
|
-
import Map from "ol/Map";
|
|
15
|
-
import { createLayer, createMapFromContext } from "./create-map";
|
|
16
|
-
import { applyContextDiffToMap } from "./apply-context-diff";
|
|
13
|
+
} from "@geospatial-sdk/core/fixtures/map-context.fixtures.js";
|
|
14
|
+
import Map from "ol/Map.js";
|
|
15
|
+
import { createLayer, createMapFromContext } from "./create-map.js";
|
|
16
|
+
import { applyContextDiffToMap } from "./apply-context-diff.js";
|
|
17
17
|
import { beforeEach } from "vitest";
|
|
18
|
-
import BaseLayer from "ol/layer/Base";
|
|
18
|
+
import BaseLayer from "ol/layer/Base.js";
|
|
19
19
|
|
|
20
20
|
async function assertEqualsToModel(layer: any, layerModel: MapContextLayer) {
|
|
21
21
|
const reference = (await createLayer(layerModel)) as any;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { FeatureCollection } from "geojson";
|
|
2
|
-
import TileLayer from "ol/layer/Tile";
|
|
3
|
-
import VectorLayer from "ol/layer/Vector";
|
|
4
|
-
import Map from "ol/Map";
|
|
5
|
-
import TileWMS from "ol/source/TileWMS";
|
|
6
|
-
import VectorSource from "ol/source/Vector";
|
|
7
|
-
import XYZ from "ol/source/XYZ";
|
|
8
|
-
import View from "ol/View";
|
|
9
|
-
import GeoJSON from "ol/format/GeoJSON";
|
|
2
|
+
import TileLayer from "ol/layer/Tile.js";
|
|
3
|
+
import VectorLayer from "ol/layer/Vector.js";
|
|
4
|
+
import Map from "ol/Map.js";
|
|
5
|
+
import TileWMS from "ol/source/TileWMS.js";
|
|
6
|
+
import VectorSource from "ol/source/Vector.js";
|
|
7
|
+
import XYZ from "ol/source/XYZ.js";
|
|
8
|
+
import View from "ol/View.js";
|
|
9
|
+
import GeoJSON from "ol/format/GeoJSON.js";
|
|
10
10
|
import {
|
|
11
11
|
MAP_CTX_EXTENT_FIXTURE,
|
|
12
12
|
MAP_CTX_FIXTURE,
|
|
@@ -19,34 +19,35 @@ import {
|
|
|
19
19
|
MAP_CTX_LAYER_WMS_FIXTURE,
|
|
20
20
|
MAP_CTX_LAYER_WMTS_FIXTURE,
|
|
21
21
|
MAP_CTX_LAYER_XYZ_FIXTURE,
|
|
22
|
-
} from "@geospatial-sdk/core/fixtures/map-context.fixtures";
|
|
22
|
+
} from "@geospatial-sdk/core/fixtures/map-context.fixtures.js";
|
|
23
23
|
import {
|
|
24
24
|
MapContext,
|
|
25
25
|
MapContextLayer,
|
|
26
26
|
MapContextLayerGeojson,
|
|
27
27
|
MapContextLayerWms,
|
|
28
|
-
SourceLoadErrorEvent,
|
|
29
28
|
} from "@geospatial-sdk/core";
|
|
30
|
-
import Layer from "ol/layer/Layer";
|
|
29
|
+
import Layer from "ol/layer/Layer.js";
|
|
31
30
|
import {
|
|
32
31
|
createLayer,
|
|
33
32
|
createMapFromContext,
|
|
34
33
|
createView,
|
|
35
34
|
resetMapFromContext,
|
|
36
|
-
} from "./create-map";
|
|
37
|
-
import WMTS from "ol/source/WMTS";
|
|
38
|
-
import { VectorTile } from "ol/source";
|
|
35
|
+
} from "./create-map.js";
|
|
36
|
+
import WMTS from "ol/source/WMTS.js";
|
|
37
|
+
import { VectorTile } from "ol/source.js";
|
|
39
38
|
import { MapboxVectorLayer } from "ol-mapbox-style";
|
|
40
39
|
import {
|
|
41
40
|
handleEndpointError,
|
|
42
41
|
tileLoadErrorCatchFunction,
|
|
43
|
-
} from "./handle-errors";
|
|
44
|
-
import
|
|
42
|
+
} from "./handle-errors.js";
|
|
43
|
+
import ImageTile from "ol/ImageTile.js";
|
|
45
44
|
import TileState from "ol/TileState.js";
|
|
46
|
-
import VectorTileLayer from "ol/layer/VectorTile";
|
|
45
|
+
import VectorTileLayer from "ol/layer/VectorTile.js";
|
|
46
|
+
import { FeatureUrlFunction } from "ol/featureloader.js";
|
|
47
47
|
|
|
48
48
|
vi.mock("./handle-errors", async (importOriginal) => {
|
|
49
|
-
const actual =
|
|
49
|
+
const actual =
|
|
50
|
+
(await importOriginal()) as typeof import("./handle-errors.js");
|
|
50
51
|
return {
|
|
51
52
|
...actual,
|
|
52
53
|
tileLoadErrorCatchFunction: vi.fn(),
|
|
@@ -54,6 +55,10 @@ vi.mock("./handle-errors", async (importOriginal) => {
|
|
|
54
55
|
};
|
|
55
56
|
});
|
|
56
57
|
|
|
58
|
+
afterEach(() => {
|
|
59
|
+
vi.clearAllMocks();
|
|
60
|
+
});
|
|
61
|
+
|
|
57
62
|
describe("MapContextService", () => {
|
|
58
63
|
describe("#createLayer", () => {
|
|
59
64
|
let layerModel: MapContextLayer, layer: Layer;
|
|
@@ -140,7 +145,7 @@ describe("MapContextService", () => {
|
|
|
140
145
|
expect(layer.getVisible()).toBe(false);
|
|
141
146
|
expect(layer.getOpacity()).toBe(0.5);
|
|
142
147
|
expect(layer.get("label")).toBe("Communes");
|
|
143
|
-
// @ts-
|
|
148
|
+
// @ts-expect-error TS2554 we're not providing a view extent here
|
|
144
149
|
expect(layer.getSource()?.getAttributions()!()).toEqual(["camptocamp"]);
|
|
145
150
|
});
|
|
146
151
|
it("create a TileWMS source", () => {
|
|
@@ -200,7 +205,7 @@ describe("MapContextService", () => {
|
|
|
200
205
|
|
|
201
206
|
const attributions = layer.getSource()?.getAttributions();
|
|
202
207
|
expect(attributions).not.toBeNull();
|
|
203
|
-
// @ts-
|
|
208
|
+
// @ts-expect-error TS2554 we're not providing a view extent here
|
|
204
209
|
expect(attributions!()).toEqual(["camptocamp"]);
|
|
205
210
|
});
|
|
206
211
|
it("create a Vector source", () => {
|
|
@@ -209,7 +214,8 @@ describe("MapContextService", () => {
|
|
|
209
214
|
});
|
|
210
215
|
it("set correct url load function", () => {
|
|
211
216
|
const source = layer.getSource() as VectorSource;
|
|
212
|
-
const urlLoader = source.getUrl() as
|
|
217
|
+
const urlLoader = source.getUrl() as FeatureUrlFunction;
|
|
218
|
+
// @ts-expect-error TS2345
|
|
213
219
|
expect(urlLoader([10, 20, 30, 40])).toBe(
|
|
214
220
|
"https://www.datagrandest.fr/geoserver/region-grand-est/ows?service=WFS&version=1.1.0&request=GetFeature&outputFormat=application%2Fjson&typename=ms%3Acommune_actuelle_3857&srsname=EPSG%3A3857&bbox=10%2C20%2C30%2C40%2CEPSG%3A3857&maxFeatures=10000",
|
|
215
221
|
);
|
|
@@ -330,11 +336,8 @@ describe("MapContextService", () => {
|
|
|
330
336
|
|
|
331
337
|
describe("WMTS", () => {
|
|
332
338
|
beforeEach(async () => {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
});
|
|
336
|
-
afterEach(() => {
|
|
337
|
-
vi.clearAllMocks();
|
|
339
|
+
layerModel = MAP_CTX_LAYER_WMTS_FIXTURE;
|
|
340
|
+
layer = await createLayer(layerModel);
|
|
338
341
|
});
|
|
339
342
|
it("create a tile layer", () => {
|
|
340
343
|
expect(layer).toBeTruthy();
|
|
@@ -344,7 +347,9 @@ describe("MapContextService", () => {
|
|
|
344
347
|
expect(layer.getVisible()).toBe(true);
|
|
345
348
|
expect(layer.getOpacity()).toBe(1);
|
|
346
349
|
expect(layer.get("label")).toBeUndefined();
|
|
347
|
-
|
|
350
|
+
const source = layer.getSource() as WMTS;
|
|
351
|
+
expect(source.getAttributions()).toBeNull();
|
|
352
|
+
expect(source.getStyle()).toBe("default");
|
|
348
353
|
});
|
|
349
354
|
it("create a WMTS source", () => {
|
|
350
355
|
const source = layer.getSource();
|
|
@@ -372,15 +377,25 @@ describe("MapContextService", () => {
|
|
|
372
377
|
it("should call handleEndpointError", () => {
|
|
373
378
|
expect(handleEndpointError).toHaveBeenCalled();
|
|
374
379
|
});
|
|
375
|
-
|
|
376
|
-
|
|
380
|
+
});
|
|
381
|
+
describe("WMTS without default style given", () => {
|
|
382
|
+
beforeEach(async () => {
|
|
383
|
+
layerModel = {
|
|
384
|
+
...MAP_CTX_LAYER_WMTS_FIXTURE,
|
|
385
|
+
url: "https://wmts/no-default-style",
|
|
386
|
+
};
|
|
387
|
+
layer = await createLayer(layerModel);
|
|
388
|
+
});
|
|
389
|
+
it("uses the first style as default", async () => {
|
|
390
|
+
const source = layer.getSource() as WMTS;
|
|
391
|
+
expect(source.getStyle()).toEqual("first");
|
|
377
392
|
});
|
|
378
393
|
});
|
|
379
394
|
|
|
380
395
|
describe("Maplibre Style", () => {
|
|
381
396
|
beforeEach(async () => {
|
|
382
|
-
|
|
383
|
-
|
|
397
|
+
layerModel = MAP_CTX_LAYER_MAPBLIBRE_STYLE_FIXTURE;
|
|
398
|
+
layer = await createLayer(layerModel);
|
|
384
399
|
});
|
|
385
400
|
it("create a tile layer", () => {
|
|
386
401
|
expect(layer).toBeTruthy();
|
|
@@ -399,8 +414,8 @@ describe("MapContextService", () => {
|
|
|
399
414
|
|
|
400
415
|
describe("MVT", () => {
|
|
401
416
|
beforeEach(async () => {
|
|
402
|
-
|
|
403
|
-
|
|
417
|
+
layerModel = MAP_CTX_LAYER_MVT_FIXTURE;
|
|
418
|
+
layer = await createLayer(layerModel);
|
|
404
419
|
});
|
|
405
420
|
it("create a VectorTileLayer", () => {
|
|
406
421
|
expect(layer).toBeTruthy();
|
package/lib/map/create-map.ts
CHANGED
|
@@ -113,7 +113,7 @@ export async function createLayer(layerModel: MapContextLayer): Promise<Layer> {
|
|
|
113
113
|
olLayer.setSource(
|
|
114
114
|
new WMTS({
|
|
115
115
|
layer: layer.name,
|
|
116
|
-
style: layer.defaultStyle,
|
|
116
|
+
style: layer.defaultStyle || layer.styles[0].name,
|
|
117
117
|
matrixSet: matrixSet.identifier,
|
|
118
118
|
format: resourceUrl.format,
|
|
119
119
|
url: resourceUrl.url,
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { ImageTile, Tile } from "ol";
|
|
2
2
|
import TileState from "ol/TileState.js";
|
|
3
3
|
import { SourceLoadErrorEvent } from "@geospatial-sdk/core";
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
handleTileError,
|
|
6
|
+
tileLoadErrorCatchFunction,
|
|
7
|
+
} from "./handle-errors.js";
|
|
6
8
|
import { describe } from "node:test";
|
|
7
|
-
import TileLayer from "ol/layer/Tile";
|
|
8
|
-
import VectorLayer from "ol/layer/Vector";
|
|
9
|
+
import TileLayer from "ol/layer/Tile.js";
|
|
10
|
+
import VectorLayer from "ol/layer/Vector.js";
|
|
9
11
|
import { EndpointError } from "@camptocamp/ogc-client";
|
|
10
12
|
|
|
11
13
|
global.URL.createObjectURL = vi.fn(() => "blob:http://example.com/blob");
|
|
@@ -25,11 +27,9 @@ global.fetch = vi.fn().mockImplementation((url: string) => {
|
|
|
25
27
|
});
|
|
26
28
|
|
|
27
29
|
describe("handle-errors", () => {
|
|
28
|
-
let map: Map;
|
|
29
30
|
let tile: Tile;
|
|
30
31
|
|
|
31
32
|
beforeEach(() => {
|
|
32
|
-
map = new Map();
|
|
33
33
|
tile = new ImageTile(
|
|
34
34
|
[0, 0, 0],
|
|
35
35
|
TileState.IDLE,
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import Map from "ol/Map";
|
|
1
|
+
import Map from "ol/Map.js";
|
|
2
2
|
import { Mock } from "vitest";
|
|
3
3
|
import {
|
|
4
4
|
getFeaturesFromVectorSources,
|
|
5
5
|
getFeaturesFromWmsSources,
|
|
6
6
|
getGFIUrl,
|
|
7
7
|
listen,
|
|
8
|
-
} from "./register-events";
|
|
8
|
+
} from "./register-events.js";
|
|
9
9
|
import { Collection, MapBrowserEvent, Object as BaseObject } from "ol";
|
|
10
|
-
import View from "ol/View";
|
|
11
|
-
import { toLonLat } from "ol/proj";
|
|
12
|
-
import TileWMS from "ol/source/TileWMS";
|
|
13
|
-
import VectorSource from "ol/source/Vector";
|
|
14
|
-
import VectorLayer from "ol/layer/Vector";
|
|
15
|
-
import Point from "ol/geom/Point";
|
|
16
|
-
import TileLayer from "ol/layer/Tile";
|
|
17
|
-
import OlFeature from "ol/Feature";
|
|
10
|
+
import View from "ol/View.js";
|
|
11
|
+
import { toLonLat } from "ol/proj.js";
|
|
12
|
+
import TileWMS from "ol/source/TileWMS.js";
|
|
13
|
+
import VectorSource from "ol/source/Vector.js";
|
|
14
|
+
import VectorLayer from "ol/layer/Vector.js";
|
|
15
|
+
import Point from "ol/geom/Point.js";
|
|
16
|
+
import TileLayer from "ol/layer/Tile.js";
|
|
17
|
+
import OlFeature from "ol/Feature.js";
|
|
18
18
|
|
|
19
19
|
const EXPECTED_MAP_EXTENT_EPSG4326 = [
|
|
20
20
|
-0.0035932611364780857, -0.0026949458513598756, 0.0035932611364780857,
|
package/lib/map/styles.test.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import chroma from "chroma-js";
|
|
2
|
-
import Style from "ol/style/Style";
|
|
3
|
-
import Feature from "ol/Feature";
|
|
4
|
-
import { LineString, Point, Polygon } from "ol/geom";
|
|
2
|
+
import Style, { StyleFunction } from "ol/style/Style.js";
|
|
3
|
+
import Feature from "ol/Feature.js";
|
|
4
|
+
import { LineString, Point, Polygon } from "ol/geom.js";
|
|
5
5
|
import {
|
|
6
6
|
createGeometryStyles,
|
|
7
7
|
createStyleFunction,
|
|
8
8
|
defaultHighlightStyle,
|
|
9
9
|
defaultStyle,
|
|
10
10
|
StyleByGeometryType,
|
|
11
|
-
} from "./styles";
|
|
12
|
-
import CircleStyle from "ol/style/Circle";
|
|
11
|
+
} from "./styles.js";
|
|
12
|
+
import CircleStyle from "ol/style/Circle.js";
|
|
13
13
|
|
|
14
14
|
describe("MapStyleService", () => {
|
|
15
15
|
describe("#createGeometryStyles", () => {
|
|
@@ -139,7 +139,7 @@ describe("MapStyleService", () => {
|
|
|
139
139
|
});
|
|
140
140
|
|
|
141
141
|
describe("#createStyleFunction", () => {
|
|
142
|
-
let styleFn:
|
|
142
|
+
let styleFn: StyleFunction;
|
|
143
143
|
let feature: Feature;
|
|
144
144
|
it("returns a function", () => {
|
|
145
145
|
styleFn = createStyleFunction(
|
|
@@ -154,7 +154,7 @@ describe("MapStyleService", () => {
|
|
|
154
154
|
feature.setGeometry(new LineString([]));
|
|
155
155
|
});
|
|
156
156
|
it("resolves to a double style with stroke", () => {
|
|
157
|
-
const style = styleFn(feature, 1);
|
|
157
|
+
const style = styleFn(feature, 1) as Style[];
|
|
158
158
|
expect(style).toEqual([expect.any(Style), expect.any(Style)]);
|
|
159
159
|
expect(style[0].getStroke()).toBeTruthy();
|
|
160
160
|
expect(style[0].getFill()).toBeFalsy();
|
|
@@ -166,7 +166,7 @@ describe("MapStyleService", () => {
|
|
|
166
166
|
feature.setGeometry(new Point([]));
|
|
167
167
|
});
|
|
168
168
|
it("resolves to a style with image", () => {
|
|
169
|
-
const style = styleFn(feature, 1);
|
|
169
|
+
const style = styleFn(feature, 1) as Style;
|
|
170
170
|
expect(style.getImage()).toBeTruthy();
|
|
171
171
|
expect(style.getFill()).toBeFalsy();
|
|
172
172
|
expect(style.getStroke()).toBeFalsy();
|
|
@@ -177,7 +177,7 @@ describe("MapStyleService", () => {
|
|
|
177
177
|
feature.setGeometry(new Polygon([]));
|
|
178
178
|
});
|
|
179
179
|
it("resolves to a style with fill and stroke", () => {
|
|
180
|
-
const style = styleFn(feature, 1);
|
|
180
|
+
const style = styleFn(feature, 1) as Style;
|
|
181
181
|
expect(style.getFill()).toBeTruthy();
|
|
182
182
|
expect(style.getStroke()).toBeTruthy();
|
|
183
183
|
expect(style.getImage()).toBeFalsy();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geospatial-sdk/openlayers",
|
|
3
|
-
"version": "0.0.5-dev.
|
|
3
|
+
"version": "0.0.5-dev.44+44c94a2",
|
|
4
4
|
"description": "OpenLayers-related utilities",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ol",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"ol": ">6.x"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@geospatial-sdk/core": "^0.0.5-dev.
|
|
40
|
+
"@geospatial-sdk/core": "^0.0.5-dev.44+44c94a2",
|
|
41
41
|
"chroma-js": "^2.4.2",
|
|
42
42
|
"lodash.throttle": "^4.1.1",
|
|
43
43
|
"ol-mapbox-style": "12.4.0"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "44c94a2e3458beb7e3f3ffc98ed170c21a0fc460"
|
|
46
46
|
}
|