@masterportal/masterportalapi 2.9.0 → 2.11.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,30 +3,27 @@
3
3
 
4
4
  The [Semantic Versioning](https://semver.org/spec/v2.0.0.html) is used.
5
5
 
6
- ## Unreleased - in development
6
+ ## 2.11.0 - 2022-11-24
7
7
  ### Added
8
-
9
- ### Changed
10
-
11
- ### Deprecated
12
-
13
- ### Removed
8
+ - crossOrigin settings can now be passed to WMSSources (TileWMS, ImageWMS) via config.json or services.json
14
9
 
15
10
  ### Fixed
11
+ - Issue #847(Masterportal): searchAddress now keeps searching for house numbers if a digit was entered at the end of the search string
16
12
 
17
13
  ---
18
14
 
19
- ## 2.9.0 - 2022-10-25
15
+ ## 2.10.0 - 2022-11-03
20
16
  ### Added
17
+ - DPS-1313: Added custom DragPan interaction to add ability to use 2-Finger-Pan instead of 1-Finger-Pan on mobile devices
21
18
 
22
19
  ### Changed
23
- - Exports in src/rawLayerList and src/crs.js changed to module.exports to provide the possibility to stub the functions with sinon in masterportal.
20
+ - Exports in src/rawLayerList, src/crs.js and src/lib/load3DScript.js changed to export default {} to provide ES-Syntax.
24
21
 
25
- ### Deprecated
26
-
27
- ### Removed
22
+ ---
28
23
 
29
- ### Fixed
24
+ ## 2.9.0 - 2022-10-25
25
+ ### Changed
26
+ - Exports in src/rawLayerList and src/crs.js changed to module.exports to provide the possibility to stub the functions with sinon in masterportal.
30
27
 
31
28
  ---
32
29
 
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.9.0",
4
+ "version": "2.11.0",
5
5
  "license": "MIT",
6
6
  "description": "Basic functions of the Masterportal as api",
7
7
  "repository": {
@@ -53,6 +53,7 @@
53
53
  },
54
54
  "homepage": "https://bitbucket.org/geowerkstatt-hamburg/masterportalapi#readme",
55
55
  "directories": {
56
+ "doc": "docs",
56
57
  "example": "example",
57
58
  "test": "test"
58
59
  },
package/src/crs.js CHANGED
@@ -121,7 +121,7 @@ function transformFromMapProjection (map, targetProjection, point) {
121
121
  return transform(getMapProjection(map), targetProjection, point);
122
122
  }
123
123
 
124
- module.exports = {
124
+ export default {
125
125
  transformFromMapProjection,
126
126
  transformToMapProjection,
127
127
  transform,
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 {rawLayerList} from "../index.js";
8
+ import rawLayerList from "../rawLayerList";
9
9
 
10
10
  const OLCS_DEFAULT_OLCS_PROJECTION_CRS = "EPSG:3857";
11
11
 
@@ -82,6 +82,7 @@ export function makeParams (rawLayer) {
82
82
  * @param {string} [rawLayer.gutter] - optional the size in pixels of the gutter around image tiles to ignore
83
83
  * @param {function} [rawLayer.olAttribution] - optional function that takes a module:ol/Map~FrameState and returns a string or an array of strings representing source attributions
84
84
  * @param {string|number} [rawLayer.tilesize] - optional needed to create the tileGrid
85
+ * @param {string|"anonymous"} [rawLayer.crossOrigin] - optional needed for CORS requests of image data, to enable canvas export
85
86
  * @param {object} options - optional resolutions and origin to create the TileGrid
86
87
  * @param {Array} [options.resolutions] - optional resolutions to create the TileGrid, must be in descending order
87
88
  * @param {Array} [options.origin] - optional origin to create the TileGrid
@@ -99,7 +100,8 @@ export function createLayerSource (rawLayer, options) {
99
100
  params,
100
101
  serverType: rawLayer.serverType,
101
102
  projection: projection,
102
- attributions: rawLayer.olAttribution
103
+ attributions: rawLayer.olAttribution,
104
+ crossOrigin: rawLayer.crossOrigin
103
105
  });
104
106
  }
105
107
  if (options && options.resolutions) {
@@ -115,7 +117,8 @@ export function createLayerSource (rawLayer, options) {
115
117
  gutter: rawLayer.gutter || 0,
116
118
  tileGrid: tileGrid,
117
119
  projection: projection,
118
- attributions: rawLayer.olAttribution
120
+ attributions: rawLayer.olAttribution,
121
+ crossOrigin: rawLayer.crossOrigin
119
122
  });
120
123
  }
121
124
 
@@ -130,6 +133,7 @@ export function createLayerSource (rawLayer, options) {
130
133
  * @param {string} [rawLayer.gutter] - optional the size in pixels of the gutter around image tiles to ignore
131
134
  * @param {function} [rawLayer.olAttribution] - optional function that takes a module:ol/Map~FrameState and returns a string or an array of strings representing source attributions
132
135
  * @param {string|number} [rawLayer.tilesize] - optional needed to create the tileGrid
136
+ * @param {string|"anonymous"} [rawLayer.crossOrigin] - optional needed for CORS requests of image data, to enable canvas export
133
137
  * @param {object} layerParams - additional layer params
134
138
  * @param {object} options - optional resolutions and origin to create the TileGrid
135
139
  * @param {Array} [options.resolutions] - optional resolutions to create the TileGrid, must be in descending order
@@ -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 {rawLayerList} from "../../index.js";
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;
@@ -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));
@@ -88,7 +88,7 @@ function getDisplayNamesOfFeatureAttributes (layerId, featureAttribute) {
88
88
  }
