@masterportal/masterportalapi 2.19.2 → 2.21.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,11 +3,39 @@
3
3
 
4
4
  The [Semantic Versioning](https://semver.org/spec/v2.0.0.html) is used.
5
5
 
6
+ ## 2.21.0 - 2023-07-20
7
+ ### Added
8
+ - VectorStyle: Add Styling rules for Geoemtries of type `Circle`.
9
+ - Add Styling and zIndex to draw interactions and improve the draw behavior.
10
+
11
+ ### Changed
12
+ - Changed peerDependency from cesium 1.106.0 to @cesium/engine 2.4.1.
13
+
14
+ ---
15
+
16
+ ## 2.20.0 - 2023-06-30
17
+ ### Added
18
+ - Add draw interaction for interactive and static geometry types.
19
+ - WFS: Added function to load wfs features manually.
20
+
21
+ ### Changed
22
+ - The following packages have been updated:
23
+ - dependencies:
24
+ - ol: 7.3.0 to 7.4.0
25
+ - cesium: 1.95.0 to 1.106.0
26
+ - The examples in example/index.js are updated.
27
+
28
+ ### Fixed
29
+ - VectorStyle: fixed several bugs of multiple geometries with styling rules.
30
+
31
+ ---
32
+
6
33
  ## 2.19.2 - 2023-06-12
7
34
  ### Fixed
8
35
  - VectorStyle of multiple geometries with styling rules does not fail on not existing style.
9
36
 
10
37
  ---
38
+
11
39
  ## 2.19.1 - 2023-06-02
12
40
  ### Changed
13
41
  - Exports in src/layer/wmts.js changed to export default {} to provide ES-Syntax.
@@ -135,32 +135,53 @@
135
135
  },
136
136
  {
137
137
  "id": "6001",
138
- "name": "ADV (EPSG:25832)",
139
- "url": "https://dev.adv-smart.de/tiles/smarttiles_de_UTM32_dev/{z}/{x}/{y}.pbf",
140
- "epsg": "EPSG:25832",
138
+ "name": "ArcGIS VectorTile",
139
+ "shortname": "VectorTile",
141
140
  "typ": "VectorTile",
141
+ "visibility": false,
142
+ "preview": {
143
+ "src": "./resources/vectorTile.png"
144
+ },
145
+ "gfiAttributes": "showAll",
146
+ "url": "https://test.geoportal-hamburg.de/vt/esri/tile/{z}/{y}/{x}.pbf",
147
+ "epsg": "EPSG:25832",
142
148
  "extent": [
143
- -46133.17,
144
- 5048875.26857567,
145
- 1206211.10142433,
146
- 6301219.54000000
149
+ 441336.2209999999,
150
+ 5915995,
151
+ 594002,
152
+ 5986767.56699999981
153
+ ],
154
+ "origin": [
155
+ -9497963.94293634221,
156
+ 9997963.94293634221
147
157
  ],
148
158
  "resolutions": [
149
- 4891.96981025128,
150
- 2445.98490512564,
151
- 1222.99245256282,
152
- 611.496226281410,
153
- 305.748113140705,
154
- 152.874056570353,
155
- 76.4370282851763,
156
- 38.2185141425881,
157
- 19.1092570712941,
158
- 9.55462853564703,
159
- 4.77731426782352,
160
- 2.38865713391176
159
+ 39054.5466520950868,
160
+ 19527.2733260475434,
161
+ 9763.63666302377169,
162
+ 4881.81833151188584,
163
+ 2440.90916575594292,
164
+ 1220.45458287797146,
165
+ 610.227291438985731,
166
+ 305.113645719492865,
167
+ 152.556822859746433,
168
+ 76.2784114298732163,
169
+ 38.1392057149366082,
170
+ 19.0696028574683041,
171
+ 9.534801428734152,
172
+ 4.767400714367076,
173
+ 2.383700357183538,
174
+ 1.191850178591769
161
175
  ],
162
- "tileSize": 256,
163
- "zDirection": -1
176
+ "tileSize": 512,
177
+ "vtStyles": [
178
+ {
179
+ "id": "VectorTile_STYLE",
180
+ "name": "Test",
181
+ "url": "https://test.geoportal-hamburg.de/vt/esri/resources/styles/root.json",
182
+ "defaultStyle": true
183
+ }
184
+ ]
164
185
  },
