@maptiler/geocoding-control 2.0.0 → 2.0.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 (74) hide show
  1. package/MapLibreBasedGeocodingControl.d.ts +2616 -27
  2. package/leaflet-controller.d.ts +1 -1
  3. package/leaflet-controller.js +97 -95
  4. package/leaflet-controller.js.map +1 -1
  5. package/leaflet-controller.umd.js +2 -2
  6. package/leaflet-controller.umd.js.map +1 -1
  7. package/leaflet.d.ts +26 -4
  8. package/leaflet.js +906 -909
  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 +1 -1
  13. package/maplibregl-controller.js +480 -466
  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.d.ts +2594 -9
  18. package/maplibregl.js +2094 -1969
  19. package/maplibregl.js.map +1 -1
  20. package/maplibregl.umd.js +3 -3
  21. package/maplibregl.umd.js.map +1 -1
  22. package/maptilersdk.d.ts +2594 -9
  23. package/maptilersdk.js +2086 -1964
  24. package/maptilersdk.js.map +1 -1
  25. package/maptilersdk.umd.js +3 -3
  26. package/maptilersdk.umd.js.map +1 -1
  27. package/openlayers-controller.d.ts +1 -1
  28. package/openlayers-controller.js +62 -60
  29. package/openlayers-controller.js.map +1 -1
  30. package/openlayers-controller.umd.js +2 -2
  31. package/openlayers-controller.umd.js.map +1 -1
  32. package/openlayers.d.ts +21 -0
  33. package/openlayers.js +754 -786
  34. package/openlayers.js.map +1 -1
  35. package/openlayers.umd.js +3 -3
  36. package/openlayers.umd.js.map +1 -1
  37. package/package.json +18 -18
  38. package/react.d.ts +4 -4
  39. package/react.js +619 -619
  40. package/react.js.map +1 -1
  41. package/react.umd.js +1 -1
  42. package/react.umd.js.map +1 -1
  43. package/style.css +1 -1
  44. package/svelte/FeatureItem.svelte +1 -1
  45. package/svelte/FeatureItem.svelte.d.ts +2 -2
  46. package/svelte/GeocodingControl.svelte +31 -32
  47. package/svelte/GeocodingControl.svelte.d.ts +26 -13
  48. package/svelte/MapLibreBasedGeocodingControl.d.ts +2616 -27
  49. package/svelte/MapLibreBasedGeocodingControl.js +120 -17
  50. package/svelte/leaflet-controller.d.ts +1 -1
  51. package/svelte/leaflet-controller.js +4 -1
  52. package/svelte/leaflet.d.ts +26 -4
  53. package/svelte/leaflet.js +17 -19
  54. package/svelte/maplibregl-controller.d.ts +1 -1
  55. package/svelte/maplibregl-controller.js +45 -36
  56. package/svelte/maplibregl.d.ts +2594 -9
  57. package/svelte/maplibregl.js +11 -3
  58. package/svelte/maptilersdk.d.ts +2594 -9
  59. package/svelte/maptilersdk.js +11 -3
  60. package/svelte/openlayers-controller.d.ts +1 -1
  61. package/svelte/openlayers-controller.js +4 -1
  62. package/svelte/openlayers.d.ts +21 -0
  63. package/svelte/openlayers.js +30 -45
  64. package/svelte/react.d.ts +4 -4
  65. package/svelte/react.js +5 -5
  66. package/svelte/types.d.ts +84 -35
  67. package/svelte/vanilla.d.ts +14 -1
  68. package/svelte/vanilla.js +31 -8
  69. package/types.d.ts +84 -35
  70. package/vanilla.d.ts +14 -1
  71. package/vanilla.js +929 -901
  72. package/vanilla.js.map +1 -1
  73. package/vanilla.umd.js +1 -1
  74. package/vanilla.umd.js.map +1 -1
@@ -1,7 +1,7 @@
1
1
  import * as maptilersdk from "@maptiler/sdk";
2
- import { crateBaseClass, } from "./MapLibreBasedGeocodingControl";
2
+ import { crateClasses, } from "./MapLibreBasedGeocodingControl";
3
3
  export { createMapLibreGlMapController } from "./maplibregl-controller";
