@arcgis/map-components
Version:
ArcGIS Map Components
123 lines (122 loc) • 5.07 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import { c as _ } from "../../chunks/runtime.js";
import { css as T, html as l } from "lit";
import { LitElement as x } from "@arcgis/lumina";
import { watch as k, when as y } from "@arcgis/core/core/reactiveUtils.js";
import { a as d } from "../../chunks/maybe.js";
import { c as f, t as p } from "../../chunks/async-utils.js";
import { throttle as v } from "lodash-es";
import $ from "@arcgis/core/popup/content/MediaContent.js";
import w from "@arcgis/core/popup/content/FieldsContent.js";
import I from "@arcgis/core/popup/content/TextContent.js";
import { compileExpression as L } from "@arcgis/core/applications/Components/arcadeFeatureUtils.js";
import { s as E } from "../../chunks/feature-utils.js";
const A = T`.loading-container{display:flex;justify-content:center;padding:var(--calcite-spacing-md) 0;width:100%}`, g = 1;
class b extends x {
constructor() {
super(...arguments), this._compileThrottled = v(this._startCompile, g), this._evaluateThrottled = v(this._startEvaluate, g), this.headingLevel = 2;
}
static {
this.properties = { _compileTask: 16, _evaluateTask: 16, values: 0, fieldInfoMap: 0, expressionInfo: 0, graphic: 0, headingLevel: 9, interceptor: 0, location: 0, messages: 0, spatialReference: 0, map: 0, view: 0 };
}
static {
this.styles = A;
}
loaded() {
this.manager.onLifecycle(() => [
k(() => [this.expressionInfo, this.graphic], () => this._compileThrottled(), { initial: !0 }),
y(() => {
if (!this._compileTask?.finished)
return null;
const t = this._compileTask.value, s = t?.dependencies, { view: e } = this;
return [
t,
this.spatialReference,
this.map,
e,
s?.has("view-scale") && e && "scale" in e ? e.scale : null,
s?.has("view-time-extent") ? e?.timeExtent?.start : null,
s?.has("view-time-extent") ? e?.timeExtent?.end : null
];
}, ([t]) => this._evaluateThrottled(t)),
{
remove: () => this._cancelThrottles()
}
]);
}
_cancelThrottles() {
this._compileThrottled.cancel(), this._evaluateThrottled.cancel();
}
_startCompile() {
this._evaluateTask = d(this._evaluateTask), this._compileTask = d(this._compileTask), this._compileTask = f(async (t) => {
const { expressionInfo: s, graphic: e } = this, a = s?.expression;
if (!a || !e)
return null;
const n = await L({
expression: a,
graphic: e
});
return p(t), n;
});
}
_startEvaluate(t) {
this._evaluateTask = d(this._evaluateTask), this._evaluateTask = f(async (s) => {
const { graphic: e } = this;
if (!t || !e)
return null;
const { interceptor: a, spatialReference: n, map: i, location: r, view: o } = this, c = await t.evaluate({
graphic: e,
interceptor: a,
location: r,
map: i,
options: { signal: s },
spatialReference: n,
view: o
});
p(s);
const m = c && "castAsJsonAsync" in c && typeof c.castAsJsonAsync == "function" ? c : null;
if (!m)
return null;
const h = await m.castAsJsonAsync(s);
p(s);
const u = h?.type;
return u === "media" ? $.fromJSON(h) : u === "text" ? I.fromJSON(h) : u === "fields" ? w.fromJSON(h) : null;
});
}
render() {
const t = !this._compileTask?.finished || !this._evaluateTask?.finished;
return l`<div class="root">${t ? this._renderLoading() : this._evaluateTask?.value ? this._renderContent() : null}</div>`;
}
_renderContent() {
const { values: t, fieldInfoMap: s } = this, e = this._evaluateTask?.value, a = e?.type, n = { ...t, ...e?.attributes };
if (!a)
return null;
if (a === "text") {
const { text: i } = e;
if (!i)
return null;
const r = E({
values: n,
fieldInfoMap: s ?? /* @__PURE__ */ new Map(),
globalValues: n,
layer: void 0,
text: i
});
return l`<arcgis-feature-content .creator=${r} .graphic=${this.graphic}></arcgis-feature-content>`;
} else if (a === "media") {
const { title: i, description: r, mediaInfos: o } = e;
return !o?.length && !i && !r ? null : l`<arcgis-feature-media .heading=${i ?? ""} .values=${n} .formattedValues=${n} .description=${r ?? ""} .mediaInfos=${o ?? []} .messages=${this.messages} .headingLevel=${this.headingLevel}></arcgis-feature-media>`;
} else if (a === "fields") {
const { title: i, description: r, fieldInfos: o } = e;
return !o?.length && !i && !r ? null : l`<arcgis-feature-fields .fieldInfos=${o ?? []} .heading=${i ?? ""} .values=${n} .description=${r ?? ""} .headingLevel=${this.headingLevel} .messages=${this.messages}></arcgis-feature-fields>`;
}
return null;
}
_renderLoading() {
return l`<div class="loading-container"><calcite-loader inline label></calcite-loader></div>`;
}
}
_("arcgis-feature-expression", b);
export {
b as ArcgisFeatureExpression
};