@masterportal/masterportalapi 2.2.0 → 2.3.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.
@@ -0,0 +1,170 @@
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
+ * @returns {void}
118
+ */
119
+ export function createDataSource (rawLayer, map) {
120
+ if (!rawLayer) {
121
+ console.warn("Cannot add entities to rawLayer which is null!");
122
+ }
123
+ else if (map && typeof map.getDataSources === "function") {
124
+ const dataSources = map.getDataSources();
125
+ let dataSource = dataSources.getByName(rawLayer.id);
126
+
127
+ if (dataSource.length === 0) {
128
+ dataSource = new Cesium.CustomDataSource(rawLayer.id);
129
+ dataSources.add(dataSource).then(function (addedDataSource) {
130
+ addEntities(rawLayer, addedDataSource, map);
131
+ });
132
+ }
133
+ else {
134
+ addEntities(rawLayer, dataSource, map);
135
+ }
136
+ }
137
+ }
138
+
139
+
140
+ /**
141
+ * Creates an entities layer to use in ol-Cesium map.
142
+ * @param {Object} rawLayer layer specification as in services.json
143
+ * @param {string} [rawLayer.id] optional id of the layer, passed to help identification in services.json
144
+ * @param {string} [rawLayer.name] optional name of the layer, passed to help identification in services.json
145
+ * @param {string} [rawLayer.typ] typ of the layer, passed to help identification in services.json
146
+ * @param {Array} [rawLayer.entities] array of entities to add
147
+ * @param {OLCesium} map ol cesium map
148
+ * @returns {Object} layer
149
+ */
150
+ export function createLayer (rawLayer, map) {
151
+ createDataSource(rawLayer, map);
152
+ this.values = {
153
+ name: rawLayer.name,
154
+ id: rawLayer.id,
155
+ typ: rawLayer.typ
156
+ };
157
+ return this;
158
+ }
159
+
160
+ /**
161
+ * Returns the value for the given key of the rawlayer.
162
+ * @param {String} key to get the value for
163
+ * @returns {*} the value to the key
164
+ */
165
+ export function get (key) {
166
+ if (!this.values) {
167
+ return undefined;
168
+ }
169
+ return this.values[key];
170
+ }
@@ -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
 
