UNPKG

@maptiler/geocoding-control

Version:

The Javascript & TypeScript Map Control component for MapTiler Geocoding service. Easy to be integrated into any JavaScript mapping application.

1,212 lines (1,195 loc) 53.7 kB
import { css as I, LitElement as F, svg as z, html as m, unsafeCSS as ce, nothing as J } from "lit"; import { customElement as O, property as p, state as b, query as De } from "lit/decorators.js"; import { convert as Ve } from "geo-coordinates-parser"; import { classMap as A } from "lit/directives/class-map.js"; import { repeat as qe } from "lit/directives/repeat.js"; import "@turf/clone"; import { styleMap as Ne } from "lit/directives/style-map.js"; import { config as Ze } from "@maptiler/sdk"; import { featureCollection as D, polygon as Ke, feature as Qe } from "@turf/helpers"; import Le from "@turf/union"; import H from "maplibre-gl"; import be from "@turf/bbox"; import Ye from "@turf/difference"; import He from "@turf/flatten"; var Je = Object.getOwnPropertyDescriptor, Xe = (t, e, i, a) => { for (var s = a > 1 ? void 0 : a ? Je(e, i) : e, o = t.length - 1, r; o >= 0; o--) (r = t[o]) && (s = r(s) || s); return s; }; let X = class extends F { render() { return z` <svg viewBox="0 0 14 14" width="13" height="13"> <path d="M13.12.706a.982.982 0 0 0-1.391 0L6.907 5.517 2.087.696a.982.982 0 1 0-1.391 1.39l4.821 4.821L.696 11.73a.982.982 0 1 0 1.39 1.39l4.821-4.821 4.822 4.821a.982.982 0 1 0 1.39-1.39L8.298 6.908l4.821-4.822a.988.988 0 0 0 0-1.38Z" /> </svg> `; } }; X.styles = I` svg { display: block; fill: var(--color-icon-button); } `; X = Xe([ O("maptiler-geocode-clear-icon") ], X); var et = Object.getOwnPropertyDescriptor, tt = (t, e, i, a) => { for (var s = a > 1 ? void 0 : a ? et(e, i) : e, o = t.length - 1, r; o >= 0; o--) (r = t[o]) && (s = r(s) || s); return s; }; let ee = class extends F { render() { return z` <svg viewBox="0 0 30 30" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M15 0C6.705 0 0 6.705 0 15C0 23.295 6.705 30 15 30C23.295 30 30 23.295 30 15C30 6.705 23.295 0 15 0ZM22.5 20.385L20.385 22.5L15 17.115L9.615 22.5L7.5 20.385L12.885 15L7.5 9.615L9.615 7.5L15 12.885L20.385 7.5L22.5 9.615L17.115 15L22.5 20.385Z" /> </svg> `; } }; ee.styles = I` svg { display: block; fill: #e15042; } `; ee = tt([ O("maptiler-geocode-fail-icon") ], ee); var it = Object.getOwnPropertyDescriptor, st = (t, e, i, a) => { for (var s = a > 1 ? void 0 : a ? it(e, i) : e, o = t.length - 1, r; o >= 0; o--) (r = t[o]) && (s = r(s) || s); return s; }; let te = class extends F { render() { return m` <div> <svg viewBox="0 0 18 18" width="24" height="24" class="loading-icon"> <path fill="#333" d="M4.4 4.4l.8.8c2.1-2.1 5.5-2.1 7.6 0l.8-.8c-2.5-2.5-6.7-2.5-9.2 0z" /> <path opacity=".1" d="M12.8 12.9c-2.1 2.1-5.5 2.1-7.6 0-2.1-2.1-2.1-5.5 0-7.7l-.8-.8c-2.5 2.5-2.5 6.7 0 9.2s6.6 2.5 9.2 0 2.5-6.6 0-9.2l-.8.8c2.2 2.1 2.2 5.6 0 7.7z" /> </svg> </div> `; } }; te.styles = I` div { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); pointer-events: none; display: flex; align-items: center; } .loading-icon { animation: rotate 0.8s infinite cubic-bezier(0.45, 0.05, 0.55, 0.95); } @keyframes rotate { from { -webkit-transform: rotate(0); transform: rotate(0); } to { -webkit-transform: rotate(360deg); transform: rotate(360deg); } } `; te = st([ O("maptiler-geocode-loading-icon") ], te); var rt = Object.getOwnPropertyDescriptor, ot = (t, e, i, a) => { for (var s = a > 1 ? void 0 : a ? rt(e, i) : e, o = t.length - 1, r; o >= 0; o--) (r = t[o]) && (s = r(s) || s); return s; }; let ie = class extends F { render() { return z` <svg viewBox="0 0 60.006 21.412" width="14" height="20"> <path d="M30.003-26.765C13.46-26.765 0-14.158 0 1.337c0 23.286 24.535 42.952 28.39 46.04.24.192.402.316.471.376.323.282.732.424 1.142.424.41 0 .82-.142 1.142-.424.068-.06.231-.183.471-.376 3.856-3.09 28.39-22.754 28.39-46.04 0-15.495-13.46-28.102-30.003-28.102Zm1.757 12.469c4.38 0 7.858 1.052 10.431 3.158 2.595 2.105 3.89 4.913 3.89 8.422 0 2.34-.53 4.362-1.593 6.063-1.063 1.702-3.086 3.616-6.063 5.742-2.042 1.51-3.337 2.659-3.89 3.446-.532.787-.8 1.82-.8 3.096v1.914h-8.449V15.18c0-2.041.434-3.815 1.306-5.325.872-1.51 2.467-3.118 4.785-4.82 2.233-1.594 3.7-2.89 4.402-3.889a5.582 5.582 0 0 0 1.087-3.35c0-1.382-.51-2.435-1.531-3.158-1.02-.723-2.45-1.087-4.28-1.087-3.19 0-6.826 1.047-10.91 3.131l-3.472-6.986c4.742-2.659 9.77-3.992 15.087-3.992Zm-1.88 37.324c1.765 0 3.124.472 4.08 1.408.98.936 1.47 2.276 1.47 4.02 0 1.68-.49 3.007-1.47 3.985-.977.957-2.336 1.435-4.08 1.435-1.787 0-3.171-.465-4.15-1.4-.978-.958-1.47-2.298-1.47-4.02 0-1.787.48-3.14 1.436-4.054.957-.915 2.355-1.374 4.184-1.374Z" /> </svg> `; } }; ie.styles = I` svg { display: block; fill: var(--color-icon-button); } `; ie = ot([ O("maptiler-geocode-reverse-geocoding-icon") ], ie); var at = Object.getOwnPropertyDescriptor, lt = (t, e, i, a) => { for (var s = a > 1 ? void 0 : a ? at(e, i) : e, o = t.length - 1, r; o >= 0; o--) (r = t[o]) && (s = r(s) || s); return s; }; let se = class extends F { render() { return z` <svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 13 13" > <circle cx="4.789" cy="4.787" r="3.85" /> <path d="M12.063 12.063 7.635 7.635" /> </svg> `; } }; se.styles = I` circle { stroke-width: 1.875; fill: none; } path { stroke-width: 1.875; stroke-linecap: round; } svg { display: block; stroke: var(--color-icon-button); } `; se = lt([ O("maptiler-geocode-search-icon") ], se); function nt(t, e, i) { const a = e[1], s = e[0], o = a - s; return t === a && i ? t : ((t - s) % o + o) % o + s; } function V(t) { const e = [...t]; return e[2] < e[0] && (Math.abs((e[0] + e[2] + 360) / 2) > Math.abs((e[0] - 360 + e[2]) / 2) ? e[0] -= 360 : e[2] += 360), e; } let P; async function ct(t, e, i) { for (const a of e ?? []) if (!(t && (a.minZoom != null && a.minZoom > t[0] || a.maxZoom != null && a.maxZoom < t[0]))) { if (a.type === "fixed") return a.coordinates.join(","); if (a.type === "client-geolocation") if (P && a.cachedLocationExpiry && P.time + a.cachedLocationExpiry > Date.now()) { if (P.coords) return P.coords; } else { let s; try { return s = await new Promise((o, r) => { i.signal.addEventListener("abort", () => { r(Error("aborted")); }), navigator.geolocation.getCurrentPosition( (u) => { o([u.coords.longitude, u.coords.latitude].map((y) => y.toFixed(6)).join(",")); }, (u) => { r(u); }, a ); }), s; } catch { } finally { a.cachedLocationExpiry && (P = { time: Date.now(), coords: s }); } if (i.signal.aborted) return; } if (a.type === "server-geolocation") return "ip"; if (t && a.type === "map-center") return t[1].toFixed(6) + "," + t[2].toFixed(6); } } const ht = ".sprite-icon{align-self:center;justify-self:center;opacity:.75;background-repeat:no-repeat}li{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:first-child{padding-top:10px}li:last-child{padding-bottom:10px}li.picked{background-color:#e7edff}li.picked .secondary{color:#96a4c7;padding-left:4px}li.picked .line2{color:#96a4c7}li.selected{background-color:#f3f6ff;animation:backAndForth 5s linear infinite}li.selected .primary{color:#2b8bfb}li.selected .secondary{color:#a2adc7;padding-left:4px}li.selected .line2{color:#a2adc7}li>img{align-self:center;justify-self:center;opacity:.75}.texts{padding:0 17px 0 0}.texts>*{white-space:nowrap;display:block;min-width:fit-content}.primary{font-weight:600}.secondary{color:#aeb6c7;padding-left:4px}.line2{color:#aeb6c7}@keyframes 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)}}"; var pt = Object.defineProperty, dt = Object.getOwnPropertyDescriptor, $e = (t) => { throw TypeError(t); }, L = (t, e, i, a) => { for (var s = a > 1 ? void 0 : a ? dt(e, i) : e, o = t.length - 1, r; o >= 0; o--) (r = t[o]) && (s = (a ? r(e, i, s) : r(s)) || s); return a && s && pt(e, i, s), s; }, Ie = (t, e, i) => e.has(t) || $e("Cannot " + i), f = (t, e, i) => (Ie(t, e, "read from private field"), i ? i.call(t) : e.get(t)), ut = (t, e, i) => e.has(t) ? $e("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, i), C = (t, e, i) => (Ie(t, e, "access private method"), i), d, q, G, g, Fe, Oe, he, re; const Me = typeof devicePixelRatio > "u" || devicePixelRatio > 1.25, Te = Me ? "@2x" : "", S = Me ? 2 : 1; let T, Se, k = class extends F { constructor() { super(...arguments), ut(this, d), this.itemStyle = "default", this.showPlaceType = "if-needed", this.missingIconsCache = /* @__PURE__ */ new Set(), this.iconsBaseUrl = "", this.index = 0; } willUpdate(t) { t.has("feature") && f(this, d, q) && (this.index = f(this, d, q).length, C(this, d, he).call(this)); } render() { return m` <li tabindex="-1" role="option" aria-selected=${this.itemStyle === "selected"} aria-checked=${this.itemStyle === "picked"} class=${this.itemStyle} @click=${() => this.dispatchEvent(new CustomEvent("select"))} > ${T && this.spriteIcon ? m` <div class="sprite-icon" style=${Ne({ width: `${this.spriteIcon.width / S}px`, height: `${this.spriteIcon.height / S}px`, backgroundImage: `url(${this.iconsBaseUrl}sprite${Te}.png)`, backgroundPosition: `-${this.spriteIcon.x / S}px -${this.spriteIcon.y / S}px`, backgroundSize: `${T.width / S}px ${T.height / S}px` })} title=${f(this, d, g)} /> ` : this.imageUrl ? m` <img src=${this.imageUrl} alt=${this.category} title=${f(this, d, g)} @error=${C(this, d, Oe)} />` : this.feature?.address ? m` <img src=${this.iconsBaseUrl + "housenumber.svg"} alt=${f(this, d, g)} title=${f(this, d, g)} /> ` : this.feature?.id.startsWith("road.") ? m` <img src=${this.iconsBaseUrl + "road.svg"} alt=${f(this, d, g)} title=${f(this, d, g)} /> ` : this.feature?.id.startsWith("address.") ? m` <img src=${this.iconsBaseUrl + "street.svg"} alt=${f(this, d, g)} title=${f(this, d, g)} /> ` : this.feature?.id.startsWith("postal_code.") ? m` <img src=${this.iconsBaseUrl + "postal_code.svg"} alt=${f(this, d, g)} title=${f(this, d, g)} /> ` : this.feature?.id.startsWith("poi.") ? m` <img src=${this.iconsBaseUrl + "poi.svg"} alt=${f(this, d, g)} title=${f(this, d, g)} /> ` : f(this, d, G) ? m` <img src=${this.iconsBaseUrl + "reverse.svg"} alt=${f(this, d, g)} title=${f(this, d, g)} /> ` : m` <img src=${this.iconsBaseUrl + "area.svg"} alt=${f(this, d, g)} title=${f(this, d, g)} /> `} <span class="texts"> <span> <span class="primary"> ${f(this, d, G) ? this.feature?.place_name : this.feature?.place_name.replace(/,.*/, "")} </span> ${this.showPlaceType === "always" || this.showPlaceType !== "never" && !this.feature?.address && !this.feature?.id.startsWith("road.") && !this.feature?.id.startsWith("address.") && !this.feature?.id.startsWith("postal_code.") && (!this.feature?.id.startsWith("poi.") || !this.imageUrl) && !f(this, d, G) ? m` <span class="secondary"> ${f(this, d, g)} </span> ` : J} </span> <span class="line2"> ${f(this, d, G) ? this.feature?.text : this.feature?.place_name.replace(/[^,]*,?s*/, "")} </span> </span> </li> `; } }; d = /* @__PURE__ */ new WeakSet(); q = function() { return this.feature?.properties?.categories; }; G = function() { return this.feature?.place_type[0] === "reverse"; }; g = function() { return this.feature?.properties?.categories?.join(", ") ?? this.feature?.place_type_name?.[0] ?? this.feature?.place_type[0]; }; Fe = function() { Se ??= fetch(`${this.iconsBaseUrl}sprite${Te}.json`).then((t) => t.json()).then((t) => { T = t; }).catch(() => { T = null; }); }; Oe = function() { this.imageUrl && this.missingIconsCache.add(this.imageUrl), C(this, d, he).call(this); }; he = function() { T !== void 0 ? C(this, d, re).call(this) : (C(this, d, Fe).call(this), Se?.then(() => { C(this, d, re).call(this); })); }; re = function() { do { if (this.index--, this.category = f(this, d, q)?.[this.index], this.spriteIcon = this.category ? T?.icons[this.category] : void 0, this.spriteIcon) break; this.imageUrl = this.category ? this.iconsBaseUrl + this.category.replace(/ /g, "_") + ".svg" : void 0; } while (this.index > -1 && (!this.imageUrl || this.missingIconsCache.has(this.imageUrl))); }; k.styles = I` ${ce(ht)} `; L([ p({ type: Object }) ], k.prototype, "feature", 2); L([ p({ type: String }) ], k.prototype, "itemStyle", 2); L([ p({ type: String }) ], k.prototype, "showPlaceType", 2); L([ p({ attribute: !1 }) ], k.prototype, "missingIconsCache", 2); L([ p({ type: String }) ], k.prototype, "iconsBaseUrl", 2); L([ b() ], k.prototype, "category", 2); L([ b() ], k.prototype, "imageUrl", 2); L([ b() ], k.prototype, "spriteIcon", 2); L([ b() ], k.prototype, "index", 2); k = L([ O("maptiler-geocoder-feature-item") ], k); const ft = "form{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;pointer-events:all}form,form *,form *:after,form *:before{box-sizing:border-box}form.can-collapse{max-width:29px}form.can-collapse input::placeholder{transition:opacity .25s;opacity:0}form{width:270px;max-width:270px}form:focus-within,form:hover{width:270px;max-width:270px}form input::placeholder,form:focus-within input::placeholder,form:hover input::placeholder{opacity:1}input{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:focus{color:#444952;outline:0;outline:none;box-shadow:none}ul,div.error,div.no-results{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{font-size:14px;line-height:16px;box-shadow:0 5px 10px #33335926}div.error,div.no-results{font:inherit;line-height:18px;font-size:12px;display:flex;gap:16px}div.error{padding:16px;font-weight:600;color:#e25041;background-color:#fbeae8}div.error div{flex-grow:1}div.error maptiler-geocode-fail-icon{flex-shrink:0;width:20px;height:20px}div.error button{flex-shrink:0}div.error button maptiler-geocode-clear-icon{--color-icon-button: #e25041}div.error button:hover maptiler-geocode-clear-icon,div.error button:active maptiler-geocode-clear-icon{--color-icon-button: inherit}div.no-results{padding:14px 24px 14px 16px;font-weight:400;color:#6b7c93;box-shadow:0 5px 10px #33335926}div.no-results maptiler-geocode-fail-icon{margin-top:4px;flex-shrink:0;width:20px;height:20px}ul.options.open-on-top{top:auto;bottom:calc(100% + 6px)}button{padding:0;margin:0;border:0;background-color:transparent;height:auto;width:auto}button:hover{background-color:transparent}button:hover,button:active{--color-icon-button: #2b8bfb}.input-group{display:flex;align-items:stretch;gap:7px;padding-inline:8px;border-radius:4px;overflow:hidden}.input-group:focus-within{outline:#2b8bfb solid 2px}.search-button{flex-shrink:0}.clear-button-container{display:flex;display:none;position:relative;align-items:stretch}.clear-button-container.displayable{display:flex;flex-shrink:0}:host(.maptiler-geocoder):not(:empty){box-shadow:none}:host(.maptiler-geocoder) .input-group{border:white solid 2px}:host(.maptiler-geocoder) .input-group:focus-within{border:#2b8bfb solid 2px;outline:0;outline:none}:host(.maptiler-geocoder) form.can-collapse{max-width:33px}:host(.maptiler-geocoder) form,:host(.maptiler-geocoder) form:focus-within,:host(.maptiler-geocoder) form:hover{width:270px;max-width:270px}:host(.leaflet-geocoder) .input-group{border:white solid 1px}:host(.leaflet-geocoder) form.can-collapse{max-width:30px}"; var mt = Object.defineProperty, gt = Object.getOwnPropertyDescriptor, Ce = (t) => { throw TypeError(t); }, c = (t, e, i, a) => { for (var s = a > 1 ? void 0 : a ? gt(e, i) : e, o = t.length - 1, r; o >= 0; o--) (r = t[o]) && (s = (a ? r(e, i, s) : r(s)) || s); return a && s && mt(e, i, s), s; }, pe = (t, e, i) => e.has(t) || Ce("Cannot " + i), w = (t, e, i) => (pe(t, e, "read from private field"), i ? i.call(t) : e.get(t)), U = (t, e, i) => e.has(t) ? Ce("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, i), oe = (t, e, i, a) => (pe(t, e, "write to private field"), e.set(t, i), i), h = (t, e, i) => (pe(t, e, "access private method"), i), N, B, ae, R, l, Z, Ee, de, x, ue, K, fe, me, $, ge, Q, Pe, le, Ue, Ge, Be, Re, ze, je, Ae; let n = class extends F { constructor() { super(...arguments), U(this, l), this.clearListOnPick = !1, this.clearOnBlur = !1, this.collapsed = !1, this.excludeTypes = !1, this.exhaustiveReverseGeocoding = !1, this.fetchFullGeometryOnPick = !1, this.keepListOpen = !1, this.openListOnTop = !1, this.reverseActive = !1, this.searchValue = "", this.selectedItemIndex = -1, this.cachedFeatures = [], this.lastSearchUrl = "", this.focused = !1, this.isFeatureListVisible = !1, this.isFeatureListInteractedWith = !1, U(this, N, !1), U(this, B), U(this, ae, /* @__PURE__ */ new Set()), U(this, R); } firstUpdated() { oe(this, N, !0); } /** * Set the options of this instance. * * @param options options to set */ setOptions(t) { const e = { ...t }; for (const i of Object.keys(e)) yt.includes(i) || delete e[i]; Object.assign(this, e); } /** * Set the content of search input box. * * @param value text to set */ setQuery(t) { h(this, l, me).call(this, t, { external: !0 }), h(this, l, fe).call(this); } /** * Set the content of search input box and immediately submit it. * * @param value text to set and submit */ submitQuery(t) { h(this, l, ge).call(this, t, { external: !0 }); } /** * Clear search result list. */ clearList() { h(this, l, $).call(this), this.picked = void 0, this.selectedItemIndex = -1; } /** * Focus the search input box. * * @param options [FocusOptions](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus#options) */ focus(t) { this.input.focus(t); } /** * Blur the search input box. */ blur() { this.input.blur(); } addEventListener(t, e, i) { super.addEventListener(t, e, i); } removeEventListener(t, e, i) { super.removeEventListener(t, e, i); } /** @internal */ handleMapChange(t) { oe(this, R, t); } /** @internal */ handleMapClick(t) { this.reverseActive && h(this, l, Pe).call(this, t); } willUpdate(t) { t.has("error") && this.error && console.error("[MapTilerGeocodingControl] Error:", this.error), t.has("enableReverse") && (this.reverseActive = this.enableReverse === "always"), ["picked"].some((e) => t.has(e)) && this.picked && (this.clearListOnPick && h(this, l, $).call(this), this.selectedItemIndex = -1), ["searchValue", "minLength"].some((e) => t.has(e)) && w(this, l, de) && (h(this, l, $).call(this), this.error = void 0), ["focused", "listIsInteractedWith"].some((e) => t.has(e)) && this.clearOnBlur && !this.focused && !this.isFeatureListInteractedWith && (this.searchValue = ""), ["selectFirst", "listFeatures", "selectedItemIndex", "picked"].some((e) => t.has(e)) && this.selectFirst !== !1 && this.listFeatures?.length && this.selectedItemIndex == -1 && !this.picked && (this.selectedItemIndex = 0), ["listFeatures", "selectedItemIndex"].some((e) => t.has(e)) && h(this, l, x).call(this, "select", { feature: w(this, l, Z) }), ["picked"].some((e) => t.has(e)) && this.picked && this.picked.id !== t.get("picked")?.id && (this.fetchFullGeometryOnPick && !this.picked.address && this.picked.geometry.type === "Point" && this.picked.place_type[0] !== "reverse" ? h(this, l, Q).call(this, this.picked.id, { byId: !0 }) : Promise.resolve()).then( () => { h(this, l, x).call(this, "pick", { feature: this.picked }); }, (e) => { e && typeof e == "object" && "name" in e && e.name === "AbortError" || (this.error = e, h(this, l, x).call(this, "pick", { feature: this.picked })); } ), ["listFeatures", "focused", "isFeatureListInteractedWith", "keepListOpen"].some((e) => t.has(e)) && (this.isFeatureListVisible = !!this.listFeatures?.length && (this.focused || this.isFeatureListInteractedWith || this.keepListOpen)), ["isFeatureListVisible"].some((e) => t.has(e)) && (this.isFeatureListVisible ? h(this, l, x).call(this, "featuresshow") : h(this, l, x).call(this, "featureshide")), ["reverseActive"].some((e) => t.has(e)) && h(this, l, x).call(this, "reversetoggle", { reverse: this.reverseActive }); } render() { return m` <form @submit=${h(this, l, ue)} class=${A({ "can-collapse": this.collapsed && this.searchValue === "" })}> <div class="input-group"> <button class="search-button" type="button" @click=${() => { this.input.focus(); }} > <maptiler-geocode-search-icon></maptiler-geocode-search-icon> </button> <input .value=${this.searchValue} @focus=${() => this.focused = !0} @blur=${() => this.focused = !1} @click=${() => this.focused = !0} @keydown=${h(this, l, le)} @input=${h(this, l, Ue)} @change=${() => this.picked = void 0} placeholder=${this.placeholder ?? "Search"} aria-label=${this.placeholder ?? "Search"} /> <div class="clear-button-container ${A({ displayable: this.searchValue !== "" })}"> ${w(this, l, Ee) ? m`<maptiler-geocode-loading-icon></maptiler-geocode-loading-icon>` : m` <button type="button" @click=${h(this, l, Ae)} title=${this.clearButtonTitle ?? "clear"}> <maptiler-geocode-clear-icon></maptiler-geocode-clear-icon> </button> `} </div> ${this.enableReverse === "button" ? m` <button type="button" class=${A({ active: this.reverseActive })} title=${this.reverseButtonTitle ?? "toggle reverse geocoding"} @click=${() => this.reverseActive = !this.reverseActive} > <maptiler-geocode-reverse-geocoding-icon></maptiler-geocode-reverse-geocoding-icon> </button> ` : J} <!-- <slot /> --> </div> ${this.error ? m` <div class="error"> <maptiler-geocode-fail-icon></maptiler-geocode-fail-icon> <div>${this.errorMessage ?? "Something went wrong…"}</div> <button @click=${() => this.error = void 0}> <maptiler-geocode-clear-icon></maptiler-geocode-clear-icon> </button> </div> ` : !this.focused && !this.isFeatureListInteractedWith && !this.keepListOpen || this.listFeatures === void 0 ? J : this.listFeatures.length === 0 ? m` <div class="no-results"> <maptiler-geocode-fail-icon></maptiler-geocode-fail-icon> <div> ${this.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!"} </div> </div> ` : m` <ul class="options ${A({ "open-on-top": this.openListOnTop })}" @pointerleave=${h(this, l, Re)} @pointerdown=${h(this, l, ze)} @pointerup=${h(this, l, je)} @keydown=${h(this, l, le)} role="listbox" > ${qe( this.listFeatures, (t) => t.id + (t.address ? "," + t.address : ""), (t, e) => m` <maptiler-geocoder-feature-item .feature=${t} .showPlaceType=${this.showPlaceType ?? "if-needed"} itemStyle=${this.selectedItemIndex === e ? "selected" : this.picked?.id === t.id ? "picked" : "default"} @pointerenter=${() => { h(this, l, Be).call(this, e); }} @select=${() => { h(this, l, Ge).call(this, t); }} .missingIconsCache=${w(this, ae)} .iconsBaseUrl=${this.iconsBaseUrl ?? "https://cdn.maptiler.com/maptiler-geocoding-control/v3.0.0/icons/"} /> ` )} </ul> `} </form> `; } }; N = /* @__PURE__ */ new WeakMap(); B = /* @__PURE__ */ new WeakMap(); ae = /* @__PURE__ */ new WeakMap(); R = /* @__PURE__ */ new WeakMap(); l = /* @__PURE__ */ new WeakSet(); Z = function() { return this.listFeatures?.[this.selectedItemIndex]; }; Ee = function() { return this.abortController !== void 0; }; de = function() { return this.searchValue.length < (this.minLength ?? 2); }; x = function(t, ...[e]) { w(this, N) && this.dispatchEvent( new CustomEvent(t, { bubbles: !0, composed: !0, detail: e }) ); }; ue = function(t, { external: e = !1 } = {}) { t?.preventDefault(), this.focused = !1, clearTimeout(w(this, B)), this.selectedItemIndex > -1 && this.listFeatures ? (this.picked = this.listFeatures[this.selectedItemIndex], this.searchValue = this.picked.place_type[0] === "reverse" ? this.picked.place_name : this.picked.place_name.replace(/,.*/, ""), this.error = void 0, this.selectedItemIndex = -1) : this.searchValue && h(this, l, Q).call(this, this.searchValue, { exact: !0, external: e }).then(() => { this.picked = void 0; }).catch((i) => this.error = i); }; K = function(t) { try { return Ve(t, 6); } catch { return !1; } }; fe = function() { setTimeout(() => { this.input.focus(), this.focused = !0, this.input.select(); }); }; me = function(t, { external: e = !1 } = {}) { if (this.searchValue = t, h(this, l, x).call(this, "querychange", { query: this.searchValue, reverseCoords: h(this, l, K).call(this, t) }), this.error = void 0, this.picked = void 0, this.showResultsWhileTyping !== !1) { if (clearTimeout(w(this, B)), w(this, l, de)) return; const i = this.searchValue; oe(this, B, window.setTimeout(() => { h(this, l, Q).call(this, i, { external: e }).catch((a) => this.error = a); }, this.debounceSearch ?? 200)); } else h(this, l, $).call(this); }; $ = function() { this.listFeatures !== void 0 && (this.listFeatures = void 0, h(this, l, x).call(this, "featuresclear")); }; ge = function(t, { external: e = !1 } = {}) { this.searchValue = t, h(this, l, x).call(this, "querychange", { query: this.searchValue, reverseCoords: h(this, l, K).call(this, t) }), this.selectedItemIndex = -1, h(this, l, ue).call(this, void 0, { external: e }); }; Q = async function(t, { byId: e = !1, exact: i = !1, external: a = !1 } = {}) { this.error = void 0, this.abortController?.abort(); const s = new AbortController(); this.abortController = s; try { const o = this.apiUrl ?? "https://api.maptiler.com/geocoding", r = h(this, l, K).call(this, t), u = new URL(o + "/" + encodeURIComponent(r ? `${r.decimalLongitude},${r.decimalLatitude}` : t) + ".json"), y = u.searchParams; this.language !== void 0 && y.set("language", Array.isArray(this.language) ? this.language.join(",") : this.language ?? ""); const [M] = w(this, R) ?? [void 0]; let _ = (!r || this.reverseGeocodingTypes === void 0 ? this.types : this.reverseGeocodingTypes)?.map( (v) => typeof v == "string" ? v : M === void 0 || (v[0] ?? 0) <= M && M < (v[1] ?? 1 / 0) ? v[2] : void 0 ).filter((v) => v !== void 0); _ && (_ = [...new Set(_)], y.set("types", _.join(","))); const ye = !r || this.reverseGeocodingExcludeTypes === void 0 ? this.excludeTypes : this.reverseGeocodingExcludeTypes; if (ye && y.set("excludeTypes", String(ye)), this.bbox && y.set("bbox", this.bbox.map((v) => v.toFixed(6)).join(",")), this.country && y.set("country", Array.isArray(this.country) ? this.country.join(",") : this.country), this.worldview && y.set("worldview", this.worldview), !e && !r) { const v = this.proximity ?? [{ type: "server-geolocation" }], xe = await ct(w(this, R), v, s); xe && y.set("proximity", xe), (i || this.showResultsWhileTyping === !1) && y.set("autocomplete", "false"), y.set("fuzzyMatch", String(this.fuzzyMatch !== !1)); } const ve = this.limit ?? 5, Y = this.reverseGeocodingLimit ?? ve; Y > 1 && _?.length !== 1 && console.warn("[MapTilerGeocodingControl] Warning: For reverse geocoding when limit > 1 then types must contain single value."), r ? (Y === 1 || this.exhaustiveReverseGeocoding || _?.length === 1) && y.set("limit", String(Y)) : y.set("limit", String(ve)), this.apiKey && y.set("key", this.apiKey), this.adjustUrl?.(u); const We = u.searchParams.get("types") === "" && u.searchParams.get("excludeTypes") !== "true", j = u.toString(); if (j === this.lastSearchUrl) { e ? (this.clearListOnPick && h(this, l, $).call(this), this.picked = this.cachedFeatures[0]) : (this.listFeatures = this.cachedFeatures, h(this, l, x).call(this, "featureslisted", { features: this.listFeatures, external: a }), this.listFeatures[this.selectedItemIndex]?.id !== w(this, l, Z)?.id && (this.selectedItemIndex = -1)); return; } h(this, l, x).call(this, "request", { urlObj: u }), this.lastSearchUrl = j; let E; if (We) E = { type: "FeatureCollection", features: [] }; else { const v = await fetch(j, { signal: s.signal, ...this.fetchParameters }); if (!v.ok) throw new Error(await v.text()); E = await v.json(); } h(this, l, x).call(this, "response", { url: j, featureCollection: E }), e ? (this.clearListOnPick && h(this, l, $).call(this), this.picked = E.features[0], this.cachedFeatures = [this.picked]) : (this.listFeatures = E.features.filter(this.filter ?? (() => !0)), r && this.listFeatures.unshift({ type: "Feature", properties: {}, /* eslint-disable @typescript-eslint/restrict-template-expressions */ id: `reverse_${r.decimalLongitude}_${r.decimalLatitude}`, place_name: `${r.decimalLatitude}, ${r.decimalLongitude}`, text: r.toCoordinateFormat("DMS"), /* eslint-enable @typescript-eslint/restrict-template-expressions */ place_type: ["reverse"], place_type_name: ["reverse"], center: [r.decimalLongitude, r.decimalLatitude], bbox: [r.decimalLongitude, r.decimalLatitude, r.decimalLongitude, r.decimalLatitude], geometry: { type: "Point", coordinates: [r.decimalLongitude, r.decimalLatitude] } }), h(this, l, x).call(this, "featureslisted", { features: this.listFeatures, external: a }), this.cachedFeatures = this.listFeatures, this.listFeatures[this.selectedItemIndex]?.id !== w(this, l, Z)?.id && (this.selectedItemIndex = -1), r && this.input.focus()); } catch (o) { if (o && typeof o == "object" && "name" in o && o.name === "AbortError") return; throw o; } finally { s === this.abortController && (this.abortController = void 0); } }; Pe = function(t) { this.reverseActive = this.enableReverse === "always", h(this, l, $).call(this), this.picked = void 0, h(this, l, ge).call(this, `${t[1].toFixed(6)}, ${nt(t[0], [-180, 180], !0).toFixed(6)}`), h(this, l, fe).call(this); }; le = function(t) { if (!this.listFeatures) return; const e = t.key === "ArrowDown" ? 1 : t.key === "ArrowUp" ? -1 : 0; e && (this.input.focus(), this.focused = !0, t.preventDefault(), this.picked && this.selectedItemIndex === -1 && (this.selectedItemIndex = this.listFeatures.findIndex((i) => i.id === this.picked?.id)), this.selectedItemIndex === (this.picked || this.selectFirst !== !1 ? 0 : -1) && e === -1 && (this.selectedItemIndex = this.listFeatures.length), this.selectedItemIndex += e, this.selectedItemIndex >= this.listFeatures.length && (this.selectedItemIndex = -1), this.selectedItemIndex < 0 && (this.picked || this.selectFirst !== !1) && (this.selectedItemIndex = 0)); }; Ue = function(t) { h(this, l, me).call(this, t.target.value); }; Ge = function(t) { (!this.picked || this.picked.id !== t.id) && (this.picked = t, this.searchValue = t.place_name); }; Be = function(t) { this.selectedItemIndex = t; }; Re = function() { (!this.selectFirst || this.picked) && (this.selectedItemIndex = -1), this.isFeatureListInteractedWith && (this.isFeatureListInteractedWith = !1); }; ze = function() { this.isFeatureListInteractedWith = !0; }; je = function() { setTimeout(() => { this.isFeatureListInteractedWith = !1; }); }; Ae = function() { this.searchValue = "", h(this, l, x).call(this, "queryclear"), this.picked = void 0, this.input.focus(); }; n.styles = I` ${ce(ft)} `; c([ p({ attribute: !1 }) ], n.prototype, "adjustUrl", 2); c([ p({ type: String }) ], n.prototype, "apiKey", 2); c([ p({ type: String }) ], n.prototype, "apiUrl", 2); c([ p({ type: Array }) ], n.prototype, "bbox", 2); c([ p({ type: String }) ], n.prototype, "clearButtonTitle", 2); c([ p({ type: Boolean }) ], n.prototype, "clearListOnPick", 2); c([ p({ type: Boolean }) ], n.prototype, "clearOnBlur", 2); c([ p({ type: Boolean }) ], n.prototype, "collapsed", 2); c([ p({ attribute: !1 }) ], n.prototype, "country", 2); c([ p({ type: Number }) ], n.prototype, "debounceSearch", 2); c([ p({ type: String }) ], n.prototype, "enableReverse", 2); c([ p({ type: String }) ], n.prototype, "errorMessage", 2); c([ p({ type: Boolean }) ], n.prototype, "excludeTypes", 2); c([ p({ type: Boolean }) ], n.prototype, "exhaustiveReverseGeocoding", 2); c([ p({ type: Boolean }) ], n.prototype, "fetchFullGeometryOnPick", 2); c([ p({ type: Object }) ], n.prototype, "fetchParameters", 2); c([ p({ attribute: !1 }) ], n.prototype, "filter", 2); c([ p({ type: Object }) ], n.prototype, "fuzzyMatch", 2); c([ p({ type: String }) ], n.prototype, "iconsBaseUrl", 2); c([ p({ type: Boolean }) ], n.prototype, "keepListOpen", 2); c([ p({ attribute: !1 }) ], n.prototype, "language", 2); c([ p({ type: Number }) ], n.prototype, "limit", 2); c([ p({ type: Number }) ], n.prototype, "minLength", 2); c([ p({ type: String }) ], n.prototype, "noResultsMessage", 2); c([ p({ type: Boolean }) ], n.prototype, "openListOnTop", 2); c([ p({ type: String }) ], n.prototype, "placeholder", 2); c([ p({ type: Array }) ], n.prototype, "proximity", 2); c([ p({ type: Boolean }) ], n.prototype, "reverseActive", 2); c([ p({ type: String }) ], n.prototype, "reverseButtonTitle", 2); c([ p({ type: Object }) ], n.prototype, "reverseGeocodingExcludeTypes", 2); c([ p({ type: Number }) ], n.prototype, "reverseGeocodingLimit", 2); c([ p({ type: Array }) ], n.prototype, "reverseGeocodingTypes", 2); c([ p({ type: Object }) ], n.prototype, "selectFirst", 2); c([ p({ type: String }) ], n.prototype, "showPlaceType", 2); c([ p({ type: Object }) ], n.prototype, "showResultsWhileTyping", 2); c([ p({ type: Array }) ], n.prototype, "types", 2); c([ p({ type: String }) ], n.prototype, "worldview", 2); c([ De("input") ], n.prototype, "input", 2); c([ b() ], n.prototype, "searchValue", 2); c([ b() ], n.prototype, "listFeatures", 2); c([ b() ], n.prototype, "selectedItemIndex", 2); c([ b() ], n.prototype, "picked", 2); c([ b() ], n.prototype, "cachedFeatures", 2); c([ b() ], n.prototype, "lastSearchUrl", 2); c([ b() ], n.prototype, "error", 2); c([ b() ], n.prototype, "abortController", 2); c([ b() ], n.prototype, "focused", 2); c([ b() ], n.prototype, "isFeatureListVisible", 2); c([ b() ], n.prototype, "isFeatureListInteractedWith", 2); n = c([ O("maptiler-geocoder") ], n); const yt = [ "adjustUrl", "apiKey", "apiUrl", "bbox", "clearButtonTitle", "clearListOnPick", "clearOnBlur", "collapsed", "country", "debounceSearch", "enableReverse", "errorMessage", "excludeTypes", "reverseGeocodingExcludeTypes", "exhaustiveReverseGeocoding", "fetchParameters", "fetchFullGeometryOnPick", "filter", "fuzzyMatch", "iconsBaseUrl", "keepListOpen", "language", "limit", "reverseGeocodingLimit", "minLength", "noResultsMessage", "openListOnTop", "placeholder", "proximity", "reverseActive", "reverseButtonTitle", "selectFirst", "showPlaceType", "showResultsWhileTyping", "types", "reverseGeocodingTypes", "worldview" ], vt = "svg{display:block;fill:var(--maptiler-geocode-marker-fill, #3170fe);stroke:var(--maptiler-geocode-marker-stroke, #3170fe);height:30px}:host(.marker-selected){z-index:2}:host(.marker-selected) svg path{fill:var(--maptiler-geocode-marker-selected-fill, #98b7ff);stroke:var(--maptiler-geocode-marker-selected-stroke, #3170fe)}:host(.marker-reverse) svg path{fill:var(--maptiler-geocode-marker-reverse-fill, silver);stroke:var(--maptiler-geocode-marker-reverse-stroke, gray)}:host(.marker-interactive){cursor:pointer!important}:host(.marker-fuzzy) svg path{fill:var(--maptiler-geocode-marker-fuzzy-fill, silver);stroke:var(--maptiler-geocode-marker-fuzzy-stroke, gray)}:host(.marker-fuzzy.marker-selected) svg path{fill:var(--maptiler-geocode-marker-selected-fuzzy-fill, #ddd);stroke:var(--maptiler-geocode-marker-selected-fuzzy-stroke, silver)}"; var xt = Object.getOwnPropertyDescriptor, bt = (t, e, i, a) => { for (var s = a > 1 ? void 0 : a ? xt(e, i) : e, o = t.length - 1, r; o >= 0; o--) (r = t[o]) && (s = r(s) || s); return s; }; let ne = class extends F { render() { return z` <svg viewBox="0 0 70 85" fill="none" class:in-map={displayIn !== "list"} > <path stroke-width="4" d="M 5,33.103579 C 5,17.607779 18.457,5 35,5 C 51.543,5 65,17.607779 65,33.103579 C 65,56.388679 40.4668,76.048179 36.6112,79.137779 C 36.3714,79.329879 36.2116,79.457979 36.1427,79.518879 C 35.8203,79.800879 35.4102,79.942779 35,79.942779 C 34.5899,79.942779 34.1797,79.800879 33.8575,79.518879 C 33.7886,79.457979 33.6289,79.330079 33.3893,79.138079 C 29.5346,76.049279 5,56.389379 5,33.103579 Z M 35.0001,49.386379 C 43.1917,49.386379 49.8323,42.646079 49.8323,34.331379 C 49.8323,26.016779 43.1917,19.276479 35.0001,19.276479 C 26.8085,19.276479 20.1679,26.016779 20.1679,34.331379 C 20.1679,42.646079 26.8085,49.386379 35.0001,49.386379 Z" /> </svg> `; } }; ne.styles = I` ${ce(vt)} `; ne = bt([ O("maptiler-geocode-marker") ], ne); const wt = "@maptiler/geocoding-control", kt = "3.0.0"; function we(t) { const e = Ye( D([ Ke([ [ [180, 90], [-180, 90], [-180, -90], [180, -90], [180, 90] ] ]), t ]) ); if (!e) return; e.properties = { isMask: !0 }; const i = V(be(t)), a = (i[2] - i[0]) / 360 / 1e3, s = i[0] < -180, o = i[2] > 180, r = He(t); if (r.features.length > 1 && (s || o)) for (const u of r.features) { const y = V(be(u)); if (o && y[0] < -180 + a) for (const M of u.geometry.coordinates) for (const _ of M) _[0] += 360 - a; if (s && y[2] > 180 - a) for (const M of u.geometry.coordinates) for (const _ of M) _[0] -= 360 - a; } return D([r.features.length < 2 ? t : Le(r) ?? t, e]); } const _t = { continental_marine: 4, country: 4, major_landform: 8, region: 5, subregion: 6, county: 7, joint_municipality: 8, joint_submunicipality: 9, municipality: 10, municipal_district: 11, locality: 12, neighbourhood: 13, place: 14, postal_code: 14, road: 16, poi: 17, address: 18, "poi.peak": 15, "poi.shop": 18, "poi.cafe": 18, "poi.restaurant": 18, "poi.aerodrome": 13 // TODO add many more }, Lt = { fill: { paint: { "fill-color": "#000", "fill-opacity": 0.1 }, filter: ["all", ["==", ["geometry-type"], "Polygon"], ["has", "isMask"]] }, line: { layout: { "line-cap": "square" }, paint: { "line-width": ["case", ["==", ["geometry-type"], "Polygon"], 2, 3], "line-dasharray": [1, 1], "line-color": "#3170fe" }, filter: ["!", ["has", "isMask"]] } }, W = "mtlr-gc-full-geom", ke = "mtlr-gc-full-geom-fill", _e = "mtlr-gc-full-geom-line"; class $t extends H.Evented { #e = {}; #t; #i; constructor(e = {}) { super(), this.setOptions(e); } /** @internal Not to be called directly */ onAdd(e) { this.#t = e, this.#i = e._container.ownerDocument.createElement("maptiler-geocoder"), this.#i.classList.add("maplibregl-geocoder"), this.#v(), this.#k(); const i = e._container.ownerDocument.createElement("div"); return i.classList.add("maplibregl-ctrl-geocoder", "maplibregl-ctrl", "maplibregl-ctrl-group"), i.style.position = "relative", i.style.zIndex = "3", i.appendChild(this.#i), setTimeout(() => this.#i?.setOptions({ openListOnTop: i.matches(".maplibregl-ctrl-bottom-left *, .maplibregl-ctrl-bottom-right *") })), i; } /** @internal Not to be called directly */ onRemove() { this.#_(), this.#t = void 0, this.#i = void 0; } getOptions() { return { ...this.#e }; } setOptions(e) { Object.assign(this.#e, e), this.#v(); } setQuery(e) { this.#i?.setQuery(e); } submitQuery(e) { this.#i?.submitQuery(e); } clearMap() { this.#o = [], this.#p(void 0, void 0); } clearList() { this.#i?.clearList(); } setReverseMode(e) { this.setOptions({ reverseActive: e }); } focus(e) { this.#i?.focus(e); } blur() { this.#i?.blur(); } /** Markers currently displayed on the map */ #l = /* @__PURE__ */ new Map(); /** Marker representing the selected feature */ #c; /** Marker representing the picked feature */ #r; /** Features currently marked on the map */ #o; /** Used to restore features on style switch */ #a; /** Remember last feature that the map flew to as to not do it again */ #m; #g = { reversetoggle: (e) => { const i = this.#t?.getCanvasContainer(); i && (i.style.cursor = e.detail.reverse ? "crosshair" : ""), this.#s("reversetoggle", e.detail); }, querychange: (e) => { const i = e.detail.reverseCoords; this.#w(i ? [i.decimalLongitude, i.decimalLatitude] : void 0), this.#s("querychange", e.detail); }, queryclear: () => { this.#w(void 0), this.#s("queryclear"); }, request: (e) => { this.#s("request", e.detail); }, response: (e) => { this.#s("response", e.detail); }, select: (e) => { const i = e.detail.feature; i && this.#d && this.#e.flyToSelected && this.#x(i.center, this.#h(i)), this.#o && i && this.#O(i), this.#s("select", e.detail); }, pick: (e) => { const i = e.detail.feature; i && i.id !== this.#m && this.#d && (this.#L(i), this.#p(this.#o, i)), this.#m = i?.id, this.#s("pick", e.detail); }, featuresshow: () => { this.#s("featuresshow"); }, featureshide: () => { this.#s("featureshide"); }, featureslisted: (e) => { const i = e.detail.features; this.#o = i, this.#p(this.#o, void 0), this.#$(e), this.#s("featureslisted", e.detail); }, featuresclear: () => { this.#o = void 0, this.#p(void 0, void 0), this.#s("featuresclear"); }, focusin: () => { this.#s("focusin"); }, focusout: () => { this.#s("focusout"); } }; #y = { render: () => { const e = this.#t?.getZoom(), i = this.#t?.getCenter(); this.#i?.handleMapChange(e && i ? [e, i.lng, i.lat] : void 0); }, click: (e) => { this.#i?.handleMapClick([e.lngLat.lng, e.lngLat.lat]); }, styledata: () => { setTimeout(() => { this.#a && this.#u(); }); } }; #v() { this.#i && (this.#i.setOptions(this.#e), this.#i.fetchFullGeometryOnPick = this.#e.pickedResultStyle !== "marker-only"); } #k() { if (!(!this.#i || !this.#t)) { for (const [e, i] of Object.entries(this.#g)) this.#i.addEventListener(e, i); for (const [e, i] of Object.entries(this.#y)) this.#t.on(e, i); } } #_() { if (!(!this.#i || !this.#t)) { for (const [e, i] of Object.entries(this.#g)) this.#i.removeEventListener(e, i); for (const [e, i] of Object.entries(this.#y)) this.#t.off(e, i); } } #s(e, i) { return super.fire({ type: e, ...i ?? {} }); } #L(e) { e.bbox[0] === e.bbox[2] && e.bbox[1] === e.bbox[3] ? this.#x(e.center, this.#h(e)) : this.#b(V(e.bbox), 50, this.#h(e)); } #$({ detail: { features: e, external: i } }) { if (!e || e.length === 0 || !this.#d || this.#e.flyToFeatures === !1 || this.#e.flyToFeatures === "never" || !i && (this.#e.flyToFeatures === void 0 || this.#e.flyToFeatures === "external")) return; const a = e.every((r) => r.matching_text), s = e.reduce( (r, u) => a || !u.matching_text ? [Math.min(r[0], u.bbox[0]), Math.min(r[1], u.bbox[1]), Math.max(r[2], u.bbox[2]), Math.max(r[3], u.bbox[3])] : r, [180, 90, -180, -90] ), o = e.map((r) => this.#h(r)).filter((r) => r !== void 0).reduce((r, u) => r === void 0 ? u : Math.max(r, u), void 0); this.#b(V(s), 50, o); } #h(e) { if (e.bbox[0] !== e.bbox[2] || e.bbox[1] !== e.bbox[3]) return; const i = e.id.replace(/\..*/, ""), a = this.#e.zoom ?? _t; return (Array.isArray(e.properties?.categories) ? e.properties.categories.reduce((s, o) => { const r = a[i + "." + o]; return s === void 0 ? r : r === void 0 ? s : Math.max(s, r); }, void 0) : void 0) ?? a[i]; } get #d() { return !!this.#e.flyTo || this.#e.flyTo === void 0; } get #I() { return typeof this.#e.flyTo == "boolean" ? {} : this.#e.flyTo; } get #F() { return typeof this.#e.flyTo == "boolean" ? {} : this.#e.flyTo; } #x(e, i) { this.#t?.flyTo({ center: e, ...i ? { zoom: i } : {}, ...this.#I }); } #b(e, i, a) { this.#t?.fitBounds( [ [e[0], e[1]], [e[2], e[3]] ], { padding: i, ...a ? { maxZoom: a } : {}, ...this.#F } ); } #w(e) { if (!(this.#e.marker === !1 || this.#e.marker === null || !this.#t)) { if (!e) { this.#r?.remove(), this.#r = void 0; return; } this.#r || (this.#e.marker instanceof Function ? this.#r = this.#e.marker(this.#t) ?? void 0 : (this.#r = this.#f(this.#e.marker).setLngLat(e).addTo(this.#t), this.#r.getElement().classList.add("marker-reverse"))), this.#r?.setLngLat(e); } } #p(e, i) { if (!this.#t) return; for (const s of this.#l.values()) s.remove(); this.#l = /* @__PURE__ */ new Map(), this.#n(void 0); const a = () => { if (!i || !this.#t || this.#e.marker === !1 || this.#e.marker === null) return; const s = this.#e.marker instanceof Function ? this.#e.marker(this.#t, i) : this.#f(this.#e.marker).setLngLat(i.center).addTo(this.#t); s && this.#l.set(i, s); }; if (i?.geometry.type === "GeometryCollection") { const s = i.geometry.geometries.filter( (o) => o.type === "Polygon" || o.type === "MultiPolygon" ); if (s.length > 0) { const o = Le(D(s.map((r) => Qe(r)))); if (o) { const r = we({ ...i, geometry: o.geometry }); r && this.#n(r); } } else { const o = i.geometry.geometries.filter( (r) => r.type === "LineString" || r.type === "MultiLineString" ); o.length > 0 && this.#n({ ...i, geometry: { type: "GeometryCollection", geometries: o } }); } } else if (i?.geometry.type.endsWith("Polygon")) { const s = we(i); s && this.#n(s), this.#e.pickedResultStyle === "full-geometry-including-polygon-center-marker" && a(); } else i?.geometry.type.endsWith("LineString") ? this.#n(i) : i?.geometry.type.endsWith("Point") && a(); if (this.#e.showResultMarkers !== !1 && this.#e.showResultMarkers !== null) for (const s of e ?? []) { if (s.id === i?.id || s.place_type.includes("reverse")) continue; let o; if (this.#e.showResultMarkers instanceof Function) { if (o = this.#e.showResultMarkers(this.#t, s), !o) continue; } else o = this.#f(this.#e.showResultMarkers).setLngLat(s.center).setPopup( new H.Popup({