@masterportal/masterportalapi 2.1.1

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.
Files changed (92) hide show
  1. package/.editorconfig +15 -0
  2. package/.eslintignore +6 -0
  3. package/.eslintrc +184 -0
  4. package/.husky/pre-push +4 -0
  5. package/CHANGELOG.md +217 -0
  6. package/License.txt +21 -0
  7. package/README.md +24 -0
  8. package/babel.config.json +6 -0
  9. package/example/README.md +7 -0
  10. package/example/config/localGeoJSON.js +956 -0
  11. package/example/config/portal.json +35 -0
  12. package/example/config/services.json +79 -0
  13. package/example/index.html +27 -0
  14. package/example/index.js +210 -0
  15. package/example/style.scss +59 -0
  16. package/jest.config.js +18 -0
  17. package/jest.setup.js +5 -0
  18. package/jsdoc.json +15 -0
  19. package/package.json +62 -0
  20. package/public/marker.svg +1 -0
  21. package/public/stringMarker.js +5 -0
  22. package/src/crs.js +122 -0
  23. package/src/defaults.js +38 -0
  24. package/src/index.js +30 -0
  25. package/src/layer/geojson/index.js +109 -0
  26. package/src/layer/geojson/style.js +61 -0
  27. package/src/layer/lib.js +32 -0
  28. package/src/layer/oaf.js +207 -0
  29. package/src/layer/terrain.js +72 -0
  30. package/src/layer/tileset.js +71 -0
  31. package/src/layer/vector.js +48 -0
  32. package/src/layer/vectorBase.js +39 -0
  33. package/src/layer/wfs.js +218 -0
  34. package/src/layer/wms.js +185 -0
  35. package/src/lib/coordsToPairs.js +15 -0
  36. package/src/lib/getInitialLayers.js +22 -0
  37. package/src/lib/load3DScript.js +22 -0
  38. package/src/lib/oafUtil.js +22 -0
  39. package/src/lib/setBackgroundImage.js +23 -0
  40. package/src/lib/wfsUtil.js +75 -0
  41. package/src/lib/zoomTo.js +40 -0
  42. package/src/maps/api.js +5 -0
  43. package/src/maps/map.js +35 -0
  44. package/src/maps/mapView.js +54 -0
  45. package/src/maps/ol/olMap.js +124 -0
  46. package/src/maps/olcs/3dUtils/fixedOverlaySynchronizer.js +39 -0
  47. package/src/maps/olcs/3dUtils/wmsRasterSynchronizer.js +348 -0
  48. package/src/maps/olcs/olcsMap.js +212 -0
  49. package/src/rawLayerList.js +88 -0
  50. package/src/searchAddress/gazetteerUrl.js +22 -0
  51. package/src/searchAddress/index.js +13 -0
  52. package/src/searchAddress/parse.js +196 -0
  53. package/src/searchAddress/search.js +184 -0
  54. package/src/searchAddress/searchGazetteer.js +52 -0
  55. package/src/searchAddress/showGeographicIdentifier.js +20 -0
  56. package/src/searchAddress/types.js +17 -0
  57. package/test/.eslintrc +7 -0
  58. package/test/crs.test.js +109 -0
  59. package/test/layer/geojson/index.test.js +133 -0
  60. package/test/layer/geojson/style.test.js +46 -0
  61. package/test/layer/lib.test.js +83 -0
  62. package/test/layer/oaf.test.js +245 -0
  63. package/test/layer/resources/oafFeatures.js +105 -0
  64. package/test/layer/resources/wfsFeatures.js +26 -0
  65. package/test/layer/resources/wfsFilter.js +17 -0
  66. package/test/layer/terrain.test.js +106 -0
  67. package/test/layer/tileset.test.js +116 -0
  68. package/test/layer/vector.test.js +76 -0
  69. package/test/layer/vectorBase.test.js +48 -0
  70. package/test/layer/wfs.test.js +388 -0
  71. package/test/layer/wms.test.js +256 -0
  72. package/test/lib/coordsToPairs.test.js +9 -0
  73. package/test/lib/getInitialLayers.test.js +28 -0
  74. package/test/lib/oafUtil.test.js +24 -0
  75. package/test/lib/setBackgroundImage.test.js +49 -0
  76. package/test/lib/wfsUtil.test.js +28 -0
  77. package/test/lib/zoomTo.test.js +74 -0
  78. package/test/map.test.js +258 -0
  79. package/test/mapView.test.js +59 -0
  80. package/test/rawLayerList.test.js +48 -0
  81. package/test/searchAddress/gazetteerSearchResults/address.js +175 -0
  82. package/test/searchAddress/gazetteerSearchResults/district.js +71 -0
  83. package/test/searchAddress/gazetteerSearchResults/houseNumber.js +32 -0
  84. package/test/searchAddress/gazetteerSearchResults/index.js +19 -0
  85. package/test/searchAddress/gazetteerSearchResults/parcel.js +44 -0
  86. package/test/searchAddress/gazetteerSearchResults/street.js +46 -0
  87. package/test/searchAddress/gazetteerSearchResults/streetKey.js +51 -0
  88. package/test/searchAddress/gazetteerUrl.test.js +22 -0
  89. package/test/searchAddress/parse.test.js +110 -0
  90. package/test/searchAddress/search.test.js +150 -0
  91. package/test/searchAddress/searchGazetteer.test.js +58 -0
  92. package/test/searchAddress/showGeographicIdentifier.test.js +22 -0
