@masterportal/masterportalapi 2.16.0 → 2.17.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,22 @@
3
3
 
4
4
  The [Semantic Versioning](https://semver.org/spec/v2.0.0.html) is used.
5
5
 
6
+ ## 2.17.0 - 2023-04-27
7
+ ### Added
8
+ - Added functionality for mapbox style raster sources for vector tile layer.
9
+ - Added possibility to use zoomToFeatureId in vectorStyle.
10
+
11
+ ### Changed
12
+ - ol map default interactions and keyboardEventTarget can now be set by config parameters.
13
+ - The following packages have been updated:
14
+ - dependencies:
15
+ - xml2js: 0.4.23 to 0.5.0
16
+
17
+ ### Fix
18
+ - Fix vectorStyle for circlesegments.
19
+
20
+ ---
21
+
6
22
  ## 2.16.0 - 2023-03-28
7
23
  ### Added
8
24
  - Added support for `npm` version ^9.1.3.
package/example/index.js CHANGED
@@ -262,7 +262,7 @@ fetch(vtStyleUrl)
262
262
  .then(style => {
263
263
  const vtLayer = window.mpapi.map.addLayer("6001");
264
264
 
265
- mpapi.vectorTile.setStyle(vtLayer, style);
265
+ mpapi.vectorTile.setStyle(vtLayer, style, vtStyleUrl);
266
266
  });
267
267
  //*/
268
268
 
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.16.0",
4
+ "version": "2.17.0",
5
5
  "license": "MIT",
6
6
  "description": "Basic functions of the Masterportal as api",
7
7
  "repository": {
@@ -23,7 +23,7 @@
23
23
  "ol": "7.3.0",
24
24
  "olcs": "^2.13.1",
25
25
  "proj4": "^2.9.0",
26
- "xml2js": "^0.4.23"
26
+ "xml2js": "^0.5.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@babel/core": "^7.21.3",
@@ -4,7 +4,7 @@ import VectorTileSource from "ol/source/VectorTile";
4
4
  import OpenLayersTileGrid from "ol/tilegrid/TileGrid";
5
5
  import {extentFromProjection} from "ol/tilegrid";
6
6
 
7
- import {stylefunction} from "ol-mapbox-style";
7
+ import {stylefunction, apply} from "ol-mapbox-style";
8
8
 
9
9
  import defaults from "../defaults";
10
10
 
@@ -161,13 +161,25 @@ export function createLayer (rawLayer = {}, {layerParams = {}, options = {}} = {
161
161
  * @param {ol.layer.VectorTile} layer - layer to style
162
162
  * @param {object} glStyle - MapBox style definition
163
163
  * @param {options} [styleParams={}] - Additional options for style specification
164
+ * @param {string} url - MapBox style url
164
165
  * @returns {void}
165
166
  */
166
- export function setStyle (layer, glStyle, {options = {}} = {}) {
167
- stylefunction(layer, glStyle,
168
- options.sourceId ? options.sourceId : Object.keys(glStyle.sources)[0],
169
- options.resolutions,
170
- options.spriteData,
171
- options.spriteImageUrl,
172
- options.getFonts);
167
+ export function setStyle (layer, glStyle, {options = {}} = {}, url) {
168
+ Object.keys(glStyle.sources).forEach((key) => {
169
+ const glStyleSourceId = key;
170
+
171
+ if (glStyle.sources[key].type !== "vector" && glStyle.sources[key].type !== "geojson") {
172
+ const olMap = layer.get("map");
173
+
174
+ apply(olMap, url);
175
+ }
176
+ else {
177
+ stylefunction(layer, glStyle,
178
+ options.sourceId ? options.sourceId : glStyleSourceId,
179
+ options.resolutions,
180
+ options.spriteData,
181
+ options.spriteImageUrl,
182
+ options.getFonts);
183
+ }
184
+ });
173
185
  }
@@ -150,18 +150,23 @@ export function createMap (config = defaults, {mapParams, callback, errorCallbac
150
150
  crs.registerProjections(config.namedProjections);
151
151
  setBackgroundImage(config);
152
152
  setGazetteerUrl(config.gazetteerUrl);
153
- const map = new Map(Object.assign({
154
- target: config.target || defaults.target,
155
- interactions: olDefaultInteractions({dragPan: false, altShiftDragRotate: false, pinchRotate: false}).extend([
156
- new DragPan({
157
- condition: function (event) {
158
- return (!event.originalEvent.pointerType || event.originalEvent.pointerType === "mouse") || (config.twoFingerPan && this.getPointerCount() === 2) || !config.twoFingerPan;
159
- }
160
- })
161
- ]),
162
- controls: [],
163
- view: createMapView(config)
164
- }, mapParams));
153
+ const selectedInteractions = config.mapInteractions?.interactionModes ? config.mapInteractions?.interactionModes : {dragPan: false, altShiftDragRotate: false, pinchRotate: false},
154
+ map = new Map(Object.assign({
155
+ target: config.target || defaults.target,
156
+ interactions: olDefaultInteractions(selectedInteractions).extend([
157
+ new DragPan({
158
+ condition: function (event) {
159
+ if (event.originalEvent.shiftKey) {
160
+ return false;
161
+ }
162
+ return (!event.originalEvent.pointerType || event.originalEvent.pointerType === "mouse") || (config.twoFingerPan && this.getPointerCount() === 2) || !config.twoFingerPan;
163
+ }
164
+ })
165
+ ]),
166
+ controls: [],
167
+ view: createMapView(config),
168
+ keyboardEventTarget: config.mapInteractions?.keyboardEventTarget ? config.mapInteractions?.keyboardEventTarget : false
169
+ }, mapParams));
165
170
 
166
171
  map.set("mapMode", "2D");
167
172
  map.set("id", `map2D_${mapIdCounter++}`);
@@ -18,7 +18,8 @@ let styleList,
18
18
  highlightFeaturesPolygonStyleId,
19
19
  highlightFeaturesLineStyleId,
20
20
  styleConf,
21
- featureViaUrlLayers;
21
+ featureViaUrlLayers,
22
+ zoomToFeatureId;
22
23
 
23
24
  /**
24
25
  * Gathers the styleIds of the layers.
@@ -196,9 +197,10 @@ function parseStyles (data) {
196
197
  getStyleIdForHighlightFeaturesPolygon(),
197
198
  getStyleIdForHighlightFeaturesLine(),
198
199
  getStyleIdsFromTools(),
199
- getFeatureViaURLStyles());
200
+ getFeatureViaURLStyles(),
201
+ zoomToFeatureId);
200
202
 
201
- styleIds = styleIds.reduce((acc, val) => acc.concat(val), []);
203
+ styleIds = styleIds.reduce((acc, val) => acc.concat(val), []).filter(item => item);
202
204
  filteredData = dataWithDefaultValue.filter(styleObject => styleIds.includes(styleObject.styleId));
203
205
 
204
206
  return filteredData;
@@ -223,6 +225,7 @@ function initializeStyleList (styleGetters, Config, layers, tools, callback) {
223
225
  highlightFeaturesPointStyleId = styleGetters.highlightFeaturesPointStyleId;
224
226
  highlightFeaturesPolygonStyleId = styleGetters.highlightFeaturesPolygonStyleId;
225
227
  highlightFeaturesLineStyleId = styleGetters.highlightFeaturesLineStyleId;
228
+ zoomToFeatureId = styleGetters.zoomToFeatureId;
226
229
 
227
230
  styleConf = Config.styleConf;
228
231
  featureViaUrlLayers = Config.featureViaURL?.layers;
@@ -220,11 +220,14 @@ export function createNominalPointStyle (attributes, feature, defaultImageName)
220
220
  if (styleScalingShape === "CIRCLESEGMENTS") {
221
221
  svgPath = createNominalCircleSegments(workingFeature, attributes);
222
222
  style = createSVGStyle(svgPath, 5);
223
+ style.type = "CIRCLESEGMENTS";
224
+ style.scalingAttribute = workingFeature.get(attributes.scalingAttribute);
223
225
  }
224
226
 
225
227
  // create style from svg and image
226
228
  if (imageName !== defaultImageName) {
227
229
  imageStyle = createIconStyle(attributes, feature);
230
+ imageStyle.type = "imageStyle";
228
231
  style = [style, imageStyle];
229
232
  }
230
233