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

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 (37) hide show
  1. package/dist/map/constants.d.ts +2 -0
  2. package/dist/map/constants.d.ts.map +1 -0
  3. package/dist/map/constants.js +1 -0
  4. package/dist/map/create-map.d.ts.map +1 -1
  5. package/dist/map/create-map.js +3 -2
  6. package/dist/map/feature-hover.d.ts +7 -0
  7. package/dist/map/feature-hover.d.ts.map +1 -0
  8. package/dist/map/feature-hover.js +71 -0
  9. package/dist/map/get-features.d.ts +12 -0
  10. package/dist/map/get-features.d.ts.map +1 -0
  11. package/dist/map/get-features.js +50 -0
  12. package/dist/map/index.d.ts +0 -1
  13. package/dist/map/index.d.ts.map +1 -1
  14. package/dist/map/index.js +0 -1
  15. package/dist/map/layer-update.d.ts.map +1 -1
  16. package/dist/map/layer-update.js +10 -0
  17. package/dist/map/register-events.d.ts +0 -8
  18. package/dist/map/register-events.d.ts.map +1 -1
  19. package/dist/map/register-events.js +1 -57
  20. package/lib/map/constants.ts +1 -0
  21. package/lib/map/create-map.test.ts +16 -13
  22. package/lib/map/create-map.ts +3 -1
  23. package/lib/map/feature-hover.ts +96 -0
  24. package/lib/map/get-features.test.ts +109 -0
  25. package/lib/map/get-features.ts +89 -0
  26. package/lib/map/handle-errors.test.ts +0 -1
  27. package/lib/map/index.ts +0 -1
  28. package/lib/map/layer-update.test.ts +27 -1
  29. package/lib/map/layer-update.ts +27 -3
  30. package/lib/map/register-events.test.ts +41 -85
  31. package/lib/map/register-events.ts +2 -97
  32. package/package.json +5 -5
  33. package/dist/map/styles.d.ts +0 -16
  34. package/dist/map/styles.d.ts.map +0 -1
  35. package/dist/map/styles.js +0 -77
  36. package/lib/map/styles.test.ts +0 -217
  37. package/lib/map/styles.ts +0 -103