89
89
 
90
90
 
91
- module.exports = {
91
+ export default {
92
92
  getLayerWhere,
93
93
  getDisplayNamesOfFeatureAttributes,
94
94
  initializeLayerList,
@@ -10,16 +10,19 @@ let abortController = null;
10
10
  * Chains gazetteer request and response parser.
11
11
  * @param {string} type from searchTypes
12
12
  * @param {(string|string[])} values one or multiple strings, depending on type
13
+ * @param {function} sortFunction a function with two parameters which can be used to sort all results
14
+ * @param {function} filterFunction a function which will be executed to filter results
13
15
  * @returns {Promise<SearchResult[]>} parsed response
14
16
  * @ignore
15
17
  */
16
- function searchAndParse (type, values) {
18
+ function searchAndParse (type, values, sortFunction = (a, b) => a.name.localeCompare(b.name), filterFunction = () => true) {
17
19
  return new Promise((resolve, reject) => {
18
20
  searchGazetteer(type, values, abortController)
19
21
  .then(results => {
20
- const parsed = parse(type, results);
21
-
22
- resolve(parsed);
22
+ parse(type, results).then(parsed => {
23
+ resolve(parsed.filter(filterFunction)
24
+ .sort(sortFunction));
25
+ });
23
26
  })
24
27
  .catch(e => reject(e));
25
28
  });
@@ -38,7 +41,8 @@ function searchAndParseStreetAndHouseNumber (searchstring, searchHouseNumbers) {
38
41
  searchGazetteer(searchTypes.STREET, searchstring, abortController)
39
42
  .then(streetResults => parse(searchTypes.STREET, streetResults))
40
43
  .then(parsedStreetResults => {
41
- const allSearches = [];
44
+ const allSearches = [],
45
+ matches = searchstring.match(new RegExp("^(.+)[\\s,](\\d+|\\d.*)$"));
42
46
 
43
47
  for (let i = 0; i < parsedStreetResults.length; i++) {
44
48
  // put street in front of street's street+hnr as ordering
@@ -48,6 +52,13 @@ function searchAndParseStreetAndHouseNumber (searchstring, searchHouseNumbers) {
48
52
  }
49
53
  }
50
54
 
55
+ if (!parsedStreetResults.length && matches?.length && searchHouseNumbers) {
56
+ allSearches.push(searchAndParse(searchTypes.HOUSE_NUMBERS_FOR_STREET,
57
+ matches[1],
58
+ (a, b) => parseInt(a.properties?.hausnummer, 10) - parseInt(b.properties?.hausnummer, 10),
59
+ item => item.properties?.hausnummerkomplett?.indexOf(matches[2]) === 0)); // check longer housenumbers and suffixes!
60
+ }
61
+
51
62
  return Promise.all(allSearches);
52
63
  })
53
64
  .then(allResults => resolve([].concat(...allResults)))
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",
@@ -111,6 +111,16 @@ describe("wms.js", function () {
111
111
 
112
112
  expect(source).toBeInstanceOf(ImageWMS);
113
113
  });
114
+ it("creates a LayerSource with crossOrigin set to 'anonymous'", function () {
115
+ // only relevant for TileWMS and ImageWMS instances
116
+ const
117
+ tileWMS = wms.createLayerSource({singleTile: false, crossOrigin: "anonymous"}),
118
+ imageWMS = wms.createLayerSource({singleTile: true, crossOrigin: "anonymous"});
119
+
120
+ // eslint-disable-next-line no-underscore-dangle
121
+ expect(imageWMS.crossOrigin_).toEqual("anonymous");
122
+ expect(tileWMS.crossOrigin).toEqual("anonymous");
123
+ });
114
124
  });
115
125
  describe("createLayerSource with a tileGrid", function () {
116
126
  function attrFunction () {
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 = [