UNPKG

gisviewer-vue3-arcgis

Version:

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

2 lines (1 loc) 2.72 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const f=require("ol/format/GeoJSON"),y=require("ol/layer/Vector"),w=require("ol/Observable"),S=require("ol/source/Vector"),d=require("ol/style"),p=require("vue"),E=require("../../../stores/index.js"),n=class{constructor(e){this.initialized=!1,this.layer=null,this.roadsectIndexMap=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=E.default.useAppDataStore;let t=(o=p.toRaw(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 y({source:new S({url:t,format:new f}),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=()=>{w.unByKey([c,l]),i()},c=e.on("featuresloadend",a),l=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 d.Style({stroke:new d.Stroke({color:"#808080",width:o})});const a=this.theme==="flow"?i.flowVolume:i.avgTravelTimeS,c=this.theme==="flow"?n.FLOW_BREAKS:n.SPEED_BREAKS,l=this.theme==="flow"?n.FLOW_COLORS:n.SPEED_COLORS,h=c.findIndex(m=>a<=m),u=l[h===-1?l.length-1:h],g=this.theme==="both"?this.getFlowWidth(i.flowVolume,t):o;return new d.Style({stroke:new d.Stroke({color:u,width:g})})}getFlowWidth(e,s){const t=n.FLOW_BREAKS.findIndex(a=>e<=a),i=(t===-1?n.FLOW_BREAKS.length:t)+2;return console.log(i),s>18?i*2:i}};let r=n;r.FLOW_BREAKS=[50,150,300,500];r.SPEED_BREAKS=[8,15,25,35];r.FLOW_COLORS=["#1A9850","#91CF60","#FEE08B","#FC8D59","#D73027"];r.SPEED_COLORS=["#B2182B","#EF6548","#FEE08B","#A6D96A","#1A9850"];exports.default=r;