@geospatial-sdk/openlayers 0.0.5-dev.53 → 0.0.5-dev.54
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/feature-hover.d.ts +1 -1
- package/dist/map/feature-hover.d.ts.map +1 -1
- package/dist/map/feature-hover.js +6 -6
- package/dist/map/layer-update.d.ts.map +1 -1
- package/dist/map/layer-update.js +6 -6
- package/dist/map/listen.d.ts.map +1 -1
- package/dist/map/listen.js +2 -2
- package/dist/map/register-events.js +2 -2
- package/dist/map/resolved-map-state.d.ts.map +1 -1
- package/dist/map/resolved-map-state.js +1 -2
- package/lib/map/feature-hover.ts +8 -8
- package/lib/map/layer-update.test.ts +5 -5
- package/lib/map/layer-update.ts +7 -13
- package/lib/map/register-events.ts +2 -2
- package/package.json +3 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type OlMap from "ol/Map.js";
|
|
2
1
|
import VectorLayer from "ol/layer/Vector.js";
|
|
2
|
+
import type OlMap from "ol/Map.js";
|
|
3
3
|
import VectorSource from "ol/source/Vector.js";
|
|
4
4
|
export declare function initHoverLayer(map: OlMap): void;
|
|
5
5
|
export declare function getHoverLayer(map: OlMap): VectorLayer<VectorSource>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature-hover.d.ts","sourceRoot":"","sources":["../../lib/map/feature-hover.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"feature-hover.d.ts","sourceRoot":"","sources":["../../lib/map/feature-hover.ts"],"names":[],"mappings":"AAQA,OAAO,WAAW,MAAM,oBAAoB,CAAC;AAC7C,OAAO,KAAK,KAAK,MAAM,WAAW,CAAC;AAEnC,OAAO,YAAY,MAAM,qBAAqB,CAAC;AAO/C,wBAAgB,cAAc,CAAC,GAAG,EAAE,KAAK,QAoGxC;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,KAAK,GAAG,WAAW,CAAC,YAAY,CAAC,CAEnE;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,KAAK,QAMzC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { GEOSPATIAL_SDK_PREFIX } from "./constants.js";
|
|
2
|
-
import VectorLayer from "ol/layer/Vector.js";
|
|
3
|
-
import VectorSource from "ol/source/Vector.js";
|
|
4
1
|
import { defaultHighlightStyle, FeaturesHoverEventType, } from "@geospatial-sdk/core";
|
|
5
2
|
import OlFeature from "ol/Feature.js";
|
|
3
|
+
import VectorLayer from "ol/layer/Vector.js";
|
|
6
4
|
import { unByKey } from "ol/Observable.js";
|
|
5
|
+
import VectorSource from "ol/source/Vector.js";
|
|
6
|
+
import { GEOSPATIAL_SDK_PREFIX } from "./constants.js";
|
|
7
7
|
import { readFeaturesAtPixel } from "./get-features.js";
|
|
8
8
|
const hoverLayerKey = `${GEOSPATIAL_SDK_PREFIX}hover-layer`;
|
|
9
9
|
const unsubscribeKey = `${GEOSPATIAL_SDK_PREFIX}hover-unsub`;
|
|
@@ -19,15 +19,15 @@ export function initHoverLayer(map) {
|
|
|
19
19
|
}),
|
|
20
20
|
style: defaultHighlightStyle,
|
|
21
21
|
properties: {
|
|
22
|
-
[`${GEOSPATIAL_SDK_PREFIX}
|
|
23
|
-
[`${GEOSPATIAL_SDK_PREFIX}
|
|
22
|
+
[`${GEOSPATIAL_SDK_PREFIX}hoverable`]: false,
|
|
23
|
+
[`${GEOSPATIAL_SDK_PREFIX}clickable`]: false,
|
|
24
24
|
},
|
|
25
25
|
});
|
|
26
26
|
map.set(hoverLayerKey, hoverLayer);
|
|
27
27
|
hoverLayer.setMap(map);
|
|
28
28
|
// store original cursor style in order to change it later
|
|
29
29
|
const originalCursorStyle = map.getTargetElement()?.style.cursor ?? "";
|
|
30
|
-
const layerFilter = (layer) => layer.get(`${GEOSPATIAL_SDK_PREFIX}
|
|
30
|
+
const layerFilter = (layer) => layer.get(`${GEOSPATIAL_SDK_PREFIX}hoverable`);
|
|
31
31
|
const unKey = map.on("pointermove", async (event) => {
|
|
32
32
|
// skip hit detection if the view is moving as it can have an impact on performance
|
|
33
33
|
if (map.getView().getInteracting() || map.getView().getAnimating()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layer-update.d.ts","sourceRoot":"","sources":["../../lib/map/layer-update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAKhE,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,
|
|
1
|
+
{"version":3,"file":"layer-update.d.ts","sourceRoot":"","sources":["../../lib/map/layer-update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAKhE,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
|
@@ -7,8 +7,8 @@ const UPDATABLE_PROPERTIES = [
|
|
|
7
7
|
"attributions",
|
|
8
8
|
"extras",
|
|
9
9
|
"version",
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"hoverable",
|
|
11
|
+
"clickable",
|
|
12
12
|
"style",
|
|
13
13
|
"hoverStyle",
|
|
14
14
|
// TODO (when available) "zIndex"
|
|
@@ -60,14 +60,14 @@ export function updateLayerProperties(layerModel, olLayer, previousLayerModel) {
|
|
|
60
60
|
if (shouldApplyProperty("label")) {
|
|
61
61
|
olLayer.set("label", layerModel.label);
|
|
62
62
|
}
|
|
63
|
-
if (shouldApplyProperty("
|
|
64
|
-
olLayer.set(`${GEOSPATIAL_SDK_PREFIX}
|
|
63
|
+
if (shouldApplyProperty("hoverable")) {
|
|
64
|
+
olLayer.set(`${GEOSPATIAL_SDK_PREFIX}hoverable`, layerModel.hoverable);
|
|
65
65
|
}
|
|
66
66
|
if (shouldApplyProperty("hoverStyle")) {
|
|
67
67
|
olLayer.set(`${GEOSPATIAL_SDK_PREFIX}hover-style`, layerModel.hoverStyle);
|
|
68
68
|
}
|
|
69
|
-
if (shouldApplyProperty("
|
|
70
|
-
olLayer.set(`${GEOSPATIAL_SDK_PREFIX}
|
|
69
|
+
if (shouldApplyProperty("clickable")) {
|
|
70
|
+
olLayer.set(`${GEOSPATIAL_SDK_PREFIX}clickable`, layerModel.clickable);
|
|
71
71
|
}
|
|
72
72
|
if (shouldApplyProperty("style") &&
|
|
73
73
|
"setStyle" in olLayer) {
|
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,EAKL,eAAe,EAShB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"listen.d.ts","sourceRoot":"","sources":["../../lib/map/listen.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,WAAW,CAAC;AAG5B,OAAO,EAKL,eAAe,EAShB,MAAM,sBAAsB,CAAC;AA8B9B,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,QA+E9C"}
|
package/dist/map/listen.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { toLonLat } from "ol/proj.js";
|
|
2
2
|
import { FeaturesClickEventType, FeaturesHoverEventType, MapClickEventType, MapExtentChangeEventType, MapLayerStateChangeEventType, MapStateChangeEventType, MapViewStateChangeEventType, SourceLoadErrorType, } from "@geospatial-sdk/core";
|
|
3
3
|
import { GEOSPATIAL_SDK_PREFIX } from "./constants.js";
|
|
4
|
-
import { registerFeatureClickEvent, registerFeatureHoverEvent, registerMapViewStateChangeEvent, } from "./register-events.js";
|
|
4
|
+
import { registerFeatureClickEvent, registerFeatureHoverEvent, registerMapLayerStateChangeEvent, registerMapViewStateChangeEvent, } 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
|
|
@@ -34,7 +34,7 @@ export function listen(map, eventType, callback) {
|
|
|
34
34
|
addEventListener(map, eventType, callback);
|
|
35
35
|
break;
|
|
36
36
|
case MapLayerStateChangeEventType:
|
|
37
|
-
|
|
37
|
+
registerMapLayerStateChangeEvent(map);
|
|
38
38
|
addEventListener(map, eventType, callback);
|
|
39
39
|
break;
|
|
40
40
|
case MapStateChangeEventType:
|
|
@@ -6,8 +6,8 @@ import { readFeaturesAtPixel } from "./get-features.js";
|
|
|
6
6
|
function registerFeatureClickEvent(map) {
|
|
7
7
|
if (map.get(FeaturesClickEventType))
|
|
8
8
|
return;
|
|
9
|
-
// Filter to only query layers
|
|
10
|
-
const layerFilter = (layer) =>
|
|
9
|
+
// Filter to only query clickable layers
|
|
10
|
+
const layerFilter = (layer) => layer.get(`${GEOSPATIAL_SDK_PREFIX}clickable`) !== false;
|
|
11
11
|
map.on("click", async (event) => {
|
|
12
12
|
const featuresByLayer = await readFeaturesAtPixel(map, event, layerFilter);
|
|
13
13
|
const features = Array.from(featuresByLayer.values()).flat();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolved-map-state.d.ts","sourceRoot":"","sources":["../../lib/map/resolved-map-state.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,WAAW,CAAC;AAE5B,OAAO,
|
|
1
|
+
{"version":3,"file":"resolved-map-state.d.ts","sourceRoot":"","sources":["../../lib/map/resolved-map-state.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,WAAW,CAAC;AAE5B,OAAO,EAAsB,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAOhF;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,GAAG,GAAG,oBAAoB,CAwB/D"}
|
|
@@ -10,7 +10,7 @@ const PIXEL_SIZE_MM = 0.28;
|
|
|
10
10
|
export function readMapViewState(map) {
|
|
11
11
|
const view = map.getView();
|
|
12
12
|
const projection = view.getProjection();
|
|
13
|
-
const extent = transformExtent(view.calculateExtent(), projection, "EPSG:4326");
|
|
13
|
+
const extent = transformExtent(view.calculateExtent(map.getSize()), projection, "EPSG:4326");
|
|
14
14
|
const center = transformCoordinate(view.getCenter() ?? [0, 0], projection, "EPSG:4326");
|
|
15
15
|
const resolution = view.getResolution() ?? 1;
|
|
16
16
|
const metersPerUnit = projection.getMetersPerUnit() ?? 1;
|
|
@@ -24,4 +24,3 @@ export function readMapViewState(map) {
|
|
|
24
24
|
bearing,
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
export function processLayerEvent(map, layer) { }
|
package/lib/map/feature-hover.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { GEOSPATIAL_SDK_PREFIX } from "./constants.js";
|
|
2
|
-
import type OlMap from "ol/Map.js";
|
|
3
|
-
import VectorLayer from "ol/layer/Vector.js";
|
|
4
|
-
import VectorSource from "ol/source/Vector.js";
|
|
5
1
|
import {
|
|
6
2
|
defaultHighlightStyle,
|
|
7
3
|
FeaturesHoverEventType,
|
|
8
4
|
} from "@geospatial-sdk/core";
|
|
9
|
-
import type BaseEvent from "ol/events/Event.js";
|
|
10
5
|
import { MapBrowserEvent } from "ol";
|
|
6
|
+
import type BaseEvent from "ol/events/Event.js";
|
|
11
7
|
import OlFeature from "ol/Feature.js";
|
|
12
8
|
import type BaseLayer from "ol/layer/Base.js";
|
|
9
|
+
import VectorLayer from "ol/layer/Vector.js";
|
|
10
|
+
import type OlMap from "ol/Map.js";
|
|
13
11
|
import { unByKey } from "ol/Observable.js";
|
|
12
|
+
import VectorSource from "ol/source/Vector.js";
|
|
13
|
+
import { GEOSPATIAL_SDK_PREFIX } from "./constants.js";
|
|
14
14
|
import { readFeaturesAtPixel } from "./get-features.js";
|
|
15
15
|
|
|
16
16
|
const hoverLayerKey = `${GEOSPATIAL_SDK_PREFIX}hover-layer`;
|
|
@@ -29,8 +29,8 @@ export function initHoverLayer(map: OlMap) {
|
|
|
29
29
|
}),
|
|
30
30
|
style: defaultHighlightStyle,
|
|
31
31
|
properties: {
|
|
32
|
-
[`${GEOSPATIAL_SDK_PREFIX}
|
|
33
|
-
[`${GEOSPATIAL_SDK_PREFIX}
|
|
32
|
+
[`${GEOSPATIAL_SDK_PREFIX}hoverable`]: false,
|
|
33
|
+
[`${GEOSPATIAL_SDK_PREFIX}clickable`]: false,
|
|
34
34
|
},
|
|
35
35
|
});
|
|
36
36
|
map.set(hoverLayerKey, hoverLayer);
|
|
@@ -40,7 +40,7 @@ export function initHoverLayer(map: OlMap) {
|
|
|
40
40
|
const originalCursorStyle = map.getTargetElement()?.style.cursor ?? "";
|
|
41
41
|
|
|
42
42
|
const layerFilter = (layer: BaseLayer) =>
|
|
43
|
-
layer.get(`${GEOSPATIAL_SDK_PREFIX}
|
|
43
|
+
layer.get(`${GEOSPATIAL_SDK_PREFIX}hoverable`);
|
|
44
44
|
|
|
45
45
|
const unKey = map.on(
|
|
46
46
|
"pointermove",
|
|
@@ -125,8 +125,8 @@ describe("Layer update utils", () => {
|
|
|
125
125
|
style: {
|
|
126
126
|
"circle-fill-color": "blue",
|
|
127
127
|
},
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
hoverable: true,
|
|
129
|
+
clickable: false,
|
|
130
130
|
};
|
|
131
131
|
const prevLayerModel = SAMPLE_LAYER3;
|
|
132
132
|
updateLayerProperties(layerModel, olLayer, prevLayerModel);
|
|
@@ -134,12 +134,12 @@ describe("Layer update utils", () => {
|
|
|
134
134
|
layerModel.style,
|
|
135
135
|
);
|
|
136
136
|
expect(olLayer.set).toHaveBeenCalledWith(
|
|
137
|
-
"--geospatial-sdk-
|
|
137
|
+
"--geospatial-sdk-hoverable",
|
|
138
138
|
true,
|
|
139
139
|
);
|
|
140
140
|
expect(olLayer.set).toHaveBeenCalledWith(
|
|
141
|
-
"--geospatial-sdk-
|
|
142
|
-
|
|
141
|
+
"--geospatial-sdk-clickable",
|
|
142
|
+
false,
|
|
143
143
|
);
|
|
144
144
|
});
|
|
145
145
|
});
|
package/lib/map/layer-update.ts
CHANGED
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
MapContextLayerVector,
|
|
5
5
|
} from "@geospatial-sdk/core/lib/model/map-context.js";
|
|
6
6
|
import Layer from "ol/layer/Layer.js";
|
|
7
|
-
import { GEOSPATIAL_SDK_PREFIX } from "./constants.js";
|
|
8
7
|
import VectorLayer from "ol/layer/Vector.js";
|
|
9
8
|
import type VectorSource from "ol/source/Vector.js";
|
|
9
|
+
import { GEOSPATIAL_SDK_PREFIX } from "./constants.js";
|
|
10
10
|
|
|
11
11
|
const UPDATABLE_PROPERTIES: (
|
|
12
12
|
| keyof MapContextBaseLayer
|
|
@@ -18,8 +18,8 @@ const UPDATABLE_PROPERTIES: (
|
|
|
18
18
|
"attributions",
|
|
19
19
|
"extras",
|
|
20
20
|
"version",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
21
|
+
"hoverable",
|
|
22
|
+
"clickable",
|
|
23
23
|
"style",
|
|
24
24
|
"hoverStyle",
|
|
25
25
|
// TODO (when available) "zIndex"
|
|
@@ -82,11 +82,8 @@ export function updateLayerProperties(
|
|
|
82
82
|
if (shouldApplyProperty("label")) {
|
|
83
83
|
olLayer.set("label", layerModel.label);
|
|
84
84
|
}
|
|
85
|
-
if (shouldApplyProperty("
|
|
86
|
-
olLayer.set(
|
|
87
|
-
`${GEOSPATIAL_SDK_PREFIX}enable-hover`,
|
|
88
|
-
(layerModel as MapContextLayerVector).enableHover,
|
|
89
|
-
);
|
|
85
|
+
if (shouldApplyProperty("hoverable")) {
|
|
86
|
+
olLayer.set(`${GEOSPATIAL_SDK_PREFIX}hoverable`, layerModel.hoverable);
|
|
90
87
|
}
|
|
91
88
|
if (shouldApplyProperty("hoverStyle" as keyof MapContextLayer)) {
|
|
92
89
|
olLayer.set(
|
|
@@ -94,11 +91,8 @@ export function updateLayerProperties(
|
|
|
94
91
|
(layerModel as MapContextLayerVector).hoverStyle,
|
|
95
92
|
);
|
|
96
93
|
}
|
|
97
|
-
if (shouldApplyProperty("
|
|
98
|
-
olLayer.set(
|
|
99
|
-
`${GEOSPATIAL_SDK_PREFIX}disable-click`,
|
|
100
|
-
layerModel.disableClick,
|
|
101
|
-
);
|
|
94
|
+
if (shouldApplyProperty("clickable" as keyof MapContextLayer)) {
|
|
95
|
+
olLayer.set(`${GEOSPATIAL_SDK_PREFIX}clickable`, layerModel.clickable);
|
|
102
96
|
}
|
|
103
97
|
if (
|
|
104
98
|
shouldApplyProperty("style" as keyof MapContextLayer) &&
|
|
@@ -19,9 +19,9 @@ import { readFeaturesAtPixel } from "./get-features.js";
|
|
|
19
19
|
function registerFeatureClickEvent(map: Map) {
|
|
20
20
|
if (map.get(FeaturesClickEventType)) return;
|
|
21
21
|
|
|
22
|
-
// Filter to only query layers
|
|
22
|
+
// Filter to only query clickable layers
|
|
23
23
|
const layerFilter = (layer: BaseLayer) =>
|
|
24
|
-
|
|
24
|
+
layer.get(`${GEOSPATIAL_SDK_PREFIX}clickable`) !== false;
|
|
25
25
|
|
|
26
26
|
map.on("click", async (event: any) => {
|
|
27
27
|
const featuresByLayer = await readFeaturesAtPixel(map, event, layerFilter);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geospatial-sdk/openlayers",
|
|
3
|
-
"version": "0.0.5-dev.
|
|
3
|
+
"version": "0.0.5-dev.54+352b554",
|
|
4
4
|
"description": "OpenLayers-related utilities",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ol",
|
|
@@ -37,10 +37,9 @@
|
|
|
37
37
|
"ol": ">9.x"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@geospatial-sdk/core": "^0.0.5-dev.
|
|
41
|
-
"chroma-js": "^2.4.2",
|
|
40
|
+
"@geospatial-sdk/core": "^0.0.5-dev.54+352b554",
|
|
42
41
|
"lodash.throttle": "^4.1.1",
|
|
43
42
|
"ol-mapbox-style": "12.4.0"
|
|
44
43
|
},
|
|
45
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "352b554ec0ca6a27dee923a28b4b1bb4e3f12973"
|
|
46
45
|
}
|