UNPKG

gisviewer-vue3-arcgis

Version:

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

2 lines (1 loc) 2.24 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("ol/interaction"),d=require("ol/layer/Vector"),w=require("ol/source/Vector"),y=require("./style/line-style.js"),p=require("./style/point-style.js"),l=require("./style/polygon-style.js");class h{constructor(e){this.drawInteraction=null,this.drawSource=null,this.drawLayer=null,this.map=e}startDraw(e){this.stopDraw(),this.drawSource=new w({wrapX:!1});const t=this.parseStyleConfig(e.geometryType,e.style);this.drawLayer=new d({source:this.drawSource,style:t}),this.drawLayer.set("id","__draw_layer__"),this.map.addLayer(this.drawLayer);const o=this.mapGeometryType(e.geometryType);if(!o){console.warn(`不支持的绘制类型: ${e.geometryType}`);return}const c={source:this.drawSource,type:o};e.geometryType.toLowerCase()==="rectangle"&&(c.type="Circle",c.geometryFunction=(s,r)=>{const n=require("ol/geom/Polygon").default;r||(r=new n([]));const i=s[0],a=s[1];return i&&a&&r.setCoordinates([[i,[i[0],a[1]],a,[a[0],i[1]],i]]),r}),this.drawInteraction=new u.Draw(c),this.drawInteraction.on("drawend",s=>{const r=s.feature,n=r.getGeometry(),i=n==null?void 0:n.getType(),a={feature:r,geometry:n,geometryType:i,coordinates:this.getCoordinates(n)};e.callback&&e.callback(a)}),this.map.addInteraction(this.drawInteraction)}stopDraw(){this.drawInteraction&&(this.map.removeInteraction(this.drawInteraction),this.drawInteraction=null)}clearDraw(){this.drawSource&&this.drawSource.clear()}mapGeometryType(e){return{point:"Point",linestring:"LineString",line:"LineString",polygon:"Polygon",circle:"Circle",rectangle:"Circle"}[e.toLowerCase()]||null}parseStyleConfig(e,t){switch(e.toLowerCase()){case"point":return p.getPointStyle(t);case"linestring":case"line":return y.getLineStyle(t);case"polygon":case"rectangle":case"circle":return l.getPolygonStyle(t);default:return l.getPolygonStyle(t)}}getCoordinates(e){var o;if(!e)return null;switch(e.getType()){case"Point":return e.getCoordinates();case"LineString":return e.getCoordinates();case"Polygon":return e.getCoordinates();case"Circle":return{center:e.getCenter(),radius:e.getRadius()};default:return((o=e.getCoordinates)==null?void 0:o.call(e))||null}}}exports.default=h;