UNPKG

@arcgis/map-components

Version:
107 lines (106 loc) 4.38 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */ import { c as m } from "../../chunks/runtime.js"; import p from "@arcgis/core/Color.js"; import l from "@arcgis/core/Graphic.js"; import g from "@arcgis/core/layers/GraphicsLayer.js"; import y from "@arcgis/core/symbols/SimpleFillSymbol.js"; import n from "@arcgis/core/symbols/SimpleLineSymbol.js"; import d from "@arcgis/core/symbols/SimpleMarkerSymbol.js"; import { LitElement as w, createEvent as _, nothing as f } from "@arcgis/lumina"; import { log as s, composeMissingPropertyMessage as a } from "@arcgis/toolkit/log"; import { css as G, html as u } from "lit"; import { u as L } from "../../chunks/useT9n.js"; import { a as v, b as o } from "../../chunks/layer-utils.js"; const b = G`.loader-container{display:flex;justify-content:center;padding-bottom:var(--calcite-spacing-md)}`, h = 12; class S extends w { constructor() { super(...arguments), this._graphicsLayerName = "arcgis-utility-network-aggregated-geometry-graphics", this._messages = L({ blocking: !0 }), this._graphics = [], this._addAggregatedGeometryToView = () => { const e = this.geometry, { line: i, multipoint: r, polygon: c } = e; this._graphics = [i, r, c].filter((t) => t != null).map((t) => this._makeGraphicFromGeometry(t)), this._graphicsLayer.addMany(this._graphics); }, this._createGraphicsLayer = () => { const e = this.view.map, i = this._graphicsLayerName, r = e.findLayerById(i); if (r && v(r)) { this._graphicsLayer = r; return; } this._graphicsLayer = new g({ id: i, listMode: "hide", title: i }), o(this.view, this._graphicsLayer); }, this.hideGraphics = !1, this.graphicsColor = new p([255, 255, 0, 0.6]), this.autoDestroyDisabled = !1, this.arcgisHideGraphicsChange = _(); } static { this.properties = { geometry: 0, hideGraphics: 5, graphicsColor: 0, view: 0, autoDestroyDisabled: 5 }; } static { this.styles = b; } async destroy() { this.view?.map && this._graphicsLayer && this.view.map.remove(this._graphicsLayer), await this.manager.destroy(); } connectedCallback() { super.connectedCallback(), this.view && this._graphicsLayer && o(this.view, this._graphicsLayer); } load() { !this.geometry || !this.view?.map || this._createGraphicsLayer(); } willUpdate(e) { if (e.has("graphicsColor") && this._updateGraphicSymbols(), e.has("geometry") && (this._graphicsLayer?.removeAll(), this._addAggregatedGeometryToView()), e.has("view")) { const i = e.get("view"); i?.map && this._graphicsLayer && (i.map.remove(this._graphicsLayer), this._createGraphicsLayer(), this._addAggregatedGeometryToView()); } } loaded() { this.geometry || s("error", this, a("geometry")), this.view ? this.view.map || s("error", this, a("The property `view` was provided, but `view.map` is null. Cannot draw aggregated geometry.")) : s("error", this, a("view")); } _handleShowGraphicsChange() { this.hideGraphics = !this.hideGraphics, this.hideGraphics ? this._graphicsLayer?.removeAll() : this._graphicsLayer?.addMany(this._graphics), this.arcgisHideGraphicsChange.emit(this.hideGraphics); } _makeGraphicFromGeometry(e) { return new l({ geometry: e, symbol: this._makeSymbolForGeometry(e) }); } _makeSymbolForGeometry(e) { const i = this.graphicsColor; switch (e.type) { case "multipoint": return new d({ color: i, size: h, outline: { color: i, width: 0 } }); case "polygon": return new y({ color: i, outline: { color: i, width: h } }); case "polyline": return new n({ color: i, width: h }); } } _updateGraphicSymbols() { this._graphicsLayer?.graphics.forEach((e) => { const i = e.geometry; e.symbol = this._makeSymbolForGeometry(i); }); } render() { return u`<calcite-switch .checked=${!this.hideGraphics} .label=${this._messages.labels.showGraphicsToggle} label-text-end=${this._messages.showGraphics ?? f} @calciteSwitchChange=${this._handleShowGraphicsChange}></calcite-switch>`; } } m("arcgis-utility-network-aggregated-geometry", S); export { S as ArcgisUtilityNetworkAggregatedGeometry };