@geospatial-sdk/openlayers 0.0.5-alpha.8 → 0.0.5-dev.0
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/package.json +3 -3
- package/dist/map/apply-context-diff.test.d.ts +0 -2
- package/dist/map/apply-context-diff.test.d.ts.map +0 -1
- package/dist/map/apply-context-diff.test.js +0 -251
- package/dist/map/create-map.test.d.ts +0 -2
- package/dist/map/create-map.test.d.ts.map +0 -1
- package/dist/map/create-map.test.js +0 -300
- package/dist/map/styles.test.d.ts +0 -2
- package/dist/map/styles.test.d.ts.map +0 -1
- package/dist/map/styles.test.js +0 -204
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geospatial-sdk/openlayers",
|
|
3
|
-
"version": "0.0.5-
|
|
3
|
+
"version": "0.0.5-dev.0+97d2685",
|
|
4
4
|
"description": "OpenLayers-related utilities",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ol",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"ol": ">6.x"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@geospatial-sdk/core": "^0.0.5-
|
|
38
|
+
"@geospatial-sdk/core": "^0.0.5-dev.0+97d2685",
|
|
39
39
|
"chroma-js": "^2.4.2"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "97d2685498a9b6208d833a15480a5a9ca804e12f"
|
|
42
42
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"apply-context-diff.test.d.ts","sourceRoot":"","sources":["../../lib/map/apply-context-diff.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
import { SAMPLE_CONTEXT, SAMPLE_LAYER1, SAMPLE_LAYER2, SAMPLE_LAYER3, SAMPLE_LAYER4, SAMPLE_LAYER5, } from "@geospatial-sdk/core/fixtures/map-context.fixtures";
|
|
2
|
-
import { createLayer, createMapFromContext } from "./create-map";
|
|
3
|
-
import { applyContextDiffToMap } from "./apply-context-diff";
|
|
4
|
-
import { beforeEach } from "vitest";
|
|
5
|
-
function assertEqualsToModel(layer, layerModel) {
|
|
6
|
-
var _a;
|
|
7
|
-
const reference = createLayer(layerModel);
|
|
8
|
-
expect(reference).toBeInstanceOf(layer.constructor);
|
|
9
|
-
const refSource = reference.getSource();
|
|
10
|
-
const layerSource = layer.getSource();
|
|
11
|
-
expect(reference.getSource()).toBeInstanceOf((_a = layer.getSource()) === null || _a === void 0 ? void 0 : _a.constructor);
|
|
12
|
-
if (typeof (refSource === null || refSource === void 0 ? void 0 : refSource.getUrl) === "function") {
|
|
13
|
-
expect(layerSource === null || layerSource === void 0 ? void 0 : layerSource.getUrl).toBeTypeOf("function");
|
|
14
|
-
}
|
|
15
|
-
else if (typeof (refSource === null || refSource === void 0 ? void 0 : refSource.getUrls) !== "undefined") {
|
|
16
|
-
expect(refSource === null || refSource === void 0 ? void 0 : refSource.getUrls()).toEqual(layerSource === null || layerSource === void 0 ? void 0 : layerSource.getUrls());
|
|
17
|
-
}
|
|
18
|
-
else if (typeof (refSource === null || refSource === void 0 ? void 0 : refSource.getUrl) !== "undefined") {
|
|
19
|
-
expect(refSource === null || refSource === void 0 ? void 0 : refSource.getUrl()).toEqual(layerSource === null || layerSource === void 0 ? void 0 : layerSource.getUrl());
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
describe("applyContextDiffToMap", () => {
|
|
23
|
-
let context;
|
|
24
|
-
let diff;
|
|
25
|
-
let map;
|
|
26
|
-
let layersArray;
|
|
27
|
-
beforeEach(() => {
|
|
28
|
-
context = Object.assign(Object.assign({}, SAMPLE_CONTEXT), { layers: [SAMPLE_LAYER2, SAMPLE_LAYER1] });
|
|
29
|
-
map = createMapFromContext(context);
|
|
30
|
-
});
|
|
31
|
-
describe("no change", () => {
|
|
32
|
-
beforeEach(() => {
|
|
33
|
-
diff = {
|
|
34
|
-
layersAdded: [],
|
|
35
|
-
layersChanged: [],
|
|
36
|
-
layersRemoved: [],
|
|
37
|
-
layersReordered: [],
|
|
38
|
-
viewChanges: {},
|
|
39
|
-
};
|
|
40
|
-
applyContextDiffToMap(map, diff);
|
|
41
|
-
layersArray = map.getLayers().getArray();
|
|
42
|
-
});
|
|
43
|
-
it("does not affect the map", () => {
|
|
44
|
-
expect(layersArray.length).toEqual(2);
|
|
45
|
-
assertEqualsToModel(layersArray[0], SAMPLE_LAYER2);
|
|
46
|
-
assertEqualsToModel(layersArray[1], SAMPLE_LAYER1);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
describe("layers added", () => {
|
|
50
|
-
beforeEach(() => {
|
|
51
|
-
diff = {
|
|
52
|
-
layersAdded: [
|
|
53
|
-
{
|
|
54
|
-
layer: SAMPLE_LAYER3,
|
|
55
|
-
position: 0,
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
layer: SAMPLE_LAYER4,
|
|
59
|
-
position: 2,
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
|
-
layersChanged: [],
|
|
63
|
-
layersRemoved: [],
|
|
64
|
-
layersReordered: [],
|
|
65
|
-
viewChanges: {},
|
|
66
|
-
};
|
|
67
|
-
applyContextDiffToMap(map, diff);
|
|
68
|
-
layersArray = map.getLayers().getArray();
|
|
69
|
-
});
|
|
70
|
-
it("adds the layers to the map", () => {
|
|
71
|
-
expect(layersArray.length).toEqual(4);
|
|
72
|
-
assertEqualsToModel(layersArray[0], SAMPLE_LAYER3);
|
|
73
|
-
assertEqualsToModel(layersArray[1], SAMPLE_LAYER2);
|
|
74
|
-
assertEqualsToModel(layersArray[2], SAMPLE_LAYER4);
|
|
75
|
-
assertEqualsToModel(layersArray[3], SAMPLE_LAYER1);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
describe("layers removed", () => {
|
|
79
|
-
beforeEach(() => {
|
|
80
|
-
diff = {
|
|
81
|
-
layersAdded: [],
|
|
82
|
-
layersChanged: [],
|
|
83
|
-
layersRemoved: [
|
|
84
|
-
{
|
|
85
|
-
layer: SAMPLE_LAYER2,
|
|
86
|
-
position: 0,
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
layer: SAMPLE_LAYER1,
|
|
90
|
-
position: 1,
|
|
91
|
-
},
|
|
92
|
-
],
|
|
93
|
-
layersReordered: [],
|
|
94
|
-
viewChanges: {},
|
|
95
|
-
};
|
|
96
|
-
applyContextDiffToMap(map, diff);
|
|
97
|
-
});
|
|
98
|
-
it("deletes the layers", () => {
|
|
99
|
-
expect(map.getLayers().getLength()).toEqual(0);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
describe("layers changed", () => {
|
|
103
|
-
beforeEach(() => {
|
|
104
|
-
diff = {
|
|
105
|
-
layersAdded: [],
|
|
106
|
-
layersChanged: [
|
|
107
|
-
{
|
|
108
|
-
layer: Object.assign(Object.assign({}, SAMPLE_LAYER2), { url: "http://changed/" }),
|
|
109
|
-
position: 0,
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
layer: Object.assign(Object.assign({}, SAMPLE_LAYER1), { url: "http://changed/", extras: {
|
|
113
|
-
changed: true,
|
|
114
|
-
} }),
|
|
115
|
-
position: 1,
|
|
116
|
-
},
|
|
117
|
-
],
|
|
118
|
-
layersRemoved: [],
|
|
119
|
-
layersReordered: [],
|
|
120
|
-
viewChanges: {},
|
|
121
|
-
};
|
|
122
|
-
applyContextDiffToMap(map, diff);
|
|
123
|
-
layersArray = map.getLayers().getArray();
|
|
124
|
-
});
|
|
125
|
-
it("modifies the layers accordingly", () => {
|
|
126
|
-
expect(layersArray.length).toEqual(2);
|
|
127
|
-
assertEqualsToModel(layersArray[0], diff.layersChanged[0].layer);
|
|
128
|
-
assertEqualsToModel(layersArray[1], diff.layersChanged[1].layer);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
describe("reordering", () => {
|
|
132
|
-
describe("three layers reordered", () => {
|
|
133
|
-
beforeEach(() => {
|
|
134
|
-
context = Object.assign(Object.assign({}, SAMPLE_CONTEXT), { layers: [SAMPLE_LAYER1, SAMPLE_LAYER2, SAMPLE_LAYER3] });
|
|
135
|
-
map = createMapFromContext(context);
|
|
136
|
-
diff = {
|
|
137
|
-
layersAdded: [],
|
|
138
|
-
layersChanged: [],
|
|
139
|
-
layersRemoved: [],
|
|
140
|
-
layersReordered: [
|
|
141
|
-
{
|
|
142
|
-
layer: SAMPLE_LAYER2,
|
|
143
|
-
newPosition: 0,
|
|
144
|
-
previousPosition: 1,
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
layer: SAMPLE_LAYER1,
|
|
148
|
-
newPosition: 1,
|
|
149
|
-
previousPosition: 0,
|
|
150
|
-
},
|
|
151
|
-
],
|
|
152
|
-
viewChanges: {},
|
|
153
|
-
};
|
|
154
|
-
applyContextDiffToMap(map, diff);
|
|
155
|
-
layersArray = map.getLayers().getArray();
|
|
156
|
-
});
|
|
157
|
-
it("moves the layers accordingly", () => {
|
|
158
|
-
expect(layersArray.length).toEqual(3);
|
|
159
|
-
assertEqualsToModel(layersArray[0], SAMPLE_LAYER2);
|
|
160
|
-
assertEqualsToModel(layersArray[1], SAMPLE_LAYER1);
|
|
161
|
-
assertEqualsToModel(layersArray[2], SAMPLE_LAYER3);
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
describe("four layers reordered", () => {
|
|
165
|
-
beforeEach(() => {
|
|
166
|
-
context = Object.assign(Object.assign({}, SAMPLE_CONTEXT), { layers: [SAMPLE_LAYER1, SAMPLE_LAYER3, SAMPLE_LAYER4, SAMPLE_LAYER2] });
|
|
167
|
-
map = createMapFromContext(context);
|
|
168
|
-
diff = {
|
|
169
|
-
layersAdded: [],
|
|
170
|
-
layersChanged: [],
|
|
171
|
-
layersRemoved: [],
|
|
172
|
-
layersReordered: [
|
|
173
|
-
{
|
|
174
|
-
layer: SAMPLE_LAYER4,
|
|
175
|
-
newPosition: 0,
|
|
176
|
-
previousPosition: 2,
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
layer: SAMPLE_LAYER1,
|
|
180
|
-
newPosition: 2,
|
|
181
|
-
previousPosition: 0,
|
|
182
|
-
},
|
|
183
|
-
],
|
|
184
|
-
viewChanges: {},
|
|
185
|
-
};
|
|
186
|
-
applyContextDiffToMap(map, diff);
|
|
187
|
-
layersArray = map.getLayers().getArray();
|
|
188
|
-
});
|
|
189
|
-
it("moves the layers accordingly", () => {
|
|
190
|
-
expect(layersArray.length).toEqual(4);
|
|
191
|
-
assertEqualsToModel(layersArray[0], SAMPLE_LAYER4);
|
|
192
|
-
assertEqualsToModel(layersArray[1], SAMPLE_LAYER3);
|
|
193
|
-
assertEqualsToModel(layersArray[2], SAMPLE_LAYER1);
|
|
194
|
-
assertEqualsToModel(layersArray[3], SAMPLE_LAYER2);
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
describe("combined changes", () => {
|
|
199
|
-
let changedLayer;
|
|
200
|
-
beforeEach(() => {
|
|
201
|
-
changedLayer = Object.assign(Object.assign({}, SAMPLE_LAYER3), { extras: { prop: true } });
|
|
202
|
-
context = Object.assign(Object.assign({}, context), { layers: [SAMPLE_LAYER1, SAMPLE_LAYER5, SAMPLE_LAYER3, SAMPLE_LAYER4] });
|
|
203
|
-
map = createMapFromContext(context);
|
|
204
|
-
diff = {
|
|
205
|
-
layersAdded: [
|
|
206
|
-
{
|
|
207
|
-
layer: SAMPLE_LAYER2,
|
|
208
|
-
position: 0,
|
|
209
|
-
},
|
|
210
|
-
],
|
|
211
|
-
layersChanged: [
|
|
212
|
-
{
|
|
213
|
-
layer: changedLayer,
|
|
214
|
-
position: 1,
|
|
215
|
-
},
|
|
216
|
-
],
|
|
217
|
-
layersRemoved: [
|
|
218
|
-
{
|
|
219
|
-
layer: SAMPLE_LAYER1,
|
|
220
|
-
position: 0,
|
|
221
|
-
},
|
|
222
|
-
{
|
|
223
|
-
layer: SAMPLE_LAYER4,
|
|
224
|
-
position: 3,
|
|
225
|
-
},
|
|
226
|
-
],
|
|
227
|
-
layersReordered: [
|
|
228
|
-
{
|
|
229
|
-
layer: changedLayer,
|
|
230
|
-
newPosition: 1,
|
|
231
|
-
previousPosition: 2,
|
|
232
|
-
},
|
|
233
|
-
{
|
|
234
|
-
layer: SAMPLE_LAYER5,
|
|
235
|
-
newPosition: 2,
|
|
236
|
-
previousPosition: 1,
|
|
237
|
-
},
|
|
238
|
-
],
|
|
239
|
-
viewChanges: {},
|
|
240
|
-
};
|
|
241
|
-
applyContextDiffToMap(map, diff);
|
|
242
|
-
layersArray = map.getLayers().getArray();
|
|
243
|
-
});
|
|
244
|
-
it("applies all changes", () => {
|
|
245
|
-
expect(layersArray.length).toEqual(3);
|
|
246
|
-
assertEqualsToModel(layersArray[0], SAMPLE_LAYER2);
|
|
247
|
-
assertEqualsToModel(layersArray[1], changedLayer);
|
|
248
|
-
assertEqualsToModel(layersArray[2], SAMPLE_LAYER5);
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-map.test.d.ts","sourceRoot":"","sources":["../../lib/map/create-map.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
import TileLayer from "ol/layer/Tile";
|
|
2
|
-
import VectorLayer from "ol/layer/Vector";
|
|
3
|
-
import Map from "ol/Map";
|
|
4
|
-
import TileWMS from "ol/source/TileWMS";
|
|
5
|
-
import VectorSource from "ol/source/Vector";
|
|
6
|
-
import XYZ from "ol/source/XYZ";
|
|
7
|
-
import View from "ol/View";
|
|
8
|
-
import GeoJSON from "ol/format/GeoJSON";
|
|
9
|
-
import { MAP_CTX_EXTENT_FIXTURE, MAP_CTX_FIXTURE, MAP_CTX_LAYER_GEOJSON_FIXTURE, MAP_CTX_LAYER_GEOJSON_REMOTE_FIXTURE, MAP_CTX_LAYER_WFS_FIXTURE, MAP_CTX_LAYER_WMS_FIXTURE, MAP_CTX_LAYER_XYZ_FIXTURE, } from "@geospatial-sdk/core/fixtures/map-context.fixtures";
|
|
10
|
-
import { createLayer, createMapFromContext, createView, resetMapFromContext, } from "./create-map";
|
|
11
|
-
describe("MapContextService", () => {
|
|
12
|
-
describe("#createLayer", () => {
|
|
13
|
-
let layerModel, layer;
|
|
14
|
-
describe("XYZ", () => {
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
layerModel = MAP_CTX_LAYER_XYZ_FIXTURE;
|
|
17
|
-
layer = createLayer(layerModel);
|
|
18
|
-
});
|
|
19
|
-
it("create a tile layer", () => {
|
|
20
|
-
expect(layer).toBeTruthy();
|
|
21
|
-
expect(layer).toBeInstanceOf(TileLayer);
|
|
22
|
-
});
|
|
23
|
-
it("set correct layer properties", () => {
|
|
24
|
-
var _a;
|
|
25
|
-
expect(layer.getVisible()).toBe(true);
|
|
26
|
-
expect(layer.getOpacity()).toBe(1);
|
|
27
|
-
expect(layer.get("label")).toBeUndefined();
|
|
28
|
-
expect((_a = layer.getSource()) === null || _a === void 0 ? void 0 : _a.getAttributions()).toBeNull();
|
|
29
|
-
});
|
|
30
|
-
it("create a XYZ source", () => {
|
|
31
|
-
const source = layer.getSource();
|
|
32
|
-
expect(source).toBeInstanceOf(XYZ);
|
|
33
|
-
});
|
|
34
|
-
it("set correct urls", () => {
|
|
35
|
-
var _a;
|
|
36
|
-
const source = layer.getSource();
|
|
37
|
-
const urls = (_a = source.getUrls()) !== null && _a !== void 0 ? _a : [];
|
|
38
|
-
expect(urls.length).toBe(3);
|
|
39
|
-
expect(urls[0]).toEqual("https://a.tile.openstreetmap.org/{z}/{x}/{y}.png");
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
describe("WMS", () => {
|
|
43
|
-
beforeEach(() => {
|
|
44
|
-
(layerModel = MAP_CTX_LAYER_WMS_FIXTURE),
|
|
45
|
-
(layer = createLayer(layerModel));
|
|
46
|
-
});
|
|
47
|
-
it("create a tile layer", () => {
|
|
48
|
-
expect(layer).toBeTruthy();
|
|
49
|
-
expect(layer).toBeInstanceOf(TileLayer);
|
|
50
|
-
});
|
|
51
|
-
it("set correct layer properties", () => {
|
|
52
|
-
var _a;
|
|
53
|
-
expect(layer.getVisible()).toBe(false);
|
|
54
|
-
expect(layer.getOpacity()).toBe(0.5);
|
|
55
|
-
expect(layer.get("label")).toBe("Communes");
|
|
56
|
-
// @ts-ignore
|
|
57
|
-
expect((_a = layer.getSource()) === null || _a === void 0 ? void 0 : _a.getAttributions()()).toEqual(["camptocamp"]);
|
|
58
|
-
});
|
|
59
|
-
it("create a TileWMS source", () => {
|
|
60
|
-
const source = layer.getSource();
|
|
61
|
-
expect(source).toBeInstanceOf(TileWMS);
|
|
62
|
-
});
|
|
63
|
-
it("set correct WMS params", () => {
|
|
64
|
-
const source = layer.getSource();
|
|
65
|
-
const params = source.getParams();
|
|
66
|
-
expect(params.LAYERS).toBe(layerModel.name);
|
|
67
|
-
});
|
|
68
|
-
it("set correct url without existing REQUEST and SERVICE params", () => {
|
|
69
|
-
const source = layer.getSource();
|
|
70
|
-
const urls = source.getUrls() || [];
|
|
71
|
-
expect(urls.length).toBe(1);
|
|
72
|
-
expect(urls[0]).toBe("https://www.geograndest.fr/geoserver/region-grand-est/ows");
|
|
73
|
-
});
|
|
74
|
-
it("set WMS gutter of 20px", () => {
|
|
75
|
-
const source = layer.getSource();
|
|
76
|
-
const gutter = source["gutter_"];
|
|
77
|
-
expect(gutter).toBe(20);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
describe("WFS", () => {
|
|
81
|
-
beforeEach(() => {
|
|
82
|
-
(layerModel = MAP_CTX_LAYER_WFS_FIXTURE),
|
|
83
|
-
(layer = createLayer(layerModel));
|
|
84
|
-
});
|
|
85
|
-
it("create a vector layer", () => {
|
|
86
|
-
expect(layer).toBeTruthy();
|
|
87
|
-
expect(layer).toBeInstanceOf(VectorLayer);
|
|
88
|
-
});
|
|
89
|
-
it("set correct layer properties", () => {
|
|
90
|
-
var _a;
|
|
91
|
-
expect(layer.getVisible()).toBe(true);
|
|
92
|
-
expect(layer.getOpacity()).toBe(0.5);
|
|
93
|
-
expect(layer.get("label")).toBe("Communes");
|
|
94
|
-
const attributions = (_a = layer.getSource()) === null || _a === void 0 ? void 0 : _a.getAttributions();
|
|
95
|
-
expect(attributions).not.toBeNull();
|
|
96
|
-
// @ts-ignore
|
|
97
|
-
expect(attributions()).toEqual(["camptocamp"]);
|
|
98
|
-
});
|
|
99
|
-
it("create a Vector source", () => {
|
|
100
|
-
const source = layer.getSource();
|
|
101
|
-
expect(source).toBeInstanceOf(VectorSource);
|
|
102
|
-
});
|
|
103
|
-
it("set correct url load function", () => {
|
|
104
|
-
const source = layer.getSource();
|
|
105
|
-
const urlLoader = source.getUrl();
|
|
106
|
-
expect(urlLoader([10, 20, 30, 40])).toBe("https://www.geograndest.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");
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
describe("GEOJSON", () => {
|
|
110
|
-
describe("with inline data", () => {
|
|
111
|
-
beforeEach(() => {
|
|
112
|
-
layerModel = MAP_CTX_LAYER_GEOJSON_FIXTURE;
|
|
113
|
-
layer = createLayer(layerModel);
|
|
114
|
-
});
|
|
115
|
-
it("create a VectorLayer", () => {
|
|
116
|
-
expect(layer).toBeTruthy();
|
|
117
|
-
expect(layer).toBeInstanceOf(VectorLayer);
|
|
118
|
-
});
|
|
119
|
-
it("set correct layer properties", () => {
|
|
120
|
-
expect(layer.getVisible()).toBe(true);
|
|
121
|
-
expect(layer.getOpacity()).toBe(0.8);
|
|
122
|
-
expect(layer.get("label")).toBe("Regions");
|
|
123
|
-
});
|
|
124
|
-
it("create a VectorSource source", () => {
|
|
125
|
-
const source = layer.getSource();
|
|
126
|
-
expect(source).toBeInstanceOf(VectorSource);
|
|
127
|
-
});
|
|
128
|
-
it("add features", () => {
|
|
129
|
-
const source = layer.getSource();
|
|
130
|
-
const features = source.getFeatures();
|
|
131
|
-
const data = layerModel
|
|
132
|
-
.data;
|
|
133
|
-
expect(features.length).toBe(data.features.length);
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
describe("with inline data as string", () => {
|
|
137
|
-
beforeEach(() => {
|
|
138
|
-
layerModel = Object.assign({}, MAP_CTX_LAYER_GEOJSON_FIXTURE);
|
|
139
|
-
layerModel.data = JSON.stringify(layerModel.data);
|
|
140
|
-
layer = createLayer(layerModel);
|
|
141
|
-
});
|
|
142
|
-
it("create a VectorLayer", () => {
|
|
143
|
-
expect(layer).toBeTruthy();
|
|
144
|
-
expect(layer).toBeInstanceOf(VectorLayer);
|
|
145
|
-
});
|
|
146
|
-
it("create a VectorSource source", () => {
|
|
147
|
-
const source = layer.getSource();
|
|
148
|
-
expect(source).toBeInstanceOf(VectorSource);
|
|
149
|
-
});
|
|
150
|
-
it("add features", () => {
|
|
151
|
-
const source = layer.getSource();
|
|
152
|
-
const features = source.getFeatures();
|
|
153
|
-
expect(features.length).toBe(MAP_CTX_LAYER_GEOJSON_FIXTURE.data.features
|
|
154
|
-
.length);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
describe("with invalid inline data as string", () => {
|
|
158
|
-
beforeEach(() => {
|
|
159
|
-
const spy = vi.spyOn(window.console, "warn");
|
|
160
|
-
spy.mockClear();
|
|
161
|
-
layerModel = Object.assign(Object.assign({}, MAP_CTX_LAYER_GEOJSON_FIXTURE), { url: undefined, data: "blargz" });
|
|
162
|
-
layer = createLayer(layerModel);
|
|
163
|
-
});
|
|
164
|
-
it("create a VectorLayer", () => {
|
|
165
|
-
expect(layer).toBeTruthy();
|
|
166
|
-
expect(layer).toBeInstanceOf(VectorLayer);
|
|
167
|
-
});
|
|
168
|
-
it("outputs error in the console", () => {
|
|
169
|
-
expect(window.console.warn).toHaveBeenCalled();
|
|
170
|
-
});
|
|
171
|
-
it("create an empty VectorSource source", () => {
|
|
172
|
-
const source = layer.getSource();
|
|
173
|
-
expect(source).toBeInstanceOf(VectorSource);
|
|
174
|
-
expect(source.getFeatures().length).toBe(0);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
describe("with remote file url", () => {
|
|
178
|
-
beforeEach(() => {
|
|
179
|
-
layerModel = MAP_CTX_LAYER_GEOJSON_REMOTE_FIXTURE;
|
|
180
|
-
layer = createLayer(layerModel);
|
|
181
|
-
});
|
|
182
|
-
it("create a VectorLayer", () => {
|
|
183
|
-
expect(layer).toBeTruthy();
|
|
184
|
-
expect(layer).toBeInstanceOf(VectorLayer);
|
|
185
|
-
});
|
|
186
|
-
it("create a VectorSource source", () => {
|
|
187
|
-
const source = layer.getSource();
|
|
188
|
-
expect(source).toBeInstanceOf(VectorSource);
|
|
189
|
-
});
|
|
190
|
-
it("sets the format as GeoJSON", () => {
|
|
191
|
-
const source = layer.getSource();
|
|
192
|
-
expect(source.getFormat()).toBeInstanceOf(GeoJSON);
|
|
193
|
-
});
|
|
194
|
-
it("set the url to point to the file", () => {
|
|
195
|
-
const source = layer.getSource();
|
|
196
|
-
expect(source.getUrl()).toBe(layerModel.url);
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
describe("#createView", () => {
|
|
202
|
-
let view;
|
|
203
|
-
let map;
|
|
204
|
-
describe("from center and zoom", () => {
|
|
205
|
-
const contextModel = MAP_CTX_FIXTURE;
|
|
206
|
-
beforeEach(() => {
|
|
207
|
-
map = createMapFromContext(contextModel);
|
|
208
|
-
view = createView(contextModel.view, map);
|
|
209
|
-
});
|
|
210
|
-
it("create a view", () => {
|
|
211
|
-
expect(view).toBeTruthy();
|
|
212
|
-
expect(view).toBeInstanceOf(View);
|
|
213
|
-
});
|
|
214
|
-
it("set center", () => {
|
|
215
|
-
const center = view.getCenter();
|
|
216
|
-
expect(center).toEqual([862726.0536478702, 6207260.308175252]);
|
|
217
|
-
});
|
|
218
|
-
it("set zoom", () => {
|
|
219
|
-
const zoom = view.getZoom();
|
|
220
|
-
expect(zoom).toEqual(contextModel.view.zoom);
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
describe("from extent", () => {
|
|
224
|
-
const contextModel = Object.assign(Object.assign({}, MAP_CTX_FIXTURE), { view: Object.assign(Object.assign({}, MAP_CTX_FIXTURE.view), { extent: MAP_CTX_EXTENT_FIXTURE }) });
|
|
225
|
-
const map = new Map({});
|
|
226
|
-
map.setSize([100, 100]);
|
|
227
|
-
beforeEach(() => {
|
|
228
|
-
view = createView(contextModel.view, map);
|
|
229
|
-
});
|
|
230
|
-
it("create a view", () => {
|
|
231
|
-
expect(view).toBeTruthy();
|
|
232
|
-
expect(view).toBeInstanceOf(View);
|
|
233
|
-
});
|
|
234
|
-
it("set center", () => {
|
|
235
|
-
const center = view.getCenter();
|
|
236
|
-
expect(center).toEqual([324027.04834895337, 6438563.654151043]);
|
|
237
|
-
});
|
|
238
|
-
it("set zoom", () => {
|
|
239
|
-
const zoom = view.getZoom();
|
|
240
|
-
expect(zoom).toEqual(5);
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
describe("#resetMapFromContext", () => {
|
|
245
|
-
const map = new Map({});
|
|
246
|
-
const mapContext = MAP_CTX_FIXTURE;
|
|
247
|
-
beforeEach(() => {
|
|
248
|
-
resetMapFromContext(map, mapContext);
|
|
249
|
-
});
|
|
250
|
-
it("create a map", () => {
|
|
251
|
-
expect(map).toBeTruthy();
|
|
252
|
-
expect(map).toBeInstanceOf(Map);
|
|
253
|
-
});
|
|
254
|
-
it("add layers", () => {
|
|
255
|
-
const layers = map.getLayers().getArray();
|
|
256
|
-
expect(layers.length).toEqual(3);
|
|
257
|
-
});
|
|
258
|
-
it("set view", () => {
|
|
259
|
-
const view = map.getView();
|
|
260
|
-
expect(view).toBeTruthy();
|
|
261
|
-
expect(view).toBeInstanceOf(View);
|
|
262
|
-
});
|
|
263
|
-
describe("uses default fallback view", () => {
|
|
264
|
-
let view;
|
|
265
|
-
const map = new Map({});
|
|
266
|
-
const mapContext = {
|
|
267
|
-
view: {},
|
|
268
|
-
layers: [
|
|
269
|
-
MAP_CTX_LAYER_XYZ_FIXTURE,
|
|
270
|
-
MAP_CTX_LAYER_WMS_FIXTURE,
|
|
271
|
-
MAP_CTX_LAYER_GEOJSON_FIXTURE,
|
|
272
|
-
],
|
|
273
|
-
};
|
|
274
|
-
beforeEach(() => {
|
|
275
|
-
resetMapFromContext(map, mapContext);
|
|
276
|
-
});
|
|
277
|
-
it("create a map", () => {
|
|
278
|
-
expect(map).toBeTruthy();
|
|
279
|
-
expect(map).toBeInstanceOf(Map);
|
|
280
|
-
});
|
|
281
|
-
it("add layers", () => {
|
|
282
|
-
const layers = map.getLayers().getArray();
|
|
283
|
-
expect(layers.length).toEqual(3);
|
|
284
|
-
});
|
|
285
|
-
it("set view", () => {
|
|
286
|
-
view = map.getView();
|
|
287
|
-
expect(view).toBeTruthy();
|
|
288
|
-
expect(view).toBeInstanceOf(View);
|
|
289
|
-
});
|
|
290
|
-
it("set center", () => {
|
|
291
|
-
const center = view.getCenter();
|
|
292
|
-
expect(center).toEqual([0, 0]);
|
|
293
|
-
});
|
|
294
|
-
it("set zoom", () => {
|
|
295
|
-
const zoom = view.getZoom();
|
|
296
|
-
expect(zoom).toEqual(0);
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"styles.test.d.ts","sourceRoot":"","sources":["../../lib/map/styles.test.ts"],"names":[],"mappings":""}
|
package/dist/map/styles.test.js
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
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";
|
|
5
|
-
import { createGeometryStyles, createStyleFunction, defaultHighlightStyle, defaultStyle, } from "./styles";
|
|
6
|
-
describe("MapStyleService", () => {
|
|
7
|
-
describe("#createGeometryStyles", () => {
|
|
8
|
-
let styles;
|
|
9
|
-
let pointStyle;
|
|
10
|
-
let lineStyle;
|
|
11
|
-
let polygonStyle;
|
|
12
|
-
describe("unfocused style", () => {
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
const options = {
|
|
15
|
-
color: "orange",
|
|
16
|
-
};
|
|
17
|
-
styles = createGeometryStyles(options);
|
|
18
|
-
pointStyle = styles.point;
|
|
19
|
-
lineStyle = styles.line;
|
|
20
|
-
polygonStyle = styles.polygon;
|
|
21
|
-
});
|
|
22
|
-
describe("point style", () => {
|
|
23
|
-
it("has 1 style", () => {
|
|
24
|
-
expect(pointStyle).toBeInstanceOf(Style);
|
|
25
|
-
});
|
|
26
|
-
it("has correct radius", () => {
|
|
27
|
-
var _a;
|
|
28
|
-
expect((_a = pointStyle.getImage()) === null || _a === void 0 ? void 0 : _a.getRadius()).toBe(7);
|
|
29
|
-
});
|
|
30
|
-
it("has correct fill color", () => {
|
|
31
|
-
var _a, _b;
|
|
32
|
-
expect((_b = (_a = pointStyle.getImage()) === null || _a === void 0 ? void 0 : _a.getFill()) === null || _b === void 0 ? void 0 : _b.getColor()).toBe("orange");
|
|
33
|
-
});
|
|
34
|
-
it("has correct stroke color and width", () => {
|
|
35
|
-
var _a, _b, _c, _d;
|
|
36
|
-
expect((_b = (_a = pointStyle.getImage()) === null || _a === void 0 ? void 0 : _a.getStroke()) === null || _b === void 0 ? void 0 : _b.getColor()).toBe("white");
|
|
37
|
-
expect((_d = (_c = pointStyle.getImage()) === null || _c === void 0 ? void 0 : _c.getStroke()) === null || _d === void 0 ? void 0 : _d.getWidth()).toBe(2);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
describe("polygon style", () => {
|
|
41
|
-
it("has 1 style", () => {
|
|
42
|
-
expect(polygonStyle).toBeInstanceOf(Style);
|
|
43
|
-
});
|
|
44
|
-
it("has correct fill color", () => {
|
|
45
|
-
var _a;
|
|
46
|
-
expect((_a = polygonStyle.getFill()) === null || _a === void 0 ? void 0 : _a.getColor()).toBe(chroma("orange").alpha(0.25).css());
|
|
47
|
-
});
|
|
48
|
-
it("has correct stroke color and width", () => {
|
|
49
|
-
var _a, _b;
|
|
50
|
-
expect((_a = polygonStyle.getStroke()) === null || _a === void 0 ? void 0 : _a.getColor()).toBe("white");
|
|
51
|
-
expect((_b = polygonStyle.getStroke()) === null || _b === void 0 ? void 0 : _b.getWidth()).toBe(2);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
describe("line style", () => {
|
|
55
|
-
it("has 2 styles", () => {
|
|
56
|
-
expect(lineStyle).toEqual([expect.any(Style), expect.any(Style)]);
|
|
57
|
-
});
|
|
58
|
-
it("has correct color (back stroke)", () => {
|
|
59
|
-
var _a;
|
|
60
|
-
expect((_a = lineStyle[0].getStroke()) === null || _a === void 0 ? void 0 : _a.getColor()).toBe("white");
|
|
61
|
-
});
|
|
62
|
-
it("has correct width (back stroke)", () => {
|
|
63
|
-
var _a;
|
|
64
|
-
expect((_a = lineStyle[0].getStroke()) === null || _a === void 0 ? void 0 : _a.getWidth()).toBe(6);
|
|
65
|
-
});
|
|
66
|
-
it("has correct color (front stroke)", () => {
|
|
67
|
-
var _a;
|
|
68
|
-
expect((_a = lineStyle[1].getStroke()) === null || _a === void 0 ? void 0 : _a.getColor()).toBe("orange");
|
|
69
|
-
});
|
|
70
|
-
it("has correct width (front stroke)", () => {
|
|
71
|
-
var _a;
|
|
72
|
-
expect((_a = lineStyle[1].getStroke()) === null || _a === void 0 ? void 0 : _a.getWidth()).toBe(2);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
describe("focused style", () => {
|
|
77
|
-
beforeEach(() => {
|
|
78
|
-
const options = {
|
|
79
|
-
color: "pink",
|
|
80
|
-
isFocused: true,
|
|
81
|
-
};
|
|
82
|
-
styles = createGeometryStyles(options);
|
|
83
|
-
pointStyle = styles.point;
|
|
84
|
-
lineStyle = styles.line;
|
|
85
|
-
polygonStyle = styles.polygon;
|
|
86
|
-
});
|
|
87
|
-
describe("point style", () => {
|
|
88
|
-
it("has correct radius", () => {
|
|
89
|
-
var _a;
|
|
90
|
-
expect((_a = pointStyle.getImage()) === null || _a === void 0 ? void 0 : _a.getRadius()).toBe(8);
|
|
91
|
-
});
|
|
92
|
-
it("has correct fill color", () => {
|
|
93
|
-
var _a, _b;
|
|
94
|
-
expect((_b = (_a = pointStyle.getImage()) === null || _a === void 0 ? void 0 : _a.getFill()) === null || _b === void 0 ? void 0 : _b.getColor()).toBe("pink");
|
|
95
|
-
});
|
|
96
|
-
it("has correct stroke color and width", () => {
|
|
97
|
-
var _a, _b, _c, _d;
|
|
98
|
-
expect((_b = (_a = pointStyle.getImage()) === null || _a === void 0 ? void 0 : _a.getStroke()) === null || _b === void 0 ? void 0 : _b.getColor()).toBe("white");
|
|
99
|
-
expect((_d = (_c = pointStyle.getImage()) === null || _c === void 0 ? void 0 : _c.getStroke()) === null || _d === void 0 ? void 0 : _d.getWidth()).toBe(3);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
describe("polygon style", () => {
|
|
103
|
-
it("has correct fill color", () => {
|
|
104
|
-
var _a;
|
|
105
|
-
expect((_a = polygonStyle.getFill()) === null || _a === void 0 ? void 0 : _a.getColor()).toBe(chroma("pink").alpha(0.25).css());
|
|
106
|
-
});
|
|
107
|
-
it("has correct stroke color and width", () => {
|
|
108
|
-
var _a, _b;
|
|
109
|
-
expect((_a = polygonStyle.getStroke()) === null || _a === void 0 ? void 0 : _a.getColor()).toBe("white");
|
|
110
|
-
expect((_b = polygonStyle.getStroke()) === null || _b === void 0 ? void 0 : _b.getWidth()).toBe(2);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
describe("line style", () => {
|
|
114
|
-
it("has correct color (back stroke)", () => {
|
|
115
|
-
var _a;
|
|
116
|
-
expect((_a = lineStyle[0].getStroke()) === null || _a === void 0 ? void 0 : _a.getColor()).toBe("white");
|
|
117
|
-
});
|
|
118
|
-
it("has correct width (back stroke)", () => {
|
|
119
|
-
var _a;
|
|
120
|
-
expect((_a = lineStyle[0].getStroke()) === null || _a === void 0 ? void 0 : _a.getWidth()).toBe(8);
|
|
121
|
-
});
|
|
122
|
-
it("has correct color (front stroke)", () => {
|
|
123
|
-
var _a;
|
|
124
|
-
expect((_a = lineStyle[1].getStroke()) === null || _a === void 0 ? void 0 : _a.getColor()).toBe("pink");
|
|
125
|
-
});
|
|
126
|
-
it("has correct width (front stroke)", () => {
|
|
127
|
-
var _a;
|
|
128
|
-
expect((_a = lineStyle[1].getStroke()) === null || _a === void 0 ? void 0 : _a.getWidth()).toBe(3);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
describe("#createStyleFunction", () => {
|
|
134
|
-
let styleFn;
|
|
135
|
-
let feature;
|
|
136
|
-
it("returns a function", () => {
|
|
137
|
-
styleFn = createStyleFunction(createGeometryStyles({
|
|
138
|
-
color: "blue",
|
|
139
|
-
}));
|
|
140
|
-
feature = new Feature();
|
|
141
|
-
});
|
|
142
|
-
describe("with linestring geometry", () => {
|
|
143
|
-
beforeEach(() => {
|
|
144
|
-
feature.setGeometry(new LineString([]));
|
|
145
|
-
});
|
|
146
|
-
it("resolves to a double style with stroke", () => {
|
|
147
|
-
const style = styleFn(feature, 1);
|
|
148
|
-
expect(style).toEqual([expect.any(Style), expect.any(Style)]);
|
|
149
|
-
expect(style[0].getStroke()).toBeTruthy();
|
|
150
|
-
expect(style[0].getFill()).toBeFalsy();
|
|
151
|
-
expect(style[0].getImage()).toBeFalsy();
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
describe("with point geometry", () => {
|
|
155
|
-
beforeEach(() => {
|
|
156
|
-
feature.setGeometry(new Point([]));
|
|
157
|
-
});
|
|
158
|
-
it("resolves to a style with image", () => {
|
|
159
|
-
const style = styleFn(feature, 1);
|
|
160
|
-
expect(style.getImage()).toBeTruthy();
|
|
161
|
-
expect(style.getFill()).toBeFalsy();
|
|
162
|
-
expect(style.getStroke()).toBeFalsy();
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
describe("with polygon geometry", () => {
|
|
166
|
-
beforeEach(() => {
|
|
167
|
-
feature.setGeometry(new Polygon([]));
|
|
168
|
-
});
|
|
169
|
-
it("resolves to a style with fill and stroke", () => {
|
|
170
|
-
const style = styleFn(feature, 1);
|
|
171
|
-
expect(style.getFill()).toBeTruthy();
|
|
172
|
-
expect(style.getStroke()).toBeTruthy();
|
|
173
|
-
expect(style.getImage()).toBeFalsy();
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
describe("built-in styles", () => {
|
|
178
|
-
let pointFeature;
|
|
179
|
-
let pointStyle;
|
|
180
|
-
beforeEach(() => {
|
|
181
|
-
pointFeature = new Feature(new Point([]));
|
|
182
|
-
});
|
|
183
|
-
describe("default style", () => {
|
|
184
|
-
beforeEach(() => {
|
|
185
|
-
const styleFn = defaultStyle;
|
|
186
|
-
pointStyle = styleFn(pointFeature, 1);
|
|
187
|
-
});
|
|
188
|
-
it("uses the primary theme color", () => {
|
|
189
|
-
var _a, _b;
|
|
190
|
-
expect((_b = (_a = pointStyle.getImage()) === null || _a === void 0 ? void 0 : _a.getFill()) === null || _b === void 0 ? void 0 : _b.getColor()).toEqual("blue");
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
describe("default highlight style", () => {
|
|
194
|
-
beforeEach(() => {
|
|
195
|
-
const styleFn = defaultHighlightStyle;
|
|
196
|
-
pointStyle = styleFn(pointFeature, 1);
|
|
197
|
-
});
|
|
198
|
-
it("uses the secondary theme color", () => {
|
|
199
|
-
var _a, _b;
|
|
200
|
-
expect((_b = (_a = pointStyle.getImage()) === null || _a === void 0 ? void 0 : _a.getFill()) === null || _b === void 0 ? void 0 : _b.getColor()).toEqual("red");
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
});
|