UNPKG

@arcgis/map-components

Version:
281 lines (280 loc) • 11.2 kB
import { c as T } from "../../chunks/runtime.js"; import { html as o } from "lit-html"; import { usePropertyChange as W } from "@arcgis/lumina/controllers"; import { classes as y } from "@arcgis/components-utils"; import { nothing as v, safeStyleMap as O, LitElement as x, createEvent as S, noShadowRoot as B, safeClassMap as g } from "@arcgis/lumina"; import { u as E } from "../../chunks/useT9n.js"; import { m as H } from "../../chunks/useViewModel.js"; import { H as L } from "../../chunks/heading.js"; import { g as w } from "../../chunks/globalCss.js"; import { css as A } from "@lit/reactive-element/css-tag.js"; import D from "@arcgis/core/core/Accessor.js"; import { property as h, subclass as k } from "@arcgis/core/core/accessorSupport/decorators.js"; import { watch as P } from "@arcgis/core/core/reactiveUtils.js"; import b from "@arcgis/core/views/3d/environment/CloudyWeather.js"; import f from "@arcgis/core/views/3d/environment/FoggyWeather.js"; import _ from "@arcgis/core/views/3d/environment/RainyWeather.js"; import $ from "@arcgis/core/views/3d/environment/SnowyWeather.js"; import C from "@arcgis/core/views/3d/environment/SunnyWeather.js"; /*! All material copyright Esri, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. v4.33.13 */ const c = "arcgis-weather", d = { base: c, content: `${c}__content`, hasError: `${c}__content--has-error`, selector: `${c}__selector`, options: `${c}__options`, optionsHidden: `${c}__options--hidden`, error: `${c}__error`, warning: `${c}__warning` }, R = A`@layer{.arcgis-weather{position:relative;padding:var(--esri-widget-padding);width:fit-content}.arcgis-weather__content{display:flex;flex-direction:column;gap:var(--calcite-spacing-md);width:min-content}.arcgis-weather__content--has-error{visibility:hidden;height:0;overflow:hidden;pointer-events:none}.arcgis-weather__selector{display:flex;flex-direction:row;gap:var(--calcite-spacing-sm);align-items:center}.arcgis-weather__options{display:flex;flex-direction:column;gap:var(--calcite-spacing-sm);calcite-label:last-child{--calcite-label-margin-bottom: 0}}.arcgis-weather__options--hidden{display:none}.arcgis-weather__warning{display:flex;flex-direction:row;gap:var(--calcite-spacing-xs);align-items:center;font-size:var(--calcite-font-size-sm);calcite-icon{color:var(--calcite-color-status-warning)}}}`; var V = Object.defineProperty, j = Object.getOwnPropertyDescriptor, a = (t, e, s, i) => { for (var r = i > 1 ? void 0 : i ? j(e, s) : e, p = t.length - 1, l; p >= 0; p--) (l = t[p]) && (r = (i ? l(e, s, r) : l(r)) || r); return i && r && V(e, s, r), r; }; const z = { sunny: C, cloudy: b, rainy: _, snowy: $, foggy: f }, M = Object.keys(z); let n = class extends D { //#region Lifecycle constructor(t) { super(t), this.view = null, this._settingWeather = !1, this._weatherByType = { sunny: new C(), cloudy: new b(), rainy: new _(), snowy: new $(), foggy: new f() }; } initialize() { this.addHandles([ // When the weather is changed directly in the environment (not in the VM), // we need to update the corresponding weather instance in the view model. P( () => this.current, (t) => { this._settingWeather || t == null || (this._weatherByType = { ...this._weatherByType, [t.type]: t }); }, { sync: !0, initial: !0 } ) ]); } get state() { if (!this.view?.ready) return "disabled"; if (this.error != null) switch (this.error) { // When the weather is not visible because of camera position, we don't // consider it to be a fatal error so we still want to display the full // UI, just with a warning at the bottom. case "not-visible": return "ready"; // Other errors make the widget unusable, so we consider them to be fatal // and show only the error message. default: return "error"; } return "ready"; } get disabled() { return this.state === "disabled"; } get weatherByType() { return this._weatherByType; } get error() { const t = this.view; return t?.ready ? t.type !== "3d" ? "unsupported-view" : t.viewingMode === "local" ? "local-scene" : t.environment.atmosphereEnabled ? t.environment.weatherAvailable ? null : "not-visible" : "no-atmosphere" : null; } get current() { return this._environment?.weather ?? this._weatherByType.sunny; } set current(t) { const e = this._environment; e && (e.weather = t); } get _environment() { const t = this.view; return t != null && t.type === "3d" ? t.environment : null; } //#endregion //#region Public Methods setWeatherByType(t) { if (!M.includes(t)) { console.warn(`arcgis-weather - "${t}" is not a valid weather type`); return; } const e = this._environment; e != null && (this._settingWeather = !0, e.weather = this._weatherByType[t], this._settingWeather = !1); } setSnowCoverEnabled(t) { const e = this.current; "snowCover" in e && (e.snowCover = t ? "enabled" : "disabled"); } //#endregion }; a([ h() ], n.prototype, "view", 2); a([ h() ], n.prototype, "state", 1); a([ h() ], n.prototype, "disabled", 1); a([ h() ], n.prototype, "weatherByType", 1); a([ h() ], n.prototype, "error", 1); a([ h() ], n.prototype, "current", 1); a([ h() ], n.prototype, "_weatherByType", 2); a([ h() ], n.prototype, "_environment", 1); n = a([ k("components.weather.WeatherViewModel") ], n); function u({ label: t, value: e, disabled: s, onChange: i }) { const r = (p) => { const l = p.currentTarget.value; i?.(l); }; return o`<calcite-label scale=s>${t}<calcite-slider aria-label=${t ?? v} .disabled=${s} style=${O({ // Tweaks to make the slider more compact and better-align within the weather component */ marginInline: "-7px", marginBottom: "-7px" })} max=1 min=0 step=0.01 .value=${e ?? 0} @calciteSliderChange=${r} @calciteSliderInput=${r}></calcite-slider></calcite-label>`; } const F = H(n), I = { sunny: "brightness", cloudy: "partly-cloudy", rainy: "rain", snowy: "snow", foggy: "fog" }; class q extends x { constructor() { super(...arguments), this.viewModel = F(this), this.messages = E(), this.autoDestroyDisabled = !1, this.headingLevel = 4, this.hideHeader = !1, this.icon = "partly-cloudy", this.label = this.messages.componentLabel, this.position = "bottom-left", this.state = this.viewModel.state, this.arcgisPropertyChange = W()("state"), this.arcgisReady = S(); } static { this.properties = { autoDestroyDisabled: 5, headingLevel: 9, hideHeader: 5, icon: 1, label: 1, messageOverrides: 0, position: 1, referenceElement: 1, state: 35 }; } static { this.shadowRootOptions = B; } static { this.styles = R; } async destroy() { await this.manager.destroy(); } _getWarningMessage() { switch (this.viewModel.error) { case "not-visible": { const { view: e } = this.viewModel; return e?.type === "3d" && e.environment.atmosphereEnabled ? this.messages.error?.notVisible : void 0; } default: return; } } _getErrorMessage() { const e = this.messages.error; if (e) switch (this.viewModel.error) { case "local-scene": return e.localScene; case "no-atmosphere": return e.noAtmosphere; case "unsupported-view": return e.unsupported; default: return; } } render() { return o`<div aria-label=${this.messages.componentLabelAccessible ?? v} class=${g(y(d.base, w.widget, this.viewModel.disabled && w.widgetDisabled))} role=region>${this._renderContent()}</div>`; } _renderContent() { const { headingLevel: e, messages: s, viewModel: i } = this, r = this._getWarningMessage(), p = i.current, l = i.state === "error"; return o`${this.hideHeader ? void 0 : L({ level: e, children: s.componentLabel })}${l ? o`<div class=${g(d.error)}>${this._getErrorMessage()}</div>` : void 0}<div class=${g(y({ [d.content]: !0, [d.hasError]: l }))}><div aria-label=${s.weatherType ?? v} class=${g(d.selector)} role=radiogroup>${M.map(this._renderWeatherTypeButton, this)}</div>${Object.values(i.weatherByType).map((m) => o`<div class=${g(y({ [d.options]: !0, [d.optionsHidden]: m.type !== p?.type }))}>${this._renderOptions(m)}</div>`)}${r ? this._renderWarning(r) : void 0}</div>`; } _renderWeatherTypeButton(e) { const s = this.messages[e]?.label ?? "", { disabled: i } = this.viewModel, r = !i && this.viewModel.current.type === e; return o`<calcite-button .appearance=${r ? "solid" : "outline"} aria-checked=${r ? "true" : "false"} .disabled=${i} .iconStart=${I[e]} .kind=${r ? "brand" : "neutral"} .label=${s} @click=${() => { r || this.viewModel.setWeatherByType(e); }} scale=l title=${s ?? v}></calcite-button>`; } _renderOptions(e) { switch (e.type) { case "sunny": return this._renderSunnyOptions(e); case "cloudy": return this._renderCloudyOptions(e); case "rainy": return this._renderRainyOptions(e); case "snowy": return this._renderSnowyOptions(e); case "foggy": return this._renderFoggyOptions(e); } } _renderSunnyOptions(e) { return u({ disabled: this.viewModel.disabled, label: this.messages.sunny?.cloudCover, value: e.cloudCover, onChange: (s) => { e.cloudCover = s; } }); } _renderCloudyOptions(e) { return u({ disabled: this.viewModel.disabled, label: this.messages.cloudy?.cloudCover, value: e.cloudCover, onChange: (s) => { e.cloudCover = s; } }); } _renderRainyOptions(e) { const { disabled: s } = this.viewModel, i = this.messages.rainy; return o`${u({ disabled: s, label: i?.cloudCover, value: e.cloudCover, onChange: (r) => { e.cloudCover = r; } })}${u({ disabled: s, label: i?.precipitation, value: e.precipitation, onChange: (r) => { e.precipitation = r; } })}`; } _renderSnowyOptions(e) { const { disabled: s } = this.viewModel, i = this.messages.snowy; return o`${u({ disabled: s, label: i?.cloudCover, value: e.cloudCover, onChange: (r) => { e.cloudCover = r; } })}${u({ disabled: s, label: i?.precipitation, value: e.precipitation, onChange: (r) => { e.precipitation = r; } })}<calcite-label layout=inline scale=s title=${i?.snowCoverTooltip ?? v}><calcite-checkbox .checked=${e.snowCover === "enabled"} .disabled=${s} @calciteCheckboxChange=${(r) => { this.viewModel.setSnowCoverEnabled(r.currentTarget.checked); }}></calcite-checkbox>${i?.snowCover}</calcite-label>`; } _renderFoggyOptions(e) { return u({ disabled: this.viewModel.disabled, label: this.messages.foggy?.fogStrength, value: e.fogStrength, onChange: (s) => { e.fogStrength = s; } }); } _renderWarning(e) { return o`<div class=${g(d.warning)}><calcite-icon icon=exclamation-mark-triangle scale=s></calcite-icon>${e}</div>`; } } T("arcgis-weather", q); export { q as ArcgisWeather };