@maptiler/geocoding-control 2.1.0-rc1 → 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 +2800 -2368
- 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 +2858 -2425
- package/maplibregl.js.map +1 -1
- package/maplibregl.umd.js +1 -22
- package/maplibregl.umd.js.map +1 -1
- package/maptilersdk.js +2863 -2428
- 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 +2785 -2353
- 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 +800 -784
- 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 +55 -14
- package/svelte/GeocodingControl.svelte.d.ts +5 -2
- 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 -127
- package/vanilla.js +870 -857
- package/vanilla.js.map +1 -1
- package/vanilla.umd.js +1 -1
- package/vanilla.umd.js.map +1 -1
- package/types.d.ts +0 -343
- /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!";
|
|
@@ -69,13 +71,17 @@ export let selectFirst = true;
|
|
|
69
71
|
export let flyToSelected = false;
|
|
70
72
|
export let markerOnSelected = true;
|
|
71
73
|
export let types = undefined;
|
|
74
|
+
const COPY_TYPES = [];
|
|
75
|
+
export let reverseGeocodingTypes = COPY_TYPES;
|
|
72
76
|
export let exhaustiveReverseGeocoding = false;
|
|
73
77
|
export let excludeTypes = false;
|
|
78
|
+
const COPY_EXCLUDE_TYPES = undefined;
|
|
79
|
+
export let reverseGeocodingExcludeTypes = COPY_EXCLUDE_TYPES;
|
|
74
80
|
export let zoom = ZOOM_DEFAULTS;
|
|
75
81
|
export let apiUrl = "https://api.maptiler.com/geocoding";
|
|
76
82
|
export let fetchParameters = {};
|
|
77
83
|
export let iconsBaseUrl = "https://cdn.maptiler.com/maptiler-geocoding-control/v" +
|
|
78
|
-
"2.1.
|
|
84
|
+
"2.1.1" +
|
|
79
85
|
"/icons/";
|
|
80
86
|
/**
|
|
81
87
|
* @deprecated use `adjustUrl`
|
|
@@ -320,11 +326,26 @@ async function search(searchValue, { byId = false, exact = false, } = {}) {
|
|
|
320
326
|
if (language !== undefined) {
|
|
321
327
|
sp.set("language", Array.isArray(language) ? language.join(",") : (language ?? ""));
|
|
322
328
|
}
|
|
323
|
-
|
|
324
|
-
|
|
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(","));
|
|
325
343
|
}
|
|
326
|
-
|
|
327
|
-
|
|
344
|
+
const effExcludeTypes = !isReverse || reverseGeocodingExcludeTypes === COPY_EXCLUDE_TYPES
|
|
345
|
+
? excludeTypes
|
|
346
|
+
: reverseGeocodingExcludeTypes;
|
|
347
|
+
if (effExcludeTypes) {
|
|
348
|
+
sp.set("excludeTypes", String(effExcludeTypes));
|
|
328
349
|
}
|
|
329
350
|
if (bbox) {
|
|
330
351
|
sp.set("bbox", bbox.map((c) => c.toFixed(6)).join(","));
|
|
@@ -342,13 +363,27 @@ async function search(searchValue, { byId = false, exact = false, } = {}) {
|
|
|
342
363
|
}
|
|
343
364
|
sp.set("fuzzyMatch", String(fuzzyMatch));
|
|
344
365
|
}
|
|
345
|
-
|
|
346
|
-
|
|
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) {
|
|
347
380
|
sp.set("limit", String(limit));
|
|
348
381
|
}
|
|
349
382
|
sp.set("key", apiKey);
|
|
350
383
|
adjustUrlQuery(sp);
|
|
351
384
|
adjustUrl(urlObj);
|
|
385
|
+
const noTypes = urlObj.searchParams.get("types") === "" &&
|
|
386
|
+
urlObj.searchParams.get("excludeTypes") !== "true";
|
|
352
387
|
const url = urlObj.toString();
|
|
353
388
|
if (url === lastSearchUrl) {
|
|
354
389
|
if (byId) {
|
|
@@ -366,14 +401,20 @@ async function search(searchValue, { byId = false, exact = false, } = {}) {
|
|
|
366
401
|
return;
|
|
367
402
|
}
|
|
368
403
|
lastSearchUrl = url;
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
|
|
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();
|
|
375
417
|
}
|
|
376
|
-
const featureCollection = await res.json();
|
|
377
418
|
dispatch("response", { url, featureCollection });
|
|
378
419
|
if (byId) {
|
|
379
420
|
if (clearListOnPick) {
|
|
@@ -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;
|
|
@@ -34,9 +35,11 @@ declare const __propDef: {
|
|
|
34
35
|
selectFirst?: boolean;
|
|
35
36
|
flyToSelected?: boolean;
|
|
36
37
|
markerOnSelected?: boolean;
|
|
37
|
-
types?:
|
|
38
|
+
types?: TypeRule[] | undefined;
|
|
39
|
+
reverseGeocodingTypes?: TypeRule[] | undefined;
|
|
38
40
|
exhaustiveReverseGeocoding?: boolean;
|
|
39
41
|
excludeTypes?: boolean;
|
|
42
|
+
reverseGeocodingExcludeTypes?: boolean | undefined;
|
|
40
43
|
zoom?: Record<string, number>;
|
|
41
44
|
apiUrl?: string;
|
|
42
45
|
fetchParameters?: RequestInit;
|