@@ -0,0 +1,89 @@
1
+ import GeoJSON from "ol/format/GeoJSON.js";
2
+ import Map from "ol/Map.js";
3
+ import { Pixel } from "ol/pixel.js";
4
+ import type { Feature, FeatureCollection } from "geojson";
5
+ import OlFeature from "ol/Feature.js";
6
+ import TileWMS from "ol/source/TileWMS.js";
7
+ import ImageWMS from "ol/source/ImageWMS.js";
8
+ import { Coordinate } from "ol/coordinate.js";
9
+ import Layer from "ol/layer/Layer.js";
10
+ import throttle from "lodash.throttle";
11
+ import { MapBrowserEvent } from "ol";
12
+
13
+ const GEOJSON = new GeoJSON();
14
+
15
+ export function getFeaturesFromVectorSources(
16
+ olMap: Map,
17
+ pixel: Pixel,
18
+ ): Feature[] {
19
+ const olFeatures = olMap.getFeaturesAtPixel(pixel);
20
+ const { features } = GEOJSON.writeFeaturesObject(olFeatures as OlFeature[]);
21
+ if (!features) {
22
+ return [];
23
+ }
24
+ return features;
25
+ }
26
+
27
+ export function getGFIUrl(
28
+ source: TileWMS | ImageWMS,
29
+ map: Map,
30
+ coordinate: Coordinate,
31
+ ): string | null {
32
+ const view = map.getView();
33
+ const projection = view.getProjection();
34
+ const resolution = view.getResolution() as number;
35
+ const params = {
36
+ ...source.getParams(),
37
+ INFO_FORMAT: "application/json",
38
+ };
39
+ return (
40
+ source.getFeatureInfoUrl(coordinate, resolution, projection, params) ?? null
41
+ );
42
+ }
43
+
44
+ export function getFeaturesFromWmsSources(
45
+ olMap: Map,
46
+ coordinate: Coordinate,
47
+ ): Promise<Feature[]> {
48
+ const wmsSources: (ImageWMS | TileWMS)[] = olMap
49
+ .getLayers()
50
+ .getArray()
51
+ .filter(
52
+ (layer): layer is Layer<ImageWMS | TileWMS> =>
53
+ layer instanceof Layer &&
54
+ (layer.getSource() instanceof TileWMS ||
55
+ layer.getSource() instanceof ImageWMS),
56
+ )
57
+ .map((layer) => layer.getSource()!);
58
+
59
+ if (!wmsSources.length) {
60
+ return Promise.resolve([]);
61
+ }
62
+
63
+ const gfiUrls = wmsSources.reduce((urls, source) => {
64
+ const gfiUrl = getGFIUrl(source, olMap, coordinate);
65
+ return gfiUrl ? [...urls, gfiUrl] : urls;
66
+ }, [] as string[]);
67
+ return Promise.all(
68
+ gfiUrls.map((url) =>
69
+ fetch(url)
70
+ .then((response) => response.json())
71
+ .then((collection: FeatureCollection) => collection.features),
72
+ ),
73
+ ).then((features) => features.flat());
74
+ }
75
+
76
+ const getFeaturesFromWmsSourcesThrottled = throttle(
77
+ getFeaturesFromWmsSources,
78
+ 250,
79
+ );
80
+
81
+ export async function readFeaturesAtPixel(
82
+ map: Map,
83
+ event: MapBrowserEvent<PointerEvent>,
84
+ ) {
85
+ return [
86
+ ...getFeaturesFromVectorSources(map, event.pixel),
87
+ ...(await getFeaturesFromWmsSourcesThrottled(map, event.coordinate)),
88
+ ];
89
+ }
@@ -5,7 +5,6 @@ import {
5
5
  handleTileError,
6
6
  tileLoadErrorCatchFunction,
7
7
  } from "./handle-errors.js";
8
- import { describe } from "node:test";
9
8
  import TileLayer from "ol/layer/Tile.js";
10
9
  import VectorLayer from "ol/layer/Vector.js";
11
10
  import { EndpointError } from "@camptocamp/ogc-client";
package/lib/map/index.ts CHANGED
@@ -3,7 +3,6 @@
3
3
  * @packageDocumentation
4
4
  */
5
5
 
6
- export * from "./styles.js";
7
6
  export { createMapFromContext, resetMapFromContext } from "./create-map.js";
8
7
  export { applyContextDiffToMap } from "./apply-context-diff.js";
9
8
  export { listen } from "./register-events.js";
