@masterportal/masterportalapi 2.23.0 → 2.24.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,10 +3,38 @@
3
3
 
4
4
  The [Semantic Versioning](https://semver.org/spec/v2.0.0.html) is used.
5
5
 
6
+ ## 2.24.0 - 2023-08-03
7
+ ### Added
8
+ - The following packages have been installed:
9
+ - @swc/jest: 0.2.27
10
+ - Add a function to convertUnits in drawInteractions.
11
+
12
+ ### Changed
13
+ - The following packages have been updated:
14
+ - dependencies:
15
+ - core-js: 3.30.2 to 3.32.0
16
+ - dayjs: 1.11.7 to 1.11.9
17
+ - olcs: 2.14.0 to 2.15.0
18
+ - xml2js: 0.5.0 to 0.6.2
19
+ - devDependencies:
20
+ - @babel/core: 7.21.8 to 7.22.9
21
+ - @babel/plugin-transform-modules-commonjs: 7.21.5 to 7.21.5
22
+ - @parcel/transformer-sass: 2.8.3 to 2.9.3
23
+ - buffer: 5.7.1 to 6.0.3
24
+ - eslint: 8.40.0 to 8.46.0
25
+ - jest: 29.5.0 to 29.6.2
26
+ - jest-canvas-mock: 2.5.0 to 2.5.2
27
+ - jest-environment-jsdom: 29.5.0 to 29.6.2
28
+ - parcel: 2.8.3 to 2.9.3
29
+ - sass: 1.62.1 to 1.64.2
30
+
31
+ ### Fixed
32
+ - Changed peerDependency from cesium 1.106.0 to @cesium/engine 2.4.1.
33
+
34
+ ---
35
+
6
36
  ## 2.23.0 - 2023-08-02
7
37
  ### 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
38
  - Add select and modify interactions for editing ol features.
11
39
 
12
40
  ### Fixed
@@ -15,8 +43,15 @@
15
43
  ---
16
44
 
17
45
  ## 2.22.0 - 2023-07-25
46
+ ### Changed
47
+ - Replace derprecated cesium tileset and terrain loading functions.
48
+ - WFST Refactoring
49
+
50
+ ---
51
+
52
+ ## 2.21.0 - 2023-07-21
18
53
  ### Added
19
- - VectorStyle: Add Styling rules for Geoemtries of type `Circle`.
54
+ - VectorStyle: Add Styling rules for Geometries of type `Circle`.
20
55
  - Add Styling and zIndex to draw interactions and improve the draw behavior.
21
56
 
22
57
  ### Changed
@@ -24,9 +59,6 @@
24
59
  - WFS:
25
60
  - Migrated writeTransaction and sendTransaction from masterportal the masterportalAPI.
26
61
  - Exports in src/layer/wfs.js changed to export default {} to provide ES-Syntax.
27
- ### Deprecated
28
-
29
- ### Removed
30
62
 
31
63
  ### Fixed
32
64
  - WFS: fixed a bug that prevented parsing GeoServer responses.
@@ -77,6 +77,6 @@
77
77
  }
78
78
  }
79
79
  ],
80
- "cesiumLib":"https://geoportal-hamburg.de/mastercode/cesium/1_99/Cesium.js",
80
+ "cesiumLib":"https://geoportal-hamburg.de/mastercode/cesium/latest/Cesium.js",
81
81
  "wfsImgPath": "https://geodienste.hamburg.de/lgv-config/img/"
82
82
  }
