UNPKG

gisviewer-vue3-arcgis

Version:

在应用中引入私服的包, 项目根目录下 新建文件 .npmrc 在 .npmrc 中对包源进行配置:

107 lines (106 loc) 3.46 kB
import g from "ol/format/GeoJSON"; import w from "ol/layer/Vector"; import { unByKey as y } from "ol/Observable"; import S from "ol/source/Vector"; import { Style as h, Stroke as m } from "ol/style"; import { toRaw as E } from "vue"; import R from "../../../stores/index.mjs"; const r = class { constructor(e) { this.initialized = !1, this.layer = null, this.roadsectIndexMap = /* @__PURE__ */ new Map(), this.theme = "flow", this.map = e; } async showRoadIndex(e) { var s, t; this.theme = e.options.theme, this.roadsectIndexMap = new Map( e.roadsects.map((o) => [String(o.roadId), o]) ), this.initialized || (await this.initialize(), this.initialized = !0), (s = this.layer) == null || s.setVisible(!0), (t = this.layer) == null || t.changed(), (e.options.needZoom ?? !0) && await this.zoomToRoadsects(); } destroy() { this.clearRoadIndex(), this.layer && (this.map.removeLayer(this.layer), this.layer.dispose(), this.layer = null), this.initialized = !1; } clearRoadIndex() { var e; this.roadsectIndexMap.clear(), (e = this.layer) == null || e.setVisible(!1); } async initialize() { var o; const e = R.useAppDataStore; let t = (o = E(e.mapConfig).roadsectIndex) == null ? void 0 : o.roadsectLayer; if (!t) { console.log( "No roadsect layer URL found in mapConfig.roadsectIndex. Initialization aborted." ); return; } this.layer = new w({ source: new S({ url: t, format: new g() }), style: (i, a) => this.getRoadsectStyle(i, a) }), this.map.addLayer(this.layer), this.layer.setVisible(!0); } async zoomToRoadsects() { var o; const e = (o = this.layer) == null ? void 0 : o.getSource(); if (!e) return; const s = this.map.getView(), t = this.map.getSize(); e.getFeatures().length === 0 && t && await new Promise((i) => { const a = () => { y([d, n]), i(); }, d = e.on("featuresloadend", a), n = e.on("featuresloaderror", a); e.loadFeatures( s.calculateExtent(t), s.getResolution() ?? 1, s.getProjection() ); }), e.getFeatures().length !== 0 && this.map.getView().fit(e.getExtent(), { padding: [10, 10, 10, 10], maxZoom: 18 }); } getRoadsectStyle(e, s) { const t = this.map.getView().getZoomForResolution(s) ?? 18, o = t < 18 ? 2 : 4, i = this.roadsectIndexMap.get(String(e.get("id"))); if (!i) return new h({ stroke: new m({ color: "#808080", width: o }) }); const a = this.theme === "flow" ? i.flowVolume : i.avgTravelTimeS, d = this.theme === "flow" ? r.FLOW_BREAKS : r.SPEED_BREAKS, n = this.theme === "flow" ? r.FLOW_COLORS : r.SPEED_COLORS, c = d.findIndex((u) => a <= u), f = n[c === -1 ? n.length - 1 : c], p = this.theme === "both" ? this.getFlowWidth(i.flowVolume, t) : o; return new h({ stroke: new m({ color: f, width: p }) }); } getFlowWidth(e, s) { const t = r.FLOW_BREAKS.findIndex( (a) => e <= a ), i = (t === -1 ? r.FLOW_BREAKS.length : t) + 2; return console.log(i), s > 18 ? i * 2 : i; } }; let l = r; l.FLOW_BREAKS = [50, 150, 300, 500]; l.SPEED_BREAKS = [8, 15, 25, 35]; l.FLOW_COLORS = [ "#1A9850", "#91CF60", "#FEE08B", "#FC8D59", "#D73027" ]; l.SPEED_COLORS = [ "#B2182B", "#EF6548", "#FEE08B", "#A6D96A", "#1A9850" ]; export { l as default };