@masterportal/masterportalapi 2.3.0 → 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/CHANGELOG.md CHANGED
@@ -3,6 +3,15 @@
3
3
 
4
4
  The [Semantic Versioning](https://semver.org/spec/v2.0.0.html) is used.
5
5
 
6
+ ## 2.4.0 - 2022-07-06
7
+ ### Added
8
+ - Issue 776: Add 3D mode for WMTS layers.
9
+
10
+ ### Fixed
11
+ - 3D: Handling of camera parameters at olcsmap are adapted.
12
+
13
+ ---
14
+
6
15
  ## 2.3.0 - 2022-05-27
7
16
  ### Added
8
17
  - Add a new layer type WMTS.
@@ -106,15 +106,71 @@
106
106
  "zDirection": -1
107
107
  },
108
108
  {
109
- "id": "7001",
110
- "name": "BKG TopPlus Open WMTS optionsFromCapabilities",
111
- "capabilitiesUrl": "https://sgx.geodatenzentrum.de/wmts_topplus_open/1.0.0/WMTSCapabilities.xml",
109
+ "id":"7001",
110
+ "name":"TopPlusOpen",
111
+ "capabilitiesUrl":"https://sgx.geodatenzentrum.de/wmts_topplus_open/1.0.0/WMTSCapabilities.xml",
112
+ "optionsFromCapabilities":true,
113
+ "typ":"WMTS",
114
+ "layers":"web"
115
+ },
116
+ {
117
+ "id": "7002",
118
+ "name": "EOC Basemap",
119
+ "capabilitiesUrl": "https://tiles.geoservice.dlr.de/service/wmts?SERVICE=WMTS&REQUEST=GetCapabilities",
112
120
  "typ": "WMTS",
113
121
  "optionsFromCapabilities": true,
114
- "layers": "web",
115
- "visibility": true,
116
- "maxScale": "5000000",
117
- "tileMatrixSet": "EU_EPSG_25832_TOPPLUS"
122
+ "layers": "eoc:basemap"
123
+ },
124
+ {
125
+ "id": "7003",
126
+ "name": "Geoland Basemap",
127
+ "urls": [
128
+ "https://maps1.wien.gv.at/basemap/geolandbasemap/{Style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png",
129
+ "https://maps2.wien.gv.at/basemap/geolandbasemap/{Style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png",
130
+ "https://maps3.wien.gv.at/basemap/geolandbasemap/{Style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png",
131
+ "https://maps4.wien.gv.at/basemap/geolandbasemap/{Style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png",
132
+ "https://maps.wien.gv.at/basemap/geolandbasemap/{Style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png"
133
+ ],
134
+ "typ": "WMTS",
135
+ "layer": "geolandbasemap",
136
+ "version": "1.0.0",
137
+ "format": "image/png",
138
+ "style": "normal",
139
+ "transparent": false,
140
+ "tileSize": "256",
141
+ "minScale": "0",
142
+ "maxScale": "2500000",
143
+ "tileMatrixSet": "google3857",
144
+ "matrixSizes": [
145
+ [1, 1], [2, 2],
146
+ [4, 4], [8, 8],
147
+ [16, 16], [32, 32],
148
+ [64, 64], [128, 128],
149
+ [256, 256], [512, 512],
150
+ [1024, 1024], [2048, 2048],
151
+ [4096, 4096], [8192, 8192],
152
+ [16384, 16384], [32768, 32768],
153
+ [65536, 65536], [131072, 131072],
154
+ [262144, 262144], [524288, 524288]
155
+ ],
156
+ "coordinateSystem": "EPSG:3857",
157
+ "layerAttribution": "nicht vorhanden",
158
+ "legend": false,
159
+ "cache": true,
160
+ "wrapX": true,
161
+ "origin": [
162
+ -20037508.3428,
163
+ 20037508.3428
164
+ ],
165
+ "scales": [
166
+ 559082264.029, 279541132.015, 139770566.007, 69885283.0036,
167
+ 34942641.5018, 17471320.7509, 8735660.37545, 4367830.18773,
168
+ 2183915.09386, 1091957.54693, 45978.773466, 272989.386733,
169
+ 136494.693366, 68247.3466832, 34123.6733416, 17061.8366708,
170
+ 8530.91833540, 4265.45916770, 2132.72958385, 1066.36479193
171
+ ],
172
+ "resLength": "20",
173
+ "requestEncoding": "REST"
118
174
  },