package/example/index.js CHANGED
@@ -249,7 +249,7 @@ document.getElementById("enable").addEventListener("click", function () {
249
249
  document.getElementById("layer-visibility").style.display = "none";
250
250
  }
251
251
  else {
252
- const lib = portalConfig.cesiumLib ? portalConfig.cesiumLib : "https://geoportal-hamburg.de/mastercode/cesium/1_99/index.js";
252
+ const lib = portalConfig.cesiumLib ? portalConfig.cesiumLib : "https://geoportal-hamburg.de/mastercode/cesium/latest/index.js";
253
253
 
254
254
  document.getElementById("layer-visibility").style.display = "block";
255
255
 
package/jest.config.js CHANGED
@@ -1,5 +1,8 @@
1
1
  /* eslint-env node */
2
2
  module.exports = {
3
+ "transform": {
4
+ "^.+\\.(t|j)sx?$": "@swc/jest"
5
+ },
3
6
  /** ol prints errors without HTMLCanvasElement being available in test environment */
4
7
  "setupFiles": ["jest-canvas-mock"],
5
8
  /** node_modules are usually ignored by babel-jest, but ol is published in ES6 */
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.23.0",
4
+ "version": "2.24.0",
5
5
  "license": "MIT",
6
6
  "description": "Basic functions of the Masterportal as api",
7
7
  "repository": {
@@ -19,30 +19,31 @@
19
19
  "prepare": "husky install"
20
20
  },
21
21
  "dependencies": {
22
- "core-js": "^3.30.2",
23
- "dayjs": "^1.11.7",
22
+ "core-js": "^3.32.0",
23
+ "dayjs": "^1.11.9",
24
24
  "ol": "7.4.0",
25
- "olcs": "^2.14.0",
25
+ "olcs": "^2.15.0",
26
26
  "proj4": "^2.9.0",
27
- "xml2js": "^0.5.0"
27
+ "xml2js": "^0.6.2"
28
28
  },
29
29
  "devDependencies": {
30
- "@babel/core": "^7.21.8",
31
- "@babel/plugin-transform-modules-commonjs": "^7.21.5",
32
- "@parcel/transformer-sass": "^2.8.3",
33
- "buffer": "^5.7.1",
30
+ "@babel/core": "^7.22.9",
31
+ "@babel/plugin-transform-modules-commonjs": "^7.22.5",
32
+ "@parcel/transformer-sass": "^2.9.3",
33
+ "@swc/jest": "^0.2.27",
34
+ "buffer": "^6.0.3",
34
35
  "canvas": "^2.11.2",
35
- "eslint": "^8.40.0",
36
+ "eslint": "^8.46.0",
36
37
  "events": "^3.3.0",
37
38
  "husky": "^8.0.3",
38
- "jest": "^29.5.0",
39
- "jest-canvas-mock": "^2.5.0",
40
- "jest-environment-jsdom": "^29.5.0",
39
+ "jest": "^29.6.2",
40
+ "jest-canvas-mock": "^2.5.2",
41
+ "jest-environment-jsdom": "^29.6.2",
41
42
  "jest-fetch-mock": "^3.0.3",
42
43
  "jsdoc": "^4.0.2",
43
- "parcel": "^2.8.3",
44
+ "parcel": "^2.9.3",
44
45
  "process": "^0.11.10",
45
- "sass": "^1.62.1",
46
+ "sass": "^1.64.2",
46
47
  "stream-browserify": "^3.0.0",
47
48
  "timers-browserify": "^2.0.12",
48
49
  "use-resize-observer": "^9.1.0"
@@ -5,14 +5,15 @@
5
5
  * @param {string} [rawLayer.cesiumTerrainProviderOptions] - see https://cesiumjs.org/Cesium/Build/Documentation/CesiumTerrainProvider.html
6
6
  * @returns {void}
7
7
  */
8
- function createTerrainProvider (rawLayer) {
9
- const options = {};
8
+ async function createTerrainProvider (rawLayer) {
9
+ const options = {},
10
+ terrainProvider = await Cesium.CesiumTerrainProvider.fromUrl(rawLayer.url, options);
10
11
 
11
12
  if (rawLayer.cesiumTerrainProviderOptions) {
12
13
  Object.assign(options, rawLayer.cesiumTerrainProviderOptions);
13
14
  }
14
- options.url = rawLayer.url;
15
- return new Cesium.CesiumTerrainProvider(options);
15
+
16
+ return terrainProvider;
16
17
  }
17
18
 
18
19
  /**
@@ -24,10 +25,10 @@ function createTerrainProvider (rawLayer) {
24
25
  * @param {OLCesium} map ol cesium map
25
26
  * @returns {void}
26
27
  */
27
- export function setVisible (value, rawLayer, map) {
28
+ async function setVisible (value, rawLayer, map) {
28
29
  if (map && typeof map.getCesiumScene === "function") {
29
30
  if (value) {
30
- map.getCesiumScene().terrainProvider = createTerrainProvider(rawLayer);
31
+ map.getCesiumScene().terrainProvider = await createTerrainProvider(rawLayer);
31
32
  }
32
33
  else {
33
34
  map.getCesiumScene().terrainProvider = new Cesium.EllipsoidTerrainProvider({});
@@ -63,3 +64,4 @@ export function get (key) {
63
64
  return this.values[key];
64
65
  }
65
66
 
67
+ module.exports.setVisible = setVisible;
@@ -9,11 +9,12 @@ function createTileSet (rawLayer) {
9
9
  const url = rawLayer.url.split("?")[0] + "/tileset.json",
10
10
  options = {};
11
11
 
12
+
12
13
  if (rawLayer.cesium3DTilesetOptions) {
13
14
  Object.assign(options, rawLayer.cesium3DTilesetOptions);
14
15
  }
15
- options.url = url;
16
- return new Cesium.Cesium3DTileset(options);
16
+
17
+ return Promise.resolve(Cesium.Cesium3DTileset.fromUrl(url, options));
17
18
  }
18
19
 
19
20
  /**
@@ -24,6 +25,7 @@ function createTileSet (rawLayer) {
24
25
  * @param {string} [rawLayer.cesiumTerrainProviderOptions] - see https://cesiumjs.org/Cesium/Build/Documentation/CesiumTerrainProvider.html
25
26
  * @returns {void}
26
27
  */
28
+
27
29
  export default function Tileset (rawLayer) {
28
30
  this.values = {
29
31
  name: rawLayer.name,
@@ -31,8 +33,13 @@ export default function Tileset (rawLayer) {
31
33
  typ: rawLayer.typ
32
34
  };
33
35
  if (Cesium) {
34
- this.tileset = createTileSet(rawLayer);
35
- this.tileset.layerReferenceId = rawLayer.id;
36
+ this.tileset = Promise.resolve(createTileSet(rawLayer));
37
+ this.tileset.then(function (tileset) {
38
+ if (tileset) {
39
+ tileset.layerReferenceId = rawLayer.id;
40
+ }
41
+ });
42
+
36
43
  }
37
44
  }
38
45
 
@@ -69,7 +76,9 @@ Tileset.prototype.setVisible = function (value, map) {
69
76
  if (map && typeof map.getCesiumScene === "function") {
70
77
  if (value) {
71
78
  if (!map.getCesiumScene().primitives.contains(this.tileset)) {
72
- map.getCesiumScene().primitives.add(this.tileset);
79
+ this.tileset.then(function (tileset) {
80
+ map.getCesiumScene().primitives.add(tileset);
81
+ });
73
82
  }
74
83
  this.tileset.show = true;
75
84
  }
@@ -38,6 +38,26 @@ let styleObject = null,
38
38
  styleObjectOuterCircle = null,
39
39
  zIndex = 0;
40
40
 
41
+ /**
42
+ * Converts a value from one unit to another.
43
+ * @param {Number} value The value to convert.
44
+ * @param {String} sourceUnit The source unit.
45
+ * @param {String} targetUnit The target unit.
46
+ * @returns {Number} The converted value.
47
+ */
48
+ function convertUnits (value, sourceUnit, targetUnit) {
49
+ if (sourceUnit === targetUnit) {
50
+ return value;
51
+ }
52
+ else if (sourceUnit === "m" && targetUnit === "km") {
53
+ return value / 1000;
54
+ }
55
+ else if (sourceUnit === "km" && targetUnit === "m") {
56
+ return value * 1000;
57
+ }
58
+ return value;
59
+ }
60
+
41
61
  /**
42
62
  * Transform the radius to map projection unit.
43
63
  * @param {Number} radius The radius.
@@ -70,8 +90,10 @@ function transformMapUnitRadius (radius, mapProjection) {
70
90
  */
71
91
  function drawOuterCircle (feature, mapProjection, source, options = {}) {
72
92
  const innerCircleFeature = feature.clone(),
73
- mapUnitInnerRadius = transformMapUnitRadius(options.innerRadius, mapProjection),
74
- mapUnitOuterRadius = transformMapUnitRadius(options.outerRadius, mapProjection),
93
+ innerRadius = convertUnits(options.innerRadius, options.unit, "m"),
94
+ outerRadius = convertUnits(options.outerRadius, options.unit, "m"),
95
+ mapUnitInnerRadius = transformMapUnitRadius(innerRadius, mapProjection),
96
+ mapUnitOuterRadius = transformMapUnitRadius(outerRadius, mapProjection),
75
97
  innerStyle = createStyle.createStyle(styleObject, innerCircleFeature, false),
76
98
  outerStyle = createStyle.createStyle(styleObjectOuterCircle, feature, false);
77
99
 
@@ -95,7 +117,8 @@ function drawOuterCircle (feature, mapProjection, source, options = {}) {
95
117
  * @returns {void}
96
118
  */
97
119
  function drawInnerCircle (feature, mapProjection, options = {}) {
98
- const mapUnitInnerRadius = transformMapUnitRadius(options.innerRadius, mapProjection);
120
+ const innerRadius = convertUnits(options.innerRadius, options.unit, "m"),
121
+ mapUnitInnerRadius = transformMapUnitRadius(innerRadius, mapProjection);
99
122
 
100
123
  feature.getGeometry().setRadius(mapUnitInnerRadius);
101
124
  }
@@ -205,6 +228,7 @@ function createDrawInteraction (drawType, source) {
205
228
  export {styleObject};
206
229
 
207
230
  export default {
231
+ convertUnits,
208
232
  createDrawInteraction,
209
233
  drawCircle,
210
234
  drawInnerCircle,
@@ -6,8 +6,8 @@ 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
8
  import WMTS from "ol/source/WMTS.js";
9
- import olcsAbstractSynchronizer from "olcs/AbstractSynchronizer.js";
10
- import {extentToRectangle, tileLayerToImageryLayer, updateCesiumLayerProperties} from "olcs/core.js";
9
+ import olcsAbstractSynchronizer from "olcs/AbstractSynchronizer.ts";
10
+ import {extentToRectangle, tileLayerToImageryLayer, updateCesiumLayerProperties} from "olcs/core.ts";
11
11
  import {Tile, Image as ImageLayer} from "ol/layer.js";
12
12
  import {stableSort} from "ol/array.js";
13
13
  import {getBottomLeft, getBottomRight, getTopRight, getTopLeft} from "ol/extent.js";
@@ -1,6 +1,6 @@
1
- import OLCesium from "olcs/OLCesium.js";
1
+ import OLCesium from "olcs/OLCesium.ts";
2
2
  import {transform, get} from "ol/proj.js";
3
- import VectorSynchronizer from "olcs/VectorSynchronizer.js";
3
+ import VectorSynchronizer from "olcs/VectorSynchronizer.ts";
4
4
 
5
5
  import FixedOverlaySynchronizer from "./3dUtils/fixedOverlaySynchronizer.js";
6
6
  import WMSRasterSynchronizer from "./3dUtils/wmsRasterSynchronizer.js";
@@ -10,8 +10,10 @@ const features = [new Feature(), new Feature()];
10
10
  jest.mock("../../../src/renderer/webgl.js", () => {
11
11
  const original = jest.requireActual("../../../src/renderer/webgl.js");
12
12
 
13
- original.afterLoading = jest.fn();
14
- return original;
13
+ return {
14
+ ...original,
15
+ afterLoading: jest.fn()
16
+ };
15
17
  });
16
18
 
17
19
  describe("geojson/index", function () {
@@ -19,8 +19,10 @@ jest.mock("../../src/rawLayerList.js", () => {
19
19
  jest.mock("../../src/renderer/webgl.js", () => {
20
20
  const original = jest.requireActual("../../src/renderer/webgl.js");
21
21
 
22
- original.afterLoading = jest.fn();
23
- return original;
22
+ return {
23
+ ...original,
24
+ afterLoading: jest.fn()
25
+ };
24
26
  });
25
27
 
26
28
 
@@ -272,4 +274,4 @@ describe("oaf.js", function () {
272
274
  expect(webgl.afterLoading).toHaveBeenCalled();
273
275
  });
274
276
  });
275
- });
277
+ });
@@ -5,8 +5,10 @@ describe("terrain.js", function () {
5
5
 
6
6
  beforeEach(() => {
7
7
  global.Cesium = {};
8
- global.Cesium.CesiumTerrainProvider = jest.fn();
8
+ global.Cesium.CesiumTerrainProvider = {};
9
+ global.Cesium.CesiumTerrainProvider.fromUrl = jest.fn();
9
10
  global.Cesium.EllipsoidTerrainProvider = jest.fn();
11
+
10
12
  attr = {
11
13
  id: "12883",
12
14
  name: "Gelaende",
@@ -21,7 +23,7 @@ describe("terrain.js", function () {
21
23
  return {};
22
24
  }
23
25
  };
24
- cesiumTerrainProviderSpy = jest.spyOn(global.Cesium, "CesiumTerrainProvider");
26
+ cesiumTerrainProviderSpy = jest.spyOn(global.Cesium.CesiumTerrainProvider, "fromUrl");
25
27
  });
26
28
 
27
29
  afterEach(() => {
@@ -6,7 +6,8 @@ describe("tileset.js", function () {
6
6
 
7
7
  beforeEach(() => {
8
8
  global.Cesium = {};
9
- global.Cesium.Cesium3DTileset = jest.fn();
9
+ global.Cesium.Cesium3DTileset = {};
10
+ global.Cesium.Cesium3DTileset.fromUrl = jest.fn();
10
11
  global.Cesium.Cesium3DTileStyle = jest.fn(color => color);
11
12
  attr = {
12
13
  id: "4002",
@@ -28,7 +29,9 @@ describe("tileset.js", function () {
28
29
  };
29
30
  }
30
31
  };
31
- cesium3DTilesetSpy = jest.spyOn(global.Cesium, "Cesium3DTileset");
32
+ cesium3DTilesetSpy = jest.spyOn(global.Cesium.Cesium3DTileset, "fromUrl").mockImplementation(() => {
33
+ return Promise.resolve({});
34
+ });
32
35
  console.warn = jest.fn();
33
36
  });
34
37
 
@@ -38,21 +41,23 @@ describe("tileset.js", function () {
38
41
  console.warn = consoleWarn;
39
42
  });
40
43
 
41
- function checkAttributes (layer, attrs) {
44
+ async function checkAttributes (layer, attrs) {
45
+ const tileset = await layer.tileset;
46
+
42
47
  expect(layer.get("name")).toEqual(attrs.name);
43
48
  expect(layer.get("typ")).toEqual(attrs.typ);
44
49
  expect(layer.get("id")).toEqual(attrs.id);
45
- expect(layer.tileset.layerReferenceId).toEqual(attrs.id);
50
+ expect(tileset.layerReferenceId).toEqual(attrs.id);
46
51
  }
47
52
 
48
53
  describe("createLayer", function () {
49
54
  it("creates tileset layer without map", function () {
50
55
  const layer = new Tileset(attr);
51
56
 
52
- checkAttributes(layer, attr);
53
57
  expect(layer.tileSet).toEqual(undefined);
54
58
  expect(layer.tileset.show).toEqual(undefined);
55
59
  expect(cesium3DTilesetSpy).toHaveBeenCalledTimes(1);
60
+ checkAttributes(layer, attr);
56
61
  });
57
62
  it("creates 2 tileset layers with map and checks attributes", function () {
58
63
  const attr2 = {
@@ -9,8 +9,10 @@ import * as webgl from "../../src/renderer/webgl.js";
9
9
  jest.mock("../../src/renderer/webgl.js", () => {
10
10
  const original = jest.requireActual("../../src/renderer/webgl.js");
11
11
 
12
- original.afterLoading = jest.fn();
13
- return original;
12
+ return {
13
+ ...original,
14
+ afterLoading: jest.fn()
15
+ };
14
16
  });
15
17
 
16
18
  describe("vectorBase.js", function () {
@@ -24,8 +24,10 @@ jest.mock("../../src/rawLayerList.js", () => {
24
24
  jest.mock("../../src/renderer/webgl.js", () => {
25
25
  const original = jest.requireActual("../../src/renderer/webgl.js");
26
26
 
27
- original.afterLoading = jest.fn();
28
- return original;
27
+ return {
28
+ ...original,
29
+ afterLoading: jest.fn()
30
+ };
29
31
  });
30
32
 
31
33
 
@@ -6,6 +6,40 @@ import VectorSource from "ol/source/Vector";
6
6
  import drawInteractions, {styleObject} from "../../../src/maps/interactions/drawInteraction";
7
7
 
8
8
  describe("src/maps/interactions/drawInteraction.js", () => {
9
+ describe("convertUnits", () => {
10
+ it("shold return 1000 for sourceUnit === 'm' and targetUnit === 'm'", () =>{
11
+ const value = 1000,
12
+ sourceUnit = "m",
13
+ targetUnit = "m";
14
+
15
+ expect(drawInteractions.convertUnits(value, sourceUnit, targetUnit)).toEqual(1000);
16
+ });
17
+
18
+ it("shold return 1000 for sourceUnit === 'm' and targetUnit === 'km'", () =>{
19
+ const value = 1000,
20
+ sourceUnit = "m",
21
+ targetUnit = "km";
22
+
23
+ expect(drawInteractions.convertUnits(value, sourceUnit, targetUnit)).toEqual(1);
24
+ });
25
+
26
+ it("shold return 1000 for sourceUnit === 'km' and targetUnit === 'm'", () =>{
27
+ const value = 1000,
28
+ sourceUnit = "km",
29
+ targetUnit = "m";
30
+
31
+ expect(drawInteractions.convertUnits(value, sourceUnit, targetUnit)).toEqual(1000000);
32
+ });
33
+
34
+ it("shold return 1000 for sourceUnit === 'abc' and targetUnit === 'def'", () =>{
35
+ const value = 1000,
36
+ sourceUnit = "abc",
37
+ targetUnit = "def";
38
+
39
+ expect(drawInteractions.convertUnits(value, sourceUnit, targetUnit)).toEqual(1000);
40
+ });
41
+ });
42
+
9
43
  describe("transformMapUnitRadius", () => {
10
44
  it("should return the input meter radius in meter ", () => {
11
45
  const radius = 100,