zhihao-ui 1.3.22 → 1.3.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/{Map-B9MkYv-r.js → Map-CRPS0mWA.js} +562 -569
- package/dist/es/index.js +1 -1
- package/dist/index.css +1 -1
- package/dist/umd/index.css +1 -1
- package/dist/umd/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/umd/index.umd.cjs
CHANGED
|
@@ -201,7 +201,7 @@ hooks.version="2.30.1",setHookCallback(createLocal),hooks.fn=proto,hooks.min=min
|
|
|
201
201
|
<path d="M1.99982 46.9998L1.99982 1.99982L46.9998 1.99982L46.9998 46.9998L1.99982 46.9998Z" fill="#FF2424" fill-opacity="0.2"/>
|
|
202
202
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M19.9998 0.5V3.5L3.49976 3.5V20H0.499756V0.500002L19.9998 0.5ZM45.4998 3.5H28.9998V0.5H48.4998V20H45.4998V3.5ZM48.4998 29L48.4998 48.5H28.9998V45.5H45.4998L45.4998 29H48.4998ZM3.49976 45.5L3.49976 29H0.499756L0.499758 48.5L19.9998 48.5V45.5L3.49976 45.5Z" fill="#FF2424"/>
|
|
203
203
|
</svg>
|
|
204
|
-
`,y=document.createElement("div");return y.className="ship-overlay-selected",y.innerHTML=g,y},createLabelStyle=(t,e)=>{const{lon:n,lat:r,blinking:i}=e,g=createLabelElement(e);n&&r&&addOverlay(t,fromLonLat([n,r]),g,{...e,blinking:i})},createLabelElement=t=>{const e=document.createElement("div");e.className="ship-overlay-box",e.style.position="relative";const{lon:n,lat:r,blinking:i,blinkingColors:g,name:y}=t,k=vue.createVNode({setup(){return useShipOverlay({position:[n+.002,r+.002],selected:i,name:y,colors:g||[],existDevice:t==null?void 0:t.existDevice,existMobile:t==null?void 0:t.existMobile,existWaterGauge:t==null?void 0:t.existWaterGauge})}});return vue.render(k,e),e},getRightIcons=t=>{const e=[];return t.existDevice&&e.push(""),t.existMobile&&e.push(""),t.existWaterGauge&&e.push(""),e};function getRandomLineDirection(){const t=["left-top","left-middle","left-bottom","right-top","right-middle","right-bottom"];return t[Math.floor(Math.random()*t.length)]}const devicePixelRatio$1=window.devicePixelRatio||1;function generateBase64Icon(t,e,n="left-bottom",r=2){const i=document.createElement("canvas"),g=i.getContext("2d");if(!g)return"";const y=2,k=16,L=window.devicePixelRatio||1,$="500 12px Arial",V="14px map-iconfont";g.font=$;const re=g.measureText(t).width;g.font=V;const ie=e.map(Ue=>({width:g.measureText(getIconFont(Ue)).width,height:14})),j=ie.reduce((Ue,Et)=>Ue+Et.width,0),oe=(e.length-1)*r,ae=y+re+j+oe+y*2,le=y+16+y;let de,he,ue=0,pe=0,Ce=0,_e=0,xe=0,Ie=0;switch(de=k+ae,n){case"right-top":he=k+le,ue=0,pe=k+le,Ce=k,_e=0,xe=k,Ie=0;break;case"right-middle":he=le,ue=0,pe=le/2,Ce=k,_e=le/2,xe=k,Ie=0;break;case"right-bottom":he=k+le,ue=0,pe=0,Ce=k,_e=k,xe=k,Ie=k;break;case"left-top":he=k+le,ue=ae,pe=k,Ce=ae+k,_e=le+k,xe=0,Ie=0;break;case"left-middle":he=le,ue=ae,pe=le/2,Ce=ae+k,_e=le/2,xe=0,Ie=0;break;case"left-bottom":he=k+le,ue=ae,pe=le,Ce=ae+k,_e=0,xe=0,Ie=k;break}i.width=Math.round(de*L),i.height=Math.round(he*L),i.style.width=`${de}px`,i.style.height=`${he}px`,g.scale(L,L),g.clearRect(0,0,de,he),g.beginPath(),g.moveTo(ue,pe),g.lineTo(Ce,_e),g.strokeStyle="#FFF",g.lineWidth=1,g.stroke(),g.fillStyle="#FFF",g.fillRect(xe,Ie,ae,le),g.font=$,g.textBaseline="middle";const Oe=Ie+y+le/2;g.strokeStyle="#ffffff",g.lineWidth=1,g.strokeText(t,xe+y,Oe),g.fillStyle="#000000",g.fillText(t,xe+y,Oe),g.font=V,g.fillStyle="#3370ff";let Ve=xe+y+re+r;return e.forEach((Ue,Et)=>{const At=Ie+y+le/2;g.fillText(getIconFont(Ue),Ve,At),Ve+=ie[Et].width+r}),i.toDataURL("image/png")}const createLabelFeatureStyle=t=>{const{name:e,rightIcons:n}=t.getProperties(),r=getRandomLineDirection(),i=generateBase64Icon(e,n,r);let g=[0,0];switch(r){case"right-top":g=[0,1];break;case"right-middle":g=[0,.5];break;case"right-bottom":g=[0,0];break;case"left-top":g=[1,1];break;case"left-middle":g=[1,.5];break;case"left-bottom":g=[1,0];break}return new Style({image:new Icon({src:i,anchor:g,displacement:[0,0],scale:1/devicePixelRatio$1,anchorXUnits:"fraction",anchorYUnits:"fraction"})})},useShipManager=t=>{let e=null,n=null;const r=new VectorSource,i=new VectorImageLayer({source:r,className:"zh-map--ship-layer",renderBuffer:300,zIndex:101}),g=new VectorSource,y=new VectorLayer({source:g,className:"zh-map--ship-label-layer",zIndex:102,updateWhileInteracting:!1,updateWhileAnimating:!1,declutter:function(_e,xe){try{return!(xe&&(xe!=null&&xe.get("selected")))}catch(Ie){return console.log(Ie),!0}}});t==null||t.addLayer(i),t==null||t.addLayer(y);let k="",L={},$={};const V=_e=>{if(!_e||!t)return;const xe=(n==null?void 0:n.id)||(e==null?void 0:e.get("id"));if(n){const Ie=_e.filter(Oe=>Oe.id===xe);Ie.length===0?_e.push(n):n=Ie[0]}ie(),j(!0),Ce(_e),re()},z=_e=>{var Fe;const xe=(n==null?void 0:n.id)||(e==null?void 0:e.get("id")),Ie=fromLonLat([_e==null?void 0:_e.lon,_e==null?void 0:_e.lat]),Oe=((Fe=$[_e.id])==null?void 0:Fe.blinkColors)||[],Ue=Oe[Oe.length-1]||_e.fill||"#04C900",Et=getShipDirectPath(_e),At=new Feature({geometry:new Point(Ie),shipData:_e,id:_e.id,name:_e.cnname||_e.enname||_e.id||"未命名船舶",selected:_e.id===xe,rightIcons:getRightIcons(_e),color:Ue,direct:Et,isHighlight:!1});return At.set("clickGeometry",new Circle(Ie)),At},re=async()=>{if(!n||!t)return;let xe=t.getOverlays().getArray().find(Ie=>Ie.get("class")=="ship-overlay-selected");if(console.log("selectedOverlay----------",xe),xe){const Ie=selectedShipElement(t,n);await xe.setElement(Ie),await xe.setPosition(fromLonLat([n.lon,n.lat]))}else xe=selectedShipStyle(t,n),xe&&t.addOverlay(xe);setTimeout(()=>{var Ie;xe&&((Ie=xe.get("element"))!=null&&Ie.parentElement)&&(xe.get("element").parentElement.style.display="block")},20)},ie=()=>{t&&r&&(r.clear(),g.clear(),j())},j=_e=>{const xe=t.getOverlays().getArray().filter(Ie=>Ie.get("class")=="zh-map-ship-overlay");if(xe&&xe.length>0){for(let Ie=0;Ie<xe.length;Ie++)if(!_e&&xe[Ie].get("class")!=="ship-overlay-selected"){const Oe=xe[Ie];Oe.setPosition(void 0),t.removeOverlay(Oe),Oe.dispose()}}},oe=(_e,xe)=>{L=_e,$=xe;const Ie=t.getOverlays().getArray(),Oe=r.getFeatures();for(const Ve in L){const Ue=L[Ve],Et=Ie.find(Fe=>Fe.getId()==="label-"+Ve),At=Oe.find(Fe=>Ve===Fe.get("id"));if(Et&&At){const Fe=xe[Ve].blinkColors,{shipData:$e,name:ze}=At==null?void 0:At.getProperties();At.set("color",Fe[Fe.length-1]||""),At.set("blinking",Ue);const qe={...$e,blinking:Ue,blinkingColors:Fe||[],name:ze+"("+xe[Ve].shipState+")"},Ne=Et.getElement(),kt=createLabelElement(qe);Ne&&Ne!==kt&&Et.setElement(kt)}}},ae=_e=>{if(!t)return;const xe=r.getFeatures(),Ie=g.getFeatures(),Oe=e?e.get("id"):"",Ve=xe.filter(Fe=>Fe.get("id")!==Oe),Ue=Ie==null?void 0:Ie.filter(Fe=>Fe.get("id")!==Oe),Et=new Map;_e.forEach(Fe=>{Et.set(Fe.id,!0)});const At=t.getOverlays().getArray();Ve.forEach(Fe=>{const $e=Fe.get("id");if(!Et.has($e))Fe.setStyle([]);else{const qe=Fe.getStyle();(qe==null?void 0:qe.length)==0&&Fe.setStyle(createShipStyle(t,Fe))}const ze=At.find(qe=>qe.getId()==="label-"+$e);ze&&ze.setPosition(void 0)}),Ue.forEach(Fe=>{const $e=Fe.get("id");if(!Et.has($e))Fe.setStyle([]);else{const ze=Fe.getStyle();(ze==null?void 0:ze.length)==0&&Fe.setStyle(createLabelFeatureStyle(Fe))}})},le=_e=>{if(_e){console.log("选中",_e);const xe=r.getFeatures().find(Oe=>Oe.get("id")===_e.id),Ie=g.getFeatures().find(Oe=>Oe.get("id")===_e.id);xe&&(e=xe),Ie&&Ie.set("selected",!0),n=_e,re()}else console.log("取消选中"),n=null,e=null,ue()},de=debounce((_e,xe,Ie)=>{if(_e){const Oe=_e.get("shipData"),Ve=_e.get("id");if(t.getTargetElement().style.cursor=Ve?"pointer":"",xe==="click"&&(le(Oe),Ie&&Ie(Ve)),xe==="hover"){k&&k!==Ve&&he(),k=Ve;const Ue=r.getFeatures().find(Et=>Et.get("id")===k);Ue==null||Ue.set("isHighlight",!0),Ue==null||Ue.setStyle(createShipStyle(t,Ue))}}else t.getTargetElement().style.cursor="",he()},10),he=()=>{const _e=k?r.getFeatures().find(xe=>xe.get("id")===k):null;k=null,_e==null||_e.set("isHighlight",!1),_e==null||_e.setStyle(createShipStyle(t,_e))},ue=()=>{try{const xe=t.getOverlays().getArray().find(Ie=>Ie.get("class")=="ship-overlay-selected");xe&&xe.setPosition(void 0)}catch(_e){console.log(_e)}},pe=_e=>{const xe=fromLonLat([_e==null?void 0:_e.lon,_e==null?void 0:_e.lat]),Ie=new Feature({geometry:new Point(xe),name:_e.cnname||_e.enname||_e.id||"未命名船舶",rightIcons:getRightIcons(_e),selected:(_e==null?void 0:_e.id)===(n==null?void 0:n.id),shipData:_e});Ie.set("id",_e.id);const Oe=createLabelFeatureStyle(Ie);return Ie.setStyle(Oe),Ie},Ce=_e=>{const xe=t.getView().getZoom();_e.forEach(Ie=>{const Oe=z(Ie);if(Oe.setStyle(createShipStyle(t,Oe)),r.addFeature(Oe),(n==null?void 0:n.id)==Ie.id||xe>=MAP_ZOOM.shipModelMin)if(L[Ie.id]){if(Ie.id&&$[Ie==null?void 0:Ie.id]){const Ve=$[Ie==null?void 0:Ie.id]||{};console.log(Ve);const Ue=(Ve==null?void 0:Ve.blinkColors)||[],Et=(Ve==null?void 0:Ve.shipState)||"",At=(Ie.cnname||Ie.enname||Ie.id||"未命名船舶")+"("+Et+")",Fe={...Ie,name:At,blinking:L[Ie.id],blinkingColors:Ue||[]};createLabelStyle(t,Fe)}}else{const Ve=pe(Ie);g.addFeature(Ve)}})};return{render:V,selected:le,filter:ae,blinking:oe,clear:ie,handleShipMapEvent:de}},useLayerManager=t=>{const e=()=>t==null?void 0:t.getLayers(),n=vue.ref("vector"),r=()=>n.value,i=L=>{n.value=L;const $=e();$&&($==null||$.getArray().forEach(V=>{(V.className_==="vector"||V.className_==="satellite")&&V.setVisible(V.className_===L)}))},g=vue.ref(!1);return{getLayers:e,getGreenTileVisible:()=>g.value,setGreenTileVisible:L=>{if(L!==g.value){if(L){const $=e();if(!$.getArray().find(z=>z.className_==="greenTile")){const z=new TileLayer({source:new XYZ({url:BASE_MAP_LINK.greenTile}),visible:L,zIndex:2,className:"greenTile"});$.push(z)}}else{const $=e(),V=$.getArray().find(z=>z.className_==="greenTile");V&&$.remove(V)}g.value=L}},getShowLayerType:r,setShowLayerType:i}},usePropsManager=()=>{const t=vue.ref();return{setProps:r=>{t.value=r},getProps:()=>t.value}},usePositionManager=t=>{const e="zh-map-location-layer";let n,r,i=null,g=null;const y=j=>{if(!(!j||j.length===0)){if(r||(r=new VectorSource),r.clear(),g){const oe=j.find(ae=>ae.id===g.id);oe?g=oe:j.push(g)}j.forEach(oe=>{k(oe)}),n||(n=new VectorLayer({className:e,source:r,zIndex:100}),t==null||t.addLayer(n))}},k=j=>{const oe=t==null?void 0:t.getView().getZoom(),[ae,le]=j.latLon.split(","),de=new Feature({geometry:new Point(fromLonLat([Number(ae),Number(le)]))});de.setStyle(L(j,oe,j.id===(g==null?void 0:g.id))),de.set("loactionData",j),r.addFeature(de)},L=(j,oe,ae)=>{const le={image:new Icon({src:ae&&j.selectedPath||j.defaultPath,scale:.5*oe/10})};return j.name&&(le.text=new Text({text:j.name,font:"12px sans-serif",fill:new Fill({color:"#000000"}),backgroundFill:new Fill({color:"#FFFFFF"}),offsetY:30})),new Style(le)},$=()=>{if(i){const j=i.get("loactionData").id;r.getFeatures().forEach(oe=>{oe.get("loactionData").id!==j&&r.removeFeature(oe)})}else r.clear()},V=()=>{var le;const j=i.get("loactionData"),oe=(le=t==null?void 0:t.getView())==null?void 0:le.getZoom();r.getFeatures().forEach(de=>{de.get("loactionData").id===j.id&&(de==null||de.setStyle(L(j,oe,!1)))}),g=null,i=null},z=j=>{j?(re(),ie(j)):clearSelectedPort()},re=()=>{var j;if(i){const oe=i.get("loactionData"),ae=(j=t==null?void 0:t.getView())==null?void 0:j.getZoom();i.setStyle(L(oe,ae,!1))}},ie=j=>{const oe=r.getFeatures();g=j,i=oe.find(ae=>ae.get("loactionData").id===j.id)};return{render:y,selected:z,clearSelected:V,clear:$}},DrawEventType={DRAWSTART:"drawstart",DRAWEND:"drawend",DRAWABORT:"drawabort"};class DrawEvent extends BaseEvent{constructor(e,n){super(e),this.feature=n}}function getTraceTargets(t,e){const n=[];for(let r=0;r<e.length;++r){const g=e[r].getGeometry();appendGeometryTraceTargets(t,g,n)}return n}function getSquaredDistance(t,e){return squaredDistance$1(t[0],t[1],e[0],e[1])}function getCoordinate(t,e){const n=t.length;return e<0?t[e+n]:e>=n?t[e-n]:t[e]}function getCumulativeSquaredDistance(t,e,n){let r,i;e<n?(r=e,i=n):(r=n,i=e);const g=Math.ceil(r),y=Math.floor(i);if(g>y){const L=interpolateCoordinate(t,r),$=interpolateCoordinate(t,i);return getSquaredDistance(L,$)}let k=0;if(r<g){const L=interpolateCoordinate(t,r),$=getCoordinate(t,g);k+=getSquaredDistance(L,$)}if(y<i){const L=getCoordinate(t,y),$=interpolateCoordinate(t,i);k+=getSquaredDistance(L,$)}for(let L=g;L<y-1;++L){const $=getCoordinate(t,L),V=getCoordinate(t,L+1);k+=getSquaredDistance($,V)}return k}function appendGeometryTraceTargets(t,e,n){if(e instanceof LineString){appendTraceTarget(t,e.getCoordinates(),!1,n);return}if(e instanceof MultiLineString){const r=e.getCoordinates();for(let i=0,g=r.length;i<g;++i)appendTraceTarget(t,r[i],!1,n);return}if(e instanceof Polygon){const r=e.getCoordinates();for(let i=0,g=r.length;i<g;++i)appendTraceTarget(t,r[i],!0,n);return}if(e instanceof MultiPolygon){const r=e.getCoordinates();for(let i=0,g=r.length;i<g;++i){const y=r[i];for(let k=0,L=y.length;k<L;++k)appendTraceTarget(t,y[k],!0,n)}return}if(e instanceof GeometryCollection){const r=e.getGeometries();for(let i=0;i<r.length;++i)appendGeometryTraceTargets(t,r[i],n);return}}const sharedUpdateInfo={index:-1,endIndex:NaN};function getTraceTargetUpdate(t,e,n,r){const i=t[0],g=t[1];let y=1/0,k=-1,L=NaN;for(let z=0;z<e.targets.length;++z){const re=e.targets[z],ie=re.coordinates;let j=1/0,oe;for(let ae=0;ae<ie.length-1;++ae){const le=ie[ae],de=ie[ae+1],he=getPointSegmentRelationship(i,g,le,de);he.squaredDistance<j&&(j=he.squaredDistance,oe=ae+he.along)}j<y&&(y=j,re.ring&&e.targetIndex===z&&(re.endIndex>re.startIndex?oe<re.startIndex&&(oe+=ie.length):re.endIndex<re.startIndex&&oe>re.startIndex&&(oe-=ie.length)),L=oe,k=z)}const $=e.targets[k];let V=$.ring;if(e.targetIndex===k&&V){const z=interpolateCoordinate($.coordinates,L),re=n.getPixelFromCoordinate(z);distance(re,e.startPx)>r&&(V=!1)}if(V){const z=$.coordinates,re=z.length,ie=$.startIndex,j=L;if(ie<j){const oe=getCumulativeSquaredDistance(z,ie,j);getCumulativeSquaredDistance(z,ie,j-re)<oe&&(L-=re)}else{const oe=getCumulativeSquaredDistance(z,ie,j);getCumulativeSquaredDistance(z,ie,j+re)<oe&&(L+=re)}}return sharedUpdateInfo.index=k,sharedUpdateInfo.endIndex=L,sharedUpdateInfo}function appendTraceTarget(t,e,n,r){const i=t[0],g=t[1];for(let y=0,k=e.length-1;y<k;++y){const L=e[y],$=e[y+1],V=getPointSegmentRelationship(i,g,L,$);if(V.squaredDistance===0){const z=y+V.along;r.push({coordinates:e,ring:n,startIndex:z,endIndex:z});return}}}const sharedRel={along:0,squaredDistance:0};function getPointSegmentRelationship(t,e,n,r){const i=n[0],g=n[1],y=r[0],k=r[1],L=y-i,$=k-g;let V=0,z=i,re=g;return(L!==0||$!==0)&&(V=clamp(((t-i)*L+(e-g)*$)/(L*L+$*$),0,1),z+=L*V,re+=$*V),sharedRel.along=V,sharedRel.squaredDistance=toFixed(squaredDistance$1(t,e,z,re),10),sharedRel}function interpolateCoordinate(t,e){const n=t.length;let r=Math.floor(e);const i=e-r;r>=n?r-=n:r<0&&(r+=n);let g=r+1;g>=n&&(g-=n);const y=t[r],k=y[0],L=y[1],$=t[g],V=$[0]-k,z=$[1]-L;return[k+V*i,L+z*i]}class Draw extends PointerInteraction{constructor(e){const n=e;n.stopDown||(n.stopDown=FALSE),super(n),this.on,this.once,this.un,this.shouldHandle_=!1,this.downPx_=null,this.downTimeout_,this.lastDragTime_,this.pointerType_,this.freehand_=!1,this.source_=e.source?e.source:null,this.features_=e.features?e.features:null,this.snapTolerance_=e.snapTolerance?e.snapTolerance:12,this.type_=e.type,this.mode_=getMode(this.type_),this.stopClick_=!!e.stopClick,this.minPoints_=e.minPoints?e.minPoints:this.mode_==="Polygon"?3:2,this.maxPoints_=this.mode_==="Circle"?2:e.maxPoints?e.maxPoints:1/0,this.finishCondition_=e.finishCondition?e.finishCondition:TRUE,this.geometryLayout_=e.geometryLayout?e.geometryLayout:"XY";let r=e.geometryFunction;if(!r){const i=this.mode_;if(i==="Circle")r=(g,y,k)=>{const L=y||new Circle([NaN,NaN]),$=fromUserCoordinate(g[0]),V=squaredDistance($,fromUserCoordinate(g[g.length-1]));return L.setCenterAndRadius($,Math.sqrt(V),this.geometryLayout_),L};else{let g;i==="Point"?g=Point:i==="LineString"?g=LineString:i==="Polygon"&&(g=Polygon),r=(y,k,L)=>(k?i==="Polygon"?y[0].length?k.setCoordinates([y[0].concat([y[0][0]])],this.geometryLayout_):k.setCoordinates([],this.geometryLayout_):k.setCoordinates(y,this.geometryLayout_):k=new g(y,this.geometryLayout_),k)}}this.geometryFunction_=r,this.dragVertexDelay_=e.dragVertexDelay!==void 0?e.dragVertexDelay:500,this.finishCoordinate_=null,this.sketchFeature_=null,this.sketchPoint_=null,this.sketchCoords_=null,this.sketchLine_=null,this.sketchLineCoords_=null,this.squaredClickTolerance_=e.clickTolerance?e.clickTolerance*e.clickTolerance:36,this.overlay_=new VectorLayer({source:new VectorSource({useSpatialIndex:!1,wrapX:e.wrapX?e.wrapX:!1}),style:e.style?e.style:getDefaultStyleFunction(),updateWhileInteracting:!0}),this.geometryName_=e.geometryName,this.condition_=e.condition?e.condition:noModifierKeys,this.freehandCondition_,e.freehand?this.freehandCondition_=always:this.freehandCondition_=e.freehandCondition?e.freehandCondition:shiftKeyOnly,this.traceCondition_,this.setTrace(e.trace||!1),this.traceState_={active:!1},this.traceSource_=e.traceSource||e.source||null,this.addChangeListener(InteractionProperty.ACTIVE,this.updateState_)}setTrace(e){let n;e?e===!0?n=always:n=e:n=never,this.traceCondition_=n}setMap(e){super.setMap(e),this.updateState_()}getOverlay(){return this.overlay_}handleEvent(e){e.originalEvent.type===EventType.CONTEXTMENU&&e.originalEvent.preventDefault(),this.freehand_=this.mode_!=="Point"&&this.freehandCondition_(e);let n=e.type===MapBrowserEventType.POINTERMOVE,r=!0;return!this.freehand_&&this.lastDragTime_&&e.type===MapBrowserEventType.POINTERDRAG&&(Date.now()-this.lastDragTime_>=this.dragVertexDelay_?(this.downPx_=e.pixel,this.shouldHandle_=!this.freehand_,n=!0):this.lastDragTime_=void 0,this.shouldHandle_&&this.downTimeout_!==void 0&&(clearTimeout(this.downTimeout_),this.downTimeout_=void 0)),this.freehand_&&e.type===MapBrowserEventType.POINTERDRAG&&this.sketchFeature_!==null?(this.addToDrawing_(e.coordinate),r=!1):this.freehand_&&e.type===MapBrowserEventType.POINTERDOWN?r=!1:n&&this.getPointerCount()<2?(r=e.type===MapBrowserEventType.POINTERMOVE,r&&this.freehand_?(this.handlePointerMove_(e),this.shouldHandle_&&e.originalEvent.preventDefault()):(e.originalEvent.pointerType==="mouse"||e.type===MapBrowserEventType.POINTERDRAG&&this.downTimeout_===void 0)&&this.handlePointerMove_(e)):e.type===MapBrowserEventType.DBLCLICK&&(r=!1),super.handleEvent(e)&&r}handleDownEvent(e){return this.shouldHandle_=!this.freehand_,this.freehand_?(this.downPx_=e.pixel,this.finishCoordinate_||this.startDrawing_(e.coordinate),!0):this.condition_(e)?(this.lastDragTime_=Date.now(),this.downTimeout_=setTimeout(()=>{this.handlePointerMove_(new MapBrowserEvent(MapBrowserEventType.POINTERMOVE,e.map,e.originalEvent,!1,e.frameState))},this.dragVertexDelay_),this.downPx_=e.pixel,!0):(this.lastDragTime_=void 0,!1)}deactivateTrace_(){this.traceState_={active:!1}}toggleTraceState_(e){if(!this.traceSource_||!this.traceCondition_(e))return;if(this.traceState_.active){this.deactivateTrace_();return}const n=this.getMap(),r=n.getCoordinateFromPixel([e.pixel[0]-this.snapTolerance_,e.pixel[1]+this.snapTolerance_]),i=n.getCoordinateFromPixel([e.pixel[0]+this.snapTolerance_,e.pixel[1]-this.snapTolerance_]),g=boundingExtent([r,i]),y=this.traceSource_.getFeaturesInExtent(g);if(y.length===0)return;const k=getTraceTargets(e.coordinate,y);k.length&&(this.traceState_={active:!0,startPx:e.pixel.slice(),targets:k,targetIndex:-1})}addOrRemoveTracedCoordinates_(e,n){const r=e.startIndex<=e.endIndex,i=e.startIndex<=n;r===i?r&&n>e.endIndex||!r&&n<e.endIndex?this.addTracedCoordinates_(e,e.endIndex,n):(r&&n<e.endIndex||!r&&n>e.endIndex)&&this.removeTracedCoordinates_(n,e.endIndex):(this.removeTracedCoordinates_(e.startIndex,e.endIndex),this.addTracedCoordinates_(e,e.startIndex,n))}removeTracedCoordinates_(e,n){if(e===n)return;let r=0;if(e<n){const i=Math.ceil(e);let g=Math.floor(n);g===n&&(g-=1),r=g-i+1}else{const i=Math.floor(e);let g=Math.ceil(n);g===n&&(g+=1),r=i-g+1}r>0&&this.removeLastPoints_(r)}addTracedCoordinates_(e,n,r){if(n===r)return;const i=[];if(n<r){const g=Math.ceil(n);let y=Math.floor(r);y===r&&(y-=1);for(let k=g;k<=y;++k)i.push(getCoordinate(e.coordinates,k))}else{const g=Math.floor(n);let y=Math.ceil(r);y===r&&(y+=1);for(let k=g;k>=y;--k)i.push(getCoordinate(e.coordinates,k))}i.length&&this.appendCoordinates(i)}updateTrace_(e){const n=this.traceState_;if(!n.active||n.targetIndex===-1&&distance(n.startPx,e.pixel)<this.snapTolerance_)return;const r=getTraceTargetUpdate(e.coordinate,n,this.getMap(),this.snapTolerance_);if(n.targetIndex!==r.index){if(n.targetIndex!==-1){const L=n.targets[n.targetIndex];this.removeTracedCoordinates_(L.startIndex,L.endIndex)}const k=n.targets[r.index];this.addTracedCoordinates_(k,k.startIndex,r.endIndex)}else{const k=n.targets[n.targetIndex];this.addOrRemoveTracedCoordinates_(k,r.endIndex)}n.targetIndex=r.index;const i=n.targets[n.targetIndex];i.endIndex=r.endIndex;const g=interpolateCoordinate(i.coordinates,i.endIndex),y=this.getMap().getPixelFromCoordinate(g);e.coordinate=g,e.pixel=[Math.round(y[0]),Math.round(y[1])]}handleUpEvent(e){let n=!0;if(this.getPointerCount()===0){this.downTimeout_&&(clearTimeout(this.downTimeout_),this.downTimeout_=void 0),this.handlePointerMove_(e);const r=this.traceState_.active;if(this.toggleTraceState_(e),this.shouldHandle_){const i=!this.finishCoordinate_;i&&this.startDrawing_(e.coordinate),!i&&this.freehand_?this.finishDrawing():!this.freehand_&&(!i||this.mode_==="Point")&&(this.atFinish_(e.pixel,r)?this.finishCondition_(e)&&this.finishDrawing():this.addToDrawing_(e.coordinate)),n=!1}else this.freehand_&&this.abortDrawing()}return!n&&this.stopClick_&&e.preventDefault(),n}handlePointerMove_(e){if(this.pointerType_=e.originalEvent.pointerType,this.downPx_&&(!this.freehand_&&this.shouldHandle_||this.freehand_&&!this.shouldHandle_)){const n=this.downPx_,r=e.pixel,i=n[0]-r[0],g=n[1]-r[1],y=i*i+g*g;if(this.shouldHandle_=this.freehand_?y>this.squaredClickTolerance_:y<=this.squaredClickTolerance_,!this.shouldHandle_)return}if(!this.finishCoordinate_){this.createOrUpdateSketchPoint_(e.coordinate.slice());return}this.updateTrace_(e),this.modifyDrawing_(e.coordinate)}atFinish_(e,n){let r=!1;if(this.sketchFeature_){let i=!1,g=[this.finishCoordinate_];const y=this.mode_;if(y==="Point")r=!0;else if(y==="Circle")r=this.sketchCoords_.length===2;else if(y==="LineString")i=!n&&this.sketchCoords_.length>this.minPoints_;else if(y==="Polygon"){const k=this.sketchCoords_;i=k[0].length>this.minPoints_,g=[k[0][0],k[0][k[0].length-2]],n?g=[k[0][0]]:g=[k[0][0],k[0][k[0].length-2]]}if(i){const k=this.getMap();for(let L=0,$=g.length;L<$;L++){const V=g[L],z=k.getPixelFromCoordinate(V),re=e[0]-z[0],ie=e[1]-z[1],j=this.freehand_?1:this.snapTolerance_;if(r=Math.sqrt(re*re+ie*ie)<=j,r){this.finishCoordinate_=V;break}}}}return r}createOrUpdateSketchPoint_(e){this.sketchPoint_?this.sketchPoint_.getGeometry().setCoordinates(e):(this.sketchPoint_=new Feature(new Point(e)),this.updateSketchFeatures_())}createOrUpdateCustomSketchLine_(e){this.sketchLine_||(this.sketchLine_=new Feature);const n=e.getLinearRing(0);let r=this.sketchLine_.getGeometry();r?(r.setFlatCoordinates(n.getLayout(),n.getFlatCoordinates()),r.changed()):(r=new LineString(n.getFlatCoordinates(),n.getLayout()),this.sketchLine_.setGeometry(r))}startDrawing_(e){const n=this.getMap().getView().getProjection(),r=getStrideForLayout(this.geometryLayout_);for(;e.length<r;)e.push(0);this.finishCoordinate_=e,this.mode_==="Point"?this.sketchCoords_=e.slice():this.mode_==="Polygon"?(this.sketchCoords_=[[e.slice(),e.slice()]],this.sketchLineCoords_=this.sketchCoords_[0]):this.sketchCoords_=[e.slice(),e.slice()],this.sketchLineCoords_&&(this.sketchLine_=new Feature(new LineString(this.sketchLineCoords_)));const i=this.geometryFunction_(this.sketchCoords_,void 0,n);this.sketchFeature_=new Feature,this.geometryName_&&this.sketchFeature_.setGeometryName(this.geometryName_),this.sketchFeature_.setGeometry(i),this.updateSketchFeatures_(),this.dispatchEvent(new DrawEvent(DrawEventType.DRAWSTART,this.sketchFeature_))}modifyDrawing_(e){const n=this.getMap(),r=this.sketchFeature_.getGeometry(),i=n.getView().getProjection(),g=getStrideForLayout(this.geometryLayout_);let y,k;for(;e.length<g;)e.push(0);this.mode_==="Point"?k=this.sketchCoords_:this.mode_==="Polygon"?(y=this.sketchCoords_[0],k=y[y.length-1],this.atFinish_(n.getPixelFromCoordinate(e))&&(e=this.finishCoordinate_.slice())):(y=this.sketchCoords_,k=y[y.length-1]),k[0]=e[0],k[1]=e[1],this.geometryFunction_(this.sketchCoords_,r,i),this.sketchPoint_&&this.sketchPoint_.getGeometry().setCoordinates(e),r.getType()==="Polygon"&&this.mode_!=="Polygon"?this.createOrUpdateCustomSketchLine_(r):this.sketchLineCoords_&&this.sketchLine_.getGeometry().setCoordinates(this.sketchLineCoords_),this.updateSketchFeatures_()}addToDrawing_(e){const n=this.sketchFeature_.getGeometry(),r=this.getMap().getView().getProjection();let i,g;const y=this.mode_;return y==="LineString"||y==="Circle"?(this.finishCoordinate_=e.slice(),g=this.sketchCoords_,g.length>=this.maxPoints_&&(this.freehand_?g.pop():i=!0),g.push(e.slice()),this.geometryFunction_(g,n,r)):y==="Polygon"&&(g=this.sketchCoords_[0],g.length>=this.maxPoints_&&(this.freehand_?g.pop():i=!0),g.push(e.slice()),i&&(this.finishCoordinate_=g[0]),this.geometryFunction_(this.sketchCoords_,n,r)),this.createOrUpdateSketchPoint_(e.slice()),this.updateSketchFeatures_(),i?this.finishDrawing():this.sketchFeature_}removeLastPoints_(e){if(!this.sketchFeature_)return;const n=this.sketchFeature_.getGeometry(),r=this.getMap().getView().getProjection(),i=this.mode_;for(let g=0;g<e;++g){let y;if(i==="LineString"||i==="Circle"){if(y=this.sketchCoords_,y.splice(-2,1),y.length>=2){this.finishCoordinate_=y[y.length-2].slice();const k=this.finishCoordinate_.slice();y[y.length-1]=k,this.createOrUpdateSketchPoint_(k)}this.geometryFunction_(y,n,r),n.getType()==="Polygon"&&this.sketchLine_&&this.createOrUpdateCustomSketchLine_(n)}else if(i==="Polygon"){y=this.sketchCoords_[0],y.splice(-2,1);const k=this.sketchLine_.getGeometry();if(y.length>=2){const L=y[y.length-2].slice();y[y.length-1]=L,this.createOrUpdateSketchPoint_(L)}k.setCoordinates(y),this.geometryFunction_(this.sketchCoords_,n,r)}if(y.length===1){this.abortDrawing();break}}this.updateSketchFeatures_()}removeLastPoint(){this.removeLastPoints_(1)}finishDrawing(){const e=this.abortDrawing_();if(!e)return null;let n=this.sketchCoords_;const r=e.getGeometry(),i=this.getMap().getView().getProjection();return this.mode_==="LineString"?(n.pop(),this.geometryFunction_(n,r,i)):this.mode_==="Polygon"&&(n[0].pop(),this.geometryFunction_(n,r,i),n=r.getCoordinates()),this.type_==="MultiPoint"?e.setGeometry(new MultiPoint([n])):this.type_==="MultiLineString"?e.setGeometry(new MultiLineString([n])):this.type_==="MultiPolygon"&&e.setGeometry(new MultiPolygon([n])),this.dispatchEvent(new DrawEvent(DrawEventType.DRAWEND,e)),this.features_&&this.features_.push(e),this.source_&&this.source_.addFeature(e),e}abortDrawing_(){this.finishCoordinate_=null;const e=this.sketchFeature_;return this.sketchFeature_=null,this.sketchPoint_=null,this.sketchLine_=null,this.overlay_.getSource().clear(!0),this.deactivateTrace_(),e}abortDrawing(){const e=this.abortDrawing_();e&&this.dispatchEvent(new DrawEvent(DrawEventType.DRAWABORT,e))}appendCoordinates(e){const n=this.mode_,r=!this.sketchFeature_;r&&this.startDrawing_(e[0]);let i;if(n==="LineString"||n==="Circle")i=this.sketchCoords_;else if(n==="Polygon")i=this.sketchCoords_&&this.sketchCoords_.length?this.sketchCoords_[0]:[];else return;r&&i.shift(),i.pop();for(let y=0;y<e.length;y++)this.addToDrawing_(e[y]);const g=e[e.length-1];this.sketchFeature_=this.addToDrawing_(g),this.modifyDrawing_(g)}extend(e){const r=e.getGeometry();this.sketchFeature_=e,this.sketchCoords_=r.getCoordinates();const i=this.sketchCoords_[this.sketchCoords_.length-1];this.finishCoordinate_=i.slice(),this.sketchCoords_.push(i.slice()),this.sketchPoint_=new Feature(new Point(i)),this.updateSketchFeatures_(),this.dispatchEvent(new DrawEvent(DrawEventType.DRAWSTART,this.sketchFeature_))}updateSketchFeatures_(){const e=[];this.sketchFeature_&&e.push(this.sketchFeature_),this.sketchLine_&&e.push(this.sketchLine_),this.sketchPoint_&&e.push(this.sketchPoint_);const n=this.overlay_.getSource();n.clear(!0),n.addFeatures(e)}updateState_(){const e=this.getMap(),n=this.getActive();(!e||!n)&&this.abortDrawing(),this.overlay_.setMap(n?e:null)}}function getDefaultStyleFunction(){const t=createEditingStyle();return function(e,n){return t[e.getGeometry().getType()]}}function getMode(t){switch(t){case"Point":case"MultiPoint":return"Point";case"LineString":case"MultiLineString":return"LineString";case"Polygon":case"MultiPolygon":return"Polygon";case"Circle":return"Circle";default:throw new Error("Invalid type: "+t)}}const disableDoubleClickZoom=t=>{t.getInteractions().forEach(e=>{e instanceof DoubleClickZoom&&e.setActive(!1)})},enableDoubleClickZoom=t=>{t.getInteractions().forEach(e=>{e instanceof DoubleClickZoom&&e.setActive(!0)})},changeCursor=(t,e)=>{const n=t.getViewport();n&&(n.style.cursor=e)},useDrawLineManager=(t,e)=>{const n=vue.ref([]),r=vue.ref("km"),i=Ie=>{r.value=Ie};let g;const y=vue.ref(!1),k=()=>{V(),disableDoubleClickZoom(t),changeCursor(t,"crosshair"),t.on("pointermove",ie),t.getViewport().addEventListener("mouseout",()=>{g&&g.classList.add("hidden")}),oe(),y.value=!0};let L,$;const V=()=>{L=new VectorSource,$=new VectorLayer({source:L,zIndex:1e3,style:{"fill-color":"rgba(255, 255, 255, 0.2)","stroke-color":"#ffcc33","stroke-width":2,"circle-radius":7,"circle-fill-color":"#ffcc33"}}),t==null||t.addLayer($)};let z,re;const ie=Ie=>{if(Ie.dragging)return;let Oe="点击选择起点";z&&(Oe="单击继续,双击结束"),g&&(g.innerHTML=Oe,re.setPosition(Ie.coordinate),g.classList.remove("hidden"))};let j;const oe=()=>{j=new Draw({source:L,type:"LineString",style:new Style({fill:new Fill({color:"rgba(255, 255, 255, 0.2)"}),stroke:new Stroke({color:"rgba(255,204,51)",lineDash:[10,10],width:2}),image:new CircleStyle({radius:5,stroke:new Stroke({color:"rgba(0, 0, 0, 0.7)"}),fill:new Fill({color:"rgba(255, 255, 255, 0.2)"})})}),condition:Oe=>Oe.originalEvent.target.tagName!=="DIV"}),t==null||t.addInteraction(j),he(),ue();let Ie;j.on("drawstart",function(Oe){var Ue;z=Oe.feature,z.set("randomId",ae());let Ve;Ie=(Ue=z.getGeometry())==null?void 0:Ue.on("change",function(Et){const At=Et.target,Fe=computedDistance(At,r.value);Ve=At.getLastCoordinate(),le&&Fe&&(le.innerHTML=Fe),de.setPosition(Ve)})}),j.on("drawend",function(){var Oe,Ve,Ue;if(le&&(le.className="ol-tooltip ol-tooltip-static ol-tooltip-measure"),le!=null&&le.innerHTML){const Et=(z==null?void 0:z.get("randomId"))||ae();n.value.push({id:Et,value:le==null?void 0:le.innerHTML}),le.innerHTML=`${le.innerHTML}<div class="ol-tooltip-delete-button" data-id="${Et}"><i class="map-iconfont icon-delete"></i></div>`}(Oe=document.querySelector(".ol-selectable:has(.ol-tooltip-delete-button):last-child .ol-tooltip-delete-button"))==null||Oe.addEventListener("click",Et=>{var Fe;Et.preventDefault(),Et.stopPropagation();const At=(Fe=Et.target)==null?void 0:Fe.getAttribute("data-id");At&&Ce(At)}),de.setOffset([0,-7]),z=null,le=null,he(),Ie&&unByKey(Ie),(Ue=(Ve=e.getProps())==null?void 0:Ve.lineDrawEnd)==null||Ue.call(Ve,n.value)})},ae=()=>Math.random().toString(36).substring(2,9);let le,de;const he=()=>{le!=null&&le.parentNode&&le.parentNode.removeChild(le),le=document.createElement("div"),le.className="ol-tooltip ol-tooltip-measure",de=new Overlay({element:le,offset:[0,-15],positioning:"bottom-center",stopEvent:!1,insertFirst:!1}),t==null||t.addOverlay(de)},ue=()=>{g!=null&&g.parentNode&&g.parentNode.removeChild(g),g=document.createElement("div"),g.className="ol-tooltip hidden",re=new Overlay({element:g,offset:[15,0],positioning:"center-left"}),t==null||t.addOverlay(re)},pe=()=>{n.value.forEach((Ie,Oe)=>{var Et,At;const Ve=document.querySelectorAll(".ol-tooltip.ol-tooltip-static.ol-tooltip-measure");Ve[Oe]&&((At=(Et=Ve[Oe])==null?void 0:Et.parentNode)==null||At.removeChild(Ve[Oe]));const Ue=L.getFeatures();Ue[Oe]&&L.removeFeature(Ue[Oe])}),_e(),enableDoubleClickZoom(t),y.value=!1,changeCursor(t,"pointer")},Ce=Ie=>{var Ve,Ue,Et,At;const Oe=n.value.findIndex(Fe=>Fe.id===Ie);if(Oe!==-1){n.value.splice(Oe,1);const Fe=document.querySelectorAll(".ol-tooltip.ol-tooltip-static.ol-tooltip-measure");Fe[Oe]&&((Ue=(Ve=Fe[Oe])==null?void 0:Ve.parentNode)==null||Ue.removeChild(Fe[Oe]));const $e=L.getFeatures();$e[Oe]&&L.removeFeature($e[Oe])}(At=(Et=e.getProps())==null?void 0:Et.lineDrawEnd)==null||At.call(Et,n.value)},_e=()=>{if(n.value=[],document.querySelectorAll(".ol-tooltip.ol-tooltip-static").forEach(Ie=>{var Oe;(Oe=Ie==null?void 0:Ie.parentNode)==null||Oe.removeChild(Ie)}),L.clear(),j){const Ie=t.getInteractions().getArray().find(Oe=>getUid(Oe)===getUid(j));Ie&&t.removeInteraction(Ie)}t.removeLayer($),g!=null&&g.parentNode&&g.parentNode.removeChild(g),le!=null&&le.parentNode&&le.parentNode.removeChild(le)};return{open:k,close:pe,deleteLine:Ce,setUnit:i,getState:()=>y.value}},computedDistance=(t,e)=>{const r=getLength(t);let i="";switch(e){case"m":i=`${Math.round(r*100)/100} m`;break;case"km":i=`${Math.round(r/1e3*100)/100} km`;break;case"nm":i=`${Math.round(r/1.852*100)/100} nm`;break}return i},useDrawPolygonManager=(t,e)=>{let n,r;const i=()=>{g(),changeCursor(t,"crosshair")},g=()=>{L(),le(),ue(),ie()};let y=null,k=null;const L=()=>{if(y&&k)return;const _e=new VectorSource,xe=new VectorLayer({source:_e,style:new Style({stroke:new Stroke({color:"#fbcc33",width:2})})});y=xe,k=_e,t.on("pointermove",V),t.addLayer(xe),t.on(["dblclick"],function(Ie){z&&(Ie.stopPropagation(),Ie.preventDefault())})};let $;const V=_e=>{if(_e.dragging)return;const xe=$?"单击继续,双击结束":"点击选择起点";de&&(de.innerHTML=xe,he.setPosition(_e.coordinate))};let z,re=!1;const ie=()=>{if(n){de!=null&&de.parentNode&&de.parentNode.removeChild(de);const _e=n.getGeometry();if(!_e)return;const xe=j(_e,"nm");oe&&(oe.innerHTML=`
|
|
204
|
+
`,y=document.createElement("div");return y.className="ship-overlay-selected",y.innerHTML=g,y},createLabelStyle=(t,e)=>{const{lon:n,lat:r,blinking:i}=e,g=createLabelElement(e);n&&r&&addOverlay(t,fromLonLat([n,r]),g,{...e,blinking:i})},createLabelElement=t=>{const e=document.createElement("div");e.className="ship-overlay-box",e.style.position="relative";const{lon:n,lat:r,blinking:i,blinkingColors:g,name:y}=t,k=vue.createVNode({setup(){return useShipOverlay({position:[n+.002,r+.002],selected:i,name:y,colors:g||[],existDevice:t==null?void 0:t.existDevice,existMobile:t==null?void 0:t.existMobile,existWaterGauge:t==null?void 0:t.existWaterGauge})}});return vue.render(k,e),e},getRightIcons=t=>{const e=[];return t.existDevice&&e.push(""),t.existMobile&&e.push(""),t.existWaterGauge&&e.push(""),e};function getRandomLineDirection(){const t=["left-top","left-middle","left-bottom","right-top","right-middle","right-bottom"];return t[Math.floor(Math.random()*t.length)]}const devicePixelRatio$1=window.devicePixelRatio||1;function generateBase64Icon(t,e,n="left-bottom",r=2){const i=document.createElement("canvas"),g=i.getContext("2d");if(!g)return"";const y=2,k=16,L=window.devicePixelRatio||1,$="500 12px Arial",V="14px map-iconfont";g.font=$;const re=g.measureText(t).width;g.font=V;const ie=e.map(Ue=>({width:g.measureText(getIconFont(Ue)).width,height:14})),j=ie.reduce((Ue,Et)=>Ue+Et.width,0),oe=(e.length-1)*r,ae=y+re+j+oe+y*2,le=y+16+y;let de,he,ue=0,pe=0,Ce=0,_e=0,xe=0,Ie=0;switch(de=k+ae,n){case"right-top":he=k+le,ue=0,pe=k+le,Ce=k,_e=0,xe=k,Ie=0;break;case"right-middle":he=le,ue=0,pe=le/2,Ce=k,_e=le/2,xe=k,Ie=0;break;case"right-bottom":he=k+le,ue=0,pe=0,Ce=k,_e=k,xe=k,Ie=k;break;case"left-top":he=k+le,ue=ae,pe=k,Ce=ae+k,_e=le+k,xe=0,Ie=0;break;case"left-middle":he=le,ue=ae,pe=le/2,Ce=ae+k,_e=le/2,xe=0,Ie=0;break;case"left-bottom":he=k+le,ue=ae,pe=le,Ce=ae+k,_e=0,xe=0,Ie=k;break}i.width=Math.round(de*L),i.height=Math.round(he*L),i.style.width=`${de}px`,i.style.height=`${he}px`,g.scale(L,L),g.clearRect(0,0,de,he),g.beginPath(),g.moveTo(ue,pe),g.lineTo(Ce,_e),g.strokeStyle="#FFF",g.lineWidth=1,g.stroke(),g.fillStyle="#FFF",g.fillRect(xe,Ie,ae,le),g.font=$,g.textBaseline="middle";const Oe=Ie+y+le/2;g.strokeStyle="#ffffff",g.lineWidth=1,g.strokeText(t,xe+y,Oe),g.fillStyle="#000000",g.fillText(t,xe+y,Oe),g.font=V,g.fillStyle="#3370ff";let Ve=xe+y+re+r;return e.forEach((Ue,Et)=>{const At=Ie+y+le/2;g.fillText(getIconFont(Ue),Ve,At),Ve+=ie[Et].width+r}),i.toDataURL("image/png")}const createLabelFeatureStyle=t=>{const{name:e,rightIcons:n,selected:r}=t.getProperties(),i=getRandomLineDirection(),g=generateBase64Icon(e,n,i);let y=[0,0];switch(i){case"right-top":y=[0,1];break;case"right-middle":y=[0,.5];break;case"right-bottom":y=[0,0];break;case"left-top":y=[1,1];break;case"left-middle":y=[1,.5];break;case"left-bottom":y=[1,0];break}return new Style({image:new Icon({src:g,anchor:y,displacement:[0,0],scale:1/devicePixelRatio$1,anchorXUnits:"fraction",anchorYUnits:"fraction"}),zIndex:r?100:10})},useShipManager=t=>{let e=null,n=null;const r=new VectorSource,i=new VectorImageLayer({source:r,className:"zh-map--ship-layer",renderBuffer:300,zIndex:101}),g=new VectorSource,y=new VectorLayer({source:g,className:"zh-map--ship-label-layer",zIndex:102,updateWhileInteracting:!1,updateWhileAnimating:!1,declutter:!0});t==null||t.addLayer(i),t==null||t.addLayer(y);let k="",L={},$={};const V=_e=>{if(!_e||!t)return;const xe=(n==null?void 0:n.id)||(e==null?void 0:e.get("id"));if(n){const Ie=_e.filter(Oe=>Oe.id===xe);Ie.length===0?_e.push(n):n=Ie[0]}ie(),j(!0),Ce(_e),re()},z=_e=>{var Fe;const xe=(n==null?void 0:n.id)||(e==null?void 0:e.get("id")),Ie=fromLonLat([_e==null?void 0:_e.lon,_e==null?void 0:_e.lat]),Oe=((Fe=$[_e.id])==null?void 0:Fe.blinkColors)||[],Ue=Oe[Oe.length-1]||_e.fill||"#04C900",Et=getShipDirectPath(_e),At=new Feature({geometry:new Point(Ie),shipData:_e,id:_e.id,name:_e.cnname||_e.enname||_e.id||"未命名船舶",selected:_e.id===xe,rightIcons:getRightIcons(_e),color:Ue,direct:Et,isHighlight:!1});return At.set("clickGeometry",new Circle(Ie)),At},re=async()=>{if(!n||!t)return;let xe=t.getOverlays().getArray().find(Ie=>Ie.get("class")=="ship-overlay-selected");if(console.log("selectedOverlay----------",xe),xe){const Ie=selectedShipElement(t,n);await xe.setElement(Ie),await xe.setPosition(fromLonLat([n.lon,n.lat]))}else xe=selectedShipStyle(t,n),xe&&t.addOverlay(xe);setTimeout(()=>{var Ie;xe&&((Ie=xe.get("element"))!=null&&Ie.parentElement)&&(xe.get("element").parentElement.style.display="block")},20)},ie=()=>{t&&r&&(r.clear(),g.clear(),j())},j=_e=>{const xe=t.getOverlays().getArray().filter(Ie=>Ie.get("class")=="zh-map-ship-overlay");if(xe&&xe.length>0){for(let Ie=0;Ie<xe.length;Ie++)if(!_e&&xe[Ie].get("class")!=="ship-overlay-selected"){const Oe=xe[Ie];Oe.setPosition(void 0),t.removeOverlay(Oe),Oe.dispose()}}},oe=(_e,xe)=>{L=_e,$=xe;const Ie=t.getOverlays().getArray(),Oe=r.getFeatures();for(const Ve in L){const Ue=L[Ve],Et=Ie.find(Fe=>Fe.getId()==="label-"+Ve),At=Oe.find(Fe=>Ve===Fe.get("id"));if(Et&&At){const Fe=xe[Ve].blinkColors,{shipData:$e,name:ze}=At==null?void 0:At.getProperties();At.set("color",Fe[Fe.length-1]||""),At.set("blinking",Ue);const qe={...$e,blinking:Ue,blinkingColors:Fe||[],name:ze+"("+xe[Ve].shipState+")"},Ne=Et.getElement(),kt=createLabelElement(qe);Ne&&Ne!==kt&&Et.setElement(kt)}}},ae=_e=>{if(!t)return;const xe=r.getFeatures(),Ie=g.getFeatures(),Oe=e?e.get("id"):"",Ve=xe.filter(Fe=>Fe.get("id")!==Oe),Ue=Ie==null?void 0:Ie.filter(Fe=>Fe.get("id")!==Oe),Et=new Map;_e.forEach(Fe=>{Et.set(Fe.id,!0)});const At=t.getOverlays().getArray();Ve.forEach(Fe=>{const $e=Fe.get("id");if(!Et.has($e))Fe.setStyle([]);else{const qe=Fe.getStyle();(qe==null?void 0:qe.length)==0&&Fe.setStyle(createShipStyle(t,Fe))}const ze=At.find(qe=>qe.getId()==="label-"+$e);ze&&ze.setPosition(void 0)}),Ue.forEach(Fe=>{const $e=Fe.get("id");if(!Et.has($e))Fe.setStyle([]);else{const ze=Fe.getStyle();(ze==null?void 0:ze.length)==0&&Fe.setStyle(createLabelFeatureStyle(Fe))}})},le=_e=>{if(_e){console.log("选中",_e);const xe=r.getFeatures().find(Oe=>Oe.get("id")===_e.id),Ie=g.getFeatures().find(Oe=>Oe.get("id")===_e.id);xe&&(e=xe),Ie&&Ie.set("selected",!0),n=_e,re()}else console.log("取消选中"),n=null,e=null,ue()},de=debounce((_e,xe,Ie)=>{if(_e){const Oe=_e.get("shipData"),Ve=_e.get("id");if(t.getTargetElement().style.cursor=Ve?"pointer":"",xe==="click"&&(le(Oe),Ie&&Ie(Ve)),xe==="hover"){k&&k!==Ve&&he(),k=Ve;const Ue=r.getFeatures().find(Et=>Et.get("id")===k);Ue==null||Ue.set("isHighlight",!0),Ue==null||Ue.setStyle(createShipStyle(t,Ue))}}else t.getTargetElement().style.cursor="",he()},10),he=()=>{const _e=k?r.getFeatures().find(xe=>xe.get("id")===k):null;k=null,_e==null||_e.set("isHighlight",!1),_e==null||_e.setStyle(createShipStyle(t,_e))},ue=()=>{try{const xe=t.getOverlays().getArray().find(Ie=>Ie.get("class")=="ship-overlay-selected");xe&&xe.setPosition(void 0)}catch(_e){console.log(_e)}},pe=_e=>{const xe=fromLonLat([_e==null?void 0:_e.lon,_e==null?void 0:_e.lat]),Ie=new Feature({geometry:new Point(xe),name:_e.cnname||_e.enname||_e.id||"未命名船舶",rightIcons:getRightIcons(_e),selected:(_e==null?void 0:_e.id)===(n==null?void 0:n.id),shipData:_e});Ie.set("id",_e.id);const Oe=createLabelFeatureStyle(Ie);return Ie.setStyle(Oe),Ie},Ce=_e=>{const xe=t.getView().getZoom();_e.forEach(Ie=>{const Oe=z(Ie);if(Oe.setStyle(createShipStyle(t,Oe)),r.addFeature(Oe),(n==null?void 0:n.id)==Ie.id||xe>=MAP_ZOOM.shipModelMin)if(L[Ie.id]){if(Ie.id&&$[Ie==null?void 0:Ie.id]){const Ve=$[Ie==null?void 0:Ie.id]||{},Ue=(Ve==null?void 0:Ve.blinkColors)||[],Et=(Ve==null?void 0:Ve.shipState)||"",At=(Ie.cnname||Ie.enname||Ie.id||"未命名船舶")+"("+Et+")",Fe={...Ie,name:At,blinking:L[Ie.id],blinkingColors:Ue||[]};createLabelStyle(t,Fe)}}else{const Ve=pe(Ie);g.addFeature(Ve)}})};return{render:V,selected:le,filter:ae,blinking:oe,clear:ie,handleShipMapEvent:de}},useLayerManager=t=>{const e=()=>t==null?void 0:t.getLayers(),n=vue.ref("vector"),r=()=>n.value,i=L=>{n.value=L;const $=e();$&&($==null||$.getArray().forEach(V=>{(V.className_==="vector"||V.className_==="satellite")&&V.setVisible(V.className_===L)}))},g=vue.ref(!1);return{getLayers:e,getGreenTileVisible:()=>g.value,setGreenTileVisible:L=>{if(L!==g.value){if(L){const $=e();if(!$.getArray().find(z=>z.className_==="greenTile")){const z=new TileLayer({source:new XYZ({url:BASE_MAP_LINK.greenTile}),visible:L,zIndex:2,className:"greenTile"});$.push(z)}}else{const $=e(),V=$.getArray().find(z=>z.className_==="greenTile");V&&$.remove(V)}g.value=L}},getShowLayerType:r,setShowLayerType:i}},usePropsManager=()=>{const t=vue.ref();return{setProps:r=>{t.value=r},getProps:()=>t.value}},usePositionManager=t=>{const e="zh-map-location-layer";let n,r,i=null,g=null;const y=j=>{if(!(!j||j.length===0)){if(r||(r=new VectorSource),r.clear(),g){const oe=j.find(ae=>ae.id===g.id);oe?g=oe:j.push(g)}j.forEach(oe=>{k(oe)}),n||(n=new VectorLayer({className:e,source:r,zIndex:100}),t==null||t.addLayer(n))}},k=j=>{const oe=t==null?void 0:t.getView().getZoom(),[ae,le]=j.latLon.split(","),de=new Feature({geometry:new Point(fromLonLat([Number(ae),Number(le)]))});de.setStyle(L(j,oe,j.id===(g==null?void 0:g.id))),de.set("loactionData",j),r.addFeature(de)},L=(j,oe,ae)=>{const le={image:new Icon({src:ae&&j.selectedPath||j.defaultPath,scale:.5*oe/10})};return j.name&&(le.text=new Text({text:j.name,font:"12px sans-serif",fill:new Fill({color:"#000000"}),backgroundFill:new Fill({color:"#FFFFFF"}),offsetY:30})),new Style(le)},$=()=>{if(i){const j=i.get("loactionData").id;r.getFeatures().forEach(oe=>{oe.get("loactionData").id!==j&&r.removeFeature(oe)})}else r.clear()},V=()=>{var le;const j=i.get("loactionData"),oe=(le=t==null?void 0:t.getView())==null?void 0:le.getZoom();r.getFeatures().forEach(de=>{de.get("loactionData").id===j.id&&(de==null||de.setStyle(L(j,oe,!1)))}),g=null,i=null},z=j=>{j?(re(),ie(j)):clearSelectedPort()},re=()=>{var j;if(i){const oe=i.get("loactionData"),ae=(j=t==null?void 0:t.getView())==null?void 0:j.getZoom();i.setStyle(L(oe,ae,!1))}},ie=j=>{const oe=r.getFeatures();g=j,i=oe.find(ae=>ae.get("loactionData").id===j.id)};return{render:y,selected:z,clearSelected:V,clear:$}},DrawEventType={DRAWSTART:"drawstart",DRAWEND:"drawend",DRAWABORT:"drawabort"};class DrawEvent extends BaseEvent{constructor(e,n){super(e),this.feature=n}}function getTraceTargets(t,e){const n=[];for(let r=0;r<e.length;++r){const g=e[r].getGeometry();appendGeometryTraceTargets(t,g,n)}return n}function getSquaredDistance(t,e){return squaredDistance$1(t[0],t[1],e[0],e[1])}function getCoordinate(t,e){const n=t.length;return e<0?t[e+n]:e>=n?t[e-n]:t[e]}function getCumulativeSquaredDistance(t,e,n){let r,i;e<n?(r=e,i=n):(r=n,i=e);const g=Math.ceil(r),y=Math.floor(i);if(g>y){const L=interpolateCoordinate(t,r),$=interpolateCoordinate(t,i);return getSquaredDistance(L,$)}let k=0;if(r<g){const L=interpolateCoordinate(t,r),$=getCoordinate(t,g);k+=getSquaredDistance(L,$)}if(y<i){const L=getCoordinate(t,y),$=interpolateCoordinate(t,i);k+=getSquaredDistance(L,$)}for(let L=g;L<y-1;++L){const $=getCoordinate(t,L),V=getCoordinate(t,L+1);k+=getSquaredDistance($,V)}return k}function appendGeometryTraceTargets(t,e,n){if(e instanceof LineString){appendTraceTarget(t,e.getCoordinates(),!1,n);return}if(e instanceof MultiLineString){const r=e.getCoordinates();for(let i=0,g=r.length;i<g;++i)appendTraceTarget(t,r[i],!1,n);return}if(e instanceof Polygon){const r=e.getCoordinates();for(let i=0,g=r.length;i<g;++i)appendTraceTarget(t,r[i],!0,n);return}if(e instanceof MultiPolygon){const r=e.getCoordinates();for(let i=0,g=r.length;i<g;++i){const y=r[i];for(let k=0,L=y.length;k<L;++k)appendTraceTarget(t,y[k],!0,n)}return}if(e instanceof GeometryCollection){const r=e.getGeometries();for(let i=0;i<r.length;++i)appendGeometryTraceTargets(t,r[i],n);return}}const sharedUpdateInfo={index:-1,endIndex:NaN};function getTraceTargetUpdate(t,e,n,r){const i=t[0],g=t[1];let y=1/0,k=-1,L=NaN;for(let z=0;z<e.targets.length;++z){const re=e.targets[z],ie=re.coordinates;let j=1/0,oe;for(let ae=0;ae<ie.length-1;++ae){const le=ie[ae],de=ie[ae+1],he=getPointSegmentRelationship(i,g,le,de);he.squaredDistance<j&&(j=he.squaredDistance,oe=ae+he.along)}j<y&&(y=j,re.ring&&e.targetIndex===z&&(re.endIndex>re.startIndex?oe<re.startIndex&&(oe+=ie.length):re.endIndex<re.startIndex&&oe>re.startIndex&&(oe-=ie.length)),L=oe,k=z)}const $=e.targets[k];let V=$.ring;if(e.targetIndex===k&&V){const z=interpolateCoordinate($.coordinates,L),re=n.getPixelFromCoordinate(z);distance(re,e.startPx)>r&&(V=!1)}if(V){const z=$.coordinates,re=z.length,ie=$.startIndex,j=L;if(ie<j){const oe=getCumulativeSquaredDistance(z,ie,j);getCumulativeSquaredDistance(z,ie,j-re)<oe&&(L-=re)}else{const oe=getCumulativeSquaredDistance(z,ie,j);getCumulativeSquaredDistance(z,ie,j+re)<oe&&(L+=re)}}return sharedUpdateInfo.index=k,sharedUpdateInfo.endIndex=L,sharedUpdateInfo}function appendTraceTarget(t,e,n,r){const i=t[0],g=t[1];for(let y=0,k=e.length-1;y<k;++y){const L=e[y],$=e[y+1],V=getPointSegmentRelationship(i,g,L,$);if(V.squaredDistance===0){const z=y+V.along;r.push({coordinates:e,ring:n,startIndex:z,endIndex:z});return}}}const sharedRel={along:0,squaredDistance:0};function getPointSegmentRelationship(t,e,n,r){const i=n[0],g=n[1],y=r[0],k=r[1],L=y-i,$=k-g;let V=0,z=i,re=g;return(L!==0||$!==0)&&(V=clamp(((t-i)*L+(e-g)*$)/(L*L+$*$),0,1),z+=L*V,re+=$*V),sharedRel.along=V,sharedRel.squaredDistance=toFixed(squaredDistance$1(t,e,z,re),10),sharedRel}function interpolateCoordinate(t,e){const n=t.length;let r=Math.floor(e);const i=e-r;r>=n?r-=n:r<0&&(r+=n);let g=r+1;g>=n&&(g-=n);const y=t[r],k=y[0],L=y[1],$=t[g],V=$[0]-k,z=$[1]-L;return[k+V*i,L+z*i]}class Draw extends PointerInteraction{constructor(e){const n=e;n.stopDown||(n.stopDown=FALSE),super(n),this.on,this.once,this.un,this.shouldHandle_=!1,this.downPx_=null,this.downTimeout_,this.lastDragTime_,this.pointerType_,this.freehand_=!1,this.source_=e.source?e.source:null,this.features_=e.features?e.features:null,this.snapTolerance_=e.snapTolerance?e.snapTolerance:12,this.type_=e.type,this.mode_=getMode(this.type_),this.stopClick_=!!e.stopClick,this.minPoints_=e.minPoints?e.minPoints:this.mode_==="Polygon"?3:2,this.maxPoints_=this.mode_==="Circle"?2:e.maxPoints?e.maxPoints:1/0,this.finishCondition_=e.finishCondition?e.finishCondition:TRUE,this.geometryLayout_=e.geometryLayout?e.geometryLayout:"XY";let r=e.geometryFunction;if(!r){const i=this.mode_;if(i==="Circle")r=(g,y,k)=>{const L=y||new Circle([NaN,NaN]),$=fromUserCoordinate(g[0]),V=squaredDistance($,fromUserCoordinate(g[g.length-1]));return L.setCenterAndRadius($,Math.sqrt(V),this.geometryLayout_),L};else{let g;i==="Point"?g=Point:i==="LineString"?g=LineString:i==="Polygon"&&(g=Polygon),r=(y,k,L)=>(k?i==="Polygon"?y[0].length?k.setCoordinates([y[0].concat([y[0][0]])],this.geometryLayout_):k.setCoordinates([],this.geometryLayout_):k.setCoordinates(y,this.geometryLayout_):k=new g(y,this.geometryLayout_),k)}}this.geometryFunction_=r,this.dragVertexDelay_=e.dragVertexDelay!==void 0?e.dragVertexDelay:500,this.finishCoordinate_=null,this.sketchFeature_=null,this.sketchPoint_=null,this.sketchCoords_=null,this.sketchLine_=null,this.sketchLineCoords_=null,this.squaredClickTolerance_=e.clickTolerance?e.clickTolerance*e.clickTolerance:36,this.overlay_=new VectorLayer({source:new VectorSource({useSpatialIndex:!1,wrapX:e.wrapX?e.wrapX:!1}),style:e.style?e.style:getDefaultStyleFunction(),updateWhileInteracting:!0}),this.geometryName_=e.geometryName,this.condition_=e.condition?e.condition:noModifierKeys,this.freehandCondition_,e.freehand?this.freehandCondition_=always:this.freehandCondition_=e.freehandCondition?e.freehandCondition:shiftKeyOnly,this.traceCondition_,this.setTrace(e.trace||!1),this.traceState_={active:!1},this.traceSource_=e.traceSource||e.source||null,this.addChangeListener(InteractionProperty.ACTIVE,this.updateState_)}setTrace(e){let n;e?e===!0?n=always:n=e:n=never,this.traceCondition_=n}setMap(e){super.setMap(e),this.updateState_()}getOverlay(){return this.overlay_}handleEvent(e){e.originalEvent.type===EventType.CONTEXTMENU&&e.originalEvent.preventDefault(),this.freehand_=this.mode_!=="Point"&&this.freehandCondition_(e);let n=e.type===MapBrowserEventType.POINTERMOVE,r=!0;return!this.freehand_&&this.lastDragTime_&&e.type===MapBrowserEventType.POINTERDRAG&&(Date.now()-this.lastDragTime_>=this.dragVertexDelay_?(this.downPx_=e.pixel,this.shouldHandle_=!this.freehand_,n=!0):this.lastDragTime_=void 0,this.shouldHandle_&&this.downTimeout_!==void 0&&(clearTimeout(this.downTimeout_),this.downTimeout_=void 0)),this.freehand_&&e.type===MapBrowserEventType.POINTERDRAG&&this.sketchFeature_!==null?(this.addToDrawing_(e.coordinate),r=!1):this.freehand_&&e.type===MapBrowserEventType.POINTERDOWN?r=!1:n&&this.getPointerCount()<2?(r=e.type===MapBrowserEventType.POINTERMOVE,r&&this.freehand_?(this.handlePointerMove_(e),this.shouldHandle_&&e.originalEvent.preventDefault()):(e.originalEvent.pointerType==="mouse"||e.type===MapBrowserEventType.POINTERDRAG&&this.downTimeout_===void 0)&&this.handlePointerMove_(e)):e.type===MapBrowserEventType.DBLCLICK&&(r=!1),super.handleEvent(e)&&r}handleDownEvent(e){return this.shouldHandle_=!this.freehand_,this.freehand_?(this.downPx_=e.pixel,this.finishCoordinate_||this.startDrawing_(e.coordinate),!0):this.condition_(e)?(this.lastDragTime_=Date.now(),this.downTimeout_=setTimeout(()=>{this.handlePointerMove_(new MapBrowserEvent(MapBrowserEventType.POINTERMOVE,e.map,e.originalEvent,!1,e.frameState))},this.dragVertexDelay_),this.downPx_=e.pixel,!0):(this.lastDragTime_=void 0,!1)}deactivateTrace_(){this.traceState_={active:!1}}toggleTraceState_(e){if(!this.traceSource_||!this.traceCondition_(e))return;if(this.traceState_.active){this.deactivateTrace_();return}const n=this.getMap(),r=n.getCoordinateFromPixel([e.pixel[0]-this.snapTolerance_,e.pixel[1]+this.snapTolerance_]),i=n.getCoordinateFromPixel([e.pixel[0]+this.snapTolerance_,e.pixel[1]-this.snapTolerance_]),g=boundingExtent([r,i]),y=this.traceSource_.getFeaturesInExtent(g);if(y.length===0)return;const k=getTraceTargets(e.coordinate,y);k.length&&(this.traceState_={active:!0,startPx:e.pixel.slice(),targets:k,targetIndex:-1})}addOrRemoveTracedCoordinates_(e,n){const r=e.startIndex<=e.endIndex,i=e.startIndex<=n;r===i?r&&n>e.endIndex||!r&&n<e.endIndex?this.addTracedCoordinates_(e,e.endIndex,n):(r&&n<e.endIndex||!r&&n>e.endIndex)&&this.removeTracedCoordinates_(n,e.endIndex):(this.removeTracedCoordinates_(e.startIndex,e.endIndex),this.addTracedCoordinates_(e,e.startIndex,n))}removeTracedCoordinates_(e,n){if(e===n)return;let r=0;if(e<n){const i=Math.ceil(e);let g=Math.floor(n);g===n&&(g-=1),r=g-i+1}else{const i=Math.floor(e);let g=Math.ceil(n);g===n&&(g+=1),r=i-g+1}r>0&&this.removeLastPoints_(r)}addTracedCoordinates_(e,n,r){if(n===r)return;const i=[];if(n<r){const g=Math.ceil(n);let y=Math.floor(r);y===r&&(y-=1);for(let k=g;k<=y;++k)i.push(getCoordinate(e.coordinates,k))}else{const g=Math.floor(n);let y=Math.ceil(r);y===r&&(y+=1);for(let k=g;k>=y;--k)i.push(getCoordinate(e.coordinates,k))}i.length&&this.appendCoordinates(i)}updateTrace_(e){const n=this.traceState_;if(!n.active||n.targetIndex===-1&&distance(n.startPx,e.pixel)<this.snapTolerance_)return;const r=getTraceTargetUpdate(e.coordinate,n,this.getMap(),this.snapTolerance_);if(n.targetIndex!==r.index){if(n.targetIndex!==-1){const L=n.targets[n.targetIndex];this.removeTracedCoordinates_(L.startIndex,L.endIndex)}const k=n.targets[r.index];this.addTracedCoordinates_(k,k.startIndex,r.endIndex)}else{const k=n.targets[n.targetIndex];this.addOrRemoveTracedCoordinates_(k,r.endIndex)}n.targetIndex=r.index;const i=n.targets[n.targetIndex];i.endIndex=r.endIndex;const g=interpolateCoordinate(i.coordinates,i.endIndex),y=this.getMap().getPixelFromCoordinate(g);e.coordinate=g,e.pixel=[Math.round(y[0]),Math.round(y[1])]}handleUpEvent(e){let n=!0;if(this.getPointerCount()===0){this.downTimeout_&&(clearTimeout(this.downTimeout_),this.downTimeout_=void 0),this.handlePointerMove_(e);const r=this.traceState_.active;if(this.toggleTraceState_(e),this.shouldHandle_){const i=!this.finishCoordinate_;i&&this.startDrawing_(e.coordinate),!i&&this.freehand_?this.finishDrawing():!this.freehand_&&(!i||this.mode_==="Point")&&(this.atFinish_(e.pixel,r)?this.finishCondition_(e)&&this.finishDrawing():this.addToDrawing_(e.coordinate)),n=!1}else this.freehand_&&this.abortDrawing()}return!n&&this.stopClick_&&e.preventDefault(),n}handlePointerMove_(e){if(this.pointerType_=e.originalEvent.pointerType,this.downPx_&&(!this.freehand_&&this.shouldHandle_||this.freehand_&&!this.shouldHandle_)){const n=this.downPx_,r=e.pixel,i=n[0]-r[0],g=n[1]-r[1],y=i*i+g*g;if(this.shouldHandle_=this.freehand_?y>this.squaredClickTolerance_:y<=this.squaredClickTolerance_,!this.shouldHandle_)return}if(!this.finishCoordinate_){this.createOrUpdateSketchPoint_(e.coordinate.slice());return}this.updateTrace_(e),this.modifyDrawing_(e.coordinate)}atFinish_(e,n){let r=!1;if(this.sketchFeature_){let i=!1,g=[this.finishCoordinate_];const y=this.mode_;if(y==="Point")r=!0;else if(y==="Circle")r=this.sketchCoords_.length===2;else if(y==="LineString")i=!n&&this.sketchCoords_.length>this.minPoints_;else if(y==="Polygon"){const k=this.sketchCoords_;i=k[0].length>this.minPoints_,g=[k[0][0],k[0][k[0].length-2]],n?g=[k[0][0]]:g=[k[0][0],k[0][k[0].length-2]]}if(i){const k=this.getMap();for(let L=0,$=g.length;L<$;L++){const V=g[L],z=k.getPixelFromCoordinate(V),re=e[0]-z[0],ie=e[1]-z[1],j=this.freehand_?1:this.snapTolerance_;if(r=Math.sqrt(re*re+ie*ie)<=j,r){this.finishCoordinate_=V;break}}}}return r}createOrUpdateSketchPoint_(e){this.sketchPoint_?this.sketchPoint_.getGeometry().setCoordinates(e):(this.sketchPoint_=new Feature(new Point(e)),this.updateSketchFeatures_())}createOrUpdateCustomSketchLine_(e){this.sketchLine_||(this.sketchLine_=new Feature);const n=e.getLinearRing(0);let r=this.sketchLine_.getGeometry();r?(r.setFlatCoordinates(n.getLayout(),n.getFlatCoordinates()),r.changed()):(r=new LineString(n.getFlatCoordinates(),n.getLayout()),this.sketchLine_.setGeometry(r))}startDrawing_(e){const n=this.getMap().getView().getProjection(),r=getStrideForLayout(this.geometryLayout_);for(;e.length<r;)e.push(0);this.finishCoordinate_=e,this.mode_==="Point"?this.sketchCoords_=e.slice():this.mode_==="Polygon"?(this.sketchCoords_=[[e.slice(),e.slice()]],this.sketchLineCoords_=this.sketchCoords_[0]):this.sketchCoords_=[e.slice(),e.slice()],this.sketchLineCoords_&&(this.sketchLine_=new Feature(new LineString(this.sketchLineCoords_)));const i=this.geometryFunction_(this.sketchCoords_,void 0,n);this.sketchFeature_=new Feature,this.geometryName_&&this.sketchFeature_.setGeometryName(this.geometryName_),this.sketchFeature_.setGeometry(i),this.updateSketchFeatures_(),this.dispatchEvent(new DrawEvent(DrawEventType.DRAWSTART,this.sketchFeature_))}modifyDrawing_(e){const n=this.getMap(),r=this.sketchFeature_.getGeometry(),i=n.getView().getProjection(),g=getStrideForLayout(this.geometryLayout_);let y,k;for(;e.length<g;)e.push(0);this.mode_==="Point"?k=this.sketchCoords_:this.mode_==="Polygon"?(y=this.sketchCoords_[0],k=y[y.length-1],this.atFinish_(n.getPixelFromCoordinate(e))&&(e=this.finishCoordinate_.slice())):(y=this.sketchCoords_,k=y[y.length-1]),k[0]=e[0],k[1]=e[1],this.geometryFunction_(this.sketchCoords_,r,i),this.sketchPoint_&&this.sketchPoint_.getGeometry().setCoordinates(e),r.getType()==="Polygon"&&this.mode_!=="Polygon"?this.createOrUpdateCustomSketchLine_(r):this.sketchLineCoords_&&this.sketchLine_.getGeometry().setCoordinates(this.sketchLineCoords_),this.updateSketchFeatures_()}addToDrawing_(e){const n=this.sketchFeature_.getGeometry(),r=this.getMap().getView().getProjection();let i,g;const y=this.mode_;return y==="LineString"||y==="Circle"?(this.finishCoordinate_=e.slice(),g=this.sketchCoords_,g.length>=this.maxPoints_&&(this.freehand_?g.pop():i=!0),g.push(e.slice()),this.geometryFunction_(g,n,r)):y==="Polygon"&&(g=this.sketchCoords_[0],g.length>=this.maxPoints_&&(this.freehand_?g.pop():i=!0),g.push(e.slice()),i&&(this.finishCoordinate_=g[0]),this.geometryFunction_(this.sketchCoords_,n,r)),this.createOrUpdateSketchPoint_(e.slice()),this.updateSketchFeatures_(),i?this.finishDrawing():this.sketchFeature_}removeLastPoints_(e){if(!this.sketchFeature_)return;const n=this.sketchFeature_.getGeometry(),r=this.getMap().getView().getProjection(),i=this.mode_;for(let g=0;g<e;++g){let y;if(i==="LineString"||i==="Circle"){if(y=this.sketchCoords_,y.splice(-2,1),y.length>=2){this.finishCoordinate_=y[y.length-2].slice();const k=this.finishCoordinate_.slice();y[y.length-1]=k,this.createOrUpdateSketchPoint_(k)}this.geometryFunction_(y,n,r),n.getType()==="Polygon"&&this.sketchLine_&&this.createOrUpdateCustomSketchLine_(n)}else if(i==="Polygon"){y=this.sketchCoords_[0],y.splice(-2,1);const k=this.sketchLine_.getGeometry();if(y.length>=2){const L=y[y.length-2].slice();y[y.length-1]=L,this.createOrUpdateSketchPoint_(L)}k.setCoordinates(y),this.geometryFunction_(this.sketchCoords_,n,r)}if(y.length===1){this.abortDrawing();break}}this.updateSketchFeatures_()}removeLastPoint(){this.removeLastPoints_(1)}finishDrawing(){const e=this.abortDrawing_();if(!e)return null;let n=this.sketchCoords_;const r=e.getGeometry(),i=this.getMap().getView().getProjection();return this.mode_==="LineString"?(n.pop(),this.geometryFunction_(n,r,i)):this.mode_==="Polygon"&&(n[0].pop(),this.geometryFunction_(n,r,i),n=r.getCoordinates()),this.type_==="MultiPoint"?e.setGeometry(new MultiPoint([n])):this.type_==="MultiLineString"?e.setGeometry(new MultiLineString([n])):this.type_==="MultiPolygon"&&e.setGeometry(new MultiPolygon([n])),this.dispatchEvent(new DrawEvent(DrawEventType.DRAWEND,e)),this.features_&&this.features_.push(e),this.source_&&this.source_.addFeature(e),e}abortDrawing_(){this.finishCoordinate_=null;const e=this.sketchFeature_;return this.sketchFeature_=null,this.sketchPoint_=null,this.sketchLine_=null,this.overlay_.getSource().clear(!0),this.deactivateTrace_(),e}abortDrawing(){const e=this.abortDrawing_();e&&this.dispatchEvent(new DrawEvent(DrawEventType.DRAWABORT,e))}appendCoordinates(e){const n=this.mode_,r=!this.sketchFeature_;r&&this.startDrawing_(e[0]);let i;if(n==="LineString"||n==="Circle")i=this.sketchCoords_;else if(n==="Polygon")i=this.sketchCoords_&&this.sketchCoords_.length?this.sketchCoords_[0]:[];else return;r&&i.shift(),i.pop();for(let y=0;y<e.length;y++)this.addToDrawing_(e[y]);const g=e[e.length-1];this.sketchFeature_=this.addToDrawing_(g),this.modifyDrawing_(g)}extend(e){const r=e.getGeometry();this.sketchFeature_=e,this.sketchCoords_=r.getCoordinates();const i=this.sketchCoords_[this.sketchCoords_.length-1];this.finishCoordinate_=i.slice(),this.sketchCoords_.push(i.slice()),this.sketchPoint_=new Feature(new Point(i)),this.updateSketchFeatures_(),this.dispatchEvent(new DrawEvent(DrawEventType.DRAWSTART,this.sketchFeature_))}updateSketchFeatures_(){const e=[];this.sketchFeature_&&e.push(this.sketchFeature_),this.sketchLine_&&e.push(this.sketchLine_),this.sketchPoint_&&e.push(this.sketchPoint_);const n=this.overlay_.getSource();n.clear(!0),n.addFeatures(e)}updateState_(){const e=this.getMap(),n=this.getActive();(!e||!n)&&this.abortDrawing(),this.overlay_.setMap(n?e:null)}}function getDefaultStyleFunction(){const t=createEditingStyle();return function(e,n){return t[e.getGeometry().getType()]}}function getMode(t){switch(t){case"Point":case"MultiPoint":return"Point";case"LineString":case"MultiLineString":return"LineString";case"Polygon":case"MultiPolygon":return"Polygon";case"Circle":return"Circle";default:throw new Error("Invalid type: "+t)}}const disableDoubleClickZoom=t=>{t.getInteractions().forEach(e=>{e instanceof DoubleClickZoom&&e.setActive(!1)})},enableDoubleClickZoom=t=>{t.getInteractions().forEach(e=>{e instanceof DoubleClickZoom&&e.setActive(!0)})},changeCursor=(t,e)=>{const n=t.getViewport();n&&(n.style.cursor=e)},useDrawLineManager=(t,e)=>{const n=vue.ref([]),r=vue.ref("km"),i=Ie=>{r.value=Ie};let g;const y=vue.ref(!1),k=()=>{V(),disableDoubleClickZoom(t),changeCursor(t,"crosshair"),t.on("pointermove",ie),t.getViewport().addEventListener("mouseout",()=>{g&&g.classList.add("hidden")}),oe(),y.value=!0};let L,$;const V=()=>{L=new VectorSource,$=new VectorLayer({source:L,zIndex:1e3,style:{"fill-color":"rgba(255, 255, 255, 0.2)","stroke-color":"#ffcc33","stroke-width":2,"circle-radius":7,"circle-fill-color":"#ffcc33"}}),t==null||t.addLayer($)};let z,re;const ie=Ie=>{if(Ie.dragging)return;let Oe="点击选择起点";z&&(Oe="单击继续,双击结束"),g&&(g.innerHTML=Oe,re.setPosition(Ie.coordinate),g.classList.remove("hidden"))};let j;const oe=()=>{j=new Draw({source:L,type:"LineString",style:new Style({fill:new Fill({color:"rgba(255, 255, 255, 0.2)"}),stroke:new Stroke({color:"rgba(255,204,51)",lineDash:[10,10],width:2}),image:new CircleStyle({radius:5,stroke:new Stroke({color:"rgba(0, 0, 0, 0.7)"}),fill:new Fill({color:"rgba(255, 255, 255, 0.2)"})})}),condition:Oe=>Oe.originalEvent.target.tagName!=="DIV"}),t==null||t.addInteraction(j),he(),ue();let Ie;j.on("drawstart",function(Oe){var Ue;z=Oe.feature,z.set("randomId",ae());let Ve;Ie=(Ue=z.getGeometry())==null?void 0:Ue.on("change",function(Et){const At=Et.target,Fe=computedDistance(At,r.value);Ve=At.getLastCoordinate(),le&&Fe&&(le.innerHTML=Fe),de.setPosition(Ve)})}),j.on("drawend",function(){var Oe,Ve,Ue;if(le&&(le.className="ol-tooltip ol-tooltip-static ol-tooltip-measure"),le!=null&&le.innerHTML){const Et=(z==null?void 0:z.get("randomId"))||ae();n.value.push({id:Et,value:le==null?void 0:le.innerHTML}),le.innerHTML=`${le.innerHTML}<div class="ol-tooltip-delete-button" data-id="${Et}"><i class="map-iconfont icon-delete"></i></div>`}(Oe=document.querySelector(".ol-selectable:has(.ol-tooltip-delete-button):last-child .ol-tooltip-delete-button"))==null||Oe.addEventListener("click",Et=>{var Fe;Et.preventDefault(),Et.stopPropagation();const At=(Fe=Et.target)==null?void 0:Fe.getAttribute("data-id");At&&Ce(At)}),de.setOffset([0,-7]),z=null,le=null,he(),Ie&&unByKey(Ie),(Ue=(Ve=e.getProps())==null?void 0:Ve.lineDrawEnd)==null||Ue.call(Ve,n.value)})},ae=()=>Math.random().toString(36).substring(2,9);let le,de;const he=()=>{le!=null&&le.parentNode&&le.parentNode.removeChild(le),le=document.createElement("div"),le.className="ol-tooltip ol-tooltip-measure",de=new Overlay({element:le,offset:[0,-15],positioning:"bottom-center",stopEvent:!1,insertFirst:!1}),t==null||t.addOverlay(de)},ue=()=>{g!=null&&g.parentNode&&g.parentNode.removeChild(g),g=document.createElement("div"),g.className="ol-tooltip hidden",re=new Overlay({element:g,offset:[15,0],positioning:"center-left"}),t==null||t.addOverlay(re)},pe=()=>{n.value.forEach((Ie,Oe)=>{var Et,At;const Ve=document.querySelectorAll(".ol-tooltip.ol-tooltip-static.ol-tooltip-measure");Ve[Oe]&&((At=(Et=Ve[Oe])==null?void 0:Et.parentNode)==null||At.removeChild(Ve[Oe]));const Ue=L.getFeatures();Ue[Oe]&&L.removeFeature(Ue[Oe])}),_e(),enableDoubleClickZoom(t),y.value=!1,changeCursor(t,"pointer")},Ce=Ie=>{var Ve,Ue,Et,At;const Oe=n.value.findIndex(Fe=>Fe.id===Ie);if(Oe!==-1){n.value.splice(Oe,1);const Fe=document.querySelectorAll(".ol-tooltip.ol-tooltip-static.ol-tooltip-measure");Fe[Oe]&&((Ue=(Ve=Fe[Oe])==null?void 0:Ve.parentNode)==null||Ue.removeChild(Fe[Oe]));const $e=L.getFeatures();$e[Oe]&&L.removeFeature($e[Oe])}(At=(Et=e.getProps())==null?void 0:Et.lineDrawEnd)==null||At.call(Et,n.value)},_e=()=>{if(n.value=[],document.querySelectorAll(".ol-tooltip.ol-tooltip-static").forEach(Ie=>{var Oe;(Oe=Ie==null?void 0:Ie.parentNode)==null||Oe.removeChild(Ie)}),L.clear(),j){const Ie=t.getInteractions().getArray().find(Oe=>getUid(Oe)===getUid(j));Ie&&t.removeInteraction(Ie)}t.removeLayer($),g!=null&&g.parentNode&&g.parentNode.removeChild(g),le!=null&&le.parentNode&&le.parentNode.removeChild(le)};return{open:k,close:pe,deleteLine:Ce,setUnit:i,getState:()=>y.value}},computedDistance=(t,e)=>{const r=getLength(t);let i="";switch(e){case"m":i=`${Math.round(r*100)/100} m`;break;case"km":i=`${Math.round(r/1e3*100)/100} km`;break;case"nm":i=`${Math.round(r/1.852*100)/100} nm`;break}return i},useDrawPolygonManager=(t,e)=>{let n,r;const i=()=>{g(),changeCursor(t,"crosshair")},g=()=>{L(),le(),ue(),ie()};let y=null,k=null;const L=()=>{if(y&&k)return;const _e=new VectorSource,xe=new VectorLayer({source:_e,style:new Style({stroke:new Stroke({color:"#fbcc33",width:2})})});y=xe,k=_e,t.on("pointermove",V),t.addLayer(xe),t.on(["dblclick"],function(Ie){z&&(Ie.stopPropagation(),Ie.preventDefault())})};let $;const V=_e=>{if(_e.dragging)return;const xe=$?"单击继续,双击结束":"点击选择起点";de&&(de.innerHTML=xe,he.setPosition(_e.coordinate))};let z,re=!1;const ie=()=>{if(n){de!=null&&de.parentNode&&de.parentNode.removeChild(de);const _e=n.getGeometry();if(!_e)return;const xe=j(_e,"nm");oe&&(oe.innerHTML=`
|
|
205
205
|
<span class="text">面积:${xe}${re?'<span class="error pl-12">超出可以绘画的距离</span>':""}</span>
|
|
206
206
|
`),oe&&(oe.innerHTML+='<span class="delete-icon" ><i class="map-iconfont icon-delete" /></div>');const Ie=_e.getCoordinates(),Oe=Ie[0][Ie[0].length-2];if(ae.setPosition(Oe),y){const Ue=y.getSource();Ue&&n&&(Ue.clear(),Ue.addFeature(n))}setTimeout(()=>{var Ue;(Ue=document.querySelector(".delete-icon"))==null||Ue.addEventListener("click",()=>{var Et,At;console.log("delete"),pe(),(At=(Et=e.getProps())==null?void 0:Et.areaDrawEnd)==null||At.call(Et,[])})},0);const Ve=getCenter(n.getGeometry().getExtent());t==null||t.getView().setCenter(Ve);return}z=new Draw({type:"Polygon",source:k,trace:!0,style:[new Style({stroke:new Stroke({color:"rgba(255, 255, 255, 1)",width:1.5,lineDash:[10,10]}),fill:new Fill({color:"rgba(255, 255, 255, 0.25)"})}),new Style({image:new CircleStyle({radius:5,fill:new Fill({color:"rgb(51,112,255, 1)"})}),geometry:function(_e){const xe=_e.getGeometry().getCoordinates();return new MultiPoint(xe)}})]}),t==null||t.addInteraction(z),z.on("drawstart",_e=>{var xe;$=_e.feature,r=(xe=$.getGeometry())==null?void 0:xe.on("change",Ie=>{const Oe=Ie.target,Ve=j(Oe,"nm"),Et=Oe.getCoordinates()[0],At=new LineString([Et[Et.length-2],Et[Et.length-1]]),Fe=computedDistance(At,"nm");if(re=Number(getLength(At)/1e3)>150,!Ve)return;const $e='<span class="error pl-4">超出可以绘画的距离</span>';oe&&(oe.innerHTML=`
|
|
207
207
|
<div class="text">
|