@masterportal/masterportalapi 2.19.0 → 2.19.2

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,12 +3,14 @@
3
3
 
4
4
  The [Semantic Versioning](https://semver.org/spec/v2.0.0.html) is used.
5
5
 
6
- ## Unreleased - in development
7
- ### Added
8
- ### Changed
9
- ### Deprecated
10
- ### Removed
6
+ ## 2.19.2 - 2023-06-12
11
7
  ### Fixed
8
+ - VectorStyle of multiple geometries with styling rules does not fail on not existing style.
9
+
10
+ ---
11
+ ## 2.19.1 - 2023-06-02
12
+ ### Changed
13
+ - Exports in src/layer/wmts.js changed to export default {} to provide ES-Syntax.
12
14
 
13
15
  ---
14
16
 
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.0",
4
+ "version": "2.19.2",
5
5
  "license": "MIT",
6
6
  "description": "Basic functions of the Masterportal as api",
7
7
  "repository": {
@@ -11,7 +11,7 @@
11
11
  "main": "src/index.js",
12
12
  "scripts": {
13
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",
14
+ "test:trace": "node --trace-warnings node_modules/jest/bin/jest.js .test.js --config ./jest.config.js",
15
15
  "test:watch": "jest .test.js --config ./jest.config.js --watch",
16
16
  "example": "parcel example/index.html",
17
17
  "generate-jsdoc": "jsdoc ./src -r -d ./docs/ -R ./README.md -c jsdoc.json",
package/src/index.js CHANGED
@@ -2,7 +2,7 @@ import {createMapView} from "./maps/mapView";
2
2
  import crs from "./crs";
3
3
  import rawLayerList from "./rawLayerList";
4
4
  import * as wms from "./layer/wms";
5
- import * as wmts from "./layer/wmts";
5
+ import wmts from "./layer/wmts";
6
6
  import * as wfs from "./layer/wfs";
7
7
  import * as geojson from "./layer/geojson";
8
8
  import * as vectorBase from "./layer/vectorBase";
package/src/layer/wmts.js CHANGED
@@ -12,7 +12,7 @@ import {get as getProjection} from "ol/proj";
12
12
  * @param {String} layerName layerName
13
13
  * @returns {void}
14
14
  */
15
- export function showErrorMessage (errorMessage, layerName) {
15
+ function showErrorMessage (errorMessage, layerName) {
16
16
  console.error("content: Layer " + layerName + ": " + errorMessage);
17
17
  }
18
18
 
@@ -24,7 +24,7 @@ export function showErrorMessage (errorMessage, layerName) {
24
24
  * @param {Number} size The tileSize depending on the extent.
25
25
  * @returns {void}
26
26
  */
27
- export function generateArrays (resolutions, matrixIds, length, size) {
27
+ function generateArrays (resolutions, matrixIds, length, size) {
28
28
  for (let i = 0; i < length; ++i) {
29
29
  resolutions[i] = size / Math.pow(2, i);
30
30
  matrixIds[i] = i;
@@ -37,7 +37,7 @@ export function generateArrays (resolutions, matrixIds, length, size) {
37
37
  * @throws {Error} on unexpected return
38
38
  * @returns {promise} promise resolves to parsed WMTS-GetCapabilities object
39
39
  */
40
- export function getWMTSCapabilities (url) {
40
+ function getWMTSCapabilities (url) {
41
41
  return fetch(url)
42
42
  .then(response => {
43
43
  if (response && response.status === 200) {
@@ -55,7 +55,7 @@ export function getWMTSCapabilities (url) {
55
55
  * @param {WMTS} tileLayer layer object
56
56
  * @returns {void}
57
57
  */
58
- export function createLayerSourceByDefinitions (attrs, tileLayer) {
58
+ function createLayerSourceByDefinitions (attrs, tileLayer) {
59
59
  const projection = getProjection(attrs.coordinateSystem),
60
60
  extent = projection.getExtent(),
61
61
  style = attrs.style,
@@ -108,7 +108,7 @@ export function createLayerSourceByDefinitions (attrs, tileLayer) {
108
108
  * @param {WMTS} tileLayer layer object
109
109
  * @returns {void}
110
110
  */
111
- export function createLayerSourceByCapabilities (attrs, tileLayer) {
111
+ function createLayerSourceByCapabilities (attrs, tileLayer) {
112
112
  const layerIdentifier = attrs.layers,
113
113
  url = attrs.capabilitiesUrl,
114
114
  matrixSet = attrs.tileMatrixSet,
@@ -169,7 +169,7 @@ export function createLayerSourceByCapabilities (attrs, tileLayer) {
169
169
  * @param {object} layerParams - additional layer params
170
170
  * @returns {void}
171
171
  */
172
- export function createLayer (rawLayer, layerParams = {}) {
172
+ function createLayer (rawLayer, layerParams = {}) {
173
173
  const tileLayer = new TileLayer(Object.assign({
174
174
  id: rawLayer.id,
175
175
  source: new WMTS({}),
@@ -193,3 +193,12 @@ export function createLayer (rawLayer, layerParams = {}) {
193
193
 
194
194
  return tileLayer;
195
195
  }
196
+
197
+ export default {
198
+ createLayer,
199
+ createLayerSourceByCapabilities,
200
+ createLayerSourceByDefinitions,
201
+ getWMTSCapabilities,
202
+ generateArrays,
203
+ showErrorMessage
204
+ };
@@ -227,10 +227,22 @@ function createStyle (styleObject, feature, isClustered, wfsImgPathFromConfig) {
227
227
  style = Array.isArray(rules) && rules.length > 0 ? rules[0].style : null,
228
228
  hasLabelField = style?.labelField,
229
229
  geometryStyle = getGeometryStyle(feature, rules, isClustered, wfsImgPathFromConfig),
230
- legendInformation = Array.isArray(geometryStyle) ? geometryStyle[0].legendInfos : geometryStyle.legendInfos,
231
- styleObjectGeometry = Array.isArray(geometryStyle) ? geometryStyle.map(styleItem => styleItem.getStyle()) : geometryStyle.getStyle();
230
+ legendInformation = Array.isArray(geometryStyle) ? geometryStyle[0].legendInfos : geometryStyle.legendInfos;
231
+ let styleObjectGeometry = null;
232
232
 
233
- if (geometryStyle.length > 1) {
233
+ if (Array.isArray(geometryStyle)) {
234
+ styleObjectGeometry = [];
235
+ geometryStyle.forEach(styleItem => {
236
+ if (styleItem.getStyle() !== null) {
237
+ styleObjectGeometry.push(styleItem.getStyle());
238
+ }
239
+ });
240
+ }
241
+ else {
242
+ styleObjectGeometry = geometryStyle.getStyle();
243
+ }
244
+
245
+ if (Array.isArray(geometryStyle) && geometryStyle.length > 1) {
234
246
  for (const i in geometryStyle) {
235
247
  captureLegendFromFeature(styleObject.styleId, geometryStyle[i].legendInfos);
236
248
  }
@@ -238,7 +250,6 @@ function createStyle (styleObject, feature, isClustered, wfsImgPathFromConfig) {
238
250
  else {
239
251
  captureLegendFromFeature(styleObject.styleId, legendInformation);
240
252
  }
241
-
242
253
  // label style is optional and depends on some fields
243
254
  if (isClustered || hasLabelField) {
244
255
  if (Array.isArray(styleObjectGeometry)) {
@@ -1,7 +1,7 @@
1
1
  import {get as getProjection} from "ol/proj";
2
2
  import {getWidth} from "ol/extent";
3
3
 
4
- import * as wmts from "../../src/layer/wmts";
4
+ import wmts from "../../src/layer/wmts";
5
5
 
6
6
  describe("wmts.js", function () {
7
7
  describe("generateArrays", function () {
@@ -239,6 +239,129 @@ describe("createStyle", () => {
239
239
 
240
240
  expect(style).toBeInstanceOf(Style);
241
241
  });
242
+
243
+ it("should return the correct style for a feature with geometry of type MultiLineString ", () => {
244
+ const stylingRules = [{
245
+ "conditions": {
246
+ "sequence": [0, 0]
247
+ },
248
+ "style": {
249
+ "lineStrokeColor": [0, 41, 255, 1],
250
+ "lineStrokeDash": [10, 2000],
251
+ "lineStrokeDashOffset": 0,
252
+ "lineStrokeWidth": 4
253
+ }
254
+ }],
255
+ styleObject = {styleId: "styleId", styleMultiGeomOnlyWithRule: true, rules: stylingRules},
256
+ isClustered = false,
257
+ multiLineStringFeature = jsonObjects[4],
258
+ style = createStyle.createStyle(styleObject, multiLineStringFeature, isClustered, wfsImgPathFromConfig);
259
+
260
+ expect(style === null).toBe(false);
261
+ expect(style).toBeInstanceOf(Array);
262
+ style.forEach(aStyle => {
263
+ expect(aStyle).toBeInstanceOf(Style);
264
+ });
265
+ });
266
+
267
+ it("should return the correct style for a feature with geometry of type MultiPolygon ", () => {
268
+ const stylingRules = [{
269
+ "conditions": {
270
+ "sequence": [0, 0]
271
+ },
272
+ "style": {
273
+ "polygonStrokeColor": [
274
+ 161,
275
+ 113,
276
+ 14,
277
+ 1
278
+ ],
279
+ "polygonStrokeWidth": 0.2,
280
+ "polygonFillColor": [
281
+ 161,
282
+ 113,
283
+ 14,
284
+ 1
285
+ ]
286
+ }
287
+ }],
288
+ styleObject = {styleId: "styleId", styleMultiGeomOnlyWithRule: true, rules: stylingRules},
289
+ isClustered = false,
290
+ multiPolygonFeature = jsonObjects[5],
291
+ style = createStyle.createStyle(styleObject, multiPolygonFeature, isClustered, wfsImgPathFromConfig);
292
+
293
+ expect(style === null).toBe(false);
294
+ expect(style).toBeInstanceOf(Array);
295
+ style.forEach(aStyle => {
296
+ expect(aStyle).toBeInstanceOf(Style);
297
+ });
298
+ });
299
+
300
+ it("should return the correct style for a feature with geometry of type GeometryCollection ", () => {
301
+ const stylingRules = [{
302
+ "conditions": {
303
+ "sequence": [0, 0]
304
+ },
305
+ "style": {
306
+ "polygonStrokeColor": [
307
+ 161,
308
+ 113,
309
+ 14,
310
+ 1
311
+ ],
312
+ "polygonStrokeWidth": 0.2,
313
+ "polygonFillColor": [
314
+ 161,
315
+ 113,
316
+ 14,
317
+ 1
318
+ ]
319
+ }
320
+ }],
321
+ styleObject = {styleId: "styleId", styleMultiGeomOnlyWithRule: true, rules: stylingRules},
322
+ isClustered = false,
323
+ geometryCollectionFeature = jsonObjects[6],
324
+ style = createStyle.createStyle(styleObject, geometryCollectionFeature, isClustered, wfsImgPathFromConfig);
325
+
326
+ expect(style === null).toBe(false);
327
+ expect(style).toBeInstanceOf(Array);
328
+ style.forEach(aStyle => {
329
+ expect(aStyle).toBeInstanceOf(Style);
330
+ });
331
+ });
332
+
333
+ it("should return the correct style for a feature with geometry of type MultiPoint ", () => {
334
+ const stylingRules = [{
335
+ "conditions": {
336
+ "sequence": [0, 0]
337
+ },
338
+ "style": {
339
+ "circleRadius": 6,
340
+ "circleStrokeColor": [
341
+ 24,
342
+ 116,
343
+ 205,
344
+ 1
345
+ ],
346
+ "circleFillColor": [
347
+ 135,
348
+ 206,
349
+ 250,
350
+ 1
351
+ ]
352
+ }
353
+ }],
354
+ styleObject = {styleId: "styleId", styleMultiGeomOnlyWithRule: true, rules: stylingRules},
355
+ isClustered = false,
356
+ multiPointFeature = jsonObjects[3],
357
+ style = createStyle.createStyle(styleObject, multiPointFeature, isClustered, wfsImgPathFromConfig);
358
+
359
+ expect(style === null).toBe(false);
360
+ expect(style).toBeInstanceOf(Array);
361
+ style.forEach(aStyle => {
362
+ expect(aStyle).toBeInstanceOf(Style);
363
+ });
364
+ });
242
365
  });
243
366
 
244
367
  describe("getSimpleGeometryStyle", function () {