@maptiler/geocoding-control 0.0.79 → 0.0.81
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/ClearIcon.svelte.d.ts +23 -0
- package/GeocodingControl.svelte +685 -0
- package/GeocodingControl.svelte.d.ts +66 -0
- package/LoadingIcon.svelte.d.ts +23 -0
- package/{src/lib/MarkerIcon.svelte → MarkerIcon.svelte} +1 -2
- package/MarkerIcon.svelte.d.ts +16 -0
- package/ReverseGeocodingIcon.svelte.d.ts +23 -0
- package/SearchIcon.svelte.d.ts +23 -0
- package/leaflet-controller.js +1 -0
- package/leaflet-controller.js.map +1 -0
- package/leaflet-controller.umd.js +1 -0
- package/leaflet-controller.umd.js.map +1 -0
- package/leaflet.js +3943 -3970
- package/leaflet.js.map +1 -0
- package/leaflet.umd.js +6 -5
- package/leaflet.umd.js.map +1 -0
- package/maplibregl-controller.js +1 -0
- package/maplibregl-controller.js.map +1 -0
- package/maplibregl-controller.umd.js +1 -0
- package/maplibregl-controller.umd.js.map +1 -0
- package/maplibregl.js +4028 -4055
- package/maplibregl.js.map +1 -0
- package/maplibregl.umd.js +6 -5
- package/maplibregl.umd.js.map +1 -0
- package/package.json +20 -20
- package/react.js +470 -552
- package/react.js.map +1 -0
- package/react.umd.js +2 -1
- package/react.umd.js.map +1 -0
- package/style.css +1 -1
- package/src/AppLeaflet.svelte +0 -55
- package/src/AppMaplibregl.svelte +0 -45
- package/src/lib/GeocodingControl.svelte +0 -851
- package/src/lib/LeafletGeocodingControl.ts +0 -154
- package/src/lib/MaplibreglGeocodingControl.ts +0 -160
- package/src/lib/ReactGeocodingControl.ts +0 -158
- package/src/lib/leafletMapController.ts +0 -305
- package/src/lib/maplibreglMapController.ts +0 -366
- package/src/lib/mask.ts +0 -70
- package/src/lib/types.ts +0 -235
- package/src/main-copy.ts +0 -59
- package/src/main.ts +0 -65
- package/src/vite-env.d.ts +0 -2
- /package/{src/lib/ClearIcon.svelte → ClearIcon.svelte} +0 -0
- /package/{src/lib/LoadingIcon.svelte → LoadingIcon.svelte} +0 -0
- /package/{src/lib/ReverseGeocodingIcon.svelte → ReverseGeocodingIcon.svelte} +0 -0
- /package/{src/lib/SearchIcon.svelte → SearchIcon.svelte} +0 -0
- /package/{maplibre.d.ts → maplibregl.d.ts} +0 -0
|
@@ -1,851 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { createEventDispatcher } from "svelte";
|
|
3
|
-
import { onDestroy } from "svelte/internal";
|
|
4
|
-
import ReverseGeocodingIcon from "./ReverseGeocodingIcon.svelte";
|
|
5
|
-
import ClearIcon from "./ClearIcon.svelte";
|
|
6
|
-
import LoadingIcon from "./LoadingIcon.svelte";
|
|
7
|
-
import MarkerIcon from "./MarkerIcon.svelte";
|
|
8
|
-
import SearchIcon from "./SearchIcon.svelte";
|
|
9
|
-
import type {
|
|
10
|
-
Feature,
|
|
11
|
-
FeatureCollection,
|
|
12
|
-
MapController,
|
|
13
|
-
Proximity,
|
|
14
|
-
} from "./types";
|
|
15
|
-
|
|
16
|
-
let className: string | undefined = undefined;
|
|
17
|
-
|
|
18
|
-
type BBox = [number, number, number, number];
|
|
19
|
-
|
|
20
|
-
export { className as class };
|
|
21
|
-
|
|
22
|
-
export let apiKey: string;
|
|
23
|
-
|
|
24
|
-
export let bbox: BBox | undefined = undefined;
|
|
25
|
-
|
|
26
|
-
export let clearButtonTitle = "clear";
|
|
27
|
-
|
|
28
|
-
export let clearOnBlur = false;
|
|
29
|
-
|
|
30
|
-
export let collapsed = false;
|
|
31
|
-
|
|
32
|
-
export let country: string | string[] | undefined = undefined;
|
|
33
|
-
|
|
34
|
-
export let debounceSearch = 200;
|
|
35
|
-
|
|
36
|
-
export let enableReverse: boolean | "always" = false;
|
|
37
|
-
|
|
38
|
-
export let errorMessage = "Searching failed";
|
|
39
|
-
|
|
40
|
-
export let filter: (feature: Feature) => boolean = () => true;
|
|
41
|
-
|
|
42
|
-
export let flyTo = true;
|
|
43
|
-
|
|
44
|
-
export let fuzzyMatch = true;
|
|
45
|
-
|
|
46
|
-
export let language: string | string[] | undefined = undefined;
|
|
47
|
-
|
|
48
|
-
export let limit: number | undefined = undefined;
|
|
49
|
-
|
|
50
|
-
export let mapController: MapController | undefined = undefined;
|
|
51
|
-
|
|
52
|
-
export let minLength = 2;
|
|
53
|
-
|
|
54
|
-
export let noResultsMessage = "No results found";
|
|
55
|
-
|
|
56
|
-
export let placeholder = "Search";
|
|
57
|
-
|
|
58
|
-
export let proximity: Proximity = undefined;
|
|
59
|
-
|
|
60
|
-
export let reverseActive = enableReverse === "always";
|
|
61
|
-
|
|
62
|
-
export let reverseButtonTitle = "toggle reverse geocoding";
|
|
63
|
-
|
|
64
|
-
export let searchValue = "";
|
|
65
|
-
|
|
66
|
-
export let showFullGeometry = true;
|
|
67
|
-
|
|
68
|
-
export let showPlaceType = false;
|
|
69
|
-
|
|
70
|
-
export let showResultsWhileTyping = true;
|
|
71
|
-
|
|
72
|
-
export let trackProximity = true;
|
|
73
|
-
|
|
74
|
-
export let types: string[] | undefined = undefined;
|
|
75
|
-
|
|
76
|
-
export let zoom = 16;
|
|
77
|
-
|
|
78
|
-
export let fetchParameters: RequestInit = {};
|
|
79
|
-
|
|
80
|
-
export function focus() {
|
|
81
|
-
input.focus();
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function blur() {
|
|
85
|
-
input.blur();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function setQuery(value: string, submit = true) {
|
|
89
|
-
searchValue = value;
|
|
90
|
-
|
|
91
|
-
if (submit) {
|
|
92
|
-
selectedItemIndex = -1;
|
|
93
|
-
|
|
94
|
-
handleOnSubmit();
|
|
95
|
-
} else {
|
|
96
|
-
handleInput();
|
|
97
|
-
|
|
98
|
-
setTimeout(() => {
|
|
99
|
-
input.focus();
|
|
100
|
-
input.select();
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
let focused = false;
|
|
106
|
-
|
|
107
|
-
let listFeatures: Feature[] | undefined;
|
|
108
|
-
|
|
109
|
-
let markedFeatures: Feature[] | undefined;
|
|
110
|
-
|
|
111
|
-
let picked: Feature | undefined;
|
|
112
|
-
|
|
113
|
-
let lastSearchUrl = "";
|
|
114
|
-
|
|
115
|
-
let input: HTMLInputElement;
|
|
116
|
-
|
|
117
|
-
let selectedItemIndex = -1;
|
|
118
|
-
|
|
119
|
-
let error: unknown;
|
|
120
|
-
|
|
121
|
-
let cachedFeatures: Feature[] = [];
|
|
122
|
-
|
|
123
|
-
let abortController: AbortController | undefined;
|
|
124
|
-
|
|
125
|
-
let searchTimeoutRef: number | undefined;
|
|
126
|
-
|
|
127
|
-
let focusedDelayed: boolean;
|
|
128
|
-
|
|
129
|
-
const dispatch = createEventDispatcher<{
|
|
130
|
-
select: Feature;
|
|
131
|
-
pick: Feature;
|
|
132
|
-
optionsVisibilityChange: boolean;
|
|
133
|
-
featuresListed: Feature[];
|
|
134
|
-
featuresMarked: Feature[];
|
|
135
|
-
response: { url: string; featureCollection: FeatureCollection };
|
|
136
|
-
reverseToggle: boolean;
|
|
137
|
-
queryChange: string;
|
|
138
|
-
}>();
|
|
139
|
-
|
|
140
|
-
$: if (!trackProximity) {
|
|
141
|
-
proximity = undefined;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
$: if (
|
|
145
|
-
showFullGeometry &&
|
|
146
|
-
picked &&
|
|
147
|
-
!picked.address &&
|
|
148
|
-
picked.geometry.type === "Point"
|
|
149
|
-
) {
|
|
150
|
-
search(picked.id, { byId: true }).catch((err) => (error = err));
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
$: if (mapController && picked && flyTo) {
|
|
154
|
-
if (
|
|
155
|
-
!picked.bbox ||
|
|
156
|
-
(picked.bbox[0] === picked.bbox[2] && picked.bbox[1] === picked.bbox[3])
|
|
157
|
-
) {
|
|
158
|
-
mapController.flyTo(picked.center, zoom);
|
|
159
|
-
} else {
|
|
160
|
-
mapController.fitBounds(unwrapBbox(picked.bbox), 50);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
listFeatures = undefined;
|
|
164
|
-
markedFeatures = undefined;
|
|
165
|
-
selectedItemIndex = -1;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
$: if (markedFeatures !== listFeatures) {
|
|
169
|
-
markedFeatures = undefined;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
$: if (mapController) {
|
|
173
|
-
mapController.setMarkers(markedFeatures, picked);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
$: if (!searchValue) {
|
|
177
|
-
picked = undefined;
|
|
178
|
-
listFeatures = undefined;
|
|
179
|
-
error = undefined;
|
|
180
|
-
markedFeatures = listFeatures;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// highlight selected marker
|
|
184
|
-
$: mapController?.setSelectedMarker(selectedItemIndex);
|
|
185
|
-
|
|
186
|
-
// close dropdown in the next cycle so that the selected item event has the chance to fire
|
|
187
|
-
$: setTimeout(() => {
|
|
188
|
-
focusedDelayed = focused;
|
|
189
|
-
|
|
190
|
-
if (clearOnBlur && !focused) {
|
|
191
|
-
searchValue = "";
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
// clear selection on edit
|
|
196
|
-
$: {
|
|
197
|
-
searchValue;
|
|
198
|
-
|
|
199
|
-
selectedItemIndex = -1;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
$: selected = listFeatures?.[selectedItemIndex];
|
|
203
|
-
|
|
204
|
-
$: {
|
|
205
|
-
const m = /^(-?\d+(?:\.\d*)?),(-?\d+(?:\.\d*)?)$/.exec(searchValue);
|
|
206
|
-
|
|
207
|
-
mapController?.setReverseMarker(
|
|
208
|
-
m ? [Number(m[1]), Number(m[2])] : undefined
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
$: dispatch("select", selected);
|
|
213
|
-
|
|
214
|
-
$: dispatch("pick", picked);
|
|
215
|
-
|
|
216
|
-
$: dispatch("optionsVisibilityChange", focusedDelayed && !!listFeatures);
|
|
217
|
-
|
|
218
|
-
$: dispatch("featuresListed", listFeatures);
|
|
219
|
-
|
|
220
|
-
$: dispatch("featuresMarked", markedFeatures);
|
|
221
|
-
|
|
222
|
-
$: dispatch("reverseToggle", reverseActive);
|
|
223
|
-
|
|
224
|
-
$: dispatch("queryChange", searchValue);
|
|
225
|
-
|
|
226
|
-
$: if (mapController) {
|
|
227
|
-
mapController.indicateReverse(reverseActive);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
$: if (mapController) {
|
|
231
|
-
mapController.setEventHandler((e) => {
|
|
232
|
-
switch (e.type) {
|
|
233
|
-
case "mapClick":
|
|
234
|
-
if (reverseActive) {
|
|
235
|
-
handleReverse(e.coordinates);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
break;
|
|
239
|
-
case "proximityChange":
|
|
240
|
-
proximity = trackProximity ? e.proximity : undefined;
|
|
241
|
-
|
|
242
|
-
break;
|
|
243
|
-
case "markerClick":
|
|
244
|
-
{
|
|
245
|
-
const feature = listFeatures?.find(
|
|
246
|
-
(feature) => feature.id === e.id
|
|
247
|
-
);
|
|
248
|
-
|
|
249
|
-
if (feature) {
|
|
250
|
-
pick(feature);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
break;
|
|
255
|
-
case "markerMouseEnter":
|
|
256
|
-
selectedItemIndex = !focusedDelayed
|
|
257
|
-
? -1
|
|
258
|
-
: listFeatures?.findIndex((feature) => feature.id === e.id) ?? -1;
|
|
259
|
-
|
|
260
|
-
break;
|
|
261
|
-
case "markerMouseLeave":
|
|
262
|
-
selectedItemIndex = -1;
|
|
263
|
-
|
|
264
|
-
break;
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
onDestroy(() => {
|
|
270
|
-
if (mapController) {
|
|
271
|
-
mapController.setEventHandler(undefined);
|
|
272
|
-
mapController.indicateReverse(false);
|
|
273
|
-
mapController.setSelectedMarker(-1);
|
|
274
|
-
mapController.setMarkers(undefined, undefined);
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
function handleOnSubmit(event?: unknown) {
|
|
279
|
-
if (searchTimeoutRef) {
|
|
280
|
-
clearTimeout(searchTimeoutRef);
|
|
281
|
-
|
|
282
|
-
searchTimeoutRef = undefined;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
if (selectedItemIndex > -1 && listFeatures) {
|
|
286
|
-
picked = listFeatures[selectedItemIndex];
|
|
287
|
-
searchValue = picked.place_name.replace(/,.*/, "");
|
|
288
|
-
error = undefined;
|
|
289
|
-
markedFeatures = undefined;
|
|
290
|
-
selectedItemIndex = -1;
|
|
291
|
-
} else if (searchValue) {
|
|
292
|
-
const zoomTo = event || !isQuerReverse();
|
|
293
|
-
|
|
294
|
-
search(searchValue, { exact: true })
|
|
295
|
-
.then(() => {
|
|
296
|
-
markedFeatures = listFeatures;
|
|
297
|
-
|
|
298
|
-
picked = undefined;
|
|
299
|
-
|
|
300
|
-
if (zoomTo) {
|
|
301
|
-
zoomToResults();
|
|
302
|
-
}
|
|
303
|
-
})
|
|
304
|
-
.catch((err) => (error = err));
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
function isQuerReverse() {
|
|
309
|
-
return /^-?\d+(\.\d+)?,-?\d+(\.\d+)?$/.test(searchValue);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
async function search(
|
|
313
|
-
searchValue: string,
|
|
314
|
-
{
|
|
315
|
-
byId = false,
|
|
316
|
-
exact = false,
|
|
317
|
-
}: undefined | { byId?: boolean; exact?: boolean } = {}
|
|
318
|
-
) {
|
|
319
|
-
error = undefined;
|
|
320
|
-
|
|
321
|
-
const isReverse = isQuerReverse();
|
|
322
|
-
|
|
323
|
-
const sp = new URLSearchParams();
|
|
324
|
-
|
|
325
|
-
if (language != undefined) {
|
|
326
|
-
sp.set(
|
|
327
|
-
"language",
|
|
328
|
-
Array.isArray(language) ? language.join(",") : language
|
|
329
|
-
);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
if (types) {
|
|
333
|
-
sp.set("types", types.join(","));
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
if (!isReverse) {
|
|
337
|
-
if (bbox) {
|
|
338
|
-
sp.set("bbox", bbox.map((c) => c.toFixed(6)).join(","));
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
if (country) {
|
|
342
|
-
sp.set("country", Array.isArray(country) ? country.join(",") : country);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
if (!byId) {
|
|
347
|
-
if (proximity) {
|
|
348
|
-
sp.set("proximity", proximity.map((c) => c.toFixed(6)).join(","));
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
if (exact || !showResultsWhileTyping) {
|
|
352
|
-
sp.set("autocomplete", "false");
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
sp.set("fuzzyMatch", String(fuzzyMatch));
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
if (limit !== undefined) {
|
|
359
|
-
sp.set("limit", String(limit));
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
sp.set("key", apiKey);
|
|
363
|
-
|
|
364
|
-
const url =
|
|
365
|
-
import.meta.env.VITE_API_URL +
|
|
366
|
-
"/" +
|
|
367
|
-
encodeURIComponent(searchValue) +
|
|
368
|
-
".json?" +
|
|
369
|
-
sp.toString();
|
|
370
|
-
|
|
371
|
-
if (url === lastSearchUrl) {
|
|
372
|
-
if (byId) {
|
|
373
|
-
listFeatures = undefined;
|
|
374
|
-
|
|
375
|
-
picked = cachedFeatures[0];
|
|
376
|
-
} else {
|
|
377
|
-
listFeatures = cachedFeatures;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
lastSearchUrl = url;
|
|
384
|
-
|
|
385
|
-
abortController?.abort();
|
|
386
|
-
|
|
387
|
-
const ac = new AbortController();
|
|
388
|
-
|
|
389
|
-
abortController = ac;
|
|
390
|
-
|
|
391
|
-
let res: Response;
|
|
392
|
-
|
|
393
|
-
try {
|
|
394
|
-
res = await fetch(url, {
|
|
395
|
-
signal: ac.signal,
|
|
396
|
-
...fetchParameters,
|
|
397
|
-
}).finally(() => {
|
|
398
|
-
if (ac === abortController) {
|
|
399
|
-
abortController = undefined;
|
|
400
|
-
}
|
|
401
|
-
});
|
|
402
|
-
} catch (e) {
|
|
403
|
-
if (e && typeof e === "object" && (e as any).name === "AbortError") {
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
throw new Error();
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
if (!res.ok) {
|
|
411
|
-
throw new Error();
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
const featureCollection: FeatureCollection = await res.json();
|
|
415
|
-
|
|
416
|
-
dispatch("response", { url, featureCollection });
|
|
417
|
-
|
|
418
|
-
if (byId) {
|
|
419
|
-
listFeatures = undefined;
|
|
420
|
-
|
|
421
|
-
picked = featureCollection.features[0];
|
|
422
|
-
|
|
423
|
-
cachedFeatures = [picked];
|
|
424
|
-
} else {
|
|
425
|
-
listFeatures = featureCollection.features.filter(filter);
|
|
426
|
-
|
|
427
|
-
cachedFeatures = listFeatures;
|
|
428
|
-
|
|
429
|
-
if (isReverse) {
|
|
430
|
-
input.focus();
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
function zoomToResults() {
|
|
436
|
-
if (!markedFeatures?.length || !flyTo) {
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
const bbox: [number, number, number, number] = [180, 90, -180, -90];
|
|
441
|
-
|
|
442
|
-
const fuzzyOnly = !markedFeatures.some((feature) => !feature.matching_text);
|
|
443
|
-
|
|
444
|
-
for (const feature of markedFeatures) {
|
|
445
|
-
if (fuzzyOnly || !feature.matching_text) {
|
|
446
|
-
bbox[0] = Math.min(bbox[0], feature.bbox?.[0] ?? feature.center[0]);
|
|
447
|
-
bbox[1] = Math.min(bbox[1], feature.bbox?.[1] ?? feature.center[1]);
|
|
448
|
-
bbox[2] = Math.max(bbox[2], feature.bbox?.[2] ?? feature.center[0]);
|
|
449
|
-
bbox[3] = Math.max(bbox[3], feature.bbox?.[3] ?? feature.center[1]);
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
if (mapController && markedFeatures.length > 0) {
|
|
454
|
-
if (picked && bbox[0] === bbox[2] && bbox[1] === bbox[3]) {
|
|
455
|
-
mapController.flyTo(picked.center, zoom);
|
|
456
|
-
} else {
|
|
457
|
-
mapController.fitBounds(unwrapBbox(bbox), 50);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
// taken from Leaflet
|
|
463
|
-
function wrapNum(x: number, range: [number, number], includeMax: boolean) {
|
|
464
|
-
const max = range[1],
|
|
465
|
-
min = range[0],
|
|
466
|
-
d = max - min;
|
|
467
|
-
|
|
468
|
-
return x === max && includeMax ? x : ((((x - min) % d) + d) % d) + min;
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
function handleReverse(coordinates: [lng: number, lat: number]) {
|
|
472
|
-
reverseActive = enableReverse === "always";
|
|
473
|
-
|
|
474
|
-
setQuery(
|
|
475
|
-
wrapNum(coordinates[0], [-180, 180], true).toFixed(6) +
|
|
476
|
-
"," +
|
|
477
|
-
coordinates[1].toFixed(6)
|
|
478
|
-
);
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
function handleKeyDown(e: KeyboardEvent) {
|
|
482
|
-
if (!listFeatures) {
|
|
483
|
-
return;
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
let dir = e.key === "ArrowDown" ? 1 : e.key === "ArrowUp" ? -1 : 0;
|
|
487
|
-
|
|
488
|
-
if (dir) {
|
|
489
|
-
if (selectedItemIndex === -1 && dir === -1) {
|
|
490
|
-
selectedItemIndex = listFeatures.length;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
selectedItemIndex += dir;
|
|
494
|
-
|
|
495
|
-
if (selectedItemIndex >= listFeatures.length) {
|
|
496
|
-
selectedItemIndex = -1;
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
e.preventDefault();
|
|
500
|
-
} else if (["ArrowLeft", "ArrowRight", "Home", "End"].includes(e.key)) {
|
|
501
|
-
selectedItemIndex = -1;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
function handleInput(debounce = true) {
|
|
506
|
-
if (showResultsWhileTyping && searchValue.length > minLength) {
|
|
507
|
-
if (searchTimeoutRef) {
|
|
508
|
-
clearTimeout(searchTimeoutRef);
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
const sv = searchValue;
|
|
512
|
-
|
|
513
|
-
searchTimeoutRef = window.setTimeout(
|
|
514
|
-
() => {
|
|
515
|
-
search(sv).catch((err) => (error = err));
|
|
516
|
-
},
|
|
517
|
-
debounce ? debounceSearch : 0
|
|
518
|
-
);
|
|
519
|
-
} else {
|
|
520
|
-
listFeatures = undefined;
|
|
521
|
-
error = undefined;
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
function pick(feature: Feature) {
|
|
526
|
-
picked = feature;
|
|
527
|
-
searchValue = feature.place_name;
|
|
528
|
-
selectedItemIndex = -1;
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
function unwrapBbox(bbox0: BBox): BBox {
|
|
532
|
-
let bbox = [...bbox0] satisfies BBox;
|
|
533
|
-
|
|
534
|
-
if (bbox[2] < bbox[0]) {
|
|
535
|
-
bbox[2] += 360;
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
return bbox;
|
|
539
|
-
}
|
|
540
|
-
</script>
|
|
541
|
-
|
|
542
|
-
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
|
543
|
-
<form
|
|
544
|
-
tabindex="0"
|
|
545
|
-
on:submit|preventDefault={handleOnSubmit}
|
|
546
|
-
class:can-collapse={collapsed && searchValue === ""}
|
|
547
|
-
class={className}
|
|
548
|
-
>
|
|
549
|
-
<div class="input-group">
|
|
550
|
-
<button type="button" on:click={() => input.focus()}>
|
|
551
|
-
<SearchIcon />
|
|
552
|
-
</button>
|
|
553
|
-
|
|
554
|
-
<input
|
|
555
|
-
bind:this={input}
|
|
556
|
-
bind:value={searchValue}
|
|
557
|
-
on:focus={() => (focused = true)}
|
|
558
|
-
on:blur={() => (focused = false)}
|
|
559
|
-
on:keydown={handleKeyDown}
|
|
560
|
-
on:input={() => handleInput()}
|
|
561
|
-
{placeholder}
|
|
562
|
-
aria-label={placeholder}
|
|
563
|
-
/>
|
|
564
|
-
|
|
565
|
-
<div class="clear-button-container">
|
|
566
|
-
<button
|
|
567
|
-
type="button"
|
|
568
|
-
on:click={() => {
|
|
569
|
-
searchValue = "";
|
|
570
|
-
input.focus();
|
|
571
|
-
}}
|
|
572
|
-
class:displayable={searchValue !== ""}
|
|
573
|
-
title={clearButtonTitle}
|
|
574
|
-
>
|
|
575
|
-
<ClearIcon />
|
|
576
|
-
</button>
|
|
577
|
-
|
|
578
|
-
{#if abortController}
|
|
579
|
-
<LoadingIcon />
|
|
580
|
-
{/if}
|
|
581
|
-
</div>
|
|
582
|
-
|
|
583
|
-
{#if enableReverse === true}
|
|
584
|
-
<button
|
|
585
|
-
type="button"
|
|
586
|
-
class:active={reverseActive}
|
|
587
|
-
title={reverseButtonTitle}
|
|
588
|
-
on:click={() => (reverseActive = !reverseActive)}
|
|
589
|
-
>
|
|
590
|
-
<ReverseGeocodingIcon />
|
|
591
|
-
</button>
|
|
592
|
-
{/if}
|
|
593
|
-
|
|
594
|
-
<slot />
|
|
595
|
-
</div>
|
|
596
|
-
|
|
597
|
-
{#if error}
|
|
598
|
-
<div class="error">{errorMessage}</div>
|
|
599
|
-
{:else if !focusedDelayed}
|
|
600
|
-
{""}
|
|
601
|
-
{:else if listFeatures?.length === 0}
|
|
602
|
-
<div class="no-results">{noResultsMessage}</div>
|
|
603
|
-
{:else if focusedDelayed && listFeatures?.length}
|
|
604
|
-
<ul
|
|
605
|
-
on:mouseleave={() => (selectedItemIndex = -1)}
|
|
606
|
-
on:blur={() => undefined}
|
|
607
|
-
>
|
|
608
|
-
{#each listFeatures as feature, i}
|
|
609
|
-
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
|
610
|
-
<li
|
|
611
|
-
tabindex="0"
|
|
612
|
-
data-selected={selectedItemIndex === i}
|
|
613
|
-
class:selected={selectedItemIndex === i}
|
|
614
|
-
on:mouseenter={() => (selectedItemIndex = i)}
|
|
615
|
-
on:focus={() => pick(feature)}
|
|
616
|
-
>
|
|
617
|
-
<MarkerIcon displayIn="list" />
|
|
618
|
-
<span>
|
|
619
|
-
<span>
|
|
620
|
-
<span>{feature.place_name.replace(/,.*/, "")}</span>
|
|
621
|
-
{#if showPlaceType}
|
|
622
|
-
<span
|
|
623
|
-
>{feature.properties?.place_type_name?.[0] ??
|
|
624
|
-
feature.place_type[0]}</span
|
|
625
|
-
>
|
|
626
|
-
{/if}
|
|
627
|
-
</span>
|
|
628
|
-
</span>
|
|
629
|
-
<span>
|
|
630
|
-
<span>{feature.place_name.replace(/[^,]*,?\s*/, "")}</span>
|
|
631
|
-
</span>
|
|
632
|
-
</li>
|
|
633
|
-
{/each}
|
|
634
|
-
</ul>
|
|
635
|
-
{/if}
|
|
636
|
-
</form>
|
|
637
|
-
|
|
638
|
-
<style>
|
|
639
|
-
form,
|
|
640
|
-
form *,
|
|
641
|
-
form *:after,
|
|
642
|
-
form *:before {
|
|
643
|
-
box-sizing: border-box;
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
form {
|
|
647
|
-
font-family: "Ubuntu", "Open Sans", "Helvetica Neue", Arial, Helvetica,
|
|
648
|
-
sans-serif;
|
|
649
|
-
position: relative;
|
|
650
|
-
background-color: #fff;
|
|
651
|
-
width: 100%;
|
|
652
|
-
z-index: 10;
|
|
653
|
-
border-radius: 4px;
|
|
654
|
-
transition: max-width 0.25s;
|
|
655
|
-
box-shadow: 0px 2px 8px rgba(51, 51, 89, 0.15);
|
|
656
|
-
--color-text: #333359;
|
|
657
|
-
--color-icon-button: #333359;
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
form.can-collapse {
|
|
661
|
-
max-width: 35px;
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
form,
|
|
665
|
-
form:focus-within,
|
|
666
|
-
form:hover {
|
|
667
|
-
max-width: 240px;
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
input {
|
|
671
|
-
font: inherit;
|
|
672
|
-
font-size: 14px;
|
|
673
|
-
width: 100%;
|
|
674
|
-
border: 0;
|
|
675
|
-
background-color: transparent;
|
|
676
|
-
margin: 0;
|
|
677
|
-
height: 36px;
|
|
678
|
-
color: rgba(0, 0, 0, 0.75);
|
|
679
|
-
white-space: nowrap;
|
|
680
|
-
overflow: hidden;
|
|
681
|
-
padding: 0;
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
input:focus {
|
|
685
|
-
color: rgba(0, 0, 0, 0.75);
|
|
686
|
-
outline: 0;
|
|
687
|
-
outline: none;
|
|
688
|
-
box-shadow: none;
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
ul,
|
|
692
|
-
div.error,
|
|
693
|
-
div.no-results {
|
|
694
|
-
background-color: #fff;
|
|
695
|
-
border-radius: 4px;
|
|
696
|
-
left: 0;
|
|
697
|
-
list-style: none;
|
|
698
|
-
margin: 0;
|
|
699
|
-
padding: 0;
|
|
700
|
-
position: absolute;
|
|
701
|
-
width: 100%;
|
|
702
|
-
top: calc(100% + 6px);
|
|
703
|
-
font-size: 14px;
|
|
704
|
-
box-shadow: 0px 2px 8px rgba(51, 51, 89, 0.15);
|
|
705
|
-
line-height: 16px;
|
|
706
|
-
overflow: hidden;
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
:global(.maplibregl-ctrl-bottom-left) ul,
|
|
710
|
-
:global(.maplibregl-ctrl-bottom-right) ul {
|
|
711
|
-
top: auto;
|
|
712
|
-
bottom: 100%;
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
li {
|
|
716
|
-
text-align: left;
|
|
717
|
-
cursor: default;
|
|
718
|
-
display: grid;
|
|
719
|
-
grid-template-columns: auto 1fr;
|
|
720
|
-
color: var(--color-text);
|
|
721
|
-
padding: 4px 0px;
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
li:first-child {
|
|
725
|
-
padding-top: 8px;
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
li:last-child {
|
|
729
|
-
padding-bottom: 8px;
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
li > span {
|
|
733
|
-
/* text-overflow: ellipsis; */
|
|
734
|
-
overflow: hidden;
|
|
735
|
-
padding-right: 8px;
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
li > span > span {
|
|
739
|
-
white-space: nowrap;
|
|
740
|
-
display: block;
|
|
741
|
-
min-width: fit-content;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
li.selected > span > span {
|
|
745
|
-
animation: backAndForth 5s linear infinite;
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
li > span:nth-of-type(1) > span > span:nth-of-type(1) {
|
|
749
|
-
font-weight: bold;
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
li > span:nth-of-type(1) > span > span:nth-of-type(2) {
|
|
753
|
-
color: #aeb6c7;
|
|
754
|
-
font-size: 12px;
|
|
755
|
-
padding-left: 4px;
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
li.selected {
|
|
759
|
-
background-color: #f3f3f3;
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
button:hover {
|
|
763
|
-
background-color: transparent;
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
button:hover :global(svg),
|
|
767
|
-
button.active :global(svg) {
|
|
768
|
-
fill: #6b7c92;
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
button {
|
|
772
|
-
padding: 0;
|
|
773
|
-
margin: 0;
|
|
774
|
-
border: 0;
|
|
775
|
-
background-color: transparent;
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
.input-group {
|
|
779
|
-
display: flex;
|
|
780
|
-
align-items: stretch;
|
|
781
|
-
gap: 7px;
|
|
782
|
-
padding-inline: 8px;
|
|
783
|
-
outline: #c1cfe4 solid 2px;
|
|
784
|
-
border-radius: 4px;
|
|
785
|
-
overflow: hidden;
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
.input-group:hover .displayable {
|
|
789
|
-
visibility: visible;
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
.input-group:focus-within {
|
|
793
|
-
outline: #3170fe solid 2px;
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
div.error,
|
|
797
|
-
div.no-results {
|
|
798
|
-
font: inherit;
|
|
799
|
-
font-size: 14px;
|
|
800
|
-
padding: 6px 10px;
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
div.error {
|
|
804
|
-
color: #e25041;
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
div.no-results {
|
|
808
|
-
color: var(--color-text);
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
.clear-button-container {
|
|
812
|
-
position: relative;
|
|
813
|
-
display: flex;
|
|
814
|
-
align-items: stretch;
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
.clear-button-container button {
|
|
818
|
-
visibility: hidden;
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
@keyframes backAndForth {
|
|
822
|
-
0% {
|
|
823
|
-
transform: translateX(0);
|
|
824
|
-
}
|
|
825
|
-
10% {
|
|
826
|
-
transform: translateX(0);
|
|
827
|
-
}
|
|
828
|
-
45% {
|
|
829
|
-
transform: translateX(calc(-100% + 196px));
|
|
830
|
-
}
|
|
831
|
-
55% {
|
|
832
|
-
transform: translateX(calc(-100% + 196px));
|
|
833
|
-
}
|
|
834
|
-
90% {
|
|
835
|
-
transform: translateX(0);
|
|
836
|
-
}
|
|
837
|
-
100% {
|
|
838
|
-
transform: translateX(0);
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
form.can-collapse button:not(:nth-of-type(1)) {
|
|
843
|
-
opacity: 0;
|
|
844
|
-
transition: opacity 0.25s;
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
form.can-collapse:focus-within :not(:nth-of-type(1)),
|
|
848
|
-
form.can-collapse:hover :not(:nth-of-type(1)) {
|
|
849
|
-
opacity: 1;
|
|
850
|
-
}
|
|
851
|
-
</style>
|