4
- const Base = crateBaseClass(maptilersdk.Evented, maptilersdk, (map, div) => {
4
+ const { MapLibreBasedGeocodingControl, events } = crateClasses(maptilersdk.Evented, maptilersdk, (map, div) => {
5
5
  const sdkConfig = {};
6
6
  if (!("getSdkConfig" in map && typeof map.getSdkConfig === "function")) {
7
7
  throw new Error("MapTiler SDK not detected");
@@ -15,8 +15,16 @@ const Base = crateBaseClass(maptilersdk.Evented, maptilersdk, (map, div) => {
15
15
  div.className += " maptiler-ctrl";
16
16
  return sdkConfig;
17
17
  });
18
- export class GeocodingControl extends Base {
18
+ export class GeocodingControl extends MapLibreBasedGeocodingControl {
19
19
  onAdd(map) {
20
20
  return super.onAddInt(map);
21
21
  }
22
22
  }
23
+ export const SelectEvent = events.SelectEvent;
24
+ export const FeaturesListedEvent = events.FeaturesListedEvent;
25
+ export const FeaturesMarkedEvent = events.FeaturesMarkedEvent;
26
+ export const OptionsVisibilityChangeEvent = events.OptionsVisibilityChangeEvent;
27
+ export const PickEvent = events.PickEvent;
28
+ export const QueryChangeEvent = events.QueryChangeEvent;
29
+ export const ResponseEvent = events.ResponseEvent;
30
+ export const ReverseToggleEvent = events.ReverseToggleEvent;
@@ -9,7 +9,7 @@ export declare function createOpenLayersMapController(map: Map, flyToOptions?: A
9
9
  fitBounds(bbox: BBox, padding: number, maxZoom: number): void;
10
10
  indicateReverse(reverse: boolean): void;
11
11
  setReverseMarker(coordinates?: Position): void;
12
- setMarkers(markedFeatures: FeatureType[] | undefined, picked: FeatureType | undefined): void;
12
+ setFeatures(markedFeatures: FeatureType[] | undefined, picked: FeatureType | undefined, showPolygonMarker: boolean): void;
13
13
  setSelectedMarker(index: number): void;
14
14
  getCenterAndZoom(): [number, x: number, y: number] | undefined;
15
15
  };
@@ -167,7 +167,7 @@ export function createOpenLayersMapController(map, flyToOptions = {}, flyToBound
167
167
  source.addFeature(reverseMarker);
168
168
  }
169
169
  },
170
- setMarkers(markedFeatures, picked) {
170
+ setFeatures(markedFeatures, picked, showPolygonMarker) {
171
171
  function setData(data) {
172
172
  if (!data) {
173
173
  return;
@@ -235,6 +235,9 @@ export function createOpenLayersMapController(map, flyToOptions = {}, flyToBound
235
235
  source.addFeature(new OlFeature(fromWgs84(new OlMultiLineString(picked.geometry.coordinates))));
236
236
  return; // no pin for (multi)linestrings
237
237
  }
238
+ if (!showPolygonMarker && picked.geometry.type !== "Point") {
239
+ return;
240
+ }
238
241
  source.addFeature(new OlFeature(fromWgs84(new OlPoint(picked.center))));
239
242
  }
240
243
  for (const feature of markedFeatures ?? []) {
@@ -1,7 +1,10 @@
1
1
  import type { Map } from "ol";
2
+ import type { ObjectEvent } from "ol/Object";
3
+ import type { CombinedOnSignature, EventTypes } from "ol/Observable";
2
4
  import type { AnimationOptions, FitOptions } from "ol/View";
3
5
  import { Control } from "ol/control";
4
6
  import type { Options } from "ol/control/Control";
7
+ import type { EventsKey } from "ol/events";
5
8
  import BaseEvent from "ol/events/Event";
6
9
  import type { StyleLike } from "ol/style/Style";
7
10
  import type { FlatStyleLike } from "ol/style/flat";
@@ -11,8 +14,26 @@ type OpenLayersControlOptions = ControlOptions & Options & {
11
14
  flyTo?: boolean | (AnimationOptions & FitOptions);
12
15
  fullGeometryStyle?: StyleLike | FlatStyleLike;
13
16
  };
17
+ type CustomEventMap = {
18
+ select: SelectEvent;
19
+ featureslisted: FeaturesListedEvent;
20
+ featuresmarked: FeaturesMarkedEvent;
21
+ optionsvisibilitychange: OptionsVisibilityChangeEvent;
22
+ pick: PickEvent;
23
+ querychange: QueryChangeEvent;
24
+ response: ResponseEvent;
25
+ reversetoggle: ReverseToggleEvent;
26
+ };
27
+ type CustomObjectOnSignature<ReturnType> = {
28
+ <K extends keyof CustomEventMap>(type: K, listener: (evt: CustomEventMap[K]) => void): ReturnType;
29
+ } & {
30
+ (type: "propertychange", listener: (evt: ObjectEvent) => void): ReturnType;
31
+ } & CombinedOnSignature<EventTypes | "propertychange" | keyof CustomEventMap, ReturnType>;
14
32
  export declare class GeocodingControl extends Control {
15
33
  #private;
34
+ on: CustomObjectOnSignature<EventsKey>;
35
+ once: CustomObjectOnSignature<EventsKey>;
36
+ un: CustomObjectOnSignature<EventsKey>;
16
37
  constructor(options: OpenLayersControlOptions);
17
38
  setMap(map: Map | null): void;
18
39
  setOptions(options: OpenLayersControlOptions): void;
@@ -21,45 +21,30 @@ export class GeocodingControl extends Control {
21
21
  ...restOptions,
22
22
  },
23
23
  });
24
- for (const eventName of [
25
- "select",
26
- "pick",
27
- "featuresListed",
28
- "featuresMarked",
29
- "response",
30
- "optionsVisibilityChange",
31
- "reverseToggle",
32
- "queryChange",
33
- ]) {
34
- this.#gc.$on(eventName, (event) => {
35
- switch (eventName) {
36
- case "select":
37
- this.dispatchEvent(new SelectEvent(event.detail));
38
- break;
39
- case "featuresListed":
40
- this.dispatchEvent(new FeaturesListedEvent(event.detail));
41
- break;
42
- case "featuresMarked":
43
- this.dispatchEvent(new FeaturesMarkedEvent(event.detail));
44
- break;
45
- case "optionsVisibilityChange":
46
- this.dispatchEvent(new OptionsVisibilityChangeEvent(event.detail));
47
- break;
48
- case "pick":
49
- this.dispatchEvent(new PickEvent(event.detail));
50
- break;
51
- case "queryChange":
52
- this.dispatchEvent(new QueryChangeEvent(event.detail));
53
- break;
54
- case "response":
55
- this.dispatchEvent(new ResponseEvent(event.detail.url, event.detail.featureCollection));
56
- break;
57
- case "reverseToggle":
58
- this.dispatchEvent(new ReverseToggleEvent(event.detail));
59
- break;
60
- }
61
- });
62
- }
24
+ this.#gc.$on("select", (event) => {
25
+ this.dispatchEvent(new SelectEvent(event.detail.feature));
26
+ });
27
+ this.#gc.$on("pick", (event) => {
28
+ this.dispatchEvent(new PickEvent(event.detail.feature));
29
+ });
30
+ this.#gc.$on("featureslisted", (event) => {
31
+ this.dispatchEvent(new FeaturesListedEvent(event.detail.features));
32
+ });
33
+ this.#gc.$on("featuresmarked", (event) => {
34
+ this.dispatchEvent(new FeaturesMarkedEvent(event.detail.features));
35
+ });
36
+ this.#gc.$on("response", (event) => {
37
+ this.dispatchEvent(new ResponseEvent(event.detail.url, event.detail.featureCollection));
38
+ });
39
+ this.#gc.$on("optionsvisibilitychange", (event) => {
40
+ this.dispatchEvent(new OptionsVisibilityChangeEvent(event.detail.optionsVisible));
41
+ });
42
+ this.#gc.$on("reversetoggle", (event) => {
43
+ this.dispatchEvent(new ReverseToggleEvent(event.detail.reverse));
44
+ });
45
+ this.#gc.$on("querychange", (event) => {
46
+ this.dispatchEvent(new QueryChangeEvent(event.detail.query));
47
+ });
63
48
  this.#options = options;