165
186
  {
166
187
  "id": "7001",
package/example/index.js CHANGED
@@ -18,6 +18,7 @@ function errorCallback (errorEvent) {
18
18
  console.error("This is an error event:", errorEvent);
19
19
  }
20
20
 
21
+ // Definitions:
21
22
  //* Add elements to window to play with API in console
22
23
  window.mpapi = {
23
24
  ...mpapi,
@@ -45,12 +46,12 @@ const hamburgServicesUrl = "https://geodienste.hamburg.de/services-internet.json
45
46
  // eslint-disable-next-line func-style
46
47
  getWfsStyleFunction = function () {
47
48
  const styleId = "8712",
48
- olLayer = window.mpapi.map.getLayers().getArray().find((element) => element.get("id") === "8712"),
49
- source = olLayer.getSource(),
49
+ olLayer = window.mpapi.map?.getLayers().getArray().find((element) => element.get("id") === "8712"),
50
+ source = olLayer?.getSource(),
50
51
  styleObject = styleList.returnStyleObject(styleId);
51
52
  let isClusterFeature = false;
52
53
 
53
- if (styleObject !== undefined) {
54
+ if (styleObject !== undefined && source !== undefined) {
54
55
  source.on("featuresloadend", event => {
55
56
  event.features.forEach(element => {
56
57
  isClusterFeature = false;
@@ -61,6 +62,9 @@ const hamburgServicesUrl = "https://geodienste.hamburg.de/services-internet.json
61
62
  };
62
63
  let map2D = null;
63
64
 
65
+
66
+ // Examples:
67
+
64
68
  /* VectorStyle example */
65
69
  // Example for using the vectorStyle that is now implemented in the masterportalAPI.
66
70
  // Hardcoded to show the school layer "8712" as a wfs and "1534" as wfs with webgl renderer.
@@ -74,70 +78,8 @@ styleList.initializeStyleList({}, config, config.layers, undefined, (currentStyl
74
78
  return currentStyleList;
75
79
  });
76
80
 
77
- // */
78
81
  //* Cleans up map before it is re-rendered (happens on every save during dev mode)
79
82
  document.getElementById(portalConfig.target).innerHTML = "";
80
- // add a click-listener to button, that creates a 3D-map on click
81
- document.getElementById("enable").addEventListener("click", function () {
82
- if (window.mpapi.map2D === null) {
83
- window.mpapi.map2D = window.mpapi.map;
84
- }
85
-
86
- if (window.mpapi.map.mapMode === "3D") {
87
- window.mpapi.map.setEnabled(false);
88
- window.mpapi.map = window.mpapi.map2D;
89
- window.mpapi.map.getView().setRotation(0);
90
- document.getElementById("layer-visibility").style.display = "none";
91
- }
92
- else {
93
- const lib = portalConfig.cesiumLib ? portalConfig.cesiumLib : "https://geoportal-hamburg.de/mastercode/cesium/1_99/index.js";
94
-
95
- document.getElementById("layer-visibility").style.display = "block";
96
-
97
- load3DScriptModule.load3DScript(lib, function Loaded3DCallback () {
98
- let tilesetLayer = null;
99
-
100
- const settings3D = {
101
- map2D: window.mpapi.map2D,
102
- // set some options to Cesium scene
103
- cesiumParameter: {
104
- fxaa: true,
105
- globe: {
106
- enableLighting: true,
107
- maximumScreenSpaceError: 2,
108
- tileCacheSize: 20
109
- }
110
- }
111
- },
112
- map3D = mapsAPI.map.createMap(settings3D, "3D"),
113
- rawLayerTerrain = rawLayerList.getLayerWhere({id: "4001"}),
114
- rawLayerTileset = rawLayerList.getLayerWhere({id: "4002"}),
115
- rawLayerEntities = rawLayerList.getLayerWhere({id: "4003"});
116
-
117
- window.mpapi.map = map3D;
118
- tilesetLayer = new mpapi.Tileset(rawLayerTileset, window.mpapi.map);
119
- tilesetLayer.setVisible(true, window.mpapi.map);
120
-
121
- // entities are 2 simple buildings in the park 'planten und blomen' near Tiergartenstraße
122
- mpapi.entities.createLayer(rawLayerEntities, window.mpapi.map);
123
- // mpapi.entities.setVisible(true, rawLayerEntities, window.mpapi.map);
124
-
125
- mpapi.terrain.createLayer(rawLayerTerrain, window.mpapi.map);
126
- mpapi.terrain.setVisible(true, rawLayerTerrain, window.mpapi.map);
127
-
128
- window.mpapi.map.setEnabled(true);
129
- });
130
- }
131
- });
132
-
133
- // add a click-listener to button, that hides background layer in 3d
134
- document.getElementById("layer-visibility").addEventListener("click", function () {
135
- map2D.getLayers().forEach(layer => {
136
- map2D.removeLayer(layer);
137
- });
138
- });
139
-
140
- map2D = mapsAPI.map.createMap(config, "2D", {errorCallback});
141
83
 
142
84
  //* geojson styling function call to override default styling and special wfs styling
143
85
  mpapi.geojson.setCustomStyles({
@@ -167,7 +109,6 @@ const styleWfs = function (feature, resolution) {
167
109
  };
168
110
 
169
111
  services.find(({id}) => id === "3001").style = styleWfs;
170
- // */
171
112
 
172
113
 
173
114
  // eslint-disable-next-line
@@ -187,6 +128,8 @@ const styleOaf = function (feature, resolution) {
187
128
  services.find(({id}) => id === "5001").style = styleOaf;
188
129
 
189
130
  //* SYNCHRONOUS EXAMPLE: layerConf is known
131
+ // /*
132
+ map2D = mapsAPI.map.createMap(config, "2D", {errorCallback});
190
133
  window.mpapi.map = map2D;
191
134
 
192
135
  ["2001", "2002", "1002", "3001", "5001"].forEach(id => window.mpapi.map.addLayer(id, {errorCallback}));
@@ -204,7 +147,8 @@ services
204
147
 
205
148
  // */
206
149
 
207
- /* ASYNCHRONOUS EXAMPLE 1: work with layerConf callback
150
+ //* ASYNCHRONOUS EXAMPLE 1: work with layerConf callback (for testing comment out SYNCHRONOUS EXAMPLE)
151
+ /*
208
152
  document.getElementById("enable").style.display = "none";
209
153
  mpapi.rawLayerList.initializeLayerList(hamburgServicesUrl,
210
154
  conf => {
@@ -213,49 +157,34 @@ mpapi.rawLayerList.initializeLayerList(hamburgServicesUrl,
213
157
  layerConf: conf,
214
158
  layers: null
215
159
  }, "2D");
216
- ["6357", "6074"].forEach(id => window.mpapi.map.addLayer(id));
160
+ ["23420", "6074"].forEach(id => window.mpapi.map.addLayer(id));
217
161
  });
218
- //*/
162
+ */
219
163
 
220
- /* ASYNCHRONOUS EXAMPLE 2: work with createMap callback
164
+ //* ASYNCHRONOUS EXAMPLE 2: work with createMap callback (for testing comment out SYNCHRONOUS EXAMPLE)
165
+ /*
221
166
  document.getElementById("enable").style.display = "none";
222
167
  window.mpapi.map = mapsAPI.map.createMap({
223
168
  ...portalConfig, layerConf: hamburgServicesUrl, layers: [
224
- {id: "6357"},
169
+ {id: "23420"},
225
170
  {id: "453", transparency: 50}
226
171
  ]}, "2D",
227
172
  {
228
173
  callback: () => ["6074"].forEach(id => window.mpapi.map.addLayer(id))
229
174
  });
230
- //*/
231
-
232
- /* SEARCH FUNCTION EXAMPLE
233
- // You may e.g. copy this code to the browser's console to run a search.
234
-
235
- window.mpapi.search("Eiffe", {
236
- map: window.mpapi.map,
237
- zoom: true,
238
- zoomToParams: {duration: 1000, maxZoom: 8},
239
- searchStreets: true
240
- }).then(x => console.log(x)).catch(e => console.error(e));
241
-
242
- window.mpapi.search("Mümmelmannsberg 72", {
243
- map: window.mpapi.map,
244
- zoom: true,
245
- zoomToParams: {duration: 1000, maxZoom: 8},
246
- searchAddress: true
247
- }).then(x => console.log(x)).catch(e => console.error(e));
175
+ */
248
176
 
249
- //*/
250
177
 
251
178
  /* VECTOR TILE EXAMPLE */
252
179
  /*
253
180
  document.getElementById("enable").style.display = "none";
254
- map2D.getLayers().forEach(layer => {
255
- map2D.removeLayer(layer);
181
+ window.mpapi.map = mapsAPI.map.createMap(config, "2D", {errorCallback});
182
+
183
+ window.mpapi.map.getLayers().forEach(layer => {
184
+ window.mpapi.map.removeLayer(layer);
256
185
  });
257
186
 
258
- const vtStyleUrl = "https://dev.adv-smart.de/styles/playground/masterportal_test1.json";
187
+ const vtStyleUrl = "https://test.geoportal-hamburg.de/vt/esri/resources/styles/root.json";
259
188
 
260
189
  fetch(vtStyleUrl)
261
190
  .then(response => response.json())
@@ -264,20 +193,105 @@ fetch(vtStyleUrl)
264
193
 
265
194
  mpapi.vectorTile.setStyle(vtLayer, style, vtStyleUrl);
266
195
  });
267
- //*/
196
+ */
268
197
 
269
198
  /* WMTS example */
270
199
  /*
271
- map2D.getLayers().forEach(layer => {
272
- map2D.removeLayer(layer);
200
+ window.mpapi.map = mapsAPI.map.createMap(config, "2D", {errorCallback});
201
+
202
+ window.mpapi.map.getLayers().forEach(layer => {
203
+ window.mpapi.map.removeLayer(layer);
273
204
  });
274
205
  window.mpapi.map.addLayer("7001");
275
206
  window.mpapi.map.addLayer("7002");
276
207
  window.mpapi.map.addLayer("7003");
277
- */
208
+ //*/
278
209
 
279
210
  /* VectorStyle example */
280
211
  // Example for using the vectorStyle that is now implemented in the masterportalAPI.
281
212
  // Apply style to layer "8172"
282
213
  // mirrors behavior of Masterportal styling
283
214
  getWfsStyleFunction();
215
+
216
+
217
+ /* SEARCH FUNCTION EXAMPLE
218
+ // You may e.g. copy this code to the browser's console to run a search.
219
+
220
+ window.mpapi.search("Eiffe", {
221
+ map: window.mpapi.map,
222
+ zoom: true,
223
+ zoomToParams: {duration: 1000, maxZoom: 8},
224
+ searchStreets: true
225
+ }).then(x => console.log(x)).catch(e => console.error(e));
226
+
227
+ window.mpapi.search("Mümmelmannsberg 72", {
228
+ map: window.mpapi.map,
229
+ zoom: true,
230
+ zoomToParams: {duration: 1000, maxZoom: 8},
231
+ searchAddress: true
232
+ }).then(x => console.log(x)).catch(e => console.error(e));
233
+
234
+ //*/
235
+
236
+
237
+ // Add 3D functionality to the example:
238
+
239
+ // add a click-listener to button, that creates a 3D-map on click
240
+ document.getElementById("enable").addEventListener("click", function () {
241
+ if (window.mpapi.map2D === null) {
242
+ window.mpapi.map2D = window.mpapi.map;
243
+ }
244
+
245
+ if (window.mpapi.map.mapMode === "3D") {
246
+ window.mpapi.map.setEnabled(false);
247
+ window.mpapi.map = window.mpapi.map2D;
248
+ window.mpapi.map.getView().setRotation(0);
249
+ document.getElementById("layer-visibility").style.display = "none";
250
+ }
251
+ else {
252
+ const lib = portalConfig.cesiumLib ? portalConfig.cesiumLib : "https://geoportal-hamburg.de/mastercode/cesium/1_99/index.js";
253
+
254
+ document.getElementById("layer-visibility").style.display = "block";
255
+
256
+ load3DScriptModule.load3DScript(lib, function Loaded3DCallback () {
257
+ let tilesetLayer = null;
258
+
259
+ const settings3D = {
260
+ map2D: window.mpapi.map2D,
261
+ // set some options to Cesium scene
262
+ cesiumParameter: {
263
+ fxaa: true,
264
+ globe: {
265
+ enableLighting: true,
266
+ maximumScreenSpaceError: 2,
267
+ tileCacheSize: 20
268
+ }
269
+ }
270
+ },
271
+ map3D = mapsAPI.map.createMap(settings3D, "3D"),
272
+ rawLayerTerrain = rawLayerList.getLayerWhere({id: "4001"}),
273
+ rawLayerTileset = rawLayerList.getLayerWhere({id: "4002"}),
274
+ rawLayerEntities = rawLayerList.getLayerWhere({id: "4003"});
275
+
276
+ window.mpapi.map = map3D;
277
+ tilesetLayer = new mpapi.Tileset(rawLayerTileset, window.mpapi.map);
278
+ tilesetLayer.setVisible(true, window.mpapi.map);
279
+
280
+ // entities are 2 simple buildings in the park 'planten und blomen' near Tiergartenstraße
281
+ mpapi.entities.createLayer(rawLayerEntities, window.mpapi.map);
282
+ // mpapi.entities.setVisible(true, rawLayerEntities, window.mpapi.map);
283
+
284
+ mpapi.terrain.createLayer(rawLayerTerrain, window.mpapi.map);
285
+ mpapi.terrain.setVisible(true, rawLayerTerrain, window.mpapi.map);
286
+
287
+ window.mpapi.map.setEnabled(true);
288
+ });
289
+ }
290
+ });
291
+
292
+ // add a click-listener to button, that hides background layer in 3d
293
+ document.getElementById("layer-visibility").addEventListener("click", function () {
294
+ map2D.getLayers().forEach(layer => {
295
+ map2D.removeLayer(layer);
296
+ });
297
+ });
package/jest.setup.js CHANGED
@@ -1,5 +1,20 @@
1
1
  import "regenerator-runtime/runtime";
2
2
 
3
+ class Worker {
4
+ constructor (stringUrl) {
5
+ this.url = stringUrl;
6
+ this.onmessage = () => {
7
+ // empty
8
+ };
9
+ }
10
+
11
+ postMessage (msg) {
12
+ this.onmessage(msg);
13
+ }
14
+ }
15
+ // a mock for web worker
16
+ window.Worker = Worker;
17
+
3
18
  window.URL.createObjectURL = function () {
4
19
  // empty
5
20
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@masterportal/masterportalapi",
3
3
  "author": "Implementierungspartnerschaft Masterportal <info@masterportal.org> (https://www.masterportal.org)",
4
- "version": "2.19.2",
4
+ "version": "2.21.0",
5
5
  "license": "MIT",
6
6
  "description": "Basic functions of the Masterportal as api",
7
7
  "repository": {
@@ -21,7 +21,7 @@
21
21
  "dependencies": {
22
22
  "core-js": "^3.30.2",
23
23
  "dayjs": "^1.11.7",
24
- "ol": "7.3.0",
24
+ "ol": "7.4.0",
25
25
  "olcs": "^2.14.0",
26
26
  "proj4": "^2.9.0",
27
27
  "xml2js": "^0.5.0"
@@ -47,7 +47,7 @@
47
47
  "use-resize-observer": "^9.1.0"
48
48
  },
49
49
  "peerDependencies": {
50
- "cesium": "^1.95.0"
50
+ "@cesium/engine": "^2.4.1"
51
51
  },
52
52
  "engines": {
53
53
  "node": "^16.13.2 || ^18.12.0",
package/src/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import {createMapView} from "./maps/mapView";
2
2
  import crs from "./crs";
3
+ import drawInteractions from "./maps/interactions/drawInteractions";
3
4
  import rawLayerList from "./rawLayerList";
4
5
  import * as wms from "./layer/wms";
5
6
  import wmts from "./layer/wmts";
@@ -36,5 +37,6 @@ export {
36
37
  ping,
37
38
  search,
38
39
  crs,
40
+ drawInteractions,
39
41
  webgl
40
42
  };
package/src/layer/wfs.js CHANGED
@@ -202,9 +202,16 @@ export function createLayerSource (rawLayer, options = {}) {
202
202
  return createClusterVectorSource(source, rawLayer.clusterDistance, options.clusterGeometryFunction);
203
203
  }
204
204
  if (rawLayer.renderer === "webgl") {
205
- source.once("featuresloadend", event => {
206
- webgl.afterLoading(event?.features, rawLayer.styleId, rawLayer.excludeTypesFromParsing);
207
- });
205
+ if (options.loadingStrategy === bbox) {
206
+ source.on("featuresloadend", event => {
207
+ webgl.afterLoading(event?.features, rawLayer.styleId, rawLayer.excludeTypesFromParsing);
208
+ });
209
+ }
210
+ else {
211
+ source.once("featuresloadend", event => {
212
+ webgl.afterLoading(event?.features, rawLayer.styleId, rawLayer.excludeTypesFromParsing);
213
+ });
214
+ }
208
215
  }
209
216
  return source;
210
217
  }
@@ -252,3 +259,22 @@ export function createLayer (rawLayer = {}, {layerParams = {}, options = {}} = {
252
259
  }
253
260
  return layer;
254
261
  }
262
+
263
+ /**
264
+ * Load the features manually.
265
+ * @param {Object} layerAttributes raw layer attributes.
266
+ * @param {module:ol/vector/Source} layerSource - the source of the layer
267
+ * @returns {void}
268
+ */
269
+ export function loadFeaturesManually (layerAttributes, layerSource) {
270
+ const getUrl = createUrl(layerAttributes, layerAttributes.version, {getCode: () => layerAttributes.crs}, "");
271
+
272
+ fetch(getUrl, layerSource)
273
+ .then(response => response.text())
274
+ .then(responseString => {
275
+ layerSource.addFeatures(layerSource.getFormat().readFeatures(responseString));
276
+ })
277
+ .catch(error => {
278
+ console.error(error);
279
+ });
280
+ }