@geospatial-sdk/openlayers 0.0.5-dev.54 → 0.0.5-dev.56
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 +73 -30
- 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.map +1 -1
- package/dist/map/listen.js +13 -26
- 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/lib/map/apply-context-diff.ts +16 -5
- package/lib/map/create-map.test.ts +172 -60
- package/lib/map/create-map.ts +100 -37
- 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/dist/map/feature-selection.d.ts +0 -8
- package/dist/map/feature-selection.d.ts.map +0 -1
- package/dist/map/feature-selection.js +0 -76
- package/dist/map/styles.d.ts +0 -16
- package/dist/map/styles.d.ts.map +0 -1
- package/dist/map/styles.js +0 -77
- package/dist/resolved-state/resolved-map-state.d.ts +0 -2
- package/dist/resolved-state/resolved-map-state.d.ts.map +0 -1
- package/dist/resolved-state/resolved-map-state.js +0 -1
- 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;AAwDtC,wBAAsB,WAAW,CAAC,UAAU,EAAE,eAAe,GAAG,OAAO,CAAC,KAAK,CAAC,CAoQ7E;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,14 +14,27 @@ 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
|
+
import GeoTIFF from "ol/source/GeoTIFF.js";
|
|
22
|
+
import WebGLTileLayer from "ol/layer/WebGLTile.js";
|
|
23
|
+
import proj4 from "proj4";
|
|
24
|
+
import { register } from "ol/proj/proj4.js";
|
|
21
25
|
import { canDoIncrementalUpdate, updateLayerProperties, } from "./layer-update.js";
|
|
22
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
|
+
// Register proj4 with OpenLayers so that arbitrary EPSG codes
|
|
30
|
+
// (e.g., UTM zones from GeoTIFF metadata) can be reprojected to the map projection
|
|
31
|
+
register(proj4);
|
|
23
32
|
const GEOJSON = new GeoJSON();
|
|
24
33
|
const WFS_MAX_FEATURES = 10000;
|
|
34
|
+
// We need to defer some events being dispatched to make sure they are caught by the map
|
|
35
|
+
// where the layers sit
|
|
36
|
+
// FIXME: this should be better handled in a separate module!
|
|
37
|
+
const defer = () => new Promise((resolve) => setTimeout(resolve, 0));
|
|
25
38
|
export async function createLayer(layerModel) {
|
|
26
39
|
const { type } = layerModel;
|
|
27
40
|
let layer;
|
|
@@ -48,6 +61,7 @@ export async function createLayer(layerModel) {
|
|
|
48
61
|
});
|
|
49
62
|
layer.setSource(source);
|
|
50
63
|
}
|
|
64
|
+
defer().then(() => emitLayerLoadingStatusSuccess(layer));
|
|
51
65
|
}
|
|
52
66
|
break;
|
|
53
67
|
case "wms":
|
|
@@ -66,6 +80,7 @@ export async function createLayer(layerModel) {
|
|
|
66
80
|
return tileLoadErrorCatchFunction(layer, tile, src);
|
|
67
81
|
});
|
|
68
82
|
layer.setSource(source);
|
|
83
|
+
defer().then(() => emitLayerLoadingStatusSuccess(layer));
|
|
69
84
|
}
|
|
70
85
|
break;
|
|
71
86
|
case "wmts": {
|
|
@@ -97,10 +112,13 @@ export async function createLayer(layerModel) {
|
|
|
97
112
|
attributions: layerModel.attributions,
|
|
98
113
|
}));
|
|
99
114
|
})
|
|
115
|
+
.then(() => emitLayerLoadingStatusSuccess(olLayer))
|
|
100
116
|
.catch((e) => {
|
|
101
|
-
|
|
117
|
+
const httpStatus = e instanceof EndpointError ? e.httpStatus : undefined;
|
|
118
|
+
emitLayerLoadingError(olLayer, e, httpStatus);
|
|
102
119
|
});
|
|
103
|
-
|
|
120
|
+
layer = olLayer;
|
|
121
|
+
break;
|
|
104
122
|
}
|
|
105
123
|
case "wfs": {
|
|
106
124
|
const olLayer = new VectorLayer({
|
|
@@ -125,8 +143,10 @@ export async function createLayer(layerModel) {
|
|
|
125
143
|
attributions: layerModel.attributions,
|
|
126
144
|
}));
|
|
127
145
|
})
|
|
146
|
+
.then(() => emitLayerLoadingStatusSuccess(olLayer))
|
|
128
147
|
.catch((e) => {
|
|
129
|
-
|
|
148
|
+
const httpStatus = e instanceof EndpointError ? e.httpStatus : undefined;
|
|
149
|
+
emitLayerLoadingError(olLayer, e, httpStatus);
|
|
130
150
|
});
|
|
131
151
|
layer = olLayer;
|
|
132
152
|
break;
|
|
@@ -136,17 +156,19 @@ export async function createLayer(layerModel) {
|
|
|
136
156
|
styleUrl: layerModel.styleUrl,
|
|
137
157
|
accessToken: layerModel.accessToken,
|
|
138
158
|
});
|
|
159
|
+
defer().then(() => emitLayerLoadingStatusSuccess(layer));
|
|
139
160
|
break;
|
|
140
161
|
}
|
|
141
162
|
case "geojson": {
|
|
163
|
+
layer = new VectorLayer({
|
|
164
|
+
style: layerModel.style ?? defaultStyle,
|
|
165
|
+
});
|
|
166
|
+
let source;
|
|
142
167
|
if (layerModel.url !== undefined) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
attributions: layerModel.attributions,
|
|
148
|
-
}),
|
|
149
|
-
style: layerModel.style ?? defaultStyle,
|
|
168
|
+
source = new VectorSource({
|
|
169
|
+
format: new GeoJSON(),
|
|
170
|
+
url: layerModel.url,
|
|
171
|
+
attributions: layerModel.attributions,
|
|
150
172
|
});
|
|
151
173
|
}
|
|
152
174
|
else {
|
|
@@ -164,14 +186,14 @@ export async function createLayer(layerModel) {
|
|
|
164
186
|
featureProjection: "EPSG:3857",
|
|
165
187
|
dataProjection: "EPSG:4326",
|
|
166
188
|
});
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
attributions: layerModel.attributions,
|
|
171
|
-
}),
|
|
172
|
-
style: layerModel.style ?? defaultStyle,
|
|
189
|
+
source = new VectorSource({
|
|
190
|
+
features,
|
|
191
|
+
attributions: layerModel.attributions,
|
|
173
192
|
});
|
|
174
193
|
}
|
|
194
|
+
layer.setSource(source);
|
|
195
|
+
// FIXME: actually track layer loading and data info
|
|
196
|
+
defer().then(() => emitLayerLoadingStatusSuccess(layer));
|
|
175
197
|
break;
|
|
176
198
|
}
|
|
177
199
|
case "ogcapi": {
|
|
@@ -200,27 +222,46 @@ export async function createLayer(layerModel) {
|
|
|
200
222
|
}
|
|
201
223
|
else {
|
|
202
224
|
layerUrl = await ogcEndpoint.getCollectionItemsUrl(layerModel.collection, layerModel.options);
|
|
225
|
+
const source = new VectorSource({
|
|
226
|
+
format: new GeoJSON(),
|
|
227
|
+
url: layerUrl,
|
|
228
|
+
attributions: layerModel.attributions,
|
|
229
|
+
});
|
|
203
230
|
layer = new VectorLayer({
|
|
204
|
-
source
|
|
205
|
-
format: new GeoJSON(),
|
|
206
|
-
url: layerUrl,
|
|
207
|
-
attributions: layerModel.attributions,
|
|
208
|
-
}),
|
|
231
|
+
source,
|
|
209
232
|
style: layerModel.style ?? defaultStyle,
|
|
210
233
|
});
|
|
211
234
|
}
|
|
235
|
+
// FIXME: actually track layer loading
|
|
236
|
+
defer().then(() => emitLayerLoadingStatusSuccess(layer));
|
|
212
237
|
break;
|
|
213
238
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
239
|
+
case "geotiff": {
|
|
240
|
+
const geoTiffSource = new GeoTIFF({
|
|
241
|
+
sources: [{ url: layerModel.url }],
|
|
242
|
+
convertToRGB: "auto",
|
|
243
|
+
});
|
|
244
|
+
layer = new WebGLTileLayer({
|
|
245
|
+
source: geoTiffSource,
|
|
246
|
+
});
|
|
247
|
+
// FIXME: actually track tile loading
|
|
248
|
+
defer().then(() => emitLayerLoadingStatusSuccess(layer));
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
default: {
|
|
252
|
+
// we create an empty placeholder layer so that we still have a corresponding layer in OL
|
|
253
|
+
layer = new VectorLayer({
|
|
254
|
+
properties: {
|
|
255
|
+
[`${GEOSPATIAL_SDK_PREFIX}layer-with-error`]: true,
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
defer().then(() => emitLayerCreationError(layer, new Error(`Unrecognized layer type: ${JSON.stringify(layerModel)}`)));
|
|
259
|
+
}
|
|
219
260
|
}
|
|
220
261
|
updateLayerProperties(layerModel, layer);
|
|
221
262
|
return layer;
|
|
222
263
|
}
|
|
223
|
-
export function updateLayerInMap(map, layerModel, layerPosition, previousLayerModel) {
|
|
264
|
+
export async function updateLayerInMap(map, layerModel, layerPosition, previousLayerModel) {
|
|
224
265
|
const layers = map.getLayers();
|
|
225
266
|
const updatedLayer = layers.item(layerPosition);
|
|
226
267
|
// if an incremental update is possible, do it to avoid costly layer recreation
|
|
@@ -230,8 +271,9 @@ export function updateLayerInMap(map, layerModel, layerPosition, previousLayerMo
|
|
|
230
271
|
}
|
|
231
272
|
// dispose and recreate layer
|
|
232
273
|
updatedLayer.dispose();
|
|
233
|
-
createLayer(layerModel).then((layer) => {
|
|
274
|
+
await createLayer(layerModel).then((layer) => {
|
|
234
275
|
layers.setAt(layerPosition, layer);
|
|
276
|
+
propagateLayerStateChangeEventToMap(map, layer);
|
|
235
277
|
});
|
|
236
278
|
}
|
|
237
279
|
export function createView(viewModel, map) {
|
|
@@ -290,6 +332,7 @@ export async function resetMapFromContext(map, context) {
|
|
|
290
332
|
for (const layerModel of context.layers) {
|
|
291
333
|
const layer = await createLayer(layerModel);
|
|
292
334
|
map.addLayer(layer);
|
|
335
|
+
propagateLayerStateChangeEventToMap(map, layer);
|
|
293
336
|
}
|
|
294
337
|
initHoverLayer(map);
|
|
295
338
|
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
package/dist/map/listen.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listen.d.ts","sourceRoot":"","sources":["../../lib/map/listen.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,WAAW,CAAC;AAG5B,OAAO,
|
|
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"}
|
package/dist/map/listen.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { toLonLat } from "ol/proj.js";
|
|
2
|
-
import { FeaturesClickEventType, FeaturesHoverEventType, MapClickEventType, MapExtentChangeEventType, MapLayerStateChangeEventType, MapStateChangeEventType, MapViewStateChangeEventType, SourceLoadErrorType, } from "@geospatial-sdk/core";
|
|
2
|
+
import { FeaturesClickEventType, FeaturesHoverEventType, LayerCreationErrorEventType, LayerLoadingErrorEventType, MapClickEventType, MapExtentChangeEventType, MapLayerStateChangeEventType, MapStateChangeEventType, MapViewStateChangeEventType, SourceLoadErrorType, } from "@geospatial-sdk/core";
|
|
3
3
|
import { GEOSPATIAL_SDK_PREFIX } from "./constants.js";
|
|
4
|
-
import { registerFeatureClickEvent, registerFeatureHoverEvent, registerMapLayerStateChangeEvent, registerMapViewStateChangeEvent, } from "./register-events.js";
|
|
4
|
+
import { registerFeatureClickEvent, registerFeatureHoverEvent, registerLayerCreationErrorEvent, registerLayerLoadingErrorEvent, registerMapLayerStateChangeEvent, registerMapStateChangeEvent, registerMapViewStateChangeEvent, registerSourceLoadErrorEvent, } from "./register-events.js";
|
|
5
5
|
function addEventListener(map, eventType, callback) {
|
|
6
6
|
map.on(`${GEOSPATIAL_SDK_PREFIX}${eventType}`, ({ target: _target, ...event }) =>
|
|
7
7
|
// we're excluding the `target` property and renaming the `type` here
|
|
@@ -38,7 +38,15 @@ export function listen(map, eventType, callback) {
|
|
|
38
38
|
addEventListener(map, eventType, callback);
|
|
39
39
|
break;
|
|
40
40
|
case MapStateChangeEventType:
|
|
41
|
-
|
|
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);
|
|
42
50
|
addEventListener(map, eventType, callback);
|
|
43
51
|
break;
|
|
44
52
|
/**
|
|
@@ -52,29 +60,8 @@ export function listen(map, eventType, callback) {
|
|
|
52
60
|
}));
|
|
53
61
|
break;
|
|
54
62
|
case SourceLoadErrorType: {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
};
|
|
58
|
-
//attach event listener to all existing layers
|
|
59
|
-
map.getLayers().forEach((layer) => {
|
|
60
|
-
if (layer) {
|
|
61
|
-
layer.on(SourceLoadErrorType, errorCallback);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
//attach event listener when layer is added
|
|
65
|
-
map.getLayers().on("add", (event) => {
|
|
66
|
-
const layer = event.element;
|
|
67
|
-
if (layer) {
|
|
68
|
-
layer.on(SourceLoadErrorType, errorCallback);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
//remove event listener when layer is removed
|
|
72
|
-
map.getLayers().on("remove", (event) => {
|
|
73
|
-
const layer = event.element;
|
|
74
|
-
if (layer) {
|
|
75
|
-
layer.un(SourceLoadErrorType, errorCallback);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
63
|
+
registerSourceLoadErrorEvent(map);
|
|
64
|
+
map.on(SourceLoadErrorType, (event) => callback(event));
|
|
78
65
|
break;
|
|
79
66
|
}
|
|
80
67
|
default:
|
|
@@ -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"}
|