UNPKG

gisviewer-vue3-arcgis

Version:

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

2 lines (1 loc) 9.04 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const P=require("@arcgis/core/Basemap"),k=require("@arcgis/core/config"),S=require("@arcgis/core/core/reactiveUtils"),v=require("@arcgis/core/geometry"),W=require("@arcgis/core/geometry/support/webMercatorUtils"),q=require("@arcgis/core/Graphic"),G=require("@arcgis/core/layers/FeatureLayer"),C=require("@arcgis/core/layers/GeoJSONLayer"),O=require("@arcgis/core/layers/GroupLayer"),x=require("@arcgis/core/layers/IntegratedMesh3DTilesLayer"),_=require("@arcgis/core/layers/MapImageLayer"),j=require("@arcgis/core/layers/TileLayer"),H=require("@arcgis/core/layers/WebTileLayer"),B=require("@arcgis/core/layers/WMSLayer"),N=require("@arcgis/core/Map"),R=require("@arcgis/core/views/MapView"),E=require("@arcgis/core/views/SceneView"),U=require("@turf/destination"),A=require("@turf/helpers"),D=require("@arcgis/core/layers/GraphicsLayer"),V=require("./custom-layer/custom-wmts-layer.js");function T(y){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(y){for(const i in y)if(i!=="default"){const s=Object.getOwnPropertyDescriptor(y,i);Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:()=>y[i]})}}return e.default=y,Object.freeze(e)}const z=T(S),M=T(W),J=T(A);class K{constructor(){this.mapConfig={},this.watchHandleMap=new Map,this.handleIndex=0,this.zoomWatchHandle=null,this.detachmentLayerLoaded=!1}processUrl(e){return e&&(e.startsWith("http://")||e.startsWith("https://")?e:e.startsWith("{{")?e.replace("{{geoServer}}",this.mapConfig.geoServer):this.mapConfig.assetsRoot+e)}async initialize(e){var p,w,g,m,b;this.mapConfig=e.mapConfig;const{container:i,markerClickCallback:s,mapClickCallback:a}=e;k.assetsPath=`${this.mapConfig.assetsRoot}/ArcgisAssets`,k.fontsUrl=`${this.mapConfig.assetsRoot}/fonts`,k.apiKey="AAPKf5a3e1044d7a4faeb3b1ec7060f5c68equIrP2KbRyL-t_b40Kk4GTWUQ1BFCyttvyQPQnWpFmBd7kp9gkrVihjfmcKBwxjW";const o=new N;((w=(p=this.mapConfig)==null?void 0:p.mapOptions.mode)==null?void 0:w.toLowerCase())!=="3d"?(this.view=new R({map:o,container:i,...this.mapConfig.mapOptions}),this.view.on("drag",t=>{t.button===2&&t.stopPropagation()})):this.view=new E({map:o,container:i,environment:{atmosphereEnabled:!0,lighting:{type:"virtual"}},...(g=this.mapConfig)==null?void 0:g.mapOptions}),this.view.popup.visibleElements={closeButton:!0,collapseButton:!1,actionBar:!1,featureNavigation:!0},this.view.popup.dockOptions={buttonEnabled:!1,breakpoint:!1},this.view.on("click",async t=>{var l,L;if(a){let n=t.mapPoint;n.spatialReference.isWebMercator&&(n=M.webMercatorToGeographic(n)),a([n.x,n.y],[t.screenPoint.x,t.screenPoint.y],t)}if(this.view.type==="3d"){const n=this.view.camera;if(this.view.spatialReference.isWebMercator){const d=M.webMercatorToGeographic(n.position),f={heading:n.heading,tilt:n.tilt,position:d.toJSON()};console.log(f),(l=navigator.clipboard)==null||l.writeText(JSON.stringify(f))}else console.log(n.toJSON());console.log(this.view.zoom,this.view.scale)}else{let n=this.view.center;this.view.spatialReference.isWebMercator&&(n=M.webMercatorToGeographic(n)),console.log({center:n.toJSON(),zoom:this.view.zoom,scale:this.view.scale})}const c=(L=(await this.view.hitTest(t)).results)==null?void 0:L.filter(n=>n.type==="graphic");c.length>0&&c.forEach(n=>{var f;const d=n.graphic;(f=d.attributes)!=null&&f.type&&s&&s(d.attributes.type,d.attributes.id,d.attributes,t)})});{let t=0,r=!1;this.view.on("pointer-move",async c=>{var L;const l=performance.now();if(!(r||l-t<100)){t=l,r=!0;try{const d=(L=(await this.view.hitTest(c)).results)==null?void 0:L.some(I=>I.type==="graphic"),f=this.view.container;f&&(f.style.cursor=d?"pointer":"default")}finally{r=!1}}})}if(this.view.on("pointer-leave",()=>{const t=this.view.container;t&&(t.style.cursor="default")}),(m=this.mapConfig)!=null&&m.baseLayers?this.mapConfig.baseLayers.forEach(t=>{const r=this.processUrl(t.url);let c=null;switch(t.type.toLowerCase()){case"webTile".toLowerCase():{c=new H({urlTemplate:r,...t.options});break}case"tile":{c=new j({url:r,...t.options});break}case"customWMTS".toLowerCase():{c=new V.default({urlTemplate:r,...t.options});break}case"mapImage".toLowerCase():{c=new _({url:r,...t.options});break}case"arcgis":{const l=new P(t.options);o.basemap=l;break}case"feature":{c=new G({url:r,...t.options});break}case"3dtiles":{c=new x({url:r,...t.options});break}case"wms":{c=new B({url:r,...t.options});break}case"geojson":{c=new C({url:r,...t.options});break}}if(c)if(t.group){let l=o.findLayerById(t.group);l&&l.type==="group"?l.add(c):(l=new O({id:t.group,title:t.groupTitle,visibilityMode:"inherited",layers:[c],visible:t.groupVisible!==!1}),o.add(l))}else o.add(c)}):o.basemap=new P({style:{id:"arcgis/light-gray",language:"zh-CN"}}),(b=this.mapConfig)!=null&&b.hdLayers){const t=this.mapConfig.hdLayers.map(r=>new C({url:this.processUrl(r.url),...r.options,title:r.options.id}));o.addMany(t)}this.view.ui.remove("attribution"),await this.view.when();const h=this.mapConfig.camera;let u;if(this.view.type==="2d"){let t=this.view.center;this.view.spatialReference.isWebMercator&&(t=M.webMercatorToGeographic(t)),u={center:[t.x,t.y],zoom:this.view.zoom}}else{let t=this.view.camera.position;this.view.spatialReference.isWebMercator&&(t=M.webMercatorToGeographic(t)),u={position:t,heading:this.view.camera.heading,tilt:this.view.camera.tilt}}return h?h.home=u:this.mapConfig.camera={home:u},this.view}async setLayerVisibility(e){const{id:i,visible:s}=e;if(i==="shanghai_district")return!this.detachmentLayerLoaded&&e.visible?await this.loadDetachmentLayer():this.detachmentLayer&&(this.detachmentLayer.visible=s),{status:0,message:"ok"};{const a=this.view.map.findLayerById(i);return a?(a.visible=s,{status:0,message:"ok"}):{status:-1,message:"未找到图层"}}}async setMapCenter(e){var i;if(!this.view)return{status:-1,message:"未初始化"};if(e.center||e.target){switch((i=e.target)==null?void 0:i.type.toLowerCase()){case"point":e.target=new v.Point(e.target);break;case"polyline":e.target=new v.Polyline(e.target);break;case"polygon":e.target=new v.Polygon(e.target);break;case"multipoint":e.target=new v.Multipoint(e.target);break}await this.view.goTo(e,{duration:(e.duration||0)*1e3})}return{status:0,message:"成功"}}setMapZoom(e){return this.view?(this.view.zoom=e.zoom,{status:0,message:"成功"}):{status:-1,message:"未初始化"}}async lookAt(e){if(this.view.type==="2d")return;const i=e.tilt||0,s=e.heading||0;if(i===0)await this.view.goTo({position:{x:e.center[0],y:e.center[1],z:e.height},heading:s,tilt:0},{duration:(e.duration||2)*1e3});else{const a=Math.tan(i*Math.PI/180)*e.height,o=U(J.point(e.center),a,s+180,{units:"meters"});await this.view.goTo({position:{x:o.geometry.coordinates[0],y:o.geometry.coordinates[1],z:e.height},heading:s,tilt:i},{duration:(e.duration||2)*1e3})}}async setMapCamera(e){if(!this.view)return{status:-1,message:"未初始化"};const{name:i,duration:s=0}=e,{camera:a}=this.mapConfig;if(!a)return{status:-1,message:"未配置camera"};const o=a[i];return o?(await this.view.goTo(o,{duration:s*1e3}),{status:0,message:"成功"}):{status:-1,message:"未配置camera"}}requestCoordinateTransform(e,i){let s=0;const o=1e3/30,h=z.watch(()=>this.view.center,()=>{const u=this.transformPoints(e),p=Date.now();p-s>o&&(i(u),s=p)});return this.handleIndex++,this.watchHandleMap.set(this.handleIndex,h),{handle:this.handleIndex,points:this.transformPoints(e)}}transformPoints(e){return e.map(i=>{const s=new v.Point({x:i[0],y:i[1]}),a=this.view.toScreen(s);return[a.x,a.y]})}cancelCoordinateTransform(e){const i=this.watchHandleMap.get(e);i&&(i.remove(),this.watchHandleMap.delete(e))}setMapZoomRange(e){const{min:i,max:s}=e;!i&&!s||(this.zoomWatchHandle&&this.zoomWatchHandle.remove(),this.zoomWatchHandle=z.watch(()=>this.view.zoom,a=>{i&&a<=i&&(this.view.zoom=i),s&&a>=s&&(this.view.zoom=s)}))}async loadDetachmentLayer(){this.detachmentLayer=new D({id:"detachmentLayer",title:"支队图层",effect:void 0}),this.view.map.add(this.detachmentLayer);const e=this.mapConfig.baseLayers;if(!e)return;const i=e.find(s=>s.options.id==="shanghai_district");if(i)try{const a=await(await fetch("/GisViewerAssets/ShangHai/Layers/district.json")).json(),o=[],{renderer:h,labelingInfo:u}=i.options;a.features.forEach(p=>{const w=p.attributes.ZD_NAME;if(w!=="高架支队"){let g=new v.Polygon({rings:p.geometry.rings});g=W.webMercatorToGeographic(g);const m=new q({geometry:g,attributes:p.attributes});if(h){if(h.type==="simple")m.symbol=h.symbol;else if(h.type==="unique-value"){const b=m.getAttribute("OBJECTID"),t=h.uniqueValueInfos.find(r=>r.value==b);m.symbol=t?t.symbol:h.defaultSymbol}}else m.symbol={type:"simple-fill",color:[227,237,255,.4],outline:{color:[255,195,153],width:2}};if(o.push(m),u&&w!=="边防港航支队"&&w!=="机场支队"){const b=new q({geometry:g.centroid,symbol:{...u.symbol,text:w}});o.push(b)}}}),this.detachmentLayer.addMany(o),this.detachmentLayerLoaded=!0}catch(s){console.error("加载支队图层失败:",s);return}}}exports.default=K;