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,205 lines (1,189 loc) 52.5 kB
import { css as F, LitElement as O, svg as W, html as g, unsafeCSS as le, nothing as H } from "lit"; import { customElement as C, property as p, state as b, query as Ae } from "lit/decorators.js"; import { convert as Ve } from "geo-coordinates-parser"; import { classMap as D } from "lit/directives/class-map.js"; import { repeat as qe } from "lit/directives/repeat.js"; import Ne from "@turf/clone"; import { styleMap as Ze } from "lit/directives/style-map.js"; import Y from "@turf/bbox"; import { featureCollection as A, polygon as Qe, feature as Ke } from "@turf/helpers"; import _e from "@turf/union"; import { Evented as He, Control as Ye, DomEvent as xe, Popup as Je, GeoJSON as Xe, DivIcon as et, Marker as tt } from "leaflet"; import it from "@turf/difference"; import st from "@turf/flatten"; var rt = Object.getOwnPropertyDescriptor, ot = (t, e, i, o) => { for (var s = o > 1 ? void 0 : o ? rt(e, i) : e, a = t.length - 1, r; a >= 0; a--) (r = t[a]) && (s = r(s) || s); return s; }; let J = class extends O { render() { return W` <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> `; } }; J.styles = F` svg { display: block; fill: var(--color-icon-button); } `; J = ot([ C("maptiler-geocode-clear-icon") ], J); var at = Object.getOwnPropertyDescriptor, nt = (t, e, i, o) => { for (var s = o > 1 ? void 0 : o ? at(e, i) : e, a = t.length - 1, r; a >= 0; a--) (r = t[a]) && (s = r(s) || s); return s; }; let X = class extends O { render() { return W` <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> `; } }; X.styles = F` svg { display: block; fill: #e15042; } `; X = nt([ C("maptiler-geocode-fail-icon") ], X); var lt = Object.getOwnPropertyDescriptor, ct = (t, e, i, o) => { for (var s = o > 1 ? void 0 : o ? lt(e, i) : e, a = t.length - 1, r; a >= 0; a--) (r = t[a]) && (s = r(s) || s); return s; }; let ee = class extends O { render() { return g` <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> `; } }; ee.styles = F` 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); } } `; ee = ct([ C("maptiler-geocode-loading-icon") ], ee); var ht = Object.getOwnPropertyDescriptor, pt = (t, e, i, o) => { for (var s = o > 1 ? void 0 : o ? ht(e, i) : e, a = t.length - 1, r; a >= 0; a--) (r = t[a]) && (s = r(s) || s); return s; }; let te = class extends O { render() { return W` <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> `; } }; te.styles = F` svg { display: block; fill: var(--color-icon-button); } `; te = pt([ C("maptiler-geocode-reverse-geocoding-icon") ], te); var dt = Object.getOwnPropertyDescriptor, ut = (t, e, i, o) => { for (var s = o > 1 ? void 0 : o ? dt(e, i) : e, a = t.length - 1, r; a >= 0; a--) (r = t[a]) && (s = r(s) || s); return s; }; let ie = class extends O { render() { return W` <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> `; } }; ie.styles = F` circle { stroke-width: 1.875; fill: none; } path { stroke-width: 1.875; stroke-linecap: round; } svg { display: block; stroke: var(--color-icon-button); } `; ie = ut([ C("maptiler-geocode-search-icon") ], ie); function ft(t, e, i) { const o = e[1], s = e[0], a = o - s; return t === o && i ? t : ((t - s) % a + a) % a + s; } function G(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; } function be(t, e) { const i = Ne(t); for (const o of i.features) if (o.geometry.type == "MultiPolygon") for (const s of o.geometry.coordinates) we(s, e); else we(o.geometry.coordinates, e); return i; } function we(t, e) { for (const i of t) for (const o of i) o[0] += e; } let P; async function mt(t, e, i) { for (const o of e ?? []) if (!(t && (o.minZoom != null && o.minZoom > t[0] || o.maxZoom != null && o.maxZoom < t[0]))) { if (o.type === "fixed") return o.coordinates.join(","); if (o.type === "client-geolocation") if (P && o.cachedLocationExpiry && P.time + o.cachedLocationExpiry > Date.now()) { if (P.coords) return P.coords; } else { let s; try { return s = await new Promise((a, r) => { i.signal.addEventListener("abort", () => { r(Error("aborted")); }), navigator.geolocation.getCurrentPosition( (u) => { a([u.coords.longitude, u.coords.latitude].map((m) => m.toFixed(6)).join(",")); }, (u) => { r(u); }, o ); }), s; } catch { } finally { o.cachedLocationExpiry && (P = { time: Date.now(), coords: s }); } if (i.signal.aborted) return; } if (o.type === "server-geolocation") return "ip"; if (t && o.type === "map-center") return t[1].toFixed(6) + "," + t[2].toFixed(6); } } const gt = ".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 yt = Object.defineProperty, vt = Object.getOwnPropertyDescriptor, Le = (t) => { throw TypeError(t); }, $ = (t, e, i, o) => { for (var s = o > 1 ? void 0 : o ? vt(e, i) : e, a = t.length - 1, r; a >= 0; a--) (r = t[a]) && (s = (o ? r(e, i, s) : r(s)) || s); return o && s && yt(e, i, s), s; }, $e = (t, e, i) => e.has(t) || Le("Cannot " + i), f = (t, e, i) => ($e(t, e, "read from private field"), i ? i.call(t) : e.get(t)), xt = (t, e, i) => e.has(t) ? Le("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, i), S = (t, e, i) => ($e(t, e, "access private method"), i), d, V, U, y, Ie, Fe, ce, se; const Oe = typeof devicePixelRatio > "u" || devicePixelRatio > 1.25, Ce = Oe ? "@2x" : "", T = Oe ? 2 : 1; let M, Me, k = class extends O { constructor() { super(...arguments), xt(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, V) && (this.index = f(this, d, V).length, S(this, d, ce).call(this)); } render() { return g` <li tabindex="-1" role="option" aria-selected=${this.itemStyle === "selected"} aria-checked=${this.itemStyle === "picked"} class=${this.itemStyle} @click=${() => this.dispatchEvent(new CustomEvent("select"))} > ${M && this.spriteIcon ? g` <div class="sprite-icon" style=${Ze({ width: `${this.spriteIcon.width / T}px`, height: `${this.spriteIcon.height / T}px`, backgroundImage: `url(${this.iconsBaseUrl}sprite${Ce}.png)`, backgroundPosition: `-${this.spriteIcon.x / T}px -${this.spriteIcon.y / T}px`, backgroundSize: `${M.width / T}px ${M.height / T}px` })} title=${f(this, d, y)} /> ` : this.imageUrl ? g` <img src=${this.imageUrl} alt=${this.category} title=${f(this, d, y)} @error=${S(this, d, Fe)} />` : this.feature?.address ? g` <img src=${this.iconsBaseUrl + "housenumber.svg"} alt=${f(this, d, y)} title=${f(this, d, y)} /> ` : this.feature?.id.startsWith("road.") ? g` <img src=${this.iconsBaseUrl + "road.svg"} alt=${f(this, d, y)} title=${f(this, d, y)} /> ` : this.feature?.id.startsWith("address.") ? g` <img src=${this.iconsBaseUrl + "street.svg"} alt=${f(this, d, y)} title=${f(this, d, y)} /> ` : this.feature?.id.startsWith("postal_code.") ? g` <img src=${this.iconsBaseUrl + "postal_code.svg"} alt=${f(this, d, y)} title=${f(this, d, y)} /> ` : this.feature?.id.startsWith("poi.") ? g` <img src=${this.iconsBaseUrl + "poi.svg"} alt=${f(this, d, y)} title=${f(this, d, y)} /> ` : f(this, d, U) ? g` <img src=${this.iconsBaseUrl + "reverse.svg"} alt=${f(this, d, y)} title=${f(this, d, y)} /> ` : g` <img src=${this.iconsBaseUrl + "area.svg"} alt=${f(this, d, y)} title=${f(this, d, y)} /> `} <span class="texts"> <span> <span class="primary"> ${f(this, d, U) ? 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, U) ? g` <span class="secondary"> ${f(this, d, y)} </span> ` : H} </span> <span class="line2"> ${f(this, d, U) ? this.feature?.text : this.feature?.place_name.replace(/[^,]*,?s*/, "")} </span> </span> </li> `; } }; d = /* @__PURE__ */ new WeakSet(); V = function() { return this.feature?.properties?.categories; }; U = function() { return this.feature?.place_type[0] === "reverse"; }; y = function() { return this.feature?.properties?.categories?.join(", ") ?? this.feature?.place_type_name?.[0] ?? this.feature?.place_type[0]; }; Ie = function() { Me ??= fetch(`${this.iconsBaseUrl}sprite${Ce}.json`).then((t) => t.json()).then((t) => { M = t; }).catch(() => { M = null; }); }; Fe = function() { this.imageUrl && this.missingIconsCache.add(this.imageUrl), S(this, d, ce).call(this); }; ce = function() { M !== void 0 ? S(this, d, se).call(this) : (S(this, d, Ie).call(this), Me?.then(() => { S(this, d, se).call(this); })); }; se = function() { do { if (this.index--, this.category = f(this, d, V)?.[this.index], this.spriteIcon = this.category ? M?.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 = F` ${le(gt)} `; $([ p({ type: Object }) ], k.prototype, "feature", 2); $([ p({ type: String }) ], k.prototype, "itemStyle", 2); $([ p({ type: String }) ], k.prototype, "showPlaceType", 2); $([ p({ attribute: !1 }) ], k.prototype, "missingIconsCache", 2); $([ p({ type: String }) ], k.prototype, "iconsBaseUrl", 2); $([ b() ], k.prototype, "category", 2); $([ b() ], k.prototype, "imageUrl", 2); $([ b() ], k.prototype, "spriteIcon", 2); $([ b() ], k.prototype, "index", 2); k = $([ C("maptiler-geocoder-feature-item") ], k); const bt = "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 wt = Object.defineProperty, kt = Object.getOwnPropertyDescriptor, Te = (t) => { throw TypeError(t); }, c = (t, e, i, o) => { for (var s = o > 1 ? void 0 : o ? kt(e, i) : e, a = t.length - 1, r; a >= 0; a--) (r = t[a]) && (s = (o ? r(e, i, s) : r(s)) || s); return o && s && wt(e, i, s), s; }, he = (t, e, i) => e.has(t) || Te("Cannot " + i), w = (t, e, i) => (he(t, e, "read from private field"), i ? i.call(t) : e.get(t)), B = (t, e, i) => e.has(t) ? Te("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, i), re = (t, e, i, o) => (he(t, e, "write to private field"), e.set(t, i), i), h = (t, e, i) => (he(t, e, "access private method"), i), q, z, oe, R, n, N, Se, pe, x, de, Z, ue, fe, I, me, Q, Ee, ae, Pe, Be, Ue, Ge, ze, Re, We; let l = class extends O { constructor() { super(...arguments), B(this, n), 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, B(this, q, !1), B(this, z), B(this, oe, /* @__PURE__ */ new Set()), B(this, R); } firstUpdated() { re(this, q, !0); } /** * Set the options of this instance. * * @param options options to set */ setOptions(t) { const e = { ...t }; for (const i of Object.keys(e)) _t.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, n, fe).call(this, t, { external: !0 }), h(this, n, ue).call(this); } /** * Set the content of search input box and immediately submit it. * * @param value text to set and submit */ submitQuery(t) { h(this, n, me).call(this, t, { external: !0 }); } /** * Clear search result list. */ clearList() { h(this, n, I).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) { re(this, R, t); } /** @internal */ handleMapClick(t) { this.reverseActive && h(this, n, Ee).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, n, I).call(this), this.selectedItemIndex = -1), ["searchValue", "minLength"].some((e) => t.has(e)) && w(this, n, pe) && (h(this, n, I).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, n, x).call(this, "select", { feature: w(this, n, N) }), ["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, n, Q).call(this, this.picked.id, { byId: !0 }) : Promise.resolve()).then( () => { h(this, n, x).call(this, "pick", { feature: this.picked }); }, (e) => { e && typeof e == "object" && "name" in e && e.name === "AbortError" || (this.error = e, h(this, n, 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, n, x).call(this, "featuresshow") : h(this, n, x).call(this, "featureshide")), ["reverseActive"].some((e) => t.has(e)) && h(this, n, x).call(this, "reversetoggle", { reverse: this.reverseActive }); } render() { return g` <form @submit=${h(this, n, de)} class=${D({ "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, n, ae)} @input=${h(this, n, Pe)} @change=${() => this.picked = void 0} placeholder=${this.placeholder ?? "Search"} aria-label=${this.placeholder ?? "Search"} /> <div class="clear-button-container ${D({ displayable: this.searchValue !== "" })}"> ${w(this, n, Se) ? g`<maptiler-geocode-loading-icon></maptiler-geocode-loading-icon>` : g` <button type="button" @click=${h(this, n, We)} title=${this.clearButtonTitle ?? "clear"}> <maptiler-geocode-clear-icon></maptiler-geocode-clear-icon> </button> `} </div> ${this.enableReverse === "button" ? g` <button type="button" class=${D({ 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> ` : H} <!-- <slot /> --> </div> ${this.error ? g` <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 ? H : this.listFeatures.length === 0 ? g` <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> ` : g` <ul class="options ${D({ "open-on-top": this.openListOnTop })}" @pointerleave=${h(this, n, Ge)} @pointerdown=${h(this, n, ze)} @pointerup=${h(this, n, Re)} @keydown=${h(this, n, ae)} role="listbox" > ${qe( this.listFeatures, (t) => t.id + (t.address ? "," + t.address : ""), (t, e) => g` <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, n, Ue).call(this, e); }} @select=${() => { h(this, n, Be).call(this, t); }} .missingIconsCache=${w(this, oe)} .iconsBaseUrl=${this.iconsBaseUrl ?? "https://cdn.maptiler.com/maptiler-geocoding-control/v3.0.0/icons/"} /> ` )} </ul> `} </form> `; } }; q = /* @__PURE__ */ new WeakMap(); z = /* @__PURE__ */ new WeakMap(); oe = /* @__PURE__ */ new WeakMap(); R = /* @__PURE__ */ new WeakMap(); n = /* @__PURE__ */ new WeakSet(); N = function() { return this.listFeatures?.[this.selectedItemIndex]; }; Se = function() { return this.abortController !== void 0; }; pe = function() { return this.searchValue.length < (this.minLength ?? 2); }; x = function(t, ...[e]) { w(this, q) && this.dispatchEvent( new CustomEvent(t, { bubbles: !0, composed: !0, detail: e }) ); }; de = function(t, { external: e = !1 } = {}) { t?.preventDefault(), this.focused = !1, clearTimeout(w(this, z)), 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, n, Q).call(this, this.searchValue, { exact: !0, external: e }).then(() => { this.picked = void 0; }).catch((i) => this.error = i); }; Z = function(t) { try { return Ve(t, 6); } catch { return !1; } }; ue = function() { setTimeout(() => { this.input.focus(), this.focused = !0, this.input.select(); }); }; fe = function(t, { external: e = !1 } = {}) { if (this.searchValue = t, h(this, n, x).call(this, "querychange", { query: this.searchValue, reverseCoords: h(this, n, Z).call(this, t) }), this.error = void 0, this.picked = void 0, this.showResultsWhileTyping !== !1) { if (clearTimeout(w(this, z)), w(this, n, pe)) return; const i = this.searchValue; re(this, z, window.setTimeout(() => { h(this, n, Q).call(this, i, { external: e }).catch((o) => this.error = o); }, this.debounceSearch ?? 200)); } else h(this, n, I).call(this); }; I = function() { this.listFeatures !== void 0 && (this.listFeatures = void 0, h(this, n, x).call(this, "featuresclear")); }; me = function(t, { external: e = !1 } = {}) { this.searchValue = t, h(this, n, x).call(this, "querychange", { query: this.searchValue, reverseCoords: h(this, n, Z).call(this, t) }), this.selectedItemIndex = -1, h(this, n, de).call(this, void 0, { external: e }); }; Q = async function(t, { byId: e = !1, exact: i = !1, external: o = !1 } = {}) { this.error = void 0, this.abortController?.abort(); const s = new AbortController(); this.abortController = s; try { const a = this.apiUrl ?? "https://api.maptiler.com/geocoding", r = h(this, n, Z).call(this, t), u = new URL(a + "/" + encodeURIComponent(r ? `${r.decimalLongitude},${r.decimalLatitude}` : t) + ".json"), m = u.searchParams; this.language !== void 0 && m.set("language", Array.isArray(this.language) ? this.language.join(",") : this.language ?? ""); const [_] = w(this, R) ?? [void 0]; let L = (!r || this.reverseGeocodingTypes === void 0 ? this.types : this.reverseGeocodingTypes)?.map( (v) => typeof v == "string" ? v : _ === void 0 || (v[0] ?? 0) <= _ && _ < (v[1] ?? 1 / 0) ? v[2] : void 0 ).filter((v) => v !== void 0); L && (L = [...new Set(L)], m.set("types", L.join(","))); const ge = !r || this.reverseGeocodingExcludeTypes === void 0 ? this.excludeTypes : this.reverseGeocodingExcludeTypes; if (ge && m.set("excludeTypes", String(ge)), this.bbox && m.set("bbox", this.bbox.map((v) => v.toFixed(6)).join(",")), this.country && m.set("country", Array.isArray(this.country) ? this.country.join(",") : this.country), this.worldview && m.set("worldview", this.worldview), !e && !r) { const v = this.proximity ?? [{ type: "server-geolocation" }], ve = await mt(w(this, R), v, s); ve && m.set("proximity", ve), (i || this.showResultsWhileTyping === !1) && m.set("autocomplete", "false"), m.set("fuzzyMatch", String(this.fuzzyMatch !== !1)); } const ye = this.limit ?? 5, K = this.reverseGeocodingLimit ?? ye; K > 1 && L?.length !== 1 && console.warn("[MapTilerGeocodingControl] Warning: For reverse geocoding when limit > 1 then types must contain single value."), r ? (K === 1 || this.exhaustiveReverseGeocoding || L?.length === 1) && m.set("limit", String(K)) : m.set("limit", String(ye)), this.apiKey && m.set("key", this.apiKey), this.adjustUrl?.(u); const De = u.searchParams.get("types") === "" && u.searchParams.get("excludeTypes") !== "true", j = u.toString(); if (j === this.lastSearchUrl) { e ? (this.clearListOnPick && h(this, n, I).call(this), this.picked = this.cachedFeatures[0]) : (this.listFeatures = this.cachedFeatures, h(this, n, x).call(this, "featureslisted", { features: this.listFeatures, external: o }), this.listFeatures[this.selectedItemIndex]?.id !== w(this, n, N)?.id && (this.selectedItemIndex = -1)); return; } h(this, n, x).call(this, "request", { urlObj: u }), this.lastSearchUrl = j; let E; if (De) 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, n, x).call(this, "response", { url: j, featureCollection: E }), e ? (this.clearListOnPick && h(this, n, I).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, n, x).call(this, "featureslisted", { features: this.listFeatures, external: o }), this.cachedFeatures = this.listFeatures, this.listFeatures[this.selectedItemIndex]?.id !== w(this, n, N)?.id && (this.selectedItemIndex = -1), r && this.input.focus()); } catch (a) { if (a && typeof a == "object" && "name" in a && a.name === "AbortError") return; throw a; } finally { s === this.abortController && (this.abortController = void 0); } }; Ee = function(t) { this.reverseActive = this.enableReverse === "always", h(this, n, I).call(this), this.picked = void 0, h(this, n, me).call(this, `${t[1].toFixed(6)}, ${ft(t[0], [-180, 180], !0).toFixed(6)}`), h(this, n, ue).call(this); }; ae = 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)); }; Pe = function(t) { h(this, n, fe).call(this, t.target.value); }; Be = function(t) { (!this.picked || this.picked.id !== t.id) && (this.picked = t, this.searchValue = t.place_name); }; Ue = function(t) { this.selectedItemIndex = t; }; Ge = function() { (!this.selectFirst || this.picked) && (this.selectedItemIndex = -1), this.isFeatureListInteractedWith && (this.isFeatureListInteractedWith = !1); }; ze = function() { this.isFeatureListInteractedWith = !0; }; Re = function() { setTimeout(() => { this.isFeatureListInteractedWith = !1; }); }; We = function() { this.searchValue = "", h(this, n, x).call(this, "queryclear"), this.picked = void 0, this.input.focus(); }; l.styles = F` ${le(bt)} `; c([ p({ attribute: !1 }) ], l.prototype, "adjustUrl", 2); c([ p({ type: String }) ], l.prototype, "apiKey", 2); c([ p({ type: String }) ], l.prototype, "apiUrl", 2); c([ p({ type: Array }) ], l.prototype, "bbox", 2); c([ p({ type: String }) ], l.prototype, "clearButtonTitle", 2); c([ p({ type: Boolean }) ], l.prototype, "clearListOnPick", 2); c([ p({ type: Boolean }) ], l.prototype, "clearOnBlur", 2); c([ p({ type: Boolean }) ], l.prototype, "collapsed", 2); c([ p({ attribute: !1 }) ], l.prototype, "country", 2); c([ p({ type: Number }) ], l.prototype, "debounceSearch", 2); c([ p({ type: String }) ], l.prototype, "enableReverse", 2); c([ p({ type: String }) ], l.prototype, "errorMessage", 2); c([ p({ type: Boolean }) ], l.prototype, "excludeTypes", 2); c([ p({ type: Boolean }) ], l.prototype, "exhaustiveReverseGeocoding", 2); c([ p({ type: Boolean }) ], l.prototype, "fetchFullGeometryOnPick", 2); c([ p({ type: Object }) ], l.prototype, "fetchParameters", 2); c([ p({ attribute: !1 }) ], l.prototype, "filter", 2); c([ p({ type: Object }) ], l.prototype, "fuzzyMatch", 2); c([ p({ type: String }) ], l.prototype, "iconsBaseUrl", 2); c([ p({ type: Boolean }) ], l.prototype, "keepListOpen", 2); c([ p({ attribute: !1 }) ], l.prototype, "language", 2); c([ p({ type: Number }) ], l.prototype, "limit", 2); c([ p({ type: Number }) ], l.prototype, "minLength", 2); c([ p({ type: String }) ], l.prototype, "noResultsMessage", 2); c([ p({ type: Boolean }) ], l.prototype, "openListOnTop", 2); c([ p({ type: String }) ], l.prototype, "placeholder", 2); c([ p({ type: Array }) ], l.prototype, "proximity", 2); c([ p({ type: Boolean }) ], l.prototype, "reverseActive", 2); c([ p({ type: String }) ], l.prototype, "reverseButtonTitle", 2); c([ p({ type: Object }) ], l.prototype, "reverseGeocodingExcludeTypes", 2); c([ p({ type: Number }) ], l.prototype, "reverseGeocodingLimit", 2); c([ p({ type: Array }) ], l.prototype, "reverseGeocodingTypes", 2); c([ p({ type: Object }) ], l.prototype, "selectFirst", 2); c([ p({ type: String }) ], l.prototype, "showPlaceType", 2); c([ p({ type: Object }) ], l.prototype, "showResultsWhileTyping", 2); c([ p({ type: Array }) ], l.prototype, "types", 2); c([ p({ type: String }) ], l.prototype, "worldview", 2); c([ Ae("input") ], l.prototype, "input", 2); c([ b() ], l.prototype, "searchValue", 2); c([ b() ], l.prototype, "listFeatures", 2); c([ b() ], l.prototype, "selectedItemIndex", 2); c([ b() ], l.prototype, "picked", 2); c([ b() ], l.prototype, "cachedFeatures", 2); c([ b() ], l.prototype, "lastSearchUrl", 2); c([ b() ], l.prototype, "error", 2); c([ b() ], l.prototype, "abortController", 2); c([ b() ], l.prototype, "focused", 2); c([ b() ], l.prototype, "isFeatureListVisible", 2); c([ b() ], l.prototype, "isFeatureListInteractedWith", 2); l = c([ C("maptiler-geocoder") ], l); const _t = [ "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" ], Lt = "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 $t = Object.getOwnPropertyDescriptor, It = (t, e, i, o) => { for (var s = o > 1 ? void 0 : o ? $t(e, i) : e, a = t.length - 1, r; a >= 0; a--) (r = t[a]) && (s = r(s) || s); return s; }; let ne = class extends O { render() { return W` <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 = F` ${le(Lt)} `; ne = It([ C("maptiler-geocode-marker") ], ne); function ke(t) { const e = it( A([ Qe([ [ [180, 90], [-180, 90], [-180, -90], [180, -90], [180, 90] ] ]), t ]) ); if (!e) return; e.properties = { isMask: !0 }; const i = G(Y(t)), o = (i[2] - i[0]) / 360 / 1e3, s = i[0] < -180, a = i[2] > 180, r = st(t); if (r.features.length > 1 && (s || a)) for (const u of r.features) { const m = G(Y(u)); if (a && m[0] < -180 + o) for (const _ of u.geometry.coordinates) for (const L of _) L[0] += 360 - o; if (s && m[2] > 180 - o) for (const _ of u.geometry.coordinates) for (const L of _) L[0] -= 360 - o; } return A([r.features.length < 2 ? t : _e(r) ?? t, e]); } const Ft = { 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 }, Ot = (t) => { const e = t?.geometry.type, i = t?.properties?.isMask, o = i ? 0 : e === "LineString" || e === "MultiLineString" ? 3 : 2; return { color: "#3170fe", fillColor: "#000", fillOpacity: i ? 0.1 : 0, weight: o, dashArray: [o, o], lineCap: "butt" }; }; class je extends Ye { } Object.assign(je.prototype, He.prototype); class Dt extends je { #e; #t; constructor(e = {}) { super(e); } /** @internal Not to be called directly */ onAdd(e) { this.#e = e, this.#t = e.getContainer().ownerDocument.createElement("maptiler-geocoder"), this.#t.classList.add("leaflet-geocoder"), this.#m(), this.#x(), this.#I(); const i = e.getContainer().ownerDocument.createElement("div"); return i.classList.add("leaflet-ctrl-geocoder", "leaflet-bar"), i.style.zIndex = "850", i.appendChild(this.#t), xe.disableClickPropagation(i), xe.disableScrollPropagation(i), i; } /** @internal Not to be called directly */ onRemove() { this.#b(), this.#F(), this.#e = void 0, this.#t = void 0; } getOptions() { return { ...this.options }; } setOptions(e) { Object.assign(this.options, e), this.#m(); } setQuery(e) { this.#t?.setQuery(e); } submitQuery(e) { this.#t?.submitQuery(e); } clearMap() { this.#o = [], this.#c(void 0, void 0); } clearList() { this.#t?.clearList(); } setReverseMode(e) { this.setOptions({ reverseActive: e }); } focus(e) { this.#t?.focus(e); } blur() { this.#t?.blur(); } /** Markers currently displayed on the map */ #a = /* @__PURE__ */ new Map(); /** Marker representing the selected feature */ #n; /** Marker representing the picked feature */ #r; /** Features currently marked on the map */ #o; /** Remember last feature that the map flew to as to not do it again */ #d; /** Layer used for showing geometry results */ #s; #u = { reversetoggle: (e) => { const i = this.#e?.getContainer(); i && (i.style.cursor = e.detail.reverse ? "crosshair" : ""), this.#i("reversetoggle", e.detail); }, querychange: (e) => { const i = e.detail.reverseCoords; this.#v(i ? { lng: i.decimalLongitude, lat: i.decimalLatitude } : void 0), this.#i("querychange", e.detail); }, queryclear: () => { this.#v(void 0), this.#i("queryclear"); }, request: (e) => { this.#i("request", e.detail); }, response: (e) => { this.#i("response", e.detail); }, select: (e) => { const i = e.detail.feature; i && this.#h && this.options.flyToSelected && this.#g({ lng: i.center[0], lat: i.center[1] }, this.#l(i)), this.#o && i && this.#$(i), this.#i("select", e.detail); }, pick: (e) => { const i = e.detail.feature; i && i.id !== this.#d && this.#h && (this.#w(i), this.#c(this.#o, i)), this.#d = i?.id, this.#i("pick", e.detail); }, featuresshow: () => { this.#i("featuresshow"); }, featureshide: () => { this.#i("featureshide"); }, featureslisted: (e) => { const i = e.detail.features; this.#o = i, this.#c(this.#o, void 0), this.#k(e), this.#i("featureslisted", e.detail); }, featuresclear: () => { this.#o = void 0, this.#c(void 0, void 0), this.#i("featuresclear"); }, focusin: () => { this.#i("focusin"); }, focusout: () => { this.#i("focusout"); } }; #f = { render: () => { const e = this.#e?.getZoom(), i = this.#e?.getCenter(); this.#t?.handleMapChange(e && i ? [e, i.lng, i.lat] : void 0); }, click: (e) => { this.#t?.handleMapClick([e.latlng.lng, e.latlng.lat]); } }; #m() { this.#t && (this.#t.setOptions(this.options), this.#t.fetchFullGeometryOnPick = this.options.pickedResultStyle !== "marker-only", this.#t.openListOnTop = this.options.position === "bottomleft" || this.options.position === "bottomright"); } #x() { if (!(!this.#t || !this.#e)) { for (const [e, i] of Object.entries(this.#u)) this.#t.addEventListener(e, i); this.#e.on(this.#f); } } #b() { if (!(!this.#t || !this.#e)) { for (const [e, i] of Object.entries(this.#u)) this.#t.removeEventListener(e, i); this.#e.off(this.#f); } } #i(e, i) { return super.fire(e, i); } #w(e) { e.bbox[0] === e.bbox[2] && e.bbox[1] === e.bbox[3] ? this.#g({ lng: e.center[0], lat: e.center[1] }, this.#l(e)) : this.#y(G(e.bbox), 50, this.#l(e)); } #k({ detail: { features: e, external: i } }) { if (!e || e.length === 0 || !this.#h || this.options.flyToFeatures === !1 || this.options.flyToFeatures === "never" || !i && (this.options.flyToFeatures === void 0 || this.options.flyToFeatures === "external")) return; const o = e.every((r) => r.matching_text), s = e.reduce( (r, u) => o || !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] ), a = e.map((r) => this.#l(r)).filter((r) => r !== void 0).reduce((r, u) => r === void 0 ? u : Math.max(r, u), void 0); this.#y(G(s), 50, a); } #l(e) { if (e.bbox[0] !== e.bbox[2] || e.bbox[1] !== e.bbox[3]) return; const i = e.id.replace(/\..*/, ""), o = this.options.zoom ?? Ft; return (Array.isArray(e.properties?.categories) ? e.properties.categories.reduce((s, a) => { const r = o[i + "." + a]; return s === void 0 ? r : r === void 0 ? s : Math.max(s, r); }, void 0) : void 0) ?? o[i]; } get #h() { return !!this.options.flyTo || this.options.flyTo === void 0; } get #_() { return typeof this.options.flyTo == "boolean" ? {} : this.options.flyTo; } get #L() { return typeof this.options.flyTo == "boolean" ? {} : this.options.flyTo; } #g(e, i) { this.#e?.flyTo(e, i, this.#_ ?? void 0); } #y(e, i, o) { this.#e?.fitBounds( [ [e[1], e[0]], [e[3], e[2]] ], { padding: [i, i], ...o ? { maxZoom: o } : {}, ...this.#L } ); } #v(e) { if (!(this.options.marker === !1 || this.options.marker === null || !this.#e)) { if (!e) { this.#r?.remove(), this.#r = void 0; return; } this.#r || (this.options.marker instanceof Function ? this.#r = this.options.marker(this.#e) ?? void 0 : (this.#r = this.#p(e, this.options.marker).addTo(this.#e), this.#r.getElement()?.classList.add("marker-reverse"))), this.#r?.setLatLng(e); } } #c(e, i) { if (!this.#e) return; for (const s of this.#a.values()) s.remove(); this.#a = /* @__PURE__ */ new Map(), this.#s?.clearLayers(); const o = () => { if (!i || !this.#e || this.options.marker === !1 || this.options.marker === null) return; const s = this.options.marker instanceof Function ? this.options.marker(this.#e, i) : this.#p({ lng: i.center[0], lat: i.center[1] }, this.options.marker).addTo(this.#e); s && this.#a.set(i, s); }; if (i?.geometry.type === "GeometryCollection") { const s = i.geometry.geometries.filter( (a) => a.type === "Polygon" || a.type === "MultiPolygon" ); if (s.length > 0) { const a = _e(A(s.map((r) => Ke(r)))); if (a) { const r = ke({ ...i, geometry: a.geometry }); if (r) { const u = [...r.features], m = G(Y(i)), _ = m[2] - m[0]; m[0] - _ / 4 < -180 && u.push(...be(r, -360).features), m[2] + _ / 4 > 180 && u.push(...be(r, 360).features), this.#s?.addData(A(u)); } } } else { const a = i.geometry.geometries.filter( (r) => r.type === "LineString" || r.type === "MultiLineString" ); a.length > 0 && this.#s?.addData({ ...i, geometry: { type: "GeometryCollection", geometries: a } }); } } else if (i?.geometry.type.endsWith("Polygon")) { const s = ke(i); s && this.#s?.addData(s), this.options.pickedResultStyle === "full-geometry-including-polygon-center-marker" && o(); } else i?.geometry.type.endsWith("LineString") ? this.#s?.addData(i) : i?.geometry.type.endsWith("Point") && o(); if (this.options.showResultMarkers !== !1 && this.options.showResultMarkers !== null) for (const s of e ?? []) { if