@masterportal/masterportalapi 2.14.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.
- package/CHANGELOG.md +7 -1
- package/example/config/localGeoJSONPoints.js +2106 -0
- package/example/config/portal.json +39 -0
- package/example/config/services.json +10 -0
- package/example/index.js +25 -14
- package/package.json +64 -63
- package/src/index.js +3 -1
- package/src/layer/geojson/index.js +55 -4
- package/src/layer/oaf.js +35 -5
- package/src/layer/vectorBase.js +20 -1
- package/src/layer/wfs.js +38 -7
- package/src/maps/ol/olMap.js +4 -3
- package/src/renderer/webgl.js +250 -0
- package/src/vectorStyle/styleList.js +1 -1
- package/test/layer/geojson/index.test.js +23 -0
- package/test/layer/oaf.test.js +30 -0
- package/test/layer/vectorBase.test.js +27 -7
- package/test/layer/wfs.test.js +30 -0
- package/test/renderer/webgl.test.js +161 -0
|
@@ -33,8 +33,47 @@
|
|
|
33
33
|
{
|
|
34
34
|
"id": "8712",
|
|
35
35
|
"name": "Schulinfosystem",
|
|
36
|
+
"renderer": "default",
|
|
36
37
|
"styleId": "8712",
|
|
37
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
|
+
}
|
|
38
77
|
}
|
|
39
78
|
],
|
|
40
79
|
"cesiumLib":"https://geoportal-hamburg.de/mastercode/cesium/1_99/Cesium.js",
|
|
@@ -123,6 +123,16 @@
|
|
|
123
123
|
"version": "1.1.0",
|
|
124
124
|
"featureNS": "https://registry.gdi-de.org/id/de.hh.up"
|
|
125
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
|
+
},
|
|
126
136
|
{
|
|
127
137
|
"id": "6001",
|
|
128
138
|
"name": "ADV (EPSG:25832)",
|
package/example/index.js
CHANGED
|
@@ -10,7 +10,8 @@ import createStyle from "../src/vectorStyle/createStyle";
|
|
|
10
10
|
|
|
11
11
|
import services from "./config/services.json";
|
|
12
12
|
import portalConfig from "./config/portal.json";
|
|
13
|
-
import localGeoJSON from "./config/localGeoJSON
|
|
13
|
+
import localGeoJSON from "./config/localGeoJSON";
|
|
14
|
+
import localGeoJSONPoints from "./config/localGeoJSONPoints";
|
|
14
15
|
import load3DScriptModule from "../src/lib/load3DScript";
|
|
15
16
|
|
|
16
17
|
function errorCallback (errorEvent) {
|
|
@@ -23,17 +24,22 @@ window.mpapi = {
|
|
|
23
24
|
map2D: null,
|
|
24
25
|
map: null
|
|
25
26
|
};
|
|
26
|
-
//* Fake
|
|
27
|
+
//* Fake services that hold client-side prepared geojson; also nice to test automatic transformation since data is in WGS 84
|
|
27
28
|
// eslint-disable-next-line no-unused-vars
|
|
28
29
|
const hamburgServicesUrl = "https://geodienste.hamburg.de/services-internet.json",
|
|
29
|
-
|
|
30
|
+
localServices = [{
|
|
30
31
|
id: "2002",
|
|
31
32
|
typ: "GeoJSON",
|
|
32
33
|
features: localGeoJSON
|
|
33
34
|
},
|
|
35
|
+
{
|
|
36
|
+
id: "2003",
|
|
37
|
+
typ: "GeoJSON",
|
|
38
|
+
features: localGeoJSONPoints
|
|
39
|
+
}],
|
|
34
40
|
config = {
|
|
35
41
|
...portalConfig,
|
|
36
|
-
layerConf: services,
|
|
42
|
+
layerConf: [...services, ...localServices], // add local services
|
|
37
43
|
styleConf: "https://geodienste.hamburg.de/lgv-config/style_v3.json"
|
|
38
44
|
},
|
|
39
45
|
// eslint-disable-next-line func-style
|
|
@@ -55,6 +61,19 @@ const hamburgServicesUrl = "https://geodienste.hamburg.de/services-internet.json
|
|
|
55
61
|
};
|
|
56
62
|
let map2D = null;
|
|
57
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
|
+
|
|
58
77
|
// */
|
|
59
78
|
//* Cleans up map before it is re-rendered (happens on every save during dev mode)
|
|
60
79
|
document.getElementById(portalConfig.target).innerHTML = "";
|
|
@@ -119,8 +138,6 @@ document.getElementById("layer-visibility").addEventListener("click", function (
|
|
|
119
138
|
});
|
|
120
139
|
|
|
121
140
|
map2D = mapsAPI.map.createMap(config, "2D", {errorCallback});
|
|
122
|
-
services.push(localService);
|
|
123
|
-
// */
|
|
124
141
|
|
|
125
142
|
//* geojson styling function call to override default styling and special wfs styling
|
|
126
143
|
mpapi.geojson.setCustomStyles({
|
|
@@ -261,12 +278,6 @@ window.mpapi.map.addLayer("7003");
|
|
|
261
278
|
|
|
262
279
|
/* VectorStyle example */
|
|
263
280
|
// Example for using the vectorStyle that is now implemented in the masterportalAPI.
|
|
264
|
-
//
|
|
265
|
-
//
|
|
266
|
-
styleList.initializeStyleList({}, config, config.layers, undefined, (initializedStyleList, error) => {
|
|
267
|
-
if (error) {
|
|
268
|
-
console.error("Die Datei " + config.styleConf + " konnte nicht geladen werden!");
|
|
269
|
-
}
|
|
270
|
-
return initializedStyleList;
|
|
271
|
-
});
|
|
281
|
+
// Apply style to layer "8172"
|
|
282
|
+
// mirrors behavior of Masterportal styling
|
|
272
283
|
getWfsStyleFunction();
|
package/package.json
CHANGED
|
@@ -1,63 +1,64 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@masterportal/masterportalapi",
|
|
3
|
-
"author": "Implementierungspartnerschaft Masterportal <info@masterportal.org> (https://www.masterportal.org)",
|
|
4
|
-
"version": "2.
|
|
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
|
-
"
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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);
|
package/src/layer/vectorBase.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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);
|
package/src/maps/ol/olMap.js
CHANGED
|
@@ -84,12 +84,13 @@ function injectErrorCallback (layer, errorCallback) {
|
|
|
84
84
|
* This function is available on all ol/Map instances.
|
|
85
85
|
* @param {(string|ol/layer/Base)} layerOrId - if of layer to add to map
|
|
86
86
|
* @param {object} [params] - optional parameter object
|
|
87
|
+
* @param {boolean} [params.layerParams={}] - additional layerParams specified in portalConfig
|
|
87
88
|
* @param {boolean} [params.visibility=true] - whether added layer is initially visible
|
|
88
89
|
* @param {Number} [params.transparency=0] - how visible the layer is initially
|
|
89
90
|
* @param {Function} [params.errorCallback=console.error] - callback for layer source error events
|
|
90
91
|
* @returns {?ol.Layer} added layer
|
|
91
92
|
*/
|
|
92
|
-
function addLayer (layerOrId, params = {visibility: true, transparency: 0, errorCallback: console.error}) {
|
|
93
|
+
function addLayer (layerOrId, params = {layerParams: {}, visibility: true, transparency: 0, errorCallback: console.error}) {
|
|
93
94
|
const errorCallback = typeof params.errorCallback === "function"
|
|
94
95
|
? params.errorCallback
|
|
95
96
|
: console.error;
|
|
@@ -108,7 +109,7 @@ function addLayer (layerOrId, params = {visibility: true, transparency: 0, error
|
|
|
108
109
|
console.error("Layer with id '" + layerOrId + "' has unknown type '" + rawLayer.typ + "'. No layer added to map.");
|
|
109
110
|
return null;
|
|
110
111
|
}
|
|
111
|
-
layer = layerBuilder.createLayer(rawLayer, {}, {map: this});
|
|
112
|
+
layer = layerBuilder.createLayer(rawLayer, {layerParams: params.layerParams}, {map: this});
|
|
112
113
|
layer.setVisible(typeof params.visibility === "boolean" ? params.visibility : true);
|
|
113
114
|
layer.setOpacity(typeof params.transparency === "number" ? (100 - params.transparency) / 100 : 1);
|
|
114
115
|
injectErrorCallback(layer, errorCallback);
|
|
@@ -169,7 +170,7 @@ export function createMap (config = defaults, {mapParams, callback, errorCallbac
|
|
|
169
170
|
rawLayerList.initializeLayerList(config.layerConf, (param, error) => {
|
|
170
171
|
getInitialLayers(config)
|
|
171
172
|
.forEach(layer => {
|
|
172
|
-
map.addLayer(layer.id, {errorCallback});
|
|
173
|
+
map.addLayer(layer.id, {layerParams: layer, errorCallback});
|
|
173
174
|
});
|
|
174
175
|
|
|
175
176
|
if (typeof callback === "function") {
|