@masterportal/masterportalapi 2.8.0 → 2.10.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
@@ -14,6 +14,34 @@
14
14
 
15
15
  ### Fixed
16
16
 
17
+ ---
18
+ ## 2.10.0 - 2022-03-11
19
+ ### Added
20
+ - DPS-1313: Added custom DragPan interaction to add ability to use 2-Finger-Pan instead of 1-Finger-Pan on mobile devices
21
+
22
+ ### Changed
23
+ - Exports in src/rawLayerList, src/crs.js and src/lib/load3DScript.js changed to export default {} to provide ES-Syntax.
24
+
25
+ ### Deprecated
26
+
27
+ ### Removed
28
+
29
+ ### Fixed
30
+
31
+ ---
32
+
33
+ ## 2.9.0 - 2022-10-25
34
+ ### Added
35
+
36
+ ### Changed
37
+ - Exports in src/rawLayerList and src/crs.js changed to module.exports to provide the possibility to stub the functions with sinon in masterportal.
38
+
39
+ ### Deprecated
40
+
41
+ ### Removed
42
+
43
+ ### Fixed
44
+
17
45
  ---
18
46
 
19
47
  ## 2.8.0 - 2022-10-04
package/example/index.js CHANGED
@@ -4,12 +4,12 @@ import {Style, Stroke, Fill, Icon} from "ol/style.js";
4
4
 
5
5
  import * as mpapi from "../src";
6
6
  import mapsAPI from "../src/maps/api.js";
7
- import {getLayerWhere} from "../src/rawLayerList";
7
+ import rawLayerList from "../src/rawLayerList";
8
8
 
9
9
  import services from "./config/services.json";
10
10
  import portalConfig from "./config/portal.json";
11
11
  import localGeoJSON from "./config/localGeoJSON.js";
12
- import {load3DScript} from "../src/lib/load3DScript";
12
+ import load3DScriptModule from "../src/lib/load3DScript";
13
13
 