64
49
  }
65
50
  setMap(map) {
@@ -77,7 +62,7 @@ export class GeocodingControl extends Control {
77
62
  }
78
63
  }
79
64
  setOptions(options) {
80
- this.#options = options;
65
+ Object.assign(this.#options, options);
81
66
  const { flyTo, fullGeometryStyle, ...restOptions } = this.#options;
82
67
  this.#gc?.$set({
83
68
  ...restOptions,
@@ -110,21 +95,21 @@ export class SelectEvent extends BaseEvent {
110
95
  export class FeaturesListedEvent extends BaseEvent {
111
96
  features;
112
97
  constructor(features) {
113
- super("featuresListed");
98
+ super("featureslisted");
114
99
  this.features = features;
115
100
  }
116
101
  }
117
102
  export class FeaturesMarkedEvent extends BaseEvent {
118
103
  features;
119
104
  constructor(features) {
120
- super("featuresMarked");
105
+ super("featuresmarked");
121
106
  this.features = features;
122
107
  }
123
108
  }
124
109
  export class OptionsVisibilityChangeEvent extends BaseEvent {
125
110
  optionsVisible;
126
111
  constructor(optionsVisible) {
127
- super("optionsVisibilityChange");
112
+ super("optionsvisibilitychange");
128
113
  this.optionsVisible = optionsVisible;
129
114
  }
130
115
  }
@@ -138,7 +123,7 @@ export class PickEvent extends BaseEvent {
138
123
  export class QueryChangeEvent extends BaseEvent {
139
124
  query;
140
125
  constructor(query) {
141
- super("queryChange");
126
+ super("querychange");
142
127
  this.query = query;
143
128
  }
144
129
  }
@@ -154,7 +139,7 @@ export class ResponseEvent extends BaseEvent {
154
139
  export class ReverseToggleEvent extends BaseEvent {
155
140
  reverse;
156
141
  constructor(reverse) {
157
- super("reverseToggle");
142
+ super("reversetoggle");
158
143
  this.reverse = reverse;
159
144
  }
160
145
  }
package/svelte/react.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { ControlOptions, DispatcherType, MapController } from "./types";
2
- type EventNames = keyof DispatcherType;
1
+ import type { ControlOptions, DispatcherTypeCC, MapController } from "./types";
2
+ type EventNames = keyof DispatcherTypeCC;
3
3
  type EventHandlerFnName<T extends EventNames> = `on${Capitalize<T>}`;
4
4
  type CallbackProperties<T> = {
5
5
  [K in keyof T as EventHandlerFnName<Extract<K, EventNames>>]?: (event: T[K]) => void;
@@ -7,7 +7,7 @@ type CallbackProperties<T> = {
7
7
  type MapControllerProp = {
8
8
  mapController?: MapController;
9
9
  };
10
- export type Props = ControlOptions & CallbackProperties<DispatcherType> & MapControllerProp;
10
+ export type Props = ControlOptions & CallbackProperties<DispatcherTypeCC> & MapControllerProp;
11
11
  export type Methods = {
12
12
  blur(): void;
13
13
  focus(): void;
@@ -15,5 +15,5 @@ export type Methods = {
15
15
  clearMap(): void;
16
16
  clearList(): void;
17
17
  };
18
- declare const ReactGeocodingControl: import("react").ForwardRefExoticComponent<ControlOptions & CallbackProperties<DispatcherType> & MapControllerProp & import("react").RefAttributes<Methods>>;
18
+ declare const ReactGeocodingControl: import("react").ForwardRefExoticComponent<ControlOptions & CallbackProperties<DispatcherTypeCC> & MapControllerProp & import("react").RefAttributes<Methods>>;
19
19
  export { ReactGeocodingControl as GeocodingControl };
package/svelte/react.js CHANGED
@@ -11,6 +11,7 @@ const eventNames = [
11
11
  "select",
12
12
  ];
13
13
  const propertyNames = [
14
+ "adjustUrlQuery",
14
15
  "apiKey",
15
16
  "bbox",
16
17
  "clearButtonTitle",
@@ -19,25 +20,24 @@ const propertyNames = [
19
20
  "country",
20
21
  "debounceSearch",
21
22
  "enableReverse",
22
- "reverseActive",
23
23
  "errorMessage",
24
+ "excludeTypes",
24
25
  "filter",
25
26
  "fuzzyMatch",
26
27
  "language",
27
28
  "limit",
29
+ "mapController",
28
30
  "minLength",
29
31
  "noResultsMessage",
32
+ "pickedResultStyle",
30
33
  "placeholder",
31
34
  "proximity",
35
+ "reverseActive",
32
36
  "reverseButtonTitle",
33
- "showFullGeometry",
34
37
  "showPlaceType",
35
38
  "showResultsWhileTyping",
36
- "adjustUrlQuery",
37
39
  "types",
38
- "excludeTypes",
39
40
  "zoom",
40
- "mapController",
41
41
  ];
42
42
  function getEventFnName(name) {
43
43
  return ("on" +
package/svelte/types.d.ts CHANGED
@@ -33,7 +33,7 @@ export type MapController = {
33
33
  flyTo(center: Position, zoom?: number): void;
34
34
  fitBounds(bbox: BBox, padding: number, maxZoom?: number): void;
35
35
  indicateReverse(reverse: boolean): void;
36
- setMarkers(features: Feature[] | undefined, picked: Feature | undefined): void;
36
+ setFeatures(features: Feature[] | undefined, picked: Feature | undefined, showPolygonMarker: boolean): void;
37
37
  setReverseMarker(coordinates?: Position): void;
38
38
  setSelectedMarker(index: number): void;
39
39
  getCenterAndZoom(): [zoom: number, lon: number, lat: number] | undefined;
@@ -68,43 +68,51 @@ export type ControlOptions = {
68
68
  /**
69
69
  * Sets the amount of time, in milliseconds, to wait before querying the server when a user types into the Geocoder input box.
70
70
  * This parameter may be useful for reducing the total number of API calls made for a single query.
71
+ *
71
72
  * Default value is `200`.
72
73
  */
73
74
  debounceSearch?: number;
74
75
  /**
75
76
  * Search results closer to the proximity point will be given higher priority. First matching rule from the array will be used.
76
77
  * Set to `null` to disable the proximity.
78
+ *
77
79
  * Default value is `[{ type: "server-geolocation" }]`.
78
80
  */
79
81
  proximity?: ProximityRule[] | null;
80
82
  /**
81
83
  * Override the default placeholder attribute value.
84
+ *
82
85
  * Default value is `"Search"`.
83
86
  */
84
87
  placeholder?: string;
85
88
  /**
86
89
  * Override the default error message.
90
+ *
87
91
  * Default value is `"Something went wrong…"`.
88
92
  */
89
93
  errorMessage?: string;
90
94
  /**
91
95
  * Override the default message if no results are found.
96
+ *
92
97
  * Default value is `"Oops! Looks like you're trying to predict something that's not quite right. We can't seem to find what you're looking for. Maybe try double-checking your spelling or try a different search term. Keep on typing - we'll do our best to get you where you need to go!"`.
93
98
  */
94
99
  noResultsMessage?: string;
95
100
  /**
96
101
  * Minimum number of characters to enter before results are shown.
102
+ *
97
103
  * Default value is `2`.
98
104
  */
99
105
  minLength?: number;
100
106
  /**
101
107
  * A bounding box argument: this is a bounding box given as an array in the format [minX, minY, maxX, maxY].
102
108
  * Search results will be limited to the bounding box.
109
+ *
103
110
  * Default value is `undefined`.
104
111
  */
105
112
  bbox?: BBox;
106
113
  /**
107
114
  * Maximum number of results to show.
115
+ *
108
116
  * Default value is `5`.
109
117
  */
110
118
  limit?: number;
@@ -113,128 +121,144 @@ export type ControlOptions = {
113
121
  * Options are IETF language tags comprised of a mandatory ISO 639-1 language code and optionally one or more IETF subtags for country or script.
114
122
  * More than one value can also be specified, separated by commas.
115
123
  * Set to `null` or empty string for disabling language-specific searching.
116
- * Defaults to the browser's language settings.
117
- * Default value is `undefined`.
124
+ *
125
+ * Default value is `undefined` which means to use the browser's language settings.
118
126
  */
119
127
  language?: string | string[] | null;
120
128
  /**
121
129
  * If `false`, indicates that search will only occur on enter key press.
122
130
  * If `true`, indicates that the Geocoder will search on the input box being updated above the minLength option.
131
+ *
123
132
  * Default value is `false`.
124
133
  */
125
134
  showResultsWhileTyping?: boolean;
126
135
  /**
127
136
  * Set to `false` to disable fuzzy search.
128
- * Default value is `true`
137
+ *
138
+ * Default value is `true`.
129
139
  */
130
140
  fuzzyMatch?: boolean;
131
141
  /**
132
142
  * On geocoded result what zoom level should the map animate to when a bbox in the response isn't present or is a point.
133
143
  * If a bbox is present and not a point then the map will fit to the bbox.
134
144
  *
135
- * Value can be a number (deprecated) or key-value pairs, where key is a &lt;type&gt; or &lt;type&gt;.&lt;categoy&gt; and value is the zoom level.
145
+ * Value is key-value pairs, where key is a &lt;type&gt; or &lt;type&gt;.&lt;categoy&gt; and the value is the zoom level.
136
146
  *
137
147
  * Default value is `GeocodingControl.ZOOM_DEFAULTS`.
138
148
  */
139
- zoom?: number | Record<string, number>;
140
- /**
141
- * On geocoded result what max zoom level should the map animate to when a bbox in the response isn't present or is a point.
142
- * Used for small features.
143
- *
144
- * If a bbox is present and not a point then the map will fit to the bbox.
145
- *
146
- * @deprecated use `zoom` option
147
- */
148
- maxZoom?: number;
149
+ zoom?: Record<string, number>;
149
150
  /**
150
151
  * If `true`, the geocoder control will collapse until hovered or in focus.
152
+ *
151
153
  * Default value is `false`.
152
154
  */
153
155
  collapsed?: boolean;
154
156
  /**
155
157
  * If true, the geocoder control will clear its value when the input blurs.
158
+ *
156
159
  * Default value is `false`.
157
160
  */
158
161
  clearOnBlur?: boolean;
159
162
  /**
160
163
  * A function which accepts a Feature in the Carmen GeoJSON format to filter out results from the Geocoding API response before they are included in the suggestions list.
161
164
  * Return true to keep the item, false otherwise.
165
+ *
166
+ * Default value is a function returning always `true`.
162
167
  */
163
168
  filter?: (feature: Feature) => boolean;
164
169
  /**
165
170
  * Class of the root element.
171
+ *
166
172
  * Default value is `undefined`.
167
173
  */
168
174
  class?: string;
169
175
  /**
170
- * Set to `true` to enable reverse geocoding button with title. Set to `"always"` to reverse geocoding be always active.
171
- * Default value is `false`
176
+ * Set to `button` to enable reverse geocoding button with title. Set to `"always"` to reverse geocoding be always active.
177
+ *
178
+ * Default value is `"never"`.
172
179
  */
173
- enableReverse?: boolean | "always";
180
+ enableReverse?: EnableReverse;
174
181
  /**
175
- * Toggle reverse mode.
182
+ * Reverse mode active.
183
+ *
176
184
  * Default value is `false`.
177
185
  */
178
186
  reverseActive?: boolean;
179
187
  /**
180
- * Reverse toggle button title.
188
+ * Title of the reverse toggle button.
189
+ *
181
190
  * Default value is `"toggle reverse geocoding"`.
182
191
  */
183
192
  reverseButtonTitle?: string;
184
193
  /**
185
- * Clear button title.
194
+ * Title of the clear button.
195
+ *
186
196
  * Default value is `"clear"`.
187
197
  */
188
198
  clearButtonTitle?: string;
189
199
  /**
190
- * Set to `false` to hide place/POI type. If set to `"always"` then type is shown for all items.
191
- * If set to `"ifNeeded"` then type is shown only for places/POIs not determined from the icon.
192
- * Default value is `"ifNeeded"`.
200
+ * Set to `"never"` to hide place/POI type. If set to `"always"` then type is shown for all items.
201
+ * If set to `"if-needed"` then type is shown only for places/POIs not determined from the icon.
202
+ *
203
+ * Default value is `"if-needed"`.
193
204
  */
194
- showPlaceType?: false | "always" | "ifNeeded";
205
+ showPlaceType?: ShowPlaceType;
195
206
  /**
196
- * Set to `true` to show full feature geometry of the chosen result. Otherwise only marker will be shown.
207
+ * Style of the picked result on the map:
208
+ *
209
+ * - `"marker-only"` - show only marker at the center of the feature
210
+ * - `"full-geometry"` - show full feature geometry of the chosen result
211
+ * - `"full-geometry-including-polygon-center-marker"` - show full feature geometry of the chosen result together with a marker in the center of polygon feature
212
+ *
197
213
  * Default value is `true`.
198
214
  */
199
- showFullGeometry?: boolean;
215
+ pickedResultStyle?: PickedResultStyle;
200
216
  /**
201
217
  * Limit search to specified country(ies).
218
+ *
202
219
  * Default value is `undefined` - use all countries.
203
220
  */
204
221
  country?: string | string[];
205
222
  /**
206
223
  * Filter of feature types to return.
224
+ *
207
225
  * Default value is `undefined` - all available feature types are returned.
208
226
  */
209
227
  types?: string[];
210
228
  /**
211
229
  * Use `limit` value for reverse geocoding even if `types` is not an array with a single element.
212
230
  * Will work only if enabled on the server.
231
+ *
213
232
  * Default value is `false`.
214
233
  */
215
234
  exhaustiveReverseGeocoding?: boolean;
216
235
  /**
217
236
  * If set to `true` then use all types except for those listed in `types`.
237
+ *
218
238
  * Default value is `false`.
219
239
  */
220
240
  excludeTypes?: boolean;
221
241
  /**
222
242
  * Geocoding API URL.
243
+ *
223
244
  * Default value is MapTiler Geocoding API URL.
224
245
  */
225
246
  apiUrl?: string;
226
247
  /**
227
248
  * Extra fetch parameters.
249
+ *
228
250
  * Default value is `undefined`.
229
251
  */
230
252
  fetchParameters?: RequestInit;
231
253
  /**
232
254
  * Base URL for POI icons.
255
+ *
233
256
  * Default value is `"icons/"` for Svelte apps, otherwise `"https://cdn.maptiler.com/maptiler-geocoding-control/v${version}/icons/"`.
234
257
  */
235
258
  iconsBaseUrl?: string;
236
259
  /**
237
260
  * Function to adjust URL search parameters.
261
+ *
238
262
  * Default value is empty function.
239
263
  */
240
264
  adjustUrlQuery?: (sp: URLSearchParams) => void;
@@ -257,16 +281,41 @@ export type ControlOptions = {
257
281
  */
258
282
  markerOnSelected?: boolean;
259
283
  };
260
- export type DispatcherType = {
261
- featuresListed: Feature[] | undefined;
262
- featuresMarked: Feature[] | undefined;
263
- optionsVisibilityChange: boolean;
264
- pick: Feature | undefined;
265
- queryChange: string;
284
+ export type PickedResultStyle = "marker-only" | "full-geometry" | "full-geometry-including-polygon-center-marker";
285
+ export type EnableReverse = "never" | "always" | "button";
286
+ export type ShowPlaceType = "never" | "always" | "if-needed";
287
+ export type DispatcherTypeCC = {
288
+ featuresListed: {
289
+ features: Feature[] | undefined;
290
+ };
291
+ featuresMarked: {
292
+ features: Feature[] | undefined;
293
+ };
294
+ optionsVisibilityChange: {
295
+ optionsVisible: boolean;
296
+ };
297
+ pick: {
298
+ feature: Feature | undefined;
299
+ };
300
+ queryChange: {
301
+ query: string;
302
+ };
266
303
  response: {
267
304
  url: string;
268
305
  featureCollection: FeatureCollection;
269
306
  };
270
- reverseToggle: boolean;
271
- select: Feature | undefined;
307
+ reverseToggle: {
308
+ reverse: boolean;
309
+ };
310
+ select: {
311
+ feature: Feature | undefined;
312
+ };
313
+ };
314
+ export type DispatcherType = {
315
+ [T in keyof DispatcherTypeCC as Lowercase<T>]: DispatcherTypeCC[T];
272
316
  };
317
+ export type RedefineType<OriginalType, UpdatedType extends {
318
+ [K in keyof OriginalType]: OriginalType[K];
319
+ } & {
320
+ [K in Exclude<keyof UpdatedType, keyof OriginalType>]: never;
321
+ }> = UpdatedType;
@@ -1,7 +1,17 @@
1
- import type { ControlOptions, MapController } from "./types";
1
+ import type { ControlOptions, DispatcherType, MapController } from "./types";
2
2
  type Options = ControlOptions & {
3
3
  mapController?: MapController;
4
4
  };
5
+ interface GeocodingControlEvent<T> extends CustomEvent<T> {
6
+ readonly target: GeocodingControl;
7
+ readonly currentTarget: GeocodingControl;
8
+ }
9
+ type CustomEventListenerOrEventListenerObject<K extends keyof CustomEventMap> = ((evt: CustomEventMap[K]) => void) | {
10
+ handleEvent(object: CustomEventMap[K]): void;
11
+ };
12
+ type CustomEventMap = {
13
+ [T in keyof DispatcherType]: GeocodingControlEvent<DispatcherType[T]>;
14
+ };
5
15
  export declare class GeocodingControl extends EventTarget {
6
16
  #private;
7
17
  constructor({ target, ...options }: Options & {
@@ -13,5 +23,8 @@ export declare class GeocodingControl extends EventTarget {
13
23
  clearList(): void;
14
24
  focus(): void;
15
25
  blur(): void;
26
+ addEventListener<K extends keyof CustomEventMap>(type: K, callback: CustomEventListenerOrEventListenerObject<K> | null, options?: AddEventListenerOptions | boolean): void;
27
+ removeEventListener<K extends keyof CustomEventMap>(type: K, callback: CustomEventListenerOrEventListenerObject<K> | null, options?: EventListenerOptions | boolean): void;
28
+ dispatchEvent<K extends keyof CustomEventMap>(event: CustomEventMap[K]): boolean;
16
29
  }
17
30
  export {};
package/svelte/vanilla.js CHANGED
@@ -1,4 +1,4 @@
1
- import GC from "./GeocodingControl.svelte";
1
+ import GeocodingControlComponent from "./GeocodingControl.svelte";
2
2
  const finalizationRegistry = new FinalizationRegistry((gc) => {
3
3
  gc.$destroy();
4
4
  });
@@ -6,22 +6,31 @@ export class GeocodingControl extends EventTarget {
6
6
  #gc;
7
7
  constructor({ target, ...options }) {
8
8
  super();
9
- this.#gc = new GC({
9
+ this.#gc = new GeocodingControlComponent({
10
10
  target,
11
11
  props: options,
12
12
  });
13
13
  for (const eventName of [
14
14
  "select",
15
15
  "pick",
16
- "featuresListed",
17
- "featuresMarked",
16
+ "featureslisted",
17
+ "featuresmarked",
18
18
  "response",
19
- "optionsVisibilityChange",
20
- "reverseToggle",
21
- "queryChange",
19
+ "optionsvisibilitychange",
20
+ "reversetoggle",
21
+ "querychange",
22
22
  ]) {
23
- this.#gc.$on(eventName, (event) => this.dispatchEvent(event));
23
+ this.#gc.$on(eventName, (event) => {
24
+ // Use the new `emit` method for type-safe dispatching
25
+ this.#emit(eventName, event.detail);
26
+ });
24
27
  }
28
+ this.#gc.$on("select", (event) => {
29
+ const geocodingEvent = new CustomEvent(event.type, {
30
+ detail: event.detail,
31
+ });
32
+ this.dispatchEvent(geocodingEvent);
33
+ });
25
34
  finalizationRegistry.register(this, this.#gc);
26
35
  }
27
36
  setOptions(options) {
@@ -42,4 +51,18 @@ export class GeocodingControl extends EventTarget {
42
51
  blur() {
43
52
  this.#gc?.blur();
44
53
  }
54
+ addEventListener(type, callback, options) {
55
+ super.addEventListener(type, callback, options);
56
+ }
57
+ removeEventListener(type, callback, options) {
58
+ super.removeEventListener(type, callback, options);
59
+ }
60
+ dispatchEvent(event) {
61
+ return super.dispatchEvent(event);
62
+ }
63
+ #emit(type, detail) {
64
+ return super.dispatchEvent(new CustomEvent(type, {
65
+ detail,
66
+ }));
67
+ }
45
68
  }