@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.
- package/.editorconfig +15 -0
- package/.eslintignore +6 -0
- package/.eslintrc +184 -0
- package/.husky/pre-push +4 -0
- package/CHANGELOG.md +217 -0
- package/License.txt +21 -0
- package/README.md +24 -0
- package/babel.config.json +6 -0
- package/example/README.md +7 -0
- package/example/config/localGeoJSON.js +956 -0
- package/example/config/portal.json +35 -0
- package/example/config/services.json +79 -0
- package/example/index.html +27 -0
- package/example/index.js +210 -0
- package/example/style.scss +59 -0
- package/jest.config.js +18 -0
- package/jest.setup.js +5 -0
- package/jsdoc.json +15 -0
- package/package.json +62 -0
- package/public/marker.svg +1 -0
- package/public/stringMarker.js +5 -0
- package/src/crs.js +122 -0
- package/src/defaults.js +38 -0
- package/src/index.js +30 -0
- package/src/layer/geojson/index.js +109 -0
- package/src/layer/geojson/style.js +61 -0
- package/src/layer/lib.js +32 -0
- package/src/layer/oaf.js +207 -0
- package/src/layer/terrain.js +72 -0
- package/src/layer/tileset.js +71 -0
- package/src/layer/vector.js +48 -0
- package/src/layer/vectorBase.js +39 -0
- package/src/layer/wfs.js +218 -0
- package/src/layer/wms.js +185 -0
- package/src/lib/coordsToPairs.js +15 -0
- package/src/lib/getInitialLayers.js +22 -0
- package/src/lib/load3DScript.js +22 -0
- package/src/lib/oafUtil.js +22 -0
- package/src/lib/setBackgroundImage.js +23 -0
- package/src/lib/wfsUtil.js +75 -0
- package/src/lib/zoomTo.js +40 -0
- package/src/maps/api.js +5 -0
- package/src/maps/map.js +35 -0
- package/src/maps/mapView.js +54 -0
- package/src/maps/ol/olMap.js +124 -0
- package/src/maps/olcs/3dUtils/fixedOverlaySynchronizer.js +39 -0
- package/src/maps/olcs/3dUtils/wmsRasterSynchronizer.js +348 -0
- package/src/maps/olcs/olcsMap.js +212 -0
- package/src/rawLayerList.js +88 -0
- package/src/searchAddress/gazetteerUrl.js +22 -0
- package/src/searchAddress/index.js +13 -0
- package/src/searchAddress/parse.js +196 -0
- package/src/searchAddress/search.js +184 -0
- package/src/searchAddress/searchGazetteer.js +52 -0
- package/src/searchAddress/showGeographicIdentifier.js +20 -0
- package/src/searchAddress/types.js +17 -0
- package/test/.eslintrc +7 -0
- package/test/crs.test.js +109 -0
- package/test/layer/geojson/index.test.js +133 -0
- package/test/layer/geojson/style.test.js +46 -0
- package/test/layer/lib.test.js +83 -0
- package/test/layer/oaf.test.js +245 -0
- package/test/layer/resources/oafFeatures.js +105 -0
- package/test/layer/resources/wfsFeatures.js +26 -0
- package/test/layer/resources/wfsFilter.js +17 -0
- package/test/layer/terrain.test.js +106 -0
- package/test/layer/tileset.test.js +116 -0
- package/test/layer/vector.test.js +76 -0
- package/test/layer/vectorBase.test.js +48 -0
- package/test/layer/wfs.test.js +388 -0
- package/test/layer/wms.test.js +256 -0
- package/test/lib/coordsToPairs.test.js +9 -0
- package/test/lib/getInitialLayers.test.js +28 -0
- package/test/lib/oafUtil.test.js +24 -0
- package/test/lib/setBackgroundImage.test.js +49 -0
- package/test/lib/wfsUtil.test.js +28 -0
- package/test/lib/zoomTo.test.js +74 -0
- package/test/map.test.js +258 -0
- package/test/mapView.test.js +59 -0
- package/test/rawLayerList.test.js +48 -0
- package/test/searchAddress/gazetteerSearchResults/address.js +175 -0
- package/test/searchAddress/gazetteerSearchResults/district.js +71 -0
- package/test/searchAddress/gazetteerSearchResults/houseNumber.js +32 -0
- package/test/searchAddress/gazetteerSearchResults/index.js +19 -0
- package/test/searchAddress/gazetteerSearchResults/parcel.js +44 -0
- package/test/searchAddress/gazetteerSearchResults/street.js +46 -0
- package/test/searchAddress/gazetteerSearchResults/streetKey.js +51 -0
- package/test/searchAddress/gazetteerUrl.test.js +22 -0
- package/test/searchAddress/parse.test.js +110 -0
- package/test/searchAddress/search.test.js +150 -0
- package/test/searchAddress/searchGazetteer.test.js +58 -0
- package/test/searchAddress/showGeographicIdentifier.test.js +22 -0
package/src/defaults.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Since all functions are exported for users, all functions with defaults
|
|
3
|
+
* have to import this object themselves to use fallbacks.
|
|
4
|
+
* @type {object}
|
|
5
|
+
* @ignore
|
|
6
|
+
*/
|
|
7
|
+
export default {
|
|
8
|
+
target: "map",
|
|
9
|
+
epsg: "EPSG:25832",
|
|
10
|
+
backgroundImage: "",
|
|
11
|
+
extent: [510000.0, 5850000.0, 625000.4, 6000000.0],
|
|
12
|
+
options: [
|
|
13
|
+
{resolution: 66.14579761460263, scale: 250000, zoomLevel: 0},
|
|
14
|
+
{resolution: 26.458319045841044, scale: 100000, zoomLevel: 1},
|
|
15
|
+
{resolution: 15.874991427504629, scale: 60000, zoomLevel: 2},
|
|
16
|
+
{resolution: 10.583327618336419, scale: 40000, zoomLevel: 3},
|
|
17
|
+
{resolution: 5.2916638091682096, scale: 20000, zoomLevel: 4},
|
|
18
|
+
{resolution: 2.6458319045841048, scale: 10000, zoomLevel: 5},
|
|
19
|
+
{resolution: 1.3229159522920524, scale: 5000, zoomLevel: 6},
|
|
20
|
+
{resolution: 0.6614579761460262, scale: 2500, zoomLevel: 7},
|
|
21
|
+
{resolution: 0.2645831904584105, scale: 1000, zoomLevel: 8},
|
|
22
|
+
{resolution: 0.13229159522920521, scale: 500, zoomLevel: 9}
|
|
23
|
+
],
|
|
24
|
+
namedProjections: [
|
|
25
|
+
["EPSG:25832", "+proj=utm +zone=32 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"]
|
|
26
|
+
],
|
|
27
|
+
startResolution: 15.874991427504629,
|
|
28
|
+
startCenter: [565874, 5934140],
|
|
29
|
+
layerConf: "https://geodienste.hamburg.de/services-internet.json",
|
|
30
|
+
layers: [
|
|
31
|
+
{
|
|
32
|
+
"id": "453",
|
|
33
|
+
"visibility": true
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
gazetteerUrl: "https://geodienste.hamburg.de/HH_WFS_GAGES?service=WFS&request=GetFeature&version=2.0.0",
|
|
37
|
+
showGeographicIdentifier: false
|
|
38
|
+
};
|
package/src/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {createMapView} from "./maps/mapView";
|
|
2
|
+
import * as crs from "./crs";
|
|
3
|
+
import * as rawLayerList from "./rawLayerList";
|
|
4
|
+
import * as wms from "./layer/wms";
|
|
5
|
+
import * as wfs from "./layer/wfs";
|
|
6
|
+
import * as geojson from "./layer/geojson";
|
|
7
|
+
import * as vectorBase from "./layer/vectorBase";
|
|
8
|
+
import * as oaf from "./layer/oaf";
|
|
9
|
+
import * as terrain from "./layer/terrain";
|
|
10
|
+
import Tileset from "./layer/tileset";
|
|
11
|
+
import * as layerLib from "./layer/lib";
|
|
12
|
+
import {search, setGazetteerUrl} from "./searchAddress";
|
|
13
|
+
import setBackgroundImage from "./lib/setBackgroundImage";
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
createMapView,
|
|
17
|
+
wms,
|
|
18
|
+
wfs,
|
|
19
|
+
geojson,
|
|
20
|
+
layerLib,
|
|
21
|
+
vectorBase,
|
|
22
|
+
oaf,
|
|
23
|
+
terrain,
|
|
24
|
+
Tileset,
|
|
25
|
+
setBackgroundImage,
|
|
26
|
+
setGazetteerUrl,
|
|
27
|
+
rawLayerList,
|
|
28
|
+
search,
|
|
29
|
+
crs
|
|
30
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import VectorLayer from "ol/layer/Vector";
|
|
2
|
+
import GeoJSON from "ol/format/GeoJSON.js";
|
|
3
|
+
import style, {setCustomStyles} from "./style";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import {createVectorSource, createClusterVectorSource} from "../vector";
|
|
7
|
+
|
|
8
|
+
// forward import to export
|
|
9
|
+
export {setCustomStyles};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 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
|
+
* @param {object} rawLayer - rawLayer as specified in services.json
|
|
14
|
+
* @param {string} [rawLayer.url] - url to fetch geojson from; if no rawLayer.features given, this is required
|
|
15
|
+
* @param {object} [rawLayer.features] - if features are transmitted via rawLayer, they will be used instead of requesting an URL
|
|
16
|
+
* @param {object} options - options of the geojson layer
|
|
17
|
+
* @returns {ol.source.Vector} created VectorSource
|
|
18
|
+
*/
|
|
19
|
+
export function createLayerSource ({url, features, clusterDistance}, options) {
|
|
20
|
+
const format = new GeoJSON();
|
|
21
|
+
let source = null;
|
|
22
|
+
|
|
23
|
+
source = createVectorSource(url || features, options.loadingStrategy, format);
|
|
24
|
+
|
|
25
|
+
if (clusterDistance) {
|
|
26
|
+
return createClusterVectorSource(source, clusterDistance, options.clusterGeometryFunction);
|
|
27
|
+
}
|
|
28
|
+
return source;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Creates a layer for GeoJSON.
|
|
33
|
+
* @param {object} rawLayer - rawLayer as specified in services.json
|
|
34
|
+
* @param {object} [layerParams={}] - extra params of the layer
|
|
35
|
+
* @param {object} [options={}] - parameter object
|
|
36
|
+
* @param {ol.Map} [options.map] - map the geojson is to be projected on
|
|
37
|
+
* @param {ol.Style} [options.layerStyle] - optional style; if not given, default styling (modifiable by setCustomStyles) is used
|
|
38
|
+
* @returns {ol.layer.Vector} Layer with id and source specified in rawLayer
|
|
39
|
+
*/
|
|
40
|
+
export function createLayer (rawLayer = {}, {layerParams = {}, options = {}} = {}) {
|
|
41
|
+
const layer = new VectorLayer(Object.assign({
|
|
42
|
+
id: rawLayer.id,
|
|
43
|
+
source: createLayerSource(rawLayer, options)
|
|
44
|
+
}, layerParams));
|
|
45
|
+
|
|
46
|
+
if (options.style) {
|
|
47
|
+
layer.setStyle(options.style);
|
|
48
|
+
}
|
|
49
|
+
else if (rawLayer.style) {
|
|
50
|
+
layer.setStyle(rawLayer.style);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
layer.setStyle(style);
|
|
54
|
+
}
|
|
55
|
+
return layer;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* GeoJSON layer with an URL will be reloaded. All other layers will be refreshed.
|
|
60
|
+
* @param {ol.layer.Vector} layer - GeoJSON layer to update
|
|
61
|
+
* @returns {undefined}
|
|
62
|
+
*/
|
|
63
|
+
export function updateSource (layer) {
|
|
64
|
+
// openlayers named this "refresh", but it also means "reload" if an URL is set
|
|
65
|
+
layer.getSource().refresh();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Sets a style to all given features.
|
|
70
|
+
* @param {ol.Feature[]} features - openlayers features to be styled
|
|
71
|
+
* @param {ol.style.Style~StyleLike} featureStyle - style, array of styles, or style function
|
|
72
|
+
* @returns {undefined}
|
|
73
|
+
*/
|
|
74
|
+
export function setFeatureStyle (features, featureStyle) {
|
|
75
|
+
features.forEach(feature => feature.setStyle(featureStyle));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @param {ol.Layer} layer - layer to hide all features of
|
|
80
|
+
* @returns {undefined}
|
|
81
|
+
*/
|
|
82
|
+
export function hideAllFeatures (layer) {
|
|
83
|
+
// () => null is the "do not display" function for openlayers (overriding VectorLayer styles)
|
|
84
|
+
setFeatureStyle(layer.getSource().getFeatures(), () => null);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @param {ol.Layer} layer - layer to show all features of
|
|
89
|
+
* @returns {undefined}
|
|
90
|
+
*/
|
|
91
|
+
export function showAllFeatures (layer) {
|
|
92
|
+
// if feature has undefined style, openlayers will check containing VectorLayer for styles
|
|
93
|
+
setFeatureStyle(layer.getSource().getFeatures(), undefined);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @param {ol.Layer} layer - layer to show some features of
|
|
98
|
+
* @param {string[]} featureIdList - list of feature.id to show
|
|
99
|
+
* @returns {undefined}
|
|
100
|
+
*/
|
|
101
|
+
export function showFeaturesById (layer, featureIdList) {
|
|
102
|
+
const features = layer
|
|
103
|
+
.getSource()
|
|
104
|
+
.getFeatures()
|
|
105
|
+
.filter(feature => featureIdList.indexOf(feature.getId()) >= 0);
|
|
106
|
+
|
|
107
|
+
hideAllFeatures(layer);
|
|
108
|
+
setFeatureStyle(features, undefined);
|
|
109
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {Style, Icon, Stroke, Fill} from "ol/style.js";
|
|
2
|
+
import markerSvg from "../../../public/marker.svg";
|
|
3
|
+
|
|
4
|
+
let customStyles = {};
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Allows setting custom styles. When available, they will be used.
|
|
8
|
+
* @param {object.<string, ol.Style>} styles - lookup from feature's geometry type (Point, LineString, ...) to style
|
|
9
|
+
* @returns {undefined}
|
|
10
|
+
*/
|
|
11
|
+
export function setCustomStyles (styles) {
|
|
12
|
+
customStyles = styles;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// // // STYLE PARTS
|
|
16
|
+
const marker = new Icon({
|
|
17
|
+
src: markerSvg,
|
|
18
|
+
// center bottom of marker 📍 is intended to show the spot
|
|
19
|
+
anchor: [0.5, 1]
|
|
20
|
+
}),
|
|
21
|
+
stroke = new Stroke({
|
|
22
|
+
width: 2,
|
|
23
|
+
color: "#005CA9"
|
|
24
|
+
}),
|
|
25
|
+
fill = new Fill({
|
|
26
|
+
color: "#005CA915"
|
|
27
|
+
}),
|
|
28
|
+
|
|
29
|
+
// // // STYLES
|
|
30
|
+
pointStyle = new Style({image: marker}),
|
|
31
|
+
lineStyle = new Style({stroke}),
|
|
32
|
+
polygonStyle = new Style({stroke, fill}),
|
|
33
|
+
circleStyle = new Style({stroke, fill}),
|
|
34
|
+
geometryCollectionStyle = new Style({stroke, fill, image: marker}),
|
|
35
|
+
|
|
36
|
+
// // // DEFAULT STYLE LOOKUP
|
|
37
|
+
defaultStyles = {
|
|
38
|
+
Point: pointStyle,
|
|
39
|
+
LineString: lineStyle,
|
|
40
|
+
MultiLineString: lineStyle,
|
|
41
|
+
MultiPoint: pointStyle,
|
|
42
|
+
MultiPolygon: polygonStyle,
|
|
43
|
+
Polygon: polygonStyle,
|
|
44
|
+
GeometryCollection: geometryCollectionStyle,
|
|
45
|
+
Circle: circleStyle
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Style function according to https://openlayers.org/en/latest/apidoc/module-ol_style_Style.html#~StyleFunction.
|
|
50
|
+
* Will use custom values first, if set, and fall back on holes in definition.
|
|
51
|
+
* @param {ol.Feature} feature - to be styled
|
|
52
|
+
* @returns {ol.Style} style for feature
|
|
53
|
+
* @ignore
|
|
54
|
+
*/
|
|
55
|
+
function style (feature) {
|
|
56
|
+
const type = feature.getGeometry().getType();
|
|
57
|
+
|
|
58
|
+
return customStyles[type] || defaultStyles[type];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default style;
|
package/src/layer/lib.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {ol.Layer} layer - layer to check
|
|
3
|
+
* @param {number} params - parameter object
|
|
4
|
+
* @param {number} [params.resolution] - resolution to check; if not given, map is required
|
|
5
|
+
* @param {object} [params.map] - map to check; if not given, resolution is required
|
|
6
|
+
* @returns {boolean} whether layer is visible in given resolution
|
|
7
|
+
*/
|
|
8
|
+
export function isLayerVisibleInResolution (layer, {resolution, map}) {
|
|
9
|
+
const r = typeof resolution === "undefined"
|
|
10
|
+
? map.getView().getResolution()
|
|
11
|
+
: resolution;
|
|
12
|
+
|
|
13
|
+
return layer.getMaxResolution() >= r && r >= layer.getMinResolution();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Generates an array of URLs that are supposed to hold legend graphics.
|
|
18
|
+
*
|
|
19
|
+
* @param {*} rawLayer - layer specification as in services.json
|
|
20
|
+
* @param {string} [rawLayer.layers=""] - comma separated list of service layers
|
|
21
|
+
* @returns {string[]} URLs of legend graphics for the rawLayer.
|
|
22
|
+
*/
|
|
23
|
+
export function getLegendURLs ({legendURL, layers = "", url, typ, format, version}) {
|
|
24
|
+
if (legendURL) {
|
|
25
|
+
return legendURL === "ignore" ? [] : [legendURL];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return layers
|
|
29
|
+
.split(",")
|
|
30
|
+
.filter(x => x /* filters empty string since it's falsy */)
|
|
31
|
+
.map(layerName => `${url}?SERVICE=${typ}&REQUEST=GetLegendGraphic&FORMAT=${format || "image/png"}&VERSION=${version}&LAYER=${layerName}`);
|
|
32
|
+
}
|
package/src/layer/oaf.js
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import VectorLayer from "ol/layer/Vector.js";
|
|
2
|
+
import {bbox} from "ol/loadingstrategy.js";
|
|
3
|
+
import GeoJSON from "ol/format/GeoJSON.js";
|
|
4
|
+
import {createVectorSource, createClusterVectorSource} from "./vector";
|
|
5
|
+
import {onError, onLoad} from "../lib/wfsUtil";
|
|
6
|
+
import {getParamsUrl} from "../lib/oafUtil";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Layer specification as in services.json.
|
|
10
|
+
* @typedef {Object} rawLayer
|
|
11
|
+
* @property {string} id - id of the layer
|
|
12
|
+
* @property {string} url - url to load features from
|
|
13
|
+
* @property {string} collection - name of the oaf collection
|
|
14
|
+
* @property {number} clusterDistance - pixel radius, within this radius, all features are "clustered" into one feature - if available, a cluster source is created.
|
|
15
|
+
* @property {function} style - style function to style the layer if options.style is not set
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Additional options used to create and load the layer source.
|
|
20
|
+
* @typedef {Object} options
|
|
21
|
+
* @property {module:ol.source.Vector~LoadingStrategy} loadingStrategy - the loading strategy to use, if not set 'bbox' is used
|
|
22
|
+
* @property {function} onLoadingError - function called on loading error, gets parameter error
|
|
23
|
+
* @property {function} beforeLoading - function called before loading
|
|
24
|
+
* @property {function} afterLoading - function called after loading, gets parameter features
|
|
25
|
+
* @property {function} featuresFilter - function called after loading to filter features, gets parameter features
|
|
26
|
+
* @property {function} clusterGeometryFunction - used in cluster source. Returns the geometry of the cluster, gets parameter feature
|
|
27
|
+
* @property {function} style - style function to style the layer
|
|
28
|
+
* @property {object} loadingParams - added as params to url
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Returns the 'onError' function if response is not ok
|
|
33
|
+
* @param {object} response of the request
|
|
34
|
+
* @param {function} onErrorFn Calls options.onLoadingError and 'featuresloaderror' event will be fired by using failure callback.
|
|
35
|
+
* @param {options} [options] additional options
|
|
36
|
+
* @param {function} failure failure callback to ol.VectorLayer, fires 'featuresloaderror' event
|
|
37
|
+
* @returns {void}
|
|
38
|
+
*/
|
|
39
|
+
function handleErrors (response, onErrorFn, options, failure) {
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
return onErrorFn(`Request to wfs-filter failed. Response status is ${response.statusText}`, options, failure);
|
|
42
|
+
}
|
|
43
|
+
return response;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Parses the given feature collection for the next nextLink.
|
|
49
|
+
* @param {Object} featureCollection the feature collection
|
|
50
|
+
* @returns {String|Boolean} the next link or false if no next link exists
|
|
51
|
+
*/
|
|
52
|
+
function getNextLinkFromFeatureCollection (featureCollection) {
|
|
53
|
+
if (typeof featureCollection !== "object" || featureCollection === null || !Array.isArray(featureCollection.links)) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
for (let i = 0; i < featureCollection.links.length; i++) {
|
|
57
|
+
if (
|
|
58
|
+
typeof featureCollection.links[i] === "object" && featureCollection.links[i] !== null
|
|
59
|
+
&& typeof featureCollection.links[i].href === "string"
|
|
60
|
+
&& featureCollection.links[i].title === "next page"
|
|
61
|
+
) {
|
|
62
|
+
return featureCollection.links[i].href;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Loads the Layer Source (Geojson).
|
|
70
|
+
* Iterates over all collection pages and collect it.
|
|
71
|
+
* Filters the features after load, if options.featuresFilter is given.
|
|
72
|
+
* Adds the features to the source.
|
|
73
|
+
* @param {string} url url to load features from
|
|
74
|
+
* @param {ol.source.VectorSource} source the vector source
|
|
75
|
+
* @param {object} errorAndSuccessFns functions to handle error and success
|
|
76
|
+
* @param {function} errorAndSuccessFns.onErrorFn Calls options.onLoadingError and 'featuresloaderror' event will be fired by using failure callback.
|
|
77
|
+
* @param {function} errorAndSuccessFns.success callback: 'featuresloadend' event will be fired
|
|
78
|
+
* @param {function} errorAndSuccessFns.failure failure callback to ol.VectorLayer, fires 'featuresloaderror' event
|
|
79
|
+
* @param {options} [options] optional additional options
|
|
80
|
+
* @param {Object[]} collectedFeatures the features from previous calls
|
|
81
|
+
* @returns {void}
|
|
82
|
+
*/
|
|
83
|
+
function loadSource (url, source, {onErrorFn, success, failure}, options, collectedFeatures = []) {
|
|
84
|
+
const params = {
|
|
85
|
+
headers: {
|
|
86
|
+
Accept: "application/geo+json"
|
|
87
|
+
},
|
|
88
|
+
method: "GET"
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
fetch(url, params)
|
|
92
|
+
.then((response) => handleErrors(response, onErrorFn, options, failure))
|
|
93
|
+
.then((response) => response.json())
|
|
94
|
+
.then(responseJson => {
|
|
95
|
+
const nextLink = getNextLinkFromFeatureCollection(responseJson);
|
|
96
|
+
|
|
97
|
+
responseJson.features.forEach(feature => collectedFeatures.push(feature));
|
|
98
|
+
if (typeof nextLink === "string") {
|
|
99
|
+
loadSource(nextLink, source, {onErrorFn: onError, success, failure}, options, collectedFeatures);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
responseJson.features = collectedFeatures;
|
|
103
|
+
responseJson.numberReturned = responseJson.numberMatched;
|
|
104
|
+
onLoad(source, source.getFormat().readFeatures(responseJson), onErrorFn, success, failure, options);
|
|
105
|
+
})
|
|
106
|
+
.catch((error) => {
|
|
107
|
+
onErrorFn(error, options, failure);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Creates an ol/source element for the rawLayer by using a loader.
|
|
113
|
+
* The 'featuresloadend' and 'featuresloaderror' events will be fired by using success and failure callbacks of the loader.
|
|
114
|
+
* @param {rawLayer} rawLayer layer specification as in services.json
|
|
115
|
+
* @param {options} [options] additional options
|
|
116
|
+
* @param {String} url the parsed url
|
|
117
|
+
* {@link https://openlayers.org/en/latest/apidoc/module-ol_source_Vector-VectorSource.html failure/success see}
|
|
118
|
+
* @returns {(ol.source.VectorSource|ol.source.Cluster)} VectorSource or Cluster, depending on whether clusterDistance is set.
|
|
119
|
+
*/
|
|
120
|
+
function getLayerSource (rawLayer, options, url) {
|
|
121
|
+
const format = new GeoJSON();
|
|
122
|
+
let source = null;
|
|
123
|
+
|
|
124
|
+
function loader (extent, resolution, projection, success, failure) {
|
|
125
|
+
loadSource(url, source, {onErrorFn: onError, success, failure}, options);
|
|
126
|
+
}
|
|
127
|
+
source = createVectorSource(loader, options.loadingStrategy, format);
|
|
128
|
+
|
|
129
|
+
if (options.beforeLoading) {
|
|
130
|
+
source.once("featuresloadstart", () => options.beforeLoading());
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (rawLayer.clusterDistance) {
|
|
134
|
+
return createClusterVectorSource(source, rawLayer.clusterDistance, options.clusterGeometryFunction);
|
|
135
|
+
}
|
|
136
|
+
return source;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Creates the url for OAF request.
|
|
141
|
+
* @param {rawLayer} rawLayer layer specification as in services.json
|
|
142
|
+
* @returns {string} the url
|
|
143
|
+
*/
|
|
144
|
+
function createUrl (rawLayer) {
|
|
145
|
+
let url = rawLayer.url,
|
|
146
|
+
appendingString;
|
|
147
|
+
const crsDefault = "";
|
|
148
|
+
|
|
149
|
+
url += typeof rawLayer.collection === "string" ? "/collections/" + rawLayer.collection + "/items?" : "";
|
|
150
|
+
url += typeof rawLayer.limit === "number" ? "limit=" + rawLayer.limit + "&" : "";
|
|
151
|
+
if (Array.isArray(rawLayer.bbox) && rawLayer.bbox.length === 4) {
|
|
152
|
+
appendingString = "";
|
|
153
|
+
|
|
154
|
+
rawLayer.bbox.forEach((bboxEntry, i) => {
|
|
155
|
+
appendingString += i !== rawLayer.bbox.length - 1 ? bboxEntry + "," : bboxEntry;
|
|
156
|
+
});
|
|
157
|
+
url += "bbox=" + appendingString + "&";
|
|
158
|
+
}
|
|
159
|
+
url += typeof rawLayer.bboxCrs === "string" && rawLayer.bboxCrs !== "" ? "bbox-crs=" + encodeURIComponent(rawLayer.bboxCrs) + "&" : "";
|
|
160
|
+
url += "crs=" + encodeURIComponent(typeof rawLayer.crs === "string" && rawLayer.crs !== "" ? rawLayer.crs : crsDefault) + "&";
|
|
161
|
+
url += typeof rawLayer.datetime === "string" && rawLayer.datetime !== "" ? "datetime=" + rawLayer.datetime + "&" : "";
|
|
162
|
+
url += getParamsUrl(rawLayer.params);
|
|
163
|
+
|
|
164
|
+
return url;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Creates an ol/source element for the rawLayer by OAF (XML or Geojson)
|
|
169
|
+
* @param {rawLayer} rawLayer layer specification as in services.json
|
|
170
|
+
* @param {options} [options] additional options
|
|
171
|
+
* {@link https://openlayers.org/en/latest/apidoc/module-ol_source_Vector-VectorSource.html failure/success see}
|
|
172
|
+
* @returns {(ol.source.VectorSource|ol.source.Cluster)} VectorSource or Cluster, depending on whether clusterDistance is set.
|
|
173
|
+
*/
|
|
174
|
+
export function createLayerSource (rawLayer, options = {}) {
|
|
175
|
+
if (!options.loadingStrategy) {
|
|
176
|
+
options.loadingStrategy = bbox;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const url = createUrl(rawLayer),
|
|
180
|
+
source = getLayerSource(rawLayer, options, url);
|
|
181
|
+
|
|
182
|
+
return source;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Creates complete ol/Layer from rawLayer containing all required children.
|
|
187
|
+
* @param {rawLayer} rawLayer - layer specification as in services.json
|
|
188
|
+
* @param {object} [optionalParams] - optional params
|
|
189
|
+
* @param {object} [optionalParams.layerParams] - additional layer params
|
|
190
|
+
* @param {options} [optionalParams.options] - additional options
|
|
191
|
+
* @returns {ol.Layer} Layer that can be added to map.
|
|
192
|
+
*/
|
|
193
|
+
export function createLayer (rawLayer = {}, {layerParams = {}, options = {}} = {}) {
|
|
194
|
+
const source = createLayerSource(rawLayer, options),
|
|
195
|
+
layer = new VectorLayer(Object.assign({
|
|
196
|
+
source,
|
|
197
|
+
id: rawLayer.id
|
|
198
|
+
}, layerParams));
|
|
199
|
+
|
|
200
|
+
if (options.style) {
|
|
201
|
+
layer.setStyle(options.style);
|
|
202
|
+
}
|
|
203
|
+
else if (rawLayer.style) {
|
|
204
|
+
layer.setStyle(rawLayer.style);
|
|
205
|
+
}
|
|
206
|
+
return layer;
|
|
207
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a terrain provider with the cesiumTerrainProviderOptions, if not exists.
|
|
3
|
+
* @param {Object} rawLayer attributes of the layer
|
|
4
|
+
* @param {string} [rawLayer.url] - the URL of the Cesium terrain server
|
|
5
|
+
* @param {string} [rawLayer.cesiumTerrainProviderOptions] - see https://cesiumjs.org/Cesium/Build/Documentation/CesiumTerrainProvider.html
|
|
6
|
+
* @returns {void}
|
|
7
|
+
*/
|
|
8
|
+
function createTerrainProvider (rawLayer) {
|
|
9
|
+
const options = {};
|
|
10
|
+
|
|
11
|
+
if (rawLayer.cesiumTerrainProviderOptions) {
|
|
12
|
+
Object.assign(options, rawLayer.cesiumTerrainProviderOptions);
|
|
13
|
+
}
|
|
14
|
+
options.url = rawLayer.url;
|
|
15
|
+
/* eslint-disable no-undef */
|
|
16
|
+
return new Cesium.CesiumTerrainProvider(options);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Sets the layers visibility by setting the terrain provider at Cesium scene.
|
|
21
|
+
* @param {boolean} value if true, terrainProvider is set to map and terrain will be visible
|
|
22
|
+
* @param {Object} rawLayer attributes of the layer
|
|
23
|
+
* @param {string} [rawLayer.url] - the URL of the Cesium terrain server
|
|
24
|
+
* @param {string} [rawLayer.cesiumTerrainProviderOptions] - see https://cesiumjs.org/Cesium/Build/Documentation/CesiumTerrainProvider.html
|
|
25
|
+
* @param {OLCesium} map ol cesium map
|
|
26
|
+
* @returns {void}
|
|
27
|
+
*/
|
|
28
|
+
export function setVisible (value, rawLayer, map) {
|
|
29
|
+
if (map && typeof map.getCesiumScene === "function") {
|
|
30
|
+
if (value) {
|
|
31
|
+
map.getCesiumScene().terrainProvider = createTerrainProvider(rawLayer);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
/* eslint-disable no-undef */
|
|
35
|
+
map.getCesiumScene().terrainProvider = new Cesium.EllipsoidTerrainProvider({});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Creates an terrain layer to use in ol-Cesium map.
|
|
42
|
+
* @param {Object} rawLayer - layer specification as in services.json
|
|
43
|
+
* @param {string} [rawLayer.id] - optional id of the layer, passed to help identification in services.json
|
|
44
|
+
* @param {string} [rawLayer.url] - the URL of the Cesium terrain server
|
|
45
|
+
* @param {string} [rawLayer.isSelected] - if true, terrain is created and shown
|
|
46
|
+
* @param {string} [rawLayer.cesiumTerrainProviderOptions] - see https://cesiumjs.org/Cesium/Build/Documentation/CesiumTerrainProvider.html
|
|
47
|
+
* @param {OLCesium} map ol cesium map
|
|
48
|
+
* @returns {Object} layer
|
|
49
|
+
*/
|
|
50
|
+
export function createLayer (rawLayer, map) {
|
|
51
|
+
this.values = {
|
|
52
|
+
name: rawLayer.name,
|
|
53
|
+
id: rawLayer.id,
|
|
54
|
+
typ: rawLayer.typ
|
|
55
|
+
};
|
|
56
|
+
if (rawLayer.isSelected && map && typeof map.getCesiumScene === "function") {
|
|
57
|
+
setVisible(true, rawLayer, map);
|
|
58
|
+
}
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Returns the value for the given key of the rawlayer.
|
|
63
|
+
* @param {String} key to get the value for
|
|
64
|
+
* @returns {*} the value to the key
|
|
65
|
+
*/
|
|
66
|
+
export function get (key) {
|
|
67
|
+
if (!this.values) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
return this.values[key];
|
|
71
|
+
}
|
|
72
|
+
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates the tileset.
|
|
3
|
+
* @param {Object} rawLayer attributes of the layer
|
|
4
|
+
* @param {string} [rawLayer.url] - the URL of the Cesium terrain server
|
|
5
|
+
* @param {string} [rawLayer.cesiumTerrainProviderOptions] - see https://cesiumjs.org/Cesium/Build/Documentation/CesiumTerrainProvider.html
|
|
6
|
+
* @returns {Cesium.Cesium3DTileset} the tileset
|
|
7
|
+
*/
|
|
8
|
+
function createTileSet (rawLayer) {
|
|
9
|
+
const url = rawLayer.url.split("?")[0] + "/tileset.json",
|
|
10
|
+
options = {};
|
|
11
|
+
|
|
12
|
+
if (rawLayer.cesium3DTilesetOptions) {
|
|
13
|
+
Object.assign(options, rawLayer.cesium3DTilesetOptions);
|
|
14
|
+
}
|
|
15
|
+
options.url = url;
|
|
16
|
+
/* eslint-disable no-undef */
|
|
17
|
+
return new Cesium.Cesium3DTileset(options);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates an terrain layer to use in ol-Cesium map. Sets the id of the rawlayer to tileset.layerReferenceId.
|
|
21
|
+
* @param {Object} rawLayer - layer specification as in services.json
|
|
22
|
+
* @param {string} [rawLayer.id] - optional id of the layer, passed to help identification in services.json
|
|
23
|
+
* @param {string} [rawLayer.url] - the URL of the Cesium terrain server
|
|
24
|
+
* @param {string} [rawLayer.isSelected] - if true, terrain is created and shown
|
|
25
|
+
* @param {string} [rawLayer.cesiumTerrainProviderOptions] - see https://cesiumjs.org/Cesium/Build/Documentation/CesiumTerrainProvider.html
|
|
26
|
+
* @param {OLCesium} map ol cesium map
|
|
27
|
+
* @returns {void}
|
|
28
|
+
*/
|
|
29
|
+
export default function Tileset (rawLayer, map) {
|
|
30
|
+
this.values = {
|
|
31
|
+
name: rawLayer.name,
|
|
32
|
+
id: rawLayer.id,
|
|
33
|
+
typ: rawLayer.typ
|
|
34
|
+
};
|
|
35
|
+
this.tileset = createTileSet(rawLayer);
|
|
36
|
+
this.tileset.layerReferenceId = rawLayer.id;
|
|
37
|
+
|
|
38
|
+
if (rawLayer.isSelected && map && typeof map.getCesiumScene === "function") {
|
|
39
|
+
this.setVisible(true, map);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @param {boolean} value if true, terrainProvider is set to map and terrain will be visible
|
|
45
|
+
* @param {OLCesium} map ol cesium map
|
|
46
|
+
* @returns {void}
|
|
47
|
+
*/
|
|
48
|
+
Tileset.prototype.setVisible = function (value, map) {
|
|
49
|
+
if (map && typeof map.getCesiumScene === "function") {
|
|
50
|
+
if (value) {
|
|
51
|
+
if (!map.getCesiumScene().primitives.contains(this.tileset)) {
|
|
52
|
+
map.getCesiumScene().primitives.add(this.tileset);
|
|
53
|
+
}
|
|
54
|
+
this.tileset.show = true;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this.tileset.show = false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Returns the value for the given key of the rawlayer.
|
|
63
|
+
* @param {String} key to get the value for
|
|
64
|
+
* @returns {*} the value to the key
|
|
65
|
+
*/
|
|
66
|
+
Tileset.prototype.get = function (key) {
|
|
67
|
+
if (!this.values) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
return this.values[key];
|
|
71
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import VectorSource from "ol/source/Vector.js";
|
|
2
|
+
import Cluster from "ol/source/Cluster.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates a VectorSource.
|
|
6
|
+
* @param {function|string} urlOrLoader loader-function to load the features or an url to load them
|
|
7
|
+
* @param {module:ol.source.Vector~LoadingStrategy} strategy The loading strategy to use.
|
|
8
|
+
* @param {module:ol.Format} format to parse the response with
|
|
9
|
+
* @returns {(module:ol.source.VectorSource|module:ol.source.Cluster)} the VectorSource
|
|
10
|
+
*/
|
|
11
|
+
export function createVectorSource (urlOrLoader, strategy, format) {
|
|
12
|
+
let loader,
|
|
13
|
+
url,
|
|
14
|
+
features;
|
|
15
|
+
|
|
16
|
+
if (typeof urlOrLoader === "string") {
|
|
17
|
+
url = urlOrLoader;
|
|
18
|
+
}
|
|
19
|
+
else if (typeof urlOrLoader === "function") {
|
|
20
|
+
loader = urlOrLoader;
|
|
21
|
+
}
|
|
22
|
+
else if (typeof urlOrLoader === "object") {
|
|
23
|
+
features = format.readFeatures(urlOrLoader, {
|
|
24
|
+
dataProjection: "EPSG:4326",
|
|
25
|
+
featureProjection: "EPSG:25832"
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return new VectorSource({
|
|
29
|
+
loader,
|
|
30
|
+
features,
|
|
31
|
+
url,
|
|
32
|
+
strategy,
|
|
33
|
+
format
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Creates a Cluster.
|
|
38
|
+
* @param {module:ol.source.VectorSource} source the source of the layer
|
|
39
|
+
* @param {number} distance - Pixel radius, within this radius, all features are "clustered" into one feature. If available, a cluster source is created.
|
|
40
|
+
* @param {function | undefined} geometryFunction - returns the geometry of the cluster, gets parameter feature. When a feature should not be considered for clustering, the function should return null.
|
|
41
|
+
* @returns {module:ol.source.Cluster} the Cluster
|
|
42
|
+
*/
|
|
43
|
+
export function createClusterVectorSource (source, distance, geometryFunction) {
|
|
44
|
+
return new Cluster({
|
|
45
|
+
source,
|
|
46
|
+
distance,
|
|
47
|
+
geometryFunction});
|
|
48
|
+
}
|