@maptiler/geocoding-control
Version:
The Javascript & TypeScript Map Control component for MapTiler Geocoding service. Easy to be integrated into any JavaScript mapping application.
1,218 lines (1,202 loc) • 53.4 kB
JavaScript
import { css as F, LitElement as O, svg as W, html as m, unsafeCSS as ce, nothing as J } from "lit";
import { customElement as S, property as d, state as b, query as Ze } from "lit/decorators.js";
import { convert as Ne } from "geo-coordinates-parser";
import { classMap as V } from "lit/directives/class-map.js";
import { repeat as Qe } from "lit/directives/repeat.js";
import "@turf/clone";
import { styleMap as Ke } from "lit/directives/style-map.js";
import { Feature as $ } from "ol";
import { Control as Ye } from "ol/control";
import He from "ol/events/Event";
import { Point as H, Polygon as be, MultiPolygon as we, GeometryCollection as Je, LineString as ke, MultiLineString as _e } from "ol/geom";
import Xe from "ol/layer/Vector";
import { transformExtent as et, getUserProjection as tt, fromLonLat as it, toLonLat as st } from "ol/proj";
import rt from "ol/source/Vector";
import Le from "@turf/bbox";
import ot from "@turf/difference";
import at from "@turf/flatten";
import { featureCollection as $e, polygon as nt } from "@turf/helpers";
import lt from "@turf/union";
import Ie from "ol/style/Fill";
import ct from "ol/style/Icon";
import Fe from "ol/style/Stroke";
import ht from "ol/style/Style";
import dt from "ol/style/Text";
var pt = Object.getOwnPropertyDescriptor, ut = (t, e, i, o) => {
for (var s = o > 1 ? void 0 : o ? pt(e, i) : e, r = t.length - 1, a; r >= 0; r--)
(a = t[r]) && (s = a(s) || s);
return s;
};
let X = 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>
`;
}
};
X.styles = F`
svg {
display: block;
fill: var(--color-icon-button);
}
`;
X = ut([
S("maptiler-geocode-clear-icon")
], X);
var ft = Object.getOwnPropertyDescriptor, mt = (t, e, i, o) => {
for (var s = o > 1 ? void 0 : o ? ft(e, i) : e, r = t.length - 1, a; r >= 0; r--)
(a = t[r]) && (s = a(s) || s);
return s;
};
let ee = 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>
`;
}
};
ee.styles = F`
svg {
display: block;
fill: #e15042;
}
`;
ee = mt([
S("maptiler-geocode-fail-icon")
], ee);
var gt = Object.getOwnPropertyDescriptor, yt = (t, e, i, o) => {
for (var s = o > 1 ? void 0 : o ? gt(e, i) : e, r = t.length - 1, a; r >= 0; r--)
(a = t[r]) && (s = a(s) || s);
return s;
};
let te = class extends O {
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 = 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);
}
}
`;
te = yt([
S("maptiler-geocode-loading-icon")
], te);
var vt = Object.getOwnPropertyDescriptor, xt = (t, e, i, o) => {
for (var s = o > 1 ? void 0 : o ? vt(e, i) : e, r = t.length - 1, a; r >= 0; r--)
(a = t[r]) && (s = a(s) || s);
return s;
};
let ie = 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>
`;
}
};
ie.styles = F`
svg {
display: block;
fill: var(--color-icon-button);
}
`;
ie = xt([
S("maptiler-geocode-reverse-geocoding-icon")
], ie);
var bt = Object.getOwnPropertyDescriptor, wt = (t, e, i, o) => {
for (var s = o > 1 ? void 0 : o ? bt(e, i) : e, r = t.length - 1, a; r >= 0; r--)
(a = t[r]) && (s = a(s) || s);
return s;
};
let se = 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>
`;
}
};
se.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);
}
`;
se = wt([
S("maptiler-geocode-search-icon")
], se);
function kt(t, e, i) {
const o = e[1], s = e[0], r = o - s;
return t === o && i ? t : ((t - s) % r + r) % r + s;
}
function D(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 B;
async function _t(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 (B && o.cachedLocationExpiry && B.time + o.cachedLocationExpiry > Date.now()) {
if (B.coords)
return B.coords;
} else {
let s;
try {
return s = await new Promise((r, a) => {
i.signal.addEventListener("abort", () => {
a(Error("aborted"));
}), navigator.geolocation.getCurrentPosition(
(u) => {
r([u.coords.longitude, u.coords.latitude].map((y) => y.toFixed(6)).join(","));
},
(u) => {
a(u);
},
o
);
}), s;
} catch {
} finally {
o.cachedLocationExpiry && (B = {
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 Lt = ".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 $t = Object.defineProperty, It = Object.getOwnPropertyDescriptor, Oe = (t) => {
throw TypeError(t);
}, L = (t, e, i, o) => {
for (var s = o > 1 ? void 0 : o ? It(e, i) : e, r = t.length - 1, a; r >= 0; r--)
(a = t[r]) && (s = (o ? a(e, i, s) : a(s)) || s);
return o && s && $t(e, i, s), s;
}, Se = (t, e, i) => e.has(t) || Oe("Cannot " + i), f = (t, e, i) => (Se(t, e, "read from private field"), i ? i.call(t) : e.get(t)), Ft = (t, e, i) => e.has(t) ? Oe("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, i), E = (t, e, i) => (Se(t, e, "access private method"), i), p, q, z, g, Me, Te, he, re;
const Ce = typeof devicePixelRatio > "u" || devicePixelRatio > 1.25, Pe = Ce ? "@2x" : "", P = Ce ? 2 : 1;
let C, Ee, k = class extends O {
constructor() {
super(...arguments), Ft(this, p), this.itemStyle = "default", this.showPlaceType = "if-needed", this.missingIconsCache = /* @__PURE__ */ new Set(), this.iconsBaseUrl = "", this.index = 0;
}
willUpdate(t) {
t.has("feature") && f(this, p, q) && (this.index = f(this, p, q).length, E(this, p, 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"))}
>
${C && this.spriteIcon ? m`
<div
class="sprite-icon"
style=${Ke({
width: `${this.spriteIcon.width / P}px`,
height: `${this.spriteIcon.height / P}px`,
backgroundImage: `url(${this.iconsBaseUrl}sprite${Pe}.png)`,
backgroundPosition: `-${this.spriteIcon.x / P}px -${this.spriteIcon.y / P}px`,
backgroundSize: `${C.width / P}px ${C.height / P}px`
})}
title=${f(this, p, g)}
/>
` : this.imageUrl ? m` <img src=${this.imageUrl} alt=${this.category} title=${f(this, p, g)} @error=${E(this, p, Te)} />` : this.feature?.address ? m` <img src=${this.iconsBaseUrl + "housenumber.svg"} alt=${f(this, p, g)} title=${f(this, p, g)} /> ` : this.feature?.id.startsWith("road.") ? m` <img src=${this.iconsBaseUrl + "road.svg"} alt=${f(this, p, g)} title=${f(this, p, g)} /> ` : this.feature?.id.startsWith("address.") ? m` <img src=${this.iconsBaseUrl + "street.svg"} alt=${f(this, p, g)} title=${f(this, p, g)} /> ` : this.feature?.id.startsWith("postal_code.") ? m` <img src=${this.iconsBaseUrl + "postal_code.svg"} alt=${f(this, p, g)} title=${f(this, p, g)} /> ` : this.feature?.id.startsWith("poi.") ? m` <img src=${this.iconsBaseUrl + "poi.svg"} alt=${f(this, p, g)} title=${f(this, p, g)} /> ` : f(this, p, z) ? m` <img src=${this.iconsBaseUrl + "reverse.svg"} alt=${f(this, p, g)} title=${f(this, p, g)} /> ` : m` <img src=${this.iconsBaseUrl + "area.svg"} alt=${f(this, p, g)} title=${f(this, p, g)} /> `}
<span class="texts">
<span>
<span class="primary"> ${f(this, p, z) ? 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, p, z) ? m` <span class="secondary"> ${f(this, p, g)} </span> ` : J}
</span>
<span class="line2"> ${f(this, p, z) ? this.feature?.text : this.feature?.place_name.replace(/[^,]*,?s*/, "")} </span>
</span>
</li>
`;
}
};
p = /* @__PURE__ */ new WeakSet();
q = function() {
return this.feature?.properties?.categories;
};
z = 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];
};
Me = function() {
Ee ??= fetch(`${this.iconsBaseUrl}sprite${Pe}.json`).then((t) => t.json()).then((t) => {
C = t;
}).catch(() => {
C = null;
});
};
Te = function() {
this.imageUrl && this.missingIconsCache.add(this.imageUrl), E(this, p, he).call(this);
};
he = function() {
C !== void 0 ? E(this, p, re).call(this) : (E(this, p, Me).call(this), Ee?.then(() => {
E(this, p, re).call(this);
}));
};
re = function() {
do {
if (this.index--, this.category = f(this, p, q)?.[this.index], this.spriteIcon = this.category ? C?.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`
${ce(Lt)}
`;
L([
d({ type: Object })
], k.prototype, "feature", 2);
L([
d({ type: String })
], k.prototype, "itemStyle", 2);
L([
d({ type: String })
], k.prototype, "showPlaceType", 2);
L([
d({ attribute: !1 })
], k.prototype, "missingIconsCache", 2);
L([
d({ 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([
S("maptiler-geocoder-feature-item")
], k);
const Ot = "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 St = Object.defineProperty, Mt = Object.getOwnPropertyDescriptor, Ue = (t) => {
throw TypeError(t);
}, c = (t, e, i, o) => {
for (var s = o > 1 ? void 0 : o ? Mt(e, i) : e, r = t.length - 1, a; r >= 0; r--)
(a = t[r]) && (s = (o ? a(e, i, s) : a(s)) || s);
return o && s && St(e, i, s), s;
}, de = (t, e, i) => e.has(t) || Ue("Cannot " + i), w = (t, e, i) => (de(t, e, "read from private field"), i ? i.call(t) : e.get(t)), G = (t, e, i) => e.has(t) ? Ue("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, i), oe = (t, e, i, o) => (de(t, e, "write to private field"), e.set(t, i), i), h = (t, e, i) => (de(t, e, "access private method"), i), Z, j, ae, R, n, N, Be, pe, x, ue, Q, fe, me, I, ge, K, Ge, ne, ze, je, Re, We, Ae, Ve, De;
let l = class extends O {
constructor() {
super(...arguments), G(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, G(this, Z, !1), G(this, j), G(this, ae, /* @__PURE__ */ new Set()), G(this, R);
}
firstUpdated() {
oe(this, Z, !0);
}
/**
* Set the options of this instance.
*
* @param options options to set
*/
setOptions(t) {
const e = { ...t };
for (const i of Object.keys(e))
Tt.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, me).call(this, t, { external: !0 }), h(this, n, 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, n, ge).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) {
oe(this, R, t);
}
/** @internal */
handleMapClick(t) {
this.reverseActive && h(this, n, Ge).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, K).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 m`
<form @submit=${h(this, n, ue)} class=${V({ "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, ne)}
@input=${h(this, n, ze)}
@change=${() => this.picked = void 0}
placeholder=${this.placeholder ?? "Search"}
aria-label=${this.placeholder ?? "Search"}
/>
<div class="clear-button-container ${V({ displayable: this.searchValue !== "" })}">
${w(this, n, Be) ? m`<maptiler-geocode-loading-icon></maptiler-geocode-loading-icon>` : m`
<button type="button" @click=${h(this, n, De)} title=${this.clearButtonTitle ?? "clear"}>
<maptiler-geocode-clear-icon></maptiler-geocode-clear-icon>
</button>
`}
</div>
${this.enableReverse === "button" ? m`
<button
type="button"
class=${V({ 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 ${V({ "open-on-top": this.openListOnTop })}"
@pointerleave=${h(this, n, We)}
@pointerdown=${h(this, n, Ae)}
@pointerup=${h(this, n, Ve)}
@keydown=${h(this, n, ne)}
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, n, Re).call(this, e);
}}
@select=${() => {
h(this, n, je).call(this, t);
}}
.missingIconsCache=${w(this, ae)}
.iconsBaseUrl=${this.iconsBaseUrl ?? "https://cdn.maptiler.com/maptiler-geocoding-control/v3.0.0/icons/"}
/>
`
)}
</ul>
`}
</form>
`;
}
};
Z = /* @__PURE__ */ new WeakMap();
j = /* @__PURE__ */ new WeakMap();
ae = /* @__PURE__ */ new WeakMap();
R = /* @__PURE__ */ new WeakMap();
n = /* @__PURE__ */ new WeakSet();
N = function() {
return this.listFeatures?.[this.selectedItemIndex];
};
Be = function() {
return this.abortController !== void 0;
};
pe = function() {
return this.searchValue.length < (this.minLength ?? 2);
};
x = function(t, ...[e]) {
w(this, Z) && 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, j)), 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, K).call(this, this.searchValue, { exact: !0, external: e }).then(() => {
this.picked = void 0;
}).catch((i) => this.error = i);
};
Q = function(t) {
try {
return Ne(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, n, x).call(this, "querychange", { query: this.searchValue, reverseCoords: h(this, n, Q).call(this, t) }), this.error = void 0, this.picked = void 0, this.showResultsWhileTyping !== !1) {
if (clearTimeout(w(this, j)), w(this, n, pe))
return;
const i = this.searchValue;
oe(this, j, window.setTimeout(() => {
h(this, n, K).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"));
};
ge = function(t, { external: e = !1 } = {}) {
this.searchValue = t, h(this, n, x).call(this, "querychange", { query: this.searchValue, reverseCoords: h(this, n, Q).call(this, t) }), this.selectedItemIndex = -1, h(this, n, ue).call(this, void 0, { external: e });
};
K = 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 r = this.apiUrl ?? "https://api.maptiler.com/geocoding", a = h(this, n, Q).call(this, t), u = new URL(r + "/" + encodeURIComponent(a ? `${a.decimalLongitude},${a.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 _ = (!a || 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 = !a || 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 && !a) {
const v = this.proximity ?? [{ type: "server-geolocation" }], xe = await _t(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."), a ? (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 qe = u.searchParams.get("types") === "" && u.searchParams.get("excludeTypes") !== "true", A = u.toString();
if (A === 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 = A;
let U;
if (qe)
U = { type: "FeatureCollection", features: [] };
else {
const v = await fetch(A, {
signal: s.signal,
...this.fetchParameters
});
if (!v.ok)
throw new Error(await v.text());
U = await v.json();
}
h(this, n, x).call(this, "response", { url: A, featureCollection: U }), e ? (this.clearListOnPick && h(this, n, I).call(this), this.picked = U.features[0], this.cachedFeatures = [this.picked]) : (this.listFeatures = U.features.filter(this.filter ?? (() => !0)), a && this.listFeatures.unshift({
type: "Feature",
properties: {},
/* eslint-disable @typescript-eslint/restrict-template-expressions */
id: `reverse_${a.decimalLongitude}_${a.decimalLatitude}`,
place_name: `${a.decimalLatitude}, ${a.decimalLongitude}`,
text: a.toCoordinateFormat("DMS"),
/* eslint-enable @typescript-eslint/restrict-template-expressions */
place_type: ["reverse"],
place_type_name: ["reverse"],
center: [a.decimalLongitude, a.decimalLatitude],
bbox: [a.decimalLongitude, a.decimalLatitude, a.decimalLongitude, a.decimalLatitude],
geometry: {
type: "Point",
coordinates: [a.decimalLongitude, a.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), a && this.input.focus());
} catch (r) {
if (r && typeof r == "object" && "name" in r && r.name === "AbortError")
return;
throw r;
} finally {
s === this.abortController && (this.abortController = void 0);
}
};
Ge = function(t) {
this.reverseActive = this.enableReverse === "always", h(this, n, I).call(this), this.picked = void 0, h(this, n, ge).call(this, `${t[1].toFixed(6)}, ${kt(t[0], [-180, 180], !0).toFixed(6)}`), h(this, n, fe).call(this);
};
ne = 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));
};
ze = function(t) {
h(this, n, me).call(this, t.target.value);
};
je = function(t) {
(!this.picked || this.picked.id !== t.id) && (this.picked = t, this.searchValue = t.place_name);
};
Re = function(t) {
this.selectedItemIndex = t;
};
We = function() {
(!this.selectFirst || this.picked) && (this.selectedItemIndex = -1), this.isFeatureListInteractedWith && (this.isFeatureListInteractedWith = !1);
};
Ae = function() {
this.isFeatureListInteractedWith = !0;
};
Ve = function() {
setTimeout(() => {
this.isFeatureListInteractedWith = !1;
});
};
De = function() {
this.searchValue = "", h(this, n, x).call(this, "queryclear"), this.picked = void 0, this.input.focus();
};
l.styles = F`
${ce(Ot)}
`;
c([
d({ attribute: !1 })
], l.prototype, "adjustUrl", 2);
c([
d({ type: String })
], l.prototype, "apiKey", 2);
c([
d({ type: String })
], l.prototype, "apiUrl", 2);
c([
d({ type: Array })
], l.prototype, "bbox", 2);
c([
d({ type: String })
], l.prototype, "clearButtonTitle", 2);
c([
d({ type: Boolean })
], l.prototype, "clearListOnPick", 2);
c([
d({ type: Boolean })
], l.prototype, "clearOnBlur", 2);
c([
d({ type: Boolean })
], l.prototype, "collapsed", 2);
c([
d({ attribute: !1 })
], l.prototype, "country", 2);
c([
d({ type: Number })
], l.prototype, "debounceSearch", 2);
c([
d({ type: String })
], l.prototype, "enableReverse", 2);
c([
d({ type: String })
], l.prototype, "errorMessage", 2);
c([
d({ type: Boolean })
], l.prototype, "excludeTypes", 2);
c([
d({ type: Boolean })
], l.prototype, "exhaustiveReverseGeocoding", 2);
c([
d({ type: Boolean })
], l.prototype, "fetchFullGeometryOnPick", 2);
c([
d({ type: Object })
], l.prototype, "fetchParameters", 2);
c([
d({ attribute: !1 })
], l.prototype, "filter", 2);
c([
d({ type: Object })
], l.prototype, "fuzzyMatch", 2);
c([
d({ type: String })
], l.prototype, "iconsBaseUrl", 2);
c([
d({ type: Boolean })
], l.prototype, "keepListOpen", 2);
c([
d({ attribute: !1 })
], l.prototype, "language", 2);
c([
d({ type: Number })
], l.prototype, "limit", 2);
c([
d({ type: Number })
], l.prototype, "minLength", 2);
c([
d({ type: String })
], l.prototype, "noResultsMessage", 2);
c([
d({ type: Boolean })
], l.prototype, "openListOnTop", 2);
c([
d({ type: String })
], l.prototype, "placeholder", 2);
c([
d({ type: Array })
], l.prototype, "proximity", 2);
c([
d({ type: Boolean })
], l.prototype, "reverseActive", 2);
c([
d({ type: String })
], l.prototype, "reverseButtonTitle", 2);
c([
d({ type: Object })
], l.prototype, "reverseGeocodingExcludeTypes", 2);
c([
d({ type: Number })
], l.prototype, "reverseGeocodingLimit", 2);
c([
d({ type: Array })
], l.prototype, "reverseGeocodingTypes", 2);
c([
d({ type: Object })
], l.prototype, "selectFirst", 2);
c([
d({ type: String })
], l.prototype, "showPlaceType", 2);
c([
d({ type: Object })
], l.prototype, "showResultsWhileTyping", 2);
c([
d({ type: Array })
], l.prototype, "types", 2);
c([
d({ type: String })
], l.prototype, "worldview", 2);
c([
Ze("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([
S("maptiler-geocoder")
], l);
const Tt = [
"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"
], Ct = "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 Pt = Object.getOwnPropertyDescriptor, Et = (t, e, i, o) => {
for (var s = o > 1 ? void 0 : o ? Pt(e, i) : e, r = t.length - 1, a; r >= 0; r--)
(a = t[r]) && (s = a(s) || s);
return s;
};
let le = 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>
`;
}
};
le.styles = F`
${ce(Ct)}
`;
le = Et([
S("maptiler-geocode-marker")
], le);
function Ut(t) {
const e = ot(
$e([
nt([
[
[180, 90],
[-180, 90],
[-180, -90],
[180, -90],
[180, 90]
]
]),
t
])
);
if (!e)
return;
e.properties = { isMask: !0 };
const i = D(Le(t)), o = (i[2] - i[0]) / 360 / 1e3, s = i[0] < -180, r = i[2] > 180, a = at(t);
if (a.features.length > 1 && (s || r))
for (const u of a.features) {
const y = D(Le(u));
if (r && y[0] < -180 + o)
for (const M of u.geometry.coordinates)
for (const _ of M)
_[0] += 360 - o;
if (s && y[2] > 180 - o)
for (const M of u.geometry.coordinates)
for (const _ of M)
_[0] -= 360 - o;
}
return $e([a.features.length < 2 ? t : lt(a) ?? t, e]);
}
const Bt = {
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
}, Gt = (t) => (e) => {
const i = t.iconsBaseUrl ?? "https://cdn.maptiler.com/maptiler-geocoding-control/v3.0.0/icons/", o = e.getProperties(), s = e.getGeometry()?.getType(), r = o.isMask ? 0 : s === "LineString" || s === "MultiLineString" ? 3 : 2;
return new ht({
stroke: o.isMask ? void 0 : new Fe({
color: "#3170fe",
lineDash: [r, r],
width: r,
lineCap: "butt"
}),
fill: o.isMask ? new Ie({
color: "#00000020"
}) : void 0,
image: new ct({
src: `${i}marker_${o.isReverse ? "reverse" : o.isSelected ? "selected" : "unselected"}.svg`,
anchor: [0.5, 1]
}),
zIndex: o.isSelected ? 2 : o.isReverse ? 0 : 1,
text: (o.isSelected || o.isMouseOver) && o.tooltip ? new dt({
backgroundFill: new Ie({ color: "white" }),
text: o.tooltip,
offsetY: -40,
backgroundStroke: new Fe({
color: "white",
lineJoin: "round",
width: 3
}),
padding: [2, 0, 0, 2]
}) : void 0
});
}, T = "EPSG:4326";
class li extends Ye {
#e;
#t;
#r;
constructor(e = {}) {
const i = document.createElement("div");
super({
element: i,
...e
}), this.#e = e, this.#r = document.createElement("maptiler-geocoder"), this.#r.classList.add("openlayers-geocoder"), this.#b(), i.classList.add("openlayers-ctrl-geocoder"), i.style.zIndex = "3", i.appendChild(this.#r);
}
/** @internal Not to be called directly */
setMap(e) {
super.setMap(e), this.#t && this.#t !== e && (this.#I(), this.#P(), this.#t = void 0), e && (this.#t = e, this.#$(), this.#C());
}
getOptions() {
return { ...this.#e };
}
setOptions(e) {
Object.assign(this.#e, e), this.#b();
}
setQuery(e) {
this.#r.setQuery(e);
}
submitQuery(e) {
this.#r.submitQuery(e);
}
clearMap() {
this.#a = [], this.#u(void 0, void 0);
}
clearList() {
this.#r.clearList();
}
setReverseMode(e) {
this.setOptions({ reverseActive: e });
}
focus(e) {
this.#r.focus(e);
}
blur() {
this.#r.blur();
}
/** Markers currently displayed on the map */
#c = /* @__PURE__ */ new Map();
/** Marker representing the selected feature */
#h;
/** Marker representing the picked feature */
#o;
/** Features currently marked on the map */
#a;
/** Remember last feature that the map flew to as to not do it again */
#g;
/** Layer used for showing results */
#l;
// eslint-disable-line @typescript-eslint/no-explicit-any
/** Source connected to layer used for showing results */
#s;
/** Last marker the mouse was over, used to detech mouseover and mouseleave events on markers */
#d;
/** Flag whether to show reverse geocoding cursor */
#y = !1;
#v = {
reversetoggle: (e) => {
this.#y = e.detail.reverse, this.#i("reversetoggle", e.detail);
},
querychange: (e) => {
const i = e.detail.reverseCoords;
this.#_(i ? [i.decimalLongitude, i.decimalLatitude] : void 0), this.#i("querychange", e.detail);
},
queryclear: () => {
this.#_(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.#m && this.#e.flyToSelected && this.#w(i.center, this.#p(i)), this.#a && i && this.#T(i), this.#i("select", e.detail);
},
pick: (e) => {
const i = e.detail.feature;
i && i.id !== this.#g && this.#m && (this.#F(i), this.#u(this.#a, i)), this.#g = i?.id, this.#i("pick", e.detail);
},
featuresshow: () => {
this.#i("featuresshow");
},
featureshide: () => {
this.#i("featureshide");
},
featureslisted: (e) => {
const i = e.detail.features;
this.#a = i, this.#u(this.#a, void 0), this.#O(e), this.#i("featureslisted", e.detail);
},
featuresclear: () => {
this.#a = void 0, this.#u(void 0, void 0), this.#i("featuresclear");
},
focusin: () => {
this.#i("focusin");
},
focusout: () => {
this.#i("focusout");
}
};
#x = {
postrender: () => {
const e = this.#t?.getView().getZoom(), i = this.#t?.getView().getCenter();
this.#r.handleMapChange(e && i ? [e, ...this.#L(i)] : void 0);
},
click: (e) => {
this.#r.handleMapClick(this.#L(e.coordinate)), this.#t?.forEachFeatureAtPixel(e.pixel, (i) => {
const o = i.getId(), s = this.#a?.find((r) => r.id === o);
if (!(!o || !s))
return e.stopPropagation(), this.#i("markerclick", { feature: s, marker: i }), !0;
});
},
pointermove: (e) => {
if (!this.#t) return;
const i = this.#t.forEachFeatureAtPixel(e.pixel, (s) => s.getId() ? s : void 0);
this.#t.getTargetElement().style.cursor = i ? "pointer" : this.#y ? "crosshair" : "";
const o = i?.getId();
if (this.#d !== o) {
if (this.#d) {
const s = this.#a?.find((a) => a.id === this.#d), r = this.#c.get(s);
r?.set("isMouseOver", !1), s && r && this.#i("markermouseleave", { feature: s, marker: r });
}
if (i) {
const s = this.#a?.find((r) => r.id === o);
this.#i("markermouseenter", { feature: s, marker: i }), i.set("isMouseOver", !0);
}
this.#d = o;
}
}
};
#b() {
this.#r.setOptions(this.#e), this.#r.fetchFullGeometryOnPick = this.#e.pickedResultStyle !== "marker-only";
}
#$() {
if (this.#t) {
for (const [e, i] of Object.entries(this.#v))
this.#r.addEventListener(e, i);
for (const [e, i] of Object.entries(this.#x))
this.#t.on([e], i);
}
}
#I() {
if (this.#t) {
for (const [e, i] of Object.entries(this.#v))
this.#r.removeEventListener(e, i);
for (const [e, i] of Object.entries(this.#x))
this.#t.un([e], i);
}
}
#i(e, i) {
this.dispatchEvent(Object.assign(new He(e), i));
}
#F(e) {
e.bbox[0] === e.bbox[2] && e.bbox[1] === e.bbox[3] ? this.#w(e.center, this.#p(e)) : this.#k(D(e.bbox), 50, this.#p(e));
}
#O({ detail: { features: e, external: i } }) {
if (!e || e.length === 0 || !this.#m || this.#e.flyToFeatures === !1 || this.#e.flyToFeatures === "never" || !i && (this.#e.flyToFeatures === void 0 || this.#e.flyToFeatures === "external"))
return;
const o = e.every((a) => a.matching_text), s = e.reduce(
(a, u) => o || !u.matching_text ? [Math.min(a[0], u.bbox[0]), Math.min(a[1], u.bbox[1]), Math.max(a[2], u.bbox[2]), Math.max(a[3], u.bbox[3])] : a,
[180, 90, -180, -90]
), r = e.map((a) => this.#p(a)).filter((a) => a !== void 0).reduce((a, u) => a === void 0 ? u : Math.max(a, u), void 0);
this.#k(D(s), 50, r);
}
#p(e) {
if (e.bbox[0] !== e.bbox[2] || e.bbox[1] !== e.bbox[3])
return;
const i = e.id.replace(/\..*/, ""), o = this.#e.zoom ?? Bt;
return (Array.isArray(e.properties?.categories) ? e.properties.categories.reduce((s, r) => {
const a = o[i + "." + r];
return s === void 0 ? a : a === void 0 ? s : Math.max(s, a);
}, void 0) : void 0) ?? o[i];
}
get #m() {
return !!this.#e.flyTo || this.#e.flyTo === void 0;
}
get #S() {
return typeof this.#e.flyTo == "boolean" ? {} : this.#e.flyTo;
}
get #M() {
return typeof this.#e.flyTo == "boolean" ? {} : this.#e.flyTo;
}
#w(e, i) {
this.#t?.getView().animate({
center: this.#f(e),
...i ? { zoom: i } : {},
duration: 2e3,
...this.#S
});
}
#k(e, i, o) {
this.#t?.getView().fit(et(e, T, this.#n()), {
padding: [i, i, i, i],
...o ? { maxZoom: o } : {},
duration: 2e3,
...this.#M
});
}
#_(e) {
if (this.#e.marker === !1 || !this.#t || !this.#s)
return;
if (!e) {
this.#o && (this.#s.removeFeature(this.#o), this.#o.dispose(), this.#o = void 0);
return;
}
const i = this.#f(e);
if (!this.#o) {
this.#o = new $(new H(i)), this.#o.set("isReverse", !0), this.#s.addFeature(this.#o);
return;
}
this.#o.getGeometry().setCoordinates(i);
}
#u(e, i) {
if (!this.#t || !this.#s)
return;
this.#