@taichina/map-sdk 1.0.5 → 1.0.7

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.
@@ -1,10 +1,15 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`maplibre-gl`),require(`@turf/bbox`),require(`@turf/nearest-point-on-line`)):typeof define==`function`&&define.amd?define([`exports`,`maplibre-gl`,`@turf/bbox`,`@turf/nearest-point-on-line`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.TeeeMapSDK={},e.maplibregl,e.turfBbox,e.turfNearestPointOnLine))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var i=Object.create,a=Object.defineProperty,o=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,c=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty,u=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=s(t),c=0,u=i.length,d;c<u;c++)d=i[c],!l.call(e,d)&&d!==n&&a(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=o(t,d))||r.enumerable});return e},d=(e,t,n)=>(n=e==null?{}:i(c(e)),u(t||!e||!e.__esModule?a(n,`default`,{value:e,enumerable:!0}):n,e));t=d(t,1),n=d(n,1);var f=async()=>{let e=document.createElement(`canvas`);e.width=25,e.height=17;let t=e.getContext(`2d`);if(!t)throw Error(`无法获取 Canvas 上下文`);t.rect(0,0,e.width,e.height),t.fillStyle=`rgba(0, 0, 0, 0)`,t.fill(),t.strokeStyle=`red`,t.lineWidth=3,t.stroke();let n=new Image;return n.src=e.toDataURL(),new Promise((e,t)=>{n.onload=()=>e(n),n.onerror=()=>t(Error(`Failed to load redBoxIcon image`))})},p=async()=>{let e=document.createElement(`canvas`);e.width=64,e.height=64;let t=e.getContext(`2d`);if(!t)throw Error(`无法获取 Canvas 上下文`);let n=e.width/2,r=e.height/2;t.beginPath(),t.arc(n,r,20,0,Math.PI*2),t.fillStyle=`rgba(0, 0, 0, 0)`,t.fill(),t.strokeStyle=`#ffffff`,t.lineWidth=3,t.setLineDash([6,6]),t.lineCap=`round`,t.lineJoin=`round`,t.stroke();let i=new Image;return i.src=e.toDataURL(),new Promise((e,t)=>{i.onload=()=>e(i),i.onerror=()=>t(Error(`Failed to load dashCircle image`))})},m=async(e=`h`,t=`r`,n=``,r=``)=>{let i=e===`h`,a=t===`r`,o=`transparent`,s=n||o,c=r||o,l=27*.5,u=3*1.75,d=i?27*1.25:27,f=12*1.2,p=3+(i?f:0)+54+u,m=d+l,h=document.createElement(`canvas`);h.width=p,h.height=m;let g=h.getContext(`2d`);if(!g)throw Error(`无法获取 Canvas 上下文`);g.clearRect(0,0,p,m),g.save(),a||(g.translate(p/2,m/2),g.scale(1,-1),g.translate(-p/2,-m/2)),g.strokeStyle=`rgb(255,255,255)`,g.fillStyle=`rgb(255,255,255)`,3/2-u/2+5;let _=m-l;g.beginPath(),g.rect(3.875,_,u,l),g.fill(),g.beginPath(),g.lineWidth=3;let v=6.5,ee=m-l-d,te=m-l;g.moveTo(v,ee),g.lineTo(v,te),g.stroke(),g.lineWidth=2;let y=ee+27/2,b=16+(i?f:0)+5,ne=b+27-1;if(g.beginPath(),g.strokeStyle=`rgb(255,255,255)`,g.lineWidth=2,g.fillStyle=s,g.arc(b,y,12,0,Math.PI*2),g.fill(),g.stroke(),g.beginPath(),g.strokeStyle=`rgb(255,255,255)`,g.lineWidth=2,g.fillStyle=c,g.arc(ne,y,12,0,Math.PI*2),g.fill(),g.stroke(),i){g.beginPath(),g.lineWidth=2,g.strokeStyle=`rgb(255,255,255)`,v+3/2;let e=b-12-2/2,t=y;g.moveTo(8,t),g.lineTo(e,t),g.stroke()}g.restore();let x=new Image;return x.src=h.toDataURL(),new Promise((e,t)=>{x.onload=()=>e(x),x.onerror=t})},h=async(e=`h`,t=`r`)=>{let n=e===`h`,r=t===`r`,i=12*1.2,a=27*.5,o=n?27*1.25:27,s=3+(n?i:0)+54+5.25+8,c=o+a+8,l=document.createElement(`canvas`);l.width=s,l.height=c;let u=l.getContext(`2d`);if(!u)throw Error(`无法获取 Canvas 上下文`);u.clearRect(0,0,s,c),u.save(),r||(u.translate(s/2,c/2),u.scale(1,-1),u.translate(-s/2,-c/2));let d=c-a-o-4+27/2,f=16+(n?i:0)+4+27,p=1.5,m=f+12+4*1.5,h=d-12,g=d+12+8;u.beginPath(),u.setLineDash([8,8]),u.strokeStyle=`#ffffff`,u.lineWidth=3,u.rect(p,h,m-p,g-h),u.stroke(),u.restore();let _=new Image;return _.src=l.toDataURL(),new Promise((e,t)=>{_.onload=()=>e(_),_.onerror=t})},g=async(e=`h`,t=`r`,n=!0)=>{let r=e===`h`,i=t===`r`,a=12*1.2,o=27*.5,s=r?27*1.25:27,c=3+(r?a:0)+54+5.25,l=s+o,u=document.createElement(`canvas`);u.width=c,u.height=l;let d=u.getContext(`2d`);if(!d)throw Error(`无法获取 Canvas 上下文`);d.clearRect(0,0,c,l),d.save(),i||(d.translate(c/2,l/2),d.scale(1,-1),d.translate(-c/2,-l/2));let f=l-o-s+27/2,p=16+(r?a:0)+5,m=p+27;d.lineWidth=4,d.strokeStyle=`#ff0000`,n&&(d.beginPath(),d.moveTo(p-12,f-12),d.lineTo(p+12,f+12),d.moveTo(p+12,f-12),d.lineTo(p-12,f+12),d.stroke()),n&&(d.beginPath(),d.moveTo(m-12,f-12),d.lineTo(m+12,f+12),d.moveTo(m+12,f-12),d.lineTo(m-12,f+12),d.stroke()),d.restore();let h=new Image;return h.src=u.toDataURL(),new Promise((e,t)=>{h.onload=()=>e(h),h.onerror=t})},_=async(e=`h`,t=`r`,n,r)=>{let i=e===`h`,a=t===`r`,o=12*1.2,s=27*.5,c=i?27*1.25:27,l=3+(i?o:0)+54+5.25,u=c+s,d=document.createElement(`canvas`);d.width=l,d.height=u;let f=d.getContext(`2d`);if(!f)throw Error(`无法获取 Canvas 上下文`);f.clearRect(0,0,l,u),f.save(),a||(f.translate(l/2,u/2),f.scale(1,-1),f.translate(-l/2,-u/2));let p=u-s-c+27/2,m=16+(i?o:0)+27+5;f.save(),f.translate(m,p),f.fillStyle=n;let h=r?12:24;f.fillRect(-12,-12,h,24),r&&(f.fillStyle=r,f.fillRect(0,-12,12,24)),f.strokeStyle=`white`,f.lineWidth=2,f.strokeRect(-12,-12,24,24),f.restore(),f.restore();let g=new Image;return g.src=d.toDataURL(),new Promise((e,t)=>{g.onload=()=>e(g),g.onerror=t})},v=`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='1776081402940'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='9172'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='32'%20height='32'%3e%3cpath%20d='M675.84%20409.6v-102.4a163.84%20163.84%200%201%200-327.68%200v102.4h327.68z%20m-409.6%200v-102.4c0-135.72096%20110.03904-245.76%20245.76-245.76s245.76%20110.03904%20245.76%20245.76v102.4a81.92%2081.92%200%200%201%2081.92%2081.92v225.28c0%20135.72096-110.03904%20245.76-245.76%20245.76h-163.84c-135.72096%200-245.76-110.03904-245.76-245.76V491.52a81.92%2081.92%200%200%201%2081.92-81.92z%20m286.72%20348.16v-51.87584a40.96%2040.96%200%200%201%2014.19264-30.98624%2081.92%2081.92%200%201%200-113.07008-2.56c0.79872%200.79872%201.72032%201.6384%202.7648%202.56A40.96%2040.96%200%200%201%20471.04%20705.88416V757.76a40.96%2040.96%200%201%200%2081.92%200z'%20p-id='9173'%20fill='%23ffffff'%3e%3c/path%3e%3c/svg%3e`,ee=`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='1781252097660'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='13038'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='32'%20height='32'%3e%3cpath%20d='M725.333333%2085.333333a128%20128%200%200%201%20127.786667%20120.490667L853.333333%20213.333333v597.333334a128%20128%200%200%201-120.490666%20127.786666L725.333333%20938.666667h-75.904a32.170667%2032.170667%200%200%200-2.645333-5.674667l-158.464-309.333333-1.706667-2.432%2034.816-121.770667%200.298667-1.408%2013.568%2037.632%202.858667%206.826667c7.253333%2015.573333%2019.456%2028.458667%2034.730666%2036.565333l84.053334%2044.672%203.925333%201.792a32%2032%200%200%200%2026.112-58.282667l-84.053333-44.672-2.389334-1.621333a15.786667%2015.786667%200%200%201-5.034666-6.954667l-23.168-64.384-2.56-6.229333a78.762667%2078.762667%200%200%200-54.613334-43.946667l-3.285333-0.768-7.765333-1.28a80%2080%200%200%200-58.282667%2016.042667L360.96%20478.805333l-5.205333%204.352a79.786667%2079.786667%200%200%200-21.76%2033.450667l-33.792%20100.693333-1.109334%204.266667a32%2032%200%200%200%2061.781334%2016.128l33.792-100.693333%201.28-2.858667a15.786667%2015.786667%200%200%201%204.053333-4.693333l59.306667-45.653334-40.277334%20140.928-1.706666%207.253334c-0.896%204.864-1.365333%209.813333-1.365334%2014.762666v122.666667l-0.298666%203.114667a16%2016%200%200%201-4.394667%208.192l-103.253333%20145.493333-3.072%203.584a31.786667%2031.786667%200%200%200-4.693334%208.874667H298.666667a128%20128%200%200%201-127.786667-120.490667L170.666667%20810.666667V213.333333a128%20128%200%200%201%20120.490666-127.786666L298.666667%2085.333333h426.666666z%20m-245.333333%20662.101334L577.877333%20938.666667h-201.386666l79.914666-112.597334%204.778667-5.205333c12.074667-14.336%2018.773333-32.554667%2018.773333-51.456v-21.973333zM549.546667%20230.656a74.666667%2074.666667%200%201%200%200%20149.333333%2074.666667%2074.666667%200%200%200%200-149.333333z'%20fill='%2336a83e'%20p-id='13039'%3e%3c/path%3e%3c/svg%3e`,te=`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='1781252097660'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='13038'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='32'%20height='32'%3e%3cpath%20d='M725.333333%2085.333333a128%20128%200%200%201%20127.786667%20120.490667L853.333333%20213.333333v597.333334a128%20128%200%200%201-120.490666%20127.786666L725.333333%20938.666667h-75.904a32.170667%2032.170667%200%200%200-2.645333-5.674667l-158.464-309.333333-1.706667-2.432%2034.816-121.770667%200.298667-1.408%2013.568%2037.632%202.858667%206.826667c7.253333%2015.573333%2019.456%2028.458667%2034.730666%2036.565333l84.053334%2044.672%203.925333%201.792a32%2032%200%200%200%2026.112-58.282667l-84.053333-44.672-2.389334-1.621333a15.786667%2015.786667%200%200%201-5.034666-6.954667l-23.168-64.384-2.56-6.229333a78.762667%2078.762667%200%200%200-54.613334-43.946667l-3.285333-0.768-7.765333-1.28a80%2080%200%200%200-58.282667%2016.042667L360.96%20478.805333l-5.205333%204.352a79.786667%2079.786667%200%200%200-21.76%2033.450667l-33.792%20100.693333-1.109334%204.266667a32%2032%200%200%200%2061.781334%2016.128l33.792-100.693333%201.28-2.858667a15.786667%2015.786667%200%200%201%204.053333-4.693333l59.306667-45.653334-40.277334%20140.928-1.706666%207.253334c-0.896%204.864-1.365333%209.813333-1.365334%2014.762666v122.666667l-0.298666%203.114667a16%2016%200%200%201-4.394667%208.192l-103.253333%20145.493333-3.072%203.584a31.786667%2031.786667%200%200%200-4.693334%208.874667H298.666667a128%20128%200%200%201-127.786667-120.490667L170.666667%20810.666667V213.333333a128%20128%200%200%201%20120.490666-127.786666L298.666667%2085.333333h426.666666z%20m-245.333333%20662.101334L577.877333%20938.666667h-201.386666l79.914666-112.597334%204.778667-5.205333c12.074667-14.336%2018.773333-32.554667%2018.773333-51.456v-21.973333zM549.546667%20230.656a74.666667%2074.666667%200%201%200%200%20149.333333%2074.666667%2074.666667%200%200%200%200-149.333333z'%20fill='%23b92511'%20p-id='13039'%3e%3c/path%3e%3c/svg%3e`,y=`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='1781416346105'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='55023'%20width='32'%20height='32'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3cpath%20d='M725.333333%2085.333333a128%20128%200%200%201%20127.786667%20120.490667L853.333333%20213.333333v597.333334a128%20128%200%200%201-120.490666%20127.786666L725.333333%20938.666667h-75.904a32.170667%2032.170667%200%200%200-2.645333-5.674667l-158.464-309.333333-1.706667-2.432%2034.816-121.770667%200.298667-1.408%2013.568%2037.632%202.858667%206.826667c7.253333%2015.573333%2019.456%2028.458667%2034.730666%2036.565333l84.053334%2044.672%203.925333%201.792a32%2032%200%200%200%2026.112-58.282667l-84.053333-44.672-2.389334-1.621333a15.786667%2015.786667%200%200%201-5.034666-6.954667l-23.168-64.384-2.56-6.229333a78.762667%2078.762667%200%200%200-54.613334-43.946667l-3.285333-0.768-7.765333-1.28a80%2080%200%200%200-58.282667%2016.042667L360.96%20478.805333l-5.205333%204.352a79.786667%2079.786667%200%200%200-21.76%2033.450667l-33.792%20100.693333-1.109334%204.266667a32%2032%200%200%200%2061.781334%2016.128l33.792-100.693333%201.28-2.858667a15.786667%2015.786667%200%200%201%204.053333-4.693333l59.306667-45.653334-40.277334%20140.928-1.706666%207.253334c-0.896%204.864-1.365333%209.813333-1.365334%2014.762666v122.666667l-0.298666%203.114667a16%2016%200%200%201-4.394667%208.192l-103.253333%20145.493333-3.072%203.584a31.786667%2031.786667%200%200%200-4.693334%208.874667H298.666667a128%20128%200%200%201-127.786667-120.490667L170.666667%20810.666667V213.333333a128%20128%200%200%201%20120.490666-127.786666L298.666667%2085.333333h426.666666z%20m-245.333333%20662.101334L577.877333%20938.666667h-201.386666l79.914666-112.597334%204.778667-5.205333c12.074667-14.336%2018.773333-32.554667%2018.773333-51.456v-21.973333zM549.546667%20230.656a74.666667%2074.666667%200%201%200%200%20149.333333%2074.666667%2074.666667%200%200%200%200-149.333333z'%20fill='%23bfbfbf'%20p-id='55024'%3e%3c/path%3e%3c/svg%3e`,b={BASE_COLOR:`rgb(85,120,182)`,BG_COLOR:`rgb(0,0,0)`},ne=(e,t,n)=>{let r=document.createElement(`canvas`);r.width=66,r.height=64;let i=r.getContext(`2d`);return i?(i.clearRect(0,0,r.width,r.height),n===2&&(i.translate(66,0),i.scale(-1,1)),e===1?(i.beginPath(),i.arc(46,20,20-4/2,0,Math.PI*2),i.fillStyle=t||`rgb(255,255,255,0)`,i.strokeStyle=t||b.BASE_COLOR,i.lineWidth=4,i.fill(),i.stroke(),i.beginPath(),i.moveTo(6,40/2),i.lineTo(26,40/2),i.lineWidth=4,i.strokeStyle=b.BASE_COLOR,i.stroke(),i.beginPath(),i.lineCap=`round`,i.moveTo(8/2,0),i.lineTo(8/2,40),i.lineWidth=4,i.strokeStyle=b.BASE_COLOR,i.stroke(),i.beginPath(),i.moveTo(8/2,40),i.lineTo(8/2,64),i.lineWidth=8,i.strokeStyle=b.BASE_COLOR,i.stroke(),r):(i.beginPath(),i.arc(26,20,20-4/2,0,Math.PI*2),i.fillStyle=t||`rgb(255,255,255,0)`,i.strokeStyle=t||b.BASE_COLOR,i.lineWidth=4,i.fill(),i.stroke(),i.beginPath(),i.lineCap=`round`,i.moveTo(8/2,0),i.lineTo(8/2,40),i.lineWidth=4,i.strokeStyle=b.BASE_COLOR,i.stroke(),i.beginPath(),i.moveTo(8/2,40),i.lineTo(8/2,64),i.lineWidth=8,i.strokeStyle=b.BASE_COLOR,i.stroke(),r)):r},x=()=>{let e=document.createElement(`canvas`);e.width=24,e.height=64;let t=e.getContext(`2d`);return t?(t.fillStyle=b.BG_COLOR,t.fillRect(0,0,24,64),t.strokeStyle=b.BASE_COLOR,t.lineWidth=8,t.strokeRect(0,0,24,64),e):e},S=()=>{let e=document.createElement(`canvas`);e.width=15,e.height=40;let t=e.getContext(`2d`);return t?(t.clearRect(0,0,e.width,e.height),t.beginPath(),t.moveTo(0,4/2),t.lineTo(15-4/2,4/2),t.moveTo(4/2,4/2),t.lineTo(4/2,36),t.moveTo(0,36),t.lineTo(15-4/2,36),t.lineWidth=4,t.strokeStyle=b.BASE_COLOR,t.stroke(),e):e},re=async(e=`h`,t=`r`,n=``)=>{let r=ne(e==`h`?1:2,n,t==`l`?1:2),i=new Image;return i.src=r.toDataURL(),new Promise((e,t)=>{i.onload=()=>e(i),i.onerror=t})},ie=async()=>{let e=x(),t=new Image;return t.src=e.toDataURL(),new Promise((e,n)=>{t.onload=()=>e(t),t.onerror=n})},ae=async()=>{let e=S(),t=new Image;return t.src=e.toDataURL(),new Promise((e,n)=>{t.onload=()=>e(t),t.onerror=n})},C=function(e){return e.Blue=`blue`,e.Green=`green`,e.Red=`red`,e.Yellow=`yellow`,e.Gray=`gray`,e.Purple=`purple`,e.Red_Purple=`red-purple`,e}({}),w=function(e){return e.Red=`red`,e.Red_Yellow=`red-yellow`,e.Yellow=`yellow`,e.Yellow_Yellow=`yellow-yellow`,e.Yellow_Green=`yellow-green`,e.Green=`green`,e.Blue=`blue`,e.White=`white`,e}({}),oe=async()=>{let[e,t,n,r]=await Promise.all([re(`h`,`r`,``),re(`h`,`l`,``),re(`l`,`r`,``),re(`l`,`l`,``)]),i=new Image;i.src=v;let a=new Image;a.src=te;let o=new Image;o.src=ee;let s=new Image;s.src=y;let[c,l,u]=await Promise.all([ae(),f(),p()]),[d,b,ne,x]=await Promise.all([m(`h`,`r`,``),m(`h`,`l`,``),m(`l`,`r`,``),m(`l`,`l`,``)]),[S,oe,T,se]=await Promise.all([h(`h`,`r`),h(`h`,`l`),h(`l`,`r`),h(`l`,`l`)]),[ce,le,ue,de]=await Promise.all([g(`h`,`r`),g(`h`,`l`),g(`l`,`r`),g(`l`,`l`)]),fe=[`h`,`l`],pe=[`r`,`l`],me=[C.Blue,C.Green,C.Red,C.Yellow,C.Gray,C.Purple,C.Red_Purple],he=fe.flatMap(e=>pe.flatMap(t=>me.map(n=>({height:e,dir:t,color:n})))),ge=await Promise.all(he.map(({height:e,dir:t,color:n})=>_(e,t,n===C.Red_Purple?`red`:n,n===C.Red_Purple?`purple`:void 0))),_e=[w.Red,w.Red_Yellow,w.Yellow,w.Yellow_Yellow,w.Yellow_Green,w.Green,w.Blue,w.White],E=fe.flatMap(e=>pe.flatMap(t=>_e.map(n=>({height:e,dir:t,color:n})))),ve=await Promise.all(E.map(({height:e,dir:t,color:n})=>{let r=n,i;return n===w.Red_Yellow?(r=`red`,i=`yellow`):n===w.Yellow_Yellow?(r=`yellow`,i=`yellow`):n===w.Yellow_Green&&(r=`yellow`,i=`green`),m(e,t,r,i)})),ye=[w.Red,w.Green,w.White,w.Blue],be=fe.flatMap(e=>pe.flatMap(t=>ye.map(n=>({height:e,dir:t,color:n})))),xe=await Promise.all(be.map(({height:e,dir:t,color:n})=>re(e,t,n))),Se=await ie();return[{id:`icon-door-open`,image:o},{id:`icon-door-close`,image:a},{id:`icon-door-none`,image:s},{id:`icon-signal-h-r`,image:e},{id:`icon-signal-h-l`,image:t},{id:`icon-signal-l-r`,image:n},{id:`icon-signal-l-l`,image:r},{id:`icon-lock`,image:i},{id:`icon-bumper`,image:c},{id:`icon-red-box`,image:l},{id:`icon-dash-circle`,image:u},{id:`icon-ctc-signal-h-r`,image:d},{id:`icon-ctc-signal-h-l`,image:b},{id:`icon-ctc-signal-l-r`,image:ne},{id:`icon-ctc-signal-l-l`,image:x},{id:`icon-ctc-box-h-r`,image:S},{id:`icon-ctc-box-h-l`,image:oe},{id:`icon-ctc-box-l-r`,image:T},{id:`icon-ctc-box-l-l`,image:se},{id:`icon-ctc-x-h-r`,image:ce},{id:`icon-ctc-x-h-l`,image:le},{id:`icon-ctc-x-l-r`,image:ue},{id:`icon-ctc-x-l-l`,image:de},{id:`icon-jcw`,image:Se},...ge.map((e,t)=>{let n=he[t];return{id:`icon-ctc-s-${n.height}-${n.dir}-${n.color}`,image:e}}),...ve.map((e,t)=>{let n=E[t];return{id:`icon-ctc-signal-${n.height}-${n.dir}-${n.color}`,image:e}}),...xe.map((e,t)=>{let n=be[t];return{id:`icon-signal-${n.height}-${n.dir}-${n.color}`,image:e}})]},T={geojson:e=>({type:`geojson`,data:e||{type:`FeatureCollection`,features:[]},promoteId:`code`}),raster:e=>({type:`raster`,tiles:[e],scheme:`tms`,tileSize:256}),graph:e=>({type:`vector`,tiles:[e],scheme:`tms`,promoteId:`code`}),geom:e=>({type:`vector`,tiles:[e],scheme:`tms`,promoteId:`code`}),image:(e,t)=>({type:`image`,url:e,coordinates:t}),video:(e,t)=>({type:`video`,urls:e,coordinates:t}),canvas:(e,t)=>({type:`canvas`,canvas:e,coordinates:t}),mbtiles:e=>({type:`vector`,tiles:[e]})},se={background:(e,t)=>({id:`${e.id}_${t}`,type:`background`,paint:{"background-color":`#131212`}}),track:(e,t)=>[{id:`${e.id}_${t}_lock`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`#a7009e`,"line-width":3,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`1`],1,0]}},{id:`${e.id}_${t}_lock_icon`,type:`symbol`,source:e.id,"source-layer":t,layout:{"symbol-placement":`line-center`,"icon-anchor":`top`,"icon-image":`icon-lock`,"icon-size":[`interpolate`,[`exponential`,2],[`zoom`],12,.2,15,.5,16,.6,17,.8],"icon-offset":[0,5],"icon-allow-overlap":!0,"icon-rotation-alignment":`viewport`,"icon-rotate":0},paint:{"icon-opacity":[`case`,[`==`,[`feature-state`,`state`],`1`],1,0]}},{id:`${e.id}_${t}_poweroff_border`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`green`,"line-width":9,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e.id}_${t}_poweroff_fill`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`black`,"line-width":6,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e.id}_${t}_catenery_border`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`grey`,"line-width":9,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`3`],1,0]}},{id:`${e.id}_${t}_catenery_fill`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`black`,"line-width":6,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`3`],1,0]}},{id:`${e.id}_${t}_select_border`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`#ffffff`,"line-dasharray":[.5,.5],"line-width":9,"line-opacity":[`case`,[`==`,[`feature-state`,`select`],!0],1,0]}},{id:`${e.id}_${t}_hitarea`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`black`,"line-width":6,"line-opacity":[`case`,[`==`,[`feature-state`,`select`],!0],1,0]}},{id:`${e.id}_${t}`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`#85A0D9`,"line-width":2}}],track_circuit:(e,t)=>[{id:`${e.id}_${t}_poweroff_border`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`green`,"line-width":9,"line-opacity":[`case`,[`==`,[`feature-state`,`subState1`],`1`],1,0]}},{id:`${e.id}_${t}_poweroff_fill`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`black`,"line-width":6,"line-opacity":[`case`,[`==`,[`feature-state`,`subState1`],`1`],1,0]}},{id:`${e.id}_${t}_select_border`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`#ffffff`,"line-dasharray":[.4,.4],"line-width":9,"line-opacity":[`case`,[`==`,[`feature-state`,`select`],!0],1,0]}},{id:`${e.id}_${t}_hitarea`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`black`,"line-width":6,"line-opacity":[`case`,[`==`,[`feature-state`,`select`],!0],1,0]}},{id:`${e.id}_${t}`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`grey`,"line-width":3}},{id:`${e.id}_${t}_red`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`red`,"line-width":3,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`1`],1,0]}},{id:`${e.id}_${t}_white`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`white`,"line-width":3,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e.id}_${t}_grey`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`,visibility:`none`},paint:{"line-color":`grey`,"line-width":3,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`3`],1,0]}},{id:`${e.id}_${t}_subpath`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`burlywood`,"line-width":3,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`4`],1,0]}},{id:`${e.id}_${t}_mainpath`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`white`,"line-width":3,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`5`],1,0]}},{id:`${e.id}_${t}_cable_hover`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`red`,"line-width":3,"line-opacity":[`case`,[`==`,[`feature-state`,`subState1`],`1`],1,0]}},{id:`${e.id}_${t}_cable`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`red`,"line-width":3,"line-opacity":[`case`,[`==`,[`feature-state`,`subState2`],`1`],1,0]}}],signal:(e,t)=>{let n=[`interpolate`,[`exponential`,2],[`zoom`],12,.2,16,.6,18,.8,20,1.5],r=[];[C.Blue,C.Green,C.Red,C.Yellow,C.Gray,C.Purple,C.Red_Purple].forEach(i=>{r.push({id:`${e.id}_${t}_square_${i}`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":[`case`,[`==`,[`get`,`inst_type`],1],[`case`,[`==`,[`get`,`posi_side`],1],`icon-ctc-s-h-r-${i}`,`icon-ctc-s-h-l-${i}`],[`case`,[`==`,[`get`,`posi_side`],1],`icon-ctc-s-l-r-${i}`,`icon-ctc-s-l-l-${i}`]],"icon-size":n,"icon-rotate":[`+`,[`to-number`,[`get`,`angle`]],90],"icon-allow-overlap":!0,"icon-anchor":[`case`,[`==`,[`get`,`posi_side`],1],`bottom-right`,`top-right`]},paint:{"icon-opacity":[`case`,[`all`,[`==`,[`feature-state`,`subState1`],i],[`!=`,[`feature-state`,`visiable`],!1]],1,0]}})});let i=[];return[w.Red,w.Red_Yellow,w.Yellow,w.Yellow_Yellow,w.Yellow_Green,w.Green,w.Blue,w.White].forEach(r=>{i.push({id:`${e.id}_${t}_${r}`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":[`case`,[`==`,[`get`,`inst_type`],1],[`case`,[`==`,[`get`,`posi_side`],1],`icon-ctc-signal-h-r-${r}`,`icon-ctc-signal-h-l-${r}`],[`case`,[`==`,[`get`,`posi_side`],1],`icon-ctc-signal-l-r-${r}`,`icon-ctc-signal-l-l-${r}`]],"icon-size":n,"icon-rotate":[`+`,[`to-number`,[`get`,`angle`]],90],"icon-allow-overlap":!0,"icon-anchor":[`case`,[`==`,[`get`,`posi_side`],1],`bottom-left`,`top-left`]},paint:{"icon-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],r],[`!=`,[`feature-state`,`visiable`],!1]],1,0]}})}),[...i,{id:`${e.id}_${t}`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":[`case`,[`==`,[`get`,`inst_type`],1],[`case`,[`==`,[`get`,`posi_side`],1],`icon-ctc-signal-h-r`,`icon-ctc-signal-h-l`],[`case`,[`==`,[`get`,`posi_side`],1],`icon-ctc-signal-l-r`,`icon-ctc-signal-l-l`]],"icon-size":n,"icon-rotate":[`+`,[`to-number`,[`get`,`angle`]],90],"icon-allow-overlap":!0,"icon-anchor":[`case`,[`==`,[`get`,`posi_side`],1],`bottom-left`,`top-left`]},paint:{"icon-opacity":[`case`,[`!=`,[`feature-state`,`visiable`],!1],1,0]}},{id:`${e.id}_${t}_box`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":[`case`,[`==`,[`get`,`inst_type`],1],[`case`,[`==`,[`get`,`posi_side`],1],`icon-ctc-box-h-r`,`icon-ctc-box-h-l`],[`case`,[`==`,[`get`,`posi_side`],1],`icon-ctc-box-l-r`,`icon-ctc-box-l-l`]],"icon-size":n,"icon-rotate":[`+`,[`to-number`,[`get`,`angle`]],90],"icon-allow-overlap":!0,"icon-anchor":[`case`,[`==`,[`get`,`posi_side`],1],`bottom-left`,`top-left`]},paint:{"icon-opacity":[`case`,[`all`,[`==`,[`feature-state`,`select`],!0],[`!=`,[`feature-state`,`visiable`],!1]],1,0]}},{id:`${e.id}_${t}_x`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":[`case`,[`==`,[`get`,`inst_type`],1],[`case`,[`==`,[`get`,`posi_side`],1],`icon-ctc-x-h-r`,`icon-ctc-x-h-l`],[`case`,[`==`,[`get`,`posi_side`],1],`icon-ctc-x-l-r`,`icon-ctc-x-l-l`]],"icon-size":n,"icon-rotate":[`+`,[`to-number`,[`get`,`angle`]],90],"icon-allow-overlap":!0,"icon-anchor":[`case`,[`==`,[`get`,`posi_side`],1],`bottom-left`,`top-left`]},paint:{"icon-opacity":[`case`,[`all`,[`==`,[`feature-state`,`subState2`],`off`],[`!=`,[`feature-state`,`visiable`],!1]],1,0]}},...r]},bumper:(e,t)=>({id:`${e.id}_${t}`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":`icon-bumper`,"icon-size":.3,"icon-allow-overlap":!0},paint:{"icon-opacity":0}}),switch:(e,t)=>[{id:`${e.id}_${t}_hitarea`,type:`circle`,source:e.id,"source-layer":t,paint:{"circle-radius":[`interpolate`,[`linear`],[`zoom`],5,11],"circle-color":`red`,"circle-opacity":0}},{id:`${e.id}_${t}_dash_circle`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":`icon-dash-circle`,"icon-allow-overlap":!0,"icon-size":[`interpolate`,[`linear`],[`zoom`],17,.5]},paint:{"icon-opacity":[`case`,[`==`,[`feature-state`,`select`],!0],1,0]}},{id:`${e.id}_${t}_text`,type:`symbol`,source:e.id,"source-layer":t,layout:{"text-field":[`get`,`name`],"text-size":[`interpolate`,[`linear`],[`zoom`],15,11,22,15],"text-font":[`Open Sans Regular`],"text-anchor":`top`,"text-offset":[0,.5],"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":[`match`,[`feature-state`,`state`],`2`,`lightgreen`,`3`,`yellow`,`4`,`red`,`white`]}},{id:`${e.id}_${t}_lock`,type:`circle`,source:e.id,"source-layer":t,layout:{visibility:`visible`},paint:{"circle-radius":[`interpolate`,[`linear`],[`zoom`],5,8],"circle-stroke-width":1.7,"circle-stroke-color":[`match`,[`feature-state`,`state`],`2`,`green`,`3`,`yellow`,`4`,`red`,`white`],"circle-color":`transparent`,"circle-stroke-opacity":[`case`,[`==`,[`feature-state`,`subState2`],`1`],1,0]}},{id:`${e.id}_${t}_danfen`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":`icon-red-box`,"icon-allow-overlap":!0,"icon-offset":[0,15],"icon-size":[`interpolate`,[`linear`],[`zoom`],5,.2,10,.5,18,1]},paint:{"icon-opacity":[`case`,[`==`,[`feature-state`,`subState3`],`1`],1,0]}}],switch_loc:(e,t)=>[{id:`${e.id}_${t}`,type:`line`,source:e.id,"source-layer":t,paint:{"line-width":5,"line-color":`#000000`}},{id:`${e.id}_${t}_normal`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`2`]],paint:{"line-width":4,"line-color":`green`,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e.id}_${t}_reverse`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`3`]],paint:{"line-width":4,"line-color":`yellow`,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`3`],1,0]}},{id:`${e.id}_${t}_fourway`,type:`line`,source:e.id,"source-layer":t,paint:{"line-width":4,"line-color":`#000000`,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`4`],1,0]}},{id:`${e.id}_${t}_normal_white`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`2`]],paint:{"line-width":4,"line-color":`white`,"line-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],`2`],[`==`,[`feature-state`,`subState1`],`2`]],1,0]}},{id:`${e.id}_${t}_reverse_white`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`3`]],paint:{"line-width":4,"line-color":`white`,"line-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],`3`],[`==`,[`feature-state`,`subState1`],`2`]],1,0]}},{id:`${e.id}_${t}_normal_red`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`2`]],paint:{"line-width":4,"line-color":`red`,"line-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],`2`],[`==`,[`feature-state`,`subState1`],`3`]],1,0]}},{id:`${e.id}_${t}_reverse_red`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`3`]],paint:{"line-width":4,"line-color":`red`,"line-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],`3`],[`==`,[`feature-state`,`subState1`],`3`]],1,0]}}],insulation:(e,t)=>{let n=[`interpolate`,[`exponential`,2],[`zoom`],12,1,15,1.5,16,2,17,4];return{id:`${e.id}_${t}`,type:`circle`,source:e.id,"source-layer":t,filter:[`!=`,[`get`,`category`],2],paint:{"circle-radius":n,"circle-stroke-width":n,"circle-stroke-color":`#ffbb00`},layout:{visibility:`none`}}},label:(e,t)=>({id:`${e.id}_${t}`,type:`symbol`,source:e.id,"source-layer":t,filter:[`!=`,[`get`,`category`],2],layout:{"text-field":[`get`,`name`],"text-size":[`interpolate`,[`linear`],[`zoom`],15,[`case`,[`==`,[`get`,`category`],50],10,[`==`,[`get`,`category`],96],8,7],22,[`case`,[`==`,[`get`,`category`],50],16,[`==`,[`get`,`category`],96],12,13]],"text-font":[`Open Sans Regular`],"text-anchor":[`case`,[`==`,[`get`,`angle`],90],`bottom-left`,`top-right`],"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":`#C0C33F`}}),prevention:(e,t)=>[{id:`${e.id}_${t}_circle`,type:`circle`,source:e.id,"source-layer":t,filter:[`match`,[`to-string`,[`get`,`uc_oob_type`]],[`2`,`8`,`20`,`87`],!0,!1],paint:{"circle-radius":[`interpolate`,[`exponential`,2],[`zoom`],10,3,20,10],"circle-stroke-width":2,"circle-stroke-color":`red`},layout:{visibility:`none`}},{id:`${e.id}_${t}_text`,type:`symbol`,source:e.id,"source-layer":t,filter:[`match`,[`to-string`,[`get`,`uc_oob_type`]],[`2`,`8`,`20`,`87`],!0,!1],layout:{"text-field":[`case`,[`==`,[`to-string`,[`get`,`uc_oob_type`]],`2`],`网`,[`==`,[`to-string`,[`get`,`uc_oob_type`]],`8`],`停`,[`==`,[`to-string`,[`get`,`uc_oob_type`]],`20`],`界`,`门`],"text-font":[`Open Sans Regular`],"text-size":[`interpolate`,[`linear`],[`zoom`],10,2,20,12],"text-anchor":`center`,"symbol-placement":`point`,"text-allow-overlap":!0,visibility:`none`},paint:{"text-color":`white`}}],sgfhqy:(e,t)=>{let n=[`interpolate`,[`exponential`,2],[`zoom`],12,.2,14,.8,16,1.4,18,1.8];return[{id:`${e.id}_${t}_fill`,type:`fill`,source:e.id,"source-layer":t,filter:[`==`,[`geometry-type`],`Polygon`],layout:{visibility:`visible`},paint:{"fill-color":`#9ccc8ac0`,"fill-opacity":.4}},{id:`${e.id}_${t}_fill_outline`,type:`line`,source:e.id,"source-layer":t,filter:[`==`,[`geometry-type`],`Polygon`],layout:{visibility:`visible`},paint:{"line-color":`#131212`,"line-width":[`interpolate`,[`linear`],[`zoom`],14,1,15,3,16,8]}},{id:`${e.id}_${t}_line`,type:`line`,source:e.id,"source-layer":t,filter:[`==`,[`geometry-type`],`LineString`],layout:{visibility:`visible`},paint:{"line-color":`#00ff00`,"line-width":2,"line-dasharray":[4,2]}},{id:`${e.id}_${t}_door_dot`,type:`circle`,source:e.id,"source-layer":t,filter:[`==`,[`geometry-type`],`Point`],layout:{visibility:`visible`},paint:{"circle-radius":4,"circle-color":`#999999`,"circle-stroke-width":1.5,"circle-stroke-color":`#fff`}},{id:`${e.id}_${t}_door_dot_open`,type:`circle`,source:e.id,"source-layer":t,filter:[`==`,[`geometry-type`],`Point`],layout:{visibility:`visible`},paint:{"circle-radius":4,"circle-color":`#00ff00`,"circle-stroke-width":1.5,"circle-stroke-color":`#fff`,"circle-opacity":[`case`,[`any`,[`==`,[`feature-state`,`state`],`1`],[`==`,[`feature-state`,`state`],`3`]],1,0]}},{id:`${e.id}_${t}_door_dot_close`,type:`circle`,source:e.id,"source-layer":t,filter:[`==`,[`geometry-type`],`Point`],layout:{visibility:`visible`},paint:{"circle-radius":4,"circle-color":`#ff0000`,"circle-stroke-width":1.5,"circle-stroke-color":`#fff`,"circle-opacity":[`case`,[`any`,[`==`,[`feature-state`,`state`],`2`],[`==`,[`feature-state`,`state`],`4`]],1,0]}},{id:`${e.id}_${t}_door`,type:`symbol`,source:e.id,"source-layer":t,filter:[`==`,[`geometry-type`],`Point`],layout:{visibility:`visible`,"icon-image":`icon-door-none`,"icon-size":n,"icon-allow-overlap":!0,"icon-anchor":`top`,"text-field":[`get`,`name`],"text-anchor":`top-left`,"text-offset":[1.5,1],"text-size":13,"text-allow-overlap":!0},paint:{"text-color":`#999999`}},{id:`${e.id}_${t}_door_open`,type:`symbol`,source:e.id,"source-layer":t,filter:[`==`,[`geometry-type`],`Point`],layout:{visibility:`visible`,"icon-image":`icon-door-open`,"icon-size":n,"icon-allow-overlap":!0,"icon-anchor":`top`,"text-field":[`get`,`name`],"text-anchor":`top-left`,"text-offset":[1.5,1],"text-size":13,"text-allow-overlap":!0},paint:{"text-color":`#00ff00`,"icon-opacity":[`case`,[`any`,[`==`,[`feature-state`,`state`],`1`],[`==`,[`feature-state`,`state`],`3`]],1,0],"text-opacity":[`case`,[`any`,[`==`,[`feature-state`,`state`],`1`],[`==`,[`feature-state`,`state`],`3`]],1,0]}},{id:`${e.id}_${t}_door_close`,type:`symbol`,source:e.id,"source-layer":t,filter:[`==`,[`geometry-type`],`Point`],layout:{visibility:`visible`,"icon-image":`icon-door-close`,"icon-size":n,"icon-allow-overlap":!0,"icon-anchor":`top`,"text-field":[`get`,`name`],"text-anchor":`top-left`,"text-offset":[1.5,1],"text-size":13,"text-allow-overlap":!0},paint:{"text-color":`#ff0000`,"icon-opacity":[`case`,[`any`,[`==`,[`feature-state`,`state`],`2`],[`==`,[`feature-state`,`state`],`4`]],1,0],"text-opacity":[`case`,[`any`,[`==`,[`feature-state`,`state`],`2`],[`==`,[`feature-state`,`state`],`4`]],1,0]}}]}},ce=e=>{let t=[];return e.layers.forEach((n,r)=>{let i=se[n],a=e.sourceLayers[r];if(i){let n=i(e,a);Array.isArray(n)?t.push(...n):t.push(n)}else console.warn(`图层 ${n} 尚未实现`)}),t},le=(e,t)=>({id:`${e.id}_${t}`,type:`background`,paint:{"background-color":`#131212`}}),ue=(e,t)=>[{id:`${e.id}_${t}_lock`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`#a7009e`,"line-width":3,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`1`],1,0]}},{id:`${e.id}_${t}_lock_icon`,type:`symbol`,source:e.id,"source-layer":t,layout:{"symbol-placement":`line-center`,"icon-anchor":`top`,"icon-image":`icon-lock`,"icon-size":[`interpolate`,[`exponential`,2],[`zoom`],12,.2,15,.5,16,.6,17,.8],"icon-offset":[0,5],"icon-allow-overlap":!0,"icon-rotation-alignment":`viewport`,"icon-rotate":0},paint:{"icon-opacity":[`case`,[`==`,[`feature-state`,`state`],`1`],1,0]}},{id:`${e.id}_${t}_poweroff_border`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`green`,"line-width":9,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e.id}_${t}_poweroff_fill`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`black`,"line-width":6,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e.id}_${t}_catenery_border`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`grey`,"line-width":9,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`3`],1,0]}},{id:`${e.id}_${t}_catenery_fill`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`black`,"line-width":6,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`3`],1,0]}},{id:`${e.id}_${t}`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`#85A0D9`,"line-width":2}}],de=(e,t)=>{let n=[`interpolate`,[`exponential`,2],[`zoom`],12,2,16,3.5,18,4.5,20,5];return[{id:`${e.id}_${t}`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`grey`,"line-width":3}},{id:`${e.id}_${t}_red`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`red`,"line-width":n,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`1`],1,0]}},{id:`${e.id}_${t}_white`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`white`,"line-width":n,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e.id}_${t}_grey`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`,visibility:`none`},paint:{"line-color":`grey`,"line-width":n,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`3`],1,0]}},{id:`${e.id}_${t}_white_label`,type:`symbol`,source:e.id,"source-layer":t,filter:[`!=`,[`get`,`category`],2],layout:{"text-field":[`get`,`name`],"text-size":[`interpolate`,[`linear`],[`zoom`],15,[`case`,[`==`,[`get`,`category`],50],12,[`==`,[`get`,`category`],96],10,9],22,[`case`,[`==`,[`get`,`category`],50],18,[`==`,[`get`,`category`],96],14,15]],"text-font":[`Open Sans Regular`],"text-anchor":`bottom`,"text-offset":[0,-1],"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":`white`,"text-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e.id}_${t}_red_label`,type:`symbol`,source:e.id,"source-layer":t,filter:[`!=`,[`get`,`category`],2],layout:{"text-field":[`get`,`name`],"text-size":[`interpolate`,[`linear`],[`zoom`],15,[`case`,[`==`,[`get`,`category`],50],12,[`==`,[`get`,`category`],96],10,9],22,[`case`,[`==`,[`get`,`category`],50],18,[`==`,[`get`,`category`],96],14,15]],"text-font":[`Open Sans Regular`],"text-anchor":`bottom`,"text-offset":[0,-1],"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":`red`,"text-opacity":[`case`,[`==`,[`feature-state`,`state`],`1`],1,0]}}]},fe=(e,t)=>{let n=[`interpolate`,[`exponential`,2],[`zoom`],12,.2,16,.6,18,.8,20,1.5],r=[];return[w.Red,w.Green,w.White,w.Blue].forEach(i=>{r.push({id:`${e.id}_${t}_${i}`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":[`case`,[`==`,[`get`,`inst_type`],1],[`case`,[`==`,[`get`,`posi_side`],1],`icon-signal-h-l-${i}`,`icon-signal-h-r-${i}`],[`case`,[`==`,[`get`,`posi_side`],1],`icon-signal-l-l-${i}`,`icon-signal-l-r-${i}`]],"icon-size":n,"icon-rotate":[`case`,[`==`,[`get`,`posi_side`],2],[`+`,270,[`to-number`,[`get`,`angle`]]],[`+`,90,[`to-number`,[`get`,`angle`]]]],"icon-allow-overlap":!0,"icon-anchor":[`case`,[`==`,[`get`,`posi_side`],1],`bottom-left`,`bottom-right`]},paint:{"icon-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],i],[`!=`,[`feature-state`,`visiable`],!1]],1,0]}})}),[...r,{id:`${e.id}_${t}`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":[`case`,[`==`,[`get`,`inst_type`],1],[`case`,[`==`,[`get`,`posi_side`],1],`icon-signal-h-l`,`icon-signal-h-r`],[`case`,[`==`,[`get`,`posi_side`],1],`icon-signal-l-l`,`icon-signal-l-r`]],"icon-size":n,"icon-rotate":[`case`,[`==`,[`get`,`posi_side`],2],[`+`,270,[`to-number`,[`get`,`angle`]]],[`+`,90,[`to-number`,[`get`,`angle`]]]],"icon-allow-overlap":!0,"icon-anchor":[`case`,[`==`,[`get`,`posi_side`],1],`bottom-left`,`bottom-right`]},paint:{"icon-opacity":[`case`,[`!=`,[`feature-state`,`visiable`],!1],1,0]}}]},pe=(e,t)=>[{id:`${e.id}_${t}_hitarea`,type:`circle`,source:e.id,"source-layer":t,paint:{"circle-radius":[`interpolate`,[`linear`],[`zoom`],5,11],"circle-color":`red`,"circle-opacity":0}},{id:`${e.id}_${t}_text`,type:`symbol`,source:e.id,"source-layer":t,layout:{"text-field":[`get`,`name`],"text-size":[`interpolate`,[`linear`],[`zoom`],15,11,22,15],"text-font":[`Open Sans Regular`],"text-anchor":`top`,"text-offset":[0,.5],"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":[`match`,[`feature-state`,`state`],`2`,`lightgreen`,`3`,`darkorange`,`4`,`red`,`white`]}},{id:`${e.id}_${t}_lock`,type:`circle`,source:e.id,"source-layer":t,layout:{visibility:`visible`},paint:{"circle-radius":[`interpolate`,[`linear`],[`zoom`],5,8],"circle-stroke-width":1.7,"circle-stroke-color":[`match`,[`feature-state`,`state`],`2`,`green`,`3`,`darkorange`,`4`,`red`,`white`],"circle-color":`transparent`,"circle-stroke-opacity":[`case`,[`==`,[`feature-state`,`subState2`],`1`],1,0]}},{id:`${e.id}_${t}_danfen`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":`icon-red-box`,"icon-allow-overlap":!0,"icon-offset":[0,15],"icon-size":[`interpolate`,[`linear`],[`zoom`],5,.2,10,.5,18,1]},paint:{"icon-opacity":[`case`,[`==`,[`feature-state`,`subState3`],`1`],1,0]}}],me=(e,t)=>[{id:`${e.id}_${t}`,type:`line`,source:e.id,"source-layer":t,paint:{"line-width":5,"line-color":`#000000`}},{id:`${e.id}_${t}_normal`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`2`]],paint:{"line-width":4,"line-color":`green`,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e.id}_${t}_reverse`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`3`]],paint:{"line-width":4,"line-color":`darkorange`,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`3`],1,0]}},{id:`${e.id}_${t}_fourway`,type:`line`,source:e.id,"source-layer":t,paint:{"line-width":4,"line-color":`#000000`,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`4`],1,0]}},{id:`${e.id}_${t}_normal_white`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`2`]],paint:{"line-width":4,"line-color":`white`,"line-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],`2`],[`==`,[`feature-state`,`subState1`],`2`]],1,0]}},{id:`${e.id}_${t}_reverse_white`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`3`]],paint:{"line-width":4,"line-color":`white`,"line-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],`3`],[`==`,[`feature-state`,`subState1`],`2`]],1,0]}},{id:`${e.id}_${t}_normal_red`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`2`]],paint:{"line-width":4,"line-color":`red`,"line-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],`2`],[`==`,[`feature-state`,`subState1`],`3`]],1,0]}},{id:`${e.id}_${t}_reverse_red`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`3`]],paint:{"line-width":4,"line-color":`red`,"line-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],`3`],[`==`,[`feature-state`,`subState1`],`3`]],1,0]}}],he=(e,t)=>({id:`${e.id}_${t}`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":`icon-bumper`,"icon-size":[`interpolate`,[`exponential`,2],[`zoom`],12,.1,16,.5,18,.7,20,1.4],"icon-rotate":[`get`,`angle`],"icon-allow-overlap":!0,"icon-anchor":`left`}}),ge=(e,t)=>({id:`${e.id}_${t}`,type:`symbol`,source:e.id,"source-layer":t,filter:[`!=`,[`get`,`category`],2],layout:{"text-field":[`get`,`name`],"text-size":[`interpolate`,[`linear`],[`zoom`],15,[`case`,[`==`,[`get`,`category`],50],10,[`==`,[`get`,`category`],96],8,7],22,[`case`,[`==`,[`get`,`category`],50],16,[`==`,[`get`,`category`],96],12,13]],"text-font":[`Open Sans Regular`],"text-anchor":[`case`,[`==`,[`get`,`angle`],90],`bottom-left`,`top-right`],"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":`#C0C33F`}}),_e=(e,t)=>{let n=[`interpolate`,[`exponential`,2],[`zoom`],12,1,15,1.5,16,2,17,4];return{id:`${e.id}_${t}`,type:`circle`,source:e.id,"source-layer":t,filter:[`!=`,[`get`,`category`],2],paint:{"circle-radius":n,"circle-stroke-width":n,"circle-stroke-color":`#ffbb00`},layout:{visibility:`none`}}},E=function(e){return e[e.NULL=0]=`NULL`,e[e.BUMPER=1]=`BUMPER`,e[e.CONTACTLINEEND=2]=`CONTACTLINEEND`,e[e.FIXEDDERAILER=3]=`FIXEDDERAILER`,e[e.CONTACTLINENOSTOP=4]=`CONTACTLINENOSTOP`,e[e.CONTACTLINENOSTOPIN=5]=`CONTACTLINENOSTOPIN`,e[e.OTHERPROMPT=6]=`OTHERPROMPT`,e[e.OTHERBRAKE=7]=`OTHERBRAKE`,e[e.ONESTOP=8]=`ONESTOP`,e[e.SPEEDLIMITED=9]=`SPEEDLIMITED`,e[e.SPEEDNOTICE=10]=`SPEEDNOTICE`,e[e.CROSSSPEEDLIMITED=11]=`CROSSSPEEDLIMITED`,e[e.CONTACTLINEPSS=12]=`CONTACTLINEPSS`,e[e.SSG=13]=`SSG`,e[e.CONTACTLINEPSSIN=14]=`CONTACTLINEPSSIN`,e[e.CONTACTLINENOAREA=15]=`CONTACTLINENOAREA`,e[e.HIGHPOSTSIGNAL=16]=`HIGHPOSTSIGNAL`,e[e.RESCUEVEHICLE=17]=`RESCUEVEHICLE`,e[e.RAILWAYCROSS=18]=`RAILWAYCROSS`,e[e.TRAIN=19]=`TRAIN`,e[e.STATIONBOUND=20]=`STATIONBOUND`,e[e.SHORTPOSTSIGNAL=21]=`SHORTPOSTSIGNAL`,e[e.BRIDGE=22]=`BRIDGE`,e[e.WHITE=23]=`WHITE`,e[e.WHITEBLUE=24]=`WHITEBLUE`,e[e.BLUE=25]=`BLUE`,e[e.BLUEWHITE=26]=`BLUEWHITE`,e[e.SLOPE=27]=`SLOPE`,e[e.PEOPLE=28]=`PEOPLE`,e[e.TUNNEL=29]=`TUNNEL`,e[e.DANGER=30]=`DANGER`,e[e.SIGNAL=31]=`SIGNAL`,e[e.SWERVE=32]=`SWERVE`,e[e.SWITCH=33]=`SWITCH`,e[e.FOULINGPOST=38]=`FOULINGPOST`,e[e.CUNCHE=39]=`CUNCHE`,e[e.STATIONBOUNDEXTEND=40]=`STATIONBOUNDEXTEND`,e[e.RED=41]=`RED`,e[e.GREEN=42]=`GREEN`,e[e.YELLOW=43]=`YELLOW`,e[e.BLOCKLINE=50]=`BLOCKLINE`,e[e.WORKAREA=51]=`WORKAREA`,e[e.ROUTELINE=52]=`ROUTELINE`,e[e.PARK=53]=`PARK`,e[e.WORKBUOND=54]=`WORKBUOND`,e[e.WORKBUONDCROSS=55]=`WORKBUONDCROSS`,e[e.LEFTHIGHPLATFORM=61]=`LEFTHIGHPLATFORM`,e[e.RIGHTHIGHPLATFORM=62]=`RIGHTHIGHPLATFORM`,e[e.BOTHSIDEHIGHPLATFORM=63]=`BOTHSIDEHIGHPLATFORM`,e[e.TGQ=47]=`TGQ`,e[e.DOOR=87]=`DOOR`,e[e.OTHER=95]=`OTHER`,e[e.SIDE=253]=`SIDE`,e[e.NONE=254]=`NONE`,e[e.MAX=255]=`MAX`,e[e.ISOLATE=35]=`ISOLATE`,e[e.ISOLATESWITCH=100]=`ISOLATESWITCH`,e}({}),ve={background:le,signal:fe,track:ue,track_circuit:de,bumper:he,switch:pe,switch_loc:me,insulation:_e,label:ge,prevention:(e,t)=>[{id:`${e.id}_${t}_jcw`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":[`case`,[`==`,[`to-string`,[`get`,`uc_oob_type`]],String(E.CONTACTLINEEND)],`icon-jcw`,``],"icon-size":[`interpolate`,[`exponential`,2],[`zoom`],12,.1,16,.5,18,.7,20,1.4],"icon-allow-overlap":!0,"icon-anchor":`left`}},{id:`${e.id}_${t}_circle`,type:`circle`,source:e.id,"source-layer":t,filter:[`match`,[`to-string`,[`get`,`uc_oob_type`]],[String(E.ONESTOP),String(E.STATIONBOUND),String(E.DOOR)],!0,!1],paint:{"circle-radius":[`interpolate`,[`exponential`,2],[`zoom`],10,6,20,18],"circle-stroke-width":2,"circle-stroke-color":`red`},layout:{visibility:`visible`}},{id:`${e.id}_${t}_text`,type:`symbol`,source:e.id,"source-layer":t,filter:[`match`,[`to-string`,[`get`,`uc_oob_type`]],[String(E.CONTACTLINEEND),String(E.ONESTOP),String(E.STATIONBOUND),String(E.DOOR)],!0,!1],layout:{"text-field":[`case`,[`==`,[`to-string`,[`get`,`uc_oob_type`]],String(E.ONESTOP)],`停`,[`==`,[`to-string`,[`get`,`uc_oob_type`]],String(E.STATIONBOUND)],`界`,``],"text-font":[`Open Sans Regular`],"text-size":[`interpolate`,[`linear`],[`zoom`],10,6,20,18],"text-anchor":`center`,"symbol-placement":`point`,"text-allow-overlap":!0,visibility:`visible`},paint:{"text-color":`white`}}]},ye=e=>{let t=[];return e.layers.forEach((n,r)=>{let i=ve[n],a=e.sourceLayers[r];if(i){let n=i(e,a);Array.isArray(n)?t.push(...n):t.push(n)}else console.warn(`图层 ${n} 尚未实现`)}),t},be={background:(e,t)=>({id:`${e.id}_${t}`,type:`background`,paint:{"background-color":`#131212`}}),signal:(e,t)=>[{id:`${e.id}_${t}`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":[`case`,[`==`,[`get`,`inst_type`],1],[`case`,[`==`,[`get`,`posi_side`],2],`icon-signal-h-r`,`icon-signal-h-l`],[`case`,[`==`,[`get`,`posi_side`],2],`icon-signal-l-r`,`icon-signal-l-l`]],"icon-allow-overlap":!0,"icon-rotate":[`case`,[`==`,[`get`,`posi_side`],2],[`-`,270,[`to-number`,[`get`,`angle`]]],[`-`,90,[`to-number`,[`get`,`angle`]]]],"icon-size":[`interpolate`,[`exponential`,2],[`zoom`],12,0,16,.3,18,.5,20,1],"icon-anchor":[`case`,[`==`,[`get`,`posi_side`],1],`bottom-left`,`bottom-right`],"icon-offset":[0,2]},paint:{"icon-opacity":[`case`,[`!=`,[`feature-state`,`visiable`],!1],1,0]}},{id:`${e.id}_${t}_text`,type:`symbol`,source:e.id,"source-layer":t,layout:{"text-field":[`get`,`name`],"text-font":[`Arial Unicode MS Bold`],"text-size":[`interpolate`,[`linear`],[`zoom`],12,5,14,8,18,14],"text-anchor":`center`,"symbol-placement":`point`,"text-allow-overlap":!0,"text-offset":[0,.6]},paint:{"text-color":`gold`}}],track:(e,t)=>[{id:`${e.id}_${t}_hitarea`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`black`,"line-width":6,"line-opacity":[`case`,[`==`,[`feature-state`,`select`],!0],1,0]}},{id:`${e.id}_${t}`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`#85A0D9`,"line-width":2}}],track_circuit:null,bumper:(e,t)=>[{id:`${e.id}_${t}`,type:`circle`,source:e.id,"source-layer":t,paint:{"circle-radius":[`interpolate`,[`exponential`,2],[`zoom`],10,3,12,3,14,5,16,6,20,8],"circle-stroke-width":2,"circle-stroke-color":`red`}},{id:`${e.id}_${t}_text`,type:`symbol`,source:e.id,"source-layer":t,layout:{"text-field":`档`,"text-font":[`Arial Unicode MS Bold`],"text-size":[`interpolate`,[`linear`],[`zoom`],10,6,12,8,14,10,16,12,20,12],"text-anchor":`center`,"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":`white`}}],switch:null,switch_loc:null,insulation:null,label:null,prevention:(e,t)=>[{id:`${e.id}_${t}`,type:`circle`,source:e.id,"source-layer":t,filter:[`match`,[`to-string`,[`get`,`uc_oob_type`]],[`2`,`8`,`20`,`87`],!0,!1],paint:{"circle-radius":[`interpolate`,[`exponential`,2],[`zoom`],10,3,12,3,14,5,16,6,20,8],"circle-stroke-width":2,"circle-stroke-color":`red`}},{id:`${e.id}_${t}_text`,type:`symbol`,source:e.id,"source-layer":t,layout:{"text-field":[`case`,[`==`,[`to-string`,[`get`,`uc_oob_type`]],`2`],`网`,[`==`,[`to-string`,[`get`,`uc_oob_type`]],`8`],`停`,[`==`,[`to-string`,[`get`,`uc_oob_type`]],`20`],`界`,`门`],"text-font":[`Arial Unicode MS Bold`],"text-size":[`interpolate`,[`linear`],[`zoom`],10,6,12,8,14,10,16,12,20,12],"text-anchor":`center`,"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":`white`}}]},xe=e=>{let t=[];return e.layers.forEach((n,r)=>{let i=be[n],a=e.sourceLayers[r];if(i){let n=i(e,a);Array.isArray(n)?t.push(...n):t.push(n)}else console.warn(`图层 ${n} 尚未实现`)}),t},Se=e=>[{id:`${e}_raster_layer`,type:`raster`,source:e,paint:{"raster-opacity":.8}}],Ce=e=>({id:`${e}_background`,type:`background`,paint:{"background-color":`#131212`}}),we=e=>[{id:`${e}_track_lock`,type:`line`,source:e,layout:{"line-join":`round`},paint:{"line-color":`#a7009e`,"line-width":3,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`1`],1,0]}},{id:`${e}_track_lock_icon`,type:`symbol`,source:e,layout:{"symbol-placement":`line-center`,"icon-anchor":`top`,"icon-image":`icon-lock`,"icon-size":[`interpolate`,[`exponential`,2],[`zoom`],12,.2,15,.5,16,.6,17,.8],"icon-offset":[0,5],"icon-allow-overlap":!0,"icon-rotation-alignment":`viewport`,"icon-rotate":0},paint:{"icon-opacity":[`case`,[`==`,[`feature-state`,`state`],`1`],1,0]}},{id:`${e}_track_poweroff_border`,type:`line`,source:e,layout:{"line-join":`round`},paint:{"line-color":`green`,"line-width":9,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e}_track_poweroff_fill`,type:`line`,source:e,layout:{"line-join":`round`},paint:{"line-color":`black`,"line-width":6,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e}_track_catenery_border`,type:`line`,source:e,layout:{"line-join":`round`},paint:{"line-color":`grey`,"line-width":9,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`3`],1,0]}},{id:`${e}_track_catenery_fill`,type:`line`,source:e,layout:{"line-join":`round`},paint:{"line-color":`black`,"line-width":6,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`3`],1,0]}},{id:`${e}_track`,type:`line`,source:e,layout:{"line-join":`round`},paint:{"line-color":`#85A0D9`,"line-width":2}}],Te=function(e){return e[e.RedCircuit=1]=`RedCircuit`,e[e.WhiteCircuit=2]=`WhiteCircuit`,e[e.EqualRedCircuit=3]=`EqualRedCircuit`,e[e.GreyCircuit=4]=`GreyCircuit`,e[e.GreenCircuit=5]=`GreenCircuit`,e}({}),Ee={background:Ce,signal:e=>{let t=[`interpolate`,[`exponential`,2],[`zoom`],12,.2,16,.6,18,.8,20,1.5];return[...[w.Red,w.Green,w.White,w.Blue].map(n=>({id:`${e}_signal_${n}`,type:`symbol`,source:e,layout:{"icon-image":[`case`,[`==`,[`get`,`installType`],1],[`case`,[`==`,[`get`,`positionSide`],1],`icon-signal-h-l-${n}`,`icon-signal-h-r-${n}`],[`case`,[`==`,[`get`,`positionSide`],1],`icon-signal-l-l-${n}`,`icon-signal-l-r-${n}`]],"icon-size":t,"icon-rotate":[`case`,[`==`,[`get`,`positionSide`],2],[`+`,270,[`to-number`,[`get`,`angle`]]],[`+`,90,[`to-number`,[`get`,`angle`]]]],"icon-allow-overlap":!0,"icon-anchor":[`case`,[`==`,[`get`,`positionSide`],1],`bottom-left`,`bottom-right`]},paint:{"icon-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],n],[`!=`,[`feature-state`,`visiable`],!1]],1,0]}})),{id:`${e}_signal`,type:`symbol`,source:e,layout:{"icon-image":[`case`,[`==`,[`get`,`installType`],1],[`case`,[`==`,[`get`,`positionSide`],1],`icon-signal-h-l`,`icon-signal-h-r`],[`case`,[`==`,[`get`,`positionSide`],1],`icon-signal-l-l`,`icon-signal-l-r`]],"icon-size":t,"icon-rotate":[`case`,[`==`,[`get`,`positionSide`],2],[`+`,270,[`to-number`,[`get`,`angle`]]],[`+`,90,[`to-number`,[`get`,`angle`]]]],"icon-allow-overlap":!0,"icon-anchor":[`case`,[`==`,[`get`,`positionSide`],1],`bottom-left`,`bottom-right`]},paint:{"icon-opacity":[`case`,[`!=`,[`feature-state`,`visiable`],!1],1,0]}}]},track:we,track_circuit:e=>{let t=[`interpolate`,[`exponential`,2],[`zoom`],12,2,16,3.5,18,4.5,20,5];return[{id:`${e}_trackcircuit_bad`,type:`line`,source:e,layout:{"line-join":`round`},paint:{"line-color":[`case`,[`==`,[`feature-state`,`state`],Te.RedCircuit],`#ff0000`,[`==`,[`feature-state`,`state`],Te.WhiteCircuit],`#ffffff`,[`==`,[`feature-state`,`state`],Te.GreyCircuit],`#808080`,`#000000`],"line-width":t,"line-dasharray":[4,4],"line-opacity":[`case`,[`==`,[`feature-state`,`substate`],0],1,0]}},{id:`${e}_trackcircuit_grey`,type:`line`,source:e,layout:{"line-join":`round`},paint:{"line-color":`grey`,"line-width":t,"line-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],Te.GreyCircuit],[`!=`,[`feature-state`,`substate`],0]],1,0]}},{id:`${e}_trackcircuit_red`,type:`line`,source:e,layout:{"line-join":`round`},paint:{"line-color":`red`,"line-width":t,"line-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],Te.RedCircuit],[`!=`,[`feature-state`,`substate`],0]],1,0]}},{id:`${e}_trackcircuit_white`,type:`line`,source:e,layout:{"line-join":`round`},paint:{"line-color":`white`,"line-width":t,"line-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],Te.WhiteCircuit],[`!=`,[`feature-state`,`substate`],0]],1,0]}},{id:`${e}_trackcircuit_white_label`,type:`symbol`,source:e,filter:[`!=`,[`get`,`category`],2],layout:{"text-field":[`get`,`name`],"text-size":[`interpolate`,[`linear`],[`zoom`],15,[`case`,[`==`,[`get`,`category`],50],12,[`==`,[`get`,`category`],96],10,9],22,[`case`,[`==`,[`get`,`category`],50],18,[`==`,[`get`,`category`],96],14,15]],"text-font":[`Open Sans Regular`],"text-anchor":`bottom`,"text-offset":[0,-1],"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":`white`,"text-opacity":[`case`,[`==`,[`feature-state`,`state`],Te.WhiteCircuit],1,0]}},{id:`${e}_trackcircuit_red_label`,type:`symbol`,source:e,filter:[`!=`,[`get`,`category`],2],layout:{"text-field":[`get`,`name`],"text-size":[`interpolate`,[`linear`],[`zoom`],15,[`case`,[`==`,[`get`,`category`],50],12,[`==`,[`get`,`category`],96],10,9],22,[`case`,[`==`,[`get`,`category`],50],18,[`==`,[`get`,`category`],96],14,15]],"text-font":[`Open Sans Regular`],"text-anchor":`bottom`,"text-offset":[0,-1],"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":`red`,"text-opacity":[`case`,[`==`,[`feature-state`,`state`],Te.RedCircuit],1,0]}}]},bumper:e=>({id:`${e}_bumper`,type:`symbol`,source:e,layout:{"icon-image":`icon-bumper`,"icon-size":[`interpolate`,[`exponential`,2],[`zoom`],12,.1,16,.5,18,.7,20,1.4],"icon-rotate":[`get`,`angle`],"icon-allow-overlap":!0,"icon-anchor":`left`}}),switch:e=>[{id:`${e}_switch_hitarea`,type:`circle`,source:e,paint:{"circle-radius":[`interpolate`,[`linear`],[`zoom`],5,11],"circle-color":`red`,"circle-opacity":0}},{id:`${e}_switch_text`,type:`symbol`,source:e,layout:{"text-field":[`get`,`name`],"text-size":[`interpolate`,[`linear`],[`zoom`],15,11,22,15],"text-font":[`Open Sans Regular`],"text-anchor":`top`,"text-offset":[0,.5],"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":[`match`,[`feature-state`,`state`],`2`,`lightgreen`,`3`,`darkorange`,`4`,`red`,`white`]}}],switch_loc:e=>[{id:`${e}_switchloc`,type:`line`,source:e,paint:{"line-width":5,"line-color":`#000000`}},{id:`${e}_switchloc_normal`,type:`line`,source:e,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`2`]],paint:{"line-width":4,"line-color":`green`,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e}_switchloc_reverse`,type:`line`,source:e,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`3`]],paint:{"line-width":4,"line-color":`darkorange`,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`3`],1,0]}}],insulation:e=>{let t=[`interpolate`,[`exponential`,2],[`zoom`],12,1,15,1.5,16,2,17,4];return{id:`${e}_insulation`,type:`circle`,source:e,filter:[`!=`,[`get`,`category`],2],paint:{"circle-radius":t,"circle-stroke-width":t,"circle-stroke-color":`#ffbb00`}}},label:e=>({id:`${e}_label`,type:`symbol`,source:e,filter:[`!=`,[`get`,`category`],2],layout:{"text-field":[`get`,`name`],"text-size":[`interpolate`,[`linear`],[`zoom`],15,[`case`,[`==`,[`get`,`category`],50],12,[`==`,[`get`,`category`],96],10,9],22,[`case`,[`==`,[`get`,`category`],50],18,[`==`,[`get`,`category`],96],14,15]],"text-font":[`Open Sans Regular`],"text-anchor":[`case`,[`==`,[`get`,`angle`],90],`bottom-left`,`top-right`],"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":`yellow`}}),prevention:e=>[{id:`${e}_prevention_jcw`,type:`symbol`,source:e,layout:{"icon-image":[`case`,[`==`,[`to-number`,[`get`,`ucOobType`]],E.CONTACTLINEEND],`icon-jcw`,``],"icon-size":[`interpolate`,[`exponential`,2],[`zoom`],12,.1,16,.5,18,.7,20,1.4],"icon-allow-overlap":!0,"icon-anchor":`left`}},{id:`${e}_prevention_circle`,type:`circle`,source:e,filter:[`match`,[`to-number`,[`get`,`ucOobType`]],[E.ONESTOP,E.STATIONBOUND,E.DOOR],!0,!1],paint:{"circle-radius":[`interpolate`,[`exponential`,2],[`zoom`],10,6,20,18],"circle-stroke-width":2,"circle-stroke-color":`red`}},{id:`${e}_prevention_text`,type:`symbol`,source:e,filter:[`match`,[`to-number`,[`get`,`ucOobType`]],[E.CONTACTLINEEND,E.ONESTOP,E.STATIONBOUND,E.DOOR],!0,!1],layout:{"text-field":[`case`,[`==`,[`to-number`,[`get`,`ucOobType`]],E.ONESTOP],`停`,[`==`,[`to-number`,[`get`,`ucOobType`]],E.STATIONBOUND],`界`,[`==`,[`to-number`,[`get`,`ucOobType`]],E.DOOR],`门`,``],"text-font":[`Open Sans Regular`],"text-size":[`interpolate`,[`linear`],[`zoom`],10,6,20,18],"text-anchor":`center`,"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":`white`}}]},D={ctc:ce,graph:ye,geom:xe,raster:Se,geojson:(e,t)=>{let n=[];return e.forEach((e,r)=>{let i=t[r],a=Ee[e];if(!a){console.warn(`GeoJSON 图层 ${e} 尚未实现`);return}let o=a(i);Array.isArray(o)?n.push(...o):n.push(o)}),n}};function De(e){if(!e||e.length<11)return``;let t=e.charAt(10),n=e.charAt(9);return n===`6`&&t===`7`?`sgfhqy_door`:n===`6`&&t===`8`?`sgfhqy_line`:n===`6`&&t===`9`?`sgfhqy_area`:t===`1`&&n===`0`?`track`:t===`3`?`signal`:t===`2`&&n===`0`||t===`1`&&n===`1`?`switch`:t===`2`&&n===`1`?`circuit`:``}var Oe=class{teeeMap;trackFeatures=[];switchFeatures=[];switchlocFeatures=[];circuitFeatures=[];signalFeatures=[];sgfhqyFeatures=[];pathInfoRecords=[];onPathSelected;boundHandlePathClick;constructor(e){this.teeeMap=e,this.boundHandlePathClick=this.handlePathClick.bind(this),e.map.once(`idle`,()=>{if(!e.mapConfigs)return;let{id:t}=e.mapConfigs,n=e.mapConfigs.sourceLayers,r=e.mapConfigs.layers;e.map.moveLayer(`${t}_${n[r.indexOf(`track`)]}_lock`)})}cacheFeatures(){let{mapConfigs:e}=this.teeeMap;if(!e)return;let t=e.id,n=e.sourceLayers,r=e.layers;this.trackFeatures=this.teeeMap.map.querySourceFeatures(t,{sourceLayer:n[r.indexOf(`track`)]}),this.switchFeatures=this.teeeMap.map.querySourceFeatures(t,{sourceLayer:n[r.indexOf(`switch`)]}),this.switchlocFeatures=this.teeeMap.map.querySourceFeatures(t,{sourceLayer:n[r.indexOf(`switch_loc`)]}),this.circuitFeatures=this.teeeMap.map.querySourceFeatures(t,{sourceLayer:n[r.indexOf(`track_circuit`)]}),this.signalFeatures=this.teeeMap.map.querySourceFeatures(t,{sourceLayer:n[r.indexOf(`signal`)]}),this.sgfhqyFeatures=this.teeeMap.map.querySourceFeatures(t,{sourceLayer:n[r.indexOf(`sgfhqy`)]})}initState(){let{mapConfigs:e}=this.teeeMap;if(!e)return;let t=e.id;e.sourceLayers.forEach(e=>{e.includes(`switch`)?this.teeeMap.map.querySourceFeatures(t,{sourceLayer:e}).forEach(e=>this.initCTCFeatureState(e)):e.includes(`signal`)?this.teeeMap.map.querySourceFeatures(t,{sourceLayer:e}).forEach(e=>{this.initCTCFeatureState(e)}):(e.includes(`track`)||e.includes(`sgfhqy`))&&this.teeeMap.map.querySourceFeatures(t,{sourceLayer:e}).forEach(e=>this.initCTCFeatureState(e))})}initCTCFeatureState(e){if(!e)return;let t=e.properties.code,n=De(t);if(n===`switch`)this.teeeMap.updateFeatureState(e.properties.code,{state:`2`,select:!1,visiable:!0,subState1:``,subState2:``,subState3:``});else if(n===`signal`){let t=e.properties,n=t.attach||0,r=t.func_type,i={state:``,select:!1,visiable:!0,subState1:`grey`,subState2:``,subState3:``};r==1&&n==0||(r==2||r==3)&&n==0||(r==2||r==3||r==11)&&n==1?(i.state=`red`,i.subState1=`blue`):(r==4||r==5||r==12)&&n==0?(i.state=`blue`,i.subState1=`green`):r==6&&n==0||(r==7||r==11)&&n==0?(i.state=`red`,i.subState1=`blue`):(i.state=``,i.subState1=`grey`),this.teeeMap.updateFeatureState(t.code,i)}else n===`signal`||n===`circuit`?this.teeeMap.updateFeatureState(e.properties.code,{state:``,select:!1,visiable:!0,subState1:``,subState2:``,subState3:``}):n===`sgfhqy_door`&&this.teeeMap.updateFeatureState(e.properties.code,{state:`2`,select:!1,visiable:!0,subState1:``,subState2:``,subState3:``})}changeFeatureState(e,t){if(this.teeeMap.updateFeatureState(e,t),!e||e.length<11)return;let n=e.charAt(10),r=e.charAt(9);n===`2`&&r===`0`&&this.switchlocFeatures.forEach(n=>{n.properties.s_code==e&&this.teeeMap.updateFeatureState(n.properties.code,t)})}parseSignals(e){let t=[],n=this.signalFeatures.filter(t=>t.properties.name==e.destSignal)[0],r=this.signalFeatures.filter(t=>t.properties.name==e.srcSignal)[0];return t.push(n),t.push(r),t}parseSwitchs(e){let t=[];return e.forEach(e=>{let n=`2`,r=e;e.startsWith(`[`)&&e.endsWith(`]`)?(n=`protect`,r=e.slice(1,-1)):e.startsWith(`(`)&&e.endsWith(`)`)?(n=`3`,r=e.slice(1,-1)):e.startsWith(`{`)&&e.endsWith(`}`)&&(n=`drive`,r=e.slice(1,-1)),r.split(`/`).forEach(e=>{let r=this.switchFeatures.filter(t=>t.properties.name===e.trim());r.length>0&&t.push({name:e.trim(),code:r[0].properties.code,type:n,f:r})})}),t}parseTrackCircuits(e,t){let n=[];return e.forEach(e=>{let r=this.circuitFeatures.filter(t=>t.properties.name===e);if(!r.length)return;r.forEach(e=>{this.teeeMap.updateFeatureState(e.properties.code,{state:`3`})});let i=r.filter(e=>{let n=e.properties.switches?e.properties.switches.split(`,`):[],r=e.properties.positions?e.properties.positions.split(`,`).map(e=>Number(e)):[];if(n.length===0)return!0;for(let e=0;e<n.length;e++){let i=n[e],a=r[e*2],o=r[e*2+1],s=Math.max(a,o),c=t.get(i);if(!c||c!==s)return!1}return!0});if(i.length>0){let t=new Map;i.forEach(e=>{let n=e.properties.code;t.has(n)||t.set(n,e)});let r=Array.from(t.values());r.length===1?n.push(...r):r.length===0?console.warn(`未匹配到有效区段:`,e):console.warn(`匹配到多个区段,数据异常:`,e,i)}}),n}calcPathInfo(e){let t=[];for(let n of e){let e=n.trackSections,r=n.turnouts,i=this.parseSignals(n),a=this.parseSwitchs(r),o=new Map;a.forEach(e=>{o.set(e.code,Number(e.type))});let s=this.parseTrackCircuits(e,o);t.push({signalInfos:i,switchInfos:a,pathInfo:s})}return t}changePathState(e){if(e.length===0)return;let t=`4`;e.forEach((e,n,r)=>{n===r.length-1&&(t=`5`),e.routes.forEach(e=>{e.signalInfos.forEach(e=>{e&&this.changeFeatureState(e.properties.code,{state:`white`})}),e.switchInfos.forEach(e=>{e&&this.changeFeatureState(e.code,{state:e.type,subState1:`2`})}),e.pathInfo.forEach(e=>{e&&this.changeFeatureState(e.properties.code,{state:t})})})})}unloadPathClick(){this.teeeMap.map.off(`click`,this.boundHandlePathClick),this.pathInfoRecords=[]}handlePathClick(e){let t=this.teeeMap.getMapConfigs().id,n=this.teeeMap.getMapConfigs().sourceLayers,r=this.teeeMap.getMapConfigs().layers,i=[`${t}_${n[r.indexOf(`track_circuit`)]}_mainpath`,`${t}_${n[r.indexOf(`track_circuit`)]}_subpath`,`${t}_${n[r.indexOf(`track_circuit`)]}_hitarea`],a=this.teeeMap.map.queryRenderedFeatures(e.point,{layers:i});if(a.length>0){let e=a,t=this.pathInfoRecords.find(t=>e.some(e=>t.routes.some(t=>t.pathInfo.some(t=>t.properties.name===e.properties.name&&t.properties.code===e.properties.code))));if(t){let e=this.pathInfoRecords.indexOf(t);e>-1&&(this.pathInfoRecords.splice(e,1),this.pathInfoRecords.push(t)),this.changePathState(this.pathInfoRecords),this.onPathSelected?.(t)}}else console.warn(`未点击到有效的进路区段,请点击主进路或辅进路的电路区段`)}handlePathInfo(e){if(this.pathInfoRecords=[],e.forEach(e=>{let t={originalData:e,routes:this.calcPathInfo(e.routes)};this.pathInfoRecords.unshift(t)}),this.pathInfoRecords.length===0)return;this.changePathState(this.pathInfoRecords),this.pathInfoRecords.length>1?(console.log(`请左键单击选择目标进路`),this.teeeMap.map.on(`click`,this.boundHandlePathClick)):this.teeeMap.map.off(`click`,this.boundHandlePathClick);let t=this.pathInfoRecords[this.pathInfoRecords.length-1];this.onPathSelected?.(t)}createSignalAction(e){let t,n,r,i=[],a={},o=e.state,s=e.feature,c=s.properties;return o.subState1&&(o.subState1==`red`?(t=`nf`,n=`扭封`,i.push(s),a=e,r=`对${c.name}信号机钮封操作`):(t=`jf`,n=`解封`,i.push(s),a=e,r=`对${c.name}信号机解封操作`)),o.subState2&&(o.subState2==`off`?(t=`lightoff`,n=`灭灯`,i.push(s),a=e,r=`对${c.name}信号机灭灯操作`):(t=`lighton`,n=`点灯`,i.push(s),a=e,r=`对${c.name}信号机点灯操作`)),{actionType:t,actionName:n,content:r,feature:i,data:a}}createAllLightAction(e){let t,n,r,i=[],a={};return e.state.subState2===`off`?(t=`lightoff`,n=`全灭`,r=`信号机全灭操作`,a=e):(t=`lighton`,n=`全亮`,r=`信号机全亮操作`,a=e),{actionType:t,actionName:n,content:r,feature:i,data:a}}createSwitchAction(e){let t,n,r,i=[],a={},o=e.state,s=e.feature,c=s.properties;return o.subState1&&(o.subState1==`red`?(t=`nf`,n=`扭封`,i.push(s),a=e,r=`对${c.name}信号机钮封操作`):(t=`jf`,n=`解封`,i.push(s),a=e,r=`对${c.name}信号机解封操作`)),o.subState2&&(o.subState2==`off`?(t=`dd`,n=`灭灯`,i.push(s),a=e,r=`对${c.name}信号机灭灯操作`):(t=`md`,n=`点灯`,i.push(s),a=e,r=`对${c.name}信号机点灯操作`)),o.subState1!==void 0&&(o.subState1===`2`?(t=`dcsb`,n=`道岔锁闭`,i.push(s),a=e,r=`对${c.name}道岔锁闭操作`):o.subState1===`3`?(t=`dczy`,n=`道岔占用`,i.push(s),a=e,r=`对${c.name}道岔占用操作`):o.subState1===``&&(t=`dccq`,n=`道岔出清`,i.push(s),a=e,r=`对${c.name}道岔出清操作`)),o.subState2!==void 0&&(o.subState2===``?(t=`dcjs`,n=`道岔解锁`,i.push(s),a=e,r=`对${c.name}道岔解锁操作`):(t=`dcds`,n=`道岔单锁`,i.push(s),a=e,r=`对${c.name}道岔单锁操作`)),o.subState3!==void 0&&(o.subState3===`1`?(t=`dcdf`,n=`道岔单封`,i.push(s),a=e,r=`对${c.name}道岔单封操作`):o.subState3===``&&(t=`dcjf`,n=`道岔解封`,i.push(s),a=e,r=`对${c.name}道岔解封操作`)),{actionType:t,actionName:n,content:r,feature:i,data:a}}createPathAction(e){let t,n,r,i=[],a={},o=e.meta,s=e.feature,c=s.properties;return o.pathType==`srcSignal`?(t=`path`,n=`srcSignal`,i.push(s),a=e,r=`进路起点:${c.name}信号`):(t=`path`,n=`destSignal`,i.push(s),a=e,r=`进路终点:${c.name}信号`),{actionType:t,actionName:n,content:r,feature:i,data:a}}createDLTXAction(e){let t,n,r,i=[],a={},o=e.feature,s=o.properties;return e.featureType==`dltx`&&(t=`dltx`,n=`短路铜线`,i.push(o),a=e,r=`区段:${s.name}安置短路铜线`),{actionType:t,actionName:n,content:r,feature:i,data:a}}createWorkersAction(e){let t,n,r,i=[],a={};return e.featureType&&(t=e.featureType,n=`工人绘制`,i=e.fs,a=e,r=e.content),{actionType:t,actionName:n,content:r,feature:i,data:a}}};function ke(e,t){let n=this.map;if(n&&!n.getSource(e)){let r=T.graph(t);n.addSource(e,r)}}function Ae(e,t){let n=this.map;if(n&&!n.getSource(e)){let r=T.raster(t);n.addSource(e,r)}}function je(e,t){let n=this.map;if(!n){console.error(`地图实例未初始化`);return}try{if(n.getSource(e))console.warn(`源已存在,跳过添加: ${e}`);else{let r=t?T.geojson(t):T.geojson(void 0);n.addSource(e,r),console.log(`成功添加 GeoJSON 源: ${e}`)}}catch(t){console.error(` 添加源失败 [${e}]:`,t)}}function Me(e){let t=this.map;if(t)if(t.getSource(e))try{(t.getStyle().layers||[]).filter(t=>{if(`source`in t)return t.source===e}).forEach(e=>{t.removeLayer(e.id),console.log(`移除关联图层: ${e.id}`)}),t.removeSource(e),console.log(`成功移除源: ${e}`)}catch(t){console.error(`移除源失败 [${e}]:`,t)}else console.warn(`源不存在,无法移除: ${e}`)}function Ne(e,t){let n=this.map;if(!n)return;let r=n.getSource(e);r?(r.setData(t),console.log(`更新源数据: ${e}`)):this.addGeoJsonSource(e,t)}function Pe(e){let t=this.map;if(!t||!t.getSource(e))return null;let n=t.querySourceFeatures(e);return JSON.parse(JSON.stringify({type:`FeatureCollection`,features:n}))}function Fe(e,t,n=`fill`,r,i){let a=this.map;if(!a)return;if(!a.getSource(t)){console.error(`无法添加图层: 源 '${t}' 不存在`);return}a.getLayer(e)&&a.removeLayer(e);let o={};n===`fill`&&(o[`fill-color`]=`#3b82f6`),n===`line`&&(o[`line-color`]=`#3b82f6`),n===`circle`&&(o[`circle-color`]=`#3b82f6`);let s={id:e,type:n,source:t,paint:{...o,...r},layout:i||{}};a.addLayer(s)}function Ie(e,t){let n=this.map;n&&(n.getLayer(e)?(Object.keys(t).forEach(r=>{n.setPaintProperty(e,r,t[r])}),console.log(`样式已更新: ${e}`)):console.warn(` 图层不存在,无法更新样式: ${e}`))}function Le(e){let t=this.map;t&&(t.getLayer(e)?(t.removeLayer(e),console.log(`图层已移除: ${e}`)):console.warn(` 图层不存在,无法删除: ${e}`))}function Re(e,t){let n=this.map;if(!n)return;let r=Array.isArray(e)?e:[e];n.on(`click`,e=>{let i=n.queryRenderedFeatures(e.point,{layers:r});if(!i.length)return;let a=i[0];t(a,e.lngLat)}),n.on(`mouseenter`,r[r.length-1],()=>{n.getCanvas().style.cursor=`pointer`}),n.on(`mouseleave`,r[r.length-1],()=>{n.getCanvas().style.cursor=``})}function ze(){this.stashFeatures.clear(),this.map&&(this.map.remove(),console.log(`地图实例已移除`))}function Be(e){e.addGeoJsonSource=je,e.addVectorTileSource=ke,e.addRasterTileSource=Ae,e.updateGeoJsonSource=Ne,e.getGeoJsonSourceData=Pe,e.removeSource=Me,e.addGeoJsonLayer=Fe,e.updateLayerStyle=Ie,e.removeLayer=Le,e.onFeatureClick=Re,e.destroy=ze}var Ve=class{signalExist=!0;productInfo;stationCode;time;interlockInfo=new Map;getProductInfo(){return this.productInfo}getStCode(){return this.stationCode}getInterlockInfo(){return this.interlockInfo}isSignalExist(){return this.signalExist}setYardSignal(e){let t=e.split(`&`);this.time=t[0];let n=[],r=[],i=[];this.stationCode=t[1];let a=t[1],o=0;t.length===6&&(this.productInfo=t[2],o=1);let s=t[2],c=a+`:`+s;if(t[2+o]!==``){let e=t[2+o].split(`;`);for(let t of e){let e=t.split(`:`);n.push({name:e[0]+`:`+a,state:e[1]})}}if(t[3+o]!==``){let e=t[3+o].split(`;`);for(let t of e){let e=t.split(`:`);r.push({name:e[0]+`:`+a,state:e[1]})}}if(t[4+o]!==``){let e=t[4+o].split(`;`);for(let t of e){let e=t.split(`:`);i.push({name:e[0]+`:`+a,state:e[1]})}}this.interlockInfo.set(c,{signalInterlock:n,switchInterlock:r,circuitInterlock:i})}reset(){}resetInterlockInfo(){this.interlockInfo=new Map}},He=class{insulationSignalMap=new Map;signalInsulationMap=new Map;setInsulation(e){this.insulationSignalMap.clear(),this.signalInsulationMap.clear(),e.length===0&&console.warn(`没有绝缘节数据!`),e.forEach(e=>{let t=String(e.id??e.properties?.code??``),n=e.properties?.upSignal??null,r=e.properties?.downSignal??null,i=e.properties?.name??``;this.insulationSignalMap.set(t,{upsignal:n,downsignal:r}),n!=null&&this.signalInsulationMap.set(String(n),t+`-`+i),r!=null&&this.signalInsulationMap.set(String(r),t+`-`+i)})}getInsulationBySignalKey(e){return this.signalInsulationMap.get(e)}getSignalByInsulationKey(e){return this.insulationSignalMap.get(e)}},Ue=function(e){return e.RedLight=`red`,e.GreenLight=`green`,e.BlueLight=`blue`,e.WhiteLight=`white`,e}({}),We={1:Ue.RedLight,2:Ue.GreenLight,3:Ue.WhiteLight,4:Ue.BlueLight},Ge=class{map;layers;firstSwitches;updateFeatureState;queryGeojsonFeatures;sourceFrom;signalStore=new Ve;interLockInsulation=new He;interLockState={signal:new Map,switch:new Map,circuit:new Map};pathCircuits=[];pathCircuitsCodes=[];linkWhiteCircuits=[];signalEnable=!1;onSendSignal;stationSignalState=[];constructor(e){if(this.map=e.map,this.firstSwitches=e.firstSwitches??[],this.updateFeatureState=e.updateFeatureState,`mode`in e&&e.mode===`geojson`){let t=e.sourceIds;this.layers={signal:{sourceId:t.signal},switch:{sourceId:t.switch},switch_loc:{sourceId:t.switch_loc},track_circuit:{sourceId:t.track_circuit},track:{sourceId:t.track},insulation:{sourceId:t.insulation}},this.queryGeojsonFeatures=e.queryGeojsonFeatures,this.sourceFrom=`Geojson`}else{let t=e.sourceId,n=e.sourceLayers;this.layers={signal:{sourceId:t,sourceLayer:n.signal},switch:{sourceId:t,sourceLayer:n.switch},switch_loc:{sourceId:t,sourceLayer:n.switch_loc},track_circuit:{sourceId:t,sourceLayer:n.track_circuit},track:{sourceId:t,sourceLayer:n.track},insulation:{sourceId:t,sourceLayer:n.insulation}},this.sourceFrom=`VectorTile`}}queryFeatures(e){if(this.sourceFrom===`Geojson`&&this.queryGeojsonFeatures)return this.queryGeojsonFeatures(e);let t=this.layers[e];return this.map.querySourceFeatures(t.sourceId,t.sourceLayer?{sourceLayer:t.sourceLayer}:void 0)}setFeatureState(e,t,n){if(this.updateFeatureState)return this.updateFeatureState(t,n);let r=this.layers[e];this.map.setFeatureState(r.sourceLayer?{source:r.sourceId,sourceLayer:r.sourceLayer,id:t}:{source:r.sourceId,id:t},n)}getFeatureState(e,t){let n=this.layers[e];return this.map.getFeatureState(n.sourceLayer?{source:n.sourceId,sourceLayer:n.sourceLayer,id:t}:{source:n.sourceId,id:t})}initInsulation(){let e=this.queryFeatures(`insulation`);this.interLockInsulation.setInsulation(e)}handleSignalData(e){this.signalStore.resetInterlockInfo(),!e||e.length===0?this.signalStore.signalExist=!1:(this.signalStore.signalExist=!0,this.signalStore.setYardSignal(e)),this.signalStore.isSignalExist()&&this.signalStore.getInterlockInfo().forEach((e,t)=>{let n=t.split(`:`)[0],r=t.split(`:`)[1];this.arrToMap(this.interLockState.signal,e.signalInterlock),this.arrToMap(this.interLockState.switch,e.switchInterlock),this.arrToMap(this.interLockState.circuit,e.circuitInterlock),r===`ZK01`?this.visualizeZK(e,r,n):this.visualizeYD(e,r,n)})}turnOffSignals(){this.interLockState={signal:new Map,switch:new Map,circuit:new Map}}reset(e){this.clearCircuits(e),this.clearSwitchLocs(e)}clearCircuits(e){this.queryFeatures(`track_circuit`).forEach(t=>{t.properties?.stcode===e&&this.setFeatureState(`track_circuit`,t.properties.code,{state:``,visiable:!0})})}clearSwitchLocs(e){this.queryFeatures(`switch_loc`).forEach(t=>{t.properties?.stcode===e&&this.setFeatureState(`switch_loc`,t.properties.code,{state:``,visiable:!0})})}visualizeZK(e,t,n){this.reset(n);for(let t of e.signalInterlock){let e=t.name.split(`:`)[0],n=t.name.split(`:`)[1],r=this.getSignalFeature(e,n);r&&this.setFeatureState(`signal`,r.properties.code,{state:We[Number(t.state)],visiable:!0})}for(let t of e.switchInterlock){let e=t.name.split(`:`)[0],n=t.name.split(`:`)[1];this.getSwitchLocFeatures(e,n,t.state).forEach(e=>{this.setFeatureState(`switch_loc`,e.properties.code,{state:t.state})})}for(let t of e.circuitInterlock){let e=t.name.split(`:`)[0],n=t.name.split(`:`)[1],r=this.getCircuitFeature(e,n);r&&this.setFeatureState(`track_circuit`,r.properties.code,{state:Number(t.state),visiable:!0})}this.applyHandSwitchPaths(n,e.switchInterlock)}visualizeYD(e,t,n){this.reset(n);for(let t of e.signalInterlock){let e=t.name.split(`:`)[0],n=t.name.split(`:`)[1],r=this.getSignalFeature(e,n);r&&this.setFeatureState(`signal`,r.properties.code,{state:We[Number(t.state)],visiable:!0})}for(let t of e.switchInterlock){let e=t.name.split(`:`)[0],n=t.name.split(`:`)[1];this.getSwitchLocFeatures(e,n,t.state).forEach(e=>{this.setFeatureState(`switch_loc`,e.properties.code,{state:t.state,visiable:!0})})}this.pathCircuits=[],this.pathCircuitsCodes=[],this.linkWhiteCircuits=[];for(let t of e.circuitInterlock){let e=t.name.split(`:`)[0],n=t.name.split(`:`)[1],r=this.getCircuitFeature(e,n);r&&(this.pathCircuits.push(r),this.pathCircuitsCodes.push(String(r.properties?.code??``)))}for(let t of e.circuitInterlock){let e=t.name.split(`:`)[0],n=t.name.split(`:`)[1],r=this.getCircuitFeature(e,n);if(!r){console.warn(`没有找到对应的区段YD`,t.name,t.state);continue}if(t.state===`1`)this.setFeatureState(`track_circuit`,r.properties.code,{state:t.state,controlName:``,visiable:!0});else{let e=String(r.properties?.fromCode??``),n=String(r.properties?.toCode??``);try{let i=this.getCircuitState([e,n],null);i?(this.setFeatureState(`track_circuit`,r.properties.code,{state:i.circuitState,controlName:i.controlName,link:i.controlName===``?void 0:0,visiable:!0}),i.controlName!==``&&this.linkWhiteCircuits.push(r)):this.setFeatureState(`track_circuit`,r.properties.code,{state:t.state,visiable:!0})}catch(e){if(e instanceof Error&&e.message!==`End Loop`)throw e}}}this.queryFeatures(`track_circuit`).forEach(e=>{let t=String(e.properties?.code??``),n=this.linkWhiteCircuits.find(e=>String(e.properties?.code??``)===t);if(n){let t=this.getFeatureState(`track_circuit`,e.id);t.state!==`2`&&t.state!==2&&t.state!==`1`&&t.state!==1&&this.setFeatureState(`track_circuit`,e.properties.code,{state:2,link:1,controlName:n.properties?.controlName??``,visiable:!0})}}),this.applyHandSwitchPaths(n,e.switchInterlock)}applyHandSwitchPaths(e,t){let n=[];for(let r of this.firstSwitches)this.findHandSwitchPath(r,e,t,n,[]);n.forEach(e=>{this.setFeatureState(`track`,e,{state:5,visiable:!0})})}findHandSwitchPath(e,t,n,r,i){let a=this.findSwitchInfo(e,t,n);if(!this.validSwitchInfo(a))return;let o=this.getSwitchLocFeatures(e,t,a.state);for(let a of o){let o=String(a.properties?.t_code??``),s=String(a.properties?.s_code??``),c=this.getTrackByCode(o);if(!c)continue;let l=String(c.properties?.fromCode??``),u=String(c.properties?.toCode??``),d=c.properties?.fromLyr,f=c.properties?.toLyr,p=``,m=null;if(l===s?(p=u,m=f):u===s&&(p=l,m=d),m===2){let a=this.getSwitchByCode(p);if(a){r.push(o);let s=String(a.properties?.name??``),c=this.findSwitchInfo(s,t,n);c&&this.validSwitchInfo(c)&&!i.includes(s)&&this.doseTrackConnectSwitch(o,c)&&(i.push(e),this.findHandSwitchPath(s,t,n,r,i))}}else r.push(o)}}doseTrackConnectSwitch(e,t){let n=t.name.split(`:`)[0],r=t.name.split(`:`)[1];return this.getSwitchLocFeatures(n,r,t.state).some(t=>String(t.properties?.t_code??``)===e)}getCircuitState(e,t){let n=4,r=null;try{e.forEach((i,a)=>{let o=this.interLockInsulation.getSignalByInsulationKey(i),s=this.getInsulationSignalState(o??null);if(t==null&&s!=null&&(r=s),s==null&&t!=null&&(s={name:t.name,dir:t.dir,state:`3`}),s!=null&&s.state===`3`){n=2;let t=e.find(e=>e!==i),r=this.findNextCircuit(t,s);if(r!=null){let e=this.interLockInsulation.getSignalByInsulationKey(t);if(this.getControlSignalState(e??null,s)!=4){let e=String(r.properties?.fromCode??``),t=String(r.properties?.toCode??``),n={...r,properties:{...r.properties,controlName:s.name}};this.linkWhiteCircuits.push(n),this.getCircuitState([e,t],s)}}}})}catch(e){console.error(e)}return{circuitState:n,controlName:r==null?``:r.name}}findNextCircuit(e,t){let n=this.pathCircuits.find(n=>{let r=String(n.properties?.fromCode??``),i=String(n.properties?.toCode??``);return t.dir===`up`&&r===e||t.dir===`down`&&i===e});return n?this.linkWhiteCircuits.find(e=>String(e.properties?.code??``)===String(n.properties?.code??``))?null:n:null}getInsulationSignalState(e){if(!e)return null;if(e.upsignal){let t=this.getSignalById(String(e.upsignal));if(t){let e=String(t.properties?.name??``),n=String(t.properties?.stcode??``),r=this.interLockState.signal.get(e+`:`+n);if(r===`3`)return{name:e,state:r,dir:`up`}}}if(e.downsignal){let t=this.getSignalById(String(e.downsignal));if(t){let e=String(t.properties?.name??``),n=String(t.properties?.stcode??``),r=this.interLockState.signal.get(e+`:`+n);if(r===`3`)return{name:e,state:r,dir:`down`}}}return null}getControlSignalState(e,t){if(e){if(t.dir===`up`&&e.upsignal){let t=this.getSignalById(String(e.upsignal));if(t){let e=String(t.properties?.name??``),n=String(t.properties?.stcode??``);return this.interLockState.signal.get(e+`:`+n)}}if(t.dir===`down`&&e.downsignal){let t=this.getSignalById(String(e.downsignal));if(t){let e=String(t.properties?.name??``),n=String(t.properties?.stcode??``);return this.interLockState.signal.get(e+`:`+n)}}}}getSignalFeature(e,t){return this.queryFeatures(`signal`).find(n=>n.properties?.name===e&&String(n.properties?.code??``).includes(t))}getSignalById(e){return this.queryFeatures(`signal`).find(t=>String(t.id??t.properties?.code??``)===e)}getSwitchLocFeatures(e,t,n){let r=this.queryFeatures(`switch`).find(n=>n.properties?.name===e&&String(n.properties?.code??``).includes(t));if(!r)return[];let i=String(r.properties?.code??``),a=this.queryFeatures(`switch_loc`);return n===`4`?a.filter(e=>String(e.properties?.s_code??``)===i):a.filter(e=>String(e.properties?.s_code??``)===i&&(String(e.properties?.location??``)===n||String(e.properties?.location??``)===`1`))}getSwitchByCode(e){return this.queryFeatures(`switch`).find(t=>String(t.id??t.properties?.code??``)===e)}getTrackByCode(e){return this.queryFeatures(`track`).find(t=>String(t.id??t.properties?.code??``)===e)}getCircuitFeature(e,t){let n=this.queryFeatures(`track_circuit`).filter(n=>n.properties?.name===e&&String(n.properties?.code??``).includes(t));if(n.length===0)return;let r;if(n.length>=1&&(n[0].properties?.type===`1`||n[0].properties?.type===1))return n[0];for(let e of n){if(r)break;if(e.properties?.type===2||e.properties?.type===`2`){let t=String(e.properties?.switches??``).split(`,`),n=String(e.properties?.positions??``).replace(/\s+/g,``).split(`,`).filter(e=>e!==`1`);for(let i=0;i<t.length;i++){let a=t[i],o=n[i],s=this.getSwitchNameByCode(a);if(!s||o!==this.interLockState.switch.get(s+`:`+a.substring(0,9)))break;if(i==t.length-1){r=e;break}}}}return r}getSwitchNameByCode(e){let t=this.queryFeatures(`switch`).find(t=>String(t.properties?.code??``)===e);return t?String(t.properties?.name??``):void 0}findSwitchInfo(e,t,n){let r=e+`:`+t;return n.find(e=>e.name===r)??null}validSwitchInfo(e){return e?e.state===`2`||e.state===`3`:!1}arrToMap(e,t){t?.forEach(t=>e.set(t.name,t.state))}startRunning(){this.signalEnable=!0}stopRunning(){this.signalEnable=!1}setSendSignalCallback(e){this.onSendSignal=e}setStationSignalState(e){this.stationSignalState=e}sendSignal(){if(!this.signalEnable||this.interLockState.signal.size===0&&this.interLockState.switch.size===0&&this.interLockState.circuit.size===0)return;let e=Math.floor(Date.now()/1e3),t=new Map,n=[];this.interLockState.signal.forEach((e,n)=>{let r=n.split(`:`)[0],i=n.split(`:`)[1],a=t.get(i);a=a?a+r+`:`+e+`;`:r+`:`+e+`;`,t.set(i,a)}),t.forEach((e,n)=>{t.set(n,(e.endsWith(`;`)?e.slice(0,-1):e)+`&`)}),this.interLockState.switch.forEach((e,n)=>{let r=n.split(`:`)[0],i=n.split(`:`)[1],a=Number(e),o=t.get(i);if(o!==void 0)if(a===5||a===6){let t=a===5?2:3;o+=r+`:`+t+`;`,o+=r+`-F:`+e+`;`}else o+=r+`:`+e+`;`;else if(a===5||a===6){let t=a===5?2:3;o=`&`+r+`:`+t+`;`,o+=r+`-F:`+e+`;`}else o=`&`+r+`:`+e+`;`;t.set(i,o)}),t.forEach((e,n)=>{t.set(n,(e.endsWith(`;`)?e.slice(0,-1):e)+`&`)});let r=new Map;this.interLockState.circuit.forEach((e,t)=>{let n=t.split(`:`)[0],i=t.split(`:`)[1],a=i+`_`+n;r.get(a)?(e===`1`||e===`2`)&&r.set(a,{name:n,yard:i,state:e}):r.set(a,{name:n,yard:i,state:e})}),r.forEach(e=>{let n=t.get(e.yard);n=n?n+e.name+`:`+e.state+`;`:`& &`+e.name+`:`+e.state+`;`,t.set(e.yard,n)}),t.forEach((t,r)=>{let i=t.endsWith(`;`)?t.slice(0,-1):t;n.push(e+`&`+r+`&`+i)}),n.length>0&&this.onSendSignal?.(n)}pauseSignal(){this.interLockState.circuit.forEach((e,t)=>this.interLockState.circuit.set(t,`0`)),this.interLockState.signal.forEach((e,t)=>this.interLockState.signal.set(t,`0`)),this.interLockState.switch.forEach((e,t)=>this.interLockState.switch.set(t,`0`)),this.sendSignal()}collectStateAndSend(){if(!this.signalEnable)return;let e=Math.floor(Date.now()/1e3),t=new Map,n=[],r={red:`1`,green:`2`,white:`3`,blue:`4`};for(let e of this.queryFeatures(`signal`)){let n=String(e.properties?.name??``),i=String(e.properties?.code??``),a=String(e.properties?.stcode??i.substring(0,9));if(!n||!i||!a||!this.stationSignalState.includes(a))continue;let o=String(this.getFeatureState(`signal`,i)?.state??``);if(!o)continue;let s=r[o]??o,c=t.get(a);t.set(a,c?c+n+`:`+s+`;`:n+`:`+s+`;`)}t.forEach((e,n)=>t.set(n,(e.endsWith(`;`)?e.slice(0,-1):e)+`&`));let i=this.queryFeatures(`switch_loc`);for(let e of this.queryFeatures(`switch`)){let n=String(e.properties?.name??``),r=String(e.properties?.code??``),a=String(e.properties?.stcode??r.substring(0,9));if(!n||!r||!a||!this.stationSignalState.includes(a))continue;let o=i.find(e=>String(e.properties?.s_code??``)===r&&String(e.properties?.location??``)===`1`)??i.find(e=>String(e.properties?.s_code??``)===r);if(!o)continue;let s=String(this.getFeatureState(`switch_loc`,String(o.properties?.code??``))?.state??``);if(!s)continue;let c=Number(s),l=t.get(a);l===void 0?l=`&`+(c===5||c===6?n+`:`+(c===5?2:3)+`;`+n+`-F:`+s+`;`:n+`:`+s+`;`):l+=c===5||c===6?n+`:`+(c===5?2:3)+`;`+n+`-F:`+s+`;`:n+`:`+s+`;`,t.set(a,l)}t.forEach((e,n)=>t.set(n,(e.endsWith(`;`)?e.slice(0,-1):e)+`&`));let a=new Map;for(let e of this.queryFeatures(`track_circuit`)){let t=String(e.properties?.name??``),n=String(e.properties?.code??``),r=String(e.properties?.stcode??n.substring(0,9));if(!t||!n||!r||!this.stationSignalState.includes(r))continue;let i=String(this.getFeatureState(`track_circuit`,n)?.state??``);if(!i)continue;let o=r+`_`+t;a.get(o)?(i===`1`||i===`2`)&&a.set(o,{name:t,stcode:r,state:i}):a.set(o,{name:t,stcode:r,state:i})}a.forEach(e=>{let n=t.get(e.stcode);t.set(e.stcode,n?n+e.name+`:`+e.state+`;`:`& &`+e.name+`:`+e.state+`;`)}),t.forEach((t,r)=>{let i=t.endsWith(`;`)?t.slice(0,-1):t;n.push(e+`&`+r+`&`+i)}),n.length>0&&this.onSendSignal?.(n)}};function Ke(){if(!this.mapConfigs)return;let e=this.mapConfigs.id;this.mapConfigs.sourceLayers?.forEach(t=>{(t.includes(`switch`)||t.includes(`signal`)||t.includes(`track`))&&this.map.querySourceFeatures(e,{sourceLayer:t}).forEach(e=>{this.initGraphFeatureState(e)})})}function qe(e){if(!e||e.length<11)return``;let t=e.charAt(10),n=e.charAt(9);return t===`1`&&n===`0`?`track`:t===`3`?`signal`:t===`2`&&n===`0`||t===`1`&&n===`1`?`switch`:t===`2`&&n===`1`?`circuit`:``}function Je(e){if(!e)return;let t=e.properties.code,n=qe(t);if(n===`switch`){let t={state:``,visiable:!0};t.state=`2`;let n=e.properties;this.updateFeatureState(n.code,t)}else if(n===`signal`){let t=e.properties,n=t.attach||0,r=t.func_type,i={state:``,visiable:!0};r==1&&n==0||(r==2||r==3)&&n==0||(r==2||r==3||r==11)&&n==1?(i.state=`red`,this.updateFeatureState(t.code,i)):(r==4||r==5||r==12)&&n==0?(i.state=`blue`,this.updateFeatureState(t.code,i)):r==6&&n==0||(r==7||r==11)&&n==0?(i.state=`red`,this.updateFeatureState(t.code,i)):(i.state=``,this.updateFeatureState(t.code,i))}else if(n===`signal`||n===`circuit`){let t={state:``,visiable:!0},n=e.properties;this.updateFeatureState(n.code,t)}}function Ye(e){if(!e.mapConfigs)return;let t=e.mapConfigs.id,n=e.mapConfigs.layers?.reduce((t,n,r)=>(t[n]=e.mapConfigs.sourceLayers[r],t),{});if(n)return new Ge({map:e.map,sourceId:t,sourceLayers:n,updateFeatureState:(t,n)=>e.updateFeatureState(t,n)})}function Xe(e){e.initGraphFeatureState=Je,e.initState=Ke,e.interLockVisualization=Ye(e),e.map.once(`idle`,()=>{})}function Ze(){this.mapConfigs&&(this.mapConfigs.layers??[]).forEach(e=>{let t=`geojson_${e}`;this.map.getSource(t)&&this.stashFeatures.forEach(n=>{n.sourceLayer!==t||!n.properties||this.initGeoJsonFeatureState({properties:n.properties},e)})})}function Qe(e,t){if(!e)return;let n=e.properties,r=n?.code;if(r)if(t===`switch`||t===`switch_loc`)this.updateFeatureState(r,{state:`2`,visiable:!0});else if(t===`signal`){let e=n?.attach||0,t=n?.functionType,i={state:``,visiable:!0};t==1&&e==0||(t==2||t==3)&&e==0||(t==2||t==3||t==11)&&e==1||t==6&&e==0||(t==7||t==11)&&e==0?i.state=`red`:(t==4||t==5||t==12)&&e==0&&(i.state=`blue`),this.updateFeatureState(r,i)}else t===`track_circuit`&&this.updateFeatureState(r,{state:4,substate:1,visiable:!0})}function $e(e){if(!e.mapConfigs)return;let t=[`signal`,`switch`,`switch_loc`,`track_circuit`,`track`,`insulation`].reduce((e,t)=>(e[t]=`geojson_${t}`,e),{});return new Ge({mode:`geojson`,map:e.map,sourceIds:t,updateFeatureState:(t,n)=>e.updateFeatureState(t,n),queryGeojsonFeatures:t=>e.queryGeojsonFeatures(t)})}function et(e){e.initGeoJsonFeatureState=Qe,e.initGeoJsonState=Ze,e.interLockVisualization=$e(e),e.map.once(`idle`,()=>{})}function O(){return O=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},O.apply(null,arguments)}var k=`draw`,tt=`edit`,nt=`deleteCoordinate`,rt=`insertMidpoint`,A;(function(e){e.Commit=`commit`,e.Provisional=`provisional`,e.Finish=`finish`})(A||={});var it=`https://raw.githubusercontent.com/JamesLMilner/terra-draw/refs/heads/main/assets/markers/marker-blue.png`,j={SELECTED:`selected`,MID_POINT:`midPoint`,SELECTION_POINT_FEATURE_ID:`selectionPointFeatureId`,SELECTION_POINT:`selectionPoint`},M={MODE:`mode`,CURRENTLY_DRAWING:`currentlyDrawing`,EDITED:`edited`,CLOSING_POINT:`closingPoint`,SNAPPING_POINT:`snappingPoint`,COORDINATE_POINT:`coordinatePoint`,COORDINATE_POINT_FEATURE_ID:`coordinatePointFeatureId`,COORDINATE_POINT_IDS:`coordinatePointIds`,PROVISIONAL_COORDINATE_COUNT:`provisionalCoordinateCount`,COMMITTED_COORDINATE_COUNT:`committedCoordinateCount`,MARKER:`marker`},N=10;function at(e){return!!(e&&typeof e==`object`&&e&&!Array.isArray(e))}function ot(e){return!!(e&&typeof e==`object`&&`properties`in e&&typeof e.properties==`object`&&e.properties!==null&&`mode`in e.properties)}function st(e){return!!function(e){return typeof e==`number`&&!isNaN(new Date(e).valueOf())}(e)}var ct=`Feature mode property does not match the mode being added to`,lt;(function(e){e.Drawing=`drawing`,e.Select=`select`,e.Static=`static`,e.Render=`render`})(lt||={});var ut={rightClick:!0,contextMenu:!1,leftClick:!0,onDragStart:!0,onDrag:!0,onDragEnd:!0},P=class{get state(){return this._state}set state(e){throw Error(`Please use the modes lifecycle methods`)}get styles(){return this._styles}set styles(e){if(typeof e!=`object`)throw Error(`Styling must be an object`);this.onStyleChange&&this.onStyleChange([],`styling`),this._styles=e}registerBehaviors(e){}constructor(e,t=!1){this._state=`unregistered`,this._styles={},this.pointerEvents=ut,this.behaviors=[],this.validate=void 0,this.pointerDistance=40,this.coordinatePrecision=void 0,this.undoRedoMaxStackSize=void 0,this.onStyleChange=void 0,this.store=void 0,this.projection=`web-mercator`,this.setDoubleClickToZoom=void 0,this.unproject=void 0,this.project=void 0,this.setCursor=void 0,this.isInitialUpdate=!1,this.type=lt.Drawing,this.mode=`base`,t?this.isInitialUpdate=!0:this.updateOptions(O({},e))}updateOptions(e){e!=null&&e.styles&&(this.styles=O({},this._styles,e.styles)),e!=null&&e.pointerDistance&&(this.pointerDistance=e.pointerDistance),e!=null&&e.validation&&(this.validate=e&&e.validation),e!=null&&e.projection&&(this.projection=e.projection),e?.pointerEvents!==void 0&&(this.pointerEvents=e.pointerEvents),e!=null&&e.modeName&&!0===this.isInitialUpdate&&(this.mode=e.modeName),this.isInitialUpdate=!1}allowPointerEvent(e,t){return typeof e==`boolean`?e:typeof e!=`function`||e(t)}setDrawing(){if(this._state!==`started`)throw Error(`Mode must be unregistered or stopped to start`);this._state=`drawing`}setStarted(){if(this._state!==`stopped`&&this._state!==`registered`&&this._state!==`drawing`&&this._state!==`selecting`)throw Error(`Mode must be unregistered or stopped to start`);this._state=`started`,this.setDoubleClickToZoom(!1)}setStopped(){if(this._state!==`started`)throw Error(`Mode must be started to be stopped`);this._state=`stopped`,this.setDoubleClickToZoom(!0)}register(e){if(this._state!==`unregistered`)throw Error(`Can not register unless mode is unregistered`);this._state=`registered`,this.store=e.store,this.store.registerOnChange(e.onChange),this.setDoubleClickToZoom=e.setDoubleClickToZoom,this.project=e.project,this.unproject=e.unproject,this.onSelect=e.onSelect,this.onDeselect=e.onDeselect,this.setCursor=e.setCursor,this.onStyleChange=e.onChange,this.onFinish=e.onFinish,this.coordinatePrecision=e.coordinatePrecision,this.undoRedoMaxStackSize=e.undoRedoMaxStackSize,this.registerBehaviors({mode:e.mode,store:this.store,project:this.project,unproject:this.unproject,pointerDistance:this.pointerDistance,coordinatePrecision:e.coordinatePrecision,projection:this.projection,undoRedoMaxStackSize:e.undoRedoMaxStackSize})}validateFeature(e){return this.performFeatureValidation(e)}afterFeatureAdded(e){}afterFeatureUpdated(e){}performFeatureValidation(e){if(this._state===`unregistered`)throw Error(`Mode must be registered`);let t=function(e,t){let n;if(at(e))if(e.id==null)n=`Feature has no id`;else if(typeof e.id!=`string`&&typeof e.id!=`number`)n=`Feature must be string or number as per GeoJSON spec`;else if(t(e.id))if(at(e.geometry))if(at(e.properties))if(typeof e.geometry.type==`string`&&[`Polygon`,`LineString`,`Point`].includes(e.geometry.type))if(Array.isArray(e.geometry.coordinates)){if(!e.properties.mode||typeof e.properties.mode!=`string`)return{valid:!1,reason:`Feature does not have a valid mode property`}}else n=`Feature coordinates is not an array`;else n=`Feature is not Point, LineString or Polygon`;else n=`Feature has no properties`;else n=`Feature has no geometry`;else n=`Feature must match the id strategy (default is UUID4)`;else n=`Feature is not object`;return n?{valid:!1,reason:n}:{valid:!0}}(e,this.store.idStrategy.isValidId);if(!t.valid)return t;if(this.validate){let n=this.validate(e,{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:A.Provisional});return{valid:t.valid&&n.valid,reason:n.reason}}return{valid:t.valid,reason:t.reason}}validateModeFeature(e,t){let n=this.performFeatureValidation(e);return n.valid?e.properties.mode===this.mode?t(e):{valid:!1,reason:ct}:{valid:!1,reason:n.reason}}onFinish(e,t){}onDeselect(e){}onSelect(e){}onKeyDown(e){}onKeyUp(e){}undo(){}clearHistory(){}undoSize(){return 0}redoSize(){return 0}redo(){}onMouseMove(e){}onClick(e){}onDragStart(e,t){}onDrag(e,t){}onDragEnd(e,t){}getHexColorStylingValue(e,t,n){return this.getStylingValue(e,t,n)}getNumericStylingValue(e,t,n){return this.getStylingValue(e,t,n)}getUrlStylingValue(e,t,n){return this.getStylingValue(e,t,n)}getStylingValue(e,t,n){return e===void 0?t:typeof e==`function`?(r=e(n))??t:e;var r}},dt=class extends P{constructor(...e){super(...e),this.type=lt.Select}};function F(e,t){let n=e=>e*Math.PI/180,r=n(e[1]),i=n(e[0]),a=n(t[1]),o=a-r,s=n(t[0])-i,c=Math.sin(o/2)*Math.sin(o/2)+Math.cos(r)*Math.cos(a)*Math.sin(s/2)*Math.sin(s/2);return 2*Math.atan2(Math.sqrt(c),Math.sqrt(1-c))*6371e3/1e3}var ft=6371008.8;function I(e){return e%360*Math.PI/180}function pt(e){return e/6371.0088}function L(e){return e%(2*Math.PI)*180/Math.PI}function R(e,t=9){let n=10**t;return Math.round(e*n)/n}var mt=57.29577951308232,ht=.017453292519943295,gt=6378137,z=(e,t)=>({x:e===0?0:e*ht*gt,y:t===0?0:Math.log(Math.tan(Math.PI/4+t*ht/2))*gt}),B=(e,t)=>({lng:e===0?0:e/gt*mt,lat:t===0?0:(2*Math.atan(Math.exp(t/gt))-Math.PI/2)*mt});function _t(e,t,n){let r=I(e[0]),i=I(e[1]),a=I(n),o=pt(t),s=Math.asin(Math.sin(i)*Math.cos(o)+Math.cos(i)*Math.sin(o)*Math.cos(a));return[L(r+Math.atan2(Math.sin(a)*Math.sin(o)*Math.cos(i),Math.cos(o)-Math.sin(i)*Math.sin(s))),L(s)]}function vt(e){let{center:t,radiusKilometers:n,coordinatePrecision:r}=e,i=e.steps?e.steps:64,a=[];for(let e=0;e<i;e++){let o=_t(t,n,-360*e/i);a.push([R(o[0],r),R(o[1],r)])}return a.push(a[0]),{type:`Feature`,geometry:{type:`Polygon`,coordinates:[a]},properties:{}}}function yt(e){let t;if(e.geometry.type===`Polygon`)t=e.geometry.coordinates;else{if(e.geometry.type!==`LineString`)throw Error(`Self intersects only accepts Polygons and LineStrings`);t=[e.geometry.coordinates]}let n=[];for(let e=0;e<t.length;e++)for(let n=0;n<t[e].length-1;n++)for(let r=0;r<t.length;r++)for(let a=0;a<t[r].length-1;a++)i(e,n,r,a);return n.length>0;function r(e){return e<0||e>1}function i(e,i,a,o){let s=t[e][i],c=t[e][i+1],l=t[a][o],u=t[a][o+1],d=function(e,t,n,r){if(bt(e,n)||bt(e,r)||bt(t,n)||bt(r,n))return null;let i=e[0],a=e[1],o=t[0],s=t[1],c=n[0],l=n[1],u=r[0],d=r[1],f=(i-o)*(l-d)-(a-s)*(c-u);return f===0?null:[((i*s-a*o)*(c-u)-(i-o)*(c*d-l*u))/f,((i*s-a*o)*(l-d)-(a-s)*(c*d-l*u))/f]}(s,c,l,u);if(d===null)return;let f,p;f=c[0]===s[0]?(d[1]-s[1])/(c[1]-s[1]):(d[0]-s[0])/(c[0]-s[0]),p=u[0]===l[0]?(d[1]-l[1])/(u[1]-l[1]):(d[0]-l[0])/(u[0]-l[0]),r(f)||r(p)||(d.toString(),n.push(d))}}function bt(e,t){return e[0]===t[0]&&e[1]===t[1]}function xt(e,t){return Ct(e[0])<=t&&Ct(e[1])<=t}function St(e){return e.length===2&&typeof e[0]==`number`&&typeof e[1]==`number`&&e[0]!==1/0&&e[1]!==1/0&&(n=e[0])>=-180&&n<=180&&(t=e[1])>=-90&&t<=90;var t,n}function Ct(e){let t=1,n=0;for(;Math.round(e*t)/t!==e;)t*=10,n++;return n}var wt=`Feature has holes`,Tt=`Feature has less than 4 coordinates`,Et=`Feature has invalid coordinates`,Dt=`Feature coordinates are not closed`;function Ot(e,t){if(e.geometry.type!==`Polygon`)return{valid:!1,reason:`Feature is not a Polygon`};if(e.geometry.coordinates.length!==1)return{valid:!1,reason:wt};if(e.geometry.coordinates[0].length<4)return{valid:!1,reason:Tt};for(let n=0;n<e.geometry.coordinates[0].length;n++){if(!St(e.geometry.coordinates[0][n]))return{valid:!1,reason:Et};if(!xt(e.geometry.coordinates[0][n],t))return{valid:!1,reason:`Feature has coordinates with excessive precision`}}return(n=e.geometry.coordinates[0][0])[0]!==(r=e.geometry.coordinates[0][e.geometry.coordinates[0].length-1])[0]||n[1]!==r[1]?{valid:!1,reason:Dt}:{valid:!0};var n,r}function kt(e,t){let n=Ot(e,t);return n.valid?yt(e)?{valid:!1,reason:`Feature intersects itself`}:{valid:!0}:n}var V=class{constructor({store:e,mode:t,project:n,unproject:r,pointerDistance:i,coordinatePrecision:a,projection:o,undoRedoMaxStackSize:s}){this.store=void 0,this.mode=void 0,this.project=void 0,this.unproject=void 0,this.pointerDistance=void 0,this.coordinatePrecision=void 0,this.projection=void 0,this.undoRedoMaxStackSize=void 0,this.store=e,this.mode=t,this.project=n,this.unproject=r,this.pointerDistance=i,this.coordinatePrecision=a,this.projection=o,this.undoRedoMaxStackSize=s}};function At(e){if(!function(e){let t=e.coordinates[0],n=0;for(let e=0;e<t.length-1;e++){let[r,i]=t[e],[a,o]=t[e+1];n+=(a-r)*(o+i)}return n<0}(e))return{type:`Polygon`,coordinates:[e.coordinates[0].reverse()]}}var jt=`insert-before`,Mt=`insert-after`,H=`update`,Nt=`delete`,U=`replace`,W=class extends V{constructor(e,t){super(e),this.options=void 0,this.options=t}createPoint({coordinates:e,properties:t,context:n}){if(n?.updateType!==A.Finish||this.validateGeometryWithUpdateType({geometry:{type:`Point`,coordinates:e},properties:t,updateType:A.Finish}))return this.handleCreateFeature({geometry:{type:`Point`,coordinates:e},properties:t})}createLineString({coordinates:e,properties:t}){return this.handleCreateFeature({geometry:{type:`LineString`,coordinates:e},properties:t})}createPolygon({coordinates:e,properties:t}){let n=At({type:`Polygon`,coordinates:[e]});return this.handleCreateFeature({geometry:{type:`Polygon`,coordinates:n?n.coordinates:[e]},properties:t})}createGuidancePoint({coordinate:e,type:t}){return this.createGuidancePoints({coordinates:[e],type:t})[0]}createGuidancePoints({coordinates:e,type:t,additionalProperties:n}){let r=e.map((e,r)=>({type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:O({mode:this.mode,[t]:!0},n?n(r):{})}));return this.createFeatures(r)}updatePoint({featureId:e,coordinateMutations:t,propertyMutations:n,context:r}){return this.handleMutateFeature({type:`Point`,featureId:e,coordinateMutations:t,propertyMutations:n,context:r})}updatePolygon({featureId:e,coordinateMutations:t,context:n,propertyMutations:r}){return this.handleMutateFeature({type:`Polygon`,featureId:e,coordinateMutations:t,propertyMutations:r,context:n})}updateLineString({featureId:e,coordinateMutations:t,context:n,propertyMutations:r}){return this.handleMutateFeature({type:`LineString`,featureId:e,coordinateMutations:t,propertyMutations:r,context:n})}deleteFeatureIfPresent(e){e&&this.store.has(e)&&this.store.delete([e])}deleteFeaturesIfPresent(e){if(e.length===0)return;let t=e.filter(e=>this.store.has(e));t.length&&this.store.delete(t)}setDeselected(e){let t=e.filter(e=>this.store.has(e)).map(e=>({featureId:e,properties:{[j.SELECTED]:!1}}));this.updateFeatureProperties(t)}setSelected(e){let{type:t}=this.store.getGeometryCopy(e),n={featureId:e,propertyMutations:{[j.SELECTED]:!0},context:{updateType:A.Commit}};t===`Polygon`?this.updatePolygon(n):t===`LineString`?this.updateLineString(n):t===`Point`&&this.updatePoint(n)}updateGuidancePoints(e){this.updateFeatureGeometries(e.map(({featureId:e,coordinate:t})=>({id:e,geometry:{type:`Point`,coordinates:t}})))}handleCreateFeature({geometry:e,properties:t}){return this.createFeatureWithGeometry({geometry:e,properties:t})}handleMutateFeature({type:e,featureId:t,coordinateMutations:n,propertyMutations:r,context:i}){if(!this.mutateFeature({type:e,featureId:t,coordinateMutations:n,propertyMutations:r,context:i.updateType===A.Finish?O({},i,{correctRightHandRule:!0}):O({},i)}))return null;let a=this.buildFeatureWithGeometry(t);return i.updateType!==A.Finish||n||this.validateGeometryWithUpdateType({geometry:a.geometry,properties:a.properties,updateType:i.updateType})?a:null}mutateFeature({type:e,featureId:t,coordinateMutations:n,propertyMutations:r,context:i}){if(!t)return!1;let a=this.store.getGeometryCopy(t),o=this.store.getPropertiesCopy(t);if(a.type!==e)throw Error(`${e} geometries cannot be updated on features with ${a.type} geometries`);if(n){let e=this.applyCoordinateMutations(a,n);if(i.correctRightHandRule&&e.type===`Polygon`){let t=At(e);t&&(e=t)}if(!this.validateGeometryWithUpdateType({geometry:e,properties:o,updateType:i.updateType}))return!1;this.updateFeatureGeometries([{id:t,geometry:e}])}return r&&this.updateFeatureProperties([{featureId:t,properties:r}]),!0}applyCoordinateMutations(e,t){if(this.isReplaceMutation(t))return O({},e,{coordinates:t.coordinates});if(e.type===`Point`)throw Error(`Coordinate mutations are not supported for Point geometries`);let n=e.type===`Polygon`,r=n?e.coordinates[0].slice():e.coordinates.slice(),i=r.length,a=e=>{let t=e<0?i+e:e;if(t<0||t>=i)throw RangeError(`Index ${e} (normalized to ${t}) is out of bounds`);return t},o=Array(i).fill(void 0),s=Array.from({length:i},()=>[]),c=Array.from({length:i},()=>[]),l=[];for(let e of t){if(e.type===jt||e.type===Mt){let t=e.index,n=t<0?i+t:t;if(n<0||n>i)throw RangeError(`Index ${e.index} (normalized to ${n}) is out of bounds`);if(e.type===jt){if(n>=i)throw RangeError(`INSERT_BEFORE index ${e.index} (normalized to ${n}) is out of bounds for length ${i}`);s[n].push(e)}else n===i?l.push(e):c[n].push(e);continue}let t=a(e.index);o[t]=O({},e,{index:t})}let u=[];for(let e=0;e<i;e++){let t=s[e];for(let e of t)u.push(e.coordinate);let n=o[e];n?n.type===Nt||u.push(n.coordinate):u.push(r[e]);let i=c[e];for(let e of i)u.push(e.coordinate)}for(let e of l)u.push(e.coordinate);return O({},e,n?{coordinates:[u,...e.coordinates.slice(1)]}:{coordinates:u})}isReplaceMutation(e){return e.type===U}createFeatureWithGeometry({geometry:e,properties:t}){let[n]=this.createFeatures([{type:`Feature`,geometry:e,properties:t}]);return{id:n,type:`Feature`,properties:this.store.getPropertiesCopy(n),geometry:this.store.getGeometryCopy(n)}}validateGeometryWithUpdateType({geometry:e,properties:t,updateType:n}){return!this.options.validate||this.options.validate({type:`Feature`,geometry:e,properties:t||{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:n}).valid}buildFeatureWithGeometry(e){return{id:e,type:`Feature`,properties:this.store.getPropertiesCopy(e),geometry:this.store.getGeometryCopy(e)}}createFeatures(e){return this.store.create(e)}updateFeatureGeometries(e){this.store.updateGeometry(e)}updateFeatureProperties(e){let t=e.map(({featureId:e,properties:t})=>Object.entries(t).map(([t,n])=>({id:e,property:t,value:n}))).flat();this.store.updateProperty(t)}},Pt={cancel:`Escape`,finish:`Enter`},Ft={start:`crosshair`},It=class extends P{constructor(e){super(e,!0),this.mode=`circle`,this.center=void 0,this.endPosition=void 0,this.segments=64,this.currentCircleId=void 0,this.keyEvents=Pt,this.cursors=Ft,this.startingRadiusKilometers=1e-5,this.cursorMovedAfterInitialCursorDown=!1,this.drawInteraction=`click-move`,this.drawType=void 0,this.mutateFeature=void 0,this.updateOptions(e)}updateOptions(e){super.updateOptions(e),e!=null&&e.cursors&&(this.cursors=O({},this.cursors,e.cursors)),e?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:e!=null&&e.keyEvents&&(this.keyEvents=O({},this.keyEvents,e.keyEvents)),e!=null&&e.startingRadiusKilometers&&(this.startingRadiusKilometers=e.startingRadiusKilometers),e!=null&&e.drawInteraction&&(this.drawInteraction=e.drawInteraction),e!=null&&e.segments&&(this.segments=e.segments<3?3:e.segments)}close(){if(this.currentCircleId===void 0||this.endPosition===void 0||!this.updateCircle(this.endPosition,A.Finish))return;let e=this.currentCircleId;this.cursorMovedAfterInitialCursorDown=!1,this.center=void 0,this.currentCircleId=void 0,this.drawType=void 0,this.state===`drawing`&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:k})}beginDrawing(e,t=`click`){this.center=[e.lng,e.lat],this.endPosition=[e.lng,e.lat];let n=vt({center:this.center,radiusKilometers:this.startingRadiusKilometers,coordinatePrecision:this.coordinatePrecision}),r=this.mutateFeature.createPolygon({coordinates:n.geometry.coordinates[0],properties:{mode:this.mode,radiusKilometers:this.startingRadiusKilometers,[M.CURRENTLY_DRAWING]:!0}});r&&(this.currentCircleId=r.id,this.cursorMovedAfterInitialCursorDown=!1,this.drawType=t,this.setDrawing())}dragDrawAllowed(){return this.drawInteraction===`click-drag`||this.drawInteraction===`click-move-or-drag`}moveDrawAllowed(){return this.drawInteraction===`click-move`||this.drawInteraction===`click-move-or-drag`}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onClick(e){this.moveDrawAllowed()&&(e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e))&&(this.center?this.center&&this.currentCircleId!==void 0&&(this.endPosition=[e.lng,e.lat],this.close()):this.beginDrawing(e))}onMouseMove(e){this.cursorMovedAfterInitialCursorDown=!0,this.endPosition=[e.lng,e.lat],this.updateCircle(this.endPosition,A.Provisional)}onKeyDown(){}onKeyUp(e){e.key===this.keyEvents.cancel?this.cleanUp():e.key===this.keyEvents.finish&&this.close()}onDragStart(e,t){this.state!==`drawing`&&this.allowPointerEvent(this.pointerEvents.onDragStart,e)&&this.dragDrawAllowed()&&(this.beginDrawing(e,`drag`),t(!1))}onDrag(e,t){this.allowPointerEvent(this.pointerEvents.onDrag,e)&&this.dragDrawAllowed()&&this.drawType===`drag`&&(this.cursorMovedAfterInitialCursorDown=!0,this.endPosition=[e.lng,e.lat],this.updateCircle(this.endPosition,A.Provisional))}onDragEnd(e,t){this.allowPointerEvent(this.pointerEvents.onDragEnd,e)&&this.dragDrawAllowed()&&this.drawType===`drag`&&(this.endPosition=[e.lng,e.lat],this.close(),t(!0))}cleanUp(){let e=this.currentCircleId;this.center=void 0,this.currentCircleId=void 0,this.drawType=void 0,this.state===`drawing`&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(e)}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return e.type===`Feature`&&e.geometry.type===`Polygon`&&e.properties.mode===this.mode?(t.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,t.polygonFillColor,e),t.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,t.polygonOutlineColor,e),t.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,t.polygonOutlineWidth,e),t.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,e),t.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,t.polygonFillOpacity,e),t.zIndex=N,t):t}validateFeature(e){return this.validateModeFeature(e,e=>kt(e,this.coordinatePrecision))}updateCircle(e,t){if(this.currentCircleId===void 0||this.center===void 0)return;let n=t===A.Finish,r,i;if(this.cursorMovedAfterInitialCursorDown)if(i=F(this.center,e),this.projection===`web-mercator`){let t=function(e,t){let n=1e3*F(e,t);if(n===0)return 1;let{x:r,y:i}=z(e[0],e[1]),{x:a,y:o}=z(t[0],t[1]);return Math.sqrt((a-r)**2+(o-i)**2)/n}(this.center,e);r=function(e){let{center:t,radiusKilometers:n,coordinatePrecision:r}=e,i=e.steps?e.steps:64,a=1e3*n,[o,s]=t,{x:c,y:l}=z(o,s),u=[];for(let e=0;e<i;e++){let t=360*e/i*Math.PI/180,n=a*Math.cos(t),o=a*Math.sin(t),[s,d]=[c+n,l+o],{lng:f,lat:p}=B(s,d);u.push([R(f,r),R(p,r)])}return u.push(u[0]),{type:`Feature`,geometry:{type:`Polygon`,coordinates:[u]},properties:{}}}({center:this.center,radiusKilometers:i*t,coordinatePrecision:this.coordinatePrecision,steps:this.segments})}else{if(this.projection!==`globe`)throw Error(`Invalid projection`);r=vt({center:this.center,radiusKilometers:i,coordinatePrecision:this.coordinatePrecision,steps:this.segments})}let a={};return r&&i&&(a.radiusKilometers=i),n&&(a[M.CURRENTLY_DRAWING]=void 0),this.mutateFeature.updatePolygon({featureId:this.currentCircleId,coordinateMutations:r?{type:U,coordinates:r.geometry.coordinates}:void 0,propertyMutations:a,context:n?{updateType:t,action:k}:{updateType:t}})}afterFeatureUpdated(e){this.currentCircleId===e.id&&(this.cursorMovedAfterInitialCursorDown=!1,this.center=void 0,this.currentCircleId=void 0,this.drawType=void 0,this.state===`drawing`&&this.setStarted())}registerBehaviors(e){this.mutateFeature=new W(e,{validate:this.validate})}},G=(e,t)=>{let{x:n,y:r}=e,{x:i,y:a}=t,o=i-n,s=a-r;return Math.sqrt(s*s+o*o)};function Lt(e,t){return e[0]===t[0]&&e[1]===t[1]}var K=class extends V{constructor(e){super(e)}getGeometryType(e){return this.store.getGeometryCopy(e).type}coordinateAtIndexIsIdentical({featureId:e,newCoordinate:t,index:n}){let r=this.store.getGeometryCopy(e),i;if(r.type===`Polygon`)i=r.coordinates[0][n];else if(r.type===`LineString`)i=r.coordinates[n];else{if(n!==0)throw Error(`Point geometries only have one coordinate at index 0`);i=r.coordinates}return Lt(t,i)}getGeometry(e){return this.store.getGeometryCopy(e)}getCoordinates(e){let{type:t,coordinates:n}=this.store.getGeometryCopy(e);return t===`Polygon`?n[0]:n}getCoordinate(e,t){let n=this.getCoordinates(e),r=t<0?n.length+t:t;if(r<0||r>=n.length)throw RangeError(`Index ${t} (normalized to ${r}) is out of bounds`);return n[r]}getProperties(e){return this.store.getPropertiesCopy(e)}hasFeature(e){return this.store.has(e)}getAllFeatureIdsWhere(e){return this.store.copyAllWhere(e).map(({id:e})=>e)}},Rt={cancel:`Escape`,finish:`Enter`},zt={start:`crosshair`,close:`pointer`},Bt=class extends P{constructor(e){super(e,!0),this.mode=`freehand`,this.canClose=!1,this.currentId=void 0,this.closingPointId=void 0,this.minDistance=20,this.keyEvents=Rt,this.cursors=zt,this.preventPointsNearClose=!0,this.autoClose=!1,this.autoCloseTimeout=500,this.hasLeftStartingPoint=!1,this.preventNewFeature=!1,this.drawInteraction=`click-move`,this.drawType=void 0,this.smoothing=0,this.mutateFeature=void 0,this.readFeature=void 0,this.updateOptions(e)}updateOptions(e){super.updateOptions(e),e!=null&&e.minDistance&&(this.minDistance=e.minDistance),e?.smoothing!==void 0&&(this.smoothing=Math.min(Math.max(e.smoothing,0),.999)),e?.preventPointsNearClose!==void 0&&(this.preventPointsNearClose=e.preventPointsNearClose),e?.autoClose!==void 0&&(this.autoClose=e.autoClose),e!=null&&e.autoCloseTimeout&&(this.autoCloseTimeout=e.autoCloseTimeout),e?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:e!=null&&e.keyEvents&&(this.keyEvents=O({},this.keyEvents,e.keyEvents)),e!=null&&e.cursors&&(this.cursors=O({},this.cursors,e.cursors)),e!=null&&e.drawInteraction&&(this.drawInteraction=e.drawInteraction)}moveDrawAllowed(){return this.drawInteraction===`click-move`||this.drawInteraction===`click-move-or-drag`}dragDrawAllowed(){return this.drawInteraction===`click-drag`||this.drawInteraction===`click-move-or-drag`}beginDrawing(e,t=`click`){let{id:n}=this.mutateFeature.createPolygon({coordinates:[[e.lng,e.lat],[e.lng,e.lat],[e.lng,e.lat],[e.lng,e.lat]],properties:{mode:this.mode,[M.CURRENTLY_DRAWING]:!0}});this.currentId=n,this.drawType=t,this.closingPointId=this.mutateFeature.createGuidancePoint({coordinate:[e.lng,e.lat],type:M.CLOSING_POINT}),this.canClose=!0,this.state!==`drawing`&&this.setDrawing()}addCoordinate(e){if(this.currentId===void 0||!1===this.canClose)return void this.setCursor(this.cursors.start);let[t,n]=this.readFeature.getCoordinate(this.currentId,-2),{x:r,y:i}=this.project(t,n),a=G({x:r,y:i},{x:e.containerX,y:e.containerY}),[o,s]=this.readFeature.getCoordinate(this.currentId,0),{x:c,y:l}=this.project(o,s);if(G({x:c,y:l},{x:e.containerX,y:e.containerY})<this.pointerDistance){if(this.autoClose&&this.hasLeftStartingPoint&&(this.preventNewFeature=!0,setTimeout(()=>{this.preventNewFeature=!1},this.autoCloseTimeout),this.close()),this.setCursor(this.cursors.close),this.preventPointsNearClose)return}else this.hasLeftStartingPoint=!0,this.setCursor(this.cursors.start);if(a<this.minDistance)return;let u=this.getSmoothedCoordinate([t,n],[e.lng,e.lat]);this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:jt,index:-1,coordinate:u}],context:{updateType:A.Provisional}})}getSmoothedCoordinate(e,t){if(this.smoothing===0)return t;let[n,r]=e,[i,a]=t;return[n*this.smoothing+i*(1-this.smoothing),r*this.smoothing+a*(1-this.smoothing)]}close(){if(this.currentId===void 0||!this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:{[M.CURRENTLY_DRAWING]:void 0},context:{updateType:A.Finish,action:k}}))return;let e=this.currentId;this.mutateFeature.deleteFeatureIfPresent(this.closingPointId),this.canClose=!1,this.currentId=void 0,this.closingPointId=void 0,this.hasLeftStartingPoint=!1,this.drawType=void 0,this.state===`drawing`&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:k})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onMouseMove(e){this.moveDrawAllowed()&&this.drawType===`click`&&this.addCoordinate(e)}onClick(e){if(this.moveDrawAllowed()&&(e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e))){if(this.preventNewFeature)return;if(!1===this.canClose)return void this.beginDrawing(e);this.close()}}onKeyDown(){}onKeyUp(e){e.key===this.keyEvents.cancel?this.cleanUp():e.key===this.keyEvents.finish&&!0===this.canClose&&this.close()}onDragStart(e,t){this.state!==`drawing`&&(this.preventNewFeature||this.allowPointerEvent(this.pointerEvents.onDragStart,e)&&this.dragDrawAllowed()&&(this.beginDrawing(e,`drag`),t(!1)))}onDrag(e,t){this.allowPointerEvent(this.pointerEvents.onDrag,e)&&this.dragDrawAllowed()&&this.drawType===`drag`&&this.addCoordinate(e)}onDragEnd(e,t){this.allowPointerEvent(this.pointerEvents.onDragEnd,e)&&this.dragDrawAllowed()&&this.drawType===`drag`&&(this.preventNewFeature=!0,setTimeout(()=>{this.preventNewFeature=!1},this.autoCloseTimeout),this.close(),t(!0))}cleanUp(){let e=this.currentId,t=this.closingPointId;this.closingPointId=void 0,this.currentId=void 0,this.canClose=!1,this.hasLeftStartingPoint=!1,this.drawType=void 0,this.state===`drawing`&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(e),this.mutateFeature.deleteFeatureIfPresent(t)}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return e.type===`Feature`&&e.geometry.type===`Polygon`&&e.properties.mode===this.mode?(t.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,t.polygonFillColor,e),t.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,t.polygonOutlineColor,e),t.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,e),t.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,t.polygonOutlineWidth,e),t.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,t.polygonFillOpacity,e),t.zIndex=N,t):e.type===`Feature`&&e.geometry.type===`Point`&&e.properties.mode===this.mode?(t.pointWidth=this.getNumericStylingValue(this.styles.closingPointWidth,t.pointWidth,e),t.pointColor=this.getHexColorStylingValue(this.styles.closingPointColor,t.pointColor,e),t.pointOpacity=this.getNumericStylingValue(this.styles.closingPointOpacity,t.pointOpacity===void 0?1:t.pointOpacity,e),t.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,t.pointOutlineColor,e),t.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,e),t.pointOutlineOpacity=this.getNumericStylingValue(this.styles.closingPointOutlineOpacity,t.pointOutlineOpacity===void 0?1:t.pointOutlineOpacity,e),t.zIndex=50,t):t}validateFeature(e){return this.validateModeFeature(e,e=>Ot(e,this.coordinatePrecision))}afterFeatureUpdated(e){this.currentId===e.id&&(this.mutateFeature.deleteFeatureIfPresent(this.closingPointId),this.canClose=!1,this.currentId=void 0,this.closingPointId=void 0,this.hasLeftStartingPoint=!1)}registerBehaviors(e){this.readFeature=new K(e),this.mutateFeature=new W(e,{validate:this.validate})}};function Vt({unproject:e,point:t,pointerDistance:n}){let r=n/2,{x:i,y:a}=t;return{type:`Feature`,properties:{},geometry:{type:`Polygon`,coordinates:[[e(i-r,a-r),e(i+r,a-r),e(i+r,a+r),e(i-r,a+r),e(i-r,a-r)].map(e=>[e.lng,e.lat])]}}}var Ht=class extends V{constructor(e){super(e)}create(e){let{containerX:t,containerY:n}=e;return Vt({unproject:this.unproject,point:{x:t,y:n},pointerDistance:this.pointerDistance})}},Ut=class extends V{constructor(e){super(e)}measure(e,t){let{x:n,y:r}=this.project(t[0],t[1]);return G({x:n,y:r},{x:e.containerX,y:e.containerY})}},Wt=class extends V{constructor(e,t,n){super(e),this.config=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.getSnappableCoordinateFirstClick=e=>this.getSnappable(e,e=>!!(e.properties&&e.properties.mode===this.mode)).coordinate,this.getSnappableCoordinate=(e,t)=>this.getSnappable(e,e=>!!(e.properties&&e.properties.mode===this.mode&&e.id!==t)).coordinate,this.config=e,this.pixelDistance=t,this.clickBoundingBox=n}getSnappable(e,t){let n=this.clickBoundingBox.create(e),r=this.store.search(n,t),i={featureId:void 0,featureCoordinateIndex:void 0,coordinate:void 0,minDist:1/0};return r.forEach(t=>{let n;if(t.geometry.type===`Polygon`)n=t.geometry.coordinates[0];else{if(t.geometry.type!==`LineString`)return;n=t.geometry.coordinates}n.forEach((n,r)=>{let a=this.pixelDistance.measure(e,n);a<i.minDist&&a<this.pointerDistance&&(i.coordinate=n,i.minDist=a,i.featureId=t.id,i.featureCoordinateIndex=r)})}),i}};function Gt(e,t,n){let r=I(e[0]),i=I(e[1]),a=I(n),o=pt(t),s=Math.asin(Math.sin(i)*Math.cos(o)+Math.cos(i)*Math.sin(o)*Math.cos(a));return[L(r+Math.atan2(Math.sin(a)*Math.sin(o)*Math.cos(i),Math.cos(o)-Math.sin(i)*Math.sin(s))),L(s)]}function Kt({x:e,y:t},n,r){let i=I(r);return{x:e+n*Math.cos(i),y:t+n*Math.sin(i)}}function qt(e,t){let n=I(e[0]),r=I(t[0]),i=I(e[1]),a=I(t[1]),o=Math.sin(r-n)*Math.cos(a),s=Math.cos(i)*Math.sin(a)-Math.sin(i)*Math.cos(a)*Math.cos(r-n);return L(Math.atan2(o,s))}function q({x:e,y:t},{x:n,y:r}){let i=n-e,a=r-t;if(i===0&&a===0)return 0;let o=Math.atan2(a,i);return o*=180/Math.PI,o>180?o-=360:o<-180&&(o+=360),o}function Jt(e){return(e+360)%360}function Yt(e,t,n){let r=[],i=e.length,a,o,s,c=0;for(let i=0;i<e.length&&!(t>=c&&i===e.length-1);i++){if(c>t&&r.length===0){if(a=t-c,!a)return r.push(e[i]),r;o=qt(e[i],e[i-1])-180,s=Gt(e[i],a,o),r.push(s)}if(c>=n)return a=n-c,a?(o=qt(e[i],e[i-1])-180,s=Gt(e[i],a,o),r.push(s),r):(r.push(e[i]),r);if(c>=t&&r.push(e[i]),i===e.length-1)return r;c+=F(e[i],e[i+1])}if(c<t&&e.length===i)throw Error(`Start position is beyond line`);let l=e[e.length-1];return[l,l]}function Xt(e){return Math.PI/180*e}function Zt(e){return 180/Math.PI*e}var Qt=class extends V{constructor(e){super(e),this.config=void 0,this.config=e}generateInsertionCoordinates(e,t,n){let r=[e,t],i=0;for(let e=0;e<r.length-1;e++)i+=F(r[0],r[1]);if(i<=n)return r;let a=i/n-1;Number.isInteger(a)||(a=Math.floor(a)+1);let o=[];for(let e=0;e<a;e++){let t=Yt(r,n*e,n*(e+1));o.push(t)}let s=[];for(let e=0;e<o.length;e++)s.push(o[e][1]);return this.limitCoordinates(s)}generateInsertionGeodesicCoordinates(e,t,n){let r=F(e,t),i=function(e,t,n){let r=[],i=Xt(e[1]),a=Xt(e[0]),o=Xt(t[1]),s=Xt(t[0]);n+=1;let c=2*Math.asin(Math.sqrt(Math.sin((o-i)/2)**2+Math.cos(i)*Math.cos(o)*Math.sin((s-a)/2)**2));if(c===0||isNaN(c))return r;for(let e=0;e<=n;e++){let t=e/n,l=Math.sin((1-t)*c)/Math.sin(c),u=Math.sin(t*c)/Math.sin(c),d=l*Math.cos(i)*Math.cos(a)+u*Math.cos(o)*Math.cos(s),f=l*Math.cos(i)*Math.sin(a)+u*Math.cos(o)*Math.sin(s),p=l*Math.sin(i)+u*Math.sin(o);if(isNaN(d)||isNaN(f)||isNaN(p))continue;let m=Math.atan2(p,Math.sqrt(d**2+f**2)),h=Math.atan2(f,d);isNaN(m)||isNaN(h)||r.push([Zt(h),Zt(m)])}return r.slice(1,-1)}(e,t,Math.floor(r/n));return this.limitCoordinates(i)}limitCoordinates(e){return e.map(e=>[R(e[0],this.config.coordinatePrecision),R(e[1],this.config.coordinatePrecision)])}};function $t(e,t){if(e.geometry.type!==`LineString`)return{valid:!1,reason:`Feature is not a LineString`};if(e.geometry.coordinates.length<2)return{valid:!1,reason:`Feature has less than 2 coordinates`};for(let n=0;n<e.geometry.coordinates.length;n++){if(!St(e.geometry.coordinates[n]))return{valid:!1,reason:`Feature has invalid coordinates`};if(!xt(e.geometry.coordinates[n],t))return{valid:!1,reason:`Feature has coordinates with excessive precision`}}return{valid:!0}}function en(e){return Math.sqrt(e[0]**2+e[1]**2+e[2]**2)}function tn(e,t){let n=function(e,t){let[n,r,i]=e,[a,o,s]=t;return n*a+r*o+i*s}(e,t)/(en(e)*en(t));return Math.acos(Math.min(Math.max(n,-1),1))}function nn(e){let t=I(e[1]),n=I(e[0]);return[Math.cos(t)*Math.cos(n),Math.cos(t)*Math.sin(n),Math.sin(t)]}function rn(e){let[t,n,r]=e,i=L(Math.asin(r));return[L(Math.atan2(n,t)),i]}function an(e,t,n){let r=nn(e),i=nn(t),[a,o,s]=nn(n),[c,l,u]=function(e,t){let[n,r,i]=e,[a,o,s]=t;return[r*s-i*o,i*a-n*s,n*o-r*a]}(r,i),d=l*s-u*o,f=u*a-c*s,p=c*o-l*a,m=p*l-f*u,h=d*u-p*c,g=f*c-d*l,_=1/Math.sqrt(m**2+h**2+g**2),v=[m*_,h*_,g*_],ee=[-1*m*_,-1*h*_,-1*g*_],te=tn(r,i),y=tn(r,v),b=tn(i,v),ne=tn(r,ee),x=tn(i,ee),S;return S=y<ne&&y<x||b<ne&&b<x?v:ee,tn(r,S)>te||tn(i,S)>te?F(rn(S),rn(r))<=F(rn(S),rn(i))?[rn(r),!0,!1]:[rn(i),!1,!0]:[rn(S),!1,!1]}function on(e,t,n){let r=t.x-e.x,i=t.y-e.y,a=Math.max(0,Math.min(1,((n.x-e.x)*r+(n.y-e.y)*i)/(r*r+i*i)));return{x:e.x+a*r,y:e.y+a*i}}var sn=class extends V{constructor(e,t,n){super(e),this.config=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.getSnappableCoordinateFirstClick=e=>{let t=this.getSnappable(e,e=>!!(e.properties&&e.properties.mode===this.mode));return t.coordinate?[R(t.coordinate[0],this.config.coordinatePrecision),R(t.coordinate[1],this.config.coordinatePrecision)]:void 0},this.getSnappableCoordinate=(e,t)=>{let n=this.getSnappable(e,e=>!!(e.properties&&e.properties.mode===this.mode&&e.id!==t));return n.coordinate?[R(n.coordinate[0],this.config.coordinatePrecision),R(n.coordinate[1],this.config.coordinatePrecision)]:void 0},this.config=e,this.pixelDistance=t,this.clickBoundingBox=n}getSnappable(e,t){let n=this.clickBoundingBox.create(e),r=this.store.search(n,t),i={featureId:void 0,featureCoordinateIndex:void 0,coordinate:void 0,minDistance:1/0};return r.forEach(t=>{let n;if(t.geometry.type===`Polygon`)n=t.geometry.coordinates[0];else{if(t.geometry.type!==`LineString`)return;n=t.geometry.coordinates}let r=[];for(let e=0;e<n.length-1;e++)r.push([n[e],n[e+1]]);let a,o=[e.lng,e.lat];if(this.config.projection===`web-mercator`?a=function(e,t){let n=[1/0,1/0],r=1/0,i=0;for(let a of t){let o=a[0],s=a[1],c,l=1/0,u=z(o[0],o[1]),d=z(s[0],s[1]),f=z(e[0],e[1]);if(o[0]===e[0]&&o[1]===e[1])c=o;else if(s[0]===e[0]&&s[1]===e[1])c=s;else{let{x:e,y:t}=on(u,d,f),{lng:n,lat:r}=B(e,t);c=[n,r]}c&&(l=G(f,z(c[0],c[1])),l<r&&(n=c,r=l,i=t.indexOf(a)))}return r===1/0?void 0:{coordinate:n,lineIndex:i,distance:r}}(o,r):this.config.projection===`globe`&&(a=function(e,t){let n=[1/0,1/0],r=1/0,i=0;for(let a of t){let o=a[0],s=a[1],c,l=1/0;o[0]===e[0]&&o[1]===e[1]?c=o:s[0]===e[0]&&s[1]===e[1]?c=s:[c]=an(o,s,e),c&&(l=F(e,c),l<r&&(n=c,r=l,i=t.indexOf(a)))}return r===1/0?void 0:{coordinate:n,distance:r,lineIndex:i}}(o,r)),!a)return;let s=this.pixelDistance.measure(e,a.coordinate);s<i.minDistance&&s<this.pointerDistance&&(i.featureId=t.id,i.coordinate=[R(a.coordinate[0],this.config.coordinatePrecision),R(a.coordinate[1],this.config.coordinatePrecision)],i.featureCoordinateIndex=a.lineIndex,i.minDistance=s)}),i}};function cn(e){return Array.isArray(e)&&e.length>0&&Array.isArray(e[0])&&Array.isArray(e[0][0])}var ln=e=>cn(e)?e[0].slice(0,-1):e,un=e=>cn(e)?e[0]:e,dn=class extends V{constructor(e,t,n,r){super(e),this.config=void 0,this.pixelDistance=void 0,this.mutateFeatureBehavior=void 0,this.readFeatureBehavior=void 0,this._startEndPoints=[],this.config=e,this.pixelDistance=t,this.mutateFeatureBehavior=n,this.readFeatureBehavior=r}get ids(){return this._startEndPoints.concat()}set ids(e){}create(e){if(this.ids.length)throw Error(`Opening and closing points already created`);let t=cn(e),n=un(e);if(t){if(n.length<=3)throw Error(`Requires at least 4 coordinates`);this._startEndPoints=this.mutateFeatureBehavior.createGuidancePoints({coordinates:[n[0],n[n.length-2]],type:M.CLOSING_POINT})}else this._startEndPoints=[this.mutateFeatureBehavior.createGuidancePoint({coordinate:n[n.length-2],type:M.CLOSING_POINT})]}delete(){this.ids.length&&(this.mutateFeatureBehavior.deleteFeaturesIfPresent(this.ids),this._startEndPoints=[])}updateOne(e,t){this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[e],coordinate:t}])}update(e){let t=un(e);this.ids.length===1?this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[0],coordinate:t[t.length-2]}]):this.ids.length===2&&this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[0],coordinate:t[0]},{featureId:this.ids[1],coordinate:t[t.length-3]}])}isLineStringClosingPoint(e){if(this.ids.length!==1)return{isClosing:!1};let t=this.readFeatureBehavior.getGeometry(this.ids[0]);return{isClosing:this.pixelDistance.measure(e,t.coordinates)<this.pointerDistance}}isPolygonClosingPoints(e){if(this.ids.length!==2)return{isClosing:!1,isPreviousClosing:!1};let t=this.readFeatureBehavior.getGeometry(this.ids[0]),n=this.readFeatureBehavior.getGeometry(this.ids[1]),r=this.pixelDistance.measure(e,t.coordinates),i=this.pixelDistance.measure(e,n.coordinates);return{isClosing:r<this.pointerDistance,isPreviousClosing:i<this.pointerDistance}}},fn=class extends V{constructor(e,t,n){super(e),this.readFeature=void 0,this.mutateFeature=void 0,this.readFeature=t,this.mutateFeature=n}createOrUpdate({featureId:e,featureCoordinates:t}){if(!this.readFeature.hasFeature(e))return void this.deleteOrphanedPoints(e);let n=ln(t),r=this.readFeature.getProperties(e),i=r.coordinatePointIds;if(i)if(i&&i.every(e=>this.readFeature.hasFeature(e))){let t=r.coordinatePointIds,i=t.map(e=>this.readFeature.getGeometry(e).coordinates);if(t.length!==n.length){this.deleteCoordinatePoints(t);let i=this.createPoints(n,r.mode,e);this.setFeatureCoordinatePoints(e,i)}else{let e=[];n.forEach((n,r)=>{n[0]===i[r][0]&&n[1]===i[r][1]||e.push({featureId:t[r],coordinate:n})}),this.mutateFeature.updateGuidancePoints(e)}}else{let t=i.filter(e=>this.readFeature.hasFeature(e));t.length&&this.deleteCoordinatePoints(t);let a=this.createPoints(n,r.mode,e);this.setFeatureCoordinatePoints(e,a)}else{let t=this.createPoints(n,r.mode,e);this.setFeatureCoordinatePoints(e,t)}}deletePointsByFeatureIds(e){for(let t of e)this.deleteIfPresent(t)}updateOneAtIndex(e,t,n){let r=this.readFeature.getProperties(e).coordinatePointIds;r&&r.length!==0&&r[t]!==void 0&&this.mutateFeature.updateGuidancePoints([{featureId:r[t],coordinate:n}])}updateAllInPlace({featureId:e,featureCoordinates:t}){let n=this.readFeature.getProperties(e);if(!n.coordinatePointIds)return;let r=ln(t);r.length===n.coordinatePointIds.length&&this.mutateFeature.updateGuidancePoints(n.coordinatePointIds.map((e,t)=>({featureId:e,coordinate:r[t]})))}createPoints(e,t,n){return this.mutateFeature.createGuidancePoints({coordinates:e,type:M.COORDINATE_POINT,additionalProperties:e=>({mode:t,[M.COORDINATE_POINT]:!0,[M.COORDINATE_POINT_FEATURE_ID]:n,index:e})})}setFeatureCoordinatePoints(e,t,n=A.Commit){let r=this.readFeature.getGeometryType(e),i={featureId:e,propertyMutations:{[M.COORDINATE_POINT_IDS]:t},context:{updateType:n}};if(r===`Polygon`)this.mutateFeature.updatePolygon(i);else{if(r!==`LineString`)throw Error(`Unsupported geometry type for coordinate points`);this.mutateFeature.updateLineString(i)}}deleteCoordinatePoints(e){this.mutateFeature.deleteFeaturesIfPresent(e)}deleteIfPresent(e){if(!this.readFeature.hasFeature(e))return;let t=this.readFeature.getProperties(e).coordinatePointIds;t&&(this.deleteCoordinatePoints(t),this.setFeatureCoordinatePoints(e,null))}deleteOrphanedPoints(e){let t=this.readFeature.getAllFeatureIdsWhere(t=>t[M.COORDINATE_POINT_FEATURE_ID]===e);this.mutateFeature.deleteFeaturesIfPresent(t)}},pn=class{constructor(e){this.undoHistory=[],this.redoHistory=[],this.cloneCoordinatesFunction=void 0,this.maxStackSize=void 0,this.cloneCoordinatesFunction=e=>this.cloneRecursively(e);let t=e?.maxStackSize;this.maxStackSize=t!==void 0&&Number.isFinite(t)?Math.max(0,Math.floor(t)):1/0}setMaxStackSize(e){Number.isFinite(e)?(this.maxStackSize=Math.max(0,Math.floor(e)),this.trimHistoryToMax(this.undoHistory),this.trimHistoryToMax(this.redoHistory)):this.maxStackSize=1/0}trimHistoryToMax(e){if(Number.isFinite(this.maxStackSize))for(;e.length>this.maxStackSize;)e.shift()}pushUndoEntry(e){this.maxStackSize!==0&&(this.undoHistory.push(e),this.trimHistoryToMax(this.undoHistory))}pushRedoEntry(e){this.maxStackSize!==0&&(this.redoHistory.push(e),this.trimHistoryToMax(this.redoHistory))}cloneRecursively(e){return Array.isArray(e)?e.map(e=>this.cloneRecursively(e)):typeof e==`object`&&e?O({},e):e}cloneCoordinates(e){return this.cloneCoordinatesFunction(e)}cloneEntry(e){return{featureCoordinates:this.cloneCoordinates(e.featureCoordinates),currentCoordinate:e.currentCoordinate}}clear(){this.undoHistory=[],this.redoHistory=[]}undoSize(){return this.undoHistory.length}redoSize(){return this.redoHistory.length}recordSnapshot(e){this.pushUndoEntry(this.cloneEntry(e)),this.redoHistory=[]}beginUndo(){let e=this.undoHistory.pop();if(!e)return;let t=this.cloneEntry(e);this.pushRedoEntry(t);let n=this.undoHistory[this.undoHistory.length-1];return{undoneEntry:t,previousEntry:n?this.cloneEntry(n):void 0}}takeRedo(){let e=this.redoHistory.pop();if(e)return this.cloneEntry(e)}commitRedo(e){this.pushUndoEntry(this.cloneEntry(e))}},mn={cancel:`Escape`,finish:`Enter`},hn={start:`crosshair`,close:`pointer`,dragStart:`grabbing`,dragEnd:`crosshair`},gn=class extends P{constructor(e){super(e,!0),this.mode=`linestring`,this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=mn,this.snapping=void 0,this.cursors=hn,this.mouseMove=!1,this.insertCoordinates=void 0,this.lastCommittedCoordinates=void 0,this.snappedPointId=void 0,this.lastMouseMoveEvent=void 0,this.showCoordinatePoints=!1,this.finishOnNthCoordinate=void 0,this.editable=!1,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0,this.editedInsertIndex=void 0,this.editedPointId=void 0,this.coordinateSnapping=void 0,this.insertPoint=void 0,this.lineSnapping=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.closingPoints=void 0,this.coordinatePoints=void 0,this.undoRedo=void 0,this.updateOptions(e)}updateOptions(e){if(super.updateOptions(e),e?.finishOnNthCoordinate!==void 0&&Number.isInteger(e.finishOnNthCoordinate)&&e.finishOnNthCoordinate>1&&(this.finishOnNthCoordinate=Math.floor(e.finishOnNthCoordinate)),e!=null&&e.cursors&&(this.cursors=O({},this.cursors,e.cursors)),e!=null&&e.snapping&&(this.snapping=e.snapping),e?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:e!=null&&e.keyEvents&&(this.keyEvents=O({},this.keyEvents,e.keyEvents)),e!=null&&e.insertCoordinates&&(this.insertCoordinates=e.insertCoordinates),e&&e.editable&&(this.editable=e.editable),e?.showCoordinatePoints!==void 0){if(this.showCoordinatePoints=e.showCoordinatePoints,this.coordinatePoints&&!0===e.showCoordinatePoints)this.store.copyAllWhere(e=>e.mode===this.mode).forEach(e=>{this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates})});else if(this.coordinatePoints&&!1===this.showCoordinatePoints){let e=this.store.copyAllWhere(e=>e.mode===this.mode&&!!e[M.COORDINATE_POINT_IDS]?.length);this.coordinatePoints.deletePointsByFeatureIds(e.map(e=>e.id))}}}shouldFinishOnCommit(e){return!!this.finishOnNthCoordinate&&Math.max(0,e.coordinates.length-1)>=this.finishOnNthCoordinate}updateSnappedCoordinate(e){let t=this.snapCoordinate(e);return t?(this.snappedPointId?this.mutateFeature.updateGuidancePoints([{featureId:this.snappedPointId,coordinate:t}]):this.snappedPointId=this.mutateFeature.createGuidancePoint({coordinate:t,type:M.SNAPPING_POINT}),e.lng=t[0],e.lat=t[1]):this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0),t}close(){if(this.currentId===void 0)return;let e=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:A.Finish,action:k},coordinateMutations:[{type:Nt,index:-1}],propertyMutations:{[M.CURRENTLY_DRAWING]:void 0}});if(!e)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates});let t=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),this.state===`drawing`&&this.setStarted(),this.closingPoints.delete(),this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0),this.onFinish(t,{mode:this.mode,action:k})}generateInsertCoordinates(e,t){if(!this.insertCoordinates||!this.lastCommittedCoordinates)throw Error(`Not able to insert coordinates`);if(this.insertCoordinates.strategy!==`amount`)throw Error(`Strategy does not exist`);let n=F(e,t)/(this.insertCoordinates.value+1),r=[];return this.projection===`globe`?r=this.insertPoint.generateInsertionGeodesicCoordinates(e,t,n):this.projection===`web-mercator`&&(r=this.insertPoint.generateInsertionCoordinates(e,t,n)),r}createLine(e){let t=this.mutateFeature.createLineString({coordinates:[e,e],properties:{mode:this.mode,[M.CURRENTLY_DRAWING]:!0}});this.lastCommittedCoordinates=t.geometry.coordinates,this.currentId=t.id,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.setDrawing(),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:t.geometry.coordinates})}firstUpdateToLine(e){if(!this.currentId)return;this.setCursor(this.cursors.close);let t=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:A.Commit},coordinateMutations:[{type:Mt,index:-1,coordinate:e}]});t&&(this.closingPoints.create(t.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:t.geometry.coordinates}),this.lastCommittedCoordinates=t.geometry.coordinates,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.shouldFinishOnCommit(t.geometry)&&this.close())}updateToLine(e,t){if(!this.currentId)return;let{isClosing:n}=this.closingPoints.isLineStringClosingPoint(e);if(n)return void this.close();this.setCursor(this.cursors.close);let r=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:A.Commit},coordinateMutations:[{type:Mt,index:-1,coordinate:t}]});r&&(this.closingPoints.update(r.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:r.geometry.coordinates}),this.lastCommittedCoordinates=r.geometry.coordinates,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.shouldFinishOnCommit(r.geometry)&&this.close())}undoSize(){return this.undoRedo.undoSize()}clearHistory(){this.undoRedo.clear()}pushHistorySnapshot(e,t){let n=this.readFeature.getGeometry(e);this.undoRedo.recordSnapshot({featureCoordinates:n.coordinates,currentCoordinate:t})}updateSnappedGuidancePointFromLastMouseMove(){this.snapping&&this.lastMouseMoveEvent?this.updateSnappedCoordinate(this.lastMouseMoveEvent):this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0)}syncClosingPoints(e){this.currentCoordinate>=2?this.closingPoints.ids.length?this.closingPoints.update(e):this.closingPoints.create(e):this.closingPoints.delete()}undo(){if(this.state!==`drawing`||!this.currentId)return;let e=this.undoRedo.beginUndo();if(!e)return;let{previousEntry:t}=e;if(!t){let e=this.currentId;this.currentId=void 0,this.currentCoordinate=0,this.lastCommittedCoordinates=void 0,this.closingPoints.delete(),this.state===`drawing`&&this.setStarted(),this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([e]),this.mutateFeature.deleteFeatureIfPresent(e),this.updateSnappedGuidancePointFromLastMouseMove();return}let n=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:{type:U,coordinates:t.featureCoordinates},propertyMutations:{[M.CURRENTLY_DRAWING]:!0},context:{updateType:A.Commit}});n&&(this.currentCoordinate=t.currentCoordinate,this.lastCommittedCoordinates=n.geometry.coordinates,this.syncClosingPoints(n.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:n.geometry.coordinates}),this.updateSnappedGuidancePointFromLastMouseMove())}redoSize(){return this.undoRedo.redoSize()}redo(){let e=this.undoRedo.takeRedo();if(e){if(this.currentId){let t=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:{type:U,coordinates:e.featureCoordinates},propertyMutations:{[M.CURRENTLY_DRAWING]:!0},context:{updateType:A.Commit}});if(!t)return;this.currentCoordinate=e.currentCoordinate,this.lastCommittedCoordinates=t.geometry.coordinates,this.syncClosingPoints(t.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:t.geometry.coordinates})}else{let{id:t,geometry:n}=this.mutateFeature.createLineString({coordinates:e.featureCoordinates,properties:{mode:this.mode,[M.CURRENTLY_DRAWING]:!0}});this.currentId=t,this.currentCoordinate=e.currentCoordinate,this.lastCommittedCoordinates=n.coordinates,this.state===`started`&&this.setDrawing(),this.syncClosingPoints(n.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t,featureCoordinates:n.coordinates})}this.undoRedo.commitRedo(e),this.updateSnappedGuidancePointFromLastMouseMove()}}registerBehaviors(e){this.insertPoint=new Qt(e),this.clickBoundingBox=new Ht(e),this.pixelDistance=new Ut(e),this.lineSnapping=new sn(e,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new Wt(e,this.pixelDistance,this.clickBoundingBox),this.readFeature=new K(e),this.mutateFeature=new W(e,{validate:this.validate}),this.closingPoints=new dn(e,this.pixelDistance,this.mutateFeature,this.readFeature),this.coordinatePoints=new fn(e,this.readFeature,this.mutateFeature),this.undoRedo=new pn({maxStackSize:e.undoRedoMaxStackSize})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onMouseMove(e){this.mouseMove=!0,this.setCursor(this.cursors.start),this.lastMouseMoveEvent=e;let t=this.updateSnappedCoordinate(e)||[e.lng,e.lat];if(this.currentId===void 0||this.currentCoordinate===0)return;let{isClosing:n}=this.closingPoints.isLineStringClosingPoint(e);n&&this.setCursor(this.cursors.close);let r=[{type:H,index:-1,coordinate:t}];if(this.insertCoordinates){let e=this.getInsertCoordinates(t);e&&(r={type:U,coordinates:e})}let i=this.mutateFeature.updateLineString({coordinateMutations:r,featureId:this.currentId,context:{updateType:A.Provisional}});i&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates})}getInsertCoordinates(e){if(!this.lastCommittedCoordinates)return;let t=this.lastCommittedCoordinates[this.lastCommittedCoordinates.length-1];if(Lt(t,e))return;let n=this.generateInsertCoordinates(t,e);return[...this.lastCommittedCoordinates.slice(0,-1),...n,e]}onRightClick(e){if(!this.editable||this.state!==`started`)return;let{featureId:t,featureCoordinateIndex:n}=this.coordinateSnapping.getSnappable(e,e=>this.lineStringFilter(e));if(!t||n===void 0)return;let r=this.readFeature.getGeometry(t),i;if(r.type!==`LineString`||(i=r.coordinates,i.length<=2))return;let a=this.mutateFeature.updateLineString({featureId:t,coordinateMutations:[{type:Nt,index:n}],context:{updateType:A.Finish,action:tt}});a&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t,featureCoordinates:a.geometry.coordinates}),this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0),this.closingPoints.delete(),this.onFinish(t,{mode:this.mode,action:nt})}onLeftClick(e){this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0);let t=this.snapCoordinate(e)||[e.lng,e.lat];this.currentCoordinate===0?this.createLine(t):this.currentCoordinate===1&&this.currentId?this.firstUpdateToLine(t):this.currentId&&this.updateToLine(e,t)}onClick(e){this.currentId===void 0||this.readFeature.hasFeature(this.currentId)||this.cleanUp(),(e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e))&&(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(e),this.mouseMove=!1,e.button===`right`?this.onRightClick(e):e.button===`left`&&this.onLeftClick(e))}onKeyDown(){}onKeyUp(e){e.key===this.keyEvents.cancel&&this.cleanUp(),e.key===this.keyEvents.finish&&this.close()}onDragStart(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDragStart,e)||!this.editable)return;let n;if(this.state===`started`){let t=this.lineSnapping.getSnappable(e,e=>this.lineStringFilter(e));t.coordinate&&(this.editedSnapType=`line`,this.editedFeatureCoordinateIndex=t.featureCoordinateIndex,this.editedFeatureId=t.featureId,n=t.coordinate);let r=this.coordinateSnapping.getSnappable(e,e=>this.lineStringFilter(e));r.coordinate&&(this.editedSnapType=`coordinate`,this.editedFeatureCoordinateIndex=r.featureCoordinateIndex,this.editedFeatureId=r.featureId,n=r.coordinate)}this.editedFeatureId&&n&&(this.editedPointId||=this.mutateFeature.createGuidancePoint({coordinate:n,type:M.EDITED}),this.setCursor(this.cursors.dragStart),t(!1))}onDrag(e,t){if(this.allowPointerEvent(this.pointerEvents.onDrag,e)&&this.editedFeatureId!==void 0&&this.editedFeatureCoordinateIndex!==void 0){if(this.editedSnapType===`coordinate`||this.editedSnapType===`line`&&this.editedInsertIndex!==void 0){let t=this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:A.Provisional},coordinateMutations:[{type:H,index:this.editedFeatureCoordinateIndex,coordinate:[e.lng,e.lat]}]});if(!t)return;this.showCoordinatePoints&&(this.editedInsertIndex===void 0?this.coordinatePoints.updateOneAtIndex(this.editedFeatureId,this.editedFeatureCoordinateIndex,[e.lng,e.lat]):this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:t.geometry.coordinates}))}else if(this.editedSnapType===`line`&&this.editedInsertIndex===void 0){this.editedInsertIndex=this.editedFeatureCoordinateIndex+1;let e=this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:A.Provisional}});if(!e)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:e.geometry.coordinates}),this.editedFeatureCoordinateIndex++}this.snapping&&this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&this.mutateFeature.updateGuidancePoints([{featureId:this.editedPointId,coordinate:[e.lng,e.lat]}]),this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:A.Provisional},propertyMutations:{[M.EDITED]:!0}})}}onDragEnd(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDragEnd,e)||this.editedFeatureId===void 0||(this.setCursor(this.cursors.dragEnd),!this.mutateFeature.updateLineString({featureId:this.editedFeatureId,propertyMutations:{[M.EDITED]:!1},context:{updateType:A.Finish,action:tt}})))return;let n=this.editedFeatureId;t(!0),this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0),this.closingPoints.delete(),this.onFinish(n,{mode:this.mode,action:tt})}cleanUp(){let e=this.currentId,t=this.snappedPointId;this.snappedPointId=void 0,this.currentId=void 0,this.currentCoordinate=0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),this.state===`drawing`&&this.setStarted(),e&&this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([e]),this.mutateFeature.deleteFeatureIfPresent(e),this.mutateFeature.deleteFeatureIfPresent(t),this.closingPoints.delete()}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});if(e.type===`Feature`&&e.geometry.type===`LineString`&&e.properties.mode===this.mode)return t.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,t.lineStringColor,e),t.lineStringOpacity=this.getNumericStylingValue(this.styles.lineStringOpacity,t.lineStringOpacity===void 0?1:t.lineStringOpacity,e),t.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,t.lineStringWidth,e),t.zIndex=N,t;if(e.type===`Feature`&&e.geometry.type===`Point`&&e.properties.mode===this.mode){let n=e.properties[M.COORDINATE_POINT],r=e.properties[M.CLOSING_POINT]?`closingPoint`:e.properties[M.SNAPPING_POINT]?`snappingPoint`:n?`coordinatePoint`:void 0;if(!r)return t;let i={closingPoint:{width:this.styles.closingPointWidth,color:this.styles.closingPointColor,opacity:this.styles.closingPointOpacity,outlineColor:this.styles.closingPointOutlineColor,outlineWidth:this.styles.closingPointOutlineWidth,outlineOpacity:this.styles.closingPointOutlineOpacity},snappingPoint:{width:this.styles.snappingPointWidth,color:this.styles.snappingPointColor,opacity:this.styles.snappingPointOpacity,outlineColor:this.styles.snappingPointOutlineColor,outlineWidth:this.styles.snappingPointOutlineWidth,outlineOpacity:this.styles.snappingPointOutlineOpacity},coordinatePoint:{width:this.styles.coordinatePointWidth,color:this.styles.coordinatePointColor,opacity:this.styles.coordinatePointOpacity,outlineColor:this.styles.coordinatePointOutlineColor,outlineWidth:this.styles.coordinatePointOutlineWidth,outlineOpacity:this.styles.coordinatePointOutlineOpacity}};return t.pointWidth=this.getNumericStylingValue(i[r].width,t.pointWidth,e),t.pointOpacity=this.getNumericStylingValue(i[r].opacity,1,e),t.pointColor=this.getHexColorStylingValue(i[r].color,t.pointColor,e),t.pointOutlineColor=this.getHexColorStylingValue(i[r].outlineColor,`#ffffff`,e),t.pointOutlineWidth=this.getNumericStylingValue(i[r].outlineWidth,2,e),t.pointOutlineOpacity=this.getNumericStylingValue(i[r].outlineOpacity,1,e),t.zIndex=n?20:50,t}return t}validateFeature(e){return this.validateModeFeature(e,e=>$t(e,this.coordinatePrecision))}lineStringFilter(e){return!!(e.geometry.type===`LineString`&&e.properties&&e.properties.mode===this.mode)}snapCoordinate(e){var t,n,r;let i;if((t=this.snapping)!=null&&t.toLine){let t;t=this.currentId?this.lineSnapping.getSnappableCoordinate(e,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(e),t&&(i=t)}if((n=this.snapping)!=null&&n.toCoordinate){let t;t=this.currentId?this.coordinateSnapping.getSnappableCoordinate(e,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(e),t&&(i=t)}if((r=this.snapping)!=null&&r.toCustom){let t=this.snapping.toCustom(e,{currentCoordinate:this.currentCoordinate,currentId:this.currentId,getCurrentGeometrySnapshot:this.currentId?()=>this.readFeature.getGeometry(this.currentId):()=>null,project:this.project,unproject:this.unproject});t&&(i=t)}return i}afterFeatureUpdated(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates}),this.editedFeatureId===e.id&&this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0),this.snappedPointId&&this.lastMouseMoveEvent&&this.updateSnappedCoordinate(this.lastMouseMoveEvent),this.currentId===e.id&&(this.closingPoints.delete(),this.currentCoordinate=0,this.currentId=void 0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),this.state===`drawing`&&this.setStarted())}afterFeatureAdded(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates})}},_n=`Feature is not a Point`,vn=`Feature has invalid coordinates`,yn=`Feature has coordinates with excessive precision`;function bn(e,t){return e.geometry.type===`Point`?St(e.geometry.coordinates)?xt(e.geometry.coordinates,t)?{valid:!0}:{valid:!1,reason:yn}:{valid:!1,reason:vn}:{valid:!1,reason:_n}}var xn=class extends V{constructor(e,t,n){super(e),this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.pixelDistance=t,this.clickBoundingBox=n}getNearestPointFeature(e){let t=this.clickBoundingBox.create(e),n=this.store.search(t),r,i=1/0;for(let t=0;t<n.length;t++){let a=n[t];if(a.geometry.type!==`Point`||a.properties.mode!==this.mode)continue;let o=this.pixelDistance.measure(e,a.geometry.coordinates);o>i||o>this.pointerDistance||(i=o,r=a)}return r}},Sn={create:`crosshair`,dragStart:`grabbing`,dragEnd:`crosshair`},Cn=class extends P{constructor(e){super(e,!0),this.mode=`point`,this.cursors=Sn,this.editable=!1,this.editedFeatureId=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.pointSearch=void 0,this.mutateFeature=void 0,this.updateOptions(e)}updateOptions(e){super.updateOptions(e),e!=null&&e.cursors&&(this.cursors=O({},this.cursors,e.cursors)),e!=null&&e.editable&&(this.editable=e.editable)}start(){this.setStarted(),this.setCursor(this.cursors.create)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onClick(e){e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e)?this.onRightClick(e):e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)&&this.onLeftClick(e)}onMouseMove(){}onKeyDown(){}onKeyUp(){}cleanUp(){this.editedFeatureId=void 0}onDragStart(e,t){this.allowPointerEvent(this.pointerEvents.onDragStart,e)&&(this.editable&&(this.editedFeatureId=this.pointSearch.getNearestPointFeature(e)?.id),this.editedFeatureId&&(this.setCursor(this.cursors.dragStart),t(!1)))}onDrag(e,t){this.allowPointerEvent(this.pointerEvents.onDrag,e)&&this.editedFeatureId!==void 0&&this.mutateFeature.updatePoint({featureId:this.editedFeatureId,coordinateMutations:{type:U,coordinates:[e.lng,e.lat]},propertyMutations:{[M.EDITED]:!0},context:{updateType:A.Provisional}})}onDragEnd(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDragEnd,e)||this.editedFeatureId===void 0||!this.mutateFeature.updatePoint({featureId:this.editedFeatureId,propertyMutations:{mode:this.mode,[M.EDITED]:!1},context:{updateType:A.Finish,action:`edit`}}))return;let n=this.editedFeatureId;this.setCursor(this.cursors.dragEnd),this.editedFeatureId=void 0,t(!0),this.onFinish(n,{mode:this.mode,action:k})}registerBehaviors(e){this.pixelDistance=new Ut(e),this.clickBoundingBox=new Ht(e),this.pointSearch=new xn(e,this.pixelDistance,this.clickBoundingBox),this.mutateFeature=new W(e,{validate:this.validate})}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});if(e.type===`Feature`&&e.geometry.type===`Point`&&e.properties.mode===this.mode){let n=!!(e.id&&this.editedFeatureId===e.id);t.pointWidth=this.getNumericStylingValue(n?this.styles.editedPointWidth:this.styles.pointWidth,t.pointWidth,e),t.pointOpacity=this.getNumericStylingValue(this.styles.pointOpacity,t.pointOpacity===void 0?1:t.pointOpacity,e),t.pointColor=this.getHexColorStylingValue(n?this.styles.editedPointColor:this.styles.pointColor,t.pointColor,e),t.pointOutlineColor=this.getHexColorStylingValue(n?this.styles.editedPointOutlineColor:this.styles.pointOutlineColor,t.pointOutlineColor,e),t.pointOutlineOpacity=this.getNumericStylingValue(this.styles.pointOutlineOpacity,t.pointOutlineOpacity===void 0?1:t.pointOutlineOpacity,e),t.pointOutlineWidth=this.getNumericStylingValue(n?this.styles.editedPointOutlineWidth:this.styles.pointOutlineWidth,2,e),t.zIndex=30}return t}validateFeature(e){return this.validateModeFeature(e,e=>bn(e,this.coordinatePrecision))}onLeftClick(e){let t=this.mutateFeature.createPoint({coordinates:[e.lng,e.lat],properties:{mode:this.mode},context:{updateType:A.Finish,action:k}});t&&this.onFinish(t.id,{mode:this.mode,action:k})}onRightClick(e){if(!this.editable)return;let t=this.pointSearch.getNearestPointFeature(e);t&&this.mutateFeature.deleteFeatureIfPresent(t.id)}afterFeatureUpdated(e){this.editedFeatureId===e.id&&(this.editedFeatureId=void 0,this.setCursor(this.cursors.create))}},wn={cancel:`Escape`,finish:`Enter`},Tn={start:`crosshair`,close:`pointer`,dragStart:`grabbing`,dragEnd:`crosshair`},En=class extends P{constructor(e){super(e,!0),this.mode=`polygon`,this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=wn,this.cursors=Tn,this.mouseMove=!1,this.showCoordinatePoints=!1,this.lastMouseMoveEvent=void 0,this.snapping=void 0,this.snappedPointId=void 0,this.editable=!1,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0,this.editedInsertIndex=void 0,this.editedPointId=void 0,this.coordinatePoints=void 0,this.lineSnapping=void 0,this.coordinateSnapping=void 0,this.pixelDistance=void 0,this.closingPoints=void 0,this.clickBoundingBox=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.undoRedo=void 0,this.updateOptions(e)}updateOptions(e){if(super.updateOptions(e),e!=null&&e.cursors&&(this.cursors=O({},this.cursors,e.cursors)),e?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:e!=null&&e.keyEvents&&(this.keyEvents=O({},this.keyEvents,e.keyEvents)),e!=null&&e.snapping&&(this.snapping=e.snapping),e?.editable!==void 0&&(this.editable=e.editable),e?.pointerEvents!==void 0&&(this.pointerEvents=e.pointerEvents),e?.showCoordinatePoints!==void 0){if(this.showCoordinatePoints=e.showCoordinatePoints,this.coordinatePoints&&!0===e.showCoordinatePoints)this.store.copyAllWhere(e=>e.mode===this.mode).filter(e=>e.geometry.type===`Polygon`).forEach(e=>{this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates})});else if(this.coordinatePoints&&!1===this.showCoordinatePoints){let e=this.store.copyAllWhere(e=>e.mode===this.mode&&!!e[M.COORDINATE_POINT_IDS]).filter(e=>e.geometry.type===`Polygon`);this.coordinatePoints.deletePointsByFeatureIds(e.map(e=>e.id))}}}close(){if(this.currentId===void 0||this.readFeature.getCoordinates(this.currentId).length<5)return;let e=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:Nt,index:-2}],propertyMutations:{[M.CURRENTLY_DRAWING]:void 0,[M.COMMITTED_COORDINATE_COUNT]:void 0,[M.PROVISIONAL_COORDINATE_COUNT]:void 0},context:{updateType:A.Finish,action:k}});if(!e)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates}),this.state===`drawing`&&this.setStarted(),this.editedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),void 0),this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0),this.closingPoints.delete();let t=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.undoRedo.clear(),this.onFinish(t,{mode:this.mode,action:k})}registerBehaviors(e){this.readFeature=new K(e),this.mutateFeature=new W(e,{validate:this.validate}),this.clickBoundingBox=new Ht(e),this.pixelDistance=new Ut(e),this.lineSnapping=new sn(e,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new Wt(e,this.pixelDistance,this.clickBoundingBox),this.closingPoints=new dn(e,this.pixelDistance,this.mutateFeature,this.readFeature),this.coordinatePoints=new fn(e,this.readFeature,this.mutateFeature),this.undoRedo=new pn({maxStackSize:e.undoRedoMaxStackSize})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}updateSnappedCoordinate(e){let t=this.snapCoordinate(e);t?(this.snappedPointId?this.mutateFeature.updateGuidancePoints([{featureId:this.snappedPointId,coordinate:t}]):this.snappedPointId=this.mutateFeature.createGuidancePoint({coordinate:t,type:M.SNAPPING_POINT}),e.lng=t[0],e.lat=t[1]):this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0)}undoSize(){return this.undoRedo.undoSize()}clearHistory(){this.undoRedo.clear()}pushHistorySnapshot(e,t){let n=this.readFeature.getGeometry(e);this.undoRedo.recordSnapshot({featureCoordinates:n.coordinates,currentCoordinate:t})}updateSnappedGuidancePointFromLastMouseMove(){this.snapping&&this.lastMouseMoveEvent?this.updateSnappedCoordinate(this.lastMouseMoveEvent):this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0)}syncClosingPoints(e){this.currentCoordinate>=3?this.closingPoints.ids.length?this.closingPoints.update(e):this.closingPoints.create(e):this.closingPoints.delete()}undo(){if(this.state!==`drawing`||!this.currentId)return;let e=this.undoRedo.beginUndo();if(!e)return;let{previousEntry:t}=e;if(!t){let e=this.currentId;this.currentId=void 0,this.currentCoordinate=0,this.closingPoints.delete(),this.state===`drawing`&&this.setStarted(),this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([e]),this.mutateFeature.deleteFeatureIfPresent(e),this.updateSnappedGuidancePointFromLastMouseMove();return}let n=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:{type:U,coordinates:t.featureCoordinates},propertyMutations:{[M.CURRENTLY_DRAWING]:!0,[M.COMMITTED_COORDINATE_COUNT]:t.currentCoordinate,[M.PROVISIONAL_COORDINATE_COUNT]:t.currentCoordinate},context:{updateType:A.Commit}});n&&(this.currentCoordinate=t.currentCoordinate,this.syncClosingPoints(n.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:n.geometry.coordinates}),this.updateSnappedGuidancePointFromLastMouseMove())}redoSize(){return this.undoRedo.redoSize()}redo(){let e=this.undoRedo.takeRedo();if(e){if(this.currentId){let t=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:{type:U,coordinates:e.featureCoordinates},propertyMutations:{[M.CURRENTLY_DRAWING]:!0,[M.COMMITTED_COORDINATE_COUNT]:e.currentCoordinate,[M.PROVISIONAL_COORDINATE_COUNT]:e.currentCoordinate},context:{updateType:A.Commit}});if(!t)return;this.currentCoordinate=e.currentCoordinate,this.syncClosingPoints(t.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:t.geometry.coordinates})}else{let t=this.undoRedo.cloneCoordinates(e.featureCoordinates)[0],{id:n,geometry:r}=this.mutateFeature.createPolygon({coordinates:t,properties:{mode:this.mode,[M.CURRENTLY_DRAWING]:!0,[M.COMMITTED_COORDINATE_COUNT]:e.currentCoordinate,[M.PROVISIONAL_COORDINATE_COUNT]:e.currentCoordinate}});this.currentId=n,this.currentCoordinate=e.currentCoordinate,this.state===`started`&&this.setDrawing(),this.syncClosingPoints(r.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:n,featureCoordinates:r.coordinates})}this.undoRedo.commitRedo(e),this.updateSnappedGuidancePointFromLastMouseMove()}}onMouseMove(e){if(this.mouseMove=!0,this.setCursor(this.cursors.start),this.lastMouseMoveEvent=e,this.updateSnappedCoordinate(e),this.currentId===void 0||this.currentCoordinate===0)return;let t=this.readFeature.getCoordinate(this.currentId,0),n=[e.lng,e.lat],r;if(this.currentCoordinate===1)r=[{type:H,index:1,coordinate:n},{type:H,index:2,coordinate:[e.lng,e.lat]}];else if(this.currentCoordinate===2)r=[{type:H,index:2,coordinate:n}];else{let{isClosing:i,isPreviousClosing:a}=this.closingPoints.isPolygonClosingPoints(e);a||i?(this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0),this.setCursor(this.cursors.close),r=[{type:H,index:-1,coordinate:t},{type:H,index:-2,coordinate:t}]):r=[{type:H,index:-2,coordinate:n},{type:H,index:-1,coordinate:t}]}let i=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:r,propertyMutations:{[M.PROVISIONAL_COORDINATE_COUNT]:this.currentCoordinate+1},context:{updateType:A.Provisional}});i&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates})}snapCoordinate(e){var t,n,r;let i;if((t=this.snapping)!=null&&t.toLine){let t;t=this.currentId?this.lineSnapping.getSnappableCoordinate(e,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(e),t&&(i=t)}if((n=this.snapping)!=null&&n.toCoordinate){let t;t=this.currentId?this.coordinateSnapping.getSnappableCoordinate(e,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(e),t&&(i=t)}if((r=this.snapping)!=null&&r.toCustom){let t=this.snapping.toCustom(e,{currentCoordinate:this.currentCoordinate,currentId:this.currentId,getCurrentGeometrySnapshot:this.currentId?()=>this.readFeature.getGeometry(this.currentId):()=>null,project:this.project,unproject:this.unproject});t&&(i=t)}return i}polygonFilter(e){return!!(e.geometry.type===`Polygon`&&e.properties&&e.properties.mode===this.mode)}onRightClick(e){if(!this.editable||this.state!==`started`)return;let{featureId:t,featureCoordinateIndex:n}=this.coordinateSnapping.getSnappable(e,e=>this.polygonFilter(e));if(!t||n===void 0)return;let r=this.readFeature.getGeometry(t);if(r.type!==`Polygon`)return;let i=r.coordinates[0];if(i.length<=4)return;let a;a=n===0||n===i.length-1?[{type:Nt,index:0},{type:Nt,index:-1},{type:Mt,index:-1,coordinate:i[1]}]:[{type:Nt,index:n}];let o=this.mutateFeature.updatePolygon({featureId:t,coordinateMutations:a,context:{updateType:A.Finish,action:tt}});if(o){if(this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t,featureCoordinates:o.geometry.coordinates}),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0,this.snapping)){let t=this.snapCoordinate(e);if(t){let[e]=this.mutateFeature.createGuidancePoints({type:M.SNAPPING_POINT,coordinates:[t]});this.snappedPointId=e}}this.onFinish(t,{mode:this.mode,action:tt})}}onLeftClick(e){this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0);let t=this.snapCoordinate(e)||[e.lng,e.lat];if(this.currentCoordinate===0){let{id:e,geometry:n}=this.mutateFeature.createPolygon({coordinates:[t,t,t,t],properties:{mode:this.mode,[M.CURRENTLY_DRAWING]:!0,[M.COMMITTED_COORDINATE_COUNT]:this.currentCoordinate+1,[M.PROVISIONAL_COORDINATE_COUNT]:this.currentCoordinate+1}});this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:e,featureCoordinates:n.coordinates}),this.currentId=e,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.setDrawing()}else if(this.currentCoordinate===1&&this.currentId){if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:t,index:0}))return;let e=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:H,index:1,coordinate:t},{type:H,index:2,coordinate:t}],propertyMutations:{[M.COMMITTED_COORDINATE_COUNT]:this.currentCoordinate+1},context:{updateType:A.Commit}});if(!e)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates}),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate)}else if(this.currentCoordinate===2&&this.currentId){if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:t,index:1}))return;let e=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:H,index:2,coordinate:t},{type:Mt,index:2,coordinate:t}],propertyMutations:{[M.COMMITTED_COORDINATE_COUNT]:this.currentCoordinate+1},context:{updateType:A.Commit}});if(!e)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates}),this.currentCoordinate===2&&this.closingPoints.create(e.geometry.coordinates),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate)}else if(this.currentId){let{isClosing:n,isPreviousClosing:r}=this.closingPoints.isPolygonClosingPoints(e);if(r||n)this.close();else{if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:t,index:this.currentCoordinate-1}))return;let e=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:jt,index:-1,coordinate:t}],propertyMutations:{[M.COMMITTED_COORDINATE_COUNT]:this.currentCoordinate+1},context:{updateType:A.Commit}});if(!e)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates}),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.closingPoints.ids.length&&this.closingPoints.update(e.geometry.coordinates)}}}onClick(e){this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(e),this.mouseMove=!1,e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e)?this.onRightClick(e):e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)&&this.onLeftClick(e)}onKeyUp(e){e.key===this.keyEvents.cancel?this.cleanUp():e.key===this.keyEvents.finish&&this.close()}onKeyDown(){}onDragStart(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDragStart,e)||!this.editable)return;let n;if(this.state===`started`){let t=this.lineSnapping.getSnappable(e,e=>this.polygonFilter(e));t.coordinate&&(this.editedSnapType=`line`,this.editedFeatureCoordinateIndex=t.featureCoordinateIndex,this.editedFeatureId=t.featureId,n=t.coordinate);let r=this.coordinateSnapping.getSnappable(e,e=>this.polygonFilter(e));r.coordinate&&(this.editedSnapType=`coordinate`,this.editedFeatureCoordinateIndex=r.featureCoordinateIndex,this.editedFeatureId=r.featureId,n=r.coordinate)}this.editedFeatureId&&n&&(this.editedPointId||=this.mutateFeature.createGuidancePoint({coordinate:n,type:M.EDITED}),this.setCursor(this.cursors.dragStart),t(!1))}onDrag(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDrag,e)||this.editedFeatureId===void 0||this.editedFeatureCoordinateIndex===void 0)return;let n=this.readFeature.getGeometry(this.editedFeatureId),r=[e.lng,e.lat],i=[];if(this.editedSnapType===`coordinate`||this.editedSnapType===`line`&&this.editedInsertIndex!==void 0?i=this.editedFeatureCoordinateIndex===0||this.editedFeatureCoordinateIndex===n.coordinates[0].length-1?[{type:H,index:0,coordinate:r},{type:H,index:-1,coordinate:r}]:[{type:H,index:this.editedFeatureCoordinateIndex,coordinate:r}]:this.editedSnapType===`line`&&this.editedInsertIndex===void 0&&(this.editedInsertIndex=this.editedFeatureCoordinateIndex+1,i=[{type:jt,index:this.editedInsertIndex,coordinate:r}],this.editedFeatureCoordinateIndex++),i.length===0)return;let a=this.mutateFeature.updatePolygon({featureId:this.editedFeatureId,coordinateMutations:i,propertyMutations:{[M.EDITED]:!0},context:{updateType:A.Provisional}});a&&(this.showCoordinatePoints&&(this.editedInsertIndex?this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:a.geometry.coordinates}):this.coordinatePoints.updateOneAtIndex(this.editedFeatureId,this.editedFeatureCoordinateIndex,a.geometry.coordinates[0][this.editedFeatureCoordinateIndex])),this.snapping&&this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&this.mutateFeature.updateGuidancePoints([{featureId:this.editedPointId,coordinate:r}]))}onDragEnd(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDragEnd,e)||this.editedFeatureId===void 0||(this.setCursor(this.cursors.dragEnd),!this.mutateFeature.updatePolygon({featureId:this.editedFeatureId,propertyMutations:{[M.EDITED]:!1},context:{updateType:A.Finish,action:tt}})))return;let n=this.editedFeatureId;this.editedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),void 0),this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0),this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0,t(!0),this.onFinish(n,{mode:this.mode,action:tt})}cleanUp(){let e=this.currentId,t=this.snappedPointId,n=this.editedPointId;this.currentId=void 0,this.snappedPointId=void 0,this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0,this.currentCoordinate=0,this.undoRedo.clear(),this.state===`drawing`&&this.setStarted(),e&&this.coordinatePoints.deletePointsByFeatureIds([e]),this.mutateFeature.deleteFeatureIfPresent(e),this.mutateFeature.deleteFeatureIfPresent(n),this.mutateFeature.deleteFeatureIfPresent(t),this.closingPoints.ids.length&&this.closingPoints.delete()}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});if(e.properties.mode===this.mode){if(e.geometry.type===`Polygon`)return t.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,t.polygonFillColor,e),t.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,t.polygonOutlineColor,e),t.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,t.polygonOutlineWidth,e),t.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,t.polygonFillOpacity,e),t.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,e),t.zIndex=N,t;if(e.geometry.type===`Point`){let n=e.properties[M.EDITED],r=e.properties[M.COORDINATE_POINT],i=n?`editedPoint`:e.properties[M.CLOSING_POINT]?`closingPoint`:e.properties[M.SNAPPING_POINT]?`snappingPoint`:r?`coordinatePoint`:void 0;if(!i)return t;let a={editedPoint:{width:this.styles.editedPointOutlineWidth,color:this.styles.editedPointColor,opacity:this.styles.editedPointOpacity,outlineColor:this.styles.editedPointOutlineColor,outlineWidth:this.styles.editedPointOutlineWidth,outlineOpacity:this.styles.editedPointOutlineOpacity},closingPoint:{width:this.styles.closingPointWidth,color:this.styles.closingPointColor,opacity:this.styles.closingPointOpacity,outlineColor:this.styles.closingPointOutlineColor,outlineWidth:this.styles.closingPointOutlineWidth,outlineOpacity:this.styles.closingPointOutlineOpacity},snappingPoint:{width:this.styles.snappingPointWidth,color:this.styles.snappingPointColor,opacity:this.styles.snappingPointOpacity,outlineColor:this.styles.snappingPointOutlineColor,outlineWidth:this.styles.snappingPointOutlineWidth,outlineOpacity:this.styles.snappingPointOutlineOpacity},coordinatePoint:{width:this.styles.coordinatePointWidth,color:this.styles.coordinatePointColor,opacity:this.styles.coordinatePointOpacity,outlineColor:this.styles.coordinatePointOutlineColor,outlineWidth:this.styles.coordinatePointOutlineWidth,outlineOpacity:this.styles.coordinatePointOutlineOpacity}};return t.pointWidth=this.getNumericStylingValue(a[i].width,t.pointWidth,e),t.pointOpacity=this.getNumericStylingValue(a[i].opacity,1,e),t.pointColor=this.getHexColorStylingValue(a[i].color,t.pointColor,e),t.pointOutlineColor=this.getHexColorStylingValue(a[i].outlineColor,t.pointOutlineColor,e),t.pointOutlineOpacity=this.getNumericStylingValue(a[i].outlineOpacity,1,e),t.pointOutlineWidth=this.getNumericStylingValue(a[i].outlineWidth,2,e),t.zIndex=n?40:r?20:30,t}}return t}afterFeatureAdded(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates})}afterFeatureUpdated(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates}),this.editedFeatureId===e.id&&this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0),this.snappedPointId&&this.lastMouseMoveEvent&&this.updateSnappedCoordinate(this.lastMouseMoveEvent),this.currentId===e.id&&(this.currentCoordinate=0,this.currentId=void 0,this.undoRedo.clear(),this.closingPoints.delete(),this.state===`drawing`&&this.setStarted())}validateFeature(e){return this.validateModeFeature(e,e=>Ot(e,this.coordinatePrecision))}},Dn={cancel:`Escape`,finish:`Enter`},On={start:`crosshair`},kn=class extends P{constructor(e){super(e,!0),this.mode=`rectangle`,this.startPosition=void 0,this.endPosition=void 0,this.currentRectangleId=void 0,this.keyEvents=Dn,this.cursors=On,this.drawInteraction=`click-move`,this.drawType=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.updateOptions(e)}updateOptions(e){super.updateOptions(e),e!=null&&e.cursors&&(this.cursors=O({},this.cursors,e.cursors)),e?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:e!=null&&e.keyEvents&&(this.keyEvents=O({},this.keyEvents,e.keyEvents)),e!=null&&e.drawInteraction&&(this.drawInteraction=e.drawInteraction)}updateRectangle(e,t){if(!this.startPosition||!this.currentRectangleId)return;let n=t===A.Finish;return this.mutateFeature.updatePolygon({featureId:this.currentRectangleId,coordinateMutations:[{type:H,index:1,coordinate:[e[0],this.startPosition[1]]},{type:H,index:2,coordinate:e},{type:H,index:3,coordinate:[this.startPosition[0],e[1]]}],propertyMutations:n?{[M.CURRENTLY_DRAWING]:void 0}:{},context:n?{updateType:t,action:k}:{updateType:t}})}close(){if(!this.currentRectangleId||!this.endPosition||!this.updateRectangle(this.endPosition,A.Finish))return;let e=this.currentRectangleId;this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,this.state===`drawing`&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:k})}beginDrawing(e,t=`click`){this.startPosition=[e.lng,e.lat],this.endPosition=[e.lng,e.lat],this.currentRectangleId=this.mutateFeature.createPolygon({coordinates:[[e.lng,e.lat],[e.lng,e.lat],[e.lng,e.lat],[e.lng,e.lat],[e.lng,e.lat]],properties:{mode:this.mode,[M.CURRENTLY_DRAWING]:!0}}).id,this.drawType=t,this.setDrawing()}moveDrawAllowed(){return this.drawInteraction===`click-move`||this.drawInteraction===`click-move-or-drag`}dragDrawAllowed(){return this.drawInteraction===`click-drag`||this.drawInteraction===`click-move-or-drag`}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onClick(e){this.moveDrawAllowed()&&(e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e))&&(this.startPosition?(this.endPosition=[e.lng,e.lat],this.close()):this.beginDrawing(e))}onMouseMove(e){this.endPosition=[e.lng,e.lat],this.updateRectangle(this.endPosition,A.Provisional)}onKeyDown(){}onKeyUp(e){e.key===this.keyEvents.cancel?this.cleanUp():e.key===this.keyEvents.finish&&this.close()}onDragStart(e,t){this.state!==`drawing`&&this.allowPointerEvent(this.pointerEvents.onDragStart,e)&&this.dragDrawAllowed()&&(this.beginDrawing(e,`drag`),t(!1))}onDrag(e,t){this.allowPointerEvent(this.pointerEvents.onDrag,e)&&this.dragDrawAllowed()&&this.drawType===`drag`&&(this.endPosition=[e.lng,e.lat],this.updateRectangle(this.endPosition,A.Provisional))}onDragEnd(e,t){this.allowPointerEvent(this.pointerEvents.onDragEnd,e)&&this.dragDrawAllowed()&&this.drawType===`drag`&&(this.endPosition=[e.lng,e.lat],this.close(),t(!0))}cleanUp(){let e=this.currentRectangleId;this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,this.state===`drawing`&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(e)}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return e.type===`Feature`&&e.geometry.type===`Polygon`&&e.properties.mode===this.mode?(t.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,t.polygonFillColor,e),t.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,t.polygonOutlineColor,e),t.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,e),t.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,t.polygonOutlineWidth,e),t.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,t.polygonFillOpacity,e),t.zIndex=N,t):t}validateFeature(e){return this.validateModeFeature(e,e=>kt(e,this.coordinatePrecision))}afterFeatureUpdated(e){this.currentRectangleId===e.id&&(this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,this.state===`drawing`&&this.setStarted())}registerBehaviors(e){this.readFeature=new K(e),this.mutateFeature=new W(e,{validate:this.validate})}},An=class extends P{constructor(e){if(!e.modeName)throw Error(`Mode name is required for TerraDrawRenderMode`);super(e,!0),this.type=lt.Render,this.mode=`render`,this.updateOptions(e)}updateOptions(e){super.updateOptions(e)}registerBehaviors(e){this.mode=e.mode}start(){this.setStarted()}stop(){this.setStopped()}onKeyUp(){}onKeyDown(){}onClick(){}onDragStart(){}onDrag(){}onDragEnd(){}onMouseMove(){}cleanUp(){}styleFeature(e){return{pointColor:this.getHexColorStylingValue(this.styles.pointColor,`#3f97e0`,e),pointWidth:this.getNumericStylingValue(this.styles.pointWidth,6,e),pointOpacity:this.getNumericStylingValue(this.styles.pointOpacity,1,e),pointOutlineColor:this.getHexColorStylingValue(this.styles.pointOutlineColor,`#ffffff`,e),pointOutlineWidth:this.getNumericStylingValue(this.styles.pointOutlineWidth,0,e),pointOutlineOpacity:this.getNumericStylingValue(this.styles.pointOutlineOpacity,1,e),polygonFillColor:this.getHexColorStylingValue(this.styles.polygonFillColor,`#3f97e0`,e),polygonFillOpacity:this.getNumericStylingValue(this.styles.polygonFillOpacity,.3,e),polygonOutlineColor:this.getHexColorStylingValue(this.styles.polygonOutlineColor,`#3f97e0`,e),polygonOutlineWidth:this.getNumericStylingValue(this.styles.polygonOutlineWidth,4,e),lineStringWidth:this.getNumericStylingValue(this.styles.lineStringWidth,4,e),lineStringColor:this.getHexColorStylingValue(this.styles.lineStringColor,`#3f97e0`,e),lineStringOpacity:this.getNumericStylingValue(this.styles.lineStringOpacity,1,e),zIndex:this.getNumericStylingValue(this.styles.zIndex,0,e)}}validateFeature(e){let t=super.validateFeature(e);if(t.valid){let t=e,n=bn(t,this.coordinatePrecision).valid||Ot(t,this.coordinatePrecision).valid||$t(t,this.coordinatePrecision).valid;return n?{valid:!0}:{valid:n,reason:`Feature is not a valid Point, Polygon or LineString feature`}}return t}};function jn(e,t){let n=e,r=t,i=I(n[1]),a=I(r[1]),o=I(r[0]-n[0]);o>Math.PI&&(o-=2*Math.PI),o<-Math.PI&&(o+=2*Math.PI);let s=Math.log(Math.tan(a/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),c=(L(Math.atan2(o,s))+360)%360;return c>180?-(360-c):c}function Mn(e,t,n){let r=t;t<0&&(r=-Math.abs(r));let i=r/ft,a=e[0]*Math.PI/180,o=I(e[1]),s=I(n),c=i*Math.cos(s),l=o+c;Math.abs(l)>Math.PI/2&&(l=l>0?Math.PI-l:-Math.PI-l);let u=Math.log(Math.tan(l/2+Math.PI/4)/Math.tan(o/2+Math.PI/4)),d=Math.abs(u)>1e-11?c/u:Math.cos(o),f=[(180*(a+i*Math.sin(s)/d)/Math.PI+540)%360-180,180*l/Math.PI];return f[0]+=f[0]-e[0]>180?-360:e[0]-f[0]>180?360:0,f}function Nn(e,t,n,r,i){let a=r(e[0],e[1]),o=r(t[0],t[1]),{lng:s,lat:c}=i((a.x+o.x)/2,(a.y+o.y)/2);return[R(s,n),R(c,n)]}function Pn(e,t,n){let r=Mn(e,1e3*F(e,t)/2,jn(e,t));return[R(r[0],n),R(r[1],n)]}function Fn({featureCoords:e,precision:t,unproject:n,project:r,projection:i}){let a=[];for(let o=0;o<e.length-1;o++){let s;if(i===`web-mercator`)s=Nn(e[o],e[o+1],t,r,n);else{if(i!==`globe`)throw Error(`Invalid projection`);s=Pn(e[o],e[o+1],t)}a.push(s)}return a}var In=class extends V{constructor(e,t,n,r,i,a){super(e),this.config=void 0,this.selectionPointBehavior=void 0,this.coordinatePointBehavior=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.pixelDistance=void 0,this._midPoints=[],this.config=e,this.selectionPointBehavior=t,this.coordinatePointBehavior=n,this.mutateFeature=r,this.readFeature=i,this.pixelDistance=a}getMidpointConfig(e){return{featureCoords:e,precision:this.coordinatePrecision,project:this.config.project,unproject:this.config.unproject,projection:this.config.projection}}get ids(){return this._midPoints.concat()}set ids(e){}getNearestMidPoint(e){let t,n=1/0;return this.ids.forEach(r=>{let i=this.readFeature.getGeometry(r),a=this.pixelDistance.measure(e,i.coordinates);a<this.pointerDistance&&a<n&&(n=a,t=r)}),t}insert({featureId:e,midPointId:t}){let n=this.readFeature.getGeometry(t),{midPointFeatureId:r,midPointSegment:i}=this.readFeature.getProperties(t),a=this.readFeature.getGeometry(r),o={featureId:r,coordinateMutations:[{type:Mt,index:i,coordinate:n.coordinates}],context:{updateType:A.Commit}},s=null;if(a.type===`Polygon`)s=this.mutateFeature.updatePolygon(o);else{if(a.type!==`LineString`)throw Error(`Midpoints can only be added to polygons or linestrings`);s=this.mutateFeature.updateLineString(o)}if(!s)throw Error(`Failed to insert midpoint coordinate`);let c=s.geometry.coordinates;this.readFeature.getProperties(e)[M.COORDINATE_POINT_IDS]&&this.coordinatePointBehavior.createOrUpdate({featureId:e,featureCoordinates:c}),this.mutateFeature.deleteFeaturesIfPresent([...this.selectionPointBehavior.ids,...this._midPoints]),this.create({featureCoordinates:c,featureId:r}),this.selectionPointBehavior.create({featureCoordinates:c,featureId:e})}create({featureCoordinates:e,featureId:t}){if(!this.readFeature.hasFeature(t))throw Error(`Store does not have feature with this id`);let n=un(e),r=Fn(this.getMidpointConfig(n));this._midPoints=this.mutateFeature.createGuidancePoints({additionalProperties:e=>({mode:this.mode,midPointSegment:e,midPointFeatureId:t,[j.MID_POINT]:!0}),coordinates:r,type:j.MID_POINT})}delete(){this._midPoints.length&&(this.mutateFeature.deleteFeaturesIfPresent(this._midPoints),this._midPoints=[])}updateAllInPlace({featureCoordinates:e}){if(this._midPoints.length===0)return;let t=un(e),n=Fn(this.getMidpointConfig(t));this.mutateFeature.updateGuidancePoints(this._midPoints.map((e,t)=>({featureId:e,coordinate:n[t]})))}updateOneAtIndex(e,t){if(e<0&&(e=this._midPoints.length+e),this._midPoints[e]===void 0)return;let n=un(t),r=Fn(this.getMidpointConfig(n));this.mutateFeature.updateGuidancePoints([{featureId:this._midPoints[e],coordinate:r[e]}])}},Ln=class extends V{constructor(e,t){super(e),this.mutateFeature=void 0,this._selectionPoints=[],this.mutateFeature=t}get ids(){return this._selectionPoints.concat()}set ids(e){}create({featureId:e,featureCoordinates:t}){let n=ln(t);this._selectionPoints=this.mutateFeature.createGuidancePoints({coordinates:n,type:j.SELECTION_POINT,additionalProperties:t=>({[j.SELECTION_POINT_FEATURE_ID]:e,index:t})})}delete(){this.ids.length&&(this.mutateFeature.deleteFeaturesIfPresent(this.ids),this._selectionPoints=[])}updateAllInPlace({featureCoordinates:e}){if(this._selectionPoints.length===0)return;let t=ln(e);t.length===this._selectionPoints.length&&this.mutateFeature.updateGuidancePoints(this._selectionPoints.map((e,n)=>({featureId:e,coordinate:t[n]})))}updateOneAtIndex(e,t){this._selectionPoints[e]!==void 0&&this.mutateFeature.updateGuidancePoints([{featureId:this._selectionPoints[e],coordinate:t}])}};function Rn(e,t){let n=!1;for(let o=0,s=t.length;o<s;o++){let s=t[o];for(let t=0,o=s.length,c=o-1;t<o;c=t++)(i=s[t])[1]>(r=e)[1]!=(a=s[c])[1]>r[1]&&r[0]<(a[0]-i[0])*(r[1]-i[1])/(a[1]-i[1])+i[0]&&(n=!n)}var r,i,a;return n}var zn=(e,t,n)=>{let r=e=>e*e,i=(e,t)=>r(e.x-t.x)+r(e.y-t.y);return Math.sqrt(((e,t,n)=>{let r=i(t,n);if(r===0)return i(e,t);let a=((e.x-t.x)*(n.x-t.x)+(e.y-t.y)*(n.y-t.y))/r;return a=Math.max(0,Math.min(1,a)),i(e,{x:t.x+a*(n.x-t.x),y:t.y+a*(n.y-t.y)})})(e,t,n))},Bn=class extends V{constructor(e,t,n){super(e),this.config=void 0,this.createClickBoundingBox=void 0,this.pixelDistance=void 0,this.config=e,this.createClickBoundingBox=t,this.pixelDistance=n}find(e,t){let n,r,i,a=1/0,o=1/0,s=this.createClickBoundingBox.create(e),c=this.store.search(s);for(let s=0;s<c.length;s++){let l=c[s],u=l.geometry;if(u.type===`Point`){if(l.properties.selectionPoint||l.properties.coordinatePoint||!t&&l.properties[j.MID_POINT])continue;let r=this.pixelDistance.measure(e,u.coordinates);!l.properties[j.MID_POINT]&&r<this.pointerDistance&&r<a&&(a=r,n=l)}else if(u.type===`LineString`){if(n)continue;for(let t=0;t<u.coordinates.length-1;t++){let n=u.coordinates[t],i=u.coordinates[t+1],a=zn({x:e.containerX,y:e.containerY},this.project(n[0],n[1]),this.project(i[0],i[1]));a<this.pointerDistance&&a<o&&(o=a,r=l)}}else if(u.type===`Polygon`){if(n||r)continue;Rn([e.lng,e.lat],u.coordinates)&&(i=l)}}return{clickedFeature:n||r||i}}},Vn=class extends V{constructor(e,t,n,r,i,a,o){super(e),this.config=void 0,this.featuresAtCursorEvent=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.coordinatePoints=void 0,this.readFeature=void 0,this.mutateFeature=void 0,this.draggedFeatureId=null,this.dragPosition=void 0,this.config=e,this.featuresAtCursorEvent=t,this.selectionPoints=n,this.midPoints=r,this.coordinatePoints=i,this.readFeature=a,this.mutateFeature=o}startDragging(e,t){this.draggedFeatureId=t,this.dragPosition=[e.lng,e.lat]}stopDragging(){this.draggedFeatureId=null,this.dragPosition=void 0}isDragging(){return this.draggedFeatureId!==null}canDrag(e,t){let{clickedFeature:n}=this.featuresAtCursorEvent.find(e,!0);return!(!n||n.id!==t)}drag(e){if(!this.draggedFeatureId)return;let t=this.readFeature.getGeometry(this.draggedFeatureId),n=[e.lng,e.lat];if(t.type===`Polygon`||t.type===`LineString`){let r,i;if(t.type===`Polygon`?(r=t.coordinates[0],i=r.length-1):(r=t.coordinates,i=r.length),!this.dragPosition)return!1;for(let e=0;e<i;e++){let t=r[e],i,a;if(this.config.projection===`web-mercator`){let e=z(this.dragPosition[0],this.dragPosition[1]),r=z(n[0],n[1]),o=z(t[0],t[1]),s={x:e.x-r.x,y:e.y-r.y},{lng:c,lat:l}=B(o.x-s.x,o.y-s.y);i=c,a=l}else{let e=[this.dragPosition[0]-n[0],this.dragPosition[1]-n[1]];i=t[0]-e[0],a=t[1]-e[1]}if(i=R(i,this.config.coordinatePrecision),a=R(a,this.config.coordinatePrecision),i>180||i<-180||a>90||a<-90)return!1;r[e]=[i,a]}t.type===`Polygon`&&(r[r.length-1]=[r[0][0],r[0][1]]);let a=this.draggedFeatureId,o=null;if(t.type===`Polygon`)o=this.mutateFeature.updatePolygon({featureId:a,coordinateMutations:{type:U,coordinates:[r]},context:{updateType:A.Provisional}});else{if(t.type!==`LineString`)return;o=this.mutateFeature.updateLineString({featureId:a,coordinateMutations:{type:U,coordinates:r},context:{updateType:A.Provisional}})}if(!o)return!1;let s=o.geometry.coordinates;this.midPoints.updateAllInPlace({featureCoordinates:s}),this.selectionPoints.updateAllInPlace({featureCoordinates:s}),this.coordinatePoints.updateAllInPlace({featureId:a,featureCoordinates:s}),this.dragPosition=[e.lng,e.lat]}else t.type===`Point`&&(this.mutateFeature.updatePoint({featureId:this.draggedFeatureId,coordinateMutations:{type:U,coordinates:n},context:{updateType:A.Provisional}}),this.dragPosition=[e.lng,e.lat])}},Hn=class extends V{constructor(e,t,n,r,i,a,o,s,c){super(e),this.config=void 0,this.pixelDistance=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.coordinatePoints=void 0,this.coordinateSnapping=void 0,this.lineSnapping=void 0,this.readFeature=void 0,this.mutateFeature=void 0,this.draggedCoordinate={id:null,index:-1},this.config=e,this.pixelDistance=t,this.selectionPoints=n,this.midPoints=r,this.coordinatePoints=i,this.coordinateSnapping=a,this.lineSnapping=o,this.readFeature=s,this.mutateFeature=c}getClosestCoordinate(e,t){let n={dist:1/0,index:-1,isFirstOrLastPolygonCoord:!1},r;if(t.type===`LineString`)r=t.coordinates;else{if(t.type!==`Polygon`)return n;r=t.coordinates[0]}for(let i=0;i<r.length;i++){let a=this.pixelDistance.measure(e,r[i]);if(a<this.pointerDistance&&a<n.dist){let e=t.type===`Polygon`&&(i===r.length-1||i===0);n.dist=a,n.index=e?0:i,n.isFirstOrLastPolygonCoord=e}}return n}getDraggable(e,t){let n=this.readFeature.getGeometry(t);return this.getClosestCoordinate(e,n)}getDraggableIndex(e,t){let n=this.readFeature.getGeometry(t),r=this.getClosestCoordinate(e,n);return r.index===-1?-1:r.index}snapCoordinate(e,t,n){let r=[e.lng,e.lat],i=e=>!!(e.properties&&e.properties.mode===n.properties.mode&&e.id!==this.draggedCoordinate.id);if(t!=null&&t.toLine){let t;t=this.lineSnapping.getSnappable(e,i).coordinate,t&&(r=t)}if(t.toCoordinate){let t;t=this.coordinateSnapping.getSnappable(e,i).coordinate,t&&(r=t)}if(t!=null&&t.toCustom){let i;i=t.toCustom(e,{currentCoordinate:this.draggedCoordinate.index,currentId:n.id,getCurrentGeometrySnapshot:n.id?()=>this.readFeature.getGeometry(n.id):()=>null,project:this.project,unproject:this.unproject}),i&&(r=i)}return r}drag(e,t,n){let r=this.draggedCoordinate.id;if(r===null)return!1;let i=this.draggedCoordinate.index,a=this.readFeature.getGeometry(r),o=this.readFeature.getProperties(r),s=a.type===`LineString`?a.coordinates:a.coordinates[0],c=a.type===`Polygon`&&(i===s.length-1||i===0),l=this.snapCoordinate(e,n,{type:`Feature`,id:r,geometry:a,properties:o});if(e.lng>180||e.lng<-180||e.lat>90||e.lat<-90)return!1;if(c){let e=s.length-1;s[0]=l,s[e]=l}else s[i]=l;if(a.type!==`Point`&&!t&&yt({type:`Feature`,geometry:a,properties:{}}))return!1;let u=r,d=null;return a.type===`Polygon`?d=this.mutateFeature.updatePolygon({featureId:u,coordinateMutations:{type:U,coordinates:[s]},context:{updateType:A.Provisional}}):a.type===`LineString`&&(d=this.mutateFeature.updateLineString({featureId:u,coordinateMutations:{type:U,coordinates:s},context:{updateType:A.Provisional}})),!!d&&(this.midPoints.updateOneAtIndex(i>0?i-1:-1,s),this.midPoints.updateOneAtIndex(i,s),this.selectionPoints.updateOneAtIndex(i,l),this.coordinatePoints.updateOneAtIndex(u,i,l),!0)}isDragging(){return this.draggedCoordinate.id!==null}startDragging(e,t){this.draggedCoordinate={id:e,index:t}}stopDragging(){this.draggedCoordinate={id:null,index:-1}}};function Un(e){let t=0,n=0,r=0;return(e.geometry.type===`Polygon`?e.geometry.coordinates[0].slice(0,-1):e.geometry.coordinates).forEach(e=>{t+=e[0],n+=e[1],r++},!0),[t/r,n/r]}var Wn=(e,t)=>{if(t===0||t===360||t===-360)return e;let n=.017453292519943295*t,r=(e.geometry.type===`Polygon`?e.geometry.coordinates[0]:e.geometry.coordinates).map(([e,t])=>z(e,t)),i=r.reduce((e,t)=>({x:e.x+t.x,y:e.y+t.y}),{x:0,y:0});i.x/=r.length,i.y/=r.length;let a=r.map(e=>({x:i.x+(e.x-i.x)*Math.cos(n)-(e.y-i.y)*Math.sin(n),y:i.y+(e.x-i.x)*Math.sin(n)+(e.y-i.y)*Math.cos(n)})).map(({x:e,y:t})=>[B(e,t).lng,B(e,t).lat]);return e.geometry.type===`Polygon`?e.geometry.coordinates[0]=a:e.geometry.coordinates=a,e};function Gn(e){let t=(e.geometry.type===`Polygon`?e.geometry.coordinates[0]:e.geometry.coordinates).map(e=>{let{x:t,y:n}=z(e[0],e[1]);return[t,n]});return e.geometry.type===`Polygon`?function(e){let t=0,n=0,r=0,i=e.length;for(let a=0;a<i-1;a++){let[i,o]=e[a],[s,c]=e[a+1],l=i*c-s*o;t+=l,n+=(i+s)*l,r+=(o+c)*l}return t/=2,n/=6*t,r/=6*t,{x:n,y:r}}(t):function(e){let t=e.length,n=0,r=0;for(let i=0;i<t;i++){let[t,a]=e[i];n+=t,r+=a}return{x:n/t,y:r/t}}(t)}var Kn=class extends V{constructor(e,t,n,r,i,a){super(e),this.config=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.coordinatePoints=void 0,this.readFeature=void 0,this.mutateFeature=void 0,this.lastBearing=void 0,this.selectedGeometry=void 0,this.selectedGeometryCentroid=void 0,this.selectedGeometryWebMercatorCentroid=void 0,this.config=e,this.selectionPoints=t,this.midPoints=n,this.coordinatePoints=r,this.readFeature=i,this.mutateFeature=a}reset(){this.lastBearing=void 0,this.selectedGeometry=void 0,this.selectedGeometryWebMercatorCentroid=void 0,this.selectedGeometryCentroid=void 0}rotate(e,t){this.selectedGeometry||=this.readFeature.getGeometry(t);let n=this.selectedGeometry;if(n.type!==`Polygon`&&n.type!==`LineString`)return;let r=[e.lng,e.lat],i,a={type:`Feature`,geometry:n,properties:{}};if(this.config.projection===`web-mercator`){this.selectedGeometryWebMercatorCentroid||=Gn(a);let t=z(e.lng,e.lat);if(i=q(this.selectedGeometryWebMercatorCentroid,t),i===0)return;if(!this.lastBearing)return void(this.lastBearing=i);Wn(a,-(this.lastBearing-i))}else{if(this.config.projection!==`globe`)throw Error(`Unsupported projection`);if(this.selectedGeometryCentroid||=Un({type:`Feature`,geometry:n,properties:{}}),i=jn(this.selectedGeometryCentroid,r),!this.lastBearing)return void(this.lastBearing=i+180);(function(e,t){if(t===0||t===360||t===-360)return e;let n=Un(e);(e.geometry.type===`Polygon`?e.geometry.coordinates[0]:e.geometry.coordinates).forEach(e=>{let r=jn(n,e)+t,i=Mn(n,function(e,t){e[0]+=e[0]-t[0]>180?-360:t[0]-e[0]>180?360:0;let n=ft,r=t[1]*Math.PI/180,i=e[1]*Math.PI/180,a=i-r,o=Math.abs(e[0]-t[0])*Math.PI/180;o>Math.PI&&(o-=2*Math.PI);let s=Math.log(Math.tan(i/2+Math.PI/4)/Math.tan(r/2+Math.PI/4)),c=Math.abs(s)>1e-11?a/s:Math.cos(r);return Math.sqrt(a*a+c*c*o*o)*n}(n,e),r);e[0]=i[0],e[1]=i[1]})})(a,-(this.lastBearing-(i+180)))}let o=n.type===`Polygon`?n.coordinates[0]:n.coordinates;o.forEach(e=>{e[0]=R(e[0],this.coordinatePrecision),e[1]=R(e[1],this.coordinatePrecision)});let s={featureId:t,coordinateMutations:{type:U,coordinates:n.type===`Polygon`?[o]:o},context:{updateType:A.Provisional}},c=null;if(a.geometry.type===`Polygon`)c=this.mutateFeature.updatePolygon(s);else{if(a.geometry.type!==`LineString`)return;c=this.mutateFeature.updateLineString(s)}if(!c)return!1;let l=c.geometry.coordinates;this.midPoints.updateAllInPlace({featureCoordinates:l}),this.selectionPoints.updateAllInPlace({featureCoordinates:l}),this.coordinatePoints.updateAllInPlace({featureId:t,featureCoordinates:l}),this.projection===`web-mercator`?this.lastBearing=i:this.projection===`globe`&&(this.lastBearing=i+180)}},qn=class extends V{constructor(e,t){super(e),this.config=void 0,this.dragCoordinateResizeBehavior=void 0,this.config=e,this.dragCoordinateResizeBehavior=t}scale(e,t){if(!this.dragCoordinateResizeBehavior.isDragging()){let n=this.dragCoordinateResizeBehavior.getDraggableIndex(e,t);this.dragCoordinateResizeBehavior.startDragging(t,n)}this.dragCoordinateResizeBehavior.drag(e,`center-fixed`)}reset(){this.dragCoordinateResizeBehavior.stopDragging()}};function Jn({coordinates:e,originX:t,originY:n,xScale:r,yScale:i}){r===1&&i===1||e.forEach(e=>{let{x:a,y:o}=z(e[0],e[1]),{lng:s,lat:c}=B(t+(a-t)*r,n+(o-n)*i);e[0]=s,e[1]=c})}var Yn=class extends V{constructor(e,t,n,r,i,a,o){super(e),this.config=void 0,this.pixelDistance=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.coordinatePoints=void 0,this.readFeature=void 0,this.mutateFeature=void 0,this.minimumScale=1e-4,this.draggedCoordinate={id:null,index:-1},this.boundingBoxMaps={opposite:{0:4,1:5,2:6,3:7,4:0,5:1,6:2,7:3}},this.config=e,this.pixelDistance=t,this.selectionPoints=n,this.midPoints=r,this.coordinatePoints=i,this.readFeature=a,this.mutateFeature=o}getClosestCoordinate(e,t){let n={dist:1/0,index:-1,isFirstOrLastPolygonCoord:!1},r;if(t.type===`LineString`)r=t.coordinates;else{if(t.type!==`Polygon`)return n;r=t.coordinates[0]}for(let i=0;i<r.length;i++){let a=this.pixelDistance.measure(e,r[i]);if(a<this.pointerDistance&&a<n.dist){let e=t.type===`Polygon`&&(i===r.length-1||i===0);n.dist=a,n.index=e?0:i,n.isFirstOrLastPolygonCoord=e}}return n}isValidDragWebMercator(e,t,n){switch(e){case 0:if(t<=0||n>=0)return!1;break;case 1:if(n>=0)return!1;break;case 2:if(t>=0||n>=0)return!1;break;case 3:if(t>=0)return!1;break;case 4:if(t>=0||n<=0)return!1;break;case 5:if(n<=0)return!1;break;case 6:if(t<=0||n<=0)return!1;break;case 7:if(t<=0)return!1}return!0}getSelectedFeatureDataWebMercator(){if(!this.draggedCoordinate.id||this.draggedCoordinate.index===-1)return null;let e=this.getFeature(this.draggedCoordinate.id);if(!e)return null;let t=this.getNormalisedCoordinates(e.geometry);return{boundingBox:this.getBBoxWebMercator(t),feature:e,updatedCoords:t,selectedCoordinate:t[this.draggedCoordinate.index]}}centerWebMercatorDrag(e){let t=this.getSelectedFeatureDataWebMercator();if(!t)return null;let{feature:n,boundingBox:r,updatedCoords:i,selectedCoordinate:a}=t,o=Gn(n);if(!o)return null;let s=z(a[0],a[1]),{closestBBoxIndex:c}=this.getIndexesWebMercator(r,s),l=z(e.lng,e.lat);return this.scaleWebMercator({closestBBoxIndex:c,updatedCoords:i,webMercatorCursor:l,webMercatorSelected:s,webMercatorOrigin:o}),i}centerFixedWebMercatorDrag(e){let t=this.getSelectedFeatureDataWebMercator();if(!t)return null;let{feature:n,boundingBox:r,updatedCoords:i,selectedCoordinate:a}=t,o=Gn(n);if(!o)return null;let s=z(a[0],a[1]),{closestBBoxIndex:c}=this.getIndexesWebMercator(r,s),l=z(e.lng,e.lat);return this.scaleFixedWebMercator({closestBBoxIndex:c,updatedCoords:i,webMercatorCursor:l,webMercatorSelected:s,webMercatorOrigin:o}),i}scaleFixedWebMercator({closestBBoxIndex:e,webMercatorOrigin:t,webMercatorSelected:n,webMercatorCursor:r,updatedCoords:i}){if(!this.isValidDragWebMercator(e,t.x-r.x,t.y-r.y))return null;let a=G(t,r)/G(t,n);return a<0&&(a=this.minimumScale),Jn({coordinates:i,originX:t.x,originY:t.y,xScale:a,yScale:a}),i}oppositeFixedWebMercatorDrag(e){let t=this.getSelectedFeatureDataWebMercator();if(!t)return null;let{boundingBox:n,updatedCoords:r,selectedCoordinate:i}=t,a=z(i[0],i[1]),{oppositeBboxIndex:o,closestBBoxIndex:s}=this.getIndexesWebMercator(n,a),c={x:n[o][0],y:n[o][1]},l=z(e.lng,e.lat);return this.scaleFixedWebMercator({closestBBoxIndex:s,updatedCoords:r,webMercatorCursor:l,webMercatorSelected:a,webMercatorOrigin:c}),r}oppositeWebMercatorDrag(e){let t=this.getSelectedFeatureDataWebMercator();if(!t)return null;let{boundingBox:n,updatedCoords:r,selectedCoordinate:i}=t,a=z(i[0],i[1]),{oppositeBboxIndex:o,closestBBoxIndex:s}=this.getIndexesWebMercator(n,a),c={x:n[o][0],y:n[o][1]},l=z(e.lng,e.lat);return this.scaleWebMercator({closestBBoxIndex:s,updatedCoords:r,webMercatorCursor:l,webMercatorSelected:a,webMercatorOrigin:c}),r}scaleWebMercator({closestBBoxIndex:e,webMercatorOrigin:t,webMercatorSelected:n,webMercatorCursor:r,updatedCoords:i}){let a=t.x-r.x,o=t.y-r.y;if(!this.isValidDragWebMercator(e,a,o))return null;let s=1;a!==0&&e!==1&&e!==5&&(s=1-(t.x-n.x-a)/a);let c=1;return o!==0&&e!==3&&e!==7&&(c=1-(t.y-n.y-o)/o),this.validateScale(s,c)?(s<0&&(s=this.minimumScale),c<0&&(c=this.minimumScale),this.performWebMercatorScale(i,t.x,t.y,s,c),i):null}getFeature(e){if(this.draggedCoordinate.id===null)return null;let t=this.readFeature.getGeometry(e);return t.type!==`Polygon`&&t.type!==`LineString`?null:{id:e,type:`Feature`,geometry:t,properties:{}}}getNormalisedCoordinates(e){return e.type===`Polygon`?e.coordinates[0]:e.coordinates}validateScale(e,t){return!isNaN(e)&&t<2**53-1&&!isNaN(t)&&t<2**53-1}performWebMercatorScale(e,t,n,r,i){e.forEach(e=>{let{x:a,y:o}=z(e[0],e[1]),{lng:s,lat:c}=B(t+(a-t)*r,n+(o-n)*i);e[0]=s,e[1]=c})}getBBoxWebMercator(e){let t=[1/0,1/0,-1/0,-1/0];(e=e.map(e=>{let{x:t,y:n}=z(e[0],e[1]);return[t,n]})).forEach(([e,n])=>{e<t[0]&&(t[0]=e),n<t[1]&&(t[1]=n),e>t[2]&&(t[2]=e),n>t[3]&&(t[3]=n)});let[n,r,i,a]=t;return[[n,a],[(n+i)/2,a],[i,a],[i,a+(r-a)/2],[i,r],[(n+i)/2,r],[n,r],[n,a+(r-a)/2]]}getIndexesWebMercator(e,t){let n,r=1/0;for(let i=0;i<e.length;i++){let a=G({x:t.x,y:t.y},{x:e[i][0],y:e[i][1]});a<r&&(n=i,r=a)}if(n===void 0)throw Error(`No closest coordinate found`);return{oppositeBboxIndex:this.boundingBoxMaps.opposite[n],closestBBoxIndex:n}}isDragging(){return this.draggedCoordinate.id!==null}startDragging(e,t){this.draggedCoordinate={id:e,index:t}}stopDragging(){this.draggedCoordinate={id:null,index:-1}}getDraggableIndex(e,t){let n=this.readFeature.getGeometry(t),r=this.getClosestCoordinate(e,n);return r.index===-1?-1:r.index}drag(e,t){if(!this.draggedCoordinate.id)return!1;let n=this.getFeature(this.draggedCoordinate.id);if(!n)return!1;let r=null;if(t===`center`?r=this.centerWebMercatorDrag(e):t===`opposite`?r=this.oppositeWebMercatorDrag(e):t===`center-fixed`?r=this.centerFixedWebMercatorDrag(e):t===`opposite-fixed`&&(r=this.oppositeFixedWebMercatorDrag(e)),!r)return!1;for(let e=0;e<r.length;e++){let t=r[e];if(t[0]=R(t[0],this.coordinatePrecision),t[1]=R(t[1],this.coordinatePrecision),!xt(t,this.coordinatePrecision))return!1}let i=n.id,a=null;if(n.geometry.type===`Polygon`?a=this.mutateFeature.updatePolygon({featureId:i,coordinateMutations:{type:U,coordinates:[r]},context:{updateType:A.Provisional}}):n.geometry.type===`LineString`&&(a=this.mutateFeature.updateLineString({featureId:i,coordinateMutations:{type:U,coordinates:r},context:{updateType:A.Provisional}})),!a)return!1;let o=a.geometry.coordinates;return this.midPoints.updateAllInPlace({featureCoordinates:o}),this.selectionPoints.updateAllInPlace({featureCoordinates:o}),this.coordinatePoints.updateAllInPlace({featureId:i,featureCoordinates:o}),!0}},Xn={deselect:`Escape`,delete:`Delete`,rotate:[`Control`,`r`],scale:[`Control`,`s`]},Zn={pointerOver:`move`,dragStart:`move`,dragEnd:`move`,insertMidpoint:`crosshair`},Qn=class extends dt{constructor(e){super(e,!0),this.mode=`select`,this.allowManualDeselection=!0,this.allowManualSelection=!0,this.dragEventThrottle=5,this.dragEventCount=0,this.selected=[],this.flags={},this.keyEvents=Xn,this.cursors=Zn,this.validations={},this.dragTarget={type:`none`},this.selectionPoints=void 0,this.midPoints=void 0,this.coordinateSnap=void 0,this.featuresAtMouseEvent=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.dragFeature=void 0,this.dragCoordinate=void 0,this.rotateFeature=void 0,this.scaleFeature=void 0,this.dragCoordinateResizeFeature=void 0,this.coordinatePoints=void 0,this.lineSnap=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.updateOptions(e)}updateOptions(e){if(super.updateOptions(e),this.cursors=e&&e.cursors?O({},this.cursors,e.cursors):Zn,e?.keyEvents===null?this.keyEvents={deselect:null,delete:null,rotate:null,scale:null}:e!=null&&e.keyEvents&&(this.keyEvents=O({},this.keyEvents,e.keyEvents)),e?.dragEventThrottle!==void 0&&(this.dragEventThrottle=e.dragEventThrottle),e?.allowManualDeselection!==void 0&&(this.allowManualDeselection=e.allowManualDeselection),e?.allowManualSelection!==void 0&&(this.allowManualSelection=e.allowManualSelection),e!=null&&e.flags){this.flags=O({},this.flags,e.flags),this.validations={};for(let e in this.flags){let t=this.flags[e].feature;t&&t.validation&&(this.validations[e]=t.validation)}}}selectFeature(e){this.select(e,!1)}setSelecting(){if(this._state!==`started`)throw Error(`Mode must be started to move to selecting state`);this._state=`selecting`}registerBehaviors(e){this.readFeature=new K(e),this.mutateFeature=new W(e,{validate:(e,t)=>{let n=e.properties.mode;return this.validations&&this.validations[n]?this.validations[n](e,t):{valid:!0}}}),this.pixelDistance=new Ut(e),this.clickBoundingBox=new Ht(e),this.featuresAtMouseEvent=new Bn(e,this.clickBoundingBox,this.pixelDistance),this.selectionPoints=new Ln(e,this.mutateFeature),this.coordinatePoints=new fn(e,this.readFeature,this.mutateFeature),this.midPoints=new In(e,this.selectionPoints,this.coordinatePoints,this.mutateFeature,this.readFeature,this.pixelDistance),this.coordinateSnap=new Wt(e,this.pixelDistance,this.clickBoundingBox),this.lineSnap=new sn(e,this.pixelDistance,this.clickBoundingBox),this.rotateFeature=new Kn(e,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.dragFeature=new Vn(e,this.featuresAtMouseEvent,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.dragCoordinate=new Hn(e,this.pixelDistance,this.selectionPoints,this.midPoints,this.coordinatePoints,this.coordinateSnap,this.lineSnap,this.readFeature,this.mutateFeature),this.dragCoordinateResizeFeature=new Yn(e,this.pixelDistance,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.scaleFeature=new qn(e,this.dragCoordinateResizeFeature)}deselectFeature(e){this.deselect(e)}deselect(e){this.selected.includes(e)&&(this.mutateFeature.setDeselected(this.selected),this.onDeselect(this.selected[0]),this.selected=[],this.selectionPoints.delete(),this.midPoints.delete(),this.dragTarget={type:`none`})}deleteSelected(){this.selected.length&&this.mutateFeature.deleteFeaturesIfPresent(this.selected),this.selected=[],this.dragTarget={type:`none`}}clearDragTargetAndCursor(){this.dragTarget={type:`none`},this.setCursor(`unset`)}getSelectedFlags(e){let t=this.readFeature.getProperties(e),n=this.flags[t.mode]?.feature,r=n?.coordinates;return{featureFlags:n,coordinatesFlags:r,hasDraggableFlags:n&&(n.draggable||r?.draggable||r?.resizable||typeof r?.midpoints==`object`&&r.midpoints.draggable)}}onRightClick(e){if(!this.selectionPoints.ids.length)return;let t,n=1/0;if(this.selectionPoints.ids.forEach(r=>{let i=this.readFeature.getGeometry(r),a=this.pixelDistance.measure(e,i.coordinates);a<this.pointerDistance&&a<n&&(n=a,t=this.readFeature.getProperties(r))}),!t)return;let r=t.selectionPointFeatureId,i=t.index,a=this.readFeature.getProperties(r),o=this.flags[a.mode];if(!(o&&o.feature&&o.feature.coordinates&&o.feature.coordinates.deletable))return;let s=this.readFeature.getGeometry(r),c;if(s.type===`Polygon`){if(c=s.coordinates[0],c.length<=4)return}else if(s.type!==`LineString`||(c=s.coordinates,c.length<=2))return;s.type!==`Polygon`||i!==0&&i!==c.length-1?c.splice(i,1):(c.shift(),c.pop(),c.push([c[0][0],c[0][1]]));let l=null;if(s.type===`Polygon`?l=this.mutateFeature.updatePolygon({featureId:r,coordinateMutations:{type:U,coordinates:[c]},context:{updateType:A.Commit}}):s.type===`LineString`&&(l=this.mutateFeature.updateLineString({featureId:r,coordinateMutations:{type:U,coordinates:c},context:{updateType:A.Commit}})),!l)return;let u=l.geometry.coordinates;this.mutateFeature.deleteFeaturesIfPresent([...this.midPoints.ids,...this.selectionPoints.ids]),a.coordinatePointIds&&this.coordinatePoints.createOrUpdate({featureId:r,featureCoordinates:u}),this.selectionPoints.create({featureCoordinates:u,featureId:r}),o&&o.feature&&o.feature.coordinates&&o.feature.coordinates.midpoints&&this.midPoints.create({featureCoordinates:u,featureId:r}),this.onFinish(r,{action:nt,mode:this.mode})}select(e,t=!0){if(this.selected[0]===e)return;let{mode:n}=this.readFeature.getProperties(e),r=this.flags[n];if(!r||!r.feature)return;let i=this.selected[0];if(i){if(i===e)return;this.deselect(i)}t&&this.setCursor(this.cursors.pointerOver),this.selected=[e],this.mutateFeature.setSelected(e),this.onSelect(e);let{type:a,coordinates:o}=this.readFeature.getGeometry(e);a!==`LineString`&&a!==`Polygon`||o&&r&&r.feature.coordinates&&(this.selectionPoints.create({featureCoordinates:o,featureId:e}),r.feature.coordinates.midpoints&&this.midPoints.create({featureCoordinates:o,featureId:e}))}onLeftClick(e){let{clickedFeature:t}=this.featuresAtMouseEvent.find(e,this.selected.length>0),n=this.midPoints.getNearestMidPoint(e),r=this.selected[0];if(r){var i;let{featureFlags:t}=this.getSelectedFlags(r);if(t!=null&&(i=t.coordinates)!=null&&i.midpoints&&n){if(t.coordinates.draggable){let t=this.pixelDistance.measure(e,this.readFeature.getGeometry(n).coordinates),{dist:i}=this.dragCoordinate.getDraggable(e,r);if(i!==void 0&&t>i)return}this.midPoints.insert({featureId:r,midPointId:n}),this.onFinish(this.selected[0],{action:rt,mode:this.mode});return}}if(t!=null&&t.id)this.allowManualSelection&&this.select(t.id,!0);else if(this.selected.length&&this.allowManualDeselection)return void this.deselect(this.selected[0])}start(){this.setStarted(),this.setSelecting()}stop(){this.cleanUp(),this.setStarted(),this.setStopped()}onClick(e){e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e)?this.onRightClick(e):e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)&&this.onLeftClick(e)}canScale(e){return this.keyEvents.scale&&this.keyEvents.scale.every(t=>e.heldKeys.includes(t))}canRotate(e){return this.keyEvents.rotate&&this.keyEvents.rotate.every(t=>e.heldKeys.includes(t))}preventDefaultKeyEvent(e){let t=this.canRotate(e),n=this.canScale(e);(t||n)&&e.preventDefault()}onKeyDown(e){this.preventDefaultKeyEvent(e)}onKeyUp(e){if(this.preventDefaultKeyEvent(e),this.keyEvents.delete&&e.key===this.keyEvents.delete){if(!this.selected.length)return;let e=this.selected[0];this.onDeselect(this.selected[0]),this.coordinatePoints.deletePointsByFeatureIds([e]),this.deleteSelected(),this.selectionPoints.delete(),this.midPoints.delete()}else this.keyEvents.deselect&&e.key===this.keyEvents.deselect&&this.cleanUp()}cleanUp(){this.selected.length&&this.deselect(this.selected[0])}onDragStart(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDragStart,e))return;let n=this.selected[0];if(!n)return;let{featureFlags:r,coordinatesFlags:i,hasDraggableFlags:a}=this.getSelectedFlags(n);if(!a)return;this.dragEventCount=0;let o=this.dragTarget.type!==`none`&&this.dragTarget.featureId===n?this.dragTarget:{type:`none`},s=o.type===`coordinate`?o.coordinateIndex:this.dragCoordinate.getDraggableIndex(e,n),c=o.type===`resize`?o.coordinateIndex:this.dragCoordinateResizeFeature.getDraggableIndex(e,n),l=i?.resizable&&c!==-1,u=i?.draggable&&s!==-1,d=i&&typeof i.midpoints==`object`&&i.midpoints.draggable,f=r?.draggable&&(o.type===`feature`||this.dragFeature.canDrag(e,n));if(l)return this.setCursor(this.cursors.dragStart),this.dragCoordinateResizeFeature.startDragging(n,c),void t(!1);if(u)return this.setCursor(this.cursors.dragStart),this.dragCoordinate.startDragging(n,s),void t(!1);if(d){let r=o.type===`midpoint`?o.midPointId:this.midPoints.getNearestMidPoint(e);if(this.selected.length&&r){this.midPoints.insert({featureId:n,midPointId:r}),this.onFinish(this.selected[0],{action:rt,mode:this.mode});let i=this.dragCoordinate.getDraggableIndex(e,n);this.dragCoordinate.startDragging(n,i),t(!1);return}}if(f)return this.setCursor(this.cursors.dragStart),this.dragFeature.startDragging(e,n),void t(!1);this.setCursor(`unset`)}onDrag(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDrag,e))return;let n=this.selected[0];if(!n)return;let r=this.readFeature.getProperties(n),i=this.flags[r.mode],a=!0===(i&&i.feature&&i.feature.selfIntersectable);if(this.dragEventCount++,this.dragEventCount%this.dragEventThrottle!=0){if(i&&i.feature&&i.feature.rotateable&&this.canRotate(e))return t(!1),void this.rotateFeature.rotate(e,n);if(i&&i.feature&&i.feature.scaleable&&this.canScale(e))return t(!1),void this.scaleFeature.scale(e,n);if(this.dragCoordinateResizeFeature.isDragging()&&i.feature&&i.feature.coordinates&&i.feature.coordinates.resizable){if(this.projection===`globe`)throw Error(`Globe is currently unsupported projection for resizable`);t(!1),this.dragCoordinateResizeFeature.drag(e,i.feature.coordinates.resizable);return}if(this.dragCoordinate.isDragging()){var o;let t=(o=i.feature)==null||(o=o.coordinates)==null?void 0:o.snappable,n={toCoordinate:!1};!0===t?n={toCoordinate:!0}:typeof t==`object`&&(n=t),this.dragCoordinate.drag(e,a,n);return}this.dragFeature.isDragging()?this.dragFeature.drag(e):t(!0)}}onDragEnd(e,t){this.allowPointerEvent(this.pointerEvents.onDragEnd,e)&&(this.setCursor(this.cursors.dragEnd),this.dragCoordinate.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:`dragCoordinate`}):this.dragFeature.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:`dragFeature`}):this.dragCoordinateResizeFeature.isDragging()&&this.onFinish(this.selected[0],{mode:this.mode,action:`dragCoordinateResize`}),this.dragCoordinate.stopDragging(),this.dragFeature.stopDragging(),this.dragCoordinateResizeFeature.stopDragging(),this.rotateFeature.reset(),this.scaleFeature.reset(),t(!0))}onMouseMove(e){let t=this.selected[0];if(!t)return void this.clearDragTargetAndCursor();if(this.dragFeature.isDragging()||this.dragCoordinate.isDragging()||this.dragCoordinateResizeFeature.isDragging())return;let{featureFlags:n}=this.getSelectedFlags(t);if(!n)return void this.clearDragTargetAndCursor();let r,i=n.coordinates;if(i!=null&&i.midpoints&&(r=this.midPoints.getNearestMidPoint(e),r&&(this.dragTarget={type:`midpoint`,featureId:t,midPointId:r},this.setCursor(this.cursors.insertMidpoint))),i&&i.draggable){let{index:n,dist:i}=this.dragCoordinate.getDraggable(e,t);if(n>-1){if(r&&this.pixelDistance.measure(e,this.readFeature.getGeometry(r).coordinates)<i)return;this.dragTarget={type:`coordinate`,featureId:t,coordinateIndex:n},this.setCursor(this.cursors.pointerOver);return}}if(i&&i.resizable){let n=this.dragCoordinateResizeFeature.getDraggableIndex(e,t);if(n>-1)return this.dragTarget={type:`resize`,featureId:t,coordinateIndex:n},void this.setCursor(this.cursors.pointerOver)}if(n.draggable&&this.dragFeature.canDrag(e,t)){if(r)return;this.dragTarget={type:`feature`,featureId:t},this.setCursor(this.cursors.pointerOver);return}r||this.clearDragTargetAndCursor()}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});if(e.properties.mode===this.mode&&e.geometry.type===`Point`){if(e.properties[j.SELECTION_POINT])return t.pointColor=this.getHexColorStylingValue(this.styles.selectionPointColor,t.pointColor,e),t.pointOpacity=this.getNumericStylingValue(this.styles.selectionPointOpacity,1,e),t.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectionPointOutlineColor,t.pointOutlineColor,e),t.pointWidth=this.getNumericStylingValue(this.styles.selectionPointWidth,t.pointWidth,e),t.pointOutlineOpacity=this.getNumericStylingValue(this.styles.selectionPointOutlineOpacity,1,e),t.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectionPointOutlineWidth,2,e),t.zIndex=30,t;if(e.properties[j.MID_POINT])return t.pointColor=this.getHexColorStylingValue(this.styles.midPointColor,t.pointColor,e),t.pointOpacity=this.getNumericStylingValue(this.styles.midPointOpacity,1,e),t.pointOutlineColor=this.getHexColorStylingValue(this.styles.midPointOutlineColor,t.pointOutlineColor,e),t.pointWidth=this.getNumericStylingValue(this.styles.midPointWidth,4,e),t.pointOutlineOpacity=this.getNumericStylingValue(this.styles.midPointOutlineOpacity,1,e),t.pointOutlineWidth=this.getNumericStylingValue(this.styles.midPointOutlineWidth,2,e),t.zIndex=50,t}else if(e.properties[j.SELECTED]){if(e.geometry.type===`Point`&&e.properties[M.MARKER])return t.markerUrl=this.getUrlStylingValue(this.styles.selectedMarkerUrl,it,e),t.markerHeight=this.getNumericStylingValue(this.styles.selectedMarkerHeight,40,e),t.markerWidth=this.getNumericStylingValue(this.styles.selectedMarkerWidth,32,e),t;if(e.geometry.type===`Polygon`)return t.polygonFillColor=this.getHexColorStylingValue(this.styles.selectedPolygonColor,t.polygonFillColor,e),t.polygonOutlineWidth=this.getNumericStylingValue(this.styles.selectedPolygonOutlineWidth,t.polygonOutlineWidth,e),t.polygonOutlineColor=this.getHexColorStylingValue(this.styles.selectedPolygonOutlineColor,t.polygonOutlineColor,e),t.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.selectedPolygonOutlineOpacity,1,e),t.polygonFillOpacity=this.getNumericStylingValue(this.styles.selectedPolygonFillOpacity,t.polygonFillOpacity,e),t.zIndex=N,t;if(e.geometry.type===`LineString`)return t.lineStringColor=this.getHexColorStylingValue(this.styles.selectedLineStringColor,t.lineStringColor,e),t.lineStringWidth=this.getNumericStylingValue(this.styles.selectedLineStringWidth,t.lineStringWidth,e),t.zIndex=N,t;if(e.geometry.type===`Point`)return t.pointWidth=this.getNumericStylingValue(this.styles.selectedPointWidth,t.pointWidth,e),t.pointColor=this.getHexColorStylingValue(this.styles.selectedPointColor,t.pointColor,e),t.pointOpacity=this.getNumericStylingValue(this.styles.selectedPointOpacity,1,e),t.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectedPointOutlineColor,t.pointOutlineColor,e),t.pointOutlineOpacity=this.getNumericStylingValue(this.styles.selectedPointOutlineOpacity,1,e),t.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectedPointOutlineWidth,t.pointOutlineWidth,e),t.zIndex=N,t}return t}afterFeatureUpdated(e){if(this.selected.length&&e.id===this.selected[0]){var t,n;let r=this.flags[e.properties.mode];if(r==null||(t=r.feature)==null||!t.coordinates)return;let i=e.geometry.type,a=e.id;if(this.selectionPoints.delete(),this.midPoints.delete(),i!==`LineString`&&i!==`Polygon`)return;let o=e.geometry.coordinates;this.selectionPoints.create({featureCoordinates:o,featureId:a}),r!=null&&(n=r.feature)!=null&&(n=n.coordinates)!=null&&n.midpoints&&this.midPoints.create({featureCoordinates:o,featureId:a})}}},$n=class extends P{constructor(...e){super(...e),this.type=lt.Static,this.mode=`static`}start(){}stop(){}onKeyUp(){}onKeyDown(){}onClick(){}onDragStart(){}onDrag(){}onDragEnd(){}onMouseMove(){}cleanUp(){}styleFeature(){return O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0})}};function er(e,t,n,r,i){for(;r>n;){if(r-n>600){let a=r-n+1,o=t-n+1,s=Math.log(a),c=.5*Math.exp(2*s/3),l=.5*Math.sqrt(s*c*(a-c)/a)*(o-a/2<0?-1:1);er(e,t,Math.max(n,Math.floor(t-o*c/a+l)),Math.min(r,Math.floor(t+(a-o)*c/a+l)),i)}let a=e[t],o=n,s=r;for(tr(e,n,t),i(e[r],a)>0&&tr(e,n,r);o<s;){for(tr(e,o,s),o++,s--;i(e[o],a)<0;)o++;for(;i(e[s],a)>0;)s--}i(e[n],a)===0?tr(e,n,s):(s++,tr(e,s,r)),s<=t&&(n=s+1),t<=s&&(r=s-1)}}function tr(e,t,n){let r=e[t];e[t]=e[n],e[n]=r}function nr(e,t){rr(e,0,e.children.length,t,e)}function rr(e,t,n,r,i){i||=fr([]),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let a=t;a<n;a++){let t=e.children[a];ir(i,e.leaf?r(t):t)}return i}function ir(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function ar(e,t){return e.minX-t.minX}function or(e,t){return e.minY-t.minY}function sr(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function cr(e){return e.maxX-e.minX+(e.maxY-e.minY)}function lr(e,t){let n=Math.max(e.minX,t.minX),r=Math.max(e.minY,t.minY),i=Math.min(e.maxX,t.maxX),a=Math.min(e.maxY,t.maxY);return Math.max(0,i-n)*Math.max(0,a-r)}function ur(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function dr(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function fr(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function pr(e,t,n,r,i){let a=[t,n];for(;a.length;){if((n=a.pop())-(t=a.pop())<=r)continue;let o=t+Math.ceil((n-t)/r/2)*r;er(e,o,t,n,i),a.push(t,o,o,n)}}var mr=class{constructor(e){this._maxEntries=void 0,this._minEntries=void 0,this.data=void 0,this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}search(e){let t=this.data,n=[];if(!dr(e,t))return n;let r=this.toBBox,i=[];for(;t;){for(let a=0;a<t.children.length;a++){let o=t.children[a],s=t.leaf?r(o):o;dr(e,s)&&(t.leaf?n.push(o):ur(e,s)?this._all(o,n):i.push(o))}t=i.pop()}return n}collides(e){let t=this.data;if(dr(e,t)){let n=[];for(;t;){for(let r=0;r<t.children.length;r++){let i=t.children[r],a=t.leaf?this.toBBox(i):i;if(dr(e,a)){if(t.leaf||ur(e,a))return!0;n.push(i)}}t=n.pop()}}return!1}load(e){if(e.length<this._minEntries){for(let t=0;t<e.length;t++)this.insert(e[t]);return}let t=this._build(e.slice(),0,e.length-1,0);if(this.data.children.length)if(this.data.height===t.height)this._splitRoot(this.data,t);else{if(this.data.height<t.height){let e=this.data;this.data=t,t=e}this._insert(t,this.data.height-t.height-1,!0)}else this.data=t}insert(e){this._insert(e,this.data.height-1)}clear(){this.data=fr([])}remove(e){let t=this.data,n=this.toBBox(e),r=[],i=[],a,o,s=!1;for(;t||r.length;){if(t||(t=r.pop(),o=r[r.length-1],a=i.pop(),s=!0),t.leaf){let n=t.children.indexOf(e);n!==-1&&(t.children.splice(n,1),r.push(t),this._condense(r))}s||t.leaf||!ur(t,n)?o?(a++,t=o.children[a],s=!1):t=null:(r.push(t),i.push(a),a=0,o=t,t=t.children[0])}}toBBox(e){return e}compareMinX(e,t){return e.minX-t.minX}compareMinY(e,t){return e.minY-t.minY}_all(e,t){let n=[];for(;e;)e.leaf?t.push(...e.children):n.push(...e.children),e=n.pop();return t}_build(e,t,n,r){let i=n-t+1,a,o=this._maxEntries;if(i<=o)return a=fr(e.slice(t,n+1)),nr(a,this.toBBox),a;r||(r=Math.ceil(Math.log(i)/Math.log(o)),o=Math.ceil(i/o**(r-1))),a=fr([]),a.leaf=!1,a.height=r;let s=Math.ceil(i/o),c=s*Math.ceil(Math.sqrt(o));pr(e,t,n,c,this.compareMinX);for(let i=t;i<=n;i+=c){let t=Math.min(i+c-1,n);pr(e,i,t,s,this.compareMinY);for(let n=i;n<=t;n+=s){let i=Math.min(n+s-1,t);a.children.push(this._build(e,n,i,r-1))}}return nr(a,this.toBBox),a}_chooseSubtree(e,t,n,r){for(;r.push(t),!t.leaf&&r.length-1!==n;){let n,r=1/0,o=1/0;for(let s=0;s<t.children.length;s++){let c=t.children[s],l=sr(c),u=(i=e,a=c,(Math.max(a.maxX,i.maxX)-Math.min(a.minX,i.minX))*(Math.max(a.maxY,i.maxY)-Math.min(a.minY,i.minY))-l);u<o?(o=u,r=l<r?l:r,n=c):u===o&&l<r&&(r=l,n=c)}t=n||t.children[0]}var i,a;return t}_insert(e,t,n){let r=n?e:this.toBBox(e),i=[],a=this._chooseSubtree(r,this.data,t,i);for(a.children.push(e),ir(a,r);t>=0&&i[t].children.length>this._maxEntries;)this._split(i,t),t--;this._adjustParentBBoxes(r,i,t)}_split(e,t){let n=e[t],r=n.children.length,i=this._minEntries;this._chooseSplitAxis(n,i,r);let a=this._chooseSplitIndex(n,i,r),o=fr(n.children.splice(a,n.children.length-a));o.height=n.height,o.leaf=n.leaf,nr(n,this.toBBox),nr(o,this.toBBox),t?e[t-1].children.push(o):this._splitRoot(n,o)}_splitRoot(e,t){this.data=fr([e,t]),this.data.height=e.height+1,this.data.leaf=!1,nr(this.data,this.toBBox)}_chooseSplitIndex(e,t,n){let r,i=1/0,a=1/0;for(let o=t;o<=n-t;o++){let t=rr(e,0,o,this.toBBox),s=rr(e,o,n,this.toBBox),c=lr(t,s),l=sr(t)+sr(s);c<i?(i=c,r=o,a=l<a?l:a):c===i&&l<a&&(a=l,r=o)}return r||n-t}_chooseSplitAxis(e,t,n){let r=e.leaf?this.compareMinX:ar,i=e.leaf?this.compareMinY:or;this._allDistMargin(e,t,n,r)<this._allDistMargin(e,t,n,i)&&e.children.sort(r)}_allDistMargin(e,t,n,r){e.children.sort(r);let i=this.toBBox,a=rr(e,0,t,i),o=rr(e,n-t,n,i),s=cr(a)+cr(o);for(let r=t;r<n-t;r++){let t=e.children[r];ir(a,e.leaf?i(t):t),s+=cr(a)}for(let r=n-t-1;r>=t;r--){let t=e.children[r];ir(o,e.leaf?i(t):t),s+=cr(o)}return s}_adjustParentBBoxes(e,t,n){for(let r=n;r>=0;r--)ir(t[r],e)}_condense(e){for(let t,n=e.length-1;n>=0;n--)e[n].children.length===0?n>0?(t=e[n-1].children,t.splice(t.indexOf(e[n]),1)):this.clear():nr(e[n],this.toBBox)}},hr=class{constructor(e){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new mr(e&&e.maxEntries?e.maxEntries:9),this.idToNode=new Map,this.nodeToId=new Map}setMaps(e,t){this.idToNode.set(e.id,t),this.nodeToId.set(t,e.id)}toBBox(e){let t=[],n=[],r;if(e.geometry.type===`Polygon`)r=e.geometry.coordinates[0];else if(e.geometry.type===`LineString`)r=e.geometry.coordinates;else{if(e.geometry.type!==`Point`)throw Error(`Not a valid feature to turn into a bounding box`);r=[e.geometry.coordinates]}for(let e=0;e<r.length;e++)n.push(r[e][1]),t.push(r[e][0]);let i=Math.min(...n),a=Math.max(...n);return{minX:Math.min(...t),minY:i,maxX:Math.max(...t),maxY:a}}insert(e){if(this.idToNode.get(String(e.id)))throw Error(`Feature already exists`);let t=this.toBBox(e);this.setMaps(e,t),this.tree.insert(t)}load(e){let t=[],n=new Set;e.forEach(e=>{let r=this.toBBox(e);if(this.setMaps(e,r),n.has(String(e.id)))throw Error(`Duplicate feature ID found ${e.id}`);n.add(String(e.id)),t.push(r)}),this.tree.load(t)}update(e){this.remove(e.id);let t=this.toBBox(e);this.setMaps(e,t),this.tree.insert(t)}remove(e){let t=this.idToNode.get(e);if(!t)throw Error(`${e} not inserted into the spatial index`);this.tree.remove(t)}clear(){this.tree.clear()}search(e){return this.tree.search(this.toBBox(e)).map(e=>this.nodeToId.get(e))}collides(e){return this.tree.collides(this.toBBox(e))}},gr={getId:()=>`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,function(e){let t=16*Math.random()|0;return(e==`x`?t:3&t|8).toString(16)}),isValidId:e=>typeof e==`string`&&e.length===36},_r={target:`geometry`},vr={target:`properties`},yr=class{constructor(e){this.idStrategy=void 0,this.tracked=void 0,this.spatialIndex=void 0,this.store=void 0,this._onChange=()=>{},this.store={},this.spatialIndex=new hr,this.tracked=!e||!1!==e.tracked,this.idStrategy=e&&e.idStrategy?e.idStrategy:gr}clone(e){return JSON.parse(JSON.stringify(e))}getId(){return this.idStrategy.getId()}has(e){return!!this.store[e]}load(e,t,n,r){if(e.length===0)return[];let i=this.clone(e),a=[],o=[];i=i.filter(e=>{e.id??=this.idStrategy.getId();let n=e.id;if(t){let r=t(e);if(!r.valid)return a.push({id:n,valid:!1,reason:r.reason}),!1}if(this.tracked){if(e.properties.createdAt){if(!st(e.properties.createdAt))return a.push({id:e.id,valid:!1,reason:`createdAt is not a valid numeric timestamp`}),!1}else e.properties.createdAt=+new Date;if(e.properties.updatedAt){if(!st(e.properties.updatedAt))return a.push({id:e.id,valid:!1,reason:`updatedAt is not a valid numeric timestamp`}),!1}else e.properties.updatedAt=+new Date}return this.has(n)?(a.push({id:n,valid:!1,reason:`Feature already exists with this id: ${n}`}),!1):(this.store[n]=e,o.push(e),a.push({id:n,valid:!0}),!0)}),this.spatialIndex.load(i);let s=o.map(({id:e})=>e);return s.length>0&&(this._onChange(s,`create`,r),n&&o.forEach(e=>{n(e)})),a}search(e,t){let n=this.spatialIndex.search(e).map(e=>this.store[e]);return this.clone(t?n.filter(t):n)}registerOnChange(e){this._onChange=(t,n,r)=>{e(t,n,r)}}getGeometryCopy(e){let t=this.store[e];if(!t)throw Error(`No feature with this id (${e}), can not get geometry copy`);return this.clone(t.geometry)}getPropertiesCopy(e){let t=this.store[e];if(!t)throw Error(`No feature with this id (${e}), can not get properties copy`);return this.clone(t.properties)}updateProperty(e,t){let n=new Set;e.forEach(({id:e,property:t,value:r})=>{let i=this.store[e];if(!i)throw Error(`No feature with this (${e}), can not update geometry`);i.properties[t]!==r&&(n.add(e),r===void 0?delete i.properties[t]:i.properties[t]=r,this.tracked&&(i.properties.updatedAt=+new Date))}),this._onChange&&n.size>0&&this._onChange(Array.from(n),`update`,t?O({},t,vr):vr)}updateGeometry(e,t){let n=new Set;e.forEach(({id:e,geometry:t})=>{n.add(e);let r=this.store[e];if(!r)throw Error(`No feature with this (${e}), can not update geometry`);r.geometry=this.clone(t),this.spatialIndex.update(r),this.tracked&&(r.properties.updatedAt=+new Date)}),this._onChange&&n.size>0&&this._onChange(Array.from(n),`update`,t?O({},t,_r):_r)}create(e,t){let n=[];return e.forEach(({geometry:e,properties:t})=>{let r,i=O({},t);this.tracked&&(r=+new Date,t?(i.createdAt=typeof t.createdAt==`number`?t.createdAt:r,i.updatedAt=typeof t.updatedAt==`number`?t.updatedAt:r):i={createdAt:r,updatedAt:r});let a=this.getId(),o={id:a,type:`Feature`,geometry:e,properties:i};this.store[a]=o,this.spatialIndex.insert(o),n.push(a)}),this._onChange&&this._onChange([...n],`create`,t),n}delete(e,t){e.forEach(e=>{if(!this.store[e])throw Error(`No feature with id ${e}, can not delete`);delete this.store[e],this.spatialIndex.remove(e)}),this._onChange&&this._onChange([...e],`delete`,t)}copy(e){return this.clone(this.store[e])}copyAll(){return this.clone(Object.keys(this.store).map(e=>this.store[e]))}copyAllWhere(e){return this.clone(Object.keys(this.store).map(e=>this.store[e]).filter(t=>t.properties&&e(t.properties)))}clear(e){let t=Object.keys(this.store);this.store={},this.spatialIndex.clear(),this._onChange(t,`delete`,e)}size(){return Object.keys(this.store).length}};Math.PI/180;var br=`Feature is not a Polygon or LineString`,xr=`Feature intersects itself`,Sr=e=>e.geometry.type!==`Polygon`&&e.geometry.type!==`LineString`?{valid:!1,reason:br}:yt(e)?{valid:!1,reason:xr}:{valid:!0};function Cr(e,t,n){let r=q(e,t),i=q(t,n)-r;return i<0&&(i+=360),180-Math.abs(i-90-90)}var wr={cancel:`Escape`,finish:`Enter`},Tr={start:`crosshair`,close:`pointer`},Er=class extends P{constructor(e){super(e,!0),this.mode=`angled-rectangle`,this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=wr,this.cursors=Tr,this.mouseMove=!1,this.mutateFeature=void 0,this.readFeature=void 0,this.updateOptions(e)}updateOptions(e){super.updateOptions(e),e!=null&&e.cursors&&(this.cursors=O({},this.cursors,e.cursors)),e?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:e!=null&&e.keyEvents&&(this.keyEvents=O({},this.keyEvents,e.keyEvents))}close(){if(this.currentId===void 0||!this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:{[M.CURRENTLY_DRAWING]:void 0},context:{updateType:A.Finish,action:k}}))return;let e=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.state===`drawing`&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:k})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onMouseMove(e){if(this.mouseMove=!0,this.setCursor(this.cursors.start),this.currentId===void 0||this.currentCoordinate===0)return;let t=[];if(this.currentCoordinate===1)t=this.getUpdateForSecondCoordinate(e);else{if(this.currentCoordinate!==2)return;t=this.getNewSecondAndThirdCoordinates(e)}this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:t,context:{updateType:A.Provisional}})}getUpdateForSecondCoordinate(e){return[{type:H,index:1,coordinate:[e.lng,e.lat]},{type:H,index:2,coordinate:[e.lng,e.lat]}]}getNewSecondAndThirdCoordinates(e){if(!this.currentId)throw Error(`No current feature being drawn`);let t=this.readFeature.getCoordinate(this.currentId,0),n=this.readFeature.getCoordinate(this.currentId,1),r=Nn(t,n,this.coordinatePrecision,this.project,this.unproject),i=z(t[0],t[1]),a=z(r[0],r[1]),o=z(n[0],n[1]),s=z(e.lng,e.lat),c=G(s,i)<G(s,o),l=Cr(i,a,s),u=c?90-l:Cr(i,a,s)-90,d=G(a,s),f=Math.cos(I(u))*d,p=q(i,o)+(function(e,t,n){let r=(n.x-t.x)*(e.y-t.y)-(n.y-t.y)*(e.x-t.x);return r>1e-10?`left`:r<-1e-10?`right`:`left`}(i,o,s)===`right`?-90:90),m=Kt(i,f,p),h=Kt(o,f,p),g=B(m.x,m.y),_=B(h.x,h.y);return[{type:H,index:2,coordinate:[R(_.lng,this.coordinatePrecision),R(_.lat,this.coordinatePrecision)]},{type:H,index:3,coordinate:[R(g.lng,this.coordinatePrecision),R(g.lat,this.coordinatePrecision)]}]}onClick(e){if(e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e))if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(e),this.mouseMove=!1,this.currentCoordinate===0){let{id:t}=this.mutateFeature.createPolygon({coordinates:[[e.lng,e.lat],[e.lng,e.lat],[e.lng,e.lat],[e.lng,e.lat]],properties:{mode:this.mode,[M.CURRENTLY_DRAWING]:!0}});this.currentId=t,this.currentCoordinate++,this.setDrawing()}else if(this.currentCoordinate===1&&this.currentId){let t=this.readFeature.getCoordinate(this.currentId,0);if(Lt([e.lng,e.lat],t)||!this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:H,index:1,coordinate:[e.lng,e.lat]},{type:Mt,index:1,coordinate:[e.lng,e.lat]}],context:{updateType:A.Commit}}))return;this.currentCoordinate++}else this.currentCoordinate===2&&this.currentId&&this.close()}onKeyUp(e){if(e.key===this.keyEvents.cancel)this.cleanUp();else if(e.key===this.keyEvents.finish){if(this.currentCoordinate<2)return void this.cleanUp();this.close()}}onKeyDown(){}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){let e=this.currentId;this.currentId=void 0,this.currentCoordinate=0,this.state===`drawing`&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(e)}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return e.properties.mode===this.mode&&e.geometry.type===`Polygon`&&(t.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,t.polygonFillColor,e),t.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,t.polygonOutlineColor,e),t.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,t.polygonOutlineWidth,e),t.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,e),t.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,t.polygonFillOpacity,e),t.zIndex=N),t}validateFeature(e){return this.validateModeFeature(e,e=>kt(e,this.coordinatePrecision))}afterFeatureUpdated(e){this.currentId===e.id&&(this.currentId=void 0,this.currentCoordinate=0,this.state===`drawing`&&this.setStarted())}registerBehaviors(e){this.readFeature=new K(e),this.mutateFeature=new W(e,{validate:this.validate})}};function Dr(e,t,n){return(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x)<=0}var Or={cancel:`Escape`,finish:`Enter`},kr={start:`crosshair`,close:`pointer`},Ar=class extends P{constructor(e){super(e,!0),this.mode=`sector`,this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=Or,this.direction=void 0,this.arcPoints=64,this.cursors=kr,this.mouseMove=!1,this.readFeature=void 0,this.mutateFeature=void 0,this.updateOptions(e)}updateOptions(e){super.updateOptions(e),e!=null&&e.cursors&&(this.cursors=O({},this.cursors,e.cursors)),e?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:e!=null&&e.keyEvents&&(this.keyEvents=O({},this.keyEvents,e.keyEvents)),e!=null&&e.arcPoints&&(this.arcPoints=e.arcPoints)}close(){if(this.currentId===void 0||!this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:{[M.CURRENTLY_DRAWING]:void 0},coordinateMutations:{coordinates:this.readFeature.getGeometry(this.currentId).coordinates,type:U},context:{updateType:A.Finish,action:k}}))return;let e=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.direction=void 0,this.state===`drawing`&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:k})}getSectorCoordinates(e){let t=this.readFeature.getCoordinates(this.currentId),n=t[0],r=t[1],i=[e.lng,e.lat],a=z(n[0],n[1]),o=z(r[0],r[1]),s=z(i[0],i[1]);this.direction===void 0&&(this.direction=Dr(a,o,s)?`clockwise`:`anticlockwise`);let c=G(a,o),l=q(a,o),u=q(a,s),d=this.arcPoints,f=[n],p=Jt(l),m=Jt(u),h;this.direction===`anticlockwise`?(h=m-p,h<0&&(h+=360)):(h=p-m,h<0&&(h+=360));let g=(this.direction===`anticlockwise`?1:-1)*h/d;f.push(r);for(let e=0;e<=d;e++){let t=Kt(a,c,p+e*g),{lng:n,lat:r}=B(t.x,t.y),i=[R(n,this.coordinatePrecision),R(r,this.coordinatePrecision)];i[0]!==f[f.length-1][0]&&i[1]!==f[f.length-1][1]&&f.push(i)}return f.push(n),f}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onMouseMove(e){if(this.mouseMove=!0,this.setCursor(this.cursors.start),this.currentId===void 0||this.currentCoordinate===0)return;let t;if(this.currentCoordinate===1)t=[{type:H,index:1,coordinate:[e.lng,e.lat]},{type:H,index:2,coordinate:[e.lng,e.lat]}];else{if(this.currentCoordinate!==2)return;{let n=this.getSectorCoordinates(e);if(!n)return;t={type:U,coordinates:[n]}}}this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:t,context:{updateType:A.Provisional}})}onClick(e){if(e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e))if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(e),this.mouseMove=!1,this.currentCoordinate===0)this.currentId=this.mutateFeature.createPolygon({coordinates:[[e.lng,e.lat],[e.lng,e.lat],[e.lng,e.lat],[e.lng,e.lat]],properties:{mode:this.mode,[M.CURRENTLY_DRAWING]:!0}})?.id,this.currentCoordinate++,this.setDrawing();else if(this.currentCoordinate===1&&this.currentId){if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,index:0,newCoordinate:[e.lng,e.lat]})||!this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:H,index:1,coordinate:[e.lng,e.lat]},{type:H,index:2,coordinate:[e.lng,e.lat]}],context:{updateType:A.Provisional}}))return;this.currentCoordinate++}else this.currentCoordinate===2&&this.currentId&&this.close()}onKeyUp(e){e.key===this.keyEvents.cancel?this.cleanUp():e.key===this.keyEvents.finish&&this.close()}onKeyDown(){}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){let e=this.currentId;this.currentId=void 0,this.direction=void 0,this.currentCoordinate=0,this.state===`drawing`&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(e)}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return e.properties.mode===this.mode&&e.geometry.type===`Polygon`&&(t.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,t.polygonFillColor,e),t.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,t.polygonOutlineColor,e),t.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,t.polygonOutlineWidth,e),t.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,e),t.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,t.polygonFillOpacity,e),t.zIndex=N),t}validateFeature(e){return this.validateModeFeature(e,e=>kt(e,this.coordinatePrecision))}afterFeatureUpdated(e){this.currentId===e.id&&(this.currentId=void 0,this.direction=void 0,this.currentCoordinate=0,this.state===`drawing`&&this.setStarted())}registerBehaviors(e){this.readFeature=new K(e),this.mutateFeature=new W(e,{validate:this.validate})}},jr={cancel:`Escape`,finish:`Enter`},Mr={start:`crosshair`,close:`pointer`},Nr=class extends P{constructor(e){super(e,!0),this.mode=`sensor`,this.currentCoordinate=0,this.currentId=void 0,this.currentInitialArcId=void 0,this.currentStartingPointId=void 0,this.keyEvents=jr,this.direction=void 0,this.arcPoints=64,this.cursors=Mr,this.mouseMove=!1,this.readFeature=void 0,this.mutateFeature=void 0,this.updateOptions(e)}updateOptions(e){super.updateOptions(e),e!=null&&e.cursors&&(this.cursors=O({},this.cursors,e.cursors)),e?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:e!=null&&e.keyEvents&&(this.keyEvents=O({},this.keyEvents,e.keyEvents)),e!=null&&e.arcPoints&&(this.arcPoints=e.arcPoints)}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onMouseMove(e){if(this.mouseMove=!0,this.setCursor(this.cursors.start),this.currentInitialArcId!==void 0&&this.currentStartingPointId!==void 0&&this.currentCoordinate!==0){if(this.currentCoordinate===2){let t=this.getUpdatedLineStringCoordinates(e);if(!t)return;this.mutateFeature.updateLineString({featureId:this.currentInitialArcId,coordinateMutations:{type:U,coordinates:t},context:{updateType:A.Provisional}})}else if(this.currentCoordinate===3){let t=this.getUpdatedPolygonCoordinates(e);if(!t)return;if(this.currentId)this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:{type:U,coordinates:[t]},context:{updateType:A.Provisional}});else{let e=this.mutateFeature.createPolygon({coordinates:t,properties:{mode:this.mode,[M.CURRENTLY_DRAWING]:!0}});if(!e)return;this.currentId=e.id}}}}onClick(e){if(e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e))if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(e),this.mouseMove=!1,this.currentCoordinate===0){let t=this.mutateFeature.createPoint({coordinates:[e.lng,e.lat],properties:{mode:this.mode}});if(!t)return;this.currentStartingPointId=t.id,this.currentCoordinate++,this.setDrawing()}else if(this.currentCoordinate===1&&this.currentStartingPointId){let t=this.mutateFeature.createLineString({coordinates:[[e.lng,e.lat],[e.lng,e.lat]],properties:{mode:this.mode}});if(!t)return;this.currentInitialArcId=t.id,this.currentCoordinate++}else this.currentCoordinate===2&&this.currentStartingPointId?this.currentCoordinate++:this.currentCoordinate===3&&this.currentStartingPointId&&this.close()}onKeyUp(e){e.key===this.keyEvents.cancel?this.cleanUp():e.key===this.keyEvents.finish&&this.close()}onKeyDown(){}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){this.mutateFeature.deleteFeatureIfPresent(this.currentStartingPointId),this.mutateFeature.deleteFeatureIfPresent(this.currentInitialArcId),this.mutateFeature.deleteFeatureIfPresent(this.currentId),this.currentStartingPointId=void 0,this.direction=void 0,this.currentId=void 0,this.currentCoordinate=0,this.state===`drawing`&&this.setStarted()}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return e.properties.mode===this.mode&&(e.geometry.type===`Polygon`?(t.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,t.polygonFillColor,e),t.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,t.polygonOutlineColor,e),t.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,t.polygonOutlineWidth,e),t.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,e),t.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,t.polygonFillOpacity,e),t.zIndex=N):e.geometry.type===`LineString`?(t.lineStringColor=this.getHexColorStylingValue(this.styles.outlineColor,t.polygonOutlineColor,e),t.lineStringWidth=this.getNumericStylingValue(this.styles.outlineWidth,t.polygonOutlineWidth,e),t.zIndex=N):e.geometry.type===`Point`&&(t.pointColor=this.getHexColorStylingValue(this.styles.centerPointColor,t.pointColor,e),t.pointOpacity=this.getNumericStylingValue(this.styles.centerPointOpacity,1,e),t.pointWidth=this.getNumericStylingValue(this.styles.centerPointWidth,t.pointWidth,e),t.pointOutlineColor=this.getHexColorStylingValue(this.styles.centerPointOutlineColor,t.pointOutlineColor,e),t.pointOutlineOpacity=this.getNumericStylingValue(this.styles.centerPointOutlineOpacity,1,e),t.pointOutlineWidth=this.getNumericStylingValue(this.styles.centerPointOutlineWidth,t.pointOutlineWidth,e),t.zIndex=20)),t}validateFeature(e){return this.validateModeFeature(e,e=>kt(e,this.coordinatePrecision))}afterFeatureUpdated(e){this.currentId===e.id&&(this.mutateFeature.deleteFeatureIfPresent(this.currentStartingPointId),this.mutateFeature.deleteFeatureIfPresent(this.currentInitialArcId),this.currentStartingPointId=void 0,this.direction=void 0,this.currentId=void 0,this.currentCoordinate=0,this.state===`drawing`&&this.setStarted())}registerBehaviors(e){this.readFeature=new K(e),this.mutateFeature=new W(e,{validate:this.validate})}close(){if(this.currentStartingPointId===void 0)return;let e=this.currentStartingPointId,t=this.currentInitialArcId;if(this.currentId&&!this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:{[M.CURRENTLY_DRAWING]:void 0},coordinateMutations:{coordinates:this.readFeature.getGeometry(this.currentId).coordinates,type:U},context:{updateType:A.Finish,action:k}}))return;let n=this.currentId;this.mutateFeature.deleteFeatureIfPresent(e),this.mutateFeature.deleteFeatureIfPresent(t),this.currentCoordinate=0,this.currentStartingPointId=void 0,this.currentInitialArcId=void 0,this.currentId=void 0,this.direction=void 0,this.state===`drawing`&&this.setStarted(),n&&this.onFinish(n,{mode:this.mode,action:k})}getUpdatedPolygonCoordinates(e){if(this.currentInitialArcId===void 0||this.currentStartingPointId===void 0||this.currentCoordinate<3)return;let t=this.readFeature.getCoordinates(this.currentInitialArcId);if(t.length<2||!this.direction)return;let n=this.readFeature.getGeometry(this.currentStartingPointId).coordinates,r=t[0],i=t[t.length-1],a=z(e.lng,e.lat),o=z(r[0],r[1]),s=z(i[0],i[1]),c=z(n[0],n[1]),l=G(c,o),u=G(c,a)<l?o:a,d=q(c,a),f=q(c,o),p=q(c,s),m=Jt(f),h=Jt(p),g=Jt(d);if(this.notInSector({normalizedCursor:g,normalizedStart:m,normalizedEnd:h,direction:this.direction}))return;let _=this.getDeltaBearing(this.direction,m,h),v=this.arcPoints,ee=(this.direction===`anticlockwise`?1:-1)*_/v,te=G(c,u),y=[];for(let e=0;e<=v;e++){let n=Kt(c,te,m+e*ee),{lng:r,lat:i}=B(n.x,n.y),a=[R(r,this.coordinatePrecision),R(i,this.coordinatePrecision)];a[0]!==t[t.length-1][0]&&a[1]!==t[t.length-1][1]&&y.unshift(a)}return t.push(...y),t.push(t[0]),t}getUpdatedLineStringCoordinates(e){if(this.currentInitialArcId===void 0||this.currentStartingPointId===void 0||this.currentCoordinate<2)return;let t=this.readFeature.getGeometry(this.currentInitialArcId).coordinates,n=this.readFeature.getGeometry(this.currentStartingPointId).coordinates,r=t[0],i=[e.lng,e.lat],a=z(r[0],r[1]),o=z(i[0],i[1]),s=z(n[0],n[1]),c=G(s,a);this.direction===void 0&&(this.direction=Dr(s,a,o)?`clockwise`:`anticlockwise`);let l=q(s,a),u=q(s,o),d=this.arcPoints,f=[r],p=Jt(l),m=Jt(u),h;this.direction===`anticlockwise`?(h=m-p,h<0&&(h+=360)):(h=p-m,h<0&&(h+=360));let g=(this.direction===`anticlockwise`?1:-1)*h/d;for(let e=0;e<=d;e++){let t=Kt(s,c,p+e*g),{lng:n,lat:r}=B(t.x,t.y),i=[R(n,this.coordinatePrecision),R(r,this.coordinatePrecision)];i[0]!==f[f.length-1][0]&&i[1]!==f[f.length-1][1]&&f.push(i)}return f}getDeltaBearing(e,t,n){let r;return e===`anticlockwise`?(r=n-t,r<0&&(r+=360)):(r=t-n,r<0&&(r+=360)),r}notInSector({normalizedCursor:e,normalizedStart:t,normalizedEnd:n,direction:r}){return r===`clockwise`?t<=n?e>=t&&e<=n:e>=t||e<=n:t>=n?e<=t&&e>=n:e<=t||e>=n}},Pr=class{constructor({name:e,callback:t,unregister:n,register:r}){this.name=void 0,this.callback=void 0,this.registered=!1,this.register=void 0,this.unregister=void 0,this.name=e,this.register=()=>{this.registered||(this.registered=!0,r(t))},this.unregister=()=>{this.register&&(this.registered=!1,n(t))},this.callback=t}},Fr={__proto__:null,GeoJSONStore:yr,TerraDrawBaseDrawMode:P,TerraDrawBaseSelectMode:dt,TerraDrawBaseAdapter:class{constructor(e){this._nextKeyUpIsContextMenu=!1,this._lastPointerDownEventTarget=void 0,this._ignoreMismatchedPointerEvents=!1,this._minPixelDragDistance=void 0,this._minPixelDragDistanceDrawing=void 0,this._minPixelDragDistanceSelecting=void 0,this._lastDrawEvent=void 0,this._coordinatePrecision=void 0,this._heldKeys=new Set,this._listeners=[],this._dragState=`not-dragging`,this._currentModeCallbacks=void 0,this._ignoreMismatchedPointerEvents=typeof e.ignoreMismatchedPointerEvents==`boolean`&&e.ignoreMismatchedPointerEvents,this._minPixelDragDistance=typeof e.minPixelDragDistance==`number`?e.minPixelDragDistance:1,this._minPixelDragDistanceSelecting=typeof e.minPixelDragDistanceSelecting==`number`?e.minPixelDragDistanceSelecting:1,this._minPixelDragDistanceDrawing=typeof e.minPixelDragDistanceDrawing==`number`?e.minPixelDragDistanceDrawing:8,this._coordinatePrecision=typeof e.coordinatePrecision==`number`?e.coordinatePrecision:9}getButton(e){return e.button===-1?`neither`:e.button===0?`left`:e.button===1?`middle`:e.button===2?`right`:`neither`}getMapElementXYPosition(e){let{left:t,top:n}=this.getMapEventElement(e.type).getBoundingClientRect();return{containerX:e.clientX-t,containerY:e.clientY-n}}getDrawEventFromEvent(e,t=!1){let n=this.getLngLatFromEvent(e);if(!n)return null;let{lng:r,lat:i}=n,{containerX:a,containerY:o}=this.getMapElementXYPosition(e),s=this.getButton(e),c=Array.from(this._heldKeys);return{lng:R(r,this._coordinatePrecision),lat:R(i,this._coordinatePrecision),containerX:a,containerY:o,button:s,heldKeys:c,isContextMenu:t}}register(e){this._currentModeCallbacks=e,this._listeners=this.getAdapterListeners(),this._listeners.forEach(e=>{e.register()})}getCoordinatePrecision(){return this._coordinatePrecision}getAdapterListeners(){return[new Pr({name:`pointerdown`,callback:e=>{if(!this._currentModeCallbacks||!e.isPrimary)return;let t=this.getDrawEventFromEvent(e);t&&(this._dragState=`pre-dragging`,this._lastDrawEvent=t,this._lastPointerDownEventTarget=e.target?e.target:void 0)},register:e=>{this.getMapEventElement(`pointerdown`).addEventListener(`pointerdown`,e)},unregister:e=>{this.getMapEventElement(`pointerdown`).removeEventListener(`pointerdown`,e)}}),new Pr({name:`pointermove`,callback:e=>{if(!this._currentModeCallbacks||!e.isPrimary)return;e.preventDefault();let t=this.getDrawEventFromEvent(e);if(t)if(this._dragState===`not-dragging`)this._currentModeCallbacks.onMouseMove(t),this._lastDrawEvent=t;else if(this._dragState===`pre-dragging`){if(!this._lastDrawEvent)return;let e={x:this._lastDrawEvent.containerX,y:this._lastDrawEvent.containerY},n={x:t.containerX,y:t.containerY},r=this._currentModeCallbacks.getState(),i=G(e,n),a=!1;if(a=r===`drawing`?i<this._minPixelDragDistanceDrawing:r===`selecting`?i<this._minPixelDragDistanceSelecting:i<this._minPixelDragDistance,a)return;this._nextKeyUpIsContextMenu=!1,this._dragState=`dragging`,this._currentModeCallbacks.onDragStart(t,e=>{this.setDraggability.bind(this)(e)})}else this._dragState===`dragging`&&this._currentModeCallbacks.onDrag(t,e=>{this.setDraggability.bind(this)(e)})},register:e=>{this.getMapEventElement(`pointermove`).addEventListener(`pointermove`,e)},unregister:e=>{this.getMapEventElement(`pointermove`).removeEventListener(`pointermove`,e)}}),new Pr({name:`contextmenu`,callback:e=>{this._currentModeCallbacks&&(e.preventDefault(),this._nextKeyUpIsContextMenu=!0)},register:e=>{this.getMapEventElement(`contextmenu`).addEventListener(`contextmenu`,e)},unregister:e=>{this.getMapEventElement(`contextmenu`).removeEventListener(`contextmenu`,e)}}),new Pr({name:`pointerup`,callback:e=>{if(!this._currentModeCallbacks||e.target!==this.getMapEventElement(`pointerup`)||this._ignoreMismatchedPointerEvents&&this._lastPointerDownEventTarget!==e.target||(this._lastPointerDownEventTarget=void 0,!e.isPrimary))return;let t=this.getDrawEventFromEvent(e);t&&(this._dragState===`dragging`?this._currentModeCallbacks.onDragEnd(t,e=>{this.setDraggability.bind(this)(e)}):this._dragState!==`not-dragging`&&this._dragState!==`pre-dragging`||(this._nextKeyUpIsContextMenu&&=(t.isContextMenu=!0,!1),this._currentModeCallbacks.onClick(t)),this._dragState=`not-dragging`,this.setDraggability(!0))},register:e=>{this.getMapEventElement(`pointerup`).addEventListener(`pointerup`,e)},unregister:e=>{this.getMapEventElement(`pointerup`).removeEventListener(`pointerup`,e)}}),new Pr({name:`keyup`,callback:e=>{this._currentModeCallbacks&&(this._heldKeys.delete(e.key),this._currentModeCallbacks.onKeyUp({key:e.key,heldKeys:Array.from(this._heldKeys),preventDefault:()=>e.preventDefault()}))},register:e=>{this.getMapEventElement(`keyup`).addEventListener(`keyup`,e)},unregister:e=>{this.getMapEventElement(`keyup`).removeEventListener(`keyup`,e)}}),new Pr({name:`keydown`,callback:e=>{this._currentModeCallbacks&&(this._heldKeys.add(e.key),this._currentModeCallbacks.onKeyDown({key:e.key,heldKeys:Array.from(this._heldKeys),preventDefault:()=>e.preventDefault()}))},register:e=>{this.getMapEventElement(`keydown`).addEventListener(`keydown`,e)},unregister:e=>{this.getMapEventElement(`keydown`).removeEventListener(`keydown`,e)}})]}unregister(){this._listeners.forEach(e=>{e.unregister()}),this.clear(),this._currentModeCallbacks=void 0,this._lastDrawEvent=void 0,this._lastPointerDownEventTarget=void 0,this._nextKeyUpIsContextMenu=!1}},getDefaultStyling:()=>({polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0}),SELECT_PROPERTIES:j},Ir={cancel:`Escape`,finish:`Enter`},Lr={start:`crosshair`,close:`pointer`},Rr=class extends P{constructor(e){super(e,!0),this.mode=`freehand-linestring`,this.canClose=!1,this.currentId=void 0,this.minDistance=20,this.keyEvents=Ir,this.cursors=Lr,this.preventNewFeature=!1,this.mutateFeature=void 0,this.readFeature=void 0,this.pixelDistance=void 0,this.closingPoints=void 0,this.updateOptions(e)}updateOptions(e){super.updateOptions(e),e!=null&&e.minDistance&&(this.minDistance=e.minDistance),e?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:e!=null&&e.keyEvents&&(this.keyEvents=O({},this.keyEvents,e.keyEvents)),e!=null&&e.cursors&&(this.cursors=O({},this.cursors,e.cursors))}close(){if(this.currentId===void 0||!this.mutateFeature.updateLineString({featureId:this.currentId,propertyMutations:{[M.CURRENTLY_DRAWING]:void 0},context:{updateType:A.Finish,action:k}}))return;let e=this.currentId;this.closingPoints.delete(),this.canClose=!1,this.currentId=void 0,this.state===`drawing`&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:k})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onMouseMove(e){if(this.currentId===void 0||!1===this.canClose)return void this.setCursor(this.cursors.start);let[t,n]=this.readFeature.getCoordinate(this.currentId,-2),{x:r,y:i}=this.project(t,n),a=G({x:r,y:i},{x:e.containerX,y:e.containerY}),[o,s]=this.readFeature.getCoordinate(this.currentId,-1),{x:c,y:l}=this.project(o,s),u=G({x:c,y:l},{x:e.containerX,y:e.containerY});if(this.setCursor(u<this.pointerDistance?this.cursors.close:this.cursors.start),a<this.minDistance)return;let d=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:[{type:Mt,index:-1,coordinate:[e.lng,e.lat]}],context:{updateType:A.Provisional}});d&&this.closingPoints.update(d.geometry.coordinates)}onClick(e){if(e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e)){if(this.preventNewFeature)return;if(!1===this.canClose){let{id:t,geometry:n}=this.mutateFeature.createLineString({coordinates:[[e.lng,e.lat],[e.lng,e.lat]],properties:{mode:this.mode,[M.CURRENTLY_DRAWING]:!0}});this.closingPoints.create(n.coordinates),this.currentId=t,this.canClose=!0,this.state!==`drawing`&&this.setDrawing();return}this.close()}}onKeyDown(){}onKeyUp(e){e.key===this.keyEvents.cancel?this.cleanUp():e.key===this.keyEvents.finish&&!0===this.canClose&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){let e=this.currentId;this.currentId=void 0,this.canClose=!1,this.state===`drawing`&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(e),this.closingPoints.delete()}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return e.type===`Feature`&&e.geometry.type===`LineString`&&e.properties.mode===this.mode?(t.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,t.lineStringColor,e),t.lineStringOpacity=this.getNumericStylingValue(this.styles.lineStringOpacity,t.lineStringOpacity===void 0?1:t.lineStringOpacity,e),t.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,t.lineStringWidth,e),t.zIndex=N,t):e.type===`Feature`&&e.geometry.type===`Point`&&e.properties.mode===this.mode?(t.pointWidth=this.getNumericStylingValue(this.styles.closingPointWidth,t.pointWidth,e),t.pointOpacity=this.getNumericStylingValue(this.styles.closingPointOpacity,1,e),t.pointColor=this.getHexColorStylingValue(this.styles.closingPointColor,t.pointColor,e),t.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,t.pointOutlineColor,e),t.pointOutlineOpacity=this.getNumericStylingValue(this.styles.closingPointOutlineOpacity,1,e),t.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,e),t.zIndex=50,t):t}validateFeature(e){return this.validateModeFeature(e,e=>$t(e,this.coordinatePrecision))}afterFeatureUpdated(e){this.currentId===e.id&&(this.closingPoints.delete(),this.canClose=!1,this.currentId=void 0)}registerBehaviors(e){this.readFeature=new K(e),this.mutateFeature=new W(e,{validate:this.validate}),this.pixelDistance=new Ut(e),this.closingPoints=new dn(e,this.pixelDistance,this.mutateFeature,this.readFeature)}};function zr(e){if(e===null||typeof e==`boolean`||typeof e==`string`)return!0;if(e===void 0)return!1;if(typeof e==`number`)return Number.isFinite(e);if(typeof e==`bigint`||typeof e==`symbol`||typeof e==`function`||e instanceof RegExp||e instanceof Map||e instanceof Set||e instanceof Date)return!1;if(typeof e==`object`&&e&&!Array.isArray(e)){let t=Object.getPrototypeOf(e);if(t!==Object.prototype&&t!==null)return!1}if(ArrayBuffer.isView(e)&&!(e instanceof DataView))return!1;if(Array.isArray(e)){for(let t of e)if(!zr(t))return!1}return typeof e==`object`&&Object.keys(e).every(t=>typeof t==`string`&&zr(e[t]))}var Br={create:`crosshair`,dragStart:`grabbing`,dragEnd:`crosshair`},Vr=class extends P{constructor(e){super(e,!0),this.mode=`marker`,this.cursors=Br,this.editable=!1,this.editedFeatureId=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.pointSearch=void 0,this.mutateFeature=void 0,this.updateOptions(e)}updateOptions(e){super.updateOptions(e),e!=null&&e.cursors&&(this.cursors=O({},this.cursors,e.cursors)),e!=null&&e.editable&&(this.editable=e.editable)}start(){this.setStarted(),this.setCursor(this.cursors.create)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onClick(e){e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e)?this.onRightClick(e):e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)&&this.onLeftClick(e)}onMouseMove(){}onKeyDown(){}onKeyUp(){}cleanUp(){this.editedFeatureId=void 0}onDragStart(e,t){this.allowPointerEvent(this.pointerEvents.onDragStart,e)&&(this.editable&&(this.editedFeatureId=this.pointSearch.getNearestPointFeature(e)?.id),this.editedFeatureId&&(this.setCursor(this.cursors.dragStart),t(!1)))}onDrag(e,t){this.allowPointerEvent(this.pointerEvents.onDrag,e)&&this.editedFeatureId!==void 0&&this.mutateFeature.updatePoint({featureId:this.editedFeatureId,coordinateMutations:{type:U,coordinates:[e.lng,e.lat]},propertyMutations:{[M.EDITED]:!0},context:{updateType:A.Provisional}})}onDragEnd(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDragEnd,e)||this.editedFeatureId===void 0||!this.mutateFeature.updatePoint({featureId:this.editedFeatureId,propertyMutations:{mode:this.mode,[M.EDITED]:!1},context:{updateType:A.Finish,action:`edit`}}))return;let n=this.editedFeatureId;this.setCursor(this.cursors.dragEnd),this.editedFeatureId=void 0,t(!0),this.onFinish(n,{mode:this.mode,action:k})}registerBehaviors(e){this.pixelDistance=new Ut(e),this.clickBoundingBox=new Ht(e),this.pointSearch=new xn(e,this.pixelDistance,this.clickBoundingBox),this.mutateFeature=new W(e,{validate:this.validate})}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return e.type===`Feature`&&e.geometry.type===`Point`&&e.properties.mode===this.mode&&(t.zIndex=30,t.markerHeight=this.getNumericStylingValue(this.styles?.markerHeight,40,e),t.markerWidth=this.getNumericStylingValue(this.styles?.markerWidth,32,e),t.markerUrl=this.getUrlStylingValue(this.styles?.markerUrl,it,e)),t}validateFeature(e){return this.validateModeFeature(e,e=>bn(e,this.coordinatePrecision))}onLeftClick(e){let t=this.mutateFeature.createPoint({coordinates:[e.lng,e.lat],properties:{mode:this.mode,[M.MARKER]:!0},context:{updateType:A.Finish,action:k}});t&&this.onFinish(t.id,{mode:this.mode,action:k})}onRightClick(e){if(!this.editable)return;let t=this.pointSearch.getNearestPointFeature(e);t&&this.mutateFeature.deleteFeatureIfPresent(t.id)}afterFeatureUpdated(e){this.editedFeatureId===e.id&&(this.editedFeatureId=void 0,this.setCursor(this.cursors.create))}},Hr=[{key:`z`,heldKeys:[`meta`]},{key:`z`,heldKeys:[`control`]}],Ur=[{key:`z`,heldKeys:[`meta`,`shift`]},{key:`z`,heldKeys:[`control`,`shift`]},{key:`y`,heldKeys:[`control`]}],Wr=(e,t)=>{let n=e.key.toLowerCase(),r=new Set(e.heldKeys.map(e=>e.toLowerCase()).filter(e=>e!==n));if(t.key.toLowerCase()!==n)return!1;let i=new Set(t.heldKeys.map(e=>e.toLowerCase()));if(r.size!==i.size)return!1;for(let e of i)if(!r.has(e))return!1;return!0},Gr=class{constructor(e){this.undoKeyboardShortcuts=void 0,this.redoKeyboardShortcuts=void 0,this.undoKeyboardShortcuts=e?.undo??Hr,this.redoKeyboardShortcuts=e?.redo??Ur}isUndoKeyboardShortcut(e){return this.undoKeyboardShortcuts.some(t=>Wr(e,t))}isRedoKeyboardShortcut(e){return this.redoKeyboardShortcuts.some(t=>Wr(e,t))}};function Kr(e){return e!==void 0&&Number.isFinite(e)?Math.max(0,Math.floor(e)):1/0}var J=`undo`,qr=`redo`,Jr=`push`,Yr=`mode`,Xr=`session`,Zr=class{constructor(e){this.getModeState=void 0,this.getModeHistorySizes=void 0,this.undoMode=void 0,this.redoMode=void 0,this.clearModeHistory=void 0,this.onHistoryChange=void 0,this.maxStackSize=void 0,this.lastHistorySizes={undoSize:0,redoSize:0},this.maxStackSize=Kr(e?.maxStackSize)}getMaxStackSize(){return this.maxStackSize}register(e){this.getModeState=e.getModeState,this.getModeHistorySizes=e.getModeHistorySizes,this.undoMode=e.undoMode,this.redoMode=e.redoMode,this.clearModeHistory=e.clearModeHistory,this.onHistoryChange=e.onHistoryChange}inDrawingState(){return!!this.getModeState&&this.getModeState()===`drawing`}canUndo(){if(!this.inDrawingState())return!1;let{undoSize:e}=this.getHistorySizes();return e>0}canRedo(){if(!this.inDrawingState())return!1;let{redoSize:e}=this.getHistorySizes();return e>0}undo(){return!(!this.canUndo()||!this.undoMode||(this.undoMode(),this.emitHistoryChange(J),0))}redo(){return!(!this.canRedo()||!this.redoMode||(this.redoMode(),this.emitHistoryChange(qr),0))}clearHistory(){this.clearModeHistory&&this.clearModeHistory(),this.lastHistorySizes={undoSize:0,redoSize:0}}getHistorySizes(){return this.getModeHistorySizes?this.getModeHistorySizes():{undoSize:0,redoSize:0}}undoSize(){return this.getHistorySizes().undoSize}redoSize(){return this.getHistorySizes().redoSize}emitPushIfHistoryChangedFromLastSnapshot(){if(!this.inDrawingState())return;let e=this.getHistorySizes();e.undoSize===this.lastHistorySizes.undoSize&&e.redoSize===this.lastHistorySizes.redoSize||this.emitHistoryChange(Jr)}emitPushIfHistoryChanged(e){if(!this.inDrawingState())return;let t=this.getHistorySizes();t.undoSize===e.undoSize&&t.redoSize===e.redoSize||this.emitHistoryChange(Jr)}emitHistoryChange(e){if(!this.onHistoryChange)return;let{undoSize:t,redoSize:n}=this.getHistorySizes();this.lastHistorySizes={undoSize:t,redoSize:n},this.onHistoryChange({cause:e,stack:Yr,undoStackSize:t,redoStackSize:n})}},Qr=class{constructor(e){this.draw=void 0,this.onHistoryChange=void 0,this.maxStackSize=void 0,this.historyById={},this.undoStack=[],this.ignoreProgrammaticCreate={},this.ignoreProgrammaticDelete={},this.deletedFeatureIds={},this.redoStack=[],this.emitStackChange=e=>{this.onHistoryChange&&this.onHistoryChange({cause:e,stack:Xr,undoStackSize:this.undoStack.length,redoStackSize:this.redoStack.length})},this.handleChange=(e,t,n)=>{if(!this.draw||this.isDrawing()||this.maxStackSize===0||t!==`delete`&&t!==`create`)return;if(t===`create`){if(n===void 0||!(`origin`in n)||n.origin!==`api`)return;let t=!1,r=Array.isArray(e)?e:[e],i=[];for(let e of r){if(this.ignoreProgrammaticCreate[e]){delete this.ignoreProgrammaticCreate[e],delete this.deletedFeatureIds[e];continue}let n=String(e),r=this.draw.getSnapshotFeature(e);r&&(this.deletedFeatureIds[e]&&(this.historyById[n]=[],delete this.deletedFeatureIds[e]),this.historyById[n]||(this.historyById[n]=[]),this.historyById[n].push(r),i.push({id:e,toIndex:this.historyById[n].length-1,snapshot:r}),t=!0)}if(i.length>1)this.pushUndoStackEntry({id:i[0].id,toIndex:i[0].toIndex,action:`batch-create`,metadata:{entries:i}});else if(i.length===1){let e=i[0];this.pushUndoStackEntry({id:e.id,toIndex:e.toIndex,action:`single`})}t&&(this.redoStack.length=0,this.emitStackChange(Jr));return}let r=!1,i=Array.isArray(e)?e:[e],a=[];for(let e of i){let t=String(e);if(this.ignoreProgrammaticDelete[e]){delete this.ignoreProgrammaticDelete[e];continue}if(!this.historyById[t])continue;let n=this.historyById[t].length-1;if(n>=0){let i=this.historyById[t][n];if(!i)continue;a.push({id:e,toIndex:n,snapshot:i}),this.deletedFeatureIds[e]=!0,r=!0}}if(a.length>1)this.pushUndoStackEntry({id:a[0].id,toIndex:a[0].toIndex,action:`batch-delete`,metadata:{entries:a}});else if(a.length===1){let e=a[0];this.pushUndoStackEntry({id:e.id,toIndex:e.toIndex,action:`single`})}r&&(this.redoStack.length=0,this.emitStackChange(Jr))},this.handleFinish=e=>{if(!this.draw||this.maxStackSize===0)return;let t=Array.isArray(e)?e:[e],n=!1;for(let e of t){if(e==null)continue;let t=String(e),r=this.draw.getSnapshotFeature(e);r&&(this.historyById[t]||(this.historyById[t]=[]),this.historyById[t].push(r),n||=(this.redoStack.length=0,!0),this.pushUndoStackEntry({id:e,toIndex:this.historyById[t].length-1,action:`single`}),this.emitStackChange(Jr))}},this.maxStackSize=Kr(e?.maxStackSize)}register(e){this.draw===e.draw?this.onHistoryChange=e.onHistoryChange:(this.draw&&(this.draw.off(`change`,this.handleChange),this.draw.off(`finish`,this.handleFinish)),this.draw=e.draw,this.draw.on(`change`,this.handleChange),this.draw.on(`finish`,this.handleFinish),this.onHistoryChange=e.onHistoryChange)}pushUndoStackEntry(e){this.maxStackSize!==0&&(this.undoStack.push(e),this.undoStack.length>this.maxStackSize&&this.undoStack.shift())}pushRedoStackEntry(e){this.maxStackSize!==0&&(this.redoStack.push(e),this.redoStack.length>this.maxStackSize&&this.redoStack.shift())}isDrawing(){return!!this.draw&&this.draw.getModeState()===`drawing`}canUndo(){return!(!this.draw||this.isDrawing())&&this.undoStack.length>0}canRedo(){return!(!this.draw||this.isDrawing())&&this.redoStack.length>0}undo(){if(!this.canUndo()||!this.draw)return!1;let e=this.undoStack.pop();if(!e)return this.emitStackChange(J),!1;if(e.action===`batch-create`){let t=e.metadata?.entries||[];if(t.length===0)return this.emitStackChange(J),!1;let n=t.map(e=>e.id);return n.forEach(e=>{this.ignoreProgrammaticDelete[e]=!0,this.deletedFeatureIds[e]=!0}),this.draw.removeFeatures(n),this.pushRedoStackEntry({id:t[0].id,toIndex:t[0].toIndex,action:`batch-create`,metadata:{entries:t}}),this.emitStackChange(J),!0}if(e.action===`batch-delete`){let t=e.metadata?.entries||[];if(t.length===0)return this.emitStackChange(J),!1;let n=t.map(e=>e.snapshot).filter(e=>e!==void 0);return n.length>0&&(t.forEach(e=>{this.ignoreProgrammaticCreate[e.id]=!0,delete this.deletedFeatureIds[e.id]}),this.draw.addFeatures(n)),this.pushRedoStackEntry({id:t[0].id,toIndex:t[0].toIndex,action:`batch-delete`,metadata:{entries:t}}),this.emitStackChange(J),!0}let t=e.id,n=e.toIndex,r=String(t),i=this.historyById[r];if(!i||i.length===0)return this.emitStackChange(J),!1;let a=Math.min(n,i.length-1);if(!this.draw.hasFeature(t)){let e=i[a];return e?(this.ignoreProgrammaticCreate[t]=!0,delete this.deletedFeatureIds[t],this.draw.addFeatures([e]),this.pushRedoStackEntry({id:t,toIndex:a,action:`delete`,snapshot:e}),this.emitStackChange(J),!0):(this.emitStackChange(J),!1)}if(a<=0)return this.pushRedoStackEntry({id:t,toIndex:0,action:`create`}),this.ignoreProgrammaticDelete[t]=!0,this.deletedFeatureIds[t]=!0,this.draw.removeFeatures([t]),this.undoStack=this.undoStack.filter(e=>e.id!==t),this.emitStackChange(J),!0;let o=i[a],s=i[a-1];return o&&this.pushRedoStackEntry({id:t,toIndex:a,snapshot:o,action:`update`}),this.draw.updateFeatureGeometry(t,s.geometry),i.length=a,this.emitStackChange(J),!0}redo(){if(!this.canRedo()||!this.draw)return!1;let{id:e,toIndex:t,snapshot:n,action:r,metadata:i}=this.redoStack.pop();if(r===`batch-create`){let e=i?.entries||[];if(e.length===0)return this.emitStackChange(qr),!1;let t=e.map(e=>e.snapshot).filter(e=>e!==void 0);return t.length>0&&(e.forEach(e=>{this.ignoreProgrammaticCreate[e.id]=!0}),this.draw.addFeatures(t)),this.pushUndoStackEntry({id:e[0].id,toIndex:e[0].toIndex,action:`batch-create`,metadata:{entries:e}}),this.emitStackChange(qr),!0}if(r===`batch-delete`){let e=i?.entries||[];if(e.length===0)return this.emitStackChange(qr),!1;let t=e.map(e=>e.id);return t.forEach(e=>{this.ignoreProgrammaticDelete[e]=!0,this.deletedFeatureIds[e]=!0}),this.draw.removeFeatures(t),this.pushUndoStackEntry({id:e[0].id,toIndex:e[0].toIndex,action:`batch-delete`,metadata:{entries:e}}),this.emitStackChange(qr),!0}let a=String(e),o=this.historyById[a]||(this.historyById[a]=[]);if(r===`delete`)return this.ignoreProgrammaticDelete[e]=!0,this.deletedFeatureIds[e]=!0,this.draw.removeFeatures([e]),this.pushUndoStackEntry({id:e,toIndex:t,action:`single`}),this.emitStackChange(qr),!0;if(t<=0){let t=o[0];return!!t&&(this.ignoreProgrammaticCreate[e]=!0,this.draw.addFeatures([t]),this.pushUndoStackEntry({id:e,toIndex:0,action:`single`}),this.emitStackChange(qr),!0)}let s=n||o[t];return!!s&&(o.length===t?o.push(s):(o[t]=s,o.length=t+1),this.draw.updateFeatureGeometry(e,s.geometry),this.pushUndoStackEntry({id:e,toIndex:t,action:`single`}),this.emitStackChange(qr),!0)}clearHistory(){let e={};if(this.draw&&!this.isDrawing()){let t=this.draw.getSnapshot();for(let n of t)e[String(n.id)]=[n]}this.historyById=e,this.undoStack=[],this.ignoreProgrammaticCreate={},this.ignoreProgrammaticDelete={},this.deletedFeatureIds={},this.redoStack=[]}undoSize(){return this.undoStack.length}redoSize(){return this.redoStack.length}},$r=class{constructor(e){this.modeLevel=void 0,this.sessionLevel=void 0,this.shouldPreferMode=void 0,this.onHistoryChange=void 0,this.shouldEmitHistoryChange=void 0,this.modeLevel=e.modeLevel,this.sessionLevel=e.sessionLevel,this.shouldPreferMode=e.shouldPreferMode,this.onHistoryChange=e.onHistoryChange,this.shouldEmitHistoryChange=e.shouldEmitHistoryChange??(()=>!0)}emitStackHistoryChange(e){this.shouldEmitHistoryChange()&&this.onHistoryChange&&this.onHistoryChange({cause:e.cause,stack:e.stack,undoSize:e.undoStackSize,redoSize:e.redoStackSize})}hasSessionUndo(){return!!(this.sessionLevel&&this.sessionLevel.canUndo())}hasSessionRedo(){return!!(this.sessionLevel&&this.sessionLevel.canRedo())}activeStackForUndo(){var e,t;return this.shouldPreferMode()&&(e=this.modeLevel)!=null&&e.canUndo()?Yr:this.hasSessionUndo()?Xr:(t=this.modeLevel)!=null&&t.canUndo()?Yr:void 0}activeStackForRedo(){var e,t;return this.shouldPreferMode()&&(e=this.modeLevel)!=null&&e.canRedo()?Yr:this.hasSessionRedo()?Xr:(t=this.modeLevel)!=null&&t.canRedo()?Yr:void 0}canUndo(){return this.activeStackForUndo()!==void 0}canRedo(){return this.activeStackForRedo()!==void 0}undo(){let e=this.activeStackForUndo();return!!e&&(e===Yr?!!this.modeLevel&&this.modeLevel.undo():!(!this.sessionLevel||!this.sessionLevel.canUndo())&&this.sessionLevel.undo())}redo(){let e=this.activeStackForRedo();return!!e&&(e===Yr?!!this.modeLevel&&this.modeLevel.redo():!(!this.sessionLevel||!this.sessionLevel.canRedo())&&this.sessionLevel.redo())}clearHistory(){this.modeLevel&&this.modeLevel.clearHistory(),this.sessionLevel&&this.sessionLevel.clearHistory()}emitPushAfterFinish(){this.sessionLevel?this.emitStackHistoryChange({cause:Jr,undoStackSize:this.sessionLevel.undoSize(),redoStackSize:this.sessionLevel.redoSize(),stack:Xr}):this.modeLevel&&this.emitStackHistoryChange({cause:Jr,undoStackSize:this.modeLevel.undoSize(),redoStackSize:this.modeLevel.redoSize(),stack:Yr})}},ei=class{constructor(e){var t,n,r,i;this._modes=void 0,this._mode=void 0,this._adapter=void 0,this._enabled=!1,this._store=void 0,this._eventListeners=void 0,this._instanceSelectModes=void 0,this.sessionUndoRedoEnabled=!1,this.keyboardShortcutsMatcher=void 0,this.drawingUndoRedo=void 0,this.sessionUndoRedo=void 0,this.undoRedoCoordinator=void 0,this._adapter=e.adapter,this._instanceSelectModes=[];let a=e==null||(t=e.undoRedo)==null?void 0:t.modeLevel;a&&(this.drawingUndoRedo=a);let o=e==null||(n=e.undoRedo)==null?void 0:n.keyboardShortcuts;o&&(this.keyboardShortcutsMatcher=o),this.sessionUndoRedoEnabled=!!(!(e==null||(r=e.undoRedo)==null)&&r.sessionLevel);let s=e==null||(i=e.undoRedo)==null?void 0:i.sessionLevel;this._mode=new $n;let c=new Set,l=e.modes.reduce((e,t)=>{if(c.has(t.mode))throw Error(`There is already a ${t.mode} mode provided`);return c.add(t.mode),e[t.mode]=t,e},{}),u=Object.keys(l);if(u.length===0)throw Error(`No modes provided`);u.forEach(e=>{l[e].type===lt.Select&&this._instanceSelectModes.push(e)}),this._modes=O({},l,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[],finish:[],ready:[],history:[]},this._store=new yr({tracked:!!e.tracked,idStrategy:e.idStrategy?e.idStrategy:void 0});let d=e=>{let t=[];return{changed:t,unchanged:this._store.copyAll().filter(n=>!e.includes(n.id)||(t.push(n),!1))}},f=(e,t)=>{this._enabled&&(this._eventListeners.finish.forEach(n=>{n(e,t)}),this.emitHistoryChangeAfterFinish())},p=(e,t,n)=>{if(!this._enabled)return;this._eventListeners.change.forEach(r=>{r(e,t,n)}),this.emitDrawingPushIfHistoryChangedFromLastSnapshot();let{changed:r,unchanged:i}=d(e);t===`create`?this._adapter.render({created:r,deletedIds:[],unchanged:i,updated:[]},this.getModeStyles()):t===`update`?this._adapter.render({created:[],deletedIds:[],unchanged:i,updated:r},this.getModeStyles()):t===`delete`?this._adapter.render({created:[],deletedIds:e,unchanged:i,updated:[]},this.getModeStyles()):t===`styling`&&this._adapter.render({created:[],deletedIds:[],unchanged:i,updated:[]},this.getModeStyles())},m=e=>{if(!this._enabled)return;this._eventListeners.select.forEach(t=>{t(e)});let{changed:t,unchanged:n}=d([e]);this._adapter.render({created:[],deletedIds:[],unchanged:n,updated:t},this.getModeStyles())},h=e=>{if(!this._enabled)return;this._eventListeners.deselect.forEach(t=>{t(e)});let{changed:t,unchanged:n}=d([e]);t&&this._adapter.render({created:[],deletedIds:[],unchanged:n,updated:t},this.getModeStyles())};Object.keys(this._modes).forEach(e=>{var t;this._modes[e].register({mode:e,store:this._store,setCursor:this._adapter.setCursor.bind(this._adapter),project:this._adapter.project.bind(this._adapter),unproject:this._adapter.unproject.bind(this._adapter),setDoubleClickToZoom:this._adapter.setDoubleClickToZoom.bind(this._adapter),onChange:p,onSelect:m,onDeselect:h,onFinish:f,coordinatePrecision:this._adapter.getCoordinatePrecision(),undoRedoMaxStackSize:(t=this.drawingUndoRedo)==null||t.getMaxStackSize==null?void 0:t.getMaxStackSize()})}),this.sessionUndoRedoEnabled&&s&&(this.sessionUndoRedo=s,s.register({draw:this,onHistoryChange:e=>{var t;(t=this.undoRedoCoordinator)==null||t.emitStackHistoryChange(e)}})),this.drawingUndoRedo&&this.drawingUndoRedo.register({getModeState:()=>this.getModeState(),getModeHistorySizes:()=>this.getDrawingHistorySizes(),undoMode:()=>{this._mode.undo&&this._mode.undo()},redoMode:()=>{this._mode.redo&&this._mode.redo()},clearModeHistory:()=>{let e=this._mode;e.clearHistory&&e.clearHistory()},onHistoryChange:e=>{var t;(t=this.undoRedoCoordinator)==null||t.emitStackHistoryChange(e)}}),this.undoRedoCoordinator=new $r({modeLevel:this.drawingUndoRedo,sessionLevel:this.sessionUndoRedo,shouldPreferMode:()=>this.getModeState()===`drawing`,onHistoryChange:e=>{this._eventListeners.history.forEach(t=>{t(e)})},shouldEmitHistoryChange:()=>this._enabled})}checkEnabled(){if(!this._enabled)throw Error(`Terra Draw is not enabled`)}handleUndoRedoKeyboardShortcut(e){if(!this.drawingUndoRedo&&!this.sessionUndoRedoEnabled||!this.keyboardShortcutsMatcher)return!1;let t=this.keyboardShortcutsMatcher.isUndoKeyboardShortcut(e),n=this.keyboardShortcutsMatcher.isRedoKeyboardShortcut(e);if(t){if(!this.canUndo())return!1;let t=this.undo();return t&&e.preventDefault(),t}if(n){if(!this.canRedo())return!1;let t=this.redo();return t&&e.preventDefault(),t}return!1}getDrawingHistorySizes(){return{undoSize:this._mode.undoSize&&typeof this._mode.undoSize==`function`?this._mode.undoSize():0,redoSize:this._mode.redoSize&&typeof this._mode.redoSize==`function`?this._mode.redoSize():0}}emitDrawingPushIfHistoryChangedFromLastSnapshot(){this.drawingUndoRedo&&this.drawingUndoRedo.emitPushIfHistoryChangedFromLastSnapshot()}emitDrawingPushIfHistoryChanged(e){this.drawingUndoRedo&&this.drawingUndoRedo.emitPushIfHistoryChanged(e)}emitHistoryChangeAfterFinish(){var e;(e=this.undoRedoCoordinator)==null||e.emitPushAfterFinish()}getModeStyles(){let e={},t=this._instanceSelectModes.includes(this._mode.mode)?this._mode.mode:void 0;return Object.keys(this._modes).forEach(n=>{e[n]=e=>t&&e.properties[j.SELECTED]?this._modes[t].styleFeature.bind(this._modes[t])(e):this._modes[n].styleFeature.bind(this._modes[n])(e)}),e}featuresAtLocation({lng:e,lat:t},n){let r=n&&n.pointerDistance!==void 0?n.pointerDistance:30,i=!n||n.ignoreSelectFeatures===void 0||n.ignoreSelectFeatures,a=!(!n||n.ignoreCoordinatePoints===void 0)&&n.ignoreCoordinatePoints,o=!(!n||n.ignoreCurrentlyDrawing===void 0)&&n.ignoreCurrentlyDrawing,s=!(!n||n.ignoreClosingPoints===void 0)&&n.ignoreClosingPoints,c=!(!n||n.ignoreSnappingPoints===void 0)&&n.ignoreSnappingPoints,l=this._adapter.unproject.bind(this._adapter),u=this._adapter.project.bind(this._adapter),d=u(e,t),f=Vt({unproject:l,point:d,pointerDistance:r});return this._store.search(f).filter(l=>{if(i&&(l.properties[j.MID_POINT]||l.properties[j.SELECTION_POINT])||a&&l.properties[M.COORDINATE_POINT]||s&&l.properties[M.CLOSING_POINT]||o&&l.properties[M.CURRENTLY_DRAWING]||c&&l.properties[M.SNAPPING_POINT])return!1;if(l.geometry.type===`Point`){let e=l.geometry.coordinates;return G(d,u(e[0],e[1]))<r}if(l.geometry.type===`LineString`){let e=l.geometry.coordinates;for(let t=0;t<e.length-1;t++){let n=e[t],i=e[t+1];if(zn(d,u(n[0],n[1]),u(i[0],i[1]))<r)return!0}return!1}if(Rn([e,t],l.geometry.coordinates))return!0;if(n!=null&&n.includePolygonsWithinPointerDistance){let e=l.geometry.coordinates;for(let t of e)for(let e=0;e<t.length-1;e++){let n=t[e],i=t[e+1];if(zn(d,u(n[0],n[1]),u(i[0],i[1]))<r)return!0}}return!1}).map(r=>{if(n==null||!n.addClosestCoordinateInfoToProperties)return r;let i;if(r.geometry.type===`Polygon`)i=r.geometry.coordinates[0].slice(0,-1);else{if(r.geometry.type!==`LineString`)return r;i=r.geometry.coordinates}let a,o=-1,s=1/0;for(let e=0;e<i.length;e++){let t=i[e],n=G(u(t[0],t[1]),d);n<s&&(o=e,s=n,a=t)}return r.properties.closestCoordinateIndexToEvent=o,r.properties.closestCoordinatePixelDistanceToEvent=s,r.properties.closestCoordinateDistanceKmToEvent=F(a,[e,t]),r})}getSelectModeOrThrow(e=void 0){let t=this.getSelectMode({switchToSelectMode:!0,selectMode:e});if(!t)throw Error(`No select mode defined in instance`);return t}getSelectMode({switchToSelectMode:e,selectMode:t}){this.checkEnabled();let n=this.getMode();if(this._instanceSelectModes.length===0)return null;if(t!==void 0&&!this._instanceSelectModes.includes(t))throw Error(`No select mode with this name present: ${t}`);let r;return r=t===void 0?this._instanceSelectModes.includes(n)?n:this._instanceSelectModes[0]:t,e&&n!==r&&this.setMode(r),this._modes[r]}isGuidanceFeature(e){return!!(e.properties[j.MID_POINT]||e.properties[j.SELECTION_POINT]||e.properties[M.COORDINATE_POINT]||e.properties[M.SNAPPING_POINT])}setModeStyles(e,t){if(this.checkEnabled(),!this._modes[e])throw Error(`No mode with this name present`);this._modes[e].styles=t}updateModeOptions(e,t){if(this.checkEnabled(),!this._modes[e])throw Error(`No mode with this name present`);this._modes[e].updateOptions(t)}getSnapshot(){return this._store.copyAll()}getSnapshotFeature(e){if(this._store.has(e))return this._store.copy(e)}clear(){this.checkEnabled(),this._adapter.clear()}get enabled(){return this._enabled}set enabled(e){throw Error(`Enabled is read only`)}getMode(){return this._mode.mode}getModeState(){return this._mode.state}setMode(e){if(this.checkEnabled(),!this._modes[e])throw Error(`No mode with this name present`);this._mode.stop(),this._mode=this._modes[e],this._mode.start()}removeFeatures(e){this.checkEnabled();let t=[],n=[],r;e.forEach(e=>{if(!this._store.has(e))throw Error(`No feature with id ${e}, can not delete`);let i=this._store.getPropertiesCopy(e);i[j.SELECTED]&&this.deselectFeature(e),i[M.CURRENTLY_DRAWING]&&this._modes[i.mode]?r=i.mode:(i[M.COORDINATE_POINT_IDS]&&t.push(...i[M.COORDINATE_POINT_IDS]),n.push(e))}),this._store.delete([...n,...t],{origin:`api`}),r&&this._modes[r]&&this._modes[r].cleanUp()&&this._modes[r].cleanUp()}selectFeature(e,t){this.getSelectModeOrThrow(t).selectFeature(e)}deselectFeature(e){this.getSelectModeOrThrow().deselectFeature(e)}getFeatureId(){return this._store.getId()}hasFeature(e){return this._store.has(e)}checkIsReservedProperty(e){return![...Object.values(j),...Object.values(M)].includes(e)}updateFeatureProperties(e,t){if(!this._store.has(e))throw Error(`No feature with id ${e} present in store`);let n=this._store.copy(e);if(this.isGuidanceFeature(n))throw Error(`Guidance features are not allowed to be updated directly.`);let r=n.properties.mode;if(!this._modes[r])throw Error(`No mode with name ${r} present in instance`);let i=Object.entries(t);i.forEach(([e,t])=>{if(!this.checkIsReservedProperty(e))throw Error(`You are trying to update a reserved property name: ${e}. Please choose another name.`);if(t!==void 0&&!zr(t))throw Error(`Invalid JSON value provided for property ${e}`)}),this._store.updateProperty(i.map(([e,t])=>({id:n.id,property:e,value:t})),{origin:`api`})}updateFeatureGeometry(e,t){if(!this._store.has(e))throw Error(`No feature with id ${e} present in store`);let n=this._store.copy(e);if(this.isGuidanceFeature(n))throw Error(`Guidance features are not allowed to be updated directly.`);if(!(n&&t&&t.type&&t.coordinates))throw Error(`Invalid geometry provided`);if(t.type!==n.geometry.type)throw Error(`Geometry type mismatch: expected ${n.geometry.type}, got ${t.type}`);let r=n.properties.mode,i=this._modes[r];if(!i)throw Error(`No mode with name ${r} present in instance`);let a=O({},n,{geometry:t}),o=i.validateFeature(a);if(!o.valid)throw Error(`Feature validation failed: ${o.reason||`Unknown reason`}`);if(this._store.updateGeometry([{id:n.id,geometry:t}],{origin:`api`}),i.afterFeatureUpdated){i.afterFeatureUpdated(a);let e=a.properties[j.SELECTED],t=this.getSelectMode({switchToSelectMode:!1});t&&e&&t.afterFeatureUpdated(a)}}transformFeatureGeometry(e,t){if(!this._store.has(e))throw Error(`No feature with id ${e} present in store`);let n=this._store.copy(e);if(this.isGuidanceFeature(n))throw Error(`Guidance features are not allowed to be updated directly.`);let r=n.properties.mode,i=this._modes[r];if(!i)throw Error(`No mode with name ${r} present in instance`);let a;if(n.geometry.type===`Polygon`)a=n.geometry.coordinates[0];else{if(n.geometry.type!==`LineString`)throw Error(`Feature geometry type ${n.geometry.type} is not supported for transformation`);a=n.geometry.coordinates}if(t.projection!=`web-mercator`)throw Error(`Projection ${t.projection} is not currently supported for transformation`);if(t.type===`scale`){let{x:e,y:n}=z(t.origin[0],t.origin[1]);Jn({coordinates:a,originX:e,originY:n,xScale:t.options.xScale||1,yScale:t.options.yScale||1})}else t.type===`rotate`&&(n=Wn(n,t.options.angle||0),a=n.geometry.type===`Polygon`?n.geometry.coordinates[0]:n.geometry.coordinates);if(a=a.map(e=>[R(e[0],this._adapter.getCoordinatePrecision()),R(e[1],this._adapter.getCoordinatePrecision())]),n.geometry.coordinates=n.geometry.type===`Polygon`?[a]:a,this._store.updateGeometry([{id:n.id,geometry:n.geometry}],{origin:`api`}),i.afterFeatureUpdated){i.afterFeatureUpdated(n);let e=n.properties[j.SELECTED],t=this.getSelectMode({switchToSelectMode:!1});t&&e&&t.afterFeatureUpdated(n)}}undo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.undo()}canUndo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.canUndo()}canRedo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.canRedo()}redo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.redo()}clearUndoRedoHistory(){this.checkEnabled(),this.undoRedoCoordinator&&this.undoRedoCoordinator.clearHistory()}addFeatures(e){return this.checkEnabled(),e.length===0?[]:this._store.load(e,e=>{if(ot(e)){let t=e.properties.mode,n=this._modes[t];if(!n)return{id:e.id,valid:!1,reason:`${t} mode is not in the list of instantiated modes`};let r=n.validateFeature.bind(n)(e);return{id:e.id,valid:r.valid,reason:r.reason?r.reason:r.valid?void 0:`Feature is invalid`}}return{id:e.id,valid:!1,reason:`Mode property does not exist`}},e=>{if(ot(e)){let t=this._modes[e.properties.mode];t&&t.afterFeatureAdded&&t.afterFeatureAdded(e)}},{origin:`api`})}start(){this._enabled||(this._enabled=!0,this._adapter.register({onReady:()=>{this._eventListeners.ready.forEach(e=>{e()})},getState:()=>this._mode.state,onClick:e=>{let t=this.drawingUndoRedo?this.drawingUndoRedo.getHistorySizes():{undoSize:0,redoSize:0};this._mode.onClick(e),this.emitDrawingPushIfHistoryChanged(t)},onMouseMove:e=>{this._mode.onMouseMove(e)},onKeyDown:e=>{this.handleUndoRedoKeyboardShortcut(e)||this._mode.onKeyDown(e)},onKeyUp:e=>{let t=this.drawingUndoRedo?this.drawingUndoRedo.getHistorySizes():{undoSize:0,redoSize:0};this._mode.onKeyUp(e),this.emitDrawingPushIfHistoryChanged(t)},onDragStart:(e,t)=>{this._mode.onDragStart(e,t)},onDrag:(e,t)=>{this._mode.onDrag(e,t)},onDragEnd:(e,t)=>{this._mode.onDragEnd(e,t)},onClear:()=>{this._mode.cleanUp(),this._store.clear({origin:`api`})}}))}getFeaturesAtLngLat(e,t){let{lng:n,lat:r}=e;return this.featuresAtLocation({lng:n,lat:r},t)}getFeaturesAtPointerEvent(e,t){let n=this._adapter.getLngLatFromEvent.bind(this._adapter)(e);return n===null?[]:this.featuresAtLocation(n,t)}stop(){this._enabled&&(this._enabled=!1,this._adapter.unregister())}on(e,t){let n=this._eventListeners[e];n.includes(t)||n.push(t)}off(e,t){let n=this._eventListeners[e];n.includes(t)&&n.splice(n.indexOf(t),1)}},ti=class extends Fr.TerraDrawBaseAdapter{constructor(e){super(e),this._renderBeforeLayerId=void 0,this._prefixId=void 0,this._initialDragPan=void 0,this._initialDragRotate=void 0,this._nextRender=void 0,this._map=void 0,this._container=void 0,this.changedIds={deletion:!1,points:!1,linestrings:!1,polygons:!1,styling:!1},this._map=e.map,this._container=this._map.getContainer(),this._initialDragRotate=this._map.dragRotate.isEnabled(),this._initialDragPan=this._map.dragPan.isEnabled(),this._renderBeforeLayerId=e.renderBelowLayerId,this._prefixId=e.prefixId||`td`}hashCode(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return Math.abs(t)}resizeImage(e,t,n,r){let i=new Image;i.crossOrigin=`anonymous`,i.onload=()=>{let e=document.createElement(`canvas`);e.width=t,e.height=n;let a=e.getContext(`2d`);if(!a)throw Error(`Could not get canvas context`);a.drawImage(i,0,0,t,n),r(e.toDataURL())},i.src=e}_addGeoJSONSource(e,t){this._map.addSource(e,{type:`geojson`,data:{type:`FeatureCollection`,features:t},tolerance:0})}_addFillLayer(e){return this._map.addLayer({id:e,source:e,type:`fill`,layout:{"fill-sort-key":[`get`,`zIndex`]},paint:{"fill-color":[`get`,`polygonFillColor`],"fill-opacity":[`get`,`polygonFillOpacity`]}})}_addFillOutlineLayer(e){return this._map.addLayer({id:e+`-outline`,source:e,type:`line`,layout:{"line-sort-key":[`get`,`zIndex`]},paint:{"line-width":[`get`,`polygonOutlineWidth`],"line-color":[`get`,`polygonOutlineColor`],"line-opacity":[`get`,`polygonOutlineOpacity`]}})}_addLineLayer(e){return this._map.addLayer({id:e,source:e,type:`line`,layout:{"line-sort-key":[`get`,`zIndex`]},paint:{"line-width":[`get`,`lineStringWidth`],"line-color":[`get`,`lineStringColor`],"line-opacity":[`get`,`lineStringOpacity`]}})}_addPointLayer(e){return this._map.addLayer({id:e,source:e,type:`circle`,layout:{"circle-sort-key":[`get`,`zIndex`]},paint:{"circle-stroke-color":[`get`,`pointOutlineColor`],"circle-stroke-width":[`get`,`pointOutlineWidth`],"circle-stroke-opacity":[`get`,`pointOutlineOpacity`],"circle-radius":[`get`,`pointWidth`],"circle-color":[`get`,`pointColor`],"circle-opacity":[`get`,`pointOpacity`]}})}_addMarkerLayer(e){return this._map.addLayer({id:e+`-marker`,source:e,type:`symbol`,filter:[`has`,`markerId`],layout:{"icon-image":[`image`,[`get`,`markerId`]],"icon-anchor":`bottom`,"icon-allow-overlap":!0}})}_addLayer(e,t){t===`Point`&&(this._addPointLayer(e),this._addMarkerLayer(e)),t===`LineString`&&this._addLineLayer(e),t===`Polygon`&&(this._addFillLayer(e),this._addFillOutlineLayer(e))}_addGeoJSONLayer(e,t){let n=`${this._prefixId}-${e.toLowerCase()}`;return this._addGeoJSONSource(n,t),this._addLayer(n,e),n}_setGeoJSONLayerData(e,t){let n=`${this._prefixId}-${e.toLowerCase()}`;return this._map.getSource(n).setData({type:`FeatureCollection`,features:t}),n}updateChangedIds(e){[...e.updated,...e.created].forEach(e=>{e.geometry.type===`Point`?this.changedIds.points=!0:e.geometry.type===`LineString`?this.changedIds.linestrings=!0:e.geometry.type===`Polygon`&&(this.changedIds.polygons=!0)}),e.deletedIds.length>0&&(this.changedIds.deletion=!0),e.created.length===0&&e.updated.length===0&&e.deletedIds.length===0&&(this.changedIds.styling=!0)}getLngLatFromEvent(e){let{left:t,top:n}=this._container.getBoundingClientRect();return this.unproject(e.clientX-t,e.clientY-n)}getMapEventElement(){return this._map.getCanvas()}setDraggability(e){e?(this._initialDragRotate&&this._map.dragRotate.enable(),this._initialDragPan&&this._map.dragPan.enable()):(this._initialDragRotate&&this._map.dragRotate.disable(),this._initialDragPan&&this._map.dragPan.disable())}project(e,t){let{x:n,y:r}=this._map.project({lng:e,lat:t});return{x:n,y:r}}unproject(e,t){let{lng:n,lat:r}=this._map.unproject({x:e,y:t});return{lng:n,lat:r}}setCursor(e){let t=this._map.getCanvas();e===`unset`?t.style.removeProperty(`cursor`):t.style.cursor=e}setDoubleClickToZoom(e){e?this._map.doubleClickZoom.enable():this._map.doubleClickZoom.disable()}render(e,t){this.updateChangedIds(e),this._nextRender&&cancelAnimationFrame(this._nextRender),this._nextRender=requestAnimationFrame(()=>{if(!this._currentModeCallbacks)return;let n=[...e.created,...e.updated,...e.unchanged],r=[],i=[],a=[];for(let e=0;e<n.length;e++){let o=n[e],{properties:s}=o,c=t[s.mode](o);if(s.zIndex=c.zIndex,s.zIndex=c.zIndex,o.geometry.type===`Point`){s.pointColor=c.pointColor,s.pointOutlineColor=c.pointOutlineColor,s.pointOutlineWidth=c.pointOutlineWidth;let e=c.pointOutlineOpacity;s.pointOutlineOpacity=e===void 0?1:e,s.pointWidth=c.pointWidth;let t=c.pointOpacity;if(s.pointOpacity=t===void 0?1:t,c.markerUrl&&c.markerWidth&&c.markerHeight){let e=`marker-${this.hashCode(c.markerUrl)}`;this._map.hasImage(e)||this.resizeImage(c.markerUrl,c.markerWidth,c.markerHeight,t=>{this._map.loadImage(t).then(t=>{this._map.hasImage(e)||this._map.addImage(e,t.data)})}),s.markerId=e,s.pointWidth=0}r.push(o)}else if(o.geometry.type===`LineString`){s.lineStringColor=c.lineStringColor,s.lineStringWidth=c.lineStringWidth;let e=c.lineStringOpacity;s.lineStringOpacity=e===void 0?1:e,i.push(o)}else if(o.geometry.type===`Polygon`){let e=c.polygonOutlineOpacity;s.polygonFillColor=c.polygonFillColor,s.polygonFillOpacity=c.polygonFillOpacity,s.polygonOutlineOpacity=e===void 0?1:e,s.polygonOutlineColor=c.polygonOutlineColor,s.polygonOutlineWidth=c.polygonOutlineWidth,a.push(o)}}let o=this.changedIds.deletion||this.changedIds.styling,s=o||this.changedIds.linestrings,c=o||this.changedIds.polygons;(o||this.changedIds.points)&&this._setGeoJSONLayerData(`Point`,r),s&&this._setGeoJSONLayerData(`LineString`,i),c&&this._setGeoJSONLayerData(`Polygon`,a),this.changedIds={points:!1,linestrings:!1,polygons:!1,deletion:!1,styling:!1}})}clear(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this._nextRender&&=(cancelAnimationFrame(this._nextRender),void 0),this._setGeoJSONLayerData(`Point`,[]),this._setGeoJSONLayerData(`LineString`,[]),this._setGeoJSONLayerData(`Polygon`,[]))}getCoordinatePrecision(){return super.getCoordinatePrecision()}unregister(){super.unregister(),this.changedIds={points:!1,linestrings:!1,polygons:!1,deletion:!1,styling:!1},this._map.removeLayer(`${this._prefixId}-point`),this._map.removeLayer(`${this._prefixId}-point-marker`),this._map.removeSource(`${this._prefixId}-point`),this._map.removeLayer(`${this._prefixId}-linestring`),this._map.removeSource(`${this._prefixId}-linestring`),this._map.removeLayer(`${this._prefixId}-polygon`),this._map.removeLayer(`${this._prefixId}-polygon-outline`),this._map.removeSource(`${this._prefixId}-polygon`)}register(e){var t;super.register(e);let n=this._addGeoJSONLayer(`Polygon`,[]),r=this._addGeoJSONLayer(`LineString`,[]),i=this._addGeoJSONLayer(`Point`,[]);var a;this._renderBeforeLayerId&&(this._map.moveLayer(i,this._renderBeforeLayerId),this._map.moveLayer(r,i),this._map.moveLayer(`${n}-outline`,r),this._map.moveLayer(n,`${n}-outline`)),(t=this._currentModeCallbacks)!=null&&t.onReady&&((a=this._currentModeCallbacks)==null||a.onReady())}},ni={modes:[`render`,`point`,`marker`,`linestring`,`polygon`,`rectangle`,`angled-rectangle`,`sensor`,`sector`,`circle`,`freehand`,`freehand-linestring`,`select`,`delete-selection`,`delete`,`undo`,`redo`,`download`],open:!1},ri={modes:[`render`,`point`,`marker`,`linestring`,`polygon`,`rectangle`,`angled-rectangle`,`sensor`,`sector`,`circle`,`freehand`,`freehand-linestring`,`select`,`delete-selection`,`delete`,`undo`,`redo`,`download`],open:!1,modeOptions:{point:new Cn({editable:!0,styles:{pointColor:`#FFFFFF`,pointWidth:5,pointOutlineColor:`#666666`,pointOutlineWidth:1}}),marker:new Vr({editable:!0,styles:{markerUrl:`data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='UTF-8'%20standalone='no'?%3e%3csvg%20xmlns:dc='http://purl.org/dc/elements/1.1/'%20xmlns:cc='http://creativecommons.org/ns%23'%20xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns%23'%20xmlns:svg='http://www.w3.org/2000/svg'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:sodipodi='http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd'%20xmlns:inkscape='http://www.inkscape.org/namespaces/inkscape'%20inkscape:version='1.0%20(4035a4fb49,%202020-05-01)'%20sodipodi:docname='poi.svg'%20id='svg4460'%20height='100'%20width='100'%20version='1.1'%3e%3csodipodi:namedview%20inkscape:document-rotation='0'%20inkscape:current-layer='svg4460'%20inkscape:window-maximized='1'%20inkscape:window-y='-8'%20inkscape:window-x='-8'%20inkscape:cy='70.031285'%20inkscape:cx='-78.460726'%20inkscape:zoom='2.02'%20showgrid='false'%20id='namedview11'%20inkscape:window-height='1017'%20inkscape:window-width='1920'%20inkscape:pageshadow='2'%20inkscape:pageopacity='0'%20guidetolerance='10'%20gridtolerance='10'%20objecttolerance='10'%20borderopacity='1'%20bordercolor='%23666666'%20pagecolor='%23ffffff'%20/%3e%3cdefs%20id='defs4462'%20/%3e%3cmetadata%20id='metadata4465'%3e%3crdf:RDF%3e%3ccc:Work%20rdf:about=''%3e%3cdc:format%3eimage/svg+xml%3c/dc:format%3e%3cdc:type%20rdf:resource='http://purl.org/dc/dcmitype/StillImage'%20/%3e%3cdc:title%3e%3c/dc:title%3e%3c/cc:Work%3e%3c/rdf:RDF%3e%3c/metadata%3e%3cpath%20d='M%2050.001528,3.3861402e-7%20C%2030.763177,3.3861402e-7%2015,15.718144%2015,34.901534%20c%200,7.432782%202.373565,14.339962%206.391689,20.019029%20l%2024.338528,42.073163%20c%203.40849,4.452814%205.674917,3.607154%208.509014,-0.23458%20L%2081.083105,51.075788%20C%2081.625418,50.0948%2082.050328,49.050173%2082.421327,47.983517%2084.078241,43.936622%2085.000002,39.521943%2085,34.901534%2085,15.718144%2069.23988,3.3861402e-7%2050.001528,3.3861402e-7%20Z%20m%200,16.35400066138598%20c%2010.359296,0%2018.597616,8.21783%2018.597618,18.547533%200,10.329703%20-8.238322,18.544487%20-18.597618,18.544487%20-10.359299,0%20-18.600672,-8.214784%20-18.600672,-18.544487%200,-10.329703%208.241373,-18.547533%2018.600672,-18.547533%20z'%20style='fill:rgb(95,%2099,%20104);stroke-width:4.26019'%20id='path4135'%20/%3e%3c/svg%3e`,markerWidth:27,markerHeight:27}}),linestring:new gn({editable:!0,styles:{lineStringColor:`#666666`,lineStringWidth:2,closingPointColor:`#FFFFFF`,closingPointWidth:3,closingPointOutlineColor:`#666666`,closingPointOutlineWidth:1}}),polygon:new En({editable:!0,styles:{fillColor:`#EDEFF0`,fillOpacity:.7,outlineColor:`#666666`,outlineWidth:2,closingPointColor:`#FAFAFA`,closingPointWidth:3,closingPointOutlineColor:`#666666`,closingPointOutlineWidth:1}}),rectangle:new kn({styles:{fillColor:`#EDEFF0`,fillOpacity:.7,outlineColor:`#666666`,outlineWidth:2}}),"angled-rectangle":new Er({styles:{fillColor:`#EDEFF0`,fillOpacity:.7,outlineColor:`#666666`,outlineWidth:2}}),circle:new It({styles:{fillColor:`#EDEFF0`,fillOpacity:.7,outlineColor:`#666666`,outlineWidth:2}}),freehand:new Bt({styles:{fillColor:`#EDEFF0`,fillOpacity:.7,outlineColor:`#666666`,outlineWidth:2,closingPointColor:`#FAFAFA`,closingPointWidth:3,closingPointOutlineColor:`#666666`,closingPointOutlineWidth:1}}),"freehand-linestring":new Rr({styles:{lineStringColor:`#666666`,lineStringWidth:2,closingPointColor:`#FFFFFF`,closingPointWidth:3,closingPointOutlineColor:`#666666`,closingPointOutlineWidth:1}}),sensor:new Nr({styles:{fillColor:`#EDEFF0`,fillOpacity:.7,outlineColor:`#666666`,outlineWidth:2,centerPointColor:`#FAFAFA`,centerPointWidth:3,centerPointOutlineColor:`#666666`,centerPointOutlineWidth:1}}),sector:new Ar({styles:{fillColor:`#EDEFF0`,fillOpacity:.7,outlineColor:`#666666`,outlineWidth:2}}),select:new Qn({flags:{point:{feature:{draggable:!1}},marker:{feature:{draggable:!1}},polygon:{feature:{draggable:!0,rotateable:!0,scaleable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},linestring:{feature:{draggable:!0,rotateable:!0,scaleable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},freehand:{feature:{draggable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},"freehand-linestring":{feature:{draggable:!0,rotateable:!0,scaleable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},circle:{feature:{draggable:!0,coordinates:{resizable:`center`,deletable:!1,midpoints:!1}}},rectangle:{feature:{draggable:!0,rotateable:!0,coordinates:{resizable:`opposite`,deletable:!1,midpoints:!1}}},"angled-rectangle":{feature:{draggable:!0,rotateable:!0,coordinates:{resizable:`opposite`,deletable:!1,midpoints:!1}}},sensor:{feature:{draggable:!0,rotateable:!0,scaleable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},sector:{feature:{draggable:!0,rotateable:!0,scaleable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}}}})},pointLayerLabelSpec:{id:`{prefix}-point-label`,type:`symbol`,source:`{prefix}-point`,filter:[`all`,[`==`,`$type`,`Point`],[`any`,[`==`,`mode`,`point`],[`==`,`mode`,`marker`]]],layout:{"text-field":[`case`,[`all`,[`has`,`elevation`],[`>`,[`get`,`elevation`],0]],[`concat`,`Alt. `,[`to-string`,[`floor`,[`get`,`elevation`]]],` `,[`get`,`elevationUnit`]],``],"symbol-placement":`point`,"text-size":[`interpolate`,[`linear`],[`zoom`],5,10,10,12,13,14,14,16,18,18],"text-overlap":`always`,"text-variable-anchor":[`left`,`right`,`top`,`bottom`],"text-radial-offset":.5,"text-justify":`center`,"text-letter-spacing":.05},paint:{"text-halo-color":`#F7F7F7`,"text-halo-width":2,"text-color":`#232E3D`}},lineLayerLabelSpec:{id:`{prefix}-line-label`,type:`symbol`,source:`{prefix}-line-source`,filter:[`==`,`$type`,`Point`],layout:{"text-field":[`concat`,[`to-string`,[`get`,`distance`]],` `,[`get`,`unit`],[`case`,[`==`,[`get`,`total`],0],``,[`concat`,`
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`maplibre-gl`),require(`@turf/bbox`),require(`@turf/nearest-point-on-line`)):typeof define==`function`&&define.amd?define([`exports`,`maplibre-gl`,`@turf/bbox`,`@turf/nearest-point-on-line`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.TeeeMapSDK={},e.maplibregl,e.turfBbox,e.turfNearestPointOnLine))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var i=Object.create,a=Object.defineProperty,o=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,c=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty,u=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=s(t),c=0,u=i.length,d;c<u;c++)d=i[c],!l.call(e,d)&&d!==n&&a(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=o(t,d))||r.enumerable});return e},d=(e,t,n)=>(n=e==null?{}:i(c(e)),u(t||!e||!e.__esModule?a(n,`default`,{value:e,enumerable:!0}):n,e));t=d(t,1),n=d(n,1);var f=async()=>{let e=document.createElement(`canvas`);e.width=25,e.height=17;let t=e.getContext(`2d`);if(!t)throw Error(`无法获取 Canvas 上下文`);t.rect(0,0,e.width,e.height),t.fillStyle=`rgba(0, 0, 0, 0)`,t.fill(),t.strokeStyle=`red`,t.lineWidth=3,t.stroke();let n=new Image;return n.src=e.toDataURL(),new Promise((e,t)=>{n.onload=()=>e(n),n.onerror=()=>t(Error(`Failed to load redBoxIcon image`))})},p=async()=>{let e=document.createElement(`canvas`);e.width=64,e.height=64;let t=e.getContext(`2d`);if(!t)throw Error(`无法获取 Canvas 上下文`);let n=e.width/2,r=e.height/2;t.beginPath(),t.arc(n,r,20,0,Math.PI*2),t.fillStyle=`rgba(0, 0, 0, 0)`,t.fill(),t.strokeStyle=`#ffffff`,t.lineWidth=3,t.setLineDash([6,6]),t.lineCap=`round`,t.lineJoin=`round`,t.stroke();let i=new Image;return i.src=e.toDataURL(),new Promise((e,t)=>{i.onload=()=>e(i),i.onerror=()=>t(Error(`Failed to load dashCircle image`))})},m=async(e=`h`,t=`r`,n=``,r=``)=>{let i=e===`h`,a=t===`r`,o=`transparent`,s=n||o,c=r||o,l=27*.5,u=3*1.75,d=i?27*1.25:27,f=12*1.2,p=3+(i?f:0)+54+u,m=d+l,h=document.createElement(`canvas`);h.width=p,h.height=m;let g=h.getContext(`2d`);if(!g)throw Error(`无法获取 Canvas 上下文`);g.clearRect(0,0,p,m),g.save(),a||(g.translate(p/2,m/2),g.scale(1,-1),g.translate(-p/2,-m/2)),g.strokeStyle=`rgb(255,255,255)`,g.fillStyle=`rgb(255,255,255)`,3/2-u/2+5;let _=m-l;g.beginPath(),g.rect(3.875,_,u,l),g.fill(),g.beginPath(),g.lineWidth=3;let v=6.5,ee=m-l-d,te=m-l;g.moveTo(v,ee),g.lineTo(v,te),g.stroke(),g.lineWidth=2;let y=ee+27/2,b=16+(i?f:0)+5,ne=b+27-1;if(g.beginPath(),g.strokeStyle=`rgb(255,255,255)`,g.lineWidth=2,g.fillStyle=s,g.arc(b,y,12,0,Math.PI*2),g.fill(),g.stroke(),g.beginPath(),g.strokeStyle=`rgb(255,255,255)`,g.lineWidth=2,g.fillStyle=c,g.arc(ne,y,12,0,Math.PI*2),g.fill(),g.stroke(),i){g.beginPath(),g.lineWidth=2,g.strokeStyle=`rgb(255,255,255)`,v+3/2;let e=b-12-2/2,t=y;g.moveTo(8,t),g.lineTo(e,t),g.stroke()}g.restore();let x=new Image;return x.src=h.toDataURL(),new Promise((e,t)=>{x.onload=()=>e(x),x.onerror=t})},h=async(e=`h`,t=`r`)=>{let n=e===`h`,r=t===`r`,i=12*1.2,a=27*.5,o=n?27*1.25:27,s=3+(n?i:0)+54+5.25+8,c=o+a+8,l=document.createElement(`canvas`);l.width=s,l.height=c;let u=l.getContext(`2d`);if(!u)throw Error(`无法获取 Canvas 上下文`);u.clearRect(0,0,s,c),u.save(),r||(u.translate(s/2,c/2),u.scale(1,-1),u.translate(-s/2,-c/2));let d=c-a-o-4+27/2,f=16+(n?i:0)+4+27,p=1.5,m=f+12+4*1.5,h=d-12,g=d+12+8;u.beginPath(),u.setLineDash([8,8]),u.strokeStyle=`#ffffff`,u.lineWidth=3,u.rect(p,h,m-p,g-h),u.stroke(),u.restore();let _=new Image;return _.src=l.toDataURL(),new Promise((e,t)=>{_.onload=()=>e(_),_.onerror=t})},g=async(e=`h`,t=`r`,n=!0)=>{let r=e===`h`,i=t===`r`,a=12*1.2,o=27*.5,s=r?27*1.25:27,c=3+(r?a:0)+54+5.25,l=s+o,u=document.createElement(`canvas`);u.width=c,u.height=l;let d=u.getContext(`2d`);if(!d)throw Error(`无法获取 Canvas 上下文`);d.clearRect(0,0,c,l),d.save(),i||(d.translate(c/2,l/2),d.scale(1,-1),d.translate(-c/2,-l/2));let f=l-o-s+27/2,p=16+(r?a:0)+5,m=p+27;d.lineWidth=4,d.strokeStyle=`#ff0000`,n&&(d.beginPath(),d.moveTo(p-12,f-12),d.lineTo(p+12,f+12),d.moveTo(p+12,f-12),d.lineTo(p-12,f+12),d.stroke()),n&&(d.beginPath(),d.moveTo(m-12,f-12),d.lineTo(m+12,f+12),d.moveTo(m+12,f-12),d.lineTo(m-12,f+12),d.stroke()),d.restore();let h=new Image;return h.src=u.toDataURL(),new Promise((e,t)=>{h.onload=()=>e(h),h.onerror=t})},_=async(e=`h`,t=`r`,n,r)=>{let i=e===`h`,a=t===`r`,o=12*1.2,s=27*.5,c=i?27*1.25:27,l=3+(i?o:0)+54+5.25,u=c+s,d=document.createElement(`canvas`);d.width=l,d.height=u;let f=d.getContext(`2d`);if(!f)throw Error(`无法获取 Canvas 上下文`);f.clearRect(0,0,l,u),f.save(),a||(f.translate(l/2,u/2),f.scale(1,-1),f.translate(-l/2,-u/2));let p=u-s-c+27/2,m=16+(i?o:0)+27+5;f.save(),f.translate(m,p),f.fillStyle=n;let h=r?12:24;f.fillRect(-12,-12,h,24),r&&(f.fillStyle=r,f.fillRect(0,-12,12,24)),f.strokeStyle=`white`,f.lineWidth=2,f.strokeRect(-12,-12,24,24),f.restore(),f.restore();let g=new Image;return g.src=d.toDataURL(),new Promise((e,t)=>{g.onload=()=>e(g),g.onerror=t})},v=`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='1776081402940'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='9172'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='32'%20height='32'%3e%3cpath%20d='M675.84%20409.6v-102.4a163.84%20163.84%200%201%200-327.68%200v102.4h327.68z%20m-409.6%200v-102.4c0-135.72096%20110.03904-245.76%20245.76-245.76s245.76%20110.03904%20245.76%20245.76v102.4a81.92%2081.92%200%200%201%2081.92%2081.92v225.28c0%20135.72096-110.03904%20245.76-245.76%20245.76h-163.84c-135.72096%200-245.76-110.03904-245.76-245.76V491.52a81.92%2081.92%200%200%201%2081.92-81.92z%20m286.72%20348.16v-51.87584a40.96%2040.96%200%200%201%2014.19264-30.98624%2081.92%2081.92%200%201%200-113.07008-2.56c0.79872%200.79872%201.72032%201.6384%202.7648%202.56A40.96%2040.96%200%200%201%20471.04%20705.88416V757.76a40.96%2040.96%200%201%200%2081.92%200z'%20p-id='9173'%20fill='%23ffffff'%3e%3c/path%3e%3c/svg%3e`,ee=`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='1781252097660'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='13038'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='32'%20height='32'%3e%3cpath%20d='M725.333333%2085.333333a128%20128%200%200%201%20127.786667%20120.490667L853.333333%20213.333333v597.333334a128%20128%200%200%201-120.490666%20127.786666L725.333333%20938.666667h-75.904a32.170667%2032.170667%200%200%200-2.645333-5.674667l-158.464-309.333333-1.706667-2.432%2034.816-121.770667%200.298667-1.408%2013.568%2037.632%202.858667%206.826667c7.253333%2015.573333%2019.456%2028.458667%2034.730666%2036.565333l84.053334%2044.672%203.925333%201.792a32%2032%200%200%200%2026.112-58.282667l-84.053333-44.672-2.389334-1.621333a15.786667%2015.786667%200%200%201-5.034666-6.954667l-23.168-64.384-2.56-6.229333a78.762667%2078.762667%200%200%200-54.613334-43.946667l-3.285333-0.768-7.765333-1.28a80%2080%200%200%200-58.282667%2016.042667L360.96%20478.805333l-5.205333%204.352a79.786667%2079.786667%200%200%200-21.76%2033.450667l-33.792%20100.693333-1.109334%204.266667a32%2032%200%200%200%2061.781334%2016.128l33.792-100.693333%201.28-2.858667a15.786667%2015.786667%200%200%201%204.053333-4.693333l59.306667-45.653334-40.277334%20140.928-1.706666%207.253334c-0.896%204.864-1.365333%209.813333-1.365334%2014.762666v122.666667l-0.298666%203.114667a16%2016%200%200%201-4.394667%208.192l-103.253333%20145.493333-3.072%203.584a31.786667%2031.786667%200%200%200-4.693334%208.874667H298.666667a128%20128%200%200%201-127.786667-120.490667L170.666667%20810.666667V213.333333a128%20128%200%200%201%20120.490666-127.786666L298.666667%2085.333333h426.666666z%20m-245.333333%20662.101334L577.877333%20938.666667h-201.386666l79.914666-112.597334%204.778667-5.205333c12.074667-14.336%2018.773333-32.554667%2018.773333-51.456v-21.973333zM549.546667%20230.656a74.666667%2074.666667%200%201%200%200%20149.333333%2074.666667%2074.666667%200%200%200%200-149.333333z'%20fill='%2336a83e'%20p-id='13039'%3e%3c/path%3e%3c/svg%3e`,te=`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='1781252097660'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='13038'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='32'%20height='32'%3e%3cpath%20d='M725.333333%2085.333333a128%20128%200%200%201%20127.786667%20120.490667L853.333333%20213.333333v597.333334a128%20128%200%200%201-120.490666%20127.786666L725.333333%20938.666667h-75.904a32.170667%2032.170667%200%200%200-2.645333-5.674667l-158.464-309.333333-1.706667-2.432%2034.816-121.770667%200.298667-1.408%2013.568%2037.632%202.858667%206.826667c7.253333%2015.573333%2019.456%2028.458667%2034.730666%2036.565333l84.053334%2044.672%203.925333%201.792a32%2032%200%200%200%2026.112-58.282667l-84.053333-44.672-2.389334-1.621333a15.786667%2015.786667%200%200%201-5.034666-6.954667l-23.168-64.384-2.56-6.229333a78.762667%2078.762667%200%200%200-54.613334-43.946667l-3.285333-0.768-7.765333-1.28a80%2080%200%200%200-58.282667%2016.042667L360.96%20478.805333l-5.205333%204.352a79.786667%2079.786667%200%200%200-21.76%2033.450667l-33.792%20100.693333-1.109334%204.266667a32%2032%200%200%200%2061.781334%2016.128l33.792-100.693333%201.28-2.858667a15.786667%2015.786667%200%200%201%204.053333-4.693333l59.306667-45.653334-40.277334%20140.928-1.706666%207.253334c-0.896%204.864-1.365333%209.813333-1.365334%2014.762666v122.666667l-0.298666%203.114667a16%2016%200%200%201-4.394667%208.192l-103.253333%20145.493333-3.072%203.584a31.786667%2031.786667%200%200%200-4.693334%208.874667H298.666667a128%20128%200%200%201-127.786667-120.490667L170.666667%20810.666667V213.333333a128%20128%200%200%201%20120.490666-127.786666L298.666667%2085.333333h426.666666z%20m-245.333333%20662.101334L577.877333%20938.666667h-201.386666l79.914666-112.597334%204.778667-5.205333c12.074667-14.336%2018.773333-32.554667%2018.773333-51.456v-21.973333zM549.546667%20230.656a74.666667%2074.666667%200%201%200%200%20149.333333%2074.666667%2074.666667%200%200%200%200-149.333333z'%20fill='%23b92511'%20p-id='13039'%3e%3c/path%3e%3c/svg%3e`,y=`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='1781416346105'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='55023'%20width='32'%20height='32'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3cpath%20d='M725.333333%2085.333333a128%20128%200%200%201%20127.786667%20120.490667L853.333333%20213.333333v597.333334a128%20128%200%200%201-120.490666%20127.786666L725.333333%20938.666667h-75.904a32.170667%2032.170667%200%200%200-2.645333-5.674667l-158.464-309.333333-1.706667-2.432%2034.816-121.770667%200.298667-1.408%2013.568%2037.632%202.858667%206.826667c7.253333%2015.573333%2019.456%2028.458667%2034.730666%2036.565333l84.053334%2044.672%203.925333%201.792a32%2032%200%200%200%2026.112-58.282667l-84.053333-44.672-2.389334-1.621333a15.786667%2015.786667%200%200%201-5.034666-6.954667l-23.168-64.384-2.56-6.229333a78.762667%2078.762667%200%200%200-54.613334-43.946667l-3.285333-0.768-7.765333-1.28a80%2080%200%200%200-58.282667%2016.042667L360.96%20478.805333l-5.205333%204.352a79.786667%2079.786667%200%200%200-21.76%2033.450667l-33.792%20100.693333-1.109334%204.266667a32%2032%200%200%200%2061.781334%2016.128l33.792-100.693333%201.28-2.858667a15.786667%2015.786667%200%200%201%204.053333-4.693333l59.306667-45.653334-40.277334%20140.928-1.706666%207.253334c-0.896%204.864-1.365333%209.813333-1.365334%2014.762666v122.666667l-0.298666%203.114667a16%2016%200%200%201-4.394667%208.192l-103.253333%20145.493333-3.072%203.584a31.786667%2031.786667%200%200%200-4.693334%208.874667H298.666667a128%20128%200%200%201-127.786667-120.490667L170.666667%20810.666667V213.333333a128%20128%200%200%201%20120.490666-127.786666L298.666667%2085.333333h426.666666z%20m-245.333333%20662.101334L577.877333%20938.666667h-201.386666l79.914666-112.597334%204.778667-5.205333c12.074667-14.336%2018.773333-32.554667%2018.773333-51.456v-21.973333zM549.546667%20230.656a74.666667%2074.666667%200%201%200%200%20149.333333%2074.666667%2074.666667%200%200%200%200-149.333333z'%20fill='%23bfbfbf'%20p-id='55024'%3e%3c/path%3e%3c/svg%3e`,b={BASE_COLOR:`rgb(85,120,182)`,BG_COLOR:`rgb(0,0,0)`},ne=(e,t,n)=>{let r=document.createElement(`canvas`);r.width=66,r.height=64;let i=r.getContext(`2d`);return i?(i.clearRect(0,0,r.width,r.height),n===2&&(i.translate(66,0),i.scale(-1,1)),e===1?(i.beginPath(),i.arc(46,20,20-4/2,0,Math.PI*2),i.fillStyle=t||`rgb(255,255,255,0)`,i.strokeStyle=t||b.BASE_COLOR,i.lineWidth=4,i.fill(),i.stroke(),i.beginPath(),i.moveTo(6,40/2),i.lineTo(26,40/2),i.lineWidth=4,i.strokeStyle=b.BASE_COLOR,i.stroke(),i.beginPath(),i.lineCap=`round`,i.moveTo(8/2,0),i.lineTo(8/2,40),i.lineWidth=4,i.strokeStyle=b.BASE_COLOR,i.stroke(),i.beginPath(),i.moveTo(8/2,40),i.lineTo(8/2,64),i.lineWidth=8,i.strokeStyle=b.BASE_COLOR,i.stroke(),r):(i.beginPath(),i.arc(26,20,20-4/2,0,Math.PI*2),i.fillStyle=t||`rgb(255,255,255,0)`,i.strokeStyle=t||b.BASE_COLOR,i.lineWidth=4,i.fill(),i.stroke(),i.beginPath(),i.lineCap=`round`,i.moveTo(8/2,0),i.lineTo(8/2,40),i.lineWidth=4,i.strokeStyle=b.BASE_COLOR,i.stroke(),i.beginPath(),i.moveTo(8/2,40),i.lineTo(8/2,64),i.lineWidth=8,i.strokeStyle=b.BASE_COLOR,i.stroke(),r)):r},x=()=>{let e=document.createElement(`canvas`);e.width=24,e.height=64;let t=e.getContext(`2d`);return t?(t.fillStyle=b.BG_COLOR,t.fillRect(0,0,24,64),t.strokeStyle=b.BASE_COLOR,t.lineWidth=8,t.strokeRect(0,0,24,64),e):e},S=()=>{let e=document.createElement(`canvas`);e.width=15,e.height=40;let t=e.getContext(`2d`);return t?(t.clearRect(0,0,e.width,e.height),t.beginPath(),t.moveTo(0,4/2),t.lineTo(15-4/2,4/2),t.moveTo(4/2,4/2),t.lineTo(4/2,36),t.moveTo(0,36),t.lineTo(15-4/2,36),t.lineWidth=4,t.strokeStyle=b.BASE_COLOR,t.stroke(),e):e},re=async(e=`h`,t=`r`,n=``)=>{let r=ne(e==`h`?1:2,n,t==`l`?1:2),i=new Image;return i.src=r.toDataURL(),new Promise((e,t)=>{i.onload=()=>e(i),i.onerror=t})},ie=async()=>{let e=x(),t=new Image;return t.src=e.toDataURL(),new Promise((e,n)=>{t.onload=()=>e(t),t.onerror=n})},ae=async()=>{let e=S(),t=new Image;return t.src=e.toDataURL(),new Promise((e,n)=>{t.onload=()=>e(t),t.onerror=n})},C=function(e){return e.Blue=`blue`,e.Green=`green`,e.Red=`red`,e.Yellow=`yellow`,e.Gray=`gray`,e.Purple=`purple`,e.Red_Purple=`red-purple`,e}({}),w=function(e){return e.Red=`red`,e.Red_Yellow=`red-yellow`,e.Yellow=`yellow`,e.Yellow_Yellow=`yellow-yellow`,e.Yellow_Green=`yellow-green`,e.Green=`green`,e.Blue=`blue`,e.White=`white`,e}({}),oe=async()=>{let[e,t,n,r]=await Promise.all([re(`h`,`r`,``),re(`h`,`l`,``),re(`l`,`r`,``),re(`l`,`l`,``)]),i=new Image;i.src=v;let a=new Image;a.src=te;let o=new Image;o.src=ee;let s=new Image;s.src=y;let[c,l,u]=await Promise.all([ae(),f(),p()]),[d,b,ne,x]=await Promise.all([m(`h`,`r`,``),m(`h`,`l`,``),m(`l`,`r`,``),m(`l`,`l`,``)]),[S,oe,T,se]=await Promise.all([h(`h`,`r`),h(`h`,`l`),h(`l`,`r`),h(`l`,`l`)]),[ce,le,ue,de]=await Promise.all([g(`h`,`r`),g(`h`,`l`),g(`l`,`r`),g(`l`,`l`)]),fe=[`h`,`l`],pe=[`r`,`l`],me=[C.Blue,C.Green,C.Red,C.Yellow,C.Gray,C.Purple,C.Red_Purple],he=fe.flatMap(e=>pe.flatMap(t=>me.map(n=>({height:e,dir:t,color:n})))),ge=await Promise.all(he.map(({height:e,dir:t,color:n})=>_(e,t,n===C.Red_Purple?`red`:n,n===C.Red_Purple?`purple`:void 0))),_e=[w.Red,w.Red_Yellow,w.Yellow,w.Yellow_Yellow,w.Yellow_Green,w.Green,w.Blue,w.White],E=fe.flatMap(e=>pe.flatMap(t=>_e.map(n=>({height:e,dir:t,color:n})))),ve=await Promise.all(E.map(({height:e,dir:t,color:n})=>{let r=n,i;return n===w.Red_Yellow?(r=`red`,i=`yellow`):n===w.Yellow_Yellow?(r=`yellow`,i=`yellow`):n===w.Yellow_Green&&(r=`yellow`,i=`green`),m(e,t,r,i)})),ye=[w.Red,w.Green,w.White,w.Blue],be=fe.flatMap(e=>pe.flatMap(t=>ye.map(n=>({height:e,dir:t,color:n})))),xe=await Promise.all(be.map(({height:e,dir:t,color:n})=>re(e,t,n))),Se=await ie();return[{id:`icon-door-open`,image:o},{id:`icon-door-close`,image:a},{id:`icon-door-none`,image:s},{id:`icon-signal-h-r`,image:e},{id:`icon-signal-h-l`,image:t},{id:`icon-signal-l-r`,image:n},{id:`icon-signal-l-l`,image:r},{id:`icon-lock`,image:i},{id:`icon-bumper`,image:c},{id:`icon-red-box`,image:l},{id:`icon-dash-circle`,image:u},{id:`icon-ctc-signal-h-r`,image:d},{id:`icon-ctc-signal-h-l`,image:b},{id:`icon-ctc-signal-l-r`,image:ne},{id:`icon-ctc-signal-l-l`,image:x},{id:`icon-ctc-box-h-r`,image:S},{id:`icon-ctc-box-h-l`,image:oe},{id:`icon-ctc-box-l-r`,image:T},{id:`icon-ctc-box-l-l`,image:se},{id:`icon-ctc-x-h-r`,image:ce},{id:`icon-ctc-x-h-l`,image:le},{id:`icon-ctc-x-l-r`,image:ue},{id:`icon-ctc-x-l-l`,image:de},{id:`icon-jcw`,image:Se},...ge.map((e,t)=>{let n=he[t];return{id:`icon-ctc-s-${n.height}-${n.dir}-${n.color}`,image:e}}),...ve.map((e,t)=>{let n=E[t];return{id:`icon-ctc-signal-${n.height}-${n.dir}-${n.color}`,image:e}}),...xe.map((e,t)=>{let n=be[t];return{id:`icon-signal-${n.height}-${n.dir}-${n.color}`,image:e}})]},T={geojson:e=>({type:`geojson`,data:e||{type:`FeatureCollection`,features:[]},promoteId:`code`}),raster:e=>({type:`raster`,tiles:[e],scheme:`tms`,tileSize:256}),graph:e=>({type:`vector`,tiles:[e],scheme:`tms`,promoteId:`code`}),geom:e=>({type:`vector`,tiles:[e],scheme:`tms`,promoteId:`code`}),image:(e,t)=>({type:`image`,url:e,coordinates:t}),video:(e,t)=>({type:`video`,urls:e,coordinates:t}),canvas:(e,t)=>({type:`canvas`,canvas:e,coordinates:t}),mbtiles:e=>({type:`vector`,tiles:[e]})},se={background:(e,t)=>({id:`${e.id}_${t}`,type:`background`,paint:{"background-color":`#131212`}}),track:(e,t)=>[{id:`${e.id}_${t}_lock`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`#a7009e`,"line-width":3,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`1`],1,0]}},{id:`${e.id}_${t}_lock_icon`,type:`symbol`,source:e.id,"source-layer":t,layout:{"symbol-placement":`line-center`,"icon-anchor":`top`,"icon-image":`icon-lock`,"icon-size":[`interpolate`,[`exponential`,2],[`zoom`],12,.2,15,.5,16,.6,17,.8],"icon-offset":[0,5],"icon-allow-overlap":!0,"icon-rotation-alignment":`viewport`,"icon-rotate":0},paint:{"icon-opacity":[`case`,[`==`,[`feature-state`,`state`],`1`],1,0]}},{id:`${e.id}_${t}_poweroff_border`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`green`,"line-width":9,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e.id}_${t}_poweroff_fill`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`black`,"line-width":6,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e.id}_${t}_catenery_border`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`grey`,"line-width":9,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`3`],1,0]}},{id:`${e.id}_${t}_catenery_fill`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`black`,"line-width":6,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`3`],1,0]}},{id:`${e.id}_${t}_select_border`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`#ffffff`,"line-dasharray":[.5,.5],"line-width":9,"line-opacity":[`case`,[`==`,[`feature-state`,`select`],!0],1,0]}},{id:`${e.id}_${t}_hitarea`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`black`,"line-width":6,"line-opacity":[`case`,[`==`,[`feature-state`,`select`],!0],1,0]}},{id:`${e.id}_${t}`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`#85A0D9`,"line-width":2}}],track_circuit:(e,t)=>[{id:`${e.id}_${t}_poweroff_border`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`green`,"line-width":9,"line-opacity":[`case`,[`==`,[`feature-state`,`subState1`],`1`],1,0]}},{id:`${e.id}_${t}_poweroff_fill`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`black`,"line-width":6,"line-opacity":[`case`,[`==`,[`feature-state`,`subState1`],`1`],1,0]}},{id:`${e.id}_${t}_select_border`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`#ffffff`,"line-dasharray":[.4,.4],"line-width":9,"line-opacity":[`case`,[`==`,[`feature-state`,`select`],!0],1,0]}},{id:`${e.id}_${t}_hitarea`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`black`,"line-width":6,"line-opacity":[`case`,[`==`,[`feature-state`,`select`],!0],1,0]}},{id:`${e.id}_${t}`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`grey`,"line-width":3}},{id:`${e.id}_${t}_red`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`red`,"line-width":3,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`1`],1,0]}},{id:`${e.id}_${t}_white`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`white`,"line-width":3,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e.id}_${t}_grey`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`,visibility:`none`},paint:{"line-color":`grey`,"line-width":3,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`3`],1,0]}},{id:`${e.id}_${t}_subpath`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`burlywood`,"line-width":3,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`4`],1,0]}},{id:`${e.id}_${t}_mainpath`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`white`,"line-width":3,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`5`],1,0]}},{id:`${e.id}_${t}_cable_hover`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`red`,"line-width":3,"line-opacity":[`case`,[`==`,[`feature-state`,`subState1`],`1`],1,0]}},{id:`${e.id}_${t}_cable`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`red`,"line-width":3,"line-opacity":[`case`,[`==`,[`feature-state`,`subState2`],`1`],1,0]}}],signal:(e,t)=>{let n=[`interpolate`,[`exponential`,2],[`zoom`],12,.2,16,.6,18,.8,20,1.5],r=[];[C.Blue,C.Green,C.Red,C.Yellow,C.Gray,C.Purple,C.Red_Purple].forEach(i=>{r.push({id:`${e.id}_${t}_square_${i}`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":[`case`,[`==`,[`get`,`inst_type`],1],[`case`,[`==`,[`get`,`posi_side`],1],`icon-ctc-s-h-r-${i}`,`icon-ctc-s-h-l-${i}`],[`case`,[`==`,[`get`,`posi_side`],1],`icon-ctc-s-l-r-${i}`,`icon-ctc-s-l-l-${i}`]],"icon-size":n,"icon-rotate":[`+`,[`to-number`,[`get`,`angle`]],90],"icon-allow-overlap":!0,"icon-anchor":[`case`,[`==`,[`get`,`posi_side`],1],`bottom-right`,`top-right`]},paint:{"icon-opacity":[`case`,[`all`,[`==`,[`feature-state`,`subState1`],i],[`!=`,[`feature-state`,`visiable`],!1]],1,0]}})});let i=[];return[w.Red,w.Red_Yellow,w.Yellow,w.Yellow_Yellow,w.Yellow_Green,w.Green,w.Blue,w.White].forEach(r=>{i.push({id:`${e.id}_${t}_${r}`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":[`case`,[`==`,[`get`,`inst_type`],1],[`case`,[`==`,[`get`,`posi_side`],1],`icon-ctc-signal-h-r-${r}`,`icon-ctc-signal-h-l-${r}`],[`case`,[`==`,[`get`,`posi_side`],1],`icon-ctc-signal-l-r-${r}`,`icon-ctc-signal-l-l-${r}`]],"icon-size":n,"icon-rotate":[`+`,[`to-number`,[`get`,`angle`]],90],"icon-allow-overlap":!0,"icon-anchor":[`case`,[`==`,[`get`,`posi_side`],1],`bottom-left`,`top-left`]},paint:{"icon-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],r],[`!=`,[`feature-state`,`visiable`],!1]],1,0]}})}),[...i,{id:`${e.id}_${t}`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":[`case`,[`==`,[`get`,`inst_type`],1],[`case`,[`==`,[`get`,`posi_side`],1],`icon-ctc-signal-h-r`,`icon-ctc-signal-h-l`],[`case`,[`==`,[`get`,`posi_side`],1],`icon-ctc-signal-l-r`,`icon-ctc-signal-l-l`]],"icon-size":n,"icon-rotate":[`+`,[`to-number`,[`get`,`angle`]],90],"icon-allow-overlap":!0,"icon-anchor":[`case`,[`==`,[`get`,`posi_side`],1],`bottom-left`,`top-left`]},paint:{"icon-opacity":[`case`,[`!=`,[`feature-state`,`visiable`],!1],1,0]}},{id:`${e.id}_${t}_box`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":[`case`,[`==`,[`get`,`inst_type`],1],[`case`,[`==`,[`get`,`posi_side`],1],`icon-ctc-box-h-r`,`icon-ctc-box-h-l`],[`case`,[`==`,[`get`,`posi_side`],1],`icon-ctc-box-l-r`,`icon-ctc-box-l-l`]],"icon-size":n,"icon-rotate":[`+`,[`to-number`,[`get`,`angle`]],90],"icon-allow-overlap":!0,"icon-anchor":[`case`,[`==`,[`get`,`posi_side`],1],`bottom-left`,`top-left`]},paint:{"icon-opacity":[`case`,[`all`,[`==`,[`feature-state`,`select`],!0],[`!=`,[`feature-state`,`visiable`],!1]],1,0]}},{id:`${e.id}_${t}_x`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":[`case`,[`==`,[`get`,`inst_type`],1],[`case`,[`==`,[`get`,`posi_side`],1],`icon-ctc-x-h-r`,`icon-ctc-x-h-l`],[`case`,[`==`,[`get`,`posi_side`],1],`icon-ctc-x-l-r`,`icon-ctc-x-l-l`]],"icon-size":n,"icon-rotate":[`+`,[`to-number`,[`get`,`angle`]],90],"icon-allow-overlap":!0,"icon-anchor":[`case`,[`==`,[`get`,`posi_side`],1],`bottom-left`,`top-left`]},paint:{"icon-opacity":[`case`,[`all`,[`==`,[`feature-state`,`subState2`],`off`],[`!=`,[`feature-state`,`visiable`],!1]],1,0]}},...r]},bumper:(e,t)=>({id:`${e.id}_${t}`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":`icon-bumper`,"icon-size":.3,"icon-allow-overlap":!0},paint:{"icon-opacity":0}}),switch:(e,t)=>[{id:`${e.id}_${t}_hitarea`,type:`circle`,source:e.id,"source-layer":t,paint:{"circle-radius":[`interpolate`,[`linear`],[`zoom`],5,11],"circle-color":`red`,"circle-opacity":0}},{id:`${e.id}_${t}_dash_circle`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":`icon-dash-circle`,"icon-allow-overlap":!0,"icon-size":[`interpolate`,[`linear`],[`zoom`],17,.5]},paint:{"icon-opacity":[`case`,[`==`,[`feature-state`,`select`],!0],1,0]}},{id:`${e.id}_${t}_text`,type:`symbol`,source:e.id,"source-layer":t,layout:{"text-field":[`get`,`name`],"text-size":[`interpolate`,[`linear`],[`zoom`],15,11,22,15],"text-font":[`Open Sans Regular`],"text-anchor":`top`,"text-offset":[0,.5],"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":[`match`,[`feature-state`,`state`],`2`,`lightgreen`,`3`,`yellow`,`4`,`red`,`white`]}},{id:`${e.id}_${t}_lock`,type:`circle`,source:e.id,"source-layer":t,layout:{visibility:`visible`},paint:{"circle-radius":[`interpolate`,[`linear`],[`zoom`],5,8],"circle-stroke-width":1.7,"circle-stroke-color":[`match`,[`feature-state`,`state`],`2`,`green`,`3`,`yellow`,`4`,`red`,`white`],"circle-color":`transparent`,"circle-stroke-opacity":[`case`,[`==`,[`feature-state`,`subState2`],`1`],1,0]}},{id:`${e.id}_${t}_danfen`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":`icon-red-box`,"icon-allow-overlap":!0,"icon-offset":[0,15],"icon-size":[`interpolate`,[`linear`],[`zoom`],5,.2,10,.5,18,1]},paint:{"icon-opacity":[`case`,[`==`,[`feature-state`,`subState3`],`1`],1,0]}}],switch_loc:(e,t)=>[{id:`${e.id}_${t}`,type:`line`,source:e.id,"source-layer":t,paint:{"line-width":5,"line-color":`#000000`}},{id:`${e.id}_${t}_normal`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`2`]],paint:{"line-width":4,"line-color":`green`,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e.id}_${t}_reverse`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`3`]],paint:{"line-width":4,"line-color":`yellow`,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`3`],1,0]}},{id:`${e.id}_${t}_fourway`,type:`line`,source:e.id,"source-layer":t,paint:{"line-width":4,"line-color":`#000000`,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`4`],1,0]}},{id:`${e.id}_${t}_normal_white`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`2`]],paint:{"line-width":4,"line-color":`white`,"line-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],`2`],[`==`,[`feature-state`,`subState1`],`2`]],1,0]}},{id:`${e.id}_${t}_reverse_white`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`3`]],paint:{"line-width":4,"line-color":`white`,"line-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],`3`],[`==`,[`feature-state`,`subState1`],`2`]],1,0]}},{id:`${e.id}_${t}_normal_red`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`2`]],paint:{"line-width":4,"line-color":`red`,"line-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],`2`],[`==`,[`feature-state`,`subState1`],`3`]],1,0]}},{id:`${e.id}_${t}_reverse_red`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`3`]],paint:{"line-width":4,"line-color":`red`,"line-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],`3`],[`==`,[`feature-state`,`subState1`],`3`]],1,0]}}],insulation:(e,t)=>{let n=[`interpolate`,[`exponential`,2],[`zoom`],12,1,15,1.5,16,2,17,4];return{id:`${e.id}_${t}`,type:`circle`,source:e.id,"source-layer":t,filter:[`!=`,[`get`,`category`],2],paint:{"circle-radius":n,"circle-stroke-width":n,"circle-stroke-color":`#ffbb00`},layout:{visibility:`none`}}},label:(e,t)=>({id:`${e.id}_${t}`,type:`symbol`,source:e.id,"source-layer":t,filter:[`!=`,[`get`,`category`],2],layout:{"text-field":[`get`,`name`],"text-size":[`interpolate`,[`linear`],[`zoom`],15,[`case`,[`==`,[`get`,`category`],50],10,[`==`,[`get`,`category`],96],8,7],22,[`case`,[`==`,[`get`,`category`],50],16,[`==`,[`get`,`category`],96],12,13]],"text-font":[`Open Sans Regular`],"text-anchor":[`case`,[`==`,[`get`,`angle`],90],`bottom-left`,`top-right`],"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":`#C0C33F`}}),prevention:(e,t)=>[{id:`${e.id}_${t}_circle`,type:`circle`,source:e.id,"source-layer":t,filter:[`match`,[`to-string`,[`get`,`uc_oob_type`]],[`2`,`8`,`20`,`87`],!0,!1],paint:{"circle-radius":[`interpolate`,[`exponential`,2],[`zoom`],10,3,20,10],"circle-stroke-width":2,"circle-stroke-color":`red`},layout:{visibility:`none`}},{id:`${e.id}_${t}_text`,type:`symbol`,source:e.id,"source-layer":t,filter:[`match`,[`to-string`,[`get`,`uc_oob_type`]],[`2`,`8`,`20`,`87`],!0,!1],layout:{"text-field":[`case`,[`==`,[`to-string`,[`get`,`uc_oob_type`]],`2`],`网`,[`==`,[`to-string`,[`get`,`uc_oob_type`]],`8`],`停`,[`==`,[`to-string`,[`get`,`uc_oob_type`]],`20`],`界`,`门`],"text-font":[`Open Sans Regular`],"text-size":[`interpolate`,[`linear`],[`zoom`],10,2,20,12],"text-anchor":`center`,"symbol-placement":`point`,"text-allow-overlap":!0,visibility:`none`},paint:{"text-color":`white`}}],sgfhqy:(e,t)=>{let n=[`interpolate`,[`exponential`,2],[`zoom`],12,.2,14,.8,16,1.4,18,1.8];return[{id:`${e.id}_${t}_fill`,type:`fill`,source:e.id,"source-layer":t,filter:[`==`,[`geometry-type`],`Polygon`],layout:{visibility:`visible`},paint:{"fill-color":`#9ccc8ac0`,"fill-opacity":.4}},{id:`${e.id}_${t}_fill_hitarea`,type:`fill`,source:e.id,"source-layer":t,filter:[`==`,[`geometry-type`],`Polygon`],layout:{visibility:`visible`},paint:{"fill-color":`#8bc34a`,"fill-opacity":[`case`,[`all`,[`==`,[`feature-state`,`select`],!0],[`!=`,[`feature-state`,`visiable`],!1]],.7,0]}},{id:`${e.id}_${t}_fill_selected`,type:`fill`,source:e.id,"source-layer":t,filter:[`==`,[`geometry-type`],`Polygon`],layout:{visibility:`visible`},paint:{"fill-color":`#8bc34a`,"fill-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],`1`],[`!=`,[`feature-state`,`visiable`],!1]],.7,0]}},{id:`${e.id}_${t}_fill_outline`,type:`line`,source:e.id,"source-layer":t,filter:[`==`,[`geometry-type`],`Polygon`],layout:{visibility:`visible`},paint:{"line-color":`#131212`,"line-width":[`interpolate`,[`linear`],[`zoom`],14,1,15,3,16,8]}},{id:`${e.id}_${t}_fill_selected_label`,type:`symbol`,source:e.id,"source-layer":t,filter:[`==`,[`geometry-type`],`Polygon`],layout:{visibility:`visible`,"text-field":[`get`,`name`],"text-size":14,"text-allow-overlap":!0,"text-offset":[.6,.6]},paint:{"text-color":`#1b5e20`,"text-halo-color":`#ffffff`,"text-halo-width":2,"text-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],`1`],[`!=`,[`feature-state`,`visiable`],!1]],1,0]}},{id:`${e.id}_${t}_line`,type:`line`,source:e.id,"source-layer":t,filter:[`==`,[`geometry-type`],`LineString`],layout:{visibility:`visible`},paint:{"line-color":`#00ff00`,"line-width":2,"line-dasharray":[4,2]}},{id:`${e.id}_${t}_door_dot`,type:`circle`,source:e.id,"source-layer":t,filter:[`==`,[`geometry-type`],`Point`],layout:{visibility:`visible`},paint:{"circle-radius":4,"circle-color":`#999999`,"circle-stroke-width":1.5,"circle-stroke-color":`#fff`}},{id:`${e.id}_${t}_door_dot_open`,type:`circle`,source:e.id,"source-layer":t,filter:[`==`,[`geometry-type`],`Point`],layout:{visibility:`visible`},paint:{"circle-radius":4,"circle-color":`#00ff00`,"circle-stroke-width":1.5,"circle-stroke-color":`#fff`,"circle-opacity":[`case`,[`any`,[`==`,[`feature-state`,`state`],`1`],[`==`,[`feature-state`,`state`],`3`]],1,0]}},{id:`${e.id}_${t}_door_dot_close`,type:`circle`,source:e.id,"source-layer":t,filter:[`==`,[`geometry-type`],`Point`],layout:{visibility:`visible`},paint:{"circle-radius":4,"circle-color":`#ff0000`,"circle-stroke-width":1.5,"circle-stroke-color":`#fff`,"circle-opacity":[`case`,[`any`,[`==`,[`feature-state`,`state`],`2`],[`==`,[`feature-state`,`state`],`4`]],1,0]}},{id:`${e.id}_${t}_door`,type:`symbol`,source:e.id,"source-layer":t,filter:[`==`,[`geometry-type`],`Point`],layout:{visibility:`visible`,"icon-image":`icon-door-none`,"icon-size":n,"icon-allow-overlap":!0,"icon-anchor":`top`,"text-field":[`get`,`name`],"text-anchor":`top-left`,"text-offset":[1.5,1],"text-size":13,"text-allow-overlap":!0},paint:{"text-color":`#999999`}},{id:`${e.id}_${t}_door_open`,type:`symbol`,source:e.id,"source-layer":t,filter:[`==`,[`geometry-type`],`Point`],layout:{visibility:`visible`,"icon-image":`icon-door-open`,"icon-size":n,"icon-allow-overlap":!0,"icon-anchor":`top`,"text-field":[`get`,`name`],"text-anchor":`top-left`,"text-offset":[1.5,1],"text-size":13,"text-allow-overlap":!0},paint:{"text-color":`#00ff00`,"icon-opacity":[`case`,[`any`,[`==`,[`feature-state`,`state`],`1`],[`==`,[`feature-state`,`state`],`3`]],1,0],"text-opacity":[`case`,[`any`,[`==`,[`feature-state`,`state`],`1`],[`==`,[`feature-state`,`state`],`3`]],1,0]}},{id:`${e.id}_${t}_door_close`,type:`symbol`,source:e.id,"source-layer":t,filter:[`==`,[`geometry-type`],`Point`],layout:{visibility:`visible`,"icon-image":`icon-door-close`,"icon-size":n,"icon-allow-overlap":!0,"icon-anchor":`top`,"text-field":[`get`,`name`],"text-anchor":`top-left`,"text-offset":[1.5,1],"text-size":13,"text-allow-overlap":!0},paint:{"text-color":`#ff0000`,"icon-opacity":[`case`,[`any`,[`==`,[`feature-state`,`state`],`2`],[`==`,[`feature-state`,`state`],`4`]],1,0],"text-opacity":[`case`,[`any`,[`==`,[`feature-state`,`state`],`2`],[`==`,[`feature-state`,`state`],`4`]],1,0]}}]}},ce=e=>{let t=[];return e.layers.forEach((n,r)=>{let i=se[n],a=e.sourceLayers[r];if(i){let n=i(e,a);Array.isArray(n)?t.push(...n):t.push(n)}else console.warn(`图层 ${n} 尚未实现`)}),t},le=(e,t)=>({id:`${e.id}_${t}`,type:`background`,paint:{"background-color":`#131212`}}),ue=(e,t)=>[{id:`${e.id}_${t}_lock`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`#a7009e`,"line-width":3,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`1`],1,0]}},{id:`${e.id}_${t}_lock_icon`,type:`symbol`,source:e.id,"source-layer":t,layout:{"symbol-placement":`line-center`,"icon-anchor":`top`,"icon-image":`icon-lock`,"icon-size":[`interpolate`,[`exponential`,2],[`zoom`],12,.2,15,.5,16,.6,17,.8],"icon-offset":[0,5],"icon-allow-overlap":!0,"icon-rotation-alignment":`viewport`,"icon-rotate":0},paint:{"icon-opacity":[`case`,[`==`,[`feature-state`,`state`],`1`],1,0]}},{id:`${e.id}_${t}_poweroff_border`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`green`,"line-width":9,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e.id}_${t}_poweroff_fill`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`black`,"line-width":6,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e.id}_${t}_catenery_border`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`grey`,"line-width":9,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`3`],1,0]}},{id:`${e.id}_${t}_catenery_fill`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`black`,"line-width":6,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`3`],1,0]}},{id:`${e.id}_${t}`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`#85A0D9`,"line-width":2}}],de=(e,t)=>{let n=[`interpolate`,[`exponential`,2],[`zoom`],12,2,16,3.5,18,4.5,20,5];return[{id:`${e.id}_${t}`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`grey`,"line-width":3}},{id:`${e.id}_${t}_red`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`red`,"line-width":n,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`1`],1,0]}},{id:`${e.id}_${t}_white`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`white`,"line-width":n,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e.id}_${t}_grey`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`,visibility:`none`},paint:{"line-color":`grey`,"line-width":n,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`3`],1,0]}},{id:`${e.id}_${t}_white_label`,type:`symbol`,source:e.id,"source-layer":t,filter:[`!=`,[`get`,`category`],2],layout:{"text-field":[`get`,`name`],"text-size":[`interpolate`,[`linear`],[`zoom`],15,[`case`,[`==`,[`get`,`category`],50],12,[`==`,[`get`,`category`],96],10,9],22,[`case`,[`==`,[`get`,`category`],50],18,[`==`,[`get`,`category`],96],14,15]],"text-font":[`Open Sans Regular`],"text-anchor":`bottom`,"text-offset":[0,-1],"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":`white`,"text-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e.id}_${t}_red_label`,type:`symbol`,source:e.id,"source-layer":t,filter:[`!=`,[`get`,`category`],2],layout:{"text-field":[`get`,`name`],"text-size":[`interpolate`,[`linear`],[`zoom`],15,[`case`,[`==`,[`get`,`category`],50],12,[`==`,[`get`,`category`],96],10,9],22,[`case`,[`==`,[`get`,`category`],50],18,[`==`,[`get`,`category`],96],14,15]],"text-font":[`Open Sans Regular`],"text-anchor":`bottom`,"text-offset":[0,-1],"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":`red`,"text-opacity":[`case`,[`==`,[`feature-state`,`state`],`1`],1,0]}}]},fe=(e,t)=>{let n=[`interpolate`,[`exponential`,2],[`zoom`],12,.2,16,.6,18,.8,20,1.5],r=[];return[w.Red,w.Green,w.White,w.Blue].forEach(i=>{r.push({id:`${e.id}_${t}_${i}`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":[`case`,[`==`,[`get`,`inst_type`],1],[`case`,[`==`,[`get`,`posi_side`],1],`icon-signal-h-l-${i}`,`icon-signal-h-r-${i}`],[`case`,[`==`,[`get`,`posi_side`],1],`icon-signal-l-l-${i}`,`icon-signal-l-r-${i}`]],"icon-size":n,"icon-rotate":[`case`,[`==`,[`get`,`posi_side`],2],[`+`,270,[`to-number`,[`get`,`angle`]]],[`+`,90,[`to-number`,[`get`,`angle`]]]],"icon-allow-overlap":!0,"icon-anchor":[`case`,[`==`,[`get`,`posi_side`],1],`bottom-left`,`bottom-right`]},paint:{"icon-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],i],[`!=`,[`feature-state`,`visiable`],!1]],1,0]}})}),[...r,{id:`${e.id}_${t}`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":[`case`,[`==`,[`get`,`inst_type`],1],[`case`,[`==`,[`get`,`posi_side`],1],`icon-signal-h-l`,`icon-signal-h-r`],[`case`,[`==`,[`get`,`posi_side`],1],`icon-signal-l-l`,`icon-signal-l-r`]],"icon-size":n,"icon-rotate":[`case`,[`==`,[`get`,`posi_side`],2],[`+`,270,[`to-number`,[`get`,`angle`]]],[`+`,90,[`to-number`,[`get`,`angle`]]]],"icon-allow-overlap":!0,"icon-anchor":[`case`,[`==`,[`get`,`posi_side`],1],`bottom-left`,`bottom-right`]},paint:{"icon-opacity":[`case`,[`!=`,[`feature-state`,`visiable`],!1],1,0]}}]},pe=(e,t)=>[{id:`${e.id}_${t}_hitarea`,type:`circle`,source:e.id,"source-layer":t,paint:{"circle-radius":[`interpolate`,[`linear`],[`zoom`],5,11],"circle-color":`red`,"circle-opacity":0}},{id:`${e.id}_${t}_text`,type:`symbol`,source:e.id,"source-layer":t,layout:{"text-field":[`get`,`name`],"text-size":[`interpolate`,[`linear`],[`zoom`],15,11,22,15],"text-font":[`Open Sans Regular`],"text-anchor":`top`,"text-offset":[0,.5],"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":[`match`,[`feature-state`,`state`],`2`,`lightgreen`,`3`,`darkorange`,`4`,`red`,`white`]}},{id:`${e.id}_${t}_lock`,type:`circle`,source:e.id,"source-layer":t,layout:{visibility:`visible`},paint:{"circle-radius":[`interpolate`,[`linear`],[`zoom`],5,8],"circle-stroke-width":1.7,"circle-stroke-color":[`match`,[`feature-state`,`state`],`2`,`green`,`3`,`darkorange`,`4`,`red`,`white`],"circle-color":`transparent`,"circle-stroke-opacity":[`case`,[`==`,[`feature-state`,`subState2`],`1`],1,0]}},{id:`${e.id}_${t}_danfen`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":`icon-red-box`,"icon-allow-overlap":!0,"icon-offset":[0,15],"icon-size":[`interpolate`,[`linear`],[`zoom`],5,.2,10,.5,18,1]},paint:{"icon-opacity":[`case`,[`==`,[`feature-state`,`subState3`],`1`],1,0]}}],me=(e,t)=>[{id:`${e.id}_${t}`,type:`line`,source:e.id,"source-layer":t,paint:{"line-width":5,"line-color":`#000000`}},{id:`${e.id}_${t}_normal`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`2`]],paint:{"line-width":4,"line-color":`green`,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e.id}_${t}_reverse`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`3`]],paint:{"line-width":4,"line-color":`darkorange`,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`3`],1,0]}},{id:`${e.id}_${t}_fourway`,type:`line`,source:e.id,"source-layer":t,paint:{"line-width":4,"line-color":`#000000`,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`4`],1,0]}},{id:`${e.id}_${t}_normal_white`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`2`]],paint:{"line-width":4,"line-color":`white`,"line-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],`2`],[`==`,[`feature-state`,`subState1`],`2`]],1,0]}},{id:`${e.id}_${t}_reverse_white`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`3`]],paint:{"line-width":4,"line-color":`white`,"line-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],`3`],[`==`,[`feature-state`,`subState1`],`2`]],1,0]}},{id:`${e.id}_${t}_normal_red`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`2`]],paint:{"line-width":4,"line-color":`red`,"line-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],`2`],[`==`,[`feature-state`,`subState1`],`3`]],1,0]}},{id:`${e.id}_${t}_reverse_red`,type:`line`,source:e.id,"source-layer":t,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`3`]],paint:{"line-width":4,"line-color":`red`,"line-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],`3`],[`==`,[`feature-state`,`subState1`],`3`]],1,0]}}],he=(e,t)=>({id:`${e.id}_${t}`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":`icon-bumper`,"icon-size":[`interpolate`,[`exponential`,2],[`zoom`],12,.1,16,.5,18,.7,20,1.4],"icon-rotate":[`get`,`angle`],"icon-allow-overlap":!0,"icon-anchor":`left`}}),ge=(e,t)=>({id:`${e.id}_${t}`,type:`symbol`,source:e.id,"source-layer":t,filter:[`!=`,[`get`,`category`],2],layout:{"text-field":[`get`,`name`],"text-size":[`interpolate`,[`linear`],[`zoom`],15,[`case`,[`==`,[`get`,`category`],50],10,[`==`,[`get`,`category`],96],8,7],22,[`case`,[`==`,[`get`,`category`],50],16,[`==`,[`get`,`category`],96],12,13]],"text-font":[`Open Sans Regular`],"text-anchor":[`case`,[`==`,[`get`,`angle`],90],`bottom-left`,`top-right`],"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":`#C0C33F`}}),_e=(e,t)=>{let n=[`interpolate`,[`exponential`,2],[`zoom`],12,1,15,1.5,16,2,17,4];return{id:`${e.id}_${t}`,type:`circle`,source:e.id,"source-layer":t,filter:[`!=`,[`get`,`category`],2],paint:{"circle-radius":n,"circle-stroke-width":n,"circle-stroke-color":`#ffbb00`},layout:{visibility:`none`}}},E=function(e){return e[e.NULL=0]=`NULL`,e[e.BUMPER=1]=`BUMPER`,e[e.CONTACTLINEEND=2]=`CONTACTLINEEND`,e[e.FIXEDDERAILER=3]=`FIXEDDERAILER`,e[e.CONTACTLINENOSTOP=4]=`CONTACTLINENOSTOP`,e[e.CONTACTLINENOSTOPIN=5]=`CONTACTLINENOSTOPIN`,e[e.OTHERPROMPT=6]=`OTHERPROMPT`,e[e.OTHERBRAKE=7]=`OTHERBRAKE`,e[e.ONESTOP=8]=`ONESTOP`,e[e.SPEEDLIMITED=9]=`SPEEDLIMITED`,e[e.SPEEDNOTICE=10]=`SPEEDNOTICE`,e[e.CROSSSPEEDLIMITED=11]=`CROSSSPEEDLIMITED`,e[e.CONTACTLINEPSS=12]=`CONTACTLINEPSS`,e[e.SSG=13]=`SSG`,e[e.CONTACTLINEPSSIN=14]=`CONTACTLINEPSSIN`,e[e.CONTACTLINENOAREA=15]=`CONTACTLINENOAREA`,e[e.HIGHPOSTSIGNAL=16]=`HIGHPOSTSIGNAL`,e[e.RESCUEVEHICLE=17]=`RESCUEVEHICLE`,e[e.RAILWAYCROSS=18]=`RAILWAYCROSS`,e[e.TRAIN=19]=`TRAIN`,e[e.STATIONBOUND=20]=`STATIONBOUND`,e[e.SHORTPOSTSIGNAL=21]=`SHORTPOSTSIGNAL`,e[e.BRIDGE=22]=`BRIDGE`,e[e.WHITE=23]=`WHITE`,e[e.WHITEBLUE=24]=`WHITEBLUE`,e[e.BLUE=25]=`BLUE`,e[e.BLUEWHITE=26]=`BLUEWHITE`,e[e.SLOPE=27]=`SLOPE`,e[e.PEOPLE=28]=`PEOPLE`,e[e.TUNNEL=29]=`TUNNEL`,e[e.DANGER=30]=`DANGER`,e[e.SIGNAL=31]=`SIGNAL`,e[e.SWERVE=32]=`SWERVE`,e[e.SWITCH=33]=`SWITCH`,e[e.FOULINGPOST=38]=`FOULINGPOST`,e[e.CUNCHE=39]=`CUNCHE`,e[e.STATIONBOUNDEXTEND=40]=`STATIONBOUNDEXTEND`,e[e.RED=41]=`RED`,e[e.GREEN=42]=`GREEN`,e[e.YELLOW=43]=`YELLOW`,e[e.BLOCKLINE=50]=`BLOCKLINE`,e[e.WORKAREA=51]=`WORKAREA`,e[e.ROUTELINE=52]=`ROUTELINE`,e[e.PARK=53]=`PARK`,e[e.WORKBUOND=54]=`WORKBUOND`,e[e.WORKBUONDCROSS=55]=`WORKBUONDCROSS`,e[e.LEFTHIGHPLATFORM=61]=`LEFTHIGHPLATFORM`,e[e.RIGHTHIGHPLATFORM=62]=`RIGHTHIGHPLATFORM`,e[e.BOTHSIDEHIGHPLATFORM=63]=`BOTHSIDEHIGHPLATFORM`,e[e.TGQ=47]=`TGQ`,e[e.DOOR=87]=`DOOR`,e[e.OTHER=95]=`OTHER`,e[e.SIDE=253]=`SIDE`,e[e.NONE=254]=`NONE`,e[e.MAX=255]=`MAX`,e[e.ISOLATE=35]=`ISOLATE`,e[e.ISOLATESWITCH=100]=`ISOLATESWITCH`,e}({}),ve={background:le,signal:fe,track:ue,track_circuit:de,bumper:he,switch:pe,switch_loc:me,insulation:_e,label:ge,prevention:(e,t)=>[{id:`${e.id}_${t}_jcw`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":[`case`,[`==`,[`to-string`,[`get`,`uc_oob_type`]],String(E.CONTACTLINEEND)],`icon-jcw`,``],"icon-size":[`interpolate`,[`exponential`,2],[`zoom`],12,.1,16,.5,18,.7,20,1.4],"icon-allow-overlap":!0,"icon-anchor":`left`}},{id:`${e.id}_${t}_circle`,type:`circle`,source:e.id,"source-layer":t,filter:[`match`,[`to-string`,[`get`,`uc_oob_type`]],[String(E.ONESTOP),String(E.STATIONBOUND),String(E.DOOR)],!0,!1],paint:{"circle-radius":[`interpolate`,[`exponential`,2],[`zoom`],10,6,20,18],"circle-stroke-width":2,"circle-stroke-color":`red`},layout:{visibility:`visible`}},{id:`${e.id}_${t}_text`,type:`symbol`,source:e.id,"source-layer":t,filter:[`match`,[`to-string`,[`get`,`uc_oob_type`]],[String(E.CONTACTLINEEND),String(E.ONESTOP),String(E.STATIONBOUND),String(E.DOOR)],!0,!1],layout:{"text-field":[`case`,[`==`,[`to-string`,[`get`,`uc_oob_type`]],String(E.ONESTOP)],`停`,[`==`,[`to-string`,[`get`,`uc_oob_type`]],String(E.STATIONBOUND)],`界`,``],"text-font":[`Open Sans Regular`],"text-size":[`interpolate`,[`linear`],[`zoom`],10,6,20,18],"text-anchor":`center`,"symbol-placement":`point`,"text-allow-overlap":!0,visibility:`visible`},paint:{"text-color":`white`}}]},ye=e=>{let t=[];return e.layers.forEach((n,r)=>{let i=ve[n],a=e.sourceLayers[r];if(i){let n=i(e,a);Array.isArray(n)?t.push(...n):t.push(n)}else console.warn(`图层 ${n} 尚未实现`)}),t},be={background:(e,t)=>({id:`${e.id}_${t}`,type:`background`,paint:{"background-color":`#131212`}}),signal:(e,t)=>[{id:`${e.id}_${t}`,type:`symbol`,source:e.id,"source-layer":t,layout:{"icon-image":[`case`,[`==`,[`get`,`inst_type`],1],[`case`,[`==`,[`get`,`posi_side`],2],`icon-signal-h-r`,`icon-signal-h-l`],[`case`,[`==`,[`get`,`posi_side`],2],`icon-signal-l-r`,`icon-signal-l-l`]],"icon-allow-overlap":!0,"icon-rotate":[`case`,[`==`,[`get`,`posi_side`],2],[`-`,270,[`to-number`,[`get`,`angle`]]],[`-`,90,[`to-number`,[`get`,`angle`]]]],"icon-size":[`interpolate`,[`exponential`,2],[`zoom`],12,0,16,.3,18,.5,20,1],"icon-anchor":[`case`,[`==`,[`get`,`posi_side`],1],`bottom-left`,`bottom-right`],"icon-offset":[0,2]},paint:{"icon-opacity":[`case`,[`!=`,[`feature-state`,`visiable`],!1],1,0]}},{id:`${e.id}_${t}_text`,type:`symbol`,source:e.id,"source-layer":t,layout:{"text-field":[`get`,`name`],"text-font":[`Arial Unicode MS Bold`],"text-size":[`interpolate`,[`linear`],[`zoom`],12,5,14,8,18,14],"text-anchor":`center`,"symbol-placement":`point`,"text-allow-overlap":!0,"text-offset":[0,.6]},paint:{"text-color":`gold`}}],track:(e,t)=>[{id:`${e.id}_${t}_hitarea`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`black`,"line-width":6,"line-opacity":[`case`,[`==`,[`feature-state`,`select`],!0],1,0]}},{id:`${e.id}_${t}`,type:`line`,source:e.id,"source-layer":t,layout:{"line-join":`round`},paint:{"line-color":`#85A0D9`,"line-width":2}}],track_circuit:null,bumper:(e,t)=>[{id:`${e.id}_${t}`,type:`circle`,source:e.id,"source-layer":t,paint:{"circle-radius":[`interpolate`,[`exponential`,2],[`zoom`],10,3,12,3,14,5,16,6,20,8],"circle-stroke-width":2,"circle-stroke-color":`red`}},{id:`${e.id}_${t}_text`,type:`symbol`,source:e.id,"source-layer":t,layout:{"text-field":`档`,"text-font":[`Arial Unicode MS Bold`],"text-size":[`interpolate`,[`linear`],[`zoom`],10,6,12,8,14,10,16,12,20,12],"text-anchor":`center`,"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":`white`}}],switch:null,switch_loc:null,insulation:null,label:null,prevention:(e,t)=>[{id:`${e.id}_${t}`,type:`circle`,source:e.id,"source-layer":t,filter:[`match`,[`to-string`,[`get`,`uc_oob_type`]],[`2`,`8`,`20`,`87`],!0,!1],paint:{"circle-radius":[`interpolate`,[`exponential`,2],[`zoom`],10,3,12,3,14,5,16,6,20,8],"circle-stroke-width":2,"circle-stroke-color":`red`}},{id:`${e.id}_${t}_text`,type:`symbol`,source:e.id,"source-layer":t,layout:{"text-field":[`case`,[`==`,[`to-string`,[`get`,`uc_oob_type`]],`2`],`网`,[`==`,[`to-string`,[`get`,`uc_oob_type`]],`8`],`停`,[`==`,[`to-string`,[`get`,`uc_oob_type`]],`20`],`界`,`门`],"text-font":[`Arial Unicode MS Bold`],"text-size":[`interpolate`,[`linear`],[`zoom`],10,6,12,8,14,10,16,12,20,12],"text-anchor":`center`,"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":`white`}}]},xe=e=>{let t=[];return e.layers.forEach((n,r)=>{let i=be[n],a=e.sourceLayers[r];if(i){let n=i(e,a);Array.isArray(n)?t.push(...n):t.push(n)}else console.warn(`图层 ${n} 尚未实现`)}),t},Se=e=>[{id:`${e}_raster_layer`,type:`raster`,source:e,paint:{"raster-opacity":.8}}],Ce=e=>({id:`${e}_background`,type:`background`,paint:{"background-color":`#131212`}}),we=e=>[{id:`${e}_track_lock`,type:`line`,source:e,layout:{"line-join":`round`},paint:{"line-color":`#a7009e`,"line-width":3,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`1`],1,0]}},{id:`${e}_track_lock_icon`,type:`symbol`,source:e,layout:{"symbol-placement":`line-center`,"icon-anchor":`top`,"icon-image":`icon-lock`,"icon-size":[`interpolate`,[`exponential`,2],[`zoom`],12,.2,15,.5,16,.6,17,.8],"icon-offset":[0,5],"icon-allow-overlap":!0,"icon-rotation-alignment":`viewport`,"icon-rotate":0},paint:{"icon-opacity":[`case`,[`==`,[`feature-state`,`state`],`1`],1,0]}},{id:`${e}_track_poweroff_border`,type:`line`,source:e,layout:{"line-join":`round`},paint:{"line-color":`green`,"line-width":9,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e}_track_poweroff_fill`,type:`line`,source:e,layout:{"line-join":`round`},paint:{"line-color":`black`,"line-width":6,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e}_track_catenery_border`,type:`line`,source:e,layout:{"line-join":`round`},paint:{"line-color":`grey`,"line-width":9,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`3`],1,0]}},{id:`${e}_track_catenery_fill`,type:`line`,source:e,layout:{"line-join":`round`},paint:{"line-color":`black`,"line-width":6,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`3`],1,0]}},{id:`${e}_track`,type:`line`,source:e,layout:{"line-join":`round`},paint:{"line-color":`#85A0D9`,"line-width":2}}],Te=function(e){return e[e.RedCircuit=1]=`RedCircuit`,e[e.WhiteCircuit=2]=`WhiteCircuit`,e[e.EqualRedCircuit=3]=`EqualRedCircuit`,e[e.GreyCircuit=4]=`GreyCircuit`,e[e.GreenCircuit=5]=`GreenCircuit`,e}({}),Ee={background:Ce,signal:e=>{let t=[`interpolate`,[`exponential`,2],[`zoom`],12,.2,16,.6,18,.8,20,1.5];return[...[w.Red,w.Green,w.White,w.Blue].map(n=>({id:`${e}_signal_${n}`,type:`symbol`,source:e,layout:{"icon-image":[`case`,[`==`,[`get`,`installType`],1],[`case`,[`==`,[`get`,`positionSide`],1],`icon-signal-h-l-${n}`,`icon-signal-h-r-${n}`],[`case`,[`==`,[`get`,`positionSide`],1],`icon-signal-l-l-${n}`,`icon-signal-l-r-${n}`]],"icon-size":t,"icon-rotate":[`case`,[`==`,[`get`,`positionSide`],2],[`+`,270,[`to-number`,[`get`,`angle`]]],[`+`,90,[`to-number`,[`get`,`angle`]]]],"icon-allow-overlap":!0,"icon-anchor":[`case`,[`==`,[`get`,`positionSide`],1],`bottom-left`,`bottom-right`]},paint:{"icon-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],n],[`!=`,[`feature-state`,`visiable`],!1]],1,0]}})),{id:`${e}_signal`,type:`symbol`,source:e,layout:{"icon-image":[`case`,[`==`,[`get`,`installType`],1],[`case`,[`==`,[`get`,`positionSide`],1],`icon-signal-h-l`,`icon-signal-h-r`],[`case`,[`==`,[`get`,`positionSide`],1],`icon-signal-l-l`,`icon-signal-l-r`]],"icon-size":t,"icon-rotate":[`case`,[`==`,[`get`,`positionSide`],2],[`+`,270,[`to-number`,[`get`,`angle`]]],[`+`,90,[`to-number`,[`get`,`angle`]]]],"icon-allow-overlap":!0,"icon-anchor":[`case`,[`==`,[`get`,`positionSide`],1],`bottom-left`,`bottom-right`]},paint:{"icon-opacity":[`case`,[`!=`,[`feature-state`,`visiable`],!1],1,0]}}]},track:we,track_circuit:e=>{let t=[`interpolate`,[`exponential`,2],[`zoom`],12,2,16,3.5,18,4.5,20,5];return[{id:`${e}_trackcircuit_bad`,type:`line`,source:e,layout:{"line-join":`round`},paint:{"line-color":[`case`,[`==`,[`feature-state`,`state`],Te.RedCircuit],`#ff0000`,[`==`,[`feature-state`,`state`],Te.WhiteCircuit],`#ffffff`,[`==`,[`feature-state`,`state`],Te.GreyCircuit],`#808080`,`#000000`],"line-width":t,"line-dasharray":[4,4],"line-opacity":[`case`,[`==`,[`feature-state`,`substate`],0],1,0]}},{id:`${e}_trackcircuit_grey`,type:`line`,source:e,layout:{"line-join":`round`},paint:{"line-color":`grey`,"line-width":t,"line-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],Te.GreyCircuit],[`!=`,[`feature-state`,`substate`],0]],1,0]}},{id:`${e}_trackcircuit_red`,type:`line`,source:e,layout:{"line-join":`round`},paint:{"line-color":`red`,"line-width":t,"line-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],Te.RedCircuit],[`!=`,[`feature-state`,`substate`],0]],1,0]}},{id:`${e}_trackcircuit_white`,type:`line`,source:e,layout:{"line-join":`round`},paint:{"line-color":`white`,"line-width":t,"line-opacity":[`case`,[`all`,[`==`,[`feature-state`,`state`],Te.WhiteCircuit],[`!=`,[`feature-state`,`substate`],0]],1,0]}},{id:`${e}_trackcircuit_white_label`,type:`symbol`,source:e,filter:[`!=`,[`get`,`category`],2],layout:{"text-field":[`get`,`name`],"text-size":[`interpolate`,[`linear`],[`zoom`],15,[`case`,[`==`,[`get`,`category`],50],12,[`==`,[`get`,`category`],96],10,9],22,[`case`,[`==`,[`get`,`category`],50],18,[`==`,[`get`,`category`],96],14,15]],"text-font":[`Open Sans Regular`],"text-anchor":`bottom`,"text-offset":[0,-1],"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":`white`,"text-opacity":[`case`,[`==`,[`feature-state`,`state`],Te.WhiteCircuit],1,0]}},{id:`${e}_trackcircuit_red_label`,type:`symbol`,source:e,filter:[`!=`,[`get`,`category`],2],layout:{"text-field":[`get`,`name`],"text-size":[`interpolate`,[`linear`],[`zoom`],15,[`case`,[`==`,[`get`,`category`],50],12,[`==`,[`get`,`category`],96],10,9],22,[`case`,[`==`,[`get`,`category`],50],18,[`==`,[`get`,`category`],96],14,15]],"text-font":[`Open Sans Regular`],"text-anchor":`bottom`,"text-offset":[0,-1],"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":`red`,"text-opacity":[`case`,[`==`,[`feature-state`,`state`],Te.RedCircuit],1,0]}}]},bumper:e=>({id:`${e}_bumper`,type:`symbol`,source:e,layout:{"icon-image":`icon-bumper`,"icon-size":[`interpolate`,[`exponential`,2],[`zoom`],12,.1,16,.5,18,.7,20,1.4],"icon-rotate":[`get`,`angle`],"icon-allow-overlap":!0,"icon-anchor":`left`}}),switch:e=>[{id:`${e}_switch_hitarea`,type:`circle`,source:e,paint:{"circle-radius":[`interpolate`,[`linear`],[`zoom`],5,11],"circle-color":`red`,"circle-opacity":0}},{id:`${e}_switch_text`,type:`symbol`,source:e,layout:{"text-field":[`get`,`name`],"text-size":[`interpolate`,[`linear`],[`zoom`],15,11,22,15],"text-font":[`Open Sans Regular`],"text-anchor":`top`,"text-offset":[0,.5],"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":[`match`,[`feature-state`,`state`],`2`,`lightgreen`,`3`,`darkorange`,`4`,`red`,`white`]}}],switch_loc:e=>[{id:`${e}_switchloc`,type:`line`,source:e,paint:{"line-width":5,"line-color":`#000000`}},{id:`${e}_switchloc_normal`,type:`line`,source:e,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`2`]],paint:{"line-width":4,"line-color":`green`,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`2`],1,0]}},{id:`${e}_switchloc_reverse`,type:`line`,source:e,filter:[`any`,[`==`,[`get`,`location`],`1`],[`==`,[`get`,`location`],`3`]],paint:{"line-width":4,"line-color":`darkorange`,"line-opacity":[`case`,[`==`,[`feature-state`,`state`],`3`],1,0]}}],insulation:e=>{let t=[`interpolate`,[`exponential`,2],[`zoom`],12,1,15,1.5,16,2,17,4];return{id:`${e}_insulation`,type:`circle`,source:e,filter:[`!=`,[`get`,`category`],2],paint:{"circle-radius":t,"circle-stroke-width":t,"circle-stroke-color":`#ffbb00`}}},label:e=>({id:`${e}_label`,type:`symbol`,source:e,filter:[`!=`,[`get`,`category`],2],layout:{"text-field":[`get`,`name`],"text-size":[`interpolate`,[`linear`],[`zoom`],15,[`case`,[`==`,[`get`,`category`],50],12,[`==`,[`get`,`category`],96],10,9],22,[`case`,[`==`,[`get`,`category`],50],18,[`==`,[`get`,`category`],96],14,15]],"text-font":[`Open Sans Regular`],"text-anchor":[`case`,[`==`,[`get`,`angle`],90],`bottom-left`,`top-right`],"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":`yellow`}}),prevention:e=>[{id:`${e}_prevention_jcw`,type:`symbol`,source:e,layout:{"icon-image":[`case`,[`==`,[`to-number`,[`get`,`ucOobType`]],E.CONTACTLINEEND],`icon-jcw`,``],"icon-size":[`interpolate`,[`exponential`,2],[`zoom`],12,.1,16,.5,18,.7,20,1.4],"icon-allow-overlap":!0,"icon-anchor":`left`}},{id:`${e}_prevention_circle`,type:`circle`,source:e,filter:[`match`,[`to-number`,[`get`,`ucOobType`]],[E.ONESTOP,E.STATIONBOUND,E.DOOR],!0,!1],paint:{"circle-radius":[`interpolate`,[`exponential`,2],[`zoom`],10,6,20,18],"circle-stroke-width":2,"circle-stroke-color":`red`}},{id:`${e}_prevention_text`,type:`symbol`,source:e,filter:[`match`,[`to-number`,[`get`,`ucOobType`]],[E.CONTACTLINEEND,E.ONESTOP,E.STATIONBOUND,E.DOOR],!0,!1],layout:{"text-field":[`case`,[`==`,[`to-number`,[`get`,`ucOobType`]],E.ONESTOP],`停`,[`==`,[`to-number`,[`get`,`ucOobType`]],E.STATIONBOUND],`界`,[`==`,[`to-number`,[`get`,`ucOobType`]],E.DOOR],`门`,``],"text-font":[`Open Sans Regular`],"text-size":[`interpolate`,[`linear`],[`zoom`],10,6,20,18],"text-anchor":`center`,"symbol-placement":`point`,"text-allow-overlap":!0},paint:{"text-color":`white`}}]},D={ctc:ce,graph:ye,geom:xe,raster:Se,geojson:(e,t)=>{let n=[];return e.forEach((e,r)=>{let i=t[r],a=Ee[e];if(!a){console.warn(`GeoJSON 图层 ${e} 尚未实现`);return}let o=a(i);Array.isArray(o)?n.push(...o):n.push(o)}),n}};function De(e){if(!e||e.length<11)return``;let t=e.charAt(10),n=e.charAt(9);return n===`6`&&t===`7`?`sgfhqy_door`:n===`6`&&t===`8`?`sgfhqy_line`:n===`6`&&t===`9`?`sgfhqy_area`:t===`1`&&n===`0`?`track`:t===`3`?`signal`:t===`2`&&n===`0`||t===`1`&&n===`1`?`switch`:t===`2`&&n===`1`?`circuit`:``}var Oe=class{teeeMap;trackFeatures=[];switchFeatures=[];switchlocFeatures=[];circuitFeatures=[];signalFeatures=[];sgfhqyFeatures=[];pathInfoRecords=[];onPathSelected;boundHandlePathClick;constructor(e){this.teeeMap=e,this.boundHandlePathClick=this.handlePathClick.bind(this),e.map.once(`idle`,()=>{if(!e.mapConfigs)return;let{id:t}=e.mapConfigs,n=e.mapConfigs.sourceLayers,r=e.mapConfigs.layers;e.map.moveLayer(`${t}_${n[r.indexOf(`track`)]}_lock`)})}cacheFeatures(){let{mapConfigs:e}=this.teeeMap;if(!e)return;let t=e.id,n=e.sourceLayers,r=e.layers;this.trackFeatures=this.teeeMap.map.querySourceFeatures(t,{sourceLayer:n[r.indexOf(`track`)]}),this.switchFeatures=this.teeeMap.map.querySourceFeatures(t,{sourceLayer:n[r.indexOf(`switch`)]}),this.switchlocFeatures=this.teeeMap.map.querySourceFeatures(t,{sourceLayer:n[r.indexOf(`switch_loc`)]}),this.circuitFeatures=this.teeeMap.map.querySourceFeatures(t,{sourceLayer:n[r.indexOf(`track_circuit`)]}),this.signalFeatures=this.teeeMap.map.querySourceFeatures(t,{sourceLayer:n[r.indexOf(`signal`)]}),this.sgfhqyFeatures=this.teeeMap.map.querySourceFeatures(t,{sourceLayer:n[r.indexOf(`sgfhqy`)]})}initState(){let{mapConfigs:e}=this.teeeMap;if(!e)return;let t=e.id;e.sourceLayers.forEach(e=>{e.includes(`switch`)?this.teeeMap.map.querySourceFeatures(t,{sourceLayer:e}).forEach(e=>this.initCTCFeatureState(e)):e.includes(`signal`)?this.teeeMap.map.querySourceFeatures(t,{sourceLayer:e}).forEach(e=>{this.initCTCFeatureState(e)}):(e.includes(`track`)||e.includes(`sgfhqy`))&&this.teeeMap.map.querySourceFeatures(t,{sourceLayer:e}).forEach(e=>this.initCTCFeatureState(e))})}initCTCFeatureState(e){if(!e)return;let t=e.properties.code,n=De(t);if(n===`switch`)this.teeeMap.updateFeatureState(e.properties.code,{state:`2`,select:!1,visiable:!0,subState1:``,subState2:``,subState3:``});else if(n===`signal`){let t=e.properties,n=t.attach||0,r=t.func_type,i={state:``,select:!1,visiable:!0,subState1:`grey`,subState2:``,subState3:``};r==1&&n==0||(r==2||r==3)&&n==0||(r==2||r==3||r==11)&&n==1?(i.state=`red`,i.subState1=`blue`):(r==4||r==5||r==12)&&n==0?(i.state=`blue`,i.subState1=`green`):r==6&&n==0||(r==7||r==11)&&n==0?(i.state=`red`,i.subState1=`blue`):(i.state=``,i.subState1=`grey`),this.teeeMap.updateFeatureState(t.code,i)}else n===`signal`||n===`circuit`?this.teeeMap.updateFeatureState(e.properties.code,{state:``,select:!1,visiable:!0,subState1:``,subState2:``,subState3:``}):n===`sgfhqy_door`?this.teeeMap.updateFeatureState(e.properties.code,{state:`2`,select:!1,visiable:!0,subState1:``,subState2:``,subState3:``}):n===`sgfhqy_fill`&&this.teeeMap.updateFeatureState(e.properties.code,{state:``,select:!1,visiable:!0,subState1:``,subState2:``,subState3:``})}changeFeatureState(e,t){if(this.teeeMap.updateFeatureState(e,t),!e||e.length<11)return;let n=e.charAt(10),r=e.charAt(9);n===`2`&&r===`0`&&this.switchlocFeatures.forEach(n=>{n.properties.s_code==e&&this.teeeMap.updateFeatureState(n.properties.code,t)})}parseSignals(e){let t=[],n=this.signalFeatures.filter(t=>t.properties.name==e.destSignal)[0],r=this.signalFeatures.filter(t=>t.properties.name==e.srcSignal)[0];return t.push(n),t.push(r),t}parseSwitchs(e){let t=[];return e.forEach(e=>{let n=`2`,r=e;e.startsWith(`[`)&&e.endsWith(`]`)?(n=`protect`,r=e.slice(1,-1)):e.startsWith(`(`)&&e.endsWith(`)`)?(n=`3`,r=e.slice(1,-1)):e.startsWith(`{`)&&e.endsWith(`}`)&&(n=`drive`,r=e.slice(1,-1)),r.split(`/`).forEach(e=>{let r=this.switchFeatures.filter(t=>t.properties.name===e.trim());r.length>0&&t.push({name:e.trim(),code:r[0].properties.code,type:n,f:r})})}),t}parseTrackCircuits(e,t){let n=[];return e.forEach(e=>{let r=this.circuitFeatures.filter(t=>t.properties.name===e);if(!r.length)return;r.forEach(e=>{this.teeeMap.updateFeatureState(e.properties.code,{state:`3`})});let i=r.filter(e=>{let n=e.properties.switches?e.properties.switches.split(`,`):[],r=e.properties.positions?e.properties.positions.split(`,`).map(e=>Number(e)):[];if(n.length===0)return!0;for(let e=0;e<n.length;e++){let i=n[e],a=r[e*2],o=r[e*2+1],s=Math.max(a,o),c=t.get(i);if(!c||c!==s)return!1}return!0});if(i.length>0){let t=new Map;i.forEach(e=>{let n=e.properties.code;t.has(n)||t.set(n,e)});let r=Array.from(t.values());r.length===1?n.push(...r):r.length===0?console.warn(`未匹配到有效区段:`,e):console.warn(`匹配到多个区段,数据异常:`,e,i)}}),n}calcPathInfo(e){let t=[];for(let n of e){let e=n.trackSections,r=n.turnouts,i=this.parseSignals(n),a=this.parseSwitchs(r),o=new Map;a.forEach(e=>{o.set(e.code,Number(e.type))});let s=this.parseTrackCircuits(e,o);t.push({signalInfos:i,switchInfos:a,pathInfo:s})}return t}changePathState(e){if(e.length===0)return;let t=`4`;e.forEach((e,n,r)=>{n===r.length-1&&(t=`5`),e.routes.forEach(e=>{e.signalInfos.forEach(e=>{e&&this.changeFeatureState(e.properties.code,{state:`white`})}),e.switchInfos.forEach(e=>{e&&this.changeFeatureState(e.code,{state:e.type,subState1:`2`})}),e.pathInfo.forEach(e=>{e&&this.changeFeatureState(e.properties.code,{state:t})})})})}unloadPathClick(){this.teeeMap.map.off(`click`,this.boundHandlePathClick),this.pathInfoRecords=[]}handlePathClick(e){let t=this.teeeMap.getMapConfigs().id,n=this.teeeMap.getMapConfigs().sourceLayers,r=this.teeeMap.getMapConfigs().layers,i=[`${t}_${n[r.indexOf(`track_circuit`)]}_mainpath`,`${t}_${n[r.indexOf(`track_circuit`)]}_subpath`,`${t}_${n[r.indexOf(`track_circuit`)]}_hitarea`],a=this.teeeMap.map.queryRenderedFeatures(e.point,{layers:i});if(a.length>0){let e=a,t=this.pathInfoRecords.find(t=>e.some(e=>t.routes.some(t=>t.pathInfo.some(t=>t.properties.name===e.properties.name&&t.properties.code===e.properties.code))));if(t){let e=this.pathInfoRecords.indexOf(t);e>-1&&(this.pathInfoRecords.splice(e,1),this.pathInfoRecords.push(t)),this.changePathState(this.pathInfoRecords),this.onPathSelected?.(t)}}else console.warn(`未点击到有效的进路区段,请点击主进路或辅进路的电路区段`)}handlePathInfo(e){if(this.pathInfoRecords=[],e.forEach(e=>{let t={originalData:e,routes:this.calcPathInfo(e.routes)};this.pathInfoRecords.unshift(t)}),this.pathInfoRecords.length===0)return;this.changePathState(this.pathInfoRecords),this.pathInfoRecords.length>1?(console.log(`请左键单击选择目标进路`),this.teeeMap.map.on(`click`,this.boundHandlePathClick)):this.teeeMap.map.off(`click`,this.boundHandlePathClick);let t=this.pathInfoRecords[this.pathInfoRecords.length-1];this.onPathSelected?.(t)}createSignalAction(e){let t,n,r,i={},a,o=e.state,s=e.feature.properties,c=s.name;return o.subState1&&(o.subState1==`red`?(t=`nf`,n=`扭封`,a=c,i=e,r=`对${s.name}信号机钮封操作`):(t=`jf`,n=`解封`,a=c,i=e,r=`对${s.name}信号机解封操作`)),o.subState2&&(o.subState2==`off`?(t=`lightoff`,n=`灭灯`,a=c,i=e,r=`对${s.name}信号机灭灯操作`):(t=`lighton`,n=`点灯`,a=c,i=e,r=`对${s.name}信号机点灯操作`)),{actionType:t,actionName:n,content:r,target:a,data:i}}createAllLightAction(e){let t,n,r,i,a={};return e.state.subState2===`off`?(t=`lightoff`,n=`全灭`,r=`信号机全灭操作`,i=`lightoff`,a=e):(t=`lighton`,n=`全亮`,r=`信号机全亮操作`,i=`lighton`,a=e),{actionType:t,actionName:n,content:r,target:i,data:a}}createSwitchAction(e){let t,n,r,i,a={},o=e.state,s=e.feature.properties,c=s.name;return o.subState1&&(o.subState1==`red`?(t=`nf`,n=`扭封`,i=c,a=e,r=`对${s.name}信号机钮封操作`):(t=`jf`,n=`解封`,i=c,a=e,r=`对${s.name}信号机解封操作`)),o.subState2&&(o.subState2==`off`?(t=`dd`,n=`灭灯`,i=c,a=e,r=`对${s.name}信号机灭灯操作`):(t=`md`,n=`点灯`,i=c,a=e,r=`对${s.name}信号机点灯操作`)),o.subState1!==void 0&&(o.subState1===`2`?(t=`dcsb`,n=`道岔锁闭`,i=c,a=e,r=`对${s.name}道岔锁闭操作`):o.subState1===`3`?(t=`dczy`,n=`道岔占用`,i=c,a=e,r=`对${s.name}道岔占用操作`):o.subState1===``&&(t=`dccq`,n=`道岔出清`,i=c,a=e,r=`对${s.name}道岔出清操作`)),o.subState2!==void 0&&(o.subState2===``?(t=`dcjs`,n=`道岔解锁`,i=c,a=e,r=`对${s.name}道岔解锁操作`):(t=`dcds`,n=`道岔单锁`,i=c,a=e,r=`对${s.name}道岔单锁操作`)),o.subState3!==void 0&&(o.subState3===`1`?(t=`dcdf`,n=`道岔单封`,i=c,a=e,r=`对${s.name}道岔单封操作`):o.subState3===``&&(t=`dcjf`,n=`道岔解封`,i=c,a=e,r=`对${s.name}道岔解封操作`)),{actionType:t,actionName:n,content:r,target:i,data:a}}createPathAction(e){let t,n,r,i,a={},o=e.meta,s=e.feature.properties,c=s.name;return o.pathType==`srcSignal`?(t=`path`,n=`srcSignal`,i=c,a=e,r=`进路起点:${s.name}信号`):(t=`path`,n=`destSignal`,i=c,a=e,r=`进路终点:${s.name}信号`),{actionType:t,actionName:n,content:r,target:i,data:a}}createDLTXAction(e){let t,n,r,i,a={},o=e.feature.properties,s=o.name;return e.featureType==`dltx`&&(t=`dltx`,n=`短路铜线`,i=s,a=e,r=`区段:${o.name}安置短路铜线`),{actionType:t,actionName:n,content:r,target:i,data:a}}createWorkersAction(e){let t,n,r,i,a={};return e.featureType&&(t=e.featureType,n=`拖动绘制`,i=e.content,a=e,r=e.content),{actionType:t,actionName:n,content:r,target:i,data:a}}createFSQAction(e){let t,n,r,i,a={};e.state;let o=e.feature.properties,s=o.name;return e.featureType&&(t=`fsq`,n=`封锁区`,r=`对${o.name}区域进行封锁操作`,i=s,a=e),{actionType:t,actionName:n,content:r,target:i,data:a}}createDoorAction(e){let t=e.state,n=e.feature.properties.name,r={1:{op:`open`,label:`施工开门`},2:{op:`close`,label:`施工关门`},3:{op:`lsopen`,label:`临时开门`},4:{op:`lsclose`,label:`临时关门`}},i=e=>e===`1`?`t`:`f`,{op:a,label:o}=r[t.state]||{op:`unknown`,label:`未知操作`};return{actionType:`door_${a}_${i(t.subState1)}_${i(t.subState2)}_${i(t.subState3)}`,actionName:`通道门${o}`,content:`对${n} ${o}`,target:n,data:e}}};function ke(e,t){let n=this.map;if(n&&!n.getSource(e)){let r=T.graph(t);n.addSource(e,r)}}function Ae(e,t){let n=this.map;if(n&&!n.getSource(e)){let r=T.raster(t);n.addSource(e,r)}}function je(e,t){let n=this.map;if(!n){console.error(`地图实例未初始化`);return}try{if(n.getSource(e))console.warn(`源已存在,跳过添加: ${e}`);else{let r=t?T.geojson(t):T.geojson(void 0);n.addSource(e,r),console.log(`成功添加 GeoJSON 源: ${e}`)}}catch(t){console.error(` 添加源失败 [${e}]:`,t)}}function Me(e){let t=this.map;if(t)if(t.getSource(e))try{(t.getStyle().layers||[]).filter(t=>{if(`source`in t)return t.source===e}).forEach(e=>{t.removeLayer(e.id),console.log(`移除关联图层: ${e.id}`)}),t.removeSource(e),console.log(`成功移除源: ${e}`)}catch(t){console.error(`移除源失败 [${e}]:`,t)}else console.warn(`源不存在,无法移除: ${e}`)}function Ne(e,t){let n=this.map;if(!n)return;let r=n.getSource(e);r?(r.setData(t),console.log(`更新源数据: ${e}`)):this.addGeoJsonSource(e,t)}function Pe(e){let t=this.map;if(!t||!t.getSource(e))return null;let n=t.querySourceFeatures(e);return JSON.parse(JSON.stringify({type:`FeatureCollection`,features:n}))}function Fe(e,t,n=`fill`,r,i){let a=this.map;if(!a)return;if(!a.getSource(t)){console.error(`无法添加图层: 源 '${t}' 不存在`);return}a.getLayer(e)&&a.removeLayer(e);let o={};n===`fill`&&(o[`fill-color`]=`#3b82f6`),n===`line`&&(o[`line-color`]=`#3b82f6`),n===`circle`&&(o[`circle-color`]=`#3b82f6`);let s={id:e,type:n,source:t,paint:{...o,...r},layout:i||{}};a.addLayer(s)}function Ie(e,t){let n=this.map;n&&(n.getLayer(e)?(Object.keys(t).forEach(r=>{n.setPaintProperty(e,r,t[r])}),console.log(`样式已更新: ${e}`)):console.warn(` 图层不存在,无法更新样式: ${e}`))}function Le(e){let t=this.map;t&&(t.getLayer(e)?(t.removeLayer(e),console.log(`图层已移除: ${e}`)):console.warn(` 图层不存在,无法删除: ${e}`))}function Re(e,t){let n=this.map;if(!n)return;let r=Array.isArray(e)?e:[e];n.on(`click`,e=>{let i=n.queryRenderedFeatures(e.point,{layers:r});if(!i.length)return;let a=i[0];t(a,e.lngLat)}),n.on(`mouseenter`,r[r.length-1],()=>{n.getCanvas().style.cursor=`pointer`}),n.on(`mouseleave`,r[r.length-1],()=>{n.getCanvas().style.cursor=``})}function ze(){this.stashFeatures.clear(),this.map&&(this.map.remove(),console.log(`地图实例已移除`))}function Be(e){e.addGeoJsonSource=je,e.addVectorTileSource=ke,e.addRasterTileSource=Ae,e.updateGeoJsonSource=Ne,e.getGeoJsonSourceData=Pe,e.removeSource=Me,e.addGeoJsonLayer=Fe,e.updateLayerStyle=Ie,e.removeLayer=Le,e.onFeatureClick=Re,e.destroy=ze}var Ve=class{signalExist=!0;productInfo;stationCode;time;interlockInfo=new Map;getProductInfo(){return this.productInfo}getStCode(){return this.stationCode}getInterlockInfo(){return this.interlockInfo}isSignalExist(){return this.signalExist}setYardSignal(e){let t=e.split(`&`);this.time=t[0];let n=[],r=[],i=[];this.stationCode=t[1];let a=t[1],o=0;t.length===6&&(this.productInfo=t[2],o=1);let s=t[2],c=a+`:`+s;if(t[2+o]!==``){let e=t[2+o].split(`;`);for(let t of e){let e=t.split(`:`);n.push({name:e[0]+`:`+a,state:e[1]})}}if(t[3+o]!==``){let e=t[3+o].split(`;`);for(let t of e){let e=t.split(`:`);r.push({name:e[0]+`:`+a,state:e[1]})}}if(t[4+o]!==``){let e=t[4+o].split(`;`);for(let t of e){let e=t.split(`:`);i.push({name:e[0]+`:`+a,state:e[1]})}}this.interlockInfo.set(c,{signalInterlock:n,switchInterlock:r,circuitInterlock:i})}reset(){}resetInterlockInfo(){this.interlockInfo=new Map}},He=class{insulationSignalMap=new Map;signalInsulationMap=new Map;setInsulation(e){this.insulationSignalMap.clear(),this.signalInsulationMap.clear(),e.length===0&&console.warn(`没有绝缘节数据!`),e.forEach(e=>{let t=String(e.id??e.properties?.code??``),n=e.properties?.upSignal??null,r=e.properties?.downSignal??null,i=e.properties?.name??``;this.insulationSignalMap.set(t,{upsignal:n,downsignal:r}),n!=null&&this.signalInsulationMap.set(String(n),t+`-`+i),r!=null&&this.signalInsulationMap.set(String(r),t+`-`+i)})}getInsulationBySignalKey(e){return this.signalInsulationMap.get(e)}getSignalByInsulationKey(e){return this.insulationSignalMap.get(e)}},Ue=function(e){return e.RedLight=`red`,e.GreenLight=`green`,e.BlueLight=`blue`,e.WhiteLight=`white`,e}({}),We={1:Ue.RedLight,2:Ue.GreenLight,3:Ue.WhiteLight,4:Ue.BlueLight},Ge=class{map;layers;firstSwitches;updateFeatureState;queryGeojsonFeatures;sourceFrom;signalStore=new Ve;interLockInsulation=new He;interLockState={signal:new Map,switch:new Map,circuit:new Map};pathCircuits=[];pathCircuitsCodes=[];linkWhiteCircuits=[];signalEnable=!1;onSendSignal;stationSignalState=[];constructor(e){if(this.map=e.map,this.firstSwitches=e.firstSwitches??[],this.updateFeatureState=e.updateFeatureState,`mode`in e&&e.mode===`geojson`){let t=e.sourceIds;this.layers={signal:{sourceId:t.signal},switch:{sourceId:t.switch},switch_loc:{sourceId:t.switch_loc},track_circuit:{sourceId:t.track_circuit},track:{sourceId:t.track},insulation:{sourceId:t.insulation}},this.queryGeojsonFeatures=e.queryGeojsonFeatures,this.sourceFrom=`Geojson`}else{let t=e.sourceId,n=e.sourceLayers;this.layers={signal:{sourceId:t,sourceLayer:n.signal},switch:{sourceId:t,sourceLayer:n.switch},switch_loc:{sourceId:t,sourceLayer:n.switch_loc},track_circuit:{sourceId:t,sourceLayer:n.track_circuit},track:{sourceId:t,sourceLayer:n.track},insulation:{sourceId:t,sourceLayer:n.insulation}},this.sourceFrom=`VectorTile`}}queryFeatures(e){if(this.sourceFrom===`Geojson`&&this.queryGeojsonFeatures)return this.queryGeojsonFeatures(e);let t=this.layers[e];return this.map.querySourceFeatures(t.sourceId,t.sourceLayer?{sourceLayer:t.sourceLayer}:void 0)}setFeatureState(e,t,n){if(this.updateFeatureState)return this.updateFeatureState(t,n);let r=this.layers[e];this.map.setFeatureState(r.sourceLayer?{source:r.sourceId,sourceLayer:r.sourceLayer,id:t}:{source:r.sourceId,id:t},n)}getFeatureState(e,t){let n=this.layers[e];return this.map.getFeatureState(n.sourceLayer?{source:n.sourceId,sourceLayer:n.sourceLayer,id:t}:{source:n.sourceId,id:t})}initInsulation(){let e=this.queryFeatures(`insulation`);this.interLockInsulation.setInsulation(e)}handleSignalData(e){this.signalStore.resetInterlockInfo(),!e||e.length===0?this.signalStore.signalExist=!1:(this.signalStore.signalExist=!0,this.signalStore.setYardSignal(e)),this.signalStore.isSignalExist()&&this.signalStore.getInterlockInfo().forEach((e,t)=>{let n=t.split(`:`)[0],r=t.split(`:`)[1];this.arrToMap(this.interLockState.signal,e.signalInterlock),this.arrToMap(this.interLockState.switch,e.switchInterlock),this.arrToMap(this.interLockState.circuit,e.circuitInterlock),r===`ZK01`?this.visualizeZK(e,r,n):this.visualizeYD(e,r,n)})}turnOffSignals(){this.interLockState={signal:new Map,switch:new Map,circuit:new Map}}reset(e){this.clearCircuits(e),this.clearSwitchLocs(e)}clearCircuits(e){this.queryFeatures(`track_circuit`).forEach(t=>{t.properties?.stcode===e&&this.setFeatureState(`track_circuit`,t.properties.code,{state:``,visiable:!0})})}clearSwitchLocs(e){this.queryFeatures(`switch_loc`).forEach(t=>{t.properties?.stcode===e&&this.setFeatureState(`switch_loc`,t.properties.code,{state:``,visiable:!0})})}visualizeZK(e,t,n){this.reset(n);for(let t of e.signalInterlock){let e=t.name.split(`:`)[0],n=t.name.split(`:`)[1],r=this.getSignalFeature(e,n);r&&this.setFeatureState(`signal`,r.properties.code,{state:We[Number(t.state)],visiable:!0})}for(let t of e.switchInterlock){let e=t.name.split(`:`)[0],n=t.name.split(`:`)[1];this.getSwitchLocFeatures(e,n,t.state).forEach(e=>{this.setFeatureState(`switch_loc`,e.properties.code,{state:t.state})})}for(let t of e.circuitInterlock){let e=t.name.split(`:`)[0],n=t.name.split(`:`)[1],r=this.getCircuitFeature(e,n);r&&this.setFeatureState(`track_circuit`,r.properties.code,{state:Number(t.state),visiable:!0})}this.applyHandSwitchPaths(n,e.switchInterlock)}visualizeYD(e,t,n){this.reset(n);for(let t of e.signalInterlock){let e=t.name.split(`:`)[0],n=t.name.split(`:`)[1],r=this.getSignalFeature(e,n);r&&this.setFeatureState(`signal`,r.properties.code,{state:We[Number(t.state)],visiable:!0})}for(let t of e.switchInterlock){let e=t.name.split(`:`)[0],n=t.name.split(`:`)[1];this.getSwitchLocFeatures(e,n,t.state).forEach(e=>{this.setFeatureState(`switch_loc`,e.properties.code,{state:t.state,visiable:!0})})}this.pathCircuits=[],this.pathCircuitsCodes=[],this.linkWhiteCircuits=[];for(let t of e.circuitInterlock){let e=t.name.split(`:`)[0],n=t.name.split(`:`)[1],r=this.getCircuitFeature(e,n);r&&(this.pathCircuits.push(r),this.pathCircuitsCodes.push(String(r.properties?.code??``)))}for(let t of e.circuitInterlock){let e=t.name.split(`:`)[0],n=t.name.split(`:`)[1],r=this.getCircuitFeature(e,n);if(!r){console.warn(`没有找到对应的区段YD`,t.name,t.state);continue}if(t.state===`1`)this.setFeatureState(`track_circuit`,r.properties.code,{state:t.state,controlName:``,visiable:!0});else{let e=String(r.properties?.fromCode??``),n=String(r.properties?.toCode??``);try{let i=this.getCircuitState([e,n],null);i?(this.setFeatureState(`track_circuit`,r.properties.code,{state:i.circuitState,controlName:i.controlName,link:i.controlName===``?void 0:0,visiable:!0}),i.controlName!==``&&this.linkWhiteCircuits.push(r)):this.setFeatureState(`track_circuit`,r.properties.code,{state:t.state,visiable:!0})}catch(e){if(e instanceof Error&&e.message!==`End Loop`)throw e}}}this.queryFeatures(`track_circuit`).forEach(e=>{let t=String(e.properties?.code??``),n=this.linkWhiteCircuits.find(e=>String(e.properties?.code??``)===t);if(n){let t=this.getFeatureState(`track_circuit`,e.id);t.state!==`2`&&t.state!==2&&t.state!==`1`&&t.state!==1&&this.setFeatureState(`track_circuit`,e.properties.code,{state:2,link:1,controlName:n.properties?.controlName??``,visiable:!0})}}),this.applyHandSwitchPaths(n,e.switchInterlock)}applyHandSwitchPaths(e,t){let n=[];for(let r of this.firstSwitches)this.findHandSwitchPath(r,e,t,n,[]);n.forEach(e=>{this.setFeatureState(`track`,e,{state:5,visiable:!0})})}findHandSwitchPath(e,t,n,r,i){let a=this.findSwitchInfo(e,t,n);if(!this.validSwitchInfo(a))return;let o=this.getSwitchLocFeatures(e,t,a.state);for(let a of o){let o=String(a.properties?.t_code??``),s=String(a.properties?.s_code??``),c=this.getTrackByCode(o);if(!c)continue;let l=String(c.properties?.fromCode??``),u=String(c.properties?.toCode??``),d=c.properties?.fromLyr,f=c.properties?.toLyr,p=``,m=null;if(l===s?(p=u,m=f):u===s&&(p=l,m=d),m===2){let a=this.getSwitchByCode(p);if(a){r.push(o);let s=String(a.properties?.name??``),c=this.findSwitchInfo(s,t,n);c&&this.validSwitchInfo(c)&&!i.includes(s)&&this.doseTrackConnectSwitch(o,c)&&(i.push(e),this.findHandSwitchPath(s,t,n,r,i))}}else r.push(o)}}doseTrackConnectSwitch(e,t){let n=t.name.split(`:`)[0],r=t.name.split(`:`)[1];return this.getSwitchLocFeatures(n,r,t.state).some(t=>String(t.properties?.t_code??``)===e)}getCircuitState(e,t){let n=4,r=null;try{e.forEach((i,a)=>{let o=this.interLockInsulation.getSignalByInsulationKey(i),s=this.getInsulationSignalState(o??null);if(t==null&&s!=null&&(r=s),s==null&&t!=null&&(s={name:t.name,dir:t.dir,state:`3`}),s!=null&&s.state===`3`){n=2;let t=e.find(e=>e!==i),r=this.findNextCircuit(t,s);if(r!=null){let e=this.interLockInsulation.getSignalByInsulationKey(t);if(this.getControlSignalState(e??null,s)!=4){let e=String(r.properties?.fromCode??``),t=String(r.properties?.toCode??``),n={...r,properties:{...r.properties,controlName:s.name}};this.linkWhiteCircuits.push(n),this.getCircuitState([e,t],s)}}}})}catch(e){console.error(e)}return{circuitState:n,controlName:r==null?``:r.name}}findNextCircuit(e,t){let n=this.pathCircuits.find(n=>{let r=String(n.properties?.fromCode??``),i=String(n.properties?.toCode??``);return t.dir===`up`&&r===e||t.dir===`down`&&i===e});return n?this.linkWhiteCircuits.find(e=>String(e.properties?.code??``)===String(n.properties?.code??``))?null:n:null}getInsulationSignalState(e){if(!e)return null;if(e.upsignal){let t=this.getSignalById(String(e.upsignal));if(t){let e=String(t.properties?.name??``),n=String(t.properties?.stcode??``),r=this.interLockState.signal.get(e+`:`+n);if(r===`3`)return{name:e,state:r,dir:`up`}}}if(e.downsignal){let t=this.getSignalById(String(e.downsignal));if(t){let e=String(t.properties?.name??``),n=String(t.properties?.stcode??``),r=this.interLockState.signal.get(e+`:`+n);if(r===`3`)return{name:e,state:r,dir:`down`}}}return null}getControlSignalState(e,t){if(e){if(t.dir===`up`&&e.upsignal){let t=this.getSignalById(String(e.upsignal));if(t){let e=String(t.properties?.name??``),n=String(t.properties?.stcode??``);return this.interLockState.signal.get(e+`:`+n)}}if(t.dir===`down`&&e.downsignal){let t=this.getSignalById(String(e.downsignal));if(t){let e=String(t.properties?.name??``),n=String(t.properties?.stcode??``);return this.interLockState.signal.get(e+`:`+n)}}}}getSignalFeature(e,t){return this.queryFeatures(`signal`).find(n=>n.properties?.name===e&&String(n.properties?.code??``).includes(t))}getSignalById(e){return this.queryFeatures(`signal`).find(t=>String(t.id??t.properties?.code??``)===e)}getSwitchLocFeatures(e,t,n){let r=this.queryFeatures(`switch`).find(n=>n.properties?.name===e&&String(n.properties?.code??``).includes(t));if(!r)return[];let i=String(r.properties?.code??``),a=this.queryFeatures(`switch_loc`);return n===`4`?a.filter(e=>String(e.properties?.s_code??``)===i):a.filter(e=>String(e.properties?.s_code??``)===i&&(String(e.properties?.location??``)===n||String(e.properties?.location??``)===`1`))}getSwitchByCode(e){return this.queryFeatures(`switch`).find(t=>String(t.id??t.properties?.code??``)===e)}getTrackByCode(e){return this.queryFeatures(`track`).find(t=>String(t.id??t.properties?.code??``)===e)}getCircuitFeature(e,t){let n=this.queryFeatures(`track_circuit`).filter(n=>n.properties?.name===e&&String(n.properties?.code??``).includes(t));if(n.length===0)return;let r;if(n.length>=1&&(n[0].properties?.type===`1`||n[0].properties?.type===1))return n[0];for(let e of n){if(r)break;if(e.properties?.type===2||e.properties?.type===`2`){let t=String(e.properties?.switches??``).split(`,`),n=String(e.properties?.positions??``).replace(/\s+/g,``).split(`,`).filter(e=>e!==`1`);for(let i=0;i<t.length;i++){let a=t[i],o=n[i],s=this.getSwitchNameByCode(a);if(!s||o!==this.interLockState.switch.get(s+`:`+a.substring(0,9)))break;if(i==t.length-1){r=e;break}}}}return r}getSwitchNameByCode(e){let t=this.queryFeatures(`switch`).find(t=>String(t.properties?.code??``)===e);return t?String(t.properties?.name??``):void 0}findSwitchInfo(e,t,n){let r=e+`:`+t;return n.find(e=>e.name===r)??null}validSwitchInfo(e){return e?e.state===`2`||e.state===`3`:!1}arrToMap(e,t){t?.forEach(t=>e.set(t.name,t.state))}startRunning(){this.signalEnable=!0}stopRunning(){this.signalEnable=!1}setSendSignalCallback(e){this.onSendSignal=e}setStationSignalState(e){this.stationSignalState=e}sendSignal(){if(!this.signalEnable||this.interLockState.signal.size===0&&this.interLockState.switch.size===0&&this.interLockState.circuit.size===0)return;let e=Math.floor(Date.now()/1e3),t=new Map,n=[];this.interLockState.signal.forEach((e,n)=>{let r=n.split(`:`)[0],i=n.split(`:`)[1],a=t.get(i);a=a?a+r+`:`+e+`;`:r+`:`+e+`;`,t.set(i,a)}),t.forEach((e,n)=>{t.set(n,(e.endsWith(`;`)?e.slice(0,-1):e)+`&`)}),this.interLockState.switch.forEach((e,n)=>{let r=n.split(`:`)[0],i=n.split(`:`)[1],a=Number(e),o=t.get(i);if(o!==void 0)if(a===5||a===6){let t=a===5?2:3;o+=r+`:`+t+`;`,o+=r+`-F:`+e+`;`}else o+=r+`:`+e+`;`;else if(a===5||a===6){let t=a===5?2:3;o=`&`+r+`:`+t+`;`,o+=r+`-F:`+e+`;`}else o=`&`+r+`:`+e+`;`;t.set(i,o)}),t.forEach((e,n)=>{t.set(n,(e.endsWith(`;`)?e.slice(0,-1):e)+`&`)});let r=new Map;this.interLockState.circuit.forEach((e,t)=>{let n=t.split(`:`)[0],i=t.split(`:`)[1],a=i+`_`+n;r.get(a)?(e===`1`||e===`2`)&&r.set(a,{name:n,yard:i,state:e}):r.set(a,{name:n,yard:i,state:e})}),r.forEach(e=>{let n=t.get(e.yard);n=n?n+e.name+`:`+e.state+`;`:`& &`+e.name+`:`+e.state+`;`,t.set(e.yard,n)}),t.forEach((t,r)=>{let i=t.endsWith(`;`)?t.slice(0,-1):t;n.push(e+`&`+r+`&`+i)}),n.length>0&&this.onSendSignal?.(n)}pauseSignal(){this.interLockState.circuit.forEach((e,t)=>this.interLockState.circuit.set(t,`0`)),this.interLockState.signal.forEach((e,t)=>this.interLockState.signal.set(t,`0`)),this.interLockState.switch.forEach((e,t)=>this.interLockState.switch.set(t,`0`)),this.sendSignal()}collectStateAndSend(){if(!this.signalEnable)return;let e=Math.floor(Date.now()/1e3),t=new Map,n=[],r={red:`1`,green:`2`,white:`3`,blue:`4`};for(let e of this.queryFeatures(`signal`)){let n=String(e.properties?.name??``),i=String(e.properties?.code??``),a=String(e.properties?.stcode??i.substring(0,9));if(!n||!i||!a||!this.stationSignalState.includes(a))continue;let o=String(this.getFeatureState(`signal`,i)?.state??``);if(!o)continue;let s=r[o]??o,c=t.get(a);t.set(a,c?c+n+`:`+s+`;`:n+`:`+s+`;`)}t.forEach((e,n)=>t.set(n,(e.endsWith(`;`)?e.slice(0,-1):e)+`&`));let i=this.queryFeatures(`switch_loc`);for(let e of this.queryFeatures(`switch`)){let n=String(e.properties?.name??``),r=String(e.properties?.code??``),a=String(e.properties?.stcode??r.substring(0,9));if(!n||!r||!a||!this.stationSignalState.includes(a))continue;let o=i.find(e=>String(e.properties?.s_code??``)===r&&String(e.properties?.location??``)===`1`)??i.find(e=>String(e.properties?.s_code??``)===r);if(!o)continue;let s=String(this.getFeatureState(`switch_loc`,String(o.properties?.code??``))?.state??``);if(!s)continue;let c=Number(s),l=t.get(a);l===void 0?l=`&`+(c===5||c===6?n+`:`+(c===5?2:3)+`;`+n+`-F:`+s+`;`:n+`:`+s+`;`):l+=c===5||c===6?n+`:`+(c===5?2:3)+`;`+n+`-F:`+s+`;`:n+`:`+s+`;`,t.set(a,l)}t.forEach((e,n)=>t.set(n,(e.endsWith(`;`)?e.slice(0,-1):e)+`&`));let a=new Map;for(let e of this.queryFeatures(`track_circuit`)){let t=String(e.properties?.name??``),n=String(e.properties?.code??``),r=String(e.properties?.stcode??n.substring(0,9));if(!t||!n||!r||!this.stationSignalState.includes(r))continue;let i=String(this.getFeatureState(`track_circuit`,n)?.state??``);if(!i)continue;let o=r+`_`+t;a.get(o)?(i===`1`||i===`2`)&&a.set(o,{name:t,stcode:r,state:i}):a.set(o,{name:t,stcode:r,state:i})}a.forEach(e=>{let n=t.get(e.stcode);t.set(e.stcode,n?n+e.name+`:`+e.state+`;`:`& &`+e.name+`:`+e.state+`;`)}),t.forEach((t,r)=>{let i=t.endsWith(`;`)?t.slice(0,-1):t;n.push(e+`&`+r+`&`+i)}),n.length>0&&this.onSendSignal?.(n)}};function Ke(){if(!this.mapConfigs)return;let e=this.mapConfigs.id;this.mapConfigs.sourceLayers?.forEach(t=>{(t.includes(`switch`)||t.includes(`signal`)||t.includes(`track`))&&this.map.querySourceFeatures(e,{sourceLayer:t}).forEach(e=>{this.initGraphFeatureState(e)})})}function qe(e){if(!e||e.length<11)return``;let t=e.charAt(10),n=e.charAt(9);return t===`1`&&n===`0`?`track`:t===`3`?`signal`:t===`2`&&n===`0`||t===`1`&&n===`1`?`switch`:t===`2`&&n===`1`?`circuit`:``}function Je(e){if(!e)return;let t=e.properties.code,n=qe(t);if(n===`switch`){let t={state:``,visiable:!0};t.state=`2`;let n=e.properties;this.updateFeatureState(n.code,t)}else if(n===`signal`){let t=e.properties,n=t.attach||0,r=t.func_type,i={state:``,visiable:!0};r==1&&n==0||(r==2||r==3)&&n==0||(r==2||r==3||r==11)&&n==1?(i.state=`red`,this.updateFeatureState(t.code,i)):(r==4||r==5||r==12)&&n==0?(i.state=`blue`,this.updateFeatureState(t.code,i)):r==6&&n==0||(r==7||r==11)&&n==0?(i.state=`red`,this.updateFeatureState(t.code,i)):(i.state=``,this.updateFeatureState(t.code,i))}else if(n===`signal`||n===`circuit`){let t={state:``,visiable:!0},n=e.properties;this.updateFeatureState(n.code,t)}}function Ye(e){if(!e.mapConfigs)return;let t=e.mapConfigs.id,n=e.mapConfigs.layers?.reduce((t,n,r)=>(t[n]=e.mapConfigs.sourceLayers[r],t),{});if(n)return new Ge({map:e.map,sourceId:t,sourceLayers:n,updateFeatureState:(t,n)=>e.updateFeatureState(t,n)})}function Xe(e){e.initGraphFeatureState=Je,e.initState=Ke,e.interLockVisualization=Ye(e),e.map.once(`idle`,()=>{})}function Ze(){this.mapConfigs&&(this.mapConfigs.layers??[]).forEach(e=>{let t=`geojson_${e}`;this.map.getSource(t)&&this.stashFeatures.forEach(n=>{n.sourceLayer!==t||!n.properties||this.initGeoJsonFeatureState({properties:n.properties},e)})})}function Qe(e,t){if(!e)return;let n=e.properties,r=n?.code;if(r)if(t===`switch`||t===`switch_loc`)this.updateFeatureState(r,{state:`2`,visiable:!0});else if(t===`signal`){let e=n?.attach||0,t=n?.functionType,i={state:``,visiable:!0};t==1&&e==0||(t==2||t==3)&&e==0||(t==2||t==3||t==11)&&e==1||t==6&&e==0||(t==7||t==11)&&e==0?i.state=`red`:(t==4||t==5||t==12)&&e==0&&(i.state=`blue`),this.updateFeatureState(r,i)}else t===`track_circuit`&&this.updateFeatureState(r,{state:4,substate:1,visiable:!0})}function $e(e){if(!e.mapConfigs)return;let t=[`signal`,`switch`,`switch_loc`,`track_circuit`,`track`,`insulation`].reduce((e,t)=>(e[t]=`geojson_${t}`,e),{});return new Ge({mode:`geojson`,map:e.map,sourceIds:t,updateFeatureState:(t,n)=>e.updateFeatureState(t,n),queryGeojsonFeatures:t=>e.queryGeojsonFeatures(t)})}function et(e){e.initGeoJsonFeatureState=Qe,e.initGeoJsonState=Ze,e.interLockVisualization=$e(e),e.map.once(`idle`,()=>{})}function O(){return O=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},O.apply(null,arguments)}var k=`draw`,tt=`edit`,nt=`deleteCoordinate`,rt=`insertMidpoint`,A;(function(e){e.Commit=`commit`,e.Provisional=`provisional`,e.Finish=`finish`})(A||={});var it=`https://raw.githubusercontent.com/JamesLMilner/terra-draw/refs/heads/main/assets/markers/marker-blue.png`,j={SELECTED:`selected`,MID_POINT:`midPoint`,SELECTION_POINT_FEATURE_ID:`selectionPointFeatureId`,SELECTION_POINT:`selectionPoint`},M={MODE:`mode`,CURRENTLY_DRAWING:`currentlyDrawing`,EDITED:`edited`,CLOSING_POINT:`closingPoint`,SNAPPING_POINT:`snappingPoint`,COORDINATE_POINT:`coordinatePoint`,COORDINATE_POINT_FEATURE_ID:`coordinatePointFeatureId`,COORDINATE_POINT_IDS:`coordinatePointIds`,PROVISIONAL_COORDINATE_COUNT:`provisionalCoordinateCount`,COMMITTED_COORDINATE_COUNT:`committedCoordinateCount`,MARKER:`marker`},N=10;function at(e){return!!(e&&typeof e==`object`&&e&&!Array.isArray(e))}function ot(e){return!!(e&&typeof e==`object`&&`properties`in e&&typeof e.properties==`object`&&e.properties!==null&&`mode`in e.properties)}function st(e){return!!function(e){return typeof e==`number`&&!isNaN(new Date(e).valueOf())}(e)}var ct=`Feature mode property does not match the mode being added to`,lt;(function(e){e.Drawing=`drawing`,e.Select=`select`,e.Static=`static`,e.Render=`render`})(lt||={});var ut={rightClick:!0,contextMenu:!1,leftClick:!0,onDragStart:!0,onDrag:!0,onDragEnd:!0},P=class{get state(){return this._state}set state(e){throw Error(`Please use the modes lifecycle methods`)}get styles(){return this._styles}set styles(e){if(typeof e!=`object`)throw Error(`Styling must be an object`);this.onStyleChange&&this.onStyleChange([],`styling`),this._styles=e}registerBehaviors(e){}constructor(e,t=!1){this._state=`unregistered`,this._styles={},this.pointerEvents=ut,this.behaviors=[],this.validate=void 0,this.pointerDistance=40,this.coordinatePrecision=void 0,this.undoRedoMaxStackSize=void 0,this.onStyleChange=void 0,this.store=void 0,this.projection=`web-mercator`,this.setDoubleClickToZoom=void 0,this.unproject=void 0,this.project=void 0,this.setCursor=void 0,this.isInitialUpdate=!1,this.type=lt.Drawing,this.mode=`base`,t?this.isInitialUpdate=!0:this.updateOptions(O({},e))}updateOptions(e){e!=null&&e.styles&&(this.styles=O({},this._styles,e.styles)),e!=null&&e.pointerDistance&&(this.pointerDistance=e.pointerDistance),e!=null&&e.validation&&(this.validate=e&&e.validation),e!=null&&e.projection&&(this.projection=e.projection),e?.pointerEvents!==void 0&&(this.pointerEvents=e.pointerEvents),e!=null&&e.modeName&&!0===this.isInitialUpdate&&(this.mode=e.modeName),this.isInitialUpdate=!1}allowPointerEvent(e,t){return typeof e==`boolean`?e:typeof e!=`function`||e(t)}setDrawing(){if(this._state!==`started`)throw Error(`Mode must be unregistered or stopped to start`);this._state=`drawing`}setStarted(){if(this._state!==`stopped`&&this._state!==`registered`&&this._state!==`drawing`&&this._state!==`selecting`)throw Error(`Mode must be unregistered or stopped to start`);this._state=`started`,this.setDoubleClickToZoom(!1)}setStopped(){if(this._state!==`started`)throw Error(`Mode must be started to be stopped`);this._state=`stopped`,this.setDoubleClickToZoom(!0)}register(e){if(this._state!==`unregistered`)throw Error(`Can not register unless mode is unregistered`);this._state=`registered`,this.store=e.store,this.store.registerOnChange(e.onChange),this.setDoubleClickToZoom=e.setDoubleClickToZoom,this.project=e.project,this.unproject=e.unproject,this.onSelect=e.onSelect,this.onDeselect=e.onDeselect,this.setCursor=e.setCursor,this.onStyleChange=e.onChange,this.onFinish=e.onFinish,this.coordinatePrecision=e.coordinatePrecision,this.undoRedoMaxStackSize=e.undoRedoMaxStackSize,this.registerBehaviors({mode:e.mode,store:this.store,project:this.project,unproject:this.unproject,pointerDistance:this.pointerDistance,coordinatePrecision:e.coordinatePrecision,projection:this.projection,undoRedoMaxStackSize:e.undoRedoMaxStackSize})}validateFeature(e){return this.performFeatureValidation(e)}afterFeatureAdded(e){}afterFeatureUpdated(e){}performFeatureValidation(e){if(this._state===`unregistered`)throw Error(`Mode must be registered`);let t=function(e,t){let n;if(at(e))if(e.id==null)n=`Feature has no id`;else if(typeof e.id!=`string`&&typeof e.id!=`number`)n=`Feature must be string or number as per GeoJSON spec`;else if(t(e.id))if(at(e.geometry))if(at(e.properties))if(typeof e.geometry.type==`string`&&[`Polygon`,`LineString`,`Point`].includes(e.geometry.type))if(Array.isArray(e.geometry.coordinates)){if(!e.properties.mode||typeof e.properties.mode!=`string`)return{valid:!1,reason:`Feature does not have a valid mode property`}}else n=`Feature coordinates is not an array`;else n=`Feature is not Point, LineString or Polygon`;else n=`Feature has no properties`;else n=`Feature has no geometry`;else n=`Feature must match the id strategy (default is UUID4)`;else n=`Feature is not object`;return n?{valid:!1,reason:n}:{valid:!0}}(e,this.store.idStrategy.isValidId);if(!t.valid)return t;if(this.validate){let n=this.validate(e,{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:A.Provisional});return{valid:t.valid&&n.valid,reason:n.reason}}return{valid:t.valid,reason:t.reason}}validateModeFeature(e,t){let n=this.performFeatureValidation(e);return n.valid?e.properties.mode===this.mode?t(e):{valid:!1,reason:ct}:{valid:!1,reason:n.reason}}onFinish(e,t){}onDeselect(e){}onSelect(e){}onKeyDown(e){}onKeyUp(e){}undo(){}clearHistory(){}undoSize(){return 0}redoSize(){return 0}redo(){}onMouseMove(e){}onClick(e){}onDragStart(e,t){}onDrag(e,t){}onDragEnd(e,t){}getHexColorStylingValue(e,t,n){return this.getStylingValue(e,t,n)}getNumericStylingValue(e,t,n){return this.getStylingValue(e,t,n)}getUrlStylingValue(e,t,n){return this.getStylingValue(e,t,n)}getStylingValue(e,t,n){return e===void 0?t:typeof e==`function`?(r=e(n))??t:e;var r}},dt=class extends P{constructor(...e){super(...e),this.type=lt.Select}};function F(e,t){let n=e=>e*Math.PI/180,r=n(e[1]),i=n(e[0]),a=n(t[1]),o=a-r,s=n(t[0])-i,c=Math.sin(o/2)*Math.sin(o/2)+Math.cos(r)*Math.cos(a)*Math.sin(s/2)*Math.sin(s/2);return 2*Math.atan2(Math.sqrt(c),Math.sqrt(1-c))*6371e3/1e3}var ft=6371008.8;function I(e){return e%360*Math.PI/180}function pt(e){return e/6371.0088}function L(e){return e%(2*Math.PI)*180/Math.PI}function R(e,t=9){let n=10**t;return Math.round(e*n)/n}var mt=57.29577951308232,ht=.017453292519943295,gt=6378137,z=(e,t)=>({x:e===0?0:e*ht*gt,y:t===0?0:Math.log(Math.tan(Math.PI/4+t*ht/2))*gt}),B=(e,t)=>({lng:e===0?0:e/gt*mt,lat:t===0?0:(2*Math.atan(Math.exp(t/gt))-Math.PI/2)*mt});function _t(e,t,n){let r=I(e[0]),i=I(e[1]),a=I(n),o=pt(t),s=Math.asin(Math.sin(i)*Math.cos(o)+Math.cos(i)*Math.sin(o)*Math.cos(a));return[L(r+Math.atan2(Math.sin(a)*Math.sin(o)*Math.cos(i),Math.cos(o)-Math.sin(i)*Math.sin(s))),L(s)]}function vt(e){let{center:t,radiusKilometers:n,coordinatePrecision:r}=e,i=e.steps?e.steps:64,a=[];for(let e=0;e<i;e++){let o=_t(t,n,-360*e/i);a.push([R(o[0],r),R(o[1],r)])}return a.push(a[0]),{type:`Feature`,geometry:{type:`Polygon`,coordinates:[a]},properties:{}}}function yt(e){let t;if(e.geometry.type===`Polygon`)t=e.geometry.coordinates;else{if(e.geometry.type!==`LineString`)throw Error(`Self intersects only accepts Polygons and LineStrings`);t=[e.geometry.coordinates]}let n=[];for(let e=0;e<t.length;e++)for(let n=0;n<t[e].length-1;n++)for(let r=0;r<t.length;r++)for(let a=0;a<t[r].length-1;a++)i(e,n,r,a);return n.length>0;function r(e){return e<0||e>1}function i(e,i,a,o){let s=t[e][i],c=t[e][i+1],l=t[a][o],u=t[a][o+1],d=function(e,t,n,r){if(bt(e,n)||bt(e,r)||bt(t,n)||bt(r,n))return null;let i=e[0],a=e[1],o=t[0],s=t[1],c=n[0],l=n[1],u=r[0],d=r[1],f=(i-o)*(l-d)-(a-s)*(c-u);return f===0?null:[((i*s-a*o)*(c-u)-(i-o)*(c*d-l*u))/f,((i*s-a*o)*(l-d)-(a-s)*(c*d-l*u))/f]}(s,c,l,u);if(d===null)return;let f,p;f=c[0]===s[0]?(d[1]-s[1])/(c[1]-s[1]):(d[0]-s[0])/(c[0]-s[0]),p=u[0]===l[0]?(d[1]-l[1])/(u[1]-l[1]):(d[0]-l[0])/(u[0]-l[0]),r(f)||r(p)||(d.toString(),n.push(d))}}function bt(e,t){return e[0]===t[0]&&e[1]===t[1]}function xt(e,t){return Ct(e[0])<=t&&Ct(e[1])<=t}function St(e){return e.length===2&&typeof e[0]==`number`&&typeof e[1]==`number`&&e[0]!==1/0&&e[1]!==1/0&&(n=e[0])>=-180&&n<=180&&(t=e[1])>=-90&&t<=90;var t,n}function Ct(e){let t=1,n=0;for(;Math.round(e*t)/t!==e;)t*=10,n++;return n}var wt=`Feature has holes`,Tt=`Feature has less than 4 coordinates`,Et=`Feature has invalid coordinates`,Dt=`Feature coordinates are not closed`;function Ot(e,t){if(e.geometry.type!==`Polygon`)return{valid:!1,reason:`Feature is not a Polygon`};if(e.geometry.coordinates.length!==1)return{valid:!1,reason:wt};if(e.geometry.coordinates[0].length<4)return{valid:!1,reason:Tt};for(let n=0;n<e.geometry.coordinates[0].length;n++){if(!St(e.geometry.coordinates[0][n]))return{valid:!1,reason:Et};if(!xt(e.geometry.coordinates[0][n],t))return{valid:!1,reason:`Feature has coordinates with excessive precision`}}return(n=e.geometry.coordinates[0][0])[0]!==(r=e.geometry.coordinates[0][e.geometry.coordinates[0].length-1])[0]||n[1]!==r[1]?{valid:!1,reason:Dt}:{valid:!0};var n,r}function kt(e,t){let n=Ot(e,t);return n.valid?yt(e)?{valid:!1,reason:`Feature intersects itself`}:{valid:!0}:n}var V=class{constructor({store:e,mode:t,project:n,unproject:r,pointerDistance:i,coordinatePrecision:a,projection:o,undoRedoMaxStackSize:s}){this.store=void 0,this.mode=void 0,this.project=void 0,this.unproject=void 0,this.pointerDistance=void 0,this.coordinatePrecision=void 0,this.projection=void 0,this.undoRedoMaxStackSize=void 0,this.store=e,this.mode=t,this.project=n,this.unproject=r,this.pointerDistance=i,this.coordinatePrecision=a,this.projection=o,this.undoRedoMaxStackSize=s}};function At(e){if(!function(e){let t=e.coordinates[0],n=0;for(let e=0;e<t.length-1;e++){let[r,i]=t[e],[a,o]=t[e+1];n+=(a-r)*(o+i)}return n<0}(e))return{type:`Polygon`,coordinates:[e.coordinates[0].reverse()]}}var jt=`insert-before`,Mt=`insert-after`,H=`update`,Nt=`delete`,U=`replace`,W=class extends V{constructor(e,t){super(e),this.options=void 0,this.options=t}createPoint({coordinates:e,properties:t,context:n}){if(n?.updateType!==A.Finish||this.validateGeometryWithUpdateType({geometry:{type:`Point`,coordinates:e},properties:t,updateType:A.Finish}))return this.handleCreateFeature({geometry:{type:`Point`,coordinates:e},properties:t})}createLineString({coordinates:e,properties:t}){return this.handleCreateFeature({geometry:{type:`LineString`,coordinates:e},properties:t})}createPolygon({coordinates:e,properties:t}){let n=At({type:`Polygon`,coordinates:[e]});return this.handleCreateFeature({geometry:{type:`Polygon`,coordinates:n?n.coordinates:[e]},properties:t})}createGuidancePoint({coordinate:e,type:t}){return this.createGuidancePoints({coordinates:[e],type:t})[0]}createGuidancePoints({coordinates:e,type:t,additionalProperties:n}){let r=e.map((e,r)=>({type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:O({mode:this.mode,[t]:!0},n?n(r):{})}));return this.createFeatures(r)}updatePoint({featureId:e,coordinateMutations:t,propertyMutations:n,context:r}){return this.handleMutateFeature({type:`Point`,featureId:e,coordinateMutations:t,propertyMutations:n,context:r})}updatePolygon({featureId:e,coordinateMutations:t,context:n,propertyMutations:r}){return this.handleMutateFeature({type:`Polygon`,featureId:e,coordinateMutations:t,propertyMutations:r,context:n})}updateLineString({featureId:e,coordinateMutations:t,context:n,propertyMutations:r}){return this.handleMutateFeature({type:`LineString`,featureId:e,coordinateMutations:t,propertyMutations:r,context:n})}deleteFeatureIfPresent(e){e&&this.store.has(e)&&this.store.delete([e])}deleteFeaturesIfPresent(e){if(e.length===0)return;let t=e.filter(e=>this.store.has(e));t.length&&this.store.delete(t)}setDeselected(e){let t=e.filter(e=>this.store.has(e)).map(e=>({featureId:e,properties:{[j.SELECTED]:!1}}));this.updateFeatureProperties(t)}setSelected(e){let{type:t}=this.store.getGeometryCopy(e),n={featureId:e,propertyMutations:{[j.SELECTED]:!0},context:{updateType:A.Commit}};t===`Polygon`?this.updatePolygon(n):t===`LineString`?this.updateLineString(n):t===`Point`&&this.updatePoint(n)}updateGuidancePoints(e){this.updateFeatureGeometries(e.map(({featureId:e,coordinate:t})=>({id:e,geometry:{type:`Point`,coordinates:t}})))}handleCreateFeature({geometry:e,properties:t}){return this.createFeatureWithGeometry({geometry:e,properties:t})}handleMutateFeature({type:e,featureId:t,coordinateMutations:n,propertyMutations:r,context:i}){if(!this.mutateFeature({type:e,featureId:t,coordinateMutations:n,propertyMutations:r,context:i.updateType===A.Finish?O({},i,{correctRightHandRule:!0}):O({},i)}))return null;let a=this.buildFeatureWithGeometry(t);return i.updateType!==A.Finish||n||this.validateGeometryWithUpdateType({geometry:a.geometry,properties:a.properties,updateType:i.updateType})?a:null}mutateFeature({type:e,featureId:t,coordinateMutations:n,propertyMutations:r,context:i}){if(!t)return!1;let a=this.store.getGeometryCopy(t),o=this.store.getPropertiesCopy(t);if(a.type!==e)throw Error(`${e} geometries cannot be updated on features with ${a.type} geometries`);if(n){let e=this.applyCoordinateMutations(a,n);if(i.correctRightHandRule&&e.type===`Polygon`){let t=At(e);t&&(e=t)}if(!this.validateGeometryWithUpdateType({geometry:e,properties:o,updateType:i.updateType}))return!1;this.updateFeatureGeometries([{id:t,geometry:e}])}return r&&this.updateFeatureProperties([{featureId:t,properties:r}]),!0}applyCoordinateMutations(e,t){if(this.isReplaceMutation(t))return O({},e,{coordinates:t.coordinates});if(e.type===`Point`)throw Error(`Coordinate mutations are not supported for Point geometries`);let n=e.type===`Polygon`,r=n?e.coordinates[0].slice():e.coordinates.slice(),i=r.length,a=e=>{let t=e<0?i+e:e;if(t<0||t>=i)throw RangeError(`Index ${e} (normalized to ${t}) is out of bounds`);return t},o=Array(i).fill(void 0),s=Array.from({length:i},()=>[]),c=Array.from({length:i},()=>[]),l=[];for(let e of t){if(e.type===jt||e.type===Mt){let t=e.index,n=t<0?i+t:t;if(n<0||n>i)throw RangeError(`Index ${e.index} (normalized to ${n}) is out of bounds`);if(e.type===jt){if(n>=i)throw RangeError(`INSERT_BEFORE index ${e.index} (normalized to ${n}) is out of bounds for length ${i}`);s[n].push(e)}else n===i?l.push(e):c[n].push(e);continue}let t=a(e.index);o[t]=O({},e,{index:t})}let u=[];for(let e=0;e<i;e++){let t=s[e];for(let e of t)u.push(e.coordinate);let n=o[e];n?n.type===Nt||u.push(n.coordinate):u.push(r[e]);let i=c[e];for(let e of i)u.push(e.coordinate)}for(let e of l)u.push(e.coordinate);return O({},e,n?{coordinates:[u,...e.coordinates.slice(1)]}:{coordinates:u})}isReplaceMutation(e){return e.type===U}createFeatureWithGeometry({geometry:e,properties:t}){let[n]=this.createFeatures([{type:`Feature`,geometry:e,properties:t}]);return{id:n,type:`Feature`,properties:this.store.getPropertiesCopy(n),geometry:this.store.getGeometryCopy(n)}}validateGeometryWithUpdateType({geometry:e,properties:t,updateType:n}){return!this.options.validate||this.options.validate({type:`Feature`,geometry:e,properties:t||{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:n}).valid}buildFeatureWithGeometry(e){return{id:e,type:`Feature`,properties:this.store.getPropertiesCopy(e),geometry:this.store.getGeometryCopy(e)}}createFeatures(e){return this.store.create(e)}updateFeatureGeometries(e){this.store.updateGeometry(e)}updateFeatureProperties(e){let t=e.map(({featureId:e,properties:t})=>Object.entries(t).map(([t,n])=>({id:e,property:t,value:n}))).flat();this.store.updateProperty(t)}},Pt={cancel:`Escape`,finish:`Enter`},Ft={start:`crosshair`},It=class extends P{constructor(e){super(e,!0),this.mode=`circle`,this.center=void 0,this.endPosition=void 0,this.segments=64,this.currentCircleId=void 0,this.keyEvents=Pt,this.cursors=Ft,this.startingRadiusKilometers=1e-5,this.cursorMovedAfterInitialCursorDown=!1,this.drawInteraction=`click-move`,this.drawType=void 0,this.mutateFeature=void 0,this.updateOptions(e)}updateOptions(e){super.updateOptions(e),e!=null&&e.cursors&&(this.cursors=O({},this.cursors,e.cursors)),e?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:e!=null&&e.keyEvents&&(this.keyEvents=O({},this.keyEvents,e.keyEvents)),e!=null&&e.startingRadiusKilometers&&(this.startingRadiusKilometers=e.startingRadiusKilometers),e!=null&&e.drawInteraction&&(this.drawInteraction=e.drawInteraction),e!=null&&e.segments&&(this.segments=e.segments<3?3:e.segments)}close(){if(this.currentCircleId===void 0||this.endPosition===void 0||!this.updateCircle(this.endPosition,A.Finish))return;let e=this.currentCircleId;this.cursorMovedAfterInitialCursorDown=!1,this.center=void 0,this.currentCircleId=void 0,this.drawType=void 0,this.state===`drawing`&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:k})}beginDrawing(e,t=`click`){this.center=[e.lng,e.lat],this.endPosition=[e.lng,e.lat];let n=vt({center:this.center,radiusKilometers:this.startingRadiusKilometers,coordinatePrecision:this.coordinatePrecision}),r=this.mutateFeature.createPolygon({coordinates:n.geometry.coordinates[0],properties:{mode:this.mode,radiusKilometers:this.startingRadiusKilometers,[M.CURRENTLY_DRAWING]:!0}});r&&(this.currentCircleId=r.id,this.cursorMovedAfterInitialCursorDown=!1,this.drawType=t,this.setDrawing())}dragDrawAllowed(){return this.drawInteraction===`click-drag`||this.drawInteraction===`click-move-or-drag`}moveDrawAllowed(){return this.drawInteraction===`click-move`||this.drawInteraction===`click-move-or-drag`}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onClick(e){this.moveDrawAllowed()&&(e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e))&&(this.center?this.center&&this.currentCircleId!==void 0&&(this.endPosition=[e.lng,e.lat],this.close()):this.beginDrawing(e))}onMouseMove(e){this.cursorMovedAfterInitialCursorDown=!0,this.endPosition=[e.lng,e.lat],this.updateCircle(this.endPosition,A.Provisional)}onKeyDown(){}onKeyUp(e){e.key===this.keyEvents.cancel?this.cleanUp():e.key===this.keyEvents.finish&&this.close()}onDragStart(e,t){this.state!==`drawing`&&this.allowPointerEvent(this.pointerEvents.onDragStart,e)&&this.dragDrawAllowed()&&(this.beginDrawing(e,`drag`),t(!1))}onDrag(e,t){this.allowPointerEvent(this.pointerEvents.onDrag,e)&&this.dragDrawAllowed()&&this.drawType===`drag`&&(this.cursorMovedAfterInitialCursorDown=!0,this.endPosition=[e.lng,e.lat],this.updateCircle(this.endPosition,A.Provisional))}onDragEnd(e,t){this.allowPointerEvent(this.pointerEvents.onDragEnd,e)&&this.dragDrawAllowed()&&this.drawType===`drag`&&(this.endPosition=[e.lng,e.lat],this.close(),t(!0))}cleanUp(){let e=this.currentCircleId;this.center=void 0,this.currentCircleId=void 0,this.drawType=void 0,this.state===`drawing`&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(e)}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return e.type===`Feature`&&e.geometry.type===`Polygon`&&e.properties.mode===this.mode?(t.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,t.polygonFillColor,e),t.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,t.polygonOutlineColor,e),t.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,t.polygonOutlineWidth,e),t.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,e),t.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,t.polygonFillOpacity,e),t.zIndex=N,t):t}validateFeature(e){return this.validateModeFeature(e,e=>kt(e,this.coordinatePrecision))}updateCircle(e,t){if(this.currentCircleId===void 0||this.center===void 0)return;let n=t===A.Finish,r,i;if(this.cursorMovedAfterInitialCursorDown)if(i=F(this.center,e),this.projection===`web-mercator`){let t=function(e,t){let n=1e3*F(e,t);if(n===0)return 1;let{x:r,y:i}=z(e[0],e[1]),{x:a,y:o}=z(t[0],t[1]);return Math.sqrt((a-r)**2+(o-i)**2)/n}(this.center,e);r=function(e){let{center:t,radiusKilometers:n,coordinatePrecision:r}=e,i=e.steps?e.steps:64,a=1e3*n,[o,s]=t,{x:c,y:l}=z(o,s),u=[];for(let e=0;e<i;e++){let t=360*e/i*Math.PI/180,n=a*Math.cos(t),o=a*Math.sin(t),[s,d]=[c+n,l+o],{lng:f,lat:p}=B(s,d);u.push([R(f,r),R(p,r)])}return u.push(u[0]),{type:`Feature`,geometry:{type:`Polygon`,coordinates:[u]},properties:{}}}({center:this.center,radiusKilometers:i*t,coordinatePrecision:this.coordinatePrecision,steps:this.segments})}else{if(this.projection!==`globe`)throw Error(`Invalid projection`);r=vt({center:this.center,radiusKilometers:i,coordinatePrecision:this.coordinatePrecision,steps:this.segments})}let a={};return r&&i&&(a.radiusKilometers=i),n&&(a[M.CURRENTLY_DRAWING]=void 0),this.mutateFeature.updatePolygon({featureId:this.currentCircleId,coordinateMutations:r?{type:U,coordinates:r.geometry.coordinates}:void 0,propertyMutations:a,context:n?{updateType:t,action:k}:{updateType:t}})}afterFeatureUpdated(e){this.currentCircleId===e.id&&(this.cursorMovedAfterInitialCursorDown=!1,this.center=void 0,this.currentCircleId=void 0,this.drawType=void 0,this.state===`drawing`&&this.setStarted())}registerBehaviors(e){this.mutateFeature=new W(e,{validate:this.validate})}},G=(e,t)=>{let{x:n,y:r}=e,{x:i,y:a}=t,o=i-n,s=a-r;return Math.sqrt(s*s+o*o)};function Lt(e,t){return e[0]===t[0]&&e[1]===t[1]}var K=class extends V{constructor(e){super(e)}getGeometryType(e){return this.store.getGeometryCopy(e).type}coordinateAtIndexIsIdentical({featureId:e,newCoordinate:t,index:n}){let r=this.store.getGeometryCopy(e),i;if(r.type===`Polygon`)i=r.coordinates[0][n];else if(r.type===`LineString`)i=r.coordinates[n];else{if(n!==0)throw Error(`Point geometries only have one coordinate at index 0`);i=r.coordinates}return Lt(t,i)}getGeometry(e){return this.store.getGeometryCopy(e)}getCoordinates(e){let{type:t,coordinates:n}=this.store.getGeometryCopy(e);return t===`Polygon`?n[0]:n}getCoordinate(e,t){let n=this.getCoordinates(e),r=t<0?n.length+t:t;if(r<0||r>=n.length)throw RangeError(`Index ${t} (normalized to ${r}) is out of bounds`);return n[r]}getProperties(e){return this.store.getPropertiesCopy(e)}hasFeature(e){return this.store.has(e)}getAllFeatureIdsWhere(e){return this.store.copyAllWhere(e).map(({id:e})=>e)}},Rt={cancel:`Escape`,finish:`Enter`},zt={start:`crosshair`,close:`pointer`},Bt=class extends P{constructor(e){super(e,!0),this.mode=`freehand`,this.canClose=!1,this.currentId=void 0,this.closingPointId=void 0,this.minDistance=20,this.keyEvents=Rt,this.cursors=zt,this.preventPointsNearClose=!0,this.autoClose=!1,this.autoCloseTimeout=500,this.hasLeftStartingPoint=!1,this.preventNewFeature=!1,this.drawInteraction=`click-move`,this.drawType=void 0,this.smoothing=0,this.mutateFeature=void 0,this.readFeature=void 0,this.updateOptions(e)}updateOptions(e){super.updateOptions(e),e!=null&&e.minDistance&&(this.minDistance=e.minDistance),e?.smoothing!==void 0&&(this.smoothing=Math.min(Math.max(e.smoothing,0),.999)),e?.preventPointsNearClose!==void 0&&(this.preventPointsNearClose=e.preventPointsNearClose),e?.autoClose!==void 0&&(this.autoClose=e.autoClose),e!=null&&e.autoCloseTimeout&&(this.autoCloseTimeout=e.autoCloseTimeout),e?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:e!=null&&e.keyEvents&&(this.keyEvents=O({},this.keyEvents,e.keyEvents)),e!=null&&e.cursors&&(this.cursors=O({},this.cursors,e.cursors)),e!=null&&e.drawInteraction&&(this.drawInteraction=e.drawInteraction)}moveDrawAllowed(){return this.drawInteraction===`click-move`||this.drawInteraction===`click-move-or-drag`}dragDrawAllowed(){return this.drawInteraction===`click-drag`||this.drawInteraction===`click-move-or-drag`}beginDrawing(e,t=`click`){let{id:n}=this.mutateFeature.createPolygon({coordinates:[[e.lng,e.lat],[e.lng,e.lat],[e.lng,e.lat],[e.lng,e.lat]],properties:{mode:this.mode,[M.CURRENTLY_DRAWING]:!0}});this.currentId=n,this.drawType=t,this.closingPointId=this.mutateFeature.createGuidancePoint({coordinate:[e.lng,e.lat],type:M.CLOSING_POINT}),this.canClose=!0,this.state!==`drawing`&&this.setDrawing()}addCoordinate(e){if(this.currentId===void 0||!1===this.canClose)return void this.setCursor(this.cursors.start);let[t,n]=this.readFeature.getCoordinate(this.currentId,-2),{x:r,y:i}=this.project(t,n),a=G({x:r,y:i},{x:e.containerX,y:e.containerY}),[o,s]=this.readFeature.getCoordinate(this.currentId,0),{x:c,y:l}=this.project(o,s);if(G({x:c,y:l},{x:e.containerX,y:e.containerY})<this.pointerDistance){if(this.autoClose&&this.hasLeftStartingPoint&&(this.preventNewFeature=!0,setTimeout(()=>{this.preventNewFeature=!1},this.autoCloseTimeout),this.close()),this.setCursor(this.cursors.close),this.preventPointsNearClose)return}else this.hasLeftStartingPoint=!0,this.setCursor(this.cursors.start);if(a<this.minDistance)return;let u=this.getSmoothedCoordinate([t,n],[e.lng,e.lat]);this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:jt,index:-1,coordinate:u}],context:{updateType:A.Provisional}})}getSmoothedCoordinate(e,t){if(this.smoothing===0)return t;let[n,r]=e,[i,a]=t;return[n*this.smoothing+i*(1-this.smoothing),r*this.smoothing+a*(1-this.smoothing)]}close(){if(this.currentId===void 0||!this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:{[M.CURRENTLY_DRAWING]:void 0},context:{updateType:A.Finish,action:k}}))return;let e=this.currentId;this.mutateFeature.deleteFeatureIfPresent(this.closingPointId),this.canClose=!1,this.currentId=void 0,this.closingPointId=void 0,this.hasLeftStartingPoint=!1,this.drawType=void 0,this.state===`drawing`&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:k})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onMouseMove(e){this.moveDrawAllowed()&&this.drawType===`click`&&this.addCoordinate(e)}onClick(e){if(this.moveDrawAllowed()&&(e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e))){if(this.preventNewFeature)return;if(!1===this.canClose)return void this.beginDrawing(e);this.close()}}onKeyDown(){}onKeyUp(e){e.key===this.keyEvents.cancel?this.cleanUp():e.key===this.keyEvents.finish&&!0===this.canClose&&this.close()}onDragStart(e,t){this.state!==`drawing`&&(this.preventNewFeature||this.allowPointerEvent(this.pointerEvents.onDragStart,e)&&this.dragDrawAllowed()&&(this.beginDrawing(e,`drag`),t(!1)))}onDrag(e,t){this.allowPointerEvent(this.pointerEvents.onDrag,e)&&this.dragDrawAllowed()&&this.drawType===`drag`&&this.addCoordinate(e)}onDragEnd(e,t){this.allowPointerEvent(this.pointerEvents.onDragEnd,e)&&this.dragDrawAllowed()&&this.drawType===`drag`&&(this.preventNewFeature=!0,setTimeout(()=>{this.preventNewFeature=!1},this.autoCloseTimeout),this.close(),t(!0))}cleanUp(){let e=this.currentId,t=this.closingPointId;this.closingPointId=void 0,this.currentId=void 0,this.canClose=!1,this.hasLeftStartingPoint=!1,this.drawType=void 0,this.state===`drawing`&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(e),this.mutateFeature.deleteFeatureIfPresent(t)}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return e.type===`Feature`&&e.geometry.type===`Polygon`&&e.properties.mode===this.mode?(t.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,t.polygonFillColor,e),t.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,t.polygonOutlineColor,e),t.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,e),t.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,t.polygonOutlineWidth,e),t.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,t.polygonFillOpacity,e),t.zIndex=N,t):e.type===`Feature`&&e.geometry.type===`Point`&&e.properties.mode===this.mode?(t.pointWidth=this.getNumericStylingValue(this.styles.closingPointWidth,t.pointWidth,e),t.pointColor=this.getHexColorStylingValue(this.styles.closingPointColor,t.pointColor,e),t.pointOpacity=this.getNumericStylingValue(this.styles.closingPointOpacity,t.pointOpacity===void 0?1:t.pointOpacity,e),t.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,t.pointOutlineColor,e),t.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,e),t.pointOutlineOpacity=this.getNumericStylingValue(this.styles.closingPointOutlineOpacity,t.pointOutlineOpacity===void 0?1:t.pointOutlineOpacity,e),t.zIndex=50,t):t}validateFeature(e){return this.validateModeFeature(e,e=>Ot(e,this.coordinatePrecision))}afterFeatureUpdated(e){this.currentId===e.id&&(this.mutateFeature.deleteFeatureIfPresent(this.closingPointId),this.canClose=!1,this.currentId=void 0,this.closingPointId=void 0,this.hasLeftStartingPoint=!1)}registerBehaviors(e){this.readFeature=new K(e),this.mutateFeature=new W(e,{validate:this.validate})}};function Vt({unproject:e,point:t,pointerDistance:n}){let r=n/2,{x:i,y:a}=t;return{type:`Feature`,properties:{},geometry:{type:`Polygon`,coordinates:[[e(i-r,a-r),e(i+r,a-r),e(i+r,a+r),e(i-r,a+r),e(i-r,a-r)].map(e=>[e.lng,e.lat])]}}}var Ht=class extends V{constructor(e){super(e)}create(e){let{containerX:t,containerY:n}=e;return Vt({unproject:this.unproject,point:{x:t,y:n},pointerDistance:this.pointerDistance})}},Ut=class extends V{constructor(e){super(e)}measure(e,t){let{x:n,y:r}=this.project(t[0],t[1]);return G({x:n,y:r},{x:e.containerX,y:e.containerY})}},Wt=class extends V{constructor(e,t,n){super(e),this.config=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.getSnappableCoordinateFirstClick=e=>this.getSnappable(e,e=>!!(e.properties&&e.properties.mode===this.mode)).coordinate,this.getSnappableCoordinate=(e,t)=>this.getSnappable(e,e=>!!(e.properties&&e.properties.mode===this.mode&&e.id!==t)).coordinate,this.config=e,this.pixelDistance=t,this.clickBoundingBox=n}getSnappable(e,t){let n=this.clickBoundingBox.create(e),r=this.store.search(n,t),i={featureId:void 0,featureCoordinateIndex:void 0,coordinate:void 0,minDist:1/0};return r.forEach(t=>{let n;if(t.geometry.type===`Polygon`)n=t.geometry.coordinates[0];else{if(t.geometry.type!==`LineString`)return;n=t.geometry.coordinates}n.forEach((n,r)=>{let a=this.pixelDistance.measure(e,n);a<i.minDist&&a<this.pointerDistance&&(i.coordinate=n,i.minDist=a,i.featureId=t.id,i.featureCoordinateIndex=r)})}),i}};function Gt(e,t,n){let r=I(e[0]),i=I(e[1]),a=I(n),o=pt(t),s=Math.asin(Math.sin(i)*Math.cos(o)+Math.cos(i)*Math.sin(o)*Math.cos(a));return[L(r+Math.atan2(Math.sin(a)*Math.sin(o)*Math.cos(i),Math.cos(o)-Math.sin(i)*Math.sin(s))),L(s)]}function Kt({x:e,y:t},n,r){let i=I(r);return{x:e+n*Math.cos(i),y:t+n*Math.sin(i)}}function qt(e,t){let n=I(e[0]),r=I(t[0]),i=I(e[1]),a=I(t[1]),o=Math.sin(r-n)*Math.cos(a),s=Math.cos(i)*Math.sin(a)-Math.sin(i)*Math.cos(a)*Math.cos(r-n);return L(Math.atan2(o,s))}function q({x:e,y:t},{x:n,y:r}){let i=n-e,a=r-t;if(i===0&&a===0)return 0;let o=Math.atan2(a,i);return o*=180/Math.PI,o>180?o-=360:o<-180&&(o+=360),o}function Jt(e){return(e+360)%360}function Yt(e,t,n){let r=[],i=e.length,a,o,s,c=0;for(let i=0;i<e.length&&!(t>=c&&i===e.length-1);i++){if(c>t&&r.length===0){if(a=t-c,!a)return r.push(e[i]),r;o=qt(e[i],e[i-1])-180,s=Gt(e[i],a,o),r.push(s)}if(c>=n)return a=n-c,a?(o=qt(e[i],e[i-1])-180,s=Gt(e[i],a,o),r.push(s),r):(r.push(e[i]),r);if(c>=t&&r.push(e[i]),i===e.length-1)return r;c+=F(e[i],e[i+1])}if(c<t&&e.length===i)throw Error(`Start position is beyond line`);let l=e[e.length-1];return[l,l]}function Xt(e){return Math.PI/180*e}function Zt(e){return 180/Math.PI*e}var Qt=class extends V{constructor(e){super(e),this.config=void 0,this.config=e}generateInsertionCoordinates(e,t,n){let r=[e,t],i=0;for(let e=0;e<r.length-1;e++)i+=F(r[0],r[1]);if(i<=n)return r;let a=i/n-1;Number.isInteger(a)||(a=Math.floor(a)+1);let o=[];for(let e=0;e<a;e++){let t=Yt(r,n*e,n*(e+1));o.push(t)}let s=[];for(let e=0;e<o.length;e++)s.push(o[e][1]);return this.limitCoordinates(s)}generateInsertionGeodesicCoordinates(e,t,n){let r=F(e,t),i=function(e,t,n){let r=[],i=Xt(e[1]),a=Xt(e[0]),o=Xt(t[1]),s=Xt(t[0]);n+=1;let c=2*Math.asin(Math.sqrt(Math.sin((o-i)/2)**2+Math.cos(i)*Math.cos(o)*Math.sin((s-a)/2)**2));if(c===0||isNaN(c))return r;for(let e=0;e<=n;e++){let t=e/n,l=Math.sin((1-t)*c)/Math.sin(c),u=Math.sin(t*c)/Math.sin(c),d=l*Math.cos(i)*Math.cos(a)+u*Math.cos(o)*Math.cos(s),f=l*Math.cos(i)*Math.sin(a)+u*Math.cos(o)*Math.sin(s),p=l*Math.sin(i)+u*Math.sin(o);if(isNaN(d)||isNaN(f)||isNaN(p))continue;let m=Math.atan2(p,Math.sqrt(d**2+f**2)),h=Math.atan2(f,d);isNaN(m)||isNaN(h)||r.push([Zt(h),Zt(m)])}return r.slice(1,-1)}(e,t,Math.floor(r/n));return this.limitCoordinates(i)}limitCoordinates(e){return e.map(e=>[R(e[0],this.config.coordinatePrecision),R(e[1],this.config.coordinatePrecision)])}};function $t(e,t){if(e.geometry.type!==`LineString`)return{valid:!1,reason:`Feature is not a LineString`};if(e.geometry.coordinates.length<2)return{valid:!1,reason:`Feature has less than 2 coordinates`};for(let n=0;n<e.geometry.coordinates.length;n++){if(!St(e.geometry.coordinates[n]))return{valid:!1,reason:`Feature has invalid coordinates`};if(!xt(e.geometry.coordinates[n],t))return{valid:!1,reason:`Feature has coordinates with excessive precision`}}return{valid:!0}}function en(e){return Math.sqrt(e[0]**2+e[1]**2+e[2]**2)}function tn(e,t){let n=function(e,t){let[n,r,i]=e,[a,o,s]=t;return n*a+r*o+i*s}(e,t)/(en(e)*en(t));return Math.acos(Math.min(Math.max(n,-1),1))}function nn(e){let t=I(e[1]),n=I(e[0]);return[Math.cos(t)*Math.cos(n),Math.cos(t)*Math.sin(n),Math.sin(t)]}function rn(e){let[t,n,r]=e,i=L(Math.asin(r));return[L(Math.atan2(n,t)),i]}function an(e,t,n){let r=nn(e),i=nn(t),[a,o,s]=nn(n),[c,l,u]=function(e,t){let[n,r,i]=e,[a,o,s]=t;return[r*s-i*o,i*a-n*s,n*o-r*a]}(r,i),d=l*s-u*o,f=u*a-c*s,p=c*o-l*a,m=p*l-f*u,h=d*u-p*c,g=f*c-d*l,_=1/Math.sqrt(m**2+h**2+g**2),v=[m*_,h*_,g*_],ee=[-1*m*_,-1*h*_,-1*g*_],te=tn(r,i),y=tn(r,v),b=tn(i,v),ne=tn(r,ee),x=tn(i,ee),S;return S=y<ne&&y<x||b<ne&&b<x?v:ee,tn(r,S)>te||tn(i,S)>te?F(rn(S),rn(r))<=F(rn(S),rn(i))?[rn(r),!0,!1]:[rn(i),!1,!0]:[rn(S),!1,!1]}function on(e,t,n){let r=t.x-e.x,i=t.y-e.y,a=Math.max(0,Math.min(1,((n.x-e.x)*r+(n.y-e.y)*i)/(r*r+i*i)));return{x:e.x+a*r,y:e.y+a*i}}var sn=class extends V{constructor(e,t,n){super(e),this.config=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.getSnappableCoordinateFirstClick=e=>{let t=this.getSnappable(e,e=>!!(e.properties&&e.properties.mode===this.mode));return t.coordinate?[R(t.coordinate[0],this.config.coordinatePrecision),R(t.coordinate[1],this.config.coordinatePrecision)]:void 0},this.getSnappableCoordinate=(e,t)=>{let n=this.getSnappable(e,e=>!!(e.properties&&e.properties.mode===this.mode&&e.id!==t));return n.coordinate?[R(n.coordinate[0],this.config.coordinatePrecision),R(n.coordinate[1],this.config.coordinatePrecision)]:void 0},this.config=e,this.pixelDistance=t,this.clickBoundingBox=n}getSnappable(e,t){let n=this.clickBoundingBox.create(e),r=this.store.search(n,t),i={featureId:void 0,featureCoordinateIndex:void 0,coordinate:void 0,minDistance:1/0};return r.forEach(t=>{let n;if(t.geometry.type===`Polygon`)n=t.geometry.coordinates[0];else{if(t.geometry.type!==`LineString`)return;n=t.geometry.coordinates}let r=[];for(let e=0;e<n.length-1;e++)r.push([n[e],n[e+1]]);let a,o=[e.lng,e.lat];if(this.config.projection===`web-mercator`?a=function(e,t){let n=[1/0,1/0],r=1/0,i=0;for(let a of t){let o=a[0],s=a[1],c,l=1/0,u=z(o[0],o[1]),d=z(s[0],s[1]),f=z(e[0],e[1]);if(o[0]===e[0]&&o[1]===e[1])c=o;else if(s[0]===e[0]&&s[1]===e[1])c=s;else{let{x:e,y:t}=on(u,d,f),{lng:n,lat:r}=B(e,t);c=[n,r]}c&&(l=G(f,z(c[0],c[1])),l<r&&(n=c,r=l,i=t.indexOf(a)))}return r===1/0?void 0:{coordinate:n,lineIndex:i,distance:r}}(o,r):this.config.projection===`globe`&&(a=function(e,t){let n=[1/0,1/0],r=1/0,i=0;for(let a of t){let o=a[0],s=a[1],c,l=1/0;o[0]===e[0]&&o[1]===e[1]?c=o:s[0]===e[0]&&s[1]===e[1]?c=s:[c]=an(o,s,e),c&&(l=F(e,c),l<r&&(n=c,r=l,i=t.indexOf(a)))}return r===1/0?void 0:{coordinate:n,distance:r,lineIndex:i}}(o,r)),!a)return;let s=this.pixelDistance.measure(e,a.coordinate);s<i.minDistance&&s<this.pointerDistance&&(i.featureId=t.id,i.coordinate=[R(a.coordinate[0],this.config.coordinatePrecision),R(a.coordinate[1],this.config.coordinatePrecision)],i.featureCoordinateIndex=a.lineIndex,i.minDistance=s)}),i}};function cn(e){return Array.isArray(e)&&e.length>0&&Array.isArray(e[0])&&Array.isArray(e[0][0])}var ln=e=>cn(e)?e[0].slice(0,-1):e,un=e=>cn(e)?e[0]:e,dn=class extends V{constructor(e,t,n,r){super(e),this.config=void 0,this.pixelDistance=void 0,this.mutateFeatureBehavior=void 0,this.readFeatureBehavior=void 0,this._startEndPoints=[],this.config=e,this.pixelDistance=t,this.mutateFeatureBehavior=n,this.readFeatureBehavior=r}get ids(){return this._startEndPoints.concat()}set ids(e){}create(e){if(this.ids.length)throw Error(`Opening and closing points already created`);let t=cn(e),n=un(e);if(t){if(n.length<=3)throw Error(`Requires at least 4 coordinates`);this._startEndPoints=this.mutateFeatureBehavior.createGuidancePoints({coordinates:[n[0],n[n.length-2]],type:M.CLOSING_POINT})}else this._startEndPoints=[this.mutateFeatureBehavior.createGuidancePoint({coordinate:n[n.length-2],type:M.CLOSING_POINT})]}delete(){this.ids.length&&(this.mutateFeatureBehavior.deleteFeaturesIfPresent(this.ids),this._startEndPoints=[])}updateOne(e,t){this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[e],coordinate:t}])}update(e){let t=un(e);this.ids.length===1?this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[0],coordinate:t[t.length-2]}]):this.ids.length===2&&this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[0],coordinate:t[0]},{featureId:this.ids[1],coordinate:t[t.length-3]}])}isLineStringClosingPoint(e){if(this.ids.length!==1)return{isClosing:!1};let t=this.readFeatureBehavior.getGeometry(this.ids[0]);return{isClosing:this.pixelDistance.measure(e,t.coordinates)<this.pointerDistance}}isPolygonClosingPoints(e){if(this.ids.length!==2)return{isClosing:!1,isPreviousClosing:!1};let t=this.readFeatureBehavior.getGeometry(this.ids[0]),n=this.readFeatureBehavior.getGeometry(this.ids[1]),r=this.pixelDistance.measure(e,t.coordinates),i=this.pixelDistance.measure(e,n.coordinates);return{isClosing:r<this.pointerDistance,isPreviousClosing:i<this.pointerDistance}}},fn=class extends V{constructor(e,t,n){super(e),this.readFeature=void 0,this.mutateFeature=void 0,this.readFeature=t,this.mutateFeature=n}createOrUpdate({featureId:e,featureCoordinates:t}){if(!this.readFeature.hasFeature(e))return void this.deleteOrphanedPoints(e);let n=ln(t),r=this.readFeature.getProperties(e),i=r.coordinatePointIds;if(i)if(i&&i.every(e=>this.readFeature.hasFeature(e))){let t=r.coordinatePointIds,i=t.map(e=>this.readFeature.getGeometry(e).coordinates);if(t.length!==n.length){this.deleteCoordinatePoints(t);let i=this.createPoints(n,r.mode,e);this.setFeatureCoordinatePoints(e,i)}else{let e=[];n.forEach((n,r)=>{n[0]===i[r][0]&&n[1]===i[r][1]||e.push({featureId:t[r],coordinate:n})}),this.mutateFeature.updateGuidancePoints(e)}}else{let t=i.filter(e=>this.readFeature.hasFeature(e));t.length&&this.deleteCoordinatePoints(t);let a=this.createPoints(n,r.mode,e);this.setFeatureCoordinatePoints(e,a)}else{let t=this.createPoints(n,r.mode,e);this.setFeatureCoordinatePoints(e,t)}}deletePointsByFeatureIds(e){for(let t of e)this.deleteIfPresent(t)}updateOneAtIndex(e,t,n){let r=this.readFeature.getProperties(e).coordinatePointIds;r&&r.length!==0&&r[t]!==void 0&&this.mutateFeature.updateGuidancePoints([{featureId:r[t],coordinate:n}])}updateAllInPlace({featureId:e,featureCoordinates:t}){let n=this.readFeature.getProperties(e);if(!n.coordinatePointIds)return;let r=ln(t);r.length===n.coordinatePointIds.length&&this.mutateFeature.updateGuidancePoints(n.coordinatePointIds.map((e,t)=>({featureId:e,coordinate:r[t]})))}createPoints(e,t,n){return this.mutateFeature.createGuidancePoints({coordinates:e,type:M.COORDINATE_POINT,additionalProperties:e=>({mode:t,[M.COORDINATE_POINT]:!0,[M.COORDINATE_POINT_FEATURE_ID]:n,index:e})})}setFeatureCoordinatePoints(e,t,n=A.Commit){let r=this.readFeature.getGeometryType(e),i={featureId:e,propertyMutations:{[M.COORDINATE_POINT_IDS]:t},context:{updateType:n}};if(r===`Polygon`)this.mutateFeature.updatePolygon(i);else{if(r!==`LineString`)throw Error(`Unsupported geometry type for coordinate points`);this.mutateFeature.updateLineString(i)}}deleteCoordinatePoints(e){this.mutateFeature.deleteFeaturesIfPresent(e)}deleteIfPresent(e){if(!this.readFeature.hasFeature(e))return;let t=this.readFeature.getProperties(e).coordinatePointIds;t&&(this.deleteCoordinatePoints(t),this.setFeatureCoordinatePoints(e,null))}deleteOrphanedPoints(e){let t=this.readFeature.getAllFeatureIdsWhere(t=>t[M.COORDINATE_POINT_FEATURE_ID]===e);this.mutateFeature.deleteFeaturesIfPresent(t)}},pn=class{constructor(e){this.undoHistory=[],this.redoHistory=[],this.cloneCoordinatesFunction=void 0,this.maxStackSize=void 0,this.cloneCoordinatesFunction=e=>this.cloneRecursively(e);let t=e?.maxStackSize;this.maxStackSize=t!==void 0&&Number.isFinite(t)?Math.max(0,Math.floor(t)):1/0}setMaxStackSize(e){Number.isFinite(e)?(this.maxStackSize=Math.max(0,Math.floor(e)),this.trimHistoryToMax(this.undoHistory),this.trimHistoryToMax(this.redoHistory)):this.maxStackSize=1/0}trimHistoryToMax(e){if(Number.isFinite(this.maxStackSize))for(;e.length>this.maxStackSize;)e.shift()}pushUndoEntry(e){this.maxStackSize!==0&&(this.undoHistory.push(e),this.trimHistoryToMax(this.undoHistory))}pushRedoEntry(e){this.maxStackSize!==0&&(this.redoHistory.push(e),this.trimHistoryToMax(this.redoHistory))}cloneRecursively(e){return Array.isArray(e)?e.map(e=>this.cloneRecursively(e)):typeof e==`object`&&e?O({},e):e}cloneCoordinates(e){return this.cloneCoordinatesFunction(e)}cloneEntry(e){return{featureCoordinates:this.cloneCoordinates(e.featureCoordinates),currentCoordinate:e.currentCoordinate}}clear(){this.undoHistory=[],this.redoHistory=[]}undoSize(){return this.undoHistory.length}redoSize(){return this.redoHistory.length}recordSnapshot(e){this.pushUndoEntry(this.cloneEntry(e)),this.redoHistory=[]}beginUndo(){let e=this.undoHistory.pop();if(!e)return;let t=this.cloneEntry(e);this.pushRedoEntry(t);let n=this.undoHistory[this.undoHistory.length-1];return{undoneEntry:t,previousEntry:n?this.cloneEntry(n):void 0}}takeRedo(){let e=this.redoHistory.pop();if(e)return this.cloneEntry(e)}commitRedo(e){this.pushUndoEntry(this.cloneEntry(e))}},mn={cancel:`Escape`,finish:`Enter`},hn={start:`crosshair`,close:`pointer`,dragStart:`grabbing`,dragEnd:`crosshair`},gn=class extends P{constructor(e){super(e,!0),this.mode=`linestring`,this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=mn,this.snapping=void 0,this.cursors=hn,this.mouseMove=!1,this.insertCoordinates=void 0,this.lastCommittedCoordinates=void 0,this.snappedPointId=void 0,this.lastMouseMoveEvent=void 0,this.showCoordinatePoints=!1,this.finishOnNthCoordinate=void 0,this.editable=!1,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0,this.editedInsertIndex=void 0,this.editedPointId=void 0,this.coordinateSnapping=void 0,this.insertPoint=void 0,this.lineSnapping=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.closingPoints=void 0,this.coordinatePoints=void 0,this.undoRedo=void 0,this.updateOptions(e)}updateOptions(e){if(super.updateOptions(e),e?.finishOnNthCoordinate!==void 0&&Number.isInteger(e.finishOnNthCoordinate)&&e.finishOnNthCoordinate>1&&(this.finishOnNthCoordinate=Math.floor(e.finishOnNthCoordinate)),e!=null&&e.cursors&&(this.cursors=O({},this.cursors,e.cursors)),e!=null&&e.snapping&&(this.snapping=e.snapping),e?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:e!=null&&e.keyEvents&&(this.keyEvents=O({},this.keyEvents,e.keyEvents)),e!=null&&e.insertCoordinates&&(this.insertCoordinates=e.insertCoordinates),e&&e.editable&&(this.editable=e.editable),e?.showCoordinatePoints!==void 0){if(this.showCoordinatePoints=e.showCoordinatePoints,this.coordinatePoints&&!0===e.showCoordinatePoints)this.store.copyAllWhere(e=>e.mode===this.mode).forEach(e=>{this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates})});else if(this.coordinatePoints&&!1===this.showCoordinatePoints){let e=this.store.copyAllWhere(e=>e.mode===this.mode&&!!e[M.COORDINATE_POINT_IDS]?.length);this.coordinatePoints.deletePointsByFeatureIds(e.map(e=>e.id))}}}shouldFinishOnCommit(e){return!!this.finishOnNthCoordinate&&Math.max(0,e.coordinates.length-1)>=this.finishOnNthCoordinate}updateSnappedCoordinate(e){let t=this.snapCoordinate(e);return t?(this.snappedPointId?this.mutateFeature.updateGuidancePoints([{featureId:this.snappedPointId,coordinate:t}]):this.snappedPointId=this.mutateFeature.createGuidancePoint({coordinate:t,type:M.SNAPPING_POINT}),e.lng=t[0],e.lat=t[1]):this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0),t}close(){if(this.currentId===void 0)return;let e=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:A.Finish,action:k},coordinateMutations:[{type:Nt,index:-1}],propertyMutations:{[M.CURRENTLY_DRAWING]:void 0}});if(!e)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates});let t=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),this.state===`drawing`&&this.setStarted(),this.closingPoints.delete(),this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0),this.onFinish(t,{mode:this.mode,action:k})}generateInsertCoordinates(e,t){if(!this.insertCoordinates||!this.lastCommittedCoordinates)throw Error(`Not able to insert coordinates`);if(this.insertCoordinates.strategy!==`amount`)throw Error(`Strategy does not exist`);let n=F(e,t)/(this.insertCoordinates.value+1),r=[];return this.projection===`globe`?r=this.insertPoint.generateInsertionGeodesicCoordinates(e,t,n):this.projection===`web-mercator`&&(r=this.insertPoint.generateInsertionCoordinates(e,t,n)),r}createLine(e){let t=this.mutateFeature.createLineString({coordinates:[e,e],properties:{mode:this.mode,[M.CURRENTLY_DRAWING]:!0}});this.lastCommittedCoordinates=t.geometry.coordinates,this.currentId=t.id,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.setDrawing(),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:t.geometry.coordinates})}firstUpdateToLine(e){if(!this.currentId)return;this.setCursor(this.cursors.close);let t=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:A.Commit},coordinateMutations:[{type:Mt,index:-1,coordinate:e}]});t&&(this.closingPoints.create(t.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:t.geometry.coordinates}),this.lastCommittedCoordinates=t.geometry.coordinates,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.shouldFinishOnCommit(t.geometry)&&this.close())}updateToLine(e,t){if(!this.currentId)return;let{isClosing:n}=this.closingPoints.isLineStringClosingPoint(e);if(n)return void this.close();this.setCursor(this.cursors.close);let r=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:A.Commit},coordinateMutations:[{type:Mt,index:-1,coordinate:t}]});r&&(this.closingPoints.update(r.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:r.geometry.coordinates}),this.lastCommittedCoordinates=r.geometry.coordinates,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.shouldFinishOnCommit(r.geometry)&&this.close())}undoSize(){return this.undoRedo.undoSize()}clearHistory(){this.undoRedo.clear()}pushHistorySnapshot(e,t){let n=this.readFeature.getGeometry(e);this.undoRedo.recordSnapshot({featureCoordinates:n.coordinates,currentCoordinate:t})}updateSnappedGuidancePointFromLastMouseMove(){this.snapping&&this.lastMouseMoveEvent?this.updateSnappedCoordinate(this.lastMouseMoveEvent):this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0)}syncClosingPoints(e){this.currentCoordinate>=2?this.closingPoints.ids.length?this.closingPoints.update(e):this.closingPoints.create(e):this.closingPoints.delete()}undo(){if(this.state!==`drawing`||!this.currentId)return;let e=this.undoRedo.beginUndo();if(!e)return;let{previousEntry:t}=e;if(!t){let e=this.currentId;this.currentId=void 0,this.currentCoordinate=0,this.lastCommittedCoordinates=void 0,this.closingPoints.delete(),this.state===`drawing`&&this.setStarted(),this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([e]),this.mutateFeature.deleteFeatureIfPresent(e),this.updateSnappedGuidancePointFromLastMouseMove();return}let n=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:{type:U,coordinates:t.featureCoordinates},propertyMutations:{[M.CURRENTLY_DRAWING]:!0},context:{updateType:A.Commit}});n&&(this.currentCoordinate=t.currentCoordinate,this.lastCommittedCoordinates=n.geometry.coordinates,this.syncClosingPoints(n.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:n.geometry.coordinates}),this.updateSnappedGuidancePointFromLastMouseMove())}redoSize(){return this.undoRedo.redoSize()}redo(){let e=this.undoRedo.takeRedo();if(e){if(this.currentId){let t=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:{type:U,coordinates:e.featureCoordinates},propertyMutations:{[M.CURRENTLY_DRAWING]:!0},context:{updateType:A.Commit}});if(!t)return;this.currentCoordinate=e.currentCoordinate,this.lastCommittedCoordinates=t.geometry.coordinates,this.syncClosingPoints(t.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:t.geometry.coordinates})}else{let{id:t,geometry:n}=this.mutateFeature.createLineString({coordinates:e.featureCoordinates,properties:{mode:this.mode,[M.CURRENTLY_DRAWING]:!0}});this.currentId=t,this.currentCoordinate=e.currentCoordinate,this.lastCommittedCoordinates=n.coordinates,this.state===`started`&&this.setDrawing(),this.syncClosingPoints(n.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t,featureCoordinates:n.coordinates})}this.undoRedo.commitRedo(e),this.updateSnappedGuidancePointFromLastMouseMove()}}registerBehaviors(e){this.insertPoint=new Qt(e),this.clickBoundingBox=new Ht(e),this.pixelDistance=new Ut(e),this.lineSnapping=new sn(e,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new Wt(e,this.pixelDistance,this.clickBoundingBox),this.readFeature=new K(e),this.mutateFeature=new W(e,{validate:this.validate}),this.closingPoints=new dn(e,this.pixelDistance,this.mutateFeature,this.readFeature),this.coordinatePoints=new fn(e,this.readFeature,this.mutateFeature),this.undoRedo=new pn({maxStackSize:e.undoRedoMaxStackSize})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onMouseMove(e){this.mouseMove=!0,this.setCursor(this.cursors.start),this.lastMouseMoveEvent=e;let t=this.updateSnappedCoordinate(e)||[e.lng,e.lat];if(this.currentId===void 0||this.currentCoordinate===0)return;let{isClosing:n}=this.closingPoints.isLineStringClosingPoint(e);n&&this.setCursor(this.cursors.close);let r=[{type:H,index:-1,coordinate:t}];if(this.insertCoordinates){let e=this.getInsertCoordinates(t);e&&(r={type:U,coordinates:e})}let i=this.mutateFeature.updateLineString({coordinateMutations:r,featureId:this.currentId,context:{updateType:A.Provisional}});i&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates})}getInsertCoordinates(e){if(!this.lastCommittedCoordinates)return;let t=this.lastCommittedCoordinates[this.lastCommittedCoordinates.length-1];if(Lt(t,e))return;let n=this.generateInsertCoordinates(t,e);return[...this.lastCommittedCoordinates.slice(0,-1),...n,e]}onRightClick(e){if(!this.editable||this.state!==`started`)return;let{featureId:t,featureCoordinateIndex:n}=this.coordinateSnapping.getSnappable(e,e=>this.lineStringFilter(e));if(!t||n===void 0)return;let r=this.readFeature.getGeometry(t),i;if(r.type!==`LineString`||(i=r.coordinates,i.length<=2))return;let a=this.mutateFeature.updateLineString({featureId:t,coordinateMutations:[{type:Nt,index:n}],context:{updateType:A.Finish,action:tt}});a&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t,featureCoordinates:a.geometry.coordinates}),this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0),this.closingPoints.delete(),this.onFinish(t,{mode:this.mode,action:nt})}onLeftClick(e){this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0);let t=this.snapCoordinate(e)||[e.lng,e.lat];this.currentCoordinate===0?this.createLine(t):this.currentCoordinate===1&&this.currentId?this.firstUpdateToLine(t):this.currentId&&this.updateToLine(e,t)}onClick(e){this.currentId===void 0||this.readFeature.hasFeature(this.currentId)||this.cleanUp(),(e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e))&&(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(e),this.mouseMove=!1,e.button===`right`?this.onRightClick(e):e.button===`left`&&this.onLeftClick(e))}onKeyDown(){}onKeyUp(e){e.key===this.keyEvents.cancel&&this.cleanUp(),e.key===this.keyEvents.finish&&this.close()}onDragStart(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDragStart,e)||!this.editable)return;let n;if(this.state===`started`){let t=this.lineSnapping.getSnappable(e,e=>this.lineStringFilter(e));t.coordinate&&(this.editedSnapType=`line`,this.editedFeatureCoordinateIndex=t.featureCoordinateIndex,this.editedFeatureId=t.featureId,n=t.coordinate);let r=this.coordinateSnapping.getSnappable(e,e=>this.lineStringFilter(e));r.coordinate&&(this.editedSnapType=`coordinate`,this.editedFeatureCoordinateIndex=r.featureCoordinateIndex,this.editedFeatureId=r.featureId,n=r.coordinate)}this.editedFeatureId&&n&&(this.editedPointId||=this.mutateFeature.createGuidancePoint({coordinate:n,type:M.EDITED}),this.setCursor(this.cursors.dragStart),t(!1))}onDrag(e,t){if(this.allowPointerEvent(this.pointerEvents.onDrag,e)&&this.editedFeatureId!==void 0&&this.editedFeatureCoordinateIndex!==void 0){if(this.editedSnapType===`coordinate`||this.editedSnapType===`line`&&this.editedInsertIndex!==void 0){let t=this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:A.Provisional},coordinateMutations:[{type:H,index:this.editedFeatureCoordinateIndex,coordinate:[e.lng,e.lat]}]});if(!t)return;this.showCoordinatePoints&&(this.editedInsertIndex===void 0?this.coordinatePoints.updateOneAtIndex(this.editedFeatureId,this.editedFeatureCoordinateIndex,[e.lng,e.lat]):this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:t.geometry.coordinates}))}else if(this.editedSnapType===`line`&&this.editedInsertIndex===void 0){this.editedInsertIndex=this.editedFeatureCoordinateIndex+1;let e=this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:A.Provisional}});if(!e)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:e.geometry.coordinates}),this.editedFeatureCoordinateIndex++}this.snapping&&this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&this.mutateFeature.updateGuidancePoints([{featureId:this.editedPointId,coordinate:[e.lng,e.lat]}]),this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:A.Provisional},propertyMutations:{[M.EDITED]:!0}})}}onDragEnd(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDragEnd,e)||this.editedFeatureId===void 0||(this.setCursor(this.cursors.dragEnd),!this.mutateFeature.updateLineString({featureId:this.editedFeatureId,propertyMutations:{[M.EDITED]:!1},context:{updateType:A.Finish,action:tt}})))return;let n=this.editedFeatureId;t(!0),this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0),this.closingPoints.delete(),this.onFinish(n,{mode:this.mode,action:tt})}cleanUp(){let e=this.currentId,t=this.snappedPointId;this.snappedPointId=void 0,this.currentId=void 0,this.currentCoordinate=0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),this.state===`drawing`&&this.setStarted(),e&&this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([e]),this.mutateFeature.deleteFeatureIfPresent(e),this.mutateFeature.deleteFeatureIfPresent(t),this.closingPoints.delete()}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});if(e.type===`Feature`&&e.geometry.type===`LineString`&&e.properties.mode===this.mode)return t.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,t.lineStringColor,e),t.lineStringOpacity=this.getNumericStylingValue(this.styles.lineStringOpacity,t.lineStringOpacity===void 0?1:t.lineStringOpacity,e),t.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,t.lineStringWidth,e),t.zIndex=N,t;if(e.type===`Feature`&&e.geometry.type===`Point`&&e.properties.mode===this.mode){let n=e.properties[M.COORDINATE_POINT],r=e.properties[M.CLOSING_POINT]?`closingPoint`:e.properties[M.SNAPPING_POINT]?`snappingPoint`:n?`coordinatePoint`:void 0;if(!r)return t;let i={closingPoint:{width:this.styles.closingPointWidth,color:this.styles.closingPointColor,opacity:this.styles.closingPointOpacity,outlineColor:this.styles.closingPointOutlineColor,outlineWidth:this.styles.closingPointOutlineWidth,outlineOpacity:this.styles.closingPointOutlineOpacity},snappingPoint:{width:this.styles.snappingPointWidth,color:this.styles.snappingPointColor,opacity:this.styles.snappingPointOpacity,outlineColor:this.styles.snappingPointOutlineColor,outlineWidth:this.styles.snappingPointOutlineWidth,outlineOpacity:this.styles.snappingPointOutlineOpacity},coordinatePoint:{width:this.styles.coordinatePointWidth,color:this.styles.coordinatePointColor,opacity:this.styles.coordinatePointOpacity,outlineColor:this.styles.coordinatePointOutlineColor,outlineWidth:this.styles.coordinatePointOutlineWidth,outlineOpacity:this.styles.coordinatePointOutlineOpacity}};return t.pointWidth=this.getNumericStylingValue(i[r].width,t.pointWidth,e),t.pointOpacity=this.getNumericStylingValue(i[r].opacity,1,e),t.pointColor=this.getHexColorStylingValue(i[r].color,t.pointColor,e),t.pointOutlineColor=this.getHexColorStylingValue(i[r].outlineColor,`#ffffff`,e),t.pointOutlineWidth=this.getNumericStylingValue(i[r].outlineWidth,2,e),t.pointOutlineOpacity=this.getNumericStylingValue(i[r].outlineOpacity,1,e),t.zIndex=n?20:50,t}return t}validateFeature(e){return this.validateModeFeature(e,e=>$t(e,this.coordinatePrecision))}lineStringFilter(e){return!!(e.geometry.type===`LineString`&&e.properties&&e.properties.mode===this.mode)}snapCoordinate(e){var t,n,r;let i;if((t=this.snapping)!=null&&t.toLine){let t;t=this.currentId?this.lineSnapping.getSnappableCoordinate(e,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(e),t&&(i=t)}if((n=this.snapping)!=null&&n.toCoordinate){let t;t=this.currentId?this.coordinateSnapping.getSnappableCoordinate(e,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(e),t&&(i=t)}if((r=this.snapping)!=null&&r.toCustom){let t=this.snapping.toCustom(e,{currentCoordinate:this.currentCoordinate,currentId:this.currentId,getCurrentGeometrySnapshot:this.currentId?()=>this.readFeature.getGeometry(this.currentId):()=>null,project:this.project,unproject:this.unproject});t&&(i=t)}return i}afterFeatureUpdated(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates}),this.editedFeatureId===e.id&&this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0),this.snappedPointId&&this.lastMouseMoveEvent&&this.updateSnappedCoordinate(this.lastMouseMoveEvent),this.currentId===e.id&&(this.closingPoints.delete(),this.currentCoordinate=0,this.currentId=void 0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),this.state===`drawing`&&this.setStarted())}afterFeatureAdded(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates})}},_n=`Feature is not a Point`,vn=`Feature has invalid coordinates`,yn=`Feature has coordinates with excessive precision`;function bn(e,t){return e.geometry.type===`Point`?St(e.geometry.coordinates)?xt(e.geometry.coordinates,t)?{valid:!0}:{valid:!1,reason:yn}:{valid:!1,reason:vn}:{valid:!1,reason:_n}}var xn=class extends V{constructor(e,t,n){super(e),this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.pixelDistance=t,this.clickBoundingBox=n}getNearestPointFeature(e){let t=this.clickBoundingBox.create(e),n=this.store.search(t),r,i=1/0;for(let t=0;t<n.length;t++){let a=n[t];if(a.geometry.type!==`Point`||a.properties.mode!==this.mode)continue;let o=this.pixelDistance.measure(e,a.geometry.coordinates);o>i||o>this.pointerDistance||(i=o,r=a)}return r}},Sn={create:`crosshair`,dragStart:`grabbing`,dragEnd:`crosshair`},Cn=class extends P{constructor(e){super(e,!0),this.mode=`point`,this.cursors=Sn,this.editable=!1,this.editedFeatureId=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.pointSearch=void 0,this.mutateFeature=void 0,this.updateOptions(e)}updateOptions(e){super.updateOptions(e),e!=null&&e.cursors&&(this.cursors=O({},this.cursors,e.cursors)),e!=null&&e.editable&&(this.editable=e.editable)}start(){this.setStarted(),this.setCursor(this.cursors.create)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onClick(e){e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e)?this.onRightClick(e):e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)&&this.onLeftClick(e)}onMouseMove(){}onKeyDown(){}onKeyUp(){}cleanUp(){this.editedFeatureId=void 0}onDragStart(e,t){this.allowPointerEvent(this.pointerEvents.onDragStart,e)&&(this.editable&&(this.editedFeatureId=this.pointSearch.getNearestPointFeature(e)?.id),this.editedFeatureId&&(this.setCursor(this.cursors.dragStart),t(!1)))}onDrag(e,t){this.allowPointerEvent(this.pointerEvents.onDrag,e)&&this.editedFeatureId!==void 0&&this.mutateFeature.updatePoint({featureId:this.editedFeatureId,coordinateMutations:{type:U,coordinates:[e.lng,e.lat]},propertyMutations:{[M.EDITED]:!0},context:{updateType:A.Provisional}})}onDragEnd(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDragEnd,e)||this.editedFeatureId===void 0||!this.mutateFeature.updatePoint({featureId:this.editedFeatureId,propertyMutations:{mode:this.mode,[M.EDITED]:!1},context:{updateType:A.Finish,action:`edit`}}))return;let n=this.editedFeatureId;this.setCursor(this.cursors.dragEnd),this.editedFeatureId=void 0,t(!0),this.onFinish(n,{mode:this.mode,action:k})}registerBehaviors(e){this.pixelDistance=new Ut(e),this.clickBoundingBox=new Ht(e),this.pointSearch=new xn(e,this.pixelDistance,this.clickBoundingBox),this.mutateFeature=new W(e,{validate:this.validate})}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});if(e.type===`Feature`&&e.geometry.type===`Point`&&e.properties.mode===this.mode){let n=!!(e.id&&this.editedFeatureId===e.id);t.pointWidth=this.getNumericStylingValue(n?this.styles.editedPointWidth:this.styles.pointWidth,t.pointWidth,e),t.pointOpacity=this.getNumericStylingValue(this.styles.pointOpacity,t.pointOpacity===void 0?1:t.pointOpacity,e),t.pointColor=this.getHexColorStylingValue(n?this.styles.editedPointColor:this.styles.pointColor,t.pointColor,e),t.pointOutlineColor=this.getHexColorStylingValue(n?this.styles.editedPointOutlineColor:this.styles.pointOutlineColor,t.pointOutlineColor,e),t.pointOutlineOpacity=this.getNumericStylingValue(this.styles.pointOutlineOpacity,t.pointOutlineOpacity===void 0?1:t.pointOutlineOpacity,e),t.pointOutlineWidth=this.getNumericStylingValue(n?this.styles.editedPointOutlineWidth:this.styles.pointOutlineWidth,2,e),t.zIndex=30}return t}validateFeature(e){return this.validateModeFeature(e,e=>bn(e,this.coordinatePrecision))}onLeftClick(e){let t=this.mutateFeature.createPoint({coordinates:[e.lng,e.lat],properties:{mode:this.mode},context:{updateType:A.Finish,action:k}});t&&this.onFinish(t.id,{mode:this.mode,action:k})}onRightClick(e){if(!this.editable)return;let t=this.pointSearch.getNearestPointFeature(e);t&&this.mutateFeature.deleteFeatureIfPresent(t.id)}afterFeatureUpdated(e){this.editedFeatureId===e.id&&(this.editedFeatureId=void 0,this.setCursor(this.cursors.create))}},wn={cancel:`Escape`,finish:`Enter`},Tn={start:`crosshair`,close:`pointer`,dragStart:`grabbing`,dragEnd:`crosshair`},En=class extends P{constructor(e){super(e,!0),this.mode=`polygon`,this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=wn,this.cursors=Tn,this.mouseMove=!1,this.showCoordinatePoints=!1,this.lastMouseMoveEvent=void 0,this.snapping=void 0,this.snappedPointId=void 0,this.editable=!1,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0,this.editedInsertIndex=void 0,this.editedPointId=void 0,this.coordinatePoints=void 0,this.lineSnapping=void 0,this.coordinateSnapping=void 0,this.pixelDistance=void 0,this.closingPoints=void 0,this.clickBoundingBox=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.undoRedo=void 0,this.updateOptions(e)}updateOptions(e){if(super.updateOptions(e),e!=null&&e.cursors&&(this.cursors=O({},this.cursors,e.cursors)),e?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:e!=null&&e.keyEvents&&(this.keyEvents=O({},this.keyEvents,e.keyEvents)),e!=null&&e.snapping&&(this.snapping=e.snapping),e?.editable!==void 0&&(this.editable=e.editable),e?.pointerEvents!==void 0&&(this.pointerEvents=e.pointerEvents),e?.showCoordinatePoints!==void 0){if(this.showCoordinatePoints=e.showCoordinatePoints,this.coordinatePoints&&!0===e.showCoordinatePoints)this.store.copyAllWhere(e=>e.mode===this.mode).filter(e=>e.geometry.type===`Polygon`).forEach(e=>{this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates})});else if(this.coordinatePoints&&!1===this.showCoordinatePoints){let e=this.store.copyAllWhere(e=>e.mode===this.mode&&!!e[M.COORDINATE_POINT_IDS]).filter(e=>e.geometry.type===`Polygon`);this.coordinatePoints.deletePointsByFeatureIds(e.map(e=>e.id))}}}close(){if(this.currentId===void 0||this.readFeature.getCoordinates(this.currentId).length<5)return;let e=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:Nt,index:-2}],propertyMutations:{[M.CURRENTLY_DRAWING]:void 0,[M.COMMITTED_COORDINATE_COUNT]:void 0,[M.PROVISIONAL_COORDINATE_COUNT]:void 0},context:{updateType:A.Finish,action:k}});if(!e)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates}),this.state===`drawing`&&this.setStarted(),this.editedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),void 0),this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0),this.closingPoints.delete();let t=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.undoRedo.clear(),this.onFinish(t,{mode:this.mode,action:k})}registerBehaviors(e){this.readFeature=new K(e),this.mutateFeature=new W(e,{validate:this.validate}),this.clickBoundingBox=new Ht(e),this.pixelDistance=new Ut(e),this.lineSnapping=new sn(e,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new Wt(e,this.pixelDistance,this.clickBoundingBox),this.closingPoints=new dn(e,this.pixelDistance,this.mutateFeature,this.readFeature),this.coordinatePoints=new fn(e,this.readFeature,this.mutateFeature),this.undoRedo=new pn({maxStackSize:e.undoRedoMaxStackSize})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}updateSnappedCoordinate(e){let t=this.snapCoordinate(e);t?(this.snappedPointId?this.mutateFeature.updateGuidancePoints([{featureId:this.snappedPointId,coordinate:t}]):this.snappedPointId=this.mutateFeature.createGuidancePoint({coordinate:t,type:M.SNAPPING_POINT}),e.lng=t[0],e.lat=t[1]):this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0)}undoSize(){return this.undoRedo.undoSize()}clearHistory(){this.undoRedo.clear()}pushHistorySnapshot(e,t){let n=this.readFeature.getGeometry(e);this.undoRedo.recordSnapshot({featureCoordinates:n.coordinates,currentCoordinate:t})}updateSnappedGuidancePointFromLastMouseMove(){this.snapping&&this.lastMouseMoveEvent?this.updateSnappedCoordinate(this.lastMouseMoveEvent):this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0)}syncClosingPoints(e){this.currentCoordinate>=3?this.closingPoints.ids.length?this.closingPoints.update(e):this.closingPoints.create(e):this.closingPoints.delete()}undo(){if(this.state!==`drawing`||!this.currentId)return;let e=this.undoRedo.beginUndo();if(!e)return;let{previousEntry:t}=e;if(!t){let e=this.currentId;this.currentId=void 0,this.currentCoordinate=0,this.closingPoints.delete(),this.state===`drawing`&&this.setStarted(),this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([e]),this.mutateFeature.deleteFeatureIfPresent(e),this.updateSnappedGuidancePointFromLastMouseMove();return}let n=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:{type:U,coordinates:t.featureCoordinates},propertyMutations:{[M.CURRENTLY_DRAWING]:!0,[M.COMMITTED_COORDINATE_COUNT]:t.currentCoordinate,[M.PROVISIONAL_COORDINATE_COUNT]:t.currentCoordinate},context:{updateType:A.Commit}});n&&(this.currentCoordinate=t.currentCoordinate,this.syncClosingPoints(n.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:n.geometry.coordinates}),this.updateSnappedGuidancePointFromLastMouseMove())}redoSize(){return this.undoRedo.redoSize()}redo(){let e=this.undoRedo.takeRedo();if(e){if(this.currentId){let t=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:{type:U,coordinates:e.featureCoordinates},propertyMutations:{[M.CURRENTLY_DRAWING]:!0,[M.COMMITTED_COORDINATE_COUNT]:e.currentCoordinate,[M.PROVISIONAL_COORDINATE_COUNT]:e.currentCoordinate},context:{updateType:A.Commit}});if(!t)return;this.currentCoordinate=e.currentCoordinate,this.syncClosingPoints(t.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:t.geometry.coordinates})}else{let t=this.undoRedo.cloneCoordinates(e.featureCoordinates)[0],{id:n,geometry:r}=this.mutateFeature.createPolygon({coordinates:t,properties:{mode:this.mode,[M.CURRENTLY_DRAWING]:!0,[M.COMMITTED_COORDINATE_COUNT]:e.currentCoordinate,[M.PROVISIONAL_COORDINATE_COUNT]:e.currentCoordinate}});this.currentId=n,this.currentCoordinate=e.currentCoordinate,this.state===`started`&&this.setDrawing(),this.syncClosingPoints(r.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:n,featureCoordinates:r.coordinates})}this.undoRedo.commitRedo(e),this.updateSnappedGuidancePointFromLastMouseMove()}}onMouseMove(e){if(this.mouseMove=!0,this.setCursor(this.cursors.start),this.lastMouseMoveEvent=e,this.updateSnappedCoordinate(e),this.currentId===void 0||this.currentCoordinate===0)return;let t=this.readFeature.getCoordinate(this.currentId,0),n=[e.lng,e.lat],r;if(this.currentCoordinate===1)r=[{type:H,index:1,coordinate:n},{type:H,index:2,coordinate:[e.lng,e.lat]}];else if(this.currentCoordinate===2)r=[{type:H,index:2,coordinate:n}];else{let{isClosing:i,isPreviousClosing:a}=this.closingPoints.isPolygonClosingPoints(e);a||i?(this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0),this.setCursor(this.cursors.close),r=[{type:H,index:-1,coordinate:t},{type:H,index:-2,coordinate:t}]):r=[{type:H,index:-2,coordinate:n},{type:H,index:-1,coordinate:t}]}let i=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:r,propertyMutations:{[M.PROVISIONAL_COORDINATE_COUNT]:this.currentCoordinate+1},context:{updateType:A.Provisional}});i&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates})}snapCoordinate(e){var t,n,r;let i;if((t=this.snapping)!=null&&t.toLine){let t;t=this.currentId?this.lineSnapping.getSnappableCoordinate(e,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(e),t&&(i=t)}if((n=this.snapping)!=null&&n.toCoordinate){let t;t=this.currentId?this.coordinateSnapping.getSnappableCoordinate(e,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(e),t&&(i=t)}if((r=this.snapping)!=null&&r.toCustom){let t=this.snapping.toCustom(e,{currentCoordinate:this.currentCoordinate,currentId:this.currentId,getCurrentGeometrySnapshot:this.currentId?()=>this.readFeature.getGeometry(this.currentId):()=>null,project:this.project,unproject:this.unproject});t&&(i=t)}return i}polygonFilter(e){return!!(e.geometry.type===`Polygon`&&e.properties&&e.properties.mode===this.mode)}onRightClick(e){if(!this.editable||this.state!==`started`)return;let{featureId:t,featureCoordinateIndex:n}=this.coordinateSnapping.getSnappable(e,e=>this.polygonFilter(e));if(!t||n===void 0)return;let r=this.readFeature.getGeometry(t);if(r.type!==`Polygon`)return;let i=r.coordinates[0];if(i.length<=4)return;let a;a=n===0||n===i.length-1?[{type:Nt,index:0},{type:Nt,index:-1},{type:Mt,index:-1,coordinate:i[1]}]:[{type:Nt,index:n}];let o=this.mutateFeature.updatePolygon({featureId:t,coordinateMutations:a,context:{updateType:A.Finish,action:tt}});if(o){if(this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t,featureCoordinates:o.geometry.coordinates}),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0,this.snapping)){let t=this.snapCoordinate(e);if(t){let[e]=this.mutateFeature.createGuidancePoints({type:M.SNAPPING_POINT,coordinates:[t]});this.snappedPointId=e}}this.onFinish(t,{mode:this.mode,action:tt})}}onLeftClick(e){this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0);let t=this.snapCoordinate(e)||[e.lng,e.lat];if(this.currentCoordinate===0){let{id:e,geometry:n}=this.mutateFeature.createPolygon({coordinates:[t,t,t,t],properties:{mode:this.mode,[M.CURRENTLY_DRAWING]:!0,[M.COMMITTED_COORDINATE_COUNT]:this.currentCoordinate+1,[M.PROVISIONAL_COORDINATE_COUNT]:this.currentCoordinate+1}});this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:e,featureCoordinates:n.coordinates}),this.currentId=e,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.setDrawing()}else if(this.currentCoordinate===1&&this.currentId){if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:t,index:0}))return;let e=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:H,index:1,coordinate:t},{type:H,index:2,coordinate:t}],propertyMutations:{[M.COMMITTED_COORDINATE_COUNT]:this.currentCoordinate+1},context:{updateType:A.Commit}});if(!e)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates}),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate)}else if(this.currentCoordinate===2&&this.currentId){if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:t,index:1}))return;let e=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:H,index:2,coordinate:t},{type:Mt,index:2,coordinate:t}],propertyMutations:{[M.COMMITTED_COORDINATE_COUNT]:this.currentCoordinate+1},context:{updateType:A.Commit}});if(!e)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates}),this.currentCoordinate===2&&this.closingPoints.create(e.geometry.coordinates),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate)}else if(this.currentId){let{isClosing:n,isPreviousClosing:r}=this.closingPoints.isPolygonClosingPoints(e);if(r||n)this.close();else{if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:t,index:this.currentCoordinate-1}))return;let e=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:jt,index:-1,coordinate:t}],propertyMutations:{[M.COMMITTED_COORDINATE_COUNT]:this.currentCoordinate+1},context:{updateType:A.Commit}});if(!e)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates}),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.closingPoints.ids.length&&this.closingPoints.update(e.geometry.coordinates)}}}onClick(e){this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(e),this.mouseMove=!1,e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e)?this.onRightClick(e):e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)&&this.onLeftClick(e)}onKeyUp(e){e.key===this.keyEvents.cancel?this.cleanUp():e.key===this.keyEvents.finish&&this.close()}onKeyDown(){}onDragStart(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDragStart,e)||!this.editable)return;let n;if(this.state===`started`){let t=this.lineSnapping.getSnappable(e,e=>this.polygonFilter(e));t.coordinate&&(this.editedSnapType=`line`,this.editedFeatureCoordinateIndex=t.featureCoordinateIndex,this.editedFeatureId=t.featureId,n=t.coordinate);let r=this.coordinateSnapping.getSnappable(e,e=>this.polygonFilter(e));r.coordinate&&(this.editedSnapType=`coordinate`,this.editedFeatureCoordinateIndex=r.featureCoordinateIndex,this.editedFeatureId=r.featureId,n=r.coordinate)}this.editedFeatureId&&n&&(this.editedPointId||=this.mutateFeature.createGuidancePoint({coordinate:n,type:M.EDITED}),this.setCursor(this.cursors.dragStart),t(!1))}onDrag(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDrag,e)||this.editedFeatureId===void 0||this.editedFeatureCoordinateIndex===void 0)return;let n=this.readFeature.getGeometry(this.editedFeatureId),r=[e.lng,e.lat],i=[];if(this.editedSnapType===`coordinate`||this.editedSnapType===`line`&&this.editedInsertIndex!==void 0?i=this.editedFeatureCoordinateIndex===0||this.editedFeatureCoordinateIndex===n.coordinates[0].length-1?[{type:H,index:0,coordinate:r},{type:H,index:-1,coordinate:r}]:[{type:H,index:this.editedFeatureCoordinateIndex,coordinate:r}]:this.editedSnapType===`line`&&this.editedInsertIndex===void 0&&(this.editedInsertIndex=this.editedFeatureCoordinateIndex+1,i=[{type:jt,index:this.editedInsertIndex,coordinate:r}],this.editedFeatureCoordinateIndex++),i.length===0)return;let a=this.mutateFeature.updatePolygon({featureId:this.editedFeatureId,coordinateMutations:i,propertyMutations:{[M.EDITED]:!0},context:{updateType:A.Provisional}});a&&(this.showCoordinatePoints&&(this.editedInsertIndex?this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:a.geometry.coordinates}):this.coordinatePoints.updateOneAtIndex(this.editedFeatureId,this.editedFeatureCoordinateIndex,a.geometry.coordinates[0][this.editedFeatureCoordinateIndex])),this.snapping&&this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&this.mutateFeature.updateGuidancePoints([{featureId:this.editedPointId,coordinate:r}]))}onDragEnd(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDragEnd,e)||this.editedFeatureId===void 0||(this.setCursor(this.cursors.dragEnd),!this.mutateFeature.updatePolygon({featureId:this.editedFeatureId,propertyMutations:{[M.EDITED]:!1},context:{updateType:A.Finish,action:tt}})))return;let n=this.editedFeatureId;this.editedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),void 0),this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0),this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0,t(!0),this.onFinish(n,{mode:this.mode,action:tt})}cleanUp(){let e=this.currentId,t=this.snappedPointId,n=this.editedPointId;this.currentId=void 0,this.snappedPointId=void 0,this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0,this.currentCoordinate=0,this.undoRedo.clear(),this.state===`drawing`&&this.setStarted(),e&&this.coordinatePoints.deletePointsByFeatureIds([e]),this.mutateFeature.deleteFeatureIfPresent(e),this.mutateFeature.deleteFeatureIfPresent(n),this.mutateFeature.deleteFeatureIfPresent(t),this.closingPoints.ids.length&&this.closingPoints.delete()}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});if(e.properties.mode===this.mode){if(e.geometry.type===`Polygon`)return t.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,t.polygonFillColor,e),t.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,t.polygonOutlineColor,e),t.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,t.polygonOutlineWidth,e),t.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,t.polygonFillOpacity,e),t.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,e),t.zIndex=N,t;if(e.geometry.type===`Point`){let n=e.properties[M.EDITED],r=e.properties[M.COORDINATE_POINT],i=n?`editedPoint`:e.properties[M.CLOSING_POINT]?`closingPoint`:e.properties[M.SNAPPING_POINT]?`snappingPoint`:r?`coordinatePoint`:void 0;if(!i)return t;let a={editedPoint:{width:this.styles.editedPointOutlineWidth,color:this.styles.editedPointColor,opacity:this.styles.editedPointOpacity,outlineColor:this.styles.editedPointOutlineColor,outlineWidth:this.styles.editedPointOutlineWidth,outlineOpacity:this.styles.editedPointOutlineOpacity},closingPoint:{width:this.styles.closingPointWidth,color:this.styles.closingPointColor,opacity:this.styles.closingPointOpacity,outlineColor:this.styles.closingPointOutlineColor,outlineWidth:this.styles.closingPointOutlineWidth,outlineOpacity:this.styles.closingPointOutlineOpacity},snappingPoint:{width:this.styles.snappingPointWidth,color:this.styles.snappingPointColor,opacity:this.styles.snappingPointOpacity,outlineColor:this.styles.snappingPointOutlineColor,outlineWidth:this.styles.snappingPointOutlineWidth,outlineOpacity:this.styles.snappingPointOutlineOpacity},coordinatePoint:{width:this.styles.coordinatePointWidth,color:this.styles.coordinatePointColor,opacity:this.styles.coordinatePointOpacity,outlineColor:this.styles.coordinatePointOutlineColor,outlineWidth:this.styles.coordinatePointOutlineWidth,outlineOpacity:this.styles.coordinatePointOutlineOpacity}};return t.pointWidth=this.getNumericStylingValue(a[i].width,t.pointWidth,e),t.pointOpacity=this.getNumericStylingValue(a[i].opacity,1,e),t.pointColor=this.getHexColorStylingValue(a[i].color,t.pointColor,e),t.pointOutlineColor=this.getHexColorStylingValue(a[i].outlineColor,t.pointOutlineColor,e),t.pointOutlineOpacity=this.getNumericStylingValue(a[i].outlineOpacity,1,e),t.pointOutlineWidth=this.getNumericStylingValue(a[i].outlineWidth,2,e),t.zIndex=n?40:r?20:30,t}}return t}afterFeatureAdded(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates})}afterFeatureUpdated(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates}),this.editedFeatureId===e.id&&this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0),this.snappedPointId&&this.lastMouseMoveEvent&&this.updateSnappedCoordinate(this.lastMouseMoveEvent),this.currentId===e.id&&(this.currentCoordinate=0,this.currentId=void 0,this.undoRedo.clear(),this.closingPoints.delete(),this.state===`drawing`&&this.setStarted())}validateFeature(e){return this.validateModeFeature(e,e=>Ot(e,this.coordinatePrecision))}},Dn={cancel:`Escape`,finish:`Enter`},On={start:`crosshair`},kn=class extends P{constructor(e){super(e,!0),this.mode=`rectangle`,this.startPosition=void 0,this.endPosition=void 0,this.currentRectangleId=void 0,this.keyEvents=Dn,this.cursors=On,this.drawInteraction=`click-move`,this.drawType=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.updateOptions(e)}updateOptions(e){super.updateOptions(e),e!=null&&e.cursors&&(this.cursors=O({},this.cursors,e.cursors)),e?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:e!=null&&e.keyEvents&&(this.keyEvents=O({},this.keyEvents,e.keyEvents)),e!=null&&e.drawInteraction&&(this.drawInteraction=e.drawInteraction)}updateRectangle(e,t){if(!this.startPosition||!this.currentRectangleId)return;let n=t===A.Finish;return this.mutateFeature.updatePolygon({featureId:this.currentRectangleId,coordinateMutations:[{type:H,index:1,coordinate:[e[0],this.startPosition[1]]},{type:H,index:2,coordinate:e},{type:H,index:3,coordinate:[this.startPosition[0],e[1]]}],propertyMutations:n?{[M.CURRENTLY_DRAWING]:void 0}:{},context:n?{updateType:t,action:k}:{updateType:t}})}close(){if(!this.currentRectangleId||!this.endPosition||!this.updateRectangle(this.endPosition,A.Finish))return;let e=this.currentRectangleId;this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,this.state===`drawing`&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:k})}beginDrawing(e,t=`click`){this.startPosition=[e.lng,e.lat],this.endPosition=[e.lng,e.lat],this.currentRectangleId=this.mutateFeature.createPolygon({coordinates:[[e.lng,e.lat],[e.lng,e.lat],[e.lng,e.lat],[e.lng,e.lat],[e.lng,e.lat]],properties:{mode:this.mode,[M.CURRENTLY_DRAWING]:!0}}).id,this.drawType=t,this.setDrawing()}moveDrawAllowed(){return this.drawInteraction===`click-move`||this.drawInteraction===`click-move-or-drag`}dragDrawAllowed(){return this.drawInteraction===`click-drag`||this.drawInteraction===`click-move-or-drag`}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onClick(e){this.moveDrawAllowed()&&(e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e))&&(this.startPosition?(this.endPosition=[e.lng,e.lat],this.close()):this.beginDrawing(e))}onMouseMove(e){this.endPosition=[e.lng,e.lat],this.updateRectangle(this.endPosition,A.Provisional)}onKeyDown(){}onKeyUp(e){e.key===this.keyEvents.cancel?this.cleanUp():e.key===this.keyEvents.finish&&this.close()}onDragStart(e,t){this.state!==`drawing`&&this.allowPointerEvent(this.pointerEvents.onDragStart,e)&&this.dragDrawAllowed()&&(this.beginDrawing(e,`drag`),t(!1))}onDrag(e,t){this.allowPointerEvent(this.pointerEvents.onDrag,e)&&this.dragDrawAllowed()&&this.drawType===`drag`&&(this.endPosition=[e.lng,e.lat],this.updateRectangle(this.endPosition,A.Provisional))}onDragEnd(e,t){this.allowPointerEvent(this.pointerEvents.onDragEnd,e)&&this.dragDrawAllowed()&&this.drawType===`drag`&&(this.endPosition=[e.lng,e.lat],this.close(),t(!0))}cleanUp(){let e=this.currentRectangleId;this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,this.state===`drawing`&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(e)}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return e.type===`Feature`&&e.geometry.type===`Polygon`&&e.properties.mode===this.mode?(t.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,t.polygonFillColor,e),t.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,t.polygonOutlineColor,e),t.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,e),t.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,t.polygonOutlineWidth,e),t.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,t.polygonFillOpacity,e),t.zIndex=N,t):t}validateFeature(e){return this.validateModeFeature(e,e=>kt(e,this.coordinatePrecision))}afterFeatureUpdated(e){this.currentRectangleId===e.id&&(this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,this.state===`drawing`&&this.setStarted())}registerBehaviors(e){this.readFeature=new K(e),this.mutateFeature=new W(e,{validate:this.validate})}},An=class extends P{constructor(e){if(!e.modeName)throw Error(`Mode name is required for TerraDrawRenderMode`);super(e,!0),this.type=lt.Render,this.mode=`render`,this.updateOptions(e)}updateOptions(e){super.updateOptions(e)}registerBehaviors(e){this.mode=e.mode}start(){this.setStarted()}stop(){this.setStopped()}onKeyUp(){}onKeyDown(){}onClick(){}onDragStart(){}onDrag(){}onDragEnd(){}onMouseMove(){}cleanUp(){}styleFeature(e){return{pointColor:this.getHexColorStylingValue(this.styles.pointColor,`#3f97e0`,e),pointWidth:this.getNumericStylingValue(this.styles.pointWidth,6,e),pointOpacity:this.getNumericStylingValue(this.styles.pointOpacity,1,e),pointOutlineColor:this.getHexColorStylingValue(this.styles.pointOutlineColor,`#ffffff`,e),pointOutlineWidth:this.getNumericStylingValue(this.styles.pointOutlineWidth,0,e),pointOutlineOpacity:this.getNumericStylingValue(this.styles.pointOutlineOpacity,1,e),polygonFillColor:this.getHexColorStylingValue(this.styles.polygonFillColor,`#3f97e0`,e),polygonFillOpacity:this.getNumericStylingValue(this.styles.polygonFillOpacity,.3,e),polygonOutlineColor:this.getHexColorStylingValue(this.styles.polygonOutlineColor,`#3f97e0`,e),polygonOutlineWidth:this.getNumericStylingValue(this.styles.polygonOutlineWidth,4,e),lineStringWidth:this.getNumericStylingValue(this.styles.lineStringWidth,4,e),lineStringColor:this.getHexColorStylingValue(this.styles.lineStringColor,`#3f97e0`,e),lineStringOpacity:this.getNumericStylingValue(this.styles.lineStringOpacity,1,e),zIndex:this.getNumericStylingValue(this.styles.zIndex,0,e)}}validateFeature(e){let t=super.validateFeature(e);if(t.valid){let t=e,n=bn(t,this.coordinatePrecision).valid||Ot(t,this.coordinatePrecision).valid||$t(t,this.coordinatePrecision).valid;return n?{valid:!0}:{valid:n,reason:`Feature is not a valid Point, Polygon or LineString feature`}}return t}};function jn(e,t){let n=e,r=t,i=I(n[1]),a=I(r[1]),o=I(r[0]-n[0]);o>Math.PI&&(o-=2*Math.PI),o<-Math.PI&&(o+=2*Math.PI);let s=Math.log(Math.tan(a/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),c=(L(Math.atan2(o,s))+360)%360;return c>180?-(360-c):c}function Mn(e,t,n){let r=t;t<0&&(r=-Math.abs(r));let i=r/ft,a=e[0]*Math.PI/180,o=I(e[1]),s=I(n),c=i*Math.cos(s),l=o+c;Math.abs(l)>Math.PI/2&&(l=l>0?Math.PI-l:-Math.PI-l);let u=Math.log(Math.tan(l/2+Math.PI/4)/Math.tan(o/2+Math.PI/4)),d=Math.abs(u)>1e-11?c/u:Math.cos(o),f=[(180*(a+i*Math.sin(s)/d)/Math.PI+540)%360-180,180*l/Math.PI];return f[0]+=f[0]-e[0]>180?-360:e[0]-f[0]>180?360:0,f}function Nn(e,t,n,r,i){let a=r(e[0],e[1]),o=r(t[0],t[1]),{lng:s,lat:c}=i((a.x+o.x)/2,(a.y+o.y)/2);return[R(s,n),R(c,n)]}function Pn(e,t,n){let r=Mn(e,1e3*F(e,t)/2,jn(e,t));return[R(r[0],n),R(r[1],n)]}function Fn({featureCoords:e,precision:t,unproject:n,project:r,projection:i}){let a=[];for(let o=0;o<e.length-1;o++){let s;if(i===`web-mercator`)s=Nn(e[o],e[o+1],t,r,n);else{if(i!==`globe`)throw Error(`Invalid projection`);s=Pn(e[o],e[o+1],t)}a.push(s)}return a}var In=class extends V{constructor(e,t,n,r,i,a){super(e),this.config=void 0,this.selectionPointBehavior=void 0,this.coordinatePointBehavior=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.pixelDistance=void 0,this._midPoints=[],this.config=e,this.selectionPointBehavior=t,this.coordinatePointBehavior=n,this.mutateFeature=r,this.readFeature=i,this.pixelDistance=a}getMidpointConfig(e){return{featureCoords:e,precision:this.coordinatePrecision,project:this.config.project,unproject:this.config.unproject,projection:this.config.projection}}get ids(){return this._midPoints.concat()}set ids(e){}getNearestMidPoint(e){let t,n=1/0;return this.ids.forEach(r=>{let i=this.readFeature.getGeometry(r),a=this.pixelDistance.measure(e,i.coordinates);a<this.pointerDistance&&a<n&&(n=a,t=r)}),t}insert({featureId:e,midPointId:t}){let n=this.readFeature.getGeometry(t),{midPointFeatureId:r,midPointSegment:i}=this.readFeature.getProperties(t),a=this.readFeature.getGeometry(r),o={featureId:r,coordinateMutations:[{type:Mt,index:i,coordinate:n.coordinates}],context:{updateType:A.Commit}},s=null;if(a.type===`Polygon`)s=this.mutateFeature.updatePolygon(o);else{if(a.type!==`LineString`)throw Error(`Midpoints can only be added to polygons or linestrings`);s=this.mutateFeature.updateLineString(o)}if(!s)throw Error(`Failed to insert midpoint coordinate`);let c=s.geometry.coordinates;this.readFeature.getProperties(e)[M.COORDINATE_POINT_IDS]&&this.coordinatePointBehavior.createOrUpdate({featureId:e,featureCoordinates:c}),this.mutateFeature.deleteFeaturesIfPresent([...this.selectionPointBehavior.ids,...this._midPoints]),this.create({featureCoordinates:c,featureId:r}),this.selectionPointBehavior.create({featureCoordinates:c,featureId:e})}create({featureCoordinates:e,featureId:t}){if(!this.readFeature.hasFeature(t))throw Error(`Store does not have feature with this id`);let n=un(e),r=Fn(this.getMidpointConfig(n));this._midPoints=this.mutateFeature.createGuidancePoints({additionalProperties:e=>({mode:this.mode,midPointSegment:e,midPointFeatureId:t,[j.MID_POINT]:!0}),coordinates:r,type:j.MID_POINT})}delete(){this._midPoints.length&&(this.mutateFeature.deleteFeaturesIfPresent(this._midPoints),this._midPoints=[])}updateAllInPlace({featureCoordinates:e}){if(this._midPoints.length===0)return;let t=un(e),n=Fn(this.getMidpointConfig(t));this.mutateFeature.updateGuidancePoints(this._midPoints.map((e,t)=>({featureId:e,coordinate:n[t]})))}updateOneAtIndex(e,t){if(e<0&&(e=this._midPoints.length+e),this._midPoints[e]===void 0)return;let n=un(t),r=Fn(this.getMidpointConfig(n));this.mutateFeature.updateGuidancePoints([{featureId:this._midPoints[e],coordinate:r[e]}])}},Ln=class extends V{constructor(e,t){super(e),this.mutateFeature=void 0,this._selectionPoints=[],this.mutateFeature=t}get ids(){return this._selectionPoints.concat()}set ids(e){}create({featureId:e,featureCoordinates:t}){let n=ln(t);this._selectionPoints=this.mutateFeature.createGuidancePoints({coordinates:n,type:j.SELECTION_POINT,additionalProperties:t=>({[j.SELECTION_POINT_FEATURE_ID]:e,index:t})})}delete(){this.ids.length&&(this.mutateFeature.deleteFeaturesIfPresent(this.ids),this._selectionPoints=[])}updateAllInPlace({featureCoordinates:e}){if(this._selectionPoints.length===0)return;let t=ln(e);t.length===this._selectionPoints.length&&this.mutateFeature.updateGuidancePoints(this._selectionPoints.map((e,n)=>({featureId:e,coordinate:t[n]})))}updateOneAtIndex(e,t){this._selectionPoints[e]!==void 0&&this.mutateFeature.updateGuidancePoints([{featureId:this._selectionPoints[e],coordinate:t}])}};function Rn(e,t){let n=!1;for(let o=0,s=t.length;o<s;o++){let s=t[o];for(let t=0,o=s.length,c=o-1;t<o;c=t++)(i=s[t])[1]>(r=e)[1]!=(a=s[c])[1]>r[1]&&r[0]<(a[0]-i[0])*(r[1]-i[1])/(a[1]-i[1])+i[0]&&(n=!n)}var r,i,a;return n}var zn=(e,t,n)=>{let r=e=>e*e,i=(e,t)=>r(e.x-t.x)+r(e.y-t.y);return Math.sqrt(((e,t,n)=>{let r=i(t,n);if(r===0)return i(e,t);let a=((e.x-t.x)*(n.x-t.x)+(e.y-t.y)*(n.y-t.y))/r;return a=Math.max(0,Math.min(1,a)),i(e,{x:t.x+a*(n.x-t.x),y:t.y+a*(n.y-t.y)})})(e,t,n))},Bn=class extends V{constructor(e,t,n){super(e),this.config=void 0,this.createClickBoundingBox=void 0,this.pixelDistance=void 0,this.config=e,this.createClickBoundingBox=t,this.pixelDistance=n}find(e,t){let n,r,i,a=1/0,o=1/0,s=this.createClickBoundingBox.create(e),c=this.store.search(s);for(let s=0;s<c.length;s++){let l=c[s],u=l.geometry;if(u.type===`Point`){if(l.properties.selectionPoint||l.properties.coordinatePoint||!t&&l.properties[j.MID_POINT])continue;let r=this.pixelDistance.measure(e,u.coordinates);!l.properties[j.MID_POINT]&&r<this.pointerDistance&&r<a&&(a=r,n=l)}else if(u.type===`LineString`){if(n)continue;for(let t=0;t<u.coordinates.length-1;t++){let n=u.coordinates[t],i=u.coordinates[t+1],a=zn({x:e.containerX,y:e.containerY},this.project(n[0],n[1]),this.project(i[0],i[1]));a<this.pointerDistance&&a<o&&(o=a,r=l)}}else if(u.type===`Polygon`){if(n||r)continue;Rn([e.lng,e.lat],u.coordinates)&&(i=l)}}return{clickedFeature:n||r||i}}},Vn=class extends V{constructor(e,t,n,r,i,a,o){super(e),this.config=void 0,this.featuresAtCursorEvent=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.coordinatePoints=void 0,this.readFeature=void 0,this.mutateFeature=void 0,this.draggedFeatureId=null,this.dragPosition=void 0,this.config=e,this.featuresAtCursorEvent=t,this.selectionPoints=n,this.midPoints=r,this.coordinatePoints=i,this.readFeature=a,this.mutateFeature=o}startDragging(e,t){this.draggedFeatureId=t,this.dragPosition=[e.lng,e.lat]}stopDragging(){this.draggedFeatureId=null,this.dragPosition=void 0}isDragging(){return this.draggedFeatureId!==null}canDrag(e,t){let{clickedFeature:n}=this.featuresAtCursorEvent.find(e,!0);return!(!n||n.id!==t)}drag(e){if(!this.draggedFeatureId)return;let t=this.readFeature.getGeometry(this.draggedFeatureId),n=[e.lng,e.lat];if(t.type===`Polygon`||t.type===`LineString`){let r,i;if(t.type===`Polygon`?(r=t.coordinates[0],i=r.length-1):(r=t.coordinates,i=r.length),!this.dragPosition)return!1;for(let e=0;e<i;e++){let t=r[e],i,a;if(this.config.projection===`web-mercator`){let e=z(this.dragPosition[0],this.dragPosition[1]),r=z(n[0],n[1]),o=z(t[0],t[1]),s={x:e.x-r.x,y:e.y-r.y},{lng:c,lat:l}=B(o.x-s.x,o.y-s.y);i=c,a=l}else{let e=[this.dragPosition[0]-n[0],this.dragPosition[1]-n[1]];i=t[0]-e[0],a=t[1]-e[1]}if(i=R(i,this.config.coordinatePrecision),a=R(a,this.config.coordinatePrecision),i>180||i<-180||a>90||a<-90)return!1;r[e]=[i,a]}t.type===`Polygon`&&(r[r.length-1]=[r[0][0],r[0][1]]);let a=this.draggedFeatureId,o=null;if(t.type===`Polygon`)o=this.mutateFeature.updatePolygon({featureId:a,coordinateMutations:{type:U,coordinates:[r]},context:{updateType:A.Provisional}});else{if(t.type!==`LineString`)return;o=this.mutateFeature.updateLineString({featureId:a,coordinateMutations:{type:U,coordinates:r},context:{updateType:A.Provisional}})}if(!o)return!1;let s=o.geometry.coordinates;this.midPoints.updateAllInPlace({featureCoordinates:s}),this.selectionPoints.updateAllInPlace({featureCoordinates:s}),this.coordinatePoints.updateAllInPlace({featureId:a,featureCoordinates:s}),this.dragPosition=[e.lng,e.lat]}else t.type===`Point`&&(this.mutateFeature.updatePoint({featureId:this.draggedFeatureId,coordinateMutations:{type:U,coordinates:n},context:{updateType:A.Provisional}}),this.dragPosition=[e.lng,e.lat])}},Hn=class extends V{constructor(e,t,n,r,i,a,o,s,c){super(e),this.config=void 0,this.pixelDistance=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.coordinatePoints=void 0,this.coordinateSnapping=void 0,this.lineSnapping=void 0,this.readFeature=void 0,this.mutateFeature=void 0,this.draggedCoordinate={id:null,index:-1},this.config=e,this.pixelDistance=t,this.selectionPoints=n,this.midPoints=r,this.coordinatePoints=i,this.coordinateSnapping=a,this.lineSnapping=o,this.readFeature=s,this.mutateFeature=c}getClosestCoordinate(e,t){let n={dist:1/0,index:-1,isFirstOrLastPolygonCoord:!1},r;if(t.type===`LineString`)r=t.coordinates;else{if(t.type!==`Polygon`)return n;r=t.coordinates[0]}for(let i=0;i<r.length;i++){let a=this.pixelDistance.measure(e,r[i]);if(a<this.pointerDistance&&a<n.dist){let e=t.type===`Polygon`&&(i===r.length-1||i===0);n.dist=a,n.index=e?0:i,n.isFirstOrLastPolygonCoord=e}}return n}getDraggable(e,t){let n=this.readFeature.getGeometry(t);return this.getClosestCoordinate(e,n)}getDraggableIndex(e,t){let n=this.readFeature.getGeometry(t),r=this.getClosestCoordinate(e,n);return r.index===-1?-1:r.index}snapCoordinate(e,t,n){let r=[e.lng,e.lat],i=e=>!!(e.properties&&e.properties.mode===n.properties.mode&&e.id!==this.draggedCoordinate.id);if(t!=null&&t.toLine){let t;t=this.lineSnapping.getSnappable(e,i).coordinate,t&&(r=t)}if(t.toCoordinate){let t;t=this.coordinateSnapping.getSnappable(e,i).coordinate,t&&(r=t)}if(t!=null&&t.toCustom){let i;i=t.toCustom(e,{currentCoordinate:this.draggedCoordinate.index,currentId:n.id,getCurrentGeometrySnapshot:n.id?()=>this.readFeature.getGeometry(n.id):()=>null,project:this.project,unproject:this.unproject}),i&&(r=i)}return r}drag(e,t,n){let r=this.draggedCoordinate.id;if(r===null)return!1;let i=this.draggedCoordinate.index,a=this.readFeature.getGeometry(r),o=this.readFeature.getProperties(r),s=a.type===`LineString`?a.coordinates:a.coordinates[0],c=a.type===`Polygon`&&(i===s.length-1||i===0),l=this.snapCoordinate(e,n,{type:`Feature`,id:r,geometry:a,properties:o});if(e.lng>180||e.lng<-180||e.lat>90||e.lat<-90)return!1;if(c){let e=s.length-1;s[0]=l,s[e]=l}else s[i]=l;if(a.type!==`Point`&&!t&&yt({type:`Feature`,geometry:a,properties:{}}))return!1;let u=r,d=null;return a.type===`Polygon`?d=this.mutateFeature.updatePolygon({featureId:u,coordinateMutations:{type:U,coordinates:[s]},context:{updateType:A.Provisional}}):a.type===`LineString`&&(d=this.mutateFeature.updateLineString({featureId:u,coordinateMutations:{type:U,coordinates:s},context:{updateType:A.Provisional}})),!!d&&(this.midPoints.updateOneAtIndex(i>0?i-1:-1,s),this.midPoints.updateOneAtIndex(i,s),this.selectionPoints.updateOneAtIndex(i,l),this.coordinatePoints.updateOneAtIndex(u,i,l),!0)}isDragging(){return this.draggedCoordinate.id!==null}startDragging(e,t){this.draggedCoordinate={id:e,index:t}}stopDragging(){this.draggedCoordinate={id:null,index:-1}}};function Un(e){let t=0,n=0,r=0;return(e.geometry.type===`Polygon`?e.geometry.coordinates[0].slice(0,-1):e.geometry.coordinates).forEach(e=>{t+=e[0],n+=e[1],r++},!0),[t/r,n/r]}var Wn=(e,t)=>{if(t===0||t===360||t===-360)return e;let n=.017453292519943295*t,r=(e.geometry.type===`Polygon`?e.geometry.coordinates[0]:e.geometry.coordinates).map(([e,t])=>z(e,t)),i=r.reduce((e,t)=>({x:e.x+t.x,y:e.y+t.y}),{x:0,y:0});i.x/=r.length,i.y/=r.length;let a=r.map(e=>({x:i.x+(e.x-i.x)*Math.cos(n)-(e.y-i.y)*Math.sin(n),y:i.y+(e.x-i.x)*Math.sin(n)+(e.y-i.y)*Math.cos(n)})).map(({x:e,y:t})=>[B(e,t).lng,B(e,t).lat]);return e.geometry.type===`Polygon`?e.geometry.coordinates[0]=a:e.geometry.coordinates=a,e};function Gn(e){let t=(e.geometry.type===`Polygon`?e.geometry.coordinates[0]:e.geometry.coordinates).map(e=>{let{x:t,y:n}=z(e[0],e[1]);return[t,n]});return e.geometry.type===`Polygon`?function(e){let t=0,n=0,r=0,i=e.length;for(let a=0;a<i-1;a++){let[i,o]=e[a],[s,c]=e[a+1],l=i*c-s*o;t+=l,n+=(i+s)*l,r+=(o+c)*l}return t/=2,n/=6*t,r/=6*t,{x:n,y:r}}(t):function(e){let t=e.length,n=0,r=0;for(let i=0;i<t;i++){let[t,a]=e[i];n+=t,r+=a}return{x:n/t,y:r/t}}(t)}var Kn=class extends V{constructor(e,t,n,r,i,a){super(e),this.config=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.coordinatePoints=void 0,this.readFeature=void 0,this.mutateFeature=void 0,this.lastBearing=void 0,this.selectedGeometry=void 0,this.selectedGeometryCentroid=void 0,this.selectedGeometryWebMercatorCentroid=void 0,this.config=e,this.selectionPoints=t,this.midPoints=n,this.coordinatePoints=r,this.readFeature=i,this.mutateFeature=a}reset(){this.lastBearing=void 0,this.selectedGeometry=void 0,this.selectedGeometryWebMercatorCentroid=void 0,this.selectedGeometryCentroid=void 0}rotate(e,t){this.selectedGeometry||=this.readFeature.getGeometry(t);let n=this.selectedGeometry;if(n.type!==`Polygon`&&n.type!==`LineString`)return;let r=[e.lng,e.lat],i,a={type:`Feature`,geometry:n,properties:{}};if(this.config.projection===`web-mercator`){this.selectedGeometryWebMercatorCentroid||=Gn(a);let t=z(e.lng,e.lat);if(i=q(this.selectedGeometryWebMercatorCentroid,t),i===0)return;if(!this.lastBearing)return void(this.lastBearing=i);Wn(a,-(this.lastBearing-i))}else{if(this.config.projection!==`globe`)throw Error(`Unsupported projection`);if(this.selectedGeometryCentroid||=Un({type:`Feature`,geometry:n,properties:{}}),i=jn(this.selectedGeometryCentroid,r),!this.lastBearing)return void(this.lastBearing=i+180);(function(e,t){if(t===0||t===360||t===-360)return e;let n=Un(e);(e.geometry.type===`Polygon`?e.geometry.coordinates[0]:e.geometry.coordinates).forEach(e=>{let r=jn(n,e)+t,i=Mn(n,function(e,t){e[0]+=e[0]-t[0]>180?-360:t[0]-e[0]>180?360:0;let n=ft,r=t[1]*Math.PI/180,i=e[1]*Math.PI/180,a=i-r,o=Math.abs(e[0]-t[0])*Math.PI/180;o>Math.PI&&(o-=2*Math.PI);let s=Math.log(Math.tan(i/2+Math.PI/4)/Math.tan(r/2+Math.PI/4)),c=Math.abs(s)>1e-11?a/s:Math.cos(r);return Math.sqrt(a*a+c*c*o*o)*n}(n,e),r);e[0]=i[0],e[1]=i[1]})})(a,-(this.lastBearing-(i+180)))}let o=n.type===`Polygon`?n.coordinates[0]:n.coordinates;o.forEach(e=>{e[0]=R(e[0],this.coordinatePrecision),e[1]=R(e[1],this.coordinatePrecision)});let s={featureId:t,coordinateMutations:{type:U,coordinates:n.type===`Polygon`?[o]:o},context:{updateType:A.Provisional}},c=null;if(a.geometry.type===`Polygon`)c=this.mutateFeature.updatePolygon(s);else{if(a.geometry.type!==`LineString`)return;c=this.mutateFeature.updateLineString(s)}if(!c)return!1;let l=c.geometry.coordinates;this.midPoints.updateAllInPlace({featureCoordinates:l}),this.selectionPoints.updateAllInPlace({featureCoordinates:l}),this.coordinatePoints.updateAllInPlace({featureId:t,featureCoordinates:l}),this.projection===`web-mercator`?this.lastBearing=i:this.projection===`globe`&&(this.lastBearing=i+180)}},qn=class extends V{constructor(e,t){super(e),this.config=void 0,this.dragCoordinateResizeBehavior=void 0,this.config=e,this.dragCoordinateResizeBehavior=t}scale(e,t){if(!this.dragCoordinateResizeBehavior.isDragging()){let n=this.dragCoordinateResizeBehavior.getDraggableIndex(e,t);this.dragCoordinateResizeBehavior.startDragging(t,n)}this.dragCoordinateResizeBehavior.drag(e,`center-fixed`)}reset(){this.dragCoordinateResizeBehavior.stopDragging()}};function Jn({coordinates:e,originX:t,originY:n,xScale:r,yScale:i}){r===1&&i===1||e.forEach(e=>{let{x:a,y:o}=z(e[0],e[1]),{lng:s,lat:c}=B(t+(a-t)*r,n+(o-n)*i);e[0]=s,e[1]=c})}var Yn=class extends V{constructor(e,t,n,r,i,a,o){super(e),this.config=void 0,this.pixelDistance=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.coordinatePoints=void 0,this.readFeature=void 0,this.mutateFeature=void 0,this.minimumScale=1e-4,this.draggedCoordinate={id:null,index:-1},this.boundingBoxMaps={opposite:{0:4,1:5,2:6,3:7,4:0,5:1,6:2,7:3}},this.config=e,this.pixelDistance=t,this.selectionPoints=n,this.midPoints=r,this.coordinatePoints=i,this.readFeature=a,this.mutateFeature=o}getClosestCoordinate(e,t){let n={dist:1/0,index:-1,isFirstOrLastPolygonCoord:!1},r;if(t.type===`LineString`)r=t.coordinates;else{if(t.type!==`Polygon`)return n;r=t.coordinates[0]}for(let i=0;i<r.length;i++){let a=this.pixelDistance.measure(e,r[i]);if(a<this.pointerDistance&&a<n.dist){let e=t.type===`Polygon`&&(i===r.length-1||i===0);n.dist=a,n.index=e?0:i,n.isFirstOrLastPolygonCoord=e}}return n}isValidDragWebMercator(e,t,n){switch(e){case 0:if(t<=0||n>=0)return!1;break;case 1:if(n>=0)return!1;break;case 2:if(t>=0||n>=0)return!1;break;case 3:if(t>=0)return!1;break;case 4:if(t>=0||n<=0)return!1;break;case 5:if(n<=0)return!1;break;case 6:if(t<=0||n<=0)return!1;break;case 7:if(t<=0)return!1}return!0}getSelectedFeatureDataWebMercator(){if(!this.draggedCoordinate.id||this.draggedCoordinate.index===-1)return null;let e=this.getFeature(this.draggedCoordinate.id);if(!e)return null;let t=this.getNormalisedCoordinates(e.geometry);return{boundingBox:this.getBBoxWebMercator(t),feature:e,updatedCoords:t,selectedCoordinate:t[this.draggedCoordinate.index]}}centerWebMercatorDrag(e){let t=this.getSelectedFeatureDataWebMercator();if(!t)return null;let{feature:n,boundingBox:r,updatedCoords:i,selectedCoordinate:a}=t,o=Gn(n);if(!o)return null;let s=z(a[0],a[1]),{closestBBoxIndex:c}=this.getIndexesWebMercator(r,s),l=z(e.lng,e.lat);return this.scaleWebMercator({closestBBoxIndex:c,updatedCoords:i,webMercatorCursor:l,webMercatorSelected:s,webMercatorOrigin:o}),i}centerFixedWebMercatorDrag(e){let t=this.getSelectedFeatureDataWebMercator();if(!t)return null;let{feature:n,boundingBox:r,updatedCoords:i,selectedCoordinate:a}=t,o=Gn(n);if(!o)return null;let s=z(a[0],a[1]),{closestBBoxIndex:c}=this.getIndexesWebMercator(r,s),l=z(e.lng,e.lat);return this.scaleFixedWebMercator({closestBBoxIndex:c,updatedCoords:i,webMercatorCursor:l,webMercatorSelected:s,webMercatorOrigin:o}),i}scaleFixedWebMercator({closestBBoxIndex:e,webMercatorOrigin:t,webMercatorSelected:n,webMercatorCursor:r,updatedCoords:i}){if(!this.isValidDragWebMercator(e,t.x-r.x,t.y-r.y))return null;let a=G(t,r)/G(t,n);return a<0&&(a=this.minimumScale),Jn({coordinates:i,originX:t.x,originY:t.y,xScale:a,yScale:a}),i}oppositeFixedWebMercatorDrag(e){let t=this.getSelectedFeatureDataWebMercator();if(!t)return null;let{boundingBox:n,updatedCoords:r,selectedCoordinate:i}=t,a=z(i[0],i[1]),{oppositeBboxIndex:o,closestBBoxIndex:s}=this.getIndexesWebMercator(n,a),c={x:n[o][0],y:n[o][1]},l=z(e.lng,e.lat);return this.scaleFixedWebMercator({closestBBoxIndex:s,updatedCoords:r,webMercatorCursor:l,webMercatorSelected:a,webMercatorOrigin:c}),r}oppositeWebMercatorDrag(e){let t=this.getSelectedFeatureDataWebMercator();if(!t)return null;let{boundingBox:n,updatedCoords:r,selectedCoordinate:i}=t,a=z(i[0],i[1]),{oppositeBboxIndex:o,closestBBoxIndex:s}=this.getIndexesWebMercator(n,a),c={x:n[o][0],y:n[o][1]},l=z(e.lng,e.lat);return this.scaleWebMercator({closestBBoxIndex:s,updatedCoords:r,webMercatorCursor:l,webMercatorSelected:a,webMercatorOrigin:c}),r}scaleWebMercator({closestBBoxIndex:e,webMercatorOrigin:t,webMercatorSelected:n,webMercatorCursor:r,updatedCoords:i}){let a=t.x-r.x,o=t.y-r.y;if(!this.isValidDragWebMercator(e,a,o))return null;let s=1;a!==0&&e!==1&&e!==5&&(s=1-(t.x-n.x-a)/a);let c=1;return o!==0&&e!==3&&e!==7&&(c=1-(t.y-n.y-o)/o),this.validateScale(s,c)?(s<0&&(s=this.minimumScale),c<0&&(c=this.minimumScale),this.performWebMercatorScale(i,t.x,t.y,s,c),i):null}getFeature(e){if(this.draggedCoordinate.id===null)return null;let t=this.readFeature.getGeometry(e);return t.type!==`Polygon`&&t.type!==`LineString`?null:{id:e,type:`Feature`,geometry:t,properties:{}}}getNormalisedCoordinates(e){return e.type===`Polygon`?e.coordinates[0]:e.coordinates}validateScale(e,t){return!isNaN(e)&&t<2**53-1&&!isNaN(t)&&t<2**53-1}performWebMercatorScale(e,t,n,r,i){e.forEach(e=>{let{x:a,y:o}=z(e[0],e[1]),{lng:s,lat:c}=B(t+(a-t)*r,n+(o-n)*i);e[0]=s,e[1]=c})}getBBoxWebMercator(e){let t=[1/0,1/0,-1/0,-1/0];(e=e.map(e=>{let{x:t,y:n}=z(e[0],e[1]);return[t,n]})).forEach(([e,n])=>{e<t[0]&&(t[0]=e),n<t[1]&&(t[1]=n),e>t[2]&&(t[2]=e),n>t[3]&&(t[3]=n)});let[n,r,i,a]=t;return[[n,a],[(n+i)/2,a],[i,a],[i,a+(r-a)/2],[i,r],[(n+i)/2,r],[n,r],[n,a+(r-a)/2]]}getIndexesWebMercator(e,t){let n,r=1/0;for(let i=0;i<e.length;i++){let a=G({x:t.x,y:t.y},{x:e[i][0],y:e[i][1]});a<r&&(n=i,r=a)}if(n===void 0)throw Error(`No closest coordinate found`);return{oppositeBboxIndex:this.boundingBoxMaps.opposite[n],closestBBoxIndex:n}}isDragging(){return this.draggedCoordinate.id!==null}startDragging(e,t){this.draggedCoordinate={id:e,index:t}}stopDragging(){this.draggedCoordinate={id:null,index:-1}}getDraggableIndex(e,t){let n=this.readFeature.getGeometry(t),r=this.getClosestCoordinate(e,n);return r.index===-1?-1:r.index}drag(e,t){if(!this.draggedCoordinate.id)return!1;let n=this.getFeature(this.draggedCoordinate.id);if(!n)return!1;let r=null;if(t===`center`?r=this.centerWebMercatorDrag(e):t===`opposite`?r=this.oppositeWebMercatorDrag(e):t===`center-fixed`?r=this.centerFixedWebMercatorDrag(e):t===`opposite-fixed`&&(r=this.oppositeFixedWebMercatorDrag(e)),!r)return!1;for(let e=0;e<r.length;e++){let t=r[e];if(t[0]=R(t[0],this.coordinatePrecision),t[1]=R(t[1],this.coordinatePrecision),!xt(t,this.coordinatePrecision))return!1}let i=n.id,a=null;if(n.geometry.type===`Polygon`?a=this.mutateFeature.updatePolygon({featureId:i,coordinateMutations:{type:U,coordinates:[r]},context:{updateType:A.Provisional}}):n.geometry.type===`LineString`&&(a=this.mutateFeature.updateLineString({featureId:i,coordinateMutations:{type:U,coordinates:r},context:{updateType:A.Provisional}})),!a)return!1;let o=a.geometry.coordinates;return this.midPoints.updateAllInPlace({featureCoordinates:o}),this.selectionPoints.updateAllInPlace({featureCoordinates:o}),this.coordinatePoints.updateAllInPlace({featureId:i,featureCoordinates:o}),!0}},Xn={deselect:`Escape`,delete:`Delete`,rotate:[`Control`,`r`],scale:[`Control`,`s`]},Zn={pointerOver:`move`,dragStart:`move`,dragEnd:`move`,insertMidpoint:`crosshair`},Qn=class extends dt{constructor(e){super(e,!0),this.mode=`select`,this.allowManualDeselection=!0,this.allowManualSelection=!0,this.dragEventThrottle=5,this.dragEventCount=0,this.selected=[],this.flags={},this.keyEvents=Xn,this.cursors=Zn,this.validations={},this.dragTarget={type:`none`},this.selectionPoints=void 0,this.midPoints=void 0,this.coordinateSnap=void 0,this.featuresAtMouseEvent=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.dragFeature=void 0,this.dragCoordinate=void 0,this.rotateFeature=void 0,this.scaleFeature=void 0,this.dragCoordinateResizeFeature=void 0,this.coordinatePoints=void 0,this.lineSnap=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.updateOptions(e)}updateOptions(e){if(super.updateOptions(e),this.cursors=e&&e.cursors?O({},this.cursors,e.cursors):Zn,e?.keyEvents===null?this.keyEvents={deselect:null,delete:null,rotate:null,scale:null}:e!=null&&e.keyEvents&&(this.keyEvents=O({},this.keyEvents,e.keyEvents)),e?.dragEventThrottle!==void 0&&(this.dragEventThrottle=e.dragEventThrottle),e?.allowManualDeselection!==void 0&&(this.allowManualDeselection=e.allowManualDeselection),e?.allowManualSelection!==void 0&&(this.allowManualSelection=e.allowManualSelection),e!=null&&e.flags){this.flags=O({},this.flags,e.flags),this.validations={};for(let e in this.flags){let t=this.flags[e].feature;t&&t.validation&&(this.validations[e]=t.validation)}}}selectFeature(e){this.select(e,!1)}setSelecting(){if(this._state!==`started`)throw Error(`Mode must be started to move to selecting state`);this._state=`selecting`}registerBehaviors(e){this.readFeature=new K(e),this.mutateFeature=new W(e,{validate:(e,t)=>{let n=e.properties.mode;return this.validations&&this.validations[n]?this.validations[n](e,t):{valid:!0}}}),this.pixelDistance=new Ut(e),this.clickBoundingBox=new Ht(e),this.featuresAtMouseEvent=new Bn(e,this.clickBoundingBox,this.pixelDistance),this.selectionPoints=new Ln(e,this.mutateFeature),this.coordinatePoints=new fn(e,this.readFeature,this.mutateFeature),this.midPoints=new In(e,this.selectionPoints,this.coordinatePoints,this.mutateFeature,this.readFeature,this.pixelDistance),this.coordinateSnap=new Wt(e,this.pixelDistance,this.clickBoundingBox),this.lineSnap=new sn(e,this.pixelDistance,this.clickBoundingBox),this.rotateFeature=new Kn(e,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.dragFeature=new Vn(e,this.featuresAtMouseEvent,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.dragCoordinate=new Hn(e,this.pixelDistance,this.selectionPoints,this.midPoints,this.coordinatePoints,this.coordinateSnap,this.lineSnap,this.readFeature,this.mutateFeature),this.dragCoordinateResizeFeature=new Yn(e,this.pixelDistance,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.scaleFeature=new qn(e,this.dragCoordinateResizeFeature)}deselectFeature(e){this.deselect(e)}deselect(e){this.selected.includes(e)&&(this.mutateFeature.setDeselected(this.selected),this.onDeselect(this.selected[0]),this.selected=[],this.selectionPoints.delete(),this.midPoints.delete(),this.dragTarget={type:`none`})}deleteSelected(){this.selected.length&&this.mutateFeature.deleteFeaturesIfPresent(this.selected),this.selected=[],this.dragTarget={type:`none`}}clearDragTargetAndCursor(){this.dragTarget={type:`none`},this.setCursor(`unset`)}getSelectedFlags(e){let t=this.readFeature.getProperties(e),n=this.flags[t.mode]?.feature,r=n?.coordinates;return{featureFlags:n,coordinatesFlags:r,hasDraggableFlags:n&&(n.draggable||r?.draggable||r?.resizable||typeof r?.midpoints==`object`&&r.midpoints.draggable)}}onRightClick(e){if(!this.selectionPoints.ids.length)return;let t,n=1/0;if(this.selectionPoints.ids.forEach(r=>{let i=this.readFeature.getGeometry(r),a=this.pixelDistance.measure(e,i.coordinates);a<this.pointerDistance&&a<n&&(n=a,t=this.readFeature.getProperties(r))}),!t)return;let r=t.selectionPointFeatureId,i=t.index,a=this.readFeature.getProperties(r),o=this.flags[a.mode];if(!(o&&o.feature&&o.feature.coordinates&&o.feature.coordinates.deletable))return;let s=this.readFeature.getGeometry(r),c;if(s.type===`Polygon`){if(c=s.coordinates[0],c.length<=4)return}else if(s.type!==`LineString`||(c=s.coordinates,c.length<=2))return;s.type!==`Polygon`||i!==0&&i!==c.length-1?c.splice(i,1):(c.shift(),c.pop(),c.push([c[0][0],c[0][1]]));let l=null;if(s.type===`Polygon`?l=this.mutateFeature.updatePolygon({featureId:r,coordinateMutations:{type:U,coordinates:[c]},context:{updateType:A.Commit}}):s.type===`LineString`&&(l=this.mutateFeature.updateLineString({featureId:r,coordinateMutations:{type:U,coordinates:c},context:{updateType:A.Commit}})),!l)return;let u=l.geometry.coordinates;this.mutateFeature.deleteFeaturesIfPresent([...this.midPoints.ids,...this.selectionPoints.ids]),a.coordinatePointIds&&this.coordinatePoints.createOrUpdate({featureId:r,featureCoordinates:u}),this.selectionPoints.create({featureCoordinates:u,featureId:r}),o&&o.feature&&o.feature.coordinates&&o.feature.coordinates.midpoints&&this.midPoints.create({featureCoordinates:u,featureId:r}),this.onFinish(r,{action:nt,mode:this.mode})}select(e,t=!0){if(this.selected[0]===e)return;let{mode:n}=this.readFeature.getProperties(e),r=this.flags[n];if(!r||!r.feature)return;let i=this.selected[0];if(i){if(i===e)return;this.deselect(i)}t&&this.setCursor(this.cursors.pointerOver),this.selected=[e],this.mutateFeature.setSelected(e),this.onSelect(e);let{type:a,coordinates:o}=this.readFeature.getGeometry(e);a!==`LineString`&&a!==`Polygon`||o&&r&&r.feature.coordinates&&(this.selectionPoints.create({featureCoordinates:o,featureId:e}),r.feature.coordinates.midpoints&&this.midPoints.create({featureCoordinates:o,featureId:e}))}onLeftClick(e){let{clickedFeature:t}=this.featuresAtMouseEvent.find(e,this.selected.length>0),n=this.midPoints.getNearestMidPoint(e),r=this.selected[0];if(r){var i;let{featureFlags:t}=this.getSelectedFlags(r);if(t!=null&&(i=t.coordinates)!=null&&i.midpoints&&n){if(t.coordinates.draggable){let t=this.pixelDistance.measure(e,this.readFeature.getGeometry(n).coordinates),{dist:i}=this.dragCoordinate.getDraggable(e,r);if(i!==void 0&&t>i)return}this.midPoints.insert({featureId:r,midPointId:n}),this.onFinish(this.selected[0],{action:rt,mode:this.mode});return}}if(t!=null&&t.id)this.allowManualSelection&&this.select(t.id,!0);else if(this.selected.length&&this.allowManualDeselection)return void this.deselect(this.selected[0])}start(){this.setStarted(),this.setSelecting()}stop(){this.cleanUp(),this.setStarted(),this.setStopped()}onClick(e){e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e)?this.onRightClick(e):e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)&&this.onLeftClick(e)}canScale(e){return this.keyEvents.scale&&this.keyEvents.scale.every(t=>e.heldKeys.includes(t))}canRotate(e){return this.keyEvents.rotate&&this.keyEvents.rotate.every(t=>e.heldKeys.includes(t))}preventDefaultKeyEvent(e){let t=this.canRotate(e),n=this.canScale(e);(t||n)&&e.preventDefault()}onKeyDown(e){this.preventDefaultKeyEvent(e)}onKeyUp(e){if(this.preventDefaultKeyEvent(e),this.keyEvents.delete&&e.key===this.keyEvents.delete){if(!this.selected.length)return;let e=this.selected[0];this.onDeselect(this.selected[0]),this.coordinatePoints.deletePointsByFeatureIds([e]),this.deleteSelected(),this.selectionPoints.delete(),this.midPoints.delete()}else this.keyEvents.deselect&&e.key===this.keyEvents.deselect&&this.cleanUp()}cleanUp(){this.selected.length&&this.deselect(this.selected[0])}onDragStart(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDragStart,e))return;let n=this.selected[0];if(!n)return;let{featureFlags:r,coordinatesFlags:i,hasDraggableFlags:a}=this.getSelectedFlags(n);if(!a)return;this.dragEventCount=0;let o=this.dragTarget.type!==`none`&&this.dragTarget.featureId===n?this.dragTarget:{type:`none`},s=o.type===`coordinate`?o.coordinateIndex:this.dragCoordinate.getDraggableIndex(e,n),c=o.type===`resize`?o.coordinateIndex:this.dragCoordinateResizeFeature.getDraggableIndex(e,n),l=i?.resizable&&c!==-1,u=i?.draggable&&s!==-1,d=i&&typeof i.midpoints==`object`&&i.midpoints.draggable,f=r?.draggable&&(o.type===`feature`||this.dragFeature.canDrag(e,n));if(l)return this.setCursor(this.cursors.dragStart),this.dragCoordinateResizeFeature.startDragging(n,c),void t(!1);if(u)return this.setCursor(this.cursors.dragStart),this.dragCoordinate.startDragging(n,s),void t(!1);if(d){let r=o.type===`midpoint`?o.midPointId:this.midPoints.getNearestMidPoint(e);if(this.selected.length&&r){this.midPoints.insert({featureId:n,midPointId:r}),this.onFinish(this.selected[0],{action:rt,mode:this.mode});let i=this.dragCoordinate.getDraggableIndex(e,n);this.dragCoordinate.startDragging(n,i),t(!1);return}}if(f)return this.setCursor(this.cursors.dragStart),this.dragFeature.startDragging(e,n),void t(!1);this.setCursor(`unset`)}onDrag(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDrag,e))return;let n=this.selected[0];if(!n)return;let r=this.readFeature.getProperties(n),i=this.flags[r.mode],a=!0===(i&&i.feature&&i.feature.selfIntersectable);if(this.dragEventCount++,this.dragEventCount%this.dragEventThrottle!=0){if(i&&i.feature&&i.feature.rotateable&&this.canRotate(e))return t(!1),void this.rotateFeature.rotate(e,n);if(i&&i.feature&&i.feature.scaleable&&this.canScale(e))return t(!1),void this.scaleFeature.scale(e,n);if(this.dragCoordinateResizeFeature.isDragging()&&i.feature&&i.feature.coordinates&&i.feature.coordinates.resizable){if(this.projection===`globe`)throw Error(`Globe is currently unsupported projection for resizable`);t(!1),this.dragCoordinateResizeFeature.drag(e,i.feature.coordinates.resizable);return}if(this.dragCoordinate.isDragging()){var o;let t=(o=i.feature)==null||(o=o.coordinates)==null?void 0:o.snappable,n={toCoordinate:!1};!0===t?n={toCoordinate:!0}:typeof t==`object`&&(n=t),this.dragCoordinate.drag(e,a,n);return}this.dragFeature.isDragging()?this.dragFeature.drag(e):t(!0)}}onDragEnd(e,t){this.allowPointerEvent(this.pointerEvents.onDragEnd,e)&&(this.setCursor(this.cursors.dragEnd),this.dragCoordinate.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:`dragCoordinate`}):this.dragFeature.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:`dragFeature`}):this.dragCoordinateResizeFeature.isDragging()&&this.onFinish(this.selected[0],{mode:this.mode,action:`dragCoordinateResize`}),this.dragCoordinate.stopDragging(),this.dragFeature.stopDragging(),this.dragCoordinateResizeFeature.stopDragging(),this.rotateFeature.reset(),this.scaleFeature.reset(),t(!0))}onMouseMove(e){let t=this.selected[0];if(!t)return void this.clearDragTargetAndCursor();if(this.dragFeature.isDragging()||this.dragCoordinate.isDragging()||this.dragCoordinateResizeFeature.isDragging())return;let{featureFlags:n}=this.getSelectedFlags(t);if(!n)return void this.clearDragTargetAndCursor();let r,i=n.coordinates;if(i!=null&&i.midpoints&&(r=this.midPoints.getNearestMidPoint(e),r&&(this.dragTarget={type:`midpoint`,featureId:t,midPointId:r},this.setCursor(this.cursors.insertMidpoint))),i&&i.draggable){let{index:n,dist:i}=this.dragCoordinate.getDraggable(e,t);if(n>-1){if(r&&this.pixelDistance.measure(e,this.readFeature.getGeometry(r).coordinates)<i)return;this.dragTarget={type:`coordinate`,featureId:t,coordinateIndex:n},this.setCursor(this.cursors.pointerOver);return}}if(i&&i.resizable){let n=this.dragCoordinateResizeFeature.getDraggableIndex(e,t);if(n>-1)return this.dragTarget={type:`resize`,featureId:t,coordinateIndex:n},void this.setCursor(this.cursors.pointerOver)}if(n.draggable&&this.dragFeature.canDrag(e,t)){if(r)return;this.dragTarget={type:`feature`,featureId:t},this.setCursor(this.cursors.pointerOver);return}r||this.clearDragTargetAndCursor()}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});if(e.properties.mode===this.mode&&e.geometry.type===`Point`){if(e.properties[j.SELECTION_POINT])return t.pointColor=this.getHexColorStylingValue(this.styles.selectionPointColor,t.pointColor,e),t.pointOpacity=this.getNumericStylingValue(this.styles.selectionPointOpacity,1,e),t.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectionPointOutlineColor,t.pointOutlineColor,e),t.pointWidth=this.getNumericStylingValue(this.styles.selectionPointWidth,t.pointWidth,e),t.pointOutlineOpacity=this.getNumericStylingValue(this.styles.selectionPointOutlineOpacity,1,e),t.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectionPointOutlineWidth,2,e),t.zIndex=30,t;if(e.properties[j.MID_POINT])return t.pointColor=this.getHexColorStylingValue(this.styles.midPointColor,t.pointColor,e),t.pointOpacity=this.getNumericStylingValue(this.styles.midPointOpacity,1,e),t.pointOutlineColor=this.getHexColorStylingValue(this.styles.midPointOutlineColor,t.pointOutlineColor,e),t.pointWidth=this.getNumericStylingValue(this.styles.midPointWidth,4,e),t.pointOutlineOpacity=this.getNumericStylingValue(this.styles.midPointOutlineOpacity,1,e),t.pointOutlineWidth=this.getNumericStylingValue(this.styles.midPointOutlineWidth,2,e),t.zIndex=50,t}else if(e.properties[j.SELECTED]){if(e.geometry.type===`Point`&&e.properties[M.MARKER])return t.markerUrl=this.getUrlStylingValue(this.styles.selectedMarkerUrl,it,e),t.markerHeight=this.getNumericStylingValue(this.styles.selectedMarkerHeight,40,e),t.markerWidth=this.getNumericStylingValue(this.styles.selectedMarkerWidth,32,e),t;if(e.geometry.type===`Polygon`)return t.polygonFillColor=this.getHexColorStylingValue(this.styles.selectedPolygonColor,t.polygonFillColor,e),t.polygonOutlineWidth=this.getNumericStylingValue(this.styles.selectedPolygonOutlineWidth,t.polygonOutlineWidth,e),t.polygonOutlineColor=this.getHexColorStylingValue(this.styles.selectedPolygonOutlineColor,t.polygonOutlineColor,e),t.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.selectedPolygonOutlineOpacity,1,e),t.polygonFillOpacity=this.getNumericStylingValue(this.styles.selectedPolygonFillOpacity,t.polygonFillOpacity,e),t.zIndex=N,t;if(e.geometry.type===`LineString`)return t.lineStringColor=this.getHexColorStylingValue(this.styles.selectedLineStringColor,t.lineStringColor,e),t.lineStringWidth=this.getNumericStylingValue(this.styles.selectedLineStringWidth,t.lineStringWidth,e),t.zIndex=N,t;if(e.geometry.type===`Point`)return t.pointWidth=this.getNumericStylingValue(this.styles.selectedPointWidth,t.pointWidth,e),t.pointColor=this.getHexColorStylingValue(this.styles.selectedPointColor,t.pointColor,e),t.pointOpacity=this.getNumericStylingValue(this.styles.selectedPointOpacity,1,e),t.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectedPointOutlineColor,t.pointOutlineColor,e),t.pointOutlineOpacity=this.getNumericStylingValue(this.styles.selectedPointOutlineOpacity,1,e),t.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectedPointOutlineWidth,t.pointOutlineWidth,e),t.zIndex=N,t}return t}afterFeatureUpdated(e){if(this.selected.length&&e.id===this.selected[0]){var t,n;let r=this.flags[e.properties.mode];if(r==null||(t=r.feature)==null||!t.coordinates)return;let i=e.geometry.type,a=e.id;if(this.selectionPoints.delete(),this.midPoints.delete(),i!==`LineString`&&i!==`Polygon`)return;let o=e.geometry.coordinates;this.selectionPoints.create({featureCoordinates:o,featureId:a}),r!=null&&(n=r.feature)!=null&&(n=n.coordinates)!=null&&n.midpoints&&this.midPoints.create({featureCoordinates:o,featureId:a})}}},$n=class extends P{constructor(...e){super(...e),this.type=lt.Static,this.mode=`static`}start(){}stop(){}onKeyUp(){}onKeyDown(){}onClick(){}onDragStart(){}onDrag(){}onDragEnd(){}onMouseMove(){}cleanUp(){}styleFeature(){return O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0})}};function er(e,t,n,r,i){for(;r>n;){if(r-n>600){let a=r-n+1,o=t-n+1,s=Math.log(a),c=.5*Math.exp(2*s/3),l=.5*Math.sqrt(s*c*(a-c)/a)*(o-a/2<0?-1:1);er(e,t,Math.max(n,Math.floor(t-o*c/a+l)),Math.min(r,Math.floor(t+(a-o)*c/a+l)),i)}let a=e[t],o=n,s=r;for(tr(e,n,t),i(e[r],a)>0&&tr(e,n,r);o<s;){for(tr(e,o,s),o++,s--;i(e[o],a)<0;)o++;for(;i(e[s],a)>0;)s--}i(e[n],a)===0?tr(e,n,s):(s++,tr(e,s,r)),s<=t&&(n=s+1),t<=s&&(r=s-1)}}function tr(e,t,n){let r=e[t];e[t]=e[n],e[n]=r}function nr(e,t){rr(e,0,e.children.length,t,e)}function rr(e,t,n,r,i){i||=fr([]),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let a=t;a<n;a++){let t=e.children[a];ir(i,e.leaf?r(t):t)}return i}function ir(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function ar(e,t){return e.minX-t.minX}function or(e,t){return e.minY-t.minY}function sr(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function cr(e){return e.maxX-e.minX+(e.maxY-e.minY)}function lr(e,t){let n=Math.max(e.minX,t.minX),r=Math.max(e.minY,t.minY),i=Math.min(e.maxX,t.maxX),a=Math.min(e.maxY,t.maxY);return Math.max(0,i-n)*Math.max(0,a-r)}function ur(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function dr(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function fr(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function pr(e,t,n,r,i){let a=[t,n];for(;a.length;){if((n=a.pop())-(t=a.pop())<=r)continue;let o=t+Math.ceil((n-t)/r/2)*r;er(e,o,t,n,i),a.push(t,o,o,n)}}var mr=class{constructor(e){this._maxEntries=void 0,this._minEntries=void 0,this.data=void 0,this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}search(e){let t=this.data,n=[];if(!dr(e,t))return n;let r=this.toBBox,i=[];for(;t;){for(let a=0;a<t.children.length;a++){let o=t.children[a],s=t.leaf?r(o):o;dr(e,s)&&(t.leaf?n.push(o):ur(e,s)?this._all(o,n):i.push(o))}t=i.pop()}return n}collides(e){let t=this.data;if(dr(e,t)){let n=[];for(;t;){for(let r=0;r<t.children.length;r++){let i=t.children[r],a=t.leaf?this.toBBox(i):i;if(dr(e,a)){if(t.leaf||ur(e,a))return!0;n.push(i)}}t=n.pop()}}return!1}load(e){if(e.length<this._minEntries){for(let t=0;t<e.length;t++)this.insert(e[t]);return}let t=this._build(e.slice(),0,e.length-1,0);if(this.data.children.length)if(this.data.height===t.height)this._splitRoot(this.data,t);else{if(this.data.height<t.height){let e=this.data;this.data=t,t=e}this._insert(t,this.data.height-t.height-1,!0)}else this.data=t}insert(e){this._insert(e,this.data.height-1)}clear(){this.data=fr([])}remove(e){let t=this.data,n=this.toBBox(e),r=[],i=[],a,o,s=!1;for(;t||r.length;){if(t||(t=r.pop(),o=r[r.length-1],a=i.pop(),s=!0),t.leaf){let n=t.children.indexOf(e);n!==-1&&(t.children.splice(n,1),r.push(t),this._condense(r))}s||t.leaf||!ur(t,n)?o?(a++,t=o.children[a],s=!1):t=null:(r.push(t),i.push(a),a=0,o=t,t=t.children[0])}}toBBox(e){return e}compareMinX(e,t){return e.minX-t.minX}compareMinY(e,t){return e.minY-t.minY}_all(e,t){let n=[];for(;e;)e.leaf?t.push(...e.children):n.push(...e.children),e=n.pop();return t}_build(e,t,n,r){let i=n-t+1,a,o=this._maxEntries;if(i<=o)return a=fr(e.slice(t,n+1)),nr(a,this.toBBox),a;r||(r=Math.ceil(Math.log(i)/Math.log(o)),o=Math.ceil(i/o**(r-1))),a=fr([]),a.leaf=!1,a.height=r;let s=Math.ceil(i/o),c=s*Math.ceil(Math.sqrt(o));pr(e,t,n,c,this.compareMinX);for(let i=t;i<=n;i+=c){let t=Math.min(i+c-1,n);pr(e,i,t,s,this.compareMinY);for(let n=i;n<=t;n+=s){let i=Math.min(n+s-1,t);a.children.push(this._build(e,n,i,r-1))}}return nr(a,this.toBBox),a}_chooseSubtree(e,t,n,r){for(;r.push(t),!t.leaf&&r.length-1!==n;){let n,r=1/0,o=1/0;for(let s=0;s<t.children.length;s++){let c=t.children[s],l=sr(c),u=(i=e,a=c,(Math.max(a.maxX,i.maxX)-Math.min(a.minX,i.minX))*(Math.max(a.maxY,i.maxY)-Math.min(a.minY,i.minY))-l);u<o?(o=u,r=l<r?l:r,n=c):u===o&&l<r&&(r=l,n=c)}t=n||t.children[0]}var i,a;return t}_insert(e,t,n){let r=n?e:this.toBBox(e),i=[],a=this._chooseSubtree(r,this.data,t,i);for(a.children.push(e),ir(a,r);t>=0&&i[t].children.length>this._maxEntries;)this._split(i,t),t--;this._adjustParentBBoxes(r,i,t)}_split(e,t){let n=e[t],r=n.children.length,i=this._minEntries;this._chooseSplitAxis(n,i,r);let a=this._chooseSplitIndex(n,i,r),o=fr(n.children.splice(a,n.children.length-a));o.height=n.height,o.leaf=n.leaf,nr(n,this.toBBox),nr(o,this.toBBox),t?e[t-1].children.push(o):this._splitRoot(n,o)}_splitRoot(e,t){this.data=fr([e,t]),this.data.height=e.height+1,this.data.leaf=!1,nr(this.data,this.toBBox)}_chooseSplitIndex(e,t,n){let r,i=1/0,a=1/0;for(let o=t;o<=n-t;o++){let t=rr(e,0,o,this.toBBox),s=rr(e,o,n,this.toBBox),c=lr(t,s),l=sr(t)+sr(s);c<i?(i=c,r=o,a=l<a?l:a):c===i&&l<a&&(a=l,r=o)}return r||n-t}_chooseSplitAxis(e,t,n){let r=e.leaf?this.compareMinX:ar,i=e.leaf?this.compareMinY:or;this._allDistMargin(e,t,n,r)<this._allDistMargin(e,t,n,i)&&e.children.sort(r)}_allDistMargin(e,t,n,r){e.children.sort(r);let i=this.toBBox,a=rr(e,0,t,i),o=rr(e,n-t,n,i),s=cr(a)+cr(o);for(let r=t;r<n-t;r++){let t=e.children[r];ir(a,e.leaf?i(t):t),s+=cr(a)}for(let r=n-t-1;r>=t;r--){let t=e.children[r];ir(o,e.leaf?i(t):t),s+=cr(o)}return s}_adjustParentBBoxes(e,t,n){for(let r=n;r>=0;r--)ir(t[r],e)}_condense(e){for(let t,n=e.length-1;n>=0;n--)e[n].children.length===0?n>0?(t=e[n-1].children,t.splice(t.indexOf(e[n]),1)):this.clear():nr(e[n],this.toBBox)}},hr=class{constructor(e){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new mr(e&&e.maxEntries?e.maxEntries:9),this.idToNode=new Map,this.nodeToId=new Map}setMaps(e,t){this.idToNode.set(e.id,t),this.nodeToId.set(t,e.id)}toBBox(e){let t=[],n=[],r;if(e.geometry.type===`Polygon`)r=e.geometry.coordinates[0];else if(e.geometry.type===`LineString`)r=e.geometry.coordinates;else{if(e.geometry.type!==`Point`)throw Error(`Not a valid feature to turn into a bounding box`);r=[e.geometry.coordinates]}for(let e=0;e<r.length;e++)n.push(r[e][1]),t.push(r[e][0]);let i=Math.min(...n),a=Math.max(...n);return{minX:Math.min(...t),minY:i,maxX:Math.max(...t),maxY:a}}insert(e){if(this.idToNode.get(String(e.id)))throw Error(`Feature already exists`);let t=this.toBBox(e);this.setMaps(e,t),this.tree.insert(t)}load(e){let t=[],n=new Set;e.forEach(e=>{let r=this.toBBox(e);if(this.setMaps(e,r),n.has(String(e.id)))throw Error(`Duplicate feature ID found ${e.id}`);n.add(String(e.id)),t.push(r)}),this.tree.load(t)}update(e){this.remove(e.id);let t=this.toBBox(e);this.setMaps(e,t),this.tree.insert(t)}remove(e){let t=this.idToNode.get(e);if(!t)throw Error(`${e} not inserted into the spatial index`);this.tree.remove(t)}clear(){this.tree.clear()}search(e){return this.tree.search(this.toBBox(e)).map(e=>this.nodeToId.get(e))}collides(e){return this.tree.collides(this.toBBox(e))}},gr={getId:()=>`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,function(e){let t=16*Math.random()|0;return(e==`x`?t:3&t|8).toString(16)}),isValidId:e=>typeof e==`string`&&e.length===36},_r={target:`geometry`},vr={target:`properties`},yr=class{constructor(e){this.idStrategy=void 0,this.tracked=void 0,this.spatialIndex=void 0,this.store=void 0,this._onChange=()=>{},this.store={},this.spatialIndex=new hr,this.tracked=!e||!1!==e.tracked,this.idStrategy=e&&e.idStrategy?e.idStrategy:gr}clone(e){return JSON.parse(JSON.stringify(e))}getId(){return this.idStrategy.getId()}has(e){return!!this.store[e]}load(e,t,n,r){if(e.length===0)return[];let i=this.clone(e),a=[],o=[];i=i.filter(e=>{e.id??=this.idStrategy.getId();let n=e.id;if(t){let r=t(e);if(!r.valid)return a.push({id:n,valid:!1,reason:r.reason}),!1}if(this.tracked){if(e.properties.createdAt){if(!st(e.properties.createdAt))return a.push({id:e.id,valid:!1,reason:`createdAt is not a valid numeric timestamp`}),!1}else e.properties.createdAt=+new Date;if(e.properties.updatedAt){if(!st(e.properties.updatedAt))return a.push({id:e.id,valid:!1,reason:`updatedAt is not a valid numeric timestamp`}),!1}else e.properties.updatedAt=+new Date}return this.has(n)?(a.push({id:n,valid:!1,reason:`Feature already exists with this id: ${n}`}),!1):(this.store[n]=e,o.push(e),a.push({id:n,valid:!0}),!0)}),this.spatialIndex.load(i);let s=o.map(({id:e})=>e);return s.length>0&&(this._onChange(s,`create`,r),n&&o.forEach(e=>{n(e)})),a}search(e,t){let n=this.spatialIndex.search(e).map(e=>this.store[e]);return this.clone(t?n.filter(t):n)}registerOnChange(e){this._onChange=(t,n,r)=>{e(t,n,r)}}getGeometryCopy(e){let t=this.store[e];if(!t)throw Error(`No feature with this id (${e}), can not get geometry copy`);return this.clone(t.geometry)}getPropertiesCopy(e){let t=this.store[e];if(!t)throw Error(`No feature with this id (${e}), can not get properties copy`);return this.clone(t.properties)}updateProperty(e,t){let n=new Set;e.forEach(({id:e,property:t,value:r})=>{let i=this.store[e];if(!i)throw Error(`No feature with this (${e}), can not update geometry`);i.properties[t]!==r&&(n.add(e),r===void 0?delete i.properties[t]:i.properties[t]=r,this.tracked&&(i.properties.updatedAt=+new Date))}),this._onChange&&n.size>0&&this._onChange(Array.from(n),`update`,t?O({},t,vr):vr)}updateGeometry(e,t){let n=new Set;e.forEach(({id:e,geometry:t})=>{n.add(e);let r=this.store[e];if(!r)throw Error(`No feature with this (${e}), can not update geometry`);r.geometry=this.clone(t),this.spatialIndex.update(r),this.tracked&&(r.properties.updatedAt=+new Date)}),this._onChange&&n.size>0&&this._onChange(Array.from(n),`update`,t?O({},t,_r):_r)}create(e,t){let n=[];return e.forEach(({geometry:e,properties:t})=>{let r,i=O({},t);this.tracked&&(r=+new Date,t?(i.createdAt=typeof t.createdAt==`number`?t.createdAt:r,i.updatedAt=typeof t.updatedAt==`number`?t.updatedAt:r):i={createdAt:r,updatedAt:r});let a=this.getId(),o={id:a,type:`Feature`,geometry:e,properties:i};this.store[a]=o,this.spatialIndex.insert(o),n.push(a)}),this._onChange&&this._onChange([...n],`create`,t),n}delete(e,t){e.forEach(e=>{if(!this.store[e])throw Error(`No feature with id ${e}, can not delete`);delete this.store[e],this.spatialIndex.remove(e)}),this._onChange&&this._onChange([...e],`delete`,t)}copy(e){return this.clone(this.store[e])}copyAll(){return this.clone(Object.keys(this.store).map(e=>this.store[e]))}copyAllWhere(e){return this.clone(Object.keys(this.store).map(e=>this.store[e]).filter(t=>t.properties&&e(t.properties)))}clear(e){let t=Object.keys(this.store);this.store={},this.spatialIndex.clear(),this._onChange(t,`delete`,e)}size(){return Object.keys(this.store).length}};Math.PI/180;var br=`Feature is not a Polygon or LineString`,xr=`Feature intersects itself`,Sr=e=>e.geometry.type!==`Polygon`&&e.geometry.type!==`LineString`?{valid:!1,reason:br}:yt(e)?{valid:!1,reason:xr}:{valid:!0};function Cr(e,t,n){let r=q(e,t),i=q(t,n)-r;return i<0&&(i+=360),180-Math.abs(i-90-90)}var wr={cancel:`Escape`,finish:`Enter`},Tr={start:`crosshair`,close:`pointer`},Er=class extends P{constructor(e){super(e,!0),this.mode=`angled-rectangle`,this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=wr,this.cursors=Tr,this.mouseMove=!1,this.mutateFeature=void 0,this.readFeature=void 0,this.updateOptions(e)}updateOptions(e){super.updateOptions(e),e!=null&&e.cursors&&(this.cursors=O({},this.cursors,e.cursors)),e?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:e!=null&&e.keyEvents&&(this.keyEvents=O({},this.keyEvents,e.keyEvents))}close(){if(this.currentId===void 0||!this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:{[M.CURRENTLY_DRAWING]:void 0},context:{updateType:A.Finish,action:k}}))return;let e=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.state===`drawing`&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:k})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onMouseMove(e){if(this.mouseMove=!0,this.setCursor(this.cursors.start),this.currentId===void 0||this.currentCoordinate===0)return;let t=[];if(this.currentCoordinate===1)t=this.getUpdateForSecondCoordinate(e);else{if(this.currentCoordinate!==2)return;t=this.getNewSecondAndThirdCoordinates(e)}this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:t,context:{updateType:A.Provisional}})}getUpdateForSecondCoordinate(e){return[{type:H,index:1,coordinate:[e.lng,e.lat]},{type:H,index:2,coordinate:[e.lng,e.lat]}]}getNewSecondAndThirdCoordinates(e){if(!this.currentId)throw Error(`No current feature being drawn`);let t=this.readFeature.getCoordinate(this.currentId,0),n=this.readFeature.getCoordinate(this.currentId,1),r=Nn(t,n,this.coordinatePrecision,this.project,this.unproject),i=z(t[0],t[1]),a=z(r[0],r[1]),o=z(n[0],n[1]),s=z(e.lng,e.lat),c=G(s,i)<G(s,o),l=Cr(i,a,s),u=c?90-l:Cr(i,a,s)-90,d=G(a,s),f=Math.cos(I(u))*d,p=q(i,o)+(function(e,t,n){let r=(n.x-t.x)*(e.y-t.y)-(n.y-t.y)*(e.x-t.x);return r>1e-10?`left`:r<-1e-10?`right`:`left`}(i,o,s)===`right`?-90:90),m=Kt(i,f,p),h=Kt(o,f,p),g=B(m.x,m.y),_=B(h.x,h.y);return[{type:H,index:2,coordinate:[R(_.lng,this.coordinatePrecision),R(_.lat,this.coordinatePrecision)]},{type:H,index:3,coordinate:[R(g.lng,this.coordinatePrecision),R(g.lat,this.coordinatePrecision)]}]}onClick(e){if(e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e))if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(e),this.mouseMove=!1,this.currentCoordinate===0){let{id:t}=this.mutateFeature.createPolygon({coordinates:[[e.lng,e.lat],[e.lng,e.lat],[e.lng,e.lat],[e.lng,e.lat]],properties:{mode:this.mode,[M.CURRENTLY_DRAWING]:!0}});this.currentId=t,this.currentCoordinate++,this.setDrawing()}else if(this.currentCoordinate===1&&this.currentId){let t=this.readFeature.getCoordinate(this.currentId,0);if(Lt([e.lng,e.lat],t)||!this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:H,index:1,coordinate:[e.lng,e.lat]},{type:Mt,index:1,coordinate:[e.lng,e.lat]}],context:{updateType:A.Commit}}))return;this.currentCoordinate++}else this.currentCoordinate===2&&this.currentId&&this.close()}onKeyUp(e){if(e.key===this.keyEvents.cancel)this.cleanUp();else if(e.key===this.keyEvents.finish){if(this.currentCoordinate<2)return void this.cleanUp();this.close()}}onKeyDown(){}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){let e=this.currentId;this.currentId=void 0,this.currentCoordinate=0,this.state===`drawing`&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(e)}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return e.properties.mode===this.mode&&e.geometry.type===`Polygon`&&(t.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,t.polygonFillColor,e),t.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,t.polygonOutlineColor,e),t.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,t.polygonOutlineWidth,e),t.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,e),t.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,t.polygonFillOpacity,e),t.zIndex=N),t}validateFeature(e){return this.validateModeFeature(e,e=>kt(e,this.coordinatePrecision))}afterFeatureUpdated(e){this.currentId===e.id&&(this.currentId=void 0,this.currentCoordinate=0,this.state===`drawing`&&this.setStarted())}registerBehaviors(e){this.readFeature=new K(e),this.mutateFeature=new W(e,{validate:this.validate})}};function Dr(e,t,n){return(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x)<=0}var Or={cancel:`Escape`,finish:`Enter`},kr={start:`crosshair`,close:`pointer`},Ar=class extends P{constructor(e){super(e,!0),this.mode=`sector`,this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=Or,this.direction=void 0,this.arcPoints=64,this.cursors=kr,this.mouseMove=!1,this.readFeature=void 0,this.mutateFeature=void 0,this.updateOptions(e)}updateOptions(e){super.updateOptions(e),e!=null&&e.cursors&&(this.cursors=O({},this.cursors,e.cursors)),e?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:e!=null&&e.keyEvents&&(this.keyEvents=O({},this.keyEvents,e.keyEvents)),e!=null&&e.arcPoints&&(this.arcPoints=e.arcPoints)}close(){if(this.currentId===void 0||!this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:{[M.CURRENTLY_DRAWING]:void 0},coordinateMutations:{coordinates:this.readFeature.getGeometry(this.currentId).coordinates,type:U},context:{updateType:A.Finish,action:k}}))return;let e=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.direction=void 0,this.state===`drawing`&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:k})}getSectorCoordinates(e){let t=this.readFeature.getCoordinates(this.currentId),n=t[0],r=t[1],i=[e.lng,e.lat],a=z(n[0],n[1]),o=z(r[0],r[1]),s=z(i[0],i[1]);this.direction===void 0&&(this.direction=Dr(a,o,s)?`clockwise`:`anticlockwise`);let c=G(a,o),l=q(a,o),u=q(a,s),d=this.arcPoints,f=[n],p=Jt(l),m=Jt(u),h;this.direction===`anticlockwise`?(h=m-p,h<0&&(h+=360)):(h=p-m,h<0&&(h+=360));let g=(this.direction===`anticlockwise`?1:-1)*h/d;f.push(r);for(let e=0;e<=d;e++){let t=Kt(a,c,p+e*g),{lng:n,lat:r}=B(t.x,t.y),i=[R(n,this.coordinatePrecision),R(r,this.coordinatePrecision)];i[0]!==f[f.length-1][0]&&i[1]!==f[f.length-1][1]&&f.push(i)}return f.push(n),f}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onMouseMove(e){if(this.mouseMove=!0,this.setCursor(this.cursors.start),this.currentId===void 0||this.currentCoordinate===0)return;let t;if(this.currentCoordinate===1)t=[{type:H,index:1,coordinate:[e.lng,e.lat]},{type:H,index:2,coordinate:[e.lng,e.lat]}];else{if(this.currentCoordinate!==2)return;{let n=this.getSectorCoordinates(e);if(!n)return;t={type:U,coordinates:[n]}}}this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:t,context:{updateType:A.Provisional}})}onClick(e){if(e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e))if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(e),this.mouseMove=!1,this.currentCoordinate===0)this.currentId=this.mutateFeature.createPolygon({coordinates:[[e.lng,e.lat],[e.lng,e.lat],[e.lng,e.lat],[e.lng,e.lat]],properties:{mode:this.mode,[M.CURRENTLY_DRAWING]:!0}})?.id,this.currentCoordinate++,this.setDrawing();else if(this.currentCoordinate===1&&this.currentId){if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,index:0,newCoordinate:[e.lng,e.lat]})||!this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:H,index:1,coordinate:[e.lng,e.lat]},{type:H,index:2,coordinate:[e.lng,e.lat]}],context:{updateType:A.Provisional}}))return;this.currentCoordinate++}else this.currentCoordinate===2&&this.currentId&&this.close()}onKeyUp(e){e.key===this.keyEvents.cancel?this.cleanUp():e.key===this.keyEvents.finish&&this.close()}onKeyDown(){}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){let e=this.currentId;this.currentId=void 0,this.direction=void 0,this.currentCoordinate=0,this.state===`drawing`&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(e)}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return e.properties.mode===this.mode&&e.geometry.type===`Polygon`&&(t.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,t.polygonFillColor,e),t.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,t.polygonOutlineColor,e),t.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,t.polygonOutlineWidth,e),t.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,e),t.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,t.polygonFillOpacity,e),t.zIndex=N),t}validateFeature(e){return this.validateModeFeature(e,e=>kt(e,this.coordinatePrecision))}afterFeatureUpdated(e){this.currentId===e.id&&(this.currentId=void 0,this.direction=void 0,this.currentCoordinate=0,this.state===`drawing`&&this.setStarted())}registerBehaviors(e){this.readFeature=new K(e),this.mutateFeature=new W(e,{validate:this.validate})}},jr={cancel:`Escape`,finish:`Enter`},Mr={start:`crosshair`,close:`pointer`},Nr=class extends P{constructor(e){super(e,!0),this.mode=`sensor`,this.currentCoordinate=0,this.currentId=void 0,this.currentInitialArcId=void 0,this.currentStartingPointId=void 0,this.keyEvents=jr,this.direction=void 0,this.arcPoints=64,this.cursors=Mr,this.mouseMove=!1,this.readFeature=void 0,this.mutateFeature=void 0,this.updateOptions(e)}updateOptions(e){super.updateOptions(e),e!=null&&e.cursors&&(this.cursors=O({},this.cursors,e.cursors)),e?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:e!=null&&e.keyEvents&&(this.keyEvents=O({},this.keyEvents,e.keyEvents)),e!=null&&e.arcPoints&&(this.arcPoints=e.arcPoints)}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onMouseMove(e){if(this.mouseMove=!0,this.setCursor(this.cursors.start),this.currentInitialArcId!==void 0&&this.currentStartingPointId!==void 0&&this.currentCoordinate!==0){if(this.currentCoordinate===2){let t=this.getUpdatedLineStringCoordinates(e);if(!t)return;this.mutateFeature.updateLineString({featureId:this.currentInitialArcId,coordinateMutations:{type:U,coordinates:t},context:{updateType:A.Provisional}})}else if(this.currentCoordinate===3){let t=this.getUpdatedPolygonCoordinates(e);if(!t)return;if(this.currentId)this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:{type:U,coordinates:[t]},context:{updateType:A.Provisional}});else{let e=this.mutateFeature.createPolygon({coordinates:t,properties:{mode:this.mode,[M.CURRENTLY_DRAWING]:!0}});if(!e)return;this.currentId=e.id}}}}onClick(e){if(e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e))if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(e),this.mouseMove=!1,this.currentCoordinate===0){let t=this.mutateFeature.createPoint({coordinates:[e.lng,e.lat],properties:{mode:this.mode}});if(!t)return;this.currentStartingPointId=t.id,this.currentCoordinate++,this.setDrawing()}else if(this.currentCoordinate===1&&this.currentStartingPointId){let t=this.mutateFeature.createLineString({coordinates:[[e.lng,e.lat],[e.lng,e.lat]],properties:{mode:this.mode}});if(!t)return;this.currentInitialArcId=t.id,this.currentCoordinate++}else this.currentCoordinate===2&&this.currentStartingPointId?this.currentCoordinate++:this.currentCoordinate===3&&this.currentStartingPointId&&this.close()}onKeyUp(e){e.key===this.keyEvents.cancel?this.cleanUp():e.key===this.keyEvents.finish&&this.close()}onKeyDown(){}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){this.mutateFeature.deleteFeatureIfPresent(this.currentStartingPointId),this.mutateFeature.deleteFeatureIfPresent(this.currentInitialArcId),this.mutateFeature.deleteFeatureIfPresent(this.currentId),this.currentStartingPointId=void 0,this.direction=void 0,this.currentId=void 0,this.currentCoordinate=0,this.state===`drawing`&&this.setStarted()}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return e.properties.mode===this.mode&&(e.geometry.type===`Polygon`?(t.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,t.polygonFillColor,e),t.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,t.polygonOutlineColor,e),t.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,t.polygonOutlineWidth,e),t.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,e),t.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,t.polygonFillOpacity,e),t.zIndex=N):e.geometry.type===`LineString`?(t.lineStringColor=this.getHexColorStylingValue(this.styles.outlineColor,t.polygonOutlineColor,e),t.lineStringWidth=this.getNumericStylingValue(this.styles.outlineWidth,t.polygonOutlineWidth,e),t.zIndex=N):e.geometry.type===`Point`&&(t.pointColor=this.getHexColorStylingValue(this.styles.centerPointColor,t.pointColor,e),t.pointOpacity=this.getNumericStylingValue(this.styles.centerPointOpacity,1,e),t.pointWidth=this.getNumericStylingValue(this.styles.centerPointWidth,t.pointWidth,e),t.pointOutlineColor=this.getHexColorStylingValue(this.styles.centerPointOutlineColor,t.pointOutlineColor,e),t.pointOutlineOpacity=this.getNumericStylingValue(this.styles.centerPointOutlineOpacity,1,e),t.pointOutlineWidth=this.getNumericStylingValue(this.styles.centerPointOutlineWidth,t.pointOutlineWidth,e),t.zIndex=20)),t}validateFeature(e){return this.validateModeFeature(e,e=>kt(e,this.coordinatePrecision))}afterFeatureUpdated(e){this.currentId===e.id&&(this.mutateFeature.deleteFeatureIfPresent(this.currentStartingPointId),this.mutateFeature.deleteFeatureIfPresent(this.currentInitialArcId),this.currentStartingPointId=void 0,this.direction=void 0,this.currentId=void 0,this.currentCoordinate=0,this.state===`drawing`&&this.setStarted())}registerBehaviors(e){this.readFeature=new K(e),this.mutateFeature=new W(e,{validate:this.validate})}close(){if(this.currentStartingPointId===void 0)return;let e=this.currentStartingPointId,t=this.currentInitialArcId;if(this.currentId&&!this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:{[M.CURRENTLY_DRAWING]:void 0},coordinateMutations:{coordinates:this.readFeature.getGeometry(this.currentId).coordinates,type:U},context:{updateType:A.Finish,action:k}}))return;let n=this.currentId;this.mutateFeature.deleteFeatureIfPresent(e),this.mutateFeature.deleteFeatureIfPresent(t),this.currentCoordinate=0,this.currentStartingPointId=void 0,this.currentInitialArcId=void 0,this.currentId=void 0,this.direction=void 0,this.state===`drawing`&&this.setStarted(),n&&this.onFinish(n,{mode:this.mode,action:k})}getUpdatedPolygonCoordinates(e){if(this.currentInitialArcId===void 0||this.currentStartingPointId===void 0||this.currentCoordinate<3)return;let t=this.readFeature.getCoordinates(this.currentInitialArcId);if(t.length<2||!this.direction)return;let n=this.readFeature.getGeometry(this.currentStartingPointId).coordinates,r=t[0],i=t[t.length-1],a=z(e.lng,e.lat),o=z(r[0],r[1]),s=z(i[0],i[1]),c=z(n[0],n[1]),l=G(c,o),u=G(c,a)<l?o:a,d=q(c,a),f=q(c,o),p=q(c,s),m=Jt(f),h=Jt(p),g=Jt(d);if(this.notInSector({normalizedCursor:g,normalizedStart:m,normalizedEnd:h,direction:this.direction}))return;let _=this.getDeltaBearing(this.direction,m,h),v=this.arcPoints,ee=(this.direction===`anticlockwise`?1:-1)*_/v,te=G(c,u),y=[];for(let e=0;e<=v;e++){let n=Kt(c,te,m+e*ee),{lng:r,lat:i}=B(n.x,n.y),a=[R(r,this.coordinatePrecision),R(i,this.coordinatePrecision)];a[0]!==t[t.length-1][0]&&a[1]!==t[t.length-1][1]&&y.unshift(a)}return t.push(...y),t.push(t[0]),t}getUpdatedLineStringCoordinates(e){if(this.currentInitialArcId===void 0||this.currentStartingPointId===void 0||this.currentCoordinate<2)return;let t=this.readFeature.getGeometry(this.currentInitialArcId).coordinates,n=this.readFeature.getGeometry(this.currentStartingPointId).coordinates,r=t[0],i=[e.lng,e.lat],a=z(r[0],r[1]),o=z(i[0],i[1]),s=z(n[0],n[1]),c=G(s,a);this.direction===void 0&&(this.direction=Dr(s,a,o)?`clockwise`:`anticlockwise`);let l=q(s,a),u=q(s,o),d=this.arcPoints,f=[r],p=Jt(l),m=Jt(u),h;this.direction===`anticlockwise`?(h=m-p,h<0&&(h+=360)):(h=p-m,h<0&&(h+=360));let g=(this.direction===`anticlockwise`?1:-1)*h/d;for(let e=0;e<=d;e++){let t=Kt(s,c,p+e*g),{lng:n,lat:r}=B(t.x,t.y),i=[R(n,this.coordinatePrecision),R(r,this.coordinatePrecision)];i[0]!==f[f.length-1][0]&&i[1]!==f[f.length-1][1]&&f.push(i)}return f}getDeltaBearing(e,t,n){let r;return e===`anticlockwise`?(r=n-t,r<0&&(r+=360)):(r=t-n,r<0&&(r+=360)),r}notInSector({normalizedCursor:e,normalizedStart:t,normalizedEnd:n,direction:r}){return r===`clockwise`?t<=n?e>=t&&e<=n:e>=t||e<=n:t>=n?e<=t&&e>=n:e<=t||e>=n}},Pr=class{constructor({name:e,callback:t,unregister:n,register:r}){this.name=void 0,this.callback=void 0,this.registered=!1,this.register=void 0,this.unregister=void 0,this.name=e,this.register=()=>{this.registered||(this.registered=!0,r(t))},this.unregister=()=>{this.register&&(this.registered=!1,n(t))},this.callback=t}},Fr={__proto__:null,GeoJSONStore:yr,TerraDrawBaseDrawMode:P,TerraDrawBaseSelectMode:dt,TerraDrawBaseAdapter:class{constructor(e){this._nextKeyUpIsContextMenu=!1,this._lastPointerDownEventTarget=void 0,this._ignoreMismatchedPointerEvents=!1,this._minPixelDragDistance=void 0,this._minPixelDragDistanceDrawing=void 0,this._minPixelDragDistanceSelecting=void 0,this._lastDrawEvent=void 0,this._coordinatePrecision=void 0,this._heldKeys=new Set,this._listeners=[],this._dragState=`not-dragging`,this._currentModeCallbacks=void 0,this._ignoreMismatchedPointerEvents=typeof e.ignoreMismatchedPointerEvents==`boolean`&&e.ignoreMismatchedPointerEvents,this._minPixelDragDistance=typeof e.minPixelDragDistance==`number`?e.minPixelDragDistance:1,this._minPixelDragDistanceSelecting=typeof e.minPixelDragDistanceSelecting==`number`?e.minPixelDragDistanceSelecting:1,this._minPixelDragDistanceDrawing=typeof e.minPixelDragDistanceDrawing==`number`?e.minPixelDragDistanceDrawing:8,this._coordinatePrecision=typeof e.coordinatePrecision==`number`?e.coordinatePrecision:9}getButton(e){return e.button===-1?`neither`:e.button===0?`left`:e.button===1?`middle`:e.button===2?`right`:`neither`}getMapElementXYPosition(e){let{left:t,top:n}=this.getMapEventElement(e.type).getBoundingClientRect();return{containerX:e.clientX-t,containerY:e.clientY-n}}getDrawEventFromEvent(e,t=!1){let n=this.getLngLatFromEvent(e);if(!n)return null;let{lng:r,lat:i}=n,{containerX:a,containerY:o}=this.getMapElementXYPosition(e),s=this.getButton(e),c=Array.from(this._heldKeys);return{lng:R(r,this._coordinatePrecision),lat:R(i,this._coordinatePrecision),containerX:a,containerY:o,button:s,heldKeys:c,isContextMenu:t}}register(e){this._currentModeCallbacks=e,this._listeners=this.getAdapterListeners(),this._listeners.forEach(e=>{e.register()})}getCoordinatePrecision(){return this._coordinatePrecision}getAdapterListeners(){return[new Pr({name:`pointerdown`,callback:e=>{if(!this._currentModeCallbacks||!e.isPrimary)return;let t=this.getDrawEventFromEvent(e);t&&(this._dragState=`pre-dragging`,this._lastDrawEvent=t,this._lastPointerDownEventTarget=e.target?e.target:void 0)},register:e=>{this.getMapEventElement(`pointerdown`).addEventListener(`pointerdown`,e)},unregister:e=>{this.getMapEventElement(`pointerdown`).removeEventListener(`pointerdown`,e)}}),new Pr({name:`pointermove`,callback:e=>{if(!this._currentModeCallbacks||!e.isPrimary)return;e.preventDefault();let t=this.getDrawEventFromEvent(e);if(t)if(this._dragState===`not-dragging`)this._currentModeCallbacks.onMouseMove(t),this._lastDrawEvent=t;else if(this._dragState===`pre-dragging`){if(!this._lastDrawEvent)return;let e={x:this._lastDrawEvent.containerX,y:this._lastDrawEvent.containerY},n={x:t.containerX,y:t.containerY},r=this._currentModeCallbacks.getState(),i=G(e,n),a=!1;if(a=r===`drawing`?i<this._minPixelDragDistanceDrawing:r===`selecting`?i<this._minPixelDragDistanceSelecting:i<this._minPixelDragDistance,a)return;this._nextKeyUpIsContextMenu=!1,this._dragState=`dragging`,this._currentModeCallbacks.onDragStart(t,e=>{this.setDraggability.bind(this)(e)})}else this._dragState===`dragging`&&this._currentModeCallbacks.onDrag(t,e=>{this.setDraggability.bind(this)(e)})},register:e=>{this.getMapEventElement(`pointermove`).addEventListener(`pointermove`,e)},unregister:e=>{this.getMapEventElement(`pointermove`).removeEventListener(`pointermove`,e)}}),new Pr({name:`contextmenu`,callback:e=>{this._currentModeCallbacks&&(e.preventDefault(),this._nextKeyUpIsContextMenu=!0)},register:e=>{this.getMapEventElement(`contextmenu`).addEventListener(`contextmenu`,e)},unregister:e=>{this.getMapEventElement(`contextmenu`).removeEventListener(`contextmenu`,e)}}),new Pr({name:`pointerup`,callback:e=>{if(!this._currentModeCallbacks||e.target!==this.getMapEventElement(`pointerup`)||this._ignoreMismatchedPointerEvents&&this._lastPointerDownEventTarget!==e.target||(this._lastPointerDownEventTarget=void 0,!e.isPrimary))return;let t=this.getDrawEventFromEvent(e);t&&(this._dragState===`dragging`?this._currentModeCallbacks.onDragEnd(t,e=>{this.setDraggability.bind(this)(e)}):this._dragState!==`not-dragging`&&this._dragState!==`pre-dragging`||(this._nextKeyUpIsContextMenu&&=(t.isContextMenu=!0,!1),this._currentModeCallbacks.onClick(t)),this._dragState=`not-dragging`,this.setDraggability(!0))},register:e=>{this.getMapEventElement(`pointerup`).addEventListener(`pointerup`,e)},unregister:e=>{this.getMapEventElement(`pointerup`).removeEventListener(`pointerup`,e)}}),new Pr({name:`keyup`,callback:e=>{this._currentModeCallbacks&&(this._heldKeys.delete(e.key),this._currentModeCallbacks.onKeyUp({key:e.key,heldKeys:Array.from(this._heldKeys),preventDefault:()=>e.preventDefault()}))},register:e=>{this.getMapEventElement(`keyup`).addEventListener(`keyup`,e)},unregister:e=>{this.getMapEventElement(`keyup`).removeEventListener(`keyup`,e)}}),new Pr({name:`keydown`,callback:e=>{this._currentModeCallbacks&&(this._heldKeys.add(e.key),this._currentModeCallbacks.onKeyDown({key:e.key,heldKeys:Array.from(this._heldKeys),preventDefault:()=>e.preventDefault()}))},register:e=>{this.getMapEventElement(`keydown`).addEventListener(`keydown`,e)},unregister:e=>{this.getMapEventElement(`keydown`).removeEventListener(`keydown`,e)}})]}unregister(){this._listeners.forEach(e=>{e.unregister()}),this.clear(),this._currentModeCallbacks=void 0,this._lastDrawEvent=void 0,this._lastPointerDownEventTarget=void 0,this._nextKeyUpIsContextMenu=!1}},getDefaultStyling:()=>({polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0}),SELECT_PROPERTIES:j},Ir={cancel:`Escape`,finish:`Enter`},Lr={start:`crosshair`,close:`pointer`},Rr=class extends P{constructor(e){super(e,!0),this.mode=`freehand-linestring`,this.canClose=!1,this.currentId=void 0,this.minDistance=20,this.keyEvents=Ir,this.cursors=Lr,this.preventNewFeature=!1,this.mutateFeature=void 0,this.readFeature=void 0,this.pixelDistance=void 0,this.closingPoints=void 0,this.updateOptions(e)}updateOptions(e){super.updateOptions(e),e!=null&&e.minDistance&&(this.minDistance=e.minDistance),e?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:e!=null&&e.keyEvents&&(this.keyEvents=O({},this.keyEvents,e.keyEvents)),e!=null&&e.cursors&&(this.cursors=O({},this.cursors,e.cursors))}close(){if(this.currentId===void 0||!this.mutateFeature.updateLineString({featureId:this.currentId,propertyMutations:{[M.CURRENTLY_DRAWING]:void 0},context:{updateType:A.Finish,action:k}}))return;let e=this.currentId;this.closingPoints.delete(),this.canClose=!1,this.currentId=void 0,this.state===`drawing`&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:k})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onMouseMove(e){if(this.currentId===void 0||!1===this.canClose)return void this.setCursor(this.cursors.start);let[t,n]=this.readFeature.getCoordinate(this.currentId,-2),{x:r,y:i}=this.project(t,n),a=G({x:r,y:i},{x:e.containerX,y:e.containerY}),[o,s]=this.readFeature.getCoordinate(this.currentId,-1),{x:c,y:l}=this.project(o,s),u=G({x:c,y:l},{x:e.containerX,y:e.containerY});if(this.setCursor(u<this.pointerDistance?this.cursors.close:this.cursors.start),a<this.minDistance)return;let d=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:[{type:Mt,index:-1,coordinate:[e.lng,e.lat]}],context:{updateType:A.Provisional}});d&&this.closingPoints.update(d.geometry.coordinates)}onClick(e){if(e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e)){if(this.preventNewFeature)return;if(!1===this.canClose){let{id:t,geometry:n}=this.mutateFeature.createLineString({coordinates:[[e.lng,e.lat],[e.lng,e.lat]],properties:{mode:this.mode,[M.CURRENTLY_DRAWING]:!0}});this.closingPoints.create(n.coordinates),this.currentId=t,this.canClose=!0,this.state!==`drawing`&&this.setDrawing();return}this.close()}}onKeyDown(){}onKeyUp(e){e.key===this.keyEvents.cancel?this.cleanUp():e.key===this.keyEvents.finish&&!0===this.canClose&&this.close()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){let e=this.currentId;this.currentId=void 0,this.canClose=!1,this.state===`drawing`&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(e),this.closingPoints.delete()}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return e.type===`Feature`&&e.geometry.type===`LineString`&&e.properties.mode===this.mode?(t.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,t.lineStringColor,e),t.lineStringOpacity=this.getNumericStylingValue(this.styles.lineStringOpacity,t.lineStringOpacity===void 0?1:t.lineStringOpacity,e),t.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,t.lineStringWidth,e),t.zIndex=N,t):e.type===`Feature`&&e.geometry.type===`Point`&&e.properties.mode===this.mode?(t.pointWidth=this.getNumericStylingValue(this.styles.closingPointWidth,t.pointWidth,e),t.pointOpacity=this.getNumericStylingValue(this.styles.closingPointOpacity,1,e),t.pointColor=this.getHexColorStylingValue(this.styles.closingPointColor,t.pointColor,e),t.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,t.pointOutlineColor,e),t.pointOutlineOpacity=this.getNumericStylingValue(this.styles.closingPointOutlineOpacity,1,e),t.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,e),t.zIndex=50,t):t}validateFeature(e){return this.validateModeFeature(e,e=>$t(e,this.coordinatePrecision))}afterFeatureUpdated(e){this.currentId===e.id&&(this.closingPoints.delete(),this.canClose=!1,this.currentId=void 0)}registerBehaviors(e){this.readFeature=new K(e),this.mutateFeature=new W(e,{validate:this.validate}),this.pixelDistance=new Ut(e),this.closingPoints=new dn(e,this.pixelDistance,this.mutateFeature,this.readFeature)}};function zr(e){if(e===null||typeof e==`boolean`||typeof e==`string`)return!0;if(e===void 0)return!1;if(typeof e==`number`)return Number.isFinite(e);if(typeof e==`bigint`||typeof e==`symbol`||typeof e==`function`||e instanceof RegExp||e instanceof Map||e instanceof Set||e instanceof Date)return!1;if(typeof e==`object`&&e&&!Array.isArray(e)){let t=Object.getPrototypeOf(e);if(t!==Object.prototype&&t!==null)return!1}if(ArrayBuffer.isView(e)&&!(e instanceof DataView))return!1;if(Array.isArray(e)){for(let t of e)if(!zr(t))return!1}return typeof e==`object`&&Object.keys(e).every(t=>typeof t==`string`&&zr(e[t]))}var Br={create:`crosshair`,dragStart:`grabbing`,dragEnd:`crosshair`},Vr=class extends P{constructor(e){super(e,!0),this.mode=`marker`,this.cursors=Br,this.editable=!1,this.editedFeatureId=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.pointSearch=void 0,this.mutateFeature=void 0,this.updateOptions(e)}updateOptions(e){super.updateOptions(e),e!=null&&e.cursors&&(this.cursors=O({},this.cursors,e.cursors)),e!=null&&e.editable&&(this.editable=e.editable)}start(){this.setStarted(),this.setCursor(this.cursors.create)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onClick(e){e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e)?this.onRightClick(e):e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)&&this.onLeftClick(e)}onMouseMove(){}onKeyDown(){}onKeyUp(){}cleanUp(){this.editedFeatureId=void 0}onDragStart(e,t){this.allowPointerEvent(this.pointerEvents.onDragStart,e)&&(this.editable&&(this.editedFeatureId=this.pointSearch.getNearestPointFeature(e)?.id),this.editedFeatureId&&(this.setCursor(this.cursors.dragStart),t(!1)))}onDrag(e,t){this.allowPointerEvent(this.pointerEvents.onDrag,e)&&this.editedFeatureId!==void 0&&this.mutateFeature.updatePoint({featureId:this.editedFeatureId,coordinateMutations:{type:U,coordinates:[e.lng,e.lat]},propertyMutations:{[M.EDITED]:!0},context:{updateType:A.Provisional}})}onDragEnd(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDragEnd,e)||this.editedFeatureId===void 0||!this.mutateFeature.updatePoint({featureId:this.editedFeatureId,propertyMutations:{mode:this.mode,[M.EDITED]:!1},context:{updateType:A.Finish,action:`edit`}}))return;let n=this.editedFeatureId;this.setCursor(this.cursors.dragEnd),this.editedFeatureId=void 0,t(!0),this.onFinish(n,{mode:this.mode,action:k})}registerBehaviors(e){this.pixelDistance=new Ut(e),this.clickBoundingBox=new Ht(e),this.pointSearch=new xn(e,this.pixelDistance,this.clickBoundingBox),this.mutateFeature=new W(e,{validate:this.validate})}styleFeature(e){let t=O({},{polygonFillColor:`#3f97e0`,polygonOutlineColor:`#3f97e0`,polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:`#3f97e0`,pointOpacity:1,pointOutlineColor:`#ffffff`,pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:`#3f97e0`,lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return e.type===`Feature`&&e.geometry.type===`Point`&&e.properties.mode===this.mode&&(t.zIndex=30,t.markerHeight=this.getNumericStylingValue(this.styles?.markerHeight,40,e),t.markerWidth=this.getNumericStylingValue(this.styles?.markerWidth,32,e),t.markerUrl=this.getUrlStylingValue(this.styles?.markerUrl,it,e)),t}validateFeature(e){return this.validateModeFeature(e,e=>bn(e,this.coordinatePrecision))}onLeftClick(e){let t=this.mutateFeature.createPoint({coordinates:[e.lng,e.lat],properties:{mode:this.mode,[M.MARKER]:!0},context:{updateType:A.Finish,action:k}});t&&this.onFinish(t.id,{mode:this.mode,action:k})}onRightClick(e){if(!this.editable)return;let t=this.pointSearch.getNearestPointFeature(e);t&&this.mutateFeature.deleteFeatureIfPresent(t.id)}afterFeatureUpdated(e){this.editedFeatureId===e.id&&(this.editedFeatureId=void 0,this.setCursor(this.cursors.create))}},Hr=[{key:`z`,heldKeys:[`meta`]},{key:`z`,heldKeys:[`control`]}],Ur=[{key:`z`,heldKeys:[`meta`,`shift`]},{key:`z`,heldKeys:[`control`,`shift`]},{key:`y`,heldKeys:[`control`]}],Wr=(e,t)=>{let n=e.key.toLowerCase(),r=new Set(e.heldKeys.map(e=>e.toLowerCase()).filter(e=>e!==n));if(t.key.toLowerCase()!==n)return!1;let i=new Set(t.heldKeys.map(e=>e.toLowerCase()));if(r.size!==i.size)return!1;for(let e of i)if(!r.has(e))return!1;return!0},Gr=class{constructor(e){this.undoKeyboardShortcuts=void 0,this.redoKeyboardShortcuts=void 0,this.undoKeyboardShortcuts=e?.undo??Hr,this.redoKeyboardShortcuts=e?.redo??Ur}isUndoKeyboardShortcut(e){return this.undoKeyboardShortcuts.some(t=>Wr(e,t))}isRedoKeyboardShortcut(e){return this.redoKeyboardShortcuts.some(t=>Wr(e,t))}};function Kr(e){return e!==void 0&&Number.isFinite(e)?Math.max(0,Math.floor(e)):1/0}var J=`undo`,qr=`redo`,Jr=`push`,Yr=`mode`,Xr=`session`,Zr=class{constructor(e){this.getModeState=void 0,this.getModeHistorySizes=void 0,this.undoMode=void 0,this.redoMode=void 0,this.clearModeHistory=void 0,this.onHistoryChange=void 0,this.maxStackSize=void 0,this.lastHistorySizes={undoSize:0,redoSize:0},this.maxStackSize=Kr(e?.maxStackSize)}getMaxStackSize(){return this.maxStackSize}register(e){this.getModeState=e.getModeState,this.getModeHistorySizes=e.getModeHistorySizes,this.undoMode=e.undoMode,this.redoMode=e.redoMode,this.clearModeHistory=e.clearModeHistory,this.onHistoryChange=e.onHistoryChange}inDrawingState(){return!!this.getModeState&&this.getModeState()===`drawing`}canUndo(){if(!this.inDrawingState())return!1;let{undoSize:e}=this.getHistorySizes();return e>0}canRedo(){if(!this.inDrawingState())return!1;let{redoSize:e}=this.getHistorySizes();return e>0}undo(){return!(!this.canUndo()||!this.undoMode||(this.undoMode(),this.emitHistoryChange(J),0))}redo(){return!(!this.canRedo()||!this.redoMode||(this.redoMode(),this.emitHistoryChange(qr),0))}clearHistory(){this.clearModeHistory&&this.clearModeHistory(),this.lastHistorySizes={undoSize:0,redoSize:0}}getHistorySizes(){return this.getModeHistorySizes?this.getModeHistorySizes():{undoSize:0,redoSize:0}}undoSize(){return this.getHistorySizes().undoSize}redoSize(){return this.getHistorySizes().redoSize}emitPushIfHistoryChangedFromLastSnapshot(){if(!this.inDrawingState())return;let e=this.getHistorySizes();e.undoSize===this.lastHistorySizes.undoSize&&e.redoSize===this.lastHistorySizes.redoSize||this.emitHistoryChange(Jr)}emitPushIfHistoryChanged(e){if(!this.inDrawingState())return;let t=this.getHistorySizes();t.undoSize===e.undoSize&&t.redoSize===e.redoSize||this.emitHistoryChange(Jr)}emitHistoryChange(e){if(!this.onHistoryChange)return;let{undoSize:t,redoSize:n}=this.getHistorySizes();this.lastHistorySizes={undoSize:t,redoSize:n},this.onHistoryChange({cause:e,stack:Yr,undoStackSize:t,redoStackSize:n})}},Qr=class{constructor(e){this.draw=void 0,this.onHistoryChange=void 0,this.maxStackSize=void 0,this.historyById={},this.undoStack=[],this.ignoreProgrammaticCreate={},this.ignoreProgrammaticDelete={},this.deletedFeatureIds={},this.redoStack=[],this.emitStackChange=e=>{this.onHistoryChange&&this.onHistoryChange({cause:e,stack:Xr,undoStackSize:this.undoStack.length,redoStackSize:this.redoStack.length})},this.handleChange=(e,t,n)=>{if(!this.draw||this.isDrawing()||this.maxStackSize===0||t!==`delete`&&t!==`create`)return;if(t===`create`){if(n===void 0||!(`origin`in n)||n.origin!==`api`)return;let t=!1,r=Array.isArray(e)?e:[e],i=[];for(let e of r){if(this.ignoreProgrammaticCreate[e]){delete this.ignoreProgrammaticCreate[e],delete this.deletedFeatureIds[e];continue}let n=String(e),r=this.draw.getSnapshotFeature(e);r&&(this.deletedFeatureIds[e]&&(this.historyById[n]=[],delete this.deletedFeatureIds[e]),this.historyById[n]||(this.historyById[n]=[]),this.historyById[n].push(r),i.push({id:e,toIndex:this.historyById[n].length-1,snapshot:r}),t=!0)}if(i.length>1)this.pushUndoStackEntry({id:i[0].id,toIndex:i[0].toIndex,action:`batch-create`,metadata:{entries:i}});else if(i.length===1){let e=i[0];this.pushUndoStackEntry({id:e.id,toIndex:e.toIndex,action:`single`})}t&&(this.redoStack.length=0,this.emitStackChange(Jr));return}let r=!1,i=Array.isArray(e)?e:[e],a=[];for(let e of i){let t=String(e);if(this.ignoreProgrammaticDelete[e]){delete this.ignoreProgrammaticDelete[e];continue}if(!this.historyById[t])continue;let n=this.historyById[t].length-1;if(n>=0){let i=this.historyById[t][n];if(!i)continue;a.push({id:e,toIndex:n,snapshot:i}),this.deletedFeatureIds[e]=!0,r=!0}}if(a.length>1)this.pushUndoStackEntry({id:a[0].id,toIndex:a[0].toIndex,action:`batch-delete`,metadata:{entries:a}});else if(a.length===1){let e=a[0];this.pushUndoStackEntry({id:e.id,toIndex:e.toIndex,action:`single`})}r&&(this.redoStack.length=0,this.emitStackChange(Jr))},this.handleFinish=e=>{if(!this.draw||this.maxStackSize===0)return;let t=Array.isArray(e)?e:[e],n=!1;for(let e of t){if(e==null)continue;let t=String(e),r=this.draw.getSnapshotFeature(e);r&&(this.historyById[t]||(this.historyById[t]=[]),this.historyById[t].push(r),n||=(this.redoStack.length=0,!0),this.pushUndoStackEntry({id:e,toIndex:this.historyById[t].length-1,action:`single`}),this.emitStackChange(Jr))}},this.maxStackSize=Kr(e?.maxStackSize)}register(e){this.draw===e.draw?this.onHistoryChange=e.onHistoryChange:(this.draw&&(this.draw.off(`change`,this.handleChange),this.draw.off(`finish`,this.handleFinish)),this.draw=e.draw,this.draw.on(`change`,this.handleChange),this.draw.on(`finish`,this.handleFinish),this.onHistoryChange=e.onHistoryChange)}pushUndoStackEntry(e){this.maxStackSize!==0&&(this.undoStack.push(e),this.undoStack.length>this.maxStackSize&&this.undoStack.shift())}pushRedoStackEntry(e){this.maxStackSize!==0&&(this.redoStack.push(e),this.redoStack.length>this.maxStackSize&&this.redoStack.shift())}isDrawing(){return!!this.draw&&this.draw.getModeState()===`drawing`}canUndo(){return!(!this.draw||this.isDrawing())&&this.undoStack.length>0}canRedo(){return!(!this.draw||this.isDrawing())&&this.redoStack.length>0}undo(){if(!this.canUndo()||!this.draw)return!1;let e=this.undoStack.pop();if(!e)return this.emitStackChange(J),!1;if(e.action===`batch-create`){let t=e.metadata?.entries||[];if(t.length===0)return this.emitStackChange(J),!1;let n=t.map(e=>e.id);return n.forEach(e=>{this.ignoreProgrammaticDelete[e]=!0,this.deletedFeatureIds[e]=!0}),this.draw.removeFeatures(n),this.pushRedoStackEntry({id:t[0].id,toIndex:t[0].toIndex,action:`batch-create`,metadata:{entries:t}}),this.emitStackChange(J),!0}if(e.action===`batch-delete`){let t=e.metadata?.entries||[];if(t.length===0)return this.emitStackChange(J),!1;let n=t.map(e=>e.snapshot).filter(e=>e!==void 0);return n.length>0&&(t.forEach(e=>{this.ignoreProgrammaticCreate[e.id]=!0,delete this.deletedFeatureIds[e.id]}),this.draw.addFeatures(n)),this.pushRedoStackEntry({id:t[0].id,toIndex:t[0].toIndex,action:`batch-delete`,metadata:{entries:t}}),this.emitStackChange(J),!0}let t=e.id,n=e.toIndex,r=String(t),i=this.historyById[r];if(!i||i.length===0)return this.emitStackChange(J),!1;let a=Math.min(n,i.length-1);if(!this.draw.hasFeature(t)){let e=i[a];return e?(this.ignoreProgrammaticCreate[t]=!0,delete this.deletedFeatureIds[t],this.draw.addFeatures([e]),this.pushRedoStackEntry({id:t,toIndex:a,action:`delete`,snapshot:e}),this.emitStackChange(J),!0):(this.emitStackChange(J),!1)}if(a<=0)return this.pushRedoStackEntry({id:t,toIndex:0,action:`create`}),this.ignoreProgrammaticDelete[t]=!0,this.deletedFeatureIds[t]=!0,this.draw.removeFeatures([t]),this.undoStack=this.undoStack.filter(e=>e.id!==t),this.emitStackChange(J),!0;let o=i[a],s=i[a-1];return o&&this.pushRedoStackEntry({id:t,toIndex:a,snapshot:o,action:`update`}),this.draw.updateFeatureGeometry(t,s.geometry),i.length=a,this.emitStackChange(J),!0}redo(){if(!this.canRedo()||!this.draw)return!1;let{id:e,toIndex:t,snapshot:n,action:r,metadata:i}=this.redoStack.pop();if(r===`batch-create`){let e=i?.entries||[];if(e.length===0)return this.emitStackChange(qr),!1;let t=e.map(e=>e.snapshot).filter(e=>e!==void 0);return t.length>0&&(e.forEach(e=>{this.ignoreProgrammaticCreate[e.id]=!0}),this.draw.addFeatures(t)),this.pushUndoStackEntry({id:e[0].id,toIndex:e[0].toIndex,action:`batch-create`,metadata:{entries:e}}),this.emitStackChange(qr),!0}if(r===`batch-delete`){let e=i?.entries||[];if(e.length===0)return this.emitStackChange(qr),!1;let t=e.map(e=>e.id);return t.forEach(e=>{this.ignoreProgrammaticDelete[e]=!0,this.deletedFeatureIds[e]=!0}),this.draw.removeFeatures(t),this.pushUndoStackEntry({id:e[0].id,toIndex:e[0].toIndex,action:`batch-delete`,metadata:{entries:e}}),this.emitStackChange(qr),!0}let a=String(e),o=this.historyById[a]||(this.historyById[a]=[]);if(r===`delete`)return this.ignoreProgrammaticDelete[e]=!0,this.deletedFeatureIds[e]=!0,this.draw.removeFeatures([e]),this.pushUndoStackEntry({id:e,toIndex:t,action:`single`}),this.emitStackChange(qr),!0;if(t<=0){let t=o[0];return!!t&&(this.ignoreProgrammaticCreate[e]=!0,this.draw.addFeatures([t]),this.pushUndoStackEntry({id:e,toIndex:0,action:`single`}),this.emitStackChange(qr),!0)}let s=n||o[t];return!!s&&(o.length===t?o.push(s):(o[t]=s,o.length=t+1),this.draw.updateFeatureGeometry(e,s.geometry),this.pushUndoStackEntry({id:e,toIndex:t,action:`single`}),this.emitStackChange(qr),!0)}clearHistory(){let e={};if(this.draw&&!this.isDrawing()){let t=this.draw.getSnapshot();for(let n of t)e[String(n.id)]=[n]}this.historyById=e,this.undoStack=[],this.ignoreProgrammaticCreate={},this.ignoreProgrammaticDelete={},this.deletedFeatureIds={},this.redoStack=[]}undoSize(){return this.undoStack.length}redoSize(){return this.redoStack.length}},$r=class{constructor(e){this.modeLevel=void 0,this.sessionLevel=void 0,this.shouldPreferMode=void 0,this.onHistoryChange=void 0,this.shouldEmitHistoryChange=void 0,this.modeLevel=e.modeLevel,this.sessionLevel=e.sessionLevel,this.shouldPreferMode=e.shouldPreferMode,this.onHistoryChange=e.onHistoryChange,this.shouldEmitHistoryChange=e.shouldEmitHistoryChange??(()=>!0)}emitStackHistoryChange(e){this.shouldEmitHistoryChange()&&this.onHistoryChange&&this.onHistoryChange({cause:e.cause,stack:e.stack,undoSize:e.undoStackSize,redoSize:e.redoStackSize})}hasSessionUndo(){return!!(this.sessionLevel&&this.sessionLevel.canUndo())}hasSessionRedo(){return!!(this.sessionLevel&&this.sessionLevel.canRedo())}activeStackForUndo(){var e,t;return this.shouldPreferMode()&&(e=this.modeLevel)!=null&&e.canUndo()?Yr:this.hasSessionUndo()?Xr:(t=this.modeLevel)!=null&&t.canUndo()?Yr:void 0}activeStackForRedo(){var e,t;return this.shouldPreferMode()&&(e=this.modeLevel)!=null&&e.canRedo()?Yr:this.hasSessionRedo()?Xr:(t=this.modeLevel)!=null&&t.canRedo()?Yr:void 0}canUndo(){return this.activeStackForUndo()!==void 0}canRedo(){return this.activeStackForRedo()!==void 0}undo(){let e=this.activeStackForUndo();return!!e&&(e===Yr?!!this.modeLevel&&this.modeLevel.undo():!(!this.sessionLevel||!this.sessionLevel.canUndo())&&this.sessionLevel.undo())}redo(){let e=this.activeStackForRedo();return!!e&&(e===Yr?!!this.modeLevel&&this.modeLevel.redo():!(!this.sessionLevel||!this.sessionLevel.canRedo())&&this.sessionLevel.redo())}clearHistory(){this.modeLevel&&this.modeLevel.clearHistory(),this.sessionLevel&&this.sessionLevel.clearHistory()}emitPushAfterFinish(){this.sessionLevel?this.emitStackHistoryChange({cause:Jr,undoStackSize:this.sessionLevel.undoSize(),redoStackSize:this.sessionLevel.redoSize(),stack:Xr}):this.modeLevel&&this.emitStackHistoryChange({cause:Jr,undoStackSize:this.modeLevel.undoSize(),redoStackSize:this.modeLevel.redoSize(),stack:Yr})}},ei=class{constructor(e){var t,n,r,i;this._modes=void 0,this._mode=void 0,this._adapter=void 0,this._enabled=!1,this._store=void 0,this._eventListeners=void 0,this._instanceSelectModes=void 0,this.sessionUndoRedoEnabled=!1,this.keyboardShortcutsMatcher=void 0,this.drawingUndoRedo=void 0,this.sessionUndoRedo=void 0,this.undoRedoCoordinator=void 0,this._adapter=e.adapter,this._instanceSelectModes=[];let a=e==null||(t=e.undoRedo)==null?void 0:t.modeLevel;a&&(this.drawingUndoRedo=a);let o=e==null||(n=e.undoRedo)==null?void 0:n.keyboardShortcuts;o&&(this.keyboardShortcutsMatcher=o),this.sessionUndoRedoEnabled=!!(!(e==null||(r=e.undoRedo)==null)&&r.sessionLevel);let s=e==null||(i=e.undoRedo)==null?void 0:i.sessionLevel;this._mode=new $n;let c=new Set,l=e.modes.reduce((e,t)=>{if(c.has(t.mode))throw Error(`There is already a ${t.mode} mode provided`);return c.add(t.mode),e[t.mode]=t,e},{}),u=Object.keys(l);if(u.length===0)throw Error(`No modes provided`);u.forEach(e=>{l[e].type===lt.Select&&this._instanceSelectModes.push(e)}),this._modes=O({},l,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[],finish:[],ready:[],history:[]},this._store=new yr({tracked:!!e.tracked,idStrategy:e.idStrategy?e.idStrategy:void 0});let d=e=>{let t=[];return{changed:t,unchanged:this._store.copyAll().filter(n=>!e.includes(n.id)||(t.push(n),!1))}},f=(e,t)=>{this._enabled&&(this._eventListeners.finish.forEach(n=>{n(e,t)}),this.emitHistoryChangeAfterFinish())},p=(e,t,n)=>{if(!this._enabled)return;this._eventListeners.change.forEach(r=>{r(e,t,n)}),this.emitDrawingPushIfHistoryChangedFromLastSnapshot();let{changed:r,unchanged:i}=d(e);t===`create`?this._adapter.render({created:r,deletedIds:[],unchanged:i,updated:[]},this.getModeStyles()):t===`update`?this._adapter.render({created:[],deletedIds:[],unchanged:i,updated:r},this.getModeStyles()):t===`delete`?this._adapter.render({created:[],deletedIds:e,unchanged:i,updated:[]},this.getModeStyles()):t===`styling`&&this._adapter.render({created:[],deletedIds:[],unchanged:i,updated:[]},this.getModeStyles())},m=e=>{if(!this._enabled)return;this._eventListeners.select.forEach(t=>{t(e)});let{changed:t,unchanged:n}=d([e]);this._adapter.render({created:[],deletedIds:[],unchanged:n,updated:t},this.getModeStyles())},h=e=>{if(!this._enabled)return;this._eventListeners.deselect.forEach(t=>{t(e)});let{changed:t,unchanged:n}=d([e]);t&&this._adapter.render({created:[],deletedIds:[],unchanged:n,updated:t},this.getModeStyles())};Object.keys(this._modes).forEach(e=>{var t;this._modes[e].register({mode:e,store:this._store,setCursor:this._adapter.setCursor.bind(this._adapter),project:this._adapter.project.bind(this._adapter),unproject:this._adapter.unproject.bind(this._adapter),setDoubleClickToZoom:this._adapter.setDoubleClickToZoom.bind(this._adapter),onChange:p,onSelect:m,onDeselect:h,onFinish:f,coordinatePrecision:this._adapter.getCoordinatePrecision(),undoRedoMaxStackSize:(t=this.drawingUndoRedo)==null||t.getMaxStackSize==null?void 0:t.getMaxStackSize()})}),this.sessionUndoRedoEnabled&&s&&(this.sessionUndoRedo=s,s.register({draw:this,onHistoryChange:e=>{var t;(t=this.undoRedoCoordinator)==null||t.emitStackHistoryChange(e)}})),this.drawingUndoRedo&&this.drawingUndoRedo.register({getModeState:()=>this.getModeState(),getModeHistorySizes:()=>this.getDrawingHistorySizes(),undoMode:()=>{this._mode.undo&&this._mode.undo()},redoMode:()=>{this._mode.redo&&this._mode.redo()},clearModeHistory:()=>{let e=this._mode;e.clearHistory&&e.clearHistory()},onHistoryChange:e=>{var t;(t=this.undoRedoCoordinator)==null||t.emitStackHistoryChange(e)}}),this.undoRedoCoordinator=new $r({modeLevel:this.drawingUndoRedo,sessionLevel:this.sessionUndoRedo,shouldPreferMode:()=>this.getModeState()===`drawing`,onHistoryChange:e=>{this._eventListeners.history.forEach(t=>{t(e)})},shouldEmitHistoryChange:()=>this._enabled})}checkEnabled(){if(!this._enabled)throw Error(`Terra Draw is not enabled`)}handleUndoRedoKeyboardShortcut(e){if(!this.drawingUndoRedo&&!this.sessionUndoRedoEnabled||!this.keyboardShortcutsMatcher)return!1;let t=this.keyboardShortcutsMatcher.isUndoKeyboardShortcut(e),n=this.keyboardShortcutsMatcher.isRedoKeyboardShortcut(e);if(t){if(!this.canUndo())return!1;let t=this.undo();return t&&e.preventDefault(),t}if(n){if(!this.canRedo())return!1;let t=this.redo();return t&&e.preventDefault(),t}return!1}getDrawingHistorySizes(){return{undoSize:this._mode.undoSize&&typeof this._mode.undoSize==`function`?this._mode.undoSize():0,redoSize:this._mode.redoSize&&typeof this._mode.redoSize==`function`?this._mode.redoSize():0}}emitDrawingPushIfHistoryChangedFromLastSnapshot(){this.drawingUndoRedo&&this.drawingUndoRedo.emitPushIfHistoryChangedFromLastSnapshot()}emitDrawingPushIfHistoryChanged(e){this.drawingUndoRedo&&this.drawingUndoRedo.emitPushIfHistoryChanged(e)}emitHistoryChangeAfterFinish(){var e;(e=this.undoRedoCoordinator)==null||e.emitPushAfterFinish()}getModeStyles(){let e={},t=this._instanceSelectModes.includes(this._mode.mode)?this._mode.mode:void 0;return Object.keys(this._modes).forEach(n=>{e[n]=e=>t&&e.properties[j.SELECTED]?this._modes[t].styleFeature.bind(this._modes[t])(e):this._modes[n].styleFeature.bind(this._modes[n])(e)}),e}featuresAtLocation({lng:e,lat:t},n){let r=n&&n.pointerDistance!==void 0?n.pointerDistance:30,i=!n||n.ignoreSelectFeatures===void 0||n.ignoreSelectFeatures,a=!(!n||n.ignoreCoordinatePoints===void 0)&&n.ignoreCoordinatePoints,o=!(!n||n.ignoreCurrentlyDrawing===void 0)&&n.ignoreCurrentlyDrawing,s=!(!n||n.ignoreClosingPoints===void 0)&&n.ignoreClosingPoints,c=!(!n||n.ignoreSnappingPoints===void 0)&&n.ignoreSnappingPoints,l=this._adapter.unproject.bind(this._adapter),u=this._adapter.project.bind(this._adapter),d=u(e,t),f=Vt({unproject:l,point:d,pointerDistance:r});return this._store.search(f).filter(l=>{if(i&&(l.properties[j.MID_POINT]||l.properties[j.SELECTION_POINT])||a&&l.properties[M.COORDINATE_POINT]||s&&l.properties[M.CLOSING_POINT]||o&&l.properties[M.CURRENTLY_DRAWING]||c&&l.properties[M.SNAPPING_POINT])return!1;if(l.geometry.type===`Point`){let e=l.geometry.coordinates;return G(d,u(e[0],e[1]))<r}if(l.geometry.type===`LineString`){let e=l.geometry.coordinates;for(let t=0;t<e.length-1;t++){let n=e[t],i=e[t+1];if(zn(d,u(n[0],n[1]),u(i[0],i[1]))<r)return!0}return!1}if(Rn([e,t],l.geometry.coordinates))return!0;if(n!=null&&n.includePolygonsWithinPointerDistance){let e=l.geometry.coordinates;for(let t of e)for(let e=0;e<t.length-1;e++){let n=t[e],i=t[e+1];if(zn(d,u(n[0],n[1]),u(i[0],i[1]))<r)return!0}}return!1}).map(r=>{if(n==null||!n.addClosestCoordinateInfoToProperties)return r;let i;if(r.geometry.type===`Polygon`)i=r.geometry.coordinates[0].slice(0,-1);else{if(r.geometry.type!==`LineString`)return r;i=r.geometry.coordinates}let a,o=-1,s=1/0;for(let e=0;e<i.length;e++){let t=i[e],n=G(u(t[0],t[1]),d);n<s&&(o=e,s=n,a=t)}return r.properties.closestCoordinateIndexToEvent=o,r.properties.closestCoordinatePixelDistanceToEvent=s,r.properties.closestCoordinateDistanceKmToEvent=F(a,[e,t]),r})}getSelectModeOrThrow(e=void 0){let t=this.getSelectMode({switchToSelectMode:!0,selectMode:e});if(!t)throw Error(`No select mode defined in instance`);return t}getSelectMode({switchToSelectMode:e,selectMode:t}){this.checkEnabled();let n=this.getMode();if(this._instanceSelectModes.length===0)return null;if(t!==void 0&&!this._instanceSelectModes.includes(t))throw Error(`No select mode with this name present: ${t}`);let r;return r=t===void 0?this._instanceSelectModes.includes(n)?n:this._instanceSelectModes[0]:t,e&&n!==r&&this.setMode(r),this._modes[r]}isGuidanceFeature(e){return!!(e.properties[j.MID_POINT]||e.properties[j.SELECTION_POINT]||e.properties[M.COORDINATE_POINT]||e.properties[M.SNAPPING_POINT])}setModeStyles(e,t){if(this.checkEnabled(),!this._modes[e])throw Error(`No mode with this name present`);this._modes[e].styles=t}updateModeOptions(e,t){if(this.checkEnabled(),!this._modes[e])throw Error(`No mode with this name present`);this._modes[e].updateOptions(t)}getSnapshot(){return this._store.copyAll()}getSnapshotFeature(e){if(this._store.has(e))return this._store.copy(e)}clear(){this.checkEnabled(),this._adapter.clear()}get enabled(){return this._enabled}set enabled(e){throw Error(`Enabled is read only`)}getMode(){return this._mode.mode}getModeState(){return this._mode.state}setMode(e){if(this.checkEnabled(),!this._modes[e])throw Error(`No mode with this name present`);this._mode.stop(),this._mode=this._modes[e],this._mode.start()}removeFeatures(e){this.checkEnabled();let t=[],n=[],r;e.forEach(e=>{if(!this._store.has(e))throw Error(`No feature with id ${e}, can not delete`);let i=this._store.getPropertiesCopy(e);i[j.SELECTED]&&this.deselectFeature(e),i[M.CURRENTLY_DRAWING]&&this._modes[i.mode]?r=i.mode:(i[M.COORDINATE_POINT_IDS]&&t.push(...i[M.COORDINATE_POINT_IDS]),n.push(e))}),this._store.delete([...n,...t],{origin:`api`}),r&&this._modes[r]&&this._modes[r].cleanUp()&&this._modes[r].cleanUp()}selectFeature(e,t){this.getSelectModeOrThrow(t).selectFeature(e)}deselectFeature(e){this.getSelectModeOrThrow().deselectFeature(e)}getFeatureId(){return this._store.getId()}hasFeature(e){return this._store.has(e)}checkIsReservedProperty(e){return![...Object.values(j),...Object.values(M)].includes(e)}updateFeatureProperties(e,t){if(!this._store.has(e))throw Error(`No feature with id ${e} present in store`);let n=this._store.copy(e);if(this.isGuidanceFeature(n))throw Error(`Guidance features are not allowed to be updated directly.`);let r=n.properties.mode;if(!this._modes[r])throw Error(`No mode with name ${r} present in instance`);let i=Object.entries(t);i.forEach(([e,t])=>{if(!this.checkIsReservedProperty(e))throw Error(`You are trying to update a reserved property name: ${e}. Please choose another name.`);if(t!==void 0&&!zr(t))throw Error(`Invalid JSON value provided for property ${e}`)}),this._store.updateProperty(i.map(([e,t])=>({id:n.id,property:e,value:t})),{origin:`api`})}updateFeatureGeometry(e,t){if(!this._store.has(e))throw Error(`No feature with id ${e} present in store`);let n=this._store.copy(e);if(this.isGuidanceFeature(n))throw Error(`Guidance features are not allowed to be updated directly.`);if(!(n&&t&&t.type&&t.coordinates))throw Error(`Invalid geometry provided`);if(t.type!==n.geometry.type)throw Error(`Geometry type mismatch: expected ${n.geometry.type}, got ${t.type}`);let r=n.properties.mode,i=this._modes[r];if(!i)throw Error(`No mode with name ${r} present in instance`);let a=O({},n,{geometry:t}),o=i.validateFeature(a);if(!o.valid)throw Error(`Feature validation failed: ${o.reason||`Unknown reason`}`);if(this._store.updateGeometry([{id:n.id,geometry:t}],{origin:`api`}),i.afterFeatureUpdated){i.afterFeatureUpdated(a);let e=a.properties[j.SELECTED],t=this.getSelectMode({switchToSelectMode:!1});t&&e&&t.afterFeatureUpdated(a)}}transformFeatureGeometry(e,t){if(!this._store.has(e))throw Error(`No feature with id ${e} present in store`);let n=this._store.copy(e);if(this.isGuidanceFeature(n))throw Error(`Guidance features are not allowed to be updated directly.`);let r=n.properties.mode,i=this._modes[r];if(!i)throw Error(`No mode with name ${r} present in instance`);let a;if(n.geometry.type===`Polygon`)a=n.geometry.coordinates[0];else{if(n.geometry.type!==`LineString`)throw Error(`Feature geometry type ${n.geometry.type} is not supported for transformation`);a=n.geometry.coordinates}if(t.projection!=`web-mercator`)throw Error(`Projection ${t.projection} is not currently supported for transformation`);if(t.type===`scale`){let{x:e,y:n}=z(t.origin[0],t.origin[1]);Jn({coordinates:a,originX:e,originY:n,xScale:t.options.xScale||1,yScale:t.options.yScale||1})}else t.type===`rotate`&&(n=Wn(n,t.options.angle||0),a=n.geometry.type===`Polygon`?n.geometry.coordinates[0]:n.geometry.coordinates);if(a=a.map(e=>[R(e[0],this._adapter.getCoordinatePrecision()),R(e[1],this._adapter.getCoordinatePrecision())]),n.geometry.coordinates=n.geometry.type===`Polygon`?[a]:a,this._store.updateGeometry([{id:n.id,geometry:n.geometry}],{origin:`api`}),i.afterFeatureUpdated){i.afterFeatureUpdated(n);let e=n.properties[j.SELECTED],t=this.getSelectMode({switchToSelectMode:!1});t&&e&&t.afterFeatureUpdated(n)}}undo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.undo()}canUndo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.canUndo()}canRedo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.canRedo()}redo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.redo()}clearUndoRedoHistory(){this.checkEnabled(),this.undoRedoCoordinator&&this.undoRedoCoordinator.clearHistory()}addFeatures(e){return this.checkEnabled(),e.length===0?[]:this._store.load(e,e=>{if(ot(e)){let t=e.properties.mode,n=this._modes[t];if(!n)return{id:e.id,valid:!1,reason:`${t} mode is not in the list of instantiated modes`};let r=n.validateFeature.bind(n)(e);return{id:e.id,valid:r.valid,reason:r.reason?r.reason:r.valid?void 0:`Feature is invalid`}}return{id:e.id,valid:!1,reason:`Mode property does not exist`}},e=>{if(ot(e)){let t=this._modes[e.properties.mode];t&&t.afterFeatureAdded&&t.afterFeatureAdded(e)}},{origin:`api`})}start(){this._enabled||(this._enabled=!0,this._adapter.register({onReady:()=>{this._eventListeners.ready.forEach(e=>{e()})},getState:()=>this._mode.state,onClick:e=>{let t=this.drawingUndoRedo?this.drawingUndoRedo.getHistorySizes():{undoSize:0,redoSize:0};this._mode.onClick(e),this.emitDrawingPushIfHistoryChanged(t)},onMouseMove:e=>{this._mode.onMouseMove(e)},onKeyDown:e=>{this.handleUndoRedoKeyboardShortcut(e)||this._mode.onKeyDown(e)},onKeyUp:e=>{let t=this.drawingUndoRedo?this.drawingUndoRedo.getHistorySizes():{undoSize:0,redoSize:0};this._mode.onKeyUp(e),this.emitDrawingPushIfHistoryChanged(t)},onDragStart:(e,t)=>{this._mode.onDragStart(e,t)},onDrag:(e,t)=>{this._mode.onDrag(e,t)},onDragEnd:(e,t)=>{this._mode.onDragEnd(e,t)},onClear:()=>{this._mode.cleanUp(),this._store.clear({origin:`api`})}}))}getFeaturesAtLngLat(e,t){let{lng:n,lat:r}=e;return this.featuresAtLocation({lng:n,lat:r},t)}getFeaturesAtPointerEvent(e,t){let n=this._adapter.getLngLatFromEvent.bind(this._adapter)(e);return n===null?[]:this.featuresAtLocation(n,t)}stop(){this._enabled&&(this._enabled=!1,this._adapter.unregister())}on(e,t){let n=this._eventListeners[e];n.includes(t)||n.push(t)}off(e,t){let n=this._eventListeners[e];n.includes(t)&&n.splice(n.indexOf(t),1)}},ti=class extends Fr.TerraDrawBaseAdapter{constructor(e){super(e),this._renderBeforeLayerId=void 0,this._prefixId=void 0,this._initialDragPan=void 0,this._initialDragRotate=void 0,this._nextRender=void 0,this._map=void 0,this._container=void 0,this.changedIds={deletion:!1,points:!1,linestrings:!1,polygons:!1,styling:!1},this._map=e.map,this._container=this._map.getContainer(),this._initialDragRotate=this._map.dragRotate.isEnabled(),this._initialDragPan=this._map.dragPan.isEnabled(),this._renderBeforeLayerId=e.renderBelowLayerId,this._prefixId=e.prefixId||`td`}hashCode(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return Math.abs(t)}resizeImage(e,t,n,r){let i=new Image;i.crossOrigin=`anonymous`,i.onload=()=>{let e=document.createElement(`canvas`);e.width=t,e.height=n;let a=e.getContext(`2d`);if(!a)throw Error(`Could not get canvas context`);a.drawImage(i,0,0,t,n),r(e.toDataURL())},i.src=e}_addGeoJSONSource(e,t){this._map.addSource(e,{type:`geojson`,data:{type:`FeatureCollection`,features:t},tolerance:0})}_addFillLayer(e){return this._map.addLayer({id:e,source:e,type:`fill`,layout:{"fill-sort-key":[`get`,`zIndex`]},paint:{"fill-color":[`get`,`polygonFillColor`],"fill-opacity":[`get`,`polygonFillOpacity`]}})}_addFillOutlineLayer(e){return this._map.addLayer({id:e+`-outline`,source:e,type:`line`,layout:{"line-sort-key":[`get`,`zIndex`]},paint:{"line-width":[`get`,`polygonOutlineWidth`],"line-color":[`get`,`polygonOutlineColor`],"line-opacity":[`get`,`polygonOutlineOpacity`]}})}_addLineLayer(e){return this._map.addLayer({id:e,source:e,type:`line`,layout:{"line-sort-key":[`get`,`zIndex`]},paint:{"line-width":[`get`,`lineStringWidth`],"line-color":[`get`,`lineStringColor`],"line-opacity":[`get`,`lineStringOpacity`]}})}_addPointLayer(e){return this._map.addLayer({id:e,source:e,type:`circle`,layout:{"circle-sort-key":[`get`,`zIndex`]},paint:{"circle-stroke-color":[`get`,`pointOutlineColor`],"circle-stroke-width":[`get`,`pointOutlineWidth`],"circle-stroke-opacity":[`get`,`pointOutlineOpacity`],"circle-radius":[`get`,`pointWidth`],"circle-color":[`get`,`pointColor`],"circle-opacity":[`get`,`pointOpacity`]}})}_addMarkerLayer(e){return this._map.addLayer({id:e+`-marker`,source:e,type:`symbol`,filter:[`has`,`markerId`],layout:{"icon-image":[`image`,[`get`,`markerId`]],"icon-anchor":`bottom`,"icon-allow-overlap":!0}})}_addLayer(e,t){t===`Point`&&(this._addPointLayer(e),this._addMarkerLayer(e)),t===`LineString`&&this._addLineLayer(e),t===`Polygon`&&(this._addFillLayer(e),this._addFillOutlineLayer(e))}_addGeoJSONLayer(e,t){let n=`${this._prefixId}-${e.toLowerCase()}`;return this._addGeoJSONSource(n,t),this._addLayer(n,e),n}_setGeoJSONLayerData(e,t){let n=`${this._prefixId}-${e.toLowerCase()}`;return this._map.getSource(n).setData({type:`FeatureCollection`,features:t}),n}updateChangedIds(e){[...e.updated,...e.created].forEach(e=>{e.geometry.type===`Point`?this.changedIds.points=!0:e.geometry.type===`LineString`?this.changedIds.linestrings=!0:e.geometry.type===`Polygon`&&(this.changedIds.polygons=!0)}),e.deletedIds.length>0&&(this.changedIds.deletion=!0),e.created.length===0&&e.updated.length===0&&e.deletedIds.length===0&&(this.changedIds.styling=!0)}getLngLatFromEvent(e){let{left:t,top:n}=this._container.getBoundingClientRect();return this.unproject(e.clientX-t,e.clientY-n)}getMapEventElement(){return this._map.getCanvas()}setDraggability(e){e?(this._initialDragRotate&&this._map.dragRotate.enable(),this._initialDragPan&&this._map.dragPan.enable()):(this._initialDragRotate&&this._map.dragRotate.disable(),this._initialDragPan&&this._map.dragPan.disable())}project(e,t){let{x:n,y:r}=this._map.project({lng:e,lat:t});return{x:n,y:r}}unproject(e,t){let{lng:n,lat:r}=this._map.unproject({x:e,y:t});return{lng:n,lat:r}}setCursor(e){let t=this._map.getCanvas();e===`unset`?t.style.removeProperty(`cursor`):t.style.cursor=e}setDoubleClickToZoom(e){e?this._map.doubleClickZoom.enable():this._map.doubleClickZoom.disable()}render(e,t){this.updateChangedIds(e),this._nextRender&&cancelAnimationFrame(this._nextRender),this._nextRender=requestAnimationFrame(()=>{if(!this._currentModeCallbacks)return;let n=[...e.created,...e.updated,...e.unchanged],r=[],i=[],a=[];for(let e=0;e<n.length;e++){let o=n[e],{properties:s}=o,c=t[s.mode](o);if(s.zIndex=c.zIndex,s.zIndex=c.zIndex,o.geometry.type===`Point`){s.pointColor=c.pointColor,s.pointOutlineColor=c.pointOutlineColor,s.pointOutlineWidth=c.pointOutlineWidth;let e=c.pointOutlineOpacity;s.pointOutlineOpacity=e===void 0?1:e,s.pointWidth=c.pointWidth;let t=c.pointOpacity;if(s.pointOpacity=t===void 0?1:t,c.markerUrl&&c.markerWidth&&c.markerHeight){let e=`marker-${this.hashCode(c.markerUrl)}`;this._map.hasImage(e)||this.resizeImage(c.markerUrl,c.markerWidth,c.markerHeight,t=>{this._map.loadImage(t).then(t=>{this._map.hasImage(e)||this._map.addImage(e,t.data)})}),s.markerId=e,s.pointWidth=0}r.push(o)}else if(o.geometry.type===`LineString`){s.lineStringColor=c.lineStringColor,s.lineStringWidth=c.lineStringWidth;let e=c.lineStringOpacity;s.lineStringOpacity=e===void 0?1:e,i.push(o)}else if(o.geometry.type===`Polygon`){let e=c.polygonOutlineOpacity;s.polygonFillColor=c.polygonFillColor,s.polygonFillOpacity=c.polygonFillOpacity,s.polygonOutlineOpacity=e===void 0?1:e,s.polygonOutlineColor=c.polygonOutlineColor,s.polygonOutlineWidth=c.polygonOutlineWidth,a.push(o)}}let o=this.changedIds.deletion||this.changedIds.styling,s=o||this.changedIds.linestrings,c=o||this.changedIds.polygons;(o||this.changedIds.points)&&this._setGeoJSONLayerData(`Point`,r),s&&this._setGeoJSONLayerData(`LineString`,i),c&&this._setGeoJSONLayerData(`Polygon`,a),this.changedIds={points:!1,linestrings:!1,polygons:!1,deletion:!1,styling:!1}})}clear(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this._nextRender&&=(cancelAnimationFrame(this._nextRender),void 0),this._setGeoJSONLayerData(`Point`,[]),this._setGeoJSONLayerData(`LineString`,[]),this._setGeoJSONLayerData(`Polygon`,[]))}getCoordinatePrecision(){return super.getCoordinatePrecision()}unregister(){super.unregister(),this.changedIds={points:!1,linestrings:!1,polygons:!1,deletion:!1,styling:!1},this._map.removeLayer(`${this._prefixId}-point`),this._map.removeLayer(`${this._prefixId}-point-marker`),this._map.removeSource(`${this._prefixId}-point`),this._map.removeLayer(`${this._prefixId}-linestring`),this._map.removeSource(`${this._prefixId}-linestring`),this._map.removeLayer(`${this._prefixId}-polygon`),this._map.removeLayer(`${this._prefixId}-polygon-outline`),this._map.removeSource(`${this._prefixId}-polygon`)}register(e){var t;super.register(e);let n=this._addGeoJSONLayer(`Polygon`,[]),r=this._addGeoJSONLayer(`LineString`,[]),i=this._addGeoJSONLayer(`Point`,[]);var a;this._renderBeforeLayerId&&(this._map.moveLayer(i,this._renderBeforeLayerId),this._map.moveLayer(r,i),this._map.moveLayer(`${n}-outline`,r),this._map.moveLayer(n,`${n}-outline`)),(t=this._currentModeCallbacks)!=null&&t.onReady&&((a=this._currentModeCallbacks)==null||a.onReady())}},ni={modes:[`render`,`point`,`marker`,`linestring`,`polygon`,`rectangle`,`angled-rectangle`,`sensor`,`sector`,`circle`,`freehand`,`freehand-linestring`,`select`,`delete-selection`,`delete`,`undo`,`redo`,`download`],open:!1},ri={modes:[`render`,`point`,`marker`,`linestring`,`polygon`,`rectangle`,`angled-rectangle`,`sensor`,`sector`,`circle`,`freehand`,`freehand-linestring`,`select`,`delete-selection`,`delete`,`undo`,`redo`,`download`],open:!1,modeOptions:{point:new Cn({editable:!0,styles:{pointColor:`#FFFFFF`,pointWidth:5,pointOutlineColor:`#666666`,pointOutlineWidth:1}}),marker:new Vr({editable:!0,styles:{markerUrl:`data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='UTF-8'%20standalone='no'?%3e%3csvg%20xmlns:dc='http://purl.org/dc/elements/1.1/'%20xmlns:cc='http://creativecommons.org/ns%23'%20xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns%23'%20xmlns:svg='http://www.w3.org/2000/svg'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:sodipodi='http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd'%20xmlns:inkscape='http://www.inkscape.org/namespaces/inkscape'%20inkscape:version='1.0%20(4035a4fb49,%202020-05-01)'%20sodipodi:docname='poi.svg'%20id='svg4460'%20height='100'%20width='100'%20version='1.1'%3e%3csodipodi:namedview%20inkscape:document-rotation='0'%20inkscape:current-layer='svg4460'%20inkscape:window-maximized='1'%20inkscape:window-y='-8'%20inkscape:window-x='-8'%20inkscape:cy='70.031285'%20inkscape:cx='-78.460726'%20inkscape:zoom='2.02'%20showgrid='false'%20id='namedview11'%20inkscape:window-height='1017'%20inkscape:window-width='1920'%20inkscape:pageshadow='2'%20inkscape:pageopacity='0'%20guidetolerance='10'%20gridtolerance='10'%20objecttolerance='10'%20borderopacity='1'%20bordercolor='%23666666'%20pagecolor='%23ffffff'%20/%3e%3cdefs%20id='defs4462'%20/%3e%3cmetadata%20id='metadata4465'%3e%3crdf:RDF%3e%3ccc:Work%20rdf:about=''%3e%3cdc:format%3eimage/svg+xml%3c/dc:format%3e%3cdc:type%20rdf:resource='http://purl.org/dc/dcmitype/StillImage'%20/%3e%3cdc:title%3e%3c/dc:title%3e%3c/cc:Work%3e%3c/rdf:RDF%3e%3c/metadata%3e%3cpath%20d='M%2050.001528,3.3861402e-7%20C%2030.763177,3.3861402e-7%2015,15.718144%2015,34.901534%20c%200,7.432782%202.373565,14.339962%206.391689,20.019029%20l%2024.338528,42.073163%20c%203.40849,4.452814%205.674917,3.607154%208.509014,-0.23458%20L%2081.083105,51.075788%20C%2081.625418,50.0948%2082.050328,49.050173%2082.421327,47.983517%2084.078241,43.936622%2085.000002,39.521943%2085,34.901534%2085,15.718144%2069.23988,3.3861402e-7%2050.001528,3.3861402e-7%20Z%20m%200,16.35400066138598%20c%2010.359296,0%2018.597616,8.21783%2018.597618,18.547533%200,10.329703%20-8.238322,18.544487%20-18.597618,18.544487%20-10.359299,0%20-18.600672,-8.214784%20-18.600672,-18.544487%200,-10.329703%208.241373,-18.547533%2018.600672,-18.547533%20z'%20style='fill:rgb(95,%2099,%20104);stroke-width:4.26019'%20id='path4135'%20/%3e%3c/svg%3e`,markerWidth:27,markerHeight:27}}),linestring:new gn({editable:!0,styles:{lineStringColor:`#666666`,lineStringWidth:2,closingPointColor:`#FFFFFF`,closingPointWidth:3,closingPointOutlineColor:`#666666`,closingPointOutlineWidth:1}}),polygon:new En({editable:!0,styles:{fillColor:`#EDEFF0`,fillOpacity:.7,outlineColor:`#666666`,outlineWidth:2,closingPointColor:`#FAFAFA`,closingPointWidth:3,closingPointOutlineColor:`#666666`,closingPointOutlineWidth:1}}),rectangle:new kn({styles:{fillColor:`#EDEFF0`,fillOpacity:.7,outlineColor:`#666666`,outlineWidth:2}}),"angled-rectangle":new Er({styles:{fillColor:`#EDEFF0`,fillOpacity:.7,outlineColor:`#666666`,outlineWidth:2}}),circle:new It({styles:{fillColor:`#EDEFF0`,fillOpacity:.7,outlineColor:`#666666`,outlineWidth:2}}),freehand:new Bt({styles:{fillColor:`#EDEFF0`,fillOpacity:.7,outlineColor:`#666666`,outlineWidth:2,closingPointColor:`#FAFAFA`,closingPointWidth:3,closingPointOutlineColor:`#666666`,closingPointOutlineWidth:1}}),"freehand-linestring":new Rr({styles:{lineStringColor:`#666666`,lineStringWidth:2,closingPointColor:`#FFFFFF`,closingPointWidth:3,closingPointOutlineColor:`#666666`,closingPointOutlineWidth:1}}),sensor:new Nr({styles:{fillColor:`#EDEFF0`,fillOpacity:.7,outlineColor:`#666666`,outlineWidth:2,centerPointColor:`#FAFAFA`,centerPointWidth:3,centerPointOutlineColor:`#666666`,centerPointOutlineWidth:1}}),sector:new Ar({styles:{fillColor:`#EDEFF0`,fillOpacity:.7,outlineColor:`#666666`,outlineWidth:2}}),select:new Qn({flags:{point:{feature:{draggable:!1}},marker:{feature:{draggable:!1}},polygon:{feature:{draggable:!0,rotateable:!0,scaleable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},linestring:{feature:{draggable:!0,rotateable:!0,scaleable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},freehand:{feature:{draggable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},"freehand-linestring":{feature:{draggable:!0,rotateable:!0,scaleable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},circle:{feature:{draggable:!0,coordinates:{resizable:`center`,deletable:!1,midpoints:!1}}},rectangle:{feature:{draggable:!0,rotateable:!0,coordinates:{resizable:`opposite`,deletable:!1,midpoints:!1}}},"angled-rectangle":{feature:{draggable:!0,rotateable:!0,coordinates:{resizable:`opposite`,deletable:!1,midpoints:!1}}},sensor:{feature:{draggable:!0,rotateable:!0,scaleable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},sector:{feature:{draggable:!0,rotateable:!0,scaleable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}}}})},pointLayerLabelSpec:{id:`{prefix}-point-label`,type:`symbol`,source:`{prefix}-point`,filter:[`all`,[`==`,`$type`,`Point`],[`any`,[`==`,`mode`,`point`],[`==`,`mode`,`marker`]]],layout:{"text-field":[`case`,[`all`,[`has`,`elevation`],[`>`,[`get`,`elevation`],0]],[`concat`,`Alt. `,[`to-string`,[`floor`,[`get`,`elevation`]]],` `,[`get`,`elevationUnit`]],``],"symbol-placement":`point`,"text-size":[`interpolate`,[`linear`],[`zoom`],5,10,10,12,13,14,14,16,18,18],"text-overlap":`always`,"text-variable-anchor":[`left`,`right`,`top`,`bottom`],"text-radial-offset":.5,"text-justify":`center`,"text-letter-spacing":.05},paint:{"text-halo-color":`#F7F7F7`,"text-halo-width":2,"text-color":`#232E3D`}},lineLayerLabelSpec:{id:`{prefix}-line-label`,type:`symbol`,source:`{prefix}-line-source`,filter:[`==`,`$type`,`Point`],layout:{"text-field":[`concat`,[`to-string`,[`get`,`distance`]],` `,[`get`,`unit`],[`case`,[`==`,[`get`,`total`],0],``,[`concat`,`
2
2
  (`,[`to-string`,[`get`,`total`]],` `,[`get`,`totalUnit`],`)`]],[`case`,[`all`,[`has`,`elevation`],[`>`,[`get`,`elevation`],0]],[`concat`,`
3
3
  Alt. `,[`to-string`,[`floor`,[`get`,`elevation`]]],` `,[`get`,`elevationUnit`]],``]],"symbol-placement":`point`,"text-size":[`interpolate`,[`linear`],[`zoom`],5,10,10,12,13,14,14,16,18,18],"text-overlap":`always`,"text-variable-anchor":[`left`,`right`,`top`,`bottom`],"text-radial-offset":.5,"text-justify":`center`,"text-letter-spacing":.05},paint:{"text-halo-color":`#F7F7F7`,"text-halo-width":2,"text-color":`#232E3D`}},routingLineLayerNodeSpec:{id:`{prefix}-line-node`,type:`circle`,source:`{prefix}-line-source`,filter:[`==`,`$type`,`Point`],layout:{},paint:{"circle-radius":3,"circle-color":`#FFFFFF`,"circle-stroke-color":`#000000`,"circle-stroke-width":1}},polygonLayerSpec:{id:`{prefix}-polygon-label`,type:`symbol`,source:`{prefix}-polygon-source`,filter:[`==`,`$type`,`Point`],layout:{"text-field":[`concat`,[`to-string`,[`get`,`area`]],` `,[`get`,`unit`]],"symbol-placement":`point`,"text-size":[`interpolate`,[`linear`],[`zoom`],5,10,10,12,13,14,14,16,18,18],"text-overlap":`always`,"text-letter-spacing":.05},paint:{"text-halo-color":`#F7F7F7`,"text-halo-width":2,"text-color":`#232E3D`}},computeElevation:!1,terrainSource:{url:`https://tiles.mapterhorn.com/{z}/{x}/{y}.webp`,encoding:`terrarium`,tileSize:512,minzoom:0,maxzoom:12,tms:!1},measureUnitType:`metric`,distancePrecision:2,distanceUnit:void 0,areaPrecision:2,areaUnit:void 0,measureUnitSymbols:JSON.parse(JSON.stringify({kilometer:`km`,meter:`m`,centimeter:`cm`,mile:`mi`,foot:`ft`,inch:`in`,"square meters":`m²`,"square kilometers":`km²`,ares:`a`,hectares:`ha`,"square feet":`ft²`,"square yards":`yd²`,acres:`acres`,"square miles":`mi²`})),elevationCacheConfig:{enabled:!0,maxSize:1e3,ttl:3600*1e3,precision:9},adapterOptions:{prefixId:`td-measure`}},ii={modes:[`render`,`routing`,`time-isochrone`,`distance-isochrone`,`select`,`delete-selection`,`delete`,`download`,`settings`],open:!1,modeOptions:{"time-isochrone":new Cn({modeName:`time-isochrone`,editable:!1,styles:{pointColor:`#FFFFFF`,pointWidth:5,pointOutlineColor:`#666666`,pointOutlineWidth:1}}),"distance-isochrone":new Cn({modeName:`distance-isochrone`,editable:!1,styles:{pointColor:`#FFFFFF`,pointWidth:5,pointOutlineColor:`#666666`,pointOutlineWidth:1}}),routing:new gn({modeName:`routing`,editable:!1,styles:{lineStringColor:`#FF0000`,lineStringWidth:2,closingPointColor:`#FF0000`,closingPointWidth:3,closingPointOutlineColor:`#666666`,closingPointOutlineWidth:1}}),select:new Qn({flags:{"time-isochrone":{feature:{draggable:!1}},"distance-isochrone":{feature:{draggable:!1}},routing:{feature:{draggable:!1,rotateable:!1,scaleable:!1,coordinates:{midpoints:!1,draggable:!1,deletable:!1}}}}}),settings:new An({modeName:`settings`,styles:{}})},valhallaOptions:{url:``,routingOptions:{costingModel:`auto`,distanceUnit:`kilometers`},isochroneOptions:{timeCostingModel:`auto`,distanceCostingModel:`auto`,contours:[{time:3,distance:1,color:`#ff0000`},{time:5,distance:2,color:`#ffff00`},{time:10,distance:3,color:`#0000ff`},{time:15,distance:4,color:`#ff00ff`}]}},adapterOptions:{prefixId:`td-valhalla`},routingLineLayerNodeLabelSpec:{id:`{prefix}-routing-node-label`,type:`symbol`,source:`{prefix}-routing-source`,filter:[`==`,`$type`,`Point`],layout:{"text-field":[`case`,[`all`,[`has`,`distance`],[`has`,`distance_unit`],[`has`,`time`]],[`concat`,[`to-string`,[`get`,`text`]],`
4
4
  `,[`to-string`,[`/`,[`round`,[`*`,[`get`,`distance`],10]],10]],[`to-string`,[`get`,`distance_unit`]],`
5
5
  `,[`to-string`,[`get`,`time`]],`min`],[`all`,[`has`,`costingModel`]],[`concat`,[`to-string`,[`get`,`text`]],`
6
- (`,[`to-string`,[`get`,`costingModel`]],`)`],[`concat`,[`to-string`,[`get`,`text`]]]],"symbol-placement":`point`,"text-size":[`interpolate`,[`linear`],[`zoom`],5,10,10,12,13,14,14,16,18,18],"text-overlap":`always`,"text-variable-anchor":[`left`,`right`,`top`,`bottom`],"text-radial-offset":.5,"text-justify":`left`,"text-letter-spacing":.05},paint:{"text-halo-color":`#F7F7F7`,"text-halo-width":2,"text-color":`#232E3D`}},routingLineLayerNodeSpec:{id:`{prefix}-routing-node`,type:`circle`,source:`{prefix}-routing-source`,filter:[`==`,`$type`,`Point`],layout:{},paint:{"circle-radius":3,"circle-color":[`case`,[`==`,[`get`,`text`],`Start`],`#0000FF`,[`==`,[`get`,`text`],`Goal`],`#FFFF00`,`#FFFFFF`],"circle-stroke-color":`#000000`,"circle-stroke-width":1}},timeIsochronePolygonLayerSpec:{id:`{prefix}-time-isochrone-polygon`,type:`fill`,source:`{prefix}-time-isochrone-source`,layout:{},paint:{"fill-color":[`get`,`fillColor`],"fill-opacity":[`get`,`fillOpacity`]}},timeIsochroneLineLayerSpec:{id:`{prefix}-time-isochrone-line`,type:`line`,source:`{prefix}-time-isochrone-source`,layout:{"line-join":`round`,"line-cap":`round`},paint:{"line-color":[`get`,`fillColor`],"line-width":3}},timeIsochroneLabelLayerSpec:{id:`{prefix}-time-isochrone-label`,type:`symbol`,source:`{prefix}-time-isochrone-source`,layout:{"symbol-placement":`line`,"text-pitch-alignment":`viewport`,"text-field":[`concat`,[`get`,`contour`],` `,`min`],"text-size":12,"symbol-spacing":100,"text-max-angle":45},paint:{"text-color":`rgb(0, 0, 0)`,"text-halo-width":1,"text-halo-color":`rgb(255, 255, 255)`}},distanceIsochronePolygonLayerSpec:{id:`{prefix}-distance-isochrone-polygon`,type:`fill`,source:`{prefix}-distance-isochrone-source`,layout:{},paint:{"fill-color":[`get`,`fillColor`],"fill-opacity":[`get`,`fillOpacity`]}},distanceIsochroneLineLayerSpec:{id:`{prefix}-distance-isochrone-line`,type:`line`,source:`{prefix}-distance-isochrone-source`,layout:{"line-join":`round`,"line-cap":`round`},paint:{"line-color":[`get`,`fillColor`],"line-width":3}},distanceIsochroneLabelLayerSpec:{id:`{prefix}-distance-isochrone-label`,type:`symbol`,source:`{prefix}-distance-isochrone-source`,layout:{"symbol-placement":`line`,"text-pitch-alignment":`viewport`,"text-field":[`concat`,[`get`,`contour`],` `,`km`],"text-size":12,"symbol-spacing":100,"text-max-angle":45},paint:{"text-color":`rgb(0, 0, 0)`,"text-halo-width":1,"text-halo-color":`rgb(255, 255, 255)`}}},ai=`data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='UTF-8'%20standalone='no'?%3e%3csvg%20xmlns:dc='http://purl.org/dc/elements/1.1/'%20xmlns:cc='http://creativecommons.org/ns%23'%20xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns%23'%20xmlns:svg='http://www.w3.org/2000/svg'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:sodipodi='http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd'%20xmlns:inkscape='http://www.inkscape.org/namespaces/inkscape'%20inkscape:version='1.0%20(4035a4fb49,%202020-05-01)'%20sodipodi:docname='poi.svg'%20id='svg4460'%20height='100'%20width='100'%20version='1.1'%3e%3csodipodi:namedview%20inkscape:document-rotation='0'%20inkscape:current-layer='svg4460'%20inkscape:window-maximized='1'%20inkscape:window-y='-8'%20inkscape:window-x='-8'%20inkscape:cy='70.031285'%20inkscape:cx='-78.460726'%20inkscape:zoom='2.02'%20showgrid='false'%20id='namedview11'%20inkscape:window-height='1017'%20inkscape:window-width='1920'%20inkscape:pageshadow='2'%20inkscape:pageopacity='0'%20guidetolerance='10'%20gridtolerance='10'%20objecttolerance='10'%20borderopacity='1'%20bordercolor='%23666666'%20pagecolor='%23ffffff'%20/%3e%3cdefs%20id='defs4462'%20/%3e%3cmetadata%20id='metadata4465'%3e%3crdf:RDF%3e%3ccc:Work%20rdf:about=''%3e%3cdc:format%3eimage/svg+xml%3c/dc:format%3e%3cdc:type%20rdf:resource='http://purl.org/dc/dcmitype/StillImage'%20/%3e%3cdc:title%3e%3c/dc:title%3e%3c/cc:Work%3e%3c/rdf:RDF%3e%3c/metadata%3e%3cpath%20d='M%2050.001528,3.3861402e-7%20C%2030.763177,3.3861402e-7%2015,15.718144%2015,34.901534%20c%200,7.432782%202.373565,14.339962%206.391689,20.019029%20l%2024.338528,42.073163%20c%203.40849,4.452814%205.674917,3.607154%208.509014,-0.23458%20L%2081.083105,51.075788%20C%2081.625418,50.0948%2082.050328,49.050173%2082.421327,47.983517%2084.078241,43.936622%2085.000002,39.521943%2085,34.901534%2085,15.718144%2069.23988,3.3861402e-7%2050.001528,3.3861402e-7%20Z%20m%200,16.35400066138598%20c%2010.359296,0%2018.597616,8.21783%2018.597618,18.547533%200,10.329703%20-8.238322,18.544487%20-18.597618,18.544487%20-10.359299,0%20-18.600672,-8.214784%20-18.600672,-18.544487%200,-10.329703%208.241373,-18.547533%2018.600672,-18.547533%20z'%20style='fill:%233FB1CE;stroke-width:4.26019'%20id='path4135'%20/%3e%3c/svg%3e`,oi=(e,t)=>{let n=t.updateType;return n===`finish`||n===`commit`?Sr(e):{valid:!0}},si=()=>({render:new An({modeName:`render`,styles:{}}),point:new Cn({editable:!0}),marker:new Vr({editable:!0,styles:{markerUrl:ai,markerWidth:27,markerHeight:27}}),linestring:new gn({editable:!0}),polygon:new En({editable:!0,validation:oi}),rectangle:new kn,"angled-rectangle":new Er,circle:new It,freehand:new Bt,"freehand-linestring":new Rr,sensor:new Nr,sector:new Ar,select:new Qn({flags:{point:{feature:{draggable:!0}},marker:{feature:{draggable:!0}},polygon:{feature:{draggable:!0,rotateable:!0,scaleable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},linestring:{feature:{draggable:!0,rotateable:!0,scaleable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},freehand:{feature:{draggable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},"freehand-linestring":{feature:{draggable:!0,rotateable:!0,scaleable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},circle:{feature:{draggable:!0,coordinates:{resizable:`center`,deletable:!1,midpoints:!1}}},rectangle:{feature:{draggable:!0,rotateable:!0,coordinates:{resizable:`opposite`,deletable:!1,midpoints:!1}}},"angled-rectangle":{feature:{draggable:!0,rotateable:!0,coordinates:{resizable:`opposite`,deletable:!1,midpoints:!1}}},sensor:{feature:{draggable:!0,rotateable:!0,scaleable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},sector:{feature:{draggable:!0,rotateable:!0,scaleable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}}}}),delete:new An({modeName:`delete`,styles:{}}),"delete-selection":new An({modeName:`delete-selection`,styles:{}}),download:new An({modeName:`download`,styles:{}}),undo:new An({modeName:`undo`,styles:{}}),redo:new An({modeName:`redo`,styles:{}})}),Y=6371008.8;Y*100,Y*100,360/(2*Math.PI),Y*3.28084,Y*39.37,Y/1e3,Y/1e3,Y/1609.344,Y*1e3,Y*1e3,Y/1852,Y*1.0936,Y*Y/2,Math.PI/180;var ci=e=>e.charAt(0).toUpperCase()+e.slice(1),li=[`{prefix}-point`,`{prefix}-point-lower`,`{prefix}-linestring`,`{prefix}-polygon`,`{prefix}-polygon-outline`];[...li,ri.polygonLayerSpec?.source,ri.lineLayerLabelSpec?.source],[...li,ii.routingLineLayerNodeLabelSpec?.source,ii.routingLineLayerNodeSpec?.source,ii.timeIsochronePolygonLayerSpec?.source,ii.timeIsochroneLineLayerSpec?.source,ii.timeIsochroneLabelLayerSpec?.source,ii.distanceIsochronePolygonLayerSpec?.source,ii.distanceIsochroneLineLayerSpec?.source,ii.distanceIsochroneLabelLayerSpec?.source];var ui=(e,t,n=li,r=`td`)=>{n=n.map(e=>e.replace(`{prefix}`,r));let i=JSON.parse(JSON.stringify(e));return t&&(t.onlyTerraDrawLayers===!0?(i.layers=i.layers.filter(e=>`source`in e&&n.includes(e.source)),Object.keys(i.sources).forEach(e=>{n.includes(e)||delete i.sources[e]})):t.excludeTerraDrawLayers===!0&&(i.layers=i.layers.filter(e=>`source`in e&&!n.includes(e.source)||e.type===`background`),Object.keys(i.sources).forEach(e=>{n.includes(e)&&delete i.sources[e]}))),i},di=class{className;dialog;title;constructor(e,t){this.className=e,this.title=t}create(e,t){let n=document.getElementsByClassName(this.className);n.length>0&&Array.from(n).forEach(e=>{e.remove()}),this.dialog=document.createElement(`dialog`),this.dialog.classList.add(this.className);let r=document.createElement(`div`);r.classList.add(`dialog-header`);let i=document.createElement(`h3`);i.textContent=this.title,i.classList.add(`dialog-title`),r.appendChild(i);let a=document.createElement(`button`);a.type=`button`,a.classList.add(`close-button`),a.innerHTML=`×`,a.setAttribute(`aria-label`,`Close dialog`),a.addEventListener(`click`,()=>{this.close()}),r.appendChild(a),this.dialog.appendChild(r);let o=document.createElement(`div`);o.classList.add(`content`),this.dialog.appendChild(t(o)),this.dialog.addEventListener(`click`,e=>{let t=e.target?.getBoundingClientRect();t&&(t.left>e.clientX||t.right<e.clientX||t.top>e.clientY||t.bottom<e.clientY)&&this.close()}),e.appendChild(this.dialog)}open(){this.dialog?.showModal()}close(){this.dialog?.close()}createSegmentButtons(e,t,n=()=>{}){let r=document.createElement(`div`);return r.classList.add(`segment-buttons`),e.forEach(e=>{let i=document.createElement(`button`);i.type=`button`,i.classList.add(`segment-button`),i.value=e.value,i.textContent=e.label,e.value===t&&i.classList.add(`active`),i.addEventListener(`click`,()=>{r.querySelectorAll(`.segment-button`).forEach(e=>e.classList.remove(`active`)),i.classList.add(`active`),n(i.value)}),r.appendChild(i)}),r}};2*Math.PI*6378137/2;var fi=class{controlContainer;map;modeButtons={};_isExpanded=!1;_cssPrefix=``;get isExpanded(){return this._isExpanded}get cssPrefix(){return this._cssPrefix}set isExpanded(e){this._isExpanded=e;let t=document.getElementsByClassName(`maplibregl-terradraw-${this.cssPrefix}add-control`);for(let e=0;e<t.length;e++){let n=t.item(e);n&&(this.isExpanded?n.classList.remove(`hidden`):n.classList.add(`hidden`))}let n=document.getElementsByClassName(`maplibregl-terradraw-${this.cssPrefix}render-button`);n&&n.length>0&&(this.isExpanded?n.item(0)?.classList.add(`enabled`):(n.item(0)?.classList.remove(`enabled`),this.resetActiveMode())),this.toggleDeleteSelectionButton(),this.toggleButtonsWhenNoFeature(),this.isExpanded?this.dispatchEvent(`expanded`):this.dispatchEvent(`collapsed`)}get showDeleteConfirmation(){return this.options.showDeleteConfirmation===!0}set showDeleteConfirmation(e){this.options.showDeleteConfirmation=e}terradraw;options;events={};defaultMode=`render`;constructor(e){this.modeButtons={},this.options={...ni,modes:[...ni.modes??[]],...e};let t=this.options.adapterOptions?.prefixId??`td`;this.options.adapterOptions||(this.options.adapterOptions={}),this.options.adapterOptions?.prefixId||(this.options.adapterOptions.prefixId=t),this.options.undoRedo||(this.options.undoRedo={modeLevel:new Zr({maxStackSize:100}),sessionLevel:new Qr({maxStackSize:100}),keyboardShortcuts:new Gr})}getDefaultPosition(){return`top-right`}onAdd(e){if(this.options&&this.options.modes&&this.options.modes.length===0)throw Error(`At least a mode must be enabled.`);this.map=e;let t=si(),n=[];return this.options?.modes?.forEach(e=>{if(this.options.modeOptions&&this.options.modeOptions[e]){let r=this.options.modeOptions[e];if(e===`select`){let n=t[e];if(n){let e=n.flags;Object.keys(e).forEach(t=>{r.flags[t]||(r.flags[t]=e[t])})}}n.push(r)}else t[e]&&n.push(t[e])}),n.forEach(e=>{e.state!==`unregistered`&&(e._state=`unregistered`)}),this.options?.modes?.includes(`render`)||(n.push(new An({modeName:`default`,styles:{}})),this.defaultMode=`default`),this.isExpanded=this.options.open===!0,this.terradraw=new ei({adapter:new ti({map:e,...this.options.adapterOptions}),modes:n,undoRedo:this.options.undoRedo}),this.map?.loaded()?this.terradraw.start():this.map?.once(`load`,()=>{this.terradraw?.start()}),this.controlContainer=document.createElement(`div`),this.controlContainer.classList.add(`maplibregl-ctrl`),this.controlContainer.classList.add(`maplibregl-ctrl-group`),n.forEach(e=>{e.mode!==`default`&&this.addTerradrawButton(e.mode)}),Object.values(this.modeButtons).forEach(e=>{this.controlContainer?.appendChild(e)}),this.toggleButtonsWhenNoFeature(),this.terradraw?.on(`finish`,this.toggleButtonsWhenNoFeature.bind(this)),this.terradraw?.on(`history`,this.handleHistoryChange.bind(this)),this.map.once(`idle`,()=>{this.toggleButtonsWhenNoFeature()}),this.controlContainer}onRemove(){!this.controlContainer||!this.controlContainer.parentNode||!this.map||(this.deactivate(),this.modeButtons={},this.terradraw=void 0,this.map=void 0,this.controlContainer.parentNode.removeChild(this.controlContainer))}on(e,t){this.events[e]?this.events[e].push(t):this.events[e]=[t]}off(e,t){if(!this.events[e])return;let n=this.events[e].findIndex(e=>e===t);n!==-1&&this.events[e].splice(n,1)}dispatchEvent(e,t){this.events[e]&&this.events[e].forEach(e=>{let n=(this.terradraw?.getSnapshot())?.filter(e=>e.properties.selected===!0);e({feature:n,mode:this.terradraw?.getMode(),...t})})}activate(){this.terradraw&&(this.terradraw.enabled||this.terradraw.start())}deactivate(){this.terradraw&&this.terradraw.enabled&&(this.resetActiveMode(),this.dispatchEvent(`mode-changed`),this.terradraw.stop())}handleModeChange(e,t){let n=t.setMode(e);return this.syncButtonStates(e),e!==this.defaultMode&&this.activate(),this.dispatchEvent(`mode-changed`),n}syncButtonStates(e){if(!this.controlContainer)return;let t=this.controlContainer.getElementsByClassName(`maplibregl-terradraw-${this.cssPrefix}add-control`);for(let e=0;e<t.length;e++){let n=t.item(e);n&&n.classList.remove(`active`)}if(e!==this.defaultMode&&e!==`render`){let t=this.controlContainer.getElementsByClassName(`maplibregl-terradraw-${this.cssPrefix}add-${e}-button`);t&&t.length>0&&t[0].classList.add(`active`)}this.toggleDeleteSelectionButton(),this.toggleButtonsWhenNoFeature()}getTerraDrawInstance(){return this.terradraw?new Proxy(this.terradraw,{get:(e,t,n)=>t===`setMode`?t=>this.handleModeChange(t,e):t===`clearUndoRedoHistory`?()=>{e.clearUndoRedoHistory(),this.handleHistoryChange({undoSize:0,redoSize:0})}:Reflect.get(e,t,n)}):this.terradraw}handleHistoryChange(e){if(!this.controlContainer)return;let t=this.controlContainer.getElementsByClassName(`maplibregl-terradraw-${this.cssPrefix}undo-button`);for(let n=0;n<t.length;n++){let r=t.item(n);r&&(r.disabled=e.undoSize===0)}let n=this.controlContainer.getElementsByClassName(`maplibregl-terradraw-${this.cssPrefix}redo-button`);for(let t=0;t<n.length;t++){let r=n.item(t);r&&(r.disabled=e.redoSize===0)}}toggleEditor(){this.terradraw&&(this.isExpanded=!this.isExpanded)}resetActiveMode(){this.terradraw&&(this.terradraw.enabled||this.terradraw.start(),this.terradraw?.setMode(this.defaultMode),this.syncButtonStates(this.defaultMode))}addTerradrawButton(e){let t=document.createElement(`button`);t.type=`button`,this.modeButtons[e]=t,e===`render`?(t.classList.add(`maplibregl-terradraw-${this.cssPrefix}${e}-button`),this.isExpanded&&t.classList.add(`enabled`),t.type=`button`,t.title=ci(`expand or collapse drawing tool`),t.addEventListener(`click`,this.toggleEditor.bind(this))):(t.classList.add(`maplibregl-terradraw-${this.cssPrefix}add-control`),this.isExpanded||t.classList.add(`hidden`),t.title=ci(e.replace(/-/g,` `)),e===`delete`?(t.classList.add(`maplibregl-terradraw-${this.cssPrefix}${e}-button`),t.addEventListener(`click`,this.handleDeleteAllFeatures.bind(this))):e===`delete-selection`?(t.classList.add(`maplibregl-terradraw-${this.cssPrefix}${e}-button`),t.classList.add(`hidden-delete-selection`),t.addEventListener(`click`,this.handleDeleteSelectedFeatures.bind(this))):e===`download`?(t.classList.add(`maplibregl-terradraw-${this.cssPrefix}${e}-button`),t.addEventListener(`click`,this.handleDownload.bind(this))):[`undo`,`redo`].includes(e)?(t.classList.add(`maplibregl-terradraw-${this.cssPrefix}${e}-button`),t.disabled=!0,t.addEventListener(`click`,()=>{this.terradraw&&(e===`undo`?this.terradraw.undo():this.terradraw.redo())})):(t.classList.add(`maplibregl-terradraw-${this.cssPrefix}add-${e}-button`),t.addEventListener(`click`,()=>{if(!this.terradraw)return;let n=t.classList.contains(`active`);this.activate(),this.resetActiveMode(),n||(this.terradraw.setMode(e),this.syncButtonStates(e)),this.dispatchEvent(`mode-changed`)})))}getFeatures(e=!1){if(!this.terradraw)return;let t={type:`FeatureCollection`,features:(this.terradraw?.getSnapshot()).filter(e=>e.properties.mode!==`select`)};return e===!0&&(t.features=t.features.filter(e=>e.properties.selected===!0)),t}cleanStyle(e,t){return ui(e,t,li,this.options.adapterOptions?.prefixId)}showDeleteConfirmationDialog(e){let t=new di(`maplibre-terradraw-delete-confirmation-dialog`,`Delete All Features`);t.create(document.body,n=>{let r=document.createElement(`p`);r.textContent=`Are you sure you want to delete all features?`,n.appendChild(r);let i=document.createElement(`div`);i.classList.add(`dialog-buttons`);let a=document.createElement(`button`);a.type=`button`,a.textContent=`Cancel`,a.classList.add(`dialog-button-cancel`),a.addEventListener(`click`,()=>{t.close()});let o=document.createElement(`button`);return o.type=`button`,o.textContent=`Delete`,o.classList.add(`dialog-button-delete`),o.addEventListener(`click`,()=>{e(),t.close()}),i.appendChild(a),i.appendChild(o),n.appendChild(i),n}),t.open()}handleDeleteAllFeatures(){if(!this.terradraw||!this.terradraw.enabled)return;let e=()=>{this.terradraw?.clear(),this.resetActiveMode(),this.toggleDeleteSelectionButton(),this.toggleButtonsWhenNoFeature(),this.dispatchEvent(`feature-deleted`)};this.options.showDeleteConfirmation===!0?this.showDeleteConfirmationDialog(e):e()}handleDeleteSelectedFeatures(){if(!this.terradraw||!this.terradraw.enabled)return;let e=(this.terradraw?.getSnapshot()).filter(e=>e.properties.selected===!0);if(e.length>0){let t=e.map(e=>e.id);this.terradraw.removeFeatures(t);for(let e of t)this.terradraw.deselectFeature(e);this.dispatchEvent(`feature-deleted`,{deletedIds:t})}this.toggleDeleteSelectionButton(),this.toggleButtonsWhenNoFeature()}handleDownload(){let e=this.getFeatures(!1),t=`data:application/json;charset=utf-8,`+encodeURIComponent(JSON.stringify(e)),n=document.createElement(`a`);n.setAttribute(`href`,t),n.setAttribute(`download`,`data.geojson`),document.body.appendChild(n),n.click(),n.remove()}toggleButtonsWhenNoFeature(){if(!this.controlContainer)return;let e=(this.terradraw?.getSnapshot())?.filter(e=>e.properties.mode!==`select`),t=!!(e&&e.length>0),n=[`maplibregl-terradraw-${this.cssPrefix}add-select-button`,`maplibregl-terradraw-${this.cssPrefix}download-button`,`maplibregl-terradraw-${this.cssPrefix}delete-button`];for(let e of n){let n=this.controlContainer.getElementsByClassName(e);for(let e=0;e<n.length;e++){let r=n.item(e);r&&(r.disabled=!t)}}}toggleDeleteSelectionButton(){let e=this.terradraw?.enabled||!1,t=this.terradraw?.getMode(),n=this.getFeatures(!1),r=n&&n.features.length>0,i=r&&e&&t===`select`,a=document.getElementsByClassName(`maplibregl-terradraw-${this.cssPrefix}delete-selection-button`);for(let e=0;e<a.length;e++){let t=a.item(e);t&&(i?t.classList.remove(`hidden-delete-selection`):t.classList.add(`hidden-delete-selection`))}if(!r){let e=document.getElementsByClassName(`maplibregl-terradraw-${this.cssPrefix}add-select-button`);for(let t=0;t<e.length;t++){let n=e.item(t);n&&n.classList.remove(`active`)}}}clearExtendedFeatures(e,t=void 0){if(this.map)for(let n of e){let e=this.map.getStyle().sources[n];e&&typeof e.data!=`string`&&e.data.type===`FeatureCollection`&&(t===void 0?e.data.features=[]:e.data.features=e.data.features.filter(e=>e.properties?.originalId?!t.includes(e.properties.originalId):!t.includes(e.id)),this.map.getSource(n)?.setData(e.data))}}},pi=class{drawControl=null;mapInstance;onFinishCallback;onChangeCallback;onDeleteCallback;onSelectCallback;changeTimer=null;lastFeatureCount=0;constructor(e){this.mapInstance=e.map}async addToMap(e=!0){this.drawControl||(this.drawControl=new fi({open:e}),this.mapInstance.addControl(this.drawControl,`top-right`),await new Promise(e=>{this.mapInstance.isStyleLoaded()?e():this.mapInstance.once(`idle`,()=>e())}),this.bindEvents())}bindEvents(){if(!this.drawControl)return;let e=this.drawControl.getTerraDrawInstance();e&&(e.on(`change`,()=>{let t=e.getSnapshot(),n=this.toGeoJSON(t);t.length<this.lastFeatureCount?this.onDeleteCallback?.(n):t.length>this.lastFeatureCount&&this.onFinishCallback?.(n),this.lastFeatureCount=t.length,this.changeTimer&&clearTimeout(this.changeTimer),this.changeTimer=setTimeout(()=>{this.onChangeCallback?.(n)},50)}),e.on(`select`,e=>this.onSelectCallback?.(String(e))),e.on(`deselect`,()=>this.onSelectCallback?.(null)))}toGeoJSON(e){return{type:`FeatureCollection`,features:e.map(e=>({type:`Feature`,geometry:e.geometry,properties:{...e.properties||{},id:e.id}}))}}changeMode(e){if(!this.drawControl)return;let t=this.drawControl.getTerraDrawInstance();if(t){if(e===`undo`){t.undo();return}if(e===`redo`){t.redo();return}if(e===`download`){this.downloadGeoJSON();return}t.setMode(e)}}setEnabled(e){if(!this.drawControl)return;let t=this.drawControl.getTerraDrawInstance();t&&(e?t.setMode(`select`):t.setMode(`render`))}getFeatureById(e){if(!this.drawControl)return;let t=this.drawControl.getTerraDrawInstance();if(t)return t.getSnapshot().find(t=>t.id===e)}deleteFeatureById(e){if(!this.drawControl)return;let t=this.drawControl.getTerraDrawInstance();if(!t)return;let n=Array.isArray(e)?e:[e];t.removeFeatures(n)}updateModeStyles(e,t){if(!this.drawControl)return;let n=this.drawControl.getTerraDrawInstance();n&&n.updateModeOptions(e,{styles:t})}drawWithForcedCoordinates(e,t){if(!this.drawControl)return;let n=this.drawControl.getTerraDrawInstance();if(!n)return;let r;e===`point`?r={type:`Point`,coordinates:t[0]}:e===`linestring`?r={type:`LineString`,coordinates:t}:e===`polygon`&&(r={type:`Polygon`,coordinates:[[...t,t[0]]]}),r&&n.addFeatures([{type:`Feature`,geometry:r,properties:{}}])}addFeatures(e){if(!this.drawControl||!e.features.length)return;let t=this.drawControl.getTerraDrawInstance();t&&(t.addFeatures(e.features),this.lastFeatureCount=t.getSnapshot().length)}clear(){if(!this.drawControl)return;let e=this.drawControl.getTerraDrawInstance();e&&(e.clear(),this.lastFeatureCount=0)}downloadGeoJSON(){let e=this.drawControl?.getTerraDrawInstance(),t=this.toGeoJSON(e?.getSnapshot()||[]),n=new Blob([JSON.stringify(t,null,2)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`draw_data_${Date.now()}.geojson`,i.click(),URL.revokeObjectURL(r)}destroy(){this.drawControl&&(this.changeTimer&&clearTimeout(this.changeTimer),this.mapInstance.removeControl(this.drawControl),this.drawControl=null,this.onFinishCallback=void 0,this.onChangeCallback=void 0,this.onDeleteCallback=void 0,this.onSelectCallback=void 0)}setOnFinish(e){this.onFinishCallback=e}setOnChange(e){this.onChangeCallback=e}setOnDelete(e){this.onDeleteCallback=e}setOnSelect(e){this.onSelectCallback=e}},mi=`<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1781332754772" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="40602" width="32" height="32" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M645.12 1007.104c-103.936 0-187.904-83.456-187.904-187.904v-136.704h68.096V819.2c0 66.56 52.736 119.296 119.296 119.296s119.296-52.736 119.296-119.296h68.096c1.024 103.936-84.48 187.904-186.88 187.904z" fill="#d81e06" p-id="40603"></path><path d="M631.296 1024c-103.936 0-187.904-83.456-187.904-187.904v-136.704H512v136.704c0 66.56 52.736 119.296 119.296 119.296s133.12-70.144 133.12-136.704l82.432 0.512c0 104.448-113.152 204.8-215.552 204.8zM321.024 16.896H389.12v204.8H321.024zM593.92 16.896h96.256v204.8H593.92zM358.4 419.328h272.896V512H358.4V419.328z" fill="#d81e06" p-id="40604"></path><path d="M755.2 716.8H248.832L155.648 457.216l-5.12-269.824h681.984v269.824L755.2 716.8zM307.2 648.704h387.072l60.416-201.216V276.48H238.592l-5.12 170.496L307.2 648.704z" fill="#d81e06" p-id="40605"></path><path d="M96.6144 678.80448L916.41856 123.392l51.11808 75.45344L147.7376 754.2528z" fill="#d81e06" p-id="40606"></path></svg>`,hi=`<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1781338967549" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="57837" xmlns:xlink="http://www.w3.org/1999/xlink" width="32" height="32"><path d="M426.666667 85.333333C473.6 85.333333 512 123.733333 512 170.666667L512 362.666667C512 362.666667 597.333333 352 597.333333 394.666667 597.333333 394.666667 682.666667 384 682.666667 426.666667 682.666667 426.666667 768 416 768 458.666667 768 458.666667 853.333333 448 853.333333 490.666667L853.333333 640C853.333333 682.666667 725.333333 896 725.333333 938.666667L384 938.666667C384 938.666667 298.666667 640 170.666667 554.666667 170.666667 554.666667 128 298.666667 341.333333 512L341.333333 170.666667C341.333333 123.733333 379.733333 85.333333 426.666667 85.333333Z" p-id="57838" fill="#f7f5f5"></path></svg>`,gi=`<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1781413096158" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="38813" width="32" height="32" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M770.56 343.488c-9.984 93.888-72.64 194.176-157.184 241.536l1.984-2.56c-23.552 26.304-17.152 48.576 19.2 66.752C858.176 683.584 1024 809.664 1024 960c0 75.328-727.424 76.16-956.096 30.336C25.28 981.76 0 971.52 0 960c0-149.376 163.776-274.88 385.28-310.144l-2.368 1.28c42.24-20.032 51.84-41.984 28.8-65.92C327.552 538.048 265.984 437.568 256 343.488h514.56zM512 0c136 0 274.176 106.048 284.48 240h3.52a32 32 0 1 1 0 64h-576a32 32 0 1 1 0-64h16.128C249.536 106.048 376 0 512 0z" fill="#707070" p-id="38814"></path></svg>`,_i=`<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1781413291157" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="47319" width="48" height="48" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M711.210667 344.917333l-294.101334 25.770667a387.584 387.584 0 0 1 3.584-75.818667c95.36 17.493333 191.914667 27.989333 288.810667 31.445334V267.562667c-145.621333-8.96-270.421333-106.965333-270.421333-106.965334A190.976 190.976 0 0 0 290.602667 110.933333c-33.578667 1.706667-65.365333 15.786667-89.301334 39.424a651.946667 651.946667 0 0 0-91.392 120.789334c-31.317333 51.029333-44.8 106.368-17.664 165.162666 8.661333 18.432 19.413333 35.84 32.042667 51.797334 2.858667 3.413333 12.714667 18.944 17.28 18.944-26.88 17.322667-52.736 36.053333-77.568 56.149333h60.672s39.68-29.781333 79.445333-54.272l81.365334 1.706667c-17.237333 12.928-53.845333 40.618667-81.152 66.005333H264.96s113.792-84.181333 208.597333-103.338667l-9.685333 1.706667C652.074667 421.546667 710.442667 418.133333 710.442667 418.133333l0.768-73.216zM102.826667 332.8c0-13.653333 16.896-24.661333 37.930666-24.661333s37.930667 11.008 37.930667 24.661333c0 13.653333-16.896 24.618667-37.930667 24.618667s-37.930667-10.965333-37.930666-24.618667z m144.896-107.52l-75.861334-4.010667s33.92-52.693333 44.757334-56.106666l46.848 0.938666-15.786667 59.178667z m34.304-56.917333l65.792 2.133333v59.306667L268.8 226.602667l13.269333-58.24z m35.456 140.16c20.906667 0 37.973333 10.965333 37.973333 24.618666 0 13.653333-16.896 24.661333-37.973333 24.661334-21.034667 0-37.930667-11.008-37.930667-24.661334 0-13.653333 16.896-24.618667 37.973333-24.618666z" fill="#1296db" p-id="47320"></path><path d="M653.098667 257.450667a190.634667 190.634667 0 0 0-190.421334 190.378666 190.634667 190.634667 0 0 0 190.421334 190.378667 190.677333 190.677333 0 0 0 190.421333-190.378667 190.634667 190.634667 0 0 0-190.421333-190.378666z" fill="#1296db" p-id="47321"></path><path d="M799.829333 633.856c-40.533333 32.085333-91.093333 51.968-146.773333 51.968-55.637333 0-106.112-19.925333-146.773333-51.968-76.970667 49.066667-130.56 135.082667-137.941334 234.794667 26.965333 3.626667 74.922667 7.594667 143.36 7.594666h282.666667c68.48 0 116.48-3.968 143.445333-7.594666-7.296-99.754667-60.885333-185.770667-137.984-234.794667z" fill="#1296db" p-id="47322"></path></svg>`,vi=`<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1781412204514" class="icon" viewBox="0 0 1049 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="15838" width="32.78125" height="32" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M573.540453 699.171348c-17.241629-6.05787-33.45808-13.140917-49.488135-18.639599-2.050356-1.025178-59.646716-21.155945-30.289348-111.278404l1.025178-2.982336 2.982336-3.075534c46.598997-48.556155 86.021748-98.044289 90.12246-208.390713H206.340358c2.982336 111.837592 42.498285 161.791717 89.004084 209.322693l1.957158 2.050356 1.025177 2.982336c26.375032 65.238596-13.140917 102.517793-37.279197 111.278404h-1.025178C134.577903 725.54638 0 805.417061 0 874.19718v30.289348c0 76.888345 141.66095 119.38663 397.489443 119.38663a1365.350606 1365.350606 0 0 0 222.556808-15.191273 254.710116 254.710116 0 0 1-77.820324-184.066038A263.750322 263.750322 0 0 1 573.540453 699.171348zM641.295394 253.125751c-7.083048-1.957158-26.281834-7.083048-26.281834-27.307013 0-77.913523-51.631688-146.600444-129.452013-174.932634-9.319799 23.299498-23.299498 87.978906-33.45808 143.618109l-31.314526-2.982336V9.319799c0-5.032692-2.982336-9.319799-7.083047-9.319799h-36.440416a9.319799 9.319799 0 0 0-7.176245 9.319799v182.015682l-33.364882 3.075534a1316.980847 1316.980847 0 0 0-33.45808-143.618108C225.352748 78.006721 174.746238 146.880038 174.746238 225.72554c0 19.198787-17.241629 25.256656-25.256656 27.307013-11.183759 2.982336-25.256656 7.083048-27.959398 45.48062h548.936182c-3.821118-39.329553-17.055233-42.405087-29.170972-45.387422z" p-id="15839" fill="#4CAF50"></path><path d="M1024.24595 641.108998l-23.113103 23.2063a63.374636 63.374636 0 0 1-89.563272-89.65647l22.740311-23.2063c12.861323-12.768125 4.287108-27.959398-18.639599-24.324676a115.845106 115.845106 0 0 0-95.155151 138.678614L626.756507 860.310679a63.374636 63.374636 0 1 0 89.470074 89.65647l193.851826-194.504213a115.751908 115.751908 0 0 0 138.492219-95.527943c3.541524-23.019904-11.556551-31.59412-24.324676-18.639599zM685.937233 920.050593a21.062747 21.062747 0 1 1 0-29.823358 20.969549 20.969549 0 0 1 0 29.823358z m-21.062747-275.120477l73.067227 73.253623 29.916556-29.823358-73.160425-73.253623-16.402847-31.407724-52.190876-37.279198-29.916556 29.823358 37.279197 52.284075zM909.612417 800.384369a10.438175 10.438175 0 0 0-14.911679 0l-44.828234 44.828235a10.531373 10.531373 0 0 0 0 14.911679l105.593326 105.686525a42.24665 42.24665 0 0 0 59.739914-59.739914z" p-id="15840" fill="#4CAF50"></path></svg>`,yi=`<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1781412389454" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="19959" xmlns:xlink="http://www.w3.org/1999/xlink" width="32" height="32"><path d="M551.216148 731.115158a245.716122 245.716122 0 0 0 55.944296 240.231387H38.941911c-17.551152 0-30.166042-3.839314-34.005356-8.227102s-7.130155-15.357258 0-29.617568c6.033208-49.362614 14.808784-100.919122 25.778254-150.281736a44.974826 44.974826 0 0 1 34.005356-38.393144l83.916444-26.875201 106.403856-32.908409c10.420996-3.839314 14.808784-2.193894 19.196572 4.387788a194.708088 194.708088 0 0 0 157.960365 80.625603 201.838243 201.838243 0 0 0 119.018746-38.941618zM285.206507 76.786288a267.106588 267.106588 0 0 0-103.113015 178.253883v3.839315c0 6.581682 0 14.808784-6.581682 19.196572-17.002678 17.002678-17.002678 36.19925-17.002678 59.78361v25.778254a31.811462 31.811462 0 0 0 1.64542 12.61489 2544.916979 2544.916979 0 0 0 274.236744 15.357258 2542.723085 2542.723085 0 0 0 273.688269-15.357258 22.487413 22.487413 0 0 1 2.193894-10.420996v-10.96947c1.64542-25.22978 3.290841-48.81414-10.969469-69.107659a67.462239 67.462239 0 0 1-12.61489-31.811463 269.848956 269.848956 0 0 0-96.531334-173.317621 25.778254 25.778254 0 0 0-8.227102-7.130156c-0.548473 1.64542-0.548473 3.290841-1.645421 4.387788s-0.548473 3.290841-1.096947 4.936262A914.305303 914.305303 0 0 1 532.56805 251.200857l-19.196572-2.193894v-21.938939a375.704339 375.704339 0 0 1 8.775575-55.395823c6.033208-41.135512 12.61489-83.916443 14.808785-123.955008a28.520621 28.520621 0 0 0-21.390466-32.359935A259.976433 259.976433 0 0 0 387.771049 3.290841C325.245072 14.260311 323.051178 16.454205 330.181333 81.174076a21.390466 21.390466 0 0 0 1.096947 8.227102 41.683985 41.683985 0 0 1 0.548473 8.227103l22.487413 148.087841-19.745045 4.387788c-23.58436-49.362614-36.19925-108.049277-48.81414-167.832887z m147.539368 361.992502c-76.786288 0-153.024103-3.839314-228.713444-10.96947v1.64542l1.645421 9.32405c4.387788 36.19925 10.420996 72.3985 38.393144 97.62828a38.941618 38.941618 0 0 1 8.775575 17.002678 264.912694 264.912694 0 0 0 112.985539 137.118372 125.051955 125.051955 0 0 0 126.697375 6.033208 254.491698 254.491698 0 0 0 123.406535-139.312265v-3.839315a40.587038 40.587038 0 0 1 8.775575-14.808784c31.811462-27.972148 36.19925-68.010712 40.587039-109.146224a268.203535 268.203535 0 0 1-36.199251 2.742368H620.323808c-57.589716 4.936261-121.761114 7.130155-187.577933 7.130155z" p-id="19960" fill="#FF9800"></path><path d="M792.544482 563.282271a230.358864 230.358864 0 1 0 230.358865 230.358865 230.358864 230.358864 0 0 0-230.358865-230.358865z m-15.357257 428.357793h-8.227102l16.454204-159.605784-96.531334-38.393144 121.212641-197.998929v8.227102l-7.678629 150.830209 93.788966 38.941618z" p-id="19961" fill="#FF9800"></path></svg>`,bi=`<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1781414010736" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="48244" width="50" height="50" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M433.32 232.3m-159.61 0a159.61 159.61 0 1 0 319.22 0 159.61 159.61 0 1 0-319.22 0Z" fill="#d81e06" p-id="48245"></path><path d="M501.7 629.08c-1.46-96.26 40.84-149.17 68.44-173.42-41.82-18.74-88.04-29.39-136.83-29.39C248.13 426.27 98 576.39 98 761.58h458.42c-32.8-37.02-53.98-83.92-54.72-132.5zM763.46 654.45c-38.84 0-70.47-31.62-70.47-70.47 0-38.84 31.62-70.47 70.47-70.47s70.47 31.62 70.47 70.47c0 38.84-31.62 70.47-70.47 70.47z m0-115.15c-24.64 0-44.68 20.04-44.68 44.68s20.04 44.68 44.68 44.68 44.68-20.04 44.68-44.68-20.04-44.68-44.68-44.68z" fill="#d81e06" p-id="48246"></path><path d="M679.74 686.44c-33.91-26.15-53.38-65.73-53.38-108.6 0-42.77 19.47-82.28 53.38-108.44l21.02 27.19c-25.45 19.61-40.02 49.22-40.02 81.24 0 32.13 14.57 61.81 40.02 81.41l-21.02 27.2z" fill="#d81e06" p-id="48247"></path><path d="M683.06 752.41c-67.85-31.26-111.66-99.77-111.66-174.57 0-74.7 43.81-143.15 111.66-174.4l14.37 31.22c-55.66 25.65-91.65 81.85-91.65 143.18 0 61.44 35.99 117.7 91.65 143.35l-14.37 31.22zM847.12 686.47l-20.95-27.26c25.41-19.57 40.02-49.25 40.02-81.38 0-32.03-14.6-61.64-40.02-81.21l20.95-27.26c33.97 26.15 53.45 65.7 53.45 108.47 0 42.88-19.47 82.49-53.45 108.64z" fill="#d81e06" p-id="48248"></path><path d="M843.83 752.41l-14.37-31.22c55.66-25.65 91.65-81.91 91.65-143.35 0-61.34-35.99-117.53-91.65-143.18l14.37-31.22c67.85 31.26 111.66 99.71 111.66 174.4 0 74.79-43.81 143.31-111.66 174.57zM763.46 610.43c-14.6 0-26.49-11.85-26.49-26.45s11.88-26.49 26.49-26.49 26.45 11.88 26.45 26.49-11.84 26.45-26.45 26.45z m0-35.75c-5.14 0-9.3 4.16-9.3 9.3 0 5.1 4.16 9.27 9.3 9.27 5.1 0 9.27-4.16 9.27-9.27 0-5.14-4.16-9.3-9.27-9.3zM752.48 643.24h21.95v141.68h-21.95z" fill="#d81e06" p-id="48249"></path></svg>`,xi=`<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1781414908820" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="53275" width="36" height="36" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M968.533333 896c-21.333333-89.6-68.266667-166.4-132.266666-230.4-25.6-25.6-55.466667-51.2-85.333334-68.266667-4.266667-4.266667-8.533333-8.533333-17.066666-8.533333-17.066667-8.533333-34.133333-17.066667-55.466667-25.6 21.333333-21.333333 42.666667-46.933333 55.466667-76.8 12.8-29.866667 21.333333-64 21.333333-98.133333H768c25.6 0 46.933333-8.533333 64-25.6 17.066667-17.066667 25.6-38.4 25.6-64s-8.533333-46.933333-25.6-64c-21.333333-17.066667-42.666667-25.6-64-25.6h-21.333333c-17.066667-51.2-46.933333-89.6-85.333334-119.466667C614.4 55.466667 567.466667 42.666667 512 42.666667c-55.466667 0-102.4 17.066667-145.066667 46.933333-42.666667 29.866667-72.533333 72.533333-85.333333 119.466667h-29.866667c-25.6 0-46.933333 8.533333-64 25.6-17.066667 17.066667-25.6 38.4-25.6 64s8.533333 46.933333 25.6 64c17.066667 17.066667 38.4 25.6 64 25.6h17.066667c0 34.133333 8.533333 64 21.333333 98.133333 12.8 29.866667 29.866667 55.466667 55.466667 76.8-17.066667 8.533333-38.4 17.066667-55.466667 25.6-4.266667 0-12.8 4.266667-12.8 8.533333-34.133333 21.333333-64 42.666667-89.6 72.533334-64 64-106.666667 140.8-128 230.4-4.266667 21.333333 0 42.666667 12.8 59.733333 8.533333 12.8 29.866667 21.333333 51.2 21.333333h776.533334c21.333333 0 42.666667-8.533333 55.466666-25.6s17.066667-38.4 12.8-59.733333zM465.066667 72.533333c17.066667-4.266667 29.866667-4.266667 46.933333-4.266666s29.866667 0 46.933333 4.266666v76.8c0 29.866667-17.066667 46.933333-46.933333 46.933334-29.866667 0-46.933333-17.066667-46.933333-46.933334V72.533333zM315.733333 908.8l-38.4-221.866667 81.066667-51.2 46.933333 264.533334v4.266666H315.733333z m76.8-409.6c-29.866667-29.866667-46.933333-68.266667-46.933333-110.933333h332.8c0 42.666667-17.066667 81.066667-51.2 110.933333-34.133333 34.133333-72.533333 46.933333-119.466667 46.933333s-81.066667-12.8-115.2-46.933333z m320 409.6h-89.6v-4.266667l46.933334-264.533333 81.066666 51.2-38.4 217.6z" p-id="53276" fill="#87c38f"></path></svg>`,Si=`<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1781346936424" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="71834" width="28" height="28" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M810.6496 896l42.7008 85.2992H170.6496l42.7008-85.2992h597.2992zM698.88 42.6496a170.6496 170.6496 0 0 1 169.8304 153.7024l27.2896 272.9472V768a85.3504 85.3504 0 0 1-85.3504 85.2992H213.3504A85.3504 85.3504 0 0 1 128 768V469.2992l27.2896-272.9472A170.6496 170.6496 0 0 1 325.12 42.6496h373.76z m5.12 469.3504a64 64 0 1 0 0 128 64 64 0 0 0 0-128z m-384 0a64 64 0 1 0 0 128 64 64 0 0 0 0-128z m392.5504-298.7008H311.4496L298.6496 384h426.7008l-12.8-170.7008z" p-id="71835" fill="#1296db"></path></svg>`,Ci=`<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1781410414799" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="75688" width="40" height="40" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M955.076923 556.882708h31.413169v1.102769a31.507692 31.507692 0 0 1 12.067446 60.652308 31.507692 31.507692 0 0 1-12.067446 2.394584h-50.365046l-75.712984 57.296739c0 11.689354-14.036677 21.047138-31.523447 21.047138h-5.781661a94.570338 94.570338 0 1 1-177.435569 0H382.188308a94.570338 94.570338 0 1 1-177.43557 0h-5.781661c-17.360738 0-31.507692-9.468062-31.507692-21.047138l-75.618462-57.659077H41.3696a31.507692 31.507692 0 1 1 0-63.046893h63.645538a29.128862 29.128862 0 0 1-0.031507-0.598646h850.093292v-0.157538z m-48.380061-31.365908l-111.300924-153.017108a31.397415 31.397415 0 0 0-29.428184-19.692307h-125.952a31.507692 31.507692 0 0 0-20.6848 7.750892L581.632 393.531077l-105.393231-139.264a31.507692 31.507692 0 0 0-33.870769-11.074954l-252.030031 73.885539a31.523446 31.523446 0 0 0-22.291692 24.623261L113.0496 525.5168h793.647262zM319.645538 747.267938a31.507692 31.507692 0 0 0 5.277539-17.486769h-0.362339a31.507692 31.507692 0 0 0-31.507692-31.507692 31.523446 31.523446 0 1 0 26.592492 48.994461z m441.01317 0.047262a31.523446 31.523446 0 1 0-52.4288-35.036554 31.523446 31.523446 0 0 0 52.4288 35.036554z" fill="#e0620d" p-id="75689"></path></svg>`,wi=`<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1781411158072" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="77161" xmlns:xlink="http://www.w3.org/1999/xlink" width="40" height="40"><path d="M492.32 658.752c131.2 2.176 264.128 0 395.264 0 34.656 0 56.448-32 64.96-72.96 3.008-13.76 4.704-28.672 4.704-43.648 0-14.944-1.696-29.472-4.288-43.136-8.544-39.712-29.888-70.944-65.376-70.944h-71.328c-0.448-17.92 0-36.352 0-54.72 0.448-25.184 0.864-50.4 0-75.168a19.2 19.2 0 0 0-19.648-18.816h-0.864a4456 4456 0 0 0-129.024 0H610.24c-7.68 0-14.08 4.288-17.024 10.688-25.28 40.576-58.144 97.856-85.92 147.008-6.016 10.24-11.52 20.064-17.088 29.888-12.8-17.536-26.976-37.6-41.472-57.696-21.792-30.752-43.968-61.088-58.912-81.6-17.12-22.656-34.24-32.864-53.44-31.2-17.504 1.28-34.176 12.832-52.096 33.76l-99.136 114.944a19.84 19.84 0 0 0-0.896 23.936c6.016 8.96 10.272 16.672 14.976 24.768 7.296 12.832 14.976 25.664 28.16 44a19.04 19.04 0 0 0 26.528 4.288 30.08 30.08 0 0 0 5.12-5.12c8.992-11.52 15.808-20.064 22.656-28.672 15.36-19.616 31.168-39.264 47.808-59.328 4.736-5.984 3.872-10.24 5.152-9.44 5.12 2.56 14.112 15.392 27.776 36.8l113.664 173.888a19.52 19.52 0 0 0 16.192 8.48zM147.136 484.896c-54.272 47.008-95.68 103.008-79.904 178.592a145.44 145.44 0 0 0 32.032 64.544c14.944 18.784 35.04 33.728 57.728 44.448 60.192 27.296 141.44 23.072 219.2-39.776a19.456 19.456 0 0 0 2.976-26.912 19.136 19.136 0 0 0-11.552-6.848c-41.44-8.96-73.504-20.064-95.744-38.848-21.344-17.984-34.592-44.416-40.576-84.224a15.872 15.872 0 0 0-3.424-8.48l-51.68-79.04a18.784 18.784 0 0 0-29.056-3.456zM448 784a80 80 0 0 1 80-80h352a80 80 0 0 1 0 160h-352a80 80 0 0 1-80-80z" fill="#8992c8" p-id="77162" class="selected"></path></svg>`;function X(e,t,n){return`url(data:image/svg+xml,${encodeURIComponent(e)}) ${t} ${n}, auto`}var Ti=new Image;Ti.src=`data:image/svg+xml,${encodeURIComponent(hi)}`;function Ei(e,t){let n=t/2,r=t/2;e.fillStyle=`rgba(218, 217, 217, 0.99)`,e.fillRect(0,r-1,t,3),e.fillRect(n-1,0,3,t)}var Di={default:{type:`css`,value:`default`},pointer:{type:`css`,value:`pointer`},crosshair:{type:`css`,value:`crosshair`},grab:{type:`css`,value:`grab`},grabbing:{type:`css`,value:`grabbing`},move:{type:`css`,value:`move`},none:{type:`css`,value:`none`},text:{type:`css`,value:`text`},ctc:{type:`canvas`,draw:Ei,size:25,hotspot:{x:12,y:12}},cable:{type:`css`,value:X(mi,20,50)},worker:{type:`css`,value:X(gi,50,50)},chewu:{type:`css`,value:X(_i,50,50)},gongwu:{type:`css`,value:X(vi,50,50)},gongdian:{type:`css`,value:X(yi,50,50)},dianwu:{type:`css`,value:X(bi,50,50)},fanghu:{type:`css`,value:X(xi,50,50)},loco:{type:`css`,value:X(Si,50,50)},flatbed:{type:`css`,value:X(Ci,50,50)},excavator:{type:`css`,value:X(wi,50,50)}},Oi=class{canvas;_current=`default`;constructor(e){this.canvas=e.getCanvas()}use(e,t){if(e===`text`&&t){this.createTextCursor(t),this._current=e;return}let n=Di[e];n&&(n.type===`css`?(this.canvas.style.cursor=n.value,this._current=e):(this.applyCanvasCursor(n.draw,n.size,n.hotspot),this._current=e))}setCursor(e){e.canvasDraw?this.applyCanvasCursor(e.canvasDraw,e.size??32,e.hotspot??{x:16,y:16}):e.imageUrl&&this.applyImageCursor(e.imageUrl,e.hotspot)}reset(){this.use(`default`)}get current(){return this._current}createTextCursor(e){let t=e.length>12?e.slice(0,12)+`…`:e,n=document.createElement(`canvas`),r=n.getContext(`2d`);r.font=`bold 12px sans-serif`;let i=r.measureText(t).width+12;n.width=26+i+1,n.height=24,r.drawImage(Ti,1,1,22,22),r.fillStyle=`rgba(0,0,0,0.78)`,r.beginPath(),r.moveTo(30,3),r.lineTo(26+i-4,3),r.quadraticCurveTo(26+i,3,26+i,7),r.lineTo(26+i,17),r.quadraticCurveTo(26+i,21,26+i-4,21),r.lineTo(30,21),r.quadraticCurveTo(26,21,26,17),r.lineTo(26,7),r.quadraticCurveTo(26,3,30,3),r.fill(),r.font=`bold 12px sans-serif`,r.fillStyle=`#fff`,r.textBaseline=`middle`,r.textAlign=`center`,r.fillText(t,26+i/2,12),this.applyImageCursor(n.toDataURL(`image/png`),{x:0,y:0})}applyImageCursor(e,t){let n=t?.x??0,r=t?.y??0;this.canvas.style.cursor=`url(${e}) ${n} ${r}, auto`}applyCanvasCursor(e,t,n){let r=document.createElement(`canvas`);r.width=t,r.height=t,e(r.getContext(`2d`),t),this.applyImageCursor(r.toDataURL(`image/png`),n)}},ki=[{type:`worker`,iconId:`icon_worker`,color:`#707070`,svgPath:`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='1781413096158'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='38813'%20width='32'%20height='32'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3cpath%20d='M770.56%20343.488c-9.984%2093.888-72.64%20194.176-157.184%20241.536l1.984-2.56c-23.552%2026.304-17.152%2048.576%2019.2%2066.752C858.176%20683.584%201024%20809.664%201024%20960c0%2075.328-727.424%2076.16-956.096%2030.336C25.28%20981.76%200%20971.52%200%20960c0-149.376%20163.776-274.88%20385.28-310.144l-2.368%201.28c42.24-20.032%2051.84-41.984%2028.8-65.92C327.552%20538.048%20265.984%20437.568%20256%20343.488h514.56zM512%200c136%200%20274.176%20106.048%20284.48%20240h3.52a32%2032%200%201%201%200%2064h-576a32%2032%200%201%201%200-64h16.128C249.536%20106.048%20376%200%20512%200z'%20fill='%23707070'%20p-id='38814'%3e%3c/path%3e%3c/svg%3e`},{type:`gongwu`,iconId:`icon_gongwu`,color:`#4CAF50`,svgPath:`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='1781412204514'%20class='icon'%20viewBox='0%200%201049%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='15838'%20width='32.78125'%20height='32'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3cpath%20d='M573.540453%20699.171348c-17.241629-6.05787-33.45808-13.140917-49.488135-18.639599-2.050356-1.025178-59.646716-21.155945-30.289348-111.278404l1.025178-2.982336%202.982336-3.075534c46.598997-48.556155%2086.021748-98.044289%2090.12246-208.390713H206.340358c2.982336%20111.837592%2042.498285%20161.791717%2089.004084%20209.322693l1.957158%202.050356%201.025177%202.982336c26.375032%2065.238596-13.140917%20102.517793-37.279197%20111.278404h-1.025178C134.577903%20725.54638%200%20805.417061%200%20874.19718v30.289348c0%2076.888345%20141.66095%20119.38663%20397.489443%20119.38663a1365.350606%201365.350606%200%200%200%20222.556808-15.191273%20254.710116%20254.710116%200%200%201-77.820324-184.066038A263.750322%20263.750322%200%200%201%20573.540453%20699.171348zM641.295394%20253.125751c-7.083048-1.957158-26.281834-7.083048-26.281834-27.307013%200-77.913523-51.631688-146.600444-129.452013-174.932634-9.319799%2023.299498-23.299498%2087.978906-33.45808%20143.618109l-31.314526-2.982336V9.319799c0-5.032692-2.982336-9.319799-7.083047-9.319799h-36.440416a9.319799%209.319799%200%200%200-7.176245%209.319799v182.015682l-33.364882%203.075534a1316.980847%201316.980847%200%200%200-33.45808-143.618108C225.352748%2078.006721%20174.746238%20146.880038%20174.746238%20225.72554c0%2019.198787-17.241629%2025.256656-25.256656%2027.307013-11.183759%202.982336-25.256656%207.083048-27.959398%2045.48062h548.936182c-3.821118-39.329553-17.055233-42.405087-29.170972-45.387422z'%20p-id='15839'%20fill='%234CAF50'%3e%3c/path%3e%3cpath%20d='M1024.24595%20641.108998l-23.113103%2023.2063a63.374636%2063.374636%200%200%201-89.563272-89.65647l22.740311-23.2063c12.861323-12.768125%204.287108-27.959398-18.639599-24.324676a115.845106%20115.845106%200%200%200-95.155151%20138.678614L626.756507%20860.310679a63.374636%2063.374636%200%201%200%2089.470074%2089.65647l193.851826-194.504213a115.751908%20115.751908%200%200%200%20138.492219-95.527943c3.541524-23.019904-11.556551-31.59412-24.324676-18.639599zM685.937233%20920.050593a21.062747%2021.062747%200%201%201%200-29.823358%2020.969549%2020.969549%200%200%201%200%2029.823358z%20m-21.062747-275.120477l73.067227%2073.253623%2029.916556-29.823358-73.160425-73.253623-16.402847-31.407724-52.190876-37.279198-29.916556%2029.823358%2037.279197%2052.284075zM909.612417%20800.384369a10.438175%2010.438175%200%200%200-14.911679%200l-44.828234%2044.828235a10.531373%2010.531373%200%200%200%200%2014.911679l105.593326%20105.686525a42.24665%2042.24665%200%200%200%2059.739914-59.739914z'%20p-id='15840'%20fill='%234CAF50'%3e%3c/path%3e%3c/svg%3e`},{type:`gongdian`,iconId:`icon_gongdian`,color:`#FF9800`,svgPath:`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='1781412389454'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='19959'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='32'%20height='32'%3e%3cpath%20d='M551.216148%20731.115158a245.716122%20245.716122%200%200%200%2055.944296%20240.231387H38.941911c-17.551152%200-30.166042-3.839314-34.005356-8.227102s-7.130155-15.357258%200-29.617568c6.033208-49.362614%2014.808784-100.919122%2025.778254-150.281736a44.974826%2044.974826%200%200%201%2034.005356-38.393144l83.916444-26.875201%20106.403856-32.908409c10.420996-3.839314%2014.808784-2.193894%2019.196572%204.387788a194.708088%20194.708088%200%200%200%20157.960365%2080.625603%20201.838243%20201.838243%200%200%200%20119.018746-38.941618zM285.206507%2076.786288a267.106588%20267.106588%200%200%200-103.113015%20178.253883v3.839315c0%206.581682%200%2014.808784-6.581682%2019.196572-17.002678%2017.002678-17.002678%2036.19925-17.002678%2059.78361v25.778254a31.811462%2031.811462%200%200%200%201.64542%2012.61489%202544.916979%202544.916979%200%200%200%20274.236744%2015.357258%202542.723085%202542.723085%200%200%200%20273.688269-15.357258%2022.487413%2022.487413%200%200%201%202.193894-10.420996v-10.96947c1.64542-25.22978%203.290841-48.81414-10.969469-69.107659a67.462239%2067.462239%200%200%201-12.61489-31.811463%20269.848956%20269.848956%200%200%200-96.531334-173.317621%2025.778254%2025.778254%200%200%200-8.227102-7.130156c-0.548473%201.64542-0.548473%203.290841-1.645421%204.387788s-0.548473%203.290841-1.096947%204.936262A914.305303%20914.305303%200%200%201%20532.56805%20251.200857l-19.196572-2.193894v-21.938939a375.704339%20375.704339%200%200%201%208.775575-55.395823c6.033208-41.135512%2012.61489-83.916443%2014.808785-123.955008a28.520621%2028.520621%200%200%200-21.390466-32.359935A259.976433%20259.976433%200%200%200%20387.771049%203.290841C325.245072%2014.260311%20323.051178%2016.454205%20330.181333%2081.174076a21.390466%2021.390466%200%200%200%201.096947%208.227102%2041.683985%2041.683985%200%200%201%200.548473%208.227103l22.487413%20148.087841-19.745045%204.387788c-23.58436-49.362614-36.19925-108.049277-48.81414-167.832887z%20m147.539368%20361.992502c-76.786288%200-153.024103-3.839314-228.713444-10.96947v1.64542l1.645421%209.32405c4.387788%2036.19925%2010.420996%2072.3985%2038.393144%2097.62828a38.941618%2038.941618%200%200%201%208.775575%2017.002678%20264.912694%20264.912694%200%200%200%20112.985539%20137.118372%20125.051955%20125.051955%200%200%200%20126.697375%206.033208%20254.491698%20254.491698%200%200%200%20123.406535-139.312265v-3.839315a40.587038%2040.587038%200%200%201%208.775575-14.808784c31.811462-27.972148%2036.19925-68.010712%2040.587039-109.146224a268.203535%20268.203535%200%200%201-36.199251%202.742368H620.323808c-57.589716%204.936261-121.761114%207.130155-187.577933%207.130155z'%20p-id='19960'%20fill='%23FF9800'%3e%3c/path%3e%3cpath%20d='M792.544482%20563.282271a230.358864%20230.358864%200%201%200%20230.358865%20230.358865%20230.358864%20230.358864%200%200%200-230.358865-230.358865z%20m-15.357257%20428.357793h-8.227102l16.454204-159.605784-96.531334-38.393144%20121.212641-197.998929v8.227102l-7.678629%20150.830209%2093.788966%2038.941618z'%20p-id='19961'%20fill='%23FF9800'%3e%3c/path%3e%3c/svg%3e`},{type:`dianwu`,iconId:`icon_dianwu`,color:`#d81e06`,svgPath:`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='1781414010736'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='48244'%20width='50'%20height='50'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3cpath%20d='M433.32%20232.3m-159.61%200a159.61%20159.61%200%201%200%20319.22%200%20159.61%20159.61%200%201%200-319.22%200Z'%20fill='%23d81e06'%20p-id='48245'%3e%3c/path%3e%3cpath%20d='M501.7%20629.08c-1.46-96.26%2040.84-149.17%2068.44-173.42-41.82-18.74-88.04-29.39-136.83-29.39C248.13%20426.27%2098%20576.39%2098%20761.58h458.42c-32.8-37.02-53.98-83.92-54.72-132.5zM763.46%20654.45c-38.84%200-70.47-31.62-70.47-70.47%200-38.84%2031.62-70.47%2070.47-70.47s70.47%2031.62%2070.47%2070.47c0%2038.84-31.62%2070.47-70.47%2070.47z%20m0-115.15c-24.64%200-44.68%2020.04-44.68%2044.68s20.04%2044.68%2044.68%2044.68%2044.68-20.04%2044.68-44.68-20.04-44.68-44.68-44.68z'%20fill='%23d81e06'%20p-id='48246'%3e%3c/path%3e%3cpath%20d='M679.74%20686.44c-33.91-26.15-53.38-65.73-53.38-108.6%200-42.77%2019.47-82.28%2053.38-108.44l21.02%2027.19c-25.45%2019.61-40.02%2049.22-40.02%2081.24%200%2032.13%2014.57%2061.81%2040.02%2081.41l-21.02%2027.2z'%20fill='%23d81e06'%20p-id='48247'%3e%3c/path%3e%3cpath%20d='M683.06%20752.41c-67.85-31.26-111.66-99.77-111.66-174.57%200-74.7%2043.81-143.15%20111.66-174.4l14.37%2031.22c-55.66%2025.65-91.65%2081.85-91.65%20143.18%200%2061.44%2035.99%20117.7%2091.65%20143.35l-14.37%2031.22zM847.12%20686.47l-20.95-27.26c25.41-19.57%2040.02-49.25%2040.02-81.38%200-32.03-14.6-61.64-40.02-81.21l20.95-27.26c33.97%2026.15%2053.45%2065.7%2053.45%20108.47%200%2042.88-19.47%2082.49-53.45%20108.64z'%20fill='%23d81e06'%20p-id='48248'%3e%3c/path%3e%3cpath%20d='M843.83%20752.41l-14.37-31.22c55.66-25.65%2091.65-81.91%2091.65-143.35%200-61.34-35.99-117.53-91.65-143.18l14.37-31.22c67.85%2031.26%20111.66%2099.71%20111.66%20174.4%200%2074.79-43.81%20143.31-111.66%20174.57zM763.46%20610.43c-14.6%200-26.49-11.85-26.49-26.45s11.88-26.49%2026.49-26.49%2026.45%2011.88%2026.45%2026.49-11.84%2026.45-26.45%2026.45z%20m0-35.75c-5.14%200-9.3%204.16-9.3%209.3%200%205.1%204.16%209.27%209.3%209.27%205.1%200%209.27-4.16%209.27-9.27%200-5.14-4.16-9.3-9.27-9.3zM752.48%20643.24h21.95v141.68h-21.95z'%20fill='%23d81e06'%20p-id='48249'%3e%3c/path%3e%3c/svg%3e`},{type:`chewu`,iconId:`icon_chewu`,color:`#1296db`,svgPath:`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='1781413291157'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='47319'%20width='48'%20height='48'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3cpath%20d='M711.210667%20344.917333l-294.101334%2025.770667a387.584%20387.584%200%200%201%203.584-75.818667c95.36%2017.493333%20191.914667%2027.989333%20288.810667%2031.445334V267.562667c-145.621333-8.96-270.421333-106.965333-270.421333-106.965334A190.976%20190.976%200%200%200%20290.602667%20110.933333c-33.578667%201.706667-65.365333%2015.786667-89.301334%2039.424a651.946667%20651.946667%200%200%200-91.392%20120.789334c-31.317333%2051.029333-44.8%20106.368-17.664%20165.162666%208.661333%2018.432%2019.413333%2035.84%2032.042667%2051.797334%202.858667%203.413333%2012.714667%2018.944%2017.28%2018.944-26.88%2017.322667-52.736%2036.053333-77.568%2056.149333h60.672s39.68-29.781333%2079.445333-54.272l81.365334%201.706667c-17.237333%2012.928-53.845333%2040.618667-81.152%2066.005333H264.96s113.792-84.181333%20208.597333-103.338667l-9.685333%201.706667C652.074667%20421.546667%20710.442667%20418.133333%20710.442667%20418.133333l0.768-73.216zM102.826667%20332.8c0-13.653333%2016.896-24.661333%2037.930666-24.661333s37.930667%2011.008%2037.930667%2024.661333c0%2013.653333-16.896%2024.618667-37.930667%2024.618667s-37.930667-10.965333-37.930666-24.618667z%20m144.896-107.52l-75.861334-4.010667s33.92-52.693333%2044.757334-56.106666l46.848%200.938666-15.786667%2059.178667z%20m34.304-56.917333l65.792%202.133333v59.306667L268.8%20226.602667l13.269333-58.24z%20m35.456%20140.16c20.906667%200%2037.973333%2010.965333%2037.973333%2024.618666%200%2013.653333-16.896%2024.661333-37.973333%2024.661334-21.034667%200-37.930667-11.008-37.930667-24.661334%200-13.653333%2016.896-24.618667%2037.973333-24.618666z'%20fill='%231296db'%20p-id='47320'%3e%3c/path%3e%3cpath%20d='M653.098667%20257.450667a190.634667%20190.634667%200%200%200-190.421334%20190.378666%20190.634667%20190.634667%200%200%200%20190.421334%20190.378667%20190.677333%20190.677333%200%200%200%20190.421333-190.378667%20190.634667%20190.634667%200%200%200-190.421333-190.378666z'%20fill='%231296db'%20p-id='47321'%3e%3c/path%3e%3cpath%20d='M799.829333%20633.856c-40.533333%2032.085333-91.093333%2051.968-146.773333%2051.968-55.637333%200-106.112-19.925333-146.773333-51.968-76.970667%2049.066667-130.56%20135.082667-137.941334%20234.794667%2026.965333%203.626667%2074.922667%207.594667%20143.36%207.594666h282.666667c68.48%200%20116.48-3.968%20143.445333-7.594666-7.296-99.754667-60.885333-185.770667-137.984-234.794667z'%20fill='%231296db'%20p-id='47322'%3e%3c/path%3e%3c/svg%3e`},{type:`fanghu`,iconId:`icon_fanghu`,color:`#87c38f`,svgPath:`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='1781414908820'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='53275'%20width='36'%20height='36'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3cpath%20d='M968.533333%20896c-21.333333-89.6-68.266667-166.4-132.266666-230.4-25.6-25.6-55.466667-51.2-85.333334-68.266667-4.266667-4.266667-8.533333-8.533333-17.066666-8.533333-17.066667-8.533333-34.133333-17.066667-55.466667-25.6%2021.333333-21.333333%2042.666667-46.933333%2055.466667-76.8%2012.8-29.866667%2021.333333-64%2021.333333-98.133333H768c25.6%200%2046.933333-8.533333%2064-25.6%2017.066667-17.066667%2025.6-38.4%2025.6-64s-8.533333-46.933333-25.6-64c-21.333333-17.066667-42.666667-25.6-64-25.6h-21.333333c-17.066667-51.2-46.933333-89.6-85.333334-119.466667C614.4%2055.466667%20567.466667%2042.666667%20512%2042.666667c-55.466667%200-102.4%2017.066667-145.066667%2046.933333-42.666667%2029.866667-72.533333%2072.533333-85.333333%20119.466667h-29.866667c-25.6%200-46.933333%208.533333-64%2025.6-17.066667%2017.066667-25.6%2038.4-25.6%2064s8.533333%2046.933333%2025.6%2064c17.066667%2017.066667%2038.4%2025.6%2064%2025.6h17.066667c0%2034.133333%208.533333%2064%2021.333333%2098.133333%2012.8%2029.866667%2029.866667%2055.466667%2055.466667%2076.8-17.066667%208.533333-38.4%2017.066667-55.466667%2025.6-4.266667%200-12.8%204.266667-12.8%208.533333-34.133333%2021.333333-64%2042.666667-89.6%2072.533334-64%2064-106.666667%20140.8-128%20230.4-4.266667%2021.333333%200%2042.666667%2012.8%2059.733333%208.533333%2012.8%2029.866667%2021.333333%2051.2%2021.333333h776.533334c21.333333%200%2042.666667-8.533333%2055.466666-25.6s17.066667-38.4%2012.8-59.733333zM465.066667%2072.533333c17.066667-4.266667%2029.866667-4.266667%2046.933333-4.266666s29.866667%200%2046.933333%204.266666v76.8c0%2029.866667-17.066667%2046.933333-46.933333%2046.933334-29.866667%200-46.933333-17.066667-46.933333-46.933334V72.533333zM315.733333%20908.8l-38.4-221.866667%2081.066667-51.2%2046.933333%20264.533334v4.266666H315.733333z%20m76.8-409.6c-29.866667-29.866667-46.933333-68.266667-46.933333-110.933333h332.8c0%2042.666667-17.066667%2081.066667-51.2%20110.933333-34.133333%2034.133333-72.533333%2046.933333-119.466667%2046.933333s-81.066667-12.8-115.2-46.933333z%20m320%20409.6h-89.6v-4.266667l46.933334-264.533333%2081.066666%2051.2-38.4%20217.6z'%20p-id='53276'%20fill='%2387c38f'%3e%3c/path%3e%3c/svg%3e`},{type:`loco`,iconId:`icon_loco`,color:`#1E90FF`,svgPath:`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='1781346936424'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='71834'%20width='28'%20height='28'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3cpath%20d='M810.6496%20896l42.7008%2085.2992H170.6496l42.7008-85.2992h597.2992zM698.88%2042.6496a170.6496%20170.6496%200%200%201%20169.8304%20153.7024l27.2896%20272.9472V768a85.3504%2085.3504%200%200%201-85.3504%2085.2992H213.3504A85.3504%2085.3504%200%200%201%20128%20768V469.2992l27.2896-272.9472A170.6496%20170.6496%200%200%201%20325.12%2042.6496h373.76z%20m5.12%20469.3504a64%2064%200%201%200%200%20128%2064%2064%200%200%200%200-128z%20m-384%200a64%2064%200%201%200%200%20128%2064%2064%200%200%200%200-128z%20m392.5504-298.7008H311.4496L298.6496%20384h426.7008l-12.8-170.7008z'%20p-id='71835'%20fill='%231296db'%3e%3c/path%3e%3c/svg%3e`},{type:`flatbed`,iconId:`icon_flatbed`,color:`#FFA500`,svgPath:`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='1781410414799'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='75688'%20width='40'%20height='40'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3cpath%20d='M955.076923%20556.882708h31.413169v1.102769a31.507692%2031.507692%200%200%201%2012.067446%2060.652308%2031.507692%2031.507692%200%200%201-12.067446%202.394584h-50.365046l-75.712984%2057.296739c0%2011.689354-14.036677%2021.047138-31.523447%2021.047138h-5.781661a94.570338%2094.570338%200%201%201-177.435569%200H382.188308a94.570338%2094.570338%200%201%201-177.43557%200h-5.781661c-17.360738%200-31.507692-9.468062-31.507692-21.047138l-75.618462-57.659077H41.3696a31.507692%2031.507692%200%201%201%200-63.046893h63.645538a29.128862%2029.128862%200%200%201-0.031507-0.598646h850.093292v-0.157538z%20m-48.380061-31.365908l-111.300924-153.017108a31.397415%2031.397415%200%200%200-29.428184-19.692307h-125.952a31.507692%2031.507692%200%200%200-20.6848%207.750892L581.632%20393.531077l-105.393231-139.264a31.507692%2031.507692%200%200%200-33.870769-11.074954l-252.030031%2073.885539a31.523446%2031.523446%200%200%200-22.291692%2024.623261L113.0496%20525.5168h793.647262zM319.645538%20747.267938a31.507692%2031.507692%200%200%200%205.277539-17.486769h-0.362339a31.507692%2031.507692%200%200%200-31.507692-31.507692%2031.523446%2031.523446%200%201%200%2026.592492%2048.994461z%20m441.01317%200.047262a31.523446%2031.523446%200%201%200-52.4288-35.036554%2031.523446%2031.523446%200%200%200%2052.4288%2035.036554z'%20fill='%23e0620d'%20p-id='75689'%3e%3c/path%3e%3c/svg%3e`},{type:`excavator`,iconId:`icon_excavator`,color:`#8992c8`,svgPath:`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='1781411158072'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='77161'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='40'%20height='40'%3e%3cpath%20d='M492.32%20658.752c131.2%202.176%20264.128%200%20395.264%200%2034.656%200%2056.448-32%2064.96-72.96%203.008-13.76%204.704-28.672%204.704-43.648%200-14.944-1.696-29.472-4.288-43.136-8.544-39.712-29.888-70.944-65.376-70.944h-71.328c-0.448-17.92%200-36.352%200-54.72%200.448-25.184%200.864-50.4%200-75.168a19.2%2019.2%200%200%200-19.648-18.816h-0.864a4456%204456%200%200%200-129.024%200H610.24c-7.68%200-14.08%204.288-17.024%2010.688-25.28%2040.576-58.144%2097.856-85.92%20147.008-6.016%2010.24-11.52%2020.064-17.088%2029.888-12.8-17.536-26.976-37.6-41.472-57.696-21.792-30.752-43.968-61.088-58.912-81.6-17.12-22.656-34.24-32.864-53.44-31.2-17.504%201.28-34.176%2012.832-52.096%2033.76l-99.136%20114.944a19.84%2019.84%200%200%200-0.896%2023.936c6.016%208.96%2010.272%2016.672%2014.976%2024.768%207.296%2012.832%2014.976%2025.664%2028.16%2044a19.04%2019.04%200%200%200%2026.528%204.288%2030.08%2030.08%200%200%200%205.12-5.12c8.992-11.52%2015.808-20.064%2022.656-28.672%2015.36-19.616%2031.168-39.264%2047.808-59.328%204.736-5.984%203.872-10.24%205.152-9.44%205.12%202.56%2014.112%2015.392%2027.776%2036.8l113.664%20173.888a19.52%2019.52%200%200%200%2016.192%208.48zM147.136%20484.896c-54.272%2047.008-95.68%20103.008-79.904%20178.592a145.44%20145.44%200%200%200%2032.032%2064.544c14.944%2018.784%2035.04%2033.728%2057.728%2044.448%2060.192%2027.296%20141.44%2023.072%20219.2-39.776a19.456%2019.456%200%200%200%202.976-26.912%2019.136%2019.136%200%200%200-11.552-6.848c-41.44-8.96-73.504-20.064-95.744-38.848-21.344-17.984-34.592-44.416-40.576-84.224a15.872%2015.872%200%200%200-3.424-8.48l-51.68-79.04a18.784%2018.784%200%200%200-29.056-3.456zM448%20784a80%2080%200%200%201%2080-80h352a80%2080%200%200%201%200%20160h-352a80%2080%200%200%201-80-80z'%20fill='%238992c8'%20p-id='77162'%20class='selected'%3e%3c/path%3e%3c/svg%3e`}];function Ai(e){let t=`geojson_${e}`;this.addGeoJsonSource(t);for(let n of ki){let r=`${e}_${n.type}_line`,i=`${e}_${n.type}_point`,a=[`all`,[`==`,[`get`,`type`],n.type],[`==`,[`geometry-type`],`LineString`]],o=[`all`,[`==`,[`get`,`type`],n.type],[`==`,[`geometry-type`],`Point`]];this.map.getLayer(r)||this.map.addLayer({id:r,type:`line`,source:t,filter:a,paint:{"line-color":n.color,"line-width":2}});let s=()=>{this.map.getLayer(i)||this.map.addLayer({id:i,type:`symbol`,source:t,filter:o,layout:{"icon-image":n.iconId,"icon-size":.8,"icon-allow-overlap":!0,"icon-anchor":`bottom`,"text-field":[`get`,`content`],"text-size":12,"text-offset":[0,1],"text-allow-overlap":!0},paint:{"text-color":`#000000`,"text-halo-color":n.color,"text-halo-width":2}})};if(this.map.hasImage(n.iconId))s();else{let e=new Image;e.onload=()=>{this.map.hasImage(n.iconId)||(this.map.addImage(n.iconId,e),s())},e.src=n.svgPath}}}var Z=6371008.8;Z*100,Z*100,360/(2*Math.PI),Z*3.28084,Z*39.37,Z/1e3,Z/1e3,Z/1609.344,Z*1e3,Z*1e3,Z/1852,Z*1.0936;function ji(e,t,n={}){let r={type:`Feature`};return(n.id===0||n.id)&&(r.id=n.id),n.bbox&&(r.bbox=n.bbox),r.properties=t||{},r.geometry=e,r}function Mi(e,t,n={}){if(!e)throw Error(`coordinates is required`);if(!Array.isArray(e))throw Error(`coordinates must be an Array`);if(e.length<2)throw Error(`coordinates must be at least 2 numbers long`);if(!Pi(e[0])||!Pi(e[1]))throw Error(`coordinates must contain numbers`);return ji({type:`Point`,coordinates:e},t,n)}function Ni(e,t,n={}){if(e.length<2)throw Error(`coordinates must be an array of two or more positions`);return ji({type:`LineString`,coordinates:e},t,n)}function Pi(e){return!isNaN(e)&&e!==null&&!Array.isArray(e)}var Fi=15,Ii=.2;function Li(e,t,n,i=Fi,a=Ii){let o=t.project(e),s=[[o.x-i*2,o.y-i*2],[o.x+i*2,o.y+i*2]],c=t.queryRenderedFeatures(s,{layers:n});if(c.length===0)return null;let l=Mi([e.lng,e.lat]),u=null,d=1/0;for(let e of c){let n=e.geometry;if(n.type===`Point`){let r=t.project(n.coordinates),i=Math.hypot(r.x-o.x,r.y-o.y)*a;i<d&&(d=i,u={lngLat:{lng:n.coordinates[0],lat:n.coordinates[1]},feature:e});continue}if(n.type!==`LineString`&&n.type!==`MultiLineString`)continue;let i=n.type===`LineString`?[n.coordinates]:n.coordinates;for(let n of i){if(n.length<2)continue;for(let r of n){let n=t.project([r[0],r[1]]),i=Math.hypot(n.x-o.x,n.y-o.y)*a;i<d&&(d=i,u={lngLat:{lng:r[0],lat:r[1]},feature:e})}let i=(0,r.nearestPointOnLine)(Ni(n),l),s=t.project([i.geometry.coordinates[0],i.geometry.coordinates[1]]),c=Math.hypot(s.x-o.x,s.y-o.y);c<d&&(d=c,u={lngLat:{lng:i.geometry.coordinates[0],lat:i.geometry.coordinates[1]},feature:e})}}return u&&d<=i?u:null}var Ri=class{map;snapMarker=null;layerIds=[];onClick=null;active=!1;thresholdPx=Fi;vertexBias=Ii;boundMouseMove;boundClick;constructor(e){this.map=e.map,this.boundMouseMove=this.onMouseMove.bind(this),this.boundClick=this.onClick_.bind(this)}start(e,t){this.active&&this.close(),this.layerIds=Array.isArray(e)?e:[e],this.onClick=t,this.active=!0,this.map.on(`mousemove`,this.boundMouseMove),this.map.on(`click`,this.boundClick)}close(){this.active=!1,this.snapMarker?.remove(),this.snapMarker=null,this.onClick=null,this.layerIds=[],this.map.off(`mousemove`,this.boundMouseMove),this.map.off(`click`,this.boundClick)}destroy(){this.close()}getMarkerEl(e=`crosshair`){let t=document.createElement(`div`);return t.style.pointerEvents=`none`,e===`dot`?t.innerHTML=`<svg width="12" height="12" viewBox="0 0 12 12" style="display:block"><circle cx="6" cy="6" r="5" fill="#ff4d4f" stroke="#fff" stroke-width="1.5"/></svg>`:t.innerHTML=`<svg width="20" height="20" viewBox="0 0 20 20" style="display:block"><circle cx="10" cy="10" r="7" fill="none" stroke="#ff4d4f" stroke-width="2"/><line x1="10" y1="0" x2="10" y2="5" stroke="#ff4d4f" stroke-width="1.5"/><line x1="10" y1="15" x2="10" y2="20" stroke="#ff4d4f" stroke-width="1.5"/><line x1="0" y1="10" x2="5" y2="10" stroke="#ff4d4f" stroke-width="1.5"/><line x1="15" y1="10" x2="20" y2="10" stroke="#ff4d4f" stroke-width="1.5"/></svg>`,t}onMouseMove(e){if(!this.active||this.layerIds.length===0)return;let n=Li(e.lngLat,this.map,this.layerIds,this.thresholdPx,this.vertexBias);n?(this.snapMarker||=new t.default.Marker({element:this.getMarkerEl(`crosshair`),anchor:`center`}),this.snapMarker.setLngLat(n.lngLat).addTo(this.map)):this.snapMarker?.remove()}onClick_(e){if(!this.active||!this.onClick)return;let t=this.layerIds.length>0?Li(e.lngLat,this.map,this.layerIds,this.thresholdPx,this.vertexBias):null;this.onClick(t?t.lngLat:e.lngLat,t?.feature)}},zi=`draw-route-preview-source`,Bi=`draw-route-preview-layer`,Vi=class{map;active=!1;vertices=[];tempMarkers=[];onFinish=null;onStop=null;boundMouseMove;boundDblClick;boundContextMenu;constructor(e){this.map=e.map,this.boundMouseMove=this.onMouseMove.bind(this),this.boundDblClick=this.onDblClick.bind(this),this.boundContextMenu=this.onContextMenu.bind(this)}start(e,t){this.active&&this.stop(!1),this.active=!0,this.onFinish=e,this.onStop=t??null,this.vertices=[],this.ensurePreviewLayer(),this.map.on(`mousemove`,this.boundMouseMove),this.map.on(`dblclick`,this.boundDblClick),this.map.on(`contextmenu`,this.boundContextMenu)}stop(e=!0){if(this.active){if(e&&this.vertices.length>=2&&this.onFinish){let e=this.vertices.map(e=>[e.lng,e.lat]);this.onFinish({type:`Feature`,geometry:{type:`LineString`,coordinates:e},properties:{}})}this.active=!1,this.onFinish=null,this.onStop?.(),this.onStop=null,this.clearTempMarkers(),this.clearPreview(),this.removePreviewLayer(),this.map.off(`mousemove`,this.boundMouseMove),this.map.off(`dblclick`,this.boundDblClick),this.map.off(`contextmenu`,this.boundContextMenu)}}destroy(){this.stop(!1)}ensurePreviewLayer(){this.map.getSource(zi)||this.map.addSource(zi,{type:`geojson`,data:{type:`FeatureCollection`,features:[]}}),this.map.getLayer(Bi)||this.map.addLayer({id:Bi,type:`line`,source:zi,paint:{"line-color":`#ff4d4f`,"line-width":2,"line-dasharray":[4,2]}})}updatePreview(){let e=this.map.getSource(zi);if(!e)return;let t=this.vertices.map(e=>[e.lng,e.lat]);e.setData({type:`FeatureCollection`,features:t.length<2?[]:[{type:`Feature`,geometry:{type:`LineString`,coordinates:t},properties:{}}]})}clearPreview(){let e=this.map.getSource(zi);e&&e.setData({type:`FeatureCollection`,features:[]})}removePreviewLayer(){this.map.getLayer(Bi)&&this.map.removeLayer(Bi),this.map.getSource(zi)&&this.map.removeSource(zi)}addTempMarker(e){let n=new t.default.Marker({color:`#ff4d4f`,scale:.7}).setLngLat(e).addTo(this.map);this.tempMarkers.push(n)}clearTempMarkers(){this.tempMarkers.forEach(e=>e.remove()),this.tempMarkers=[]}onMouseMove(e){if(!this.active)return;let t=this.vertices.map(e=>[e.lng,e.lat]);t.push([e.lngLat.lng,e.lngLat.lat]);let n=this.map.getSource(zi);n&&n.setData({type:`FeatureCollection`,features:t.length<2?[]:[{type:`Feature`,geometry:{type:`LineString`,coordinates:t},properties:{}}]})}addVertex(e){this.active&&(this.vertices.push(e),this.addTempMarker(e),this.updatePreview())}onDblClick(){if(!this.active||this.vertices.length<2)return;let e=this.vertices.map(e=>[e.lng,e.lat]);this.onFinish?.({type:`Feature`,geometry:{type:`LineString`,coordinates:e},properties:{}}),this.clearTempMarkers(),this.clearPreview(),this.vertices=[]}onContextMenu(e){e.preventDefault();let t=this.vertices.map(e=>[e.lng,e.lat]);this.onFinish?.({type:`Feature`,geometry:{type:`LineString`,coordinates:t},properties:{}}),this.clearTempMarkers(),this.clearPreview(),this.vertices=[]}},Hi={signal:`信号机`,switch:`道岔`,track:`股道`,track_circuit:`股道电路`,sgfhqy_door:`通道门`},Ui=class{teeeMap;el=null;active=!1;queryLayers=[];currentFeature=null;onSelect;boundContextMenu;boundMapMove;constructor(e){this.teeeMap=e,this.boundContextMenu=this.onContextMenu.bind(this),this.boundMapMove=this.onMapMove.bind(this)}start(e,t){this.active&&this.stop(),this.active=!0,this.queryLayers=e,this.onSelect=t,this.teeeMap.map.on(`contextmenu`,this.boundContextMenu),this.teeeMap.map.on(`move`,this.boundMapMove)}stop(){this.active&&(this.active=!1,this.teeeMap.map.off(`contextmenu`,this.boundContextMenu),this.teeeMap.map.off(`move`,this.boundMapMove),this.remove())}destroy(){this.stop()}onContextMenu(e){e.preventDefault(),this.remove();let t=this.teeeMap.map.queryRenderedFeatures(e.point,{layers:this.queryLayers});if(!t.length){this.showLightMenu(e);return}let n=t[0];n.id!==void 0&&(this.currentFeature=n,this.teeeMap.ctcTool?.changeFeatureState(n.properties.code,{select:!0}),this.showFeatureMenu(e,n))}onMapMove(){this.el&&this.remove()}getViewportPos(e){let t=this.teeeMap.map.getContainer().getBoundingClientRect();return{x:t.left+e.point.x,y:t.top+e.point.y}}createContainer(e,t){let n=this.getViewportPos(e),r=document.createElement(`div`);r.className=`ctc-menu`,r.style.cssText=`position:fixed;z-index:9999;left:${n.x}px;top:${n.y}px;border-radius:2px;background:#fff;color:#000;font-size:13px;min-width:150px;`;let i=document.createElement(`div`);return i.style.cssText=`padding:8px;font-size:14px;font-weight:600;display:flex;justify-content:space-between;align-items:center;`,i.innerHTML=`${t}<span class="ctc-menu-close" style="cursor:pointer;font-size:18px;color:#999;line-height:1;">×</span>`,i.querySelector(`.ctc-menu-close`).addEventListener(`click`,()=>this.remove()),r.appendChild(i),r}addSplit(e){let t=document.createElement(`div`);t.style.cssText=`height:2px;background-color:#e4e4e4;`,e.appendChild(t)}addItem(e,t,n,r,i=!1){let a=document.createElement(`div`);a.style.cssText=`padding:2px 12px;text-align:left;cursor:pointer;white-space:nowrap;`,i&&(a.style.cssText+=`opacity:0.5;cursor:not-allowed;pointer-events:none;`),n?(a.style.cssText+=`font-weight:600;`,a.innerHTML=`✔ ${t}`):a.textContent=t,a.addEventListener(`mouseenter`,()=>{a.style.background=`#f2f2f2`}),a.addEventListener(`mouseleave`,()=>{a.style.background=``}),i||a.addEventListener(`click`,r),e.appendChild(a)}adjustPosition(e,t){let n=this.getViewportPos(t),r=e.getBoundingClientRect();r.right>window.innerWidth&&(e.style.left=`${n.x-r.width}px`),r.bottom>window.innerHeight&&(e.style.top=`${Math.max(0,n.y-r.height)}px`)}showFeatureMenu(e,t){let n=t.properties.code,r=De(n),i=t.properties.name||Hi[r]||``,a=this.createContainer(e,`${Hi[r]}: ${i}`);console.log(r,i);let o=t.state||{};switch(r){case`signal`:this.buildSignalMenu(a,t,o);break;case`switch`:this.buildSwitchMenu(a,t,o);break;case`track`:this.buildTrackMenu(a,t,o);break;case`track_circuit`:this.buildCircuitMenu(a,t,o);break;case`sgfhqy_door`:this.buildSgfhqyDoorMenu(a,t,o);break}document.body.appendChild(a),this.adjustPosition(a,e),this.el=a}emit(e,t){if(!this.currentFeature)return;let n={feature:this.currentFeature,featureType:De(this.currentFeature.properties.code),code:this.currentFeature.properties.code};t?(n.meta={pathType:t},n.featureType=`path`):n.state=e,this.remove(),this.onSelect?.(n)}getSignalMode(e){let t=e.properties.func_type,n=e.properties.attach||0;return t==1&&n==0?`TrainAndShunting`:(t==2||t==3)&&n==0?`Train`:(t==2||t==3||t==11)&&n==1?`TrainAndShunting`:(t==4||t==5||t==12)&&n==0?`Shunting`:t==6&&n==0?`Train`:(t==7||t==11)&&n==0?`TrainAndShunting`:``}getSignalDefaultSubState1(e){let t=e.properties.func_type,n=e.properties.attach;return t==1&&n==0||(t==2||t==3)&&n==0||(t==2||t==3||t==11)&&n==1?`blue`:(t==4||t==5||t==12)&&n==0?`green`:t==6&&n==0||(t==7||t==11)&&n==0?`blue`:`grey`}buildSignalMenu(e,t,n){let r=this.getSignalMode(t),i=r===`Train`||r===`TrainAndShunting`,a=r===`Shunting`||r===`TrainAndShunting`;this.addSplit(e),i&&(this.addItem(e,`列车红灯`,n.state===`red`,()=>this.emit({state:`red`}),!1),this.addItem(e,`列车绿灯`,n.state===`green`,()=>this.emit({state:`green`}),!1)),a&&(this.addItem(e,`调车白灯`,n.state===`white`,()=>this.emit({state:`white`})),this.addItem(e,`调车蓝灯`,n.state===`blue`,()=>this.emit({state:`blue`}),!1)),this.addSplit(e),a&&(this.addItem(e,`进路始端(调车)`,!1,()=>this.emit({},`srcSignal`)),this.addItem(e,`进路终端(调车)`,!1,()=>this.emit({},`destSignal`))),i&&(this.addItem(e,`进路始端(列车)`,!1,()=>this.emit({},`srcSignal`)),this.addItem(e,`进路终端(列车)`,!1,()=>this.emit({},`destSignal`))),this.addSplit(e);let o=n.subState1===`red`;this.addItem(e,`钮封`,o,()=>this.emit({subState1:`red`}));let s=this.getSignalDefaultSubState1(t);this.addItem(e,`解封`,!o,()=>this.emit({subState1:s})),this.addSplit(e);let c=n.subState2===`on`;this.addItem(e,`点灯`,c,()=>this.emit({subState2:`on`})),this.addItem(e,`灭灯`,n.subState2===`off`,()=>this.emit({subState2:`off`}))}buildSwitchMenu(e,t,n){this.addSplit(e),this.addItem(e,`定位`,n.state===`2`,()=>this.emit({state:`2`}),!1),this.addItem(e,`反位`,n.state===`3`,()=>this.emit({state:`3`}),!1),this.addItem(e,`四开`,n.state===`4`,()=>this.emit({state:`4`}),!1),this.addSplit(e);let r=n.subState1===`2`,i=n.subState1===`3`;this.addItem(e,`锁闭`,r,()=>this.emit({subState1:`2`})),this.addItem(e,`占用`,i,()=>this.emit({subState1:`3`})),this.addItem(e,`出清`,!n.subState1,()=>this.emit({subState1:``})),this.addSplit(e);let a=n.subState2===`1`;this.addItem(e,`单锁`,a,()=>this.emit({subState2:`1`})),this.addItem(e,`解锁`,!n.subState2,()=>this.emit({subState2:``})),this.addSplit(e);let o=n.subState3===`1`;this.addItem(e,`单封`,o,()=>this.emit({subState3:`1`})),this.addItem(e,`解封`,!n.subState3,()=>this.emit({subState3:``}))}buildTrackMenu(e,t,n){this.addSplit(e),this.addItem(e,`封锁`,n.state===`1`,()=>this.emit({state:`1`})),this.addItem(e,`停电`,n.state===`2`,()=>this.emit({state:`2`})),this.addItem(e,`无接触网`,n.state===`3`,()=>this.emit({state:`3`})),this.addItem(e,`临时限速`,!1,()=>{})}buildCircuitMenu(e,t,n){this.addSplit(e);let r=!n.subState1,i=n.subState1===`1`;this.addItem(e,`供电`,r,()=>this.emit({subState1:``})),this.addItem(e,`停电`,i,()=>this.emit({subState1:`1`}))}buildSgfhqyDoorMenu(e,t,n){this.addSplit(e),this.addItem(e,`施工开门`,n.state===`1`,()=>this.emit({state:`1`})),this.addItem(e,`施工关门`,n.state===`2`,()=>this.emit({state:`2`})),this.addItem(e,`施工临时开门`,n.state===`3`,()=>this.emit({state:`3`})),this.addItem(e,`施工临时关门`,n.state===`4`,()=>this.emit({state:`4`})),this.addSplit(e),this.addItem(e,`调度命令确认`,n.subState1===`1`,()=>this.emit({subState1:`1`})),this.addItem(e,`调度命令取消`,n.subState1===``,()=>this.emit({subState1:``})),this.addSplit(e),this.addItem(e,`进入申请确认`,n.subState2===`1`,()=>this.emit({subState2:`1`})),this.addItem(e,`进入申请取消`,n.subState2===``,()=>this.emit({subState2:``})),this.addSplit(e),this.addItem(e,`人员工机通道门号确认`,n.subState3===`1`,()=>this.emit({subState3:`1`})),this.addItem(e,`人员工机通道门号取消`,n.subState3===``,()=>this.emit({subState3:``}))}showLightMenu(e){let t=this.createContainer(e,`点灯操作`);this.addSplit(t),this.addItem(t,`全亮`,!1,()=>{this.remove(),this.onSelect?.({featureType:`lightOn`,state:{subState2:`on`}})}),this.addItem(t,`全灭`,!1,()=>{this.remove(),this.onSelect?.({featureType:`lightOff`,state:{subState2:`off`}})}),document.body.appendChild(t),this.adjustPosition(t,e),this.el=t}remove(){this.el&&=(this.el.remove(),null),this.currentFeature&&=(this.teeeMap.ctcTool?.changeFeatureState(this.currentFeature.properties.code,{select:!1}),null)}},Wi=class{map;layerIds=[];callbacks={};hovered=null;popup=null;popupRenderer;_active=!1;_boundMouseMove;_boundMove;constructor(e){this.map=e.map,this._boundMouseMove=this._onMouseMove.bind(this),this._boundMove=this._onMove.bind(this)}start(e,t){this._active&&this.stop(),this._active=!0,this.layerIds=e,this.callbacks=t??{},this.map.on(`mousemove`,this._boundMouseMove),this.map.on(`move`,this._boundMove)}stop(){this._active&&(this._active=!1,this.map.off(`mousemove`,this._boundMouseMove),this.map.off(`move`,this._boundMove),this.hovered=null,this.popup?.remove(),this.popup=null,this.callbacks.onStop?.(),this.callbacks={},this.layerIds=[])}setPopupRenderer(e){this.popupRenderer=e}destroy(){this.stop(),this.popupRenderer=void 0}_onMouseMove(e){if(!this.layerIds.length)return;let n=this.map.queryRenderedFeatures(e.point,{layers:this.layerIds});if(n.length>0){let r=n[0];if(this.hovered&&this.hovered.properties.code===r.properties.code){this.popup?.setLngLat(e.lngLat);return}this._clearHover(),this.hovered=r,this.callbacks.onEnter?.(this.hovered),this.popup||=new t.default.Popup({closeButton:!1,closeOnClick:!1,anchor:`top-left`,offset:[15,0]}),this.popup.setLngLat(e.lngLat).setHTML(this._renderPopup(n)).addTo(this.map)}else this._clearHover()}_onMove(){this._active&&(this._clearHover(),this.popup?.remove())}_clearHover(){if(!this.hovered)return;let e=this.hovered;this.hovered=null,this.popup?.remove(),this.callbacks.onLeave?.(e)}_renderPopup(e){return this.popupRenderer?this.popupRenderer(e):[...new Set(e.map(e=>e.properties.name))].join(`<br>`)}},Gi=class{map;sourceId;constructor(e,t){this.map=e,this.sourceId=t}getLayers(){return(this.map.getStyle().layers||[]).filter(e=>e.id.startsWith(this.sourceId)).map(e=>({id:e.id,visible:this.getVisibility(e.id)}))}getVisibility(e){return this.map.getLayoutProperty(e,`visibility`)!==`none`}setVisibility(e,t){this.map.getLayer(e)&&this.map.setLayoutProperty(e,`visibility`,t?`visible`:`none`)}toggleVisibility(e){let t=!this.getVisibility(e);return this.setVisibility(e,t),t}},Q={base:Be,ctc:Oe,graph:Xe,geojson:et,draw:pi,cursor:Oi,injectTeeeGeoJson:Ai,snaps:Ri,drawRoute:Vi,ctcMenu:Ui,ctcHover:Wi},$={ctc:(e,t,n)=>({id:`ctc`,sourceUrl:t,layers:n,sourceLayers:n.map(t=>t===`switch_loc`?`${e}_t_${t}`:t===`sgfhqy`?`${e}_a_${t}_graph`:`${e}_t_${t}_graph`)}),raster:e=>({id:`raster`,sourceUrl:e,zoom:20}),geom:(e,t,n)=>({id:`geom`,sourceUrl:t,layers:n,sourceLayers:n.map(t=>t===`switch_loc`?`${e}_t_${t}`:`${e}_t_${t}_geom`)}),graph:(e,t,n)=>({id:`graph`,sourceUrl:t,layers:n,sourceLayers:n.map(t=>t===`switch_loc`?`${e}_t_${t}`:t===`sgfhqy`?`a_${t}_graph`:`${e}_t_${t}_graph`)}),geojson:e=>({id:e}),rswp:e=>({id:`rswp`,sourceUrl:e}),mbtiles:(e,t)=>({id:`mbtiles`,sourceUrl:e,layers:t,sourceLayers:t.map(e=>`t_${e}_graph`)}),rage:(e,t,n,r)=>({id:`geom`,subSourceId:`raster`,sourceUrl:e,subSourceUrl:t,layers:r,sourceLayers:r.map(e=>e===`switch_loc`?`${n}_t_${e}`:`${n}_t_${e}_geom`)})};function Ki(e,t,n){let r=BigInt(e),i=BigInt(t),a=BigInt(n),o=r*r*i^a;o===0n&&(o=3735928559n);let s=o;s^=s<<11n,s^=s>>5n,s^=s<<13n,s===0n&&(s=3405691582n);let c=s,l=s^s<<16n,u=s^s>>16n;return{z:r^c,x:i^l,y:a^u}}function qi(e){e.map.setTransformRequest((e,t)=>{if(String(t)!==`Tile`)return{url:e};let n=/^https?:\/\//i.test(e)?e:`${window.location.origin}${e}`,r=new URL(n),i=r.pathname.split(`/`).filter(e=>e);if(i.length>=3){let e=Number(i[i.length-3]),t=Number(i[i.length-2]),n=i[i.length-1],a=n.includes(`.`)?n.split(`.`).pop():`pbf`,o=Number(n.replace(/\.(pbf|png)$/i,``));if(Number.isInteger(e)&&e>=0&&Number.isInteger(t)&&t>=0&&Number.isInteger(o)&&o>=0){let n=Ki(e,t,o),s=i.slice(0,i.length-3).join(`/`);return{url:`${r.protocol}//${r.host}/${s}/${n.z}/${n.x}/${n.y}.${a}`}}}return{url:e}})}var Ji=20037508.34,Yi=(e,t)=>[e/Ji*180,Math.atan(Math.exp(t/Ji*Math.PI))*360/Math.PI-90],Xi=e=>`coordinates`in e,Zi=e=>typeof e[0]==`number`?Yi(e[0],e[1]):e.map(Zi),Qi=e=>e?.features?{...e,features:e.features.map(e=>({...e,geometry:Xi(e.geometry)?{...e.geometry,coordinates:Zi(e.geometry.coordinates)}:e.geometry}))}:e,$i=(e,t)=>{if(e===`signal`){if(!t?.features)return;t.features.forEach(({properties:e})=>{e&&(!e.positionSide&&e.posi_side&&(e.positionSide=e.posi_side,delete e.posi_side),!e.installType&&e.install_type&&(e.installType=e.install_type,delete e.install_type),!e.functionType&&e.function_type&&(e.functionType=e.function_type,delete e.function_type))})}if(e===`track_circuit`){if(!t?.features)return;t.features.forEach(({properties:e})=>{e&&(!e.fromCode&&e.from_code&&(e.fromCode=e.from_code,delete e.from_code),!e.toCode&&e.to_code&&(e.toCode=e.to_code,delete e.to_code))})}if(e===`insulation`){if(!t?.features)return;t.features.forEach(({properties:e})=>{e&&(!e.downSignal&&e.downsignal&&(e.downSignal=e.downsignal,delete e.downsignal),!e.upSignal&&e.upsignal&&(e.upSignal=e.upsignal,delete e.upsignal))})}},ea=class{map;mapConfigs;stashFeatures=new Map;layerFeaturesCache=new Map;constructor(e){let n={version:8,sources:{},layers:[]};this.map=new t.default.Map({container:e,style:n,center:[0,0],zoom:14,attributionControl:!1}),Q.base(this),this.map.on(`load`,()=>{this.cursorTool=new Q.cursor(this.map),this.drawTool=new Q.draw(this),this.injectTeeeGeoJson=Q.injectTeeeGeoJson,this.snaps=new Q.snaps(this),this.drawRoute=new Q.drawRoute(this)})}initMap(e){let t=async()=>{try{console.log(`开始构建业务地图: ${e.id}`),Array.isArray(e.source)?e.source.forEach((e,t)=>{this.map.addSource(this.mapConfigs.sourceLayers[t],e)}):this.map.getSource(e.id)?console.warn(`地图源已存在,跳过添加: ${e.id}`):this.map.addSource(e.id,e.source),e.subSourceId&&(this.map.getSource(e.subSourceId)?console.warn(`地图源已存在,跳过添加: ${e.subSourceId}`):this.map.addSource(e.subSourceId,e.subSource)),(await oe()).forEach(e=>{this.map.hasImage(e.id)?console.warn(`图标已存在,跳过添加: ${e.id}`):this.map.addImage(e.id,e.image)}),e.layers&&e.layers.forEach(e=>{this.map.getLayer(e.id)?console.debug(`图层已存在: ${e.id}`):this.map.addLayer(e)}),this.layerTree=new Gi(this.map,e.id);let t=this.map.getStyle().sources,n=Object.keys(t);console.log(`源列表 (${n.length}):`,n,t);let r=this.map.getStyle().layers,i=r.map(e=>e.id);console.log(`图层列表 (${i.length}):`,r);let a=this.map.listImages();console.log(`图标列表 (${a.length}):`,a),console.groupEnd(),console.log(`地图构建全部完成: ${e.id}`)}catch(t){console.error(`地图初始化失败: ${e.id}`,t),t instanceof Error&&console.error(`错误详情: ${t.message}`)}};this.map.loaded()?t():this.map.on(`load`,()=>{t()}),this.map.once(`idle`,()=>{setTimeout(()=>{this.stashAllFeature()},800)})}createCTCMap(e,t,n){this.mapConfigs=$.ctc(e,t,n);let r=T.graph(this.mapConfigs.sourceUrl),i=D.ctc(this.mapConfigs),a={id:this.mapConfigs.id,source:r,layers:i};this.initMap(a),this.ctcTool=new Q.ctc(this),this.ctcMenu=new Q.ctcMenu(this),this.ctcHoverTool=new Q.ctcHover(this)}createCTCEncryptedMap(e,t,n){qi(this),this.mapConfigs=$.ctc(e,t,n);let r=T.graph(this.mapConfigs.sourceUrl),i=D.ctc(this.mapConfigs),a={id:this.mapConfigs.id,source:r,layers:i};this.initMap(a),this.ctcTool=new Q.ctc(this),this.ctcMenu=new Q.ctcMenu(this),this.ctcHoverTool=new Q.ctcHover(this)}createRSWPMap(e){let t=$.rswp(e),n=T.raster(t.sourceUrl),r=D.raster(t.id),i=$.geojson(`rswp-geojson`),a=T.geojson(),o={id:t.id,source:n,subSourceId:i.id,subSource:a,layers:r};this.mapConfigs=t,this.mapConfigs.subSourceId=i.id,this.initMap(o)}createGraphMap(e,t,n){this.mapConfigs=$.graph(e,t,n);let r=T.graph(this.mapConfigs.sourceUrl),i=D.graph(this.mapConfigs),a={id:this.mapConfigs.id,source:r,layers:i};this.initMap(a),Q.graph(this)}createGraphEncryptedMap(e,t,n){qi(this),this.mapConfigs=$.graph(e,t,n);let r=T.graph(this.mapConfigs.sourceUrl),i=D.ctc(this.mapConfigs),a={id:this.mapConfigs.id,source:r,layers:i};this.initMap(a),this.ctcTool=new Q.ctc(this),this.ctcMenu=new Q.ctcMenu(this)}createGeomMap(e,t,n){this.mapConfigs=$.geom(e,t,n);let r=T.geom(this.mapConfigs.sourceUrl),i=D.geom(this.mapConfigs),a={id:this.mapConfigs.id,source:r,layers:i};this.initMap(a)}createGeomEncryptedMap(e,t,n){qi(this),this.mapConfigs=$.geom(e,t,n);let r=T.geom(this.mapConfigs.sourceUrl),i=D.geom(this.mapConfigs),a={id:this.mapConfigs.id,source:r,layers:i};this.initMap(a)}async createGeoJsonStationMap(e){let t=e.map(e=>e.name),r=t.map(e=>`geojson_${e}`);this.mapConfigs=$.geojson(`geojson`),this.mapConfigs.layers=t,this.mapConfigs.sourceLayers=r;let i=await Promise.all(e.map(async(e,t)=>{let n=r[t],i=e.name;if(this.map.getSource(n))return;let a=e.data,o;return typeof a==`string`?(o=Qi(await(await fetch(a)).json()),$i(i,o)):(o=Qi(a),$i(i,o)),this.layerFeaturesCache.set(i,o.features),T.geojson(o)})),a={id:this.mapConfigs.id,source:i,layers:D.geojson(t,r)};this.initMap(a);let o=e.find(e=>e.name===`track`)?.data;if(o){let e=(0,n.default)(Qi(o));this.map.fitBounds([[e[0],e[1]],[e[2],e[3]]],{padding:100,maxZoom:15})}Q.geojson(this)}createRasterMap(e){this.mapConfigs=$.raster(e);let t=T.raster(this.mapConfigs.sourceUrl),n=D.raster(this.mapConfigs.id),r={id:this.mapConfigs.id,source:t,layers:n};this.initMap(r)}createEncryptedRasterMap(e){qi(this),this.mapConfigs=$.raster(e);let t=T.raster(this.mapConfigs.sourceUrl),n=D.raster(this.mapConfigs.id),r={id:this.mapConfigs.id,source:t,layers:n};this.initMap(r)}createRAGEMap(e,t,n){let r=[`track`,`signal`,`bumper`,`prevention`];qi(this),this.mapConfigs=$.rage(e,t,n,r);let i=T.geom(this.mapConfigs.sourceUrl),a=T.raster(this.mapConfigs.subSourceUrl),o=D.geom(this.mapConfigs),s=[...D.raster(this.mapConfigs.subSourceId),...o],c={id:this.mapConfigs.id,source:i,subSourceId:this.mapConfigs.subSourceId,subSource:a,layers:s};this.initMap(c)}getMap(){return this.map}getMapConfigs(){return this.mapConfigs}async stashAllFeature(){if(!this.mapConfigs)return;let e=this.mapConfigs.sourceLayers,t=this.mapConfigs.id;this.stashFeatures.clear(),e?.forEach(e=>{e.includes(`prevention`)||this.map.querySourceFeatures(t,{sourceLayer:e}).forEach(t=>{t.properties.code&&this.stashFeatures.set(t.properties.code,{sourceLayer:e})})});let n=this.mapConfigs.layers??[];await Promise.all(n.map(async e=>{if(e===`prevention`)return;let t=`geojson_${e}`,n=this.map.getSource(t);n&&(await n.getData()).features?.forEach(e=>{let n=e.properties?.code;n&&!this.stashFeatures.get(n)&&this.stashFeatures.set(n,{sourceLayer:t,properties:e.properties})})}))}updateFeatureState(e,t){if(!this.stashFeatures.get(e))return;Object.assign(this.stashFeatures.get(e),t);let n=this.stashFeatures.get(e);if(n.sourceLayer?.startsWith(`geojson_`))this.map.setFeatureState({source:n.sourceLayer,id:e},n);else{if(!this.mapConfigs)return;this.map.setFeatureState({source:this.mapConfigs.id,sourceLayer:n.sourceLayer,id:e},n)}}getFeatureState(e){if(this.stashFeatures.get(e))return this.stashFeatures.get(e)}locateGeojsonFeature(e){let t=(0,n.default)(Qi(e));this.map.fitBounds([[t[0],t[1]],[t[2],t[3]]],{padding:50,maxZoom:18})}queryGeojsonFeatures(e){return this.layerFeaturesCache.get(e)??[]}},ta=document.createElement(`style`);ta.textContent=`
6
+ (`,[`to-string`,[`get`,`costingModel`]],`)`],[`concat`,[`to-string`,[`get`,`text`]]]],"symbol-placement":`point`,"text-size":[`interpolate`,[`linear`],[`zoom`],5,10,10,12,13,14,14,16,18,18],"text-overlap":`always`,"text-variable-anchor":[`left`,`right`,`top`,`bottom`],"text-radial-offset":.5,"text-justify":`left`,"text-letter-spacing":.05},paint:{"text-halo-color":`#F7F7F7`,"text-halo-width":2,"text-color":`#232E3D`}},routingLineLayerNodeSpec:{id:`{prefix}-routing-node`,type:`circle`,source:`{prefix}-routing-source`,filter:[`==`,`$type`,`Point`],layout:{},paint:{"circle-radius":3,"circle-color":[`case`,[`==`,[`get`,`text`],`Start`],`#0000FF`,[`==`,[`get`,`text`],`Goal`],`#FFFF00`,`#FFFFFF`],"circle-stroke-color":`#000000`,"circle-stroke-width":1}},timeIsochronePolygonLayerSpec:{id:`{prefix}-time-isochrone-polygon`,type:`fill`,source:`{prefix}-time-isochrone-source`,layout:{},paint:{"fill-color":[`get`,`fillColor`],"fill-opacity":[`get`,`fillOpacity`]}},timeIsochroneLineLayerSpec:{id:`{prefix}-time-isochrone-line`,type:`line`,source:`{prefix}-time-isochrone-source`,layout:{"line-join":`round`,"line-cap":`round`},paint:{"line-color":[`get`,`fillColor`],"line-width":3}},timeIsochroneLabelLayerSpec:{id:`{prefix}-time-isochrone-label`,type:`symbol`,source:`{prefix}-time-isochrone-source`,layout:{"symbol-placement":`line`,"text-pitch-alignment":`viewport`,"text-field":[`concat`,[`get`,`contour`],` `,`min`],"text-size":12,"symbol-spacing":100,"text-max-angle":45},paint:{"text-color":`rgb(0, 0, 0)`,"text-halo-width":1,"text-halo-color":`rgb(255, 255, 255)`}},distanceIsochronePolygonLayerSpec:{id:`{prefix}-distance-isochrone-polygon`,type:`fill`,source:`{prefix}-distance-isochrone-source`,layout:{},paint:{"fill-color":[`get`,`fillColor`],"fill-opacity":[`get`,`fillOpacity`]}},distanceIsochroneLineLayerSpec:{id:`{prefix}-distance-isochrone-line`,type:`line`,source:`{prefix}-distance-isochrone-source`,layout:{"line-join":`round`,"line-cap":`round`},paint:{"line-color":[`get`,`fillColor`],"line-width":3}},distanceIsochroneLabelLayerSpec:{id:`{prefix}-distance-isochrone-label`,type:`symbol`,source:`{prefix}-distance-isochrone-source`,layout:{"symbol-placement":`line`,"text-pitch-alignment":`viewport`,"text-field":[`concat`,[`get`,`contour`],` `,`km`],"text-size":12,"symbol-spacing":100,"text-max-angle":45},paint:{"text-color":`rgb(0, 0, 0)`,"text-halo-width":1,"text-halo-color":`rgb(255, 255, 255)`}}},ai=`data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='UTF-8'%20standalone='no'?%3e%3csvg%20xmlns:dc='http://purl.org/dc/elements/1.1/'%20xmlns:cc='http://creativecommons.org/ns%23'%20xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns%23'%20xmlns:svg='http://www.w3.org/2000/svg'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:sodipodi='http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd'%20xmlns:inkscape='http://www.inkscape.org/namespaces/inkscape'%20inkscape:version='1.0%20(4035a4fb49,%202020-05-01)'%20sodipodi:docname='poi.svg'%20id='svg4460'%20height='100'%20width='100'%20version='1.1'%3e%3csodipodi:namedview%20inkscape:document-rotation='0'%20inkscape:current-layer='svg4460'%20inkscape:window-maximized='1'%20inkscape:window-y='-8'%20inkscape:window-x='-8'%20inkscape:cy='70.031285'%20inkscape:cx='-78.460726'%20inkscape:zoom='2.02'%20showgrid='false'%20id='namedview11'%20inkscape:window-height='1017'%20inkscape:window-width='1920'%20inkscape:pageshadow='2'%20inkscape:pageopacity='0'%20guidetolerance='10'%20gridtolerance='10'%20objecttolerance='10'%20borderopacity='1'%20bordercolor='%23666666'%20pagecolor='%23ffffff'%20/%3e%3cdefs%20id='defs4462'%20/%3e%3cmetadata%20id='metadata4465'%3e%3crdf:RDF%3e%3ccc:Work%20rdf:about=''%3e%3cdc:format%3eimage/svg+xml%3c/dc:format%3e%3cdc:type%20rdf:resource='http://purl.org/dc/dcmitype/StillImage'%20/%3e%3cdc:title%3e%3c/dc:title%3e%3c/cc:Work%3e%3c/rdf:RDF%3e%3c/metadata%3e%3cpath%20d='M%2050.001528,3.3861402e-7%20C%2030.763177,3.3861402e-7%2015,15.718144%2015,34.901534%20c%200,7.432782%202.373565,14.339962%206.391689,20.019029%20l%2024.338528,42.073163%20c%203.40849,4.452814%205.674917,3.607154%208.509014,-0.23458%20L%2081.083105,51.075788%20C%2081.625418,50.0948%2082.050328,49.050173%2082.421327,47.983517%2084.078241,43.936622%2085.000002,39.521943%2085,34.901534%2085,15.718144%2069.23988,3.3861402e-7%2050.001528,3.3861402e-7%20Z%20m%200,16.35400066138598%20c%2010.359296,0%2018.597616,8.21783%2018.597618,18.547533%200,10.329703%20-8.238322,18.544487%20-18.597618,18.544487%20-10.359299,0%20-18.600672,-8.214784%20-18.600672,-18.544487%200,-10.329703%208.241373,-18.547533%2018.600672,-18.547533%20z'%20style='fill:%233FB1CE;stroke-width:4.26019'%20id='path4135'%20/%3e%3c/svg%3e`,oi=(e,t)=>{let n=t.updateType;return n===`finish`||n===`commit`?Sr(e):{valid:!0}},si=()=>({render:new An({modeName:`render`,styles:{}}),point:new Cn({editable:!0}),marker:new Vr({editable:!0,styles:{markerUrl:ai,markerWidth:27,markerHeight:27}}),linestring:new gn({editable:!0}),polygon:new En({editable:!0,validation:oi}),rectangle:new kn,"angled-rectangle":new Er,circle:new It,freehand:new Bt,"freehand-linestring":new Rr,sensor:new Nr,sector:new Ar,select:new Qn({flags:{point:{feature:{draggable:!0}},marker:{feature:{draggable:!0}},polygon:{feature:{draggable:!0,rotateable:!0,scaleable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},linestring:{feature:{draggable:!0,rotateable:!0,scaleable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},freehand:{feature:{draggable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},"freehand-linestring":{feature:{draggable:!0,rotateable:!0,scaleable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},circle:{feature:{draggable:!0,coordinates:{resizable:`center`,deletable:!1,midpoints:!1}}},rectangle:{feature:{draggable:!0,rotateable:!0,coordinates:{resizable:`opposite`,deletable:!1,midpoints:!1}}},"angled-rectangle":{feature:{draggable:!0,rotateable:!0,coordinates:{resizable:`opposite`,deletable:!1,midpoints:!1}}},sensor:{feature:{draggable:!0,rotateable:!0,scaleable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},sector:{feature:{draggable:!0,rotateable:!0,scaleable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}}}}),delete:new An({modeName:`delete`,styles:{}}),"delete-selection":new An({modeName:`delete-selection`,styles:{}}),download:new An({modeName:`download`,styles:{}}),undo:new An({modeName:`undo`,styles:{}}),redo:new An({modeName:`redo`,styles:{}})}),Y=6371008.8;Y*100,Y*100,360/(2*Math.PI),Y*3.28084,Y*39.37,Y/1e3,Y/1e3,Y/1609.344,Y*1e3,Y*1e3,Y/1852,Y*1.0936,Y*Y/2,Math.PI/180;var ci=e=>e.charAt(0).toUpperCase()+e.slice(1),li=[`{prefix}-point`,`{prefix}-point-lower`,`{prefix}-linestring`,`{prefix}-polygon`,`{prefix}-polygon-outline`];[...li,ri.polygonLayerSpec?.source,ri.lineLayerLabelSpec?.source],[...li,ii.routingLineLayerNodeLabelSpec?.source,ii.routingLineLayerNodeSpec?.source,ii.timeIsochronePolygonLayerSpec?.source,ii.timeIsochroneLineLayerSpec?.source,ii.timeIsochroneLabelLayerSpec?.source,ii.distanceIsochronePolygonLayerSpec?.source,ii.distanceIsochroneLineLayerSpec?.source,ii.distanceIsochroneLabelLayerSpec?.source];var ui=(e,t,n=li,r=`td`)=>{n=n.map(e=>e.replace(`{prefix}`,r));let i=JSON.parse(JSON.stringify(e));return t&&(t.onlyTerraDrawLayers===!0?(i.layers=i.layers.filter(e=>`source`in e&&n.includes(e.source)),Object.keys(i.sources).forEach(e=>{n.includes(e)||delete i.sources[e]})):t.excludeTerraDrawLayers===!0&&(i.layers=i.layers.filter(e=>`source`in e&&!n.includes(e.source)||e.type===`background`),Object.keys(i.sources).forEach(e=>{n.includes(e)&&delete i.sources[e]}))),i},di=class{className;dialog;title;constructor(e,t){this.className=e,this.title=t}create(e,t){let n=document.getElementsByClassName(this.className);n.length>0&&Array.from(n).forEach(e=>{e.remove()}),this.dialog=document.createElement(`dialog`),this.dialog.classList.add(this.className);let r=document.createElement(`div`);r.classList.add(`dialog-header`);let i=document.createElement(`h3`);i.textContent=this.title,i.classList.add(`dialog-title`),r.appendChild(i);let a=document.createElement(`button`);a.type=`button`,a.classList.add(`close-button`),a.innerHTML=`×`,a.setAttribute(`aria-label`,`Close dialog`),a.addEventListener(`click`,()=>{this.close()}),r.appendChild(a),this.dialog.appendChild(r);let o=document.createElement(`div`);o.classList.add(`content`),this.dialog.appendChild(t(o)),this.dialog.addEventListener(`click`,e=>{let t=e.target?.getBoundingClientRect();t&&(t.left>e.clientX||t.right<e.clientX||t.top>e.clientY||t.bottom<e.clientY)&&this.close()}),e.appendChild(this.dialog)}open(){this.dialog?.showModal()}close(){this.dialog?.close()}createSegmentButtons(e,t,n=()=>{}){let r=document.createElement(`div`);return r.classList.add(`segment-buttons`),e.forEach(e=>{let i=document.createElement(`button`);i.type=`button`,i.classList.add(`segment-button`),i.value=e.value,i.textContent=e.label,e.value===t&&i.classList.add(`active`),i.addEventListener(`click`,()=>{r.querySelectorAll(`.segment-button`).forEach(e=>e.classList.remove(`active`)),i.classList.add(`active`),n(i.value)}),r.appendChild(i)}),r}};2*Math.PI*6378137/2;var fi=class{controlContainer;map;modeButtons={};_isExpanded=!1;_cssPrefix=``;get isExpanded(){return this._isExpanded}get cssPrefix(){return this._cssPrefix}set isExpanded(e){this._isExpanded=e;let t=document.getElementsByClassName(`maplibregl-terradraw-${this.cssPrefix}add-control`);for(let e=0;e<t.length;e++){let n=t.item(e);n&&(this.isExpanded?n.classList.remove(`hidden`):n.classList.add(`hidden`))}let n=document.getElementsByClassName(`maplibregl-terradraw-${this.cssPrefix}render-button`);n&&n.length>0&&(this.isExpanded?n.item(0)?.classList.add(`enabled`):(n.item(0)?.classList.remove(`enabled`),this.resetActiveMode())),this.toggleDeleteSelectionButton(),this.toggleButtonsWhenNoFeature(),this.isExpanded?this.dispatchEvent(`expanded`):this.dispatchEvent(`collapsed`)}get showDeleteConfirmation(){return this.options.showDeleteConfirmation===!0}set showDeleteConfirmation(e){this.options.showDeleteConfirmation=e}terradraw;options;events={};defaultMode=`render`;constructor(e){this.modeButtons={},this.options={...ni,modes:[...ni.modes??[]],...e};let t=this.options.adapterOptions?.prefixId??`td`;this.options.adapterOptions||(this.options.adapterOptions={}),this.options.adapterOptions?.prefixId||(this.options.adapterOptions.prefixId=t),this.options.undoRedo||(this.options.undoRedo={modeLevel:new Zr({maxStackSize:100}),sessionLevel:new Qr({maxStackSize:100}),keyboardShortcuts:new Gr})}getDefaultPosition(){return`top-right`}onAdd(e){if(this.options&&this.options.modes&&this.options.modes.length===0)throw Error(`At least a mode must be enabled.`);this.map=e;let t=si(),n=[];return this.options?.modes?.forEach(e=>{if(this.options.modeOptions&&this.options.modeOptions[e]){let r=this.options.modeOptions[e];if(e===`select`){let n=t[e];if(n){let e=n.flags;Object.keys(e).forEach(t=>{r.flags[t]||(r.flags[t]=e[t])})}}n.push(r)}else t[e]&&n.push(t[e])}),n.forEach(e=>{e.state!==`unregistered`&&(e._state=`unregistered`)}),this.options?.modes?.includes(`render`)||(n.push(new An({modeName:`default`,styles:{}})),this.defaultMode=`default`),this.isExpanded=this.options.open===!0,this.terradraw=new ei({adapter:new ti({map:e,...this.options.adapterOptions}),modes:n,undoRedo:this.options.undoRedo}),this.map?.loaded()?this.terradraw.start():this.map?.once(`load`,()=>{this.terradraw?.start()}),this.controlContainer=document.createElement(`div`),this.controlContainer.classList.add(`maplibregl-ctrl`),this.controlContainer.classList.add(`maplibregl-ctrl-group`),n.forEach(e=>{e.mode!==`default`&&this.addTerradrawButton(e.mode)}),Object.values(this.modeButtons).forEach(e=>{this.controlContainer?.appendChild(e)}),this.toggleButtonsWhenNoFeature(),this.terradraw?.on(`finish`,this.toggleButtonsWhenNoFeature.bind(this)),this.terradraw?.on(`history`,this.handleHistoryChange.bind(this)),this.map.once(`idle`,()=>{this.toggleButtonsWhenNoFeature()}),this.controlContainer}onRemove(){!this.controlContainer||!this.controlContainer.parentNode||!this.map||(this.deactivate(),this.modeButtons={},this.terradraw=void 0,this.map=void 0,this.controlContainer.parentNode.removeChild(this.controlContainer))}on(e,t){this.events[e]?this.events[e].push(t):this.events[e]=[t]}off(e,t){if(!this.events[e])return;let n=this.events[e].findIndex(e=>e===t);n!==-1&&this.events[e].splice(n,1)}dispatchEvent(e,t){this.events[e]&&this.events[e].forEach(e=>{let n=(this.terradraw?.getSnapshot())?.filter(e=>e.properties.selected===!0);e({feature:n,mode:this.terradraw?.getMode(),...t})})}activate(){this.terradraw&&(this.terradraw.enabled||this.terradraw.start())}deactivate(){this.terradraw&&this.terradraw.enabled&&(this.resetActiveMode(),this.dispatchEvent(`mode-changed`),this.terradraw.stop())}handleModeChange(e,t){let n=t.setMode(e);return this.syncButtonStates(e),e!==this.defaultMode&&this.activate(),this.dispatchEvent(`mode-changed`),n}syncButtonStates(e){if(!this.controlContainer)return;let t=this.controlContainer.getElementsByClassName(`maplibregl-terradraw-${this.cssPrefix}add-control`);for(let e=0;e<t.length;e++){let n=t.item(e);n&&n.classList.remove(`active`)}if(e!==this.defaultMode&&e!==`render`){let t=this.controlContainer.getElementsByClassName(`maplibregl-terradraw-${this.cssPrefix}add-${e}-button`);t&&t.length>0&&t[0].classList.add(`active`)}this.toggleDeleteSelectionButton(),this.toggleButtonsWhenNoFeature()}getTerraDrawInstance(){return this.terradraw?new Proxy(this.terradraw,{get:(e,t,n)=>t===`setMode`?t=>this.handleModeChange(t,e):t===`clearUndoRedoHistory`?()=>{e.clearUndoRedoHistory(),this.handleHistoryChange({undoSize:0,redoSize:0})}:Reflect.get(e,t,n)}):this.terradraw}handleHistoryChange(e){if(!this.controlContainer)return;let t=this.controlContainer.getElementsByClassName(`maplibregl-terradraw-${this.cssPrefix}undo-button`);for(let n=0;n<t.length;n++){let r=t.item(n);r&&(r.disabled=e.undoSize===0)}let n=this.controlContainer.getElementsByClassName(`maplibregl-terradraw-${this.cssPrefix}redo-button`);for(let t=0;t<n.length;t++){let r=n.item(t);r&&(r.disabled=e.redoSize===0)}}toggleEditor(){this.terradraw&&(this.isExpanded=!this.isExpanded)}resetActiveMode(){this.terradraw&&(this.terradraw.enabled||this.terradraw.start(),this.terradraw?.setMode(this.defaultMode),this.syncButtonStates(this.defaultMode))}addTerradrawButton(e){let t=document.createElement(`button`);t.type=`button`,this.modeButtons[e]=t,e===`render`?(t.classList.add(`maplibregl-terradraw-${this.cssPrefix}${e}-button`),this.isExpanded&&t.classList.add(`enabled`),t.type=`button`,t.title=ci(`expand or collapse drawing tool`),t.addEventListener(`click`,this.toggleEditor.bind(this))):(t.classList.add(`maplibregl-terradraw-${this.cssPrefix}add-control`),this.isExpanded||t.classList.add(`hidden`),t.title=ci(e.replace(/-/g,` `)),e===`delete`?(t.classList.add(`maplibregl-terradraw-${this.cssPrefix}${e}-button`),t.addEventListener(`click`,this.handleDeleteAllFeatures.bind(this))):e===`delete-selection`?(t.classList.add(`maplibregl-terradraw-${this.cssPrefix}${e}-button`),t.classList.add(`hidden-delete-selection`),t.addEventListener(`click`,this.handleDeleteSelectedFeatures.bind(this))):e===`download`?(t.classList.add(`maplibregl-terradraw-${this.cssPrefix}${e}-button`),t.addEventListener(`click`,this.handleDownload.bind(this))):[`undo`,`redo`].includes(e)?(t.classList.add(`maplibregl-terradraw-${this.cssPrefix}${e}-button`),t.disabled=!0,t.addEventListener(`click`,()=>{this.terradraw&&(e===`undo`?this.terradraw.undo():this.terradraw.redo())})):(t.classList.add(`maplibregl-terradraw-${this.cssPrefix}add-${e}-button`),t.addEventListener(`click`,()=>{if(!this.terradraw)return;let n=t.classList.contains(`active`);this.activate(),this.resetActiveMode(),n||(this.terradraw.setMode(e),this.syncButtonStates(e)),this.dispatchEvent(`mode-changed`)})))}getFeatures(e=!1){if(!this.terradraw)return;let t={type:`FeatureCollection`,features:(this.terradraw?.getSnapshot()).filter(e=>e.properties.mode!==`select`)};return e===!0&&(t.features=t.features.filter(e=>e.properties.selected===!0)),t}cleanStyle(e,t){return ui(e,t,li,this.options.adapterOptions?.prefixId)}showDeleteConfirmationDialog(e){let t=new di(`maplibre-terradraw-delete-confirmation-dialog`,`Delete All Features`);t.create(document.body,n=>{let r=document.createElement(`p`);r.textContent=`Are you sure you want to delete all features?`,n.appendChild(r);let i=document.createElement(`div`);i.classList.add(`dialog-buttons`);let a=document.createElement(`button`);a.type=`button`,a.textContent=`Cancel`,a.classList.add(`dialog-button-cancel`),a.addEventListener(`click`,()=>{t.close()});let o=document.createElement(`button`);return o.type=`button`,o.textContent=`Delete`,o.classList.add(`dialog-button-delete`),o.addEventListener(`click`,()=>{e(),t.close()}),i.appendChild(a),i.appendChild(o),n.appendChild(i),n}),t.open()}handleDeleteAllFeatures(){if(!this.terradraw||!this.terradraw.enabled)return;let e=()=>{this.terradraw?.clear(),this.resetActiveMode(),this.toggleDeleteSelectionButton(),this.toggleButtonsWhenNoFeature(),this.dispatchEvent(`feature-deleted`)};this.options.showDeleteConfirmation===!0?this.showDeleteConfirmationDialog(e):e()}handleDeleteSelectedFeatures(){if(!this.terradraw||!this.terradraw.enabled)return;let e=(this.terradraw?.getSnapshot()).filter(e=>e.properties.selected===!0);if(e.length>0){let t=e.map(e=>e.id);this.terradraw.removeFeatures(t);for(let e of t)this.terradraw.deselectFeature(e);this.dispatchEvent(`feature-deleted`,{deletedIds:t})}this.toggleDeleteSelectionButton(),this.toggleButtonsWhenNoFeature()}handleDownload(){let e=this.getFeatures(!1),t=`data:application/json;charset=utf-8,`+encodeURIComponent(JSON.stringify(e)),n=document.createElement(`a`);n.setAttribute(`href`,t),n.setAttribute(`download`,`data.geojson`),document.body.appendChild(n),n.click(),n.remove()}toggleButtonsWhenNoFeature(){if(!this.controlContainer)return;let e=(this.terradraw?.getSnapshot())?.filter(e=>e.properties.mode!==`select`),t=!!(e&&e.length>0),n=[`maplibregl-terradraw-${this.cssPrefix}add-select-button`,`maplibregl-terradraw-${this.cssPrefix}download-button`,`maplibregl-terradraw-${this.cssPrefix}delete-button`];for(let e of n){let n=this.controlContainer.getElementsByClassName(e);for(let e=0;e<n.length;e++){let r=n.item(e);r&&(r.disabled=!t)}}}toggleDeleteSelectionButton(){let e=this.terradraw?.enabled||!1,t=this.terradraw?.getMode(),n=this.getFeatures(!1),r=n&&n.features.length>0,i=r&&e&&t===`select`,a=document.getElementsByClassName(`maplibregl-terradraw-${this.cssPrefix}delete-selection-button`);for(let e=0;e<a.length;e++){let t=a.item(e);t&&(i?t.classList.remove(`hidden-delete-selection`):t.classList.add(`hidden-delete-selection`))}if(!r){let e=document.getElementsByClassName(`maplibregl-terradraw-${this.cssPrefix}add-select-button`);for(let t=0;t<e.length;t++){let n=e.item(t);n&&n.classList.remove(`active`)}}}clearExtendedFeatures(e,t=void 0){if(this.map)for(let n of e){let e=this.map.getStyle().sources[n];e&&typeof e.data!=`string`&&e.data.type===`FeatureCollection`&&(t===void 0?e.data.features=[]:e.data.features=e.data.features.filter(e=>e.properties?.originalId?!t.includes(e.properties.originalId):!t.includes(e.id)),this.map.getSource(n)?.setData(e.data))}}},pi=class{drawControl=null;mapInstance;onFinishCallback;onChangeCallback;onDeleteCallback;onSelectCallback;changeTimer=null;lastFeatureCount=0;constructor(e){this.mapInstance=e.map}async addToMap(e=!0){this.drawControl||(this.drawControl=new fi({open:e}),this.mapInstance.addControl(this.drawControl,`top-right`),await new Promise(e=>{this.mapInstance.isStyleLoaded()?e():this.mapInstance.once(`idle`,()=>e())}),this.bindEvents())}bindEvents(){if(!this.drawControl)return;let e=this.drawControl.getTerraDrawInstance();e&&(e.on(`change`,()=>{let t=e.getSnapshot(),n=this.toGeoJSON(t);t.length<this.lastFeatureCount?this.onDeleteCallback?.(n):t.length>this.lastFeatureCount&&this.onFinishCallback?.(n),this.lastFeatureCount=t.length,this.changeTimer&&clearTimeout(this.changeTimer),this.changeTimer=setTimeout(()=>{this.onChangeCallback?.(n)},50)}),e.on(`select`,e=>this.onSelectCallback?.(String(e))),e.on(`deselect`,()=>this.onSelectCallback?.(null)))}toGeoJSON(e){return{type:`FeatureCollection`,features:e.map(e=>({type:`Feature`,geometry:e.geometry,properties:{...e.properties||{},id:e.id}}))}}changeMode(e){if(!this.drawControl)return;let t=this.drawControl.getTerraDrawInstance();if(t){if(e===`undo`){t.undo();return}if(e===`redo`){t.redo();return}if(e===`download`){this.downloadGeoJSON();return}t.setMode(e)}}setEnabled(e){if(!this.drawControl)return;let t=this.drawControl.getTerraDrawInstance();t&&(e?t.setMode(`select`):t.setMode(`render`))}getFeatureById(e){if(!this.drawControl)return;let t=this.drawControl.getTerraDrawInstance();if(t)return t.getSnapshot().find(t=>t.id===e)}deleteFeatureById(e){if(!this.drawControl)return;let t=this.drawControl.getTerraDrawInstance();if(!t)return;let n=Array.isArray(e)?e:[e];t.removeFeatures(n)}updateModeStyles(e,t){if(!this.drawControl)return;let n=this.drawControl.getTerraDrawInstance();n&&n.updateModeOptions(e,{styles:t})}drawWithForcedCoordinates(e,t){if(!this.drawControl)return;let n=this.drawControl.getTerraDrawInstance();if(!n)return;let r;e===`point`?r={type:`Point`,coordinates:t[0]}:e===`linestring`?r={type:`LineString`,coordinates:t}:e===`polygon`&&(r={type:`Polygon`,coordinates:[[...t,t[0]]]}),r&&n.addFeatures([{type:`Feature`,geometry:r,properties:{}}])}addFeatures(e){if(!this.drawControl||!e.features.length)return;let t=this.drawControl.getTerraDrawInstance();t&&(t.addFeatures(e.features),this.lastFeatureCount=t.getSnapshot().length)}clear(){if(!this.drawControl)return;let e=this.drawControl.getTerraDrawInstance();e&&(e.clear(),this.lastFeatureCount=0)}downloadGeoJSON(){let e=this.drawControl?.getTerraDrawInstance(),t=this.toGeoJSON(e?.getSnapshot()||[]),n=new Blob([JSON.stringify(t,null,2)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`draw_data_${Date.now()}.geojson`,i.click(),URL.revokeObjectURL(r)}destroy(){this.drawControl&&(this.changeTimer&&clearTimeout(this.changeTimer),this.mapInstance.removeControl(this.drawControl),this.drawControl=null,this.onFinishCallback=void 0,this.onChangeCallback=void 0,this.onDeleteCallback=void 0,this.onSelectCallback=void 0)}setOnFinish(e){this.onFinishCallback=e}setOnChange(e){this.onChangeCallback=e}setOnDelete(e){this.onDeleteCallback=e}setOnSelect(e){this.onSelectCallback=e}},mi=`<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1781332754772" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="40602" width="32" height="32" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M645.12 1007.104c-103.936 0-187.904-83.456-187.904-187.904v-136.704h68.096V819.2c0 66.56 52.736 119.296 119.296 119.296s119.296-52.736 119.296-119.296h68.096c1.024 103.936-84.48 187.904-186.88 187.904z" fill="#d81e06" p-id="40603"></path><path d="M631.296 1024c-103.936 0-187.904-83.456-187.904-187.904v-136.704H512v136.704c0 66.56 52.736 119.296 119.296 119.296s133.12-70.144 133.12-136.704l82.432 0.512c0 104.448-113.152 204.8-215.552 204.8zM321.024 16.896H389.12v204.8H321.024zM593.92 16.896h96.256v204.8H593.92zM358.4 419.328h272.896V512H358.4V419.328z" fill="#d81e06" p-id="40604"></path><path d="M755.2 716.8H248.832L155.648 457.216l-5.12-269.824h681.984v269.824L755.2 716.8zM307.2 648.704h387.072l60.416-201.216V276.48H238.592l-5.12 170.496L307.2 648.704z" fill="#d81e06" p-id="40605"></path><path d="M96.6144 678.80448L916.41856 123.392l51.11808 75.45344L147.7376 754.2528z" fill="#d81e06" p-id="40606"></path></svg>`,hi=`<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1781338967549" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="57837" xmlns:xlink="http://www.w3.org/1999/xlink" width="32" height="32"><path d="M426.666667 85.333333C473.6 85.333333 512 123.733333 512 170.666667L512 362.666667C512 362.666667 597.333333 352 597.333333 394.666667 597.333333 394.666667 682.666667 384 682.666667 426.666667 682.666667 426.666667 768 416 768 458.666667 768 458.666667 853.333333 448 853.333333 490.666667L853.333333 640C853.333333 682.666667 725.333333 896 725.333333 938.666667L384 938.666667C384 938.666667 298.666667 640 170.666667 554.666667 170.666667 554.666667 128 298.666667 341.333333 512L341.333333 170.666667C341.333333 123.733333 379.733333 85.333333 426.666667 85.333333Z" p-id="57838" fill="#f7f5f5"></path></svg>`,gi=`<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1781413096158" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="38813" width="32" height="32" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M770.56 343.488c-9.984 93.888-72.64 194.176-157.184 241.536l1.984-2.56c-23.552 26.304-17.152 48.576 19.2 66.752C858.176 683.584 1024 809.664 1024 960c0 75.328-727.424 76.16-956.096 30.336C25.28 981.76 0 971.52 0 960c0-149.376 163.776-274.88 385.28-310.144l-2.368 1.28c42.24-20.032 51.84-41.984 28.8-65.92C327.552 538.048 265.984 437.568 256 343.488h514.56zM512 0c136 0 274.176 106.048 284.48 240h3.52a32 32 0 1 1 0 64h-576a32 32 0 1 1 0-64h16.128C249.536 106.048 376 0 512 0z" fill="#707070" p-id="38814"></path></svg>`,_i=`<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1781413291157" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="47319" width="48" height="48" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M711.210667 344.917333l-294.101334 25.770667a387.584 387.584 0 0 1 3.584-75.818667c95.36 17.493333 191.914667 27.989333 288.810667 31.445334V267.562667c-145.621333-8.96-270.421333-106.965333-270.421333-106.965334A190.976 190.976 0 0 0 290.602667 110.933333c-33.578667 1.706667-65.365333 15.786667-89.301334 39.424a651.946667 651.946667 0 0 0-91.392 120.789334c-31.317333 51.029333-44.8 106.368-17.664 165.162666 8.661333 18.432 19.413333 35.84 32.042667 51.797334 2.858667 3.413333 12.714667 18.944 17.28 18.944-26.88 17.322667-52.736 36.053333-77.568 56.149333h60.672s39.68-29.781333 79.445333-54.272l81.365334 1.706667c-17.237333 12.928-53.845333 40.618667-81.152 66.005333H264.96s113.792-84.181333 208.597333-103.338667l-9.685333 1.706667C652.074667 421.546667 710.442667 418.133333 710.442667 418.133333l0.768-73.216zM102.826667 332.8c0-13.653333 16.896-24.661333 37.930666-24.661333s37.930667 11.008 37.930667 24.661333c0 13.653333-16.896 24.618667-37.930667 24.618667s-37.930667-10.965333-37.930666-24.618667z m144.896-107.52l-75.861334-4.010667s33.92-52.693333 44.757334-56.106666l46.848 0.938666-15.786667 59.178667z m34.304-56.917333l65.792 2.133333v59.306667L268.8 226.602667l13.269333-58.24z m35.456 140.16c20.906667 0 37.973333 10.965333 37.973333 24.618666 0 13.653333-16.896 24.661333-37.973333 24.661334-21.034667 0-37.930667-11.008-37.930667-24.661334 0-13.653333 16.896-24.618667 37.973333-24.618666z" fill="#1296db" p-id="47320"></path><path d="M653.098667 257.450667a190.634667 190.634667 0 0 0-190.421334 190.378666 190.634667 190.634667 0 0 0 190.421334 190.378667 190.677333 190.677333 0 0 0 190.421333-190.378667 190.634667 190.634667 0 0 0-190.421333-190.378666z" fill="#1296db" p-id="47321"></path><path d="M799.829333 633.856c-40.533333 32.085333-91.093333 51.968-146.773333 51.968-55.637333 0-106.112-19.925333-146.773333-51.968-76.970667 49.066667-130.56 135.082667-137.941334 234.794667 26.965333 3.626667 74.922667 7.594667 143.36 7.594666h282.666667c68.48 0 116.48-3.968 143.445333-7.594666-7.296-99.754667-60.885333-185.770667-137.984-234.794667z" fill="#1296db" p-id="47322"></path></svg>`,vi=`<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1781412204514" class="icon" viewBox="0 0 1049 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="15838" width="32.78125" height="32" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M573.540453 699.171348c-17.241629-6.05787-33.45808-13.140917-49.488135-18.639599-2.050356-1.025178-59.646716-21.155945-30.289348-111.278404l1.025178-2.982336 2.982336-3.075534c46.598997-48.556155 86.021748-98.044289 90.12246-208.390713H206.340358c2.982336 111.837592 42.498285 161.791717 89.004084 209.322693l1.957158 2.050356 1.025177 2.982336c26.375032 65.238596-13.140917 102.517793-37.279197 111.278404h-1.025178C134.577903 725.54638 0 805.417061 0 874.19718v30.289348c0 76.888345 141.66095 119.38663 397.489443 119.38663a1365.350606 1365.350606 0 0 0 222.556808-15.191273 254.710116 254.710116 0 0 1-77.820324-184.066038A263.750322 263.750322 0 0 1 573.540453 699.171348zM641.295394 253.125751c-7.083048-1.957158-26.281834-7.083048-26.281834-27.307013 0-77.913523-51.631688-146.600444-129.452013-174.932634-9.319799 23.299498-23.299498 87.978906-33.45808 143.618109l-31.314526-2.982336V9.319799c0-5.032692-2.982336-9.319799-7.083047-9.319799h-36.440416a9.319799 9.319799 0 0 0-7.176245 9.319799v182.015682l-33.364882 3.075534a1316.980847 1316.980847 0 0 0-33.45808-143.618108C225.352748 78.006721 174.746238 146.880038 174.746238 225.72554c0 19.198787-17.241629 25.256656-25.256656 27.307013-11.183759 2.982336-25.256656 7.083048-27.959398 45.48062h548.936182c-3.821118-39.329553-17.055233-42.405087-29.170972-45.387422z" p-id="15839" fill="#4CAF50"></path><path d="M1024.24595 641.108998l-23.113103 23.2063a63.374636 63.374636 0 0 1-89.563272-89.65647l22.740311-23.2063c12.861323-12.768125 4.287108-27.959398-18.639599-24.324676a115.845106 115.845106 0 0 0-95.155151 138.678614L626.756507 860.310679a63.374636 63.374636 0 1 0 89.470074 89.65647l193.851826-194.504213a115.751908 115.751908 0 0 0 138.492219-95.527943c3.541524-23.019904-11.556551-31.59412-24.324676-18.639599zM685.937233 920.050593a21.062747 21.062747 0 1 1 0-29.823358 20.969549 20.969549 0 0 1 0 29.823358z m-21.062747-275.120477l73.067227 73.253623 29.916556-29.823358-73.160425-73.253623-16.402847-31.407724-52.190876-37.279198-29.916556 29.823358 37.279197 52.284075zM909.612417 800.384369a10.438175 10.438175 0 0 0-14.911679 0l-44.828234 44.828235a10.531373 10.531373 0 0 0 0 14.911679l105.593326 105.686525a42.24665 42.24665 0 0 0 59.739914-59.739914z" p-id="15840" fill="#4CAF50"></path></svg>`,yi=`<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1781412389454" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="19959" xmlns:xlink="http://www.w3.org/1999/xlink" width="32" height="32"><path d="M551.216148 731.115158a245.716122 245.716122 0 0 0 55.944296 240.231387H38.941911c-17.551152 0-30.166042-3.839314-34.005356-8.227102s-7.130155-15.357258 0-29.617568c6.033208-49.362614 14.808784-100.919122 25.778254-150.281736a44.974826 44.974826 0 0 1 34.005356-38.393144l83.916444-26.875201 106.403856-32.908409c10.420996-3.839314 14.808784-2.193894 19.196572 4.387788a194.708088 194.708088 0 0 0 157.960365 80.625603 201.838243 201.838243 0 0 0 119.018746-38.941618zM285.206507 76.786288a267.106588 267.106588 0 0 0-103.113015 178.253883v3.839315c0 6.581682 0 14.808784-6.581682 19.196572-17.002678 17.002678-17.002678 36.19925-17.002678 59.78361v25.778254a31.811462 31.811462 0 0 0 1.64542 12.61489 2544.916979 2544.916979 0 0 0 274.236744 15.357258 2542.723085 2542.723085 0 0 0 273.688269-15.357258 22.487413 22.487413 0 0 1 2.193894-10.420996v-10.96947c1.64542-25.22978 3.290841-48.81414-10.969469-69.107659a67.462239 67.462239 0 0 1-12.61489-31.811463 269.848956 269.848956 0 0 0-96.531334-173.317621 25.778254 25.778254 0 0 0-8.227102-7.130156c-0.548473 1.64542-0.548473 3.290841-1.645421 4.387788s-0.548473 3.290841-1.096947 4.936262A914.305303 914.305303 0 0 1 532.56805 251.200857l-19.196572-2.193894v-21.938939a375.704339 375.704339 0 0 1 8.775575-55.395823c6.033208-41.135512 12.61489-83.916443 14.808785-123.955008a28.520621 28.520621 0 0 0-21.390466-32.359935A259.976433 259.976433 0 0 0 387.771049 3.290841C325.245072 14.260311 323.051178 16.454205 330.181333 81.174076a21.390466 21.390466 0 0 0 1.096947 8.227102 41.683985 41.683985 0 0 1 0.548473 8.227103l22.487413 148.087841-19.745045 4.387788c-23.58436-49.362614-36.19925-108.049277-48.81414-167.832887z m147.539368 361.992502c-76.786288 0-153.024103-3.839314-228.713444-10.96947v1.64542l1.645421 9.32405c4.387788 36.19925 10.420996 72.3985 38.393144 97.62828a38.941618 38.941618 0 0 1 8.775575 17.002678 264.912694 264.912694 0 0 0 112.985539 137.118372 125.051955 125.051955 0 0 0 126.697375 6.033208 254.491698 254.491698 0 0 0 123.406535-139.312265v-3.839315a40.587038 40.587038 0 0 1 8.775575-14.808784c31.811462-27.972148 36.19925-68.010712 40.587039-109.146224a268.203535 268.203535 0 0 1-36.199251 2.742368H620.323808c-57.589716 4.936261-121.761114 7.130155-187.577933 7.130155z" p-id="19960" fill="#FF9800"></path><path d="M792.544482 563.282271a230.358864 230.358864 0 1 0 230.358865 230.358865 230.358864 230.358864 0 0 0-230.358865-230.358865z m-15.357257 428.357793h-8.227102l16.454204-159.605784-96.531334-38.393144 121.212641-197.998929v8.227102l-7.678629 150.830209 93.788966 38.941618z" p-id="19961" fill="#FF9800"></path></svg>`,bi=`<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1781414010736" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="48244" width="50" height="50" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M433.32 232.3m-159.61 0a159.61 159.61 0 1 0 319.22 0 159.61 159.61 0 1 0-319.22 0Z" fill="#d81e06" p-id="48245"></path><path d="M501.7 629.08c-1.46-96.26 40.84-149.17 68.44-173.42-41.82-18.74-88.04-29.39-136.83-29.39C248.13 426.27 98 576.39 98 761.58h458.42c-32.8-37.02-53.98-83.92-54.72-132.5zM763.46 654.45c-38.84 0-70.47-31.62-70.47-70.47 0-38.84 31.62-70.47 70.47-70.47s70.47 31.62 70.47 70.47c0 38.84-31.62 70.47-70.47 70.47z m0-115.15c-24.64 0-44.68 20.04-44.68 44.68s20.04 44.68 44.68 44.68 44.68-20.04 44.68-44.68-20.04-44.68-44.68-44.68z" fill="#d81e06" p-id="48246"></path><path d="M679.74 686.44c-33.91-26.15-53.38-65.73-53.38-108.6 0-42.77 19.47-82.28 53.38-108.44l21.02 27.19c-25.45 19.61-40.02 49.22-40.02 81.24 0 32.13 14.57 61.81 40.02 81.41l-21.02 27.2z" fill="#d81e06" p-id="48247"></path><path d="M683.06 752.41c-67.85-31.26-111.66-99.77-111.66-174.57 0-74.7 43.81-143.15 111.66-174.4l14.37 31.22c-55.66 25.65-91.65 81.85-91.65 143.18 0 61.44 35.99 117.7 91.65 143.35l-14.37 31.22zM847.12 686.47l-20.95-27.26c25.41-19.57 40.02-49.25 40.02-81.38 0-32.03-14.6-61.64-40.02-81.21l20.95-27.26c33.97 26.15 53.45 65.7 53.45 108.47 0 42.88-19.47 82.49-53.45 108.64z" fill="#d81e06" p-id="48248"></path><path d="M843.83 752.41l-14.37-31.22c55.66-25.65 91.65-81.91 91.65-143.35 0-61.34-35.99-117.53-91.65-143.18l14.37-31.22c67.85 31.26 111.66 99.71 111.66 174.4 0 74.79-43.81 143.31-111.66 174.57zM763.46 610.43c-14.6 0-26.49-11.85-26.49-26.45s11.88-26.49 26.49-26.49 26.45 11.88 26.45 26.49-11.84 26.45-26.45 26.45z m0-35.75c-5.14 0-9.3 4.16-9.3 9.3 0 5.1 4.16 9.27 9.3 9.27 5.1 0 9.27-4.16 9.27-9.27 0-5.14-4.16-9.3-9.27-9.3zM752.48 643.24h21.95v141.68h-21.95z" fill="#d81e06" p-id="48249"></path></svg>`,xi=`<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1781414908820" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="53275" width="36" height="36" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M968.533333 896c-21.333333-89.6-68.266667-166.4-132.266666-230.4-25.6-25.6-55.466667-51.2-85.333334-68.266667-4.266667-4.266667-8.533333-8.533333-17.066666-8.533333-17.066667-8.533333-34.133333-17.066667-55.466667-25.6 21.333333-21.333333 42.666667-46.933333 55.466667-76.8 12.8-29.866667 21.333333-64 21.333333-98.133333H768c25.6 0 46.933333-8.533333 64-25.6 17.066667-17.066667 25.6-38.4 25.6-64s-8.533333-46.933333-25.6-64c-21.333333-17.066667-42.666667-25.6-64-25.6h-21.333333c-17.066667-51.2-46.933333-89.6-85.333334-119.466667C614.4 55.466667 567.466667 42.666667 512 42.666667c-55.466667 0-102.4 17.066667-145.066667 46.933333-42.666667 29.866667-72.533333 72.533333-85.333333 119.466667h-29.866667c-25.6 0-46.933333 8.533333-64 25.6-17.066667 17.066667-25.6 38.4-25.6 64s8.533333 46.933333 25.6 64c17.066667 17.066667 38.4 25.6 64 25.6h17.066667c0 34.133333 8.533333 64 21.333333 98.133333 12.8 29.866667 29.866667 55.466667 55.466667 76.8-17.066667 8.533333-38.4 17.066667-55.466667 25.6-4.266667 0-12.8 4.266667-12.8 8.533333-34.133333 21.333333-64 42.666667-89.6 72.533334-64 64-106.666667 140.8-128 230.4-4.266667 21.333333 0 42.666667 12.8 59.733333 8.533333 12.8 29.866667 21.333333 51.2 21.333333h776.533334c21.333333 0 42.666667-8.533333 55.466666-25.6s17.066667-38.4 12.8-59.733333zM465.066667 72.533333c17.066667-4.266667 29.866667-4.266667 46.933333-4.266666s29.866667 0 46.933333 4.266666v76.8c0 29.866667-17.066667 46.933333-46.933333 46.933334-29.866667 0-46.933333-17.066667-46.933333-46.933334V72.533333zM315.733333 908.8l-38.4-221.866667 81.066667-51.2 46.933333 264.533334v4.266666H315.733333z m76.8-409.6c-29.866667-29.866667-46.933333-68.266667-46.933333-110.933333h332.8c0 42.666667-17.066667 81.066667-51.2 110.933333-34.133333 34.133333-72.533333 46.933333-119.466667 46.933333s-81.066667-12.8-115.2-46.933333z m320 409.6h-89.6v-4.266667l46.933334-264.533333 81.066666 51.2-38.4 217.6z" p-id="53276" fill="#87c38f"></path></svg>`,Si=`<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1781346936424" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="71834" width="28" height="28" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M810.6496 896l42.7008 85.2992H170.6496l42.7008-85.2992h597.2992zM698.88 42.6496a170.6496 170.6496 0 0 1 169.8304 153.7024l27.2896 272.9472V768a85.3504 85.3504 0 0 1-85.3504 85.2992H213.3504A85.3504 85.3504 0 0 1 128 768V469.2992l27.2896-272.9472A170.6496 170.6496 0 0 1 325.12 42.6496h373.76z m5.12 469.3504a64 64 0 1 0 0 128 64 64 0 0 0 0-128z m-384 0a64 64 0 1 0 0 128 64 64 0 0 0 0-128z m392.5504-298.7008H311.4496L298.6496 384h426.7008l-12.8-170.7008z" p-id="71835" fill="#1296db"></path></svg>`,Ci=`<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1781410414799" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="75688" width="40" height="40" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M955.076923 556.882708h31.413169v1.102769a31.507692 31.507692 0 0 1 12.067446 60.652308 31.507692 31.507692 0 0 1-12.067446 2.394584h-50.365046l-75.712984 57.296739c0 11.689354-14.036677 21.047138-31.523447 21.047138h-5.781661a94.570338 94.570338 0 1 1-177.435569 0H382.188308a94.570338 94.570338 0 1 1-177.43557 0h-5.781661c-17.360738 0-31.507692-9.468062-31.507692-21.047138l-75.618462-57.659077H41.3696a31.507692 31.507692 0 1 1 0-63.046893h63.645538a29.128862 29.128862 0 0 1-0.031507-0.598646h850.093292v-0.157538z m-48.380061-31.365908l-111.300924-153.017108a31.397415 31.397415 0 0 0-29.428184-19.692307h-125.952a31.507692 31.507692 0 0 0-20.6848 7.750892L581.632 393.531077l-105.393231-139.264a31.507692 31.507692 0 0 0-33.870769-11.074954l-252.030031 73.885539a31.523446 31.523446 0 0 0-22.291692 24.623261L113.0496 525.5168h793.647262zM319.645538 747.267938a31.507692 31.507692 0 0 0 5.277539-17.486769h-0.362339a31.507692 31.507692 0 0 0-31.507692-31.507692 31.523446 31.523446 0 1 0 26.592492 48.994461z m441.01317 0.047262a31.523446 31.523446 0 1 0-52.4288-35.036554 31.523446 31.523446 0 0 0 52.4288 35.036554z" fill="#e0620d" p-id="75689"></path></svg>`,wi=`<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1781411158072" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="77161" xmlns:xlink="http://www.w3.org/1999/xlink" width="40" height="40"><path d="M492.32 658.752c131.2 2.176 264.128 0 395.264 0 34.656 0 56.448-32 64.96-72.96 3.008-13.76 4.704-28.672 4.704-43.648 0-14.944-1.696-29.472-4.288-43.136-8.544-39.712-29.888-70.944-65.376-70.944h-71.328c-0.448-17.92 0-36.352 0-54.72 0.448-25.184 0.864-50.4 0-75.168a19.2 19.2 0 0 0-19.648-18.816h-0.864a4456 4456 0 0 0-129.024 0H610.24c-7.68 0-14.08 4.288-17.024 10.688-25.28 40.576-58.144 97.856-85.92 147.008-6.016 10.24-11.52 20.064-17.088 29.888-12.8-17.536-26.976-37.6-41.472-57.696-21.792-30.752-43.968-61.088-58.912-81.6-17.12-22.656-34.24-32.864-53.44-31.2-17.504 1.28-34.176 12.832-52.096 33.76l-99.136 114.944a19.84 19.84 0 0 0-0.896 23.936c6.016 8.96 10.272 16.672 14.976 24.768 7.296 12.832 14.976 25.664 28.16 44a19.04 19.04 0 0 0 26.528 4.288 30.08 30.08 0 0 0 5.12-5.12c8.992-11.52 15.808-20.064 22.656-28.672 15.36-19.616 31.168-39.264 47.808-59.328 4.736-5.984 3.872-10.24 5.152-9.44 5.12 2.56 14.112 15.392 27.776 36.8l113.664 173.888a19.52 19.52 0 0 0 16.192 8.48zM147.136 484.896c-54.272 47.008-95.68 103.008-79.904 178.592a145.44 145.44 0 0 0 32.032 64.544c14.944 18.784 35.04 33.728 57.728 44.448 60.192 27.296 141.44 23.072 219.2-39.776a19.456 19.456 0 0 0 2.976-26.912 19.136 19.136 0 0 0-11.552-6.848c-41.44-8.96-73.504-20.064-95.744-38.848-21.344-17.984-34.592-44.416-40.576-84.224a15.872 15.872 0 0 0-3.424-8.48l-51.68-79.04a18.784 18.784 0 0 0-29.056-3.456zM448 784a80 80 0 0 1 80-80h352a80 80 0 0 1 0 160h-352a80 80 0 0 1-80-80z" fill="#8992c8" p-id="77162" class="selected"></path></svg>`;function X(e,t,n){return`url(data:image/svg+xml,${encodeURIComponent(e)}) ${t} ${n}, auto`}var Ti=new Image;Ti.src=`data:image/svg+xml,${encodeURIComponent(hi)}`;function Ei(e,t){let n=t/2,r=t/2;e.fillStyle=`rgba(218, 217, 217, 0.99)`,e.fillRect(0,r-1,t,3),e.fillRect(n-1,0,3,t)}var Di={default:{type:`css`,value:`default`},pointer:{type:`css`,value:`pointer`},crosshair:{type:`css`,value:`crosshair`},grab:{type:`css`,value:`grab`},grabbing:{type:`css`,value:`grabbing`},move:{type:`css`,value:`move`},none:{type:`css`,value:`none`},text:{type:`css`,value:`text`},ctc:{type:`canvas`,draw:Ei,size:25,hotspot:{x:12,y:12}},cable:{type:`css`,value:X(mi,20,50)},worker:{type:`css`,value:X(gi,50,50)},chewu:{type:`css`,value:X(_i,50,50)},gongwu:{type:`css`,value:X(vi,50,50)},gongdian:{type:`css`,value:X(yi,50,50)},dianwu:{type:`css`,value:X(bi,50,50)},fanghu:{type:`css`,value:X(xi,50,50)},loco:{type:`css`,value:X(Si,50,50)},flatbed:{type:`css`,value:X(Ci,50,50)},excavator:{type:`css`,value:X(wi,50,50)}},Oi=class{canvas;_current=`default`;constructor(e){this.canvas=e.getCanvas()}use(e,t){if(e===`text`&&t){this.createTextCursor(t),this._current=e;return}let n=Di[e];n&&(n.type===`css`?(this.canvas.style.cursor=n.value,this._current=e):(this.applyCanvasCursor(n.draw,n.size,n.hotspot),this._current=e))}setCursor(e){e.canvasDraw?this.applyCanvasCursor(e.canvasDraw,e.size??32,e.hotspot??{x:16,y:16}):e.imageUrl&&this.applyImageCursor(e.imageUrl,e.hotspot)}reset(){this.use(`default`)}get current(){return this._current}createTextCursor(e){let t=e.length>12?e.slice(0,12)+`…`:e,n=document.createElement(`canvas`),r=n.getContext(`2d`);r.font=`bold 12px sans-serif`;let i=r.measureText(t).width+12;n.width=26+i+1,n.height=24,r.drawImage(Ti,1,1,22,22),r.fillStyle=`rgba(0,0,0,0.78)`,r.beginPath(),r.moveTo(30,3),r.lineTo(26+i-4,3),r.quadraticCurveTo(26+i,3,26+i,7),r.lineTo(26+i,17),r.quadraticCurveTo(26+i,21,26+i-4,21),r.lineTo(30,21),r.quadraticCurveTo(26,21,26,17),r.lineTo(26,7),r.quadraticCurveTo(26,3,30,3),r.fill(),r.font=`bold 12px sans-serif`,r.fillStyle=`#fff`,r.textBaseline=`middle`,r.textAlign=`center`,r.fillText(t,26+i/2,12),this.applyImageCursor(n.toDataURL(`image/png`),{x:0,y:0})}applyImageCursor(e,t){let n=t?.x??0,r=t?.y??0;this.canvas.style.cursor=`url(${e}) ${n} ${r}, auto`}applyCanvasCursor(e,t,n){let r=document.createElement(`canvas`);r.width=t,r.height=t,e(r.getContext(`2d`),t),this.applyImageCursor(r.toDataURL(`image/png`),n)}},ki=[{type:`worker`,iconId:`icon_worker`,color:`#707070`,svgPath:`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='1781413096158'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='38813'%20width='32'%20height='32'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3cpath%20d='M770.56%20343.488c-9.984%2093.888-72.64%20194.176-157.184%20241.536l1.984-2.56c-23.552%2026.304-17.152%2048.576%2019.2%2066.752C858.176%20683.584%201024%20809.664%201024%20960c0%2075.328-727.424%2076.16-956.096%2030.336C25.28%20981.76%200%20971.52%200%20960c0-149.376%20163.776-274.88%20385.28-310.144l-2.368%201.28c42.24-20.032%2051.84-41.984%2028.8-65.92C327.552%20538.048%20265.984%20437.568%20256%20343.488h514.56zM512%200c136%200%20274.176%20106.048%20284.48%20240h3.52a32%2032%200%201%201%200%2064h-576a32%2032%200%201%201%200-64h16.128C249.536%20106.048%20376%200%20512%200z'%20fill='%23707070'%20p-id='38814'%3e%3c/path%3e%3c/svg%3e`},{type:`gongwu`,iconId:`icon_gongwu`,color:`#4CAF50`,svgPath:`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='1781412204514'%20class='icon'%20viewBox='0%200%201049%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='15838'%20width='32.78125'%20height='32'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3cpath%20d='M573.540453%20699.171348c-17.241629-6.05787-33.45808-13.140917-49.488135-18.639599-2.050356-1.025178-59.646716-21.155945-30.289348-111.278404l1.025178-2.982336%202.982336-3.075534c46.598997-48.556155%2086.021748-98.044289%2090.12246-208.390713H206.340358c2.982336%20111.837592%2042.498285%20161.791717%2089.004084%20209.322693l1.957158%202.050356%201.025177%202.982336c26.375032%2065.238596-13.140917%20102.517793-37.279197%20111.278404h-1.025178C134.577903%20725.54638%200%20805.417061%200%20874.19718v30.289348c0%2076.888345%20141.66095%20119.38663%20397.489443%20119.38663a1365.350606%201365.350606%200%200%200%20222.556808-15.191273%20254.710116%20254.710116%200%200%201-77.820324-184.066038A263.750322%20263.750322%200%200%201%20573.540453%20699.171348zM641.295394%20253.125751c-7.083048-1.957158-26.281834-7.083048-26.281834-27.307013%200-77.913523-51.631688-146.600444-129.452013-174.932634-9.319799%2023.299498-23.299498%2087.978906-33.45808%20143.618109l-31.314526-2.982336V9.319799c0-5.032692-2.982336-9.319799-7.083047-9.319799h-36.440416a9.319799%209.319799%200%200%200-7.176245%209.319799v182.015682l-33.364882%203.075534a1316.980847%201316.980847%200%200%200-33.45808-143.618108C225.352748%2078.006721%20174.746238%20146.880038%20174.746238%20225.72554c0%2019.198787-17.241629%2025.256656-25.256656%2027.307013-11.183759%202.982336-25.256656%207.083048-27.959398%2045.48062h548.936182c-3.821118-39.329553-17.055233-42.405087-29.170972-45.387422z'%20p-id='15839'%20fill='%234CAF50'%3e%3c/path%3e%3cpath%20d='M1024.24595%20641.108998l-23.113103%2023.2063a63.374636%2063.374636%200%200%201-89.563272-89.65647l22.740311-23.2063c12.861323-12.768125%204.287108-27.959398-18.639599-24.324676a115.845106%20115.845106%200%200%200-95.155151%20138.678614L626.756507%20860.310679a63.374636%2063.374636%200%201%200%2089.470074%2089.65647l193.851826-194.504213a115.751908%20115.751908%200%200%200%20138.492219-95.527943c3.541524-23.019904-11.556551-31.59412-24.324676-18.639599zM685.937233%20920.050593a21.062747%2021.062747%200%201%201%200-29.823358%2020.969549%2020.969549%200%200%201%200%2029.823358z%20m-21.062747-275.120477l73.067227%2073.253623%2029.916556-29.823358-73.160425-73.253623-16.402847-31.407724-52.190876-37.279198-29.916556%2029.823358%2037.279197%2052.284075zM909.612417%20800.384369a10.438175%2010.438175%200%200%200-14.911679%200l-44.828234%2044.828235a10.531373%2010.531373%200%200%200%200%2014.911679l105.593326%20105.686525a42.24665%2042.24665%200%200%200%2059.739914-59.739914z'%20p-id='15840'%20fill='%234CAF50'%3e%3c/path%3e%3c/svg%3e`},{type:`gongdian`,iconId:`icon_gongdian`,color:`#FF9800`,svgPath:`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='1781412389454'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='19959'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='32'%20height='32'%3e%3cpath%20d='M551.216148%20731.115158a245.716122%20245.716122%200%200%200%2055.944296%20240.231387H38.941911c-17.551152%200-30.166042-3.839314-34.005356-8.227102s-7.130155-15.357258%200-29.617568c6.033208-49.362614%2014.808784-100.919122%2025.778254-150.281736a44.974826%2044.974826%200%200%201%2034.005356-38.393144l83.916444-26.875201%20106.403856-32.908409c10.420996-3.839314%2014.808784-2.193894%2019.196572%204.387788a194.708088%20194.708088%200%200%200%20157.960365%2080.625603%20201.838243%20201.838243%200%200%200%20119.018746-38.941618zM285.206507%2076.786288a267.106588%20267.106588%200%200%200-103.113015%20178.253883v3.839315c0%206.581682%200%2014.808784-6.581682%2019.196572-17.002678%2017.002678-17.002678%2036.19925-17.002678%2059.78361v25.778254a31.811462%2031.811462%200%200%200%201.64542%2012.61489%202544.916979%202544.916979%200%200%200%20274.236744%2015.357258%202542.723085%202542.723085%200%200%200%20273.688269-15.357258%2022.487413%2022.487413%200%200%201%202.193894-10.420996v-10.96947c1.64542-25.22978%203.290841-48.81414-10.969469-69.107659a67.462239%2067.462239%200%200%201-12.61489-31.811463%20269.848956%20269.848956%200%200%200-96.531334-173.317621%2025.778254%2025.778254%200%200%200-8.227102-7.130156c-0.548473%201.64542-0.548473%203.290841-1.645421%204.387788s-0.548473%203.290841-1.096947%204.936262A914.305303%20914.305303%200%200%201%20532.56805%20251.200857l-19.196572-2.193894v-21.938939a375.704339%20375.704339%200%200%201%208.775575-55.395823c6.033208-41.135512%2012.61489-83.916443%2014.808785-123.955008a28.520621%2028.520621%200%200%200-21.390466-32.359935A259.976433%20259.976433%200%200%200%20387.771049%203.290841C325.245072%2014.260311%20323.051178%2016.454205%20330.181333%2081.174076a21.390466%2021.390466%200%200%200%201.096947%208.227102%2041.683985%2041.683985%200%200%201%200.548473%208.227103l22.487413%20148.087841-19.745045%204.387788c-23.58436-49.362614-36.19925-108.049277-48.81414-167.832887z%20m147.539368%20361.992502c-76.786288%200-153.024103-3.839314-228.713444-10.96947v1.64542l1.645421%209.32405c4.387788%2036.19925%2010.420996%2072.3985%2038.393144%2097.62828a38.941618%2038.941618%200%200%201%208.775575%2017.002678%20264.912694%20264.912694%200%200%200%20112.985539%20137.118372%20125.051955%20125.051955%200%200%200%20126.697375%206.033208%20254.491698%20254.491698%200%200%200%20123.406535-139.312265v-3.839315a40.587038%2040.587038%200%200%201%208.775575-14.808784c31.811462-27.972148%2036.19925-68.010712%2040.587039-109.146224a268.203535%20268.203535%200%200%201-36.199251%202.742368H620.323808c-57.589716%204.936261-121.761114%207.130155-187.577933%207.130155z'%20p-id='19960'%20fill='%23FF9800'%3e%3c/path%3e%3cpath%20d='M792.544482%20563.282271a230.358864%20230.358864%200%201%200%20230.358865%20230.358865%20230.358864%20230.358864%200%200%200-230.358865-230.358865z%20m-15.357257%20428.357793h-8.227102l16.454204-159.605784-96.531334-38.393144%20121.212641-197.998929v8.227102l-7.678629%20150.830209%2093.788966%2038.941618z'%20p-id='19961'%20fill='%23FF9800'%3e%3c/path%3e%3c/svg%3e`},{type:`dianwu`,iconId:`icon_dianwu`,color:`#d81e06`,svgPath:`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='1781414010736'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='48244'%20width='50'%20height='50'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3cpath%20d='M433.32%20232.3m-159.61%200a159.61%20159.61%200%201%200%20319.22%200%20159.61%20159.61%200%201%200-319.22%200Z'%20fill='%23d81e06'%20p-id='48245'%3e%3c/path%3e%3cpath%20d='M501.7%20629.08c-1.46-96.26%2040.84-149.17%2068.44-173.42-41.82-18.74-88.04-29.39-136.83-29.39C248.13%20426.27%2098%20576.39%2098%20761.58h458.42c-32.8-37.02-53.98-83.92-54.72-132.5zM763.46%20654.45c-38.84%200-70.47-31.62-70.47-70.47%200-38.84%2031.62-70.47%2070.47-70.47s70.47%2031.62%2070.47%2070.47c0%2038.84-31.62%2070.47-70.47%2070.47z%20m0-115.15c-24.64%200-44.68%2020.04-44.68%2044.68s20.04%2044.68%2044.68%2044.68%2044.68-20.04%2044.68-44.68-20.04-44.68-44.68-44.68z'%20fill='%23d81e06'%20p-id='48246'%3e%3c/path%3e%3cpath%20d='M679.74%20686.44c-33.91-26.15-53.38-65.73-53.38-108.6%200-42.77%2019.47-82.28%2053.38-108.44l21.02%2027.19c-25.45%2019.61-40.02%2049.22-40.02%2081.24%200%2032.13%2014.57%2061.81%2040.02%2081.41l-21.02%2027.2z'%20fill='%23d81e06'%20p-id='48247'%3e%3c/path%3e%3cpath%20d='M683.06%20752.41c-67.85-31.26-111.66-99.77-111.66-174.57%200-74.7%2043.81-143.15%20111.66-174.4l14.37%2031.22c-55.66%2025.65-91.65%2081.85-91.65%20143.18%200%2061.44%2035.99%20117.7%2091.65%20143.35l-14.37%2031.22zM847.12%20686.47l-20.95-27.26c25.41-19.57%2040.02-49.25%2040.02-81.38%200-32.03-14.6-61.64-40.02-81.21l20.95-27.26c33.97%2026.15%2053.45%2065.7%2053.45%20108.47%200%2042.88-19.47%2082.49-53.45%20108.64z'%20fill='%23d81e06'%20p-id='48248'%3e%3c/path%3e%3cpath%20d='M843.83%20752.41l-14.37-31.22c55.66-25.65%2091.65-81.91%2091.65-143.35%200-61.34-35.99-117.53-91.65-143.18l14.37-31.22c67.85%2031.26%20111.66%2099.71%20111.66%20174.4%200%2074.79-43.81%20143.31-111.66%20174.57zM763.46%20610.43c-14.6%200-26.49-11.85-26.49-26.45s11.88-26.49%2026.49-26.49%2026.45%2011.88%2026.45%2026.49-11.84%2026.45-26.45%2026.45z%20m0-35.75c-5.14%200-9.3%204.16-9.3%209.3%200%205.1%204.16%209.27%209.3%209.27%205.1%200%209.27-4.16%209.27-9.27%200-5.14-4.16-9.3-9.27-9.3zM752.48%20643.24h21.95v141.68h-21.95z'%20fill='%23d81e06'%20p-id='48249'%3e%3c/path%3e%3c/svg%3e`},{type:`chewu`,iconId:`icon_chewu`,color:`#1296db`,svgPath:`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='1781413291157'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='47319'%20width='48'%20height='48'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3cpath%20d='M711.210667%20344.917333l-294.101334%2025.770667a387.584%20387.584%200%200%201%203.584-75.818667c95.36%2017.493333%20191.914667%2027.989333%20288.810667%2031.445334V267.562667c-145.621333-8.96-270.421333-106.965333-270.421333-106.965334A190.976%20190.976%200%200%200%20290.602667%20110.933333c-33.578667%201.706667-65.365333%2015.786667-89.301334%2039.424a651.946667%20651.946667%200%200%200-91.392%20120.789334c-31.317333%2051.029333-44.8%20106.368-17.664%20165.162666%208.661333%2018.432%2019.413333%2035.84%2032.042667%2051.797334%202.858667%203.413333%2012.714667%2018.944%2017.28%2018.944-26.88%2017.322667-52.736%2036.053333-77.568%2056.149333h60.672s39.68-29.781333%2079.445333-54.272l81.365334%201.706667c-17.237333%2012.928-53.845333%2040.618667-81.152%2066.005333H264.96s113.792-84.181333%20208.597333-103.338667l-9.685333%201.706667C652.074667%20421.546667%20710.442667%20418.133333%20710.442667%20418.133333l0.768-73.216zM102.826667%20332.8c0-13.653333%2016.896-24.661333%2037.930666-24.661333s37.930667%2011.008%2037.930667%2024.661333c0%2013.653333-16.896%2024.618667-37.930667%2024.618667s-37.930667-10.965333-37.930666-24.618667z%20m144.896-107.52l-75.861334-4.010667s33.92-52.693333%2044.757334-56.106666l46.848%200.938666-15.786667%2059.178667z%20m34.304-56.917333l65.792%202.133333v59.306667L268.8%20226.602667l13.269333-58.24z%20m35.456%20140.16c20.906667%200%2037.973333%2010.965333%2037.973333%2024.618666%200%2013.653333-16.896%2024.661333-37.973333%2024.661334-21.034667%200-37.930667-11.008-37.930667-24.661334%200-13.653333%2016.896-24.618667%2037.973333-24.618666z'%20fill='%231296db'%20p-id='47320'%3e%3c/path%3e%3cpath%20d='M653.098667%20257.450667a190.634667%20190.634667%200%200%200-190.421334%20190.378666%20190.634667%20190.634667%200%200%200%20190.421334%20190.378667%20190.677333%20190.677333%200%200%200%20190.421333-190.378667%20190.634667%20190.634667%200%200%200-190.421333-190.378666z'%20fill='%231296db'%20p-id='47321'%3e%3c/path%3e%3cpath%20d='M799.829333%20633.856c-40.533333%2032.085333-91.093333%2051.968-146.773333%2051.968-55.637333%200-106.112-19.925333-146.773333-51.968-76.970667%2049.066667-130.56%20135.082667-137.941334%20234.794667%2026.965333%203.626667%2074.922667%207.594667%20143.36%207.594666h282.666667c68.48%200%20116.48-3.968%20143.445333-7.594666-7.296-99.754667-60.885333-185.770667-137.984-234.794667z'%20fill='%231296db'%20p-id='47322'%3e%3c/path%3e%3c/svg%3e`},{type:`fanghu`,iconId:`icon_fanghu`,color:`#87c38f`,svgPath:`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='1781414908820'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='53275'%20width='36'%20height='36'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3cpath%20d='M968.533333%20896c-21.333333-89.6-68.266667-166.4-132.266666-230.4-25.6-25.6-55.466667-51.2-85.333334-68.266667-4.266667-4.266667-8.533333-8.533333-17.066666-8.533333-17.066667-8.533333-34.133333-17.066667-55.466667-25.6%2021.333333-21.333333%2042.666667-46.933333%2055.466667-76.8%2012.8-29.866667%2021.333333-64%2021.333333-98.133333H768c25.6%200%2046.933333-8.533333%2064-25.6%2017.066667-17.066667%2025.6-38.4%2025.6-64s-8.533333-46.933333-25.6-64c-21.333333-17.066667-42.666667-25.6-64-25.6h-21.333333c-17.066667-51.2-46.933333-89.6-85.333334-119.466667C614.4%2055.466667%20567.466667%2042.666667%20512%2042.666667c-55.466667%200-102.4%2017.066667-145.066667%2046.933333-42.666667%2029.866667-72.533333%2072.533333-85.333333%20119.466667h-29.866667c-25.6%200-46.933333%208.533333-64%2025.6-17.066667%2017.066667-25.6%2038.4-25.6%2064s8.533333%2046.933333%2025.6%2064c17.066667%2017.066667%2038.4%2025.6%2064%2025.6h17.066667c0%2034.133333%208.533333%2064%2021.333333%2098.133333%2012.8%2029.866667%2029.866667%2055.466667%2055.466667%2076.8-17.066667%208.533333-38.4%2017.066667-55.466667%2025.6-4.266667%200-12.8%204.266667-12.8%208.533333-34.133333%2021.333333-64%2042.666667-89.6%2072.533334-64%2064-106.666667%20140.8-128%20230.4-4.266667%2021.333333%200%2042.666667%2012.8%2059.733333%208.533333%2012.8%2029.866667%2021.333333%2051.2%2021.333333h776.533334c21.333333%200%2042.666667-8.533333%2055.466666-25.6s17.066667-38.4%2012.8-59.733333zM465.066667%2072.533333c17.066667-4.266667%2029.866667-4.266667%2046.933333-4.266666s29.866667%200%2046.933333%204.266666v76.8c0%2029.866667-17.066667%2046.933333-46.933333%2046.933334-29.866667%200-46.933333-17.066667-46.933333-46.933334V72.533333zM315.733333%20908.8l-38.4-221.866667%2081.066667-51.2%2046.933333%20264.533334v4.266666H315.733333z%20m76.8-409.6c-29.866667-29.866667-46.933333-68.266667-46.933333-110.933333h332.8c0%2042.666667-17.066667%2081.066667-51.2%20110.933333-34.133333%2034.133333-72.533333%2046.933333-119.466667%2046.933333s-81.066667-12.8-115.2-46.933333z%20m320%20409.6h-89.6v-4.266667l46.933334-264.533333%2081.066666%2051.2-38.4%20217.6z'%20p-id='53276'%20fill='%2387c38f'%3e%3c/path%3e%3c/svg%3e`},{type:`loco`,iconId:`icon_loco`,color:`#1E90FF`,svgPath:`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='1781346936424'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='71834'%20width='28'%20height='28'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3cpath%20d='M810.6496%20896l42.7008%2085.2992H170.6496l42.7008-85.2992h597.2992zM698.88%2042.6496a170.6496%20170.6496%200%200%201%20169.8304%20153.7024l27.2896%20272.9472V768a85.3504%2085.3504%200%200%201-85.3504%2085.2992H213.3504A85.3504%2085.3504%200%200%201%20128%20768V469.2992l27.2896-272.9472A170.6496%20170.6496%200%200%201%20325.12%2042.6496h373.76z%20m5.12%20469.3504a64%2064%200%201%200%200%20128%2064%2064%200%200%200%200-128z%20m-384%200a64%2064%200%201%200%200%20128%2064%2064%200%200%200%200-128z%20m392.5504-298.7008H311.4496L298.6496%20384h426.7008l-12.8-170.7008z'%20p-id='71835'%20fill='%231296db'%3e%3c/path%3e%3c/svg%3e`},{type:`flatbed`,iconId:`icon_flatbed`,color:`#FFA500`,svgPath:`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='1781410414799'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='75688'%20width='40'%20height='40'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3cpath%20d='M955.076923%20556.882708h31.413169v1.102769a31.507692%2031.507692%200%200%201%2012.067446%2060.652308%2031.507692%2031.507692%200%200%201-12.067446%202.394584h-50.365046l-75.712984%2057.296739c0%2011.689354-14.036677%2021.047138-31.523447%2021.047138h-5.781661a94.570338%2094.570338%200%201%201-177.435569%200H382.188308a94.570338%2094.570338%200%201%201-177.43557%200h-5.781661c-17.360738%200-31.507692-9.468062-31.507692-21.047138l-75.618462-57.659077H41.3696a31.507692%2031.507692%200%201%201%200-63.046893h63.645538a29.128862%2029.128862%200%200%201-0.031507-0.598646h850.093292v-0.157538z%20m-48.380061-31.365908l-111.300924-153.017108a31.397415%2031.397415%200%200%200-29.428184-19.692307h-125.952a31.507692%2031.507692%200%200%200-20.6848%207.750892L581.632%20393.531077l-105.393231-139.264a31.507692%2031.507692%200%200%200-33.870769-11.074954l-252.030031%2073.885539a31.523446%2031.523446%200%200%200-22.291692%2024.623261L113.0496%20525.5168h793.647262zM319.645538%20747.267938a31.507692%2031.507692%200%200%200%205.277539-17.486769h-0.362339a31.507692%2031.507692%200%200%200-31.507692-31.507692%2031.523446%2031.523446%200%201%200%2026.592492%2048.994461z%20m441.01317%200.047262a31.523446%2031.523446%200%201%200-52.4288-35.036554%2031.523446%2031.523446%200%200%200%2052.4288%2035.036554z'%20fill='%23e0620d'%20p-id='75689'%3e%3c/path%3e%3c/svg%3e`},{type:`excavator`,iconId:`icon_excavator`,color:`#8992c8`,svgPath:`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='1781411158072'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='77161'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='40'%20height='40'%3e%3cpath%20d='M492.32%20658.752c131.2%202.176%20264.128%200%20395.264%200%2034.656%200%2056.448-32%2064.96-72.96%203.008-13.76%204.704-28.672%204.704-43.648%200-14.944-1.696-29.472-4.288-43.136-8.544-39.712-29.888-70.944-65.376-70.944h-71.328c-0.448-17.92%200-36.352%200-54.72%200.448-25.184%200.864-50.4%200-75.168a19.2%2019.2%200%200%200-19.648-18.816h-0.864a4456%204456%200%200%200-129.024%200H610.24c-7.68%200-14.08%204.288-17.024%2010.688-25.28%2040.576-58.144%2097.856-85.92%20147.008-6.016%2010.24-11.52%2020.064-17.088%2029.888-12.8-17.536-26.976-37.6-41.472-57.696-21.792-30.752-43.968-61.088-58.912-81.6-17.12-22.656-34.24-32.864-53.44-31.2-17.504%201.28-34.176%2012.832-52.096%2033.76l-99.136%20114.944a19.84%2019.84%200%200%200-0.896%2023.936c6.016%208.96%2010.272%2016.672%2014.976%2024.768%207.296%2012.832%2014.976%2025.664%2028.16%2044a19.04%2019.04%200%200%200%2026.528%204.288%2030.08%2030.08%200%200%200%205.12-5.12c8.992-11.52%2015.808-20.064%2022.656-28.672%2015.36-19.616%2031.168-39.264%2047.808-59.328%204.736-5.984%203.872-10.24%205.152-9.44%205.12%202.56%2014.112%2015.392%2027.776%2036.8l113.664%20173.888a19.52%2019.52%200%200%200%2016.192%208.48zM147.136%20484.896c-54.272%2047.008-95.68%20103.008-79.904%20178.592a145.44%20145.44%200%200%200%2032.032%2064.544c14.944%2018.784%2035.04%2033.728%2057.728%2044.448%2060.192%2027.296%20141.44%2023.072%20219.2-39.776a19.456%2019.456%200%200%200%202.976-26.912%2019.136%2019.136%200%200%200-11.552-6.848c-41.44-8.96-73.504-20.064-95.744-38.848-21.344-17.984-34.592-44.416-40.576-84.224a15.872%2015.872%200%200%200-3.424-8.48l-51.68-79.04a18.784%2018.784%200%200%200-29.056-3.456zM448%20784a80%2080%200%200%201%2080-80h352a80%2080%200%200%201%200%20160h-352a80%2080%200%200%201-80-80z'%20fill='%238992c8'%20p-id='77162'%20class='selected'%3e%3c/path%3e%3c/svg%3e`}];function Ai(e){let t=`geojson_${e}`;this.addGeoJsonSource(t);for(let n of ki){let r=`${e}_${n.type}_line`,i=`${e}_${n.type}_point`,a=[`all`,[`==`,[`get`,`type`],n.type],[`==`,[`geometry-type`],`LineString`]],o=[`all`,[`==`,[`get`,`type`],n.type],[`==`,[`geometry-type`],`Point`]];this.map.getLayer(r)||this.map.addLayer({id:r,type:`line`,source:t,filter:a,paint:{"line-color":n.color,"line-width":2}});let s=()=>{this.map.getLayer(i)||this.map.addLayer({id:i,type:`symbol`,source:t,filter:o,layout:{"icon-image":n.iconId,"icon-size":.8,"icon-allow-overlap":!0,"icon-anchor":`bottom`,"text-field":[`get`,`content`],"text-size":12,"text-offset":[0,1],"text-allow-overlap":!0},paint:{"text-color":`#000000`,"text-halo-color":n.color,"text-halo-width":2}})};if(this.map.hasImage(n.iconId))s();else{let e=new Image;e.onload=()=>{this.map.hasImage(n.iconId)||(this.map.addImage(n.iconId,e),s())},e.src=n.svgPath}}}var Z=6371008.8;Z*100,Z*100,360/(2*Math.PI),Z*3.28084,Z*39.37,Z/1e3,Z/1e3,Z/1609.344,Z*1e3,Z*1e3,Z/1852,Z*1.0936;function ji(e,t,n={}){let r={type:`Feature`};return(n.id===0||n.id)&&(r.id=n.id),n.bbox&&(r.bbox=n.bbox),r.properties=t||{},r.geometry=e,r}function Mi(e,t,n={}){if(!e)throw Error(`coordinates is required`);if(!Array.isArray(e))throw Error(`coordinates must be an Array`);if(e.length<2)throw Error(`coordinates must be at least 2 numbers long`);if(!Pi(e[0])||!Pi(e[1]))throw Error(`coordinates must contain numbers`);return ji({type:`Point`,coordinates:e},t,n)}function Ni(e,t,n={}){if(e.length<2)throw Error(`coordinates must be an array of two or more positions`);return ji({type:`LineString`,coordinates:e},t,n)}function Pi(e){return!isNaN(e)&&e!==null&&!Array.isArray(e)}var Fi=15,Ii=.2;function Li(e,t,n,i=Fi,a=Ii){let o=t.project(e),s=[[o.x-i*2,o.y-i*2],[o.x+i*2,o.y+i*2]],c=t.queryRenderedFeatures(s,{layers:n});if(c.length===0)return null;let l=Mi([e.lng,e.lat]),u=null,d=1/0;for(let e of c){let n=e.geometry;if(n.type===`Point`){let r=t.project(n.coordinates),i=Math.hypot(r.x-o.x,r.y-o.y)*a;i<d&&(d=i,u={lngLat:{lng:n.coordinates[0],lat:n.coordinates[1]},feature:e});continue}if(n.type!==`LineString`&&n.type!==`MultiLineString`)continue;let i=n.type===`LineString`?[n.coordinates]:n.coordinates;for(let n of i){if(n.length<2)continue;for(let r of n){let n=t.project([r[0],r[1]]),i=Math.hypot(n.x-o.x,n.y-o.y)*a;i<d&&(d=i,u={lngLat:{lng:r[0],lat:r[1]},feature:e})}let i=(0,r.nearestPointOnLine)(Ni(n),l),s=t.project([i.geometry.coordinates[0],i.geometry.coordinates[1]]),c=Math.hypot(s.x-o.x,s.y-o.y);c<d&&(d=c,u={lngLat:{lng:i.geometry.coordinates[0],lat:i.geometry.coordinates[1]},feature:e})}}return u&&d<=i?u:null}var Ri=class{map;snapMarker=null;layerIds=[];onClick=null;active=!1;thresholdPx=Fi;vertexBias=Ii;boundMouseMove;boundClick;constructor(e){this.map=e.map,this.boundMouseMove=this.onMouseMove.bind(this),this.boundClick=this.onClick_.bind(this)}start(e,t){this.active&&this.stop(),this.layerIds=Array.isArray(e)?e:[e],this.onClick=t,this.active=!0,this.map.on(`mousemove`,this.boundMouseMove),this.map.on(`click`,this.boundClick)}stop(){this.active=!1,this.snapMarker?.remove(),this.snapMarker=null,this.onClick=null,this.layerIds=[],this.map.off(`mousemove`,this.boundMouseMove),this.map.off(`click`,this.boundClick)}destroy(){this.stop()}getMarkerEl(e=`crosshair`){let t=document.createElement(`div`);return t.style.pointerEvents=`none`,e===`dot`?t.innerHTML=`<svg width="12" height="12" viewBox="0 0 12 12" style="display:block"><circle cx="6" cy="6" r="5" fill="#ff4d4f" stroke="#fff" stroke-width="1.5"/></svg>`:t.innerHTML=`<svg width="20" height="20" viewBox="0 0 20 20" style="display:block"><circle cx="10" cy="10" r="7" fill="none" stroke="#ff4d4f" stroke-width="2"/><line x1="10" y1="0" x2="10" y2="5" stroke="#ff4d4f" stroke-width="1.5"/><line x1="10" y1="15" x2="10" y2="20" stroke="#ff4d4f" stroke-width="1.5"/><line x1="0" y1="10" x2="5" y2="10" stroke="#ff4d4f" stroke-width="1.5"/><line x1="15" y1="10" x2="20" y2="10" stroke="#ff4d4f" stroke-width="1.5"/></svg>`,t}onMouseMove(e){if(!this.active||this.layerIds.length===0)return;let n=Li(e.lngLat,this.map,this.layerIds,this.thresholdPx,this.vertexBias);n?(this.snapMarker||=new t.default.Marker({element:this.getMarkerEl(`crosshair`),anchor:`center`}),this.snapMarker.setLngLat(n.lngLat).addTo(this.map)):this.snapMarker?.remove()}onClick_(e){if(!this.active||!this.onClick)return;let t=this.layerIds.length>0?Li(e.lngLat,this.map,this.layerIds,this.thresholdPx,this.vertexBias):null;this.onClick(t?t.lngLat:e.lngLat,t?.feature)}},zi=`draw-route-preview-source`,Bi=`draw-route-preview-layer`,Vi=class{map;active=!1;vertices=[];tempMarkers=[];onFinish=null;onStop=null;boundMouseMove;boundDblClick;boundContextMenu;constructor(e){this.map=e.map,this.boundMouseMove=this.onMouseMove.bind(this),this.boundDblClick=this.onDblClick.bind(this),this.boundContextMenu=this.onContextMenu.bind(this)}start(e,t){this.active&&this.stop(!1),this.active=!0,this.onFinish=e,this.onStop=t??null,this.vertices=[],this.ensurePreviewLayer(),this.map.on(`mousemove`,this.boundMouseMove),this.map.on(`dblclick`,this.boundDblClick),this.map.on(`contextmenu`,this.boundContextMenu)}stop(e=!0){if(this.active){if(e&&this.vertices.length>=2&&this.onFinish){let e=this.vertices.map(e=>[e.lng,e.lat]);this.onFinish({type:`Feature`,geometry:{type:`LineString`,coordinates:e},properties:{}})}this.active=!1,this.onFinish=null,this.onStop?.(),this.onStop=null,this.clearTempMarkers(),this.clearPreview(),this.removePreviewLayer(),this.map.off(`mousemove`,this.boundMouseMove),this.map.off(`dblclick`,this.boundDblClick),this.map.off(`contextmenu`,this.boundContextMenu)}}destroy(){this.stop(!1)}ensurePreviewLayer(){this.map.getSource(zi)||this.map.addSource(zi,{type:`geojson`,data:{type:`FeatureCollection`,features:[]}}),this.map.getLayer(Bi)||this.map.addLayer({id:Bi,type:`line`,source:zi,paint:{"line-color":`#ff4d4f`,"line-width":2,"line-dasharray":[4,2]}})}updatePreview(){let e=this.map.getSource(zi);if(!e)return;let t=this.vertices.map(e=>[e.lng,e.lat]);e.setData({type:`FeatureCollection`,features:t.length<2?[]:[{type:`Feature`,geometry:{type:`LineString`,coordinates:t},properties:{}}]})}clearPreview(){let e=this.map.getSource(zi);e&&e.setData({type:`FeatureCollection`,features:[]})}removePreviewLayer(){this.map.getLayer(Bi)&&this.map.removeLayer(Bi),this.map.getSource(zi)&&this.map.removeSource(zi)}addTempMarker(e){let n=new t.default.Marker({color:`#ff4d4f`,scale:.7}).setLngLat(e).addTo(this.map);this.tempMarkers.push(n)}clearTempMarkers(){this.tempMarkers.forEach(e=>e.remove()),this.tempMarkers=[]}onMouseMove(e){if(!this.active)return;let t=this.vertices.map(e=>[e.lng,e.lat]);t.push([e.lngLat.lng,e.lngLat.lat]);let n=this.map.getSource(zi);n&&n.setData({type:`FeatureCollection`,features:t.length<2?[]:[{type:`Feature`,geometry:{type:`LineString`,coordinates:t},properties:{}}]})}addVertex(e){this.active&&(this.vertices.push(e),this.addTempMarker(e),this.updatePreview())}onDblClick(){if(!this.active||this.vertices.length<2)return;let e=this.vertices.map(e=>[e.lng,e.lat]);this.onFinish?.({type:`Feature`,geometry:{type:`LineString`,coordinates:e},properties:{}}),this.clearTempMarkers(),this.clearPreview(),this.vertices=[]}onContextMenu(e){e.preventDefault();let t=this.vertices.map(e=>[e.lng,e.lat]);this.onFinish?.({type:`Feature`,geometry:{type:`LineString`,coordinates:t},properties:{}}),this.clearTempMarkers(),this.clearPreview(),this.vertices=[]}},Hi={signal:`信号机`,switch:`道岔`,track:`股道`,track_circuit:`股道电路`,sgfhqy_door:`通道门`},Ui=class{teeeMap;el=null;active=!1;queryLayers=[];currentFeature=null;onSelect;boundContextMenu;boundMapMove;constructor(e){this.teeeMap=e,this.boundContextMenu=this.onContextMenu.bind(this),this.boundMapMove=this.onMapMove.bind(this)}start(e,t){this.active&&this.stop(),this.active=!0,this.queryLayers=e,this.onSelect=t,this.teeeMap.map.on(`contextmenu`,this.boundContextMenu),this.teeeMap.map.on(`move`,this.boundMapMove)}stop(){this.active&&(this.active=!1,this.teeeMap.map.off(`contextmenu`,this.boundContextMenu),this.teeeMap.map.off(`move`,this.boundMapMove),this.remove())}destroy(){this.stop()}onContextMenu(e){e.preventDefault(),this.remove();let t=this.teeeMap.map.queryRenderedFeatures(e.point,{layers:this.queryLayers});if(!t.length){this.showLightMenu(e);return}let n=t[0];n.id!==void 0&&(this.currentFeature=n,this.teeeMap.ctcTool?.changeFeatureState(n.properties.code,{select:!0}),this.showFeatureMenu(e,n))}onMapMove(){this.el&&this.remove()}getViewportPos(e){let t=this.teeeMap.map.getContainer().getBoundingClientRect();return{x:t.left+e.point.x,y:t.top+e.point.y}}createContainer(e,t){let n=this.getViewportPos(e),r=document.createElement(`div`);r.className=`ctc-menu`,r.style.cssText=`position:fixed;z-index:9999;left:${n.x}px;top:${n.y}px;border-radius:2px;background:#fff;color:#000;font-size:13px;min-width:150px;`;let i=document.createElement(`div`);return i.style.cssText=`padding:8px;font-size:14px;font-weight:600;display:flex;justify-content:space-between;align-items:center;`,i.innerHTML=`${t}<span class="ctc-menu-close" style="cursor:pointer;font-size:18px;color:#999;line-height:1;">×</span>`,i.querySelector(`.ctc-menu-close`).addEventListener(`click`,()=>this.remove()),r.appendChild(i),r}addSplit(e){let t=document.createElement(`div`);t.style.cssText=`height:2px;background-color:#e4e4e4;`,e.appendChild(t)}addItem(e,t,n,r,i=!1){let a=document.createElement(`div`);a.style.cssText=`padding:2px 12px;text-align:left;cursor:pointer;white-space:nowrap;`,i&&(a.style.cssText+=`opacity:0.5;cursor:not-allowed;pointer-events:none;`),n?(a.style.cssText+=`font-weight:600;`,a.innerHTML=`✔ ${t}`):a.textContent=t,a.addEventListener(`mouseenter`,()=>{a.style.background=`#f2f2f2`}),a.addEventListener(`mouseleave`,()=>{a.style.background=``}),i||a.addEventListener(`click`,r),e.appendChild(a)}adjustPosition(e,t){let n=this.getViewportPos(t),r=e.getBoundingClientRect();r.right>window.innerWidth&&(e.style.left=`${n.x-r.width}px`),r.bottom>window.innerHeight&&(e.style.top=`${Math.max(0,n.y-r.height)}px`)}showFeatureMenu(e,t){let n=t.properties.code,r=De(n),i=t.properties.name||Hi[r]||``,a=this.createContainer(e,`${Hi[r]}: ${i}`);console.log(r,i);let o=t.state||{};switch(r){case`signal`:this.buildSignalMenu(a,t,o);break;case`switch`:this.buildSwitchMenu(a,t,o);break;case`track`:this.buildTrackMenu(a,t,o);break;case`track_circuit`:this.buildCircuitMenu(a,t,o);break;case`sgfhqy_door`:this.buildSgfhqyDoorMenu(a,t,o);break}document.body.appendChild(a),this.adjustPosition(a,e),this.el=a}emit(e,t){if(!this.currentFeature)return;let n={feature:this.currentFeature,featureType:De(this.currentFeature.properties.code),code:this.currentFeature.properties.code};t?(n.meta={pathType:t},n.featureType=`path`):n.state=e,this.remove(),this.onSelect?.(n)}getSignalMode(e){let t=e.properties.func_type,n=e.properties.attach||0;return t==1&&n==0?`TrainAndShunting`:(t==2||t==3)&&n==0?`Train`:(t==2||t==3||t==11)&&n==1?`TrainAndShunting`:(t==4||t==5||t==12)&&n==0?`Shunting`:t==6&&n==0?`Train`:(t==7||t==11)&&n==0?`TrainAndShunting`:``}getSignalDefaultSubState1(e){let t=e.properties.func_type,n=e.properties.attach;return t==1&&n==0||(t==2||t==3)&&n==0||(t==2||t==3||t==11)&&n==1?`blue`:(t==4||t==5||t==12)&&n==0?`green`:t==6&&n==0||(t==7||t==11)&&n==0?`blue`:`grey`}buildSignalMenu(e,t,n){let r=this.getSignalMode(t),i=r===`Train`||r===`TrainAndShunting`,a=r===`Shunting`||r===`TrainAndShunting`;this.addSplit(e),i&&(this.addItem(e,`列车红灯`,n.state===`red`,()=>this.emit({state:`red`}),!1),this.addItem(e,`列车绿灯`,n.state===`green`,()=>this.emit({state:`green`}),!1)),a&&(this.addItem(e,`调车白灯`,n.state===`white`,()=>this.emit({state:`white`})),this.addItem(e,`调车蓝灯`,n.state===`blue`,()=>this.emit({state:`blue`}),!1)),this.addSplit(e),a&&(this.addItem(e,`进路始端(调车)`,!1,()=>this.emit({},`srcSignal`)),this.addItem(e,`进路终端(调车)`,!1,()=>this.emit({},`destSignal`))),i&&(this.addItem(e,`进路始端(列车)`,!1,()=>this.emit({},`srcSignal`)),this.addItem(e,`进路终端(列车)`,!1,()=>this.emit({},`destSignal`))),this.addSplit(e);let o=n.subState1===`red`;this.addItem(e,`钮封`,o,()=>this.emit({subState1:`red`}));let s=this.getSignalDefaultSubState1(t);this.addItem(e,`解封`,!o,()=>this.emit({subState1:s})),this.addSplit(e);let c=n.subState2===`on`;this.addItem(e,`点灯`,c,()=>this.emit({subState2:`on`})),this.addItem(e,`灭灯`,n.subState2===`off`,()=>this.emit({subState2:`off`}))}buildSwitchMenu(e,t,n){this.addSplit(e),this.addItem(e,`定位`,n.state===`2`,()=>this.emit({state:`2`}),!1),this.addItem(e,`反位`,n.state===`3`,()=>this.emit({state:`3`}),!1),this.addItem(e,`四开`,n.state===`4`,()=>this.emit({state:`4`}),!1),this.addSplit(e);let r=n.subState1===`2`,i=n.subState1===`3`;this.addItem(e,`锁闭`,r,()=>this.emit({subState1:`2`})),this.addItem(e,`占用`,i,()=>this.emit({subState1:`3`})),this.addItem(e,`出清`,!n.subState1,()=>this.emit({subState1:``})),this.addSplit(e);let a=n.subState2===`1`;this.addItem(e,`单锁`,a,()=>this.emit({subState2:`1`})),this.addItem(e,`解锁`,!n.subState2,()=>this.emit({subState2:``})),this.addSplit(e);let o=n.subState3===`1`;this.addItem(e,`单封`,o,()=>this.emit({subState3:`1`})),this.addItem(e,`解封`,!n.subState3,()=>this.emit({subState3:``}))}buildTrackMenu(e,t,n){this.addSplit(e),this.addItem(e,`封锁`,n.state===`1`,()=>this.emit({state:`1`})),this.addItem(e,`停电`,n.state===`2`,()=>this.emit({state:`2`})),this.addItem(e,`无接触网`,n.state===`3`,()=>this.emit({state:`3`})),this.addItem(e,`临时限速`,!1,()=>{})}buildCircuitMenu(e,t,n){this.addSplit(e);let r=!n.subState1,i=n.subState1===`1`;this.addItem(e,`供电`,r,()=>this.emit({subState1:``})),this.addItem(e,`停电`,i,()=>this.emit({subState1:`1`}))}buildSgfhqyDoorMenu(e,t,n){this.addSplit(e),this.addItem(e,`施工开始开门`,n.state===`1`,()=>this.emit({state:`1`})),this.addItem(e,`施工结束关门`,n.state===`2`,()=>this.emit({state:`2`})),this.addItem(e,`施工临时开门`,n.state===`3`,()=>this.emit({state:`3`})),this.addItem(e,`施工临时关门`,n.state===`4`,()=>this.emit({state:`4`})),this.addSplit(e),this.addItem(e,`调度命令确认`,n.subState1===`1`,()=>this.emit({subState1:`1`})),this.addItem(e,`调度命令取消`,n.subState1===``,()=>this.emit({subState1:``})),this.addSplit(e),this.addItem(e,`进入申请确认`,n.subState2===`1`,()=>this.emit({subState2:`1`})),this.addItem(e,`进入申请取消`,n.subState2===``,()=>this.emit({subState2:``})),this.addSplit(e),this.addItem(e,`人员工机通道门号确认`,n.subState3===`1`,()=>this.emit({subState3:`1`})),this.addItem(e,`人员工机通道门号取消`,n.subState3===``,()=>this.emit({subState3:``}))}showLightMenu(e){let t=this.createContainer(e,`点灯操作`);this.addSplit(t),this.addItem(t,`全亮`,!1,()=>{this.remove(),this.onSelect?.({featureType:`lightOn`,state:{subState2:`on`}})}),this.addItem(t,`全灭`,!1,()=>{this.remove(),this.onSelect?.({featureType:`lightOff`,state:{subState2:`off`}})}),document.body.appendChild(t),this.adjustPosition(t,e),this.el=t}remove(){this.el&&=(this.el.remove(),null),this.currentFeature&&=(this.teeeMap.ctcTool?.changeFeatureState(this.currentFeature.properties.code,{select:!1}),null)}},Wi=class{map;layerIds=[];callbacks={};hovered=null;popup=null;popupRenderer;_active=!1;_boundMouseMove;_boundMove;constructor(e){this.map=e.map,this._boundMouseMove=this._onMouseMove.bind(this),this._boundMove=this._onMove.bind(this)}start(e,t){this._active&&this.stop(),this._active=!0,this.layerIds=e,this.callbacks=t??{},this.map.on(`mousemove`,this._boundMouseMove),this.map.on(`move`,this._boundMove)}stop(){this._active&&(this._active=!1,this.map.off(`mousemove`,this._boundMouseMove),this.map.off(`move`,this._boundMove),this.hovered=null,this.popup?.remove(),this.popup=null,this.callbacks.onStop?.(),this.callbacks={},this.layerIds=[])}setPopupRenderer(e){this.popupRenderer=e}destroy(){this.stop(),this.popupRenderer=void 0}_onMouseMove(e){if(!this.layerIds.length)return;let n=this.map.queryRenderedFeatures(e.point,{layers:this.layerIds});if(n.length>0){let r=n[0];if(this.hovered&&this.hovered.properties.code===r.properties.code){this.popup?.setLngLat(e.lngLat);return}this._clearHover(),this.hovered=r,this.callbacks.onEnter?.(this.hovered),this.popup||=new t.default.Popup({closeButton:!1,closeOnClick:!1,anchor:`top-left`,offset:[15,0]}),this.popup.setLngLat(e.lngLat).setHTML(this._renderPopup(n)).addTo(this.map)}else this._clearHover()}_onMove(){this._active&&(this._clearHover(),this.popup?.remove())}_clearHover(){if(!this.hovered)return;let e=this.hovered;this.hovered=null,this.popup?.remove(),this.callbacks.onLeave?.(e)}_renderPopup(e){return this.popupRenderer?this.popupRenderer(e):[...new Set(e.map(e=>e.properties.name))].join(`<br>`)}},Gi=class{map;layerIds=[];callbacks={onClick:()=>{}};hovered=null;popup=null;popupRenderer;_active=!1;_boundMouseMove;_boundClick;_boundMove;constructor(e){this.map=e.map,this._boundMouseMove=this._onMouseMove.bind(this),this._boundClick=this._onClick.bind(this),this._boundMove=this._onMove.bind(this)}start(e,t){this._active&&this.stop(),this._active=!0,this.layerIds=e,this.callbacks=t,this.map.on(`mousemove`,this._boundMouseMove),this.map.on(`click`,this._boundClick),this.map.on(`move`,this._boundMove)}stop(){this._active&&(this._active=!1,this.map.off(`mousemove`,this._boundMouseMove),this.map.off(`click`,this._boundClick),this.map.off(`move`,this._boundMove),this._clearHover(),this.popup?.remove(),this.popup=null,this.callbacks.onStop?.(),this.callbacks={onClick:()=>{}},this.layerIds=[])}setPopupRenderer(e){this.popupRenderer=e}destroy(){this.stop(),this.popupRenderer=void 0}_onMouseMove(e){if(!this.layerIds.length)return;let n=this.map.queryRenderedFeatures(e.point,{layers:this.layerIds});if(n.length>0){let r=n[0];if(this.hovered&&this.hovered.properties.code===r.properties.code){this.popup?.setLngLat(e.lngLat);return}this._clearHover(),this.hovered=r,this.callbacks.onEnter?.(this.hovered),this.popup||=new t.default.Popup({closeButton:!1,closeOnClick:!1,anchor:`top-left`,offset:[15,0]}),this.popup.setLngLat(e.lngLat).setHTML(this._renderPopup(r)).addTo(this.map)}else this._clearHover()}_onClick(e){if(!this.layerIds.length)return;let t=this.map.queryRenderedFeatures(e.point,{layers:this.layerIds});t.length>0&&this.callbacks.onClick(t[0])}_onMove(){this._active&&(this._clearHover(),this.popup?.remove())}_clearHover(){if(!this.hovered)return;let e=this.hovered;this.hovered=null,this.popup?.remove(),this.callbacks.onLeave?.(e)}_renderPopup(e){if(this.popupRenderer)return this.popupRenderer(e);let t=e.properties;return`
7
+ <div style="max-width:300px;overflow:auto;font-size:12px">
8
+ <div style="font-weight:700;font-size:13px;padding:0px 0;border-bottom:1px solid #e8e8e8;margin-bottom:2px">${t.name||``}</div>
9
+ <table style="border-collapse:collapse">${Object.entries({danyuan:`单元`,quyu:`区域`,tianchuan:`天窗`,zhengxian:`正线`,bz:`备注`}).filter(([e])=>t[e]!==void 0&&t[e]!==null).map(([e,n])=>`<tr><td style="padding:2px 6px;font-weight:600;white-space:nowrap;vertical-align:top">${n}</td><td style="padding:2px 6px">${t[e]}</td></tr>`).join(``)}</table>
10
+ </div>
11
+ `}},Ki=class{map;teeeMap;layerIds=[];callback=null;active=!1;el=null;currentFeature=null;checked={state:``,subState1:``,subState2:``,subState3:``};boundContextMenu;boundMove;constructor(e){this.teeeMap=e,this.map=e.map,this.boundContextMenu=this._onContextMenu.bind(this),this.boundMove=this._onMove.bind(this)}start(e,t){this.active&&this.stop(),this.active=!0,this.layerIds=e,this.callback=t,this.map.on(`contextmenu`,this.boundContextMenu),this.map.on(`move`,this.boundMove)}stop(){this.active&&(this.active=!1,this.map.off(`contextmenu`,this.boundContextMenu),this.map.off(`move`,this.boundMove),this._removePopup(),this.callback=null,this.layerIds=[])}destroy(){this.stop()}_onContextMenu(e){e.preventDefault(),this._removePopup();let t=this.map.queryRenderedFeatures(e.point,{layers:this.layerIds});if(!t.length)return;let n=t[0];this.currentFeature=n,this.teeeMap.ctcTool?.changeFeatureState(n.properties.code,{select:!0});let r=n.state||{},i=r.state||``;this.checked={state:``,subState1:r.subState1||``,subState2:r.subState2||``,subState3:r.subState3||``},this._showPopup(e,n,i)}_onMove(){this._removePopup()}_showPopup(e,t,n){let r=this._getViewportPos(e),i=t.properties.name||``,a=document.createElement(`div`);a.className=`door-tool-popup`,a.style.cssText=`position:fixed;z-index:9999;left:${r.x}px;top:${r.y}px;background:#fff;color:#000;font-size:13px;min-width:220px;border-radius:4px;box-shadow:0 2px 8px rgba(0,0,0,0.2);`;let o=document.createElement(`div`);o.style.cssText=`padding:8px 10px;font-size:14px;font-weight:600;display:flex;justify-content:space-between;align-items:center;border-bottom:1px solid #e8e8e8;`,o.innerHTML=`${i}<span class="door-popup-close" style="cursor:pointer;font-size:16px;color:#999;line-height:1;">×</span>`,o.querySelector(`.door-popup-close`).addEventListener(`click`,()=>this._removePopup()),a.appendChild(o),this._addCheckItem(a,`调度命令确认`,`subState1`),this._addCheckItem(a,`进入通道门申请确认`,`subState2`),this._addCheckItem(a,`人员、工机具、通道门号确认`,`subState3`);let s=document.createElement(`div`);s.style.cssText=`height:1px;background:#e8e8e8;margin:4px 0;`,a.appendChild(s);let c=document.createElement(`div`);c.style.cssText=`display:grid;grid-template-columns:1fr 1fr;gap:6px;padding:8px 10px;`,this._addButton(c,`施工开始开门`,`1`,n),this._addButton(c,`施工结束关门`,`2`,n),this._addButton(c,`临时开门`,`3`,n),this._addButton(c,`临时关门`,`4`,n),a.appendChild(c),document.body.appendChild(a),this._adjustPosition(a,e),this.el=a}_addCheckItem(e,t,n){let r=this.checked[n]===`1`,i=document.createElement(`div`);i.style.cssText=`padding:6px 10px;display:flex;align-items:center;gap:8px;cursor:pointer;user-select:none;`,i.innerHTML=r?`<span style="color:#1677ff;font-weight:600;width:16px;">✓</span>${t}`:`<span style="color:#ccc;width:16px;">○</span>${t}`,i.addEventListener(`mouseenter`,()=>{i.style.background=`#f2f2f2`}),i.addEventListener(`mouseleave`,()=>{i.style.background=``}),i.addEventListener(`click`,()=>{this.checked={...this.checked,[n]:this.checked[n]===`1`?``:`1`};let e=i.querySelector(`span`);this.checked[n]===`1`?(e.style.color=`#1677ff`,e.style.fontWeight=`600`,e.textContent=`✓`):(e.style.color=`#ccc`,e.style.fontWeight=``,e.textContent=`○`)}),e.appendChild(i)}_addButton(e,t,n,r){let i=n===r,a=document.createElement(`button`);a.textContent=t,a.style.cssText=`padding:6px 0;border:1px solid #d9d9d9;border-radius:4px;background:${i?`#e6f4ff`:`#fff`};color:${i?`#1677ff`:`#000`};border-color:${i?`#1677ff`:`#d9d9d9`};font-weight:${i?`600`:`normal`};cursor:pointer;font-size:13px;white-space:nowrap;`,i||(a.addEventListener(`mouseenter`,()=>{a.style.borderColor=`#1677ff`,a.style.color=`#1677ff`}),a.addEventListener(`mouseleave`,()=>{a.style.borderColor=`#d9d9d9`,a.style.color=``})),a.addEventListener(`click`,()=>{let e={...this.checked,state:n},t=this.currentFeature;this._removePopup(),this.callback?.(t,e)}),e.appendChild(a)}_getViewportPos(e){let t=this.map.getContainer().getBoundingClientRect();return{x:t.left+e.point.x,y:t.top+e.point.y}}_adjustPosition(e,t){let n=this._getViewportPos(t),r=e.getBoundingClientRect();r.right>window.innerWidth&&(e.style.left=`${n.x-r.width}px`),r.bottom>window.innerHeight&&(e.style.top=`${Math.max(0,n.y-r.height)}px`)}_removePopup(){this.el&&=(this.el.remove(),null),this.currentFeature&&=(this.teeeMap.ctcTool?.changeFeatureState(this.currentFeature.properties.code,{select:!1}),null)}},qi=class{map;sourceId;constructor(e,t){this.map=e,this.sourceId=t}getLayers(){return(this.map.getStyle().layers||[]).filter(e=>e.id.startsWith(this.sourceId)).map(e=>({id:e.id,visible:this.getVisibility(e.id)}))}getVisibility(e){return this.map.getLayoutProperty(e,`visibility`)!==`none`}setVisibility(e,t){this.map.getLayer(e)&&this.map.setLayoutProperty(e,`visibility`,t?`visible`:`none`)}toggleVisibility(e){let t=!this.getVisibility(e);return this.setVisibility(e,t),t}},Q={base:Be,ctc:Oe,graph:Xe,geojson:et,draw:pi,cursor:Oi,injectTeeeGeoJson:Ai,snaps:Ri,drawRoute:Vi,ctcMenu:Ui,ctcHover:Wi,sgfhqy:Gi,door:Ki},$={ctc:(e,t,n)=>({id:`ctc`,sourceUrl:t,layers:n,sourceLayers:n.map(t=>t===`switch_loc`?`${e}_t_${t}`:t===`sgfhqy`?`${e}_a_${t}_graph`:`${e}_t_${t}_graph`)}),raster:e=>({id:`raster`,sourceUrl:e,zoom:20}),geom:(e,t,n)=>({id:`geom`,sourceUrl:t,layers:n,sourceLayers:n.map(t=>t===`switch_loc`?`${e}_t_${t}`:`${e}_t_${t}_geom`)}),graph:(e,t,n)=>({id:`graph`,sourceUrl:t,layers:n,sourceLayers:n.map(t=>t===`switch_loc`?`${e}_t_${t}`:t===`sgfhqy`?`a_${t}_graph`:`${e}_t_${t}_graph`)}),geojson:e=>({id:e}),rswp:e=>({id:`rswp`,sourceUrl:e}),mbtiles:(e,t)=>({id:`mbtiles`,sourceUrl:e,layers:t,sourceLayers:t.map(e=>`t_${e}_graph`)}),rage:(e,t,n,r)=>({id:`geom`,subSourceId:`raster`,sourceUrl:e,subSourceUrl:t,layers:r,sourceLayers:r.map(e=>e===`switch_loc`?`${n}_t_${e}`:`${n}_t_${e}_geom`)})};function Ji(e,t,n){let r=BigInt(e),i=BigInt(t),a=BigInt(n),o=r*r*i^a;o===0n&&(o=3735928559n);let s=o;s^=s<<11n,s^=s>>5n,s^=s<<13n,s===0n&&(s=3405691582n);let c=s,l=s^s<<16n,u=s^s>>16n;return{z:r^c,x:i^l,y:a^u}}function Yi(e){e.map.setTransformRequest((e,t)=>{if(String(t)!==`Tile`)return{url:e};let n=/^https?:\/\//i.test(e)?e:`${window.location.origin}${e}`,r=new URL(n),i=r.pathname.split(`/`).filter(e=>e);if(i.length>=3){let e=Number(i[i.length-3]),t=Number(i[i.length-2]),n=i[i.length-1],a=n.includes(`.`)?n.split(`.`).pop():`pbf`,o=Number(n.replace(/\.(pbf|png)$/i,``));if(Number.isInteger(e)&&e>=0&&Number.isInteger(t)&&t>=0&&Number.isInteger(o)&&o>=0){let n=Ji(e,t,o),s=i.slice(0,i.length-3).join(`/`);return{url:`${r.protocol}//${r.host}/${s}/${n.z}/${n.x}/${n.y}.${a}`}}}return{url:e}})}var Xi=20037508.34,Zi=(e,t)=>[e/Xi*180,Math.atan(Math.exp(t/Xi*Math.PI))*360/Math.PI-90],Qi=e=>`coordinates`in e,$i=e=>typeof e[0]==`number`?Zi(e[0],e[1]):e.map($i),ea=e=>e?.features?{...e,features:e.features.map(e=>({...e,geometry:Qi(e.geometry)?{...e.geometry,coordinates:$i(e.geometry.coordinates)}:e.geometry}))}:e,ta=(e,t)=>{if(e===`signal`){if(!t?.features)return;t.features.forEach(({properties:e})=>{e&&(!e.positionSide&&e.posi_side&&(e.positionSide=e.posi_side,delete e.posi_side),!e.installType&&e.install_type&&(e.installType=e.install_type,delete e.install_type),!e.functionType&&e.function_type&&(e.functionType=e.function_type,delete e.function_type))})}if(e===`track_circuit`){if(!t?.features)return;t.features.forEach(({properties:e})=>{e&&(!e.fromCode&&e.from_code&&(e.fromCode=e.from_code,delete e.from_code),!e.toCode&&e.to_code&&(e.toCode=e.to_code,delete e.to_code))})}if(e===`insulation`){if(!t?.features)return;t.features.forEach(({properties:e})=>{e&&(!e.downSignal&&e.downsignal&&(e.downSignal=e.downsignal,delete e.downsignal),!e.upSignal&&e.upsignal&&(e.upSignal=e.upsignal,delete e.upsignal))})}},na=class{map;mapConfigs;stashFeatures=new Map;layerFeaturesCache=new Map;constructor(e){let n={version:8,sources:{},layers:[]};this.map=new t.default.Map({container:e,style:n,center:[0,0],zoom:14,attributionControl:!1}),Q.base(this),this.map.on(`load`,()=>{this.cursorTool=new Q.cursor(this.map),this.drawTool=new Q.draw(this),this.injectTeeeGeoJson=Q.injectTeeeGeoJson,this.snaps=new Q.snaps(this),this.drawRoute=new Q.drawRoute(this)})}initMap(e){let t=async()=>{try{console.log(`开始构建业务地图: ${e.id}`),Array.isArray(e.source)?e.source.forEach((e,t)=>{this.map.addSource(this.mapConfigs.sourceLayers[t],e)}):this.map.getSource(e.id)?console.warn(`地图源已存在,跳过添加: ${e.id}`):this.map.addSource(e.id,e.source),e.subSourceId&&(this.map.getSource(e.subSourceId)?console.warn(`地图源已存在,跳过添加: ${e.subSourceId}`):this.map.addSource(e.subSourceId,e.subSource)),(await oe()).forEach(e=>{this.map.hasImage(e.id)?console.warn(`图标已存在,跳过添加: ${e.id}`):this.map.addImage(e.id,e.image)}),e.layers&&e.layers.forEach(e=>{this.map.getLayer(e.id)?console.debug(`图层已存在: ${e.id}`):this.map.addLayer(e)}),this.layerTree=new qi(this.map,e.id);let t=this.map.getStyle().sources,n=Object.keys(t);console.log(`源列表 (${n.length}):`,n,t);let r=this.map.getStyle().layers,i=r.map(e=>e.id);console.log(`图层列表 (${i.length}):`,r),this.map.listImages(),console.groupEnd(),console.log(`地图构建全部完成: ${e.id}`)}catch(t){console.error(`地图初始化失败: ${e.id}`,t),t instanceof Error&&console.error(`错误详情: ${t.message}`)}};this.map.loaded()?t():this.map.on(`load`,()=>{t()}),this.map.once(`idle`,()=>{setTimeout(()=>{this.stashAllFeature()},800)})}createCTCMap(e,t,n){this.mapConfigs=$.ctc(e,t,n);let r=T.graph(this.mapConfigs.sourceUrl),i=D.ctc(this.mapConfigs),a={id:this.mapConfigs.id,source:r,layers:i};this.initMap(a),this.ctcTool=new Q.ctc(this),this.ctcMenu=new Q.ctcMenu(this),this.ctcHoverTool=new Q.ctcHover(this),this.sgfhqyTool=new Q.sgfhqy(this),this.doorTool=new Q.door(this)}createCTCEncryptedMap(e,t,n){Yi(this),this.mapConfigs=$.ctc(e,t,n);let r=T.graph(this.mapConfigs.sourceUrl),i=D.ctc(this.mapConfigs),a={id:this.mapConfigs.id,source:r,layers:i};this.initMap(a),this.ctcTool=new Q.ctc(this),this.ctcMenu=new Q.ctcMenu(this),this.ctcHoverTool=new Q.ctcHover(this),this.sgfhqyTool=new Q.sgfhqy(this),this.doorTool=new Q.door(this)}createRSWPMap(e){let t=$.rswp(e),n=T.raster(t.sourceUrl),r=D.raster(t.id),i=$.geojson(`rswp-geojson`),a=T.geojson(),o={id:t.id,source:n,subSourceId:i.id,subSource:a,layers:r};this.mapConfigs=t,this.mapConfigs.subSourceId=i.id,this.initMap(o)}createGraphMap(e,t,n){this.mapConfigs=$.graph(e,t,n);let r=T.graph(this.mapConfigs.sourceUrl),i=D.graph(this.mapConfigs),a={id:this.mapConfigs.id,source:r,layers:i};this.initMap(a),Q.graph(this)}createGraphEncryptedMap(e,t,n){Yi(this),this.mapConfigs=$.graph(e,t,n);let r=T.graph(this.mapConfigs.sourceUrl),i=D.ctc(this.mapConfigs),a={id:this.mapConfigs.id,source:r,layers:i};this.initMap(a),this.ctcTool=new Q.ctc(this),this.ctcMenu=new Q.ctcMenu(this)}createGeomMap(e,t,n){this.mapConfigs=$.geom(e,t,n);let r=T.geom(this.mapConfigs.sourceUrl),i=D.geom(this.mapConfigs),a={id:this.mapConfigs.id,source:r,layers:i};this.initMap(a)}createGeomEncryptedMap(e,t,n){Yi(this),this.mapConfigs=$.geom(e,t,n);let r=T.geom(this.mapConfigs.sourceUrl),i=D.geom(this.mapConfigs),a={id:this.mapConfigs.id,source:r,layers:i};this.initMap(a)}async createGeoJsonStationMap(e){let t=e.map(e=>e.name),r=t.map(e=>`geojson_${e}`);this.mapConfigs=$.geojson(`geojson`),this.mapConfigs.layers=t,this.mapConfigs.sourceLayers=r;let i=await Promise.all(e.map(async(e,t)=>{let n=r[t],i=e.name;if(this.map.getSource(n))return;let a=e.data,o;return typeof a==`string`?(o=ea(await(await fetch(a)).json()),ta(i,o)):(o=ea(a),ta(i,o)),this.layerFeaturesCache.set(i,o.features),T.geojson(o)})),a={id:this.mapConfigs.id,source:i,layers:D.geojson(t,r)};this.initMap(a);let o=e.find(e=>e.name===`track`)?.data;if(o){let e=(0,n.default)(ea(o));this.map.fitBounds([[e[0],e[1]],[e[2],e[3]]],{padding:100,maxZoom:15})}Q.geojson(this)}createRasterMap(e){this.mapConfigs=$.raster(e);let t=T.raster(this.mapConfigs.sourceUrl),n=D.raster(this.mapConfigs.id),r={id:this.mapConfigs.id,source:t,layers:n};this.initMap(r)}createEncryptedRasterMap(e){Yi(this),this.mapConfigs=$.raster(e);let t=T.raster(this.mapConfigs.sourceUrl),n=D.raster(this.mapConfigs.id),r={id:this.mapConfigs.id,source:t,layers:n};this.initMap(r)}createRAGEMap(e,t,n){let r=[`track`,`signal`,`bumper`,`prevention`];Yi(this),this.mapConfigs=$.rage(e,t,n,r);let i=T.geom(this.mapConfigs.sourceUrl),a=T.raster(this.mapConfigs.subSourceUrl),o=D.geom(this.mapConfigs),s=[...D.raster(this.mapConfigs.subSourceId),...o],c={id:this.mapConfigs.id,source:i,subSourceId:this.mapConfigs.subSourceId,subSource:a,layers:s};this.initMap(c)}getMap(){return this.map}getMapConfigs(){return this.mapConfigs}async stashAllFeature(){if(!this.mapConfigs)return;let e=this.mapConfigs.sourceLayers,t=this.mapConfigs.id;this.stashFeatures.clear(),e?.forEach(e=>{e.includes(`prevention`)||this.map.querySourceFeatures(t,{sourceLayer:e}).forEach(t=>{t.properties.code&&this.stashFeatures.set(t.properties.code,{sourceLayer:e})})});let n=this.mapConfigs.layers??[];await Promise.all(n.map(async e=>{if(e===`prevention`)return;let t=`geojson_${e}`,n=this.map.getSource(t);n&&(await n.getData()).features?.forEach(e=>{let n=e.properties?.code;n&&!this.stashFeatures.get(n)&&this.stashFeatures.set(n,{sourceLayer:t,properties:e.properties})})}))}updateFeatureState(e,t){if(!this.stashFeatures.get(e))return;Object.assign(this.stashFeatures.get(e),t);let n=this.stashFeatures.get(e);if(n.sourceLayer?.startsWith(`geojson_`))this.map.setFeatureState({source:n.sourceLayer,id:e},n);else{if(!this.mapConfigs)return;this.map.setFeatureState({source:this.mapConfigs.id,sourceLayer:n.sourceLayer,id:e},n)}}getFeatureState(e){if(this.stashFeatures.get(e))return this.stashFeatures.get(e)}locateGeojsonFeature(e,t=!0){let r=(0,n.default)(t?ea(e):e);this.map.fitBounds([[r[0],r[1]],[r[2],r[3]]],{padding:50,maxZoom:18})}queryGeojsonFeatures(e){return this.layerFeaturesCache.get(e)??[]}getTrackCircuitFeaturesByCodes(e){return this.layerFeaturesCache.get(`track_circuit`)?.filter(t=>e.includes(t.properties.code))??[]}},ra=document.createElement(`style`);ra.textContent=`
7
12
  .maplibregl-ctrl-attrib.maplibregl-compact {
8
13
  display: none !important;
9
14
  }
10
- `,document.head.appendChild(ta),e.TeeeMap=ea});
15
+ `,document.head.appendChild(ra),e.TeeeMap=na});