@masterportal/masterportalapi 2.1.1 → 2.4.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 +3 -0
- package/CHANGELOG.md +28 -6
- package/example/config/localGeoJSON.js +24 -24
- package/example/config/portal.json +1 -1
- package/example/config/services.json +189 -53
- package/example/index.js +79 -64
- package/package.json +2 -2
- package/src/defaults.js +17 -1
- package/src/index.js +6 -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 +174 -0
- package/src/layer/wms.js +4 -0
- package/src/layer/wmts.js +194 -0
- package/src/maps/ol/olMap.js +4 -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 +172 -0
- package/test/layer/wmts.test.js +26 -0
- package/test/map.test.js +34 -1
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import OpenLayersVectorTileLayer from "ol/layer/VectorTile";
|
|
2
|
+
import OpenLayersVectorTileSource from "ol/source/VectorTile";
|
|
3
|
+
import OpenLayersTileGrid from "ol/tilegrid/TileGrid";
|
|
4
|
+
|
|
5
|
+
import {Feature} from "ol";
|
|
6
|
+
import Polygon from "ol/geom/Polygon";
|
|
7
|
+
|
|
8
|
+
import * as vectorTile from "../../src/layer/vectorTile";
|
|
9
|
+
import {registerProjections} from "../../src/crs";
|
|
10
|
+
import defaults from "../../src/defaults";
|
|
11
|
+
|
|
12
|
+
jest.mock("../../src/rawLayerList.js", () => {
|
|
13
|
+
const original = jest.requireActual("../../src/rawLayerList.js");
|
|
14
|
+
|
|
15
|
+
original.initializeLayerList = jest.fn();
|
|
16
|
+
return original;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe("vectorTile.js", function () {
|
|
20
|
+
|
|
21
|
+
beforeAll(() => registerProjections());
|
|
22
|
+
|
|
23
|
+
const layerParams = {
|
|
24
|
+
name: "VT Test",
|
|
25
|
+
id: "VT_01",
|
|
26
|
+
url: "https://example.org"
|
|
27
|
+
},
|
|
28
|
+
tileGridParams = {
|
|
29
|
+
extent: [0, 0, 1, 1],
|
|
30
|
+
tileSize: 512,
|
|
31
|
+
minZoom: 0
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
vtStyle = {
|
|
35
|
+
"version": 8,
|
|
36
|
+
"sources": {
|
|
37
|
+
"test": {
|
|
38
|
+
"type": "vector"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"layers": [
|
|
42
|
+
{
|
|
43
|
+
"type": "fill",
|
|
44
|
+
"source": "test",
|
|
45
|
+
"source-layer": "Background",
|
|
46
|
+
"paint": {"fill-color": "rgb(255,253,238)", "fill-opacity": 1}
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
feature = new Feature({
|
|
52
|
+
geometry: new Polygon([[0, 0], [0, 1], [1, 1], [0, 0]]),
|
|
53
|
+
layer: "Background"
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe("createTileGrid", function () {
|
|
57
|
+
it("creates a ol/tilegrid/TileGrid with default values for not required parameters", function () {
|
|
58
|
+
const tileGrid = vectorTile.createTileGrid(tileGridParams);
|
|
59
|
+
|
|
60
|
+
expect(tileGrid).toBeInstanceOf(OpenLayersTileGrid);
|
|
61
|
+
expect(tileGrid.getExtent()).toEqual(tileGridParams.extent);
|
|
62
|
+
expect(tileGrid.getResolutions()).toEqual(defaults.options.map(x => x.resolution));
|
|
63
|
+
expect(tileGrid.getTileSize()).toEqual(new Array(2).fill(tileGridParams.tileSize));
|
|
64
|
+
expect(tileGrid.getMinZoom()).toBe(tileGrid.minZoom);
|
|
65
|
+
expect(tileGrid.getOrigin()).toEqual([tileGridParams.extent[0], tileGridParams.extent[3]]);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe("createLayerSource", function () {
|
|
70
|
+
it("creates a layerSource", function () {
|
|
71
|
+
const tileGrid = vectorTile.createTileGrid(tileGridParams),
|
|
72
|
+
sourceParams = {
|
|
73
|
+
tileGrid: tileGrid,
|
|
74
|
+
tileSize: tileGrid.getTileSize(),
|
|
75
|
+
zDirection: 1,
|
|
76
|
+
minZoom: 0,
|
|
77
|
+
maxZoom: 22
|
|
78
|
+
},
|
|
79
|
+
source = vectorTile.createLayerSource("https://foo.example.org", sourceParams);
|
|
80
|
+
|
|
81
|
+
expect(source).toBeInstanceOf(OpenLayersVectorTileSource);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe("createLayer", function () {
|
|
86
|
+
it("creates a vector Tile Layer", function () {
|
|
87
|
+
const layer = vectorTile.createLayer(layerParams);
|
|
88
|
+
|
|
89
|
+
expect(layer).toBeInstanceOf(OpenLayersVectorTileLayer);
|
|
90
|
+
expect(layer.getSource()).toBeInstanceOf(OpenLayersVectorTileSource);
|
|
91
|
+
expect(layer.get("name")).toEqual("VT Test");
|
|
92
|
+
expect(layer.get("id")).toEqual("VT_01");
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("should log an error when required param is missing", function () {
|
|
96
|
+
const spyConsole = jest.spyOn(console, "error").mockImplementation(() => ""),
|
|
97
|
+
layer = vectorTile.createLayer({
|
|
98
|
+
name: "VT Test",
|
|
99
|
+
id: "VT_01"
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
expect(layer).toBeUndefined();
|
|
103
|
+
expect(console.error).toHaveBeenCalled();
|
|
104
|
+
expect(spyConsole.mock.calls[0][0]).toContain("Cancelled creation of layer \"VT_01\"(VT Test) because of missing required parameters");
|
|
105
|
+
spyConsole.mockRestore();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("should apply default values for all not required ones", function () {
|
|
109
|
+
const defaultValues = { // defaults defined in services.json.md
|
|
110
|
+
zDirection: 1,
|
|
111
|
+
epsg: "EPSG:25832", // default value from config.json.md/MapView. Should be the default CRS
|
|
112
|
+
extent: [ // If not set, the portal's coordinate reference system's extent is used
|
|
113
|
+
// Note: this should be the extent of the projection but is the extent of EPSG:3857
|
|
114
|
+
// this is because in masterportalAPI is no definition of the extent of the
|
|
115
|
+
// default projection which is EPSG:25832
|
|
116
|
+
-20015077.371242613,
|
|
117
|
+
-20015077.371242613,
|
|
118
|
+
20015077.371242613,
|
|
119
|
+
20015077.371242613
|
|
120
|
+
],
|
|
121
|
+
origin: [ // if not set, the portal's coordinate reference system's top-left corner is used.
|
|
122
|
+
// Note: this should be the top left corner of the projection extent but is top left
|
|
123
|
+
// corner of extent of EPSG:3857 this is because in masterportalAPI is no
|
|
124
|
+
// definition of the extent of the default projection which is EPSG:25832
|
|
125
|
+
-20015077.371242613,
|
|
126
|
+
20015077.371242613
|
|
127
|
+
],
|
|
128
|
+
resolutions: [ // If not used, the portal's resolutions are used. (Missing default resolution definition? used default resolutions from masterportal-api)
|
|
129
|
+
66.14579761460263,
|
|
130
|
+
26.458319045841044,
|
|
131
|
+
15.874991427504629,
|
|
132
|
+
10.583327618336419,
|
|
133
|
+
5.2916638091682096,
|
|
134
|
+
2.6458319045841048,
|
|
135
|
+
1.3229159522920524,
|
|
136
|
+
0.6614579761460262,
|
|
137
|
+
0.2645831904584105,
|
|
138
|
+
0.13229159522920522
|
|
139
|
+
],
|
|
140
|
+
tileSize: 512
|
|
141
|
+
},
|
|
142
|
+
layer = vectorTile.createLayer(layerParams),
|
|
143
|
+
source = layer.getSource(),
|
|
144
|
+
tileGrid = source.getTileGrid();
|
|
145
|
+
|
|
146
|
+
expect(layer.getExtent()).toEqual(defaultValues.extent);
|
|
147
|
+
|
|
148
|
+
expect(source.getProjection().getCode()).toEqual(defaultValues.epsg);
|
|
149
|
+
|
|
150
|
+
expect(tileGrid.getExtent()).toEqual(defaultValues.extent);
|
|
151
|
+
expect(tileGrid.getOrigin()).toEqual(defaultValues.origin);
|
|
152
|
+
expect(tileGrid.getResolutions()).toEqual(defaultValues.resolutions);
|
|
153
|
+
expect(tileGrid.getTileSize()).toEqual(new Array(2).fill(defaultValues.tileSize));
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe("setStyle", function () {
|
|
158
|
+
it("should apply a given style", function () {
|
|
159
|
+
const layer = vectorTile.createLayer(layerParams);
|
|
160
|
+
|
|
161
|
+
let featureStyle = null;
|
|
162
|
+
|
|
163
|
+
vectorTile.setStyle(layer, vtStyle);
|
|
164
|
+
|
|
165
|
+
expect(typeof layer.getStyle()).toBe("function");
|
|
166
|
+
|
|
167
|
+
featureStyle = layer.getStyle()(feature, 1.3229159522920524);
|
|
168
|
+
|
|
169
|
+
expect(featureStyle[0].getFill().getColor()).toBe("rgba(255,253,238,1)");
|
|
170
|
+
});
|
|
171
|
+
});
|
|
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);
|