@geospatial-sdk/openlayers 0.0.5-dev.51 → 0.0.5-dev.53

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.
Files changed (35) hide show
  1. package/dist/map/feature-hover.d.ts +4 -4
  2. package/dist/map/feature-hover.d.ts.map +1 -1
  3. package/dist/map/feature-hover.js +28 -7
  4. package/dist/map/feature-selection.d.ts +8 -0
  5. package/dist/map/feature-selection.d.ts.map +1 -0
  6. package/dist/map/feature-selection.js +76 -0
  7. package/dist/map/get-features.d.ts +10 -9
  8. package/dist/map/get-features.d.ts.map +1 -1
  9. package/dist/map/get-features.js +60 -31
  10. package/dist/map/layer-update.d.ts.map +1 -1
  11. package/dist/map/layer-update.js +8 -0
  12. package/dist/map/listen.d.ts +4 -0
  13. package/dist/map/listen.d.ts.map +1 -0
  14. package/dist/map/listen.js +83 -0
  15. package/dist/map/register-events.d.ts +1 -1
  16. package/dist/map/register-events.d.ts.map +1 -1
  17. package/dist/map/register-events.js +7 -2
  18. package/dist/map/resolved-map-state.d.ts +8 -0
  19. package/dist/map/resolved-map-state.d.ts.map +1 -0
  20. package/dist/map/resolved-map-state.js +27 -0
  21. package/dist/map/styles.d.ts +16 -0
  22. package/dist/map/styles.d.ts.map +1 -0
  23. package/dist/map/styles.js +77 -0
  24. package/dist/resolved-state/resolved-map-state.d.ts +2 -0
  25. package/dist/resolved-state/resolved-map-state.d.ts.map +1 -0
  26. package/dist/resolved-state/resolved-map-state.js +1 -0
  27. package/lib/map/feature-hover.ts +52 -17
  28. package/lib/map/get-features.test.ts +32 -20
  29. package/lib/map/get-features.ts +85 -48
  30. package/lib/map/handle-errors.test.ts +4 -4
  31. package/lib/map/layer-update.test.ts +6 -1
  32. package/lib/map/layer-update.ts +16 -1
  33. package/lib/map/register-events.test.ts +60 -64
  34. package/lib/map/register-events.ts +13 -5
  35. package/package.json +3 -3
@@ -1,7 +1,7 @@
1
- import type Map from "ol/Map.js";
1
+ import type OlMap from "ol/Map.js";
2
2
  import VectorLayer from "ol/layer/Vector.js";
3
3
  import VectorSource from "ol/source/Vector.js";
4
- export declare function initHoverLayer(map: Map): void;
5
- export declare function getHoverLayer(map: Map): VectorLayer<VectorSource>;
6
- export declare function clearHoverLayer(map: Map): void;
4
+ export declare function initHoverLayer(map: OlMap): void;
5
+ export declare function getHoverLayer(map: OlMap): VectorLayer<VectorSource>;
6
+ export declare function clearHoverLayer(map: OlMap): void;
7
7
  //# sourceMappingURL=feature-hover.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"feature-hover.d.ts","sourceRoot":"","sources":["../../lib/map/feature-hover.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AACjC,OAAO,WAAW,MAAM,oBAAoB,CAAC;AAC7C,OAAO,YAAY,MAAM,qBAAqB,CAAC;AAiB/C,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,QA+DtC;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,GAAG,GAAG,WAAW,CAAC,YAAY,CAAC,CAEjE;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,GAAG,QAMvC"}
