@masterportal/masterportalapi 2.1.1 → 2.4.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/.eslintignore +0 -1
- package/.eslintrc +3 -0
- package/CHANGELOG.md +28 -6
- package/example/config/localGeoJSON.js +24 -24
- package/example/config/portal.json +1 -1
- package/example/config/services.json +189 -53
- package/example/index.js +79 -64
- package/package.json +2 -2
- package/src/defaults.js +17 -1
- package/src/index.js +6 -0
- package/src/layer/entities.js +179 -0
- package/src/layer/geojson/index.js +7 -0
- package/src/layer/geojson/style.js +1 -0
- package/src/layer/terrain.js +1 -8
- package/src/layer/tileset.js +1 -8
- package/src/layer/vectorTile.js +174 -0
- package/src/layer/wms.js +4 -0
- package/src/layer/wmts.js +194 -0
- package/src/maps/ol/olMap.js +4 -0
- package/src/maps/olcs/3dUtils/wmsRasterSynchronizer.js +88 -52
- package/src/maps/olcs/olcsMap.js +115 -99
- package/test/layer/entities.test.js +277 -0
- package/test/layer/terrain.test.js +1 -14
- package/test/layer/tileset.test.js +3 -10
- package/test/layer/vectorTile.test.js +172 -0
- package/test/layer/wmts.test.js +26 -0
- package/test/map.test.js +34 -1
package/src/defaults.js
CHANGED
|
@@ -34,5 +34,21 @@ export default {
|
|
|
34
34
|
}
|
|
35
35
|
],
|
|
36
36
|
gazetteerUrl: "https://geodienste.hamburg.de/HH_WFS_GAGES?service=WFS&request=GetFeature&version=2.0.0",
|
|
37
|
-
showGeographicIdentifier: false
|
|
37
|
+
showGeographicIdentifier: false,
|
|
38
|
+
sceneOptions: {
|
|
39
|
+
camera: {
|
|
40
|
+
enableTerrainAdjustmentWhenLoading: true
|
|
41
|
+
},
|
|
42
|
+
globe: {
|
|
43
|
+
depthTestAgainstTerrain: true // is necessary for scene.pickedPosition and correct height of the terrain. @see {https://github.com/CesiumGS/cesium/issues/5676}
|
|
44
|
+
},
|
|
45
|
+
highDynamicRange: false,
|
|
46
|
+
pickTranslucentDepth: true,
|
|
47
|
+
shadowMap: {
|
|
48
|
+
darkness: 0.6,
|
|
49
|
+
maximumDistance: 5000.0,
|
|
50
|
+
size: 2048
|
|
51
|
+
},
|
|
52
|
+
shadows: false
|
|
53
|
+
}
|
|
38
54
|
};
|
package/src/index.js
CHANGED
|
@@ -2,11 +2,14 @@ import {createMapView} from "./maps/mapView";
|
|
|
2
2
|
import * as crs from "./crs";
|
|
3
3
|
import * as rawLayerList from "./rawLayerList";
|
|
4
4
|
import * as wms from "./layer/wms";
|
|
5
|
+
import * as wmts from "./layer/wmts";
|
|
5
6
|
import * as wfs from "./layer/wfs";
|
|
6
7
|
import * as geojson from "./layer/geojson";
|
|
7
8
|
import * as vectorBase from "./layer/vectorBase";
|
|
9
|
+
import * as vectorTile from "./layer/vectorTile";
|
|
8
10
|
import * as oaf from "./layer/oaf";
|
|
9
11
|
import * as terrain from "./layer/terrain";
|
|
12
|
+
import * as entities from "./layer/entities";
|
|
10
13
|
import Tileset from "./layer/tileset";
|
|
11
14
|
import * as layerLib from "./layer/lib";
|
|
12
15
|
import {search, setGazetteerUrl} from "./searchAddress";
|
|
@@ -15,12 +18,15 @@ import setBackgroundImage from "./lib/setBackgroundImage";
|
|
|
15
18
|
export {
|
|
16
19
|
createMapView,
|
|
17
20
|
wms,
|
|
21
|
+
wmts,
|
|
18
22
|
wfs,
|
|
19
23
|
geojson,
|
|
20
24
|
layerLib,
|
|
21
25
|
vectorBase,
|
|
26
|
+
vectorTile,
|
|
22
27
|
oaf,
|
|
23
28
|
terrain,
|
|
29
|
+
entities,
|
|
24
30
|
Tileset,
|
|
25
31
|
setBackgroundImage,
|
|
26
32
|
setGazetteerUrl,
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets the layers visibility by setting the show attribute at the datasource.
|
|
3
|
+
* @param {boolean} value if true, the entity will be shown
|
|
4
|
+
* @param {Object} rawLayer attributes of the layer
|
|
5
|
+
* @param {string} [rawLayer.id] the id of the layer
|
|
6
|
+
* @param {OLCesium} map ol cesium map
|
|
7
|
+
* @returns {void}
|
|
8
|
+
*/
|
|
9
|
+
export function setVisible (value, rawLayer, map) {
|
|
10
|
+
if (map && typeof map.getDataSources === "function") {
|
|
11
|
+
const dataSources = map.getDataSources(),
|
|
12
|
+
dataSource = dataSources.getByName(rawLayer?.id);
|
|
13
|
+
|
|
14
|
+
if (dataSource.length === 0) {
|
|
15
|
+
console.warn("Cannot change visibility of 3D entity for layer with id ", rawLayer.id, ". Datasource is not available.");
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
dataSource[0].show = typeof value === "boolean" ? value : false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Adapts the rawEntity and adds it to the dataSource's entities.
|
|
25
|
+
* The created entity has the attribute 'layerReferenceId' which contains the rawLayer's id.
|
|
26
|
+
* @param {Object} rawEntity to add to the dataSource
|
|
27
|
+
* @param {string} [rawEntity.url] specifying the URI of the glTF asset
|
|
28
|
+
* @param {number} [rawEntity.longitude] longitude of the position
|
|
29
|
+
* @param {number} [rawEntity.latitude] latitude of the position
|
|
30
|
+
* @param {number} [rawEntity.height] height of the position
|
|
31
|
+
* @param {boolean} [rawEntity.allowPicking] if true, each geometry instance will only be pickable with Scene#pick. When false, GPU memory is saved
|
|
32
|
+
* @param {Array} [rawEntity.attributes] attributes of the glTF asset
|
|
33
|
+
* @param {number} [rawEntity.heading] the rotation about the negative z axis
|
|
34
|
+
* @param {number} [rawEntity.pitch] the rotation about the negative y axis
|
|
35
|
+
* @param {number} [rawEntity.roll] the rotation about the positive x axis
|
|
36
|
+
* @param {boolean} [rawEntity.show] optional- if true, entity is shown.
|
|
37
|
+
* @param {Cesium.CustomDataSource} dataSource a Cesium.DataSource implementation to manage a group of entities
|
|
38
|
+
* @param {Object} rawLayer layer specification as in services.json
|
|
39
|
+
* @param {string} [rawLayer.id] optional id of the layer, passed to help identification in services.json
|
|
40
|
+
* @returns {Object} the created entity
|
|
41
|
+
*/
|
|
42
|
+
function addEntity (rawEntity, dataSource, rawLayer) {
|
|
43
|
+
if (typeof rawEntity.url !== "string") {
|
|
44
|
+
console.warn("Url of entity must be a string, but is:", rawEntity.url);
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
if (![rawEntity.longitude, rawEntity.latitude, rawEntity.height].every(num => typeof num === "number")) {
|
|
48
|
+
console.warn("longitude, latitude and height of entity must be a number.");
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const position = Cesium.Cartesian3.fromDegrees(rawEntity.longitude, rawEntity.latitude, rawEntity.height),
|
|
52
|
+
allowPicking = typeof rawEntity.allowPicking === "boolean" ? rawEntity.allowPicking : true,
|
|
53
|
+
attributes = rawEntity.attributes ? rawEntity.attributes : {};
|
|
54
|
+
let headingPitchRoll = "",
|
|
55
|
+
orientation = "",
|
|
56
|
+
modelOptions = "",
|
|
57
|
+
entityOptions = null,
|
|
58
|
+
entity = "",
|
|
59
|
+
heading = 0,
|
|
60
|
+
pitch = 0,
|
|
61
|
+
roll = 0;
|
|
62
|
+
|
|
63
|
+
if (typeof rawEntity.heading === "number") {
|
|
64
|
+
heading = rawEntity.heading / 180 * Math.PI;
|
|
65
|
+
}
|
|
66
|
+
if (typeof rawEntity.pitch === "number") {
|
|
67
|
+
pitch = rawEntity.pitch / 180 * Math.PI;
|
|
68
|
+
}
|
|
69
|
+
if (typeof rawEntity.roll === "number") {
|
|
70
|
+
roll = rawEntity.roll / 180 * Math.PI;
|
|
71
|
+
}
|
|
72
|
+
headingPitchRoll = new Cesium.HeadingPitchRoll(heading, pitch, roll);
|
|
73
|
+
orientation = Cesium.Transforms.headingPitchRollQuaternion(position, headingPitchRoll);
|
|
74
|
+
modelOptions = Object.assign(rawEntity.modelOptions || {}, {
|
|
75
|
+
uri: rawEntity.url,
|
|
76
|
+
scale: typeof rawEntity.scale === "number" ? rawEntity.scale : 1,
|
|
77
|
+
show: typeof rawEntity.show === "boolean" ? rawEntity.show : false
|
|
78
|
+
});
|
|
79
|
+
entityOptions = {
|
|
80
|
+
name: rawEntity.url,
|
|
81
|
+
position,
|
|
82
|
+
orientation,
|
|
83
|
+
show: typeof rawEntity.show === "boolean" ? rawEntity.show : false,
|
|
84
|
+
model: modelOptions
|
|
85
|
+
};
|
|
86
|
+
entity = dataSource.entities.add(entityOptions);
|
|
87
|
+
entity.attributes = attributes;
|
|
88
|
+
entity.allowPicking = allowPicking;
|
|
89
|
+
entity.layerReferenceId = rawLayer.id;
|
|
90
|
+
return entity;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Iterates over the entities of the raw layer and adds them to dataSource.
|
|
95
|
+
* @param {Object} rawLayer attributes of the layer
|
|
96
|
+
* @param {string} [rawLayer.id] the id of the layer
|
|
97
|
+
* @param {string} [rawLayer.entities] array of entities to add
|
|
98
|
+
* @param {Cesium.CustomDataSource} dataSource a Cesium.DataSource implementation to manage a group of entities
|
|
99
|
+
* @returns {void}
|
|
100
|
+
*/
|
|
101
|
+
function addEntities (rawLayer, dataSource) {
|
|
102
|
+
if (rawLayer.entities) {
|
|
103
|
+
rawLayer.entities.forEach(entity => {
|
|
104
|
+
// just created dataSource is an object, but if it is got by name it is contained in an array
|
|
105
|
+
addEntity(entity, Array.isArray(dataSource) ? dataSource[0] : dataSource, rawLayer);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Creates a Cesium.CustomDataSource and adds it to map's dataSources.
|
|
112
|
+
* Iterates over the entities of the raw layer and adds them to dataSource.
|
|
113
|
+
* @param {Object} rawLayer attributes of the layer
|
|
114
|
+
* @param {string} [rawLayer.id] the id of the layer
|
|
115
|
+
* @param {string} [rawLayer.entities] array of entities to add
|
|
116
|
+
* @param {OLCesium} map ol cesium map
|
|
117
|
+
* @param {function} callback to execute after datasource is added to map and entities are added
|
|
118
|
+
* @returns {*} null or the return-value of the callback
|
|
119
|
+
*/
|
|
120
|
+
export function createDataSource (rawLayer, map, callback) {
|
|
121
|
+
if (!rawLayer) {
|
|
122
|
+
console.warn("Cannot add entities to rawLayer which is null!");
|
|
123
|
+
}
|
|
124
|
+
else if (map && typeof map.getDataSources === "function") {
|
|
125
|
+
const dataSources = map.getDataSources();
|
|
126
|
+
let dataSource = dataSources.getByName(rawLayer.id);
|
|
127
|
+
|
|
128
|
+
if (dataSource.length === 0) {
|
|
129
|
+
dataSource = new Cesium.CustomDataSource(rawLayer.id);
|
|
130
|
+
dataSources.add(dataSource).then(function (addedDataSource) {
|
|
131
|
+
addEntities(rawLayer, addedDataSource, map);
|
|
132
|
+
if (callback) {
|
|
133
|
+
return callback();
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
addEntities(rawLayer, dataSource, map);
|
|
140
|
+
if (callback) {
|
|
141
|
+
return callback();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Creates an entities layer to use in ol-Cesium map.
|
|
151
|
+
* @param {Object} rawLayer layer specification as in services.json
|
|
152
|
+
* @param {string} [rawLayer.id] optional id of the layer, passed to help identification in services.json
|
|
153
|
+
* @param {string} [rawLayer.name] optional name of the layer, passed to help identification in services.json
|
|
154
|
+
* @param {string} [rawLayer.typ] typ of the layer, passed to help identification in services.json
|
|
155
|
+
* @param {Array} [rawLayer.entities] array of entities to add
|
|
156
|
+
* @param {OLCesium} map ol cesium map
|
|
157
|
+
* @returns {Object} layer
|
|
158
|
+
*/
|
|
159
|
+
export function createLayer (rawLayer, map) {
|
|
160
|
+
createDataSource(rawLayer, map);
|
|
161
|
+
this.values = {
|
|
162
|
+
name: rawLayer.name,
|
|
163
|
+
id: rawLayer.id,
|
|
164
|
+
typ: rawLayer.typ
|
|
165
|
+
};
|
|
166
|
+
return this;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Returns the value for the given key of the rawlayer.
|
|
171
|
+
* @param {String} key to get the value for
|
|
172
|
+
* @returns {*} the value to the key
|
|
173
|
+
*/
|
|
174
|
+
export function get (key) {
|
|
175
|
+
if (!this.values) {
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
return this.values[key];
|
|
179
|
+
}
|
|
@@ -25,6 +25,13 @@ export function createLayerSource ({url, features, clusterDistance}, options) {
|
|
|
25
25
|
if (clusterDistance) {
|
|
26
26
|
return createClusterVectorSource(source, clusterDistance, options.clusterGeometryFunction);
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
source.once("featuresloadend", event => {
|
|
30
|
+
if (typeof options.afterLoading === "function") {
|
|
31
|
+
options.afterLoading(event?.features);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
28
35
|
return source;
|
|
29
36
|
}
|
|
30
37
|
|
package/src/layer/terrain.js
CHANGED
|
@@ -12,7 +12,6 @@ function createTerrainProvider (rawLayer) {
|
|
|
12
12
|
Object.assign(options, rawLayer.cesiumTerrainProviderOptions);
|
|
13
13
|
}
|
|
14
14
|
options.url = rawLayer.url;
|
|
15
|
-
/* eslint-disable no-undef */
|
|
16
15
|
return new Cesium.CesiumTerrainProvider(options);
|
|
17
16
|
}
|
|
18
17
|
|
|
@@ -31,7 +30,6 @@ export function setVisible (value, rawLayer, map) {
|
|
|
31
30
|
map.getCesiumScene().terrainProvider = createTerrainProvider(rawLayer);
|
|
32
31
|
}
|
|
33
32
|
else {
|
|
34
|
-
/* eslint-disable no-undef */
|
|
35
33
|
map.getCesiumScene().terrainProvider = new Cesium.EllipsoidTerrainProvider({});
|
|
36
34
|
}
|
|
37
35
|
}
|
|
@@ -42,20 +40,15 @@ export function setVisible (value, rawLayer, map) {
|
|
|
42
40
|
* @param {Object} rawLayer - layer specification as in services.json
|
|
43
41
|
* @param {string} [rawLayer.id] - optional id of the layer, passed to help identification in services.json
|
|
44
42
|
* @param {string} [rawLayer.url] - the URL of the Cesium terrain server
|
|
45
|
-
* @param {string} [rawLayer.isSelected] - if true, terrain is created and shown
|
|
46
43
|
* @param {string} [rawLayer.cesiumTerrainProviderOptions] - see https://cesiumjs.org/Cesium/Build/Documentation/CesiumTerrainProvider.html
|
|
47
|
-
* @param {OLCesium} map ol cesium map
|
|
48
44
|
* @returns {Object} layer
|
|
49
45
|
*/
|
|
50
|
-
export function createLayer (rawLayer
|
|
46
|
+
export function createLayer (rawLayer) {
|
|
51
47
|
this.values = {
|
|
52
48
|
name: rawLayer.name,
|
|
53
49
|
id: rawLayer.id,
|
|
54
50
|
typ: rawLayer.typ
|
|
55
51
|
};
|
|
56
|
-
if (rawLayer.isSelected && map && typeof map.getCesiumScene === "function") {
|
|
57
|
-
setVisible(true, rawLayer, map);
|
|
58
|
-
}
|
|
59
52
|
return this;
|
|
60
53
|
}
|
|
61
54
|
/**
|
package/src/layer/tileset.js
CHANGED
|
@@ -13,7 +13,6 @@ function createTileSet (rawLayer) {
|
|
|
13
13
|
Object.assign(options, rawLayer.cesium3DTilesetOptions);
|
|
14
14
|
}
|
|
15
15
|
options.url = url;
|
|
16
|
-
/* eslint-disable no-undef */
|
|
17
16
|
return new Cesium.Cesium3DTileset(options);
|
|
18
17
|
}
|
|
19
18
|
/**
|
|
@@ -21,12 +20,10 @@ function createTileSet (rawLayer) {
|
|
|
21
20
|
* @param {Object} rawLayer - layer specification as in services.json
|
|
22
21
|
* @param {string} [rawLayer.id] - optional id of the layer, passed to help identification in services.json
|
|
23
22
|
* @param {string} [rawLayer.url] - the URL of the Cesium terrain server
|
|
24
|
-
* @param {string} [rawLayer.isSelected] - if true, terrain is created and shown
|
|
25
23
|
* @param {string} [rawLayer.cesiumTerrainProviderOptions] - see https://cesiumjs.org/Cesium/Build/Documentation/CesiumTerrainProvider.html
|
|
26
|
-
* @param {OLCesium} map ol cesium map
|
|
27
24
|
* @returns {void}
|
|
28
25
|
*/
|
|
29
|
-
export default function Tileset (rawLayer
|
|
26
|
+
export default function Tileset (rawLayer) {
|
|
30
27
|
this.values = {
|
|
31
28
|
name: rawLayer.name,
|
|
32
29
|
id: rawLayer.id,
|
|
@@ -34,10 +31,6 @@ export default function Tileset (rawLayer, map) {
|
|
|
34
31
|
};
|
|
35
32
|
this.tileset = createTileSet(rawLayer);
|
|
36
33
|
this.tileset.layerReferenceId = rawLayer.id;
|
|
37
|
-
|
|
38
|
-
if (rawLayer.isSelected && map && typeof map.getCesiumScene === "function") {
|
|
39
|
-
this.setVisible(true, map);
|
|
40
|
-
}
|
|
41
34
|
}
|
|
42
35
|
/**
|
|
43
36
|
*
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import MVT from "ol/format/MVT";
|
|
2
|
+
import VectorTileLayer from "ol/layer/VectorTile";
|
|
3
|
+
import VectorTileSource from "ol/source/VectorTile";
|
|
4
|
+
import OpenLayersTileGrid from "ol/tilegrid/TileGrid";
|
|
5
|
+
import {extentFromProjection} from "ol/tilegrid";
|
|
6
|
+
|
|
7
|
+
import stylefunction from "ol-mapbox-style/dist/stylefunction";
|
|
8
|
+
import {defaultResolutions} from "ol-mapbox-style/dist/util";
|
|
9
|
+
|
|
10
|
+
import defaults from "../defaults";
|
|
11
|
+
|
|
12
|
+
const OL_DEFAULT_VECTOR_TILE_GRID_CRS = "EPSG:3857";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Used properites of layer specification as in services.json.
|
|
16
|
+
*
|
|
17
|
+
* @typedef {Object} rawLayer
|
|
18
|
+
* @property {string} id - Layer id
|
|
19
|
+
* @property {string} name - Layer name
|
|
20
|
+
* @property {string} url - source url
|
|
21
|
+
* @property {string} [epsg=defaults.epsg] - vector tiles crs
|
|
22
|
+
* @property {number[]} [extent] - extent
|
|
23
|
+
* @property {number} [maxZoom=22] - min zoom level
|
|
24
|
+
* @property {number} [minZoom] - max zoom level
|
|
25
|
+
* @property {function} [olAttribution] - optional function that takes a module:ol/PluggableMap~FrameState and returns a string or an array of strings representing source attributions
|
|
26
|
+
* @property {number[]} [origin] - The tile grid origin, i.e. where the x and y axes meet ([z, 0, 0]). Tile coordinates increase left to right and downwards
|
|
27
|
+
* @property {number[][]} [origins] - Tile grid origins, i.e. where the x and y axes meet ([z, 0, 0]), for each zoom level. If given, the array length should match the length of the resolutions array, i.e. each resolution can have a different origin. Tile coordinates increase left to right and downwards. If not specified, extent or origin must be provided.
|
|
28
|
+
* @property {number[]} [resolutions] - Resolutions. The array index of each resolution needs to match the zoom level. This means that even if a minZoom is configured, the resolutions array will have a length of maxZoom + 1.
|
|
29
|
+
* @property {number} [tileSize=512] - size of a tile in px
|
|
30
|
+
* @property {number} [zDirection=1] - zoom level offset for requested tiles
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Used properites of layer specification as in services.json.
|
|
35
|
+
*
|
|
36
|
+
* @typedef {Object} tileGridProperties
|
|
37
|
+
* @property {string} [epsg] - vector tiles crs
|
|
38
|
+
* @property {number} [tileSize=512] - size of a tile in px
|
|
39
|
+
* @property {number} [zDirection=1] - zoom level offset for requested tiles
|
|
40
|
+
* @property {number} [minZoom] - min zoom level
|
|
41
|
+
* @property {number} [maxZoom=22] - may zoom level
|
|
42
|
+
* @property {number[]} [extent] - extent
|
|
43
|
+
* @property {number[]} [resolutions] - Resolutions. The array index of each resolution needs to match the zoom level. This means that even if a minZoom is configured, the resolutions array will have a length of maxZoom + 1.
|
|
44
|
+
* @property {number[]} [origin] - The tile grid origin, i.e. where the x and y axes meet ([z, 0, 0]). Tile coordinates increase left to right and downwards
|
|
45
|
+
* @property {number[][]} [origins] - Tile grid origins, i.e. where the x and y axes meet ([z, 0, 0]), for each zoom level. If given, the array length should match the length of the resolutions array, i.e. each resolution can have a different origin. Tile coordinates increase left to right and downwards. If not specified, extent or origin must be provided.
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Additional properties for style specification
|
|
50
|
+
* @typedef {Object} styleParams
|
|
51
|
+
* @property {string} [sourceId] - key from the Mapbox Style object. When a source key is provided, all layers for the specified source will be included in the style function.
|
|
52
|
+
* @property {number[]} [resolutions] - Resolutions for mapping resolution to zoom level.
|
|
53
|
+
* @property {object} [spriteData] - Sprite data from the url specified in the Mapbox Style object's sprite property. Only required if a sprite property is specified in the Mapbox Style object.
|
|
54
|
+
* @property {string} [spriteImageUrl] - Url to sprite image
|
|
55
|
+
* @property {function} [getFonts] - Function that receives a font stack as arguments, and returns a (modified) font stack that is available. Font names are the names used in the Mapbox Style object. If not provided, the font stack will be used as-is. This function can also be used for loading web fonts.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Create a TileGrid.
|
|
60
|
+
*
|
|
61
|
+
* @param {tileGridProperties} [options] - options
|
|
62
|
+
* @returns {ol.tilegrid.TileGrid} TileGrid
|
|
63
|
+
*/
|
|
64
|
+
export function createTileGrid (options = {}) {
|
|
65
|
+
|
|
66
|
+
const epsg = options.epsg ? options.epsg : defaults.epsg,
|
|
67
|
+
extent = options.extent ? options.extent : extentFromProjection(epsg),
|
|
68
|
+
tileSize = options.tileSize ? options.tileSize : 512,
|
|
69
|
+
resolutions = options.resolutions ? options.resolutions : defaults.options.map(x => x.resolution),
|
|
70
|
+
tileGridParams = {
|
|
71
|
+
extent: extent,
|
|
72
|
+
resolutions: resolutions,
|
|
73
|
+
minZoom: options.minZoom,
|
|
74
|
+
tileSize: new Array(2).fill(tileSize)
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
if (options.origins) {
|
|
78
|
+
tileGridParams.origins = options.origins;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
tileGridParams.origin = options.origin ? options.origin : [tileGridParams.extent[0], tileGridParams.extent[3]];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return new OpenLayersTileGrid(tileGridParams);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Check if TileGrid must be created.
|
|
89
|
+
*
|
|
90
|
+
* @param {tileGridProperties} options - tile grid parameters
|
|
91
|
+
* @returns {boolean} must create tileGrid
|
|
92
|
+
*/
|
|
93
|
+
function mustCreateTileGrid (options = {}) {
|
|
94
|
+
const createOptions = [options.extent, options.tileSize, options.resolutions, options.origin, options.origins, options.minZoom],
|
|
95
|
+
epsgTest = options.epsg ? options.epsg.toUpperCase() : options.epsg;
|
|
96
|
+
|
|
97
|
+
if (!createOptions.every((x) => typeof x === "undefined")) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (epsgTest !== OL_DEFAULT_VECTOR_TILE_GRID_CRS) {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Creates a Vector Tiles source.
|
|
109
|
+
*
|
|
110
|
+
* @param {string} url - url to vector tile service
|
|
111
|
+
* @param {tileGridProperties} [options] - properties for tileGrid
|
|
112
|
+
* @returns {ol.source.VectorTile} Source
|
|
113
|
+
*/
|
|
114
|
+
export function createLayerSource (url, options = {}) {
|
|
115
|
+
options.epsg = options.epsg ? options.epsg : defaults.epsg;
|
|
116
|
+
|
|
117
|
+
const sourceParams = {
|
|
118
|
+
projection: options.epsg,
|
|
119
|
+
format: new MVT(),
|
|
120
|
+
url: url,
|
|
121
|
+
tileSize: options.tileSize,
|
|
122
|
+
zDirection: options.zDirection,
|
|
123
|
+
minZoom: options.minZoom,
|
|
124
|
+
maxZoom: options.maxZoom
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
if (mustCreateTileGrid(options)) {
|
|
128
|
+
sourceParams.tileGrid = createTileGrid(options);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return new VectorTileSource(sourceParams);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Creates a Vector Tiles layer.
|
|
136
|
+
*
|
|
137
|
+
* @param {rawLayer} rawLayer - rawLayer as specified in services.json
|
|
138
|
+
* @param {object} [layerParams={}] - extra params of the layer. Can overwrite or extend all ol layer parameters.
|
|
139
|
+
* @param {object} [options={}] - parameter object. Not used atm.
|
|
140
|
+
* @returns {ol.layer.VectorTile} Layer with id and source specified in rawLayer
|
|
141
|
+
*/
|
|
142
|
+
export function createLayer (rawLayer = {}, {layerParams = {}, options = {}} = {}) {
|
|
143
|
+
if ([rawLayer.id, rawLayer.name, rawLayer.url].some((x) => typeof x === "undefined")) {
|
|
144
|
+
console.error(`Cancelled creation of layer "${rawLayer.id}"(${rawLayer.name}) because of missing required parameters`);
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
const source = createLayerSource(rawLayer.url, rawLayer),
|
|
148
|
+
layer = new VectorTileLayer(Object.assign({
|
|
149
|
+
id: rawLayer.id, name: rawLayer.name, attribution: rawLayer.olAttribution, extent: source.getTileGrid().getExtent(),
|
|
150
|
+
minZoom: rawLayer.minZoom, maxZoom: rawLayer.maxZoom, source: source,
|
|
151
|
+
declutter: true}, layerParams));
|
|
152
|
+
|
|
153
|
+
if (options.style) {
|
|
154
|
+
layer.setStyle(options.style);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return layer;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Set a mapbox style
|
|
162
|
+
* @param {ol.layer.VectorTile} layer - layer to style
|
|
163
|
+
* @param {object} glStyle - MapBox style definition
|
|
164
|
+
* @param {options} [styleParams={}] - Additional options for style specification
|
|
165
|
+
* @returns {void}
|
|
166
|
+
*/
|
|
167
|
+
export function setStyle (layer, glStyle, {options = {}} = {}) {
|
|
168
|
+
stylefunction(layer, glStyle,
|
|
169
|
+
options.sourceId ? options.sourceId : Object.keys(glStyle.sources)[0],
|
|
170
|
+
options.resolutions ? options.resolutions : defaultResolutions,
|
|
171
|
+
options.spriteData,
|
|
172
|
+
options.spriteImageUrl,
|
|
173
|
+
options.getFonts);
|
|
174
|
+
}
|
package/src/layer/wms.js
CHANGED
|
@@ -7,6 +7,8 @@ import {get as getProjection} from "ol/proj";
|
|
|
7
7
|
|
|
8
8
|
import {getLayerWhere} from "../rawLayerList";
|
|
9
9
|
|
|
10
|
+
const OLCS_DEFAULT_OLCS_PROJECTION_CRS = "EPSG:3857";
|
|
11
|
+
|
|
10
12
|
/** @returns {number} random session id in range (0, 9999999) */
|
|
11
13
|
export function generateSessionId () {
|
|
12
14
|
return Math.floor(Math.random() * 9999999);
|
|
@@ -138,6 +140,8 @@ export function createLayer (rawLayer, layerParams = {}, options) {
|
|
|
138
140
|
const source = createLayerSource(rawLayer, options),
|
|
139
141
|
Layer = rawLayer.singleTile ? ImageLayer : TileLayer;
|
|
140
142
|
|
|
143
|
+
source.set("olcs.projection", getProjection(OLCS_DEFAULT_OLCS_PROJECTION_CRS));
|
|
144
|
+
|
|
141
145
|
return new Layer(Object.assign({
|
|
142
146
|
source,
|
|
143
147
|
minResolution: rawLayer.minScale,
|