@masterportal/masterportalapi 2.13.0 → 2.15.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.
Files changed (61) hide show
  1. package/.eslintrc +2 -1
  2. package/CHANGELOG.md +16 -7
  3. package/example/config/localGeoJSONPoints.js +2106 -0
  4. package/example/config/portal.json +47 -1
  5. package/example/config/services.json +20 -0
  6. package/example/index.js +50 -7
  7. package/jest.config.js +1 -1
  8. package/jest.setup.js +9 -1
  9. package/package.json +64 -62
  10. package/src/index.js +3 -1
  11. package/src/layer/geojson/index.js +55 -4
  12. package/src/layer/oaf.js +35 -5
  13. package/src/layer/vectorBase.js +20 -1
  14. package/src/layer/wfs.js +38 -7
  15. package/src/lib/attributeMapper.js +231 -0
  16. package/src/lib/getValueFromObjectByPath.js +73 -0
  17. package/src/lib/thousandsSeparator.js +23 -0
  18. package/src/maps/ol/olMap.js +4 -3
  19. package/src/renderer/webgl.js +250 -0
  20. package/src/vectorStyle/createStyle.js +259 -0
  21. package/src/vectorStyle/lib/colorConvertions.js +97 -0
  22. package/src/vectorStyle/lib/createLegendInfo.js +28 -0
  23. package/src/vectorStyle/lib/getGeometryTypeFromService.js +153 -0
  24. package/src/vectorStyle/lib/getRuleForIndex.js +62 -0
  25. package/src/vectorStyle/lib/valueOperations.js +172 -0
  26. package/src/vectorStyle/styleList.js +281 -0
  27. package/src/vectorStyle/styles/defaultStyles.js +177 -0
  28. package/src/vectorStyle/styles/point/stylePoint.js +108 -0
  29. package/src/vectorStyle/styles/point/stylePointCircle.js +29 -0
  30. package/src/vectorStyle/styles/point/stylePointIcon.js +79 -0
  31. package/src/vectorStyle/styles/point/stylePointInterval.js +124 -0
  32. package/src/vectorStyle/styles/point/stylePointNominal.js +232 -0
  33. package/src/vectorStyle/styles/point/stylePointRegularShape.js +39 -0
  34. package/src/vectorStyle/styles/polygon/polygonStyleHatch.js +160 -0
  35. package/src/vectorStyle/styles/polygon/stylePolygon.js +125 -0
  36. package/src/vectorStyle/styles/style.js +161 -0
  37. package/src/vectorStyle/styles/styleCesium.js +106 -0
  38. package/src/vectorStyle/styles/styleLine.js +51 -0
  39. package/src/vectorStyle/styles/styleText.js +143 -0
  40. package/test/layer/geojson/index.test.js +23 -0
  41. package/test/layer/oaf.test.js +30 -0
  42. package/test/layer/vectorBase.test.js +27 -7
  43. package/test/layer/wfs.test.js +30 -0
  44. package/test/lib/attributeMapper.test.js +290 -0
  45. package/test/lib/getValueFromObjectByPath.test.js +61 -0
  46. package/test/lib/thousandsSeparator.test.js +58 -0
  47. package/test/renderer/webgl.test.js +161 -0
  48. package/test/vectorStyle/createStyle.test.js +335 -0
  49. package/test/vectorStyle/lib/colorConvertions.test.js +42 -0
  50. package/test/vectorStyle/lib/getRuleForIndex.test.js +132 -0
  51. package/test/vectorStyle/lib/valueOperations.test.js +191 -0
  52. package/test/vectorStyle/styles/point/stylePoint.test.js +28 -0
  53. package/test/vectorStyle/styles/point/stylePointCircle.test.js +30 -0
  54. package/test/vectorStyle/styles/point/stylePointIcon.test.js +83 -0
  55. package/test/vectorStyle/styles/point/stylePointInterval.test.js +57 -0
  56. package/test/vectorStyle/styles/point/stylePointNominal.test.js +84 -0
  57. package/test/vectorStyle/styles/point/stylePointRegularShape.test.js +24 -0
  58. package/test/vectorStyle/styles/polygon/polygonStyleHatch.test.js +95 -0
  59. package/test/vectorStyle/styles/polygon/stylePolygon.test.js +61 -0
  60. package/test/vectorStyle/styles/styleLine.test.js +29 -0
  61. package/test/vectorStyle/styles/styleText.test.js +49 -0
