UNPKG

@arcgis/map-components

Version:
72 lines (71 loc) 3.81 kB
import { c as m } from "../../chunks/runtime.js"; import { html as t } from "lit-html"; import { usePropertyChange as g } from "@arcgis/components-controllers"; import { reEmitEvent as r } from "@arcgis/components-controllers/accessor"; import { classes as u } from "@arcgis/components-utils"; import f from "@arcgis/core/widgets/Locate/LocateViewModel.js"; import { LitElement as v, createEvent as w, noShadowRoot as E, safeClassMap as l, nothing as b } from "@arcgis/lumina"; import { u as M } from "../../chunks/useT9n.js"; import { m as y } from "../../chunks/useViewModel.js"; import { g as c } from "../../chunks/globalCss.js"; import { l as $ } from "../../chunks/legacyIcon.js"; import { css as L } from "@lit/reactive-element/css-tag.js"; /*! All material copyright Esri, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. v4.32.13 */ const D = L`@layer{arcgis-locate{display:block}}`, O = { base: "esri-locate" }, n = "gps-off", T = y(f); class I extends v { constructor() { super(...arguments), this.messages = M(), this.viewModel = T(this), this.autoDestroyDisabled = !1, this.geolocationOptions = this.viewModel.geolocationOptions, this.goToLocationDisabled = this.viewModel.goToLocationEnabled, this.goToOverride = this.viewModel.goToOverride, this.graphic = this.viewModel.graphic, this.icon = n, this.popupDisabled = this.viewModel.popupEnabled, this.position = "top-left", this.scale = this.viewModel.scale, this.state = this.viewModel.state, this.arcgisError = r(() => this.viewModel, "locate-error"), this.arcgisPropertyChange = g()("state"), this.arcgisReady = w(), this.arcgisSuccess = r(() => this.viewModel, "locate"); } static { this.properties = { autoDestroyDisabled: 5, geolocationOptions: 1, goToLocationDisabled: 7, goToOverride: 0, graphic: 0, icon: 3, label: 1, messageOverrides: 0, popupDisabled: 5, position: 3, referenceElement: 1, scale: 9, state: 3 }; } static { this.shadowRootOptions = E; } static { this.styles = D; } // #endregion // #region Public Methods /** * This function provides the ability to interrupt and cancel the process of * programmatically obtaining the location of the user's device. */ async cancelLocate() { this.viewModel.cancelLocate(); } /** Permanently destroy the component */ async destroy() { await this.manager.destroy(); } async locate() { return await this.viewModel.locate(); } // #endregion // #region Private Methods _localizeError(e) { if (e instanceof GeolocationPositionError) return e.code === GeolocationPositionError.PERMISSION_DENIED ? this.messages?.permissionError : e.code === GeolocationPositionError.TIMEOUT ? this.messages?.timeoutError : this.messages?.positionUnavailable; if (e instanceof Error) return e.message; } _locate() { const { viewModel: e } = this; e.state === "locating" ? e.cancelLocate() : e.locate().catch(() => { }); } // #endregion // #region Rendering render() { const { viewModel: e, icon: d } = this, { state: o } = e, i = o === "locating", s = i ? this.messages.cancel : this.messages.title, h = o === "feature-unsupported", p = $ === void 0 ? n : void 0, a = this._localizeError(this.viewModel?.error); return t`<div class=${l(u(O.base, c.widget))}>${!h && t`<calcite-button class=${l(c.widgetButton)} .disabled=${o === "disabled"} .iconStart=${i ? void 0 : d ?? p} kind=neutral .label=${s} @click=${this._locate} title=${s ?? b}>${i ? t`<calcite-loader inline label></calcite-loader>` : null}</calcite-button>` || ""}${a ? t`<calcite-tooltip open overlay-positioning=fixed .referenceElement=${this.el}>${a}</calcite-tooltip>` : null}</div>`; } } m("arcgis-locate", I); export { I as ArcgisLocate };