@maptiler/geocoding-control 1.4.2-dev.2 → 2.0.0-rc.1

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 (72) hide show
  1. package/MapLibreBasedGeocodingControl.d.ts +2971 -35
  2. package/leaflet-controller.d.ts +1 -1
  3. package/leaflet-controller.js +580 -569
  4. package/leaflet-controller.js.map +1 -1
  5. package/leaflet-controller.umd.js +3 -3
  6. package/leaflet-controller.umd.js.map +1 -1
  7. package/leaflet.d.ts +74 -16
  8. package/leaflet.js +1344 -1311
  9. package/leaflet.js.map +1 -1
  10. package/leaflet.umd.js +3 -3
  11. package/leaflet.umd.js.map +1 -1
  12. package/maplibregl-controller.d.ts +7 -7
  13. package/maplibregl-controller.js +683 -661
  14. package/maplibregl-controller.js.map +1 -1
  15. package/maplibregl-controller.umd.js +3 -3
  16. package/maplibregl-controller.umd.js.map +1 -1
  17. package/maplibregl.js +1632 -1481
  18. package/maplibregl.js.map +1 -1
  19. package/maplibregl.umd.js +3 -3
  20. package/maplibregl.umd.js.map +1 -1
  21. package/maptilersdk.js +1642 -1488
  22. package/maptilersdk.js.map +1 -1
  23. package/maptilersdk.umd.js +3 -3
  24. package/maptilersdk.umd.js.map +1 -1
  25. package/openlayers-controller.d.ts +1 -1
  26. package/openlayers-controller.js +308 -306
  27. package/openlayers-controller.js.map +1 -1
  28. package/openlayers-controller.umd.js +3 -3
  29. package/openlayers-controller.umd.js.map +1 -1
  30. package/openlayers.d.ts +21 -0
  31. package/openlayers.js +1301 -1313
  32. package/openlayers.js.map +1 -1
  33. package/openlayers.umd.js +3 -3
  34. package/openlayers.umd.js.map +1 -1
  35. package/package.json +18 -18
  36. package/react.d.ts +4 -4
  37. package/react.js +663 -644
  38. package/react.js.map +1 -1
  39. package/react.umd.js +1 -1
  40. package/react.umd.js.map +1 -1
  41. package/style.css +1 -1
  42. package/svelte/FeatureItem.svelte.d.ts +1 -1
  43. package/svelte/GeocodingControl.svelte +64 -33
  44. package/svelte/GeocodingControl.svelte.d.ts +25 -9
  45. package/svelte/MapLibreBasedGeocodingControl.d.ts +2971 -35
  46. package/svelte/MapLibreBasedGeocodingControl.js +166 -58
  47. package/svelte/leaflet-controller.d.ts +1 -1
  48. package/svelte/leaflet-controller.js +50 -24
  49. package/svelte/leaflet.d.ts +74 -16
  50. package/svelte/leaflet.js +25 -15
  51. package/svelte/maplibregl-controller.d.ts +7 -7
  52. package/svelte/maplibregl-controller.js +96 -66
  53. package/svelte/maplibregl.js +10 -7
  54. package/svelte/maptilersdk.js +23 -18
  55. package/svelte/openlayers-controller.d.ts +1 -1
  56. package/svelte/openlayers-controller.js +4 -1
  57. package/svelte/openlayers.d.ts +21 -0
  58. package/svelte/openlayers.js +30 -45
  59. package/svelte/react.d.ts +4 -4
  60. package/svelte/types.d.ts +38 -12
  61. package/svelte/vanilla.d.ts +14 -1
  62. package/svelte/vanilla.js +31 -8
  63. package/types.d.ts +38 -12
  64. package/vanilla.d.ts +14 -1
  65. package/vanilla.js +838 -791
  66. package/vanilla.js.map +1 -1
  67. package/vanilla.umd.js +1 -1
  68. package/vanilla.umd.js.map +1 -1
  69. package/maplibregl.d.ts +0 -16
  70. package/maptilersdk.d.ts +0 -11
  71. package/svelte/maplibregl.d.ts +0 -16
  72. package/svelte/maptilersdk.d.ts +0 -11
