@geospatial-sdk/openlayers 0.0.5-dev.55 → 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 +56 -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 +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 +127 -38
- package/lib/map/create-map.ts +82 -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/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,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,17 @@ 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";
|
|
27
29
|
// Register proj4 with OpenLayers so that arbitrary EPSG codes
|
|
28
30
|
// (e.g., UTM zones from GeoTIFF metadata) can be reprojected to the map projection
|
|
29
31
|
register(proj4);
|
|
30
32
|
const GEOJSON = new GeoJSON();
|
|
31
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));
|
|
32
38
|
export async function createLayer(layerModel) {
|
|
33
39
|
const { type } = layerModel;
|
|
34
40
|
let layer;
|
|
@@ -55,6 +61,7 @@ export async function createLayer(layerModel) {
|
|
|
55
61
|
});
|
|
56
62
|
layer.setSource(source);
|
|
57
63
|
}
|
|
64
|
+
defer().then(() => emitLayerLoadingStatusSuccess(layer));
|
|
58
65
|
}
|
|
59
66
|
break;
|
|
60
67
|
case "wms":
|
|
@@ -73,6 +80,7 @@ export async function createLayer(layerModel) {
|
|
|
73
80
|
return tileLoadErrorCatchFunction(layer, tile, src);
|
|
74
81
|
});
|
|
75
82
|
layer.setSource(source);
|
|
83
|
+
defer().then(() => emitLayerLoadingStatusSuccess(layer));
|
|
76
84
|
}
|
|
77
85
|
break;
|
|
78
86
|
case "wmts": {
|
|
@@ -104,10 +112,13 @@ export async function createLayer(layerModel) {
|
|
|
104
112
|
attributions: layerModel.attributions,
|
|
105
113
|
}));
|
|
106
114
|
})
|
|
115
|
+
.then(() => emitLayerLoadingStatusSuccess(olLayer))
|
|
107
116
|
.catch((e) => {
|
|
108
|
-
|
|
117
|
+
const httpStatus = e instanceof EndpointError ? e.httpStatus : undefined;
|
|
118
|
+
emitLayerLoadingError(olLayer, e, httpStatus);
|
|
109
119
|
});
|
|
110
|
-
|
|
120
|
+
layer = olLayer;
|
|
121
|
+
break;
|
|
111
122
|
}
|
|
112
123
|
case "wfs": {
|
|
113
124
|
const olLayer = new VectorLayer({
|
|
@@ -132,8 +143,10 @@ export async function createLayer(layerModel) {
|
|
|
132
143
|
attributions: layerModel.attributions,
|
|
133
144
|
}));
|
|
134
145
|
})
|
|
146
|
+
.then(() => emitLayerLoadingStatusSuccess(olLayer))
|
|
135
147
|
.catch((e) => {
|
|
136
|
-
|
|
148
|
+
const httpStatus = e instanceof EndpointError ? e.httpStatus : undefined;
|
|
149
|
+
emitLayerLoadingError(olLayer, e, httpStatus);
|
|
137
150
|
});
|
|
138
151
|
layer = olLayer;
|
|
139
152
|
break;
|
|
@@ -143,17 +156,19 @@ export async function createLayer(layerModel) {
|
|
|
143
156
|
styleUrl: layerModel.styleUrl,
|
|
144
157
|
accessToken: layerModel.accessToken,
|
|
145
158
|
});
|
|
159
|
+
defer().then(() => emitLayerLoadingStatusSuccess(layer));
|
|
146
160
|
break;
|
|
147
161
|
}
|
|
148
162
|
case "geojson": {
|
|
163
|
+
layer = new VectorLayer({
|
|
164
|
+
style: layerModel.style ?? defaultStyle,
|
|
165
|
+
});
|
|
166
|
+
let source;
|
|
149
167
|
if (layerModel.url !== undefined) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
attributions: layerModel.attributions,
|
|
155
|
-
}),
|
|
156
|
-
style: layerModel.style ?? defaultStyle,
|
|
168
|
+
source = new VectorSource({
|
|
169
|
+
format: new GeoJSON(),
|
|
170
|
+
url: layerModel.url,
|
|
171
|
+
attributions: layerModel.attributions,
|
|
157
172
|
});
|
|
158
173
|
}
|
|
159
174
|
else {
|
|
@@ -171,14 +186,14 @@ export async function createLayer(layerModel) {
|
|
|
171
186
|
featureProjection: "EPSG:3857",
|
|
172
187
|
dataProjection: "EPSG:4326",
|
|
173
188
|
});
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
attributions: layerModel.attributions,
|
|
178
|
-
}),
|
|
179
|
-
style: layerModel.style ?? defaultStyle,
|
|
189
|
+
source = new VectorSource({
|
|
190
|
+
features,
|
|
191
|
+
attributions: layerModel.attributions,
|
|
180
192
|
});
|
|
181
193
|
}
|
|
194
|
+
layer.setSource(source);
|
|
195
|
+
// FIXME: actually track layer loading and data info
|
|
196
|
+
defer().then(() => emitLayerLoadingStatusSuccess(layer));
|
|
182
197
|
break;
|
|
183
198
|
}
|
|
184
199
|
case "ogcapi": {
|
|
@@ -207,15 +222,18 @@ export async function createLayer(layerModel) {
|
|
|
207
222
|
}
|
|
208
223
|
else {
|
|
209
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
|
+
});
|
|
210
230
|
layer = new VectorLayer({
|
|
211
|
-
source
|
|
212
|
-
format: new GeoJSON(),
|
|
213
|
-
url: layerUrl,
|
|
214
|
-
attributions: layerModel.attributions,
|
|
215
|
-
}),
|
|
231
|
+
source,
|
|
216
232
|
style: layerModel.style ?? defaultStyle,
|
|
217
233
|
});
|
|
218
234
|
}
|
|
235
|
+
// FIXME: actually track layer loading
|
|
236
|
+
defer().then(() => emitLayerLoadingStatusSuccess(layer));
|
|
219
237
|
break;
|
|
220
238
|
}
|
|
221
239
|
case "geotiff": {
|
|
@@ -226,18 +244,24 @@ export async function createLayer(layerModel) {
|
|
|
226
244
|
layer = new WebGLTileLayer({
|
|
227
245
|
source: geoTiffSource,
|
|
228
246
|
});
|
|
247
|
+
// FIXME: actually track tile loading
|
|
248
|
+
defer().then(() => emitLayerLoadingStatusSuccess(layer));
|
|
229
249
|
break;
|
|
230
250
|
}
|
|
231
|
-
default:
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
+
}
|
|
236
260
|
}
|
|
237
261
|
updateLayerProperties(layerModel, layer);
|
|
238
262
|
return layer;
|
|
239
263
|
}
|
|
240
|
-
export function updateLayerInMap(map, layerModel, layerPosition, previousLayerModel) {
|
|
264
|
+
export async function updateLayerInMap(map, layerModel, layerPosition, previousLayerModel) {
|
|
241
265
|
const layers = map.getLayers();
|
|
242
266
|
const updatedLayer = layers.item(layerPosition);
|
|
243
267
|
// if an incremental update is possible, do it to avoid costly layer recreation
|
|
@@ -247,8 +271,9 @@ export function updateLayerInMap(map, layerModel, layerPosition, previousLayerMo
|
|
|
247
271
|
}
|
|
248
272
|
// dispose and recreate layer
|
|
249
273
|
updatedLayer.dispose();
|
|
250
|
-
createLayer(layerModel).then((layer) => {
|
|
274
|
+
await createLayer(layerModel).then((layer) => {
|
|
251
275
|
layers.setAt(layerPosition, layer);
|
|
276
|
+
propagateLayerStateChangeEventToMap(map, layer);
|
|
252
277
|
});
|
|
253
278
|
}
|
|
254
279
|
export function createView(viewModel, map) {
|
|
@@ -307,6 +332,7 @@ export async function resetMapFromContext(map, context) {
|
|
|
307
332
|
for (const layerModel of context.layers) {
|
|
308
333
|
const layer = await createLayer(layerModel);
|
|
309
334
|
map.addLayer(layer);
|
|
335
|
+
propagateLayerStateChangeEventToMap(map, layer);
|
|
310
336
|
}
|
|
311
337
|
initHoverLayer(map);
|
|
312
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
|
@@ -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"}
|