@@ -29,7 +29,53 @@
29
29
  "layers": [
30
30
  {
31
31
  "id": "1001"
32
+ },
33
+ {
34
+ "id": "8712",
35
+ "name": "Schulinfosystem",
36
+ "renderer": "default",
37
+ "styleId": "8712",
38
+ "typ": "WFS"
39
+ },
40
+ {
41
+ "id": "1534",
42
+ "renderer": "webgl",
43
+ "isPointLayer": false,
44
+ "styleId": "1534",
45
+ "typ": "WFS"
46
+ },
47
+ {
48
+ "id": "2003",
49
+ "renderer": "webgl",
50
+ "hitTolerance": 20,
51
+ "isPointLayer": true,
52
+ "style": {
53
+ "symbol": {
54
+ "symbolType": "circle",
55
+ "size": [
56
+ "interpolate",
57
+ ["linear"],
58
+ ["get", "Total_votes"],
59
+ 0,
60
+ 6,
61
+ 18,
62
+ 24
63
+ ],
64
+ "color": [
65
+ "interpolate",
66
+ ["linear"],
67
+ ["get", "compound"],
68
+ -1,
69
+ [240, 40, 30],
70
+ 1,
71
+ [0, 200, 60]
72
+ ],
73
+ "opacity": 0.8,
74
+ "rotateWithView": true
75
+ }
76
+ }
32
77
  }
33
78
  ],
34
- "cesiumLib":"https://geoportal-hamburg.de/mastercode/cesium/1_99/Cesium.js"
79
+ "cesiumLib":"https://geoportal-hamburg.de/mastercode/cesium/1_99/Cesium.js",
80
+ "wfsImgPath": "https://geodienste.hamburg.de/lgv-config/img/"
35
81
  }
@@ -113,6 +113,26 @@
113
113
  "anzahl_schueler": ">1000"
114
114
  }
115
115
  },
