gisviewer-vue3-arcgis
Version:
在应用中引入私服的包, 项目根目录下 新建文件 .npmrc 在 .npmrc 中对包源进行配置:
84 lines (83 loc) • 2.76 kB
JavaScript
import L from "@arcgis/core/Graphic";
import d from "@arcgis/core/layers/GraphicsLayer";
import h from "@turf/area";
import C from "@turf/buffer";
import q from "@turf/destination";
import * as u from "@turf/helpers";
import P from "@turf/intersect";
import w from "../../stores/index.mjs";
class $ {
constructor(e) {
this.initialized = !1, this.lanePolygonMap = /* @__PURE__ */ new Map(), this.view = e;
const t = w.useAppDataStore;
this.mapConfig = JSON.parse(JSON.stringify(t.mapConfig)), this.queueLengthLayer = new d(), this.view.map.add(this.queueLengthLayer);
}
async initializeLaneGraphic() {
if (!this.mapConfig.lanePolygonLayer)
return;
const e = `${this.mapConfig.assetsRoot}/${this.mapConfig.lanePolygonLayer}`, n = await (await fetch(e)).json(), { features: i } = n;
i.forEach((r) => {
const { properties: o, geometry: s } = r, p = u.polygon(s.coordinates, {
code: o.code,
laneDirection: o.laneDirection,
stopLineCenter: o.stopLineCenter
});
this.lanePolygonMap.set(o.code, p);
}), this.initialized = !0;
}
async updateQueueLength(e) {
if (this.initialized || await this.initializeLaneGraphic(), this.lanePolygonMap.size !== 0)
for (const t of e) {
const n = String(t.laneId), i = `${t.crossNo}+${n[0]}+${n[1]}`, r = this.lanePolygonMap.get(i);
if (!r)
continue;
const o = this.queueLengthLayer.graphics.find(
(s) => s.getAttribute("code") === i
);
o && this.queueLengthLayer.remove(o), t.queueLength !== 0 && this.generateQueuePolygon(r, t.queueLength);
}
}
removeQueueLength() {
this.queueLengthLayer.removeAll();
}
generateQueuePolygon(e, t) {
const n = e.properties.laneDirection, i = JSON.parse(
e.properties.stopLineCenter
), r = u.point(i), o = n > 0 ? n - 180 : n + 180, s = q(r, t, o, {
units: "meters"
}), p = u.lineString([
i,
s.geometry.coordinates
]), g = C(p, 10, { units: "meters" }), a = P(e, g);
if (!a)
return;
const f = h(a.geometry), m = h(e), l = f / m, c = l > 0.8 ? [139, 0, 0, 0.6] : l > 0.6 ? [255, 165, 0, 0.5] : [46, 139, 87, 0.5], y = new L({
geometry: {
type: "polygon",
rings: a == null ? void 0 : a.geometry.coordinates
},
symbol: {
type: "polygon-3d",
symbolLayers: [
{
type: "fill",
material: {
color: c
},
outline: {
color: [c[0], c[1], c[2]],
size: 3
}
}
]
},
attributes: {
code: e.properties.code
}
});
this.queueLengthLayer.add(y);
}
}
export {
$ as default
};