gisviewer-vue3-arcgis
Version:
在应用中引入私服的包, 项目根目录下 新建文件 .npmrc 在 .npmrc 中对包源进行配置:
128 lines (127 loc) • 4.06 kB
JavaScript
import { Point as l, Polygon as d } from "@arcgis/core/geometry";
import f from "../common-utils.mjs";
import p from "./entrance.mjs";
import u from "./exit.mjs";
class C {
constructor(n) {
this.nearbyFeatures = /* @__PURE__ */ new Map(), this.entrances = [], this.exits = [], this.initialized = !1, this.id = n.id, this.crossCenter = new l({ x: n.center[0], y: n.center[1] });
}
/**
* 初始化路口,设置周边车道与停止线
* @param params
*/
async initialize(n) {
n.lanes.forEach((e) => {
const t = e.getAttribute("RoadSecID"), s = e.geometry, i = this.nearbyFeatures.get(t);
i ? i.lanes.push(s) : this.nearbyFeatures.set(t, {
lanes: [s],
stopLines: []
});
}), n.stopLines.forEach((e) => {
const t = e.getAttribute("RoadSecID"), s = e.geometry, i = this.nearbyFeatures.get(t);
i ? i.stopLines.push(s) : this.nearbyFeatures.set(t, {
lanes: [],
stopLines: [s]
});
}), await this.createEntranceAndExit(), console.log(`${this.id} has ${this.entrances.length} entrance`), this.entrances.forEach((e) => {
console.log(`${e.id} has ${e.lanes.length} lanes`);
}), this.orderEntrance(), this.initialized = !0;
}
/**
* 标注车道序号的信息,进口道序号+车道序号
* @returns
*/
getLaneNumberInfo() {
const n = [];
return this.entrances.forEach((e) => {
e.lanes.forEach((t, s) => {
n.push({
crossId: this.id,
// 路口id
laneNumber: e.id + String(s + 1),
// 车道序号
stopLineCenter: [t.stopLineCenter.x, t.stopLineCenter.y],
// 车道停止线中心点
laneDirection: t.laneDirection - 180
// 车道方向
});
});
}), this.exits.forEach((e) => {
e.lanes.forEach((t, s) => {
n.push({
crossId: this.id,
// 路口id
laneNumber: "-" + e.id + String(s + 1),
// 车道序号
stopLineCenter: [t.stopLineCenter.x, t.stopLineCenter.y],
// 车道停止线中心点
laneDirection: t.laneDirection - 180
// 车道方向
});
});
}), n;
}
/**
* 计算路口指标计算区域。
* 由相邻进口道的停止线延长线交点围成的区域
*/
async calCrossIndicatorArea() {
const n = [];
for (let e = 0; e < this.entrances.length; e++) {
const t = this.entrances[e], s = this.entrances[(e + 1) % this.entrances.length], i = t.furthestLane.extendedStopLine, a = s.furthestLane.extendedStopLine, o = await f.getIntersectPointOfTwoLines(
i,
a
);
if (o)
n.push(o);
else {
const r = this.findExitOfEntrance(t), c = (r ? r.lanes[r.lanes.length - 1] : t.lanes[t.lanes.length - 1]).stopLine.getPoint(0, 1);
n.push(c);
const h = s.lanes[s.lanes.length - 1].stopLine.getPoint(0, 1);
n.push(h);
}
}
if (n.length > 2)
return new d({
rings: [n.map((e) => [e.x, e.y])]
});
}
/**
* 创建进口道与出口道,并得到道口的车道与车道停止线
*/
async createEntranceAndExit() {
for (const n of this.nearbyFeatures) {
const e = n[0], t = n[1];
if (t.stopLines.length === 0) {
const s = new u(e);
s.addLanes(t), this.exits.push(s);
} else {
const s = new p(e);
await s.addLanes(t), this.entrances.push(s);
}
}
for (const n of this.exits)
await n.findCorrespondingEntrance(this.entrances);
}
/**
* 进口道排序
*/
orderEntrance() {
this.entrances.sort((n, e) => {
let t = n.dir, s = e.dir;
return t < 225 && (t += 360), s < 225 && (s += 360), t - s;
}), this.entrances.forEach((n, e) => {
n.id = String(e + 1);
const t = this.findExitOfEntrance(n);
t && (t.id = String(e + 1));
});
}
findExitOfEntrance(n) {
for (const e of this.exits)
if (e.entrance === n)
return e;
}
}
export {
C as default
};