@geospatial-sdk/openlayers 0.0.5-dev.17 → 0.0.5-dev.18

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.
@@ -1,5 +1,5 @@
1
1
  import Map from "ol/Map";
2
- import { MapEvent, MapEventType } from "@geospatial-sdk/core";
2
+ import { MapEventsByType } from "@geospatial-sdk/core";
3
3
  import { Coordinate } from "ol/coordinate";
4
4
  import TileWMS from "ol/source/TileWMS";
5
5
  import ImageWMS from "ol/source/ImageWMS";
@@ -8,5 +8,5 @@ import type { Feature } from "geojson";
8
8
  export declare function getFeaturesFromVectorSources(olMap: Map, pixel: Pixel): Feature[];
9
9
  export declare function getGFIUrl(source: TileWMS | ImageWMS, map: Map, coordinate: Coordinate): string | null;
10
10
  export declare function getFeaturesFromWmsSources(olMap: Map, coordinate: Coordinate): Promise<Feature[]>;
11
- export declare function listen(map: Map, event: MapEventType, callback: (event: MapEvent) => void): void;
11
+ export declare function listen<T extends keyof MapEventsByType>(map: Map, eventType: T, callback: (event: MapEventsByType[T]) => void): void;
12
12
  //# 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,QAAQ,CAAC;AAClD,OAAO,EAIL,QAAQ,EACR,YAAY,EACb,MAAM,sBAAsB,CAAC;AAM9B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,OAAO,MAAM,mBAAmB,CAAC;AACxC,OAAO,QAAQ,MAAM,oBAAoB,CAAC;AAE1C,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,KAAK,EAAE,OAAO,EAAqB,MAAM,SAAS,CAAC;AAK1D,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,GAAG,EACV,KAAK,EAAE,KAAK,GACX,OAAO,EAAE,CAOX;AAED,wBAA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CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,IAAI,QAgC9C"}
@@ -83,29 +83,32 @@ function registerFeatureHoverEvent(map) {
83
83
  }));
84
84
  map.set(FeaturesHoverEventType, true);
85
85
  }
86
- export function listen(map, event, callback) {
87
- switch (event) {
86
+ export function listen(map, eventType, callback) {
87
+ switch (eventType) {
88
88
  case FeaturesClickEventType:
89
89
  registerFeatureClickEvent(map);
90
90
  // we're using a custom event type here so we need to cast to unknown first
91
- map.on(event, (event) => {
91
+ map.on(eventType, (event) => {
92
92
  callback(event);
93
93
  });
94
94
  break;
95
95
  case FeaturesHoverEventType:
96
96
  registerFeatureHoverEvent(map);
97
97
  // see comment above
98
- map.on(event, (event) => {
98
+ map.on(eventType, (event) => {
99
99
  callback(event);
100
100
  });
101
101
  break;
102
102
  case MapClickEventType:
103
103
  map.on("click", (event) => {
104
104
  const coordinate = toLonLat(event.pixel, map.getView().getProjection());
105
- callback({ coordinate });
105
+ callback({
106
+ type: "map-click",
107
+ coordinate,
108
+ });
106
109
  });
107
110
  break;
108
111
  default:
109
- throw new Error(`Unrecognized event type: ${event}`);
112
+ throw new Error(`Unrecognized event type: ${eventType}`);
110
113
  }
111
114
  }
@@ -190,7 +190,10 @@ describe("event registration", () => {
190
190
  map.dispatchEvent(createMapEvent(map, "click"));
191
191
  });
192
192
  it("registers the event on the map", () => {
193
- expect(callback).toHaveBeenCalledWith({ coordinate: toLonLat([10, 10]) });
193
+ expect(callback).toHaveBeenCalledWith({
194
+ coordinate: toLonLat([10, 10]),
195
+ type: "map-click",
196
+ });
194
197
  });
195
198
  });
196
199
  });
@@ -3,8 +3,7 @@ import {
3
3
  FeaturesClickEventType,
4
4
  FeaturesHoverEventType,
5
5
  MapClickEventType,
6
- MapEvent,
7
- MapEventType,
6
+ MapEventsByType,
8
7
  } from "@geospatial-sdk/core";
9
8
  import { toLonLat } from "ol/proj";
10
9
  import GeoJSON from "ol/format/GeoJSON";
@@ -121,24 +120,24 @@ function registerFeatureHoverEvent(map: Map) {
121
120
  map.set(FeaturesHoverEventType, true);
122
121
  }
123
122
 
124
- export function listen(
123
+ export function listen<T extends keyof MapEventsByType>(
125
124
  map: Map,
126
- event: MapEventType,
127
- callback: (event: MapEvent) => void,
125
+ eventType: T,
126
+ callback: (event: MapEventsByType[T]) => void,
128
127
  ) {
129
- switch (event) {
128
+ switch (eventType) {
130
129
  case FeaturesClickEventType:
131
130
  registerFeatureClickEvent(map);
132
131
  // we're using a custom event type here so we need to cast to unknown first
133
- map.on(event as unknown as MapObjectEventTypes, (event) => {
134
- callback(event as unknown as MapEvent);
132
+ map.on(eventType as unknown as MapObjectEventTypes, (event) => {
133
+ (callback as (event: unknown) => void)(event);
135
134
  });
136
135
  break;
137
136
  case FeaturesHoverEventType:
138
137
  registerFeatureHoverEvent(map);
139
138
  // see comment above
140
- map.on(event as unknown as MapObjectEventTypes, (event) => {
141
- callback(event as unknown as MapEvent);
139
+ map.on(eventType as unknown as MapObjectEventTypes, (event) => {
140
+ (callback as (event: unknown) => void)(event);
142
141
  });
143
142
  break;
144
143
  case MapClickEventType:
@@ -147,10 +146,13 @@ export function listen(
147
146
  event.pixel,
148
147
  map.getView().getProjection(),
149
148
  ) as [number, number];
150
- callback({ coordinate });
149
+ (callback as (event: unknown) => void)({
150
+ type: "map-click",
151
+ coordinate,
152
+ });
151
153
  });
152
154
  break;
153
155
  default:
154
- throw new Error(`Unrecognized event type: ${event}`);
156
+ throw new Error(`Unrecognized event type: ${eventType}`);
155
157
  }
156
158
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geospatial-sdk/openlayers",
3
- "version": "0.0.5-dev.17+e758ce3",
3
+ "version": "0.0.5-dev.18+6f12b0b",
4
4
  "description": "OpenLayers-related utilities",
5
5
  "keywords": [
6
6
  "ol",
@@ -37,9 +37,9 @@
37
37
  "ol": ">6.x"
38
38
  },
39
39
  "dependencies": {
40
- "@geospatial-sdk/core": "^0.0.5-dev.17+e758ce3",
40
+ "@geospatial-sdk/core": "^0.0.5-dev.18+6f12b0b",
41
41
  "chroma-js": "^2.4.2",
42
42
  "lodash.throttle": "^4.1.1"
43
43
  },
44
- "gitHead": "e758ce3d88f26443f0680907277ae4fde3c748f9"
44
+ "gitHead": "6f12b0b59e2794a24b27940c9c62dd279e2120e8"
45
45
  }