@@ -14,6 +14,7 @@ export function setCustomStyles (styles) {
14
14
 
15
15
  // // // STYLE PARTS
16
16
  const marker = new Icon({
17
+ crossOrigin: "anonymous",
17
18
  src: markerSvg,
18
19
  // center bottom of marker 📍 is intended to show the spot
19
20
  anchor: [0.5, 1]
@@ -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, map) {
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
  /**
@@ -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, map) {
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
  *
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,
@@ -0,0 +1,194 @@
1
+ import WMTS, {optionsFromCapabilities} from "ol/source/WMTS";
2
+ import WMTSTileGrid from "ol/tilegrid/WMTS";
3
+ import TileLayer from "ol/layer/Tile";
4
+ import {DEVICE_PIXEL_RATIO} from "ol/has";
5
+ import {getWidth} from "ol/extent";
6
+ import WMTSCapabilities from "ol/format/WMTSCapabilities";
7
+ import {get as getProjection} from "ol/proj";
8
+
9
+ /**
10
+ * Shows error message in console for various WMTS errors.
11
+ * @param {String} errorMessage error message
12
+ * @param {String} layerName layerName
13
+ * @returns {void}
14
+ */
15
+ export function showErrorMessage (errorMessage, layerName) {
16
+ console.error("content: Layer " + layerName + ": " + errorMessage);
17
+ }
18
+
19
+ /**
20
+ * Generates resolutions and matrixIds arrays for the WMTS LayerSource.
21
+ * @param {Array} resolutions The resolutions array for the LayerSource.
22
+ * @param {Array} matrixIds The matrixIds array for the LayerSource.
23
+ * @param {Number} length The length of the given arrays.
24
+ * @param {Number} size The tileSize depending on the extent.
25
+ * @returns {void}
26
+ */
27
+ export function generateArrays (resolutions, matrixIds, length, size) {
28
+ for (let i = 0; i < length; ++i) {
29
+ resolutions[i] = size / Math.pow(2, i);
30
+ matrixIds[i] = i;
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Gets the WMTS-GetCapabilities document and parse it
36
+ * @param {String} url url for getting capabilities
37
+ * @throws {Error} on unexpected return
38
+ * @returns {promise} promise resolves to parsed WMTS-GetCapabilities object
39
+ */
40
+ export function getWMTSCapabilities (url) {
41
+ return fetch(url)
42
+ .then(response => {
43
+ if (response && response.status === 200) {
44
+ return response.text();
45
+ }
46
+ console.error(response);
47
+ throw new Error(`Failing WMTS request to ${url}. Status: ${response?.status}`);
48
+ })
49
+ .then((text) => new WMTSCapabilities().read(text));
50
+ }
51
+
52
+ /**
53
+ * Creates the LayerSource from definitions in the service.json for this WMTSLayer.
54
+ * @param {Object} attrs attributes of the layer
55
+ * @param {WMTS} tileLayer layer object
56
+ * @returns {void}
57
+ */
58
+ export function createLayerSourceByDefinitions (attrs, tileLayer) {
59
+ const projection = getProjection(attrs.coordinateSystem),
60
+ extent = projection.getExtent(),
61
+ style = attrs.style,
62
+ format = attrs.format,
63
+ wrapX = attrs.wrapX ? attrs.wrapX : false,
64
+ urls = attrs.urls,
65
+ size = extent ? getWidth(extent) / parseInt(attrs.tileSize, 10) : null,
66
+ resLength = parseInt(attrs.resLength, 10),
67
+ resolutions = new Array(resLength),
68
+ matrixIds = new Array(resLength),
69
+ source = new WMTS({
70
+ projection: projection,
71
+ attributions: attrs.olAttribution,
72
+ tileGrid: new WMTSTileGrid({
73
+ origin: attrs.origin,
74
+ resolutions: resolutions,
75
+ matrixIds: matrixIds,
76
+ tileSize: attrs.tileSize
77
+ }),
78
+ tilePixelRatio: DEVICE_PIXEL_RATIO,
79
+ urls: urls,
80
+ matrixSet: attrs.tileMatrixSet,
81
+ matrixSizes: attrs.matrixSizes,
82
+ layer: attrs.layers,
83
+ format: format,
84
+ style: style,
85
+ version: attrs.version,
86
+ transparent: attrs.transparent.toString(),
87
+ wrapX: wrapX,
88
+ requestEncoding: attrs.requestEncoding,
89
+ scales: attrs.scales
90
+ });
91
+
92
+ if (size) {
93
+ generateArrays(resolutions, matrixIds, resLength, size);
94
+ }
95
+ else {
96
+ showErrorMessage(attrs.name, `${projection.getCode()} has been given as projection to wmts.js for layer with id ${attrs.id}, but only "EPSG:4326" and "EPSG:3857" are supported. Please use the "capabilitiesUrl" and "optionsFromCapabilities" configuration parameters on this layer.`);
97
+ }
98
+
99
+ source.matrixSizes = attrs.matrixSizes;
100
+ source.scales = attrs.scales;
101
+ tileLayer.setSource(source);
102
+ tileLayer.getSource().refresh();
103
+ }
104
+
105
+ /**
106
+ * Creates the LayerSource for this WMTSLayer from the WMTS capabilities.
107
+ * @param {Object} attrs attributes of the layer
108
+ * @param {WMTS} tileLayer layer object
109
+ * @returns {void}
110
+ */
111
+ export function createLayerSourceByCapabilities (attrs, tileLayer) {
112
+ const layerIdentifier = attrs.layers,
113
+ url = attrs.capabilitiesUrl,
114
+ matrixSet = attrs.tileMatrixSet,
115
+ capabilitiesOptions = {
116
+ layer: layerIdentifier
117
+ };
118
+
119
+ // use the matrixSet (if defined) for optionsFromCapabilities
120
+ // else look for a tilematrixset in epsg:3857
121
+ if (matrixSet && matrixSet.length > 0) {
122
+ capabilitiesOptions.matrixSet = matrixSet;
123
+ }
124
+ else {
125
+ capabilitiesOptions.projection = "EPSG:3857";
126
+ }
127
+
128
+ getWMTSCapabilities(url)
129
+ .then((result) => {
130
+ const options = optionsFromCapabilities(result, capabilitiesOptions),
131
+ tileMatrixSet = result.Contents.TileMatrixSet.filter(set => set.Identifier === options.matrixSet)[0],
132
+ matrixSizes = [],
133
+ scales = [];
134
+
135
+ // Add the parameters "ScaleDenominator" and "MatrixHeight" / "MatrixWidth" to the source to be able to print WMTS layers
136
+ tileMatrixSet.TileMatrix.forEach(({MatrixHeight, MatrixWidth, ScaleDenominator}) => {
137
+ matrixSizes.push([MatrixWidth, MatrixHeight]);
138
+ scales.push(ScaleDenominator);
139
+ });
140
+
141
+ if (options !== null) {
142
+ const source = new WMTS(options);
143
+
144
+ source.matrixSizes = matrixSizes;
145
+ source.scales = scales;
146
+ tileLayer.set("options", options);
147
+ tileLayer.setSource(source);
148
+ tileLayer.getSource().refresh();
149
+ }
150
+ else {
151
+ const errorMessage = "Cannot get options from WMTS-Capabilities";
152
+
153
+ showErrorMessage(errorMessage, attrs.name || attrs.id);
154
+ throw new Error(errorMessage);
155
+ }
156
+ })
157
+ .catch((error) => {
158
+ if (error === "Fetch error") {
159
+ // error message has already been printed earlier
160
+ return;
161
+ }
162
+ showErrorMessage(error, attrs.name || attrs.id);
163
+ });
164
+ }
165
+
166
+ /**
167
+ * Creates the WMTSLayer.
168
+ * @param {Object} attrs attributes of the layer
169
+ * @returns {void}
170
+ */
171
+ export function createLayer (attrs) {
172
+ const tileLayer = new TileLayer({
173
+ id: attrs.id,
174
+ source: new WMTS({}),
175
+ name: attrs.name,
176
+ minResolution: attrs.minScale,
177
+ maxResolution: attrs.maxScale,
178
+ supported: ["2D", "3D"],
179
+ showSettings: true,
180
+ extent: null,
181
+ typ: attrs.typ,
182
+ legendURL: attrs.legendURL,
183
+ infoFormat: attrs.infoFormat
184
+ });
185
+
186
+ if (attrs.optionsFromCapabilities === undefined) {
187
+ createLayerSourceByDefinitions(attrs, tileLayer);
188
+ }
189
+ else {
190
+ createLayerSourceByCapabilities(attrs, tileLayer);
191
+ }
192
+
193
+ return tileLayer;
194
+ }
@@ -4,6 +4,7 @@ import setBackgroundImage from "../../lib/setBackgroundImage";
4
4
  import getInitialLayers from "../../lib/getInitialLayers";
5
5
  import defaults from "../../defaults";
6
6
  import * as wms from "../../layer/wms";
7
+ import * as wmts from "../../layer/wmts";
7
8
  import * as geojson from "../../layer/geojson";
8
9
  import * as wfs from "../../layer/wfs";
9
10
  import * as vectorBase from "../../layer/vectorBase";
@@ -22,6 +23,7 @@ let mapIdCounter = 0;
22
23
  */
23
24
  const layerBuilderMap = {
24
25
  wms,
26
+ wmts,
25
27
  wfs,
26
28
  geojson,
27
29
  vectorBase,
@@ -4,6 +4,7 @@
4
4
  import olLayerGroup from "ol/layer/Group.js";
5
5
  import {getUid} from "olcs/util.js";
6
6
  import TileWMS from "ol/source/TileWMS.js";
7
+ import ImageWMS from "ol/source/ImageWMS.js";
7
8
  import olcsAbstractSynchronizer from "olcs/AbstractSynchronizer.js";
8
9
  import olcsCore from "olcs/core.js";
9
10
  import {Tile, Image as ImageLayer} from "ol/layer.js";
@@ -40,7 +41,6 @@ class WMSRasterSynchronizer extends olcsAbstractSynchronizer {
40
41
  * @type {!Cesium.ImageryLayerCollection}
41
42
  * @private
42
43
  */
43
- /* eslint-disable no-undef */
44
44
  this.ourLayers = new Cesium.ImageryLayerCollection();
45
45
  }
46
46
 
@@ -87,17 +87,17 @@ class WMSRasterSynchronizer extends olcsAbstractSynchronizer {
87
87
  * May be overriden by child classes to implement custom behavior.
88
88
  * The default implementation handles tiled imageries in EPSG:4326 or
89
89
  * EPSG:3859.
90
- * @param {!ol.layer.Base} olLayer -
91
- * @param {?ol.proj.Projection} viewProj Projection of the view.
92
- * @return {?Array.<!Cesium.ImageryLayer>} array or null if not possible
90
+ * @param {module:ol/layer/Base~BaseLayer } olLayer The raster layer.
91
+ * @param {module:ol/proj} viewProj Projection of the view.
92
+ * @return {?Array.<!Cesium.ImageryLayer>} Array or null if not possible.
93
93
  * (or supported)
94
94
  * @protected
95
95
  */
96
96
  convertLayerToCesiumImageries (olLayer, viewProj) {
97
- let layerOptions = {
98
- "show": false
99
- },
100
- source = {},
97
+ const layerOptions = {
98
+ "show": false
99
+ };
100
+ let source = {},
101
101
  cesiumLayer = {},
102
102
  provider = null;
103
103
 
@@ -108,61 +108,87 @@ class WMSRasterSynchronizer extends olcsAbstractSynchronizer {
108
108
  source = olLayer.getSource();
109
109
 
110
110
  if (source instanceof TileWMS) {
111
- const params = source.getParams(),
112
- options = {
113
- "url": source.getUrls()[0],
114
- "parameters": params,
115
- "layers": params.LAYERS,
116
- "show": false
117
- },
118
- tileGrid = source.getTileGrid();
119
-
120
- if (tileGrid) {
121
- const ext = olLayer.getExtent();
122
-
123
- if (ext && viewProj) {
124
- options.rectangle = olcsCore.extentToRectangle(ext, viewProj);
125
- const minMax = this.getMinMaxLevelFromTileGrid(tileGrid, ext, viewProj);
126
-
127
- options.tileWidth = tileGrid.getTileSize(0)[0];
128
- options.tileHeight = tileGrid.getTileSize(0)[1];
129
- options.minimumLevel = minMax[0];
130
- options.maximumLevel = minMax[1];
131
- }
132
- }
133
- /* eslint-disable no-undef */
134
- provider = new Cesium.WebMapServiceImageryProvider(options);
111
+ provider = this.createProviderForTileWMS(source, viewProj, olLayer);
112
+ }
113
+ else if (source instanceof ImageWMS) {
114
+ return [this.createImageryLayerForImageWMS(olLayer, viewProj)];
135
115
  }
136
116
  else if (source instanceof StaticImageSource) {
137
- const extent = source.getImageExtent(),
138
- options = {
139
- "url": source.getUrl(),
140
- "show": false
141
- },
142
- bottomLeftCorner = proj4("EPSG:25832", "EPSG:4326", getBottomLeft(extent)),
143
- topRightCorner = proj4("EPSG:25832", "EPSG:4326", getTopRight(extent));
144
-
145
- /* eslint-disable no-undef */
146
- options.rectangle = Cesium.Rectangle.fromDegrees(bottomLeftCorner[0], bottomLeftCorner[1], topRightCorner[0], topRightCorner[1]);
147
- /* eslint-disable no-undef */
148
- provider = new Cesium.SingleTileImageryProvider(options);
149
-
117
+ provider = this.createProviderForStaticImageSource(source);
150
118
  }
151
119
  else {
152
120
  console.warn("Sources other than TileImage are currently not supported.");
153
121
  return null;
154
122
  }
155
123
 
156
- // the provider is always non-null if we got this far
157
- layerOptions = {
158
- "show": false
159
- };
160
- /* eslint-disable no-undef */
161
124
  cesiumLayer = new Cesium.ImageryLayer(provider, layerOptions);
162
125
 
163
126
  return cesiumLayer ? [cesiumLayer] : null;
164
127
  }
165
128
 
129
+ /**
130
+ * Creates an Cesium.WebMapServiceImageryProvider for RasterLayer of the type TileWMS.
131
+ * @param {module:ol/source/TileWMS} source The raster layer source.
132
+ * @param {module:ol/proj} viewProj Projection of the view.
133
+ * @param {module:ol/layer/Base~BaseLayer } olLayer The raster layer.
134
+ * @returns {WebMapServiceImageryProvider} The imagery provider.
135
+ */
136
+ createProviderForTileWMS (source, viewProj, olLayer) {
137
+ const params = source.getParams(),
138
+ options = {
139
+ "url": source.getUrls()[0],
140
+ "parameters": params,
141
+ "layers": params.LAYERS,
142
+ "show": false
143
+ },
144
+ tileGrid = source.getTileGrid();
145
+
146
+ if (tileGrid) {
147
+ const ext = olLayer.getExtent();
148
+
149
+ if (ext && viewProj) {
150
+ options.rectangle = olcsCore.extentToRectangle(ext, viewProj);
151
+ const minMax = this.getMinMaxLevelFromTileGrid(tileGrid, ext, viewProj);
152
+
153
+ options.tileWidth = tileGrid.getTileSize(0)[0];
154
+ options.tileHeight = tileGrid.getTileSize(0)[1];
155
+ options.minimumLevel = minMax[0];
156
+ options.maximumLevel = minMax[1];
157
+ }
158
+ }
159
+
160
+ return new Cesium.WebMapServiceImageryProvider(options);
161
+ }
162
+
163
+ /**
164
+ * Creates an Cesium.ImageryLayer for RasterLayer of the type ImageWMS.
165
+ * @param {module:ol/layer/Base~BaseLayer } olLayer The raster layer.
166
+ * @param {module:ol/proj} viewProj Projection of the view.
167
+ * @returns {Cesium.ImageryLayer} The imagery layer.
168
+ */
169
+ createImageryLayerForImageWMS (olLayer, viewProj) {
170
+ return olcsCore.tileLayerToImageryLayer(this.map, olLayer, viewProj);
171
+ }
172
+
173
+ /**
174
+ * Creates an Cesium.SingleTileImageryProvider for RasterLayer of the type StaticImageSource.
175
+ * @param {module:ol/source/ImageStatic} source The raster layer source.
176
+ * @returns {SingleTileImageryProvider} The imagery provider.
177
+ */
178
+ createProviderForStaticImageSource (source) {
179
+ const extent = source.getImageExtent(),
180
+ options = {
181
+ "url": source.getUrl(),
182
+ "show": false
183
+ },
184
+ bottomLeftCorner = proj4(source.getProjection().getCode(), "EPSG:4326", getBottomLeft(extent)),
185
+ topRightCorner = proj4(source.getProjection().getCode(), "EPSG:4326", getTopRight(extent));
186
+
187
+ options.rectangle = Cesium.Rectangle.fromDegrees(bottomLeftCorner[0], bottomLeftCorner[1], topRightCorner[0], topRightCorner[1]);
188
+
189
+ return new Cesium.SingleTileImageryProvider(options);
190
+ }
191
+
166
192
  /**
167
193
  *
168
194
  * @param {ol.Extent} extent -
@@ -179,7 +205,6 @@ class WMSRasterSynchronizer extends olcsAbstractSynchronizer {
179
205
  getTopLeft(wgs84Extent)
180
206
  ];
181
207
 
182
- /* eslint-disable no-undef */
183
208
  return olCoords.map(coord => Cesium.Cartographic.fromDegrees(coord[0], coord[1]));
184
209
  }
185
210
  /**
@@ -201,7 +226,6 @@ class WMSRasterSynchronizer extends olcsAbstractSynchronizer {
201
226
  distanceLocalX = Math.abs(tileCoordsLocal[0][1] - tileCoordsLocal[1][1]),
202
227
  distanceLocalY = Math.abs(tileCoordsLocal[0][2] - tileCoordsLocal[3][2]),
203
228
  extentCoords = this.getExtentPoints(extent, projection),
204
- /* eslint-disable no-undef */
205
229
  tilingScheme = new Cesium.GeographicTilingScheme({});
206
230
  let minLevel = 0,
207
231
  maxLevel = 20;