bbl-mapbox-react 0.0.20 → 0.0.22
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/components/CanvasImageRenderer.d.ts +1 -1
- package/dist/components/CircleRenderer.d.ts +1 -1
- package/dist/components/PolygonRenderer.d.ts +1 -1
- package/dist/components/PolylineRenderer.d.ts +1 -1
- package/dist/components/RectangleRenderer.d.ts +1 -1
- package/dist/components/SquareRenderer.d.ts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.css +1 -1
- package/dist/index.mjs +164 -149
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`react`);c=s(c);let l=require(`mapbox-gl`);l=s(l);let u=require(`@turf/turf`);u=s(u);let d=require(`react-dom/client`);d=s(d);let f=require(`react-dom`);f=s(f);let p=require(`react/jsx-runtime`);p=s(p);let m=require(`@arco-design/web-react`);m=s(m);const h={fillColor:`#ffffff`,fillOpacity:1,strokeColor:`rgba(0, 0, 0, 0.8)`,strokeWidth:1,strokeOpacity:1},g={fillColor:`#ffcc00`,fillOpacity:1,strokeColor:`#ff6600`,strokeWidth:2,strokeOpacity:1},_={fillColor:`#ffffff`,fillOpacity:1,strokeColor:`rgba(0, 0, 0, 0.8)`,strokeWidth:1,strokeOpacity:1},v={color:`#ffffff`,width:1,opacity:1,dashArray:[4,4]};function y(e,t,n=v){return{color:e?.color??t?.color??n.color,width:e?.width??t?.width??n.width,opacity:e?.opacity??t?.opacity??n.opacity,dashArray:e?.dashArray??t?.dashArray??n.dashArray}}const b={fillColor:`#ffffff`,fillOpacity:1,strokeColor:`rgba(0, 0, 0, 0.8)`,strokeWidth:1,strokeOpacity:1};function x(e,t,n=h){return{fillColor:e?.fillColor??t?.fillColor??n.fillColor,fillOpacity:e?.fillOpacity??t?.fillOpacity??n.fillOpacity,strokeColor:e?.strokeColor??t?.strokeColor??n.strokeColor,strokeWidth:e?.strokeWidth??t?.strokeWidth??n.strokeWidth,strokeOpacity:e?.strokeOpacity??t?.strokeOpacity??n.strokeOpacity}}function S(e,t){if(!t)return e;let n={...e};return(n.type===`circle`||n.type===`square`||n.type===`rectangle`||n.type===`polygon`)&&n.showArea===void 0&&(n.showArea=t.showArea),(n.type===`square`||n.type===`rectangle`||n.type===`polygon`||n.type===`polyline`)&&n.showLength===void 0&&(n.showLength=t.showLength),n.type===`circle`&&n.showRadius===void 0&&(n.showRadius=t.showRadius),n}const C={blue:{center:`#4285f4`,edge:`#4285f400`,mid:`#1a73e8`},green:{center:`#34a853`,edge:`#34a85300`,mid:`#0d652d`},red:{center:`#ea4335`,edge:`#ea433500`,mid:`#c5221f`},purple:{center:`#9c27b0`,edge:`#9c27b000`,mid:`#6a1b9a`},cyan:{center:`#00bcd4`,edge:`#00bcd400`,mid:`#00838f`},orange:{center:`#ff9800`,edge:`#ff980000`,mid:`#f57c00`}},w={rotationSpeed:1,initialRotation:0,colorScheme:`green`,opacity:70,gradientType:`conical`,showRings:!0,showCenter:!0,showScanLine:!0},T={trigger:`click`,position:`top`,offset:[0,-10],showCloseButton:!0,animation:`fade`,closeOnClickOutside:!0,closeOnEscape:!0,hoverDelay:300,maxWidth:320,zIndex:1e3},E=[{class:`motorway`,label:`高速公路`,color:`#E84E3C`},{class:`trunk`,label:`国道`,color:`#FF8C00`},{class:`primary`,label:`主干道`,color:`#FFD700`},{class:`secondary`,label:`次干道`,color:`#4CAF50`},{class:`tertiary`,label:`三级道路`,color:`#2196F3`},{class:`motorway_link`,label:`高速匝道`,color:`#FF6B6B`},{class:`trunk_link`,label:`国道匝道`,color:`#FFB84D`},{class:`primary_link`,label:`主干道匝道`,color:`#FFE066`},{class:`secondary_link`,label:`次干道匝道`,color:`#66BB6A`},{class:`tertiary_link`,label:`三级道路匝道`,color:`#42A5F5`},{class:`minor`,label:`小路`,color:`#81C784`},{class:`residential`,label:`居民区道路`,color:`#81C784`},{class:`unclassified`,label:`未分类道路`,color:`#9E9E9E`},{class:`service`,label:`服务道路`,color:`#64B5F6`},{class:`track`,label:`土路`,color:`#A1887F`},{class:`path`,label:`小径`,color:`#BCAAA4`}];function D(e,t,n){let r=u.point(e);return u.destination(r,t/1e3,n,{units:`kilometers`}).geometry.coordinates}function O(e,t){return u.distance(u.point(e),u.point(t),{units:`kilometers`})*1e3}function k(e,t){return u.bearing(u.point(e),u.point(t))}function ee(e){let t=u.polygon([e]);return u.area(t)}function A(e){return e>=1e6?`${(e/1e6).toFixed(2)} km²`:`${e.toFixed(0)} m²`}function j(e){return e>=1e3?`${(e/1e3).toFixed(2)} km`:`${e.toFixed(0)} m`}const M=512,te=512/2,ne=512/2-2;function N(e){return e*Math.PI/180}function P(e=1){return .3+Math.max(0,Math.min(1,e))*.7}var re=class{constructor(e,t,n,r,i,a){this.isDestroyed=!1,this.isSelected=!1,this.map=e,this.entity=t,this.entityId=t.id,this.globalNameConfig=r,this.globalSelectNameConfig=i,this.globalAreaConfig=a,this.sourceId=`${n}-source-${String(t.id)}`,this.layerId=`${n}-layer-${String(t.id)}`,this.labelSourceId=`${n}-label-source-${String(t.id)}`,this.labelLayerId=`${n}-label-layer-${String(t.id)}`,this.areaSourceId=`${n}-area-source-${String(t.id)}`,this.areaLayerId=`${n}-area-layer-${String(t.id)}`,this.canvas=document.createElement(`canvas`),this.canvas.width=512,this.canvas.height=512,this.ctx=this.canvas.getContext(`2d`)}init(e){this.draw(),this.map.addSource(this.sourceId,{type:`canvas`,canvas:this.canvas,coordinates:e,animate:!0}),this.map.addLayer({id:this.layerId,type:`raster`,source:this.sourceId,paint:{"raster-fade-duration":0,"raster-opacity":1}}),this.initLabelLayer(),this.initAreaLayer()}get nameStyle(){return x(this.entity.nameConfig,this.globalNameConfig,h)}get selectNameStyle(){return x(this.entity.selectNameConfig,this.globalSelectNameConfig,g)}get areaStyle(){return x(`areaConfig`in this.entity?this.entity.areaConfig:void 0,this.globalAreaConfig,_)}getAreaLabelAnchor(){return{anchor:`center`,offset:[0,0]}}initLabelLayer(){let e=this.getEntityCenter(),{confidence:t}=this.entity,n=P(t);this.map.addSource(this.labelSourceId,{type:`geojson`,data:{type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:{name:this.entity.name||``,selected:this.isSelected,opacity:n}}}),this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.labelSourceId,layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.5],"text-allow-overlap":!0},paint:{"text-opacity":[`get`,`opacity`],"text-color":[`case`,[`get`,`selected`],this.selectNameStyle.fillColor,this.nameStyle.fillColor],"text-halo-color":[`case`,[`get`,`selected`],this.selectNameStyle.strokeColor,this.nameStyle.strokeColor],"text-halo-width":[`case`,[`get`,`selected`],this.selectNameStyle.strokeWidth,this.nameStyle.strokeWidth]}})}initAreaLayer(){if(!(`showArea`in this.entity&&this.entity.showArea)||!this.getArea)return;let e=this.getEntityCenter(),{confidence:t}=this.entity,n=P(t),{anchor:r,offset:i}=this.getAreaLabelAnchor();this.map.addSource(this.areaSourceId,{type:`geojson`,data:{type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:{area:A(this.getArea()),opacity:n}}}),this.map.addLayer({id:this.areaLayerId,type:`symbol`,source:this.areaSourceId,layout:{"text-field":[`get`,`area`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":r,"text-offset":i,"text-allow-overlap":!0},paint:{"text-opacity":[`get`,`opacity`],"text-color":this.areaStyle.fillColor,"text-halo-color":this.areaStyle.strokeColor,"text-halo-width":this.areaStyle.strokeWidth}})}updateLabel(){let e=this.map.getSource(this.labelSourceId);if(!e)return;let t=P(this.entity.confidence);e.setData({type:`Feature`,geometry:{type:`Point`,coordinates:this.getEntityCenter()},properties:{name:this.entity.name||``,selected:this.isSelected,opacity:t}})}updateAreaLabel(){if(`showArea`in this.entity&&this.entity.showArea&&this.getArea){let e=this.map.getSource(this.areaSourceId);if(e){let t=P(this.entity.confidence);e.setData({type:`Feature`,geometry:{type:`Point`,coordinates:this.getEntityCenter()},properties:{area:A(this.getArea()),opacity:t}})}else this.initAreaLayer()}else this.map.getLayer(this.areaLayerId)&&this.map.removeLayer(this.areaLayerId),this.map.getSource(this.areaSourceId)&&this.map.removeSource(this.areaSourceId)}setSelected(e){this.isSelected!==e&&(this.isSelected=e,this.updateLabel())}colorWithAlpha(e,t){if(e.startsWith(`rgba`))return e;if(e.startsWith(`#`)){let n=e.slice(1),r=parseInt(n.slice(0,2),16),i=parseInt(n.slice(2,4),16),a=parseInt(n.slice(4,6),16);return`rgba(${r}, ${i}, ${a}, ${t})`}return e.startsWith(`rgb(`)?e.replace(`rgb(`,`rgba(`).replace(`)`,`, ${t})`):e}updateSourceCoordinates(e){this.map.getSource(this.sourceId)?.setCoordinates(e)}getEntityId(){return this.entityId}getCenter(){return this.getEntityCenter()}getBounds(){return this.getEntityBounds()}getLayerId(){return this.layerId}getLabelLayerId(){return this.labelLayerId}destroy(){this.isDestroyed=!0,this.map.getLayer(this.areaLayerId)&&this.map.removeLayer(this.areaLayerId),this.map.getSource(this.areaSourceId)&&this.map.removeSource(this.areaSourceId),this.map.getLayer(this.labelLayerId)&&this.map.removeLayer(this.labelLayerId),this.map.getSource(this.labelSourceId)&&this.map.removeSource(this.labelSourceId),this.map.getLayer(this.layerId)&&this.map.removeLayer(this.layerId),this.map.getSource(this.sourceId)&&this.map.removeSource(this.sourceId)}},ie=`data:image/svg+xml,%3c?xml%20version='1.0'%20standalone='no'?%3e%3c!DOCTYPE%20svg%20PUBLIC%20'-//W3C//DTD%20SVG%201.1//EN'%20'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3e%3csvg%20t='1775030039452'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='24839'%20data-spm-anchor-id='a313x.search_index.0.i1.78953a81FCkAe0'%20width='64'%20height='64'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3cpath%20d='M512%20938.666667l-170.666667-170.666667h341.333334l-170.666667%20170.666667z%20m0-853.333334l170.666667%20170.666667H341.333333l170.666667-170.666667z%20m0%20512a85.333333%2085.333333%200%201%201%200-170.666666%2085.333333%2085.333333%200%200%201%200%20170.666666zM85.333333%20512l170.666667-170.666667v341.333334l-170.666667-170.666667z%20m853.333334%200l-170.666667%20170.666667V341.333333l170.666667%20170.666667z'%20fill='%23ffffff'%20p-id='24840'%3e%3c/path%3e%3c/svg%3e`;const ae=`__edit-move-icon__`;var F=!1;function I(e){if(e.hasImage(`__edit-move-icon__`)||F)return;F=!0;let t=new Image;t.onload=()=>{if(e.hasImage(`__edit-move-icon__`)){F=!1;return}let n=document.createElement(`canvas`);n.width=28,n.height=28;let r=n.getContext(`2d`);r.beginPath(),r.arc(28/2,28/2,28/2,0,Math.PI*2),r.fillStyle=`rgba(51,136,255,0.9)`,r.fill();let i=28*.6,a=(28-i)/2;r.drawImage(t,a,a,i,i);let o=r.getImageData(0,0,28,28);e.addImage(ae,{width:28,height:28,data:new Uint8Array(o.data.buffer)}),F=!1},t.onerror=()=>{F=!1},t.src=ie}function oe(e,t){let n=D(e,t,0),r=D(e,t,90),i=D(e,t,180),a=D(e,t,270)[0],o=r[0],s=i[1],c=n[1];return[[a,c],[o,c],[o,s],[a,s]]}var se=class extends re{constructor(e,t,n,r){super(e,t,`radar`,n,r),this.animationFrameId=null,this.isEditing=!1,this.editSourceId=``,this.editMoveLayerId=``,this.editSourceId=`radar-edit-source-${t.id}`,this.editMoveLayerId=`radar-edit-move-${t.id}`,this.currentRotation=t.initialRotation??w.initialRotation;let i=oe(t.center,t.radius);this.init(i),t.isAnimating&&this.startAnimation()}getEntityCenter(){return this.entity.center}getEntityBounds(){let e=oe(this.entity.center,this.entity.radius),t=e[3][0],n=e[3][1],r=e[1][0],i=e[1][1];return[[t,n],[r,i]]}draw(){let e=this.ctx,t=this.entity;e.clearRect(0,0,512,512),e.globalAlpha=P(t.confidence),this.drawSector(e,t),(t.showRings??w.showRings)&&this.drawRings(e),(t.showScanLine??w.showScanLine)&&this.drawScanLine(e,t),(t.showCenter??w.showCenter)&&this.drawCenterDot(e,t),e.globalAlpha=1}drawSector(e,t){let n=t.colorScheme??w.colorScheme,r=C[n],i=(t.opacity??w.opacity)/100,a=t.sectorAngle,o=N(this.currentRotation-a/2-90),s=N(this.currentRotation+a/2-90),c=e.createRadialGradient(256,256,0,256,256,254);c.addColorStop(0,this.colorWithAlpha(r.center,i)),c.addColorStop(.5,this.colorWithAlpha(r.mid,i*.6)),c.addColorStop(1,this.colorWithAlpha(r.edge,0)),e.beginPath(),e.moveTo(256,256),e.arc(256,256,254,o,s),e.closePath(),e.fillStyle=c,e.fill()}drawRings(e){e.strokeStyle=`rgba(255, 255, 255, 0.2)`,e.lineWidth=2,e.setLineDash([5,5]);for(let t=1;t<=3;t++){let n=254*t/3;e.beginPath(),e.arc(256,256,n,0,Math.PI*2),e.stroke()}e.setLineDash([])}drawScanLine(e,t){let n=t.colorScheme??w.colorScheme,r=C[n],i=N(this.currentRotation-90),a=256+Math.cos(i)*254,o=256+Math.sin(i)*254;e.beginPath(),e.moveTo(256,256),e.lineTo(a,o),e.strokeStyle=r.center,e.lineWidth=2,e.lineCap=`round`,e.globalAlpha=.8,e.stroke(),e.globalAlpha=1}drawCenterDot(e,t){let n=t.colorScheme??w.colorScheme,r=C[n];e.beginPath(),e.arc(256,256,5,0,Math.PI*2),e.fillStyle=r.center,e.fill(),e.strokeStyle=`white`,e.lineWidth=2,e.stroke()}startAnimation(){if(this.animationFrameId!==null||this.isDestroyed)return;let e=()=>{if(this.isDestroyed)return;let t=this.entity.rotationSpeed??w.rotationSpeed;this.currentRotation+=t,this.currentRotation>=360&&(this.currentRotation-=360),this.draw(),this.animationFrameId=requestAnimationFrame(e)};this.animationFrameId=requestAnimationFrame(e),this.map.getSource(this.sourceId)?.play()}stopAnimation(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.map.getSource(this.sourceId)?.pause()}update(e){let t=this.entity;if(this.entity=e,t.center[0]!==e.center[0]||t.center[1]!==e.center[1]||t.radius!==e.radius){let t=oe(e.center,e.radius);this.updateSourceCoordinates(t)}(t.center[0]!==e.center[0]||t.center[1]!==e.center[1]||t.name!==e.name||t.confidence!==e.confidence)&&this.updateLabel(),t.isAnimating!==e.isAnimating&&(e.isAnimating?this.startAnimation():this.stopAnimation()),e.isAnimating||this.draw()}isPointInEntity(e){let{center:t,radius:n}=this.entity,r=e[0]-t[0],i=e[1]-t[1],a=111320*Math.cos(t[1]*Math.PI/180);return Math.sqrt((r*a)**2+(i*110540)**2)<=n}destroy(){this.removeEditLayers(),this.stopAnimation(),super.destroy()}getEditHandleGeoJSON(e){return{type:`FeatureCollection`,features:[{type:`Feature`,geometry:{type:`Point`,coordinates:e??this.entity.center},properties:{handleType:`move`,index:0}}]}}createEditLayers(){this.map.getSource(this.editSourceId)||(I(this.map),this.map.addSource(this.editSourceId,{type:`geojson`,data:this.getEditHandleGeoJSON()}),this.map.addLayer({id:this.editMoveLayerId,type:`symbol`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`move`],layout:{"icon-image":ae,"icon-allow-overlap":!0,"icon-ignore-placement":!0}}))}removeEditLayers(){this.map.getLayer(this.editMoveLayerId)&&this.map.removeLayer(this.editMoveLayerId),this.map.getSource(this.editSourceId)&&this.map.removeSource(this.editSourceId)}refreshEditHandles(e){let t=this.map.getSource(this.editSourceId);t&&t.setData(this.getEditHandleGeoJSON(e))}setEditing(e){this.isEditing!==e&&(this.isEditing=e,e?this.createEditLayers():this.removeEditLayers())}getEditHandleAt(e,t){if(!this.isEditing)return null;let n=this.entity.center,r=this.map.project(e),i=this.map.project(n),a=r.x-i.x,o=r.y-i.y;return a*a+o*o<=144?{type:`move`,index:0,position:n}:null}applyHandleMove(e,t){let n=t[0]-e.position[0],r=t[1]-e.position[1],i=[this.entity.center[0]+n,this.entity.center[1]+r],a={...this.entity,center:i};this.entity=a;let o=oe(i,this.entity.radius);return this.updateSourceCoordinates(o),this.updateLabel(),this.refreshEditHandles(),a}updateEditPreview(e,t){let n=t[0]-e.position[0],r=t[1]-e.position[1],i=[this.entity.center[0]+n,this.entity.center[1]+r],a=oe(i,this.entity.radius);this.updateSourceCoordinates(a);let o=this.entity;this.entity={...this.entity,center:i},this.updateLabel(),this.entity=o,this.refreshEditHandles(i)}cancelEditPreview(){let e=oe(this.entity.center,this.entity.radius);this.updateSourceCoordinates(e),this.updateLabel(),this.refreshEditHandles()}};function ce(e,t,n){let r=t/2,i=n/2,a=D(e,i,0),o=D(e,r,90),s=D(e,i,180),c=D(e,r,270)[0],l=o[0],u=s[1],d=a[1];return[[c,d],[l,d],[l,u],[c,u]]}var le=class extends re{constructor(e,t,n,r){super(e,t,`image`,n,r),this.loadedImage=null,this.imageLoaded=!1,this.currentSrc=``,this.imageAspectRatio=1,this.isEditing=!1,this.editSourceId=``,this.editMoveLayerId=``,this.editSourceId=`image-edit-source-${t.id}`,this.editMoveLayerId=`image-edit-move-${t.id}`,this.loadImage(t.src,!0)}getSize(){let{width:e}=this.entity,t=e/this.imageAspectRatio;return[e,t]}loadImage(e,t=!1){if(!e){console.warn(`Image src is empty`);return}this.currentSrc=e;let n=new Image;n.crossOrigin=`anonymous`,n.onload=()=>{if(e===this.currentSrc)if(this.loadedImage=n,this.imageLoaded=!0,this.imageAspectRatio=n.naturalWidth/n.naturalHeight,t){let[e,t]=this.getSize(),n=ce(this.entity.center,e,t);this.init(n)}else{let[e,t]=this.getSize(),n=ce(this.entity.center,e,t);this.updateSourceCoordinates(n),this.draw()}},n.onerror=()=>{console.error(`Failed to load image: ${e}`)},n.src=e}getEntityCenter(){return this.entity.center}getEntityBounds(){let[e,t]=this.getSize(),n=ce(this.entity.center,e,t),r=n[3][0],i=n[3][1],a=n[1][0],o=n[1][1];return[[r,i],[a,o]]}initLabelLayer(){let e=this.getEntityCenter(),{name:t,confidence:n}=this.entity,r=P(n);this.map.addSource(this.labelSourceId,{type:`geojson`,data:{type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:{name:t||``,selected:this.isSelected,opacity:r}}}),this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.labelSourceId,layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.8],"text-allow-overlap":!0},paint:{"text-opacity":[`get`,`opacity`],"text-color":[`case`,[`get`,`selected`],`#ffcc00`,`#ffffff`],"text-halo-color":[`case`,[`get`,`selected`],`#ff6600`,`rgba(0, 0, 0, 0.8)`],"text-halo-width":[`case`,[`get`,`selected`],2,1]}})}draw(){let e=this.ctx;if(e.clearRect(0,0,512,512),!this.imageLoaded||!this.loadedImage)return;e.globalAlpha=P(this.entity.confidence),e.save(),e.translate(256,256);let t=this.entity.rotation??0;t!==0&&e.rotate(N(t)),e.drawImage(this.loadedImage,-508/2,-508/2,508,508),e.restore(),e.globalAlpha=1}update(e){let t=this.entity;if(this.entity=e,t.src!==e.src){this.imageLoaded=!1,this.loadedImage=null,this.loadImage(e.src);return}if(t.center[0]!==e.center[0]||t.center[1]!==e.center[1]||t.width!==e.width){let[t,n]=this.getSize(),r=ce(e.center,t,n);this.updateSourceCoordinates(r)}(t.center[0]!==e.center[0]||t.center[1]!==e.center[1]||t.name!==e.name||t.confidence!==e.confidence)&&this.updateLabel(),(t.rotation!==e.rotation||t.confidence!==e.confidence)&&this.draw()}isPointInEntity(e){let{center:t}=this.entity,[n,r]=this.getSize(),i=e[0]-t[0],a=e[1]-t[1],o=111320*Math.cos(t[1]*Math.PI/180),s=Math.abs(i*o),c=Math.abs(a*110540);return s<=n/2&&c<=r/2}getEditHandleGeoJSON(e){return{type:`FeatureCollection`,features:[{type:`Feature`,geometry:{type:`Point`,coordinates:e??this.entity.center},properties:{handleType:`move`,index:0}}]}}createEditLayers(){this.map.getSource(this.editSourceId)||(I(this.map),this.map.addSource(this.editSourceId,{type:`geojson`,data:this.getEditHandleGeoJSON()}),this.map.addLayer({id:this.editMoveLayerId,type:`symbol`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`move`],layout:{"icon-image":ae,"icon-allow-overlap":!0,"icon-ignore-placement":!0}}))}removeEditLayers(){this.map.getLayer(this.editMoveLayerId)&&this.map.removeLayer(this.editMoveLayerId),this.map.getSource(this.editSourceId)&&this.map.removeSource(this.editSourceId)}refreshEditHandles(e){let t=this.map.getSource(this.editSourceId);t&&t.setData(this.getEditHandleGeoJSON(e))}setEditing(e){this.isEditing!==e&&(this.isEditing=e,e?this.createEditLayers():this.removeEditLayers())}getEditHandleAt(e,t){if(!this.isEditing)return null;let n=this.entity.center,r=this.map.project(e),i=this.map.project(n),a=r.x-i.x,o=r.y-i.y;return a*a+o*o<=144?{type:`move`,index:0,position:n}:null}applyHandleMove(e,t){let n=t[0]-e.position[0],r=t[1]-e.position[1],i=[this.entity.center[0]+n,this.entity.center[1]+r],a={...this.entity,center:i};this.entity=a;let[o,s]=this.getSize(),c=ce(i,o,s);return this.updateSourceCoordinates(c),this.updateLabel(),this.refreshEditHandles(),a}updateEditPreview(e,t){let n=t[0]-e.position[0],r=t[1]-e.position[1],i=[this.entity.center[0]+n,this.entity.center[1]+r],[a,o]=this.getSize(),s=ce(i,a,o);this.updateSourceCoordinates(s);let c=this.entity;this.entity={...this.entity,center:i},this.updateLabel(),this.entity=c,this.refreshEditHandles(i)}cancelEditPreview(){let[e,t]=this.getSize(),n=ce(this.entity.center,e,t);this.updateSourceCoordinates(n),this.updateLabel(),this.refreshEditHandles()}destroy(){this.removeEditLayers(),super.destroy()}},ue=class{constructor(e,t,n,r){this.marker=null,this.markerElement=null,this.imageElement=null,this.labelElement=null,this.placeholderElement=null,this.isSelected=!1,this.imageAspectRatio=1,this.imageLoaded=!1,this.destroyed=!1,this.isEditing=!1,this.moveIconElement=null,this.map=e,this.entity=t,this.globalNameConfig=n,this.globalSelectNameConfig=r,this.loadImageAndCreateMarker(t.src)}loadImageAndCreateMarker(e){if(!e){console.warn(`Marker src is empty`);return}let t=new Image;t.crossOrigin=`anonymous`,t.onload=()=>{this.destroyed||(this.imageAspectRatio=t.naturalWidth/t.naturalHeight,this.imageLoaded=!0,this.createMarker())},t.onerror=()=>{console.error(`Failed to load marker image: ${e}`)},t.src=e}createMarker(){let{center:e,src:t,width:n,rotation:r=0,anchor:i=`center`,name:a,confidence:o}=this.entity,s=n/this.imageAspectRatio;this.markerElement=document.createElement(`div`),this.markerElement.className=`mapbox-marker-container`,this.markerElement.setAttribute(`data-entity-id`,String(this.entity.id)),this.onBeforeImageCreate(),a&&(this.placeholderElement=document.createElement(`div`),this.placeholderElement.className=`mapbox-marker-placeholder`,this.placeholderElement.textContent=a,this.markerElement.appendChild(this.placeholderElement)),this.imageElement=document.createElement(`img`),this.imageElement.src=t,this.imageElement.style.width=`${n}px`,this.imageElement.style.height=`${s}px`,this.imageElement.style.transform=`rotate(${r}deg)`,this.imageElement.style.opacity=`${P(o)}`,this.imageElement.style.pointerEvents=`auto`,this.markerElement.appendChild(this.imageElement),a&&(this.labelElement=document.createElement(`div`),this.labelElement.className=`mapbox-marker-label`,this.labelElement.textContent=a,this.labelElement.setAttribute(`data-entity-id`,String(this.entity.id)),this.updateLabelStyle(),this.markerElement.appendChild(this.labelElement)),this.marker=new l.default.Marker({element:this.markerElement,anchor:i}).setLngLat(e).addTo(this.map),this.onMarkerCreated()}onBeforeImageCreate(){}onMarkerCreated(){}get nameStyle(){return x(this.entity.nameConfig,this.globalNameConfig,h)}get selectNameStyle(){return x(this.entity.selectNameConfig,this.globalSelectNameConfig,g)}updateLabelStyle(){if(!this.labelElement)return;let{confidence:e}=this.entity,t=P(e),n=this.isSelected?this.selectNameStyle:this.nameStyle;this.labelElement.className=this.isSelected?`mapbox-marker-label mapbox-marker-label--selected`:`mapbox-marker-label`,this.labelElement.style.opacity=`${t}`,this.labelElement.style.color=n.fillColor;let r=n.strokeWidth,i=n.strokeColor;this.labelElement.style.webkitTextStroke=`${r*1.5}px ${i}`,this.labelElement.style.paintOrder=`stroke fill`,this.labelElement.style.textShadow=`none`}getEntityId(){return this.entity.id}getCenter(){return this.entity.center}getBounds(){let{center:e,width:t}=this.entity,n=t/this.imageAspectRatio,r=this.map.getZoom(),i=156543.03392*Math.cos(e[1]*Math.PI/180)/2**r,a=t*i,o=n*i,s=111320*Math.cos(e[1]*Math.PI/180),c=a/2/s,l=o/2/110540;return[[e[0]-c,e[1]-l],[e[0]+c,e[1]+l]]}getLayerId(){return`marker-${this.entity.id}`}getLabelLayerId(){return null}setSelected(e){this.isSelected!==e&&(this.isSelected=e,this.updateLabelStyle())}isPointInEntity(e){if(!this.marker||!this.imageLoaded)return!1;let{center:t,width:n}=this.entity,r=n/this.imageAspectRatio,i=this.map.getZoom(),a=156543.03392*Math.cos(t[1]*Math.PI/180)/2**i,o=n*a,s=r*a,c=e[0]-t[0],l=e[1]-t[1],u=111320*Math.cos(t[1]*Math.PI/180),d=Math.abs(c*u),f=Math.abs(l*110540);return d<=o/2&&f<=s/2}update(e){let t=this.entity;if(this.entity=e,t.src!==e.src){this.destroy(),this.imageLoaded=!1,this.loadImageAndCreateMarker(e.src);return}if(!this.marker||!this.imageElement)return;(t.center[0]!==e.center[0]||t.center[1]!==e.center[1])&&this.marker.setLngLat(e.center);let n=e.width/this.imageAspectRatio,r=e.rotation??0,i=P(e.confidence);(t.width!==e.width||t.rotation!==e.rotation||t.confidence!==e.confidence)&&(this.imageElement.style.width=`${e.width}px`,this.imageElement.style.height=`${n}px`,this.imageElement.style.transform=`rotate(${r}deg)`,this.imageElement.style.opacity=`${i}`),t.name!==e.name&&(e.name&&!this.labelElement?(this.labelElement=document.createElement(`div`),this.labelElement.className=`mapbox-marker-label`,this.labelElement.textContent=e.name,this.updateLabelStyle(),this.markerElement?.appendChild(this.labelElement),this.placeholderElement=document.createElement(`div`),this.placeholderElement.className=`mapbox-marker-placeholder`,this.placeholderElement.textContent=e.name,this.markerElement?.insertBefore(this.placeholderElement,this.markerElement.firstChild)):!e.name&&this.labelElement?(this.labelElement.remove(),this.labelElement=null,this.placeholderElement?.remove(),this.placeholderElement=null):this.labelElement&&(this.labelElement.textContent=e.name||``,this.placeholderElement&&(this.placeholderElement.textContent=e.name||``))),t.confidence!==e.confidence&&this.updateLabelStyle()}destroy(){this.removeMoveIcon(),this.destroyed=!0,this.marker&&=(this.marker.remove(),null),this.markerElement=null,this.imageElement=null,this.labelElement=null,this.placeholderElement=null}createMoveIcon(){if(this.moveIconElement||!this.markerElement)return;let e=document.createElement(`div`);e.className=`mapbox-marker-move-icon`,e.style.cssText=`width:28px;height:28px;border-radius:50%;background:rgba(51,136,255,0.9);display:flex;align-items:center;justify-content:center;cursor:move;position:absolute;left:50%;bottom:0;transform:translate(-50%,100%);pointer-events:none;`;let t=document.createElement(`img`);t.src=ie,t.style.cssText=`width:60%;height:60%;`,e.appendChild(t),this.markerElement.appendChild(e),this.moveIconElement=e}removeMoveIcon(){this.moveIconElement&&=(this.moveIconElement.remove(),null)}setEditing(e){this.isEditing!==e&&(this.isEditing=e,e?this.createMoveIcon():this.removeMoveIcon())}getEditHandleAt(e,t){if(!this.isEditing)return null;let n=this.map.project(e);if(this.moveIconElement){let t=this.moveIconElement.getBoundingClientRect(),r=this.map.getContainer().getBoundingClientRect(),i=t.left+t.width/2-r.left,a=t.top+t.height/2-r.top,o=n.x-i,s=n.y-a;if(o*o+s*s<=256)return{type:`move`,index:0,position:e}}return null}applyHandleMove(e,t){let n=t[0]-e.position[0],r=t[1]-e.position[1],i=[this.entity.center[0]+n,this.entity.center[1]+r],a={...this.entity,center:i};return this.entity=a,this.marker&&this.marker.setLngLat(i),a}updateEditPreview(e,t){let n=t[0]-e.position[0],r=t[1]-e.position[1],i=[this.entity.center[0]+n,this.entity.center[1]+r];this.marker&&this.marker.setLngLat(i)}cancelEditPreview(){this.marker&&this.marker.setLngLat(this.entity.center)}},de=class extends ue{constructor(e,t,n,r){super(e,t,n,r),this.showTrajectory=0,this.showTrajectoryPoints=!1,this.trajInitialized=!1,this.statusElement=null,this.statusRoot=null,this.trajSourceId=`unit-traj-source-${t.id}`,this.trajLayerId=`unit-traj-layer-${t.id}`,this.trajPointsLayerId=`unit-traj-points-layer-${t.id}`,t.showTrajectory&&(this.showTrajectory=t.showTrajectory),this.showTrajectoryPoints=t.showTrajectoryPoints??!1}renderStatus(){return null}onBeforeImageCreate(){this.markerElement&&(this.statusElement=document.createElement(`div`),this.statusElement.className=`mapbox-unit-status`,this.markerElement.appendChild(this.statusElement),this.updateStatusContent())}updateStatusContent(){if(!this.statusElement)return;let e=this.renderStatus();e?(this.statusRoot||=(0,d.createRoot)(this.statusElement),this.statusRoot.render(e),this.statusElement.style.display=`block`):(this.statusRoot&&this.statusRoot.render(null),this.statusElement.style.display=`none`)}refreshStatus(){this.updateStatusContent()}getLayerId(){return`unit-${this.entity.id}`}onMarkerCreated(){this.entity.showTrajectory&&(this.showTrajectory=this.entity.showTrajectory,this.initTrajectoryLayer())}shouldShowTrajectory(){return this.showTrajectory===`all`||typeof this.showTrajectory==`number`&&this.showTrajectory>0}getTrajectoryCount(){let{predicted_traj:e}=this.entity;return!e||e.length===0?0:this.showTrajectory===`all`?e.length:typeof this.showTrajectory==`number`&&this.showTrajectory>0?Math.min(this.showTrajectory,e.length):0}initTrajectoryLayer(){if(this.trajInitialized)return;if(!this.map.isStyleLoaded()){requestAnimationFrame(()=>this.initTrajectoryLayer());return}let e=this.getTrajectoryGeoJSON();this.map.addSource(this.trajSourceId,{type:`geojson`,data:e});let t=this.shouldShowTrajectory()?`visible`:`none`,n=this.shouldShowTrajectory()&&this.showTrajectoryPoints?`visible`:`none`;this.map.addLayer({id:this.trajLayerId,type:`line`,source:this.trajSourceId,layout:{"line-join":`round`,"line-cap":`round`,visibility:t},paint:{"line-color":this.isSelected?`#ffcc00`:`#00ff88`,"line-width":3,"line-opacity":P(this.entity.confidence)*.8,"line-dasharray":[2,2]}}),this.map.addLayer({id:this.trajPointsLayerId,type:`circle`,source:this.trajSourceId,filter:[`==`,`$type`,`Point`],layout:{visibility:n},paint:{"circle-radius":4,"circle-color":this.isSelected?`#ffcc00`:`#00ff88`,"circle-stroke-color":`#ffffff`,"circle-stroke-width":1,"circle-opacity":P(this.entity.confidence)}}),this.trajInitialized=!0}getTrajectoryGeoJSON(){let{predicted_traj:e,center:t}=this.entity,n=this.getTrajectoryCount();if(!e||e.length===0||n===0)return{type:`FeatureCollection`,features:[]};let r=e.slice(0,n),i=[t],a=[];return r.forEach((e,t)=>{let n=[e.lon,e.lat];i.push(n),a.push({type:`Feature`,geometry:{type:`Point`,coordinates:n},properties:{index:t,alt:e.alt}})}),{type:`FeatureCollection`,features:[{type:`Feature`,geometry:{type:`LineString`,coordinates:i},properties:{}},...a]}}setShowTrajectory(e){let t=e===`all`||typeof e==`number`&&e>0;if(t&&!this.trajInitialized){this.showTrajectory=e,this.initTrajectoryLayer();return}let n=this.shouldShowTrajectory();if(this.showTrajectory=e,this.trajInitialized){let e=t?`visible`:`none`,r=t&&this.showTrajectoryPoints?`visible`:`none`;this.map.getLayer(this.trajLayerId)&&this.map.setLayoutProperty(this.trajLayerId,`visibility`,e),this.map.getLayer(this.trajPointsLayerId)&&this.map.setLayoutProperty(this.trajPointsLayerId,`visibility`,r),t&&n&&this.updateTrajectoryData()}}getShowTrajectory(){return this.showTrajectory}setShowTrajectoryPoints(e){if(this.showTrajectoryPoints=e,this.trajInitialized&&this.map.getLayer(this.trajPointsLayerId)){let t=this.shouldShowTrajectory()&&e?`visible`:`none`;this.map.setLayoutProperty(this.trajPointsLayerId,`visibility`,t)}}getShowTrajectoryPoints(){return this.showTrajectoryPoints}setSelected(e){let t=this.isSelected;super.setSelected(e),t!==e&&this.trajInitialized&&this.updateTrajectoryStyle()}updateTrajectoryStyle(){let e=this.isSelected?`#ffcc00`:`#00ff88`,t=P(this.entity.confidence);this.map.getLayer(this.trajLayerId)&&(this.map.setPaintProperty(this.trajLayerId,`line-color`,e),this.map.setPaintProperty(this.trajLayerId,`line-opacity`,t*.8)),this.map.getLayer(this.trajPointsLayerId)&&(this.map.setPaintProperty(this.trajPointsLayerId,`circle-color`,e),this.map.setPaintProperty(this.trajPointsLayerId,`circle-opacity`,t))}updateTrajectoryData(){if(!this.trajInitialized)return;let e=this.map.getSource(this.trajSourceId);e&&e.setData(this.getTrajectoryGeoJSON())}update(e){let t=this.entity;super.update(e),t.showTrajectory!==e.showTrajectory&&this.setShowTrajectory(e.showTrajectory??0),t.showTrajectoryPoints!==e.showTrajectoryPoints&&this.setShowTrajectoryPoints(e.showTrajectoryPoints??!1),this.updateTrajectoryData(),t.confidence!==e.confidence&&this.updateTrajectoryStyle()}destroy(){this.statusRoot&&=(this.statusRoot.unmount(),null),this.statusElement=null,this.trajInitialized&&(this.map.getLayer(this.trajPointsLayerId)&&this.map.removeLayer(this.trajPointsLayerId),this.map.getLayer(this.trajLayerId)&&this.map.removeLayer(this.trajLayerId),this.map.getSource(this.trajSourceId)&&this.map.removeSource(this.trajSourceId)),super.destroy()}},fe=class e{static{this.DEFAULTS={strokeColor:`#3388ff`,strokeWidth:2,strokeOpacity:1,fillColor:`#3388ff`,fillOpacity:.2}}constructor(e,t,n,r,i,a){this.isSelected=!1,this.initialized=!1,this.isEditing=!1,this.map=e,this.entity=t,this.globalNameConfig=n,this.globalSelectNameConfig=r,this.globalAreaConfig=i,this.globalLengthConfig=a,this.sourceId=`polygon-source-${t.id}`,this.fillLayerId=`polygon-fill-${t.id}`,this.strokeLayerId=`polygon-stroke-${t.id}`,this.labelLayerId=`polygon-label-${t.id}`,this.areaLayerId=`polygon-area-${t.id}`,this.lengthLayerId=`polygon-length-${t.id}`,this.editSourceId=`polygon-edit-source-${t.id}`,this.editHandleLayerId=`polygon-edit-handles-${t.id}`,this.editMidpointLayerId=`polygon-edit-midpoints-${t.id}`,this.editMoveLayerId=`polygon-edit-move-${t.id}`,this.initLayers()}get nameStyle(){return x(this.entity.nameConfig,this.globalNameConfig,h)}get selectNameStyle(){return x(this.entity.selectNameConfig,this.globalSelectNameConfig,g)}get areaStyle(){return x(this.entity.areaConfig,this.globalAreaConfig,_)}get lengthStyle(){return x(this.entity.lengthConfig,this.globalLengthConfig,b)}initLayers(){if(!this.initialized)try{let t=this.getGeoJSON();this.map.addSource(this.sourceId,{type:`geojson`,data:t});let n=this.entity.confidence??1,r=P(n);this.map.addLayer({id:this.fillLayerId,type:`fill`,source:this.sourceId,filter:[`==`,`$type`,`Polygon`],paint:{"fill-color":this.entity.fillColor??e.DEFAULTS.fillColor,"fill-opacity":(this.entity.fillOpacity??e.DEFAULTS.fillOpacity)*r}}),this.map.addLayer({id:this.strokeLayerId,type:`line`,source:this.sourceId,filter:[`==`,`$type`,`Polygon`],layout:{"line-join":`round`,"line-cap":`round`},paint:{"line-color":this.isSelected?`#ffcc00`:this.entity.strokeColor??e.DEFAULTS.strokeColor,"line-width":this.entity.strokeWidth??e.DEFAULTS.strokeWidth,"line-opacity":(this.entity.strokeOpacity??e.DEFAULTS.strokeOpacity)*r}}),this.entity.name&&this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`label`],layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.8],"text-allow-overlap":!0},paint:{"text-color":this.isSelected?this.selectNameStyle.fillColor:this.nameStyle.fillColor,"text-halo-color":this.isSelected?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor,"text-halo-width":this.isSelected?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth,"text-opacity":r}}),this.entity.showArea&&this.map.addLayer({id:this.areaLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`area`],layout:{"text-field":[`get`,`area`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-allow-overlap":!0},paint:{"text-color":this.areaStyle.fillColor,"text-halo-color":this.areaStyle.strokeColor,"text-halo-width":this.areaStyle.strokeWidth,"text-opacity":r}}),this.entity.showLength&&this.map.addLayer({id:this.lengthLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`length`],layout:{"text-field":[`get`,`length`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-offset":[0,-.8],"text-allow-overlap":!0},paint:{"text-color":this.lengthStyle.fillColor,"text-halo-color":this.lengthStyle.strokeColor,"text-halo-width":this.lengthStyle.strokeWidth,"text-opacity":r}}),this.initialized=!0}catch{this.map.once(`idle`,()=>this.initLayers())}}getGeoJSON(){let{coordinates:e}=this.entity;if(!e||e.length<3)return{type:`FeatureCollection`,features:[]};let t=[...e];(e[0][0]!==e[e.length-1][0]||e[0][1]!==e[e.length-1][1])&&t.push(e[0]);let n=[{type:`Feature`,geometry:{type:`Polygon`,coordinates:[t]},properties:{}}];if(this.entity.name){let t=this.getBottomPoint(e);n.push({type:`Feature`,geometry:{type:`Point`,coordinates:t},properties:{pointType:`label`,name:this.entity.name}})}if(this.entity.showArea){let e=this.calculateGeometricCenter();n.push({type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:{pointType:`area`,area:A(this.getArea())}})}if(this.entity.showLength)for(let t=0;t<e.length;t++){let r=e[t],i=e[(t+1)%e.length],a=[(r[0]+i[0])/2,(r[1]+i[1])/2],o=O(r,i);n.push({type:`Feature`,geometry:{type:`Point`,coordinates:a},properties:{pointType:`length`,length:j(o)}})}return{type:`FeatureCollection`,features:n}}getBottomPoint(e){let t=e[0],n=e[0][1];for(let r of e)r[1]<n&&(n=r[1],t=r);return t}getArea(){let{coordinates:e}=this.entity;if(!e||e.length<3)return 0;let t=[...e];return(t[0][0]!==t[t.length-1][0]||t[0][1]!==t[t.length-1][1])&&t.push(t[0]),ee(t)}getEntityId(){return this.entity.id}getBounds(){let{coordinates:e}=this.entity;if(!e||e.length===0){let e=this.getCenter();return[e,e]}let t=1/0,n=-1/0,r=1/0,i=-1/0;for(let a of e)t=Math.min(t,a[0]),n=Math.max(n,a[0]),r=Math.min(r,a[1]),i=Math.max(i,a[1]);return[[t,r],[n,i]]}getCenter(){return this.entity.center?this.entity.center:this.calculateGeometricCenter()}calculateGeometricCenter(){let{coordinates:e}=this.entity;if(!e||e.length===0)return[0,0];let t=0,n=0;for(let r of e)t+=r[0],n+=r[1];return[t/e.length,n/e.length]}getLayerId(){return this.fillLayerId}getLabelLayerId(){return this.entity.name?this.labelLayerId:null}setSelected(t){this.isSelected!==t&&(this.isSelected=t,this.initialized&&(this.map.getLayer(this.strokeLayerId)&&this.map.setPaintProperty(this.strokeLayerId,`line-color`,t?`#ffcc00`:this.entity.strokeColor??e.DEFAULTS.strokeColor),this.map.getLayer(this.labelLayerId)&&(this.map.setPaintProperty(this.labelLayerId,`text-color`,t?this.selectNameStyle.fillColor:this.nameStyle.fillColor),this.map.setPaintProperty(this.labelLayerId,`text-halo-color`,t?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor),this.map.setPaintProperty(this.labelLayerId,`text-halo-width`,t?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth))))}isPointInEntity(e){let{coordinates:t}=this.entity;return!t||t.length<3?!1:this.pointInPolygon(e,t)}pointInPolygon(e,t){let[n,r]=e,i=!1;for(let e=0,a=t.length-1;e<t.length;a=e++){let[o,s]=t[e],[c,l]=t[a];s>r!=l>r&&n<(c-o)*(r-s)/(l-s)+o&&(i=!i)}return i}update(t){let n=this.entity;if(this.entity=t,!this.initialized)return;let r=t.confidence??1,i=P(r);if(n.coordinates!==t.coordinates||n.name!==t.name||n.showArea!==t.showArea||n.showLength!==t.showLength){let e=this.map.getSource(this.sourceId);e&&e.setData(this.getGeoJSON()),!n.name&&t.name&&!this.map.getLayer(this.labelLayerId)?this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`label`],layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.8],"text-allow-overlap":!0},paint:{"text-color":this.isSelected?this.selectNameStyle.fillColor:this.nameStyle.fillColor,"text-halo-color":this.isSelected?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor,"text-halo-width":this.isSelected?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth,"text-opacity":i}}):n.name&&!t.name&&this.map.getLayer(this.labelLayerId)&&this.map.removeLayer(this.labelLayerId),!n.showArea&&t.showArea&&!this.map.getLayer(this.areaLayerId)?this.map.addLayer({id:this.areaLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`area`],layout:{"text-field":[`get`,`area`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-allow-overlap":!0},paint:{"text-color":this.areaStyle.fillColor,"text-halo-color":this.areaStyle.strokeColor,"text-halo-width":this.areaStyle.strokeWidth,"text-opacity":i}}):n.showArea&&!t.showArea&&this.map.getLayer(this.areaLayerId)&&this.map.removeLayer(this.areaLayerId),!n.showLength&&t.showLength&&!this.map.getLayer(this.lengthLayerId)?this.map.addLayer({id:this.lengthLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`length`],layout:{"text-field":[`get`,`length`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-offset":[0,-.8],"text-allow-overlap":!0},paint:{"text-color":this.lengthStyle.fillColor,"text-halo-color":this.lengthStyle.strokeColor,"text-halo-width":this.lengthStyle.strokeWidth,"text-opacity":i}}):n.showLength&&!t.showLength&&this.map.getLayer(this.lengthLayerId)&&this.map.removeLayer(this.lengthLayerId)}(n.fillColor!==t.fillColor||n.fillOpacity!==t.fillOpacity||n.confidence!==t.confidence)&&this.map.getLayer(this.fillLayerId)&&(this.map.setPaintProperty(this.fillLayerId,`fill-color`,t.fillColor??e.DEFAULTS.fillColor),this.map.setPaintProperty(this.fillLayerId,`fill-opacity`,(t.fillOpacity??e.DEFAULTS.fillOpacity)*i)),(n.strokeColor!==t.strokeColor||n.strokeWidth!==t.strokeWidth||n.strokeOpacity!==t.strokeOpacity||n.confidence!==t.confidence)&&this.map.getLayer(this.strokeLayerId)&&(this.isSelected||this.map.setPaintProperty(this.strokeLayerId,`line-color`,t.strokeColor??e.DEFAULTS.strokeColor),this.map.setPaintProperty(this.strokeLayerId,`line-width`,t.strokeWidth??e.DEFAULTS.strokeWidth),this.map.setPaintProperty(this.strokeLayerId,`line-opacity`,(t.strokeOpacity??e.DEFAULTS.strokeOpacity)*i)),n.confidence!==t.confidence&&(this.map.getLayer(this.labelLayerId)&&this.map.setPaintProperty(this.labelLayerId,`text-opacity`,i),this.map.getLayer(this.areaLayerId)&&this.map.setPaintProperty(this.areaLayerId,`text-opacity`,i),this.map.getLayer(this.lengthLayerId)&&this.map.setPaintProperty(this.lengthLayerId,`text-opacity`,i))}getEditHandleGeoJSON(e){let t=e??this.entity.coordinates;if(!t||t.length<3)return{type:`FeatureCollection`,features:[]};let n=[];for(let e=0;e<t.length;e++)n.push({type:`Feature`,geometry:{type:`Point`,coordinates:t[e]},properties:{handleType:`vertex`,index:e}});for(let e=0;e<t.length;e++){let r=t[e],i=t[(e+1)%t.length];n.push({type:`Feature`,geometry:{type:`Point`,coordinates:[(r[0]+i[0])/2,(r[1]+i[1])/2]},properties:{handleType:`midpoint`,index:e}})}let r=0,i=0;for(let e of t)r+=e[0],i+=e[1];return r/=t.length,i/=t.length,n.push({type:`Feature`,geometry:{type:`Point`,coordinates:[r,i]},properties:{handleType:`move`,index:0}}),{type:`FeatureCollection`,features:n}}createEditLayers(){this.map.getSource(this.editSourceId)||(I(this.map),this.map.addSource(this.editSourceId,{type:`geojson`,data:this.getEditHandleGeoJSON()}),this.map.addLayer({id:this.editMidpointLayerId,type:`circle`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`midpoint`],paint:{"circle-radius":4,"circle-color":`#3388ff`,"circle-opacity":.5,"circle-stroke-color":`#3388ff`,"circle-stroke-width":1}}),this.map.addLayer({id:this.editHandleLayerId,type:`circle`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`vertex`],paint:{"circle-radius":6,"circle-color":`#ffffff`,"circle-stroke-color":`#3388ff`,"circle-stroke-width":2}}),this.map.addLayer({id:this.editMoveLayerId,type:`symbol`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`move`],layout:{"icon-image":ae,"icon-allow-overlap":!0,"icon-ignore-placement":!0}}))}removeEditLayers(){this.map.getLayer(this.editMoveLayerId)&&this.map.removeLayer(this.editMoveLayerId),this.map.getLayer(this.editHandleLayerId)&&this.map.removeLayer(this.editHandleLayerId),this.map.getLayer(this.editMidpointLayerId)&&this.map.removeLayer(this.editMidpointLayerId),this.map.getSource(this.editSourceId)&&this.map.removeSource(this.editSourceId)}refreshEditHandles(e){let t=this.map.getSource(this.editSourceId);t&&t.setData(this.getEditHandleGeoJSON(e))}setEditing(e){this.isEditing!==e&&(this.isEditing=e,this.initialized&&(e?this.createEditLayers():this.removeEditLayers()))}getEditHandleAt(e,t){if(!this.isEditing)return null;let n=this.entity.coordinates;if(!n||n.length<3)return null;let r=this.map.project(e),i=0,a=0;for(let e of n)i+=e[0],a+=e[1];i/=n.length,a/=n.length;let o=this.map.project([i,a]),s=r.x-o.x,c=r.y-o.y;if(s*s+c*c<=144)return{type:`move`,index:0,position:[i,a]};for(let e=0;e<n.length;e++){let t=this.map.project(n[e]),i=r.x-t.x,a=r.y-t.y;if(i*i+a*a<=100)return{type:`vertex`,index:e,position:n[e]}}for(let e=0;e<n.length;e++){let t=n[e],i=n[(e+1)%n.length],a=[(t[0]+i[0])/2,(t[1]+i[1])/2],o=this.map.project(a),s=r.x-o.x,c=r.y-o.y;if(s*s+c*c<=100)return{type:`midpoint`,index:e,position:a}}return null}offsetCoordinates(e,t,n){let r=n[0]-t[0],i=n[1]-t[1];return e.map(e=>[e[0]+r,e[1]+i])}applyHandleMove(e,t){let n;e.type===`move`?n=this.offsetCoordinates(this.entity.coordinates,e.position,t):(n=[...this.entity.coordinates],n[e.index]=t);let r={...this.entity,coordinates:n};this.entity=r;let i=this.map.getSource(this.sourceId);return i&&i.setData(this.getGeoJSON()),this.refreshEditHandles(),r}updateEditPreview(e,t){let n;e.type===`move`?n=this.offsetCoordinates(this.entity.coordinates,e.position,t):(n=[...this.entity.coordinates],n[e.index]=t);let r=this.entity;this.entity={...this.entity,coordinates:n};let i=this.map.getSource(this.sourceId);i&&i.setData(this.getGeoJSON()),this.entity=r,this.refreshEditHandles(n)}cancelEditPreview(){let e=this.map.getSource(this.sourceId);e&&e.setData(this.getGeoJSON()),this.refreshEditHandles()}deleteVertex(e){let t=this.entity.coordinates;if(!t||t.length<=3)return null;let n=t.filter((t,n)=>n!==e),r={...this.entity,coordinates:n};this.entity=r;let i=this.map.getSource(this.sourceId);return i&&i.setData(this.getGeoJSON()),this.refreshEditHandles(),r}addVertex(e,t){let n=[...this.entity.coordinates];n.splice(e+1,0,t);let r={...this.entity,coordinates:n};this.entity=r;let i=this.map.getSource(this.sourceId);return i&&i.setData(this.getGeoJSON()),this.refreshEditHandles(),r}destroy(){this.initialized&&=(this.removeEditLayers(),this.map.getLayer(this.lengthLayerId)&&this.map.removeLayer(this.lengthLayerId),this.map.getLayer(this.areaLayerId)&&this.map.removeLayer(this.areaLayerId),this.map.getLayer(this.labelLayerId)&&this.map.removeLayer(this.labelLayerId),this.map.getLayer(this.strokeLayerId)&&this.map.removeLayer(this.strokeLayerId),this.map.getLayer(this.fillLayerId)&&this.map.removeLayer(this.fillLayerId),this.map.getSource(this.sourceId)&&this.map.removeSource(this.sourceId),!1)}},pe=class e{static{this.DEFAULTS={strokeColor:`#3388ff`,strokeWidth:2,strokeOpacity:1,lineCap:`round`,lineJoin:`round`}}constructor(e,t,n,r,i){this.isSelected=!1,this.initialized=!1,this.isEditing=!1,this.map=e,this.entity=t,this.globalNameConfig=n,this.globalSelectNameConfig=r,this.globalLengthConfig=i,this.sourceId=`polyline-source-${t.id}`,this.lineLayerId=`polyline-stroke-${t.id}`,this.labelLayerId=`polyline-label-${t.id}`,this.lengthLayerId=`polyline-length-${t.id}`,this.editSourceId=`polyline-edit-source-${t.id}`,this.editHandleLayerId=`polyline-edit-handles-${t.id}`,this.editMidpointLayerId=`polyline-edit-midpoints-${t.id}`,this.editMoveLayerId=`polyline-edit-move-${t.id}`,this.initLayers()}get nameStyle(){return x(this.entity.nameConfig,this.globalNameConfig,h)}get selectNameStyle(){return x(this.entity.selectNameConfig,this.globalSelectNameConfig,g)}get lengthStyle(){return x(this.entity.lengthConfig,this.globalLengthConfig,b)}initLayers(){if(!this.initialized)try{let t=this.getGeoJSON();this.map.addSource(this.sourceId,{type:`geojson`,data:t});let n=this.entity.confidence??1,r=P(n);this.map.addLayer({id:this.lineLayerId,type:`line`,source:this.sourceId,filter:[`==`,`$type`,`LineString`],layout:{"line-join":this.entity.lineJoin??e.DEFAULTS.lineJoin,"line-cap":this.entity.lineCap??e.DEFAULTS.lineCap},paint:{"line-color":this.isSelected?`#ffcc00`:this.entity.strokeColor??e.DEFAULTS.strokeColor,"line-width":this.entity.strokeWidth??e.DEFAULTS.strokeWidth,"line-opacity":(this.entity.strokeOpacity??e.DEFAULTS.strokeOpacity)*r,...this.entity.dashArray?{"line-dasharray":this.entity.dashArray}:{}}}),this.entity.name&&this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`label`],layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.8],"text-allow-overlap":!0},paint:{"text-color":this.isSelected?this.selectNameStyle.fillColor:this.nameStyle.fillColor,"text-halo-color":this.isSelected?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor,"text-halo-width":this.isSelected?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth,"text-opacity":r}}),this.entity.showLength&&this.map.addLayer({id:this.lengthLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`length`],layout:{"text-field":[`get`,`length`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-offset":[0,-.8],"text-allow-overlap":!0},paint:{"text-color":this.lengthStyle.fillColor,"text-halo-color":this.lengthStyle.strokeColor,"text-halo-width":this.lengthStyle.strokeWidth,"text-opacity":r}}),this.initialized=!0}catch{this.map.once(`idle`,()=>this.initLayers())}}getGeoJSON(){let{coordinates:e,name:t}=this.entity;if(!e||e.length<2)return{type:`FeatureCollection`,features:[]};let n=[{type:`Feature`,geometry:{type:`LineString`,coordinates:e},properties:{}}];if(t){let r=this.getMidPoint(e);n.push({type:`Feature`,geometry:{type:`Point`,coordinates:r},properties:{pointType:`label`,name:t}})}if(this.entity.showLength)for(let t=0;t<e.length-1;t++){let r=e[t],i=e[t+1],a=[(r[0]+i[0])/2,(r[1]+i[1])/2],o=O(r,i);n.push({type:`Feature`,geometry:{type:`Point`,coordinates:a},properties:{pointType:`length`,length:j(o)}})}return{type:`FeatureCollection`,features:n}}getMidPoint(e){if(e.length===1)return e[0];let t=Math.floor((e.length-1)/2),n=e[t],r=e[t+1];return[(n[0]+r[0])/2,(n[1]+r[1])/2]}getEntityId(){return this.entity.id}getBounds(){let{coordinates:e}=this.entity;if(!e||e.length===0){let e=this.getCenter();return[e,e]}let t=1/0,n=-1/0,r=1/0,i=-1/0;for(let a of e)t=Math.min(t,a[0]),n=Math.max(n,a[0]),r=Math.min(r,a[1]),i=Math.max(i,a[1]);return[[t,r],[n,i]]}getCenter(){return this.entity.center?this.entity.center:this.calculateGeometricCenter()}calculateGeometricCenter(){let{coordinates:e}=this.entity;if(!e||e.length===0)return[0,0];let t=0,n=0;for(let r of e)t+=r[0],n+=r[1];return[t/e.length,n/e.length]}getLayerId(){return this.lineLayerId}getLabelLayerId(){return this.entity.name?this.labelLayerId:null}setSelected(t){this.isSelected!==t&&(this.isSelected=t,this.initialized&&(this.map.getLayer(this.lineLayerId)&&this.map.setPaintProperty(this.lineLayerId,`line-color`,t?`#ffcc00`:this.entity.strokeColor??e.DEFAULTS.strokeColor),this.map.getLayer(this.labelLayerId)&&(this.map.setPaintProperty(this.labelLayerId,`text-color`,t?this.selectNameStyle.fillColor:this.nameStyle.fillColor),this.map.setPaintProperty(this.labelLayerId,`text-halo-color`,t?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor),this.map.setPaintProperty(this.labelLayerId,`text-halo-width`,t?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth))))}isPointInEntity(e){let{coordinates:t}=this.entity;if(!t||t.length<2)return!1;let n=this.getClickThreshold();for(let r=0;r<t.length-1;r++)if(this.pointToSegmentDistance(e,t[r],t[r+1])<n)return!0;return!1}getClickThreshold(){return .001*2**(12-this.map.getZoom())}pointToSegmentDistance(e,t,n){let[r,i]=e,[a,o]=t,[s,c]=n,l=s-a,u=c-o,d=l*l+u*u;if(d===0)return Math.sqrt((r-a)*(r-a)+(i-o)*(i-o));let f=((r-a)*l+(i-o)*u)/d;f=Math.max(0,Math.min(1,f));let p=a+f*l,m=o+f*u;return Math.sqrt((r-p)*(r-p)+(i-m)*(i-m))}update(t){let n=this.entity;if(this.entity=t,!this.initialized)return;let r=t.confidence??1,i=P(r);if(n.coordinates!==t.coordinates||n.name!==t.name||n.showLength!==t.showLength){let e=this.map.getSource(this.sourceId);e&&e.setData(this.getGeoJSON()),!n.name&&t.name&&!this.map.getLayer(this.labelLayerId)?this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`label`],layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.8],"text-allow-overlap":!0},paint:{"text-color":this.isSelected?this.selectNameStyle.fillColor:this.nameStyle.fillColor,"text-halo-color":this.isSelected?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor,"text-halo-width":this.isSelected?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth,"text-opacity":i}}):n.name&&!t.name&&this.map.getLayer(this.labelLayerId)&&this.map.removeLayer(this.labelLayerId),!n.showLength&&t.showLength&&!this.map.getLayer(this.lengthLayerId)?this.map.addLayer({id:this.lengthLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`length`],layout:{"text-field":[`get`,`length`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-offset":[0,-.8],"text-allow-overlap":!0},paint:{"text-color":this.lengthStyle.fillColor,"text-halo-color":this.lengthStyle.strokeColor,"text-halo-width":this.lengthStyle.strokeWidth,"text-opacity":i}}):n.showLength&&!t.showLength&&this.map.getLayer(this.lengthLayerId)&&this.map.removeLayer(this.lengthLayerId)}(n.strokeColor!==t.strokeColor||n.strokeWidth!==t.strokeWidth||n.strokeOpacity!==t.strokeOpacity||n.confidence!==t.confidence||n.dashArray!==t.dashArray)&&this.map.getLayer(this.lineLayerId)&&(this.isSelected||this.map.setPaintProperty(this.lineLayerId,`line-color`,t.strokeColor??e.DEFAULTS.strokeColor),this.map.setPaintProperty(this.lineLayerId,`line-width`,t.strokeWidth??e.DEFAULTS.strokeWidth),this.map.setPaintProperty(this.lineLayerId,`line-opacity`,(t.strokeOpacity??e.DEFAULTS.strokeOpacity)*i),t.dashArray&&this.map.setPaintProperty(this.lineLayerId,`line-dasharray`,t.dashArray)),(n.lineCap!==t.lineCap||n.lineJoin!==t.lineJoin)&&this.map.getLayer(this.lineLayerId)&&(this.map.setLayoutProperty(this.lineLayerId,`line-cap`,t.lineCap??e.DEFAULTS.lineCap),this.map.setLayoutProperty(this.lineLayerId,`line-join`,t.lineJoin??e.DEFAULTS.lineJoin)),n.confidence!==t.confidence&&this.map.getLayer(this.labelLayerId)&&this.map.setPaintProperty(this.labelLayerId,`text-opacity`,i),n.confidence!==t.confidence&&this.map.getLayer(this.lengthLayerId)&&this.map.setPaintProperty(this.lengthLayerId,`text-opacity`,i)}getEditHandleGeoJSON(e){let t=e??this.entity.coordinates;if(!t||t.length<2)return{type:`FeatureCollection`,features:[]};let n=[];for(let e=0;e<t.length;e++)n.push({type:`Feature`,geometry:{type:`Point`,coordinates:t[e]},properties:{handleType:`vertex`,index:e}});for(let e=0;e<t.length-1;e++){let r=t[e],i=t[e+1];n.push({type:`Feature`,geometry:{type:`Point`,coordinates:[(r[0]+i[0])/2,(r[1]+i[1])/2]},properties:{handleType:`midpoint`,index:e}})}let r=0,i=0;for(let e of t)r+=e[0],i+=e[1];return r/=t.length,i/=t.length,n.push({type:`Feature`,geometry:{type:`Point`,coordinates:[r,i]},properties:{handleType:`move`,index:0}}),{type:`FeatureCollection`,features:n}}createEditLayers(){this.map.getSource(this.editSourceId)||(I(this.map),this.map.addSource(this.editSourceId,{type:`geojson`,data:this.getEditHandleGeoJSON()}),this.map.addLayer({id:this.editMidpointLayerId,type:`circle`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`midpoint`],paint:{"circle-radius":4,"circle-color":`#3388ff`,"circle-opacity":.5,"circle-stroke-color":`#3388ff`,"circle-stroke-width":1}}),this.map.addLayer({id:this.editHandleLayerId,type:`circle`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`vertex`],paint:{"circle-radius":6,"circle-color":`#ffffff`,"circle-stroke-color":`#3388ff`,"circle-stroke-width":2}}),this.map.addLayer({id:this.editMoveLayerId,type:`symbol`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`move`],layout:{"icon-image":ae,"icon-allow-overlap":!0,"icon-ignore-placement":!0}}))}removeEditLayers(){this.map.getLayer(this.editMoveLayerId)&&this.map.removeLayer(this.editMoveLayerId),this.map.getLayer(this.editHandleLayerId)&&this.map.removeLayer(this.editHandleLayerId),this.map.getLayer(this.editMidpointLayerId)&&this.map.removeLayer(this.editMidpointLayerId),this.map.getSource(this.editSourceId)&&this.map.removeSource(this.editSourceId)}refreshEditHandles(e){let t=this.map.getSource(this.editSourceId);t&&t.setData(this.getEditHandleGeoJSON(e))}setEditing(e){this.isEditing!==e&&(this.isEditing=e,this.initialized&&(e?this.createEditLayers():this.removeEditLayers()))}getEditHandleAt(e,t){if(!this.isEditing)return null;let n=this.entity.coordinates;if(!n||n.length<2)return null;let r=this.map.project(e),i=0,a=0;for(let e of n)i+=e[0],a+=e[1];i/=n.length,a/=n.length;let o=this.map.project([i,a]),s=r.x-o.x,c=r.y-o.y;if(s*s+c*c<=144)return{type:`move`,index:0,position:[i,a]};for(let e=0;e<n.length;e++){let t=this.map.project(n[e]),i=r.x-t.x,a=r.y-t.y;if(i*i+a*a<=100)return{type:`vertex`,index:e,position:n[e]}}for(let e=0;e<n.length-1;e++){let t=n[e],i=n[e+1],a=[(t[0]+i[0])/2,(t[1]+i[1])/2],o=this.map.project(a),s=r.x-o.x,c=r.y-o.y;if(s*s+c*c<=100)return{type:`midpoint`,index:e,position:a}}return null}offsetCoordinates(e,t,n){let r=n[0]-t[0],i=n[1]-t[1];return e.map(e=>[e[0]+r,e[1]+i])}applyHandleMove(e,t){let n;e.type===`move`?n=this.offsetCoordinates(this.entity.coordinates,e.position,t):(n=[...this.entity.coordinates],n[e.index]=t);let r={...this.entity,coordinates:n};this.entity=r;let i=this.map.getSource(this.sourceId);return i&&i.setData(this.getGeoJSON()),this.refreshEditHandles(),r}updateEditPreview(e,t){let n;e.type===`move`?n=this.offsetCoordinates(this.entity.coordinates,e.position,t):(n=[...this.entity.coordinates],n[e.index]=t);let r=this.entity;this.entity={...this.entity,coordinates:n};let i=this.map.getSource(this.sourceId);i&&i.setData(this.getGeoJSON()),this.entity=r,this.refreshEditHandles(n)}cancelEditPreview(){let e=this.map.getSource(this.sourceId);e&&e.setData(this.getGeoJSON()),this.refreshEditHandles()}deleteVertex(e){let t=this.entity.coordinates;if(!t||t.length<=2)return null;let n=t.filter((t,n)=>n!==e),r={...this.entity,coordinates:n};this.entity=r;let i=this.map.getSource(this.sourceId);return i&&i.setData(this.getGeoJSON()),this.refreshEditHandles(),r}addVertex(e,t){let n=[...this.entity.coordinates];n.splice(e+1,0,t);let r={...this.entity,coordinates:n};this.entity=r;let i=this.map.getSource(this.sourceId);return i&&i.setData(this.getGeoJSON()),this.refreshEditHandles(),r}destroy(){this.initialized&&=(this.removeEditLayers(),this.map.getLayer(this.lengthLayerId)&&this.map.removeLayer(this.lengthLayerId),this.map.getLayer(this.labelLayerId)&&this.map.removeLayer(this.labelLayerId),this.map.getLayer(this.lineLayerId)&&this.map.removeLayer(this.lineLayerId),this.map.getSource(this.sourceId)&&this.map.removeSource(this.sourceId),!1)}};function me(e,t,n=64){let[r,i]=e,a=[],o=t/6371e3,s=i*Math.PI/180;for(let e=0;e<=n;e++){let t=e/n*2*Math.PI,c=o*Math.cos(t),l=o*Math.sin(t)/Math.cos(s),u=i+c*180/Math.PI,d=r+l*180/Math.PI;a.push([d,u])}return a}var he=class e{static{this.GRADIENT_STEPS=10}static{this.DEFAULTS={strokeColor:`#3388ff`,strokeWidth:2,strokeOpacity:1,fillColor:`#3388ff`,fillOpacity:.2,fillType:`solid`,showCenterPoint:!0,centerPointRadius:4}}constructor(e,t,n,r,i,a){this.isSelected=!1,this.initialized=!1,this.gradientLayerIds=[],this.gradientSourceIds=[],this.isEditing=!1,this.map=e,this.entity=t,this.globalNameConfig=n,this.globalSelectNameConfig=r,this.globalAreaConfig=i,this.globalCircleConfig=a,this.sourceId=`circle-source-${t.id}`,this.fillLayerId=`circle-fill-${t.id}`,this.strokeLayerId=`circle-stroke-${t.id}`,this.centerPointLayerId=`circle-center-${t.id}`,this.labelLayerId=`circle-label-${t.id}`,this.areaLayerId=`circle-area-${t.id}`,this.radiusLineLayerId=`circle-radius-line-${t.id}`,this.radiusLabelLayerId=`circle-radius-label-${t.id}`,this.editSourceId=`circle-edit-source-${t.id}`,this.editHandleLayerId=`circle-edit-handles-${t.id}`,this.editMoveLayerId=`circle-edit-move-${t.id}`,this.initLayers()}get nameStyle(){return x(this.entity.nameConfig,this.globalNameConfig,h)}get selectNameStyle(){return x(this.entity.selectNameConfig,this.globalSelectNameConfig,g)}get areaStyle(){return x(this.entity.areaConfig,this.globalAreaConfig,_)}get radiusTextStyle(){return x(this.entity.circleConfig,this.globalCircleConfig,h)}get radiusLineStyle(){return y(this.entity.circleConfig?.radiusLine,this.globalCircleConfig?.radiusLine,v)}initLayers(){if(!this.initialized)try{let t=this.getGeoJSON();this.map.addSource(this.sourceId,{type:`geojson`,data:t});let n=this.entity.confidence??1,r=P(n);if((this.entity.fillType??e.DEFAULTS.fillType)===`radial-gradient`?this.initGradientLayers(r):this.map.addLayer({id:this.fillLayerId,type:`fill`,source:this.sourceId,filter:[`==`,[`get`,`type`],`circle`],paint:{"fill-color":this.entity.fillColor??e.DEFAULTS.fillColor,"fill-opacity":(this.entity.fillOpacity??e.DEFAULTS.fillOpacity)*r}}),this.map.addLayer({id:this.strokeLayerId,type:`line`,source:this.sourceId,filter:[`==`,[`get`,`type`],`circle`],layout:{"line-join":`round`,"line-cap":`round`},paint:{"line-color":this.isSelected?`#ffcc00`:this.entity.strokeColor??e.DEFAULTS.strokeColor,"line-width":this.entity.strokeWidth??e.DEFAULTS.strokeWidth,"line-opacity":(this.entity.strokeOpacity??e.DEFAULTS.strokeOpacity)*r}}),(this.entity.showCenterPoint??e.DEFAULTS.showCenterPoint)&&this.map.addLayer({id:this.centerPointLayerId,type:`circle`,source:this.sourceId,filter:[`==`,[`get`,`type`],`center`],paint:{"circle-radius":this.entity.centerPointRadius??e.DEFAULTS.centerPointRadius,"circle-color":this.entity.centerPointColor??this.entity.fillColor??e.DEFAULTS.fillColor,"circle-opacity":r,"circle-stroke-width":1,"circle-stroke-color":`#ffffff`,"circle-stroke-opacity":r*.8}}),this.entity.name&&this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`type`],`center`],layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.8],"text-allow-overlap":!0},paint:{"text-color":this.isSelected?this.selectNameStyle.fillColor:this.nameStyle.fillColor,"text-halo-color":this.isSelected?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor,"text-halo-width":this.isSelected?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth,"text-opacity":r}}),this.entity.showArea&&this.map.addLayer({id:this.areaLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`type`],`center`],layout:{"text-field":[`get`,`area`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`bottom`,"text-offset":[0,-.8],"text-allow-overlap":!0},paint:{"text-color":this.areaStyle.fillColor,"text-halo-color":this.areaStyle.strokeColor,"text-halo-width":this.areaStyle.strokeWidth,"text-opacity":r}}),this.entity.showRadius){let e=this.radiusLineStyle;this.map.addLayer({id:this.radiusLineLayerId,type:`line`,source:this.sourceId,filter:[`==`,[`get`,`type`],`radius-line`],layout:{"line-cap":`round`},paint:{"line-color":e.color,"line-width":e.width,"line-opacity":e.opacity*r,"line-dasharray":e.dashArray}}),this.map.addLayer({id:this.radiusLabelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`type`],`radius-label`],layout:{"text-field":[`get`,`radius`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-offset":[0,-.8],"text-allow-overlap":!0},paint:{"text-color":this.radiusTextStyle.fillColor,"text-halo-color":this.radiusTextStyle.strokeColor,"text-halo-width":this.radiusTextStyle.strokeWidth,"text-opacity":r}})}this.initialized=!0}catch{this.map.once(`idle`,()=>this.initLayers())}}initGradientLayers(t){let{center:n,radius:r}=this.entity,i=this.entity.fillColor??e.DEFAULTS.fillColor,a=this.entity.fillOpacity??e.DEFAULTS.fillOpacity,o=this.parseColor(i);for(let i=0;i<e.GRADIENT_STEPS;i++){let s=1-i/e.GRADIENT_STEPS,c=r*s,l=i/(e.GRADIENT_STEPS-1)*a*t,u=`${this.sourceId}-gradient-${i}`,d=`${this.fillLayerId}-gradient-${i}`,f=me(n,c);this.map.addSource(u,{type:`geojson`,data:{type:`Feature`,geometry:{type:`Polygon`,coordinates:[f]},properties:{}}}),this.map.addLayer({id:d,type:`fill`,source:u,paint:{"fill-color":`rgb(${o.r}, ${o.g}, ${o.b})`,"fill-opacity":l}}),this.gradientSourceIds.push(u),this.gradientLayerIds.push(d)}}parseColor(e){if(e.startsWith(`#`)){let t=e.slice(1);return{r:parseInt(t.slice(0,2),16),g:parseInt(t.slice(2,4),16),b:parseInt(t.slice(4,6),16)}}let t=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);return t?{r:parseInt(t[1],10),g:parseInt(t[2],10),b:parseInt(t[3],10)}:{r:51,g:136,b:255}}getGeoJSON(){let{center:e,radius:t}=this.entity,n=[{type:`Feature`,geometry:{type:`Polygon`,coordinates:[me(e,t)]},properties:{type:`circle`}},{type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:{type:`center`,name:this.entity.name||``,area:this.entity.showArea?A(this.getArea()):``}}];if(this.entity.showRadius){let r=this.entity.radiusAngle??90,i=D(e,t,r),a=[(e[0]+i[0])/2,(e[1]+i[1])/2];n.push({type:`Feature`,geometry:{type:`LineString`,coordinates:[e,i]},properties:{type:`radius-line`}},{type:`Feature`,geometry:{type:`Point`,coordinates:a},properties:{type:`radius-label`,radius:j(t)}})}return{type:`FeatureCollection`,features:n}}getArea(){return Math.PI*this.entity.radius*this.entity.radius}getEntityId(){return this.entity.id}getCenter(){return this.entity.center}getBounds(){let{center:e,radius:t}=this.entity,[n,r]=e,i=t/6371e3,a=r*Math.PI/180,o=i*180/Math.PI,s=i*180/Math.PI/Math.cos(a);return[[n-s,r-o],[n+s,r+o]]}getLayerId(){return this.gradientLayerIds.length>0?this.gradientLayerIds[this.gradientLayerIds.length-1]:this.fillLayerId}getLabelLayerId(){return this.entity.name?this.labelLayerId:null}setSelected(t){this.isSelected!==t&&(this.isSelected=t,this.initialized&&(this.map.getLayer(this.strokeLayerId)&&this.map.setPaintProperty(this.strokeLayerId,`line-color`,t?`#ffcc00`:this.entity.strokeColor??e.DEFAULTS.strokeColor),this.map.getLayer(this.labelLayerId)&&(this.map.setPaintProperty(this.labelLayerId,`text-color`,t?this.selectNameStyle.fillColor:this.nameStyle.fillColor),this.map.setPaintProperty(this.labelLayerId,`text-halo-color`,t?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor),this.map.setPaintProperty(this.labelLayerId,`text-halo-width`,t?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth))))}isPointInEntity(e){let{center:t,radius:n}=this.entity;return this.calculateDistance(e,t)<=n}calculateDistance(e,t){let[n,r]=e,[i,a]=t,o=(a-r)*Math.PI/180,s=(i-n)*Math.PI/180,c=Math.sin(o/2)*Math.sin(o/2)+Math.cos(r*Math.PI/180)*Math.cos(a*Math.PI/180)*Math.sin(s/2)*Math.sin(s/2);return 6371e3*(2*Math.atan2(Math.sqrt(c),Math.sqrt(1-c)))}update(t){let n=this.entity;if(this.entity=t,!this.initialized)return;let r=t.confidence??1,i=P(r),a=t.fillType??e.DEFAULTS.fillType,o=n.fillType??e.DEFAULTS.fillType;if(a!==o){this.destroy(),this.initialized=!1,this.gradientLayerIds=[],this.gradientSourceIds=[],this.initLayers();return}if(n.center!==t.center||n.radius!==t.radius||n.name!==t.name||n.showArea!==t.showArea||n.showRadius!==t.showRadius||n.radiusAngle!==t.radiusAngle){let e=this.map.getSource(this.sourceId);if(e&&e.setData(this.getGeoJSON()),a===`radial-gradient`&&this.updateGradientLayers(i),!n.name&&t.name&&!this.map.getLayer(this.labelLayerId)?this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`type`],`center`],layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.8],"text-allow-overlap":!0},paint:{"text-color":this.isSelected?this.selectNameStyle.fillColor:this.nameStyle.fillColor,"text-halo-color":this.isSelected?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor,"text-halo-width":this.isSelected?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth,"text-opacity":i}}):n.name&&!t.name&&this.map.getLayer(this.labelLayerId)&&this.map.removeLayer(this.labelLayerId),!n.showArea&&t.showArea&&!this.map.getLayer(this.areaLayerId)?this.map.addLayer({id:this.areaLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`type`],`center`],layout:{"text-field":[`get`,`area`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`bottom`,"text-offset":[0,-.8],"text-allow-overlap":!0},paint:{"text-color":this.areaStyle.fillColor,"text-halo-color":this.areaStyle.strokeColor,"text-halo-width":this.areaStyle.strokeWidth,"text-opacity":i}}):n.showArea&&!t.showArea&&this.map.getLayer(this.areaLayerId)&&this.map.removeLayer(this.areaLayerId),!n.showRadius&&t.showRadius){let e=this.radiusLineStyle;this.map.getLayer(this.radiusLineLayerId)||this.map.addLayer({id:this.radiusLineLayerId,type:`line`,source:this.sourceId,filter:[`==`,[`get`,`type`],`radius-line`],layout:{"line-cap":`round`},paint:{"line-color":e.color,"line-width":e.width,"line-opacity":e.opacity*i,"line-dasharray":e.dashArray}}),this.map.getLayer(this.radiusLabelLayerId)||this.map.addLayer({id:this.radiusLabelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`type`],`radius-label`],layout:{"text-field":[`get`,`radius`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-offset":[0,-.8],"text-allow-overlap":!0,"text-rotate":[`get`,`textRotation`],"text-rotation-alignment":`map`},paint:{"text-color":this.radiusTextStyle.fillColor,"text-halo-color":this.radiusTextStyle.strokeColor,"text-halo-width":this.radiusTextStyle.strokeWidth,"text-opacity":i}})}else n.showRadius&&!t.showRadius&&(this.map.getLayer(this.radiusLabelLayerId)&&this.map.removeLayer(this.radiusLabelLayerId),this.map.getLayer(this.radiusLineLayerId)&&this.map.removeLayer(this.radiusLineLayerId))}if(a===`solid`?(n.fillColor!==t.fillColor||n.fillOpacity!==t.fillOpacity||n.confidence!==t.confidence)&&this.map.getLayer(this.fillLayerId)&&(this.map.setPaintProperty(this.fillLayerId,`fill-color`,t.fillColor??e.DEFAULTS.fillColor),this.map.setPaintProperty(this.fillLayerId,`fill-opacity`,(t.fillOpacity??e.DEFAULTS.fillOpacity)*i)):(n.fillColor!==t.fillColor||n.fillOpacity!==t.fillOpacity||n.confidence!==t.confidence)&&this.updateGradientLayerStyles(i),(n.strokeColor!==t.strokeColor||n.strokeWidth!==t.strokeWidth||n.strokeOpacity!==t.strokeOpacity||n.confidence!==t.confidence)&&this.map.getLayer(this.strokeLayerId)&&(this.isSelected||this.map.setPaintProperty(this.strokeLayerId,`line-color`,t.strokeColor??e.DEFAULTS.strokeColor),this.map.setPaintProperty(this.strokeLayerId,`line-width`,t.strokeWidth??e.DEFAULTS.strokeWidth),this.map.setPaintProperty(this.strokeLayerId,`line-opacity`,(t.strokeOpacity??e.DEFAULTS.strokeOpacity)*i)),(n.centerPointColor!==t.centerPointColor||n.centerPointRadius!==t.centerPointRadius||n.fillColor!==t.fillColor||n.confidence!==t.confidence)&&this.map.getLayer(this.centerPointLayerId)&&(this.map.setPaintProperty(this.centerPointLayerId,`circle-color`,t.centerPointColor??t.fillColor??e.DEFAULTS.fillColor),this.map.setPaintProperty(this.centerPointLayerId,`circle-radius`,t.centerPointRadius??e.DEFAULTS.centerPointRadius),this.map.setPaintProperty(this.centerPointLayerId,`circle-opacity`,i)),n.confidence!==t.confidence){if(this.map.getLayer(this.labelLayerId)&&this.map.setPaintProperty(this.labelLayerId,`text-opacity`,i),this.map.getLayer(this.areaLayerId)&&this.map.setPaintProperty(this.areaLayerId,`text-opacity`,i),this.map.getLayer(this.radiusLineLayerId)){let e=this.radiusLineStyle;this.map.setPaintProperty(this.radiusLineLayerId,`line-opacity`,e.opacity*i)}this.map.getLayer(this.radiusLabelLayerId)&&this.map.setPaintProperty(this.radiusLabelLayerId,`text-opacity`,i)}}updateGradientLayers(t){let{center:n,radius:r}=this.entity;for(let t=0;t<this.gradientSourceIds.length;t++){let i=1-t/e.GRADIENT_STEPS,a=r*i,o=me(n,a),s=this.map.getSource(this.gradientSourceIds[t]);s&&s.setData({type:`Feature`,geometry:{type:`Polygon`,coordinates:[o]},properties:{}})}this.updateGradientLayerStyles(t)}updateGradientLayerStyles(t){let n=this.entity.fillColor??e.DEFAULTS.fillColor,r=this.entity.fillOpacity??e.DEFAULTS.fillOpacity,i=this.parseColor(n);for(let n=0;n<this.gradientLayerIds.length;n++){let a=n/(e.GRADIENT_STEPS-1)*r*t;this.map.getLayer(this.gradientLayerIds[n])&&(this.map.setPaintProperty(this.gradientLayerIds[n],`fill-color`,`rgb(${i.r}, ${i.g}, ${i.b})`),this.map.setPaintProperty(this.gradientLayerIds[n],`fill-opacity`,a))}}static{this.EDGE_BEARINGS=[0,90,180,270]}getEditHandlePositions(t,n){let r=t??this.entity.center,i=n??this.entity.radius,a=[];for(let t=0;t<e.EDGE_BEARINGS.length;t++)a.push({type:`edge`,index:t,position:D(r,i,e.EDGE_BEARINGS[t])});return a.push({type:`move`,index:0,position:r}),a}getEditHandleGeoJSON(e,t){return{type:`FeatureCollection`,features:this.getEditHandlePositions(e,t).map(e=>({type:`Feature`,geometry:{type:`Point`,coordinates:e.position},properties:{handleType:e.type,index:e.index}}))}}createEditLayers(){this.map.getSource(this.editSourceId)||(I(this.map),this.map.addSource(this.editSourceId,{type:`geojson`,data:this.getEditHandleGeoJSON()}),this.map.addLayer({id:this.editHandleLayerId,type:`circle`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`edge`],paint:{"circle-radius":6,"circle-color":`#ffffff`,"circle-stroke-color":`#3388ff`,"circle-stroke-width":2}}),this.map.addLayer({id:this.editMoveLayerId,type:`symbol`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`move`],layout:{"icon-image":ae,"icon-allow-overlap":!0,"icon-ignore-placement":!0}}))}removeEditLayers(){this.map.getLayer(this.editMoveLayerId)&&this.map.removeLayer(this.editMoveLayerId),this.map.getLayer(this.editHandleLayerId)&&this.map.removeLayer(this.editHandleLayerId),this.map.getSource(this.editSourceId)&&this.map.removeSource(this.editSourceId)}refreshEditHandles(e,t){let n=this.map.getSource(this.editSourceId);n&&n.setData(this.getEditHandleGeoJSON(e,t))}setEditing(e){this.isEditing!==e&&(this.isEditing=e,this.initialized&&(e?this.createEditLayers():this.removeEditLayers()))}getEditHandleAt(e,t){if(!this.isEditing)return null;let n=this.map.project(e),r=this.getEditHandlePositions(),i=r.find(e=>e.type===`move`);if(i){let e=this.map.project(i.position),t=n.x-e.x,r=n.y-e.y;if(t*t+r*r<=144)return{type:`move`,index:i.index,position:i.position}}for(let e of r){if(e.type===`move`)continue;let t=this.map.project(e.position),r=n.x-t.x,i=n.y-t.y;if(r*r+i*i<=100)return{type:e.type,index:e.index,position:e.position}}return null}applyHandleMove(e,t){let n;if(e.type===`move`)n={...this.entity,center:t};else{let e=this.calculateDistance(this.entity.center,t);n={...this.entity,radius:e}}this.entity=n;let r=this.map.getSource(this.sourceId);return r&&r.setData(this.getGeoJSON()),this.refreshEditHandles(),n}updateEditPreview(e,t){let n,r;e.type===`move`?(n=t,r=this.entity.radius):(n=this.entity.center,r=this.calculateDistance(this.entity.center,t));let i=this.entity;this.entity={...this.entity,center:n,radius:r};let a=this.map.getSource(this.sourceId);a&&a.setData(this.getGeoJSON()),this.entity=i,this.refreshEditHandles(n,r)}cancelEditPreview(){let e=this.map.getSource(this.sourceId);e&&e.setData(this.getGeoJSON()),this.refreshEditHandles()}destroy(){if(this.initialized){this.removeEditLayers(),this.map.getLayer(this.radiusLabelLayerId)&&this.map.removeLayer(this.radiusLabelLayerId),this.map.getLayer(this.radiusLineLayerId)&&this.map.removeLayer(this.radiusLineLayerId),this.map.getLayer(this.areaLayerId)&&this.map.removeLayer(this.areaLayerId),this.map.getLayer(this.labelLayerId)&&this.map.removeLayer(this.labelLayerId),this.map.getLayer(this.centerPointLayerId)&&this.map.removeLayer(this.centerPointLayerId),this.map.getLayer(this.strokeLayerId)&&this.map.removeLayer(this.strokeLayerId),this.map.getLayer(this.fillLayerId)&&this.map.removeLayer(this.fillLayerId);for(let e of this.gradientLayerIds)this.map.getLayer(e)&&this.map.removeLayer(e);for(let e of this.gradientSourceIds)this.map.getSource(e)&&this.map.removeSource(e);this.map.getSource(this.sourceId)&&this.map.removeSource(this.sourceId),this.initialized=!1}}};const L={gradientAnimation:`flicker`,animationSpeed:1,fillColor:`#3388ff`,fillOpacity:.6,strokeColor:`#3388ff`,strokeWidth:2,strokeOpacity:1,showCenterPoint:!0,centerPointRadius:4};function ge(e,t){let n=D(e,t,0),r=D(e,t,90),i=D(e,t,180),a=D(e,t,270)[0],o=r[0],s=i[1],c=n[1];return[[a,c],[o,c],[o,s],[a,s]]}var _e=class e extends re{static{this.EDGE_BEARINGS=[0,90,180,270]}constructor(e,t,n,r,i,a){super(e,t,`canvas-circle`,n,r,i),this.animationFrameId=null,this.animationTime=0,this.pulsePhase=0,this.isEditing=!1,this.editSourceId=``,this.editHandleLayerId=``,this.editMoveLayerId=``,this.globalCircleConfig=a,this.radiusSourceId=`canvas-circle-radius-source-${String(t.id)}`,this.radiusLineLayerId=`canvas-circle-radius-line-${String(t.id)}`,this.radiusLabelLayerId=`canvas-circle-radius-label-${String(t.id)}`,this.editSourceId=`canvas-circle-edit-source-${String(t.id)}`,this.editHandleLayerId=`canvas-circle-edit-handles-${String(t.id)}`,this.editMoveLayerId=`canvas-circle-edit-move-${String(t.id)}`;let o=ge(t.center,t.radius);this.init(o),this.initRadiusLayer(),t.isAnimating&&this.startAnimation()}getArea(){return Math.PI*this.entity.radius*this.entity.radius}getAreaLabelAnchor(){return{anchor:`bottom`,offset:[0,-.8]}}get radiusTextStyle(){return x(this.entity.circleConfig,this.globalCircleConfig,h)}get radiusLineStyleResolved(){return y(this.entity.circleConfig?.radiusLine,this.globalCircleConfig?.radiusLine,v)}initRadiusLayer(){if(!this.entity.showRadius)return;let{center:e,radius:t}=this.entity,n=this.entity.radiusAngle??90,r=D(e,t,n),i=[(e[0]+r[0])/2,(e[1]+r[1])/2],a=P(this.entity.confidence),o=this.radiusLineStyleResolved;this.map.addSource(this.radiusSourceId,{type:`geojson`,data:{type:`FeatureCollection`,features:[{type:`Feature`,geometry:{type:`LineString`,coordinates:[e,r]},properties:{featureType:`line`}},{type:`Feature`,geometry:{type:`Point`,coordinates:i},properties:{featureType:`label`,radius:j(t)}}]}}),this.map.addLayer({id:this.radiusLineLayerId,type:`line`,source:this.radiusSourceId,filter:[`==`,[`get`,`featureType`],`line`],layout:{"line-cap":`round`},paint:{"line-color":o.color,"line-width":o.width,"line-opacity":o.opacity*a,"line-dasharray":o.dashArray}}),this.map.addLayer({id:this.radiusLabelLayerId,type:`symbol`,source:this.radiusSourceId,filter:[`==`,[`get`,`featureType`],`label`],layout:{"text-field":[`get`,`radius`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-offset":[0,-.8],"text-allow-overlap":!0},paint:{"text-color":this.radiusTextStyle.fillColor,"text-halo-color":this.radiusTextStyle.strokeColor,"text-halo-width":this.radiusTextStyle.strokeWidth,"text-opacity":a}})}updateRadiusLayer(){if(this.entity.showRadius){let e=this.map.getSource(this.radiusSourceId);if(e){let{center:t,radius:n}=this.entity,r=this.entity.radiusAngle??90,i=D(t,n,r),a=[(t[0]+i[0])/2,(t[1]+i[1])/2];e.setData({type:`FeatureCollection`,features:[{type:`Feature`,geometry:{type:`LineString`,coordinates:[t,i]},properties:{featureType:`line`}},{type:`Feature`,geometry:{type:`Point`,coordinates:a},properties:{featureType:`label`,radius:j(n)}}]})}else this.initRadiusLayer()}else this.map.getLayer(this.radiusLabelLayerId)&&this.map.removeLayer(this.radiusLabelLayerId),this.map.getLayer(this.radiusLineLayerId)&&this.map.removeLayer(this.radiusLineLayerId),this.map.getSource(this.radiusSourceId)&&this.map.removeSource(this.radiusSourceId)}getEntityCenter(){return this.entity.center}getEntityBounds(){let e=ge(this.entity.center,this.entity.radius),t=e[3][0],n=e[3][1],r=e[1][0],i=e[1][1];return[[t,n],[r,i]]}draw(){let e=this.ctx,t=this.entity;switch(e.clearRect(0,0,512,512),e.globalAlpha=P(t.confidence),t.gradientAnimation??L.gradientAnimation){case`static`:this.drawStaticGradient(e);break;case`flicker`:this.drawFlickerGradient(e);break;case`breath`:this.drawBreathGradient(e);break;case`pulse`:this.drawPulseGradient(e);break;default:this.drawStaticGradient(e)}this.drawStroke(e),(t.showCenterPoint??L.showCenterPoint)&&this.drawCenterPoint(e),e.globalAlpha=1}drawStaticGradient(e){let t=this.entity.fillColor??L.fillColor,n=this.entity.fillOpacity??L.fillOpacity,r=e.createRadialGradient(256,256,0,256,256,254),i=this.parseColor(t);r.addColorStop(0,`rgba(${i.r}, ${i.g}, ${i.b}, ${n})`),r.addColorStop(.7,`rgba(${i.r}, ${i.g}, ${i.b}, ${n*.5})`),r.addColorStop(1,`rgba(${i.r}, ${i.g}, ${i.b}, 0)`),e.beginPath(),e.arc(256,256,254,0,Math.PI*2),e.fillStyle=r,e.fill()}drawFlickerGradient(e){let t=this.entity.fillColor??L.fillColor,n=this.entity.fillOpacity??L.fillOpacity,r=this.entity.animationSpeed??L.animationSpeed,i=.5+.5*Math.sin(this.animationTime*r*8),a=n*(.3+.7*i),o=e.createRadialGradient(256,256,0,256,256,254),s=this.parseColor(t);o.addColorStop(0,`rgba(${s.r}, ${s.g}, ${s.b}, ${a})`),o.addColorStop(.7,`rgba(${s.r}, ${s.g}, ${s.b}, ${a*.5})`),o.addColorStop(1,`rgba(${s.r}, ${s.g}, ${s.b}, 0)`),e.beginPath(),e.arc(256,256,254,0,Math.PI*2),e.fillStyle=o,e.fill()}drawBreathGradient(e){let t=this.entity.fillColor??L.fillColor,n=this.entity.fillOpacity??L.fillOpacity,r=this.entity.animationSpeed??L.animationSpeed,i=.5+.5*Math.sin(this.animationTime*r*2),a=n*(.2+.8*i),o=e.createRadialGradient(256,256,0,256,256,254),s=this.parseColor(t);o.addColorStop(0,`rgba(${s.r}, ${s.g}, ${s.b}, ${a})`),o.addColorStop(.7,`rgba(${s.r}, ${s.g}, ${s.b}, ${a*.5})`),o.addColorStop(1,`rgba(${s.r}, ${s.g}, ${s.b}, 0)`),e.beginPath(),e.arc(256,256,254,0,Math.PI*2),e.fillStyle=o,e.fill()}drawPulseGradient(e){let t=this.entity.fillColor??L.fillColor,n=this.entity.fillOpacity??L.fillOpacity,r=this.parseColor(t),i=e.createRadialGradient(256,256,0,256,256,254);i.addColorStop(0,`rgba(${r.r}, ${r.g}, ${r.b}, ${n*.3})`),i.addColorStop(1,`rgba(${r.r}, ${r.g}, ${r.b}, 0)`),e.beginPath(),e.arc(256,256,254,0,Math.PI*2),e.fillStyle=i,e.fill();for(let t=0;t<3;t++){let i=(this.pulsePhase+t/3)%1,a=254*i,o=n*(1-i)*.6;a>0&&o>0&&(e.beginPath(),e.arc(256,256,a,0,Math.PI*2),e.strokeStyle=`rgba(${r.r}, ${r.g}, ${r.b}, ${o})`,e.lineWidth=3,e.stroke())}}drawStroke(e){let t=this.entity.strokeColor??L.strokeColor,n=this.entity.strokeWidth??L.strokeWidth,r=this.entity.strokeOpacity??L.strokeOpacity;n>0&&r>0&&(e.beginPath(),e.arc(256,256,254-n/2,0,Math.PI*2),e.strokeStyle=this.colorWithAlpha(t,r),e.lineWidth=n,e.stroke())}drawCenterPoint(e){let t=this.entity.centerPointColor??this.entity.fillColor??L.fillColor,n=(this.entity.centerPointRadius??L.centerPointRadius)*2;e.beginPath(),e.arc(256,256,n,0,Math.PI*2),e.fillStyle=t,e.fill(),e.strokeStyle=`white`,e.lineWidth=2,e.stroke()}parseColor(e){if(e.startsWith(`#`)){let t=e.slice(1);return{r:parseInt(t.slice(0,2),16),g:parseInt(t.slice(2,4),16),b:parseInt(t.slice(4,6),16)}}let t=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);return t?{r:parseInt(t[1],10),g:parseInt(t[2],10),b:parseInt(t[3],10)}:{r:51,g:136,b:255}}startAnimation(){if(this.animationFrameId!==null||this.isDestroyed)return;let e=this.entity.animationSpeed??L.animationSpeed,t=performance.now(),n=r=>{if(this.isDestroyed)return;let i=(r-t)/1e3;t=r,this.animationTime+=i,this.pulsePhase+=i*e*.5,this.pulsePhase>=1&&--this.pulsePhase,this.draw(),this.animationFrameId=requestAnimationFrame(n)};this.animationFrameId=requestAnimationFrame(n),this.map.getSource(this.sourceId)?.play()}stopAnimation(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.map.getSource(this.sourceId)?.pause()}update(e){let t=this.entity;if(this.entity=e,t.center[0]!==e.center[0]||t.center[1]!==e.center[1]||t.radius!==e.radius){let t=ge(e.center,e.radius);this.updateSourceCoordinates(t)}(t.center[0]!==e.center[0]||t.center[1]!==e.center[1]||t.name!==e.name||t.radius!==e.radius||t.confidence!==e.confidence)&&this.updateLabel(),(t.showArea!==e.showArea||t.radius!==e.radius||t.confidence!==e.confidence)&&this.updateAreaLabel(),(t.showRadius!==e.showRadius||t.radius!==e.radius||t.radiusAngle!==e.radiusAngle||t.center[0]!==e.center[0]||t.center[1]!==e.center[1]||t.confidence!==e.confidence)&&this.updateRadiusLayer(),t.isAnimating!==e.isAnimating&&(e.isAnimating?this.startAnimation():this.stopAnimation()),e.isAnimating||this.draw()}isPointInEntity(e){let{center:t,radius:n}=this.entity,r=e[0]-t[0],i=e[1]-t[1],a=111320*Math.cos(t[1]*Math.PI/180);return Math.sqrt((r*a)**2+(i*110540)**2)<=n}destroy(){this.removeEditLayers(),this.stopAnimation(),this.map.getLayer(this.radiusLabelLayerId)&&this.map.removeLayer(this.radiusLabelLayerId),this.map.getLayer(this.radiusLineLayerId)&&this.map.removeLayer(this.radiusLineLayerId),this.map.getSource(this.radiusSourceId)&&this.map.removeSource(this.radiusSourceId),super.destroy()}getEditHandlePositions(t,n){let r=t??this.entity.center,i=n??this.entity.radius,a=[];for(let t=0;t<e.EDGE_BEARINGS.length;t++)a.push({type:`edge`,index:t,position:D(r,i,e.EDGE_BEARINGS[t])});return a.push({type:`move`,index:0,position:r}),a}getEditHandleGeoJSON(e,t){return{type:`FeatureCollection`,features:this.getEditHandlePositions(e,t).map(e=>({type:`Feature`,geometry:{type:`Point`,coordinates:e.position},properties:{handleType:e.type,index:e.index}}))}}createEditLayers(){this.map.getSource(this.editSourceId)||(I(this.map),this.map.addSource(this.editSourceId,{type:`geojson`,data:this.getEditHandleGeoJSON()}),this.map.addLayer({id:this.editHandleLayerId,type:`circle`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`edge`],paint:{"circle-radius":6,"circle-color":`#ffffff`,"circle-stroke-color":`#3388ff`,"circle-stroke-width":2}}),this.map.addLayer({id:this.editMoveLayerId,type:`symbol`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`move`],layout:{"icon-image":ae,"icon-allow-overlap":!0,"icon-ignore-placement":!0}}))}removeEditLayers(){this.map.getLayer(this.editMoveLayerId)&&this.map.removeLayer(this.editMoveLayerId),this.map.getLayer(this.editHandleLayerId)&&this.map.removeLayer(this.editHandleLayerId),this.map.getSource(this.editSourceId)&&this.map.removeSource(this.editSourceId)}refreshEditHandles(e,t){let n=this.map.getSource(this.editSourceId);n&&n.setData(this.getEditHandleGeoJSON(e,t))}setEditing(e){this.isEditing!==e&&(this.isEditing=e,e?this.createEditLayers():this.removeEditLayers())}getEditHandleAt(e,t){if(!this.isEditing)return null;let n=this.map.project(e),r=this.getEditHandlePositions(),i=r.find(e=>e.type===`move`);if(i){let e=this.map.project(i.position),t=n.x-e.x,r=n.y-e.y;if(t*t+r*r<=144)return{type:`move`,index:i.index,position:i.position}}for(let e of r){if(e.type===`move`)continue;let t=this.map.project(e.position),r=n.x-t.x,i=n.y-t.y;if(r*r+i*i<=100)return{type:e.type,index:e.index,position:e.position}}return null}applyHandleMove(e,t){let n;if(e.type===`move`){let r=t[0]-e.position[0],i=t[1]-e.position[1],a=[this.entity.center[0]+r,this.entity.center[1]+i];n={...this.entity,center:a}}else{let e=O(this.entity.center,t);n={...this.entity,radius:e}}this.entity=n;let r=ge(n.center,n.radius);return this.updateSourceCoordinates(r),this.updateLabel(),this.updateAreaLabel(),this.updateRadiusLayer(),this.refreshEditHandles(),n}updateEditPreview(e,t){let n,r;if(e.type===`move`){let i=t[0]-e.position[0],a=t[1]-e.position[1];n=[this.entity.center[0]+i,this.entity.center[1]+a],r=this.entity.radius}else n=this.entity.center,r=O(this.entity.center,t);let i=ge(n,r);this.updateSourceCoordinates(i);let a=this.entity;this.entity={...this.entity,center:n,radius:r},this.updateLabel(),this.entity=a,this.refreshEditHandles(n,r)}cancelEditPreview(){let e=ge(this.entity.center,this.entity.radius);this.updateSourceCoordinates(e),this.updateLabel(),this.refreshEditHandles()}};function ve(e,t){let[n,r]=e,i=t/2/6371e3,a=r*Math.PI/180,o=i*180/Math.PI,s=i*180/Math.PI/Math.cos(a);return[[n-s,r+o],[n+s,r+o],[n+s,r-o],[n-s,r-o],[n-s,r+o]]}var ye=class e{static{this.DEFAULTS={strokeColor:`#3388ff`,strokeWidth:2,strokeOpacity:1,fillColor:`#3388ff`,fillOpacity:.2}}constructor(e,t,n,r,i,a){this.isSelected=!1,this.initialized=!1,this.isEditing=!1,this.map=e,this.entity=t,this.globalNameConfig=n,this.globalSelectNameConfig=r,this.globalAreaConfig=i,this.globalLengthConfig=a,this.sourceId=`square-source-${t.id}`,this.fillLayerId=`square-fill-${t.id}`,this.strokeLayerId=`square-stroke-${t.id}`,this.labelLayerId=`square-label-${t.id}`,this.areaLayerId=`square-area-${t.id}`,this.lengthLayerId=`square-length-${t.id}`,this.editSourceId=`square-edit-source-${t.id}`,this.editHandleLayerId=`square-edit-handles-${t.id}`,this.editMoveLayerId=`square-edit-move-${t.id}`,this.initLayers()}get nameStyle(){return x(this.entity.nameConfig,this.globalNameConfig,h)}get selectNameStyle(){return x(this.entity.selectNameConfig,this.globalSelectNameConfig,g)}get areaStyle(){return x(this.entity.areaConfig,this.globalAreaConfig,_)}get lengthStyle(){return x(this.entity.lengthConfig,this.globalLengthConfig,b)}initLayers(){if(!this.initialized)try{let t=this.getGeoJSON();this.map.addSource(this.sourceId,{type:`geojson`,data:t});let n=this.entity.confidence??1,r=P(n);this.map.addLayer({id:this.fillLayerId,type:`fill`,source:this.sourceId,filter:[`==`,`$type`,`Polygon`],paint:{"fill-color":this.entity.fillColor??e.DEFAULTS.fillColor,"fill-opacity":(this.entity.fillOpacity??e.DEFAULTS.fillOpacity)*r}}),this.map.addLayer({id:this.strokeLayerId,type:`line`,source:this.sourceId,filter:[`==`,`$type`,`Polygon`],layout:{"line-join":`miter`,"line-cap":`square`},paint:{"line-color":this.isSelected?`#ffcc00`:this.entity.strokeColor??e.DEFAULTS.strokeColor,"line-width":this.entity.strokeWidth??e.DEFAULTS.strokeWidth,"line-opacity":(this.entity.strokeOpacity??e.DEFAULTS.strokeOpacity)*r}}),this.entity.name&&this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`label`],layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.8],"text-allow-overlap":!0},paint:{"text-color":this.isSelected?this.selectNameStyle.fillColor:this.nameStyle.fillColor,"text-halo-color":this.isSelected?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor,"text-halo-width":this.isSelected?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth,"text-opacity":r}}),this.entity.showArea&&this.map.addLayer({id:this.areaLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`area`],layout:{"text-field":[`get`,`area`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-allow-overlap":!0},paint:{"text-color":this.areaStyle.fillColor,"text-halo-color":this.areaStyle.strokeColor,"text-halo-width":this.areaStyle.strokeWidth,"text-opacity":r}}),this.entity.showLength&&this.map.addLayer({id:this.lengthLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`length`],layout:{"text-field":[`get`,`length`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-offset":[.8,0],"text-allow-overlap":!0,"text-rotate":[`get`,`textRotation`],"text-rotation-alignment":`map`},paint:{"text-color":this.lengthStyle.fillColor,"text-halo-color":this.lengthStyle.strokeColor,"text-halo-width":this.lengthStyle.strokeWidth,"text-opacity":r}}),this.initialized=!0}catch{this.map.once(`idle`,()=>this.initLayers())}}getGeoJSON(){let{center:e,length:t}=this.entity,n=ve(e,t),r=[{type:`Feature`,geometry:{type:`Polygon`,coordinates:[n]},properties:{}}];if(this.entity.name){let e=this.getBottomCenterPoint(n);r.push({type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:{pointType:`label`,name:this.entity.name}})}if(this.entity.showArea&&r.push({type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:{pointType:`area`,area:A(this.getArea())}}),this.entity.showLength){let e=n[1],t=n[2],i=[(e[0]+t[0])/2,(e[1]+t[1])/2],a=O(e,t);r.push({type:`Feature`,geometry:{type:`Point`,coordinates:i},properties:{pointType:`length`,length:j(a),textRotation:0}})}return{type:`FeatureCollection`,features:r}}getBottomCenterPoint(e){let t=e[2],n=e[3];return[(t[0]+n[0])/2,(t[1]+n[1])/2]}getArea(){return this.entity.length*this.entity.length}getEntityId(){return this.entity.id}getCenter(){return this.entity.center}getBounds(){let{center:e,length:t}=this.entity,[n,r]=e,i=t/2/6371e3,a=r*Math.PI/180,o=i*180/Math.PI,s=i*180/Math.PI/Math.cos(a);return[[n-s,r-o],[n+s,r+o]]}getLayerId(){return this.fillLayerId}getLabelLayerId(){return this.entity.name?this.labelLayerId:null}setSelected(t){this.isSelected!==t&&(this.isSelected=t,this.initialized&&(this.map.getLayer(this.strokeLayerId)&&this.map.setPaintProperty(this.strokeLayerId,`line-color`,t?`#ffcc00`:this.entity.strokeColor??e.DEFAULTS.strokeColor),this.map.getLayer(this.labelLayerId)&&(this.map.setPaintProperty(this.labelLayerId,`text-color`,t?this.selectNameStyle.fillColor:this.nameStyle.fillColor),this.map.setPaintProperty(this.labelLayerId,`text-halo-color`,t?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor),this.map.setPaintProperty(this.labelLayerId,`text-halo-width`,t?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth))))}isPointInEntity(e){let{center:t,length:n}=this.entity,r=ve(t,n);return this.pointInPolygon(e,r)}pointInPolygon(e,t){let[n,r]=e,i=!1;for(let e=0,a=t.length-1;e<t.length;a=e++){let[o,s]=t[e],[c,l]=t[a];s>r!=l>r&&n<(c-o)*(r-s)/(l-s)+o&&(i=!i)}return i}update(t){let n=this.entity;if(this.entity=t,!this.initialized)return;let r=t.confidence??1,i=P(r);if(n.center!==t.center||n.length!==t.length||n.name!==t.name||n.showArea!==t.showArea||n.showLength!==t.showLength){let e=this.map.getSource(this.sourceId);e&&e.setData(this.getGeoJSON()),!n.name&&t.name&&!this.map.getLayer(this.labelLayerId)?this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`label`],layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.8],"text-allow-overlap":!0},paint:{"text-color":this.isSelected?this.selectNameStyle.fillColor:this.nameStyle.fillColor,"text-halo-color":this.isSelected?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor,"text-halo-width":this.isSelected?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth,"text-opacity":i}}):n.name&&!t.name&&this.map.getLayer(this.labelLayerId)&&this.map.removeLayer(this.labelLayerId),!n.showArea&&t.showArea&&!this.map.getLayer(this.areaLayerId)?this.map.addLayer({id:this.areaLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`area`],layout:{"text-field":[`get`,`area`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-allow-overlap":!0},paint:{"text-color":this.areaStyle.fillColor,"text-halo-color":this.areaStyle.strokeColor,"text-halo-width":this.areaStyle.strokeWidth,"text-opacity":i}}):n.showArea&&!t.showArea&&this.map.getLayer(this.areaLayerId)&&this.map.removeLayer(this.areaLayerId),!n.showLength&&t.showLength&&!this.map.getLayer(this.lengthLayerId)?this.map.addLayer({id:this.lengthLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`length`],layout:{"text-field":[`get`,`length`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-offset":[.8,0],"text-allow-overlap":!0,"text-rotate":[`get`,`textRotation`],"text-rotation-alignment":`map`},paint:{"text-color":this.lengthStyle.fillColor,"text-halo-color":this.lengthStyle.strokeColor,"text-halo-width":this.lengthStyle.strokeWidth,"text-opacity":i}}):n.showLength&&!t.showLength&&this.map.getLayer(this.lengthLayerId)&&this.map.removeLayer(this.lengthLayerId)}(n.fillColor!==t.fillColor||n.fillOpacity!==t.fillOpacity||n.confidence!==t.confidence)&&this.map.getLayer(this.fillLayerId)&&(this.map.setPaintProperty(this.fillLayerId,`fill-color`,t.fillColor??e.DEFAULTS.fillColor),this.map.setPaintProperty(this.fillLayerId,`fill-opacity`,(t.fillOpacity??e.DEFAULTS.fillOpacity)*i)),(n.strokeColor!==t.strokeColor||n.strokeWidth!==t.strokeWidth||n.strokeOpacity!==t.strokeOpacity||n.confidence!==t.confidence)&&this.map.getLayer(this.strokeLayerId)&&(this.isSelected||this.map.setPaintProperty(this.strokeLayerId,`line-color`,t.strokeColor??e.DEFAULTS.strokeColor),this.map.setPaintProperty(this.strokeLayerId,`line-width`,t.strokeWidth??e.DEFAULTS.strokeWidth),this.map.setPaintProperty(this.strokeLayerId,`line-opacity`,(t.strokeOpacity??e.DEFAULTS.strokeOpacity)*i)),n.confidence!==t.confidence&&(this.map.getLayer(this.labelLayerId)&&this.map.setPaintProperty(this.labelLayerId,`text-opacity`,i),this.map.getLayer(this.areaLayerId)&&this.map.setPaintProperty(this.areaLayerId,`text-opacity`,i),this.map.getLayer(this.lengthLayerId)&&this.map.setPaintProperty(this.lengthLayerId,`text-opacity`,i))}getCorners(e,t){return ve(e??this.entity.center,t??this.entity.length).slice(0,4)}getEditHandleGeoJSON(e,t){let n=this.getCorners(e,t).map((e,t)=>({type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:{handleType:`vertex`,index:t}})),r=e??this.entity.center;return n.push({type:`Feature`,geometry:{type:`Point`,coordinates:r},properties:{handleType:`move`,index:0}}),{type:`FeatureCollection`,features:n}}createEditLayers(){this.map.getSource(this.editSourceId)||(I(this.map),this.map.addSource(this.editSourceId,{type:`geojson`,data:this.getEditHandleGeoJSON()}),this.map.addLayer({id:this.editHandleLayerId,type:`circle`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`vertex`],paint:{"circle-radius":6,"circle-color":`#ffffff`,"circle-stroke-color":`#3388ff`,"circle-stroke-width":2}}),this.map.addLayer({id:this.editMoveLayerId,type:`symbol`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`move`],layout:{"icon-image":ae,"icon-allow-overlap":!0,"icon-ignore-placement":!0}}))}removeEditLayers(){this.map.getLayer(this.editMoveLayerId)&&this.map.removeLayer(this.editMoveLayerId),this.map.getLayer(this.editHandleLayerId)&&this.map.removeLayer(this.editHandleLayerId),this.map.getSource(this.editSourceId)&&this.map.removeSource(this.editSourceId)}refreshEditHandles(e,t){let n=this.map.getSource(this.editSourceId);n&&n.setData(this.getEditHandleGeoJSON(e,t))}setEditing(e){this.isEditing!==e&&(this.isEditing=e,this.initialized&&(e?this.createEditLayers():this.removeEditLayers()))}getEditHandleAt(e,t){if(!this.isEditing)return null;let n=this.getCorners(),r=this.map.project(e),i=this.entity.center,a=this.map.project(i),o=r.x-a.x,s=r.y-a.y;if(o*o+s*s<=144)return{type:`move`,index:0,position:i};for(let e=0;e<n.length;e++){let t=this.map.project(n[e]),i=r.x-t.x,a=r.y-t.y;if(i*i+a*a<=100)return{type:`vertex`,index:e,position:n[e]}}return null}computeNewLength(e){return O(this.entity.center,e)*Math.SQRT2}applyHandleMove(e,t){let n;if(e.type===`move`){let r=t[0]-e.position[0],i=t[1]-e.position[1],a=[this.entity.center[0]+r,this.entity.center[1]+i];n={...this.entity,center:a}}else{let e=this.computeNewLength(t);n={...this.entity,length:e}}this.entity=n;let r=this.map.getSource(this.sourceId);return r&&r.setData(this.getGeoJSON()),this.refreshEditHandles(),n}updateEditPreview(e,t){let n,r;if(e.type===`move`){let i=t[0]-e.position[0],a=t[1]-e.position[1];n=[this.entity.center[0]+i,this.entity.center[1]+a],r=this.entity.length}else n=this.entity.center,r=this.computeNewLength(t);let i=this.entity;this.entity={...this.entity,center:n,length:r};let a=this.map.getSource(this.sourceId);a&&a.setData(this.getGeoJSON()),this.entity=i,this.refreshEditHandles(n,r)}cancelEditPreview(){let e=this.map.getSource(this.sourceId);e&&e.setData(this.getGeoJSON()),this.refreshEditHandles()}destroy(){this.initialized&&=(this.removeEditLayers(),this.map.getLayer(this.lengthLayerId)&&this.map.removeLayer(this.lengthLayerId),this.map.getLayer(this.areaLayerId)&&this.map.removeLayer(this.areaLayerId),this.map.getLayer(this.labelLayerId)&&this.map.removeLayer(this.labelLayerId),this.map.getLayer(this.strokeLayerId)&&this.map.removeLayer(this.strokeLayerId),this.map.getLayer(this.fillLayerId)&&this.map.removeLayer(this.fillLayerId),this.map.getSource(this.sourceId)&&this.map.removeSource(this.sourceId),!1)}};function be(e){let[[t,n],[r,i]]=e,a=Math.min(t,r),o=Math.max(t,r),s=Math.min(n,i),c=Math.max(n,i);return[[a,c],[o,c],[o,s],[a,s],[a,c]]}var xe=class e{static{this.DEFAULTS={strokeColor:`#3388ff`,strokeWidth:2,strokeOpacity:1,fillColor:`#3388ff`,fillOpacity:.2}}constructor(e,t,n,r,i,a){this.isSelected=!1,this.initialized=!1,this.isEditing=!1,this.map=e,this.entity=t,this.globalNameConfig=n,this.globalSelectNameConfig=r,this.globalAreaConfig=i,this.globalLengthConfig=a,this.sourceId=`rectangle-source-${t.id}`,this.fillLayerId=`rectangle-fill-${t.id}`,this.strokeLayerId=`rectangle-stroke-${t.id}`,this.labelLayerId=`rectangle-label-${t.id}`,this.areaLayerId=`rectangle-area-${t.id}`,this.lengthLayerId=`rectangle-length-${t.id}`,this.editSourceId=`rectangle-edit-source-${t.id}`,this.editHandleLayerId=`rectangle-edit-handles-${t.id}`,this.editMoveLayerId=`rectangle-edit-move-${t.id}`,this.initLayers()}get nameStyle(){return x(this.entity.nameConfig,this.globalNameConfig,h)}get selectNameStyle(){return x(this.entity.selectNameConfig,this.globalSelectNameConfig,g)}get areaStyle(){return x(this.entity.areaConfig,this.globalAreaConfig,_)}get lengthStyle(){return x(this.entity.lengthConfig,this.globalLengthConfig,b)}initLayers(){if(!this.initialized)try{let t=this.getGeoJSON();this.map.addSource(this.sourceId,{type:`geojson`,data:t});let n=this.entity.confidence??1,r=P(n);this.map.addLayer({id:this.fillLayerId,type:`fill`,source:this.sourceId,filter:[`==`,`$type`,`Polygon`],paint:{"fill-color":this.entity.fillColor??e.DEFAULTS.fillColor,"fill-opacity":(this.entity.fillOpacity??e.DEFAULTS.fillOpacity)*r}}),this.map.addLayer({id:this.strokeLayerId,type:`line`,source:this.sourceId,filter:[`==`,`$type`,`Polygon`],layout:{"line-join":`miter`,"line-cap":`square`},paint:{"line-color":this.isSelected?`#ffcc00`:this.entity.strokeColor??e.DEFAULTS.strokeColor,"line-width":this.entity.strokeWidth??e.DEFAULTS.strokeWidth,"line-opacity":(this.entity.strokeOpacity??e.DEFAULTS.strokeOpacity)*r}}),this.entity.name&&this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`label`],layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.8],"text-allow-overlap":!0},paint:{"text-color":this.isSelected?this.selectNameStyle.fillColor:this.nameStyle.fillColor,"text-halo-color":this.isSelected?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor,"text-halo-width":this.isSelected?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth,"text-opacity":r}}),this.entity.showArea&&this.map.addLayer({id:this.areaLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`area`],layout:{"text-field":[`get`,`area`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-allow-overlap":!0},paint:{"text-color":this.areaStyle.fillColor,"text-halo-color":this.areaStyle.strokeColor,"text-halo-width":this.areaStyle.strokeWidth,"text-opacity":r}}),this.entity.showLength&&this.map.addLayer({id:this.lengthLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`length`],layout:{"text-field":[`get`,`length`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-offset":[0,-.8],"text-allow-overlap":!0},paint:{"text-color":this.lengthStyle.fillColor,"text-halo-color":this.lengthStyle.strokeColor,"text-halo-width":this.lengthStyle.strokeWidth,"text-opacity":r}}),this.initialized=!0}catch{this.map.once(`idle`,()=>this.initLayers())}}getGeoJSON(){let{bounds:e}=this.entity,t=be(e),n=[{type:`Feature`,geometry:{type:`Polygon`,coordinates:[t]},properties:{}}];if(this.entity.name){let e=this.getBottomCenterPoint(t);n.push({type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:{pointType:`label`,name:this.entity.name}})}if(this.entity.showArea){let e=this.calculateRectangleCenter();n.push({type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:{pointType:`area`,area:A(this.getArea())}})}if(this.entity.showLength)for(let[e,r,i]of[[0,1,0],[1,2,0]]){let a=t[e],o=t[r],s=[(a[0]+o[0])/2,(a[1]+o[1])/2],c=O(a,o);n.push({type:`Feature`,geometry:{type:`Point`,coordinates:s},properties:{pointType:`length`,length:j(c),textRotation:i}})}return{type:`FeatureCollection`,features:n}}getBottomCenterPoint(e){let t=e[2],n=e[3];return[(t[0]+n[0])/2,(t[1]+n[1])/2]}getArea(){let e=be(this.entity.bounds);return ee(e)}getEntityId(){return this.entity.id}getBounds(){let[[e,t],[n,r]]=this.entity.bounds,i=Math.min(e,n),a=Math.max(e,n);return[[i,Math.min(t,r)],[a,Math.max(t,r)]]}getCenter(){return this.entity.center?this.entity.center:this.calculateRectangleCenter()}calculateRectangleCenter(){let[[e,t],[n,r]]=this.entity.bounds;return[(e+n)/2,(t+r)/2]}getLayerId(){return this.fillLayerId}getLabelLayerId(){return this.entity.name?this.labelLayerId:null}setSelected(t){this.isSelected!==t&&(this.isSelected=t,this.initialized&&(this.map.getLayer(this.strokeLayerId)&&this.map.setPaintProperty(this.strokeLayerId,`line-color`,t?`#ffcc00`:this.entity.strokeColor??e.DEFAULTS.strokeColor),this.map.getLayer(this.labelLayerId)&&(this.map.setPaintProperty(this.labelLayerId,`text-color`,t?this.selectNameStyle.fillColor:this.nameStyle.fillColor),this.map.setPaintProperty(this.labelLayerId,`text-halo-color`,t?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor),this.map.setPaintProperty(this.labelLayerId,`text-halo-width`,t?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth))))}isPointInEntity(e){let{bounds:t}=this.entity,n=be(t);return this.pointInPolygon(e,n)}pointInPolygon(e,t){let[n,r]=e,i=!1;for(let e=0,a=t.length-1;e<t.length;a=e++){let[o,s]=t[e],[c,l]=t[a];s>r!=l>r&&n<(c-o)*(r-s)/(l-s)+o&&(i=!i)}return i}update(t){let n=this.entity;if(this.entity=t,!this.initialized)return;let r=t.confidence??1,i=P(r);if(n.bounds!==t.bounds||n.name!==t.name||n.showArea!==t.showArea||n.showLength!==t.showLength){let e=this.map.getSource(this.sourceId);e&&e.setData(this.getGeoJSON()),!n.name&&t.name&&!this.map.getLayer(this.labelLayerId)?this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`label`],layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.8],"text-allow-overlap":!0},paint:{"text-color":this.isSelected?this.selectNameStyle.fillColor:this.nameStyle.fillColor,"text-halo-color":this.isSelected?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor,"text-halo-width":this.isSelected?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth,"text-opacity":i}}):n.name&&!t.name&&this.map.getLayer(this.labelLayerId)&&this.map.removeLayer(this.labelLayerId),!n.showArea&&t.showArea&&!this.map.getLayer(this.areaLayerId)?this.map.addLayer({id:this.areaLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`area`],layout:{"text-field":[`get`,`area`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-allow-overlap":!0},paint:{"text-color":this.areaStyle.fillColor,"text-halo-color":this.areaStyle.strokeColor,"text-halo-width":this.areaStyle.strokeWidth,"text-opacity":i}}):n.showArea&&!t.showArea&&this.map.getLayer(this.areaLayerId)&&this.map.removeLayer(this.areaLayerId),!n.showLength&&t.showLength&&!this.map.getLayer(this.lengthLayerId)?this.map.addLayer({id:this.lengthLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`length`],layout:{"text-field":[`get`,`length`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-offset":[0,-.8],"text-allow-overlap":!0},paint:{"text-color":this.lengthStyle.fillColor,"text-halo-color":this.lengthStyle.strokeColor,"text-halo-width":this.lengthStyle.strokeWidth,"text-opacity":i}}):n.showLength&&!t.showLength&&this.map.getLayer(this.lengthLayerId)&&this.map.removeLayer(this.lengthLayerId)}(n.fillColor!==t.fillColor||n.fillOpacity!==t.fillOpacity||n.confidence!==t.confidence)&&this.map.getLayer(this.fillLayerId)&&(this.map.setPaintProperty(this.fillLayerId,`fill-color`,t.fillColor??e.DEFAULTS.fillColor),this.map.setPaintProperty(this.fillLayerId,`fill-opacity`,(t.fillOpacity??e.DEFAULTS.fillOpacity)*i)),(n.strokeColor!==t.strokeColor||n.strokeWidth!==t.strokeWidth||n.strokeOpacity!==t.strokeOpacity||n.confidence!==t.confidence)&&this.map.getLayer(this.strokeLayerId)&&(this.isSelected||this.map.setPaintProperty(this.strokeLayerId,`line-color`,t.strokeColor??e.DEFAULTS.strokeColor),this.map.setPaintProperty(this.strokeLayerId,`line-width`,t.strokeWidth??e.DEFAULTS.strokeWidth),this.map.setPaintProperty(this.strokeLayerId,`line-opacity`,(t.strokeOpacity??e.DEFAULTS.strokeOpacity)*i)),n.confidence!==t.confidence&&(this.map.getLayer(this.labelLayerId)&&this.map.setPaintProperty(this.labelLayerId,`text-opacity`,i),this.map.getLayer(this.areaLayerId)&&this.map.setPaintProperty(this.areaLayerId,`text-opacity`,i),this.map.getLayer(this.lengthLayerId)&&this.map.setPaintProperty(this.lengthLayerId,`text-opacity`,i))}getCorners(e){return be(e??this.entity.bounds).slice(0,4)}getEditHandleGeoJSON(e){let t=this.getCorners(e).map((e,t)=>({type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:{handleType:`vertex`,index:t}})),n=e??this.entity.bounds,r=(n[0][0]+n[1][0])/2,i=(n[0][1]+n[1][1])/2;return t.push({type:`Feature`,geometry:{type:`Point`,coordinates:[r,i]},properties:{handleType:`move`,index:0}}),{type:`FeatureCollection`,features:t}}createEditLayers(){this.map.getSource(this.editSourceId)||(I(this.map),this.map.addSource(this.editSourceId,{type:`geojson`,data:this.getEditHandleGeoJSON()}),this.map.addLayer({id:this.editHandleLayerId,type:`circle`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`vertex`],paint:{"circle-radius":6,"circle-color":`#ffffff`,"circle-stroke-color":`#3388ff`,"circle-stroke-width":2}}),this.map.addLayer({id:this.editMoveLayerId,type:`symbol`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`move`],layout:{"icon-image":ae,"icon-allow-overlap":!0,"icon-ignore-placement":!0}}))}removeEditLayers(){this.map.getLayer(this.editMoveLayerId)&&this.map.removeLayer(this.editMoveLayerId),this.map.getLayer(this.editHandleLayerId)&&this.map.removeLayer(this.editHandleLayerId),this.map.getSource(this.editSourceId)&&this.map.removeSource(this.editSourceId)}refreshEditHandles(e){let t=this.map.getSource(this.editSourceId);t&&t.setData(this.getEditHandleGeoJSON(e))}setEditing(e){this.isEditing!==e&&(this.isEditing=e,this.initialized&&(e?this.createEditLayers():this.removeEditLayers()))}getEditHandleAt(e,t){if(!this.isEditing)return null;let n=this.getCorners(),r=this.map.project(e),i=this.calculateRectangleCenter(),a=this.map.project(i),o=r.x-a.x,s=r.y-a.y;if(o*o+s*s<=144)return{type:`move`,index:0,position:i};for(let e=0;e<n.length;e++){let t=this.map.project(n[e]),i=r.x-t.x,a=r.y-t.y;if(i*i+a*a<=100)return{type:`vertex`,index:e,position:n[e]}}return null}computeNewBounds(e,t){let n=this.getCorners(),r=(e+2)%4,i=n[r];return[[Math.min(t[0],i[0]),Math.min(t[1],i[1])],[Math.max(t[0],i[0]),Math.max(t[1],i[1])]]}offsetBounds(e,t,n){let r=n[0]-t[0],i=n[1]-t[1];return[[e[0][0]+r,e[0][1]+i],[e[1][0]+r,e[1][1]+i]]}applyHandleMove(e,t){let n;n=e.type===`move`?this.offsetBounds(this.entity.bounds,e.position,t):this.computeNewBounds(e.index,t);let r={...this.entity,bounds:n};this.entity=r;let i=this.map.getSource(this.sourceId);return i&&i.setData(this.getGeoJSON()),this.refreshEditHandles(),r}updateEditPreview(e,t){let n;n=e.type===`move`?this.offsetBounds(this.entity.bounds,e.position,t):this.computeNewBounds(e.index,t);let r=this.entity;this.entity={...this.entity,bounds:n};let i=this.map.getSource(this.sourceId);i&&i.setData(this.getGeoJSON()),this.entity=r,this.refreshEditHandles(n)}cancelEditPreview(){let e=this.map.getSource(this.sourceId);e&&e.setData(this.getGeoJSON()),this.refreshEditHandles()}destroy(){this.initialized&&=(this.removeEditLayers(),this.map.getLayer(this.lengthLayerId)&&this.map.removeLayer(this.lengthLayerId),this.map.getLayer(this.areaLayerId)&&this.map.removeLayer(this.areaLayerId),this.map.getLayer(this.labelLayerId)&&this.map.removeLayer(this.labelLayerId),this.map.getLayer(this.strokeLayerId)&&this.map.removeLayer(this.strokeLayerId),this.map.getLayer(this.fillLayerId)&&this.map.removeLayer(this.fillLayerId),this.map.getSource(this.sourceId)&&this.map.removeSource(this.sourceId),!1)}};const Se=({popupState:e,onClose:t,portalContainer:n,popupRef:r})=>{let i=(0,c.useRef)(null),[a,o]=(0,c.useState)(`entering`),[s,l]=(0,c.useState)(!1),u=(0,c.useRef)(e.position),d=(0,c.useRef)(!1),m=r||i;d.current||(u.current=e.position),(0,c.useEffect)(()=>{let e=setTimeout(()=>{l(!0)},60);return()=>clearTimeout(e)},[]),(0,c.useEffect)(()=>{if(a===`entering`&&s){let e=setTimeout(()=>o(`entered`),50);return()=>clearTimeout(e)}},[a,s]);let h=(0,c.useCallback)(()=>{e.config.animation===`none`?t():(d.current=!0,o(`exiting`),setTimeout(()=>t(),200))},[e.config.animation,t]);(0,c.useEffect)(()=>{if(!e.config.closeOnEscape)return;let t=e=>{e.key===`Escape`&&h()};return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[e.config.closeOnEscape,h]),(0,c.useEffect)(()=>{if(!e.config.closeOnClickOutside)return;let t=e=>{m.current&&!m.current.contains(e.target)&&h()},n=setTimeout(()=>{document.addEventListener(`click`,t,!0)},0);return()=>{clearTimeout(n),document.removeEventListener(`click`,t,!0)}},[e.config.closeOnClickOutside,h,m]);let g=()=>{switch(e.actualPosition){case`top`:return`center bottom`;case`bottom`:return`center top`;case`left`:return`right center`;case`right`:return`left center`;case`center`:default:return`center center`}},_=u.current,v=(0,p.jsxs)(`div`,{ref:m,className:`entity-popup ${s?`entity-popup--${a} animation-${e.config.animation}`:``} ${e.config.className||``}`,style:{position:`fixed`,left:`${_.x}px`,top:`${_.y}px`,maxWidth:e.config.maxWidth,zIndex:e.config.zIndex,pointerEvents:`all`,opacity:s?void 0:0,transformOrigin:g(),...e.config.style},role:`dialog`,"aria-modal":`true`,children:[e.config.showCloseButton&&(0,p.jsx)(`button`,{className:`entity-popup__close`,onClick:h,"aria-label":`Close popup`,children:`×`}),(0,p.jsx)(`div`,{className:`entity-popup__content`,children:e.config.content})]});return(0,f.createPortal)(v,n)};var Ce=`data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20t='1768373933818'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20p-id='30344'%20width='200'%20height='200'%3e%3cpath%20d='M400.440142%201024h-0.073136a48.781895%2048.781895%200%200%201-45.490763-31.448598L3.383306%2066.061072a48.781895%2048.781895%200%200%201%2062.897196-62.897197l926.563466%20351.419801a48.928168%2048.928168%200%200%201%200.219409%2091.127799L597.761811%20597.688654l-151.904042%20395.082157a48.781895%2048.781895%200%200%201-45.490763%2031.229189zM133.053921%20132.907627l267.678766%20705.691916%20113.87318-296.201913a48.855032%2048.855032%200%200%201%2028.011193-27.938057l296.201913-113.87318-705.765052-267.678766z'%20p-id='30345'%20fill='%23ffffff'%20/%3e%3cscript%20xmlns=''%20/%3e%3c/svg%3e`;function we({map:e,precision:t=6,className:n=``,style:r}){let[i,a]=(0,c.useState)(null),o=(0,c.useCallback)(e=>{a({lng:Number(e.lngLat.lng.toFixed(t)),lat:Number(e.lngLat.lat.toFixed(t))})},[t]);return(0,c.useEffect)(()=>{if(e)return e.on(`mousemove`,o),()=>{e.off(`mousemove`,o)}},[e,o]),i?(0,p.jsxs)(`div`,{className:`mapbox-coordinate-display ${n}`,style:r,children:[(0,p.jsx)(`img`,{src:Ce,alt:`location`,className:`mapbox-coordinate-display__icon`}),(0,p.jsxs)(`div`,{className:`mapbox-coordinate-display__content`,children:[(0,p.jsxs)(`span`,{className:`mapbox-coordinate-display__item`,children:[`经度:`,i.lng]}),(0,p.jsxs)(`span`,{className:`mapbox-coordinate-display__item`,children:[`纬度:`,i.lat]})]})]}):null}var R=`data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20t='1768374054549'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20p-id='31504'%20width='200'%20height='200'%3e%3cpath%20d='M53.80096%20687.40096l282.79808%20282.79808%20633.6-633.6-282.79808-282.79808-90.39872%2090.39872-28.29824%2028.20096-42.7008%2042.7008-23.5008%2023.5008-63.20128%2063.19616-12.29824%2012.29824-373.20192%20373.30432z%20m282.79808%20212.10112l-212.10112-212.1984%2054.99904-54.99904%20106.10176%20106.10176%2028.29824-28.29824-106.10176-106.10176%2042.39872-42.39872%2070.70208%2070.70208%2028.29824-28.29824-70.69184-70.71232%2042.39872-42.39872%2070.70208%2070.70208%2028.29824-28.29824-70.70208-70.70208%2042.39872-42.39872%20106.10176%20106.10176%2028.29824-28.29824-106.09664-106.10688%2042.39872-42.39872%2070.70208%2070.70208%2028.29824-28.29824-70.70208-70.7072%2042.39872-42.39872%2070.70208%2070.70208%2028.29824-28.29824-70.70208-70.70208%2042.7008-42.7008%20106.10176%20106.10176%2028.29824-28.29824-105.99936-106.10176%2054.99904-54.99904%20212.10112%20212.10112L336.59904%20899.50208z'%20fill='%23ffffff'%20p-id='31505'%20/%3e%3cscript%20xmlns=''%20/%3e%3c/svg%3e`;function Te({map:e,maxWidth:t=100,unit:n=`metric`,className:r=``,style:i}){let[a,o]=(0,c.useState)({width:100,label:`100 m`}),s=(0,c.useCallback)(()=>{if(!e)return;let r=e.getZoom(),i=e.getCenter().lat,a=40075016.686/(256*2**r),s=i*Math.PI/180,c=a*Math.cos(s)*t,l,u;if(n===`imperial`){let e=3.2808*c;if(e>5280){let n=e/5280;l=z(n),u=`${l} mi`;let r=l/n;o({width:t*r,label:u})}else{l=z(e),u=`${l} ft`;let n=l/e;o({width:t*n,label:u})}}else if(n===`nautical`){let e=c/1852;l=z(e),u=`${l} nm`;let n=l/e;o({width:t*n,label:u})}else if(c>=1e3){l=z(c/1e3),u=`${l} km`;let e=l/(c/1e3);o({width:t*e,label:u})}else{l=z(c),u=`${l} m`;let e=l/c;o({width:t*e,label:u})}},[e,t,n]);return(0,c.useEffect)(()=>{if(e)return s(),e.on(`move`,s),e.on(`zoom`,s),()=>{e.off(`move`,s),e.off(`zoom`,s)}},[e,s]),(0,p.jsxs)(`div`,{className:`mapbox-scale-control ${r}`,style:i,children:[(0,p.jsxs)(`div`,{className:`mapbox-scale-control__bar-wrapper`,children:[(0,p.jsx)(`img`,{src:R,alt:`scale`,className:`mapbox-scale-control__icon`}),(0,p.jsxs)(`div`,{className:`mapbox-scale-control__bar`,style:{width:`${a.width}px`},children:[(0,p.jsx)(`div`,{className:`mapbox-scale-control__tick mapbox-scale-control__tick--left`}),(0,p.jsx)(`div`,{className:`mapbox-scale-control__tick mapbox-scale-control__tick--right`})]})]}),(0,p.jsx)(`span`,{className:`mapbox-scale-control__label`,children:a.label})]})}function z(e){let t=10**(`${Math.floor(e)}`.length-1),n=e/t;return n=n>=10?10:n>=5?5:n>=3?3:n>=2?2:1,t*n}var B=`data:image/svg+xml,%3c?xml%20version='1.0'%20standalone='no'?%3e%3c!DOCTYPE%20svg%20PUBLIC%20'-//W3C//DTD%20SVG%201.1//EN'%20'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3e%3csvg%20t='1768989620222'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='5780'%20width='128'%20height='128'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3cpath%20d='M938.666667%20602.752a42.666667%2042.666667%200%200%201%2042.368%2037.674667l0.298666%204.992V853.333333a128%20128%200%200%201-120.490666%20127.786667L853.333333%20981.333333h-208.896a42.666667%2042.666667%200%200%201-4.949333-85.034666l4.949333-0.298667H853.333333a42.666667%2042.666667%200%200%200%2042.368-37.674667L896%20853.333333v-207.914666a42.666667%2042.666667%200%200%201%2042.666667-42.666667z%20m-853.333334%203.285333a42.666667%2042.666667%200%200%201%2042.368%2037.674667l0.298667%204.992V853.333333a42.666667%2042.666667%200%200%200%2037.674667%2042.368L170.666667%20896h211.882666a42.666667%2042.666667%200%200%201%204.992%2085.034667L382.549333%20981.333333H170.666667a128%20128%200%200%201-127.786667-120.490666L42.666667%20853.333333v-204.629333a42.666667%2042.666667%200%200%201%2042.666666-42.666667zM381.866667%2042.666667A42.666667%2042.666667%200%200%201%20386.944%20127.701333L381.866667%20128H170.666667a42.666667%2042.666667%200%200%200-42.368%2037.674667L128%20170.666667v216.448a42.666667%2042.666667%200%200%201-85.034667%204.992L42.666667%20387.114667V170.666667A128%20128%200%200%201%20163.157333%2042.88L170.666667%2042.666667h211.2zM853.333333%2042.666667a128%20128%200%200%201%20127.786667%20120.490666L981.333333%20170.666667v216.064a42.666667%2042.666667%200%200%201-85.034666%204.992L896%20386.730667V170.666667a42.666667%2042.666667%200%200%200-37.674667-42.368L853.333333%20128h-214.4a42.666667%2042.666667%200%200%201-4.949333-85.034667L638.933333%2042.666667H853.333333z'%20fill='%23ffffff'%20p-id='5781'%3e%3c/path%3e%3cpath%20d='M512%20512m-128%200a128%20128%200%201%200%20256%200%20128%20128%200%201%200-256%200Z'%20fill='%23ffffff'%20p-id='5782'%3e%3c/path%3e%3c/svg%3e`;function Ee({map:e,initialCenter:t,initialZoom:n,initialPitch:r=0,initialBearing:i=0,className:a=``,style:o,duration:s=1e3}){return(0,p.jsxs)(`button`,{className:`mapbox-control-btn mapbox-reset-view-control ${a}`,onClick:()=>{e&&e.flyTo({center:t,zoom:n,pitch:r,bearing:i,duration:s})},style:o,title:`回到初始位置`,children:[(0,p.jsx)(`img`,{src:B,alt:`home`,className:`mapbox-control-btn__icon`}),(0,p.jsx)(`span`,{children:`复位`})]})}var De=`data:image/svg+xml,%3c?xml%20version='1.0'%20standalone='no'?%3e%3c!DOCTYPE%20svg%20PUBLIC%20'-//W3C//DTD%20SVG%201.1//EN'%20'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3e%3csvg%20t='1769487141027'%20class='icon'%20viewBox='0%200%201517%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='2644'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='189.625'%20height='128'%3e%3cpath%20d='M1.68121071-242.12320149h1508.24640296v1508.24640298h-1508.24640296z'%20fill='%23ffffff'%20fill-opacity='0'%20p-id='2645'%3e%3c/path%3e%3cpath%20d='M437.30078846%20170.6624h682.66239999v682.6624H437.30078846z'%20fill='%23ffffff'%20fill-opacity='0'%20p-id='2646'%3e%3c/path%3e%3cpath%20d='M1151.68343834%2040.66710748H373.42829443A81.76345149%2081.76345149%200%200%200%20292.90207634%20121.49379654v784.42363608c0%2040.42218191%2036.92257893%2077.41545989%2080.5262181%2077.4154599h781.6133488a81.76345149%2081.76345149%200%200%200%2080.52621814-80.82668906V121.49379654C1232.08593315%2077.76643404%201195.25172802%2040.66710748%201151.6657636%2040.66710748z%20m-325.39237822%20616.14222197H618.29445458V451.37556451h53.66057906c6.71640976%200%2013.41514477-3.35820487%2020.11387975-6.73408452l97.28189301-100.99359314h134.18679716v208.72127078c-46.96184405%2013.50351858-87.22495312%2053.90802574-97.28189299%20104.4048223z%20m130.7932427-20.23760311c23.50743418%200%2043.65666346%2020.21992834%2043.65666349%2043.76271204a44.50505206%2044.50505206%200%200%201-43.62131391%2043.7803868%2044.50505206%2044.50505206%200%200%201-43.6036392-43.7803868c0-23.54278369%2020.096205-43.76271203%2043.6036392-43.76271204h-0.05302433zM564.63387554%20926.10201142H373.42829443a22.87114272%2022.87114272%200%200%201-16.79102442-6.71640975%2023.04789036%2023.04789036%200%200%201-6.71640975-16.82637394V714.02253578h214.73069002v212.07947564z%20m0-269.31035673H349.92086026V118.13559167c0-10.1453137%2010.05693988-20.2376031%2023.50743417-20.23760309h553.4321645v188.53669194h-147.54891766c-6.69873499%200-13.39747001%203.35820487-20.096205%206.71640977l-97.28189297%2097.653063H460.61789801a26.44144475%2026.44144475%200%200%200-19.08874355%207.79457028%2026.63586714%2026.63586714%200%200%200-7.72387123%2019.1594426c0%2016.80869917%2013.39747001%2026.90098858%2026.81261478%2026.90098857h104.03365227v212.13249995z%20m610.48629795%20245.71454877c0.17674763%206.29221547-2.24469484%2012.37233377-6.68106024%2016.84404869s-10.49880895%206.89315739-16.77334965%206.75175927h-533.42433329v-212.0971504H829.63159021c13.39747001%2057.24855586%2067.07572382%2097.65306301%20127.48806219%2097.653063a128.67227125%20128.67227125%200%200%200%2093.05762473-37.87701612%20129.60903367%20129.60903367%200%200%200%2037.73561801-93.39344522c0-64.00031515-46.96184405-117.8553166-103.98062799-128.00063029v-208.73894554h194.56378599v558.91134088h-3.35820489v-0.05302427z%20m0-616.07152294H980.57406228V97.89798858h171.10937607c13.39747001%200%2023.45440988%2010.07461465%2023.4544099%2023.59580796v164.94088398z'%20fill='%23ffffff'%20p-id='2647'%3e%3c/path%3e%3c/svg%3e`,V=`road-highlight-`,Oe=[{source:`composite`,sourceLayer:`road`},{source:`openmaptiles`,sourceLayer:`transportation`},{source:`maptiler_planet`,sourceLayer:`transportation`}];function ke(e){let t=e.getStyle();if(!t||!t.sources)return null;for(let e of Oe){let n=t.sources[e.source];if(n&&n.type===`vector`)return e}for(let[e,n]of Object.entries(t.sources))if(n.type===`vector`)return{source:e,sourceLayer:`transportation`};return null}function Ae({map:e,highlightWidth:t=3,defaultRoadTypes:n=[],defaultMinWidth:r=0,source:i,sourceLayer:a,classField:o=`class`,className:s=``,style:u}){let[d,f]=(0,c.useState)(!1),[h,g]=(0,c.useState)(n),[_,v]=(0,c.useState)(!1),y=(0,c.useRef)(!1),b=(0,c.useRef)(null),x=(0,c.useRef)(null),S=(0,c.useRef)(null),C=(0,c.useCallback)((e,n,r)=>{if(!e.isStyleLoaded()||!e.getSource(n))return!1;let i=!0;return E.forEach(a=>{let s=`${V}${a.class}`;if(!e.getLayer(s))try{e.addLayer({id:s,type:`line`,source:n,"source-layer":r,filter:[`==`,[`get`,o],a.class],paint:{"line-color":a.color,"line-width":t,"line-opacity":.8},layout:{visibility:`none`}}),console.log(`Added road highlight layer: ${s} (source: ${n}, source-layer: ${r})`)}catch(e){console.error(`Failed to add road highlight layer for ${a.class}:`,e),i=!1}}),i},[t,o]);(0,c.useEffect)(()=>{if(!e)return;let t=()=>{let t=i,n=a;if(!t||!n){let r=ke(e);r&&(console.log(`Auto-detected vector source:`,r),t||=r.source,n||=r.sourceLayer)}t&&n?C(e,t,n)&&(y.current=!0,v(!0)):console.warn(`No vector source found for road highlighting`)};e.isStyleLoaded()?t():e.once(`load`,t);let n=()=>{e.isStyleLoaded()&&t()},r=()=>{y.current||t()};return e.on(`styledata`,n),e.on(`sourcedata`,r),()=>{e.off(`styledata`,n),e.off(`sourcedata`,r)}},[e,i,a,C]),(0,c.useEffect)(()=>{!e||!_||E.forEach(t=>{let n=`${V}${t.class}`;if(e.getLayer(n))try{let r=h.includes(t.class);e.setLayoutProperty(n,`visibility`,r?`visible`:`none`)}catch(e){console.error(`Failed to update layer ${n}:`,e)}})},[e,_,h]),(0,c.useEffect)(()=>{if(!d)return;let e=e=>{b.current&&!b.current.contains(e.target)&&x.current&&!x.current.contains(e.target)&&f(!1)},t=setTimeout(()=>{document.addEventListener(`mousedown`,e)},0);return()=>{clearTimeout(t),document.removeEventListener(`mousedown`,e)}},[d]),(0,c.useEffect)(()=>()=>{e&&e.getStyle()&&E.forEach(t=>{let n=`${V}${t.class}`;if(e.getLayer(n))try{e.removeLayer(n)}catch{}}),S.current&&=(S.current.remove(),null)},[e]);let w=(0,c.useCallback)(e=>E.find(t=>t.class===e)?.label||e,[]),T=(0,c.useCallback)(t=>{if(!e||h.length===0){S.current&&S.current.remove(),e?.getCanvas().style.cursor&&(e.getCanvas().style.cursor=``);return}let n=h.map(e=>`${V}${e}`),r=[[t.point.x-10,t.point.y-10],[t.point.x+10,t.point.y+10]],i=e.queryRenderedFeatures(r,{layers:n.filter(t=>e.getLayer(t))});if(i.length>0){let n=i[0].properties||{},r=t.lngLat,a=n.name||n.name_en||n.name_local||``,s=n[o]||``,c=n.type||``,u=n.structure||``,d=n.oneway,f=n.layer,p=n.iso_3166_1||``,m=n.iso_3166_2||``,h=e=>!(e==null||e===``||typeof e==`string`&&e.toLowerCase()===`none`),g=[];h(s)&&g.push(`
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`react`);c=s(c);let l=require(`mapbox-gl`);l=s(l);let u=require(`@turf/turf`);u=s(u);let d=require(`react-dom/client`);d=s(d);let f=require(`react-dom`);f=s(f);let p=require(`react/jsx-runtime`);p=s(p);let m=require(`@arco-design/web-react`);m=s(m);const h={fillColor:`#ffffff`,fillOpacity:1,strokeColor:`rgba(0, 0, 0, 0.8)`,strokeWidth:1,strokeOpacity:1},g={fillColor:`#ffcc00`,fillOpacity:1,strokeColor:`#ff6600`,strokeWidth:2,strokeOpacity:1},_={fillColor:`#ffffff`,fillOpacity:1,strokeColor:`rgba(0, 0, 0, 0.8)`,strokeWidth:1,strokeOpacity:1},v={color:`#ffffff`,width:1,opacity:1,dashArray:[4,4]};function y(e,t,n=v){return{color:e?.color??t?.color??n.color,width:e?.width??t?.width??n.width,opacity:e?.opacity??t?.opacity??n.opacity,dashArray:e?.dashArray??t?.dashArray??n.dashArray}}const b={fillColor:`#ffffff`,fillOpacity:1,strokeColor:`rgba(0, 0, 0, 0.8)`,strokeWidth:1,strokeOpacity:1};function x(e,t,n=h){return{fillColor:e?.fillColor??t?.fillColor??n.fillColor,fillOpacity:e?.fillOpacity??t?.fillOpacity??n.fillOpacity,strokeColor:e?.strokeColor??t?.strokeColor??n.strokeColor,strokeWidth:e?.strokeWidth??t?.strokeWidth??n.strokeWidth,strokeOpacity:e?.strokeOpacity??t?.strokeOpacity??n.strokeOpacity}}function S(e,t){if(!t)return e;let n={...e};return(n.type===`circle`||n.type===`square`||n.type===`rectangle`||n.type===`polygon`)&&n.showArea===void 0&&(n.showArea=t.showArea),(n.type===`square`||n.type===`rectangle`||n.type===`polygon`||n.type===`polyline`)&&n.showLength===void 0&&(n.showLength=t.showLength),n.type===`circle`&&n.showRadius===void 0&&(n.showRadius=t.showRadius),n}const C={blue:{center:`#4285f4`,edge:`#4285f400`,mid:`#1a73e8`},green:{center:`#34a853`,edge:`#34a85300`,mid:`#0d652d`},red:{center:`#ea4335`,edge:`#ea433500`,mid:`#c5221f`},purple:{center:`#9c27b0`,edge:`#9c27b000`,mid:`#6a1b9a`},cyan:{center:`#00bcd4`,edge:`#00bcd400`,mid:`#00838f`},orange:{center:`#ff9800`,edge:`#ff980000`,mid:`#f57c00`}},w={rotationSpeed:1,initialRotation:0,colorScheme:`green`,opacity:70,gradientType:`conical`,showRings:!0,showCenter:!0,showScanLine:!0},T={trigger:`click`,position:`top`,offset:[0,-10],showCloseButton:!0,animation:`fade`,closeOnClickOutside:!0,closeOnEscape:!0,hoverDelay:300,maxWidth:320,zIndex:1e3},E=[{class:`motorway`,label:`高速公路`,color:`#E84E3C`},{class:`trunk`,label:`国道`,color:`#FF8C00`},{class:`primary`,label:`主干道`,color:`#FFD700`},{class:`secondary`,label:`次干道`,color:`#4CAF50`},{class:`tertiary`,label:`三级道路`,color:`#2196F3`},{class:`motorway_link`,label:`高速匝道`,color:`#FF6B6B`},{class:`trunk_link`,label:`国道匝道`,color:`#FFB84D`},{class:`primary_link`,label:`主干道匝道`,color:`#FFE066`},{class:`secondary_link`,label:`次干道匝道`,color:`#66BB6A`},{class:`tertiary_link`,label:`三级道路匝道`,color:`#42A5F5`},{class:`minor`,label:`小路`,color:`#81C784`},{class:`residential`,label:`居民区道路`,color:`#81C784`},{class:`unclassified`,label:`未分类道路`,color:`#9E9E9E`},{class:`service`,label:`服务道路`,color:`#64B5F6`},{class:`track`,label:`土路`,color:`#A1887F`},{class:`path`,label:`小径`,color:`#BCAAA4`}];function D(e,t,n){let r=u.point(e);return u.destination(r,t/1e3,n,{units:`kilometers`}).geometry.coordinates}function O(e,t){return u.distance(u.point(e),u.point(t),{units:`kilometers`})*1e3}function k(e,t){return u.bearing(u.point(e),u.point(t))}function ee(e){let t=u.polygon([e]);return u.area(t)}function A(e){return e>=1e6?`${(e/1e6).toFixed(2)} km²`:`${e.toFixed(0)} m²`}function j(e){return e>=1e3?`${(e/1e3).toFixed(2)} km`:`${e.toFixed(0)} m`}const M=512,te=512/2,ne=512/2-2;function N(e){return e*Math.PI/180}function P(e=1){return .3+Math.max(0,Math.min(1,e))*.7}var re=class{constructor(e,t,n,r,i,a){this.isDestroyed=!1,this.isSelected=!1,this.map=e,this.entity=t,this.entityId=t.id,this.globalNameConfig=r,this.globalSelectNameConfig=i,this.globalAreaConfig=a,this.sourceId=`${n}-source-${String(t.id)}`,this.layerId=`${n}-layer-${String(t.id)}`,this.labelSourceId=`${n}-label-source-${String(t.id)}`,this.labelLayerId=`${n}-label-layer-${String(t.id)}`,this.areaSourceId=`${n}-area-source-${String(t.id)}`,this.areaLayerId=`${n}-area-layer-${String(t.id)}`,this.canvas=document.createElement(`canvas`),this.canvas.width=512,this.canvas.height=512,this.ctx=this.canvas.getContext(`2d`)}init(e){this.draw(),this.map.addSource(this.sourceId,{type:`canvas`,canvas:this.canvas,coordinates:e,animate:!0}),this.map.addLayer({id:this.layerId,type:`raster`,source:this.sourceId,paint:{"raster-fade-duration":0,"raster-opacity":1}}),this.initLabelLayer(),this.initAreaLayer()}get nameStyle(){return x(this.entity.nameConfig,this.globalNameConfig,h)}get selectNameStyle(){return x(this.entity.selectNameConfig,this.globalSelectNameConfig,g)}get areaStyle(){return x(`areaConfig`in this.entity?this.entity.areaConfig:void 0,this.globalAreaConfig,_)}getAreaLabelAnchor(){return{anchor:`center`,offset:[0,0]}}initLabelLayer(){let e=this.getEntityCenter(),{confidence:t}=this.entity,n=P(t);this.map.addSource(this.labelSourceId,{type:`geojson`,data:{type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:{name:this.entity.name||``,selected:this.isSelected,opacity:n}}}),this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.labelSourceId,layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.5],"text-allow-overlap":!0},paint:{"text-opacity":[`get`,`opacity`],"text-color":[`case`,[`get`,`selected`],this.selectNameStyle.fillColor,this.nameStyle.fillColor],"text-halo-color":[`case`,[`get`,`selected`],this.selectNameStyle.strokeColor,this.nameStyle.strokeColor],"text-halo-width":[`case`,[`get`,`selected`],this.selectNameStyle.strokeWidth,this.nameStyle.strokeWidth]}})}initAreaLayer(){if(!(`showArea`in this.entity&&this.entity.showArea)||!this.getArea)return;let e=this.getEntityCenter(),{confidence:t}=this.entity,n=P(t),{anchor:r,offset:i}=this.getAreaLabelAnchor();this.map.addSource(this.areaSourceId,{type:`geojson`,data:{type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:{area:A(this.getArea()),opacity:n}}}),this.map.addLayer({id:this.areaLayerId,type:`symbol`,source:this.areaSourceId,layout:{"text-field":[`get`,`area`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":r,"text-offset":i,"text-allow-overlap":!0},paint:{"text-opacity":[`get`,`opacity`],"text-color":this.areaStyle.fillColor,"text-halo-color":this.areaStyle.strokeColor,"text-halo-width":this.areaStyle.strokeWidth}})}updateLabel(){let e=this.map.getSource(this.labelSourceId);if(!e)return;let t=P(this.entity.confidence);e.setData({type:`Feature`,geometry:{type:`Point`,coordinates:this.getEntityCenter()},properties:{name:this.entity.name||``,selected:this.isSelected,opacity:t}})}updateAreaLabel(){if(`showArea`in this.entity&&this.entity.showArea&&this.getArea){let e=this.map.getSource(this.areaSourceId);if(e){let t=P(this.entity.confidence);e.setData({type:`Feature`,geometry:{type:`Point`,coordinates:this.getEntityCenter()},properties:{area:A(this.getArea()),opacity:t}})}else this.initAreaLayer()}else this.map.getLayer(this.areaLayerId)&&this.map.removeLayer(this.areaLayerId),this.map.getSource(this.areaSourceId)&&this.map.removeSource(this.areaSourceId)}setSelected(e){this.isSelected!==e&&(this.isSelected=e,this.updateLabel())}colorWithAlpha(e,t){if(e.startsWith(`rgba`))return e;if(e.startsWith(`#`)){let n=e.slice(1),r=parseInt(n.slice(0,2),16),i=parseInt(n.slice(2,4),16),a=parseInt(n.slice(4,6),16);return`rgba(${r}, ${i}, ${a}, ${t})`}return e.startsWith(`rgb(`)?e.replace(`rgb(`,`rgba(`).replace(`)`,`, ${t})`):e}updateSourceCoordinates(e){this.map.getSource(this.sourceId)?.setCoordinates(e)}getEntityId(){return this.entityId}getCenter(){return this.getEntityCenter()}getBounds(){return this.getEntityBounds()}getLayerId(){return this.layerId}getLabelLayerId(){return this.labelLayerId}destroy(){this.isDestroyed=!0,this.map.getLayer(this.areaLayerId)&&this.map.removeLayer(this.areaLayerId),this.map.getSource(this.areaSourceId)&&this.map.removeSource(this.areaSourceId),this.map.getLayer(this.labelLayerId)&&this.map.removeLayer(this.labelLayerId),this.map.getSource(this.labelSourceId)&&this.map.removeSource(this.labelSourceId),this.map.getLayer(this.layerId)&&this.map.removeLayer(this.layerId),this.map.getSource(this.sourceId)&&this.map.removeSource(this.sourceId)}},ie=`data:image/svg+xml,%3c?xml%20version='1.0'%20standalone='no'?%3e%3c!DOCTYPE%20svg%20PUBLIC%20'-//W3C//DTD%20SVG%201.1//EN'%20'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3e%3csvg%20t='1775030039452'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='24839'%20data-spm-anchor-id='a313x.search_index.0.i1.78953a81FCkAe0'%20width='64'%20height='64'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3cpath%20d='M512%20938.666667l-170.666667-170.666667h341.333334l-170.666667%20170.666667z%20m0-853.333334l170.666667%20170.666667H341.333333l170.666667-170.666667z%20m0%20512a85.333333%2085.333333%200%201%201%200-170.666666%2085.333333%2085.333333%200%200%201%200%20170.666666zM85.333333%20512l170.666667-170.666667v341.333334l-170.666667-170.666667z%20m853.333334%200l-170.666667%20170.666667V341.333333l170.666667%20170.666667z'%20fill='%23ffffff'%20p-id='24840'%3e%3c/path%3e%3c/svg%3e`;const ae=`__edit-move-icon__`;var F=!1;function I(e){if(e.hasImage(`__edit-move-icon__`)||F)return;F=!0;let t=new Image;t.onload=()=>{if(e.hasImage(`__edit-move-icon__`)){F=!1;return}let n=document.createElement(`canvas`);n.width=28,n.height=28;let r=n.getContext(`2d`);r.beginPath(),r.arc(28/2,28/2,28/2,0,Math.PI*2),r.fillStyle=`rgba(51,136,255,0.9)`,r.fill();let i=28*.6,a=(28-i)/2;r.drawImage(t,a,a,i,i);let o=r.getImageData(0,0,28,28);e.addImage(ae,{width:28,height:28,data:new Uint8Array(o.data.buffer)}),F=!1},t.onerror=()=>{F=!1},t.src=ie}function oe(e,t){let n=D(e,t,0),r=D(e,t,90),i=D(e,t,180),a=D(e,t,270)[0],o=r[0],s=i[1],c=n[1];return[[a,c],[o,c],[o,s],[a,s]]}var se=class extends re{constructor(e,t,n,r){super(e,t,`radar`,n,r),this.animationFrameId=null,this.isEditing=!1,this.editSourceId=``,this.editMoveLayerId=``,this.editSourceId=`radar-edit-source-${t.id}`,this.editMoveLayerId=`radar-edit-move-${t.id}`,this.currentRotation=t.initialRotation??w.initialRotation;let i=oe(t.center,t.radius);this.init(i),t.isAnimating&&this.startAnimation()}getEntityCenter(){return this.entity.center}getEntityBounds(){let e=oe(this.entity.center,this.entity.radius),t=e[3][0],n=e[3][1],r=e[1][0],i=e[1][1];return[[t,n],[r,i]]}draw(){let e=this.ctx,t=this.entity;e.clearRect(0,0,512,512),e.globalAlpha=P(t.confidence),this.drawSector(e,t),(t.showRings??w.showRings)&&this.drawRings(e),(t.showScanLine??w.showScanLine)&&this.drawScanLine(e,t),(t.showCenter??w.showCenter)&&this.drawCenterDot(e,t),e.globalAlpha=1}drawSector(e,t){let n=t.colorScheme??w.colorScheme,r=C[n],i=(t.opacity??w.opacity)/100,a=t.sectorAngle,o=N(this.currentRotation-a/2-90),s=N(this.currentRotation+a/2-90),c=e.createRadialGradient(256,256,0,256,256,254);c.addColorStop(0,this.colorWithAlpha(r.center,i)),c.addColorStop(.5,this.colorWithAlpha(r.mid,i*.6)),c.addColorStop(1,this.colorWithAlpha(r.edge,0)),e.beginPath(),e.moveTo(256,256),e.arc(256,256,254,o,s),e.closePath(),e.fillStyle=c,e.fill()}drawRings(e){e.strokeStyle=`rgba(255, 255, 255, 0.2)`,e.lineWidth=2,e.setLineDash([5,5]);for(let t=1;t<=3;t++){let n=254*t/3;e.beginPath(),e.arc(256,256,n,0,Math.PI*2),e.stroke()}e.setLineDash([])}drawScanLine(e,t){let n=t.colorScheme??w.colorScheme,r=C[n],i=N(this.currentRotation-90),a=256+Math.cos(i)*254,o=256+Math.sin(i)*254;e.beginPath(),e.moveTo(256,256),e.lineTo(a,o),e.strokeStyle=r.center,e.lineWidth=2,e.lineCap=`round`,e.globalAlpha=.8,e.stroke(),e.globalAlpha=1}drawCenterDot(e,t){let n=t.colorScheme??w.colorScheme,r=C[n];e.beginPath(),e.arc(256,256,5,0,Math.PI*2),e.fillStyle=r.center,e.fill(),e.strokeStyle=`white`,e.lineWidth=2,e.stroke()}startAnimation(){if(this.animationFrameId!==null||this.isDestroyed)return;let e=()=>{if(this.isDestroyed)return;let t=this.entity.rotationSpeed??w.rotationSpeed;this.currentRotation+=t,this.currentRotation>=360&&(this.currentRotation-=360),this.draw(),this.animationFrameId=requestAnimationFrame(e)};this.animationFrameId=requestAnimationFrame(e),this.map.getSource(this.sourceId)?.play()}stopAnimation(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.map.getSource(this.sourceId)?.pause()}update(e){let t=this.entity;if(this.entity=e,t.center[0]!==e.center[0]||t.center[1]!==e.center[1]||t.radius!==e.radius){let t=oe(e.center,e.radius);this.updateSourceCoordinates(t)}(t.center[0]!==e.center[0]||t.center[1]!==e.center[1]||t.name!==e.name||t.confidence!==e.confidence)&&this.updateLabel(),t.isAnimating!==e.isAnimating&&(e.isAnimating?this.startAnimation():this.stopAnimation()),e.isAnimating||this.draw()}isPointInEntity(e){let{center:t,radius:n}=this.entity,r=e[0]-t[0],i=e[1]-t[1],a=111320*Math.cos(t[1]*Math.PI/180);return Math.sqrt((r*a)**2+(i*110540)**2)<=n}destroy(){this.removeEditLayers(),this.stopAnimation(),super.destroy()}getEditHandleGeoJSON(e){return{type:`FeatureCollection`,features:[{type:`Feature`,geometry:{type:`Point`,coordinates:e??this.entity.center},properties:{handleType:`move`,index:0}}]}}createEditLayers(){this.map.getSource(this.editSourceId)||(I(this.map),this.map.addSource(this.editSourceId,{type:`geojson`,data:this.getEditHandleGeoJSON()}),this.map.addLayer({id:this.editMoveLayerId,type:`symbol`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`move`],layout:{"icon-image":ae,"icon-allow-overlap":!0,"icon-ignore-placement":!0}}))}removeEditLayers(){this.map.getLayer(this.editMoveLayerId)&&this.map.removeLayer(this.editMoveLayerId),this.map.getSource(this.editSourceId)&&this.map.removeSource(this.editSourceId)}refreshEditHandles(e){let t=this.map.getSource(this.editSourceId);t&&t.setData(this.getEditHandleGeoJSON(e))}setEditing(e){this.isEditing!==e&&(this.isEditing=e,e?this.createEditLayers():this.removeEditLayers())}getEditHandleAt(e,t){if(!this.isEditing)return null;let n=this.entity.center,r=this.map.project(e),i=this.map.project(n),a=r.x-i.x,o=r.y-i.y;return a*a+o*o<=144?{type:`move`,index:0,position:n}:null}applyHandleMove(e,t){let n=t[0]-e.position[0],r=t[1]-e.position[1],i=[this.entity.center[0]+n,this.entity.center[1]+r],a={...this.entity,center:i};this.entity=a;let o=oe(i,this.entity.radius);return this.updateSourceCoordinates(o),this.updateLabel(),this.refreshEditHandles(),a}updateEditPreview(e,t){let n=t[0]-e.position[0],r=t[1]-e.position[1],i=[this.entity.center[0]+n,this.entity.center[1]+r],a=oe(i,this.entity.radius);this.updateSourceCoordinates(a);let o=this.entity;this.entity={...this.entity,center:i},this.updateLabel(),this.entity=o,this.refreshEditHandles(i)}cancelEditPreview(){let e=oe(this.entity.center,this.entity.radius);this.updateSourceCoordinates(e),this.updateLabel(),this.refreshEditHandles()}};function ce(e,t,n){let r=t/2,i=n/2,a=D(e,i,0),o=D(e,r,90),s=D(e,i,180),c=D(e,r,270)[0],l=o[0],u=s[1],d=a[1];return[[c,d],[l,d],[l,u],[c,u]]}var le=class extends re{constructor(e,t,n,r){super(e,t,`image`,n,r),this.loadedImage=null,this.imageLoaded=!1,this.currentSrc=``,this.imageAspectRatio=1,this.isEditing=!1,this.editSourceId=``,this.editMoveLayerId=``,this.editSourceId=`image-edit-source-${t.id}`,this.editMoveLayerId=`image-edit-move-${t.id}`,this.loadImage(t.src,!0)}getSize(){let{width:e}=this.entity,t=e/this.imageAspectRatio;return[e,t]}loadImage(e,t=!1){if(!e){console.warn(`Image src is empty`);return}this.currentSrc=e;let n=new Image;n.crossOrigin=`anonymous`,n.onload=()=>{if(e===this.currentSrc)if(this.loadedImage=n,this.imageLoaded=!0,this.imageAspectRatio=n.naturalWidth/n.naturalHeight,t){let[e,t]=this.getSize(),n=ce(this.entity.center,e,t);this.init(n)}else{let[e,t]=this.getSize(),n=ce(this.entity.center,e,t);this.updateSourceCoordinates(n),this.draw()}},n.onerror=()=>{console.error(`Failed to load image: ${e}`)},n.src=e}getEntityCenter(){return this.entity.center}getEntityBounds(){let[e,t]=this.getSize(),n=ce(this.entity.center,e,t),r=n[3][0],i=n[3][1],a=n[1][0],o=n[1][1];return[[r,i],[a,o]]}initLabelLayer(){let e=this.getEntityCenter(),{name:t,confidence:n}=this.entity,r=P(n);this.map.addSource(this.labelSourceId,{type:`geojson`,data:{type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:{name:t||``,selected:this.isSelected,opacity:r}}}),this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.labelSourceId,layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.8],"text-allow-overlap":!0},paint:{"text-opacity":[`get`,`opacity`],"text-color":[`case`,[`get`,`selected`],`#ffcc00`,`#ffffff`],"text-halo-color":[`case`,[`get`,`selected`],`#ff6600`,`rgba(0, 0, 0, 0.8)`],"text-halo-width":[`case`,[`get`,`selected`],2,1]}})}draw(){let e=this.ctx;if(e.clearRect(0,0,512,512),!this.imageLoaded||!this.loadedImage)return;e.globalAlpha=P(this.entity.confidence),e.save(),e.translate(256,256);let t=this.entity.rotation??0;t!==0&&e.rotate(N(t)),e.drawImage(this.loadedImage,-508/2,-508/2,508,508),e.restore(),e.globalAlpha=1}update(e){let t=this.entity;if(this.entity=e,t.src!==e.src){this.imageLoaded=!1,this.loadedImage=null,this.loadImage(e.src);return}if(t.center[0]!==e.center[0]||t.center[1]!==e.center[1]||t.width!==e.width){let[t,n]=this.getSize(),r=ce(e.center,t,n);this.updateSourceCoordinates(r)}(t.center[0]!==e.center[0]||t.center[1]!==e.center[1]||t.name!==e.name||t.confidence!==e.confidence)&&this.updateLabel(),(t.rotation!==e.rotation||t.confidence!==e.confidence)&&this.draw()}isPointInEntity(e){let{center:t}=this.entity,[n,r]=this.getSize(),i=e[0]-t[0],a=e[1]-t[1],o=111320*Math.cos(t[1]*Math.PI/180),s=Math.abs(i*o),c=Math.abs(a*110540);return s<=n/2&&c<=r/2}getEditHandleGeoJSON(e){return{type:`FeatureCollection`,features:[{type:`Feature`,geometry:{type:`Point`,coordinates:e??this.entity.center},properties:{handleType:`move`,index:0}}]}}createEditLayers(){this.map.getSource(this.editSourceId)||(I(this.map),this.map.addSource(this.editSourceId,{type:`geojson`,data:this.getEditHandleGeoJSON()}),this.map.addLayer({id:this.editMoveLayerId,type:`symbol`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`move`],layout:{"icon-image":ae,"icon-allow-overlap":!0,"icon-ignore-placement":!0}}))}removeEditLayers(){this.map.getLayer(this.editMoveLayerId)&&this.map.removeLayer(this.editMoveLayerId),this.map.getSource(this.editSourceId)&&this.map.removeSource(this.editSourceId)}refreshEditHandles(e){let t=this.map.getSource(this.editSourceId);t&&t.setData(this.getEditHandleGeoJSON(e))}setEditing(e){this.isEditing!==e&&(this.isEditing=e,e?this.createEditLayers():this.removeEditLayers())}getEditHandleAt(e,t){if(!this.isEditing)return null;let n=this.entity.center,r=this.map.project(e),i=this.map.project(n),a=r.x-i.x,o=r.y-i.y;return a*a+o*o<=144?{type:`move`,index:0,position:n}:null}applyHandleMove(e,t){let n=t[0]-e.position[0],r=t[1]-e.position[1],i=[this.entity.center[0]+n,this.entity.center[1]+r],a={...this.entity,center:i};this.entity=a;let[o,s]=this.getSize(),c=ce(i,o,s);return this.updateSourceCoordinates(c),this.updateLabel(),this.refreshEditHandles(),a}updateEditPreview(e,t){let n=t[0]-e.position[0],r=t[1]-e.position[1],i=[this.entity.center[0]+n,this.entity.center[1]+r],[a,o]=this.getSize(),s=ce(i,a,o);this.updateSourceCoordinates(s);let c=this.entity;this.entity={...this.entity,center:i},this.updateLabel(),this.entity=c,this.refreshEditHandles(i)}cancelEditPreview(){let[e,t]=this.getSize(),n=ce(this.entity.center,e,t);this.updateSourceCoordinates(n),this.updateLabel(),this.refreshEditHandles()}destroy(){this.removeEditLayers(),super.destroy()}},ue=class{constructor(e,t,n,r){this.marker=null,this.markerElement=null,this.imageElement=null,this.labelElement=null,this.placeholderElement=null,this.isSelected=!1,this.imageAspectRatio=1,this.imageLoaded=!1,this.destroyed=!1,this.isEditing=!1,this.moveIconElement=null,this.map=e,this.entity=t,this.globalNameConfig=n,this.globalSelectNameConfig=r,this.loadImageAndCreateMarker(t.src)}loadImageAndCreateMarker(e){if(!e){console.warn(`Marker src is empty`);return}let t=new Image;t.crossOrigin=`anonymous`,t.onload=()=>{this.destroyed||(this.imageAspectRatio=t.naturalWidth/t.naturalHeight,this.imageLoaded=!0,this.createMarker())},t.onerror=()=>{console.error(`Failed to load marker image: ${e}`)},t.src=e}createMarker(){let{center:e,src:t,width:n,rotation:r=0,anchor:i=`center`,name:a,confidence:o}=this.entity,s=n/this.imageAspectRatio;this.markerElement=document.createElement(`div`),this.markerElement.className=`mapbox-marker-container`,this.markerElement.setAttribute(`data-entity-id`,String(this.entity.id)),this.onBeforeImageCreate(),a&&(this.placeholderElement=document.createElement(`div`),this.placeholderElement.className=`mapbox-marker-placeholder`,this.placeholderElement.textContent=a,this.markerElement.appendChild(this.placeholderElement)),this.imageElement=document.createElement(`img`),this.imageElement.src=t,this.imageElement.style.width=`${n}px`,this.imageElement.style.height=`${s}px`,this.imageElement.style.transform=`rotate(${r}deg)`,this.imageElement.style.opacity=`${P(o)}`,this.imageElement.style.pointerEvents=`auto`,this.markerElement.appendChild(this.imageElement),a&&(this.labelElement=document.createElement(`div`),this.labelElement.className=`mapbox-marker-label`,this.labelElement.textContent=a,this.labelElement.setAttribute(`data-entity-id`,String(this.entity.id)),this.updateLabelStyle(),this.markerElement.appendChild(this.labelElement)),this.marker=new l.default.Marker({element:this.markerElement,anchor:i}).setLngLat(e).addTo(this.map),this.onMarkerCreated()}onBeforeImageCreate(){}onMarkerCreated(){}get nameStyle(){return x(this.entity.nameConfig,this.globalNameConfig,h)}get selectNameStyle(){return x(this.entity.selectNameConfig,this.globalSelectNameConfig,g)}updateLabelStyle(){if(!this.labelElement)return;let{confidence:e}=this.entity,t=P(e),n=this.isSelected?this.selectNameStyle:this.nameStyle;this.labelElement.className=this.isSelected?`mapbox-marker-label mapbox-marker-label--selected`:`mapbox-marker-label`,this.labelElement.style.opacity=`${t}`,this.labelElement.style.color=n.fillColor;let r=n.strokeWidth,i=n.strokeColor;this.labelElement.style.webkitTextStroke=`${r*1.5}px ${i}`,this.labelElement.style.paintOrder=`stroke fill`,this.labelElement.style.textShadow=`none`}getEntityId(){return this.entity.id}getCenter(){return this.entity.center}getBounds(){let{center:e,width:t}=this.entity,n=t/this.imageAspectRatio,r=this.map.getZoom(),i=156543.03392*Math.cos(e[1]*Math.PI/180)/2**r,a=t*i,o=n*i,s=111320*Math.cos(e[1]*Math.PI/180),c=a/2/s,l=o/2/110540;return[[e[0]-c,e[1]-l],[e[0]+c,e[1]+l]]}getLayerId(){return`marker-${this.entity.id}`}getLabelLayerId(){return null}setSelected(e){this.isSelected!==e&&(this.isSelected=e,this.updateLabelStyle())}isPointInEntity(e){if(!this.marker||!this.imageLoaded)return!1;let{center:t,width:n}=this.entity,r=n/this.imageAspectRatio,i=this.map.getZoom(),a=156543.03392*Math.cos(t[1]*Math.PI/180)/2**i,o=n*a,s=r*a,c=e[0]-t[0],l=e[1]-t[1],u=111320*Math.cos(t[1]*Math.PI/180),d=Math.abs(c*u),f=Math.abs(l*110540);return d<=o/2&&f<=s/2}update(e){let t=this.entity;if(this.entity=e,t.src!==e.src){this.destroy(),this.imageLoaded=!1,this.loadImageAndCreateMarker(e.src);return}if(!this.marker||!this.imageElement)return;(t.center[0]!==e.center[0]||t.center[1]!==e.center[1])&&this.marker.setLngLat(e.center);let n=e.width/this.imageAspectRatio,r=e.rotation??0,i=P(e.confidence);(t.width!==e.width||t.rotation!==e.rotation||t.confidence!==e.confidence)&&(this.imageElement.style.width=`${e.width}px`,this.imageElement.style.height=`${n}px`,this.imageElement.style.transform=`rotate(${r}deg)`,this.imageElement.style.opacity=`${i}`),t.name!==e.name&&(e.name&&!this.labelElement?(this.labelElement=document.createElement(`div`),this.labelElement.className=`mapbox-marker-label`,this.labelElement.textContent=e.name,this.updateLabelStyle(),this.markerElement?.appendChild(this.labelElement),this.placeholderElement=document.createElement(`div`),this.placeholderElement.className=`mapbox-marker-placeholder`,this.placeholderElement.textContent=e.name,this.markerElement?.insertBefore(this.placeholderElement,this.markerElement.firstChild)):!e.name&&this.labelElement?(this.labelElement.remove(),this.labelElement=null,this.placeholderElement?.remove(),this.placeholderElement=null):this.labelElement&&(this.labelElement.textContent=e.name||``,this.placeholderElement&&(this.placeholderElement.textContent=e.name||``))),t.confidence!==e.confidence&&this.updateLabelStyle()}destroy(){this.removeMoveIcon(),this.destroyed=!0,this.marker&&=(this.marker.remove(),null),this.markerElement=null,this.imageElement=null,this.labelElement=null,this.placeholderElement=null}createMoveIcon(){if(this.moveIconElement||!this.markerElement)return;let e=document.createElement(`div`);e.className=`mapbox-marker-move-icon`,e.style.cssText=`width:28px;height:28px;border-radius:50%;background:rgba(51,136,255,0.9);display:flex;align-items:center;justify-content:center;cursor:move;position:absolute;left:50%;bottom:0;transform:translate(-50%,100%);pointer-events:none;`;let t=document.createElement(`img`);t.src=ie,t.style.cssText=`width:60%;height:60%;`,e.appendChild(t),this.markerElement.appendChild(e),this.moveIconElement=e}removeMoveIcon(){this.moveIconElement&&=(this.moveIconElement.remove(),null)}setEditing(e){this.isEditing!==e&&(this.isEditing=e,e?this.createMoveIcon():this.removeMoveIcon())}getEditHandleAt(e,t){if(!this.isEditing)return null;let n=this.map.project(e);if(this.moveIconElement){let t=this.moveIconElement.getBoundingClientRect(),r=this.map.getContainer().getBoundingClientRect(),i=t.left+t.width/2-r.left,a=t.top+t.height/2-r.top,o=n.x-i,s=n.y-a;if(o*o+s*s<=256)return{type:`move`,index:0,position:e}}return null}applyHandleMove(e,t){let n=t[0]-e.position[0],r=t[1]-e.position[1],i=[this.entity.center[0]+n,this.entity.center[1]+r],a={...this.entity,center:i};return this.entity=a,this.marker&&this.marker.setLngLat(i),a}updateEditPreview(e,t){let n=t[0]-e.position[0],r=t[1]-e.position[1],i=[this.entity.center[0]+n,this.entity.center[1]+r];this.marker&&this.marker.setLngLat(i)}cancelEditPreview(){this.marker&&this.marker.setLngLat(this.entity.center)}},de=class extends ue{constructor(e,t,n,r){super(e,t,n,r),this.showTrajectory=0,this.showTrajectoryPoints=!1,this.trajInitialized=!1,this.statusElement=null,this.statusRoot=null,this.trajSourceId=`unit-traj-source-${t.id}`,this.trajLayerId=`unit-traj-layer-${t.id}`,this.trajPointsLayerId=`unit-traj-points-layer-${t.id}`,t.showTrajectory&&(this.showTrajectory=t.showTrajectory),this.showTrajectoryPoints=t.showTrajectoryPoints??!1}renderStatus(){return null}onBeforeImageCreate(){this.markerElement&&(this.statusElement=document.createElement(`div`),this.statusElement.className=`mapbox-unit-status`,this.markerElement.appendChild(this.statusElement),this.updateStatusContent())}updateStatusContent(){if(!this.statusElement)return;let e=this.renderStatus();e?(this.statusRoot||=(0,d.createRoot)(this.statusElement),this.statusRoot.render(e),this.statusElement.style.display=`block`):(this.statusRoot&&this.statusRoot.render(null),this.statusElement.style.display=`none`)}refreshStatus(){this.updateStatusContent()}getLayerId(){return`unit-${this.entity.id}`}onMarkerCreated(){this.entity.showTrajectory&&(this.showTrajectory=this.entity.showTrajectory,this.initTrajectoryLayer())}shouldShowTrajectory(){return this.showTrajectory===`all`||typeof this.showTrajectory==`number`&&this.showTrajectory>0}getTrajectoryCount(){let{predicted_traj:e}=this.entity;return!e||e.length===0?0:this.showTrajectory===`all`?e.length:typeof this.showTrajectory==`number`&&this.showTrajectory>0?Math.min(this.showTrajectory,e.length):0}initTrajectoryLayer(){if(this.trajInitialized)return;if(!this.map.isStyleLoaded()){requestAnimationFrame(()=>this.initTrajectoryLayer());return}let e=this.getTrajectoryGeoJSON();this.map.addSource(this.trajSourceId,{type:`geojson`,data:e});let t=this.shouldShowTrajectory()?`visible`:`none`,n=this.shouldShowTrajectory()&&this.showTrajectoryPoints?`visible`:`none`;this.map.addLayer({id:this.trajLayerId,type:`line`,source:this.trajSourceId,layout:{"line-join":`round`,"line-cap":`round`,visibility:t},paint:{"line-color":this.isSelected?`#ffcc00`:`#00ff88`,"line-width":3,"line-opacity":P(this.entity.confidence)*.8,"line-dasharray":[2,2]}}),this.map.addLayer({id:this.trajPointsLayerId,type:`circle`,source:this.trajSourceId,filter:[`==`,`$type`,`Point`],layout:{visibility:n},paint:{"circle-radius":4,"circle-color":this.isSelected?`#ffcc00`:`#00ff88`,"circle-stroke-color":`#ffffff`,"circle-stroke-width":1,"circle-opacity":P(this.entity.confidence)}}),this.trajInitialized=!0}getTrajectoryGeoJSON(){let{predicted_traj:e,center:t}=this.entity,n=this.getTrajectoryCount();if(!e||e.length===0||n===0)return{type:`FeatureCollection`,features:[]};let r=e.slice(0,n),i=[t],a=[];return r.forEach((e,t)=>{let n=[e.lon,e.lat];i.push(n),a.push({type:`Feature`,geometry:{type:`Point`,coordinates:n},properties:{index:t,alt:e.alt}})}),{type:`FeatureCollection`,features:[{type:`Feature`,geometry:{type:`LineString`,coordinates:i},properties:{}},...a]}}setShowTrajectory(e){let t=e===`all`||typeof e==`number`&&e>0;if(t&&!this.trajInitialized){this.showTrajectory=e,this.initTrajectoryLayer();return}let n=this.shouldShowTrajectory();if(this.showTrajectory=e,this.trajInitialized){let e=t?`visible`:`none`,r=t&&this.showTrajectoryPoints?`visible`:`none`;this.map.getLayer(this.trajLayerId)&&this.map.setLayoutProperty(this.trajLayerId,`visibility`,e),this.map.getLayer(this.trajPointsLayerId)&&this.map.setLayoutProperty(this.trajPointsLayerId,`visibility`,r),t&&n&&this.updateTrajectoryData()}}getShowTrajectory(){return this.showTrajectory}setShowTrajectoryPoints(e){if(this.showTrajectoryPoints=e,this.trajInitialized&&this.map.getLayer(this.trajPointsLayerId)){let t=this.shouldShowTrajectory()&&e?`visible`:`none`;this.map.setLayoutProperty(this.trajPointsLayerId,`visibility`,t)}}getShowTrajectoryPoints(){return this.showTrajectoryPoints}setSelected(e){let t=this.isSelected;super.setSelected(e),t!==e&&this.trajInitialized&&this.updateTrajectoryStyle()}updateTrajectoryStyle(){let e=this.isSelected?`#ffcc00`:`#00ff88`,t=P(this.entity.confidence);this.map.getLayer(this.trajLayerId)&&(this.map.setPaintProperty(this.trajLayerId,`line-color`,e),this.map.setPaintProperty(this.trajLayerId,`line-opacity`,t*.8)),this.map.getLayer(this.trajPointsLayerId)&&(this.map.setPaintProperty(this.trajPointsLayerId,`circle-color`,e),this.map.setPaintProperty(this.trajPointsLayerId,`circle-opacity`,t))}updateTrajectoryData(){if(!this.trajInitialized)return;let e=this.map.getSource(this.trajSourceId);e&&e.setData(this.getTrajectoryGeoJSON())}update(e){let t=this.entity;super.update(e),t.showTrajectory!==e.showTrajectory&&this.setShowTrajectory(e.showTrajectory??0),t.showTrajectoryPoints!==e.showTrajectoryPoints&&this.setShowTrajectoryPoints(e.showTrajectoryPoints??!1),this.updateTrajectoryData(),t.confidence!==e.confidence&&this.updateTrajectoryStyle()}destroy(){this.statusRoot&&=(this.statusRoot.unmount(),null),this.statusElement=null,this.trajInitialized&&(this.map.getLayer(this.trajPointsLayerId)&&this.map.removeLayer(this.trajPointsLayerId),this.map.getLayer(this.trajLayerId)&&this.map.removeLayer(this.trajLayerId),this.map.getSource(this.trajSourceId)&&this.map.removeSource(this.trajSourceId)),super.destroy()}},fe=class e{static{this.DEFAULTS={strokeColor:`#3388ff`,strokeWidth:2,strokeOpacity:1,fillColor:`#3388ff`,fillOpacity:.2}}constructor(e,t,n,r,i,a){this.isSelected=!1,this.initialized=!1,this.isEditing=!1,this.map=e,this.entity=t,this.globalNameConfig=n,this.globalSelectNameConfig=r,this.globalAreaConfig=i,this.globalLengthConfig=a,this.sourceId=`polygon-source-${t.id}`,this.fillLayerId=`polygon-fill-${t.id}`,this.strokeLayerId=`polygon-stroke-${t.id}`,this.labelLayerId=`polygon-label-${t.id}`,this.areaLayerId=`polygon-area-${t.id}`,this.lengthLayerId=`polygon-length-${t.id}`,this.editSourceId=`polygon-edit-source-${t.id}`,this.editHandleLayerId=`polygon-edit-handles-${t.id}`,this.editMidpointLayerId=`polygon-edit-midpoints-${t.id}`,this.editMoveLayerId=`polygon-edit-move-${t.id}`,this.initLayers()}get nameStyle(){return x(this.entity.nameConfig,this.globalNameConfig,h)}get selectNameStyle(){return x(this.entity.selectNameConfig,this.globalSelectNameConfig,g)}get areaStyle(){return x(this.entity.areaConfig,this.globalAreaConfig,_)}get lengthStyle(){return x(this.entity.lengthConfig,this.globalLengthConfig,b)}initLayers(){if(!this.initialized)try{let t=this.getGeoJSON();this.map.addSource(this.sourceId,{type:`geojson`,data:t});let n=this.entity.confidence??1,r=P(n);this.map.addLayer({id:this.fillLayerId,type:`fill`,source:this.sourceId,filter:[`==`,`$type`,`Polygon`],paint:{"fill-color":this.entity.fillColor??e.DEFAULTS.fillColor,"fill-opacity":(this.entity.fillOpacity??e.DEFAULTS.fillOpacity)*r}}),this.map.addLayer({id:this.strokeLayerId,type:`line`,source:this.sourceId,filter:[`==`,`$type`,`Polygon`],layout:{"line-join":`round`,"line-cap":`round`},paint:{"line-color":this.isSelected?`#ffcc00`:this.entity.strokeColor??e.DEFAULTS.strokeColor,"line-width":this.entity.strokeWidth??e.DEFAULTS.strokeWidth,"line-opacity":(this.entity.strokeOpacity??e.DEFAULTS.strokeOpacity)*r}}),this.entity.name&&this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`label`],layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.8],"text-allow-overlap":!0},paint:{"text-color":this.isSelected?this.selectNameStyle.fillColor:this.nameStyle.fillColor,"text-halo-color":this.isSelected?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor,"text-halo-width":this.isSelected?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth,"text-opacity":r}}),this.entity.showArea&&this.map.addLayer({id:this.areaLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`area`],layout:{"text-field":[`get`,`area`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-allow-overlap":!0},paint:{"text-color":this.areaStyle.fillColor,"text-halo-color":this.areaStyle.strokeColor,"text-halo-width":this.areaStyle.strokeWidth,"text-opacity":r}}),this.entity.showLength&&this.map.addLayer({id:this.lengthLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`length`],layout:{"text-field":[`get`,`length`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-offset":[0,-.8],"text-allow-overlap":!0},paint:{"text-color":this.lengthStyle.fillColor,"text-halo-color":this.lengthStyle.strokeColor,"text-halo-width":this.lengthStyle.strokeWidth,"text-opacity":r}}),this.initialized=!0}catch{this.map.once(`idle`,()=>this.initLayers())}}getGeoJSON(){let{coordinates:e}=this.entity;if(!e||e.length<3)return{type:`FeatureCollection`,features:[]};let t=[...e];(e[0][0]!==e[e.length-1][0]||e[0][1]!==e[e.length-1][1])&&t.push(e[0]);let n=[{type:`Feature`,geometry:{type:`Polygon`,coordinates:[t]},properties:{}}];if(this.entity.name){let t=this.getBottomPoint(e);n.push({type:`Feature`,geometry:{type:`Point`,coordinates:t},properties:{pointType:`label`,name:this.entity.name}})}if(this.entity.showArea){let e=this.calculateGeometricCenter();n.push({type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:{pointType:`area`,area:A(this.getArea())}})}if(this.entity.showLength)for(let t=0;t<e.length;t++){let r=e[t],i=e[(t+1)%e.length],a=[(r[0]+i[0])/2,(r[1]+i[1])/2],o=O(r,i);n.push({type:`Feature`,geometry:{type:`Point`,coordinates:a},properties:{pointType:`length`,length:j(o)}})}return{type:`FeatureCollection`,features:n}}getBottomPoint(e){let t=e[0],n=e[0][1];for(let r of e)r[1]<n&&(n=r[1],t=r);return t}getArea(){let{coordinates:e}=this.entity;if(!e||e.length<3)return 0;let t=[...e];return(t[0][0]!==t[t.length-1][0]||t[0][1]!==t[t.length-1][1])&&t.push(t[0]),ee(t)}getEntityId(){return this.entity.id}getBounds(){let{coordinates:e}=this.entity;if(!e||e.length===0){let e=this.getCenter();return[e,e]}let t=1/0,n=-1/0,r=1/0,i=-1/0;for(let a of e)t=Math.min(t,a[0]),n=Math.max(n,a[0]),r=Math.min(r,a[1]),i=Math.max(i,a[1]);return[[t,r],[n,i]]}getCenter(){return this.entity.center?this.entity.center:this.calculateGeometricCenter()}calculateGeometricCenter(){let{coordinates:e}=this.entity;if(!e||e.length===0)return[0,0];let t=0,n=0;for(let r of e)t+=r[0],n+=r[1];return[t/e.length,n/e.length]}getLayerId(){return this.fillLayerId}getLabelLayerId(){return this.entity.name?this.labelLayerId:null}setSelected(t){this.isSelected!==t&&(this.isSelected=t,this.initialized&&(this.map.getLayer(this.strokeLayerId)&&this.map.setPaintProperty(this.strokeLayerId,`line-color`,t?`#ffcc00`:this.entity.strokeColor??e.DEFAULTS.strokeColor),this.map.getLayer(this.labelLayerId)&&(this.map.setPaintProperty(this.labelLayerId,`text-color`,t?this.selectNameStyle.fillColor:this.nameStyle.fillColor),this.map.setPaintProperty(this.labelLayerId,`text-halo-color`,t?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor),this.map.setPaintProperty(this.labelLayerId,`text-halo-width`,t?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth))))}isPointInEntity(e){let{coordinates:t}=this.entity;return!t||t.length<3?!1:this.pointInPolygon(e,t)}pointInPolygon(e,t){let[n,r]=e,i=!1;for(let e=0,a=t.length-1;e<t.length;a=e++){let[o,s]=t[e],[c,l]=t[a];s>r!=l>r&&n<(c-o)*(r-s)/(l-s)+o&&(i=!i)}return i}update(t){let n=this.entity;if(this.entity=t,!this.initialized)return;let r=t.confidence??1,i=P(r);if(n.coordinates!==t.coordinates||n.name!==t.name||n.showArea!==t.showArea||n.showLength!==t.showLength){let e=this.map.getSource(this.sourceId);e&&e.setData(this.getGeoJSON()),!n.name&&t.name&&!this.map.getLayer(this.labelLayerId)?this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`label`],layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.8],"text-allow-overlap":!0},paint:{"text-color":this.isSelected?this.selectNameStyle.fillColor:this.nameStyle.fillColor,"text-halo-color":this.isSelected?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor,"text-halo-width":this.isSelected?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth,"text-opacity":i}}):n.name&&!t.name&&this.map.getLayer(this.labelLayerId)&&this.map.removeLayer(this.labelLayerId),!n.showArea&&t.showArea&&!this.map.getLayer(this.areaLayerId)?this.map.addLayer({id:this.areaLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`area`],layout:{"text-field":[`get`,`area`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-allow-overlap":!0},paint:{"text-color":this.areaStyle.fillColor,"text-halo-color":this.areaStyle.strokeColor,"text-halo-width":this.areaStyle.strokeWidth,"text-opacity":i}}):n.showArea&&!t.showArea&&this.map.getLayer(this.areaLayerId)&&this.map.removeLayer(this.areaLayerId),!n.showLength&&t.showLength&&!this.map.getLayer(this.lengthLayerId)?this.map.addLayer({id:this.lengthLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`length`],layout:{"text-field":[`get`,`length`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-offset":[0,-.8],"text-allow-overlap":!0},paint:{"text-color":this.lengthStyle.fillColor,"text-halo-color":this.lengthStyle.strokeColor,"text-halo-width":this.lengthStyle.strokeWidth,"text-opacity":i}}):n.showLength&&!t.showLength&&this.map.getLayer(this.lengthLayerId)&&this.map.removeLayer(this.lengthLayerId)}(n.fillColor!==t.fillColor||n.fillOpacity!==t.fillOpacity||n.confidence!==t.confidence)&&this.map.getLayer(this.fillLayerId)&&(this.map.setPaintProperty(this.fillLayerId,`fill-color`,t.fillColor??e.DEFAULTS.fillColor),this.map.setPaintProperty(this.fillLayerId,`fill-opacity`,(t.fillOpacity??e.DEFAULTS.fillOpacity)*i)),(n.strokeColor!==t.strokeColor||n.strokeWidth!==t.strokeWidth||n.strokeOpacity!==t.strokeOpacity||n.confidence!==t.confidence)&&this.map.getLayer(this.strokeLayerId)&&(this.isSelected||this.map.setPaintProperty(this.strokeLayerId,`line-color`,t.strokeColor??e.DEFAULTS.strokeColor),this.map.setPaintProperty(this.strokeLayerId,`line-width`,t.strokeWidth??e.DEFAULTS.strokeWidth),this.map.setPaintProperty(this.strokeLayerId,`line-opacity`,(t.strokeOpacity??e.DEFAULTS.strokeOpacity)*i)),n.confidence!==t.confidence&&(this.map.getLayer(this.labelLayerId)&&this.map.setPaintProperty(this.labelLayerId,`text-opacity`,i),this.map.getLayer(this.areaLayerId)&&this.map.setPaintProperty(this.areaLayerId,`text-opacity`,i),this.map.getLayer(this.lengthLayerId)&&this.map.setPaintProperty(this.lengthLayerId,`text-opacity`,i))}getEditHandleGeoJSON(e){let t=e??this.entity.coordinates;if(!t||t.length<3)return{type:`FeatureCollection`,features:[]};let n=[];for(let e=0;e<t.length;e++)n.push({type:`Feature`,geometry:{type:`Point`,coordinates:t[e]},properties:{handleType:`vertex`,index:e}});for(let e=0;e<t.length;e++){let r=t[e],i=t[(e+1)%t.length];n.push({type:`Feature`,geometry:{type:`Point`,coordinates:[(r[0]+i[0])/2,(r[1]+i[1])/2]},properties:{handleType:`midpoint`,index:e}})}let r=0,i=0;for(let e of t)r+=e[0],i+=e[1];return r/=t.length,i/=t.length,n.push({type:`Feature`,geometry:{type:`Point`,coordinates:[r,i]},properties:{handleType:`move`,index:0}}),{type:`FeatureCollection`,features:n}}createEditLayers(){this.map.getSource(this.editSourceId)||(I(this.map),this.map.addSource(this.editSourceId,{type:`geojson`,data:this.getEditHandleGeoJSON()}),this.map.addLayer({id:this.editMidpointLayerId,type:`circle`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`midpoint`],paint:{"circle-radius":4,"circle-color":`#3388ff`,"circle-opacity":.5,"circle-stroke-color":`#3388ff`,"circle-stroke-width":1}}),this.map.addLayer({id:this.editHandleLayerId,type:`circle`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`vertex`],paint:{"circle-radius":6,"circle-color":`#ffffff`,"circle-stroke-color":`#3388ff`,"circle-stroke-width":2}}),this.map.addLayer({id:this.editMoveLayerId,type:`symbol`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`move`],layout:{"icon-image":ae,"icon-allow-overlap":!0,"icon-ignore-placement":!0}}))}removeEditLayers(){this.map.getLayer(this.editMoveLayerId)&&this.map.removeLayer(this.editMoveLayerId),this.map.getLayer(this.editHandleLayerId)&&this.map.removeLayer(this.editHandleLayerId),this.map.getLayer(this.editMidpointLayerId)&&this.map.removeLayer(this.editMidpointLayerId),this.map.getSource(this.editSourceId)&&this.map.removeSource(this.editSourceId)}refreshEditHandles(e){let t=this.map.getSource(this.editSourceId);t&&t.setData(this.getEditHandleGeoJSON(e))}setEditing(e){this.isEditing!==e&&(this.isEditing=e,this.initialized&&(e?this.createEditLayers():this.removeEditLayers()))}getEditHandleAt(e,t){if(!this.isEditing)return null;let n=this.entity.coordinates;if(!n||n.length<3)return null;let r=this.map.project(e),i=0,a=0;for(let e of n)i+=e[0],a+=e[1];i/=n.length,a/=n.length;let o=this.map.project([i,a]),s=r.x-o.x,c=r.y-o.y;if(s*s+c*c<=144)return{type:`move`,index:0,position:[i,a]};for(let e=0;e<n.length;e++){let t=this.map.project(n[e]),i=r.x-t.x,a=r.y-t.y;if(i*i+a*a<=100)return{type:`vertex`,index:e,position:n[e]}}for(let e=0;e<n.length;e++){let t=n[e],i=n[(e+1)%n.length],a=[(t[0]+i[0])/2,(t[1]+i[1])/2],o=this.map.project(a),s=r.x-o.x,c=r.y-o.y;if(s*s+c*c<=100)return{type:`midpoint`,index:e,position:a}}return null}offsetCoordinates(e,t,n){let r=n[0]-t[0],i=n[1]-t[1];return e.map(e=>[e[0]+r,e[1]+i])}applyHandleMove(e,t){let n;e.type===`move`?n=this.offsetCoordinates(this.entity.coordinates,e.position,t):(n=[...this.entity.coordinates],n[e.index]=t);let r={...this.entity,coordinates:n};this.entity=r;let i=this.map.getSource(this.sourceId);return i&&i.setData(this.getGeoJSON()),this.refreshEditHandles(),r}updateEditPreview(e,t){let n;e.type===`move`?n=this.offsetCoordinates(this.entity.coordinates,e.position,t):(n=[...this.entity.coordinates],n[e.index]=t);let r=this.entity;this.entity={...this.entity,coordinates:n};let i=this.map.getSource(this.sourceId);i&&i.setData(this.getGeoJSON()),this.entity=r,this.refreshEditHandles(n)}cancelEditPreview(){let e=this.map.getSource(this.sourceId);e&&e.setData(this.getGeoJSON()),this.refreshEditHandles()}deleteVertex(e){let t=this.entity.coordinates;if(!t||t.length<=3)return null;let n=t.filter((t,n)=>n!==e),r={...this.entity,coordinates:n};this.entity=r;let i=this.map.getSource(this.sourceId);return i&&i.setData(this.getGeoJSON()),this.refreshEditHandles(),r}addVertex(e,t){let n=[...this.entity.coordinates];n.splice(e+1,0,t);let r={...this.entity,coordinates:n};this.entity=r;let i=this.map.getSource(this.sourceId);return i&&i.setData(this.getGeoJSON()),this.refreshEditHandles(),r}destroy(){this.initialized&&=(this.removeEditLayers(),this.map.getLayer(this.lengthLayerId)&&this.map.removeLayer(this.lengthLayerId),this.map.getLayer(this.areaLayerId)&&this.map.removeLayer(this.areaLayerId),this.map.getLayer(this.labelLayerId)&&this.map.removeLayer(this.labelLayerId),this.map.getLayer(this.strokeLayerId)&&this.map.removeLayer(this.strokeLayerId),this.map.getLayer(this.fillLayerId)&&this.map.removeLayer(this.fillLayerId),this.map.getSource(this.sourceId)&&this.map.removeSource(this.sourceId),!1)}},pe=class e{static{this.DEFAULTS={strokeColor:`#3388ff`,strokeWidth:2,strokeOpacity:1,lineCap:`round`,lineJoin:`round`}}constructor(e,t,n,r,i){this.isSelected=!1,this.initialized=!1,this.isEditing=!1,this.map=e,this.entity=t,this.globalNameConfig=n,this.globalSelectNameConfig=r,this.globalLengthConfig=i,this.sourceId=`polyline-source-${t.id}`,this.lineLayerId=`polyline-stroke-${t.id}`,this.labelLayerId=`polyline-label-${t.id}`,this.lengthLayerId=`polyline-length-${t.id}`,this.editSourceId=`polyline-edit-source-${t.id}`,this.editHandleLayerId=`polyline-edit-handles-${t.id}`,this.editMidpointLayerId=`polyline-edit-midpoints-${t.id}`,this.editMoveLayerId=`polyline-edit-move-${t.id}`,this.initLayers()}get nameStyle(){return x(this.entity.nameConfig,this.globalNameConfig,h)}get selectNameStyle(){return x(this.entity.selectNameConfig,this.globalSelectNameConfig,g)}get lengthStyle(){return x(this.entity.lengthConfig,this.globalLengthConfig,b)}initLayers(){if(!this.initialized)try{let t=this.getGeoJSON();this.map.addSource(this.sourceId,{type:`geojson`,data:t});let n=this.entity.confidence??1,r=P(n);this.map.addLayer({id:this.lineLayerId,type:`line`,source:this.sourceId,filter:[`==`,`$type`,`LineString`],layout:{"line-join":this.entity.lineJoin??e.DEFAULTS.lineJoin,"line-cap":this.entity.lineCap??e.DEFAULTS.lineCap},paint:{"line-color":this.isSelected?`#ffcc00`:this.entity.strokeColor??e.DEFAULTS.strokeColor,"line-width":this.entity.strokeWidth??e.DEFAULTS.strokeWidth,"line-opacity":(this.entity.strokeOpacity??e.DEFAULTS.strokeOpacity)*r,...this.entity.dashArray?{"line-dasharray":this.entity.dashArray}:{}}}),this.entity.name&&this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`label`],layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.8],"text-allow-overlap":!0},paint:{"text-color":this.isSelected?this.selectNameStyle.fillColor:this.nameStyle.fillColor,"text-halo-color":this.isSelected?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor,"text-halo-width":this.isSelected?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth,"text-opacity":r}}),this.entity.showLength&&this.map.addLayer({id:this.lengthLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`length`],layout:{"text-field":[`get`,`length`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-offset":[0,-.8],"text-allow-overlap":!0},paint:{"text-color":this.lengthStyle.fillColor,"text-halo-color":this.lengthStyle.strokeColor,"text-halo-width":this.lengthStyle.strokeWidth,"text-opacity":r}}),this.initialized=!0}catch{this.map.once(`idle`,()=>this.initLayers())}}getGeoJSON(){let{coordinates:e,name:t}=this.entity;if(!e||e.length<2)return{type:`FeatureCollection`,features:[]};let n=[{type:`Feature`,geometry:{type:`LineString`,coordinates:e},properties:{}}];if(t){let r=this.getMidPoint(e);n.push({type:`Feature`,geometry:{type:`Point`,coordinates:r},properties:{pointType:`label`,name:t}})}if(this.entity.showLength)for(let t=0;t<e.length-1;t++){let r=e[t],i=e[t+1],a=[(r[0]+i[0])/2,(r[1]+i[1])/2],o=O(r,i);n.push({type:`Feature`,geometry:{type:`Point`,coordinates:a},properties:{pointType:`length`,length:j(o)}})}return{type:`FeatureCollection`,features:n}}getMidPoint(e){if(e.length===1)return e[0];let t=Math.floor((e.length-1)/2),n=e[t],r=e[t+1];return[(n[0]+r[0])/2,(n[1]+r[1])/2]}getEntityId(){return this.entity.id}getBounds(){let{coordinates:e}=this.entity;if(!e||e.length===0){let e=this.getCenter();return[e,e]}let t=1/0,n=-1/0,r=1/0,i=-1/0;for(let a of e)t=Math.min(t,a[0]),n=Math.max(n,a[0]),r=Math.min(r,a[1]),i=Math.max(i,a[1]);return[[t,r],[n,i]]}getCenter(){return this.entity.center?this.entity.center:this.calculateGeometricCenter()}calculateGeometricCenter(){let{coordinates:e}=this.entity;if(!e||e.length===0)return[0,0];let t=0,n=0;for(let r of e)t+=r[0],n+=r[1];return[t/e.length,n/e.length]}getLayerId(){return this.lineLayerId}getLabelLayerId(){return this.entity.name?this.labelLayerId:null}setSelected(t){this.isSelected!==t&&(this.isSelected=t,this.initialized&&(this.map.getLayer(this.lineLayerId)&&this.map.setPaintProperty(this.lineLayerId,`line-color`,t?`#ffcc00`:this.entity.strokeColor??e.DEFAULTS.strokeColor),this.map.getLayer(this.labelLayerId)&&(this.map.setPaintProperty(this.labelLayerId,`text-color`,t?this.selectNameStyle.fillColor:this.nameStyle.fillColor),this.map.setPaintProperty(this.labelLayerId,`text-halo-color`,t?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor),this.map.setPaintProperty(this.labelLayerId,`text-halo-width`,t?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth))))}isPointInEntity(e){let{coordinates:t}=this.entity;if(!t||t.length<2)return!1;let n=this.getClickThreshold();for(let r=0;r<t.length-1;r++)if(this.pointToSegmentDistance(e,t[r],t[r+1])<n)return!0;return!1}getClickThreshold(){return .001*2**(12-this.map.getZoom())}pointToSegmentDistance(e,t,n){let[r,i]=e,[a,o]=t,[s,c]=n,l=s-a,u=c-o,d=l*l+u*u;if(d===0)return Math.sqrt((r-a)*(r-a)+(i-o)*(i-o));let f=((r-a)*l+(i-o)*u)/d;f=Math.max(0,Math.min(1,f));let p=a+f*l,m=o+f*u;return Math.sqrt((r-p)*(r-p)+(i-m)*(i-m))}update(t){let n=this.entity;if(this.entity=t,!this.initialized)return;let r=t.confidence??1,i=P(r);if(n.coordinates!==t.coordinates||n.name!==t.name||n.showLength!==t.showLength){let e=this.map.getSource(this.sourceId);e&&e.setData(this.getGeoJSON()),!n.name&&t.name&&!this.map.getLayer(this.labelLayerId)?this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`label`],layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.8],"text-allow-overlap":!0},paint:{"text-color":this.isSelected?this.selectNameStyle.fillColor:this.nameStyle.fillColor,"text-halo-color":this.isSelected?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor,"text-halo-width":this.isSelected?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth,"text-opacity":i}}):n.name&&!t.name&&this.map.getLayer(this.labelLayerId)&&this.map.removeLayer(this.labelLayerId),!n.showLength&&t.showLength&&!this.map.getLayer(this.lengthLayerId)?this.map.addLayer({id:this.lengthLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`length`],layout:{"text-field":[`get`,`length`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-offset":[0,-.8],"text-allow-overlap":!0},paint:{"text-color":this.lengthStyle.fillColor,"text-halo-color":this.lengthStyle.strokeColor,"text-halo-width":this.lengthStyle.strokeWidth,"text-opacity":i}}):n.showLength&&!t.showLength&&this.map.getLayer(this.lengthLayerId)&&this.map.removeLayer(this.lengthLayerId)}(n.strokeColor!==t.strokeColor||n.strokeWidth!==t.strokeWidth||n.strokeOpacity!==t.strokeOpacity||n.confidence!==t.confidence||n.dashArray!==t.dashArray)&&this.map.getLayer(this.lineLayerId)&&(this.isSelected||this.map.setPaintProperty(this.lineLayerId,`line-color`,t.strokeColor??e.DEFAULTS.strokeColor),this.map.setPaintProperty(this.lineLayerId,`line-width`,t.strokeWidth??e.DEFAULTS.strokeWidth),this.map.setPaintProperty(this.lineLayerId,`line-opacity`,(t.strokeOpacity??e.DEFAULTS.strokeOpacity)*i),t.dashArray&&this.map.setPaintProperty(this.lineLayerId,`line-dasharray`,t.dashArray)),(n.lineCap!==t.lineCap||n.lineJoin!==t.lineJoin)&&this.map.getLayer(this.lineLayerId)&&(this.map.setLayoutProperty(this.lineLayerId,`line-cap`,t.lineCap??e.DEFAULTS.lineCap),this.map.setLayoutProperty(this.lineLayerId,`line-join`,t.lineJoin??e.DEFAULTS.lineJoin)),n.confidence!==t.confidence&&this.map.getLayer(this.labelLayerId)&&this.map.setPaintProperty(this.labelLayerId,`text-opacity`,i),n.confidence!==t.confidence&&this.map.getLayer(this.lengthLayerId)&&this.map.setPaintProperty(this.lengthLayerId,`text-opacity`,i)}getEditHandleGeoJSON(e){let t=e??this.entity.coordinates;if(!t||t.length<2)return{type:`FeatureCollection`,features:[]};let n=[];for(let e=0;e<t.length;e++)n.push({type:`Feature`,geometry:{type:`Point`,coordinates:t[e]},properties:{handleType:`vertex`,index:e}});for(let e=0;e<t.length-1;e++){let r=t[e],i=t[e+1];n.push({type:`Feature`,geometry:{type:`Point`,coordinates:[(r[0]+i[0])/2,(r[1]+i[1])/2]},properties:{handleType:`midpoint`,index:e}})}let r=0,i=0;for(let e of t)r+=e[0],i+=e[1];return r/=t.length,i/=t.length,n.push({type:`Feature`,geometry:{type:`Point`,coordinates:[r,i]},properties:{handleType:`move`,index:0}}),{type:`FeatureCollection`,features:n}}createEditLayers(){this.map.getSource(this.editSourceId)||(I(this.map),this.map.addSource(this.editSourceId,{type:`geojson`,data:this.getEditHandleGeoJSON()}),this.map.addLayer({id:this.editMidpointLayerId,type:`circle`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`midpoint`],paint:{"circle-radius":4,"circle-color":`#3388ff`,"circle-opacity":.5,"circle-stroke-color":`#3388ff`,"circle-stroke-width":1}}),this.map.addLayer({id:this.editHandleLayerId,type:`circle`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`vertex`],paint:{"circle-radius":6,"circle-color":`#ffffff`,"circle-stroke-color":`#3388ff`,"circle-stroke-width":2}}),this.map.addLayer({id:this.editMoveLayerId,type:`symbol`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`move`],layout:{"icon-image":ae,"icon-allow-overlap":!0,"icon-ignore-placement":!0}}))}removeEditLayers(){this.map.getLayer(this.editMoveLayerId)&&this.map.removeLayer(this.editMoveLayerId),this.map.getLayer(this.editHandleLayerId)&&this.map.removeLayer(this.editHandleLayerId),this.map.getLayer(this.editMidpointLayerId)&&this.map.removeLayer(this.editMidpointLayerId),this.map.getSource(this.editSourceId)&&this.map.removeSource(this.editSourceId)}refreshEditHandles(e){let t=this.map.getSource(this.editSourceId);t&&t.setData(this.getEditHandleGeoJSON(e))}setEditing(e){this.isEditing!==e&&(this.isEditing=e,this.initialized&&(e?this.createEditLayers():this.removeEditLayers()))}getEditHandleAt(e,t){if(!this.isEditing)return null;let n=this.entity.coordinates;if(!n||n.length<2)return null;let r=this.map.project(e),i=0,a=0;for(let e of n)i+=e[0],a+=e[1];i/=n.length,a/=n.length;let o=this.map.project([i,a]),s=r.x-o.x,c=r.y-o.y;if(s*s+c*c<=144)return{type:`move`,index:0,position:[i,a]};for(let e=0;e<n.length;e++){let t=this.map.project(n[e]),i=r.x-t.x,a=r.y-t.y;if(i*i+a*a<=100)return{type:`vertex`,index:e,position:n[e]}}for(let e=0;e<n.length-1;e++){let t=n[e],i=n[e+1],a=[(t[0]+i[0])/2,(t[1]+i[1])/2],o=this.map.project(a),s=r.x-o.x,c=r.y-o.y;if(s*s+c*c<=100)return{type:`midpoint`,index:e,position:a}}return null}offsetCoordinates(e,t,n){let r=n[0]-t[0],i=n[1]-t[1];return e.map(e=>[e[0]+r,e[1]+i])}applyHandleMove(e,t){let n;e.type===`move`?n=this.offsetCoordinates(this.entity.coordinates,e.position,t):(n=[...this.entity.coordinates],n[e.index]=t);let r={...this.entity,coordinates:n};this.entity=r;let i=this.map.getSource(this.sourceId);return i&&i.setData(this.getGeoJSON()),this.refreshEditHandles(),r}updateEditPreview(e,t){let n;e.type===`move`?n=this.offsetCoordinates(this.entity.coordinates,e.position,t):(n=[...this.entity.coordinates],n[e.index]=t);let r=this.entity;this.entity={...this.entity,coordinates:n};let i=this.map.getSource(this.sourceId);i&&i.setData(this.getGeoJSON()),this.entity=r,this.refreshEditHandles(n)}cancelEditPreview(){let e=this.map.getSource(this.sourceId);e&&e.setData(this.getGeoJSON()),this.refreshEditHandles()}deleteVertex(e){let t=this.entity.coordinates;if(!t||t.length<=2)return null;let n=t.filter((t,n)=>n!==e),r={...this.entity,coordinates:n};this.entity=r;let i=this.map.getSource(this.sourceId);return i&&i.setData(this.getGeoJSON()),this.refreshEditHandles(),r}addVertex(e,t){let n=[...this.entity.coordinates];n.splice(e+1,0,t);let r={...this.entity,coordinates:n};this.entity=r;let i=this.map.getSource(this.sourceId);return i&&i.setData(this.getGeoJSON()),this.refreshEditHandles(),r}destroy(){this.initialized&&=(this.removeEditLayers(),this.map.getLayer(this.lengthLayerId)&&this.map.removeLayer(this.lengthLayerId),this.map.getLayer(this.labelLayerId)&&this.map.removeLayer(this.labelLayerId),this.map.getLayer(this.lineLayerId)&&this.map.removeLayer(this.lineLayerId),this.map.getSource(this.sourceId)&&this.map.removeSource(this.sourceId),!1)}};function me(e,t,n=64){let[r,i]=e,a=[],o=t/6371e3,s=i*Math.PI/180;for(let e=0;e<=n;e++){let t=e/n*2*Math.PI,c=o*Math.cos(t),l=o*Math.sin(t)/Math.cos(s),u=i+c*180/Math.PI,d=r+l*180/Math.PI;a.push([d,u])}return a}var he=class e{static{this.GRADIENT_STEPS=10}static{this.DEFAULTS={strokeColor:`#3388ff`,strokeWidth:2,strokeOpacity:1,fillColor:`#3388ff`,fillOpacity:.2,fillType:`solid`,showCenterPoint:!0,centerPointRadius:4}}constructor(e,t,n,r,i,a){this.isSelected=!1,this.initialized=!1,this.gradientLayerIds=[],this.gradientSourceIds=[],this.isEditing=!1,this.map=e,this.entity=t,this.globalNameConfig=n,this.globalSelectNameConfig=r,this.globalAreaConfig=i,this.globalCircleConfig=a,this.sourceId=`circle-source-${t.id}`,this.fillLayerId=`circle-fill-${t.id}`,this.strokeLayerId=`circle-stroke-${t.id}`,this.centerPointLayerId=`circle-center-${t.id}`,this.labelLayerId=`circle-label-${t.id}`,this.areaLayerId=`circle-area-${t.id}`,this.radiusLineLayerId=`circle-radius-line-${t.id}`,this.radiusLabelLayerId=`circle-radius-label-${t.id}`,this.editSourceId=`circle-edit-source-${t.id}`,this.editHandleLayerId=`circle-edit-handles-${t.id}`,this.editMoveLayerId=`circle-edit-move-${t.id}`,this.initLayers()}get nameStyle(){return x(this.entity.nameConfig,this.globalNameConfig,h)}get selectNameStyle(){return x(this.entity.selectNameConfig,this.globalSelectNameConfig,g)}get areaStyle(){return x(this.entity.areaConfig,this.globalAreaConfig,_)}get radiusTextStyle(){return x(this.entity.circleConfig,this.globalCircleConfig,h)}get radiusLineStyle(){return y(this.entity.circleConfig?.radiusLine,this.globalCircleConfig?.radiusLine,v)}initLayers(){if(!this.initialized)try{let t=this.getGeoJSON();this.map.addSource(this.sourceId,{type:`geojson`,data:t});let n=this.entity.confidence??1,r=P(n);if((this.entity.fillType??e.DEFAULTS.fillType)===`radial-gradient`?this.initGradientLayers(r):this.map.addLayer({id:this.fillLayerId,type:`fill`,source:this.sourceId,filter:[`==`,[`get`,`type`],`circle`],paint:{"fill-color":this.entity.fillColor??e.DEFAULTS.fillColor,"fill-opacity":(this.entity.fillOpacity??e.DEFAULTS.fillOpacity)*r}}),this.map.addLayer({id:this.strokeLayerId,type:`line`,source:this.sourceId,filter:[`==`,[`get`,`type`],`circle`],layout:{"line-join":`round`,"line-cap":`round`},paint:{"line-color":this.isSelected?`#ffcc00`:this.entity.strokeColor??e.DEFAULTS.strokeColor,"line-width":this.entity.strokeWidth??e.DEFAULTS.strokeWidth,"line-opacity":(this.entity.strokeOpacity??e.DEFAULTS.strokeOpacity)*r}}),(this.entity.showCenterPoint??e.DEFAULTS.showCenterPoint)&&this.map.addLayer({id:this.centerPointLayerId,type:`circle`,source:this.sourceId,filter:[`==`,[`get`,`type`],`center`],paint:{"circle-radius":this.entity.centerPointRadius??e.DEFAULTS.centerPointRadius,"circle-color":this.entity.centerPointColor??this.entity.fillColor??e.DEFAULTS.fillColor,"circle-opacity":r,"circle-stroke-width":1,"circle-stroke-color":`#ffffff`,"circle-stroke-opacity":r*.8}}),this.entity.name&&this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`type`],`center`],layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.8],"text-allow-overlap":!0},paint:{"text-color":this.isSelected?this.selectNameStyle.fillColor:this.nameStyle.fillColor,"text-halo-color":this.isSelected?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor,"text-halo-width":this.isSelected?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth,"text-opacity":r}}),this.entity.showArea&&this.map.addLayer({id:this.areaLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`type`],`center`],layout:{"text-field":[`get`,`area`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`bottom`,"text-offset":[0,-.8],"text-allow-overlap":!0},paint:{"text-color":this.areaStyle.fillColor,"text-halo-color":this.areaStyle.strokeColor,"text-halo-width":this.areaStyle.strokeWidth,"text-opacity":r}}),this.entity.showRadius){let e=this.radiusLineStyle;this.map.addLayer({id:this.radiusLineLayerId,type:`line`,source:this.sourceId,filter:[`==`,[`get`,`type`],`radius-line`],layout:{"line-cap":`round`},paint:{"line-color":e.color,"line-width":e.width,"line-opacity":e.opacity*r,"line-dasharray":e.dashArray}}),this.map.addLayer({id:this.radiusLabelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`type`],`radius-label`],layout:{"text-field":[`get`,`radius`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-offset":[0,-.8],"text-allow-overlap":!0},paint:{"text-color":this.radiusTextStyle.fillColor,"text-halo-color":this.radiusTextStyle.strokeColor,"text-halo-width":this.radiusTextStyle.strokeWidth,"text-opacity":r}})}this.initialized=!0}catch{this.map.once(`idle`,()=>this.initLayers())}}initGradientLayers(t){let{center:n,radius:r}=this.entity,i=this.entity.fillColor??e.DEFAULTS.fillColor,a=this.entity.fillOpacity??e.DEFAULTS.fillOpacity,o=this.parseColor(i);for(let i=0;i<e.GRADIENT_STEPS;i++){let s=1-i/e.GRADIENT_STEPS,c=r*s,l=i/(e.GRADIENT_STEPS-1)*a*t,u=`${this.sourceId}-gradient-${i}`,d=`${this.fillLayerId}-gradient-${i}`,f=me(n,c);this.map.addSource(u,{type:`geojson`,data:{type:`Feature`,geometry:{type:`Polygon`,coordinates:[f]},properties:{}}}),this.map.addLayer({id:d,type:`fill`,source:u,paint:{"fill-color":`rgb(${o.r}, ${o.g}, ${o.b})`,"fill-opacity":l}}),this.gradientSourceIds.push(u),this.gradientLayerIds.push(d)}}parseColor(e){if(e.startsWith(`#`)){let t=e.slice(1);return{r:parseInt(t.slice(0,2),16),g:parseInt(t.slice(2,4),16),b:parseInt(t.slice(4,6),16)}}let t=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);return t?{r:parseInt(t[1],10),g:parseInt(t[2],10),b:parseInt(t[3],10)}:{r:51,g:136,b:255}}getGeoJSON(){let{center:e,radius:t}=this.entity,n=[{type:`Feature`,geometry:{type:`Polygon`,coordinates:[me(e,t)]},properties:{type:`circle`}},{type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:{type:`center`,name:this.entity.name||``,area:this.entity.showArea?A(this.getArea()):``}}];if(this.entity.showRadius){let r=this.entity.radiusAngle??90,i=D(e,t,r),a=[(e[0]+i[0])/2,(e[1]+i[1])/2];n.push({type:`Feature`,geometry:{type:`LineString`,coordinates:[e,i]},properties:{type:`radius-line`}},{type:`Feature`,geometry:{type:`Point`,coordinates:a},properties:{type:`radius-label`,radius:j(t)}})}return{type:`FeatureCollection`,features:n}}getArea(){return Math.PI*this.entity.radius*this.entity.radius}getEntityId(){return this.entity.id}getCenter(){return this.entity.center}getBounds(){let{center:e,radius:t}=this.entity,[n,r]=e,i=t/6371e3,a=r*Math.PI/180,o=i*180/Math.PI,s=i*180/Math.PI/Math.cos(a);return[[n-s,r-o],[n+s,r+o]]}getLayerId(){return this.gradientLayerIds.length>0?this.gradientLayerIds[this.gradientLayerIds.length-1]:this.fillLayerId}getLabelLayerId(){return this.entity.name?this.labelLayerId:null}setSelected(t){this.isSelected!==t&&(this.isSelected=t,this.initialized&&(this.map.getLayer(this.strokeLayerId)&&this.map.setPaintProperty(this.strokeLayerId,`line-color`,t?`#ffcc00`:this.entity.strokeColor??e.DEFAULTS.strokeColor),this.map.getLayer(this.labelLayerId)&&(this.map.setPaintProperty(this.labelLayerId,`text-color`,t?this.selectNameStyle.fillColor:this.nameStyle.fillColor),this.map.setPaintProperty(this.labelLayerId,`text-halo-color`,t?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor),this.map.setPaintProperty(this.labelLayerId,`text-halo-width`,t?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth))))}isPointInEntity(e){let{center:t,radius:n}=this.entity;return this.calculateDistance(e,t)<=n}calculateDistance(e,t){let[n,r]=e,[i,a]=t,o=(a-r)*Math.PI/180,s=(i-n)*Math.PI/180,c=Math.sin(o/2)*Math.sin(o/2)+Math.cos(r*Math.PI/180)*Math.cos(a*Math.PI/180)*Math.sin(s/2)*Math.sin(s/2);return 6371e3*(2*Math.atan2(Math.sqrt(c),Math.sqrt(1-c)))}update(t){let n=this.entity;if(this.entity=t,!this.initialized)return;let r=t.confidence??1,i=P(r),a=t.fillType??e.DEFAULTS.fillType,o=n.fillType??e.DEFAULTS.fillType;if(a!==o){this.destroy(),this.initialized=!1,this.gradientLayerIds=[],this.gradientSourceIds=[],this.initLayers();return}if(n.center!==t.center||n.radius!==t.radius||n.name!==t.name||n.showArea!==t.showArea||n.showRadius!==t.showRadius||n.radiusAngle!==t.radiusAngle){let e=this.map.getSource(this.sourceId);if(e&&e.setData(this.getGeoJSON()),a===`radial-gradient`&&this.updateGradientLayers(i),!n.name&&t.name&&!this.map.getLayer(this.labelLayerId)?this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`type`],`center`],layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.8],"text-allow-overlap":!0},paint:{"text-color":this.isSelected?this.selectNameStyle.fillColor:this.nameStyle.fillColor,"text-halo-color":this.isSelected?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor,"text-halo-width":this.isSelected?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth,"text-opacity":i}}):n.name&&!t.name&&this.map.getLayer(this.labelLayerId)&&this.map.removeLayer(this.labelLayerId),!n.showArea&&t.showArea&&!this.map.getLayer(this.areaLayerId)?this.map.addLayer({id:this.areaLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`type`],`center`],layout:{"text-field":[`get`,`area`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`bottom`,"text-offset":[0,-.8],"text-allow-overlap":!0},paint:{"text-color":this.areaStyle.fillColor,"text-halo-color":this.areaStyle.strokeColor,"text-halo-width":this.areaStyle.strokeWidth,"text-opacity":i}}):n.showArea&&!t.showArea&&this.map.getLayer(this.areaLayerId)&&this.map.removeLayer(this.areaLayerId),!n.showRadius&&t.showRadius){let e=this.radiusLineStyle;this.map.getLayer(this.radiusLineLayerId)||this.map.addLayer({id:this.radiusLineLayerId,type:`line`,source:this.sourceId,filter:[`==`,[`get`,`type`],`radius-line`],layout:{"line-cap":`round`},paint:{"line-color":e.color,"line-width":e.width,"line-opacity":e.opacity*i,"line-dasharray":e.dashArray}}),this.map.getLayer(this.radiusLabelLayerId)||this.map.addLayer({id:this.radiusLabelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`type`],`radius-label`],layout:{"text-field":[`get`,`radius`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-offset":[0,-.8],"text-allow-overlap":!0,"text-rotate":[`get`,`textRotation`],"text-rotation-alignment":`map`},paint:{"text-color":this.radiusTextStyle.fillColor,"text-halo-color":this.radiusTextStyle.strokeColor,"text-halo-width":this.radiusTextStyle.strokeWidth,"text-opacity":i}})}else n.showRadius&&!t.showRadius&&(this.map.getLayer(this.radiusLabelLayerId)&&this.map.removeLayer(this.radiusLabelLayerId),this.map.getLayer(this.radiusLineLayerId)&&this.map.removeLayer(this.radiusLineLayerId))}if(a===`solid`?(n.fillColor!==t.fillColor||n.fillOpacity!==t.fillOpacity||n.confidence!==t.confidence)&&this.map.getLayer(this.fillLayerId)&&(this.map.setPaintProperty(this.fillLayerId,`fill-color`,t.fillColor??e.DEFAULTS.fillColor),this.map.setPaintProperty(this.fillLayerId,`fill-opacity`,(t.fillOpacity??e.DEFAULTS.fillOpacity)*i)):(n.fillColor!==t.fillColor||n.fillOpacity!==t.fillOpacity||n.confidence!==t.confidence)&&this.updateGradientLayerStyles(i),(n.strokeColor!==t.strokeColor||n.strokeWidth!==t.strokeWidth||n.strokeOpacity!==t.strokeOpacity||n.confidence!==t.confidence)&&this.map.getLayer(this.strokeLayerId)&&(this.isSelected||this.map.setPaintProperty(this.strokeLayerId,`line-color`,t.strokeColor??e.DEFAULTS.strokeColor),this.map.setPaintProperty(this.strokeLayerId,`line-width`,t.strokeWidth??e.DEFAULTS.strokeWidth),this.map.setPaintProperty(this.strokeLayerId,`line-opacity`,(t.strokeOpacity??e.DEFAULTS.strokeOpacity)*i)),(n.centerPointColor!==t.centerPointColor||n.centerPointRadius!==t.centerPointRadius||n.fillColor!==t.fillColor||n.confidence!==t.confidence)&&this.map.getLayer(this.centerPointLayerId)&&(this.map.setPaintProperty(this.centerPointLayerId,`circle-color`,t.centerPointColor??t.fillColor??e.DEFAULTS.fillColor),this.map.setPaintProperty(this.centerPointLayerId,`circle-radius`,t.centerPointRadius??e.DEFAULTS.centerPointRadius),this.map.setPaintProperty(this.centerPointLayerId,`circle-opacity`,i)),n.confidence!==t.confidence){if(this.map.getLayer(this.labelLayerId)&&this.map.setPaintProperty(this.labelLayerId,`text-opacity`,i),this.map.getLayer(this.areaLayerId)&&this.map.setPaintProperty(this.areaLayerId,`text-opacity`,i),this.map.getLayer(this.radiusLineLayerId)){let e=this.radiusLineStyle;this.map.setPaintProperty(this.radiusLineLayerId,`line-opacity`,e.opacity*i)}this.map.getLayer(this.radiusLabelLayerId)&&this.map.setPaintProperty(this.radiusLabelLayerId,`text-opacity`,i)}}updateGradientLayers(t){let{center:n,radius:r}=this.entity;for(let t=0;t<this.gradientSourceIds.length;t++){let i=1-t/e.GRADIENT_STEPS,a=r*i,o=me(n,a),s=this.map.getSource(this.gradientSourceIds[t]);s&&s.setData({type:`Feature`,geometry:{type:`Polygon`,coordinates:[o]},properties:{}})}this.updateGradientLayerStyles(t)}updateGradientLayerStyles(t){let n=this.entity.fillColor??e.DEFAULTS.fillColor,r=this.entity.fillOpacity??e.DEFAULTS.fillOpacity,i=this.parseColor(n);for(let n=0;n<this.gradientLayerIds.length;n++){let a=n/(e.GRADIENT_STEPS-1)*r*t;this.map.getLayer(this.gradientLayerIds[n])&&(this.map.setPaintProperty(this.gradientLayerIds[n],`fill-color`,`rgb(${i.r}, ${i.g}, ${i.b})`),this.map.setPaintProperty(this.gradientLayerIds[n],`fill-opacity`,a))}}static{this.EDGE_BEARINGS=[0,90,180,270]}getEditHandlePositions(t,n){let r=t??this.entity.center,i=n??this.entity.radius,a=[];for(let t=0;t<e.EDGE_BEARINGS.length;t++)a.push({type:`edge`,index:t,position:D(r,i,e.EDGE_BEARINGS[t])});return a.push({type:`move`,index:0,position:r}),a}getEditHandleGeoJSON(e,t){return{type:`FeatureCollection`,features:this.getEditHandlePositions(e,t).map(e=>({type:`Feature`,geometry:{type:`Point`,coordinates:e.position},properties:{handleType:e.type,index:e.index}}))}}createEditLayers(){this.map.getSource(this.editSourceId)||(I(this.map),this.map.addSource(this.editSourceId,{type:`geojson`,data:this.getEditHandleGeoJSON()}),this.map.addLayer({id:this.editHandleLayerId,type:`circle`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`edge`],paint:{"circle-radius":6,"circle-color":`#ffffff`,"circle-stroke-color":`#3388ff`,"circle-stroke-width":2}}),this.map.addLayer({id:this.editMoveLayerId,type:`symbol`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`move`],layout:{"icon-image":ae,"icon-allow-overlap":!0,"icon-ignore-placement":!0}}))}removeEditLayers(){this.map.getLayer(this.editMoveLayerId)&&this.map.removeLayer(this.editMoveLayerId),this.map.getLayer(this.editHandleLayerId)&&this.map.removeLayer(this.editHandleLayerId),this.map.getSource(this.editSourceId)&&this.map.removeSource(this.editSourceId)}refreshEditHandles(e,t){let n=this.map.getSource(this.editSourceId);n&&n.setData(this.getEditHandleGeoJSON(e,t))}setEditing(e){this.isEditing!==e&&(this.isEditing=e,this.initialized&&(e?this.createEditLayers():this.removeEditLayers()))}getEditHandleAt(e,t){if(!this.isEditing)return null;let n=this.map.project(e),r=this.getEditHandlePositions(),i=r.find(e=>e.type===`move`);if(i){let e=this.map.project(i.position),t=n.x-e.x,r=n.y-e.y;if(t*t+r*r<=144)return{type:`move`,index:i.index,position:i.position}}for(let e of r){if(e.type===`move`)continue;let t=this.map.project(e.position),r=n.x-t.x,i=n.y-t.y;if(r*r+i*i<=100)return{type:e.type,index:e.index,position:e.position}}return null}applyHandleMove(e,t){let n;if(e.type===`move`)n={...this.entity,center:t};else{let e=this.calculateDistance(this.entity.center,t);n={...this.entity,radius:e}}this.entity=n;let r=this.map.getSource(this.sourceId);return r&&r.setData(this.getGeoJSON()),this.refreshEditHandles(),n}updateEditPreview(e,t){let n,r;e.type===`move`?(n=t,r=this.entity.radius):(n=this.entity.center,r=this.calculateDistance(this.entity.center,t));let i=this.entity;this.entity={...this.entity,center:n,radius:r};let a=this.map.getSource(this.sourceId);a&&a.setData(this.getGeoJSON()),this.entity=i,this.refreshEditHandles(n,r)}cancelEditPreview(){let e=this.map.getSource(this.sourceId);e&&e.setData(this.getGeoJSON()),this.refreshEditHandles()}destroy(){if(this.initialized){this.removeEditLayers(),this.map.getLayer(this.radiusLabelLayerId)&&this.map.removeLayer(this.radiusLabelLayerId),this.map.getLayer(this.radiusLineLayerId)&&this.map.removeLayer(this.radiusLineLayerId),this.map.getLayer(this.areaLayerId)&&this.map.removeLayer(this.areaLayerId),this.map.getLayer(this.labelLayerId)&&this.map.removeLayer(this.labelLayerId),this.map.getLayer(this.centerPointLayerId)&&this.map.removeLayer(this.centerPointLayerId),this.map.getLayer(this.strokeLayerId)&&this.map.removeLayer(this.strokeLayerId),this.map.getLayer(this.fillLayerId)&&this.map.removeLayer(this.fillLayerId);for(let e of this.gradientLayerIds)this.map.getLayer(e)&&this.map.removeLayer(e);for(let e of this.gradientSourceIds)this.map.getSource(e)&&this.map.removeSource(e);this.map.getSource(this.sourceId)&&this.map.removeSource(this.sourceId),this.initialized=!1}}};const L={gradientAnimation:`flicker`,animationSpeed:1,fillColor:`#3388ff`,fillOpacity:.6,strokeColor:`#3388ff`,strokeWidth:2,strokeOpacity:1,showCenterPoint:!0,centerPointRadius:4};function ge(e,t){let n=D(e,t,0),r=D(e,t,90),i=D(e,t,180),a=D(e,t,270)[0],o=r[0],s=i[1],c=n[1];return[[a,c],[o,c],[o,s],[a,s]]}var _e=class e extends re{static{this.EDGE_BEARINGS=[0,90,180,270]}constructor(e,t,n,r,i,a){super(e,t,`canvas-circle`,n,r,i),this.animationFrameId=null,this.animationTime=0,this.pulsePhase=0,this.isEditing=!1,this.editSourceId=``,this.editHandleLayerId=``,this.editMoveLayerId=``,this.globalCircleConfig=a,this.radiusSourceId=`canvas-circle-radius-source-${String(t.id)}`,this.radiusLineLayerId=`canvas-circle-radius-line-${String(t.id)}`,this.radiusLabelLayerId=`canvas-circle-radius-label-${String(t.id)}`,this.editSourceId=`canvas-circle-edit-source-${String(t.id)}`,this.editHandleLayerId=`canvas-circle-edit-handles-${String(t.id)}`,this.editMoveLayerId=`canvas-circle-edit-move-${String(t.id)}`;let o=ge(t.center,t.radius);this.init(o),this.initRadiusLayer(),t.isAnimating&&this.startAnimation()}getArea(){return Math.PI*this.entity.radius*this.entity.radius}getAreaLabelAnchor(){return{anchor:`bottom`,offset:[0,-.8]}}get radiusTextStyle(){return x(this.entity.circleConfig,this.globalCircleConfig,h)}get radiusLineStyleResolved(){return y(this.entity.circleConfig?.radiusLine,this.globalCircleConfig?.radiusLine,v)}initRadiusLayer(){if(!this.entity.showRadius)return;let{center:e,radius:t}=this.entity,n=this.entity.radiusAngle??90,r=D(e,t,n),i=[(e[0]+r[0])/2,(e[1]+r[1])/2],a=P(this.entity.confidence),o=this.radiusLineStyleResolved;this.map.addSource(this.radiusSourceId,{type:`geojson`,data:{type:`FeatureCollection`,features:[{type:`Feature`,geometry:{type:`LineString`,coordinates:[e,r]},properties:{featureType:`line`}},{type:`Feature`,geometry:{type:`Point`,coordinates:i},properties:{featureType:`label`,radius:j(t)}}]}}),this.map.addLayer({id:this.radiusLineLayerId,type:`line`,source:this.radiusSourceId,filter:[`==`,[`get`,`featureType`],`line`],layout:{"line-cap":`round`},paint:{"line-color":o.color,"line-width":o.width,"line-opacity":o.opacity*a,"line-dasharray":o.dashArray}}),this.map.addLayer({id:this.radiusLabelLayerId,type:`symbol`,source:this.radiusSourceId,filter:[`==`,[`get`,`featureType`],`label`],layout:{"text-field":[`get`,`radius`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-offset":[0,-.8],"text-allow-overlap":!0},paint:{"text-color":this.radiusTextStyle.fillColor,"text-halo-color":this.radiusTextStyle.strokeColor,"text-halo-width":this.radiusTextStyle.strokeWidth,"text-opacity":a}})}updateRadiusLayer(){if(this.entity.showRadius){let e=this.map.getSource(this.radiusSourceId);if(e){let{center:t,radius:n}=this.entity,r=this.entity.radiusAngle??90,i=D(t,n,r),a=[(t[0]+i[0])/2,(t[1]+i[1])/2];e.setData({type:`FeatureCollection`,features:[{type:`Feature`,geometry:{type:`LineString`,coordinates:[t,i]},properties:{featureType:`line`}},{type:`Feature`,geometry:{type:`Point`,coordinates:a},properties:{featureType:`label`,radius:j(n)}}]})}else this.initRadiusLayer()}else this.map.getLayer(this.radiusLabelLayerId)&&this.map.removeLayer(this.radiusLabelLayerId),this.map.getLayer(this.radiusLineLayerId)&&this.map.removeLayer(this.radiusLineLayerId),this.map.getSource(this.radiusSourceId)&&this.map.removeSource(this.radiusSourceId)}getEntityCenter(){return this.entity.center}getEntityBounds(){let e=ge(this.entity.center,this.entity.radius),t=e[3][0],n=e[3][1],r=e[1][0],i=e[1][1];return[[t,n],[r,i]]}draw(){let e=this.ctx,t=this.entity;switch(e.clearRect(0,0,512,512),e.globalAlpha=P(t.confidence),t.gradientAnimation??L.gradientAnimation){case`static`:this.drawStaticGradient(e);break;case`flicker`:this.drawFlickerGradient(e);break;case`breath`:this.drawBreathGradient(e);break;case`pulse`:this.drawPulseGradient(e);break;default:this.drawStaticGradient(e)}this.drawStroke(e),(t.showCenterPoint??L.showCenterPoint)&&this.drawCenterPoint(e),e.globalAlpha=1}drawStaticGradient(e){let t=this.entity.fillColor??L.fillColor,n=this.entity.fillOpacity??L.fillOpacity,r=e.createRadialGradient(256,256,0,256,256,254),i=this.parseColor(t);r.addColorStop(0,`rgba(${i.r}, ${i.g}, ${i.b}, ${n})`),r.addColorStop(.7,`rgba(${i.r}, ${i.g}, ${i.b}, ${n*.5})`),r.addColorStop(1,`rgba(${i.r}, ${i.g}, ${i.b}, 0)`),e.beginPath(),e.arc(256,256,254,0,Math.PI*2),e.fillStyle=r,e.fill()}drawFlickerGradient(e){let t=this.entity.fillColor??L.fillColor,n=this.entity.fillOpacity??L.fillOpacity,r=this.entity.animationSpeed??L.animationSpeed,i=.5+.5*Math.sin(this.animationTime*r*8),a=n*(.3+.7*i),o=e.createRadialGradient(256,256,0,256,256,254),s=this.parseColor(t);o.addColorStop(0,`rgba(${s.r}, ${s.g}, ${s.b}, ${a})`),o.addColorStop(.7,`rgba(${s.r}, ${s.g}, ${s.b}, ${a*.5})`),o.addColorStop(1,`rgba(${s.r}, ${s.g}, ${s.b}, 0)`),e.beginPath(),e.arc(256,256,254,0,Math.PI*2),e.fillStyle=o,e.fill()}drawBreathGradient(e){let t=this.entity.fillColor??L.fillColor,n=this.entity.fillOpacity??L.fillOpacity,r=this.entity.animationSpeed??L.animationSpeed,i=.5+.5*Math.sin(this.animationTime*r*2),a=n*(.2+.8*i),o=e.createRadialGradient(256,256,0,256,256,254),s=this.parseColor(t);o.addColorStop(0,`rgba(${s.r}, ${s.g}, ${s.b}, ${a})`),o.addColorStop(.7,`rgba(${s.r}, ${s.g}, ${s.b}, ${a*.5})`),o.addColorStop(1,`rgba(${s.r}, ${s.g}, ${s.b}, 0)`),e.beginPath(),e.arc(256,256,254,0,Math.PI*2),e.fillStyle=o,e.fill()}drawPulseGradient(e){let t=this.entity.fillColor??L.fillColor,n=this.entity.fillOpacity??L.fillOpacity,r=this.parseColor(t),i=e.createRadialGradient(256,256,0,256,256,254);i.addColorStop(0,`rgba(${r.r}, ${r.g}, ${r.b}, ${n*.3})`),i.addColorStop(1,`rgba(${r.r}, ${r.g}, ${r.b}, 0)`),e.beginPath(),e.arc(256,256,254,0,Math.PI*2),e.fillStyle=i,e.fill();for(let t=0;t<3;t++){let i=(this.pulsePhase+t/3)%1,a=254*i,o=n*(1-i)*.6;a>0&&o>0&&(e.beginPath(),e.arc(256,256,a,0,Math.PI*2),e.strokeStyle=`rgba(${r.r}, ${r.g}, ${r.b}, ${o})`,e.lineWidth=3,e.stroke())}}drawStroke(e){let t=this.entity.strokeColor??L.strokeColor,n=this.entity.strokeWidth??L.strokeWidth,r=this.entity.strokeOpacity??L.strokeOpacity;n>0&&r>0&&(e.beginPath(),e.arc(256,256,254-n/2,0,Math.PI*2),e.strokeStyle=this.colorWithAlpha(t,r),e.lineWidth=n,e.stroke())}drawCenterPoint(e){let t=this.entity.centerPointColor??this.entity.fillColor??L.fillColor,n=(this.entity.centerPointRadius??L.centerPointRadius)*2;e.beginPath(),e.arc(256,256,n,0,Math.PI*2),e.fillStyle=t,e.fill(),e.strokeStyle=`white`,e.lineWidth=2,e.stroke()}parseColor(e){if(e.startsWith(`#`)){let t=e.slice(1);return{r:parseInt(t.slice(0,2),16),g:parseInt(t.slice(2,4),16),b:parseInt(t.slice(4,6),16)}}let t=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);return t?{r:parseInt(t[1],10),g:parseInt(t[2],10),b:parseInt(t[3],10)}:{r:51,g:136,b:255}}startAnimation(){if(this.animationFrameId!==null||this.isDestroyed)return;let e=this.entity.animationSpeed??L.animationSpeed,t=performance.now(),n=r=>{if(this.isDestroyed)return;let i=(r-t)/1e3;t=r,this.animationTime+=i,this.pulsePhase+=i*e*.5,this.pulsePhase>=1&&--this.pulsePhase,this.draw(),this.animationFrameId=requestAnimationFrame(n)};this.animationFrameId=requestAnimationFrame(n),this.map.getSource(this.sourceId)?.play()}stopAnimation(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.map.getSource(this.sourceId)?.pause()}update(e){let t=this.entity;if(this.entity=e,t.center[0]!==e.center[0]||t.center[1]!==e.center[1]||t.radius!==e.radius){let t=ge(e.center,e.radius);this.updateSourceCoordinates(t)}(t.center[0]!==e.center[0]||t.center[1]!==e.center[1]||t.name!==e.name||t.radius!==e.radius||t.confidence!==e.confidence)&&this.updateLabel(),(t.showArea!==e.showArea||t.radius!==e.radius||t.confidence!==e.confidence)&&this.updateAreaLabel(),(t.showRadius!==e.showRadius||t.radius!==e.radius||t.radiusAngle!==e.radiusAngle||t.center[0]!==e.center[0]||t.center[1]!==e.center[1]||t.confidence!==e.confidence)&&this.updateRadiusLayer(),t.isAnimating!==e.isAnimating&&(e.isAnimating?this.startAnimation():this.stopAnimation()),e.isAnimating||this.draw()}isPointInEntity(e){let{center:t,radius:n}=this.entity,r=e[0]-t[0],i=e[1]-t[1],a=111320*Math.cos(t[1]*Math.PI/180);return Math.sqrt((r*a)**2+(i*110540)**2)<=n}destroy(){this.removeEditLayers(),this.stopAnimation(),this.map.getLayer(this.radiusLabelLayerId)&&this.map.removeLayer(this.radiusLabelLayerId),this.map.getLayer(this.radiusLineLayerId)&&this.map.removeLayer(this.radiusLineLayerId),this.map.getSource(this.radiusSourceId)&&this.map.removeSource(this.radiusSourceId),super.destroy()}getEditHandlePositions(t,n){let r=t??this.entity.center,i=n??this.entity.radius,a=[];for(let t=0;t<e.EDGE_BEARINGS.length;t++)a.push({type:`edge`,index:t,position:D(r,i,e.EDGE_BEARINGS[t])});return a.push({type:`move`,index:0,position:r}),a}getEditHandleGeoJSON(e,t){return{type:`FeatureCollection`,features:this.getEditHandlePositions(e,t).map(e=>({type:`Feature`,geometry:{type:`Point`,coordinates:e.position},properties:{handleType:e.type,index:e.index}}))}}createEditLayers(){this.map.getSource(this.editSourceId)||(I(this.map),this.map.addSource(this.editSourceId,{type:`geojson`,data:this.getEditHandleGeoJSON()}),this.map.addLayer({id:this.editHandleLayerId,type:`circle`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`edge`],paint:{"circle-radius":6,"circle-color":`#ffffff`,"circle-stroke-color":`#3388ff`,"circle-stroke-width":2}}),this.map.addLayer({id:this.editMoveLayerId,type:`symbol`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`move`],layout:{"icon-image":ae,"icon-allow-overlap":!0,"icon-ignore-placement":!0}}))}removeEditLayers(){this.map.getLayer(this.editMoveLayerId)&&this.map.removeLayer(this.editMoveLayerId),this.map.getLayer(this.editHandleLayerId)&&this.map.removeLayer(this.editHandleLayerId),this.map.getSource(this.editSourceId)&&this.map.removeSource(this.editSourceId)}refreshEditHandles(e,t){let n=this.map.getSource(this.editSourceId);n&&n.setData(this.getEditHandleGeoJSON(e,t))}setEditing(e){this.isEditing!==e&&(this.isEditing=e,e?this.createEditLayers():this.removeEditLayers())}getEditHandleAt(e,t){if(!this.isEditing)return null;let n=this.map.project(e),r=this.getEditHandlePositions(),i=r.find(e=>e.type===`move`);if(i){let e=this.map.project(i.position),t=n.x-e.x,r=n.y-e.y;if(t*t+r*r<=144)return{type:`move`,index:i.index,position:i.position}}for(let e of r){if(e.type===`move`)continue;let t=this.map.project(e.position),r=n.x-t.x,i=n.y-t.y;if(r*r+i*i<=100)return{type:e.type,index:e.index,position:e.position}}return null}applyHandleMove(e,t){let n;if(e.type===`move`){let r=t[0]-e.position[0],i=t[1]-e.position[1],a=[this.entity.center[0]+r,this.entity.center[1]+i];n={...this.entity,center:a}}else{let e=O(this.entity.center,t);n={...this.entity,radius:e}}this.entity=n;let r=ge(n.center,n.radius);return this.updateSourceCoordinates(r),this.updateLabel(),this.updateAreaLabel(),this.updateRadiusLayer(),this.refreshEditHandles(),n}updateEditPreview(e,t){let n,r;if(e.type===`move`){let i=t[0]-e.position[0],a=t[1]-e.position[1];n=[this.entity.center[0]+i,this.entity.center[1]+a],r=this.entity.radius}else n=this.entity.center,r=O(this.entity.center,t);let i=ge(n,r);this.updateSourceCoordinates(i);let a=this.entity;this.entity={...this.entity,center:n,radius:r},this.updateLabel(),this.entity=a,this.refreshEditHandles(n,r)}cancelEditPreview(){let e=ge(this.entity.center,this.entity.radius);this.updateSourceCoordinates(e),this.updateLabel(),this.refreshEditHandles()}};function ve(e,t){let[n,r]=e,i=t/2/6371e3,a=r*Math.PI/180,o=i*180/Math.PI,s=i*180/Math.PI/Math.cos(a);return[[n-s,r+o],[n+s,r+o],[n+s,r-o],[n-s,r-o],[n-s,r+o]]}var ye=class e{static{this.DEFAULTS={strokeColor:`#3388ff`,strokeWidth:2,strokeOpacity:1,fillColor:`#3388ff`,fillOpacity:.2}}constructor(e,t,n,r,i,a){this.isSelected=!1,this.initialized=!1,this.isEditing=!1,this.map=e,this.entity=t,this.globalNameConfig=n,this.globalSelectNameConfig=r,this.globalAreaConfig=i,this.globalLengthConfig=a,this.sourceId=`square-source-${t.id}`,this.fillLayerId=`square-fill-${t.id}`,this.strokeLayerId=`square-stroke-${t.id}`,this.labelLayerId=`square-label-${t.id}`,this.areaLayerId=`square-area-${t.id}`,this.lengthLayerId=`square-length-${t.id}`,this.editSourceId=`square-edit-source-${t.id}`,this.editHandleLayerId=`square-edit-handles-${t.id}`,this.editMoveLayerId=`square-edit-move-${t.id}`,this.initLayers()}get nameStyle(){return x(this.entity.nameConfig,this.globalNameConfig,h)}get selectNameStyle(){return x(this.entity.selectNameConfig,this.globalSelectNameConfig,g)}get areaStyle(){return x(this.entity.areaConfig,this.globalAreaConfig,_)}get lengthStyle(){return x(this.entity.lengthConfig,this.globalLengthConfig,b)}initLayers(){if(!this.initialized)try{let t=this.getGeoJSON();this.map.addSource(this.sourceId,{type:`geojson`,data:t});let n=this.entity.confidence??1,r=P(n);this.map.addLayer({id:this.fillLayerId,type:`fill`,source:this.sourceId,filter:[`==`,`$type`,`Polygon`],paint:{"fill-color":this.entity.fillColor??e.DEFAULTS.fillColor,"fill-opacity":(this.entity.fillOpacity??e.DEFAULTS.fillOpacity)*r}}),this.map.addLayer({id:this.strokeLayerId,type:`line`,source:this.sourceId,filter:[`==`,`$type`,`Polygon`],layout:{"line-join":`miter`,"line-cap":`square`},paint:{"line-color":this.isSelected?`#ffcc00`:this.entity.strokeColor??e.DEFAULTS.strokeColor,"line-width":this.entity.strokeWidth??e.DEFAULTS.strokeWidth,"line-opacity":(this.entity.strokeOpacity??e.DEFAULTS.strokeOpacity)*r}}),this.entity.name&&this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`label`],layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.8],"text-allow-overlap":!0},paint:{"text-color":this.isSelected?this.selectNameStyle.fillColor:this.nameStyle.fillColor,"text-halo-color":this.isSelected?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor,"text-halo-width":this.isSelected?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth,"text-opacity":r}}),this.entity.showArea&&this.map.addLayer({id:this.areaLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`area`],layout:{"text-field":[`get`,`area`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-allow-overlap":!0},paint:{"text-color":this.areaStyle.fillColor,"text-halo-color":this.areaStyle.strokeColor,"text-halo-width":this.areaStyle.strokeWidth,"text-opacity":r}}),this.entity.showLength&&this.map.addLayer({id:this.lengthLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`length`],layout:{"text-field":[`get`,`length`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-offset":[.8,0],"text-allow-overlap":!0,"text-rotate":[`get`,`textRotation`],"text-rotation-alignment":`map`},paint:{"text-color":this.lengthStyle.fillColor,"text-halo-color":this.lengthStyle.strokeColor,"text-halo-width":this.lengthStyle.strokeWidth,"text-opacity":r}}),this.initialized=!0}catch{this.map.once(`idle`,()=>this.initLayers())}}getGeoJSON(){let{center:e,length:t}=this.entity,n=ve(e,t),r=[{type:`Feature`,geometry:{type:`Polygon`,coordinates:[n]},properties:{}}];if(this.entity.name){let e=this.getBottomCenterPoint(n);r.push({type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:{pointType:`label`,name:this.entity.name}})}if(this.entity.showArea&&r.push({type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:{pointType:`area`,area:A(this.getArea())}}),this.entity.showLength){let e=n[1],t=n[2],i=[(e[0]+t[0])/2,(e[1]+t[1])/2],a=O(e,t);r.push({type:`Feature`,geometry:{type:`Point`,coordinates:i},properties:{pointType:`length`,length:j(a),textRotation:0}})}return{type:`FeatureCollection`,features:r}}getBottomCenterPoint(e){let t=e[2],n=e[3];return[(t[0]+n[0])/2,(t[1]+n[1])/2]}getArea(){return this.entity.length*this.entity.length}getEntityId(){return this.entity.id}getCenter(){return this.entity.center}getBounds(){let{center:e,length:t}=this.entity,[n,r]=e,i=t/2/6371e3,a=r*Math.PI/180,o=i*180/Math.PI,s=i*180/Math.PI/Math.cos(a);return[[n-s,r-o],[n+s,r+o]]}getLayerId(){return this.fillLayerId}getLabelLayerId(){return this.entity.name?this.labelLayerId:null}setSelected(t){this.isSelected!==t&&(this.isSelected=t,this.initialized&&(this.map.getLayer(this.strokeLayerId)&&this.map.setPaintProperty(this.strokeLayerId,`line-color`,t?`#ffcc00`:this.entity.strokeColor??e.DEFAULTS.strokeColor),this.map.getLayer(this.labelLayerId)&&(this.map.setPaintProperty(this.labelLayerId,`text-color`,t?this.selectNameStyle.fillColor:this.nameStyle.fillColor),this.map.setPaintProperty(this.labelLayerId,`text-halo-color`,t?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor),this.map.setPaintProperty(this.labelLayerId,`text-halo-width`,t?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth))))}isPointInEntity(e){let{center:t,length:n}=this.entity,r=ve(t,n);return this.pointInPolygon(e,r)}pointInPolygon(e,t){let[n,r]=e,i=!1;for(let e=0,a=t.length-1;e<t.length;a=e++){let[o,s]=t[e],[c,l]=t[a];s>r!=l>r&&n<(c-o)*(r-s)/(l-s)+o&&(i=!i)}return i}update(t){let n=this.entity;if(this.entity=t,!this.initialized)return;let r=t.confidence??1,i=P(r);if(n.center!==t.center||n.length!==t.length||n.name!==t.name||n.showArea!==t.showArea||n.showLength!==t.showLength){let e=this.map.getSource(this.sourceId);e&&e.setData(this.getGeoJSON()),!n.name&&t.name&&!this.map.getLayer(this.labelLayerId)?this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`label`],layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.8],"text-allow-overlap":!0},paint:{"text-color":this.isSelected?this.selectNameStyle.fillColor:this.nameStyle.fillColor,"text-halo-color":this.isSelected?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor,"text-halo-width":this.isSelected?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth,"text-opacity":i}}):n.name&&!t.name&&this.map.getLayer(this.labelLayerId)&&this.map.removeLayer(this.labelLayerId),!n.showArea&&t.showArea&&!this.map.getLayer(this.areaLayerId)?this.map.addLayer({id:this.areaLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`area`],layout:{"text-field":[`get`,`area`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-allow-overlap":!0},paint:{"text-color":this.areaStyle.fillColor,"text-halo-color":this.areaStyle.strokeColor,"text-halo-width":this.areaStyle.strokeWidth,"text-opacity":i}}):n.showArea&&!t.showArea&&this.map.getLayer(this.areaLayerId)&&this.map.removeLayer(this.areaLayerId),!n.showLength&&t.showLength&&!this.map.getLayer(this.lengthLayerId)?this.map.addLayer({id:this.lengthLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`length`],layout:{"text-field":[`get`,`length`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-offset":[.8,0],"text-allow-overlap":!0,"text-rotate":[`get`,`textRotation`],"text-rotation-alignment":`map`},paint:{"text-color":this.lengthStyle.fillColor,"text-halo-color":this.lengthStyle.strokeColor,"text-halo-width":this.lengthStyle.strokeWidth,"text-opacity":i}}):n.showLength&&!t.showLength&&this.map.getLayer(this.lengthLayerId)&&this.map.removeLayer(this.lengthLayerId)}(n.fillColor!==t.fillColor||n.fillOpacity!==t.fillOpacity||n.confidence!==t.confidence)&&this.map.getLayer(this.fillLayerId)&&(this.map.setPaintProperty(this.fillLayerId,`fill-color`,t.fillColor??e.DEFAULTS.fillColor),this.map.setPaintProperty(this.fillLayerId,`fill-opacity`,(t.fillOpacity??e.DEFAULTS.fillOpacity)*i)),(n.strokeColor!==t.strokeColor||n.strokeWidth!==t.strokeWidth||n.strokeOpacity!==t.strokeOpacity||n.confidence!==t.confidence)&&this.map.getLayer(this.strokeLayerId)&&(this.isSelected||this.map.setPaintProperty(this.strokeLayerId,`line-color`,t.strokeColor??e.DEFAULTS.strokeColor),this.map.setPaintProperty(this.strokeLayerId,`line-width`,t.strokeWidth??e.DEFAULTS.strokeWidth),this.map.setPaintProperty(this.strokeLayerId,`line-opacity`,(t.strokeOpacity??e.DEFAULTS.strokeOpacity)*i)),n.confidence!==t.confidence&&(this.map.getLayer(this.labelLayerId)&&this.map.setPaintProperty(this.labelLayerId,`text-opacity`,i),this.map.getLayer(this.areaLayerId)&&this.map.setPaintProperty(this.areaLayerId,`text-opacity`,i),this.map.getLayer(this.lengthLayerId)&&this.map.setPaintProperty(this.lengthLayerId,`text-opacity`,i))}getCorners(e,t){return ve(e??this.entity.center,t??this.entity.length).slice(0,4)}getEditHandleGeoJSON(e,t){let n=this.getCorners(e,t).map((e,t)=>({type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:{handleType:`vertex`,index:t}})),r=e??this.entity.center;return n.push({type:`Feature`,geometry:{type:`Point`,coordinates:r},properties:{handleType:`move`,index:0}}),{type:`FeatureCollection`,features:n}}createEditLayers(){this.map.getSource(this.editSourceId)||(I(this.map),this.map.addSource(this.editSourceId,{type:`geojson`,data:this.getEditHandleGeoJSON()}),this.map.addLayer({id:this.editHandleLayerId,type:`circle`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`vertex`],paint:{"circle-radius":6,"circle-color":`#ffffff`,"circle-stroke-color":`#3388ff`,"circle-stroke-width":2}}),this.map.addLayer({id:this.editMoveLayerId,type:`symbol`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`move`],layout:{"icon-image":ae,"icon-allow-overlap":!0,"icon-ignore-placement":!0}}))}removeEditLayers(){this.map.getLayer(this.editMoveLayerId)&&this.map.removeLayer(this.editMoveLayerId),this.map.getLayer(this.editHandleLayerId)&&this.map.removeLayer(this.editHandleLayerId),this.map.getSource(this.editSourceId)&&this.map.removeSource(this.editSourceId)}refreshEditHandles(e,t){let n=this.map.getSource(this.editSourceId);n&&n.setData(this.getEditHandleGeoJSON(e,t))}setEditing(e){this.isEditing!==e&&(this.isEditing=e,this.initialized&&(e?this.createEditLayers():this.removeEditLayers()))}getEditHandleAt(e,t){if(!this.isEditing)return null;let n=this.getCorners(),r=this.map.project(e),i=this.entity.center,a=this.map.project(i),o=r.x-a.x,s=r.y-a.y;if(o*o+s*s<=144)return{type:`move`,index:0,position:i};for(let e=0;e<n.length;e++){let t=this.map.project(n[e]),i=r.x-t.x,a=r.y-t.y;if(i*i+a*a<=100)return{type:`vertex`,index:e,position:n[e]}}return null}computeNewLength(e){return O(this.entity.center,e)*Math.SQRT2}applyHandleMove(e,t){let n;if(e.type===`move`){let r=t[0]-e.position[0],i=t[1]-e.position[1],a=[this.entity.center[0]+r,this.entity.center[1]+i];n={...this.entity,center:a}}else{let e=this.computeNewLength(t);n={...this.entity,length:e}}this.entity=n;let r=this.map.getSource(this.sourceId);return r&&r.setData(this.getGeoJSON()),this.refreshEditHandles(),n}updateEditPreview(e,t){let n,r;if(e.type===`move`){let i=t[0]-e.position[0],a=t[1]-e.position[1];n=[this.entity.center[0]+i,this.entity.center[1]+a],r=this.entity.length}else n=this.entity.center,r=this.computeNewLength(t);let i=this.entity;this.entity={...this.entity,center:n,length:r};let a=this.map.getSource(this.sourceId);a&&a.setData(this.getGeoJSON()),this.entity=i,this.refreshEditHandles(n,r)}cancelEditPreview(){let e=this.map.getSource(this.sourceId);e&&e.setData(this.getGeoJSON()),this.refreshEditHandles()}destroy(){this.initialized&&=(this.removeEditLayers(),this.map.getLayer(this.lengthLayerId)&&this.map.removeLayer(this.lengthLayerId),this.map.getLayer(this.areaLayerId)&&this.map.removeLayer(this.areaLayerId),this.map.getLayer(this.labelLayerId)&&this.map.removeLayer(this.labelLayerId),this.map.getLayer(this.strokeLayerId)&&this.map.removeLayer(this.strokeLayerId),this.map.getLayer(this.fillLayerId)&&this.map.removeLayer(this.fillLayerId),this.map.getSource(this.sourceId)&&this.map.removeSource(this.sourceId),!1)}};function be(e){let[[t,n],[r,i]]=e,a=Math.min(t,r),o=Math.max(t,r),s=Math.min(n,i),c=Math.max(n,i);return[[a,c],[o,c],[o,s],[a,s],[a,c]]}var xe=class e{static{this.DEFAULTS={strokeColor:`#3388ff`,strokeWidth:2,strokeOpacity:1,fillColor:`#3388ff`,fillOpacity:.2}}constructor(e,t,n,r,i,a){this.isSelected=!1,this.initialized=!1,this.isEditing=!1,this.map=e,this.entity=t,this.globalNameConfig=n,this.globalSelectNameConfig=r,this.globalAreaConfig=i,this.globalLengthConfig=a,this.sourceId=`rectangle-source-${t.id}`,this.fillLayerId=`rectangle-fill-${t.id}`,this.strokeLayerId=`rectangle-stroke-${t.id}`,this.labelLayerId=`rectangle-label-${t.id}`,this.areaLayerId=`rectangle-area-${t.id}`,this.lengthLayerId=`rectangle-length-${t.id}`,this.editSourceId=`rectangle-edit-source-${t.id}`,this.editHandleLayerId=`rectangle-edit-handles-${t.id}`,this.editMoveLayerId=`rectangle-edit-move-${t.id}`,this.initLayers()}get nameStyle(){return x(this.entity.nameConfig,this.globalNameConfig,h)}get selectNameStyle(){return x(this.entity.selectNameConfig,this.globalSelectNameConfig,g)}get areaStyle(){return x(this.entity.areaConfig,this.globalAreaConfig,_)}get lengthStyle(){return x(this.entity.lengthConfig,this.globalLengthConfig,b)}initLayers(){if(!this.initialized)try{let t=this.getGeoJSON();this.map.addSource(this.sourceId,{type:`geojson`,data:t});let n=this.entity.confidence??1,r=P(n);this.map.addLayer({id:this.fillLayerId,type:`fill`,source:this.sourceId,filter:[`==`,`$type`,`Polygon`],paint:{"fill-color":this.entity.fillColor??e.DEFAULTS.fillColor,"fill-opacity":(this.entity.fillOpacity??e.DEFAULTS.fillOpacity)*r}}),this.map.addLayer({id:this.strokeLayerId,type:`line`,source:this.sourceId,filter:[`==`,`$type`,`Polygon`],layout:{"line-join":`miter`,"line-cap":`square`},paint:{"line-color":this.isSelected?`#ffcc00`:this.entity.strokeColor??e.DEFAULTS.strokeColor,"line-width":this.entity.strokeWidth??e.DEFAULTS.strokeWidth,"line-opacity":(this.entity.strokeOpacity??e.DEFAULTS.strokeOpacity)*r}}),this.entity.name&&this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`label`],layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.8],"text-allow-overlap":!0},paint:{"text-color":this.isSelected?this.selectNameStyle.fillColor:this.nameStyle.fillColor,"text-halo-color":this.isSelected?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor,"text-halo-width":this.isSelected?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth,"text-opacity":r}}),this.entity.showArea&&this.map.addLayer({id:this.areaLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`area`],layout:{"text-field":[`get`,`area`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-allow-overlap":!0},paint:{"text-color":this.areaStyle.fillColor,"text-halo-color":this.areaStyle.strokeColor,"text-halo-width":this.areaStyle.strokeWidth,"text-opacity":r}}),this.entity.showLength&&this.map.addLayer({id:this.lengthLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`length`],layout:{"text-field":[`get`,`length`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-offset":[0,-.8],"text-allow-overlap":!0},paint:{"text-color":this.lengthStyle.fillColor,"text-halo-color":this.lengthStyle.strokeColor,"text-halo-width":this.lengthStyle.strokeWidth,"text-opacity":r}}),this.initialized=!0}catch{this.map.once(`idle`,()=>this.initLayers())}}getGeoJSON(){let{bounds:e}=this.entity,t=be(e),n=[{type:`Feature`,geometry:{type:`Polygon`,coordinates:[t]},properties:{}}];if(this.entity.name){let e=this.getBottomCenterPoint(t);n.push({type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:{pointType:`label`,name:this.entity.name}})}if(this.entity.showArea){let e=this.calculateRectangleCenter();n.push({type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:{pointType:`area`,area:A(this.getArea())}})}if(this.entity.showLength)for(let[e,r,i]of[[0,1,0],[1,2,0]]){let a=t[e],o=t[r],s=[(a[0]+o[0])/2,(a[1]+o[1])/2],c=O(a,o);n.push({type:`Feature`,geometry:{type:`Point`,coordinates:s},properties:{pointType:`length`,length:j(c),textRotation:i}})}return{type:`FeatureCollection`,features:n}}getBottomCenterPoint(e){let t=e[2],n=e[3];return[(t[0]+n[0])/2,(t[1]+n[1])/2]}getArea(){let e=be(this.entity.bounds);return ee(e)}getEntityId(){return this.entity.id}getBounds(){let[[e,t],[n,r]]=this.entity.bounds,i=Math.min(e,n),a=Math.max(e,n);return[[i,Math.min(t,r)],[a,Math.max(t,r)]]}getCenter(){return this.entity.center?this.entity.center:this.calculateRectangleCenter()}calculateRectangleCenter(){let[[e,t],[n,r]]=this.entity.bounds;return[(e+n)/2,(t+r)/2]}getLayerId(){return this.fillLayerId}getLabelLayerId(){return this.entity.name?this.labelLayerId:null}setSelected(t){this.isSelected!==t&&(this.isSelected=t,this.initialized&&(this.map.getLayer(this.strokeLayerId)&&this.map.setPaintProperty(this.strokeLayerId,`line-color`,t?`#ffcc00`:this.entity.strokeColor??e.DEFAULTS.strokeColor),this.map.getLayer(this.labelLayerId)&&(this.map.setPaintProperty(this.labelLayerId,`text-color`,t?this.selectNameStyle.fillColor:this.nameStyle.fillColor),this.map.setPaintProperty(this.labelLayerId,`text-halo-color`,t?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor),this.map.setPaintProperty(this.labelLayerId,`text-halo-width`,t?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth))))}isPointInEntity(e){let{bounds:t}=this.entity,n=be(t);return this.pointInPolygon(e,n)}pointInPolygon(e,t){let[n,r]=e,i=!1;for(let e=0,a=t.length-1;e<t.length;a=e++){let[o,s]=t[e],[c,l]=t[a];s>r!=l>r&&n<(c-o)*(r-s)/(l-s)+o&&(i=!i)}return i}update(t){let n=this.entity;if(this.entity=t,!this.initialized)return;let r=t.confidence??1,i=P(r);if(n.bounds!==t.bounds||n.name!==t.name||n.showArea!==t.showArea||n.showLength!==t.showLength){let e=this.map.getSource(this.sourceId);e&&e.setData(this.getGeoJSON()),!n.name&&t.name&&!this.map.getLayer(this.labelLayerId)?this.map.addLayer({id:this.labelLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`label`],layout:{"text-field":[`get`,`name`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":14,"text-anchor":`top`,"text-offset":[0,.8],"text-allow-overlap":!0},paint:{"text-color":this.isSelected?this.selectNameStyle.fillColor:this.nameStyle.fillColor,"text-halo-color":this.isSelected?this.selectNameStyle.strokeColor:this.nameStyle.strokeColor,"text-halo-width":this.isSelected?this.selectNameStyle.strokeWidth:this.nameStyle.strokeWidth,"text-opacity":i}}):n.name&&!t.name&&this.map.getLayer(this.labelLayerId)&&this.map.removeLayer(this.labelLayerId),!n.showArea&&t.showArea&&!this.map.getLayer(this.areaLayerId)?this.map.addLayer({id:this.areaLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`area`],layout:{"text-field":[`get`,`area`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-allow-overlap":!0},paint:{"text-color":this.areaStyle.fillColor,"text-halo-color":this.areaStyle.strokeColor,"text-halo-width":this.areaStyle.strokeWidth,"text-opacity":i}}):n.showArea&&!t.showArea&&this.map.getLayer(this.areaLayerId)&&this.map.removeLayer(this.areaLayerId),!n.showLength&&t.showLength&&!this.map.getLayer(this.lengthLayerId)?this.map.addLayer({id:this.lengthLayerId,type:`symbol`,source:this.sourceId,filter:[`==`,[`get`,`pointType`],`length`],layout:{"text-field":[`get`,`length`],"text-font":[`Open Sans Bold`,`Arial Unicode MS Bold`],"text-size":12,"text-anchor":`center`,"text-offset":[0,-.8],"text-allow-overlap":!0},paint:{"text-color":this.lengthStyle.fillColor,"text-halo-color":this.lengthStyle.strokeColor,"text-halo-width":this.lengthStyle.strokeWidth,"text-opacity":i}}):n.showLength&&!t.showLength&&this.map.getLayer(this.lengthLayerId)&&this.map.removeLayer(this.lengthLayerId)}(n.fillColor!==t.fillColor||n.fillOpacity!==t.fillOpacity||n.confidence!==t.confidence)&&this.map.getLayer(this.fillLayerId)&&(this.map.setPaintProperty(this.fillLayerId,`fill-color`,t.fillColor??e.DEFAULTS.fillColor),this.map.setPaintProperty(this.fillLayerId,`fill-opacity`,(t.fillOpacity??e.DEFAULTS.fillOpacity)*i)),(n.strokeColor!==t.strokeColor||n.strokeWidth!==t.strokeWidth||n.strokeOpacity!==t.strokeOpacity||n.confidence!==t.confidence)&&this.map.getLayer(this.strokeLayerId)&&(this.isSelected||this.map.setPaintProperty(this.strokeLayerId,`line-color`,t.strokeColor??e.DEFAULTS.strokeColor),this.map.setPaintProperty(this.strokeLayerId,`line-width`,t.strokeWidth??e.DEFAULTS.strokeWidth),this.map.setPaintProperty(this.strokeLayerId,`line-opacity`,(t.strokeOpacity??e.DEFAULTS.strokeOpacity)*i)),n.confidence!==t.confidence&&(this.map.getLayer(this.labelLayerId)&&this.map.setPaintProperty(this.labelLayerId,`text-opacity`,i),this.map.getLayer(this.areaLayerId)&&this.map.setPaintProperty(this.areaLayerId,`text-opacity`,i),this.map.getLayer(this.lengthLayerId)&&this.map.setPaintProperty(this.lengthLayerId,`text-opacity`,i))}getCorners(e){return be(e??this.entity.bounds).slice(0,4)}getEditHandleGeoJSON(e){let t=this.getCorners(e).map((e,t)=>({type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:{handleType:`vertex`,index:t}})),n=e??this.entity.bounds,r=(n[0][0]+n[1][0])/2,i=(n[0][1]+n[1][1])/2;return t.push({type:`Feature`,geometry:{type:`Point`,coordinates:[r,i]},properties:{handleType:`move`,index:0}}),{type:`FeatureCollection`,features:t}}createEditLayers(){this.map.getSource(this.editSourceId)||(I(this.map),this.map.addSource(this.editSourceId,{type:`geojson`,data:this.getEditHandleGeoJSON()}),this.map.addLayer({id:this.editHandleLayerId,type:`circle`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`vertex`],paint:{"circle-radius":6,"circle-color":`#ffffff`,"circle-stroke-color":`#3388ff`,"circle-stroke-width":2}}),this.map.addLayer({id:this.editMoveLayerId,type:`symbol`,source:this.editSourceId,filter:[`==`,[`get`,`handleType`],`move`],layout:{"icon-image":ae,"icon-allow-overlap":!0,"icon-ignore-placement":!0}}))}removeEditLayers(){this.map.getLayer(this.editMoveLayerId)&&this.map.removeLayer(this.editMoveLayerId),this.map.getLayer(this.editHandleLayerId)&&this.map.removeLayer(this.editHandleLayerId),this.map.getSource(this.editSourceId)&&this.map.removeSource(this.editSourceId)}refreshEditHandles(e){let t=this.map.getSource(this.editSourceId);t&&t.setData(this.getEditHandleGeoJSON(e))}setEditing(e){this.isEditing!==e&&(this.isEditing=e,this.initialized&&(e?this.createEditLayers():this.removeEditLayers()))}getEditHandleAt(e,t){if(!this.isEditing)return null;let n=this.getCorners(),r=this.map.project(e),i=this.calculateRectangleCenter(),a=this.map.project(i),o=r.x-a.x,s=r.y-a.y;if(o*o+s*s<=144)return{type:`move`,index:0,position:i};for(let e=0;e<n.length;e++){let t=this.map.project(n[e]),i=r.x-t.x,a=r.y-t.y;if(i*i+a*a<=100)return{type:`vertex`,index:e,position:n[e]}}return null}computeNewBounds(e,t){let n=this.getCorners(),r=(e+2)%4,i=n[r];return[[Math.min(t[0],i[0]),Math.min(t[1],i[1])],[Math.max(t[0],i[0]),Math.max(t[1],i[1])]]}offsetBounds(e,t,n){let r=n[0]-t[0],i=n[1]-t[1];return[[e[0][0]+r,e[0][1]+i],[e[1][0]+r,e[1][1]+i]]}applyHandleMove(e,t){let n;n=e.type===`move`?this.offsetBounds(this.entity.bounds,e.position,t):this.computeNewBounds(e.index,t);let r={...this.entity,bounds:n};this.entity=r;let i=this.map.getSource(this.sourceId);return i&&i.setData(this.getGeoJSON()),this.refreshEditHandles(),r}updateEditPreview(e,t){let n;n=e.type===`move`?this.offsetBounds(this.entity.bounds,e.position,t):this.computeNewBounds(e.index,t);let r=this.entity;this.entity={...this.entity,bounds:n};let i=this.map.getSource(this.sourceId);i&&i.setData(this.getGeoJSON()),this.entity=r,this.refreshEditHandles(n)}cancelEditPreview(){let e=this.map.getSource(this.sourceId);e&&e.setData(this.getGeoJSON()),this.refreshEditHandles()}destroy(){this.initialized&&=(this.removeEditLayers(),this.map.getLayer(this.lengthLayerId)&&this.map.removeLayer(this.lengthLayerId),this.map.getLayer(this.areaLayerId)&&this.map.removeLayer(this.areaLayerId),this.map.getLayer(this.labelLayerId)&&this.map.removeLayer(this.labelLayerId),this.map.getLayer(this.strokeLayerId)&&this.map.removeLayer(this.strokeLayerId),this.map.getLayer(this.fillLayerId)&&this.map.removeLayer(this.fillLayerId),this.map.getSource(this.sourceId)&&this.map.removeSource(this.sourceId),!1)}};const Se=({popupState:e,onClose:t,portalContainer:n,popupRef:r})=>{let i=(0,c.useRef)(null),[a,o]=(0,c.useState)(`entering`),[s,l]=(0,c.useState)(!1),u=(0,c.useRef)(e.position),d=(0,c.useRef)(!1),m=r||i;d.current||(u.current=e.position),(0,c.useEffect)(()=>{let e=setTimeout(()=>{l(!0)},60);return()=>clearTimeout(e)},[]),(0,c.useEffect)(()=>{if(a===`entering`&&s){let e=setTimeout(()=>o(`entered`),50);return()=>clearTimeout(e)}},[a,s]);let h=(0,c.useCallback)(()=>{e.config.animation===`none`?t():(d.current=!0,o(`exiting`),setTimeout(()=>t(),200))},[e.config.animation,t]);(0,c.useEffect)(()=>{if(!e.config.closeOnEscape)return;let t=e=>{e.key===`Escape`&&h()};return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[e.config.closeOnEscape,h]),(0,c.useEffect)(()=>{if(!e.config.closeOnClickOutside)return;let t=e=>{m.current&&!m.current.contains(e.target)&&h()},n=setTimeout(()=>{document.addEventListener(`click`,t,!0)},0);return()=>{clearTimeout(n),document.removeEventListener(`click`,t,!0)}},[e.config.closeOnClickOutside,h,m]);let g=()=>{switch(e.actualPosition){case`top`:return`center bottom`;case`bottom`:return`center top`;case`left`:return`right center`;case`right`:return`left center`;case`center`:default:return`center center`}},_=u.current,v=(0,p.jsxs)(`div`,{ref:m,className:`entity-popup ${s?`entity-popup--${a} animation-${e.config.animation}`:``} ${e.config.className||``}`,style:{position:`fixed`,left:`${_.x}px`,top:`${_.y}px`,maxWidth:e.config.maxWidth,zIndex:e.config.zIndex,pointerEvents:`all`,opacity:s?void 0:0,transformOrigin:g(),...e.config.style},role:`dialog`,"aria-modal":`true`,children:[e.config.showCloseButton&&(0,p.jsx)(`button`,{className:`entity-popup__close`,onClick:h,"aria-label":`Close popup`,children:`×`}),(0,p.jsx)(`div`,{className:`entity-popup__content`,children:e.config.content})]});return(0,f.createPortal)(v,n)};var Ce=`data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20t='1768373933818'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20p-id='30344'%20width='200'%20height='200'%3e%3cpath%20d='M400.440142%201024h-0.073136a48.781895%2048.781895%200%200%201-45.490763-31.448598L3.383306%2066.061072a48.781895%2048.781895%200%200%201%2062.897196-62.897197l926.563466%20351.419801a48.928168%2048.928168%200%200%201%200.219409%2091.127799L597.761811%20597.688654l-151.904042%20395.082157a48.781895%2048.781895%200%200%201-45.490763%2031.229189zM133.053921%20132.907627l267.678766%20705.691916%20113.87318-296.201913a48.855032%2048.855032%200%200%201%2028.011193-27.938057l296.201913-113.87318-705.765052-267.678766z'%20p-id='30345'%20fill='%23ffffff'%20/%3e%3cscript%20xmlns=''%20/%3e%3c/svg%3e`;function we({map:e,precision:t=6,className:n=``,style:r}){let[i,a]=(0,c.useState)(null),[o,s]=(0,c.useState)(!1),l=(0,c.useRef)(void 0),u=(0,c.useCallback)(e=>{a({lng:Number(e.lngLat.lng.toFixed(t)),lat:Number(e.lngLat.lat.toFixed(t))})},[t]);(0,c.useEffect)(()=>{if(e)return e.on(`mousemove`,u),()=>{e.off(`mousemove`,u)}},[e,u]),(0,c.useEffect)(()=>()=>{l.current&&clearTimeout(l.current)},[]);let d=(0,c.useCallback)(()=>{if(!i)return;let e=`${i.lng},${i.lat}`;navigator.clipboard.writeText(e).then(()=>{s(!0),l.current&&clearTimeout(l.current),l.current=setTimeout(()=>s(!1),1500)})},[i]);return i?(0,p.jsxs)(`div`,{className:`mapbox-coordinate-display ${o?`mapbox-coordinate-display--copied`:``} ${n}`,style:r,onClick:d,title:`点击复制坐标`,children:[(0,p.jsx)(`img`,{src:Ce,alt:`location`,className:`mapbox-coordinate-display__icon`}),(0,p.jsx)(`div`,{className:`mapbox-coordinate-display__content`,children:o?(0,p.jsx)(`span`,{className:`mapbox-coordinate-display__copied`,children:`已复制`}):(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`span`,{className:`mapbox-coordinate-display__item`,children:[`经度:`,i.lng]}),(0,p.jsxs)(`span`,{className:`mapbox-coordinate-display__item`,children:[`纬度:`,i.lat]})]})})]}):null}var R=`data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20t='1768374054549'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20p-id='31504'%20width='200'%20height='200'%3e%3cpath%20d='M53.80096%20687.40096l282.79808%20282.79808%20633.6-633.6-282.79808-282.79808-90.39872%2090.39872-28.29824%2028.20096-42.7008%2042.7008-23.5008%2023.5008-63.20128%2063.19616-12.29824%2012.29824-373.20192%20373.30432z%20m282.79808%20212.10112l-212.10112-212.1984%2054.99904-54.99904%20106.10176%20106.10176%2028.29824-28.29824-106.10176-106.10176%2042.39872-42.39872%2070.70208%2070.70208%2028.29824-28.29824-70.69184-70.71232%2042.39872-42.39872%2070.70208%2070.70208%2028.29824-28.29824-70.70208-70.70208%2042.39872-42.39872%20106.10176%20106.10176%2028.29824-28.29824-106.09664-106.10688%2042.39872-42.39872%2070.70208%2070.70208%2028.29824-28.29824-70.70208-70.7072%2042.39872-42.39872%2070.70208%2070.70208%2028.29824-28.29824-70.70208-70.70208%2042.7008-42.7008%20106.10176%20106.10176%2028.29824-28.29824-105.99936-106.10176%2054.99904-54.99904%20212.10112%20212.10112L336.59904%20899.50208z'%20fill='%23ffffff'%20p-id='31505'%20/%3e%3cscript%20xmlns=''%20/%3e%3c/svg%3e`;function Te({map:e,maxWidth:t=100,unit:n=`metric`,className:r=``,style:i}){let[a,o]=(0,c.useState)({width:100,label:`100 m`}),s=(0,c.useCallback)(()=>{if(!e)return;let r=e.getCanvas().clientHeight/2,i=e.unproject([0,r]),a=e.unproject([t,r]),s=i.lat*Math.PI/180,c=a.lat*Math.PI/180,l=c-s,u=(a.lng-i.lng)*Math.PI/180,d=Math.sin(l/2)*Math.sin(l/2)+Math.cos(s)*Math.cos(c)*Math.sin(u/2)*Math.sin(u/2),f=6371008.8*(2*Math.atan2(Math.sqrt(d),Math.sqrt(1-d))),p,m;if(n===`imperial`){let e=3.2808*f;if(e>5280){let n=e/5280;p=z(n),m=`${p} mi`;let r=p/n;o({width:t*r,label:m})}else{p=z(e),m=`${p} ft`;let n=p/e;o({width:t*n,label:m})}}else if(n===`nautical`){let e=f/1852;p=z(e),m=`${p} nm`;let n=p/e;o({width:t*n,label:m})}else if(f>=1e3){p=z(f/1e3),m=`${p} km`;let e=p/(f/1e3);o({width:t*e,label:m})}else{p=z(f),m=`${p} m`;let e=p/f;o({width:t*e,label:m})}},[e,t,n]);return(0,c.useEffect)(()=>{if(e)return s(),e.on(`move`,s),e.on(`zoom`,s),()=>{e.off(`move`,s),e.off(`zoom`,s)}},[e,s]),(0,p.jsxs)(`div`,{className:`mapbox-scale-control ${r}`,style:i,children:[(0,p.jsxs)(`div`,{className:`mapbox-scale-control__bar-wrapper`,children:[(0,p.jsx)(`img`,{src:R,alt:`scale`,className:`mapbox-scale-control__icon`}),(0,p.jsxs)(`div`,{className:`mapbox-scale-control__bar`,style:{width:`${a.width}px`},children:[(0,p.jsx)(`div`,{className:`mapbox-scale-control__tick mapbox-scale-control__tick--left`}),(0,p.jsx)(`div`,{className:`mapbox-scale-control__tick mapbox-scale-control__tick--right`})]})]}),(0,p.jsx)(`span`,{className:`mapbox-scale-control__label`,children:a.label})]})}function z(e){let t=10**(`${Math.floor(e)}`.length-1),n=e/t;return n=n>=10?10:n>=5?5:n>=3?3:n>=2?2:1,t*n}var B=`data:image/svg+xml,%3c?xml%20version='1.0'%20standalone='no'?%3e%3c!DOCTYPE%20svg%20PUBLIC%20'-//W3C//DTD%20SVG%201.1//EN'%20'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3e%3csvg%20t='1768989620222'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='5780'%20width='128'%20height='128'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3cpath%20d='M938.666667%20602.752a42.666667%2042.666667%200%200%201%2042.368%2037.674667l0.298666%204.992V853.333333a128%20128%200%200%201-120.490666%20127.786667L853.333333%20981.333333h-208.896a42.666667%2042.666667%200%200%201-4.949333-85.034666l4.949333-0.298667H853.333333a42.666667%2042.666667%200%200%200%2042.368-37.674667L896%20853.333333v-207.914666a42.666667%2042.666667%200%200%201%2042.666667-42.666667z%20m-853.333334%203.285333a42.666667%2042.666667%200%200%201%2042.368%2037.674667l0.298667%204.992V853.333333a42.666667%2042.666667%200%200%200%2037.674667%2042.368L170.666667%20896h211.882666a42.666667%2042.666667%200%200%201%204.992%2085.034667L382.549333%20981.333333H170.666667a128%20128%200%200%201-127.786667-120.490666L42.666667%20853.333333v-204.629333a42.666667%2042.666667%200%200%201%2042.666666-42.666667zM381.866667%2042.666667A42.666667%2042.666667%200%200%201%20386.944%20127.701333L381.866667%20128H170.666667a42.666667%2042.666667%200%200%200-42.368%2037.674667L128%20170.666667v216.448a42.666667%2042.666667%200%200%201-85.034667%204.992L42.666667%20387.114667V170.666667A128%20128%200%200%201%20163.157333%2042.88L170.666667%2042.666667h211.2zM853.333333%2042.666667a128%20128%200%200%201%20127.786667%20120.490666L981.333333%20170.666667v216.064a42.666667%2042.666667%200%200%201-85.034666%204.992L896%20386.730667V170.666667a42.666667%2042.666667%200%200%200-37.674667-42.368L853.333333%20128h-214.4a42.666667%2042.666667%200%200%201-4.949333-85.034667L638.933333%2042.666667H853.333333z'%20fill='%23ffffff'%20p-id='5781'%3e%3c/path%3e%3cpath%20d='M512%20512m-128%200a128%20128%200%201%200%20256%200%20128%20128%200%201%200-256%200Z'%20fill='%23ffffff'%20p-id='5782'%3e%3c/path%3e%3c/svg%3e`;function Ee({map:e,initialCenter:t,initialZoom:n,initialPitch:r=0,initialBearing:i=0,className:a=``,style:o,duration:s=1e3}){return(0,p.jsxs)(`button`,{className:`mapbox-control-btn mapbox-reset-view-control ${a}`,onClick:()=>{e&&e.flyTo({center:t,zoom:n,pitch:r,bearing:i,duration:s})},style:o,title:`回到初始位置`,children:[(0,p.jsx)(`img`,{src:B,alt:`home`,className:`mapbox-control-btn__icon`}),(0,p.jsx)(`span`,{children:`复位`})]})}var De=`data:image/svg+xml,%3c?xml%20version='1.0'%20standalone='no'?%3e%3c!DOCTYPE%20svg%20PUBLIC%20'-//W3C//DTD%20SVG%201.1//EN'%20'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3e%3csvg%20t='1769487141027'%20class='icon'%20viewBox='0%200%201517%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='2644'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='189.625'%20height='128'%3e%3cpath%20d='M1.68121071-242.12320149h1508.24640296v1508.24640298h-1508.24640296z'%20fill='%23ffffff'%20fill-opacity='0'%20p-id='2645'%3e%3c/path%3e%3cpath%20d='M437.30078846%20170.6624h682.66239999v682.6624H437.30078846z'%20fill='%23ffffff'%20fill-opacity='0'%20p-id='2646'%3e%3c/path%3e%3cpath%20d='M1151.68343834%2040.66710748H373.42829443A81.76345149%2081.76345149%200%200%200%20292.90207634%20121.49379654v784.42363608c0%2040.42218191%2036.92257893%2077.41545989%2080.5262181%2077.4154599h781.6133488a81.76345149%2081.76345149%200%200%200%2080.52621814-80.82668906V121.49379654C1232.08593315%2077.76643404%201195.25172802%2040.66710748%201151.6657636%2040.66710748z%20m-325.39237822%20616.14222197H618.29445458V451.37556451h53.66057906c6.71640976%200%2013.41514477-3.35820487%2020.11387975-6.73408452l97.28189301-100.99359314h134.18679716v208.72127078c-46.96184405%2013.50351858-87.22495312%2053.90802574-97.28189299%20104.4048223z%20m130.7932427-20.23760311c23.50743418%200%2043.65666346%2020.21992834%2043.65666349%2043.76271204a44.50505206%2044.50505206%200%200%201-43.62131391%2043.7803868%2044.50505206%2044.50505206%200%200%201-43.6036392-43.7803868c0-23.54278369%2020.096205-43.76271203%2043.6036392-43.76271204h-0.05302433zM564.63387554%20926.10201142H373.42829443a22.87114272%2022.87114272%200%200%201-16.79102442-6.71640975%2023.04789036%2023.04789036%200%200%201-6.71640975-16.82637394V714.02253578h214.73069002v212.07947564z%20m0-269.31035673H349.92086026V118.13559167c0-10.1453137%2010.05693988-20.2376031%2023.50743417-20.23760309h553.4321645v188.53669194h-147.54891766c-6.69873499%200-13.39747001%203.35820487-20.096205%206.71640977l-97.28189297%2097.653063H460.61789801a26.44144475%2026.44144475%200%200%200-19.08874355%207.79457028%2026.63586714%2026.63586714%200%200%200-7.72387123%2019.1594426c0%2016.80869917%2013.39747001%2026.90098858%2026.81261478%2026.90098857h104.03365227v212.13249995z%20m610.48629795%20245.71454877c0.17674763%206.29221547-2.24469484%2012.37233377-6.68106024%2016.84404869s-10.49880895%206.89315739-16.77334965%206.75175927h-533.42433329v-212.0971504H829.63159021c13.39747001%2057.24855586%2067.07572382%2097.65306301%20127.48806219%2097.653063a128.67227125%20128.67227125%200%200%200%2093.05762473-37.87701612%20129.60903367%20129.60903367%200%200%200%2037.73561801-93.39344522c0-64.00031515-46.96184405-117.8553166-103.98062799-128.00063029v-208.73894554h194.56378599v558.91134088h-3.35820489v-0.05302427z%20m0-616.07152294H980.57406228V97.89798858h171.10937607c13.39747001%200%2023.45440988%2010.07461465%2023.4544099%2023.59580796v164.94088398z'%20fill='%23ffffff'%20p-id='2647'%3e%3c/path%3e%3c/svg%3e`,V=`road-highlight-`,Oe=[{source:`composite`,sourceLayer:`road`},{source:`openmaptiles`,sourceLayer:`transportation`},{source:`maptiler_planet`,sourceLayer:`transportation`}];function ke(e){let t=e.getStyle();if(!t||!t.sources)return null;for(let e of Oe){let n=t.sources[e.source];if(n&&n.type===`vector`)return e}for(let[e,n]of Object.entries(t.sources))if(n.type===`vector`)return{source:e,sourceLayer:`transportation`};return null}function Ae({map:e,highlightWidth:t=3,defaultRoadTypes:n=[],defaultMinWidth:r=0,source:i,sourceLayer:a,classField:o=`class`,className:s=``,style:u}){let[d,f]=(0,c.useState)(!1),[h,g]=(0,c.useState)(n),[_,v]=(0,c.useState)(!1),y=(0,c.useRef)(!1),b=(0,c.useRef)(null),x=(0,c.useRef)(null),S=(0,c.useRef)(null),C=(0,c.useCallback)((e,n,r)=>{if(!e.isStyleLoaded()||!e.getSource(n))return!1;let i=!0;return E.forEach(a=>{let s=`${V}${a.class}`;if(!e.getLayer(s))try{e.addLayer({id:s,type:`line`,source:n,"source-layer":r,filter:[`==`,[`get`,o],a.class],paint:{"line-color":a.color,"line-width":t,"line-opacity":.8},layout:{visibility:`none`}}),console.log(`Added road highlight layer: ${s} (source: ${n}, source-layer: ${r})`)}catch(e){console.error(`Failed to add road highlight layer for ${a.class}:`,e),i=!1}}),i},[t,o]);(0,c.useEffect)(()=>{if(!e)return;let t=()=>{let t=i,n=a;if(!t||!n){let r=ke(e);r&&(console.log(`Auto-detected vector source:`,r),t||=r.source,n||=r.sourceLayer)}t&&n?C(e,t,n)&&(y.current=!0,v(!0)):console.warn(`No vector source found for road highlighting`)};e.isStyleLoaded()?t():e.once(`load`,t);let n=()=>{e.isStyleLoaded()&&t()},r=()=>{y.current||t()};return e.on(`styledata`,n),e.on(`sourcedata`,r),()=>{e.off(`styledata`,n),e.off(`sourcedata`,r)}},[e,i,a,C]),(0,c.useEffect)(()=>{!e||!_||E.forEach(t=>{let n=`${V}${t.class}`;if(e.getLayer(n))try{let r=h.includes(t.class);e.setLayoutProperty(n,`visibility`,r?`visible`:`none`)}catch(e){console.error(`Failed to update layer ${n}:`,e)}})},[e,_,h]),(0,c.useEffect)(()=>{if(!d)return;let e=e=>{b.current&&!b.current.contains(e.target)&&x.current&&!x.current.contains(e.target)&&f(!1)},t=setTimeout(()=>{document.addEventListener(`mousedown`,e)},0);return()=>{clearTimeout(t),document.removeEventListener(`mousedown`,e)}},[d]),(0,c.useEffect)(()=>()=>{e&&e.getStyle()&&E.forEach(t=>{let n=`${V}${t.class}`;if(e.getLayer(n))try{e.removeLayer(n)}catch{}}),S.current&&=(S.current.remove(),null)},[e]);let w=(0,c.useCallback)(e=>E.find(t=>t.class===e)?.label||e,[]),T=(0,c.useCallback)(t=>{if(!e||h.length===0){S.current&&S.current.remove(),e?.getCanvas().style.cursor&&(e.getCanvas().style.cursor=``);return}let n=h.map(e=>`${V}${e}`),r=[[t.point.x-10,t.point.y-10],[t.point.x+10,t.point.y+10]],i=e.queryRenderedFeatures(r,{layers:n.filter(t=>e.getLayer(t))});if(i.length>0){let n=i[0].properties||{},r=t.lngLat,a=n.name||n.name_en||n.name_local||``,s=n[o]||``,c=n.type||``,u=n.structure||``,d=n.oneway,f=n.layer,p=n.iso_3166_1||``,m=n.iso_3166_2||``,h=e=>!(e==null||e===``||typeof e==`string`&&e.toLowerCase()===`none`),g=[];h(s)&&g.push(`
|
|
2
2
|
<div class="road-highlight-popup__row">
|
|
3
3
|
<span>道路类型:</span>
|
|
4
4
|
<span class="road-highlight-popup__value">${w(s)}</span>
|