@masterportal/masterportalapi 2.2.0 → 2.5.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/.eslintignore +0 -1
- package/.eslintrc +4 -1
- package/CHANGELOG.md +49 -4
- package/example/config/localGeoJSON.js +24 -24
- package/example/config/portal.json +1 -1
- package/example/config/services.json +190 -1
- package/example/index.js +65 -67
- package/package.json +18 -17
- package/src/defaults.js +18 -2
- package/src/index.js +4 -0
- package/src/layer/entities.js +179 -0
- package/src/layer/geojson/index.js +7 -0
- package/src/layer/geojson/style.js +1 -0
- package/src/layer/terrain.js +1 -8
- package/src/layer/tileset.js +1 -8
- package/src/layer/vectorTile.js +3 -3
- package/src/layer/wms.js +4 -0
- package/src/layer/wmts.js +194 -0
- package/src/maps/ol/olMap.js +2 -0
- package/src/maps/olcs/3dUtils/wmsRasterSynchronizer.js +88 -52
- package/src/maps/olcs/olcsMap.js +115 -99
- package/test/layer/entities.test.js +277 -0
- package/test/layer/terrain.test.js +1 -14
- package/test/layer/tileset.test.js +3 -10
- package/test/layer/vectorTile.test.js +2 -2
- package/test/layer/wmts.test.js +26 -0
- package/test/map.test.js +34 -1
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import * as entities from "../../src/layer/entities";
|
|
2
|
+
|
|
3
|
+
describe("entities.js", function () {
|
|
4
|
+
let attr,
|
|
5
|
+
map,
|
|
6
|
+
dataSources = [],
|
|
7
|
+
dataSourcesContent,
|
|
8
|
+
dataSourceValues,
|
|
9
|
+
cesiumCustomDataSourceSpy,
|
|
10
|
+
cesiumHeadingPitchRollSpy,
|
|
11
|
+
tick;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
tick = () => {
|
|
15
|
+
return new Promise(resolve => {
|
|
16
|
+
setTimeout(resolve, 0);
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
dataSourcesContent = {};
|
|
20
|
+
dataSourceValues = [];
|
|
21
|
+
global.Cesium = {};
|
|
22
|
+
global.Cesium.Cartesian3 = {};
|
|
23
|
+
global.Cesium.Transforms = {};
|
|
24
|
+
global.Cesium.Cartesian3.fromDegrees = jest.fn();
|
|
25
|
+
global.Cesium.HeadingPitchRoll = jest.fn();
|
|
26
|
+
global.Cesium.Transforms.headingPitchRollQuaternion = jest.fn();
|
|
27
|
+
global.Cesium.CustomDataSource = function CustomDataSource (name) {
|
|
28
|
+
this.name = name;
|
|
29
|
+
this.entities = {
|
|
30
|
+
values: dataSourceValues,
|
|
31
|
+
add: (toAdd) => {
|
|
32
|
+
dataSourceValues.push(toAdd);
|
|
33
|
+
this.length++;
|
|
34
|
+
return toAdd;
|
|
35
|
+
},
|
|
36
|
+
contains: (value) => dataSourceValues.includes(value)
|
|
37
|
+
};
|
|
38
|
+
this.length = 0;
|
|
39
|
+
this.forEach = () => dataSourceValues.forEach;
|
|
40
|
+
};
|
|
41
|
+
attr = {
|
|
42
|
+
id: "4003",
|
|
43
|
+
name: "EntitiesLayer",
|
|
44
|
+
typ: "Entities3D",
|
|
45
|
+
entities: [
|
|
46
|
+
{
|
|
47
|
+
"url": "https://daten-hamburg.de/gdi3d/datasource-data/Simple_Building.glb",
|
|
48
|
+
"attributes": {
|
|
49
|
+
"name": "einfaches Haus in Planten und Blomen"
|
|
50
|
+
},
|
|
51
|
+
"latitude": 53.5631,
|
|
52
|
+
"longitude": 9.9800,
|
|
53
|
+
"height": 16,
|
|
54
|
+
"heading": 0,
|
|
55
|
+
"pitch": 0,
|
|
56
|
+
"roll": 0,
|
|
57
|
+
"scale": 5,
|
|
58
|
+
"allowPicking": true,
|
|
59
|
+
"show": true
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
};
|
|
63
|
+
dataSources = {
|
|
64
|
+
getByName: (name) => {
|
|
65
|
+
return dataSourcesContent[name] ? [dataSourcesContent[name]] : [];
|
|
66
|
+
},
|
|
67
|
+
add: async (dataSource) => {
|
|
68
|
+
dataSourcesContent[dataSource.name] = dataSource;
|
|
69
|
+
return Promise.resolve(dataSource).then(function (value) {
|
|
70
|
+
return value;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
map = {
|
|
75
|
+
getDataSources: () => {
|
|
76
|
+
return dataSources;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
cesiumCustomDataSourceSpy = jest.spyOn(global.Cesium, "CustomDataSource");
|
|
80
|
+
cesiumHeadingPitchRollSpy = jest.spyOn(global.Cesium.Transforms, "headingPitchRollQuaternion");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
afterEach(() => {
|
|
84
|
+
global.Cesium = null;
|
|
85
|
+
jest.clearAllMocks();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
function checkAttributes (layer, attrs) {
|
|
89
|
+
expect(layer.get("name")).toEqual(attrs.name);
|
|
90
|
+
expect(layer.get("typ")).toEqual(attrs.typ);
|
|
91
|
+
expect(layer.get("id")).toEqual(attrs.id);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
describe("createLayer", function () {
|
|
95
|
+
it("creates a wrapper for terrain layer without map", function () {
|
|
96
|
+
const layer = entities.createLayer(attr);
|
|
97
|
+
|
|
98
|
+
checkAttributes(layer, attr);
|
|
99
|
+
});
|
|
100
|
+
it("creates a wrapper for entities layer with map and show is false", async function () {
|
|
101
|
+
attr.entities[0].show = false;
|
|
102
|
+
const layer = entities.createLayer(attr, map);
|
|
103
|
+
|
|
104
|
+
await tick();
|
|
105
|
+
|
|
106
|
+
checkAttributes(layer, attr);
|
|
107
|
+
expect(dataSourceValues.length).toEqual(1);
|
|
108
|
+
expect(dataSourceValues[0].show).toEqual(false);
|
|
109
|
+
expect(Object.keys(dataSourcesContent).length).toEqual(1);
|
|
110
|
+
expect(cesiumCustomDataSourceSpy).toHaveBeenCalledTimes(1);
|
|
111
|
+
expect(cesiumHeadingPitchRollSpy).toHaveBeenCalledTimes(1);
|
|
112
|
+
});
|
|
113
|
+
it("creates a wrapper for terrain layer with map and show not set", async function () {
|
|
114
|
+
attr.entities[0].show = undefined;
|
|
115
|
+
const layer = entities.createLayer(attr, map);
|
|
116
|
+
|
|
117
|
+
await tick();
|
|
118
|
+
|
|
119
|
+
checkAttributes(layer, attr);
|
|
120
|
+
expect(dataSourceValues.length).toEqual(1);
|
|
121
|
+
expect(dataSourceValues[0].show).toEqual(false);
|
|
122
|
+
expect(Object.keys(dataSourcesContent).length).toEqual(1);
|
|
123
|
+
expect(cesiumCustomDataSourceSpy).toHaveBeenCalledTimes(1);
|
|
124
|
+
expect(cesiumHeadingPitchRollSpy).toHaveBeenCalledTimes(1);
|
|
125
|
+
});
|
|
126
|
+
it("creates a wrapper for terrain layer with map and show is true", async function () {
|
|
127
|
+
attr.entities[0].show = true;
|
|
128
|
+
const layer = entities.createLayer(attr, map);
|
|
129
|
+
|
|
130
|
+
await tick();
|
|
131
|
+
|
|
132
|
+
checkAttributes(layer, attr);
|
|
133
|
+
expect(dataSourceValues.length).toEqual(1);
|
|
134
|
+
expect(dataSourceValues[0].show).toEqual(true);
|
|
135
|
+
expect(Object.keys(dataSourcesContent).length).toEqual(1);
|
|
136
|
+
expect(cesiumCustomDataSourceSpy).toHaveBeenCalledTimes(1);
|
|
137
|
+
expect(cesiumHeadingPitchRollSpy).toHaveBeenCalledTimes(1);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
describe("setVisible", function () {
|
|
141
|
+
let consoleWarnOrig;
|
|
142
|
+
|
|
143
|
+
beforeEach(() => {
|
|
144
|
+
consoleWarnOrig = console.warn;
|
|
145
|
+
console.warn = jest.fn();
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
afterEach(() => {
|
|
149
|
+
console.warn = consoleWarnOrig;
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("call setVisible without map shall not fail and shall do nothing", async function () {
|
|
153
|
+
attr.isSelected = false;
|
|
154
|
+
attr.entities[0].show = false;
|
|
155
|
+
const layer = entities.createLayer(attr, map);
|
|
156
|
+
|
|
157
|
+
entities.setVisible(true, attr);
|
|
158
|
+
|
|
159
|
+
await tick();
|
|
160
|
+
|
|
161
|
+
checkAttributes(layer, attr);
|
|
162
|
+
expect(dataSourceValues.length).toEqual(1);
|
|
163
|
+
expect(dataSourceValues[0].show).toEqual(false);
|
|
164
|
+
});
|
|
165
|
+
it("call setVisible without map and rawLayer shall not fail and shall do nothing", async function () {
|
|
166
|
+
attr.isSelected = false;
|
|
167
|
+
attr.entities[0].show = false;
|
|
168
|
+
const layer = entities.createLayer(attr, map);
|
|
169
|
+
|
|
170
|
+
entities.setVisible(true, null);
|
|
171
|
+
|
|
172
|
+
await tick();
|
|
173
|
+
|
|
174
|
+
checkAttributes(layer, attr);
|
|
175
|
+
expect(dataSourceValues.length).toEqual(1);
|
|
176
|
+
expect(dataSourceValues[0].show).toEqual(false);
|
|
177
|
+
});
|
|
178
|
+
it("call setVisible shall set show to true", async function () {
|
|
179
|
+
attr.isSelected = false;
|
|
180
|
+
attr.entities[0].show = false;
|
|
181
|
+
const layer = entities.createLayer(attr, map);
|
|
182
|
+
|
|
183
|
+
await tick();
|
|
184
|
+
|
|
185
|
+
expect(dataSourceValues[0].show).toEqual(false);
|
|
186
|
+
|
|
187
|
+
layer.setVisible(true, attr, map);
|
|
188
|
+
|
|
189
|
+
checkAttributes(layer, attr);
|
|
190
|
+
expect(dataSourceValues.length).toEqual(1);
|
|
191
|
+
expect(dataSourcesContent[attr.id].show).toEqual(true);
|
|
192
|
+
});
|
|
193
|
+
it("call setVisible shall only warn, if no dataSource found", async function () {
|
|
194
|
+
attr.isSelected = false;
|
|
195
|
+
attr.entities[0].show = false;
|
|
196
|
+
const layer = entities.createLayer(attr, map);
|
|
197
|
+
|
|
198
|
+
await tick();
|
|
199
|
+
|
|
200
|
+
checkAttributes(layer, attr);
|
|
201
|
+
|
|
202
|
+
attr.id = "notExist";
|
|
203
|
+
entities.setVisible(true, attr, map);
|
|
204
|
+
|
|
205
|
+
expect(dataSourceValues.length).toEqual(1);
|
|
206
|
+
expect(dataSourcesContent[attr.id]).toEqual(undefined);
|
|
207
|
+
expect(console.warn).toHaveBeenCalledTimes(1);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
describe("get", function () {
|
|
211
|
+
it("calls get for attributes", async function () {
|
|
212
|
+
const layer = entities.createLayer(attr, map);
|
|
213
|
+
|
|
214
|
+
checkAttributes(layer, attr);
|
|
215
|
+
expect(layer.get(null)).toEqual(undefined);
|
|
216
|
+
expect(layer.get(undefined)).toEqual(undefined);
|
|
217
|
+
expect(layer.get("")).toEqual(undefined);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
describe("addEntities", function () {
|
|
221
|
+
let consoleWarnOrig;
|
|
222
|
+
|
|
223
|
+
beforeEach(() => {
|
|
224
|
+
consoleWarnOrig = console.warn;
|
|
225
|
+
console.warn = jest.fn();
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
afterEach(() => {
|
|
229
|
+
console.warn = consoleWarnOrig;
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("addEntities without map shall not fail", async function () {
|
|
233
|
+
const layer = entities.createLayer(attr, map);
|
|
234
|
+
|
|
235
|
+
await tick();
|
|
236
|
+
layer.createDataSource(attr);
|
|
237
|
+
});
|
|
238
|
+
it("addEntities without rawLayer shall not fail", async function () {
|
|
239
|
+
const layer = entities.createLayer(attr, map);
|
|
240
|
+
|
|
241
|
+
await tick();
|
|
242
|
+
layer.createDataSource(null, map);
|
|
243
|
+
expect(console.warn).toHaveBeenCalledTimes(1);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("addEntities shall add entity twice", async function () {
|
|
247
|
+
attr.entities[0].show = false;
|
|
248
|
+
const layer = entities.createLayer(attr, map);
|
|
249
|
+
|
|
250
|
+
await tick();
|
|
251
|
+
|
|
252
|
+
checkAttributes(layer, attr);
|
|
253
|
+
expect(dataSourceValues.length).toEqual(1);
|
|
254
|
+
|
|
255
|
+
layer.createDataSource(attr, map);
|
|
256
|
+
expect(dataSourceValues.length).toEqual(2);
|
|
257
|
+
expect(dataSourceValues[0].show).toEqual(false);
|
|
258
|
+
expect(dataSourceValues[1].show).toEqual(false);
|
|
259
|
+
});
|
|
260
|
+
it("addEntities shall add entity and set Visible", async function () {
|
|
261
|
+
attr.entities[0].show = true;
|
|
262
|
+
const layer = entities.createLayer(attr, map);
|
|
263
|
+
|
|
264
|
+
await tick();
|
|
265
|
+
|
|
266
|
+
checkAttributes(layer, attr);
|
|
267
|
+
expect(dataSourceValues.length).toEqual(1);
|
|
268
|
+
expect(dataSourceValues[0].show).toEqual(true);
|
|
269
|
+
|
|
270
|
+
layer.createDataSource(attr, map);
|
|
271
|
+
expect(dataSourceValues.length).toEqual(2);
|
|
272
|
+
expect(dataSourceValues[0].show).toEqual(true);
|
|
273
|
+
expect(dataSourceValues[1].show).toEqual(true);
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
|
|
@@ -36,25 +36,12 @@ describe("terrain.js", function () {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
describe("createLayer", function () {
|
|
39
|
-
it("creates a wrapper for terrain layer
|
|
40
|
-
const layer = terrain.createLayer(attr);
|
|
41
|
-
|
|
42
|
-
checkAttributes(layer, attr);
|
|
43
|
-
});
|
|
44
|
-
it("creates a wrapper for terrain layer with map and not selected", function () {
|
|
45
|
-
attr.isSelected = false;
|
|
39
|
+
it("creates a wrapper for terrain layer with map", function () {
|
|
46
40
|
const layer = terrain.createLayer(attr, map);
|
|
47
41
|
|
|
48
42
|
checkAttributes(layer, attr);
|
|
49
43
|
expect(cesiumTerrainProviderSpy).toHaveBeenCalledTimes(0);
|
|
50
44
|
});
|
|
51
|
-
it("creates a wrapper for terrain layer with map and selected", function () {
|
|
52
|
-
attr.isSelected = true;
|
|
53
|
-
const layer = terrain.createLayer(attr, map);
|
|
54
|
-
|
|
55
|
-
checkAttributes(layer, attr);
|
|
56
|
-
expect(cesiumTerrainProviderSpy).toHaveBeenCalledTimes(1);
|
|
57
|
-
});
|
|
58
45
|
});
|
|
59
46
|
describe("setVisible", function () {
|
|
60
47
|
it("calls setVisible without map shall not fail", function () {
|
|
@@ -45,22 +45,15 @@ describe("tileset.js", function () {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
describe("createLayer", function () {
|
|
48
|
-
it("creates tileset layer without map
|
|
48
|
+
it("creates tileset layer without map", function () {
|
|
49
49
|
const layer = new Tileset(attr);
|
|
50
50
|
|
|
51
51
|
checkAttributes(layer, attr);
|
|
52
52
|
expect(layer.tileSet).toEqual(undefined);
|
|
53
|
+
expect(layer.tileset.show).toEqual(undefined);
|
|
53
54
|
expect(cesium3DTilesetSpy).toHaveBeenCalledTimes(1);
|
|
54
55
|
});
|
|
55
|
-
it("creates tileset
|
|
56
|
-
attr.isSelected = true;
|
|
57
|
-
const layer = new Tileset(attr, map);
|
|
58
|
-
|
|
59
|
-
checkAttributes(layer, attr);
|
|
60
|
-
expect(layer.tileset.show).toEqual(true);
|
|
61
|
-
expect(cesium3DTilesetSpy).toHaveBeenCalledTimes(1);
|
|
62
|
-
});
|
|
63
|
-
it("creates 2 tileset layers with map and selected and checks attributes", function () {
|
|
56
|
+
it("creates 2 tileset layers with map and checks attributes", function () {
|
|
64
57
|
const attr2 = {
|
|
65
58
|
id: "4003",
|
|
66
59
|
name: "name",
|
|
@@ -135,7 +135,7 @@ describe("vectorTile.js", function () {
|
|
|
135
135
|
1.3229159522920524,
|
|
136
136
|
0.6614579761460262,
|
|
137
137
|
0.2645831904584105,
|
|
138
|
-
0.
|
|
138
|
+
0.1322915952292052
|
|
139
139
|
],
|
|
140
140
|
tileSize: 512
|
|
141
141
|
},
|
|
@@ -169,4 +169,4 @@ describe("vectorTile.js", function () {
|
|
|
169
169
|
expect(featureStyle[0].getFill().getColor()).toBe("rgba(255,253,238,1)");
|
|
170
170
|
});
|
|
171
171
|
});
|
|
172
|
-
});
|
|
172
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {get as getProjection} from "ol/proj";
|
|
2
|
+
import {getWidth} from "ol/extent";
|
|
3
|
+
|
|
4
|
+
import * as wmts from "../../src/layer/wmts";
|
|
5
|
+
|
|
6
|
+
describe.only("wmts.js", function () {
|
|
7
|
+
describe("generateArrays", function () {
|
|
8
|
+
it("should fill the arrays resolutions and matrixIds with numbers", function () {
|
|
9
|
+
const size = getWidth(getProjection("EPSG:3857").getExtent()) / 256,
|
|
10
|
+
resLength = 20,
|
|
11
|
+
resolutions = new Array(resLength),
|
|
12
|
+
matrixIds = new Array(resLength);
|
|
13
|
+
|
|
14
|
+
wmts.generateArrays(resolutions, matrixIds, resLength, size);
|
|
15
|
+
|
|
16
|
+
resolutions.forEach((element, index) => {
|
|
17
|
+
expect(typeof element).toBe("number");
|
|
18
|
+
expect(resolutions[index]).toBe(size / Math.pow(2, index));
|
|
19
|
+
});
|
|
20
|
+
matrixIds.forEach((id, index) => {
|
|
21
|
+
expect(typeof id).toBe("number");
|
|
22
|
+
expect(matrixIds[index]).toBe(index);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
});
|
package/test/map.test.js
CHANGED
|
@@ -167,8 +167,41 @@ describe("map.js", function () {
|
|
|
167
167
|
const map3D = map.createMap(config, "3D");
|
|
168
168
|
|
|
169
169
|
expect(map3D.mapMode).toBe("3D");
|
|
170
|
-
|
|
170
|
+
expect(map3D.getCesiumScene().camera.getAltitude()).toBe(config.cameraParameter.altitude);
|
|
171
|
+
expect(map3D.getCesiumScene().camera.getHeading()).toBe(config.cameraParameter.heading);
|
|
172
|
+
expect(map3D.getCesiumScene().camera.getTilt()).toBe(config.cameraParameter.tilt);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
it("set the camera parameter from config under camera", function () {
|
|
176
|
+
const config = {
|
|
177
|
+
map2D: {
|
|
178
|
+
getView: () => {
|
|
179
|
+
return {
|
|
180
|
+
getProjection: () => {
|
|
181
|
+
return {getCode: () => "code"};
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
},
|
|
185
|
+
getViewport: () => {
|
|
186
|
+
return {
|
|
187
|
+
appendChild: jest.fn()
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
cameraParameter: {
|
|
192
|
+
camera: {
|
|
193
|
+
altitude: 272.3469798217454,
|
|
194
|
+
heading: -0.30858728378862876,
|
|
195
|
+
tilt: 0.9321791580603296
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
cesiumLib: "https://lib.virtualcitymap.de/v3.6.x/lib/Cesium/Cesium.js"
|
|
199
|
+
};
|
|
171
200
|
|
|
201
|
+
load3DScript(config.cesiumLib, function Loaded3DCallback () {
|
|
202
|
+
const map3D = map.createMap(config, "3D");
|
|
203
|
+
|
|
204
|
+
expect(map3D.mapMode).toBe("3D");
|
|
172
205
|
expect(map3D.getCesiumScene().camera.getAltitude()).toBe(config.cameraParameter.altitude);
|
|
173
206
|
expect(map3D.getCesiumScene().camera.getHeading()).toBe(config.cameraParameter.heading);
|
|
174
207
|
expect(map3D.getCesiumScene().camera.getTilt()).toBe(config.cameraParameter.tilt);
|