@maptiler/geocoding-control 2.0.1 → 2.1.0-with-autocomplete-timeout
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/MapLibreBasedGeocodingControl.d.ts +1037 -626
- package/icons/10pin.svg +4 -1
- package/icons/9pin.svg +4 -1
- package/icons/alcohol.svg +1 -1
- package/icons/alpine_hut.svg +1 -1
- package/icons/apartment.svg +4 -1
- package/icons/area.svg +1 -5
- package/icons/artwork.svg +4 -1
- package/icons/beauty.svg +14 -1
- package/icons/bicycle_repair_station.svg +18 -1
- package/icons/biergarten.svg +4 -1
- package/icons/books.svg +14 -1
- package/icons/bowl.svg +4 -1
- package/icons/bowling_alley.svg +4 -1
- package/icons/bus_station.svg +1 -1
- package/icons/camping.svg +1 -1
- package/icons/car_repair.svg +14 -1
- package/icons/car_wash.svg +19 -1
- package/icons/cave_entrance.svg +15 -1
- package/icons/chalet.svg +1 -1
- package/icons/chemist.svg +14 -1
- package/icons/church.svg +4 -1
- package/icons/community_centre.svg +20 -1
- package/icons/firestation.svg +4 -1
- package/icons/guest_house.svg +29 -8
- package/icons/hotel.svg +1 -1
- package/icons/housenumber.svg +19 -14
- package/icons/hut.svg +1 -4
- package/icons/medical_supply.svg +20 -1
- package/icons/memorial.svg +14 -1
- package/icons/motel.svg +19 -1
- package/icons/post.svg +1 -1
- package/icons/post_office.svg +1 -1
- package/icons/postal_code.svg +1 -23
- package/icons/public_bookcase.svg +14 -1
- package/icons/public_building.svg +4 -1
- package/icons/shintoist.svg +1 -1
- package/icons/street.svg +11 -14
- package/icons/vehicle_inspection.svg +18 -1
- package/icons/wilderness_hut.svg +1 -1
- package/leaflet-controller.js +32 -31
- package/leaflet-controller.js.map +1 -1
- package/leaflet-controller.umd.js +1 -1
- package/leaflet-controller.umd.js.map +1 -1
- package/leaflet.d.ts +32 -1
- package/leaflet.js +1611 -1416
- package/leaflet.js.map +1 -1
- package/leaflet.umd.js +3 -3
- package/leaflet.umd.js.map +1 -1
- package/maplibregl-controller.js +5 -5
- package/maplibregl-controller.js.map +1 -1
- package/maplibregl-controller.umd.js +1 -1
- package/maplibregl-controller.umd.js.map +1 -1
- package/maplibregl.d.ts +527 -626
- package/maplibregl.js +1968 -1778
- package/maplibregl.js.map +1 -1
- package/maplibregl.umd.js +3 -3
- package/maplibregl.umd.js.map +1 -1
- package/maptilersdk.d.ts +527 -626
- package/maptilersdk.js +1966 -1776
- package/maptilersdk.js.map +1 -1
- package/maptilersdk.umd.js +3 -3
- package/maptilersdk.umd.js.map +1 -1
- package/openlayers-controller.js +5 -4
- package/openlayers-controller.js.map +1 -1
- package/openlayers-controller.umd.js +1 -1
- package/openlayers-controller.umd.js.map +1 -1
- package/openlayers.d.ts +32 -1
- package/openlayers.js +2082 -1887
- package/openlayers.js.map +1 -1
- package/openlayers.umd.js +3 -3
- package/openlayers.umd.js.map +1 -1
- package/package.json +23 -23
- package/react.d.ts +27 -1
- package/react.js +1320 -1145
- package/react.js.map +1 -1
- package/react.umd.js +1 -1
- package/react.umd.js.map +1 -1
- package/style.css +1 -1
- package/svelte/FeatureItem.svelte +59 -12
- package/svelte/FeatureItem.svelte.d.ts +2 -2
- package/svelte/GeocodingControl.svelte +182 -85
- package/svelte/GeocodingControl.svelte.d.ts +11 -3
- package/svelte/MapLibreBasedGeocodingControl.d.ts +1037 -626
- package/svelte/MapLibreBasedGeocodingControl.js +36 -6
- package/svelte/leaflet-controller.js +3 -3
- package/svelte/leaflet.d.ts +32 -1
- package/svelte/leaflet.js +35 -2
- package/svelte/maplibregl-controller.js +3 -3
- package/svelte/maplibregl.d.ts +527 -626
- package/svelte/maptilersdk.d.ts +527 -626
- package/svelte/openlayers-controller.js +4 -4
- package/svelte/openlayers.d.ts +32 -1
- package/svelte/openlayers.js +36 -3
- package/svelte/react.d.ts +27 -1
- package/svelte/react.js +16 -4
- package/svelte/types.d.ts +24 -1
- package/svelte/vanilla.d.ts +32 -1
- package/svelte/vanilla.js +35 -2
- package/types.d.ts +24 -1
- package/vanilla.d.ts +32 -1
- package/vanilla.js +1184 -990
- package/vanilla.js.map +1 -1
- package/vanilla.umd.js +1 -1
- package/vanilla.umd.js.map +1 -1
- package/icons/aerodrome.12.svg +0 -1
- package/icons/bus_stop.12.svg +0 -1
- package/icons/elevator.12.svg +0 -1
- /package/icons/{helipad.16.svg → helipad.svg} +0 -0
- /package/icons/{traffic_light.13.svg → traffic_light.svg} +0 -0
package/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
svg.svelte-d2loi5{display:block;fill:#e15042}li.svelte-
|
|
1
|
+
svg.svelte-d2loi5{display:block;fill:#e15042}li.svelte-z7p9pp.svelte-z7p9pp{text-align:left;cursor:default;display:grid;grid-template-columns:40px 1fr;color:var(--color-text);padding:8px 0;font-size:14px;line-height:18px;min-width:fit-content;outline:0}li.svelte-z7p9pp.svelte-z7p9pp:first-child{padding-top:10px}li.svelte-z7p9pp.svelte-z7p9pp:last-child{padding-bottom:10px}li.picked.svelte-z7p9pp.svelte-z7p9pp{background-color:#e7edff}li.picked.svelte-z7p9pp .secondary.svelte-z7p9pp{color:#96a4c7;padding-left:4px}li.picked.svelte-z7p9pp .line2.svelte-z7p9pp{color:#96a4c7}li.selected.svelte-z7p9pp.svelte-z7p9pp{background-color:#f3f6ff}li.selected.svelte-z7p9pp.svelte-z7p9pp{animation:svelte-z7p9pp-backAndForth 5s linear infinite}li.selected.svelte-z7p9pp .primary.svelte-z7p9pp{color:#2b8bfb}li.selected.svelte-z7p9pp .secondary.svelte-z7p9pp{color:#a2adc7;padding-left:4px}li.selected.svelte-z7p9pp .line2.svelte-z7p9pp{color:#a2adc7}li.svelte-z7p9pp>img.svelte-z7p9pp{align-self:center;justify-self:center;opacity:.75}.texts.svelte-z7p9pp.svelte-z7p9pp{padding:0 17px 0 0}.texts.svelte-z7p9pp>.svelte-z7p9pp{white-space:nowrap;display:block;min-width:fit-content}.primary.svelte-z7p9pp.svelte-z7p9pp{font-weight:600}.secondary.svelte-z7p9pp.svelte-z7p9pp{color:#aeb6c7;padding-left:4px}.line2.svelte-z7p9pp.svelte-z7p9pp{color:#aeb6c7}@keyframes svelte-z7p9pp-backAndForth{0%{transform:translate(0)}10%{transform:translate(0)}45%{transform:translate(calc(-100% + 270px))}55%{transform:translate(calc(-100% + 270px))}90%{transform:translate(0)}to{transform:translate(0)}}div.svelte-7cmwmc{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);pointer-events:none;display:flex;align-items:center}svg.svelte-7cmwmc{animation:svelte-7cmwmc-rotate .8s infinite cubic-bezier(.45,.05,.55,.95)}@keyframes svelte-7cmwmc-rotate{0%{-webkit-transform:rotate(0);transform:rotate(0)}to{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}svg.svelte-gzo3ar.svelte-gzo3ar{display:block;fill:#6b7c93;stroke:#6b7c93}.list-icon.svelte-gzo3ar.svelte-gzo3ar{grid-row:1/3;align-self:center;margin:8px}.in-map.svelte-gzo3ar.svelte-gzo3ar{height:30px}.maplibregl-canvas-container .marker-selected{z-index:1}.maplibregl-canvas-container svg.svelte-gzo3ar path.svelte-gzo3ar,.leaflet-map-pane svg.svelte-gzo3ar path.svelte-gzo3ar{fill:#3170fe;stroke:#3170fe}.marker-selected svg.svelte-gzo3ar path.svelte-gzo3ar{fill:#98b7ff;stroke:#3170fe}.marker-reverse svg.svelte-gzo3ar path.svelte-gzo3ar{fill:silver;stroke:gray}.marker-interactive{cursor:pointer!important}.maptiler-gc-popup>.maplibregl-popup-content{padding:2px 8px}svg.svelte-en2qvf{display:block;fill:var(--color-icon-button)}circle.svelte-1aq105l{stroke-width:1.875;fill:none}path.svelte-1aq105l{stroke-width:1.875;stroke-linecap:round}svg.svelte-1aq105l{display:block;stroke:var(--color-icon-button)}form.svelte-bz0zu3.svelte-bz0zu3{font-family:Open Sans,Ubuntu,Helvetica Neue,Arial,Helvetica,sans-serif;position:relative;background-color:#fff;z-index:10;border-radius:4px;margin:0;transition:max-width .25s;box-shadow:0 2px 5px #33335926;--color-text:#444952;--color-icon-button:#444952}form.svelte-bz0zu3.svelte-bz0zu3,form.svelte-bz0zu3 .svelte-bz0zu3,form.svelte-bz0zu3 .svelte-bz0zu3:after,form.svelte-bz0zu3 .svelte-bz0zu3:before{box-sizing:border-box}form.can-collapse.svelte-bz0zu3.svelte-bz0zu3{max-width:29px}form.can-collapse.svelte-bz0zu3 input.svelte-bz0zu3::placeholder{transition:opacity .25s;opacity:0}form.svelte-bz0zu3.svelte-bz0zu3,form.svelte-bz0zu3.svelte-bz0zu3:focus-within,form.svelte-bz0zu3.svelte-bz0zu3:hover{width:270px;max-width:270px}form.svelte-bz0zu3 input.svelte-bz0zu3::placeholder,form.svelte-bz0zu3:focus-within input.svelte-bz0zu3::placeholder,form.svelte-bz0zu3:hover input.svelte-bz0zu3::placeholder{opacity:1}input.svelte-bz0zu3.svelte-bz0zu3{font:inherit;font-size:14px;flex-grow:1;min-height:29px;background-color:transparent;color:#444952;white-space:nowrap;overflow:hidden;border:0;margin:0;padding:0}input.svelte-bz0zu3.svelte-bz0zu3:focus{color:#444952;outline:0;outline:none;box-shadow:none}ul.svelte-bz0zu3.svelte-bz0zu3,div.error.svelte-bz0zu3.svelte-bz0zu3,div.no-results.svelte-bz0zu3.svelte-bz0zu3{background-color:#fff;border-radius:4px;left:0;list-style:none;margin:0;padding:0;position:absolute;width:100%;top:calc(100% + 6px);overflow:hidden}ul.svelte-bz0zu3.svelte-bz0zu3{font-size:14px;line-height:16px;box-shadow:0 5px 10px #33335926}div.error.svelte-bz0zu3.svelte-bz0zu3,div.no-results.svelte-bz0zu3.svelte-bz0zu3{font:inherit;line-height:18px;font-size:12px;display:flex;gap:16px}div.error.svelte-bz0zu3.svelte-bz0zu3{padding:16px;font-weight:600;color:#e25041;background-color:#fbeae8}div.error.svelte-bz0zu3 div.svelte-bz0zu3{flex-grow:1}div.error.svelte-bz0zu3 svg{flex-shrink:0;width:20px;height:20px}div.error.svelte-bz0zu3 button.svelte-bz0zu3{flex-shrink:0}div.error.svelte-bz0zu3 button.svelte-bz0zu3>svg{width:13px;fill:#e25041}div.error.svelte-bz0zu3 button.svelte-bz0zu3:hover svg,div.error.svelte-bz0zu3 button.svelte-bz0zu3:active svg{fill:#444952}div.no-results.svelte-bz0zu3.svelte-bz0zu3{padding:14px 24px 14px 16px;font-weight:400;color:#6b7c93;box-shadow:0 5px 10px #33335926}div.no-results.svelte-bz0zu3 svg{margin-top:4px;flex-shrink:0;width:20px;height:20px;width:30px;height:30px}.leaflet-bottom ul.options.svelte-bz0zu3.svelte-bz0zu3,.maplibregl-ctrl-bottom-left ul.options.svelte-bz0zu3.svelte-bz0zu3,.maplibregl-ctrl-bottom-right ul.options.svelte-bz0zu3.svelte-bz0zu3{top:auto;bottom:calc(100% + 6px)}button.svelte-bz0zu3.svelte-bz0zu3{padding:0;margin:0;border:0;background-color:transparent;height:auto;width:auto}button.svelte-bz0zu3.svelte-bz0zu3:hover{background-color:transparent}button.svelte-bz0zu3:hover svg,button.svelte-bz0zu3:active svg{fill:#2b8bfb}.input-group.svelte-bz0zu3.svelte-bz0zu3{display:flex;align-items:stretch;gap:7px;padding-inline:8px;border-radius:4px;overflow:hidden}.input-group.svelte-bz0zu3.svelte-bz0zu3:focus-within{outline:#2b8bfb solid 2px}.search-button.svelte-bz0zu3.svelte-bz0zu3{flex-shrink:0}.maplibregl-ctrl-geocoder:not(.maptiler-ctrl) .search-button svg{width:12px!important;transform:translate(.5px)}.clear-button-container.svelte-bz0zu3.svelte-bz0zu3{display:flex;display:none;position:relative;align-items:stretch}.clear-button-container.displayable.svelte-bz0zu3.svelte-bz0zu3{display:flex;flex-shrink:0}.maplibregl-ctrl-geocoder{position:relative;z-index:3}.maptiler-ctrl:not(:empty){box-shadow:none}.maptiler-ctrl .input-group.svelte-bz0zu3.svelte-bz0zu3{padding-inline:8px;border:white solid 2px}.maptiler-ctrl .input-group.svelte-bz0zu3.svelte-bz0zu3:focus-within{border:#2b8bfb solid 2px;outline:0;outline:none}.maptiler-ctrl form.can-collapse.svelte-bz0zu3.svelte-bz0zu3{max-width:33px}.maptiler-ctrl form.svelte-bz0zu3.svelte-bz0zu3,.maptiler-ctrl form.svelte-bz0zu3.svelte-bz0zu3:focus-within,.maptiler-ctrl form.svelte-bz0zu3.svelte-bz0zu3:hover{width:270px;max-width:270px}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
export let
|
|
1
|
+
<script>import { createEventDispatcher } from "svelte";
|
|
2
|
+
export let feature;
|
|
3
|
+
export let style = "default";
|
|
3
4
|
export let showPlaceType;
|
|
4
5
|
export let missingIconsCache;
|
|
5
6
|
export let iconsBaseUrl;
|
|
7
|
+
const dispatch = createEventDispatcher();
|
|
6
8
|
const categories = feature.properties?.categories;
|
|
7
9
|
let category;
|
|
8
10
|
let imageUrl;
|
|
@@ -32,24 +34,51 @@ function handleImgError() {
|
|
|
32
34
|
}
|
|
33
35
|
</script>
|
|
34
36
|
|
|
35
|
-
<!-- svelte-ignore a11y-
|
|
36
|
-
<li
|
|
37
|
+
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
38
|
+
<li
|
|
39
|
+
tabindex="-1"
|
|
40
|
+
role="option"
|
|
41
|
+
aria-selected={style === "selected"}
|
|
42
|
+
aria-checked={style === "picked"}
|
|
43
|
+
class={style}
|
|
44
|
+
on:mouseenter
|
|
45
|
+
on:focus={() => dispatch("select", undefined)}
|
|
46
|
+
on:click={(ev) => {
|
|
47
|
+
// this is to trigger the event if we click on focused item
|
|
48
|
+
if (document.activeElement !== ev.target) {
|
|
49
|
+
dispatch("select", undefined);
|
|
50
|
+
}
|
|
51
|
+
}}
|
|
52
|
+
>
|
|
37
53
|
{#if imageUrl}
|
|
38
|
-
<img
|
|
54
|
+
<img
|
|
55
|
+
src={imageUrl}
|
|
56
|
+
alt={category}
|
|
57
|
+
title={placeType}
|
|
58
|
+
on:error={() => handleImgError()}
|
|
59
|
+
/>
|
|
39
60
|
{:else if feature.address}
|
|
40
|
-
<img
|
|
61
|
+
<img
|
|
62
|
+
src={iconsBaseUrl + "housenumber.svg"}
|
|
63
|
+
alt={placeType}
|
|
64
|
+
title={placeType}
|
|
65
|
+
/>
|
|
41
66
|
{:else if feature.id.startsWith("road.")}
|
|
42
|
-
<img src={iconsBaseUrl + "road.svg"} alt={placeType} />
|
|
67
|
+
<img src={iconsBaseUrl + "road.svg"} alt={placeType} title={placeType} />
|
|
43
68
|
{:else if feature.id.startsWith("address.")}
|
|
44
|
-
<img src={iconsBaseUrl + "street.svg"} alt={placeType} />
|
|
69
|
+
<img src={iconsBaseUrl + "street.svg"} alt={placeType} title={placeType} />
|
|
45
70
|
{:else if feature.id.startsWith("postal_code.")}
|
|
46
|
-
<img
|
|
71
|
+
<img
|
|
72
|
+
src={iconsBaseUrl + "postal_code.svg"}
|
|
73
|
+
alt={placeType}
|
|
74
|
+
title={placeType}
|
|
75
|
+
/>
|
|
47
76
|
{:else if feature.id.startsWith("poi.")}
|
|
48
|
-
<img src={iconsBaseUrl + "poi.svg"} alt={placeType} />
|
|
77
|
+
<img src={iconsBaseUrl + "poi.svg"} alt={placeType} title={placeType} />
|
|
49
78
|
{:else if isReverse}
|
|
50
|
-
<img src={iconsBaseUrl + "reverse.svg"} alt={placeType} />
|
|
79
|
+
<img src={iconsBaseUrl + "reverse.svg"} alt={placeType} title={placeType} />
|
|
51
80
|
{:else}
|
|
52
|
-
<img src={iconsBaseUrl + "area.svg"} alt={placeType} />
|
|
81
|
+
<img src={iconsBaseUrl + "area.svg"} alt={placeType} title={placeType} />
|
|
53
82
|
{/if}
|
|
54
83
|
|
|
55
84
|
<span class="texts">
|
|
@@ -81,6 +110,7 @@ function handleImgError() {
|
|
|
81
110
|
font-size: 14px;
|
|
82
111
|
line-height: 18px;
|
|
83
112
|
min-width: fit-content;
|
|
113
|
+
outline: 0;
|
|
84
114
|
}
|
|
85
115
|
li:first-child {
|
|
86
116
|
padding-top: 10px;
|
|
@@ -88,6 +118,16 @@ li:first-child {
|
|
|
88
118
|
li:last-child {
|
|
89
119
|
padding-bottom: 10px;
|
|
90
120
|
}
|
|
121
|
+
li.picked {
|
|
122
|
+
background-color: #e7edff;
|
|
123
|
+
}
|
|
124
|
+
li.picked .secondary {
|
|
125
|
+
color: #96a4c7;
|
|
126
|
+
padding-left: 4px;
|
|
127
|
+
}
|
|
128
|
+
li.picked .line2 {
|
|
129
|
+
color: #96a4c7;
|
|
130
|
+
}
|
|
91
131
|
li.selected {
|
|
92
132
|
background-color: #f3f6ff;
|
|
93
133
|
}
|
|
@@ -97,6 +137,13 @@ li.selected {
|
|
|
97
137
|
li.selected .primary {
|
|
98
138
|
color: #2b8bfb;
|
|
99
139
|
}
|
|
140
|
+
li.selected .secondary {
|
|
141
|
+
color: #a2adc7;
|
|
142
|
+
padding-left: 4px;
|
|
143
|
+
}
|
|
144
|
+
li.selected .line2 {
|
|
145
|
+
color: #a2adc7;
|
|
146
|
+
}
|
|
100
147
|
li > img {
|
|
101
148
|
align-self: center;
|
|
102
149
|
justify-self: center;
|
|
@@ -3,14 +3,14 @@ import type { Feature, ShowPlaceType } from "./types";
|
|
|
3
3
|
declare const __propDef: {
|
|
4
4
|
props: {
|
|
5
5
|
feature: Feature;
|
|
6
|
-
|
|
6
|
+
style?: "selected" | "picked" | "default";
|
|
7
7
|
showPlaceType: ShowPlaceType;
|
|
8
8
|
missingIconsCache: Set<string>;
|
|
9
9
|
iconsBaseUrl: string;
|
|
10
10
|
};
|
|
11
11
|
events: {
|
|
12
12
|
mouseenter: MouseEvent;
|
|
13
|
-
|
|
13
|
+
select: CustomEvent<undefined>;
|
|
14
14
|
} & {
|
|
15
15
|
[evt: string]: CustomEvent<any>;
|
|
16
16
|
};
|
|
@@ -40,6 +40,8 @@ export let apiKey;
|
|
|
40
40
|
export let bbox = undefined;
|
|
41
41
|
export let clearButtonTitle = "clear";
|
|
42
42
|
export let clearOnBlur = false;
|
|
43
|
+
export let clearListOnPick = false;
|
|
44
|
+
export let keepListOpen = false;
|
|
43
45
|
export let collapsed = false;
|
|
44
46
|
export let country = undefined;
|
|
45
47
|
export let debounceSearch = 200;
|
|
@@ -63,6 +65,7 @@ export let searchValue = "";
|
|
|
63
65
|
export let pickedResultStyle = "full-geometry";
|
|
64
66
|
export let showPlaceType = "if-needed";
|
|
65
67
|
export let showResultsWhileTyping = true;
|
|
68
|
+
export let autocompleteTimeout = undefined;
|
|
66
69
|
export let selectFirst = true;
|
|
67
70
|
export let flyToSelected = false;
|
|
68
71
|
export let markerOnSelected = true;
|
|
@@ -73,39 +76,65 @@ export let zoom = ZOOM_DEFAULTS;
|
|
|
73
76
|
export let apiUrl = "https://api.maptiler.com/geocoding";
|
|
74
77
|
export let fetchParameters = {};
|
|
75
78
|
export let iconsBaseUrl = "https://cdn.maptiler.com/maptiler-geocoding-control/v" +
|
|
76
|
-
"2.0
|
|
79
|
+
"2.1.0-with-autocomplete-timeout" +
|
|
77
80
|
"/icons/";
|
|
81
|
+
/**
|
|
82
|
+
* @deprecated use `adjustUrl`
|
|
83
|
+
*/
|
|
78
84
|
export let adjustUrlQuery = () => { };
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Adjust geocoding URL before the fetch.
|
|
87
|
+
*/
|
|
88
|
+
export let adjustUrl = () => { };
|
|
89
|
+
/**
|
|
90
|
+
* Focus the search input box.
|
|
91
|
+
*
|
|
92
|
+
* @param options [FocusOptions](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus#options)
|
|
93
|
+
*/
|
|
94
|
+
export function focus(options) {
|
|
95
|
+
input.focus(options);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Blur the search input box.
|
|
99
|
+
*/
|
|
82
100
|
export function blur() {
|
|
83
101
|
input.blur();
|
|
84
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Set the content of search input box.
|
|
105
|
+
*
|
|
106
|
+
* @param value text to set
|
|
107
|
+
* @param submit perform the search
|
|
108
|
+
*/
|
|
85
109
|
export function setQuery(value, submit = true, reverse = false) {
|
|
86
110
|
searchValue = value;
|
|
87
111
|
if (submit) {
|
|
88
112
|
selectedItemIndex = -1;
|
|
89
|
-
|
|
113
|
+
handleSubmit();
|
|
90
114
|
}
|
|
91
115
|
else {
|
|
92
|
-
handleInput(!reverse, reverse);
|
|
116
|
+
handleInput(undefined, !reverse, reverse);
|
|
93
117
|
setTimeout(() => {
|
|
94
118
|
input.focus();
|
|
95
119
|
input.select();
|
|
96
120
|
});
|
|
97
121
|
}
|
|
98
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Clear search result list.
|
|
125
|
+
*/
|
|
99
126
|
export function clearList() {
|
|
100
127
|
listFeatures = undefined;
|
|
101
128
|
picked = undefined;
|
|
102
129
|
selectedItemIndex = -1;
|
|
103
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Clear geocoding search results from the map.
|
|
133
|
+
*/
|
|
104
134
|
export function clearMap() {
|
|
105
135
|
markedFeatures = [];
|
|
106
136
|
picked = undefined;
|
|
107
137
|
}
|
|
108
|
-
let focused = false;
|
|
109
138
|
let listFeatures;
|
|
110
139
|
let markedFeatures;
|
|
111
140
|
let picked;
|
|
@@ -116,13 +145,13 @@ let error;
|
|
|
116
145
|
let cachedFeatures = [];
|
|
117
146
|
let abortController;
|
|
118
147
|
let searchTimeoutRef;
|
|
148
|
+
let autocompleteTimeoutRef;
|
|
119
149
|
let focusedDelayed;
|
|
120
150
|
let prevIdToFly;
|
|
151
|
+
let focused = false;
|
|
121
152
|
const missingIconsCache = new Set();
|
|
122
153
|
const dispatch = createEventDispatcher();
|
|
123
|
-
$:
|
|
124
|
-
reverseActive = enableReverse === "always";
|
|
125
|
-
}
|
|
154
|
+
$: reverseActive = enableReverse === "always";
|
|
126
155
|
$: if (pickedResultStyle !== "marker-only" &&
|
|
127
156
|
picked &&
|
|
128
157
|
!picked.address &&
|
|
@@ -132,14 +161,10 @@ $: if (pickedResultStyle !== "marker-only" &&
|
|
|
132
161
|
}
|
|
133
162
|
$: {
|
|
134
163
|
if (mapController && picked && picked.id !== prevIdToFly && flyTo) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
mapController.fitBounds(unwrapBbox(picked.bbox), 50, computeZoom(picked));
|
|
164
|
+
goToPicked();
|
|
165
|
+
if (clearListOnPick) {
|
|
166
|
+
listFeatures = undefined;
|
|
141
167
|
}
|
|
142
|
-
listFeatures = undefined;
|
|
143
168
|
markedFeatures = undefined;
|
|
144
169
|
selectedItemIndex = -1;
|
|
145
170
|
}
|
|
@@ -155,7 +180,7 @@ $: if (!markerOnSelected) {
|
|
|
155
180
|
mapController?.setFeatures(undefined, undefined, showPolygonMarker);
|
|
156
181
|
}
|
|
157
182
|
$: if (mapController && markerOnSelected && !markedFeatures) {
|
|
158
|
-
mapController.setFeatures(selected ? [selected] : undefined,
|
|
183
|
+
mapController.setFeatures(selected ? [selected] : undefined, picked, showPolygonMarker);
|
|
159
184
|
mapController.setSelectedMarker(selected ? 0 : -1);
|
|
160
185
|
}
|
|
161
186
|
$: if (markedFeatures !== listFeatures) {
|
|
@@ -165,7 +190,6 @@ $: if (mapController) {
|
|
|
165
190
|
mapController.setFeatures(markedFeatures, picked, showPolygonMarker);
|
|
166
191
|
}
|
|
167
192
|
$: if (searchValue.length < minLength) {
|
|
168
|
-
picked = undefined;
|
|
169
193
|
listFeatures = undefined;
|
|
170
194
|
error = undefined;
|
|
171
195
|
markedFeatures = listFeatures;
|
|
@@ -177,29 +201,38 @@ $: if (markedFeatures && mapController) {
|
|
|
177
201
|
// close dropdown in the next cycle so that the selected item event has the chance to fire
|
|
178
202
|
$: setTimeout(() => {
|
|
179
203
|
focusedDelayed = focused;
|
|
180
|
-
if (clearOnBlur && !
|
|
204
|
+
if (clearOnBlur && !focusedDelayed) {
|
|
181
205
|
searchValue = "";
|
|
182
206
|
}
|
|
183
207
|
});
|
|
208
|
+
function isInAutocompleteTimeout() {
|
|
209
|
+
return !!autocompleteTimeoutRef;
|
|
210
|
+
}
|
|
184
211
|
$: if (selectFirst && listFeatures?.length) {
|
|
185
|
-
|
|
212
|
+
if (!isInAutocompleteTimeout()) {
|
|
213
|
+
selectedItemIndex = 0;
|
|
214
|
+
}
|
|
186
215
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
selectedItemIndex =
|
|
216
|
+
$: if (selectFirst &&
|
|
217
|
+
listFeatures?.length &&
|
|
218
|
+
selectedItemIndex == -1 &&
|
|
219
|
+
!picked) {
|
|
220
|
+
selectedItemIndex = 0;
|
|
192
221
|
}
|
|
193
222
|
$: selected = listFeatures?.[selectedItemIndex];
|
|
223
|
+
$: if (selected) {
|
|
224
|
+
window.clearTimeout(autocompleteTimeoutRef);
|
|
225
|
+
autocompleteTimeoutRef = undefined;
|
|
226
|
+
}
|
|
194
227
|
$: if (mapController) {
|
|
195
228
|
const coords = isQueryReverse(searchValue);
|
|
196
229
|
mapController.setReverseMarker(coords ? [coords.decimalLongitude, coords.decimalLatitude] : undefined);
|
|
197
230
|
}
|
|
198
231
|
$: dispatch("select", { feature: selected });
|
|
199
232
|
$: dispatch("pick", { feature: picked });
|
|
200
|
-
$:
|
|
201
|
-
|
|
202
|
-
});
|
|
233
|
+
$: optionsVisible =
|
|
234
|
+
!!listFeatures?.length && (focusedDelayed || keepListOpen);
|
|
235
|
+
$: dispatch("optionsvisibilitychange", { optionsVisible });
|
|
203
236
|
$: dispatch("featureslisted", { features: listFeatures });
|
|
204
237
|
$: dispatch("featuresmarked", { features: markedFeatures });
|
|
205
238
|
$: dispatch("reversetoggle", { reverse: reverseActive });
|
|
@@ -247,11 +280,18 @@ onDestroy(() => {
|
|
|
247
280
|
mapController.setFeatures(undefined, undefined, false);
|
|
248
281
|
}
|
|
249
282
|
});
|
|
250
|
-
function
|
|
283
|
+
function handleSubmit(event) {
|
|
284
|
+
focused = false;
|
|
251
285
|
if (searchTimeoutRef) {
|
|
252
|
-
clearTimeout(searchTimeoutRef);
|
|
286
|
+
window.clearTimeout(searchTimeoutRef);
|
|
253
287
|
searchTimeoutRef = undefined;
|
|
254
288
|
}
|
|
289
|
+
if (autocompleteTimeoutRef) {
|
|
290
|
+
window.clearTimeout(autocompleteTimeoutRef);
|
|
291
|
+
autocompleteTimeoutRef = undefined;
|
|
292
|
+
search(searchValue, { appendSpace: true });
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
255
295
|
if (selectedItemIndex > -1 && listFeatures) {
|
|
256
296
|
picked = listFeatures[selectedItemIndex];
|
|
257
297
|
searchValue =
|
|
@@ -283,14 +323,20 @@ function isQueryReverse(searchValue) {
|
|
|
283
323
|
return false;
|
|
284
324
|
}
|
|
285
325
|
}
|
|
286
|
-
async function search(searchValue, { byId = false, exact = false, } = {}) {
|
|
326
|
+
async function search(searchValue, { byId = false, exact = false, appendSpace = false, } = {}) {
|
|
287
327
|
error = undefined;
|
|
288
328
|
abortController?.abort();
|
|
289
329
|
const ac = new AbortController();
|
|
290
330
|
abortController = ac;
|
|
291
331
|
try {
|
|
292
332
|
const isReverse = isQueryReverse(searchValue);
|
|
293
|
-
const
|
|
333
|
+
const urlObj = new URL(apiUrl +
|
|
334
|
+
"/" +
|
|
335
|
+
encodeURIComponent(isReverse
|
|
336
|
+
? isReverse.decimalLongitude + "," + isReverse.decimalLatitude
|
|
337
|
+
: searchValue + (appendSpace ? " " : "")) +
|
|
338
|
+
".json");
|
|
339
|
+
const sp = urlObj.searchParams;
|
|
294
340
|
if (language !== undefined) {
|
|
295
341
|
sp.set("language", Array.isArray(language) ? language.join(",") : (language ?? ""));
|
|
296
342
|
}
|
|
@@ -322,20 +368,20 @@ async function search(searchValue, { byId = false, exact = false, } = {}) {
|
|
|
322
368
|
}
|
|
323
369
|
sp.set("key", apiKey);
|
|
324
370
|
adjustUrlQuery(sp);
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
encodeURIComponent(isReverse
|
|
328
|
-
? isReverse.decimalLongitude + "," + isReverse.decimalLatitude
|
|
329
|
-
: searchValue) +
|
|
330
|
-
".json?" +
|
|
331
|
-
sp.toString();
|
|
371
|
+
adjustUrl(urlObj);
|
|
372
|
+
const url = urlObj.toString();
|
|
332
373
|
if (url === lastSearchUrl) {
|
|
333
374
|
if (byId) {
|
|
334
|
-
|
|
375
|
+
if (clearListOnPick) {
|
|
376
|
+
listFeatures = undefined;
|
|
377
|
+
}
|
|
335
378
|
picked = cachedFeatures[0];
|
|
336
379
|
}
|
|
337
380
|
else {
|
|
338
381
|
listFeatures = cachedFeatures;
|
|
382
|
+
if (listFeatures[selectedItemIndex]?.id !== selected?.id) {
|
|
383
|
+
selectedItemIndex = -1;
|
|
384
|
+
}
|
|
339
385
|
}
|
|
340
386
|
return;
|
|
341
387
|
}
|
|
@@ -350,7 +396,9 @@ async function search(searchValue, { byId = false, exact = false, } = {}) {
|
|
|
350
396
|
const featureCollection = await res.json();
|
|
351
397
|
dispatch("response", { url, featureCollection });
|
|
352
398
|
if (byId) {
|
|
353
|
-
|
|
399
|
+
if (clearListOnPick) {
|
|
400
|
+
listFeatures = undefined;
|
|
401
|
+
}
|
|
354
402
|
picked = featureCollection.features[0];
|
|
355
403
|
cachedFeatures = [picked];
|
|
356
404
|
}
|
|
@@ -384,6 +432,9 @@ async function search(searchValue, { byId = false, exact = false, } = {}) {
|
|
|
384
432
|
});
|
|
385
433
|
}
|
|
386
434
|
cachedFeatures = listFeatures;
|
|
435
|
+
if (listFeatures[selectedItemIndex]?.id !== selected?.id) {
|
|
436
|
+
selectedItemIndex = -1;
|
|
437
|
+
}
|
|
387
438
|
if (isReverse) {
|
|
388
439
|
input.focus();
|
|
389
440
|
}
|
|
@@ -434,6 +485,18 @@ function zoomToResults() {
|
|
|
434
485
|
}
|
|
435
486
|
}
|
|
436
487
|
}
|
|
488
|
+
function goToPicked() {
|
|
489
|
+
if (!picked || !mapController) {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
if (!picked.bbox ||
|
|
493
|
+
(picked.bbox[0] === picked.bbox[2] && picked.bbox[1] === picked.bbox[3])) {
|
|
494
|
+
mapController.flyTo(picked.center, computeZoom(picked));
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
mapController.fitBounds(unwrapBbox(picked.bbox), 50, computeZoom(picked));
|
|
498
|
+
}
|
|
499
|
+
}
|
|
437
500
|
function computeZoom(feature) {
|
|
438
501
|
if (!feature.bbox ||
|
|
439
502
|
(feature.bbox[0] !== feature.bbox[2] &&
|
|
@@ -462,43 +525,75 @@ function handleKeyDown(e) {
|
|
|
462
525
|
return;
|
|
463
526
|
}
|
|
464
527
|
let dir = e.key === "ArrowDown" ? 1 : e.key === "ArrowUp" ? -1 : 0;
|
|
465
|
-
if (dir) {
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
528
|
+
if (!dir) {
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
input.focus();
|
|
532
|
+
focused = true;
|
|
533
|
+
e.preventDefault();
|
|
534
|
+
if (picked && selectedItemIndex === -1) {
|
|
535
|
+
selectedItemIndex = listFeatures.findIndex((listFeature) => listFeature.id === picked?.id);
|
|
536
|
+
}
|
|
537
|
+
if (selectedItemIndex === (picked || selectFirst ? 0 : -1) && dir === -1) {
|
|
538
|
+
selectedItemIndex = listFeatures.length;
|
|
539
|
+
}
|
|
540
|
+
selectedItemIndex += dir;
|
|
541
|
+
if (selectedItemIndex >= listFeatures.length) {
|
|
542
|
+
selectedItemIndex = -1;
|
|
543
|
+
}
|
|
544
|
+
if (selectedItemIndex < 0 && (picked || selectFirst)) {
|
|
545
|
+
selectedItemIndex = 0;
|
|
477
546
|
}
|
|
478
547
|
}
|
|
479
|
-
function handleInput(debounce = true, reverse = false) {
|
|
548
|
+
function handleInput(_, debounce = true, reverse = false) {
|
|
480
549
|
error = undefined;
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
return;
|
|
487
|
-
}
|
|
488
|
-
const sv = searchValue;
|
|
489
|
-
searchTimeoutRef = window.setTimeout(() => {
|
|
490
|
-
search(sv).catch((err) => (error = err));
|
|
491
|
-
}, debounce ? debounceSearch : 0);
|
|
550
|
+
picked = undefined;
|
|
551
|
+
focused = true;
|
|
552
|
+
if (searchTimeoutRef) {
|
|
553
|
+
window.clearTimeout(searchTimeoutRef);
|
|
554
|
+
searchTimeoutRef = undefined;
|
|
492
555
|
}
|
|
493
|
-
|
|
556
|
+
if (autocompleteTimeoutRef) {
|
|
557
|
+
window.clearTimeout(autocompleteTimeoutRef);
|
|
558
|
+
autocompleteTimeoutRef = undefined;
|
|
559
|
+
}
|
|
560
|
+
if ((!showResultsWhileTyping && !reverse) ||
|
|
561
|
+
searchValue.length < minLength) {
|
|
494
562
|
listFeatures = undefined;
|
|
495
|
-
|
|
563
|
+
return;
|
|
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);
|
|
496
575
|
}
|
|
497
576
|
}
|
|
498
577
|
function pick(feature) {
|
|
499
|
-
picked
|
|
500
|
-
|
|
501
|
-
|
|
578
|
+
if (picked && picked?.id === feature?.id) {
|
|
579
|
+
goToPicked();
|
|
580
|
+
}
|
|
581
|
+
else {
|
|
582
|
+
picked = feature;
|
|
583
|
+
searchValue = feature.place_name;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
function handleMouseEnter(index) {
|
|
587
|
+
selectedItemIndex = index;
|
|
588
|
+
}
|
|
589
|
+
function handleMouseLeave() {
|
|
590
|
+
if (!selectFirst || picked) {
|
|
591
|
+
selectedItemIndex = -1;
|
|
592
|
+
}
|
|
593
|
+
// re-focus on picked
|
|
594
|
+
if (flyToSelected) {
|
|
595
|
+
goToPicked();
|
|
596
|
+
}
|
|
502
597
|
}
|
|
503
598
|
</script>
|
|
504
599
|
|
|
@@ -507,10 +602,8 @@ function pick(feature) {
|
|
|
507
602
|
<MarkerIcon displayIn="list" />
|
|
508
603
|
{/if}
|
|
509
604
|
|
|
510
|
-
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
|
511
605
|
<form
|
|
512
|
-
|
|
513
|
-
on:submit|preventDefault={handleOnSubmit}
|
|
606
|
+
on:submit|preventDefault={handleSubmit}
|
|
514
607
|
class:can-collapse={collapsed && searchValue === ""}
|
|
515
608
|
class={className}
|
|
516
609
|
>
|
|
@@ -524,8 +617,10 @@ function pick(feature) {
|
|
|
524
617
|
bind:value={searchValue}
|
|
525
618
|
on:focus={() => (focused = true)}
|
|
526
619
|
on:blur={() => (focused = false)}
|
|
620
|
+
on:click={() => (focused = true)}
|
|
527
621
|
on:keydown={handleKeyDown}
|
|
528
|
-
on:input={
|
|
622
|
+
on:input={handleInput}
|
|
623
|
+
on:change={() => (picked = undefined)}
|
|
529
624
|
{placeholder}
|
|
530
625
|
aria-label={placeholder}
|
|
531
626
|
/>
|
|
@@ -571,7 +666,7 @@ function pick(feature) {
|
|
|
571
666
|
<ClearIcon />
|
|
572
667
|
</button>
|
|
573
668
|
</div>
|
|
574
|
-
{:else if !focusedDelayed}
|
|
669
|
+
{:else if !focusedDelayed && !keepListOpen}
|
|
575
670
|
{""}
|
|
576
671
|
{:else if listFeatures?.length === 0}
|
|
577
672
|
<div class="no-results">
|
|
@@ -579,23 +674,25 @@ function pick(feature) {
|
|
|
579
674
|
|
|
580
675
|
<div>{noResultsMessage}</div>
|
|
581
676
|
</div>
|
|
582
|
-
{:else if
|
|
677
|
+
{:else if listFeatures?.length && (focusedDelayed || keepListOpen)}
|
|
583
678
|
<ul
|
|
584
679
|
class="options"
|
|
585
|
-
on:mouseleave={
|
|
586
|
-
if (!selectFirst) {
|
|
587
|
-
selectedItemIndex = -1;
|
|
588
|
-
}
|
|
589
|
-
}}
|
|
680
|
+
on:mouseleave={handleMouseLeave}
|
|
590
681
|
on:blur={() => undefined}
|
|
682
|
+
on:keydown={handleKeyDown}
|
|
683
|
+
role="listbox"
|
|
591
684
|
>
|
|
592
685
|
{#each listFeatures as feature, i (feature.id + (feature.address ? "," + feature.address : ""))}
|
|
593
686
|
<FeatureItem
|
|
594
687
|
{feature}
|
|
595
688
|
{showPlaceType}
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
689
|
+
style={selectedItemIndex === i
|
|
690
|
+
? "selected"
|
|
691
|
+
: picked?.id === feature.id
|
|
692
|
+
? "picked"
|
|
693
|
+
: "default"}
|
|
694
|
+
on:mouseenter={() => handleMouseEnter(i)}
|
|
695
|
+
on:select={() => pick(feature)}
|
|
599
696
|
{missingIconsCache}
|
|
600
697
|
{iconsBaseUrl}
|
|
601
698
|
/>
|
|
@@ -8,6 +8,8 @@ declare const __propDef: {
|
|
|
8
8
|
bbox?: BBox | undefined;
|
|
9
9
|
clearButtonTitle?: string;
|
|
10
10
|
clearOnBlur?: boolean;
|
|
11
|
+
clearListOnPick?: boolean;
|
|
12
|
+
keepListOpen?: boolean;
|
|
11
13
|
collapsed?: boolean;
|
|
12
14
|
country?: string | string[] | undefined;
|
|
13
15
|
debounceSearch?: number;
|
|
@@ -29,6 +31,7 @@ declare const __propDef: {
|
|
|
29
31
|
pickedResultStyle?: PickedResultStyle;
|
|
30
32
|
showPlaceType?: ShowPlaceType;
|
|
31
33
|
showResultsWhileTyping?: boolean;
|
|
34
|
+
autocompleteTimeout?: number | undefined;
|
|
32
35
|
selectFirst?: boolean;
|
|
33
36
|
flyToSelected?: boolean;
|
|
34
37
|
markerOnSelected?: boolean;
|
|
@@ -39,8 +42,13 @@ declare const __propDef: {
|
|
|
39
42
|
apiUrl?: string;
|
|
40
43
|
fetchParameters?: RequestInit;
|
|
41
44
|
iconsBaseUrl?: string;
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated use `adjustUrl`
|
|
47
|
+
*/ adjustUrlQuery?: (sp: URLSearchParams) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Adjust geocoding URL before the fetch.
|
|
50
|
+
*/ adjustUrl?: (url: URL) => void;
|
|
51
|
+
focus?: (options?: FocusOptions) => void;
|
|
44
52
|
blur?: () => void;
|
|
45
53
|
setQuery?: (value: string, submit?: boolean, reverse?: boolean) => void;
|
|
46
54
|
clearList?: () => void;
|
|
@@ -86,7 +94,7 @@ export type GeocodingControlEvents = typeof __propDef.events;
|
|
|
86
94
|
export type GeocodingControlSlots = typeof __propDef.slots;
|
|
87
95
|
export default class GeocodingControl extends SvelteComponent<GeocodingControlProps, GeocodingControlEvents, GeocodingControlSlots> {
|
|
88
96
|
get ZOOM_DEFAULTS(): Record<string, number>;
|
|
89
|
-
get focus(): () => void;
|
|
97
|
+
get focus(): (options?: FocusOptions) => void;
|
|
90
98
|
get blur(): () => void;
|
|
91
99
|
get setQuery(): (value: string, submit?: boolean, reverse?: boolean) => void;
|
|
92
100
|
get clearList(): () => void;
|