@maptiler/geocoding-control 2.1.0-with-autocomplete-timeout → 2.1.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.
- package/leaflet-controller.js +1942 -1523
- package/leaflet-controller.js.map +1 -1
- package/leaflet-controller.umd.js +1 -22
- package/leaflet-controller.umd.js.map +1 -1
- package/leaflet.js +2798 -2385
- package/leaflet.js.map +1 -1
- package/leaflet.umd.js +1 -22
- package/leaflet.umd.js.map +1 -1
- package/maplibregl-controller.js +1918 -1498
- package/maplibregl-controller.js.map +1 -1
- package/maplibregl-controller.umd.js +1 -22
- package/maplibregl-controller.umd.js.map +1 -1
- package/maplibregl.js +2892 -2478
- package/maplibregl.js.map +1 -1
- package/maplibregl.umd.js +1 -22
- package/maplibregl.umd.js.map +1 -1
- package/maptilersdk.js +2898 -2482
- package/maptilersdk.js.map +1 -1
- package/maptilersdk.umd.js +1 -22
- package/maptilersdk.umd.js.map +1 -1
- package/openlayers-controller.js +1686 -1264
- package/openlayers-controller.js.map +1 -1
- package/openlayers-controller.umd.js +1 -22
- package/openlayers-controller.umd.js.map +1 -1
- package/openlayers.js +2778 -2365
- package/openlayers.js.map +1 -1
- package/openlayers.umd.js +1 -22
- package/openlayers.umd.js.map +1 -1
- package/package.json +19 -19
- package/react.js +753 -756
- package/react.js.map +1 -1
- package/react.umd.js +1 -1
- package/react.umd.js.map +1 -1
- package/{MapLibreBasedGeocodingControl.d.ts → src/MapLibreBasedGeocodingControl.d.ts} +35 -69
- package/{maplibregl.d.ts → src/maplibregl.d.ts} +34 -68
- package/{maptilersdk.d.ts → src/maptilersdk.d.ts} +34 -68
- package/src/types.d.ts +391 -0
- package/svelte/GeocodingControl.svelte +71 -58
- package/svelte/GeocodingControl.svelte.d.ts +5 -3
- package/svelte/MapLibreBasedGeocodingControl.d.ts +35 -69
- package/svelte/maplibregl.d.ts +34 -68
- package/svelte/maptilersdk.d.ts +34 -68
- package/svelte/maptilersdk.js +2 -0
- package/svelte/react.js +3 -0
- package/svelte/types.d.ts +175 -128
- package/vanilla.js +847 -853
- package/vanilla.js.map +1 -1
- package/vanilla.umd.js +1 -1
- package/vanilla.umd.js.map +1 -1
- package/types.d.ts +0 -344
- /package/{geo-coordinates-parser.t.d.ts → src/geo-coordinates-parser.t.d.ts} +0 -0
- /package/{geoUtils.d.ts → src/geoUtils.d.ts} +0 -0
- /package/{leaflet-controller.d.ts → src/leaflet-controller.d.ts} +0 -0
- /package/{leaflet.d.ts → src/leaflet.d.ts} +0 -0
- /package/{maplibregl-controller.d.ts → src/maplibregl-controller.d.ts} +0 -0
- /package/{mask.d.ts → src/mask.d.ts} +0 -0
- /package/{openlayers-controller.d.ts → src/openlayers-controller.d.ts} +0 -0
- /package/{openlayers.d.ts → src/openlayers.d.ts} +0 -0
- /package/{proximity.d.ts → src/proximity.d.ts} +0 -0
- /package/{react.d.ts → src/react.d.ts} +0 -0
- /package/{vanilla.d.ts → src/vanilla.d.ts} +0 -0
package/src/types.d.ts
ADDED
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import type { Feature as FeatureType, Geometry } from "geojson";
|
|
2
|
+
export type BBox = [minx: number, miny: number, maxx: number, maxy: number];
|
|
3
|
+
export type Position = [x: number, y: number];
|
|
4
|
+
export type Feature<T extends Geometry = Geometry> = FeatureType<T> & {
|
|
5
|
+
id: string;
|
|
6
|
+
text: string;
|
|
7
|
+
place_name: string;
|
|
8
|
+
place_type: string[];
|
|
9
|
+
center: Position;
|
|
10
|
+
bbox: BBox;
|
|
11
|
+
address?: string;
|
|
12
|
+
matching_text?: string;
|
|
13
|
+
};
|
|
14
|
+
export type FeatureCollection<T extends Geometry = Geometry> = {
|
|
15
|
+
type: "FeatureCollection";
|
|
16
|
+
features: Feature<T>[];
|
|
17
|
+
};
|
|
18
|
+
export type MapEvent = {
|
|
19
|
+
type: "mapClick";
|
|
20
|
+
coordinates: Position;
|
|
21
|
+
} | {
|
|
22
|
+
type: "markerClick";
|
|
23
|
+
id: string;
|
|
24
|
+
} | {
|
|
25
|
+
type: "markerMouseEnter";
|
|
26
|
+
id: string;
|
|
27
|
+
} | {
|
|
28
|
+
type: "markerMouseLeave";
|
|
29
|
+
id: string;
|
|
30
|
+
};
|
|
31
|
+
export type MapController = {
|
|
32
|
+
setEventHandler(handler: undefined | ((e: MapEvent) => void)): void;
|
|
33
|
+
flyTo(center: Position, zoom?: number): void;
|
|
34
|
+
fitBounds(bbox: BBox, padding: number, maxZoom?: number): void;
|
|
35
|
+
indicateReverse(reverse: boolean): void;
|
|
36
|
+
setFeatures(features: Feature[] | undefined, picked: Feature | undefined, showPolygonMarker: boolean): void;
|
|
37
|
+
setReverseMarker(coordinates?: Position): void;
|
|
38
|
+
setSelectedMarker(index: number): void;
|
|
39
|
+
getCenterAndZoom(): [zoom: number, lon: number, lat: number] | undefined;
|
|
40
|
+
};
|
|
41
|
+
export type ProximityRule = {
|
|
42
|
+
/** minimal map zoom for the rule to be used */
|
|
43
|
+
minZoom?: number;
|
|
44
|
+
/** maximal map zoom for the rule to be used */
|
|
45
|
+
maxZoom?: number;
|
|
46
|
+
} & ({
|
|
47
|
+
/** fixed proximity */
|
|
48
|
+
type: "fixed";
|
|
49
|
+
/** coordinates of the fixed proximity */
|
|
50
|
+
coordinates: Position;
|
|
51
|
+
} | {
|
|
52
|
+
/** use map center coordinates for the proximity */
|
|
53
|
+
type: "map-center";
|
|
54
|
+
} | {
|
|
55
|
+
/** resolve proximity by geolocating IP of the geocoding API call */
|
|
56
|
+
type: "server-geolocation";
|
|
57
|
+
} | ({
|
|
58
|
+
/** use browser's geolocation API for proximity. If it fails, following proximity rules are iterated. */
|
|
59
|
+
type: "client-geolocation";
|
|
60
|
+
/** how long should the geolocation result be cached, in milliseconds */
|
|
61
|
+
cachedLocationExpiry?: number;
|
|
62
|
+
} & PositionOptions));
|
|
63
|
+
export type ControlOptions = {
|
|
64
|
+
/**
|
|
65
|
+
* Callback function to adjust URL search parameters.
|
|
66
|
+
*
|
|
67
|
+
* Default: Empty function.
|
|
68
|
+
*
|
|
69
|
+
* @deprecated Use `adjustUrl` instead.
|
|
70
|
+
*/
|
|
71
|
+
adjustUrlQuery?: (sp: URLSearchParams) => void;
|
|
72
|
+
/**
|
|
73
|
+
* Callback function to adjust the geocoding URL before fetching.
|
|
74
|
+
*
|
|
75
|
+
* @param url [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) parameter that can be modified.
|
|
76
|
+
*
|
|
77
|
+
* Default: Empty function.
|
|
78
|
+
*/
|
|
79
|
+
adjustUrl?: (url: URL) => void;
|
|
80
|
+
/**
|
|
81
|
+
* MapTiler API key.
|
|
82
|
+
*/
|
|
83
|
+
apiKey: string;
|
|
84
|
+
/**
|
|
85
|
+
* Geocoding API URL.
|
|
86
|
+
*
|
|
87
|
+
* Default: MapTiler Geocoding API URL.
|
|
88
|
+
*/
|
|
89
|
+
apiUrl?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Bounding box in the format `[minX, minY, maxX, maxY]` to limit search results.
|
|
92
|
+
*
|
|
93
|
+
* Default: `undefined`.
|
|
94
|
+
*/
|
|
95
|
+
bbox?: BBox;
|
|
96
|
+
/**
|
|
97
|
+
* CSS class for the root element.
|
|
98
|
+
*
|
|
99
|
+
* Default: `undefined`.
|
|
100
|
+
*/
|
|
101
|
+
class?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Title of the clear button.
|
|
104
|
+
*
|
|
105
|
+
* Default: `"clear"`.
|
|
106
|
+
*/
|
|
107
|
+
clearButtonTitle?: string;
|
|
108
|
+
/**
|
|
109
|
+
* Clears the result list after picking an item.
|
|
110
|
+
* Prevents redisplaying the list when the input box is focused.
|
|
111
|
+
*
|
|
112
|
+
* Default: `false`.
|
|
113
|
+
*/
|
|
114
|
+
clearListOnPick?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Clears the input value when it loses focus.
|
|
117
|
+
*
|
|
118
|
+
* Default: `false`.
|
|
119
|
+
*/
|
|
120
|
+
clearOnBlur?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Collapses the geocoder control until hovered or focused.
|
|
123
|
+
*
|
|
124
|
+
* Default: `false`.
|
|
125
|
+
*/
|
|
126
|
+
collapsed?: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Limits search to the specified country or countries.
|
|
129
|
+
*
|
|
130
|
+
* Default: `undefined` (all countries).
|
|
131
|
+
*/
|
|
132
|
+
country?: string | string[];
|
|
133
|
+
/**
|
|
134
|
+
* Time delay (in milliseconds) before querying the server after typing in the input box.
|
|
135
|
+
* Useful for reducing the number of API calls.
|
|
136
|
+
*
|
|
137
|
+
* Default: `200`.
|
|
138
|
+
*/
|
|
139
|
+
debounceSearch?: number;
|
|
140
|
+
/**
|
|
141
|
+
* Enables reverse geocoding:
|
|
142
|
+
* - `"button"`: Enables reverse geocoding button.
|
|
143
|
+
* - `"always"`: Reverse geocoding is always active.
|
|
144
|
+
*
|
|
145
|
+
* Default: `"never"`.
|
|
146
|
+
*/
|
|
147
|
+
enableReverse?: EnableReverse;
|
|
148
|
+
/**
|
|
149
|
+
* Custom error message.
|
|
150
|
+
*
|
|
151
|
+
* Default: `"Something went wrong…"`.
|
|
152
|
+
*/
|
|
153
|
+
errorMessage?: string;
|
|
154
|
+
/**
|
|
155
|
+
* Includes all available types except those listed in the `types` option.
|
|
156
|
+
*
|
|
157
|
+
* See `reverseGeocodingExcludeTypes` for reverse geocoding exclusion.
|
|
158
|
+
*
|
|
159
|
+
* Default: `false`.
|
|
160
|
+
*/
|
|
161
|
+
excludeTypes?: boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Uses the `limit` option value for reverse geocoding even if the `types` option has multiple elements.
|
|
164
|
+
* Works only if enabled on the server.
|
|
165
|
+
*
|
|
166
|
+
* Default: `false`.
|
|
167
|
+
*/
|
|
168
|
+
exhaustiveReverseGeocoding?: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Additional parameters for fetch requests.
|
|
171
|
+
*
|
|
172
|
+
* Default: `undefined`.
|
|
173
|
+
*/
|
|
174
|
+
fetchParameters?: RequestInit;
|
|
175
|
+
/**
|
|
176
|
+
* Callback function to filter results from the Geocoding API response.
|
|
177
|
+
* The function should return `true` to keep an item, or `false` to exclude it.
|
|
178
|
+
*
|
|
179
|
+
* Default: A function that always returns `true`.
|
|
180
|
+
*/
|
|
181
|
+
filter?: (feature: Feature) => boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Animates the map to the selected feature from the result list.
|
|
184
|
+
*
|
|
185
|
+
* Default: `false`.
|
|
186
|
+
*/
|
|
187
|
+
flyToSelected?: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Enables fuzzy search.
|
|
190
|
+
*
|
|
191
|
+
* Default: `true`.
|
|
192
|
+
*/
|
|
193
|
+
fuzzyMatch?: boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Base URL for POI icons.
|
|
196
|
+
*
|
|
197
|
+
* Default:
|
|
198
|
+
* - `"icons/"` for Svelte apps.
|
|
199
|
+
* - `"https://cdn.maptiler.com/maptiler-geocoding-control/v${version}/icons/"` for others.
|
|
200
|
+
*/
|
|
201
|
+
iconsBaseUrl?: string;
|
|
202
|
+
/**
|
|
203
|
+
* Keeps the result list open even if the control is unfocused.
|
|
204
|
+
*
|
|
205
|
+
* Default: `false`.
|
|
206
|
+
*/
|
|
207
|
+
keepListOpen?: boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Language for response text and query weighting.
|
|
210
|
+
* Accepts IETF language tags.
|
|
211
|
+
* Set to `null` or an empty string to disable language-specific searching.
|
|
212
|
+
*
|
|
213
|
+
* Default: `undefined` (uses the browser's language settings).
|
|
214
|
+
*/
|
|
215
|
+
language?: string | string[] | null;
|
|
216
|
+
/**
|
|
217
|
+
* Maximum number of results to display.
|
|
218
|
+
*
|
|
219
|
+
* See `reverseGeocodingLimit` for reverse geocoding limits.
|
|
220
|
+
*
|
|
221
|
+
* Default: `5`.
|
|
222
|
+
*/
|
|
223
|
+
limit?: number;
|
|
224
|
+
/**
|
|
225
|
+
* Displays a marker on the selected feature from the result list.
|
|
226
|
+
*
|
|
227
|
+
* Default: `true`.
|
|
228
|
+
*/
|
|
229
|
+
markerOnSelected?: boolean;
|
|
230
|
+
/**
|
|
231
|
+
* Minimum number of characters required to start a search.
|
|
232
|
+
*
|
|
233
|
+
* Default: `2`.
|
|
234
|
+
*/
|
|
235
|
+
minLength?: number;
|
|
236
|
+
/**
|
|
237
|
+
* Custom message for when no results are found.
|
|
238
|
+
*
|
|
239
|
+
* Default:
|
|
240
|
+
* ```
|
|
241
|
+
* "Oops! Looks like you're trying to predict something that's not quite right.
|
|
242
|
+
* We can't seem to find what you're looking for. Maybe try double-checking your spelling or try a different search term.
|
|
243
|
+
* Keep on typing - we'll do our best to get you where you need to go!"
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
noResultsMessage?: string;
|
|
247
|
+
/**
|
|
248
|
+
* Style of the picked result on the map:
|
|
249
|
+
* - `"marker-only"`: Show only a marker at the center of the feature.
|
|
250
|
+
* - `"full-geometry"`: Display the full feature geometry.
|
|
251
|
+
* - `"full-geometry-including-polygon-center-marker"`: Display full geometry with a marker at the polygon center.
|
|
252
|
+
*
|
|
253
|
+
* Default: `"full-geometry"`.
|
|
254
|
+
*/
|
|
255
|
+
pickedResultStyle?: PickedResultStyle;
|
|
256
|
+
/**
|
|
257
|
+
* Custom placeholder for the input box.
|
|
258
|
+
*
|
|
259
|
+
* Default: `"Search"`.
|
|
260
|
+
*/
|
|
261
|
+
placeholder?: string;
|
|
262
|
+
/**
|
|
263
|
+
* Prioritizes search results closer to a proximity point.
|
|
264
|
+
* The first matching rule in the array is used.
|
|
265
|
+
* Set to `null` to disable proximity.
|
|
266
|
+
*
|
|
267
|
+
* Default: `[ { type: "server-geolocation" } ]`.
|
|
268
|
+
*/
|
|
269
|
+
proximity?: ProximityRule[] | null;
|
|
270
|
+
/**
|
|
271
|
+
* Activates reverse geocoding.
|
|
272
|
+
*
|
|
273
|
+
* Default: `false`.
|
|
274
|
+
*/
|
|
275
|
+
reverseActive?: boolean;
|
|
276
|
+
/**
|
|
277
|
+
* Title of the reverse geocoding toggle button.
|
|
278
|
+
*
|
|
279
|
+
* Default: `"toggle reverse geocoding"`.
|
|
280
|
+
*/
|
|
281
|
+
reverseButtonTitle?: string;
|
|
282
|
+
/**
|
|
283
|
+
* Excludes types for reverse geocoding.
|
|
284
|
+
*
|
|
285
|
+
* Default: Same as `excludeTypes`.
|
|
286
|
+
*/
|
|
287
|
+
reverseGeocodingExcludeTypes?: boolean;
|
|
288
|
+
/**
|
|
289
|
+
* Limits results for reverse geocoding.
|
|
290
|
+
* Applied only if value is 1 or effective types contain a single value.
|
|
291
|
+
*
|
|
292
|
+
* See also `reverseGeocodingTypes` option.
|
|
293
|
+
*
|
|
294
|
+
* Default: The value of the `limit` option if set. If effective types contain a single value, the default is `1`. In all other cases, this option is not used.
|
|
295
|
+
*/
|
|
296
|
+
reverseGeocodingLimit?: number;
|
|
297
|
+
/**
|
|
298
|
+
* Specifies types for reverse geocoding.
|
|
299
|
+
*
|
|
300
|
+
* If effective types are multiple values, the `limit`/`reverseGeocodingLimit` option is ignored.
|
|
301
|
+
*
|
|
302
|
+
* See also `reverseGeocodingLimit` option.
|
|
303
|
+
*
|
|
304
|
+
* Default: Same as `types`.
|
|
305
|
+
*/
|
|
306
|
+
reverseGeocodingTypes?: TypeRule[];
|
|
307
|
+
/**
|
|
308
|
+
* Automatically selects the first feature in the result list.
|
|
309
|
+
*
|
|
310
|
+
* Default: `true`.
|
|
311
|
+
*/
|
|
312
|
+
selectFirst?: boolean;
|
|
313
|
+
/**
|
|
314
|
+
* Indicates when to show place/POI types in the dropdown:
|
|
315
|
+
* - `"never"`: Hide the type.
|
|
316
|
+
* - `"always"`: Always show the type.
|
|
317
|
+
* - `"if-needed"`: Show the type only if it cannot be determined from the icon.
|
|
318
|
+
*
|
|
319
|
+
* Default: `"if-needed"`.
|
|
320
|
+
*/
|
|
321
|
+
showPlaceType?: ShowPlaceType;
|
|
322
|
+
/**
|
|
323
|
+
* Displays results while typing:
|
|
324
|
+
* - `false`: Search occurs only on pressing the Enter key.
|
|
325
|
+
* - `true`: Search begins when the input meets the `minLength` requirement.
|
|
326
|
+
*
|
|
327
|
+
* Default: `false`.
|
|
328
|
+
*/
|
|
329
|
+
showResultsWhileTyping?: boolean;
|
|
330
|
+
/**
|
|
331
|
+
* Types to query, either as an array or `[minZoom, maxZoom, type]` format.
|
|
332
|
+
* `minZoom` is inclusive, `maxZoom` is exclusive, and either can be `null` or `undefined` for unbounded values.
|
|
333
|
+
*
|
|
334
|
+
* See `reverseGeocodingTypes` option for reverse geocoding types.
|
|
335
|
+
*
|
|
336
|
+
* Default: `undefined` (uses server default feature types).
|
|
337
|
+
*/
|
|
338
|
+
types?: TypeRule[];
|
|
339
|
+
/**
|
|
340
|
+
* Specifies the zoom level to animate the map to for a geocoded result when no bounding box is present or when the result is a point.
|
|
341
|
+
* If a bounding box is present and not a point, the map will fit to the bounding box.
|
|
342
|
+
*
|
|
343
|
+
* Values are key-value pairs where the key is a `<type>` or `<type>.<category>` and the value is the zoom level.
|
|
344
|
+
*
|
|
345
|
+
* Default: `GeocodingControl.ZOOM_DEFAULTS`.
|
|
346
|
+
*/
|
|
347
|
+
zoom?: Record<string, number>;
|
|
348
|
+
};
|
|
349
|
+
export type PickedResultStyle = "marker-only" | "full-geometry" | "full-geometry-including-polygon-center-marker";
|
|
350
|
+
export type EnableReverse = "never" | "always" | "button";
|
|
351
|
+
export type ShowPlaceType = "never" | "always" | "if-needed";
|
|
352
|
+
export type DispatcherTypeCC = {
|
|
353
|
+
featuresListed: {
|
|
354
|
+
features: Feature[] | undefined;
|
|
355
|
+
};
|
|
356
|
+
featuresMarked: {
|
|
357
|
+
features: Feature[] | undefined;
|
|
358
|
+
};
|
|
359
|
+
optionsVisibilityChange: {
|
|
360
|
+
optionsVisible: boolean;
|
|
361
|
+
};
|
|
362
|
+
pick: {
|
|
363
|
+
feature: Feature | undefined;
|
|
364
|
+
};
|
|
365
|
+
queryChange: {
|
|
366
|
+
query: string;
|
|
367
|
+
};
|
|
368
|
+
response: {
|
|
369
|
+
url: string;
|
|
370
|
+
featureCollection: FeatureCollection;
|
|
371
|
+
};
|
|
372
|
+
reverseToggle: {
|
|
373
|
+
reverse: boolean;
|
|
374
|
+
};
|
|
375
|
+
select: {
|
|
376
|
+
feature: Feature | undefined;
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
export type DispatcherType = {
|
|
380
|
+
[T in keyof DispatcherTypeCC as Lowercase<T>]: DispatcherTypeCC[T];
|
|
381
|
+
};
|
|
382
|
+
export type RedefineType<OriginalType, UpdatedType extends {
|
|
383
|
+
[K in keyof OriginalType]: OriginalType[K];
|
|
384
|
+
} & {
|
|
385
|
+
[K in Exclude<keyof UpdatedType, keyof OriginalType>]: never;
|
|
386
|
+
}> = UpdatedType;
|
|
387
|
+
export type TypeRule = string | [
|
|
388
|
+
minZoom: number | null | undefined,
|
|
389
|
+
maxZoom: number | null | undefined,
|
|
390
|
+
type: string
|
|
391
|
+
];
|
|
@@ -52,6 +52,8 @@ export let flyTo = true;
|
|
|
52
52
|
export let fuzzyMatch = true;
|
|
53
53
|
export let language = undefined;
|
|
54
54
|
export let limit = undefined;
|
|
55
|
+
const COPY_LIMIT = +41415112612;
|
|
56
|
+
export let reverseGeocodingLimit = COPY_LIMIT;
|
|
55
57
|
export let mapController = undefined;
|
|
56
58
|
export let minLength = 2;
|
|
57
59
|
export let noResultsMessage = "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!";
|
|
@@ -65,18 +67,21 @@ export let searchValue = "";
|
|
|
65
67
|
export let pickedResultStyle = "full-geometry";
|
|
66
68
|
export let showPlaceType = "if-needed";
|
|
67
69
|
export let showResultsWhileTyping = true;
|
|
68
|
-
export let autocompleteTimeout = undefined;
|
|
69
70
|
export let selectFirst = true;
|
|
70
71
|
export let flyToSelected = false;
|
|
71
72
|
export let markerOnSelected = true;
|
|
72
73
|
export let types = undefined;
|
|
74
|
+
const COPY_TYPES = [];
|
|
75
|
+
export let reverseGeocodingTypes = COPY_TYPES;
|
|
73
76
|
export let exhaustiveReverseGeocoding = false;
|
|
74
77
|
export let excludeTypes = false;
|
|
78
|
+
const COPY_EXCLUDE_TYPES = undefined;
|
|
79
|
+
export let reverseGeocodingExcludeTypes = COPY_EXCLUDE_TYPES;
|
|
75
80
|
export let zoom = ZOOM_DEFAULTS;
|
|
76
81
|
export let apiUrl = "https://api.maptiler.com/geocoding";
|
|
77
82
|
export let fetchParameters = {};
|
|
78
83
|
export let iconsBaseUrl = "https://cdn.maptiler.com/maptiler-geocoding-control/v" +
|
|
79
|
-
"2.1.
|
|
84
|
+
"2.1.1" +
|
|
80
85
|
"/icons/";
|
|
81
86
|
/**
|
|
82
87
|
* @deprecated use `adjustUrl`
|
|
@@ -145,7 +150,6 @@ let error;
|
|
|
145
150
|
let cachedFeatures = [];
|
|
146
151
|
let abortController;
|
|
147
152
|
let searchTimeoutRef;
|
|
148
|
-
let autocompleteTimeoutRef;
|
|
149
153
|
let focusedDelayed;
|
|
150
154
|
let prevIdToFly;
|
|
151
155
|
let focused = false;
|
|
@@ -205,14 +209,6 @@ $: setTimeout(() => {
|
|
|
205
209
|
searchValue = "";
|
|
206
210
|
}
|
|
207
211
|
});
|
|
208
|
-
function isInAutocompleteTimeout() {
|
|
209
|
-
return !!autocompleteTimeoutRef;
|
|
210
|
-
}
|
|
211
|
-
$: if (selectFirst && listFeatures?.length) {
|
|
212
|
-
if (!isInAutocompleteTimeout()) {
|
|
213
|
-
selectedItemIndex = 0;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
212
|
$: if (selectFirst &&
|
|
217
213
|
listFeatures?.length &&
|
|
218
214
|
selectedItemIndex == -1 &&
|
|
@@ -220,10 +216,6 @@ $: if (selectFirst &&
|
|
|
220
216
|
selectedItemIndex = 0;
|
|
221
217
|
}
|
|
222
218
|
$: selected = listFeatures?.[selectedItemIndex];
|
|
223
|
-
$: if (selected) {
|
|
224
|
-
window.clearTimeout(autocompleteTimeoutRef);
|
|
225
|
-
autocompleteTimeoutRef = undefined;
|
|
226
|
-
}
|
|
227
219
|
$: if (mapController) {
|
|
228
220
|
const coords = isQueryReverse(searchValue);
|
|
229
221
|
mapController.setReverseMarker(coords ? [coords.decimalLongitude, coords.decimalLatitude] : undefined);
|
|
@@ -283,15 +275,9 @@ onDestroy(() => {
|
|
|
283
275
|
function handleSubmit(event) {
|
|
284
276
|
focused = false;
|
|
285
277
|
if (searchTimeoutRef) {
|
|
286
|
-
|
|
278
|
+
clearTimeout(searchTimeoutRef);
|
|
287
279
|
searchTimeoutRef = undefined;
|
|
288
280
|
}
|
|
289
|
-
if (autocompleteTimeoutRef) {
|
|
290
|
-
window.clearTimeout(autocompleteTimeoutRef);
|
|
291
|
-
autocompleteTimeoutRef = undefined;
|
|
292
|
-
search(searchValue, { appendSpace: true });
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
281
|
if (selectedItemIndex > -1 && listFeatures) {
|
|
296
282
|
picked = listFeatures[selectedItemIndex];
|
|
297
283
|
searchValue =
|
|
@@ -323,7 +309,7 @@ function isQueryReverse(searchValue) {
|
|
|
323
309
|
return false;
|
|
324
310
|
}
|
|
325
311
|
}
|
|
326
|
-
async function search(searchValue, { byId = false, exact = false,
|
|
312
|
+
async function search(searchValue, { byId = false, exact = false, } = {}) {
|
|
327
313
|
error = undefined;
|
|
328
314
|
abortController?.abort();
|
|
329
315
|
const ac = new AbortController();
|
|
@@ -334,17 +320,32 @@ async function search(searchValue, { byId = false, exact = false, appendSpace =
|
|
|
334
320
|
"/" +
|
|
335
321
|
encodeURIComponent(isReverse
|
|
336
322
|
? isReverse.decimalLongitude + "," + isReverse.decimalLatitude
|
|
337
|
-
: searchValue
|
|
323
|
+
: searchValue) +
|
|
338
324
|
".json");
|
|
339
325
|
const sp = urlObj.searchParams;
|
|
340
326
|
if (language !== undefined) {
|
|
341
327
|
sp.set("language", Array.isArray(language) ? language.join(",") : (language ?? ""));
|
|
342
328
|
}
|
|
343
|
-
|
|
344
|
-
|
|
329
|
+
const [zoom] = mapController?.getCenterAndZoom() ?? [];
|
|
330
|
+
let effTypes = (!isReverse || reverseGeocodingTypes === COPY_TYPES
|
|
331
|
+
? types
|
|
332
|
+
: reverseGeocodingTypes)
|
|
333
|
+
?.map((typeRule) => typeof typeRule === "string"
|
|
334
|
+
? typeRule
|
|
335
|
+
: zoom === undefined ||
|
|
336
|
+
((typeRule[0] ?? 0) <= zoom && zoom < (typeRule[1] ?? Infinity))
|
|
337
|
+
? typeRule[2]
|
|
338
|
+
: undefined)
|
|
339
|
+
.filter((type) => type !== undefined);
|
|
340
|
+
if (effTypes) {
|
|
341
|
+
effTypes = [...new Set(effTypes)];
|
|
342
|
+
sp.set("types", effTypes.join(","));
|
|
345
343
|
}
|
|
346
|
-
|
|
347
|
-
|
|
344
|
+
const effExcludeTypes = !isReverse || reverseGeocodingExcludeTypes === COPY_EXCLUDE_TYPES
|
|
345
|
+
? excludeTypes
|
|
346
|
+
: reverseGeocodingExcludeTypes;
|
|
347
|
+
if (effExcludeTypes) {
|
|
348
|
+
sp.set("excludeTypes", String(effExcludeTypes));
|
|
348
349
|
}
|
|
349
350
|
if (bbox) {
|
|
350
351
|
sp.set("bbox", bbox.map((c) => c.toFixed(6)).join(","));
|
|
@@ -362,13 +363,27 @@ async function search(searchValue, { byId = false, exact = false, appendSpace =
|
|
|
362
363
|
}
|
|
363
364
|
sp.set("fuzzyMatch", String(fuzzyMatch));
|
|
364
365
|
}
|
|
365
|
-
|
|
366
|
-
|
|
366
|
+
const effReverseGeocodingLimit = reverseGeocodingLimit === COPY_LIMIT ? limit : reverseGeocodingLimit;
|
|
367
|
+
if (effReverseGeocodingLimit !== undefined &&
|
|
368
|
+
effReverseGeocodingLimit > 1 &&
|
|
369
|
+
effTypes?.length !== 1) {
|
|
370
|
+
console.warn("For reverse geocoding when limit > 1 then types must contain single value.");
|
|
371
|
+
}
|
|
372
|
+
if (isReverse) {
|
|
373
|
+
if (effReverseGeocodingLimit === 1 ||
|
|
374
|
+
(effReverseGeocodingLimit !== undefined &&
|
|
375
|
+
(exhaustiveReverseGeocoding || effTypes?.length === 1))) {
|
|
376
|
+
sp.set("limit", String(effReverseGeocodingLimit));
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
else if (limit !== undefined) {
|
|
367
380
|
sp.set("limit", String(limit));
|
|
368
381
|
}
|
|
369
382
|
sp.set("key", apiKey);
|
|
370
383
|
adjustUrlQuery(sp);
|
|
371
384
|
adjustUrl(urlObj);
|
|
385
|
+
const noTypes = urlObj.searchParams.get("types") === "" &&
|
|
386
|
+
urlObj.searchParams.get("excludeTypes") !== "true";
|
|
372
387
|
const url = urlObj.toString();
|
|
373
388
|
if (url === lastSearchUrl) {
|
|
374
389
|
if (byId) {
|
|
@@ -386,14 +401,20 @@ async function search(searchValue, { byId = false, exact = false, appendSpace =
|
|
|
386
401
|
return;
|
|
387
402
|
}
|
|
388
403
|
lastSearchUrl = url;
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
|
|
404
|
+
let featureCollection;
|
|
405
|
+
if (noTypes) {
|
|
406
|
+
featureCollection = { type: "FeatureCollection", features: [] };
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
const res = await fetch(url, {
|
|
410
|
+
signal: ac.signal,
|
|
411
|
+
...fetchParameters,
|
|
412
|
+
});
|
|
413
|
+
if (!res.ok) {
|
|
414
|
+
throw new Error(await res.text());
|
|
415
|
+
}
|
|
416
|
+
featureCollection = await res.json();
|
|
395
417
|
}
|
|
396
|
-
const featureCollection = await res.json();
|
|
397
418
|
dispatch("response", { url, featureCollection });
|
|
398
419
|
if (byId) {
|
|
399
420
|
if (clearListOnPick) {
|
|
@@ -549,29 +570,21 @@ function handleInput(_, debounce = true, reverse = false) {
|
|
|
549
570
|
error = undefined;
|
|
550
571
|
picked = undefined;
|
|
551
572
|
focused = true;
|
|
552
|
-
if (
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
573
|
+
if (showResultsWhileTyping || reverse) {
|
|
574
|
+
if (searchTimeoutRef) {
|
|
575
|
+
clearTimeout(searchTimeoutRef);
|
|
576
|
+
}
|
|
577
|
+
if (searchValue.length < minLength) {
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
const sv = searchValue;
|
|
581
|
+
searchTimeoutRef = window.setTimeout(() => {
|
|
582
|
+
search(sv).catch((err) => (error = err));
|
|
583
|
+
}, debounce ? debounceSearch : 0);
|
|
559
584
|
}
|
|
560
|
-
|
|
561
|
-
searchValue.length < minLength) {
|
|
585
|
+
else {
|
|
562
586
|
listFeatures = undefined;
|
|
563
|
-
|
|
564
|
-
}
|
|
565
|
-
const sv = searchValue;
|
|
566
|
-
searchTimeoutRef = window.setTimeout(() => {
|
|
567
|
-
searchTimeoutRef = undefined;
|
|
568
|
-
search(sv).catch((err) => (error = err));
|
|
569
|
-
}, debounce ? debounceSearch : 0);
|
|
570
|
-
if (!searchValue.endsWith(" ")) {
|
|
571
|
-
autocompleteTimeoutRef = window.setTimeout(() => {
|
|
572
|
-
autocompleteTimeoutRef = undefined;
|
|
573
|
-
search(sv, { appendSpace: true }).catch((err) => (error = err));
|
|
574
|
-
}, autocompleteTimeout);
|
|
587
|
+
error = undefined;
|
|
575
588
|
}
|
|
576
589
|
}
|
|
577
590
|
function pick(feature) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
|
-
import type { BBox, EnableReverse, Feature, FeatureCollection, MapController, PickedResultStyle, ProximityRule, ShowPlaceType } from "./types";
|
|
2
|
+
import type { BBox, EnableReverse, Feature, FeatureCollection, MapController, PickedResultStyle, ProximityRule, ShowPlaceType, TypeRule } from "./types";
|
|
3
3
|
declare const __propDef: {
|
|
4
4
|
props: {
|
|
5
5
|
ZOOM_DEFAULTS?: Record<string, number>;
|
|
@@ -20,6 +20,7 @@ declare const __propDef: {
|
|
|
20
20
|
fuzzyMatch?: boolean;
|
|
21
21
|
language?: string | string[] | null | undefined;
|
|
22
22
|
limit?: number | undefined;
|
|
23
|
+
reverseGeocodingLimit?: number | undefined;
|
|
23
24
|
mapController?: MapController | undefined;
|
|
24
25
|
minLength?: number;
|
|
25
26
|
noResultsMessage?: string;
|
|
@@ -31,13 +32,14 @@ declare const __propDef: {
|
|
|
31
32
|
pickedResultStyle?: PickedResultStyle;
|
|
32
33
|
showPlaceType?: ShowPlaceType;
|
|
33
34
|
showResultsWhileTyping?: boolean;
|
|
34
|
-
autocompleteTimeout?: number | undefined;
|
|
35
35
|
selectFirst?: boolean;
|
|
36
36
|
flyToSelected?: boolean;
|
|
37
37
|
markerOnSelected?: boolean;
|
|
38
|
-
types?:
|
|
38
|
+
types?: TypeRule[] | undefined;
|
|
39
|
+
reverseGeocodingTypes?: TypeRule[] | undefined;
|
|
39
40
|
exhaustiveReverseGeocoding?: boolean;
|
|
40
41
|
excludeTypes?: boolean;
|
|
42
|
+
reverseGeocodingExcludeTypes?: boolean | undefined;
|
|
41
43
|
zoom?: Record<string, number>;
|
|
42
44
|
apiUrl?: string;
|
|
43
45
|
fetchParameters?: RequestInit;
|