1
+ {"version":3,"file":"feature-hover.d.ts","sourceRoot":"","sources":["../../lib/map/feature-hover.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,WAAW,CAAC;AACnC,OAAO,WAAW,MAAM,oBAAoB,CAAC;AAC7C,OAAO,YAAY,MAAM,qBAAqB,CAAC;AAe/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"}
@@ -2,9 +2,9 @@ import { GEOSPATIAL_SDK_PREFIX } from "./constants.js";
2
2
  import VectorLayer from "ol/layer/Vector.js";
3
3
  import VectorSource from "ol/source/Vector.js";
4
4
  import { defaultHighlightStyle, FeaturesHoverEventType, } from "@geospatial-sdk/core";
5
- import GeoJSON from "ol/format/GeoJSON.js";
5
+ import OlFeature from "ol/Feature.js";
6
6
  import { unByKey } from "ol/Observable.js";
7
- const GEOJSON = new GeoJSON();
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`;
10
10
  export function initHoverLayer(map) {
@@ -18,12 +18,16 @@ export function initHoverLayer(map) {
18
18
  useSpatialIndex: false,
19
19
  }),
20
20
  style: defaultHighlightStyle,
21
+ properties: {
22
+ [`${GEOSPATIAL_SDK_PREFIX}enable-hover`]: false,
23
+ [`${GEOSPATIAL_SDK_PREFIX}disable-click`]: true,
24
+ },
21
25
  });
22
26
  map.set(hoverLayerKey, hoverLayer);
23
27
  hoverLayer.setMap(map);
24
28
  // store original cursor style in order to change it later
25
29
  const originalCursorStyle = map.getTargetElement()?.style.cursor ?? "";
26
- const layerFilter = (layer) => layer !== hoverLayer && layer.get(`${GEOSPATIAL_SDK_PREFIX}enable-hover`);
30
+ const layerFilter = (layer) => layer.get(`${GEOSPATIAL_SDK_PREFIX}enable-hover`);
27
31
  const unKey = map.on("pointermove", async (event) => {
28
32
  // skip hit detection if the view is moving as it can have an impact on performance
29
33
  if (map.getView().getInteracting() || map.getView().getAnimating()) {
@@ -44,16 +48,33 @@ export function initHoverLayer(map) {
44
48
  return;
45
49
  }
46
50
  // add hovered feature to the layer
47
- const hovered = map.getFeaturesAtPixel(event.pixel, {
51
+ const hoveredFeatureResult = [];
52
+ map.forEachFeatureAtPixel(event.pixel, (feature, layer) => {
53
+ if (feature instanceof OlFeature) {
54
+ hoveredFeatureResult.push({ feature, layer });
55
+ return true;
56
+ }
57
+ }, {
48
58
  layerFilter,
49
59
  });
50
- hoveredSource.addFeature(hovered[0]);
60
+ if (hoveredFeatureResult.length === 0) {
61
+ return;
62
+ }
63
+ const { feature: firstFeature, layer: sourceLayer } = hoveredFeatureResult[0];
64
+ // Get the hoverStyle from the source layer, fallback to defaultHighlightStyle
65
+ const hoverStyle = sourceLayer.get(`${GEOSPATIAL_SDK_PREFIX}hover-style`) ??
66
+ defaultHighlightStyle;
67
+ // Apply the hover style to the layer (FlatStyleLike works on layers, not features)
68
+ hoverLayer.setStyle(hoverStyle);
69
+ hoveredSource.addFeature(firstFeature);
51
70
  // dispatch event if subscribed to
52
71
  if (map.get(FeaturesHoverEventType)) {
53
- const { features } = GEOJSON.writeFeaturesObject(hovered);
72
+ const featuresByLayer = await readFeaturesAtPixel(map, event, layerFilter);
73
+ const features = Array.from(featuresByLayer.values()).flat();
54
74
  map.dispatchEvent({
55
75
  type: FeaturesHoverEventType,
56
- features: features ?? [],
76
+ features,
77
+ featuresByLayer,
57
78
  });
58
79
  }
59
80
  });
@@ -0,0 +1,8 @@
1
+ import type OlMap from "ol/Map.js";
2
+ import VectorLayer from "ol/layer/Vector.js";
3
+ import VectorSource from "ol/source/Vector.js";
4
+ export declare function initSelectionLayer(map: OlMap): void;
5
+ export declare function getSelectionLayer(map: OlMap): VectorLayer<VectorSource>;
6
+ export declare function clearSelectionLayer(map: OlMap): void;
7
+ export declare function clearSelection(map: OlMap): void;
8
+ //# sourceMappingURL=feature-selection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature-selection.d.ts","sourceRoot":"","sources":["../../lib/map/feature-selection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,WAAW,CAAC;AACnC,OAAO,WAAW,MAAM,oBAAoB,CAAC;AAC7C,OAAO,YAAY,MAAM,qBAAqB,CAAC;AAU/C,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,KAAK,QAqE5C;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,KAAK,GAAG,WAAW,CAAC,YAAY,CAAC,CAEvE;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,KAAK,QAM7C;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,KAAK,QAQxC"}
@@ -0,0 +1,76 @@
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
+ import { defaultHighlightStyle } from "@geospatial-sdk/core";
5
+ import OlFeature from "ol/Feature.js";
6
+ import { unByKey } from "ol/Observable.js";
7
+ const selectionLayerKey = `${GEOSPATIAL_SDK_PREFIX}selection-layer`;
8
+ const unsubscribeKey = `${GEOSPATIAL_SDK_PREFIX}selection-unsub`;
9
+ export function initSelectionLayer(map) {
10
+ if (map.get(selectionLayerKey)) {
11
+ clearSelectionLayer(map);
12
+ }
13
+ // create layer & add on top of everything else
14
+ const selectionLayer = new VectorLayer({
15
+ source: new VectorSource({
16
+ features: [],
17
+ useSpatialIndex: false,
18
+ }),
19
+ style: defaultHighlightStyle,
20
+ });
21
+ map.set(selectionLayerKey, selectionLayer);
22
+ selectionLayer.setMap(map);
23
+ const layerFilter = (layer) => layer !== selectionLayer &&
24
+ layer.get(`${GEOSPATIAL_SDK_PREFIX}enable-selection`);
25
+ const unKey = map.on("click", async (event) => {
26
+ const selectedSource = selectionLayer.getSource();
27
+ selectedSource.clear(true);
28
+ // Check if there's a feature at the clicked pixel
29
+ const hasFeature = map.hasFeatureAtPixel(event.pixel, {
30
+ layerFilter,
31
+ });
32
+ if (!hasFeature) {
33
+ return;
34
+ }
35
+ // Find the selected feature and its source layer
36
+ const selectedFeatureResult = [];
37
+ map.forEachFeatureAtPixel(event.pixel, (feature, layer) => {
38
+ if (feature instanceof OlFeature) {
39
+ selectedFeatureResult.push({ feature, layer });
40
+ return true;
41
+ }
42
+ }, {
43
+ layerFilter,
44
+ });
45
+ if (selectedFeatureResult.length === 0) {
46
+ return;
47
+ }
48
+ const { feature: firstFeature, layer: sourceLayer } = selectedFeatureResult[0];
49
+ // Get the selectedStyle from the source layer, fallback to defaultHighlightStyle
50
+ const selectedStyle = sourceLayer.get(`${GEOSPATIAL_SDK_PREFIX}selected-style`) ??
51
+ defaultHighlightStyle;
52
+ // Apply the selected style to the layer (FlatStyleLike works on layers, not features)
53
+ selectionLayer.setStyle(selectedStyle);
54
+ selectedSource.addFeature(firstFeature);
55
+ });
56
+ map.set(unsubscribeKey, unKey);
57
+ }
58
+ export function getSelectionLayer(map) {
59
+ return map.get(selectionLayerKey);
60
+ }
61
+ export function clearSelectionLayer(map) {
62
+ const selectionLayer = getSelectionLayer(map);
63
+ selectionLayer.setMap(null);
64
+ selectionLayer.dispose();
65
+ map.set(selectionLayerKey, null);
66
+ unByKey(map.get(unsubscribeKey));
67
+ }
68
+ export function clearSelection(map) {
69
+ const selectionLayer = getSelectionLayer(map);
70
+ if (selectionLayer) {
71
+ const source = selectionLayer.getSource();
72
+ if (source) {
73
+ source.clear(true);
74
+ }
75
+ }
76
+ }
@@ -1,12 +1,13 @@
1
- import Map from "ol/Map.js";
1
+ import type { FeaturesByLayerIndex } from "@geospatial-sdk/core";
2
+ import { Coordinate } from "ol/coordinate.js";
3
+ import Layer from "ol/layer/Layer.js";
4
+ import OlMap from "ol/Map.js";
5
+ import type MapBrowserEvent from "ol/MapBrowserEvent.js";
2
6
  import { Pixel } from "ol/pixel.js";
3
- import type { Feature } from "geojson";
4
- import TileWMS from "ol/source/TileWMS.js";
5
7
  import ImageWMS from "ol/source/ImageWMS.js";
6
- import { Coordinate } from "ol/coordinate.js";
7
- import { MapBrowserEvent } from "ol";
8
- export declare function getFeaturesFromVectorSources(olMap: Map, pixel: Pixel): Feature[];
9
- export declare function getGFIUrl(source: TileWMS | ImageWMS, map: Map, coordinate: Coordinate): string | null;
10
- export declare function getFeaturesFromWmsSources(olMap: Map, coordinate: Coordinate): Promise<Feature[]>;
11
- export declare function readFeaturesAtPixel(map: Map, event: MapBrowserEvent<PointerEvent>): Promise<Feature<import("geojson").Geometry, import("geojson").GeoJsonProperties>[]>;
8
+ import TileWMS from "ol/source/TileWMS.js";
9
+ export declare function getFeaturesFromVectorSources(olMap: OlMap, pixel: Pixel, layerFilter?: (layer: Layer) => boolean): FeaturesByLayerIndex;
10
+ export declare function getGFIUrl(source: TileWMS | ImageWMS, map: OlMap, coordinate: Coordinate): string | null;
11
+ export declare function getFeaturesFromWmsSources(olMap: OlMap, coordinate: Coordinate, layerFilter?: (layer: Layer) => boolean): Promise<FeaturesByLayerIndex>;
12
+ export declare function readFeaturesAtPixel(map: OlMap, event: MapBrowserEvent<PointerEvent>, layerFilter?: (layer: Layer) => boolean): Promise<FeaturesByLayerIndex>;
12
13
  //# sourceMappingURL=get-features.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-features.d.ts","sourceRoot":"","sources":["../../lib/map/get-features.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,MAAM,WAAW,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAqB,MAAM,SAAS,CAAC;AAE1D,OAAO,OAAO,MAAM,sBAAsB,CAAC;AAC3C,OAAO,QAAQ,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAIrC,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,GAAG,EACV,KAAK,EAAE,KAAK,GACX,OAAO,EAAE,CAOX;AAED,wBAAgB,SAAS,CACvB,MAAM,EAAE,OAAO,GAAG,QAAQ,EAC1B,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,GACrB,MAAM,GAAG,IAAI,CAWf;AAED,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,GAAG,EACV,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,OAAO,EAAE,CAAC,CA2BpB;AAOD,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,eAAe,CAAC,YAAY,CAAC,uFAMrC"}
1
+ {"version":3,"file":"get-features.d.ts","sourceRoot":"","sources":["../../lib/map/get-features.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAGjE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,OAAO,KAAK,MAAM,mBAAmB,CAAC;AACtC,OAAO,KAAK,MAAM,WAAW,CAAC;AAC9B,OAAO,KAAK,eAAe,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,QAAQ,MAAM,uBAAuB,CAAC;AAC7C,OAAO,OAAO,MAAM,sBAAsB,CAAC;AAI3C,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,KAAK,EACZ,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,GACtC,oBAAoB,CAyBtB;AAED,wBAAgB,SAAS,CACvB,MAAM,EAAE,OAAO,GAAG,QAAQ,EAC1B,GAAG,EAAE,KAAK,EACV,UAAU,EAAE,UAAU,GACrB,MAAM,GAAG,IAAI,CAWf;AAED,wBAAsB,yBAAyB,CAC7C,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,UAAU,EACtB,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,GACtC,OAAO,CAAC,oBAAoB,CAAC,CAsC/B;AAOD,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,KAAK,EACV,KAAK,EAAE,eAAe,CAAC,YAAY,CAAC,EACpC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,GACtC,OAAO,CAAC,oBAAoB,CAAC,CAS/B"}
@@ -1,16 +1,28 @@
1
+ import throttle from "lodash.throttle";
1
2
  import GeoJSON from "ol/format/GeoJSON.js";
2
- import TileWMS from "ol/source/TileWMS.js";
3
- import ImageWMS from "ol/source/ImageWMS.js";
4
3
  import Layer from "ol/layer/Layer.js";
5
- import throttle from "lodash.throttle";
4
+ import ImageWMS from "ol/source/ImageWMS.js";
5
+ import TileWMS from "ol/source/TileWMS.js";
6
6
  const GEOJSON = new GeoJSON();
7
- export function getFeaturesFromVectorSources(olMap, pixel) {
8
- const olFeatures = olMap.getFeaturesAtPixel(pixel);
9
- const { features } = GEOJSON.writeFeaturesObject(olFeatures);
10
- if (!features) {
11
- return [];
12
- }
13
- return features;
7
+ export function getFeaturesFromVectorSources(olMap, pixel, layerFilter) {
8
+ const result = new Map();
9
+ const layerArray = olMap.getLayers().getArray();
10
+ olMap.forEachFeatureAtPixel(pixel, (feature, layer) => {
11
+ // can happen for unmanaged layer (i.e. hover layer)
12
+ if (layer === null) {
13
+ return null;
14
+ }
15
+ const layerIndex = layerArray.indexOf(layer);
16
+ if (!result.has(layerIndex)) {
17
+ result.set(layerIndex, []);
18
+ }
19
+ result.get(layerIndex).push(GEOJSON.writeFeatureObject(feature, {
20
+ featureProjection: olMap.getView().getProjection(),
21
+ dataProjection: "EPSG:4326",
22
+ }));
23
+ return null;
24
+ }, { layerFilter });
25
+ return result;
14
26
  }
15
27
  export function getGFIUrl(source, map, coordinate) {
16
28
  const view = map.getView();
@@ -22,29 +34,46 @@ export function getGFIUrl(source, map, coordinate) {
22
34
  };
23
35
  return (source.getFeatureInfoUrl(coordinate, resolution, projection, params) ?? null);
24
36
  }
25
- export function getFeaturesFromWmsSources(olMap, coordinate) {
26
- const wmsSources = olMap
27
- .getLayers()
28
- .getArray()
29
- .filter((layer) => layer instanceof Layer &&
30
- (layer.getSource() instanceof TileWMS ||
31
- layer.getSource() instanceof ImageWMS))
32
- .map((layer) => layer.getSource());
33
- if (!wmsSources.length) {
34
- return Promise.resolve([]);
37
+ export async function getFeaturesFromWmsSources(olMap, coordinate, layerFilter) {
38
+ const result = new Map();
39
+ const layerArray = olMap.getLayers().getArray();
40
+ const hasWms = layerArray.some((layer) => {
41
+ const source = layer instanceof Layer ? layer.getSource() : null;
42
+ return source instanceof TileWMS || source instanceof ImageWMS;
43
+ });
44
+ if (!hasWms) {
45
+ return result;
35
46
  }
36
- const gfiUrls = wmsSources.reduce((urls, source) => {
47
+ const gfiPromises = layerArray.map((layer) => {
48
+ if (!(layer instanceof Layer)) {
49
+ return null;
50
+ }
51
+ if (layerFilter && !layerFilter(layer)) {
52
+ return null;
53
+ }
54
+ const source = layer.getSource();
55
+ if (!(source instanceof TileWMS) && !(source instanceof ImageWMS)) {
56
+ return null;
57
+ }
37
58
  const gfiUrl = getGFIUrl(source, olMap, coordinate);
38
- return gfiUrl ? [...urls, gfiUrl] : urls;
39
- }, []);
40
- return Promise.all(gfiUrls.map((url) => fetch(url)
41
- .then((response) => response.json())
42
- .then((collection) => collection.features))).then((features) => features.flat());
59
+ return gfiUrl
60
+ ? fetch(gfiUrl)
61
+ .then((response) => response.json())
62
+ .then((collection) => collection.features)
63
+ : null;
64
+ });
65
+ const responses = await Promise.all(gfiPromises);
66
+ responses.forEach((features, index) => {
67
+ if (features !== null && features.length > 0) {
68
+ result.set(index, features);
69
+ }
70
+ });
71
+ return result;
43
72
  }
44
73
  const getFeaturesFromWmsSourcesThrottled = throttle(getFeaturesFromWmsSources, 250);
45
- export async function readFeaturesAtPixel(map, event) {
46
- return [
47
- ...getFeaturesFromVectorSources(map, event.pixel),
48
- ...(await getFeaturesFromWmsSourcesThrottled(map, event.coordinate)),
49
- ];
74
+ export async function readFeaturesAtPixel(map, event, layerFilter) {
75
+ return new Map([
76
+ ...getFeaturesFromVectorSources(map, event.pixel, layerFilter),
77
+ ...(await getFeaturesFromWmsSourcesThrottled(map, event.coordinate, layerFilter)),
78
+ ]);
50
79
  }
@@ -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;AAmBtC;;;;;;;;;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,QA2CrC"}
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,QAuDrC"}
@@ -8,7 +8,9 @@ const UPDATABLE_PROPERTIES = [
8
8
  "extras",
9
9
  "version",
10
10
  "enableHover",
11
+ "disableClick",
11
12
  "style",
13
+ "hoverStyle",
12
14
  // TODO (when available) "zIndex"
13
15
  ];
14
16
  /**
@@ -61,6 +63,12 @@ export function updateLayerProperties(layerModel, olLayer, previousLayerModel) {
61
63
  if (shouldApplyProperty("enableHover")) {
62
64
  olLayer.set(`${GEOSPATIAL_SDK_PREFIX}enable-hover`, layerModel.enableHover);
63
65
  }
66
+ if (shouldApplyProperty("hoverStyle")) {
67
+ olLayer.set(`${GEOSPATIAL_SDK_PREFIX}hover-style`, layerModel.hoverStyle);
68
+ }
69
+ if (shouldApplyProperty("disableClick")) {
70
+ olLayer.set(`${GEOSPATIAL_SDK_PREFIX}disable-click`, layerModel.disableClick);
71
+ }
64
72
  if (shouldApplyProperty("style") &&
65
73
  "setStyle" in olLayer) {
66
74
  olLayer.setStyle(layerModel.style);
@@ -0,0 +1,4 @@
1
+ import Map from "ol/Map.js";
2
+ import { MapEventsByType } from "@geospatial-sdk/core";
3
+ export declare function listen<T extends keyof MapEventsByType>(map: Map, eventType: T, callback: (event: MapEventsByType[T]) => void): void;
4
+ //# sourceMappingURL=listen.d.ts.map
@@ -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,EAKL,eAAe,EAShB,MAAM,sBAAsB,CAAC;AA6B9B,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"}
@@ -0,0 +1,83 @@
1
+ import { toLonLat } from "ol/proj.js";
2
+ import { FeaturesClickEventType, FeaturesHoverEventType, MapClickEventType, MapExtentChangeEventType, MapLayerStateChangeEventType, MapStateChangeEventType, MapViewStateChangeEventType, SourceLoadErrorType, } from "@geospatial-sdk/core";
3
+ import { GEOSPATIAL_SDK_PREFIX } from "./constants.js";
4
+ import { registerFeatureClickEvent, registerFeatureHoverEvent, registerMapViewStateChangeEvent, } 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
+ // TODO: registerMapLayerStateChangeEvent(map);
38
+ addEventListener(map, eventType, callback);
39
+ break;
40
+ case MapStateChangeEventType:
41
+ // TODO: registerMapStateChangeEvent(map);
42
+ addEventListener(map, eventType, callback);
43
+ break;
44
+ /**
45
+ * DEPRECATED
46
+ */
47
+ case MapExtentChangeEventType:
48
+ registerMapViewStateChangeEvent(map);
49
+ map.on(`${GEOSPATIAL_SDK_PREFIX}${MapViewStateChangeEventType}`, (event) => callback({
50
+ type: MapExtentChangeEventType,
51
+ extent: event.viewState.extent,
52
+ }));
53
+ break;
54
+ case SourceLoadErrorType: {
55
+ const errorCallback = (event) => {
56
+ callback(event);
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
+ });
78
+ break;
79
+ }
80
+ default:
81
+ throw new Error(`Unrecognized event type: ${eventType}`);
82
+ }
83
+ }
@@ -1,4 +1,4 @@
1
- import Map from "ol/Map.js";
2
1
  import { MapEventsByType } from "@geospatial-sdk/core";
2
+ import Map from "ol/Map.js";
3
3
  export declare function listen<T extends keyof MapEventsByType>(map: Map, eventType: T, callback: (event: MapEventsByType[T]) => void): void;
4
4
  //# 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,GAA4B,MAAM,WAAW,CAAC;AACrD,OAAO,EAIL,eAAe,EAGhB,MAAM,sBAAsB,CAAC;AA4D9B,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,QA0E9C"}
1
+ {"version":3,"file":"register-events.d.ts","sourceRoot":"","sources":["../../lib/map/register-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,eAAe,EAGhB,MAAM,sBAAsB,CAAC;AAM9B,OAAO,GAA4B,MAAM,WAAW,CAAC;AA+DrD,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,QA0E9C"}
@@ -1,15 +1,20 @@
1
1
  import { FeaturesClickEventType, FeaturesHoverEventType, MapClickEventType, MapExtentChangeEventType, SourceLoadErrorType, } from "@geospatial-sdk/core";
2
- import { toLonLat, transformExtent } from "ol/proj.js";
3
2
  import { equals } from "ol/extent.js";
3
+ import { toLonLat, transformExtent } from "ol/proj.js";
4
+ import { GEOSPATIAL_SDK_PREFIX } from "./constants.js";
4
5
  import { readFeaturesAtPixel } from "./get-features.js";
5
6
  function registerFeatureClickEvent(map) {
6
7
  if (map.get(FeaturesClickEventType))
7
8
  return;
9
+ // Filter to only query layers with enableSelection
10
+ const layerFilter = (layer) => !layer.get(`${GEOSPATIAL_SDK_PREFIX}disable-click`);
8
11
  map.on("click", async (event) => {
9
- const features = await readFeaturesAtPixel(map, event);
12
+ const featuresByLayer = await readFeaturesAtPixel(map, event, layerFilter);
13
+ const features = Array.from(featuresByLayer.values()).flat();
10
14
  map.dispatchEvent({
11
15
  type: FeaturesClickEventType,
12
16
  features,
17
+ featuresByLayer,
13
18
  });
14
19
  });
15
20
  map.set(FeaturesClickEventType, true);
@@ -0,0 +1,8 @@
1
+ import Map from "ol/Map.js";
2
+ import { ResolvedMapViewState } from "@geospatial-sdk/core";
3
+ /**
4
+ * Reads the current view state of the map.
5
+ * @param map
6
+ */
7
+ export declare function readMapViewState(map: Map): ResolvedMapViewState;
8
+ //# sourceMappingURL=resolved-map-state.d.ts.map
@@ -0,0 +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,EAAU,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAIpE;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,GAAG,GAAG,oBAAoB,CAgB/D"}
@@ -0,0 +1,27 @@
1
+ import { transform as transformCoordinate, transformExtent } from "ol/proj.js";
2
+ /**
3
+ * This magic value is generally used across OGC services as a reasonable approximation for most displays
4
+ */
5
+ const PIXEL_SIZE_MM = 0.28;
6
+ /**
7
+ * Reads the current view state of the map.
8
+ * @param map
9
+ */
10
+ export function readMapViewState(map) {
11
+ const view = map.getView();
12
+ const projection = view.getProjection();
13
+ const extent = transformExtent(view.calculateExtent(), projection, "EPSG:4326");
14
+ const center = transformCoordinate(view.getCenter() ?? [0, 0], projection, "EPSG:4326");
15
+ const resolution = view.getResolution() ?? 1;
16
+ const metersPerUnit = projection.getMetersPerUnit() ?? 1;
17
+ const scaleDenominator = metersPerUnit * resolution * (1000 / PIXEL_SIZE_MM);
18
+ const bearing = view.getRotation() * (180 / Math.PI) + 90; // by default, bearing is North
19
+ return {
20
+ center,
21
+ extent,
22
+ resolution,
23
+ scaleDenominator,
24
+ bearing,
25
+ };
26
+ }
27
+ export function processLayerEvent(map, layer) { }
@@ -0,0 +1,16 @@
1
+ import { Style } from "ol/style.js";
2
+ import { StyleFunction } from "ol/style/Style.js";
3
+ export interface CreateStyleOptions {
4
+ color: string;
5
+ isFocused?: boolean;
6
+ }
7
+ export interface StyleByGeometryType {
8
+ line: Style | Style[];
9
+ polygon: Style | Style[];
10
+ point: Style | Style[];
11
+ }
12
+ export declare function createGeometryStyles(options: CreateStyleOptions): StyleByGeometryType;
13
+ export declare function createStyleFunction(styleByGeometryType: StyleByGeometryType): StyleFunction;
14
+ export declare const defaultStyle: StyleFunction;
15
+ export declare const defaultHighlightStyle: StyleFunction;
16
+ //# sourceMappingURL=styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../lib/map/styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIlD,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,KAAK,GAAG,KAAK,EAAE,CAAC;IACtB,OAAO,EAAE,KAAK,GAAG,KAAK,EAAE,CAAC;IACzB,KAAK,EAAE,KAAK,GAAG,KAAK,EAAE,CAAC;CACxB;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,kBAAkB,GAC1B,mBAAmB,CA4CrB;AAED,wBAAgB,mBAAmB,CACjC,mBAAmB,EAAE,mBAAmB,GACvC,aAAa,CAmBf;AAMD,eAAO,MAAM,YAAY,eAIxB,CAAC;AAEF,eAAO,MAAM,qBAAqB,eAKjC,CAAC"}
@@ -0,0 +1,77 @@
1
+ import { Circle, Fill, Stroke, Style } from "ol/style.js";
2
+ import chroma from "chroma-js";
3
+ export function createGeometryStyles(options) {
4
+ const { color, isFocused } = options;
5
+ const zIndex = isFocused ? 10 : undefined;
6
+ return {
7
+ polygon: new Style({
8
+ fill: new Fill({
9
+ color: computeTransparentFillColor(color),
10
+ }),
11
+ stroke: new Stroke({
12
+ color: "white",
13
+ width: 2,
14
+ }),
15
+ zIndex,
16
+ }),
17
+ point: new Style({
18
+ image: new Circle({
19
+ fill: new Fill({
20
+ color,
21
+ }),
22
+ stroke: new Stroke({
23
+ color: "white",
24
+ width: isFocused ? 3 : 2,
25
+ }),
26
+ radius: isFocused ? 8 : 7,
27
+ }),
28
+ zIndex,
29
+ }),
30
+ line: [
31
+ new Style({
32
+ stroke: new Stroke({
33
+ color: "white",
34
+ width: isFocused ? 8 : 6,
35
+ }),
36
+ zIndex,
37
+ }),
38
+ new Style({
39
+ stroke: new Stroke({
40
+ color,
41
+ width: isFocused ? 3 : 2,
42
+ }),
43
+ zIndex,
44
+ }),
45
+ ],
46
+ };
47
+ }
48
+ export function createStyleFunction(styleByGeometryType) {
49
+ return (feature) => {
50
+ const geometryType = feature?.getGeometry()?.getType();
51
+ switch (geometryType) {
52
+ case "LinearRing":
53
+ case "LineString":
54
+ case "MultiLineString":
55
+ return styleByGeometryType.line;
56
+ case "Point":
57
+ case "MultiPoint":
58
+ return styleByGeometryType.point;
59
+ case "Circle":
60
+ case "Polygon":
61
+ case "MultiPolygon":
62
+ return styleByGeometryType.polygon;
63
+ default:
64
+ return styleByGeometryType.point;
65
+ }
66
+ };
67
+ }
68
+ function computeTransparentFillColor(color, alpha = 0.25) {
69
+ return chroma(color).alpha(alpha).css();
70
+ }
71
+ export const defaultStyle = createStyleFunction(createGeometryStyles({
72
+ color: "blue",
73
+ }));
74
+ export const defaultHighlightStyle = createStyleFunction(createGeometryStyles({
75
+ color: "red",
76
+ isFocused: true,
77
+ }));
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=resolved-map-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolved-map-state.d.ts","sourceRoot":"","sources":["../../lib/resolved-state/resolved-map-state.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export {};