14
14
  function errorCallback (errorEvent) {
15
15
  console.error("This is an error event:", errorEvent);
@@ -55,7 +55,7 @@ document.getElementById("enable").addEventListener("click", function () {
55
55
 
56
56
  document.getElementById("layer-visibility").style.display = "block";
57
57
 
58
- load3DScript(lib, function Loaded3DCallback () {
58
+ load3DScriptModule.load3DScript(lib, function Loaded3DCallback () {
59
59
  let tilesetLayer = null;
60
60
 
61
61
  const settings3D = {
@@ -71,9 +71,9 @@ document.getElementById("enable").addEventListener("click", function () {
71
71
  }
72
72
  },
73
73
  map3D = mapsAPI.map.createMap(settings3D, "3D"),
74
- rawLayerTerrain = getLayerWhere({id: "4001"}),
75
- rawLayerTileset = getLayerWhere({id: "4002"}),
76
- rawLayerEntities = getLayerWhere({id: "4003"});
74
+ rawLayerTerrain = rawLayerList.getLayerWhere({id: "4001"}),
75
+ rawLayerTileset = rawLayerList.getLayerWhere({id: "4002"}),
76
+ rawLayerEntities = rawLayerList.getLayerWhere({id: "4003"});
77
77
 
78
78
  window.mpapi.map = map3D;
79
79
  tilesetLayer = new mpapi.Tileset(rawLayerTileset, window.mpapi.map);
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.8.0",
4
+ "version": "2.10.0",
5
5
  "license": "MIT",
6
6
  "description": "Basic functions of the Masterportal as api",
7
7
  "repository": {
@@ -58,9 +58,5 @@
58
58
  },
59
59
  "bugs": {
60
60
  "url": "https://bitbucket.org/geowerkstatt-hamburg/masterportalapi/issues"
61
- },
62
- "keywords": [
63
- "geo",
64
- "map"
65
- ]
61
+ }
66
62
  }
package/src/crs.js CHANGED
@@ -22,7 +22,7 @@ function addAliasForWFSFromGeoserver (epsgCode) {
22
22
  * @param {string} name - projection name as written in [0] position of namedProjections
23
23
  * @returns {(object|undefined)} proj4 projection object or undefined
24
24
  */
25
- export function getProjection (name) {
25
+ function getProjection (name) {
26
26
  return proj4.defs(name);
27
27
  }
28
28
 
@@ -33,7 +33,7 @@ export function getProjection (name) {
33
33
  ]] - projection name, projection definition string
34
34
  * @returns {undefined}
35
35
  */
36
- export function registerProjections (namedProjections = defaults.namedProjections) {
36
+ function registerProjections (namedProjections = defaults.namedProjections) {
37
37
  proj4.defs(namedProjections);
38
38
  register(proj4);
39
39
  namedProjections.forEach(projection => {
@@ -48,7 +48,7 @@ export function registerProjections (namedProjections = defaults.namedProjection
48
48
  * Returns all known projections.
49
49
  * @returns {object[]} array of projection objects with their name added
50
50
  */
51
- export function getProjections () {
51
+ function getProjections () {
52
52
  const projections = Object
53
53
  .keys(proj4.defs)
54
54
  .map(name => Object.assign(proj4.defs(name), {name}));
@@ -64,7 +64,7 @@ export function getProjections () {
64
64
  * @param {ol.Map} map - map to get projection of
65
65
  * @returns {string} active projection name of map
66
66
  */
67
- export function getMapProjection (map) {
67
+ function getMapProjection (map) {
68
68
  return map.getView().getProjection().getCode();
69
69
  }
70
70
 
@@ -87,7 +87,7 @@ function getProj4Projection (projection) {
87
87
  * @param {number[]} point - point to project
88
88
  * @returns {number[]|undefined} transformed point
89
89
  */
90
- export function transform (sourceProjection, targetProjection, point) {
90
+ function transform (sourceProjection, targetProjection, point) {
91
91
  const source = getProj4Projection(sourceProjection),
92
92
  target = getProj4Projection(targetProjection);
93
93
 
@@ -106,7 +106,7 @@ export function transform (sourceProjection, targetProjection, point) {
106
106
  * @param {number[]} point - point to project
107
107
  * @returns {number[]|undefined} new point or undefined
108
108
  */
109
- export function transformToMapProjection (map, sourceProjection, point) {
109
+ function transformToMapProjection (map, sourceProjection, point) {
110
110
  return transform(sourceProjection, getMapProjection(map), point);
111
111
  }
112
112
 
@@ -117,6 +117,16 @@ export function transformToMapProjection (map, sourceProjection, point) {
117
117
  * @param {number[]} point - point to project
118
118
  * @returns {(number[]|undefined)} new point or undefined
119
119
  */
120
- export function transformFromMapProjection (map, targetProjection, point) {
120
+ function transformFromMapProjection (map, targetProjection, point) {
121
121
  return transform(getMapProjection(map), targetProjection, point);
122
122
  }
123
+
124
+ export default {
125
+ transformFromMapProjection,
126
+ transformToMapProjection,
127
+ transform,
128
+ getMapProjection,
129
+ getProjections,
130
+ registerProjections,
131
+ getProjection
132
+ };
package/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {createMapView} from "./maps/mapView";
2
- import * as crs from "./crs";
3
- import * as rawLayerList from "./rawLayerList";
2
+ import crs from "./crs";
3
+ import rawLayerList from "./rawLayerList";
4
4
  import * as wms from "./layer/wms";
5
5
  import * as wmts from "./layer/wmts";
6
6
  import * as wfs from "./layer/wfs";
package/src/layer/wms.js CHANGED
@@ -5,7 +5,7 @@ import TileGrid from "ol/tilegrid/TileGrid";
5
5
  import ImageWMS from "ol/source/ImageWMS.js";
6
6
  import {get as getProjection} from "ol/proj";
7
7
 
8
- import {getLayerWhere} from "../rawLayerList";
8
+ import rawLayerList from "../rawLayerList";
9
9
 
10
10
  const OLCS_DEFAULT_OLCS_PROJECTION_CRS = "EPSG:3857";
11
11
 
@@ -176,7 +176,7 @@ export function updateSource (layer) {
176
176
  * @returns {(string|undefined)} the gfiURL, or undefined if it could not be constructed
177
177
  */
178
178
  export function getGfiURL (layer, map, coordinate) {
179
- const rawLayer = getLayerWhere({Id: layer.get("id")}),
179
+ const rawLayer = rawLayerList.getLayerWhere({Id: layer.get("id")}),
180
180
  resolution = map.getView().getResolution(),
181
181
  projection = map.getView().getProjection(),
182
182
  params = Object.assign({
@@ -4,7 +4,7 @@
4
4
  * @param {Function} callback - the Function to call after loading has completed
5
5
  * @returns {undefined}
6
6
  */
7
- export function load3DScript (fileName, callback) {
7
+ function load3DScript (fileName, callback) {
8
8
  const head = document.getElementsByTagName("head")[0],
9
9
  script = document.createElement("script");
10
10
 
@@ -20,3 +20,7 @@ export function load3DScript (fileName, callback) {
20
20
  };
21
21
  head.appendChild(script);
22
22
  }
23
+
24
+ export default {
25
+ load3DScript
26
+ };
@@ -1,5 +1,5 @@
1
1
  import {Map} from "ol";
2
- import {defaults as olDefaultInteractions} from "ol/interaction.js";
2
+ import {DragPan, defaults as olDefaultInteractions} from "ol/interaction.js";
3
3
  import setBackgroundImage from "../../lib/setBackgroundImage";
4
4
  import getInitialLayers from "../../lib/getInitialLayers";
5
5
  import defaults from "../../defaults";
@@ -11,8 +11,8 @@ import * as vectorBase from "../../layer/vectorBase";
11
11
  import * as vectortile from "../../layer/vectorTile";
12
12
  import * as oaf from "../../layer/oaf";
13
13
  import {createMapView} from "../../maps/mapView";
14
- import {initializeLayerList, getLayerWhere} from "../../rawLayerList";
15
- import {registerProjections} from "../../crs";
14
+ import rawLayerList from "../../rawLayerList";
15
+ import crs from "../../crs";
16
16
  import {setGazetteerUrl} from "../../searchAddress";
17
17
 
18
18
  let mapIdCounter = 0;
@@ -97,7 +97,7 @@ function addLayer (layerOrId, params = {visibility: true, transparency: 0, error
97
97
 
98
98
  // if parameter is id, create and add layer with masterportalAPI mechanisms
99
99
  if (typeof layerOrId === "string") {
100
- const rawLayer = getLayerWhere({id: layerOrId});
100
+ const rawLayer = rawLayerList.getLayerWhere({id: layerOrId});
101
101
 
102
102
  if (!rawLayer) {
103
103
  console.error("Layer with id '" + layerOrId + "' not found. No layer added to map.");
@@ -146,12 +146,18 @@ Map.prototype.addLayer = addLayer;
146
146
  * @returns {object} map object from ol
147
147
  */
148
148
  export function createMap (config = defaults, {mapParams, callback, errorCallback} = {}) {
149
- registerProjections(config.namedProjections);
149
+ crs.registerProjections(config.namedProjections);
150
150
  setBackgroundImage(config);
151
151
  setGazetteerUrl(config.gazetteerUrl);
152
152
  const map = new Map(Object.assign({
153
153
  target: config.target || defaults.target,
154
- interactions: olDefaultInteractions({altShiftDragRotate: false, pinchRotate: false}),
154
+ interactions: olDefaultInteractions({dragPan: false, altShiftDragRotate: false, pinchRotate: false}).extend([
155
+ new DragPan({
156
+ condition: function (event) {
157
+ return (!event.originalEvent.pointerType || event.originalEvent.pointerType === "mouse") || (config.twoFingerPan && this.getPointerCount() === 2) || !config.twoFingerPan;
158
+ }
159
+ })
160
+ ]),
155
161
  controls: [],
156
162
  view: createMapView(config)
157
163
  }, mapParams));
@@ -160,7 +166,7 @@ export function createMap (config = defaults, {mapParams, callback, errorCallbac
160
166
  map.set("id", `map2D_${mapIdCounter++}`);
161
167
 
162
168
  // extend callback to load configured initial layers
163
- initializeLayerList(config.layerConf, (param, error) => {
169
+ rawLayerList.initializeLayerList(config.layerConf, (param, error) => {
164
170
  getInitialLayers(config)
165
171
  .forEach(layer => {
166
172
  map.addLayer(layer.id, {errorCallback});
@@ -14,7 +14,7 @@ let layerList = [];
14
14
  * @param {function} [callback] - called with services after loaded; called with false and error on error
15
15
  * @returns {undefined} nothing, add callback to receive layerList
16
16
  */
17
- export function initializeLayerList (layerConf = defaults.layerConf, callback) {
17
+ function initializeLayerList (layerConf = defaults.layerConf, callback) {
18
18
  if (Array.isArray(layerConf)) {
19
19
  // case: parameter was services.json contents
20
20
  layerList = layerConf;
@@ -55,14 +55,14 @@ export function initializeLayerList (layerConf = defaults.layerConf, callback) {
55
55
  * @param {object} searchAttributes - key/value-pairs to be searched for, e.g. { typ: "WMS" } to get the first WMS
56
56
  * @returns {?object} first layer matching the searchAttributes or null if none was found
57
57
  */
58
- export function getLayerWhere (searchAttributes) {
58
+ function getLayerWhere (searchAttributes) {
59
59
  const keys = Object.keys(searchAttributes);
60
60
 
61
61
  return layerList.find(entry => keys.every(key => entry[key] === searchAttributes[key])) || null;
62
62
  }
63
63
 
64
64
  /** @returns {object[]} complete layerList as initialized */
65
- export function getLayerList () {
65
+ function getLayerList () {
66
66
  return layerList;
67
67
  }
68
68
 
@@ -72,7 +72,7 @@ export function getLayerList () {
72
72
  * @param {string} [featureAttribute] - if given, only one entry of map is returned
73
73
  * @returns {?(object|string)} - map of originalName->displayName or name of featureAttribute if specified; if layer or featureAttribute not found, null
74
74
  */
75
- export function getDisplayNamesOfFeatureAttributes (layerId, featureAttribute) {
75
+ function getDisplayNamesOfFeatureAttributes (layerId, featureAttribute) {
76
76
  const attributes = getLayerWhere({id: layerId});
77
77
 
78
78
  if (attributes && typeof featureAttribute === "string") {
@@ -86,3 +86,11 @@ export function getDisplayNamesOfFeatureAttributes (layerId, featureAttribute) {
86
86
 
87
87
  return null;
88
88
  }
89
+
90
+
91
+ export default {
92
+ getLayerWhere,
93
+ getDisplayNamesOfFeatureAttributes,
94
+ initializeLayerList,
95
+ getLayerList
96
+ };
package/test/crs.test.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {Map, View} from "ol";
2
2
  import proj4 from "proj4";
3
3
  import * as Proj from "ol/proj.js";
4
- import * as crs from "../src/crs";
4
+ import crs from "../src/crs";
5
5
 
6
6
  const namedProjections = [
7
7
  ["EPSG:31467", "+title=Bessel/Gauß-Krüger 3 +proj=tmerc +lat_0=0 +lon_0=9 +k=1 +x_0=3500000 +y_0=0 +ellps=bessel +datum=potsdam +units=m +no_defs"],
@@ -6,7 +6,7 @@ import {Feature} from "ol";
6
6
  import Polygon from "ol/geom/Polygon";
7
7
 
8
8
  import * as vectorTile from "../../src/layer/vectorTile";
9
- import {registerProjections} from "../../src/crs";
9
+ import crs from "../../src/crs";
10
10
  import defaults from "../../src/defaults";
11
11
 
12
12
  jest.mock("../../src/rawLayerList.js", () => {
@@ -18,7 +18,7 @@ jest.mock("../../src/rawLayerList.js", () => {
18
18
 
19
19
  describe("vectorTile.js", function () {
20
20
 
21
- beforeAll(() => registerProjections());
21
+ beforeAll(() => crs.registerProjections());
22
22
 
23
23
  const layerParams = {
24
24
  name: "VT Test",
package/test/map.test.js CHANGED
@@ -2,12 +2,12 @@ import {Map} from "ol";
2
2
  import TileLayer from "ol/layer/Tile";
3
3
  import map from "../src/maps/map.js";
4
4
  import {createMap as create3DMap} from "../src/maps/olcs/olcsMap.js";
5
- import {initializeLayerList} from "../src/rawLayerList.js";
6
- import {registerProjections} from "../src/crs.js";
5
+ import rawLayerList from "../src/rawLayerList.js";
6
+ import crs from "../src/crs.js";
7
7
  import setBackgroundImage from "../src/lib/setBackgroundImage.js";
8
8
  import {createMapView} from "../src/maps/mapView";
9
9
  import defaults from "../src/defaults";
10
- import {load3DScript} from "../src/lib/load3DScript";
10
+ import load3DScriptModule from "../src/lib/load3DScript";
11
11
 
12
12
  /*
13
13
  * This test is mocking a lot to check what functions are called with.
@@ -15,18 +15,23 @@ import {load3DScript} from "../src/lib/load3DScript";
15
15
  */
16
16
  jest.mock("ol");
17
17
  jest.mock("../src/rawLayerList.js", () => {
18
- const original = jest.requireActual("../src/rawLayerList.js");
19
-
20
- original.getLayerWhere = ({id}) => ({
21
- exists: {
22
- typ: "doesntExist"
23
- },
24
- works: {
25
- typ: "WMS"
18
+ const originalModule = jest.requireActual("../src/rawLayerList.js");
19
+
20
+ return {
21
+ __esModule: true,
22
+ ...originalModule,
23
+ default: {
24
+ getLayerWhere: ({id}) => ({
25
+ exists: {
26
+ typ: "doesntExist"
27
+ },
28
+ works: {
29
+ typ: "WMS"
30
+ }
31
+ })[id],
32
+ initializeLayerList: jest.fn()
26
33
  }
27
- })[id];
28
- original.initializeLayerList = jest.fn();
29
- return original;
34
+ };
30
35
  });
31
36
  jest.mock("../src/crs.js");
32
37
  jest.mock("../src/lib/setBackgroundImage.js");
@@ -38,8 +43,8 @@ describe("map.js", function () {
38
43
  const callback = jest.fn();
39
44
 
40
45
  map.createMap(defaults, "2D", {mapParams: {}, callback: callback});
41
- expect(initializeLayerList).toHaveBeenCalledWith(defaults.layerConf, expect.any(Function));
42
- expect(registerProjections).toHaveBeenCalledWith(defaults.namedProjections);
46
+ expect(rawLayerList.initializeLayerList).toHaveBeenCalledWith(defaults.layerConf, expect.any(Function));
47
+ expect(crs.registerProjections).toHaveBeenCalledWith(defaults.namedProjections);
43
48
  expect(setBackgroundImage).toHaveBeenCalledWith(defaults);
44
49
  });
45
50
 
@@ -70,7 +75,7 @@ describe("map.js", function () {
70
75
  cesiumLib: "https://lib.virtualcitymap.de/v3.6.x/lib/Cesium/Cesium.js"
71
76
  };
72
77
 
73
- load3DScript(config.cesiumLib, function Loaded3DCallback () {
78
+ load3DScriptModule.load3DScript(config.cesiumLib, function Loaded3DCallback () {
74
79
  const map3D = map.createMap(config, "3D");
75
80
 
76
81
  expect(create3DMap).toHaveBeenCalledWith(defaults);
@@ -163,7 +168,7 @@ describe("map.js", function () {
163
168
  cesiumLib: "https://lib.virtualcitymap.de/v3.6.x/lib/Cesium/Cesium.js"
164
169
  };
165
170
 
166
- load3DScript(config.cesiumLib, function Loaded3DCallback () {
171
+ load3DScriptModule.load3DScript(config.cesiumLib, function Loaded3DCallback () {
167
172
  const map3D = map.createMap(config, "3D");
168
173
 
169
174
  expect(map3D.mapMode).toBe("3D");
@@ -198,7 +203,7 @@ describe("map.js", function () {
198
203
  cesiumLib: "https://lib.virtualcitymap.de/v3.6.x/lib/Cesium/Cesium.js"
199
204
  };
200
205
 
201
- load3DScript(config.cesiumLib, function Loaded3DCallback () {
206
+ load3DScriptModule.load3DScript(config.cesiumLib, function Loaded3DCallback () {
202
207
  const map3D = map.createMap(config, "3D");
203
208
 
204
209
  expect(map3D.mapMode).toBe("3D");
@@ -243,7 +248,7 @@ describe("map.js", function () {
243
248
  cesiumLib: "https://lib.virtualcitymap.de/v3.6.x/lib/Cesium/Cesium.js"
244
249
  };
245
250
 
246
- load3DScript(config.cesiumLib, function Loaded3DCallback () {
251
+ load3DScriptModule.load3DScript(config.cesiumLib, function Loaded3DCallback () {
247
252
  const map3D = map.createMap(config, "3D");
248
253
 
249
254
  expect(map3D.mapMode).toBe("3D");
@@ -279,7 +284,7 @@ describe("map.js", function () {
279
284
  cesiumLib: "https://lib.virtualcitymap.de/v3.6.x/lib/Cesium/Cesium.js"
280
285
  };
281
286
 
282
- load3DScript(config.cesiumLib, function Loaded3DCallback () {
287
+ load3DScriptModule.load3DScript(config.cesiumLib, function Loaded3DCallback () {
283
288
  const map3D = map.createMap(config, "3D");
284
289
 
285
290
  expect(map3D.mapMode).toBe("3D");
@@ -1,4 +1,4 @@
1
- import * as rll from "../src/rawLayerList";
1
+ import rll from "../src/rawLayerList";
2
2
 
3
3
  const symbol = Symbol(),
4
4
  services = [