@@ -1,70 +1,178 @@
1
1
  import GeocodingControlComponent from "./GeocodingControl.svelte";
2
- import { createMapLibreGlMapController } from "./maplibregl-controller";
3
- export { createMapLibreGlMapController } from "./maplibregl-controller";
4
- export class MapLibreBasedGeocodingControl extends EventTarget {
5
- #gc;
6
- #options;
7
- constructor(options = {}) {
8
- super();
9
- this.#options = options;
2
+ import { createMapLibreGlMapController, } from "./maplibregl-controller";
3
+ export { createMapLibreGlMapController, } from "./maplibregl-controller";
4
+ export function crateClasses(Evented, maplibreGl, getExtraProps) {
5
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
+ const _keysMatch = true;
7
+ // NOTE We can't use Maplibre `Event` - see https://github.com/maplibre/maplibre-gl-js/issues/5015
8
+ class Event {
9
+ type;
10
+ target;
11
+ constructor(target, type) {
12
+ this.type = type;
13
+ this.target = target;
14
+ }
10
15
  }
11
- onAddInt(map) {
12
- const div = document.createElement("div");
13
- div.className =
14
- "mapboxgl-ctrl-geocoder mapboxgl-ctrl maplibregl-ctrl-geocoder maplibregl-ctrl mapboxgl-ctrl-group";
15
- const { marker, showResultMarkers, flyTo, fullGeometryStyle, ...restOptions } = this.#options;
16
- const flyToOptions = typeof flyTo === "boolean" ? {} : flyTo;
17
- const extraConfig = this.getExtraProps(map, div);
18
- const mapController = createMapLibreGlMapController(map, this.getMapLibreGl(), marker, showResultMarkers, flyToOptions, flyToOptions, fullGeometryStyle);
19
- const props = {
20
- mapController,
21
- flyTo: flyTo === undefined ? true : !!flyTo,
22
- apiKey: "", // just to satisfy apiKey; TODO find a better solution
23
- ...extraConfig,
24
- ...restOptions,
25
- };
26
- if (!props.apiKey) {
27
- throw new Error("no apiKey provided");
28
- }
29
- this.#gc = new GeocodingControlComponent({ target: div, props });
30
- for (const eventName of [
31
- "select",
32
- "pick",
33
- "featuresListed",
34
- "featuresMarked",
35
- "response",
36
- "optionsVisibilityChange",
37
- "reverseToggle",
38
- "queryChange",
39
- ]) {
40
- this.#gc.$on(eventName, (event) => this.dispatchEvent(event));
41
- }
42
- return div;
16
+ class SelectEvent extends Event {
17
+ feature;
18
+ constructor(target, details) {
19
+ super(target, "select");
20
+ Object.assign(this, details);
21
+ }
43
22
  }
44
- setOptions(options) {
45
- this.#options = options;
46
- const { marker, showResultMarkers, flyTo, fullGeometryStyle, ...restOptions } = this.#options;
47
- this.#gc?.$set(restOptions);
23
+ class FeaturesListedEvent extends Event {
24
+ features;
25
+ constructor(target, features) {
26
+ super(target, "featureslisted");
27
+ this.features = features;
28
+ }
48
29
  }
49
- setQuery(value, submit = true) {
50
- this.#gc?.setQuery(value, submit);
30
+ class FeaturesMarkedEvent extends Event {
31
+ features;
32
+ constructor(target, features) {
33
+ super(target, "featuresmarked");
34
+ this.features = features;
35
+ }
51
36
  }
52
- clearMap() {
53
- this.#gc?.clearMap();
37
+ class OptionsVisibilityChangeEvent extends Event {
38
+ optionsVisible;
39
+ constructor(target, optionsVisible) {
40
+ super(target, "optionsvisibilitychange");
41
+ this.optionsVisible = optionsVisible;
42
+ }
54
43
  }
55
- clearList() {
56
- this.#gc?.clearList();
44
+ class PickEvent extends Event {
45
+ feature;
46
+ constructor(target, feature) {
47
+ super(target, "pick");
48
+ this.feature = feature;
49
+ }
57
50
  }
58
- setReverseMode(value) {
59
- this.#gc?.$set({ reverseActive: value });
51
+ class QueryChangeEvent extends Event {
52
+ query;
53
+ constructor(target, query) {
54
+ super(target, "querychange");
55
+ this.query = query;
56
+ }
60
57
  }
61
- focus() {
62
- this.#gc?.focus();
58
+ class ResponseEvent extends Event {
59
+ url;
60
+ featureCollection;
61
+ constructor(target, url, featureCollection) {
62
+ super(target, "response");
63
+ this.url = url;
64
+ this.featureCollection = featureCollection;
65
+ }
63
66
  }
64
- blur() {
65
- this.#gc?.blur();
67
+ class ReverseToggleEvent extends Event {
68
+ reverse;
69
+ constructor(target, reverse) {
70
+ super(target, "reversetoggle");
71
+ this.reverse = reverse;
72
+ }
66
73
  }
67
- onRemove() {
68
- this.#gc?.$destroy();
74
+ class MapLibreBasedGeocodingControl extends Evented {
75
+ #gc;
76
+ #options;
77
+ constructor(options = {}) {
78
+ super();
79
+ this.#options = options;
80
+ }
81
+ onAddInt(map) {
82
+ const div = document.createElement("div");
83
+ div.className =
84
+ "mapboxgl-ctrl-geocoder mapboxgl-ctrl maplibregl-ctrl-geocoder maplibregl-ctrl mapboxgl-ctrl-group";
85
+ const { marker, showResultMarkers, flyTo, fullGeometryStyle, ...restOptions } = this.#options;
86
+ const flyToOptions = typeof flyTo === "boolean" ? {} : flyTo;
87
+ const mapController = createMapLibreGlMapController(map, maplibreGl, marker, showResultMarkers, flyToOptions, flyToOptions, fullGeometryStyle, restOptions.showFullGeometry === "polygon-with-marker");
88
+ const props = {
89
+ mapController,
90
+ flyTo: flyTo === undefined ? true : !!flyTo,
91
+ apiKey: "", // just to satisfy apiKey; TODO find a better solution
92
+ ...getExtraProps?.(map, div),
93
+ ...restOptions,
94
+ };
95
+ if (!props.apiKey) {
96
+ throw new Error("no apiKey provided");
97
+ }
98
+ this.#gc = new GeocodingControlComponent({ target: div, props });
99
+ this.#gc.$on("select", (event) => {
100
+ this.fire(new SelectEvent(this, event.detail));
101
+ });
102
+ this.#gc.$on("pick", (event) => {
103
+ this.fire(new PickEvent(this, event.detail.feature));
104
+ });
105
+ this.#gc.$on("featureslisted", (event) => {
106
+ this.fire(new FeaturesListedEvent(this, event.detail.features));
107
+ });
108
+ this.#gc.$on("featuresmarked", (event) => {
109
+ this.fire(new FeaturesMarkedEvent(this, event.detail.features));
110
+ });
111
+ this.#gc.$on("response", (event) => {
112
+ this.fire(new ResponseEvent(this, event.detail.url, event.detail.featureCollection));
113
+ });
114
+ this.#gc.$on("optionsvisibilitychange", (event) => {
115
+ this.fire(new OptionsVisibilityChangeEvent(this, event.detail.optionsVisible));
116
+ });
117
+ this.#gc.$on("reversetoggle", (event) => {
118
+ this.fire(new ReverseToggleEvent(this, event.detail.reverse));
119
+ });
120
+ this.#gc.$on("querychange", (event) => {
121
+ this.fire(new QueryChangeEvent(this, event.detail.query));
122
+ });
123
+ return div;
124
+ }
125
+ on(type, listener) {
126
+ return super.on(type, listener);
127
+ }
128
+ once(type, listener) {
129
+ return super.once(type, listener);
130
+ }
131
+ off(type, listener) {
132
+ return super.off(type, listener);
133
+ }
134
+ listens(type) {
135
+ return super.listens(type);
136
+ }
137
+ setOptions(options) {
138
+ this.#options = options;
139
+ const { marker, showResultMarkers, flyTo, fullGeometryStyle, ...restOptions } = this.#options;
140
+ this.#gc?.$set(restOptions);
141
+ }
142
+ setQuery(value, submit = true) {
143
+ this.#gc?.setQuery(value, submit);
144
+ }
145
+ clearMap() {
146
+ this.#gc?.clearMap();
147
+ }
148
+ clearList() {
149
+ this.#gc?.clearList();
150
+ }
151
+ setReverseMode(value) {
152
+ this.#gc?.$set({ reverseActive: value });
153
+ }
154
+ focus() {
155
+ this.#gc?.focus();
156
+ }
157
+ blur() {
158
+ this.#gc?.blur();
159
+ }
160
+ onRemove() {
161
+ this.#gc?.$destroy();
162
+ }
69
163
  }