@@ -0,0 +1,35 @@
1
+ {
2
+ "target": "map-div-id",
3
+ "epsg": "EPSG:25832",
4
+ "namedProjections": [
5
+ ["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
+ ["EPSG:25832", "+title=ETRS89/UTM 32N +proj=utm +zone=32 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"],
7
+ ["EPSG:8395", "+title=ETRS89/Gauß-Krüger 3 +proj=tmerc +lat_0=0 +lon_0=9 +k=1 +x_0=3500000 +y_0=0 +ellps=GRS80 +datum=GRS80 +units=m +no_defs"],
8
+ ["EPSG:4326", "+title=WGS 84 (long/lat) +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"]
9
+ ],
10
+ "extent": [510000.0, 5850000.0, 625000.4, 6000000.0],
11
+ "options": [
12
+ { "resolution": 264.583190458, "scale": 1000000, "zoomLevel": 0 },
13
+ { "resolution": 132.291595229, "scale": 500000, "zoomLevel": 1 },
14
+ { "resolution": 66.14579761460263, "scale": 250000, "zoomLevel": 2 },
15
+ { "resolution": 26.458319045841044, "scale": 100000, "zoomLevel": 3 },
16
+ { "resolution": 15.874991427504629, "scale": 60000, "zoomLevel": 4 },
17
+ { "resolution": 10.583327618336419, "scale": 40000, "zoomLevel": 5 },
18
+ { "resolution": 5.2916638091682096, "scale": 20000, "zoomLevel": 6 },
19
+ { "resolution": 2.6458319045841048, "scale": 10000, "zoomLevel": 7 },
20
+ { "resolution": 1.3229159522920524, "scale": 5000, "zoomLevel": 8 },
21
+ { "resolution": 0.6614579761460262, "scale": 2500, "zoomLevel": 9 },
22
+ { "resolution": 0.2645831904584105, "scale": 1000, "zoomLevel": 10 },
23
+ { "resolution": 0.13229159522920521, "scale": 500, "zoomLevel": 11 }
24
+ ],
25
+ "startResolution": 132.291595229,
26
+ "startCenter": [565874, 5934140],
27
+ "units": "m",
28
+ "layerConf": "",
29
+ "layers": [
30
+ {
31
+ "id": "1001"
32
+ }
33
+ ],
34
+ "cesiumLib":"https://geoportal-hamburg.de/mastercode/cesium/1_88/Cesium.js"
35
+ }
@@ -0,0 +1,79 @@
1
+ [
2
+ {
3
+ "id": "1001",
4
+ "typ": "WMS",
5
+ "name": "WebAtlasDe",
6
+ "url": "https://sg.geodatenzentrum.de/wms_webatlasde__54a30b0f-b92f-34ba-39c0-3af32cfa13d6",
7
+ "format": "image/png",
8
+ "version": "1.3.0",
9
+ "layers": "webatlasde",
10
+ "transparent": true,
11
+ "singleTile": false,
12
+ "tilesize": 256,
13
+ "gutter": 0,
14
+ "minScale": 1,
15
+ "maxScale": 200
16
+ },
17
+ {
18
+ "id" : "1002",
19
+ "name" : "Krankenhäuser",
20
+ "url" : "https://geodienste.hamburg.de/HH_WMS_Krankenhaeuser",
21
+ "typ" : "WMS",
22
+ "layers" : "krankenhaeuser",
23
+ "format" : "image/png",
24
+ "version" : "1.3.0",
25
+ "singleTile" : false,
26
+ "transparent" : true,
27
+ "transparency" : 0,
28
+ "urlIsVisible" : true,
29
+ "tilesize" : 512
30
+ },
31
+ {
32
+ "id" : "2001",
33
+ "typ" : "GeoJSON",
34
+ "name" : "Landesgrenze Hamburg",
35
+ "url" : "https://geoportal-hamburg.de/lgv-config/landesgrenze_hh.json"
36
+ },
37
+ {
38
+ "id" : "3001",
39
+ "name" : "Bauwerke",
40
+ "url" : "https://geodienste.hamburg.de/HH_WFS_Geotourismus",
41
+ "typ" : "WFS",
42
+ "featureType" : "bauwerke",
43
+ "outputFormat" : "XML",
44
+ "version" : "1.1.0",
45
+ "featureNS" : "http://www.deegree.org/app"
46
+ },
47
+ {
48
+ "id" : "4001",
49
+ "name" : "Gelaende",
50
+ "url" : "https://daten-hamburg.de/gdi3d/datasource-data/Gelaende ",
51
+ "typ" : "Terrain3D",
52
+ "cesiumTerrainProviderOptions" : {
53
+ "requestVertexNormals" : true
54
+ }
55
+ },
56
+ {
57
+ "id" : "4002",
58
+ "name" : "Gebäude LoD2",
59
+ "url" : "https://daten-hamburg.de/gdi3d/datasource-data/LoD2",
60
+ "typ" : "TileSet3D",
61
+ "cesium3DTilesetOptions" : {
62
+ "maximumScreenSpaceError" : 6
63
+ }
64
+ },
65
+ {
66
+ "id": "5001",
67
+ "name": "Schulen",
68
+ "url": "https://api.hamburg.de/datasets/v1/schulen",
69
+ "collection" : "staatliche_schulen",
70
+ "typ": "OAF",
71
+ "bbox": "",
72
+ "bboxCrs": "",
73
+ "datetime": "",
74
+ "crs": "EPSG:25832",
75
+ "params": {
76
+ "anzahl_schueler": ">1000"
77
+ }
78
+ }
79
+ ]
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <!-- this is a test page for the usage of MPAPI -->
4
+ <head>
5
+ <meta charset="utf-8">
6
+ <title>Masterportal API Example</title>
7
+ <link rel="stylesheet" href="style.scss">
8
+ </head>
9
+ <body>
10
+ <div class="mock-body">
11
+ <div class="mock-content">
12
+ <p>
13
+ The example page is meant to simulate an actual website using the Masterportal-API in 2D and 3D. Use this page during development to see your changes live.
14
+ </p>
15
+ <input id="enable" type="button" value="2D/3D" />
16
+ <input id="layer-visibility" type="button" style="display: none;" value="Hintergrundkarte ausblenden" />
17
+ <div class="map-background">
18
+ <!-- map is supposed to render itself in this div -->
19
+ <div id="map-div-id"></div>
20
+ <div id="controls"></div>
21
+ </div>
22
+ </div>
23
+ </div>
24
+ <script type="module" src="./index.js"></script>
25
+
26
+ </body>
27
+ </html>
@@ -0,0 +1,210 @@
1
+ import "ol/ol.css";
2
+
3
+ import {Style, Stroke, Fill, Icon} from "ol/style.js";
4
+
5
+ import * as mpapi from "../src";
6
+ import mapsAPI from "../src/maps/api.js";
7
+ import {getLayerWhere} from "../src/rawLayerList";
8
+
9
+ import services from "./config/services.json";
10
+ import portalConfig from "./config/portal.json";
11
+ import localGeoJSON from "./config/localGeoJSON.js";
12
+ import {load3DScript} from "../src/lib/load3DScript";
13
+
14
+ //* Add elements to window to play with API in console
15
+ window.mpapi = {
16
+ ...mpapi,
17
+ map2D: null,
18
+ map: null
19
+ };
20
+ // */
21
+ //* Cleans up map before it is re-rendered (happens on every save during dev mode)
22
+ document.getElementById(portalConfig.target).innerHTML = "";
23
+ // add a click-listener to button, that creates a 3D-map on click
24
+ document.getElementById("enable").addEventListener("click", function () {
25
+ if (window.mpapi.map2D === null) {
26
+ window.mpapi.map2D = window.mpapi.map;
27
+ }
28
+
29
+ if (window.mpapi.map.mapMode === "3D") {
30
+ window.mpapi.map.setEnabled(false);
31
+ window.mpapi.map = window.mpapi.map2D;
32
+ document.getElementById("layer-visibility").style.display = "none";
33
+ ["1001", "2001", "2002", "1002", "3001", "5001"].forEach(id => window.mpapi.map.addLayer(id));
34
+ }
35
+ else {
36
+ const lib = portalConfig.cesiumLib ? portalConfig.cesiumLib : "https://geoportal-hamburg.de/mastercode/cesium/1_88/Cesium.js";
37
+
38
+ document.getElementById("layer-visibility").style.display = "block";
39
+
40
+ load3DScript(lib, function Loaded3DCallback () {
41
+ let terrainLayer = null, tilesetLayer = null;
42
+ const toRemove = ["2001", "2002", "1002", "3001", "5001"];
43
+
44
+ layers2D.forEach(layer => {
45
+ const layerId = layer?.id || layer?.values_?.id;
46
+ if(toRemove.find(id => id === layerId)){
47
+ map2D.removeLayer(layer);
48
+ }
49
+ });
50
+
51
+ const settings3D = {
52
+ "map2D": window.mpapi.map2D
53
+ },
54
+ map3D = mapsAPI.map.createMap(settings3D, "3D"),
55
+ rawLayerTerrain = getLayerWhere({id: "4001"}),
56
+ rawLayerTileset = getLayerWhere({id: "4002"}),
57
+ scene = map3D.getCesiumScene();
58
+
59
+ //set some options to Cesium scene
60
+ scene.globe.enableLighting = true;
61
+ scene.globe.tileCacheSize = 20;
62
+ scene.globe.maximumScreenSpaceError =2;
63
+ scene.fxaa = true;
64
+ scene.highDynamicRange = false;
65
+ scene.pickTranslucentDepth = true;
66
+
67
+ window.mpapi.map = map3D;
68
+ tilesetLayer = new mpapi.Tileset(rawLayerTileset, window.mpapi.map);
69
+ tilesetLayer.setVisible(true, window.mpapi.map);
70
+
71
+ window.mpapi.map.setEnabled(true);
72
+
73
+ terrainLayer = mpapi.terrain.createLayer(rawLayerTerrain, window.mpapi.map);
74
+ terrainLayer.setVisible(true, rawLayerTerrain, window.mpapi.map);
75
+
76
+ });
77
+ }
78
+ });
79
+
80
+ // add a click-listener to button, that hides background layer in 3d
81
+ document.getElementById("layer-visibility").addEventListener("click", function () {
82
+ map2D.getLayers().forEach(layer => {
83
+ map2D.removeLayer(layer);
84
+ });
85
+ });
86
+
87
+ //* Fake service that holds client-side prepared geojson; also nice to test automatic transformation since data is in WGS 84
88
+ // eslint-disable-next-line no-unused-vars
89
+ const hamburgServicesUrl = "http://geoportal-hamburg.de/lgv-config/services-internet.json",
90
+ localService = {
91
+ id: "2002",
92
+ typ: "GeoJSON",
93
+ features: localGeoJSON
94
+ },
95
+ config = {
96
+ ...portalConfig,
97
+ layerConf: services
98
+ },
99
+ map2D = mapsAPI.map.createMap(config, "2D"),
100
+ layers2D = [];
101
+
102
+ services.push(localService);
103
+ // */
104
+
105
+ //* geojson styling function call to override default styling and special wfs styling
106
+ mpapi.geojson.setCustomStyles({
107
+ MultiPolygon: new Style({
108
+ stroke: new Stroke({
109
+ width: 2,
110
+ color: "#000000"
111
+ }),
112
+ fill: new Fill({
113
+ color: "#FFFFFF55"
114
+ })
115
+ })
116
+ });
117
+
118
+ // eslint-disable-next-line
119
+ const styleWfs = function (feature, resolution) {
120
+ const icon = new Style({
121
+ image: new Icon({
122
+ src: "https://img.icons8.com/windows/50/000000/building.png",
123
+ scale: 0.5,
124
+ opacity: 1
125
+ })
126
+ });
127
+
128
+ return [icon];
129
+ };
130
+
131
+ services.find(({id}) => id === "3001").style = styleWfs;
132
+ // */
133
+
134
+
135
+ // eslint-disable-next-line
136
+ const styleOaf = function (feature, resolution) {
137
+ const icon = new Style({
138
+ image: new Icon({
139
+ src: "https://geodienste.hamburg.de/lgv-config/img/gymnasien.svg",
140
+ scale: 0.5,
141
+ opacity: 1
142
+ })
143
+ });
144
+
145
+ return [icon];
146
+ };
147
+
148
+ services.find(({id}) => id === "5001").style = styleOaf;
149
+
150
+ //* SYNCHRONOUS EXAMPLE: layerConf is known
151
+ window.mpapi.map = map2D;
152
+
153
+ ["2001", "2002", "1002", "3001", "5001"].forEach(id => window.mpapi.map.addLayer(id));
154
+ map2D.getLayers().forEach(layer => {
155
+ layers2D.push(layer);
156
+ });
157
+
158
+ // */
159
+
160
+ /* ASYNCHRONOUS EXAMPLE 1: work with layerConf callback
161
+ document.getElementById("enable").style.display = "none";
162
+ mpapi.rawLayerList.initializeLayerList(
163
+ hamburgServicesUrl,
164
+ conf => {
165
+ window.mpapi.map = mapsAPI.map.createMap({
166
+ ...portalConfig,
167
+ layerConf: conf,
168
+ layers: null
169
+ }, "2D");
170
+ ["6357", "6074"].forEach(
171
+ id => window.mpapi.map.addLayer(id)
172
+ );
173
+ }
174
+ );
175
+ //*/
176
+
177
+ /* ASYNCHRONOUS EXAMPLE 2: work with createMap callback
178
+ document.getElementById("enable").style.display = "none";
179
+ window.mpapi.map = mapsAPI.map.createMap(
180
+ {...portalConfig, layerConf: hamburgServicesUrl, layers: [
181
+ { id: "6357" },
182
+ { id: "453", transparency: 50 }
183
+ ]}, "2D",
184
+ {
185
+ callback: () =>
186
+ ["6074"].forEach(
187
+ id => window.mpapi.map.addLayer(id)
188
+ )
189
+ }
190
+ );
191
+ //*/
192
+
193
+ /* SEARCH FUNCTION EXAMPLE
194
+ // You may e.g. copy this code to the browser's console to run a search.
195
+
196
+ window.mpapi.search("Eiffe", {
197
+ map: window.mpapi.map,
198
+ zoom: true,
199
+ zoomToParams: {duration: 1000, maxZoom: 8},
200
+ searchStreets: true
201
+ }).then(x => console.log(x)).catch(e => console.error(e))
202
+
203
+ window.mpapi.search("Mümmelmannsberg 72", {
204
+ map: window.mpapi.map,
205
+ zoom: true,
206
+ zoomToParams: {duration: 1000, maxZoom: 8},
207
+ searchAddress: true
208
+ }).then(x => console.log(x)).catch(e => console.error(e))
209
+
210
+ //*/
@@ -0,0 +1,59 @@
1
+ /* CSS for example page. Do not manipulate map itself here, has no effect on prod. */
2
+ html, body {
3
+ display: flex;
4
+ flex-direction: column;
5
+ margin: 0;
6
+ height: 100%;
7
+ font-family: sans-serif;
8
+
9
+ .mock-body {
10
+ display: flex;
11
+ flex-direction: row;
12
+ flex-wrap: nowrap;
13
+ height: 100%;
14
+
15
+ .mock-content {
16
+ padding: 1em;
17
+ color: black;
18
+ background: #E0E0E0;
19
+ flex-grow: 1;
20
+ display: flex;
21
+ flex-direction: column;
22
+ .content-mock {
23
+ padding: 0.2em;
24
+ }
25
+ }
26
+
27
+ /* Not part of MPAPI, but really nice if no background image is configured. */
28
+ .map-background {
29
+ background: #22222222;
30
+ flex-grow: 1;
31
+
32
+ #map-div-id {
33
+ /* map container needs a defined height */
34
+ height: 100%;
35
+ }
36
+
37
+ #controls {
38
+ right: 15px;
39
+ top: 160px;
40
+ padding: 10px;
41
+ text-align: right;
42
+ position: absolute;
43
+ z-index: 50;
44
+ opacity: 0.9;
45
+ background-color: transparent;
46
+
47
+ input:first-child {
48
+ font-size: 17px;
49
+ margin-top: 4px;
50
+ padding: 6px 6px 6px 6px;
51
+ font-family: "MasterPortalFont Bold", "Arial Narrow", Arial, sans-serif;
52
+ color: #f3f3f3;
53
+ background-color: #E10019;
54
+ box-shadow: 0 6px 12px rgb(0 0 0 / 18%);
55
+ }
56
+ }
57
+ }
58
+ }
59
+ }
package/jest.config.js ADDED
@@ -0,0 +1,18 @@
1
+ /* eslint-env node */
2
+ module.exports = {
3
+ /** ol prints errors without HTMLCanvasElement being available in test environment */
4
+ "setupFiles": ["jest-canvas-mock"],
5
+ /** node_modules are usually ignored by babel-jest, but ol is published in ES6 */
6
+ "transformIgnorePatterns": ["/node_modules/(?!(ol|olcs|ol-mapbox-style|geotiff)/).*/"],
7
+ /** only consider files in src/ for coverage */
8
+ "collectCoverageFrom": ["src/**/*.js"],
9
+ /** coverage reporters */
10
+ "coverageReporters": ["json", "lcov", "text", "clover", "cobertura"],
11
+ /** mapping svg to string representation since jest can't handle svg */
12
+ "moduleNameMapper": {
13
+ "marker.svg": "<rootDir>/public/stringMarker.js"
14
+ },
15
+ "testEnvironment": "jsdom",
16
+ "setupFilesAfterEnv": ["./jest.setup.js"],
17
+ "verbose": true
18
+ };
package/jest.setup.js ADDED
@@ -0,0 +1,5 @@
1
+ import "regenerator-runtime/runtime";
2
+
3
+ window.URL.createObjectURL = function () {
4
+ // empty
5
+ };
package/jsdoc.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "tags": {
3
+ "allowUnknownTags": true,
4
+ "dictionaries": ["jsdoc", "closure"]
5
+ },
6
+ "source": {
7
+ "includePattern": ".+\\.js(doc|x)?$",
8
+ "excludePattern": ""
9
+ },
10
+ "plugins": [],
11
+ "templates": {
12
+ "cleverLinks": false,
13
+ "monospaceLinks": false
14
+ }
15
+ }
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@masterportal/masterportalapi",
3
+ "author": "Implementierungspartnerschaft Masterportal <info@masterportal.org> (https://www.masterportal.org)",
4
+ "version": "2.1.1",
5
+ "license": "MIT",
6
+ "description": "Basic functions of the Masterportal as api",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://bitbucket.org/geowerkstatt-hamburg/masterportalapi.git"
10
+ },
11
+ "main": "src/index.js",
12
+ "scripts": {
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",
15
+ "test:watch": "jest .test.js --config ./jest.config.js --watch",
16
+ "example": "parcel example/index.html",
17
+ "generate-jsdoc": "jsdoc ./src -r -d ./docs/ -R ./README.md -c jsdoc.json",
18
+ "prePushHook": "eslint --max-warnings 0 \"./**/*.js\" && npm run test",
19
+ "prepare": "husky install"
20
+ },
21
+ "dependencies": {
22
+ "core-js": "^3.16.1",
23
+ "ol": "6.13.0",
24
+ "olcs": "^2.13.0",
25
+ "proj4": "^2.7.5",
26
+ "xml2js": "^0.4.23"
27
+ },
28
+ "devDependencies": {
29
+ "@babel/core": "^7.16.7",
30
+ "@babel/plugin-transform-modules-commonjs": "^7.16.8",
31
+ "@parcel/transformer-sass": "^2.2.0",
32
+ "buffer": "^6.0.3",
33
+ "canvas": "^2.8.0",
34
+ "eslint": "^7.32.0",
35
+ "events": "^3.3.0",
36
+ "husky": "^7.0.1",
37
+ "jest": "^27.4.0",
38
+ "jest-canvas-mock": "^2.3.1",
39
+ "jsdoc": "^3.6.7",
40
+ "parcel": "^2.2.0",
41
+ "process": "^0.11.10",
42
+ "regenerator-runtime": "0.13.9",
43
+ "sass": "^1.37.5",
44
+ "stream-browserify": "^3.0.0",
45
+ "timers-browserify": "^2.0.12"
46
+ },
47
+ "peerDependencies": {
48
+ "cesium": "^1.88.0"
49
+ },
50
+ "engines": {
51
+ "node": "^16.13.2",
52
+ "npm": "^8.1.2"
53
+ },
54
+ "homepage": "https://bitbucket.org/geowerkstatt-hamburg/masterportalapi#readme",
55
+ "directories": {
56
+ "example": "example",
57
+ "test": "test"
58
+ },
59
+ "bugs": {
60
+ "url": "https://bitbucket.org/geowerkstatt-hamburg/masterportalapi/issues"
61
+ }
62
+ }
@@ -0,0 +1 @@
1
+ <svg width="23" height="32" viewBox="0 0 30 43" xmlns="http://www.w3.org/2000/svg"><title>DB6C494E-88E8-49F1-89CE-97CBEC3A5240</title><path d="M14.584 1C7.101 1 1 7.101 1 14.584c0 8.103 7.865 20.448 11.63 25.93a2.36 2.36 0 0 0 3.908 0c3.766-5.482 11.63-17.922 11.63-25.93C28.168 7.054 22.068 1 14.584 1z" stroke="#FFF" stroke-width="2" fill="#005CA9" fill-rule="nonzero"/></svg>
@@ -0,0 +1,5 @@
1
+ /**
2
+ * marker.svg as URI. Jest uses this instead since it can't handle SVG files.
3
+ * @ignore
4
+ */
5
+ export default "data:image/svg+xml,%3Csvg%20width%3D%2223%22%20height%3D%2232%22%20viewBox%3D%220%200%2030%2043%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Ctitle%3EDB6C494E-88E8-49F1-89CE-97CBEC3A5240%3C%2Ftitle%3E%3Cpath%20d%3D%22M14.584%201C7.101%201%201%207.101%201%2014.584c0%208.103%207.865%2020.448%2011.63%2025.93a2.36%202.36%200%200%200%203.908%200c3.766-5.482%2011.63-17.922%2011.63-25.93C28.168%207.054%2022.068%201%2014.584%201z%22%20stroke%3D%22%23FFF%22%20stroke-width%3D%222%22%20fill%3D%22%23005CA9%22%20fill-rule%3D%22nonzero%22%2F%3E%3C%2Fsvg%3E%0A";
package/src/crs.js ADDED
@@ -0,0 +1,122 @@
1
+ import proj4 from "proj4";
2
+ import * as Proj from "ol/proj.js";
3
+ import {register} from "ol/proj/proj4.js";
4
+ import defaults from "./defaults";
5
+
6
+
7
+ /**
8
+ * Creates an alias for the srsName.
9
+ * This is necessary for WFS from geoserver.org.
10
+ * @param {string} epsgCode used epsg code in the mapView
11
+ * @returns {void}
12
+ */
13
+ function addAliasForWFSFromGeoserver (epsgCode) {
14
+ const epsgCodeNumber = epsgCode.split(":")[1];
15
+
16
+ proj4.defs("http://www.opengis.net/gml/srs/epsg.xml#" + epsgCodeNumber, proj4.defs(epsgCode));
17
+ register(proj4);
18
+ }
19
+
20
+ /**
21
+ * Returns the proj4 projection definition for a registered name.
22
+ * @param {string} name - projection name as written in [0] position of namedProjections
23
+ * @returns {(object|undefined)} proj4 projection object or undefined
24
+ */
25
+ export function getProjection (name) {
26
+ return proj4.defs(name);
27
+ }
28
+
29
+ /**
30
+ * The configured named projections and proj4 have to be registered initially.
31
+ * @param {string[]} [namedProjections=[
32
+ ["EPSG:25832", "+proj=utm +zone=32 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"]
33
+ ]] - projection name, projection definition string
34
+ * @returns {undefined}
35
+ */
36
+ export function registerProjections (namedProjections = defaults.namedProjections) {
37
+ proj4.defs(namedProjections);
38
+ register(proj4);
39
+ namedProjections.forEach(projection => {
40
+ Proj.addProjection(Proj.get(projection[0]));
41
+ addAliasForWFSFromGeoserver(projection[0]);
42
+ getProjection(projection[0]).masterportal = true;
43
+ });
44
+
45
+ }
46
+
47
+ /**
48
+ * Returns all known projections.
49
+ * @returns {object[]} array of projection objects with their name added
50
+ */
51
+ export function getProjections () {
52
+ const projections = Object
53
+ .keys(proj4.defs)
54
+ .map(name => Object.assign(proj4.defs(name), {name}));
55
+
56
+ // return no duplicates and only the projections which are registred with masterportal=true
57
+ return projections.filter(function (projection, index, self) {
58
+ return index === self.indexOf(projection) && projection.masterportal === true;
59
+ });
60
+ }
61
+
62
+ /**
63
+ * Returns the currently active projection's name of a map's view.
64
+ * @param {ol.Map} map - map to get projection of
65
+ * @returns {string} active projection name of map
66
+ */
67
+ export function getMapProjection (map) {
68
+ return map.getView().getProjection().getCode();
69
+ }
70
+
71
+ /**
72
+ * Resolves a string to a projection object; everything else is returned as-is.
73
+ * If a string can not be resolved, returns undefined.
74
+ * @param {(string|object)} projection - projection name or projection
75
+ * @returns {(object|undefined)} proj4 projection or undefined or parameter
76
+ */
77
+ function getProj4Projection (projection) {
78
+ return typeof projection === "string"
79
+ ? getProjection(projection)
80
+ : projection;
81
+ }
82
+
83
+ /**
84
+ * Transforms a given point from a source to a target projection.
85
+ * @param {(string|object)} sourceProjection - projection name or projection of point
86
+ * @param {(string|object)} targetProjection - projection name or projection to project point to
87
+ * @param {number[]} point - point to project
88
+ * @returns {number[]|undefined} transformed point
89
+ */
90
+ export function transform (sourceProjection, targetProjection, point) {
91
+ const source = getProj4Projection(sourceProjection),
92
+ target = getProj4Projection(targetProjection);
93
+
94
+ if (source && target && point) {
95
+ return proj4(source, target, point);
96
+ }
97
+
98
+ console.error(`Cancelled coordinate transformation with invalid parameters: ${sourceProjection}; ${targetProjection}; ${point}`);
99
+ return undefined;
100
+ }
101
+
102
+ /**
103
+ * Projects a point to the given map.
104
+ * @param {ol.Map} map - map to project to
105
+ * @param {(string|object)} sourceProjection - projection name or projection of point
106
+ * @param {number[]} point - point to project
107
+ * @returns {number[]|undefined} new point or undefined
108
+ */
109
+ export function transformToMapProjection (map, sourceProjection, point) {
110
+ return transform(sourceProjection, getMapProjection(map), point);
111
+ }
112
+
113
+ /**
114
+ * Projects a point from the given map.
115
+ * @param {ol.Map} map - map to project from, and point must be in map's projection
116
+ * @param {(string|object)} targetProjection - projection name or projection to project to
117
+ * @param {number[]} point - point to project
118
+ * @returns {(number[]|undefined)} new point or undefined
119
+ */
120
+ export function transformFromMapProjection (map, targetProjection, point) {
121
+ return transform(getMapProjection(map), targetProjection, point);
122
+ }