116
+ {
117
+ "id": "8712",
118
+ "name": "de.hh.up:staatliche schulen",
119
+ "url": "https://geodienste.hamburg.de/HH_WFS_Schulen",
120
+ "typ": "WFS",
121
+ "featureType": "staatliche_schulen",
122
+ "outputFormat": "XML",
123
+ "version": "1.1.0",
124
+ "featureNS": "https://registry.gdi-de.org/id/de.hh.up"
125
+ },
126
+ {
127
+ "id" : "1534",
128
+ "name" : "de.hh.up:verzeichnis oeffentlicher gruenanlagen",
129
+ "url" : "https://geodienste.hamburg.de/HH_WFS_Gruenplan",
130
+ "typ" : "WFS",
131
+ "featureType" : "verzeichnis_oeffentlicher_gruenanlagen",
132
+ "outputFormat" : "XML",
133
+ "version" : "1.1.0",
134
+ "featureNS" : "https://registry.gdi-de.org/id/de.hh.up"
135
+ },
116
136
  {
117
137
  "id": "6001",
118
138
  "name": "ADV (EPSG:25832)",
package/example/index.js CHANGED
@@ -5,10 +5,13 @@ import {Style, Stroke, Fill, Icon} from "ol/style.js";
5
5
  import * as mpapi from "../src";
6
6
  import mapsAPI from "../src/maps/api.js";
7
7
  import rawLayerList from "../src/rawLayerList";
8
+ import styleList from "../src/vectorStyle/styleList";
9
+ import createStyle from "../src/vectorStyle/createStyle";
8
10
 
9
11
  import services from "./config/services.json";
10
12
  import portalConfig from "./config/portal.json";
11
- import localGeoJSON from "./config/localGeoJSON.js";
13
+ import localGeoJSON from "./config/localGeoJSON";
14
+ import localGeoJSONPoints from "./config/localGeoJSONPoints";
12
15
  import load3DScriptModule from "../src/lib/load3DScript";
13
16
 
14
17
  function errorCallback (errorEvent) {
@@ -21,20 +24,56 @@ window.mpapi = {
21
24
  map2D: null,
22
25
  map: null
23
26
  };
24
- //* Fake service that holds client-side prepared geojson; also nice to test automatic transformation since data is in WGS 84
27
+ //* Fake services that hold client-side prepared geojson; also nice to test automatic transformation since data is in WGS 84
25
28
  // eslint-disable-next-line no-unused-vars
26
29
  const hamburgServicesUrl = "https://geodienste.hamburg.de/services-internet.json",
27
- localService = {
30
+ localServices = [{
28
31
  id: "2002",
29
32
  typ: "GeoJSON",
30
33
  features: localGeoJSON
31
34
  },
35
+ {
36
+ id: "2003",
37
+ typ: "GeoJSON",
38
+ features: localGeoJSONPoints
39
+ }],
32
40
  config = {
33
41
  ...portalConfig,
34
- layerConf: services
42
+ layerConf: [...services, ...localServices], // add local services
43
+ styleConf: "https://geodienste.hamburg.de/lgv-config/style_v3.json"
44
+ },
45
+ // eslint-disable-next-line func-style
46
+ getWfsStyleFunction = function () {
47
+ const styleId = "8712",
48
+ olLayer = window.mpapi.map.getLayers().getArray().find((element) => element.get("id") === "8712"),
49
+ source = olLayer.getSource(),
50
+ styleObject = styleList.returnStyleObject(styleId);
51
+ let isClusterFeature = false;
52
+
53
+ if (styleObject !== undefined) {
54
+ source.on("featuresloadend", event => {
55
+ event.features.forEach(element => {
56
+ isClusterFeature = false;
57
+ element.setStyle(createStyle.createStyle(styleObject, element, isClusterFeature, config.wfsImgPath));
58
+ });
59
+ });
60
+ }
35
61
  };
36
62
  let map2D = null;
37
63
 
64
+ /* VectorStyle example */
65
+ // Example for using the vectorStyle that is now implemented in the masterportalAPI.
66
+ // Hardcoded to show the school layer "8712" as a wfs and "1534" as wfs with webgl renderer.
67
+ // For better visibility adding of the other layers, especially "5001", should be commented out.
68
+ // initialize StyleList before map is created for automated lookup of styleObject when creating webgl layer
69
+ // application of regular canvas style happens after loading
70
+ styleList.initializeStyleList({}, config, config.layers, undefined, (currentStyleList, error) => {
71
+ if (error) {
72
+ console.error("Die Datei " + config.styleConf + " konnte nicht geladen werden!");
73
+ }
74
+ return currentStyleList;
75
+ });
76
+
38
77
  // */
39
78
  //* Cleans up map before it is re-rendered (happens on every save during dev mode)
40
79
  document.getElementById(portalConfig.target).innerHTML = "";
@@ -99,8 +138,6 @@ document.getElementById("layer-visibility").addEventListener("click", function (
99
138
  });
100
139
 
101
140
  map2D = mapsAPI.map.createMap(config, "2D", {errorCallback});
102
- services.push(localService);
103
- // */
104
141
 
105
142
  //* geojson styling function call to override default styling and special wfs styling
106
143
  mpapi.geojson.setCustomStyles({
@@ -237,4 +274,10 @@ map2D.getLayers().forEach(layer => {
237
274
  window.mpapi.map.addLayer("7001");
238
275
  window.mpapi.map.addLayer("7002");
239
276
  window.mpapi.map.addLayer("7003");
240
- // */
277
+ */
278
+
279
+ /* VectorStyle example */
280
+ // Example for using the vectorStyle that is now implemented in the masterportalAPI.
281
+ // Apply style to layer "8172"
282
+ // mirrors behavior of Masterportal styling
283
+ getWfsStyleFunction();
package/jest.config.js CHANGED
@@ -3,7 +3,7 @@ module.exports = {
3
3
  /** ol prints errors without HTMLCanvasElement being available in test environment */
4
4
  "setupFiles": ["jest-canvas-mock"],
5
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)/).*/"],
6
+ "transformIgnorePatterns": ["/node_modules/(?!(ol|olcs|ol-mapbox-style|geotiff|quick-lru)/).*/"],
7
7
  /** only consider files in src/ for coverage */
8
8
  "collectCoverageFrom": ["src/**/*.js"],
9
9
  /** coverage reporters */
package/jest.setup.js CHANGED
@@ -2,4 +2,12 @@ import "regenerator-runtime/runtime";
2
2
 
3
3
  window.URL.createObjectURL = function () {
4
4
  // empty
5
- };
5
+ };
6
+
7
+ window.ResizeObserver =
8
+ window.ResizeObserver ||
9
+ jest.fn().mockImplementation(() => ({
10
+ disconnect: jest.fn(),
11
+ observe: jest.fn(),
12
+ unobserve: jest.fn()
13
+ }));
package/package.json CHANGED
@@ -1,62 +1,64 @@
1
- {
2
- "name": "@masterportal/masterportalapi",
3
- "author": "Implementierungspartnerschaft Masterportal <info@masterportal.org> (https://www.masterportal.org)",
4
- "version": "2.13.0",
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.27.1",
23
- "ol": "7.1.0",
24
- "olcs": "^2.13.1",
25
- "proj4": "^2.8.1",
26
- "xml2js": "^0.4.23"
27
- },
28
- "devDependencies": {
29
- "@babel/core": "^7.20.12",
30
- "@babel/plugin-transform-modules-commonjs": "^7.20.11",
31
- "@parcel/transformer-sass": "^2.6.0",
32
- "buffer": "^6.0.3",
33
- "canvas": "^2.11.0",
34
- "eslint": "^8.31.0",
35
- "events": "^3.3.0",
36
- "husky": "^8.0.3",
37
- "jest": "^29.3.1",
38
- "jest-canvas-mock": "^2.4.0",
39
- "jest-environment-jsdom": "^29.3.1",
40
- "jsdoc": "^4.0.0",
41
- "parcel": "^2.6.0",
42
- "process": "^0.11.10",
43
- "sass": "^1.57.1",
44
- "stream-browserify": "^3.0.0",
45
- "timers-browserify": "^2.0.12"
46
- },
47
- "peerDependencies": {
48
- "cesium": "^1.95.0"
49
- },
50
- "engines": {
51
- "node": "^16.13.2 || ^18.12.0",
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
- }
1
+ {
2
+ "name": "@masterportal/masterportalapi",
3
+ "author": "Implementierungspartnerschaft Masterportal <info@masterportal.org> (https://www.masterportal.org)",
4
+ "version": "2.15.0",
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.27.1",
23
+ "ol": "7.2.2",
24
+ "olcs": "^2.13.1",
25
+ "proj4": "^2.8.1",
26
+ "xml2js": "^0.4.23"
27
+ },
28
+ "devDependencies": {
29
+ "@babel/core": "^7.20.12",
30
+ "@babel/plugin-transform-modules-commonjs": "^7.20.11",
31
+ "@parcel/transformer-sass": "^2.6.0",
32
+ "buffer": "^6.0.3",
33
+ "canvas": "^2.11.0",
34
+ "eslint": "^8.31.0",
35
+ "events": "^3.3.0",
36
+ "husky": "^8.0.3",
37
+ "jest": "^29.3.1",
38
+ "jest-canvas-mock": "^2.4.0",
39
+ "jest-environment-jsdom": "^29.3.1",
40
+ "jsdoc": "^4.0.0",
41
+ "parcel": "^2.6.0",
42
+ "process": "^0.11.10",
43
+ "sass": "^1.57.1",
44
+ "stream-browserify": "^3.0.0",
45
+ "timers-browserify": "^2.0.12",
46
+ "use-resize-observer": "^9.1.0"
47
+ },
48
+ "peerDependencies": {
49
+ "cesium": "^1.95.0"
50
+ },
51
+ "engines": {
52
+ "node": "^16.13.2 || ^18.12.0",
53
+ "npm": "^8.1.2"
54
+ },
55
+ "homepage": "https://bitbucket.org/geowerkstatt-hamburg/masterportalapi#readme",
56
+ "directories": {
57
+ "doc": "docs",
58
+ "example": "example",
59
+ "test": "test"
60
+ },
61
+ "bugs": {
62
+ "url": "https://bitbucket.org/geowerkstatt-hamburg/masterportalapi/issues"
63
+ }
64
+ }
package/src/index.js CHANGED
@@ -10,6 +10,7 @@ import * as vectorTile from "./layer/vectorTile";
10
10
  import * as oaf from "./layer/oaf";
11
11
  import * as terrain from "./layer/terrain";
12
12
  import * as entities from "./layer/entities";
13
+ import * as webgl from "./renderer/webgl";
13
14
  import Tileset from "./layer/tileset";
14
15
  import * as layerLib from "./layer/lib";
15
16
  import {search, setGazetteerUrl} from "./searchAddress";
@@ -34,5 +35,6 @@ export {
34
35
  rawLayerList,
35
36
  ping,
36
37
  search,
37
- crs
38
+ crs,
39
+ webgl
38
40
  };
@@ -1,22 +1,32 @@
1
1
  import VectorLayer from "ol/layer/Vector";
2
2
  import GeoJSON from "ol/format/GeoJSON.js";
3
3
  import style, {setCustomStyles} from "./style";
4
-
4
+ import * as webgl from "../../renderer/webgl";
5
5
 
6
6
  import {createVectorSource, createClusterVectorSource} from "../vector";
7
7
 
8
8
  // forward import to export
9
9
  export {setCustomStyles};
10
10
 
11
+ /**
12
+ * @typedef {Object} layerParams
13
+ * @property {string} [renderer] - use default canvas or webgl renderer
14
+ * @property {string} [styleId] - the styleId of the layer
15
+ * @property {string[]} [excludeTypesFromParsing] - types that should not be parsed from strings, only necessary for webgl
16
+ */
17
+
11
18
  /**
12
19
  * Creates the VectorSource for a GeoJSON layer. It will ensure each feature has the field id set to use with the other exported geojson functions.
13
20
  * @param {object} rawLayer - rawLayer as specified in services.json
14
21
  * @param {string} [rawLayer.url] - url to fetch geojson from; if no rawLayer.features given, this is required
15
22
  * @param {object} [rawLayer.features] - if features are transmitted via rawLayer, they will be used instead of requesting an URL
23
+ * @param {"default" | "webgl" | undefined} [rawLayer.renderer] - use default canvas or webgl renderer
24
+ * @param {string} [rawLayer.styleId] - the styleId of the layer, only necessary for webgl style pipeline
25
+ * @param {string[]} [rawLayer.excludeTypesFromParsing] - types that should not be parsed from strings, only necessary for webgl
16
26
  * @param {object} options - options of the geojson layer
17
27
  * @returns {ol.source.Vector} created VectorSource
18
28
  */
19
- export function createLayerSource ({url, features, clusterDistance}, options) {
29
+ export function createLayerSource ({url, features, clusterDistance, renderer, styleId, excludeTypesFromParsing}, options) {
20
30
  const format = new GeoJSON();
21
31
  let source = null;
22
32
 
@@ -32,6 +42,18 @@ export function createLayerSource ({url, features, clusterDistance}, options) {
32
42
  }
33
43
  });
34
44
 
45
+ // perform necessary feature operations if renderer is webgl
46
+ if (renderer === "webgl") {
47
+ // if features were provided before source creation
48
+ if (features?.length > 0) {
49
+ webgl.afterLoading(source.getFeatures(), styleId, excludeTypesFromParsing);
50
+ }
51
+ // wait for loading
52
+ source.once("featuresloadend", event => {
53
+ webgl.afterLoading(event?.features, styleId, excludeTypesFromParsing);
54
+ });
55
+ }
56
+
35
57
  return source;
36
58
  }
37
59
 
@@ -45,9 +67,30 @@ export function createLayerSource ({url, features, clusterDistance}, options) {
45
67
  * @returns {ol.layer.Vector} Layer with id and source specified in rawLayer
46
68
  */
47
69
  export function createLayer (rawLayer = {}, {layerParams = {}, options = {}} = {}) {
48
- const layer = new VectorLayer(Object.assign({
70
+ let layer, source;
71
+
72
+ // use WebGL render pipeline, if specified
73
+ if (layerParams.renderer === "webgl") {
74
+ source = createLayerSource({
75
+ ...rawLayer,
76
+ renderer: layerParams.renderer,
77
+ styleId: layerParams.styleId,
78
+ excludeTypesFromParsing: layerParams.excludeTypesFromParsing
79
+ }, options);
80
+ layer = webgl.createLayer({
81
+ ...rawLayer,
82
+ ...layerParams,
83
+ source
84
+ });
85
+
86
+ return layer;
87
+ }
88
+
89
+ // use default canvas renderer
90
+ source = createLayerSource(rawLayer, options);
91
+ layer = new VectorLayer(Object.assign({
49
92
  id: rawLayer.id,
50
- source: createLayerSource(rawLayer, options)
93
+ source
51
94
  }, layerParams));
52
95
 
53
96
  if (options.style) {
@@ -59,6 +102,7 @@ export function createLayer (rawLayer = {}, {layerParams = {}, options = {}} = {
59
102
  else {
60
103
  layer.setStyle(style);
61
104
  }
105
+
62
106
  return layer;
63
107
  }
64
108
 
@@ -70,6 +114,13 @@ export function createLayer (rawLayer = {}, {layerParams = {}, options = {}} = {
70
114
  export function updateSource (layer) {
71
115
  // openlayers named this "refresh", but it also means "reload" if an URL is set
72
116
  layer.getSource().refresh();
117
+
118
+ // perform necessary feature operations if renderer is webgl
119
+ if (layer.get("renderer") === "webgl") {
120
+ layer.getSource().once("featuresloadend", event => {
121
+ webgl.afterLoading(event?.features, layer.get("styleId"), layer.get("excludeTypesFromParsing"));
122
+ });
123
+ }
73
124
  }
74
125
 
75
126
  /**
package/src/layer/oaf.js CHANGED
@@ -4,6 +4,7 @@ import GeoJSON from "ol/format/GeoJSON.js";
4
4
  import {createVectorSource, createClusterVectorSource} from "./vector";
5
5
  import {onError, onLoad} from "../lib/wfsUtil";
6
6
  import {getParamsUrl} from "../lib/oafUtil";
7
+ import * as webgl from "../renderer/webgl";
7
8
 
8
9
  /**
9
10
  * Layer specification as in services.json.
@@ -170,6 +171,9 @@ function createUrl (rawLayer) {
170
171
  /**
171
172
  * Creates an ol/source element for the rawLayer by OAF (XML or Geojson)
172
173
  * @param {rawLayer} rawLayer layer specification as in services.json
174
+ * @param {"default" | "webgl" | undefined} [rawLayer.renderer] - use default canvas or webgl renderer
175
+ * @param {string} [rawLayer.styleId] - the styleId of the layer, only necessary for webgl style pipeline
176
+ * @param {string[]} [rawLayer.excludeTypesFromParsing] - types that should not be parsed from strings, only necessary for webgl
173
177
  * @param {options} [options] additional options
174
178
  * {@link https://openlayers.org/en/latest/apidoc/module-ol_source_Vector-VectorSource.html failure/success see}
175
179
  * @returns {(ol.source.VectorSource|ol.source.Cluster)} VectorSource or Cluster, depending on whether clusterDistance is set.
@@ -182,6 +186,12 @@ export function createLayerSource (rawLayer, options = {}) {
182
186
  const url = createUrl(rawLayer),
183
187
  source = getLayerSource(rawLayer, options, url);
184
188
 
189
+ if (rawLayer.renderer === "webgl") {
190
+ source.once("featuresloadend", event => {
191
+ webgl.afterLoading(event?.features, rawLayer.styleId, rawLayer.excludeTypesFromParsing);
192
+ });
193
+ }
194
+
185
195
  return source;
186
196
  }
187
197
 
@@ -194,11 +204,31 @@ export function createLayerSource (rawLayer, options = {}) {
194
204
  * @returns {ol.Layer} Layer that can be added to map.
195
205
  */
196
206
  export function createLayer (rawLayer = {}, {layerParams = {}, options = {}} = {}) {
197
- const source = createLayerSource(rawLayer, options),
198
- layer = new VectorLayer(Object.assign({
199
- source,
200
- id: rawLayer.id
201
- }, layerParams));
207
+ let layer, source;
208
+
209
+ // use WebGL render pipeline, if specified
210
+ if (layerParams.renderer === "webgl") {
211
+ source = createLayerSource({
212
+ ...rawLayer,
213
+ renderer: layerParams.renderer,
214
+ styleId: layerParams.styleId,
215
+ excludeTypesFromParsing: layerParams.excludeTypesFromParsing
216
+ }, options);
217
+ layer = webgl.createLayer({
218
+ ...rawLayer,
219
+ ...layerParams,
220
+ source
221
+ });
222
+
223
+ return layer;
224
+ }
225
+
226
+ // use default canvas renderer
227
+ source = createLayerSource(rawLayer, options);
228
+ layer = new VectorLayer(Object.assign({
229
+ source,
230
+ id: rawLayer.id
231
+ }, layerParams));
202
232
 
203
233
  if (options.style) {
204
234
  layer.setStyle(options.style);
@@ -1,6 +1,7 @@
1
1
 
2
2
  import VectorLayer from "ol/layer/Vector.js";
3
3
  import VectorSource from "ol/source/Vector.js";
4
+ import * as webgl from "../renderer/webgl";
4
5
 
5
6
  /**
6
7
  * Triggered by Layer to create a layerSource
@@ -8,9 +9,16 @@ import VectorSource from "ol/source/Vector.js";
8
9
  * @returns {void}
9
10
  */
10
11
  export function createLayerSource (attrs) {
11
- return new VectorSource({
12
+ const source = new VectorSource({
12
13
  features: attrs.features
13
14
  });
15
+
16
+ // perform necessary feature operations if renderer is webgl
17
+ if (attrs.renderer === "webgl") {
18
+ webgl.afterLoading(source.getFeatures(), attrs.styleId, attrs.excludeTypesFromParsing);
19
+ }
20
+
21
+ return source;
14
22
  }
15
23
 
16
24
  /**
@@ -20,6 +28,11 @@ export function createLayerSource (attrs) {
20
28
  * @returns {void}
21
29
  */
22
30
  export function updateSource (layer, features) {
31
+ // perform necessary feature operations if renderer is webgl
32
+ if (layer.get("renderer") === "webgl") {
33
+ webgl.afterLoading(features, layer.get("styleId"), layer.get("excludeTypesFromParsing"));
34
+ }
35
+
23
36
  layer.getSource().clear(true);
24
37
  layer.getSource().addFeatures(features);
25
38
  }
@@ -32,6 +45,12 @@ export function updateSource (layer, features) {
32
45
  export function createLayer (attrs) {
33
46
  const source = this.createLayerSource(attrs);
34
47
 
48
+ if (attrs.renderer === "webgl") {
49
+ return webgl.createLayer({
50
+ ...attrs,
51
+ source
52
+ });
53
+ }
35
54
  return new VectorLayer({
36
55
  source: source,
37
56
  name: attrs.name,
package/src/layer/wfs.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import VectorLayer from "ol/layer/Vector.js";
2
2
  import {bbox} from "ol/loadingstrategy.js";
3
3
  import {WFS} from "ol/format.js";
4
+ import * as webgl from "../renderer/webgl";
4
5
 
5
6
  import {createVectorSource, createClusterVectorSource} from "./vector";
6
7
  import {getVersion, onError, onLoad} from "../lib/wfsUtil";
@@ -14,6 +15,9 @@ import {getVersion, onError, onLoad} from "../lib/wfsUtil";
14
15
  * @property {string} featureNS - the namespace URI used for features
15
16
  * @property {number} clusterDistance - pixel radius, within this radius, all features are "clustered" into one feature - if available, a cluster source is created.
16
17
  * @property {function} style - style function to style the layer if options.style is not set
18
+ * @property {string} [renderer] - use default canvas or webgl renderer
19
+ * @property {string} [styleId] - the styleId of the layer
20
+ * @property {string[]} [excludeTypesFromParsing] - types that should not be parsed from strings, only necessary for webgl
17
21
  */
18
22
 
19
23
  /**
@@ -95,7 +99,7 @@ function loadWFS (url, params, source, {onErrorFn, success, failure}, options) {
95
99
  * @param {string} filter xml resource as wfs filter
96
100
  * @param {string} url url to load features from
97
101
  * @param {ol.source.VectorSource} source the vector source
98
- * @param {object} errorAndSuccessFns functions to handle error and success
102
+ * @param {object} errorAndSuccessFns functions to handle error and success
99
103
  * @param {function} errorAndSuccessFns.onErrorFn Calls options.onLoadingError and 'featuresloaderror' event will be fired by using failure callback.
100
104
  * @param {function} errorAndSuccessFns.success callback: 'featuresloadend' event will be fired
101
105
  * @param {function} errorAndSuccessFns.failure failure callback to ol.VectorLayer, fires 'featuresloaderror' event
@@ -138,6 +142,9 @@ function createUrl (rawLayer, version, projection, bboxParam) {
138
142
  * Creates an ol/source element for the rawLayer by using a loader.
139
143
  * The 'featuresloadend' and 'featuresloaderror' events will be fired by using success and failure callbacks of the loader.
140
144
  * @param {rawLayer} rawLayer layer specification as in services.json
145
+ * @param {"default" | "webgl" | undefined} [rawLayer.renderer] - use default canvas or webgl renderer
146
+ * @param {string} [rawLayer.styleId] - the styleId of the layer, only necessary for webgl style pipeline
147
+ * @param {string[]} [rawLayer.excludeTypesFromParsing] - types that should not be parsed from strings, only necessary for webgl
141
148
  * @param {options} [options] additional options
142
149
  * {@link https://openlayers.org/en/latest/apidoc/module-ol_source_Vector-VectorSource.html failure/success see}
143
150
  * @returns {(ol.source.VectorSource|ol.source.Cluster)} VectorSource or Cluster, depending on whether clusterDistance is set.
@@ -186,10 +193,14 @@ export function createLayerSource (rawLayer, options = {}) {
186
193
  if (options.beforeLoading) {
187
194
  source.once("featuresloadstart", () => options.beforeLoading());
188
195
  }
189
-
190
196
  if (rawLayer.clusterDistance) {
191
197
  return createClusterVectorSource(source, rawLayer.clusterDistance, options.clusterGeometryFunction);
192
198
  }
199
+ if (rawLayer.renderer === "webgl") {
200
+ source.once("featuresloadend", event => {
201
+ webgl.afterLoading(event?.features, rawLayer.styleId, rawLayer.excludeTypesFromParsing);
202
+ });
203
+ }
193
204
  return source;
194
205
  }
195
206
 
@@ -202,11 +213,31 @@ export function createLayerSource (rawLayer, options = {}) {
202
213
  * @returns {ol.Layer} Layer that can be added to map.
203
214
  */
204
215
  export function createLayer (rawLayer = {}, {layerParams = {}, options = {}} = {}) {
205
- const source = createLayerSource(rawLayer, options),
206
- layer = new VectorLayer(Object.assign({
207
- source,
208
- id: rawLayer.id
209
- }, layerParams));
216
+ let layer, source;
217
+
218
+ // use WebGL render pipeline, if specified
219
+ if (layerParams.renderer === "webgl") {
220
+ source = createLayerSource({
221
+ ...rawLayer,
222
+ renderer: layerParams.renderer,
223
+ styleId: layerParams.styleId,
224
+ excludeTypesFromParsing: layerParams.excludeTypesFromParsing
225
+ }, options);
226
+ layer = webgl.createLayer({
227
+ ...rawLayer,
228
+ ...layerParams,
229
+ source
230
+ });
231
+
232
+ return layer;
233
+ }
234
+
235
+ // use default canvas renderer
236
+ source = createLayerSource(rawLayer, options);
237
+ layer = new VectorLayer(Object.assign({
238
+ source,
239
+ id: rawLayer.id
240
+ }, layerParams));
210
241
 
211
242
  if (options.style) {
212
243
  layer.setStyle(options.style);