@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,13 +1,6 @@
|
|
|
1
|
-
import { ImageTile, Tile } from "ol";
|
|
2
|
-
import TileState from "ol/TileState.js";
|
|
3
|
-
import { SourceLoadErrorEvent } from "@geospatial-sdk/core";
|
|
4
|
-
import {
|
|
5
|
-
handleTileError,
|
|
6
|
-
tileLoadErrorCatchFunction,
|
|
7
|
-
} from "./handle-errors.js";
|
|
8
1
|
import TileLayer from "ol/layer/Tile.js";
|
|
9
2
|
import VectorLayer from "ol/layer/Vector.js";
|
|
10
|
-
import {
|
|
3
|
+
import { emitLayerLoadingError } from "./register-events.js";
|
|
11
4
|
|
|
12
5
|
globalThis.URL.createObjectURL = vi.fn(() => "blob:http://example.com/blob");
|
|
13
6
|
|
|
@@ -26,45 +19,29 @@ globalThis.fetch = vi.fn().mockImplementation((url: string) => {
|
|
|
26
19
|
});
|
|
27
20
|
|
|
28
21
|
describe("handle-errors", () => {
|
|
29
|
-
let tile: Tile;
|
|
30
|
-
|
|
31
|
-
beforeEach(() => {
|
|
32
|
-
tile = new ImageTile(
|
|
33
|
-
[0, 0, 0],
|
|
34
|
-
TileState.IDLE,
|
|
35
|
-
"",
|
|
36
|
-
null,
|
|
37
|
-
() => tileLoadErrorCatchFunction,
|
|
38
|
-
);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
22
|
describe("handleEndpointError", () => {
|
|
42
23
|
it("should dispatch SourceLoadErrorEvent", () => {
|
|
43
|
-
const endpointErrorMock: EndpointError = {
|
|
44
|
-
name: "Error",
|
|
45
|
-
message: "FORBIDDEN",
|
|
46
|
-
httpStatus: 403,
|
|
47
|
-
};
|
|
48
24
|
const layer = new VectorLayer({});
|
|
49
25
|
const dispatchEventSpy = vi.spyOn(layer, "dispatchEvent");
|
|
50
|
-
|
|
51
|
-
expect(dispatchEventSpy).toHaveBeenCalledWith(
|
|
52
|
-
|
|
53
|
-
|
|
26
|
+
emitLayerLoadingError(layer, new Error("FORBIDDEN"), 403);
|
|
27
|
+
expect(dispatchEventSpy).toHaveBeenCalledWith({
|
|
28
|
+
type: "--geospatial-sdk-layer-loading-error",
|
|
29
|
+
error: new Error("FORBIDDEN"),
|
|
30
|
+
httpStatus: 403,
|
|
31
|
+
});
|
|
54
32
|
});
|
|
55
33
|
});
|
|
56
34
|
|
|
57
35
|
describe("handleTileError", () => {
|
|
58
36
|
it("should set tile state to ERROR and dispatch SourceLoadErrorEvent", () => {
|
|
59
|
-
const response = new Response("Forbidden", { status: 403 });
|
|
60
37
|
const layer = new TileLayer({});
|
|
61
38
|
const dispatchEventSpy = vi.spyOn(layer, "dispatchEvent");
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
);
|
|
39
|
+
emitLayerLoadingError(layer, new Error("Forbidden"), 403);
|
|
40
|
+
expect(dispatchEventSpy).toHaveBeenCalledWith({
|
|
41
|
+
type: "--geospatial-sdk-layer-loading-error",
|
|
42
|
+
error: new Error("Forbidden"),
|
|
43
|
+
httpStatus: 403,
|
|
44
|
+
});
|
|
68
45
|
});
|
|
69
46
|
});
|
|
70
47
|
});
|
package/lib/map/handle-errors.ts
CHANGED
|
@@ -1,30 +1,7 @@
|
|
|
1
|
-
import { EndpointError } from "@camptocamp/ogc-client";
|
|
2
|
-
import { SourceLoadErrorEvent } from "@geospatial-sdk/core";
|
|
3
1
|
import { ImageTile, Tile } from "ol";
|
|
4
2
|
import { Layer } from "ol/layer.js";
|
|
5
|
-
import TileLayer from "ol/layer/Tile.js";
|
|
6
|
-
import VectorLayer from "ol/layer/Vector.js";
|
|
7
|
-
import TileSource from "ol/source/Tile.js";
|
|
8
|
-
import VectorSource from "ol/source/Vector.js";
|
|
9
3
|
import TileState from "ol/TileState.js";
|
|
10
|
-
|
|
11
|
-
export function handleEndpointError(
|
|
12
|
-
layer: TileLayer<TileSource> | VectorLayer<VectorSource>,
|
|
13
|
-
error: EndpointError,
|
|
14
|
-
) {
|
|
15
|
-
console.error("Error loading Endpoint", error);
|
|
16
|
-
layer.dispatchEvent(new SourceLoadErrorEvent(error));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function handleTileError(
|
|
20
|
-
response: Response | Error,
|
|
21
|
-
tile: Tile,
|
|
22
|
-
layer: Layer,
|
|
23
|
-
) {
|
|
24
|
-
console.error("Error loading tile", response);
|
|
25
|
-
tile.setState(TileState.ERROR);
|
|
26
|
-
layer.dispatchEvent(new SourceLoadErrorEvent(response));
|
|
27
|
-
}
|
|
4
|
+
import { emitLayerLoadingError } from "./register-events.js";
|
|
28
5
|
|
|
29
6
|
export function tileLoadErrorCatchFunction(
|
|
30
7
|
layer: Layer,
|
|
@@ -40,14 +17,19 @@ export function tileLoadErrorCatchFunction(
|
|
|
40
17
|
const image = (tile as ImageTile).getImage();
|
|
41
18
|
(image as HTMLImageElement).src = URL.createObjectURL(blob);
|
|
42
19
|
})
|
|
43
|
-
.catch(() => {
|
|
44
|
-
|
|
20
|
+
.catch((error) => {
|
|
21
|
+
tile.setState(TileState.ERROR);
|
|
22
|
+
emitLayerLoadingError(layer, error);
|
|
45
23
|
});
|
|
46
24
|
} else {
|
|
47
|
-
|
|
25
|
+
tile.setState(TileState.ERROR);
|
|
26
|
+
response.text().then((text) => {
|
|
27
|
+
emitLayerLoadingError(layer, new Error(text), response.status);
|
|
28
|
+
});
|
|
48
29
|
}
|
|
49
30
|
})
|
|
50
31
|
.catch((error) => {
|
|
51
|
-
|
|
32
|
+
tile.setState(TileState.ERROR);
|
|
33
|
+
emitLayerLoadingError(layer, error);
|
|
52
34
|
});
|
|
53
35
|
}
|
package/lib/map/index.ts
CHANGED
|
@@ -5,4 +5,5 @@
|
|
|
5
5
|
|
|
6
6
|
export { createMapFromContext, resetMapFromContext } from "./create-map.js";
|
|
7
7
|
export { applyContextDiffToMap } from "./apply-context-diff.js";
|
|
8
|
-
export { listen } from "./
|
|
8
|
+
export { listen } from "./listen.js";
|
|
9
|
+
export { readMapViewState } from "./resolved-map-state.js";
|
package/lib/map/layer-update.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { getHash, MapContextLayer } from "@geospatial-sdk/core";
|
|
2
1
|
import {
|
|
2
|
+
getHash,
|
|
3
3
|
MapContextBaseLayer,
|
|
4
|
+
MapContextLayer,
|
|
4
5
|
MapContextLayerVector,
|
|
5
|
-
} from "@geospatial-sdk/core
|
|
6
|
+
} from "@geospatial-sdk/core";
|
|
6
7
|
import Layer from "ol/layer/Layer.js";
|
|
7
8
|
import VectorLayer from "ol/layer/Vector.js";
|
|
8
9
|
import type VectorSource from "ol/source/Vector.js";
|