UNPKG

@arcgis/map-components

Version:
74 lines (73 loc) 3.86 kB
import { c as p } from "../../chunks/runtime.js"; import { html as e } from "lit-html"; import { usePropertyChange as m } from "@arcgis/components-controllers"; import { reEmitEvent as a } from "@arcgis/components-controllers/accessor"; import { classes as u } from "@arcgis/components-utils"; import v from "@arcgis/core/widgets/Track/TrackViewModel.js"; import { LitElement as w, createEvent as f, noShadowRoot as M, safeClassMap as n, nothing as k } from "@arcgis/lumina"; import { u as E } from "../../chunks/useT9n.js"; import { m as b } from "../../chunks/useViewModel.js"; import { g as c } from "../../chunks/globalCss.js"; import { css as T } 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 y = T`@layer{arcgis-track{display:block}}`, $ = { base: "esri-track" }, O = b(v); class D extends w { constructor() { super(...arguments), this.messages = E(), this.viewModel = O(this), this.autoDestroyDisabled = !1, this.error = this.viewModel.error, this.geolocationOptions = this.viewModel.geolocationOptions, this.goToOverride = this.viewModel.goToOverride, this.goToLocationDisabled = this.viewModel.goToLocationEnabled, this.graphic = this.viewModel.graphic, this.icon = "compass-north-circle", this.position = "top-left", this.positionFilterFunction = this.viewModel.positionFilterFunction, this.scale = this.viewModel.scale, this.state = this.viewModel.state, this.tracking = this.viewModel.tracking, this.arcgisComplete = a(() => this.viewModel, "track"), this.arcgisError = a(() => this.viewModel, "track-error"), this.arcgisPropertyChange = m()("state"), this.arcgisReady = f(); } static { this.properties = { autoDestroyDisabled: 5, error: 1, geolocationOptions: 1, goToOverride: 0, goToLocationDisabled: 7, graphic: 0, icon: 3, label: 1, messageOverrides: 0, position: 3, positionFilterFunction: 0, referenceElement: 1, scale: 9, state: 0, tracking: 4 }; } static { this.shadowRootOptions = M; } static { this.styles = y; } // #endregion // #region Public Methods /** Permanently destroy the component */ async destroy() { await this.manager.destroy(); } async start() { this.viewModel.start(); } async stop() { this.viewModel.stop(); } // #endregion // #region Private Methods _localizeError(t) { if (t instanceof GeolocationPositionError) return t.code === GeolocationPositionError.PERMISSION_DENIED ? this.messages?.permissionError : t.code === GeolocationPositionError.TIMEOUT ? this.messages?.timeoutError : this.messages?.positionUnavailable; if (t instanceof Error) return t.message; } _toggleTracking() { if (!this.viewModel) return; const { state: t } = this.viewModel; if (!(t === "feature-unsupported" || t === "disabled")) { if (t === "tracking" || t === "waiting") { this.viewModel.stop(); return; } this.viewModel.start(); } } // #endregion // #region Rendering render() { const { viewModel: t, messages: o, icon: l } = this, i = t?.state, d = i === "tracking", s = this._localizeError(this.viewModel?.error), r = (d ? o?.stopTracking : o?.startTracking) ?? "", h = i === "feature-unsupported", g = (i === "tracking" ? "pause" : void 0) ?? l ?? void 0; return e`<div class=${n(u($.base, c.widget))}>${!h && e`<calcite-button class=${n(c.widgetButton)} .disabled=${i === "disabled"} .iconStart=${g} kind=neutral .label=${r} .loading=${i === "waiting"} @click=${this._toggleTracking} title=${r ?? k}></calcite-button>` || ""}${s ? e`<calcite-tooltip open overlay-positioning=fixed .referenceElement=${this.el}>${s}</calcite-tooltip>` : null}</div>`; } } p("arcgis-track", D); export { D as ArcgisTrack };