119
175
  {
120
176
  "id": "4003",
package/example/index.js CHANGED
@@ -220,4 +220,6 @@ map2D.getLayers().forEach(layer => {
220
220
  map2D.removeLayer(layer);
221
221
  });
222
222
  window.mpapi.map.addLayer("7001");
223
+ window.mpapi.map.addLayer("7002");
224
+ window.mpapi.map.addLayer("7003");
223
225
  // */
package/package.json CHANGED
@@ -1,62 +1,62 @@
1
- {
2
- "name": "@masterportal/masterportalapi",
3
- "author": "Implementierungspartnerschaft Masterportal <info@masterportal.org> (https://www.masterportal.org)",
4
- "version": "2.3.0",
5
- "license": "MIT",
6
- "description": "Basic functions of the Masterportal as api",
7
- "repository": {
8
- "type": "git",
9
- "url": "git+https://bitbucket.org/geowerkstatt-hamburg/masterportalapi.git"
10
- },
11
- "main": "src/index.js",
12
- "scripts": {
13
- "test": "jest .test.js --config ./jest.config.js --collectCoverage",
14
- "test:trace": "node --trace-warnings node_modules/jest/bin/jest.js ./test/layer/wfs.test.js --config ./jest.config.js",
15
- "test:watch": "jest .test.js --config ./jest.config.js --watch",
16
- "example": "parcel example/index.html",
17
- "generate-jsdoc": "jsdoc ./src -r -d ./docs/ -R ./README.md -c jsdoc.json",
18
- "prePushHook": "eslint --max-warnings 0 \"./**/*.js\" && npm run test",
19
- "prepare": "husky install"
20
- },
21
- "dependencies": {
22
- "core-js": "^3.16.1",
23
- "ol": "6.14.1",
24
- "olcs": "^2.13.0",
25
- "proj4": "^2.7.5",
26
- "xml2js": "^0.4.23"
27
- },
28
- "devDependencies": {
29
- "@babel/core": "^7.16.7",
30
- "@babel/plugin-transform-modules-commonjs": "^7.16.8",
31
- "@parcel/transformer-sass": "^2.2.0",
32
- "buffer": "^6.0.3",
33
- "canvas": "^2.8.0",
34
- "eslint": "^7.32.0",
35
- "events": "^3.3.0",
36
- "husky": "^7.0.1",
37
- "jest": "^27.4.0",
38
- "jest-canvas-mock": "^2.3.1",
39
- "jsdoc": "^3.6.7",
40
- "parcel": "^2.2.0",
41
- "process": "^0.11.10",
42
- "regenerator-runtime": "0.13.9",
43
- "sass": "^1.37.5",
44
- "stream-browserify": "^3.0.0",
45
- "timers-browserify": "^2.0.12"
46
- },
47
- "peerDependencies": {
48
- "cesium": "^1.88.0"
49
- },
50
- "engines": {
51
- "node": "^16.13.2",
52
- "npm": "^8.1.2"
53
- },
54
- "homepage": "https://bitbucket.org/geowerkstatt-hamburg/masterportalapi#readme",
55
- "directories": {
56
- "example": "example",
57
- "test": "test"
58
- },
59
- "bugs": {
60
- "url": "https://bitbucket.org/geowerkstatt-hamburg/masterportalapi/issues"
61
- }
62
- }
1
+ {
2
+ "name": "@masterportal/masterportalapi",
3
+ "author": "Implementierungspartnerschaft Masterportal <info@masterportal.org> (https://www.masterportal.org)",
4
+ "version": "2.4.0",
5
+ "license": "MIT",
6
+ "description": "Basic functions of the Masterportal as api",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://bitbucket.org/geowerkstatt-hamburg/masterportalapi.git"
10
+ },
11
+ "main": "src/index.js",
12
+ "scripts": {
13
+ "test": "jest .test.js --config ./jest.config.js --collectCoverage",
14
+ "test:trace": "node --trace-warnings node_modules/jest/bin/jest.js ./test/layer/wfs.test.js --config ./jest.config.js",
15
+ "test:watch": "jest .test.js --config ./jest.config.js --watch",
16
+ "example": "parcel example/index.html",
17
+ "generate-jsdoc": "jsdoc ./src -r -d ./docs/ -R ./README.md -c jsdoc.json",
18
+ "prePushHook": "eslint --max-warnings 0 \"./**/*.js\" && npm run test",
19
+ "prepare": "husky install"
20
+ },
21
+ "dependencies": {
22
+ "core-js": "^3.16.1",
23
+ "ol": "6.14.1",
24
+ "olcs": "^2.13.0",
25
+ "proj4": "^2.7.5",
26
+ "xml2js": "^0.4.23"
27
+ },
28
+ "devDependencies": {
29
+ "@babel/core": "^7.16.7",
30
+ "@babel/plugin-transform-modules-commonjs": "^7.16.8",
31
+ "@parcel/transformer-sass": "^2.2.0",
32
+ "buffer": "^6.0.3",
33
+ "canvas": "^2.8.0",
34
+ "eslint": "^7.32.0",
35
+ "events": "^3.3.0",
36
+ "husky": "^7.0.1",
37
+ "jest": "^27.4.0",
38
+ "jest-canvas-mock": "^2.3.1",
39
+ "jsdoc": "^3.6.7",
40
+ "parcel": "^2.2.0",
41
+ "process": "^0.11.10",
42
+ "regenerator-runtime": "0.13.9",
43
+ "sass": "^1.37.5",
44
+ "stream-browserify": "^3.0.0",
45
+ "timers-browserify": "^2.0.12"
46
+ },
47
+ "peerDependencies": {
48
+ "cesium": "^1.88.0"
49
+ },
50
+ "engines": {
51
+ "node": "^16.13.2",
52
+ "npm": "^8.1.2"
53
+ },
54
+ "homepage": "https://bitbucket.org/geowerkstatt-hamburg/masterportalapi#readme",
55
+ "directories": {
56
+ "example": "example",
57
+ "test": "test"
58
+ },
59
+ "bugs": {
60
+ "url": "https://bitbucket.org/geowerkstatt-hamburg/masterportalapi/issues"
61
+ }
62
+ }
@@ -114,9 +114,10 @@ function addEntities (rawLayer, dataSource) {
114
114
  * @param {string} [rawLayer.id] the id of the layer
115
115
  * @param {string} [rawLayer.entities] array of entities to add
116
116
  * @param {OLCesium} map ol cesium map
117
- * @returns {void}
117
+ * @param {function} callback to execute after datasource is added to map and entities are added
118
+ * @returns {*} null or the return-value of the callback
118
119
  */
119
- export function createDataSource (rawLayer, map) {
120
+ export function createDataSource (rawLayer, map, callback) {
120
121
  if (!rawLayer) {
121
122
  console.warn("Cannot add entities to rawLayer which is null!");
122
123
  }
@@ -128,12 +129,20 @@ export function createDataSource (rawLayer, map) {
128
129
  dataSource = new Cesium.CustomDataSource(rawLayer.id);
129
130
  dataSources.add(dataSource).then(function (addedDataSource) {
130
131
  addEntities(rawLayer, addedDataSource, map);
132
+ if (callback) {
133
+ return callback();
134
+ }
135
+ return null;
131
136
  });
132
137
  }
133
138
  else {
134
139
  addEntities(rawLayer, dataSource, map);
140
+ if (callback) {
141
+ return callback();
142
+ }
135
143
  }
136
144
  }
145
+ return null;
137
146
  }
138
147
 
139
148
 
@@ -5,6 +5,7 @@ import olLayerGroup from "ol/layer/Group.js";
5
5
  import {getUid} from "olcs/util.js";
6
6
  import TileWMS from "ol/source/TileWMS.js";
7
7
  import ImageWMS from "ol/source/ImageWMS.js";
8
+ import WMTS from "ol/source/WMTS.js";
8
9
  import olcsAbstractSynchronizer from "olcs/AbstractSynchronizer.js";
9
10
  import olcsCore from "olcs/core.js";
10
11
  import {Tile, Image as ImageLayer} from "ol/layer.js";
@@ -116,6 +117,17 @@ class WMSRasterSynchronizer extends olcsAbstractSynchronizer {
116
117
  else if (source instanceof StaticImageSource) {
117
118
  provider = this.createProviderForStaticImageSource(source);
118
119
  }
120
+ else if (source instanceof WMTS) {
121
+ provider = new Cesium.WebMapTileServiceImageryProvider({
122
+ url: source.getUrls()[0],
123
+ format: source.getFormat(),
124
+ layer: source.getLayer(),
125
+ style: source.getStyle(),
126
+ tileMatrixSetID: source.getMatrixSet(),
127
+ tileMatrixLabels: source.getTileGrid().getMatrixIds(),
128
+ credit: source.getAttributions()
129
+ });
130
+ }
119
131
  else {
120
132
  console.warn("Sources other than TileImage are currently not supported.");
121
133
  return null;
@@ -20,7 +20,9 @@ export function setCesiumSceneParams (scene, params) {
20
20
 
21
21
  if (typeof paramValue === "object") {
22
22
  Object.keys(paramValue).forEach(paramSubKey => {
23
- scene[paramKey][paramSubKey] = paramValue[paramSubKey];
23
+ if (paramSubKey !== "heading" && paramSubKey !== "tilt" && paramSubKey !== "altitude") {
24
+ scene[paramKey][paramSubKey] = paramValue[paramSubKey];
25
+ }
24
26
  });
25
27
  }
26
28
  else {
@@ -28,6 +30,71 @@ export function setCesiumSceneParams (scene, params) {
28
30
  }
29
31
  });
30
32
  }
33
+ /**
34
+ * Sets the camera parameters either from config or from an trigger.
35
+ * @param {Object} params Params.
36
+ * @param {Object} map3D olcs map.
37
+ * @param {Cesium} cesium cesium.
38
+ * @returns {void}
39
+ */
40
+ export function setCameraParameter (params, map3D, cesium) {
41
+ let camera,
42
+ destination,
43
+ orientation,
44
+ heading;
45
+
46
+ if (params && map3D) {
47
+ if (typeof params.heading !== "undefined") {
48
+ heading = parseFloat(params.heading);
49
+ }
50
+ else if (typeof params.camera?.heading !== "undefined") {
51
+ heading = parseFloat(params.camera?.heading);
52
+ }
53
+ // if the cameraPosition is given, directly set the cesium camera position, otherwise use olcesium Camera
54
+ if (params.cameraPosition) {
55
+ camera = map3D.getCesiumScene().camera;
56
+ destination = cesium.Cartesian3.fromDegrees(params.cameraPosition[0], params.cameraPosition[1], params.cameraPosition[2]);
57
+ orientation = {
58
+ heading: cesium.Math.toRadians(heading),
59
+ pitch: cesium.Math.toRadians(parseFloat(params.pitch)),
60
+ roll: cesium.Math.toRadians(parseFloat(params.roll))
61
+ };
62
+
63
+ camera.setView({
64
+ destination,
65
+ orientation
66
+ });
67
+ }
68
+ else {
69
+ let tilt,
70
+ altitude;
71
+
72
+ if (typeof params.tilt !== "undefined") {
73
+ tilt = parseFloat(params.tilt);
74
+ }
75
+ else if (typeof params.camera?.tilt !== "undefined") {
76
+ tilt = parseFloat(params.camera?.tilt);
77
+ }
78
+ if (typeof params.altitude !== "undefined") {
79
+ altitude = parseFloat(params.altitude);
80
+ }
81
+ else if (typeof params.camera?.altitude !== "undefined") {
82
+ altitude = parseFloat(params.camera?.altitude);
83
+ }
84
+ camera = map3D.getCamera();
85
+
86
+ if (tilt) {
87
+ camera.setTilt(tilt);
88
+ }
89
+ if (heading) {
90
+ camera.setHeading(heading);
91
+ }
92
+ if (altitude) {
93
+ camera.setAltitude(altitude);
94
+ }
95
+ }
96
+ }
97
+ }
31
98
 
32
99
  /**
33
100
  * Creates a 3D-map.
@@ -52,52 +119,12 @@ export function createMap (settings) {
52
119
  setCesiumSceneParams(map3D.getCesiumScene(), defaults.sceneOptions);
53
120
  if (settings?.cesiumParameter) {
54
121
  setCesiumSceneParams(map3D.getCesiumScene(), settings.cesiumParameter);
122
+ setCameraParameter(settings.cesiumParameter, map3D, Cesium);
55
123
  }
56
124
 
57
125
  return map3D;
58
126
  }
59
127
 
60
- /**
61
- * Sets the camera parameters either from config or from an trigger.
62
- * @param {Object} params Params.
63
- * @param {Object} map3D olcs map.
64
- * @param {Cesium} cesium cesium.
65
- * @returns {void}
66
- */
67
- export function setCameraParameter (params, map3D, cesium) {
68
- let camera,
69
- destination,
70
- orientation;
71
-
72
- // if the cameraPosition is given, directly set the cesium camera position, otherwise use olcesium Camera
73
- if (map3D && params.cameraPosition) {
74
- camera = map3D.getCesiumScene().camera;
75
- destination = cesium.Cartesian3.fromDegrees(params.cameraPosition[0], params.cameraPosition[1], params.cameraPosition[2]);
76
- orientation = {
77
- heading: cesium.Math.toRadians(parseFloat(params.heading)),
78
- pitch: cesium.Math.toRadians(parseFloat(params.pitch)),
79
- roll: cesium.Math.toRadians(parseFloat(params.roll))
80
- };
81
-
82
- camera.setView({
83
- destination,
84
- orientation
85
- });
86
- }
87
- else if (map3D !== undefined && params !== null) {
88
- camera = map3D.getCamera();
89
- if (params?.tilt) {
90
- camera.setTilt(parseFloat(params.tilt));
91
- }
92
- if (params?.heading) {
93
- camera.setHeading(parseFloat(params.heading));
94
- }
95
- if (params?.altitude) {
96
- camera.setAltitude(parseFloat(params.altitude));
97
- }
98
- }
99
- }
100
-
101
128
  /**
102
129
  * Reacts to 3D click event in cesium scene.
103
130
  * @param {Event} event The cesium event.
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
- map.setCameraParameter(config.cameraParameter, map3D, config.cesiumLib);
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);