@geospatial-sdk/openlayers 0.0.5-dev.55 → 0.0.5-dev.57
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/dist/map/apply-context-diff.d.ts.map +1 -1
- package/dist/map/apply-context-diff.js +9 -1
- package/dist/map/create-map.d.ts +1 -1
- package/dist/map/create-map.d.ts.map +1 -1
- package/dist/map/create-map.js +85 -44
- package/dist/map/feature-hover.js +1 -1
- package/dist/map/handle-errors.d.ts +0 -7
- package/dist/map/handle-errors.d.ts.map +1 -1
- package/dist/map/handle-errors.js +10 -14
- package/dist/map/index.d.ts +2 -1
- package/dist/map/index.d.ts.map +1 -1
- package/dist/map/index.js +2 -1
- package/dist/map/layer-update.d.ts.map +1 -1
- package/dist/map/layer-update.js +1 -1
- package/dist/map/listen.d.ts +4 -0
- package/dist/map/listen.d.ts.map +1 -0
- package/dist/map/listen.js +70 -0
- package/dist/map/register-events.d.ts +16 -2
- package/dist/map/register-events.d.ts.map +1 -1
- package/dist/map/register-events.js +172 -81
- package/dist/map/resolved-map-state.d.ts +8 -0
- package/dist/map/resolved-map-state.d.ts.map +1 -0
- package/dist/map/resolved-map-state.js +26 -0
- package/lib/map/apply-context-diff.ts +16 -5
- package/lib/map/create-map.test.ts +178 -40
- package/lib/map/create-map.ts +114 -55
- package/lib/map/feature-hover.ts +1 -1
- package/lib/map/handle-errors.test.ts +13 -36
- package/lib/map/handle-errors.ts +10 -28
- package/lib/map/index.ts +2 -1
- package/lib/map/layer-update.ts +3 -2
- package/lib/map/listen.test.ts +977 -0
- package/lib/map/listen.ts +123 -0
- package/lib/map/register-events.ts +229 -109
- package/lib/map/resolved-map-state.ts +38 -0
- package/package.json +3 -3
- package/lib/map/register-events.test.ts +0 -259
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply-context-diff.d.ts","sourceRoot":"","sources":["../../lib/map/apply-context-diff.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,WAAW,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"apply-context-diff.d.ts","sourceRoot":"","sources":["../../lib/map/apply-context-diff.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,WAAW,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAStD;;;;GAIG;AACH,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,cAAc,GAC1B,OAAO,CAAC,GAAG,CAAC,CAuGd"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createLayer, createView, updateLayerInMap } from "./create-map.js";
|
|
2
2
|
import { fromLonLat, transformExtent } from "ol/proj.js";
|
|
3
3
|
import GeoJSON from "ol/format/GeoJSON.js";
|
|
4
|
+
import { propagateLayerStateChangeEventToMap } from "./register-events.js";
|
|
4
5
|
const GEOJSON = new GeoJSON();
|
|
5
6
|
/**
|
|
6
7
|
* Apply a context diff to an OpenLayers map
|
|
@@ -20,6 +21,9 @@ export async function applyContextDiffToMap(map, contextDiff) {
|
|
|
20
21
|
// insert added layers
|
|
21
22
|
const newLayers = await Promise.all(contextDiff.layersAdded.map((layerAdded) => createLayer(layerAdded.layer)));
|
|
22
23
|
newLayers.forEach((layer, index) => {
|
|
24
|
+
if (!layer) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
23
27
|
const position = contextDiff.layersAdded[index].position;
|
|
24
28
|
if (position >= layers.getLength()) {
|
|
25
29
|
layers.push(layer);
|
|
@@ -27,6 +31,7 @@ export async function applyContextDiffToMap(map, contextDiff) {
|
|
|
27
31
|
else {
|
|
28
32
|
layers.insertAt(position, layer);
|
|
29
33
|
}
|
|
34
|
+
propagateLayerStateChangeEventToMap(map, layer);
|
|
30
35
|
});
|
|
31
36
|
// move reordered layers (sorted by ascending new position)
|
|
32
37
|
if (contextDiff.layersReordered.length > 0) {
|
|
@@ -39,8 +44,9 @@ export async function applyContextDiffToMap(map, contextDiff) {
|
|
|
39
44
|
map.setLayers([...layersArray]);
|
|
40
45
|
}
|
|
41
46
|
// update or recreate changed layers
|
|
47
|
+
const updatePromises = [];
|
|
42
48
|
for (const layerChanged of contextDiff.layersChanged) {
|
|
43
|
-
updateLayerInMap(map, layerChanged.layer, layerChanged.position, layerChanged.previousLayer);
|
|
49
|
+
updatePromises.push(updateLayerInMap(map, layerChanged.layer, layerChanged.position, layerChanged.previousLayer));
|
|
44
50
|
}
|
|
45
51
|
if (typeof contextDiff.viewChanges !== "undefined") {
|
|
46
52
|
const { viewChanges } = contextDiff;
|
|
@@ -82,5 +88,7 @@ export async function applyContextDiffToMap(map, contextDiff) {
|
|
|
82
88
|
// }
|
|
83
89
|
}
|
|
84
90
|
}
|
|
91
|
+
// wait for all layers to have been updated
|
|
92
|
+
await Promise.all(updatePromises);
|
|
85
93
|
return map;
|
|
86
94
|
}
|
package/dist/map/create-map.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import Map from "ol/Map.js";
|
|
|
3
3
|
import View from "ol/View.js";
|
|
4
4
|
import Layer from "ol/layer/Layer.js";
|
|
5
5
|
export declare function createLayer(layerModel: MapContextLayer): Promise<Layer>;
|
|
6
|
-
export declare function updateLayerInMap(map: Map, layerModel: MapContextLayer, layerPosition: number, previousLayerModel: MapContextLayer): void
|
|
6
|
+
export declare function updateLayerInMap(map: Map, layerModel: MapContextLayer, layerPosition: number, previousLayerModel: MapContextLayer): Promise<void>;
|
|
7
7
|
export declare function createView(viewModel: MapContextView | null, map: Map): View;
|
|
8
8
|
/**
|
|
9
9
|
* Create an OpenLayers map from a context; optionally specify a target (root element) for the map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-map.d.ts","sourceRoot":"","sources":["../../lib/map/create-map.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EACV,eAAe,EACf,cAAc,EAEf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,GAAG,MAAM,WAAW,CAAC;AAC5B,OAAO,IAAI,MAAM,YAAY,CAAC;AAC9B,OAAO,KAAK,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"create-map.d.ts","sourceRoot":"","sources":["../../lib/map/create-map.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EACV,eAAe,EACf,cAAc,EAEf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,GAAG,MAAM,WAAW,CAAC;AAC5B,OAAO,IAAI,MAAM,YAAY,CAAC;AAC9B,OAAO,KAAK,MAAM,mBAAmB,CAAC;AA0DtC,wBAAsB,WAAW,CAAC,UAAU,EAAE,eAAe,GAAG,OAAO,CAAC,KAAK,CAAC,CAgR7E;AAED,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,eAAe,EAC3B,aAAa,EAAE,MAAM,EACrB,kBAAkB,EAAE,eAAe,GAClC,OAAO,CAAC,IAAI,CAAC,CAgBf;AAED,wBAAgB,UAAU,CAAC,SAAS,EAAE,cAAc,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,CAkC3E;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,UAAU,EACnB,MAAM,CAAC,EAAE,MAAM,GAAG,WAAW,GAC5B,OAAO,CAAC,GAAG,CAAC,CAKd;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,GAAG,CAAC,CAUd"}
|
package/dist/map/create-map.js
CHANGED
|
@@ -14,9 +14,9 @@ import OGCMapTile from "ol/source/OGCMapTile.js";
|
|
|
14
14
|
import OGCVectorTile from "ol/source/OGCVectorTile.js";
|
|
15
15
|
import WMTS from "ol/source/WMTS.js";
|
|
16
16
|
import MVT from "ol/format/MVT.js";
|
|
17
|
-
import { OgcApiEndpoint, WfsEndpoint, WmtsEndpoint, } from "@camptocamp/ogc-client";
|
|
17
|
+
import { EndpointError, OgcApiEndpoint, WfsEndpoint, WmtsEndpoint, } from "@camptocamp/ogc-client";
|
|
18
18
|
import { MapboxVectorLayer } from "ol-mapbox-style";
|
|
19
|
-
import {
|
|
19
|
+
import { tileLoadErrorCatchFunction } from "./handle-errors.js";
|
|
20
20
|
import VectorTile from "ol/source/VectorTile.js";
|
|
21
21
|
import GeoTIFF from "ol/source/GeoTIFF.js";
|
|
22
22
|
import WebGLTileLayer from "ol/layer/WebGLTile.js";
|
|
@@ -24,11 +24,19 @@ import proj4 from "proj4";
|
|
|
24
24
|
import { register } from "ol/proj/proj4.js";
|
|
25
25
|
import { canDoIncrementalUpdate, updateLayerProperties, } from "./layer-update.js";
|
|
26
26
|
import { initHoverLayer } from "./feature-hover.js";
|
|
27
|
+
import { emitLayerCreationError, emitLayerLoadingError, emitLayerLoadingStatusSuccess, propagateLayerStateChangeEventToMap, } from "./register-events.js";
|
|
28
|
+
import { GEOSPATIAL_SDK_PREFIX } from "./constants.js";
|
|
29
|
+
import ImageLayer from "ol/layer/Image.js";
|
|
30
|
+
import ImageWMS from "ol/source/ImageWMS.js";
|
|
27
31
|
// Register proj4 with OpenLayers so that arbitrary EPSG codes
|
|
28
32
|
// (e.g., UTM zones from GeoTIFF metadata) can be reprojected to the map projection
|
|
29
33
|
register(proj4);
|
|
30
34
|
const GEOJSON = new GeoJSON();
|
|
31
35
|
const WFS_MAX_FEATURES = 10000;
|
|
36
|
+
// We need to defer some events being dispatched to make sure they are caught by the map
|
|
37
|
+
// where the layers sit
|
|
38
|
+
// FIXME: this should be better handled in a separate module!
|
|
39
|
+
const defer = () => new Promise((resolve) => setTimeout(resolve, 0));
|
|
32
40
|
export async function createLayer(layerModel) {
|
|
33
41
|
const { type } = layerModel;
|
|
34
42
|
let layer;
|
|
@@ -55,24 +63,39 @@ export async function createLayer(layerModel) {
|
|
|
55
63
|
});
|
|
56
64
|
layer.setSource(source);
|
|
57
65
|
}
|
|
66
|
+
defer().then(() => emitLayerLoadingStatusSuccess(layer));
|
|
58
67
|
}
|
|
59
68
|
break;
|
|
60
69
|
case "wms":
|
|
61
70
|
{
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
71
|
+
const url = removeSearchParams(layerModel.url, ["request", "service"]);
|
|
72
|
+
const params = {
|
|
73
|
+
LAYERS: layerModel.name,
|
|
74
|
+
...(layerModel.style && { STYLES: layerModel.style }),
|
|
75
|
+
};
|
|
76
|
+
if (layerModel.useTiles === false) {
|
|
77
|
+
layer = new ImageLayer({
|
|
78
|
+
source: new ImageWMS({
|
|
79
|
+
url,
|
|
80
|
+
params,
|
|
81
|
+
attributions: layerModel.attributions,
|
|
82
|
+
}),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
layer = new TileLayer({
|
|
87
|
+
source: new TileWMS({
|
|
88
|
+
url,
|
|
89
|
+
params: { ...params, TILED: true },
|
|
90
|
+
gutter: 20,
|
|
91
|
+
attributions: layerModel.attributions,
|
|
92
|
+
tileLoadFunction: function (tile, src) {
|
|
93
|
+
return tileLoadErrorCatchFunction(layer, tile, src);
|
|
94
|
+
},
|
|
95
|
+
}),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
defer().then(() => emitLayerLoadingStatusSuccess(layer));
|
|
76
99
|
}
|
|
77
100
|
break;
|
|
78
101
|
case "wmts": {
|
|
@@ -104,10 +127,13 @@ export async function createLayer(layerModel) {
|
|
|
104
127
|
attributions: layerModel.attributions,
|
|
105
128
|
}));
|
|
106
129
|
})
|
|
130
|
+
.then(() => emitLayerLoadingStatusSuccess(olLayer))
|
|
107
131
|
.catch((e) => {
|
|
108
|
-
|
|
132
|
+
const httpStatus = e instanceof EndpointError ? e.httpStatus : undefined;
|
|
133
|
+
emitLayerLoadingError(olLayer, e, httpStatus);
|
|
109
134
|
});
|
|
110
|
-
|
|
135
|
+
layer = olLayer;
|
|
136
|
+
break;
|
|
111
137
|
}
|
|
112
138
|
case "wfs": {
|
|
113
139
|
const olLayer = new VectorLayer({
|
|
@@ -132,8 +158,10 @@ export async function createLayer(layerModel) {
|
|
|
132
158
|
attributions: layerModel.attributions,
|
|
133
159
|
}));
|
|
134
160
|
})
|
|
161
|
+
.then(() => emitLayerLoadingStatusSuccess(olLayer))
|
|
135
162
|
.catch((e) => {
|
|
136
|
-
|
|
163
|
+
const httpStatus = e instanceof EndpointError ? e.httpStatus : undefined;
|
|
164
|
+
emitLayerLoadingError(olLayer, e, httpStatus);
|
|
137
165
|
});
|
|
138
166
|
layer = olLayer;
|
|
139
167
|
break;
|
|
@@ -143,17 +171,19 @@ export async function createLayer(layerModel) {
|
|
|
143
171
|
styleUrl: layerModel.styleUrl,
|
|
144
172
|
accessToken: layerModel.accessToken,
|
|
145
173
|
});
|
|
174
|
+
defer().then(() => emitLayerLoadingStatusSuccess(layer));
|
|
146
175
|
break;
|
|
147
176
|
}
|
|
148
177
|
case "geojson": {
|
|
178
|
+
layer = new VectorLayer({
|
|
179
|
+
style: layerModel.style ?? defaultStyle,
|
|
180
|
+
});
|
|
181
|
+
let source;
|
|
149
182
|
if (layerModel.url !== undefined) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
attributions: layerModel.attributions,
|
|
155
|
-
}),
|
|
156
|
-
style: layerModel.style ?? defaultStyle,
|
|
183
|
+
source = new VectorSource({
|
|
184
|
+
format: new GeoJSON(),
|
|
185
|
+
url: layerModel.url,
|
|
186
|
+
attributions: layerModel.attributions,
|
|
157
187
|
});
|
|
158
188
|
}
|
|
159
189
|
else {
|
|
@@ -171,14 +201,14 @@ export async function createLayer(layerModel) {
|
|
|
171
201
|
featureProjection: "EPSG:3857",
|
|
172
202
|
dataProjection: "EPSG:4326",
|
|
173
203
|
});
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
attributions: layerModel.attributions,
|
|
178
|
-
}),
|
|
179
|
-
style: layerModel.style ?? defaultStyle,
|
|
204
|
+
source = new VectorSource({
|
|
205
|
+
features,
|
|
206
|
+
attributions: layerModel.attributions,
|
|
180
207
|
});
|
|
181
208
|
}
|
|
209
|
+
layer.setSource(source);
|
|
210
|
+
// FIXME: actually track layer loading and data info
|
|
211
|
+
defer().then(() => emitLayerLoadingStatusSuccess(layer));
|
|
182
212
|
break;
|
|
183
213
|
}
|
|
184
214
|
case "ogcapi": {
|
|
@@ -207,15 +237,18 @@ export async function createLayer(layerModel) {
|
|
|
207
237
|
}
|
|
208
238
|
else {
|
|
209
239
|
layerUrl = await ogcEndpoint.getCollectionItemsUrl(layerModel.collection, layerModel.options);
|
|
240
|
+
const source = new VectorSource({
|
|
241
|
+
format: new GeoJSON(),
|
|
242
|
+
url: layerUrl,
|
|
243
|
+
attributions: layerModel.attributions,
|
|
244
|
+
});
|
|
210
245
|
layer = new VectorLayer({
|
|
211
|
-
source
|
|
212
|
-
format: new GeoJSON(),
|
|
213
|
-
url: layerUrl,
|
|
214
|
-
attributions: layerModel.attributions,
|
|
215
|
-
}),
|
|
246
|
+
source,
|
|
216
247
|
style: layerModel.style ?? defaultStyle,
|
|
217
248
|
});
|
|
218
249
|
}
|
|
250
|
+
// FIXME: actually track layer loading
|
|
251
|
+
defer().then(() => emitLayerLoadingStatusSuccess(layer));
|
|
219
252
|
break;
|
|
220
253
|
}
|
|
221
254
|
case "geotiff": {
|
|
@@ -226,18 +259,24 @@ export async function createLayer(layerModel) {
|
|
|
226
259
|
layer = new WebGLTileLayer({
|
|
227
260
|
source: geoTiffSource,
|
|
228
261
|
});
|
|
262
|
+
// FIXME: actually track tile loading
|
|
263
|
+
defer().then(() => emitLayerLoadingStatusSuccess(layer));
|
|
229
264
|
break;
|
|
230
265
|
}
|
|
231
|
-
default:
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
266
|
+
default: {
|
|
267
|
+
// we create an empty placeholder layer so that we still have a corresponding layer in OL
|
|
268
|
+
layer = new VectorLayer({
|
|
269
|
+
properties: {
|
|
270
|
+
[`${GEOSPATIAL_SDK_PREFIX}layer-with-error`]: true,
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
defer().then(() => emitLayerCreationError(layer, new Error(`Unrecognized layer type: ${JSON.stringify(layerModel)}`)));
|
|
274
|
+
}
|
|
236
275
|
}
|
|
237
276
|
updateLayerProperties(layerModel, layer);
|
|
238
277
|
return layer;
|
|
239
278
|
}
|
|
240
|
-
export function updateLayerInMap(map, layerModel, layerPosition, previousLayerModel) {
|
|
279
|
+
export async function updateLayerInMap(map, layerModel, layerPosition, previousLayerModel) {
|
|
241
280
|
const layers = map.getLayers();
|
|
242
281
|
const updatedLayer = layers.item(layerPosition);
|
|
243
282
|
// if an incremental update is possible, do it to avoid costly layer recreation
|
|
@@ -247,8 +286,9 @@ export function updateLayerInMap(map, layerModel, layerPosition, previousLayerMo
|
|
|
247
286
|
}
|
|
248
287
|
// dispose and recreate layer
|
|
249
288
|
updatedLayer.dispose();
|
|
250
|
-
createLayer(layerModel).then((layer) => {
|
|
289
|
+
await createLayer(layerModel).then((layer) => {
|
|
251
290
|
layers.setAt(layerPosition, layer);
|
|
291
|
+
propagateLayerStateChangeEventToMap(map, layer);
|
|
252
292
|
});
|
|
253
293
|
}
|
|
254
294
|
export function createView(viewModel, map) {
|
|
@@ -307,6 +347,7 @@ export async function resetMapFromContext(map, context) {
|
|
|
307
347
|
for (const layerModel of context.layers) {
|
|
308
348
|
const layer = await createLayer(layerModel);
|
|
309
349
|
map.addLayer(layer);
|
|
350
|
+
propagateLayerStateChangeEventToMap(map, layer);
|
|
310
351
|
}
|
|
311
352
|
initHoverLayer(map);
|
|
312
353
|
return map;
|
|
@@ -72,7 +72,7 @@ export function initHoverLayer(map) {
|
|
|
72
72
|
const featuresByLayer = await readFeaturesAtPixel(map, event, layerFilter);
|
|
73
73
|
const features = Array.from(featuresByLayer.values()).flat();
|
|
74
74
|
map.dispatchEvent({
|
|
75
|
-
type: FeaturesHoverEventType
|
|
75
|
+
type: `${GEOSPATIAL_SDK_PREFIX}${FeaturesHoverEventType}`,
|
|
76
76
|
features,
|
|
77
77
|
featuresByLayer,
|
|
78
78
|
});
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import { EndpointError } from "@camptocamp/ogc-client";
|
|
2
1
|
import { Tile } from "ol";
|
|
3
2
|
import { Layer } from "ol/layer.js";
|
|
4
|
-
import TileLayer from "ol/layer/Tile.js";
|
|
5
|
-
import VectorLayer from "ol/layer/Vector.js";
|
|
6
|
-
import TileSource from "ol/source/Tile.js";
|
|
7
|
-
import VectorSource from "ol/source/Vector.js";
|
|
8
|
-
export declare function handleEndpointError(layer: TileLayer<TileSource> | VectorLayer<VectorSource>, error: EndpointError): void;
|
|
9
|
-
export declare function handleTileError(response: Response | Error, tile: Tile, layer: Layer): void;
|
|
10
3
|
export declare function tileLoadErrorCatchFunction(layer: Layer, tile: Tile, src: string): void;
|
|
11
4
|
//# sourceMappingURL=handle-errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle-errors.d.ts","sourceRoot":"","sources":["../../lib/map/handle-errors.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"handle-errors.d.ts","sourceRoot":"","sources":["../../lib/map/handle-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,IAAI,EAAE,MAAM,IAAI,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAIpC,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,MAAM,QA0BZ"}
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
import { SourceLoadErrorEvent } from "@geospatial-sdk/core";
|
|
2
1
|
import TileState from "ol/TileState.js";
|
|
3
|
-
|
|
4
|
-
console.error("Error loading Endpoint", error);
|
|
5
|
-
layer.dispatchEvent(new SourceLoadErrorEvent(error));
|
|
6
|
-
}
|
|
7
|
-
export function handleTileError(response, tile, layer) {
|
|
8
|
-
console.error("Error loading tile", response);
|
|
9
|
-
tile.setState(TileState.ERROR);
|
|
10
|
-
layer.dispatchEvent(new SourceLoadErrorEvent(response));
|
|
11
|
-
}
|
|
2
|
+
import { emitLayerLoadingError } from "./register-events.js";
|
|
12
3
|
export function tileLoadErrorCatchFunction(layer, tile, src) {
|
|
13
4
|
fetch(src)
|
|
14
5
|
.then((response) => {
|
|
@@ -19,15 +10,20 @@ export function tileLoadErrorCatchFunction(layer, tile, src) {
|
|
|
19
10
|
const image = tile.getImage();
|
|
20
11
|
image.src = URL.createObjectURL(blob);
|
|
21
12
|
})
|
|
22
|
-
.catch(() => {
|
|
23
|
-
|
|
13
|
+
.catch((error) => {
|
|
14
|
+
tile.setState(TileState.ERROR);
|
|
15
|
+
emitLayerLoadingError(layer, error);
|
|
24
16
|
});
|
|
25
17
|
}
|
|
26
18
|
else {
|
|
27
|
-
|
|
19
|
+
tile.setState(TileState.ERROR);
|
|
20
|
+
response.text().then((text) => {
|
|
21
|
+
emitLayerLoadingError(layer, new Error(text), response.status);
|
|
22
|
+
});
|
|
28
23
|
}
|
|
29
24
|
})
|
|
30
25
|
.catch((error) => {
|
|
31
|
-
|
|
26
|
+
tile.setState(TileState.ERROR);
|
|
27
|
+
emitLayerLoadingError(layer, error);
|
|
32
28
|
});
|
|
33
29
|
}
|
package/dist/map/index.d.ts
CHANGED
|
@@ -4,5 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { createMapFromContext, resetMapFromContext } from "./create-map.js";
|
|
6
6
|
export { applyContextDiffToMap } from "./apply-context-diff.js";
|
|
7
|
-
export { listen } from "./
|
|
7
|
+
export { listen } from "./listen.js";
|
|
8
|
+
export { readMapViewState } from "./resolved-map-state.js";
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/map/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/map/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/map/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/map/index.js
CHANGED
|
@@ -4,4 +4,5 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { createMapFromContext, resetMapFromContext } from "./create-map.js";
|
|
6
6
|
export { applyContextDiffToMap } from "./apply-context-diff.js";
|
|
7
|
-
export { listen } from "./
|
|
7
|
+
export { listen } from "./listen.js";
|
|
8
|
+
export { readMapViewState } from "./resolved-map-state.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layer-update.d.ts","sourceRoot":"","sources":["../../lib/map/layer-update.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"layer-update.d.ts","sourceRoot":"","sources":["../../lib/map/layer-update.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,eAAe,EAEhB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,MAAM,mBAAmB,CAAC;AAsBtC;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,eAAe,EACzB,QAAQ,EAAE,eAAe,GACxB,OAAO,CAIT;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,eAAe,EAC3B,OAAO,EAAE,KAAK,EACd,kBAAkB,CAAC,EAAE,eAAe,QAiDrC"}
|
package/dist/map/layer-update.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listen.d.ts","sourceRoot":"","sources":["../../lib/map/listen.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,WAAW,CAAC;AAG5B,OAAO,EAOL,eAAe,EAShB,MAAM,sBAAsB,CAAC;AAgC9B,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,eAAe,EACpD,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,CAAC,EACZ,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,IAAI,QAoE9C"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { toLonLat } from "ol/proj.js";
|
|
2
|
+
import { FeaturesClickEventType, FeaturesHoverEventType, LayerCreationErrorEventType, LayerLoadingErrorEventType, MapClickEventType, MapExtentChangeEventType, MapLayerStateChangeEventType, MapStateChangeEventType, MapViewStateChangeEventType, SourceLoadErrorType, } from "@geospatial-sdk/core";
|
|
3
|
+
import { GEOSPATIAL_SDK_PREFIX } from "./constants.js";
|
|
4
|
+
import { registerFeatureClickEvent, registerFeatureHoverEvent, registerLayerCreationErrorEvent, registerLayerLoadingErrorEvent, registerMapLayerStateChangeEvent, registerMapStateChangeEvent, registerMapViewStateChangeEvent, registerSourceLoadErrorEvent, } from "./register-events.js";
|
|
5
|
+
function addEventListener(map, eventType, callback) {
|
|
6
|
+
map.on(`${GEOSPATIAL_SDK_PREFIX}${eventType}`, ({ target: _target, ...event }) =>
|
|
7
|
+
// we're excluding the `target` property and renaming the `type` here
|
|
8
|
+
callback({
|
|
9
|
+
...event,
|
|
10
|
+
type: eventType,
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
13
|
+
export function listen(map, eventType, callback) {
|
|
14
|
+
switch (eventType) {
|
|
15
|
+
case FeaturesClickEventType:
|
|
16
|
+
registerFeatureClickEvent(map);
|
|
17
|
+
addEventListener(map, eventType, callback);
|
|
18
|
+
break;
|
|
19
|
+
case FeaturesHoverEventType:
|
|
20
|
+
registerFeatureHoverEvent(map);
|
|
21
|
+
addEventListener(map, eventType, callback);
|
|
22
|
+
break;
|
|
23
|
+
case MapClickEventType:
|
|
24
|
+
map.on("click", (event) => {
|
|
25
|
+
const coordinate = toLonLat(event.coordinate, map.getView().getProjection());
|
|
26
|
+
callback({
|
|
27
|
+
type: MapClickEventType,
|
|
28
|
+
coordinate,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
break;
|
|
32
|
+
case MapViewStateChangeEventType:
|
|
33
|
+
registerMapViewStateChangeEvent(map);
|
|
34
|
+
addEventListener(map, eventType, callback);
|
|
35
|
+
break;
|
|
36
|
+
case MapLayerStateChangeEventType:
|
|
37
|
+
registerMapLayerStateChangeEvent(map);
|
|
38
|
+
addEventListener(map, eventType, callback);
|
|
39
|
+
break;
|
|
40
|
+
case MapStateChangeEventType:
|
|
41
|
+
registerMapStateChangeEvent(map);
|
|
42
|
+
addEventListener(map, eventType, callback);
|
|
43
|
+
break;
|
|
44
|
+
case LayerCreationErrorEventType:
|
|
45
|
+
registerLayerCreationErrorEvent(map);
|
|
46
|
+
addEventListener(map, eventType, callback);
|
|
47
|
+
break;
|
|
48
|
+
case LayerLoadingErrorEventType:
|
|
49
|
+
registerLayerLoadingErrorEvent(map);
|
|
50
|
+
addEventListener(map, eventType, callback);
|
|
51
|
+
break;
|
|
52
|
+
/**
|
|
53
|
+
* DEPRECATED
|
|
54
|
+
*/
|
|
55
|
+
case MapExtentChangeEventType:
|
|
56
|
+
registerMapViewStateChangeEvent(map);
|
|
57
|
+
map.on(`${GEOSPATIAL_SDK_PREFIX}${MapViewStateChangeEventType}`, (event) => callback({
|
|
58
|
+
type: MapExtentChangeEventType,
|
|
59
|
+
extent: event.viewState.extent,
|
|
60
|
+
}));
|
|
61
|
+
break;
|
|
62
|
+
case SourceLoadErrorType: {
|
|
63
|
+
registerSourceLoadErrorEvent(map);
|
|
64
|
+
map.on(SourceLoadErrorType, (event) => callback(event));
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
default:
|
|
68
|
+
throw new Error(`Unrecognized event type: ${eventType}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
import { MapEventsByType } from "@geospatial-sdk/core";
|
|
2
1
|
import Map from "ol/Map.js";
|
|
3
|
-
|
|
2
|
+
import { MapLayerDataInfo } from "@geospatial-sdk/core";
|
|
3
|
+
import type BaseLayer from "ol/layer/Base.js";
|
|
4
|
+
export declare function registerFeatureClickEvent(map: Map): void;
|
|
5
|
+
export declare function registerFeatureHoverEvent(map: Map): void;
|
|
6
|
+
export declare function registerMapLayerStateChangeEvent(map: Map): void;
|
|
7
|
+
export declare function emitLayerCreationError(layer: BaseLayer, error: Error): void;
|
|
8
|
+
export declare function emitLayerLoadingStatusLoading(layer: BaseLayer): void;
|
|
9
|
+
export declare function emitLayerLoadingStatusSuccess(layer: BaseLayer): void;
|
|
10
|
+
export declare function emitLayerLoadingError(layer: BaseLayer, error: Error, httpStatus?: number): void;
|
|
11
|
+
export declare function emitLayerDataInfo(layer: BaseLayer, dataInfo: MapLayerDataInfo): void;
|
|
12
|
+
export declare function propagateLayerStateChangeEventToMap(map: Map, layer: BaseLayer): void;
|
|
13
|
+
export declare function registerMapStateChangeEvent(map: Map): void;
|
|
14
|
+
export declare function registerLayerCreationErrorEvent(map: Map): void;
|
|
15
|
+
export declare function registerLayerLoadingErrorEvent(map: Map): void;
|
|
16
|
+
export declare function registerMapViewStateChangeEvent(map: Map): void;
|
|
17
|
+
export declare function registerSourceLoadErrorEvent(map: Map): void;
|
|
4
18
|
//# sourceMappingURL=register-events.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-events.d.ts","sourceRoot":"","sources":["../../lib/map/register-events.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"register-events.d.ts","sourceRoot":"","sources":["../../lib/map/register-events.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,WAAW,CAAC;AAC5B,OAAO,EAKL,gBAAgB,EAWjB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAC;AAO9C,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,GAAG,QAkBjD;AAED,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,GAAG,QAGjD;AAED,wBAAgB,gCAAgC,CAAC,GAAG,EAAE,GAAG,QAGxD;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,QAKpE;AACD,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,SAAS,QAK7D;AACD,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,SAAS,QAK7D;AACD,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,KAAK,EACZ,UAAU,CAAC,EAAE,MAAM,QAOpB;AACD,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,SAAS,EAChB,QAAQ,EAAE,gBAAgB,QAM3B;AAED,wBAAgB,mCAAmC,CACjD,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,SAAS,QAsFjB;AAED,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,GAAG,QA6CnD;AAED,wBAAgB,+BAA+B,CAAC,GAAG,EAAE,GAAG,QAGvD;AAED,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,GAAG,QAGtD;AAID,wBAAgB,+BAA+B,CAAC,GAAG,EAAE,GAAG,QAwBvD;AAED,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,GAAG,QAGpD"}
|