@@ -5,8 +5,12 @@ import {
5
5
  import { MapContextLayer } from "@geospatial-sdk/core";
6
6
  import Layer from "ol/layer/Layer.js";
7
7
  import { Source } from "ol/source.js";
8
- import { SAMPLE_LAYER1 } from "@geospatial-sdk/core/fixtures/map-context.fixtures.js";
8
+ import {
9
+ SAMPLE_LAYER1,
10
+ SAMPLE_LAYER3,
11
+ } from "@geospatial-sdk/core/fixtures/map-context.fixtures.js";
9
12
  import VectorSource from "ol/source/Vector.js";
13
+ import VectorLayer from "ol/layer/Vector.js";
10
14
 
11
15
  describe("Layer update utils", () => {
12
16
  describe("canDoIncrementalUpdate", () => {
@@ -111,5 +115,27 @@ describe("Layer update utils", () => {
111
115
  expect(olSource.setAttributions).toHaveBeenCalledWith("hello world");
112
116
  expect(olLayer.set).toHaveBeenCalledWith("label", "Test Layer");
113
117
  });
118
+
119
+ it("applies properties specific to vector layers without recreating them", async () => {
120
+ // mocking a vector layer
121
+ (olLayer as VectorLayer).setStyle = vi.fn();
122
+
123
+ const layerModel = {
124
+ ...SAMPLE_LAYER3,
125
+ style: {
126
+ "circle-fill-color": "blue",
127
+ },
128
+ enableHover: true,
129
+ };
130
+ const prevLayerModel = SAMPLE_LAYER3;
131
+ updateLayerProperties(layerModel, olLayer, prevLayerModel);
132
+ expect((olLayer as VectorLayer).setStyle).toHaveBeenCalledWith(
133
+ layerModel.style,
134
+ );
135
+ expect(olLayer.set).toHaveBeenCalledWith(
136
+ "--geospatial-sdk-enable-hover",
137
+ true,
138
+ );
139
+ });
114
140
  });
115
141
  });
@@ -1,14 +1,24 @@
1
1
  import { getHash, MapContextLayer } from "@geospatial-sdk/core";
2
- import { MapContextBaseLayer } from "@geospatial-sdk/core/lib/model/map-context.js";
2
+ import {
3
+ MapContextBaseLayer,
4
+ MapContextLayerVector,
5
+ } from "@geospatial-sdk/core/lib/model/map-context.js";
3
6
  import Layer from "ol/layer/Layer.js";
7
+ import { GEOSPATIAL_SDK_PREFIX } from "./constants.js";
8
+ import VectorLayer from "ol/layer/Vector.js";
4
9
 
5
- const UPDATABLE_PROPERTIES: (keyof MapContextBaseLayer)[] = [
10
+ const UPDATABLE_PROPERTIES: (
11
+ | keyof MapContextBaseLayer
12
+ | keyof MapContextLayerVector
13
+ )[] = [
6
14
  "opacity",
7
15
  "visibility",
8
16
  "label",
9
17
  "attributions",
10
18
  "extras",
11
19
  "version",
20
+ "enableHover",
21
+ "style",
12
22
  // TODO (when available) "zIndex"
13
23
  ];
14
24
 
@@ -43,7 +53,7 @@ export function updateLayerProperties(
43
53
  olLayer: Layer,
44
54
  previousLayerModel?: MapContextLayer,
45
55
  ) {
46
- function shouldApplyProperty(prop: keyof MapContextBaseLayer): boolean {
56
+ function shouldApplyProperty(prop: keyof MapContextLayer): boolean {
47
57
  // if the new layer model does not define that property, skip it
48
58
  // (setting or resetting it to a default value would be counter-intuitive)
49
59
  if (!(prop in layerModel) || typeof layerModel[prop] === "undefined")
@@ -69,5 +79,19 @@ export function updateLayerProperties(
69
79
  if (shouldApplyProperty("label")) {
70
80
  olLayer.set("label", layerModel.label);
71
81
  }
82
+ if (shouldApplyProperty("enableHover" as keyof MapContextLayer)) {
83
+ olLayer.set(
84
+ `${GEOSPATIAL_SDK_PREFIX}enable-hover`,
85
+ (layerModel as MapContextLayerVector).enableHover,
86
+ );
87
+ }
88
+ if (
89
+ shouldApplyProperty("style" as keyof MapContextLayer) &&
90
+ "setStyle" in olLayer
91
+ ) {
92
+ (olLayer as VectorLayer).setStyle(
93
+ (layerModel as MapContextLayerVector).style,
94
+ );
95
+ }
72
96
  // TODO: z-index
73
97
  }
@@ -1,55 +1,45 @@
1
1
  import Map from "ol/Map.js";
2
2
  import { Mock } from "vitest";
3
- import {
4
- getFeaturesFromVectorSources,
5
- getFeaturesFromWmsSources,
6
- getGFIUrl,
7
- listen,
8
- } from "./register-events.js";
9
- import { Collection, MapBrowserEvent, Object as BaseObject } from "ol";
3
+ import { listen } from "./register-events.js";
4
+ import { MapBrowserEvent, Object as BaseObject } from "ol";
10
5
  import View from "ol/View.js";
11
6
  import { toLonLat } from "ol/proj.js";
12
- import TileWMS from "ol/source/TileWMS.js";
13
- import VectorSource from "ol/source/Vector.js";
14
- import VectorLayer from "ol/layer/Vector.js";
15
7
  import Point from "ol/geom/Point.js";
16
- import TileLayer from "ol/layer/Tile.js";
17
8
  import OlFeature from "ol/Feature.js";
9
+ import { FeaturesHoverEventType } from "@geospatial-sdk/core";
10
+ import BaseEvent from "ol/events/Event.js";
11
+
12
+ vi.mock("./get-features.js", () => ({
13
+ readFeaturesAtPixel() {
14
+ return [
15
+ {
16
+ geometry: {
17
+ coordinates: [100, 200],
18
+ type: "Point",
19
+ },
20
+ properties: null,
21
+ type: "Feature",
22
+ },
23
+ {
24
+ geometry: null,
25
+ properties: {
26
+ density: 123,
27
+ },
28
+ type: "Feature",
29
+ },
30
+ ];
31
+ },
32
+ }));
18
33
 
19
34
  const EXPECTED_MAP_EXTENT_EPSG4326 = [
20
35
  -0.0035932611364780857, -0.0026949458513598756, 0.0035932611364780857,
21
36
  0.0026949458513740865,
22
37
  ];
23
38
 
24
- const gfiResult = {
25
- type: "Feature",
26
- properties: {
27
- density: 123,
28
- },
29
- geometry: null,
30
- };
31
- function createWmsSource() {
32
- return new TileWMS({
33
- url: "http://my.service.org/wms?SERVICE=WMS",
34
- params: {
35
- LAYERS: "layerName",
36
- FORMAT: "image/png",
37
- TRANSPARENT: true,
38
- },
39
- });
40
- }
41
39
  function createMap(): Map {
42
- const wmsLayer = new TileLayer({
43
- source: createWmsSource(),
44
- });
45
40
  const feature = new OlFeature({
46
41
  geometry: new Point([100, 200]),
47
42
  });
48
- const vectorLayer = new VectorLayer({
49
- source: new VectorSource({
50
- features: [feature],
51
- }),
52
- });
53
43
  const view = new View({
54
44
  projection: "EPSG:3857",
55
45
  resolution: 1,
@@ -58,12 +48,26 @@ function createMap(): Map {
58
48
  const map = new BaseObject() as Map;
59
49
  Object.defineProperties(map, {
60
50
  getView: { value: vi.fn(() => view) },
61
- getLayers: { value: vi.fn(() => new Collection([wmsLayer, vectorLayer])) },
62
51
  getEventPixel: { value: vi.fn(() => [10, 10]) },
63
52
  getCoordinateFromPixel: { value: vi.fn(() => [123, 123]) },
64
53
  getFeaturesAtPixel: { value: vi.fn(() => [feature]) },
65
54
  getSize: { value: vi.fn(() => [800, 600]) },
66
55
  });
56
+ // simulate hover feature initialization
57
+ map.on("pointermove", () => {
58
+ map.dispatchEvent({
59
+ type: FeaturesHoverEventType,
60
+ features: [
61
+ {
62
+ geometry: null,
63
+ properties: {
64
+ density: 123,
65
+ },
66
+ type: "Feature",
67
+ },
68
+ ],
69
+ } as unknown as BaseEvent);
70
+ });
67
71
  return map;
68
72
  }
69
73
  function createMapEvent(map: Map, type: string) {
@@ -82,48 +86,8 @@ describe("event registration", () => {
82
86
  let map: Map;
83
87
  beforeEach(() => {
84
88
  map = createMap();
85
- vi.spyOn(global, "fetch").mockImplementation(() =>
86
- Promise.resolve({
87
- ok: true,
88
- json: () => Promise.resolve({ features: [gfiResult] }),
89
- } as Response),
90
- );
91
89
  vi.useFakeTimers();
92
90
  });
93
- describe("getFeaturesFromVectorSources", () => {
94
- it("returns an array of features", () => {
95
- const features = getFeaturesFromVectorSources(map, [0, 0]);
96
- expect(features).toEqual([
97
- {
98
- geometry: {
99
- coordinates: [100, 200],
100
- type: "Point",
101
- },
102
- properties: null,
103
- type: "Feature",
104
- },
105
- ]);
106
- });
107
- });
108
- describe("getGFIUrl", () => {
109
- let url: string;
110
- const coordinate = [-182932.49329334166, 6125319.813853541];
111
- beforeEach(() => {
112
- const wmsSource = createWmsSource();
113
- url = getGFIUrl(wmsSource, map, coordinate) as string;
114
- });
115
- it("returns true", () => {
116
- expect(url).toEqual(
117
- "http://my.service.org/wms?SERVICE=WMS&REQUEST=GetFeatureInfo&QUERY_LAYERS=layerName&SERVICE=WMS&VERSION=1.3.0&FORMAT=image%2Fpng&STYLES=&TRANSPARENT=true&LAYERS=layerName&INFO_FORMAT=application%2Fjson&I=176&J=31&WIDTH=256&HEIGHT=256&CRS=EPSG%3A3857&BBOX=-183143.11977128312%2C6125051.950547744%2C-182837.37165814242%2C6125357.698660884",
118
- );
119
- });
120
- });
121
- describe("getFeaturesFromWmsSources", () => {
122
- it("queries the WMS sources", async () => {
123
- const features = await getFeaturesFromWmsSources(map, [0, 0]);
124
- expect(features).toEqual([gfiResult]);
125
- });
126
- });
127
91
  describe("features hover event", () => {
128
92
  let callback: Mock;
129
93
  beforeEach(async () => {
@@ -136,14 +100,6 @@ describe("event registration", () => {
136
100
  expect(callback).toHaveBeenCalledWith({
137
101
  type: "features-hover",
138
102
  features: [
139
- {
140
- geometry: {
141
- coordinates: [100, 200],
142
- type: "Point",
143
- },
144
- properties: null,
145
- type: "Feature",
146
- },
147
103
  {
148
104
  geometry: null,
149
105
  properties: {
@@ -3,102 +3,16 @@ import {
3
3
  FeaturesClickEventType,
4
4
  FeaturesHoverEventType,
5
5
  MapClickEventType,
6
- MapExtentChangeEventType,
7
6
  MapEventsByType,
7
+ MapExtentChangeEventType,
8
8
  SourceLoadErrorType,
9
9
  } from "@geospatial-sdk/core";
10
10
  import { toLonLat, transformExtent } from "ol/proj.js";
11
- import GeoJSON from "ol/format/GeoJSON.js";
12
- import OlFeature from "ol/Feature.js";
13
11
  import BaseEvent from "ol/events/Event.js";
14
- import { MapBrowserEvent } from "ol";
15
- import { Coordinate } from "ol/coordinate.js";
16
- import TileWMS from "ol/source/TileWMS.js";
17
- import ImageWMS from "ol/source/ImageWMS.js";
18
12
  import Layer from "ol/layer/Layer.js";
19
- import { Pixel } from "ol/pixel.js";
20
- import type { Feature, FeatureCollection } from "geojson";
21
- import throttle from "lodash.throttle";
22
13
  import { BaseLayerObjectEventTypes } from "ol/layer/Base.js";
23
14
  import { equals } from "ol/extent.js";
24
-
25
- const GEOJSON = new GeoJSON();
26
-
27
- export function getFeaturesFromVectorSources(
28
- olMap: Map,
29
- pixel: Pixel,
30
- ): Feature[] {
31
- const olFeatures = olMap.getFeaturesAtPixel(pixel);
32
- const { features } = GEOJSON.writeFeaturesObject(olFeatures as OlFeature[]);
33
- if (!features) {
34
- return [];
35
- }
36
- return features;
37
- }
38
-
39
- export function getGFIUrl(
40
- source: TileWMS | ImageWMS,
41
- map: Map,
42
- coordinate: Coordinate,
43
- ): string | null {
44
- const view = map.getView();
45
- const projection = view.getProjection();
46
- const resolution = view.getResolution() as number;
47
- const params = {
48
- ...source.getParams(),
49
- INFO_FORMAT: "application/json",
50
- };
51
- return (
52
- source.getFeatureInfoUrl(coordinate, resolution, projection, params) ?? null
53
- );
54
- }
55
-
56
- export function getFeaturesFromWmsSources(
57
- olMap: Map,
58
- coordinate: Coordinate,
59
- ): Promise<Feature[]> {
60
- const wmsSources: (ImageWMS | TileWMS)[] = olMap
61
- .getLayers()
62
- .getArray()
63
- .filter(
64
- (layer): layer is Layer<ImageWMS | TileWMS> =>
65
- layer instanceof Layer &&
66
- (layer.getSource() instanceof TileWMS ||
67
- layer.getSource() instanceof ImageWMS),
68
- )
69
- .map((layer) => layer.getSource()!);
70
-
71
- if (!wmsSources.length) {
72
- return Promise.resolve([]);
73
- }
74
-
75
- const gfiUrls = wmsSources.reduce((urls, source) => {
76
- const gfiUrl = getGFIUrl(source, olMap, coordinate);
77
- return gfiUrl ? [...urls, gfiUrl] : urls;
78
- }, [] as string[]);
79
- return Promise.all(
80
- gfiUrls.map((url) =>
81
- fetch(url)
82
- .then((response) => response.json())
83
- .then((collection: FeatureCollection) => collection.features),
84
- ),
85
- ).then((features) => features.flat());
86
- }
87
-
88
- const getFeaturesFromWmsSourcesThrottled = throttle(
89
- getFeaturesFromWmsSources,
90
- 250,
91
- );
92
-
93
- async function readFeaturesAtPixel(
94
- map: Map,
95
- event: MapBrowserEvent<PointerEvent>,
96
- ) {
97
- return [
98
- ...getFeaturesFromVectorSources(map, event.pixel),
99
- ...(await getFeaturesFromWmsSourcesThrottled(map, event.coordinate)),
100
- ];
101
- }
15
+ import { readFeaturesAtPixel } from "./get-features.js";
102
16
 
103
17
  function registerFeatureClickEvent(map: Map) {
104
18
  if (map.get(FeaturesClickEventType)) return;
@@ -116,15 +30,6 @@ function registerFeatureClickEvent(map: Map) {
116
30
 
117
31
  function registerFeatureHoverEvent(map: Map) {
118
32
  if (map.get(FeaturesHoverEventType)) return;
119
-
120
- map.on("pointermove", async (event: any) => {
121
- const features = await readFeaturesAtPixel(map, event);
122
- map.dispatchEvent({
123
- type: FeaturesHoverEventType,
124
- features,
125
- } as unknown as BaseEvent);
126
- });
127
-
128
33
  map.set(FeaturesHoverEventType, true);
129
34
  }
130
35
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geospatial-sdk/openlayers",
3
- "version": "0.0.5-dev.49+67854c5",
3
+ "version": "0.0.5-dev.51+33b8820",
4
4
  "description": "OpenLayers-related utilities",
5
5
  "keywords": [
6
6
  "ol",
@@ -30,17 +30,17 @@
30
30
  "devDependencies": {
31
31
  "@types/chroma-js": "^2.4.3",
32
32
  "@types/lodash.throttle": "^4.1.9",
33
- "ol": "^8.2.0",
33
+ "ol": "^10.7.0",
34
34
  "ol-mapbox-style": "12.4.0"
35
35
  },
36
36
  "peerDependencies": {
37
- "ol": ">6.x"
37
+ "ol": ">9.x"
38
38
  },
39
39
  "dependencies": {
40
- "@geospatial-sdk/core": "^0.0.5-dev.49+67854c5",
40
+ "@geospatial-sdk/core": "^0.0.5-dev.51+33b8820",
41
41
  "chroma-js": "^2.4.2",
42
42
  "lodash.throttle": "^4.1.1",
43
43
  "ol-mapbox-style": "12.4.0"
44
44
  },
45
- "gitHead": "67854c5bbe5b473e1a8160f5e8e56fe162e1d427"
45
+ "gitHead": "33b882078fc7b6f4f12d3eaac671d9c142ecf9f7"
46
46
  }
@@ -1,16 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,77 +0,0 @@
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
- }));