164
+ const events = {
165
+ SelectEvent,
166
+ FeaturesListedEvent,
167
+ FeaturesMarkedEvent,
168
+ OptionsVisibilityChangeEvent,
169
+ PickEvent,
170
+ QueryChangeEvent,
171
+ ResponseEvent,
172
+ ReverseToggleEvent,
173
+ };
174
+ return {
175
+ MapLibreBasedGeocodingControl,
176
+ events,
177
+ };
70
178
  }
@@ -1,6 +1,6 @@
1
1
  import * as L from "leaflet";
2
2
  import type { BBox, Feature, MapEvent, Position } from "./types";
3
- export declare function createLeafletMapController(map: L.Map, marker?: boolean | L.MarkerOptions, showResultMarkers?: boolean | L.MarkerOptions, flyToOptions?: L.ZoomPanOptions, flyToBounds?: L.FitBoundsOptions, fullGeometryStyle?: L.PathOptions | L.StyleFunction): {
3
+ export declare function createLeafletMapController(map: L.Map, marker?: boolean | null | L.MarkerOptions | ((map: L.Map, feature?: Feature) => L.Marker | undefined | null), showResultMarkers?: boolean | null | L.MarkerOptions | ((map: L.Map, feature: Feature) => L.Marker | undefined | null), flyToOptions?: L.ZoomPanOptions | null, flyToBounds?: L.FitBoundsOptions | null, fullGeometryStyle?: null | boolean | L.PathOptions | L.StyleFunction, showPolyMarker?: boolean): {
4
4
  setEventHandler(handler: undefined | ((e: MapEvent) => void)): void;
5
5
  flyTo(center: Position, zoom?: number): void;
6
6
  fitBounds(bbox: BBox, padding: number, maxZoom?: number): void;
@@ -6,7 +6,7 @@ import * as L from "leaflet";
6
6
  import { unwrapBbox } from "./geoUtils";
7
7
  import MarkerIcon from "./MarkerIcon.svelte";
8
8
  import { setMask } from "./mask";
9
- export function createLeafletMapController(map, marker = true, showResultMarkers = true, flyToOptions = {}, flyToBounds = {}, fullGeometryStyle = (feature) => {
9
+ const defaultFullGeometryStyle = (feature) => {
10
10
  const type = feature?.geometry?.type;
11
11
  const weight = feature?.properties?.isMask
12
12
  ? 0
@@ -21,13 +21,18 @@ export function createLeafletMapController(map, marker = true, showResultMarkers
21
21
  dashArray: [weight, weight],
22
22
  lineCap: "butt",
23
23
  };
24
- }) {
24
+ };
25
+ export function createLeafletMapController(map, marker = true, showResultMarkers = true, flyToOptions = {}, flyToBounds = {}, fullGeometryStyle = defaultFullGeometryStyle, showPolyMarker = false) {
25
26
  let eventHandler;
26
27
  const markers = [];
27
28
  let selectedMarker;
28
29
  let reverseMarker;
29
30
  const resultLayer = L.geoJSON(undefined, {
30
- style: fullGeometryStyle,
31
+ style: fullGeometryStyle === true
32
+ ? defaultFullGeometryStyle
33
+ : fullGeometryStyle === false
34
+ ? undefined
35
+ : (fullGeometryStyle ?? undefined),
31
36
  interactive: false,
32
37
  }).addTo(map);
33
38
  const handleMapClick = (e) => {
@@ -93,16 +98,18 @@ export function createLeafletMapController(map, marker = true, showResultMarkers
93
98
  }
94
99
  }
95
100
  else if (latLng) {
96
- reverseMarker = (typeof marker === "object"
97
- ? new L.Marker(latLng, marker)
98
- : createMarker(latLng)).addTo(map);
99
- reverseMarker.getElement()?.classList.add("marker-reverse");
101
+ if (marker instanceof Function) {
102
+ reverseMarker = marker(map) ?? undefined;
103
+ }
104
+ else {
105
+ reverseMarker = (typeof marker === "object"
106
+ ? new L.Marker(latLng, marker)
107
+ : createMarker(latLng)).addTo(map);
108
+ reverseMarker.getElement()?.classList.add("marker-reverse");
109
+ }
100
110
  }
101
111
  },
102
112
  setMarkers(markedFeatures, picked) {
103
- if (!marker) {
104
- return;
105
- }
106
113
  function setData(data) {
107
114
  resultLayer.clearLayers();
108
115
  if (data) {
@@ -170,10 +177,21 @@ export function createLeafletMapController(map, marker = true, showResultMarkers
170
177
  setData(picked);
171
178
  return; // no pin for (multi)linestrings
172
179
  }
173
- const pos = [picked.center[1], picked.center[0]];
174
- markers.push((typeof marker === "object"
175
- ? new L.Marker(pos, marker)
176
- : createMarker(pos)).addTo(map));
180
+ if (!showPolyMarker && picked.geometry.type !== "Point") {
181
+ return;
182
+ }
183
+ if (marker instanceof Function) {
184
+ const m = marker(map, picked);
185
+ if (m) {
186
+ markers.push(m.addTo(map));
187
+ }
188
+ }
189
+ else if (marker) {
190
+ const pos = [picked.center[1], picked.center[0]];
191
+ markers.push(typeof marker === "object"
192
+ ? new L.Marker(pos, marker)
193
+ : createMarker(pos).addTo(map));
194
+ }
177
195
  }
178
196
  if (showResultMarkers) {
179
197
  for (const feature of markedFeatures ?? []) {
@@ -184,16 +202,24 @@ export function createLeafletMapController(map, marker = true, showResultMarkers
184
202
  feature.center[1],
185
203
  feature.center[0],
186
204
  ];
187
- const marker = typeof showResultMarkers === "object"
188
- ? new L.Marker(pos, showResultMarkers)
189
- : createMarker(pos, true);
190
- marker
191
- .addTo(map)
192
- .bindTooltip(feature.place_type[0] === "reverse"
193
- ? feature.place_name
194
- : feature.place_name.replace(/,.*/, ""), {
195
- direction: "top",
196
- });
205
+ let marker;
206
+ if (showResultMarkers instanceof Function) {
207
+ marker = showResultMarkers(map, feature);
208
+ if (!marker) {
209
+ continue;
210
+ }
211
+ }
212
+ else {
213
+ marker = (typeof showResultMarkers === "object"
214
+ ? new L.Marker(pos, showResultMarkers)
215
+ : createMarker(pos, true))
216
+ .addTo(map)
217
+ .bindTooltip(feature.place_type[0] === "reverse"
218
+ ? feature.place_name
219
+ : feature.place_name.replace(/,.*/, ""), {
220
+ direction: "top",
221
+ });
222
+ }
197
223
  const element = marker.getElement();
198
224
  if (element) {
199
225
  element.addEventListener("click", (e) => {
@@ -1,34 +1,92 @@
1
1
  import * as L from "leaflet";
2
- import type { ControlOptions } from "./types";
2
+ import type { ControlOptions, DispatcherType, Feature } from "./types";
3
3
  export { createLeafletMapController } from "./leaflet-controller";
4
4
  type LeafletControlOptions = ControlOptions & L.ControlOptions & {
5
5
  /**
6
- * If `true`, a [Marker](https://leafletjs.com/reference.html#marker) will be added to the map at the location of the user-selected result using a default set of Marker options.
7
- * If the value is an object, the marker will be constructed using these options.
8
- * If `false`, no marker will be added to the map.
6
+ * Marker to be added to the map at the location of the user-selected result using a default set of Marker options.
7
+ *
8
+ * - If `true` or `undefined` then a default marker will be used.\
9
+ * - If the value is [MarkerOptions](https://leafletjs.com/reference.html#marker-option) then the marker will be constructed using these options.
10
+ * - If the value is a function then it can create and configure custom [Marker](https://leafletjs.com/reference.html#marker),
11
+ * add it to the [Map](https://leafletjs.com/reference.html#map) and return it.
12
+ * Function accepts [Map](https://leafletjs.com/reference.html#map) and `Feature` as parameters.
13
+ * Feature is `undefined` for the reverse location marker.
14
+ * - If `false` or `null` then no marker will be added to the map.
15
+ *
9
16
  * Default value is `true`.
10
17
  */
11
- marker?: boolean | L.MarkerOptions;
18
+ marker?: null | boolean | L.MarkerOptions | ((map: L.Map, feature?: Feature) => L.Marker | undefined | null);
12
19
  /**
13
- * If `true`, [Markers](https://leafletjs.com/reference.html#marker) will be added to the map at the location the top results for the query.
14
- * If the value is an object, the marker will be constructed using these options.
15
- * If `false`, no marker will be added to the map.
20
+ * Marker be added to the map at the location the geocoding results.
21
+ *
22
+ * - If `true` or `undefined` then a default marker will be used.
23
+ * - If the value is [MarkerOptions](https://leafletjs.com/reference.html#marker-option) then the marker will be constructed using these options.
24
+ * - If the value is a function then it can create and configure custom [Marker](https://leafletjs.com/reference.html#marker),
25
+ * add it to the [Map](https://leafletjs.com/reference.html#map) and return it.
26
+ * In this case the default pop-up won't be added to the marker.
27
+ * Function accepts [Map](https://leafletjs.com/reference.html#map) and `Feature` as parameters.
28
+ * - If `false` or `null` then no marker will be added to the map.
29
+ *
16
30
  * Default value is `true`.
17
31
  */
18
- showResultMarkers?: boolean | L.MarkerOptions;
32
+ showResultMarkers?: null | boolean | L.MarkerOptions | ((map: L.Map, feature: Feature) => L.Marker | undefined | null);
19
33
  /**
20
- * If `false`, animating the map to a selected result is disabled.
21
- * If `true`, animating the map will use the default animation parameters.
22
- * If an object, it will be passed as options to the map `flyTo` or `fitBounds` method providing control over the animation of the transition.
34
+ * Animation to selected feature on the map.
35
+ *
36
+ * - If `false` or `null` then animating the map to a selected result is disabled.
37
+ * - If `true` or `undefined` then animating the map will use the default animation parameters.
38
+ * - If an [ZoomPanOptions](https://leafletjs.com/reference.html#zoom/pan-options)
39
+ * ` & `[FitBoundsOptions](https://leafletjs.com/reference.html#fitbounds-options) then it will be passed as options
40
+ * to the map [flyTo](https://leafletjs.com/reference.html#map-flyto)
41
+ * or [fitBounds](https://leafletjs.com/reference.html#map-fitbounds) method providing control over the animation of the transition.
42
+ *
23
43
  * Default value is `true`.
24
44
  */
25
- flyTo?: boolean | (L.ZoomPanOptions & L.FitBoundsOptions);
45
+ flyTo?: null | boolean | (L.ZoomPanOptions & L.FitBoundsOptions);
26
46
  /**
27
- * Style for full feature geometry GeoJSON.
47
+ * Style for the full feature geometry.
48
+ *
49
+ * - If `false` or `null` then no full geometry is drawn.
50
+ * - If `true` or `undefined` then default-styled full geometry is drawn.
51
+ * - If an [PathOptions](https://leafletjs.com/reference.html#path-option) then it will be used to style the full geometry.
52
+ * - If a function accepting a `Feature` and returning [PathOptions](https://leafletjs.com/reference.html#path-option)
53
+ * then it must teturn the style and will be used to style the full geometry.
28
54
  */
29
- fullGeometryStyle?: L.PathOptions | L.StyleFunction;
55
+ fullGeometryStyle?: null | boolean | L.PathOptions | L.StyleFunction;
30
56
  };
31
- export declare class GeocodingControl extends L.Control {
57
+ type LeafletEvent<T> = {
58
+ type: T;
59
+ target: GeocodingControl;
60
+ sourceTarget: GeocodingControl;
61
+ };
62
+ type CustomEventMap = {
63
+ [T in keyof DispatcherType]: DispatcherType[T] & LeafletEvent<T>;
64
+ };
65
+ /**
66
+ * Leaflet mixins https://leafletjs.com/reference.html#class
67
+ * for TypeScript https://www.typescriptlang.org/docs/handbook/mixins.html
68
+ * @internal
69
+ */
70
+ declare class EventedControl extends L.Control {
71
+ }
72
+ interface EventedControl extends L.Control {
73
+ on<T extends keyof CustomEventMap>(type: T, fn: (event: CustomEventMap[T]) => void, context?: unknown): this;
74
+ addEventListener<T extends keyof CustomEventMap>(type: T, fn: (event: CustomEventMap[T]) => void, context?: unknown): this;
75
+ once<T extends keyof CustomEventMap>(type: T, fn: (event: CustomEventMap[T]) => void, context?: unknown): this;
76
+ addOneTimeEventListener<T extends keyof CustomEventMap>(type: T, fn: (event: CustomEventMap[T]) => void, context?: unknown): this;
77
+ off<T extends keyof CustomEventMap>(type?: T, fn?: (event: CustomEventMap[T]) => void, context?: unknown): this;
78
+ off(eventMap?: {
79
+ [T in keyof CustomEventMap]?: (event: CustomEventMap[T]) => void;
80
+ }): this;
81
+ removeEventListener<T extends keyof CustomEventMap>(type?: T, fn?: (event: CustomEventMap[T]) => void, context?: unknown): this;
82
+ listens<T extends keyof CustomEventMap>(type: T, fn: (event: CustomEventMap[T]) => void, context?: unknown, propagate?: boolean): boolean;
83
+ fire(type: string, data?: unknown, propagate?: boolean): this;
84
+ addEventParent(obj: L.Evented): this;
85
+ removeEventParent(obj: L.Evented): this;
86
+ fireEvent(type: string, data?: unknown, propagate?: boolean): this;
87
+ hasEventListeners<T extends keyof CustomEventMap>(type: T): boolean;
88
+ }
89
+ export declare class GeocodingControl extends EventedControl {
32
90
  #private;
33
91
  constructor(options: LeafletControlOptions);
34
92
  onAdd(map: L.Map): HTMLDivElement;
package/svelte/leaflet.js CHANGED
@@ -2,11 +2,20 @@ import * as L from "leaflet";
2
2
  import GeocodingControlComponent from "./GeocodingControl.svelte";
3
3
  import { createLeafletMapController } from "./leaflet-controller";
4
4
  export { createLeafletMapController } from "./leaflet-controller";
5
- export class GeocodingControl extends L.Control {
5
+ /**
6
+ * Leaflet mixins https://leafletjs.com/reference.html#class
7
+ * for TypeScript https://www.typescriptlang.org/docs/handbook/mixins.html
8
+ * @internal
9
+ */
10
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
11
+ class EventedControl extends L.Control {
12
+ }
13
+ L.Util.extend(EventedControl.prototype, L.Evented.prototype);
14
+ export class GeocodingControl extends EventedControl {
6
15
  #gc;
7
16
  #options;
8
17
  constructor(options) {
9
- super();
18
+ super(options);
10
19
  this.#options = options;
11
20
  }
12
21
  onAdd(map) {
@@ -14,9 +23,9 @@ export class GeocodingControl extends L.Control {
14
23
  div.className = "leaflet-ctrl-geocoder";
15
24
  L.DomEvent.disableClickPropagation(div);
16
25
  L.DomEvent.disableScrollPropagation(div);
17
- const { marker, showResultMarkers, flyTo, fullGeometryStyle, ...restOptions } = this.#options;
26
+ const { marker, showResultMarkers, flyTo, fullGeometryStyle, position, ...restOptions } = this.#options;
18
27
  const flyToOptions = typeof flyTo === "boolean" ? {} : flyTo;
19
- const mapController = createLeafletMapController(map, marker, showResultMarkers, flyToOptions, flyToOptions, fullGeometryStyle);
28
+ const mapController = createLeafletMapController(map, marker, showResultMarkers, flyToOptions, flyToOptions, fullGeometryStyle, restOptions.showFullGeometry === "polygon-with-marker");
20
29
  this.#gc = new GeocodingControlComponent({
21
30
  target: div,
22
31
  props: {
@@ -25,17 +34,18 @@ export class GeocodingControl extends L.Control {
25
34
  ...restOptions,
26
35
  },
27
36
  });
28
- for (const eventName of [
29
- "select",
30
- "pick",
31
- "featuresListed",
32
- "featuresMarked",
33
- "response",
34
- "optionsVisibilityChange",
35
- "reverseToggle",
36
- "queryChange",
37
- ]) {
38
- this.#gc.$on(eventName, (event) => map.fire(eventName.toLowerCase(), event.detail));
37
+ const eventNames = {
38
+ select: undefined,
39
+ pick: undefined,
40
+ featureslisted: undefined,
41
+ featuresmarked: undefined,
42
+ response: undefined,
43
+ optionsvisibilitychange: undefined,
44
+ reversetoggle: undefined,
45
+ querychange: undefined,
46
+ };
47
+ for (const eventName in eventNames) {
48
+ this.#gc.$on(eventName, (event) => this.fire(eventName, event.detail));
39
49
  }
40
50
  return div;
41
51
  }
@@ -1,12 +1,13 @@
1
1
  import type * as maplibregl from "maplibre-gl";
2
- import type { FillLayerSpecification, FitBoundsOptions, FlyToOptions, LineLayerSpecification, Map } from "maplibre-gl";
2
+ import type { FillLayerSpecification, FitBoundsOptions, FlyToOptions, LineLayerSpecification, Map, Marker, MarkerOptions } from "maplibre-gl";
3
3
  import type { BBox, Position } from "./types";
4
4
  import type { Feature, MapEvent } from "./types.js";
5
- type MapLibreGL = Pick<typeof maplibregl, "Marker" | "Popup">;
6
- export declare function createMapLibreGlMapController(map: Map, maplibregl?: MapLibreGL | undefined, marker?: boolean | maplibregl.MarkerOptions, showResultMarkers?: boolean | maplibregl.MarkerOptions, flyToOptions?: FlyToOptions, fitBoundsOptions?: FitBoundsOptions, fullGeometryStyle?: undefined | {
7
- fill?: Pick<FillLayerSpecification, "layout" | "paint" | "filter">;
8
- line?: Pick<LineLayerSpecification, "layout" | "paint" | "filter">;
9
- }): {
5
+ export type MapLibreGL = Pick<typeof maplibregl, "Marker" | "Popup">;
6
+ export type FullGeometryStyle = {
7
+ fill: Pick<FillLayerSpecification, "layout" | "paint" | "filter">;
8
+ line: Pick<LineLayerSpecification, "layout" | "paint" | "filter">;
9
+ };
10
+ export declare function createMapLibreGlMapController(map: Map, maplibregl?: MapLibreGL | undefined, marker?: boolean | null | MarkerOptions | ((map: Map, feature?: Feature) => Marker | undefined | null), showResultMarkers?: boolean | null | MarkerOptions | ((map: Map, feature: Feature) => Marker | undefined | null), flyToOptions?: FlyToOptions | null, fitBoundsOptions?: FitBoundsOptions | null, fullGeometryStyle?: boolean | null | FullGeometryStyle, showPolyMarker?: boolean): {
10
11
  setEventHandler(handler: undefined | ((e: MapEvent) => void)): void;
11
12
  flyTo(center: Position, zoom?: number): void;
12
13
  fitBounds(bbox: BBox, padding: number, maxZoom?: number): void;
@@ -16,4 +17,3 @@ export declare function createMapLibreGlMapController(map: Map, maplibregl?: Map
16
17
  setSelectedMarker(index: number): void;
17
18
  getCenterAndZoom(): [number, number, number];
18
19
  };
19
- export {};