ofs-object 0.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/README.md +511 -0
- package/dist/index.d.ts +4887 -0
- package/dist/ofs-object.cjs +384 -0
- package/dist/ofs-object.css +565 -0
- package/dist/ofs-object.js +53733 -0
- package/docs/API.md +574 -0
- package/package.json +89 -0
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
"use strict";var x2=Object.defineProperty;var b2=(i,t,e)=>t in i?x2(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var Y=(i,t,e)=>b2(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I2=require("maplibre-gl");function S2(i){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const e in i)if(e!=="default"){const n=Object.getOwnPropertyDescriptor(i,e);Object.defineProperty(t,e,n.get?n:{enumerable:!0,get:()=>i[e]})}}return t.default=i,Object.freeze(t)}const Fy=S2(I2);class jr{constructor(){Y(this,"listeners",new Map)}on(t,e){return this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(e),()=>this.off(t,e)}once(t,e){const n=s=>{this.off(t,n),e(s)};return this.on(t,n)}off(t,e){const n=this.listeners.get(t);n&&(n.delete(e),n.size===0&&this.listeners.delete(t))}emit(t,e){const n=this.listeners.get(t);n&&n.forEach(s=>{try{s(e)}catch(r){console.error(`Error in event handler for "${String(t)}":`,r)}})}removeAllListeners(t){t?this.listeners.delete(t):this.listeners.clear()}listenerCount(t){var e;return((e=this.listeners.get(t))==null?void 0:e.size)??0}}class Pe extends Error{constructor(t){super(t),this.name="OFSError",Object.setPrototypeOf(this,new.target.prototype)}}class Su extends Pe{constructor(t="Operation was cancelled by user"){super(t),this.name="CommandCancelledError"}}class Fg extends Pe{constructor(t){super(`Layer with id "${t}" not found`),this.name="LayerNotFoundError"}}class $g extends Pe{constructor(t,e){super(e?`Feature "${t}" not found in layer "${e}"`:`Feature "${t}" not found`),this.name="FeatureNotFoundError"}}class yh extends Pe{constructor(t="Invalid GeoJSON geometry"){super(t),this.name="InvalidGeometryError"}}class M2 extends Pe{constructor(t){super(`Invalid coordinate format: "${t}". Expected [lng, lat] or "lng, lat" (longitude first)`),this.name="InvalidCoordinateError"}}class ua extends Pe{constructor(t="Map engine has not been initialized yet"){super(t),this.name="MapEngineNotInitializedError"}}class zv extends Pe{constructor(t,e){super(e?`Feature "${t}" already exists in layer "${e}"`:`Feature "${t}" already exists`),this.name="DuplicateFeatureIdError"}}function Uv(i){const t=i.trim();if(!t)return null;const n=(t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t).split(/[\s,]+/).filter(Boolean);if(n.length!==2)return null;const s=Number(n[0]),r=Number(n[1]);return Number.isFinite(s)&&Number.isFinite(r)?[s,r]:null}function Fm(i){const t=Uv(i);return t&&lc(t[0],t[1])?[t[0],t[1]]:null}function $m(i){const t=Uv(i);return t&&lc(t[1],t[0])?[t[1],t[0]]:null}function qh(i){const t=String(i).trim(),e=$m(t);return e?`"${t}" is not lng,lat — longitude comes first; did you mean "${e[0]}, ${e[1]}"?`:`"${t}" is not a coordinate (use lng,lat, e.g. 100.5018, 13.7563)`}function lc(i,t){return Number.isFinite(i)&&Number.isFinite(t)&&i>=-180&&i<=180&&t>=-90&&t<=90}function N2(i){const t=i.trim();if(!t)return null;let e;try{e=JSON.parse(t)}catch{return null}if(!Array.isArray(e)||e.length===0)return null;const n=[];for(const s of e){if(!Array.isArray(s)||s.length<2)return null;const r=Number(s[0]),o=Number(s[1]);if(!lc(r,o))return null;n.push([r,o])}return n}function L2(i,t=6){return`${i[0].toFixed(t)}, ${i[1].toFixed(t)}`}function _o(i,t){const e=63710088e-1,n=(t[1]-i[1])*Math.PI/180,s=(t[0]-i[0])*Math.PI/180,r=i[1]*Math.PI/180,o=t[1]*Math.PI/180,a=Math.sin(n/2)*Math.sin(n/2)+Math.sin(s/2)*Math.sin(s/2)*Math.cos(r)*Math.cos(o),l=2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a));return e*l}function C2(i,t){const e=t[0]-i[0],n=t[1]-i[1];return Math.sqrt(e*e+n*n)}function P2(i,t){return[(i[0]+t[0])/2,(i[1]+t[1])/2]}function k2(i){if(i.length===0)return[0,0,0,0];let t=1/0,e=1/0,n=-1/0,s=-1/0;for(const[r,o]of i)r<t&&(t=r),o<e&&(e=o),r>n&&(n=r),o>s&&(s=o);return[t,e,n,s]}function Yv(i,t=32){if(i.length<3)return[...i];const e=[],n=i.length-1;for(let s=0;s<=t;s++){const r=s/t;let o=0,a=0;for(let l=0;l<=n;l++){const h=T2(n,l)*Math.pow(1-r,n-l)*Math.pow(r,l);o+=i[l][0]*h,a+=i[l][1]*h}e.push([o,a])}return e}function T2(i,t){if(t<0||t>i)return 0;if(t===0||t===i)return 1;let e=1;for(let n=1;n<=t;n++)e=e*(i-(t-n))/n;return e}function R2(i){i("EPSG:4326","+title=WGS 84 (long/lat) +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees"),i("EPSG:4269","+title=NAD83 (long/lat) +proj=longlat +a=6378137.0 +b=6356752.31414036 +ellps=GRS80 +datum=NAD83 +units=degrees"),i("EPSG:3857","+title=WGS 84 / Pseudo-Mercator +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs");for(var t=1;t<=60;++t)i("EPSG:"+(32600+t),"+proj=utm +zone="+t+" +datum=WGS84 +units=m"),i("EPSG:"+(32700+t),"+proj=utm +zone="+t+" +south +datum=WGS84 +units=m");i("EPSG:5041","+title=WGS 84 / UPS North (E,N) +proj=stere +lat_0=90 +lon_0=0 +k=0.994 +x_0=2000000 +y_0=2000000 +datum=WGS84 +units=m"),i("EPSG:5042","+title=WGS 84 / UPS South (E,N) +proj=stere +lat_0=-90 +lon_0=0 +k=0.994 +x_0=2000000 +y_0=2000000 +datum=WGS84 +units=m"),i.WGS84=i["EPSG:4326"],i["EPSG:3785"]=i["EPSG:3857"],i.GOOGLE=i["EPSG:3857"],i["EPSG:900913"]=i["EPSG:3857"],i["EPSG:102113"]=i["EPSG:3857"]}var Po=1,ko=2,Pa=3,A2=4,Dg=5,$y=6378137,O2=6356752314e-3,Dy=.0066943799901413165,gu=484813681109536e-20,_t=Math.PI/2,F2=.16666666666666666,$2=.04722222222222222,D2=.022156084656084655,Mt=1e-10,We=.017453292519943295,ai=57.29577951308232,be=Math.PI/4,Mu=Math.PI*2,en=3.14159265359,di={};di.greenwich=0;di.lisbon=-9.131906111111;di.paris=2.337229166667;di.bogota=-74.080916666667;di.madrid=-3.687938888889;di.rome=12.452333333333;di.bern=7.439583333333;di.jakarta=106.807719444444;di.ferro=-17.666666666667;di.brussels=4.367975;di.stockholm=18.058277777778;di.athens=23.7163375;di.oslo=10.722916666667;const G2={mm:{to_meter:.001},cm:{to_meter:.01},ft:{to_meter:.3048},"us-ft":{to_meter:1200/3937},fath:{to_meter:1.8288},kmi:{to_meter:1852},"us-ch":{to_meter:20.1168402336805},"us-mi":{to_meter:1609.34721869444},km:{to_meter:1e3},"ind-ft":{to_meter:.30479841},"ind-yd":{to_meter:.91439523},mi:{to_meter:1609.344},yd:{to_meter:.9144},ch:{to_meter:20.1168},link:{to_meter:.201168},dm:{to_meter:.1},in:{to_meter:.0254},"ind-ch":{to_meter:20.11669506},"us-in":{to_meter:.025400050800101},"us-yd":{to_meter:.914401828803658}};var Gy=/[\s_\-\/\(\)]/g;function Gr(i,t){if(i[t])return i[t];for(var e=Object.keys(i),n=t.toLowerCase().replace(Gy,""),s=-1,r,o;++s<e.length;)if(r=e[s],o=r.toLowerCase().replace(Gy,""),o===n)return i[r]}function Gg(i){var t={},e=i.split("+").map(function(a){return a.trim()}).filter(function(a){return a}).reduce(function(a,l){var h=l.split("=");return h.push(!0),a[h[0].toLowerCase()]=h[1],a},{}),n,s,r,o={proj:function(a){t.projName=["lonlat","latlon","latlong"].includes(a)?"longlat":a},datum:"datumCode",rf:function(a){t.rf=parseFloat(a)},lat_0:function(a){t.lat0=a*We},lat_1:function(a){t.lat1=a*We},lat_2:function(a){t.lat2=a*We},lat_ts:function(a){t.lat_ts=a*We},lon_0:function(a){t.long0=a*We},lon_wrap:function(a){t.long_wrap=parseFloat(a)*We},lon_1:function(a){t.long1=a*We},lon_2:function(a){t.long2=a*We},alpha:function(a){t.alpha=parseFloat(a)*We},gamma:function(a){t.rectified_grid_angle=parseFloat(a)*We},lonc:function(a){t.longc=a*We},x_0:function(a){t.x0=parseFloat(a)},y_0:function(a){t.y0=parseFloat(a)},k_0:function(a){t.k0=parseFloat(a)},k:function(a){t.k0=parseFloat(a)},a:function(a){t.a=parseFloat(a)},b:function(a){t.b=parseFloat(a)},r:function(a){t.a=t.b=parseFloat(a)},r_a:function(){t.R_A=!0},zone:function(a){t.zone=parseInt(a,10)},south:function(){t.utmSouth=!0},towgs84:function(a){t.datum_params=a.split(",").map(function(l){return parseFloat(l)})},to_meter:function(a){t.to_meter=parseFloat(a)},units:function(a){t.units=a;var l=Gr(G2,a);l&&(t.to_meter=l.to_meter)},from_greenwich:function(a){t.from_greenwich=a*We},pm:function(a){var l=Gr(di,a);t.from_greenwich=(l||parseFloat(a))*We},nadgrids:function(a){a==="@null"?t.datumCode="none":t.nadgrids=a},axis:function(a){var l="ewnsud";a.length===3&&l.indexOf(a.substr(0,1))!==-1&&l.indexOf(a.substr(1,1))!==-1&&l.indexOf(a.substr(2,1))!==-1&&(t.axis=a)},approx:function(){t.approx=!0},over:function(){t.over=!0}};for(n in e)s=e[n],n in o?(r=o[n],typeof r=="function"?r(s):t[r]=s):t[n]=s;return typeof t.datumCode=="string"&&t.datumCode!=="WGS84"&&(t.datumCode=t.datumCode.toLowerCase()),t.projStr=i,t}class B2{static getId(t){const e=t.find(n=>Array.isArray(n)&&n[0]==="ID");return e&&e.length>=3?{authority:e[1],code:parseInt(e[2],10)}:null}static convertUnit(t,e="unit"){if(!t||t.length<3)return{type:e,name:"unknown",conversion_factor:null};const n=t[1],s=parseFloat(t[2])||null,r=t.find(a=>Array.isArray(a)&&a[0]==="ID"),o=r?{authority:r[1],code:parseInt(r[2],10)}:null;return{type:e,name:n,conversion_factor:s,id:o}}static convertAxis(t){const e=t[1]||"Unknown";let n;const s=e.match(/^\((.)\)$/);if(s){const h=s[1].toUpperCase();if(h==="E")n="east";else if(h==="N")n="north";else if(h==="U")n="up";else if(t[2])n=t[2];else throw new Error(`Unknown axis abbreviation: ${h}`)}else n=t[2]||"unknown";const r=t.find(h=>Array.isArray(h)&&h[0]==="ORDER"),o=r?parseInt(r[1],10):null,a=t.find(h=>Array.isArray(h)&&(h[0]==="LENGTHUNIT"||h[0]==="ANGLEUNIT"||h[0]==="SCALEUNIT")),l=this.convertUnit(a);return{name:e,direction:n,unit:l,order:o}}static extractAxes(t){return t.filter(e=>Array.isArray(e)&&e[0]==="AXIS").map(e=>this.convertAxis(e)).sort((e,n)=>(e.order||0)-(n.order||0))}static convert(t,e={}){switch(t[0]){case"PROJCRS":e.type="ProjectedCRS",e.name=t[1],e.base_crs=t.find(y=>Array.isArray(y)&&y[0]==="BASEGEOGCRS")?this.convert(t.find(y=>Array.isArray(y)&&y[0]==="BASEGEOGCRS")):null,e.conversion=t.find(y=>Array.isArray(y)&&y[0]==="CONVERSION")?this.convert(t.find(y=>Array.isArray(y)&&y[0]==="CONVERSION")):null;const n=t.find(y=>Array.isArray(y)&&y[0]==="CS");n&&(e.coordinate_system={subtype:n[1],axis:this.extractAxes(t)});const s=t.find(y=>Array.isArray(y)&&y[0]==="LENGTHUNIT");if(s){const y=this.convertUnit(s);e.coordinate_system.unit=y}e.id=this.getId(t);break;case"BASEGEOGCRS":case"GEOGCRS":case"GEODCRS":e.type=t[0]==="GEODCRS"?"GeodeticCRS":"GeographicCRS",e.name=t[1];const r=t.find(y=>Array.isArray(y)&&(y[0]==="DATUM"||y[0]==="ENSEMBLE"));if(r){const y=this.convert(r);r[0]==="ENSEMBLE"?e.datum_ensemble=y:e.datum=y;const _=t.find(E=>Array.isArray(E)&&E[0]==="PRIMEM");_&&_[1]!=="Greenwich"&&(y.prime_meridian={name:_[1],longitude:parseFloat(_[2])})}const o=t.find(y=>Array.isArray(y)&&y[0]==="CS");e.coordinate_system={subtype:o?o[1]:"ellipsoidal",axis:this.extractAxes(t)},e.id=this.getId(t);break;case"DATUM":e.type="GeodeticReferenceFrame",e.name=t[1],e.ellipsoid=t.find(y=>Array.isArray(y)&&y[0]==="ELLIPSOID")?this.convert(t.find(y=>Array.isArray(y)&&y[0]==="ELLIPSOID")):null;break;case"ENSEMBLE":e.type="DatumEnsemble",e.name=t[1],e.members=t.filter(y=>Array.isArray(y)&&y[0]==="MEMBER").map(y=>({type:"DatumEnsembleMember",name:y[1],id:this.getId(y)}));const a=t.find(y=>Array.isArray(y)&&y[0]==="ENSEMBLEACCURACY");a&&(e.accuracy=parseFloat(a[1]));const l=t.find(y=>Array.isArray(y)&&y[0]==="ELLIPSOID");l&&(e.ellipsoid=this.convert(l)),e.id=this.getId(t);break;case"ELLIPSOID":e.type="Ellipsoid",e.name=t[1],e.semi_major_axis=parseFloat(t[2]),e.inverse_flattening=parseFloat(t[3]),t.find(y=>Array.isArray(y)&&y[0]==="LENGTHUNIT")&&this.convert(t.find(y=>Array.isArray(y)&&y[0]==="LENGTHUNIT"),e);break;case"CONVERSION":e.type="Conversion",e.name=t[1],e.method=t.find(y=>Array.isArray(y)&&y[0]==="METHOD")?this.convert(t.find(y=>Array.isArray(y)&&y[0]==="METHOD")):null,e.parameters=t.filter(y=>Array.isArray(y)&&y[0]==="PARAMETER").map(y=>this.convert(y));break;case"METHOD":e.type="Method",e.name=t[1],e.id=this.getId(t);break;case"PARAMETER":e.type="Parameter",e.name=t[1],e.value=parseFloat(t[2]),e.unit=this.convertUnit(t.find(y=>Array.isArray(y)&&(y[0]==="LENGTHUNIT"||y[0]==="ANGLEUNIT"||y[0]==="SCALEUNIT"))),e.id=this.getId(t);break;case"BOUNDCRS":e.type="BoundCRS";const h=t.find(y=>Array.isArray(y)&&y[0]==="SOURCECRS");if(h){const y=h.find(_=>Array.isArray(_));e.source_crs=y?this.convert(y):null}const f=t.find(y=>Array.isArray(y)&&y[0]==="TARGETCRS");if(f){const y=f.find(_=>Array.isArray(_));e.target_crs=y?this.convert(y):null}const d=t.find(y=>Array.isArray(y)&&y[0]==="ABRIDGEDTRANSFORMATION");d?e.transformation=this.convert(d):e.transformation=null;break;case"ABRIDGEDTRANSFORMATION":if(e.type="Transformation",e.name=t[1],e.method=t.find(y=>Array.isArray(y)&&y[0]==="METHOD")?this.convert(t.find(y=>Array.isArray(y)&&y[0]==="METHOD")):null,e.parameters=t.filter(y=>Array.isArray(y)&&(y[0]==="PARAMETER"||y[0]==="PARAMETERFILE")).map(y=>{if(y[0]==="PARAMETER")return this.convert(y);if(y[0]==="PARAMETERFILE")return{name:y[1],value:y[2],id:{authority:"EPSG",code:8656}}}),e.parameters.length===7){const y=e.parameters[6];y.name==="Scale difference"&&(y.value=Math.round((y.value-1)*1e12)/1e6)}e.id=this.getId(t);break;case"AXIS":e.coordinate_system||(e.coordinate_system={type:"unspecified",axis:[]}),e.coordinate_system.axis.push(this.convertAxis(t));break;case"LENGTHUNIT":const p=this.convertUnit(t,"LinearUnit");e.coordinate_system&&e.coordinate_system.axis&&e.coordinate_system.axis.forEach(y=>{y.unit||(y.unit=p)}),p.conversion_factor&&p.conversion_factor!==1&&e.semi_major_axis&&(e.semi_major_axis={value:e.semi_major_axis,unit:p});break;default:e.keyword=t[0];break}return e}}function q2(i){return B2.convert(i)}function z2(i){const t=i.toUpperCase();return t.includes("PROJCRS")||t.includes("GEOGCRS")||t.includes("BOUNDCRS")||t.includes("VERTCRS")||t.includes("LENGTHUNIT")||t.includes("ANGLEUNIT")||t.includes("SCALEUNIT")?"WKT2":(t.includes("PROJCS")||t.includes("GEOGCS")||t.includes("LOCAL_CS")||t.includes("VERT_CS")||t.includes("UNIT"),"WKT1")}var Nu=1,Xv=2,jv=3,zh=4,Vv=5,Dm=-1,U2=/\s/,Y2=/[A-Za-z]/,X2=/[A-Za-z84_]/,zf=/[,\]]/,Hv=/[\d\.E\-\+]/;function xr(i){if(typeof i!="string")throw new Error("not a string");this.text=i.trim(),this.level=0,this.place=0,this.root=null,this.stack=[],this.currentObject=null,this.state=Nu}xr.prototype.readCharicter=function(){var i=this.text[this.place++];if(this.state!==zh)for(;U2.test(i);){if(this.place>=this.text.length)return;i=this.text[this.place++]}switch(this.state){case Nu:return this.neutral(i);case Xv:return this.keyword(i);case zh:return this.quoted(i);case Vv:return this.afterquote(i);case jv:return this.number(i);case Dm:return}};xr.prototype.afterquote=function(i){if(i==='"'){this.word+='"',this.state=zh;return}if(zf.test(i)){this.word=this.word.trim(),this.afterItem(i);return}throw new Error(`havn't handled "`+i+'" in afterquote yet, index '+this.place)};xr.prototype.afterItem=function(i){if(i===","){this.word!==null&&this.currentObject.push(this.word),this.word=null,this.state=Nu;return}if(i==="]"){this.level--,this.word!==null&&(this.currentObject.push(this.word),this.word=null),this.state=Nu,this.currentObject=this.stack.pop(),this.currentObject||(this.state=Dm);return}};xr.prototype.number=function(i){if(Hv.test(i)){this.word+=i;return}if(zf.test(i)){this.word=parseFloat(this.word),this.afterItem(i);return}throw new Error(`havn't handled "`+i+'" in number yet, index '+this.place)};xr.prototype.quoted=function(i){if(i==='"'){this.state=Vv;return}this.word+=i};xr.prototype.keyword=function(i){if(X2.test(i)){this.word+=i;return}if(i==="["){var t=[];t.push(this.word),this.level++,this.root===null?this.root=t:this.currentObject.push(t),this.stack.push(this.currentObject),this.currentObject=t,this.state=Nu;return}if(zf.test(i)){this.afterItem(i);return}throw new Error(`havn't handled "`+i+'" in keyword yet, index '+this.place)};xr.prototype.neutral=function(i){if(Y2.test(i)){this.word=i,this.state=Xv;return}if(i==='"'){this.word="",this.state=zh;return}if(Hv.test(i)){this.word=i,this.state=jv;return}if(zf.test(i)){this.afterItem(i);return}throw new Error(`havn't handled "`+i+'" in neutral yet, index '+this.place)};xr.prototype.output=function(){for(;this.place<this.text.length;)this.readCharicter();if(this.state===Dm)return this.root;throw new Error('unable to parse string "'+this.text+'". State is '+this.state)};function j2(i){var t=new xr(i);return t.output()}function qd(i,t,e){Array.isArray(t)&&(e.unshift(t),t=null);var n=t?{}:i,s=e.reduce(function(r,o){return va(o,r),r},n);t&&(i[t]=s)}function va(i,t){if(!Array.isArray(i)){t[i]=!0;return}var e=i.shift();if(e==="PARAMETER"&&(e=i.shift()),i.length===1){if(Array.isArray(i[0])){t[e]={},va(i[0],t[e]);return}t[e]=i[0];return}if(!i.length){t[e]=!0;return}if(e==="TOWGS84"){t[e]=i;return}if(e==="AXIS"){e in t||(t[e]=[]),t[e].push(i);return}Array.isArray(e)||(t[e]={});var n;switch(e){case"UNIT":case"PRIMEM":case"VERT_DATUM":t[e]={name:i[0].toLowerCase(),convert:i[1]},i.length===3&&va(i[2],t[e]);return;case"SPHEROID":case"ELLIPSOID":t[e]={name:i[0],a:i[1],rf:i[2]},i.length===4&&va(i[3],t[e]);return;case"EDATUM":case"ENGINEERINGDATUM":case"LOCAL_DATUM":case"DATUM":case"VERT_CS":case"VERTCRS":case"VERTICALCRS":i[0]=["name",i[0]],qd(t,e,i);return;case"COMPD_CS":case"COMPOUNDCRS":case"FITTED_CS":case"PROJECTEDCRS":case"PROJCRS":case"GEOGCS":case"GEOCCS":case"PROJCS":case"LOCAL_CS":case"GEODCRS":case"GEODETICCRS":case"GEODETICDATUM":case"ENGCRS":case"ENGINEERINGCRS":i[0]=["name",i[0]],qd(t,e,i),t[e].type=e;return;default:for(n=-1;++n<i.length;)if(!Array.isArray(i[n]))return va(i,t[e]);return qd(t,e,i)}}var V2=.017453292519943295;function qi(i){return i*V2}function Wv(i){const t=(i.projName||"").toLowerCase().replace(/_/g," ");i.long0===void 0&&i.longc!==void 0&&(i.long0=i.longc),!i.lat_ts&&i.lat1&&(t==="stereographic south pole"||t==="polar stereographic (variant b)")?(i.lat0=qi(i.lat1>0?90:-90),i.lat_ts=i.lat1,delete i.lat1):!i.lat_ts&&i.lat0&&(t==="polar stereographic"||t==="polar stereographic (variant a)")&&(i.lat_ts=i.lat0,i.lat0=qi(i.lat0>0?90:-90),delete i.lat1)}function By(i){let t={units:null,to_meter:void 0};return typeof i=="string"?(t.units=i.toLowerCase(),t.units==="metre"&&(t.units="meter"),t.units==="meter"&&(t.to_meter=1)):i&&i.name&&(t.units=i.name.toLowerCase(),t.units==="metre"&&(t.units="meter"),t.to_meter=i.conversion_factor),t}function qy(i){return typeof i=="object"?i.value*i.unit.conversion_factor:i}function zy(i,t){i.ellipsoid.radius?(t.a=i.ellipsoid.radius,t.rf=0):(t.a=qy(i.ellipsoid.semi_major_axis),i.ellipsoid.inverse_flattening!==void 0?t.rf=i.ellipsoid.inverse_flattening:i.ellipsoid.semi_major_axis!==void 0&&i.ellipsoid.semi_minor_axis!==void 0&&(t.rf=t.a/(t.a-qy(i.ellipsoid.semi_minor_axis))))}function Uh(i,t={}){return!i||typeof i!="object"?i:i.type==="BoundCRS"?(Uh(i.source_crs,t),i.transformation&&(i.transformation.method&&i.transformation.method.name==="NTv2"?t.nadgrids=i.transformation.parameters[0].value:t.datum_params=i.transformation.parameters.map(e=>e.value)),t):(Object.keys(i).forEach(e=>{const n=i[e];if(n!==null)switch(e){case"name":if(t.srsCode)break;t.name=n,t.srsCode=n;break;case"type":n==="GeographicCRS"?t.projName="longlat":n==="GeodeticCRS"?i.coordinate_system&&i.coordinate_system.subtype==="Cartesian"?t.projName="geocent":t.projName="longlat":n==="ProjectedCRS"&&i.conversion&&i.conversion.method&&(t.projName=i.conversion.method.name);break;case"datum":case"datum_ensemble":n.ellipsoid&&(t.ellps=n.ellipsoid.name,zy(n,t)),n.prime_meridian&&(t.from_greenwich=n.prime_meridian.longitude*Math.PI/180);break;case"ellipsoid":t.ellps=n.name,zy(n,t);break;case"prime_meridian":t.long0=(n.longitude||0)*Math.PI/180;break;case"coordinate_system":if(n.axis){const s={east:"e",north:"n",west:"w",south:"s",up:"u",down:"d",geocentricx:"e",geocentricy:"n",geocentricz:"u"},r=n.axis.map(o=>s[o.direction.toLowerCase()]);if(r.every(Boolean)&&(t.axis=r.join(""),t.axis.length===2&&(t.axis+="u")),n.unit){const{units:o,to_meter:a}=By(n.unit);t.units=o,t.to_meter=a}else if(n.axis[0]&&n.axis[0].unit){const{units:o,to_meter:a}=By(n.axis[0].unit);t.units=o,t.to_meter=a}}break;case"id":n.authority&&n.code&&(t.title=n.authority+":"+n.code);break;case"conversion":n.method&&n.method.name&&(t.projName=n.method.name),n.parameters&&n.parameters.forEach(s=>{const r=s.name.toLowerCase().replace(/\s+/g,"_"),o=s.value;s.unit&&s.unit.conversion_factor?t[r]=o*s.unit.conversion_factor:s.unit==="degree"?t[r]=o*Math.PI/180:t[r]=o});break;case"unit":n.name&&(t.units=n.name.toLowerCase(),t.units==="metre"&&(t.units="meter")),n.conversion_factor&&(t.to_meter=n.conversion_factor);break;case"base_crs":Uh(n,t),t.datumCode=n.id?n.id.authority+"_"+n.id.code:n.name;break}}),t.latitude_of_false_origin!==void 0&&(t.lat0=t.latitude_of_false_origin),t.longitude_of_false_origin!==void 0&&(t.long0=t.longitude_of_false_origin),t.latitude_of_standard_parallel!==void 0&&(t.lat0=t.latitude_of_standard_parallel,t.lat1=t.latitude_of_standard_parallel),t.latitude_of_1st_standard_parallel!==void 0&&(t.lat1=t.latitude_of_1st_standard_parallel),t.latitude_of_2nd_standard_parallel!==void 0&&(t.lat2=t.latitude_of_2nd_standard_parallel),t.latitude_of_projection_centre!==void 0&&(t.lat0=t.latitude_of_projection_centre),t.longitude_of_projection_centre!==void 0&&(t.longc=t.longitude_of_projection_centre),t.easting_at_false_origin!==void 0&&(t.x0=t.easting_at_false_origin),t.northing_at_false_origin!==void 0&&(t.y0=t.northing_at_false_origin),t.latitude_of_natural_origin!==void 0&&(t.lat0=t.latitude_of_natural_origin),t.longitude_of_natural_origin!==void 0&&(t.long0=t.longitude_of_natural_origin),t.longitude_of_origin!==void 0&&(t.long0=t.longitude_of_origin),t.false_easting!==void 0&&(t.x0=t.false_easting),t.easting_at_projection_centre&&(t.x0=t.easting_at_projection_centre),t.false_northing!==void 0&&(t.y0=t.false_northing),t.northing_at_projection_centre&&(t.y0=t.northing_at_projection_centre),t.standard_parallel_1!==void 0&&(t.lat1=t.standard_parallel_1),t.standard_parallel_2!==void 0&&(t.lat2=t.standard_parallel_2),t.scale_factor_at_natural_origin!==void 0&&(t.k0=t.scale_factor_at_natural_origin),t.scale_factor_at_projection_centre!==void 0&&(t.k0=t.scale_factor_at_projection_centre),t.scale_factor_on_pseudo_standard_parallel!==void 0&&(t.k0=t.scale_factor_on_pseudo_standard_parallel),t.azimuth!==void 0&&(t.alpha=t.azimuth),t.azimuth_at_projection_centre!==void 0&&(t.alpha=t.azimuth_at_projection_centre),t.angle_from_rectified_to_skew_grid&&(t.rectified_grid_angle=t.angle_from_rectified_to_skew_grid),Wv(t),t)}var H2=["PROJECTEDCRS","PROJCRS","GEOGCS","GEOCCS","PROJCS","LOCAL_CS","GEODCRS","GEODETICCRS","GEODETICDATUM","ENGCRS","ENGINEERINGCRS"];function W2(i,t){var e=t[0],n=t[1];!(e in i)&&n in i&&(i[e]=i[n],t.length===3&&(i[e]=t[2](i[e])))}function Kv(i){for(var t=Object.keys(i),e=0,n=t.length;e<n;++e){var s=t[e];H2.indexOf(s)!==-1&&K2(i[s]),typeof i[s]=="object"&&Kv(i[s])}}function K2(i){if(i.AUTHORITY){var t=Object.keys(i.AUTHORITY)[0];t&&t in i.AUTHORITY&&(i.title=t+":"+i.AUTHORITY[t])}if(i.type==="GEOGCS"?i.projName="longlat":i.type==="LOCAL_CS"?(i.projName="identity",i.local=!0):typeof i.PROJECTION=="object"?i.projName=Object.keys(i.PROJECTION)[0]:i.projName=i.PROJECTION,i.AXIS){for(var e="",n=0,s=i.AXIS.length;n<s;++n){var r=[i.AXIS[n][0].toLowerCase(),i.AXIS[n][1].toLowerCase()];r[0].indexOf("north")!==-1||(r[0]==="y"||r[0]==="lat")&&r[1]==="north"?e+="n":r[0].indexOf("south")!==-1||(r[0]==="y"||r[0]==="lat")&&r[1]==="south"?e+="s":r[0].indexOf("east")!==-1||(r[0]==="x"||r[0]==="lon")&&r[1]==="east"?e+="e":(r[0].indexOf("west")!==-1||(r[0]==="x"||r[0]==="lon")&&r[1]==="west")&&(e+="w")}e.length===2&&(e+="u"),e.length===3&&(i.axis=e)}i.UNIT&&(i.units=i.UNIT.name.toLowerCase(),i.units==="metre"&&(i.units="meter"),i.UNIT.convert&&(i.type==="GEOGCS"?i.DATUM&&i.DATUM.SPHEROID&&(i.to_meter=i.UNIT.convert*i.DATUM.SPHEROID.a):i.to_meter=i.UNIT.convert));var o=i.GEOGCS;i.type==="GEOGCS"&&(o=i),o&&(o.PRIMEM&&o.PRIMEM.convert&&(i.from_greenwich=qi(o.PRIMEM.convert)),o.DATUM?i.datumCode=o.DATUM.name.toLowerCase():i.datumCode=o.name.toLowerCase(),i.datumCode.slice(0,2)==="d_"&&(i.datumCode=i.datumCode.slice(2)),i.datumCode==="new_zealand_1949"&&(i.datumCode="nzgd49"),(i.datumCode==="wgs_1984"||i.datumCode==="world_geodetic_system_1984")&&(i.PROJECTION==="Mercator_Auxiliary_Sphere"&&(i.sphere=!0),i.datumCode="wgs84"),i.datumCode==="belge_1972"&&(i.datumCode="rnb72"),o.DATUM&&o.DATUM.SPHEROID&&(i.ellps=o.DATUM.SPHEROID.name.replace("_19","").replace(/[Cc]larke\_18/,"clrk"),i.ellps.toLowerCase().slice(0,13)==="international"&&(i.ellps="intl"),i.a=o.DATUM.SPHEROID.a,i.rf=parseFloat(o.DATUM.SPHEROID.rf)),o.DATUM&&o.DATUM.TOWGS84&&(i.datum_params=o.DATUM.TOWGS84),~i.datumCode.indexOf("osgb_1936")&&(i.datumCode="osgb36"),~i.datumCode.indexOf("osni_1952")&&(i.datumCode="osni52"),(~i.datumCode.indexOf("tm65")||~i.datumCode.indexOf("geodetic_datum_of_1965"))&&(i.datumCode="ire65"),i.datumCode==="ch1903+"&&(i.datumCode="ch1903"),~i.datumCode.indexOf("israel")&&(i.datumCode="isr93")),i.b&&!isFinite(i.b)&&(i.b=i.a),i.rectified_grid_angle&&(i.rectified_grid_angle=qi(i.rectified_grid_angle));function a(f){var d=i.to_meter||1;return f*d}var l=function(f){return W2(i,f)},h=[["standard_parallel_1","Standard_Parallel_1"],["standard_parallel_1","Latitude of 1st standard parallel"],["standard_parallel_2","Standard_Parallel_2"],["standard_parallel_2","Latitude of 2nd standard parallel"],["false_easting","False_Easting"],["false_easting","False easting"],["false-easting","Easting at false origin"],["false_northing","False_Northing"],["false_northing","False northing"],["false_northing","Northing at false origin"],["central_meridian","Central_Meridian"],["central_meridian","Longitude of natural origin"],["central_meridian","Longitude of false origin"],["latitude_of_origin","Latitude_Of_Origin"],["latitude_of_origin","Central_Parallel"],["latitude_of_origin","Latitude of natural origin"],["latitude_of_origin","Latitude of false origin"],["scale_factor","Scale_Factor"],["k0","scale_factor"],["latitude_of_center","Latitude_Of_Center"],["latitude_of_center","Latitude_of_center"],["lat0","latitude_of_center",qi],["longitude_of_center","Longitude_Of_Center"],["longitude_of_center","Longitude_of_center"],["longc","longitude_of_center",qi],["x0","false_easting",a],["y0","false_northing",a],["long0","central_meridian",qi],["lat0","latitude_of_origin",qi],["lat0","standard_parallel_1",qi],["lat1","standard_parallel_1",qi],["lat2","standard_parallel_2",qi],["azimuth","Azimuth"],["alpha","azimuth",qi],["srsCode","name"]];h.forEach(l),Wv(i)}function Yh(i){if(typeof i=="object")return Uh(i);const t=z2(i);var e=j2(i);if(t==="WKT2"){const r=q2(e);return Uh(r)}var n=e[0],s={};return va(e,s),Kv(s),s[n]}function bn(i){var t=this;if(arguments.length===2){var e=arguments[1];typeof e=="string"?e.charAt(0)==="+"?bn[i]=Gg(arguments[1]):bn[i]=Yh(arguments[1]):e&&typeof e=="object"&&!("projName"in e)?bn[i]=Yh(arguments[1]):(bn[i]=e,e||delete bn[i])}else if(arguments.length===1){if(Array.isArray(i))return i.map(function(n){return Array.isArray(n)?bn.apply(t,n):bn(n)});if(typeof i=="string"){if(i in bn)return bn[i]}else"EPSG"in i?bn["EPSG:"+i.EPSG]=i:"ESRI"in i?bn["ESRI:"+i.ESRI]=i:"IAU2000"in i?bn["IAU2000:"+i.IAU2000]=i:console.log(i);return}}R2(bn);function Z2(i){return typeof i=="string"}function J2(i){return i in bn}function Q2(i){return i.indexOf("+")!==0&&i.indexOf("[")!==-1||typeof i=="object"&&!("srsCode"in i)}var Uy=["3857","900913","3785","102113"];function tM(i){if(i.title)return i.title.toLowerCase().indexOf("epsg:")===0&&Uy.indexOf(i.title.substr(5))>-1;var t=Gr(i,"authority");if(t){var e=Gr(t,"epsg");return e&&Uy.indexOf(e)>-1}}function eM(i){var t=Gr(i,"extension");if(t)return Gr(t,"proj4")}function nM(i){return i[0]==="+"}function iM(i){let t;if(Z2(i))if(J2(i))t=bn[i];else if(Q2(i)){t=Yh(i);var e=eM(t);e&&(t=Gg(e))}else nM(i)&&(t=Gg(i));else"projName"in i?t=i:t=Yh(i);return t&&tM(t)?bn["EPSG:3857"]:t}function Yy(i,t){i=i||{};var e,n;if(!t)return i;for(n in t)e=t[n],e!==void 0&&(i[n]=e);return i}function Zs(i,t,e){var n=i*t;return e/Math.sqrt(1-n*n)}function uc(i){return i<0?-1:1}function Lt(i,t){return t||Math.abs(i)<=en?i:i-uc(i)*Mu}function Es(i,t,e){var n=i*e,s=.5*i;return n=Math.pow((1-n)/(1+n),s),Math.tan(.5*(_t-t))/n}function Lu(i,t){for(var e=.5*i,n,s,r=_t-2*Math.atan(t),o=0;o<=15;o++)if(n=i*Math.sin(r),s=_t-2*Math.atan(t*Math.pow((1-n)/(1+n),e))-r,r+=s,Math.abs(s)<=1e-10)return r;return-9999}function sM(){var i=this.b/this.a;this.es=1-i*i,"x0"in this||(this.x0=0),"y0"in this||(this.y0=0),this.long0=this.long0||0,this.e=Math.sqrt(this.es),this.lat_ts?this.sphere?this.k0=Math.cos(this.lat_ts):this.k0=Zs(this.e,Math.sin(this.lat_ts),Math.cos(this.lat_ts)):this.k0||(this.k?this.k0=this.k:this.k0=1)}function rM(i){var t=i.x,e=i.y;if(e*ai>90&&e*ai<-90&&t*ai>180&&t*ai<-180)return null;var n,s;if(Math.abs(Math.abs(e)-_t)<=Mt)return null;if(this.sphere)n=this.x0+this.a*this.k0*Lt(t-this.long0,this.over),s=this.y0+this.a*this.k0*Math.log(Math.tan(be+.5*e));else{var r=Math.sin(e),o=Es(this.e,e,r);n=this.x0+this.a*this.k0*Lt(t-this.long0,this.over),s=this.y0-this.a*this.k0*Math.log(o)}return i.x=n,i.y=s,i}function oM(i){var t=i.x-this.x0,e=i.y-this.y0,n,s;if(this.sphere)s=_t-2*Math.atan(Math.exp(-e/(this.a*this.k0)));else{var r=Math.exp(-e/(this.a*this.k0));if(s=Lu(this.e,r),s===-9999)return null}return n=Lt(this.long0+t/(this.a*this.k0),this.over),i.x=n,i.y=s,i}var aM=["Mercator","Popular Visualisation Pseudo Mercator","Mercator_1SP","Mercator_Auxiliary_Sphere","Mercator_Variant_A","merc"];const lM={init:sM,forward:rM,inverse:oM,names:aM};function uM(){}function Xy(i){return i}var Zv=["longlat","identity","lonlat","latlon","latlong"];const cM={init:uM,forward:Xy,inverse:Xy,names:Zv};var hM=[lM,cM],go={},Ea=[];function Jv(i,t){var e=Ea.length;return i.names?(Ea[e]=i,i.names.forEach(function(n){go[n.toLowerCase()]=e}),this):(console.log(t),!0)}function Qv(i){return i.replace(/[-\(\)\s]+/g," ").trim().replace(/ /g,"_")}function fM(i){if(!i)return!1;var t=i.toLowerCase();if(typeof go[t]<"u"&&Ea[go[t]]||(t=Qv(t),t in go&&Ea[go[t]]))return Ea[go[t]]}function dM(){hM.forEach(Jv)}const gM={start:dM,add:Jv,get:fM};var tE={MERIT:{a:6378137,rf:298.257,ellipseName:"MERIT 1983"},SGS85:{a:6378136,rf:298.257,ellipseName:"Soviet Geodetic System 85"},GRS80:{a:6378137,rf:298.257222101,ellipseName:"GRS 1980(IUGG, 1980)"},IAU76:{a:6378140,rf:298.257,ellipseName:"IAU 1976"},airy:{a:6377563396e-3,b:635625691e-2,ellipseName:"Airy 1830"},APL4:{a:6378137,rf:298.25,ellipseName:"Appl. Physics. 1965"},NWL9D:{a:6378145,rf:298.25,ellipseName:"Naval Weapons Lab., 1965"},mod_airy:{a:6377340189e-3,b:6356034446e-3,ellipseName:"Modified Airy"},andrae:{a:637710443e-2,rf:300,ellipseName:"Andrae 1876 (Den., Iclnd.)"},aust_SA:{a:6378160,rf:298.25,ellipseName:"Australian Natl & S. Amer. 1969"},GRS67:{a:6378160,rf:298.247167427,ellipseName:"GRS 67(IUGG 1967)"},bessel:{a:6377397155e-3,rf:299.1528128,ellipseName:"Bessel 1841"},bess_nam:{a:6377483865e-3,rf:299.1528128,ellipseName:"Bessel 1841 (Namibia)"},clrk66:{a:63782064e-1,b:63565838e-1,ellipseName:"Clarke 1866"},clrk80:{a:6378249145e-3,rf:293.4663,ellipseName:"Clarke 1880 mod."},clrk80ign:{a:63782492e-1,b:6356515,rf:293.4660213,ellipseName:"Clarke 1880 (IGN)"},clrk58:{a:6378293645208759e-9,rf:294.2606763692654,ellipseName:"Clarke 1858"},CPM:{a:63757387e-1,rf:334.29,ellipseName:"Comm. des Poids et Mesures 1799"},delmbr:{a:6376428,rf:311.5,ellipseName:"Delambre 1810 (Belgium)"},engelis:{a:637813605e-2,rf:298.2566,ellipseName:"Engelis 1985"},evrst30:{a:6377276345e-3,rf:300.8017,ellipseName:"Everest 1830"},evrst48:{a:6377304063e-3,rf:300.8017,ellipseName:"Everest 1948"},evrst56:{a:6377301243e-3,rf:300.8017,ellipseName:"Everest 1956"},evrst69:{a:6377295664e-3,rf:300.8017,ellipseName:"Everest 1969"},evrstSS:{a:6377298556e-3,rf:300.8017,ellipseName:"Everest (Sabah & Sarawak)"},fschr60:{a:6378166,rf:298.3,ellipseName:"Fischer (Mercury Datum) 1960"},fschr60m:{a:6378155,rf:298.3,ellipseName:"Fischer 1960"},fschr68:{a:6378150,rf:298.3,ellipseName:"Fischer 1968"},helmert:{a:6378200,rf:298.3,ellipseName:"Helmert 1906"},hough:{a:6378270,rf:297,ellipseName:"Hough"},intl:{a:6378388,rf:297,ellipseName:"International 1909 (Hayford)"},kaula:{a:6378163,rf:298.24,ellipseName:"Kaula 1961"},lerch:{a:6378139,rf:298.257,ellipseName:"Lerch 1979"},mprts:{a:6397300,rf:191,ellipseName:"Maupertius 1738"},new_intl:{a:63781575e-1,b:63567722e-1,ellipseName:"New International 1967"},plessis:{a:6376523,b:6355863,ellipseName:"Plessis 1817 (France)"},krass:{a:6378245,rf:298.3,ellipseName:"Krassovsky, 1942"},SEasia:{a:6378155,b:63567733205e-4,ellipseName:"Southeast Asia"},walbeck:{a:6376896,b:63558348467e-4,ellipseName:"Walbeck"},WGS60:{a:6378165,rf:298.3,ellipseName:"WGS 60"},WGS66:{a:6378145,rf:298.25,ellipseName:"WGS 66"},WGS7:{a:6378135,rf:298.26,ellipseName:"WGS 72"},WGS84:{a:6378137,rf:298.257223563,ellipseName:"WGS 84"},sphere:{a:6370997,b:6370997,ellipseName:"Normal Sphere (r=6370997)"}};const mM=tE.WGS84;function pM(i,t,e,n){var s=i*i,r=t*t,o=(s-r)/s,a=0;n?(i*=1-o*(F2+o*($2+o*D2)),s=i*i,o=0):a=Math.sqrt(o);var l=(s-r)/r;return{es:o,e:a,ep2:l}}function yM(i,t,e,n,s){if(!i){var r=Gr(tE,n);r||(r=mM),i=r.a,t=r.b,e=r.rf}return e&&!t&&(t=(1-1/e)*i),(e===0||Math.abs(i-t)<Mt)&&(s=!0,t=i),{a:i,b:t,rf:e,sphere:s}}var _h={wgs84:{towgs84:"0,0,0",ellipse:"WGS84",datumName:"WGS84"},ch1903:{towgs84:"674.374,15.056,405.346",ellipse:"bessel",datumName:"swiss"},ggrs87:{towgs84:"-199.87,74.79,246.62",ellipse:"GRS80",datumName:"Greek_Geodetic_Reference_System_1987"},nad83:{towgs84:"0,0,0",ellipse:"GRS80",datumName:"North_American_Datum_1983"},nad27:{nadgrids:"@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat",ellipse:"clrk66",datumName:"North_American_Datum_1927"},potsdam:{towgs84:"598.1,73.7,418.2,0.202,0.045,-2.455,6.7",ellipse:"bessel",datumName:"Potsdam Rauenberg 1950 DHDN"},carthage:{towgs84:"-263.0,6.0,431.0",ellipse:"clrk80ign",datumName:"Carthage 1934 Tunisia"},hermannskogel:{towgs84:"577.326,90.129,463.919,5.137,1.474,5.297,2.4232",ellipse:"bessel",datumName:"Hermannskogel"},mgi:{towgs84:"577.326,90.129,463.919,5.137,1.474,5.297,2.4232",ellipse:"bessel",datumName:"Militar-Geographische Institut"},osni52:{towgs84:"482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15",ellipse:"airy",datumName:"Irish National"},ire65:{towgs84:"482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15",ellipse:"mod_airy",datumName:"Ireland 1965"},rassadiran:{towgs84:"-133.63,-157.5,-158.62",ellipse:"intl",datumName:"Rassadiran"},nzgd49:{towgs84:"59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993",ellipse:"intl",datumName:"New Zealand Geodetic Datum 1949"},osgb36:{towgs84:"446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894",ellipse:"airy",datumName:"Ordnance Survey of Great Britain 1936"},s_jtsk:{towgs84:"589,76,480",ellipse:"bessel",datumName:"S-JTSK (Ferro)"},beduaram:{towgs84:"-106,-87,188",ellipse:"clrk80",datumName:"Beduaram"},gunung_segara:{towgs84:"-403,684,41",ellipse:"bessel",datumName:"Gunung Segara Jakarta"},rnb72:{towgs84:"106.869,-52.2978,103.724,-0.33657,0.456955,-1.84218,1",ellipse:"intl",datumName:"Reseau National Belge 1972"},EPSG_5451:{towgs84:"6.41,-49.05,-11.28,1.5657,0.5242,6.9718,-5.7649"},IGNF_LURESG:{towgs84:"-192.986,13.673,-39.309,-0.4099,-2.9332,2.6881,0.43"},EPSG_4614:{towgs84:"-119.4248,-303.65872,-11.00061,1.164298,0.174458,1.096259,3.657065"},EPSG_4615:{towgs84:"-494.088,-312.129,279.877,-1.423,-1.013,1.59,-0.748"},ESRI_37241:{towgs84:"-76.822,257.457,-12.817,2.136,-0.033,-2.392,-0.031"},ESRI_37249:{towgs84:"-440.296,58.548,296.265,1.128,10.202,4.559,-0.438"},ESRI_37245:{towgs84:"-511.151,-181.269,139.609,1.05,2.703,1.798,3.071"},EPSG_4178:{towgs84:"24.9,-126.4,-93.2,-0.063,-0.247,-0.041,1.01"},EPSG_4622:{towgs84:"-472.29,-5.63,-304.12,0.4362,-0.8374,0.2563,1.8984"},EPSG_4625:{towgs84:"126.93,547.94,130.41,-2.7867,5.1612,-0.8584,13.8227"},EPSG_5252:{towgs84:"0.023,0.036,-0.068,0.00176,0.00912,-0.01136,0.00439"},EPSG_4314:{towgs84:"597.1,71.4,412.1,0.894,0.068,-1.563,7.58"},EPSG_4282:{towgs84:"-178.3,-316.7,-131.5,5.278,6.077,10.979,19.166"},EPSG_4231:{towgs84:"-83.11,-97.38,-117.22,0.005693,-0.044698,0.044285,0.1218"},EPSG_4274:{towgs84:"-230.994,102.591,25.199,0.633,-0.239,0.9,1.95"},EPSG_4134:{towgs84:"-180.624,-225.516,173.919,-0.81,-1.898,8.336,16.71006"},EPSG_4254:{towgs84:"18.38,192.45,96.82,0.056,-0.142,-0.2,-0.0013"},EPSG_4159:{towgs84:"-194.513,-63.978,-25.759,-3.4027,3.756,-3.352,-0.9175"},EPSG_4687:{towgs84:"0.072,-0.507,-0.245,0.0183,-0.0003,0.007,-0.0093"},EPSG_4227:{towgs84:"-83.58,-397.54,458.78,-17.595,-2.847,4.256,3.225"},EPSG_4746:{towgs84:"599.4,72.4,419.2,-0.062,-0.022,-2.723,6.46"},EPSG_4745:{towgs84:"612.4,77,440.2,-0.054,0.057,-2.797,2.55"},EPSG_6311:{towgs84:"8.846,-4.394,-1.122,-0.00237,-0.146528,0.130428,0.783926"},EPSG_4289:{towgs84:"565.7381,50.4018,465.2904,-0.395026,0.330772,-1.876073,4.07244"},EPSG_4230:{towgs84:"-68.863,-134.888,-111.49,-0.53,-0.14,0.57,-3.4"},EPSG_4154:{towgs84:"-123.02,-158.95,-168.47"},EPSG_4156:{towgs84:"570.8,85.7,462.8,4.998,1.587,5.261,3.56"},EPSG_4299:{towgs84:"482.5,-130.6,564.6,-1.042,-0.214,-0.631,8.15"},EPSG_4179:{towgs84:"33.4,-146.6,-76.3,-0.359,-0.053,0.844,-0.84"},EPSG_4313:{towgs84:"-106.8686,52.2978,-103.7239,0.3366,-0.457,1.8422,-1.2747"},EPSG_4194:{towgs84:"163.511,127.533,-159.789"},EPSG_4195:{towgs84:"105,326,-102.5"},EPSG_4196:{towgs84:"-45,417,-3.5"},EPSG_4611:{towgs84:"-162.619,-276.959,-161.764,0.067753,-2.243648,-1.158828,-1.094246"},EPSG_4633:{towgs84:"137.092,131.66,91.475,-1.9436,-11.5993,-4.3321,-7.4824"},EPSG_4641:{towgs84:"-408.809,366.856,-412.987,1.8842,-0.5308,2.1655,-121.0993"},EPSG_4643:{towgs84:"-480.26,-438.32,-643.429,16.3119,20.1721,-4.0349,-111.7002"},EPSG_4300:{towgs84:"482.5,-130.6,564.6,-1.042,-0.214,-0.631,8.15"},EPSG_4188:{towgs84:"482.5,-130.6,564.6,-1.042,-0.214,-0.631,8.15"},EPSG_4660:{towgs84:"982.6087,552.753,-540.873,6.681627,-31.611492,-19.848161,16.805"},EPSG_4662:{towgs84:"97.295,-263.247,310.882,-1.5999,0.8386,3.1409,13.3259"},EPSG_3906:{towgs84:"577.88891,165.22205,391.18289,4.9145,-0.94729,-13.05098,7.78664"},EPSG_4307:{towgs84:"-209.3622,-87.8162,404.6198,0.0046,3.4784,0.5805,-1.4547"},EPSG_6892:{towgs84:"-76.269,-16.683,68.562,-6.275,10.536,-4.286,-13.686"},EPSG_4690:{towgs84:"221.597,152.441,176.523,2.403,1.3893,0.884,11.4648"},EPSG_4691:{towgs84:"218.769,150.75,176.75,3.5231,2.0037,1.288,10.9817"},EPSG_4629:{towgs84:"72.51,345.411,79.241,-1.5862,-0.8826,-0.5495,1.3653"},EPSG_4630:{towgs84:"165.804,216.213,180.26,-0.6251,-0.4515,-0.0721,7.4111"},EPSG_4692:{towgs84:"217.109,86.452,23.711,0.0183,-0.0003,0.007,-0.0093"},EPSG_9333:{towgs84:"0,0,0,-0.008393,0.000749,-0.010276,0"},EPSG_9059:{towgs84:"0,0,0"},EPSG_4312:{towgs84:"601.705,84.263,485.227,4.7354,1.3145,5.393,-2.3887"},EPSG_4123:{towgs84:"-96.062,-82.428,-121.753,4.801,0.345,-1.376,1.496"},EPSG_4309:{towgs84:"-124.45,183.74,44.64,-0.4384,0.5446,-0.9706,-2.1365"},ESRI_104106:{towgs84:"-283.088,-70.693,117.445,-1.157,0.059,-0.652,-4.058"},EPSG_4281:{towgs84:"-219.247,-73.802,269.529"},EPSG_4322:{towgs84:"0,0,4.5"},EPSG_4324:{towgs84:"0,0,1.9"},EPSG_4284:{towgs84:"43.822,-108.842,-119.585,1.455,-0.761,0.737,0.549"},EPSG_4277:{towgs84:"446.448,-125.157,542.06,0.15,0.247,0.842,-20.489"},EPSG_4207:{towgs84:"-282.1,-72.2,120,-1.529,0.145,-0.89,-4.46"},EPSG_4688:{towgs84:"347.175,1077.618,2623.677,33.9058,-70.6776,9.4013,186.0647"},EPSG_4689:{towgs84:"410.793,54.542,80.501,-2.5596,-2.3517,-0.6594,17.3218"},EPSG_4720:{towgs84:"0,0,4.5"},EPSG_4273:{towgs84:"278.3,93,474.5,7.889,0.05,-6.61,6.21"},EPSG_4240:{towgs84:"204.64,834.74,293.8"},EPSG_4817:{towgs84:"278.3,93,474.5,7.889,0.05,-6.61,6.21"},ESRI_104131:{towgs84:"426.62,142.62,460.09,4.98,4.49,-12.42,-17.1"},EPSG_4265:{towgs84:"-104.1,-49.1,-9.9,0.971,-2.917,0.714,-11.68"},EPSG_4263:{towgs84:"-111.92,-87.85,114.5,1.875,0.202,0.219,0.032"},EPSG_4298:{towgs84:"-689.5937,623.84046,-65.93566,-0.02331,1.17094,-0.80054,5.88536"},EPSG_4270:{towgs84:"-253.4392,-148.452,386.5267,0.15605,0.43,-0.1013,-0.0424"},EPSG_4229:{towgs84:"-121.8,98.1,-10.7"},EPSG_4220:{towgs84:"-55.5,-348,-229.2"},EPSG_4214:{towgs84:"12.646,-155.176,-80.863"},EPSG_4232:{towgs84:"-345,3,223"},EPSG_4238:{towgs84:"-1.977,-13.06,-9.993,0.364,0.254,0.689,-1.037"},EPSG_4168:{towgs84:"-170,33,326"},EPSG_4131:{towgs84:"199,931,318.9"},EPSG_4152:{towgs84:"-0.9102,2.0141,0.5602,0.029039,0.010065,0.010101,0"},EPSG_5228:{towgs84:"572.213,85.334,461.94,4.9732,1.529,5.2484,3.5378"},EPSG_8351:{towgs84:"485.021,169.465,483.839,7.786342,4.397554,4.102655,0"},EPSG_4683:{towgs84:"-127.62,-67.24,-47.04,-3.068,4.903,1.578,-1.06"},EPSG_4133:{towgs84:"0,0,0"},EPSG_7373:{towgs84:"0.819,-0.5762,-1.6446,-0.00378,-0.03317,0.00318,0.0693"},EPSG_9075:{towgs84:"-0.9102,2.0141,0.5602,0.029039,0.010065,0.010101,0"},EPSG_9072:{towgs84:"-0.9102,2.0141,0.5602,0.029039,0.010065,0.010101,0"},EPSG_9294:{towgs84:"1.16835,-1.42001,-2.24431,-0.00822,-0.05508,0.01818,0.23388"},EPSG_4212:{towgs84:"-267.434,173.496,181.814,-13.4704,8.7154,7.3926,14.7492"},EPSG_4191:{towgs84:"-44.183,-0.58,-38.489,2.3867,2.7072,-3.5196,-8.2703"},EPSG_4237:{towgs84:"52.684,-71.194,-13.975,-0.312,-0.1063,-0.3729,1.0191"},EPSG_4740:{towgs84:"-1.08,-0.27,-0.9"},EPSG_4124:{towgs84:"419.3836,99.3335,591.3451,0.850389,1.817277,-7.862238,-0.99496"},EPSG_5681:{towgs84:"584.9636,107.7175,413.8067,1.1155,0.2824,-3.1384,7.9922"},EPSG_4141:{towgs84:"23.772,17.49,17.859,-0.3132,-1.85274,1.67299,-5.4262"},EPSG_4204:{towgs84:"-85.645,-273.077,-79.708,2.289,-1.421,2.532,3.194"},EPSG_4319:{towgs84:"226.702,-193.337,-35.371,-2.229,-4.391,9.238,0.9798"},EPSG_4200:{towgs84:"24.82,-131.21,-82.66"},EPSG_4130:{towgs84:"0,0,0"},EPSG_4127:{towgs84:"-82.875,-57.097,-156.768,-2.158,1.524,-0.982,-0.359"},EPSG_4149:{towgs84:"674.374,15.056,405.346"},EPSG_4617:{towgs84:"-0.991,1.9072,0.5129,0.02579,0.00965,0.01166,0"},EPSG_4663:{towgs84:"-210.502,-66.902,-48.476,2.094,-15.067,-5.817,0.485"},EPSG_4664:{towgs84:"-211.939,137.626,58.3,-0.089,0.251,0.079,0.384"},EPSG_4665:{towgs84:"-105.854,165.589,-38.312,-0.003,-0.026,0.024,-0.048"},EPSG_4666:{towgs84:"631.392,-66.551,481.442,1.09,-4.445,-4.487,-4.43"},EPSG_4756:{towgs84:"-192.873,-39.382,-111.202,-0.00205,-0.0005,0.00335,0.0188"},EPSG_4723:{towgs84:"-179.483,-69.379,-27.584,-7.862,8.163,6.042,-13.925"},EPSG_4726:{towgs84:"8.853,-52.644,180.304,-0.393,-2.323,2.96,-24.081"},EPSG_4267:{towgs84:"-8.0,160.0,176.0"},EPSG_5365:{towgs84:"-0.16959,0.35312,0.51846,0.03385,-0.16325,0.03446,0.03693"},EPSG_4218:{towgs84:"304.5,306.5,-318.1"},EPSG_4242:{towgs84:"-33.722,153.789,94.959,-8.581,-4.478,4.54,8.95"},EPSG_4216:{towgs84:"-292.295,248.758,429.447,4.9971,2.99,6.6906,1.0289"},ESRI_104105:{towgs84:"631.392,-66.551,481.442,1.09,-4.445,-4.487,-4.43"},ESRI_104129:{towgs84:"0,0,0"},EPSG_4673:{towgs84:"174.05,-25.49,112.57"},EPSG_4202:{towgs84:"-124,-60,154"},EPSG_4203:{towgs84:"-117.763,-51.51,139.061,0.292,0.443,0.277,-0.191"},EPSG_3819:{towgs84:"595.48,121.69,515.35,4.115,-2.9383,0.853,-3.408"},EPSG_8694:{towgs84:"-93.799,-132.737,-219.073,-1.844,0.648,-6.37,-0.169"},EPSG_4145:{towgs84:"275.57,676.78,229.6"},EPSG_4283:{towgs84:"0.06155,-0.01087,-0.04019,0.039492,0.032722,0.032898,-0.009994"},EPSG_4317:{towgs84:"2.3287,-147.0425,-92.0802,-0.309248,0.324822,0.497299,5.689063"},EPSG_4272:{towgs84:"59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993"},EPSG_4248:{towgs84:"-307.7,265.3,-363.5"},EPSG_5561:{towgs84:"24,-121,-76"},EPSG_5233:{towgs84:"-0.293,766.95,87.713,0.195704,1.695068,3.473016,-0.039338"},ESRI_104130:{towgs84:"-86,-98,-119"},ESRI_104102:{towgs84:"682,-203,480"},ESRI_37207:{towgs84:"7,-10,-26"},EPSG_4675:{towgs84:"59.935,118.4,-10.871"},ESRI_104109:{towgs84:"-89.121,-348.182,260.871"},ESRI_104112:{towgs84:"-185.583,-230.096,281.361"},ESRI_104113:{towgs84:"25.1,-275.6,222.6"},IGNF_WGS72G:{towgs84:"0,12,6"},IGNF_NTFG:{towgs84:"-168,-60,320"},IGNF_EFATE57G:{towgs84:"-127,-769,472"},IGNF_PGP50G:{towgs84:"324.8,153.6,172.1"},IGNF_REUN47G:{towgs84:"94,-948,-1262"},IGNF_CSG67G:{towgs84:"-186,230,110"},IGNF_GUAD48G:{towgs84:"-467,-16,-300"},IGNF_TAHI51G:{towgs84:"162,117,154"},IGNF_TAHAAG:{towgs84:"65,342,77"},IGNF_NUKU72G:{towgs84:"84,274,65"},IGNF_PETRELS72G:{towgs84:"365,194,166"},IGNF_WALL78G:{towgs84:"253,-133,-127"},IGNF_MAYO50G:{towgs84:"-382,-59,-262"},IGNF_TANNAG:{towgs84:"-139,-967,436"},IGNF_IGN72G:{towgs84:"-13,-348,292"},IGNF_ATIGG:{towgs84:"1118,23,66"},IGNF_FANGA84G:{towgs84:"150.57,158.33,118.32"},IGNF_RUSAT84G:{towgs84:"202.13,174.6,-15.74"},IGNF_KAUE70G:{towgs84:"126.74,300.1,-75.49"},IGNF_MOP90G:{towgs84:"-10.8,-1.8,12.77"},IGNF_MHPF67G:{towgs84:"338.08,212.58,-296.17"},IGNF_TAHI79G:{towgs84:"160.61,116.05,153.69"},IGNF_ANAA92G:{towgs84:"1.5,3.84,4.81"},IGNF_MARQUI72G:{towgs84:"330.91,-13.92,58.56"},IGNF_APAT86G:{towgs84:"143.6,197.82,74.05"},IGNF_TUBU69G:{towgs84:"237.17,171.61,-77.84"},IGNF_STPM50G:{towgs84:"11.363,424.148,373.13"},EPSG_4150:{towgs84:"674.374,15.056,405.346"},EPSG_4754:{towgs84:"-208.4058,-109.8777,-2.5764"},ESRI_104101:{towgs84:"372.87,149.23,585.29"},EPSG_4693:{towgs84:"0,-0.15,0.68"},EPSG_6207:{towgs84:"293.17,726.18,245.36"},EPSG_4153:{towgs84:"-133.63,-157.5,-158.62"},EPSG_4132:{towgs84:"-241.54,-163.64,396.06"},EPSG_4221:{towgs84:"-154.5,150.7,100.4"},EPSG_4266:{towgs84:"-80.7,-132.5,41.1"},EPSG_4193:{towgs84:"-70.9,-151.8,-41.4"},EPSG_5340:{towgs84:"-0.41,0.46,-0.35"},EPSG_4246:{towgs84:"-294.7,-200.1,525.5"},EPSG_4318:{towgs84:"-3.2,-5.7,2.8"},EPSG_4121:{towgs84:"-199.87,74.79,246.62"},EPSG_4223:{towgs84:"-260.1,5.5,432.2"},EPSG_4158:{towgs84:"-0.465,372.095,171.736"},EPSG_4285:{towgs84:"-128.16,-282.42,21.93"},EPSG_4613:{towgs84:"-404.78,685.68,45.47"},EPSG_4607:{towgs84:"195.671,332.517,274.607"},EPSG_4475:{towgs84:"-381.788,-57.501,-256.673"},EPSG_4208:{towgs84:"-157.84,308.54,-146.6"},EPSG_4743:{towgs84:"70.995,-335.916,262.898"},EPSG_4710:{towgs84:"-323.65,551.39,-491.22"},EPSG_7881:{towgs84:"-0.077,0.079,0.086"},EPSG_4682:{towgs84:"283.729,735.942,261.143"},EPSG_4739:{towgs84:"-156,-271,-189"},EPSG_4679:{towgs84:"-80.01,253.26,291.19"},EPSG_4750:{towgs84:"-56.263,16.136,-22.856"},EPSG_4644:{towgs84:"-10.18,-350.43,291.37"},EPSG_4695:{towgs84:"-103.746,-9.614,-255.95"},EPSG_4292:{towgs84:"-355,21,72"},EPSG_4302:{towgs84:"-61.702,284.488,472.052"},EPSG_4143:{towgs84:"-124.76,53,466.79"},EPSG_4606:{towgs84:"-153,153,307"},EPSG_4699:{towgs84:"-770.1,158.4,-498.2"},EPSG_4247:{towgs84:"-273.5,110.6,-357.9"},EPSG_4160:{towgs84:"8.88,184.86,106.69"},EPSG_4161:{towgs84:"-233.43,6.65,173.64"},EPSG_9251:{towgs84:"-9.5,122.9,138.2"},EPSG_9253:{towgs84:"-78.1,101.6,133.3"},EPSG_4297:{towgs84:"-198.383,-240.517,-107.909"},EPSG_4269:{towgs84:"0,0,0"},EPSG_4301:{towgs84:"-147,506,687"},EPSG_4618:{towgs84:"-59,-11,-52"},EPSG_4612:{towgs84:"0,0,0"},EPSG_4678:{towgs84:"44.585,-131.212,-39.544"},EPSG_4250:{towgs84:"-130,29,364"},EPSG_4144:{towgs84:"214,804,268"},EPSG_4147:{towgs84:"-17.51,-108.32,-62.39"},EPSG_4259:{towgs84:"-254.1,-5.36,-100.29"},EPSG_4164:{towgs84:"-76,-138,67"},EPSG_4211:{towgs84:"-378.873,676.002,-46.255"},EPSG_4182:{towgs84:"-422.651,-172.995,84.02"},EPSG_4224:{towgs84:"-143.87,243.37,-33.52"},EPSG_4225:{towgs84:"-205.57,168.77,-4.12"},EPSG_5527:{towgs84:"-67.35,3.88,-38.22"},EPSG_4752:{towgs84:"98,390,-22"},EPSG_4310:{towgs84:"-30,190,89"},EPSG_9248:{towgs84:"-192.26,65.72,132.08"},EPSG_4680:{towgs84:"124.5,-63.5,-281"},EPSG_4701:{towgs84:"-79.9,-158,-168.9"},EPSG_4706:{towgs84:"-146.21,112.63,4.05"},EPSG_4805:{towgs84:"682,-203,480"},EPSG_4201:{towgs84:"-165,-11,206"},EPSG_4210:{towgs84:"-157,-2,-299"},EPSG_4183:{towgs84:"-104,167,-38"},EPSG_4139:{towgs84:"11,72,-101"},EPSG_4668:{towgs84:"-86,-98,-119"},EPSG_4717:{towgs84:"-2,151,181"},EPSG_4732:{towgs84:"102,52,-38"},EPSG_4280:{towgs84:"-377,681,-50"},EPSG_4209:{towgs84:"-138,-105,-289"},EPSG_4261:{towgs84:"31,146,47"},EPSG_4658:{towgs84:"-73,46,-86"},EPSG_4721:{towgs84:"265.025,384.929,-194.046"},EPSG_4222:{towgs84:"-136,-108,-292"},EPSG_4601:{towgs84:"-255,-15,71"},EPSG_4602:{towgs84:"725,685,536"},EPSG_4603:{towgs84:"72,213.7,93"},EPSG_4605:{towgs84:"9,183,236"},EPSG_4621:{towgs84:"137,248,-430"},EPSG_4657:{towgs84:"-28,199,5"},EPSG_4316:{towgs84:"103.25,-100.4,-307.19"},EPSG_4642:{towgs84:"-13,-348,292"},EPSG_4698:{towgs84:"145,-187,103"},EPSG_4192:{towgs84:"-206.1,-174.7,-87.7"},EPSG_4311:{towgs84:"-265,120,-358"},EPSG_4135:{towgs84:"58,-283,-182"},ESRI_104138:{towgs84:"198,-226,-347"},EPSG_4245:{towgs84:"-11,851,5"},EPSG_4142:{towgs84:"-125,53,467"},EPSG_4213:{towgs84:"-106,-87,188"},EPSG_4253:{towgs84:"-133,-77,-51"},EPSG_4129:{towgs84:"-132,-110,-335"},EPSG_4713:{towgs84:"-77,-128,142"},EPSG_4239:{towgs84:"217,823,299"},EPSG_4146:{towgs84:"295,736,257"},EPSG_4155:{towgs84:"-83,37,124"},EPSG_4165:{towgs84:"-173,253,27"},EPSG_4672:{towgs84:"175,-38,113"},EPSG_4236:{towgs84:"-637,-549,-203"},EPSG_4251:{towgs84:"-90,40,88"},EPSG_4271:{towgs84:"-2,374,172"},EPSG_4175:{towgs84:"-88,4,101"},EPSG_4716:{towgs84:"298,-304,-375"},EPSG_4315:{towgs84:"-23,259,-9"},EPSG_4744:{towgs84:"-242.2,-144.9,370.3"},EPSG_4244:{towgs84:"-97,787,86"},EPSG_4293:{towgs84:"616,97,-251"},EPSG_4714:{towgs84:"-127,-769,472"},EPSG_4736:{towgs84:"260,12,-147"},EPSG_6883:{towgs84:"-235,-110,393"},EPSG_6894:{towgs84:"-63,176,185"},EPSG_4205:{towgs84:"-43,-163,45"},EPSG_4256:{towgs84:"41,-220,-134"},EPSG_4262:{towgs84:"639,405,60"},EPSG_4604:{towgs84:"174,359,365"},EPSG_4169:{towgs84:"-115,118,426"},EPSG_4620:{towgs84:"-106,-129,165"},EPSG_4184:{towgs84:"-203,141,53"},EPSG_4616:{towgs84:"-289,-124,60"},EPSG_9403:{towgs84:"-307,-92,127"},EPSG_4684:{towgs84:"-133,-321,50"},EPSG_4708:{towgs84:"-491,-22,435"},EPSG_4707:{towgs84:"114,-116,-333"},EPSG_4709:{towgs84:"145,75,-272"},EPSG_4712:{towgs84:"-205,107,53"},EPSG_4711:{towgs84:"124,-234,-25"},EPSG_4718:{towgs84:"230,-199,-752"},EPSG_4719:{towgs84:"211,147,111"},EPSG_4724:{towgs84:"208,-435,-229"},EPSG_4725:{towgs84:"189,-79,-202"},EPSG_4735:{towgs84:"647,1777,-1124"},EPSG_4722:{towgs84:"-794,119,-298"},EPSG_4728:{towgs84:"-307,-92,127"},EPSG_4734:{towgs84:"-632,438,-609"},EPSG_4727:{towgs84:"912,-58,1227"},EPSG_4729:{towgs84:"185,165,42"},EPSG_4730:{towgs84:"170,42,84"},EPSG_4733:{towgs84:"276,-57,149"},ESRI_37218:{towgs84:"230,-199,-752"},ESRI_37240:{towgs84:"-7,215,225"},ESRI_37221:{towgs84:"252,-209,-751"},ESRI_4305:{towgs84:"-123,-206,219"},ESRI_104139:{towgs84:"-73,-247,227"},EPSG_4748:{towgs84:"51,391,-36"},EPSG_4219:{towgs84:"-384,664,-48"},EPSG_4255:{towgs84:"-333,-222,114"},EPSG_4257:{towgs84:"-587.8,519.75,145.76"},EPSG_4646:{towgs84:"-963,510,-359"},EPSG_6881:{towgs84:"-24,-203,268"},EPSG_6882:{towgs84:"-183,-15,273"},EPSG_4715:{towgs84:"-104,-129,239"},IGNF_RGF93GDD:{towgs84:"0,0,0"},IGNF_RGM04GDD:{towgs84:"0,0,0"},IGNF_RGSPM06GDD:{towgs84:"0,0,0"},IGNF_RGTAAF07GDD:{towgs84:"0,0,0"},IGNF_RGFG95GDD:{towgs84:"0,0,0"},IGNF_RGNCG:{towgs84:"0,0,0"},IGNF_RGPFGDD:{towgs84:"0,0,0"},IGNF_ETRS89G:{towgs84:"0,0,0"},IGNF_RGR92GDD:{towgs84:"0,0,0"},EPSG_4173:{towgs84:"0,0,0"},EPSG_4180:{towgs84:"0,0,0"},EPSG_4619:{towgs84:"0,0,0"},EPSG_4667:{towgs84:"0,0,0"},EPSG_4075:{towgs84:"0,0,0"},EPSG_6706:{towgs84:"0,0,0"},EPSG_7798:{towgs84:"0,0,0"},EPSG_4661:{towgs84:"0,0,0"},EPSG_4669:{towgs84:"0,0,0"},EPSG_8685:{towgs84:"0,0,0"},EPSG_4151:{towgs84:"0,0,0"},EPSG_9702:{towgs84:"0,0,0"},EPSG_4758:{towgs84:"0,0,0"},EPSG_4761:{towgs84:"0,0,0"},EPSG_4765:{towgs84:"0,0,0"},EPSG_8997:{towgs84:"0,0,0"},EPSG_4023:{towgs84:"0,0,0"},EPSG_4670:{towgs84:"0,0,0"},EPSG_4694:{towgs84:"0,0,0"},EPSG_4148:{towgs84:"0,0,0"},EPSG_4163:{towgs84:"0,0,0"},EPSG_4167:{towgs84:"0,0,0"},EPSG_4189:{towgs84:"0,0,0"},EPSG_4190:{towgs84:"0,0,0"},EPSG_4176:{towgs84:"0,0,0"},EPSG_4659:{towgs84:"0,0,0"},EPSG_3824:{towgs84:"0,0,0"},EPSG_3889:{towgs84:"0,0,0"},EPSG_4046:{towgs84:"0,0,0"},EPSG_4081:{towgs84:"0,0,0"},EPSG_4558:{towgs84:"0,0,0"},EPSG_4483:{towgs84:"0,0,0"},EPSG_5013:{towgs84:"0,0,0"},EPSG_5264:{towgs84:"0,0,0"},EPSG_5324:{towgs84:"0,0,0"},EPSG_5354:{towgs84:"0,0,0"},EPSG_5371:{towgs84:"0,0,0"},EPSG_5373:{towgs84:"0,0,0"},EPSG_5381:{towgs84:"0,0,0"},EPSG_5393:{towgs84:"0,0,0"},EPSG_5489:{towgs84:"0,0,0"},EPSG_5593:{towgs84:"0,0,0"},EPSG_6135:{towgs84:"0,0,0"},EPSG_6365:{towgs84:"0,0,0"},EPSG_5246:{towgs84:"0,0,0"},EPSG_7886:{towgs84:"0,0,0"},EPSG_8431:{towgs84:"0,0,0"},EPSG_8427:{towgs84:"0,0,0"},EPSG_8699:{towgs84:"0,0,0"},EPSG_8818:{towgs84:"0,0,0"},EPSG_4757:{towgs84:"0,0,0"},EPSG_9140:{towgs84:"0,0,0"},EPSG_8086:{towgs84:"0,0,0"},EPSG_4686:{towgs84:"0,0,0"},EPSG_4737:{towgs84:"0,0,0"},EPSG_4702:{towgs84:"0,0,0"},EPSG_4747:{towgs84:"0,0,0"},EPSG_4749:{towgs84:"0,0,0"},EPSG_4674:{towgs84:"0,0,0"},EPSG_4755:{towgs84:"0,0,0"},EPSG_4759:{towgs84:"0,0,0"},EPSG_4762:{towgs84:"0,0,0"},EPSG_4763:{towgs84:"0,0,0"},EPSG_4764:{towgs84:"0,0,0"},EPSG_4166:{towgs84:"0,0,0"},EPSG_4170:{towgs84:"0,0,0"},EPSG_5546:{towgs84:"0,0,0"},EPSG_7844:{towgs84:"0,0,0"},EPSG_4818:{towgs84:"589,76,480"},EPSG_10328:{towgs84:"0,0,0"},EPSG_9782:{towgs84:"0,0,0"},EPSG_9777:{towgs84:"0,0,0"},EPSG_10690:{towgs84:"0,0,0"},EPSG_10639:{towgs84:"0,0,0"},EPSG_10739:{towgs84:"0,0,0"},EPSG_7686:{towgs84:"0,0,0"},EPSG_8900:{towgs84:"0,0,0"},EPSG_5886:{towgs84:"0,0,0"},EPSG_7683:{towgs84:"0,0,0"},EPSG_6668:{towgs84:"0,0,0"},EPSG_20046:{towgs84:"0,0,0"},EPSG_10299:{towgs84:"0,0,0"},EPSG_10310:{towgs84:"0,0,0"},EPSG_10475:{towgs84:"0,0,0"},EPSG_4742:{towgs84:"0,0,0"},EPSG_10671:{towgs84:"0,0,0"},EPSG_10762:{towgs84:"0,0,0"},EPSG_10725:{towgs84:"0,0,0"},EPSG_10791:{towgs84:"0,0,0"},EPSG_10800:{towgs84:"0,0,0"},EPSG_10305:{towgs84:"0,0,0"},EPSG_10941:{towgs84:"0,0,0"},EPSG_10968:{towgs84:"0,0,0"},EPSG_10875:{towgs84:"0,0,0"},EPSG_6318:{towgs84:"0,0,0"},EPSG_10910:{towgs84:"0,0,0"}};for(var _M in _h){var zd=_h[_M];zd.datumName&&(_h[zd.datumName]=zd)}function vM(i,t,e,n,s,r,o){var a={};return a.datum_type=Dg,t&&(a.datum_type=A2,a.datum_params=t.map(parseFloat),(a.datum_params[0]!==0||a.datum_params[1]!==0||a.datum_params[2]!==0)&&(a.datum_type=Po),a.datum_params.length>3&&(a.datum_params[3]!==0||a.datum_params[4]!==0||a.datum_params[5]!==0||a.datum_params[6]!==0)&&(a.datum_type=ko,a.datum_params[3]*=gu,a.datum_params[4]*=gu,a.datum_params[5]*=gu,a.datum_params[6]=a.datum_params[6]/1e6+1)),o&&(a.datum_type=Pa,a.grids=o),a.a=e,a.b=n,a.es=s,a.ep2=r,a}var Gm={};function EM(i,t,e){return t instanceof ArrayBuffer?wM(i,t,e):{ready:xM(i,t)}}function wM(i,t,e){var n=!0;e!==void 0&&e.includeErrorFields===!1&&(n=!1);var s=new DataView(t),r=SM(s),o=MM(s,r),a=NM(s,o,r,n),l={header:o,subgrids:a};return Gm[i]=l,l}async function xM(i,t){for(var e=[],n=await t.getImageCount(),s=n-1;s>=0;s--){var r=await t.getImage(s),o=await r.readRasters(),a=o,l=[r.getWidth(),r.getHeight()],h=r.getBoundingBox().map(jy),f=typeof r.fileDirectory.getValue=="function"?r.fileDirectory.getValue("ModelPixelScale"):r.fileDirectory.ModelPixelScale,d=[f[0],f[1]].map(jy),p=h[0]+(l[0]-1)*d[0],y=h[3]-(l[1]-1)*d[1],_=a[0],E=a[1],w=[];for(let P=l[1]-1;P>=0;P--)for(let N=l[0]-1;N>=0;N--){var L=P*l[0]+N;w.push([-Tr(E[L]),Tr(_[L])])}e.push({del:d,lim:l,ll:[-p,y],cvs:w})}var b={header:{nSubgrids:n},subgrids:e};return Gm[i]=b,b}function bM(i){if(i===void 0)return null;var t=i.split(",");return t.map(IM)}function IM(i){if(i.length===0)return null;var t=i[0]==="@";return t&&(i=i.slice(1)),i==="null"?{name:"null",mandatory:!t,grid:null,isNull:!0}:{name:i,mandatory:!t,grid:Gm[i]||null,isNull:!1}}function jy(i){return i*Math.PI/180}function Tr(i){return i/3600*Math.PI/180}function SM(i){var t=i.getInt32(8,!1);return t===11?!1:(t=i.getInt32(8,!0),t!==11&&console.warn("Failed to detect nadgrid endian-ness, defaulting to little-endian"),!0)}function MM(i,t){return{nFields:i.getInt32(8,t),nSubgridFields:i.getInt32(24,t),nSubgrids:i.getInt32(40,t),shiftType:Bg(i,56,64).trim(),fromSemiMajorAxis:i.getFloat64(120,t),fromSemiMinorAxis:i.getFloat64(136,t),toSemiMajorAxis:i.getFloat64(152,t),toSemiMinorAxis:i.getFloat64(168,t)}}function Bg(i,t,e){return String.fromCharCode.apply(null,new Uint8Array(i.buffer.slice(t,e)))}function NM(i,t,e,n){for(var s=176,r=[],o=0;o<t.nSubgrids;o++){var a=CM(i,s,e),l=PM(i,s,a,e,n),h=Math.round(1+(a.upperLongitude-a.lowerLongitude)/a.longitudeInterval),f=Math.round(1+(a.upperLatitude-a.lowerLatitude)/a.latitudeInterval);r.push({ll:[Tr(a.lowerLongitude),Tr(a.lowerLatitude)],del:[Tr(a.longitudeInterval),Tr(a.latitudeInterval)],lim:[h,f],count:a.gridNodeCount,cvs:LM(l)});var d=16;n===!1&&(d=8),s+=176+a.gridNodeCount*d}return r}function LM(i){return i.map(function(t){return[Tr(t.longitudeShift),Tr(t.latitudeShift)]})}function CM(i,t,e){return{name:Bg(i,t+8,t+16).trim(),parent:Bg(i,t+24,t+24+8).trim(),lowerLatitude:i.getFloat64(t+72,e),upperLatitude:i.getFloat64(t+88,e),lowerLongitude:i.getFloat64(t+104,e),upperLongitude:i.getFloat64(t+120,e),latitudeInterval:i.getFloat64(t+136,e),longitudeInterval:i.getFloat64(t+152,e),gridNodeCount:i.getInt32(t+168,e)}}function PM(i,t,e,n,s){var r=t+176,o=16;s===!1&&(o=8);for(var a=[],l=0;l<e.gridNodeCount;l++){var h={latitudeShift:i.getFloat32(r+l*o,n),longitudeShift:i.getFloat32(r+l*o+4,n)};s!==!1&&(h.latitudeAccuracy=i.getFloat32(r+l*o+8,n),h.longitudeAccuracy=i.getFloat32(r+l*o+12,n)),a.push(h)}return a}function Ji(i,t){if(!(this instanceof Ji))return new Ji(i);this.forward=null,this.inverse=null,this.init=null,this.name,this.axis,this.names=null,this.title,t=t||function(h){if(h)throw h};var e=iM(i);if(typeof e!="object"){t("Could not parse to valid json: "+i);return}var n=Ji.projections.get(e.projName);if(!n){t("Could not get projection name from: "+i);return}if(e.datumCode&&e.datumCode!=="none"){var s=Gr(_h,e.datumCode);s&&(e.datum_params=e.datum_params||(s.towgs84?s.towgs84.split(","):null),e.ellps=s.ellipse,e.datumName=s.datumName?s.datumName:e.datumCode)}e.axis=e.axis||"enu",e.ellps=e.ellps||"wgs84",e.lat1=e.lat1||e.lat0;var r=yM(e.a,e.b,e.rf,e.ellps,e.sphere),o=pM(r.a,r.b,r.rf,e.R_A),a=bM(e.nadgrids),l=e.datum||vM(e.datumCode,e.datum_params,r.a,r.b,o.es,o.ep2,a);Yy(this,e),Yy(this,n),this.a=r.a,this.b=r.b,this.rf=r.rf,this.sphere=r.sphere,this.es=o.es,this.e=o.e,this.ep2=o.ep2,this.datum=l,"init"in this&&typeof this.init=="function"&&this.init(),this.k0||(this.k0=1),t(null,this)}Ji.projections=gM;Ji.projections.start();function kM(i,t){return i.datum_type!==t.datum_type||i.a!==t.a||Math.abs(i.es-t.es)>5e-11?!1:i.datum_type===Po?i.datum_params[0]===t.datum_params[0]&&i.datum_params[1]===t.datum_params[1]&&i.datum_params[2]===t.datum_params[2]:i.datum_type===ko?i.datum_params[0]===t.datum_params[0]&&i.datum_params[1]===t.datum_params[1]&&i.datum_params[2]===t.datum_params[2]&&i.datum_params[3]===t.datum_params[3]&&i.datum_params[4]===t.datum_params[4]&&i.datum_params[5]===t.datum_params[5]&&i.datum_params[6]===t.datum_params[6]:!0}function eE(i,t,e){var n=i.x,s=i.y,r=i.z?i.z:0,o,a,l,h;if(s<-_t&&s>-1.001*_t)s=-_t;else if(s>_t&&s<1.001*_t)s=_t;else{if(s<-_t)return{x:-1/0,y:-1/0,z:i.z};if(s>_t)return{x:1/0,y:1/0,z:i.z}}return n>Math.PI&&(n-=2*Math.PI),a=Math.sin(s),h=Math.cos(s),l=a*a,o=e/Math.sqrt(1-t*l),{x:(o+r)*h*Math.cos(n),y:(o+r)*h*Math.sin(n),z:(o*(1-t)+r)*a}}function nE(i,t,e,n){var s=1e-12,r=s*s,o=30,a,l,h,f,d,p,y,_,E,w,L,b,P,N=i.x,S=i.y,C=i.z?i.z:0,T,I,M;if(a=Math.sqrt(N*N+S*S),l=Math.sqrt(N*N+S*S+C*C),a/e<s){if(T=0,l/e<s)return I=_t,M=-n,{x:i.x,y:i.y,z:i.z}}else T=Math.atan2(S,N);h=C/l,f=a/l,d=1/Math.sqrt(1-t*(2-t)*f*f),_=f*(1-t)*d,E=h*d,P=0;do P++,y=e/Math.sqrt(1-t*E*E),M=a*_+C*E-y*(1-t*E*E),p=t*y/(y+M),d=1/Math.sqrt(1-p*(2-p)*f*f),w=f*(1-p)*d,L=h*d,b=L*_-w*E,_=w,E=L;while(b*b>r&&P<o);return I=Math.atan(L/Math.abs(w)),{x:T,y:I,z:M}}function TM(i,t,e){if(t===Po)return{x:i.x+e[0],y:i.y+e[1],z:i.z+e[2]};if(t===ko){var n=e[0],s=e[1],r=e[2],o=e[3],a=e[4],l=e[5],h=e[6];return{x:h*(i.x-l*i.y+a*i.z)+n,y:h*(l*i.x+i.y-o*i.z)+s,z:h*(-a*i.x+o*i.y+i.z)+r}}}function RM(i,t,e){if(t===Po)return{x:i.x-e[0],y:i.y-e[1],z:i.z-e[2]};if(t===ko){var n=e[0],s=e[1],r=e[2],o=e[3],a=e[4],l=e[5],h=e[6],f=(i.x-n)/h,d=(i.y-s)/h,p=(i.z-r)/h;return{x:f+l*d-a*p,y:-l*f+d+o*p,z:a*f-o*d+p}}}function Gc(i){return i===Po||i===ko}function AM(i,t,e){if(kM(i,t)||i.datum_type===Dg||t.datum_type===Dg)return e;var n=i.a,s=i.es;if(i.datum_type===Pa){var r=Vy(i,!1,e);if(r!==0)return;n=$y,s=Dy}var o=t.a,a=t.b,l=t.es;if(t.datum_type===Pa&&(o=$y,a=O2,l=Dy),s===l&&n===o&&!Gc(i.datum_type)&&!Gc(t.datum_type))return e;if(e=eE(e,s,n),Gc(i.datum_type)&&(e=TM(e,i.datum_type,i.datum_params)),Gc(t.datum_type)&&(e=RM(e,t.datum_type,t.datum_params)),e=nE(e,l,o,a),t.datum_type===Pa){var h=Vy(t,!0,e);if(h!==0)return}return e}function Vy(i,t,e){if(i.grids===null||i.grids.length===0)return console.log("Grid shift grids not found"),-1;var n={x:-e.x,y:e.y},s={x:Number.NaN,y:Number.NaN},r=[];t:for(var o=0;o<i.grids.length;o++){var a=i.grids[o];if(r.push(a.name),a.isNull){s=n;break}if(a.grid===null){if(a.mandatory)return console.log("Unable to find mandatory grid '"+a.name+"'"),-1;continue}for(var l=a.grid.subgrids,h=0,f=l.length;h<f;h++){var d=l[h],p=(Math.abs(d.del[1])+Math.abs(d.del[0]))/1e4,y=d.ll[0]-p,_=d.ll[1]-p,E=d.ll[0]+(d.lim[0]-1)*d.del[0]+p,w=d.ll[1]+(d.lim[1]-1)*d.del[1]+p;if(!(_>n.y||y>n.x||w<n.y||E<n.x)&&(s=OM(n,t,d),!isNaN(s.x)))break t}}return isNaN(s.x)?(console.log("Failed to find a grid shift table for location '"+-n.x*ai+" "+n.y*ai+" tried: '"+r+"'"),-1):(e.x=-s.x,e.y=s.y,0)}function OM(i,t,e){var n={x:Number.NaN,y:Number.NaN};if(isNaN(i.x))return n;var s={x:i.x,y:i.y};s.x-=e.ll[0],s.y-=e.ll[1],s.x=Lt(s.x-Math.PI)+Math.PI;var r=Hy(s,e);if(t){if(isNaN(r.x))return n;r.x=s.x-r.x,r.y=s.y-r.y;var o=9,a=1e-12,l,h;do{if(h=Hy(r,e),isNaN(h.x)){console.log("Inverse grid shift iteration failed, presumably at grid edge. Using first approximation.");break}l={x:s.x-(h.x+r.x),y:s.y-(h.y+r.y)},r.x+=l.x,r.y+=l.y}while(o--&&Math.abs(l.x)>a&&Math.abs(l.y)>a);if(o<0)return console.log("Inverse grid shift iterator failed to converge."),n;n.x=Lt(r.x+e.ll[0]),n.y=r.y+e.ll[1]}else isNaN(r.x)||(n.x=i.x+r.x,n.y=i.y+r.y);return n}function Hy(i,t){var e={x:i.x/t.del[0],y:i.y/t.del[1]},n={x:Math.floor(e.x),y:Math.floor(e.y)},s={x:e.x-1*n.x,y:e.y-1*n.y},r={x:Number.NaN,y:Number.NaN},o;if(n.x<0||n.x>=t.lim[0]||n.y<0||n.y>=t.lim[1])return r;o=n.y*t.lim[0]+n.x;var a={x:t.cvs[o][0],y:t.cvs[o][1]};o++;var l={x:t.cvs[o][0],y:t.cvs[o][1]};o+=t.lim[0];var h={x:t.cvs[o][0],y:t.cvs[o][1]};o--;var f={x:t.cvs[o][0],y:t.cvs[o][1]},d=s.x*s.y,p=s.x*(1-s.y),y=(1-s.x)*(1-s.y),_=(1-s.x)*s.y;return r.x=y*a.x+p*l.x+_*f.x+d*h.x,r.y=y*a.y+p*l.y+_*f.y+d*h.y,r}var mo=["x","y","z"];function FM(i,t){const e={};for(let n=0,s=i.axis.length;n<s;n++){if(n===2&&t.z===void 0)continue;let r=t[mo[n]];switch(i.axis[n]){case"e":e.x=r;break;case"w":e.x=-r;break;case"n":e.y=r;break;case"s":e.y=-r;break;case"u":e.z=r;break;case"d":e.z=-r;break;default:return null}}return e}function $M(i,t){const e={};for(let n=0,s=i.axis.length;n<s;n++)if(!(n===2&&t.z===void 0))switch(i.axis[n]){case"e":e[mo[n]]=t.x;break;case"w":e[mo[n]]=-t.x;break;case"n":e[mo[n]]=t.y;break;case"s":e[mo[n]]=-t.y;break;case"u":e[mo[n]]=t.z;break;case"d":e[mo[n]]=-t.z;break;default:return null}return e}function Bm(i){var t={x:i[0],y:i[1]};return i.length>2&&(t.z=i[2]),i.length>3&&(t.m=i[3]),t}function DM(i){Wy(i.x),Wy(i.y)}function Wy(i){if(typeof Number.isFinite=="function"){if(Number.isFinite(i))return;throw new TypeError("coordinates must be finite numbers")}if(typeof i!="number"||i!==i||!isFinite(i))throw new TypeError("coordinates must be finite numbers")}function GM(i,t){return(i.datum.datum_type===Po||i.datum.datum_type===ko||i.datum.datum_type===Pa)&&t.datumCode!=="WGS84"||(t.datum.datum_type===Po||t.datum.datum_type===ko||t.datum.datum_type===Pa)&&i.datumCode!=="WGS84"}function Xh(i,t,e,n){var s,r=e.z!==void 0;if(DM(e),i.datum&&t.datum&&GM(i,t)&&(s=new Ji("WGS84"),e=Xh(i,s,e,n),i=s),n&&i.axis!=="enu"&&(e=FM(i,e)),i.projName==="longlat")e={x:e.x*We,y:e.y*We,z:e.z||0};else if(i.to_meter&&(e={x:e.x*i.to_meter,y:e.y*i.to_meter,z:e.z||0}),e=i.inverse(e),!e)return;if(i.from_greenwich&&(e.x+=i.from_greenwich),e=AM(i.datum,t.datum,e),!!e)return e=e,t.from_greenwich&&(e={x:e.x-t.from_greenwich,y:e.y,z:e.z||0}),t.projName==="longlat"?(t.long_wrap!==void 0&&(e.x=t.long_wrap+Lt(e.x-t.long_wrap)),e={x:e.x*ai,y:e.y*ai,z:e.z||0}):(e=t.forward(e),t.to_meter&&(e={x:e.x/t.to_meter,y:e.y/t.to_meter,z:e.z||0})),n&&t.axis!=="enu"?$M(t,e):(e&&!r&&t.projName!=="geocent"&&delete e.z,e)}function BM(i,t,e,n){var s;return Array.isArray(e)?s=Bm(e):s={x:e.x,y:e.y,z:e.z,m:e.m},Xh(i,t,s,n)}var Ky=Ji("WGS84");function Ud(i,t,e,n){var s,r,o;return Array.isArray(e)?(s=Xh(i,t,Bm(e),n)||{x:NaN,y:NaN},e.length>2?(r=typeof i.name<"u"&&i.name==="geocent"||typeof t.name<"u"&&t.name==="geocent",r?typeof s.z=="number"?[s.x,s.y,s.z].concat(e.slice(3)):[s.x,s.y,e[2]].concat(e.slice(3)):n&&typeof s.z=="number"?[s.x,s.y,s.z].concat(e.slice(3)):[s.x,s.y].concat(e.slice(2))):[s.x,s.y]):(s=Xh(i,t,{x:e.x,y:e.y,z:e.z,m:e.m},n)||{x:NaN,y:NaN},o=Object.keys(e),o.length===2||(r=typeof i.name<"u"&&i.name==="geocent"||typeof t.name<"u"&&t.name==="geocent",o.forEach(function(a){a==="x"||a==="y"||a==="z"&&(r||n)||(s[a]=e[a])})),s)}function Bc(i){return i instanceof Ji?i:typeof i=="object"&&"oProj"in i?i.oProj:Ji(i)}function qM(i,t,e){var n,s,r=!1,o;return typeof t>"u"?(s=Bc(i),n=Ky,r=!0):(typeof t.x<"u"||Array.isArray(t))&&(e=t,s=Bc(i),n=Ky,r=!0),n||(n=Bc(i)),s||(s=Bc(t)),e?Ud(n,s,e):(o={forward:function(a,l){return Ud(n,s,a,l)},inverse:function(a,l){return Ud(s,n,a,l)}},r&&(o.oProj=s),o)}var Zy=6,iE="AJSAJS",sE="AFAFAF",wa=65,Qn=73,zi=79,tu=86,eu=90;const zM={forward:rE,inverse:UM,toPoint:oE};function rE(i,t){return t=t||5,jM(YM({lat:i[1],lon:i[0]}),t)}function UM(i){var t=qm(lE(i.toUpperCase()));return t.lat&&t.lon?[t.lon,t.lat,t.lon,t.lat]:[t.left,t.bottom,t.right,t.top]}function oE(i){var t=qm(lE(i.toUpperCase()));return t.lat&&t.lon?[t.lon,t.lat]:[(t.left+t.right)/2,(t.top+t.bottom)/2]}function Yd(i){return i*(Math.PI/180)}function Jy(i){return 180*(i/Math.PI)}function YM(i){var t=i.lat,e=i.lon,n=6378137,s=.00669438,r=.9996,o,a,l,h,f,d,p,y=Yd(t),_=Yd(e),E,w;w=Math.floor((e+180)/6)+1,e===180&&(w=60),t>=56&&t<64&&e>=3&&e<12&&(w=32),t>=72&&t<84&&(e>=0&&e<9?w=31:e>=9&&e<21?w=33:e>=21&&e<33?w=35:e>=33&&e<42&&(w=37)),o=(w-1)*6-180+3,E=Yd(o),a=s/(1-s),l=n/Math.sqrt(1-s*Math.sin(y)*Math.sin(y)),h=Math.tan(y)*Math.tan(y),f=a*Math.cos(y)*Math.cos(y),d=Math.cos(y)*(_-E),p=n*((1-s/4-3*s*s/64-5*s*s*s/256)*y-(3*s/8+3*s*s/32+45*s*s*s/1024)*Math.sin(2*y)+(15*s*s/256+45*s*s*s/1024)*Math.sin(4*y)-35*s*s*s/3072*Math.sin(6*y));var L=r*l*(d+(1-h+f)*d*d*d/6+(5-18*h+h*h+72*f-58*a)*d*d*d*d*d/120)+5e5,b=r*(p+l*Math.tan(y)*(d*d/2+(5-h+9*f+4*f*f)*d*d*d*d/24+(61-58*h+h*h+600*f-330*a)*d*d*d*d*d*d/720));return t<0&&(b+=1e7),{northing:Math.round(b),easting:Math.round(L),zoneNumber:w,zoneLetter:XM(t)}}function qm(i){var t=i.northing,e=i.easting,n=i.zoneLetter,s=i.zoneNumber;if(s<0||s>60)return null;var r=.9996,o=6378137,a=.00669438,l,h=(1-Math.sqrt(1-a))/(1+Math.sqrt(1-a)),f,d,p,y,_,E,w,L,b,P=e-5e5,N=t;n<"N"&&(N-=1e7),w=(s-1)*6-180+3,l=a/(1-a),E=N/r,L=E/(o*(1-a/4-3*a*a/64-5*a*a*a/256)),b=L+(3*h/2-27*h*h*h/32)*Math.sin(2*L)+(21*h*h/16-55*h*h*h*h/32)*Math.sin(4*L)+151*h*h*h/96*Math.sin(6*L),f=o/Math.sqrt(1-a*Math.sin(b)*Math.sin(b)),d=Math.tan(b)*Math.tan(b),p=l*Math.cos(b)*Math.cos(b),y=o*(1-a)/Math.pow(1-a*Math.sin(b)*Math.sin(b),1.5),_=P/(f*r);var S=b-f*Math.tan(b)/y*(_*_/2-(5+3*d+10*p-4*p*p-9*l)*_*_*_*_/24+(61+90*d+298*p+45*d*d-252*l-3*p*p)*_*_*_*_*_*_/720);S=Jy(S);var C=(_-(1+2*d+p)*_*_*_/6+(5-2*p+28*d-3*p*p+8*l+24*d*d)*_*_*_*_*_/120)/Math.cos(b);C=w+Jy(C);var T;if(i.accuracy){var I=qm({northing:i.northing+i.accuracy,easting:i.easting+i.accuracy,zoneLetter:i.zoneLetter,zoneNumber:i.zoneNumber});T={top:I.lat,right:I.lon,bottom:S,left:C}}else T={lat:S,lon:C};return T}function XM(i){var t="Z";return 84>=i&&i>=72?t="X":72>i&&i>=64?t="W":64>i&&i>=56?t="V":56>i&&i>=48?t="U":48>i&&i>=40?t="T":40>i&&i>=32?t="S":32>i&&i>=24?t="R":24>i&&i>=16?t="Q":16>i&&i>=8?t="P":8>i&&i>=0?t="N":0>i&&i>=-8?t="M":-8>i&&i>=-16?t="L":-16>i&&i>=-24?t="K":-24>i&&i>=-32?t="J":-32>i&&i>=-40?t="H":-40>i&&i>=-48?t="G":-48>i&&i>=-56?t="F":-56>i&&i>=-64?t="E":-64>i&&i>=-72?t="D":-72>i&&i>=-80&&(t="C"),t}function jM(i,t){var e="00000"+i.easting,n="00000"+i.northing;return i.zoneNumber+i.zoneLetter+VM(i.easting,i.northing,i.zoneNumber)+e.substr(e.length-5,t)+n.substr(n.length-5,t)}function VM(i,t,e){var n=aE(e),s=Math.floor(i/1e5),r=Math.floor(t/1e5)%20;return HM(s,r,n)}function aE(i){var t=i%Zy;return t===0&&(t=Zy),t}function HM(i,t,e){var n=e-1,s=iE.charCodeAt(n),r=sE.charCodeAt(n),o=s+i-1,a=r+t,l=!1;o>eu&&(o=o-eu+wa-1,l=!0),(o===Qn||s<Qn&&o>Qn||(o>Qn||s<Qn)&&l)&&o++,(o===zi||s<zi&&o>zi||(o>zi||s<zi)&&l)&&(o++,o===Qn&&o++),o>eu&&(o=o-eu+wa-1),a>tu?(a=a-tu+wa-1,l=!0):l=!1,(a===Qn||r<Qn&&a>Qn||(a>Qn||r<Qn)&&l)&&a++,(a===zi||r<zi&&a>zi||(a>zi||r<zi)&&l)&&(a++,a===Qn&&a++),a>tu&&(a=a-tu+wa-1);var h=String.fromCharCode(o)+String.fromCharCode(a);return h}function lE(i){if(i&&i.length===0)throw"MGRSPoint coverting from nothing";for(var t=i.length,e=null,n="",s,r=0;!/[A-Z]/.test(s=i.charAt(r));){if(r>=2)throw"MGRSPoint bad conversion from: "+i;n+=s,r++}var o=parseInt(n,10);if(r===0||r+3>t)throw"MGRSPoint bad conversion from: "+i;var a=i.charAt(r++);if(a<="A"||a==="B"||a==="Y"||a>="Z"||a==="I"||a==="O")throw"MGRSPoint zone letter "+a+" not handled: "+i;e=i.substring(r,r+=2);for(var l=aE(o),h=WM(e.charAt(0),l),f=KM(e.charAt(1),l);f<ZM(a);)f+=2e6;var d=t-r;if(d%2!==0)throw`MGRSPoint has to have an even number
|
|
2
|
+
of digits after the zone letter and two 100km letters - front
|
|
3
|
+
half for easting meters, second half for
|
|
4
|
+
northing meters`+i;var p=d/2,y=0,_=0,E,w,L,b,P;return p>0&&(E=1e5/Math.pow(10,p),w=i.substring(r,r+p),y=parseFloat(w)*E,L=i.substring(r+p),_=parseFloat(L)*E),b=y+h,P=_+f,{easting:b,northing:P,zoneLetter:a,zoneNumber:o,accuracy:E}}function WM(i,t){for(var e=iE.charCodeAt(t-1),n=1e5,s=!1;e!==i.charCodeAt(0);){if(e++,e===Qn&&e++,e===zi&&e++,e>eu){if(s)throw"Bad character: "+i;e=wa,s=!0}n+=1e5}return n}function KM(i,t){if(i>"V")throw"MGRSPoint given invalid Northing "+i;for(var e=sE.charCodeAt(t-1),n=0,s=!1;e!==i.charCodeAt(0);){if(e++,e===Qn&&e++,e===zi&&e++,e>tu){if(s)throw"Bad character: "+i;e=wa,s=!0}n+=1e5}return n}function ZM(i){var t;switch(i){case"C":t=11e5;break;case"D":t=2e6;break;case"E":t=28e5;break;case"F":t=37e5;break;case"G":t=46e5;break;case"H":t=55e5;break;case"J":t=64e5;break;case"K":t=73e5;break;case"L":t=82e5;break;case"M":t=91e5;break;case"N":t=0;break;case"P":t=8e5;break;case"Q":t=17e5;break;case"R":t=26e5;break;case"S":t=35e5;break;case"T":t=44e5;break;case"U":t=53e5;break;case"V":t=62e5;break;case"W":t=7e6;break;case"X":t=79e5;break;default:t=-1}if(t>=0)return t;throw"Invalid zone letter: "+i}function Ha(i,t,e){if(!(this instanceof Ha))return new Ha(i,t,e);if(Array.isArray(i))this.x=i[0],this.y=i[1],this.z=i[2]||0;else if(typeof i=="object")this.x=i.x,this.y=i.y,this.z=i.z||0;else if(typeof i=="string"&&typeof t>"u"){var n=i.split(",");this.x=parseFloat(n[0]),this.y=parseFloat(n[1]),this.z=parseFloat(n[2])||0}else this.x=i,this.y=t,this.z=e||0;console.warn("proj4.Point will be removed in version 3, use proj4.toPoint")}Ha.fromMGRS=function(i){return new Ha(oE(i))};Ha.prototype.toMGRS=function(i){return rE([this.x,this.y],i)};var JM=1,QM=.25,Qy=.046875,t1=.01953125,e1=.01068115234375,tN=.75,eN=.46875,nN=.013020833333333334,iN=.007120768229166667,sN=.3645833333333333,rN=.005696614583333333,oN=.3076171875;function zm(i){var t=[];t[0]=JM-i*(QM+i*(Qy+i*(t1+i*e1))),t[1]=i*(tN-i*(Qy+i*(t1+i*e1)));var e=i*i;return t[2]=e*(eN-i*(nN+i*iN)),e*=i,t[3]=e*(sN-i*rN),t[4]=e*i*oN,t}function gl(i,t,e,n){return e*=t,t*=t,n[0]*i-e*(n[1]+t*(n[2]+t*(n[3]+t*n[4])))}var aN=20;function Um(i,t,e){for(var n=1/(1-t),s=i,r=aN;r;--r){var o=Math.sin(s),a=1-t*o*o;if(a=(gl(s,o,Math.cos(s),e)-i)*(a*Math.sqrt(a))*n,s-=a,Math.abs(a)<Mt)return s}return s}function lN(){this.x0=this.x0!==void 0?this.x0:0,this.y0=this.y0!==void 0?this.y0:0,this.long0=this.long0!==void 0?this.long0:0,this.lat0=this.lat0!==void 0?this.lat0:0,this.es&&(this.en=zm(this.es),this.ml0=gl(this.lat0,Math.sin(this.lat0),Math.cos(this.lat0),this.en))}function uN(i){var t=i.x,e=i.y,n=Lt(t-this.long0,this.over),s,r,o,a=Math.sin(e),l=Math.cos(e);if(this.es){var f=l*n,d=Math.pow(f,2),p=this.ep2*Math.pow(l,2),y=Math.pow(p,2),_=Math.abs(l)>Mt?Math.tan(e):0,E=Math.pow(_,2),w=Math.pow(E,2);s=1-this.es*Math.pow(a,2),f=f/Math.sqrt(s);var L=gl(e,a,l,this.en);r=this.a*(this.k0*f*(1+d/6*(1-E+p+d/20*(5-18*E+w+14*p-58*E*p+d/42*(61+179*w-w*E-479*E)))))+this.x0,o=this.a*(this.k0*(L-this.ml0+a*n*f/2*(1+d/12*(5-E+9*p+4*y+d/30*(61+w-58*E+270*p-330*E*p+d/56*(1385+543*w-w*E-3111*E))))))+this.y0}else{var h=l*Math.sin(n);if(Math.abs(Math.abs(h)-1)<Mt)return 93;if(r=.5*this.a*this.k0*Math.log((1+h)/(1-h))+this.x0,o=l*Math.cos(n)/Math.sqrt(1-Math.pow(h,2)),h=Math.abs(o),h>=1){if(h-1>Mt)return 93;o=0}else o=Math.acos(o);e<0&&(o=-o),o=this.a*this.k0*(o-this.lat0)+this.y0}return i.x=r,i.y=o,i}function cN(i){var t,e,n,s,r=(i.x-this.x0)*(1/this.a),o=(i.y-this.y0)*(1/this.a);if(this.es)if(t=this.ml0+o/this.k0,e=Um(t,this.es,this.en),Math.abs(e)<_t){var d=Math.sin(e),p=Math.cos(e),y=Math.abs(p)>Mt?Math.tan(e):0,_=this.ep2*Math.pow(p,2),E=Math.pow(_,2),w=Math.pow(y,2),L=Math.pow(w,2);t=1-this.es*Math.pow(d,2);var b=r*Math.sqrt(t)/this.k0,P=Math.pow(b,2);t=t*y,n=e-t*P/(1-this.es)*.5*(1-P/12*(5+3*w-9*_*w+_-4*E-P/30*(61+90*w-252*_*w+45*L+46*_-P/56*(1385+3633*w+4095*L+1574*L*w)))),s=Lt(this.long0+b*(1-P/6*(1+2*w+_-P/20*(5+28*w+24*L+8*_*w+6*_-P/42*(61+662*w+1320*L+720*L*w))))/p,this.over)}else n=_t*uc(o),s=0;else{var a=Math.exp(r/this.k0),l=.5*(a-1/a),h=this.lat0+o/this.k0,f=Math.cos(h);t=Math.sqrt((1-Math.pow(f,2))/(1+Math.pow(l,2))),n=Math.asin(t),o<0&&(n=-n),l===0&&f===0?s=0:s=Lt(Math.atan2(l,f)+this.long0,this.over)}return i.x=s,i.y=n,i}var hN=["Fast_Transverse_Mercator","Fast Transverse Mercator"];const vh={init:lN,forward:uN,inverse:cN,names:hN};function uE(i){var t=Math.exp(i);return t=(t-1/t)/2,t}function ri(i,t){i=Math.abs(i),t=Math.abs(t);var e=Math.max(i,t),n=Math.min(i,t)/(e||1);return e*Math.sqrt(1+Math.pow(n,2))}function fN(i){var t=1+i,e=t-1;return e===0?i:i*Math.log(t)/e}function dN(i){var t=Math.abs(i);return t=fN(t*(1+t/(ri(1,t)+1))),i<0?-t:t}function Ym(i,t){for(var e=2*Math.cos(2*t),n=i.length-1,s=i[n],r=0,o;--n>=0;)o=-r+e*s+i[n],r=s,s=o;return t+o*Math.sin(2*t)}function gN(i,t){for(var e=2*Math.cos(t),n=i.length-1,s=i[n],r=0,o;--n>=0;)o=-r+e*s+i[n],r=s,s=o;return Math.sin(t)*o}function mN(i){var t=Math.exp(i);return t=(t+1/t)/2,t}function cE(i,t,e){for(var n=Math.sin(t),s=Math.cos(t),r=uE(e),o=mN(e),a=2*s*o,l=-2*n*r,h=i.length-1,f=i[h],d=0,p=0,y=0,_,E;--h>=0;)_=p,E=d,p=f,d=y,f=-_+a*p-l*d+i[h],y=-E+l*p+a*d;return a=n*o,l=s*r,[a*f-l*y,a*y+l*f]}function pN(){if(!this.approx&&(isNaN(this.es)||this.es<=0))throw new Error('Incorrect elliptical usage. Try using the +approx option in the proj string, or PROJECTION["Fast_Transverse_Mercator"] in the WKT.');this.approx&&(vh.init.apply(this),this.forward=vh.forward,this.inverse=vh.inverse),this.x0=this.x0!==void 0?this.x0:0,this.y0=this.y0!==void 0?this.y0:0,this.long0=this.long0!==void 0?this.long0:0,this.lat0=this.lat0!==void 0?this.lat0:0,this.k0=this.k0!==void 0?this.k0:1,this.cgb=[],this.cbg=[],this.utg=[],this.gtu=[];var i=this.es/(1+Math.sqrt(1-this.es)),t=i/(2-i),e=t;this.cgb[0]=t*(2+t*(-2/3+t*(-2+t*(116/45+t*(26/45+t*(-2854/675)))))),this.cbg[0]=t*(-2+t*(2/3+t*(4/3+t*(-82/45+t*(32/45+t*(4642/4725)))))),e=e*t,this.cgb[1]=e*(7/3+t*(-8/5+t*(-227/45+t*(2704/315+t*(2323/945))))),this.cbg[1]=e*(5/3+t*(-16/15+t*(-13/9+t*(904/315+t*(-1522/945))))),e=e*t,this.cgb[2]=e*(56/15+t*(-136/35+t*(-1262/105+t*(73814/2835)))),this.cbg[2]=e*(-26/15+t*(34/21+t*(8/5+t*(-12686/2835)))),e=e*t,this.cgb[3]=e*(4279/630+t*(-332/35+t*(-399572/14175))),this.cbg[3]=e*(1237/630+t*(-12/5+t*(-24832/14175))),e=e*t,this.cgb[4]=e*(4174/315+t*(-144838/6237)),this.cbg[4]=e*(-734/315+t*(109598/31185)),e=e*t,this.cgb[5]=e*(601676/22275),this.cbg[5]=e*(444337/155925),e=Math.pow(t,2),this.Qn=this.k0/(1+t)*(1+e*(1/4+e*(1/64+e/256))),this.utg[0]=t*(-.5+t*(2/3+t*(-37/96+t*(1/360+t*(81/512+t*(-96199/604800)))))),this.gtu[0]=t*(.5+t*(-2/3+t*(5/16+t*(41/180+t*(-127/288+t*(7891/37800)))))),this.utg[1]=e*(-1/48+t*(-1/15+t*(437/1440+t*(-46/105+t*(1118711/3870720))))),this.gtu[1]=e*(13/48+t*(-3/5+t*(557/1440+t*(281/630+t*(-1983433/1935360))))),e=e*t,this.utg[2]=e*(-17/480+t*(37/840+t*(209/4480+t*(-5569/90720)))),this.gtu[2]=e*(61/240+t*(-103/140+t*(15061/26880+t*(167603/181440)))),e=e*t,this.utg[3]=e*(-4397/161280+t*(11/504+t*(830251/7257600))),this.gtu[3]=e*(49561/161280+t*(-179/168+t*(6601661/7257600))),e=e*t,this.utg[4]=e*(-4583/161280+t*(108847/3991680)),this.gtu[4]=e*(34729/80640+t*(-3418889/1995840)),e=e*t,this.utg[5]=e*(-20648693/638668800),this.gtu[5]=e*(212378941/319334400);var n=Ym(this.cbg,this.lat0);this.Zb=-this.Qn*(n+gN(this.gtu,2*n))}function yN(i){var t=Lt(i.x-this.long0,this.over),e=i.y;e=Ym(this.cbg,e);var n=Math.sin(e),s=Math.cos(e),r=Math.sin(t),o=Math.cos(t);e=Math.atan2(n,o*s),t=Math.atan2(r*s,ri(n,s*o)),t=dN(Math.tan(t));var a=cE(this.gtu,2*e,2*t);e=e+a[0],t=t+a[1];var l,h;return Math.abs(t)<=2.623395162778?(l=this.a*(this.Qn*t)+this.x0,h=this.a*(this.Qn*e+this.Zb)+this.y0):(l=1/0,h=1/0),i.x=l,i.y=h,i}function _N(i){var t=(i.x-this.x0)*(1/this.a),e=(i.y-this.y0)*(1/this.a);e=(e-this.Zb)/this.Qn,t=t/this.Qn;var n,s;if(Math.abs(t)<=2.623395162778){var r=cE(this.utg,2*e,2*t);e=e+r[0],t=t+r[1],t=Math.atan(uE(t));var o=Math.sin(e),a=Math.cos(e),l=Math.sin(t),h=Math.cos(t);e=Math.atan2(o*h,ri(l,h*a)),t=Math.atan2(l,h*a),n=Lt(t+this.long0,this.over),s=Ym(this.cgb,e)}else n=1/0,s=1/0;return i.x=n,i.y=s,i}var vN=["Extended_Transverse_Mercator","Extended Transverse Mercator","etmerc","Transverse_Mercator","Transverse Mercator","Gauss Kruger","Gauss_Kruger","tmerc"];const Eh={init:pN,forward:yN,inverse:_N,names:vN};function EN(i,t){if(i===void 0){if(i=Math.floor((Lt(t)+Math.PI)*30/Math.PI)+1,i<0)return 0;if(i>60)return 60}return i}var wN="etmerc";function xN(){var i=EN(this.zone,this.long0);if(i===void 0)throw new Error("unknown utm zone");this.lat0=0,this.long0=(6*Math.abs(i)-183)*We,this.x0=5e5,this.y0=this.utmSouth?1e7:0,this.k0=.9996,Eh.init.apply(this),this.forward=Eh.forward,this.inverse=Eh.inverse}var bN=["Universal Transverse Mercator System","utm"];const IN={init:xN,names:bN,dependsOn:wN};function Xm(i,t){return Math.pow((1-i)/(1+i),t)}var SN=20;function MN(){var i=Math.sin(this.lat0),t=Math.cos(this.lat0);t*=t,this.rc=Math.sqrt(1-this.es)/(1-this.es*i*i),this.C=Math.sqrt(1+this.es*t*t/(1-this.es)),this.phic0=Math.asin(i/this.C),this.ratexp=.5*this.C*this.e,this.K=Math.tan(.5*this.phic0+be)/(Math.pow(Math.tan(.5*this.lat0+be),this.C)*Xm(this.e*i,this.ratexp))}function NN(i){var t=i.x,e=i.y;return i.y=2*Math.atan(this.K*Math.pow(Math.tan(.5*e+be),this.C)*Xm(this.e*Math.sin(e),this.ratexp))-_t,i.x=this.C*t,i}function LN(i){for(var t=1e-14,e=i.x/this.C,n=i.y,s=Math.pow(Math.tan(.5*n+be)/this.K,1/this.C),r=SN;r>0&&(n=2*Math.atan(s*Xm(this.e*Math.sin(i.y),-.5*this.e))-_t,!(Math.abs(n-i.y)<t));--r)i.y=n;return r?(i.x=e,i.y=n,i):null}const jm={init:MN,forward:NN,inverse:LN};function CN(){jm.init.apply(this),this.rc&&(this.sinc0=Math.sin(this.phic0),this.cosc0=Math.cos(this.phic0),this.R2=2*this.rc,this.title||(this.title="Oblique Stereographic Alternative"))}function PN(i){var t,e,n,s;return i.x=Lt(i.x-this.long0,this.over),jm.forward.apply(this,[i]),t=Math.sin(i.y),e=Math.cos(i.y),n=Math.cos(i.x),s=this.k0*this.R2/(1+this.sinc0*t+this.cosc0*e*n),i.x=s*e*Math.sin(i.x),i.y=s*(this.cosc0*t-this.sinc0*e*n),i.x=this.a*i.x+this.x0,i.y=this.a*i.y+this.y0,i}function kN(i){var t,e,n,s,r;if(i.x=(i.x-this.x0)/this.a,i.y=(i.y-this.y0)/this.a,i.x/=this.k0,i.y/=this.k0,r=ri(i.x,i.y)){var o=2*Math.atan2(r,this.R2);t=Math.sin(o),e=Math.cos(o),s=Math.asin(e*this.sinc0+i.y*t*this.cosc0/r),n=Math.atan2(i.x*t,r*this.cosc0*e-i.y*this.sinc0*t)}else s=this.phic0,n=0;return i.x=n,i.y=s,jm.inverse.apply(this,[i]),i.x=Lt(i.x+this.long0,this.over),i}var TN=["Stereographic_North_Pole","Oblique_Stereographic","sterea","Oblique Stereographic Alternative","Double_Stereographic"];const RN={init:CN,forward:PN,inverse:kN,names:TN};function Vm(i,t,e){return t*=e,Math.tan(.5*(_t+i))*Math.pow((1-t)/(1+t),.5*e)}function AN(){this.x0=this.x0||0,this.y0=this.y0||0,this.lat0=this.lat0||0,this.long0=this.long0||0,this.coslat0=Math.cos(this.lat0),this.sinlat0=Math.sin(this.lat0),this.sphere?!isNaN(this.lat_ts)&&Math.abs(this.coslat0)<=Mt&&(this.k0=.5*(1+uc(this.lat0)*Math.sin(this.lat_ts))):(Math.abs(this.coslat0)<=Mt&&(this.lat0>0?this.con=1:this.con=-1),this.cons=Math.sqrt(Math.pow(1+this.e,1+this.e)*Math.pow(1-this.e,1-this.e)),!isNaN(this.lat_ts)&&Math.abs(this.coslat0)<=Mt&&Math.abs(Math.cos(this.lat_ts))>Mt&&(this.k0=.5*this.cons*Zs(this.e,Math.sin(this.lat_ts),Math.cos(this.lat_ts))/Es(this.e,this.con*this.lat_ts,this.con*Math.sin(this.lat_ts))),this.ms1=Zs(this.e,this.sinlat0,this.coslat0),this.X0=2*Math.atan(Vm(this.lat0,this.sinlat0,this.e))-_t,this.cosX0=Math.cos(this.X0),this.sinX0=Math.sin(this.X0))}function ON(i){var t=i.x,e=i.y,n=Math.sin(e),s=Math.cos(e),r,o,a,l,h,f,d=Lt(t-this.long0,this.over);return Math.abs(Math.abs(t-this.long0)-Math.PI)<=Mt&&Math.abs(e+this.lat0)<=Mt?(i.x=NaN,i.y=NaN,i):this.sphere?(r=2*this.k0/(1+this.sinlat0*n+this.coslat0*s*Math.cos(d)),i.x=this.a*r*s*Math.sin(d)+this.x0,i.y=this.a*r*(this.coslat0*n-this.sinlat0*s*Math.cos(d))+this.y0,i):(o=2*Math.atan(Vm(e,n,this.e))-_t,l=Math.cos(o),a=Math.sin(o),Math.abs(this.coslat0)<=Mt?(h=Es(this.e,e*this.con,this.con*n),f=2*this.a*this.k0*h/this.cons,i.x=this.x0+f*Math.sin(t-this.long0),i.y=this.y0-this.con*f*Math.cos(t-this.long0),i):(Math.abs(this.sinlat0)<Mt?(r=2*this.a*this.k0/(1+l*Math.cos(d)),i.y=r*a):(r=2*this.a*this.k0*this.ms1/(this.cosX0*(1+this.sinX0*a+this.cosX0*l*Math.cos(d))),i.y=r*(this.cosX0*a-this.sinX0*l*Math.cos(d))+this.y0),i.x=r*l*Math.sin(d)+this.x0,i))}function FN(i){i.x-=this.x0,i.y-=this.y0;var t,e,n,s,r,o=Math.sqrt(i.x*i.x+i.y*i.y);if(this.sphere){var a=2*Math.atan(o/(2*this.a*this.k0));return t=this.long0,e=this.lat0,o<=Mt?(i.x=t,i.y=e,i):(e=Math.asin(Math.cos(a)*this.sinlat0+i.y*Math.sin(a)*this.coslat0/o),Math.abs(this.coslat0)<Mt?this.lat0>0?t=Lt(this.long0+Math.atan2(i.x,-1*i.y),this.over):t=Lt(this.long0+Math.atan2(i.x,i.y),this.over):t=Lt(this.long0+Math.atan2(i.x*Math.sin(a),o*this.coslat0*Math.cos(a)-i.y*this.sinlat0*Math.sin(a)),this.over),i.x=t,i.y=e,i)}else if(Math.abs(this.coslat0)<=Mt){if(o<=Mt)return e=this.lat0,t=this.long0,i.x=t,i.y=e,i;i.x*=this.con,i.y*=this.con,n=o*this.cons/(2*this.a*this.k0),e=this.con*Lu(this.e,n),t=this.con*Lt(this.con*this.long0+Math.atan2(i.x,-1*i.y),this.over)}else s=2*Math.atan(o*this.cosX0/(2*this.a*this.k0*this.ms1)),t=this.long0,o<=Mt?r=this.X0:(r=Math.asin(Math.cos(s)*this.sinX0+i.y*Math.sin(s)*this.cosX0/o),t=Lt(this.long0+Math.atan2(i.x*Math.sin(s),o*this.cosX0*Math.cos(s)-i.y*this.sinX0*Math.sin(s)),this.over)),e=-1*Lu(this.e,Math.tan(.5*(_t+r)));return i.x=t,i.y=e,i}var $N=["stere","Stereographic_South_Pole","Polar_Stereographic_variant_A","Polar_Stereographic_variant_B","Polar_Stereographic"];const DN={init:AN,forward:ON,inverse:FN,names:$N,ssfn_:Vm};function GN(){this.k0||(this.k0=1);var i=this.lat0;this.lambda0=this.long0;var t=Math.sin(i),e=this.a,n=this.rf,s=1/n,r=2*s-Math.pow(s,2),o=this.e=Math.sqrt(r);this.R=this.k0*e*Math.sqrt(1-r)/(1-r*Math.pow(t,2)),this.alpha=Math.sqrt(1+r/(1-r)*Math.pow(Math.cos(i),4)),this.b0=Math.asin(t/this.alpha);var a=Math.log(Math.tan(Math.PI/4+this.b0/2)),l=Math.log(Math.tan(Math.PI/4+i/2)),h=Math.log((1+o*t)/(1-o*t));this.K=a-this.alpha*l+this.alpha*o/2*h}function BN(i){var t=Math.log(Math.tan(Math.PI/4-i.y/2)),e=this.e/2*Math.log((1+this.e*Math.sin(i.y))/(1-this.e*Math.sin(i.y))),n=-this.alpha*(t+e)+this.K,s=2*(Math.atan(Math.exp(n))-Math.PI/4),r=this.alpha*(i.x-this.lambda0),o=Math.atan(Math.sin(r)/(Math.sin(this.b0)*Math.tan(s)+Math.cos(this.b0)*Math.cos(r))),a=Math.asin(Math.cos(this.b0)*Math.sin(s)-Math.sin(this.b0)*Math.cos(s)*Math.cos(r));return i.y=this.R/2*Math.log((1+Math.sin(a))/(1-Math.sin(a)))+this.y0,i.x=this.R*o+this.x0,i}function qN(i){for(var t=i.x-this.x0,e=i.y-this.y0,n=t/this.R,s=2*(Math.atan(Math.exp(e/this.R))-Math.PI/4),r=Math.asin(Math.cos(this.b0)*Math.sin(s)+Math.sin(this.b0)*Math.cos(s)*Math.cos(n)),o=Math.atan(Math.sin(n)/(Math.cos(this.b0)*Math.cos(n)-Math.sin(this.b0)*Math.tan(s))),a=this.lambda0+o/this.alpha,l=0,h=r,f=-1e3,d=0;Math.abs(h-f)>1e-7;){if(++d>20)return;l=1/this.alpha*(Math.log(Math.tan(Math.PI/4+r/2))-this.K)+this.e*Math.log(Math.tan(Math.PI/4+Math.asin(this.e*Math.sin(h))/2)),f=h,h=2*Math.atan(Math.exp(l))-Math.PI/2}return i.x=a,i.y=h,i}var zN=["somerc"];const UN={init:GN,forward:BN,inverse:qN,names:zN};var ca=1e-7;function YN(i){var t=["Hotine_Oblique_Mercator","Hotine_Oblique_Mercator_variant_A","Hotine_Oblique_Mercator_Azimuth_Natural_Origin"],e=typeof i.projName=="object"?Object.keys(i.projName)[0]:i.projName;return"no_uoff"in i||"no_off"in i||t.indexOf(e)!==-1||t.indexOf(Qv(e))!==-1}function XN(){var i,t,e,n,s,r,o,a,l,h,f=0,d,p=0,y=0,_=0,E=0,w=0,L=0;this.k0||(this.k0=1),this.no_off=YN(this),this.no_rot="no_rot"in this;var b=!1;"alpha"in this&&(b=!0);var P=!1;if("rectified_grid_angle"in this&&(P=!0),b&&(L=this.alpha),P&&(f=this.rectified_grid_angle,b||(L=0,b=!0)),b||P)p=this.longc;else if(y=this.long1,E=this.lat1,_=this.long2,w=this.lat2,Math.abs(E-w)<=ca||(i=Math.abs(E))<=ca||Math.abs(i-_t)<=ca||Math.abs(Math.abs(this.lat0)-_t)<=ca||Math.abs(Math.abs(w)-_t)<=ca)throw new Error;var N=1-this.es;t=Math.sqrt(N),Math.abs(this.lat0)>Mt?(a=Math.sin(this.lat0),e=Math.cos(this.lat0),i=1-this.es*a*a,this.B=e*e,this.B=Math.sqrt(1+this.es*this.B*this.B/N),this.A=this.B*this.k0*t/i,n=this.B*t/(e*Math.sqrt(i)),s=n*n-1,s<=0?s=0:(s=Math.sqrt(s),this.lat0<0&&(s=-s)),this.E=s+=n,this.E*=Math.pow(Es(this.e,this.lat0,a),this.B)):(this.B=1/t,this.A=this.k0,this.E=n=s=1),b||P?(b?(d=Math.asin(Math.sin(L)/n),P||(f=L)):(d=f,L=Math.asin(n*Math.sin(d))),this.lam0=p-Math.asin(.5*(s-1/s)*Math.tan(d))/this.B):(r=Math.pow(Es(this.e,E,Math.sin(E)),this.B),o=Math.pow(Es(this.e,w,Math.sin(w)),this.B),s=this.E/r,l=(o-r)/(o+r),h=this.E*this.E,h=(h-o*r)/(h+o*r),i=y-_,i<-Math.PI?_-=Mu:i>Math.PI&&(_+=Mu),this.lam0=Lt(.5*(y+_)-Math.atan(h*Math.tan(.5*this.B*(y-_))/l)/this.B,this.over),d=Math.atan(2*Math.sin(this.B*Lt(y-this.lam0,this.over))/(s-1/s)),f=L=Math.asin(n*Math.sin(d))),this.singam=Math.sin(d),this.cosgam=Math.cos(d),this.sinrot=Math.sin(f),this.cosrot=Math.cos(f),this.rB=1/this.B,this.ArB=this.A*this.rB,this.BrA=1/this.ArB,this.no_off?this.u_0=0:(this.u_0=Math.abs(this.ArB*Math.atan(Math.sqrt(n*n-1)/Math.cos(L))),this.lat0<0&&(this.u_0=-this.u_0)),s=.5*d,this.v_pole_n=this.ArB*Math.log(Math.tan(be-s)),this.v_pole_s=this.ArB*Math.log(Math.tan(be+s))}function jN(i){var t={},e,n,s,r,o,a,l,h;if(i.x=i.x-this.lam0,Math.abs(Math.abs(i.y)-_t)>Mt){if(o=this.E/Math.pow(Es(this.e,i.y,Math.sin(i.y)),this.B),a=1/o,e=.5*(o-a),n=.5*(o+a),r=Math.sin(this.B*i.x),s=(e*this.singam-r*this.cosgam)/n,Math.abs(Math.abs(s)-1)<Mt)throw new Error;h=.5*this.ArB*Math.log((1-s)/(1+s)),a=Math.cos(this.B*i.x),Math.abs(a)<ca?l=this.A*i.x:l=this.ArB*Math.atan2(e*this.cosgam+r*this.singam,a)}else h=i.y>0?this.v_pole_n:this.v_pole_s,l=this.ArB*i.y;return this.no_rot?(t.x=l,t.y=h):(l-=this.u_0,t.x=h*this.cosrot+l*this.sinrot,t.y=l*this.cosrot-h*this.sinrot),t.x=this.a*t.x+this.x0,t.y=this.a*t.y+this.y0,i.z!==void 0&&(t.z=i.z),i.m!==void 0&&(t.m=i.m),t}function VN(i){var t,e,n,s,r,o,a,l={};if(i.x=(i.x-this.x0)*(1/this.a),i.y=(i.y-this.y0)*(1/this.a),this.no_rot?(e=i.y,t=i.x):(e=i.x*this.cosrot-i.y*this.sinrot,t=i.y*this.cosrot+i.x*this.sinrot+this.u_0),n=Math.exp(-this.BrA*e),s=.5*(n-1/n),r=.5*(n+1/n),o=Math.sin(this.BrA*t),a=(o*this.cosgam+s*this.singam)/r,Math.abs(Math.abs(a)-1)<Mt)l.x=0,l.y=a<0?-_t:_t;else{if(l.y=this.E/Math.sqrt((1+a)/(1-a)),l.y=Lu(this.e,Math.pow(l.y,1/this.B)),l.y===1/0)throw new Error;l.x=-this.rB*Math.atan2(s*this.cosgam-o*this.singam,Math.cos(this.BrA*t))}return l.x+=this.lam0,i.z!==void 0&&(l.z=i.z),i.m!==void 0&&(l.m=i.m),l}var HN=["Hotine_Oblique_Mercator","Hotine Oblique Mercator","Hotine_Oblique_Mercator_variant_A","Hotine_Oblique_Mercator_Variant_B","Hotine_Oblique_Mercator_Azimuth_Natural_Origin","Hotine_Oblique_Mercator_Two_Point_Natural_Origin","Hotine_Oblique_Mercator_Azimuth_Center","Oblique_Mercator","omerc"];const WN={init:XN,forward:jN,inverse:VN,names:HN};function KN(){if(this.lat2||(this.lat2=this.lat1),this.k0||(this.k0=1),this.x0=this.x0||0,this.y0=this.y0||0,this.long0=this.long0||0,!(Math.abs(this.lat1+this.lat2)<Mt)){var i=this.b/this.a;this.e=Math.sqrt(1-i*i);var t=Math.sin(this.lat1),e=Math.cos(this.lat1),n=Zs(this.e,t,e),s=Es(this.e,this.lat1,t),r=Math.sin(this.lat2),o=Math.cos(this.lat2),a=Zs(this.e,r,o),l=Es(this.e,this.lat2,r),h=Es(this.e,this.lat0,Math.sin(this.lat0));Math.abs(this.lat1-this.lat2)>Mt?this.ns=Math.log(n/a)/Math.log(s/l):this.ns=t,isNaN(this.ns)&&(this.ns=t),this.f0=n/(this.ns*Math.pow(s,this.ns)),this.rh=Math.abs(Math.abs(this.lat0)-_t)<Mt?0:this.a*this.f0*Math.pow(h,this.ns),this.title||(this.title="Lambert Conformal Conic")}}function ZN(i){var t=i.x,e=i.y;Math.abs(2*Math.abs(e)-Math.PI)<=Mt&&(e=uc(e)*(_t-2*Mt));var n=Math.abs(Math.abs(e)-_t),s,r;if(n>Mt)s=Es(this.e,e,Math.sin(e)),r=this.a*this.f0*Math.pow(s,this.ns);else{if(n=e*this.ns,n<=0)return null;r=0}var o=this.ns*Lt(t-this.long0,this.over);return i.x=this.k0*(r*Math.sin(o))+this.x0,i.y=this.k0*(this.rh-r*Math.cos(o))+this.y0,i}function JN(i){var t,e,n,s,r,o=(i.x-this.x0)/this.k0,a=this.rh-(i.y-this.y0)/this.k0;this.ns>0?(t=Math.sqrt(o*o+a*a),e=1):(t=-Math.sqrt(o*o+a*a),e=-1);var l=0;if(t!==0&&(l=Math.atan2(e*o,e*a)),t!==0||this.ns>0){if(e=1/this.ns,n=Math.pow(t/(this.a*this.f0),e),s=Lu(this.e,n),s===-9999)return null}else s=-_t;return r=Lt(l/this.ns+this.long0,this.over),i.x=r,i.y=s,i}var QN=["Lambert Tangential Conformal Conic Projection","Lambert_Conformal_Conic","Lambert_Conformal_Conic_1SP","Lambert_Conformal_Conic_2SP","lcc","Lambert Conic Conformal (1SP)","Lambert Conic Conformal (2SP)"];const tL={init:KN,forward:ZN,inverse:JN,names:QN};function eL(){this.a=6377397155e-3,this.es=.006674372230614,this.e=Math.sqrt(this.es),this.lat0||(this.lat0=.863937979737193),this.long0||(this.long0=.7417649320975901-.308341501185665),this.k0||(this.k0=.9999),this.s45=.785398163397448,this.s90=2*this.s45,this.fi0=this.lat0,this.e2=this.es,this.e=Math.sqrt(this.e2),this.alfa=Math.sqrt(1+this.e2*Math.pow(Math.cos(this.fi0),4)/(1-this.e2)),this.uq=1.04216856380474,this.u0=Math.asin(Math.sin(this.fi0)/this.alfa),this.g=Math.pow((1+this.e*Math.sin(this.fi0))/(1-this.e*Math.sin(this.fi0)),this.alfa*this.e/2),this.k=Math.tan(this.u0/2+this.s45)/Math.pow(Math.tan(this.fi0/2+this.s45),this.alfa)*this.g,this.k1=this.k0,this.n0=this.a*Math.sqrt(1-this.e2)/(1-this.e2*Math.pow(Math.sin(this.fi0),2)),this.s0=1.37008346281555,this.n=Math.sin(this.s0),this.ro0=this.k1*this.n0/Math.tan(this.s0),this.ad=this.s90-this.uq}function nL(i){var t,e,n,s,r,o,a,l=i.x,h=i.y,f=Lt(l-this.long0,this.over);return t=Math.pow((1+this.e*Math.sin(h))/(1-this.e*Math.sin(h)),this.alfa*this.e/2),e=2*(Math.atan(this.k*Math.pow(Math.tan(h/2+this.s45),this.alfa)/t)-this.s45),n=-f*this.alfa,s=Math.asin(Math.cos(this.ad)*Math.sin(e)+Math.sin(this.ad)*Math.cos(e)*Math.cos(n)),r=Math.asin(Math.cos(e)*Math.sin(n)/Math.cos(s)),o=this.n*r,a=this.ro0*Math.pow(Math.tan(this.s0/2+this.s45),this.n)/Math.pow(Math.tan(s/2+this.s45),this.n),i.y=a*Math.cos(o)/1,i.x=a*Math.sin(o)/1,this.czech||(i.y*=-1,i.x*=-1),i}function iL(i){var t,e,n,s,r,o,a,l,h=i.x;i.x=i.y,i.y=h,this.czech||(i.y*=-1,i.x*=-1),o=Math.sqrt(i.x*i.x+i.y*i.y),r=Math.atan2(i.y,i.x),s=r/Math.sin(this.s0),n=2*(Math.atan(Math.pow(this.ro0/o,1/this.n)*Math.tan(this.s0/2+this.s45))-this.s45),t=Math.asin(Math.cos(this.ad)*Math.sin(n)-Math.sin(this.ad)*Math.cos(n)*Math.cos(s)),e=Math.asin(Math.cos(n)*Math.sin(s)/Math.cos(t)),i.x=this.long0-e/this.alfa,a=t,l=0;var f=0;do i.y=2*(Math.atan(Math.pow(this.k,-1/this.alfa)*Math.pow(Math.tan(t/2+this.s45),1/this.alfa)*Math.pow((1+this.e*Math.sin(a))/(1-this.e*Math.sin(a)),this.e/2))-this.s45),Math.abs(a-i.y)<1e-10&&(l=1),a=i.y,f+=1;while(l===0&&f<15);return f>=15?null:i}var sL=["Krovak","Krovak Modified","Krovak (North Orientated)","Krovak Modified (North Orientated)","krovak"];const rL={init:eL,forward:nL,inverse:iL,names:sL};function Zn(i,t,e,n,s){return i*s-t*Math.sin(2*s)+e*Math.sin(4*s)-n*Math.sin(6*s)}function cc(i){return 1-.25*i*(1+i/16*(3+1.25*i))}function hc(i){return .375*i*(1+.25*i*(1+.46875*i))}function fc(i){return .05859375*i*i*(1+.75*i)}function dc(i){return i*i*i*(35/3072)}function Hm(i,t,e){var n=t*e;return i/Math.sqrt(1-n*n)}function Vr(i){return Math.abs(i)<_t?i:i-uc(i)*Math.PI}function jh(i,t,e,n,s){var r,o;r=i/t;for(var a=0;a<15;a++)if(o=(i-(t*r-e*Math.sin(2*r)+n*Math.sin(4*r)-s*Math.sin(6*r)))/(t-2*e*Math.cos(2*r)+4*n*Math.cos(4*r)-6*s*Math.cos(6*r)),r+=o,Math.abs(o)<=1e-10)return r;return NaN}function oL(){this.sphere||(this.e0=cc(this.es),this.e1=hc(this.es),this.e2=fc(this.es),this.e3=dc(this.es),this.ml0=this.a*Zn(this.e0,this.e1,this.e2,this.e3,this.lat0))}function aL(i){var t,e,n=i.x,s=i.y;if(n=Lt(n-this.long0,this.over),this.sphere)t=this.a*Math.asin(Math.cos(s)*Math.sin(n)),e=this.a*(Math.atan2(Math.tan(s),Math.cos(n))-this.lat0);else{var r=Math.sin(s),o=Math.cos(s),a=Hm(this.a,this.e,r),l=Math.tan(s)*Math.tan(s),h=n*Math.cos(s),f=h*h,d=this.es*o*o/(1-this.es),p=this.a*Zn(this.e0,this.e1,this.e2,this.e3,s);t=a*h*(1-f*l*(1/6-(8-l+8*d)*f/120)),e=p-this.ml0+a*r/o*f*(.5+(5-l+6*d)*f/24)}return i.x=t+this.x0,i.y=e+this.y0,i}function lL(i){i.x-=this.x0,i.y-=this.y0;var t=i.x/this.a,e=i.y/this.a,n,s;if(this.sphere){var r=e+this.lat0;n=Math.asin(Math.sin(r)*Math.cos(t)),s=Math.atan2(Math.tan(t),Math.cos(r))}else{var o=this.ml0/this.a+e,a=jh(o,this.e0,this.e1,this.e2,this.e3);if(Math.abs(Math.abs(a)-_t)<=Mt)return i.x=this.long0,i.y=_t,e<0&&(i.y*=-1),i;var l=Hm(this.a,this.e,Math.sin(a)),h=l*l*l/this.a/this.a*(1-this.es),f=Math.pow(Math.tan(a),2),d=t*this.a/l,p=d*d;n=a-l*Math.tan(a)/h*d*d*(.5-(1+3*f)*d*d/24),s=d*(1-p*(f/3+(1+3*f)*f*p/15))/Math.cos(a)}return i.x=Lt(s+this.long0,this.over),i.y=Vr(n),i}var uL=["Cassini","Cassini_Soldner","cass"];const cL={init:oL,forward:aL,inverse:lL,names:uL};function Us(i,t){var e;return i>1e-7?(e=i*t,(1-i*i)*(t/(1-e*e)-.5/i*Math.log((1-e)/(1+e)))):2*t}var hL=.3333333333333333,fL=.17222222222222222,dL=.10257936507936508,gL=.06388888888888888,mL=.0664021164021164,pL=.016415012942191543;function hE(i){var t,e=[];return e[0]=i*hL,t=i*i,e[0]+=t*fL,e[1]=t*gL,t*=i,e[0]+=t*dL,e[1]+=t*mL,e[2]=t*pL,e}function fE(i,t){var e=i+i;return i+t[0]*Math.sin(e)+t[1]*Math.sin(e+e)+t[2]*Math.sin(e+e+e)}var qg=1,zg=2,Ug=3,wh=4;function yL(){var i=Math.abs(this.lat0);if(Math.abs(i-_t)<Mt?this.mode=this.lat0<0?qg:zg:Math.abs(i)<Mt?this.mode=Ug:this.mode=wh,this.es>0){var t;switch(this.qp=Us(this.e,1),this.mmf=.5/(1-this.es),this.apa=hE(this.es),this.mode){case zg:this.dd=1;break;case qg:this.dd=1;break;case Ug:this.rq=Math.sqrt(.5*this.qp),this.dd=1/this.rq,this.xmf=1,this.ymf=.5*this.qp;break;case wh:this.rq=Math.sqrt(.5*this.qp),t=Math.sin(this.lat0),this.sinb1=Us(this.e,t)/this.qp,this.cosb1=Math.sqrt(1-this.sinb1*this.sinb1),this.dd=Math.cos(this.lat0)/(Math.sqrt(1-this.es*t*t)*this.rq*this.cosb1),this.ymf=(this.xmf=this.rq)/this.dd,this.xmf*=this.dd;break}}else this.mode===wh&&(this.sinph0=Math.sin(this.lat0),this.cosph0=Math.cos(this.lat0))}function _L(i){var t,e,n,s,r,o,a,l,h,f,d=i.x,p=i.y;if(d=Lt(d-this.long0,this.over),this.sphere){if(r=Math.sin(p),f=Math.cos(p),n=Math.cos(d),this.mode===this.OBLIQ||this.mode===this.EQUIT){if(e=this.mode===this.EQUIT?1+f*n:1+this.sinph0*r+this.cosph0*f*n,e<=Mt)return null;e=Math.sqrt(2/e),t=e*f*Math.sin(d),e*=this.mode===this.EQUIT?r:this.cosph0*r-this.sinph0*f*n}else if(this.mode===this.N_POLE||this.mode===this.S_POLE){if(this.mode===this.N_POLE&&(n=-n),Math.abs(p+this.lat0)<Mt)return null;e=be-p*.5,e=2*(this.mode===this.S_POLE?Math.cos(e):Math.sin(e)),t=e*Math.sin(d),e*=n}}else{switch(a=0,l=0,h=0,n=Math.cos(d),s=Math.sin(d),r=Math.sin(p),o=Us(this.e,r),(this.mode===this.OBLIQ||this.mode===this.EQUIT)&&(a=o/this.qp,l=Math.sqrt(1-a*a)),this.mode){case this.OBLIQ:h=1+this.sinb1*a+this.cosb1*l*n;break;case this.EQUIT:h=1+l*n;break;case this.N_POLE:h=_t+p,o=this.qp-o;break;case this.S_POLE:h=p-_t,o=this.qp+o;break}if(Math.abs(h)<Mt)return null;switch(this.mode){case this.OBLIQ:case this.EQUIT:h=Math.sqrt(2/h),this.mode===this.OBLIQ?e=this.ymf*h*(this.cosb1*a-this.sinb1*l*n):e=(h=Math.sqrt(2/(1+l*n)))*a*this.ymf,t=this.xmf*h*l*s;break;case this.N_POLE:case this.S_POLE:o>=0?(t=(h=Math.sqrt(o))*s,e=n*(this.mode===this.S_POLE?h:-h)):t=e=0;break}}return i.x=this.a*t+this.x0,i.y=this.a*e+this.y0,i}function vL(i){i.x-=this.x0,i.y-=this.y0;var t=i.x/this.a,e=i.y/this.a,n,s,r,o,a,l,h;if(this.sphere){var f=0,d,p=0;if(d=Math.sqrt(t*t+e*e),s=d*.5,s>1)return null;switch(s=2*Math.asin(s),(this.mode===this.OBLIQ||this.mode===this.EQUIT)&&(p=Math.sin(s),f=Math.cos(s)),this.mode){case this.EQUIT:s=Math.abs(d)<=Mt?0:Math.asin(e*p/d),t*=p,e=f*d;break;case this.OBLIQ:s=Math.abs(d)<=Mt?this.lat0:Math.asin(f*this.sinph0+e*p*this.cosph0/d),t*=p*this.cosph0,e=(f-Math.sin(s)*this.sinph0)*d;break;case this.N_POLE:e=-e,s=_t-s;break;case this.S_POLE:s-=_t;break}n=e===0&&(this.mode===this.EQUIT||this.mode===this.OBLIQ)?0:Math.atan2(t,e)}else{if(h=0,this.mode===this.OBLIQ||this.mode===this.EQUIT){if(t/=this.dd,e*=this.dd,l=Math.sqrt(t*t+e*e),l<Mt)return i.x=this.long0,i.y=this.lat0,i;o=2*Math.asin(.5*l/this.rq),r=Math.cos(o),t*=o=Math.sin(o),this.mode===this.OBLIQ?(h=r*this.sinb1+e*o*this.cosb1/l,a=this.qp*h,e=l*this.cosb1*r-e*this.sinb1*o):(h=e*o/l,a=this.qp*h,e=l*r)}else if(this.mode===this.N_POLE||this.mode===this.S_POLE){if(this.mode===this.N_POLE&&(e=-e),a=t*t+e*e,!a)return i.x=this.long0,i.y=this.lat0,i;h=1-a/this.qp,this.mode===this.S_POLE&&(h=-h)}n=Math.atan2(t,e),s=fE(Math.asin(h),this.apa)}return i.x=Lt(this.long0+n,this.over),i.y=s,i}var EL=["Lambert Azimuthal Equal Area","Lambert_Azimuthal_Equal_Area","laea"];const wL={init:yL,forward:_L,inverse:vL,names:EL,S_POLE:qg,N_POLE:zg,EQUIT:Ug,OBLIQ:wh};function Br(i){return Math.abs(i)>1&&(i=i>1?1:-1),Math.asin(i)}function xL(){Math.abs(this.lat1+this.lat2)<Mt||(this.temp=this.b/this.a,this.es=1-Math.pow(this.temp,2),this.e3=Math.sqrt(this.es),this.sin_po=Math.sin(this.lat1),this.cos_po=Math.cos(this.lat1),this.t1=this.sin_po,this.con=this.sin_po,this.ms1=Zs(this.e3,this.sin_po,this.cos_po),this.qs1=Us(this.e3,this.sin_po),this.sin_po=Math.sin(this.lat2),this.cos_po=Math.cos(this.lat2),this.t2=this.sin_po,this.ms2=Zs(this.e3,this.sin_po,this.cos_po),this.qs2=Us(this.e3,this.sin_po),this.sin_po=Math.sin(this.lat0),this.cos_po=Math.cos(this.lat0),this.t3=this.sin_po,this.qs0=Us(this.e3,this.sin_po),Math.abs(this.lat1-this.lat2)>Mt?this.ns0=(this.ms1*this.ms1-this.ms2*this.ms2)/(this.qs2-this.qs1):this.ns0=this.con,this.c=this.ms1*this.ms1+this.ns0*this.qs1,this.rh=this.a*Math.sqrt(this.c-this.ns0*this.qs0)/this.ns0)}function bL(i){var t=i.x,e=i.y;this.sin_phi=Math.sin(e),this.cos_phi=Math.cos(e);var n=Us(this.e3,this.sin_phi),s=this.a*Math.sqrt(this.c-this.ns0*n)/this.ns0,r=this.ns0*Lt(t-this.long0,this.over),o=s*Math.sin(r)+this.x0,a=this.rh-s*Math.cos(r)+this.y0;return i.x=o,i.y=a,i}function IL(i){var t,e,n,s,r,o;return i.x-=this.x0,i.y=this.rh-i.y+this.y0,this.ns0>=0?(t=Math.sqrt(i.x*i.x+i.y*i.y),n=1):(t=-Math.sqrt(i.x*i.x+i.y*i.y),n=-1),s=0,t!==0&&(s=Math.atan2(n*i.x,n*i.y)),n=t*this.ns0/this.a,this.sphere?o=Math.asin((this.c-n*n)/(2*this.ns0)):(e=(this.c-n*n)/this.ns0,o=this.phi1z(this.e3,e)),r=Lt(s/this.ns0+this.long0,this.over),i.x=r,i.y=o,i}function SL(i,t){var e,n,s,r,o,a=Br(.5*t);if(i<Mt)return a;for(var l=i*i,h=1;h<=25;h++)if(e=Math.sin(a),n=Math.cos(a),s=i*e,r=1-s*s,o=.5*r*r/n*(t/(1-l)-e/r+.5/i*Math.log((1-s)/(1+s))),a=a+o,Math.abs(o)<=1e-7)return a;return null}var ML=["Albers_Conic_Equal_Area","Albers_Equal_Area","Albers","aea"];const NL={init:xL,forward:bL,inverse:IL,names:ML,phi1z:SL};function LL(){this.sin_p14=Math.sin(this.lat0),this.cos_p14=Math.cos(this.lat0),this.infinity_dist=1e3*this.a,this.rc=1}function CL(i){var t,e,n,s,r,o,a,l,h=i.x,f=i.y;return n=Lt(h-this.long0,this.over),t=Math.sin(f),e=Math.cos(f),s=Math.cos(n),o=this.sin_p14*t+this.cos_p14*e*s,r=1,o>0||Math.abs(o)<=Mt?(a=this.x0+this.a*r*e*Math.sin(n)/o,l=this.y0+this.a*r*(this.cos_p14*t-this.sin_p14*e*s)/o):(a=this.x0+this.infinity_dist*e*Math.sin(n),l=this.y0+this.infinity_dist*(this.cos_p14*t-this.sin_p14*e*s)),i.x=a,i.y=l,i}function PL(i){var t,e,n,s,r,o;return i.x=(i.x-this.x0)/this.a,i.y=(i.y-this.y0)/this.a,i.x/=this.k0,i.y/=this.k0,(t=Math.sqrt(i.x*i.x+i.y*i.y))?(s=Math.atan2(t,this.rc),e=Math.sin(s),n=Math.cos(s),o=Br(n*this.sin_p14+i.y*e*this.cos_p14/t),r=Math.atan2(i.x*e,t*this.cos_p14*n-i.y*this.sin_p14*e),r=Lt(this.long0+r,this.over)):(o=this.phic0,r=0),i.x=r,i.y=o,i}var kL=["gnom"];const TL={init:LL,forward:CL,inverse:PL,names:kL};function RL(i,t){var e=1-(1-i*i)/(2*i)*Math.log((1-i)/(1+i));if(Math.abs(Math.abs(t)-e)<1e-6)return t<0?-1*_t:_t;for(var n=Math.asin(.5*t),s,r,o,a,l=0;l<30;l++)if(r=Math.sin(n),o=Math.cos(n),a=i*r,s=Math.pow(1-a*a,2)/(2*o)*(t/(1-i*i)-r/(1-a*a)+.5/i*Math.log((1-a)/(1+a))),n+=s,Math.abs(s)<=1e-10)return n;return NaN}function AL(){this.sphere||(this.k0=Zs(this.e,Math.sin(this.lat_ts),Math.cos(this.lat_ts)))}function OL(i){var t=i.x,e=i.y,n,s,r=Lt(t-this.long0,this.over);if(this.sphere)n=this.x0+this.a*r*Math.cos(this.lat_ts),s=this.y0+this.a*Math.sin(e)/Math.cos(this.lat_ts);else{var o=Us(this.e,Math.sin(e));n=this.x0+this.a*this.k0*r,s=this.y0+this.a*o*.5/this.k0}return i.x=n,i.y=s,i}function FL(i){i.x-=this.x0,i.y-=this.y0;var t,e;return this.sphere?(t=Lt(this.long0+i.x/this.a/Math.cos(this.lat_ts),this.over),e=Math.asin(i.y/this.a*Math.cos(this.lat_ts))):(e=RL(this.e,2*i.y*this.k0/this.a),t=Lt(this.long0+i.x/(this.a*this.k0),this.over)),i.x=t,i.y=e,i}var $L=["cea"];const DL={init:AL,forward:OL,inverse:FL,names:$L};function GL(){this.x0=this.x0||0,this.y0=this.y0||0,this.lat0=this.lat0||0,this.long0=this.long0||0,this.lat_ts=this.lat_ts||0,this.title=this.title||"Equidistant Cylindrical (Plate Carre)",this.rc=Math.cos(this.lat_ts)}function BL(i){var t=i.x,e=i.y,n=Lt(t-this.long0,this.over),s=Vr(e-this.lat0);return i.x=this.x0+this.a*n*this.rc,i.y=this.y0+this.a*s,i}function qL(i){var t=i.x,e=i.y;return i.x=Lt(this.long0+(t-this.x0)/(this.a*this.rc),this.over),i.y=Vr(this.lat0+(e-this.y0)/this.a),i}var zL=["Equirectangular","Equidistant_Cylindrical","Equidistant_Cylindrical_Spherical","eqc"];const UL={init:GL,forward:BL,inverse:qL,names:zL};var n1=20;function YL(){this.temp=this.b/this.a,this.es=1-Math.pow(this.temp,2),this.e=Math.sqrt(this.es),this.e0=cc(this.es),this.e1=hc(this.es),this.e2=fc(this.es),this.e3=dc(this.es),this.ml0=this.a*Zn(this.e0,this.e1,this.e2,this.e3,this.lat0)}function XL(i){var t=i.x,e=i.y,n,s,r,o=Lt(t-this.long0,this.over);if(r=o*Math.sin(e),this.sphere)Math.abs(e)<=Mt?(n=this.a*o,s=-1*this.a*this.lat0):(n=this.a*Math.sin(r)/Math.tan(e),s=this.a*(Vr(e-this.lat0)+(1-Math.cos(r))/Math.tan(e)));else if(Math.abs(e)<=Mt)n=this.a*o,s=-1*this.ml0;else{var a=Hm(this.a,this.e,Math.sin(e))/Math.tan(e);n=a*Math.sin(r),s=this.a*Zn(this.e0,this.e1,this.e2,this.e3,e)-this.ml0+a*(1-Math.cos(r))}return i.x=n+this.x0,i.y=s+this.y0,i}function jL(i){var t,e,n,s,r,o,a,l,h;if(n=i.x-this.x0,s=i.y-this.y0,this.sphere)if(Math.abs(s+this.a*this.lat0)<=Mt)t=Lt(n/this.a+this.long0,this.over),e=0;else{o=this.lat0+s/this.a,a=n*n/this.a/this.a+o*o,l=o;var f;for(r=n1;r;--r)if(f=Math.tan(l),h=-1*(o*(l*f+1)-l-.5*(l*l+a)*f)/((l-o)/f-1),l+=h,Math.abs(h)<=Mt){e=l;break}t=Lt(this.long0+Math.asin(n*Math.tan(l)/this.a)/Math.sin(e),this.over)}else if(Math.abs(s+this.ml0)<=Mt)e=0,t=Lt(this.long0+n/this.a,this.over);else{o=(this.ml0+s)/this.a,a=n*n/this.a/this.a+o*o,l=o;var d,p,y,_,E;for(r=n1;r;--r)if(E=this.e*Math.sin(l),d=Math.sqrt(1-E*E)*Math.tan(l),p=this.a*Zn(this.e0,this.e1,this.e2,this.e3,l),y=this.e0-2*this.e1*Math.cos(2*l)+4*this.e2*Math.cos(4*l)-6*this.e3*Math.cos(6*l),_=p/this.a,h=(o*(d*_+1)-_-.5*d*(_*_+a))/(this.es*Math.sin(2*l)*(_*_+a-2*o*_)/(4*d)+(o-_)*(d*y-2/Math.sin(2*l))-y),l-=h,Math.abs(h)<=Mt){e=l;break}d=Math.sqrt(1-this.es*Math.pow(Math.sin(e),2))*Math.tan(e),t=Lt(this.long0+Math.asin(n*d/this.a)/Math.sin(e),this.over)}return i.x=t,i.y=e,i}var VL=["Polyconic","American_Polyconic","poly"];const HL={init:YL,forward:XL,inverse:jL,names:VL};var WL=1;function KL(){this.A=[],this.A[1]=.6399175073,this.A[2]=-.1358797613,this.A[3]=.063294409,this.A[4]=-.02526853,this.A[5]=.0117879,this.A[6]=-.0055161,this.A[7]=.0026906,this.A[8]=-.001333,this.A[9]=67e-5,this.A[10]=-34e-5,this.B_re=[],this.B_im=[],this.B_re[1]=.7557853228,this.B_im[1]=0,this.B_re[2]=.249204646,this.B_im[2]=.003371507,this.B_re[3]=-.001541739,this.B_im[3]=.04105856,this.B_re[4]=-.10162907,this.B_im[4]=.01727609,this.B_re[5]=-.26623489,this.B_im[5]=-.36249218,this.B_re[6]=-.6870983,this.B_im[6]=-1.1651967,this.C_re=[],this.C_im=[],this.C_re[1]=1.3231270439,this.C_im[1]=0,this.C_re[2]=-.577245789,this.C_im[2]=-.007809598,this.C_re[3]=.508307513,this.C_im[3]=-.112208952,this.C_re[4]=-.15094762,this.C_im[4]=.18200602,this.C_re[5]=1.01418179,this.C_im[5]=1.64497696,this.C_re[6]=1.9660549,this.C_im[6]=2.5127645,this.D=[],this.D[1]=1.5627014243,this.D[2]=.5185406398,this.D[3]=-.03333098,this.D[4]=-.1052906,this.D[5]=-.0368594,this.D[6]=.007317,this.D[7]=.0122,this.D[8]=.00394,this.D[9]=-.0013}function ZL(i){var t,e=i.x,n=i.y,s=n-this.lat0,r=e-this.long0,o=s/gu*1e-5,a=r,l=1,h=0;for(t=1;t<=10;t++)l=l*o,h=h+this.A[t]*l;var f=h,d=a,p=1,y=0,_,E,w=0,L=0;for(t=1;t<=6;t++)_=p*f-y*d,E=y*f+p*d,p=_,y=E,w=w+this.B_re[t]*p-this.B_im[t]*y,L=L+this.B_im[t]*p+this.B_re[t]*y;return i.x=L*this.a+this.x0,i.y=w*this.a+this.y0,i}function JL(i){var t,e=i.x,n=i.y,s=e-this.x0,r=n-this.y0,o=r/this.a,a=s/this.a,l=1,h=0,f,d,p=0,y=0;for(t=1;t<=6;t++)f=l*o-h*a,d=h*o+l*a,l=f,h=d,p=p+this.C_re[t]*l-this.C_im[t]*h,y=y+this.C_im[t]*l+this.C_re[t]*h;for(var _=0;_<this.iterations;_++){var E=p,w=y,L,b,P=o,N=a;for(t=2;t<=6;t++)L=E*p-w*y,b=w*p+E*y,E=L,w=b,P=P+(t-1)*(this.B_re[t]*E-this.B_im[t]*w),N=N+(t-1)*(this.B_im[t]*E+this.B_re[t]*w);E=1,w=0;var S=this.B_re[1],C=this.B_im[1];for(t=2;t<=6;t++)L=E*p-w*y,b=w*p+E*y,E=L,w=b,S=S+t*(this.B_re[t]*E-this.B_im[t]*w),C=C+t*(this.B_im[t]*E+this.B_re[t]*w);var T=S*S+C*C;p=(P*S+N*C)/T,y=(N*S-P*C)/T}var I=p,M=y,R=1,A=0;for(t=1;t<=9;t++)R=R*I,A=A+this.D[t]*R;var F=this.lat0+A*gu*1e5,$=this.long0+M;return i.x=$,i.y=F,i}var QL=["New_Zealand_Map_Grid","nzmg"];const tC={init:KL,forward:ZL,inverse:JL,names:QL,iterations:WL};function eC(){}function nC(i){var t=i.x,e=i.y,n=Lt(t-this.long0,this.over),s=this.x0+this.a*n,r=this.y0+this.a*Math.log(Math.tan(Math.PI/4+e/2.5))*1.25;return i.x=s,i.y=r,i}function iC(i){i.x-=this.x0,i.y-=this.y0;var t=Lt(this.long0+i.x/this.a,this.over),e=2.5*(Math.atan(Math.exp(.8*i.y/this.a))-Math.PI/4);return i.x=t,i.y=e,i}var sC=["Miller_Cylindrical","mill"];const rC={init:eC,forward:nC,inverse:iC,names:sC};var oC=20;function aC(){this.long0=this.long0||0,this.sphere?(this.n=1,this.m=0,this.es=0,this.C_y=Math.sqrt((this.m+1)/this.n),this.C_x=this.C_y/(this.m+1)):this.en=zm(this.es)}function dE(i){var t,e,n=i.x,s=i.y;if(n=Lt(n-this.long0,this.over),this.sphere){if(!this.m)s=this.n!==1?Math.asin(this.n*Math.sin(s)):s;else for(var r=this.n*Math.sin(s),o=oC;o;--o){var a=(this.m*s+Math.sin(s)-r)/(this.m+Math.cos(s));if(s-=a,Math.abs(a)<Mt)break}t=this.a*this.C_x*n*(this.m+Math.cos(s)),e=this.a*this.C_y*s}else{var l=Math.sin(s),h=Math.cos(s);e=this.a*gl(s,l,h,this.en),t=this.a*n*h/Math.sqrt(1-this.es*l*l)}return i.x=t,i.y=e,i}function gE(i){var t,e,n,s;return i.x-=this.x0,n=i.x/this.a,i.y-=this.y0,t=i.y/this.a,this.sphere?(t/=this.C_y,n=n/(this.C_x*(this.m+Math.cos(t))),this.m?t=Br((this.m*t+Math.sin(t))/this.n):this.n!==1&&(t=Br(Math.sin(t)/this.n)),n=Lt(n+this.long0,this.over),t=Vr(t)):(t=Um(i.y/this.a,this.es,this.en),s=Math.abs(t),s<_t?(s=Math.sin(t),e=this.long0+i.x*Math.sqrt(1-this.es*s*s)/(this.a*Math.cos(t)),n=Lt(e,this.over)):s-Mt<_t&&(n=this.long0)),i.x=n,i.y=t,i}var lC=["Sinusoidal","sinu"];const uC={init:aC,forward:dE,inverse:gE,names:lC};function cC(){this.sphere=!0,this.b=this.a,this.m=1,this.n=2.5707963267948966,this.es=0,this.C_y=Math.sqrt((this.m+1)/this.n),this.C_x=this.C_y/(this.m+1)}var hC=dE,fC=gE,dC=["Eckert_VI","eck6"];const gC={init:cC,forward:hC,inverse:fC,names:dC};function mC(){this.x0=this.x0!==void 0?this.x0:0,this.y0=this.y0!==void 0?this.y0:0,this.long0=this.long0!==void 0?this.long0:0}function pC(i){for(var t=i.x,e=i.y,n=Lt(t-this.long0,this.over),s=e,r=Math.PI*Math.sin(e);;){var o=-(s+Math.sin(s)-r)/(1+Math.cos(s));if(s+=o,Math.abs(o)<Mt)break}s/=2,Math.PI/2-Math.abs(e)<Mt&&(n=0);var a=.900316316158*this.a*n*Math.cos(s)+this.x0,l=1.4142135623731*this.a*Math.sin(s)+this.y0;return i.x=a,i.y=l,i}function yC(i){var t,e;i.x-=this.x0,i.y-=this.y0,e=i.y/(1.4142135623731*this.a),Math.abs(e)>.999999999999&&(e=.999999999999),t=Math.asin(e);var n=Lt(this.long0+i.x/(.900316316158*this.a*Math.cos(t)),this.over);n<-Math.PI&&(n=-Math.PI),n>Math.PI&&(n=Math.PI),e=(2*t+Math.sin(2*t))/Math.PI,Math.abs(e)>1&&(e=1);var s=Math.asin(e);return i.x=n,i.y=s,i}var _C=["Mollweide","moll"];const vC={init:mC,forward:pC,inverse:yC,names:_C};function EC(){Math.abs(this.lat1+this.lat2)<Mt||(this.lat2=this.lat2||this.lat1,this.temp=this.b/this.a,this.es=1-Math.pow(this.temp,2),this.e=Math.sqrt(this.es),this.e0=cc(this.es),this.e1=hc(this.es),this.e2=fc(this.es),this.e3=dc(this.es),this.sin_phi=Math.sin(this.lat1),this.cos_phi=Math.cos(this.lat1),this.ms1=Zs(this.e,this.sin_phi,this.cos_phi),this.ml1=Zn(this.e0,this.e1,this.e2,this.e3,this.lat1),Math.abs(this.lat1-this.lat2)<Mt?this.ns=this.sin_phi:(this.sin_phi=Math.sin(this.lat2),this.cos_phi=Math.cos(this.lat2),this.ms2=Zs(this.e,this.sin_phi,this.cos_phi),this.ml2=Zn(this.e0,this.e1,this.e2,this.e3,this.lat2),this.ns=(this.ms1-this.ms2)/(this.ml2-this.ml1)),this.g=this.ml1+this.ms1/this.ns,this.ml0=Zn(this.e0,this.e1,this.e2,this.e3,this.lat0),this.rh=this.a*(this.g-this.ml0))}function wC(i){var t=i.x,e=i.y,n;if(this.sphere)n=this.a*(this.g-e);else{var s=Zn(this.e0,this.e1,this.e2,this.e3,e);n=this.a*(this.g-s)}var r=this.ns*Lt(t-this.long0,this.over),o=this.x0+n*Math.sin(r),a=this.y0+this.rh-n*Math.cos(r);return i.x=o,i.y=a,i}function xC(i){i.x-=this.x0,i.y=this.rh-i.y+this.y0;var t,e,n,s;this.ns>=0?(e=Math.sqrt(i.x*i.x+i.y*i.y),t=1):(e=-Math.sqrt(i.x*i.x+i.y*i.y),t=-1);var r=0;if(e!==0&&(r=Math.atan2(t*i.x,t*i.y)),this.sphere)return s=Lt(this.long0+r/this.ns,this.over),n=Vr(this.g-e/this.a),i.x=s,i.y=n,i;var o=this.g-e/this.a;return n=jh(o,this.e0,this.e1,this.e2,this.e3),s=Lt(this.long0+r/this.ns,this.over),i.x=s,i.y=n,i}var bC=["Equidistant_Conic","eqdc"];const IC={init:EC,forward:wC,inverse:xC,names:bC};function SC(){this.R=this.a}function MC(i){var t=i.x,e=i.y,n=Lt(t-this.long0,this.over),s,r;if(Math.abs(e)<=Mt)return s=this.x0+this.R*n,r=this.y0,i.x=s,i.y=r,i;var o=Br(2*Math.abs(e/Math.PI));if(Math.abs(n)<=Mt||Math.abs(Math.abs(e)-_t)<=Mt)return s=this.x0,e>=0?r=this.y0+Math.PI*this.R*Math.tan(.5*o):r=this.y0+Math.PI*this.R*-Math.tan(.5*o),i.x=s,i.y=r,i;var a=.5*Math.abs(Math.PI/n-n/Math.PI),l=a*a,h=Math.sin(o),f=Math.cos(o),d=f/(h+f-1),p=d*d,y=d*(2/h-1),_=y*y,E=Math.PI*this.R*(a*(d-_)+Math.sqrt(l*(d-_)*(d-_)-(_+l)*(p-_)))/(_+l);n<0&&(E=-E),s=this.x0+E;var w=l+d;return E=Math.PI*this.R*(y*w-a*Math.sqrt((_+l)*(l+1)-w*w))/(_+l),e>=0?r=this.y0+E:r=this.y0-E,i.x=s,i.y=r,i}function NC(i){var t,e,n,s,r,o,a,l,h,f,d,p,y;return i.x-=this.x0,i.y-=this.y0,d=Math.PI*this.R,n=i.x/d,s=i.y/d,r=n*n+s*s,o=-Math.abs(s)*(1+r),a=o-2*s*s+n*n,l=-2*o+1+2*s*s+r*r,y=s*s/l+(2*a*a*a/l/l/l-9*o*a/l/l)/27,h=(o-a*a/3/l)/l,f=2*Math.sqrt(-h/3),d=3*y/h/f,Math.abs(d)>1&&(d>=0?d=1:d=-1),p=Math.acos(d)/3,i.y>=0?e=(-f*Math.cos(p+Math.PI/3)-a/3/l)*Math.PI:e=-(-f*Math.cos(p+Math.PI/3)-a/3/l)*Math.PI,Math.abs(n)<Mt?t=this.long0:t=Lt(this.long0+Math.PI*(r-1+Math.sqrt(1+2*(n*n-s*s)+r*r))/2/n,this.over),i.x=t,i.y=e,i}var LC=["Van_der_Grinten_I","VanDerGrinten","Van_der_Grinten","vandg"];const CC={init:SC,forward:MC,inverse:NC,names:LC};function PC(i,t,e,n,s,r){const o=n-t,a=Math.atan((1-r)*Math.tan(i)),l=Math.atan((1-r)*Math.tan(e)),h=Math.sin(a),f=Math.cos(a),d=Math.sin(l),p=Math.cos(l);let y=o,_,E=100,w,L,b,P,N,S,C,T,I,M,R,A,F,$;do{if(w=Math.sin(y),L=Math.cos(y),b=Math.sqrt(p*w*(p*w)+(f*d-h*p*L)*(f*d-h*p*L)),b===0)return{azi1:0,s12:0};P=h*d+f*p*L,N=Math.atan2(b,P),S=f*p*w/b,C=1-S*S,T=C!==0?P-2*h*d/C:0,I=r/16*C*(4+r*(4-3*C)),_=y,y=o+(1-I)*r*S*(N+I*b*(T+I*P*(-1+2*T*T)))}while(Math.abs(y-_)>1e-12&&--E>0);return E===0?{azi1:NaN,s12:NaN}:(M=C*(s*s-s*(1-r)*(s*(1-r)))/(s*(1-r)*(s*(1-r))),R=1+M/16384*(4096+M*(-768+M*(320-175*M))),A=M/1024*(256+M*(-128+M*(74-47*M))),F=A*b*(T+A/4*(P*(-1+2*T*T)-A/6*T*(-3+4*b*b)*(-3+4*T*T))),$=s*(1-r)*R*(N-F),{azi1:Math.atan2(p*w,f*d-h*p*L),s12:$})}function kC(i,t,e,n,s,r){const o=Math.atan((1-r)*Math.tan(i)),a=Math.sin(o),l=Math.cos(o),h=Math.sin(e),f=Math.cos(e),d=Math.atan2(a,l*f),p=l*h,y=1-p*p,_=y*(s*s-s*(1-r)*(s*(1-r)))/(s*(1-r)*(s*(1-r))),E=1+_/16384*(4096+_*(-768+_*(320-175*_))),w=_/1024*(256+_*(-128+_*(74-47*_)));let L=n/(s*(1-r)*E),b,P=100,N,S,C,T;do N=Math.cos(2*d+L),S=Math.sin(L),C=Math.cos(L),T=w*S*(N+w/4*(C*(-1+2*N*N)-w/6*N*(-3+4*S*S)*(-3+4*N*N))),b=L,L=n/(s*(1-r)*E)+T;while(Math.abs(L-b)>1e-12&&--P>0);if(P===0)return{lat2:NaN,lon2:NaN};const I=a*S-l*C*f,M=Math.atan2(a*C+l*S*f,(1-r)*Math.sqrt(p*p+I*I)),R=Math.atan2(S*h,l*C-a*S*f),A=r/16*y*(4+r*(4-3*y)),F=R-(1-A)*r*p*(L+A*S*(N+A*C*(-1+2*N*N))),$=t+F;return{lat2:M,lon2:$}}function TC(){this.sin_p12=Math.sin(this.lat0),this.cos_p12=Math.cos(this.lat0),this.x0=this.x0||0,this.y0=this.y0||0,this.long0=this.long0||0,this.f=this.es/(1+Math.sqrt(1-this.es))}function RC(i){var t=i.x,e=i.y,n=Math.sin(i.y),s=Math.cos(i.y),r=Lt(t-this.long0,this.over),o,a,l,h,f,d,p,y,_,E,w;return this.sphere?Math.abs(this.sin_p12-1)<=Mt?(i.x=this.x0+this.a*(_t-e)*Math.sin(r),i.y=this.y0-this.a*(_t-e)*Math.cos(r),i):Math.abs(this.sin_p12+1)<=Mt?(i.x=this.x0+this.a*(_t+e)*Math.sin(r),i.y=this.y0+this.a*(_t+e)*Math.cos(r),i):(_=this.sin_p12*n+this.cos_p12*s*Math.cos(r),p=Math.acos(_),y=p?p/Math.sin(p):1,i.x=this.x0+this.a*y*s*Math.sin(r),i.y=this.y0+this.a*y*(this.cos_p12*n-this.sin_p12*s*Math.cos(r)),i):(o=cc(this.es),a=hc(this.es),l=fc(this.es),h=dc(this.es),Math.abs(this.sin_p12-1)<=Mt?(f=this.a*Zn(o,a,l,h,_t),d=this.a*Zn(o,a,l,h,e),i.x=this.x0+(f-d)*Math.sin(r),i.y=this.y0-(f-d)*Math.cos(r),i):Math.abs(this.sin_p12+1)<=Mt?(f=this.a*Zn(o,a,l,h,_t),d=this.a*Zn(o,a,l,h,e),i.x=this.x0+(f+d)*Math.sin(r),i.y=this.y0+(f+d)*Math.cos(r),i):Math.abs(t)<Mt&&Math.abs(e-this.lat0)<Mt?(i.x=this.x0,i.y=this.y0,i):(E=PC(this.lat0,this.long0,e,t,this.a,this.f),w=E.azi1,i.x=this.x0+E.s12*Math.sin(w),i.y=this.y0+E.s12*Math.cos(w),i))}function AC(i){i.x-=this.x0,i.y-=this.y0;var t,e,n,s,r,o,a,l,h,f,d,p,y,_,E,w;return this.sphere?(t=Math.sqrt(i.x*i.x+i.y*i.y),t>2*_t*this.a?void 0:(e=t/this.a,n=Math.sin(e),s=Math.cos(e),r=this.long0,Math.abs(t)<=Mt?o=this.lat0:(o=Br(s*this.sin_p12+i.y*n*this.cos_p12/t),a=Math.abs(this.lat0)-_t,Math.abs(a)<=Mt?this.lat0>=0?r=Lt(this.long0+Math.atan2(i.x,-i.y),this.over):r=Lt(this.long0-Math.atan2(-i.x,i.y),this.over):r=Lt(this.long0+Math.atan2(i.x*n,t*this.cos_p12*s-i.y*this.sin_p12*n),this.over)),i.x=r,i.y=o,i)):(l=cc(this.es),h=hc(this.es),f=fc(this.es),d=dc(this.es),Math.abs(this.sin_p12-1)<=Mt?(p=this.a*Zn(l,h,f,d,_t),t=Math.sqrt(i.x*i.x+i.y*i.y),y=p-t,o=jh(y/this.a,l,h,f,d),r=Lt(this.long0+Math.atan2(i.x,-1*i.y),this.over),i.x=r,i.y=o,i):Math.abs(this.sin_p12+1)<=Mt?(p=this.a*Zn(l,h,f,d,_t),t=Math.sqrt(i.x*i.x+i.y*i.y),y=t-p,o=jh(y/this.a,l,h,f,d),r=Lt(this.long0+Math.atan2(i.x,i.y),this.over),i.x=r,i.y=o,i):(_=Math.atan2(i.x,i.y),E=Math.sqrt(i.x*i.x+i.y*i.y),w=kC(this.lat0,this.long0,_,E,this.a,this.f),i.x=w.lon2,i.y=w.lat2,i))}var OC=["Azimuthal_Equidistant","aeqd"];const FC={init:TC,forward:RC,inverse:AC,names:OC};function $C(){this.sin_p14=Math.sin(this.lat0||0),this.cos_p14=Math.cos(this.lat0||0)}function DC(i){var t,e,n,s,r,o,a,l,h=i.x,f=i.y;return n=Lt(h-(this.long0||0),this.over),t=Math.sin(f),e=Math.cos(f),s=Math.cos(n),o=this.sin_p14*t+this.cos_p14*e*s,r=1,(o>0||Math.abs(o)<=Mt)&&(a=(this.x0||0)+this.a*r*e*Math.sin(n),l=(this.y0||0)+this.a*r*(this.cos_p14*t-this.sin_p14*e*s)),i.x=a,i.y=l,i}function GC(i){var t,e,n,s,r,o,a,l,h;return i.x-=this.x0||0,i.y-=this.y0||0,t=Math.sqrt(i.x*i.x+i.y*i.y),e=Br(t/this.a),n=Math.sin(e),s=Math.cos(e),l=this.long0||0,h=this.lat0||0,o=l,Math.abs(t)<=Mt?(a=h,i.x=o,i.y=a,i):(a=Br(s*this.sin_p14+i.y*n*this.cos_p14/t),r=Math.abs(h)-_t,Math.abs(r)<=Mt?(h>=0?o=Lt(l+Math.atan2(i.x,-i.y),this.over):o=Lt(l-Math.atan2(-i.x,i.y),this.over),i.x=o,i.y=a,i):(o=Lt(l+Math.atan2(i.x*n,t*this.cos_p14*s-i.y*this.sin_p14*n),this.over),i.x=o,i.y=a,i))}var BC=["ortho"];const qC={init:$C,forward:DC,inverse:GC,names:BC};var Ke={FRONT:1,RIGHT:2,BACK:3,LEFT:4,TOP:5,BOTTOM:6},Ie={AREA_0:1,AREA_1:2,AREA_2:3,AREA_3:4};function zC(){this.x0=this.x0||0,this.y0=this.y0||0,this.lat0=this.lat0||0,this.long0=this.long0||0,this.lat_ts=this.lat_ts||0,this.title=this.title||"Quadrilateralized Spherical Cube",this.lat0>=_t-be/2?this.face=Ke.TOP:this.lat0<=-(_t-be/2)?this.face=Ke.BOTTOM:Math.abs(this.long0)<=be?this.face=Ke.FRONT:Math.abs(this.long0)<=_t+be?this.face=this.long0>0?Ke.RIGHT:Ke.LEFT:this.face=Ke.BACK,this.es!==0&&(this.one_minus_f=1-(this.a-this.b)/this.a,this.one_minus_f_squared=this.one_minus_f*this.one_minus_f)}function UC(i){var t={x:0,y:0},e,n,s,r,o,a,l={value:0};if(i.x-=this.long0,this.es!==0?e=Math.atan(this.one_minus_f_squared*Math.tan(i.y)):e=i.y,n=i.x,this.face===Ke.TOP)r=_t-e,n>=be&&n<=_t+be?(l.value=Ie.AREA_0,s=n-_t):n>_t+be||n<=-(_t+be)?(l.value=Ie.AREA_1,s=n>0?n-en:n+en):n>-(_t+be)&&n<=-be?(l.value=Ie.AREA_2,s=n+_t):(l.value=Ie.AREA_3,s=n);else if(this.face===Ke.BOTTOM)r=_t+e,n>=be&&n<=_t+be?(l.value=Ie.AREA_0,s=-n+_t):n<be&&n>=-be?(l.value=Ie.AREA_1,s=-n):n<-be&&n>=-(_t+be)?(l.value=Ie.AREA_2,s=-n-_t):(l.value=Ie.AREA_3,s=n>0?-n+en:-n-en);else{var h,f,d,p,y,_,E;this.face===Ke.RIGHT?n=ka(n,+_t):this.face===Ke.BACK?n=ka(n,+en):this.face===Ke.LEFT&&(n=ka(n,-_t)),p=Math.sin(e),y=Math.cos(e),_=Math.sin(n),E=Math.cos(n),h=y*E,f=y*_,d=p,this.face===Ke.FRONT?(r=Math.acos(h),s=qc(r,d,f,l)):this.face===Ke.RIGHT?(r=Math.acos(f),s=qc(r,d,-h,l)):this.face===Ke.BACK?(r=Math.acos(-h),s=qc(r,d,-f,l)):this.face===Ke.LEFT?(r=Math.acos(-f),s=qc(r,d,h,l)):(r=s=0,l.value=Ie.AREA_0)}return a=Math.atan(12/en*(s+Math.acos(Math.sin(s)*Math.cos(be))-_t)),o=Math.sqrt((1-Math.cos(r))/(Math.cos(a)*Math.cos(a))/(1-Math.cos(Math.atan(1/Math.cos(s))))),l.value===Ie.AREA_1?a+=_t:l.value===Ie.AREA_2?a+=en:l.value===Ie.AREA_3&&(a+=1.5*en),t.x=o*Math.cos(a),t.y=o*Math.sin(a),t.x=t.x*this.a+this.x0,t.y=t.y*this.a+this.y0,i.x=t.x,i.y=t.y,i}function YC(i){var t={lam:0,phi:0},e,n,s,r,o,a,l,h,f,d={value:0};if(i.x=(i.x-this.x0)/this.a,i.y=(i.y-this.y0)/this.a,n=Math.atan(Math.sqrt(i.x*i.x+i.y*i.y)),e=Math.atan2(i.y,i.x),i.x>=0&&i.x>=Math.abs(i.y)?d.value=Ie.AREA_0:i.y>=0&&i.y>=Math.abs(i.x)?(d.value=Ie.AREA_1,e-=_t):i.x<0&&-i.x>=Math.abs(i.y)?(d.value=Ie.AREA_2,e=e<0?e+en:e-en):(d.value=Ie.AREA_3,e+=_t),f=en/12*Math.tan(e),o=Math.sin(f)/(Math.cos(f)-1/Math.sqrt(2)),a=Math.atan(o),s=Math.cos(e),r=Math.tan(n),l=1-s*s*r*r*(1-Math.cos(Math.atan(1/Math.cos(a)))),l<-1?l=-1:l>1&&(l=1),this.face===Ke.TOP)h=Math.acos(l),t.phi=_t-h,d.value===Ie.AREA_0?t.lam=a+_t:d.value===Ie.AREA_1?t.lam=a<0?a+en:a-en:d.value===Ie.AREA_2?t.lam=a-_t:t.lam=a;else if(this.face===Ke.BOTTOM)h=Math.acos(l),t.phi=h-_t,d.value===Ie.AREA_0?t.lam=-a+_t:d.value===Ie.AREA_1?t.lam=-a:d.value===Ie.AREA_2?t.lam=-a-_t:t.lam=a<0?-a-en:-a+en;else{var p,y,_;p=l,f=p*p,f>=1?_=0:_=Math.sqrt(1-f)*Math.sin(a),f+=_*_,f>=1?y=0:y=Math.sqrt(1-f),d.value===Ie.AREA_1?(f=y,y=-_,_=f):d.value===Ie.AREA_2?(y=-y,_=-_):d.value===Ie.AREA_3&&(f=y,y=_,_=-f),this.face===Ke.RIGHT?(f=p,p=-y,y=f):this.face===Ke.BACK?(p=-p,y=-y):this.face===Ke.LEFT&&(f=p,p=y,y=-f),t.phi=Math.acos(-_)-_t,t.lam=Math.atan2(y,p),this.face===Ke.RIGHT?t.lam=ka(t.lam,-_t):this.face===Ke.BACK?t.lam=ka(t.lam,-en):this.face===Ke.LEFT&&(t.lam=ka(t.lam,+_t))}if(this.es!==0){var E,w,L;E=t.phi<0?1:0,w=Math.tan(t.phi),L=this.b/Math.sqrt(w*w+this.one_minus_f_squared),t.phi=Math.atan(Math.sqrt(this.a*this.a-L*L)/(this.one_minus_f*L)),E&&(t.phi=-t.phi)}return t.lam+=this.long0,i.x=t.lam,i.y=t.phi,i}function qc(i,t,e,n){var s;return i<Mt?(n.value=Ie.AREA_0,s=0):(s=Math.atan2(t,e),Math.abs(s)<=be?n.value=Ie.AREA_0:s>be&&s<=_t+be?(n.value=Ie.AREA_1,s-=_t):s>_t+be||s<=-(_t+be)?(n.value=Ie.AREA_2,s=s>=0?s-en:s+en):(n.value=Ie.AREA_3,s+=_t)),s}function ka(i,t){var e=i+t;return e<-en?e+=Mu:e>+en&&(e-=Mu),e}var XC=["Quadrilateralized Spherical Cube","Quadrilateralized_Spherical_Cube","qsc"];const jC={init:zC,forward:UC,inverse:YC,names:XC};var Yg=[[1,22199e-21,-715515e-10,31103e-10],[.9986,-482243e-9,-24897e-9,-13309e-10],[.9954,-83103e-8,-448605e-10,-986701e-12],[.99,-.00135364,-59661e-9,36777e-10],[.9822,-.00167442,-449547e-11,-572411e-11],[.973,-.00214868,-903571e-10,18736e-12],[.96,-.00305085,-900761e-10,164917e-11],[.9427,-.00382792,-653386e-10,-26154e-10],[.9216,-.00467746,-10457e-8,481243e-11],[.8962,-.00536223,-323831e-10,-543432e-11],[.8679,-.00609363,-113898e-9,332484e-11],[.835,-.00698325,-640253e-10,934959e-12],[.7986,-.00755338,-500009e-10,935324e-12],[.7597,-.00798324,-35971e-9,-227626e-11],[.7186,-.00851367,-701149e-10,-86303e-10],[.6732,-.00986209,-199569e-9,191974e-10],[.6213,-.010418,883923e-10,624051e-11],[.5722,-.00906601,182e-6,624051e-11],[.5322,-.00677797,275608e-9,624051e-11]],nu=[[-520417e-23,.0124,121431e-23,-845284e-16],[.062,.0124,-126793e-14,422642e-15],[.124,.0124,507171e-14,-160604e-14],[.186,.0123999,-190189e-13,600152e-14],[.248,.0124002,710039e-13,-224e-10],[.31,.0123992,-264997e-12,835986e-13],[.372,.0124029,988983e-12,-311994e-12],[.434,.0123893,-369093e-11,-435621e-12],[.4958,.0123198,-102252e-10,-345523e-12],[.5571,.0121916,-154081e-10,-582288e-12],[.6176,.0119938,-241424e-10,-525327e-12],[.6769,.011713,-320223e-10,-516405e-12],[.7346,.0113541,-397684e-10,-609052e-12],[.7903,.0109107,-489042e-10,-104739e-11],[.8435,.0103431,-64615e-9,-140374e-14],[.8936,.00969686,-64636e-9,-8547e-9],[.9394,.00840947,-192841e-9,-42106e-10],[.9761,.00616527,-256e-6,-42106e-10],[1,.00328947,-319159e-9,-42106e-10]],mE=.8487,pE=1.3523,yE=ai/5,VC=1/yE,xa=18,Vh=function(i,t){return i[0]+t*(i[1]+t*(i[2]+t*i[3]))},HC=function(i,t){return i[1]+t*(2*i[2]+t*3*i[3])};function WC(i,t,e,n){for(var s=t;n;--n){var r=i(s);if(s-=r,Math.abs(r)<e)break}return s}function KC(){this.x0=this.x0||0,this.y0=this.y0||0,this.long0=this.long0||0,this.es=0,this.title=this.title||"Robinson"}function ZC(i){var t=Lt(i.x-this.long0,this.over),e=Math.abs(i.y),n=Math.floor(e*yE);n<0?n=0:n>=xa&&(n=xa-1),e=ai*(e-VC*n);var s={x:Vh(Yg[n],e)*t,y:Vh(nu[n],e)};return i.y<0&&(s.y=-s.y),s.x=s.x*this.a*mE+this.x0,s.y=s.y*this.a*pE+this.y0,i.z!==void 0&&(s.z=i.z),i.m!==void 0&&(s.m=i.m),s}function JC(i){var t={x:(i.x-this.x0)/(this.a*mE),y:Math.abs(i.y-this.y0)/(this.a*pE)};if(t.y>=1)t.x/=Yg[xa][0],t.y=i.y<0?-_t:_t;else{var e=Math.floor(t.y*xa);for(e<0?e=0:e>=xa&&(e=xa-1);;)if(nu[e][0]>t.y)--e;else if(nu[e+1][0]<=t.y)++e;else break;var n=nu[e],s=5*(t.y-n[0])/(nu[e+1][0]-n[0]);s=WC(function(r){return(Vh(n,r)-t.y)/HC(n,r)},s,Mt,100),t.x/=Vh(Yg[e],s),t.y=(5*e+s)*We,i.y<0&&(t.y=-t.y)}return t.x=Lt(t.x+this.long0,this.over),i.z!==void 0&&(t.z=i.z),i.m!==void 0&&(t.m=i.m),t}var QC=["Robinson","robin"];const tP={init:KC,forward:ZC,inverse:JC,names:QC};function eP(){this.name="geocent"}function nP(i){var t=eE(i,this.es,this.a);return t}function iP(i){var t=nE(i,this.es,this.a,this.b);return t}var sP=["Geocentric","geocentric","geocent","Geocent"];const rP={init:eP,forward:nP,inverse:iP,names:sP};var Fn={N_POLE:0,S_POLE:1,EQUIT:2,OBLIQ:3},zl={h:{def:1e5,num:!0},azi:{def:0,num:!0,degrees:!0},tilt:{def:0,num:!0,degrees:!0},long0:{def:0,num:!0},lat0:{def:0,num:!0}};function oP(){if(Object.keys(zl).forEach((function(e){if(typeof this[e]>"u")this[e]=zl[e].def;else{if(zl[e].num&&isNaN(this[e]))throw new Error("Invalid parameter value, must be numeric "+e+" = "+this[e]);zl[e].num&&(this[e]=parseFloat(this[e]))}zl[e].degrees&&(this[e]=this[e]*We)}).bind(this)),Math.abs(Math.abs(this.lat0)-_t)<Mt?this.mode=this.lat0<0?Fn.S_POLE:Fn.N_POLE:Math.abs(this.lat0)<Mt?this.mode=Fn.EQUIT:(this.mode=Fn.OBLIQ,this.sinph0=Math.sin(this.lat0),this.cosph0=Math.cos(this.lat0)),this.pn1=this.h/this.a,this.pn1<=0||this.pn1>1e10)throw new Error("Invalid height");this.p=1+this.pn1,this.rp=1/this.p,this.h1=1/this.pn1,this.pfact=(this.p+1)*this.h1,this.es=0;var i=this.tilt,t=this.azi;this.cg=Math.cos(t),this.sg=Math.sin(t),this.cw=Math.cos(i),this.sw=Math.sin(i)}function aP(i){i.x-=this.long0;var t=Math.sin(i.y),e=Math.cos(i.y),n=Math.cos(i.x),s,r;switch(this.mode){case Fn.OBLIQ:r=this.sinph0*t+this.cosph0*e*n;break;case Fn.EQUIT:r=e*n;break;case Fn.S_POLE:r=-t;break;case Fn.N_POLE:r=t;break}switch(r=this.pn1/(this.p-r),s=r*e*Math.sin(i.x),this.mode){case Fn.OBLIQ:r*=this.cosph0*t-this.sinph0*e*n;break;case Fn.EQUIT:r*=t;break;case Fn.N_POLE:r*=-(e*n);break;case Fn.S_POLE:r*=e*n;break}var o,a;return o=r*this.cg+s*this.sg,a=1/(o*this.sw*this.h1+this.cw),s=(s*this.cg-r*this.sg)*this.cw*a,r=o*a,i.x=s*this.a,i.y=r*this.a,i}function lP(i){i.x/=this.a,i.y/=this.a;var t={x:i.x,y:i.y},e,n,s;s=1/(this.pn1-i.y*this.sw),e=this.pn1*i.x*s,n=this.pn1*i.y*this.cw*s,i.x=e*this.cg+n*this.sg,i.y=n*this.cg-e*this.sg;var r=ri(i.x,i.y);if(Math.abs(r)<Mt)t.x=0,t.y=i.y;else{var o,a;switch(a=1-r*r*this.pfact,a=(this.p-Math.sqrt(a))/(this.pn1/r+r/this.pn1),o=Math.sqrt(1-a*a),this.mode){case Fn.OBLIQ:t.y=Math.asin(o*this.sinph0+i.y*a*this.cosph0/r),i.y=(o-this.sinph0*Math.sin(t.y))*r,i.x*=a*this.cosph0;break;case Fn.EQUIT:t.y=Math.asin(i.y*a/r),i.y=o*r,i.x*=a;break;case Fn.N_POLE:t.y=Math.asin(o),i.y=-i.y;break;case Fn.S_POLE:t.y=-Math.asin(o);break}t.x=Math.atan2(i.x,i.y)}return i.x=t.x+this.long0,i.y=t.y,i}var uP=["Tilted_Perspective","tpers"];const cP={init:oP,forward:aP,inverse:lP,names:uP};function hP(){if(this.flip_axis=this.sweep==="x"?1:0,this.h=Number(this.h),this.radius_g_1=this.h/this.a,this.radius_g_1<=0||this.radius_g_1>1e10)throw new Error;if(this.radius_g=1+this.radius_g_1,this.C=this.radius_g*this.radius_g-1,this.es!==0){var i=1-this.es,t=1/i;this.radius_p=Math.sqrt(i),this.radius_p2=i,this.radius_p_inv2=t,this.shape="ellipse"}else this.radius_p=1,this.radius_p2=1,this.radius_p_inv2=1,this.shape="sphere";this.title||(this.title="Geostationary Satellite View")}function fP(i){var t=i.x,e=i.y,n,s,r,o;if(t=t-this.long0,this.shape==="ellipse"){e=Math.atan(this.radius_p2*Math.tan(e));var a=this.radius_p/ri(this.radius_p*Math.cos(e),Math.sin(e));if(s=a*Math.cos(t)*Math.cos(e),r=a*Math.sin(t)*Math.cos(e),o=a*Math.sin(e),(this.radius_g-s)*s-r*r-o*o*this.radius_p_inv2<0)return i.x=Number.NaN,i.y=Number.NaN,i;n=this.radius_g-s,this.flip_axis?(i.x=this.radius_g_1*Math.atan(r/ri(o,n)),i.y=this.radius_g_1*Math.atan(o/n)):(i.x=this.radius_g_1*Math.atan(r/n),i.y=this.radius_g_1*Math.atan(o/ri(r,n)))}else this.shape==="sphere"&&(n=Math.cos(e),s=Math.cos(t)*n,r=Math.sin(t)*n,o=Math.sin(e),n=this.radius_g-s,this.flip_axis?(i.x=this.radius_g_1*Math.atan(r/ri(o,n)),i.y=this.radius_g_1*Math.atan(o/n)):(i.x=this.radius_g_1*Math.atan(r/n),i.y=this.radius_g_1*Math.atan(o/ri(r,n))));return i.x=i.x*this.a,i.y=i.y*this.a,i}function dP(i){var t=-1,e=0,n=0,s,r,o,a;if(i.x=i.x/this.a,i.y=i.y/this.a,this.shape==="ellipse"){this.flip_axis?(n=Math.tan(i.y/this.radius_g_1),e=Math.tan(i.x/this.radius_g_1)*ri(1,n)):(e=Math.tan(i.x/this.radius_g_1),n=Math.tan(i.y/this.radius_g_1)*ri(1,e));var l=n/this.radius_p;if(s=e*e+l*l+t*t,r=2*this.radius_g*t,o=r*r-4*s*this.C,o<0)return i.x=Number.NaN,i.y=Number.NaN,i;a=(-r-Math.sqrt(o))/(2*s),t=this.radius_g+a*t,e*=a,n*=a,i.x=Math.atan2(e,t),i.y=Math.atan(n*Math.cos(i.x)/t),i.y=Math.atan(this.radius_p_inv2*Math.tan(i.y))}else if(this.shape==="sphere"){if(this.flip_axis?(n=Math.tan(i.y/this.radius_g_1),e=Math.tan(i.x/this.radius_g_1)*Math.sqrt(1+n*n)):(e=Math.tan(i.x/this.radius_g_1),n=Math.tan(i.y/this.radius_g_1)*Math.sqrt(1+e*e)),s=e*e+n*n+t*t,r=2*this.radius_g*t,o=r*r-4*s*this.C,o<0)return i.x=Number.NaN,i.y=Number.NaN,i;a=(-r-Math.sqrt(o))/(2*s),t=this.radius_g+a*t,e*=a,n*=a,i.x=Math.atan2(e,t),i.y=Math.atan(n*Math.cos(i.x)/t)}return i.x=i.x+this.long0,i}var gP=["Geostationary Satellite View","Geostationary_Satellite","geos"];const mP={init:hP,forward:fP,inverse:dP,names:gP};var mu=1.340264,pu=-.081106,yu=893e-6,_u=.003796,Hh=Math.sqrt(3)/2;function pP(){this.long0=this.long0!==void 0?this.long0:0,this.x0=this.x0!==void 0?this.x0:0,this.y0=this.y0!==void 0?this.y0:0,this.es!==0&&(this.apa=hE(this.es),this.qp=Us(this.e,1),this.rqda=Math.sqrt(.5*this.qp))}function yP(i){var t=Lt(i.x-this.long0,this.over),e=i.y,n=Math.sin(e);this.es!==0&&(n=Us(this.e,n)/this.qp);var s=Math.asin(Hh*n),r=s*s,o=r*r*r;return i.x=t*Math.cos(s)/(Hh*(mu+3*pu*r+o*(7*yu+9*_u*r))),i.y=s*(mu+pu*r+o*(yu+_u*r)),this.es!==0&&(i.x*=this.rqda,i.y*=this.rqda),i.x=this.a*i.x+this.x0,i.y=this.a*i.y+this.y0,i}function _P(i){i.x=(i.x-this.x0)/this.a,i.y=(i.y-this.y0)/this.a,this.es!==0&&(i.x/=this.rqda,i.y/=this.rqda);var t=1e-9,e=12,n=i.y,s,r,o,a,l,h;for(h=0;h<e&&(s=n*n,r=s*s*s,o=n*(mu+pu*s+r*(yu+_u*s))-i.y,a=mu+3*pu*s+r*(7*yu+9*_u*s),n-=l=o/a,!(Math.abs(l)<t));++h);return s=n*n,r=s*s*s,i.x=Hh*i.x*(mu+3*pu*s+r*(7*yu+9*_u*s))/Math.cos(n),i.y=Math.asin(Math.sin(n)/Hh),this.es!==0&&(i.y=fE(i.y,this.apa)),i.x=Lt(i.x+this.long0,this.over),i}var vP=["eqearth","Equal Earth","Equal_Earth"];const EP={init:pP,forward:yP,inverse:_P,names:vP};var Cu=1e-10;function wP(){var i;if(this.phi1=this.lat1,Math.abs(this.phi1)<Cu)throw new Error;this.es?(this.en=zm(this.es),this.m1=gl(this.phi1,this.am1=Math.sin(this.phi1),i=Math.cos(this.phi1),this.en),this.am1=i/(Math.sqrt(1-this.es*this.am1*this.am1)*this.am1),this.inverse=bP,this.forward=xP):(Math.abs(this.phi1)+Cu>=_t?this.cphi1=0:this.cphi1=1/Math.tan(this.phi1),this.inverse=SP,this.forward=IP)}function xP(i){var t=Lt(i.x-(this.long0||0),this.over),e=i.y,n,s,r;return n=this.am1+this.m1-gl(e,s=Math.sin(e),r=Math.cos(e),this.en),s=r*t/(n*Math.sqrt(1-this.es*s*s)),i.x=n*Math.sin(s),i.y=this.am1-n*Math.cos(s),i.x=this.a*i.x+(this.x0||0),i.y=this.a*i.y+(this.y0||0),i}function bP(i){i.x=(i.x-(this.x0||0))/this.a,i.y=(i.y-(this.y0||0))/this.a;var t,e,n,s;if(e=ri(i.x,i.y=this.am1-i.y),s=Um(this.am1+this.m1-e,this.es,this.en),(t=Math.abs(s))<_t)t=Math.sin(s),n=e*Math.atan2(i.x,i.y)*Math.sqrt(1-this.es*t*t)/Math.cos(s);else if(Math.abs(t-_t)<=Cu)n=0;else throw new Error;return i.x=Lt(n+(this.long0||0),this.over),i.y=Vr(s),i}function IP(i){var t=Lt(i.x-(this.long0||0),this.over),e=i.y,n,s;return s=this.cphi1+this.phi1-e,Math.abs(s)>Cu?(i.x=s*Math.sin(n=t*Math.cos(e)/s),i.y=this.cphi1-s*Math.cos(n)):i.x=i.y=0,i.x=this.a*i.x+(this.x0||0),i.y=this.a*i.y+(this.y0||0),i}function SP(i){i.x=(i.x-(this.x0||0))/this.a,i.y=(i.y-(this.y0||0))/this.a;var t,e,n=ri(i.x,i.y=this.cphi1-i.y);if(e=this.cphi1+this.phi1-n,Math.abs(e)>_t)throw new Error;return Math.abs(Math.abs(e)-_t)<=Cu?t=0:t=n*Math.atan2(i.x,i.y)/Math.cos(e),i.x=Lt(t+(this.long0||0),this.over),i.y=Vr(e),i}var MP=["bonne","Bonne (Werner lat_1=90)"];const NP={init:wP,names:MP},i1={OBLIQUE:{forward:TP,inverse:AP},TRANSVERSE:{forward:RP,inverse:OP}},Wh={ROTATE:{o_alpha:"oAlpha",o_lon_c:"oLongC",o_lat_c:"oLatC"},NEW_POLE:{o_lat_p:"oLatP",o_lon_p:"oLongP"},NEW_EQUATOR:{o_lon_1:"oLong1",o_lat_1:"oLat1",o_lon_2:"oLong2",o_lat_2:"oLat2"}};function LP(){if(this.x0=this.x0||0,this.y0=this.y0||0,this.long0=this.long0||0,this.title=this.title||"General Oblique Transformation",this.isIdentity=Zv.includes(this.o_proj),!this.o_proj)throw new Error("Missing parameter: o_proj");if(this.o_proj==="ob_tran")throw new Error("Invalid value for o_proj: "+this.o_proj);const i=this.projStr.replace("+proj=ob_tran","").replace("+o_proj=","+proj=").trim(),t=Ji(i);if(!t)throw new Error("Invalid parameter: o_proj. Unknown projection "+this.o_proj);t.long0=0,this.obliqueProjection=t;let e;const n=Object.keys(Wh),s=a=>{if(typeof this[a]>"u")return;const l=parseFloat(this[a])*We;if(isNaN(l))throw new Error("Invalid value for "+a+": "+this[a]);return l};for(let a=0;a<n.length;a++){const l=n[a],h=Wh[l],f=Object.entries(h);if(f.some(([p])=>typeof this[p]<"u")){e=h;for(let p=0;p<f.length;p++){const[y,_]=f[p],E=s(y);if(typeof E>"u")throw new Error("Missing parameter: "+y+".");this[_]=E}break}}if(!e)throw new Error("No valid parameters provided for ob_tran projection.");const{lamp:r,phip:o}=kP(this,e);this.lamp=r,Math.abs(o)>Mt?(this.cphip=Math.cos(o),this.sphip=Math.sin(o),this.projectionType=i1.OBLIQUE):this.projectionType=i1.TRANSVERSE}function CP(i){return this.projectionType.forward(this,i)}function PP(i){return this.projectionType.inverse(this,i)}function kP(i,t){let e,n;if(t===Wh.ROTATE){let s=i.oLongC,r=i.oLatC,o=i.oAlpha;if(Math.abs(Math.abs(r)-_t)<=Mt)throw new Error("Invalid value for o_lat_c: "+i.o_lat_c+" should be < 90°");n=s+Math.atan2(-1*Math.cos(o),-1*Math.sin(o)*Math.sin(r)),e=Math.asin(Math.cos(r)*Math.sin(o))}else if(t===Wh.NEW_POLE)n=i.oLongP,e=i.oLatP;else{let s=i.oLong1,r=i.oLat1,o=i.oLong2,a=i.oLat2,l=Math.abs(r);if(Math.abs(r)>_t-Mt)throw new Error("Invalid value for o_lat_1: "+i.o_lat_1+" should be < 90°");if(Math.abs(a)>_t-Mt)throw new Error("Invalid value for o_lat_2: "+i.o_lat_2+" should be < 90°");if(Math.abs(r-a)<Mt)throw new Error("Invalid value for o_lat_1 and o_lat_2: o_lat_1 should be different from o_lat_2");if(l<Mt)throw new Error("Invalid value for o_lat_1: o_lat_1 should be different from zero");n=Math.atan2(Math.cos(r)*Math.sin(a)*Math.cos(s)-Math.sin(r)*Math.cos(a)*Math.cos(o),Math.sin(r)*Math.cos(a)*Math.sin(o)-Math.cos(r)*Math.sin(a)*Math.sin(s)),e=Math.atan(-1*Math.cos(n-s)/Math.tan(r))}return{lamp:n,phip:e}}function TP(i,t){let{x:e,y:n}=t;e=Lt(e-i.long0,i.over);const s=Math.cos(e),r=Math.sin(n),o=Math.cos(n);t.x=Lt(Math.atan2(o*Math.sin(e),i.sphip*o*s+i.cphip*r)+i.lamp),t.y=Math.asin(i.sphip*r-i.cphip*o*s);const a=i.obliqueProjection.forward(t);return i.isIdentity&&(a.x*=ai,a.y*=ai),a}function RP(i,t){let{x:e,y:n}=t;e=Lt(e-i.long0,i.over);const s=Math.cos(n),r=Math.cos(e);t.x=Lt(Math.atan2(s*Math.sin(e),Math.sin(n))+i.lamp),t.y=Math.asin(-1*s*r);const o=i.obliqueProjection.forward(t);return i.isIdentity&&(o.x*=ai,o.y*=ai),o}function AP(i,t){i.isIdentity&&(t.x*=We,t.y*=We);const e=i.obliqueProjection.inverse(t);let{x:n,y:s}=e;if(n<Number.MAX_VALUE){n-=i.lamp;const r=Math.cos(n),o=Math.sin(s),a=Math.cos(s);t.x=Math.atan2(a*Math.sin(n),i.sphip*a*r-i.cphip*o),t.y=Math.asin(i.sphip*o+i.cphip*a*r)}return t.x=Lt(t.x+i.long0),t}function OP(i,t){i.isIdentity&&(t.x*=We,t.y*=We);const e=i.obliqueProjection.inverse(t);let{x:n,y:s}=e;if(n<Number.MAX_VALUE){const r=Math.cos(s);n-=i.lamp,t.x=Math.atan2(r*Math.sin(n),-1*Math.sin(s)),t.y=Math.asin(r*Math.cos(n))}return t.x=Lt(t.x+i.long0),t}var FP=["General Oblique Transformation","General_Oblique_Transformation","ob_tran"];const $P={init:LP,forward:CP,inverse:PP,names:FP};function DP(i){i.Proj.projections.add(vh),i.Proj.projections.add(Eh),i.Proj.projections.add(IN),i.Proj.projections.add(RN),i.Proj.projections.add(DN),i.Proj.projections.add(UN),i.Proj.projections.add(WN),i.Proj.projections.add(tL),i.Proj.projections.add(rL),i.Proj.projections.add(cL),i.Proj.projections.add(wL),i.Proj.projections.add(NL),i.Proj.projections.add(TL),i.Proj.projections.add(DL),i.Proj.projections.add(UL),i.Proj.projections.add(HL),i.Proj.projections.add(tC),i.Proj.projections.add(rC),i.Proj.projections.add(uC),i.Proj.projections.add(gC),i.Proj.projections.add(vC),i.Proj.projections.add(IC),i.Proj.projections.add(CC),i.Proj.projections.add(FC),i.Proj.projections.add(qC),i.Proj.projections.add(jC),i.Proj.projections.add(tP),i.Proj.projections.add(rP),i.Proj.projections.add(cP),i.Proj.projections.add(mP),i.Proj.projections.add(EP),i.Proj.projections.add(NP),i.Proj.projections.add($P)}const Hr=Object.assign(qM,{defaultDatum:"WGS84",Proj:Ji,WGS84:new Ji("WGS84"),Point:Ha,toPoint:Bm,defs:bn,nadgrid:EM,transform:BM,mgrs:zM,version:"__VERSION__"});DP(Hr);const s1=1e-4,GP=512,lo=new Map;function BP(i){let t=lo.get(i);return t?(lo.delete(i),lo.set(i,t),t):(t=Hr("EPSG:4326",i),lo.set(i,t),lo.size>GP&&lo.delete(lo.keys().next().value),t)}function r1(i){return Number((Math.round(i/s1)*s1).toFixed(6))}function _E(i,t){if(typeof i[0]=="number"){const e=t(i);return i.length>2?[e[0],e[1],...i.slice(2)]:e}return i.map(e=>_E(e,t))}function xh(i,t){return i.type==="GeometryCollection"?{...i,geometries:i.geometries.map(e=>xh(e,t))}:{...i,coordinates:_E(i.coordinates,t)}}class we{constructor(t){Y(this,"definition");Y(this,"converter");this.definition=t,this.converter=BP(t)}static utmZoneFor(t){const e=((t+180)%360+360)%360-180;return Math.min(60,Math.max(1,Math.floor((e+180)/6)+1))}static utm(t,e=!1){return new we(`+proj=utm +zone=${t} ${e?"+south ":""}+datum=WGS84 +units=m +no_defs`)}static forCoordinate(t){const e=r1(t[0]),n=r1(t[1]);return new we(`+proj=tmerc +lat_0=${n} +lon_0=${e} +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs`)}static forBBox(t){return we.forCoordinate([(t[0]+t[2])/2,(t[1]+t[3])/2])}static forGeometries(t){let e=1/0,n=1/0,s=-1/0,r=-1/0;const o=a=>(a[0]<e&&(e=a[0]),a[1]<n&&(n=a[1]),a[0]>s&&(s=a[0]),a[1]>r&&(r=a[1]),a);return t.forEach(a=>xh(a,o)),Number.isFinite(e)?we.forBBox([e,n,s,r]):we.forCoordinate([0,0])}toPlanar(t){const e=this.converter.forward([t[0],t[1]]);return[e[0],e[1]]}toGeographic(t){const e=this.converter.inverse([t[0],t[1]]);return[e[0],e[1]]}projectGeometry(t){return xh(t,e=>this.toPlanar(e))}unprojectGeometry(t){return xh(t,e=>this.toGeographic(e))}distance(t,e){const n=this.toPlanar(t),s=this.toPlanar(e);return Math.hypot(s[0]-n[0],s[1]-n[1])}}const zc=new Set,qP=500,vE=(i,t)=>{const e=t instanceof Error?t.message:String(t),n=`${i}::${e}`;zc.has(n)||(zc.size>=qP&&zc.clear(),zc.add(n),console.warn(`[OFSObject] ${i}: ${e}`,t))};let EE=vE;function zP(i){EE=i??vE}function Qt(i,t){try{EE(i,t)}catch{}}function wE(i,t,e=0,n=i.length-1,s=UP){for(;n>e;){if(n-e>600){const l=n-e+1,h=t-e+1,f=Math.log(l),d=.5*Math.exp(2*f/3),p=.5*Math.sqrt(f*d*(l-d)/l)*(h-l/2<0?-1:1),y=Math.max(e,Math.floor(t-h*d/l+p)),_=Math.min(n,Math.floor(t+(l-h)*d/l+p));wE(i,t,y,_,s)}const r=i[t];let o=e,a=n;for(Ul(i,e,t),s(i[n],r)>0&&Ul(i,e,n);o<a;){for(Ul(i,o,a),o++,a--;s(i[o],r)<0;)o++;for(;s(i[a],r)>0;)a--}s(i[e],r)===0?Ul(i,e,a):(a++,Ul(i,a,n)),a<=t&&(e=a+1),t<=a&&(n=a-1)}}function Ul(i,t,e){const n=i[t];i[t]=i[e],i[e]=n}function UP(i,t){return i<t?-1:i>t?1:0}let ha=class{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(t){let e=this.data;const n=[];if(!Yc(t,e))return n;const s=this.toBBox,r=[];for(;e;){for(let o=0;o<e.children.length;o++){const a=e.children[o],l=e.leaf?s(a):a;Yc(t,l)&&(e.leaf?n.push(a):jd(t,l)?this._all(a,n):r.push(a))}e=r.pop()}return n}collides(t){let e=this.data;if(!Yc(t,e))return!1;const n=[];for(;e;){for(let s=0;s<e.children.length;s++){const r=e.children[s],o=e.leaf?this.toBBox(r):r;if(Yc(t,o)){if(e.leaf||jd(t,o))return!0;n.push(r)}}e=n.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let n=0;n<t.length;n++)this.insert(t[n]);return this}let e=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=e;else if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){const n=this.data;this.data=e,e=n}this._insert(e,this.data.height-e.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=fa([]),this}remove(t,e){if(!t)return this;let n=this.data;const s=this.toBBox(t),r=[],o=[];let a,l,h;for(;n||r.length;){if(n||(n=r.pop(),l=r[r.length-1],a=o.pop(),h=!0),n.leaf){const f=YP(t,n.children,e);if(f!==-1)return n.children.splice(f,1),r.push(n),this._condense(r),this}!h&&!n.leaf&&jd(n,s)?(r.push(n),o.push(a),a=0,l=n,n=n.children[0]):l?(a++,n=l.children[a],h=!1):n=null}return this}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,e){const n=[];for(;t;)t.leaf?e.push(...t.children):n.push(...t.children),t=n.pop();return e}_build(t,e,n,s){const r=n-e+1;let o=this._maxEntries,a;if(r<=o)return a=fa(t.slice(e,n+1)),Jo(a,this.toBBox),a;s||(s=Math.ceil(Math.log(r)/Math.log(o)),o=Math.ceil(r/Math.pow(o,s-1))),a=fa([]),a.leaf=!1,a.height=s;const l=Math.ceil(r/o),h=l*Math.ceil(Math.sqrt(o));o1(t,e,n,h,this.compareMinX);for(let f=e;f<=n;f+=h){const d=Math.min(f+h-1,n);o1(t,f,d,l,this.compareMinY);for(let p=f;p<=d;p+=l){const y=Math.min(p+l-1,d);a.children.push(this._build(t,p,y,s-1))}}return Jo(a,this.toBBox),a}_chooseSubtree(t,e,n,s){for(;s.push(e),!(e.leaf||s.length-1===n);){let r=1/0,o=1/0,a;for(let l=0;l<e.children.length;l++){const h=e.children[l],f=Xd(h),d=VP(t,h)-f;d<o?(o=d,r=f<r?f:r,a=h):d===o&&f<r&&(r=f,a=h)}e=a||e.children[0]}return e}_insert(t,e,n){const s=n?t:this.toBBox(t),r=[],o=this._chooseSubtree(s,this.data,e,r);for(o.children.push(t),su(o,s);e>=0&&r[e].children.length>this._maxEntries;)this._split(r,e),e--;this._adjustParentBBoxes(s,r,e)}_split(t,e){const n=t[e],s=n.children.length,r=this._minEntries;this._chooseSplitAxis(n,r,s);const o=this._chooseSplitIndex(n,r,s),a=fa(n.children.splice(o,n.children.length-o));a.height=n.height,a.leaf=n.leaf,Jo(n,this.toBBox),Jo(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(n,a)}_splitRoot(t,e){this.data=fa([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Jo(this.data,this.toBBox)}_chooseSplitIndex(t,e,n){let s,r=1/0,o=1/0;for(let a=e;a<=n-e;a++){const l=iu(t,0,a,this.toBBox),h=iu(t,a,n,this.toBBox),f=HP(l,h),d=Xd(l)+Xd(h);f<r?(r=f,s=a,o=d<o?d:o):f===r&&d<o&&(o=d,s=a)}return s||n-e}_chooseSplitAxis(t,e,n){const s=t.leaf?this.compareMinX:XP,r=t.leaf?this.compareMinY:jP,o=this._allDistMargin(t,e,n,s),a=this._allDistMargin(t,e,n,r);o<a&&t.children.sort(s)}_allDistMargin(t,e,n,s){t.children.sort(s);const r=this.toBBox,o=iu(t,0,e,r),a=iu(t,n-e,n,r);let l=Uc(o)+Uc(a);for(let h=e;h<n-e;h++){const f=t.children[h];su(o,t.leaf?r(f):f),l+=Uc(o)}for(let h=n-e-1;h>=e;h--){const f=t.children[h];su(a,t.leaf?r(f):f),l+=Uc(a)}return l}_adjustParentBBoxes(t,e,n){for(let s=n;s>=0;s--)su(e[s],t)}_condense(t){for(let e=t.length-1,n;e>=0;e--)t[e].children.length===0?e>0?(n=t[e-1].children,n.splice(n.indexOf(t[e]),1)):this.clear():Jo(t[e],this.toBBox)}};function YP(i,t,e){if(!e)return t.indexOf(i);for(let n=0;n<t.length;n++)if(e(i,t[n]))return n;return-1}function Jo(i,t){iu(i,0,i.children.length,t,i)}function iu(i,t,e,n,s){s||(s=fa(null)),s.minX=1/0,s.minY=1/0,s.maxX=-1/0,s.maxY=-1/0;for(let r=t;r<e;r++){const o=i.children[r];su(s,i.leaf?n(o):o)}return s}function su(i,t){return i.minX=Math.min(i.minX,t.minX),i.minY=Math.min(i.minY,t.minY),i.maxX=Math.max(i.maxX,t.maxX),i.maxY=Math.max(i.maxY,t.maxY),i}function XP(i,t){return i.minX-t.minX}function jP(i,t){return i.minY-t.minY}function Xd(i){return(i.maxX-i.minX)*(i.maxY-i.minY)}function Uc(i){return i.maxX-i.minX+(i.maxY-i.minY)}function VP(i,t){return(Math.max(t.maxX,i.maxX)-Math.min(t.minX,i.minX))*(Math.max(t.maxY,i.maxY)-Math.min(t.minY,i.minY))}function HP(i,t){const e=Math.max(i.minX,t.minX),n=Math.max(i.minY,t.minY),s=Math.min(i.maxX,t.maxX),r=Math.min(i.maxY,t.maxY);return Math.max(0,s-e)*Math.max(0,r-n)}function jd(i,t){return i.minX<=t.minX&&i.minY<=t.minY&&t.maxX<=i.maxX&&t.maxY<=i.maxY}function Yc(i,t){return t.minX<=i.maxX&&t.minY<=i.maxY&&t.maxX>=i.minX&&t.maxY>=i.minY}function fa(i){return{children:i,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function o1(i,t,e,n,s){const r=[t,e];for(;r.length;){if(e=r.pop(),t=r.pop(),e-t<=n)continue;const o=t+Math.ceil((e-t)/n/2)*n;wE(i,o,t,e,s),r.push(t,o,o,e)}}var Oe=63710088e-1,xE={centimeters:Oe*100,centimetres:Oe*100,cm:Oe*100,degrees:360/(2*Math.PI),deg:360/(2*Math.PI),feet:Oe*3.28084,ft:Oe*3.28084,inches:Oe*39.37,in:Oe*39.37,kilometers:Oe/1e3,kilometres:Oe/1e3,km:Oe/1e3,meters:Oe,metres:Oe,m:Oe,miles:Oe/1609.344,mi:Oe/1609.344,millimeters:Oe*1e3,millimetres:Oe*1e3,mm:Oe*1e3,nauticalmiles:Oe/1852,nmi:Oe/1852,radians:1,rad:1,yards:Oe*1.0936,yd:Oe*1.0936};function vn(i,t,e={}){const n={type:"Feature"};return(e.id===0||e.id)&&(n.id=e.id),e.bbox&&(n.bbox=e.bbox),n.properties=t||{},n.geometry=i,n}function St(i,t,e={}){if(!i)throw new Error("coordinates is required");if(!Array.isArray(i))throw new Error("coordinates must be an Array");if(i.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!a1(i[0])||!a1(i[1]))throw new Error("coordinates must contain numbers");return vn({type:"Point",coordinates:i},t,e)}function Ce(i,t,e={}){for(const s of i){if(s.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(s[s.length-1].length!==s[0].length)throw new Error("First and last Position are not equivalent.");for(let r=0;r<s[s.length-1].length;r++)if(s[s.length-1][r]!==s[0][r])throw new Error("First and last Position are not equivalent.")}return vn({type:"Polygon",coordinates:i},t,e)}function re(i,t,e={}){if(i.length<2)throw new Error("coordinates must be an array of two or more positions");return vn({type:"LineString",coordinates:i},t,e)}function ae(i,t={}){const e={type:"FeatureCollection"};return t.id&&(e.id=t.id),t.bbox&&(e.bbox=t.bbox),e.features=i,e}function bE(i,t,e={}){return vn({type:"MultiLineString",coordinates:i},t,e)}function IE(i,t,e={}){return vn({type:"MultiPoint",coordinates:i},t,e)}function bo(i,t,e={}){return vn({type:"MultiPolygon",coordinates:i},t,e)}function SE(i,t="kilometers"){const e=xE[t];if(!e)throw new Error(t+" units is invalid");return i*e}function ME(i,t="kilometers"){const e=xE[t];if(!e)throw new Error(t+" units is invalid");return i/e}function Pu(i){return i%(2*Math.PI)*180/Math.PI}function Ni(i){return i%360*Math.PI/180}function a1(i){return!isNaN(i)&&i!==null&&!Array.isArray(i)}function NE(i){return i!==null&&typeof i=="object"&&!Array.isArray(i)}function li(i){if(!i)throw new Error("coord is required");if(!Array.isArray(i)){if(i.type==="Feature"&&i.geometry!==null&&i.geometry.type==="Point")return[...i.geometry.coordinates];if(i.type==="Point")return[...i.coordinates]}if(Array.isArray(i)&&i.length>=2&&!Array.isArray(i[0])&&!Array.isArray(i[1]))return[...i];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function ws(i){if(Array.isArray(i))return i;if(i.type==="Feature"){if(i.geometry!==null)return i.geometry.coordinates}else if(i.coordinates)return i.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function WP(i,t,e){if(!i)throw new Error("No feature passed");if(!i||i.type!=="Feature"||!i.geometry)throw new Error("Invalid input to "+e+", Feature with geometry required");if(!i.geometry||i.geometry.type!==t)throw new Error("Invalid input to "+e+": must be a "+t+", given "+i.geometry.type)}function Jn(i){return i.type==="Feature"?i.geometry:i}function Kh(i,t){return i.type==="FeatureCollection"?"FeatureCollection":i.type==="GeometryCollection"?"GeometryCollection":i.type==="Feature"&&i.geometry!==null?i.geometry.type:i.type}function Wa(i,t,e={}){if(e.final===!0)return KP(i,t);const n=li(i),s=li(t),r=Ni(n[0]),o=Ni(s[0]),a=Ni(n[1]),l=Ni(s[1]),h=Math.sin(o-r)*Math.cos(l),f=Math.cos(a)*Math.sin(l)-Math.sin(a)*Math.cos(l)*Math.cos(o-r);return Pu(Math.atan2(h,f))}function KP(i,t){let e=Wa(t,i);return e=(e+180)%360,e>180?e-360:e}function ku(i,t,e,n={}){const s=li(i),r=Ni(s[0]),o=Ni(s[1]),a=Ni(e),l=ME(t,n.units),h=Math.asin(Math.sin(o)*Math.cos(l)+Math.cos(o)*Math.sin(l)*Math.cos(a)),f=r+Math.atan2(Math.sin(a)*Math.sin(l)*Math.cos(o),Math.cos(l)-Math.sin(o)*Math.sin(h)),d=Pu(f),p=Pu(h);return s[2]!==void 0?St([d,p,s[2]],n.properties):St([d,p],n.properties)}function nn(i,t,e={}){var n=li(i),s=li(t),r=Ni(s[1]-n[1]),o=Ni(s[0]-n[0]),a=Ni(n[1]),l=Ni(s[1]),h=Math.pow(Math.sin(r/2),2)+Math.pow(Math.sin(o/2),2)*Math.cos(a)*Math.cos(l);return SE(2*Math.atan2(Math.sqrt(h),Math.sqrt(1-h)),e.units)}function ZP(i,t,e={}){const s=Jn(i).coordinates;let r=0;for(let o=0;o<s.length&&!(t>=r&&o===s.length-1);o++)if(r>=t){const a=t-r;if(a){const l=Wa(s[o],s[o-1])-180;return ku(s[o],a,l,e)}else return St(s[o])}else r+=nn(s[o],s[o+1],e);return St(s[s.length-1])}function Mn(i,t,e){if(i!==null)for(var n,s,r,o,a,l,h,f=0,d=0,p,y=i.type,_=y==="FeatureCollection",E=y==="Feature",w=_?i.features.length:1,L=0;L<w;L++){h=_?i.features[L].geometry:E?i.geometry:i,p=h?h.type==="GeometryCollection":!1,a=p?h.geometries.length:1;for(var b=0;b<a;b++){var P=0,N=0;if(o=p?h.geometries[b]:h,o!==null){l=o.coordinates;var S=o.type;switch(f=e&&(S==="Polygon"||S==="MultiPolygon")?1:0,S){case null:break;case"Point":if(t(l,d,L,P,N)===!1)return!1;d++,P++;break;case"LineString":case"MultiPoint":for(n=0;n<l.length;n++){if(t(l[n],d,L,P,N)===!1)return!1;d++,S==="MultiPoint"&&P++}S==="LineString"&&P++;break;case"Polygon":case"MultiLineString":for(n=0;n<l.length;n++){for(s=0;s<l[n].length-f;s++){if(t(l[n][s],d,L,P,N)===!1)return!1;d++}S==="MultiLineString"&&P++,S==="Polygon"&&N++}S==="Polygon"&&P++;break;case"MultiPolygon":for(n=0;n<l.length;n++){for(N=0,s=0;s<l[n].length;s++){for(r=0;r<l[n][s].length-f;r++){if(t(l[n][s][r],d,L,P,N)===!1)return!1;d++}N++}P++}break;case"GeometryCollection":for(n=0;n<o.geometries.length;n++)if(Mn(o.geometries[n],t,e)===!1)return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function JP(i,t,e,n){var s=e;return Mn(i,function(r,o,a,l,h){o===0&&e===void 0?s=r:s=t(s,r,o,a,l,h)},n),s}function qr(i,t){if(i.type==="Feature")t(i,0);else if(i.type==="FeatureCollection")for(var e=0;e<i.features.length&&t(i.features[e],e)!==!1;e++);}function QP(i,t,e){var n=e;return qr(i,function(s,r){r===0&&e===void 0?n=s:n=t(n,s,r)}),n}function tk(i){var t=[];return Mn(i,function(e){t.push(e)}),t}function Wr(i,t){var e,n,s,r,o,a,l,h,f,d,p=0,y=i.type==="FeatureCollection",_=i.type==="Feature",E=y?i.features.length:1;for(e=0;e<E;e++){for(a=y?i.features[e].geometry:_?i.geometry:i,h=y?i.features[e].properties:_?i.properties:{},f=y?i.features[e].bbox:_?i.bbox:void 0,d=y?i.features[e].id:_?i.id:void 0,l=a?a.type==="GeometryCollection":!1,o=l?a.geometries.length:1,s=0;s<o;s++){if(r=l?a.geometries[s]:a,r===null){if(t(null,p,h,f,d)===!1)return!1;continue}switch(r.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":{if(t(r,p,h,f,d)===!1)return!1;break}case"GeometryCollection":{for(n=0;n<r.geometries.length;n++)if(t(r.geometries[n],p,h,f,d)===!1)return!1;break}default:throw new Error("Unknown Geometry Type")}}p++}}function ek(i,t,e){var n=e;return Wr(i,function(s,r,o,a,l){n=t(n,s,r,o,a,l)}),n}function zr(i,t){Wr(i,function(e,n,s,r,o){var a=e===null?null:e.type;switch(a){case null:case"Point":case"LineString":case"Polygon":return t(vn(e,s,{bbox:r,id:o}),n,0)===!1?!1:void 0}var l;switch(a){case"MultiPoint":l="Point";break;case"MultiLineString":l="LineString";break;case"MultiPolygon":l="Polygon";break}for(var h=0;h<e.coordinates.length;h++){var f=e.coordinates[h],d={type:l,coordinates:f};if(t(vn(d,s),n,h)===!1)return!1}})}function nk(i,t){zr(i,function(e,n,s){var r=0;if(e.geometry){var o=e.geometry.type;if(!(o==="Point"||o==="MultiPoint")){var a,l=0,h=0,f=0;if(Mn(e,function(d,p,y,_,E){if(a===void 0||n>l||_>h||E>f){a=d,l=n,h=_,f=E,r=0;return}var w=re([a,d],e.properties);if(t(w,n,s,E,r)===!1)return!1;r++,a=d})===!1)return!1}}})}function ik(i,t,e){var n=e,s=!1;return nk(i,function(r,o,a,l,h){s===!1&&e===void 0?n=r:n=t(n,r,o,a,l,h),s=!0}),n}function Tu(i){return ek(i,(t,e)=>t+sk(e),0)}function sk(i){let t=0,e;switch(i.type){case"Polygon":return l1(i.coordinates);case"MultiPolygon":for(e=0;e<i.coordinates.length;e++)t+=l1(i.coordinates[e]);return t;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}function l1(i){let t=0;if(i&&i.length>0){t+=Math.abs(u1(i[0]));for(let e=1;e<i.length;e++)t-=Math.abs(u1(i[e]))}return t}var rk=Oe*Oe/2,Vd=Math.PI/180;function u1(i){const t=i.length-1;if(t<=2)return 0;let e=0,n=0;for(;n<t;){const s=i[n],r=i[n+1===t?0:n+1],o=i[n+2>=t?(n+2)%t:n+2],a=s[0]*Vd,l=r[1]*Vd,h=o[0]*Vd;e+=(h-a)*Math.sin(l),n++}return e*rk}function De(i,t={}){if(i.bbox!=null&&t.recompute!==!0)return i.bbox;const e=[1/0,1/0,-1/0,-1/0];return Mn(i,n=>{e[0]>n[0]&&(e[0]=n[0]),e[1]>n[1]&&(e[1]=n[1]),e[2]<n[0]&&(e[2]=n[0]),e[3]<n[1]&&(e[3]=n[1])}),e}function Wm(i,t={}){const e=Number(i[0]),n=Number(i[1]),s=Number(i[2]),r=Number(i[3]);if(i.length===6)throw new Error("@turf/bbox-polygon does not support BBox with 6 positions");const o=[e,n];return Ce([[o,[s,n],[s,r],[e,r],o]],t.properties,{bbox:i,id:t.id})}const fr=11102230246251565e-32,kn=134217729,ok=(3+8*fr)*fr;function Hd(i,t,e,n,s){let r,o,a,l,h=t[0],f=n[0],d=0,p=0;f>h==f>-h?(r=h,h=t[++d]):(r=f,f=n[++p]);let y=0;if(d<i&&p<e)for(f>h==f>-h?(o=h+r,a=r-(o-h),h=t[++d]):(o=f+r,a=r-(o-f),f=n[++p]),r=o,a!==0&&(s[y++]=a);d<i&&p<e;)f>h==f>-h?(o=r+h,l=o-r,a=r-(o-l)+(h-l),h=t[++d]):(o=r+f,l=o-r,a=r-(o-l)+(f-l),f=n[++p]),r=o,a!==0&&(s[y++]=a);for(;d<i;)o=r+h,l=o-r,a=r-(o-l)+(h-l),h=t[++d],r=o,a!==0&&(s[y++]=a);for(;p<e;)o=r+f,l=o-r,a=r-(o-l)+(f-l),f=n[++p],r=o,a!==0&&(s[y++]=a);return(r!==0||y===0)&&(s[y++]=r),y}function ak(i,t){let e=t[0];for(let n=1;n<i;n++)e+=t[n];return e}function gc(i){return new Float64Array(i)}const lk=(3+16*fr)*fr,uk=(2+12*fr)*fr,ck=(9+64*fr)*fr*fr,Qo=gc(4),c1=gc(8),h1=gc(12),f1=gc(16),Bn=gc(4);function hk(i,t,e,n,s,r,o){let a,l,h,f,d,p,y,_,E,w,L,b,P,N,S,C,T,I;const M=i-s,R=e-s,A=t-r,F=n-r;N=M*F,p=kn*M,y=p-(p-M),_=M-y,p=kn*F,E=p-(p-F),w=F-E,S=_*w-(N-y*E-_*E-y*w),C=A*R,p=kn*A,y=p-(p-A),_=A-y,p=kn*R,E=p-(p-R),w=R-E,T=_*w-(C-y*E-_*E-y*w),L=S-T,d=S-L,Qo[0]=S-(L+d)+(d-T),b=N+L,d=b-N,P=N-(b-d)+(L-d),L=P-C,d=P-L,Qo[1]=P-(L+d)+(d-C),I=b+L,d=I-b,Qo[2]=b-(I-d)+(L-d),Qo[3]=I;let $=ak(4,Qo),z=uk*o;if($>=z||-$>=z||(d=i-M,a=i-(M+d)+(d-s),d=e-R,h=e-(R+d)+(d-s),d=t-A,l=t-(A+d)+(d-r),d=n-F,f=n-(F+d)+(d-r),a===0&&l===0&&h===0&&f===0)||(z=ck*o+ok*Math.abs($),$+=M*f+F*a-(A*h+R*l),$>=z||-$>=z))return $;N=a*F,p=kn*a,y=p-(p-a),_=a-y,p=kn*F,E=p-(p-F),w=F-E,S=_*w-(N-y*E-_*E-y*w),C=l*R,p=kn*l,y=p-(p-l),_=l-y,p=kn*R,E=p-(p-R),w=R-E,T=_*w-(C-y*E-_*E-y*w),L=S-T,d=S-L,Bn[0]=S-(L+d)+(d-T),b=N+L,d=b-N,P=N-(b-d)+(L-d),L=P-C,d=P-L,Bn[1]=P-(L+d)+(d-C),I=b+L,d=I-b,Bn[2]=b-(I-d)+(L-d),Bn[3]=I;const D=Hd(4,Qo,4,Bn,c1);N=M*f,p=kn*M,y=p-(p-M),_=M-y,p=kn*f,E=p-(p-f),w=f-E,S=_*w-(N-y*E-_*E-y*w),C=A*h,p=kn*A,y=p-(p-A),_=A-y,p=kn*h,E=p-(p-h),w=h-E,T=_*w-(C-y*E-_*E-y*w),L=S-T,d=S-L,Bn[0]=S-(L+d)+(d-T),b=N+L,d=b-N,P=N-(b-d)+(L-d),L=P-C,d=P-L,Bn[1]=P-(L+d)+(d-C),I=b+L,d=I-b,Bn[2]=b-(I-d)+(L-d),Bn[3]=I;const B=Hd(D,c1,4,Bn,h1);N=a*f,p=kn*a,y=p-(p-a),_=a-y,p=kn*f,E=p-(p-f),w=f-E,S=_*w-(N-y*E-_*E-y*w),C=l*h,p=kn*l,y=p-(p-l),_=l-y,p=kn*h,E=p-(p-h),w=h-E,T=_*w-(C-y*E-_*E-y*w),L=S-T,d=S-L,Bn[0]=S-(L+d)+(d-T),b=N+L,d=b-N,P=N-(b-d)+(L-d),L=P-C,d=P-L,Bn[1]=P-(L+d)+(d-C),I=b+L,d=I-b,Bn[2]=b-(I-d)+(L-d),Bn[3]=I;const U=Hd(B,h1,4,Bn,f1);return f1[U-1]}function fk(i,t,e,n,s,r){const o=(t-r)*(e-s),a=(i-s)*(n-r),l=o-a,h=Math.abs(o+a);return Math.abs(l)>=lk*h?l:-hk(i,t,e,n,s,r,h)}function dk(i,t){var e,n,s=0,r,o,a,l,h,f,d,p=i[0],y=i[1],_=t.length;for(e=0;e<_;e++){n=0;var E=t[e],w=E.length-1;if(f=E[0],f[0]!==E[w][0]&&f[1]!==E[w][1])throw new Error("First and last coordinates in a ring must be the same");for(o=f[0]-p,a=f[1]-y,n;n<w;n++){if(d=E[n+1],l=d[0]-p,h=d[1]-y,a===0&&h===0){if(l<=0&&o>=0||o<=0&&l>=0)return 0}else if(h>=0&&a<=0||h<=0&&a>=0){if(r=fk(o,l,a,h,0,0),r===0)return 0;(r>0&&h>0&&a<=0||r<0&&h<=0&&a>0)&&s++}f=d,a=h,o=l}}return s%2!==0}function Ht(i,t,e={}){if(!i)throw new Error("point is required");if(!t)throw new Error("polygon is required");const n=li(i),s=Jn(t),r=s.type,o=t.bbox;let a=s.coordinates;if(o&&gk(n,o)===!1)return!1;r==="Polygon"&&(a=[a]);for(var l=0;l<a.length;++l){const h=dk(n,a[l]);if(h===0&&!e.ignoreBoundary)return!0;if(h)return!0}return!1}function gk(i,t){return t[0]<=i[0]&&t[1]<=i[1]&&t[2]>=i[0]&&t[3]>=i[1]}var mk=Ht;function oe(i,t,e={}){const n=li(i),s=ws(t);for(let r=0;r<s.length-1;r++){let o=!1;if(e.ignoreEndVertices&&(r===0&&(o="start"),r===s.length-2&&(o="end"),r===0&&r+1===s.length-1&&(o="both")),pk(s[r],s[r+1],n,o,typeof e.epsilon>"u"?null:e.epsilon))return!0}return!1}function pk(i,t,e,n,s){const r=e[0],o=e[1],a=i[0],l=i[1],h=t[0],f=t[1],d=e[0]-a,p=e[1]-l,y=h-a,_=f-l,E=d*_-p*y;if(s!==null){if(Math.abs(E)>s)return!1}else if(E!==0)return!1;if(Math.abs(y)===Math.abs(_)&&Math.abs(y)===0)return n?!1:e[0]===i[0]&&e[1]===i[1];if(n){if(n==="start")return Math.abs(y)>=Math.abs(_)?y>0?a<r&&r<=h:h<=r&&r<a:_>0?l<o&&o<=f:f<=o&&o<l;if(n==="end")return Math.abs(y)>=Math.abs(_)?y>0?a<=r&&r<h:h<r&&r<=a:_>0?l<=o&&o<f:f<o&&o<=l;if(n==="both")return Math.abs(y)>=Math.abs(_)?y>0?a<r&&r<h:h<r&&r<a:_>0?l<o&&o<f:f<o&&o<l}else return Math.abs(y)>=Math.abs(_)?y>0?a<=r&&r<=h:h<=r&&r<=a:_>0?l<=o&&o<=f:f<=o&&o<=l;return!1}function yk(i,t,e,n,s){LE(i,t,e||0,n||i.length-1,s||_k)}function LE(i,t,e,n,s){for(;n>e;){if(n-e>600){var r=n-e+1,o=t-e+1,a=Math.log(r),l=.5*Math.exp(2*a/3),h=.5*Math.sqrt(a*l*(r-l)/r)*(o-r/2<0?-1:1),f=Math.max(e,Math.floor(t-o*l/r+h)),d=Math.min(n,Math.floor(t+(r-o)*l/r+h));LE(i,t,f,d,s)}var p=i[t],y=e,_=n;for(Yl(i,e,t),s(i[n],p)>0&&Yl(i,e,n);y<_;){for(Yl(i,y,_),y++,_--;s(i[y],p)<0;)y++;for(;s(i[_],p)>0;)_--}s(i[e],p)===0?Yl(i,e,_):(_++,Yl(i,_,n)),_<=t&&(e=_+1),t<=_&&(n=_-1)}}function Yl(i,t,e){var n=i[t];i[t]=i[e],i[e]=n}function _k(i,t){return i<t?-1:i>t?1:0}let vk=class{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(t){let e=this.data;const n=[];if(!jc(t,e))return n;const s=this.toBBox,r=[];for(;e;){for(let o=0;o<e.children.length;o++){const a=e.children[o],l=e.leaf?s(a):a;jc(t,l)&&(e.leaf?n.push(a):Kd(t,l)?this._all(a,n):r.push(a))}e=r.pop()}return n}collides(t){let e=this.data;if(!jc(t,e))return!1;const n=[];for(;e;){for(let s=0;s<e.children.length;s++){const r=e.children[s],o=e.leaf?this.toBBox(r):r;if(jc(t,o)){if(e.leaf||Kd(t,o))return!0;n.push(r)}}e=n.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let n=0;n<t.length;n++)this.insert(t[n]);return this}let e=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=e;else if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){const n=this.data;this.data=e,e=n}this._insert(e,this.data.height-e.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=da([]),this}remove(t,e){if(!t)return this;let n=this.data;const s=this.toBBox(t),r=[],o=[];let a,l,h;for(;n||r.length;){if(n||(n=r.pop(),l=r[r.length-1],a=o.pop(),h=!0),n.leaf){const f=Ek(t,n.children,e);if(f!==-1)return n.children.splice(f,1),r.push(n),this._condense(r),this}!h&&!n.leaf&&Kd(n,s)?(r.push(n),o.push(a),a=0,l=n,n=n.children[0]):l?(a++,n=l.children[a],h=!1):n=null}return this}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,e){const n=[];for(;t;)t.leaf?e.push(...t.children):n.push(...t.children),t=n.pop();return e}_build(t,e,n,s){const r=n-e+1;let o=this._maxEntries,a;if(r<=o)return a=da(t.slice(e,n+1)),ta(a,this.toBBox),a;s||(s=Math.ceil(Math.log(r)/Math.log(o)),o=Math.ceil(r/Math.pow(o,s-1))),a=da([]),a.leaf=!1,a.height=s;const l=Math.ceil(r/o),h=l*Math.ceil(Math.sqrt(o));d1(t,e,n,h,this.compareMinX);for(let f=e;f<=n;f+=h){const d=Math.min(f+h-1,n);d1(t,f,d,l,this.compareMinY);for(let p=f;p<=d;p+=l){const y=Math.min(p+l-1,d);a.children.push(this._build(t,p,y,s-1))}}return ta(a,this.toBBox),a}_chooseSubtree(t,e,n,s){for(;s.push(e),!(e.leaf||s.length-1===n);){let r=1/0,o=1/0,a;for(let l=0;l<e.children.length;l++){const h=e.children[l],f=Wd(h),d=bk(t,h)-f;d<o?(o=d,r=f<r?f:r,a=h):d===o&&f<r&&(r=f,a=h)}e=a||e.children[0]}return e}_insert(t,e,n){const s=n?t:this.toBBox(t),r=[],o=this._chooseSubtree(s,this.data,e,r);for(o.children.push(t),ou(o,s);e>=0&&r[e].children.length>this._maxEntries;)this._split(r,e),e--;this._adjustParentBBoxes(s,r,e)}_split(t,e){const n=t[e],s=n.children.length,r=this._minEntries;this._chooseSplitAxis(n,r,s);const o=this._chooseSplitIndex(n,r,s),a=da(n.children.splice(o,n.children.length-o));a.height=n.height,a.leaf=n.leaf,ta(n,this.toBBox),ta(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(n,a)}_splitRoot(t,e){this.data=da([t,e]),this.data.height=t.height+1,this.data.leaf=!1,ta(this.data,this.toBBox)}_chooseSplitIndex(t,e,n){let s,r=1/0,o=1/0;for(let a=e;a<=n-e;a++){const l=ru(t,0,a,this.toBBox),h=ru(t,a,n,this.toBBox),f=Ik(l,h),d=Wd(l)+Wd(h);f<r?(r=f,s=a,o=d<o?d:o):f===r&&d<o&&(o=d,s=a)}return s||n-e}_chooseSplitAxis(t,e,n){const s=t.leaf?this.compareMinX:wk,r=t.leaf?this.compareMinY:xk,o=this._allDistMargin(t,e,n,s),a=this._allDistMargin(t,e,n,r);o<a&&t.children.sort(s)}_allDistMargin(t,e,n,s){t.children.sort(s);const r=this.toBBox,o=ru(t,0,e,r),a=ru(t,n-e,n,r);let l=Xc(o)+Xc(a);for(let h=e;h<n-e;h++){const f=t.children[h];ou(o,t.leaf?r(f):f),l+=Xc(o)}for(let h=n-e-1;h>=e;h--){const f=t.children[h];ou(a,t.leaf?r(f):f),l+=Xc(a)}return l}_adjustParentBBoxes(t,e,n){for(let s=n;s>=0;s--)ou(e[s],t)}_condense(t){for(let e=t.length-1,n;e>=0;e--)t[e].children.length===0?e>0?(n=t[e-1].children,n.splice(n.indexOf(t[e]),1)):this.clear():ta(t[e],this.toBBox)}};function Ek(i,t,e){if(!e)return t.indexOf(i);for(let n=0;n<t.length;n++)if(e(i,t[n]))return n;return-1}function ta(i,t){ru(i,0,i.children.length,t,i)}function ru(i,t,e,n,s){s||(s=da(null)),s.minX=1/0,s.minY=1/0,s.maxX=-1/0,s.maxY=-1/0;for(let r=t;r<e;r++){const o=i.children[r];ou(s,i.leaf?n(o):o)}return s}function ou(i,t){return i.minX=Math.min(i.minX,t.minX),i.minY=Math.min(i.minY,t.minY),i.maxX=Math.max(i.maxX,t.maxX),i.maxY=Math.max(i.maxY,t.maxY),i}function wk(i,t){return i.minX-t.minX}function xk(i,t){return i.minY-t.minY}function Wd(i){return(i.maxX-i.minX)*(i.maxY-i.minY)}function Xc(i){return i.maxX-i.minX+(i.maxY-i.minY)}function bk(i,t){return(Math.max(t.maxX,i.maxX)-Math.min(t.minX,i.minX))*(Math.max(t.maxY,i.maxY)-Math.min(t.minY,i.minY))}function Ik(i,t){const e=Math.max(i.minX,t.minX),n=Math.max(i.minY,t.minY),s=Math.min(i.maxX,t.maxX),r=Math.min(i.maxY,t.maxY);return Math.max(0,s-e)*Math.max(0,r-n)}function Kd(i,t){return i.minX<=t.minX&&i.minY<=t.minY&&t.maxX<=i.maxX&&t.maxY<=i.maxY}function jc(i,t){return t.minX<=i.maxX&&t.minY<=i.maxY&&t.maxX>=i.minX&&t.maxY>=i.minY}function da(i){return{children:i,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function d1(i,t,e,n,s){const r=[t,e];for(;r.length;){if(e=r.pop(),t=r.pop(),e-t<=n)continue;const o=t+Math.ceil((e-t)/n/2)*n;yk(i,o,t,e,s),r.push(t,o,o,e)}}function Zd(i){var t;if(i.bbox)t=i.bbox;else if(Array.isArray(i)&&i.length===4)t=i;else if(Array.isArray(i)&&i.length===6)t=[i[0],i[1],i[3],i[4]];else if(i.type==="Feature")t=De(i);else if(i.type==="FeatureCollection")t=De(i);else throw new Error("invalid geojson");return{minX:t[0],minY:t[1],maxX:t[2],maxY:t[3]}}var Sk=class{constructor(i=9){this.tree=new vk(i),this.tree.toBBox=Zd}insert(i){if(i.type!=="Feature")throw new Error("invalid feature");return i.bbox=i.bbox?i.bbox:De(i),this.tree.insert(i),this}load(i){var t=[];return Array.isArray(i)?i.forEach(function(e){if(e.type!=="Feature")throw new Error("invalid features");e.bbox=e.bbox?e.bbox:De(e),t.push(e)}):qr(i,function(e){if(e.type!=="Feature")throw new Error("invalid features");e.bbox=e.bbox?e.bbox:De(e),t.push(e)}),this.tree.load(t),this}remove(i,t){if(i.type!=="Feature")throw new Error("invalid feature");return i.bbox=i.bbox?i.bbox:De(i),this.tree.remove(i,t),this}clear(){return this.tree.clear(),this}search(i){var t=this.tree.search(Zd(i));return ae(t)}collides(i){return this.tree.collides(Zd(i))}all(){const i=this.tree.all();return ae(i)}toJSON(){return this.tree.toJSON()}fromJSON(i){return this.tree.fromJSON(i),this}};function CE(i){return new Sk(i)}function Mk(i,t){if(t=t??{},!NE(t))throw new Error("options is invalid");var e=t.precision,n=t.coordinates,s=t.mutate;if(e=e==null||isNaN(e)?6:e,n=n==null||isNaN(n)?3:n,!i)throw new Error("<geojson> is required");if(typeof e!="number")throw new Error("<precision> must be a number");if(typeof n!="number")throw new Error("<coordinates> must be a number");(s===!1||s===void 0)&&(i=JSON.parse(JSON.stringify(i)));var r=Math.pow(10,e);return Mn(i,function(o){Nk(o,r,n)}),i}function Nk(i,t,e){i.length>e&&i.splice(e,i.length);for(var n=0;n<i.length;n++)i[n]=Math.round(i[n]*t)/t;return i}function Lk(i){if(!i)throw new Error("geojson is required");const t=[];return zr(i,e=>{Ck(e,t)}),ae(t)}function Ck(i,t){let e=[];const n=i.geometry;if(n!==null){switch(n.type){case"Polygon":e=ws(n);break;case"LineString":e=[ws(n)]}e.forEach(s=>{Pk(s,i.properties).forEach(o=>{o.id=t.length,t.push(o)})})}}function Pk(i,t){const e=[];return i.reduce((n,s)=>{const r=re([n,s],t);return r.bbox=kk(n,s),e.push(r),s}),e}function kk(i,t){const e=i[0],n=i[1],s=t[0],r=t[1],o=e<s?e:s,a=n<r?n:r,l=e>s?e:s,h=n>r?n:r;return[o,a,l,h]}class Km{constructor(t=[],e=Tk){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let n=(this.length>>1)-1;n>=0;n--)this._down(n)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(this.length===0)return;const t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:n}=this,s=e[t];for(;t>0;){const r=t-1>>1,o=e[r];if(n(s,o)>=0)break;e[t]=o,t=r}e[t]=s}_down(t){const{data:e,compare:n}=this,s=this.length>>1,r=e[t];for(;t<s;){let o=(t<<1)+1,a=e[o];const l=o+1;if(l<this.length&&n(e[l],a)<0&&(o=l,a=e[l]),n(a,r)>=0)break;e[t]=a,t=o}e[t]=r}}function Tk(i,t){return i<t?-1:i>t?1:0}const Rk=Object.freeze(Object.defineProperty({__proto__:null,default:Km},Symbol.toStringTag,{value:"Module"})),dr=11102230246251565e-32,Tn=134217729,Ak=(3+8*dr)*dr;function Jd(i,t,e,n,s){let r,o,a,l,h=t[0],f=n[0],d=0,p=0;f>h==f>-h?(r=h,h=t[++d]):(r=f,f=n[++p]);let y=0;if(d<i&&p<e)for(f>h==f>-h?(o=h+r,a=r-(o-h),h=t[++d]):(o=f+r,a=r-(o-f),f=n[++p]),r=o,a!==0&&(s[y++]=a);d<i&&p<e;)f>h==f>-h?(o=r+h,l=o-r,a=r-(o-l)+(h-l),h=t[++d]):(o=r+f,l=o-r,a=r-(o-l)+(f-l),f=n[++p]),r=o,a!==0&&(s[y++]=a);for(;d<i;)o=r+h,l=o-r,a=r-(o-l)+(h-l),h=t[++d],r=o,a!==0&&(s[y++]=a);for(;p<e;)o=r+f,l=o-r,a=r-(o-l)+(f-l),f=n[++p],r=o,a!==0&&(s[y++]=a);return(r!==0||y===0)&&(s[y++]=r),y}function Ok(i,t){let e=t[0];for(let n=1;n<i;n++)e+=t[n];return e}function mc(i){return new Float64Array(i)}const Fk=(3+16*dr)*dr,$k=(2+12*dr)*dr,Dk=(9+64*dr)*dr*dr,ea=mc(4),g1=mc(8),m1=mc(12),p1=mc(16),qn=mc(4);function Gk(i,t,e,n,s,r,o){let a,l,h,f,d,p,y,_,E,w,L,b,P,N,S,C,T,I;const M=i-s,R=e-s,A=t-r,F=n-r;N=M*F,p=Tn*M,y=p-(p-M),_=M-y,p=Tn*F,E=p-(p-F),w=F-E,S=_*w-(N-y*E-_*E-y*w),C=A*R,p=Tn*A,y=p-(p-A),_=A-y,p=Tn*R,E=p-(p-R),w=R-E,T=_*w-(C-y*E-_*E-y*w),L=S-T,d=S-L,ea[0]=S-(L+d)+(d-T),b=N+L,d=b-N,P=N-(b-d)+(L-d),L=P-C,d=P-L,ea[1]=P-(L+d)+(d-C),I=b+L,d=I-b,ea[2]=b-(I-d)+(L-d),ea[3]=I;let $=Ok(4,ea),z=$k*o;if($>=z||-$>=z||(d=i-M,a=i-(M+d)+(d-s),d=e-R,h=e-(R+d)+(d-s),d=t-A,l=t-(A+d)+(d-r),d=n-F,f=n-(F+d)+(d-r),a===0&&l===0&&h===0&&f===0)||(z=Dk*o+Ak*Math.abs($),$+=M*f+F*a-(A*h+R*l),$>=z||-$>=z))return $;N=a*F,p=Tn*a,y=p-(p-a),_=a-y,p=Tn*F,E=p-(p-F),w=F-E,S=_*w-(N-y*E-_*E-y*w),C=l*R,p=Tn*l,y=p-(p-l),_=l-y,p=Tn*R,E=p-(p-R),w=R-E,T=_*w-(C-y*E-_*E-y*w),L=S-T,d=S-L,qn[0]=S-(L+d)+(d-T),b=N+L,d=b-N,P=N-(b-d)+(L-d),L=P-C,d=P-L,qn[1]=P-(L+d)+(d-C),I=b+L,d=I-b,qn[2]=b-(I-d)+(L-d),qn[3]=I;const D=Jd(4,ea,4,qn,g1);N=M*f,p=Tn*M,y=p-(p-M),_=M-y,p=Tn*f,E=p-(p-f),w=f-E,S=_*w-(N-y*E-_*E-y*w),C=A*h,p=Tn*A,y=p-(p-A),_=A-y,p=Tn*h,E=p-(p-h),w=h-E,T=_*w-(C-y*E-_*E-y*w),L=S-T,d=S-L,qn[0]=S-(L+d)+(d-T),b=N+L,d=b-N,P=N-(b-d)+(L-d),L=P-C,d=P-L,qn[1]=P-(L+d)+(d-C),I=b+L,d=I-b,qn[2]=b-(I-d)+(L-d),qn[3]=I;const B=Jd(D,g1,4,qn,m1);N=a*f,p=Tn*a,y=p-(p-a),_=a-y,p=Tn*f,E=p-(p-f),w=f-E,S=_*w-(N-y*E-_*E-y*w),C=l*h,p=Tn*l,y=p-(p-l),_=l-y,p=Tn*h,E=p-(p-h),w=h-E,T=_*w-(C-y*E-_*E-y*w),L=S-T,d=S-L,qn[0]=S-(L+d)+(d-T),b=N+L,d=b-N,P=N-(b-d)+(L-d),L=P-C,d=P-L,qn[1]=P-(L+d)+(d-C),I=b+L,d=I-b,qn[2]=b-(I-d)+(L-d),qn[3]=I;const U=Jd(B,m1,4,qn,p1);return p1[U-1]}function y1(i,t,e,n,s,r){const o=(t-r)*(e-s),a=(i-s)*(n-r),l=o-a;if(o===0||a===0||o>0!=a>0)return l;const h=Math.abs(o+a);return Math.abs(l)>=Fk*h?l:-Gk(i,t,e,n,s,r,h)}function Bk(i,t){const e=new Km([],PE);return zk(i,e),Uk(e,t)}function PE(i,t){return i.p.x>t.p.x?1:i.p.x<t.p.x||i.p.x===t.p.x&&(i.featureId!==t.featureId||i.ringId!==t.ringId)&&i.isLeftEndpoint&&!t.isLeftEndpoint?-1:i.p.y!==t.p.y?i.p.y>t.p.y?1:-1:1}function qk(i,t){return i.rightSweepEvent.p.x>t.rightSweepEvent.p.x?1:i.rightSweepEvent.p.x<t.rightSweepEvent.p.x?-1:i.rightSweepEvent.p.y!==t.rightSweepEvent.p.y?i.rightSweepEvent.p.y<t.rightSweepEvent.p.y?1:-1:1}function zk(i,t){if(i.type==="FeatureCollection"){const e=i.features;for(let n=0;n<e.length;n++)_1(e[n],t)}else _1(i,t)}var Vc=0,Hc=0,Wc=0;function _1(i,t){const e=i.type==="Feature"?i.geometry:i;let n=e.coordinates;(e.type==="Polygon"||e.type==="MultiLineString")&&(n=[n]),e.type==="LineString"&&(n=[[n]]);for(let s=0;s<n.length;s++)for(let r=0;r<n[s].length;r++){let o=n[s][r][0],a=null;Hc=Hc+1;for(let l=0;l<n[s][r].length-1;l++){a=n[s][r][l+1];const h=new v1(o,Vc,Hc,Wc),f=new v1(a,Vc,Hc,Wc+1);h.otherEvent=f,f.otherEvent=h,PE(h,f)>0?(f.isLeftEndpoint=!0,h.isLeftEndpoint=!1):(h.isLeftEndpoint=!0,f.isLeftEndpoint=!1),t.push(h),t.push(f),o=a,Wc=Wc+1}}Vc=Vc+1}var v1=class{constructor(i,t,e,n){this.p={x:i[0],y:i[1]},this.featureId=t,this.ringId=e,this.eventId=n,this.otherEvent=null,this.isLeftEndpoint=null}isSamePoint(i){return this.p.x===i.p.x&&this.p.y===i.p.y}asNewXY(){return[this.p.x,this.p.y]}};function Uk(i,t=!1){const e=[],n=new Km([],qk);for(;i.length;){const s=i.pop();if(s.isLeftEndpoint){const r=new Yk(s);for(let o=0;o<n.data.length;o++){const a=n.data[o];if(t&&a.leftSweepEvent.featureId===s.featureId)continue;const l=Xk(r,a);l!==!1&&e.push(l)}n.push(r)}else s.isLeftEndpoint===!1&&n.pop()}return e}var Yk=class{constructor(t){this.leftSweepEvent=t,this.rightSweepEvent=t.otherEvent}};function Xk(i,t){if(i===null||t===null)return!1;const e=i.leftSweepEvent.p.x,n=i.leftSweepEvent.p.y,s=i.rightSweepEvent.p.x,r=i.rightSweepEvent.p.y,o=t.leftSweepEvent.p.x,a=t.leftSweepEvent.p.y,l=t.rightSweepEvent.p.x,h=t.rightSweepEvent.p.y,f=y1(e,n,s,r,o,a),d=y1(e,n,s,r,l,h);if(f>0&&d>0)return!1;if(f<0&&d<0)return!1;if(i.leftSweepEvent.ringId===t.leftSweepEvent.ringId){if(i.rightSweepEvent.isSamePoint(t.leftSweepEvent)||i.rightSweepEvent.isSamePoint(t.rightSweepEvent)||i.leftSweepEvent.isSamePoint(t.leftSweepEvent)||i.leftSweepEvent.isSamePoint(t.rightSweepEvent))return!1}else{if(i.rightSweepEvent.isSamePoint(t.leftSweepEvent))return t.leftSweepEvent.asNewXY();if(i.rightSweepEvent.isSamePoint(t.rightSweepEvent))return t.rightSweepEvent.asNewXY();if(i.leftSweepEvent.isSamePoint(t.leftSweepEvent))return t.leftSweepEvent.asNewXY();if(i.leftSweepEvent.isSamePoint(t.rightSweepEvent))return t.rightSweepEvent.asNewXY()}const p=(h-a)*(s-e)-(l-o)*(r-n),y=(l-o)*(n-a)-(h-a)*(e-o),_=(s-e)*(n-a)-(r-n)*(e-o);if(p===0)return!1;const E=y/p,w=_/p;if(E>=0&&E<=1&&w>=0&&w<=1){const L=e+E*(s-e),b=n+E*(r-n);return[L,b]}return!1}function Bo(i,t,e={}){const{removeDuplicates:n=!0,ignoreSelfIntersections:s=!0}=e;let r=[];i.type==="FeatureCollection"?r=r.concat(i.features):i.type==="Feature"?r.push(i):(i.type==="LineString"||i.type==="Polygon"||i.type==="MultiLineString"||i.type==="MultiPolygon")&&r.push(vn(i)),t.type==="FeatureCollection"?r=r.concat(t.features):t.type==="Feature"?r.push(t):(t.type==="LineString"||t.type==="Polygon"||t.type==="MultiLineString"||t.type==="MultiPolygon")&&r.push(vn(t));const o=Bk(ae(r),s);let a=[];if(n){const l={};o.forEach(h=>{const f=h.join(",");l[f]||(l[f]=!0,a.push(h))})}else a=o;return ae(a.map(l=>St(l)))}var jk=Object.defineProperty,Vk=Object.defineProperties,Hk=Object.getOwnPropertyDescriptors,E1=Object.getOwnPropertySymbols,Wk=Object.prototype.hasOwnProperty,Kk=Object.prototype.propertyIsEnumerable,w1=(i,t,e)=>t in i?jk(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,Zk=(i,t)=>{for(var e in t||(t={}))Wk.call(t,e)&&w1(i,e,t[e]);if(E1)for(var e of E1(t))Kk.call(t,e)&&w1(i,e,t[e]);return i},Jk=(i,t)=>Vk(i,Hk(t));function kE(i,t,e={}){if(!i||!t)throw new Error("lines and inputPoint are required arguments");const n=li(t);let s=St([1/0,1/0],{lineStringIndex:-1,segmentIndex:-1,totalDistance:-1,lineDistance:-1,segmentDistance:-1,pointDistance:1/0,multiFeatureIndex:-1,index:-1,location:-1,dist:1/0}),r=0,o=0,a=-1;return zr(i,function(l,h,f){a!==f&&(a=f,o=0);const d=ws(l);for(let p=0;p<d.length-1;p++){const y=St(d[p]),_=li(y),E=St(d[p+1]),w=li(E),L=nn(y,E,e);let b,P;w[0]===n[0]&&w[1]===n[1]?[b,P]=[w,!0]:_[0]===n[0]&&_[1]===n[1]?[b,P]=[_,!1]:[b,P]=eT(_,w,n);const N=nn(t,b,e);if(N<s.properties.pointDistance){const S=nn(y,b,e);s=St(b,{lineStringIndex:f,segmentIndex:P?p+1:p,totalDistance:r+S,lineDistance:o+S,segmentDistance:S,pointDistance:N,multiFeatureIndex:-1,index:-1,location:-1,dist:1/0}),s.properties=Jk(Zk({},s.properties),{multiFeatureIndex:s.properties.lineStringIndex,index:s.properties.segmentIndex,location:s.properties.totalDistance,dist:s.properties.pointDistance})}r+=L,o+=L}}),s}function uo(i,t){const[e,n,s]=i,[r,o,a]=t;return e*r+n*o+s*a}function Xl(i,t){const[e,n,s]=i,[r,o,a]=t;return[n*a-s*o,s*r-e*a,e*o-n*r]}function Qk(i){return Math.sqrt(Math.pow(i[0],2)+Math.pow(i[1],2)+Math.pow(i[2],2))}function x1(i){const t=Qk(i);return[i[0]/t,i[1]/t,i[2]/t]}function Qd(i){const t=Ni(i[1]),e=Ni(i[0]);return[Math.cos(t)*Math.cos(e),Math.cos(t)*Math.sin(e),Math.sin(t)]}function tT(i){const[t,e,n]=i,s=Math.min(Math.max(n,-1),1),r=Pu(Math.asin(s));return[Pu(Math.atan2(e,t)),r]}function eT(i,t,e){const n=Qd(i),s=Qd(t),r=Qd(e),o=Xl(n,s);if(o[0]===0&&o[1]===0&&o[2]===0)return uo(n,s)>0?[[...t],!0]:[[...e],!1];const a=Xl(o,r);if(a[0]===0&&a[1]===0&&a[2]===0)return[[...t],!0];const l=Xl(a,o),h=x1(l),f=[-h[0],-h[1],-h[2]],d=uo(r,h)>uo(r,f)?h:f,p=x1(o),y=uo(Xl(n,d),p),_=uo(Xl(d,s),p);return y>=0&&_>=0?[tT(d),!1]:uo(n,r)>uo(s,r)?[[...i],!1]:[[...t],!0]}function au(i,t){if(!i)throw new Error("line is required");if(!t)throw new Error("splitter is required");const e=Kh(i),n=Kh(t);if(e!=="LineString")throw new Error("line must be LineString");if(n==="FeatureCollection")throw new Error("splitter cannot be a FeatureCollection");if(n==="GeometryCollection")throw new Error("splitter cannot be a GeometryCollection");var s=Mk(t,{precision:7});switch(i.type!=="Feature"&&(i=vn(i)),n){case"Point":return Xg(i,s);case"MultiPoint":return b1(i,s);case"LineString":case"MultiLineString":case"Polygon":case"MultiPolygon":return b1(i,Bo(i,s,{ignoreSelfIntersections:!0}))}}function b1(i,t){var e=[],n=CE();return zr(t,function(s){if(e.forEach(function(a,l){a.id=l}),!e.length)e=Xg(i,s).features,n.load(ae(e));else{var r=n.search(s);if(r.features.length){var o=TE(s,r);e=e.filter(function(a){return a.id!==o.id}),n.remove(o),qr(Xg(o,s),function(a){e.push(a),n.insert(a)})}}}),ae(e)}function Xg(i,t){var e=[],n=ws(i)[0],s=ws(i)[i.geometry.coordinates.length-1];if(tg(n,li(t))||tg(s,li(t)))return ae([i]);var r=CE(),o=Lk(i);r.load(o);var a=r.search(t);if(!a.features.length)return ae([i]);var l=TE(t,a),h=[n],f=QP(o,function(d,p,y){var _=ws(p)[1],E=li(t);return y===l.id?(d.push(E),e.push(re(d)),tg(E,_)?[E]:[E,_]):(d.push(_),d)},h);return f.length>1&&e.push(re(f)),ae(e)}function TE(i,t){if(!t.features.length)throw new Error("lines must contain features");if(t.features.length===1)return t.features[0];var e,n=1/0;return qr(t,function(s){var r=kE(s,i),o=r.properties.pointDistance;o<n&&(e=s,n=o)}),e}function tg(i,t){return i[0]===t[0]&&i[1]===t[1]}function RE(i,t){const e=Jn(i),n=Jn(t),s=e.type,r=n.type,o=e.coordinates,a=n.coordinates;switch(s){case"Point":switch(r){case"Point":return Zm(o,a);default:throw new Error("feature2 "+r+" geometry not supported")}case"MultiPoint":switch(r){case"Point":return uT(e,n);case"MultiPoint":return cT(e,n);default:throw new Error("feature2 "+r+" geometry not supported")}case"LineString":switch(r){case"Point":return oe(n,e,{ignoreEndVertices:!0});case"LineString":return dT(e,n);case"MultiPoint":return hT(e,n);default:throw new Error("feature2 "+r+" geometry not supported")}case"Polygon":switch(r){case"Point":return Ht(n,e,{ignoreBoundary:!0});case"LineString":return OE(e,n);case"Polygon":return Uf(e,n);case"MultiPoint":return fT(e,n);case"MultiPolygon":return lT(e,n);default:throw new Error("feature2 "+r+" geometry not supported")}case"MultiPolygon":switch(r){case"Point":return iT(e,n);case"MultiPoint":return sT(e,n);case"LineString":return rT(e,n);case"MultiLineString":return oT(e,n);case"Polygon":return nT(e,n);case"MultiPolygon":return aT(e,n);default:throw new Error("feature2 "+r+" geometry not supported")}default:throw new Error("feature1 "+s+" geometry not supported")}}function nT(i,t){const e=De(t);return i.coordinates.some(n=>Uf({type:"Polygon",coordinates:n},t,e))}function iT(i,t){return Ht(t,i,{ignoreBoundary:!0})}function sT(i,t){let e=!1;for(const n of t.coordinates){if(!Ht(n,i))return!1;e||(e=Ht(n,i,{ignoreBoundary:!0}))}return e}function rT(i,t){return i.coordinates.some(e=>OE({type:"Polygon",coordinates:e},t))}function oT(i,t){let e=!1;for(const n of t.coordinates){const s={type:"LineString",coordinates:n};let r="outside";for(const o of i.coordinates){const a=FE({type:"Polygon",coordinates:o},s);if(a==="interior"){r=a;break}a==="boundary"&&(r=a)}if(r==="outside")return!1;r==="interior"&&(e=!0)}return e}function aT(i,t){for(const e of t.coordinates){const n={type:"Polygon",coordinates:e},s=De(n);if(!i.coordinates.some(o=>Uf({type:"Polygon",coordinates:o},n,s)))return!1}return!0}function lT(i,t){return t.coordinates.every(e=>Uf(i,{type:"Polygon",coordinates:e}))}function uT(i,t){let e,n=!1;for(e=0;e<i.coordinates.length;e++)if(Zm(i.coordinates[e],t.coordinates)){n=!0;break}return n}function cT(i,t){for(const e of t.coordinates){let n=!1;for(const s of i.coordinates)if(Zm(e,s)){n=!0;break}if(!n)return!1}return!0}function hT(i,t){let e=!1;for(const n of t.coordinates){if(!oe(n,i))return!1;!e&&oe(n,i,{ignoreEndVertices:!0})&&(e=!0)}return e}function fT(i,t){let e=!1;for(const n of t.coordinates){if(!Ht(n,i))return!1;e||(e=Ht(n,i,{ignoreBoundary:!0}))}return e}function dT(i,t){let e=!1;const n=t.coordinates;for(let s=0;s<n.length;s++){const r=n[s];if(!oe(r,i))return!1;if(!e){if(oe(r,i,{ignoreEndVertices:!0}))e=!0;else if(s>0){const o=[(n[s-1][0]+r[0])/2,(n[s-1][1]+r[1])/2];oe(o,i,{ignoreEndVertices:!0})&&(e=!0)}}}return e}function AE(i,t){const e=i.coordinates,n=[];for(let s=0;s<e.length-1;s++){const r=re([e[s],e[s+1]]),o=au(r,vn(t));o.features.length===0?n.push(r):n.push(...o.features)}return ae(n)}function OE(i,t){return FE(i,t)==="interior"}function FE(i,t){const e=De(i),n=De(t);if(!$E(e,n))return"outside";for(const o of t.coordinates)if(!Ht(o,i))return"outside";let s=!1;const r=AE(t,i);for(const o of r.features){const a=DE(o.geometry.coordinates[0],o.geometry.coordinates[1]);if(!Ht(a,i))return"outside";!s&&Ht(a,i,{ignoreBoundary:!0})&&(s=!0)}return s?"interior":"boundary"}function Uf(i,t,e){if(i.type==="Feature"&&i.geometry===null||t.type==="Feature"&&t.geometry===null)return!1;const n=De(i),s=e??De(t);if(!$E(n,s))return!1;const r=Jn(i),o=Jn(t).coordinates;for(const a of o){for(const h of a)if(!Ht(h,i))return!1;const l=AE({coordinates:a},r);for(const h of l.features){const f=DE(h.geometry.coordinates[0],h.geometry.coordinates[1]);if(!Ht(f,i)&&!pT(f,r))return!1}}return!0}var gT=1e-6;function mT(i,t,e){const n=e[0]-t[0],s=e[1]-t[1],r=n*n+s*s;let o=0;r>0&&(o=((i[0]-t[0])*n+(i[1]-t[1])*s)/r,o=Math.max(0,Math.min(1,o)));const a=t[0]+o*n,l=t[1]+o*s,h=i[0]-a,f=i[1]-l;return Math.sqrt(h*h+f*f)}function pT(i,t){return t.coordinates.some(e=>{for(let n=0;n<e.length-1;n++)if(mT(i,e[n],e[n+1])<=gT)return!0;return!1})}function $E(i,t){return!(i[0]>t[0]||i[2]<t[2]||i[1]>t[1]||i[3]<t[3])}function Zm(i,t){return i[0]===t[0]&&i[1]===t[1]}function DE(i,t){return[(i[0]+t[0])/2,(i[1]+t[1])/2]}function Ka(i,t={}){const e=Jn(i);switch(!t.properties&&i.type==="Feature"&&(t.properties=i.properties),e.type){case"Polygon":return yT(e,t);case"MultiPolygon":return _T(e,t);default:throw new Error("invalid poly")}}function yT(i,t={}){const n=Jn(i).coordinates,s=t.properties?t.properties:i.type==="Feature"?i.properties:{};return GE(n,s)}function _T(i,t={}){const n=Jn(i).coordinates,s=t.properties?t.properties:i.type==="Feature"?i.properties:{},r=[];return n.forEach(o=>{r.push(GE(o,s))}),ae(r)}function GE(i,t){return i.length>1?bE(i,t):re(i[0],t)}var vT=Object.defineProperty,ml=(i,t)=>vT(i,"name",{value:t,configurable:!0}),BE=class{constructor(t){this.direction=!1,this.compareProperties=!0;var e,n,s;this.precision=10**-((e=t==null?void 0:t.precision)!=null?e:17),this.direction=(n=t==null?void 0:t.direction)!=null?n:!1,this.compareProperties=(s=t==null?void 0:t.compareProperties)!=null?s:!0}compare(t,e){if(t.type!==e.type||!lu(t,e))return!1;switch(t.type){case"Point":return this.compareCoord(t.coordinates,e.coordinates);case"LineString":return this.compareLine(t.coordinates,e.coordinates);case"Polygon":return this.comparePolygon(t,e);case"GeometryCollection":return this.compareGeometryCollection(t,e);case"Feature":return this.compareFeature(t,e);case"FeatureCollection":return this.compareFeatureCollection(t,e);default:if(t.type.startsWith("Multi")){const n=jg(t),s=jg(e);return n.every(r=>s.some(o=>this.compare(r,o)))}}return!1}compareCoord(t,e){return t.length===e.length&&t.every((n,s)=>Math.abs(n-e[s])<this.precision)}compareLine(t,e,n=0,s=!1){if(!lu(t,e))return!1;const r=t;let o=e;if(s&&!this.compareCoord(r[0],o[0])){const l=this.fixStartIndex(o,r);if(l)o=l;else return!1}const a=this.compareCoord(r[n],o[n]);return this.direction||a?this.comparePath(r,o):this.compareCoord(r[n],o[o.length-(1+n)])?this.comparePath(r.slice().reverse(),o):!1}fixStartIndex(t,e){let n,s=-1;for(let r=0;r<t.length;r++)if(this.compareCoord(t[r],e[0])){s=r;break}return s>=0&&(n=[].concat(t.slice(s,t.length),t.slice(1,s+1))),n}comparePath(t,e){return t.every((n,s)=>this.compareCoord(n,e[s]))}comparePolygon(t,e){if(this.compareLine(t.coordinates[0],e.coordinates[0],1,!0)){const n=t.coordinates.slice(1,t.coordinates.length),s=e.coordinates.slice(1,e.coordinates.length);return n.every(r=>s.some(o=>this.compareLine(r,o,1,!0)))}return!1}compareGeometryCollection(t,e){return lu(t.geometries,e.geometries)&&this.compareBBox(t,e)&&t.geometries.every((n,s)=>this.compare(n,e.geometries[s]))}compareFeature(t,e){return t.id===e.id&&(this.compareProperties?Jm(t.properties,e.properties):!0)&&this.compareBBox(t,e)&&this.compare(t.geometry,e.geometry)}compareFeatureCollection(t,e){return lu(t.features,e.features)&&this.compareBBox(t,e)&&t.features.every((n,s)=>this.compare(n,e.features[s]))}compareBBox(t,e){return!t.bbox&&!e.bbox||(t.bbox&&e.bbox?this.compareCoord(t.bbox,e.bbox):!1)}};ml(BE,"GeojsonEquality");var ET=BE;function lu(i,t){return i.coordinates?i.coordinates.length===t.coordinates.length:i.length===t.length}ml(lu,"sameLength");function jg(i){return i.coordinates.map(t=>({type:i.type.replace("Multi",""),coordinates:t}))}ml(jg,"explode");function qE(i,t,e){return new ET(e).compare(i,t)}ml(qE,"geojsonEquality");function Jm(i,t){if(i===null&&t===null)return!0;if(i===null||t===null)return!1;const e=Object.keys(i),n=Object.keys(t);if(e.length!==n.length)return!1;for(var s of e){const r=i[s],o=t[s],a=I1(r)&&I1(o);if(a&&!Jm(r,o)||!a&&r!==o)return!1}return!0}ml(Jm,"equal");var I1=ml(i=>i!=null&&typeof i=="object","isObject");function Ta(i,t={}){var e=typeof t=="object"?t.mutate:t;if(!i)throw new Error("geojson is required");var n=Kh(i),s=[];switch(n){case"LineString":s=eg(i,n);break;case"MultiLineString":case"Polygon":ws(i).forEach(function(o){s.push(eg(o,n))});break;case"MultiPolygon":ws(i).forEach(function(o){var a=[];o.forEach(function(l){a.push(eg(l,n))}),s.push(a)});break;case"Point":return i;case"MultiPoint":var r={};ws(i).forEach(function(o){var a=o.join("-");Object.prototype.hasOwnProperty.call(r,a)||(s.push(o),r[a]=!0)});break;default:throw new Error(n+" geometry not supported")}return i.coordinates?e===!0?(i.coordinates=s,i):{type:n,coordinates:s}:e===!0?(i.geometry.coordinates=s,i):vn({type:n,coordinates:s},i.properties,{bbox:i.bbox,id:i.id})}function eg(i,t){const e=ws(i);if(e.length===2&&!S1(e[0],e[1]))return e;const n=[];let s=0,r=1,o=2;for(n.push(e[s]);o<e.length;)oe(e[r],re([e[s],e[o]]))?r=o:(n.push(e[r]),s=r,r++,o=r),o++;if(n.push(e[r]),t==="Polygon"||t==="MultiPolygon"){if(oe(n[0],re([n[1],n[n.length-2]]))&&(n.shift(),n.pop(),n.push(n[0])),n.length<4)throw new Error("invalid polygon, fewer than 4 points");if(!S1(n[0],n[n.length-1]))throw new Error("invalid polygon, first and last points not equal")}return n}function S1(i,t){return i[0]===t[0]&&i[1]===t[1]}function Kc(i,t,e={}){let n=e.precision;if(n=n==null||isNaN(n)?6:n,typeof n!="number"||!(n>=0))throw new Error("precision must be a positive number");const s=Jn(i).type,r=Jn(t).type;return s!==r?!1:qE(Ta(i),Ta(t),{precision:n})}function wT(i,t){var e=Jn(i),n=Jn(t),s=e.type,r=n.type;switch(s){case"MultiPoint":switch(r){case"LineString":return M1(e,n);case"Polygon":return L1(e,n);default:throw new Error("feature2 "+r+" geometry not supported")}case"LineString":switch(r){case"MultiPoint":return M1(n,e);case"LineString":return xT(e,n);case"Polygon":return N1(e,n);default:throw new Error("feature2 "+r+" geometry not supported")}case"Polygon":switch(r){case"MultiPoint":return L1(n,e);case"LineString":return N1(n,e);default:throw new Error("feature2 "+r+" geometry not supported")}default:throw new Error("feature1 "+s+" geometry not supported")}}function M1(i,t){for(var e=!1,n=!1,s=i.coordinates.length,r=0;r<s&&(!e||!n);r++){for(var o=!1,a=0;a<t.coordinates.length-1;a++){var l=!0;if((a===0||a===t.coordinates.length-2)&&(l=!1),bT(t.coordinates[a],t.coordinates[a+1],i.coordinates[r],l)){o=!0;break}}o?e=!0:n=!0}return e&&n}function xT(i,t){const e=Bo(i,t);if(e.features.length===0)return!1;for(const n of e.features)if(!Kc(n,St(i.coordinates[0]))&&!Kc(n,St(i.coordinates[i.coordinates.length-1]))&&!Kc(n,St(t.coordinates[0]))&&!Kc(n,St(t.coordinates[t.coordinates.length-1])))return!0;return!1}function N1(i,t){const e=Ka(t);return Bo(i,e).features.length>0}function L1(i,t){var e=!1,n=!1,s=i.coordinates.length;for(let r=0;r<s&&(!e||!n);r++)Ht(St(i.coordinates[r]),t)?e=!0:n=!0;return n&&e}function bT(i,t,e,n){var s=e[0]-i[0],r=e[1]-i[1],o=t[0]-i[0],a=t[1]-i[1],l=s*a-r*o;return l!==0?!1:n?Math.abs(o)>=Math.abs(a)?o>0?i[0]<=e[0]&&e[0]<=t[0]:t[0]<=e[0]&&e[0]<=i[0]:a>0?i[1]<=e[1]&&e[1]<=t[1]:t[1]<=e[1]&&e[1]<=i[1]:Math.abs(o)>=Math.abs(a)?o>0?i[0]<e[0]&&e[0]<t[0]:t[0]<e[0]&&e[0]<i[0]:a>0?i[1]<e[1]&&e[1]<t[1]:t[1]<e[1]&&e[1]<i[1]}function IT(i,t,{ignoreSelfIntersections:e=!0}={ignoreSelfIntersections:!0}){let n=!0;return zr(i,s=>{zr(t,r=>{if(n===!1)return!1;n=ST(s.geometry,r.geometry,e)})}),n}function ST(i,t,e){switch(i.type){case"Point":switch(t.type){case"Point":return!CT(i.coordinates,t.coordinates);case"LineString":return!Zh(t,i);case"Polygon":return!Ht(i,t)}break;case"LineString":switch(t.type){case"Point":return!Zh(i,t);case"LineString":return!MT(i,t,e);case"Polygon":return!C1(t,i,e)}break;case"Polygon":switch(t.type){case"Point":return!Ht(t,i);case"LineString":return!C1(i,t,e);case"Polygon":return!NT(t,i,e)}}return!1}function Zh(i,t){for(let e=0;e<i.coordinates.length-1;e++)if(LT(i.coordinates[e],i.coordinates[e+1],t.coordinates))return!0;return!1}function MT(i,t,e){if(Bo(i,t,{ignoreSelfIntersections:e}).features.length>0)return!0;for(const s of i.coordinates)if(Zh(t,{coordinates:s}))return!0;for(const s of t.coordinates)if(Zh(i,{coordinates:s}))return!0;return!1}function C1(i,t,e){for(const s of t.coordinates)if(Ht(s,i))return!0;return Bo(t,Ka(i),{ignoreSelfIntersections:e}).features.length>0}function NT(i,t,e){for(const s of i.coordinates[0])if(Ht(s,t))return!0;for(const s of t.coordinates[0])if(Ht(s,i))return!0;return Bo(Ka(i),Ka(t),{ignoreSelfIntersections:e}).features.length>0}function LT(i,t,e){const n=e[0]-i[0],s=e[1]-i[1],r=t[0]-i[0],o=t[1]-i[1];return n*o-s*r!==0?!1:Math.abs(r)>=Math.abs(o)?r>0?i[0]<=e[0]&&e[0]<=t[0]:t[0]<=e[0]&&e[0]<=i[0]:o>0?i[1]<=e[1]&&e[1]<=t[1]:t[1]<=e[1]&&e[1]<=i[1]}function CT(i,t){return i[0]===t[0]&&i[1]===t[1]}function To(i,t,{ignoreSelfIntersections:e=!0}={}){return!IT(i,t,{ignoreSelfIntersections:e})}function zE(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}function PT(i){if(Object.prototype.hasOwnProperty.call(i,"__esModule"))return i;var t=i.default;if(typeof t=="function"){var e=function n(){return this instanceof n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};e.prototype=t.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(i).forEach(function(n){var s=Object.getOwnPropertyDescriptor(i,n);Object.defineProperty(e,n,s.get?s:{enumerable:!0,get:function(){return i[n]}})}),e}function kT(i,t){var e=Jn(i),n=Jn(t),s=e.type,r=n.type;switch(s){case"Point":switch(r){case"LineString":return Rn(e,n);case"MultiLineString":for(var o=!1,a=0;a<n.coordinates.length;a++)Rn(e,{coordinates:n.coordinates[a]})&&(o=!0);return o;case"Polygon":for(var l=0;l<n.coordinates.length;l++)if(oe(e,{type:"LineString",coordinates:n.coordinates[l]}))return!0;return!1;case"MultiPolygon":for(var l=0;l<n.coordinates.length;l++)for(var a=0;a<n.coordinates[l].length;a++)if(oe(e,{type:"LineString",coordinates:n.coordinates[l][a]}))return!0;return!1;default:throw new Error("feature2 "+r+" geometry not supported")}case"MultiPoint":switch(r){case"LineString":for(var o=!1,l=0;l<e.coordinates.length;l++)if(o||Rn({coordinates:e.coordinates[l]},n)&&(o=!0),oe({type:"Point",coordinates:e.coordinates[l]},n,{ignoreEndVertices:!0}))return!1;return o;case"MultiLineString":for(var o=!1,l=0;l<e.coordinates.length;l++)for(var a=0;a<n.coordinates.length;a++)if(o||Rn({coordinates:e.coordinates[l]},{coordinates:n.coordinates[a]})&&(o=!0),oe({type:"Point",coordinates:e.coordinates[l]},{type:"LineString",coordinates:n.coordinates[a]},{ignoreEndVertices:!0}))return!1;return o;case"Polygon":for(var o=!1,l=0;l<e.coordinates.length;l++)if(o||oe({type:"Point",coordinates:e.coordinates[l]},{type:"LineString",coordinates:n.coordinates[0]})&&(o=!0),Ht({type:"Point",coordinates:e.coordinates[l]},n,{ignoreBoundary:!0}))return!1;return o;case"MultiPolygon":for(var o=!1,l=0;l<e.coordinates.length;l++)for(var a=0;a<n.coordinates.length;a++)if(o||oe({type:"Point",coordinates:e.coordinates[l]},{type:"LineString",coordinates:n.coordinates[a][0]})&&(o=!0),Ht({type:"Point",coordinates:e.coordinates[l]},{type:"Polygon",coordinates:n.coordinates[a]},{ignoreBoundary:!0}))return!1;return o;default:throw new Error("feature2 "+r+" geometry not supported")}case"LineString":switch(r){case"Point":return Rn(n,e);case"MultiPoint":for(var o=!1,l=0;l<n.coordinates.length;l++)if(o||Rn({coordinates:n.coordinates[l]},e)&&(o=!0),oe({type:"Point",coordinates:n.coordinates[l]},e,{ignoreEndVertices:!0}))return!1;return o;case"LineString":var h=!1;if(Rn({coordinates:e.coordinates[0]},n)&&(h=!0),Rn({coordinates:e.coordinates[e.coordinates.length-1]},n)&&(h=!0),h===!1)return!1;for(var l=0;l<e.coordinates.length;l++)if(oe({type:"Point",coordinates:e.coordinates[l]},n,{ignoreEndVertices:!0}))return!1;return h;case"MultiLineString":for(var h=!1,l=0;l<n.coordinates.length;l++){Rn({coordinates:e.coordinates[0]},{coordinates:n.coordinates[l]})&&(h=!0),Rn({coordinates:e.coordinates[e.coordinates.length-1]},{coordinates:n.coordinates[l]})&&(h=!0);for(var a=0;a<e.coordinates[l].length;a++)if(oe({type:"Point",coordinates:e.coordinates[a]},{type:"LineString",coordinates:n.coordinates[l]},{ignoreEndVertices:!0}))return!1}return h;case"Polygon":for(var o=!1,l=0;l<e.coordinates.length;l++)if(o||oe({type:"Point",coordinates:e.coordinates[l]},{type:"LineString",coordinates:n.coordinates[0]})&&(o=!0),Ht({type:"Point",coordinates:e.coordinates[l]},n,{ignoreBoundary:!0}))return!1;return o;case"MultiPolygon":for(var o=!1,l=0;l<e.coordinates.length;l++){for(var a=0;a<n.coordinates.length;a++)o||oe({type:"Point",coordinates:e.coordinates[l]},{type:"LineString",coordinates:n.coordinates[a][0]})&&(o=!0);if(Ht({type:"Point",coordinates:e.coordinates[l]},n,{ignoreBoundary:!0}))return!1}return o;default:throw new Error("feature2 "+r+" geometry not supported")}case"MultiLineString":switch(r){case"Point":for(var l=0;l<e.coordinates.length;l++)if(Rn(n,{coordinates:e.coordinates[l]}))return!0;return!1;case"MultiPoint":for(var o=!1,l=0;l<e.coordinates.length;l++)for(var a=0;a<n.coordinates.length;a++)if(o||Rn({coordinates:n.coordinates[a]},{coordinates:e.coordinates[a]})&&(o=!0),oe({type:"Point",coordinates:n.coordinates[a]},{type:"LineString",coordinates:e.coordinates[a]},{ignoreEndVertices:!0}))return!1;return o;case"LineString":for(var h=!1,l=0;l<e.coordinates.length;l++){Rn({coordinates:e.coordinates[l][0]},n)&&(h=!0),Rn({coordinates:e.coordinates[l][e.coordinates[l].length-1]},n)&&(h=!0);for(var a=0;a<n.coordinates.length;a++)if(oe({type:"Point",coordinates:n.coordinates[a]},{type:"LineString",coordinates:e.coordinates[l]},{ignoreEndVertices:!0}))return!1}return h;case"MultiLineString":for(var h=!1,l=0;l<e.coordinates.length;l++)for(var a=0;a<n.coordinates.length;a++){Rn({coordinates:e.coordinates[l][0]},{coordinates:n.coordinates[a]})&&(h=!0),Rn({coordinates:e.coordinates[l][e.coordinates[l].length-1]},{coordinates:n.coordinates[a]})&&(h=!0);for(var f=0;f<e.coordinates[l].length;f++)if(oe({type:"Point",coordinates:e.coordinates[l][f]},{type:"LineString",coordinates:n.coordinates[a]},{ignoreEndVertices:!0}))return!1}return h;case"Polygon":for(var o=!1,l=0;l<e.coordinates.length;l++)for(var a=0;a<e.coordinates.length;a++)if(o||oe({type:"Point",coordinates:e.coordinates[l][a]},{type:"LineString",coordinates:n.coordinates[0]})&&(o=!0),Ht({type:"Point",coordinates:e.coordinates[l][a]},n,{ignoreBoundary:!0}))return!1;return o;case"MultiPolygon":for(var o=!1,l=0;l<n.coordinates[0].length;l++)for(var a=0;a<e.coordinates.length;a++)for(var f=0;f<e.coordinates[a].length;f++)if(o||oe({type:"Point",coordinates:e.coordinates[a][f]},{type:"LineString",coordinates:n.coordinates[0][l]})&&(o=!0),Ht({type:"Point",coordinates:e.coordinates[a][f]},{type:"Polygon",coordinates:[n.coordinates[0][l]]},{ignoreBoundary:!0}))return!1;return o;default:throw new Error("feature2 "+r+" geometry not supported")}case"Polygon":switch(r){case"Point":for(var l=0;l<e.coordinates.length;l++)if(oe(n,{type:"LineString",coordinates:e.coordinates[l]}))return!0;return!1;case"MultiPoint":for(var o=!1,l=0;l<n.coordinates.length;l++)if(o||oe({type:"Point",coordinates:n.coordinates[l]},{type:"LineString",coordinates:e.coordinates[0]})&&(o=!0),Ht({type:"Point",coordinates:n.coordinates[l]},e,{ignoreBoundary:!0}))return!1;return o;case"LineString":for(var o=!1,l=0;l<n.coordinates.length;l++)if(o||oe({type:"Point",coordinates:n.coordinates[l]},{type:"LineString",coordinates:e.coordinates[0]})&&(o=!0),Ht({type:"Point",coordinates:n.coordinates[l]},e,{ignoreBoundary:!0}))return!1;return o;case"MultiLineString":for(var o=!1,l=0;l<n.coordinates.length;l++)for(var a=0;a<n.coordinates[l].length;a++)if(o||oe({type:"Point",coordinates:n.coordinates[l][a]},{type:"LineString",coordinates:e.coordinates[0]})&&(o=!0),Ht({type:"Point",coordinates:n.coordinates[l][a]},e,{ignoreBoundary:!0}))return!1;return o;case"Polygon":for(var o=!1,l=0;l<e.coordinates[0].length;l++)if(o||oe({type:"Point",coordinates:e.coordinates[0][l]},{type:"LineString",coordinates:n.coordinates[0]})&&(o=!0),Ht({type:"Point",coordinates:e.coordinates[0][l]},n,{ignoreBoundary:!0}))return!1;return o;case"MultiPolygon":for(var o=!1,l=0;l<n.coordinates[0].length;l++)for(var a=0;a<e.coordinates[0].length;a++)if(o||oe({type:"Point",coordinates:e.coordinates[0][a]},{type:"LineString",coordinates:n.coordinates[0][l]})&&(o=!0),Ht({type:"Point",coordinates:e.coordinates[0][a]},{type:"Polygon",coordinates:n.coordinates[0][l]},{ignoreBoundary:!0}))return!1;return o;default:throw new Error("feature2 "+r+" geometry not supported")}case"MultiPolygon":switch(r){case"Point":for(var l=0;l<e.coordinates[0].length;l++)if(oe(n,{type:"LineString",coordinates:e.coordinates[0][l]}))return!0;return!1;case"MultiPoint":for(var o=!1,l=0;l<e.coordinates[0].length;l++)for(var a=0;a<n.coordinates.length;a++)if(o||oe({type:"Point",coordinates:n.coordinates[a]},{type:"LineString",coordinates:e.coordinates[0][l]})&&(o=!0),Ht({type:"Point",coordinates:n.coordinates[a]},{type:"Polygon",coordinates:e.coordinates[0][l]},{ignoreBoundary:!0}))return!1;return o;case"LineString":for(var o=!1,l=0;l<e.coordinates[0].length;l++)for(var a=0;a<n.coordinates.length;a++)if(o||oe({type:"Point",coordinates:n.coordinates[a]},{type:"LineString",coordinates:e.coordinates[0][l]})&&(o=!0),Ht({type:"Point",coordinates:n.coordinates[a]},{type:"Polygon",coordinates:e.coordinates[0][l]},{ignoreBoundary:!0}))return!1;return o;case"MultiLineString":for(var o=!1,l=0;l<e.coordinates.length;l++)for(var a=0;a<n.coordinates.length;a++)for(var f=0;f<n.coordinates[a].length;f++)if(o||oe({type:"Point",coordinates:n.coordinates[a][f]},{type:"LineString",coordinates:e.coordinates[l][0]})&&(o=!0),Ht({type:"Point",coordinates:n.coordinates[a][f]},{type:"Polygon",coordinates:[e.coordinates[l][0]]},{ignoreBoundary:!0}))return!1;return o;case"Polygon":for(var o=!1,l=0;l<e.coordinates[0].length;l++)for(var a=0;a<e.coordinates[0][l].length;a++)if(o||oe({type:"Point",coordinates:e.coordinates[0][l][a]},{type:"LineString",coordinates:n.coordinates[0]})&&(o=!0),Ht({type:"Point",coordinates:e.coordinates[0][l][a]},n,{ignoreBoundary:!0}))return!1;return o;case"MultiPolygon":for(var o=!1,l=0;l<e.coordinates[0].length;l++)for(var a=0;a<n.coordinates[0].length;a++)for(var f=0;f<e.coordinates[0].length;f++)if(o||oe({type:"Point",coordinates:e.coordinates[0][l][f]},{type:"LineString",coordinates:n.coordinates[0][a]})&&(o=!0),Ht({type:"Point",coordinates:e.coordinates[0][l][f]},{type:"Polygon",coordinates:n.coordinates[0][a]},{ignoreBoundary:!0}))return!1;return o;default:throw new Error("feature2 "+r+" geometry not supported")}default:throw new Error("feature1 "+s+" geometry not supported")}}function Rn(i,t){return!!(P1(t.coordinates[0],i.coordinates)||P1(t.coordinates[t.coordinates.length-1],i.coordinates))}function P1(i,t){return i[0]===t[0]&&i[1]===t[1]}function TT(i,t){return RE(t,i)}function UE(i,t={}){const e=De(i),n=(e[0]+e[2])/2,s=(e[1]+e[3])/2;return St([n,s],t.properties,t)}var bh={exports:{}},RT=bh.exports,k1;function AT(){return k1||(k1=1,(function(i,t){(function(e,n){i.exports=n()})(RT,(function(){function e(m,u){(u==null||u>m.length)&&(u=m.length);for(var c=0,g=Array(u);c<u;c++)g[c]=m[c];return g}function n(m,u,c){return u=f(u),(function(g,v){if(v&&(typeof v=="object"||typeof v=="function"))return v;if(v!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return(function(x){if(x===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return x})(g)})(m,p()?Reflect.construct(u,c||[],f(m).constructor):u.apply(m,c))}function s(m,u){if(!(m instanceof u))throw new TypeError("Cannot call a class as a function")}function r(m,u,c){if(p())return Reflect.construct.apply(null,arguments);var g=[null];g.push.apply(g,u);var v=new(m.bind.apply(m,g));return c&&y(v,c.prototype),v}function o(m,u){for(var c=0;c<u.length;c++){var g=u[c];g.enumerable=g.enumerable||!1,g.configurable=!0,"value"in g&&(g.writable=!0),Object.defineProperty(m,w(g.key),g)}}function a(m,u,c){return u&&o(m.prototype,u),c&&o(m,c),Object.defineProperty(m,"prototype",{writable:!1}),m}function l(m,u){var c=typeof Symbol<"u"&&m[Symbol.iterator]||m["@@iterator"];if(!c){if(Array.isArray(m)||(c=L(m))||u){c&&(m=c);var g=0,v=function(){};return{s:v,n:function(){return g>=m.length?{done:!0}:{done:!1,value:m[g++]}},e:function(G){throw G},f:v}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
5
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var x,k=!0,O=!1;return{s:function(){c=c.call(m)},n:function(){var G=c.next();return k=G.done,G},e:function(G){O=!0,x=G},f:function(){try{k||c.return==null||c.return()}finally{if(O)throw x}}}}function h(){return h=typeof Reflect<"u"&&Reflect.get?Reflect.get.bind():function(m,u,c){var g=(function(x,k){for(;!{}.hasOwnProperty.call(x,k)&&(x=f(x))!==null;);return x})(m,u);if(g){var v=Object.getOwnPropertyDescriptor(g,u);return v.get?v.get.call(arguments.length<3?m:c):v.value}},h.apply(null,arguments)}function f(m){return f=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(u){return u.__proto__||Object.getPrototypeOf(u)},f(m)}function d(m,u){if(typeof u!="function"&&u!==null)throw new TypeError("Super expression must either be null or a function");m.prototype=Object.create(u&&u.prototype,{constructor:{value:m,writable:!0,configurable:!0}}),Object.defineProperty(m,"prototype",{writable:!1}),u&&y(m,u)}function p(){try{var m=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch{}return(p=function(){return!!m})()}function y(m,u){return y=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(c,g){return c.__proto__=g,c},y(m,u)}function _(m,u,c,g){var v=h(f(1&g?m.prototype:m),u,c);return 2&g&&typeof v=="function"?function(x){return v.apply(c,x)}:v}function E(m){return(function(u){if(Array.isArray(u))return e(u)})(m)||(function(u){if(typeof Symbol<"u"&&u[Symbol.iterator]!=null||u["@@iterator"]!=null)return Array.from(u)})(m)||L(m)||(function(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
6
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)})()}function w(m){var u=(function(c,g){if(typeof c!="object"||!c)return c;var v=c[Symbol.toPrimitive];if(v!==void 0){var x=v.call(c,g);if(typeof x!="object")return x;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(c)})(m,"string");return typeof u=="symbol"?u:u+""}function L(m,u){if(m){if(typeof m=="string")return e(m,u);var c={}.toString.call(m).slice(8,-1);return c==="Object"&&m.constructor&&(c=m.constructor.name),c==="Map"||c==="Set"?Array.from(m):c==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?e(m,u):void 0}}function b(m){var u=typeof Map=="function"?new Map:void 0;return b=function(c){if(c===null||!(function(v){try{return Function.toString.call(v).indexOf("[native code]")!==-1}catch{return typeof v=="function"}})(c))return c;if(typeof c!="function")throw new TypeError("Super expression must either be null or a function");if(u!==void 0){if(u.has(c))return u.get(c);u.set(c,g)}function g(){return r(c,arguments,f(this).constructor)}return g.prototype=Object.create(c.prototype,{constructor:{value:g,enumerable:!1,writable:!0,configurable:!0}}),y(g,c)},b(m)}var P=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"getEndCapStyle",value:function(){return this._endCapStyle}},{key:"isSingleSided",value:function(){return this._isSingleSided}},{key:"setQuadrantSegments",value:function(u){this._quadrantSegments=u,this._quadrantSegments===0&&(this._joinStyle=m.JOIN_BEVEL),this._quadrantSegments<0&&(this._joinStyle=m.JOIN_MITRE,this._mitreLimit=Math.abs(this._quadrantSegments)),u<=0&&(this._quadrantSegments=1),this._joinStyle!==m.JOIN_ROUND&&(this._quadrantSegments=m.DEFAULT_QUADRANT_SEGMENTS)}},{key:"getJoinStyle",value:function(){return this._joinStyle}},{key:"setJoinStyle",value:function(u){this._joinStyle=u}},{key:"setSimplifyFactor",value:function(u){this._simplifyFactor=u<0?0:u}},{key:"getSimplifyFactor",value:function(){return this._simplifyFactor}},{key:"getQuadrantSegments",value:function(){return this._quadrantSegments}},{key:"setEndCapStyle",value:function(u){this._endCapStyle=u}},{key:"getMitreLimit",value:function(){return this._mitreLimit}},{key:"setMitreLimit",value:function(u){this._mitreLimit=u}},{key:"setSingleSided",value:function(u){this._isSingleSided=u}}],[{key:"constructor_",value:function(){if(this._quadrantSegments=m.DEFAULT_QUADRANT_SEGMENTS,this._endCapStyle=m.CAP_ROUND,this._joinStyle=m.JOIN_ROUND,this._mitreLimit=m.DEFAULT_MITRE_LIMIT,this._isSingleSided=!1,this._simplifyFactor=m.DEFAULT_SIMPLIFY_FACTOR,arguments.length!==0){if(arguments.length===1){var u=arguments[0];this.setQuadrantSegments(u)}else if(arguments.length===2){var c=arguments[0],g=arguments[1];this.setQuadrantSegments(c),this.setEndCapStyle(g)}else if(arguments.length===4){var v=arguments[0],x=arguments[1],k=arguments[2],O=arguments[3];this.setQuadrantSegments(v),this.setEndCapStyle(x),this.setJoinStyle(k),this.setMitreLimit(O)}}}},{key:"bufferDistanceError",value:function(u){var c=Math.PI/2/u;return 1-Math.cos(c/2)}}])})();P.CAP_ROUND=1,P.CAP_FLAT=2,P.CAP_SQUARE=3,P.JOIN_ROUND=1,P.JOIN_MITRE=2,P.JOIN_BEVEL=3,P.DEFAULT_QUADRANT_SEGMENTS=8,P.DEFAULT_MITRE_LIMIT=5,P.DEFAULT_SIMPLIFY_FACTOR=.01;var N=(function(m){function u(c){var g;return s(this,u),(g=n(this,u,[c])).name=Object.keys({Exception:u})[0],g}return d(u,m),a(u,[{key:"toString",value:function(){return this.message}}])})(b(Error)),S=(function(m){function u(c){var g;return s(this,u),(g=n(this,u,[c])).name=Object.keys({IllegalArgumentException:u})[0],g}return d(u,m),a(u)})(N),C=(function(){return a((function m(){s(this,m)}),[{key:"filter",value:function(m){}}])})();function T(){}function I(){}function M(){}var R,A,F,$,z,D,B,U,j=(function(){return a((function m(){s(this,m)}),null,[{key:"equalsWithTolerance",value:function(m,u,c){return Math.abs(m-u)<=c}}])})(),K=(function(){return a((function m(u,c){s(this,m),this.low=c||0,this.high=u||0}),null,[{key:"toBinaryString",value:function(m){var u,c="";for(u=2147483648;u>0;u>>>=1)c+=(m.high&u)===u?"1":"0";for(u=2147483648;u>0;u>>>=1)c+=(m.low&u)===u?"1":"0";return c}}])})();function W(){}function J(){}W.NaN=NaN,W.isNaN=function(m){return Number.isNaN(m)},W.isInfinite=function(m){return!Number.isFinite(m)},W.MAX_VALUE=Number.MAX_VALUE,W.POSITIVE_INFINITY=Number.POSITIVE_INFINITY,W.NEGATIVE_INFINITY=Number.NEGATIVE_INFINITY,typeof Float64Array=="function"&&typeof Int32Array=="function"?(D=2146435072,B=new Float64Array(1),U=new Int32Array(B.buffer),W.doubleToLongBits=function(m){B[0]=m;var u=0|U[0],c=0|U[1];return(c&D)===D&&1048575&c&&u!==0&&(u=0,c=2146959360),new K(c,u)},W.longBitsToDouble=function(m){return U[0]=m.low,U[1]=m.high,B[0]}):(R=1023,A=Math.log2,F=Math.floor,$=Math.pow,z=(function(){for(var m=53;m>0;m--){var u=$(2,m)-1;if(F(A(u))+1===m)return u}return 0})(),W.doubleToLongBits=function(m){var u,c,g,v,x,k,O,G,X;if(m<0||1/m===Number.NEGATIVE_INFINITY?(k=1<<31,m=-m):k=0,m===0)return new K(G=k,X=0);if(m===1/0)return new K(G=2146435072|k,X=0);if(m!=m)return new K(G=2146959360,X=0);if(v=0,X=0,(u=F(m))>1)if(u<=z)(v=F(A(u)))<=20?(X=0,G=u<<20-v&1048575):(X=u%(c=$(2,g=v-20))<<32-g,G=u/c&1048575);else for(g=u,X=0;(g=F(c=g/2))!==0;)v++,X>>>=1,X|=(1&G)<<31,G>>>=1,c!==g&&(G|=524288);if(O=v+R,x=u===0,u=m-u,v<52&&u!==0)for(g=0;;){if((c=2*u)>=1?(u=c-1,x?(O--,x=!1):(g<<=1,g|=1,v++)):(u=c,x?--O==0&&(v++,x=!1):(g<<=1,v++)),v===20)G|=g,g=0;else if(v===52){X|=g;break}if(c===1){v<20?G|=g<<20-v:v<52&&(X|=g<<52-v);break}}return G|=O<<20,new K(G|=k,X)},W.longBitsToDouble=function(m){var u,c,g,v,x=m.high,k=m.low,O=x&1<<31?-1:1;for(g=((2146435072&x)>>20)-R,v=0,c=1<<19,u=1;u<=20;u++)x&c&&(v+=$(2,-u)),c>>>=1;for(c=1<<31,u=21;u<=52;u++)k&c&&(v+=$(2,-u)),c>>>=1;if(g===-1023){if(v===0)return 0*O;g=-1022}else{if(g===1024)return v===0?O/0:NaN;v+=1}return O*v*$(2,g)});var lt=(function(m){function u(c){var g;return s(this,u),(g=n(this,u,[c])).name=Object.keys({RuntimeException:u})[0],g}return d(u,m),a(u)})(N),ft=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,null,[{key:"constructor_",value:function(){if(arguments.length===0)lt.constructor_.call(this);else if(arguments.length===1){var c=arguments[0];lt.constructor_.call(this,c)}}}])})(lt),ct=(function(){function m(){s(this,m)}return a(m,null,[{key:"shouldNeverReachHere",value:function(){if(arguments.length===0)m.shouldNeverReachHere(null);else if(arguments.length===1){var u=arguments[0];throw new ft("Should never reach here"+(u!==null?": "+u:""))}}},{key:"isTrue",value:function(){if(arguments.length===1){var u=arguments[0];m.isTrue(u,null)}else if(arguments.length===2){var c=arguments[1];if(!arguments[0])throw c===null?new ft:new ft(c)}}},{key:"equals",value:function(){if(arguments.length===2){var u=arguments[0],c=arguments[1];m.equals(u,c,null)}else if(arguments.length===3){var g=arguments[0],v=arguments[1],x=arguments[2];if(!v.equals(g))throw new ft("Expected "+g+" but encountered "+v+(x!==null?": "+x:""))}}}])})(),gt=new ArrayBuffer(8),bt=new Float64Array(gt),It=new Int32Array(gt),Q=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"getM",value:function(){return W.NaN}},{key:"setOrdinate",value:function(u,c){switch(u){case m.X:this.x=c;break;case m.Y:this.y=c;break;case m.Z:this.setZ(c);break;default:throw new S("Invalid ordinate index: "+u)}}},{key:"equals2D",value:function(){if(arguments.length===1){var u=arguments[0];return this.x===u.x&&this.y===u.y}if(arguments.length===2){var c=arguments[0],g=arguments[1];return!!j.equalsWithTolerance(this.x,c.x,g)&&!!j.equalsWithTolerance(this.y,c.y,g)}}},{key:"setM",value:function(u){throw new S("Invalid ordinate index: "+m.M)}},{key:"getZ",value:function(){return this.z}},{key:"getOrdinate",value:function(u){switch(u){case m.X:return this.x;case m.Y:return this.y;case m.Z:return this.getZ()}throw new S("Invalid ordinate index: "+u)}},{key:"equals3D",value:function(u){return this.x===u.x&&this.y===u.y&&(this.getZ()===u.getZ()||W.isNaN(this.getZ())&&W.isNaN(u.getZ()))}},{key:"equals",value:function(u){return u instanceof m&&this.equals2D(u)}},{key:"equalInZ",value:function(u,c){return j.equalsWithTolerance(this.getZ(),u.getZ(),c)}},{key:"setX",value:function(u){this.x=u}},{key:"compareTo",value:function(u){var c=u;return this.x<c.x?-1:this.x>c.x?1:this.y<c.y?-1:this.y>c.y?1:0}},{key:"getX",value:function(){return this.x}},{key:"setZ",value:function(u){this.z=u}},{key:"clone",value:function(){try{return null}catch(u){if(u instanceof CloneNotSupportedException)return ct.shouldNeverReachHere("this shouldn't happen because this class is Cloneable"),null;throw u}}},{key:"copy",value:function(){return new m(this)}},{key:"toString",value:function(){return"("+this.x+", "+this.y+", "+this.getZ()+")"}},{key:"distance3D",value:function(u){var c=this.x-u.x,g=this.y-u.y,v=this.getZ()-u.getZ();return Math.sqrt(c*c+g*g+v*v)}},{key:"getY",value:function(){return this.y}},{key:"setY",value:function(u){this.y=u}},{key:"distance",value:function(u){var c=this.x-u.x,g=this.y-u.y;return Math.sqrt(c*c+g*g)}},{key:"hashCode",value:function(){var u=17;return u=37*(u=37*u+m.hashCode(this.x))+m.hashCode(this.y)}},{key:"setCoordinate",value:function(u){this.x=u.x,this.y=u.y,this.z=u.getZ()}},{key:"interfaces_",get:function(){return[T,I,M]}}],[{key:"constructor_",value:function(){if(this.x=null,this.y=null,this.z=null,arguments.length===0)m.constructor_.call(this,0,0);else if(arguments.length===1){var u=arguments[0];m.constructor_.call(this,u.x,u.y,u.getZ())}else if(arguments.length===2){var c=arguments[0],g=arguments[1];m.constructor_.call(this,c,g,m.NULL_ORDINATE)}else if(arguments.length===3){var v=arguments[0],x=arguments[1],k=arguments[2];this.x=v,this.y=x,this.z=k}}},{key:"hashCode",value:function(u){return bt[0]=u,It[0]^It[1]}}])})(),jt=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"compare",value:function(u,c){var g=m.compare(u.x,c.x);if(g!==0)return g;var v=m.compare(u.y,c.y);return v!==0?v:this._dimensionsToTest<=2?0:m.compare(u.getZ(),c.getZ())}},{key:"interfaces_",get:function(){return[J]}}],[{key:"constructor_",value:function(){if(this._dimensionsToTest=2,arguments.length===0)m.constructor_.call(this,2);else if(arguments.length===1){var u=arguments[0];if(u!==2&&u!==3)throw new S("only 2 or 3 dimensions may be specified");this._dimensionsToTest=u}}},{key:"compare",value:function(u,c){return u<c?-1:u>c?1:W.isNaN(u)?W.isNaN(c)?0:-1:W.isNaN(c)?1:0}}])})();Q.DimensionalComparator=jt,Q.NULL_ORDINATE=W.NaN,Q.X=0,Q.Y=1,Q.Z=2,Q.M=3;var Dt=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"getArea",value:function(){return this.getWidth()*this.getHeight()}},{key:"equals",value:function(u){if(!(u instanceof m))return!1;var c=u;return this.isNull()?c.isNull():this._maxx===c.getMaxX()&&this._maxy===c.getMaxY()&&this._minx===c.getMinX()&&this._miny===c.getMinY()}},{key:"intersection",value:function(u){if(this.isNull()||u.isNull()||!this.intersects(u))return new m;var c=this._minx>u._minx?this._minx:u._minx,g=this._miny>u._miny?this._miny:u._miny;return new m(c,this._maxx<u._maxx?this._maxx:u._maxx,g,this._maxy<u._maxy?this._maxy:u._maxy)}},{key:"isNull",value:function(){return this._maxx<this._minx}},{key:"getMaxX",value:function(){return this._maxx}},{key:"covers",value:function(){if(arguments.length===1){if(arguments[0]instanceof Q){var u=arguments[0];return this.covers(u.x,u.y)}if(arguments[0]instanceof m){var c=arguments[0];return!this.isNull()&&!c.isNull()&&c.getMinX()>=this._minx&&c.getMaxX()<=this._maxx&&c.getMinY()>=this._miny&&c.getMaxY()<=this._maxy}}else if(arguments.length===2){var g=arguments[0],v=arguments[1];return!this.isNull()&&g>=this._minx&&g<=this._maxx&&v>=this._miny&&v<=this._maxy}}},{key:"intersects",value:function(){if(arguments.length===1){if(arguments[0]instanceof m){var u=arguments[0];return!this.isNull()&&!u.isNull()&&!(u._minx>this._maxx||u._maxx<this._minx||u._miny>this._maxy||u._maxy<this._miny)}if(arguments[0]instanceof Q){var c=arguments[0];return this.intersects(c.x,c.y)}}else if(arguments.length===2){if(arguments[0]instanceof Q&&arguments[1]instanceof Q){var g=arguments[0],v=arguments[1];return!this.isNull()&&!((g.x<v.x?g.x:v.x)>this._maxx)&&!((g.x>v.x?g.x:v.x)<this._minx)&&!((g.y<v.y?g.y:v.y)>this._maxy)&&!((g.y>v.y?g.y:v.y)<this._miny)}if(typeof arguments[0]=="number"&&typeof arguments[1]=="number"){var x=arguments[0],k=arguments[1];return!this.isNull()&&!(x>this._maxx||x<this._minx||k>this._maxy||k<this._miny)}}}},{key:"getMinY",value:function(){return this._miny}},{key:"getDiameter",value:function(){if(this.isNull())return 0;var u=this.getWidth(),c=this.getHeight();return Math.sqrt(u*u+c*c)}},{key:"getMinX",value:function(){return this._minx}},{key:"expandToInclude",value:function(){if(arguments.length===1){if(arguments[0]instanceof Q){var u=arguments[0];this.expandToInclude(u.x,u.y)}else if(arguments[0]instanceof m){var c=arguments[0];if(c.isNull())return null;this.isNull()?(this._minx=c.getMinX(),this._maxx=c.getMaxX(),this._miny=c.getMinY(),this._maxy=c.getMaxY()):(c._minx<this._minx&&(this._minx=c._minx),c._maxx>this._maxx&&(this._maxx=c._maxx),c._miny<this._miny&&(this._miny=c._miny),c._maxy>this._maxy&&(this._maxy=c._maxy))}}else if(arguments.length===2){var g=arguments[0],v=arguments[1];this.isNull()?(this._minx=g,this._maxx=g,this._miny=v,this._maxy=v):(g<this._minx&&(this._minx=g),g>this._maxx&&(this._maxx=g),v<this._miny&&(this._miny=v),v>this._maxy&&(this._maxy=v))}}},{key:"minExtent",value:function(){if(this.isNull())return 0;var u=this.getWidth(),c=this.getHeight();return u<c?u:c}},{key:"getWidth",value:function(){return this.isNull()?0:this._maxx-this._minx}},{key:"compareTo",value:function(u){var c=u;return this.isNull()?c.isNull()?0:-1:c.isNull()?1:this._minx<c._minx?-1:this._minx>c._minx?1:this._miny<c._miny?-1:this._miny>c._miny?1:this._maxx<c._maxx?-1:this._maxx>c._maxx?1:this._maxy<c._maxy?-1:this._maxy>c._maxy?1:0}},{key:"translate",value:function(u,c){if(this.isNull())return null;this.init(this.getMinX()+u,this.getMaxX()+u,this.getMinY()+c,this.getMaxY()+c)}},{key:"copy",value:function(){return new m(this)}},{key:"toString",value:function(){return"Env["+this._minx+" : "+this._maxx+", "+this._miny+" : "+this._maxy+"]"}},{key:"setToNull",value:function(){this._minx=0,this._maxx=-1,this._miny=0,this._maxy=-1}},{key:"disjoint",value:function(u){return!(!this.isNull()&&!u.isNull())||u._minx>this._maxx||u._maxx<this._minx||u._miny>this._maxy||u._maxy<this._miny}},{key:"getHeight",value:function(){return this.isNull()?0:this._maxy-this._miny}},{key:"maxExtent",value:function(){if(this.isNull())return 0;var u=this.getWidth(),c=this.getHeight();return u>c?u:c}},{key:"expandBy",value:function(){if(arguments.length===1){var u=arguments[0];this.expandBy(u,u)}else if(arguments.length===2){var c=arguments[0],g=arguments[1];if(this.isNull())return null;this._minx-=c,this._maxx+=c,this._miny-=g,this._maxy+=g,(this._minx>this._maxx||this._miny>this._maxy)&&this.setToNull()}}},{key:"contains",value:function(){if(arguments.length===1){if(arguments[0]instanceof m){var u=arguments[0];return this.covers(u)}if(arguments[0]instanceof Q){var c=arguments[0];return this.covers(c)}}else if(arguments.length===2){var g=arguments[0],v=arguments[1];return this.covers(g,v)}}},{key:"centre",value:function(){return this.isNull()?null:new Q((this.getMinX()+this.getMaxX())/2,(this.getMinY()+this.getMaxY())/2)}},{key:"init",value:function(){if(arguments.length===0)this.setToNull();else if(arguments.length===1){if(arguments[0]instanceof Q){var u=arguments[0];this.init(u.x,u.x,u.y,u.y)}else if(arguments[0]instanceof m){var c=arguments[0];this._minx=c._minx,this._maxx=c._maxx,this._miny=c._miny,this._maxy=c._maxy}}else if(arguments.length===2){var g=arguments[0],v=arguments[1];this.init(g.x,v.x,g.y,v.y)}else if(arguments.length===4){var x=arguments[0],k=arguments[1],O=arguments[2],G=arguments[3];x<k?(this._minx=x,this._maxx=k):(this._minx=k,this._maxx=x),O<G?(this._miny=O,this._maxy=G):(this._miny=G,this._maxy=O)}}},{key:"getMaxY",value:function(){return this._maxy}},{key:"distance",value:function(u){if(this.intersects(u))return 0;var c=0;this._maxx<u._minx?c=u._minx-this._maxx:this._minx>u._maxx&&(c=this._minx-u._maxx);var g=0;return this._maxy<u._miny?g=u._miny-this._maxy:this._miny>u._maxy&&(g=this._miny-u._maxy),c===0?g:g===0?c:Math.sqrt(c*c+g*g)}},{key:"hashCode",value:function(){var u=17;return u=37*(u=37*(u=37*(u=37*u+Q.hashCode(this._minx))+Q.hashCode(this._maxx))+Q.hashCode(this._miny))+Q.hashCode(this._maxy)}},{key:"interfaces_",get:function(){return[T,M]}}],[{key:"constructor_",value:function(){if(this._minx=null,this._maxx=null,this._miny=null,this._maxy=null,arguments.length===0)this.init();else if(arguments.length===1){if(arguments[0]instanceof Q){var u=arguments[0];this.init(u.x,u.x,u.y,u.y)}else if(arguments[0]instanceof m){var c=arguments[0];this.init(c)}}else if(arguments.length===2){var g=arguments[0],v=arguments[1];this.init(g.x,v.x,g.y,v.y)}else if(arguments.length===4){var x=arguments[0],k=arguments[1],O=arguments[2],G=arguments[3];this.init(x,k,O,G)}}},{key:"intersects",value:function(){if(arguments.length===3){var u=arguments[0],c=arguments[1],g=arguments[2];return g.x>=(u.x<c.x?u.x:c.x)&&g.x<=(u.x>c.x?u.x:c.x)&&g.y>=(u.y<c.y?u.y:c.y)&&g.y<=(u.y>c.y?u.y:c.y)}if(arguments.length===4){var v=arguments[0],x=arguments[1],k=arguments[2],O=arguments[3],G=Math.min(k.x,O.x),X=Math.max(k.x,O.x),st=Math.min(v.x,x.x),at=Math.max(v.x,x.x);return!(st>X)&&!(at<G)&&(G=Math.min(k.y,O.y),X=Math.max(k.y,O.y),st=Math.min(v.y,x.y),at=Math.max(v.y,x.y),!(st>X)&&!(at<G))}}}])})(),wt=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"isGeometryCollection",value:function(){return this.getTypeCode()===m.TYPECODE_GEOMETRYCOLLECTION}},{key:"getFactory",value:function(){return this._factory}},{key:"getGeometryN",value:function(u){return this}},{key:"getArea",value:function(){return 0}},{key:"isRectangle",value:function(){return!1}},{key:"equalsExact",value:function(u){return this===u||this.equalsExact(u,0)}},{key:"geometryChanged",value:function(){this.apply(m.geometryChangedFilter)}},{key:"geometryChangedAction",value:function(){this._envelope=null}},{key:"equalsNorm",value:function(u){return u!==null&&this.norm().equalsExact(u.norm())}},{key:"getLength",value:function(){return 0}},{key:"getNumGeometries",value:function(){return 1}},{key:"compareTo",value:function(){var u;if(arguments.length===1){var c=arguments[0];return u=c,this.getTypeCode()!==u.getTypeCode()?this.getTypeCode()-u.getTypeCode():this.isEmpty()&&u.isEmpty()?0:this.isEmpty()?-1:u.isEmpty()?1:this.compareToSameClass(c)}if(arguments.length===2){var g=arguments[0],v=arguments[1];return u=g,this.getTypeCode()!==u.getTypeCode()?this.getTypeCode()-u.getTypeCode():this.isEmpty()&&u.isEmpty()?0:this.isEmpty()?-1:u.isEmpty()?1:this.compareToSameClass(g,v)}}},{key:"getUserData",value:function(){return this._userData}},{key:"getSRID",value:function(){return this._SRID}},{key:"getEnvelope",value:function(){return this.getFactory().toGeometry(this.getEnvelopeInternal())}},{key:"checkNotGeometryCollection",value:function(u){if(u.getTypeCode()===m.TYPECODE_GEOMETRYCOLLECTION)throw new S("This method does not support GeometryCollection arguments")}},{key:"equal",value:function(u,c,g){return g===0?u.equals(c):u.distance(c)<=g}},{key:"norm",value:function(){var u=this.copy();return u.normalize(),u}},{key:"reverse",value:function(){var u=this.reverseInternal();return this.envelope!=null&&(u.envelope=this.envelope.copy()),u.setSRID(this.getSRID()),u}},{key:"copy",value:function(){var u=this.copyInternal();return u.envelope=this._envelope==null?null:this._envelope.copy(),u._SRID=this._SRID,u._userData=this._userData,u}},{key:"getPrecisionModel",value:function(){return this._factory.getPrecisionModel()}},{key:"getEnvelopeInternal",value:function(){return this._envelope===null&&(this._envelope=this.computeEnvelopeInternal()),new Dt(this._envelope)}},{key:"setSRID",value:function(u){this._SRID=u}},{key:"setUserData",value:function(u){this._userData=u}},{key:"compare",value:function(u,c){for(var g=u.iterator(),v=c.iterator();g.hasNext()&&v.hasNext();){var x=g.next(),k=v.next(),O=x.compareTo(k);if(O!==0)return O}return g.hasNext()?1:v.hasNext()?-1:0}},{key:"hashCode",value:function(){return this.getEnvelopeInternal().hashCode()}},{key:"isEquivalentClass",value:function(u){return this.getClass()===u.getClass()}},{key:"isGeometryCollectionOrDerived",value:function(){return this.getTypeCode()===m.TYPECODE_GEOMETRYCOLLECTION||this.getTypeCode()===m.TYPECODE_MULTIPOINT||this.getTypeCode()===m.TYPECODE_MULTILINESTRING||this.getTypeCode()===m.TYPECODE_MULTIPOLYGON}},{key:"interfaces_",get:function(){return[I,T,M]}},{key:"getClass",value:function(){return m}}],[{key:"hasNonEmptyElements",value:function(u){for(var c=0;c<u.length;c++)if(!u[c].isEmpty())return!0;return!1}},{key:"hasNullElements",value:function(u){for(var c=0;c<u.length;c++)if(u[c]===null)return!0;return!1}}])})();wt.constructor_=function(m){m&&(this._envelope=null,this._userData=null,this._factory=m,this._SRID=m.getSRID())},wt.TYPECODE_POINT=0,wt.TYPECODE_MULTIPOINT=1,wt.TYPECODE_LINESTRING=2,wt.TYPECODE_LINEARRING=3,wt.TYPECODE_MULTILINESTRING=4,wt.TYPECODE_POLYGON=5,wt.TYPECODE_MULTIPOLYGON=6,wt.TYPECODE_GEOMETRYCOLLECTION=7,wt.TYPENAME_POINT="Point",wt.TYPENAME_MULTIPOINT="MultiPoint",wt.TYPENAME_LINESTRING="LineString",wt.TYPENAME_LINEARRING="LinearRing",wt.TYPENAME_MULTILINESTRING="MultiLineString",wt.TYPENAME_POLYGON="Polygon",wt.TYPENAME_MULTIPOLYGON="MultiPolygon",wt.TYPENAME_GEOMETRYCOLLECTION="GeometryCollection",wt.geometryChangedFilter={get interfaces_(){return[C]},filter:function(m){m.geometryChangedAction()}};var V=(function(){function m(){s(this,m)}return a(m,null,[{key:"toLocationSymbol",value:function(u){switch(u){case m.EXTERIOR:return"e";case m.BOUNDARY:return"b";case m.INTERIOR:return"i";case m.NONE:return"-"}throw new S("Unknown location value: "+u)}}])})();V.INTERIOR=0,V.BOUNDARY=1,V.EXTERIOR=2,V.NONE=-1;var Xt=(function(){return a((function m(){s(this,m)}),[{key:"add",value:function(){}},{key:"addAll",value:function(){}},{key:"isEmpty",value:function(){}},{key:"iterator",value:function(){}},{key:"size",value:function(){}},{key:"toArray",value:function(){}},{key:"remove",value:function(){}}])})(),Ut=(function(m){function u(c){var g;return s(this,u),(g=n(this,u,[c])).name=Object.keys({NoSuchElementException:u})[0],g}return d(u,m),a(u)})(N),Gt=(function(m){function u(c){var g;return s(this,u),(g=n(this,u,[c])).name=Object.keys({UnsupportedOperationException:u})[0],g}return d(u,m),a(u)})(N),dn=(function(m){function u(){return s(this,u),n(this,u,arguments)}return d(u,m),a(u,[{key:"contains",value:function(){}}])})(Xt),wn=(function(m){function u(c){var g;return s(this,u),(g=n(this,u)).map=new Map,c instanceof Xt&&g.addAll(c),g}return d(u,m),a(u,[{key:"contains",value:function(c){var g=c.hashCode?c.hashCode():c;return!!this.map.has(g)}},{key:"add",value:function(c){var g=c.hashCode?c.hashCode():c;return!this.map.has(g)&&!!this.map.set(g,c)}},{key:"addAll",value:function(c){var g,v=l(c);try{for(v.s();!(g=v.n()).done;){var x=g.value;this.add(x)}}catch(k){v.e(k)}finally{v.f()}return!0}},{key:"remove",value:function(){throw new Gt}},{key:"size",value:function(){return this.map.size}},{key:"isEmpty",value:function(){return this.map.size===0}},{key:"toArray",value:function(){return Array.from(this.map.values())}},{key:"iterator",value:function(){return new Ln(this.map)}},{key:Symbol.iterator,value:function(){return this.map}}])})(dn),Ln=(function(){return a((function m(u){s(this,m),this.iterator=u.values();var c=this.iterator.next(),g=c.done,v=c.value;this.done=g,this.value=v}),[{key:"next",value:function(){if(this.done)throw new Ut;var m=this.value,u=this.iterator.next(),c=u.done,g=u.value;return this.done=c,this.value=g,m}},{key:"hasNext",value:function(){return!this.done}},{key:"remove",value:function(){throw new Gt}}])})(),Et=(function(){function m(){s(this,m)}return a(m,null,[{key:"opposite",value:function(u){return u===m.LEFT?m.RIGHT:u===m.RIGHT?m.LEFT:u}}])})();Et.ON=0,Et.LEFT=1,Et.RIGHT=2;var Cl=(function(m){function u(c){var g;return s(this,u),(g=n(this,u,[c])).name=Object.keys({EmptyStackException:u})[0],g}return d(u,m),a(u)})(N),tt=(function(m){function u(c){var g;return s(this,u),(g=n(this,u,[c])).name=Object.keys({IndexOutOfBoundsException:u})[0],g}return d(u,m),a(u)})(N),et=(function(m){function u(){return s(this,u),n(this,u,arguments)}return d(u,m),a(u,[{key:"get",value:function(){}},{key:"set",value:function(){}},{key:"isEmpty",value:function(){}}])})(Xt),it=(function(m){function u(){var c;return s(this,u),(c=n(this,u)).array=[],c}return d(u,m),a(u,[{key:"add",value:function(c){return this.array.push(c),!0}},{key:"get",value:function(c){if(c<0||c>=this.size())throw new tt;return this.array[c]}},{key:"push",value:function(c){return this.array.push(c),c}},{key:"pop",value:function(){if(this.array.length===0)throw new Cl;return this.array.pop()}},{key:"peek",value:function(){if(this.array.length===0)throw new Cl;return this.array[this.array.length-1]}},{key:"empty",value:function(){return this.array.length===0}},{key:"isEmpty",value:function(){return this.empty()}},{key:"search",value:function(c){return this.array.indexOf(c)}},{key:"size",value:function(){return this.array.length}},{key:"toArray",value:function(){return this.array.slice()}}])})(et);function H(m,u){return m.interfaces_&&m.interfaces_.indexOf(u)>-1}var nt=(function(){return a((function m(u){s(this,m),this.str=u}),[{key:"append",value:function(m){this.str+=m}},{key:"setCharAt",value:function(m,u){this.str=this.str.substr(0,m)+u+this.str.substr(m+1)}},{key:"toString",value:function(){return this.str}}])})(),ot=(function(){function m(u){s(this,m),this.value=u}return a(m,[{key:"intValue",value:function(){return this.value}},{key:"compareTo",value:function(u){return this.value<u?-1:this.value>u?1:0}}],[{key:"compare",value:function(u,c){return u<c?-1:u>c?1:0}},{key:"isNan",value:function(u){return Number.isNaN(u)}},{key:"valueOf",value:function(u){return new m(u)}}])})(),ut=(function(){return a((function m(){s(this,m)}),null,[{key:"isWhitespace",value:function(m){return m<=32&&m>=0||m===127}},{key:"toUpperCase",value:function(m){return m.toUpperCase()}}])})(),rt=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"le",value:function(u){return this._hi<u._hi||this._hi===u._hi&&this._lo<=u._lo}},{key:"extractSignificantDigits",value:function(u,c){var g=this.abs(),v=m.magnitude(g._hi),x=m.TEN.pow(v);(g=g.divide(x)).gt(m.TEN)?(g=g.divide(m.TEN),v+=1):g.lt(m.ONE)&&(g=g.multiply(m.TEN),v-=1);for(var k=v+1,O=new nt,G=m.MAX_PRINT_DIGITS-1,X=0;X<=G;X++){u&&X===k&&O.append(".");var st=Math.trunc(g._hi);if(st<0)break;var at=!1,mt=0;st>9?(at=!0,mt="9"):mt="0"+st,O.append(mt),g=g.subtract(m.valueOf(st)).multiply(m.TEN),at&&g.selfAdd(m.TEN);var Pt=!0,Ft=m.magnitude(g._hi);if(Ft<0&&Math.abs(Ft)>=G-X&&(Pt=!1),!Pt)break}return c[0]=v,O.toString()}},{key:"sqr",value:function(){return this.multiply(this)}},{key:"doubleValue",value:function(){return this._hi+this._lo}},{key:"subtract",value:function(){if(arguments[0]instanceof m){var u=arguments[0];return this.add(u.negate())}if(typeof arguments[0]=="number"){var c=arguments[0];return this.add(-c)}}},{key:"equals",value:function(){if(arguments.length===1&&arguments[0]instanceof m){var u=arguments[0];return this._hi===u._hi&&this._lo===u._lo}}},{key:"isZero",value:function(){return this._hi===0&&this._lo===0}},{key:"selfSubtract",value:function(){if(arguments[0]instanceof m){var u=arguments[0];return this.isNaN()?this:this.selfAdd(-u._hi,-u._lo)}if(typeof arguments[0]=="number"){var c=arguments[0];return this.isNaN()?this:this.selfAdd(-c,0)}}},{key:"getSpecialNumberString",value:function(){return this.isZero()?"0.0":this.isNaN()?"NaN ":null}},{key:"min",value:function(u){return this.le(u)?this:u}},{key:"selfDivide",value:function(){if(arguments.length===1){if(arguments[0]instanceof m){var u=arguments[0];return this.selfDivide(u._hi,u._lo)}if(typeof arguments[0]=="number"){var c=arguments[0];return this.selfDivide(c,0)}}else if(arguments.length===2){var g,v,x,k,O=arguments[0],G=arguments[1],X=null,st=null,at=null,mt=null;return x=this._hi/O,mt=(X=(at=m.SPLIT*x)-(X=at-x))*(st=(mt=m.SPLIT*O)-(st=mt-O))-(k=x*O)+X*(v=O-st)+(g=x-X)*st+g*v,mt=x+(at=(this._hi-k-mt+this._lo-x*G)/O),this._hi=mt,this._lo=x-mt+at,this}}},{key:"dump",value:function(){return"DD<"+this._hi+", "+this._lo+">"}},{key:"divide",value:function(){if(arguments[0]instanceof m){var u,c,g,v,x=arguments[0],k=null,O=null,G=null,X=null;return u=(g=this._hi/x._hi)-(k=(G=m.SPLIT*g)-(k=G-g)),X=k*(O=(X=m.SPLIT*x._hi)-(O=X-x._hi))-(v=g*x._hi)+k*(c=x._hi-O)+u*O+u*c,new m(X=g+(G=(this._hi-v-X+this._lo-g*x._lo)/x._hi),g-X+G)}if(typeof arguments[0]=="number"){var st=arguments[0];return W.isNaN(st)?m.createNaN():m.copy(this).selfDivide(st,0)}}},{key:"ge",value:function(u){return this._hi>u._hi||this._hi===u._hi&&this._lo>=u._lo}},{key:"pow",value:function(u){if(u===0)return m.valueOf(1);var c=new m(this),g=m.valueOf(1),v=Math.abs(u);if(v>1)for(;v>0;)v%2==1&&g.selfMultiply(c),(v/=2)>0&&(c=c.sqr());else g=c;return u<0?g.reciprocal():g}},{key:"ceil",value:function(){if(this.isNaN())return m.NaN;var u=Math.ceil(this._hi),c=0;return u===this._hi&&(c=Math.ceil(this._lo)),new m(u,c)}},{key:"compareTo",value:function(u){var c=u;return this._hi<c._hi?-1:this._hi>c._hi?1:this._lo<c._lo?-1:this._lo>c._lo?1:0}},{key:"rint",value:function(){return this.isNaN()?this:this.add(.5).floor()}},{key:"setValue",value:function(){if(arguments[0]instanceof m){var u=arguments[0];return this.init(u),this}if(typeof arguments[0]=="number"){var c=arguments[0];return this.init(c),this}}},{key:"max",value:function(u){return this.ge(u)?this:u}},{key:"sqrt",value:function(){if(this.isZero())return m.valueOf(0);if(this.isNegative())return m.NaN;var u=1/Math.sqrt(this._hi),c=this._hi*u,g=m.valueOf(c),v=this.subtract(g.sqr())._hi*(.5*u);return g.add(v)}},{key:"selfAdd",value:function(){if(arguments.length===1){if(arguments[0]instanceof m){var u=arguments[0];return this.selfAdd(u._hi,u._lo)}if(typeof arguments[0]=="number"){var c,g,v,x,k,O=arguments[0],G=null;return G=(v=this._hi+O)-(x=v-this._hi),g=(k=(G=O-x+(this._hi-G))+this._lo)+(v-(c=v+k)),this._hi=c+g,this._lo=g+(c-this._hi),this}}else if(arguments.length===2){var X,st,at,mt,Pt=arguments[0],Ft=arguments[1],qt=null,fe=null,le=null;at=this._hi+Pt,st=this._lo+Ft,fe=at-(le=at-this._hi),qt=st-(mt=st-this._lo);var ke=(X=at+(le=(fe=Pt-le+(this._hi-fe))+st))+(le=(qt=Ft-mt+(this._lo-qt))+(le+(at-X))),xn=le+(X-ke);return this._hi=ke,this._lo=xn,this}}},{key:"selfMultiply",value:function(){if(arguments.length===1){if(arguments[0]instanceof m){var u=arguments[0];return this.selfMultiply(u._hi,u._lo)}if(typeof arguments[0]=="number"){var c=arguments[0];return this.selfMultiply(c,0)}}else if(arguments.length===2){var g,v,x=arguments[0],k=arguments[1],O=null,G=null,X=null,st=null;O=(X=m.SPLIT*this._hi)-this._hi,st=m.SPLIT*x,O=X-O,g=this._hi-O,G=st-x;var at=(X=this._hi*x)+(st=O*(G=st-G)-X+O*(v=x-G)+g*G+g*v+(this._hi*k+this._lo*x)),mt=st+(O=X-at);return this._hi=at,this._lo=mt,this}}},{key:"selfSqr",value:function(){return this.selfMultiply(this)}},{key:"floor",value:function(){if(this.isNaN())return m.NaN;var u=Math.floor(this._hi),c=0;return u===this._hi&&(c=Math.floor(this._lo)),new m(u,c)}},{key:"negate",value:function(){return this.isNaN()?this:new m(-this._hi,-this._lo)}},{key:"clone",value:function(){try{return null}catch(u){if(u instanceof CloneNotSupportedException)return null;throw u}}},{key:"multiply",value:function(){if(arguments[0]instanceof m){var u=arguments[0];return u.isNaN()?m.createNaN():m.copy(this).selfMultiply(u)}if(typeof arguments[0]=="number"){var c=arguments[0];return W.isNaN(c)?m.createNaN():m.copy(this).selfMultiply(c,0)}}},{key:"isNaN",value:function(){return W.isNaN(this._hi)}},{key:"intValue",value:function(){return Math.trunc(this._hi)}},{key:"toString",value:function(){var u=m.magnitude(this._hi);return u>=-3&&u<=20?this.toStandardNotation():this.toSciNotation()}},{key:"toStandardNotation",value:function(){var u=this.getSpecialNumberString();if(u!==null)return u;var c=new Array(1).fill(null),g=this.extractSignificantDigits(!0,c),v=c[0]+1,x=g;if(g.charAt(0)===".")x="0"+g;else if(v<0)x="0."+m.stringOfChar("0",-v)+g;else if(g.indexOf(".")===-1){var k=v-g.length;x=g+m.stringOfChar("0",k)+".0"}return this.isNegative()?"-"+x:x}},{key:"reciprocal",value:function(){var u,c,g,v,x=null,k=null,O=null,G=null;u=(g=1/this._hi)-(x=(O=m.SPLIT*g)-(x=O-g)),k=(G=m.SPLIT*this._hi)-this._hi;var X=g+(O=(1-(v=g*this._hi)-(G=x*(k=G-k)-v+x*(c=this._hi-k)+u*k+u*c)-g*this._lo)/this._hi);return new m(X,g-X+O)}},{key:"toSciNotation",value:function(){if(this.isZero())return m.SCI_NOT_ZERO;var u=this.getSpecialNumberString();if(u!==null)return u;var c=new Array(1).fill(null),g=this.extractSignificantDigits(!1,c),v=m.SCI_NOT_EXPONENT_CHAR+c[0];if(g.charAt(0)==="0")throw new IllegalStateException("Found leading zero: "+g);var x="";g.length>1&&(x=g.substring(1));var k=g.charAt(0)+"."+x;return this.isNegative()?"-"+k+v:k+v}},{key:"abs",value:function(){return this.isNaN()?m.NaN:this.isNegative()?this.negate():new m(this)}},{key:"isPositive",value:function(){return this._hi>0||this._hi===0&&this._lo>0}},{key:"lt",value:function(u){return this._hi<u._hi||this._hi===u._hi&&this._lo<u._lo}},{key:"add",value:function(){if(arguments[0]instanceof m){var u=arguments[0];return m.copy(this).selfAdd(u)}if(typeof arguments[0]=="number"){var c=arguments[0];return m.copy(this).selfAdd(c)}}},{key:"init",value:function(){if(arguments.length===1){if(typeof arguments[0]=="number"){var u=arguments[0];this._hi=u,this._lo=0}else if(arguments[0]instanceof m){var c=arguments[0];this._hi=c._hi,this._lo=c._lo}}else if(arguments.length===2){var g=arguments[0],v=arguments[1];this._hi=g,this._lo=v}}},{key:"gt",value:function(u){return this._hi>u._hi||this._hi===u._hi&&this._lo>u._lo}},{key:"isNegative",value:function(){return this._hi<0||this._hi===0&&this._lo<0}},{key:"trunc",value:function(){return this.isNaN()?m.NaN:this.isPositive()?this.floor():this.ceil()}},{key:"signum",value:function(){return this._hi>0?1:this._hi<0?-1:this._lo>0?1:this._lo<0?-1:0}},{key:"interfaces_",get:function(){return[M,T,I]}}],[{key:"constructor_",value:function(){if(this._hi=0,this._lo=0,arguments.length===0)this.init(0);else if(arguments.length===1){if(typeof arguments[0]=="number"){var u=arguments[0];this.init(u)}else if(arguments[0]instanceof m){var c=arguments[0];this.init(c)}else if(typeof arguments[0]=="string"){var g=arguments[0];m.constructor_.call(this,m.parse(g))}}else if(arguments.length===2){var v=arguments[0],x=arguments[1];this.init(v,x)}}},{key:"determinant",value:function(){if(typeof arguments[3]=="number"&&typeof arguments[2]=="number"&&typeof arguments[0]=="number"&&typeof arguments[1]=="number"){var u=arguments[0],c=arguments[1],g=arguments[2],v=arguments[3];return m.determinant(m.valueOf(u),m.valueOf(c),m.valueOf(g),m.valueOf(v))}if(arguments[3]instanceof m&&arguments[2]instanceof m&&arguments[0]instanceof m&&arguments[1]instanceof m){var x=arguments[1],k=arguments[2],O=arguments[3];return arguments[0].multiply(O).selfSubtract(x.multiply(k))}}},{key:"sqr",value:function(u){return m.valueOf(u).selfMultiply(u)}},{key:"valueOf",value:function(){if(typeof arguments[0]=="string"){var u=arguments[0];return m.parse(u)}if(typeof arguments[0]=="number")return new m(arguments[0])}},{key:"sqrt",value:function(u){return m.valueOf(u).sqrt()}},{key:"parse",value:function(u){for(var c=0,g=u.length;ut.isWhitespace(u.charAt(c));)c++;var v=!1;if(c<g){var x=u.charAt(c);x!=="-"&&x!=="+"||(c++,x==="-"&&(v=!0))}for(var k=new m,O=0,G=0,X=0,st=!1;!(c>=g);){var at=u.charAt(c);if(c++,ut.isDigit(at)){var mt=at-"0";k.selfMultiply(m.TEN),k.selfAdd(mt),O++}else{if(at!=="."){if(at==="e"||at==="E"){var Pt=u.substring(c);try{X=ot.parseInt(Pt)}catch(ke){throw ke instanceof NumberFormatException?new NumberFormatException("Invalid exponent "+Pt+" in string "+u):ke}break}throw new NumberFormatException("Unexpected character '"+at+"' at position "+c+" in string "+u)}G=O,st=!0}}var Ft=k;st||(G=O);var qt=O-G-X;if(qt===0)Ft=k;else if(qt>0){var fe=m.TEN.pow(qt);Ft=k.divide(fe)}else if(qt<0){var le=m.TEN.pow(-qt);Ft=k.multiply(le)}return v?Ft.negate():Ft}},{key:"createNaN",value:function(){return new m(W.NaN,W.NaN)}},{key:"copy",value:function(u){return new m(u)}},{key:"magnitude",value:function(u){var c=Math.abs(u),g=Math.log(c)/Math.log(10),v=Math.trunc(Math.floor(g));return 10*Math.pow(10,v)<=c&&(v+=1),v}},{key:"stringOfChar",value:function(u,c){for(var g=new nt,v=0;v<c;v++)g.append(u);return g.toString()}}])})();rt.PI=new rt(3.141592653589793,12246467991473532e-32),rt.TWO_PI=new rt(6.283185307179586,24492935982947064e-32),rt.PI_2=new rt(1.5707963267948966,6123233995736766e-32),rt.E=new rt(2.718281828459045,14456468917292502e-32),rt.NaN=new rt(W.NaN,W.NaN),rt.EPS=123259516440783e-46,rt.SPLIT=134217729,rt.MAX_PRINT_DIGITS=32,rt.TEN=rt.valueOf(10),rt.ONE=rt.valueOf(1),rt.SCI_NOT_EXPONENT_CHAR="E",rt.SCI_NOT_ZERO="0.0E0";var Ct=(function(){function m(){s(this,m)}return a(m,null,[{key:"orientationIndex",value:function(u,c,g){var v=m.orientationIndexFilter(u,c,g);if(v<=1)return v;var x=rt.valueOf(c.x).selfAdd(-u.x),k=rt.valueOf(c.y).selfAdd(-u.y),O=rt.valueOf(g.x).selfAdd(-c.x),G=rt.valueOf(g.y).selfAdd(-c.y);return x.selfMultiply(G).selfSubtract(k.selfMultiply(O)).signum()}},{key:"signOfDet2x2",value:function(){if(arguments[3]instanceof rt&&arguments[2]instanceof rt&&arguments[0]instanceof rt&&arguments[1]instanceof rt){var u=arguments[1],c=arguments[2],g=arguments[3];return arguments[0].multiply(g).selfSubtract(u.multiply(c)).signum()}if(typeof arguments[3]=="number"&&typeof arguments[2]=="number"&&typeof arguments[0]=="number"&&typeof arguments[1]=="number"){var v=arguments[0],x=arguments[1],k=arguments[2],O=arguments[3],G=rt.valueOf(v),X=rt.valueOf(x),st=rt.valueOf(k),at=rt.valueOf(O);return G.multiply(at).selfSubtract(X.multiply(st)).signum()}}},{key:"intersection",value:function(u,c,g,v){var x=new rt(u.y).selfSubtract(c.y),k=new rt(c.x).selfSubtract(u.x),O=new rt(u.x).selfMultiply(c.y).selfSubtract(new rt(c.x).selfMultiply(u.y)),G=new rt(g.y).selfSubtract(v.y),X=new rt(v.x).selfSubtract(g.x),st=new rt(g.x).selfMultiply(v.y).selfSubtract(new rt(v.x).selfMultiply(g.y)),at=k.multiply(st).selfSubtract(X.multiply(O)),mt=G.multiply(O).selfSubtract(x.multiply(st)),Pt=x.multiply(X).selfSubtract(G.multiply(k)),Ft=at.selfDivide(Pt).doubleValue(),qt=mt.selfDivide(Pt).doubleValue();return W.isNaN(Ft)||W.isInfinite(Ft)||W.isNaN(qt)||W.isInfinite(qt)?null:new Q(Ft,qt)}},{key:"orientationIndexFilter",value:function(u,c,g){var v=null,x=(u.x-g.x)*(c.y-g.y),k=(u.y-g.y)*(c.x-g.x),O=x-k;if(x>0){if(k<=0)return m.signum(O);v=x+k}else{if(!(x<0)||k>=0)return m.signum(O);v=-x-k}var G=m.DP_SAFE_EPSILON*v;return O>=G||-O>=G?m.signum(O):2}},{key:"signum",value:function(u){return u>0?1:u<0?-1:0}}])})();Ct.DP_SAFE_EPSILON=1e-15;var kt=(function(){return a((function m(){s(this,m)}),[{key:"getM",value:function(m){if(this.hasM()){var u=this.getDimension()-this.getMeasures();return this.getOrdinate(m,u)}return W.NaN}},{key:"setOrdinate",value:function(m,u,c){}},{key:"getZ",value:function(m){return this.hasZ()?this.getOrdinate(m,2):W.NaN}},{key:"size",value:function(){}},{key:"getOrdinate",value:function(m,u){}},{key:"getCoordinate",value:function(){}},{key:"getCoordinateCopy",value:function(m){}},{key:"createCoordinate",value:function(){}},{key:"getDimension",value:function(){}},{key:"hasM",value:function(){return this.getMeasures()>0}},{key:"getX",value:function(m){}},{key:"hasZ",value:function(){return this.getDimension()-this.getMeasures()>2}},{key:"getMeasures",value:function(){return 0}},{key:"expandEnvelope",value:function(m){}},{key:"copy",value:function(){}},{key:"getY",value:function(m){}},{key:"toCoordinateArray",value:function(){}},{key:"interfaces_",get:function(){return[I]}}])})();kt.X=0,kt.Y=1,kt.Z=2,kt.M=3;var At=(function(){function m(){s(this,m)}return a(m,null,[{key:"index",value:function(u,c,g){return Ct.orientationIndex(u,c,g)}},{key:"isCCW",value:function(){if(arguments[0]instanceof Array){var u=arguments[0],c=u.length-1;if(c<3)throw new S("Ring has fewer than 4 points, so orientation cannot be determined");for(var g=u[0],v=0,x=1;x<=c;x++){var k=u[x];k.y>g.y&&(g=k,v=x)}var O=v;do(O-=1)<0&&(O=c);while(u[O].equals2D(g)&&O!==v);var G=v;do G=(G+1)%c;while(u[G].equals2D(g)&&G!==v);var X=u[O],st=u[G];if(X.equals2D(g)||st.equals2D(g)||X.equals2D(st))return!1;var at=m.index(X,g,st);return at===0?X.x>st.x:at>0}if(H(arguments[0],kt)){var mt=arguments[0],Pt=mt.size()-1;if(Pt<3)throw new S("Ring has fewer than 4 points, so orientation cannot be determined");for(var Ft=mt.getCoordinate(0),qt=0,fe=1;fe<=Pt;fe++){var le=mt.getCoordinate(fe);le.y>Ft.y&&(Ft=le,qt=fe)}var ke=null,xn=qt;do(xn-=1)<0&&(xn=Pt),ke=mt.getCoordinate(xn);while(ke.equals2D(Ft)&&xn!==qt);var Pn=null,ao=qt;do ao=(ao+1)%Pt,Pn=mt.getCoordinate(ao);while(Pn.equals2D(Ft)&&ao!==qt);if(ke.equals2D(Ft)||Pn.equals2D(Ft)||ke.equals2D(Pn))return!1;var ql=m.index(ke,Ft,Pn);return ql===0?ke.x>Pn.x:ql>0}}}])})();At.CLOCKWISE=-1,At.RIGHT=At.CLOCKWISE,At.COUNTERCLOCKWISE=1,At.LEFT=At.COUNTERCLOCKWISE,At.COLLINEAR=0,At.STRAIGHT=At.COLLINEAR;var he=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"getCoordinate",value:function(){return this._minCoord}},{key:"getRightmostSide",value:function(m,u){var c=this.getRightmostSideOfSegment(m,u);return c<0&&(c=this.getRightmostSideOfSegment(m,u-1)),c<0&&(this._minCoord=null,this.checkForRightmostCoordinate(m)),c}},{key:"findRightmostEdgeAtVertex",value:function(){var m=this._minDe.getEdge().getCoordinates();ct.isTrue(this._minIndex>0&&this._minIndex<m.length,"rightmost point expected to be interior vertex of edge");var u=m[this._minIndex-1],c=m[this._minIndex+1],g=At.index(this._minCoord,c,u),v=!1;(u.y<this._minCoord.y&&c.y<this._minCoord.y&&g===At.COUNTERCLOCKWISE||u.y>this._minCoord.y&&c.y>this._minCoord.y&&g===At.CLOCKWISE)&&(v=!0),v&&(this._minIndex=this._minIndex-1)}},{key:"getRightmostSideOfSegment",value:function(m,u){var c=m.getEdge().getCoordinates();if(u<0||u+1>=c.length||c[u].y===c[u+1].y)return-1;var g=Et.LEFT;return c[u].y<c[u+1].y&&(g=Et.RIGHT),g}},{key:"getEdge",value:function(){return this._orientedDe}},{key:"checkForRightmostCoordinate",value:function(m){for(var u=m.getEdge().getCoordinates(),c=0;c<u.length-1;c++)(this._minCoord===null||u[c].x>this._minCoord.x)&&(this._minDe=m,this._minIndex=c,this._minCoord=u[c])}},{key:"findRightmostEdgeAtNode",value:function(){var m=this._minDe.getNode().getEdges();this._minDe=m.getRightmostEdge(),this._minDe.isForward()||(this._minDe=this._minDe.getSym(),this._minIndex=this._minDe.getEdge().getCoordinates().length-1)}},{key:"findEdge",value:function(m){for(var u=m.iterator();u.hasNext();){var c=u.next();c.isForward()&&this.checkForRightmostCoordinate(c)}ct.isTrue(this._minIndex!==0||this._minCoord.equals(this._minDe.getCoordinate()),"inconsistency in rightmost processing"),this._minIndex===0?this.findRightmostEdgeAtNode():this.findRightmostEdgeAtVertex(),this._orientedDe=this._minDe,this.getRightmostSide(this._minDe,this._minIndex)===Et.LEFT&&(this._orientedDe=this._minDe.getSym())}}],[{key:"constructor_",value:function(){this._minIndex=-1,this._minCoord=null,this._minDe=null,this._orientedDe=null}}])})(),Ae=(function(m){function u(c,g){var v;return s(this,u),(v=n(this,u,[g?c+" [ "+g+" ]":c])).pt=g?new Q(g):void 0,v.name=Object.keys({TopologyException:u})[0],v}return d(u,m),a(u,[{key:"getCoordinate",value:function(){return this.pt}}])})(lt),Cn=(function(){return a((function m(){s(this,m),this.array=[]}),[{key:"addLast",value:function(m){this.array.push(m)}},{key:"removeFirst",value:function(){return this.array.shift()}},{key:"isEmpty",value:function(){return this.array.length===0}}])})(),Bt=(function(m){function u(c){var g;return s(this,u),(g=n(this,u)).array=[],c instanceof Xt&&g.addAll(c),g}return d(u,m),a(u,[{key:"interfaces_",get:function(){return[et,Xt]}},{key:"ensureCapacity",value:function(){}},{key:"add",value:function(c){return arguments.length===1?this.array.push(c):this.array.splice(arguments[0],0,arguments[1]),!0}},{key:"clear",value:function(){this.array=[]}},{key:"addAll",value:function(c){var g,v=l(c);try{for(v.s();!(g=v.n()).done;){var x=g.value;this.array.push(x)}}catch(k){v.e(k)}finally{v.f()}}},{key:"set",value:function(c,g){var v=this.array[c];return this.array[c]=g,v}},{key:"iterator",value:function(){return new Pl(this)}},{key:"get",value:function(c){if(c<0||c>=this.size())throw new tt;return this.array[c]}},{key:"isEmpty",value:function(){return this.array.length===0}},{key:"sort",value:function(c){c?this.array.sort((function(g,v){return c.compare(g,v)})):this.array.sort()}},{key:"size",value:function(){return this.array.length}},{key:"toArray",value:function(){return this.array.slice()}},{key:"remove",value:function(c){for(var g=0,v=this.array.length;g<v;g++)if(this.array[g]===c)return!!this.array.splice(g,1);return!1}},{key:Symbol.iterator,value:function(){return this.array.values()}}])})(et),Pl=(function(){return a((function m(u){s(this,m),this.arrayList=u,this.position=0}),[{key:"next",value:function(){if(this.position===this.arrayList.size())throw new Ut;return this.arrayList.get(this.position++)}},{key:"hasNext",value:function(){return this.position<this.arrayList.size()}},{key:"set",value:function(m){return this.arrayList.set(this.position-1,m)}},{key:"remove",value:function(){this.arrayList.remove(this.arrayList.get(this.position))}}])})(),kl=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"clearVisitedEdges",value:function(){for(var m=this._dirEdgeList.iterator();m.hasNext();)m.next().setVisited(!1)}},{key:"getRightmostCoordinate",value:function(){return this._rightMostCoord}},{key:"computeNodeDepth",value:function(m){for(var u=null,c=m.getEdges().iterator();c.hasNext();){var g=c.next();if(g.isVisited()||g.getSym().isVisited()){u=g;break}}if(u===null)throw new Ae("unable to find edge to compute depths at "+m.getCoordinate());m.getEdges().computeDepths(u);for(var v=m.getEdges().iterator();v.hasNext();){var x=v.next();x.setVisited(!0),this.copySymDepths(x)}}},{key:"computeDepth",value:function(m){this.clearVisitedEdges();var u=this._finder.getEdge();u.getNode(),u.getLabel(),u.setEdgeDepths(Et.RIGHT,m),this.copySymDepths(u),this.computeDepths(u)}},{key:"create",value:function(m){this.addReachable(m),this._finder.findEdge(this._dirEdgeList),this._rightMostCoord=this._finder.getCoordinate()}},{key:"findResultEdges",value:function(){for(var m=this._dirEdgeList.iterator();m.hasNext();){var u=m.next();u.getDepth(Et.RIGHT)>=1&&u.getDepth(Et.LEFT)<=0&&!u.isInteriorAreaEdge()&&u.setInResult(!0)}}},{key:"computeDepths",value:function(m){var u=new wn,c=new Cn,g=m.getNode();for(c.addLast(g),u.add(g),m.setVisited(!0);!c.isEmpty();){var v=c.removeFirst();u.add(v),this.computeNodeDepth(v);for(var x=v.getEdges().iterator();x.hasNext();){var k=x.next().getSym();if(!k.isVisited()){var O=k.getNode();u.contains(O)||(c.addLast(O),u.add(O))}}}}},{key:"compareTo",value:function(m){var u=m;return this._rightMostCoord.x<u._rightMostCoord.x?-1:this._rightMostCoord.x>u._rightMostCoord.x?1:0}},{key:"getEnvelope",value:function(){if(this._env===null){for(var m=new Dt,u=this._dirEdgeList.iterator();u.hasNext();)for(var c=u.next().getEdge().getCoordinates(),g=0;g<c.length-1;g++)m.expandToInclude(c[g]);this._env=m}return this._env}},{key:"addReachable",value:function(m){var u=new it;for(u.add(m);!u.empty();){var c=u.pop();this.add(c,u)}}},{key:"copySymDepths",value:function(m){var u=m.getSym();u.setDepth(Et.LEFT,m.getDepth(Et.RIGHT)),u.setDepth(Et.RIGHT,m.getDepth(Et.LEFT))}},{key:"add",value:function(m,u){m.setVisited(!0),this._nodes.add(m);for(var c=m.getEdges().iterator();c.hasNext();){var g=c.next();this._dirEdgeList.add(g);var v=g.getSym().getNode();v.isVisited()||u.push(v)}}},{key:"getNodes",value:function(){return this._nodes}},{key:"getDirectedEdges",value:function(){return this._dirEdgeList}},{key:"interfaces_",get:function(){return[T]}}],[{key:"constructor_",value:function(){this._finder=null,this._dirEdgeList=new Bt,this._nodes=new Bt,this._rightMostCoord=null,this._env=null,this._finder=new he}}])})(),Tl=(function(){return a((function m(){s(this,m)}),null,[{key:"intersection",value:function(m,u,c,g){var v=m.x<u.x?m.x:u.x,x=m.y<u.y?m.y:u.y,k=m.x>u.x?m.x:u.x,O=m.y>u.y?m.y:u.y,G=c.x<g.x?c.x:g.x,X=c.y<g.y?c.y:g.y,st=c.x>g.x?c.x:g.x,at=c.y>g.y?c.y:g.y,mt=((v>G?v:G)+(k<st?k:st))/2,Pt=((x>X?x:X)+(O<at?O:at))/2,Ft=m.x-mt,qt=m.y-Pt,fe=u.x-mt,le=u.y-Pt,ke=c.x-mt,xn=c.y-Pt,Pn=g.x-mt,ao=g.y-Pt,ql=qt-le,Py=fe-Ft,ky=Ft*le-fe*qt,Ty=xn-ao,Ry=Pn-ke,Ay=ke*ao-Pn*xn,Oy=ql*Ry-Ty*Py,Gd=(Py*Ay-Ry*ky)/Oy,Bd=(Ty*ky-ql*Ay)/Oy;return W.isNaN(Gd)||W.isInfinite(Gd)||W.isNaN(Bd)||W.isInfinite(Bd)?null:new Q(Gd+mt,Bd+Pt)}}])})(),Ti=(function(){return a((function m(){s(this,m)}),null,[{key:"arraycopy",value:function(m,u,c,g,v){for(var x=0,k=u;k<u+v;k++)c[g+x]=m[k],x++}},{key:"getProperty",value:function(m){return{"line.separator":`
|
|
7
|
+
`}[m]}}])})(),Rl=(function(){function m(){s(this,m)}return a(m,null,[{key:"log10",value:function(u){var c=Math.log(u);return W.isInfinite(c)||W.isNaN(c)?c:c/m.LOG_10}},{key:"min",value:function(u,c,g,v){var x=u;return c<x&&(x=c),g<x&&(x=g),v<x&&(x=v),x}},{key:"clamp",value:function(){if(typeof arguments[2]=="number"&&typeof arguments[0]=="number"&&typeof arguments[1]=="number"){var u=arguments[0],c=arguments[1],g=arguments[2];return u<c?c:u>g?g:u}if(Number.isInteger(arguments[2])&&Number.isInteger(arguments[0])&&Number.isInteger(arguments[1])){var v=arguments[0],x=arguments[1],k=arguments[2];return v<x?x:v>k?k:v}}},{key:"wrap",value:function(u,c){return u<0?c- -u%c:u%c}},{key:"max",value:function(){if(arguments.length===3){var u=arguments[1],c=arguments[2],g=arguments[0];return u>g&&(g=u),c>g&&(g=c),g}if(arguments.length===4){var v=arguments[1],x=arguments[2],k=arguments[3],O=arguments[0];return v>O&&(O=v),x>O&&(O=x),k>O&&(O=k),O}}},{key:"average",value:function(u,c){return(u+c)/2}}])})();Rl.LOG_10=Math.log(10);var Ns=(function(){function m(){s(this,m)}return a(m,null,[{key:"segmentToSegment",value:function(u,c,g,v){if(u.equals(c))return m.pointToSegment(u,g,v);if(g.equals(v))return m.pointToSegment(v,u,c);var x=!1;if(Dt.intersects(u,c,g,v)){var k=(c.x-u.x)*(v.y-g.y)-(c.y-u.y)*(v.x-g.x);if(k===0)x=!0;else{var O=(u.y-g.y)*(v.x-g.x)-(u.x-g.x)*(v.y-g.y),G=((u.y-g.y)*(c.x-u.x)-(u.x-g.x)*(c.y-u.y))/k,X=O/k;(X<0||X>1||G<0||G>1)&&(x=!0)}}else x=!0;return x?Rl.min(m.pointToSegment(u,g,v),m.pointToSegment(c,g,v),m.pointToSegment(g,u,c),m.pointToSegment(v,u,c)):0}},{key:"pointToSegment",value:function(u,c,g){if(c.x===g.x&&c.y===g.y)return u.distance(c);var v=(g.x-c.x)*(g.x-c.x)+(g.y-c.y)*(g.y-c.y),x=((u.x-c.x)*(g.x-c.x)+(u.y-c.y)*(g.y-c.y))/v;if(x<=0)return u.distance(c);if(x>=1)return u.distance(g);var k=((c.y-u.y)*(g.x-c.x)-(c.x-u.x)*(g.y-c.y))/v;return Math.abs(k)*Math.sqrt(v)}},{key:"pointToLinePerpendicular",value:function(u,c,g){var v=(g.x-c.x)*(g.x-c.x)+(g.y-c.y)*(g.y-c.y),x=((c.y-u.y)*(g.x-c.x)-(c.x-u.x)*(g.y-c.y))/v;return Math.abs(x)*Math.sqrt(v)}},{key:"pointToSegmentString",value:function(u,c){if(c.length===0)throw new S("Line array must contain at least one vertex");for(var g=u.distance(c[0]),v=0;v<c.length-1;v++){var x=m.pointToSegment(u,c[v],c[v+1]);x<g&&(g=x)}return g}}])})(),X0=(function(){return a((function m(){s(this,m)}),[{key:"create",value:function(){if(arguments.length===1)arguments[0]instanceof Array||H(arguments[0],kt);else if(arguments.length!==2){if(arguments.length===3){var m=arguments[0],u=arguments[1];return this.create(m,u)}}}}])})(),Cc=(function(){return a((function m(){s(this,m)}),[{key:"filter",value:function(m){}}])})(),xS=(function(){return a((function m(){s(this,m)}),null,[{key:"ofLine",value:function(m){var u=m.size();if(u<=1)return 0;var c=0,g=new Q;m.getCoordinate(0,g);for(var v=g.x,x=g.y,k=1;k<u;k++){m.getCoordinate(k,g);var O=g.x,G=g.y,X=O-v,st=G-x;c+=Math.sqrt(X*X+st*st),v=O,x=G}return c}}])})(),j0=a((function m(){s(this,m)})),eo=(function(){function m(){s(this,m)}return a(m,null,[{key:"copyCoord",value:function(u,c,g,v){for(var x=Math.min(u.getDimension(),g.getDimension()),k=0;k<x;k++)g.setOrdinate(v,k,u.getOrdinate(c,k))}},{key:"isRing",value:function(u){var c=u.size();return c===0||!(c<=3)&&u.getOrdinate(0,kt.X)===u.getOrdinate(c-1,kt.X)&&u.getOrdinate(0,kt.Y)===u.getOrdinate(c-1,kt.Y)}},{key:"scroll",value:function(){if(arguments.length===2){if(H(arguments[0],kt)&&Number.isInteger(arguments[1])){var u=arguments[0],c=arguments[1];m.scroll(u,c,m.isRing(u))}else if(H(arguments[0],kt)&&arguments[1]instanceof Q){var g=arguments[0],v=arguments[1],x=m.indexOf(v,g);if(x<=0)return null;m.scroll(g,x)}}else if(arguments.length===3){var k=arguments[0],O=arguments[1],G=arguments[2];if(O<=0)return null;for(var X=k.copy(),st=G?k.size()-1:k.size(),at=0;at<st;at++)for(var mt=0;mt<k.getDimension();mt++)k.setOrdinate(at,mt,X.getOrdinate((O+at)%st,mt));if(G)for(var Pt=0;Pt<k.getDimension();Pt++)k.setOrdinate(st,Pt,k.getOrdinate(0,Pt))}}},{key:"isEqual",value:function(u,c){var g=u.size();if(g!==c.size())return!1;for(var v=Math.min(u.getDimension(),c.getDimension()),x=0;x<g;x++)for(var k=0;k<v;k++){var O=u.getOrdinate(x,k),G=c.getOrdinate(x,k);if(u.getOrdinate(x,k)!==c.getOrdinate(x,k)&&(!W.isNaN(O)||!W.isNaN(G)))return!1}return!0}},{key:"minCoordinateIndex",value:function(){if(arguments.length===1){var u=arguments[0];return m.minCoordinateIndex(u,0,u.size()-1)}if(arguments.length===3){for(var c=arguments[0],g=arguments[2],v=-1,x=null,k=arguments[1];k<=g;k++){var O=c.getCoordinate(k);(x===null||x.compareTo(O)>0)&&(x=O,v=k)}return v}}},{key:"extend",value:function(u,c,g){var v=u.create(g,c.getDimension()),x=c.size();if(m.copy(c,0,v,0,x),x>0)for(var k=x;k<g;k++)m.copy(c,x-1,v,k,1);return v}},{key:"reverse",value:function(u){for(var c=u.size()-1,g=Math.trunc(c/2),v=0;v<=g;v++)m.swap(u,v,c-v)}},{key:"swap",value:function(u,c,g){if(c===g)return null;for(var v=0;v<u.getDimension();v++){var x=u.getOrdinate(c,v);u.setOrdinate(c,v,u.getOrdinate(g,v)),u.setOrdinate(g,v,x)}}},{key:"copy",value:function(u,c,g,v,x){for(var k=0;k<x;k++)m.copyCoord(u,c+k,g,v+k)}},{key:"ensureValidRing",value:function(u,c){var g=c.size();return g===0?c:g<=3?m.createClosedRing(u,c,4):c.getOrdinate(0,kt.X)===c.getOrdinate(g-1,kt.X)&&c.getOrdinate(0,kt.Y)===c.getOrdinate(g-1,kt.Y)?c:m.createClosedRing(u,c,g+1)}},{key:"indexOf",value:function(u,c){for(var g=0;g<c.size();g++)if(u.x===c.getOrdinate(g,kt.X)&&u.y===c.getOrdinate(g,kt.Y))return g;return-1}},{key:"createClosedRing",value:function(u,c,g){var v=u.create(g,c.getDimension()),x=c.size();m.copy(c,0,v,0,x);for(var k=x;k<g;k++)m.copy(c,0,v,k,1);return v}},{key:"minCoordinate",value:function(u){for(var c=null,g=0;g<u.size();g++){var v=u.getCoordinate(g);(c===null||c.compareTo(v)>0)&&(c=v)}return c}}])})(),Nt=(function(){function m(){s(this,m)}return a(m,null,[{key:"toDimensionSymbol",value:function(u){switch(u){case m.FALSE:return m.SYM_FALSE;case m.TRUE:return m.SYM_TRUE;case m.DONTCARE:return m.SYM_DONTCARE;case m.P:return m.SYM_P;case m.L:return m.SYM_L;case m.A:return m.SYM_A}throw new S("Unknown dimension value: "+u)}},{key:"toDimensionValue",value:function(u){switch(ut.toUpperCase(u)){case m.SYM_FALSE:return m.FALSE;case m.SYM_TRUE:return m.TRUE;case m.SYM_DONTCARE:return m.DONTCARE;case m.SYM_P:return m.P;case m.SYM_L:return m.L;case m.SYM_A:return m.A}throw new S("Unknown dimension symbol: "+u)}}])})();Nt.P=0,Nt.L=1,Nt.A=2,Nt.FALSE=-1,Nt.TRUE=-2,Nt.DONTCARE=-3,Nt.SYM_FALSE="F",Nt.SYM_TRUE="T",Nt.SYM_DONTCARE="*",Nt.SYM_P="0",Nt.SYM_L="1",Nt.SYM_A="2";var Pc=(function(){return a((function m(){s(this,m)}),[{key:"filter",value:function(m){}}])})(),kc=(function(){return a((function m(){s(this,m)}),[{key:"filter",value:function(m,u){}},{key:"isDone",value:function(){}},{key:"isGeometryChanged",value:function(){}}])})(),Al=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,[{key:"computeEnvelopeInternal",value:function(){return this.isEmpty()?new Dt:this._points.expandEnvelope(new Dt)}},{key:"isRing",value:function(){return this.isClosed()&&this.isSimple()}},{key:"getCoordinates",value:function(){return this._points.toCoordinateArray()}},{key:"copyInternal",value:function(){return new u(this._points.copy(),this._factory)}},{key:"equalsExact",value:function(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof wt){var c=arguments[0],g=arguments[1];if(!this.isEquivalentClass(c))return!1;var v=c;if(this._points.size()!==v._points.size())return!1;for(var x=0;x<this._points.size();x++)if(!this.equal(this._points.getCoordinate(x),v._points.getCoordinate(x),g))return!1;return!0}return _(u,"equalsExact",this,1).apply(this,arguments)}},{key:"normalize",value:function(){for(var c=0;c<Math.trunc(this._points.size()/2);c++){var g=this._points.size()-1-c;if(!this._points.getCoordinate(c).equals(this._points.getCoordinate(g))){if(this._points.getCoordinate(c).compareTo(this._points.getCoordinate(g))>0){var v=this._points.copy();eo.reverse(v),this._points=v}return null}}}},{key:"getCoordinate",value:function(){return this.isEmpty()?null:this._points.getCoordinate(0)}},{key:"getBoundaryDimension",value:function(){return this.isClosed()?Nt.FALSE:0}},{key:"isClosed",value:function(){return!this.isEmpty()&&this.getCoordinateN(0).equals2D(this.getCoordinateN(this.getNumPoints()-1))}},{key:"reverseInternal",value:function(){var c=this._points.copy();return eo.reverse(c),this.getFactory().createLineString(c)}},{key:"getEndPoint",value:function(){return this.isEmpty()?null:this.getPointN(this.getNumPoints()-1)}},{key:"getTypeCode",value:function(){return wt.TYPECODE_LINESTRING}},{key:"getDimension",value:function(){return 1}},{key:"getLength",value:function(){return xS.ofLine(this._points)}},{key:"getNumPoints",value:function(){return this._points.size()}},{key:"compareToSameClass",value:function(){if(arguments.length===1){for(var c=arguments[0],g=0,v=0;g<this._points.size()&&v<c._points.size();){var x=this._points.getCoordinate(g).compareTo(c._points.getCoordinate(v));if(x!==0)return x;g++,v++}return g<this._points.size()?1:v<c._points.size()?-1:0}if(arguments.length===2){var k=arguments[0];return arguments[1].compare(this._points,k._points)}}},{key:"apply",value:function(){if(H(arguments[0],Cc))for(var c=arguments[0],g=0;g<this._points.size();g++)c.filter(this._points.getCoordinate(g));else if(H(arguments[0],kc)){var v=arguments[0];if(this._points.size()===0)return null;for(var x=0;x<this._points.size()&&(v.filter(this._points,x),!v.isDone());x++);v.isGeometryChanged()&&this.geometryChanged()}else H(arguments[0],Pc)?arguments[0].filter(this):H(arguments[0],C)&&arguments[0].filter(this)}},{key:"getBoundary",value:function(){throw new Gt}},{key:"isEquivalentClass",value:function(c){return c instanceof u}},{key:"getCoordinateN",value:function(c){return this._points.getCoordinate(c)}},{key:"getGeometryType",value:function(){return wt.TYPENAME_LINESTRING}},{key:"getCoordinateSequence",value:function(){return this._points}},{key:"isEmpty",value:function(){return this._points.size()===0}},{key:"init",value:function(c){if(c===null&&(c=this.getFactory().getCoordinateSequenceFactory().create([])),c.size()===1)throw new S("Invalid number of points in LineString (found "+c.size()+" - must be 0 or >= 2)");this._points=c}},{key:"isCoordinate",value:function(c){for(var g=0;g<this._points.size();g++)if(this._points.getCoordinate(g).equals(c))return!0;return!1}},{key:"getStartPoint",value:function(){return this.isEmpty()?null:this.getPointN(0)}},{key:"getPointN",value:function(c){return this.getFactory().createPoint(this._points.getCoordinate(c))}},{key:"interfaces_",get:function(){return[j0]}}],[{key:"constructor_",value:function(){if(this._points=null,arguments.length!==0){if(arguments.length===2){var c=arguments[0],g=arguments[1];wt.constructor_.call(this,g),this.init(c)}}}}])})(wt),V0=a((function m(){s(this,m)})),Id=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,[{key:"computeEnvelopeInternal",value:function(){if(this.isEmpty())return new Dt;var c=new Dt;return c.expandToInclude(this._coordinates.getX(0),this._coordinates.getY(0)),c}},{key:"getCoordinates",value:function(){return this.isEmpty()?[]:[this.getCoordinate()]}},{key:"copyInternal",value:function(){return new u(this._coordinates.copy(),this._factory)}},{key:"equalsExact",value:function(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof wt){var c=arguments[0],g=arguments[1];return!!this.isEquivalentClass(c)&&(!(!this.isEmpty()||!c.isEmpty())||this.isEmpty()===c.isEmpty()&&this.equal(c.getCoordinate(),this.getCoordinate(),g))}return _(u,"equalsExact",this,1).apply(this,arguments)}},{key:"normalize",value:function(){}},{key:"getCoordinate",value:function(){return this._coordinates.size()!==0?this._coordinates.getCoordinate(0):null}},{key:"getBoundaryDimension",value:function(){return Nt.FALSE}},{key:"reverseInternal",value:function(){return this.getFactory().createPoint(this._coordinates.copy())}},{key:"getTypeCode",value:function(){return wt.TYPECODE_POINT}},{key:"getDimension",value:function(){return 0}},{key:"getNumPoints",value:function(){return this.isEmpty()?0:1}},{key:"getX",value:function(){if(this.getCoordinate()===null)throw new IllegalStateException("getX called on empty Point");return this.getCoordinate().x}},{key:"compareToSameClass",value:function(){if(arguments.length===1){var c=arguments[0];return this.getCoordinate().compareTo(c.getCoordinate())}if(arguments.length===2){var g=arguments[0];return arguments[1].compare(this._coordinates,g._coordinates)}}},{key:"apply",value:function(){if(H(arguments[0],Cc)){var c=arguments[0];if(this.isEmpty())return null;c.filter(this.getCoordinate())}else if(H(arguments[0],kc)){var g=arguments[0];if(this.isEmpty())return null;g.filter(this._coordinates,0),g.isGeometryChanged()&&this.geometryChanged()}else H(arguments[0],Pc)?arguments[0].filter(this):H(arguments[0],C)&&arguments[0].filter(this)}},{key:"getBoundary",value:function(){return this.getFactory().createGeometryCollection()}},{key:"getGeometryType",value:function(){return wt.TYPENAME_POINT}},{key:"getCoordinateSequence",value:function(){return this._coordinates}},{key:"getY",value:function(){if(this.getCoordinate()===null)throw new IllegalStateException("getY called on empty Point");return this.getCoordinate().y}},{key:"isEmpty",value:function(){return this._coordinates.size()===0}},{key:"init",value:function(c){c===null&&(c=this.getFactory().getCoordinateSequenceFactory().create([])),ct.isTrue(c.size()<=1),this._coordinates=c}},{key:"isSimple",value:function(){return!0}},{key:"interfaces_",get:function(){return[V0]}}],[{key:"constructor_",value:function(){this._coordinates=null;var c=arguments[0],g=arguments[1];wt.constructor_.call(this,g),this.init(c)}}])})(wt),H0=(function(){function m(){s(this,m)}return a(m,null,[{key:"ofRing",value:function(){if(arguments[0]instanceof Array){var u=arguments[0];return Math.abs(m.ofRingSigned(u))}if(H(arguments[0],kt)){var c=arguments[0];return Math.abs(m.ofRingSigned(c))}}},{key:"ofRingSigned",value:function(){if(arguments[0]instanceof Array){var u=arguments[0];if(u.length<3)return 0;for(var c=0,g=u[0].x,v=1;v<u.length-1;v++){var x=u[v].x-g,k=u[v+1].y;c+=x*(u[v-1].y-k)}return c/2}if(H(arguments[0],kt)){var O=arguments[0],G=O.size();if(G<3)return 0;var X=new Q,st=new Q,at=new Q;O.getCoordinate(0,st),O.getCoordinate(1,at);var mt=st.x;at.x-=mt;for(var Pt=0,Ft=1;Ft<G-1;Ft++)X.y=st.y,st.x=at.x,st.y=at.y,O.getCoordinate(Ft+1,at),at.x-=mt,Pt+=st.x*(X.y-at.y);return Pt/2}}}])})(),no=(function(){return a((function m(){s(this,m)}),null,[{key:"sort",value:function(){var m=arguments,u=arguments[0];if(arguments.length===1)u.sort((function(mt,Pt){return mt.compareTo(Pt)}));else if(arguments.length===2)u.sort((function(mt,Pt){return m[1].compare(mt,Pt)}));else if(arguments.length===3){var c=u.slice(arguments[1],arguments[2]);c.sort();var g=u.slice(0,arguments[1]).concat(c,u.slice(arguments[2],u.length));u.splice(0,u.length);var v,x=l(g);try{for(x.s();!(v=x.n()).done;){var k=v.value;u.push(k)}}catch(mt){x.e(mt)}finally{x.f()}}else if(arguments.length===4){var O=u.slice(arguments[1],arguments[2]);O.sort((function(mt,Pt){return m[3].compare(mt,Pt)}));var G=u.slice(0,arguments[1]).concat(O,u.slice(arguments[2],u.length));u.splice(0,u.length);var X,st=l(G);try{for(st.s();!(X=st.n()).done;){var at=X.value;u.push(at)}}catch(mt){st.e(mt)}finally{st.f()}}}},{key:"asList",value:function(m){var u,c=new Bt,g=l(m);try{for(g.s();!(u=g.n()).done;){var v=u.value;c.add(v)}}catch(x){g.e(x)}finally{g.f()}return c}},{key:"copyOf",value:function(m,u){return m.slice(0,u)}}])})(),W0=a((function m(){s(this,m)})),Tc=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,[{key:"computeEnvelopeInternal",value:function(){return this._shell.getEnvelopeInternal()}},{key:"getCoordinates",value:function(){if(this.isEmpty())return[];for(var c=new Array(this.getNumPoints()).fill(null),g=-1,v=this._shell.getCoordinates(),x=0;x<v.length;x++)c[++g]=v[x];for(var k=0;k<this._holes.length;k++)for(var O=this._holes[k].getCoordinates(),G=0;G<O.length;G++)c[++g]=O[G];return c}},{key:"getArea",value:function(){var c=0;c+=H0.ofRing(this._shell.getCoordinateSequence());for(var g=0;g<this._holes.length;g++)c-=H0.ofRing(this._holes[g].getCoordinateSequence());return c}},{key:"copyInternal",value:function(){for(var c=this._shell.copy(),g=new Array(this._holes.length).fill(null),v=0;v<this._holes.length;v++)g[v]=this._holes[v].copy();return new u(c,g,this._factory)}},{key:"isRectangle",value:function(){if(this.getNumInteriorRing()!==0||this._shell===null||this._shell.getNumPoints()!==5)return!1;for(var c=this._shell.getCoordinateSequence(),g=this.getEnvelopeInternal(),v=0;v<5;v++){var x=c.getX(v);if(x!==g.getMinX()&&x!==g.getMaxX())return!1;var k=c.getY(v);if(k!==g.getMinY()&&k!==g.getMaxY())return!1}for(var O=c.getX(0),G=c.getY(0),X=1;X<=4;X++){var st=c.getX(X),at=c.getY(X);if(st!==O==(at!==G))return!1;O=st,G=at}return!0}},{key:"equalsExact",value:function(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof wt){var c=arguments[0],g=arguments[1];if(!this.isEquivalentClass(c))return!1;var v=c,x=this._shell,k=v._shell;if(!x.equalsExact(k,g)||this._holes.length!==v._holes.length)return!1;for(var O=0;O<this._holes.length;O++)if(!this._holes[O].equalsExact(v._holes[O],g))return!1;return!0}return _(u,"equalsExact",this,1).apply(this,arguments)}},{key:"normalize",value:function(){if(arguments.length===0){this._shell=this.normalized(this._shell,!0);for(var c=0;c<this._holes.length;c++)this._holes[c]=this.normalized(this._holes[c],!1);no.sort(this._holes)}else if(arguments.length===2){var g=arguments[0],v=arguments[1];if(g.isEmpty())return null;var x=g.getCoordinateSequence(),k=eo.minCoordinateIndex(x,0,x.size()-2);eo.scroll(x,k,!0),At.isCCW(x)===v&&eo.reverse(x)}}},{key:"getCoordinate",value:function(){return this._shell.getCoordinate()}},{key:"getNumInteriorRing",value:function(){return this._holes.length}},{key:"getBoundaryDimension",value:function(){return 1}},{key:"reverseInternal",value:function(){for(var c=this.getExteriorRing().reverse(),g=new Array(this.getNumInteriorRing()).fill(null),v=0;v<g.length;v++)g[v]=this.getInteriorRingN(v).reverse();return this.getFactory().createPolygon(c,g)}},{key:"getTypeCode",value:function(){return wt.TYPECODE_POLYGON}},{key:"getDimension",value:function(){return 2}},{key:"getLength",value:function(){var c=0;c+=this._shell.getLength();for(var g=0;g<this._holes.length;g++)c+=this._holes[g].getLength();return c}},{key:"getNumPoints",value:function(){for(var c=this._shell.getNumPoints(),g=0;g<this._holes.length;g++)c+=this._holes[g].getNumPoints();return c}},{key:"convexHull",value:function(){return this.getExteriorRing().convexHull()}},{key:"normalized",value:function(c,g){var v=c.copy();return this.normalize(v,g),v}},{key:"compareToSameClass",value:function(){if(arguments.length===1){var c=arguments[0],g=this._shell,v=c._shell;return g.compareToSameClass(v)}if(arguments.length===2){var x=arguments[1],k=arguments[0],O=this._shell,G=k._shell,X=O.compareToSameClass(G,x);if(X!==0)return X;for(var st=this.getNumInteriorRing(),at=k.getNumInteriorRing(),mt=0;mt<st&&mt<at;){var Pt=this.getInteriorRingN(mt),Ft=k.getInteriorRingN(mt),qt=Pt.compareToSameClass(Ft,x);if(qt!==0)return qt;mt++}return mt<st?1:mt<at?-1:0}}},{key:"apply",value:function(){if(H(arguments[0],Cc)){var c=arguments[0];this._shell.apply(c);for(var g=0;g<this._holes.length;g++)this._holes[g].apply(c)}else if(H(arguments[0],kc)){var v=arguments[0];if(this._shell.apply(v),!v.isDone())for(var x=0;x<this._holes.length&&(this._holes[x].apply(v),!v.isDone());x++);v.isGeometryChanged()&&this.geometryChanged()}else if(H(arguments[0],Pc))arguments[0].filter(this);else if(H(arguments[0],C)){var k=arguments[0];k.filter(this),this._shell.apply(k);for(var O=0;O<this._holes.length;O++)this._holes[O].apply(k)}}},{key:"getBoundary",value:function(){if(this.isEmpty())return this.getFactory().createMultiLineString();var c=new Array(this._holes.length+1).fill(null);c[0]=this._shell;for(var g=0;g<this._holes.length;g++)c[g+1]=this._holes[g];return c.length<=1?this.getFactory().createLinearRing(c[0].getCoordinateSequence()):this.getFactory().createMultiLineString(c)}},{key:"getGeometryType",value:function(){return wt.TYPENAME_POLYGON}},{key:"getExteriorRing",value:function(){return this._shell}},{key:"isEmpty",value:function(){return this._shell.isEmpty()}},{key:"getInteriorRingN",value:function(c){return this._holes[c]}},{key:"interfaces_",get:function(){return[W0]}}],[{key:"constructor_",value:function(){this._shell=null,this._holes=null;var c=arguments[0],g=arguments[1],v=arguments[2];if(wt.constructor_.call(this,v),c===null&&(c=this.getFactory().createLinearRing()),g===null&&(g=[]),wt.hasNullElements(g))throw new S("holes must not contain null elements");if(c.isEmpty()&&wt.hasNonEmptyElements(g))throw new S("shell is empty but holes are not");this._shell=c,this._holes=g}}])})(wt),bS=(function(m){function u(){return s(this,u),n(this,u,arguments)}return d(u,m),a(u)})(dn),K0=(function(m){function u(c){var g;return s(this,u),(g=n(this,u)).array=[],c instanceof Xt&&g.addAll(c),g}return d(u,m),a(u,[{key:"contains",value:function(c){var g,v=l(this.array);try{for(v.s();!(g=v.n()).done;)if(g.value.compareTo(c)===0)return!0}catch(x){v.e(x)}finally{v.f()}return!1}},{key:"add",value:function(c){if(this.contains(c))return!1;for(var g=0,v=this.array.length;g<v;g++)if(this.array[g].compareTo(c)===1)return!!this.array.splice(g,0,c);return this.array.push(c),!0}},{key:"addAll",value:function(c){var g,v=l(c);try{for(v.s();!(g=v.n()).done;){var x=g.value;this.add(x)}}catch(k){v.e(k)}finally{v.f()}return!0}},{key:"remove",value:function(){throw new Gt}},{key:"size",value:function(){return this.array.length}},{key:"isEmpty",value:function(){return this.array.length===0}},{key:"toArray",value:function(){return this.array.slice()}},{key:"iterator",value:function(){return new IS(this.array)}}])})(bS),IS=(function(){return a((function m(u){s(this,m),this.array=u,this.position=0}),[{key:"next",value:function(){if(this.position===this.array.length)throw new Ut;return this.array[this.position++]}},{key:"hasNext",value:function(){return this.position<this.array.length}},{key:"remove",value:function(){throw new Gt}}])})(),pi=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,[{key:"computeEnvelopeInternal",value:function(){for(var c=new Dt,g=0;g<this._geometries.length;g++)c.expandToInclude(this._geometries[g].getEnvelopeInternal());return c}},{key:"getGeometryN",value:function(c){return this._geometries[c]}},{key:"getCoordinates",value:function(){for(var c=new Array(this.getNumPoints()).fill(null),g=-1,v=0;v<this._geometries.length;v++)for(var x=this._geometries[v].getCoordinates(),k=0;k<x.length;k++)c[++g]=x[k];return c}},{key:"getArea",value:function(){for(var c=0,g=0;g<this._geometries.length;g++)c+=this._geometries[g].getArea();return c}},{key:"copyInternal",value:function(){for(var c=new Array(this._geometries.length).fill(null),g=0;g<c.length;g++)c[g]=this._geometries[g].copy();return new u(c,this._factory)}},{key:"equalsExact",value:function(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof wt){var c=arguments[0],g=arguments[1];if(!this.isEquivalentClass(c))return!1;var v=c;if(this._geometries.length!==v._geometries.length)return!1;for(var x=0;x<this._geometries.length;x++)if(!this._geometries[x].equalsExact(v._geometries[x],g))return!1;return!0}return _(u,"equalsExact",this,1).apply(this,arguments)}},{key:"normalize",value:function(){for(var c=0;c<this._geometries.length;c++)this._geometries[c].normalize();no.sort(this._geometries)}},{key:"getCoordinate",value:function(){return this.isEmpty()?null:this._geometries[0].getCoordinate()}},{key:"getBoundaryDimension",value:function(){for(var c=Nt.FALSE,g=0;g<this._geometries.length;g++)c=Math.max(c,this._geometries[g].getBoundaryDimension());return c}},{key:"reverseInternal",value:function(){for(var c=this._geometries.length,g=new Bt(c),v=0;v<c;v++)g.add(this._geometries[v].reverse());return this.getFactory().buildGeometry(g)}},{key:"getTypeCode",value:function(){return wt.TYPECODE_GEOMETRYCOLLECTION}},{key:"getDimension",value:function(){for(var c=Nt.FALSE,g=0;g<this._geometries.length;g++)c=Math.max(c,this._geometries[g].getDimension());return c}},{key:"getLength",value:function(){for(var c=0,g=0;g<this._geometries.length;g++)c+=this._geometries[g].getLength();return c}},{key:"getNumPoints",value:function(){for(var c=0,g=0;g<this._geometries.length;g++)c+=this._geometries[g].getNumPoints();return c}},{key:"getNumGeometries",value:function(){return this._geometries.length}},{key:"compareToSameClass",value:function(){if(arguments.length===1){var c=arguments[0],g=new K0(no.asList(this._geometries)),v=new K0(no.asList(c._geometries));return this.compare(g,v)}if(arguments.length===2){for(var x=arguments[1],k=arguments[0],O=this.getNumGeometries(),G=k.getNumGeometries(),X=0;X<O&&X<G;){var st=this.getGeometryN(X),at=k.getGeometryN(X),mt=st.compareToSameClass(at,x);if(mt!==0)return mt;X++}return X<O?1:X<G?-1:0}}},{key:"apply",value:function(){if(H(arguments[0],Cc))for(var c=arguments[0],g=0;g<this._geometries.length;g++)this._geometries[g].apply(c);else if(H(arguments[0],kc)){var v=arguments[0];if(this._geometries.length===0)return null;for(var x=0;x<this._geometries.length&&(this._geometries[x].apply(v),!v.isDone());x++);v.isGeometryChanged()&&this.geometryChanged()}else if(H(arguments[0],Pc)){var k=arguments[0];k.filter(this);for(var O=0;O<this._geometries.length;O++)this._geometries[O].apply(k)}else if(H(arguments[0],C)){var G=arguments[0];G.filter(this);for(var X=0;X<this._geometries.length;X++)this._geometries[X].apply(G)}}},{key:"getBoundary",value:function(){return wt.checkNotGeometryCollection(this),ct.shouldNeverReachHere(),null}},{key:"getGeometryType",value:function(){return wt.TYPENAME_GEOMETRYCOLLECTION}},{key:"isEmpty",value:function(){for(var c=0;c<this._geometries.length;c++)if(!this._geometries[c].isEmpty())return!1;return!0}}],[{key:"constructor_",value:function(){if(this._geometries=null,arguments.length!==0){if(arguments.length===2){var c=arguments[0],g=arguments[1];if(wt.constructor_.call(this,g),c===null&&(c=[]),wt.hasNullElements(c))throw new S("geometries must not contain null elements");this._geometries=c}}}}])})(wt),Sd=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,[{key:"copyInternal",value:function(){for(var c=new Array(this._geometries.length).fill(null),g=0;g<c.length;g++)c[g]=this._geometries[g].copy();return new u(c,this._factory)}},{key:"isValid",value:function(){return!0}},{key:"equalsExact",value:function(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof wt){var c=arguments[0],g=arguments[1];return!!this.isEquivalentClass(c)&&_(u,"equalsExact",this,1).call(this,c,g)}return _(u,"equalsExact",this,1).apply(this,arguments)}},{key:"getCoordinate",value:function(){if(arguments.length===1&&Number.isInteger(arguments[0])){var c=arguments[0];return this._geometries[c].getCoordinate()}return _(u,"getCoordinate",this,1).apply(this,arguments)}},{key:"getBoundaryDimension",value:function(){return Nt.FALSE}},{key:"getTypeCode",value:function(){return wt.TYPECODE_MULTIPOINT}},{key:"getDimension",value:function(){return 0}},{key:"getBoundary",value:function(){return this.getFactory().createGeometryCollection()}},{key:"getGeometryType",value:function(){return wt.TYPENAME_MULTIPOINT}},{key:"interfaces_",get:function(){return[V0]}}],[{key:"constructor_",value:function(){var c=arguments[0],g=arguments[1];pi.constructor_.call(this,c,g)}}])})(pi),Ol=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,[{key:"copyInternal",value:function(){return new u(this._points.copy(),this._factory)}},{key:"getBoundaryDimension",value:function(){return Nt.FALSE}},{key:"isClosed",value:function(){return!!this.isEmpty()||_(u,"isClosed",this,1).call(this)}},{key:"reverseInternal",value:function(){var c=this._points.copy();return eo.reverse(c),this.getFactory().createLinearRing(c)}},{key:"getTypeCode",value:function(){return wt.TYPECODE_LINEARRING}},{key:"validateConstruction",value:function(){if(!this.isEmpty()&&!_(u,"isClosed",this,1).call(this))throw new S("Points of LinearRing do not form a closed linestring");if(this.getCoordinateSequence().size()>=1&&this.getCoordinateSequence().size()<u.MINIMUM_VALID_SIZE)throw new S("Invalid number of points in LinearRing (found "+this.getCoordinateSequence().size()+" - must be 0 or >= 4)")}},{key:"getGeometryType",value:function(){return wt.TYPENAME_LINEARRING}}],[{key:"constructor_",value:function(){var c=arguments[0],g=arguments[1];Al.constructor_.call(this,c,g),this.validateConstruction()}}])})(Al);Ol.MINIMUM_VALID_SIZE=4;var io=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,[{key:"setOrdinate",value:function(c,g){switch(c){case u.X:this.x=g;break;case u.Y:this.y=g;break;default:throw new S("Invalid ordinate index: "+c)}}},{key:"getZ",value:function(){return Q.NULL_ORDINATE}},{key:"getOrdinate",value:function(c){switch(c){case u.X:return this.x;case u.Y:return this.y}throw new S("Invalid ordinate index: "+c)}},{key:"setZ",value:function(c){throw new S("CoordinateXY dimension 2 does not support z-ordinate")}},{key:"copy",value:function(){return new u(this)}},{key:"toString",value:function(){return"("+this.x+", "+this.y+")"}},{key:"setCoordinate",value:function(c){this.x=c.x,this.y=c.y,this.z=c.getZ()}}],[{key:"constructor_",value:function(){if(arguments.length===0)Q.constructor_.call(this);else if(arguments.length===1){if(arguments[0]instanceof u){var c=arguments[0];Q.constructor_.call(this,c.x,c.y)}else if(arguments[0]instanceof Q){var g=arguments[0];Q.constructor_.call(this,g.x,g.y)}}else if(arguments.length===2){var v=arguments[0],x=arguments[1];Q.constructor_.call(this,v,x,Q.NULL_ORDINATE)}}}])})(Q);io.X=0,io.Y=1,io.Z=-1,io.M=-1;var so=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,[{key:"getM",value:function(){return this._m}},{key:"setOrdinate",value:function(c,g){switch(c){case u.X:this.x=g;break;case u.Y:this.y=g;break;case u.M:this._m=g;break;default:throw new S("Invalid ordinate index: "+c)}}},{key:"setM",value:function(c){this._m=c}},{key:"getZ",value:function(){return Q.NULL_ORDINATE}},{key:"getOrdinate",value:function(c){switch(c){case u.X:return this.x;case u.Y:return this.y;case u.M:return this._m}throw new S("Invalid ordinate index: "+c)}},{key:"setZ",value:function(c){throw new S("CoordinateXY dimension 2 does not support z-ordinate")}},{key:"copy",value:function(){return new u(this)}},{key:"toString",value:function(){return"("+this.x+", "+this.y+" m="+this.getM()+")"}},{key:"setCoordinate",value:function(c){this.x=c.x,this.y=c.y,this.z=c.getZ(),this._m=c.getM()}}],[{key:"constructor_",value:function(){if(this._m=null,arguments.length===0)Q.constructor_.call(this),this._m=0;else if(arguments.length===1){if(arguments[0]instanceof u){var c=arguments[0];Q.constructor_.call(this,c.x,c.y),this._m=c._m}else if(arguments[0]instanceof Q){var g=arguments[0];Q.constructor_.call(this,g.x,g.y),this._m=this.getM()}}else if(arguments.length===3){var v=arguments[0],x=arguments[1],k=arguments[2];Q.constructor_.call(this,v,x,Q.NULL_ORDINATE),this._m=k}}}])})(Q);so.X=0,so.Y=1,so.Z=-1,so.M=2;var Md=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,[{key:"getM",value:function(){return this._m}},{key:"setOrdinate",value:function(c,g){switch(c){case Q.X:this.x=g;break;case Q.Y:this.y=g;break;case Q.Z:this.z=g;break;case Q.M:this._m=g;break;default:throw new S("Invalid ordinate index: "+c)}}},{key:"setM",value:function(c){this._m=c}},{key:"getOrdinate",value:function(c){switch(c){case Q.X:return this.x;case Q.Y:return this.y;case Q.Z:return this.getZ();case Q.M:return this.getM()}throw new S("Invalid ordinate index: "+c)}},{key:"copy",value:function(){return new u(this)}},{key:"toString",value:function(){return"("+this.x+", "+this.y+", "+this.getZ()+" m="+this.getM()+")"}},{key:"setCoordinate",value:function(c){this.x=c.x,this.y=c.y,this.z=c.getZ(),this._m=c.getM()}}],[{key:"constructor_",value:function(){if(this._m=null,arguments.length===0)Q.constructor_.call(this),this._m=0;else if(arguments.length===1){if(arguments[0]instanceof u){var c=arguments[0];Q.constructor_.call(this,c),this._m=c._m}else if(arguments[0]instanceof Q){var g=arguments[0];Q.constructor_.call(this,g),this._m=this.getM()}}else if(arguments.length===4){var v=arguments[0],x=arguments[1],k=arguments[2],O=arguments[3];Q.constructor_.call(this,v,x,k),this._m=O}}}])})(Q),Rc=(function(){function m(){s(this,m)}return a(m,null,[{key:"measures",value:function(u){return u instanceof io?0:u instanceof so||u instanceof Md?1:0}},{key:"dimension",value:function(u){return u instanceof io?2:u instanceof so?3:u instanceof Md?4:3}},{key:"create",value:function(){if(arguments.length===1){var u=arguments[0];return m.create(u,0)}if(arguments.length===2){var c=arguments[0],g=arguments[1];return c===2?new io:c===3&&g===0?new Q:c===3&&g===1?new so:c===4&&g===1?new Md:new Q}}}])})(),Fl=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,[{key:"getCoordinate",value:function(c){return this.get(c)}},{key:"addAll",value:function(){if(arguments.length===2&&typeof arguments[1]=="boolean"&&H(arguments[0],Xt)){for(var c=arguments[1],g=!1,v=arguments[0].iterator();v.hasNext();)this.add(v.next(),c),g=!0;return g}return _(u,"addAll",this,1).apply(this,arguments)}},{key:"clone",value:function(){for(var c=_(u,"clone",this,1).call(this),g=0;g<this.size();g++)c.add(g,this.get(g).clone());return c}},{key:"toCoordinateArray",value:function(){if(arguments.length===0)return this.toArray(u.coordArrayType);if(arguments.length===1){if(arguments[0])return this.toArray(u.coordArrayType);for(var c=this.size(),g=new Array(c).fill(null),v=0;v<c;v++)g[v]=this.get(c-v-1);return g}}},{key:"add",value:function(){if(arguments.length===1){var c=arguments[0];return _(u,"add",this,1).call(this,c)}if(arguments.length===2){if(arguments[0]instanceof Array&&typeof arguments[1]=="boolean"){var g=arguments[0],v=arguments[1];return this.add(g,v,!0),!0}if(arguments[0]instanceof Q&&typeof arguments[1]=="boolean"){var x=arguments[0];if(!arguments[1]&&this.size()>=1&&this.get(this.size()-1).equals2D(x))return null;_(u,"add",this,1).call(this,x)}else if(arguments[0]instanceof Object&&typeof arguments[1]=="boolean"){var k=arguments[0],O=arguments[1];return this.add(k,O),!0}}else if(arguments.length===3){if(typeof arguments[2]=="boolean"&&arguments[0]instanceof Array&&typeof arguments[1]=="boolean"){var G=arguments[0],X=arguments[1];if(arguments[2])for(var st=0;st<G.length;st++)this.add(G[st],X);else for(var at=G.length-1;at>=0;at--)this.add(G[at],X);return!0}if(typeof arguments[2]=="boolean"&&Number.isInteger(arguments[0])&&arguments[1]instanceof Q){var mt=arguments[0],Pt=arguments[1];if(!arguments[2]){var Ft=this.size();if(Ft>0&&(mt>0&&this.get(mt-1).equals2D(Pt)||mt<Ft&&this.get(mt).equals2D(Pt)))return null}_(u,"add",this,1).call(this,mt,Pt)}}else if(arguments.length===4){var qt=arguments[0],fe=arguments[1],le=arguments[2],ke=arguments[3],xn=1;le>ke&&(xn=-1);for(var Pn=le;Pn!==ke;Pn+=xn)this.add(qt[Pn],fe);return!0}}},{key:"closeRing",value:function(){if(this.size()>0){var c=this.get(0).copy();this.add(c,!1)}}}],[{key:"constructor_",value:function(){if(arguments.length!==0){if(arguments.length===1){var c=arguments[0];this.ensureCapacity(c.length),this.add(c,!0)}else if(arguments.length===2){var g=arguments[0],v=arguments[1];this.ensureCapacity(g.length),this.add(g,v)}}}}])})(Bt);Fl.coordArrayType=new Array(0).fill(null);var gn=(function(){function m(){s(this,m)}return a(m,null,[{key:"isRing",value:function(u){return!(u.length<4)&&!!u[0].equals2D(u[u.length-1])}},{key:"ptNotInList",value:function(u,c){for(var g=0;g<u.length;g++){var v=u[g];if(m.indexOf(v,c)<0)return v}return null}},{key:"scroll",value:function(u,c){var g=m.indexOf(c,u);if(g<0)return null;var v=new Array(u.length).fill(null);Ti.arraycopy(u,g,v,0,u.length-g),Ti.arraycopy(u,0,v,u.length-g,g),Ti.arraycopy(v,0,u,0,u.length)}},{key:"equals",value:function(){if(arguments.length===2){var u=arguments[0],c=arguments[1];if(u===c)return!0;if(u===null||c===null||u.length!==c.length)return!1;for(var g=0;g<u.length;g++)if(!u[g].equals(c[g]))return!1;return!0}if(arguments.length===3){var v=arguments[0],x=arguments[1],k=arguments[2];if(v===x)return!0;if(v===null||x===null||v.length!==x.length)return!1;for(var O=0;O<v.length;O++)if(k.compare(v[O],x[O])!==0)return!1;return!0}}},{key:"intersection",value:function(u,c){for(var g=new Fl,v=0;v<u.length;v++)c.intersects(u[v])&&g.add(u[v],!0);return g.toCoordinateArray()}},{key:"measures",value:function(u){if(u===null||u.length===0)return 0;var c,g=0,v=l(u);try{for(v.s();!(c=v.n()).done;){var x=c.value;g=Math.max(g,Rc.measures(x))}}catch(k){v.e(k)}finally{v.f()}return g}},{key:"hasRepeatedPoints",value:function(u){for(var c=1;c<u.length;c++)if(u[c-1].equals(u[c]))return!0;return!1}},{key:"removeRepeatedPoints",value:function(u){return m.hasRepeatedPoints(u)?new Fl(u,!1).toCoordinateArray():u}},{key:"reverse",value:function(u){for(var c=u.length-1,g=Math.trunc(c/2),v=0;v<=g;v++){var x=u[v];u[v]=u[c-v],u[c-v]=x}}},{key:"removeNull",value:function(u){for(var c=0,g=0;g<u.length;g++)u[g]!==null&&c++;var v=new Array(c).fill(null);if(c===0)return v;for(var x=0,k=0;k<u.length;k++)u[k]!==null&&(v[x++]=u[k]);return v}},{key:"copyDeep",value:function(){if(arguments.length===1){for(var u=arguments[0],c=new Array(u.length).fill(null),g=0;g<u.length;g++)c[g]=u[g].copy();return c}if(arguments.length===5)for(var v=arguments[0],x=arguments[1],k=arguments[2],O=arguments[3],G=arguments[4],X=0;X<G;X++)k[O+X]=v[x+X].copy()}},{key:"isEqualReversed",value:function(u,c){for(var g=0;g<u.length;g++){var v=u[g],x=c[u.length-g-1];if(v.compareTo(x)!==0)return!1}return!0}},{key:"envelope",value:function(u){for(var c=new Dt,g=0;g<u.length;g++)c.expandToInclude(u[g]);return c}},{key:"toCoordinateArray",value:function(u){return u.toArray(m.coordArrayType)}},{key:"dimension",value:function(u){if(u===null||u.length===0)return 3;var c,g=0,v=l(u);try{for(v.s();!(c=v.n()).done;){var x=c.value;g=Math.max(g,Rc.dimension(x))}}catch(k){v.e(k)}finally{v.f()}return g}},{key:"atLeastNCoordinatesOrNothing",value:function(u,c){return c.length>=u?c:[]}},{key:"indexOf",value:function(u,c){for(var g=0;g<c.length;g++)if(u.equals(c[g]))return g;return-1}},{key:"increasingDirection",value:function(u){for(var c=0;c<Math.trunc(u.length/2);c++){var g=u.length-1-c,v=u[c].compareTo(u[g]);if(v!==0)return v}return 1}},{key:"compare",value:function(u,c){for(var g=0;g<u.length&&g<c.length;){var v=u[g].compareTo(c[g]);if(v!==0)return v;g++}return g<c.length?-1:g<u.length?1:0}},{key:"minCoordinate",value:function(u){for(var c=null,g=0;g<u.length;g++)(c===null||c.compareTo(u[g])>0)&&(c=u[g]);return c}},{key:"extract",value:function(u,c,g){c=Rl.clamp(c,0,u.length);var v=(g=Rl.clamp(g,-1,u.length))-c+1;g<0&&(v=0),c>=u.length&&(v=0),g<c&&(v=0);var x=new Array(v).fill(null);if(v===0)return x;for(var k=0,O=c;O<=g;O++)x[k++]=u[O];return x}}])})(),SS=(function(){return a((function m(){s(this,m)}),[{key:"compare",value:function(m,u){var c=m,g=u;return gn.compare(c,g)}},{key:"interfaces_",get:function(){return[J]}}])})(),MS=(function(){return a((function m(){s(this,m)}),[{key:"compare",value:function(m,u){var c=m,g=u;if(c.length<g.length)return-1;if(c.length>g.length)return 1;if(c.length===0)return 0;var v=gn.compare(c,g);return gn.isEqualReversed(c,g)?0:v}},{key:"OLDcompare",value:function(m,u){var c=m,g=u;if(c.length<g.length)return-1;if(c.length>g.length)return 1;if(c.length===0)return 0;for(var v=gn.increasingDirection(c),x=gn.increasingDirection(g),k=v>0?0:c.length-1,O=x>0?0:c.length-1,G=0;G<c.length;G++){var X=c[k].compareTo(g[O]);if(X!==0)return X;k+=v,O+=x}return 0}},{key:"interfaces_",get:function(){return[J]}}])})();gn.ForwardComparator=SS,gn.BidirectionalComparator=MS,gn.coordArrayType=new Array(0).fill(null);var Ac=(function(){return a((function m(u){s(this,m),this.str=u}),[{key:"append",value:function(m){this.str+=m}},{key:"setCharAt",value:function(m,u){this.str=this.str.substr(0,m)+u+this.str.substr(m+1)}},{key:"toString",value:function(){return this.str}}])})(),$l=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"getM",value:function(u){return this.hasM()?this._coordinates[u].getM():W.NaN}},{key:"setOrdinate",value:function(u,c,g){switch(c){case kt.X:this._coordinates[u].x=g;break;case kt.Y:this._coordinates[u].y=g;break;default:this._coordinates[u].setOrdinate(c,g)}}},{key:"getZ",value:function(u){return this.hasZ()?this._coordinates[u].getZ():W.NaN}},{key:"size",value:function(){return this._coordinates.length}},{key:"getOrdinate",value:function(u,c){switch(c){case kt.X:return this._coordinates[u].x;case kt.Y:return this._coordinates[u].y;default:return this._coordinates[u].getOrdinate(c)}}},{key:"getCoordinate",value:function(){if(arguments.length===1){var u=arguments[0];return this._coordinates[u]}if(arguments.length===2){var c=arguments[0];arguments[1].setCoordinate(this._coordinates[c])}}},{key:"getCoordinateCopy",value:function(u){var c=this.createCoordinate();return c.setCoordinate(this._coordinates[u]),c}},{key:"createCoordinate",value:function(){return Rc.create(this.getDimension(),this.getMeasures())}},{key:"getDimension",value:function(){return this._dimension}},{key:"getX",value:function(u){return this._coordinates[u].x}},{key:"getMeasures",value:function(){return this._measures}},{key:"expandEnvelope",value:function(u){for(var c=0;c<this._coordinates.length;c++)u.expandToInclude(this._coordinates[c]);return u}},{key:"copy",value:function(){for(var u=new Array(this.size()).fill(null),c=0;c<this._coordinates.length;c++){var g=this.createCoordinate();g.setCoordinate(this._coordinates[c]),u[c]=g}return new m(u,this._dimension,this._measures)}},{key:"toString",value:function(){if(this._coordinates.length>0){var u=new Ac(17*this._coordinates.length);u.append("("),u.append(this._coordinates[0]);for(var c=1;c<this._coordinates.length;c++)u.append(", "),u.append(this._coordinates[c]);return u.append(")"),u.toString()}return"()"}},{key:"getY",value:function(u){return this._coordinates[u].y}},{key:"toCoordinateArray",value:function(){return this._coordinates}},{key:"interfaces_",get:function(){return[kt,M]}}],[{key:"constructor_",value:function(){if(this._dimension=3,this._measures=0,this._coordinates=null,arguments.length===1){if(arguments[0]instanceof Array){var u=arguments[0];m.constructor_.call(this,u,gn.dimension(u),gn.measures(u))}else if(Number.isInteger(arguments[0])){var c=arguments[0];this._coordinates=new Array(c).fill(null);for(var g=0;g<c;g++)this._coordinates[g]=new Q}else if(H(arguments[0],kt)){var v=arguments[0];if(v===null)return this._coordinates=new Array(0).fill(null),null;this._dimension=v.getDimension(),this._measures=v.getMeasures(),this._coordinates=new Array(v.size()).fill(null);for(var x=0;x<this._coordinates.length;x++)this._coordinates[x]=v.getCoordinateCopy(x)}}else if(arguments.length===2){if(arguments[0]instanceof Array&&Number.isInteger(arguments[1])){var k=arguments[0],O=arguments[1];m.constructor_.call(this,k,O,gn.measures(k))}else if(Number.isInteger(arguments[0])&&Number.isInteger(arguments[1])){var G=arguments[0],X=arguments[1];this._coordinates=new Array(G).fill(null),this._dimension=X;for(var st=0;st<G;st++)this._coordinates[st]=Rc.create(X)}}else if(arguments.length===3){if(Number.isInteger(arguments[2])&&arguments[0]instanceof Array&&Number.isInteger(arguments[1])){var at=arguments[0],mt=arguments[1],Pt=arguments[2];this._dimension=mt,this._measures=Pt,this._coordinates=at===null?new Array(0).fill(null):at}else if(Number.isInteger(arguments[2])&&Number.isInteger(arguments[0])&&Number.isInteger(arguments[1])){var Ft=arguments[0],qt=arguments[1],fe=arguments[2];this._coordinates=new Array(Ft).fill(null),this._dimension=qt,this._measures=fe;for(var le=0;le<Ft;le++)this._coordinates[le]=this.createCoordinate()}}}}])})(),Nd=(function(){function m(){s(this,m)}return a(m,[{key:"readResolve",value:function(){return m.instance()}},{key:"create",value:function(){if(arguments.length===1){if(arguments[0]instanceof Array)return new $l(arguments[0]);if(H(arguments[0],kt))return new $l(arguments[0])}else{if(arguments.length===2){var u=arguments[1];return u>3&&(u=3),u<2&&(u=2),new $l(arguments[0],u)}if(arguments.length===3){var c=arguments[2],g=arguments[1]-c;return c>1&&(c=1),g>3&&(g=3),g<2&&(g=2),new $l(arguments[0],g+c,c)}}}},{key:"interfaces_",get:function(){return[X0,M]}}],[{key:"instance",value:function(){return m.instanceObject}}])})();Nd.instanceObject=new Nd;var Ld=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,[{key:"copyInternal",value:function(){for(var c=new Array(this._geometries.length).fill(null),g=0;g<c.length;g++)c[g]=this._geometries[g].copy();return new u(c,this._factory)}},{key:"equalsExact",value:function(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof wt){var c=arguments[0],g=arguments[1];return!!this.isEquivalentClass(c)&&_(u,"equalsExact",this,1).call(this,c,g)}return _(u,"equalsExact",this,1).apply(this,arguments)}},{key:"getBoundaryDimension",value:function(){return 1}},{key:"getTypeCode",value:function(){return wt.TYPECODE_MULTIPOLYGON}},{key:"getDimension",value:function(){return 2}},{key:"getBoundary",value:function(){if(this.isEmpty())return this.getFactory().createMultiLineString();for(var c=new Bt,g=0;g<this._geometries.length;g++)for(var v=this._geometries[g].getBoundary(),x=0;x<v.getNumGeometries();x++)c.add(v.getGeometryN(x));var k=new Array(c.size()).fill(null);return this.getFactory().createMultiLineString(c.toArray(k))}},{key:"getGeometryType",value:function(){return wt.TYPENAME_MULTIPOLYGON}},{key:"interfaces_",get:function(){return[W0]}}],[{key:"constructor_",value:function(){var c=arguments[0],g=arguments[1];pi.constructor_.call(this,c,g)}}])})(pi),Z0=(function(){return a((function m(){s(this,m)}),[{key:"get",value:function(){}},{key:"put",value:function(){}},{key:"size",value:function(){}},{key:"values",value:function(){}},{key:"entrySet",value:function(){}}])})(),NS=(function(m){function u(){var c;return s(this,u),(c=n(this,u)).map=new Map,c}return d(u,m),a(u,[{key:"get",value:function(c){return this.map.get(c)||null}},{key:"put",value:function(c,g){return this.map.set(c,g),g}},{key:"values",value:function(){for(var c=new Bt,g=this.map.values(),v=g.next();!v.done;)c.add(v.value),v=g.next();return c}},{key:"entrySet",value:function(){var c=new wn;return this.map.entries().forEach((function(g){return c.add(g)})),c}},{key:"size",value:function(){return this.map.size()}}])})(Z0),rs=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"equals",value:function(u){if(!(u instanceof m))return!1;var c=u;return this._modelType===c._modelType&&this._scale===c._scale}},{key:"compareTo",value:function(u){var c=u,g=this.getMaximumSignificantDigits(),v=c.getMaximumSignificantDigits();return ot.compare(g,v)}},{key:"getScale",value:function(){return this._scale}},{key:"isFloating",value:function(){return this._modelType===m.FLOATING||this._modelType===m.FLOATING_SINGLE}},{key:"getType",value:function(){return this._modelType}},{key:"toString",value:function(){var u="UNKNOWN";return this._modelType===m.FLOATING?u="Floating":this._modelType===m.FLOATING_SINGLE?u="Floating-Single":this._modelType===m.FIXED&&(u="Fixed (Scale="+this.getScale()+")"),u}},{key:"makePrecise",value:function(){if(typeof arguments[0]=="number"){var u=arguments[0];return W.isNaN(u)||this._modelType===m.FLOATING_SINGLE?u:this._modelType===m.FIXED?Math.round(u*this._scale)/this._scale:u}if(arguments[0]instanceof Q){var c=arguments[0];if(this._modelType===m.FLOATING)return null;c.x=this.makePrecise(c.x),c.y=this.makePrecise(c.y)}}},{key:"getMaximumSignificantDigits",value:function(){var u=16;return this._modelType===m.FLOATING?u=16:this._modelType===m.FLOATING_SINGLE?u=6:this._modelType===m.FIXED&&(u=1+Math.trunc(Math.ceil(Math.log(this.getScale())/Math.log(10)))),u}},{key:"setScale",value:function(u){this._scale=Math.abs(u)}},{key:"interfaces_",get:function(){return[M,T]}}],[{key:"constructor_",value:function(){if(this._modelType=null,this._scale=null,arguments.length===0)this._modelType=m.FLOATING;else if(arguments.length===1){if(arguments[0]instanceof Xo){var u=arguments[0];this._modelType=u,u===m.FIXED&&this.setScale(1)}else if(typeof arguments[0]=="number"){var c=arguments[0];this._modelType=m.FIXED,this.setScale(c)}else if(arguments[0]instanceof m){var g=arguments[0];this._modelType=g._modelType,this._scale=g._scale}}}},{key:"mostPrecise",value:function(u,c){return u.compareTo(c)>=0?u:c}}])})(),Xo=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"readResolve",value:function(){return m.nameToTypeMap.get(this._name)}},{key:"toString",value:function(){return this._name}},{key:"interfaces_",get:function(){return[M]}}],[{key:"constructor_",value:function(){this._name=null;var u=arguments[0];this._name=u,m.nameToTypeMap.put(u,this)}}])})();Xo.nameToTypeMap=new NS,rs.Type=Xo,rs.FIXED=new Xo("FIXED"),rs.FLOATING=new Xo("FLOATING"),rs.FLOATING_SINGLE=new Xo("FLOATING SINGLE"),rs.maximumPreciseValue=9007199254740992;var Cd=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,[{key:"copyInternal",value:function(){for(var c=new Array(this._geometries.length).fill(null),g=0;g<c.length;g++)c[g]=this._geometries[g].copy();return new u(c,this._factory)}},{key:"equalsExact",value:function(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof wt){var c=arguments[0],g=arguments[1];return!!this.isEquivalentClass(c)&&_(u,"equalsExact",this,1).call(this,c,g)}return _(u,"equalsExact",this,1).apply(this,arguments)}},{key:"getBoundaryDimension",value:function(){return this.isClosed()?Nt.FALSE:0}},{key:"isClosed",value:function(){if(this.isEmpty())return!1;for(var c=0;c<this._geometries.length;c++)if(!this._geometries[c].isClosed())return!1;return!0}},{key:"getTypeCode",value:function(){return wt.TYPECODE_MULTILINESTRING}},{key:"getDimension",value:function(){return 1}},{key:"getBoundary",value:function(){throw new Gt}},{key:"getGeometryType",value:function(){return wt.TYPENAME_MULTILINESTRING}},{key:"interfaces_",get:function(){return[j0]}}],[{key:"constructor_",value:function(){var c=arguments[0],g=arguments[1];pi.constructor_.call(this,c,g)}}])})(pi),jo=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"createEmpty",value:function(u){switch(u){case-1:return this.createGeometryCollection();case 0:return this.createPoint();case 1:return this.createLineString();case 2:return this.createPolygon();default:throw new S("Invalid dimension: "+u)}}},{key:"toGeometry",value:function(u){return u.isNull()?this.createPoint():u.getMinX()===u.getMaxX()&&u.getMinY()===u.getMaxY()?this.createPoint(new Q(u.getMinX(),u.getMinY())):u.getMinX()===u.getMaxX()||u.getMinY()===u.getMaxY()?this.createLineString([new Q(u.getMinX(),u.getMinY()),new Q(u.getMaxX(),u.getMaxY())]):this.createPolygon(this.createLinearRing([new Q(u.getMinX(),u.getMinY()),new Q(u.getMinX(),u.getMaxY()),new Q(u.getMaxX(),u.getMaxY()),new Q(u.getMaxX(),u.getMinY()),new Q(u.getMinX(),u.getMinY())]),null)}},{key:"createLineString",value:function(){if(arguments.length===0)return this.createLineString(this.getCoordinateSequenceFactory().create([]));if(arguments.length===1){if(arguments[0]instanceof Array){var u=arguments[0];return this.createLineString(u!==null?this.getCoordinateSequenceFactory().create(u):null)}if(H(arguments[0],kt))return new Al(arguments[0],this)}}},{key:"createMultiLineString",value:function(){return arguments.length===0?new Cd(null,this):arguments.length===1?new Cd(arguments[0],this):void 0}},{key:"buildGeometry",value:function(u){for(var c=null,g=!1,v=!1,x=u.iterator();x.hasNext();){var k=x.next(),O=k.getTypeCode();c===null&&(c=O),O!==c&&(g=!0),k instanceof pi&&(v=!0)}if(c===null)return this.createGeometryCollection();if(g||v)return this.createGeometryCollection(m.toGeometryArray(u));var G=u.iterator().next();if(u.size()>1){if(G instanceof Tc)return this.createMultiPolygon(m.toPolygonArray(u));if(G instanceof Al)return this.createMultiLineString(m.toLineStringArray(u));if(G instanceof Id)return this.createMultiPoint(m.toPointArray(u));ct.shouldNeverReachHere("Unhandled geometry type: "+G.getGeometryType())}return G}},{key:"createMultiPointFromCoords",value:function(u){return this.createMultiPoint(u!==null?this.getCoordinateSequenceFactory().create(u):null)}},{key:"createPoint",value:function(){if(arguments.length===0)return this.createPoint(this.getCoordinateSequenceFactory().create([]));if(arguments.length===1){if(arguments[0]instanceof Q){var u=arguments[0];return this.createPoint(u!==null?this.getCoordinateSequenceFactory().create([u]):null)}if(H(arguments[0],kt))return new Id(arguments[0],this)}}},{key:"getCoordinateSequenceFactory",value:function(){return this._coordinateSequenceFactory}},{key:"createPolygon",value:function(){if(arguments.length===0)return this.createPolygon(null,null);if(arguments.length===1){if(H(arguments[0],kt)){var u=arguments[0];return this.createPolygon(this.createLinearRing(u))}if(arguments[0]instanceof Array){var c=arguments[0];return this.createPolygon(this.createLinearRing(c))}if(arguments[0]instanceof Ol){var g=arguments[0];return this.createPolygon(g,null)}}else if(arguments.length===2)return new Tc(arguments[0],arguments[1],this)}},{key:"getSRID",value:function(){return this._SRID}},{key:"createGeometryCollection",value:function(){return arguments.length===0?new pi(null,this):arguments.length===1?new pi(arguments[0],this):void 0}},{key:"getPrecisionModel",value:function(){return this._precisionModel}},{key:"createLinearRing",value:function(){if(arguments.length===0)return this.createLinearRing(this.getCoordinateSequenceFactory().create([]));if(arguments.length===1){if(arguments[0]instanceof Array){var u=arguments[0];return this.createLinearRing(u!==null?this.getCoordinateSequenceFactory().create(u):null)}if(H(arguments[0],kt))return new Ol(arguments[0],this)}}},{key:"createMultiPolygon",value:function(){return arguments.length===0?new Ld(null,this):arguments.length===1?new Ld(arguments[0],this):void 0}},{key:"createMultiPoint",value:function(){if(arguments.length===0)return new Sd(null,this);if(arguments.length===1){if(arguments[0]instanceof Array)return new Sd(arguments[0],this);if(H(arguments[0],kt)){var u=arguments[0];if(u===null)return this.createMultiPoint(new Array(0).fill(null));for(var c=new Array(u.size()).fill(null),g=0;g<u.size();g++){var v=this.getCoordinateSequenceFactory().create(1,u.getDimension(),u.getMeasures());eo.copy(u,g,v,0,1),c[g]=this.createPoint(v)}return this.createMultiPoint(c)}}}},{key:"interfaces_",get:function(){return[M]}}],[{key:"constructor_",value:function(){if(this._precisionModel=null,this._coordinateSequenceFactory=null,this._SRID=null,arguments.length===0)m.constructor_.call(this,new rs,0);else if(arguments.length===1){if(H(arguments[0],X0)){var u=arguments[0];m.constructor_.call(this,new rs,0,u)}else if(arguments[0]instanceof rs){var c=arguments[0];m.constructor_.call(this,c,0,m.getDefaultCoordinateSequenceFactory())}}else if(arguments.length===2){var g=arguments[0],v=arguments[1];m.constructor_.call(this,g,v,m.getDefaultCoordinateSequenceFactory())}else if(arguments.length===3){var x=arguments[0],k=arguments[1],O=arguments[2];this._precisionModel=x,this._coordinateSequenceFactory=O,this._SRID=k}}},{key:"toMultiPolygonArray",value:function(u){var c=new Array(u.size()).fill(null);return u.toArray(c)}},{key:"toGeometryArray",value:function(u){if(u===null)return null;var c=new Array(u.size()).fill(null);return u.toArray(c)}},{key:"getDefaultCoordinateSequenceFactory",value:function(){return Nd.instance()}},{key:"toMultiLineStringArray",value:function(u){var c=new Array(u.size()).fill(null);return u.toArray(c)}},{key:"toLineStringArray",value:function(u){var c=new Array(u.size()).fill(null);return u.toArray(c)}},{key:"toMultiPointArray",value:function(u){var c=new Array(u.size()).fill(null);return u.toArray(c)}},{key:"toLinearRingArray",value:function(u){var c=new Array(u.size()).fill(null);return u.toArray(c)}},{key:"toPointArray",value:function(u){var c=new Array(u.size()).fill(null);return u.toArray(c)}},{key:"toPolygonArray",value:function(u){var c=new Array(u.size()).fill(null);return u.toArray(c)}},{key:"createPointFromInternalCoord",value:function(u,c){return c.getPrecisionModel().makePrecise(u),c.getFactory().createPoint(u)}}])})(),Pd="XY",LS="XYZ",CS="XYM",PS="XYZM",J0={POINT:"Point",LINE_STRING:"LineString",LINEAR_RING:"LinearRing",POLYGON:"Polygon",MULTI_POINT:"MultiPoint",MULTI_LINE_STRING:"MultiLineString",MULTI_POLYGON:"MultiPolygon",GEOMETRY_COLLECTION:"GeometryCollection",CIRCLE:"Circle"},Q0="EMPTY",Oc=1,er=2,br=3,ty=4,Vo=5,kS=6;for(var TS in J0)J0[TS].toUpperCase();var RS=(function(){return a((function m(u){s(this,m),this.wkt=u,this.index_=-1}),[{key:"isAlpha_",value:function(m){return m>="a"&&m<="z"||m>="A"&&m<="Z"}},{key:"isNumeric_",value:function(m,u){return m>="0"&&m<="9"||m=="."&&!(u!==void 0&&u)}},{key:"isWhiteSpace_",value:function(m){return m==" "||m==" "||m=="\r"||m==`
|
|
8
|
+
`}},{key:"nextChar_",value:function(){return this.wkt.charAt(++this.index_)}},{key:"nextToken",value:function(){var m,u=this.nextChar_(),c=this.index_,g=u;if(u=="(")m=er;else if(u==",")m=Vo;else if(u==")")m=br;else if(this.isNumeric_(u)||u=="-")m=ty,g=this.readNumber_();else if(this.isAlpha_(u))m=Oc,g=this.readText_();else{if(this.isWhiteSpace_(u))return this.nextToken();if(u!=="")throw new Error("Unexpected character: "+u);m=kS}return{position:c,value:g,type:m}}},{key:"readNumber_",value:function(){var m,u=this.index_,c=!1,g=!1;do m=="."?c=!0:m!="e"&&m!="E"||(g=!0),m=this.nextChar_();while(this.isNumeric_(m,c)||!g&&(m=="e"||m=="E")||g&&(m=="-"||m=="+"));return parseFloat(this.wkt.substring(u,this.index_--))}},{key:"readText_",value:function(){var m,u=this.index_;do m=this.nextChar_();while(this.isAlpha_(m));return this.wkt.substring(u,this.index_--).toUpperCase()}}])})(),AS=(function(){return a((function m(u,c){s(this,m),this.lexer_=u,this.token_,this.layout_=Pd,this.factory=c}),[{key:"consume_",value:function(){this.token_=this.lexer_.nextToken()}},{key:"isTokenType",value:function(m){return this.token_.type==m}},{key:"match",value:function(m){var u=this.isTokenType(m);return u&&this.consume_(),u}},{key:"parse",value:function(){return this.consume_(),this.parseGeometry_()}},{key:"parseGeometryLayout_",value:function(){var m=Pd,u=this.token_;if(this.isTokenType(Oc)){var c=u.value;c==="Z"?m=LS:c==="M"?m=CS:c==="ZM"&&(m=PS),m!==Pd&&this.consume_()}return m}},{key:"parseGeometryCollectionText_",value:function(){if(this.match(er)){var m=[];do m.push(this.parseGeometry_());while(this.match(Vo));if(this.match(br))return m}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parsePointText_",value:function(){if(this.match(er)){var m=this.parsePoint_();if(this.match(br))return m}else if(this.isEmptyGeometry_())return null;throw new Error(this.formatErrorMessage_())}},{key:"parseLineStringText_",value:function(){if(this.match(er)){var m=this.parsePointList_();if(this.match(br))return m}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parsePolygonText_",value:function(){if(this.match(er)){var m=this.parseLineStringTextList_();if(this.match(br))return m}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parseMultiPointText_",value:function(){var m;if(this.match(er)){if(m=this.token_.type==er?this.parsePointTextList_():this.parsePointList_(),this.match(br))return m}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parseMultiLineStringText_",value:function(){if(this.match(er)){var m=this.parseLineStringTextList_();if(this.match(br))return m}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parseMultiPolygonText_",value:function(){if(this.match(er)){var m=this.parsePolygonTextList_();if(this.match(br))return m}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parsePoint_",value:function(){for(var m=[],u=this.layout_.length,c=0;c<u;++c){var g=this.token_;if(!this.match(ty))break;m.push(g.value)}if(m.length==u)return m;throw new Error(this.formatErrorMessage_())}},{key:"parsePointList_",value:function(){for(var m=[this.parsePoint_()];this.match(Vo);)m.push(this.parsePoint_());return m}},{key:"parsePointTextList_",value:function(){for(var m=[this.parsePointText_()];this.match(Vo);)m.push(this.parsePointText_());return m}},{key:"parseLineStringTextList_",value:function(){for(var m=[this.parseLineStringText_()];this.match(Vo);)m.push(this.parseLineStringText_());return m}},{key:"parsePolygonTextList_",value:function(){for(var m=[this.parsePolygonText_()];this.match(Vo);)m.push(this.parsePolygonText_());return m}},{key:"isEmptyGeometry_",value:function(){var m=this.isTokenType(Oc)&&this.token_.value==Q0;return m&&this.consume_(),m}},{key:"formatErrorMessage_",value:function(){return"Unexpected `"+this.token_.value+"` at position "+this.token_.position+" in `"+this.lexer_.wkt+"`"}},{key:"parseGeometry_",value:function(){var m=this.factory,u=function(qt){return r(Q,E(qt))},c=function(qt){var fe=qt.map((function(le){return m.createLinearRing(le.map(u))}));return fe.length>1?m.createPolygon(fe[0],fe.slice(1)):m.createPolygon(fe[0])},g=this.token_;if(this.match(Oc)){var v=g.value;if(this.layout_=this.parseGeometryLayout_(),v=="GEOMETRYCOLLECTION"){var x=this.parseGeometryCollectionText_();return m.createGeometryCollection(x)}switch(v){case"POINT":var k=this.parsePointText_();return k?m.createPoint(r(Q,E(k))):m.createPoint();case"LINESTRING":var O=this.parseLineStringText_().map(u);return m.createLineString(O);case"LINEARRING":var G=this.parseLineStringText_().map(u);return m.createLinearRing(G);case"POLYGON":var X=this.parsePolygonText_();return X&&X.length!==0?c(X):m.createPolygon();case"MULTIPOINT":var st=this.parseMultiPointText_();if(!st||st.length===0)return m.createMultiPoint();var at=st.map(u).map((function(qt){return m.createPoint(qt)}));return m.createMultiPoint(at);case"MULTILINESTRING":var mt=this.parseMultiLineStringText_().map((function(qt){return m.createLineString(qt.map(u))}));return m.createMultiLineString(mt);case"MULTIPOLYGON":var Pt=this.parseMultiPolygonText_();if(!Pt||Pt.length===0)return m.createMultiPolygon();var Ft=Pt.map(c);return m.createMultiPolygon(Ft);default:throw new Error("Invalid geometry type: "+v)}}throw new Error(this.formatErrorMessage_())}}])})();function ey(m){if(m.isEmpty())return"";var u=m.getCoordinate(),c=[u.x,u.y];return u.z===void 0||Number.isNaN(u.z)||c.push(u.z),u.m===void 0||Number.isNaN(u.m)||c.push(u.m),c.join(" ")}function Dl(m){for(var u=m.getCoordinates().map((function(x){var k=[x.x,x.y];return x.z===void 0||Number.isNaN(x.z)||k.push(x.z),x.m===void 0||Number.isNaN(x.m)||k.push(x.m),k})),c=[],g=0,v=u.length;g<v;++g)c.push(u[g].join(" "));return c.join(", ")}function ny(m){var u=[];u.push("("+Dl(m.getExteriorRing())+")");for(var c=0,g=m.getNumInteriorRing();c<g;++c)u.push("("+Dl(m.getInteriorRingN(c))+")");return u.join(", ")}var OS={Point:ey,LineString:Dl,LinearRing:Dl,Polygon:ny,MultiPoint:function(m){for(var u=[],c=0,g=m.getNumGeometries();c<g;++c)u.push("("+ey(m.getGeometryN(c))+")");return u.join(", ")},MultiLineString:function(m){for(var u=[],c=0,g=m.getNumGeometries();c<g;++c)u.push("("+Dl(m.getGeometryN(c))+")");return u.join(", ")},MultiPolygon:function(m){for(var u=[],c=0,g=m.getNumGeometries();c<g;++c)u.push("("+ny(m.getGeometryN(c))+")");return u.join(", ")},GeometryCollection:function(m){for(var u=[],c=0,g=m.getNumGeometries();c<g;++c)u.push(iy(m.getGeometryN(c)));return u.join(", ")}};function iy(m){var u=m.getGeometryType(),c=OS[u];u=u.toUpperCase();var g=(function(v){var x="";if(v.isEmpty())return x;var k=v.getCoordinate();return k.z===void 0||Number.isNaN(k.z)||(x+="Z"),k.m===void 0||Number.isNaN(k.m)||(x+="M"),x})(m);return g.length>0&&(u+=" "+g),m.isEmpty()?u+" "+Q0:u+" ("+c(m)+")"}var FS=(function(){return a((function m(u){s(this,m),this.geometryFactory=u||new jo,this.precisionModel=this.geometryFactory.getPrecisionModel()}),[{key:"read",value:function(m){var u=new RS(m);return new AS(u,this.geometryFactory).parse()}},{key:"write",value:function(m){return iy(m)}}])})(),kd=(function(){return a((function m(u){s(this,m),this.parser=new FS(u)}),[{key:"write",value:function(m){return this.parser.write(m)}}],[{key:"toLineString",value:function(m,u){if(arguments.length!==2)throw new Error("Not implemented");return"LINESTRING ( "+m.x+" "+m.y+", "+u.x+" "+u.y+" )"}}])})(),qe=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"getIndexAlongSegment",value:function(u,c){return this.computeIntLineIndex(),this._intLineIndex[u][c]}},{key:"getTopologySummary",value:function(){var u=new Ac;return this.isEndPoint()&&u.append(" endpoint"),this._isProper&&u.append(" proper"),this.isCollinear()&&u.append(" collinear"),u.toString()}},{key:"computeIntersection",value:function(u,c,g,v){this._inputLines[0][0]=u,this._inputLines[0][1]=c,this._inputLines[1][0]=g,this._inputLines[1][1]=v,this._result=this.computeIntersect(u,c,g,v)}},{key:"getIntersectionNum",value:function(){return this._result}},{key:"computeIntLineIndex",value:function(){if(arguments.length===0)this._intLineIndex===null&&(this._intLineIndex=Array(2).fill().map((function(){return Array(2)})),this.computeIntLineIndex(0),this.computeIntLineIndex(1));else if(arguments.length===1){var u=arguments[0];this.getEdgeDistance(u,0)>this.getEdgeDistance(u,1)?(this._intLineIndex[u][0]=0,this._intLineIndex[u][1]=1):(this._intLineIndex[u][0]=1,this._intLineIndex[u][1]=0)}}},{key:"isProper",value:function(){return this.hasIntersection()&&this._isProper}},{key:"setPrecisionModel",value:function(u){this._precisionModel=u}},{key:"isInteriorIntersection",value:function(){if(arguments.length===0)return!!this.isInteriorIntersection(0)||!!this.isInteriorIntersection(1);if(arguments.length===1){for(var u=arguments[0],c=0;c<this._result;c++)if(!this._intPt[c].equals2D(this._inputLines[u][0])&&!this._intPt[c].equals2D(this._inputLines[u][1]))return!0;return!1}}},{key:"getIntersection",value:function(u){return this._intPt[u]}},{key:"isEndPoint",value:function(){return this.hasIntersection()&&!this._isProper}},{key:"hasIntersection",value:function(){return this._result!==m.NO_INTERSECTION}},{key:"getEdgeDistance",value:function(u,c){return m.computeEdgeDistance(this._intPt[c],this._inputLines[u][0],this._inputLines[u][1])}},{key:"isCollinear",value:function(){return this._result===m.COLLINEAR_INTERSECTION}},{key:"toString",value:function(){return kd.toLineString(this._inputLines[0][0],this._inputLines[0][1])+" - "+kd.toLineString(this._inputLines[1][0],this._inputLines[1][1])+this.getTopologySummary()}},{key:"getEndpoint",value:function(u,c){return this._inputLines[u][c]}},{key:"isIntersection",value:function(u){for(var c=0;c<this._result;c++)if(this._intPt[c].equals2D(u))return!0;return!1}},{key:"getIntersectionAlongSegment",value:function(u,c){return this.computeIntLineIndex(),this._intPt[this._intLineIndex[u][c]]}}],[{key:"constructor_",value:function(){this._result=null,this._inputLines=Array(2).fill().map((function(){return Array(2)})),this._intPt=new Array(2).fill(null),this._intLineIndex=null,this._isProper=null,this._pa=null,this._pb=null,this._precisionModel=null,this._intPt[0]=new Q,this._intPt[1]=new Q,this._pa=this._intPt[0],this._pb=this._intPt[1],this._result=0}},{key:"computeEdgeDistance",value:function(u,c,g){var v=Math.abs(g.x-c.x),x=Math.abs(g.y-c.y),k=-1;if(u.equals(c))k=0;else if(u.equals(g))k=v>x?v:x;else{var O=Math.abs(u.x-c.x),G=Math.abs(u.y-c.y);(k=v>x?O:G)!==0||u.equals(c)||(k=Math.max(O,G))}return ct.isTrue(!(k===0&&!u.equals(c)),"Bad distance calculation"),k}},{key:"nonRobustComputeEdgeDistance",value:function(u,c,g){var v=u.x-c.x,x=u.y-c.y,k=Math.sqrt(v*v+x*x);return ct.isTrue(!(k===0&&!u.equals(c)),"Invalid distance calculation"),k}}])})();qe.DONT_INTERSECT=0,qe.DO_INTERSECT=1,qe.COLLINEAR=2,qe.NO_INTERSECTION=0,qe.POINT_INTERSECTION=1,qe.COLLINEAR_INTERSECTION=2;var ro=(function(m){function u(){return s(this,u),n(this,u)}return d(u,m),a(u,[{key:"isInSegmentEnvelopes",value:function(c){var g=new Dt(this._inputLines[0][0],this._inputLines[0][1]),v=new Dt(this._inputLines[1][0],this._inputLines[1][1]);return g.contains(c)&&v.contains(c)}},{key:"computeIntersection",value:function(){if(arguments.length!==3)return _(u,"computeIntersection",this,1).apply(this,arguments);var c=arguments[0],g=arguments[1],v=arguments[2];if(this._isProper=!1,Dt.intersects(g,v,c)&&At.index(g,v,c)===0&&At.index(v,g,c)===0)return this._isProper=!0,(c.equals(g)||c.equals(v))&&(this._isProper=!1),this._result=qe.POINT_INTERSECTION,null;this._result=qe.NO_INTERSECTION}},{key:"intersection",value:function(c,g,v,x){var k=this.intersectionSafe(c,g,v,x);return this.isInSegmentEnvelopes(k)||(k=new Q(u.nearestEndpoint(c,g,v,x))),this._precisionModel!==null&&this._precisionModel.makePrecise(k),k}},{key:"checkDD",value:function(c,g,v,x,k){var O=Ct.intersection(c,g,v,x),G=this.isInSegmentEnvelopes(O);Ti.out.println("DD in env = "+G+" --------------------- "+O),k.distance(O)>1e-4&&Ti.out.println("Distance = "+k.distance(O))}},{key:"intersectionSafe",value:function(c,g,v,x){var k=Tl.intersection(c,g,v,x);return k===null&&(k=u.nearestEndpoint(c,g,v,x)),k}},{key:"computeCollinearIntersection",value:function(c,g,v,x){var k=Dt.intersects(c,g,v),O=Dt.intersects(c,g,x),G=Dt.intersects(v,x,c),X=Dt.intersects(v,x,g);return k&&O?(this._intPt[0]=v,this._intPt[1]=x,qe.COLLINEAR_INTERSECTION):G&&X?(this._intPt[0]=c,this._intPt[1]=g,qe.COLLINEAR_INTERSECTION):k&&G?(this._intPt[0]=v,this._intPt[1]=c,!v.equals(c)||O||X?qe.COLLINEAR_INTERSECTION:qe.POINT_INTERSECTION):k&&X?(this._intPt[0]=v,this._intPt[1]=g,!v.equals(g)||O||G?qe.COLLINEAR_INTERSECTION:qe.POINT_INTERSECTION):O&&G?(this._intPt[0]=x,this._intPt[1]=c,!x.equals(c)||k||X?qe.COLLINEAR_INTERSECTION:qe.POINT_INTERSECTION):O&&X?(this._intPt[0]=x,this._intPt[1]=g,!x.equals(g)||k||G?qe.COLLINEAR_INTERSECTION:qe.POINT_INTERSECTION):qe.NO_INTERSECTION}},{key:"computeIntersect",value:function(c,g,v,x){if(this._isProper=!1,!Dt.intersects(c,g,v,x))return qe.NO_INTERSECTION;var k=At.index(c,g,v),O=At.index(c,g,x);if(k>0&&O>0||k<0&&O<0)return qe.NO_INTERSECTION;var G=At.index(v,x,c),X=At.index(v,x,g);return G>0&&X>0||G<0&&X<0?qe.NO_INTERSECTION:k===0&&O===0&&G===0&&X===0?this.computeCollinearIntersection(c,g,v,x):(k===0||O===0||G===0||X===0?(this._isProper=!1,c.equals2D(v)||c.equals2D(x)?this._intPt[0]=c:g.equals2D(v)||g.equals2D(x)?this._intPt[0]=g:k===0?this._intPt[0]=new Q(v):O===0?this._intPt[0]=new Q(x):G===0?this._intPt[0]=new Q(c):X===0&&(this._intPt[0]=new Q(g))):(this._isProper=!0,this._intPt[0]=this.intersection(c,g,v,x)),qe.POINT_INTERSECTION)}}],[{key:"nearestEndpoint",value:function(c,g,v,x){var k=c,O=Ns.pointToSegment(c,v,x),G=Ns.pointToSegment(g,v,x);return G<O&&(O=G,k=g),(G=Ns.pointToSegment(v,c,g))<O&&(O=G,k=v),(G=Ns.pointToSegment(x,c,g))<O&&(O=G,k=x),k}}])})(qe),$S=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"countSegment",value:function(u,c){if(u.x<this._p.x&&c.x<this._p.x)return null;if(this._p.x===c.x&&this._p.y===c.y)return this._isPointOnSegment=!0,null;if(u.y===this._p.y&&c.y===this._p.y){var g=u.x,v=c.x;return g>v&&(g=c.x,v=u.x),this._p.x>=g&&this._p.x<=v&&(this._isPointOnSegment=!0),null}if(u.y>this._p.y&&c.y<=this._p.y||c.y>this._p.y&&u.y<=this._p.y){var x=At.index(u,c,this._p);if(x===At.COLLINEAR)return this._isPointOnSegment=!0,null;c.y<u.y&&(x=-x),x===At.LEFT&&this._crossingCount++}}},{key:"isPointInPolygon",value:function(){return this.getLocation()!==V.EXTERIOR}},{key:"getLocation",value:function(){return this._isPointOnSegment?V.BOUNDARY:this._crossingCount%2==1?V.INTERIOR:V.EXTERIOR}},{key:"isOnSegment",value:function(){return this._isPointOnSegment}}],[{key:"constructor_",value:function(){this._p=null,this._crossingCount=0,this._isPointOnSegment=!1;var u=arguments[0];this._p=u}},{key:"locatePointInRing",value:function(){if(arguments[0]instanceof Q&&H(arguments[1],kt)){for(var u=arguments[1],c=new m(arguments[0]),g=new Q,v=new Q,x=1;x<u.size();x++)if(u.getCoordinate(x,g),u.getCoordinate(x-1,v),c.countSegment(g,v),c.isOnSegment())return c.getLocation();return c.getLocation()}if(arguments[0]instanceof Q&&arguments[1]instanceof Array){for(var k=arguments[1],O=new m(arguments[0]),G=1;G<k.length;G++){var X=k[G],st=k[G-1];if(O.countSegment(X,st),O.isOnSegment())return O.getLocation()}return O.getLocation()}}}])})(),Td=(function(){function m(){s(this,m)}return a(m,null,[{key:"isOnLine",value:function(){if(arguments[0]instanceof Q&&H(arguments[1],kt)){for(var u=arguments[0],c=arguments[1],g=new ro,v=new Q,x=new Q,k=c.size(),O=1;O<k;O++)if(c.getCoordinate(O-1,v),c.getCoordinate(O,x),g.computeIntersection(u,v,x),g.hasIntersection())return!0;return!1}if(arguments[0]instanceof Q&&arguments[1]instanceof Array){for(var G=arguments[0],X=arguments[1],st=new ro,at=1;at<X.length;at++){var mt=X[at-1],Pt=X[at];if(st.computeIntersection(G,mt,Pt),st.hasIntersection())return!0}return!1}}},{key:"locateInRing",value:function(u,c){return $S.locatePointInRing(u,c)}},{key:"isInRing",value:function(u,c){return m.locateInRing(u,c)!==V.EXTERIOR}}])})(),Ri=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"setAllLocations",value:function(u){for(var c=0;c<this.location.length;c++)this.location[c]=u}},{key:"isNull",value:function(){for(var u=0;u<this.location.length;u++)if(this.location[u]!==V.NONE)return!1;return!0}},{key:"setAllLocationsIfNull",value:function(u){for(var c=0;c<this.location.length;c++)this.location[c]===V.NONE&&(this.location[c]=u)}},{key:"isLine",value:function(){return this.location.length===1}},{key:"merge",value:function(u){if(u.location.length>this.location.length){var c=new Array(3).fill(null);c[Et.ON]=this.location[Et.ON],c[Et.LEFT]=V.NONE,c[Et.RIGHT]=V.NONE,this.location=c}for(var g=0;g<this.location.length;g++)this.location[g]===V.NONE&&g<u.location.length&&(this.location[g]=u.location[g])}},{key:"getLocations",value:function(){return this.location}},{key:"flip",value:function(){if(this.location.length<=1)return null;var u=this.location[Et.LEFT];this.location[Et.LEFT]=this.location[Et.RIGHT],this.location[Et.RIGHT]=u}},{key:"toString",value:function(){var u=new nt;return this.location.length>1&&u.append(V.toLocationSymbol(this.location[Et.LEFT])),u.append(V.toLocationSymbol(this.location[Et.ON])),this.location.length>1&&u.append(V.toLocationSymbol(this.location[Et.RIGHT])),u.toString()}},{key:"setLocations",value:function(u,c,g){this.location[Et.ON]=u,this.location[Et.LEFT]=c,this.location[Et.RIGHT]=g}},{key:"get",value:function(u){return u<this.location.length?this.location[u]:V.NONE}},{key:"isArea",value:function(){return this.location.length>1}},{key:"isAnyNull",value:function(){for(var u=0;u<this.location.length;u++)if(this.location[u]===V.NONE)return!0;return!1}},{key:"setLocation",value:function(){if(arguments.length===1){var u=arguments[0];this.setLocation(Et.ON,u)}else if(arguments.length===2){var c=arguments[0],g=arguments[1];this.location[c]=g}}},{key:"init",value:function(u){this.location=new Array(u).fill(null),this.setAllLocations(V.NONE)}},{key:"isEqualOnSide",value:function(u,c){return this.location[c]===u.location[c]}},{key:"allPositionsEqual",value:function(u){for(var c=0;c<this.location.length;c++)if(this.location[c]!==u)return!1;return!0}}],[{key:"constructor_",value:function(){if(this.location=null,arguments.length===1){if(arguments[0]instanceof Array){var u=arguments[0];this.init(u.length)}else if(Number.isInteger(arguments[0])){var c=arguments[0];this.init(1),this.location[Et.ON]=c}else if(arguments[0]instanceof m){var g=arguments[0];if(this.init(g.location.length),g!==null)for(var v=0;v<this.location.length;v++)this.location[v]=g.location[v]}}else if(arguments.length===3){var x=arguments[0],k=arguments[1],O=arguments[2];this.init(3),this.location[Et.ON]=x,this.location[Et.LEFT]=k,this.location[Et.RIGHT]=O}}}])})(),Ai=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"getGeometryCount",value:function(){var u=0;return this.elt[0].isNull()||u++,this.elt[1].isNull()||u++,u}},{key:"setAllLocations",value:function(u,c){this.elt[u].setAllLocations(c)}},{key:"isNull",value:function(u){return this.elt[u].isNull()}},{key:"setAllLocationsIfNull",value:function(){if(arguments.length===1){var u=arguments[0];this.setAllLocationsIfNull(0,u),this.setAllLocationsIfNull(1,u)}else if(arguments.length===2){var c=arguments[0],g=arguments[1];this.elt[c].setAllLocationsIfNull(g)}}},{key:"isLine",value:function(u){return this.elt[u].isLine()}},{key:"merge",value:function(u){for(var c=0;c<2;c++)this.elt[c]===null&&u.elt[c]!==null?this.elt[c]=new Ri(u.elt[c]):this.elt[c].merge(u.elt[c])}},{key:"flip",value:function(){this.elt[0].flip(),this.elt[1].flip()}},{key:"getLocation",value:function(){if(arguments.length===1){var u=arguments[0];return this.elt[u].get(Et.ON)}if(arguments.length===2){var c=arguments[0],g=arguments[1];return this.elt[c].get(g)}}},{key:"toString",value:function(){var u=new nt;return this.elt[0]!==null&&(u.append("A:"),u.append(this.elt[0].toString())),this.elt[1]!==null&&(u.append(" B:"),u.append(this.elt[1].toString())),u.toString()}},{key:"isArea",value:function(){if(arguments.length===0)return this.elt[0].isArea()||this.elt[1].isArea();if(arguments.length===1){var u=arguments[0];return this.elt[u].isArea()}}},{key:"isAnyNull",value:function(u){return this.elt[u].isAnyNull()}},{key:"setLocation",value:function(){if(arguments.length===2){var u=arguments[0],c=arguments[1];this.elt[u].setLocation(Et.ON,c)}else if(arguments.length===3){var g=arguments[0],v=arguments[1],x=arguments[2];this.elt[g].setLocation(v,x)}}},{key:"isEqualOnSide",value:function(u,c){return this.elt[0].isEqualOnSide(u.elt[0],c)&&this.elt[1].isEqualOnSide(u.elt[1],c)}},{key:"allPositionsEqual",value:function(u,c){return this.elt[u].allPositionsEqual(c)}},{key:"toLine",value:function(u){this.elt[u].isArea()&&(this.elt[u]=new Ri(this.elt[u].location[0]))}}],[{key:"constructor_",value:function(){if(this.elt=new Array(2).fill(null),arguments.length===1){if(Number.isInteger(arguments[0])){var u=arguments[0];this.elt[0]=new Ri(u),this.elt[1]=new Ri(u)}else if(arguments[0]instanceof m){var c=arguments[0];this.elt[0]=new Ri(c.elt[0]),this.elt[1]=new Ri(c.elt[1])}}else if(arguments.length===2){var g=arguments[0],v=arguments[1];this.elt[0]=new Ri(V.NONE),this.elt[1]=new Ri(V.NONE),this.elt[g].setLocation(v)}else if(arguments.length===3){var x=arguments[0],k=arguments[1],O=arguments[2];this.elt[0]=new Ri(x,k,O),this.elt[1]=new Ri(x,k,O)}else if(arguments.length===4){var G=arguments[0],X=arguments[1],st=arguments[2],at=arguments[3];this.elt[0]=new Ri(V.NONE,V.NONE,V.NONE),this.elt[1]=new Ri(V.NONE,V.NONE,V.NONE),this.elt[G].setLocations(X,st,at)}}},{key:"toLineLabel",value:function(u){for(var c=new m(V.NONE),g=0;g<2;g++)c.setLocation(g,u.getLocation(g));return c}}])})(),Fc=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"computeRing",value:function(){if(this._ring!==null)return null;for(var m=new Array(this._pts.size()).fill(null),u=0;u<this._pts.size();u++)m[u]=this._pts.get(u);this._ring=this._geometryFactory.createLinearRing(m),this._isHole=At.isCCW(this._ring.getCoordinates())}},{key:"isIsolated",value:function(){return this._label.getGeometryCount()===1}},{key:"computePoints",value:function(m){this._startDe=m;var u=m,c=!0;do{if(u===null)throw new Ae("Found null DirectedEdge");if(u.getEdgeRing()===this)throw new Ae("Directed Edge visited twice during ring-building at "+u.getCoordinate());this._edges.add(u);var g=u.getLabel();ct.isTrue(g.isArea()),this.mergeLabel(g),this.addPoints(u.getEdge(),u.isForward(),c),c=!1,this.setEdgeRing(u,this),u=this.getNext(u)}while(u!==this._startDe)}},{key:"getLinearRing",value:function(){return this._ring}},{key:"getCoordinate",value:function(m){return this._pts.get(m)}},{key:"computeMaxNodeDegree",value:function(){this._maxNodeDegree=0;var m=this._startDe;do{var u=m.getNode().getEdges().getOutgoingDegree(this);u>this._maxNodeDegree&&(this._maxNodeDegree=u),m=this.getNext(m)}while(m!==this._startDe);this._maxNodeDegree*=2}},{key:"addPoints",value:function(m,u,c){var g=m.getCoordinates();if(u){var v=1;c&&(v=0);for(var x=v;x<g.length;x++)this._pts.add(g[x])}else{var k=g.length-2;c&&(k=g.length-1);for(var O=k;O>=0;O--)this._pts.add(g[O])}}},{key:"isHole",value:function(){return this._isHole}},{key:"setInResult",value:function(){var m=this._startDe;do m.getEdge().setInResult(!0),m=m.getNext();while(m!==this._startDe)}},{key:"containsPoint",value:function(m){var u=this.getLinearRing();if(!u.getEnvelopeInternal().contains(m)||!Td.isInRing(m,u.getCoordinates()))return!1;for(var c=this._holes.iterator();c.hasNext();)if(c.next().containsPoint(m))return!1;return!0}},{key:"addHole",value:function(m){this._holes.add(m)}},{key:"isShell",value:function(){return this._shell===null}},{key:"getLabel",value:function(){return this._label}},{key:"getEdges",value:function(){return this._edges}},{key:"getMaxNodeDegree",value:function(){return this._maxNodeDegree<0&&this.computeMaxNodeDegree(),this._maxNodeDegree}},{key:"getShell",value:function(){return this._shell}},{key:"mergeLabel",value:function(){if(arguments.length===1){var m=arguments[0];this.mergeLabel(m,0),this.mergeLabel(m,1)}else if(arguments.length===2){var u=arguments[1],c=arguments[0].getLocation(u,Et.RIGHT);if(c===V.NONE)return null;if(this._label.getLocation(u)===V.NONE)return this._label.setLocation(u,c),null}}},{key:"setShell",value:function(m){this._shell=m,m!==null&&m.addHole(this)}},{key:"toPolygon",value:function(m){for(var u=new Array(this._holes.size()).fill(null),c=0;c<this._holes.size();c++)u[c]=this._holes.get(c).getLinearRing();return m.createPolygon(this.getLinearRing(),u)}}],[{key:"constructor_",value:function(){if(this._startDe=null,this._maxNodeDegree=-1,this._edges=new Bt,this._pts=new Bt,this._label=new Ai(V.NONE),this._ring=null,this._isHole=null,this._shell=null,this._holes=new Bt,this._geometryFactory=null,arguments.length!==0){if(arguments.length===2){var m=arguments[0],u=arguments[1];this._geometryFactory=u,this.computePoints(m),this.computeRing()}}}}])})(),DS=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,[{key:"setEdgeRing",value:function(c,g){c.setMinEdgeRing(g)}},{key:"getNext",value:function(c){return c.getNextMin()}}],[{key:"constructor_",value:function(){var c=arguments[0],g=arguments[1];Fc.constructor_.call(this,c,g)}}])})(Fc),GS=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,[{key:"buildMinimalRings",value:function(){var c=new Bt,g=this._startDe;do{if(g.getMinEdgeRing()===null){var v=new DS(g,this._geometryFactory);c.add(v)}g=g.getNext()}while(g!==this._startDe);return c}},{key:"setEdgeRing",value:function(c,g){c.setEdgeRing(g)}},{key:"linkDirectedEdgesForMinimalEdgeRings",value:function(){var c=this._startDe;do c.getNode().getEdges().linkMinimalDirectedEdges(this),c=c.getNext();while(c!==this._startDe)}},{key:"getNext",value:function(c){return c.getNext()}}],[{key:"constructor_",value:function(){var c=arguments[0],g=arguments[1];Fc.constructor_.call(this,c,g)}}])})(Fc),sy=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"setVisited",value:function(m){this._isVisited=m}},{key:"setInResult",value:function(m){this._isInResult=m}},{key:"isCovered",value:function(){return this._isCovered}},{key:"isCoveredSet",value:function(){return this._isCoveredSet}},{key:"setLabel",value:function(m){this._label=m}},{key:"getLabel",value:function(){return this._label}},{key:"setCovered",value:function(m){this._isCovered=m,this._isCoveredSet=!0}},{key:"updateIM",value:function(m){ct.isTrue(this._label.getGeometryCount()>=2,"found partial label"),this.computeIM(m)}},{key:"isInResult",value:function(){return this._isInResult}},{key:"isVisited",value:function(){return this._isVisited}}],[{key:"constructor_",value:function(){if(this._label=null,this._isInResult=!1,this._isCovered=!1,this._isCoveredSet=!1,this._isVisited=!1,arguments.length!==0){if(arguments.length===1){var m=arguments[0];this._label=m}}}}])})(),$c=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,[{key:"isIncidentEdgeInResult",value:function(){for(var c=this.getEdges().getEdges().iterator();c.hasNext();)if(c.next().getEdge().isInResult())return!0;return!1}},{key:"isIsolated",value:function(){return this._label.getGeometryCount()===1}},{key:"getCoordinate",value:function(){return this._coord}},{key:"print",value:function(c){c.println("node "+this._coord+" lbl: "+this._label)}},{key:"computeIM",value:function(c){}},{key:"computeMergedLocation",value:function(c,g){var v=V.NONE;if(v=this._label.getLocation(g),!c.isNull(g)){var x=c.getLocation(g);v!==V.BOUNDARY&&(v=x)}return v}},{key:"setLabel",value:function(){if(arguments.length!==2||!Number.isInteger(arguments[1])||!Number.isInteger(arguments[0]))return _(u,"setLabel",this,1).apply(this,arguments);var c=arguments[0],g=arguments[1];this._label===null?this._label=new Ai(c,g):this._label.setLocation(c,g)}},{key:"getEdges",value:function(){return this._edges}},{key:"mergeLabel",value:function(){if(arguments[0]instanceof u){var c=arguments[0];this.mergeLabel(c._label)}else if(arguments[0]instanceof Ai)for(var g=arguments[0],v=0;v<2;v++){var x=this.computeMergedLocation(g,v);this._label.getLocation(v)===V.NONE&&this._label.setLocation(v,x)}}},{key:"add",value:function(c){this._edges.insert(c),c.setNode(this)}},{key:"setLabelBoundary",value:function(c){if(this._label===null)return null;var g=V.NONE;this._label!==null&&(g=this._label.getLocation(c));var v=null;switch(g){case V.BOUNDARY:v=V.INTERIOR;break;case V.INTERIOR:default:v=V.BOUNDARY}this._label.setLocation(c,v)}}],[{key:"constructor_",value:function(){this._coord=null,this._edges=null;var c=arguments[0],g=arguments[1];this._coord=c,this._edges=g,this._label=new Ai(0,V.NONE)}}])})(sy),BS=(function(m){function u(){return s(this,u),n(this,u,arguments)}return d(u,m),a(u)})(Z0);function ry(m){return m==null?0:m.color}function _e(m){return m==null?null:m.parent}function Ls(m,u){m!==null&&(m.color=u)}function Rd(m){return m==null?null:m.left}function oy(m){return m==null?null:m.right}var Gl=(function(m){function u(){var c;return s(this,u),(c=n(this,u)).root_=null,c.size_=0,c}return d(u,m),a(u,[{key:"get",value:function(c){for(var g=this.root_;g!==null;){var v=c.compareTo(g.key);if(v<0)g=g.left;else{if(!(v>0))return g.value;g=g.right}}return null}},{key:"put",value:function(c,g){if(this.root_===null)return this.root_={key:c,value:g,left:null,right:null,parent:null,color:0,getValue:function(){return this.value},getKey:function(){return this.key}},this.size_=1,null;var v,x,k=this.root_;do if(v=k,(x=c.compareTo(k.key))<0)k=k.left;else{if(!(x>0)){var O=k.value;return k.value=g,O}k=k.right}while(k!==null);var G={key:c,left:null,right:null,value:g,parent:v,color:0,getValue:function(){return this.value},getKey:function(){return this.key}};return x<0?v.left=G:v.right=G,this.fixAfterInsertion(G),this.size_++,null}},{key:"fixAfterInsertion",value:function(c){var g;for(c.color=1;c!=null&&c!==this.root_&&c.parent.color===1;)_e(c)===Rd(_e(_e(c)))?ry(g=oy(_e(_e(c))))===1?(Ls(_e(c),0),Ls(g,0),Ls(_e(_e(c)),1),c=_e(_e(c))):(c===oy(_e(c))&&(c=_e(c),this.rotateLeft(c)),Ls(_e(c),0),Ls(_e(_e(c)),1),this.rotateRight(_e(_e(c)))):ry(g=Rd(_e(_e(c))))===1?(Ls(_e(c),0),Ls(g,0),Ls(_e(_e(c)),1),c=_e(_e(c))):(c===Rd(_e(c))&&(c=_e(c),this.rotateRight(c)),Ls(_e(c),0),Ls(_e(_e(c)),1),this.rotateLeft(_e(_e(c))));this.root_.color=0}},{key:"values",value:function(){var c=new Bt,g=this.getFirstEntry();if(g!==null)for(c.add(g.value);(g=u.successor(g))!==null;)c.add(g.value);return c}},{key:"entrySet",value:function(){var c=new wn,g=this.getFirstEntry();if(g!==null)for(c.add(g);(g=u.successor(g))!==null;)c.add(g);return c}},{key:"rotateLeft",value:function(c){if(c!=null){var g=c.right;c.right=g.left,g.left!=null&&(g.left.parent=c),g.parent=c.parent,c.parent==null?this.root_=g:c.parent.left===c?c.parent.left=g:c.parent.right=g,g.left=c,c.parent=g}}},{key:"rotateRight",value:function(c){if(c!=null){var g=c.left;c.left=g.right,g.right!=null&&(g.right.parent=c),g.parent=c.parent,c.parent==null?this.root_=g:c.parent.right===c?c.parent.right=g:c.parent.left=g,g.right=c,c.parent=g}}},{key:"getFirstEntry",value:function(){var c=this.root_;if(c!=null)for(;c.left!=null;)c=c.left;return c}},{key:"size",value:function(){return this.size_}},{key:"containsKey",value:function(c){for(var g=this.root_;g!==null;){var v=c.compareTo(g.key);if(v<0)g=g.left;else{if(!(v>0))return!0;g=g.right}}return!1}}],[{key:"successor",value:function(c){var g;if(c===null)return null;if(c.right!==null){for(g=c.right;g.left!==null;)g=g.left;return g}g=c.parent;for(var v=c;g!==null&&v===g.right;)v=g,g=g.parent;return g}}])})(BS),ay=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"find",value:function(m){return this.nodeMap.get(m)}},{key:"addNode",value:function(){if(arguments[0]instanceof Q){var m=arguments[0],u=this.nodeMap.get(m);return u===null&&(u=this.nodeFact.createNode(m),this.nodeMap.put(m,u)),u}if(arguments[0]instanceof $c){var c=arguments[0],g=this.nodeMap.get(c.getCoordinate());return g===null?(this.nodeMap.put(c.getCoordinate(),c),c):(g.mergeLabel(c),g)}}},{key:"print",value:function(m){for(var u=this.iterator();u.hasNext();)u.next().print(m)}},{key:"iterator",value:function(){return this.nodeMap.values().iterator()}},{key:"values",value:function(){return this.nodeMap.values()}},{key:"getBoundaryNodes",value:function(m){for(var u=new Bt,c=this.iterator();c.hasNext();){var g=c.next();g.getLabel().getLocation(m)===V.BOUNDARY&&u.add(g)}return u}},{key:"add",value:function(m){var u=m.getCoordinate();this.addNode(u).add(m)}}],[{key:"constructor_",value:function(){this.nodeMap=new Gl,this.nodeFact=null;var m=arguments[0];this.nodeFact=m}}])})(),Gn=(function(){function m(){s(this,m)}return a(m,null,[{key:"isNorthern",value:function(u){return u===m.NE||u===m.NW}},{key:"isOpposite",value:function(u,c){return u!==c&&(u-c+4)%4===2}},{key:"commonHalfPlane",value:function(u,c){if(u===c)return u;if((u-c+4)%4===2)return-1;var g=u<c?u:c;return g===0&&(u>c?u:c)===3?3:g}},{key:"isInHalfPlane",value:function(u,c){return c===m.SE?u===m.SE||u===m.SW:u===c||u===c+1}},{key:"quadrant",value:function(){if(typeof arguments[0]=="number"&&typeof arguments[1]=="number"){var u=arguments[0],c=arguments[1];if(u===0&&c===0)throw new S("Cannot compute the quadrant for point ( "+u+", "+c+" )");return u>=0?c>=0?m.NE:m.SE:c>=0?m.NW:m.SW}if(arguments[0]instanceof Q&&arguments[1]instanceof Q){var g=arguments[0],v=arguments[1];if(v.x===g.x&&v.y===g.y)throw new S("Cannot compute the quadrant for two identical points "+g);return v.x>=g.x?v.y>=g.y?m.NE:m.SE:v.y>=g.y?m.NW:m.SW}}}])})();Gn.NE=0,Gn.NW=1,Gn.SW=2,Gn.SE=3;var ly=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"compareDirection",value:function(u){return this._dx===u._dx&&this._dy===u._dy?0:this._quadrant>u._quadrant?1:this._quadrant<u._quadrant?-1:At.index(u._p0,u._p1,this._p1)}},{key:"getDy",value:function(){return this._dy}},{key:"getCoordinate",value:function(){return this._p0}},{key:"setNode",value:function(u){this._node=u}},{key:"print",value:function(u){var c=Math.atan2(this._dy,this._dx),g=this.getClass().getName(),v=g.lastIndexOf("."),x=g.substring(v+1);u.print(" "+x+": "+this._p0+" - "+this._p1+" "+this._quadrant+":"+c+" "+this._label)}},{key:"compareTo",value:function(u){var c=u;return this.compareDirection(c)}},{key:"getDirectedCoordinate",value:function(){return this._p1}},{key:"getDx",value:function(){return this._dx}},{key:"getLabel",value:function(){return this._label}},{key:"getEdge",value:function(){return this._edge}},{key:"getQuadrant",value:function(){return this._quadrant}},{key:"getNode",value:function(){return this._node}},{key:"toString",value:function(){var u=Math.atan2(this._dy,this._dx),c=this.getClass().getName(),g=c.lastIndexOf(".");return" "+c.substring(g+1)+": "+this._p0+" - "+this._p1+" "+this._quadrant+":"+u+" "+this._label}},{key:"computeLabel",value:function(u){}},{key:"init",value:function(u,c){this._p0=u,this._p1=c,this._dx=c.x-u.x,this._dy=c.y-u.y,this._quadrant=Gn.quadrant(this._dx,this._dy),ct.isTrue(!(this._dx===0&&this._dy===0),"EdgeEnd with identical endpoints found")}},{key:"interfaces_",get:function(){return[T]}}],[{key:"constructor_",value:function(){if(this._edge=null,this._label=null,this._node=null,this._p0=null,this._p1=null,this._dx=null,this._dy=null,this._quadrant=null,arguments.length===1){var u=arguments[0];this._edge=u}else if(arguments.length===3){var c=arguments[0],g=arguments[1],v=arguments[2];m.constructor_.call(this,c,g,v,null)}else if(arguments.length===4){var x=arguments[0],k=arguments[1],O=arguments[2],G=arguments[3];m.constructor_.call(this,x),this.init(k,O),this._label=G}}}])})(),Ad=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,[{key:"getNextMin",value:function(){return this._nextMin}},{key:"getDepth",value:function(c){return this._depth[c]}},{key:"setVisited",value:function(c){this._isVisited=c}},{key:"computeDirectedLabel",value:function(){this._label=new Ai(this._edge.getLabel()),this._isForward||this._label.flip()}},{key:"getNext",value:function(){return this._next}},{key:"setDepth",value:function(c,g){if(this._depth[c]!==-999&&this._depth[c]!==g)throw new Ae("assigned depths do not match",this.getCoordinate());this._depth[c]=g}},{key:"isInteriorAreaEdge",value:function(){for(var c=!0,g=0;g<2;g++)this._label.isArea(g)&&this._label.getLocation(g,Et.LEFT)===V.INTERIOR&&this._label.getLocation(g,Et.RIGHT)===V.INTERIOR||(c=!1);return c}},{key:"setNextMin",value:function(c){this._nextMin=c}},{key:"print",value:function(c){_(u,"print",this,1).call(this,c),c.print(" "+this._depth[Et.LEFT]+"/"+this._depth[Et.RIGHT]),c.print(" ("+this.getDepthDelta()+")"),this._isInResult&&c.print(" inResult")}},{key:"setMinEdgeRing",value:function(c){this._minEdgeRing=c}},{key:"isLineEdge",value:function(){var c=this._label.isLine(0)||this._label.isLine(1),g=!this._label.isArea(0)||this._label.allPositionsEqual(0,V.EXTERIOR),v=!this._label.isArea(1)||this._label.allPositionsEqual(1,V.EXTERIOR);return c&&g&&v}},{key:"setEdgeRing",value:function(c){this._edgeRing=c}},{key:"getMinEdgeRing",value:function(){return this._minEdgeRing}},{key:"getDepthDelta",value:function(){var c=this._edge.getDepthDelta();return this._isForward||(c=-c),c}},{key:"setInResult",value:function(c){this._isInResult=c}},{key:"getSym",value:function(){return this._sym}},{key:"isForward",value:function(){return this._isForward}},{key:"getEdge",value:function(){return this._edge}},{key:"printEdge",value:function(c){this.print(c),c.print(" "),this._isForward?this._edge.print(c):this._edge.printReverse(c)}},{key:"setSym",value:function(c){this._sym=c}},{key:"setVisitedEdge",value:function(c){this.setVisited(c),this._sym.setVisited(c)}},{key:"setEdgeDepths",value:function(c,g){var v=this.getEdge().getDepthDelta();this._isForward||(v=-v);var x=1;c===Et.LEFT&&(x=-1);var k=Et.opposite(c),O=g+v*x;this.setDepth(c,g),this.setDepth(k,O)}},{key:"getEdgeRing",value:function(){return this._edgeRing}},{key:"isInResult",value:function(){return this._isInResult}},{key:"setNext",value:function(c){this._next=c}},{key:"isVisited",value:function(){return this._isVisited}}],[{key:"constructor_",value:function(){this._isForward=null,this._isInResult=!1,this._isVisited=!1,this._sym=null,this._next=null,this._nextMin=null,this._edgeRing=null,this._minEdgeRing=null,this._depth=[0,-999,-999];var c=arguments[0],g=arguments[1];if(ly.constructor_.call(this,c),this._isForward=g,g)this.init(c.getCoordinate(0),c.getCoordinate(1));else{var v=c.getNumPoints()-1;this.init(c.getCoordinate(v),c.getCoordinate(v-1))}this.computeDirectedLabel()}},{key:"depthFactor",value:function(c,g){return c===V.EXTERIOR&&g===V.INTERIOR?1:c===V.INTERIOR&&g===V.EXTERIOR?-1:0}}])})(ly),uy=(function(){return a((function m(){s(this,m)}),[{key:"createNode",value:function(m){return new $c(m,null)}}])})(),cy=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"printEdges",value:function(m){m.println("Edges:");for(var u=0;u<this._edges.size();u++){m.println("edge "+u+":");var c=this._edges.get(u);c.print(m),c.eiList.print(m)}}},{key:"find",value:function(m){return this._nodes.find(m)}},{key:"addNode",value:function(){if(arguments[0]instanceof $c){var m=arguments[0];return this._nodes.addNode(m)}if(arguments[0]instanceof Q){var u=arguments[0];return this._nodes.addNode(u)}}},{key:"getNodeIterator",value:function(){return this._nodes.iterator()}},{key:"linkResultDirectedEdges",value:function(){for(var m=this._nodes.iterator();m.hasNext();)m.next().getEdges().linkResultDirectedEdges()}},{key:"debugPrintln",value:function(m){Ti.out.println(m)}},{key:"isBoundaryNode",value:function(m,u){var c=this._nodes.find(u);if(c===null)return!1;var g=c.getLabel();return g!==null&&g.getLocation(m)===V.BOUNDARY}},{key:"linkAllDirectedEdges",value:function(){for(var m=this._nodes.iterator();m.hasNext();)m.next().getEdges().linkAllDirectedEdges()}},{key:"matchInSameDirection",value:function(m,u,c,g){return!!m.equals(c)&&At.index(m,u,g)===At.COLLINEAR&&Gn.quadrant(m,u)===Gn.quadrant(c,g)}},{key:"getEdgeEnds",value:function(){return this._edgeEndList}},{key:"debugPrint",value:function(m){Ti.out.print(m)}},{key:"getEdgeIterator",value:function(){return this._edges.iterator()}},{key:"findEdgeInSameDirection",value:function(m,u){for(var c=0;c<this._edges.size();c++){var g=this._edges.get(c),v=g.getCoordinates();if(this.matchInSameDirection(m,u,v[0],v[1])||this.matchInSameDirection(m,u,v[v.length-1],v[v.length-2]))return g}return null}},{key:"insertEdge",value:function(m){this._edges.add(m)}},{key:"findEdgeEnd",value:function(m){for(var u=this.getEdgeEnds().iterator();u.hasNext();){var c=u.next();if(c.getEdge()===m)return c}return null}},{key:"addEdges",value:function(m){for(var u=m.iterator();u.hasNext();){var c=u.next();this._edges.add(c);var g=new Ad(c,!0),v=new Ad(c,!1);g.setSym(v),v.setSym(g),this.add(g),this.add(v)}}},{key:"add",value:function(m){this._nodes.add(m),this._edgeEndList.add(m)}},{key:"getNodes",value:function(){return this._nodes.values()}},{key:"findEdge",value:function(m,u){for(var c=0;c<this._edges.size();c++){var g=this._edges.get(c),v=g.getCoordinates();if(m.equals(v[0])&&u.equals(v[1]))return g}return null}}],[{key:"constructor_",value:function(){if(this._edges=new Bt,this._nodes=null,this._edgeEndList=new Bt,arguments.length===0)this._nodes=new ay(new uy);else if(arguments.length===1){var m=arguments[0];this._nodes=new ay(m)}}},{key:"linkResultDirectedEdges",value:function(m){for(var u=m.iterator();u.hasNext();)u.next().getEdges().linkResultDirectedEdges()}}])})(),qS=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"sortShellsAndHoles",value:function(u,c,g){for(var v=u.iterator();v.hasNext();){var x=v.next();x.isHole()?g.add(x):c.add(x)}}},{key:"computePolygons",value:function(u){for(var c=new Bt,g=u.iterator();g.hasNext();){var v=g.next().toPolygon(this._geometryFactory);c.add(v)}return c}},{key:"placeFreeHoles",value:function(u,c){for(var g=c.iterator();g.hasNext();){var v=g.next();if(v.getShell()===null){var x=m.findEdgeRingContaining(v,u);if(x===null)throw new Ae("unable to assign hole to a shell",v.getCoordinate(0));v.setShell(x)}}}},{key:"buildMinimalEdgeRings",value:function(u,c,g){for(var v=new Bt,x=u.iterator();x.hasNext();){var k=x.next();if(k.getMaxNodeDegree()>2){k.linkDirectedEdgesForMinimalEdgeRings();var O=k.buildMinimalRings(),G=this.findShell(O);G!==null?(this.placePolygonHoles(G,O),c.add(G)):g.addAll(O)}else v.add(k)}return v}},{key:"buildMaximalEdgeRings",value:function(u){for(var c=new Bt,g=u.iterator();g.hasNext();){var v=g.next();if(v.isInResult()&&v.getLabel().isArea()&&v.getEdgeRing()===null){var x=new GS(v,this._geometryFactory);c.add(x),x.setInResult()}}return c}},{key:"placePolygonHoles",value:function(u,c){for(var g=c.iterator();g.hasNext();){var v=g.next();v.isHole()&&v.setShell(u)}}},{key:"getPolygons",value:function(){return this.computePolygons(this._shellList)}},{key:"findShell",value:function(u){for(var c=0,g=null,v=u.iterator();v.hasNext();){var x=v.next();x.isHole()||(g=x,c++)}return ct.isTrue(c<=1,"found two shells in MinimalEdgeRing list"),g}},{key:"add",value:function(){if(arguments.length===1){var u=arguments[0];this.add(u.getEdgeEnds(),u.getNodes())}else if(arguments.length===2){var c=arguments[0],g=arguments[1];cy.linkResultDirectedEdges(g);var v=this.buildMaximalEdgeRings(c),x=new Bt,k=this.buildMinimalEdgeRings(v,this._shellList,x);this.sortShellsAndHoles(k,this._shellList,x),this.placeFreeHoles(this._shellList,x)}}}],[{key:"constructor_",value:function(){this._geometryFactory=null,this._shellList=new Bt;var u=arguments[0];this._geometryFactory=u}},{key:"findEdgeRingContaining",value:function(u,c){for(var g=u.getLinearRing(),v=g.getEnvelopeInternal(),x=g.getCoordinateN(0),k=null,O=null,G=c.iterator();G.hasNext();){var X=G.next(),st=X.getLinearRing(),at=st.getEnvelopeInternal();if(!at.equals(v)&&at.contains(v)){x=gn.ptNotInList(g.getCoordinates(),st.getCoordinates());var mt=!1;Td.isInRing(x,st.getCoordinates())&&(mt=!0),mt&&(k===null||O.contains(at))&&(O=(k=X).getLinearRing().getEnvelopeInternal())}}return k}}])})(),hy=(function(){return a((function m(){s(this,m)}),[{key:"getBounds",value:function(){}}])})(),nr=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"getItem",value:function(){return this._item}},{key:"getBounds",value:function(){return this._bounds}},{key:"interfaces_",get:function(){return[hy,M]}}],[{key:"constructor_",value:function(){this._bounds=null,this._item=null;var m=arguments[0],u=arguments[1];this._bounds=m,this._item=u}}])})(),Dc=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"poll",value:function(){if(this.isEmpty())return null;var m=this._items.get(1);return this._items.set(1,this._items.get(this._size)),this._size-=1,this.reorder(1),m}},{key:"size",value:function(){return this._size}},{key:"reorder",value:function(m){for(var u=null,c=this._items.get(m);2*m<=this._size&&((u=2*m)!==this._size&&this._items.get(u+1).compareTo(this._items.get(u))<0&&u++,this._items.get(u).compareTo(c)<0);m=u)this._items.set(m,this._items.get(u));this._items.set(m,c)}},{key:"clear",value:function(){this._size=0,this._items.clear()}},{key:"peek",value:function(){return this.isEmpty()?null:this._items.get(1)}},{key:"isEmpty",value:function(){return this._size===0}},{key:"add",value:function(m){this._items.add(null),this._size+=1;var u=this._size;for(this._items.set(0,m);m.compareTo(this._items.get(Math.trunc(u/2)))<0;u/=2)this._items.set(u,this._items.get(Math.trunc(u/2)));this._items.set(u,m)}}],[{key:"constructor_",value:function(){this._size=null,this._items=null,this._size=0,this._items=new Bt,this._items.add(null)}}])})(),zS=(function(){return a((function m(){s(this,m)}),[{key:"insert",value:function(m,u){}},{key:"remove",value:function(m,u){}},{key:"query",value:function(){}}])})(),Oi=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"getLevel",value:function(){return this._level}},{key:"size",value:function(){return this._childBoundables.size()}},{key:"getChildBoundables",value:function(){return this._childBoundables}},{key:"addChildBoundable",value:function(m){ct.isTrue(this._bounds===null),this._childBoundables.add(m)}},{key:"isEmpty",value:function(){return this._childBoundables.isEmpty()}},{key:"getBounds",value:function(){return this._bounds===null&&(this._bounds=this.computeBounds()),this._bounds}},{key:"interfaces_",get:function(){return[hy,M]}}],[{key:"constructor_",value:function(){if(this._childBoundables=new Bt,this._bounds=null,this._level=null,arguments.length!==0){if(arguments.length===1){var m=arguments[0];this._level=m}}}}])})(),Ho={reverseOrder:function(){return{compare:function(m,u){return u.compareTo(m)}}},min:function(m){return Ho.sort(m),m.get(0)},sort:function(m,u){var c=m.toArray();u?no.sort(c,u):no.sort(c);for(var g=m.iterator(),v=0,x=c.length;v<x;v++)g.next(),g.set(c[v])},singletonList:function(m){var u=new Bt;return u.add(m),u}},US=(function(){function m(){s(this,m)}return a(m,null,[{key:"maxDistance",value:function(u,c,g,v,x,k,O,G){var X=m.distance(u,c,x,k);return X=Math.max(X,m.distance(u,c,O,G)),X=Math.max(X,m.distance(g,v,x,k)),X=Math.max(X,m.distance(g,v,O,G))}},{key:"distance",value:function(u,c,g,v){var x=g-u,k=v-c;return Math.sqrt(x*x+k*k)}},{key:"maximumDistance",value:function(u,c){var g=Math.min(u.getMinX(),c.getMinX()),v=Math.min(u.getMinY(),c.getMinY()),x=Math.max(u.getMaxX(),c.getMaxX()),k=Math.max(u.getMaxY(),c.getMaxY());return m.distance(g,v,x,k)}},{key:"minMaxDistance",value:function(u,c){var g=u.getMinX(),v=u.getMinY(),x=u.getMaxX(),k=u.getMaxY(),O=c.getMinX(),G=c.getMinY(),X=c.getMaxX(),st=c.getMaxY(),at=m.maxDistance(g,v,g,k,O,G,O,st);return at=Math.min(at,m.maxDistance(g,v,g,k,O,G,X,G)),at=Math.min(at,m.maxDistance(g,v,g,k,X,st,O,st)),at=Math.min(at,m.maxDistance(g,v,g,k,X,st,X,G)),at=Math.min(at,m.maxDistance(g,v,x,v,O,G,O,st)),at=Math.min(at,m.maxDistance(g,v,x,v,O,G,X,G)),at=Math.min(at,m.maxDistance(g,v,x,v,X,st,O,st)),at=Math.min(at,m.maxDistance(g,v,x,v,X,st,X,G)),at=Math.min(at,m.maxDistance(x,k,g,k,O,G,O,st)),at=Math.min(at,m.maxDistance(x,k,g,k,O,G,X,G)),at=Math.min(at,m.maxDistance(x,k,g,k,X,st,O,st)),at=Math.min(at,m.maxDistance(x,k,g,k,X,st,X,G)),at=Math.min(at,m.maxDistance(x,k,x,v,O,G,O,st)),at=Math.min(at,m.maxDistance(x,k,x,v,O,G,X,G)),at=Math.min(at,m.maxDistance(x,k,x,v,X,st,O,st)),at=Math.min(at,m.maxDistance(x,k,x,v,X,st,X,G))}}])})(),Wo=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"maximumDistance",value:function(){return US.maximumDistance(this._boundable1.getBounds(),this._boundable2.getBounds())}},{key:"expandToQueue",value:function(u,c){var g=m.isComposite(this._boundable1),v=m.isComposite(this._boundable2);if(g&&v)return m.area(this._boundable1)>m.area(this._boundable2)?(this.expand(this._boundable1,this._boundable2,!1,u,c),null):(this.expand(this._boundable2,this._boundable1,!0,u,c),null);if(g)return this.expand(this._boundable1,this._boundable2,!1,u,c),null;if(v)return this.expand(this._boundable2,this._boundable1,!0,u,c),null;throw new S("neither boundable is composite")}},{key:"isLeaves",value:function(){return!(m.isComposite(this._boundable1)||m.isComposite(this._boundable2))}},{key:"compareTo",value:function(u){var c=u;return this._distance<c._distance?-1:this._distance>c._distance?1:0}},{key:"expand",value:function(u,c,g,v,x){for(var k=u.getChildBoundables().iterator();k.hasNext();){var O=k.next(),G=null;(G=g?new m(c,O,this._itemDistance):new m(O,c,this._itemDistance)).getDistance()<x&&v.add(G)}}},{key:"getBoundable",value:function(u){return u===0?this._boundable1:this._boundable2}},{key:"getDistance",value:function(){return this._distance}},{key:"distance",value:function(){return this.isLeaves()?this._itemDistance.distance(this._boundable1,this._boundable2):this._boundable1.getBounds().distance(this._boundable2.getBounds())}},{key:"interfaces_",get:function(){return[T]}}],[{key:"constructor_",value:function(){this._boundable1=null,this._boundable2=null,this._distance=null,this._itemDistance=null;var u=arguments[0],c=arguments[1],g=arguments[2];this._boundable1=u,this._boundable2=c,this._itemDistance=g,this._distance=this.distance()}},{key:"area",value:function(u){return u.getBounds().getArea()}},{key:"isComposite",value:function(u){return u instanceof Oi}}])})(),fy=(function(){return a((function m(){s(this,m)}),[{key:"visitItem",value:function(m){}}])})(),Ko=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"queryInternal",value:function(){if(H(arguments[2],fy)&&arguments[0]instanceof Object&&arguments[1]instanceof Oi)for(var u=arguments[0],c=arguments[2],g=arguments[1].getChildBoundables(),v=0;v<g.size();v++){var x=g.get(v);this.getIntersectsOp().intersects(x.getBounds(),u)&&(x instanceof Oi?this.queryInternal(u,x,c):x instanceof nr?c.visitItem(x.getItem()):ct.shouldNeverReachHere())}else if(H(arguments[2],et)&&arguments[0]instanceof Object&&arguments[1]instanceof Oi)for(var k=arguments[0],O=arguments[2],G=arguments[1].getChildBoundables(),X=0;X<G.size();X++){var st=G.get(X);this.getIntersectsOp().intersects(st.getBounds(),k)&&(st instanceof Oi?this.queryInternal(k,st,O):st instanceof nr?O.add(st.getItem()):ct.shouldNeverReachHere())}}},{key:"getNodeCapacity",value:function(){return this._nodeCapacity}},{key:"lastNode",value:function(u){return u.get(u.size()-1)}},{key:"size",value:function(){if(arguments.length===0)return this.isEmpty()?0:(this.build(),this.size(this._root));if(arguments.length===1){for(var u=0,c=arguments[0].getChildBoundables().iterator();c.hasNext();){var g=c.next();g instanceof Oi?u+=this.size(g):g instanceof nr&&(u+=1)}return u}}},{key:"removeItem",value:function(u,c){for(var g=null,v=u.getChildBoundables().iterator();v.hasNext();){var x=v.next();x instanceof nr&&x.getItem()===c&&(g=x)}return g!==null&&(u.getChildBoundables().remove(g),!0)}},{key:"itemsTree",value:function(){if(arguments.length===0){this.build();var u=this.itemsTree(this._root);return u===null?new Bt:u}if(arguments.length===1){for(var c=arguments[0],g=new Bt,v=c.getChildBoundables().iterator();v.hasNext();){var x=v.next();if(x instanceof Oi){var k=this.itemsTree(x);k!==null&&g.add(k)}else x instanceof nr?g.add(x.getItem()):ct.shouldNeverReachHere()}return g.size()<=0?null:g}}},{key:"insert",value:function(u,c){ct.isTrue(!this._built,"Cannot insert items into an STR packed R-tree after it has been built."),this._itemBoundables.add(new nr(u,c))}},{key:"boundablesAtLevel",value:function(){if(arguments.length===1){var u=arguments[0],c=new Bt;return this.boundablesAtLevel(u,this._root,c),c}if(arguments.length===3){var g=arguments[0],v=arguments[1],x=arguments[2];if(ct.isTrue(g>-2),v.getLevel()===g)return x.add(v),null;for(var k=v.getChildBoundables().iterator();k.hasNext();){var O=k.next();O instanceof Oi?this.boundablesAtLevel(g,O,x):(ct.isTrue(O instanceof nr),g===-1&&x.add(O))}return null}}},{key:"query",value:function(){if(arguments.length===1){var u=arguments[0];this.build();var c=new Bt;return this.isEmpty()||this.getIntersectsOp().intersects(this._root.getBounds(),u)&&this.queryInternal(u,this._root,c),c}if(arguments.length===2){var g=arguments[0],v=arguments[1];if(this.build(),this.isEmpty())return null;this.getIntersectsOp().intersects(this._root.getBounds(),g)&&this.queryInternal(g,this._root,v)}}},{key:"build",value:function(){if(this._built)return null;this._root=this._itemBoundables.isEmpty()?this.createNode(0):this.createHigherLevels(this._itemBoundables,-1),this._itemBoundables=null,this._built=!0}},{key:"getRoot",value:function(){return this.build(),this._root}},{key:"remove",value:function(){if(arguments.length===2){var u=arguments[0],c=arguments[1];return this.build(),!!this.getIntersectsOp().intersects(this._root.getBounds(),u)&&this.remove(u,this._root,c)}if(arguments.length===3){var g=arguments[0],v=arguments[1],x=arguments[2],k=this.removeItem(v,x);if(k)return!0;for(var O=null,G=v.getChildBoundables().iterator();G.hasNext();){var X=G.next();if(this.getIntersectsOp().intersects(X.getBounds(),g)&&X instanceof Oi&&(k=this.remove(g,X,x))){O=X;break}}return O!==null&&O.getChildBoundables().isEmpty()&&v.getChildBoundables().remove(O),k}}},{key:"createHigherLevels",value:function(u,c){ct.isTrue(!u.isEmpty());var g=this.createParentBoundables(u,c+1);return g.size()===1?g.get(0):this.createHigherLevels(g,c+1)}},{key:"depth",value:function(){if(arguments.length===0)return this.isEmpty()?0:(this.build(),this.depth(this._root));if(arguments.length===1){for(var u=0,c=arguments[0].getChildBoundables().iterator();c.hasNext();){var g=c.next();if(g instanceof Oi){var v=this.depth(g);v>u&&(u=v)}}return u+1}}},{key:"createParentBoundables",value:function(u,c){ct.isTrue(!u.isEmpty());var g=new Bt;g.add(this.createNode(c));var v=new Bt(u);Ho.sort(v,this.getComparator());for(var x=v.iterator();x.hasNext();){var k=x.next();this.lastNode(g).getChildBoundables().size()===this.getNodeCapacity()&&g.add(this.createNode(c)),this.lastNode(g).addChildBoundable(k)}return g}},{key:"isEmpty",value:function(){return this._built?this._root.isEmpty():this._itemBoundables.isEmpty()}},{key:"interfaces_",get:function(){return[M]}}],[{key:"constructor_",value:function(){if(this._root=null,this._built=!1,this._itemBoundables=new Bt,this._nodeCapacity=null,arguments.length===0)m.constructor_.call(this,m.DEFAULT_NODE_CAPACITY);else if(arguments.length===1){var u=arguments[0];ct.isTrue(u>1,"Node capacity must be greater than 1"),this._nodeCapacity=u}}},{key:"compareDoubles",value:function(u,c){return u>c?1:u<c?-1:0}}])})();Ko.IntersectsOp=function(){},Ko.DEFAULT_NODE_CAPACITY=10;var YS=(function(){return a((function m(){s(this,m)}),[{key:"distance",value:function(m,u){}}])})(),Cs=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,[{key:"createParentBoundablesFromVerticalSlices",value:function(c,g){ct.isTrue(c.length>0);for(var v=new Bt,x=0;x<c.length;x++)v.addAll(this.createParentBoundablesFromVerticalSlice(c[x],g));return v}},{key:"nearestNeighbourK",value:function(){if(arguments.length===2){var c=arguments[0],g=arguments[1];return this.nearestNeighbourK(c,W.POSITIVE_INFINITY,g)}if(arguments.length===3){var v=arguments[0],x=arguments[2],k=arguments[1],O=new Dc;O.add(v);for(var G=new Dc;!O.isEmpty()&&k>=0;){var X=O.poll(),st=X.getDistance();if(st>=k)break;X.isLeaves()?G.size()<x?G.add(X):(G.peek().getDistance()>st&&(G.poll(),G.add(X)),k=G.peek().getDistance()):X.expandToQueue(O,k)}return u.getItems(G)}}},{key:"createNode",value:function(c){return new dy(c)}},{key:"size",value:function(){return arguments.length===0?_(u,"size",this,1).call(this):_(u,"size",this,1).apply(this,arguments)}},{key:"insert",value:function(){if(!(arguments.length===2&&arguments[1]instanceof Object&&arguments[0]instanceof Dt))return _(u,"insert",this,1).apply(this,arguments);var c=arguments[0],g=arguments[1];if(c.isNull())return null;_(u,"insert",this,1).call(this,c,g)}},{key:"getIntersectsOp",value:function(){return u.intersectsOp}},{key:"verticalSlices",value:function(c,g){for(var v=Math.trunc(Math.ceil(c.size()/g)),x=new Array(g).fill(null),k=c.iterator(),O=0;O<g;O++){x[O]=new Bt;for(var G=0;k.hasNext()&&G<v;){var X=k.next();x[O].add(X),G++}}return x}},{key:"query",value:function(){if(arguments.length===1){var c=arguments[0];return _(u,"query",this,1).call(this,c)}if(arguments.length===2){var g=arguments[0],v=arguments[1];_(u,"query",this,1).call(this,g,v)}}},{key:"getComparator",value:function(){return u.yComparator}},{key:"createParentBoundablesFromVerticalSlice",value:function(c,g){return _(u,"createParentBoundables",this,1).call(this,c,g)}},{key:"remove",value:function(){if(arguments.length===2&&arguments[1]instanceof Object&&arguments[0]instanceof Dt){var c=arguments[0],g=arguments[1];return _(u,"remove",this,1).call(this,c,g)}return _(u,"remove",this,1).apply(this,arguments)}},{key:"depth",value:function(){return arguments.length===0?_(u,"depth",this,1).call(this):_(u,"depth",this,1).apply(this,arguments)}},{key:"createParentBoundables",value:function(c,g){ct.isTrue(!c.isEmpty());var v=Math.trunc(Math.ceil(c.size()/this.getNodeCapacity())),x=new Bt(c);Ho.sort(x,u.xComparator);var k=this.verticalSlices(x,Math.trunc(Math.ceil(Math.sqrt(v))));return this.createParentBoundablesFromVerticalSlices(k,g)}},{key:"nearestNeighbour",value:function(){if(arguments.length===1){if(H(arguments[0],YS)){var c=arguments[0];if(this.isEmpty())return null;var g=new Wo(this.getRoot(),this.getRoot(),c);return this.nearestNeighbour(g)}if(arguments[0]instanceof Wo){var v=arguments[0],x=W.POSITIVE_INFINITY,k=null,O=new Dc;for(O.add(v);!O.isEmpty()&&x>0;){var G=O.poll(),X=G.getDistance();if(X>=x)break;G.isLeaves()?(x=X,k=G):G.expandToQueue(O,x)}return k===null?null:[k.getBoundable(0).getItem(),k.getBoundable(1).getItem()]}}else{if(arguments.length===2){var st=arguments[0],at=arguments[1];if(this.isEmpty()||st.isEmpty())return null;var mt=new Wo(this.getRoot(),st.getRoot(),at);return this.nearestNeighbour(mt)}if(arguments.length===3){var Pt=arguments[2],Ft=new nr(arguments[0],arguments[1]),qt=new Wo(this.getRoot(),Ft,Pt);return this.nearestNeighbour(qt)[0]}if(arguments.length===4){var fe=arguments[2],le=arguments[3],ke=new nr(arguments[0],arguments[1]),xn=new Wo(this.getRoot(),ke,fe);return this.nearestNeighbourK(xn,le)}}}},{key:"isWithinDistance",value:function(){if(arguments.length===2){var c=arguments[0],g=arguments[1],v=W.POSITIVE_INFINITY,x=new Dc;for(x.add(c);!x.isEmpty();){var k=x.poll(),O=k.getDistance();if(O>g)return!1;if(k.maximumDistance()<=g)return!0;if(k.isLeaves()){if((v=O)<=g)return!0}else k.expandToQueue(x,v)}return!1}if(arguments.length===3){var G=arguments[0],X=arguments[1],st=arguments[2],at=new Wo(this.getRoot(),G.getRoot(),X);return this.isWithinDistance(at,st)}}},{key:"interfaces_",get:function(){return[zS,M]}}],[{key:"constructor_",value:function(){if(arguments.length===0)u.constructor_.call(this,u.DEFAULT_NODE_CAPACITY);else if(arguments.length===1){var c=arguments[0];Ko.constructor_.call(this,c)}}},{key:"centreX",value:function(c){return u.avg(c.getMinX(),c.getMaxX())}},{key:"avg",value:function(c,g){return(c+g)/2}},{key:"getItems",value:function(c){for(var g=new Array(c.size()).fill(null),v=0;!c.isEmpty();){var x=c.poll();g[v]=x.getBoundable(0).getItem(),v++}return g}},{key:"centreY",value:function(c){return u.avg(c.getMinY(),c.getMaxY())}}])})(Ko),dy=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,[{key:"computeBounds",value:function(){for(var c=null,g=this.getChildBoundables().iterator();g.hasNext();){var v=g.next();c===null?c=new Dt(v.getBounds()):c.expandToInclude(v.getBounds())}return c}}],[{key:"constructor_",value:function(){var c=arguments[0];Oi.constructor_.call(this,c)}}])})(Oi);Cs.STRtreeNode=dy,Cs.xComparator=new((function(){return a((function m(){s(this,m)}),[{key:"interfaces_",get:function(){return[J]}},{key:"compare",value:function(m,u){return Ko.compareDoubles(Cs.centreX(m.getBounds()),Cs.centreX(u.getBounds()))}}])})()),Cs.yComparator=new((function(){return a((function m(){s(this,m)}),[{key:"interfaces_",get:function(){return[J]}},{key:"compare",value:function(m,u){return Ko.compareDoubles(Cs.centreY(m.getBounds()),Cs.centreY(u.getBounds()))}}])})()),Cs.intersectsOp=new((function(){return a((function m(){s(this,m)}),[{key:"interfaces_",get:function(){return[IntersectsOp]}},{key:"intersects",value:function(m,u){return m.intersects(u)}}])})()),Cs.DEFAULT_NODE_CAPACITY=10;var XS=(function(){function m(){s(this,m)}return a(m,null,[{key:"relativeSign",value:function(u,c){return u<c?-1:u>c?1:0}},{key:"compare",value:function(u,c,g){if(c.equals2D(g))return 0;var v=m.relativeSign(c.x,g.x),x=m.relativeSign(c.y,g.y);switch(u){case 0:return m.compareValue(v,x);case 1:return m.compareValue(x,v);case 2:return m.compareValue(x,-v);case 3:return m.compareValue(-v,x);case 4:return m.compareValue(-v,-x);case 5:return m.compareValue(-x,-v);case 6:return m.compareValue(-x,v);case 7:return m.compareValue(v,-x)}return ct.shouldNeverReachHere("invalid octant value"),0}},{key:"compareValue",value:function(u,c){return u<0?-1:u>0?1:c<0?-1:c>0?1:0}}])})(),jS=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"getCoordinate",value:function(){return this.coord}},{key:"print",value:function(m){m.print(this.coord),m.print(" seg # = "+this.segmentIndex)}},{key:"compareTo",value:function(m){var u=m;return this.segmentIndex<u.segmentIndex?-1:this.segmentIndex>u.segmentIndex?1:this.coord.equals2D(u.coord)?0:this._isInterior?u._isInterior?XS.compare(this._segmentOctant,this.coord,u.coord):1:-1}},{key:"isEndPoint",value:function(m){return this.segmentIndex===0&&!this._isInterior||this.segmentIndex===m}},{key:"toString",value:function(){return this.segmentIndex+":"+this.coord.toString()}},{key:"isInterior",value:function(){return this._isInterior}},{key:"interfaces_",get:function(){return[T]}}],[{key:"constructor_",value:function(){this._segString=null,this.coord=null,this.segmentIndex=null,this._segmentOctant=null,this._isInterior=null;var m=arguments[0],u=arguments[1],c=arguments[2],g=arguments[3];this._segString=m,this.coord=new Q(u),this.segmentIndex=c,this._segmentOctant=g,this._isInterior=!u.equals2D(m.getCoordinate(c))}}])})(),VS=(function(){return a((function m(){s(this,m)}),[{key:"hasNext",value:function(){}},{key:"next",value:function(){}},{key:"remove",value:function(){}}])})(),HS=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"getSplitCoordinates",value:function(){var m=new Fl;this.addEndpoints();for(var u=this.iterator(),c=u.next();u.hasNext();){var g=u.next();this.addEdgeCoordinates(c,g,m),c=g}return m.toCoordinateArray()}},{key:"addCollapsedNodes",value:function(){var m=new Bt;this.findCollapsesFromInsertedNodes(m),this.findCollapsesFromExistingVertices(m);for(var u=m.iterator();u.hasNext();){var c=u.next().intValue();this.add(this._edge.getCoordinate(c),c)}}},{key:"createSplitEdgePts",value:function(m,u){var c=u.segmentIndex-m.segmentIndex+2;if(c===2)return[new Q(m.coord),new Q(u.coord)];var g=this._edge.getCoordinate(u.segmentIndex),v=u.isInterior()||!u.coord.equals2D(g);v||c--;var x=new Array(c).fill(null),k=0;x[k++]=new Q(m.coord);for(var O=m.segmentIndex+1;O<=u.segmentIndex;O++)x[k++]=this._edge.getCoordinate(O);return v&&(x[k]=new Q(u.coord)),x}},{key:"print",value:function(m){m.println("Intersections:");for(var u=this.iterator();u.hasNext();)u.next().print(m)}},{key:"findCollapsesFromExistingVertices",value:function(m){for(var u=0;u<this._edge.size()-2;u++){var c=this._edge.getCoordinate(u);this._edge.getCoordinate(u+1);var g=this._edge.getCoordinate(u+2);c.equals2D(g)&&m.add(ot.valueOf(u+1))}}},{key:"addEdgeCoordinates",value:function(m,u,c){var g=this.createSplitEdgePts(m,u);c.add(g,!1)}},{key:"iterator",value:function(){return this._nodeMap.values().iterator()}},{key:"addSplitEdges",value:function(m){this.addEndpoints(),this.addCollapsedNodes();for(var u=this.iterator(),c=u.next();u.hasNext();){var g=u.next(),v=this.createSplitEdge(c,g);m.add(v),c=g}}},{key:"findCollapseIndex",value:function(m,u,c){if(!m.coord.equals2D(u.coord))return!1;var g=u.segmentIndex-m.segmentIndex;return u.isInterior()||g--,g===1&&(c[0]=m.segmentIndex+1,!0)}},{key:"findCollapsesFromInsertedNodes",value:function(m){for(var u=new Array(1).fill(null),c=this.iterator(),g=c.next();c.hasNext();){var v=c.next();this.findCollapseIndex(g,v,u)&&m.add(ot.valueOf(u[0])),g=v}}},{key:"getEdge",value:function(){return this._edge}},{key:"addEndpoints",value:function(){var m=this._edge.size()-1;this.add(this._edge.getCoordinate(0),0),this.add(this._edge.getCoordinate(m),m)}},{key:"createSplitEdge",value:function(m,u){var c=this.createSplitEdgePts(m,u);return new oo(c,this._edge.getData())}},{key:"add",value:function(m,u){var c=new jS(this._edge,m,u,this._edge.getSegmentOctant(u)),g=this._nodeMap.get(c);return g!==null?(ct.isTrue(g.coord.equals2D(m),"Found equal nodes with different coordinates"),g):(this._nodeMap.put(c,c),c)}},{key:"checkSplitEdgesCorrectness",value:function(m){var u=this._edge.getCoordinates(),c=m.get(0).getCoordinate(0);if(!c.equals2D(u[0]))throw new lt("bad split edge start point at "+c);var g=m.get(m.size()-1).getCoordinates(),v=g[g.length-1];if(!v.equals2D(u[u.length-1]))throw new lt("bad split edge end point at "+v)}}],[{key:"constructor_",value:function(){this._nodeMap=new Gl,this._edge=null;var m=arguments[0];this._edge=m}}])})(),WS=(function(){function m(){s(this,m)}return a(m,null,[{key:"octant",value:function(){if(typeof arguments[0]=="number"&&typeof arguments[1]=="number"){var u=arguments[0],c=arguments[1];if(u===0&&c===0)throw new S("Cannot compute the octant for point ( "+u+", "+c+" )");var g=Math.abs(u),v=Math.abs(c);return u>=0?c>=0?g>=v?0:1:g>=v?7:6:c>=0?g>=v?3:2:g>=v?4:5}if(arguments[0]instanceof Q&&arguments[1]instanceof Q){var x=arguments[0],k=arguments[1],O=k.x-x.x,G=k.y-x.y;if(O===0&&G===0)throw new S("Cannot compute the octant for two identical points "+x);return m.octant(O,G)}}}])})(),KS=(function(){return a((function m(){s(this,m)}),[{key:"getCoordinates",value:function(){}},{key:"size",value:function(){}},{key:"getCoordinate",value:function(m){}},{key:"isClosed",value:function(){}},{key:"setData",value:function(m){}},{key:"getData",value:function(){}}])})(),ZS=(function(){return a((function m(){s(this,m)}),[{key:"addIntersection",value:function(m,u){}},{key:"interfaces_",get:function(){return[KS]}}])})(),oo=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"getCoordinates",value:function(){return this._pts}},{key:"size",value:function(){return this._pts.length}},{key:"getCoordinate",value:function(u){return this._pts[u]}},{key:"isClosed",value:function(){return this._pts[0].equals(this._pts[this._pts.length-1])}},{key:"getSegmentOctant",value:function(u){return u===this._pts.length-1?-1:this.safeOctant(this.getCoordinate(u),this.getCoordinate(u+1))}},{key:"setData",value:function(u){this._data=u}},{key:"safeOctant",value:function(u,c){return u.equals2D(c)?0:WS.octant(u,c)}},{key:"getData",value:function(){return this._data}},{key:"addIntersection",value:function(){if(arguments.length===2){var u=arguments[0],c=arguments[1];this.addIntersectionNode(u,c)}else if(arguments.length===4){var g=arguments[1],v=arguments[3],x=new Q(arguments[0].getIntersection(v));this.addIntersection(x,g)}}},{key:"toString",value:function(){return kd.toLineString(new $l(this._pts))}},{key:"getNodeList",value:function(){return this._nodeList}},{key:"addIntersectionNode",value:function(u,c){var g=c,v=g+1;if(v<this._pts.length){var x=this._pts[v];u.equals2D(x)&&(g=v)}return this._nodeList.add(u,g)}},{key:"addIntersections",value:function(u,c,g){for(var v=0;v<u.getIntersectionNum();v++)this.addIntersection(u,c,g,v)}},{key:"interfaces_",get:function(){return[ZS]}}],[{key:"constructor_",value:function(){this._nodeList=new HS(this),this._pts=null,this._data=null;var u=arguments[0],c=arguments[1];this._pts=u,this._data=c}},{key:"getNodedSubstrings",value:function(){if(arguments.length===1){var u=arguments[0],c=new Bt;return m.getNodedSubstrings(u,c),c}if(arguments.length===2)for(var g=arguments[1],v=arguments[0].iterator();v.hasNext();)v.next().getNodeList().addSplitEdges(g)}}])})(),yi=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"minX",value:function(){return Math.min(this.p0.x,this.p1.x)}},{key:"orientationIndex",value:function(){if(arguments[0]instanceof m){var u=arguments[0],c=At.index(this.p0,this.p1,u.p0),g=At.index(this.p0,this.p1,u.p1);return c>=0&&g>=0||c<=0&&g<=0?Math.max(c,g):0}if(arguments[0]instanceof Q){var v=arguments[0];return At.index(this.p0,this.p1,v)}}},{key:"toGeometry",value:function(u){return u.createLineString([this.p0,this.p1])}},{key:"isVertical",value:function(){return this.p0.x===this.p1.x}},{key:"equals",value:function(u){if(!(u instanceof m))return!1;var c=u;return this.p0.equals(c.p0)&&this.p1.equals(c.p1)}},{key:"intersection",value:function(u){var c=new ro;return c.computeIntersection(this.p0,this.p1,u.p0,u.p1),c.hasIntersection()?c.getIntersection(0):null}},{key:"project",value:function(){if(arguments[0]instanceof Q){var u=arguments[0];if(u.equals(this.p0)||u.equals(this.p1))return new Q(u);var c=this.projectionFactor(u),g=new Q;return g.x=this.p0.x+c*(this.p1.x-this.p0.x),g.y=this.p0.y+c*(this.p1.y-this.p0.y),g}if(arguments[0]instanceof m){var v=arguments[0],x=this.projectionFactor(v.p0),k=this.projectionFactor(v.p1);if(x>=1&&k>=1||x<=0&&k<=0)return null;var O=this.project(v.p0);x<0&&(O=this.p0),x>1&&(O=this.p1);var G=this.project(v.p1);return k<0&&(G=this.p0),k>1&&(G=this.p1),new m(O,G)}}},{key:"normalize",value:function(){this.p1.compareTo(this.p0)<0&&this.reverse()}},{key:"angle",value:function(){return Math.atan2(this.p1.y-this.p0.y,this.p1.x-this.p0.x)}},{key:"getCoordinate",value:function(u){return u===0?this.p0:this.p1}},{key:"distancePerpendicular",value:function(u){return Ns.pointToLinePerpendicular(u,this.p0,this.p1)}},{key:"minY",value:function(){return Math.min(this.p0.y,this.p1.y)}},{key:"midPoint",value:function(){return m.midPoint(this.p0,this.p1)}},{key:"projectionFactor",value:function(u){if(u.equals(this.p0))return 0;if(u.equals(this.p1))return 1;var c=this.p1.x-this.p0.x,g=this.p1.y-this.p0.y,v=c*c+g*g;return v<=0?W.NaN:((u.x-this.p0.x)*c+(u.y-this.p0.y)*g)/v}},{key:"closestPoints",value:function(u){var c=this.intersection(u);if(c!==null)return[c,c];var g=new Array(2).fill(null),v=W.MAX_VALUE,x=null,k=this.closestPoint(u.p0);v=k.distance(u.p0),g[0]=k,g[1]=u.p0;var O=this.closestPoint(u.p1);(x=O.distance(u.p1))<v&&(v=x,g[0]=O,g[1]=u.p1);var G=u.closestPoint(this.p0);(x=G.distance(this.p0))<v&&(v=x,g[0]=this.p0,g[1]=G);var X=u.closestPoint(this.p1);return(x=X.distance(this.p1))<v&&(v=x,g[0]=this.p1,g[1]=X),g}},{key:"closestPoint",value:function(u){var c=this.projectionFactor(u);return c>0&&c<1?this.project(u):this.p0.distance(u)<this.p1.distance(u)?this.p0:this.p1}},{key:"maxX",value:function(){return Math.max(this.p0.x,this.p1.x)}},{key:"getLength",value:function(){return this.p0.distance(this.p1)}},{key:"compareTo",value:function(u){var c=u,g=this.p0.compareTo(c.p0);return g!==0?g:this.p1.compareTo(c.p1)}},{key:"reverse",value:function(){var u=this.p0;this.p0=this.p1,this.p1=u}},{key:"equalsTopo",value:function(u){return this.p0.equals(u.p0)&&this.p1.equals(u.p1)||this.p0.equals(u.p1)&&this.p1.equals(u.p0)}},{key:"lineIntersection",value:function(u){return Tl.intersection(this.p0,this.p1,u.p0,u.p1)}},{key:"maxY",value:function(){return Math.max(this.p0.y,this.p1.y)}},{key:"pointAlongOffset",value:function(u,c){var g=this.p0.x+u*(this.p1.x-this.p0.x),v=this.p0.y+u*(this.p1.y-this.p0.y),x=this.p1.x-this.p0.x,k=this.p1.y-this.p0.y,O=Math.sqrt(x*x+k*k),G=0,X=0;if(c!==0){if(O<=0)throw new IllegalStateException("Cannot compute offset from zero-length line segment");G=c*x/O,X=c*k/O}return new Q(g-X,v+G)}},{key:"setCoordinates",value:function(){if(arguments.length===1){var u=arguments[0];this.setCoordinates(u.p0,u.p1)}else if(arguments.length===2){var c=arguments[0],g=arguments[1];this.p0.x=c.x,this.p0.y=c.y,this.p1.x=g.x,this.p1.y=g.y}}},{key:"segmentFraction",value:function(u){var c=this.projectionFactor(u);return c<0?c=0:(c>1||W.isNaN(c))&&(c=1),c}},{key:"toString",value:function(){return"LINESTRING( "+this.p0.x+" "+this.p0.y+", "+this.p1.x+" "+this.p1.y+")"}},{key:"isHorizontal",value:function(){return this.p0.y===this.p1.y}},{key:"reflect",value:function(u){var c=this.p1.getY()-this.p0.getY(),g=this.p0.getX()-this.p1.getX(),v=this.p0.getY()*(this.p1.getX()-this.p0.getX())-this.p0.getX()*(this.p1.getY()-this.p0.getY()),x=c*c+g*g,k=c*c-g*g,O=u.getX(),G=u.getY();return new Q((-k*O-2*c*g*G-2*c*v)/x,(k*G-2*c*g*O-2*g*v)/x)}},{key:"distance",value:function(){if(arguments[0]instanceof m){var u=arguments[0];return Ns.segmentToSegment(this.p0,this.p1,u.p0,u.p1)}if(arguments[0]instanceof Q){var c=arguments[0];return Ns.pointToSegment(c,this.p0,this.p1)}}},{key:"pointAlong",value:function(u){var c=new Q;return c.x=this.p0.x+u*(this.p1.x-this.p0.x),c.y=this.p0.y+u*(this.p1.y-this.p0.y),c}},{key:"hashCode",value:function(){var u=W.doubleToLongBits(this.p0.x);u^=31*W.doubleToLongBits(this.p0.y);var c=Math.trunc(u)^Math.trunc(u>>32),g=W.doubleToLongBits(this.p1.x);return g^=31*W.doubleToLongBits(this.p1.y),c^(Math.trunc(g)^Math.trunc(g>>32))}},{key:"interfaces_",get:function(){return[T,M]}}],[{key:"constructor_",value:function(){if(this.p0=null,this.p1=null,arguments.length===0)m.constructor_.call(this,new Q,new Q);else if(arguments.length===1){var u=arguments[0];m.constructor_.call(this,u.p0,u.p1)}else if(arguments.length===2){var c=arguments[0],g=arguments[1];this.p0=c,this.p1=g}else if(arguments.length===4){var v=arguments[0],x=arguments[1],k=arguments[2],O=arguments[3];m.constructor_.call(this,new Q(v,x),new Q(k,O))}}},{key:"midPoint",value:function(u,c){return new Q((u.x+c.x)/2,(u.y+c.y)/2)}}])})(),JS=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"overlap",value:function(){if(arguments.length!==2){if(arguments.length===4){var m=arguments[1],u=arguments[2],c=arguments[3];arguments[0].getLineSegment(m,this._overlapSeg1),u.getLineSegment(c,this._overlapSeg2),this.overlap(this._overlapSeg1,this._overlapSeg2)}}}}],[{key:"constructor_",value:function(){this._overlapSeg1=new yi,this._overlapSeg2=new yi}}])})(),gy=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"getLineSegment",value:function(m,u){u.p0=this._pts[m],u.p1=this._pts[m+1]}},{key:"computeSelect",value:function(m,u,c,g){var v=this._pts[u],x=this._pts[c];if(c-u==1)return g.select(this,u),null;if(!m.intersects(v,x))return null;var k=Math.trunc((u+c)/2);u<k&&this.computeSelect(m,u,k,g),k<c&&this.computeSelect(m,k,c,g)}},{key:"getCoordinates",value:function(){for(var m=new Array(this._end-this._start+1).fill(null),u=0,c=this._start;c<=this._end;c++)m[u++]=this._pts[c];return m}},{key:"computeOverlaps",value:function(){if(arguments.length===2){var m=arguments[0],u=arguments[1];this.computeOverlaps(this._start,this._end,m,m._start,m._end,u)}else if(arguments.length===6){var c=arguments[0],g=arguments[1],v=arguments[2],x=arguments[3],k=arguments[4],O=arguments[5];if(g-c==1&&k-x==1)return O.overlap(this,c,v,x),null;if(!this.overlaps(c,g,v,x,k))return null;var G=Math.trunc((c+g)/2),X=Math.trunc((x+k)/2);c<G&&(x<X&&this.computeOverlaps(c,G,v,x,X,O),X<k&&this.computeOverlaps(c,G,v,X,k,O)),G<g&&(x<X&&this.computeOverlaps(G,g,v,x,X,O),X<k&&this.computeOverlaps(G,g,v,X,k,O))}}},{key:"setId",value:function(m){this._id=m}},{key:"select",value:function(m,u){this.computeSelect(m,this._start,this._end,u)}},{key:"getEnvelope",value:function(){if(this._env===null){var m=this._pts[this._start],u=this._pts[this._end];this._env=new Dt(m,u)}return this._env}},{key:"overlaps",value:function(m,u,c,g,v){return Dt.intersects(this._pts[m],this._pts[u],c._pts[g],c._pts[v])}},{key:"getEndIndex",value:function(){return this._end}},{key:"getStartIndex",value:function(){return this._start}},{key:"getContext",value:function(){return this._context}},{key:"getId",value:function(){return this._id}}],[{key:"constructor_",value:function(){this._pts=null,this._start=null,this._end=null,this._env=null,this._context=null,this._id=null;var m=arguments[0],u=arguments[1],c=arguments[2],g=arguments[3];this._pts=m,this._start=u,this._end=c,this._context=g}}])})(),QS=(function(){function m(){s(this,m)}return a(m,null,[{key:"findChainEnd",value:function(u,c){for(var g=c;g<u.length-1&&u[g].equals2D(u[g+1]);)g++;if(g>=u.length-1)return u.length-1;for(var v=Gn.quadrant(u[g],u[g+1]),x=c+1;x<u.length&&!(!u[x-1].equals2D(u[x])&&Gn.quadrant(u[x-1],u[x])!==v);)x++;return x-1}},{key:"getChains",value:function(){if(arguments.length===1){var u=arguments[0];return m.getChains(u,null)}if(arguments.length===2){var c=arguments[0],g=arguments[1],v=new Bt,x=0;do{var k=m.findChainEnd(c,x),O=new gy(c,x,k,g);v.add(O),x=k}while(x<c.length-1);return v}}}])})(),Od=(function(){return a((function m(){s(this,m)}),[{key:"computeNodes",value:function(m){}},{key:"getNodedSubstrings",value:function(){}}])})(),my=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"setSegmentIntersector",value:function(m){this._segInt=m}},{key:"interfaces_",get:function(){return[Od]}}],[{key:"constructor_",value:function(){if(this._segInt=null,arguments.length!==0){if(arguments.length===1){var m=arguments[0];this.setSegmentIntersector(m)}}}}])})(),Fd=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,[{key:"getMonotoneChains",value:function(){return this._monoChains}},{key:"getNodedSubstrings",value:function(){return oo.getNodedSubstrings(this._nodedSegStrings)}},{key:"getIndex",value:function(){return this._index}},{key:"add",value:function(c){for(var g=QS.getChains(c.getCoordinates(),c).iterator();g.hasNext();){var v=g.next();v.setId(this._idCounter++),this._index.insert(v.getEnvelope(),v),this._monoChains.add(v)}}},{key:"computeNodes",value:function(c){this._nodedSegStrings=c;for(var g=c.iterator();g.hasNext();)this.add(g.next());this.intersectChains()}},{key:"intersectChains",value:function(){for(var c=new py(this._segInt),g=this._monoChains.iterator();g.hasNext();)for(var v=g.next(),x=this._index.query(v.getEnvelope()).iterator();x.hasNext();){var k=x.next();if(k.getId()>v.getId()&&(v.computeOverlaps(k,c),this._nOverlaps++),this._segInt.isDone())return null}}}],[{key:"constructor_",value:function(){if(this._monoChains=new Bt,this._index=new Cs,this._idCounter=0,this._nodedSegStrings=null,this._nOverlaps=0,arguments.length!==0){if(arguments.length===1){var c=arguments[0];my.constructor_.call(this,c)}}}}])})(my),py=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,[{key:"overlap",value:function(){if(arguments.length!==4)return _(u,"overlap",this,1).apply(this,arguments);var c=arguments[1],g=arguments[2],v=arguments[3],x=arguments[0].getContext(),k=g.getContext();this._si.processIntersections(x,c,k,v)}}],[{key:"constructor_",value:function(){this._si=null;var c=arguments[0];this._si=c}}])})(JS);Fd.SegmentOverlapAction=py;var os=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"isDeletable",value:function(u,c,g,v){var x=this._inputLine[u],k=this._inputLine[c],O=this._inputLine[g];return!!this.isConcave(x,k,O)&&!!this.isShallow(x,k,O,v)&&this.isShallowSampled(x,k,u,g,v)}},{key:"deleteShallowConcavities",value:function(){for(var u=1,c=this.findNextNonDeletedIndex(u),g=this.findNextNonDeletedIndex(c),v=!1;g<this._inputLine.length;){var x=!1;this.isDeletable(u,c,g,this._distanceTol)&&(this._isDeleted[c]=m.DELETE,x=!0,v=!0),u=x?g:c,c=this.findNextNonDeletedIndex(u),g=this.findNextNonDeletedIndex(c)}return v}},{key:"isShallowConcavity",value:function(u,c,g,v){return At.index(u,c,g)===this._angleOrientation&&Ns.pointToSegment(c,u,g)<v}},{key:"isShallowSampled",value:function(u,c,g,v,x){var k=Math.trunc((v-g)/m.NUM_PTS_TO_CHECK);k<=0&&(k=1);for(var O=g;O<v;O+=k)if(!this.isShallow(u,c,this._inputLine[O],x))return!1;return!0}},{key:"isConcave",value:function(u,c,g){var v=At.index(u,c,g)===this._angleOrientation;return v}},{key:"simplify",value:function(u){this._distanceTol=Math.abs(u),u<0&&(this._angleOrientation=At.CLOCKWISE),this._isDeleted=new Array(this._inputLine.length).fill(null);var c=!1;do c=this.deleteShallowConcavities();while(c);return this.collapseLine()}},{key:"findNextNonDeletedIndex",value:function(u){for(var c=u+1;c<this._inputLine.length&&this._isDeleted[c]===m.DELETE;)c++;return c}},{key:"isShallow",value:function(u,c,g,v){return Ns.pointToSegment(c,u,g)<v}},{key:"collapseLine",value:function(){for(var u=new Fl,c=0;c<this._inputLine.length;c++)this._isDeleted[c]!==m.DELETE&&u.add(this._inputLine[c]);return u.toCoordinateArray()}}],[{key:"constructor_",value:function(){this._inputLine=null,this._distanceTol=null,this._isDeleted=null,this._angleOrientation=At.COUNTERCLOCKWISE;var u=arguments[0];this._inputLine=u}},{key:"simplify",value:function(u,c){return new m(u).simplify(c)}}])})();os.INIT=0,os.DELETE=1,os.KEEP=1,os.NUM_PTS_TO_CHECK=10;var yy=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"getCoordinates",value:function(){return this._ptList.toArray(m.COORDINATE_ARRAY_TYPE)}},{key:"setPrecisionModel",value:function(u){this._precisionModel=u}},{key:"addPt",value:function(u){var c=new Q(u);if(this._precisionModel.makePrecise(c),this.isRedundant(c))return null;this._ptList.add(c)}},{key:"reverse",value:function(){}},{key:"addPts",value:function(u,c){if(c)for(var g=0;g<u.length;g++)this.addPt(u[g]);else for(var v=u.length-1;v>=0;v--)this.addPt(u[v])}},{key:"isRedundant",value:function(u){if(this._ptList.size()<1)return!1;var c=this._ptList.get(this._ptList.size()-1);return u.distance(c)<this._minimimVertexDistance}},{key:"toString",value:function(){return new jo().createLineString(this.getCoordinates()).toString()}},{key:"closeRing",value:function(){if(this._ptList.size()<1)return null;var u=new Q(this._ptList.get(0)),c=this._ptList.get(this._ptList.size()-1);if(u.equals(c))return null;this._ptList.add(u)}},{key:"setMinimumVertexDistance",value:function(u){this._minimimVertexDistance=u}}],[{key:"constructor_",value:function(){this._ptList=null,this._precisionModel=null,this._minimimVertexDistance=0,this._ptList=new Bt}}])})();yy.COORDINATE_ARRAY_TYPE=new Array(0).fill(null);var _i=(function(){function m(){s(this,m)}return a(m,null,[{key:"toDegrees",value:function(u){return 180*u/Math.PI}},{key:"normalize",value:function(u){for(;u>Math.PI;)u-=m.PI_TIMES_2;for(;u<=-Math.PI;)u+=m.PI_TIMES_2;return u}},{key:"angle",value:function(){if(arguments.length===1){var u=arguments[0];return Math.atan2(u.y,u.x)}if(arguments.length===2){var c=arguments[0],g=arguments[1],v=g.x-c.x,x=g.y-c.y;return Math.atan2(x,v)}}},{key:"isAcute",value:function(u,c,g){var v=u.x-c.x,x=u.y-c.y;return v*(g.x-c.x)+x*(g.y-c.y)>0}},{key:"isObtuse",value:function(u,c,g){var v=u.x-c.x,x=u.y-c.y;return v*(g.x-c.x)+x*(g.y-c.y)<0}},{key:"interiorAngle",value:function(u,c,g){var v=m.angle(c,u),x=m.angle(c,g);return Math.abs(x-v)}},{key:"normalizePositive",value:function(u){if(u<0){for(;u<0;)u+=m.PI_TIMES_2;u>=m.PI_TIMES_2&&(u=0)}else{for(;u>=m.PI_TIMES_2;)u-=m.PI_TIMES_2;u<0&&(u=0)}return u}},{key:"angleBetween",value:function(u,c,g){var v=m.angle(c,u),x=m.angle(c,g);return m.diff(v,x)}},{key:"diff",value:function(u,c){var g=null;return(g=u<c?c-u:u-c)>Math.PI&&(g=2*Math.PI-g),g}},{key:"toRadians",value:function(u){return u*Math.PI/180}},{key:"getTurn",value:function(u,c){var g=Math.sin(c-u);return g>0?m.COUNTERCLOCKWISE:g<0?m.CLOCKWISE:m.NONE}},{key:"angleBetweenOriented",value:function(u,c,g){var v=m.angle(c,u),x=m.angle(c,g)-v;return x<=-Math.PI?x+m.PI_TIMES_2:x>Math.PI?x-m.PI_TIMES_2:x}}])})();_i.PI_TIMES_2=2*Math.PI,_i.PI_OVER_2=Math.PI/2,_i.PI_OVER_4=Math.PI/4,_i.COUNTERCLOCKWISE=At.COUNTERCLOCKWISE,_i.CLOCKWISE=At.CLOCKWISE,_i.NONE=At.COLLINEAR;var Bl=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"addNextSegment",value:function(u,c){if(this._s0=this._s1,this._s1=this._s2,this._s2=u,this._seg0.setCoordinates(this._s0,this._s1),this.computeOffsetSegment(this._seg0,this._side,this._distance,this._offset0),this._seg1.setCoordinates(this._s1,this._s2),this.computeOffsetSegment(this._seg1,this._side,this._distance,this._offset1),this._s1.equals(this._s2))return null;var g=At.index(this._s0,this._s1,this._s2),v=g===At.CLOCKWISE&&this._side===Et.LEFT||g===At.COUNTERCLOCKWISE&&this._side===Et.RIGHT;g===0?this.addCollinear(c):v?this.addOutsideTurn(g,c):this.addInsideTurn(g,c)}},{key:"addLineEndCap",value:function(u,c){var g=new yi(u,c),v=new yi;this.computeOffsetSegment(g,Et.LEFT,this._distance,v);var x=new yi;this.computeOffsetSegment(g,Et.RIGHT,this._distance,x);var k=c.x-u.x,O=c.y-u.y,G=Math.atan2(O,k);switch(this._bufParams.getEndCapStyle()){case P.CAP_ROUND:this._segList.addPt(v.p1),this.addDirectedFillet(c,G+Math.PI/2,G-Math.PI/2,At.CLOCKWISE,this._distance),this._segList.addPt(x.p1);break;case P.CAP_FLAT:this._segList.addPt(v.p1),this._segList.addPt(x.p1);break;case P.CAP_SQUARE:var X=new Q;X.x=Math.abs(this._distance)*Math.cos(G),X.y=Math.abs(this._distance)*Math.sin(G);var st=new Q(v.p1.x+X.x,v.p1.y+X.y),at=new Q(x.p1.x+X.x,x.p1.y+X.y);this._segList.addPt(st),this._segList.addPt(at)}}},{key:"getCoordinates",value:function(){return this._segList.getCoordinates()}},{key:"addMitreJoin",value:function(u,c,g,v){var x=Tl.intersection(c.p0,c.p1,g.p0,g.p1);if(x!==null&&(v<=0?1:x.distance(u)/Math.abs(v))<=this._bufParams.getMitreLimit())return this._segList.addPt(x),null;this.addLimitedMitreJoin(c,g,v,this._bufParams.getMitreLimit())}},{key:"addOutsideTurn",value:function(u,c){if(this._offset0.p1.distance(this._offset1.p0)<this._distance*m.OFFSET_SEGMENT_SEPARATION_FACTOR)return this._segList.addPt(this._offset0.p1),null;this._bufParams.getJoinStyle()===P.JOIN_MITRE?this.addMitreJoin(this._s1,this._offset0,this._offset1,this._distance):this._bufParams.getJoinStyle()===P.JOIN_BEVEL?this.addBevelJoin(this._offset0,this._offset1):(c&&this._segList.addPt(this._offset0.p1),this.addCornerFillet(this._s1,this._offset0.p1,this._offset1.p0,u,this._distance),this._segList.addPt(this._offset1.p0))}},{key:"createSquare",value:function(u){this._segList.addPt(new Q(u.x+this._distance,u.y+this._distance)),this._segList.addPt(new Q(u.x+this._distance,u.y-this._distance)),this._segList.addPt(new Q(u.x-this._distance,u.y-this._distance)),this._segList.addPt(new Q(u.x-this._distance,u.y+this._distance)),this._segList.closeRing()}},{key:"addSegments",value:function(u,c){this._segList.addPts(u,c)}},{key:"addFirstSegment",value:function(){this._segList.addPt(this._offset1.p0)}},{key:"addCornerFillet",value:function(u,c,g,v,x){var k=c.x-u.x,O=c.y-u.y,G=Math.atan2(O,k),X=g.x-u.x,st=g.y-u.y,at=Math.atan2(st,X);v===At.CLOCKWISE?G<=at&&(G+=2*Math.PI):G>=at&&(G-=2*Math.PI),this._segList.addPt(c),this.addDirectedFillet(u,G,at,v,x),this._segList.addPt(g)}},{key:"addLastSegment",value:function(){this._segList.addPt(this._offset1.p1)}},{key:"initSideSegments",value:function(u,c,g){this._s1=u,this._s2=c,this._side=g,this._seg1.setCoordinates(u,c),this.computeOffsetSegment(this._seg1,g,this._distance,this._offset1)}},{key:"addLimitedMitreJoin",value:function(u,c,g,v){var x=this._seg0.p1,k=_i.angle(x,this._seg0.p0),O=_i.angleBetweenOriented(this._seg0.p0,x,this._seg1.p1)/2,G=_i.normalize(k+O),X=_i.normalize(G+Math.PI),st=v*g,at=g-st*Math.abs(Math.sin(O)),mt=x.x+st*Math.cos(X),Pt=x.y+st*Math.sin(X),Ft=new Q(mt,Pt),qt=new yi(x,Ft),fe=qt.pointAlongOffset(1,at),le=qt.pointAlongOffset(1,-at);this._side===Et.LEFT?(this._segList.addPt(fe),this._segList.addPt(le)):(this._segList.addPt(le),this._segList.addPt(fe))}},{key:"addDirectedFillet",value:function(u,c,g,v,x){var k=v===At.CLOCKWISE?-1:1,O=Math.abs(c-g),G=Math.trunc(O/this._filletAngleQuantum+.5);if(G<1)return null;for(var X=O/G,st=new Q,at=0;at<G;at++){var mt=c+k*at*X;st.x=u.x+x*Math.cos(mt),st.y=u.y+x*Math.sin(mt),this._segList.addPt(st)}}},{key:"computeOffsetSegment",value:function(u,c,g,v){var x=c===Et.LEFT?1:-1,k=u.p1.x-u.p0.x,O=u.p1.y-u.p0.y,G=Math.sqrt(k*k+O*O),X=x*g*k/G,st=x*g*O/G;v.p0.x=u.p0.x-st,v.p0.y=u.p0.y+X,v.p1.x=u.p1.x-st,v.p1.y=u.p1.y+X}},{key:"addInsideTurn",value:function(u,c){if(this._li.computeIntersection(this._offset0.p0,this._offset0.p1,this._offset1.p0,this._offset1.p1),this._li.hasIntersection())this._segList.addPt(this._li.getIntersection(0));else if(this._hasNarrowConcaveAngle=!0,this._offset0.p1.distance(this._offset1.p0)<this._distance*m.INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR)this._segList.addPt(this._offset0.p1);else{if(this._segList.addPt(this._offset0.p1),this._closingSegLengthFactor>0){var g=new Q((this._closingSegLengthFactor*this._offset0.p1.x+this._s1.x)/(this._closingSegLengthFactor+1),(this._closingSegLengthFactor*this._offset0.p1.y+this._s1.y)/(this._closingSegLengthFactor+1));this._segList.addPt(g);var v=new Q((this._closingSegLengthFactor*this._offset1.p0.x+this._s1.x)/(this._closingSegLengthFactor+1),(this._closingSegLengthFactor*this._offset1.p0.y+this._s1.y)/(this._closingSegLengthFactor+1));this._segList.addPt(v)}else this._segList.addPt(this._s1);this._segList.addPt(this._offset1.p0)}}},{key:"createCircle",value:function(u){var c=new Q(u.x+this._distance,u.y);this._segList.addPt(c),this.addDirectedFillet(u,0,2*Math.PI,-1,this._distance),this._segList.closeRing()}},{key:"addBevelJoin",value:function(u,c){this._segList.addPt(u.p1),this._segList.addPt(c.p0)}},{key:"init",value:function(u){this._distance=u,this._maxCurveSegmentError=u*(1-Math.cos(this._filletAngleQuantum/2)),this._segList=new yy,this._segList.setPrecisionModel(this._precisionModel),this._segList.setMinimumVertexDistance(u*m.CURVE_VERTEX_SNAP_DISTANCE_FACTOR)}},{key:"addCollinear",value:function(u){this._li.computeIntersection(this._s0,this._s1,this._s1,this._s2),this._li.getIntersectionNum()>=2&&(this._bufParams.getJoinStyle()===P.JOIN_BEVEL||this._bufParams.getJoinStyle()===P.JOIN_MITRE?(u&&this._segList.addPt(this._offset0.p1),this._segList.addPt(this._offset1.p0)):this.addCornerFillet(this._s1,this._offset0.p1,this._offset1.p0,At.CLOCKWISE,this._distance))}},{key:"closeRing",value:function(){this._segList.closeRing()}},{key:"hasNarrowConcaveAngle",value:function(){return this._hasNarrowConcaveAngle}}],[{key:"constructor_",value:function(){this._maxCurveSegmentError=0,this._filletAngleQuantum=null,this._closingSegLengthFactor=1,this._segList=null,this._distance=0,this._precisionModel=null,this._bufParams=null,this._li=null,this._s0=null,this._s1=null,this._s2=null,this._seg0=new yi,this._seg1=new yi,this._offset0=new yi,this._offset1=new yi,this._side=0,this._hasNarrowConcaveAngle=!1;var u=arguments[0],c=arguments[1],g=arguments[2];this._precisionModel=u,this._bufParams=c,this._li=new ro,this._filletAngleQuantum=Math.PI/2/c.getQuadrantSegments(),c.getQuadrantSegments()>=8&&c.getJoinStyle()===P.JOIN_ROUND&&(this._closingSegLengthFactor=m.MAX_CLOSING_SEG_LEN_FACTOR),this.init(g)}}])})();Bl.OFFSET_SEGMENT_SEPARATION_FACTOR=.001,Bl.INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR=.001,Bl.CURVE_VERTEX_SNAP_DISTANCE_FACTOR=1e-6,Bl.MAX_CLOSING_SEG_LEN_FACTOR=80;var t2=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"getOffsetCurve",value:function(u,c){if(this._distance=c,c===0)return null;var g=c<0,v=Math.abs(c),x=this.getSegGen(v);u.length<=1?this.computePointCurve(u[0],x):this.computeOffsetCurve(u,g,x);var k=x.getCoordinates();return g&&gn.reverse(k),k}},{key:"computeSingleSidedBufferCurve",value:function(u,c,g){var v=this.simplifyTolerance(this._distance);if(c){g.addSegments(u,!0);var x=os.simplify(u,-v),k=x.length-1;g.initSideSegments(x[k],x[k-1],Et.LEFT),g.addFirstSegment();for(var O=k-2;O>=0;O--)g.addNextSegment(x[O],!0)}else{g.addSegments(u,!1);var G=os.simplify(u,v),X=G.length-1;g.initSideSegments(G[0],G[1],Et.LEFT),g.addFirstSegment();for(var st=2;st<=X;st++)g.addNextSegment(G[st],!0)}g.addLastSegment(),g.closeRing()}},{key:"computeRingBufferCurve",value:function(u,c,g){var v=this.simplifyTolerance(this._distance);c===Et.RIGHT&&(v=-v);var x=os.simplify(u,v),k=x.length-1;g.initSideSegments(x[k-1],x[0],c);for(var O=1;O<=k;O++){var G=O!==1;g.addNextSegment(x[O],G)}g.closeRing()}},{key:"computeLineBufferCurve",value:function(u,c){var g=this.simplifyTolerance(this._distance),v=os.simplify(u,g),x=v.length-1;c.initSideSegments(v[0],v[1],Et.LEFT);for(var k=2;k<=x;k++)c.addNextSegment(v[k],!0);c.addLastSegment(),c.addLineEndCap(v[x-1],v[x]);var O=os.simplify(u,-g),G=O.length-1;c.initSideSegments(O[G],O[G-1],Et.LEFT);for(var X=G-2;X>=0;X--)c.addNextSegment(O[X],!0);c.addLastSegment(),c.addLineEndCap(O[1],O[0]),c.closeRing()}},{key:"computePointCurve",value:function(u,c){switch(this._bufParams.getEndCapStyle()){case P.CAP_ROUND:c.createCircle(u);break;case P.CAP_SQUARE:c.createSquare(u)}}},{key:"getLineCurve",value:function(u,c){if(this._distance=c,this.isLineOffsetEmpty(c))return null;var g=Math.abs(c),v=this.getSegGen(g);if(u.length<=1)this.computePointCurve(u[0],v);else if(this._bufParams.isSingleSided()){var x=c<0;this.computeSingleSidedBufferCurve(u,x,v)}else this.computeLineBufferCurve(u,v);return v.getCoordinates()}},{key:"getBufferParameters",value:function(){return this._bufParams}},{key:"simplifyTolerance",value:function(u){return u*this._bufParams.getSimplifyFactor()}},{key:"getRingCurve",value:function(u,c,g){if(this._distance=g,u.length<=2)return this.getLineCurve(u,g);if(g===0)return m.copyCoordinates(u);var v=this.getSegGen(g);return this.computeRingBufferCurve(u,c,v),v.getCoordinates()}},{key:"computeOffsetCurve",value:function(u,c,g){var v=this.simplifyTolerance(this._distance);if(c){var x=os.simplify(u,-v),k=x.length-1;g.initSideSegments(x[k],x[k-1],Et.LEFT),g.addFirstSegment();for(var O=k-2;O>=0;O--)g.addNextSegment(x[O],!0)}else{var G=os.simplify(u,v),X=G.length-1;g.initSideSegments(G[0],G[1],Et.LEFT),g.addFirstSegment();for(var st=2;st<=X;st++)g.addNextSegment(G[st],!0)}g.addLastSegment()}},{key:"isLineOffsetEmpty",value:function(u){return u===0||u<0&&!this._bufParams.isSingleSided()}},{key:"getSegGen",value:function(u){return new Bl(this._precisionModel,this._bufParams,u)}}],[{key:"constructor_",value:function(){this._distance=0,this._precisionModel=null,this._bufParams=null;var u=arguments[0],c=arguments[1];this._precisionModel=u,this._bufParams=c}},{key:"copyCoordinates",value:function(u){for(var c=new Array(u.length).fill(null),g=0;g<c.length;g++)c[g]=new Q(u[g]);return c}}])})(),_y=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"findStabbedSegments",value:function(){if(arguments.length===1){for(var m=arguments[0],u=new Bt,c=this._subgraphs.iterator();c.hasNext();){var g=c.next(),v=g.getEnvelope();m.y<v.getMinY()||m.y>v.getMaxY()||this.findStabbedSegments(m,g.getDirectedEdges(),u)}return u}if(arguments.length===3){if(H(arguments[2],et)&&arguments[0]instanceof Q&&arguments[1]instanceof Ad){for(var x=arguments[0],k=arguments[1],O=arguments[2],G=k.getEdge().getCoordinates(),X=0;X<G.length-1;X++)if(this._seg.p0=G[X],this._seg.p1=G[X+1],this._seg.p0.y>this._seg.p1.y&&this._seg.reverse(),!(Math.max(this._seg.p0.x,this._seg.p1.x)<x.x||this._seg.isHorizontal()||x.y<this._seg.p0.y||x.y>this._seg.p1.y||At.index(this._seg.p0,this._seg.p1,x)===At.RIGHT)){var st=k.getDepth(Et.LEFT);this._seg.p0.equals(G[X])||(st=k.getDepth(Et.RIGHT));var at=new vy(this._seg,st);O.add(at)}}else if(H(arguments[2],et)&&arguments[0]instanceof Q&&H(arguments[1],et))for(var mt=arguments[0],Pt=arguments[2],Ft=arguments[1].iterator();Ft.hasNext();){var qt=Ft.next();qt.isForward()&&this.findStabbedSegments(mt,qt,Pt)}}}},{key:"getDepth",value:function(m){var u=this.findStabbedSegments(m);return u.size()===0?0:Ho.min(u)._leftDepth}}],[{key:"constructor_",value:function(){this._subgraphs=null,this._seg=new yi;var m=arguments[0];this._subgraphs=m}}])})(),vy=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"compareTo",value:function(m){var u=m;if(this._upwardSeg.minX()>=u._upwardSeg.maxX())return 1;if(this._upwardSeg.maxX()<=u._upwardSeg.minX())return-1;var c=this._upwardSeg.orientationIndex(u._upwardSeg);return c!==0||(c=-1*u._upwardSeg.orientationIndex(this._upwardSeg))!==0?c:this._upwardSeg.compareTo(u._upwardSeg)}},{key:"compareX",value:function(m,u){var c=m.p0.compareTo(u.p0);return c!==0?c:m.p1.compareTo(u.p1)}},{key:"toString",value:function(){return this._upwardSeg.toString()}},{key:"interfaces_",get:function(){return[T]}}],[{key:"constructor_",value:function(){this._upwardSeg=null,this._leftDepth=null;var m=arguments[0],u=arguments[1];this._upwardSeg=new yi(m),this._leftDepth=u}}])})();_y.DepthSegment=vy;var Ey=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,null,[{key:"constructor_",value:function(){N.constructor_.call(this,"Projective point not representable on the Cartesian plane.")}}])})(N),$d=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"getY",value:function(){var u=this.y/this.w;if(W.isNaN(u)||W.isInfinite(u))throw new Ey;return u}},{key:"getX",value:function(){var u=this.x/this.w;if(W.isNaN(u)||W.isInfinite(u))throw new Ey;return u}},{key:"getCoordinate",value:function(){var u=new Q;return u.x=this.getX(),u.y=this.getY(),u}}],[{key:"constructor_",value:function(){if(this.x=null,this.y=null,this.w=null,arguments.length===0)this.x=0,this.y=0,this.w=1;else if(arguments.length===1){var u=arguments[0];this.x=u.x,this.y=u.y,this.w=1}else if(arguments.length===2){if(typeof arguments[0]=="number"&&typeof arguments[1]=="number"){var c=arguments[0],g=arguments[1];this.x=c,this.y=g,this.w=1}else if(arguments[0]instanceof m&&arguments[1]instanceof m){var v=arguments[0],x=arguments[1];this.x=v.y*x.w-x.y*v.w,this.y=x.x*v.w-v.x*x.w,this.w=v.x*x.y-x.x*v.y}else if(arguments[0]instanceof Q&&arguments[1]instanceof Q){var k=arguments[0],O=arguments[1];this.x=k.y-O.y,this.y=O.x-k.x,this.w=k.x*O.y-O.x*k.y}}else if(arguments.length===3){var G=arguments[0],X=arguments[1],st=arguments[2];this.x=G,this.y=X,this.w=st}else if(arguments.length===4){var at=arguments[0],mt=arguments[1],Pt=arguments[2],Ft=arguments[3],qt=at.y-mt.y,fe=mt.x-at.x,le=at.x*mt.y-mt.x*at.y,ke=Pt.y-Ft.y,xn=Ft.x-Pt.x,Pn=Pt.x*Ft.y-Ft.x*Pt.y;this.x=fe*Pn-xn*le,this.y=ke*le-qt*Pn,this.w=qt*xn-ke*fe}}}])})(),e2=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"area",value:function(){return m.area(this.p0,this.p1,this.p2)}},{key:"signedArea",value:function(){return m.signedArea(this.p0,this.p1,this.p2)}},{key:"interpolateZ",value:function(u){if(u===null)throw new S("Supplied point is null.");return m.interpolateZ(u,this.p0,this.p1,this.p2)}},{key:"longestSideLength",value:function(){return m.longestSideLength(this.p0,this.p1,this.p2)}},{key:"isAcute",value:function(){return m.isAcute(this.p0,this.p1,this.p2)}},{key:"circumcentre",value:function(){return m.circumcentre(this.p0,this.p1,this.p2)}},{key:"area3D",value:function(){return m.area3D(this.p0,this.p1,this.p2)}},{key:"centroid",value:function(){return m.centroid(this.p0,this.p1,this.p2)}},{key:"inCentre",value:function(){return m.inCentre(this.p0,this.p1,this.p2)}}],[{key:"constructor_",value:function(){this.p0=null,this.p1=null,this.p2=null;var u=arguments[0],c=arguments[1],g=arguments[2];this.p0=u,this.p1=c,this.p2=g}},{key:"area",value:function(u,c,g){return Math.abs(((g.x-u.x)*(c.y-u.y)-(c.x-u.x)*(g.y-u.y))/2)}},{key:"signedArea",value:function(u,c,g){return((g.x-u.x)*(c.y-u.y)-(c.x-u.x)*(g.y-u.y))/2}},{key:"det",value:function(u,c,g,v){return u*v-c*g}},{key:"interpolateZ",value:function(u,c,g,v){var x=c.x,k=c.y,O=g.x-x,G=v.x-x,X=g.y-k,st=v.y-k,at=O*st-G*X,mt=u.x-x,Pt=u.y-k,Ft=(st*mt-G*Pt)/at,qt=(-X*mt+O*Pt)/at;return c.getZ()+Ft*(g.getZ()-c.getZ())+qt*(v.getZ()-c.getZ())}},{key:"longestSideLength",value:function(u,c,g){var v=u.distance(c),x=c.distance(g),k=g.distance(u),O=v;return x>O&&(O=x),k>O&&(O=k),O}},{key:"circumcentreDD",value:function(u,c,g){var v=rt.valueOf(u.x).subtract(g.x),x=rt.valueOf(u.y).subtract(g.y),k=rt.valueOf(c.x).subtract(g.x),O=rt.valueOf(c.y).subtract(g.y),G=rt.determinant(v,x,k,O).multiply(2),X=v.sqr().add(x.sqr()),st=k.sqr().add(O.sqr()),at=rt.determinant(x,X,O,st),mt=rt.determinant(v,X,k,st),Pt=rt.valueOf(g.x).subtract(at.divide(G)).doubleValue(),Ft=rt.valueOf(g.y).add(mt.divide(G)).doubleValue();return new Q(Pt,Ft)}},{key:"isAcute",value:function(u,c,g){return!!_i.isAcute(u,c,g)&&!!_i.isAcute(c,g,u)&&!!_i.isAcute(g,u,c)}},{key:"circumcentre",value:function(u,c,g){var v=g.x,x=g.y,k=u.x-v,O=u.y-x,G=c.x-v,X=c.y-x,st=2*m.det(k,O,G,X),at=m.det(O,k*k+O*O,X,G*G+X*X),mt=m.det(k,k*k+O*O,G,G*G+X*X);return new Q(v-at/st,x+mt/st)}},{key:"perpendicularBisector",value:function(u,c){var g=c.x-u.x,v=c.y-u.y,x=new $d(u.x+g/2,u.y+v/2,1),k=new $d(u.x-v+g/2,u.y+g+v/2,1);return new $d(x,k)}},{key:"angleBisector",value:function(u,c,g){var v=c.distance(u),x=v/(v+c.distance(g)),k=g.x-u.x,O=g.y-u.y;return new Q(u.x+x*k,u.y+x*O)}},{key:"area3D",value:function(u,c,g){var v=c.x-u.x,x=c.y-u.y,k=c.getZ()-u.getZ(),O=g.x-u.x,G=g.y-u.y,X=g.getZ()-u.getZ(),st=x*X-k*G,at=k*O-v*X,mt=v*G-x*O,Pt=st*st+at*at+mt*mt,Ft=Math.sqrt(Pt)/2;return Ft}},{key:"centroid",value:function(u,c,g){var v=(u.x+c.x+g.x)/3,x=(u.y+c.y+g.y)/3;return new Q(v,x)}},{key:"inCentre",value:function(u,c,g){var v=c.distance(g),x=u.distance(g),k=u.distance(c),O=v+x+k,G=(v*u.x+x*c.x+k*g.x)/O,X=(v*u.y+x*c.y+k*g.y)/O;return new Q(G,X)}}])})(),n2=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"addRingSide",value:function(m,u,c,g,v){if(u===0&&m.length<Ol.MINIMUM_VALID_SIZE)return null;var x=g,k=v;m.length>=Ol.MINIMUM_VALID_SIZE&&At.isCCW(m)&&(x=v,k=g,c=Et.opposite(c));var O=this._curveBuilder.getRingCurve(m,c,u);this.addCurve(O,x,k)}},{key:"addRingBothSides",value:function(m,u){this.addRingSide(m,u,Et.LEFT,V.EXTERIOR,V.INTERIOR),this.addRingSide(m,u,Et.RIGHT,V.INTERIOR,V.EXTERIOR)}},{key:"addPoint",value:function(m){if(this._distance<=0)return null;var u=m.getCoordinates(),c=this._curveBuilder.getLineCurve(u,this._distance);this.addCurve(c,V.EXTERIOR,V.INTERIOR)}},{key:"addPolygon",value:function(m){var u=this._distance,c=Et.LEFT;this._distance<0&&(u=-this._distance,c=Et.RIGHT);var g=m.getExteriorRing(),v=gn.removeRepeatedPoints(g.getCoordinates());if(this._distance<0&&this.isErodedCompletely(g,this._distance)||this._distance<=0&&v.length<3)return null;this.addRingSide(v,u,c,V.EXTERIOR,V.INTERIOR);for(var x=0;x<m.getNumInteriorRing();x++){var k=m.getInteriorRingN(x),O=gn.removeRepeatedPoints(k.getCoordinates());this._distance>0&&this.isErodedCompletely(k,-this._distance)||this.addRingSide(O,u,Et.opposite(c),V.INTERIOR,V.EXTERIOR)}}},{key:"isTriangleErodedCompletely",value:function(m,u){var c=new e2(m[0],m[1],m[2]),g=c.inCentre();return Ns.pointToSegment(g,c.p0,c.p1)<Math.abs(u)}},{key:"addLineString",value:function(m){if(this._curveBuilder.isLineOffsetEmpty(this._distance))return null;var u=gn.removeRepeatedPoints(m.getCoordinates());if(gn.isRing(u)&&!this._curveBuilder.getBufferParameters().isSingleSided())this.addRingBothSides(u,this._distance);else{var c=this._curveBuilder.getLineCurve(u,this._distance);this.addCurve(c,V.EXTERIOR,V.INTERIOR)}}},{key:"addCurve",value:function(m,u,c){if(m===null||m.length<2)return null;var g=new oo(m,new Ai(0,V.BOUNDARY,u,c));this._curveList.add(g)}},{key:"getCurves",value:function(){return this.add(this._inputGeom),this._curveList}},{key:"add",value:function(m){if(m.isEmpty())return null;if(m instanceof Tc)this.addPolygon(m);else if(m instanceof Al)this.addLineString(m);else if(m instanceof Id)this.addPoint(m);else if(m instanceof Sd)this.addCollection(m);else if(m instanceof Cd)this.addCollection(m);else if(m instanceof Ld)this.addCollection(m);else{if(!(m instanceof pi))throw new Gt(m.getGeometryType());this.addCollection(m)}}},{key:"isErodedCompletely",value:function(m,u){var c=m.getCoordinates();if(c.length<4)return u<0;if(c.length===4)return this.isTriangleErodedCompletely(c,u);var g=m.getEnvelopeInternal(),v=Math.min(g.getHeight(),g.getWidth());return u<0&&2*Math.abs(u)>v}},{key:"addCollection",value:function(m){for(var u=0;u<m.getNumGeometries();u++){var c=m.getGeometryN(u);this.add(c)}}}],[{key:"constructor_",value:function(){this._inputGeom=null,this._distance=null,this._curveBuilder=null,this._curveList=new Bt;var m=arguments[0],u=arguments[1],c=arguments[2];this._inputGeom=m,this._distance=u,this._curveBuilder=c}}])})(),i2=(function(){return a((function m(){s(this,m)}),[{key:"locate",value:function(m){}}])})(),s2=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"next",value:function(){if(this._atStart)return this._atStart=!1,m.isAtomic(this._parent)&&this._index++,this._parent;if(this._subcollectionIterator!==null){if(this._subcollectionIterator.hasNext())return this._subcollectionIterator.next();this._subcollectionIterator=null}if(this._index>=this._max)throw new Ut;var u=this._parent.getGeometryN(this._index++);return u instanceof pi?(this._subcollectionIterator=new m(u),this._subcollectionIterator.next()):u}},{key:"remove",value:function(){throw new Gt(this.getClass().getName())}},{key:"hasNext",value:function(){if(this._atStart)return!0;if(this._subcollectionIterator!==null){if(this._subcollectionIterator.hasNext())return!0;this._subcollectionIterator=null}return!(this._index>=this._max)}},{key:"interfaces_",get:function(){return[VS]}}],[{key:"constructor_",value:function(){this._parent=null,this._atStart=null,this._max=null,this._index=null,this._subcollectionIterator=null;var u=arguments[0];this._parent=u,this._atStart=!0,this._index=0,this._max=u.getNumGeometries()}},{key:"isAtomic",value:function(u){return!(u instanceof pi)}}])})(),r2=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"locate",value:function(u){return m.locate(u,this._geom)}},{key:"interfaces_",get:function(){return[i2]}}],[{key:"constructor_",value:function(){this._geom=null;var u=arguments[0];this._geom=u}},{key:"locatePointInPolygon",value:function(u,c){if(c.isEmpty())return V.EXTERIOR;var g=c.getExteriorRing(),v=m.locatePointInRing(u,g);if(v!==V.INTERIOR)return v;for(var x=0;x<c.getNumInteriorRing();x++){var k=c.getInteriorRingN(x),O=m.locatePointInRing(u,k);if(O===V.BOUNDARY)return V.BOUNDARY;if(O===V.INTERIOR)return V.EXTERIOR}return V.INTERIOR}},{key:"locatePointInRing",value:function(u,c){return c.getEnvelopeInternal().intersects(u)?Td.locateInRing(u,c.getCoordinates()):V.EXTERIOR}},{key:"containsPointInPolygon",value:function(u,c){return V.EXTERIOR!==m.locatePointInPolygon(u,c)}},{key:"locateInGeometry",value:function(u,c){if(c instanceof Tc)return m.locatePointInPolygon(u,c);if(c instanceof pi)for(var g=new s2(c);g.hasNext();){var v=g.next();if(v!==c){var x=m.locateInGeometry(u,v);if(x!==V.EXTERIOR)return x}}return V.EXTERIOR}},{key:"isContained",value:function(u,c){return V.EXTERIOR!==m.locate(u,c)}},{key:"locate",value:function(u,c){return c.isEmpty()?V.EXTERIOR:c.getEnvelopeInternal().intersects(u)?m.locateInGeometry(u,c):V.EXTERIOR}}])})(),o2=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"getNextCW",value:function(m){this.getEdges();var u=this._edgeList.indexOf(m),c=u-1;return u===0&&(c=this._edgeList.size()-1),this._edgeList.get(c)}},{key:"propagateSideLabels",value:function(m){for(var u=V.NONE,c=this.iterator();c.hasNext();){var g=c.next().getLabel();g.isArea(m)&&g.getLocation(m,Et.LEFT)!==V.NONE&&(u=g.getLocation(m,Et.LEFT))}if(u===V.NONE)return null;for(var v=u,x=this.iterator();x.hasNext();){var k=x.next(),O=k.getLabel();if(O.getLocation(m,Et.ON)===V.NONE&&O.setLocation(m,Et.ON,v),O.isArea(m)){var G=O.getLocation(m,Et.LEFT),X=O.getLocation(m,Et.RIGHT);if(X!==V.NONE){if(X!==v)throw new Ae("side location conflict",k.getCoordinate());G===V.NONE&&ct.shouldNeverReachHere("found single null side (at "+k.getCoordinate()+")"),v=G}else ct.isTrue(O.getLocation(m,Et.LEFT)===V.NONE,"found single null side"),O.setLocation(m,Et.RIGHT,v),O.setLocation(m,Et.LEFT,v)}}}},{key:"getCoordinate",value:function(){var m=this.iterator();return m.hasNext()?m.next().getCoordinate():null}},{key:"print",value:function(m){Ti.out.println("EdgeEndStar: "+this.getCoordinate());for(var u=this.iterator();u.hasNext();)u.next().print(m)}},{key:"isAreaLabelsConsistent",value:function(m){return this.computeEdgeEndLabels(m.getBoundaryNodeRule()),this.checkAreaLabelsConsistent(0)}},{key:"checkAreaLabelsConsistent",value:function(m){var u=this.getEdges();if(u.size()<=0)return!0;var c=u.size()-1,g=u.get(c).getLabel().getLocation(m,Et.LEFT);ct.isTrue(g!==V.NONE,"Found unlabelled area edge");for(var v=g,x=this.iterator();x.hasNext();){var k=x.next().getLabel();ct.isTrue(k.isArea(m),"Found non-area edge");var O=k.getLocation(m,Et.LEFT),G=k.getLocation(m,Et.RIGHT);if(O===G||G!==v)return!1;v=O}return!0}},{key:"findIndex",value:function(m){this.iterator();for(var u=0;u<this._edgeList.size();u++)if(this._edgeList.get(u)===m)return u;return-1}},{key:"iterator",value:function(){return this.getEdges().iterator()}},{key:"getEdges",value:function(){return this._edgeList===null&&(this._edgeList=new Bt(this._edgeMap.values())),this._edgeList}},{key:"getLocation",value:function(m,u,c){return this._ptInAreaLocation[m]===V.NONE&&(this._ptInAreaLocation[m]=r2.locate(u,c[m].getGeometry())),this._ptInAreaLocation[m]}},{key:"toString",value:function(){var m=new nt;m.append("EdgeEndStar: "+this.getCoordinate()),m.append(`
|
|
9
|
+
`);for(var u=this.iterator();u.hasNext();){var c=u.next();m.append(c),m.append(`
|
|
10
|
+
`)}return m.toString()}},{key:"computeEdgeEndLabels",value:function(m){for(var u=this.iterator();u.hasNext();)u.next().computeLabel(m)}},{key:"computeLabelling",value:function(m){this.computeEdgeEndLabels(m[0].getBoundaryNodeRule()),this.propagateSideLabels(0),this.propagateSideLabels(1);for(var u=[!1,!1],c=this.iterator();c.hasNext();)for(var g=c.next().getLabel(),v=0;v<2;v++)g.isLine(v)&&g.getLocation(v)===V.BOUNDARY&&(u[v]=!0);for(var x=this.iterator();x.hasNext();)for(var k=x.next(),O=k.getLabel(),G=0;G<2;G++)if(O.isAnyNull(G)){var X=V.NONE;if(u[G])X=V.EXTERIOR;else{var st=k.getCoordinate();X=this.getLocation(G,st,m)}O.setAllLocationsIfNull(G,X)}}},{key:"getDegree",value:function(){return this._edgeMap.size()}},{key:"insertEdgeEnd",value:function(m,u){this._edgeMap.put(m,u),this._edgeList=null}}],[{key:"constructor_",value:function(){this._edgeMap=new Gl,this._edgeList=null,this._ptInAreaLocation=[V.NONE,V.NONE]}}])})(),a2=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,[{key:"linkResultDirectedEdges",value:function(){this.getResultAreaEdges();for(var c=null,g=null,v=this._SCANNING_FOR_INCOMING,x=0;x<this._resultAreaEdgeList.size();x++){var k=this._resultAreaEdgeList.get(x),O=k.getSym();if(k.getLabel().isArea())switch(c===null&&k.isInResult()&&(c=k),v){case this._SCANNING_FOR_INCOMING:if(!O.isInResult())continue;g=O,v=this._LINKING_TO_OUTGOING;break;case this._LINKING_TO_OUTGOING:if(!k.isInResult())continue;g.setNext(k),v=this._SCANNING_FOR_INCOMING}}if(v===this._LINKING_TO_OUTGOING){if(c===null)throw new Ae("no outgoing dirEdge found",this.getCoordinate());ct.isTrue(c.isInResult(),"unable to link last incoming dirEdge"),g.setNext(c)}}},{key:"insert",value:function(c){var g=c;this.insertEdgeEnd(g,g)}},{key:"getRightmostEdge",value:function(){var c=this.getEdges(),g=c.size();if(g<1)return null;var v=c.get(0);if(g===1)return v;var x=c.get(g-1),k=v.getQuadrant(),O=x.getQuadrant();return Gn.isNorthern(k)&&Gn.isNorthern(O)?v:Gn.isNorthern(k)||Gn.isNorthern(O)?v.getDy()!==0?v:x.getDy()!==0?x:(ct.shouldNeverReachHere("found two horizontal edges incident on node"),null):x}},{key:"print",value:function(c){Ti.out.println("DirectedEdgeStar: "+this.getCoordinate());for(var g=this.iterator();g.hasNext();){var v=g.next();c.print("out "),v.print(c),c.println(),c.print("in "),v.getSym().print(c),c.println()}}},{key:"getResultAreaEdges",value:function(){if(this._resultAreaEdgeList!==null)return this._resultAreaEdgeList;this._resultAreaEdgeList=new Bt;for(var c=this.iterator();c.hasNext();){var g=c.next();(g.isInResult()||g.getSym().isInResult())&&this._resultAreaEdgeList.add(g)}return this._resultAreaEdgeList}},{key:"updateLabelling",value:function(c){for(var g=this.iterator();g.hasNext();){var v=g.next().getLabel();v.setAllLocationsIfNull(0,c.getLocation(0)),v.setAllLocationsIfNull(1,c.getLocation(1))}}},{key:"linkAllDirectedEdges",value:function(){this.getEdges();for(var c=null,g=null,v=this._edgeList.size()-1;v>=0;v--){var x=this._edgeList.get(v),k=x.getSym();g===null&&(g=k),c!==null&&k.setNext(c),c=x}g.setNext(c)}},{key:"computeDepths",value:function(){if(arguments.length===1){var c=arguments[0],g=this.findIndex(c),v=c.getDepth(Et.LEFT),x=c.getDepth(Et.RIGHT),k=this.computeDepths(g+1,this._edgeList.size(),v);if(this.computeDepths(0,g,k)!==x)throw new Ae("depth mismatch at "+c.getCoordinate())}else if(arguments.length===3){for(var O=arguments[1],G=arguments[2],X=arguments[0];X<O;X++){var st=this._edgeList.get(X);st.setEdgeDepths(Et.RIGHT,G),G=st.getDepth(Et.LEFT)}return G}}},{key:"mergeSymLabels",value:function(){for(var c=this.iterator();c.hasNext();){var g=c.next();g.getLabel().merge(g.getSym().getLabel())}}},{key:"linkMinimalDirectedEdges",value:function(c){for(var g=null,v=null,x=this._SCANNING_FOR_INCOMING,k=this._resultAreaEdgeList.size()-1;k>=0;k--){var O=this._resultAreaEdgeList.get(k),G=O.getSym();switch(g===null&&O.getEdgeRing()===c&&(g=O),x){case this._SCANNING_FOR_INCOMING:if(G.getEdgeRing()!==c)continue;v=G,x=this._LINKING_TO_OUTGOING;break;case this._LINKING_TO_OUTGOING:if(O.getEdgeRing()!==c)continue;v.setNextMin(O),x=this._SCANNING_FOR_INCOMING}}x===this._LINKING_TO_OUTGOING&&(ct.isTrue(g!==null,"found null for first outgoing dirEdge"),ct.isTrue(g.getEdgeRing()===c,"unable to link last incoming dirEdge"),v.setNextMin(g))}},{key:"getOutgoingDegree",value:function(){if(arguments.length===0){for(var c=0,g=this.iterator();g.hasNext();)g.next().isInResult()&&c++;return c}if(arguments.length===1){for(var v=arguments[0],x=0,k=this.iterator();k.hasNext();)k.next().getEdgeRing()===v&&x++;return x}}},{key:"getLabel",value:function(){return this._label}},{key:"findCoveredLineEdges",value:function(){for(var c=V.NONE,g=this.iterator();g.hasNext();){var v=g.next(),x=v.getSym();if(!v.isLineEdge()){if(v.isInResult()){c=V.INTERIOR;break}if(x.isInResult()){c=V.EXTERIOR;break}}}if(c===V.NONE)return null;for(var k=c,O=this.iterator();O.hasNext();){var G=O.next(),X=G.getSym();G.isLineEdge()?G.getEdge().setCovered(k===V.INTERIOR):(G.isInResult()&&(k=V.EXTERIOR),X.isInResult()&&(k=V.INTERIOR))}}},{key:"computeLabelling",value:function(c){_(u,"computeLabelling",this,1).call(this,c),this._label=new Ai(V.NONE);for(var g=this.iterator();g.hasNext();)for(var v=g.next().getEdge().getLabel(),x=0;x<2;x++){var k=v.getLocation(x);k!==V.INTERIOR&&k!==V.BOUNDARY||this._label.setLocation(x,V.INTERIOR)}}}],[{key:"constructor_",value:function(){this._resultAreaEdgeList=null,this._label=null,this._SCANNING_FOR_INCOMING=1,this._LINKING_TO_OUTGOING=2}}])})(o2),l2=(function(m){function u(){return s(this,u),n(this,u)}return d(u,m),a(u,[{key:"createNode",value:function(c){return new $c(c,new a2)}}])})(uy),wy=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"compareTo",value:function(u){var c=u;return m.compareOriented(this._pts,this._orientation,c._pts,c._orientation)}},{key:"interfaces_",get:function(){return[T]}}],[{key:"constructor_",value:function(){this._pts=null,this._orientation=null;var u=arguments[0];this._pts=u,this._orientation=m.orientation(u)}},{key:"orientation",value:function(u){return gn.increasingDirection(u)===1}},{key:"compareOriented",value:function(u,c,g,v){for(var x=c?1:-1,k=v?1:-1,O=c?u.length:-1,G=v?g.length:-1,X=c?0:u.length-1,st=v?0:g.length-1;;){var at=u[X].compareTo(g[st]);if(at!==0)return at;var mt=(X+=x)===O,Pt=(st+=k)===G;if(mt&&!Pt)return-1;if(!mt&&Pt)return 1;if(mt&&Pt)return 0}}}])})(),u2=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"print",value:function(m){m.print("MULTILINESTRING ( ");for(var u=0;u<this._edges.size();u++){var c=this._edges.get(u);u>0&&m.print(","),m.print("(");for(var g=c.getCoordinates(),v=0;v<g.length;v++)v>0&&m.print(","),m.print(g[v].x+" "+g[v].y);m.println(")")}m.print(") ")}},{key:"addAll",value:function(m){for(var u=m.iterator();u.hasNext();)this.add(u.next())}},{key:"findEdgeIndex",value:function(m){for(var u=0;u<this._edges.size();u++)if(this._edges.get(u).equals(m))return u;return-1}},{key:"iterator",value:function(){return this._edges.iterator()}},{key:"getEdges",value:function(){return this._edges}},{key:"get",value:function(m){return this._edges.get(m)}},{key:"findEqualEdge",value:function(m){var u=new wy(m.getCoordinates());return this._ocaMap.get(u)}},{key:"add",value:function(m){this._edges.add(m);var u=new wy(m.getCoordinates());this._ocaMap.put(u,m)}}],[{key:"constructor_",value:function(){this._edges=new Bt,this._ocaMap=new Gl}}])})(),xy=(function(){return a((function m(){s(this,m)}),[{key:"processIntersections",value:function(m,u,c,g){}},{key:"isDone",value:function(){}}])})(),c2=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"isTrivialIntersection",value:function(u,c,g,v){if(u===g&&this._li.getIntersectionNum()===1){if(m.isAdjacentSegments(c,v))return!0;if(u.isClosed()){var x=u.size()-1;if(c===0&&v===x||v===0&&c===x)return!0}}return!1}},{key:"getProperIntersectionPoint",value:function(){return this._properIntersectionPoint}},{key:"hasProperInteriorIntersection",value:function(){return this._hasProperInterior}},{key:"getLineIntersector",value:function(){return this._li}},{key:"hasProperIntersection",value:function(){return this._hasProper}},{key:"processIntersections",value:function(u,c,g,v){if(u===g&&c===v)return null;this.numTests++;var x=u.getCoordinates()[c],k=u.getCoordinates()[c+1],O=g.getCoordinates()[v],G=g.getCoordinates()[v+1];this._li.computeIntersection(x,k,O,G),this._li.hasIntersection()&&(this.numIntersections++,this._li.isInteriorIntersection()&&(this.numInteriorIntersections++,this._hasInterior=!0),this.isTrivialIntersection(u,c,g,v)||(this._hasIntersection=!0,u.addIntersections(this._li,c,0),g.addIntersections(this._li,v,1),this._li.isProper()&&(this.numProperIntersections++,this._hasProper=!0,this._hasProperInterior=!0)))}},{key:"hasIntersection",value:function(){return this._hasIntersection}},{key:"isDone",value:function(){return!1}},{key:"hasInteriorIntersection",value:function(){return this._hasInterior}},{key:"interfaces_",get:function(){return[xy]}}],[{key:"constructor_",value:function(){this._hasIntersection=!1,this._hasProper=!1,this._hasProperInterior=!1,this._hasInterior=!1,this._properIntersectionPoint=null,this._li=null,this._isSelfIntersection=null,this.numIntersections=0,this.numInteriorIntersections=0,this.numProperIntersections=0,this.numTests=0;var u=arguments[0];this._li=u}},{key:"isAdjacentSegments",value:function(u,c){return Math.abs(u-c)===1}}])})(),h2=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"getSegmentIndex",value:function(){return this.segmentIndex}},{key:"getCoordinate",value:function(){return this.coord}},{key:"print",value:function(m){m.print(this.coord),m.print(" seg # = "+this.segmentIndex),m.println(" dist = "+this.dist)}},{key:"compareTo",value:function(m){var u=m;return this.compare(u.segmentIndex,u.dist)}},{key:"isEndPoint",value:function(m){return this.segmentIndex===0&&this.dist===0||this.segmentIndex===m}},{key:"toString",value:function(){return this.coord+" seg # = "+this.segmentIndex+" dist = "+this.dist}},{key:"getDistance",value:function(){return this.dist}},{key:"compare",value:function(m,u){return this.segmentIndex<m?-1:this.segmentIndex>m?1:this.dist<u?-1:this.dist>u?1:0}},{key:"interfaces_",get:function(){return[T]}}],[{key:"constructor_",value:function(){this.coord=null,this.segmentIndex=null,this.dist=null;var m=arguments[0],u=arguments[1],c=arguments[2];this.coord=new Q(m),this.segmentIndex=u,this.dist=c}}])})(),f2=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"print",value:function(m){m.println("Intersections:");for(var u=this.iterator();u.hasNext();)u.next().print(m)}},{key:"iterator",value:function(){return this._nodeMap.values().iterator()}},{key:"addSplitEdges",value:function(m){this.addEndpoints();for(var u=this.iterator(),c=u.next();u.hasNext();){var g=u.next(),v=this.createSplitEdge(c,g);m.add(v),c=g}}},{key:"addEndpoints",value:function(){var m=this.edge.pts.length-1;this.add(this.edge.pts[0],0,0),this.add(this.edge.pts[m],m,0)}},{key:"createSplitEdge",value:function(m,u){var c=u.segmentIndex-m.segmentIndex+2,g=this.edge.pts[u.segmentIndex],v=u.dist>0||!u.coord.equals2D(g);v||c--;var x=new Array(c).fill(null),k=0;x[k++]=new Q(m.coord);for(var O=m.segmentIndex+1;O<=u.segmentIndex;O++)x[k++]=this.edge.pts[O];return v&&(x[k]=u.coord),new Iy(x,new Ai(this.edge._label))}},{key:"add",value:function(m,u,c){var g=new h2(m,u,c),v=this._nodeMap.get(g);return v!==null?v:(this._nodeMap.put(g,g),g)}},{key:"isIntersection",value:function(m){for(var u=this.iterator();u.hasNext();)if(u.next().coord.equals(m))return!0;return!1}}],[{key:"constructor_",value:function(){this._nodeMap=new Gl,this.edge=null;var m=arguments[0];this.edge=m}}])})(),d2=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"isIntersects",value:function(){return!this.isDisjoint()}},{key:"isCovers",value:function(){return(m.isTrue(this._matrix[V.INTERIOR][V.INTERIOR])||m.isTrue(this._matrix[V.INTERIOR][V.BOUNDARY])||m.isTrue(this._matrix[V.BOUNDARY][V.INTERIOR])||m.isTrue(this._matrix[V.BOUNDARY][V.BOUNDARY]))&&this._matrix[V.EXTERIOR][V.INTERIOR]===Nt.FALSE&&this._matrix[V.EXTERIOR][V.BOUNDARY]===Nt.FALSE}},{key:"isCoveredBy",value:function(){return(m.isTrue(this._matrix[V.INTERIOR][V.INTERIOR])||m.isTrue(this._matrix[V.INTERIOR][V.BOUNDARY])||m.isTrue(this._matrix[V.BOUNDARY][V.INTERIOR])||m.isTrue(this._matrix[V.BOUNDARY][V.BOUNDARY]))&&this._matrix[V.INTERIOR][V.EXTERIOR]===Nt.FALSE&&this._matrix[V.BOUNDARY][V.EXTERIOR]===Nt.FALSE}},{key:"set",value:function(){if(arguments.length===1)for(var u=arguments[0],c=0;c<u.length;c++){var g=Math.trunc(c/3),v=c%3;this._matrix[g][v]=Nt.toDimensionValue(u.charAt(c))}else if(arguments.length===3){var x=arguments[0],k=arguments[1],O=arguments[2];this._matrix[x][k]=O}}},{key:"isContains",value:function(){return m.isTrue(this._matrix[V.INTERIOR][V.INTERIOR])&&this._matrix[V.EXTERIOR][V.INTERIOR]===Nt.FALSE&&this._matrix[V.EXTERIOR][V.BOUNDARY]===Nt.FALSE}},{key:"setAtLeast",value:function(){if(arguments.length===1)for(var u=arguments[0],c=0;c<u.length;c++){var g=Math.trunc(c/3),v=c%3;this.setAtLeast(g,v,Nt.toDimensionValue(u.charAt(c)))}else if(arguments.length===3){var x=arguments[0],k=arguments[1],O=arguments[2];this._matrix[x][k]<O&&(this._matrix[x][k]=O)}}},{key:"setAtLeastIfValid",value:function(u,c,g){u>=0&&c>=0&&this.setAtLeast(u,c,g)}},{key:"isWithin",value:function(){return m.isTrue(this._matrix[V.INTERIOR][V.INTERIOR])&&this._matrix[V.INTERIOR][V.EXTERIOR]===Nt.FALSE&&this._matrix[V.BOUNDARY][V.EXTERIOR]===Nt.FALSE}},{key:"isTouches",value:function(u,c){return u>c?this.isTouches(c,u):(u===Nt.A&&c===Nt.A||u===Nt.L&&c===Nt.L||u===Nt.L&&c===Nt.A||u===Nt.P&&c===Nt.A||u===Nt.P&&c===Nt.L)&&this._matrix[V.INTERIOR][V.INTERIOR]===Nt.FALSE&&(m.isTrue(this._matrix[V.INTERIOR][V.BOUNDARY])||m.isTrue(this._matrix[V.BOUNDARY][V.INTERIOR])||m.isTrue(this._matrix[V.BOUNDARY][V.BOUNDARY]))}},{key:"isOverlaps",value:function(u,c){return u===Nt.P&&c===Nt.P||u===Nt.A&&c===Nt.A?m.isTrue(this._matrix[V.INTERIOR][V.INTERIOR])&&m.isTrue(this._matrix[V.INTERIOR][V.EXTERIOR])&&m.isTrue(this._matrix[V.EXTERIOR][V.INTERIOR]):u===Nt.L&&c===Nt.L&&this._matrix[V.INTERIOR][V.INTERIOR]===1&&m.isTrue(this._matrix[V.INTERIOR][V.EXTERIOR])&&m.isTrue(this._matrix[V.EXTERIOR][V.INTERIOR])}},{key:"isEquals",value:function(u,c){return u===c&&m.isTrue(this._matrix[V.INTERIOR][V.INTERIOR])&&this._matrix[V.INTERIOR][V.EXTERIOR]===Nt.FALSE&&this._matrix[V.BOUNDARY][V.EXTERIOR]===Nt.FALSE&&this._matrix[V.EXTERIOR][V.INTERIOR]===Nt.FALSE&&this._matrix[V.EXTERIOR][V.BOUNDARY]===Nt.FALSE}},{key:"toString",value:function(){for(var u=new Ac("123456789"),c=0;c<3;c++)for(var g=0;g<3;g++)u.setCharAt(3*c+g,Nt.toDimensionSymbol(this._matrix[c][g]));return u.toString()}},{key:"setAll",value:function(u){for(var c=0;c<3;c++)for(var g=0;g<3;g++)this._matrix[c][g]=u}},{key:"get",value:function(u,c){return this._matrix[u][c]}},{key:"transpose",value:function(){var u=this._matrix[1][0];return this._matrix[1][0]=this._matrix[0][1],this._matrix[0][1]=u,u=this._matrix[2][0],this._matrix[2][0]=this._matrix[0][2],this._matrix[0][2]=u,u=this._matrix[2][1],this._matrix[2][1]=this._matrix[1][2],this._matrix[1][2]=u,this}},{key:"matches",value:function(u){if(u.length!==9)throw new S("Should be length 9: "+u);for(var c=0;c<3;c++)for(var g=0;g<3;g++)if(!m.matches(this._matrix[c][g],u.charAt(3*c+g)))return!1;return!0}},{key:"add",value:function(u){for(var c=0;c<3;c++)for(var g=0;g<3;g++)this.setAtLeast(c,g,u.get(c,g))}},{key:"isDisjoint",value:function(){return this._matrix[V.INTERIOR][V.INTERIOR]===Nt.FALSE&&this._matrix[V.INTERIOR][V.BOUNDARY]===Nt.FALSE&&this._matrix[V.BOUNDARY][V.INTERIOR]===Nt.FALSE&&this._matrix[V.BOUNDARY][V.BOUNDARY]===Nt.FALSE}},{key:"isCrosses",value:function(u,c){return u===Nt.P&&c===Nt.L||u===Nt.P&&c===Nt.A||u===Nt.L&&c===Nt.A?m.isTrue(this._matrix[V.INTERIOR][V.INTERIOR])&&m.isTrue(this._matrix[V.INTERIOR][V.EXTERIOR]):u===Nt.L&&c===Nt.P||u===Nt.A&&c===Nt.P||u===Nt.A&&c===Nt.L?m.isTrue(this._matrix[V.INTERIOR][V.INTERIOR])&&m.isTrue(this._matrix[V.EXTERIOR][V.INTERIOR]):u===Nt.L&&c===Nt.L&&this._matrix[V.INTERIOR][V.INTERIOR]===0}},{key:"interfaces_",get:function(){return[I]}}],[{key:"constructor_",value:function(){if(this._matrix=null,arguments.length===0)this._matrix=Array(3).fill().map((function(){return Array(3)})),this.setAll(Nt.FALSE);else if(arguments.length===1){if(typeof arguments[0]=="string"){var u=arguments[0];m.constructor_.call(this),this.set(u)}else if(arguments[0]instanceof m){var c=arguments[0];m.constructor_.call(this),this._matrix[V.INTERIOR][V.INTERIOR]=c._matrix[V.INTERIOR][V.INTERIOR],this._matrix[V.INTERIOR][V.BOUNDARY]=c._matrix[V.INTERIOR][V.BOUNDARY],this._matrix[V.INTERIOR][V.EXTERIOR]=c._matrix[V.INTERIOR][V.EXTERIOR],this._matrix[V.BOUNDARY][V.INTERIOR]=c._matrix[V.BOUNDARY][V.INTERIOR],this._matrix[V.BOUNDARY][V.BOUNDARY]=c._matrix[V.BOUNDARY][V.BOUNDARY],this._matrix[V.BOUNDARY][V.EXTERIOR]=c._matrix[V.BOUNDARY][V.EXTERIOR],this._matrix[V.EXTERIOR][V.INTERIOR]=c._matrix[V.EXTERIOR][V.INTERIOR],this._matrix[V.EXTERIOR][V.BOUNDARY]=c._matrix[V.EXTERIOR][V.BOUNDARY],this._matrix[V.EXTERIOR][V.EXTERIOR]=c._matrix[V.EXTERIOR][V.EXTERIOR]}}}},{key:"matches",value:function(){if(Number.isInteger(arguments[0])&&typeof arguments[1]=="string"){var u=arguments[0],c=arguments[1];return c===Nt.SYM_DONTCARE||c===Nt.SYM_TRUE&&(u>=0||u===Nt.TRUE)||c===Nt.SYM_FALSE&&u===Nt.FALSE||c===Nt.SYM_P&&u===Nt.P||c===Nt.SYM_L&&u===Nt.L||c===Nt.SYM_A&&u===Nt.A}if(typeof arguments[0]=="string"&&typeof arguments[1]=="string"){var g=arguments[1];return new m(arguments[0]).matches(g)}}},{key:"isTrue",value:function(u){return u>=0||u===Nt.TRUE}}])})(),g2=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"size",value:function(){return this._size}},{key:"addAll",value:function(u){return u===null||u.length===0?null:(this.ensureCapacity(this._size+u.length),Ti.arraycopy(u,0,this._data,this._size,u.length),void(this._size+=u.length))}},{key:"ensureCapacity",value:function(u){if(u<=this._data.length)return null;var c=Math.max(u,2*this._data.length);this._data=no.copyOf(this._data,c)}},{key:"toArray",value:function(){var u=new Array(this._size).fill(null);return Ti.arraycopy(this._data,0,u,0,this._size),u}},{key:"add",value:function(u){this.ensureCapacity(this._size+1),this._data[this._size]=u,++this._size}}],[{key:"constructor_",value:function(){if(this._data=null,this._size=0,arguments.length===0)m.constructor_.call(this,10);else if(arguments.length===1){var u=arguments[0];this._data=new Array(u).fill(null)}}}])})(),m2=(function(){function m(){s(this,m)}return a(m,[{key:"getChainStartIndices",value:function(u){var c=0,g=new g2(Math.trunc(u.length/2));g.add(c);do{var v=this.findChainEnd(u,c);g.add(v),c=v}while(c<u.length-1);return g.toArray()}},{key:"findChainEnd",value:function(u,c){for(var g=Gn.quadrant(u[c],u[c+1]),v=c+1;v<u.length&&Gn.quadrant(u[v-1],u[v])===g;)v++;return v-1}},{key:"OLDgetChainStartIndices",value:function(u){var c=0,g=new Bt;g.add(c);do{var v=this.findChainEnd(u,c);g.add(v),c=v}while(c<u.length-1);return m.toIntArray(g)}}],[{key:"toIntArray",value:function(u){for(var c=new Array(u.size()).fill(null),g=0;g<c.length;g++)c[g]=u.get(g).intValue();return c}}])})(),p2=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"getCoordinates",value:function(){return this.pts}},{key:"getMaxX",value:function(m){var u=this.pts[this.startIndex[m]].x,c=this.pts[this.startIndex[m+1]].x;return u>c?u:c}},{key:"getMinX",value:function(m){var u=this.pts[this.startIndex[m]].x,c=this.pts[this.startIndex[m+1]].x;return u<c?u:c}},{key:"computeIntersectsForChain",value:function(){if(arguments.length===4){var m=arguments[0],u=arguments[1],c=arguments[2],g=arguments[3];this.computeIntersectsForChain(this.startIndex[m],this.startIndex[m+1],u,u.startIndex[c],u.startIndex[c+1],g)}else if(arguments.length===6){var v=arguments[0],x=arguments[1],k=arguments[2],O=arguments[3],G=arguments[4],X=arguments[5];if(x-v==1&&G-O==1)return X.addIntersections(this.e,v,k.e,O),null;if(!this.overlaps(v,x,k,O,G))return null;var st=Math.trunc((v+x)/2),at=Math.trunc((O+G)/2);v<st&&(O<at&&this.computeIntersectsForChain(v,st,k,O,at,X),at<G&&this.computeIntersectsForChain(v,st,k,at,G,X)),st<x&&(O<at&&this.computeIntersectsForChain(st,x,k,O,at,X),at<G&&this.computeIntersectsForChain(st,x,k,at,G,X))}}},{key:"overlaps",value:function(m,u,c,g,v){return Dt.intersects(this.pts[m],this.pts[u],c.pts[g],c.pts[v])}},{key:"getStartIndexes",value:function(){return this.startIndex}},{key:"computeIntersects",value:function(m,u){for(var c=0;c<this.startIndex.length-1;c++)for(var g=0;g<m.startIndex.length-1;g++)this.computeIntersectsForChain(c,m,g,u)}}],[{key:"constructor_",value:function(){this.e=null,this.pts=null,this.startIndex=null;var m=arguments[0];this.e=m,this.pts=m.getCoordinates();var u=new m2;this.startIndex=u.getChainStartIndices(this.pts)}}])})(),by=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"getDepth",value:function(u,c){return this._depth[u][c]}},{key:"setDepth",value:function(u,c,g){this._depth[u][c]=g}},{key:"isNull",value:function(){if(arguments.length===0){for(var u=0;u<2;u++)for(var c=0;c<3;c++)if(this._depth[u][c]!==m.NULL_VALUE)return!1;return!0}if(arguments.length===1){var g=arguments[0];return this._depth[g][1]===m.NULL_VALUE}if(arguments.length===2){var v=arguments[0],x=arguments[1];return this._depth[v][x]===m.NULL_VALUE}}},{key:"normalize",value:function(){for(var u=0;u<2;u++)if(!this.isNull(u)){var c=this._depth[u][1];this._depth[u][2]<c&&(c=this._depth[u][2]),c<0&&(c=0);for(var g=1;g<3;g++){var v=0;this._depth[u][g]>c&&(v=1),this._depth[u][g]=v}}}},{key:"getDelta",value:function(u){return this._depth[u][Et.RIGHT]-this._depth[u][Et.LEFT]}},{key:"getLocation",value:function(u,c){return this._depth[u][c]<=0?V.EXTERIOR:V.INTERIOR}},{key:"toString",value:function(){return"A: "+this._depth[0][1]+","+this._depth[0][2]+" B: "+this._depth[1][1]+","+this._depth[1][2]}},{key:"add",value:function(){if(arguments.length===1)for(var u=arguments[0],c=0;c<2;c++)for(var g=1;g<3;g++){var v=u.getLocation(c,g);v!==V.EXTERIOR&&v!==V.INTERIOR||(this.isNull(c,g)?this._depth[c][g]=m.depthAtLocation(v):this._depth[c][g]+=m.depthAtLocation(v))}else if(arguments.length===3){var x=arguments[0],k=arguments[1];arguments[2]===V.INTERIOR&&this._depth[x][k]++}}}],[{key:"constructor_",value:function(){this._depth=Array(2).fill().map((function(){return Array(3)}));for(var u=0;u<2;u++)for(var c=0;c<3;c++)this._depth[u][c]=m.NULL_VALUE}},{key:"depthAtLocation",value:function(u){return u===V.EXTERIOR?0:u===V.INTERIOR?1:m.NULL_VALUE}}])})();by.NULL_VALUE=-1;var Iy=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,[{key:"getDepth",value:function(){return this._depth}},{key:"getCollapsedEdge",value:function(){var c=new Array(2).fill(null);return c[0]=this.pts[0],c[1]=this.pts[1],new u(c,Ai.toLineLabel(this._label))}},{key:"isIsolated",value:function(){return this._isIsolated}},{key:"getCoordinates",value:function(){return this.pts}},{key:"setIsolated",value:function(c){this._isIsolated=c}},{key:"setName",value:function(c){this._name=c}},{key:"equals",value:function(c){if(!(c instanceof u))return!1;var g=c;if(this.pts.length!==g.pts.length)return!1;for(var v=!0,x=!0,k=this.pts.length,O=0;O<this.pts.length;O++)if(this.pts[O].equals2D(g.pts[O])||(v=!1),this.pts[O].equals2D(g.pts[--k])||(x=!1),!v&&!x)return!1;return!0}},{key:"getCoordinate",value:function(){if(arguments.length===0)return this.pts.length>0?this.pts[0]:null;if(arguments.length===1){var c=arguments[0];return this.pts[c]}}},{key:"print",value:function(c){c.print("edge "+this._name+": "),c.print("LINESTRING (");for(var g=0;g<this.pts.length;g++)g>0&&c.print(","),c.print(this.pts[g].x+" "+this.pts[g].y);c.print(") "+this._label+" "+this._depthDelta)}},{key:"computeIM",value:function(c){u.updateIM(this._label,c)}},{key:"isCollapsed",value:function(){return!!this._label.isArea()&&this.pts.length===3&&!!this.pts[0].equals(this.pts[2])}},{key:"isClosed",value:function(){return this.pts[0].equals(this.pts[this.pts.length-1])}},{key:"getMaximumSegmentIndex",value:function(){return this.pts.length-1}},{key:"getDepthDelta",value:function(){return this._depthDelta}},{key:"getNumPoints",value:function(){return this.pts.length}},{key:"printReverse",value:function(c){c.print("edge "+this._name+": ");for(var g=this.pts.length-1;g>=0;g--)c.print(this.pts[g]+" ");c.println("")}},{key:"getMonotoneChainEdge",value:function(){return this._mce===null&&(this._mce=new p2(this)),this._mce}},{key:"getEnvelope",value:function(){if(this._env===null){this._env=new Dt;for(var c=0;c<this.pts.length;c++)this._env.expandToInclude(this.pts[c])}return this._env}},{key:"addIntersection",value:function(c,g,v,x){var k=new Q(c.getIntersection(x)),O=g,G=c.getEdgeDistance(v,x),X=O+1;if(X<this.pts.length){var st=this.pts[X];k.equals2D(st)&&(O=X,G=0)}this.eiList.add(k,O,G)}},{key:"toString",value:function(){var c=new Ac;c.append("edge "+this._name+": "),c.append("LINESTRING (");for(var g=0;g<this.pts.length;g++)g>0&&c.append(","),c.append(this.pts[g].x+" "+this.pts[g].y);return c.append(") "+this._label+" "+this._depthDelta),c.toString()}},{key:"isPointwiseEqual",value:function(c){if(this.pts.length!==c.pts.length)return!1;for(var g=0;g<this.pts.length;g++)if(!this.pts[g].equals2D(c.pts[g]))return!1;return!0}},{key:"setDepthDelta",value:function(c){this._depthDelta=c}},{key:"getEdgeIntersectionList",value:function(){return this.eiList}},{key:"addIntersections",value:function(c,g,v){for(var x=0;x<c.getIntersectionNum();x++)this.addIntersection(c,g,v,x)}}],[{key:"constructor_",value:function(){if(this.pts=null,this._env=null,this.eiList=new f2(this),this._name=null,this._mce=null,this._isIsolated=!0,this._depth=new by,this._depthDelta=0,arguments.length===1){var c=arguments[0];u.constructor_.call(this,c,null)}else if(arguments.length===2){var g=arguments[0],v=arguments[1];this.pts=g,this._label=v}}},{key:"updateIM",value:function(){if(!(arguments.length===2&&arguments[1]instanceof d2&&arguments[0]instanceof Ai))return _(u,"updateIM",this).apply(this,arguments);var c=arguments[0],g=arguments[1];g.setAtLeastIfValid(c.getLocation(0,Et.ON),c.getLocation(1,Et.ON),1),c.isArea()&&(g.setAtLeastIfValid(c.getLocation(0,Et.LEFT),c.getLocation(1,Et.LEFT),2),g.setAtLeastIfValid(c.getLocation(0,Et.RIGHT),c.getLocation(1,Et.RIGHT),2))}}])})(sy),Sy=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"setWorkingPrecisionModel",value:function(u){this._workingPrecisionModel=u}},{key:"insertUniqueEdge",value:function(u){var c=this._edgeList.findEqualEdge(u);if(c!==null){var g=c.getLabel(),v=u.getLabel();c.isPointwiseEqual(u)||(v=new Ai(u.getLabel())).flip(),g.merge(v);var x=m.depthDelta(v),k=c.getDepthDelta()+x;c.setDepthDelta(k)}else this._edgeList.add(u),u.setDepthDelta(m.depthDelta(u.getLabel()))}},{key:"buildSubgraphs",value:function(u,c){for(var g=new Bt,v=u.iterator();v.hasNext();){var x=v.next(),k=x.getRightmostCoordinate(),O=new _y(g).getDepth(k);x.computeDepth(O),x.findResultEdges(),g.add(x),c.add(x.getDirectedEdges(),x.getNodes())}}},{key:"createSubgraphs",value:function(u){for(var c=new Bt,g=u.getNodes().iterator();g.hasNext();){var v=g.next();if(!v.isVisited()){var x=new kl;x.create(v),c.add(x)}}return Ho.sort(c,Ho.reverseOrder()),c}},{key:"createEmptyResultGeometry",value:function(){return this._geomFact.createPolygon()}},{key:"getNoder",value:function(u){if(this._workingNoder!==null)return this._workingNoder;var c=new Fd,g=new ro;return g.setPrecisionModel(u),c.setSegmentIntersector(new c2(g)),c}},{key:"buffer",value:function(u,c){var g=this._workingPrecisionModel;g===null&&(g=u.getPrecisionModel()),this._geomFact=u.getFactory();var v=new t2(g,this._bufParams),x=new n2(u,c,v).getCurves();if(x.size()<=0)return this.createEmptyResultGeometry();this.computeNodedEdges(x,g),this._graph=new cy(new l2),this._graph.addEdges(this._edgeList.getEdges());var k=this.createSubgraphs(this._graph),O=new qS(this._geomFact);this.buildSubgraphs(k,O);var G=O.getPolygons();return G.size()<=0?this.createEmptyResultGeometry():this._geomFact.buildGeometry(G)}},{key:"computeNodedEdges",value:function(u,c){var g=this.getNoder(c);g.computeNodes(u);for(var v=g.getNodedSubstrings().iterator();v.hasNext();){var x=v.next(),k=x.getCoordinates();if(k.length!==2||!k[0].equals2D(k[1])){var O=x.getData(),G=new Iy(x.getCoordinates(),new Ai(O));this.insertUniqueEdge(G)}}}},{key:"setNoder",value:function(u){this._workingNoder=u}}],[{key:"constructor_",value:function(){this._bufParams=null,this._workingPrecisionModel=null,this._workingNoder=null,this._geomFact=null,this._graph=null,this._edgeList=new u2;var u=arguments[0];this._bufParams=u}},{key:"depthDelta",value:function(u){var c=u.getLocation(0,Et.LEFT),g=u.getLocation(0,Et.RIGHT);return c===V.INTERIOR&&g===V.EXTERIOR?1:c===V.EXTERIOR&&g===V.INTERIOR?-1:0}},{key:"convertSegStrings",value:function(u){for(var c=new jo,g=new Bt;u.hasNext();){var v=u.next(),x=c.createLineString(v.getCoordinates());g.add(x)}return c.buildGeometry(g)}}])})(),y2=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"rescale",value:function(){if(H(arguments[0],Xt))for(var u=arguments[0].iterator();u.hasNext();){var c=u.next();this.rescale(c.getCoordinates())}else if(arguments[0]instanceof Array){for(var g=arguments[0],v=0;v<g.length;v++)g[v].x=g[v].x/this._scaleFactor+this._offsetX,g[v].y=g[v].y/this._scaleFactor+this._offsetY;g.length===2&&g[0].equals2D(g[1])&&Ti.out.println(g)}}},{key:"scale",value:function(){if(H(arguments[0],Xt)){for(var u=arguments[0],c=new Bt(u.size()),g=u.iterator();g.hasNext();){var v=g.next();c.add(new oo(this.scale(v.getCoordinates()),v.getData()))}return c}if(arguments[0]instanceof Array){for(var x=arguments[0],k=new Array(x.length).fill(null),O=0;O<x.length;O++)k[O]=new Q(Math.round((x[O].x-this._offsetX)*this._scaleFactor),Math.round((x[O].y-this._offsetY)*this._scaleFactor),x[O].getZ());return gn.removeRepeatedPoints(k)}}},{key:"isIntegerPrecision",value:function(){return this._scaleFactor===1}},{key:"getNodedSubstrings",value:function(){var u=this._noder.getNodedSubstrings();return this._isScaled&&this.rescale(u),u}},{key:"computeNodes",value:function(u){var c=u;this._isScaled&&(c=this.scale(u)),this._noder.computeNodes(c)}},{key:"interfaces_",get:function(){return[Od]}}],[{key:"constructor_",value:function(){if(this._noder=null,this._scaleFactor=null,this._offsetX=null,this._offsetY=null,this._isScaled=!1,arguments.length===2){var u=arguments[0],c=arguments[1];m.constructor_.call(this,u,c,0,0)}else if(arguments.length===4){var g=arguments[0],v=arguments[1];this._noder=g,this._scaleFactor=v,this._isScaled=!this.isIntegerPrecision()}}}])})(),My=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"checkEndPtVertexIntersections",value:function(){if(arguments.length===0)for(var u=this._segStrings.iterator();u.hasNext();){var c=u.next().getCoordinates();this.checkEndPtVertexIntersections(c[0],this._segStrings),this.checkEndPtVertexIntersections(c[c.length-1],this._segStrings)}else if(arguments.length===2){for(var g=arguments[0],v=arguments[1].iterator();v.hasNext();)for(var x=v.next().getCoordinates(),k=1;k<x.length-1;k++)if(x[k].equals(g))throw new lt("found endpt/interior pt intersection at index "+k+" :pt "+g)}}},{key:"checkInteriorIntersections",value:function(){if(arguments.length===0)for(var u=this._segStrings.iterator();u.hasNext();)for(var c=u.next(),g=this._segStrings.iterator();g.hasNext();){var v=g.next();this.checkInteriorIntersections(c,v)}else if(arguments.length===2)for(var x=arguments[0],k=arguments[1],O=x.getCoordinates(),G=k.getCoordinates(),X=0;X<O.length-1;X++)for(var st=0;st<G.length-1;st++)this.checkInteriorIntersections(x,X,k,st);else if(arguments.length===4){var at=arguments[0],mt=arguments[1],Pt=arguments[2],Ft=arguments[3];if(at===Pt&&mt===Ft)return null;var qt=at.getCoordinates()[mt],fe=at.getCoordinates()[mt+1],le=Pt.getCoordinates()[Ft],ke=Pt.getCoordinates()[Ft+1];if(this._li.computeIntersection(qt,fe,le,ke),this._li.hasIntersection()&&(this._li.isProper()||this.hasInteriorIntersection(this._li,qt,fe)||this.hasInteriorIntersection(this._li,le,ke)))throw new lt("found non-noded intersection at "+qt+"-"+fe+" and "+le+"-"+ke)}}},{key:"checkValid",value:function(){this.checkEndPtVertexIntersections(),this.checkInteriorIntersections(),this.checkCollapses()}},{key:"checkCollapses",value:function(){if(arguments.length===0)for(var u=this._segStrings.iterator();u.hasNext();){var c=u.next();this.checkCollapses(c)}else if(arguments.length===1)for(var g=arguments[0].getCoordinates(),v=0;v<g.length-2;v++)this.checkCollapse(g[v],g[v+1],g[v+2])}},{key:"hasInteriorIntersection",value:function(u,c,g){for(var v=0;v<u.getIntersectionNum();v++){var x=u.getIntersection(v);if(!x.equals(c)&&!x.equals(g))return!0}return!1}},{key:"checkCollapse",value:function(u,c,g){if(u.equals(g))throw new lt("found non-noded collapse at "+m.fact.createLineString([u,c,g]))}}],[{key:"constructor_",value:function(){this._li=new ro,this._segStrings=null;var u=arguments[0];this._segStrings=u}}])})();My.fact=new jo;var Dd=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"intersectsScaled",value:function(u,c){var g=Math.min(u.x,c.x),v=Math.max(u.x,c.x),x=Math.min(u.y,c.y),k=Math.max(u.y,c.y),O=this._maxx<g||this._minx>v||this._maxy<x||this._miny>k;if(O)return!1;var G=this.intersectsToleranceSquare(u,c);return ct.isTrue(!(O&&G),"Found bad envelope test"),G}},{key:"initCorners",value:function(u){var c=.5;this._minx=u.x-c,this._maxx=u.x+c,this._miny=u.y-c,this._maxy=u.y+c,this._corner[0]=new Q(this._maxx,this._maxy),this._corner[1]=new Q(this._minx,this._maxy),this._corner[2]=new Q(this._minx,this._miny),this._corner[3]=new Q(this._maxx,this._miny)}},{key:"intersects",value:function(u,c){return this._scaleFactor===1?this.intersectsScaled(u,c):(this.copyScaled(u,this._p0Scaled),this.copyScaled(c,this._p1Scaled),this.intersectsScaled(this._p0Scaled,this._p1Scaled))}},{key:"scale",value:function(u){return Math.round(u*this._scaleFactor)}},{key:"getCoordinate",value:function(){return this._originalPt}},{key:"copyScaled",value:function(u,c){c.x=this.scale(u.x),c.y=this.scale(u.y)}},{key:"getSafeEnvelope",value:function(){if(this._safeEnv===null){var u=m.SAFE_ENV_EXPANSION_FACTOR/this._scaleFactor;this._safeEnv=new Dt(this._originalPt.x-u,this._originalPt.x+u,this._originalPt.y-u,this._originalPt.y+u)}return this._safeEnv}},{key:"intersectsPixelClosure",value:function(u,c){return this._li.computeIntersection(u,c,this._corner[0],this._corner[1]),!!this._li.hasIntersection()||(this._li.computeIntersection(u,c,this._corner[1],this._corner[2]),!!this._li.hasIntersection()||(this._li.computeIntersection(u,c,this._corner[2],this._corner[3]),!!this._li.hasIntersection()||(this._li.computeIntersection(u,c,this._corner[3],this._corner[0]),!!this._li.hasIntersection())))}},{key:"intersectsToleranceSquare",value:function(u,c){var g=!1,v=!1;return this._li.computeIntersection(u,c,this._corner[0],this._corner[1]),!!this._li.isProper()||(this._li.computeIntersection(u,c,this._corner[1],this._corner[2]),!!this._li.isProper()||(this._li.hasIntersection()&&(g=!0),this._li.computeIntersection(u,c,this._corner[2],this._corner[3]),!!this._li.isProper()||(this._li.hasIntersection()&&(v=!0),this._li.computeIntersection(u,c,this._corner[3],this._corner[0]),!!this._li.isProper()||!(!g||!v)||!!u.equals(this._pt)||!!c.equals(this._pt))))}},{key:"addSnappedNode",value:function(u,c){var g=u.getCoordinate(c),v=u.getCoordinate(c+1);return!!this.intersects(g,v)&&(u.addIntersection(this.getCoordinate(),c),!0)}}],[{key:"constructor_",value:function(){this._li=null,this._pt=null,this._originalPt=null,this._ptScaled=null,this._p0Scaled=null,this._p1Scaled=null,this._scaleFactor=null,this._minx=null,this._maxx=null,this._miny=null,this._maxy=null,this._corner=new Array(4).fill(null),this._safeEnv=null;var u=arguments[0],c=arguments[1],g=arguments[2];if(this._originalPt=u,this._pt=u,this._scaleFactor=c,this._li=g,c<=0)throw new S("Scale factor must be non-zero");c!==1&&(this._pt=new Q(this.scale(u.x),this.scale(u.y)),this._p0Scaled=new Q,this._p1Scaled=new Q),this.initCorners(this._pt)}}])})();Dd.SAFE_ENV_EXPANSION_FACTOR=.75;var _2=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"select",value:function(){if(arguments.length!==1){if(arguments.length===2){var m=arguments[1];arguments[0].getLineSegment(m,this.selectedSegment),this.select(this.selectedSegment)}}}}],[{key:"constructor_",value:function(){this.selectedSegment=new yi}}])})(),Ny=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"snap",value:function(){if(arguments.length===1){var m=arguments[0];return this.snap(m,null,-1)}if(arguments.length===3){var u=arguments[0],c=arguments[1],g=arguments[2],v=u.getSafeEnvelope(),x=new Ly(u,c,g);return this._index.query(v,new((function(){return a((function k(){s(this,k)}),[{key:"interfaces_",get:function(){return[fy]}},{key:"visitItem",value:function(k){k.select(v,x)}}])})())),x.isNodeAdded()}}}],[{key:"constructor_",value:function(){this._index=null;var m=arguments[0];this._index=m}}])})(),Ly=(function(m){function u(){var c;return s(this,u),c=n(this,u),u.constructor_.apply(c,arguments),c}return d(u,m),a(u,[{key:"isNodeAdded",value:function(){return this._isNodeAdded}},{key:"select",value:function(){if(!(arguments.length===2&&Number.isInteger(arguments[1])&&arguments[0]instanceof gy))return _(u,"select",this,1).apply(this,arguments);var c=arguments[1],g=arguments[0].getContext();if(this._parentEdge===g&&(c===this._hotPixelVertexIndex||c+1===this._hotPixelVertexIndex))return null;this._isNodeAdded|=this._hotPixel.addSnappedNode(g,c)}}],[{key:"constructor_",value:function(){this._hotPixel=null,this._parentEdge=null,this._hotPixelVertexIndex=null,this._isNodeAdded=!1;var c=arguments[0],g=arguments[1],v=arguments[2];this._hotPixel=c,this._parentEdge=g,this._hotPixelVertexIndex=v}}])})(_2);Ny.HotPixelSnapAction=Ly;var v2=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"processIntersections",value:function(m,u,c,g){if(m===c&&u===g)return null;var v=m.getCoordinates()[u],x=m.getCoordinates()[u+1],k=c.getCoordinates()[g],O=c.getCoordinates()[g+1];if(this._li.computeIntersection(v,x,k,O),this._li.hasIntersection()&&this._li.isInteriorIntersection()){for(var G=0;G<this._li.getIntersectionNum();G++)this._interiorIntersections.add(this._li.getIntersection(G));m.addIntersections(this._li,u,0),c.addIntersections(this._li,g,1)}}},{key:"isDone",value:function(){return!1}},{key:"getInteriorIntersections",value:function(){return this._interiorIntersections}},{key:"interfaces_",get:function(){return[xy]}}],[{key:"constructor_",value:function(){this._li=null,this._interiorIntersections=null;var m=arguments[0];this._li=m,this._interiorIntersections=new Bt}}])})(),E2=(function(){return a((function m(){s(this,m),m.constructor_.apply(this,arguments)}),[{key:"checkCorrectness",value:function(m){var u=oo.getNodedSubstrings(m),c=new My(u);try{c.checkValid()}catch(g){if(!(g instanceof N))throw g;g.printStackTrace()}}},{key:"getNodedSubstrings",value:function(){return oo.getNodedSubstrings(this._nodedSegStrings)}},{key:"snapRound",value:function(m,u){var c=this.findInteriorIntersections(m,u);this.computeIntersectionSnaps(c),this.computeVertexSnaps(m)}},{key:"findInteriorIntersections",value:function(m,u){var c=new v2(u);return this._noder.setSegmentIntersector(c),this._noder.computeNodes(m),c.getInteriorIntersections()}},{key:"computeVertexSnaps",value:function(){if(H(arguments[0],Xt))for(var m=arguments[0].iterator();m.hasNext();){var u=m.next();this.computeVertexSnaps(u)}else if(arguments[0]instanceof oo)for(var c=arguments[0],g=c.getCoordinates(),v=0;v<g.length;v++){var x=new Dd(g[v],this._scaleFactor,this._li);this._pointSnapper.snap(x,c,v)&&c.addIntersection(g[v],v)}}},{key:"computeNodes",value:function(m){this._nodedSegStrings=m,this._noder=new Fd,this._pointSnapper=new Ny(this._noder.getIndex()),this.snapRound(m,this._li)}},{key:"computeIntersectionSnaps",value:function(m){for(var u=m.iterator();u.hasNext();){var c=u.next(),g=new Dd(c,this._scaleFactor,this._li);this._pointSnapper.snap(g)}}},{key:"interfaces_",get:function(){return[Od]}}],[{key:"constructor_",value:function(){this._pm=null,this._li=null,this._scaleFactor=null,this._noder=null,this._pointSnapper=null,this._nodedSegStrings=null;var m=arguments[0];this._pm=m,this._li=new ro,this._li.setPrecisionModel(m),this._scaleFactor=m.getScale()}}])})(),Zo=(function(){function m(){s(this,m),m.constructor_.apply(this,arguments)}return a(m,[{key:"bufferFixedPrecision",value:function(u){var c=new y2(new E2(new rs(1)),u.getScale()),g=new Sy(this._bufParams);g.setWorkingPrecisionModel(u),g.setNoder(c),this._resultGeometry=g.buffer(this._argGeom,this._distance)}},{key:"bufferReducedPrecision",value:function(){if(arguments.length===0){for(var u=m.MAX_PRECISION_DIGITS;u>=0;u--){try{this.bufferReducedPrecision(u)}catch(x){if(!(x instanceof Ae))throw x;this._saveException=x}if(this._resultGeometry!==null)return null}throw this._saveException}if(arguments.length===1){var c=arguments[0],g=m.precisionScaleFactor(this._argGeom,this._distance,c),v=new rs(g);this.bufferFixedPrecision(v)}}},{key:"computeGeometry",value:function(){if(this.bufferOriginalPrecision(),this._resultGeometry!==null)return null;var u=this._argGeom.getFactory().getPrecisionModel();u.getType()===rs.FIXED?this.bufferFixedPrecision(u):this.bufferReducedPrecision()}},{key:"setQuadrantSegments",value:function(u){this._bufParams.setQuadrantSegments(u)}},{key:"bufferOriginalPrecision",value:function(){try{var u=new Sy(this._bufParams);this._resultGeometry=u.buffer(this._argGeom,this._distance)}catch(c){if(!(c instanceof lt))throw c;this._saveException=c}}},{key:"getResultGeometry",value:function(u){return this._distance=u,this.computeGeometry(),this._resultGeometry}},{key:"setEndCapStyle",value:function(u){this._bufParams.setEndCapStyle(u)}}],[{key:"constructor_",value:function(){if(this._argGeom=null,this._distance=null,this._bufParams=new P,this._resultGeometry=null,this._saveException=null,arguments.length===1){var u=arguments[0];this._argGeom=u}else if(arguments.length===2){var c=arguments[0],g=arguments[1];this._argGeom=c,this._bufParams=g}}},{key:"bufferOp",value:function(){if(arguments.length===2){var u=arguments[1];return new m(arguments[0]).getResultGeometry(u)}if(arguments.length===3){if(Number.isInteger(arguments[2])&&arguments[0]instanceof wt&&typeof arguments[1]=="number"){var c=arguments[1],g=arguments[2],v=new m(arguments[0]);return v.setQuadrantSegments(g),v.getResultGeometry(c)}if(arguments[2]instanceof P&&arguments[0]instanceof wt&&typeof arguments[1]=="number"){var x=arguments[1];return new m(arguments[0],arguments[2]).getResultGeometry(x)}}else if(arguments.length===4){var k=arguments[1],O=arguments[2],G=arguments[3],X=new m(arguments[0]);return X.setQuadrantSegments(O),X.setEndCapStyle(G),X.getResultGeometry(k)}}},{key:"precisionScaleFactor",value:function(u,c,g){var v=u.getEnvelopeInternal(),x=Rl.max(Math.abs(v.getMaxX()),Math.abs(v.getMaxY()),Math.abs(v.getMinX()),Math.abs(v.getMinY()))+2*(c>0?c:0),k=g-Math.trunc(Math.log(x)/Math.log(10)+1);return Math.pow(10,k)}}])})();Zo.CAP_ROUND=P.CAP_ROUND,Zo.CAP_BUTT=P.CAP_FLAT,Zo.CAP_FLAT=P.CAP_FLAT,Zo.CAP_SQUARE=P.CAP_SQUARE,Zo.MAX_PRECISION_DIGITS=12;var w2=["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon"],Cy=(function(){return a((function m(u){s(this,m),this.geometryFactory=u||new jo}),[{key:"read",value:function(m){var u,c=(u=typeof m=="string"?JSON.parse(m):m).type;if(!Fi[c])throw new Error("Unknown GeoJSON type: "+u.type);return w2.indexOf(c)!==-1?Fi[c].call(this,u.coordinates):c==="GeometryCollection"?Fi[c].call(this,u.geometries):Fi[c].call(this,u)}},{key:"write",value:function(m){var u=m.getGeometryType();if(!Ps[u])throw new Error("Geometry is not supported");return Ps[u].call(this,m)}}])})(),Fi={Feature:function(m){var u={};for(var c in m)u[c]=m[c];if(m.geometry){var g=m.geometry.type;if(!Fi[g])throw new Error("Unknown GeoJSON type: "+m.type);u.geometry=this.read(m.geometry)}return m.bbox&&(u.bbox=Fi.bbox.call(this,m.bbox)),u},FeatureCollection:function(m){var u={};if(m.features){u.features=[];for(var c=0;c<m.features.length;++c)u.features.push(this.read(m.features[c]))}return m.bbox&&(u.bbox=this.parse.bbox.call(this,m.bbox)),u},coordinates:function(m){for(var u=[],c=0;c<m.length;++c){var g=m[c];u.push(r(Q,E(g)))}return u},bbox:function(m){return this.geometryFactory.createLinearRing([new Q(m[0],m[1]),new Q(m[2],m[1]),new Q(m[2],m[3]),new Q(m[0],m[3]),new Q(m[0],m[1])])},Point:function(m){var u=r(Q,E(m));return this.geometryFactory.createPoint(u)},MultiPoint:function(m){for(var u=[],c=0;c<m.length;++c)u.push(Fi.Point.call(this,m[c]));return this.geometryFactory.createMultiPoint(u)},LineString:function(m){var u=Fi.coordinates.call(this,m);return this.geometryFactory.createLineString(u)},MultiLineString:function(m){for(var u=[],c=0;c<m.length;++c)u.push(Fi.LineString.call(this,m[c]));return this.geometryFactory.createMultiLineString(u)},Polygon:function(m){for(var u=Fi.coordinates.call(this,m[0]),c=this.geometryFactory.createLinearRing(u),g=[],v=1;v<m.length;++v){var x=m[v],k=Fi.coordinates.call(this,x),O=this.geometryFactory.createLinearRing(k);g.push(O)}return this.geometryFactory.createPolygon(c,g)},MultiPolygon:function(m){for(var u=[],c=0;c<m.length;++c){var g=m[c];u.push(Fi.Polygon.call(this,g))}return this.geometryFactory.createMultiPolygon(u)},GeometryCollection:function(m){for(var u=[],c=0;c<m.length;++c){var g=m[c];u.push(this.read(g))}return this.geometryFactory.createGeometryCollection(u)}},Ps={coordinate:function(m){var u=[m.x,m.y];return m.z&&u.push(m.z),m.m&&u.push(m.m),u},Point:function(m){return{type:"Point",coordinates:Ps.coordinate.call(this,m.getCoordinate())}},MultiPoint:function(m){for(var u=[],c=0;c<m._geometries.length;++c){var g=m._geometries[c],v=Ps.Point.call(this,g);u.push(v.coordinates)}return{type:"MultiPoint",coordinates:u}},LineString:function(m){for(var u=[],c=m.getCoordinates(),g=0;g<c.length;++g){var v=c[g];u.push(Ps.coordinate.call(this,v))}return{type:"LineString",coordinates:u}},MultiLineString:function(m){for(var u=[],c=0;c<m._geometries.length;++c){var g=m._geometries[c],v=Ps.LineString.call(this,g);u.push(v.coordinates)}return{type:"MultiLineString",coordinates:u}},Polygon:function(m){var u=[],c=Ps.LineString.call(this,m._shell);u.push(c.coordinates);for(var g=0;g<m._holes.length;++g){var v=m._holes[g],x=Ps.LineString.call(this,v);u.push(x.coordinates)}return{type:"Polygon",coordinates:u}},MultiPolygon:function(m){for(var u=[],c=0;c<m._geometries.length;++c){var g=m._geometries[c],v=Ps.Polygon.call(this,g);u.push(v.coordinates)}return{type:"MultiPolygon",coordinates:u}},GeometryCollection:function(m){for(var u=[],c=0;c<m._geometries.length;++c){var g=m._geometries[c],v=g.getGeometryType();u.push(Ps[v].call(this,g))}return{type:"GeometryCollection",geometries:u}}};return{BufferOp:Zo,GeoJSONReader:(function(){return a((function m(u){s(this,m),this.parser=new Cy(u||new jo)}),[{key:"read",value:function(m){return this.parser.read(m)}}])})(),GeoJSONWriter:(function(){return a((function m(){s(this,m),this.parser=new Cy(this.geometryFactory)}),[{key:"write",value:function(m){return this.parser.write(m)}}])})()}}))})(bh)),bh.exports}var OT=AT();const FT=zE(OT);class $T{constructor(){this._partials=new Float64Array(32),this._n=0}add(t){const e=this._partials;let n=0;for(let s=0;s<this._n&&s<32;s++){const r=e[s],o=t+r,a=Math.abs(t)<Math.abs(r)?t-(o-r):r-(o-t);a&&(e[n++]=a),t=o}return e[n]=t,this._n=n+1,this}valueOf(){const t=this._partials;let e=this._n,n,s,r,o=0;if(e>0){for(o=t[--e];e>0&&(n=o,s=t[--e],o=n+s,r=s-(o-n),!r););e>0&&(r<0&&t[e-1]<0||r>0&&t[e-1]>0)&&(s=r*2,n=o+s,s==n-o&&(o=n))}return o}}function*DT(i){for(const t of i)yield*t}function YE(i){return Array.from(DT(i))}var Re=1e-6,ge=Math.PI,Ki=ge/2,T1=ge/4,bs=ge*2,ir=180/ge,wi=ge/180,on=Math.abs,GT=Math.atan,Za=Math.atan2,Xe=Math.cos,Fe=Math.sin,BT=Math.sign||function(i){return i>0?1:i<0?-1:0},pc=Math.sqrt;function XE(i){return i>1?0:i<-1?ge:Math.acos(i)}function Ja(i){return i>1?Ki:i<-1?-Ki:Math.asin(i)}function uu(){}function Jh(i,t){i&&A1.hasOwnProperty(i.type)&&A1[i.type](i,t)}var R1={Feature:function(i,t){Jh(i.geometry,t)},FeatureCollection:function(i,t){for(var e=i.features,n=-1,s=e.length;++n<s;)Jh(e[n].geometry,t)}},A1={Sphere:function(i,t){t.sphere()},Point:function(i,t){i=i.coordinates,t.point(i[0],i[1],i[2])},MultiPoint:function(i,t){for(var e=i.coordinates,n=-1,s=e.length;++n<s;)i=e[n],t.point(i[0],i[1],i[2])},LineString:function(i,t){Vg(i.coordinates,t,0)},MultiLineString:function(i,t){for(var e=i.coordinates,n=-1,s=e.length;++n<s;)Vg(e[n],t,0)},Polygon:function(i,t){O1(i.coordinates,t)},MultiPolygon:function(i,t){for(var e=i.coordinates,n=-1,s=e.length;++n<s;)O1(e[n],t)},GeometryCollection:function(i,t){for(var e=i.geometries,n=-1,s=e.length;++n<s;)Jh(e[n],t)}};function Vg(i,t,e){var n=-1,s=i.length-e,r;for(t.lineStart();++n<s;)r=i[n],t.point(r[0],r[1],r[2]);t.lineEnd()}function O1(i,t){var e=-1,n=i.length;for(t.polygonStart();++e<n;)Vg(i[e],t,1);t.polygonEnd()}function qT(i,t){i&&R1.hasOwnProperty(i.type)?R1[i.type](i,t):Jh(i,t)}function Hg(i){return[Za(i[1],i[0]),Ja(i[2])]}function Qa(i){var t=i[0],e=i[1],n=Xe(e);return[n*Xe(t),n*Fe(t),Fe(e)]}function Zc(i,t){return i[0]*t[0]+i[1]*t[1]+i[2]*t[2]}function Qh(i,t){return[i[1]*t[2]-i[2]*t[1],i[2]*t[0]-i[0]*t[2],i[0]*t[1]-i[1]*t[0]]}function ng(i,t){i[0]+=t[0],i[1]+=t[1],i[2]+=t[2]}function Jc(i,t){return[i[0]*t,i[1]*t,i[2]*t]}function Wg(i){var t=pc(i[0]*i[0]+i[1]*i[1]+i[2]*i[2]);i[0]/=t,i[1]/=t,i[2]/=t}function Kg(i,t){function e(n,s){return n=i(n,s),t(n[0],n[1])}return i.invert&&t.invert&&(e.invert=function(n,s){return n=t.invert(n,s),n&&i.invert(n[0],n[1])}),e}function Zg(i,t){return[on(i)>ge?i+Math.round(-i/bs)*bs:i,t]}Zg.invert=Zg;function zT(i,t,e){return(i%=bs)?t||e?Kg($1(i),D1(t,e)):$1(i):t||e?D1(t,e):Zg}function F1(i){return function(t,e){return t+=i,[t>ge?t-bs:t<-ge?t+bs:t,e]}}function $1(i){var t=F1(i);return t.invert=F1(-i),t}function D1(i,t){var e=Xe(i),n=Fe(i),s=Xe(t),r=Fe(t);function o(a,l){var h=Xe(l),f=Xe(a)*h,d=Fe(a)*h,p=Fe(l),y=p*e+f*n;return[Za(d*s-y*r,f*e-p*n),Ja(y*s+d*r)]}return o.invert=function(a,l){var h=Xe(l),f=Xe(a)*h,d=Fe(a)*h,p=Fe(l),y=p*s-d*r;return[Za(d*s+p*r,f*e+y*n),Ja(y*e-f*n)]},o}function UT(i,t,e,n,s,r){if(e){var o=Xe(t),a=Fe(t),l=n*e;s==null?(s=t+n*bs,r=t-l/2):(s=G1(o,s),r=G1(o,r),(n>0?s<r:s>r)&&(s+=n*bs));for(var h,f=s;n>0?f>r:f<r;f-=l)h=Hg([o,-a*Xe(f),-a*Fe(f)]),i.point(h[0],h[1])}}function G1(i,t){t=Qa(t),t[0]-=i,Wg(t);var e=XE(-t[1]);return((-t[2]<0?-e:e)+bs-Re)%bs}function jE(){var i=[],t;return{point:function(e,n,s){t.push([e,n,s])},lineStart:function(){i.push(t=[])},lineEnd:uu,rejoin:function(){i.length>1&&i.push(i.pop().concat(i.shift()))},result:function(){var e=i;return i=[],t=null,e}}}function Ih(i,t){return on(i[0]-t[0])<Re&&on(i[1]-t[1])<Re}function Qc(i,t,e,n){this.x=i,this.z=t,this.o=e,this.e=n,this.v=!1,this.n=this.p=null}function VE(i,t,e,n,s){var r=[],o=[],a,l;if(i.forEach(function(_){if(!((E=_.length-1)<=0)){var E,w=_[0],L=_[E],b;if(Ih(w,L)){if(!w[2]&&!L[2]){for(s.lineStart(),a=0;a<E;++a)s.point((w=_[a])[0],w[1]);s.lineEnd();return}L[0]+=2*Re}r.push(b=new Qc(w,_,null,!0)),o.push(b.o=new Qc(w,null,b,!1)),r.push(b=new Qc(L,_,null,!1)),o.push(b.o=new Qc(L,null,b,!0))}}),!!r.length){for(o.sort(t),B1(r),B1(o),a=0,l=o.length;a<l;++a)o[a].e=e=!e;for(var h=r[0],f,d;;){for(var p=h,y=!0;p.v;)if((p=p.n)===h)return;f=p.z,s.lineStart();do{if(p.v=p.o.v=!0,p.e){if(y)for(a=0,l=f.length;a<l;++a)s.point((d=f[a])[0],d[1]);else n(p.x,p.n.x,1,s);p=p.n}else{if(y)for(f=p.p.z,a=f.length-1;a>=0;--a)s.point((d=f[a])[0],d[1]);else n(p.x,p.p.x,-1,s);p=p.p}p=p.o,f=p.z,y=!y}while(!p.v);s.lineEnd()}}}function B1(i){if(t=i.length){for(var t,e=0,n=i[0],s;++e<t;)n.n=s=i[e],s.p=n,n=s;n.n=s=i[0],s.p=n}}function ig(i){return on(i[0])<=ge?i[0]:BT(i[0])*((on(i[0])+ge)%bs-ge)}function YT(i,t){var e=ig(t),n=t[1],s=Fe(n),r=[Fe(e),-Xe(e),0],o=0,a=0,l=new $T;s===1?n=Ki+Re:s===-1&&(n=-Ki-Re);for(var h=0,f=i.length;h<f;++h)if(p=(d=i[h]).length)for(var d,p,y=d[p-1],_=ig(y),E=y[1]/2+T1,w=Fe(E),L=Xe(E),b=0;b<p;++b,_=N,w=C,L=T,y=P){var P=d[b],N=ig(P),S=P[1]/2+T1,C=Fe(S),T=Xe(S),I=N-_,M=I>=0?1:-1,R=M*I,A=R>ge,F=w*C;if(l.add(Za(F*M*Fe(R),L*T+F*Xe(R))),o+=A?I+M*bs:I,A^_>=e^N>=e){var $=Qh(Qa(y),Qa(P));Wg($);var z=Qh(r,$);Wg(z);var D=(A^I>=0?-1:1)*Ja(z[2]);(n>D||n===D&&($[0]||$[1]))&&(a+=A^I>=0?1:-1)}}return(o<-Re||o<Re&&l<-1e-12)^a&1}function HE(i,t,e,n){return function(s){var r=t(s),o=jE(),a=t(o),l=!1,h,f,d,p={point:y,lineStart:E,lineEnd:w,polygonStart:function(){p.point=L,p.lineStart=b,p.lineEnd=P,f=[],h=[]},polygonEnd:function(){p.point=y,p.lineStart=E,p.lineEnd=w,f=YE(f);var N=YT(h,n);f.length?(l||(s.polygonStart(),l=!0),VE(f,jT,N,e,s)):N&&(l||(s.polygonStart(),l=!0),s.lineStart(),e(null,null,1,s),s.lineEnd()),l&&(s.polygonEnd(),l=!1),f=h=null},sphere:function(){s.polygonStart(),s.lineStart(),e(null,null,1,s),s.lineEnd(),s.polygonEnd()}};function y(N,S){i(N,S)&&s.point(N,S)}function _(N,S){r.point(N,S)}function E(){p.point=_,r.lineStart()}function w(){p.point=y,r.lineEnd()}function L(N,S){d.push([N,S]),a.point(N,S)}function b(){a.lineStart(),d=[]}function P(){L(d[0][0],d[0][1]),a.lineEnd();var N=a.clean(),S=o.result(),C,T=S.length,I,M,R;if(d.pop(),h.push(d),d=null,!!T){if(N&1){if(M=S[0],(I=M.length-1)>0){for(l||(s.polygonStart(),l=!0),s.lineStart(),C=0;C<I;++C)s.point((R=M[C])[0],R[1]);s.lineEnd()}return}T>1&&N&2&&S.push(S.pop().concat(S.shift())),f.push(S.filter(XT))}}return p}}function XT(i){return i.length>1}function jT(i,t){return((i=i.x)[0]<0?i[1]-Ki-Re:Ki-i[1])-((t=t.x)[0]<0?t[1]-Ki-Re:Ki-t[1])}const q1=HE(function(){return!0},VT,WT,[-ge,-Ki]);function VT(i){var t=NaN,e=NaN,n=NaN,s;return{lineStart:function(){i.lineStart(),s=1},point:function(r,o){var a=r>0?ge:-ge,l=on(r-t);on(l-ge)<Re?(i.point(t,e=(e+o)/2>0?Ki:-Ki),i.point(n,e),i.lineEnd(),i.lineStart(),i.point(a,e),i.point(r,e),s=0):n!==a&&l>=ge&&(on(t-n)<Re&&(t-=n*Re),on(r-a)<Re&&(r-=a*Re),e=HT(t,e,r,o),i.point(n,e),i.lineEnd(),i.lineStart(),i.point(a,e),s=0),i.point(t=r,e=o),n=a},lineEnd:function(){i.lineEnd(),t=e=NaN},clean:function(){return 2-s}}}function HT(i,t,e,n){var s,r,o=Fe(i-e);return on(o)>Re?GT((Fe(t)*(r=Xe(n))*Fe(e)-Fe(n)*(s=Xe(t))*Fe(i))/(s*r*o)):(t+n)/2}function WT(i,t,e,n){var s;if(i==null)s=e*Ki,n.point(-ge,s),n.point(0,s),n.point(ge,s),n.point(ge,0),n.point(ge,-s),n.point(0,-s),n.point(-ge,-s),n.point(-ge,0),n.point(-ge,s);else if(on(i[0]-t[0])>Re){var r=i[0]<t[0]?ge:-ge;s=e*r/2,n.point(-r,s),n.point(0,s),n.point(r,s)}else n.point(t[0],t[1])}function KT(i){var t=Xe(i),e=6*wi,n=t>0,s=on(t)>Re;function r(f,d,p,y){UT(y,i,e,p,f,d)}function o(f,d){return Xe(f)*Xe(d)>t}function a(f){var d,p,y,_,E;return{lineStart:function(){_=y=!1,E=1},point:function(w,L){var b=[w,L],P,N=o(w,L),S=n?N?0:h(w,L):N?h(w+(w<0?ge:-ge),L):0;if(!d&&(_=y=N)&&f.lineStart(),N!==y&&(P=l(d,b),(!P||Ih(d,P)||Ih(b,P))&&(b[2]=1)),N!==y)E=0,N?(f.lineStart(),P=l(b,d),f.point(P[0],P[1])):(P=l(d,b),f.point(P[0],P[1],2),f.lineEnd()),d=P;else if(s&&d&&n^N){var C;!(S&p)&&(C=l(b,d,!0))&&(E=0,n?(f.lineStart(),f.point(C[0][0],C[0][1]),f.point(C[1][0],C[1][1]),f.lineEnd()):(f.point(C[1][0],C[1][1]),f.lineEnd(),f.lineStart(),f.point(C[0][0],C[0][1],3)))}N&&(!d||!Ih(d,b))&&f.point(b[0],b[1]),d=b,y=N,p=S},lineEnd:function(){y&&f.lineEnd(),d=null},clean:function(){return E|(_&&y)<<1}}}function l(f,d,p){var y=Qa(f),_=Qa(d),E=[1,0,0],w=Qh(y,_),L=Zc(w,w),b=w[0],P=L-b*b;if(!P)return!p&&f;var N=t*L/P,S=-t*b/P,C=Qh(E,w),T=Jc(E,N),I=Jc(w,S);ng(T,I);var M=C,R=Zc(T,M),A=Zc(M,M),F=R*R-A*(Zc(T,T)-1);if(!(F<0)){var $=pc(F),z=Jc(M,(-R-$)/A);if(ng(z,T),z=Hg(z),!p)return z;var D=f[0],B=d[0],U=f[1],j=d[1],K;B<D&&(K=D,D=B,B=K);var W=B-D,J=on(W-ge)<Re,lt=J||W<Re;if(!J&&j<U&&(K=U,U=j,j=K),lt?J?U+j>0^z[1]<(on(z[0]-D)<Re?U:j):U<=z[1]&&z[1]<=j:W>ge^(D<=z[0]&&z[0]<=B)){var ft=Jc(M,(-R+$)/A);return ng(ft,T),[z,Hg(ft)]}}}function h(f,d){var p=n?i:ge-i,y=0;return f<-p?y|=1:f>p&&(y|=2),d<-p?y|=4:d>p&&(y|=8),y}return HE(o,a,r,n?[0,-i]:[-ge,i-ge])}function ZT(i,t,e,n,s,r){var o=i[0],a=i[1],l=t[0],h=t[1],f=0,d=1,p=l-o,y=h-a,_;if(_=e-o,!(!p&&_>0)){if(_/=p,p<0){if(_<f)return;_<d&&(d=_)}else if(p>0){if(_>d)return;_>f&&(f=_)}if(_=s-o,!(!p&&_<0)){if(_/=p,p<0){if(_>d)return;_>f&&(f=_)}else if(p>0){if(_<f)return;_<d&&(d=_)}if(_=n-a,!(!y&&_>0)){if(_/=y,y<0){if(_<f)return;_<d&&(d=_)}else if(y>0){if(_>d)return;_>f&&(f=_)}if(_=r-a,!(!y&&_<0)){if(_/=y,y<0){if(_>d)return;_>f&&(f=_)}else if(y>0){if(_<f)return;_<d&&(d=_)}return f>0&&(i[0]=o+f*p,i[1]=a+f*y),d<1&&(t[0]=o+d*p,t[1]=a+d*y),!0}}}}}var cu=1e9,th=-cu;function JT(i,t,e,n){function s(h,f){return i<=h&&h<=e&&t<=f&&f<=n}function r(h,f,d,p){var y=0,_=0;if(h==null||(y=o(h,d))!==(_=o(f,d))||l(h,f)<0^d>0)do p.point(y===0||y===3?i:e,y>1?n:t);while((y=(y+d+4)%4)!==_);else p.point(f[0],f[1])}function o(h,f){return on(h[0]-i)<Re?f>0?0:3:on(h[0]-e)<Re?f>0?2:1:on(h[1]-t)<Re?f>0?1:0:f>0?3:2}function a(h,f){return l(h.x,f.x)}function l(h,f){var d=o(h,1),p=o(f,1);return d!==p?d-p:d===0?f[1]-h[1]:d===1?h[0]-f[0]:d===2?h[1]-f[1]:f[0]-h[0]}return function(h){var f=h,d=jE(),p,y,_,E,w,L,b,P,N,S,C,T={point:I,lineStart:F,lineEnd:$,polygonStart:R,polygonEnd:A};function I(D,B){s(D,B)&&f.point(D,B)}function M(){for(var D=0,B=0,U=y.length;B<U;++B)for(var j=y[B],K=1,W=j.length,J=j[0],lt,ft,ct=J[0],gt=J[1];K<W;++K)lt=ct,ft=gt,J=j[K],ct=J[0],gt=J[1],ft<=n?gt>n&&(ct-lt)*(n-ft)>(gt-ft)*(i-lt)&&++D:gt<=n&&(ct-lt)*(n-ft)<(gt-ft)*(i-lt)&&--D;return D}function R(){f=d,p=[],y=[],C=!0}function A(){var D=M(),B=C&&D,U=(p=YE(p)).length;(B||U)&&(h.polygonStart(),B&&(h.lineStart(),r(null,null,1,h),h.lineEnd()),U&&VE(p,a,D,r,h),h.polygonEnd()),f=h,p=y=_=null}function F(){T.point=z,y&&y.push(_=[]),S=!0,N=!1,b=P=NaN}function $(){p&&(z(E,w),L&&N&&d.rejoin(),p.push(d.result())),T.point=I,N&&f.lineEnd()}function z(D,B){var U=s(D,B);if(y&&_.push([D,B]),S)E=D,w=B,L=U,S=!1,U&&(f.lineStart(),f.point(D,B));else if(U&&N)f.point(D,B);else{var j=[b=Math.max(th,Math.min(cu,b)),P=Math.max(th,Math.min(cu,P))],K=[D=Math.max(th,Math.min(cu,D)),B=Math.max(th,Math.min(cu,B))];ZT(j,K,i,t,e,n)?(N||(f.lineStart(),f.point(j[0],j[1])),f.point(K[0],K[1]),U||f.lineEnd(),C=!1):U&&(f.lineStart(),f.point(D,B),C=!1)}b=D,P=B,N=U}return T}}const z1=i=>i;var tl=1/0,tf=tl,Ru=-tl,ef=Ru,U1={point:QT,lineStart:uu,lineEnd:uu,polygonStart:uu,polygonEnd:uu,result:function(){var i=[[tl,tf],[Ru,ef]];return Ru=ef=-(tf=tl=1/0),i}};function QT(i,t){i<tl&&(tl=i),i>Ru&&(Ru=i),t<tf&&(tf=t),t>ef&&(ef=t)}function Qm(i){return function(t){var e=new Jg;for(var n in i)e[n]=i[n];return e.stream=t,e}}function Jg(){}Jg.prototype={constructor:Jg,point:function(i,t){this.stream.point(i,t)},sphere:function(){this.stream.sphere()},lineStart:function(){this.stream.lineStart()},lineEnd:function(){this.stream.lineEnd()},polygonStart:function(){this.stream.polygonStart()},polygonEnd:function(){this.stream.polygonEnd()}};function tp(i,t,e){var n=i.clipExtent&&i.clipExtent();return i.scale(150).translate([0,0]),n!=null&&i.clipExtent(null),qT(e,i.stream(U1)),t(U1.result()),n!=null&&i.clipExtent(n),i}function WE(i,t,e){return tp(i,function(n){var s=t[1][0]-t[0][0],r=t[1][1]-t[0][1],o=Math.min(s/(n[1][0]-n[0][0]),r/(n[1][1]-n[0][1])),a=+t[0][0]+(s-o*(n[1][0]+n[0][0]))/2,l=+t[0][1]+(r-o*(n[1][1]+n[0][1]))/2;i.scale(150*o).translate([a,l])},e)}function tR(i,t,e){return WE(i,[[0,0],t],e)}function eR(i,t,e){return tp(i,function(n){var s=+t,r=s/(n[1][0]-n[0][0]),o=(s-r*(n[1][0]+n[0][0]))/2,a=-r*n[0][1];i.scale(150*r).translate([o,a])},e)}function nR(i,t,e){return tp(i,function(n){var s=+t,r=s/(n[1][1]-n[0][1]),o=-r*n[0][0],a=(s-r*(n[1][1]+n[0][1]))/2;i.scale(150*r).translate([o,a])},e)}var Y1=16,iR=Xe(30*wi);function X1(i,t){return+t?rR(i,t):sR(i)}function sR(i){return Qm({point:function(t,e){t=i(t,e),this.stream.point(t[0],t[1])}})}function rR(i,t){function e(n,s,r,o,a,l,h,f,d,p,y,_,E,w){var L=h-n,b=f-s,P=L*L+b*b;if(P>4*t&&E--){var N=o+p,S=a+y,C=l+_,T=pc(N*N+S*S+C*C),I=Ja(C/=T),M=on(on(C)-1)<Re||on(r-d)<Re?(r+d)/2:Za(S,N),R=i(M,I),A=R[0],F=R[1],$=A-n,z=F-s,D=b*$-L*z;(D*D/P>t||on((L*$+b*z)/P-.5)>.3||o*p+a*y+l*_<iR)&&(e(n,s,r,o,a,l,A,F,M,N/=T,S/=T,C,E,w),w.point(A,F),e(A,F,M,N,S,C,h,f,d,p,y,_,E,w))}}return function(n){var s,r,o,a,l,h,f,d,p,y,_,E,w={point:L,lineStart:b,lineEnd:N,polygonStart:function(){n.polygonStart(),w.lineStart=S},polygonEnd:function(){n.polygonEnd(),w.lineStart=b}};function L(I,M){I=i(I,M),n.point(I[0],I[1])}function b(){d=NaN,w.point=P,n.lineStart()}function P(I,M){var R=Qa([I,M]),A=i(I,M);e(d,p,f,y,_,E,d=A[0],p=A[1],f=I,y=R[0],_=R[1],E=R[2],Y1,n),n.point(d,p)}function N(){w.point=L,n.lineEnd()}function S(){b(),w.point=C,w.lineEnd=T}function C(I,M){P(s=I,M),r=d,o=p,a=y,l=_,h=E,w.point=P}function T(){e(d,p,f,y,_,E,r,o,s,a,l,h,Y1,n),w.lineEnd=N,N()}return w}}var oR=Qm({point:function(i,t){this.stream.point(i*wi,t*wi)}});function aR(i){return Qm({point:function(t,e){var n=i(t,e);return this.stream.point(n[0],n[1])}})}function lR(i,t,e,n,s){function r(o,a){return o*=n,a*=s,[t+i*o,e-i*a]}return r.invert=function(o,a){return[(o-t)/i*n,(e-a)/i*s]},r}function j1(i,t,e,n,s,r){if(!r)return lR(i,t,e,n,s);var o=Xe(r),a=Fe(r),l=o*i,h=a*i,f=o/i,d=a/i,p=(a*e-o*t)/i,y=(a*t+o*e)/i;function _(E,w){return E*=n,w*=s,[l*E-h*w+t,e-h*E-l*w]}return _.invert=function(E,w){return[n*(f*E-d*w+p),s*(y-d*E-f*w)]},_}function uR(i){return cR(function(){return i})()}function cR(i){var t,e=150,n=480,s=250,r=0,o=0,a=0,l=0,h=0,f,d=0,p=1,y=1,_=null,E=q1,w=null,L,b,P,N=z1,S=.5,C,T,I,M,R;function A(D){return I(D[0]*wi,D[1]*wi)}function F(D){return D=I.invert(D[0],D[1]),D&&[D[0]*ir,D[1]*ir]}A.stream=function(D){return M&&R===D?M:M=oR(aR(f)(E(C(N(R=D)))))},A.preclip=function(D){return arguments.length?(E=D,_=void 0,z()):E},A.postclip=function(D){return arguments.length?(N=D,w=L=b=P=null,z()):N},A.clipAngle=function(D){return arguments.length?(E=+D?KT(_=D*wi):(_=null,q1),z()):_*ir},A.clipExtent=function(D){return arguments.length?(N=D==null?(w=L=b=P=null,z1):JT(w=+D[0][0],L=+D[0][1],b=+D[1][0],P=+D[1][1]),z()):w==null?null:[[w,L],[b,P]]},A.scale=function(D){return arguments.length?(e=+D,$()):e},A.translate=function(D){return arguments.length?(n=+D[0],s=+D[1],$()):[n,s]},A.center=function(D){return arguments.length?(r=D[0]%360*wi,o=D[1]%360*wi,$()):[r*ir,o*ir]},A.rotate=function(D){return arguments.length?(a=D[0]%360*wi,l=D[1]%360*wi,h=D.length>2?D[2]%360*wi:0,$()):[a*ir,l*ir,h*ir]},A.angle=function(D){return arguments.length?(d=D%360*wi,$()):d*ir},A.reflectX=function(D){return arguments.length?(p=D?-1:1,$()):p<0},A.reflectY=function(D){return arguments.length?(y=D?-1:1,$()):y<0},A.precision=function(D){return arguments.length?(C=X1(T,S=D*D),z()):pc(S)},A.fitExtent=function(D,B){return WE(A,D,B)},A.fitSize=function(D,B){return tR(A,D,B)},A.fitWidth=function(D,B){return eR(A,D,B)},A.fitHeight=function(D,B){return nR(A,D,B)};function $(){var D=j1(e,0,0,p,y,d).apply(null,t(r,o)),B=j1(e,n-D[0],s-D[1],p,y,d);return f=zT(a,l,h),T=Kg(t,B),I=Kg(f,T),C=X1(T,S),z()}function z(){return M=R=null,A}return function(){return t=i.apply(this,arguments),A.invert=t.invert&&F,$()}}function hR(i){return function(t,e){var n=Xe(t),s=Xe(e),r=i(n*s);return r===1/0?[2,0]:[r*s*Fe(t),r*Fe(e)]}}function fR(i){return function(t,e){var n=pc(t*t+e*e),s=i(n),r=Fe(s),o=Xe(s);return[Za(t*r,n*o),Ja(n&&e*r/n)]}}var KE=hR(function(i){return(i=XE(i))&&i/Fe(i)});KE.invert=fR(function(i){return i});function dR(){return uR(KE).scale(79.4188).clipAngle(180-.001)}var{BufferOp:gR,GeoJSONReader:mR,GeoJSONWriter:pR}=FT;function ZE(i,t,e){e=e||{};var n=e.units||"kilometers",s=e.steps||8;if(!i)throw new Error("geojson is required");if(typeof e!="object")throw new Error("options must be an object");if(typeof s!="number")throw new Error("steps must be an number");if(t===void 0)throw new Error("radius is required");if(s<=0)throw new Error("steps must be greater than 0");var r=[];switch(i.type){case"GeometryCollection":return Wr(i,function(o){var a=Sh(o,t,n,s);a&&r.push(a)}),ae(r);case"FeatureCollection":return qr(i,function(o){var a=Sh(o,t,n,s);a&&qr(a,function(l){l&&r.push(l)})}),ae(r)}return Sh(i,t,n,s)}function Sh(i,t,e,n){var s=i.properties||{},r=i.type==="Feature"?i.geometry:i;if(r.type==="GeometryCollection"){var o=[];return Wr(i,function(E){var w=Sh(E,t,e,n);w&&o.push(w)}),ae(o)}var a=yR(r),l={type:r.type,coordinates:QE(r.coordinates,a)},h=new mR,f=h.read(l),d=SE(ME(t,e),"meters"),p=gR.bufferOp(f,d,n),y=new pR;if(p=y.write(p),!JE(p.coordinates)){var _={type:p.type,coordinates:tw(p.coordinates,a)};return vn(_,s)}}function JE(i){return Array.isArray(i[0])?JE(i[0]):isNaN(i[0])}function QE(i,t){return typeof i[0]!="object"?t(i):i.map(function(e){return QE(e,t)})}function tw(i,t){return typeof i[0]!="object"?t.invert(i):i.map(function(e){return tw(e,t)})}function yR(i){var t=UE(i).geometry.coordinates,e=[-t[0],-t[1]];return dR().rotate(e).scale(Oe)}function Io(i,t={}){let e=0,n=0,s=0;return Mn(i,function(r){e+=r[0],n+=r[1],s++},!0),St([e/s,n/s],t.properties)}var eh={exports:{}},Mh={exports:{}},_R=Mh.exports,V1;function vR(){return V1||(V1=1,(function(i,t){(function(e,n){i.exports=n()})(_R,function(){function e(b,P,N,S,C){(function T(I,M,R,A,F){for(;A>R;){if(A-R>600){var $=A-R+1,z=M-R+1,D=Math.log($),B=.5*Math.exp(2*D/3),U=.5*Math.sqrt(D*B*($-B)/$)*(z-$/2<0?-1:1),j=Math.max(R,Math.floor(M-z*B/$+U)),K=Math.min(A,Math.floor(M+($-z)*B/$+U));T(I,M,j,K,F)}var W=I[M],J=R,lt=A;for(n(I,R,M),F(I[A],W)>0&&n(I,R,A);J<lt;){for(n(I,J,lt),J++,lt--;F(I[J],W)<0;)J++;for(;F(I[lt],W)>0;)lt--}F(I[R],W)===0?n(I,R,lt):n(I,++lt,A),lt<=M&&(R=lt+1),M<=lt&&(A=lt-1)}})(b,P,N||0,S||b.length-1,C||s)}function n(b,P,N){var S=b[P];b[P]=b[N],b[N]=S}function s(b,P){return b<P?-1:b>P?1:0}var r=function(b){b===void 0&&(b=9),this._maxEntries=Math.max(4,b),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()};function o(b,P,N){if(!N)return P.indexOf(b);for(var S=0;S<P.length;S++)if(N(b,P[S]))return S;return-1}function a(b,P){l(b,0,b.children.length,P,b)}function l(b,P,N,S,C){C||(C=w(null)),C.minX=1/0,C.minY=1/0,C.maxX=-1/0,C.maxY=-1/0;for(var T=P;T<N;T++){var I=b.children[T];h(C,b.leaf?S(I):I)}return C}function h(b,P){return b.minX=Math.min(b.minX,P.minX),b.minY=Math.min(b.minY,P.minY),b.maxX=Math.max(b.maxX,P.maxX),b.maxY=Math.max(b.maxY,P.maxY),b}function f(b,P){return b.minX-P.minX}function d(b,P){return b.minY-P.minY}function p(b){return(b.maxX-b.minX)*(b.maxY-b.minY)}function y(b){return b.maxX-b.minX+(b.maxY-b.minY)}function _(b,P){return b.minX<=P.minX&&b.minY<=P.minY&&P.maxX<=b.maxX&&P.maxY<=b.maxY}function E(b,P){return P.minX<=b.maxX&&P.minY<=b.maxY&&P.maxX>=b.minX&&P.maxY>=b.minY}function w(b){return{children:b,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function L(b,P,N,S,C){for(var T=[P,N];T.length;)if(!((N=T.pop())-(P=T.pop())<=S)){var I=P+Math.ceil((N-P)/S/2)*S;e(b,I,P,N,C),T.push(P,I,I,N)}}return r.prototype.all=function(){return this._all(this.data,[])},r.prototype.search=function(b){var P=this.data,N=[];if(!E(b,P))return N;for(var S=this.toBBox,C=[];P;){for(var T=0;T<P.children.length;T++){var I=P.children[T],M=P.leaf?S(I):I;E(b,M)&&(P.leaf?N.push(I):_(b,M)?this._all(I,N):C.push(I))}P=C.pop()}return N},r.prototype.collides=function(b){var P=this.data;if(!E(b,P))return!1;for(var N=[];P;){for(var S=0;S<P.children.length;S++){var C=P.children[S],T=P.leaf?this.toBBox(C):C;if(E(b,T)){if(P.leaf||_(b,T))return!0;N.push(C)}}P=N.pop()}return!1},r.prototype.load=function(b){if(!b||!b.length)return this;if(b.length<this._minEntries){for(var P=0;P<b.length;P++)this.insert(b[P]);return this}var N=this._build(b.slice(),0,b.length-1,0);if(this.data.children.length)if(this.data.height===N.height)this._splitRoot(this.data,N);else{if(this.data.height<N.height){var S=this.data;this.data=N,N=S}this._insert(N,this.data.height-N.height-1,!0)}else this.data=N;return this},r.prototype.insert=function(b){return b&&this._insert(b,this.data.height-1),this},r.prototype.clear=function(){return this.data=w([]),this},r.prototype.remove=function(b,P){if(!b)return this;for(var N,S,C,T=this.data,I=this.toBBox(b),M=[],R=[];T||M.length;){if(T||(T=M.pop(),S=M[M.length-1],N=R.pop(),C=!0),T.leaf){var A=o(b,T.children,P);if(A!==-1)return T.children.splice(A,1),M.push(T),this._condense(M),this}C||T.leaf||!_(T,I)?S?(N++,T=S.children[N],C=!1):T=null:(M.push(T),R.push(N),N=0,S=T,T=T.children[0])}return this},r.prototype.toBBox=function(b){return b},r.prototype.compareMinX=function(b,P){return b.minX-P.minX},r.prototype.compareMinY=function(b,P){return b.minY-P.minY},r.prototype.toJSON=function(){return this.data},r.prototype.fromJSON=function(b){return this.data=b,this},r.prototype._all=function(b,P){for(var N=[];b;)b.leaf?P.push.apply(P,b.children):N.push.apply(N,b.children),b=N.pop();return P},r.prototype._build=function(b,P,N,S){var C,T=N-P+1,I=this._maxEntries;if(T<=I)return a(C=w(b.slice(P,N+1)),this.toBBox),C;S||(S=Math.ceil(Math.log(T)/Math.log(I)),I=Math.ceil(T/Math.pow(I,S-1))),(C=w([])).leaf=!1,C.height=S;var M=Math.ceil(T/I),R=M*Math.ceil(Math.sqrt(I));L(b,P,N,R,this.compareMinX);for(var A=P;A<=N;A+=R){var F=Math.min(A+R-1,N);L(b,A,F,M,this.compareMinY);for(var $=A;$<=F;$+=M){var z=Math.min($+M-1,F);C.children.push(this._build(b,$,z,S-1))}}return a(C,this.toBBox),C},r.prototype._chooseSubtree=function(b,P,N,S){for(;S.push(P),!P.leaf&&S.length-1!==N;){for(var C=1/0,T=1/0,I=void 0,M=0;M<P.children.length;M++){var R=P.children[M],A=p(R),F=($=b,z=R,(Math.max(z.maxX,$.maxX)-Math.min(z.minX,$.minX))*(Math.max(z.maxY,$.maxY)-Math.min(z.minY,$.minY))-A);F<T?(T=F,C=A<C?A:C,I=R):F===T&&A<C&&(C=A,I=R)}P=I||P.children[0]}var $,z;return P},r.prototype._insert=function(b,P,N){var S=N?b:this.toBBox(b),C=[],T=this._chooseSubtree(S,this.data,P,C);for(T.children.push(b),h(T,S);P>=0&&C[P].children.length>this._maxEntries;)this._split(C,P),P--;this._adjustParentBBoxes(S,C,P)},r.prototype._split=function(b,P){var N=b[P],S=N.children.length,C=this._minEntries;this._chooseSplitAxis(N,C,S);var T=this._chooseSplitIndex(N,C,S),I=w(N.children.splice(T,N.children.length-T));I.height=N.height,I.leaf=N.leaf,a(N,this.toBBox),a(I,this.toBBox),P?b[P-1].children.push(I):this._splitRoot(N,I)},r.prototype._splitRoot=function(b,P){this.data=w([b,P]),this.data.height=b.height+1,this.data.leaf=!1,a(this.data,this.toBBox)},r.prototype._chooseSplitIndex=function(b,P,N){for(var S,C,T,I,M,R,A,F=1/0,$=1/0,z=P;z<=N-P;z++){var D=l(b,0,z,this.toBBox),B=l(b,z,N,this.toBBox),U=(C=D,T=B,I=void 0,M=void 0,R=void 0,A=void 0,I=Math.max(C.minX,T.minX),M=Math.max(C.minY,T.minY),R=Math.min(C.maxX,T.maxX),A=Math.min(C.maxY,T.maxY),Math.max(0,R-I)*Math.max(0,A-M)),j=p(D)+p(B);U<F?(F=U,S=z,$=j<$?j:$):U===F&&j<$&&($=j,S=z)}return S||N-P},r.prototype._chooseSplitAxis=function(b,P,N){var S=b.leaf?this.compareMinX:f,C=b.leaf?this.compareMinY:d;this._allDistMargin(b,P,N,S)<this._allDistMargin(b,P,N,C)&&b.children.sort(S)},r.prototype._allDistMargin=function(b,P,N,S){b.children.sort(S);for(var C=this.toBBox,T=l(b,0,P,C),I=l(b,N-P,N,C),M=y(T)+y(I),R=P;R<N-P;R++){var A=b.children[R];h(T,b.leaf?C(A):A),M+=y(T)}for(var F=N-P-1;F>=P;F--){var $=b.children[F];h(I,b.leaf?C($):$),M+=y(I)}return M},r.prototype._adjustParentBBoxes=function(b,P,N){for(var S=N;S>=0;S--)h(P[S],b)},r.prototype._condense=function(b){for(var P=b.length-1,N=void 0;P>=0;P--)b[P].children.length===0?P>0?(N=b[P-1].children).splice(N.indexOf(b[P]),1):this.clear():a(b[P],this.toBBox)},r})})(Mh)),Mh.exports}const ER=PT(Rk);var jl={exports:{}},sg,H1;function wR(){return H1||(H1=1,sg=function(t,e,n,s){var r=t[0],o=t[1],a=!1;n===void 0&&(n=0),s===void 0&&(s=e.length);for(var l=(s-n)/2,h=0,f=l-1;h<l;f=h++){var d=e[n+h*2+0],p=e[n+h*2+1],y=e[n+f*2+0],_=e[n+f*2+1],E=p>o!=_>o&&r<(y-d)*(o-p)/(_-p)+d;E&&(a=!a)}return a}),sg}var rg,W1;function xR(){return W1||(W1=1,rg=function(t,e,n,s){var r=t[0],o=t[1],a=!1;n===void 0&&(n=0),s===void 0&&(s=e.length);for(var l=s-n,h=0,f=l-1;h<l;f=h++){var d=e[h+n][0],p=e[h+n][1],y=e[f+n][0],_=e[f+n][1],E=p>o!=_>o&&r<(y-d)*(o-p)/(_-p)+d;E&&(a=!a)}return a}),rg}var K1;function bR(){if(K1)return jl.exports;K1=1;var i=wR(),t=xR();return jl.exports=function(n,s,r,o){return s.length>0&&Array.isArray(s[0])?t(n,s,r,o):i(n,s,r,o)},jl.exports.nested=t,jl.exports.flat=i,jl.exports}var hu={exports:{}},IR=hu.exports,Z1;function SR(){return Z1||(Z1=1,(function(i,t){(function(e,n){n(t)})(IR,function(e){const s=33306690738754706e-32;function r(E,w,L,b,P){let N,S,C,T,I=w[0],M=b[0],R=0,A=0;M>I==M>-I?(N=I,I=w[++R]):(N=M,M=b[++A]);let F=0;if(R<E&&A<L)for(M>I==M>-I?(C=N-((S=I+N)-I),I=w[++R]):(C=N-((S=M+N)-M),M=b[++A]),N=S,C!==0&&(P[F++]=C);R<E&&A<L;)M>I==M>-I?(C=N-((S=N+I)-(T=S-N))+(I-T),I=w[++R]):(C=N-((S=N+M)-(T=S-N))+(M-T),M=b[++A]),N=S,C!==0&&(P[F++]=C);for(;R<E;)C=N-((S=N+I)-(T=S-N))+(I-T),I=w[++R],N=S,C!==0&&(P[F++]=C);for(;A<L;)C=N-((S=N+M)-(T=S-N))+(M-T),M=b[++A],N=S,C!==0&&(P[F++]=C);return N===0&&F!==0||(P[F++]=N),F}function o(E){return new Float64Array(E)}const a=33306690738754716e-32,l=22204460492503146e-32,h=11093356479670487e-47,f=o(4),d=o(8),p=o(12),y=o(16),_=o(4);e.orient2d=function(E,w,L,b,P,N){const S=(w-N)*(L-P),C=(E-P)*(b-N),T=S-C;if(S===0||C===0||S>0!=C>0)return T;const I=Math.abs(S+C);return Math.abs(T)>=a*I?T:-(function(M,R,A,F,$,z,D){let B,U,j,K,W,J,lt,ft,ct,gt,bt,It,Q,jt,Dt,wt,V,Xt;const Ut=M-$,Gt=A-$,dn=R-z,wn=F-z;W=(Dt=(ft=Ut-(lt=(J=134217729*Ut)-(J-Ut)))*(gt=wn-(ct=(J=134217729*wn)-(J-wn)))-((jt=Ut*wn)-lt*ct-ft*ct-lt*gt))-(bt=Dt-(V=(ft=dn-(lt=(J=134217729*dn)-(J-dn)))*(gt=Gt-(ct=(J=134217729*Gt)-(J-Gt)))-((wt=dn*Gt)-lt*ct-ft*ct-lt*gt))),f[0]=Dt-(bt+W)+(W-V),W=(Q=jt-((It=jt+bt)-(W=It-jt))+(bt-W))-(bt=Q-wt),f[1]=Q-(bt+W)+(W-wt),W=(Xt=It+bt)-It,f[2]=It-(Xt-W)+(bt-W),f[3]=Xt;let Ln=(function(it,H){let nt=H[0];for(let ot=1;ot<it;ot++)nt+=H[ot];return nt})(4,f),Et=l*D;if(Ln>=Et||-Ln>=Et||(B=M-(Ut+(W=M-Ut))+(W-$),j=A-(Gt+(W=A-Gt))+(W-$),U=R-(dn+(W=R-dn))+(W-z),K=F-(wn+(W=F-wn))+(W-z),B===0&&U===0&&j===0&&K===0)||(Et=h*D+s*Math.abs(Ln),(Ln+=Ut*K+wn*B-(dn*j+Gt*U))>=Et||-Ln>=Et))return Ln;W=(Dt=(ft=B-(lt=(J=134217729*B)-(J-B)))*(gt=wn-(ct=(J=134217729*wn)-(J-wn)))-((jt=B*wn)-lt*ct-ft*ct-lt*gt))-(bt=Dt-(V=(ft=U-(lt=(J=134217729*U)-(J-U)))*(gt=Gt-(ct=(J=134217729*Gt)-(J-Gt)))-((wt=U*Gt)-lt*ct-ft*ct-lt*gt))),_[0]=Dt-(bt+W)+(W-V),W=(Q=jt-((It=jt+bt)-(W=It-jt))+(bt-W))-(bt=Q-wt),_[1]=Q-(bt+W)+(W-wt),W=(Xt=It+bt)-It,_[2]=It-(Xt-W)+(bt-W),_[3]=Xt;const Cl=r(4,f,4,_,d);W=(Dt=(ft=Ut-(lt=(J=134217729*Ut)-(J-Ut)))*(gt=K-(ct=(J=134217729*K)-(J-K)))-((jt=Ut*K)-lt*ct-ft*ct-lt*gt))-(bt=Dt-(V=(ft=dn-(lt=(J=134217729*dn)-(J-dn)))*(gt=j-(ct=(J=134217729*j)-(J-j)))-((wt=dn*j)-lt*ct-ft*ct-lt*gt))),_[0]=Dt-(bt+W)+(W-V),W=(Q=jt-((It=jt+bt)-(W=It-jt))+(bt-W))-(bt=Q-wt),_[1]=Q-(bt+W)+(W-wt),W=(Xt=It+bt)-It,_[2]=It-(Xt-W)+(bt-W),_[3]=Xt;const tt=r(Cl,d,4,_,p);W=(Dt=(ft=B-(lt=(J=134217729*B)-(J-B)))*(gt=K-(ct=(J=134217729*K)-(J-K)))-((jt=B*K)-lt*ct-ft*ct-lt*gt))-(bt=Dt-(V=(ft=U-(lt=(J=134217729*U)-(J-U)))*(gt=j-(ct=(J=134217729*j)-(J-j)))-((wt=U*j)-lt*ct-ft*ct-lt*gt))),_[0]=Dt-(bt+W)+(W-V),W=(Q=jt-((It=jt+bt)-(W=It-jt))+(bt-W))-(bt=Q-wt),_[1]=Q-(bt+W)+(W-wt),W=(Xt=It+bt)-It,_[2]=It-(Xt-W)+(bt-W),_[3]=Xt;const et=r(tt,p,4,_,y);return y[et-1]})(E,w,L,b,P,N,I)},e.orient2dfast=function(E,w,L,b,P,N){return(w-N)*(L-P)-(E-P)*(b-N)},Object.defineProperty(e,"__esModule",{value:!0})})})(hu,hu.exports)),hu.exports}var J1;function MR(){if(J1)return eh.exports;J1=1;var i=vR(),t=ER,e=bR(),n=SR().orient2d;t.default&&(t=t.default),eh.exports=s,eh.exports.default=s;function s(N,S,C){S=Math.max(0,S===void 0?2:S),C=C||0;var T=y(N),I=new i(16);I.toBBox=function(lt){return{minX:lt[0],minY:lt[1],maxX:lt[0],maxY:lt[1]}},I.compareMinX=function(lt,ft){return lt[0]-ft[0]},I.compareMinY=function(lt,ft){return lt[1]-ft[1]},I.load(N);for(var M=[],R=0,A;R<T.length;R++){var F=T[R];I.remove(F),A=_(F,A),M.push(A)}var $=new i(16);for(R=0;R<M.length;R++)$.insert(p(M[R]));for(var z=S*S,D=C*C;M.length;){var B=M.shift(),U=B.p,j=B.next.p,K=E(U,j);if(!(K<D)){var W=K/z;F=r(I,B.prev.p,U,j,B.next.next.p,W,$),F&&Math.min(E(F,U),E(F,j))<=W&&(M.push(B),M.push(_(F,B)),I.remove(F),$.remove(B),$.insert(p(B)),$.insert(p(B.next)))}}B=A;var J=[];do J.push(B.p),B=B.next;while(B!==A);return J.push(B.p),J}function r(N,S,C,T,I,M,R){for(var A=new t([],o),F=N.data;F;){for(var $=0;$<F.children.length;$++){var z=F.children[$],D=F.leaf?w(z,C,T):a(C,T,z);D>M||A.push({node:z,dist:D})}for(;A.length&&!A.peek().node.children;){var B=A.pop(),U=B.node,j=w(U,S,C),K=w(U,T,I);if(B.dist<j&&B.dist<K&&h(C,U,R)&&h(T,U,R))return U}F=A.pop(),F&&(F=F.node)}return null}function o(N,S){return N.dist-S.dist}function a(N,S,C){if(l(N,C)||l(S,C))return 0;var T=L(N[0],N[1],S[0],S[1],C.minX,C.minY,C.maxX,C.minY);if(T===0)return 0;var I=L(N[0],N[1],S[0],S[1],C.minX,C.minY,C.minX,C.maxY);if(I===0)return 0;var M=L(N[0],N[1],S[0],S[1],C.maxX,C.minY,C.maxX,C.maxY);if(M===0)return 0;var R=L(N[0],N[1],S[0],S[1],C.minX,C.maxY,C.maxX,C.maxY);return R===0?0:Math.min(T,I,M,R)}function l(N,S){return N[0]>=S.minX&&N[0]<=S.maxX&&N[1]>=S.minY&&N[1]<=S.maxY}function h(N,S,C){for(var T=Math.min(N[0],S[0]),I=Math.min(N[1],S[1]),M=Math.max(N[0],S[0]),R=Math.max(N[1],S[1]),A=C.search({minX:T,minY:I,maxX:M,maxY:R}),F=0;F<A.length;F++)if(d(A[F].p,A[F].next.p,N,S))return!1;return!0}function f(N,S,C){return n(N[0],N[1],S[0],S[1],C[0],C[1])}function d(N,S,C,T){return N!==T&&S!==C&&f(N,S,C)>0!=f(N,S,T)>0&&f(C,T,N)>0!=f(C,T,S)>0}function p(N){var S=N.p,C=N.next.p;return N.minX=Math.min(S[0],C[0]),N.minY=Math.min(S[1],C[1]),N.maxX=Math.max(S[0],C[0]),N.maxY=Math.max(S[1],C[1]),N}function y(N){for(var S=N[0],C=N[0],T=N[0],I=N[0],M=0;M<N.length;M++){var R=N[M];R[0]<S[0]&&(S=R),R[0]>T[0]&&(T=R),R[1]<C[1]&&(C=R),R[1]>I[1]&&(I=R)}var A=[S,C,T,I],F=A.slice();for(M=0;M<N.length;M++)e(N[M],A)||F.push(N[M]);return P(F)}function _(N,S){var C={p:N,prev:null,next:null,minX:0,minY:0,maxX:0,maxY:0};return S?(C.next=S.next,C.prev=S,S.next.prev=C,S.next=C):(C.prev=C,C.next=C),C}function E(N,S){var C=N[0]-S[0],T=N[1]-S[1];return C*C+T*T}function w(N,S,C){var T=S[0],I=S[1],M=C[0]-T,R=C[1]-I;if(M!==0||R!==0){var A=((N[0]-T)*M+(N[1]-I)*R)/(M*M+R*R);A>1?(T=C[0],I=C[1]):A>0&&(T+=M*A,I+=R*A)}return M=N[0]-T,R=N[1]-I,M*M+R*R}function L(N,S,C,T,I,M,R,A){var F=C-N,$=T-S,z=R-I,D=A-M,B=N-I,U=S-M,j=F*F+$*$,K=F*z+$*D,W=z*z+D*D,J=F*B+$*U,lt=z*B+D*U,ft=j*W-K*K,ct,gt,bt,It,Q=ft,jt=ft;ft===0?(gt=0,Q=1,It=lt,jt=W):(gt=K*lt-W*J,It=j*lt-K*J,gt<0?(gt=0,It=lt,jt=W):gt>Q&&(gt=Q,It=lt+K,jt=W)),It<0?(It=0,-J<0?gt=0:-J>j?gt=Q:(gt=-J,Q=j)):It>jt&&(It=jt,-J+K<0?gt=0:-J+K>j?gt=Q:(gt=-J+K,Q=j)),ct=gt===0?0:gt/Q,bt=It===0?0:It/jt;var Dt=(1-ct)*N+ct*C,wt=(1-ct)*S+ct*T,V=(1-bt)*I+bt*R,Xt=(1-bt)*M+bt*A,Ut=V-Dt,Gt=Xt-wt;return Ut*Ut+Gt*Gt}function b(N,S){return N[0]===S[0]?N[1]-S[1]:N[0]-S[0]}function P(N){N.sort(b);for(var S=[],C=0;C<N.length;C++){for(;S.length>=2&&f(S[S.length-2],S[S.length-1],N[C])<=0;)S.pop();S.push(N[C])}for(var T=[],I=N.length-1;I>=0;I--){for(;T.length>=2&&f(T[T.length-2],T[T.length-1],N[I])<=0;)T.pop();T.push(N[I])}return T.pop(),S.pop(),S.concat(T)}return eh.exports}var NR=MR();const LR=zE(NR);function CR(i,t={}){t.concavity=t.concavity||1/0;const e=[];if(Mn(i,s=>{e.push([s[0],s[1]])}),!e.length)return null;const n=LR(e,t.concavity);return n.length>3?Ce([n],t.properties):null}function ew(i,t={}){switch(Kh(i)){case"Point":return St(li(i),t.properties);case"Polygon":var e=[];Mn(i,function(N){e.push(N)});var n=Io(i,{properties:t.properties}),s=n.geometry.coordinates,r=0,o=0,a=0,l,h,f,d,p,y,_,E,w=e.map(function(N){return[N[0]-s[0],N[1]-s[1]]});for(l=0;l<e.length-1;l++)h=w[l],d=h[0],y=h[1],f=w[l+1],p=f[0],_=f[1],E=d*_-p*y,a+=E,r+=(d+p)*E,o+=(y+_)*E;if(a===0)return n;var L=a*.5,b=1/(6*L);return St([s[0]+b*r,s[1]+b*o],t.properties);default:var P=CR(i);return P?ew(P,{properties:t.properties}):Io(i,{properties:t.properties})}}function Q1(i,t,e={}){const n=e.steps||64,s=e.properties?e.properties:!Array.isArray(i)&&i.type==="Feature"&&i.properties?i.properties:{},r=[];for(let o=0;o<n;o++)r.push(ku(i,t,o*-360/n,e).geometry.coordinates);return r.push(r[0]),Ce([r],s)}function Ye(i){if(!i)throw new Error("geojson is required");switch(i.type){case"Feature":return nw(i);case"FeatureCollection":return PR(i);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return ep(i);default:throw new Error("unknown GeoJSON type")}}function nw(i){const t={type:"Feature"};return Object.keys(i).forEach(e=>{switch(e){case"type":case"properties":case"geometry":return;default:t[e]=i[e]}}),t.properties=iw(i.properties),i.geometry==null?t.geometry=null:t.geometry=ep(i.geometry),t}function iw(i){const t={};return i&&Object.keys(i).forEach(e=>{const n=i[e];typeof n=="object"?n===null?t[e]=null:Array.isArray(n)?t[e]=n.map(s=>s):t[e]=iw(n):t[e]=n}),t}function PR(i){const t={type:"FeatureCollection"};return Object.keys(i).forEach(e=>{switch(e){case"type":case"features":return;default:t[e]=i[e]}}),t.features=i.features.map(e=>nw(e)),t}function ep(i){const t={type:i.type};return i.bbox&&(t.bbox=i.bbox),i.type==="GeometryCollection"?(t.geometries=i.geometries.map(e=>ep(e)),t):(t.coordinates=sw(i.coordinates),t)}function sw(i){const t=i;return typeof t[0]!="object"?t.slice():t.map(e=>sw(e))}var kR=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,og=Math.ceil,Gi=Math.floor,ti="[BigNumber Error] ",t_=ti+"Number primitive has more than 15 significant digits: ",as=1e14,Wt=14,ag=9007199254740991,lg=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],Ir=1e7,pn=1e9;function rw(i){var t,e,n,s=b.prototype={constructor:b,toString:null,valueOf:null},r=new b(1),o=20,a=4,l=-7,h=21,f=-1e7,d=1e7,p=!1,y=1,_=0,E={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},w="0123456789abcdefghijklmnopqrstuvwxyz",L=!0;function b(I,M){var R,A,F,$,z,D,B,U,j=this;if(!(j instanceof b))return new b(I,M);if(M==null){if(I&&I._isBigNumber===!0){j.s=I.s,!I.c||I.e>d?j.c=j.e=null:I.e<f?j.c=[j.e=0]:(j.e=I.e,j.c=I.c.slice());return}if((D=typeof I=="number")&&I*0==0){if(j.s=1/I<0?(I=-I,-1):1,I===~~I){for($=0,z=I;z>=10;z/=10,$++);$>d?j.c=j.e=null:(j.e=$,j.c=[I]);return}U=String(I)}else{if(!kR.test(U=String(I)))return n(j,U,D);j.s=U.charCodeAt(0)==45?(U=U.slice(1),-1):1}($=U.indexOf("."))>-1&&(U=U.replace(".","")),(z=U.search(/e/i))>0?($<0&&($=z),$+=+U.slice(z+1),U=U.substring(0,z)):$<0&&($=U.length)}else{if(je(M,2,w.length,"Base"),M==10&&L)return j=new b(I),C(j,o+j.e+1,a);if(U=String(I),D=typeof I=="number"){if(I*0!=0)return n(j,U,D,M);if(j.s=1/I<0?(U=U.slice(1),-1):1,b.DEBUG&&U.replace(/^0\.0*|\./,"").length>15)throw Error(t_+I)}else j.s=U.charCodeAt(0)===45?(U=U.slice(1),-1):1;for(R=w.slice(0,M),$=z=0,B=U.length;z<B;z++)if(R.indexOf(A=U.charAt(z))<0){if(A=="."){if(z>$){$=B;continue}}else if(!F&&(U==U.toUpperCase()&&(U=U.toLowerCase())||U==U.toLowerCase()&&(U=U.toUpperCase()))){F=!0,z=-1,$=0;continue}return n(j,String(I),D,M)}D=!1,U=e(U,M,10,j.s),($=U.indexOf("."))>-1?U=U.replace(".",""):$=U.length}for(z=0;U.charCodeAt(z)===48;z++);for(B=U.length;U.charCodeAt(--B)===48;);if(U=U.slice(z,++B)){if(B-=z,D&&b.DEBUG&&B>15&&(I>ag||I!==Gi(I)))throw Error(t_+j.s*I);if(($=$-z-1)>d)j.c=j.e=null;else if($<f)j.c=[j.e=0];else{if(j.e=$,j.c=[],z=($+1)%Wt,$<0&&(z+=Wt),z<B){for(z&&j.c.push(+U.slice(0,z)),B-=Wt;z<B;)j.c.push(+U.slice(z,z+=Wt));z=Wt-(U=U.slice(z)).length}else z-=B;for(;z--;U+="0");j.c.push(+U)}}else j.c=[j.e=0]}b.clone=rw,b.ROUND_UP=0,b.ROUND_DOWN=1,b.ROUND_CEIL=2,b.ROUND_FLOOR=3,b.ROUND_HALF_UP=4,b.ROUND_HALF_DOWN=5,b.ROUND_HALF_EVEN=6,b.ROUND_HALF_CEIL=7,b.ROUND_HALF_FLOOR=8,b.EUCLID=9,b.config=b.set=function(I){var M,R;if(I!=null)if(typeof I=="object"){if(I.hasOwnProperty(M="DECIMAL_PLACES")&&(R=I[M],je(R,0,pn,M),o=R),I.hasOwnProperty(M="ROUNDING_MODE")&&(R=I[M],je(R,0,8,M),a=R),I.hasOwnProperty(M="EXPONENTIAL_AT")&&(R=I[M],R&&R.pop?(je(R[0],-pn,0,M),je(R[1],0,pn,M),l=R[0],h=R[1]):(je(R,-pn,pn,M),l=-(h=R<0?-R:R))),I.hasOwnProperty(M="RANGE"))if(R=I[M],R&&R.pop)je(R[0],-pn,-1,M),je(R[1],1,pn,M),f=R[0],d=R[1];else if(je(R,-pn,pn,M),R)f=-(d=R<0?-R:R);else throw Error(ti+M+" cannot be zero: "+R);if(I.hasOwnProperty(M="CRYPTO"))if(R=I[M],R===!!R)if(R)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))p=R;else throw p=!R,Error(ti+"crypto unavailable");else p=R;else throw Error(ti+M+" not true or false: "+R);if(I.hasOwnProperty(M="MODULO_MODE")&&(R=I[M],je(R,0,9,M),y=R),I.hasOwnProperty(M="POW_PRECISION")&&(R=I[M],je(R,0,pn,M),_=R),I.hasOwnProperty(M="FORMAT"))if(R=I[M],typeof R=="object")E=R;else throw Error(ti+M+" not an object: "+R);if(I.hasOwnProperty(M="ALPHABET"))if(R=I[M],typeof R=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(R))L=R.slice(0,10)=="0123456789",w=R;else throw Error(ti+M+" invalid: "+R)}else throw Error(ti+"Object expected: "+I);return{DECIMAL_PLACES:o,ROUNDING_MODE:a,EXPONENTIAL_AT:[l,h],RANGE:[f,d],CRYPTO:p,MODULO_MODE:y,POW_PRECISION:_,FORMAT:E,ALPHABET:w}},b.isBigNumber=function(I){if(!I||I._isBigNumber!==!0)return!1;if(!b.DEBUG)return!0;var M,R,A=I.c,F=I.e,$=I.s;t:if({}.toString.call(A)=="[object Array]"){if(($===1||$===-1)&&F>=-pn&&F<=pn&&F===Gi(F)){if(A[0]===0){if(F===0&&A.length===1)return!0;break t}if(M=(F+1)%Wt,M<1&&(M+=Wt),String(A[0]).length==M){for(M=0;M<A.length;M++)if(R=A[M],R<0||R>=as||R!==Gi(R))break t;if(R!==0)return!0}}}else if(A===null&&F===null&&($===null||$===1||$===-1))return!0;throw Error(ti+"Invalid BigNumber: "+I)},b.maximum=b.max=function(){return N(arguments,-1)},b.minimum=b.min=function(){return N(arguments,1)},b.random=(function(){var I=9007199254740992,M=Math.random()*I&2097151?function(){return Gi(Math.random()*I)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(R){var A,F,$,z,D,B=0,U=[],j=new b(r);if(R==null?R=o:je(R,0,pn),z=og(R/Wt),p)if(crypto.getRandomValues){for(A=crypto.getRandomValues(new Uint32Array(z*=2));B<z;)D=A[B]*131072+(A[B+1]>>>11),D>=9e15?(F=crypto.getRandomValues(new Uint32Array(2)),A[B]=F[0],A[B+1]=F[1]):(U.push(D%1e14),B+=2);B=z/2}else if(crypto.randomBytes){for(A=crypto.randomBytes(z*=7);B<z;)D=(A[B]&31)*281474976710656+A[B+1]*1099511627776+A[B+2]*4294967296+A[B+3]*16777216+(A[B+4]<<16)+(A[B+5]<<8)+A[B+6],D>=9e15?crypto.randomBytes(7).copy(A,B):(U.push(D%1e14),B+=7);B=z/7}else throw p=!1,Error(ti+"crypto unavailable");if(!p)for(;B<z;)D=M(),D<9e15&&(U[B++]=D%1e14);for(z=U[--B],R%=Wt,z&&R&&(D=lg[Wt-R],U[B]=Gi(z/D)*D);U[B]===0;U.pop(),B--);if(B<0)U=[$=0];else{for($=-1;U[0]===0;U.splice(0,1),$-=Wt);for(B=1,D=U[0];D>=10;D/=10,B++);B<Wt&&($-=Wt-B)}return j.e=$,j.c=U,j}})(),b.sum=function(){for(var I=1,M=arguments,R=new b(M[0]);I<M.length;)R=R.plus(M[I++]);return R},e=(function(){var I="0123456789";function M(R,A,F,$){for(var z,D=[0],B,U=0,j=R.length;U<j;){for(B=D.length;B--;D[B]*=A);for(D[0]+=$.indexOf(R.charAt(U++)),z=0;z<D.length;z++)D[z]>F-1&&(D[z+1]==null&&(D[z+1]=0),D[z+1]+=D[z]/F|0,D[z]%=F)}return D.reverse()}return function(R,A,F,$,z){var D,B,U,j,K,W,J,lt,ft=R.indexOf("."),ct=o,gt=a;for(ft>=0&&(j=_,_=0,R=R.replace(".",""),lt=new b(A),W=lt.pow(R.length-ft),_=j,lt.c=M(sr($i(W.c),W.e,"0"),10,F,I),lt.e=lt.c.length),J=M(R,A,F,z?(D=w,I):(D=I,w)),U=j=J.length;J[--j]==0;J.pop());if(!J[0])return D.charAt(0);if(ft<0?--U:(W.c=J,W.e=U,W.s=$,W=t(W,lt,ct,gt,F),J=W.c,K=W.r,U=W.e),B=U+ct+1,ft=J[B],j=F/2,K=K||B<0||J[B+1]!=null,K=gt<4?(ft!=null||K)&&(gt==0||gt==(W.s<0?3:2)):ft>j||ft==j&&(gt==4||K||gt==6&&J[B-1]&1||gt==(W.s<0?8:7)),B<1||!J[0])R=K?sr(D.charAt(1),-ct,D.charAt(0)):D.charAt(0);else{if(J.length=B,K)for(--F;++J[--B]>F;)J[B]=0,B||(++U,J=[1].concat(J));for(j=J.length;!J[--j];);for(ft=0,R="";ft<=j;R+=D.charAt(J[ft++]));R=sr(R,U,D.charAt(0))}return R}})(),t=(function(){function I(A,F,$){var z,D,B,U,j=0,K=A.length,W=F%Ir,J=F/Ir|0;for(A=A.slice();K--;)B=A[K]%Ir,U=A[K]/Ir|0,z=J*B+U*W,D=W*B+z%Ir*Ir+j,j=(D/$|0)+(z/Ir|0)+J*U,A[K]=D%$;return j&&(A=[j].concat(A)),A}function M(A,F,$,z){var D,B;if($!=z)B=$>z?1:-1;else for(D=B=0;D<$;D++)if(A[D]!=F[D]){B=A[D]>F[D]?1:-1;break}return B}function R(A,F,$,z){for(var D=0;$--;)A[$]-=D,D=A[$]<F[$]?1:0,A[$]=D*z+A[$]-F[$];for(;!A[0]&&A.length>1;A.splice(0,1));}return function(A,F,$,z,D){var B,U,j,K,W,J,lt,ft,ct,gt,bt,It,Q,jt,Dt,wt,V,Xt=A.s==F.s?1:-1,Ut=A.c,Gt=F.c;if(!Ut||!Ut[0]||!Gt||!Gt[0])return new b(!A.s||!F.s||(Ut?Gt&&Ut[0]==Gt[0]:!Gt)?NaN:Ut&&Ut[0]==0||!Gt?Xt*0:Xt/0);for(ft=new b(Xt),ct=ft.c=[],U=A.e-F.e,Xt=$+U+1,D||(D=as,U=Bi(A.e/Wt)-Bi(F.e/Wt),Xt=Xt/Wt|0),j=0;Gt[j]==(Ut[j]||0);j++);if(Gt[j]>(Ut[j]||0)&&U--,Xt<0)ct.push(1),K=!0;else{for(jt=Ut.length,wt=Gt.length,j=0,Xt+=2,W=Gi(D/(Gt[0]+1)),W>1&&(Gt=I(Gt,W,D),Ut=I(Ut,W,D),wt=Gt.length,jt=Ut.length),Q=wt,gt=Ut.slice(0,wt),bt=gt.length;bt<wt;gt[bt++]=0);V=Gt.slice(),V=[0].concat(V),Dt=Gt[0],Gt[1]>=D/2&&Dt++;do{if(W=0,B=M(Gt,gt,wt,bt),B<0){if(It=gt[0],wt!=bt&&(It=It*D+(gt[1]||0)),W=Gi(It/Dt),W>1)for(W>=D&&(W=D-1),J=I(Gt,W,D),lt=J.length,bt=gt.length;M(J,gt,lt,bt)==1;)W--,R(J,wt<lt?V:Gt,lt,D),lt=J.length,B=1;else W==0&&(B=W=1),J=Gt.slice(),lt=J.length;if(lt<bt&&(J=[0].concat(J)),R(gt,J,bt,D),bt=gt.length,B==-1)for(;M(Gt,gt,wt,bt)<1;)W++,R(gt,wt<bt?V:Gt,bt,D),bt=gt.length}else B===0&&(W++,gt=[0]);ct[j++]=W,gt[0]?gt[bt++]=Ut[Q]||0:(gt=[Ut[Q]],bt=1)}while((Q++<jt||gt[0]!=null)&&Xt--);K=gt[0]!=null,ct[0]||ct.splice(0,1)}if(D==as){for(j=1,Xt=ct[0];Xt>=10;Xt/=10,j++);C(ft,$+(ft.e=j+U*Wt-1)+1,z,K)}else ft.e=U,ft.r=+K;return ft}})();function P(I,M,R,A){var F,$,z,D,B;if(R==null?R=a:je(R,0,8),!I.c)return I.toString();if(F=I.c[0],z=I.e,M==null)B=$i(I.c),B=A==1||A==2&&(z<=l||z>=h)?ih(B,z):sr(B,z,"0");else if(I=C(new b(I),M,R),$=I.e,B=$i(I.c),D=B.length,A==1||A==2&&(M<=$||$<=l)){for(;D<M;B+="0",D++);B=ih(B,$)}else if(M-=z+(A===2&&$>z),B=sr(B,$,"0"),$+1>D){if(--M>0)for(B+=".";M--;B+="0");}else if(M+=$-D,M>0)for($+1==D&&(B+=".");M--;B+="0");return I.s<0&&F?"-"+B:B}function N(I,M){for(var R,A,F=1,$=new b(I[0]);F<I.length;F++)A=new b(I[F]),(!A.s||(R=co($,A))===M||R===0&&$.s===M)&&($=A);return $}function S(I,M,R){for(var A=1,F=M.length;!M[--F];M.pop());for(F=M[0];F>=10;F/=10,A++);return(R=A+R*Wt-1)>d?I.c=I.e=null:R<f?I.c=[I.e=0]:(I.e=R,I.c=M),I}n=(function(){var I=/^(-?)0([xbo])(?=\w[\w.]*$)/i,M=/^([^.]+)\.$/,R=/^\.([^.]+)$/,A=/^-?(Infinity|NaN)$/,F=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function($,z,D,B){var U,j=D?z:z.replace(F,"");if(A.test(j))$.s=isNaN(j)?null:j<0?-1:1;else{if(!D&&(j=j.replace(I,function(K,W,J){return U=(J=J.toLowerCase())=="x"?16:J=="b"?2:8,!B||B==U?W:K}),B&&(U=B,j=j.replace(M,"$1").replace(R,"0.$1")),z!=j))return new b(j,U);if(b.DEBUG)throw Error(ti+"Not a"+(B?" base "+B:"")+" number: "+z);$.s=null}$.c=$.e=null}})();function C(I,M,R,A){var F,$,z,D,B,U,j,K=I.c,W=lg;if(K){t:{for(F=1,D=K[0];D>=10;D/=10,F++);if($=M-F,$<0)$+=Wt,z=M,B=K[U=0],j=Gi(B/W[F-z-1]%10);else if(U=og(($+1)/Wt),U>=K.length)if(A){for(;K.length<=U;K.push(0));B=j=0,F=1,$%=Wt,z=$-Wt+1}else break t;else{for(B=D=K[U],F=1;D>=10;D/=10,F++);$%=Wt,z=$-Wt+F,j=z<0?0:Gi(B/W[F-z-1]%10)}if(A=A||M<0||K[U+1]!=null||(z<0?B:B%W[F-z-1]),A=R<4?(j||A)&&(R==0||R==(I.s<0?3:2)):j>5||j==5&&(R==4||A||R==6&&($>0?z>0?B/W[F-z]:0:K[U-1])%10&1||R==(I.s<0?8:7)),M<1||!K[0])return K.length=0,A?(M-=I.e+1,K[0]=W[(Wt-M%Wt)%Wt],I.e=-M||0):K[0]=I.e=0,I;if($==0?(K.length=U,D=1,U--):(K.length=U+1,D=W[Wt-$],K[U]=z>0?Gi(B/W[F-z]%W[z])*D:0),A)for(;;)if(U==0){for($=1,z=K[0];z>=10;z/=10,$++);for(z=K[0]+=D,D=1;z>=10;z/=10,D++);$!=D&&(I.e++,K[0]==as&&(K[0]=1));break}else{if(K[U]+=D,K[U]!=as)break;K[U--]=0,D=1}for($=K.length;K[--$]===0;K.pop());}I.e>d?I.c=I.e=null:I.e<f&&(I.c=[I.e=0])}return I}function T(I){var M,R=I.e;return R===null?I.toString():(M=$i(I.c),M=R<=l||R>=h?ih(M,R):sr(M,R,"0"),I.s<0?"-"+M:M)}return s.absoluteValue=s.abs=function(){var I=new b(this);return I.s<0&&(I.s=1),I},s.comparedTo=function(I,M){return co(this,new b(I,M))},s.decimalPlaces=s.dp=function(I,M){var R,A,F,$=this;if(I!=null)return je(I,0,pn),M==null?M=a:je(M,0,8),C(new b($),I+$.e+1,M);if(!(R=$.c))return null;if(A=((F=R.length-1)-Bi(this.e/Wt))*Wt,F=R[F])for(;F%10==0;F/=10,A--);return A<0&&(A=0),A},s.dividedBy=s.div=function(I,M){return t(this,new b(I,M),o,a)},s.dividedToIntegerBy=s.idiv=function(I,M){return t(this,new b(I,M),0,1)},s.exponentiatedBy=s.pow=function(I,M){var R,A,F,$,z,D,B,U,j,K=this;if(I=new b(I),I.c&&!I.isInteger())throw Error(ti+"Exponent not an integer: "+T(I));if(M!=null&&(M=new b(M)),D=I.e>14,!K.c||!K.c[0]||K.c[0]==1&&!K.e&&K.c.length==1||!I.c||!I.c[0])return j=new b(Math.pow(+T(K),D?I.s*(2-nh(I)):+T(I))),M?j.mod(M):j;if(B=I.s<0,M){if(M.c?!M.c[0]:!M.s)return new b(NaN);A=!B&&K.isInteger()&&M.isInteger(),A&&(K=K.mod(M))}else{if(I.e>9&&(K.e>0||K.e<-1||(K.e==0?K.c[0]>1||D&&K.c[1]>=24e7:K.c[0]<8e13||D&&K.c[0]<=9999975e7)))return $=K.s<0&&nh(I)?-0:0,K.e>-1&&($=1/$),new b(B?1/$:$);_&&($=og(_/Wt+2))}for(D?(R=new b(.5),B&&(I.s=1),U=nh(I)):(F=Math.abs(+T(I)),U=F%2),j=new b(r);;){if(U){if(j=j.times(K),!j.c)break;$?j.c.length>$&&(j.c.length=$):A&&(j=j.mod(M))}if(F){if(F=Gi(F/2),F===0)break;U=F%2}else if(I=I.times(R),C(I,I.e+1,1),I.e>14)U=nh(I);else{if(F=+T(I),F===0)break;U=F%2}K=K.times(K),$?K.c&&K.c.length>$&&(K.c.length=$):A&&(K=K.mod(M))}return A?j:(B&&(j=r.div(j)),M?j.mod(M):$?C(j,_,a,z):j)},s.integerValue=function(I){var M=new b(this);return I==null?I=a:je(I,0,8),C(M,M.e+1,I)},s.isEqualTo=s.eq=function(I,M){return co(this,new b(I,M))===0},s.isFinite=function(){return!!this.c},s.isGreaterThan=s.gt=function(I,M){return co(this,new b(I,M))>0},s.isGreaterThanOrEqualTo=s.gte=function(I,M){return(M=co(this,new b(I,M)))===1||M===0},s.isInteger=function(){return!!this.c&&Bi(this.e/Wt)>this.c.length-2},s.isLessThan=s.lt=function(I,M){return co(this,new b(I,M))<0},s.isLessThanOrEqualTo=s.lte=function(I,M){return(M=co(this,new b(I,M)))===-1||M===0},s.isNaN=function(){return!this.s},s.isNegative=function(){return this.s<0},s.isPositive=function(){return this.s>0},s.isZero=function(){return!!this.c&&this.c[0]==0},s.minus=function(I,M){var R,A,F,$,z=this,D=z.s;if(I=new b(I,M),M=I.s,!D||!M)return new b(NaN);if(D!=M)return I.s=-M,z.plus(I);var B=z.e/Wt,U=I.e/Wt,j=z.c,K=I.c;if(!B||!U){if(!j||!K)return j?(I.s=-M,I):new b(K?z:NaN);if(!j[0]||!K[0])return K[0]?(I.s=-M,I):new b(j[0]?z:a==3?-0:0)}if(B=Bi(B),U=Bi(U),j=j.slice(),D=B-U){for(($=D<0)?(D=-D,F=j):(U=B,F=K),F.reverse(),M=D;M--;F.push(0));F.reverse()}else for(A=($=(D=j.length)<(M=K.length))?D:M,D=M=0;M<A;M++)if(j[M]!=K[M]){$=j[M]<K[M];break}if($&&(F=j,j=K,K=F,I.s=-I.s),M=(A=K.length)-(R=j.length),M>0)for(;M--;j[R++]=0);for(M=as-1;A>D;){if(j[--A]<K[A]){for(R=A;R&&!j[--R];j[R]=M);--j[R],j[A]+=as}j[A]-=K[A]}for(;j[0]==0;j.splice(0,1),--U);return j[0]?S(I,j,U):(I.s=a==3?-1:1,I.c=[I.e=0],I)},s.modulo=s.mod=function(I,M){var R,A,F=this;return I=new b(I,M),!F.c||!I.s||I.c&&!I.c[0]?new b(NaN):!I.c||F.c&&!F.c[0]?new b(F):(y==9?(A=I.s,I.s=1,R=t(F,I,0,3),I.s=A,R.s*=A):R=t(F,I,0,y),I=F.minus(R.times(I)),!I.c[0]&&y==1&&(I.s=F.s),I)},s.multipliedBy=s.times=function(I,M){var R,A,F,$,z,D,B,U,j,K,W,J,lt,ft,ct,gt=this,bt=gt.c,It=(I=new b(I,M)).c;if(!bt||!It||!bt[0]||!It[0])return!gt.s||!I.s||bt&&!bt[0]&&!It||It&&!It[0]&&!bt?I.c=I.e=I.s=null:(I.s*=gt.s,!bt||!It?I.c=I.e=null:(I.c=[0],I.e=0)),I;for(A=Bi(gt.e/Wt)+Bi(I.e/Wt),I.s*=gt.s,B=bt.length,K=It.length,B<K&&(lt=bt,bt=It,It=lt,F=B,B=K,K=F),F=B+K,lt=[];F--;lt.push(0));for(ft=as,ct=Ir,F=K;--F>=0;){for(R=0,W=It[F]%ct,J=It[F]/ct|0,z=B,$=F+z;$>F;)U=bt[--z]%ct,j=bt[z]/ct|0,D=J*U+j*W,U=W*U+D%ct*ct+lt[$]+R,R=(U/ft|0)+(D/ct|0)+J*j,lt[$--]=U%ft;lt[$]=R}return R?++A:lt.splice(0,1),S(I,lt,A)},s.negated=function(){var I=new b(this);return I.s=-I.s||null,I},s.plus=function(I,M){var R,A=this,F=A.s;if(I=new b(I,M),M=I.s,!F||!M)return new b(NaN);if(F!=M)return I.s=-M,A.minus(I);var $=A.e/Wt,z=I.e/Wt,D=A.c,B=I.c;if(!$||!z){if(!D||!B)return new b(F/0);if(!D[0]||!B[0])return B[0]?I:new b(D[0]?A:F*0)}if($=Bi($),z=Bi(z),D=D.slice(),F=$-z){for(F>0?(z=$,R=B):(F=-F,R=D),R.reverse();F--;R.push(0));R.reverse()}for(F=D.length,M=B.length,F-M<0&&(R=B,B=D,D=R,M=F),F=0;M;)F=(D[--M]=D[M]+B[M]+F)/as|0,D[M]=as===D[M]?0:D[M]%as;return F&&(D=[F].concat(D),++z),S(I,D,z)},s.precision=s.sd=function(I,M){var R,A,F,$=this;if(I!=null&&I!==!!I)return je(I,1,pn),M==null?M=a:je(M,0,8),C(new b($),I,M);if(!(R=$.c))return null;if(F=R.length-1,A=F*Wt+1,F=R[F]){for(;F%10==0;F/=10,A--);for(F=R[0];F>=10;F/=10,A++);}return I&&$.e+1>A&&(A=$.e+1),A},s.shiftedBy=function(I){return je(I,-ag,ag),this.times("1e"+I)},s.squareRoot=s.sqrt=function(){var I,M,R,A,F,$=this,z=$.c,D=$.s,B=$.e,U=o+4,j=new b("0.5");if(D!==1||!z||!z[0])return new b(!D||D<0&&(!z||z[0])?NaN:z?$:1/0);if(D=Math.sqrt(+T($)),D==0||D==1/0?(M=$i(z),(M.length+B)%2==0&&(M+="0"),D=Math.sqrt(+M),B=Bi((B+1)/2)-(B<0||B%2),D==1/0?M="5e"+B:(M=D.toExponential(),M=M.slice(0,M.indexOf("e")+1)+B),R=new b(M)):R=new b(D+""),R.c[0]){for(B=R.e,D=B+U,D<3&&(D=0);;)if(F=R,R=j.times(F.plus(t($,F,U,1))),$i(F.c).slice(0,D)===(M=$i(R.c)).slice(0,D))if(R.e<B&&--D,M=M.slice(D-3,D+1),M=="9999"||!A&&M=="4999"){if(!A&&(C(F,F.e+o+2,0),F.times(F).eq($))){R=F;break}U+=4,D+=4,A=1}else{(!+M||!+M.slice(1)&&M.charAt(0)=="5")&&(C(R,R.e+o+2,1),I=!R.times(R).eq($));break}}return C(R,R.e+o+1,a,I)},s.toExponential=function(I,M){return I!=null&&(je(I,0,pn),I++),P(this,I,M,1)},s.toFixed=function(I,M){return I!=null&&(je(I,0,pn),I=I+this.e+1),P(this,I,M)},s.toFormat=function(I,M,R){var A,F=this;if(R==null)I!=null&&M&&typeof M=="object"?(R=M,M=null):I&&typeof I=="object"?(R=I,I=M=null):R=E;else if(typeof R!="object")throw Error(ti+"Argument not an object: "+R);if(A=F.toFixed(I,M),F.c){var $,z=A.split("."),D=+R.groupSize,B=+R.secondaryGroupSize,U=R.groupSeparator||"",j=z[0],K=z[1],W=F.s<0,J=W?j.slice(1):j,lt=J.length;if(B&&($=D,D=B,B=$,lt-=$),D>0&<>0){for($=lt%D||D,j=J.substr(0,$);$<lt;$+=D)j+=U+J.substr($,D);B>0&&(j+=U+J.slice($)),W&&(j="-"+j)}A=K?j+(R.decimalSeparator||"")+((B=+R.fractionGroupSize)?K.replace(new RegExp("\\d{"+B+"}\\B","g"),"$&"+(R.fractionGroupSeparator||"")):K):j}return(R.prefix||"")+A+(R.suffix||"")},s.toFraction=function(I){var M,R,A,F,$,z,D,B,U,j,K,W,J=this,lt=J.c;if(I!=null&&(D=new b(I),!D.isInteger()&&(D.c||D.s!==1)||D.lt(r)))throw Error(ti+"Argument "+(D.isInteger()?"out of range: ":"not an integer: ")+T(D));if(!lt)return new b(J);for(M=new b(r),U=R=new b(r),A=B=new b(r),W=$i(lt),$=M.e=W.length-J.e-1,M.c[0]=lg[(z=$%Wt)<0?Wt+z:z],I=!I||D.comparedTo(M)>0?$>0?M:U:D,z=d,d=1/0,D=new b(W),B.c[0]=0;j=t(D,M,0,1),F=R.plus(j.times(A)),F.comparedTo(I)!=1;)R=A,A=F,U=B.plus(j.times(F=U)),B=F,M=D.minus(j.times(F=M)),D=F;return F=t(I.minus(R),A,0,1),B=B.plus(F.times(U)),R=R.plus(F.times(A)),B.s=U.s=J.s,$=$*2,K=t(U,A,$,a).minus(J).abs().comparedTo(t(B,R,$,a).minus(J).abs())<1?[U,A]:[B,R],d=z,K},s.toNumber=function(){return+T(this)},s.toPrecision=function(I,M){return I!=null&&je(I,1,pn),P(this,I,M,2)},s.toString=function(I){var M,R=this,A=R.s,F=R.e;return F===null?A?(M="Infinity",A<0&&(M="-"+M)):M="NaN":(I==null?M=F<=l||F>=h?ih($i(R.c),F):sr($i(R.c),F,"0"):I===10&&L?(R=C(new b(R),o+F+1,a),M=sr($i(R.c),R.e,"0")):(je(I,2,w.length,"Base"),M=e(sr($i(R.c),F,"0"),10,I,A,!0)),A<0&&R.c[0]&&(M="-"+M)),M},s.valueOf=s.toJSON=function(){return T(this)},s._isBigNumber=!0,s[Symbol.toStringTag]="BigNumber",s[Symbol.for("nodejs.util.inspect.custom")]=s.valueOf,i!=null&&b.set(i),b}function Bi(i){var t=i|0;return i>0||i===t?t:t-1}function $i(i){for(var t,e,n=1,s=i.length,r=i[0]+"";n<s;){for(t=i[n++]+"",e=Wt-t.length;e--;t="0"+t);r+=t}for(s=r.length;r.charCodeAt(--s)===48;);return r.slice(0,s+1||1)}function co(i,t){var e,n,s=i.c,r=t.c,o=i.s,a=t.s,l=i.e,h=t.e;if(!o||!a)return null;if(e=s&&!s[0],n=r&&!r[0],e||n)return e?n?0:-a:o;if(o!=a)return o;if(e=o<0,n=l==h,!s||!r)return n?0:!s^e?1:-1;if(!n)return l>h^e?1:-1;for(a=(l=s.length)<(h=r.length)?l:h,o=0;o<a;o++)if(s[o]!=r[o])return s[o]>r[o]^e?1:-1;return l==h?0:l>h^e?1:-1}function je(i,t,e,n){if(i<t||i>e||i!==Gi(i))throw Error(ti+(n||"Argument")+(typeof i=="number"?i<t||i>e?" out of range: ":" not an integer: ":" not a primitive number: ")+String(i))}function nh(i){var t=i.c.length-1;return Bi(i.e/Wt)==t&&i.c[t]%2!=0}function ih(i,t){return(i.length>1?i.charAt(0)+"."+i.slice(1):i)+(t<0?"e":"e+")+t}function sr(i,t,e){var n,s;if(t<0){for(s=e+".";++t;s+=e);i=s+i}else if(n=i.length,++t>n){for(s=e,t-=n;--t;s+=e);i+=s}else t<n&&(i=i.slice(0,t)+"."+i.slice(t));return i}var zs=rw(),TR=class{constructor(i){Y(this,"key");Y(this,"left",null);Y(this,"right",null);this.key=i}},Vl=class extends TR{constructor(i){super(i)}},RR=class{constructor(){Y(this,"size",0);Y(this,"modificationCount",0);Y(this,"splayCount",0)}splay(i){const t=this.root;if(t==null)return this.compare(i,i),-1;let e=null,n=null,s=null,r=null,o=t;const a=this.compare;let l;for(;;)if(l=a(o.key,i),l>0){let h=o.left;if(h==null||(l=a(h.key,i),l>0&&(o.left=h.right,h.right=o,o=h,h=o.left,h==null)))break;e==null?n=o:e.left=o,e=o,o=h}else if(l<0){let h=o.right;if(h==null||(l=a(h.key,i),l<0&&(o.right=h.left,h.left=o,o=h,h=o.right,h==null)))break;s==null?r=o:s.right=o,s=o,o=h}else break;return s!=null&&(s.right=o.left,o.left=r),e!=null&&(e.left=o.right,o.right=n),this.root!==o&&(this.root=o,this.splayCount++),l}splayMin(i){let t=i,e=t.left;for(;e!=null;){const n=e;t.left=n.right,n.right=t,t=n,e=t.left}return t}splayMax(i){let t=i,e=t.right;for(;e!=null;){const n=e;t.right=n.left,n.left=t,t=n,e=t.right}return t}_delete(i){if(this.root==null||this.splay(i)!=0)return null;let e=this.root;const n=e,s=e.left;if(this.size--,s==null)this.root=e.right;else{const r=e.right;e=this.splayMax(s),e.right=r,this.root=e}return this.modificationCount++,n}addNewRoot(i,t){this.size++,this.modificationCount++;const e=this.root;if(e==null){this.root=i;return}t<0?(i.left=e,i.right=e.right,e.right=null):(i.right=e,i.left=e.left,e.left=null),this.root=i}_first(){const i=this.root;return i==null?null:(this.root=this.splayMin(i),this.root)}_last(){const i=this.root;return i==null?null:(this.root=this.splayMax(i),this.root)}clear(){this.root=null,this.size=0,this.modificationCount++}has(i){return this.validKey(i)&&this.splay(i)==0}defaultCompare(){return(i,t)=>i<t?-1:i>t?1:0}wrap(){return{getRoot:()=>this.root,setRoot:i=>{this.root=i},getSize:()=>this.size,getModificationCount:()=>this.modificationCount,getSplayCount:()=>this.splayCount,setSplayCount:i=>{this.splayCount=i},splay:i=>this.splay(i),has:i=>this.has(i)}}},Bv,qv,nf=class fu extends RR{constructor(e,n){super();Y(this,"root",null);Y(this,"compare");Y(this,"validKey");Y(this,Bv,"[object Set]");this.compare=e??this.defaultCompare(),this.validKey=n??(s=>s!=null&&s!=null)}delete(e){return this.validKey(e)?this._delete(e)!=null:!1}deleteAll(e){for(const n of e)this.delete(n)}forEach(e){const n=this[Symbol.iterator]();let s;for(;s=n.next(),!s.done;)e(s.value,s.value,this)}add(e){const n=this.splay(e);return n!=0&&this.addNewRoot(new Vl(e),n),this}addAndReturn(e){const n=this.splay(e);return n!=0&&this.addNewRoot(new Vl(e),n),this.root.key}addAll(e){for(const n of e)this.add(n)}isEmpty(){return this.root==null}isNotEmpty(){return this.root!=null}single(){if(this.size==0)throw"Bad state: No element";if(this.size>1)throw"Bad state: Too many element";return this.root.key}first(){if(this.size==0)throw"Bad state: No element";return this._first().key}last(){if(this.size==0)throw"Bad state: No element";return this._last().key}lastBefore(e){if(e==null)throw"Invalid arguments(s)";if(this.root==null)return null;if(this.splay(e)<0)return this.root.key;let s=this.root.left;if(s==null)return null;let r=s.right;for(;r!=null;)s=r,r=s.right;return s.key}firstAfter(e){if(e==null)throw"Invalid arguments(s)";if(this.root==null)return null;if(this.splay(e)>0)return this.root.key;let s=this.root.right;if(s==null)return null;let r=s.left;for(;r!=null;)s=r,r=s.left;return s.key}retainAll(e){const n=new fu(this.compare,this.validKey),s=this.modificationCount;for(const r of e){if(s!=this.modificationCount)throw"Concurrent modification during iteration.";this.validKey(r)&&this.splay(r)==0&&n.add(this.root.key)}n.size!=this.size&&(this.root=n.root,this.size=n.size,this.modificationCount++)}lookup(e){return!this.validKey(e)||this.splay(e)!=0?null:this.root.key}intersection(e){const n=new fu(this.compare,this.validKey);for(const s of this)e.has(s)&&n.add(s);return n}difference(e){const n=new fu(this.compare,this.validKey);for(const s of this)e.has(s)||n.add(s);return n}union(e){const n=this.clone();return n.addAll(e),n}clone(){const e=new fu(this.compare,this.validKey);return e.size=this.size,e.root=this.copyNode(this.root),e}copyNode(e){if(e==null)return null;function n(r,o){let a,l;do{if(a=r.left,l=r.right,a!=null){const h=new Vl(a.key);o.left=h,n(a,h)}if(l!=null){const h=new Vl(l.key);o.right=h,r=l,o=h}}while(l!=null)}const s=new Vl(e.key);return n(e,s),s}toSet(){return this.clone()}entries(){return new OR(this.wrap())}keys(){return this[Symbol.iterator]()}values(){return this[Symbol.iterator]()}[(qv=Symbol.iterator,Bv=Symbol.toStringTag,qv)](){return new AR(this.wrap())}},ow=class{constructor(i){Y(this,"tree");Y(this,"path",new Array);Y(this,"modificationCount",null);Y(this,"splayCount");this.tree=i,this.splayCount=i.getSplayCount()}[Symbol.iterator](){return this}next(){return this.moveNext()?{done:!1,value:this.current()}:{done:!0,value:null}}current(){if(!this.path.length)return null;const i=this.path[this.path.length-1];return this.getValue(i)}rebuildPath(i){this.path.splice(0,this.path.length),this.tree.splay(i),this.path.push(this.tree.getRoot()),this.splayCount=this.tree.getSplayCount()}findLeftMostDescendent(i){for(;i!=null;)this.path.push(i),i=i.left}moveNext(){if(this.modificationCount!=this.tree.getModificationCount()){if(this.modificationCount==null){this.modificationCount=this.tree.getModificationCount();let e=this.tree.getRoot();for(;e!=null;)this.path.push(e),e=e.left;return this.path.length>0}throw"Concurrent modification during iteration."}if(!this.path.length)return!1;this.splayCount!=this.tree.getSplayCount()&&this.rebuildPath(this.path[this.path.length-1].key);let i=this.path[this.path.length-1],t=i.right;if(t!=null){for(;t!=null;)this.path.push(t),t=t.left;return!0}for(this.path.pop();this.path.length&&this.path[this.path.length-1].right===i;)i=this.path.pop();return this.path.length>0}},AR=class extends ow{getValue(i){return i.key}},OR=class extends ow{getValue(i){return[i.key,i.key]}},aw=i=>()=>i,Qg=i=>{const t=i?(e,n)=>n.minus(e).abs().isLessThanOrEqualTo(i):aw(!1);return(e,n)=>t(e,n)?0:e.comparedTo(n)};function FR(i){const t=i?(e,n,s,r,o)=>e.exponentiatedBy(2).isLessThanOrEqualTo(r.minus(n).exponentiatedBy(2).plus(o.minus(s).exponentiatedBy(2)).times(i)):aw(!1);return(e,n,s)=>{const r=e.x,o=e.y,a=s.x,l=s.y,h=o.minus(l).times(n.x.minus(a)).minus(r.minus(a).times(n.y.minus(l)));return t(h,r,o,a,l)?0:h.comparedTo(0)}}var $R=i=>i,DR=i=>{if(i){const t=new nf(Qg(i)),e=new nf(Qg(i)),n=(r,o)=>o.addAndReturn(r),s=r=>({x:n(r.x,t),y:n(r.y,e)});return s({x:new zs(0),y:new zs(0)}),s}return $R},tm=i=>({set:t=>{pr=tm(t)},reset:()=>tm(i),compare:Qg(i),snap:DR(i),orient:FR(i)}),pr=tm(),Hl=(i,t)=>i.ll.x.isLessThanOrEqualTo(t.x)&&t.x.isLessThanOrEqualTo(i.ur.x)&&i.ll.y.isLessThanOrEqualTo(t.y)&&t.y.isLessThanOrEqualTo(i.ur.y),em=(i,t)=>{if(t.ur.x.isLessThan(i.ll.x)||i.ur.x.isLessThan(t.ll.x)||t.ur.y.isLessThan(i.ll.y)||i.ur.y.isLessThan(t.ll.y))return null;const e=i.ll.x.isLessThan(t.ll.x)?t.ll.x:i.ll.x,n=i.ur.x.isLessThan(t.ur.x)?i.ur.x:t.ur.x,s=i.ll.y.isLessThan(t.ll.y)?t.ll.y:i.ll.y,r=i.ur.y.isLessThan(t.ur.y)?i.ur.y:t.ur.y;return{ll:{x:e,y:s},ur:{x:n,y:r}}},Nh=(i,t)=>i.x.times(t.y).minus(i.y.times(t.x)),lw=(i,t)=>i.x.times(t.x).plus(i.y.times(t.y)),sf=i=>lw(i,i).sqrt(),GR=(i,t,e)=>{const n={x:t.x.minus(i.x),y:t.y.minus(i.y)},s={x:e.x.minus(i.x),y:e.y.minus(i.y)};return Nh(s,n).div(sf(s)).div(sf(n))},BR=(i,t,e)=>{const n={x:t.x.minus(i.x),y:t.y.minus(i.y)},s={x:e.x.minus(i.x),y:e.y.minus(i.y)};return lw(s,n).div(sf(s)).div(sf(n))},e_=(i,t,e)=>t.y.isZero()?null:{x:i.x.plus(t.x.div(t.y).times(e.minus(i.y))),y:e},n_=(i,t,e)=>t.x.isZero()?null:{x:e,y:i.y.plus(t.y.div(t.x).times(e.minus(i.x)))},qR=(i,t,e,n)=>{if(t.x.isZero())return n_(e,n,i.x);if(n.x.isZero())return n_(i,t,e.x);if(t.y.isZero())return e_(e,n,i.y);if(n.y.isZero())return e_(i,t,e.y);const s=Nh(t,n);if(s.isZero())return null;const r={x:e.x.minus(i.x),y:e.y.minus(i.y)},o=Nh(r,t).div(s),a=Nh(r,n).div(s),l=i.x.plus(a.times(t.x)),h=e.x.plus(o.times(n.x)),f=i.y.plus(a.times(t.y)),d=e.y.plus(o.times(n.y)),p=l.plus(h).div(2),y=f.plus(d).div(2);return{x:p,y}},Os=class uw{constructor(t,e){Y(this,"point");Y(this,"isLeft");Y(this,"segment");Y(this,"otherSE");Y(this,"consumedBy");t.events===void 0?t.events=[this]:t.events.push(this),this.point=t,this.isLeft=e}static compare(t,e){const n=uw.comparePoints(t.point,e.point);return n!==0?n:(t.point!==e.point&&t.link(e),t.isLeft!==e.isLeft?t.isLeft?1:-1:rf.compare(t.segment,e.segment))}static comparePoints(t,e){return t.x.isLessThan(e.x)?-1:t.x.isGreaterThan(e.x)?1:t.y.isLessThan(e.y)?-1:t.y.isGreaterThan(e.y)?1:0}link(t){if(t.point===this.point)throw new Error("Tried to link already linked events");const e=t.point.events;for(let n=0,s=e.length;n<s;n++){const r=e[n];this.point.events.push(r),r.point=this.point}this.checkForConsuming()}checkForConsuming(){const t=this.point.events.length;for(let e=0;e<t;e++){const n=this.point.events[e];if(n.segment.consumedBy===void 0)for(let s=e+1;s<t;s++){const r=this.point.events[s];r.consumedBy===void 0&&n.otherSE.point.events===r.otherSE.point.events&&n.segment.consume(r.segment)}}}getAvailableLinkedEvents(){const t=[];for(let e=0,n=this.point.events.length;e<n;e++){const s=this.point.events[e];s!==this&&!s.segment.ringOut&&s.segment.isInResult()&&t.push(s)}return t}getLeftmostComparator(t){const e=new Map,n=s=>{const r=s.otherSE;e.set(s,{sine:GR(this.point,t.point,r.point),cosine:BR(this.point,t.point,r.point)})};return(s,r)=>{e.has(s)||n(s),e.has(r)||n(r);const{sine:o,cosine:a}=e.get(s),{sine:l,cosine:h}=e.get(r);return o.isGreaterThanOrEqualTo(0)&&l.isGreaterThanOrEqualTo(0)?a.isLessThan(h)?1:a.isGreaterThan(h)?-1:0:o.isLessThan(0)&&l.isLessThan(0)?a.isLessThan(h)?-1:a.isGreaterThan(h)?1:0:l.isLessThan(o)?-1:l.isGreaterThan(o)?1:0}}},zR=class nm{constructor(t){Y(this,"events");Y(this,"poly");Y(this,"_isExteriorRing");Y(this,"_enclosingRing");this.events=t;for(let e=0,n=t.length;e<n;e++)t[e].segment.ringOut=this;this.poly=null}static factory(t){const e=[];for(let n=0,s=t.length;n<s;n++){const r=t[n];if(!r.isInResult()||r.ringOut)continue;let o=null,a=r.leftSE,l=r.rightSE;const h=[a],f=a.point,d=[];for(;o=a,a=l,h.push(a),a.point!==f;)for(;;){const p=a.getAvailableLinkedEvents();if(p.length===0){const E=h[0].point,w=h[h.length-1].point;throw new Error(`Unable to complete output ring starting at [${E.x}, ${E.y}]. Last matching segment found ends at [${w.x}, ${w.y}].`)}if(p.length===1){l=p[0].otherSE;break}let y=null;for(let E=0,w=d.length;E<w;E++)if(d[E].point===a.point){y=E;break}if(y!==null){const E=d.splice(y)[0],w=h.splice(E.index);w.unshift(w[0].otherSE),e.push(new nm(w.reverse()));continue}d.push({index:h.length,point:a.point});const _=a.getLeftmostComparator(o);l=p.sort(_)[0].otherSE;break}e.push(new nm(h))}return e}getGeom(){let t=this.events[0].point;const e=[t];for(let h=1,f=this.events.length-1;h<f;h++){const d=this.events[h].point,p=this.events[h+1].point;pr.orient(d,t,p)!==0&&(e.push(d),t=d)}if(e.length===1)return null;const n=e[0],s=e[1];pr.orient(n,t,s)===0&&e.shift(),e.push(e[0]);const r=this.isExteriorRing()?1:-1,o=this.isExteriorRing()?0:e.length-1,a=this.isExteriorRing()?e.length:-1,l=[];for(let h=o;h!=a;h+=r)l.push([e[h].x.toNumber(),e[h].y.toNumber()]);return l}isExteriorRing(){if(this._isExteriorRing===void 0){const t=this.enclosingRing();this._isExteriorRing=t?!t.isExteriorRing():!0}return this._isExteriorRing}enclosingRing(){return this._enclosingRing===void 0&&(this._enclosingRing=this._calcEnclosingRing()),this._enclosingRing}_calcEnclosingRing(){var s,r;let t=this.events[0];for(let o=1,a=this.events.length;o<a;o++){const l=this.events[o];Os.compare(t,l)>0&&(t=l)}let e=t.segment.prevInResult(),n=e?e.prevInResult():null;for(;;){if(!e)return null;if(!n)return e.ringOut;if(n.ringOut!==e.ringOut)return((s=n.ringOut)==null?void 0:s.enclosingRing())!==e.ringOut?e.ringOut:(r=e.ringOut)==null?void 0:r.enclosingRing();e=n.prevInResult(),n=e?e.prevInResult():null}}},i_=class{constructor(i){Y(this,"exteriorRing");Y(this,"interiorRings");this.exteriorRing=i,i.poly=this,this.interiorRings=[]}addInterior(i){this.interiorRings.push(i),i.poly=this}getGeom(){const i=this.exteriorRing.getGeom();if(i===null)return null;const t=[i];for(let e=0,n=this.interiorRings.length;e<n;e++){const s=this.interiorRings[e].getGeom();s!==null&&t.push(s)}return t}},UR=class{constructor(i){Y(this,"rings");Y(this,"polys");this.rings=i,this.polys=this._composePolys(i)}getGeom(){const i=[];for(let t=0,e=this.polys.length;t<e;t++){const n=this.polys[t].getGeom();n!==null&&i.push(n)}return i}_composePolys(i){var e;const t=[];for(let n=0,s=i.length;n<s;n++){const r=i[n];if(!r.poly)if(r.isExteriorRing())t.push(new i_(r));else{const o=r.enclosingRing();o!=null&&o.poly||t.push(new i_(o)),(e=o==null?void 0:o.poly)==null||e.addInterior(r)}}return t}},YR=class{constructor(i,t=rf.compare){Y(this,"queue");Y(this,"tree");Y(this,"segments");this.queue=i,this.tree=new nf(t),this.segments=[]}process(i){const t=i.segment,e=[];if(i.consumedBy)return i.isLeft?this.queue.delete(i.otherSE):this.tree.delete(t),e;i.isLeft&&this.tree.add(t);let n=t,s=t;do n=this.tree.lastBefore(n);while(n!=null&&n.consumedBy!=null);do s=this.tree.firstAfter(s);while(s!=null&&s.consumedBy!=null);if(i.isLeft){let r=null;if(n){const a=n.getIntersection(t);if(a!==null&&(t.isAnEndpoint(a)||(r=a),!n.isAnEndpoint(a))){const l=this._splitSafely(n,a);for(let h=0,f=l.length;h<f;h++)e.push(l[h])}}let o=null;if(s){const a=s.getIntersection(t);if(a!==null&&(t.isAnEndpoint(a)||(o=a),!s.isAnEndpoint(a))){const l=this._splitSafely(s,a);for(let h=0,f=l.length;h<f;h++)e.push(l[h])}}if(r!==null||o!==null){let a=null;r===null?a=o:o===null?a=r:a=Os.comparePoints(r,o)<=0?r:o,this.queue.delete(t.rightSE),e.push(t.rightSE);const l=t.split(a);for(let h=0,f=l.length;h<f;h++)e.push(l[h])}e.length>0?(this.tree.delete(t),e.push(i)):(this.segments.push(t),t.prev=n)}else{if(n&&s){const r=n.getIntersection(s);if(r!==null){if(!n.isAnEndpoint(r)){const o=this._splitSafely(n,r);for(let a=0,l=o.length;a<l;a++)e.push(o[a])}if(!s.isAnEndpoint(r)){const o=this._splitSafely(s,r);for(let a=0,l=o.length;a<l;a++)e.push(o[a])}}}this.tree.delete(t)}return e}_splitSafely(i,t){this.tree.delete(i);const e=i.rightSE;this.queue.delete(e);const n=i.split(t);return n.push(e),i.consumedBy===void 0&&this.tree.add(i),n}},XR=class{constructor(){Y(this,"type");Y(this,"numMultiPolys")}run(i,t,e){du.type=i;const n=[new r_(t,!0)];for(let h=0,f=e.length;h<f;h++)n.push(new r_(e[h],!1));if(du.numMultiPolys=n.length,du.type==="difference"){const h=n[0];let f=1;for(;f<n.length;)em(n[f].bbox,h.bbox)!==null?f++:n.splice(f,1)}if(du.type==="intersection")for(let h=0,f=n.length;h<f;h++){const d=n[h];for(let p=h+1,y=n.length;p<y;p++)if(em(d.bbox,n[p].bbox)===null)return[]}const s=new nf(Os.compare);for(let h=0,f=n.length;h<f;h++){const d=n[h].getSweepEvents();for(let p=0,y=d.length;p<y;p++)s.add(d[p])}const r=new YR(s);let o=null;for(s.size!=0&&(o=s.first(),s.delete(o));o;){const h=r.process(o);for(let f=0,d=h.length;f<d;f++){const p=h[f];p.consumedBy===void 0&&s.add(p)}s.size!=0?(o=s.first(),s.delete(o)):o=null}pr.reset();const a=zR.factory(r.segments);return new UR(a).getGeom()}},du=new XR,Au=du,jR=0,rf=class Lh{constructor(t,e,n,s){Y(this,"id");Y(this,"leftSE");Y(this,"rightSE");Y(this,"rings");Y(this,"windings");Y(this,"ringOut");Y(this,"consumedBy");Y(this,"prev");Y(this,"_prevInResult");Y(this,"_beforeState");Y(this,"_afterState");Y(this,"_isInResult");this.id=++jR,this.leftSE=t,t.segment=this,t.otherSE=e,this.rightSE=e,e.segment=this,e.otherSE=t,this.rings=n,this.windings=s}static compare(t,e){const n=t.leftSE.point.x,s=e.leftSE.point.x,r=t.rightSE.point.x,o=e.rightSE.point.x;if(o.isLessThan(n))return 1;if(r.isLessThan(s))return-1;const a=t.leftSE.point.y,l=e.leftSE.point.y,h=t.rightSE.point.y,f=e.rightSE.point.y;if(n.isLessThan(s)){if(l.isLessThan(a)&&l.isLessThan(h))return 1;if(l.isGreaterThan(a)&&l.isGreaterThan(h))return-1;const d=t.comparePoint(e.leftSE.point);if(d<0)return 1;if(d>0)return-1;const p=e.comparePoint(t.rightSE.point);return p!==0?p:-1}if(n.isGreaterThan(s)){if(a.isLessThan(l)&&a.isLessThan(f))return-1;if(a.isGreaterThan(l)&&a.isGreaterThan(f))return 1;const d=e.comparePoint(t.leftSE.point);if(d!==0)return d;const p=t.comparePoint(e.rightSE.point);return p<0?1:p>0?-1:1}if(a.isLessThan(l))return-1;if(a.isGreaterThan(l))return 1;if(r.isLessThan(o)){const d=e.comparePoint(t.rightSE.point);if(d!==0)return d}if(r.isGreaterThan(o)){const d=t.comparePoint(e.rightSE.point);if(d<0)return 1;if(d>0)return-1}if(!r.eq(o)){const d=h.minus(a),p=r.minus(n),y=f.minus(l),_=o.minus(s);if(d.isGreaterThan(p)&&y.isLessThan(_))return 1;if(d.isLessThan(p)&&y.isGreaterThan(_))return-1}return r.isGreaterThan(o)?1:r.isLessThan(o)||h.isLessThan(f)?-1:h.isGreaterThan(f)?1:t.id<e.id?-1:t.id>e.id?1:0}static fromRing(t,e,n){let s,r,o;const a=Os.comparePoints(t,e);if(a<0)s=t,r=e,o=1;else if(a>0)s=e,r=t,o=-1;else throw new Error(`Tried to create degenerate segment at [${t.x}, ${t.y}]`);const l=new Os(s,!0),h=new Os(r,!1);return new Lh(l,h,[n],[o])}replaceRightSE(t){this.rightSE=t,this.rightSE.segment=this,this.rightSE.otherSE=this.leftSE,this.leftSE.otherSE=this.rightSE}bbox(){const t=this.leftSE.point.y,e=this.rightSE.point.y;return{ll:{x:this.leftSE.point.x,y:t.isLessThan(e)?t:e},ur:{x:this.rightSE.point.x,y:t.isGreaterThan(e)?t:e}}}vector(){return{x:this.rightSE.point.x.minus(this.leftSE.point.x),y:this.rightSE.point.y.minus(this.leftSE.point.y)}}isAnEndpoint(t){return t.x.eq(this.leftSE.point.x)&&t.y.eq(this.leftSE.point.y)||t.x.eq(this.rightSE.point.x)&&t.y.eq(this.rightSE.point.y)}comparePoint(t){return pr.orient(this.leftSE.point,t,this.rightSE.point)}getIntersection(t){const e=this.bbox(),n=t.bbox(),s=em(e,n);if(s===null)return null;const r=this.leftSE.point,o=this.rightSE.point,a=t.leftSE.point,l=t.rightSE.point,h=Hl(e,a)&&this.comparePoint(a)===0,f=Hl(n,r)&&t.comparePoint(r)===0,d=Hl(e,l)&&this.comparePoint(l)===0,p=Hl(n,o)&&t.comparePoint(o)===0;if(f&&h)return p&&!d?o:!p&&d?l:null;if(f)return d&&r.x.eq(l.x)&&r.y.eq(l.y)?null:r;if(h)return p&&o.x.eq(a.x)&&o.y.eq(a.y)?null:a;if(p&&d)return null;if(p)return o;if(d)return l;const y=qR(r,this.vector(),a,t.vector());return y===null||!Hl(s,y)?null:pr.snap(y)}split(t){const e=[],n=t.events!==void 0,s=new Os(t,!0),r=new Os(t,!1),o=this.rightSE;this.replaceRightSE(r),e.push(r),e.push(s);const a=new Lh(s,o,this.rings.slice(),this.windings.slice());return Os.comparePoints(a.leftSE.point,a.rightSE.point)>0&&a.swapEvents(),Os.comparePoints(this.leftSE.point,this.rightSE.point)>0&&this.swapEvents(),n&&(s.checkForConsuming(),r.checkForConsuming()),e}swapEvents(){const t=this.rightSE;this.rightSE=this.leftSE,this.leftSE=t,this.leftSE.isLeft=!0,this.rightSE.isLeft=!1;for(let e=0,n=this.windings.length;e<n;e++)this.windings[e]*=-1}consume(t){let e=this,n=t;for(;e.consumedBy;)e=e.consumedBy;for(;n.consumedBy;)n=n.consumedBy;const s=Lh.compare(e,n);if(s!==0){if(s>0){const r=e;e=n,n=r}if(e.prev===n){const r=e;e=n,n=r}for(let r=0,o=n.rings.length;r<o;r++){const a=n.rings[r],l=n.windings[r],h=e.rings.indexOf(a);h===-1?(e.rings.push(a),e.windings.push(l)):e.windings[h]+=l}n.rings=null,n.windings=null,n.consumedBy=e,n.leftSE.consumedBy=e.leftSE,n.rightSE.consumedBy=e.rightSE}}prevInResult(){return this._prevInResult!==void 0?this._prevInResult:(this.prev?this.prev.isInResult()?this._prevInResult=this.prev:this._prevInResult=this.prev.prevInResult():this._prevInResult=null,this._prevInResult)}beforeState(){if(this._beforeState!==void 0)return this._beforeState;if(!this.prev)this._beforeState={rings:[],windings:[],multiPolys:[]};else{const t=this.prev.consumedBy||this.prev;this._beforeState=t.afterState()}return this._beforeState}afterState(){if(this._afterState!==void 0)return this._afterState;const t=this.beforeState();this._afterState={rings:t.rings.slice(0),windings:t.windings.slice(0),multiPolys:[]};const e=this._afterState.rings,n=this._afterState.windings,s=this._afterState.multiPolys;for(let a=0,l=this.rings.length;a<l;a++){const h=this.rings[a],f=this.windings[a],d=e.indexOf(h);d===-1?(e.push(h),n.push(f)):n[d]+=f}const r=[],o=[];for(let a=0,l=e.length;a<l;a++){if(n[a]===0)continue;const h=e[a],f=h.poly;if(o.indexOf(f)===-1)if(h.isExterior)r.push(f);else{o.indexOf(f)===-1&&o.push(f);const d=r.indexOf(h.poly);d!==-1&&r.splice(d,1)}}for(let a=0,l=r.length;a<l;a++){const h=r[a].multiPoly;s.indexOf(h)===-1&&s.push(h)}return this._afterState}isInResult(){if(this.consumedBy)return!1;if(this._isInResult!==void 0)return this._isInResult;const t=this.beforeState().multiPolys,e=this.afterState().multiPolys;switch(Au.type){case"union":{const n=t.length===0,s=e.length===0;this._isInResult=n!==s;break}case"intersection":{let n,s;t.length<e.length?(n=t.length,s=e.length):(n=e.length,s=t.length),this._isInResult=s===Au.numMultiPolys&&n<s;break}case"xor":{const n=Math.abs(t.length-e.length);this._isInResult=n%2===1;break}case"difference":{const n=s=>s.length===1&&s[0].isSubject;this._isInResult=n(t)!==n(e);break}}return this._isInResult}},s_=class{constructor(i,t,e){Y(this,"poly");Y(this,"isExterior");Y(this,"segments");Y(this,"bbox");if(!Array.isArray(i)||i.length===0)throw new Error("Input geometry is not a valid Polygon or MultiPolygon");if(this.poly=t,this.isExterior=e,this.segments=[],typeof i[0][0]!="number"||typeof i[0][1]!="number")throw new Error("Input geometry is not a valid Polygon or MultiPolygon");const n=pr.snap({x:new zs(i[0][0]),y:new zs(i[0][1])});this.bbox={ll:{x:n.x,y:n.y},ur:{x:n.x,y:n.y}};let s=n;for(let r=1,o=i.length;r<o;r++){if(typeof i[r][0]!="number"||typeof i[r][1]!="number")throw new Error("Input geometry is not a valid Polygon or MultiPolygon");const a=pr.snap({x:new zs(i[r][0]),y:new zs(i[r][1])});a.x.eq(s.x)&&a.y.eq(s.y)||(this.segments.push(rf.fromRing(s,a,this)),a.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=a.x),a.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=a.y),a.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=a.x),a.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=a.y),s=a)}(!n.x.eq(s.x)||!n.y.eq(s.y))&&this.segments.push(rf.fromRing(s,n,this))}getSweepEvents(){const i=[];for(let t=0,e=this.segments.length;t<e;t++){const n=this.segments[t];i.push(n.leftSE),i.push(n.rightSE)}return i}},VR=class{constructor(i,t){Y(this,"multiPoly");Y(this,"exteriorRing");Y(this,"interiorRings");Y(this,"bbox");if(!Array.isArray(i))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");this.exteriorRing=new s_(i[0],this,!0),this.bbox={ll:{x:this.exteriorRing.bbox.ll.x,y:this.exteriorRing.bbox.ll.y},ur:{x:this.exteriorRing.bbox.ur.x,y:this.exteriorRing.bbox.ur.y}},this.interiorRings=[];for(let e=1,n=i.length;e<n;e++){const s=new s_(i[e],this,!1);s.bbox.ll.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=s.bbox.ll.x),s.bbox.ll.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=s.bbox.ll.y),s.bbox.ur.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=s.bbox.ur.x),s.bbox.ur.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=s.bbox.ur.y),this.interiorRings.push(s)}this.multiPoly=t}getSweepEvents(){const i=this.exteriorRing.getSweepEvents();for(let t=0,e=this.interiorRings.length;t<e;t++){const n=this.interiorRings[t].getSweepEvents();for(let s=0,r=n.length;s<r;s++)i.push(n[s])}return i}},r_=class{constructor(i,t){Y(this,"isSubject");Y(this,"polys");Y(this,"bbox");if(!Array.isArray(i))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");try{typeof i[0][0][0]=="number"&&(i=[i])}catch{}this.polys=[],this.bbox={ll:{x:new zs(Number.POSITIVE_INFINITY),y:new zs(Number.POSITIVE_INFINITY)},ur:{x:new zs(Number.NEGATIVE_INFINITY),y:new zs(Number.NEGATIVE_INFINITY)}};for(let e=0,n=i.length;e<n;e++){const s=new VR(i[e],this);s.bbox.ll.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=s.bbox.ll.x),s.bbox.ll.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=s.bbox.ll.y),s.bbox.ur.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=s.bbox.ur.x),s.bbox.ur.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=s.bbox.ur.y),this.polys.push(s)}this.isSubject=t}getSweepEvents(){const i=[];for(let t=0,e=this.polys.length;t<e;t++){const n=this.polys[t].getSweepEvents();for(let s=0,r=n.length;s<r;s++)i.push(n[s])}return i}},HR=(i,...t)=>Au.run("union",i,t),WR=(i,...t)=>Au.run("intersection",i,t),KR=(i,...t)=>Au.run("difference",i,t);pr.set;function ba(i){const t=[];if(Wr(i,s=>{t.push(s.coordinates)}),t.length<2)throw new Error("Must have at least two features");const e=i.features[0].properties||{},n=KR(t[0],...t.slice(1));return n.length===0?null:n.length===1?Ce(n[0],e):bo(n,e)}function sh(i){if(!i)throw new Error("geojson is required");var t=[];return zr(i,function(e){t.push(e)}),ae(t)}function ZR(i){return Wm(De(i))}function JR(i){const t=[];return i.type==="FeatureCollection"?qr(i,function(e){Mn(e,function(n){t.push(St(n,e.properties))})}):i.type==="Feature"?Mn(i,function(e){t.push(St(e,i.properties))}):Mn(i,function(e){t.push(St(e))}),ae(t)}function of(i,t={}){const e=[];if(Wr(i,s=>{e.push(s.coordinates)}),e.length<2)throw new Error("Must specify at least 2 geometries");const n=WR(e[0],...e.slice(1));return n.length===0?null:n.length===1?Ce(n[0],t.properties):bo(n,t.properties)}function cw(i){let t,e;const n={type:"FeatureCollection",features:[]};if(i.type==="Feature"?e=i.geometry:e=i,e.type==="LineString")t=[e.coordinates];else if(e.type==="MultiLineString")t=e.coordinates;else if(e.type==="MultiPolygon")t=[].concat(...e.coordinates);else if(e.type==="Polygon")t=e.coordinates;else throw new Error("Input must be a LineString, MultiLineString, Polygon, or MultiPolygon Feature or Geometry");return t.forEach(s=>{t.forEach(r=>{for(let o=0;o<s.length-1;o++)for(let a=o;a<r.length-1;a++){if(s===r&&(Math.abs(o-a)===1||o===0&&a===s.length-2&&s[o][0]===s[s.length-1][0]&&s[o][1]===s[s.length-1][1]))continue;const l=QR(s[o][0],s[o][1],s[o+1][0],s[o+1][1],r[a][0],r[a][1],r[a+1][0],r[a+1][1]);l&&n.features.push(St([l[0],l[1]]))}})}),n}function QR(i,t,e,n,s,r,o,a){let l,h,f,d,p;const y={x:null,y:null,onLine1:!1,onLine2:!1};return l=(a-r)*(e-i)-(o-s)*(n-t),l===0?y.x!==null&&y.y!==null?y:!1:(h=t-r,f=i-s,d=(o-s)*h-(a-r)*f,p=(e-i)*h-(n-t)*f,h=d/l,f=p/l,y.x=i+h*(e-i),y.y=t+h*(n-t),h>=0&&h<=1&&(y.onLine1=!0),f>=0&&f<=1&&(y.onLine2=!0),y.onLine1&&y.onLine2?[y.x,y.y]:!1)}function el(i,t={}){return ik(i,(e,n)=>{const s=n.geometry.coordinates;return e+nn(s[0],s[1],t)},0)}function tA(i,t){const e=nn(i,t),n=Wa(i,t);return ku(i,e/2,n)}var eA=Object.defineProperty,nA=Object.defineProperties,iA=Object.getOwnPropertyDescriptors,o_=Object.getOwnPropertySymbols,sA=Object.prototype.hasOwnProperty,rA=Object.prototype.propertyIsEnumerable,a_=(i,t,e)=>t in i?eA(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,l_=(i,t)=>{for(var e in t||(t={}))sA.call(t,e)&&a_(i,e,t[e]);if(o_)for(var e of o_(t))rA.call(t,e)&&a_(i,e,t[e]);return i},u_=(i,t)=>nA(i,iA(t));function oA(i,t,e={}){if(!i)throw new Error("targetPoint is required");if(!t)throw new Error("points is required");let n=1/0,s=0;qr(t,(o,a)=>{const l=nn(i,o,e);l<n&&(s=a,n=l)});const r=Ye(t.features[s]);return u_(l_({},r),{properties:u_(l_({},r.properties),{featureIndex:s,distanceToPoint:n})})}function aA(i){const t=lA(i),e=UE(t);let n=!1,s=0;for(;!n&&s<t.features.length;){const r=t.features[s].geometry;let o,a,l,h,f,d,p=!1;if(r.type==="Point")e.geometry.coordinates[0]===r.coordinates[0]&&e.geometry.coordinates[1]===r.coordinates[1]&&(n=!0);else if(r.type==="MultiPoint"){let y=!1,_=0;for(;!y&&_<r.coordinates.length;)e.geometry.coordinates[0]===r.coordinates[_][0]&&e.geometry.coordinates[1]===r.coordinates[_][1]&&(n=!0,y=!0),_++}else if(r.type==="LineString"){let y=0;for(;!p&&y<r.coordinates.length-1;)o=e.geometry.coordinates[0],a=e.geometry.coordinates[1],l=r.coordinates[y][0],h=r.coordinates[y][1],f=r.coordinates[y+1][0],d=r.coordinates[y+1][1],c_(o,a,l,h,f,d)&&(p=!0,n=!0),y++}else if(r.type==="MultiLineString"){let y=0;for(;y<r.coordinates.length;){p=!1;let _=0;const E=r.coordinates[y];for(;!p&&_<E.length-1;)o=e.geometry.coordinates[0],a=e.geometry.coordinates[1],l=E[_][0],h=E[_][1],f=E[_+1][0],d=E[_+1][1],c_(o,a,l,h,f,d)&&(p=!0,n=!0),_++;y++}}else(r.type==="Polygon"||r.type==="MultiPolygon")&&Ht(e,r)&&(n=!0);s++}if(n)return e;{const r=ae([]);for(let o=0;o<t.features.length;o++)r.features=r.features.concat(JR(t.features[o]).features);return St(oA(e,r).geometry.coordinates)}}function lA(i){return i.type!=="FeatureCollection"?i.type!=="Feature"?ae([vn(i)]):ae([i]):i}function c_(i,t,e,n,s,r){const o=Math.sqrt((s-e)*(s-e)+(r-n)*(r-n)),a=Math.sqrt((i-e)*(i-e)+(t-n)*(t-n)),l=Math.sqrt((s-i)*(s-i)+(r-t)*(r-t));return o===a+l}function uA(i){return(i>0)-(i<0)||+i}function np(i,t,e){const n=t[0]-i[0],s=t[1]-i[1],r=e[0]-t[0],o=e[1]-t[1];return uA(n*o-r*s)}function cA(i,t){const e=i.geometry.coordinates[0].map(o=>o[0]),n=i.geometry.coordinates[0].map(o=>o[1]),s=t.geometry.coordinates[0].map(o=>o[0]),r=t.geometry.coordinates[0].map(o=>o[1]);return Math.max.apply(null,e)===Math.max.apply(null,s)&&Math.max.apply(null,n)===Math.max.apply(null,r)&&Math.min.apply(null,e)===Math.min.apply(null,s)&&Math.min.apply(null,n)===Math.min.apply(null,r)}function h_(i,t){return t.geometry.coordinates[0].every(e=>Ht(St(e),i))}function hA(i,t){return i[0]===t[0]&&i[1]===t[1]}var fA=class{constructor(t,e){this.id=t,this.coordinates=e,this.innerEdges=[],this.outerEdges=[],this.outerEdgesSorted=!1}removeInnerEdge(t){this.innerEdges=this.innerEdges.filter(e=>e.from.id!==t.from.id)}removeOuterEdge(t){this.outerEdges=this.outerEdges.filter(e=>e.to.id!==t.to.id)}addOuterEdge(t){this.outerEdges.push(t),this.outerEdgesSorted=!1}sortOuterEdges(){this.outerEdgesSorted||(this.outerEdges.sort((t,e)=>{const n=t.to,s=e.to;if(n.coordinates[0]-this.coordinates[0]>=0&&s.coordinates[0]-this.coordinates[0]<0)return 1;if(n.coordinates[0]-this.coordinates[0]<0&&s.coordinates[0]-this.coordinates[0]>=0)return-1;if(n.coordinates[0]-this.coordinates[0]===0&&s.coordinates[0]-this.coordinates[0]===0)return n.coordinates[1]-this.coordinates[1]>=0||s.coordinates[1]-this.coordinates[1]>=0?n.coordinates[1]-s.coordinates[1]:s.coordinates[1]-n.coordinates[1];const r=np(this.coordinates,n.coordinates,s.coordinates);if(r<0)return 1;if(r>0)return-1;const o=Math.pow(n.coordinates[0]-this.coordinates[0],2)+Math.pow(n.coordinates[1]-this.coordinates[1],2),a=Math.pow(s.coordinates[0]-this.coordinates[0],2)+Math.pow(s.coordinates[1]-this.coordinates[1],2);return o-a}),this.outerEdgesSorted=!0)}getOuterEdges(){return this.sortOuterEdges(),this.outerEdges}getOuterEdge(t){return this.sortOuterEdges(),this.outerEdges[t]}addInnerEdge(t){this.innerEdges.push(t)}},dA=class hw{getSymetric(){return this.symetric||(this.symetric=new hw(this.to,this.from),this.symetric.symetric=this),this.symetric}constructor(t,e){this.from=t,this.to=e,this.next=void 0,this.label=void 0,this.symetric=void 0,this.ring=void 0,this.from.addOuterEdge(this),this.to.addInnerEdge(this)}deleteEdge(){this.from.removeOuterEdge(this),this.to.removeInnerEdge(this)}isEqual(t){return this.from.id===t.from.id&&this.to.id===t.to.id}toString(){return`Edge { ${this.from.id} -> ${this.to.id} }`}toLineString(){return re([this.from.coordinates,this.to.coordinates])}compareTo(t){return np(t.from.coordinates,t.to.coordinates,this.to.coordinates)}},fw=class{constructor(){this.edges=[],this.polygon=void 0,this.envelope=void 0}push(t){this.edges.push(t),this.polygon=this.envelope=void 0}get(t){return this.edges[t]}get length(){return this.edges.length}forEach(t){this.edges.forEach(t)}map(t){return this.edges.map(t)}some(t){return this.edges.some(t)}isValid(){return!0}isHole(){const t=this.edges.reduce((r,o,a)=>(o.from.coordinates[1]>this.edges[r].from.coordinates[1]&&(r=a),r),0),e=(t===0?this.length:t)-1,n=(t+1)%this.length,s=np(this.edges[e].from.coordinates,this.edges[t].from.coordinates,this.edges[n].from.coordinates);return s===0?this.edges[e].from.coordinates[0]>this.edges[n].from.coordinates[0]:s>0}toMultiPoint(){return IE(this.edges.map(t=>t.from.coordinates))}toPolygon(){if(this.polygon)return this.polygon;const t=this.edges.map(e=>e.from.coordinates);return t.push(this.edges[0].from.coordinates),this.polygon=Ce([t])}getEnvelope(){return this.envelope?this.envelope:this.envelope=ZR(this.toPolygon())}static findEdgeRingContaining(t,e){const n=t.getEnvelope();let s,r;return e.forEach(o=>{const a=o.getEnvelope();if(r&&(s=r.getEnvelope()),!cA(a,n)&&h_(a,n)){const l=t.map(f=>f.from.coordinates);let h;for(const f of l)o.some(d=>hA(f,d.from.coordinates))||(h=f);h&&o.inside(St(h))&&(!r||h_(s,a))&&(r=o)}}),r}inside(t){return Ht(t,this.toPolygon())}};function gA(i){if(!i)throw new Error("No geojson passed");if(i.type!=="FeatureCollection"&&i.type!=="GeometryCollection"&&i.type!=="MultiLineString"&&i.type!=="LineString"&&i.type!=="Feature")throw new Error(`Invalid input type '${i.type}'. Geojson must be FeatureCollection, GeometryCollection, LineString, MultiLineString or Feature`)}var mA=class dw{constructor(){this.nodes=new Map,this.nodeId=0,this.edges=new Map}static fromGeoJson(t){gA(t);const e=new dw;return zr(t,n=>{WP(n,"LineString","Graph::fromGeoJson"),JP(n,(s,r)=>{if(s){const o=e.getNode(s),a=e.getNode(r);e.addEdge(o,a)}return r})}),e}getNode(t){var e;let n=(e=this.nodes.get(t[0]))==null?void 0:e.get(t[1]);if(n==null){const s=new fA(this.nodeId++,t);let r=this.nodes.get(t[0]);return r==null&&(r=new Map,this.nodes.set(t[0],r)),r.set(t[1],s),s}return n}addEdge(t,e){var n;if((n=this.edges.get(t))!=null&&n.has(e))return;const s=new dA(t,e),r=s.getSymetric();let o=this.edges.get(t);o==null&&(o=new Map,this.edges.set(t,o)),o.set(e,s);let a=this.edges.get(e);a==null&&(a=new Map,this.edges.set(e,a)),a.set(t,r)}deleteDangles(){this._forEachNode(t=>this._removeIfDangle(t))}_removeIfDangle(t){if(t.innerEdges.length<=1){const e=t.getOuterEdges().map(n=>n.to);this.removeNode(t),e.forEach(n=>this._removeIfDangle(n))}}deleteCutEdges(){this._computeNextCWEdges(),this._findLabeledEdgeRings(),this._forEachEdge(t=>{t.label===t.symetric.label&&(this.removeEdge(t.symetric),this.removeEdge(t))})}_computeNextCWEdges(t){t==null?this._forEachNode(e=>this._computeNextCWEdges(e)):t.getOuterEdges().forEach((e,n)=>{t.getOuterEdge((n===0?t.getOuterEdges().length:n)-1).symetric.next=e})}_computeNextCCWEdges(t,e){const n=t.getOuterEdges();let s,r;for(let o=n.length-1;o>=0;--o){let a=n[o],l=a.symetric,h,f;a.label===e&&(h=a),l.label===e&&(f=l),!(!h||!f)&&(f&&(r=f),h&&(r&&(r.next=h,r=void 0),s||(s=h)))}r&&(r.next=s)}_findLabeledEdgeRings(){const t=[];let e=0;return this._forEachEdge(n=>{if(n.label>=0)return;t.push(n);let s=n;do s.label=e,s=s.next;while(!n.isEqual(s));e++}),t}getEdgeRings(){this._computeNextCWEdges(),this._forEachEdge(e=>{e.label=void 0}),this._findLabeledEdgeRings().forEach(e=>{this._findIntersectionNodes(e).forEach(n=>{this._computeNextCCWEdges(n,e.label)})});const t=[];return this._forEachEdge(e=>{e.ring||t.push(this._findEdgeRing(e))}),t}_findIntersectionNodes(t){const e=[];let n=t;do{let s=0;n.from.getOuterEdges().forEach(r=>{r.label===t.label&&++s}),s>1&&e.push(n.from),n=n.next}while(!t.isEqual(n));return e}_findEdgeRing(t){let e=t;const n=new fw;do n.push(e),e.ring=n,e=e.next;while(!t.isEqual(e));return n}removeNode(t){var e;t.getOuterEdges().forEach(n=>this.removeEdge(n)),t.innerEdges.forEach(n=>this.removeEdge(n)),(e=this.nodes.get(t.coordinates[0]))==null||e.delete(t.coordinates[1])}removeEdge(t){var e;(e=this.edges.get(t.from))==null||e.delete(t.to),t.deleteEdge()}_forEachNode(t){for(const e of this.nodes.values())for(const n of e.values())t(n)}_forEachEdge(t){for(const e of this.edges.values())for(const n of e.values())t(n)}};function pA(i){const t=mA.fromGeoJson(i);t.deleteDangles(),t.deleteCutEdges();const e=[],n=[];return t.getEdgeRings().filter(s=>s.isValid()).forEach(s=>{s.isHole()?e.push(s):n.push(s)}),e.forEach(s=>{fw.findEdgeRingContaining(s,n)&&n.push(s)}),ae(n.map(s=>s.toPolygon()))}function yA(i,t){var e=i[0]-t[0],n=i[1]-t[1];return e*e+n*n}function _A(i,t,e){var n=t[0],s=t[1],r=e[0]-n,o=e[1]-s;if(r!==0||o!==0){var a=((i[0]-n)*r+(i[1]-s)*o)/(r*r+o*o);a>1?(n=e[0],s=e[1]):a>0&&(n+=r*a,s+=o*a)}return r=i[0]-n,o=i[1]-s,r*r+o*o}function vA(i,t){for(var e=i[0],n=[e],s,r=1,o=i.length;r<o;r++)s=i[r],yA(s,e)>t&&(n.push(s),e=s);return e!==s&&n.push(s),n}function im(i,t,e,n,s){for(var r=n,o,a=t+1;a<e;a++){var l=_A(i[a],i[t],i[e]);l>r&&(o=a,r=l)}r>n&&(o-t>1&&im(i,t,o,n,s),s.push(i[o]),e-o>1&&im(i,o,e,n,s))}function EA(i,t){var e=i.length-1,n=[i[0]];return im(i,0,e,t,n),n.push(i[e]),n}function af(i,t,e){if(i.length<=2)return i;var n=t!==void 0?t*t:1;return i=e?i:vA(i,n),i=EA(i,n),i}function wA(i,t={}){var e,n,s;if(t=t??{},!NE(t))throw new Error("options is invalid");const r=(e=t.tolerance)!=null?e:1,o=(n=t.highQuality)!=null?n:!1,a=(s=t.mutate)!=null?s:!1;if(!i)throw new Error("geojson is required");if(r&&r<0)throw new Error("invalid tolerance");return a!==!0&&(i=Ye(i)),Wr(i,function(l){xA(l,r,o)}),i}function xA(i,t,e){const n=i.type;if(n==="Point"||n==="MultiPoint")return i;if(Ta(i,{mutate:!0}),n!=="GeometryCollection")switch(n){case"LineString":i.coordinates=af(i.coordinates,t,e);break;case"MultiLineString":i.coordinates=i.coordinates.map(s=>af(s,t,e));break;case"Polygon":i.coordinates=f_(i.coordinates,t,e);break;case"MultiPolygon":i.coordinates=i.coordinates.map(s=>f_(s,t,e))}return i}function f_(i,t,e){return i.map(function(n){if(n.length<4)throw new Error("invalid polygon");let s=t,r=af(n,s,e);for(;!d_(r)&&s>=Number.EPSILON;)s-=s*.01,r=af(n,s,e);return d_(r)?((r[r.length-1][0]!==r[0][0]||r[r.length-1][1]!==r[0][1])&&r.push(r[0]),r):n})}function d_(i){return i.length<3?!1:!(i.length===3&&i[2][0]===i[0][0]&&i[2][1]===i[0][1])}function gw(i,t={}){const e=[];if(Wr(i,s=>{e.push(s.coordinates)}),e.length<2)throw new Error("Must have at least 2 geometries");const n=HR(e[0],...e.slice(1));return n.length===0?null:n.length===1?Ce(n[0],t.properties):bo(n,t.properties)}let g_=0;function lf(){const i=globalThis.crypto;return i&&typeof i.randomUUID=="function"?`f_${i.randomUUID()}`:(g_+=1,`f_${Date.now().toString(36)}_${g_.toString(36)}_${Math.random().toString(36).slice(2,10)}`)}function m_(i,t){if(!i.geometry)return null;const[e,n,s,r]=De(i);return[e,n,s,r].every(Number.isFinite)?{minX:e,minY:n,maxX:s,maxY:r,key:t}:null}class Yf{constructor(t,e=[]){Y(this,"id");Y(this,"name");Y(this,"type");Y(this,"zIndex");Y(this,"visible");Y(this,"opacity");Y(this,"pinned");Y(this,"tag");Y(this,"groupId");Y(this,"sourceCrs");Y(this,"sourceFile");Y(this,"fields");Y(this,"featuresMap",new Map);Y(this,"spatialIndex",new ha);Y(this,"indexItems",new Map);Y(this,"cachedFieldStats",new Map);this.id=t.id,this.name=t.name||t.id,this.type=t.type||"polygon",this.zIndex=t.zIndex??0,this.visible=t.visible??!0,this.opacity=t.opacity??1,this.pinned=t.pinned??!1,this.tag=t.tag,this.groupId=t.groupId,this.sourceCrs=t.sourceCrs,this.sourceFile=t.sourceFile,this.fields=t.fields,e.length>0&&this.setFeatures(e)}getFeatures(){return Array.from(this.featuresMap.values())}get count(){return this.featuresMap.size}resolveKey(t){if(this.featuresMap.has(t))return t;if(typeof t=="number"){const n=String(t);return this.featuresMap.has(n)?n:void 0}const e=Number(t);if(t.trim()!==""&&Number.isFinite(e)&&String(e)===t&&this.featuresMap.has(e))return e}getFeature(t){const e=this.resolveKey(t);return e===void 0?void 0:this.featuresMap.get(e)}hasFeature(t){return this.resolveKey(t)!==void 0}getAvailableId(t){if(t==null||t===""){let n=lf();for(;this.hasFeature(n);)n=lf();return n}if(!this.hasFeature(t))return t;let e=2;for(;this.hasFeature(`${t}_${e}`);)e++;return`${t}_${e}`}addFeature(t){const e=Ye(t);let n;if(e.id!==void 0&&e.id!==null){if(this.hasFeature(e.id))throw new zv(e.id,this.id);n=e.id}else n=this.getAvailableId();return e.id=n,e.properties=e.properties||{},e.properties._ofs_id=n,this.featuresMap.set(n,e),this.indexFeature(n,e),this.invalidateCache(),e}addFeatures(t){return t.map(e=>this.addFeature(e))}updateFeature(t){if(t.id===void 0||t.id===null)return!1;const e=this.resolveKey(t.id);if(e===void 0)return!1;const n=e,s=Ye(t);return s.id=n,s.properties=s.properties||{},s.properties._ofs_id=n,this.featuresMap.set(n,s),this.indexFeature(n,s),this.invalidateCache(),!0}updateProperties(t,e){const n=this.resolveKey(t);if(n===void 0)return null;const s=this.featuresMap.get(n),r={...s.properties??{}};for(const[a,l]of Object.entries(e))l===void 0?delete r[a]:r[a]=l;r._ofs_id=n;const o={...s,properties:r};return this.featuresMap.set(n,o),this.invalidateCache(),o}removeFeature(t){const e=this.resolveKey(t),n=e!==void 0&&this.featuresMap.delete(e);return n&&(this.unindexFeature(e),this.invalidateCache()),n}setFeatures(t){this.featuresMap.clear(),this.indexItems.clear(),this.spatialIndex.clear();const e=[];t.forEach(n=>{const s=Ye(n);let r;s.id===void 0||s.id===null?r=this.getAvailableId():this.hasFeature(s.id)?(r=this.getAvailableId(s.id),console.warn(`[OFSLayerData] Duplicate feature id "${s.id}" in layer "${this.id}" renamed to "${r}".`)):r=s.id,s.id=r,s.properties=s.properties||{},s.properties._ofs_id=r,this.featuresMap.set(r,s);const o=m_(s,r);o&&(this.indexItems.set(r,o),e.push(o))}),this.spatialIndex.load(e),this.invalidateCache()}clear(){this.featuresMap.clear(),this.indexItems.clear(),this.spatialIndex.clear(),this.invalidateCache()}toGeoJSON(){return{type:"FeatureCollection",features:this.getFeatures().map(t=>{const e=Ye(t);return e.properties=e.properties||{},e.id!==void 0&&e.id!==null&&(e.properties._ofs_id=e.id,e.properties.id===void 0&&(e.properties.id=e.id)),e})}}getBoundingBox(){if(this.indexItems.size===0)return[0,0,0,0];const t=this.spatialIndex.toJSON();return[t.minX,t.minY,t.maxX,t.maxY]}queryBBox(t){const[e,n,s,r]=t;return this.spatialIndex.search({minX:e,minY:n,maxX:s,maxY:r}).map(o=>this.featuresMap.get(o.key)).filter(o=>!!o)}queryNear(t,e){return this.queryBBox([t[0]-e,t[1]-e,t[0]+e,t[1]+e])}indexFeature(t,e){this.unindexFeature(t);const n=m_(e,t);n&&(this.spatialIndex.insert(n),this.indexItems.set(t,n))}unindexFeature(t){const e=this.indexItems.get(t);e&&(this.spatialIndex.remove(e),this.indexItems.delete(t))}getPropertyFields(){const t=new Map;for(const e of this.featuresMap.values())if(e.properties){for(const[n,s]of Object.entries(e.properties))if(s!=null){const r=typeof s;(r==="number"||r==="string"||r==="boolean")&&t.set(n,r)}}return Array.from(t.entries()).map(([e,n])=>({name:e,type:n}))}getNumericFieldStats(t){var l;if(this.cachedFieldStats.has(t))return this.cachedFieldStats.get(t);const e=[];for(const h of this.featuresMap.values()){const f=(l=h.properties)==null?void 0:l[t];typeof f=="number"&&Number.isFinite(f)&&e.push(f)}if(e.length===0)return null;const n=Math.min(...e),s=Math.max(...e),r=e.reduce((h,f)=>h+f,0),o=r/e.length,a={min:n,max:s,mean:o,sum:r,count:e.length};return this.cachedFieldStats.set(t,a),a}getCategoricalFieldStats(t){var r;if(this.cachedFieldStats.has(t))return this.cachedFieldStats.get(t);const e={};for(const o of this.featuresMap.values()){const a=(r=o.properties)==null?void 0:r[t];if(a!=null){const l=String(a);e[l]=(e[l]||0)+1}}const n=Object.keys(e);if(n.length===0)return null;const s={distinctValues:n,frequencies:e};return this.cachedFieldStats.set(t,s),s}invalidateCache(){this.cachedFieldStats.clear()}}class mw{constructor(t=50){Y(this,"undoStack",[]);Y(this,"redoStack",[]);Y(this,"maxHistory");Y(this,"groupStack",[]);this.maxHistory=t}record(t){const e=this.groupStack[this.groupStack.length-1];if(e){e.steps.push(t);return}this.undoStack.push(t),this.undoStack.length>this.maxHistory&&this.undoStack.shift(),this.redoStack=[]}beginGroup(t){this.groupStack.push({description:t,steps:[]})}commitGroup(){const t=this.groupStack.pop();if(!t||t.steps.length===0)return;const e=t.steps,n=e.length===1?{...e[0],description:t.description}:{description:t.description,undo:()=>{for(let s=e.length-1;s>=0;s--)e[s].undo()},redo:()=>{e.forEach(s=>s.redo())}};this.record(n)}rollbackGroup(){const t=this.groupStack.pop();if(t)for(let e=t.steps.length-1;e>=0;e--)t.steps[e].undo()}isGrouping(){return this.groupStack.length>0}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}undo(){const t=this.undoStack.pop();return t?(t.undo(),this.redoStack.push(t),t.description):null}redo(){const t=this.redoStack.pop();return t?(t.redo(),this.undoStack.push(t),t.description):null}clear(){this.undoStack=[],this.redoStack=[]}getUndoDescriptions(){return this.undoStack.map(t=>t.description)}getRedoDescriptions(){return this.redoStack.map(t=>t.description)}}const bA=1e-4;function ug(i,t){return i instanceof Yf?i.queryBBox(t):i}class Ro{static queryBBox(t,e){const[n,s,r,o]=e,a=Wm(e);return ug(t,e).filter(l=>{if(!l.geometry)return!1;const h=De(l);return h[2]<n||h[0]>r||h[3]<s||h[1]>o?!1:Ro.intersectsSafely(l,a)})}static queryGeometry(t,e){const n=De(e);return ug(t,n).filter(s=>s.geometry?s.geometry.type==="Point"?Ht(s.geometry.coordinates,e):Ro.intersectsSafely(s,e):!1)}static queryPoint(t,e){const n=St(e),s=bA,r=[e[0]-s,e[1]-s,e[0]+s,e[1]+s];return ug(t,r).filter(o=>{if(!o.geometry)return!1;const a=o.geometry.type;if(a==="Polygon"||a==="MultiPolygon")return Ht(n,o);if(a==="Point"){const l=o.geometry.coordinates;return Math.abs(l[0]-e[0])<s&&Math.abs(l[1]-e[1])<s}return!1})}static findNearest(t,e){const n=t instanceof Yf?t.getFeatures():t;if(n.length===0)return null;const s=St(e);let r=null,o=1/0;for(const a of n){if(!a.geometry)continue;let l=1/0;if(a.geometry.type==="Point")l=nn(s,a,{units:"meters"});else{const h=Io(a);l=nn(s,h,{units:"meters"})}l<o&&(o=l,r=a)}return r?{feature:r,distanceMeters:o}:null}static intersectsSafely(t,e){try{return To(t,e)}catch(n){return console.warn(`[SpatialIndexHelper] Intersection test failed for feature "${t.id}", treating as bbox hit:`,n),!0}}}function Ot(i,t){return i.interfaces_&&i.interfaces_.indexOf(t)>-1}class vo{constructor(t,e){this.low=e||0,this.high=t||0}static toBinaryString(t){let e,n="";for(e=2147483648;e>0;e>>>=1)n+=(t.high&e)===e?"1":"0";for(e=2147483648;e>0;e>>>=1)n+=(t.low&e)===e?"1":"0";return n}}function Rt(){}Rt.NaN=NaN;Rt.isNaN=i=>Number.isNaN(i);Rt.isInfinite=i=>!Number.isFinite(i);Rt.MAX_VALUE=Number.MAX_VALUE;Rt.POSITIVE_INFINITY=Number.POSITIVE_INFINITY;Rt.NEGATIVE_INFINITY=Number.NEGATIVE_INFINITY;typeof Float64Array=="function"&&typeof Int32Array=="function"?(function(){const e=new Float64Array(1),n=new Int32Array(e.buffer);Rt.doubleToLongBits=function(s){e[0]=s;let r=n[0]|0,o=n[1]|0;return(o&2146435072)===2146435072&&(o&1048575)!==0&&r!==0&&(r=0,o=2146959360),new vo(o,r)},Rt.longBitsToDouble=function(s){return n[0]=s.low,n[1]=s.high,e[0]}})():(function(){const t=Math.log2,e=Math.floor,n=Math.pow,s=(function(){for(let r=53;r>0;r--){const o=n(2,r)-1;if(e(t(o))+1===r)return o}return 0})();Rt.doubleToLongBits=function(r){let o,a,l,h,f,d,p,y,_;if(r<0||1/r===Number.NEGATIVE_INFINITY?(d=1<<31,r=-r):d=0,r===0)return _=0,y=d,new vo(y,_);if(r===1/0)return _=0,y=d|2146435072,new vo(y,_);if(r!==r)return _=0,y=2146959360,new vo(y,_);if(h=0,_=0,o=e(r),o>1)if(o<=s)h=e(t(o)),h<=20?(_=0,y=o<<20-h&1048575):(l=h-20,a=n(2,l),_=o%a<<32-l,y=o/a&1048575);else for(l=o,_=0;a=l/2,l=e(a),l!==0;)h++,_>>>=1,_|=(y&1)<<31,y>>>=1,a!==l&&(y|=524288);if(p=h+1023,f=o===0,o=r-o,h<52&&o!==0)for(l=0;;){if(a=o*2,a>=1?(o=a-1,f?(p--,f=!1):(l<<=1,l|=1,h++)):(o=a,f?--p===0&&(h++,f=!1):(l<<=1,h++)),h===20)y|=l,l=0;else if(h===52){_|=l;break}if(a===1){h<20?y|=l<<20-h:h<52&&(_|=l<<52-h);break}}return y|=p<<20,y|=d,new vo(y,_)},Rt.longBitsToDouble=function(r){let o,a,l,h;const f=r.high,d=r.low,p=f&1<<31?-1:1;for(l=((f&2146435072)>>20)-1023,h=0,a=1<<19,o=1;o<=20;o++)f&a&&(h+=n(2,-o)),a>>>=1;for(a=1<<31,o=21;o<=52;o++)d&a&&(h+=n(2,-o)),a>>>=1;if(l===-1023){if(h===0)return p*0;l=-1022}else{if(l===1024)return h===0?p/0:NaN;h+=1}return p*h*n(2,l)}})();function yc(){}class de{getM(t){if(this.hasM()){const e=this.getDimension()-this.getMeasures();return this.getOrdinate(t,e)}else return Rt.NaN}setOrdinate(t,e,n){}getZ(t){return this.hasZ()?this.getOrdinate(t,2):Rt.NaN}size(){}getOrdinate(t,e){}getCoordinate(){}getCoordinateCopy(t){}createCoordinate(){}getDimension(){}hasM(){return this.getMeasures()>0}getX(t){}hasZ(){return this.getDimension()-this.getMeasures()>2}getMeasures(){return 0}expandEnvelope(t){}copy(){}getY(t){}toCoordinateArray(){}get interfaces_(){return[yc]}}de.X=0;de.Y=1;de.Z=2;de.M=3;class pw{create(){if(arguments.length===1)arguments[0]instanceof Array||Ot(arguments[0],de);else if(arguments.length!==2){if(arguments.length===3){const t=arguments[0],e=arguments[1];return this.create(t,e)}}}}class Is extends Error{constructor(t){super(t),this.name=Object.keys({Exception:Is})[0]}toString(){return this.message}}class Zt extends Is{constructor(t){super(t),this.name=Object.keys({IllegalArgumentException:Zt})[0]}}class pl{filter(t){}}function gi(){}function mi(){}class cg{static equalsWithTolerance(t,e,n){return Math.abs(t-e)<=n}}function Kr(){}class ui extends Is{constructor(t){super(t),this.name=Object.keys({RuntimeException:ui})[0]}}class Ia extends ui{constructor(){super(),Ia.constructor_.apply(this,arguments)}static constructor_(){if(arguments.length===0)ui.constructor_.call(this);else if(arguments.length===1){const t=arguments[0];ui.constructor_.call(this,t)}}}class Yt{static shouldNeverReachHere(){if(arguments.length===0)Yt.shouldNeverReachHere(null);else if(arguments.length===1){const t=arguments[0];throw new Ia("Should never reach here"+(t!==null?": "+t:""))}}static isTrue(){if(arguments.length===1){const t=arguments[0];Yt.isTrue(t,null)}else if(arguments.length===2){const t=arguments[0],e=arguments[1];if(!t)throw e===null?new Ia:new Ia(e)}}static equals(){if(arguments.length===2){const t=arguments[0],e=arguments[1];Yt.equals(t,e,null)}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];if(!e.equals(t))throw new Ia("Expected "+t+" but encountered "+e+(n!==null?": "+n:""))}}}const yw=new ArrayBuffer(8),IA=new Float64Array(yw),p_=new Int32Array(yw);class Z{constructor(){Z.constructor_.apply(this,arguments)}static constructor_(){if(this.x=null,this.y=null,this.z=null,arguments.length===0)Z.constructor_.call(this,0,0);else if(arguments.length===1){const t=arguments[0];Z.constructor_.call(this,t.x,t.y,t.getZ())}else if(arguments.length===2){const t=arguments[0],e=arguments[1];Z.constructor_.call(this,t,e,Z.NULL_ORDINATE)}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];this.x=t,this.y=e,this.z=n}}static hashCode(t){return IA[0]=t,p_[0]^p_[1]}getM(){return Rt.NaN}setOrdinate(t,e){switch(t){case Z.X:this.x=e;break;case Z.Y:this.y=e;break;case Z.Z:this.setZ(e);break;default:throw new Zt("Invalid ordinate index: "+t)}}equals2D(){if(arguments.length===1){const t=arguments[0];return!(this.x!==t.x||this.y!==t.y)}else if(arguments.length===2){const t=arguments[0],e=arguments[1];return!(!cg.equalsWithTolerance(this.x,t.x,e)||!cg.equalsWithTolerance(this.y,t.y,e))}}setM(t){throw new Zt("Invalid ordinate index: "+Z.M)}getZ(){return this.z}getOrdinate(t){switch(t){case Z.X:return this.x;case Z.Y:return this.y;case Z.Z:return this.getZ()}throw new Zt("Invalid ordinate index: "+t)}equals3D(t){return this.x===t.x&&this.y===t.y&&(this.getZ()===t.getZ()||Rt.isNaN(this.getZ())&&Rt.isNaN(t.getZ()))}equals(t){return t instanceof Z?this.equals2D(t):!1}equalInZ(t,e){return cg.equalsWithTolerance(this.getZ(),t.getZ(),e)}setX(t){this.x=t}compareTo(t){const e=t;return this.x<e.x?-1:this.x>e.x?1:this.y<e.y?-1:this.y>e.y?1:0}getX(){return this.x}setZ(t){this.z=t}clone(){try{return null}catch(t){if(t instanceof CloneNotSupportedException)return Yt.shouldNeverReachHere("this shouldn't happen because this class is Cloneable"),null;throw t}finally{}}copy(){return new Z(this)}toString(){return"("+this.x+", "+this.y+", "+this.getZ()+")"}distance3D(t){const e=this.x-t.x,n=this.y-t.y,s=this.getZ()-t.getZ();return Math.sqrt(e*e+n*n+s*s)}getY(){return this.y}setY(t){this.y=t}distance(t){const e=this.x-t.x,n=this.y-t.y;return Math.sqrt(e*e+n*n)}hashCode(){let t=17;return t=37*t+Z.hashCode(this.x),t=37*t+Z.hashCode(this.y),t}setCoordinate(t){this.x=t.x,this.y=t.y,this.z=t.getZ()}get interfaces_(){return[gi,yc,mi]}}class Eo{constructor(){Eo.constructor_.apply(this,arguments)}static constructor_(){if(this._dimensionsToTest=2,arguments.length===0)Eo.constructor_.call(this,2);else if(arguments.length===1){const t=arguments[0];if(t!==2&&t!==3)throw new Zt("only 2 or 3 dimensions may be specified");this._dimensionsToTest=t}}static compare(t,e){return t<e?-1:t>e?1:Rt.isNaN(t)?Rt.isNaN(e)?0:-1:Rt.isNaN(e)?1:0}compare(t,e){const n=Eo.compare(t.x,e.x);if(n!==0)return n;const s=Eo.compare(t.y,e.y);return s!==0?s:this._dimensionsToTest<=2?0:Eo.compare(t.getZ(),e.getZ())}get interfaces_(){return[Kr]}}Z.DimensionalComparator=Eo;Z.NULL_ORDINATE=Rt.NaN;Z.X=0;Z.Y=1;Z.Z=2;Z.M=3;class te{constructor(){te.constructor_.apply(this,arguments)}static constructor_(){if(this._minx=null,this._maxx=null,this._miny=null,this._maxy=null,arguments.length===0)this.init();else if(arguments.length===1){if(arguments[0]instanceof Z){const t=arguments[0];this.init(t.x,t.x,t.y,t.y)}else if(arguments[0]instanceof te){const t=arguments[0];this.init(t)}}else if(arguments.length===2){const t=arguments[0],e=arguments[1];this.init(t.x,e.x,t.y,e.y)}else if(arguments.length===4){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3];this.init(t,e,n,s)}}static intersects(){if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];return n.x>=(t.x<e.x?t.x:e.x)&&n.x<=(t.x>e.x?t.x:e.x)&&n.y>=(t.y<e.y?t.y:e.y)&&n.y<=(t.y>e.y?t.y:e.y)}else if(arguments.length===4){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3];let r=Math.min(n.x,s.x),o=Math.max(n.x,s.x),a=Math.min(t.x,e.x),l=Math.max(t.x,e.x);return!(a>o||l<r||(r=Math.min(n.y,s.y),o=Math.max(n.y,s.y),a=Math.min(t.y,e.y),l=Math.max(t.y,e.y),a>o)||l<r)}}getArea(){return this.getWidth()*this.getHeight()}equals(t){if(!(t instanceof te))return!1;const e=t;return this.isNull()?e.isNull():this._maxx===e.getMaxX()&&this._maxy===e.getMaxY()&&this._minx===e.getMinX()&&this._miny===e.getMinY()}intersection(t){if(this.isNull()||t.isNull()||!this.intersects(t))return new te;const e=this._minx>t._minx?this._minx:t._minx,n=this._miny>t._miny?this._miny:t._miny,s=this._maxx<t._maxx?this._maxx:t._maxx,r=this._maxy<t._maxy?this._maxy:t._maxy;return new te(e,s,n,r)}isNull(){return this._maxx<this._minx}getMaxX(){return this._maxx}covers(){if(arguments.length===1){if(arguments[0]instanceof Z){const t=arguments[0];return this.covers(t.x,t.y)}else if(arguments[0]instanceof te){const t=arguments[0];return this.isNull()||t.isNull()?!1:t.getMinX()>=this._minx&&t.getMaxX()<=this._maxx&&t.getMinY()>=this._miny&&t.getMaxY()<=this._maxy}}else if(arguments.length===2){const t=arguments[0],e=arguments[1];return this.isNull()?!1:t>=this._minx&&t<=this._maxx&&e>=this._miny&&e<=this._maxy}}intersects(){if(arguments.length===1){if(arguments[0]instanceof te){const t=arguments[0];return this.isNull()||t.isNull()?!1:!(t._minx>this._maxx||t._maxx<this._minx||t._miny>this._maxy||t._maxy<this._miny)}else if(arguments[0]instanceof Z){const t=arguments[0];return this.intersects(t.x,t.y)}}else if(arguments.length===2){if(arguments[0]instanceof Z&&arguments[1]instanceof Z){const t=arguments[0],e=arguments[1];return!(this.isNull()||(t.x<e.x?t.x:e.x)>this._maxx||(t.x>e.x?t.x:e.x)<this._minx||(t.y<e.y?t.y:e.y)>this._maxy||(t.y>e.y?t.y:e.y)<this._miny)}else if(typeof arguments[0]=="number"&&typeof arguments[1]=="number"){const t=arguments[0],e=arguments[1];return this.isNull()?!1:!(t>this._maxx||t<this._minx||e>this._maxy||e<this._miny)}}}getMinY(){return this._miny}getDiameter(){if(this.isNull())return 0;const t=this.getWidth(),e=this.getHeight();return Math.sqrt(t*t+e*e)}getMinX(){return this._minx}expandToInclude(){if(arguments.length===1){if(arguments[0]instanceof Z){const t=arguments[0];this.expandToInclude(t.x,t.y)}else if(arguments[0]instanceof te){const t=arguments[0];if(t.isNull())return null;this.isNull()?(this._minx=t.getMinX(),this._maxx=t.getMaxX(),this._miny=t.getMinY(),this._maxy=t.getMaxY()):(t._minx<this._minx&&(this._minx=t._minx),t._maxx>this._maxx&&(this._maxx=t._maxx),t._miny<this._miny&&(this._miny=t._miny),t._maxy>this._maxy&&(this._maxy=t._maxy))}}else if(arguments.length===2){const t=arguments[0],e=arguments[1];this.isNull()?(this._minx=t,this._maxx=t,this._miny=e,this._maxy=e):(t<this._minx&&(this._minx=t),t>this._maxx&&(this._maxx=t),e<this._miny&&(this._miny=e),e>this._maxy&&(this._maxy=e))}}minExtent(){if(this.isNull())return 0;const t=this.getWidth(),e=this.getHeight();return t<e?t:e}getWidth(){return this.isNull()?0:this._maxx-this._minx}compareTo(t){const e=t;return this.isNull()?e.isNull()?0:-1:e.isNull()?1:this._minx<e._minx?-1:this._minx>e._minx?1:this._miny<e._miny?-1:this._miny>e._miny?1:this._maxx<e._maxx?-1:this._maxx>e._maxx?1:this._maxy<e._maxy?-1:this._maxy>e._maxy?1:0}translate(t,e){if(this.isNull())return null;this.init(this.getMinX()+t,this.getMaxX()+t,this.getMinY()+e,this.getMaxY()+e)}copy(){return new te(this)}toString(){return"Env["+this._minx+" : "+this._maxx+", "+this._miny+" : "+this._maxy+"]"}setToNull(){this._minx=0,this._maxx=-1,this._miny=0,this._maxy=-1}disjoint(t){return this.isNull()||t.isNull()?!0:t._minx>this._maxx||t._maxx<this._minx||t._miny>this._maxy||t._maxy<this._miny}getHeight(){return this.isNull()?0:this._maxy-this._miny}maxExtent(){if(this.isNull())return 0;const t=this.getWidth(),e=this.getHeight();return t>e?t:e}expandBy(){if(arguments.length===1){const t=arguments[0];this.expandBy(t,t)}else if(arguments.length===2){const t=arguments[0],e=arguments[1];if(this.isNull())return null;this._minx-=t,this._maxx+=t,this._miny-=e,this._maxy+=e,(this._minx>this._maxx||this._miny>this._maxy)&&this.setToNull()}}contains(){if(arguments.length===1){if(arguments[0]instanceof te){const t=arguments[0];return this.covers(t)}else if(arguments[0]instanceof Z){const t=arguments[0];return this.covers(t)}}else if(arguments.length===2){const t=arguments[0],e=arguments[1];return this.covers(t,e)}}centre(){return this.isNull()?null:new Z((this.getMinX()+this.getMaxX())/2,(this.getMinY()+this.getMaxY())/2)}init(){if(arguments.length===0)this.setToNull();else if(arguments.length===1){if(arguments[0]instanceof Z){const t=arguments[0];this.init(t.x,t.x,t.y,t.y)}else if(arguments[0]instanceof te){const t=arguments[0];this._minx=t._minx,this._maxx=t._maxx,this._miny=t._miny,this._maxy=t._maxy}}else if(arguments.length===2){const t=arguments[0],e=arguments[1];this.init(t.x,e.x,t.y,e.y)}else if(arguments.length===4){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3];t<e?(this._minx=t,this._maxx=e):(this._minx=e,this._maxx=t),n<s?(this._miny=n,this._maxy=s):(this._miny=s,this._maxy=n)}}getMaxY(){return this._maxy}distance(t){if(this.intersects(t))return 0;let e=0;this._maxx<t._minx?e=t._minx-this._maxx:this._minx>t._maxx&&(e=this._minx-t._maxx);let n=0;return this._maxy<t._miny?n=t._miny-this._maxy:this._miny>t._maxy&&(n=this._miny-t._maxy),e===0?n:n===0?e:Math.sqrt(e*e+n*n)}hashCode(){let t=17;return t=37*t+Z.hashCode(this._minx),t=37*t+Z.hashCode(this._maxx),t=37*t+Z.hashCode(this._miny),t=37*t+Z.hashCode(this._maxy),t}get interfaces_(){return[gi,mi]}}class dt{constructor(){dt.constructor_.apply(this,arguments)}isGeometryCollection(){return this.getTypeCode()===dt.TYPECODE_GEOMETRYCOLLECTION}getFactory(){return this._factory}getGeometryN(t){return this}getArea(){return 0}isRectangle(){return!1}equalsExact(t){return this===t||this.equalsExact(t,0)}geometryChanged(){this.apply(dt.geometryChangedFilter)}geometryChangedAction(){this._envelope=null}equalsNorm(t){return t===null?!1:this.norm().equalsExact(t.norm())}getLength(){return 0}getNumGeometries(){return 1}compareTo(){let t;if(arguments.length===1){const e=arguments[0];return t=e,this.getTypeCode()!==t.getTypeCode()?this.getTypeCode()-t.getTypeCode():this.isEmpty()&&t.isEmpty()?0:this.isEmpty()?-1:t.isEmpty()?1:this.compareToSameClass(e)}else if(arguments.length===2){const e=arguments[0],n=arguments[1];return t=e,this.getTypeCode()!==t.getTypeCode()?this.getTypeCode()-t.getTypeCode():this.isEmpty()&&t.isEmpty()?0:this.isEmpty()?-1:t.isEmpty()?1:this.compareToSameClass(e,n)}}getUserData(){return this._userData}getSRID(){return this._SRID}getEnvelope(){return this.getFactory().toGeometry(this.getEnvelopeInternal())}checkNotGeometryCollection(t){if(t.getTypeCode()===dt.TYPECODE_GEOMETRYCOLLECTION)throw new Zt("This method does not support GeometryCollection arguments")}equal(t,e,n){return n===0?t.equals(e):t.distance(e)<=n}norm(){const t=this.copy();return t.normalize(),t}reverse(){const t=this.reverseInternal();return this.envelope!=null&&(t.envelope=this.envelope.copy()),t.setSRID(this.getSRID()),t}copy(){const t=this.copyInternal();return t.envelope=this._envelope==null?null:this._envelope.copy(),t._SRID=this._SRID,t._userData=this._userData,t}getPrecisionModel(){return this._factory.getPrecisionModel()}getEnvelopeInternal(){return this._envelope===null&&(this._envelope=this.computeEnvelopeInternal()),new te(this._envelope)}setSRID(t){this._SRID=t}setUserData(t){this._userData=t}compare(t,e){const n=t.iterator(),s=e.iterator();for(;n.hasNext()&&s.hasNext();){const r=n.next(),o=s.next(),a=r.compareTo(o);if(a!==0)return a}return n.hasNext()?1:s.hasNext()?-1:0}hashCode(){return this.getEnvelopeInternal().hashCode()}isEquivalentClass(t){return this.getClass()===t.getClass()}isGeometryCollectionOrDerived(){return this.getTypeCode()===dt.TYPECODE_GEOMETRYCOLLECTION||this.getTypeCode()===dt.TYPECODE_MULTIPOINT||this.getTypeCode()===dt.TYPECODE_MULTILINESTRING||this.getTypeCode()===dt.TYPECODE_MULTIPOLYGON}get interfaces_(){return[yc,gi,mi]}getClass(){return dt}static hasNonEmptyElements(t){for(let e=0;e<t.length;e++)if(!t[e].isEmpty())return!0;return!1}static hasNullElements(t){for(let e=0;e<t.length;e++)if(t[e]===null)return!0;return!1}}dt.constructor_=function(i){i&&(this._envelope=null,this._userData=null,this._factory=i,this._SRID=i.getSRID())};dt.TYPECODE_POINT=0;dt.TYPECODE_MULTIPOINT=1;dt.TYPECODE_LINESTRING=2;dt.TYPECODE_LINEARRING=3;dt.TYPECODE_MULTILINESTRING=4;dt.TYPECODE_POLYGON=5;dt.TYPECODE_MULTIPOLYGON=6;dt.TYPECODE_GEOMETRYCOLLECTION=7;dt.TYPENAME_POINT="Point";dt.TYPENAME_MULTIPOINT="MultiPoint";dt.TYPENAME_LINESTRING="LineString";dt.TYPENAME_LINEARRING="LinearRing";dt.TYPENAME_MULTILINESTRING="MultiLineString";dt.TYPENAME_POLYGON="Polygon";dt.TYPENAME_MULTIPOLYGON="MultiPolygon";dt.TYPENAME_GEOMETRYCOLLECTION="GeometryCollection";dt.geometryChangedFilter={get interfaces_(){return[pl]},filter(i){i.geometryChangedAction()}};class yl{filter(t){}}class SA{static ofLine(t){const e=t.size();if(e<=1)return 0;let n=0;const s=new Z;t.getCoordinate(0,s);let r=s.x,o=s.y;for(let a=1;a<e;a++){t.getCoordinate(a,s);const l=s.x,h=s.y,f=l-r,d=h-o;n+=Math.sqrt(f*f+d*d),r=l,o=h}return n}}class _w{}class tn{static copyCoord(t,e,n,s){const r=Math.min(t.getDimension(),n.getDimension());for(let o=0;o<r;o++)n.setOrdinate(s,o,t.getOrdinate(e,o))}static isRing(t){const e=t.size();return e===0?!0:e<=3?!1:t.getOrdinate(0,de.X)===t.getOrdinate(e-1,de.X)&&t.getOrdinate(0,de.Y)===t.getOrdinate(e-1,de.Y)}static scroll(){if(arguments.length===2){if(Ot(arguments[0],de)&&Number.isInteger(arguments[1])){const t=arguments[0],e=arguments[1];tn.scroll(t,e,tn.isRing(t))}else if(Ot(arguments[0],de)&&arguments[1]instanceof Z){const t=arguments[0],e=arguments[1],n=tn.indexOf(e,t);if(n<=0)return null;tn.scroll(t,n)}}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];if(e<=0)return null;const r=t.copy(),o=n?t.size()-1:t.size();for(let a=0;a<o;a++)for(let l=0;l<t.getDimension();l++)t.setOrdinate(a,l,r.getOrdinate((e+a)%o,l));if(n)for(let a=0;a<t.getDimension();a++)t.setOrdinate(o,a,t.getOrdinate(0,a))}}static isEqual(t,e){const n=t.size(),s=e.size();if(n!==s)return!1;const r=Math.min(t.getDimension(),e.getDimension());for(let o=0;o<n;o++)for(let a=0;a<r;a++){const l=t.getOrdinate(o,a),h=e.getOrdinate(o,a);if(t.getOrdinate(o,a)!==e.getOrdinate(o,a)&&!(Rt.isNaN(l)&&Rt.isNaN(h)))return!1}return!0}static minCoordinateIndex(){if(arguments.length===1){const t=arguments[0];return tn.minCoordinateIndex(t,0,t.size()-1)}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];let s=-1,r=null;for(let o=e;o<=n;o++){const a=t.getCoordinate(o);(r===null||r.compareTo(a)>0)&&(r=a,s=o)}return s}}static extend(t,e,n){const s=t.create(n,e.getDimension()),r=e.size();if(tn.copy(e,0,s,0,r),r>0)for(let o=r;o<n;o++)tn.copy(e,r-1,s,o,1);return s}static reverse(t){const e=t.size()-1,n=Math.trunc(e/2);for(let s=0;s<=n;s++)tn.swap(t,s,e-s)}static swap(t,e,n){if(e===n)return null;for(let s=0;s<t.getDimension();s++){const r=t.getOrdinate(e,s);t.setOrdinate(e,s,t.getOrdinate(n,s)),t.setOrdinate(n,s,r)}}static copy(t,e,n,s,r){for(let o=0;o<r;o++)tn.copyCoord(t,e+o,n,s+o)}static ensureValidRing(t,e){const n=e.size();return n===0?e:n<=3?tn.createClosedRing(t,e,4):e.getOrdinate(0,de.X)===e.getOrdinate(n-1,de.X)&&e.getOrdinate(0,de.Y)===e.getOrdinate(n-1,de.Y)?e:tn.createClosedRing(t,e,n+1)}static indexOf(t,e){for(let n=0;n<e.size();n++)if(t.x===e.getOrdinate(n,de.X)&&t.y===e.getOrdinate(n,de.Y))return n;return-1}static createClosedRing(t,e,n){const s=t.create(n,e.getDimension()),r=e.size();tn.copy(e,0,s,0,r);for(let o=r;o<n;o++)tn.copy(e,0,s,o,1);return s}static minCoordinate(t){let e=null;for(let n=0;n<t.size();n++){const s=t.getCoordinate(n);(e===null||e.compareTo(s)>0)&&(e=s)}return e}}class ss extends Is{constructor(t){super(t),this.name=Object.keys({UnsupportedOperationException:ss})[0]}}class sm{static isWhitespace(t){return t<=32&&t>=0||t===127}static toUpperCase(t){return t.toUpperCase()}}class pt{static toDimensionSymbol(t){switch(t){case pt.FALSE:return pt.SYM_FALSE;case pt.TRUE:return pt.SYM_TRUE;case pt.DONTCARE:return pt.SYM_DONTCARE;case pt.P:return pt.SYM_P;case pt.L:return pt.SYM_L;case pt.A:return pt.SYM_A}throw new Zt("Unknown dimension value: "+t)}static toDimensionValue(t){switch(sm.toUpperCase(t)){case pt.SYM_FALSE:return pt.FALSE;case pt.SYM_TRUE:return pt.TRUE;case pt.SYM_DONTCARE:return pt.DONTCARE;case pt.SYM_P:return pt.P;case pt.SYM_L:return pt.L;case pt.SYM_A:return pt.A}throw new Zt("Unknown dimension symbol: "+t)}}pt.P=0;pt.L=1;pt.A=2;pt.FALSE=-1;pt.TRUE=-2;pt.DONTCARE=-3;pt.SYM_FALSE="F";pt.SYM_TRUE="T";pt.SYM_DONTCARE="*";pt.SYM_P="0";pt.SYM_L="1";pt.SYM_A="2";class Zr{filter(t){}}class _l{filter(t,e){}isDone(){}isGeometryChanged(){}}class ce extends dt{constructor(){super(),ce.constructor_.apply(this,arguments)}static constructor_(){if(this._points=null,arguments.length!==0){if(arguments.length===2){const t=arguments[0],e=arguments[1];dt.constructor_.call(this,e),this.init(t)}}}computeEnvelopeInternal(){return this.isEmpty()?new te:this._points.expandEnvelope(new te)}isRing(){return this.isClosed()&&this.isSimple()}getCoordinates(){return this._points.toCoordinateArray()}copyInternal(){return new ce(this._points.copy(),this._factory)}equalsExact(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof dt){const t=arguments[0],e=arguments[1];if(!this.isEquivalentClass(t))return!1;const n=t;if(this._points.size()!==n._points.size())return!1;for(let s=0;s<this._points.size();s++)if(!this.equal(this._points.getCoordinate(s),n._points.getCoordinate(s),e))return!1;return!0}else return super.equalsExact.apply(this,arguments)}normalize(){for(let t=0;t<Math.trunc(this._points.size()/2);t++){const e=this._points.size()-1-t;if(!this._points.getCoordinate(t).equals(this._points.getCoordinate(e))){if(this._points.getCoordinate(t).compareTo(this._points.getCoordinate(e))>0){const n=this._points.copy();tn.reverse(n),this._points=n}return null}}}getCoordinate(){return this.isEmpty()?null:this._points.getCoordinate(0)}getBoundaryDimension(){return this.isClosed()?pt.FALSE:0}isClosed(){return this.isEmpty()?!1:this.getCoordinateN(0).equals2D(this.getCoordinateN(this.getNumPoints()-1))}reverseInternal(){const t=this._points.copy();return tn.reverse(t),this.getFactory().createLineString(t)}getEndPoint(){return this.isEmpty()?null:this.getPointN(this.getNumPoints()-1)}getTypeCode(){return dt.TYPECODE_LINESTRING}getDimension(){return 1}getLength(){return SA.ofLine(this._points)}getNumPoints(){return this._points.size()}compareToSameClass(){if(arguments.length===1){const e=arguments[0];let n=0,s=0;for(;n<this._points.size()&&s<e._points.size();){const r=this._points.getCoordinate(n).compareTo(e._points.getCoordinate(s));if(r!==0)return r;n++,s++}return n<this._points.size()?1:s<e._points.size()?-1:0}else if(arguments.length===2){const t=arguments[0],e=arguments[1],n=t;return e.compare(this._points,n._points)}}apply(){if(Ot(arguments[0],yl)){const t=arguments[0];for(let e=0;e<this._points.size();e++)t.filter(this._points.getCoordinate(e))}else if(Ot(arguments[0],_l)){const t=arguments[0];if(this._points.size()===0)return null;for(let e=0;e<this._points.size()&&(t.filter(this._points,e),!t.isDone());e++);t.isGeometryChanged()&&this.geometryChanged()}else Ot(arguments[0],Zr)?arguments[0].filter(this):Ot(arguments[0],pl)&&arguments[0].filter(this)}getBoundary(){throw new ss}isEquivalentClass(t){return t instanceof ce}getCoordinateN(t){return this._points.getCoordinate(t)}getGeometryType(){return dt.TYPENAME_LINESTRING}getCoordinateSequence(){return this._points}isEmpty(){return this._points.size()===0}init(t){if(t===null&&(t=this.getFactory().getCoordinateSequenceFactory().create([])),t.size()===1)throw new Zt("Invalid number of points in LineString (found "+t.size()+" - must be 0 or >= 2)");this._points=t}isCoordinate(t){for(let e=0;e<this._points.size();e++)if(this._points.getCoordinate(e).equals(t))return!0;return!1}getStartPoint(){return this.isEmpty()?null:this.getPointN(0)}getPointN(t){return this.getFactory().createPoint(this._points.getCoordinate(t))}get interfaces_(){return[_w]}}class vw{}class Ge extends dt{constructor(){super(),Ge.constructor_.apply(this,arguments)}static constructor_(){this._coordinates=null;const t=arguments[0],e=arguments[1];dt.constructor_.call(this,e),this.init(t)}computeEnvelopeInternal(){if(this.isEmpty())return new te;const t=new te;return t.expandToInclude(this._coordinates.getX(0),this._coordinates.getY(0)),t}getCoordinates(){return this.isEmpty()?[]:[this.getCoordinate()]}copyInternal(){return new Ge(this._coordinates.copy(),this._factory)}equalsExact(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof dt){const t=arguments[0],e=arguments[1];return this.isEquivalentClass(t)?this.isEmpty()&&t.isEmpty()?!0:this.isEmpty()!==t.isEmpty()?!1:this.equal(t.getCoordinate(),this.getCoordinate(),e):!1}else return super.equalsExact.apply(this,arguments)}normalize(){}getCoordinate(){return this._coordinates.size()!==0?this._coordinates.getCoordinate(0):null}getBoundaryDimension(){return pt.FALSE}reverseInternal(){return this.getFactory().createPoint(this._coordinates.copy())}getTypeCode(){return dt.TYPECODE_POINT}getDimension(){return 0}getNumPoints(){return this.isEmpty()?0:1}getX(){if(this.getCoordinate()===null)throw new IllegalStateException("getX called on empty Point");return this.getCoordinate().x}compareToSameClass(){if(arguments.length===1){const e=arguments[0];return this.getCoordinate().compareTo(e.getCoordinate())}else if(arguments.length===2){const t=arguments[0],e=arguments[1],n=t;return e.compare(this._coordinates,n._coordinates)}}apply(){if(Ot(arguments[0],yl)){const t=arguments[0];if(this.isEmpty())return null;t.filter(this.getCoordinate())}else if(Ot(arguments[0],_l)){const t=arguments[0];if(this.isEmpty())return null;t.filter(this._coordinates,0),t.isGeometryChanged()&&this.geometryChanged()}else Ot(arguments[0],Zr)?arguments[0].filter(this):Ot(arguments[0],pl)&&arguments[0].filter(this)}getBoundary(){return this.getFactory().createGeometryCollection()}getGeometryType(){return dt.TYPENAME_POINT}getCoordinateSequence(){return this._coordinates}getY(){if(this.getCoordinate()===null)throw new IllegalStateException("getY called on empty Point");return this.getCoordinate().y}isEmpty(){return this._coordinates.size()===0}init(t){t===null&&(t=this.getFactory().getCoordinateSequenceFactory().create([])),Yt.isTrue(t.size()<=1),this._coordinates=t}isSimple(){return!0}get interfaces_(){return[vw]}}class Ou{static ofRing(){if(arguments[0]instanceof Array){const t=arguments[0];return Math.abs(Ou.ofRingSigned(t))}else if(Ot(arguments[0],de)){const t=arguments[0];return Math.abs(Ou.ofRingSigned(t))}}static ofRingSigned(){if(arguments[0]instanceof Array){const t=arguments[0];if(t.length<3)return 0;let e=0;const n=t[0].x;for(let s=1;s<t.length-1;s++){const r=t[s].x-n,o=t[s+1].y,a=t[s-1].y;e+=r*(a-o)}return e/2}else if(Ot(arguments[0],de)){const t=arguments[0],e=t.size();if(e<3)return 0;const n=new Z,s=new Z,r=new Z;t.getCoordinate(0,s),t.getCoordinate(1,r);const o=s.x;r.x-=o;let a=0;for(let l=1;l<e-1;l++)n.y=s.y,s.x=r.x,s.y=r.y,t.getCoordinate(l+1,r),r.x-=o,a+=s.x*(n.y-r.y);return a/2}}}class sn{add(){}addAll(){}isEmpty(){}iterator(){}size(){}toArray(){}remove(){}}class Xf extends Is{constructor(t){super(t),this.name=Object.keys({IndexOutOfBoundsException:Xf})[0]}}class Pi extends sn{get(){}set(){}isEmpty(){}}class vl extends Is{constructor(t){super(t),this.name=Object.keys({NoSuchElementException:vl})[0]}}class vt extends Pi{constructor(t){super(),this.array=[],t instanceof sn&&this.addAll(t)}get interfaces_(){return[Pi,sn]}ensureCapacity(){}add(t){return arguments.length===1?this.array.push(t):this.array.splice(arguments[0],0,arguments[1]),!0}clear(){this.array=[]}addAll(t){for(const e of t)this.array.push(e)}set(t,e){const n=this.array[t];return this.array[t]=e,n}iterator(){return new MA(this)}get(t){if(t<0||t>=this.size())throw new Xf;return this.array[t]}isEmpty(){return this.array.length===0}sort(t){t?this.array.sort((e,n)=>t.compare(e,n)):this.array.sort()}size(){return this.array.length}toArray(){return this.array.slice()}remove(t){for(let e=0,n=this.array.length;e<n;e++)if(this.array[e]===t)return!!this.array.splice(e,1);return!1}[Symbol.iterator](){return this.array.values()}}let MA=class{constructor(t){this.arrayList=t,this.position=0}next(){if(this.position===this.arrayList.size())throw new vl;return this.arrayList.get(this.position++)}hasNext(){return this.position<this.arrayList.size()}set(t){return this.arrayList.set(this.position-1,t)}remove(){this.arrayList.remove(this.arrayList.get(this.position))}};class Or{static sort(){const t=arguments[0];if(arguments.length===1)t.sort((e,n)=>e.compareTo(n));else if(arguments.length===2)t.sort((e,n)=>arguments[1].compare(e,n));else if(arguments.length===3){const e=t.slice(arguments[1],arguments[2]);e.sort();const n=t.slice(0,arguments[1]).concat(e,t.slice(arguments[2],t.length));t.splice(0,t.length);for(const s of n)t.push(s)}else if(arguments.length===4){const e=t.slice(arguments[1],arguments[2]);e.sort((s,r)=>arguments[3].compare(s,r));const n=t.slice(0,arguments[1]).concat(e,t.slice(arguments[2],t.length));t.splice(0,t.length);for(const s of n)t.push(s)}}static asList(t){const e=new vt;for(const n of t)e.add(n);return e}static copyOf(t,e){return t.slice(0,e)}}class Fu{constructor(t){this.str=t}append(t){this.str+=t}setCharAt(t,e){this.str=this.str.substr(0,t)+e+this.str.substr(t+1)}toString(){return this.str}}class nl{constructor(t){this.value=t}intValue(){return this.value}compareTo(t){return this.value<t?-1:this.value>t?1:0}static compare(t,e){return t<e?-1:t>e?1:0}static isNan(t){return Number.isNaN(t)}static valueOf(t){return new nl(t)}}class ht{constructor(){ht.constructor_.apply(this,arguments)}static constructor_(){if(this._hi=0,this._lo=0,arguments.length===0)this.init(0);else if(arguments.length===1){if(typeof arguments[0]=="number"){const t=arguments[0];this.init(t)}else if(arguments[0]instanceof ht){const t=arguments[0];this.init(t)}else if(typeof arguments[0]=="string"){const t=arguments[0];ht.constructor_.call(this,ht.parse(t))}}else if(arguments.length===2){const t=arguments[0],e=arguments[1];this.init(t,e)}}static determinant(){if(typeof arguments[3]=="number"&&typeof arguments[2]=="number"&&typeof arguments[0]=="number"&&typeof arguments[1]=="number"){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3];return ht.determinant(ht.valueOf(t),ht.valueOf(e),ht.valueOf(n),ht.valueOf(s))}else if(arguments[3]instanceof ht&&arguments[2]instanceof ht&&arguments[0]instanceof ht&&arguments[1]instanceof ht){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3];return t.multiply(s).selfSubtract(e.multiply(n))}}static sqr(t){return ht.valueOf(t).selfMultiply(t)}static valueOf(){if(typeof arguments[0]=="string"){const t=arguments[0];return ht.parse(t)}else if(typeof arguments[0]=="number"){const t=arguments[0];return new ht(t)}}static sqrt(t){return ht.valueOf(t).sqrt()}static parse(t){let e=0;const n=t.length;for(;sm.isWhitespace(t.charAt(e));)e++;let s=!1;if(e<n){const p=t.charAt(e);(p==="-"||p==="+")&&(e++,p==="-"&&(s=!0))}const r=new ht;let o=0,a=0,l=0,h=!1;for(;!(e>=n);){const p=t.charAt(e);if(e++,sm.isDigit(p)){const y=p-"0";r.selfMultiply(ht.TEN),r.selfAdd(y),o++;continue}if(p==="."){a=o,h=!0;continue}if(p==="e"||p==="E"){const y=t.substring(e);try{l=nl.parseInt(y)}catch(_){throw _ instanceof NumberFormatException?new NumberFormatException("Invalid exponent "+y+" in string "+t):_}finally{}break}throw new NumberFormatException("Unexpected character '"+p+"' at position "+e+" in string "+t)}let f=r;h||(a=o);const d=o-a-l;if(d===0)f=r;else if(d>0){const p=ht.TEN.pow(d);f=r.divide(p)}else if(d<0){const p=ht.TEN.pow(-d);f=r.multiply(p)}return s?f.negate():f}static createNaN(){return new ht(Rt.NaN,Rt.NaN)}static copy(t){return new ht(t)}static magnitude(t){const e=Math.abs(t),n=Math.log(e)/Math.log(10);let s=Math.trunc(Math.floor(n));return Math.pow(10,s)*10<=e&&(s+=1),s}static stringOfChar(t,e){const n=new Fu;for(let s=0;s<e;s++)n.append(t);return n.toString()}le(t){return this._hi<t._hi||this._hi===t._hi&&this._lo<=t._lo}extractSignificantDigits(t,e){let n=this.abs(),s=ht.magnitude(n._hi);const r=ht.TEN.pow(s);n=n.divide(r),n.gt(ht.TEN)?(n=n.divide(ht.TEN),s+=1):n.lt(ht.ONE)&&(n=n.multiply(ht.TEN),s-=1);const o=s+1,a=new Fu,l=ht.MAX_PRINT_DIGITS-1;for(let h=0;h<=l;h++){t&&h===o&&a.append(".");const f=Math.trunc(n._hi);if(f<0)break;let d=!1,p=0;f>9?(d=!0,p="9"):p="0"+f,a.append(p),n=n.subtract(ht.valueOf(f)).multiply(ht.TEN),d&&n.selfAdd(ht.TEN);let y=!0;const _=ht.magnitude(n._hi);if(_<0&&Math.abs(_)>=l-h&&(y=!1),!y)break}return e[0]=s,a.toString()}sqr(){return this.multiply(this)}doubleValue(){return this._hi+this._lo}subtract(){if(arguments[0]instanceof ht){const t=arguments[0];return this.add(t.negate())}else if(typeof arguments[0]=="number"){const t=arguments[0];return this.add(-t)}}equals(){if(arguments.length===1&&arguments[0]instanceof ht){const t=arguments[0];return this._hi===t._hi&&this._lo===t._lo}}isZero(){return this._hi===0&&this._lo===0}selfSubtract(){if(arguments[0]instanceof ht){const t=arguments[0];return this.isNaN()?this:this.selfAdd(-t._hi,-t._lo)}else if(typeof arguments[0]=="number"){const t=arguments[0];return this.isNaN()?this:this.selfAdd(-t,0)}}getSpecialNumberString(){return this.isZero()?"0.0":this.isNaN()?"NaN ":null}min(t){return this.le(t)?this:t}selfDivide(){if(arguments.length===1){if(arguments[0]instanceof ht){const t=arguments[0];return this.selfDivide(t._hi,t._lo)}else if(typeof arguments[0]=="number"){const t=arguments[0];return this.selfDivide(t,0)}}else if(arguments.length===2){const t=arguments[0],e=arguments[1];let n=null,s=null,r=null,o=null,a=null,l=null,h=null,f=null;return a=this._hi/t,l=ht.SPLIT*a,n=l-a,f=ht.SPLIT*t,n=l-n,s=a-n,r=f-t,h=a*t,r=f-r,o=t-r,f=n*r-h+n*o+s*r+s*o,l=(this._hi-h-f+this._lo-a*e)/t,f=a+l,this._hi=f,this._lo=a-f+l,this}}dump(){return"DD<"+this._hi+", "+this._lo+">"}divide(){if(arguments[0]instanceof ht){const t=arguments[0];let e=null,n=null,s=null,r=null,o=null,a=null,l=null,h=null;o=this._hi/t._hi,a=ht.SPLIT*o,e=a-o,h=ht.SPLIT*t._hi,e=a-e,n=o-e,s=h-t._hi,l=o*t._hi,s=h-s,r=t._hi-s,h=e*s-l+e*r+n*s+n*r,a=(this._hi-l-h+this._lo-o*t._lo)/t._hi,h=o+a;const f=h,d=o-h+a;return new ht(f,d)}else if(typeof arguments[0]=="number"){const t=arguments[0];return Rt.isNaN(t)?ht.createNaN():ht.copy(this).selfDivide(t,0)}}ge(t){return this._hi>t._hi||this._hi===t._hi&&this._lo>=t._lo}pow(t){if(t===0)return ht.valueOf(1);let e=new ht(this),n=ht.valueOf(1),s=Math.abs(t);if(s>1)for(;s>0;)s%2===1&&n.selfMultiply(e),s/=2,s>0&&(e=e.sqr());else n=e;return t<0?n.reciprocal():n}ceil(){if(this.isNaN())return ht.NaN;const t=Math.ceil(this._hi);let e=0;return t===this._hi&&(e=Math.ceil(this._lo)),new ht(t,e)}compareTo(t){const e=t;return this._hi<e._hi?-1:this._hi>e._hi?1:this._lo<e._lo?-1:this._lo>e._lo?1:0}rint(){return this.isNaN()?this:this.add(.5).floor()}setValue(){if(arguments[0]instanceof ht){const t=arguments[0];return this.init(t),this}else if(typeof arguments[0]=="number"){const t=arguments[0];return this.init(t),this}}max(t){return this.ge(t)?this:t}sqrt(){if(this.isZero())return ht.valueOf(0);if(this.isNegative())return ht.NaN;const t=1/Math.sqrt(this._hi),e=this._hi*t,n=ht.valueOf(e),r=this.subtract(n.sqr())._hi*(t*.5);return n.add(r)}selfAdd(){if(arguments.length===1){if(arguments[0]instanceof ht){const t=arguments[0];return this.selfAdd(t._hi,t._lo)}else if(typeof arguments[0]=="number"){const t=arguments[0];let e=null,n=null,s=null,r=null,o=null,a=null;return s=this._hi+t,o=s-this._hi,r=s-o,r=t-o+(this._hi-r),a=r+this._lo,e=s+a,n=a+(s-e),this._hi=e+n,this._lo=n+(e-this._hi),this}}else if(arguments.length===2){const t=arguments[0],e=arguments[1];let n=null,s=null,r=null,o=null,a=null,l=null,h=null,f=null;a=this._hi+t,r=this._lo+e,h=a-this._hi,f=r-this._lo,l=a-h,o=r-f,l=t-h+(this._hi-l),o=e-f+(this._lo-o),h=l+r,n=a+h,s=h+(a-n),h=o+s;const d=n+h,p=h+(n-d);return this._hi=d,this._lo=p,this}}selfMultiply(){if(arguments.length===1){if(arguments[0]instanceof ht){const t=arguments[0];return this.selfMultiply(t._hi,t._lo)}else if(typeof arguments[0]=="number"){const t=arguments[0];return this.selfMultiply(t,0)}}else if(arguments.length===2){const t=arguments[0],e=arguments[1];let n=null,s=null,r=null,o=null,a=null,l=null;a=ht.SPLIT*this._hi,n=a-this._hi,l=ht.SPLIT*t,n=a-n,s=this._hi-n,r=l-t,a=this._hi*t,r=l-r,o=t-r,l=n*r-a+n*o+s*r+s*o+(this._hi*e+this._lo*t);const h=a+l;n=a-h;const f=l+n;return this._hi=h,this._lo=f,this}}selfSqr(){return this.selfMultiply(this)}floor(){if(this.isNaN())return ht.NaN;const t=Math.floor(this._hi);let e=0;return t===this._hi&&(e=Math.floor(this._lo)),new ht(t,e)}negate(){return this.isNaN()?this:new ht(-this._hi,-this._lo)}clone(){try{return null}catch(t){if(t instanceof CloneNotSupportedException)return null;throw t}finally{}}multiply(){if(arguments[0]instanceof ht){const t=arguments[0];return t.isNaN()?ht.createNaN():ht.copy(this).selfMultiply(t)}else if(typeof arguments[0]=="number"){const t=arguments[0];return Rt.isNaN(t)?ht.createNaN():ht.copy(this).selfMultiply(t,0)}}isNaN(){return Rt.isNaN(this._hi)}intValue(){return Math.trunc(this._hi)}toString(){const t=ht.magnitude(this._hi);return t>=-3&&t<=20?this.toStandardNotation():this.toSciNotation()}toStandardNotation(){const t=this.getSpecialNumberString();if(t!==null)return t;const e=new Array(1).fill(null),n=this.extractSignificantDigits(!0,e),s=e[0]+1;let r=n;if(n.charAt(0)===".")r="0"+n;else if(s<0)r="0."+ht.stringOfChar("0",-s)+n;else if(n.indexOf(".")===-1){const o=s-n.length,a=ht.stringOfChar("0",o);r=n+a+".0"}return this.isNegative()?"-"+r:r}reciprocal(){let t=null,e=null,n=null,s=null,r=null,o=null,a=null,l=null;r=1/this._hi,o=ht.SPLIT*r,t=o-r,l=ht.SPLIT*this._hi,t=o-t,e=r-t,n=l-this._hi,a=r*this._hi,n=l-n,s=this._hi-n,l=t*n-a+t*s+e*n+e*s,o=(1-a-l-r*this._lo)/this._hi;const h=r+o,f=r-h+o;return new ht(h,f)}toSciNotation(){if(this.isZero())return ht.SCI_NOT_ZERO;const t=this.getSpecialNumberString();if(t!==null)return t;const e=new Array(1).fill(null),n=this.extractSignificantDigits(!1,e),s=ht.SCI_NOT_EXPONENT_CHAR+e[0];if(n.charAt(0)==="0")throw new IllegalStateException("Found leading zero: "+n);let r="";n.length>1&&(r=n.substring(1));const o=n.charAt(0)+"."+r;return this.isNegative()?"-"+o+s:o+s}abs(){return this.isNaN()?ht.NaN:this.isNegative()?this.negate():new ht(this)}isPositive(){return this._hi>0||this._hi===0&&this._lo>0}lt(t){return this._hi<t._hi||this._hi===t._hi&&this._lo<t._lo}add(){if(arguments[0]instanceof ht){const t=arguments[0];return ht.copy(this).selfAdd(t)}else if(typeof arguments[0]=="number"){const t=arguments[0];return ht.copy(this).selfAdd(t)}}init(){if(arguments.length===1){if(typeof arguments[0]=="number"){const t=arguments[0];this._hi=t,this._lo=0}else if(arguments[0]instanceof ht){const t=arguments[0];this._hi=t._hi,this._lo=t._lo}}else if(arguments.length===2){const t=arguments[0],e=arguments[1];this._hi=t,this._lo=e}}gt(t){return this._hi>t._hi||this._hi===t._hi&&this._lo>t._lo}isNegative(){return this._hi<0||this._hi===0&&this._lo<0}trunc(){return this.isNaN()?ht.NaN:this.isPositive()?this.floor():this.ceil()}signum(){return this._hi>0?1:this._hi<0?-1:this._lo>0?1:this._lo<0?-1:0}get interfaces_(){return[mi,gi,yc]}}ht.PI=new ht(3.141592653589793,12246467991473532e-32);ht.TWO_PI=new ht(6.283185307179586,24492935982947064e-32);ht.PI_2=new ht(1.5707963267948966,6123233995736766e-32);ht.E=new ht(2.718281828459045,14456468917292502e-32);ht.NaN=new ht(Rt.NaN,Rt.NaN);ht.EPS=123259516440783e-46;ht.SPLIT=134217729;ht.MAX_PRINT_DIGITS=32;ht.TEN=ht.valueOf(10);ht.ONE=ht.valueOf(1);ht.SCI_NOT_EXPONENT_CHAR="E";ht.SCI_NOT_ZERO="0.0E0";class Gs{static orientationIndex(t,e,n){const s=Gs.orientationIndexFilter(t,e,n);if(s<=1)return s;const r=ht.valueOf(e.x).selfAdd(-t.x),o=ht.valueOf(e.y).selfAdd(-t.y),a=ht.valueOf(n.x).selfAdd(-e.x),l=ht.valueOf(n.y).selfAdd(-e.y);return r.selfMultiply(l).selfSubtract(o.selfMultiply(a)).signum()}static signOfDet2x2(){if(arguments[3]instanceof ht&&arguments[2]instanceof ht&&arguments[0]instanceof ht&&arguments[1]instanceof ht){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3];return t.multiply(s).selfSubtract(e.multiply(n)).signum()}else if(typeof arguments[3]=="number"&&typeof arguments[2]=="number"&&typeof arguments[0]=="number"&&typeof arguments[1]=="number"){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3],r=ht.valueOf(t),o=ht.valueOf(e),a=ht.valueOf(n),l=ht.valueOf(s);return r.multiply(l).selfSubtract(o.multiply(a)).signum()}}static intersection(t,e,n,s){const r=new ht(t.y).selfSubtract(e.y),o=new ht(e.x).selfSubtract(t.x),a=new ht(t.x).selfMultiply(e.y).selfSubtract(new ht(e.x).selfMultiply(t.y)),l=new ht(n.y).selfSubtract(s.y),h=new ht(s.x).selfSubtract(n.x),f=new ht(n.x).selfMultiply(s.y).selfSubtract(new ht(s.x).selfMultiply(n.y)),d=o.multiply(f).selfSubtract(h.multiply(a)),p=l.multiply(a).selfSubtract(r.multiply(f)),y=r.multiply(h).selfSubtract(l.multiply(o)),_=d.selfDivide(y).doubleValue(),E=p.selfDivide(y).doubleValue();return Rt.isNaN(_)||Rt.isInfinite(_)||Rt.isNaN(E)||Rt.isInfinite(E)?null:new Z(_,E)}static orientationIndexFilter(t,e,n){let s=null;const r=(t.x-n.x)*(e.y-n.y),o=(t.y-n.y)*(e.x-n.x),a=r-o;if(r>0){if(o<=0)return Gs.signum(a);s=r+o}else if(r<0){if(o>=0)return Gs.signum(a);s=-r-o}else return Gs.signum(a);const l=Gs.DP_SAFE_EPSILON*s;return a>=l||-a>=l?Gs.signum(a):2}static signum(t){return t>0?1:t<0?-1:0}}Gs.DP_SAFE_EPSILON=1e-15;class $t{static index(t,e,n){return Gs.orientationIndex(t,e,n)}static isCCW(){if(arguments[0]instanceof Array){const t=arguments[0],e=t.length-1;if(e<3)throw new Zt("Ring has fewer than 4 points, so orientation cannot be determined");let n=t[0],s=0;for(let d=1;d<=e;d++){const p=t[d];p.y>n.y&&(n=p,s=d)}let r=s;do r=r-1,r<0&&(r=e);while(t[r].equals2D(n)&&r!==s);let o=s;do o=(o+1)%e;while(t[o].equals2D(n)&&o!==s);const a=t[r],l=t[o];if(a.equals2D(n)||l.equals2D(n)||a.equals2D(l))return!1;const h=$t.index(a,n,l);let f=null;return h===0?f=a.x>l.x:f=h>0,f}else if(Ot(arguments[0],de)){const t=arguments[0],e=t.size()-1;if(e<3)throw new Zt("Ring has fewer than 4 points, so orientation cannot be determined");let n=t.getCoordinate(0),s=0;for(let d=1;d<=e;d++){const p=t.getCoordinate(d);p.y>n.y&&(n=p,s=d)}let r=null,o=s;do o=o-1,o<0&&(o=e),r=t.getCoordinate(o);while(r.equals2D(n)&&o!==s);let a=null,l=s;do l=(l+1)%e,a=t.getCoordinate(l);while(a.equals2D(n)&&l!==s);if(r.equals2D(n)||a.equals2D(n)||r.equals2D(a))return!1;const h=$t.index(r,n,a);let f=null;return h===0?f=r.x>a.x:f=h>0,f}}}$t.CLOCKWISE=-1;$t.RIGHT=$t.CLOCKWISE;$t.COUNTERCLOCKWISE=1;$t.LEFT=$t.COUNTERCLOCKWISE;$t.COLLINEAR=0;$t.STRAIGHT=$t.COLLINEAR;class Jr{}class Te extends dt{constructor(){super(),Te.constructor_.apply(this,arguments)}static constructor_(){this._shell=null,this._holes=null;let t=arguments[0],e=arguments[1],n=arguments[2];if(dt.constructor_.call(this,n),t===null&&(t=this.getFactory().createLinearRing()),e===null&&(e=[]),dt.hasNullElements(e))throw new Zt("holes must not contain null elements");if(t.isEmpty()&&dt.hasNonEmptyElements(e))throw new Zt("shell is empty but holes are not");this._shell=t,this._holes=e}computeEnvelopeInternal(){return this._shell.getEnvelopeInternal()}getCoordinates(){if(this.isEmpty())return[];const t=new Array(this.getNumPoints()).fill(null);let e=-1;const n=this._shell.getCoordinates();for(let s=0;s<n.length;s++)e++,t[e]=n[s];for(let s=0;s<this._holes.length;s++){const r=this._holes[s].getCoordinates();for(let o=0;o<r.length;o++)e++,t[e]=r[o]}return t}getArea(){let t=0;t+=Ou.ofRing(this._shell.getCoordinateSequence());for(let e=0;e<this._holes.length;e++)t-=Ou.ofRing(this._holes[e].getCoordinateSequence());return t}copyInternal(){const t=this._shell.copy(),e=new Array(this._holes.length).fill(null);for(let n=0;n<this._holes.length;n++)e[n]=this._holes[n].copy();return new Te(t,e,this._factory)}isRectangle(){if(this.getNumInteriorRing()!==0||this._shell===null||this._shell.getNumPoints()!==5)return!1;const t=this._shell.getCoordinateSequence(),e=this.getEnvelopeInternal();for(let r=0;r<5;r++){const o=t.getX(r);if(!(o===e.getMinX()||o===e.getMaxX()))return!1;const a=t.getY(r);if(!(a===e.getMinY()||a===e.getMaxY()))return!1}let n=t.getX(0),s=t.getY(0);for(let r=1;r<=4;r++){const o=t.getX(r),a=t.getY(r);if(o!==n===(a!==s))return!1;n=o,s=a}return!0}equalsExact(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof dt){const t=arguments[0],e=arguments[1];if(!this.isEquivalentClass(t))return!1;const n=t,s=this._shell,r=n._shell;if(!s.equalsExact(r,e)||this._holes.length!==n._holes.length)return!1;for(let o=0;o<this._holes.length;o++)if(!this._holes[o].equalsExact(n._holes[o],e))return!1;return!0}else return super.equalsExact.apply(this,arguments)}normalize(){if(arguments.length===0){this._shell=this.normalized(this._shell,!0);for(let t=0;t<this._holes.length;t++)this._holes[t]=this.normalized(this._holes[t],!1);Or.sort(this._holes)}else if(arguments.length===2){const t=arguments[0],e=arguments[1];if(t.isEmpty())return null;const n=t.getCoordinateSequence(),s=tn.minCoordinateIndex(n,0,n.size()-2);tn.scroll(n,s,!0),$t.isCCW(n)===e&&tn.reverse(n)}}getCoordinate(){return this._shell.getCoordinate()}getNumInteriorRing(){return this._holes.length}getBoundaryDimension(){return 1}reverseInternal(){const t=this.getExteriorRing().reverse(),e=new Array(this.getNumInteriorRing()).fill(null);for(let n=0;n<e.length;n++)e[n]=this.getInteriorRingN(n).reverse();return this.getFactory().createPolygon(t,e)}getTypeCode(){return dt.TYPECODE_POLYGON}getDimension(){return 2}getLength(){let t=0;t+=this._shell.getLength();for(let e=0;e<this._holes.length;e++)t+=this._holes[e].getLength();return t}getNumPoints(){let t=this._shell.getNumPoints();for(let e=0;e<this._holes.length;e++)t+=this._holes[e].getNumPoints();return t}convexHull(){return this.getExteriorRing().convexHull()}normalized(t,e){const n=t.copy();return this.normalize(n,e),n}compareToSameClass(){if(arguments.length===1){const t=arguments[0],e=this._shell,n=t._shell;return e.compareToSameClass(n)}else if(arguments.length===2){const t=arguments[0],e=arguments[1],n=t,s=this._shell,r=n._shell,o=s.compareToSameClass(r,e);if(o!==0)return o;const a=this.getNumInteriorRing(),l=n.getNumInteriorRing();let h=0;for(;h<a&&h<l;){const f=this.getInteriorRingN(h),d=n.getInteriorRingN(h),p=f.compareToSameClass(d,e);if(p!==0)return p;h++}return h<a?1:h<l?-1:0}}apply(){if(Ot(arguments[0],yl)){const t=arguments[0];this._shell.apply(t);for(let e=0;e<this._holes.length;e++)this._holes[e].apply(t)}else if(Ot(arguments[0],_l)){const t=arguments[0];if(this._shell.apply(t),!t.isDone())for(let e=0;e<this._holes.length&&(this._holes[e].apply(t),!t.isDone());e++);t.isGeometryChanged()&&this.geometryChanged()}else if(Ot(arguments[0],Zr))arguments[0].filter(this);else if(Ot(arguments[0],pl)){const t=arguments[0];t.filter(this),this._shell.apply(t);for(let e=0;e<this._holes.length;e++)this._holes[e].apply(t)}}getBoundary(){if(this.isEmpty())return this.getFactory().createMultiLineString();const t=new Array(this._holes.length+1).fill(null);t[0]=this._shell;for(let e=0;e<this._holes.length;e++)t[e+1]=this._holes[e];return t.length<=1?this.getFactory().createLinearRing(t[0].getCoordinateSequence()):this.getFactory().createMultiLineString(t)}getGeometryType(){return dt.TYPENAME_POLYGON}getExteriorRing(){return this._shell}isEmpty(){return this._shell.isEmpty()}getInteriorRingN(t){return this._holes[t]}get interfaces_(){return[Jr]}}let Ew=class extends sn{contains(){}};class NA extends Ew{}class Ao extends NA{constructor(t){super(),this.array=[],t instanceof sn&&this.addAll(t)}contains(t){for(const e of this.array)if(e.compareTo(t)===0)return!0;return!1}add(t){if(this.contains(t))return!1;for(let e=0,n=this.array.length;e<n;e++)if(this.array[e].compareTo(t)===1)return!!this.array.splice(e,0,t);return this.array.push(t),!0}addAll(t){for(const e of t)this.add(e);return!0}remove(){throw new ss}size(){return this.array.length}isEmpty(){return this.array.length===0}toArray(){return this.array.slice()}iterator(){return new LA(this.array)}}let LA=class{constructor(t){this.array=t,this.position=0}next(){if(this.position===this.array.length)throw new vl;return this.array[this.position++]}hasNext(){return this.position<this.array.length}remove(){throw new ss}};class ye extends dt{constructor(){super(),ye.constructor_.apply(this,arguments)}static constructor_(){if(this._geometries=null,arguments.length!==0){if(arguments.length===2){let t=arguments[0],e=arguments[1];if(dt.constructor_.call(this,e),t===null&&(t=[]),dt.hasNullElements(t))throw new Zt("geometries must not contain null elements");this._geometries=t}}}computeEnvelopeInternal(){const t=new te;for(let e=0;e<this._geometries.length;e++)t.expandToInclude(this._geometries[e].getEnvelopeInternal());return t}getGeometryN(t){return this._geometries[t]}getCoordinates(){const t=new Array(this.getNumPoints()).fill(null);let e=-1;for(let n=0;n<this._geometries.length;n++){const s=this._geometries[n].getCoordinates();for(let r=0;r<s.length;r++)e++,t[e]=s[r]}return t}getArea(){let t=0;for(let e=0;e<this._geometries.length;e++)t+=this._geometries[e].getArea();return t}copyInternal(){const t=new Array(this._geometries.length).fill(null);for(let e=0;e<t.length;e++)t[e]=this._geometries[e].copy();return new ye(t,this._factory)}equalsExact(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof dt){const t=arguments[0],e=arguments[1];if(!this.isEquivalentClass(t))return!1;const n=t;if(this._geometries.length!==n._geometries.length)return!1;for(let s=0;s<this._geometries.length;s++)if(!this._geometries[s].equalsExact(n._geometries[s],e))return!1;return!0}else return super.equalsExact.apply(this,arguments)}normalize(){for(let t=0;t<this._geometries.length;t++)this._geometries[t].normalize();Or.sort(this._geometries)}getCoordinate(){return this.isEmpty()?null:this._geometries[0].getCoordinate()}getBoundaryDimension(){let t=pt.FALSE;for(let e=0;e<this._geometries.length;e++)t=Math.max(t,this._geometries[e].getBoundaryDimension());return t}reverseInternal(){const t=this._geometries.length,e=new vt(t);for(let n=0;n<t;n++)e.add(this._geometries[n].reverse());return this.getFactory().buildGeometry(e)}getTypeCode(){return dt.TYPECODE_GEOMETRYCOLLECTION}getDimension(){let t=pt.FALSE;for(let e=0;e<this._geometries.length;e++)t=Math.max(t,this._geometries[e].getDimension());return t}getLength(){let t=0;for(let e=0;e<this._geometries.length;e++)t+=this._geometries[e].getLength();return t}getNumPoints(){let t=0;for(let e=0;e<this._geometries.length;e++)t+=this._geometries[e].getNumPoints();return t}getNumGeometries(){return this._geometries.length}compareToSameClass(){if(arguments.length===1){const t=arguments[0],e=new Ao(Or.asList(this._geometries)),n=new Ao(Or.asList(t._geometries));return this.compare(e,n)}else if(arguments.length===2){const t=arguments[0],e=arguments[1],n=t,s=this.getNumGeometries(),r=n.getNumGeometries();let o=0;for(;o<s&&o<r;){const a=this.getGeometryN(o),l=n.getGeometryN(o),h=a.compareToSameClass(l,e);if(h!==0)return h;o++}return o<s?1:o<r?-1:0}}apply(){if(Ot(arguments[0],yl)){const t=arguments[0];for(let e=0;e<this._geometries.length;e++)this._geometries[e].apply(t)}else if(Ot(arguments[0],_l)){const t=arguments[0];if(this._geometries.length===0)return null;for(let e=0;e<this._geometries.length&&(this._geometries[e].apply(t),!t.isDone());e++);t.isGeometryChanged()&&this.geometryChanged()}else if(Ot(arguments[0],Zr)){const t=arguments[0];t.filter(this);for(let e=0;e<this._geometries.length;e++)this._geometries[e].apply(t)}else if(Ot(arguments[0],pl)){const t=arguments[0];t.filter(this);for(let e=0;e<this._geometries.length;e++)this._geometries[e].apply(t)}}getBoundary(){return dt.checkNotGeometryCollection(this),Yt.shouldNeverReachHere(),null}getGeometryType(){return dt.TYPENAME_GEOMETRYCOLLECTION}isEmpty(){for(let t=0;t<this._geometries.length;t++)if(!this._geometries[t].isEmpty())return!1;return!0}}class Ss extends ye{constructor(){super(),Ss.constructor_.apply(this,arguments)}static constructor_(){const t=arguments[0],e=arguments[1];ye.constructor_.call(this,t,e)}copyInternal(){const t=new Array(this._geometries.length).fill(null);for(let e=0;e<t.length;e++)t[e]=this._geometries[e].copy();return new Ss(t,this._factory)}isValid(){return!0}equalsExact(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof dt){const t=arguments[0],e=arguments[1];return this.isEquivalentClass(t)?super.equalsExact.call(this,t,e):!1}else return super.equalsExact.apply(this,arguments)}getCoordinate(){if(arguments.length===1&&Number.isInteger(arguments[0])){const t=arguments[0];return this._geometries[t].getCoordinate()}else return super.getCoordinate.apply(this,arguments)}getBoundaryDimension(){return pt.FALSE}getTypeCode(){return dt.TYPECODE_MULTIPOINT}getDimension(){return 0}getBoundary(){return this.getFactory().createGeometryCollection()}getGeometryType(){return dt.TYPENAME_MULTIPOINT}get interfaces_(){return[vw]}}class fn extends ce{constructor(){super(),fn.constructor_.apply(this,arguments)}static constructor_(){const t=arguments[0],e=arguments[1];ce.constructor_.call(this,t,e),this.validateConstruction()}copyInternal(){return new fn(this._points.copy(),this._factory)}getBoundaryDimension(){return pt.FALSE}isClosed(){return this.isEmpty()?!0:super.isClosed.call(this)}reverseInternal(){const t=this._points.copy();return tn.reverse(t),this.getFactory().createLinearRing(t)}getTypeCode(){return dt.TYPECODE_LINEARRING}validateConstruction(){if(!this.isEmpty()&&!super.isClosed.call(this))throw new Zt("Points of LinearRing do not form a closed linestring");if(this.getCoordinateSequence().size()>=1&&this.getCoordinateSequence().size()<fn.MINIMUM_VALID_SIZE)throw new Zt("Invalid number of points in LinearRing (found "+this.getCoordinateSequence().size()+" - must be 0 or >= 4)")}getGeometryType(){return dt.TYPENAME_LINEARRING}}fn.MINIMUM_VALID_SIZE=4;class Wn extends Z{constructor(){super(),Wn.constructor_.apply(this,arguments)}static constructor_(){if(arguments.length===0)Z.constructor_.call(this);else if(arguments.length===1){if(arguments[0]instanceof Wn){const t=arguments[0];Z.constructor_.call(this,t.x,t.y)}else if(arguments[0]instanceof Z){const t=arguments[0];Z.constructor_.call(this,t.x,t.y)}}else if(arguments.length===2){const t=arguments[0],e=arguments[1];Z.constructor_.call(this,t,e,Z.NULL_ORDINATE)}}setOrdinate(t,e){switch(t){case Wn.X:this.x=e;break;case Wn.Y:this.y=e;break;default:throw new Zt("Invalid ordinate index: "+t)}}getZ(){return Z.NULL_ORDINATE}getOrdinate(t){switch(t){case Wn.X:return this.x;case Wn.Y:return this.y}throw new Zt("Invalid ordinate index: "+t)}setZ(t){throw new Zt("CoordinateXY dimension 2 does not support z-ordinate")}copy(){return new Wn(this)}toString(){return"("+this.x+", "+this.y+")"}setCoordinate(t){this.x=t.x,this.y=t.y,this.z=t.getZ()}}Wn.X=0;Wn.Y=1;Wn.Z=-1;Wn.M=-1;class Sn extends Z{constructor(){super(),Sn.constructor_.apply(this,arguments)}static constructor_(){if(this._m=null,arguments.length===0)Z.constructor_.call(this),this._m=0;else if(arguments.length===1){if(arguments[0]instanceof Sn){const t=arguments[0];Z.constructor_.call(this,t.x,t.y),this._m=t._m}else if(arguments[0]instanceof Z){const t=arguments[0];Z.constructor_.call(this,t.x,t.y),this._m=this.getM()}}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];Z.constructor_.call(this,t,e,Z.NULL_ORDINATE),this._m=n}}getM(){return this._m}setOrdinate(t,e){switch(t){case Sn.X:this.x=e;break;case Sn.Y:this.y=e;break;case Sn.M:this._m=e;break;default:throw new Zt("Invalid ordinate index: "+t)}}setM(t){this._m=t}getZ(){return Z.NULL_ORDINATE}getOrdinate(t){switch(t){case Sn.X:return this.x;case Sn.Y:return this.y;case Sn.M:return this._m}throw new Zt("Invalid ordinate index: "+t)}setZ(t){throw new Zt("CoordinateXY dimension 2 does not support z-ordinate")}copy(){return new Sn(this)}toString(){return"("+this.x+", "+this.y+" m="+this.getM()+")"}setCoordinate(t){this.x=t.x,this.y=t.y,this.z=t.getZ(),this._m=t.getM()}}Sn.X=0;Sn.Y=1;Sn.Z=-1;Sn.M=2;class So extends Z{constructor(){super(),So.constructor_.apply(this,arguments)}static constructor_(){if(this._m=null,arguments.length===0)Z.constructor_.call(this),this._m=0;else if(arguments.length===1){if(arguments[0]instanceof So){const t=arguments[0];Z.constructor_.call(this,t),this._m=t._m}else if(arguments[0]instanceof Z){const t=arguments[0];Z.constructor_.call(this,t),this._m=this.getM()}}else if(arguments.length===4){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3];Z.constructor_.call(this,t,e,n),this._m=s}}getM(){return this._m}setOrdinate(t,e){switch(t){case Z.X:this.x=e;break;case Z.Y:this.y=e;break;case Z.Z:this.z=e;break;case Z.M:this._m=e;break;default:throw new Zt("Invalid ordinate index: "+t)}}setM(t){this._m=t}getOrdinate(t){switch(t){case Z.X:return this.x;case Z.Y:return this.y;case Z.Z:return this.getZ();case Z.M:return this.getM()}throw new Zt("Invalid ordinate index: "+t)}copy(){return new So(this)}toString(){return"("+this.x+", "+this.y+", "+this.getZ()+" m="+this.getM()+")"}setCoordinate(t){this.x=t.x,this.y=t.y,this.z=t.getZ(),this._m=t.getM()}}class il{static measures(t){return t instanceof Wn?0:t instanceof Sn||t instanceof So?1:(t instanceof Z,0)}static dimension(t){return t instanceof Wn?2:t instanceof Sn?3:t instanceof So?4:(t instanceof Z,3)}static create(){if(arguments.length===1){const t=arguments[0];return il.create(t,0)}else if(arguments.length===2){const t=arguments[0],e=arguments[1];return t===2?new Wn:t===3&&e===0?new Z:t===3&&e===1?new Sn:t===4&&e===1?new So:new Z}}}class Qi extends vt{constructor(){super(),Qi.constructor_.apply(this,arguments)}static constructor_(){if(arguments.length!==0){if(arguments.length===1){const t=arguments[0];this.ensureCapacity(t.length),this.add(t,!0)}else if(arguments.length===2){const t=arguments[0],e=arguments[1];this.ensureCapacity(t.length),this.add(t,e)}}}getCoordinate(t){return this.get(t)}addAll(){if(arguments.length===2&&typeof arguments[1]=="boolean"&&Ot(arguments[0],sn)){const t=arguments[0],e=arguments[1];let n=!1;for(let s=t.iterator();s.hasNext();)this.add(s.next(),e),n=!0;return n}else return super.addAll.apply(this,arguments)}clone(){const t=super.clone.call(this);for(let e=0;e<this.size();e++)t.add(e,this.get(e).clone());return t}toCoordinateArray(){if(arguments.length===0)return this.toArray(Qi.coordArrayType);if(arguments.length===1){if(arguments[0])return this.toArray(Qi.coordArrayType);const e=this.size(),n=new Array(e).fill(null);for(let s=0;s<e;s++)n[s]=this.get(e-s-1);return n}}add(){if(arguments.length===1){const t=arguments[0];return super.add.call(this,t)}else if(arguments.length===2){if(arguments[0]instanceof Array&&typeof arguments[1]=="boolean"){const t=arguments[0],e=arguments[1];return this.add(t,e,!0),!0}else if(arguments[0]instanceof Z&&typeof arguments[1]=="boolean"){const t=arguments[0];if(!arguments[1]&&this.size()>=1&&this.get(this.size()-1).equals2D(t))return null;super.add.call(this,t)}else if(arguments[0]instanceof Object&&typeof arguments[1]=="boolean"){const t=arguments[0],e=arguments[1];return this.add(t,e),!0}}else if(arguments.length===3){if(typeof arguments[2]=="boolean"&&arguments[0]instanceof Array&&typeof arguments[1]=="boolean"){const t=arguments[0],e=arguments[1];if(arguments[2])for(let s=0;s<t.length;s++)this.add(t[s],e);else for(let s=t.length-1;s>=0;s--)this.add(t[s],e);return!0}else if(typeof arguments[2]=="boolean"&&Number.isInteger(arguments[0])&&arguments[1]instanceof Z){const t=arguments[0],e=arguments[1];if(!arguments[2]){const s=this.size();if(s>0&&(t>0&&this.get(t-1).equals2D(e)||t<s&&this.get(t).equals2D(e)))return null}super.add.call(this,t,e)}}else if(arguments.length===4){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3];let r=1;n>s&&(r=-1);for(let o=n;o!==s;o+=r)this.add(t[o],e);return!0}}closeRing(){if(this.size()>0){const t=this.get(0).copy();this.add(t,!1)}}}Qi.coordArrayType=new Array(0).fill(null);class Oo{static log10(t){const e=Math.log(t);return Rt.isInfinite(e)||Rt.isNaN(e)?e:e/Oo.LOG_10}static min(t,e,n,s){let r=t;return e<r&&(r=e),n<r&&(r=n),s<r&&(r=s),r}static clamp(){if(typeof arguments[2]=="number"&&typeof arguments[0]=="number"&&typeof arguments[1]=="number"){const t=arguments[0],e=arguments[1],n=arguments[2];return t<e?e:t>n?n:t}else if(Number.isInteger(arguments[2])&&Number.isInteger(arguments[0])&&Number.isInteger(arguments[1])){const t=arguments[0],e=arguments[1],n=arguments[2];return t<e?e:t>n?n:t}}static wrap(t,e){return t<0?e- -t%e:t%e}static max(){if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];let s=t;return e>s&&(s=e),n>s&&(s=n),s}else if(arguments.length===4){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3];let r=t;return e>r&&(r=e),n>r&&(r=n),s>r&&(r=s),r}}static average(t,e){return(t+e)/2}}Oo.LOG_10=Math.log(10);class ci{static arraycopy(t,e,n,s,r){let o=0;for(let a=e;a<e+r;a++)n[s+o]=t[a],o++}static getProperty(t){return{"line.separator":`
|
|
11
|
+
`}[t]}}class Le{static isRing(t){return!(t.length<4||!t[0].equals2D(t[t.length-1]))}static ptNotInList(t,e){for(let n=0;n<t.length;n++){const s=t[n];if(Le.indexOf(s,e)<0)return s}return null}static scroll(t,e){const n=Le.indexOf(e,t);if(n<0)return null;const s=new Array(t.length).fill(null);ci.arraycopy(t,n,s,0,t.length-n),ci.arraycopy(t,0,s,t.length-n,n),ci.arraycopy(s,0,t,0,t.length)}static equals(){if(arguments.length===2){const t=arguments[0],e=arguments[1];if(t===e)return!0;if(t===null||e===null||t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!t[n].equals(e[n]))return!1;return!0}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];if(t===e)return!0;if(t===null||e===null||t.length!==e.length)return!1;for(let s=0;s<t.length;s++)if(n.compare(t[s],e[s])!==0)return!1;return!0}}static intersection(t,e){const n=new Qi;for(let s=0;s<t.length;s++)e.intersects(t[s])&&n.add(t[s],!0);return n.toCoordinateArray()}static measures(t){if(t===null||t.length===0)return 0;let e=0;for(const n of t)e=Math.max(e,il.measures(n));return e}static hasRepeatedPoints(t){for(let e=1;e<t.length;e++)if(t[e-1].equals(t[e]))return!0;return!1}static removeRepeatedPoints(t){return Le.hasRepeatedPoints(t)?new Qi(t,!1).toCoordinateArray():t}static reverse(t){const e=t.length-1,n=Math.trunc(e/2);for(let s=0;s<=n;s++){const r=t[s];t[s]=t[e-s],t[e-s]=r}}static removeNull(t){let e=0;for(let r=0;r<t.length;r++)t[r]!==null&&e++;const n=new Array(e).fill(null);if(e===0)return n;let s=0;for(let r=0;r<t.length;r++)t[r]!==null&&(n[s++]=t[r]);return n}static copyDeep(){if(arguments.length===1){const t=arguments[0],e=new Array(t.length).fill(null);for(let n=0;n<t.length;n++)e[n]=t[n].copy();return e}else if(arguments.length===5){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3],r=arguments[4];for(let o=0;o<r;o++)n[s+o]=t[e+o].copy()}}static isEqualReversed(t,e){for(let n=0;n<t.length;n++){const s=t[n],r=e[t.length-n-1];if(s.compareTo(r)!==0)return!1}return!0}static envelope(t){const e=new te;for(let n=0;n<t.length;n++)e.expandToInclude(t[n]);return e}static toCoordinateArray(t){return t.toArray(Le.coordArrayType)}static dimension(t){if(t===null||t.length===0)return 3;let e=0;for(const n of t)e=Math.max(e,il.dimension(n));return e}static atLeastNCoordinatesOrNothing(t,e){return e.length>=t?e:[]}static indexOf(t,e){for(let n=0;n<e.length;n++)if(t.equals(e[n]))return n;return-1}static increasingDirection(t){for(let e=0;e<Math.trunc(t.length/2);e++){const n=t.length-1-e,s=t[e].compareTo(t[n]);if(s!==0)return s}return 1}static compare(t,e){let n=0;for(;n<t.length&&n<e.length;){const s=t[n].compareTo(e[n]);if(s!==0)return s;n++}return n<e.length?-1:n<t.length?1:0}static minCoordinate(t){let e=null;for(let n=0;n<t.length;n++)(e===null||e.compareTo(t[n])>0)&&(e=t[n]);return e}static extract(t,e,n){e=Oo.clamp(e,0,t.length),n=Oo.clamp(n,-1,t.length);let s=n-e+1;n<0&&(s=0),e>=t.length&&(s=0),n<e&&(s=0);const r=new Array(s).fill(null);if(s===0)return r;let o=0;for(let a=e;a<=n;a++)r[o++]=t[a];return r}}class CA{compare(t,e){const n=t,s=e;return Le.compare(n,s)}get interfaces_(){return[Kr]}}class PA{compare(t,e){const n=t,s=e;if(n.length<s.length)return-1;if(n.length>s.length)return 1;if(n.length===0)return 0;const r=Le.compare(n,s);return Le.isEqualReversed(n,s)?0:r}OLDcompare(t,e){const n=t,s=e;if(n.length<s.length)return-1;if(n.length>s.length)return 1;if(n.length===0)return 0;const r=Le.increasingDirection(n),o=Le.increasingDirection(s);let a=r>0?0:n.length-1,l=o>0?0:n.length-1;for(let h=0;h<n.length;h++){const f=n[a].compareTo(s[l]);if(f!==0)return f;a+=r,l+=o}return 0}get interfaces_(){return[Kr]}}Le.ForwardComparator=CA;Le.BidirectionalComparator=PA;Le.coordArrayType=new Array(0).fill(null);class jf{constructor(t){this.str=t}append(t){this.str+=t}setCharAt(t,e){this.str=this.str.substr(0,t)+e+this.str.substr(t+1)}toString(){return this.str}}class _s{constructor(){_s.constructor_.apply(this,arguments)}static constructor_(){if(this._dimension=3,this._measures=0,this._coordinates=null,arguments.length===1){if(arguments[0]instanceof Array){const t=arguments[0];_s.constructor_.call(this,t,Le.dimension(t),Le.measures(t))}else if(Number.isInteger(arguments[0])){const t=arguments[0];this._coordinates=new Array(t).fill(null);for(let e=0;e<t;e++)this._coordinates[e]=new Z}else if(Ot(arguments[0],de)){const t=arguments[0];if(t===null)return this._coordinates=new Array(0).fill(null),null;this._dimension=t.getDimension(),this._measures=t.getMeasures(),this._coordinates=new Array(t.size()).fill(null);for(let e=0;e<this._coordinates.length;e++)this._coordinates[e]=t.getCoordinateCopy(e)}}else if(arguments.length===2){if(arguments[0]instanceof Array&&Number.isInteger(arguments[1])){const t=arguments[0],e=arguments[1];_s.constructor_.call(this,t,e,Le.measures(t))}else if(Number.isInteger(arguments[0])&&Number.isInteger(arguments[1])){const t=arguments[0],e=arguments[1];this._coordinates=new Array(t).fill(null),this._dimension=e;for(let n=0;n<t;n++)this._coordinates[n]=il.create(e)}}else if(arguments.length===3){if(Number.isInteger(arguments[2])&&arguments[0]instanceof Array&&Number.isInteger(arguments[1])){const t=arguments[0],e=arguments[1],n=arguments[2];this._dimension=e,this._measures=n,t===null?this._coordinates=new Array(0).fill(null):this._coordinates=t}else if(Number.isInteger(arguments[2])&&Number.isInteger(arguments[0])&&Number.isInteger(arguments[1])){const t=arguments[0],e=arguments[1],n=arguments[2];this._coordinates=new Array(t).fill(null),this._dimension=e,this._measures=n;for(let s=0;s<t;s++)this._coordinates[s]=this.createCoordinate()}}}getM(t){return this.hasM()?this._coordinates[t].getM():Rt.NaN}setOrdinate(t,e,n){switch(e){case de.X:this._coordinates[t].x=n;break;case de.Y:this._coordinates[t].y=n;break;default:this._coordinates[t].setOrdinate(e,n)}}getZ(t){return this.hasZ()?this._coordinates[t].getZ():Rt.NaN}size(){return this._coordinates.length}getOrdinate(t,e){switch(e){case de.X:return this._coordinates[t].x;case de.Y:return this._coordinates[t].y;default:return this._coordinates[t].getOrdinate(e)}}getCoordinate(){if(arguments.length===1){const t=arguments[0];return this._coordinates[t]}else if(arguments.length===2){const t=arguments[0];arguments[1].setCoordinate(this._coordinates[t])}}getCoordinateCopy(t){const e=this.createCoordinate();return e.setCoordinate(this._coordinates[t]),e}createCoordinate(){return il.create(this.getDimension(),this.getMeasures())}getDimension(){return this._dimension}getX(t){return this._coordinates[t].x}getMeasures(){return this._measures}expandEnvelope(t){for(let e=0;e<this._coordinates.length;e++)t.expandToInclude(this._coordinates[e]);return t}copy(){const t=new Array(this.size()).fill(null);for(let e=0;e<this._coordinates.length;e++){const n=this.createCoordinate();n.setCoordinate(this._coordinates[e]),t[e]=n}return new _s(t,this._dimension,this._measures)}toString(){if(this._coordinates.length>0){const t=new jf(17*this._coordinates.length);t.append("("),t.append(this._coordinates[0]);for(let e=1;e<this._coordinates.length;e++)t.append(", "),t.append(this._coordinates[e]);return t.append(")"),t.toString()}else return"()"}getY(t){return this._coordinates[t].y}toCoordinateArray(){return this._coordinates}get interfaces_(){return[de,mi]}}class sl{static instance(){return sl.instanceObject}readResolve(){return sl.instance()}create(){if(arguments.length===1){if(arguments[0]instanceof Array){const t=arguments[0];return new _s(t)}else if(Ot(arguments[0],de)){const t=arguments[0];return new _s(t)}}else if(arguments.length===2){let t=arguments[0],e=arguments[1];return e>3&&(e=3),e<2&&(e=2),new _s(t,e)}else if(arguments.length===3){let t=arguments[0],e=arguments[1],n=arguments[2],s=e-n;return n>1&&(n=1),s>3&&(s=3),s<2&&(s=2),new _s(t,s+n,n)}}get interfaces_(){return[pw,mi]}}sl.instanceObject=new sl;class hi extends ye{constructor(){super(),hi.constructor_.apply(this,arguments)}static constructor_(){const t=arguments[0],e=arguments[1];ye.constructor_.call(this,t,e)}copyInternal(){const t=new Array(this._geometries.length).fill(null);for(let e=0;e<t.length;e++)t[e]=this._geometries[e].copy();return new hi(t,this._factory)}equalsExact(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof dt){const t=arguments[0],e=arguments[1];return this.isEquivalentClass(t)?super.equalsExact.call(this,t,e):!1}else return super.equalsExact.apply(this,arguments)}getBoundaryDimension(){return 1}getTypeCode(){return dt.TYPECODE_MULTIPOLYGON}getDimension(){return 2}getBoundary(){if(this.isEmpty())return this.getFactory().createMultiLineString();const t=new vt;for(let n=0;n<this._geometries.length;n++){const r=this._geometries[n].getBoundary();for(let o=0;o<r.getNumGeometries();o++)t.add(r.getGeometryN(o))}const e=new Array(t.size()).fill(null);return this.getFactory().createMultiLineString(t.toArray(e))}getGeometryType(){return dt.TYPENAME_MULTIPOLYGON}get interfaces_(){return[Jr]}}let ww=class{get(){}put(){}size(){}values(){}entrySet(){}};class _c extends Ew{constructor(t){super(),this.map=new Map,t instanceof sn&&this.addAll(t)}contains(t){const e=t.hashCode?t.hashCode():t;return!!this.map.has(e)}add(t){const e=t.hashCode?t.hashCode():t;return this.map.has(e)?!1:!!this.map.set(e,t)}addAll(t){for(const e of t)this.add(e);return!0}remove(){throw new ss}size(){return this.map.size}isEmpty(){return this.map.size===0}toArray(){return Array.from(this.map.values())}iterator(){return new kA(this.map)}[Symbol.iterator](){return this.map}}let kA=class{constructor(t){this.iterator=t.values();const{done:e,value:n}=this.iterator.next();this.done=e,this.value=n}next(){if(this.done)throw new vl;const t=this.value,{done:e,value:n}=this.iterator.next();return this.done=e,this.value=n,t}hasNext(){return!this.done}remove(){throw new ss}};class xw extends ww{constructor(){super(),this.map=new Map}get(t){return this.map.get(t)||null}put(t,e){return this.map.set(t,e),e}values(){const t=new vt,e=this.map.values();let n=e.next();for(;!n.done;)t.add(n.value),n=e.next();return t}entrySet(){const t=new _c;return this.map.entries().forEach(e=>t.add(e)),t}size(){return this.map.size()}}class Ee{constructor(){Ee.constructor_.apply(this,arguments)}static constructor_(){if(this._modelType=null,this._scale=null,arguments.length===0)this._modelType=Ee.FLOATING;else if(arguments.length===1){if(arguments[0]instanceof Ys){const t=arguments[0];this._modelType=t,t===Ee.FIXED&&this.setScale(1)}else if(typeof arguments[0]=="number"){const t=arguments[0];this._modelType=Ee.FIXED,this.setScale(t)}else if(arguments[0]instanceof Ee){const t=arguments[0];this._modelType=t._modelType,this._scale=t._scale}}}static mostPrecise(t,e){return t.compareTo(e)>=0?t:e}equals(t){if(!(t instanceof Ee))return!1;const e=t;return this._modelType===e._modelType&&this._scale===e._scale}compareTo(t){const e=t,n=this.getMaximumSignificantDigits(),s=e.getMaximumSignificantDigits();return nl.compare(n,s)}getScale(){return this._scale}isFloating(){return this._modelType===Ee.FLOATING||this._modelType===Ee.FLOATING_SINGLE}getType(){return this._modelType}toString(){let t="UNKNOWN";return this._modelType===Ee.FLOATING?t="Floating":this._modelType===Ee.FLOATING_SINGLE?t="Floating-Single":this._modelType===Ee.FIXED&&(t="Fixed (Scale="+this.getScale()+")"),t}makePrecise(){if(typeof arguments[0]=="number"){const t=arguments[0];return Rt.isNaN(t)||this._modelType===Ee.FLOATING_SINGLE?t:this._modelType===Ee.FIXED?Math.round(t*this._scale)/this._scale:t}else if(arguments[0]instanceof Z){const t=arguments[0];if(this._modelType===Ee.FLOATING)return null;t.x=this.makePrecise(t.x),t.y=this.makePrecise(t.y)}}getMaximumSignificantDigits(){let t=16;return this._modelType===Ee.FLOATING?t=16:this._modelType===Ee.FLOATING_SINGLE?t=6:this._modelType===Ee.FIXED&&(t=1+Math.trunc(Math.ceil(Math.log(this.getScale())/Math.log(10)))),t}setScale(t){this._scale=Math.abs(t)}get interfaces_(){return[mi,gi]}}class Ys{constructor(){Ys.constructor_.apply(this,arguments)}static constructor_(){this._name=null;const t=arguments[0];this._name=t,Ys.nameToTypeMap.put(t,this)}readResolve(){return Ys.nameToTypeMap.get(this._name)}toString(){return this._name}get interfaces_(){return[mi]}}Ys.nameToTypeMap=new xw;Ee.Type=Ys;Ee.FIXED=new Ys("FIXED");Ee.FLOATING=new Ys("FLOATING");Ee.FLOATING_SINGLE=new Ys("FLOATING SINGLE");Ee.maximumPreciseValue=9007199254740992;class ns extends ye{constructor(){super(),ns.constructor_.apply(this,arguments)}static constructor_(){const t=arguments[0],e=arguments[1];ye.constructor_.call(this,t,e)}copyInternal(){const t=new Array(this._geometries.length).fill(null);for(let e=0;e<t.length;e++)t[e]=this._geometries[e].copy();return new ns(t,this._factory)}equalsExact(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof dt){const t=arguments[0],e=arguments[1];return this.isEquivalentClass(t)?super.equalsExact.call(this,t,e):!1}else return super.equalsExact.apply(this,arguments)}getBoundaryDimension(){return this.isClosed()?pt.FALSE:0}isClosed(){if(this.isEmpty())return!1;for(let t=0;t<this._geometries.length;t++)if(!this._geometries[t].isClosed())return!1;return!0}getTypeCode(){return dt.TYPECODE_MULTILINESTRING}getDimension(){return 1}getBoundary(){throw new ss}getGeometryType(){return dt.TYPENAME_MULTILINESTRING}get interfaces_(){return[_w]}}class ze{constructor(){ze.constructor_.apply(this,arguments)}static constructor_(){if(this._precisionModel=null,this._coordinateSequenceFactory=null,this._SRID=null,arguments.length===0)ze.constructor_.call(this,new Ee,0);else if(arguments.length===1){if(Ot(arguments[0],pw)){const t=arguments[0];ze.constructor_.call(this,new Ee,0,t)}else if(arguments[0]instanceof Ee){const t=arguments[0];ze.constructor_.call(this,t,0,ze.getDefaultCoordinateSequenceFactory())}}else if(arguments.length===2){const t=arguments[0],e=arguments[1];ze.constructor_.call(this,t,e,ze.getDefaultCoordinateSequenceFactory())}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];this._precisionModel=t,this._coordinateSequenceFactory=n,this._SRID=e}}static toMultiPolygonArray(t){const e=new Array(t.size()).fill(null);return t.toArray(e)}static toGeometryArray(t){if(t===null)return null;const e=new Array(t.size()).fill(null);return t.toArray(e)}static getDefaultCoordinateSequenceFactory(){return sl.instance()}static toMultiLineStringArray(t){const e=new Array(t.size()).fill(null);return t.toArray(e)}static toLineStringArray(t){const e=new Array(t.size()).fill(null);return t.toArray(e)}static toMultiPointArray(t){const e=new Array(t.size()).fill(null);return t.toArray(e)}static toLinearRingArray(t){const e=new Array(t.size()).fill(null);return t.toArray(e)}static toPointArray(t){const e=new Array(t.size()).fill(null);return t.toArray(e)}static toPolygonArray(t){const e=new Array(t.size()).fill(null);return t.toArray(e)}static createPointFromInternalCoord(t,e){return e.getPrecisionModel().makePrecise(t),e.getFactory().createPoint(t)}createEmpty(t){switch(t){case-1:return this.createGeometryCollection();case 0:return this.createPoint();case 1:return this.createLineString();case 2:return this.createPolygon();default:throw new Zt("Invalid dimension: "+t)}}toGeometry(t){return t.isNull()?this.createPoint():t.getMinX()===t.getMaxX()&&t.getMinY()===t.getMaxY()?this.createPoint(new Z(t.getMinX(),t.getMinY())):t.getMinX()===t.getMaxX()||t.getMinY()===t.getMaxY()?this.createLineString([new Z(t.getMinX(),t.getMinY()),new Z(t.getMaxX(),t.getMaxY())]):this.createPolygon(this.createLinearRing([new Z(t.getMinX(),t.getMinY()),new Z(t.getMinX(),t.getMaxY()),new Z(t.getMaxX(),t.getMaxY()),new Z(t.getMaxX(),t.getMinY()),new Z(t.getMinX(),t.getMinY())]),null)}createLineString(){if(arguments.length===0)return this.createLineString(this.getCoordinateSequenceFactory().create([]));if(arguments.length===1){if(arguments[0]instanceof Array){const t=arguments[0];return this.createLineString(t!==null?this.getCoordinateSequenceFactory().create(t):null)}else if(Ot(arguments[0],de)){const t=arguments[0];return new ce(t,this)}}}createMultiLineString(){if(arguments.length===0)return new ns(null,this);if(arguments.length===1){const t=arguments[0];return new ns(t,this)}}buildGeometry(t){let e=null,n=!1,s=!1;for(let a=t.iterator();a.hasNext();){const l=a.next(),h=l.getTypeCode();e===null&&(e=h),h!==e&&(n=!0),l instanceof ye&&(s=!0)}if(e===null)return this.createGeometryCollection();if(n||s)return this.createGeometryCollection(ze.toGeometryArray(t));const r=t.iterator().next();if(t.size()>1){if(r instanceof Te)return this.createMultiPolygon(ze.toPolygonArray(t));if(r instanceof ce)return this.createMultiLineString(ze.toLineStringArray(t));if(r instanceof Ge)return this.createMultiPoint(ze.toPointArray(t));Yt.shouldNeverReachHere("Unhandled geometry type: "+r.getGeometryType())}return r}createMultiPointFromCoords(t){return this.createMultiPoint(t!==null?this.getCoordinateSequenceFactory().create(t):null)}createPoint(){if(arguments.length===0)return this.createPoint(this.getCoordinateSequenceFactory().create([]));if(arguments.length===1){if(arguments[0]instanceof Z){const t=arguments[0];return this.createPoint(t!==null?this.getCoordinateSequenceFactory().create([t]):null)}else if(Ot(arguments[0],de)){const t=arguments[0];return new Ge(t,this)}}}getCoordinateSequenceFactory(){return this._coordinateSequenceFactory}createPolygon(){if(arguments.length===0)return this.createPolygon(null,null);if(arguments.length===1){if(Ot(arguments[0],de)){const t=arguments[0];return this.createPolygon(this.createLinearRing(t))}else if(arguments[0]instanceof Array){const t=arguments[0];return this.createPolygon(this.createLinearRing(t))}else if(arguments[0]instanceof fn){const t=arguments[0];return this.createPolygon(t,null)}}else if(arguments.length===2){const t=arguments[0],e=arguments[1];return new Te(t,e,this)}}getSRID(){return this._SRID}createGeometryCollection(){if(arguments.length===0)return new ye(null,this);if(arguments.length===1){const t=arguments[0];return new ye(t,this)}}getPrecisionModel(){return this._precisionModel}createLinearRing(){if(arguments.length===0)return this.createLinearRing(this.getCoordinateSequenceFactory().create([]));if(arguments.length===1){if(arguments[0]instanceof Array){const t=arguments[0];return this.createLinearRing(t!==null?this.getCoordinateSequenceFactory().create(t):null)}else if(Ot(arguments[0],de)){const t=arguments[0];return new fn(t,this)}}}createMultiPolygon(){if(arguments.length===0)return new hi(null,this);if(arguments.length===1){const t=arguments[0];return new hi(t,this)}}createMultiPoint(){if(arguments.length===0)return new Ss(null,this);if(arguments.length===1){if(arguments[0]instanceof Array){const t=arguments[0];return new Ss(t,this)}else if(Ot(arguments[0],de)){const t=arguments[0];if(t===null)return this.createMultiPoint(new Array(0).fill(null));const e=new Array(t.size()).fill(null);for(let n=0;n<t.size();n++){const s=this.getCoordinateSequenceFactory().create(1,t.getDimension(),t.getMeasures());tn.copy(t,n,s,0,1),e[n]=this.createPoint(s)}return this.createMultiPoint(e)}}}get interfaces_(){return[mi]}}const TA=["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon"];class bw{constructor(t){this.geometryFactory=t||new ze}read(t){let e;typeof t=="string"?e=JSON.parse(t):e=t;const n=e.type;if(!Xi[n])throw new Error("Unknown GeoJSON type: "+e.type);return TA.indexOf(n)!==-1?Xi[n].call(this,e.coordinates):n==="GeometryCollection"?Xi[n].call(this,e.geometries):Xi[n].call(this,e)}write(t){const e=t.getGeometryType();if(!As[e])throw new Error("Geometry is not supported");return As[e].call(this,t)}}const Xi={Feature:function(i){const t={};for(const e in i)t[e]=i[e];if(i.geometry){const e=i.geometry.type;if(!Xi[e])throw new Error("Unknown GeoJSON type: "+i.type);t.geometry=this.read(i.geometry)}return i.bbox&&(t.bbox=Xi.bbox.call(this,i.bbox)),t},FeatureCollection:function(i){const t={};if(i.features){t.features=[];for(let e=0;e<i.features.length;++e)t.features.push(this.read(i.features[e]))}return i.bbox&&(t.bbox=this.parse.bbox.call(this,i.bbox)),t},coordinates:function(i){const t=[];for(let e=0;e<i.length;++e){const n=i[e];t.push(new Z(...n))}return t},bbox:function(i){return this.geometryFactory.createLinearRing([new Z(i[0],i[1]),new Z(i[2],i[1]),new Z(i[2],i[3]),new Z(i[0],i[3]),new Z(i[0],i[1])])},Point:function(i){const t=new Z(...i);return this.geometryFactory.createPoint(t)},MultiPoint:function(i){const t=[];for(let e=0;e<i.length;++e)t.push(Xi.Point.call(this,i[e]));return this.geometryFactory.createMultiPoint(t)},LineString:function(i){const t=Xi.coordinates.call(this,i);return this.geometryFactory.createLineString(t)},MultiLineString:function(i){const t=[];for(let e=0;e<i.length;++e)t.push(Xi.LineString.call(this,i[e]));return this.geometryFactory.createMultiLineString(t)},Polygon:function(i){const t=Xi.coordinates.call(this,i[0]),e=this.geometryFactory.createLinearRing(t),n=[];for(let s=1;s<i.length;++s){const r=i[s],o=Xi.coordinates.call(this,r),a=this.geometryFactory.createLinearRing(o);n.push(a)}return this.geometryFactory.createPolygon(e,n)},MultiPolygon:function(i){const t=[];for(let e=0;e<i.length;++e){const n=i[e];t.push(Xi.Polygon.call(this,n))}return this.geometryFactory.createMultiPolygon(t)},GeometryCollection:function(i){const t=[];for(let e=0;e<i.length;++e){const n=i[e];t.push(this.read(n))}return this.geometryFactory.createGeometryCollection(t)}},As={coordinate:function(i){const t=[i.x,i.y];return i.z&&t.push(i.z),i.m&&t.push(i.m),t},Point:function(i){return{type:"Point",coordinates:As.coordinate.call(this,i.getCoordinate())}},MultiPoint:function(i){const t=[];for(let e=0;e<i._geometries.length;++e){const n=i._geometries[e],s=As.Point.call(this,n);t.push(s.coordinates)}return{type:"MultiPoint",coordinates:t}},LineString:function(i){const t=[],e=i.getCoordinates();for(let n=0;n<e.length;++n){const s=e[n];t.push(As.coordinate.call(this,s))}return{type:"LineString",coordinates:t}},MultiLineString:function(i){const t=[];for(let e=0;e<i._geometries.length;++e){const n=i._geometries[e],s=As.LineString.call(this,n);t.push(s.coordinates)}return{type:"MultiLineString",coordinates:t}},Polygon:function(i){const t=[],e=As.LineString.call(this,i._shell);t.push(e.coordinates);for(let n=0;n<i._holes.length;++n){const s=i._holes[n],r=As.LineString.call(this,s);t.push(r.coordinates)}return{type:"Polygon",coordinates:t}},MultiPolygon:function(i){const t=[];for(let e=0;e<i._geometries.length;++e){const n=i._geometries[e],s=As.Polygon.call(this,n);t.push(s.coordinates)}return{type:"MultiPolygon",coordinates:t}},GeometryCollection:function(i){const t=[];for(let e=0;e<i._geometries.length;++e){const n=i._geometries[e],s=n.getGeometryType();t.push(As[s].call(this,n))}return{type:"GeometryCollection",geometries:t}}};class Vf{constructor(t){this.parser=new bw(t||new ze)}read(t){return this.parser.read(t)}}class Iw{constructor(){this.parser=new bw(this.geometryFactory)}write(t){return this.parser.write(t)}}const na={XY:"XY",XYZ:"XYZ",XYM:"XYM",XYZM:"XYZM"},y_={POINT:"Point",LINE_STRING:"LineString",LINEAR_RING:"LinearRing",POLYGON:"Polygon",MULTI_POINT:"MultiPoint",MULTI_LINE_STRING:"MultiLineString",MULTI_POLYGON:"MultiPolygon",GEOMETRY_COLLECTION:"GeometryCollection",CIRCLE:"Circle"},Sw="EMPTY",Mw="Z",Nw="M",RA="ZM",xe={TEXT:1,LEFT_PAREN:2,RIGHT_PAREN:3,NUMBER:4,COMMA:5,EOF:6};for(const i in y_)y_[i].toUpperCase();class AA{constructor(t){this.wkt=t,this.index_=-1}isAlpha_(t){return t>="a"&&t<="z"||t>="A"&&t<="Z"}isNumeric_(t,e){const n=e!==void 0?e:!1;return t>="0"&&t<="9"||t=="."&&!n}isWhiteSpace_(t){return t==" "||t==" "||t=="\r"||t==`
|
|
12
|
+
`}nextChar_(){return this.wkt.charAt(++this.index_)}nextToken(){const t=this.nextChar_(),e=this.index_;let n=t,s;if(t=="(")s=xe.LEFT_PAREN;else if(t==",")s=xe.COMMA;else if(t==")")s=xe.RIGHT_PAREN;else if(this.isNumeric_(t)||t=="-")s=xe.NUMBER,n=this.readNumber_();else if(this.isAlpha_(t))s=xe.TEXT,n=this.readText_();else{if(this.isWhiteSpace_(t))return this.nextToken();if(t==="")s=xe.EOF;else throw new Error("Unexpected character: "+t)}return{position:e,value:n,type:s}}readNumber_(){let t;const e=this.index_;let n=!1,s=!1;do t=="."?n=!0:(t=="e"||t=="E")&&(s=!0),t=this.nextChar_();while(this.isNumeric_(t,n)||!s&&(t=="e"||t=="E")||s&&(t=="-"||t=="+"));return parseFloat(this.wkt.substring(e,this.index_--))}readText_(){let t;const e=this.index_;do t=this.nextChar_();while(this.isAlpha_(t));return this.wkt.substring(e,this.index_--).toUpperCase()}}let OA=class{constructor(t,e){this.lexer_=t,this.token_,this.layout_=na.XY,this.factory=e}consume_(){this.token_=this.lexer_.nextToken()}isTokenType(t){return this.token_.type==t}match(t){const e=this.isTokenType(t);return e&&this.consume_(),e}parse(){return this.consume_(),this.parseGeometry_()}parseGeometryLayout_(){let t=na.XY;const e=this.token_;if(this.isTokenType(xe.TEXT)){const n=e.value;n===Mw?t=na.XYZ:n===Nw?t=na.XYM:n===RA&&(t=na.XYZM),t!==na.XY&&this.consume_()}return t}parseGeometryCollectionText_(){if(this.match(xe.LEFT_PAREN)){const t=[];do t.push(this.parseGeometry_());while(this.match(xe.COMMA));if(this.match(xe.RIGHT_PAREN))return t}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}parsePointText_(){if(this.match(xe.LEFT_PAREN)){const t=this.parsePoint_();if(this.match(xe.RIGHT_PAREN))return t}else if(this.isEmptyGeometry_())return null;throw new Error(this.formatErrorMessage_())}parseLineStringText_(){if(this.match(xe.LEFT_PAREN)){const t=this.parsePointList_();if(this.match(xe.RIGHT_PAREN))return t}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}parsePolygonText_(){if(this.match(xe.LEFT_PAREN)){const t=this.parseLineStringTextList_();if(this.match(xe.RIGHT_PAREN))return t}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}parseMultiPointText_(){if(this.match(xe.LEFT_PAREN)){let t;if(this.token_.type==xe.LEFT_PAREN?t=this.parsePointTextList_():t=this.parsePointList_(),this.match(xe.RIGHT_PAREN))return t}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}parseMultiLineStringText_(){if(this.match(xe.LEFT_PAREN)){const t=this.parseLineStringTextList_();if(this.match(xe.RIGHT_PAREN))return t}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}parseMultiPolygonText_(){if(this.match(xe.LEFT_PAREN)){const t=this.parsePolygonTextList_();if(this.match(xe.RIGHT_PAREN))return t}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}parsePoint_(){const t=[],e=this.layout_.length;for(let n=0;n<e;++n){const s=this.token_;if(this.match(xe.NUMBER))t.push(s.value);else break}if(t.length==e)return t;throw new Error(this.formatErrorMessage_())}parsePointList_(){const t=[this.parsePoint_()];for(;this.match(xe.COMMA);)t.push(this.parsePoint_());return t}parsePointTextList_(){const t=[this.parsePointText_()];for(;this.match(xe.COMMA);)t.push(this.parsePointText_());return t}parseLineStringTextList_(){const t=[this.parseLineStringText_()];for(;this.match(xe.COMMA);)t.push(this.parseLineStringText_());return t}parsePolygonTextList_(){const t=[this.parsePolygonText_()];for(;this.match(xe.COMMA);)t.push(this.parsePolygonText_());return t}isEmptyGeometry_(){const t=this.isTokenType(xe.TEXT)&&this.token_.value==Sw;return t&&this.consume_(),t}formatErrorMessage_(){return"Unexpected `"+this.token_.value+"` at position "+this.token_.position+" in `"+this.lexer_.wkt+"`"}parseGeometry_(){const t=this.factory,e=r=>new Z(...r),n=r=>{const o=r.map(a=>t.createLinearRing(a.map(e)));return o.length>1?t.createPolygon(o[0],o.slice(1)):t.createPolygon(o[0])},s=this.token_;if(this.match(xe.TEXT)){const r=s.value;if(this.layout_=this.parseGeometryLayout_(),r=="GEOMETRYCOLLECTION"){const o=this.parseGeometryCollectionText_();return t.createGeometryCollection(o)}else switch(r){case"POINT":{const o=this.parsePointText_();return o?t.createPoint(new Z(...o)):t.createPoint()}case"LINESTRING":{const a=this.parseLineStringText_().map(e);return t.createLineString(a)}case"LINEARRING":{const a=this.parseLineStringText_().map(e);return t.createLinearRing(a)}case"POLYGON":{const o=this.parsePolygonText_();return!o||o.length===0?t.createPolygon():n(o)}case"MULTIPOINT":{const o=this.parseMultiPointText_();if(!o||o.length===0)return t.createMultiPoint();const a=o.map(e).map(l=>t.createPoint(l));return t.createMultiPoint(a)}case"MULTILINESTRING":{const a=this.parseMultiLineStringText_().map(l=>t.createLineString(l.map(e)));return t.createMultiLineString(a)}case"MULTIPOLYGON":{const o=this.parseMultiPolygonText_();if(!o||o.length===0)return t.createMultiPolygon();const a=o.map(n);return t.createMultiPolygon(a)}default:throw new Error("Invalid geometry type: "+r)}}throw new Error(this.formatErrorMessage_())}};function Lw(i){if(i.isEmpty())return"";const t=i.getCoordinate(),e=[t.x,t.y];return t.z!==void 0&&!Number.isNaN(t.z)&&e.push(t.z),t.m!==void 0&&!Number.isNaN(t.m)&&e.push(t.m),e.join(" ")}function FA(i){const t=[];for(let e=0,n=i.getNumGeometries();e<n;++e)t.push("("+Lw(i.getGeometryN(e))+")");return t.join(", ")}function $A(i){const t=[];for(let e=0,n=i.getNumGeometries();e<n;++e)t.push(Pw(i.getGeometryN(e)));return t.join(", ")}function $u(i){const t=i.getCoordinates().map(n=>{const s=[n.x,n.y];return n.z!==void 0&&!Number.isNaN(n.z)&&s.push(n.z),n.m!==void 0&&!Number.isNaN(n.m)&&s.push(n.m),s}),e=[];for(let n=0,s=t.length;n<s;++n)e.push(t[n].join(" "));return e.join(", ")}function DA(i){const t=[];for(let e=0,n=i.getNumGeometries();e<n;++e)t.push("("+$u(i.getGeometryN(e))+")");return t.join(", ")}function Cw(i){const t=[];t.push("("+$u(i.getExteriorRing())+")");for(let e=0,n=i.getNumInteriorRing();e<n;++e)t.push("("+$u(i.getInteriorRingN(e))+")");return t.join(", ")}function GA(i){const t=[];for(let e=0,n=i.getNumGeometries();e<n;++e)t.push("("+Cw(i.getGeometryN(e))+")");return t.join(", ")}function BA(i){let t="";if(i.isEmpty())return t;const e=i.getCoordinate();return e.z!==void 0&&!Number.isNaN(e.z)&&(t+=Mw),e.m!==void 0&&!Number.isNaN(e.m)&&(t+=Nw),t}const qA={Point:Lw,LineString:$u,LinearRing:$u,Polygon:Cw,MultiPoint:FA,MultiLineString:DA,MultiPolygon:GA,GeometryCollection:$A};function Pw(i){let t=i.getGeometryType();const e=qA[t];t=t.toUpperCase();const n=BA(i);if(n.length>0&&(t+=" "+n),i.isEmpty())return t+" "+Sw;const s=e(i);return t+" ("+s+")"}class zA{constructor(t){this.geometryFactory=t||new ze,this.precisionModel=this.geometryFactory.getPrecisionModel()}read(t){const e=new AA(t);return new OA(e,this.geometryFactory).parse()}write(t){return Pw(t)}}class Js{constructor(t){this.parser=new zA(t)}write(t){return this.parser.write(t)}static toLineString(t,e){if(arguments.length!==2)throw new Error("Not implemented");return"LINESTRING ( "+t.x+" "+t.y+", "+e.x+" "+e.y+" )"}}class ie{constructor(){ie.constructor_.apply(this,arguments)}static constructor_(){if(this._quadrantSegments=ie.DEFAULT_QUADRANT_SEGMENTS,this._endCapStyle=ie.CAP_ROUND,this._joinStyle=ie.JOIN_ROUND,this._mitreLimit=ie.DEFAULT_MITRE_LIMIT,this._isSingleSided=!1,this._simplifyFactor=ie.DEFAULT_SIMPLIFY_FACTOR,arguments.length!==0){if(arguments.length===1){const t=arguments[0];this.setQuadrantSegments(t)}else if(arguments.length===2){const t=arguments[0],e=arguments[1];this.setQuadrantSegments(t),this.setEndCapStyle(e)}else if(arguments.length===4){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3];this.setQuadrantSegments(t),this.setEndCapStyle(e),this.setJoinStyle(n),this.setMitreLimit(s)}}}static bufferDistanceError(t){const e=Math.PI/2/t;return 1-Math.cos(e/2)}getEndCapStyle(){return this._endCapStyle}isSingleSided(){return this._isSingleSided}setQuadrantSegments(t){this._quadrantSegments=t,this._quadrantSegments===0&&(this._joinStyle=ie.JOIN_BEVEL),this._quadrantSegments<0&&(this._joinStyle=ie.JOIN_MITRE,this._mitreLimit=Math.abs(this._quadrantSegments)),t<=0&&(this._quadrantSegments=1),this._joinStyle!==ie.JOIN_ROUND&&(this._quadrantSegments=ie.DEFAULT_QUADRANT_SEGMENTS)}getJoinStyle(){return this._joinStyle}setJoinStyle(t){this._joinStyle=t}setSimplifyFactor(t){this._simplifyFactor=t<0?0:t}getSimplifyFactor(){return this._simplifyFactor}getQuadrantSegments(){return this._quadrantSegments}setEndCapStyle(t){this._endCapStyle=t}getMitreLimit(){return this._mitreLimit}setMitreLimit(t){this._mitreLimit=t}setSingleSided(t){this._isSingleSided=t}}ie.CAP_ROUND=1;ie.CAP_FLAT=2;ie.CAP_SQUARE=3;ie.JOIN_ROUND=1;ie.JOIN_MITRE=2;ie.JOIN_BEVEL=3;ie.DEFAULT_QUADRANT_SEGMENTS=8;ie.DEFAULT_MITRE_LIMIT=5;ie.DEFAULT_SIMPLIFY_FACTOR=.01;class q{static toLocationSymbol(t){switch(t){case q.EXTERIOR:return"e";case q.BOUNDARY:return"b";case q.INTERIOR:return"i";case q.NONE:return"-"}throw new Zt("Unknown location value: "+t)}}q.INTERIOR=0;q.BOUNDARY=1;q.EXTERIOR=2;q.NONE=-1;class yt{static opposite(t){return t===yt.LEFT?yt.RIGHT:t===yt.RIGHT?yt.LEFT:t}}yt.ON=0;yt.LEFT=1;yt.RIGHT=2;class uf extends Is{constructor(t){super(t),this.name=Object.keys({EmptyStackException:uf})[0]}}class kw extends Pi{constructor(){super(),this.array=[]}add(t){return this.array.push(t),!0}get(t){if(t<0||t>=this.size())throw new Xf;return this.array[t]}push(t){return this.array.push(t),t}pop(){if(this.array.length===0)throw new uf;return this.array.pop()}peek(){if(this.array.length===0)throw new uf;return this.array[this.array.length-1]}empty(){return this.array.length===0}isEmpty(){return this.empty()}search(t){return this.array.indexOf(t)}size(){return this.array.length}toArray(){return this.array.slice()}}class ip{constructor(){ip.constructor_.apply(this,arguments)}static constructor_(){this._minIndex=-1,this._minCoord=null,this._minDe=null,this._orientedDe=null}getCoordinate(){return this._minCoord}getRightmostSide(t,e){let n=this.getRightmostSideOfSegment(t,e);return n<0&&(n=this.getRightmostSideOfSegment(t,e-1)),n<0&&(this._minCoord=null,this.checkForRightmostCoordinate(t)),n}findRightmostEdgeAtVertex(){const t=this._minDe.getEdge().getCoordinates();Yt.isTrue(this._minIndex>0&&this._minIndex<t.length,"rightmost point expected to be interior vertex of edge");const e=t[this._minIndex-1],n=t[this._minIndex+1],s=$t.index(this._minCoord,n,e);let r=!1;(e.y<this._minCoord.y&&n.y<this._minCoord.y&&s===$t.COUNTERCLOCKWISE||e.y>this._minCoord.y&&n.y>this._minCoord.y&&s===$t.CLOCKWISE)&&(r=!0),r&&(this._minIndex=this._minIndex-1)}getRightmostSideOfSegment(t,e){const s=t.getEdge().getCoordinates();if(e<0||e+1>=s.length||s[e].y===s[e+1].y)return-1;let r=yt.LEFT;return s[e].y<s[e+1].y&&(r=yt.RIGHT),r}getEdge(){return this._orientedDe}checkForRightmostCoordinate(t){const e=t.getEdge().getCoordinates();for(let n=0;n<e.length-1;n++)(this._minCoord===null||e[n].x>this._minCoord.x)&&(this._minDe=t,this._minIndex=n,this._minCoord=e[n])}findRightmostEdgeAtNode(){const e=this._minDe.getNode().getEdges();this._minDe=e.getRightmostEdge(),this._minDe.isForward()||(this._minDe=this._minDe.getSym(),this._minIndex=this._minDe.getEdge().getCoordinates().length-1)}findEdge(t){for(let n=t.iterator();n.hasNext();){const s=n.next();s.isForward()&&this.checkForRightmostCoordinate(s)}Yt.isTrue(this._minIndex!==0||this._minCoord.equals(this._minDe.getCoordinate()),"inconsistency in rightmost processing"),this._minIndex===0?this.findRightmostEdgeAtNode():this.findRightmostEdgeAtVertex(),this._orientedDe=this._minDe,this.getRightmostSide(this._minDe,this._minIndex)===yt.LEFT&&(this._orientedDe=this._minDe.getSym())}}class ki extends ui{constructor(t,e){super(e?t+" [ "+e+" ]":t),this.pt=e?new Z(e):void 0,this.name=Object.keys({TopologyException:ki})[0]}getCoordinate(){return this.pt}}class UA{constructor(){this.array=[]}addLast(t){this.array.push(t)}removeFirst(){return this.array.shift()}isEmpty(){return this.array.length===0}}class sp{constructor(){sp.constructor_.apply(this,arguments)}static constructor_(){this._finder=null,this._dirEdgeList=new vt,this._nodes=new vt,this._rightMostCoord=null,this._env=null,this._finder=new ip}clearVisitedEdges(){for(let t=this._dirEdgeList.iterator();t.hasNext();)t.next().setVisited(!1)}getRightmostCoordinate(){return this._rightMostCoord}computeNodeDepth(t){let e=null;for(let n=t.getEdges().iterator();n.hasNext();){const s=n.next();if(s.isVisited()||s.getSym().isVisited()){e=s;break}}if(e===null)throw new ki("unable to find edge to compute depths at "+t.getCoordinate());t.getEdges().computeDepths(e);for(let n=t.getEdges().iterator();n.hasNext();){const s=n.next();s.setVisited(!0),this.copySymDepths(s)}}computeDepth(t){this.clearVisitedEdges();const e=this._finder.getEdge();e.getNode(),e.getLabel(),e.setEdgeDepths(yt.RIGHT,t),this.copySymDepths(e),this.computeDepths(e)}create(t){this.addReachable(t),this._finder.findEdge(this._dirEdgeList),this._rightMostCoord=this._finder.getCoordinate()}findResultEdges(){for(let t=this._dirEdgeList.iterator();t.hasNext();){const e=t.next();e.getDepth(yt.RIGHT)>=1&&e.getDepth(yt.LEFT)<=0&&!e.isInteriorAreaEdge()&&e.setInResult(!0)}}computeDepths(t){const e=new _c,n=new UA,s=t.getNode();for(n.addLast(s),e.add(s),t.setVisited(!0);!n.isEmpty();){const r=n.removeFirst();e.add(r),this.computeNodeDepth(r);for(let o=r.getEdges().iterator();o.hasNext();){const l=o.next().getSym();if(l.isVisited())continue;const h=l.getNode();e.contains(h)||(n.addLast(h),e.add(h))}}}compareTo(t){const e=t;return this._rightMostCoord.x<e._rightMostCoord.x?-1:this._rightMostCoord.x>e._rightMostCoord.x?1:0}getEnvelope(){if(this._env===null){const t=new te;for(let e=this._dirEdgeList.iterator();e.hasNext();){const s=e.next().getEdge().getCoordinates();for(let r=0;r<s.length-1;r++)t.expandToInclude(s[r])}this._env=t}return this._env}addReachable(t){const e=new kw;for(e.add(t);!e.empty();){const n=e.pop();this.add(n,e)}}copySymDepths(t){const e=t.getSym();e.setDepth(yt.LEFT,t.getDepth(yt.RIGHT)),e.setDepth(yt.RIGHT,t.getDepth(yt.LEFT))}add(t,e){t.setVisited(!0),this._nodes.add(t);for(let n=t.getEdges().iterator();n.hasNext();){const s=n.next();this._dirEdgeList.add(s);const o=s.getSym().getNode();o.isVisited()||e.push(o)}}getNodes(){return this._nodes}getDirectedEdges(){return this._dirEdgeList}get interfaces_(){return[gi]}}class rp{static intersection(t,e,n,s){const r=t.x<e.x?t.x:e.x,o=t.y<e.y?t.y:e.y,a=t.x>e.x?t.x:e.x,l=t.y>e.y?t.y:e.y,h=n.x<s.x?n.x:s.x,f=n.y<s.y?n.y:s.y,d=n.x>s.x?n.x:s.x,p=n.y>s.y?n.y:s.y,y=r>h?r:h,_=a<d?a:d,E=o>f?o:f,w=l<p?l:p,L=(y+_)/2,b=(E+w)/2,P=t.x-L,N=t.y-b,S=e.x-L,C=e.y-b,T=n.x-L,I=n.y-b,M=s.x-L,R=s.y-b,A=N-C,F=S-P,$=P*C-S*N,z=I-R,D=M-T,B=T*R-M*I,U=F*B-D*$,j=z*$-A*B,K=A*D-z*F,W=U/K,J=j/K;return Rt.isNaN(W)||Rt.isInfinite(W)||Rt.isNaN(J)||Rt.isInfinite(J)?null:new Z(W+L,J+b)}}class hn{static segmentToSegment(t,e,n,s){if(t.equals(e))return hn.pointToSegment(t,n,s);if(n.equals(s))return hn.pointToSegment(s,t,e);let r=!1;if(!te.intersects(t,e,n,s))r=!0;else{const o=(e.x-t.x)*(s.y-n.y)-(e.y-t.y)*(s.x-n.x);if(o===0)r=!0;else{const a=(t.y-n.y)*(s.x-n.x)-(t.x-n.x)*(s.y-n.y),h=((t.y-n.y)*(e.x-t.x)-(t.x-n.x)*(e.y-t.y))/o,f=a/o;(f<0||f>1||h<0||h>1)&&(r=!0)}}return r?Oo.min(hn.pointToSegment(t,n,s),hn.pointToSegment(e,n,s),hn.pointToSegment(n,t,e),hn.pointToSegment(s,t,e)):0}static pointToSegment(t,e,n){if(e.x===n.x&&e.y===n.y)return t.distance(e);const s=(n.x-e.x)*(n.x-e.x)+(n.y-e.y)*(n.y-e.y),r=((t.x-e.x)*(n.x-e.x)+(t.y-e.y)*(n.y-e.y))/s;if(r<=0)return t.distance(e);if(r>=1)return t.distance(n);const o=((e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y))/s;return Math.abs(o)*Math.sqrt(s)}static pointToLinePerpendicular(t,e,n){const s=(n.x-e.x)*(n.x-e.x)+(n.y-e.y)*(n.y-e.y),r=((e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y))/s;return Math.abs(r)*Math.sqrt(s)}static pointToSegmentString(t,e){if(e.length===0)throw new Zt("Line array must contain at least one vertex");let n=t.distance(e[0]);for(let s=0;s<e.length-1;s++){const r=hn.pointToSegment(t,e[s],e[s+1]);r<n&&(n=r)}return n}}class Me{constructor(){Me.constructor_.apply(this,arguments)}static constructor_(){this._result=null,this._inputLines=Array(2).fill().map(()=>Array(2)),this._intPt=new Array(2).fill(null),this._intLineIndex=null,this._isProper=null,this._pa=null,this._pb=null,this._precisionModel=null,this._intPt[0]=new Z,this._intPt[1]=new Z,this._pa=this._intPt[0],this._pb=this._intPt[1],this._result=0}static computeEdgeDistance(t,e,n){const s=Math.abs(n.x-e.x),r=Math.abs(n.y-e.y);let o=-1;if(t.equals(e))o=0;else if(t.equals(n))s>r?o=s:o=r;else{const a=Math.abs(t.x-e.x),l=Math.abs(t.y-e.y);s>r?o=a:o=l,o===0&&!t.equals(e)&&(o=Math.max(a,l))}return Yt.isTrue(!(o===0&&!t.equals(e)),"Bad distance calculation"),o}static nonRobustComputeEdgeDistance(t,e,n){const s=t.x-e.x,r=t.y-e.y,o=Math.sqrt(s*s+r*r);return Yt.isTrue(!(o===0&&!t.equals(e)),"Invalid distance calculation"),o}getIndexAlongSegment(t,e){return this.computeIntLineIndex(),this._intLineIndex[t][e]}getTopologySummary(){const t=new jf;return this.isEndPoint()&&t.append(" endpoint"),this._isProper&&t.append(" proper"),this.isCollinear()&&t.append(" collinear"),t.toString()}computeIntersection(t,e,n,s){this._inputLines[0][0]=t,this._inputLines[0][1]=e,this._inputLines[1][0]=n,this._inputLines[1][1]=s,this._result=this.computeIntersect(t,e,n,s)}getIntersectionNum(){return this._result}computeIntLineIndex(){if(arguments.length===0)this._intLineIndex===null&&(this._intLineIndex=Array(2).fill().map(()=>Array(2)),this.computeIntLineIndex(0),this.computeIntLineIndex(1));else if(arguments.length===1){const t=arguments[0],e=this.getEdgeDistance(t,0),n=this.getEdgeDistance(t,1);e>n?(this._intLineIndex[t][0]=0,this._intLineIndex[t][1]=1):(this._intLineIndex[t][0]=1,this._intLineIndex[t][1]=0)}}isProper(){return this.hasIntersection()&&this._isProper}setPrecisionModel(t){this._precisionModel=t}isInteriorIntersection(){if(arguments.length===0)return!!(this.isInteriorIntersection(0)||this.isInteriorIntersection(1));if(arguments.length===1){const t=arguments[0];for(let e=0;e<this._result;e++)if(!(this._intPt[e].equals2D(this._inputLines[t][0])||this._intPt[e].equals2D(this._inputLines[t][1])))return!0;return!1}}getIntersection(t){return this._intPt[t]}isEndPoint(){return this.hasIntersection()&&!this._isProper}hasIntersection(){return this._result!==Me.NO_INTERSECTION}getEdgeDistance(t,e){return Me.computeEdgeDistance(this._intPt[e],this._inputLines[t][0],this._inputLines[t][1])}isCollinear(){return this._result===Me.COLLINEAR_INTERSECTION}toString(){return Js.toLineString(this._inputLines[0][0],this._inputLines[0][1])+" - "+Js.toLineString(this._inputLines[1][0],this._inputLines[1][1])+this.getTopologySummary()}getEndpoint(t,e){return this._inputLines[t][e]}isIntersection(t){for(let e=0;e<this._result;e++)if(this._intPt[e].equals2D(t))return!0;return!1}getIntersectionAlongSegment(t,e){return this.computeIntLineIndex(),this._intPt[this._intLineIndex[t][e]]}}Me.DONT_INTERSECT=0;Me.DO_INTERSECT=1;Me.COLLINEAR=2;Me.NO_INTERSECTION=0;Me.POINT_INTERSECTION=1;Me.COLLINEAR_INTERSECTION=2;class Nn extends Me{constructor(){super()}static nearestEndpoint(t,e,n,s){let r=t,o=hn.pointToSegment(t,n,s),a=hn.pointToSegment(e,n,s);return a<o&&(o=a,r=e),a=hn.pointToSegment(n,t,e),a<o&&(o=a,r=n),a=hn.pointToSegment(s,t,e),a<o&&(o=a,r=s),r}isInSegmentEnvelopes(t){const e=new te(this._inputLines[0][0],this._inputLines[0][1]),n=new te(this._inputLines[1][0],this._inputLines[1][1]);return e.contains(t)&&n.contains(t)}computeIntersection(){if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];if(this._isProper=!1,te.intersects(e,n,t)&&$t.index(e,n,t)===0&&$t.index(n,e,t)===0)return this._isProper=!0,(t.equals(e)||t.equals(n))&&(this._isProper=!1),this._result=Me.POINT_INTERSECTION,null;this._result=Me.NO_INTERSECTION}else return super.computeIntersection.apply(this,arguments)}intersection(t,e,n,s){let r=this.intersectionSafe(t,e,n,s);return this.isInSegmentEnvelopes(r)||(r=new Z(Nn.nearestEndpoint(t,e,n,s))),this._precisionModel!==null&&this._precisionModel.makePrecise(r),r}checkDD(t,e,n,s,r){const o=Gs.intersection(t,e,n,s),a=this.isInSegmentEnvelopes(o);ci.out.println("DD in env = "+a+" --------------------- "+o),r.distance(o)>1e-4&&ci.out.println("Distance = "+r.distance(o))}intersectionSafe(t,e,n,s){let r=rp.intersection(t,e,n,s);return r===null&&(r=Nn.nearestEndpoint(t,e,n,s)),r}computeCollinearIntersection(t,e,n,s){const r=te.intersects(t,e,n),o=te.intersects(t,e,s),a=te.intersects(n,s,t),l=te.intersects(n,s,e);return r&&o?(this._intPt[0]=n,this._intPt[1]=s,Me.COLLINEAR_INTERSECTION):a&&l?(this._intPt[0]=t,this._intPt[1]=e,Me.COLLINEAR_INTERSECTION):r&&a?(this._intPt[0]=n,this._intPt[1]=t,n.equals(t)&&!o&&!l?Me.POINT_INTERSECTION:Me.COLLINEAR_INTERSECTION):r&&l?(this._intPt[0]=n,this._intPt[1]=e,n.equals(e)&&!o&&!a?Me.POINT_INTERSECTION:Me.COLLINEAR_INTERSECTION):o&&a?(this._intPt[0]=s,this._intPt[1]=t,s.equals(t)&&!r&&!l?Me.POINT_INTERSECTION:Me.COLLINEAR_INTERSECTION):o&&l?(this._intPt[0]=s,this._intPt[1]=e,s.equals(e)&&!r&&!a?Me.POINT_INTERSECTION:Me.COLLINEAR_INTERSECTION):Me.NO_INTERSECTION}computeIntersect(t,e,n,s){if(this._isProper=!1,!te.intersects(t,e,n,s))return Me.NO_INTERSECTION;const r=$t.index(t,e,n),o=$t.index(t,e,s);if(r>0&&o>0||r<0&&o<0)return Me.NO_INTERSECTION;const a=$t.index(n,s,t),l=$t.index(n,s,e);return a>0&&l>0||a<0&&l<0?Me.NO_INTERSECTION:r===0&&o===0&&a===0&&l===0?this.computeCollinearIntersection(t,e,n,s):(r===0||o===0||a===0||l===0?(this._isProper=!1,t.equals2D(n)||t.equals2D(s)?this._intPt[0]=t:e.equals2D(n)||e.equals2D(s)?this._intPt[0]=e:r===0?this._intPt[0]=new Z(n):o===0?this._intPt[0]=new Z(s):a===0?this._intPt[0]=new Z(t):l===0&&(this._intPt[0]=new Z(e))):(this._isProper=!0,this._intPt[0]=this.intersection(t,e,n,s)),Me.POINT_INTERSECTION)}}class Ra{constructor(){Ra.constructor_.apply(this,arguments)}static constructor_(){this._p=null,this._crossingCount=0,this._isPointOnSegment=!1;const t=arguments[0];this._p=t}static locatePointInRing(){if(arguments[0]instanceof Z&&Ot(arguments[1],de)){const t=arguments[0],e=arguments[1],n=new Ra(t),s=new Z,r=new Z;for(let o=1;o<e.size();o++)if(e.getCoordinate(o,s),e.getCoordinate(o-1,r),n.countSegment(s,r),n.isOnSegment())return n.getLocation();return n.getLocation()}else if(arguments[0]instanceof Z&&arguments[1]instanceof Array){const t=arguments[0],e=arguments[1],n=new Ra(t);for(let s=1;s<e.length;s++){const r=e[s],o=e[s-1];if(n.countSegment(r,o),n.isOnSegment())return n.getLocation()}return n.getLocation()}}countSegment(t,e){if(t.x<this._p.x&&e.x<this._p.x)return null;if(this._p.x===e.x&&this._p.y===e.y)return this._isPointOnSegment=!0,null;if(t.y===this._p.y&&e.y===this._p.y){let n=t.x,s=e.x;return n>s&&(n=e.x,s=t.x),this._p.x>=n&&this._p.x<=s&&(this._isPointOnSegment=!0),null}if(t.y>this._p.y&&e.y<=this._p.y||e.y>this._p.y&&t.y<=this._p.y){let n=$t.index(t,e,this._p);if(n===$t.COLLINEAR)return this._isPointOnSegment=!0,null;e.y<t.y&&(n=-n),n===$t.LEFT&&this._crossingCount++}}isPointInPolygon(){return this.getLocation()!==q.EXTERIOR}getLocation(){return this._isPointOnSegment?q.BOUNDARY:this._crossingCount%2===1?q.INTERIOR:q.EXTERIOR}isOnSegment(){return this._isPointOnSegment}}class ts{static isOnLine(){if(arguments[0]instanceof Z&&Ot(arguments[1],de)){const t=arguments[0],e=arguments[1],n=new Nn,s=new Z,r=new Z,o=e.size();for(let a=1;a<o;a++)if(e.getCoordinate(a-1,s),e.getCoordinate(a,r),n.computeIntersection(t,s,r),n.hasIntersection())return!0;return!1}else if(arguments[0]instanceof Z&&arguments[1]instanceof Array){const t=arguments[0],e=arguments[1],n=new Nn;for(let s=1;s<e.length;s++){const r=e[s-1],o=e[s];if(n.computeIntersection(t,r,o),n.hasIntersection())return!0}return!1}}static locateInRing(t,e){return Ra.locatePointInRing(t,e)}static isInRing(t,e){return ts.locateInRing(t,e)!==q.EXTERIOR}}class jn{constructor(){jn.constructor_.apply(this,arguments)}static constructor_(){if(this.location=null,arguments.length===1){if(arguments[0]instanceof Array){const t=arguments[0];this.init(t.length)}else if(Number.isInteger(arguments[0])){const t=arguments[0];this.init(1),this.location[yt.ON]=t}else if(arguments[0]instanceof jn){const t=arguments[0];if(this.init(t.location.length),t!==null)for(let e=0;e<this.location.length;e++)this.location[e]=t.location[e]}}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];this.init(3),this.location[yt.ON]=t,this.location[yt.LEFT]=e,this.location[yt.RIGHT]=n}}setAllLocations(t){for(let e=0;e<this.location.length;e++)this.location[e]=t}isNull(){for(let t=0;t<this.location.length;t++)if(this.location[t]!==q.NONE)return!1;return!0}setAllLocationsIfNull(t){for(let e=0;e<this.location.length;e++)this.location[e]===q.NONE&&(this.location[e]=t)}isLine(){return this.location.length===1}merge(t){if(t.location.length>this.location.length){const e=new Array(3).fill(null);e[yt.ON]=this.location[yt.ON],e[yt.LEFT]=q.NONE,e[yt.RIGHT]=q.NONE,this.location=e}for(let e=0;e<this.location.length;e++)this.location[e]===q.NONE&&e<t.location.length&&(this.location[e]=t.location[e])}getLocations(){return this.location}flip(){if(this.location.length<=1)return null;const t=this.location[yt.LEFT];this.location[yt.LEFT]=this.location[yt.RIGHT],this.location[yt.RIGHT]=t}toString(){const t=new Fu;return this.location.length>1&&t.append(q.toLocationSymbol(this.location[yt.LEFT])),t.append(q.toLocationSymbol(this.location[yt.ON])),this.location.length>1&&t.append(q.toLocationSymbol(this.location[yt.RIGHT])),t.toString()}setLocations(t,e,n){this.location[yt.ON]=t,this.location[yt.LEFT]=e,this.location[yt.RIGHT]=n}get(t){return t<this.location.length?this.location[t]:q.NONE}isArea(){return this.location.length>1}isAnyNull(){for(let t=0;t<this.location.length;t++)if(this.location[t]===q.NONE)return!0;return!1}setLocation(){if(arguments.length===1){const t=arguments[0];this.setLocation(yt.ON,t)}else if(arguments.length===2){const t=arguments[0],e=arguments[1];this.location[t]=e}}init(t){this.location=new Array(t).fill(null),this.setAllLocations(q.NONE)}isEqualOnSide(t,e){return this.location[e]===t.location[e]}allPositionsEqual(t){for(let e=0;e<this.location.length;e++)if(this.location[e]!==t)return!1;return!0}}class Be{constructor(){Be.constructor_.apply(this,arguments)}static constructor_(){if(this.elt=new Array(2).fill(null),arguments.length===1){if(Number.isInteger(arguments[0])){const t=arguments[0];this.elt[0]=new jn(t),this.elt[1]=new jn(t)}else if(arguments[0]instanceof Be){const t=arguments[0];this.elt[0]=new jn(t.elt[0]),this.elt[1]=new jn(t.elt[1])}}else if(arguments.length===2){const t=arguments[0],e=arguments[1];this.elt[0]=new jn(q.NONE),this.elt[1]=new jn(q.NONE),this.elt[t].setLocation(e)}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];this.elt[0]=new jn(t,e,n),this.elt[1]=new jn(t,e,n)}else if(arguments.length===4){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3];this.elt[0]=new jn(q.NONE,q.NONE,q.NONE),this.elt[1]=new jn(q.NONE,q.NONE,q.NONE),this.elt[t].setLocations(e,n,s)}}static toLineLabel(t){const e=new Be(q.NONE);for(let n=0;n<2;n++)e.setLocation(n,t.getLocation(n));return e}getGeometryCount(){let t=0;return this.elt[0].isNull()||t++,this.elt[1].isNull()||t++,t}setAllLocations(t,e){this.elt[t].setAllLocations(e)}isNull(t){return this.elt[t].isNull()}setAllLocationsIfNull(){if(arguments.length===1){const t=arguments[0];this.setAllLocationsIfNull(0,t),this.setAllLocationsIfNull(1,t)}else if(arguments.length===2){const t=arguments[0],e=arguments[1];this.elt[t].setAllLocationsIfNull(e)}}isLine(t){return this.elt[t].isLine()}merge(t){for(let e=0;e<2;e++)this.elt[e]===null&&t.elt[e]!==null?this.elt[e]=new jn(t.elt[e]):this.elt[e].merge(t.elt[e])}flip(){this.elt[0].flip(),this.elt[1].flip()}getLocation(){if(arguments.length===1){const t=arguments[0];return this.elt[t].get(yt.ON)}else if(arguments.length===2){const t=arguments[0],e=arguments[1];return this.elt[t].get(e)}}toString(){const t=new Fu;return this.elt[0]!==null&&(t.append("A:"),t.append(this.elt[0].toString())),this.elt[1]!==null&&(t.append(" B:"),t.append(this.elt[1].toString())),t.toString()}isArea(){if(arguments.length===0)return this.elt[0].isArea()||this.elt[1].isArea();if(arguments.length===1){const t=arguments[0];return this.elt[t].isArea()}}isAnyNull(t){return this.elt[t].isAnyNull()}setLocation(){if(arguments.length===2){const t=arguments[0],e=arguments[1];this.elt[t].setLocation(yt.ON,e)}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];this.elt[t].setLocation(e,n)}}isEqualOnSide(t,e){return this.elt[0].isEqualOnSide(t.elt[0],e)&&this.elt[1].isEqualOnSide(t.elt[1],e)}allPositionsEqual(t,e){return this.elt[t].allPositionsEqual(e)}toLine(t){this.elt[t].isArea()&&(this.elt[t]=new jn(this.elt[t].location[0]))}}class rl{constructor(){rl.constructor_.apply(this,arguments)}static constructor_(){if(this._startDe=null,this._maxNodeDegree=-1,this._edges=new vt,this._pts=new vt,this._label=new Be(q.NONE),this._ring=null,this._isHole=null,this._shell=null,this._holes=new vt,this._geometryFactory=null,arguments.length!==0){if(arguments.length===2){const t=arguments[0],e=arguments[1];this._geometryFactory=e,this.computePoints(t),this.computeRing()}}}computeRing(){if(this._ring!==null)return null;const t=new Array(this._pts.size()).fill(null);for(let e=0;e<this._pts.size();e++)t[e]=this._pts.get(e);this._ring=this._geometryFactory.createLinearRing(t),this._isHole=$t.isCCW(this._ring.getCoordinates())}isIsolated(){return this._label.getGeometryCount()===1}computePoints(t){this._startDe=t;let e=t,n=!0;do{if(e===null)throw new ki("Found null DirectedEdge");if(e.getEdgeRing()===this)throw new ki("Directed Edge visited twice during ring-building at "+e.getCoordinate());this._edges.add(e);const s=e.getLabel();Yt.isTrue(s.isArea()),this.mergeLabel(s),this.addPoints(e.getEdge(),e.isForward(),n),n=!1,this.setEdgeRing(e,this),e=this.getNext(e)}while(e!==this._startDe)}getLinearRing(){return this._ring}getCoordinate(t){return this._pts.get(t)}computeMaxNodeDegree(){this._maxNodeDegree=0;let t=this._startDe;do{const n=t.getNode().getEdges().getOutgoingDegree(this);n>this._maxNodeDegree&&(this._maxNodeDegree=n),t=this.getNext(t)}while(t!==this._startDe);this._maxNodeDegree*=2}addPoints(t,e,n){const s=t.getCoordinates();if(e){let r=1;n&&(r=0);for(let o=r;o<s.length;o++)this._pts.add(s[o])}else{let r=s.length-2;n&&(r=s.length-1);for(let o=r;o>=0;o--)this._pts.add(s[o])}}isHole(){return this._isHole}setInResult(){let t=this._startDe;do t.getEdge().setInResult(!0),t=t.getNext();while(t!==this._startDe)}containsPoint(t){const e=this.getLinearRing();if(!e.getEnvelopeInternal().contains(t)||!ts.isInRing(t,e.getCoordinates()))return!1;for(let s=this._holes.iterator();s.hasNext();)if(s.next().containsPoint(t))return!1;return!0}addHole(t){this._holes.add(t)}isShell(){return this._shell===null}getLabel(){return this._label}getEdges(){return this._edges}getMaxNodeDegree(){return this._maxNodeDegree<0&&this.computeMaxNodeDegree(),this._maxNodeDegree}getShell(){return this._shell}mergeLabel(){if(arguments.length===1){const t=arguments[0];this.mergeLabel(t,0),this.mergeLabel(t,1)}else if(arguments.length===2){const t=arguments[0],e=arguments[1],n=t.getLocation(e,yt.RIGHT);if(n===q.NONE)return null;if(this._label.getLocation(e)===q.NONE)return this._label.setLocation(e,n),null}}setShell(t){this._shell=t,t!==null&&t.addHole(this)}toPolygon(t){const e=new Array(this._holes.size()).fill(null);for(let s=0;s<this._holes.size();s++)e[s]=this._holes.get(s).getLinearRing();return t.createPolygon(this.getLinearRing(),e)}}class op extends rl{constructor(){super(),op.constructor_.apply(this,arguments)}static constructor_(){const t=arguments[0],e=arguments[1];rl.constructor_.call(this,t,e)}setEdgeRing(t,e){t.setMinEdgeRing(e)}getNext(t){return t.getNextMin()}}class Hf extends rl{constructor(){super(),Hf.constructor_.apply(this,arguments)}static constructor_(){const t=arguments[0],e=arguments[1];rl.constructor_.call(this,t,e)}buildMinimalRings(){const t=new vt;let e=this._startDe;do{if(e.getMinEdgeRing()===null){const n=new op(e,this._geometryFactory);t.add(n)}e=e.getNext()}while(e!==this._startDe);return t}setEdgeRing(t,e){t.setEdgeRing(e)}linkDirectedEdgesForMinimalEdgeRings(){let t=this._startDe;do t.getNode().getEdges().linkMinimalDirectedEdges(this),t=t.getNext();while(t!==this._startDe)}getNext(t){return t.getNext()}}class Wf{constructor(){Wf.constructor_.apply(this,arguments)}static constructor_(){if(this._label=null,this._isInResult=!1,this._isCovered=!1,this._isCoveredSet=!1,this._isVisited=!1,arguments.length!==0){if(arguments.length===1){const t=arguments[0];this._label=t}}}setVisited(t){this._isVisited=t}setInResult(t){this._isInResult=t}isCovered(){return this._isCovered}isCoveredSet(){return this._isCoveredSet}setLabel(t){this._label=t}getLabel(){return this._label}setCovered(t){this._isCovered=t,this._isCoveredSet=!0}updateIM(t){Yt.isTrue(this._label.getGeometryCount()>=2,"found partial label"),this.computeIM(t)}isInResult(){return this._isInResult}isVisited(){return this._isVisited}}class yr extends Wf{constructor(){super(),yr.constructor_.apply(this,arguments)}static constructor_(){this._coord=null,this._edges=null;const t=arguments[0],e=arguments[1];this._coord=t,this._edges=e,this._label=new Be(0,q.NONE)}isIncidentEdgeInResult(){for(let t=this.getEdges().getEdges().iterator();t.hasNext();)if(t.next().getEdge().isInResult())return!0;return!1}isIsolated(){return this._label.getGeometryCount()===1}getCoordinate(){return this._coord}print(t){t.println("node "+this._coord+" lbl: "+this._label)}computeIM(t){}computeMergedLocation(t,e){let n=q.NONE;if(n=this._label.getLocation(e),!t.isNull(e)){const s=t.getLocation(e);n!==q.BOUNDARY&&(n=s)}return n}setLabel(){if(arguments.length===2&&Number.isInteger(arguments[1])&&Number.isInteger(arguments[0])){const t=arguments[0],e=arguments[1];this._label===null?this._label=new Be(t,e):this._label.setLocation(t,e)}else return super.setLabel.apply(this,arguments)}getEdges(){return this._edges}mergeLabel(){if(arguments[0]instanceof yr){const t=arguments[0];this.mergeLabel(t._label)}else if(arguments[0]instanceof Be){const t=arguments[0];for(let e=0;e<2;e++){const n=this.computeMergedLocation(t,e);this._label.getLocation(e)===q.NONE&&this._label.setLocation(e,n)}}}add(t){this._edges.insert(t),t.setNode(this)}setLabelBoundary(t){if(this._label===null)return null;let e=q.NONE;this._label!==null&&(e=this._label.getLocation(t));let n=null;switch(e){case q.BOUNDARY:n=q.INTERIOR;break;case q.INTERIOR:n=q.BOUNDARY;break;default:n=q.BOUNDARY;break}this._label.setLocation(t,n)}}class YA extends ww{}const Ts=0,Sr=1;function __(i){return i==null?Ts:i.color}function ve(i){return i==null?null:i.parent}function ks(i,t){i!==null&&(i.color=t)}function hg(i){return i==null?null:i.left}function v_(i){return i==null?null:i.right}class Qs extends YA{constructor(){super(),this.root_=null,this.size_=0}get(t){let e=this.root_;for(;e!==null;){const n=t.compareTo(e.key);if(n<0)e=e.left;else if(n>0)e=e.right;else return e.value}return null}put(t,e){if(this.root_===null)return this.root_={key:t,value:e,left:null,right:null,parent:null,color:Ts,getValue(){return this.value},getKey(){return this.key}},this.size_=1,null;let n=this.root_,s,r;do if(s=n,r=t.compareTo(n.key),r<0)n=n.left;else if(r>0)n=n.right;else{const a=n.value;return n.value=e,a}while(n!==null);const o={key:t,left:null,right:null,value:e,parent:s,color:Ts,getValue(){return this.value},getKey(){return this.key}};return r<0?s.left=o:s.right=o,this.fixAfterInsertion(o),this.size_++,null}fixAfterInsertion(t){let e;for(t.color=Sr;t!=null&&t!==this.root_&&t.parent.color===Sr;)ve(t)===hg(ve(ve(t)))?(e=v_(ve(ve(t))),__(e)===Sr?(ks(ve(t),Ts),ks(e,Ts),ks(ve(ve(t)),Sr),t=ve(ve(t))):(t===v_(ve(t))&&(t=ve(t),this.rotateLeft(t)),ks(ve(t),Ts),ks(ve(ve(t)),Sr),this.rotateRight(ve(ve(t))))):(e=hg(ve(ve(t))),__(e)===Sr?(ks(ve(t),Ts),ks(e,Ts),ks(ve(ve(t)),Sr),t=ve(ve(t))):(t===hg(ve(t))&&(t=ve(t),this.rotateRight(t)),ks(ve(t),Ts),ks(ve(ve(t)),Sr),this.rotateLeft(ve(ve(t)))));this.root_.color=Ts}values(){const t=new vt;let e=this.getFirstEntry();if(e!==null)for(t.add(e.value);(e=Qs.successor(e))!==null;)t.add(e.value);return t}entrySet(){const t=new _c;let e=this.getFirstEntry();if(e!==null)for(t.add(e);(e=Qs.successor(e))!==null;)t.add(e);return t}rotateLeft(t){if(t!=null){const e=t.right;t.right=e.left,e.left!=null&&(e.left.parent=t),e.parent=t.parent,t.parent==null?this.root_=e:t.parent.left===t?t.parent.left=e:t.parent.right=e,e.left=t,t.parent=e}}rotateRight(t){if(t!=null){const e=t.left;t.left=e.right,e.right!=null&&(e.right.parent=t),e.parent=t.parent,t.parent==null?this.root_=e:t.parent.right===t?t.parent.right=e:t.parent.left=e,e.right=t,t.parent=e}}getFirstEntry(){let t=this.root_;if(t!=null)for(;t.left!=null;)t=t.left;return t}static successor(t){let e;if(t===null)return null;if(t.right!==null){for(e=t.right;e.left!==null;)e=e.left;return e}else{e=t.parent;let n=t;for(;e!==null&&n===e.right;)n=e,e=e.parent;return e}}size(){return this.size_}containsKey(t){let e=this.root_;for(;e!==null;){const n=t.compareTo(e.key);if(n<0)e=e.left;else if(n>0)e=e.right;else return!0}return!1}}class ol{constructor(){ol.constructor_.apply(this,arguments)}static constructor_(){this.nodeMap=new Qs,this.nodeFact=null;const t=arguments[0];this.nodeFact=t}find(t){return this.nodeMap.get(t)}addNode(){if(arguments[0]instanceof Z){const t=arguments[0];let e=this.nodeMap.get(t);return e===null&&(e=this.nodeFact.createNode(t),this.nodeMap.put(t,e)),e}else if(arguments[0]instanceof yr){const t=arguments[0],e=this.nodeMap.get(t.getCoordinate());return e===null?(this.nodeMap.put(t.getCoordinate(),t),t):(e.mergeLabel(t),e)}}print(t){for(let e=this.iterator();e.hasNext();)e.next().print(t)}iterator(){return this.nodeMap.values().iterator()}values(){return this.nodeMap.values()}getBoundaryNodes(t){const e=new vt;for(let n=this.iterator();n.hasNext();){const s=n.next();s.getLabel().getLocation(t)===q.BOUNDARY&&e.add(s)}return e}add(t){const e=t.getCoordinate();this.addNode(e).add(t)}}class Ne{static isNorthern(t){return t===Ne.NE||t===Ne.NW}static isOpposite(t,e){return t===e?!1:(t-e+4)%4===2}static commonHalfPlane(t,e){if(t===e)return t;if((t-e+4)%4===2)return-1;const s=t<e?t:e,r=t>e?t:e;return s===0&&r===3?3:s}static isInHalfPlane(t,e){return e===Ne.SE?t===Ne.SE||t===Ne.SW:t===e||t===e+1}static quadrant(){if(typeof arguments[0]=="number"&&typeof arguments[1]=="number"){const t=arguments[0],e=arguments[1];if(t===0&&e===0)throw new Zt("Cannot compute the quadrant for point ( "+t+", "+e+" )");return t>=0?e>=0?Ne.NE:Ne.SE:e>=0?Ne.NW:Ne.SW}else if(arguments[0]instanceof Z&&arguments[1]instanceof Z){const t=arguments[0],e=arguments[1];if(e.x===t.x&&e.y===t.y)throw new Zt("Cannot compute the quadrant for two identical points "+t);return e.x>=t.x?e.y>=t.y?Ne.NE:Ne.SE:e.y>=t.y?Ne.NW:Ne.SW}}}Ne.NE=0;Ne.NW=1;Ne.SW=2;Ne.SE=3;class Xs{constructor(){Xs.constructor_.apply(this,arguments)}static constructor_(){if(this._edge=null,this._label=null,this._node=null,this._p0=null,this._p1=null,this._dx=null,this._dy=null,this._quadrant=null,arguments.length===1){const t=arguments[0];this._edge=t}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];Xs.constructor_.call(this,t,e,n,null)}else if(arguments.length===4){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3];Xs.constructor_.call(this,t),this.init(e,n),this._label=s}}compareDirection(t){return this._dx===t._dx&&this._dy===t._dy?0:this._quadrant>t._quadrant?1:this._quadrant<t._quadrant?-1:$t.index(t._p0,t._p1,this._p1)}getDy(){return this._dy}getCoordinate(){return this._p0}setNode(t){this._node=t}print(t){const e=Math.atan2(this._dy,this._dx),n=this.getClass().getName(),s=n.lastIndexOf("."),r=n.substring(s+1);t.print(" "+r+": "+this._p0+" - "+this._p1+" "+this._quadrant+":"+e+" "+this._label)}compareTo(t){const e=t;return this.compareDirection(e)}getDirectedCoordinate(){return this._p1}getDx(){return this._dx}getLabel(){return this._label}getEdge(){return this._edge}getQuadrant(){return this._quadrant}getNode(){return this._node}toString(){const t=Math.atan2(this._dy,this._dx),e=this.getClass().getName(),n=e.lastIndexOf(".");return" "+e.substring(n+1)+": "+this._p0+" - "+this._p1+" "+this._quadrant+":"+t+" "+this._label}computeLabel(t){}init(t,e){this._p0=t,this._p1=e,this._dx=e.x-t.x,this._dy=e.y-t.y,this._quadrant=Ne.quadrant(this._dx,this._dy),Yt.isTrue(!(this._dx===0&&this._dy===0),"EdgeEnd with identical endpoints found")}get interfaces_(){return[gi]}}class Du extends Xs{constructor(){super(),Du.constructor_.apply(this,arguments)}static constructor_(){this._isForward=null,this._isInResult=!1,this._isVisited=!1,this._sym=null,this._next=null,this._nextMin=null,this._edgeRing=null,this._minEdgeRing=null,this._depth=[0,-999,-999];const t=arguments[0],e=arguments[1];if(Xs.constructor_.call(this,t),this._isForward=e,e)this.init(t.getCoordinate(0),t.getCoordinate(1));else{const n=t.getNumPoints()-1;this.init(t.getCoordinate(n),t.getCoordinate(n-1))}this.computeDirectedLabel()}static depthFactor(t,e){return t===q.EXTERIOR&&e===q.INTERIOR?1:t===q.INTERIOR&&e===q.EXTERIOR?-1:0}getNextMin(){return this._nextMin}getDepth(t){return this._depth[t]}setVisited(t){this._isVisited=t}computeDirectedLabel(){this._label=new Be(this._edge.getLabel()),this._isForward||this._label.flip()}getNext(){return this._next}setDepth(t,e){if(this._depth[t]!==-999&&this._depth[t]!==e)throw new ki("assigned depths do not match",this.getCoordinate());this._depth[t]=e}isInteriorAreaEdge(){let t=!0;for(let e=0;e<2;e++)this._label.isArea(e)&&this._label.getLocation(e,yt.LEFT)===q.INTERIOR&&this._label.getLocation(e,yt.RIGHT)===q.INTERIOR||(t=!1);return t}setNextMin(t){this._nextMin=t}print(t){super.print.call(this,t),t.print(" "+this._depth[yt.LEFT]+"/"+this._depth[yt.RIGHT]),t.print(" ("+this.getDepthDelta()+")"),this._isInResult&&t.print(" inResult")}setMinEdgeRing(t){this._minEdgeRing=t}isLineEdge(){const t=this._label.isLine(0)||this._label.isLine(1),e=!this._label.isArea(0)||this._label.allPositionsEqual(0,q.EXTERIOR),n=!this._label.isArea(1)||this._label.allPositionsEqual(1,q.EXTERIOR);return t&&e&&n}setEdgeRing(t){this._edgeRing=t}getMinEdgeRing(){return this._minEdgeRing}getDepthDelta(){let t=this._edge.getDepthDelta();return this._isForward||(t=-t),t}setInResult(t){this._isInResult=t}getSym(){return this._sym}isForward(){return this._isForward}getEdge(){return this._edge}printEdge(t){this.print(t),t.print(" "),this._isForward?this._edge.print(t):this._edge.printReverse(t)}setSym(t){this._sym=t}setVisitedEdge(t){this.setVisited(t),this._sym.setVisited(t)}setEdgeDepths(t,e){let n=this.getEdge().getDepthDelta();this._isForward||(n=-n);let s=1;t===yt.LEFT&&(s=-1);const r=yt.opposite(t),o=n*s,a=e+o;this.setDepth(t,e),this.setDepth(r,a)}getEdgeRing(){return this._edgeRing}isInResult(){return this._isInResult}setNext(t){this._next=t}isVisited(){return this._isVisited}}class ap{createNode(t){return new yr(t,null)}}class qo{constructor(){qo.constructor_.apply(this,arguments)}static constructor_(){if(this._edges=new vt,this._nodes=null,this._edgeEndList=new vt,arguments.length===0)this._nodes=new ol(new ap);else if(arguments.length===1){const t=arguments[0];this._nodes=new ol(t)}}static linkResultDirectedEdges(t){for(let e=t.iterator();e.hasNext();)e.next().getEdges().linkResultDirectedEdges()}printEdges(t){t.println("Edges:");for(let e=0;e<this._edges.size();e++){t.println("edge "+e+":");const n=this._edges.get(e);n.print(t),n.eiList.print(t)}}find(t){return this._nodes.find(t)}addNode(){if(arguments[0]instanceof yr){const t=arguments[0];return this._nodes.addNode(t)}else if(arguments[0]instanceof Z){const t=arguments[0];return this._nodes.addNode(t)}}getNodeIterator(){return this._nodes.iterator()}linkResultDirectedEdges(){for(let t=this._nodes.iterator();t.hasNext();)t.next().getEdges().linkResultDirectedEdges()}debugPrintln(t){ci.out.println(t)}isBoundaryNode(t,e){const n=this._nodes.find(e);if(n===null)return!1;const s=n.getLabel();return s!==null&&s.getLocation(t)===q.BOUNDARY}linkAllDirectedEdges(){for(let t=this._nodes.iterator();t.hasNext();)t.next().getEdges().linkAllDirectedEdges()}matchInSameDirection(t,e,n,s){return t.equals(n)?$t.index(t,e,s)===$t.COLLINEAR&&Ne.quadrant(t,e)===Ne.quadrant(n,s):!1}getEdgeEnds(){return this._edgeEndList}debugPrint(t){ci.out.print(t)}getEdgeIterator(){return this._edges.iterator()}findEdgeInSameDirection(t,e){for(let n=0;n<this._edges.size();n++){const s=this._edges.get(n),r=s.getCoordinates();if(this.matchInSameDirection(t,e,r[0],r[1])||this.matchInSameDirection(t,e,r[r.length-1],r[r.length-2]))return s}return null}insertEdge(t){this._edges.add(t)}findEdgeEnd(t){for(let e=this.getEdgeEnds().iterator();e.hasNext();){const n=e.next();if(n.getEdge()===t)return n}return null}addEdges(t){for(let e=t.iterator();e.hasNext();){const n=e.next();this._edges.add(n);const s=new Du(n,!0),r=new Du(n,!1);s.setSym(r),r.setSym(s),this.add(s),this.add(r)}}add(t){this._nodes.add(t),this._edgeEndList.add(t)}getNodes(){return this._nodes.values()}findEdge(t,e){for(let n=0;n<this._edges.size();n++){const s=this._edges.get(n),r=s.getCoordinates();if(t.equals(r[0])&&e.equals(r[1]))return s}return null}}class Gu{constructor(){Gu.constructor_.apply(this,arguments)}static constructor_(){this._geometryFactory=null,this._shellList=new vt;const t=arguments[0];this._geometryFactory=t}static findEdgeRingContaining(t,e){const n=t.getLinearRing(),s=n.getEnvelopeInternal();let r=n.getCoordinateN(0),o=null,a=null;for(let l=e.iterator();l.hasNext();){const h=l.next(),f=h.getLinearRing(),d=f.getEnvelopeInternal();if(d.equals(s)||!d.contains(s))continue;r=Le.ptNotInList(n.getCoordinates(),f.getCoordinates());let p=!1;ts.isInRing(r,f.getCoordinates())&&(p=!0),p&&(o===null||a.contains(d))&&(o=h,a=o.getLinearRing().getEnvelopeInternal())}return o}sortShellsAndHoles(t,e,n){for(let s=t.iterator();s.hasNext();){const r=s.next();r.isHole()?n.add(r):e.add(r)}}computePolygons(t){const e=new vt;for(let n=t.iterator();n.hasNext();){const r=n.next().toPolygon(this._geometryFactory);e.add(r)}return e}placeFreeHoles(t,e){for(let n=e.iterator();n.hasNext();){const s=n.next();if(s.getShell()===null){const r=Gu.findEdgeRingContaining(s,t);if(r===null)throw new ki("unable to assign hole to a shell",s.getCoordinate(0));s.setShell(r)}}}buildMinimalEdgeRings(t,e,n){const s=new vt;for(let r=t.iterator();r.hasNext();){const o=r.next();if(o.getMaxNodeDegree()>2){o.linkDirectedEdgesForMinimalEdgeRings();const a=o.buildMinimalRings(),l=this.findShell(a);l!==null?(this.placePolygonHoles(l,a),e.add(l)):n.addAll(a)}else s.add(o)}return s}buildMaximalEdgeRings(t){const e=new vt;for(let n=t.iterator();n.hasNext();){const s=n.next();if(s.isInResult()&&s.getLabel().isArea()&&s.getEdgeRing()===null){const r=new Hf(s,this._geometryFactory);e.add(r),r.setInResult()}}return e}placePolygonHoles(t,e){for(let n=e.iterator();n.hasNext();){const s=n.next();s.isHole()&&s.setShell(t)}}getPolygons(){return this.computePolygons(this._shellList)}findShell(t){let e=0,n=null;for(let s=t.iterator();s.hasNext();){const r=s.next();r.isHole()||(n=r,e++)}return Yt.isTrue(e<=1,"found two shells in MinimalEdgeRing list"),n}add(){if(arguments.length===1){const t=arguments[0];this.add(t.getEdgeEnds(),t.getNodes())}else if(arguments.length===2){const t=arguments[0],e=arguments[1];qo.linkResultDirectedEdges(e);const n=this.buildMaximalEdgeRings(t),s=new vt,r=this.buildMinimalEdgeRings(n,this._shellList,s);this.sortShellsAndHoles(r,this._shellList,s),this.placeFreeHoles(this._shellList,s)}}}class Tw{getBounds(){}}class fs{constructor(){fs.constructor_.apply(this,arguments)}static constructor_(){this._bounds=null,this._item=null;const t=arguments[0],e=arguments[1];this._bounds=t,this._item=e}getItem(){return this._item}getBounds(){return this._bounds}get interfaces_(){return[Tw,mi]}}class Sa{constructor(){Sa.constructor_.apply(this,arguments)}static constructor_(){this._size=null,this._items=null,this._size=0,this._items=new vt,this._items.add(null)}poll(){if(this.isEmpty())return null;const t=this._items.get(1);return this._items.set(1,this._items.get(this._size)),this._size-=1,this.reorder(1),t}size(){return this._size}reorder(t){let e=null;const n=this._items.get(t);for(;t*2<=this._size&&(e=t*2,e!==this._size&&this._items.get(e+1).compareTo(this._items.get(e))<0&&e++,this._items.get(e).compareTo(n)<0);t=e)this._items.set(t,this._items.get(e));this._items.set(t,n)}clear(){this._size=0,this._items.clear()}peek(){return this.isEmpty()?null:this._items.get(1)}isEmpty(){return this._size===0}add(t){this._items.add(null),this._size+=1;let e=this._size;for(this._items.set(0,t);t.compareTo(this._items.get(Math.trunc(e/2)))<0;e/=2)this._items.set(e,this._items.get(Math.trunc(e/2)));this._items.set(e,t)}}class XA{insert(t,e){}remove(t,e){}query(){}}class ii{constructor(){ii.constructor_.apply(this,arguments)}static constructor_(){if(this._childBoundables=new vt,this._bounds=null,this._level=null,arguments.length!==0){if(arguments.length===1){const t=arguments[0];this._level=t}}}getLevel(){return this._level}size(){return this._childBoundables.size()}getChildBoundables(){return this._childBoundables}addChildBoundable(t){Yt.isTrue(this._bounds===null),this._childBoundables.add(t)}isEmpty(){return this._childBoundables.isEmpty()}getBounds(){return this._bounds===null&&(this._bounds=this.computeBounds()),this._bounds}get interfaces_(){return[Tw,mi]}}const _r={reverseOrder:function(){return{compare(i,t){return t.compareTo(i)}}},min:function(i){return _r.sort(i),i.get(0)},sort:function(i,t){const e=i.toArray();t?Or.sort(e,t):Or.sort(e);const n=i.iterator();for(let s=0,r=e.length;s<r;s++)n.next(),n.set(e[s])},singletonList:function(i){const t=new vt;return t.add(i),t}};class He{static maxDistance(t,e,n,s,r,o,a,l){let h=He.distance(t,e,r,o);return h=Math.max(h,He.distance(t,e,a,l)),h=Math.max(h,He.distance(n,s,r,o)),h=Math.max(h,He.distance(n,s,a,l)),h}static distance(t,e,n,s){const r=n-t,o=s-e;return Math.sqrt(r*r+o*o)}static maximumDistance(t,e){const n=Math.min(t.getMinX(),e.getMinX()),s=Math.min(t.getMinY(),e.getMinY()),r=Math.max(t.getMaxX(),e.getMaxX()),o=Math.max(t.getMaxY(),e.getMaxY());return He.distance(n,s,r,o)}static minMaxDistance(t,e){const n=t.getMinX(),s=t.getMinY(),r=t.getMaxX(),o=t.getMaxY(),a=e.getMinX(),l=e.getMinY(),h=e.getMaxX(),f=e.getMaxY();let d=He.maxDistance(n,s,n,o,a,l,a,f);return d=Math.min(d,He.maxDistance(n,s,n,o,a,l,h,l)),d=Math.min(d,He.maxDistance(n,s,n,o,h,f,a,f)),d=Math.min(d,He.maxDistance(n,s,n,o,h,f,h,l)),d=Math.min(d,He.maxDistance(n,s,r,s,a,l,a,f)),d=Math.min(d,He.maxDistance(n,s,r,s,a,l,h,l)),d=Math.min(d,He.maxDistance(n,s,r,s,h,f,a,f)),d=Math.min(d,He.maxDistance(n,s,r,s,h,f,h,l)),d=Math.min(d,He.maxDistance(r,o,n,o,a,l,a,f)),d=Math.min(d,He.maxDistance(r,o,n,o,a,l,h,l)),d=Math.min(d,He.maxDistance(r,o,n,o,h,f,a,f)),d=Math.min(d,He.maxDistance(r,o,n,o,h,f,h,l)),d=Math.min(d,He.maxDistance(r,o,r,s,a,l,a,f)),d=Math.min(d,He.maxDistance(r,o,r,s,a,l,h,l)),d=Math.min(d,He.maxDistance(r,o,r,s,h,f,a,f)),d=Math.min(d,He.maxDistance(r,o,r,s,h,f,h,l)),d}}class On{constructor(){On.constructor_.apply(this,arguments)}static constructor_(){this._boundable1=null,this._boundable2=null,this._distance=null,this._itemDistance=null;const t=arguments[0],e=arguments[1],n=arguments[2];this._boundable1=t,this._boundable2=e,this._itemDistance=n,this._distance=this.distance()}static area(t){return t.getBounds().getArea()}static isComposite(t){return t instanceof ii}maximumDistance(){return He.maximumDistance(this._boundable1.getBounds(),this._boundable2.getBounds())}expandToQueue(t,e){const n=On.isComposite(this._boundable1),s=On.isComposite(this._boundable2);if(n&&s)return On.area(this._boundable1)>On.area(this._boundable2)?(this.expand(this._boundable1,this._boundable2,!1,t,e),null):(this.expand(this._boundable2,this._boundable1,!0,t,e),null);if(n)return this.expand(this._boundable1,this._boundable2,!1,t,e),null;if(s)return this.expand(this._boundable2,this._boundable1,!0,t,e),null;throw new Zt("neither boundable is composite")}isLeaves(){return!(On.isComposite(this._boundable1)||On.isComposite(this._boundable2))}compareTo(t){const e=t;return this._distance<e._distance?-1:this._distance>e._distance?1:0}expand(t,e,n,s,r){const o=t.getChildBoundables();for(let a=o.iterator();a.hasNext();){const l=a.next();let h=null;n?h=new On(e,l,this._itemDistance):h=new On(l,e,this._itemDistance),h.getDistance()<r&&s.add(h)}}getBoundable(t){return t===0?this._boundable1:this._boundable2}getDistance(){return this._distance}distance(){return this.isLeaves()?this._itemDistance.distance(this._boundable1,this._boundable2):this._boundable1.getBounds().distance(this._boundable2.getBounds())}get interfaces_(){return[gi]}}class Kf{visitItem(t){}}class js{constructor(){js.constructor_.apply(this,arguments)}static constructor_(){if(this._root=null,this._built=!1,this._itemBoundables=new vt,this._nodeCapacity=null,arguments.length===0)js.constructor_.call(this,js.DEFAULT_NODE_CAPACITY);else if(arguments.length===1){const t=arguments[0];Yt.isTrue(t>1,"Node capacity must be greater than 1"),this._nodeCapacity=t}}static compareDoubles(t,e){return t>e?1:t<e?-1:0}queryInternal(){if(Ot(arguments[2],Kf)&&arguments[0]instanceof Object&&arguments[1]instanceof ii){const t=arguments[0],e=arguments[1],n=arguments[2],s=e.getChildBoundables();for(let r=0;r<s.size();r++){const o=s.get(r);this.getIntersectsOp().intersects(o.getBounds(),t)&&(o instanceof ii?this.queryInternal(t,o,n):o instanceof fs?n.visitItem(o.getItem()):Yt.shouldNeverReachHere())}}else if(Ot(arguments[2],Pi)&&arguments[0]instanceof Object&&arguments[1]instanceof ii){const t=arguments[0],e=arguments[1],n=arguments[2],s=e.getChildBoundables();for(let r=0;r<s.size();r++){const o=s.get(r);this.getIntersectsOp().intersects(o.getBounds(),t)&&(o instanceof ii?this.queryInternal(t,o,n):o instanceof fs?n.add(o.getItem()):Yt.shouldNeverReachHere())}}}getNodeCapacity(){return this._nodeCapacity}lastNode(t){return t.get(t.size()-1)}size(){if(arguments.length===0)return this.isEmpty()?0:(this.build(),this.size(this._root));if(arguments.length===1){const t=arguments[0];let e=0;for(let n=t.getChildBoundables().iterator();n.hasNext();){const s=n.next();s instanceof ii?e+=this.size(s):s instanceof fs&&(e+=1)}return e}}removeItem(t,e){let n=null;for(let s=t.getChildBoundables().iterator();s.hasNext();){const r=s.next();r instanceof fs&&r.getItem()===e&&(n=r)}return n!==null?(t.getChildBoundables().remove(n),!0):!1}itemsTree(){if(arguments.length===0){this.build();const t=this.itemsTree(this._root);return t===null?new vt:t}else if(arguments.length===1){const t=arguments[0],e=new vt;for(let n=t.getChildBoundables().iterator();n.hasNext();){const s=n.next();if(s instanceof ii){const r=this.itemsTree(s);r!==null&&e.add(r)}else s instanceof fs?e.add(s.getItem()):Yt.shouldNeverReachHere()}return e.size()<=0?null:e}}insert(t,e){Yt.isTrue(!this._built,"Cannot insert items into an STR packed R-tree after it has been built."),this._itemBoundables.add(new fs(t,e))}boundablesAtLevel(){if(arguments.length===1){const t=arguments[0],e=new vt;return this.boundablesAtLevel(t,this._root,e),e}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];if(Yt.isTrue(t>-2),e.getLevel()===t)return n.add(e),null;for(let s=e.getChildBoundables().iterator();s.hasNext();){const r=s.next();r instanceof ii?this.boundablesAtLevel(t,r,n):(Yt.isTrue(r instanceof fs),t===-1&&n.add(r))}return null}}query(){if(arguments.length===1){const t=arguments[0];this.build();const e=new vt;return this.isEmpty()||this.getIntersectsOp().intersects(this._root.getBounds(),t)&&this.queryInternal(t,this._root,e),e}else if(arguments.length===2){const t=arguments[0],e=arguments[1];if(this.build(),this.isEmpty())return null;this.getIntersectsOp().intersects(this._root.getBounds(),t)&&this.queryInternal(t,this._root,e)}}build(){if(this._built)return null;this._root=this._itemBoundables.isEmpty()?this.createNode(0):this.createHigherLevels(this._itemBoundables,-1),this._itemBoundables=null,this._built=!0}getRoot(){return this.build(),this._root}remove(){if(arguments.length===2){const t=arguments[0],e=arguments[1];return this.build(),this.getIntersectsOp().intersects(this._root.getBounds(),t)?this.remove(t,this._root,e):!1}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];let s=this.removeItem(e,n);if(s)return!0;let r=null;for(let o=e.getChildBoundables().iterator();o.hasNext();){const a=o.next();if(this.getIntersectsOp().intersects(a.getBounds(),t)&&a instanceof ii&&(s=this.remove(t,a,n),s)){r=a;break}}return r!==null&&r.getChildBoundables().isEmpty()&&e.getChildBoundables().remove(r),s}}createHigherLevels(t,e){Yt.isTrue(!t.isEmpty());const n=this.createParentBoundables(t,e+1);return n.size()===1?n.get(0):this.createHigherLevels(n,e+1)}depth(){if(arguments.length===0)return this.isEmpty()?0:(this.build(),this.depth(this._root));if(arguments.length===1){const t=arguments[0];let e=0;for(let n=t.getChildBoundables().iterator();n.hasNext();){const s=n.next();if(s instanceof ii){const r=this.depth(s);r>e&&(e=r)}}return e+1}}createParentBoundables(t,e){Yt.isTrue(!t.isEmpty());const n=new vt;n.add(this.createNode(e));const s=new vt(t);_r.sort(s,this.getComparator());for(let r=s.iterator();r.hasNext();){const o=r.next();this.lastNode(n).getChildBoundables().size()===this.getNodeCapacity()&&n.add(this.createNode(e)),this.lastNode(n).addChildBoundable(o)}return n}isEmpty(){return this._built?this._root.isEmpty():this._itemBoundables.isEmpty()}get interfaces_(){return[mi]}}function jA(){}js.IntersectsOp=jA;js.DEFAULT_NODE_CAPACITY=10;class VA{distance(t,e){}}class Je extends js{constructor(){super(),Je.constructor_.apply(this,arguments)}static constructor_(){if(arguments.length===0)Je.constructor_.call(this,Je.DEFAULT_NODE_CAPACITY);else if(arguments.length===1){const t=arguments[0];js.constructor_.call(this,t)}}static centreX(t){return Je.avg(t.getMinX(),t.getMaxX())}static avg(t,e){return(t+e)/2}static getItems(t){const e=new Array(t.size()).fill(null);let n=0;for(;!t.isEmpty();){const s=t.poll();e[n]=s.getBoundable(0).getItem(),n++}return e}static centreY(t){return Je.avg(t.getMinY(),t.getMaxY())}createParentBoundablesFromVerticalSlices(t,e){Yt.isTrue(t.length>0);const n=new vt;for(let s=0;s<t.length;s++)n.addAll(this.createParentBoundablesFromVerticalSlice(t[s],e));return n}nearestNeighbourK(){if(arguments.length===2){const t=arguments[0],e=arguments[1];return this.nearestNeighbourK(t,Rt.POSITIVE_INFINITY,e)}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];let s=e;const r=new Sa;r.add(t);const o=new Sa;for(;!r.isEmpty()&&s>=0;){const a=r.poll(),l=a.getDistance();if(l>=s)break;a.isLeaves()?o.size()<n?o.add(a):(o.peek().getDistance()>l&&(o.poll(),o.add(a)),s=o.peek().getDistance()):a.expandToQueue(r,s)}return Je.getItems(o)}}createNode(t){return new Zf(t)}size(){return arguments.length===0?super.size.call(this):super.size.apply(this,arguments)}insert(){if(arguments.length===2&&arguments[1]instanceof Object&&arguments[0]instanceof te){const t=arguments[0],e=arguments[1];if(t.isNull())return null;super.insert.call(this,t,e)}else return super.insert.apply(this,arguments)}getIntersectsOp(){return Je.intersectsOp}verticalSlices(t,e){const n=Math.trunc(Math.ceil(t.size()/e)),s=new Array(e).fill(null),r=t.iterator();for(let o=0;o<e;o++){s[o]=new vt;let a=0;for(;r.hasNext()&&a<n;){const l=r.next();s[o].add(l),a++}}return s}query(){if(arguments.length===1){const t=arguments[0];return super.query.call(this,t)}else if(arguments.length===2){const t=arguments[0],e=arguments[1];super.query.call(this,t,e)}}getComparator(){return Je.yComparator}createParentBoundablesFromVerticalSlice(t,e){return super.createParentBoundables.call(this,t,e)}remove(){if(arguments.length===2&&arguments[1]instanceof Object&&arguments[0]instanceof te){const t=arguments[0],e=arguments[1];return super.remove.call(this,t,e)}else return super.remove.apply(this,arguments)}depth(){return arguments.length===0?super.depth.call(this):super.depth.apply(this,arguments)}createParentBoundables(t,e){Yt.isTrue(!t.isEmpty());const n=Math.trunc(Math.ceil(t.size()/this.getNodeCapacity())),s=new vt(t);_r.sort(s,Je.xComparator);const r=this.verticalSlices(s,Math.trunc(Math.ceil(Math.sqrt(n))));return this.createParentBoundablesFromVerticalSlices(r,e)}nearestNeighbour(){if(arguments.length===1){if(Ot(arguments[0],VA)){const t=arguments[0];if(this.isEmpty())return null;const e=new On(this.getRoot(),this.getRoot(),t);return this.nearestNeighbour(e)}else if(arguments[0]instanceof On){const t=arguments[0];let e=Rt.POSITIVE_INFINITY,n=null;const s=new Sa;for(s.add(t);!s.isEmpty()&&e>0;){const r=s.poll(),o=r.getDistance();if(o>=e)break;r.isLeaves()?(e=o,n=r):r.expandToQueue(s,e)}return n===null?null:[n.getBoundable(0).getItem(),n.getBoundable(1).getItem()]}}else if(arguments.length===2){const t=arguments[0],e=arguments[1];if(this.isEmpty()||t.isEmpty())return null;const n=new On(this.getRoot(),t.getRoot(),e);return this.nearestNeighbour(n)}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2],s=new fs(t,e),r=new On(this.getRoot(),s,n);return this.nearestNeighbour(r)[0]}else if(arguments.length===4){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3],r=new fs(t,e),o=new On(this.getRoot(),r,n);return this.nearestNeighbourK(o,s)}}isWithinDistance(){if(arguments.length===2){const t=arguments[0],e=arguments[1];let n=Rt.POSITIVE_INFINITY;const s=new Sa;for(s.add(t);!s.isEmpty();){const r=s.poll(),o=r.getDistance();if(o>e)return!1;if(r.maximumDistance()<=e)return!0;if(r.isLeaves()){if(n=o,n<=e)return!0}else r.expandToQueue(s,n)}return!1}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2],s=new On(this.getRoot(),t.getRoot(),e);return this.isWithinDistance(s,n)}}get interfaces_(){return[XA,mi]}}class Zf extends ii{constructor(){super(),Zf.constructor_.apply(this,arguments)}static constructor_(){const t=arguments[0];ii.constructor_.call(this,t)}computeBounds(){let t=null;for(let e=this.getChildBoundables().iterator();e.hasNext();){const n=e.next();t===null?t=new te(n.getBounds()):t.expandToInclude(n.getBounds())}return t}}Je.STRtreeNode=Zf;Je.xComparator=new class{get interfaces_(){return[Kr]}compare(i,t){return js.compareDoubles(Je.centreX(i.getBounds()),Je.centreX(t.getBounds()))}};Je.yComparator=new class{get interfaces_(){return[Kr]}compare(i,t){return js.compareDoubles(Je.centreY(i.getBounds()),Je.centreY(t.getBounds()))}};Je.intersectsOp=new class{get interfaces_(){return[IntersectsOp]}intersects(i,t){return i.intersects(t)}};Je.DEFAULT_NODE_CAPACITY=10;class Ui{static relativeSign(t,e){return t<e?-1:t>e?1:0}static compare(t,e,n){if(e.equals2D(n))return 0;const s=Ui.relativeSign(e.x,n.x),r=Ui.relativeSign(e.y,n.y);switch(t){case 0:return Ui.compareValue(s,r);case 1:return Ui.compareValue(r,s);case 2:return Ui.compareValue(r,-s);case 3:return Ui.compareValue(-s,r);case 4:return Ui.compareValue(-s,-r);case 5:return Ui.compareValue(-r,-s);case 6:return Ui.compareValue(-r,s);case 7:return Ui.compareValue(s,-r)}return Yt.shouldNeverReachHere("invalid octant value"),0}static compareValue(t,e){return t<0?-1:t>0?1:e<0?-1:e>0?1:0}}class lp{constructor(){lp.constructor_.apply(this,arguments)}static constructor_(){this._segString=null,this.coord=null,this.segmentIndex=null,this._segmentOctant=null,this._isInterior=null;const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3];this._segString=t,this.coord=new Z(e),this.segmentIndex=n,this._segmentOctant=s,this._isInterior=!e.equals2D(t.getCoordinate(n))}getCoordinate(){return this.coord}print(t){t.print(this.coord),t.print(" seg # = "+this.segmentIndex)}compareTo(t){const e=t;return this.segmentIndex<e.segmentIndex?-1:this.segmentIndex>e.segmentIndex?1:this.coord.equals2D(e.coord)?0:this._isInterior?e._isInterior?Ui.compare(this._segmentOctant,this.coord,e.coord):1:-1}isEndPoint(t){return this.segmentIndex===0&&!this._isInterior||this.segmentIndex===t}toString(){return this.segmentIndex+":"+this.coord.toString()}isInterior(){return this._isInterior}get interfaces_(){return[gi]}}class HA{hasNext(){}next(){}remove(){}}class up{constructor(){up.constructor_.apply(this,arguments)}static constructor_(){this._nodeMap=new Qs,this._edge=null;const t=arguments[0];this._edge=t}getSplitCoordinates(){const t=new Qi;this.addEndpoints();const e=this.iterator();let n=e.next();for(;e.hasNext();){const s=e.next();this.addEdgeCoordinates(n,s,t),n=s}return t.toCoordinateArray()}addCollapsedNodes(){const t=new vt;this.findCollapsesFromInsertedNodes(t),this.findCollapsesFromExistingVertices(t);for(let e=t.iterator();e.hasNext();){const n=e.next().intValue();this.add(this._edge.getCoordinate(n),n)}}createSplitEdgePts(t,e){let n=e.segmentIndex-t.segmentIndex+2;if(n===2)return[new Z(t.coord),new Z(e.coord)];const s=this._edge.getCoordinate(e.segmentIndex),r=e.isInterior()||!e.coord.equals2D(s);r||n--;const o=new Array(n).fill(null);let a=0;o[a++]=new Z(t.coord);for(let l=t.segmentIndex+1;l<=e.segmentIndex;l++)o[a++]=this._edge.getCoordinate(l);return r&&(o[a]=new Z(e.coord)),o}print(t){t.println("Intersections:");for(let e=this.iterator();e.hasNext();)e.next().print(t)}findCollapsesFromExistingVertices(t){for(let e=0;e<this._edge.size()-2;e++){const n=this._edge.getCoordinate(e);this._edge.getCoordinate(e+1);const s=this._edge.getCoordinate(e+2);n.equals2D(s)&&t.add(nl.valueOf(e+1))}}addEdgeCoordinates(t,e,n){const s=this.createSplitEdgePts(t,e);n.add(s,!1)}iterator(){return this._nodeMap.values().iterator()}addSplitEdges(t){this.addEndpoints(),this.addCollapsedNodes();const e=this.iterator();let n=e.next();for(;e.hasNext();){const s=e.next(),r=this.createSplitEdge(n,s);t.add(r),n=s}}findCollapseIndex(t,e,n){if(!t.coord.equals2D(e.coord))return!1;let s=e.segmentIndex-t.segmentIndex;return e.isInterior()||s--,s===1?(n[0]=t.segmentIndex+1,!0):!1}findCollapsesFromInsertedNodes(t){const e=new Array(1).fill(null),n=this.iterator();let s=n.next();for(;n.hasNext();){const r=n.next();this.findCollapseIndex(s,r,e)&&t.add(nl.valueOf(e[0])),s=r}}getEdge(){return this._edge}addEndpoints(){const t=this._edge.size()-1;this.add(this._edge.getCoordinate(0),0),this.add(this._edge.getCoordinate(t),t)}createSplitEdge(t,e){const n=this.createSplitEdgePts(t,e);return new Vs(n,this._edge.getData())}add(t,e){const n=new lp(this._edge,t,e,this._edge.getSegmentOctant(e)),s=this._nodeMap.get(n);return s!==null?(Yt.isTrue(s.coord.equals2D(t),"Found equal nodes with different coordinates"),s):(this._nodeMap.put(n,n),n)}checkSplitEdgesCorrectness(t){const e=this._edge.getCoordinates(),s=t.get(0).getCoordinate(0);if(!s.equals2D(e[0]))throw new ui("bad split edge start point at "+s);const o=t.get(t.size()-1).getCoordinates(),a=o[o.length-1];if(!a.equals2D(e[e.length-1]))throw new ui("bad split edge end point at "+a)}}class Jf{static octant(){if(typeof arguments[0]=="number"&&typeof arguments[1]=="number"){const t=arguments[0],e=arguments[1];if(t===0&&e===0)throw new Zt("Cannot compute the octant for point ( "+t+", "+e+" )");const n=Math.abs(t),s=Math.abs(e);return t>=0?e>=0?n>=s?0:1:n>=s?7:6:e>=0?n>=s?3:2:n>=s?4:5}else if(arguments[0]instanceof Z&&arguments[1]instanceof Z){const t=arguments[0],e=arguments[1],n=e.x-t.x,s=e.y-t.y;if(n===0&&s===0)throw new Zt("Cannot compute the octant for two identical points "+t);return Jf.octant(n,s)}}}class Rw{getCoordinates(){}size(){}getCoordinate(t){}isClosed(){}setData(t){}getData(){}}class WA{addIntersection(t,e){}get interfaces_(){return[Rw]}}class Vs{constructor(){Vs.constructor_.apply(this,arguments)}static constructor_(){this._nodeList=new up(this),this._pts=null,this._data=null;const t=arguments[0],e=arguments[1];this._pts=t,this._data=e}static getNodedSubstrings(){if(arguments.length===1){const t=arguments[0],e=new vt;return Vs.getNodedSubstrings(t,e),e}else if(arguments.length===2){const t=arguments[0],e=arguments[1];for(let n=t.iterator();n.hasNext();)n.next().getNodeList().addSplitEdges(e)}}getCoordinates(){return this._pts}size(){return this._pts.length}getCoordinate(t){return this._pts[t]}isClosed(){return this._pts[0].equals(this._pts[this._pts.length-1])}getSegmentOctant(t){return t===this._pts.length-1?-1:this.safeOctant(this.getCoordinate(t),this.getCoordinate(t+1))}setData(t){this._data=t}safeOctant(t,e){return t.equals2D(e)?0:Jf.octant(t,e)}getData(){return this._data}addIntersection(){if(arguments.length===2){const t=arguments[0],e=arguments[1];this.addIntersectionNode(t,e)}else if(arguments.length===4){const t=arguments[0],e=arguments[1],n=arguments[3],s=new Z(t.getIntersection(n));this.addIntersection(s,e)}}toString(){return Js.toLineString(new _s(this._pts))}getNodeList(){return this._nodeList}addIntersectionNode(t,e){let n=e;const s=n+1;if(s<this._pts.length){const o=this._pts[s];t.equals2D(o)&&(n=s)}return this._nodeList.add(t,n)}addIntersections(t,e,n){for(let s=0;s<t.getIntersectionNum();s++)this.addIntersection(t,e,n,s)}get interfaces_(){return[WA]}}class Se{constructor(){Se.constructor_.apply(this,arguments)}static constructor_(){if(this.p0=null,this.p1=null,arguments.length===0)Se.constructor_.call(this,new Z,new Z);else if(arguments.length===1){const t=arguments[0];Se.constructor_.call(this,t.p0,t.p1)}else if(arguments.length===2){const t=arguments[0],e=arguments[1];this.p0=t,this.p1=e}else if(arguments.length===4){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3];Se.constructor_.call(this,new Z(t,e),new Z(n,s))}}static midPoint(t,e){return new Z((t.x+e.x)/2,(t.y+e.y)/2)}minX(){return Math.min(this.p0.x,this.p1.x)}orientationIndex(){if(arguments[0]instanceof Se){const t=arguments[0],e=$t.index(this.p0,this.p1,t.p0),n=$t.index(this.p0,this.p1,t.p1);return e>=0&&n>=0||e<=0&&n<=0?Math.max(e,n):0}else if(arguments[0]instanceof Z){const t=arguments[0];return $t.index(this.p0,this.p1,t)}}toGeometry(t){return t.createLineString([this.p0,this.p1])}isVertical(){return this.p0.x===this.p1.x}equals(t){if(!(t instanceof Se))return!1;const e=t;return this.p0.equals(e.p0)&&this.p1.equals(e.p1)}intersection(t){const e=new Nn;return e.computeIntersection(this.p0,this.p1,t.p0,t.p1),e.hasIntersection()?e.getIntersection(0):null}project(){if(arguments[0]instanceof Z){const t=arguments[0];if(t.equals(this.p0)||t.equals(this.p1))return new Z(t);const e=this.projectionFactor(t),n=new Z;return n.x=this.p0.x+e*(this.p1.x-this.p0.x),n.y=this.p0.y+e*(this.p1.y-this.p0.y),n}else if(arguments[0]instanceof Se){const t=arguments[0],e=this.projectionFactor(t.p0),n=this.projectionFactor(t.p1);if(e>=1&&n>=1||e<=0&&n<=0)return null;let s=this.project(t.p0);e<0&&(s=this.p0),e>1&&(s=this.p1);let r=this.project(t.p1);return n<0&&(r=this.p0),n>1&&(r=this.p1),new Se(s,r)}}normalize(){this.p1.compareTo(this.p0)<0&&this.reverse()}angle(){return Math.atan2(this.p1.y-this.p0.y,this.p1.x-this.p0.x)}getCoordinate(t){return t===0?this.p0:this.p1}distancePerpendicular(t){return hn.pointToLinePerpendicular(t,this.p0,this.p1)}minY(){return Math.min(this.p0.y,this.p1.y)}midPoint(){return Se.midPoint(this.p0,this.p1)}projectionFactor(t){if(t.equals(this.p0))return 0;if(t.equals(this.p1))return 1;const e=this.p1.x-this.p0.x,n=this.p1.y-this.p0.y,s=e*e+n*n;return s<=0?Rt.NaN:((t.x-this.p0.x)*e+(t.y-this.p0.y)*n)/s}closestPoints(t){const e=this.intersection(t);if(e!==null)return[e,e];const n=new Array(2).fill(null);let s=Rt.MAX_VALUE,r=null;const o=this.closestPoint(t.p0);s=o.distance(t.p0),n[0]=o,n[1]=t.p0;const a=this.closestPoint(t.p1);r=a.distance(t.p1),r<s&&(s=r,n[0]=a,n[1]=t.p1);const l=t.closestPoint(this.p0);r=l.distance(this.p0),r<s&&(s=r,n[0]=this.p0,n[1]=l);const h=t.closestPoint(this.p1);return r=h.distance(this.p1),r<s&&(s=r,n[0]=this.p1,n[1]=h),n}closestPoint(t){const e=this.projectionFactor(t);if(e>0&&e<1)return this.project(t);const n=this.p0.distance(t),s=this.p1.distance(t);return n<s?this.p0:this.p1}maxX(){return Math.max(this.p0.x,this.p1.x)}getLength(){return this.p0.distance(this.p1)}compareTo(t){const e=t,n=this.p0.compareTo(e.p0);return n!==0?n:this.p1.compareTo(e.p1)}reverse(){const t=this.p0;this.p0=this.p1,this.p1=t}equalsTopo(t){return this.p0.equals(t.p0)&&this.p1.equals(t.p1)||this.p0.equals(t.p1)&&this.p1.equals(t.p0)}lineIntersection(t){return rp.intersection(this.p0,this.p1,t.p0,t.p1)}maxY(){return Math.max(this.p0.y,this.p1.y)}pointAlongOffset(t,e){const n=this.p0.x+t*(this.p1.x-this.p0.x),s=this.p0.y+t*(this.p1.y-this.p0.y),r=this.p1.x-this.p0.x,o=this.p1.y-this.p0.y,a=Math.sqrt(r*r+o*o);let l=0,h=0;if(e!==0){if(a<=0)throw new IllegalStateException("Cannot compute offset from zero-length line segment");l=e*r/a,h=e*o/a}const f=n-h,d=s+l;return new Z(f,d)}setCoordinates(){if(arguments.length===1){const t=arguments[0];this.setCoordinates(t.p0,t.p1)}else if(arguments.length===2){const t=arguments[0],e=arguments[1];this.p0.x=t.x,this.p0.y=t.y,this.p1.x=e.x,this.p1.y=e.y}}segmentFraction(t){let e=this.projectionFactor(t);return e<0?e=0:(e>1||Rt.isNaN(e))&&(e=1),e}toString(){return"LINESTRING( "+this.p0.x+" "+this.p0.y+", "+this.p1.x+" "+this.p1.y+")"}isHorizontal(){return this.p0.y===this.p1.y}reflect(t){const e=this.p1.getY()-this.p0.getY(),n=this.p0.getX()-this.p1.getX(),s=this.p0.getY()*(this.p1.getX()-this.p0.getX())-this.p0.getX()*(this.p1.getY()-this.p0.getY()),r=e*e+n*n,o=e*e-n*n,a=t.getX(),l=t.getY(),h=(-o*a-2*e*n*l-2*e*s)/r,f=(o*l-2*e*n*a-2*n*s)/r;return new Z(h,f)}distance(){if(arguments[0]instanceof Se){const t=arguments[0];return hn.segmentToSegment(this.p0,this.p1,t.p0,t.p1)}else if(arguments[0]instanceof Z){const t=arguments[0];return hn.pointToSegment(t,this.p0,this.p1)}}pointAlong(t){const e=new Z;return e.x=this.p0.x+t*(this.p1.x-this.p0.x),e.y=this.p0.y+t*(this.p1.y-this.p0.y),e}hashCode(){let t=Rt.doubleToLongBits(this.p0.x);t^=Rt.doubleToLongBits(this.p0.y)*31;const e=Math.trunc(t)^Math.trunc(t>>32);let n=Rt.doubleToLongBits(this.p1.x);n^=Rt.doubleToLongBits(this.p1.y)*31;const s=Math.trunc(n)^Math.trunc(n>>32);return e^s}get interfaces_(){return[gi,mi]}}class cp{constructor(){cp.constructor_.apply(this,arguments)}static constructor_(){this._overlapSeg1=new Se,this._overlapSeg2=new Se}overlap(){if(arguments.length!==2){if(arguments.length===4){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3];t.getLineSegment(e,this._overlapSeg1),n.getLineSegment(s,this._overlapSeg2),this.overlap(this._overlapSeg1,this._overlapSeg2)}}}}let Aw=class Ow{constructor(){Ow.constructor_.apply(this,arguments)}static constructor_(){this._pts=null,this._start=null,this._end=null,this._env=null,this._context=null,this._id=null;const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3];this._pts=t,this._start=e,this._end=n,this._context=s}getLineSegment(t,e){e.p0=this._pts[t],e.p1=this._pts[t+1]}computeSelect(t,e,n,s){const r=this._pts[e],o=this._pts[n];if(n-e===1)return s.select(this,e),null;if(!t.intersects(r,o))return null;const a=Math.trunc((e+n)/2);e<a&&this.computeSelect(t,e,a,s),a<n&&this.computeSelect(t,a,n,s)}getCoordinates(){const t=new Array(this._end-this._start+1).fill(null);let e=0;for(let n=this._start;n<=this._end;n++)t[e++]=this._pts[n];return t}computeOverlaps(){if(arguments.length===2){const t=arguments[0],e=arguments[1];this.computeOverlaps(this._start,this._end,t,t._start,t._end,e)}else if(arguments.length===6){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3],r=arguments[4],o=arguments[5];if(e-t===1&&r-s===1)return o.overlap(this,t,n,s),null;if(!this.overlaps(t,e,n,s,r))return null;const a=Math.trunc((t+e)/2),l=Math.trunc((s+r)/2);t<a&&(s<l&&this.computeOverlaps(t,a,n,s,l,o),l<r&&this.computeOverlaps(t,a,n,l,r,o)),a<e&&(s<l&&this.computeOverlaps(a,e,n,s,l,o),l<r&&this.computeOverlaps(a,e,n,l,r,o))}}setId(t){this._id=t}select(t,e){this.computeSelect(t,this._start,this._end,e)}getEnvelope(){if(this._env===null){const t=this._pts[this._start],e=this._pts[this._end];this._env=new te(t,e)}return this._env}overlaps(t,e,n,s,r){return te.intersects(this._pts[t],this._pts[e],n._pts[s],n._pts[r])}getEndIndex(){return this._end}getStartIndex(){return this._start}getContext(){return this._context}getId(){return this._id}};class cf{static findChainEnd(t,e){let n=e;for(;n<t.length-1&&t[n].equals2D(t[n+1]);)n++;if(n>=t.length-1)return t.length-1;const s=Ne.quadrant(t[n],t[n+1]);let r=e+1;for(;r<t.length&&!(!t[r-1].equals2D(t[r])&&Ne.quadrant(t[r-1],t[r])!==s);)r++;return r-1}static getChains(){if(arguments.length===1){const t=arguments[0];return cf.getChains(t,null)}else if(arguments.length===2){const t=arguments[0],e=arguments[1],n=new vt;let s=0;do{const r=cf.findChainEnd(t,s),o=new Aw(t,s,r,e);n.add(o),s=r}while(s<t.length-1);return n}}}class hp{computeNodes(t){}getNodedSubstrings(){}}class hf{constructor(){hf.constructor_.apply(this,arguments)}static constructor_(){if(this._segInt=null,arguments.length!==0){if(arguments.length===1){const t=arguments[0];this.setSegmentIntersector(t)}}}setSegmentIntersector(t){this._segInt=t}get interfaces_(){return[hp]}}class El extends hf{constructor(){super(),El.constructor_.apply(this,arguments)}static constructor_(){if(this._monoChains=new vt,this._index=new Je,this._idCounter=0,this._nodedSegStrings=null,this._nOverlaps=0,arguments.length!==0){if(arguments.length===1){const t=arguments[0];hf.constructor_.call(this,t)}}}getMonotoneChains(){return this._monoChains}getNodedSubstrings(){return Vs.getNodedSubstrings(this._nodedSegStrings)}getIndex(){return this._index}add(t){const e=cf.getChains(t.getCoordinates(),t);for(let n=e.iterator();n.hasNext();){const s=n.next();s.setId(this._idCounter++),this._index.insert(s.getEnvelope(),s),this._monoChains.add(s)}}computeNodes(t){this._nodedSegStrings=t;for(let e=t.iterator();e.hasNext();)this.add(e.next());this.intersectChains()}intersectChains(){const t=new Qf(this._segInt);for(let e=this._monoChains.iterator();e.hasNext();){const n=e.next(),s=this._index.query(n.getEnvelope());for(let r=s.iterator();r.hasNext();){const o=r.next();if(o.getId()>n.getId()&&(n.computeOverlaps(o,t),this._nOverlaps++),this._segInt.isDone())return null}}}}class Qf extends cp{constructor(){super(),Qf.constructor_.apply(this,arguments)}static constructor_(){this._si=null;const t=arguments[0];this._si=t}overlap(){if(arguments.length===4){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3],r=t.getContext(),o=n.getContext();this._si.processIntersections(r,e,o,s)}else return super.overlap.apply(this,arguments)}}El.SegmentOverlapAction=Qf;class yn{constructor(){yn.constructor_.apply(this,arguments)}static constructor_(){this._inputLine=null,this._distanceTol=null,this._isDeleted=null,this._angleOrientation=$t.COUNTERCLOCKWISE;const t=arguments[0];this._inputLine=t}static simplify(t,e){return new yn(t).simplify(e)}isDeletable(t,e,n,s){const r=this._inputLine[t],o=this._inputLine[e],a=this._inputLine[n];return!this.isConcave(r,o,a)||!this.isShallow(r,o,a,s)?!1:this.isShallowSampled(r,o,t,n,s)}deleteShallowConcavities(){let t=1,e=this.findNextNonDeletedIndex(t),n=this.findNextNonDeletedIndex(e),s=!1;for(;n<this._inputLine.length;){let r=!1;this.isDeletable(t,e,n,this._distanceTol)&&(this._isDeleted[e]=yn.DELETE,r=!0,s=!0),r?t=n:t=e,e=this.findNextNonDeletedIndex(t),n=this.findNextNonDeletedIndex(e)}return s}isShallowConcavity(t,e,n,s){return $t.index(t,e,n)===this._angleOrientation?hn.pointToSegment(e,t,n)<s:!1}isShallowSampled(t,e,n,s,r){let o=Math.trunc((s-n)/yn.NUM_PTS_TO_CHECK);o<=0&&(o=1);for(let a=n;a<s;a+=o)if(!this.isShallow(t,e,this._inputLine[a],r))return!1;return!0}isConcave(t,e,n){return $t.index(t,e,n)===this._angleOrientation}simplify(t){this._distanceTol=Math.abs(t),t<0&&(this._angleOrientation=$t.CLOCKWISE),this._isDeleted=new Array(this._inputLine.length).fill(null);let e=!1;do e=this.deleteShallowConcavities();while(e);return this.collapseLine()}findNextNonDeletedIndex(t){let e=t+1;for(;e<this._inputLine.length&&this._isDeleted[e]===yn.DELETE;)e++;return e}isShallow(t,e,n,s){return hn.pointToSegment(e,t,n)<s}collapseLine(){const t=new Qi;for(let e=0;e<this._inputLine.length;e++)this._isDeleted[e]!==yn.DELETE&&t.add(this._inputLine[e]);return t.toCoordinateArray()}}yn.INIT=0;yn.DELETE=1;yn.KEEP=1;yn.NUM_PTS_TO_CHECK=10;class Bu{constructor(){Bu.constructor_.apply(this,arguments)}static constructor_(){this._ptList=null,this._precisionModel=null,this._minimimVertexDistance=0,this._ptList=new vt}getCoordinates(){return this._ptList.toArray(Bu.COORDINATE_ARRAY_TYPE)}setPrecisionModel(t){this._precisionModel=t}addPt(t){const e=new Z(t);if(this._precisionModel.makePrecise(e),this.isRedundant(e))return null;this._ptList.add(e)}reverse(){}addPts(t,e){if(e)for(let n=0;n<t.length;n++)this.addPt(t[n]);else for(let n=t.length-1;n>=0;n--)this.addPt(t[n])}isRedundant(t){if(this._ptList.size()<1)return!1;const e=this._ptList.get(this._ptList.size()-1);return t.distance(e)<this._minimimVertexDistance}toString(){return new ze().createLineString(this.getCoordinates()).toString()}closeRing(){if(this._ptList.size()<1)return null;const t=new Z(this._ptList.get(0)),e=this._ptList.get(this._ptList.size()-1);if(t.equals(e))return null;this._ptList.add(t)}setMinimumVertexDistance(t){this._minimimVertexDistance=t}}Bu.COORDINATE_ARRAY_TYPE=new Array(0).fill(null);class pe{static toDegrees(t){return t*180/Math.PI}static normalize(t){for(;t>Math.PI;)t-=pe.PI_TIMES_2;for(;t<=-Math.PI;)t+=pe.PI_TIMES_2;return t}static angle(){if(arguments.length===1){const t=arguments[0];return Math.atan2(t.y,t.x)}else if(arguments.length===2){const t=arguments[0],e=arguments[1],n=e.x-t.x,s=e.y-t.y;return Math.atan2(s,n)}}static isAcute(t,e,n){const s=t.x-e.x,r=t.y-e.y,o=n.x-e.x,a=n.y-e.y;return s*o+r*a>0}static isObtuse(t,e,n){const s=t.x-e.x,r=t.y-e.y,o=n.x-e.x,a=n.y-e.y;return s*o+r*a<0}static interiorAngle(t,e,n){const s=pe.angle(e,t),r=pe.angle(e,n);return Math.abs(r-s)}static normalizePositive(t){if(t<0){for(;t<0;)t+=pe.PI_TIMES_2;t>=pe.PI_TIMES_2&&(t=0)}else{for(;t>=pe.PI_TIMES_2;)t-=pe.PI_TIMES_2;t<0&&(t=0)}return t}static angleBetween(t,e,n){const s=pe.angle(e,t),r=pe.angle(e,n);return pe.diff(s,r)}static diff(t,e){let n=null;return t<e?n=e-t:n=t-e,n>Math.PI&&(n=2*Math.PI-n),n}static toRadians(t){return t*Math.PI/180}static getTurn(t,e){const n=Math.sin(e-t);return n>0?pe.COUNTERCLOCKWISE:n<0?pe.CLOCKWISE:pe.NONE}static angleBetweenOriented(t,e,n){const s=pe.angle(e,t),o=pe.angle(e,n)-s;return o<=-Math.PI?o+pe.PI_TIMES_2:o>Math.PI?o-pe.PI_TIMES_2:o}}pe.PI_TIMES_2=2*Math.PI;pe.PI_OVER_2=Math.PI/2;pe.PI_OVER_4=Math.PI/4;pe.COUNTERCLOCKWISE=$t.COUNTERCLOCKWISE;pe.CLOCKWISE=$t.CLOCKWISE;pe.NONE=$t.COLLINEAR;class gs{constructor(){gs.constructor_.apply(this,arguments)}static constructor_(){this._maxCurveSegmentError=0,this._filletAngleQuantum=null,this._closingSegLengthFactor=1,this._segList=null,this._distance=0,this._precisionModel=null,this._bufParams=null,this._li=null,this._s0=null,this._s1=null,this._s2=null,this._seg0=new Se,this._seg1=new Se,this._offset0=new Se,this._offset1=new Se,this._side=0,this._hasNarrowConcaveAngle=!1;const t=arguments[0],e=arguments[1],n=arguments[2];this._precisionModel=t,this._bufParams=e,this._li=new Nn,this._filletAngleQuantum=Math.PI/2/e.getQuadrantSegments(),e.getQuadrantSegments()>=8&&e.getJoinStyle()===ie.JOIN_ROUND&&(this._closingSegLengthFactor=gs.MAX_CLOSING_SEG_LEN_FACTOR),this.init(n)}addNextSegment(t,e){if(this._s0=this._s1,this._s1=this._s2,this._s2=t,this._seg0.setCoordinates(this._s0,this._s1),this.computeOffsetSegment(this._seg0,this._side,this._distance,this._offset0),this._seg1.setCoordinates(this._s1,this._s2),this.computeOffsetSegment(this._seg1,this._side,this._distance,this._offset1),this._s1.equals(this._s2))return null;const n=$t.index(this._s0,this._s1,this._s2),s=n===$t.CLOCKWISE&&this._side===yt.LEFT||n===$t.COUNTERCLOCKWISE&&this._side===yt.RIGHT;n===0?this.addCollinear(e):s?this.addOutsideTurn(n,e):this.addInsideTurn(n,e)}addLineEndCap(t,e){const n=new Se(t,e),s=new Se;this.computeOffsetSegment(n,yt.LEFT,this._distance,s);const r=new Se;this.computeOffsetSegment(n,yt.RIGHT,this._distance,r);const o=e.x-t.x,a=e.y-t.y,l=Math.atan2(a,o);switch(this._bufParams.getEndCapStyle()){case ie.CAP_ROUND:this._segList.addPt(s.p1),this.addDirectedFillet(e,l+Math.PI/2,l-Math.PI/2,$t.CLOCKWISE,this._distance),this._segList.addPt(r.p1);break;case ie.CAP_FLAT:this._segList.addPt(s.p1),this._segList.addPt(r.p1);break;case ie.CAP_SQUARE:const h=new Z;h.x=Math.abs(this._distance)*Math.cos(l),h.y=Math.abs(this._distance)*Math.sin(l);const f=new Z(s.p1.x+h.x,s.p1.y+h.y),d=new Z(r.p1.x+h.x,r.p1.y+h.y);this._segList.addPt(f),this._segList.addPt(d);break}}getCoordinates(){return this._segList.getCoordinates()}addMitreJoin(t,e,n,s){const r=rp.intersection(e.p0,e.p1,n.p0,n.p1);if(r!==null&&(s<=0?1:r.distance(t)/Math.abs(s))<=this._bufParams.getMitreLimit())return this._segList.addPt(r),null;this.addLimitedMitreJoin(e,n,s,this._bufParams.getMitreLimit())}addOutsideTurn(t,e){if(this._offset0.p1.distance(this._offset1.p0)<this._distance*gs.OFFSET_SEGMENT_SEPARATION_FACTOR)return this._segList.addPt(this._offset0.p1),null;this._bufParams.getJoinStyle()===ie.JOIN_MITRE?this.addMitreJoin(this._s1,this._offset0,this._offset1,this._distance):this._bufParams.getJoinStyle()===ie.JOIN_BEVEL?this.addBevelJoin(this._offset0,this._offset1):(e&&this._segList.addPt(this._offset0.p1),this.addCornerFillet(this._s1,this._offset0.p1,this._offset1.p0,t,this._distance),this._segList.addPt(this._offset1.p0))}createSquare(t){this._segList.addPt(new Z(t.x+this._distance,t.y+this._distance)),this._segList.addPt(new Z(t.x+this._distance,t.y-this._distance)),this._segList.addPt(new Z(t.x-this._distance,t.y-this._distance)),this._segList.addPt(new Z(t.x-this._distance,t.y+this._distance)),this._segList.closeRing()}addSegments(t,e){this._segList.addPts(t,e)}addFirstSegment(){this._segList.addPt(this._offset1.p0)}addCornerFillet(t,e,n,s,r){const o=e.x-t.x,a=e.y-t.y;let l=Math.atan2(a,o);const h=n.x-t.x,f=n.y-t.y,d=Math.atan2(f,h);s===$t.CLOCKWISE?l<=d&&(l+=2*Math.PI):l>=d&&(l-=2*Math.PI),this._segList.addPt(e),this.addDirectedFillet(t,l,d,s,r),this._segList.addPt(n)}addLastSegment(){this._segList.addPt(this._offset1.p1)}initSideSegments(t,e,n){this._s1=t,this._s2=e,this._side=n,this._seg1.setCoordinates(t,e),this.computeOffsetSegment(this._seg1,n,this._distance,this._offset1)}addLimitedMitreJoin(t,e,n,s){const r=this._seg0.p1,o=pe.angle(r,this._seg0.p0),l=pe.angleBetweenOriented(this._seg0.p0,r,this._seg1.p1)/2,h=pe.normalize(o+l),f=pe.normalize(h+Math.PI),d=s*n,p=d*Math.abs(Math.sin(l)),y=n-p,_=r.x+d*Math.cos(f),E=r.y+d*Math.sin(f),w=new Z(_,E),L=new Se(r,w),b=L.pointAlongOffset(1,y),P=L.pointAlongOffset(1,-y);this._side===yt.LEFT?(this._segList.addPt(b),this._segList.addPt(P)):(this._segList.addPt(P),this._segList.addPt(b))}addDirectedFillet(t,e,n,s,r){const o=s===$t.CLOCKWISE?-1:1,a=Math.abs(e-n),l=Math.trunc(a/this._filletAngleQuantum+.5);if(l<1)return null;const h=a/l,f=new Z;for(let d=0;d<l;d++){const p=e+o*d*h;f.x=t.x+r*Math.cos(p),f.y=t.y+r*Math.sin(p),this._segList.addPt(f)}}computeOffsetSegment(t,e,n,s){const r=e===yt.LEFT?1:-1,o=t.p1.x-t.p0.x,a=t.p1.y-t.p0.y,l=Math.sqrt(o*o+a*a),h=r*n*o/l,f=r*n*a/l;s.p0.x=t.p0.x-f,s.p0.y=t.p0.y+h,s.p1.x=t.p1.x-f,s.p1.y=t.p1.y+h}addInsideTurn(t,e){if(this._li.computeIntersection(this._offset0.p0,this._offset0.p1,this._offset1.p0,this._offset1.p1),this._li.hasIntersection())this._segList.addPt(this._li.getIntersection(0));else if(this._hasNarrowConcaveAngle=!0,this._offset0.p1.distance(this._offset1.p0)<this._distance*gs.INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR)this._segList.addPt(this._offset0.p1);else{if(this._segList.addPt(this._offset0.p1),this._closingSegLengthFactor>0){const n=new Z((this._closingSegLengthFactor*this._offset0.p1.x+this._s1.x)/(this._closingSegLengthFactor+1),(this._closingSegLengthFactor*this._offset0.p1.y+this._s1.y)/(this._closingSegLengthFactor+1));this._segList.addPt(n);const s=new Z((this._closingSegLengthFactor*this._offset1.p0.x+this._s1.x)/(this._closingSegLengthFactor+1),(this._closingSegLengthFactor*this._offset1.p0.y+this._s1.y)/(this._closingSegLengthFactor+1));this._segList.addPt(s)}else this._segList.addPt(this._s1);this._segList.addPt(this._offset1.p0)}}createCircle(t){const e=new Z(t.x+this._distance,t.y);this._segList.addPt(e),this.addDirectedFillet(t,0,2*Math.PI,-1,this._distance),this._segList.closeRing()}addBevelJoin(t,e){this._segList.addPt(t.p1),this._segList.addPt(e.p0)}init(t){this._distance=t,this._maxCurveSegmentError=t*(1-Math.cos(this._filletAngleQuantum/2)),this._segList=new Bu,this._segList.setPrecisionModel(this._precisionModel),this._segList.setMinimumVertexDistance(t*gs.CURVE_VERTEX_SNAP_DISTANCE_FACTOR)}addCollinear(t){this._li.computeIntersection(this._s0,this._s1,this._s1,this._s2),this._li.getIntersectionNum()>=2&&(this._bufParams.getJoinStyle()===ie.JOIN_BEVEL||this._bufParams.getJoinStyle()===ie.JOIN_MITRE?(t&&this._segList.addPt(this._offset0.p1),this._segList.addPt(this._offset1.p0)):this.addCornerFillet(this._s1,this._offset0.p1,this._offset1.p0,$t.CLOCKWISE,this._distance))}closeRing(){this._segList.closeRing()}hasNarrowConcaveAngle(){return this._hasNarrowConcaveAngle}}gs.OFFSET_SEGMENT_SEPARATION_FACTOR=.001;gs.INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR=.001;gs.CURVE_VERTEX_SNAP_DISTANCE_FACTOR=1e-6;gs.MAX_CLOSING_SEG_LEN_FACTOR=80;class ff{constructor(){ff.constructor_.apply(this,arguments)}static constructor_(){this._distance=0,this._precisionModel=null,this._bufParams=null;const t=arguments[0],e=arguments[1];this._precisionModel=t,this._bufParams=e}static copyCoordinates(t){const e=new Array(t.length).fill(null);for(let n=0;n<e.length;n++)e[n]=new Z(t[n]);return e}getOffsetCurve(t,e){if(this._distance=e,e===0)return null;const n=e<0,s=Math.abs(e),r=this.getSegGen(s);t.length<=1?this.computePointCurve(t[0],r):this.computeOffsetCurve(t,n,r);const o=r.getCoordinates();return n&&Le.reverse(o),o}computeSingleSidedBufferCurve(t,e,n){const s=this.simplifyTolerance(this._distance);if(e){n.addSegments(t,!0);const r=yn.simplify(t,-s),o=r.length-1;n.initSideSegments(r[o],r[o-1],yt.LEFT),n.addFirstSegment();for(let a=o-2;a>=0;a--)n.addNextSegment(r[a],!0)}else{n.addSegments(t,!1);const r=yn.simplify(t,s),o=r.length-1;n.initSideSegments(r[0],r[1],yt.LEFT),n.addFirstSegment();for(let a=2;a<=o;a++)n.addNextSegment(r[a],!0)}n.addLastSegment(),n.closeRing()}computeRingBufferCurve(t,e,n){let s=this.simplifyTolerance(this._distance);e===yt.RIGHT&&(s=-s);const r=yn.simplify(t,s),o=r.length-1;n.initSideSegments(r[o-1],r[0],e);for(let a=1;a<=o;a++){const l=a!==1;n.addNextSegment(r[a],l)}n.closeRing()}computeLineBufferCurve(t,e){const n=this.simplifyTolerance(this._distance),s=yn.simplify(t,n),r=s.length-1;e.initSideSegments(s[0],s[1],yt.LEFT);for(let l=2;l<=r;l++)e.addNextSegment(s[l],!0);e.addLastSegment(),e.addLineEndCap(s[r-1],s[r]);const o=yn.simplify(t,-n),a=o.length-1;e.initSideSegments(o[a],o[a-1],yt.LEFT);for(let l=a-2;l>=0;l--)e.addNextSegment(o[l],!0);e.addLastSegment(),e.addLineEndCap(o[1],o[0]),e.closeRing()}computePointCurve(t,e){switch(this._bufParams.getEndCapStyle()){case ie.CAP_ROUND:e.createCircle(t);break;case ie.CAP_SQUARE:e.createSquare(t);break}}getLineCurve(t,e){if(this._distance=e,this.isLineOffsetEmpty(e))return null;const n=Math.abs(e),s=this.getSegGen(n);if(t.length<=1)this.computePointCurve(t[0],s);else if(this._bufParams.isSingleSided()){const o=e<0;this.computeSingleSidedBufferCurve(t,o,s)}else this.computeLineBufferCurve(t,s);return s.getCoordinates()}getBufferParameters(){return this._bufParams}simplifyTolerance(t){return t*this._bufParams.getSimplifyFactor()}getRingCurve(t,e,n){if(this._distance=n,t.length<=2)return this.getLineCurve(t,n);if(n===0)return ff.copyCoordinates(t);const s=this.getSegGen(n);return this.computeRingBufferCurve(t,e,s),s.getCoordinates()}computeOffsetCurve(t,e,n){const s=this.simplifyTolerance(this._distance);if(e){const r=yn.simplify(t,-s),o=r.length-1;n.initSideSegments(r[o],r[o-1],yt.LEFT),n.addFirstSegment();for(let a=o-2;a>=0;a--)n.addNextSegment(r[a],!0)}else{const r=yn.simplify(t,s),o=r.length-1;n.initSideSegments(r[0],r[1],yt.LEFT),n.addFirstSegment();for(let a=2;a<=o;a++)n.addNextSegment(r[a],!0)}n.addLastSegment()}isLineOffsetEmpty(t){return t===0||t<0&&!this._bufParams.isSingleSided()}getSegGen(t){return new gs(this._precisionModel,this._bufParams,t)}}class td{constructor(){td.constructor_.apply(this,arguments)}static constructor_(){this._subgraphs=null,this._seg=new Se;const t=arguments[0];this._subgraphs=t}findStabbedSegments(){if(arguments.length===1){const t=arguments[0],e=new vt;for(let n=this._subgraphs.iterator();n.hasNext();){const s=n.next(),r=s.getEnvelope();t.y<r.getMinY()||t.y>r.getMaxY()||this.findStabbedSegments(t,s.getDirectedEdges(),e)}return e}else if(arguments.length===3){if(Ot(arguments[2],Pi)&&arguments[0]instanceof Z&&arguments[1]instanceof Du){const t=arguments[0],e=arguments[1],n=arguments[2],s=e.getEdge().getCoordinates();for(let r=0;r<s.length-1;r++){if(this._seg.p0=s[r],this._seg.p1=s[r+1],this._seg.p0.y>this._seg.p1.y&&this._seg.reverse(),Math.max(this._seg.p0.x,this._seg.p1.x)<t.x||this._seg.isHorizontal()||t.y<this._seg.p0.y||t.y>this._seg.p1.y||$t.index(this._seg.p0,this._seg.p1,t)===$t.RIGHT)continue;let a=e.getDepth(yt.LEFT);this._seg.p0.equals(s[r])||(a=e.getDepth(yt.RIGHT));const l=new ed(this._seg,a);n.add(l)}}else if(Ot(arguments[2],Pi)&&arguments[0]instanceof Z&&Ot(arguments[1],Pi)){const t=arguments[0],e=arguments[1],n=arguments[2];for(let s=e.iterator();s.hasNext();){const r=s.next();r.isForward()&&this.findStabbedSegments(t,r,n)}}}}getDepth(t){const e=this.findStabbedSegments(t);return e.size()===0?0:_r.min(e)._leftDepth}}class ed{constructor(){ed.constructor_.apply(this,arguments)}static constructor_(){this._upwardSeg=null,this._leftDepth=null;const t=arguments[0],e=arguments[1];this._upwardSeg=new Se(t),this._leftDepth=e}compareTo(t){const e=t;if(this._upwardSeg.minX()>=e._upwardSeg.maxX())return 1;if(this._upwardSeg.maxX()<=e._upwardSeg.minX())return-1;let n=this._upwardSeg.orientationIndex(e._upwardSeg);return n!==0||(n=-1*e._upwardSeg.orientationIndex(this._upwardSeg),n!==0)?n:this._upwardSeg.compareTo(e._upwardSeg)}compareX(t,e){const n=t.p0.compareTo(e.p0);return n!==0?n:t.p1.compareTo(e.p1)}toString(){return this._upwardSeg.toString()}get interfaces_(){return[gi]}}td.DepthSegment=ed;class df extends Is{constructor(){super(),df.constructor_.apply(this,arguments)}static constructor_(){Is.constructor_.call(this,"Projective point not representable on the Cartesian plane.")}}class Mo{constructor(){Mo.constructor_.apply(this,arguments)}static constructor_(){if(this.x=null,this.y=null,this.w=null,arguments.length===0)this.x=0,this.y=0,this.w=1;else if(arguments.length===1){const t=arguments[0];this.x=t.x,this.y=t.y,this.w=1}else if(arguments.length===2){if(typeof arguments[0]=="number"&&typeof arguments[1]=="number"){const t=arguments[0],e=arguments[1];this.x=t,this.y=e,this.w=1}else if(arguments[0]instanceof Mo&&arguments[1]instanceof Mo){const t=arguments[0],e=arguments[1];this.x=t.y*e.w-e.y*t.w,this.y=e.x*t.w-t.x*e.w,this.w=t.x*e.y-e.x*t.y}else if(arguments[0]instanceof Z&&arguments[1]instanceof Z){const t=arguments[0],e=arguments[1];this.x=t.y-e.y,this.y=e.x-t.x,this.w=t.x*e.y-e.x*t.y}}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];this.x=t,this.y=e,this.w=n}else if(arguments.length===4){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3],r=t.y-e.y,o=e.x-t.x,a=t.x*e.y-e.x*t.y,l=n.y-s.y,h=s.x-n.x,f=n.x*s.y-s.x*n.y;this.x=o*f-h*a,this.y=l*a-r*f,this.w=r*h-l*o}}getY(){const t=this.y/this.w;if(Rt.isNaN(t)||Rt.isInfinite(t))throw new df;return t}getX(){const t=this.x/this.w;if(Rt.isNaN(t)||Rt.isInfinite(t))throw new df;return t}getCoordinate(){const t=new Z;return t.x=this.getX(),t.y=this.getY(),t}}class Yn{constructor(){Yn.constructor_.apply(this,arguments)}static constructor_(){this.p0=null,this.p1=null,this.p2=null;const t=arguments[0],e=arguments[1],n=arguments[2];this.p0=t,this.p1=e,this.p2=n}static area(t,e,n){return Math.abs(((n.x-t.x)*(e.y-t.y)-(e.x-t.x)*(n.y-t.y))/2)}static signedArea(t,e,n){return((n.x-t.x)*(e.y-t.y)-(e.x-t.x)*(n.y-t.y))/2}static det(t,e,n,s){return t*s-e*n}static interpolateZ(t,e,n,s){const r=e.x,o=e.y,a=n.x-r,l=s.x-r,h=n.y-o,f=s.y-o,d=a*f-l*h,p=t.x-r,y=t.y-o,_=(f*p-l*y)/d,E=(-h*p+a*y)/d;return e.getZ()+_*(n.getZ()-e.getZ())+E*(s.getZ()-e.getZ())}static longestSideLength(t,e,n){const s=t.distance(e),r=e.distance(n),o=n.distance(t);let a=s;return r>a&&(a=r),o>a&&(a=o),a}static circumcentreDD(t,e,n){const s=ht.valueOf(t.x).subtract(n.x),r=ht.valueOf(t.y).subtract(n.y),o=ht.valueOf(e.x).subtract(n.x),a=ht.valueOf(e.y).subtract(n.y),l=ht.determinant(s,r,o,a).multiply(2),h=s.sqr().add(r.sqr()),f=o.sqr().add(a.sqr()),d=ht.determinant(r,h,a,f),p=ht.determinant(s,h,o,f),y=ht.valueOf(n.x).subtract(d.divide(l)).doubleValue(),_=ht.valueOf(n.y).add(p.divide(l)).doubleValue();return new Z(y,_)}static isAcute(t,e,n){return!(!pe.isAcute(t,e,n)||!pe.isAcute(e,n,t)||!pe.isAcute(n,t,e))}static circumcentre(t,e,n){const s=n.x,r=n.y,o=t.x-s,a=t.y-r,l=e.x-s,h=e.y-r,f=2*Yn.det(o,a,l,h),d=Yn.det(a,o*o+a*a,h,l*l+h*h),p=Yn.det(o,o*o+a*a,l,l*l+h*h),y=s-d/f,_=r+p/f;return new Z(y,_)}static perpendicularBisector(t,e){const n=e.x-t.x,s=e.y-t.y,r=new Mo(t.x+n/2,t.y+s/2,1),o=new Mo(t.x-s+n/2,t.y+n+s/2,1);return new Mo(r,o)}static angleBisector(t,e,n){const s=e.distance(t),r=e.distance(n),o=s/(s+r),a=n.x-t.x,l=n.y-t.y;return new Z(t.x+o*a,t.y+o*l)}static area3D(t,e,n){const s=e.x-t.x,r=e.y-t.y,o=e.getZ()-t.getZ(),a=n.x-t.x,l=n.y-t.y,h=n.getZ()-t.getZ(),f=r*h-o*l,d=o*a-s*h,p=s*l-r*a,y=f*f+d*d+p*p;return Math.sqrt(y)/2}static centroid(t,e,n){const s=(t.x+e.x+n.x)/3,r=(t.y+e.y+n.y)/3;return new Z(s,r)}static inCentre(t,e,n){const s=e.distance(n),r=t.distance(n),o=t.distance(e),a=s+r+o,l=(s*t.x+r*e.x+o*n.x)/a,h=(s*t.y+r*e.y+o*n.y)/a;return new Z(l,h)}area(){return Yn.area(this.p0,this.p1,this.p2)}signedArea(){return Yn.signedArea(this.p0,this.p1,this.p2)}interpolateZ(t){if(t===null)throw new Zt("Supplied point is null.");return Yn.interpolateZ(t,this.p0,this.p1,this.p2)}longestSideLength(){return Yn.longestSideLength(this.p0,this.p1,this.p2)}isAcute(){return Yn.isAcute(this.p0,this.p1,this.p2)}circumcentre(){return Yn.circumcentre(this.p0,this.p1,this.p2)}area3D(){return Yn.area3D(this.p0,this.p1,this.p2)}centroid(){return Yn.centroid(this.p0,this.p1,this.p2)}inCentre(){return Yn.inCentre(this.p0,this.p1,this.p2)}}class fp{constructor(){fp.constructor_.apply(this,arguments)}static constructor_(){this._inputGeom=null,this._distance=null,this._curveBuilder=null,this._curveList=new vt;const t=arguments[0],e=arguments[1],n=arguments[2];this._inputGeom=t,this._distance=e,this._curveBuilder=n}addRingSide(t,e,n,s,r){if(e===0&&t.length<fn.MINIMUM_VALID_SIZE)return null;let o=s,a=r;t.length>=fn.MINIMUM_VALID_SIZE&&$t.isCCW(t)&&(o=r,a=s,n=yt.opposite(n));const l=this._curveBuilder.getRingCurve(t,n,e);this.addCurve(l,o,a)}addRingBothSides(t,e){this.addRingSide(t,e,yt.LEFT,q.EXTERIOR,q.INTERIOR),this.addRingSide(t,e,yt.RIGHT,q.INTERIOR,q.EXTERIOR)}addPoint(t){if(this._distance<=0)return null;const e=t.getCoordinates(),n=this._curveBuilder.getLineCurve(e,this._distance);this.addCurve(n,q.EXTERIOR,q.INTERIOR)}addPolygon(t){let e=this._distance,n=yt.LEFT;this._distance<0&&(e=-this._distance,n=yt.RIGHT);const s=t.getExteriorRing(),r=Le.removeRepeatedPoints(s.getCoordinates());if(this._distance<0&&this.isErodedCompletely(s,this._distance)||this._distance<=0&&r.length<3)return null;this.addRingSide(r,e,n,q.EXTERIOR,q.INTERIOR);for(let o=0;o<t.getNumInteriorRing();o++){const a=t.getInteriorRingN(o),l=Le.removeRepeatedPoints(a.getCoordinates());this._distance>0&&this.isErodedCompletely(a,-this._distance)||this.addRingSide(l,e,yt.opposite(n),q.INTERIOR,q.EXTERIOR)}}isTriangleErodedCompletely(t,e){const n=new Yn(t[0],t[1],t[2]),s=n.inCentre();return hn.pointToSegment(s,n.p0,n.p1)<Math.abs(e)}addLineString(t){if(this._curveBuilder.isLineOffsetEmpty(this._distance))return null;const e=Le.removeRepeatedPoints(t.getCoordinates());if(Le.isRing(e)&&!this._curveBuilder.getBufferParameters().isSingleSided())this.addRingBothSides(e,this._distance);else{const n=this._curveBuilder.getLineCurve(e,this._distance);this.addCurve(n,q.EXTERIOR,q.INTERIOR)}}addCurve(t,e,n){if(t===null||t.length<2)return null;const s=new Vs(t,new Be(0,q.BOUNDARY,e,n));this._curveList.add(s)}getCurves(){return this.add(this._inputGeom),this._curveList}add(t){if(t.isEmpty())return null;if(t instanceof Te)this.addPolygon(t);else if(t instanceof ce)this.addLineString(t);else if(t instanceof Ge)this.addPoint(t);else if(t instanceof Ss)this.addCollection(t);else if(t instanceof ns)this.addCollection(t);else if(t instanceof hi)this.addCollection(t);else if(t instanceof ye)this.addCollection(t);else throw new ss(t.getGeometryType())}isErodedCompletely(t,e){const n=t.getCoordinates();if(n.length<4)return e<0;if(n.length===4)return this.isTriangleErodedCompletely(n,e);const s=t.getEnvelopeInternal(),r=Math.min(s.getHeight(),s.getWidth());return e<0&&2*Math.abs(e)>r}addCollection(t){for(let e=0;e<t.getNumGeometries();e++){const n=t.getGeometryN(e);this.add(n)}}}class Fw{locate(t){}}class Aa{constructor(){Aa.constructor_.apply(this,arguments)}static constructor_(){this._parent=null,this._atStart=null,this._max=null,this._index=null,this._subcollectionIterator=null;const t=arguments[0];this._parent=t,this._atStart=!0,this._index=0,this._max=t.getNumGeometries()}static isAtomic(t){return!(t instanceof ye)}next(){if(this._atStart)return this._atStart=!1,Aa.isAtomic(this._parent)&&this._index++,this._parent;if(this._subcollectionIterator!==null){if(this._subcollectionIterator.hasNext())return this._subcollectionIterator.next();this._subcollectionIterator=null}if(this._index>=this._max)throw new vl;const t=this._parent.getGeometryN(this._index++);return t instanceof ye?(this._subcollectionIterator=new Aa(t),this._subcollectionIterator.next()):t}remove(){throw new ss(this.getClass().getName())}hasNext(){if(this._atStart)return!0;if(this._subcollectionIterator!==null){if(this._subcollectionIterator.hasNext())return!0;this._subcollectionIterator=null}return!(this._index>=this._max)}get interfaces_(){return[HA]}}class Yi{constructor(){Yi.constructor_.apply(this,arguments)}static constructor_(){this._geom=null;const t=arguments[0];this._geom=t}static locatePointInPolygon(t,e){if(e.isEmpty())return q.EXTERIOR;const n=e.getExteriorRing(),s=Yi.locatePointInRing(t,n);if(s!==q.INTERIOR)return s;for(let r=0;r<e.getNumInteriorRing();r++){const o=e.getInteriorRingN(r),a=Yi.locatePointInRing(t,o);if(a===q.BOUNDARY)return q.BOUNDARY;if(a===q.INTERIOR)return q.EXTERIOR}return q.INTERIOR}static locatePointInRing(t,e){return e.getEnvelopeInternal().intersects(t)?ts.locateInRing(t,e.getCoordinates()):q.EXTERIOR}static containsPointInPolygon(t,e){return q.EXTERIOR!==Yi.locatePointInPolygon(t,e)}static locateInGeometry(t,e){if(e instanceof Te)return Yi.locatePointInPolygon(t,e);if(e instanceof ye){const n=new Aa(e);for(;n.hasNext();){const s=n.next();if(s!==e){const r=Yi.locateInGeometry(t,s);if(r!==q.EXTERIOR)return r}}}return q.EXTERIOR}static isContained(t,e){return q.EXTERIOR!==Yi.locate(t,e)}static locate(t,e){return e.isEmpty()||!e.getEnvelopeInternal().intersects(t)?q.EXTERIOR:Yi.locateInGeometry(t,e)}locate(t){return Yi.locate(t,this._geom)}get interfaces_(){return[Fw]}}class nd{constructor(){nd.constructor_.apply(this,arguments)}static constructor_(){this._edgeMap=new Qs,this._edgeList=null,this._ptInAreaLocation=[q.NONE,q.NONE]}getNextCW(t){this.getEdges();const e=this._edgeList.indexOf(t);let n=e-1;return e===0&&(n=this._edgeList.size()-1),this._edgeList.get(n)}propagateSideLabels(t){let e=q.NONE;for(let s=this.iterator();s.hasNext();){const o=s.next().getLabel();o.isArea(t)&&o.getLocation(t,yt.LEFT)!==q.NONE&&(e=o.getLocation(t,yt.LEFT))}if(e===q.NONE)return null;let n=e;for(let s=this.iterator();s.hasNext();){const r=s.next(),o=r.getLabel();if(o.getLocation(t,yt.ON)===q.NONE&&o.setLocation(t,yt.ON,n),o.isArea(t)){const a=o.getLocation(t,yt.LEFT),l=o.getLocation(t,yt.RIGHT);if(l!==q.NONE){if(l!==n)throw new ki("side location conflict",r.getCoordinate());a===q.NONE&&Yt.shouldNeverReachHere("found single null side (at "+r.getCoordinate()+")"),n=a}else Yt.isTrue(o.getLocation(t,yt.LEFT)===q.NONE,"found single null side"),o.setLocation(t,yt.RIGHT,n),o.setLocation(t,yt.LEFT,n)}}}getCoordinate(){const t=this.iterator();return t.hasNext()?t.next().getCoordinate():null}print(t){ci.out.println("EdgeEndStar: "+this.getCoordinate());for(let e=this.iterator();e.hasNext();)e.next().print(t)}isAreaLabelsConsistent(t){return this.computeEdgeEndLabels(t.getBoundaryNodeRule()),this.checkAreaLabelsConsistent(0)}checkAreaLabelsConsistent(t){const e=this.getEdges();if(e.size()<=0)return!0;const n=e.size()-1,r=e.get(n).getLabel().getLocation(t,yt.LEFT);Yt.isTrue(r!==q.NONE,"Found unlabelled area edge");let o=r;for(let a=this.iterator();a.hasNext();){const h=a.next().getLabel();Yt.isTrue(h.isArea(t),"Found non-area edge");const f=h.getLocation(t,yt.LEFT),d=h.getLocation(t,yt.RIGHT);if(f===d||d!==o)return!1;o=f}return!0}findIndex(t){this.iterator();for(let e=0;e<this._edgeList.size();e++)if(this._edgeList.get(e)===t)return e;return-1}iterator(){return this.getEdges().iterator()}getEdges(){return this._edgeList===null&&(this._edgeList=new vt(this._edgeMap.values())),this._edgeList}getLocation(t,e,n){return this._ptInAreaLocation[t]===q.NONE&&(this._ptInAreaLocation[t]=Yi.locate(e,n[t].getGeometry())),this._ptInAreaLocation[t]}toString(){const t=new Fu;t.append("EdgeEndStar: "+this.getCoordinate()),t.append(`
|
|
13
|
+
`);for(let e=this.iterator();e.hasNext();){const n=e.next();t.append(n),t.append(`
|
|
14
|
+
`)}return t.toString()}computeEdgeEndLabels(t){for(let e=this.iterator();e.hasNext();)e.next().computeLabel(t)}computeLabelling(t){this.computeEdgeEndLabels(t[0].getBoundaryNodeRule()),this.propagateSideLabels(0),this.propagateSideLabels(1);const e=[!1,!1];for(let n=this.iterator();n.hasNext();){const r=n.next().getLabel();for(let o=0;o<2;o++)r.isLine(o)&&r.getLocation(o)===q.BOUNDARY&&(e[o]=!0)}for(let n=this.iterator();n.hasNext();){const s=n.next(),r=s.getLabel();for(let o=0;o<2;o++)if(r.isAnyNull(o)){let a=q.NONE;if(e[o])a=q.EXTERIOR;else{const l=s.getCoordinate();a=this.getLocation(o,l,t)}r.setAllLocationsIfNull(o,a)}}}getDegree(){return this._edgeMap.size()}insertEdgeEnd(t,e){this._edgeMap.put(t,e),this._edgeList=null}}class dp extends nd{constructor(){super(),dp.constructor_.apply(this,arguments)}static constructor_(){this._resultAreaEdgeList=null,this._label=null,this._SCANNING_FOR_INCOMING=1,this._LINKING_TO_OUTGOING=2}linkResultDirectedEdges(){this.getResultAreaEdges();let t=null,e=null,n=this._SCANNING_FOR_INCOMING;for(let s=0;s<this._resultAreaEdgeList.size();s++){const r=this._resultAreaEdgeList.get(s),o=r.getSym();if(r.getLabel().isArea())switch(t===null&&r.isInResult()&&(t=r),n){case this._SCANNING_FOR_INCOMING:if(!o.isInResult())continue;e=o,n=this._LINKING_TO_OUTGOING;break;case this._LINKING_TO_OUTGOING:if(!r.isInResult())continue;e.setNext(r),n=this._SCANNING_FOR_INCOMING;break}}if(n===this._LINKING_TO_OUTGOING){if(t===null)throw new ki("no outgoing dirEdge found",this.getCoordinate());Yt.isTrue(t.isInResult(),"unable to link last incoming dirEdge"),e.setNext(t)}}insert(t){const e=t;this.insertEdgeEnd(e,e)}getRightmostEdge(){const t=this.getEdges(),e=t.size();if(e<1)return null;const n=t.get(0);if(e===1)return n;const s=t.get(e-1),r=n.getQuadrant(),o=s.getQuadrant();return Ne.isNorthern(r)&&Ne.isNorthern(o)?n:!Ne.isNorthern(r)&&!Ne.isNorthern(o)?s:n.getDy()!==0?n:s.getDy()!==0?s:(Yt.shouldNeverReachHere("found two horizontal edges incident on node"),null)}print(t){ci.out.println("DirectedEdgeStar: "+this.getCoordinate());for(let e=this.iterator();e.hasNext();){const n=e.next();t.print("out "),n.print(t),t.println(),t.print("in "),n.getSym().print(t),t.println()}}getResultAreaEdges(){if(this._resultAreaEdgeList!==null)return this._resultAreaEdgeList;this._resultAreaEdgeList=new vt;for(let t=this.iterator();t.hasNext();){const e=t.next();(e.isInResult()||e.getSym().isInResult())&&this._resultAreaEdgeList.add(e)}return this._resultAreaEdgeList}updateLabelling(t){for(let e=this.iterator();e.hasNext();){const s=e.next().getLabel();s.setAllLocationsIfNull(0,t.getLocation(0)),s.setAllLocationsIfNull(1,t.getLocation(1))}}linkAllDirectedEdges(){this.getEdges();let t=null,e=null;for(let n=this._edgeList.size()-1;n>=0;n--){const s=this._edgeList.get(n),r=s.getSym();e===null&&(e=r),t!==null&&r.setNext(t),t=s}e.setNext(t)}computeDepths(){if(arguments.length===1){const t=arguments[0],e=this.findIndex(t),n=t.getDepth(yt.LEFT),s=t.getDepth(yt.RIGHT),r=this.computeDepths(e+1,this._edgeList.size(),n);if(this.computeDepths(0,e,r)!==s)throw new ki("depth mismatch at "+t.getCoordinate())}else if(arguments.length===3){const t=arguments[0],e=arguments[1];let s=arguments[2];for(let r=t;r<e;r++){const o=this._edgeList.get(r);o.setEdgeDepths(yt.RIGHT,s),s=o.getDepth(yt.LEFT)}return s}}mergeSymLabels(){for(let t=this.iterator();t.hasNext();){const e=t.next();e.getLabel().merge(e.getSym().getLabel())}}linkMinimalDirectedEdges(t){let e=null,n=null,s=this._SCANNING_FOR_INCOMING;for(let r=this._resultAreaEdgeList.size()-1;r>=0;r--){const o=this._resultAreaEdgeList.get(r),a=o.getSym();switch(e===null&&o.getEdgeRing()===t&&(e=o),s){case this._SCANNING_FOR_INCOMING:if(a.getEdgeRing()!==t)continue;n=a,s=this._LINKING_TO_OUTGOING;break;case this._LINKING_TO_OUTGOING:if(o.getEdgeRing()!==t)continue;n.setNextMin(o),s=this._SCANNING_FOR_INCOMING;break}}s===this._LINKING_TO_OUTGOING&&(Yt.isTrue(e!==null,"found null for first outgoing dirEdge"),Yt.isTrue(e.getEdgeRing()===t,"unable to link last incoming dirEdge"),n.setNextMin(e))}getOutgoingDegree(){if(arguments.length===0){let t=0;for(let e=this.iterator();e.hasNext();)e.next().isInResult()&&t++;return t}else if(arguments.length===1){const t=arguments[0];let e=0;for(let n=this.iterator();n.hasNext();)n.next().getEdgeRing()===t&&e++;return e}}getLabel(){return this._label}findCoveredLineEdges(){let t=q.NONE;for(let n=this.iterator();n.hasNext();){const s=n.next(),r=s.getSym();if(!s.isLineEdge()){if(s.isInResult()){t=q.INTERIOR;break}if(r.isInResult()){t=q.EXTERIOR;break}}}if(t===q.NONE)return null;let e=t;for(let n=this.iterator();n.hasNext();){const s=n.next(),r=s.getSym();s.isLineEdge()?s.getEdge().setCovered(e===q.INTERIOR):(s.isInResult()&&(e=q.EXTERIOR),r.isInResult()&&(e=q.INTERIOR))}}computeLabelling(t){super.computeLabelling.call(this,t),this._label=new Be(q.NONE);for(let e=this.iterator();e.hasNext();){const r=e.next().getEdge().getLabel();for(let o=0;o<2;o++){const a=r.getLocation(o);(a===q.INTERIOR||a===q.BOUNDARY)&&this._label.setLocation(o,q.INTERIOR)}}}}class gp extends ap{constructor(){super()}createNode(t){return new yr(t,new dp)}}class Oa{constructor(){Oa.constructor_.apply(this,arguments)}static constructor_(){this._pts=null,this._orientation=null;const t=arguments[0];this._pts=t,this._orientation=Oa.orientation(t)}static orientation(t){return Le.increasingDirection(t)===1}static compareOriented(t,e,n,s){const r=e?1:-1,o=s?1:-1,a=e?t.length:-1,l=s?n.length:-1;let h=e?0:t.length-1,f=s?0:n.length-1;for(;;){const d=t[h].compareTo(n[f]);if(d!==0)return d;h+=r,f+=o;const p=h===a,y=f===l;if(p&&!y)return-1;if(!p&&y)return 1;if(p&&y)return 0}}compareTo(t){const e=t;return Oa.compareOriented(this._pts,this._orientation,e._pts,e._orientation)}get interfaces_(){return[gi]}}class id{constructor(){id.constructor_.apply(this,arguments)}static constructor_(){this._edges=new vt,this._ocaMap=new Qs}print(t){t.print("MULTILINESTRING ( ");for(let e=0;e<this._edges.size();e++){const n=this._edges.get(e);e>0&&t.print(","),t.print("(");const s=n.getCoordinates();for(let r=0;r<s.length;r++)r>0&&t.print(","),t.print(s[r].x+" "+s[r].y);t.println(")")}t.print(") ")}addAll(t){for(let e=t.iterator();e.hasNext();)this.add(e.next())}findEdgeIndex(t){for(let e=0;e<this._edges.size();e++)if(this._edges.get(e).equals(t))return e;return-1}iterator(){return this._edges.iterator()}getEdges(){return this._edges}get(t){return this._edges.get(t)}findEqualEdge(t){const e=new Oa(t.getCoordinates());return this._ocaMap.get(e)}add(t){this._edges.add(t);const e=new Oa(t.getCoordinates());this._ocaMap.put(e,t)}}let mp=class{processIntersections(t,e,n,s){}isDone(){}};class gf{constructor(){gf.constructor_.apply(this,arguments)}static constructor_(){this._hasIntersection=!1,this._hasProper=!1,this._hasProperInterior=!1,this._hasInterior=!1,this._properIntersectionPoint=null,this._li=null,this._isSelfIntersection=null,this.numIntersections=0,this.numInteriorIntersections=0,this.numProperIntersections=0,this.numTests=0;const t=arguments[0];this._li=t}static isAdjacentSegments(t,e){return Math.abs(t-e)===1}isTrivialIntersection(t,e,n,s){if(t===n&&this._li.getIntersectionNum()===1){if(gf.isAdjacentSegments(e,s))return!0;if(t.isClosed()){const r=t.size()-1;if(e===0&&s===r||s===0&&e===r)return!0}}return!1}getProperIntersectionPoint(){return this._properIntersectionPoint}hasProperInteriorIntersection(){return this._hasProperInterior}getLineIntersector(){return this._li}hasProperIntersection(){return this._hasProper}processIntersections(t,e,n,s){if(t===n&&e===s)return null;this.numTests++;const r=t.getCoordinates()[e],o=t.getCoordinates()[e+1],a=n.getCoordinates()[s],l=n.getCoordinates()[s+1];this._li.computeIntersection(r,o,a,l),this._li.hasIntersection()&&(this.numIntersections++,this._li.isInteriorIntersection()&&(this.numInteriorIntersections++,this._hasInterior=!0),this.isTrivialIntersection(t,e,n,s)||(this._hasIntersection=!0,t.addIntersections(this._li,e,0),n.addIntersections(this._li,s,1),this._li.isProper()&&(this.numProperIntersections++,this._hasProper=!0,this._hasProperInterior=!0)))}hasIntersection(){return this._hasIntersection}isDone(){return!1}hasInteriorIntersection(){return this._hasInterior}get interfaces_(){return[mp]}}class pp{constructor(){pp.constructor_.apply(this,arguments)}static constructor_(){this.coord=null,this.segmentIndex=null,this.dist=null;const t=arguments[0],e=arguments[1],n=arguments[2];this.coord=new Z(t),this.segmentIndex=e,this.dist=n}getSegmentIndex(){return this.segmentIndex}getCoordinate(){return this.coord}print(t){t.print(this.coord),t.print(" seg # = "+this.segmentIndex),t.println(" dist = "+this.dist)}compareTo(t){const e=t;return this.compare(e.segmentIndex,e.dist)}isEndPoint(t){return this.segmentIndex===0&&this.dist===0||this.segmentIndex===t}toString(){return this.coord+" seg # = "+this.segmentIndex+" dist = "+this.dist}getDistance(){return this.dist}compare(t,e){return this.segmentIndex<t?-1:this.segmentIndex>t?1:this.dist<e?-1:this.dist>e?1:0}get interfaces_(){return[gi]}}class yp{constructor(){yp.constructor_.apply(this,arguments)}static constructor_(){this._nodeMap=new Qs,this.edge=null;const t=arguments[0];this.edge=t}print(t){t.println("Intersections:");for(let e=this.iterator();e.hasNext();)e.next().print(t)}iterator(){return this._nodeMap.values().iterator()}addSplitEdges(t){this.addEndpoints();const e=this.iterator();let n=e.next();for(;e.hasNext();){const s=e.next(),r=this.createSplitEdge(n,s);t.add(r),n=s}}addEndpoints(){const t=this.edge.pts.length-1;this.add(this.edge.pts[0],0,0),this.add(this.edge.pts[t],t,0)}createSplitEdge(t,e){let n=e.segmentIndex-t.segmentIndex+2;const s=this.edge.pts[e.segmentIndex],r=e.dist>0||!e.coord.equals2D(s);r||n--;const o=new Array(n).fill(null);let a=0;o[a++]=new Z(t.coord);for(let l=t.segmentIndex+1;l<=e.segmentIndex;l++)o[a++]=this.edge.pts[l];return r&&(o[a]=e.coord),new ms(o,new Be(this.edge._label))}add(t,e,n){const s=new pp(t,e,n),r=this._nodeMap.get(s);return r!==null?r:(this._nodeMap.put(s,s),s)}isIntersection(t){for(let e=this.iterator();e.hasNext();)if(e.next().coord.equals(t))return!0;return!1}}class me{constructor(){me.constructor_.apply(this,arguments)}static constructor_(){if(this._matrix=null,arguments.length===0)this._matrix=Array(3).fill().map(()=>Array(3)),this.setAll(pt.FALSE);else if(arguments.length===1){if(typeof arguments[0]=="string"){const t=arguments[0];me.constructor_.call(this),this.set(t)}else if(arguments[0]instanceof me){const t=arguments[0];me.constructor_.call(this),this._matrix[q.INTERIOR][q.INTERIOR]=t._matrix[q.INTERIOR][q.INTERIOR],this._matrix[q.INTERIOR][q.BOUNDARY]=t._matrix[q.INTERIOR][q.BOUNDARY],this._matrix[q.INTERIOR][q.EXTERIOR]=t._matrix[q.INTERIOR][q.EXTERIOR],this._matrix[q.BOUNDARY][q.INTERIOR]=t._matrix[q.BOUNDARY][q.INTERIOR],this._matrix[q.BOUNDARY][q.BOUNDARY]=t._matrix[q.BOUNDARY][q.BOUNDARY],this._matrix[q.BOUNDARY][q.EXTERIOR]=t._matrix[q.BOUNDARY][q.EXTERIOR],this._matrix[q.EXTERIOR][q.INTERIOR]=t._matrix[q.EXTERIOR][q.INTERIOR],this._matrix[q.EXTERIOR][q.BOUNDARY]=t._matrix[q.EXTERIOR][q.BOUNDARY],this._matrix[q.EXTERIOR][q.EXTERIOR]=t._matrix[q.EXTERIOR][q.EXTERIOR]}}}static matches(){if(Number.isInteger(arguments[0])&&typeof arguments[1]=="string"){const t=arguments[0],e=arguments[1];return e===pt.SYM_DONTCARE||e===pt.SYM_TRUE&&(t>=0||t===pt.TRUE)||e===pt.SYM_FALSE&&t===pt.FALSE||e===pt.SYM_P&&t===pt.P||e===pt.SYM_L&&t===pt.L||e===pt.SYM_A&&t===pt.A}else if(typeof arguments[0]=="string"&&typeof arguments[1]=="string"){const t=arguments[0],e=arguments[1];return new me(t).matches(e)}}static isTrue(t){return t>=0||t===pt.TRUE}isIntersects(){return!this.isDisjoint()}isCovers(){return(me.isTrue(this._matrix[q.INTERIOR][q.INTERIOR])||me.isTrue(this._matrix[q.INTERIOR][q.BOUNDARY])||me.isTrue(this._matrix[q.BOUNDARY][q.INTERIOR])||me.isTrue(this._matrix[q.BOUNDARY][q.BOUNDARY]))&&this._matrix[q.EXTERIOR][q.INTERIOR]===pt.FALSE&&this._matrix[q.EXTERIOR][q.BOUNDARY]===pt.FALSE}isCoveredBy(){return(me.isTrue(this._matrix[q.INTERIOR][q.INTERIOR])||me.isTrue(this._matrix[q.INTERIOR][q.BOUNDARY])||me.isTrue(this._matrix[q.BOUNDARY][q.INTERIOR])||me.isTrue(this._matrix[q.BOUNDARY][q.BOUNDARY]))&&this._matrix[q.INTERIOR][q.EXTERIOR]===pt.FALSE&&this._matrix[q.BOUNDARY][q.EXTERIOR]===pt.FALSE}set(){if(arguments.length===1){const t=arguments[0];for(let e=0;e<t.length;e++){const n=Math.trunc(e/3),s=e%3;this._matrix[n][s]=pt.toDimensionValue(t.charAt(e))}}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];this._matrix[t][e]=n}}isContains(){return me.isTrue(this._matrix[q.INTERIOR][q.INTERIOR])&&this._matrix[q.EXTERIOR][q.INTERIOR]===pt.FALSE&&this._matrix[q.EXTERIOR][q.BOUNDARY]===pt.FALSE}setAtLeast(){if(arguments.length===1){const t=arguments[0];for(let e=0;e<t.length;e++){const n=Math.trunc(e/3),s=e%3;this.setAtLeast(n,s,pt.toDimensionValue(t.charAt(e)))}}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];this._matrix[t][e]<n&&(this._matrix[t][e]=n)}}setAtLeastIfValid(t,e,n){t>=0&&e>=0&&this.setAtLeast(t,e,n)}isWithin(){return me.isTrue(this._matrix[q.INTERIOR][q.INTERIOR])&&this._matrix[q.INTERIOR][q.EXTERIOR]===pt.FALSE&&this._matrix[q.BOUNDARY][q.EXTERIOR]===pt.FALSE}isTouches(t,e){return t>e?this.isTouches(e,t):t===pt.A&&e===pt.A||t===pt.L&&e===pt.L||t===pt.L&&e===pt.A||t===pt.P&&e===pt.A||t===pt.P&&e===pt.L?this._matrix[q.INTERIOR][q.INTERIOR]===pt.FALSE&&(me.isTrue(this._matrix[q.INTERIOR][q.BOUNDARY])||me.isTrue(this._matrix[q.BOUNDARY][q.INTERIOR])||me.isTrue(this._matrix[q.BOUNDARY][q.BOUNDARY])):!1}isOverlaps(t,e){return t===pt.P&&e===pt.P||t===pt.A&&e===pt.A?me.isTrue(this._matrix[q.INTERIOR][q.INTERIOR])&&me.isTrue(this._matrix[q.INTERIOR][q.EXTERIOR])&&me.isTrue(this._matrix[q.EXTERIOR][q.INTERIOR]):t===pt.L&&e===pt.L?this._matrix[q.INTERIOR][q.INTERIOR]===1&&me.isTrue(this._matrix[q.INTERIOR][q.EXTERIOR])&&me.isTrue(this._matrix[q.EXTERIOR][q.INTERIOR]):!1}isEquals(t,e){return t!==e?!1:me.isTrue(this._matrix[q.INTERIOR][q.INTERIOR])&&this._matrix[q.INTERIOR][q.EXTERIOR]===pt.FALSE&&this._matrix[q.BOUNDARY][q.EXTERIOR]===pt.FALSE&&this._matrix[q.EXTERIOR][q.INTERIOR]===pt.FALSE&&this._matrix[q.EXTERIOR][q.BOUNDARY]===pt.FALSE}toString(){const t=new jf("123456789");for(let e=0;e<3;e++)for(let n=0;n<3;n++)t.setCharAt(3*e+n,pt.toDimensionSymbol(this._matrix[e][n]));return t.toString()}setAll(t){for(let e=0;e<3;e++)for(let n=0;n<3;n++)this._matrix[e][n]=t}get(t,e){return this._matrix[t][e]}transpose(){let t=this._matrix[1][0];return this._matrix[1][0]=this._matrix[0][1],this._matrix[0][1]=t,t=this._matrix[2][0],this._matrix[2][0]=this._matrix[0][2],this._matrix[0][2]=t,t=this._matrix[2][1],this._matrix[2][1]=this._matrix[1][2],this._matrix[1][2]=t,this}matches(t){if(t.length!==9)throw new Zt("Should be length 9: "+t);for(let e=0;e<3;e++)for(let n=0;n<3;n++)if(!me.matches(this._matrix[e][n],t.charAt(3*e+n)))return!1;return!0}add(t){for(let e=0;e<3;e++)for(let n=0;n<3;n++)this.setAtLeast(e,n,t.get(e,n))}isDisjoint(){return this._matrix[q.INTERIOR][q.INTERIOR]===pt.FALSE&&this._matrix[q.INTERIOR][q.BOUNDARY]===pt.FALSE&&this._matrix[q.BOUNDARY][q.INTERIOR]===pt.FALSE&&this._matrix[q.BOUNDARY][q.BOUNDARY]===pt.FALSE}isCrosses(t,e){return t===pt.P&&e===pt.L||t===pt.P&&e===pt.A||t===pt.L&&e===pt.A?me.isTrue(this._matrix[q.INTERIOR][q.INTERIOR])&&me.isTrue(this._matrix[q.INTERIOR][q.EXTERIOR]):t===pt.L&&e===pt.P||t===pt.A&&e===pt.P||t===pt.A&&e===pt.L?me.isTrue(this._matrix[q.INTERIOR][q.INTERIOR])&&me.isTrue(this._matrix[q.EXTERIOR][q.INTERIOR]):t===pt.L&&e===pt.L?this._matrix[q.INTERIOR][q.INTERIOR]===0:!1}get interfaces_(){return[yc]}}class mf{constructor(){mf.constructor_.apply(this,arguments)}static constructor_(){if(this._data=null,this._size=0,arguments.length===0)mf.constructor_.call(this,10);else if(arguments.length===1){const t=arguments[0];this._data=new Array(t).fill(null)}}size(){return this._size}addAll(t){if(t===null||t.length===0)return null;this.ensureCapacity(this._size+t.length),ci.arraycopy(t,0,this._data,this._size,t.length),this._size+=t.length}ensureCapacity(t){if(t<=this._data.length)return null;const e=Math.max(t,this._data.length*2);this._data=Or.copyOf(this._data,e)}toArray(){const t=new Array(this._size).fill(null);return ci.arraycopy(this._data,0,t,0,this._size),t}add(t){this.ensureCapacity(this._size+1),this._data[this._size]=t,++this._size}}class _p{static toIntArray(t){const e=new Array(t.size()).fill(null);for(let n=0;n<e.length;n++)e[n]=t.get(n).intValue();return e}getChainStartIndices(t){let e=0;const n=new mf(Math.trunc(t.length/2));n.add(e);do{const s=this.findChainEnd(t,e);n.add(s),e=s}while(e<t.length-1);return n.toArray()}findChainEnd(t,e){const n=Ne.quadrant(t[e],t[e+1]);let s=e+1;for(;s<t.length&&Ne.quadrant(t[s-1],t[s])===n;)s++;return s-1}OLDgetChainStartIndices(t){let e=0;const n=new vt;n.add(e);do{const r=this.findChainEnd(t,e);n.add(r),e=r}while(e<t.length-1);return _p.toIntArray(n)}}class vp{constructor(){vp.constructor_.apply(this,arguments)}static constructor_(){this.e=null,this.pts=null,this.startIndex=null;const t=arguments[0];this.e=t,this.pts=t.getCoordinates();const e=new _p;this.startIndex=e.getChainStartIndices(this.pts)}getCoordinates(){return this.pts}getMaxX(t){const e=this.pts[this.startIndex[t]].x,n=this.pts[this.startIndex[t+1]].x;return e>n?e:n}getMinX(t){const e=this.pts[this.startIndex[t]].x,n=this.pts[this.startIndex[t+1]].x;return e<n?e:n}computeIntersectsForChain(){if(arguments.length===4){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3];this.computeIntersectsForChain(this.startIndex[t],this.startIndex[t+1],e,e.startIndex[n],e.startIndex[n+1],s)}else if(arguments.length===6){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3],r=arguments[4],o=arguments[5];if(e-t===1&&r-s===1)return o.addIntersections(this.e,t,n.e,s),null;if(!this.overlaps(t,e,n,s,r))return null;const a=Math.trunc((t+e)/2),l=Math.trunc((s+r)/2);t<a&&(s<l&&this.computeIntersectsForChain(t,a,n,s,l,o),l<r&&this.computeIntersectsForChain(t,a,n,l,r,o)),a<e&&(s<l&&this.computeIntersectsForChain(a,e,n,s,l,o),l<r&&this.computeIntersectsForChain(a,e,n,l,r,o))}}overlaps(t,e,n,s,r){return te.intersects(this.pts[t],this.pts[e],n.pts[s],n.pts[r])}getStartIndexes(){return this.startIndex}computeIntersects(t,e){for(let n=0;n<this.startIndex.length-1;n++)for(let s=0;s<t.startIndex.length-1;s++)this.computeIntersectsForChain(n,t,s,e)}}class hs{constructor(){hs.constructor_.apply(this,arguments)}static constructor_(){this._depth=Array(2).fill().map(()=>Array(3));for(let t=0;t<2;t++)for(let e=0;e<3;e++)this._depth[t][e]=hs.NULL_VALUE}static depthAtLocation(t){return t===q.EXTERIOR?0:t===q.INTERIOR?1:hs.NULL_VALUE}getDepth(t,e){return this._depth[t][e]}setDepth(t,e,n){this._depth[t][e]=n}isNull(){if(arguments.length===0){for(let t=0;t<2;t++)for(let e=0;e<3;e++)if(this._depth[t][e]!==hs.NULL_VALUE)return!1;return!0}else if(arguments.length===1){const t=arguments[0];return this._depth[t][1]===hs.NULL_VALUE}else if(arguments.length===2){const t=arguments[0],e=arguments[1];return this._depth[t][e]===hs.NULL_VALUE}}normalize(){for(let t=0;t<2;t++)if(!this.isNull(t)){let e=this._depth[t][1];this._depth[t][2]<e&&(e=this._depth[t][2]),e<0&&(e=0);for(let n=1;n<3;n++){let s=0;this._depth[t][n]>e&&(s=1),this._depth[t][n]=s}}}getDelta(t){return this._depth[t][yt.RIGHT]-this._depth[t][yt.LEFT]}getLocation(t,e){return this._depth[t][e]<=0?q.EXTERIOR:q.INTERIOR}toString(){return"A: "+this._depth[0][1]+","+this._depth[0][2]+" B: "+this._depth[1][1]+","+this._depth[1][2]}add(){if(arguments.length===1){const t=arguments[0];for(let e=0;e<2;e++)for(let n=1;n<3;n++){const s=t.getLocation(e,n);(s===q.EXTERIOR||s===q.INTERIOR)&&(this.isNull(e,n)?this._depth[e][n]=hs.depthAtLocation(s):this._depth[e][n]+=hs.depthAtLocation(s))}}else if(arguments.length===3){const t=arguments[0],e=arguments[1];arguments[2]===q.INTERIOR&&this._depth[t][e]++}}}hs.NULL_VALUE=-1;class ms extends Wf{constructor(){super(),ms.constructor_.apply(this,arguments)}static constructor_(){if(this.pts=null,this._env=null,this.eiList=new yp(this),this._name=null,this._mce=null,this._isIsolated=!0,this._depth=new hs,this._depthDelta=0,arguments.length===1){const t=arguments[0];ms.constructor_.call(this,t,null)}else if(arguments.length===2){const t=arguments[0],e=arguments[1];this.pts=t,this._label=e}}static updateIM(){if(arguments.length===2&&arguments[1]instanceof me&&arguments[0]instanceof Be){const t=arguments[0],e=arguments[1];e.setAtLeastIfValid(t.getLocation(0,yt.ON),t.getLocation(1,yt.ON),1),t.isArea()&&(e.setAtLeastIfValid(t.getLocation(0,yt.LEFT),t.getLocation(1,yt.LEFT),2),e.setAtLeastIfValid(t.getLocation(0,yt.RIGHT),t.getLocation(1,yt.RIGHT),2))}else return super.updateIM.apply(this,arguments)}getDepth(){return this._depth}getCollapsedEdge(){const t=new Array(2).fill(null);return t[0]=this.pts[0],t[1]=this.pts[1],new ms(t,Be.toLineLabel(this._label))}isIsolated(){return this._isIsolated}getCoordinates(){return this.pts}setIsolated(t){this._isIsolated=t}setName(t){this._name=t}equals(t){if(!(t instanceof ms))return!1;const e=t;if(this.pts.length!==e.pts.length)return!1;let n=!0,s=!0,r=this.pts.length;for(let o=0;o<this.pts.length;o++)if(this.pts[o].equals2D(e.pts[o])||(n=!1),this.pts[o].equals2D(e.pts[--r])||(s=!1),!n&&!s)return!1;return!0}getCoordinate(){if(arguments.length===0)return this.pts.length>0?this.pts[0]:null;if(arguments.length===1){const t=arguments[0];return this.pts[t]}}print(t){t.print("edge "+this._name+": "),t.print("LINESTRING (");for(let e=0;e<this.pts.length;e++)e>0&&t.print(","),t.print(this.pts[e].x+" "+this.pts[e].y);t.print(") "+this._label+" "+this._depthDelta)}computeIM(t){ms.updateIM(this._label,t)}isCollapsed(){return!this._label.isArea()||this.pts.length!==3?!1:!!this.pts[0].equals(this.pts[2])}isClosed(){return this.pts[0].equals(this.pts[this.pts.length-1])}getMaximumSegmentIndex(){return this.pts.length-1}getDepthDelta(){return this._depthDelta}getNumPoints(){return this.pts.length}printReverse(t){t.print("edge "+this._name+": ");for(let e=this.pts.length-1;e>=0;e--)t.print(this.pts[e]+" ");t.println("")}getMonotoneChainEdge(){return this._mce===null&&(this._mce=new vp(this)),this._mce}getEnvelope(){if(this._env===null){this._env=new te;for(let t=0;t<this.pts.length;t++)this._env.expandToInclude(this.pts[t])}return this._env}addIntersection(t,e,n,s){const r=new Z(t.getIntersection(s));let o=e,a=t.getEdgeDistance(n,s);const l=o+1;if(l<this.pts.length){const h=this.pts[l];r.equals2D(h)&&(o=l,a=0)}this.eiList.add(r,o,a)}toString(){const t=new jf;t.append("edge "+this._name+": "),t.append("LINESTRING (");for(let e=0;e<this.pts.length;e++)e>0&&t.append(","),t.append(this.pts[e].x+" "+this.pts[e].y);return t.append(") "+this._label+" "+this._depthDelta),t.toString()}isPointwiseEqual(t){if(this.pts.length!==t.pts.length)return!1;for(let e=0;e<this.pts.length;e++)if(!this.pts[e].equals2D(t.pts[e]))return!1;return!0}setDepthDelta(t){this._depthDelta=t}getEdgeIntersectionList(){return this.eiList}addIntersections(t,e,n){for(let s=0;s<t.getIntersectionNum();s++)this.addIntersection(t,e,n,s)}}class Fa{constructor(){Fa.constructor_.apply(this,arguments)}static constructor_(){this._bufParams=null,this._workingPrecisionModel=null,this._workingNoder=null,this._geomFact=null,this._graph=null,this._edgeList=new id;const t=arguments[0];this._bufParams=t}static depthDelta(t){const e=t.getLocation(0,yt.LEFT),n=t.getLocation(0,yt.RIGHT);return e===q.INTERIOR&&n===q.EXTERIOR?1:e===q.EXTERIOR&&n===q.INTERIOR?-1:0}static convertSegStrings(t){const e=new ze,n=new vt;for(;t.hasNext();){const s=t.next(),r=e.createLineString(s.getCoordinates());n.add(r)}return e.buildGeometry(n)}setWorkingPrecisionModel(t){this._workingPrecisionModel=t}insertUniqueEdge(t){const e=this._edgeList.findEqualEdge(t);if(e!==null){const n=e.getLabel();let s=t.getLabel();e.isPointwiseEqual(t)||(s=new Be(t.getLabel()),s.flip()),n.merge(s);const r=Fa.depthDelta(s),a=e.getDepthDelta()+r;e.setDepthDelta(a)}else this._edgeList.add(t),t.setDepthDelta(Fa.depthDelta(t.getLabel()))}buildSubgraphs(t,e){const n=new vt;for(let s=t.iterator();s.hasNext();){const r=s.next(),o=r.getRightmostCoordinate(),l=new td(n).getDepth(o);r.computeDepth(l),r.findResultEdges(),n.add(r),e.add(r.getDirectedEdges(),r.getNodes())}}createSubgraphs(t){const e=new vt;for(let n=t.getNodes().iterator();n.hasNext();){const s=n.next();if(!s.isVisited()){const r=new sp;r.create(s),e.add(r)}}return _r.sort(e,_r.reverseOrder()),e}createEmptyResultGeometry(){return this._geomFact.createPolygon()}getNoder(t){if(this._workingNoder!==null)return this._workingNoder;const e=new El,n=new Nn;return n.setPrecisionModel(t),e.setSegmentIntersector(new gf(n)),e}buffer(t,e){let n=this._workingPrecisionModel;n===null&&(n=t.getPrecisionModel()),this._geomFact=t.getFactory();const s=new ff(n,this._bufParams),o=new fp(t,e,s).getCurves();if(o.size()<=0)return this.createEmptyResultGeometry();this.computeNodedEdges(o,n),this._graph=new qo(new gp),this._graph.addEdges(this._edgeList.getEdges());const a=this.createSubgraphs(this._graph),l=new Gu(this._geomFact);this.buildSubgraphs(a,l);const h=l.getPolygons();return h.size()<=0?this.createEmptyResultGeometry():this._geomFact.buildGeometry(h)}computeNodedEdges(t,e){const n=this.getNoder(e);n.computeNodes(t);const s=n.getNodedSubstrings();for(let r=s.iterator();r.hasNext();){const o=r.next(),a=o.getCoordinates();if(a.length===2&&a[0].equals2D(a[1]))continue;const l=o.getData(),h=new ms(o.getCoordinates(),new Be(l));this.insertUniqueEdge(h)}}setNoder(t){this._workingNoder=t}}class pf{constructor(){pf.constructor_.apply(this,arguments)}static constructor_(){if(this._noder=null,this._scaleFactor=null,this._offsetX=null,this._offsetY=null,this._isScaled=!1,arguments.length===2){const t=arguments[0],e=arguments[1];pf.constructor_.call(this,t,e,0,0)}else if(arguments.length===4){const t=arguments[0],e=arguments[1];this._noder=t,this._scaleFactor=e,this._isScaled=!this.isIntegerPrecision()}}rescale(){if(Ot(arguments[0],sn)){const t=arguments[0];for(let e=t.iterator();e.hasNext();){const n=e.next();this.rescale(n.getCoordinates())}}else if(arguments[0]instanceof Array){const t=arguments[0];for(let e=0;e<t.length;e++)t[e].x=t[e].x/this._scaleFactor+this._offsetX,t[e].y=t[e].y/this._scaleFactor+this._offsetY;t.length===2&&t[0].equals2D(t[1])&&ci.out.println(t)}}scale(){if(Ot(arguments[0],sn)){const t=arguments[0],e=new vt(t.size());for(let n=t.iterator();n.hasNext();){const s=n.next();e.add(new Vs(this.scale(s.getCoordinates()),s.getData()))}return e}else if(arguments[0]instanceof Array){const t=arguments[0],e=new Array(t.length).fill(null);for(let s=0;s<t.length;s++)e[s]=new Z(Math.round((t[s].x-this._offsetX)*this._scaleFactor),Math.round((t[s].y-this._offsetY)*this._scaleFactor),t[s].getZ());return Le.removeRepeatedPoints(e)}}isIntegerPrecision(){return this._scaleFactor===1}getNodedSubstrings(){const t=this._noder.getNodedSubstrings();return this._isScaled&&this.rescale(t),t}computeNodes(t){let e=t;this._isScaled&&(e=this.scale(t)),this._noder.computeNodes(e)}get interfaces_(){return[hp]}}class qu{constructor(){qu.constructor_.apply(this,arguments)}static constructor_(){this._li=new Nn,this._segStrings=null;const t=arguments[0];this._segStrings=t}checkEndPtVertexIntersections(){if(arguments.length===0)for(let t=this._segStrings.iterator();t.hasNext();){const n=t.next().getCoordinates();this.checkEndPtVertexIntersections(n[0],this._segStrings),this.checkEndPtVertexIntersections(n[n.length-1],this._segStrings)}else if(arguments.length===2){const t=arguments[0],e=arguments[1];for(let n=e.iterator();n.hasNext();){const r=n.next().getCoordinates();for(let o=1;o<r.length-1;o++)if(r[o].equals(t))throw new ui("found endpt/interior pt intersection at index "+o+" :pt "+t)}}}checkInteriorIntersections(){if(arguments.length===0)for(let t=this._segStrings.iterator();t.hasNext();){const e=t.next();for(let n=this._segStrings.iterator();n.hasNext();){const s=n.next();this.checkInteriorIntersections(e,s)}}else if(arguments.length===2){const t=arguments[0],e=arguments[1],n=t.getCoordinates(),s=e.getCoordinates();for(let r=0;r<n.length-1;r++)for(let o=0;o<s.length-1;o++)this.checkInteriorIntersections(t,r,e,o)}else if(arguments.length===4){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3];if(t===n&&e===s)return null;const r=t.getCoordinates()[e],o=t.getCoordinates()[e+1],a=n.getCoordinates()[s],l=n.getCoordinates()[s+1];if(this._li.computeIntersection(r,o,a,l),this._li.hasIntersection()&&(this._li.isProper()||this.hasInteriorIntersection(this._li,r,o)||this.hasInteriorIntersection(this._li,a,l)))throw new ui("found non-noded intersection at "+r+"-"+o+" and "+a+"-"+l)}}checkValid(){this.checkEndPtVertexIntersections(),this.checkInteriorIntersections(),this.checkCollapses()}checkCollapses(){if(arguments.length===0)for(let t=this._segStrings.iterator();t.hasNext();){const e=t.next();this.checkCollapses(e)}else if(arguments.length===1){const e=arguments[0].getCoordinates();for(let n=0;n<e.length-2;n++)this.checkCollapse(e[n],e[n+1],e[n+2])}}hasInteriorIntersection(t,e,n){for(let s=0;s<t.getIntersectionNum();s++){const r=t.getIntersection(s);if(!(r.equals(e)||r.equals(n)))return!0}return!1}checkCollapse(t,e,n){if(t.equals(n))throw new ui("found non-noded collapse at "+qu.fact.createLineString([t,e,n]))}}qu.fact=new ze;class al{constructor(){al.constructor_.apply(this,arguments)}static constructor_(){this._li=null,this._pt=null,this._originalPt=null,this._ptScaled=null,this._p0Scaled=null,this._p1Scaled=null,this._scaleFactor=null,this._minx=null,this._maxx=null,this._miny=null,this._maxy=null,this._corner=new Array(4).fill(null),this._safeEnv=null;const t=arguments[0],e=arguments[1],n=arguments[2];if(this._originalPt=t,this._pt=t,this._scaleFactor=e,this._li=n,e<=0)throw new Zt("Scale factor must be non-zero");e!==1&&(this._pt=new Z(this.scale(t.x),this.scale(t.y)),this._p0Scaled=new Z,this._p1Scaled=new Z),this.initCorners(this._pt)}intersectsScaled(t,e){const n=Math.min(t.x,e.x),s=Math.max(t.x,e.x),r=Math.min(t.y,e.y),o=Math.max(t.y,e.y),a=this._maxx<n||this._minx>s||this._maxy<r||this._miny>o;if(a)return!1;const l=this.intersectsToleranceSquare(t,e);return Yt.isTrue(!(a&&l),"Found bad envelope test"),l}initCorners(t){this._minx=t.x-.5,this._maxx=t.x+.5,this._miny=t.y-.5,this._maxy=t.y+.5,this._corner[0]=new Z(this._maxx,this._maxy),this._corner[1]=new Z(this._minx,this._maxy),this._corner[2]=new Z(this._minx,this._miny),this._corner[3]=new Z(this._maxx,this._miny)}intersects(t,e){return this._scaleFactor===1?this.intersectsScaled(t,e):(this.copyScaled(t,this._p0Scaled),this.copyScaled(e,this._p1Scaled),this.intersectsScaled(this._p0Scaled,this._p1Scaled))}scale(t){return Math.round(t*this._scaleFactor)}getCoordinate(){return this._originalPt}copyScaled(t,e){e.x=this.scale(t.x),e.y=this.scale(t.y)}getSafeEnvelope(){if(this._safeEnv===null){const t=al.SAFE_ENV_EXPANSION_FACTOR/this._scaleFactor;this._safeEnv=new te(this._originalPt.x-t,this._originalPt.x+t,this._originalPt.y-t,this._originalPt.y+t)}return this._safeEnv}intersectsPixelClosure(t,e){return this._li.computeIntersection(t,e,this._corner[0],this._corner[1]),!!(this._li.hasIntersection()||(this._li.computeIntersection(t,e,this._corner[1],this._corner[2]),this._li.hasIntersection())||(this._li.computeIntersection(t,e,this._corner[2],this._corner[3]),this._li.hasIntersection())||(this._li.computeIntersection(t,e,this._corner[3],this._corner[0]),this._li.hasIntersection()))}intersectsToleranceSquare(t,e){let n=!1,s=!1;return this._li.computeIntersection(t,e,this._corner[0],this._corner[1]),!!(this._li.isProper()||(this._li.computeIntersection(t,e,this._corner[1],this._corner[2]),this._li.isProper())||(this._li.hasIntersection()&&(n=!0),this._li.computeIntersection(t,e,this._corner[2],this._corner[3]),this._li.isProper())||(this._li.hasIntersection()&&(s=!0),this._li.computeIntersection(t,e,this._corner[3],this._corner[0]),this._li.isProper())||n&&s||t.equals(this._pt)||e.equals(this._pt))}addSnappedNode(t,e){const n=t.getCoordinate(e),s=t.getCoordinate(e+1);return this.intersects(n,s)?(t.addIntersection(this.getCoordinate(),e),!0):!1}}al.SAFE_ENV_EXPANSION_FACTOR=.75;class Ep{constructor(){Ep.constructor_.apply(this,arguments)}static constructor_(){this.selectedSegment=new Se}select(){if(arguments.length!==1){if(arguments.length===2){const t=arguments[0],e=arguments[1];t.getLineSegment(e,this.selectedSegment),this.select(this.selectedSegment)}}}}class sd{constructor(){sd.constructor_.apply(this,arguments)}static constructor_(){this._index=null;const t=arguments[0];this._index=t}snap(){if(arguments.length===1){const t=arguments[0];return this.snap(t,null,-1)}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2],s=t.getSafeEnvelope(),r=new rd(t,e,n);return this._index.query(s,new class{get interfaces_(){return[Kf]}visitItem(o){o.select(s,r)}}),r.isNodeAdded()}}}class rd extends Ep{constructor(){super(),rd.constructor_.apply(this,arguments)}static constructor_(){this._hotPixel=null,this._parentEdge=null,this._hotPixelVertexIndex=null,this._isNodeAdded=!1;const t=arguments[0],e=arguments[1],n=arguments[2];this._hotPixel=t,this._parentEdge=e,this._hotPixelVertexIndex=n}isNodeAdded(){return this._isNodeAdded}select(){if(arguments.length===2&&Number.isInteger(arguments[1])&&arguments[0]instanceof Aw){const t=arguments[0],e=arguments[1],n=t.getContext();if(this._parentEdge===n&&(e===this._hotPixelVertexIndex||e+1===this._hotPixelVertexIndex))return null;this._isNodeAdded|=this._hotPixel.addSnappedNode(n,e)}else return super.select.apply(this,arguments)}}sd.HotPixelSnapAction=rd;class wp{constructor(){wp.constructor_.apply(this,arguments)}static constructor_(){this._li=null,this._interiorIntersections=null;const t=arguments[0];this._li=t,this._interiorIntersections=new vt}processIntersections(t,e,n,s){if(t===n&&e===s)return null;const r=t.getCoordinates()[e],o=t.getCoordinates()[e+1],a=n.getCoordinates()[s],l=n.getCoordinates()[s+1];if(this._li.computeIntersection(r,o,a,l),this._li.hasIntersection()&&this._li.isInteriorIntersection()){for(let h=0;h<this._li.getIntersectionNum();h++)this._interiorIntersections.add(this._li.getIntersection(h));t.addIntersections(this._li,e,0),n.addIntersections(this._li,s,1)}}isDone(){return!1}getInteriorIntersections(){return this._interiorIntersections}get interfaces_(){return[mp]}}class xp{constructor(){xp.constructor_.apply(this,arguments)}static constructor_(){this._pm=null,this._li=null,this._scaleFactor=null,this._noder=null,this._pointSnapper=null,this._nodedSegStrings=null;const t=arguments[0];this._pm=t,this._li=new Nn,this._li.setPrecisionModel(t),this._scaleFactor=t.getScale()}checkCorrectness(t){const e=Vs.getNodedSubstrings(t),n=new qu(e);try{n.checkValid()}catch(s){if(s instanceof Is)s.printStackTrace();else throw s}finally{}}getNodedSubstrings(){return Vs.getNodedSubstrings(this._nodedSegStrings)}snapRound(t,e){const n=this.findInteriorIntersections(t,e);this.computeIntersectionSnaps(n),this.computeVertexSnaps(t)}findInteriorIntersections(t,e){const n=new wp(e);return this._noder.setSegmentIntersector(n),this._noder.computeNodes(t),n.getInteriorIntersections()}computeVertexSnaps(){if(Ot(arguments[0],sn)){const t=arguments[0];for(let e=t.iterator();e.hasNext();){const n=e.next();this.computeVertexSnaps(n)}}else if(arguments[0]instanceof Vs){const t=arguments[0],e=t.getCoordinates();for(let n=0;n<e.length;n++){const s=new al(e[n],this._scaleFactor,this._li);this._pointSnapper.snap(s,t,n)&&t.addIntersection(e[n],n)}}}computeNodes(t){this._nodedSegStrings=t,this._noder=new El,this._pointSnapper=new sd(this._noder.getIndex()),this.snapRound(t,this._li)}computeIntersectionSnaps(t){for(let e=t.iterator();e.hasNext();){const n=e.next(),s=new al(n,this._scaleFactor,this._li);this._pointSnapper.snap(s)}}get interfaces_(){return[hp]}}class _n{constructor(){_n.constructor_.apply(this,arguments)}static constructor_(){if(this._argGeom=null,this._distance=null,this._bufParams=new ie,this._resultGeometry=null,this._saveException=null,arguments.length===1){const t=arguments[0];this._argGeom=t}else if(arguments.length===2){const t=arguments[0],e=arguments[1];this._argGeom=t,this._bufParams=e}}static bufferOp(){if(arguments.length===2){const t=arguments[0],e=arguments[1];return new _n(t).getResultGeometry(e)}else if(arguments.length===3){if(Number.isInteger(arguments[2])&&arguments[0]instanceof dt&&typeof arguments[1]=="number"){const t=arguments[0],e=arguments[1],n=arguments[2],s=new _n(t);return s.setQuadrantSegments(n),s.getResultGeometry(e)}else if(arguments[2]instanceof ie&&arguments[0]instanceof dt&&typeof arguments[1]=="number"){const t=arguments[0],e=arguments[1],n=arguments[2];return new _n(t,n).getResultGeometry(e)}}else if(arguments.length===4){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3],r=new _n(t);return r.setQuadrantSegments(n),r.setEndCapStyle(s),r.getResultGeometry(e)}}static precisionScaleFactor(t,e,n){const s=t.getEnvelopeInternal(),r=Oo.max(Math.abs(s.getMaxX()),Math.abs(s.getMaxY()),Math.abs(s.getMinX()),Math.abs(s.getMinY())),o=e>0?e:0,a=r+2*o,l=Math.trunc(Math.log(a)/Math.log(10)+1),h=n-l;return Math.pow(10,h)}bufferFixedPrecision(t){const e=new pf(new xp(new Ee(1)),t.getScale()),n=new Fa(this._bufParams);n.setWorkingPrecisionModel(t),n.setNoder(e),this._resultGeometry=n.buffer(this._argGeom,this._distance)}bufferReducedPrecision(){if(arguments.length===0){for(let t=_n.MAX_PRECISION_DIGITS;t>=0;t--){try{this.bufferReducedPrecision(t)}catch(e){if(e instanceof ki)this._saveException=e;else throw e}finally{}if(this._resultGeometry!==null)return null}throw this._saveException}else if(arguments.length===1){const t=arguments[0],e=_n.precisionScaleFactor(this._argGeom,this._distance,t),n=new Ee(e);this.bufferFixedPrecision(n)}}computeGeometry(){if(this.bufferOriginalPrecision(),this._resultGeometry!==null)return null;const t=this._argGeom.getFactory().getPrecisionModel();t.getType()===Ee.FIXED?this.bufferFixedPrecision(t):this.bufferReducedPrecision()}setQuadrantSegments(t){this._bufParams.setQuadrantSegments(t)}bufferOriginalPrecision(){try{const t=new Fa(this._bufParams);this._resultGeometry=t.buffer(this._argGeom,this._distance)}catch(t){if(t instanceof ui)this._saveException=t;else throw t}finally{}}getResultGeometry(t){return this._distance=t,this.computeGeometry(),this._resultGeometry}setEndCapStyle(t){this._bufParams.setEndCapStyle(t)}}_n.CAP_ROUND=ie.CAP_ROUND;_n.CAP_BUTT=ie.CAP_FLAT;_n.CAP_FLAT=ie.CAP_FLAT;_n.CAP_SQUARE=ie.CAP_SQUARE;_n.MAX_PRECISION_DIGITS=12;const ur=1e-9,$w=10;function Zi(i,t){return[i[0]-t[0],i[1]-t[1]]}function vr(i){return Math.hypot(i[0],i[1])}function $a(i){const t=vr(i);return t<ur?[0,0]:[i[0]/t,i[1]/t]}function KA(i,t,e,n){const s=t[0]*n[1]-t[1]*n[0];if(Math.abs(s)<ur)return null;const r=((e[0]-i[0])*n[1]-(e[1]-i[1])*n[0])/s;return[i[0]+r*t[0],i[1]+r*t[1]]}function E_(i){return i.filter((t,e)=>e===0||vr(Zi(t,i[e-1]))>ur)}function ZA(i,t,e=$w){const n=E_(i);if(n.length<2)return n;const s=[];for(let o=0;o<n.length-1;o++){const a=$a(Zi(n[o+1],n[o])),l=[a[1],-a[0]],h=[l[0]*t,l[1]*t];s.push({dir:a,start:[n[o][0]+h[0],n[o][1]+h[1]],end:[n[o+1][0]+h[0],n[o+1][1]+h[1]]})}const r=[s[0].start];for(let o=0;o<s.length-1;o++){const a=s[o],l=s[o+1],h=KA(a.start,a.dir,l.start,l.dir);h?vr(Zi(h,n[o+1]))>Math.abs(t)*e?r.push(a.end,l.start):r.push(h):r.push(a.end)}return r.push(s[s.length-1].end),E_(r)}function Dw(i,t,e=$w){const n=new Vf,s=new Iw,r=new ie;r.setJoinStyle(ie.JOIN_MITRE),r.setMitreLimit(e);const o=_n.bufferOp(n.read(i),t,r);if(!o||o.isEmpty())return null;const a=s.write(o);return a.type!=="Polygon"&&a.type!=="MultiPolygon"?null:a}function Gw(i,t,e,n,s=5){const r=Zi(i,t),o=Zi(e,t),a=vr(r),l=vr(o);if(n<=0||a<ur||l<ur)return null;const h=$a(r),f=$a(o),d=Math.max(-1,Math.min(1,h[0]*f[0]+h[1]*f[1])),p=Math.acos(d);if(p<1e-6||Math.PI-p<1e-6)return null;const y=n/Math.tan(p/2);if(y>a+ur||y>l+ur)return null;const _=[t[0]+h[0]*y,t[1]+h[1]*y],E=[t[0]+f[0]*y,t[1]+f[1]*y],w=$a([h[0]+f[0],h[1]+f[1]]),L=n/Math.sin(p/2),b=[t[0]+w[0]*L,t[1]+w[1]*L],P=Math.atan2(_[1]-b[1],_[0]-b[0]);let S=Math.atan2(E[1]-b[1],E[0]-b[0])-P;for(;S>Math.PI;)S-=2*Math.PI;for(;S<-Math.PI;)S+=2*Math.PI;const C=Math.max(2,Math.ceil(Math.abs(S)/(s*Math.PI/180))),T=[_];for(let I=1;I<C;I++){const M=P+S*I/C;T.push([b[0]+n*Math.cos(M),b[1]+n*Math.sin(M)])}return T.push(E),{tangentStart:_,tangentEnd:E,center:b,points:T}}function JA(i,t,e){const n=vr(Zi(i,t)),s=vr(Zi(e,t)),r=$a(Zi(i,t)),o=$a(Zi(e,t)),a=Math.acos(Math.max(-1,Math.min(1,r[0]*o[0]+r[1]*o[1])));return a<1e-6||Math.PI-a<1e-6?0:Math.min(n,s)*Math.tan(a/2)}function QA(i,t,e){const n=-e*Math.PI/180,s=Math.cos(n),r=Math.sin(n),o=i[0]-t[0],a=i[1]-t[1];return[t[0]+o*s-a*r,t[1]+o*r+a*s]}function t4(i,t,e){return[t[0]+(i[0]-t[0])*e,t[1]+(i[1]-t[1])*e]}function e4(i,t,e){const n=Zi(e,t),s=vr(n);return s<ur?vr(Zi(i,t)):Math.abs(n[0]*(t[1]-i[1])-n[1]*(t[0]-i[0]))/s}function n4(i,t,e){const n=Zi(e,t),s=n[0]*n[0]+n[1]*n[1];return s<ur?0:((i[0]-t[0])*n[0]+(i[1]-t[1])*n[1])/s}const rm=.001;function Wl(i,t,e){const n=Ye(i);return Mn(n,s=>{const r=t.toGeographic(e(t.toPlanar(s)));s[0]=r[0],s[1]=r[1]}),n}class ue{static extendRayOutside(t,e,n){const s=De(n),r=s[2]-s[0],o=s[3]-s[1],a=Math.max(Math.hypot(r,o),.001),l=e[0]-t[0],h=e[1]-t[1],f=Math.hypot(l,h);if(f<1e-12)return e;const d=l/f,p=h/f;return[e[0]+1.5*a*d,e[1]+1.5*a*p]}static prepareCuttingLine(t,e){const n=t.geometry.coordinates;if(n.length<2)return null;let s=n[0];Ht(St(s),e)&&(s=this.extendRayOutside(n[1],s,e));let r=n[n.length-1];return Ht(St(r),e)&&(r=this.extendRayOutside(n[n.length-2],r,e)),re([s,...n.slice(1,-1),r],t.properties)}static splitSinglePolygonByLine(t,e){try{const n=Ka(t);if(n){const s=Bo(e,n);if(s.features.length>=2){const r=[];for(const o of s.features){const a=o.geometry.coordinates;r.some(h=>{const f=h.geometry.coordinates;return Math.hypot(a[0]-f[0],a[1]-f[1])<1e-7})||r.push(o)}if(r.length>=2){let o=sh(n).features;for(const h of r){const f=[];for(const d of o){const p=au(d,h);p&&p.features.length>0?f.push(...p.features):f.push(d)}o=f}let a=[e];for(const h of r){const f=[];for(const d of a){const p=au(d,h);p&&p.features.length>0?f.push(...p.features):f.push(d)}a=f}const l=a.filter(h=>{const f=h.geometry.coordinates;if(f.length<2)return!1;const d=ZP(h,el(h)/2),p=tA(St(f[0]),St(f[f.length-1]));return Ht(d,t)||Ht(p,t)});if(l.length>0){const h=[...o,...l].filter(p=>el(p,{units:"meters"})>=1e-4),f=ae(h),d=pA(f);if(d.features.length>=2){const p=d.features.filter(y=>{Ta(y);const _=aA(y);return(Ht(_,t)||Ht(Io(y),t))&&Tu(y)>.01});if(p.length>=2)return p}}}}}}catch{}try{const n=ZE(e,5e-5,{units:"meters"});if(!n)return null;const s=ba(ae([t,n]));if(!s)return null;const r=sh(s);return r.features.length<=1?null:r.features.map(o=>(Ta(o),o))}catch{return null}}static splitPolygonByLine(t,e){try{const n=this.prepareCuttingLine(e,t);if(!n)return null;let s=[];t.geometry.type==="MultiPolygon"?s=sh(t).features:s=[t];const r=[];for(const o of s){const a=this.splitSinglePolygonByLine(o,n);a&&a.length>1?r.push(...a):r.push(o)}return r.length<=s.length?null:r.map(o=>this.cleanCollinearVertices(o))}catch(n){return console.error("splitPolygonByLine error:",n),null}}static connectLines(t,e=5,n=!0){if(t.length===0)return null;if(t.length===1)return t[0];const s=[...t],r=s.shift();let o=[...r.geometry.coordinates];for(;s.length>0;){const l=o[0],h=o[o.length-1];let f=-1,d=!1,p=!1;for(let E=0;E<s.length;E++){const w=s[E].geometry.coordinates,L=w[0],b=w[w.length-1];if(nn(St(h),St(L),{units:"meters"})<=e){f=E,d=!1,p=!1;break}if(nn(St(h),St(b),{units:"meters"})<=e){f=E,d=!0,p=!1;break}}if(f===-1)for(let E=0;E<s.length;E++){const w=s[E].geometry.coordinates,L=w[0],b=w[w.length-1];if(nn(St(b),St(l),{units:"meters"})<=e){f=E,d=!1,p=!0;break}if(nn(St(L),St(l),{units:"meters"})<=e){f=E,d=!0,p=!0;break}}if(f===-1)break;let _=[...s.splice(f,1)[0].geometry.coordinates];if(d&&_.reverse(),p){const E=_[_.length-1];nn(St(E),St(l),{units:"meters"})<=e&&_.pop(),o=[..._,...o]}else{const E=_[0];nn(St(h),St(E),{units:"meters"})<=e&&_.shift(),o=[...o,..._]}}return re(o,r.properties)}static smoothLineBezier(t,e=32){const n=t.geometry.coordinates;if(n.length<3)return t;const s=Yv(n,e);return re(s,t.properties)}static extendLine(t,e=.05){const n=t.geometry.coordinates;if(n.length<2)return t;const s=n[0],r=n[n.length-1],o=Wa(St(n[n.length-2]),St(r)),a=Wa(St(n[1]),St(s)),l=ku(St(s),e,a).geometry.coordinates,h=ku(St(r),e,o).geometry.coordinates;return re([l,...n,h])}static offset(t,e){if(!Number.isFinite(e)||e===0)return null;const n=we.forGeometries([t.geometry]);if(t.geometry.type==="LineString"){const s=t.geometry.coordinates.map(o=>n.toPlanar(o)),r=ZA(s,e);return r.length<2?null:re(r.map(o=>n.toGeographic(o)),t.properties)}if(t.geometry.type==="Polygon"){const s=Dw(n.projectGeometry(t.geometry),e);return s?vn(n.unprojectGeometry(s),t.properties):null}return null}static rotate(t,e,n){const s=n||Io(t).geometry.coordinates,r=we.forCoordinate(s),o=r.toPlanar(s);return Wl(t,r,a=>QA(a,o,e))}static scale(t,e,n){const s=n||Io(t).geometry.coordinates,r=we.forCoordinate(s),o=r.toPlanar(s);return Wl(t,r,a=>t4(a,o,e))}static explode(t){const e=[];return t.geometry.type==="Polygon"?t.geometry.coordinates.forEach((n,s)=>{var r;e.push(re(n,{...t.properties,ringIndex:s,name:`${((r=t.properties)==null?void 0:r.name)||"Polygon"} Ring ${s+1}`}))}):t.geometry.type==="MultiPolygon"&&t.geometry.coordinates.forEach((n,s)=>{n.forEach((r,o)=>{var a;e.push(re(r,{...t.properties,polygonIndex:s,ringIndex:o,name:`${((a=t.properties)==null?void 0:a.name)||"Polygon"} ${s+1}.${o+1}`}))})}),e}static fillet(t,e,n=5){const s=this.getFilletCorner(t,e);if(!s)return null;const{coords:r,prev:o,curr:a,next:l,isPolygon:h,projection:f}=s,d=Gw(f.toPlanar(o),f.toPlanar(a),f.toPlanar(l),n);if(!d)return null;const p=d.points.map(_=>f.toGeographic(_));if(h){const _=r.slice(0,-1);_.splice(e,1,...p),_.push(_[0]);const E=t.geometry.coordinates.slice(1);return Ce([_,...E],t.properties)}const y=[...r];return y.splice(e,1,...p),re(y,t.properties)}static maxFilletRadius(t,e){const n=this.getFilletCorner(t,e);if(!n)return 0;const{prev:s,curr:r,next:o,projection:a}=n;return JA(a.toPlanar(s),a.toPlanar(r),a.toPlanar(o))}static getFilletCorner(t,e){const n=t.geometry.type==="Polygon";if(!n&&t.geometry.type!=="LineString")return null;const s=n?[...t.geometry.coordinates[0]]:[...t.geometry.coordinates],r=n?s.length-1:s.length;if(r<3||!Number.isInteger(e)||(n?e<0||e>=r:e<1||e>r-2))return null;const o=s[n?(e-1+r)%r:e-1],a=s[e],l=s[n?(e+1)%r:e+1],h=we.forCoordinate(a);return{coords:s,prev:o,curr:a,next:l,isPolygon:n,projection:h}}static translate(t,e,n){const s=n*Math.PI/180;return this.translateByMeters(t,e*Math.sin(s),e*Math.cos(s))}static translateByMeters(t,e,n){const s=we.forGeometries([t.geometry]);return Wl(t,s,r=>[r[0]+e,r[1]+n])}static translateByVector(t,e,n){const s=we.forCoordinate(e),r=we.forCoordinate(n),o=s.toPlanar(e),a=r.toPlanar(n),l=Ye(t);return Mn(l,h=>{const f=s.toPlanar(h),d=r.toGeographic([a[0]+(f[0]-o[0]),a[1]+(f[1]-o[1])]);h[0]=d[0],h[1]=d[1]}),l}static align(t,e,n,s,r,o=!1){const a=we.forCoordinate(n),l=a.toPlanar(e),h=a.toPlanar(n);let f=0,d=1;if(s&&r){const _=a.toPlanar(s),E=a.toPlanar(r),w=Math.hypot(_[0]-l[0],_[1]-l[1]),L=Math.hypot(E[0]-h[0],E[1]-h[1]);if(w<1e-9||L<1e-9)throw new Error("Alignment points must be different.");f=Math.atan2(E[1]-h[1],E[0]-h[0])-Math.atan2(_[1]-l[1],_[0]-l[0]),o&&(d=L/w)}const p=Math.cos(f)*d,y=Math.sin(f)*d;return Wl(t,a,_=>{const E=_[0]-l[0],w=_[1]-l[1];return[h[0]+E*p-w*y,h[1]+E*y+w*p]})}static mirror(t,e,n){const s=we.forCoordinate(e),r=s.toPlanar(e),o=s.toPlanar(n),a=o[0]-r[0],l=o[1]-r[1],h=a*a+l*l;if(h<1e-12)throw new Error("Mirror line needs two different points");const f=Wl(t,s,y=>{const _=((y[0]-r[0])*a+(y[1]-r[1])*l)/h,E=r[0]+_*a,w=r[1]+_*l;return[2*E-y[0],2*w-y[1]]}),d=y=>y.forEach(_=>_.reverse()),p=f.geometry;return p.type==="Polygon"&&d(p.coordinates),p.type==="MultiPolygon"&&p.coordinates.forEach(d),f}static translateByOffset(t,e,n){const s=Ye(t);return Mn(s,r=>{r[0]+=e,r[1]+=n}),s}static difference(t,e){try{return ba(ae([t,e]))}catch(n){return console.error("CADOperations.difference error:",n),null}}static intersect(t,e){try{return of(ae([t,e]))}catch(n){return console.error("CADOperations.intersect error:",n),null}}static simplify(t,e=1e-4){return wA(t,{tolerance:e,highQuality:!0,mutate:!1})}static reverse(t){const e=Ye(t);return e.geometry.type==="LineString"?e.geometry.coordinates.reverse():e.geometry.type==="Polygon"&&e.geometry.coordinates.forEach(s=>{const r=s.slice(0,-1).reverse();r.push(r[0]);for(let o=0;o<s.length;o++)s[o]=r[o]}),e}static cloneFeature(t,e){const n=Ye(t);return e!==void 0&&(n.id=e),n}static snapVertices(t,e=rm){if(t.length<2||!(e>0))return t.map(o=>Ye(o));const n=we.forGeometries(t.map(o=>o.geometry)),s=(o,a)=>`${Math.floor(o/e)}:${Math.floor(a/e)}`,r=new Map;return t.map(o=>{const a=Ye(o),l=[];return Mn(a,h=>{const f=n.toPlanar(h),d=Math.floor(f[0]/e),p=Math.floor(f[1]/e);let y=null,_=e;for(let E=-1;E<=1;E++)for(let w=-1;w<=1;w++)for(const L of r.get(`${d+E}:${p+w}`)||[]){const b=Math.hypot(L.planar[0]-f[0],L.planar[1]-f[1]);b<=_&&(_=b,y=L.coord)}y?(h[0]=y[0],h[1]=y[1]):l.push({planar:f,coord:[h[0],h[1]]})}),l.forEach(h=>{const f=s(h.planar[0],h.planar[1]),d=r.get(f);d?d.push(h):r.set(f,[h])}),a})}static cleanCollinearVertices(t,e=rm){const n=Ye(t),s=we.forGeometries([t.geometry]),r=o=>{if(o.length<=4)return o;const a=o.slice(0,-1).map(f=>({coord:f,planar:s.toPlanar(f)}));let l=!0;for(;l&&a.length>3;){l=!1;for(let f=0;f<a.length&&a.length>3;f++){const d=a[(f-1+a.length)%a.length].planar,p=a[f].planar,y=a[(f+1)%a.length].planar,_=n4(p,d,y);_>0&&_<1&&e4(p,d,y)<=e&&(a.splice(f,1),f--,l=!0)}}const h=a.map(f=>f.coord);return h.push(h[0]),h};if(n.geometry.type==="Polygon"){const o=n.geometry.coordinates;n.geometry.coordinates=o.map(r)}else if(n.geometry.type==="MultiPolygon"){const o=n.geometry.coordinates;n.geometry.coordinates=o.map(a=>a.map(r))}return n}static splitOverlappingPolygons(t,e){try{if(!To(t,e))return null;const s=of(ae([t,e]));if(!s)return null;const r=ba(ae([t,e])),o=ba(ae([e,t])),a=d=>{if(!d)return[];const p=sh(d),y=[];for(const _ of p.features)Ta(_),_.geometry&&_.geometry.type==="Polygon"&&y.push(_);return y},l=a(r),h=a(s),f=a(o);return{pieceA:l,overlap:h,pieceB:f}}catch(n){return console.error("splitOverlappingPolygons error:",n),null}}static splitLine(t,e){try{let n;if(Array.isArray(e)?n=St(e):n=e,n.geometry.type==="Point"){const s=kE(t,n),r=t.geometry.coordinates,o=r[0],a=r[r.length-1],l=nn(St(o),s,{units:"meters"}),h=nn(St(a),s,{units:"meters"});if(l<.5||h<.5)return null;const f=au(t,s);if(f&&f.features.length>1)return f.features}else if(n.geometry.type==="LineString"){const s=au(t,n);if(s&&s.features.length>1)return s.features}return null}catch(n){return console.error("splitLine error:",n),null}}}class Bw extends jr{constructor(){super();Y(this,"layers",new Map);Y(this,"groups",new Map);Y(this,"activeLayerId",null);Y(this,"selectionStore",new Map);Y(this,"transactions",new mw(50));Y(this,"pendingChangedLayers",null)}emit(e,n){if(e==="features:changed"&&this.pendingChangedLayers){this.pendingChangedLayers.add(n.layerId);return}super.emit(e,n)}runTransaction(e,n){return this.withCoalescedEvents(()=>{this.transactions.beginGroup(e);try{const s=n();return this.transactions.commitGroup(),s}catch(s){throw this.transactions.rollbackGroup(),s}})}withCoalescedEvents(e){const n=this.pendingChangedLayers===null;n&&(this.pendingChangedLayers=new Set);try{return e()}finally{if(n){const s=this.pendingChangedLayers;this.pendingChangedLayers=null,s.forEach(r=>this.emit("features:changed",{layerId:r}))}}}addLayer(e,n=[]){this.layers.has(e.id)&&(console.warn(`Layer with id "${e.id}" already exists. Replacing it.`),this.removeLayer(e.id));const s=new Yf(e,n);return this.layers.set(s.id,s),this.activeLayerId===null&&this.setActiveLayer(s.id),this.emit("layer:added",{layer:s}),s}removeLayer(e){const n=this.layers.get(e);if(!n)return!1;if(n.pinned)return console.warn(`Layer "${e}" is pinned and cannot be removed.`),!1;if(this.layers.delete(e),this.selectionStore.delete(e),this.activeLayerId===e){const s=Array.from(this.layers.keys());this.setActiveLayer(s.length>0?s[0]:null)}return this.emit("layer:removed",{layerId:e}),!0}getLayer(e){return this.layers.get(e)}hasLayer(e){return this.layers.has(e)}getAllLayers(){return Array.from(this.layers.values()).sort((e,n)=>e.zIndex-n.zIndex)}setLayerVisibility(e,n){const s=this.getLayerOrThrow(e);s.visible!==n&&(s.visible=n,this.emit("layer:updated",{layer:s}))}setLayerOpacity(e,n){const s=this.getLayerOrThrow(e),r=Math.max(0,Math.min(1,n));s.opacity!==r&&(s.opacity=r,this.emit("layer:updated",{layer:s}))}setLayerZIndex(e,n){const s=this.getLayerOrThrow(e);s.zIndex!==n&&(s.zIndex=n,this.emit("layer:updated",{layer:s}))}reorderLayers(e){e.forEach((n,s)=>{const r=this.layers.get(n);r&&(r.zIndex=s)}),this.getAllLayers().forEach(n=>{this.emit("layer:updated",{layer:n})})}setLayerPinned(e,n){const s=this.getLayerOrThrow(e);s.pinned!==n&&(s.pinned=n,this.emit("layer:updated",{layer:s}))}addLayerGroup(e){if(this.groups.has(e.id))throw new Error(`Layer group "${e.id}" already exists`);const n=e.parentId??null;if(n!==null&&!this.groups.has(n))throw new Error(`Layer group "${n}" not found`);const s={id:e.id,name:e.name??e.id,parentId:n,visible:e.visible??!0,expanded:e.expanded??!0};return this.groups.set(s.id,s),this.emit("group:added",{group:s}),s}getLayerGroup(e){return this.groups.get(e)}getLayerGroups(){return Array.from(this.groups.values())}removeLayerGroup(e){const n=this.groups.get(e);n&&(this.layers.forEach(s=>{s.groupId===e&&(s.groupId=n.parentId??void 0)}),this.groups.forEach(s=>{s.parentId===e&&(s.parentId=n.parentId)}),this.groups.delete(e),this.emit("group:removed",{groupId:e}),this.getAllLayers().forEach(s=>this.emit("layer:updated",{layer:s})))}updateLayerGroup(e,n){var o;const s=this.groups.get(e);if(!s)throw new Error(`Layer group "${e}" not found`);if(n.parentId!==void 0&&n.parentId!==null){if(!this.groups.has(n.parentId))throw new Error(`Layer group "${n.parentId}" not found`);for(let a=n.parentId;a;a=((o=this.groups.get(a))==null?void 0:o.parentId)??null)if(a===e)throw new Error(`Layer group "${e}" cannot be moved into itself`)}const r=n.visible!==void 0&&n.visible!==s.visible;Object.assign(s,Object.fromEntries(Object.entries(n).filter(([,a])=>a!==void 0))),this.emit("group:updated",{group:s}),(r||n.parentId!==void 0)&&this.getAllLayers().filter(a=>this.isLayerInGroup(a.id,e)).forEach(a=>this.emit("layer:updated",{layer:a}))}setLayerGroupVisibility(e,n){this.updateLayerGroup(e,{visible:n})}moveLayerToGroup(e,n){const s=this.getLayerOrThrow(e);if(n!==null&&!this.groups.has(n))throw new Error(`Layer group "${n}" not found`);const r=n??void 0;s.groupId!==r&&(s.groupId=r,this.emit("layer:updated",{layer:s}))}isLayerInGroup(e,n){var r,o;let s=((r=this.layers.get(e))==null?void 0:r.groupId)??null;for(;s;){if(s===n)return!0;s=((o=this.groups.get(s))==null?void 0:o.parentId)??null}return!1}isLayerRendered(e){const n=this.layers.get(e);if(!n||!n.visible)return!1;let s=n.groupId??null;for(;s;){const r=this.groups.get(s);if(!r)break;if(!r.visible)return!1;s=r.parentId}return!0}setActiveLayer(e){if(e!==null&&!this.layers.has(e))throw new Fg(e);this.activeLayerId!==e&&(this.activeLayerId=e,this.emit("active-layer:changed",{layerId:e}))}getActiveLayerId(){return this.activeLayerId}getActiveLayer(){return this.activeLayerId&&this.layers.get(this.activeLayerId)||null}selectFeature(e,n,s=!1){this.selectionStore.has(e)||this.selectionStore.set(e,new Set);const r=this.selectionStore.get(e);if(!s){for(const[o,a]of this.selectionStore.entries())o!==e&&a.size>0&&(a.clear(),this.emit("selection:changed",{layerId:o,featureIds:[]}));r.clear()}r.add(n),this.emit("selection:changed",{layerId:e,featureIds:Array.from(r)})}deselectFeature(e,n){const s=this.selectionStore.get(e);s&&s.delete(n)&&this.emit("selection:changed",{layerId:e,featureIds:Array.from(s)})}toggleFeatureSelection(e,n){const s=this.selectionStore.get(e);return s&&s.has(n)?(this.deselectFeature(e,n),!1):(this.selectFeature(e,n,!0),!0)}selectFeatures(e,n,s=!1){this.selectionStore.has(e)||this.selectionStore.set(e,new Set);const r=this.selectionStore.get(e);if(!s){for(const[o,a]of this.selectionStore.entries())o!==e&&a.size>0&&(a.clear(),this.emit("selection:changed",{layerId:o,featureIds:[]}));r.clear()}n.forEach(o=>r.add(o)),this.emit("selection:changed",{layerId:e,featureIds:Array.from(r)})}getSelectedCount(){let e=0;for(const n of this.selectionStore.values())e+=n.size;return e}clearSelection(e){if(e){const n=this.selectionStore.get(e);n&&n.size>0&&(n.clear(),this.emit("selection:changed",{layerId:e,featureIds:[]}))}else for(const[n,s]of this.selectionStore.entries())s.size>0&&(s.clear(),this.emit("selection:changed",{layerId:n,featureIds:[]}))}deselectAll(e){this.clearSelection(e)}getSelectedFeatureIds(e){return Array.from(this.selectionStore.get(e)||[])}getSelectedFeatures(e){const n=this.layers.get(e);if(!n)return[];const s=this.selectionStore.get(e);return!s||s.size===0?[]:Array.from(s).map(r=>n.getFeature(r)).filter(r=>!!r)}getAnySelectedFeature(){if(this.activeLayerId){const e=this.getSelectedFeatureIds(this.activeLayerId);if(e.length>0)return{layerId:this.activeLayerId,featureId:e[0]}}for(const[e,n]of this.selectionStore.entries())if(n.size>0){const s=n.values().next().value;if(s!==void 0)return{layerId:e,featureId:s}}return null}getAnySelectedFeatures(){if(this.activeLayerId){const e=this.getSelectedFeatureIds(this.activeLayerId);if(e.length>0)return{layerId:this.activeLayerId,featureIds:e}}for(const[e,n]of this.selectionStore.entries())if(n.size>0)return{layerId:e,featureIds:Array.from(n)};return null}addFeature(e,n,s=!0){const r=this.getLayerOrThrow(e),o=r.addFeature(n);if(s&&o.id!==void 0){const a=o.id;this.transactions.record({description:`Add feature to ${r.name}`,undo:()=>{this.removeFeature(e,a,!1)},redo:()=>{this.addFeature(e,o,!1)}})}return this.emit("feature:added",{layerId:e,feature:o}),this.emit("features:changed",{layerId:e}),o}addFeatures(e,n,s=!0){const r=this.getLayerOrThrow(e),o=r.addFeatures(n);if(s){const a=o.map(l=>l.id).filter(l=>l!==void 0);this.transactions.record({description:`Add ${o.length} features to ${r.name}`,undo:()=>{a.forEach(l=>r.removeFeature(l)),this.emit("features:changed",{layerId:e})},redo:()=>{r.addFeatures(o),this.emit("features:changed",{layerId:e})}})}return o.forEach(a=>this.emit("feature:added",{layerId:e,feature:a})),this.emit("features:changed",{layerId:e}),o}updateFeature(e,n,s=!0){const r=this.getLayerOrThrow(e);if(n.id===void 0||n.id===null)return!1;const o=r.getFeature(n.id);if(!o)return!1;const a=Ye(o),l=r.updateFeature(n);return l&&(s&&this.transactions.record({description:`Update feature ${n.id} in ${r.name}`,undo:()=>{this.updateFeature(e,a,!1)},redo:()=>{this.updateFeature(e,n,!1)}}),this.emit("feature:updated",{layerId:e,feature:n}),this.emit("features:changed",{layerId:e})),l}updateFeatureProperties(e,n,s,r=!0){const o=this.getLayerOrThrow(e),a=this.propertiesBefore(o,n,s);if(!a)return!1;const l=o.updateProperties(n,s);return l?(r&&this.transactions.record({description:`Edit attributes of feature ${n} in ${o.name}`,undo:()=>{this.updateFeatureProperties(e,n,a,!1)},redo:()=>{this.updateFeatureProperties(e,n,s,!1)}}),this.emit("feature:updated",{layerId:e,feature:l}),this.emit("features:changed",{layerId:e}),!0):!1}updateFeaturePropertiesBatch(e,n,s=!0,r){const o=this.getLayerOrThrow(e),a=[],l=[];return this.withCoalescedEvents(()=>{for(const{featureId:h,patch:f}of n){const d=this.propertiesBefore(o,h,f);d&&o.updateProperties(h,f)&&(a.push({featureId:h,patch:d}),l.push({featureId:h,patch:f}),this.emit("feature:updated",{layerId:e,feature:o.getFeature(h)}))}l.length&&this.emit("features:changed",{layerId:e})}),s&&l.length&&this.transactions.record({description:r??`Edit attributes of ${l.length} features in ${o.name}`,undo:()=>{this.updateFeaturePropertiesBatch(e,a,!1)},redo:()=>{this.updateFeaturePropertiesBatch(e,l,!1)}}),l.length}propertiesBefore(e,n,s){const r=e.getFeature(n);if(!r)return null;const o={};let a=!1;for(const[l,h]of Object.entries(s)){const f=!!r.properties&&Object.prototype.hasOwnProperty.call(r.properties,l),d=f?r.properties[l]:void 0;f&&d===h||!f&&h===void 0||(o[l]=d,a=!0)}return a?o:null}removeFeature(e,n,s=!0){const r=this.getLayerOrThrow(e),o=r.getFeature(n);if(!o)return!1;const a=Ye(o),l=r.removeFeature(n);return l&&(this.deselectFeature(e,n),s&&this.transactions.record({description:`Delete feature ${n} from ${r.name}`,undo:()=>{this.addFeature(e,a,!1)},redo:()=>{this.removeFeature(e,n,!1)}}),this.emit("feature:removed",{layerId:e,featureId:n}),this.emit("features:changed",{layerId:e})),l}getAvailableFeatureId(e,n){return this.getLayerOrThrow(e).getAvailableId(n)}getFeature(e,n){var s;return(s=this.layers.get(e))==null?void 0:s.getFeature(n)}buffer(e,n,s,r="meters",o){const a=this.getLayerOrThrow(e),l=a.getFeature(n);if(!l)throw new $g(n,e);const h=ZE(l,s,{units:r});h.properties={...l.properties,_bufferDistance:s,_bufferUnit:r};let f=o;if(!f)if(a.type==="polygon")f=e;else{const d=this.getAllLayers().find(p=>p.type==="polygon");f=d?d.id:e}return this.addFeature(f,h),h}calculateArea(e,n,s="sqm"){const r=this.getFeatureOrThrow(e,n),o=Tu(r);return s==="hectares"?o/1e4:s==="rai"?o/1600:o}calculateLength(e,n,s="meters"){const r=this.getFeatureOrThrow(e,n);return el(r,{units:s})}union(e,n,s={}){const r=this.getLayerOrThrow(e),o=n.map(f=>r.getFeature(f)).filter(f=>!!(f&&(f.geometry.type==="Polygon"||f.geometry.type==="MultiPolygon")));if(o.length<2)throw new yh("Union requires at least 2 polygon features");const a=ue.snapVertices(o,s.snapToleranceMeters),l=gw(ae(a));if(!l)throw new yh("Union produced an empty geometry");const h=ue.cleanCollinearVertices(l);return h.properties={...o[0].properties||{}},delete h.id,this.runTransaction(`Union ${o.length} polygons in ${r.name}`,()=>{o.forEach(d=>this.removeFeature(e,d.id));const f=this.addFeature(e,h);return f.id!==void 0&&this.selectFeature(e,f.id,!1),f})}splitOverlapping(e,n,s){const r=this.getLayerOrThrow(e),o=r.getFeature(n),a=r.getFeature(s);if(!o||!a)return null;const l=ue.splitOverlappingPolygons(o,a);return l?(this.runTransaction(`Split overlapping polygons ${n} and ${s} in ${r.name}`,()=>{this.removeFeature(e,n),this.removeFeature(e,s),l.pieceA.forEach((h,f)=>{h.id=this.getAvailableFeatureId(e,`${n}_part_${f+1}`),h.properties={...o.properties||{},_split:"A_minus_B"},this.addFeature(e,h)}),l.overlap.forEach((h,f)=>{var d,p;h.id=this.getAvailableFeatureId(e,`overlap_${n}_${s}_${f+1}`),h.properties={name:`Overlap (${((d=o.properties)==null?void 0:d.name)||n} & ${((p=a.properties)==null?void 0:p.name)||s})`,_split:"overlap"},this.addFeature(e,h)}),l.pieceB.forEach((h,f)=>{h.id=this.getAvailableFeatureId(e,`${s}_part_${f+1}`),h.properties={...a.properties||{},_split:"B_minus_A"},this.addFeature(e,h)})}),l):null}difference(e,n,s){const r=this.getLayerOrThrow(e),o=r.getFeature(n),a=r.getFeature(s);if(!o||!a)throw new yh("Base and cut polygon features required");const l=ba(ae([o,a]));return l&&(l.id=n,l.properties={...o.properties},this.updateFeature(e,l)),l}getBoundingBox(e){if(e)return this.getLayerOrThrow(e).getBoundingBox();const n=this.getAllLayers();if(n.length===0)return[0,0,0,0];const s={type:"FeatureCollection",features:n.flatMap(r=>r.getFeatures())};return s.features.length===0?[0,0,0,0]:De(s)}undo(){const e=this.withCoalescedEvents(()=>this.transactions.undo());return e&&this.emit("transaction:undo",{description:e}),e}redo(){const e=this.withCoalescedEvents(()=>this.transactions.redo());return e&&this.emit("transaction:redo",{description:e}),e}canUndo(){return this.transactions.canUndo()}canRedo(){return this.transactions.canRedo()}getLayerOrThrow(e){const n=this.layers.get(e);if(!n)throw new Fg(e);return n}getFeatureOrThrow(e,n){const r=this.getLayerOrThrow(e).getFeature(n);if(!r)throw new $g(n,e);return r}}const i4=["vertex","intersection","midpoint","center","perpendicular","edge"];class zu{constructor(t,e){Y(this,"dataSource");Y(this,"mapAdapter");Y(this,"enabled",!0);Y(this,"tolerancePixels",18);Y(this,"modes",{vertex:!0,intersection:!0,midpoint:!0,center:!0,perpendicular:!0,edge:!0});this.dataSource=t,this.mapAdapter=e}setModes(t){this.modes={...this.modes,...t}}toggleMode(t){return this.modes[t]=!this.modes[t],this.modes[t]}getSnap(t,e=[],n){var E;if(!this.enabled||!this.mapAdapter.isReady)return null;let s;try{s=this.mapAdapter.getRawMap()}catch{return null}if(!t||!Array.isArray(t)||t.length<2||!s||typeof s.project!="function")return null;const r=s.project([t[0],t[1]]),o=this.tolerancePixels,a=new Map,l=(w,L,b,P)=>{if(!this.modes[w])return;const N=b||s.project([L[0],L[1]]),S=Math.hypot(N.x-r.x,N.y-r.y),C=a.get(w);S<=o&&(!C||S<C.distPx)&&a.set(w,{coord:L,distPx:S,segment:P})},h=[],f=(n==null?void 0:n.fromPoint)??null,d=(w,L)=>{if(!w||!L||w.length<2||L.length<2)return;const b=s.project([w[0],w[1]]),P=s.project([L[0],L[1]]),N=P.x-b.x,S=P.y-b.y,C=N*N+S*S;if(C<1)return;l("midpoint",[(w[0]+L[0])/2,(w[1]+L[1])/2],{x:(b.x+P.x)/2,y:(b.y+P.y)/2});const T=((r.x-b.x)*N+(r.y-b.y)*S)/C,I=Math.max(0,Math.min(1,T));if(Math.hypot(r.x-(b.x+I*N),r.y-(b.y+I*S))<=o&&h.push({a:w,b:L}),this.modes.edge&&T>=.08&&T<=.92&&l("edge",[w[0]+T*(L[0]-w[0]),w[1]+T*(L[1]-w[1])],{x:b.x+T*N,y:b.y+T*S},{a:w,b:L}),this.modes.perpendicular&&f){const R=zu.perpendicularFoot(f,w,L);R&&l("perpendicular",R,void 0,{a:w,b:L})}},p=w=>{for(let L=0;L<w.length-1;L++)d(w[L],w[L+1])};Array.isArray(e)&&e.length>0&&(e.forEach(w=>w&&l("vertex",w)),p(e));const y=this.dataSource.getAllLayers().filter(w=>w.visible),_=this.getSearchBBox(s,r);for(const w of y){const L=_?w.queryBBox(_):w.getFeatures();for(const b of L){if(!b.geometry)continue;const P=n==null?void 0:n.excludeFeatureId;if(P!=null&&b.id===P)continue;tk(b).forEach(S=>l("vertex",S));const N=b.geometry;if(N.type==="LineString"?p(N.coordinates):N.type==="MultiLineString"||N.type==="Polygon"?N.coordinates.forEach(p):N.type==="MultiPolygon"&&N.coordinates.forEach(S=>S.forEach(p)),this.modes.center&&((E=b.properties)==null?void 0:E.shape)==="circle"&&N.type==="Polygon"){const S=N.coordinates[0].slice(0,-1),C=S.reduce((I,M)=>I+M[0],0)/S.length,T=S.reduce((I,M)=>I+M[1],0)/S.length;l("center",[C,T])}}}if(this.modes.intersection&&h.length>=2)for(let w=0;w<h.length;w++)for(let L=w+1;L<h.length;L++){const b=zu.segmentIntersection(h[w],h[L]);b&&l("intersection",b)}for(const w of i4){const L=a.get(w);if(L)return{coordinate:L.coord,type:w,distanceMeters:_o(t,L.coord),segment:L.segment}}return null}static segmentIntersection(t,e){const[n,s]=t.a,[r,o]=t.b,[a,l]=e.a,[h,f]=e.b,d=(r-n)*(f-l)-(o-s)*(h-a);if(Math.abs(d)<1e-18)return null;const p=((a-n)*(f-l)-(l-s)*(h-a))/d,y=((a-n)*(o-s)-(l-s)*(r-n))/d,_=1e-9;return p<=_||p>=1-_||y<=_||y>=1-_?null:[n+p*(r-n),s+p*(o-s)]}static perpendicularFoot(t,e,n){const s=Math.cos(t[1]*Math.PI/180),r=e[0]*s,o=n[0]*s,a=t[0]*s,l=o-r,h=n[1]-e[1],f=l*l+h*h;if(f<1e-24)return null;const d=((a-r)*l+(t[1]-e[1])*h)/f;return d<=0||d>=1?null:[e[0]+d*(n[0]-e[0]),e[1]+d*(n[1]-e[1])]}getSearchBBox(t,e){if(typeof t.unproject!="function")return null;const n=this.tolerancePixels,s=[[e.x-n,e.y-n],[e.x+n,e.y-n],[e.x+n,e.y+n],[e.x-n,e.y+n]].map(([h,f])=>t.unproject([h,f]));let r=1/0,o=1/0,a=-1/0,l=-1/0;for(const h of s){const f=Array.isArray(h)?h[0]:h==null?void 0:h.lng,d=Array.isArray(h)?h[1]:h==null?void 0:h.lat;if(!Number.isFinite(f)||!Number.isFinite(d))return null;r=Math.min(r,f),o=Math.min(o,d),a=Math.max(a,f),l=Math.max(l,d)}return[r,o,a,l]}}const Ur={convention:"bearing",ucsRotationDeg:0},bp={enabled:!1,incrementDeg:45,toleranceDeg:4},ll=Math.PI/180;function om(i){const t=i%360;return t<0?t+360:t}function Uu(i,t){return((t.convention==="bearing"?90-i:i)+t.ucsRotationDeg)*ll}function ul(i,t){const e=i/ll-t.ucsRotationDeg;return om(t.convention==="bearing"?90-e:e)}function am(i,t){return(t.convention==="bearing"?-i:i)*ll}function Ip(i,t){const e=we.forCoordinate(i),n=e.toPlanar(i),s=e.toPlanar(t);return{projection:e,origin:n,dx:s[0]-n[0],dy:s[1]-n[1]}}function Hs(i,t,e){const n=we.forCoordinate(i),s=n.toPlanar(i);return n.toGeographic([s[0]+t*Math.cos(e),s[1]+t*Math.sin(e)])}function Qe(i,t,e=Ur){const{dx:n,dy:s}=Ip(i,t);return{distance:Math.hypot(n,s),angle:ul(Math.atan2(s,n),e)}}const Yu=String.raw`[-+]?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?`,s4=new RegExp(String.raw`^@\s*(${Yu})\s*[,\s]\s*(${Yu})$`,"i"),r4=new RegExp(String.raw`^@\s*(${Yu})\s*<\s*(${Yu})$`,"i"),o4=new RegExp(String.raw`^(${Yu})$`,"i");function Sp(i,t={}){const e=i.trim();if(!e)return null;const n=t.frame??Ur,s=t.basePoint??null,r=e.match(r4);if(r){if(!s)return{kind:"error",message:"Relative input needs a base point. Specify the first point first."};const h=Number(r[1]),f=Number(r[2]);return{kind:"point",coordinate:Hs(s,h,Uu(f,n)),description:`@${h}<${f}`}}const o=e.match(s4);if(o){if(!s)return{kind:"error",message:"Relative input needs a base point. Specify the first point first."};const h=Number(o[1]),f=Number(o[2]),d=n.ucsRotationDeg*ll,p=h*Math.cos(d)-f*Math.sin(d),y=h*Math.sin(d)+f*Math.cos(d),_=Math.hypot(p,y);return{kind:"point",coordinate:_===0?[s[0],s[1]]:Hs(s,_,Math.atan2(y,p)),description:`@${h},${f}`}}const a=e.match(o4);if(a){const h=Number(a[1]);if(!s)return{kind:"error",message:"Distance input needs a base point. Specify the first point first."};if(!t.cursor)return{kind:"error",message:"Move the cursor to show the direction, then type the distance."};const{dx:f,dy:d}=Ip(s,t.cursor);return Math.hypot(f,d)<1e-6?{kind:"error",message:"Move the cursor away from the base point to show the direction."}:{kind:"point",coordinate:Hs(s,h,Math.atan2(d,f)),description:`${h} m toward cursor`}}if(e.startsWith("@"))return{kind:"error",message:`Invalid relative input "${e}". Use @dx,dy or @distance<angle.`};const l=Fm(e);return l?{kind:"point",coordinate:l,description:`${l[0]}, ${l[1]}`}:$m(e)?{kind:"error",message:qh(e)}:null}function Mp(i,t,e){const{ortho:n,polar:s,frame:r}=e;if(!n&&!s.enabled)return{coordinate:t,lockedAngle:null,mode:null};const{projection:o,origin:a,dx:l,dy:h}=Ip(i,t);if(Math.hypot(l,h)<1e-9)return{coordinate:t,lockedAngle:null,mode:null};const d=om(Math.atan2(h,l)/ll-r.ucsRotationDeg);let p=null,y=null;if(n)p=Math.round(d/90)*90,y="ortho";else if(s.enabled&&s.incrementDeg>0){const L=Math.round(d/s.incrementDeg)*s.incrementDeg;Math.abs(d-L)<=s.toleranceDeg&&(p=L,y="polar")}if(p===null)return{coordinate:t,lockedAngle:null,mode:null};const _=(p+r.ucsRotationDeg)*ll,E=l*Math.cos(_)+h*Math.sin(_);let w=o.toGeographic([a[0]+E*Math.cos(_),a[1]+E*Math.sin(_)]);if(r.ucsRotationDeg%360===0){const L=om(p)%180;L===0?w=[t[0],i[1]]:L===90&&(w=[i[0],t[1]])}return{coordinate:w,lockedAngle:ul(_,r),mode:y}}class a4{static calculateOrtho(t,e,n=Ur){const s=Mp(t,e,{ortho:!0,polar:bp,frame:n}),{distance:r}=Qe(t,s.coordinate),o=Qe(t,s.coordinate,Ur).angle,a=((o-(90-n.ucsRotationDeg))%180+180)%180;return{coordinate:s.coordinate,distanceMeters:r,bearingDegrees:r>.1?Math.round(o*10)/10:0,axis:a<45||a>135?"horizontal":"vertical"}}}class qw extends jr{constructor(e,n,s){super();Y(this,"dataSource");Y(this,"mapAdapter");Y(this,"snapping",null);Y(this,"currentSnapResult",null);Y(this,"sourceId","_ofs_grips_temp");Y(this,"activeFeatureId",null);Y(this,"activeLayerId",null);Y(this,"activeGrip",null);Y(this,"isDragging",!1);Y(this,"dragHasMoved",!1);Y(this,"isEnabled",!1);Y(this,"activationTimestamp",0);Y(this,"initialFeatureSnapshot",null);Y(this,"unsubClick",null);Y(this,"unsubMouseDown",null);Y(this,"unsubMouseUp",null);Y(this,"unsubMove",null);Y(this,"unsubContextMenu",null);Y(this,"handleKeyDown",e=>{if(!(!this.isEnabled||!this.activeFeatureId||!this.activeLayerId)){if(e.key==="Delete"||e.key==="Backspace")this.activeGrip&&this.activeGrip.type==="vertex"&&(e.preventDefault(),this.deleteVertex(this.activeGrip.index,this.activeGrip.ringIndex,this.activeGrip.partIndex??0)&&(this.activeGrip=null,this.isDragging=!1,this.dragHasMoved=!1));else if(e.key==="Escape")if(this.isDragging&&this.initialFeatureSnapshot){this.dataSource.updateFeature(this.activeLayerId,this.initialFeatureSnapshot,!1),this.isDragging=!1,this.dragHasMoved=!1,this.activeGrip=null,this.initialFeatureSnapshot=null,this.renderGrips();try{const n=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;n&&n.dragPan&&n.dragPan.enable(),n&&n.getCanvas()&&(n.getCanvas().style.cursor="default")}catch(n){Qt("OFSGripsEditor.handleKeyDown",n)}}else this.clear()}});this.dataSource=e,this.mapAdapter=n,this.snapping=s||null,typeof window<"u"&&window.addEventListener("keydown",this.handleKeyDown),this.dataSource.on("feature:updated",({layerId:r,feature:o})=>{this.isEnabled&&this.activeLayerId===r&&this.activeFeatureId===o.id&&!this.isDragging&&this.renderGrips()})}setSnappingEngine(e){this.snapping=e}getSnappingEngine(){return this.snapping}editFeature(e,n){if(this.isEnabled&&this.activeLayerId===e&&this.activeFeatureId===n)return;const s=this.dataSource.getFeature(e,n);!s||!["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon"].includes(s.geometry.type)||(this.activeLayerId=e,this.activeFeatureId=n,this.isEnabled=!0,this.activeGrip=null,this.isDragging=!1,this.dragHasMoved=!1,this.initialFeatureSnapshot=null,this.activationTimestamp=Date.now(),this.setupLayers(),this.renderGrips(),this.bindEvents())}clear(){try{const e=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;e&&e.dragPan&&e.dragPan.enable(),e&&e.getCanvas()&&(e.getCanvas().style.cursor="default")}catch(e){Qt("OFSGripsEditor.clear",e)}this.isEnabled=!1,this.activeFeatureId=null,this.activeLayerId=null,this.activeGrip=null,this.isDragging=!1,this.dragHasMoved=!1,this.initialFeatureSnapshot=null,this.currentSnapResult=null,this.unsubClick&&(this.unsubClick(),this.unsubClick=null),this.unsubMouseDown&&(this.unsubMouseDown(),this.unsubMouseDown=null),this.unsubMouseUp&&(this.unsubMouseUp(),this.unsubMouseUp=null),this.unsubMove&&(this.unsubMove(),this.unsubMove=null),this.unsubContextMenu&&(this.unsubContextMenu(),this.unsubContextMenu=null),this.clearSource(),this.emit("grip:clear",void 0)}getActiveFeature(){return!this.activeLayerId||this.activeFeatureId===null?null:this.dataSource.getFeature(this.activeLayerId,this.activeFeatureId)||null}getActiveLayerId(){return this.activeLayerId}getActiveFeatureId(){return this.activeFeatureId}getIsEditing(){return this.isEnabled&&this.activeFeatureId!==null}hasHandleAt(e,n=18){return this.findNearestHandle(e,n)!==null}getHandles(){const e=this.getActiveFeature();if(!e)return[];const n=[],s=e.geometry.type,r=()=>{try{const o=Io(e).geometry.coordinates;n.push({id:"c_center",coordinate:o,type:"center",index:0,ringIndex:0,partIndex:0})}catch(o){Qt("OFSGripsEditor.getHandles",o)}};if(s==="Point"){const o=e.geometry.coordinates;n.push({id:"v_0",coordinate:o,type:"vertex",index:0,ringIndex:0,partIndex:0})}else if(s==="MultiPoint")e.geometry.coordinates.forEach((a,l)=>{n.push({id:`v_${l}`,coordinate:a,type:"vertex",index:l,ringIndex:0,partIndex:0})}),r();else if(s==="LineString"){const o=e.geometry.coordinates;o.forEach((a,l)=>{if(n.push({id:`v_${l}`,coordinate:a,type:"vertex",index:l,ringIndex:0,partIndex:0}),l<o.length-1){const h=o[l+1];n.push({id:`m_${l}`,coordinate:[(a[0]+h[0])/2,(a[1]+h[1])/2],type:"midpoint",index:l,ringIndex:0,partIndex:0})}}),r()}else s==="MultiLineString"?(e.geometry.coordinates.forEach((a,l)=>{a.forEach((h,f)=>{if(n.push({id:`v_${l}_${f}`,coordinate:h,type:"vertex",index:f,ringIndex:0,partIndex:l}),f<a.length-1){const d=a[f+1];n.push({id:`m_${l}_${f}`,coordinate:[(h[0]+d[0])/2,(h[1]+d[1])/2],type:"midpoint",index:f,ringIndex:0,partIndex:l})}})}),r()):s==="Polygon"?(e.geometry.coordinates.forEach((a,l)=>{const h=a.length-1;for(let f=0;f<h;f++){const d=a[f],p=a[(f+1)%h];n.push({id:`v_${l}_${f}`,coordinate:d,type:"vertex",index:f,ringIndex:l,partIndex:0}),n.push({id:`m_${l}_${f}`,coordinate:[(d[0]+p[0])/2,(d[1]+p[1])/2],type:"midpoint",index:f,ringIndex:l,partIndex:0})}}),r()):s==="MultiPolygon"&&(e.geometry.coordinates.forEach((a,l)=>{a.forEach((h,f)=>{const d=h.length-1;for(let p=0;p<d;p++){const y=h[p],_=h[(p+1)%d];n.push({id:`v_${l}_${f}_${p}`,coordinate:y,type:"vertex",index:p,ringIndex:f,partIndex:l}),n.push({id:`m_${l}_${f}_${p}`,coordinate:[(y[0]+_[0])/2,(y[1]+_[1])/2],type:"midpoint",index:p,ringIndex:f,partIndex:l})}})}),r());return n}setupLayers(){if(this.mapAdapter.isReady)try{const e=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;if(!e||typeof e.getSource!="function")return;if(!e.getSource(this.sourceId))e.addSource(this.sourceId,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),e.addLayer({id:`${this.sourceId}_shape_fill`,source:this.sourceId,type:"fill",filter:["all",["==","$type","Polygon"],["==","gripType","active_shape"]],paint:{"fill-color":"#818cf8","fill-opacity":.25}}),e.addLayer({id:`${this.sourceId}_shape_line`,source:this.sourceId,type:"line",filter:["all",["in","$type","LineString","Polygon"],["==","gripType","active_shape"]],paint:{"line-color":"#2e2b6b","line-width":2.5}}),e.addLayer({id:`${this.sourceId}_center`,source:this.sourceId,type:"circle",filter:["==",["get","gripType"],"center"],paint:{"circle-radius":8,"circle-color":"#10b981","circle-stroke-width":2.5,"circle-stroke-color":"#ffffff"}}),e.addLayer({id:`${this.sourceId}_midpoints`,source:this.sourceId,type:"circle",filter:["==",["get","gripType"],"midpoint"],paint:{"circle-radius":4.5,"circle-color":"#f43f5e","circle-stroke-width":1.5,"circle-stroke-color":"#ffffff"}}),e.addLayer({id:`${this.sourceId}_vertices`,source:this.sourceId,type:"circle",filter:["==",["get","gripType"],"vertex"],paint:{"circle-radius":6.5,"circle-color":"#f43f5e","circle-stroke-width":2.5,"circle-stroke-color":"#ffffff"}}),e.addLayer({id:`${this.sourceId}_direction_arrows`,source:this.sourceId,type:"symbol",filter:["==",["get","gripType"],"direction_arrow"],layout:{"text-field":"▲","text-size":14,"text-rotate":["get","bearing"],"text-rotation-alignment":"map","text-pitch-alignment":"map","text-keep-upright":!1,"text-allow-overlap":!0,"text-ignore-placement":!0},paint:{"text-color":"#0284c7","text-halo-color":"#ffffff","text-halo-width":2}}),e.addLayer({id:`${this.sourceId}_active`,source:this.sourceId,type:"circle",filter:["==",["get","isActive"],!0],paint:{"circle-radius":11,"circle-color":"#fbbf24","circle-opacity":.45,"circle-stroke-width":2.5,"circle-stroke-color":"#f59e0b"}}),e.addLayer({id:`${this.sourceId}_snap_halo`,source:this.sourceId,type:"circle",filter:["all",["==","$type","Point"],["==","isSnap",!0]],paint:{"circle-radius":22,"circle-color":["match",["get","snapType"],"midpoint","#38bdf8","edge","#a855f7","intersection","#f97316","perpendicular","#22c55e","center","#eab308","#3b82f6"],"circle-blur":.85,"circle-opacity":.7}}),e.addLayer({id:`${this.sourceId}_snap_glow`,source:this.sourceId,type:"circle",filter:["all",["==","$type","Point"],["==","isSnap",!0]],paint:{"circle-radius":11,"circle-color":["match",["get","snapType"],"midpoint","#0ea5e9","edge","#8b5cf6","intersection","#f97316","perpendicular","#22c55e","center","#eab308","#2563eb"],"circle-blur":.35,"circle-opacity":.55}}),e.addLayer({id:`${this.sourceId}_snap_core`,source:this.sourceId,type:"circle",filter:["all",["==","$type","Point"],["==","isSnap",!0]],paint:{"circle-radius":5.5,"circle-color":["match",["get","snapType"],"midpoint","#0284c7","edge","#7c3aed","intersection","#f97316","perpendicular","#22c55e","center","#eab308","#1d4ed8"],"circle-stroke-width":2,"circle-stroke-color":"#ffffff","circle-stroke-opacity":1}});else try{e.getLayer(`${this.sourceId}_shape_fill`)&&e.setFilter(`${this.sourceId}_shape_fill`,["all",["==","$type","Polygon"],["==","gripType","active_shape"]]),e.getLayer(`${this.sourceId}_shape_line`)&&e.setFilter(`${this.sourceId}_shape_line`,["all",["in","$type","LineString","Polygon"],["==","gripType","active_shape"]]),e.getLayer(`${this.sourceId}_snap_halo`)||e.addLayer({id:`${this.sourceId}_snap_halo`,source:this.sourceId,type:"circle",filter:["all",["==","$type","Point"],["==","isSnap",!0]],paint:{"circle-radius":22,"circle-color":["match",["get","snapType"],"midpoint","#38bdf8","edge","#a855f7","intersection","#f97316","perpendicular","#22c55e","center","#eab308","#3b82f6"],"circle-blur":.85,"circle-opacity":.7}}),e.getLayer(`${this.sourceId}_snap_glow`)||e.addLayer({id:`${this.sourceId}_snap_glow`,source:this.sourceId,type:"circle",filter:["all",["==","$type","Point"],["==","isSnap",!0]],paint:{"circle-radius":11,"circle-color":["match",["get","snapType"],"midpoint","#0ea5e9","edge","#8b5cf6","intersection","#f97316","perpendicular","#22c55e","center","#eab308","#2563eb"],"circle-blur":.35,"circle-opacity":.55}}),e.getLayer(`${this.sourceId}_snap_core`)||e.addLayer({id:`${this.sourceId}_snap_core`,source:this.sourceId,type:"circle",filter:["all",["==","$type","Point"],["==","isSnap",!0]],paint:{"circle-radius":5.5,"circle-color":["match",["get","snapType"],"midpoint","#0284c7","edge","#7c3aed","intersection","#f97316","perpendicular","#22c55e","center","#eab308","#1d4ed8"],"circle-stroke-width":2,"circle-stroke-color":"#ffffff","circle-stroke-opacity":1}})}catch(n){Qt("OFSGripsEditor.setupLayers",n)}}catch(e){Qt("OFSGripsEditor.setupLayers",e)}}renderGrips(){if(this.mapAdapter.isReady)try{const e=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;if(!e||typeof e.getSource!="function")return;const n=e.getSource(this.sourceId);if(!n||typeof n.setData!="function")return;const s=this.getActiveFeature(),r=[];if(s&&s.geometry&&r.push({type:"Feature",geometry:s.geometry,properties:{gripType:"active_shape"}}),this.getHandles().forEach(l=>{var h;r.push(St(l.coordinate,{gripId:l.id,gripType:l.type,index:l.index,ringIndex:l.ringIndex,partIndex:l.partIndex??0,isActive:((h=this.activeGrip)==null?void 0:h.id)===l.id,isSnap:!1}))}),s&&s.geometry&&s.geometry.type==="LineString"){const l=s.geometry.coordinates;for(let h=0;h<l.length-1;h++){const f=l[h],d=l[h+1],p=[(f[0]+d[0])/2,(f[1]+d[1])/2],y=Wa(St(f),St(d));r.push(St(p,{gripId:`arrow_${h}`,gripType:"direction_arrow",bearing:y,isSnap:!1}))}}this.currentSnapResult&&this.currentSnapResult.coordinate&&r.push(St(this.currentSnapResult.coordinate,{gripId:"snap_indicator",gripType:"snap_guide",isSnap:!0,snapType:this.currentSnapResult.type})),n.setData({type:"FeatureCollection",features:r}),[`${this.sourceId}_shape_fill`,`${this.sourceId}_shape_line`,`${this.sourceId}_direction_arrows`,`${this.sourceId}_center`,`${this.sourceId}_midpoints`,`${this.sourceId}_vertices`,`${this.sourceId}_active`,`${this.sourceId}_snap_halo`,`${this.sourceId}_snap_glow`,`${this.sourceId}_snap_core`].forEach(l=>{try{e.getLayer(l)&&e.moveLayer(l)}catch(h){Qt("OFSGripsEditor.renderGrips",h)}})}catch(e){Qt("OFSGripsEditor.renderGrips",e)}}clearSource(){try{const e=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;if(!e||typeof e.getSource!="function")return;const n=e.getSource(this.sourceId);n&&typeof n.setData=="function"&&n.setData({type:"FeatureCollection",features:[]})}catch(e){Qt("OFSGripsEditor.clearSource",e)}}bindEvents(){this.unsubClick&&this.unsubClick(),this.unsubMouseDown&&this.unsubMouseDown(),this.unsubMouseUp&&this.unsubMouseUp(),this.unsubMove&&this.unsubMove(),this.unsubContextMenu&&this.unsubContextMenu(),this.unsubMouseDown=typeof this.mapAdapter.onMouseDown=="function"?this.mapAdapter.onMouseDown(e=>this.handleMouseDown(e.coordinate)):()=>{},this.unsubMouseUp=typeof this.mapAdapter.onMouseUp=="function"?this.mapAdapter.onMouseUp(e=>this.handleMouseUp(e.coordinate)):()=>{},this.unsubClick=typeof this.mapAdapter.onMapClick=="function"?this.mapAdapter.onMapClick(e=>this.handleClick(e.coordinate)):()=>{},this.unsubMove=typeof this.mapAdapter.onMouseMove=="function"?this.mapAdapter.onMouseMove(e=>this.handleMove(e.coordinate)):()=>{},this.unsubContextMenu=typeof this.mapAdapter.onContextMenu=="function"?this.mapAdapter.onContextMenu(e=>this.handleContextMenu(e.coordinate,e.originalEvent)):()=>{}}findNearestHandle(e,n=18){let s;try{s=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null}catch{return null}if(!s||typeof s.project!="function"){const h=this.getHandles();let f=null,d=.001;for(const p of h){const y=Math.hypot(e[0]-p.coordinate[0],e[1]-p.coordinate[1]),_=p.type==="center"?d*.7:d;y<=_&&(d=y,f=p)}return f}const r=s.project([e[0],e[1]]),o=this.getHandles();let a=null,l=n;for(const h of o){const f=s.project([h.coordinate[0],h.coordinate[1]]),d=Math.hypot(r.x-f.x,r.y-f.y),p=h.type==="center"?Math.min(n,14):n;d<=p&&(a&&h.type!=="center"&&a.type==="center"&&d<=l+4||!a||d<l)&&(a=h,l=d)}return a}handleMouseDown(e){if(!this.isEnabled||!this.activeLayerId||this.activeFeatureId===null||Date.now()-this.activationTimestamp<250)return;const n=this.findNearestHandle(e,18);if(!n)return;const s=this.getActiveFeature();s&&(this.initialFeatureSnapshot=Ye(s)),n.type==="midpoint"?this.insertVertexAtMidpoint(n):(this.activeGrip=n,this.isDragging=!0,this.emit("grip:select",{handle:n}),this.renderGrips()),this.dragHasMoved=!1;try{const r=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;r&&r.dragPan&&typeof r.dragPan.disable=="function"&&r.dragPan.disable(),r&&typeof r.getCanvas=="function"&&r.getCanvas()&&(r.getCanvas().style.cursor="crosshair")}catch(r){Qt("OFSGripsEditor.handleMouseDown",r)}}handleMouseUp(e){var n;if(this.isEnabled){try{const s=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;s&&s.dragPan&&typeof s.dragPan.enable=="function"&&s.dragPan.enable(),s&&typeof s.getCanvas=="function"&&s.getCanvas()&&(s.getCanvas().style.cursor="default")}catch(s){Qt("OFSGripsEditor.handleMouseUp",s)}if(this.isDragging){if(this.dragHasMoved){if(this.activeGrip&&this.activeLayerId&&this.activeFeatureId!==null){const s=this.activeFeatureId,r=this.activeLayerId,o=this.initialFeatureSnapshot,a=this.getActiveFeature();if(o&&a){const l=Ye(a);this.dataSource.transactions.record({description:`Edit geometry of feature ${s}`,undo:()=>{this.dataSource.updateFeature(r,o,!1),this.renderGrips()},redo:()=>{this.dataSource.updateFeature(r,l,!1),this.renderGrips()}})}this.initialFeatureSnapshot=null,this.activeGrip=null,this.isDragging=!1,this.dragHasMoved=!1,this.currentSnapResult=null,this.renderGrips(),this.emit("grip:commit",{featureId:s,layerId:r})}}else if(((n=this.activeGrip)==null?void 0:n.type)==="center"){this.isDragging=!1,this.activeGrip=null,this.initialFeatureSnapshot=null,this.renderGrips();return}}}}handleClick(e){if(!(!this.isEnabled||!this.activeLayerId||this.activeFeatureId===null)&&!(Date.now()-this.activationTimestamp<250)){if(this.dragHasMoved){this.dragHasMoved=!1;return}if(this.isDragging){this.isDragging=!1,this.dragHasMoved=!1;const n=this.activeFeatureId,s=this.activeLayerId,r=this.initialFeatureSnapshot,o=this.getActiveFeature();if(r&&o){const a=Ye(o);this.dataSource.transactions.record({description:`Edit geometry of feature ${n}`,undo:()=>{this.dataSource.updateFeature(s,r,!1),this.renderGrips()},redo:()=>{this.dataSource.updateFeature(s,a,!1),this.renderGrips()}})}this.initialFeatureSnapshot=null,this.activeGrip=null,this.currentSnapResult=null,this.renderGrips(),this.emit("grip:commit",{featureId:n,layerId:s})}else{const n=this.findNearestHandle(e,18);if(n){if(n.type==="center")return;const s=this.getActiveFeature();s&&(this.initialFeatureSnapshot=Ye(s)),n.type==="midpoint"?this.insertVertexAtMidpoint(n):(this.activeGrip=n,this.isDragging=!0,this.emit("grip:select",{handle:n}),this.renderGrips())}}}}handleContextMenu(e,n){if(!this.isEnabled||!this.activeLayerId||this.activeFeatureId===null)return;const s=this.findNearestHandle(e,18);s&&s.type==="vertex"&&(n&&n.preventDefault(),this.deleteVertex(s.index,s.ringIndex,s.partIndex??0),this.activeGrip=null,this.isDragging=!1,this.dragHasMoved=!1)}handleMove(e){if(this.isEnabled){if(this.isDragging&&this.activeGrip&&this.activeLayerId&&this.activeFeatureId!==null){this.dragHasMoved=!0;let n=e,s=null;if(this.snapping&&this.snapping.enabled&&(this.activeGrip.type==="vertex"||this.activeGrip.type==="midpoint")){const r=this.getHandles().filter(o=>o.id!==this.activeGrip.id&&o.type==="vertex").map(o=>o.coordinate);s=this.snapping.getSnap(e,r,{excludeFeatureId:this.activeFeatureId}),s&&(n=s.coordinate)}this.currentSnapResult=s,this.applyCoordinateChange(n);return}try{const n=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;if(n&&typeof n.getCanvas=="function"&&n.getCanvas()){const s=this.findNearestHandle(e,18);s?n.getCanvas().style.cursor=s.type==="center"?"move":"pointer":n.getCanvas().style.cursor="default"}}catch(n){Qt("OFSGripsEditor.handleMove",n)}}}applyCoordinateChange(e){if(!this.activeGrip||!this.activeLayerId||this.activeFeatureId===null)return;const n=this.getActiveFeature();if(n){if(this.activeGrip.type==="center"){const s=e[0]-this.activeGrip.coordinate[0],r=e[1]-this.activeGrip.coordinate[1],o=ue.translateByOffset(n,s,r);o.id=this.activeFeatureId,this.dataSource.updateFeature(this.activeLayerId,o,!1),this.activeGrip.coordinate=e,this.renderGrips(),this.emit("grip:move",{handle:this.activeGrip,coordinate:e});return}if(n.geometry.type==="Point"){const s=St(e,n.properties);s.id=this.activeFeatureId,this.dataSource.updateFeature(this.activeLayerId,s,!1)}else if(n.geometry.type==="MultiPoint"){const s=[...n.geometry.coordinates];s[this.activeGrip.index]=e;const r=IE(s,n.properties);r.id=this.activeFeatureId,this.dataSource.updateFeature(this.activeLayerId,r,!1)}else if(n.geometry.type==="LineString"){const s=[...n.geometry.coordinates];s[this.activeGrip.index]=e;const r=re(s,n.properties);r.id=this.activeFeatureId,this.dataSource.updateFeature(this.activeLayerId,r,!1)}else if(n.geometry.type==="MultiLineString"){const s=n.geometry.coordinates.map(a=>[...a]),r=this.activeGrip.partIndex??0;s[r][this.activeGrip.index]=e;const o=bE(s,n.properties);o.id=this.activeFeatureId,this.dataSource.updateFeature(this.activeLayerId,o,!1)}else if(n.geometry.type==="Polygon"){const s=n.geometry.coordinates.map(l=>[...l]),r=this.activeGrip.ringIndex,o=this.activeGrip.index;s[r][o]=e,o===0&&(s[r][s[r].length-1]=e);const a=Ce(s,n.properties);a.id=this.activeFeatureId,this.dataSource.updateFeature(this.activeLayerId,a,!1)}else if(n.geometry.type==="MultiPolygon"){const s=n.geometry.coordinates.map(h=>h.map(f=>[...f])),r=this.activeGrip.partIndex??0,o=this.activeGrip.ringIndex,a=this.activeGrip.index;s[r][o][a]=e,a===0&&(s[r][o][s[r][o].length-1]=e);const l=bo(s,n.properties);l.id=this.activeFeatureId,this.dataSource.updateFeature(this.activeLayerId,l,!1)}this.activeGrip.coordinate=e,this.renderGrips(),this.emit("grip:move",{handle:this.activeGrip,coordinate:e})}}insertVertexAtMidpoint(e){if(!this.activeLayerId||this.activeFeatureId===null)return;const n=this.getActiveFeature();if(n){if(n.geometry.type==="LineString"){const s=[...n.geometry.coordinates],r=e.index+1;s.splice(r,0,e.coordinate);const o=re(s,n.properties);o.id=this.activeFeatureId,this.dataSource.updateFeature(this.activeLayerId,o,!1),this.activeGrip={id:`v_${r}`,coordinate:e.coordinate,type:"vertex",index:r,ringIndex:0,partIndex:0},this.isDragging=!0,this.renderGrips()}else if(n.geometry.type==="Polygon"){const s=n.geometry.coordinates.map(l=>[...l]),r=e.ringIndex,o=e.index+1;s[r].splice(o,0,e.coordinate);const a=Ce(s,n.properties);a.id=this.activeFeatureId,this.dataSource.updateFeature(this.activeLayerId,a,!1),this.activeGrip={id:`v_${r}_${o}`,coordinate:e.coordinate,type:"vertex",index:o,ringIndex:r,partIndex:0},this.isDragging=!0,this.renderGrips()}else if(n.geometry.type==="MultiPolygon"){const s=n.geometry.coordinates.map(h=>h.map(f=>[...f])),r=e.partIndex??0,o=e.ringIndex,a=e.index+1;s[r][o].splice(a,0,e.coordinate);const l=bo(s,n.properties);l.id=this.activeFeatureId,this.dataSource.updateFeature(this.activeLayerId,l,!1),this.activeGrip={id:`v_${r}_${o}_${a}`,coordinate:e.coordinate,type:"vertex",index:a,ringIndex:o,partIndex:r},this.isDragging=!0,this.renderGrips()}}}deleteVertex(e,n=0,s=0){if(!this.activeLayerId||this.activeFeatureId===null)return!1;const r=this.getActiveFeature();if(!r)return!1;if(r.geometry.type==="LineString"){const o=[...r.geometry.coordinates];if(o.length<=2)return!1;o.splice(e,1);const a=re(o,r.properties);return a.id=this.activeFeatureId,this.dataSource.updateFeature(this.activeLayerId,a,!0),this.renderGrips(),this.emit("grip:delete-vertex",{featureId:this.activeFeatureId,index:e}),!0}else if(r.geometry.type==="Polygon"){const o=r.geometry.coordinates.map(l=>[...l]);if(o[n].length<=4)return!1;o[n].splice(e,1),e===0&&(o[n][o[n].length-1]=o[n][0]);const a=Ce(o,r.properties);return a.id=this.activeFeatureId,this.dataSource.updateFeature(this.activeLayerId,a,!0),this.renderGrips(),this.emit("grip:delete-vertex",{featureId:this.activeFeatureId,index:e}),!0}else if(r.geometry.type==="MultiPolygon"){const o=r.geometry.coordinates.map(l=>l.map(h=>[...h]));if(o[s][n].length<=4)return!1;o[s][n].splice(e,1),e===0&&(o[s][n][o[s][n].length-1]=o[s][n][0]);const a=bo(o,r.properties);return a.id=this.activeFeatureId,this.dataSource.updateFeature(this.activeLayerId,a,!0),this.renderGrips(),this.emit("grip:delete-vertex",{featureId:this.activeFeatureId,index:e}),!0}return!1}destroy(){typeof window<"u"&&window.removeEventListener("keydown",this.handleKeyDown),this.clear(),this.removeAllListeners()}}const w_=1e-12;function od(i,t,e){return[i[0]+(t[0]-i[0])*e,i[1]+(t[1]-i[1])*e]}function Kn(i){return i.segmentIndex+i.t}function zw(i){const t=[],e=n=>{for(let s=0;s<n.length-1;s++)(n[s][0]!==n[s+1][0]||n[s][1]!==n[s+1][1])&&t.push({a:n[s],b:n[s+1]})};switch(i.type){case"LineString":e(i.coordinates);break;case"MultiLineString":case"Polygon":i.coordinates.forEach(e);break;case"MultiPolygon":i.coordinates.forEach(n=>n.forEach(e));break;case"GeometryCollection":i.geometries.forEach(n=>t.push(...zw(n)));break}return t}function yf(i,t,e){const n=t[0]-i[0],s=t[1]-i[1],r=e.b[0]-e.a[0],o=e.b[1]-e.a[1],a=n*o-s*r,l=Math.hypot(n,s)*Math.hypot(r,o);if(l===0||Math.abs(a)<=l*1e-12)return null;const h=e.a[0]-i[0],f=e.a[1]-i[1];return{s:(h*o-f*r)/a,u:(h*s-f*n)/a}}function Fr(i,t){const e=Math.cos(t[1]*Math.PI/180);let n={segmentIndex:0,t:0,coordinate:i[0],distance:1/0};for(let s=0;s<i.length-1;s++){const r=i[s],o=i[s+1],a=(o[0]-r[0])*e,l=o[1]-r[1],h=a*a+l*l,f=h<w_*w_?0:Math.max(0,Math.min(1,((t[0]-r[0])*e*a+(t[1]-r[1])*l)/h)),d=od(r,o,f),p=Math.hypot((t[0]-d[0])*e,t[1]-d[1]);p<n.distance&&(n={segmentIndex:s,t:f,coordinate:d,distance:p})}return n}function l4(i,t){const e=[];for(let n=0;n<i.length-1;n++){const s=i[n],r=i[n+1];for(const o of t){const a=yf(s,r,o);if(!a||a.s<-1e-9||a.s>1+1e-9||a.u<-1e-9||a.u>1+1e-9)continue;const l=Math.max(0,Math.min(1,a.s)),h=a.u<=1e-9?o.a:a.u>=1-1e-9?o.b:od(s,r,l);e.push({segmentIndex:n,t:l,coordinate:h})}}return e.sort((n,s)=>Kn(n)-Kn(s)),e.filter((n,s)=>s===0||Kn(n)-Kn(e[s-1])>1e-9)}function _f(i,t,e){const n=[t.coordinate];for(let s=t.segmentIndex+1;s<=e.segmentIndex;s++)n.push(i[s]);return n.push(e.coordinate),n.filter((s,r)=>r===0||s[0]!==n[r-1][0]||s[1]!==n[r-1][1])}function u4(i,t,e){const n=i.length,s={segmentIndex:0,coordinate:i[0]},r={segmentIndex:n-2,t:1,coordinate:i[n-1]},o=l4(i,t).filter(d=>Kn(d)>1e-9&&Kn(d)<Kn(r)-1e-9);if(o.length===0)return null;const a=Kn(Fr(i,e)),l=[...o].reverse().find(d=>Kn(d)<a)??null,h=o.find(d=>Kn(d)>a)??null,f=[];return l&&f.push(_f(i,s,l)),h&&f.push(_f(i,h,r)),f.filter(d=>d.length>=2)}function c4(i,t,e){const n=i.length;if(n<2)return null;const s=Math.cos(e[1]*Math.PI/180),r=p=>Math.hypot((p[0]-e[0])*s,p[1]-e[1]),o=r(i[n-1])<=r(i[0]),a=o?i[n-2]:i[1],l=o?i[n-1]:i[0];let h=1/0,f=null;for(const p of t){const y=yf(a,l,p);!y||y.u<-1e-9||y.u>1+1e-9||y.s<=1+1e-9||y.s<h&&(h=y.s,f=y.u<=1e-9?p.a:y.u>=1-1e-9?p.b:od(a,l,y.s))}if(!f)return null;const d=[...i];return o?d[n-1]=f:d[0]=f,d}function h4(i,t,e,n,s){const r=Fr(i,t),o=Fr(e,n),a=i[r.segmentIndex],l=i[r.segmentIndex+1],h={a:e[o.segmentIndex],b:e[o.segmentIndex+1]},f=yf(a,l,h);if(!f)return null;const d=od(a,l,f.s),p=yf(h.a,h.b,{a,b:l}),y=f.s>=r.t,_=p.s>=o.t,E=y?a:l,w=_?h.a:h.b;let L=d,b=d,P=null;if(s>0){const S=we.forCoordinate(d),C=Gw(S.toPlanar(E),S.toPlanar(d),S.toPlanar(w),s);if(!C)return null;P=C.points.map(T=>S.toGeographic(T)),L=P[0],b=P[P.length-1]}const N=(S,C,T,I)=>T?[...S.slice(0,C+1),I]:[I,...S.slice(C+1)];return{line1:N(i,r.segmentIndex,y,L),line2:N(e,o.segmentIndex,_,b),arc:P}}function Uw(i,t,e,n){const s=we.forCoordinate(e),r=s.toPlanar(e),o=s.toPlanar(n),a=o[0]-r[0],l=o[1]-r[1];let h=0;const f=y=>y[0]>=t[0]&&y[0]<=t[2]&&y[1]>=t[1]&&y[1]<=t[3],d=y=>{if(!f(y))return y;h++;const _=s.toPlanar(y),E=s.toGeographic([_[0]+a,_[1]+l]);return y.length>2?[E[0],E[1],...y.slice(2)]:E},p=y=>typeof y[0]=="number"?d(y):y.map(p);if(i.type==="GeometryCollection"){const y=i.geometries.map(_=>Uw(_,t,e,n));return{geometry:{...i,geometries:y.map(_=>_.geometry)},moved:y.reduce((_,E)=>_+E.moved,0)}}return{geometry:{...i,coordinates:p(i.coordinates)},moved:h}}function f4(i,t,e){const n=i.length,s={segmentIndex:0,coordinate:i[0]},r={segmentIndex:n-2,t:1,coordinate:i[n-1]};let o=Fr(i,t),a=Fr(i,e);Kn(a)<Kn(o)&&([o,a]=[a,o]);const l=[];return Kn(o)>1e-9&&l.push(_f(i,s,o)),Kn(a)<Kn(r)-1e-9&&l.push(_f(i,a,r)),l.filter(h=>h.length>=2)}function Yw(i){let t=0;for(let e=0;e<i.length-1;e++)t+=Qe(i[e],i[e+1]).distance;return t}function d4(i,t,e){const n=i.length;if(n<2)return null;const s=Math.cos(t[1]*Math.PI/180),r=l=>Math.hypot((l[0]-t[0])*s,l[1]-t[1]),o=r(i[n-1])<=r(i[0]),a=o?[...i]:[...i].reverse();if(e>=0){const l=a[a.length-1],h=Qe(a[a.length-2],l,{convention:"cad",ucsRotationDeg:0}).angle;a[a.length-1]=Hs(l,e,h*Math.PI/180)}else{let l=-e;for(;a.length>=2;){const h=a[a.length-1],f=a[a.length-2],d=Qe(f,h).distance;if(l<d-1e-9){const p=Qe(h,f,{convention:"cad",ucsRotationDeg:0}).angle;a[a.length-1]=Hs(h,l,p*Math.PI/180);break}if(l-=d,a.pop(),a.length<2)return null}}return o?a:a.reverse()}const g4={enabled:!0,acquireDelayMs:400,tolerancePixels:8,maxPoints:5};function x_(i,t,e){const n=t.toPlanar(i.origin),s=[Math.cos(i.angleRad),Math.sin(i.angleRad)],r=Math.abs((e[0]-n[0])*s[1]-(e[1]-n[1])*s[0]);return{line:i,point:n,dir:s,distance:r}}function b_(i,t){const e=i.dir[0]*t.dir[1]-i.dir[1]*t.dir[0];if(Math.abs(e)<1e-9)return null;const n=((t.point[0]-i.point[0])*t.dir[1]-(t.point[1]-i.point[1])*t.dir[0])/e;return[i.point[0]+n*i.dir[0],i.point[1]+n*i.dir[1]]}function m4(i,t){const e=(t[0]-i.point[0])*i.dir[0]+(t[1]-i.point[1])*i.dir[1];return[i.point[0]+e*i.dir[0],i.point[1]+e*i.dir[1]]}function p4(i,t){const{anchor:e,ortho:n,polar:s,frame:r,trackPoints:o,toleranceMeters:a}=t,l=we.forCoordinate(i),h=l.toPlanar(i);let f=null,d=null;if(e){const E=Mp(e,i,{ortho:n,polar:s,frame:r});if(E.mode&&E.lockedAngle!==null){const w={origin:e,angleRad:Uu(E.lockedAngle,r),source:"anchor"};f=x_(w,l,h),d={coordinate:E.coordinate,mode:E.mode,lines:[w]}}}const p=[0,90];if(s.enabled&&s.incrementDeg>0)for(let E=s.incrementDeg;E<180-1e-9;E+=s.incrementDeg)E!==90&&p.push(E);const y=[];for(const E of o)for(const w of p){const L={origin:E,angleRad:(w+r.ucsRotationDeg)*Math.PI/180,source:"track"},b=x_(L,l,h);b.distance<=a&&y.push(b)}y.sort((E,w)=>E.distance-w.distance);const _=(E,w)=>({coordinate:l.toGeographic(E),mode:"tracking",lines:w});if(f&&y.length>0)for(const E of y){const w=b_(f,E);if(w&&Math.hypot(w[0]-h[0],w[1]-h[1])<=f.distance+a*2)return _(w,[f.line,E.line])}for(let E=0;E<y.length;E++)for(let w=E+1;w<y.length;w++){const L=b_(y[E],y[w]);if(L&&Math.hypot(L[0]-h[0],L[1]-h[1])<=a*2)return _(L,[y[E].line,y[w].line])}return d||(y.length>0?_(m4(y[0],h),[y[0].line]):null)}class y4{constructor(t,e){Y(this,"dataSource");Y(this,"mapAdapter");Y(this,"selectionSourceId","_ofs_selection_source");Y(this,"hoverSourceId","_ofs_hover_source");Y(this,"flashSourceId","_ofs_flash_source");Y(this,"unsubSelection",null);Y(this,"currentHoveredFeatureId",null);Y(this,"flashTimer",null);this.dataSource=t,this.mapAdapter=e,this.unsubSelection=this.dataSource.on("selection:changed",()=>{this.syncSelectionOverlay()})}setupLayers(){if(this.mapAdapter.isReady)try{const t=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;if(!t||typeof t.addSource!="function")return;t.getSource(this.selectionSourceId)||(t.addSource(this.selectionSourceId,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),t.addLayer({id:`${this.selectionSourceId}_fill`,source:this.selectionSourceId,type:"fill",filter:["all",["in","$type","Polygon"],["!=","isBbox",!0]],paint:{"fill-color":"#00e5ff","fill-opacity":.22}}),t.addLayer({id:`${this.selectionSourceId}_glow`,source:this.selectionSourceId,type:"line",filter:["all",["in","$type","Polygon","LineString"],["!=","isBbox",!0]],paint:{"line-color":"#00b4d8","line-width":7,"line-blur":3.5,"line-opacity":.85}}),t.addLayer({id:`${this.selectionSourceId}_line`,source:this.selectionSourceId,type:"line",filter:["all",["in","$type","Polygon","LineString"],["!=","isBbox",!0]],paint:{"line-color":"#ffffff","line-width":3,"line-dasharray":[3,2],"line-opacity":1}}),t.addLayer({id:`${this.selectionSourceId}_points`,source:this.selectionSourceId,type:"circle",filter:["all",["in","$type","Point"],["!=","isBbox",!0]],paint:{"circle-radius":9,"circle-color":"#00e5ff","circle-stroke-width":2.5,"circle-stroke-color":"#ffffff","circle-stroke-opacity":1}}),t.addLayer({id:`${this.selectionSourceId}_bbox`,source:this.selectionSourceId,type:"line",filter:["all",["==","$type","Polygon"],["==","isBbox",!0]],paint:{"line-color":"#38bdf8","line-width":1.5,"line-dasharray":[4,4],"line-opacity":.75}})),t.getSource(this.hoverSourceId)||(t.addSource(this.hoverSourceId,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),t.addLayer({id:`${this.hoverSourceId}_fill`,source:this.hoverSourceId,type:"fill",filter:["in","$type","Polygon"],paint:{"fill-color":"#38bdf8","fill-opacity":.15}}),t.addLayer({id:`${this.hoverSourceId}_line`,source:this.hoverSourceId,type:"line",filter:["in","$type","Polygon","LineString"],paint:{"line-color":"#38bdf8","line-width":3.5,"line-opacity":.9,"line-blur":1}}),t.addLayer({id:`${this.hoverSourceId}_point`,source:this.hoverSourceId,type:"circle",filter:["in","$type","Point"],paint:{"circle-radius":8,"circle-color":"#38bdf8","circle-stroke-width":2,"circle-stroke-color":"#ffffff","circle-opacity":.8}})),t.getSource(this.flashSourceId)||(t.addSource(this.flashSourceId,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),t.addLayer({id:`${this.flashSourceId}_fill`,source:this.flashSourceId,type:"fill",filter:["in","$type","Polygon"],paint:{"fill-color":"#22c55e","fill-opacity":.35}}),t.addLayer({id:`${this.flashSourceId}_line`,source:this.flashSourceId,type:"line",filter:["in","$type","Polygon","LineString"],paint:{"line-color":"#4ade80","line-width":5,"line-blur":2,"line-opacity":.95}})),this.bringToFront()}catch{}}bringToFront(){if(this.mapAdapter.isReady)try{const t=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;if(!t||typeof t.moveLayer!="function")return;const e=[`${this.selectionSourceId}_fill`,`${this.selectionSourceId}_glow`,`${this.selectionSourceId}_line`,`${this.selectionSourceId}_points`,`${this.selectionSourceId}_bbox`,`${this.hoverSourceId}_fill`,`${this.hoverSourceId}_line`,`${this.hoverSourceId}_point`,`${this.flashSourceId}_fill`,`${this.flashSourceId}_line`];for(const n of e)t.getLayer(n)&&t.moveLayer(n)}catch(t){Qt("OFSSelectionOverlay.bringToFront",t)}}syncSelectionOverlay(){const t=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;if(!t||typeof t.getSource!="function")return;const e=t.getSource(this.selectionSourceId);if(!e||typeof e.setData!="function")return;const n=[],s=this.dataSource.getAllLayers();for(const o of s){const a=this.dataSource.getSelectedFeatureIds(o.id);a.length>0&&a.forEach(l=>{const h=o.getFeature(l);h&&n.push(Ye(h))})}const r=[...n];if(n.length>=2)try{const o=ae(n),a=De(o),l=Wm(a,{properties:{isBbox:!0}});r.push(l)}catch(o){Qt("OFSSelectionOverlay.syncSelectionOverlay",o)}e.setData({type:"FeatureCollection",features:r})}previewSelection(t){const e=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;if(!e||typeof e.getSource!="function")return;const n=e.getSource(this.selectionSourceId);!n||typeof n.setData!="function"||n.setData({type:"FeatureCollection",features:t.map(s=>Ye(s))})}setHoverFeature(t){if(!this.mapAdapter.isReady)return;const e=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;if(!e||typeof e.getSource!="function")return;const n=e.getSource(this.hoverSourceId);if(!(!n||typeof n.setData!="function")){if(!t){this.currentHoveredFeatureId=null,n.setData({type:"FeatureCollection",features:[]});return}this.currentHoveredFeatureId!==t.id&&(this.currentHoveredFeatureId=t.id??null,n.setData({type:"FeatureCollection",features:[Ye(t)]}))}}flashFeatures(t,e=750){const n=Array.isArray(t)?t:[t];if(!this.mapAdapter.isReady||n.length===0)return;const s=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;if(!s||typeof s.getSource!="function")return;const r=s.getSource(this.flashSourceId);!r||typeof r.setData!="function"||(this.flashTimer&&clearTimeout(this.flashTimer),r.setData({type:"FeatureCollection",features:n.map(o=>Ye(o))}),this.flashTimer=setTimeout(()=>{try{r.setData({type:"FeatureCollection",features:[]})}catch(o){Qt("OFSSelectionOverlay.flashFeatures",o)}this.flashTimer=null},e))}destroy(){this.unsubSelection&&this.unsubSelection(),this.flashTimer&&clearTimeout(this.flashTimer);try{const t=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;t&&([`${this.selectionSourceId}_fill`,`${this.selectionSourceId}_glow`,`${this.selectionSourceId}_line`,`${this.selectionSourceId}_points`,`${this.selectionSourceId}_bbox`,`${this.hoverSourceId}_fill`,`${this.hoverSourceId}_line`,`${this.hoverSourceId}_point`,`${this.flashSourceId}_fill`,`${this.flashSourceId}_line`].forEach(n=>{t.getLayer(n)&&t.removeLayer(n)}),t.getSource(this.selectionSourceId)&&t.removeSource(this.selectionSourceId),t.getSource(this.hoverSourceId)&&t.removeSource(this.hoverSourceId),t.getSource(this.flashSourceId)&&t.removeSource(this.flashSourceId))}catch(t){Qt("OFSSelectionOverlay.destroy",t)}}}const Xw={crosshair:!1,dimensions:!0,segmentLabels:!1,areaLabel:!0,anchor:"cursor",crosshairColor:"#ffffff",crosshairWidth:.75,angles:!0,dimensionOffsetPixels:26,font:["Open Sans Regular","Arial Unicode MS Regular"]},I_=["all",["in","$type","LineString","Polygon"],["!=","isTracking",!0],["!=","isGuide",!0],["!=","isDim",!0],["!=","isDimExt",!0],["!=","isAngle",!0]],S_=["all",["==","$type","Point"],["!=","isSnap",!0],["!=","isLabel",!0],["!=","isTrackPoint",!0]],_4={point:"crosshair",line:"crosshair",polygon:"crosshair",circle:"crosshair",rectangle:"crosshair","select-box":"crosshair","select-polygon":"crosshair",select:"default",modify:"default"};class jw extends jr{constructor(e,n){super();Y(this,"dataSource");Y(this,"mapAdapter");Y(this,"snapping");Y(this,"grips");Y(this,"selectionOverlay");Y(this,"orthoEnabled",!1);Y(this,"polarTracking",{...bp});Y(this,"inputFrame",{convention:"bearing",ucsRotationDeg:0});Y(this,"lastCursorCoord",null);Y(this,"lastConstraint",null);Y(this,"objectTracking",{...g4});Y(this,"trackingPoints",[]);Y(this,"trackingHover",null);Y(this,"now",()=>Date.now());Y(this,"pointPick",null);Y(this,"currentMode",null);Y(this,"activeCoordinates",[]);Y(this,"targetLayerId",null);Y(this,"tempSourceId","_ofs_draw_temp");Y(this,"unsubClick",null);Y(this,"unsubDblClick",null);Y(this,"unsubContextMenu",null);Y(this,"unsubMove",null);Y(this,"unsubMouseDown",null);Y(this,"unsubMouseUp",null);Y(this,"isDrawing",!1);Y(this,"guides",{...Xw});Y(this,"dragSelectStart",null);Y(this,"isDragSelecting",!1);Y(this,"justFinishedDrag",!1);Y(this,"handleKeyDown",e=>{var s;const n=(s=e.target)==null?void 0:s.tagName;if(!(n==="INPUT"||n==="TEXTAREA")){if(e.key==="F8"){e.preventDefault(),this.toggleOrtho();return}if(e.key==="F10"){e.preventDefault(),this.togglePolarTracking();return}if(e.key==="F11"){e.preventDefault(),this.setObjectTracking({enabled:!this.objectTracking.enabled});return}if(e.key==="F3"){e.preventDefault(),this.snapping.enabled=!this.snapping.enabled;return}if(e.key==="Enter"){(this.isDrawing||this.grips.getIsEditing()||this.currentMode==="modify"||this.currentMode==="select")&&(e.preventDefault(),this.finishDrawing());return}if(e.key==="Escape"){(this.isDrawing||this.grips.getIsEditing()||this.currentMode)&&(e.preventDefault(),this.cancel());return}}});this.dataSource=e,this.mapAdapter=n,this.snapping=new zu(e,n),this.grips=new qw(e,n,this.snapping),this.selectionOverlay=new y4(e,n),this.bindMapEvents()}setOrtho(e){this.orthoEnabled=e,this.emit("draw:ortho-change",{enabled:e})}toggleOrtho(){return this.orthoEnabled=!this.orthoEnabled,this.emit("draw:ortho-change",{enabled:this.orthoEnabled}),this.orthoEnabled}setPolarTracking(e){this.polarTracking={...this.polarTracking,...e},this.emit("draw:polar-change",{enabled:this.polarTracking.enabled,incrementDeg:this.polarTracking.incrementDeg})}togglePolarTracking(){return this.setPolarTracking({enabled:!this.polarTracking.enabled}),this.polarTracking.enabled}setUcsRotation(e){this.inputFrame={...this.inputFrame,ucsRotationDeg:(e%360+360)%360},this.emit("draw:ucs-change",{...this.inputFrame})}setAngleConvention(e){this.inputFrame={...this.inputFrame,convention:e},this.emit("draw:ucs-change",{...this.inputFrame})}getMapAdapter(){return this.mapAdapter}getCursorCoordinate(){return this.lastCursorCoord}isDrawModeActive(){return["point","line","polygon","circle","rectangle","select-polygon"].includes(this.currentMode)}getReferencePoint(){return this.pointPick?this.pointPick.basePoint??null:this.isDrawing&&this.activeCoordinates.length>0?this.activeCoordinates[this.activeCoordinates.length-1]:null}resolveCursor(e,n,s=[]){const r=this.snapping.getSnap(e,s,{fromPoint:n});if(r)return{coordinate:r.coordinate,snap:r,constraint:null};const o=this.objectTracking.enabled&&this.snapping.enabled?this.trackingPoints:[],a=p4(e,{anchor:n,ortho:this.orthoEnabled,polar:this.polarTracking,frame:this.inputFrame,trackPoints:o,toleranceMeters:this.objectTracking.tolerancePixels*this.metersPerPixel(e)});return a?{coordinate:a.coordinate,snap:null,constraint:a}:{coordinate:e,snap:null,constraint:null}}metersPerPixel(e){const n=this.safeRawMap();if(!n||typeof n.project!="function"||typeof n.unproject!="function")return 1;try{const s=n.project(e),r=n.unproject([s.x+1,s.y]),o=Array.isArray(r)?[r[0],r[1]]:[r.lng,r.lat],a=Qe(e,o).distance;return Number.isFinite(a)&&a>0?a:1}catch(s){return Qt("OFSDrawTools.metersPerPixel",s),1}}setObjectTracking(e){this.objectTracking={...this.objectTracking,...e},this.objectTracking.enabled||this.clearTrackingPoints(),this.emit("draw:otrack-change",{enabled:this.objectTracking.enabled})}getTrackingPoints(){return[...this.trackingPoints]}clearTrackingPoints(){this.trackingHover=null,this.trackingPoints.length!==0&&(this.trackingPoints=[],this.emit("draw:tracking-points",{points:[]}))}updateTrackingAcquisition(e){if(!this.objectTracking.enabled||!this.snapping.enabled||!e||e.type==="edge"){this.trackingHover=null;return}const n=`${e.coordinate[0]},${e.coordinate[1]}`,s=this.now();if((!this.trackingHover||this.trackingHover.key!==n)&&(this.trackingHover={key:n,coord:e.coordinate,since:s,handled:!1}),this.trackingHover.handled||s-this.trackingHover.since<this.objectTracking.acquireDelayMs)return;this.trackingHover.handled=!0;const r=this.trackingPoints.findIndex(o=>o[0]===e.coordinate[0]&&o[1]===e.coordinate[1]);r>=0?this.trackingPoints.splice(r,1):(this.trackingPoints.push(e.coordinate),this.trackingPoints.length>this.objectTracking.maxPoints&&this.trackingPoints.shift()),this.emit("draw:tracking-points",{points:[...this.trackingPoints]})}getInProgressSnapCoords(){return!this.isDrawing||this.activeCoordinates.length===0?[]:(this.currentMode==="polygon"||this.currentMode==="select-polygon")&&this.activeCoordinates.length>=3?[this.activeCoordinates[0]]:this.currentMode==="line"&&this.activeCoordinates.length>=2?this.activeCoordinates.slice(0,-1):[]}submitInput(e){const n=["point","line","polygon","circle","rectangle","select-polygon"];if(!this.currentMode||!n.includes(this.currentMode))return{handled:!1};const s=e.trim(),r=s.toLowerCase();if(s==="")return this.isDrawing?this.finishDrawing()?{handled:!0,message:`${this.currentMode??"Drawing"} finished.`}:{handled:!0,error:"Not enough points to finish."}:{handled:!1};if(this.isDrawing&&(r==="u"||r==="undo"))return this.undoLastVertex()?{handled:!0,message:"Last point removed."}:{handled:!0,error:"Nothing to undo."};if(this.isDrawing&&(r==="c"||r==="close"))return(this.currentMode==="polygon"||this.currentMode==="select-polygon")&&this.activeCoordinates.length>=3?(this.finishDrawing(),{handled:!0,message:"Polygon closed."}):this.currentMode==="line"&&this.activeCoordinates.length>=3?(this.commitDrawPoint(this.activeCoordinates[0],null),this.finishDrawing(),{handled:!0,message:"Line closed."}):{handled:!0,error:"Close needs at least 3 points."};const o=Sp(s,{basePoint:this.getReferencePoint(),cursor:this.lastCursorCoord,frame:this.inputFrame});return o?o.kind==="error"?{handled:!0,error:o.message}:(this.commitDrawPoint(o.coordinate,null),{handled:!0,message:`Point: ${o.description}`}):{handled:!1}}undoLastVertex(){return!this.isDrawing||this.activeCoordinates.length===0?!1:(this.activeCoordinates.pop(),this.activeCoordinates.length===0&&(this.isDrawing=!1),this.emit("draw:vertex-removed",{mode:this.currentMode,coordinates:[...this.activeCoordinates]}),this.updateTempFeatures(this.lastCursorCoord??this.activeCoordinates[this.activeCoordinates.length-1]??[0,0],null),!0)}beginPointPick(e,n){const s={...e,onPick:n};return this.pointPick=s,this.applyCursor(),()=>{this.pointPick===s&&(this.pointPick=null,this.applyCursor(),this.clearTrackingPoints(),this.lastConstraint=null,this.clearTempFeatures())}}isPickingPoint(){return this.pointPick!==null}setupTempDrawingLayer(){if(this.mapAdapter.isReady)try{const e=this.mapAdapter.getRawMap();if(!e)return;if(!e.getSource(this.tempSourceId))e.addSource(this.tempSourceId,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),e.addLayer({id:`${this.tempSourceId}_fill`,source:this.tempSourceId,type:"fill",filter:["==","$type","Polygon"],paint:{"fill-color":"#3b82f6","fill-opacity":.25}}),e.addLayer({id:`${this.tempSourceId}_crosshair_shadow`,source:this.tempSourceId,type:"line",filter:["all",["==","$type","LineString"],["==","isGuide",!0]],paint:{"line-color":"#0f172a","line-width":2,"line-opacity":.25,"line-dasharray":[5,5]}}),e.addLayer({id:`${this.tempSourceId}_crosshair`,source:this.tempSourceId,type:"line",filter:["all",["==","$type","LineString"],["==","isGuide",!0]],paint:{"line-color":this.guides.crosshairColor,"line-width":this.guides.crosshairWidth,"line-opacity":.95,"line-dasharray":[5,5]}}),e.addLayer({id:`${this.tempSourceId}_line`,source:this.tempSourceId,type:"line",filter:I_,paint:{"line-color":"#2563eb","line-width":2.5,"line-dasharray":[2,1]}}),e.addLayer({id:`${this.tempSourceId}_dim_ext`,source:this.tempSourceId,type:"line",filter:["all",["==","$type","LineString"],["==","isDimExt",!0]],paint:{"line-color":"#334155","line-width":.75,"line-opacity":.7}}),e.addLayer({id:`${this.tempSourceId}_dim`,source:this.tempSourceId,type:"line",filter:["all",["==","$type","LineString"],["==","isDim",!0]],paint:{"line-color":["case",["==",["get","isLive"],!0],"#1d4ed8","#334155"],"line-width":1}}),e.addLayer({id:`${this.tempSourceId}_dim_labels`,source:this.tempSourceId,type:"symbol",filter:["all",["==","$type","LineString"],["==","isDim",!0]],layout:{"text-field":["get","label"],"text-font":this.guides.font,"text-size":["case",["==",["get","isLive"],!0],13,11],"symbol-placement":"line-center","text-rotation-alignment":"map","text-offset":[0,-.7],"text-allow-overlap":!1},paint:{"text-color":["case",["==",["get","isLive"],!0],"#1d4ed8","#334155"],"text-halo-color":"#ffffff","text-halo-width":1.6}}),e.addLayer({id:`${this.tempSourceId}_angle_arc`,source:this.tempSourceId,type:"line",filter:["all",["==","$type","LineString"],["==","isAngle",!0]],paint:{"line-color":["case",["==",["get","isLive"],!0],"#16a34a","#64748b"],"line-width":1.25}}),e.addLayer({id:`${this.tempSourceId}_labels`,source:this.tempSourceId,type:"symbol",filter:["all",["==","$type","Point"],["==","isLabel",!0]],layout:{"text-field":["get","label"],"text-font":this.guides.font,"text-size":["case",["==",["get","isLive"],!0],13,11],"text-offset":[0,-.8],"text-anchor":"bottom","text-allow-overlap":!1,"text-ignore-placement":!1,"symbol-z-order":"source"},paint:{"text-color":["case",["==",["get","isLive"],!0],"#1d4ed8","#334155"],"text-halo-color":"#ffffff","text-halo-width":1.6}}),e.addLayer({id:`${this.tempSourceId}_points`,source:this.tempSourceId,type:"circle",filter:S_,paint:{"circle-radius":5,"circle-color":"#1d4ed8","circle-stroke-width":2,"circle-stroke-color":"#ffffff"}}),e.addLayer({id:`${this.tempSourceId}_snap_halo`,source:this.tempSourceId,type:"circle",filter:["all",["==","$type","Point"],["==","isSnap",!0]],paint:{"circle-radius":22,"circle-color":["match",["get","snapType"],"midpoint","#38bdf8","edge","#a855f7","intersection","#f97316","perpendicular","#22c55e","center","#eab308","#3b82f6"],"circle-blur":.85,"circle-opacity":.7}}),e.addLayer({id:`${this.tempSourceId}_snap_glow`,source:this.tempSourceId,type:"circle",filter:["all",["==","$type","Point"],["==","isSnap",!0]],paint:{"circle-radius":11,"circle-color":["match",["get","snapType"],"midpoint","#0ea5e9","edge","#8b5cf6","intersection","#f97316","perpendicular","#22c55e","center","#eab308","#2563eb"],"circle-blur":.35,"circle-opacity":.55}}),e.addLayer({id:`${this.tempSourceId}_snap_core`,source:this.tempSourceId,type:"circle",filter:["all",["==","$type","Point"],["==","isSnap",!0]],paint:{"circle-radius":5.5,"circle-color":["match",["get","snapType"],"midpoint","#0284c7","edge","#7c3aed","intersection","#f97316","perpendicular","#22c55e","center","#eab308","#1d4ed8"],"circle-stroke-width":2,"circle-stroke-color":"#ffffff","circle-stroke-opacity":1}});else{e.getLayer(`${this.tempSourceId}_snap_halo`)||e.addLayer({id:`${this.tempSourceId}_snap_halo`,source:this.tempSourceId,type:"circle",filter:["all",["==","$type","Point"],["==","isSnap",!0]],paint:{"circle-radius":22,"circle-color":["match",["get","snapType"],"midpoint","#38bdf8","edge","#a855f7","intersection","#f97316","perpendicular","#22c55e","center","#eab308","#3b82f6"],"circle-blur":.85,"circle-opacity":.7}});try{e.getLayer(`${this.tempSourceId}_points`)&&e.setFilter(`${this.tempSourceId}_points`,["all",["==","$type","Point"],["!=","isSnap",!0]]),e.getLayer(`${this.tempSourceId}_snap_halo`)&&e.setFilter(`${this.tempSourceId}_snap_halo`,["all",["==","$type","Point"],["==","isSnap",!0]]),e.getLayer(`${this.tempSourceId}_snap_glow`)&&e.setFilter(`${this.tempSourceId}_snap_glow`,["all",["==","$type","Point"],["==","isSnap",!0]]),e.getLayer(`${this.tempSourceId}_snap_core`)&&e.setFilter(`${this.tempSourceId}_snap_core`,["all",["==","$type","Point"],["==","isSnap",!0]])}catch(n){Qt("OFSDrawTools.setupTempDrawingLayer",n)}}this.ensureTrackingLayer(e),this.selectionOverlay.setupLayers(),this.selectionOverlay.syncSelectionOverlay(),this.bringTempLayersToFront()}catch{}}ensureTrackingLayer(e){try{e.getLayer(`${this.tempSourceId}_line`)&&e.setFilter(`${this.tempSourceId}_line`,I_),e.getLayer(`${this.tempSourceId}_points`)&&e.setFilter(`${this.tempSourceId}_points`,S_),e.getLayer(`${this.tempSourceId}_trackpoints`)||e.addLayer({id:`${this.tempSourceId}_trackpoints`,source:this.tempSourceId,type:"circle",filter:["==","isTrackPoint",!0],paint:{"circle-radius":5,"circle-color":"rgba(0,0,0,0)","circle-stroke-color":"#f59e0b","circle-stroke-width":2}}),e.getLayer(`${this.tempSourceId}_tracking`)||e.addLayer({id:`${this.tempSourceId}_tracking`,source:this.tempSourceId,type:"line",filter:["==","isTracking",!0],paint:{"line-color":"#f59e0b","line-width":1.25,"line-dasharray":[4,3],"line-opacity":.9}})}catch(n){Qt("OFSDrawTools.ensureTrackingLayer",n)}}trackingFeatures(e){const s=this.objectTracking.enabled&&this.snapping.enabled?this.trackingPoints.map(o=>St(o,{isTrackPoint:!0})):[],r=this.lastConstraint;if(!r||e!==this.lastCursorCoord)return s;for(const o of r.lines){const{distance:a}=Qe(o.origin,e),l=Math.max(a*4,a+200),h=o.source==="track"?Hs(o.origin,-l,o.angleRad):o.origin,f=a>1e-6?Qe(o.origin,e,{convention:"cad",ucsRotationDeg:0}).angle*Math.PI/180:o.angleRad,d=Hs(o.origin,l,f);s.push(re([h,d],{isTracking:!0}))}return s}bringTempLayersToFront(){var e;if((e=this.mapAdapter)!=null&&e.isReady)try{const n=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;if(!n||typeof n.getLayer!="function"||typeof n.moveLayer!="function")return;const s=[`${this.tempSourceId}_fill`,`${this.tempSourceId}_crosshair_shadow`,`${this.tempSourceId}_crosshair`,`${this.tempSourceId}_tracking`,`${this.tempSourceId}_trackpoints`,`${this.tempSourceId}_line`,`${this.tempSourceId}_dim_ext`,`${this.tempSourceId}_dim`,`${this.tempSourceId}_dim_labels`,`${this.tempSourceId}_angle_arc`,`${this.tempSourceId}_points`,`${this.tempSourceId}_snap_halo`,`${this.tempSourceId}_snap_glow`,`${this.tempSourceId}_snap_core`];for(const r of s)n.getLayer(r)&&n.moveLayer(r);this.selectionOverlay.bringToFront()}catch(n){Qt("OFSDrawTools.bringTempLayersToFront",n)}}bindMapEvents(){this.unsubClick=typeof this.mapAdapter.onMapClick=="function"?this.mapAdapter.onMapClick(e=>this.handleMapClick(e)):()=>{},this.unsubDblClick=typeof this.mapAdapter.onMapDblClick=="function"?this.mapAdapter.onMapDblClick(e=>this.handleMapDblClick(e)):()=>{},this.unsubContextMenu=typeof this.mapAdapter.onContextMenu=="function"?this.mapAdapter.onContextMenu(e=>this.handleContextMenu(e)):()=>{},this.unsubMove=typeof this.mapAdapter.onMouseMove=="function"?this.mapAdapter.onMouseMove(e=>this.handleMouseMove(e)):()=>{},this.unsubMouseDown=typeof this.mapAdapter.onMouseDown=="function"?this.mapAdapter.onMouseDown(e=>this.handleMouseDown(e)):()=>{},this.unsubMouseUp=typeof this.mapAdapter.onMouseUp=="function"?this.mapAdapter.onMouseUp(e=>this.handleMouseUp(e)):()=>{},typeof window<"u"&&window.addEventListener("keydown",this.handleKeyDown)}getRequiredGeometryType(e){return e==="point"?"point":e==="line"?"line":"polygon"}resolveTargetLayerId(e,n){const s=this.getRequiredGeometryType(e);if(n){const f=this.dataSource.getLayer(n);if(f&&f.type===s)return f.id}const r=this.dataSource.getActiveLayer();if(r&&r.type===s)return r.id;const o=this.dataSource.getAllLayers().find(f=>f.type===s&&f.visible);if(o)return this.dataSource.setActiveLayer(o.id),o.id;const a=this.dataSource.getAllLayers().find(f=>f.type===s);if(a)return this.dataSource.setActiveLayer(a.id),a.id;const l=s.charAt(0).toUpperCase()+s.slice(1),h=this.dataSource.addLayer({id:`draw_${s}_layer`,name:`${l}s Layer (Drawn)`,type:s,zIndex:10});return this.dataSource.setActiveLayer(h.id),h.id}getTargetLayerId(){return this.targetLayerId}setMode(e,n){var s;if(this.currentMode!==e){this.isDrawing&&this.cancel(),this.currentMode=e,e!=="modify"&&this.grips.getIsEditing()&&this.grips.clear(),e==="select"||e==="modify"||e==="select-box"||e==="select-polygon"?this.targetLayerId=n||null:e?this.targetLayerId=this.resolveTargetLayerId(e,n):(this.targetLayerId=null,this.grips.clear()),this.setupTempDrawingLayer(),this.emit("draw:mode-change",{mode:e});try{if((s=this.mapAdapter)!=null&&s.isReady){typeof this.mapAdapter.setDoubleClickZoom=="function"&&this.mapAdapter.setDoubleClickZoom(e===null||e==="select"||e==="modify");const r=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;r&&(r.boxZoom&&(e==="select"||e==="select-box"||e==="select-polygon"?r.boxZoom.disable():r.boxZoom.enable()),this.applyCursor())}}catch(r){Qt("OFSDrawTools.setMode",r)}}}getMode(){return this.currentMode}getIsDrawing(){return this.isDrawing}getActiveCoordinates(){return[...this.activeCoordinates]}handleMouseDown(e){if(this.currentMode&&(this.currentMode==="select"||this.currentMode==="select-box")){if(this.grips.getIsEditing()&&this.grips.hasHandleAt(e.coordinate,18))return;this.dragSelectStart={coord:e.coordinate,point:{x:e.point.x,y:e.point.y}},this.isDragSelecting=!1}}handleMouseUp(e){var s;const n=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;if(n&&n.dragPan&&!n.dragPan.isEnabled()&&n.dragPan.enable(),this.isDragSelecting&&this.dragSelectStart){const r=this.dragSelectStart.coord,o=e.coordinate,a=Math.min(r[0],o[0]),l=Math.max(r[0],o[0]),h=Math.min(r[1],o[1]),f=Math.max(r[1],o[1]),d=Ce([[[a,h],[l,h],[l,f],[a,f],[a,h]]]),p=!!((s=e.originalEvent)!=null&&s.shiftKey);this.executeDrawSelection("select-box",d,p),this.justFinishedDrag=!0,setTimeout(()=>{this.justFinishedDrag=!1},150),this.isDragSelecting=!1,this.dragSelectStart=null,this.clearTempFeatures();return}this.dragSelectStart=null,this.isDragSelecting=!1}handleMapClick(e){var o,a,l;if(this.pointPick){const h=this.pointPick,{coordinate:f}=this.resolveCursor(e.coordinate,h.basePoint??null);this.pointPick=null,this.applyCursor(),this.clearTrackingPoints(),this.lastConstraint=null,this.clearTempFeatures(),h.onPick(f);return}if(!this.currentMode||this.justFinishedDrag)return;if(this.currentMode==="select"){this.grips.getIsEditing()&&this.grips.clear();const h=!!((o=e.originalEvent)!=null&&o.shiftKey);if(e.features&&e.features.length>0){const f=e.features[0];if(f.id!==void 0&&f.layerId){h?this.dataSource.toggleFeatureSelection(f.layerId,f.id):this.dataSource.selectFeature(f.layerId,f.id,!1);return}}else{h||this.dataSource.clearSelection();return}return}if(this.currentMode==="modify"){if(this.grips.getIsEditing()&&this.grips.hasHandleAt(e.coordinate,18))return;const h=!!((a=e.originalEvent)!=null&&a.shiftKey);if(e.features&&e.features.length>0){const f=e.features[0];if(f.id!==void 0&&f.layerId){this.dataSource.selectFeature(f.layerId,f.id,!1),this.grips.editFeature(f.layerId,f.id);return}}else{h||this.stopEdit();return}return}if(this.currentMode==="select-box"){const h=e.coordinate,f=!!((l=e.originalEvent)!=null&&l.shiftKey);if(!this.isDrawing)this.isDrawing=!0,this.activeCoordinates=[h],this.emit("draw:start",{mode:"select-box",coordinate:h}),this.updateTempFeatures(h,null);else{const d=this.activeCoordinates[0],p=h,y=Math.min(d[0],p[0]),_=Math.max(d[0],p[0]),E=Math.min(d[1],p[1]),w=Math.max(d[1],p[1]),L=Ce([[[y,E],[_,E],[_,w],[y,w],[y,E]]]);this.executeDrawSelection("select-box",L,f),this.resetDrawingState(!0)}return}const n=this.isDrawing&&this.activeCoordinates.length>0?this.activeCoordinates[this.activeCoordinates.length-1]:null,{coordinate:s,snap:r}=this.resolveCursor(e.coordinate,n,this.getInProgressSnapCoords());this.commitDrawPoint(s,r,!0)}commitDrawPoint(e,n,s=!1){if(this.currentMode){if(this.isDrawing){if((this.currentMode==="polygon"||this.currentMode==="select-polygon")&&this.activeCoordinates.length>=3){const o=this.activeCoordinates[0];let a=!1;if(n&&n.coordinate[0]===o[0]&&n.coordinate[1]===o[1])a=!0;else if(e[0]===o[0]&&e[1]===o[1])a=!0;else if(s)try{const l=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;if(l&&typeof l.project=="function"){const h=l.project([o[0],o[1]]),f=l.project([e[0],e[1]]);h&&f&&Math.hypot(h.x-f.x,h.y-f.y)<=12&&(a=!0)}else _o(e,o)<.5&&(a=!0)}catch(l){Qt("OFSDrawTools.commitDrawPoint",l),_o(e,o)<.5&&(a=!0)}if(a){this.finishDrawing();return}}const r=this.activeCoordinates[this.activeCoordinates.length-1];if(r[0]===e[0]&&r[1]===e[1]&&(this.currentMode==="line"&&this.activeCoordinates.length>=2||(this.currentMode==="polygon"||this.currentMode==="select-polygon")&&this.activeCoordinates.length>=3)){this.finishDrawing();return}if(this.activeCoordinates.push(e),this.emit("draw:vertex-added",{mode:this.currentMode,coordinate:e,coordinates:[...this.activeCoordinates]}),(this.currentMode==="circle"||this.currentMode==="rectangle")&&this.activeCoordinates.length>=2){this.finishDrawing();return}}else if(this.isDrawing=!0,this.activeCoordinates=[e],this.emit("draw:start",{mode:this.currentMode,coordinate:e}),this.currentMode==="point"){this.finishDrawing();return}this.updateTempFeatures(e,n)}}handleMapDblClick(e){if(this.currentMode){if(this.currentMode==="select"&&e.features&&e.features.length>0){const n=e.features[0];if(n.id!==void 0&&n.layerId){this.startEdit(n.layerId,n.id);return}}if(this.isDrawing&&(this.currentMode==="line"||this.currentMode==="polygon"||this.currentMode==="select-polygon")){if(this.activeCoordinates.length>1){const n=this.activeCoordinates[this.activeCoordinates.length-1],s=this.activeCoordinates[this.activeCoordinates.length-2];n[0]===s[0]&&n[1]===s[1]&&this.activeCoordinates.pop()}this.finishDrawing()}}}handleContextMenu(e){this.currentMode&&(e.originalEvent&&e.originalEvent.preventDefault(),this.isDrawing&&((this.currentMode==="polygon"||this.currentMode==="select-polygon")&&this.activeCoordinates.length>=3||this.currentMode==="line"&&this.activeCoordinates.length>=2?this.finishDrawing():this.cancel()))}handleMouseMove(e){if(this.pointPick){const a=this.pointPick.basePoint??null,{coordinate:l,snap:h,constraint:f}=this.resolveCursor(e.coordinate,a);this.updateTrackingAcquisition(h),this.lastCursorCoord=l,this.lastConstraint=f,a&&this.emitMeasure(a,l,f),this.emit("draw:move",{coordinate:l,isSnapped:!!h,snapResult:h||void 0}),this.updatePickPreview(l,h);return}if(this.dragSelectStart&&Math.hypot(e.point.x-this.dragSelectStart.point.x,e.point.y-this.dragSelectStart.point.y)>4){this.isDragSelecting=!0;const l=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;l&&l.dragPan&&l.dragPan.isEnabled()&&l.dragPan.disable(),this.updateDragBoxPreview(this.dragSelectStart.coord,e.coordinate);const h=Math.min(this.dragSelectStart.coord[0],e.coordinate[0]),f=Math.max(this.dragSelectStart.coord[0],e.coordinate[0]),d=Math.min(this.dragSelectStart.coord[1],e.coordinate[1]),p=Math.max(this.dragSelectStart.coord[1],e.coordinate[1]),y=Ce([[[h,d],[f,d],[f,p],[h,p],[h,d]]]),_=this.queryFeaturesInGeometry(y);this.selectionOverlay.previewSelection(_.map(L=>L.feature));const E=_o([h,d],[f,d]),w=_o([h,d],[h,p]);this.emit("selection:drag-progress",{widthMeters:Math.round(E*10)/10,heightMeters:Math.round(w*10)/10,count:_.length,coordinate:e.coordinate});return}if(this.currentMode==="select"||this.currentMode==="modify"){const a=e.features&&e.features.length>0?e.features[0]:null,l=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null,h=l&&typeof l.getCanvas=="function"?l.getCanvas():null;if(a&&a.id!==void 0&&a.layerId){const f=this.dataSource.getLayer(a.layerId),d=f==null?void 0:f.getFeature(a.id);this.selectionOverlay.setHoverFeature(d||a),h&&(h.style.cursor="pointer")}else this.selectionOverlay.setHoverFeature(null),h&&(h.style.cursor="default");return}if(!this.currentMode)return;const n=this.isDrawing&&this.activeCoordinates.length>0?this.activeCoordinates[this.activeCoordinates.length-1]:null,{coordinate:s,snap:r,constraint:o}=this.resolveCursor(e.coordinate,n,this.getInProgressSnapCoords());this.isDrawModeActive()&&this.updateTrackingAcquisition(r),this.lastCursorCoord=s,this.lastConstraint=o,n&&this.emitMeasure(n,s,o),this.emit("draw:move",{coordinate:s,isSnapped:!!r,snapResult:r||void 0}),this.updateTempFeatures(s,r)}emitMeasure(e,n,s){const r=Qe(e,n,this.inputFrame),o=Qe(e,n,{convention:"bearing",ucsRotationDeg:0});this.emit("draw:measure",{distanceMeters:Math.round(r.distance*1e3)/1e3,bearingDegrees:Math.round(o.angle*100)/100,angle:Math.round(r.angle*100)/100,constraint:(s==null?void 0:s.mode)??null,coordinate:n})}updatePickPreview(e,n){var l;const s=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null,r=s&&typeof s.getSource=="function"?s.getSource(this.tempSourceId):null;if(!r||typeof r.setData!="function")return;const o=[];n&&o.push(St(n.coordinate,{isSnap:!0,snapType:n.type}));const a=(l=this.pointPick)==null?void 0:l.basePoint;a&&(o.push(St(a,{isSnap:!1})),o.push(re([a,e])),o.push(...this.trackingFeatures(e))),r.setData({type:"FeatureCollection",features:o})}finishDrawing(){if(this.grips.getIsEditing()||this.currentMode==="modify"){const s=this.grips.getActiveFeature(),r=this.grips.activeLayerId||this.targetLayerId||this.dataSource.getActiveLayerId()||"";return this.stopEdit(),(this.currentMode==="modify"||this.currentMode==="select")&&this.resetDrawingState(!1),s&&this.emit("draw:complete",{mode:"modify",layerId:r,feature:s}),s||null}if(!this.currentMode||this.activeCoordinates.length===0)return null;let e=null;const n=[...this.activeCoordinates];if(this.currentMode==="line"&&n.length<2||(this.currentMode==="polygon"||this.currentMode==="select-polygon")&&n.length<3||(this.currentMode==="circle"||this.currentMode==="rectangle"||this.currentMode==="select-box")&&n.length<2)return null;if(this.currentMode==="point")e=St(n[0],{name:`Point ${new Date().toLocaleTimeString()}`,createdAt:new Date().toISOString()});else if(this.currentMode==="line")e=re(n,{name:`Line ${new Date().toLocaleTimeString()}`,lengthMeters:el(re(n),{units:"meters"}),createdAt:new Date().toISOString()});else if(this.currentMode==="polygon"){const s=[...n],r=s[0],o=s[s.length-1];(r[0]!==o[0]||r[1]!==o[1])&&s.push(r),e=Ce([s],{name:`Polygon ${new Date().toLocaleTimeString()}`,areaM2:Tu(Ce([s])),createdAt:new Date().toISOString()})}else if(this.currentMode==="circle"){const s=n[0],r=nn(St(s),St(n[1]),{units:"meters"});e=Q1(s,r,{units:"meters",steps:64,properties:{name:`Circle ${new Date().toLocaleTimeString()}`,shape:"circle",radiusMeters:r,createdAt:new Date().toISOString()}})}else if(this.currentMode==="rectangle"){const s=n[0],r=n[1],o=Math.min(s[0],r[0]),a=Math.max(s[0],r[0]),l=Math.min(s[1],r[1]),h=Math.max(s[1],r[1]);e=Ce([[[o,l],[a,l],[a,h],[o,h],[o,l]]],{name:`Rectangle ${new Date().toLocaleTimeString()}`,shape:"rectangle",createdAt:new Date().toISOString()})}else if(this.currentMode==="select-box"){const s=n[0],r=n[1],o=Math.min(s[0],r[0]),a=Math.max(s[0],r[0]),l=Math.min(s[1],r[1]),h=Math.max(s[1],r[1]),f=Ce([[[o,l],[a,l],[a,h],[o,h],[o,l]]]);return this.executeDrawSelection("select-box",f,!1),this.resetDrawingState(!0),null}else if(this.currentMode==="select-polygon"){const s=[...n],r=s[0],o=s[s.length-1];(r[0]!==o[0]||r[1]!==o[1])&&s.push(r);const a=Ce([s]);return this.executeDrawSelection("select-polygon",a,!1),this.resetDrawingState(!0),null}if(e){const s=this.currentMode,r=this.resolveTargetLayerId(s,this.targetLayerId||void 0);return this.dataSource.addFeature(r,e),this.resetDrawingState(!0),this.emit("draw:complete",{mode:s,feature:e,layerId:r}),e}return this.resetDrawingState(!0),null}resetDrawingState(e=!0){var n;if(this.isDrawing=!1,this.clearTrackingPoints(),this.lastConstraint=null,this.activeCoordinates=[],this.clearTempFeatures(),this.selectionOverlay.setHoverFeature(null),this.selectionOverlay.syncSelectionOverlay(),e&&this.currentMode!==null){this.currentMode=null,this.targetLayerId=null;try{(n=this.mapAdapter)!=null&&n.isReady&&(typeof this.mapAdapter.setDoubleClickZoom=="function"&&this.mapAdapter.setDoubleClickZoom(!0),this.applyCursor())}catch(s){Qt("OFSDrawTools.resetDrawingState",s)}this.emit("draw:mode-change",{mode:null})}}cancel(){this.pointPick=null;const e=this.grips.getIsEditing()||this.currentMode==="modify";if(e){this.stopEdit(),this.resetDrawingState(!1),this.emit("draw:cancel",{mode:"modify"});return}const n=this.currentMode,s=this.isDrawing;this.resetDrawingState(!0),(e||n||s)&&this.emit("draw:cancel",{mode:n||"modify"})}drawPointByCoords(e,n,s={}){const r=St(e,s),o=n||this.dataSource.getActiveLayerId()||"points";return this.dataSource.hasLayer(o)||this.dataSource.addLayer({id:o,name:"Points",type:"point"}),this.dataSource.addFeature(o,r),r}drawLineByCoords(e,n,s={}){const r=re(e,s),o=n||this.dataSource.getActiveLayerId()||"lines";return this.dataSource.hasLayer(o)||this.dataSource.addLayer({id:o,name:"Lines",type:"line"}),this.dataSource.addFeature(o,r),r}drawPolygonByCoords(e,n,s={}){const r=[...e],o=r[0],a=r[r.length-1];(o[0]!==a[0]||o[1]!==a[1])&&r.push(o);const l=Ce([r],s),h=n||this.dataSource.getActiveLayerId()||"polygons";return this.dataSource.hasLayer(h)||this.dataSource.addLayer({id:h,name:"Polygons",type:"polygon"}),this.dataSource.addFeature(h,l),l}splitPolygon(e,n,s){const r=this.dataSource.getFeature(e,n);if(!r)return null;let o=null;if(s!==void 0){if(o=this.dataSource.getFeature(e,s),!o)for(const l of this.dataSource.getAllLayers()){const h=l.getFeature(s);if(h&&(h.geometry.type==="LineString"||h.geometry.type==="MultiLineString")){o=h;break}}}else{const l=De(r);for(const h of this.dataSource.getAllLayers())if(o=h.queryBBox(l).find(f=>f.id!==n&&f.geometry.type==="LineString"&&To(r,f))||null,o)break}if(!o)return null;const a=ue.splitPolygonByLine(r,o);return a&&a.length>1?(this.dataSource.runTransaction(`Split polygon ${n} into ${a.length} parts`,()=>{this.dataSource.removeFeature(e,n),a.forEach((l,h)=>{l.id=this.dataSource.getAvailableFeatureId(e,`${n}_part_${h+1}`),l.properties={...r.properties||{},_split:h+1},this.dataSource.addFeature(e,l)})}),a):null}splitOverlappingPolygons(e,n,s){return this.dataSource.splitOverlapping(e,n,s)}splitLine(e,n,s){const r=this.dataSource.getFeature(e,n);if(!r||r.geometry.type!=="LineString")return null;let o=s;if(typeof s=="string"||typeof s=="number"){let l=this.dataSource.getFeature(e,s)||null;if(!l)for(const h of this.dataSource.getAllLayers()){const f=h.getFeature(s);if(f){l=f;break}}if(!l)return null;o=l}const a=ue.splitLine(r,o);return a&&a.length>1?(this.dataSource.runTransaction(`Split line ${n} into ${a.length} segments`,()=>{this.dataSource.removeFeature(e,n),a.forEach((l,h)=>{l.id=this.dataSource.getAvailableFeatureId(e,`${n}_seg_${h+1}`),l.properties={...r.properties||{},_split:h+1},this.dataSource.addFeature(e,l)})}),a):null}joinLines(e,n,s,r=15){var h;const o=this.dataSource.getFeature(e,n);let a=this.dataSource.getFeature(e,s);if(!a)for(const f of this.dataSource.getAllLayers()){const d=f.getFeature(s);if(d&&d.geometry.type==="LineString"){a=d;break}}if(!o||!a||o.geometry.type!=="LineString"||a.geometry.type!=="LineString")return null;const l=ue.connectLines([o,a],r,!0);return l?(l.id=n,this.dataSource.runTransaction(`Join lines ${n} and ${s}`,()=>{this.dataSource.updateFeature(e,l),this.dataSource.removeFeature(e,s)}),this.grips.getIsEditing()&&((h=this.grips.getActiveFeature())==null?void 0:h.id)===n&&this.grips.editFeature(e,n),l):null}offsetFeature(e,n,s,r=!1){var l;const o=this.dataSource.getFeature(e,n);if(!o)return null;const a=ue.offset(o,s);if(a)if(r){const h=this.dataSource.getAvailableFeatureId(e);return a.id=h,a.properties&&(a.properties={...a.properties,name:`${a.properties.name||"Feature"} (Offset ${s>0?"+":""}${s}m)`}),this.dataSource.addFeature(e,a),a}else return a.id=n,this.dataSource.updateFeature(e,a),this.grips.getIsEditing()&&((l=this.grips.getActiveFeature())==null?void 0:l.id)===n&&this.grips.editFeature(e,n),a;return null}rotateFeature(e,n,s,r){const o=this.dataSource.getFeature(e,n);if(!o)return null;const a=ue.rotate(o,s,r);return a.id=n,this.dataSource.updateFeature(e,a),a}scaleFeature(e,n,s,r){const o=this.dataSource.getFeature(e,n);if(!o)return null;const a=ue.scale(o,s,r);return a.id=n,this.dataSource.updateFeature(e,a),a}explodeFeature(e,n){const s=this.dataSource.getFeature(e,n);if(!s||s.geometry.type!=="Polygon"&&s.geometry.type!=="MultiPolygon")return null;const r=ue.explode(s);return r.length>0?(this.dataSource.runTransaction(`Explode polygon ${n} into ${r.length} lines`,()=>{this.dataSource.removeFeature(e,n),r.forEach(o=>this.dataSource.addFeature(e,o))}),r):null}filletFeature(e,n,s,r=5){const o=this.dataSource.getFeature(e,n);if(!o)return null;const a=ue.fillet(o,s,r);return a?(a.id=n,this.dataSource.updateFeature(e,a),a):null}startEdit(e,n){return this.dataSource.getFeature(e,n)?(this.dataSource.selectFeature(e,n),this.grips.editFeature(e,n),this.currentMode!=="modify"&&(this.currentMode="modify",this.emit("draw:mode-change",{mode:"modify"})),!0):!1}stopEdit(){this.grips.clear(),this.currentMode==="modify"&&(this.currentMode="select",this.emit("draw:mode-change",{mode:"select"}))}isEditing(){return this.grips.getIsEditing()}getActiveEditingFeature(){return this.grips.getActiveFeature()}getActiveEditingLayerId(){return this.grips.getActiveLayerId()}getActiveEditingFeatureId(){return this.grips.getActiveFeatureId()}updateGeometry(e,n,s){var l;const r=this.dataSource.getFeature(e,n);if(!r)return!1;const o={...r,geometry:s},a=this.dataSource.updateFeature(e,o);return a&&this.grips.getIsEditing()&&((l=this.grips.getActiveFeature())==null?void 0:l.id)===n&&this.grips.editFeature(e,n),a}moveFeature(e,n,s,r){var l;const o=this.dataSource.getFeature(e,n);if(!o)return null;const a=ue.translate(o,s,r);return a.id=n,this.dataSource.updateFeature(e,a),this.grips.getIsEditing()&&((l=this.grips.getActiveFeature())==null?void 0:l.id)===n&&this.grips.editFeature(e,n),a}moveFeatureByOffset(e,n,s,r){var l;const o=this.dataSource.getFeature(e,n);if(!o)return null;const a=ue.translateByOffset(o,s,r);return a.id=n,this.dataSource.updateFeature(e,a),this.grips.getIsEditing()&&((l=this.grips.getActiveFeature())==null?void 0:l.id)===n&&this.grips.editFeature(e,n),a}copyFeature(e,n,s,r){const o=this.dataSource.getFeature(e,n);if(!o)return null;const a=ue.translateByOffset(o,s,r),l=this.dataSource.getAvailableFeatureId(e,`${n}_copy`);return a.id=l,a.properties&&(a.properties={...a.properties,name:`${a.properties.name||"Feature"} (Copy)`}),this.dataSource.addFeature(e,a),a}copyFeatureByDistance(e,n,s,r){var l;const o=this.dataSource.getFeature(e,n);if(!o)return null;const a=ue.translate(o,s,r);return a.id=this.dataSource.getAvailableFeatureId(e,`${n}_copy`),a.properties={...a.properties||{},name:`${((l=a.properties)==null?void 0:l.name)||"Feature"} (Copy)`},this.dataSource.addFeature(e,a)}transformFeatures(e,n,s,r=!1){const o=[];this.dataSource.runTransaction(n,()=>{for(const{layerId:h,featureId:f}of e){const d=this.dataSource.getFeature(h,f);if(!d)continue;const p=s(d);r?(p.id=this.dataSource.getAvailableFeatureId(h,`${f}_copy`),o.push(this.dataSource.addFeature(h,p))):(p.id=d.id,this.dataSource.updateFeature(h,p),o.push(this.dataSource.getFeature(h,d.id)))}});const a=this.grips.getIsEditing()?this.grips.getActiveFeature():null,l=this.grips.getActiveLayerId();return!r&&a&&l&&e.some(h=>h.layerId===l&&h.featureId===a.id)&&this.grips.editFeature(l,a.id),o}findLineAt(e,n=12){return this.findFeatureAt(e,{tolerancePixels:n,types:["LineString"]})}findFeatureAt(e,n={}){var d;const s=n.tolerancePixels??12,r=n.types??["LineString","Polygon"],o=typeof this.mapAdapter.getRawMap=="function"?this.safeRawMap():null,a=o&&typeof o.project=="function";let l=2/111320/Math.max(.1,Math.cos(e[1]*Math.PI/180));if(a&&typeof o.unproject=="function"){const p=o.project(e),y=o.unproject([p.x+s,p.y+s]),_=Array.isArray(y)?y[0]:y.lng,E=Array.isArray(y)?y[1]:y.lat;l=Math.max(Math.abs(_-e[0]),Math.abs(E-e[1]))}const h=p=>{let y=null;for(const _ of p){if(_.length<2)continue;const E=Fr(_,e);let w;if(a){const L=o.project(e),b=o.project(E.coordinate);if(w=Math.hypot(L.x-b.x,L.y-b.y),w>s)continue}else if(w=_o(e,E.coordinate),w>2)continue;(y===null||w<y)&&(y=w)}return y};let f=null;for(const p of this.dataSource.getAllLayers().filter(y=>y.visible))for(const y of p.queryNear(e,l)){const _=(d=y.geometry)==null?void 0:d.type;let E=null;_==="LineString"&&r.includes("LineString")?E=h([y.geometry.coordinates]):_==="Polygon"&&r.includes("Polygon")&&(E=h(y.geometry.coordinates),E===null&&Ht(e,y)&&(E=s+1)),E!==null&&(!f||E<f.distance)&&(f={layerId:p.id,feature:y,distance:E})}return f}breakLineAt(e,n){const s=this.findLineAt(e);if(!s)return null;const{layerId:r,feature:o}=s,a=f4(o.geometry.coordinates,e,n);return this.replaceLineWithPieces(r,o,a,`Break line ${o.id}`)}lengthenLineAt(e,n,s){const r=this.findLineAt(e);if(!r)return null;const o=r.feature.geometry.coordinates,a=Yw(o),l=n==="delta"?s:n==="total"?s-a:a*s/100-a;if(n!=="delta"&&s<=0)throw new Error("Length must be greater than 0.");const h=d4(o,e,l);if(!h)throw new Error(`Cannot shorten by ${Math.abs(l).toFixed(3)} m: the line is only ${a.toFixed(3)} m long.`);return this.dataSource.updateFeature(r.layerId,{...r.feature,geometry:{type:"LineString",coordinates:h}}),this.dataSource.getFeature(r.layerId,r.feature.id)}offsetAt(e,n,s){const r=this.findFeatureAt(e);if(!r)throw new Error("No line or polygon under the pick point.");const{layerId:o,feature:a}=r,l=a.geometry;let h;if(l.type==="LineString"){const p=l.coordinates,y=Fr(p,n),_={convention:"cad",ucsRotationDeg:0},E=Qe(p[y.segmentIndex],p[y.segmentIndex+1],_).angle,w=Qe(y.coordinate,n,_),L=s==="through"?w.distance:Math.abs(s),b=((w.angle-E)%360+360)%360;h=b>0&&b<180?-L:L}else{const p=l.coordinates,y=Math.min(...p.map(E=>Qe(Fr(E,n).coordinate,n).distance)),_=s==="through"?y:Math.abs(s);h=Ht(n,a)?-_:_}if(!(Math.abs(h)>0))throw new Error("Offset distance must be greater than 0.");const f=ue.offset(a,h);if(!f)throw new Error(`Offset of ${Math.abs(h).toFixed(3)} m collapses the shape.`);f.id=this.dataSource.getAvailableFeatureId(o,`${a.id}_offset`),f.properties={...a.properties||{}};const d=this.dataSource.addFeature(o,f);return{layerId:o,source:a,result:d}}replaceLineWithPieces(e,n,s,r){const o=[];return this.dataSource.runTransaction(r,()=>{if(s.length===0){this.dataSource.removeFeature(e,n.id);return}this.dataSource.updateFeature(e,{...n,geometry:{type:"LineString",coordinates:s[0]}}),o.push(this.dataSource.getFeature(e,n.id)),s.slice(1).forEach(a=>{o.push(this.dataSource.addFeature(e,{type:"Feature",id:this.dataSource.getAvailableFeatureId(e,`${n.id}_seg`),properties:{...n.properties||{}},geometry:{type:"LineString",coordinates:a}}))})}),{layerId:e,featureId:n.id,pieces:o}}safeRawMap(){try{return this.mapAdapter.getRawMap()}catch{return null}}boundarySegments(e,n){const s=[];for(const r of this.dataSource.getAllLayers().filter(o=>o.visible)){const o=n?r.queryBBox(n):r.getFeatures();for(const a of o)e&&r.id===e.layerId&&a.id===e.featureId||a.geometry&&s.push(...zw(a.geometry))}return s}trimLineAt(e){const n=this.findLineAt(e);if(!n)return null;const{layerId:s,feature:r}=n,o=r.geometry.coordinates,a=De(r),l=u4(o,this.boundarySegments({layerId:s,featureId:r.id},a),e);return l?this.replaceLineWithPieces(s,r,l,`Trim line ${r.id}`):null}extendLineAt(e){const n=this.findLineAt(e);if(!n)return null;const{layerId:s,feature:r}=n,o=c4(r.geometry.coordinates,this.boundarySegments({layerId:s,featureId:r.id}),e);return o?(this.dataSource.updateFeature(s,{...r,geometry:{type:"LineString",coordinates:o}}),{layerId:s,feature:this.dataSource.getFeature(s,r.id)}):null}filletLinesAt(e,n,s){const r=this.findLineAt(e),o=this.findLineAt(n);if(!r||!o)throw new Error("Pick two lines.");if(r.layerId===o.layerId&&r.feature.id===o.feature.id)throw new Error("Pick two different lines.");const a=h4(r.feature.geometry.coordinates,e,o.feature.geometry.coordinates,n,s);if(!a)throw new Error(s>0?`Cannot fillet with radius ${s} m: the lines are parallel or too short for this radius.`:"Cannot fillet: the picked segments are parallel.");let l=null;return this.dataSource.runTransaction(`Fillet lines ${r.feature.id} and ${o.feature.id}`,()=>{this.dataSource.updateFeature(r.layerId,{...r.feature,geometry:{type:"LineString",coordinates:a.line1}}),this.dataSource.updateFeature(o.layerId,{...o.feature,geometry:{type:"LineString",coordinates:a.line2}}),a.arc&&(l=this.dataSource.addFeature(r.layerId,{type:"Feature",id:this.dataSource.getAvailableFeatureId(r.layerId,`${r.feature.id}_fillet`),properties:{name:`Fillet R${s}m`,shape:"arc",radiusMeters:s},geometry:{type:"LineString",coordinates:a.arc}}))}),{lines:[this.dataSource.getFeature(r.layerId,r.feature.id),this.dataSource.getFeature(o.layerId,o.feature.id)],arc:l}}stretch(e,n,s,r,o){const a=[Math.min(e[0],n[0]),Math.min(e[1],n[1]),Math.max(e[0],n[0]),Math.max(e[1],n[1])],l=o??this.dataSource.getAllLayers().filter(d=>d.visible).flatMap(d=>d.queryBBox(a).map(p=>({layerId:d.id,featureId:p.id}))),h=[];let f=0;return this.dataSource.runTransaction("Stretch",()=>{for(const{layerId:d,featureId:p}of l){const y=this.dataSource.getFeature(d,p);if(!(y!=null&&y.geometry))continue;const{geometry:_,moved:E}=Uw(y.geometry,a,s,r);E!==0&&(f+=E,this.dataSource.updateFeature(d,{...y,geometry:_}),h.push(this.dataSource.getFeature(d,p)))}}),{features:h,movedVertices:f}}deleteFeature(e,n){var s;return this.grips.getIsEditing()&&((s=this.grips.getActiveFeature())==null?void 0:s.id)===n&&this.grips.clear(),this.dataSource.removeFeature(e,n)}updateVertex(e,n,s,r,o=0){const a=this.dataSource.getFeature(e,n);if(!a)return!1;if(a.geometry.type==="Point"){const l=St(r,a.properties);return l.id=n,this.dataSource.updateFeature(e,l)}else if(a.geometry.type==="LineString"){const l=[...a.geometry.coordinates];if(s<0||s>=l.length)return!1;l[s]=r;const h=re(l,a.properties);return h.id=n,this.dataSource.updateFeature(e,h)}else if(a.geometry.type==="Polygon"){const l=a.geometry.coordinates.map(d=>[...d]);if(o<0||o>=l.length)return!1;const h=l[o];if(s<0||s>=h.length)return!1;h[s]=r,s===0&&(h[h.length-1]=r);const f=Ce(l,a.properties);return f.id=n,this.dataSource.updateFeature(e,f)}return!1}insertVertex(e,n,s,r,o=0){const a=this.dataSource.getFeature(e,n);if(!a)return!1;if(a.geometry.type==="LineString"){const l=[...a.geometry.coordinates],h=r!==void 0?Math.min(Math.max(0,r),l.length):l.length;l.splice(h,0,s);const f=re(l,a.properties);return f.id=n,this.dataSource.updateFeature(e,f)}else if(a.geometry.type==="Polygon"){const l=a.geometry.coordinates.map(p=>[...p]);if(o<0||o>=l.length)return!1;const h=l[o],f=r!==void 0?Math.min(Math.max(0,r),h.length-1):h.length-1;h.splice(f,0,s);const d=Ce(l,a.properties);return d.id=n,this.dataSource.updateFeature(e,d)}return!1}deleteVertex(e,n,s,r=0){var a;if(this.grips.getIsEditing()&&((a=this.grips.getActiveFeature())==null?void 0:a.id)===n)return this.grips.deleteVertex(s,r);const o=this.dataSource.getFeature(e,n);if(!o)return!1;if(o.geometry.type==="LineString"){const l=[...o.geometry.coordinates];if(l.length<=2||s<0||s>=l.length)return!1;l.splice(s,1);const h=re(l,o.properties);return h.id=n,this.dataSource.updateFeature(e,h)}else if(o.geometry.type==="Polygon"){const l=o.geometry.coordinates.map(d=>[...d]);if(r<0||r>=l.length)return!1;const h=l[r];if(h.length<=4||s<0||s>=h.length-1)return!1;h.splice(s,1),s===0&&(h[h.length-1]=h[0]);const f=Ce(l,o.properties);return f.id=n,this.dataSource.updateFeature(e,f)}return!1}simplifyFeature(e,n,s=1e-4){var a;const r=this.dataSource.getFeature(e,n);if(!r)return null;const o=ue.simplify(r,s);return o.id=n,this.dataSource.updateFeature(e,o),this.grips.getIsEditing()&&((a=this.grips.getActiveFeature())==null?void 0:a.id)===n&&this.grips.editFeature(e,n),o}smoothFeature(e,n,s=32){var a;const r=this.dataSource.getFeature(e,n);if(!r||r.geometry.type!=="LineString")return null;const o=ue.smoothLineBezier(r,s);return o.id=n,this.dataSource.updateFeature(e,o),this.grips.getIsEditing()&&((a=this.grips.getActiveFeature())==null?void 0:a.id)===n&&this.grips.editFeature(e,n),o}reverseLine(e,n){var o;const s=this.dataSource.getFeature(e,n);if(!s||s.geometry.type!=="LineString")return null;const r=ue.reverse(s);return r.id=n,this.dataSource.updateFeature(e,r),this.grips.getIsEditing()&&((o=this.grips.getActiveFeature())==null?void 0:o.id)===n&&this.grips.editFeature(e,n),r}differenceFeature(e,n,s){const r=this.dataSource.getFeature(e,n),o=this.dataSource.getFeature(e,s);if(!r||!o)return null;const a=ue.difference(r,o);return a?(a.id=n,this.dataSource.updateFeature(e,a),a):null}intersectFeatures(e,n,s){const r=this.dataSource.getFeature(e,n),o=this.dataSource.getFeature(e,s);if(!r||!o)return null;const a=ue.intersect(r,o);if(a){const l=this.dataSource.getAvailableFeatureId(e,"intersect");return a.id=l,this.dataSource.addFeature(e,a),a}return null}applyCursor(){if(typeof this.mapAdapter.getRawMap=="function")try{const e=this.mapAdapter.getRawMap();if(!e||typeof e.getCanvas!="function"||!e.getCanvas())return;const n=this.pointPick?"crosshair":this.currentMode?_4[this.currentMode]??"crosshair":"";e.getCanvas().style.cursor=n}catch(e){Qt("OFSDrawTools.applyCursor",e)}}getGuides(){return{...this.guides}}setGuides(e){return this.guides={...this.guides,...e},this.lastCursorCoord&&this.updateTempFeatures(this.lastCursorCoord,null),this.getGuides()}crosshairFeatures(e){if(!this.guides.crosshair||typeof this.mapAdapter.getBounds!="function")return[];let n;try{n=this.mapAdapter.getBounds()}catch(f){return Qt("OFSDrawTools.crosshair",f),[]}const[s,r,o,a]=n;if(![s,r,o,a].every(f=>Number.isFinite(f)))return[];const l=(o-s)*.1,h=(a-r)*.1;return[re([[s-l,e[1]],[o+l,e[1]]],{isGuide:!0}),re([[e[0],r-h],[e[0],a+h]],{isGuide:!0})]}formatLength(e){return e>=1e3?`${(e/1e3).toFixed(2)} km`:`${e.toFixed(e<10?2:1)} m`}projector(){const e=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;return e&&typeof e.project=="function"&&typeof e.unproject=="function"?e:null}dimensionFeatures(e,n,s){const r=nn(St(e),St(n),{units:"meters"});if(r<=0)return[];const o=this.formatLength(r),a=this.projector();if(!a)return[St([(e[0]+n[0])/2,(e[1]+n[1])/2],{isLabel:!0,isLive:s,label:o})];try{const l=a.project(e),h=a.project(n),f=h.x-l.x,d=h.y-l.y,p=Math.hypot(f,d);if(p<1)return[];const y=d/p,_=-f/p,E=this.guides.dimensionOffsetPixels,w=(P,N)=>{const S=a.unproject([P.x+y*N,P.y+_*N]);return[S.lng,S.lat]},L=w(l,E),b=w(h,E);return[re([e,w(l,E+6)],{isDimExt:!0}),re([n,w(h,E+6)],{isDimExt:!0}),re([L,b],{isDim:!0,isLive:s,label:o})]}catch(l){return Qt("OFSDrawTools.dimension",l),[St([(e[0]+n[0])/2,(e[1]+n[1])/2],{isLabel:!0,isLive:s,label:o})]}}angleFeatures(e,n,s,r){if(!this.guides.angles)return[];const o=this.projector();if(!o)return[];try{const a=o.project(n),l=o.project(e),h=o.project(s);if(Math.hypot(l.x-a.x,l.y-a.y)<4||Math.hypot(h.x-a.x,h.y-a.y)<4)return[];const f=Math.atan2(l.y-a.y,l.x-a.x);let p=Math.atan2(h.y-a.y,h.x-a.x)-f;for(;p>Math.PI;)p-=Math.PI*2;for(;p<=-Math.PI;)p+=Math.PI*2;const y=Math.abs(p*180/Math.PI);if(y<.05)return[];const _=30,E=18,w=[];for(let P=0;P<=E;P++){const N=f+p*P/E,S=o.unproject([a.x+Math.cos(N)*_,a.y+Math.sin(N)*_]);w.push([S.lng,S.lat])}const L=f+p/2,b=o.unproject([a.x+Math.cos(L)*(_+16),a.y+Math.sin(L)*(_+16)]);return[re(w,{isAngle:!0,isLive:r}),St([b.lng,b.lat],{isLabel:!0,isLive:r,label:`${y.toFixed(1)}°`})]}catch(a){return Qt("OFSDrawTools.angleGuide",a),[]}}measurementFeatures(e,n){const s=[];if(e.length<2)return s;const r=n&&e.length>=3?[...e,e[0]]:e,o=r.length-2;if(this.guides.dimensions)for(let a=0;a<r.length-1;a++)!this.guides.segmentLabels&&a!==o||s.push(...this.dimensionFeatures(r[a],r[a+1],a===o));for(let a=1;a<r.length-1;a++){const l=a===r.length-2;!this.guides.segmentLabels&&!l||s.push(...this.angleFeatures(r[a-1],r[a],r[a+1],l))}if(n&&r.length>=4&&this.guides.segmentLabels&&s.push(...this.angleFeatures(r[r.length-2],r[0],r[1],!1)),this.guides.areaLabel&&n&&e.length>=3){const a=Ce([[...e,e[0]]]),l=Tu(a);if(l>0){const h=ew(a).geometry.coordinates;s.push(St(h,{isLabel:!0,isLive:!0,label:`${l.toFixed(1)} m²`}))}}return s}updateTempFeatures(e,n){const s=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;if(!s||typeof s.getSource!="function")return;const r=s.getSource(this.tempSourceId);if(!r||typeof r.setData!="function")return;const o=[];if(n&&n.coordinate&&o.push(St(n.coordinate,{isSnap:!0,snapType:n.type})),this.isDrawing&&this.activeCoordinates.length>0){const a=[...this.activeCoordinates,e];if(this.activeCoordinates.forEach(h=>{o.push(St(h,{isSnap:!1}))}),n||o.push(St(e,{isSnap:!1})),this.currentMode==="line"&&a.length>=2)o.push(re(a));else if((this.currentMode==="polygon"||this.currentMode==="select-polygon")&&a.length>=2)o.push(re(a)),a.length>=3&&o.push(Ce([[...a,a[0]]]));else if(this.currentMode==="circle"&&a.length>=2){const h=nn(St(a[0]),St(e),{units:"meters"});o.push(Q1(a[0],h,{units:"meters"}))}else if((this.currentMode==="rectangle"||this.currentMode==="select-box")&&a.length>=2){const h=a[0],f=e,d=Math.min(h[0],f[0]),p=Math.max(h[0],f[0]),y=Math.min(h[1],f[1]),_=Math.max(h[1],f[1]);o.push(Ce([[[d,y],[p,y],[p,_],[d,_],[d,y]]]))}o.push(...this.trackingFeatures(e));const l=this.currentMode==="polygon"||this.currentMode==="select-polygon";if(this.currentMode!=="circle"&&this.currentMode!=="rectangle"&&this.currentMode!=="select-box")o.push(...this.measurementFeatures(a,l));else if(this.currentMode==="circle"){const h=nn(St(a[0]),St(e),{units:"meters"});this.guides.dimensions&&h>0&&o.push(St([(a[0][0]+e[0])/2,(a[0][1]+e[1])/2],{isLabel:!0,isLive:!0,label:`r ${this.formatLength(h)}`}))}else{const h=[a[0],[e[0],a[0][1]],e,[a[0][0],e[1]]];o.push(...this.measurementFeatures(h,!0))}o.push(...this.crosshairFeatures(this.guides.anchor==="vertex"?this.activeCoordinates[this.activeCoordinates.length-1]:e))}else this.currentMode==="point"&&o.push(St(e,{isSnap:!1})),o.push(...this.trackingFeatures(e)),o.push(...this.crosshairFeatures(e));r.setData({type:"FeatureCollection",features:o})}updateDragBoxPreview(e,n){const s=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;if(!s||typeof s.getSource!="function")return;const r=s.getSource(this.tempSourceId);if(!r||typeof r.setData!="function")return;const o=Math.min(e[0],n[0]),a=Math.max(e[0],n[0]),l=Math.min(e[1],n[1]),h=Math.max(e[1],n[1]),f=Ce([[[o,l],[a,l],[a,h],[o,h],[o,l]]]);r.setData({type:"FeatureCollection",features:[f]})}queryFeaturesInGeometry(e){const n=[],s=this.dataSource.getAllLayers().filter(r=>r.visible);for(const r of s)if(!(this.targetLayerId&&r.id!==this.targetLayerId))for(const o of Ro.queryGeometry(r,e))o.id!==void 0&&n.push({layerId:r.id,feature:o});return n}executeDrawSelection(e,n,s=!1){const r=this.queryFeaturesInGeometry(n);s||this.dataSource.clearSelection();const o=new Map;for(const a of r)if(a.feature.id!==void 0){const l=o.get(a.layerId)||[];l.push(a.feature.id),o.set(a.layerId,l)}for(const[a,l]of o.entries())this.dataSource.selectFeatures(a,l,!0);this.dataSource.getSelectedCount()===1&&r.length===1?this.grips.editFeature(r[0].layerId,r[0].feature.id):this.grips.clear(),this.selectionOverlay.syncSelectionOverlay(),this.emit("selection:draw-complete",{mode:e,selectionPolygon:n,selectedFeatures:r.map(a=>a.feature),count:r.length})}flashFeatures(e,n=750){this.selectionOverlay.flashFeatures(e,n)}clearTempFeatures(){if(this.mapAdapter.isReady)try{const e=typeof this.mapAdapter.getRawMap=="function"?this.mapAdapter.getRawMap():null;if(!e||typeof e.getSource!="function")return;const n=e.getSource(this.tempSourceId);n&&typeof n.setData=="function"&&n.setData({type:"FeatureCollection",features:[]})}catch(e){Qt("OFSDrawTools.clearTempFeatures",e)}}destroy(){this.unsubClick&&this.unsubClick(),this.unsubDblClick&&this.unsubDblClick(),this.unsubContextMenu&&this.unsubContextMenu(),this.unsubMove&&this.unsubMove(),this.unsubMouseDown&&this.unsubMouseDown(),this.unsubMouseUp&&this.unsubMouseUp(),typeof window<"u"&&window.removeEventListener("keydown",this.handleKeyDown),this.cancel(),this.grips.clear(),this.selectionOverlay.destroy(),this.removeAllListeners()}}const{min:v4,max:E4}=Math,No=(i,t=0,e=1)=>v4(E4(t,i),e),Np=i=>{i._clipped=!1,i._unclipped=i.slice(0);for(let t=0;t<=3;t++)t<3?((i[t]<0||i[t]>255)&&(i._clipped=!0),i[t]=No(i[t],0,255)):t===3&&(i[t]=No(i[t],0,1));return i},Vw={};for(let i of["Boolean","Number","String","Function","Array","Date","RegExp","Undefined","Null"])Vw[`[object ${i}]`]=i.toLowerCase();function se(i){return Vw[Object.prototype.toString.call(i)]||"object"}const Jt=(i,t=null)=>i.length>=3?Array.prototype.slice.call(i):se(i[0])=="object"&&t?t.split("").filter(e=>i[0][e]!==void 0).map(e=>i[0][e]):i[0].slice(0),wl=i=>{if(i.length<2)return null;const t=i.length-1;return se(i[t])=="string"?i[t].toLowerCase():null},{PI:ad,min:Hw,max:Ww}=Math,es=i=>Math.round(i*100)/100,lm=i=>Math.round(i*100)/100,ar=ad*2,fg=ad/3,w4=ad/180,x4=180/ad;function Kw(i){return[...i.slice(0,3).reverse(),...i.slice(3)]}const Kt={format:{},autodetect:[]};class xt{constructor(...t){const e=this;if(se(t[0])==="object"&&t[0].constructor&&t[0].constructor===this.constructor)return t[0];let n=wl(t),s=!1;if(!n){s=!0,Kt.sorted||(Kt.autodetect=Kt.autodetect.sort((r,o)=>o.p-r.p),Kt.sorted=!0);for(let r of Kt.autodetect)if(n=r.test(...t),n)break}if(Kt.format[n]){const r=Kt.format[n].apply(null,s?t:t.slice(0,-1));e._rgb=Np(r)}else throw new Error("unknown format: "+t);e._rgb.length===3&&e._rgb.push(1)}toString(){return se(this.hex)=="function"?this.hex():`[${this._rgb.join(",")}]`}}const b4="3.2.0",ee=(...i)=>new xt(...i);ee.version=b4;const cl={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",laserlemon:"#ffff54",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrod:"#fafad2",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",maroon2:"#7f0000",maroon3:"#b03060",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",purple2:"#7f007f",purple3:"#a020f0",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"},I4=/^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,S4=/^#?([A-Fa-f0-9]{8}|[A-Fa-f0-9]{4})$/,Zw=i=>{if(i.match(I4)){(i.length===4||i.length===7)&&(i=i.substr(1)),i.length===3&&(i=i.split(""),i=i[0]+i[0]+i[1]+i[1]+i[2]+i[2]);const t=parseInt(i,16),e=t>>16,n=t>>8&255,s=t&255;return[e,n,s,1]}if(i.match(S4)){(i.length===5||i.length===9)&&(i=i.substr(1)),i.length===4&&(i=i.split(""),i=i[0]+i[0]+i[1]+i[1]+i[2]+i[2]+i[3]+i[3]);const t=parseInt(i,16),e=t>>24&255,n=t>>16&255,s=t>>8&255,r=Math.round((t&255)/255*100)/100;return[e,n,s,r]}throw new Error(`unknown hex color: ${i}`)},{round:rh}=Math,Jw=(...i)=>{let[t,e,n,s]=Jt(i,"rgba"),r=wl(i)||"auto";s===void 0&&(s=1),r==="auto"&&(r=s<1?"rgba":"rgb"),t=rh(t),e=rh(e),n=rh(n);let a="000000"+(t<<16|e<<8|n).toString(16);a=a.substr(a.length-6);let l="0"+rh(s*255).toString(16);switch(l=l.substr(l.length-2),r.toLowerCase()){case"rgba":return`#${a}${l}`;case"argb":return`#${l}${a}`;default:return`#${a}`}};xt.prototype.name=function(){const i=Jw(this._rgb,"rgb");for(let t of Object.keys(cl))if(cl[t]===i)return t.toLowerCase();return i};Kt.format.named=i=>{if(i=i.toLowerCase(),cl[i])return Zw(cl[i]);throw new Error("unknown color name: "+i)};Kt.autodetect.push({p:5,test:(i,...t)=>{if(!t.length&&se(i)==="string"&&cl[i.toLowerCase()])return"named"}});xt.prototype.alpha=function(i,t=!1){return i!==void 0&&se(i)==="number"?t?(this._rgb[3]=i,this):new xt([this._rgb[0],this._rgb[1],this._rgb[2],i],"rgb"):this._rgb[3]};xt.prototype.clipped=function(){return this._rgb._clipped||!1};const Ws={Kn:18,labWhitePoint:"d65",Xn:.95047,Yn:1,Zn:1.08883,kE:216/24389,kKE:8,kK:24389/27,RefWhiteRGB:{X:.95047,Y:1,Z:1.08883},MtxRGB2XYZ:{m00:.4124564390896922,m01:.21267285140562253,m02:.0193338955823293,m10:.357576077643909,m11:.715152155287818,m12:.11919202588130297,m20:.18043748326639894,m21:.07217499330655958,m22:.9503040785363679},MtxXYZ2RGB:{m00:3.2404541621141045,m01:-.9692660305051868,m02:.055643430959114726,m10:-1.5371385127977166,m11:1.8760108454466942,m12:-.2040259135167538,m20:-.498531409556016,m21:.041556017530349834,m22:1.0572251882231791},As:.9414285350000001,Bs:1.040417467,Cs:1.089532651,MtxAdaptMa:{m00:.8951,m01:-.7502,m02:.0389,m10:.2664,m11:1.7135,m12:-.0685,m20:-.1614,m21:.0367,m22:1.0296},MtxAdaptMaI:{m00:.9869929054667123,m01:.43230526972339456,m02:-.008528664575177328,m10:-.14705425642099013,m11:.5183602715367776,m12:.04004282165408487,m20:.15996265166373125,m21:.0492912282128556,m22:.9684866957875502}},M4=new Map([["a",[1.0985,.35585]],["b",[1.0985,.35585]],["c",[.98074,1.18232]],["d50",[.96422,.82521]],["d55",[.95682,.92149]],["d65",[.95047,1.08883]],["e",[1,1,1]],["f2",[.99186,.67393]],["f7",[.95041,1.08747]],["f11",[1.00962,.6435]],["icc",[.96422,.82521]]]);function cr(i){const t=M4.get(String(i).toLowerCase());if(!t)throw new Error("unknown Lab illuminant "+i);Ws.labWhitePoint=i,Ws.Xn=t[0],Ws.Zn=t[1]}function Xu(){return Ws.labWhitePoint}const Lp=(...i)=>{i=Jt(i,"lab");const[t,e,n]=i,[s,r,o]=N4(t,e,n),[a,l,h]=Qw(s,r,o);return[a,l,h,i.length>3?i[3]:1]},N4=(i,t,e)=>{const{kE:n,kK:s,kKE:r,Xn:o,Yn:a,Zn:l}=Ws,h=(i+16)/116,f=.002*t+h,d=h-.005*e,p=f*f*f,y=d*d*d,_=p>n?p:(116*f-16)/s,E=i>r?Math.pow((i+16)/116,3):i/s,w=y>n?y:(116*d-16)/s,L=_*o,b=E*a,P=w*l;return[L,b,P]},dg=i=>{const t=Math.sign(i);return i=Math.abs(i),(i<=.0031308?i*12.92:1.055*Math.pow(i,1/2.4)-.055)*t},Qw=(i,t,e)=>{const{MtxAdaptMa:n,MtxAdaptMaI:s,MtxXYZ2RGB:r,RefWhiteRGB:o,Xn:a,Yn:l,Zn:h}=Ws,f=a*n.m00+l*n.m10+h*n.m20,d=a*n.m01+l*n.m11+h*n.m21,p=a*n.m02+l*n.m12+h*n.m22,y=o.X*n.m00+o.Y*n.m10+o.Z*n.m20,_=o.X*n.m01+o.Y*n.m11+o.Z*n.m21,E=o.X*n.m02+o.Y*n.m12+o.Z*n.m22,w=(i*n.m00+t*n.m10+e*n.m20)*(y/f),L=(i*n.m01+t*n.m11+e*n.m21)*(_/d),b=(i*n.m02+t*n.m12+e*n.m22)*(E/p),P=w*s.m00+L*s.m10+b*s.m20,N=w*s.m01+L*s.m11+b*s.m21,S=w*s.m02+L*s.m12+b*s.m22,C=dg(P*r.m00+N*r.m10+S*r.m20),T=dg(P*r.m01+N*r.m11+S*r.m21),I=dg(P*r.m02+N*r.m12+S*r.m22);return[C*255,T*255,I*255]},Cp=(...i)=>{const[t,e,n,...s]=Jt(i,"rgb"),[r,o,a]=tx(t,e,n),[l,h,f]=L4(r,o,a);return[l,h,f,...s.length>0&&s[0]<1?[s[0]]:[]]};function L4(i,t,e){const{Xn:n,Yn:s,Zn:r,kE:o,kK:a}=Ws,l=i/n,h=t/s,f=e/r,d=l>o?Math.pow(l,1/3):(a*l+16)/116,p=h>o?Math.pow(h,1/3):(a*h+16)/116,y=f>o?Math.pow(f,1/3):(a*f+16)/116;return[116*p-16,500*(d-p),200*(p-y)]}function gg(i){const t=Math.sign(i);return i=Math.abs(i),(i<=.04045?i/12.92:Math.pow((i+.055)/1.055,2.4))*t}const tx=(i,t,e)=>{i=gg(i/255),t=gg(t/255),e=gg(e/255);const{MtxRGB2XYZ:n,MtxAdaptMa:s,MtxAdaptMaI:r,Xn:o,Yn:a,Zn:l,As:h,Bs:f,Cs:d}=Ws;let p=i*n.m00+t*n.m10+e*n.m20,y=i*n.m01+t*n.m11+e*n.m21,_=i*n.m02+t*n.m12+e*n.m22;const E=o*s.m00+a*s.m10+l*s.m20,w=o*s.m01+a*s.m11+l*s.m21,L=o*s.m02+a*s.m12+l*s.m22;let b=p*s.m00+y*s.m10+_*s.m20,P=p*s.m01+y*s.m11+_*s.m21,N=p*s.m02+y*s.m12+_*s.m22;return b*=E/h,P*=w/f,N*=L/d,p=b*r.m00+P*r.m10+N*r.m20,y=b*r.m01+P*r.m11+N*r.m21,_=b*r.m02+P*r.m12+N*r.m22,[p,y,_]};xt.prototype.lab=function(){return Cp(this._rgb)};const C4=(...i)=>new xt(...i,"lab");Object.assign(ee,{lab:C4,getLabWhitePoint:Xu,setLabWhitePoint:cr});Kt.format.lab=Lp;Kt.autodetect.push({p:2,test:(...i)=>{if(i=Jt(i,"lab"),se(i)==="array"&&i.length===3)return"lab"}});xt.prototype.darken=function(i=1){const t=this,e=t.lab();return e[0]-=Ws.Kn*i,new xt(e,"lab").alpha(t.alpha(),!0)};xt.prototype.brighten=function(i=1){return this.darken(-i)};xt.prototype.darker=xt.prototype.darken;xt.prototype.brighter=xt.prototype.brighten;xt.prototype.get=function(i){const[t,e]=i.split("."),n=this[t]();if(e){const s=t.indexOf(e)-(t.substr(0,2)==="ok"?2:0);if(s>-1)return n[s];throw new Error(`unknown channel ${e} in mode ${t}`)}else return n};const{pow:P4}=Math,k4=1e-7,T4=20;xt.prototype.luminance=function(i,t="rgb"){if(i!==void 0&&se(i)==="number"){if(i===0)return new xt([0,0,0,this._rgb[3]],"rgb");if(i===1)return new xt([255,255,255,this._rgb[3]],"rgb");let e=this.luminance(),n=T4;const s=(o,a)=>{const l=o.interpolate(a,.5,t),h=l.luminance();return Math.abs(i-h)<k4||!n--?l:h>i?s(o,l):s(l,a)},r=(e>i?s(new xt([0,0,0]),this):s(this,new xt([255,255,255]))).rgb();return new xt([...r,this._rgb[3]])}return R4(...this._rgb.slice(0,3))};const R4=(i,t,e)=>(i=mg(i),t=mg(t),e=mg(e),.2126*i+.7152*t+.0722*e),mg=i=>(i/=255,i<=.03928?i/12.92:P4((i+.055)/1.055,2.4)),Dn={},hl=(i,t,e=.5,...n)=>{let s=n[0]||"lrgb";if(!Dn[s]&&!n.length&&(s=Object.keys(Dn)[0]),!Dn[s])throw new Error(`interpolation mode ${s} is not defined`);return se(i)!=="object"&&(i=new xt(i)),se(t)!=="object"&&(t=new xt(t)),Dn[s](i,t,e).alpha(i.alpha()+e*(t.alpha()-i.alpha()))};xt.prototype.mix=xt.prototype.interpolate=function(i,t=.5,...e){return hl(this,i,t,...e)};xt.prototype.premultiply=function(i=!1){const t=this._rgb,e=t[3];return i?(this._rgb=[t[0]*e,t[1]*e,t[2]*e,e],this):new xt([t[0]*e,t[1]*e,t[2]*e,e],"rgb")};const{sin:A4,cos:O4}=Math,ex=(...i)=>{let[t,e,n]=Jt(i,"lch");return isNaN(n)&&(n=0),n=n*w4,[t,O4(n)*e,A4(n)*e]},Pp=(...i)=>{i=Jt(i,"lch");const[t,e,n]=i,[s,r,o]=ex(t,e,n),[a,l,h]=Lp(s,r,o);return[a,l,h,i.length>3?i[3]:1]},F4=(...i)=>{const t=Kw(Jt(i,"hcl"));return Pp(...t)},{sqrt:$4,atan2:D4,round:G4}=Math,nx=(...i)=>{const[t,e,n]=Jt(i,"lab"),s=$4(e*e+n*n);let r=(D4(n,e)*x4+360)%360;return G4(s*1e4)===0&&(r=Number.NaN),[t,s,r]},kp=(...i)=>{const[t,e,n,...s]=Jt(i,"rgb"),[r,o,a]=Cp(t,e,n),[l,h,f]=nx(r,o,a);return[l,h,f,...s.length>0&&s[0]<1?[s[0]]:[]]};xt.prototype.lch=function(){return kp(this._rgb)};xt.prototype.hcl=function(){return Kw(kp(this._rgb))};const B4=(...i)=>new xt(...i,"lch"),q4=(...i)=>new xt(...i,"hcl");Object.assign(ee,{lch:B4,hcl:q4});Kt.format.lch=Pp;Kt.format.hcl=F4;["lch","hcl"].forEach(i=>Kt.autodetect.push({p:2,test:(...t)=>{if(t=Jt(t,i),se(t)==="array"&&t.length===3)return i}}));xt.prototype.saturate=function(i=1){const t=this,e=t.lch();return e[1]+=Ws.Kn*i,e[1]<0&&(e[1]=0),new xt(e,"lch").alpha(t.alpha(),!0)};xt.prototype.desaturate=function(i=1){return this.saturate(-i)};xt.prototype.set=function(i,t,e=!1){const[n,s]=i.split("."),r=this[n]();if(s){const o=n.indexOf(s)-(n.substr(0,2)==="ok"?2:0);if(o>-1){if(se(t)=="string")switch(t.charAt(0)){case"+":r[o]+=+t;break;case"-":r[o]+=+t;break;case"*":r[o]*=+t.substr(1);break;case"/":r[o]/=+t.substr(1);break;default:r[o]=+t}else if(se(t)==="number")r[o]=t;else throw new Error("unsupported value for Color.set");const a=new xt(r,n);return e?(this._rgb=a._rgb,this):a}throw new Error(`unknown channel ${s} in mode ${n}`)}else return r};xt.prototype.tint=function(i=.5,...t){return hl(this,"white",i,...t)};xt.prototype.shade=function(i=.5,...t){return hl(this,"black",i,...t)};const z4=(i,t,e)=>{const n=i._rgb,s=t._rgb;return new xt(n[0]+e*(s[0]-n[0]),n[1]+e*(s[1]-n[1]),n[2]+e*(s[2]-n[2]),"rgb")};Dn.rgb=z4;const{sqrt:pg,pow:ia}=Math,U4=(i,t,e)=>{const[n,s,r]=i._rgb,[o,a,l]=t._rgb;return new xt(pg(ia(n,2)*(1-e)+ia(o,2)*e),pg(ia(s,2)*(1-e)+ia(a,2)*e),pg(ia(r,2)*(1-e)+ia(l,2)*e),"rgb")};Dn.lrgb=U4;const Y4=(i,t,e)=>{const n=i.lab(),s=t.lab();return new xt(n[0]+e*(s[0]-n[0]),n[1]+e*(s[1]-n[1]),n[2]+e*(s[2]-n[2]),"lab")};Dn.lab=Y4;const xl=(i,t,e,n)=>{let s,r;n==="hsl"?(s=i.hsl(),r=t.hsl()):n==="hsv"?(s=i.hsv(),r=t.hsv()):n==="hcg"?(s=i.hcg(),r=t.hcg()):n==="hsi"?(s=i.hsi(),r=t.hsi()):n==="lch"||n==="hcl"?(n="hcl",s=i.hcl(),r=t.hcl()):n==="oklch"&&(s=i.oklch().reverse(),r=t.oklch().reverse());let o,a,l,h,f,d;(n.substr(0,1)==="h"||n==="oklch")&&([o,l,f]=s,[a,h,d]=r);let p,y,_,E;return!isNaN(o)&&!isNaN(a)?(a>o&&a-o>180?E=a-(o+360):a<o&&o-a>180?E=a+360-o:E=a-o,y=o+e*E):isNaN(o)?isNaN(a)?y=Number.NaN:(y=a,(f==1||f==0)&&n!="hsv"&&(p=h)):(y=o,(d==1||d==0)&&n!="hsv"&&(p=l)),p===void 0&&(p=l+e*(h-l)),_=f+e*(d-f),n==="oklch"?new xt([_,p,y],n):new xt([y,p,_],n)},ix=(i,t,e)=>xl(i,t,e,"lch");Dn.lch=ix;Dn.hcl=ix;const X4=i=>{if(se(i)=="number"&&i>=0&&i<=16777215){const t=i>>16,e=i>>8&255,n=i&255;return[t,e,n,1]}throw new Error("unknown num color: "+i)},j4=(...i)=>{const[t,e,n]=Jt(i,"rgb");return(t<<16)+(e<<8)+n};xt.prototype.num=function(){return j4(this._rgb)};const V4=(...i)=>new xt(...i,"num");Object.assign(ee,{num:V4});Kt.format.num=X4;Kt.autodetect.push({p:5,test:(...i)=>{if(i.length===1&&se(i[0])==="number"&&i[0]>=0&&i[0]<=16777215)return"num"}});const H4=(i,t,e)=>{const n=i.num(),s=t.num();return new xt(n+e*(s-n),"num")};Dn.num=H4;const{floor:W4}=Math,K4=(...i)=>{i=Jt(i,"hcg");let[t,e,n]=i,s,r,o;n=n*255;const a=e*255;if(e===0)s=r=o=n;else{t===360&&(t=0),t>360&&(t-=360),t<0&&(t+=360),t/=60;const l=W4(t),h=t-l,f=n*(1-e),d=f+a*(1-h),p=f+a*h,y=f+a;switch(l){case 0:[s,r,o]=[y,p,f];break;case 1:[s,r,o]=[d,y,f];break;case 2:[s,r,o]=[f,y,p];break;case 3:[s,r,o]=[f,d,y];break;case 4:[s,r,o]=[p,f,y];break;case 5:[s,r,o]=[y,f,d];break}}return[s,r,o,i.length>3?i[3]:1]},Z4=(...i)=>{const[t,e,n]=Jt(i,"rgb"),s=Hw(t,e,n),r=Ww(t,e,n),o=r-s,a=o*100/255,l=s/(255-o)*100;let h;return o===0?h=Number.NaN:(t===r&&(h=(e-n)/o),e===r&&(h=2+(n-t)/o),n===r&&(h=4+(t-e)/o),h*=60,h<0&&(h+=360)),[h,a,l]};xt.prototype.hcg=function(){return Z4(this._rgb)};const J4=(...i)=>new xt(...i,"hcg");ee.hcg=J4;Kt.format.hcg=K4;Kt.autodetect.push({p:1,test:(...i)=>{if(i=Jt(i,"hcg"),se(i)==="array"&&i.length===3)return"hcg"}});const Q4=(i,t,e)=>xl(i,t,e,"hcg");Dn.hcg=Q4;const{cos:sa}=Math,t3=(...i)=>{i=Jt(i,"hsi");let[t,e,n]=i,s,r,o;return isNaN(t)&&(t=0),isNaN(e)&&(e=0),t>360&&(t-=360),t<0&&(t+=360),t/=360,t<1/3?(o=(1-e)/3,s=(1+e*sa(ar*t)/sa(fg-ar*t))/3,r=1-(o+s)):t<2/3?(t-=1/3,s=(1-e)/3,r=(1+e*sa(ar*t)/sa(fg-ar*t))/3,o=1-(s+r)):(t-=2/3,r=(1-e)/3,o=(1+e*sa(ar*t)/sa(fg-ar*t))/3,s=1-(r+o)),s=No(n*s*3),r=No(n*r*3),o=No(n*o*3),[s*255,r*255,o*255,i.length>3?i[3]:1]},{min:e3,sqrt:n3,acos:i3}=Math,s3=(...i)=>{let[t,e,n]=Jt(i,"rgb");t/=255,e/=255,n/=255;let s;const r=e3(t,e,n),o=(t+e+n)/3,a=o>0?1-r/o:0;return a===0?s=NaN:(s=(t-e+(t-n))/2,s/=n3((t-e)*(t-e)+(t-n)*(e-n)),s=i3(s),n>e&&(s=ar-s),s/=ar),[s*360,a,o]};xt.prototype.hsi=function(){return s3(this._rgb)};const r3=(...i)=>new xt(...i,"hsi");ee.hsi=r3;Kt.format.hsi=t3;Kt.autodetect.push({p:2,test:(...i)=>{if(i=Jt(i,"hsi"),se(i)==="array"&&i.length===3)return"hsi"}});const o3=(i,t,e)=>xl(i,t,e,"hsi");Dn.hsi=o3;const um=(...i)=>{i=Jt(i,"hsl");const[t,e,n]=i;let s,r,o;if(e===0)s=r=o=n*255;else{const a=[0,0,0],l=[0,0,0],h=n<.5?n*(1+e):n+e-n*e,f=2*n-h,d=t/360;a[0]=d+1/3,a[1]=d,a[2]=d-1/3;for(let p=0;p<3;p++)a[p]<0&&(a[p]+=1),a[p]>1&&(a[p]-=1),6*a[p]<1?l[p]=f+(h-f)*6*a[p]:2*a[p]<1?l[p]=h:3*a[p]<2?l[p]=f+(h-f)*(2/3-a[p])*6:l[p]=f;[s,r,o]=[l[0]*255,l[1]*255,l[2]*255]}return i.length>3?[s,r,o,i[3]]:[s,r,o,1]},sx=(...i)=>{i=Jt(i,"rgba");let[t,e,n]=i;t/=255,e/=255,n/=255;const s=Hw(t,e,n),r=Ww(t,e,n),o=(r+s)/2;let a,l;return r===s?(a=0,l=Number.NaN):a=o<.5?(r-s)/(r+s):(r-s)/(2-r-s),t==r?l=(e-n)/(r-s):e==r?l=2+(n-t)/(r-s):n==r&&(l=4+(t-e)/(r-s)),l*=60,l<0&&(l+=360),i.length>3&&i[3]!==void 0?[l,a,o,i[3]]:[l,a,o]};xt.prototype.hsl=function(){return sx(this._rgb)};const a3=(...i)=>new xt(...i,"hsl");ee.hsl=a3;Kt.format.hsl=um;Kt.autodetect.push({p:2,test:(...i)=>{if(i=Jt(i,"hsl"),se(i)==="array"&&i.length===3)return"hsl"}});const l3=(i,t,e)=>xl(i,t,e,"hsl");Dn.hsl=l3;const{floor:u3}=Math,c3=(...i)=>{i=Jt(i,"hsv");let[t,e,n]=i,s,r,o;if(n*=255,e===0)s=r=o=n;else{t===360&&(t=0),t>360&&(t-=360),t<0&&(t+=360),t/=60;const a=u3(t),l=t-a,h=n*(1-e),f=n*(1-e*l),d=n*(1-e*(1-l));switch(a){case 0:[s,r,o]=[n,d,h];break;case 1:[s,r,o]=[f,n,h];break;case 2:[s,r,o]=[h,n,d];break;case 3:[s,r,o]=[h,f,n];break;case 4:[s,r,o]=[d,h,n];break;case 5:[s,r,o]=[n,h,f];break}}return[s,r,o,i.length>3?i[3]:1]},{min:h3,max:f3}=Math,d3=(...i)=>{i=Jt(i,"rgb");let[t,e,n]=i;const s=h3(t,e,n),r=f3(t,e,n),o=r-s;let a,l,h;return h=r/255,r===0?(a=Number.NaN,l=0):(l=o/r,t===r&&(a=(e-n)/o),e===r&&(a=2+(n-t)/o),n===r&&(a=4+(t-e)/o),a*=60,a<0&&(a+=360)),[a,l,h]};xt.prototype.hsv=function(){return d3(this._rgb)};const g3=(...i)=>new xt(...i,"hsv");ee.hsv=g3;Kt.format.hsv=c3;Kt.autodetect.push({p:2,test:(...i)=>{if(i=Jt(i,"hsv"),se(i)==="array"&&i.length===3)return"hsv"}});const m3=(i,t,e)=>xl(i,t,e,"hsv");Dn.hsv=m3;function vf(i,t){let e=i.length;Array.isArray(i[0])||(i=[i]),Array.isArray(t[0])||(t=t.map(o=>[o]));let n=t[0].length,s=t[0].map((o,a)=>t.map(l=>l[a])),r=i.map(o=>s.map(a=>Array.isArray(o)?o.reduce((l,h,f)=>l+h*(a[f]||0),0):a.reduce((l,h)=>l+h*o,0)));return e===1&&(r=r[0]),n===1?r.map(o=>o[0]):r}const Tp=(...i)=>{i=Jt(i,"lab");const[t,e,n,...s]=i,[r,o,a]=p3([t,e,n]),[l,h,f]=Qw(r,o,a);return[l,h,f,...s.length>0&&s[0]<1?[s[0]]:[]]};function p3(i){var t=[[1.2268798758459243,-.5578149944602171,.2813910456659647],[-.0405757452148008,1.112286803280317,-.0717110580655164],[-.0763729366746601,-.4214933324022432,1.5869240198367816]],e=[[1,.3963377773761749,.2158037573099136],[1,-.1055613458156586,-.0638541728258133],[1,-.0894841775298119,-1.2914855480194092]],n=vf(e,i);return vf(t,n.map(s=>s**3))}const Rp=(...i)=>{const[t,e,n,...s]=Jt(i,"rgb"),r=tx(t,e,n);return[...y3(r),...s.length>0&&s[0]<1?[s[0]]:[]]};function y3(i){const t=[[.819022437996703,.3619062600528904,-.1288737815209879],[.0329836539323885,.9292868615863434,.0361446663506424],[.0481771893596242,.2642395317527308,.6335478284694309]],e=[[.210454268309314,.7936177747023054,-.0040720430116193],[1.9779985324311684,-2.42859224204858,.450593709617411],[.0259040424655478,.7827717124575296,-.8086757549230774]],n=vf(t,i);return vf(e,n.map(s=>Math.cbrt(s)))}xt.prototype.oklab=function(){return Rp(this._rgb)};const _3=(...i)=>new xt(...i,"oklab");Object.assign(ee,{oklab:_3});Kt.format.oklab=Tp;Kt.autodetect.push({p:2,test:(...i)=>{if(i=Jt(i,"oklab"),se(i)==="array"&&i.length===3)return"oklab"}});const v3=(i,t,e)=>{const n=i.oklab(),s=t.oklab();return new xt(n[0]+e*(s[0]-n[0]),n[1]+e*(s[1]-n[1]),n[2]+e*(s[2]-n[2]),"oklab")};Dn.oklab=v3;const E3=(i,t,e)=>xl(i,t,e,"oklch");Dn.oklch=E3;const{pow:yg,sqrt:_g,PI:vg,cos:M_,sin:N_,atan2:w3}=Math,x3=(i,t="lrgb",e=null)=>{const n=i.length;e||(e=Array.from(new Array(n)).map(()=>1));const s=n/e.reduce(function(d,p){return d+p});if(e.forEach((d,p)=>{e[p]*=s}),i=i.map(d=>new xt(d)),t==="lrgb")return b3(i,e);const r=i.shift(),o=r.get(t),a=[];let l=0,h=0;for(let d=0;d<o.length;d++)if(o[d]=(o[d]||0)*e[0],a.push(isNaN(o[d])?0:e[0]),t.charAt(d)==="h"&&!isNaN(o[d])){const p=o[d]/180*vg;l+=M_(p)*e[0],h+=N_(p)*e[0]}let f=r.alpha()*e[0];i.forEach((d,p)=>{const y=d.get(t);f+=d.alpha()*e[p+1];for(let _=0;_<o.length;_++)if(!isNaN(y[_]))if(a[_]+=e[p+1],t.charAt(_)==="h"){const E=y[_]/180*vg;l+=M_(E)*e[p+1],h+=N_(E)*e[p+1]}else o[_]+=y[_]*e[p+1]});for(let d=0;d<o.length;d++)if(t.charAt(d)==="h"){let p=w3(h/a[d],l/a[d])/vg*180;for(;p<0;)p+=360;for(;p>=360;)p-=360;o[d]=p}else o[d]=o[d]/a[d];return f/=n,new xt(o,t).alpha(f>.99999?1:f,!0)},b3=(i,t)=>{const e=i.length,n=[0,0,0,0];for(let s=0;s<i.length;s++){const r=i[s],o=t[s]/e,a=r._rgb;n[0]+=yg(a[0],2)*o,n[1]+=yg(a[1],2)*o,n[2]+=yg(a[2],2)*o,n[3]+=a[3]*o}return n[0]=_g(n[0]),n[1]=_g(n[1]),n[2]=_g(n[2]),n[3]>.9999999&&(n[3]=1),new xt(Np(n))},{pow:I3}=Math;function Ef(i){let t="rgb",e=ee("#ccc"),n=0,s=[0,1],r=[0,1],o=[],a=[0,0],l=!1,h=[],f=!1,d=0,p=1,y=!1,_={},E=!0,w=1;const L=function(I){if(I=I||["#fff","#000"],I&&se(I)==="string"&&ee.brewer&&ee.brewer[I.toLowerCase()]&&(I=ee.brewer[I.toLowerCase()]),se(I)==="array"){I.length===1&&(I=[I[0],I[0]]),I=I.slice(0);for(let M=0;M<I.length;M++)I[M]=ee(I[M]);o.length=0;for(let M=0;M<I.length;M++)o.push(M/(I.length-1))}return C(),h=I},b=function(I){if(l!=null){const M=l.length-1;let R=0;for(;R<M&&I>=l[R];)R++;return R-1}return 0};let P=I=>I,N=I=>I;const S=function(I,M){let R,A;if(M==null&&(M=!1),isNaN(I)||I===null)return e;M?A=I:l&&l.length>2?A=b(I)/(l.length-2):p!==d?A=(I-d)/(p-d):A=1,A=N(A),M||(A=P(A)),w!==1&&(A=I3(A,w)),A=a[0]+A*(1-a[0]-a[1]),A=No(A,0,1);const F=Math.floor(A*1e4);if(E&&_[F])R=_[F];else{if(se(h)==="array")for(let $=0;$<o.length;$++){const z=o[$];if(A<=z){R=h[$];break}if(A>=z&&$===o.length-1){R=h[$];break}if(A>z&&A<o[$+1]){A=(A-z)/(o[$+1]-z),R=ee.interpolate(h[$],h[$+1],A,t);break}}else se(h)==="function"&&(R=h(A));E&&(_[F]=R)}return R};var C=()=>_={};L(i);const T=function(I){const M=ee(S(I));return f&&M[f]?M[f]():M};return T.classes=function(I){if(I!=null){if(se(I)==="array")l=I,s=[I[0],I[I.length-1]];else{const M=ee.analyze(s);I===0?l=[M.min,M.max]:l=ee.limits(M,"e",I)}return T}return l},T.domain=function(I){if(!arguments.length)return r;r=I.slice(0),d=I[0],p=I[I.length-1],o=[];const M=h.length;if(I.length===M&&d!==p)for(let R of Array.from(I))o.push((R-d)/(p-d));else{for(let R=0;R<M;R++)o.push(R/(M-1));if(I.length>2){const R=I.map((F,$)=>$/(I.length-1)),A=I.map(F=>(F-d)/(p-d));A.every((F,$)=>R[$]===F)||(N=F=>{if(F<=0||F>=1)return F;let $=0;for(;F>=A[$+1];)$++;const z=(F-A[$])/(A[$+1]-A[$]);return R[$]+z*(R[$+1]-R[$])})}}return s=[d,p],T},T.mode=function(I){return arguments.length?(t=I,C(),T):t},T.range=function(I,M){return L(I),T},T.out=function(I){return f=I,T},T.spread=function(I){return arguments.length?(n=I,T):n},T.correctLightness=function(I){return I==null&&(I=!0),y=I,C(),y?P=function(M){const R=S(0,!0).lab()[0],A=S(1,!0).lab()[0],F=R>A;let $=S(M,!0).lab()[0];const z=R+(A-R)*M;let D=$-z,B=0,U=1,j=20;for(;Math.abs(D)>.01&&j-- >0;)(function(){return F&&(D*=-1),D<0?(B=M,M+=(U-M)*.5):(U=M,M+=(B-M)*.5),$=S(M,!0).lab()[0],D=$-z})();return M}:P=M=>M,T},T.padding=function(I){return I!=null?(se(I)==="number"&&(I=[I,I]),a=I,T):a},T.colors=function(I,M){arguments.length<2&&(M="hex");let R=[];if(arguments.length===0)R=h.slice(0);else if(I===1)R=[T(.5)];else if(I>1){const A=s[0],F=s[1]-A;R=S3(0,I).map($=>T(A+$/(I-1)*F))}else{i=[];let A=[];if(l&&l.length>2)for(let F=1,$=l.length,z=1<=$;z?F<$:F>$;z?F++:F--)A.push((l[F-1]+l[F])*.5);else A=s;R=A.map(F=>T(F))}return ee[M]&&(R=R.map(A=>A[M]())),R},T.cache=function(I){return I!=null?(E=I,T):E},T.gamma=function(I){return I!=null?(w=I,T):w},T.nodata=function(I){return I!=null?(e=ee(I),T):e},T}function S3(i,t,e){let n=[],s=i<t,r=t;for(let o=i;s?o<r:o>r;s?o++:o--)n.push(o);return n}const M3=function(i){let t=[1,1];for(let e=1;e<i;e++){let n=[1];for(let s=1;s<=t.length;s++)n[s]=(t[s]||0)+t[s-1];t=n}return t},N3=function(i){let t,e,n,s;if(i=i.map(r=>new xt(r)),i.length===2)[e,n]=i.map(r=>r.lab()),t=function(r){const o=[0,1,2].map(a=>e[a]+r*(n[a]-e[a]));return new xt(o,"lab")};else if(i.length===3)[e,n,s]=i.map(r=>r.lab()),t=function(r){const o=[0,1,2].map(a=>(1-r)*(1-r)*e[a]+2*(1-r)*r*n[a]+r*r*s[a]);return new xt(o,"lab")};else if(i.length===4){let r;[e,n,s,r]=i.map(o=>o.lab()),t=function(o){const a=[0,1,2].map(l=>(1-o)*(1-o)*(1-o)*e[l]+3*(1-o)*(1-o)*o*n[l]+3*(1-o)*o*o*s[l]+o*o*o*r[l]);return new xt(a,"lab")}}else if(i.length>=5){let r,o,a;r=i.map(l=>l.lab()),a=i.length-1,o=M3(a),t=function(l){const h=1-l,f=[0,1,2].map(d=>r.reduce((p,y,_)=>p+o[_]*h**(a-_)*l**_*y[d],0));return new xt(f,"lab")}}else throw new RangeError("No point in running bezier with only one color.");return t},L3=i=>{const t=N3(i);return t.scale=()=>Ef(t),t},{round:rx}=Math;xt.prototype.rgb=function(i=!0){return i===!1?this._rgb.slice(0,3):this._rgb.slice(0,3).map(rx)};xt.prototype.rgba=function(i=!0){return this._rgb.slice(0,4).map((t,e)=>e<3?i===!1?t:rx(t):t)};const C3=(...i)=>new xt(...i,"rgb");Object.assign(ee,{rgb:C3});Kt.format.rgb=(...i)=>{const t=Jt(i,"rgba");return t[3]===void 0&&(t[3]=1),t};Kt.autodetect.push({p:3,test:(...i)=>{if(i=Jt(i,"rgba"),se(i)==="array"&&(i.length===3||i.length===4&&se(i[3])=="number"&&i[3]>=0&&i[3]<=1))return"rgb"}});const Ms=(i,t,e)=>{if(!Ms[e])throw new Error("unknown blend mode "+e);return Ms[e](i,t)},Qr=i=>(t,e)=>{const n=ee(e).rgb(),s=ee(t).rgb();return ee.rgb(i(n,s))},to=i=>(t,e)=>{const n=[];return n[0]=i(t[0],e[0]),n[1]=i(t[1],e[1]),n[2]=i(t[2],e[2]),n},P3=i=>i,k3=(i,t)=>i*t/255,T3=(i,t)=>i>t?t:i,R3=(i,t)=>i>t?i:t,A3=(i,t)=>255*(1-(1-i/255)*(1-t/255)),O3=(i,t)=>t<128?2*i*t/255:255*(1-2*(1-i/255)*(1-t/255)),F3=(i,t)=>255*(1-(1-t/255)/(i/255)),$3=(i,t)=>i===255?255:(i=255*(t/255)/(1-i/255),i>255?255:i);Ms.normal=Qr(to(P3));Ms.multiply=Qr(to(k3));Ms.screen=Qr(to(A3));Ms.overlay=Qr(to(O3));Ms.darken=Qr(to(T3));Ms.lighten=Qr(to(R3));Ms.dodge=Qr(to($3));Ms.burn=Qr(to(F3));const{pow:D3,sin:G3,cos:B3}=Math;function q3(i=300,t=-1.5,e=1,n=1,s=[0,1]){let r=0,o;se(s)==="array"?o=s[1]-s[0]:(o=0,s=[s,s]);const a=function(l){const h=ar*((i+120)/360+t*l),f=D3(s[0]+o*l,n),p=(r!==0?e[0]+l*r:e)*f*(1-f)/2,y=B3(h),_=G3(h),E=f+p*(-.14861*y+1.78277*_),w=f+p*(-.29227*y-.90649*_),L=f+p*(1.97294*y);return ee(Np([E*255,w*255,L*255,1]))};return a.start=function(l){return l==null?i:(i=l,a)},a.rotations=function(l){return l==null?t:(t=l,a)},a.gamma=function(l){return l==null?n:(n=l,a)},a.hue=function(l){return l==null?e:(e=l,se(e)==="array"?(r=e[1]-e[0],r===0&&(e=e[1])):r=0,a)},a.lightness=function(l){return l==null?s:(se(l)==="array"?(s=l,o=l[1]-l[0]):(s=[l,l],o=0),a)},a.scale=()=>ee.scale(a),a.hue(e),a}const z3="0123456789abcdef",{floor:U3,random:Y3}=Math,X3=(i=Y3)=>{let t="#";for(let e=0;e<6;e++)t+=z3.charAt(U3(i()*16));return new xt(t,"hex")},{log:L_,pow:j3,floor:V3,abs:H3}=Math;function ox(i,t=null){const e={min:Number.MAX_VALUE,max:Number.MAX_VALUE*-1,sum:0,values:[],count:0};return se(i)==="object"&&(i=Object.values(i)),i.forEach(n=>{t&&se(n)==="object"&&(n=n[t]),n!=null&&!isNaN(n)&&(e.values.push(n),e.sum+=n,n<e.min&&(e.min=n),n>e.max&&(e.max=n),e.count+=1)}),e.domain=[e.min,e.max],e.limits=(n,s)=>ax(e,n,s),e}function ax(i,t="equal",e=7){se(i)=="array"&&(i=ox(i));const{min:n,max:s}=i,r=i.values.sort((a,l)=>a-l);if(e===1)return[n,s];const o=[];if(t.substr(0,1)==="c"&&(o.push(n),o.push(s)),t.substr(0,1)==="e"){o.push(n);for(let a=1;a<e;a++)o.push(n+a/e*(s-n));o.push(s)}else if(t.substr(0,1)==="l"){if(n<=0)throw new Error("Logarithmic scales are only possible for values > 0");const a=Math.LOG10E*L_(n),l=Math.LOG10E*L_(s);o.push(n);for(let h=1;h<e;h++)o.push(j3(10,a+h/e*(l-a)));o.push(s)}else if(t.substr(0,1)==="q"){o.push(n);for(let a=1;a<e;a++){const l=(r.length-1)*a/e,h=V3(l);if(h===l)o.push(r[h]);else{const f=l-h;o.push(r[h]*(1-f)+r[h+1]*f)}}o.push(s)}else if(t.substr(0,1)==="k"){let a;const l=r.length,h=new Array(l),f=new Array(e);let d=!0,p=0,y=null;y=[],y.push(n);for(let w=1;w<e;w++)y.push(n+w/e*(s-n));for(y.push(s);d;){for(let L=0;L<e;L++)f[L]=0;for(let L=0;L<l;L++){const b=r[L];let P=Number.MAX_VALUE,N;for(let S=0;S<e;S++){const C=H3(y[S]-b);C<P&&(P=C,N=S),f[N]++,h[L]=N}}const w=new Array(e);for(let L=0;L<e;L++)w[L]=null;for(let L=0;L<l;L++)a=h[L],w[a]===null?w[a]=r[L]:w[a]+=r[L];for(let L=0;L<e;L++)w[L]*=1/f[L];d=!1;for(let L=0;L<e;L++)if(w[L]!==y[L]){d=!0;break}y=w,p++,p>200&&(d=!1)}const _={};for(let w=0;w<e;w++)_[w]=[];for(let w=0;w<l;w++)a=h[w],_[a].push(r[w]);let E=[];for(let w=0;w<e;w++)E.push(_[w][0]),E.push(_[w][_[w].length-1]);E=E.sort((w,L)=>w-L),o.push(E[0]);for(let w=1;w<E.length;w+=2){const L=E[w];!isNaN(L)&&o.indexOf(L)===-1&&o.push(L)}}return o}const W3=(i,t)=>{i=new xt(i),t=new xt(t);const e=i.luminance(),n=t.luminance();return e>n?(e+.05)/(n+.05):(n+.05)/(e+.05)};/**
|
|
15
|
+
* @license
|
|
16
|
+
*
|
|
17
|
+
* The APCA contrast prediction algorithm is based of the formulas published
|
|
18
|
+
* in the APCA-1.0.98G specification by Myndex. The specification is available at:
|
|
19
|
+
* https://raw.githubusercontent.com/Myndex/apca-w3/master/images/APCAw3_0.1.17_APCA0.0.98G.svg
|
|
20
|
+
*
|
|
21
|
+
* Note that the APCA implementation is still beta, so please update to
|
|
22
|
+
* future versions of chroma.js when they become available.
|
|
23
|
+
*
|
|
24
|
+
* You can read more about the APCA Readability Criterion at
|
|
25
|
+
* https://readtech.org/ARC/
|
|
26
|
+
*/const C_=.027,K3=5e-4,Z3=.1,P_=1.14,oh=.022,k_=1.414,J3=(i,t)=>{i=new xt(i),t=new xt(t),i.alpha()<1&&(i=hl(t,i,i.alpha(),"rgb"));const e=T_(...i.rgb()),n=T_(...t.rgb()),s=e>=oh?e:e+Math.pow(oh-e,k_),r=n>=oh?n:n+Math.pow(oh-n,k_),o=Math.pow(r,.56)-Math.pow(s,.57),a=Math.pow(r,.65)-Math.pow(s,.62),l=Math.abs(r-s)<K3?0:s<r?o*P_:a*P_;return(Math.abs(l)<Z3?0:l>0?l-C_:l+C_)*100};function T_(i,t,e){return .2126729*Math.pow(i/255,2.4)+.7151522*Math.pow(t/255,2.4)+.072175*Math.pow(e/255,2.4)}const{sqrt:rr,pow:an,min:Q3,max:tO,atan2:R_,abs:A_,cos:ah,sin:O_,exp:eO,PI:F_}=Math;function nO(i,t,e=1,n=1,s=1){var r=function(ft){return 360*ft/(2*F_)},o=function(ft){return 2*F_*ft/360};i=new xt(i),t=new xt(t);const[a,l,h]=Array.from(i.lab()),[f,d,p]=Array.from(t.lab()),y=(a+f)/2,_=rr(an(l,2)+an(h,2)),E=rr(an(d,2)+an(p,2)),w=(_+E)/2,L=.5*(1-rr(an(w,7)/(an(w,7)+an(25,7)))),b=l*(1+L),P=d*(1+L),N=rr(an(b,2)+an(h,2)),S=rr(an(P,2)+an(p,2)),C=(N+S)/2,T=r(R_(h,b)),I=r(R_(p,P)),M=T>=0?T:T+360,R=I>=0?I:I+360,A=A_(M-R)>180?(M+R+360)/2:(M+R)/2,F=1-.17*ah(o(A-30))+.24*ah(o(2*A))+.32*ah(o(3*A+6))-.2*ah(o(4*A-63));let $=R-M;$=A_($)<=180?$:R<=M?$+360:$-360,$=2*rr(N*S)*O_(o($)/2);const z=f-a,D=S-N,B=1+.015*an(y-50,2)/rr(20+an(y-50,2)),U=1+.045*C,j=1+.015*C*F,K=30*eO(-an((A-275)/25,2)),J=-(2*rr(an(C,7)/(an(C,7)+an(25,7))))*O_(2*o(K)),lt=rr(an(z/(e*B),2)+an(D/(n*U),2)+an($/(s*j),2)+J*(D/(n*U))*($/(s*j)));return tO(0,Q3(100,lt))}function iO(i,t,e="lab"){i=new xt(i),t=new xt(t);const n=i.get(e),s=t.get(e);let r=0;for(let o in n){const a=(n[o]||0)-(s[o]||0);r+=a*a}return Math.sqrt(r)}const sO=(...i)=>{try{return new xt(...i),!0}catch{return!1}},rO={cool(){return Ef([ee.hsl(180,1,.9),ee.hsl(250,.7,.4)])},hot(){return Ef(["#000","#f00","#ff0","#fff"]).mode("rgb")}},cm={OrRd:["#fff7ec","#fee8c8","#fdd49e","#fdbb84","#fc8d59","#ef6548","#d7301f","#b30000","#7f0000"],PuBu:["#fff7fb","#ece7f2","#d0d1e6","#a6bddb","#74a9cf","#3690c0","#0570b0","#045a8d","#023858"],BuPu:["#f7fcfd","#e0ecf4","#bfd3e6","#9ebcda","#8c96c6","#8c6bb1","#88419d","#810f7c","#4d004b"],Oranges:["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#a63603","#7f2704"],BuGn:["#f7fcfd","#e5f5f9","#ccece6","#99d8c9","#66c2a4","#41ae76","#238b45","#006d2c","#00441b"],YlOrBr:["#ffffe5","#fff7bc","#fee391","#fec44f","#fe9929","#ec7014","#cc4c02","#993404","#662506"],YlGn:["#ffffe5","#f7fcb9","#d9f0a3","#addd8e","#78c679","#41ab5d","#238443","#006837","#004529"],Reds:["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d"],RdPu:["#fff7f3","#fde0dd","#fcc5c0","#fa9fb5","#f768a1","#dd3497","#ae017e","#7a0177","#49006a"],Greens:["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#006d2c","#00441b"],YlGnBu:["#ffffd9","#edf8b1","#c7e9b4","#7fcdbb","#41b6c4","#1d91c0","#225ea8","#253494","#081d58"],Purples:["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"],GnBu:["#f7fcf0","#e0f3db","#ccebc5","#a8ddb5","#7bccc4","#4eb3d3","#2b8cbe","#0868ac","#084081"],Greys:["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525","#000000"],YlOrRd:["#ffffcc","#ffeda0","#fed976","#feb24c","#fd8d3c","#fc4e2a","#e31a1c","#bd0026","#800026"],PuRd:["#f7f4f9","#e7e1ef","#d4b9da","#c994c7","#df65b0","#e7298a","#ce1256","#980043","#67001f"],Blues:["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"],PuBuGn:["#fff7fb","#ece2f0","#d0d1e6","#a6bddb","#67a9cf","#3690c0","#02818a","#016c59","#014636"],Viridis:["#440154","#482777","#3f4a8a","#31678e","#26838f","#1f9d8a","#6cce5a","#b6de2b","#fee825"],Spectral:["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"],RdYlGn:["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"],RdBu:["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"],PiYG:["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"],PRGn:["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"],RdYlBu:["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"],BrBG:["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"],RdGy:["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#ffffff","#e0e0e0","#bababa","#878787","#4d4d4d","#1a1a1a"],PuOr:["#7f3b08","#b35806","#e08214","#fdb863","#fee0b6","#f7f7f7","#d8daeb","#b2abd2","#8073ac","#542788","#2d004b"],Set2:["#66c2a5","#fc8d62","#8da0cb","#e78ac3","#a6d854","#ffd92f","#e5c494","#b3b3b3"],Accent:["#7fc97f","#beaed4","#fdc086","#ffff99","#386cb0","#f0027f","#bf5b17","#666666"],Set1:["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00","#ffff33","#a65628","#f781bf","#999999"],Set3:["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd","#ccebc5","#ffed6f"],Dark2:["#1b9e77","#d95f02","#7570b3","#e7298a","#66a61e","#e6ab02","#a6761d","#666666"],Paired:["#a6cee3","#1f78b4","#b2df8a","#33a02c","#fb9a99","#e31a1c","#fdbf6f","#ff7f00","#cab2d6","#6a3d9a","#ffff99","#b15928"],Pastel2:["#b3e2cd","#fdcdac","#cbd5e8","#f4cae4","#e6f5c9","#fff2ae","#f1e2cc","#cccccc"],Pastel1:["#fbb4ae","#b3cde3","#ccebc5","#decbe4","#fed9a6","#ffffcc","#e5d8bd","#fddaec","#f2f2f2"]},lx=Object.keys(cm),$_=new Map(lx.map(i=>[i.toLowerCase(),i])),oO=typeof Proxy=="function"?new Proxy(cm,{get(i,t){const e=t.toLowerCase();if($_.has(e))return i[$_.get(e)]},getOwnPropertyNames(){return Object.getOwnPropertyNames(lx)}}):cm,aO=(...i)=>{i=Jt(i,"cmyk");const[t,e,n,s]=i,r=i.length>4?i[4]:1;return s===1?[0,0,0,r]:[t>=1?0:255*(1-t)*(1-s),e>=1?0:255*(1-e)*(1-s),n>=1?0:255*(1-n)*(1-s),r]},{max:D_}=Math,lO=(...i)=>{let[t,e,n]=Jt(i,"rgb");t=t/255,e=e/255,n=n/255;const s=1-D_(t,D_(e,n)),r=s<1?1/(1-s):0,o=(1-t-s)*r,a=(1-e-s)*r,l=(1-n-s)*r;return[o,a,l,s]};xt.prototype.cmyk=function(){return lO(this._rgb)};const uO=(...i)=>new xt(...i,"cmyk");Object.assign(ee,{cmyk:uO});Kt.format.cmyk=aO;Kt.autodetect.push({p:2,test:(...i)=>{if(i=Jt(i,"cmyk"),se(i)==="array"&&i.length===4)return"cmyk"}});const cO=(...i)=>{const t=Jt(i,"hsla");let e=wl(i)||"lsa";return t[0]=es(t[0]||0)+"deg",t[1]=es(t[1]*100)+"%",t[2]=es(t[2]*100)+"%",e==="hsla"||t.length>3&&t[3]<1?(t[3]="/ "+(t.length>3?t[3]:1),e="hsla"):t.length=3,`${e.substr(0,3)}(${t.join(" ")})`},hO=(...i)=>{const t=Jt(i,"lab");let e=wl(i)||"lab";return t[0]=es(t[0])+"%",t[1]=es(t[1]),t[2]=es(t[2]),e==="laba"||t.length>3&&t[3]<1?t[3]="/ "+(t.length>3?t[3]:1):t.length=3,`lab(${t.join(" ")})`},fO=(...i)=>{const t=Jt(i,"lch");let e=wl(i)||"lab";return t[0]=es(t[0])+"%",t[1]=es(t[1]),t[2]=isNaN(t[2])?"none":es(t[2])+"deg",e==="lcha"||t.length>3&&t[3]<1?t[3]="/ "+(t.length>3?t[3]:1):t.length=3,`lch(${t.join(" ")})`},dO=(...i)=>{const t=Jt(i,"lab");return t[0]=es(t[0]*100)+"%",t[1]=lm(t[1]),t[2]=lm(t[2]),t.length>3&&t[3]<1?t[3]="/ "+(t.length>3?t[3]:1):t.length=3,`oklab(${t.join(" ")})`},ux=(...i)=>{const[t,e,n,...s]=Jt(i,"rgb"),[r,o,a]=Rp(t,e,n),[l,h,f]=nx(r,o,a);return[l,h,f,...s.length>0&&s[0]<1?[s[0]]:[]]},gO=(...i)=>{const t=Jt(i,"lch");return t[0]=es(t[0]*100)+"%",t[1]=lm(t[1]),t[2]=isNaN(t[2])?"none":es(t[2])+"deg",t.length>3&&t[3]<1?t[3]="/ "+(t.length>3?t[3]:1):t.length=3,`oklch(${t.join(" ")})`},{round:Eg}=Math,mO=(...i)=>{const t=Jt(i,"rgba");let e=wl(i)||"rgb";if(e.substr(0,3)==="hsl")return cO(sx(t),e);if(e.substr(0,3)==="lab"){const n=Xu();cr("d50");const s=hO(Cp(t),e);return cr(n),s}if(e.substr(0,3)==="lch"){const n=Xu();cr("d50");const s=fO(kp(t),e);return cr(n),s}return e.substr(0,5)==="oklab"?dO(Rp(t)):e.substr(0,5)==="oklch"?gO(ux(t)):(t[0]=Eg(t[0]),t[1]=Eg(t[1]),t[2]=Eg(t[2]),(e==="rgba"||t.length>3&&t[3]<1)&&(t[3]="/ "+(t.length>3?t[3]:1),e="rgba"),`${e.substr(0,3)}(${t.slice(0,e==="rgb"?3:4).join(" ")})`)},cx=(...i)=>{i=Jt(i,"lch");const[t,e,n,...s]=i,[r,o,a]=ex(t,e,n),[l,h,f]=Tp(r,o,a);return[l,h,f,...s.length>0&&s[0]<1?[s[0]]:[]]},gr=/((?:-?\d+)|(?:-?\d+(?:\.\d+)?)%|none)/.source,xs=/((?:-?(?:\d+(?:\.\d*)?|\.\d+)%?)|none)/.source,wf=/((?:-?(?:\d+(?:\.\d*)?|\.\d+)%)|none)/.source,is=/\s*/.source,bl=/\s+/.source,Ap=/\s*,\s*/.source,ld=/((?:-?(?:\d+(?:\.\d*)?|\.\d+)(?:deg)?)|none)/.source,Il=/\s*(?:\/\s*((?:[01]|[01]?\.\d+)|\d+(?:\.\d+)?%))?/.source,hx=new RegExp("^rgba?\\("+is+[gr,gr,gr].join(bl)+Il+"\\)$"),fx=new RegExp("^rgb\\("+is+[gr,gr,gr].join(Ap)+is+"\\)$"),dx=new RegExp("^rgba\\("+is+[gr,gr,gr,xs].join(Ap)+is+"\\)$"),gx=new RegExp("^hsla?\\("+is+[ld,wf,wf].join(bl)+Il+"\\)$"),mx=new RegExp("^hsl?\\("+is+[ld,wf,wf].join(Ap)+is+"\\)$"),px=/^hsla\(\s*(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)$/,yx=new RegExp("^lab\\("+is+[xs,xs,xs].join(bl)+Il+"\\)$"),_x=new RegExp("^lch\\("+is+[xs,xs,ld].join(bl)+Il+"\\)$"),vx=new RegExp("^oklab\\("+is+[xs,xs,xs].join(bl)+Il+"\\)$"),Ex=new RegExp("^oklch\\("+is+[xs,xs,ld].join(bl)+Il+"\\)$"),{round:wx}=Math,ra=i=>i.map((t,e)=>e<=2?No(wx(t),0,255):t),ln=(i,t=0,e=100,n=!1)=>(typeof i=="string"&&i.endsWith("%")&&(i=parseFloat(i.substring(0,i.length-1))/100,n?i=t+(i+1)*.5*(e-t):i=t+i*(e-t)),+i),zn=(i,t)=>i==="none"?t:i,Op=i=>{if(i=i.toLowerCase().trim(),i==="transparent")return[0,0,0,0];let t;if(Kt.format.named)try{return Kt.format.named(i)}catch{}if((t=i.match(hx))||(t=i.match(fx))){let e=t.slice(1,4);for(let s=0;s<3;s++)e[s]=+ln(zn(e[s],0),0,255);e=ra(e);const n=t[4]!==void 0?+ln(t[4],0,1):1;return e[3]=n,e}if(t=i.match(dx)){const e=t.slice(1,5);for(let n=0;n<4;n++)e[n]=+ln(e[n],0,255);return e}if((t=i.match(gx))||(t=i.match(mx))){const e=t.slice(1,4);e[0]=+zn(e[0].replace("deg",""),0),e[1]=+ln(zn(e[1],0),0,100)*.01,e[2]=+ln(zn(e[2],0),0,100)*.01;const n=ra(um(e)),s=t[4]!==void 0?+ln(t[4],0,1):1;return n[3]=s,n}if(t=i.match(px)){const e=t.slice(1,4);e[1]*=.01,e[2]*=.01;const n=um(e);for(let s=0;s<3;s++)n[s]=wx(n[s]);return n[3]=+t[4],n}if(t=i.match(yx)){const e=t.slice(1,4);e[0]=ln(zn(e[0],0),0,100),e[1]=ln(zn(e[1],0),-125,125,!0),e[2]=ln(zn(e[2],0),-125,125,!0);const n=Xu();cr("d50");const s=ra(Lp(e));cr(n);const r=t[4]!==void 0?+ln(t[4],0,1):1;return s[3]=r,s}if(t=i.match(_x)){const e=t.slice(1,4);e[0]=ln(e[0],0,100),e[1]=ln(zn(e[1],0),0,150,!1),e[2]=+zn(e[2].replace("deg",""),0);const n=Xu();cr("d50");const s=ra(Pp(e));cr(n);const r=t[4]!==void 0?+ln(t[4],0,1):1;return s[3]=r,s}if(t=i.match(vx)){const e=t.slice(1,4);e[0]=ln(zn(e[0],0),0,1),e[1]=ln(zn(e[1],0),-.4,.4,!0),e[2]=ln(zn(e[2],0),-.4,.4,!0);const n=ra(Tp(e)),s=t[4]!==void 0?+ln(t[4],0,1):1;return n[3]=s,n}if(t=i.match(Ex)){const e=t.slice(1,4);e[0]=ln(zn(e[0],0),0,1),e[1]=ln(zn(e[1],0),0,.4,!1),e[2]=+zn(e[2].replace("deg",""),0);const n=ra(cx(e)),s=t[4]!==void 0?+ln(t[4],0,1):1;return n[3]=s,n}};Op.test=i=>hx.test(i)||gx.test(i)||yx.test(i)||_x.test(i)||vx.test(i)||Ex.test(i)||fx.test(i)||dx.test(i)||mx.test(i)||px.test(i)||i==="transparent";xt.prototype.css=function(i){return mO(this._rgb,i)};const pO=(...i)=>new xt(...i,"css");ee.css=pO;Kt.format.css=Op;Kt.autodetect.push({p:5,test:(i,...t)=>{if(!t.length&&se(i)==="string"&&Op.test(i))return"css"}});Kt.format.gl=(...i)=>{const t=Jt(i,"rgba");return t[0]*=255,t[1]*=255,t[2]*=255,t};const yO=(...i)=>new xt(...i,"gl");ee.gl=yO;xt.prototype.gl=function(){const i=this._rgb;return[i[0]/255,i[1]/255,i[2]/255,i[3]]};xt.prototype.hex=function(i){return Jw(this._rgb,i)};const _O=(...i)=>new xt(...i,"hex");ee.hex=_O;Kt.format.hex=Zw;Kt.autodetect.push({p:4,test:(i,...t)=>{if(!t.length&&se(i)==="string"&&[3,4,5,6,7,8,9].indexOf(i.length)>=0)return"hex"}});const{log:lh}=Math,xx=i=>{const t=i/100;let e,n,s;return t<66?(e=255,n=t<6?0:-155.25485562709179-.44596950469579133*(n=t-2)+104.49216199393888*lh(n),s=t<20?0:-254.76935184120902+.8274096064007395*(s=t-10)+115.67994401066147*lh(s)):(e=351.97690566805693+.114206453784165*(e=t-55)-40.25366309332127*lh(e),n=325.4494125711974+.07943456536662342*(n=t-50)-28.0852963507957*lh(n),s=255),[e,n,s,1]},{round:vO}=Math,EO=(...i)=>{const t=Jt(i,"rgb"),e=t[0],n=t[2];let s=1e3,r=4e4;const o=.4;let a;for(;r-s>o;){a=(r+s)*.5;const l=xx(a);l[2]/l[0]>=n/e?r=a:s=a}return vO(a)};xt.prototype.temp=xt.prototype.kelvin=xt.prototype.temperature=function(){return EO(this._rgb)};const wg=(...i)=>new xt(...i,"temp");Object.assign(ee,{temp:wg,kelvin:wg,temperature:wg});Kt.format.temp=Kt.format.kelvin=Kt.format.temperature=xx;xt.prototype.oklch=function(){return ux(this._rgb)};const wO=(...i)=>new xt(...i,"oklch");Object.assign(ee,{oklch:wO});Kt.format.oklch=cx;Kt.autodetect.push({p:2,test:(...i)=>{if(i=Jt(i,"oklch"),se(i)==="array"&&i.length===3)return"oklch"}});Object.assign(ee,{analyze:ox,average:x3,bezier:L3,blend:Ms,brewer:oO,Color:xt,colors:cl,contrast:W3,contrastAPCA:J3,cubehelix:q3,deltaE:nO,distance:iO,input:Kt,interpolate:hl,limits:ax,mix:hl,random:X3,scale:Ef,scales:rO,valid:sO});const hm={viridis:["#440154","#3b528b","#21918c","#5ec962","#fde725"],magma:["#000004","#51127c","#b73779","#fb8861","#fcfdbf"],blues:["#eff3ff","#bdd7e7","#6baed6","#3182bd","#08519c"],greens:["#edf8e9","#bae4b3","#74c476","#31a354","#006d2c"],oranges:["#feedde","#fdbe85","#fd8d3c","#e6550d","#a63603"],purples:["#f2f0f7","#cbc9e2","#9e9ac8","#756bb1","#54278f"],ylgnbu:["#ffffd9","#c7e9b4","#41b6c4","#225ea8","#081d58"],ylorrd:["#ffffb2","#fecc5c","#fd8d3c","#f03b20","#bd0026"],spectral:["#d7191c","#fdae61","#ffffbf","#abdda4","#2b83ba"],rdylgn:["#d73027","#fc8d59","#fee08b","#d9ef8b","#91cf60","#1a9850"],rdbu:["#ca0020","#f4a582","#f7f7f7","#92c5de","#0571b0"],category10:["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],set1:["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00","#ffff33","#a65628","#f781bf"],set2:["#66c2a5","#fc8d62","#8da0cb","#e78ac3","#a6d854","#ffd92f","#e5c494","#b3b3b3"],pastel:["#fbb4ae","#b3cde3","#ccebc5","#decbe4","#fed9a6","#ffffcc","#e5d8bd","#fddaec"]},xO={viridis:"sequential",magma:"sequential",blues:"sequential",greens:"sequential",oranges:"sequential",purples:"sequential",ylgnbu:"sequential",ylorrd:"sequential",spectral:"diverging",rdylgn:"diverging",rdbu:"diverging",category10:"qualitative",set1:"qualitative",set2:"qualitative",pastel:"qualitative"},bO=i=>i.split(" ").map(t=>`#${t.toLowerCase()}`),IO={Blues:"f7fbff deebf7 c6dbef 9ecae1 6baed6 4292c6 2171b5 08519c 08306b",BuGn:"f7fcfd e5f5f9 ccece6 99d8c9 66c2a4 41ae76 238b45 006d2c 00441b",BuPu:"f7fcfd e0ecf4 bfd3e6 9ebcda 8c96c6 8c6bb1 88419d 810f7c 4d004b",GnBu:"f7fcf0 e0f3db ccebc5 a8ddb5 7bccc4 4eb3d3 2b8cbe 0868ac 084081",Greens:"f7fcf5 e5f5e0 c7e9c0 a1d99b 74c476 41ab5d 238b45 006d2c 00441b",Greys:"ffffff f0f0f0 d9d9d9 bdbdbd 969696 737373 525252 252525 000000",Oranges:"fff5eb fee6ce fdd0a2 fdae6b fd8d3c f16913 d94801 a63603 7f2704",OrRd:"fff7ec fee8c8 fdd49e fdbb84 fc8d59 ef6548 d7301f b30000 7f0000",PuBu:"fff7fb ece7f2 d0d1e6 a6bddb 74a9cf 3690c0 0570b0 045a8d 023858",PuBuGn:"fff7fb ece2f0 d0d1e6 a6bddb 67a9cf 3690c0 02818a 016c59 014636",PuRd:"f7f4f9 e7e1ef d4b9da c994c7 df65b0 e7298a ce1256 980043 67001f",Purples:"fcfbfd efedf5 dadaeb bcbddc 9e9ac8 807dba 6a51a3 54278f 3f007d",RdPu:"fff7f3 fde0dd fcc5c0 fa9fb5 f768a1 dd3497 ae017e 7a0177 49006a",Reds:"fff5f0 fee0d2 fcbba1 fc9272 fb6a4a ef3b2c cb181d a50f15 67000d",YlGn:"ffffe5 f7fcb9 d9f0a3 addd8e 78c679 41ab5d 238443 006837 004529",YlGnBu:"ffffd9 edf8b1 c7e9b4 7fcdbb 41b6c4 1d91c0 225ea8 253494 081d58",YlOrBr:"ffffe5 fff7bc fee391 fec44f fe9929 ec7014 cc4c02 993404 662506",YlOrRd:"ffffcc ffeda0 fed976 feb24c fd8d3c fc4e2a e31a1c bd0026 800026"},SO={BrBG:"543005 8c510a bf812d dfc27d f6e8c3 f5f5f5 c7eae5 80cdc1 35978f 01665e 003c30",PiYG:"8e0152 c51b7d de77ae f1b6da fde0ef f7f7f7 e6f5d0 b8e186 7fbc41 4d9221 276419",PRGn:"40004b 762a83 9970ab c2a5cf e7d4e8 f7f7f7 d9f0d3 a6dba0 5aae61 1b7837 00441b",PuOr:"7f3b08 b35806 e08214 fdb863 fee0b6 f7f7f7 d8daeb b2abd2 8073ac 542788 2d004b",RdBu:"67001f b2182b d6604d f4a582 fddbc7 f7f7f7 d1e5f0 92c5de 4393c3 2166ac 053061",RdGy:"67001f b2182b d6604d f4a582 fddbc7 ffffff e0e0e0 bababa 878787 4d4d4d 1a1a1a",RdYlBu:"a50026 d73027 f46d43 fdae61 fee090 ffffbf e0f3f8 abd9e9 74add1 4575b4 313695",RdYlGn:"a50026 d73027 f46d43 fdae61 fee08b ffffbf d9ef8b a6d96a 66bd63 1a9850 006837",Spectral:"9e0142 d53e4f f46d43 fdae61 fee08b ffffbf e6f598 abdda4 66c2a5 3288bd 5e4fa2"},MO={Accent:"7fc97f beaed4 fdc086 ffff99 386cb0 f0027f bf5b17 666666",Dark2:"1b9e77 d95f02 7570b3 e7298a 66a61e e6ab02 a6761d 666666",Paired:"a6cee3 1f78b4 b2df8a 33a02c fb9a99 e31a1c fdbf6f ff7f00 cab2d6 6a3d9a ffff99 b15928",Pastel1:"fbb4ae b3cde3 ccebc5 decbe4 fed9a6 ffffcc e5d8bd fddaec f2f2f2",Pastel2:"b3e2cd fdcdac cbd5e8 f4cae4 e6f5c9 fff2ae f1e2cc cccccc",Set3:"8dd3c7 ffffb3 bebada fb8072 80b1d3 fdb462 b3de69 fccde5 d9d9d9 bc80bd ccebc5 ffed6f"},NO={Burg:"ffc6c4 f4a3a8 e38191 cc607d ad466c 8b3058 672044",BurgYl:"fbe6c5 f5ba98 ee8a82 dc7176 c8586c 9c3f5d 70284a",RedOr:"f6d2a9 f5b78e f19c7c ea8171 dd686c ca5268 b13f64",OrYel:"ecda9a efc47e f3ad6a f7945d f97b57 f66356 ee4d5a",Peach:"fde0c5 facba6 f8b58b f59e72 f2855d ef6a4c eb4a40",PinkYl:"fef6b5 ffdd9a ffc285 ffa679 fa8a76 f16d7a e15383",Mint:"e4f1e1 b4d9cc 89c0b6 63a6a0 448c8a 287274 0d585f",BluGrn:"c4e6c3 96d2a4 6dbc90 4da284 36877a 266b6e 1d4f60",DarkMint:"d2fbd4 a5dbc2 7bbcb0 559c9e 3a7c89 235d72 123f5a",Emrld:"d3f2a3 97e196 6cc08b 4c9b82 217a79 105965 074050",ag_GrnYl:"245668 0f7279 0d8f81 39ab7e 6ec574 a9dc67 edef5d",BluYl:"f7feae b7e6a5 7ccba2 46aea0 089099 00718b 045275",Teal:"d1eeea a8dbd9 85c4c9 68abb8 4f90a6 3b738f 2a5674",TealGrn:"b0f2bc 89e8ac 67dba5 4cc8a3 38b2a3 2c98a0 257d98",Purp:"f3e0f7 e4c7f1 d1afe8 b998dd 9f82ce 826dba 63589f",PurpOr:"f9ddda f2b9c4 e597b9 ce78b3 ad5fad 834ba0 573b88",Sunset:"f3e79b fac484 f8a07e eb7f86 ce6693 a059a0 5c53a5",Magenta:"f3cbd3 eaa9bd dd88ac ca699d b14d8e 91357d 6c2167",SunsetDark:"fcde9c faa476 f0746e e34f6f dc3977 b9257a 7c1d6f",ag_Sunset:"4b2991 872ca2 c0369d ea4f88 fa7876 f6a97a edd9a3",BrwnYl:"ede5cf e0c2a2 d39c83 c1766f a65461 813753 541f3f"},LO={ArmyRose:"798234 a3ad62 d0d3a2 fdfbe4 f0c6c3 df91a3 d46780",Fall:"3d5941 778868 b5b991 f6edbd edbb8a de8a5a ca562c",Geyser:"008080 70a494 b4c8a8 f6edbd edbb8a de8a5a ca562c",Temps:"009392 39b185 9ccb86 e9e29c eeb479 e88471 cf597e",TealRose:"009392 72aaa1 b1c7b3 f1eac8 e5b9ad d98994 d0587e",Tropic:"009b9e 42b7b9 a7d3d4 f1f1f1 e4c1d9 d691c1 c75dab",Earth:"a16928 bd925a d6bd8d edeac2 b5c8b8 79a7ac 2887a1"},CO={Antique:"855c75 d9af6b af6458 736f4c 526a83 625377 68855c 9c9c5e a06177 8c785d 467378 7c7c7c",Bold:"7f3c8d 11a579 3969ac f2b701 e73f74 80ba5a e68310 008695 cf1c90 f97b72 4b4b8f a5aa99",CartoPastel:"66c5cc f6cf71 f89c74 dcb0f2 87c55f 9eb9f3 fe88b1 c9db74 8be0a4 b497e7 d3b484 b3b3b3",Prism:"5f4690 1d6996 38a6a5 0f8554 73af48 edad08 e17c05 cc503e 94346e 6f4070 994e95 666666",Safe:"88ccee cc6677 ddcc77 117733 332288 aa4499 44aa99 999933 882255 661100 6699cc 888888",Vivid:"e58606 5d69b1 52bca3 99c945 cc61b0 24796c daa51b 2f8ac4 764e9f ed645a cc3a8e a5aa99"},PO={Cividis:"00224e 123570 3b496c 575d6d 707173 8a8678 a59c74 c3b369 e1cc55 fee838",Inferno:"000004 1b0c41 4a0c6b 781c6d a52c60 cf4446 ed6925 fb9b06 f7d13d fcffa4",Plasma:"0d0887 46039f 7201a8 9c179e bd3786 d8576b ed7953 fb9f3a fdca26 f0f921"};function kO(){const i=new Map,t=n=>i.set(n.name.toLowerCase(),n);Object.keys(hm).forEach(n=>t({name:n,type:xO[n],source:"ofs",colors:[...hm[n]]}));const e=(n,s,r)=>Object.entries(n).forEach(([o,a])=>{i.has(o.toLowerCase())||t({name:o,type:s,source:r,colors:bO(a)})});return e(IO,"sequential","colorbrewer"),e(SO,"diverging","colorbrewer"),e(MO,"qualitative","colorbrewer"),e(NO,"sequential","carto"),e(LO,"diverging","carto"),e(CO,"qualitative","carto"),e(PO,"sequential","matplotlib"),i}const Fp=kO();function TO(i){if(i.colors.length===0)throw new Error(`Color ramp "${i.name}" has no colors`);i.colors.forEach(t=>{if(!ee.valid(t))throw new Error(`Color ramp "${i.name}" has an invalid color: ${t}`)}),Fp.set(i.name.toLowerCase(),{...i,colors:[...i.colors]})}function ju(i){return Fp.get(i.toLowerCase())}function $p(i){return Array.from(Fp.values()).filter(t=>!i||t.type===i)}function RO(i,t){const e=[];for(let n=0;n<i;n++){const s=(t+n)*137.508%360,r=55+(t+n)%3*10;e.push(ee.lch(r,60,s).hex())}return e}function ud(i,t,e=!1){if(t<=0)return[];let n,s;if(Array.isArray(i))n=[...i],s="sequential";else{const r=ju(i)??ju("viridis");n=[...r.colors],s=r.type}return e&&n.reverse(),s==="qualitative"?t<=n.length?n.slice(0,t):[...n,...RO(t-n.length,n.length)]:t===1?[n[Math.floor((n.length-1)/2)]]:t===n.length?n:ee.scale(n).mode("lab").colors(t)}function bx(i,t=!1){return`linear-gradient(90deg, ${ud(i,9,t).join(", ")})`}const Ch=3e3;function Dp(i,t){if(typeof t!="number"||!Number.isFinite(t))return-1;for(let e=0;e<i.length;e++){const n=i[e];if((e===0?t>=n.min:t>n.min)&&t<=n.max)return e}return-1}function Ix(i,t){for(let e=0;e<i.length;e++)if(i[e].value===t)return e;return-1}function Gp(i){const t=i.flatMap(s=>[s.min,s.max]);if(t.every(s=>Number.isInteger(s)))return 0;const e=i.map(s=>s.max-s.min).filter(s=>s>0),n=e.length>0?Math.min(...e):Math.abs(t[0]||1);return Math.max(0,Math.min(6,2-Math.floor(Math.log10(n))))}function Bp(i,t,e){return i===t?i.toFixed(e):`${i.toFixed(e)} - ${t.toFixed(e)}`}function Er(i,t,e,n,s=!1){const r=[];e.forEach(h=>{(r.length===0?h>=t:h>r[r.length-1])&&r.push(h)}),r.length===0&&r.push(t);const o=ud(n,r.length,s),a=r.map((h,f)=>({min:f===0?t:r[f-1],max:h,color:o[f],label:"",count:0}));i.forEach(h=>{const f=Dp(a,h);f>=0&&(a[f].count+=1)});const l=Gp(a);return a.forEach(h=>h.label=Bp(h.min,h.max,l)),a}function vc(i){return i.filter(t=>typeof t=="number"&&Number.isFinite(t)).sort((t,e)=>t-e)}function Sx(i,t,e="viridis",n=!1){const s=vc(i);if(s.length===0||t<=0)return[];const r=s[0],o=s[s.length-1];if(r===o)return Er(s,r,[o],e,n);const a=(o-r)/t,l=Array.from({length:t},(h,f)=>f===t-1?o:r+(f+1)*a);return Er(s,r,l,e,n)}function Mx(i,t,e="viridis",n=!1){const s=vc(i);if(s.length===0||t<=0)return[];const r=s.length,o=Array.from({length:t},(a,l)=>l===t-1?s[r-1]:s[Math.max(0,Math.ceil((l+1)*r/t)-1)]);return Er(s,s[0],o,e,n)}function Nx(i,t,e="viridis",n=!1){const s=vc(i);if(s.length===0||t<=0)return[];let r=s;if(s.length>Ch){const p=(s.length-1)/(Ch-1);r=Array.from({length:Ch},(y,_)=>s[Math.round(_*p)])}const o=r.length,a=Math.min(t,o);if(a<=1)return Er(s,s[0],[s[s.length-1]],e,n);const l=Array.from({length:o+1},()=>Array(a+1).fill(0)),h=Array.from({length:o+1},()=>Array(a+1).fill(0));for(let p=1;p<=a;p++){l[1][p]=1;for(let y=2;y<=o;y++)h[y][p]=1/0}for(let p=2;p<=o;p++){let y=0,_=0,E=0,w=0;for(let L=1;L<=p;L++){const b=p-L+1,P=r[b-1];E++,y+=P,_+=P*P,w=_-y*y/E;const N=b-1;if(N!==0)for(let S=2;S<=a;S++)h[p][S]>=w+h[N][S-1]&&(l[p][S]=b,h[p][S]=w+h[N][S-1])}l[p][1]=1,h[p][1]=w}const f=Array(a+1).fill(0);f[a]=o;for(let p=a;p>=2;p--)f[p-1]=l[f[p]][p]-1;const d=Array.from({length:a},(p,y)=>y===a-1?s[s.length-1]:r[f[y+1]-1]);return Er(s,s[0],d,e,n)}function AO(i){const t=Math.floor(Math.log10(i)),e=i/Math.pow(10,t);return(e<=1?1:e<=2?2:e<=5?5:10)*Math.pow(10,t)}function Lx(i,t,e="viridis",n=!1){const s=vc(i);if(s.length===0||t<=0)return[];const r=s[0],o=s[s.length-1];if(r===o)return Er(s,r,[o],e,n);const a=AO((o-r)/t),l=Math.max(0,-Math.floor(Math.log10(a))+1),h=d=>Number(d.toFixed(l)),f=[];for(let d=h((Math.floor(r/a)+1)*a);d<o;d=h(d+a))d>r&&f.push(d);return f.push(o),Er(s,r,f,e,n)}function Cx(i,t,e="viridis",n,s=!1){const r=vc(i),o=n??r[0]??t[0];return o===void 0?[]:Er(r,o,[...t].sort((a,l)=>a-l),e,s)}function fm(i,t,e,n="viridis",s=!1){switch(i){case"equal_interval":return Sx(t,e,n,s);case"natural_breaks":return Nx(t,e,n,s);case"pretty_breaks":return Lx(t,e,n,s);case"manual":case"quantile":default:return Mx(t,e,n,s)}}function Px(i,t){const e=r=>typeof r=="number"?0:typeof r=="boolean"?1:2,n=e(i),s=e(t);return n!==s?n-s:typeof i=="number"&&typeof t=="number"?i-t:String(i).localeCompare(String(t),void 0,{numeric:!0})}function dm(i,t="category10",e=!1){const n=new Map;i.forEach(o=>{o!=null&&(typeof o=="number"&&!Number.isFinite(o)||n.set(o,(n.get(o)||0)+1))});const s=Array.from(n.keys()).sort(Px),r=ud(t,s.length,e);return s.map((o,a)=>({value:o,color:r[a],label:String(o),count:n.get(o)}))}const cd="#3b82f6",Da={kind:"lines",color:cd,spacing:8,angleDeg:45,lineWidth:1};function kx(i=cd){return{fill:{color:i,opacity:.65,style:"solid",outlineColor:"#ffffff",outlineWidth:1.5,outlineOpacity:1},line:{color:i,width:3,opacity:1,cap:"round",join:"round"},marker:{shape:"circle",size:12,color:i,opacity:1,strokeColor:"#ffffff",strokeWidth:1.5,allowOverlap:!0}}}function Ma(i){return i===void 0?i:JSON.parse(JSON.stringify(i))}function Tx(i,t){const e=Ma(i);return t&&(t.fill&&Object.assign(e.fill,Ma(t.fill)),t.line&&Object.assign(e.line,Ma(t.line)),t.marker&&Object.assign(e.marker,Ma(t.marker))),e}function Fo(i){const t=i.simpleStyle||{},n=t.fillColor??t.circleColor??(i.type==="simple"?i.defaultColor:void 0)??cd,s=kx(n);t.circleColor&&(s.marker.color=t.circleColor),t.fillOpacity!==void 0&&(s.fill.opacity=t.fillOpacity),t.strokeColor&&(s.fill.outlineColor=t.strokeColor,s.marker.strokeColor=t.strokeColor),t.strokeWidth!==void 0&&(s.line.width=t.strokeWidth,s.marker.strokeWidth=t.strokeWidth),t.strokeOpacity!==void 0&&(s.line.opacity=t.strokeOpacity),t.circleRadius!==void 0&&(s.marker.size=t.circleRadius*2);const r=Tx(s,i.baseSymbol);return r.fill.style==="pattern"&&!r.fill.pattern&&(r.fill.pattern={...Da,color:r.fill.color}),r}function Ph(i,t,e,n){const s=Ma(i),r=(n==null?void 0:n.color)??t;r&&(s.fill.color=r,s.line.color=r,s.marker.color=r),s.fill.style==="pattern"&&s.fill.pattern&&(r&&(s.fill.pattern={...s.fill.pattern,color:r}),s.fill.patternBackground&&(s.fill.color=i.fill.color));const o=(n==null?void 0:n.size)??e;return o!==void 0&&(s.line.width=o,s.marker.size=o),n&&(n.opacity!==void 0&&(s.fill.opacity=n.opacity,s.line.opacity=n.opacity,s.marker.opacity=n.opacity),n.strokeColor!==void 0&&(s.fill.outlineColor=n.strokeColor,s.marker.strokeColor=n.strokeColor),n.strokeWidth!==void 0&&(s.fill.outlineWidth=n.strokeWidth,s.marker.strokeWidth=n.strokeWidth),n.pattern===null?(s.fill.style==="pattern"&&(s.fill.style="solid"),delete s.fill.pattern):n.pattern&&(s.fill.style="pattern",s.fill.pattern=Ma(n.pattern)),n.shape!==void 0&&(s.marker.shape=n.shape),n.icon!==void 0&&(s.marker.icon=n.icon),n.rotationDeg!==void 0&&(s.marker.rotationDeg=n.rotationDeg)),s}function OO(i,t,e,n){if(i.type!=="graduated"||i.graduatedMode!=="size")return t.map(()=>{});const s=n==="line"?[1,e.line.width*3]:[4,e.marker.size*2],[r,o]=i.sizeRange??s,a=t.length;return t.map((l,h)=>l.size??(a===1?o:r+(o-r)*h/(a-1)))}function qp(i,t){const e=Fo(i),n=[];if(i.type==="graduated"&&i.fieldName&&i.breaks&&i.breaks.length>0){const s=OO(i,i.breaks,e,t),r=i.graduatedMode==="size";i.breaks.forEach((o,a)=>{n.push({index:a,label:o.label,visible:o.visible!==!1,symbol:Ph(e,r?void 0:o.color,s[a],o.symbol),min:o.min,max:o.max,count:o.count})})}else if(i.type==="categorical"&&i.fieldName&&i.categories&&i.categories.length>0)i.categories.forEach((s,r)=>{n.push({index:r,label:s.label,visible:s.visible!==!1,symbol:Ph(e,s.color,void 0,s.symbol),value:s.value,count:s.count})});else return[{index:0,label:"",visible:!0,symbol:e}];return n.push({index:-1,label:i.otherLabel??"Other values",visible:i.showOther!==!1,symbol:Ph(e,i.defaultColor,void 0)}),n}function Rx(i,t){return t==="line"?i.line:t==="polygon"?i.fill:i.marker}function G_(i,t=0){return Array.from({length:i},(e,n)=>{const s=(t+360*n/i-90)*Math.PI/180;return[Math.cos(s),Math.sin(s)]})}function FO(i,t){return Array.from({length:i*2},(e,n)=>{const s=n%2===0?1:t,r=(180*n/i-90)*(Math.PI/180);return[s*Math.cos(r),s*Math.sin(r)]})}function B_(i){const t=i;return[[-t,-1],[t,-1],[t,-t],[1,-t],[1,t],[t,t],[t,1],[-t,1],[-t,t],[-1,t],[-1,-t],[-t,-t]]}function $O(i,t){const e=t*Math.PI/180,n=Math.cos(e),s=Math.sin(e);return i.map(([r,o])=>[r*n-o*s,r*s+o*n])}const DO={square:[[-.8,-.8],[.8,-.8],[.8,.8],[-.8,.8]],diamond:[[0,-1],[1,0],[0,1],[-1,0]],triangle:[[0,-1],[.95,.72],[-.95,.72]],star:FO(5,.45),pentagon:G_(5),hexagon:G_(6,30),cross:B_(.28),x:$O(B_(.24),45)},Vu=["circle","square","diamond","triangle","star","pentagon","hexagon","cross","x"];function zp(i){return i==="circle"||i==="icon"?null:DO[i]??null}function Ax(i,t,e,n){const s=zp(i);return s?s.map(([r,o],a)=>`${a===0?"M":"L"} ${(t+r*n).toFixed(2)} ${(e+o*n).toFixed(2)}`).join(" ")+" Z":`M ${t-n} ${e} a ${n} ${n} 0 1 0 ${n*2} 0 a ${n} ${n} 0 1 0 ${-n*2} 0 Z`}const Up=new Map,gm=new Set;function GO(i,t,e={}){if(!i.trim())throw new Error("Marker icon name must not be empty");Up.set(i,{source:t,sdf:e.sdf??!0}),gm.forEach(n=>n(i))}function Yp(i){return Up.get(i)}function Xp(){return Array.from(Up.keys())}function Ox(i){return gm.add(i),()=>gm.delete(i)}function jp(i){return i.trimStart().startsWith("<svg")||i.trimStart().startsWith("<?xml")}const xg=8,q_=1024;function BO(i,t){for(i=Math.abs(i),t=Math.abs(t);t;)[i,t]=[t,i%t];return i}function Fx(i,t,e){const n=(i%180+180)%180;let s={a:1,b:0,error:Math.min(n,180-n)};for(let r=-xg;r<=xg;r++)for(let o=0;o<=xg;o++){if(r===0&&o===0||BO(r,o)!==1||e*Math.hypot(r,o)>t)continue;const a=(Math.atan2(o,r)*180/Math.PI+180)%180,l=Math.abs(a-n),h=Math.min(l,180-l),f=Math.hypot(r,o)<Math.hypot(s.a,s.b);(h<s.error-1e-9||Math.abs(h-s.error)<=1e-9&&f)&&(s={a:r,b:o,error:h})}return{a:s.a,b:s.b}}function $x(i,t=1){const e=Math.max(1,t),n=Math.max(i.spacing,1),{a:s,b:r}=Fx(i.angleDeg,q_/e/2,n),o=Math.hypot(s,r),a=Math.max(1,Math.round(n*o*e)),l=a/o,h=[s/o,-r/o],f=[r/o,s/o];let d=null,p=1;const y=(i.dash??[]).map(S=>S*e).filter(S=>S>0);if(i.kind!=="dots"&&y.length>0){const S=y.reduce((I,M)=>I+M,0)*(y.length%2===1?2:1),C=y.length%2===1?[...y,...y]:y;let T;S<=l?T=l/Math.max(1,Math.round(l/S)):(p=Math.max(1,Math.round(S/l)),T=l*p),a*p<=q_?d=C.map(I=>I*T/S):p=1}const _=a*p,E=Math.max(i.lineWidth,.1)*e,w=[],L=[],b=[[-_,-_],[_*2,-_],[-_,_*2],[_*2,_*2]],P=_*4+E,N=(S,C)=>{const T=b.map(([$,z])=>$*C[0]+z*C[1]),I=Math.floor((Math.min(...T)-E)/l)-1,M=Math.ceil((Math.max(...T)+E)/l)+1,R=d?d.reduce(($,z)=>$+z,0):1,A=-Math.ceil(P/R)*R,F=Math.ceil(P/R)*R;for(let $=I;$<=M;$++){const z=$*l*C[0],D=$*l*C[1];w.push([z+A*S[0],D+A*S[1],z+F*S[0],D+F*S[1]])}};if(i.kind==="dots"){const S=E/2,C=Math.ceil(_*3/l)+1;for(let T=-C;T<=C;T++)for(let I=-C;I<=C;I++){const M=T*l*h[0]+I*l*f[0],R=T*l*h[1]+I*l*f[1];M>=-_-S&&M<=_*2+S&&R>=-_-S&&R<=_*2+S&&L.push([M,R])}}else N(h,f),i.kind==="cross"&&N(f,[-h[0],-h[1]]);return{size:_,pixelRatio:e,color:i.color,lineWidth:E,segments:w,dots:L,dash:d,effectiveAngleDeg:(Math.atan2(r,s)*180/Math.PI+180)%180,effectiveSpacing:l/e}}function Dx(i){let t=2166136261;for(let e=0;e<i.length;e++)t^=i.charCodeAt(e),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function Gx(i){const t=JSON.stringify([i.kind,i.color,i.spacing,i.angleDeg,i.lineWidth,i.dash??[]]);return`ofs-hatch-${Dx(t)}`}const vu=1e20;function z_(i,t,e,n,s,r,o){r[0]=0,o[0]=-vu,o[1]=vu,s[0]=i[t];for(let a=1,l=0,h=0;a<n;a++){s[a]=i[t+a*e];const f=a*a;do{const d=r[l];h=(s[a]-s[d]+f-d*d)/(a-d)/2}while(h<=o[l]&&--l>-1);l++,r[l]=a,o[l]=h,o[l+1]=vu}for(let a=0,l=0;a<n;a++){for(;o[l+1]<a;)l++;const h=r[l],f=a-h;i[t+a*e]=s[h]+f*f}}function U_(i,t,e){const n=Math.max(t,e),s=new Float64Array(n),r=new Float64Array(n+1),o=new Uint16Array(n);for(let a=0;a<t;a++)z_(i,a,t,e,s,o,r);for(let a=0;a<e;a++)z_(i,a*t,1,t,s,o,r)}function Bx(i,t,e,n=8,s=.25){const r=t*e,o=new Float64Array(r),a=new Float64Array(r);for(let h=0;h<r;h++){const f=i[h]/255;if(f>=1)o[h]=0,a[h]=vu;else if(f<=0)o[h]=vu,a[h]=0;else{const d=.5-f;o[h]=d>0?d*d:0,a[h]=d<0?d*d:0}}U_(o,t,e),U_(a,t,e);const l=new Uint8ClampedArray(r);for(let h=0;h<r;h++){const f=Math.sqrt(o[h])-Math.sqrt(a[h]);l[h]=Math.round(255-255*(f/n+s))}return l}const xf="_ofs_label",Ec=24,Hu=8,$o=2;function qx(i,t){return i==="icon"?`ofs-icon-${t??""}`:`ofs-marker-${i}`}const mm={polygon:["match",["geometry-type"],["Polygon","MultiPolygon"],!0,!1],line:["match",["geometry-type"],["LineString","MultiLineString"],!0,!1],point:["match",["geometry-type"],["Point","MultiPoint"],!0,!1]},qO={center:[0,0],left:[-1,0],right:[1,0],top:[0,-1],bottom:[0,1],"top-left":[-1,-1],"top-right":[1,-1],"bottom-left":[-1,1],"bottom-right":[1,1]};function zO(i){return Number.isInteger(i)&&Math.abs(i)<=Number.MAX_SAFE_INTEGER}function zx(i){const t=i.fieldName;if(!t)return null;const e=["get",t];if(i.type==="graduated"&&i.breaks&&i.breaks.length>0){const n=["to-number",e],s=[];return i.breaks.forEach((r,o)=>{s.push(["all",[o===0?">=":">",n,r.min],["<=",n,r.max]],o)}),["case",["!=",["typeof",e],"number"],-1,...s,-1]}if(i.type==="categorical"&&i.categories&&i.categories.length>0){const n=[],s=[],r=[],o=[],a=new Set;i.categories.forEach((h,f)=>{const d=`${typeof h.value}:${String(h.value)}`;h.value===null||h.value===void 0||a.has(d)||(a.add(d),typeof h.value=="string"?n.push(h.value,f):typeof h.value=="boolean"?o.push(["==",["to-boolean",e],h.value],f):typeof h.value=="number"&&zO(h.value)?s.push(h.value,f):typeof h.value=="number"&&Number.isFinite(h.value)&&r.push(["==",["to-number",e],h.value],f))});const l=[];if(n.length>0&&l.push(["==",["typeof",e],"string"],["match",["to-string",e],...n,-1]),s.length>0||r.length>0){const h=[];s.length>0&&h.push(["match",["to-number",e],...s,-1]);const f=r.length>0?["case",...r,s.length>0?h[0]:-1]:h[0];l.push(["==",["typeof",e],"number"],f)}return o.length>0&&l.push(["==",["typeof",e],"boolean"],["case",...o,-1]),l.length===0?null:["case",...l,-1]}return null}function Ve(i,t,e){const n=t.map(e),s=JSON.stringify(n[0]);if(!i||n.every(a=>JSON.stringify(a)===s))return n[0];const r=t.find(a=>a.index===-1),o=[];return t.forEach((a,l)=>{a.index>=0&&o.push(a.index,n[l])}),["match",i,...o,r?e(r):n[0]]}function ho(i,t){return t===1?i:typeof i=="number"?i*t:["*",t,i]}function Y_(i,t,e){const n=t.filter(e).map(s=>s.index);return i?n.length===t.length?null:n.length===0?["boolean",!1]:["match",i,n,!0,!1]:n.length>0?null:["boolean",!1]}function X_(...i){const t=i.filter(e=>e!==null);return t.length===1?t[0]:["all",...t]}function j_(i,t){const e=(i??[]).filter(n=>Number.isFinite(n)&&n>=0);if(!(e.length<2||e.every(n=>n===0)))return e.map(n=>n/Math.max(t,.01))}class Ux{static compile(t,e,n={}){const s=n.layerId??t.layerId,r=Math.max(0,Math.min(1,n.opacity??1)),o=t.highlightColor||"#FFFD3D",a=t.enableSelectionHighlight??!0,l=["boolean",["feature-state","selected"],!1],h=P=>a?["case",l,o,P]:P,f=qp(t,e),d=f.length>1?zx(t):null,p=Y_(d,f,P=>P.visible),y=e==="line"?"line":e==="polygon"?"polygon":"point",_=X_(mm[y],p),E=f.find(P=>P.index===0)??f[0],w=[],L=new Map;if(y==="polygon"){const P=E.symbol.fill,N=P.offset??[0,0],S=A=>{const F=A.symbol.fill;return F.style==="none"||F.style==="pattern"&&!F.patternBackground?0:F.opacity},C=ho(Ve(d,f,S),r),T=ho(Ve(d,f,A=>Math.max(S(A),.35)),r);w.push({id:s,role:"fill",type:"fill",filter:_,paint:{"fill-color":h(Ve(d,f,A=>A.symbol.fill.color)),"fill-opacity":a?["case",l,T,C]:C,"fill-translate":N},layout:{visibility:"visible"}});const I=A=>A.symbol.fill.style==="pattern"&&!!A.symbol.fill.pattern;if(f.some(I)){const A=$=>{if(!I($))return null;const z=Gx($.symbol.fill.pattern);return L.set(z,{id:z,kind:"hatch",pattern:$.symbol.fill.pattern}),z},F=f.map(A).find($=>!!$);w.push({id:`${s}_pattern`,role:"pattern",type:"fill",filter:X_(mm.polygon,Y_(d,f,$=>$.visible&&I($))),paint:{"fill-pattern":Ve(d,f,$=>A($)??F),"fill-opacity":ho(Ve(d,f,$=>$.symbol.fill.opacity),r),"fill-translate":N},layout:{visibility:"visible"}})}const M={"line-color":Ve(d,f,A=>A.symbol.fill.outlineColor),"line-width":Ve(d,f,A=>A.symbol.fill.outlineWidth),"line-opacity":ho(Ve(d,f,A=>A.symbol.fill.outlineOpacity),r),"line-translate":N},R=j_(P.outlineDash,P.outlineWidth);R&&(M["line-dasharray"]=R),w.push({id:`${s}_stroke`,role:"stroke",type:"line",filter:_,paint:M,layout:{visibility:"visible","line-join":"round"}})}else if(y==="line"){const P=E.symbol.line,N={"line-color":h(Ve(d,f,C=>C.symbol.line.color)),"line-width":Ve(d,f,C=>C.symbol.line.width),"line-opacity":ho(Ve(d,f,C=>C.symbol.line.opacity),r)},S=j_(P.dash,P.width);S&&(N["line-dasharray"]=S),P.offset&&(N["line-offset"]=P.offset),w.push({id:s,role:"line",type:"line",filter:_,paint:N,layout:{visibility:"visible","line-cap":P.cap??"round","line-join":P.join??"round"}})}else{const P=E.symbol.marker,N=P.offset??[0,0];if(f.some(C=>C.symbol.marker.shape!=="circle")){const C=R=>{const A=R.symbol.marker,F=qx(A.shape,A.icon);return A.shape==="icon"?L.set(F,{id:F,kind:"icon",icon:A.icon??""}):L.set(F,{id:F,kind:"marker",shape:A.shape}),F},T=P.anchor??"center",I=qO[T],M=P.allowOverlap??!0;w.push({id:s,role:"marker",type:"symbol",filter:_,paint:{"icon-color":h(Ve(d,f,R=>R.symbol.marker.color)),"icon-opacity":ho(Ve(d,f,R=>R.symbol.marker.opacity),r),"icon-halo-color":Ve(d,f,R=>R.symbol.marker.strokeColor),"icon-halo-width":Ve(d,f,R=>R.symbol.marker.strokeWidth),"icon-translate":N},layout:{visibility:"visible","icon-image":Ve(d,f,C),"icon-size":Ve(d,f,R=>R.symbol.marker.size/Ec),"icon-rotate":Ve(d,f,R=>R.symbol.marker.rotationDeg??0),"icon-anchor":T,"icon-offset":[I[0]*Hu,I[1]*Hu],"icon-allow-overlap":M,"icon-ignore-placement":M}})}else{const C=ho(Ve(d,f,T=>T.symbol.marker.opacity),r);w.push({id:s,role:"circle",type:"circle",filter:_,paint:{"circle-color":h(Ve(d,f,T=>T.symbol.marker.color)),"circle-radius":Ve(d,f,T=>T.symbol.marker.size/2),"circle-opacity":C,"circle-stroke-color":Ve(d,f,T=>T.symbol.marker.strokeColor),"circle-stroke-width":Ve(d,f,T=>T.symbol.marker.strokeWidth),"circle-stroke-opacity":C,"circle-translate":N},layout:{visibility:"visible"}})}}const b=jx(t.label,s,y,r);return b&&w.push(b),{paint:w[0].paint,layout:{visibility:"visible"},layers:w,images:Array.from(L.values())}}}function Yx(i){return!!i&&i.enabled!==!1&&!!i.expression}function Xx(i){return!!i&&i.enabled!==!1&&!!(i.field||i.expression)}function jx(i,t,e,n=1){if(!Xx(i))return null;const s=i,r=s.size??12,o=s.allowOverlap??!1,l={visibility:"visible","text-field":s.expression?["coalesce",["get",xf],""]:s.decimals!==void 0?["case",["==",["typeof",["get",s.field]],"number"],["number-format",["get",s.field],{"min-fraction-digits":s.decimals,"max-fraction-digits":s.decimals}],["to-string",["coalesce",["get",s.field],""]]]:["to-string",["coalesce",["get",s.field],""]],"text-size":r,"text-anchor":s.anchor??"center","text-max-width":s.maxWidth??10,"text-allow-overlap":o,"text-ignore-placement":o,"symbol-placement":s.placement==="line"&&e!=="point"?"line":"point"};s.font&&(l["text-font"]=s.font),s.offset&&(l["text-offset"]=s.offset),s.rotationDeg&&(l["text-rotate"]=s.rotationDeg),s.transform&&s.transform!=="none"&&(l["text-transform"]=s.transform),s.priorityField&&(l["symbol-sort-key"]=["-",0,["to-number",["coalesce",["get",s.priorityField],0]]]);const h={"text-color":s.color??"#1f2937","text-halo-color":s.haloColor??"#ffffff","text-halo-width":s.haloWidth??1.2,"text-opacity":Math.max(0,Math.min(1,(s.opacity??1)*n))},f={id:`${t}_label`,role:"label",type:"symbol",filter:mm[e],paint:h,layout:l};return s.minZoom!==void 0&&(f.minzoom=s.minZoom),s.maxZoom!==void 0&&(f.maxzoom=s.maxZoom),f}const V_="#94a3b8";function vi(i){return i===void 0?i:JSON.parse(JSON.stringify(i))}function UO(i,t){const e=vi(i)??{};return["fill","line","marker"].forEach(n=>{t[n]&&(e[n]={...e[n],...vi(t[n])})}),e}function kh(i,t){var n;const e=[];for(const s of i.getFeatures()){const r=(n=s.properties)==null?void 0:n[t];typeof r=="number"&&Number.isFinite(r)&&e.push(r)}return e}function Vx(i,t){var r,o,a;const e=new Map,n=i.fieldName,s=n&&(i.type==="graduated"&&((r=i.breaks)==null?void 0:r.length)||i.type==="categorical"&&((o=i.categories)==null?void 0:o.length));for(const l of t.getFeatures()){let h=0;if(s){const f=(a=l.properties)==null?void 0:a[n];h=i.type==="graduated"?Dp(i.breaks,f):Ix(i.categories,f)}e.set(h,(e.get(h)??0)+1)}return e}class Wu extends jr{constructor(){super();Y(this,"themes",new Map)}getTheme(e){return this.themes.get(e)}setTheme(e){this.themes.set(e.layerId,e),this.emit("theme:changed",{layerId:e.layerId,theme:e})}removeTheme(e){this.themes.delete(e)}exportThemes(){return Array.from(this.themes.values()).map(e=>vi(e))}importThemes(e){e.forEach(n=>this.setTheme(vi(n)))}carriedSymbol(e,n){var s;return vi(n??((s=this.themes.get(e))==null?void 0:s.baseSymbol))}createSimpleTheme(e,n={},s="#3b82f6"){const r=n.fillColor??n.circleColor??s,o=this.carriedSymbol(e);o!=null&&o.fill&&(delete o.fill.color,o.fill.pattern&&(o.fill.pattern.color=r)),o!=null&&o.line&&delete o.line.color,o!=null&&o.marker&&delete o.marker.color;const a={type:"simple",layerId:e,defaultColor:s,simpleStyle:{fillColor:s,strokeColor:"#ffffff",strokeWidth:2,fillOpacity:.65,circleColor:s,circleRadius:6,...n},baseSymbol:o};return this.setTheme(a),a}createCategoricalTheme(e,n,s="category10",r=V_,o={}){var h;const a=[];for(const f of e.getFeatures()){const d=(h=f.properties)==null?void 0:h[n];d!=null&&a.push(d)}const l={type:"categorical",layerId:e.id,fieldName:n,paletteName:s,defaultColor:r,categories:dm(a,s,o.reverse),baseSymbol:this.carriedSymbol(e.id,o.baseSymbol)};return this.setTheme(l),l}createGraduatedTheme(e,n,s="quantile",r=5,o="viridis",a=V_,l={}){const h=fm(s,kh(e,n),r,o,l.reverse),f={type:"graduated",layerId:e.id,fieldName:n,classificationMethod:s,classCount:r,paletteName:o,defaultColor:a,breaks:h,graduatedMode:l.mode??"color",sizeRange:l.sizeRange,baseSymbol:this.carriedSymbol(e.id,l.baseSymbol)};return this.setTheme(f),f}setManualBreaks(e,n,s){const r=this.requireTheme(e.id);if(r.type!=="graduated"||!r.fieldName)throw new Error(`Layer "${e.id}" does not have a graduated theme`);const o={...vi(r),classificationMethod:"manual",classCount:n.length,breaks:Cx(kh(e,r.fieldName),n,r.paletteName??"viridis",s)};return this.setTheme(o),o}reclassify(e){var r;const n=this.themes.get(e.id);if(!n||!n.fieldName||n.type==="simple")return n;const s=vi(n);if(n.type==="categorical"){const o=this.createCategoricalThemeData(e,n);s.categories=o.map(a=>{var h;const l=(h=n.categories)==null?void 0:h.find(f=>f.value===a.value);return l?{...a,color:l.color,label:l.label,visible:l.visible,symbol:l.symbol}:a})}else if(n.classificationMethod!=="manual"){const o=fm(n.classificationMethod??"quantile",kh(e,n.fieldName),n.classCount??((r=n.breaks)==null?void 0:r.length)??5,n.paletteName??"viridis");s.breaks=o.map((a,l)=>{var f;const h=(f=n.breaks)==null?void 0:f[l];return h?{...a,visible:h.visible,symbol:h.symbol,size:h.size}:a})}return this.setTheme(s),s}createCategoricalThemeData(e,n){var r;const s=[];for(const o of e.getFeatures()){const a=(r=o.properties)==null?void 0:r[n.fieldName];a!=null&&s.push(a)}return dm(s,n.paletteName??"category10")}updateBaseSymbol(e,n){const s=vi(this.themes.get(e))??this.defaultTheme(e);return s.baseSymbol=UO(s.baseSymbol,n),this.setTheme(s),s}setLabel(e,n){const s=vi(this.themes.get(e))??this.defaultTheme(e);if(!n)delete s.label;else{const r={...s.label??{},...n};if(n.field!==void 0&&n.expression===void 0&&delete r.expression,n.expression!==void 0&&n.field===void 0&&delete r.field,!r.field&&!r.expression)throw new Error("Labels need a field or an expression");s.label=r}return this.setTheme(s),s}getLabel(e){var n;return(n=this.themes.get(e))==null?void 0:n.label}setClassVisible(e,n,s){const r=vi(this.requireTheme(e));if(n===-1)r.showOther=s;else{const o=this.classList(r)[n];if(!o)throw new Error(`Layer "${e}" has no class ${n}`);o.visible=s}this.setTheme(r)}setAllClassesVisible(e,n){const s=vi(this.requireTheme(e));this.classList(s).forEach(r=>r.visible=n),s.showOther=n,this.setTheme(s)}updateClass(e,n,s){const r=vi(this.requireTheme(e)),a=this.classList(r)[n];if(!a)throw new Error(`Layer "${e}" has no class ${n}`);if(s.color!==void 0&&(a.color=s.color),s.visible!==void 0&&(a.visible=s.visible),s.size!==void 0&&(a.size=s.size),s.symbol===null?delete a.symbol:s.symbol&&(a.symbol={...a.symbol,...vi(s.symbol)}),r.type==="graduated"&&(s.min!==void 0||s.max!==void 0)){const l=r.breaks,h=l[n];if(s.max!==void 0){const f=l[n+1];f&&f.min===h.max&&(f.min=s.max),h.max=s.max}if(s.min!==void 0){const f=l[n-1];f&&f.max===h.min&&(f.max=s.min),h.min=s.min}if(r.classificationMethod="manual",s.label===void 0){const f=Gp(l);l.forEach(d=>d.label=Bp(d.min,d.max,f))}}s.label!==void 0&&(a.label=s.label),this.setTheme(r)}classList(e){return e.type==="graduated"?e.breaks??[]:e.type==="categorical"?e.categories??[]:[]}requireTheme(e){const n=this.themes.get(e);if(!n)throw new Error(`Layer "${e}" has no theme`);return n}defaultTheme(e){return{type:"simple",layerId:e,defaultColor:"#3b82f6",simpleStyle:{fillColor:"#3b82f6",strokeColor:"#ffffff",strokeWidth:2,fillOpacity:.65,circleColor:"#3b82f6",circleRadius:6}}}getEffectiveTheme(e){let n=this.themes.get(e);return n||(n=this.defaultTheme(e),this.themes.set(e,n)),n}compile(e){return Ux.compile(this.getEffectiveTheme(e.id),e.type,{layerId:e.id,opacity:e.opacity??1})}}class Hx extends jr{constructor(e,n){super();Y(this,"dataSource");Y(this,"thematicEngine");Y(this,"unsubscribers",[]);Y(this,"groupCounter",0);this.dataSource=e,this.thematicEngine=n||new Wu,this.bindDataSourceEvents()}bindDataSourceEvents(){if(["layer:added","layer:removed","layer:updated","features:changed","active-layer:changed","group:added","group:removed","group:updated"].forEach(n=>{const s=this.dataSource.on(n,()=>{this.notifyUpdate()});this.unsubscribers.push(s)}),this.thematicEngine){const n=this.thematicEngine.on("theme:changed",()=>{this.notifyUpdate()});this.unsubscribers.push(n)}}getSnapshot(){const n=this.dataSource.getAllLayers().sort((r,o)=>o.zIndex-r.zIndex).map(r=>{const o=this.thematicEngine.getEffectiveTheme(r.id),a=Vx(o,r),l=[];return qp(o,r.type).forEach(h=>{const f=Rx(h.symbol,r.type),d="style"in f&&f.style==="pattern"&&f.pattern?f.pattern.color:f.color;if(o.type==="simple"||h.index>=0){l.push({label:o.type==="simple"?r.name:h.label,color:d,count:o.type==="simple"?r.count:a.get(h.index)??0,min:h.min,max:h.max,value:h.value,index:h.index,visible:h.visible,symbol:h.symbol});return}const p=a.get(-1)??0;(o.type==="categorical"||p>0)&&l.push({label:h.label,color:d,count:p,index:-1,visible:h.visible,symbol:h.symbol})}),{id:r.id,name:r.name,type:r.type,visible:r.visible,rendered:this.dataSource.isLayerRendered(r.id),opacity:r.opacity,zIndex:r.zIndex,pinned:r.pinned,groupId:r.groupId&&this.dataSource.getLayerGroup(r.groupId)?r.groupId:null,featureCount:r.count,thematicType:o.type,fieldName:o.fieldName,classificationMethod:o.classificationMethod,graduatedMode:o.type==="graduated"?o.graduatedMode??"color":void 0,paletteName:o.paletteName,items:l}}),s=this.dataSource.getLayerGroups().map(r=>({...r,rendered:this.isGroupRendered(r.id)}));return{layers:n,tree:this.buildTree(n,s),groups:s,activeLayerId:this.dataSource.getActiveLayerId(),totalLayers:n.length}}isGroupRendered(e){for(let n=this.dataSource.getLayerGroup(e);n;n=n.parentId?this.dataSource.getLayerGroup(n.parentId):void 0)if(!n.visible)return!1;return!0}buildTree(e,n){const s=new Map,r=a=>{if(s.has(a))return s.get(a);s.set(a,-1/0);let l=-1/0;return e.forEach(h=>h.groupId===a&&(l=Math.max(l,h.zIndex))),n.forEach(h=>h.parentId===a&&(l=Math.max(l,r(h.id)))),s.set(a,l),l},o=a=>{const l=[];return n.filter(h=>h.parentId===a).forEach(h=>l.push({z:r(h.id),node:{kind:"group",group:h,children:o(h.id)}})),e.filter(h=>h.groupId===a).forEach(h=>l.push({z:h.zIndex,node:{kind:"layer",layer:h}})),l.sort((h,f)=>f.z-h.z).map(h=>h.node)};return o(null)}notifyUpdate(){this.emit("legend:updated",{snapshot:this.getSnapshot()})}toggleLayerVisibility(e){const n=this.dataSource.getLayer(e);n&&this.dataSource.setLayerVisibility(e,!n.visible)}setLayerOpacity(e,n){this.dataSource.setLayerOpacity(e,n)}setActiveLayer(e){this.dataSource.setActiveLayer(e)}toggleLayerPinned(e){const n=this.dataSource.getLayer(e);n&&this.dataSource.setLayerPinned(e,!n.pinned)}moveLayerUp(e){this.moveNode({kind:"layer",id:e},-1)}moveLayerDown(e){this.moveNode({kind:"layer",id:e},1)}moveGroupUp(e){this.moveNode({kind:"group",id:e},-1)}moveGroupDown(e){this.moveNode({kind:"group",id:e},1)}nodeLayers(e){return e.kind==="layer"?[e.layer.id]:e.children.flatMap(n=>this.nodeLayers(n))}findSiblings(e,n){const s=e.findIndex(r=>(r.kind==="layer"?r.layer.id:r.group.id)===n.id&&r.kind===n.kind);if(s>=0)return{siblings:e,index:s};for(const r of e)if(r.kind==="group"){const o=this.findSiblings(r.children,n);if(o)return o}return null}moveNode(e,n){const s=this.getSnapshot().tree,r=this.findSiblings(s,e);if(!r)return;const o=this.nodeLayers(r.siblings[r.index]);if(o.length===0)return;let a=[];for(let f=r.index+n;f>=0&&f<r.siblings.length&&(a=this.nodeLayers(r.siblings[f]),!(a.length>0));f+=n);if(a.length===0)return;const l=s.flatMap(f=>this.nodeLayers(f)).filter(f=>!o.includes(f)),h=n===-1?l.indexOf(a[0]):l.indexOf(a[a.length-1])+1;l.splice(h,0,...o),this.dataSource.reorderLayers([...l].reverse())}addGroup(e,n=null,s){let r=s;for(;!r||this.dataSource.getLayerGroup(r);)r=`group_${++this.groupCounter}`;return this.dataSource.addLayerGroup({id:r,name:e,parentId:n}),r}removeGroup(e){this.dataSource.removeLayerGroup(e)}renameGroup(e,n){this.dataSource.updateLayerGroup(e,{name:n})}toggleGroupVisibility(e){const n=this.dataSource.getLayerGroup(e);n&&this.dataSource.updateLayerGroup(e,{visible:!n.visible})}toggleGroupExpanded(e){const n=this.dataSource.getLayerGroup(e);n&&this.dataSource.updateLayerGroup(e,{expanded:!n.expanded})}moveLayerToGroup(e,n){const s=this.dataSource.getLayer(e);if(!s)return;const r=this.dataSource.getAllLayers().filter(a=>a.id!==e&&(n===null?!0:this.dataSource.isLayerInGroup(a.id,n))).reduce((a,l)=>Math.max(a,l.zIndex),-1/0);this.dataSource.moveLayerToGroup(e,n),Number.isFinite(r)&&(s.zIndex=r+.5);const o=this.getSnapshot().tree.flatMap(a=>this.nodeLayers(a));this.dataSource.reorderLayers(o.reverse())}setThematicSimple(e,n){this.thematicEngine.createSimpleTheme(e,{fillColor:n,circleColor:n})}setThematicCategorical(e,n,s="category10",r={}){const o=this.dataSource.getLayer(e);o&&this.thematicEngine.createCategoricalTheme(o,n,s,void 0,r)}setThematicGraduated(e,n,s="quantile",r=5,o="viridis",a={}){const l=this.dataSource.getLayer(e);l&&this.thematicEngine.createGraduatedTheme(l,n,s,r,o,void 0,a)}reclassify(e){const n=this.dataSource.getLayer(e);n&&this.thematicEngine.reclassify(n)}updateBaseSymbol(e,n){this.thematicEngine.updateBaseSymbol(e,n)}setLabel(e,n){this.thematicEngine.setLabel(e,n)}getLabel(e){return this.thematicEngine.getLabel(e)}setClassVisible(e,n,s){this.thematicEngine.setClassVisible(e,n,s)}toggleClassVisible(e,n){var r;const s=(r=this.getSnapshot().layers.find(o=>o.id===e))==null?void 0:r.items.find(o=>o.index===n);s&&this.setClassVisible(e,n,!s.visible)}setAllClassesVisible(e,n){this.thematicEngine.setAllClassesVisible(e,n)}updateClass(e,n,s){this.thematicEngine.updateClass(e,n,s)}getThematicEngine(){return this.thematicEngine}getDataSource(){return this.dataSource}destroy(){this.unsubscribers.forEach(e=>e()),this.unsubscribers=[],this.removeAllListeners()}}let YO=0;function Tt(i){return String(i).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function Un(i,t=2){return Number.isFinite(i)?String(Number(i.toFixed(t))):"0"}function H_(i){const t=(i??[]).filter(e=>Number.isFinite(e)&&e>=0);return t.length>=2?` stroke-dasharray="${t.map(e=>Un(e)).join(" ")}"`:""}function bf(i,t,e=18){const n=e,s=`<svg xmlns="http://www.w3.org/2000/svg" width="${n}" height="${n}" viewBox="0 0 ${n} ${n}" class="ofs-swatch-svg">`;if(t==="line"){const d=i.line,p=Math.min(Math.max(d.width,.5),n/2);return`${s}<line x1="2" y1="${n/2}" x2="${n-2}" y2="${n/2}" stroke="${Tt(d.color)}" stroke-width="${Un(p)}" stroke-opacity="${Un(d.opacity)}" stroke-linecap="${Tt(d.cap??"round")}"${H_(d.dash)}/></svg>`}if(t==="polygon"){const d=i.fill,p=1.5,y=(L,b="")=>`<rect x="${p}" y="${p}" width="${n-p*2}" height="${n-p*2}" rx="2" fill="${L}"${b}/>`;let _="",E="";if((d.style==="solid"||d.style==="pattern"&&d.patternBackground)&&(_+=y(Tt(d.color),` fill-opacity="${Un(d.opacity)}"`)),d.style==="pattern"&&d.pattern){const L=d.pattern,b=`ofs-swatch-hatch-${++YO}`,P=Math.max(3,Math.min(L.spacing*.6,n/3)),N=Math.max(.75,Math.min(L.lineWidth,P/2)),S=Tt(L.color);let C="";L.kind==="dots"?C=`<circle cx="${P/2}" cy="${P/2}" r="${Un(N/2+.25)}" fill="${S}"/>`:(C=`<line x1="0" y1="${P/2}" x2="${P}" y2="${P/2}" stroke="${S}" stroke-width="${Un(N)}"/>`,L.kind==="cross"&&(C+=`<line x1="${P/2}" y1="0" x2="${P/2}" y2="${P}" stroke="${S}" stroke-width="${Un(N)}"/>`)),E=`<defs><pattern id="${b}" patternUnits="userSpaceOnUse" width="${P}" height="${P}" patternTransform="rotate(${Un(-L.angleDeg)})">${C}</pattern></defs>`,_+=y(`url(#${b})`,` fill-opacity="${Un(d.opacity)}"`)}const w=Math.min(d.outlineWidth,3);return w>0&&(_+=y("none",` stroke="${Tt(d.outlineColor)}" stroke-width="${Un(w)}" stroke-opacity="${Un(d.outlineOpacity)}"${H_(d.outlineDash)}`)),`${s}${E}${_}</svg>`}const r=i.marker,o=Math.min(r.strokeWidth,3),a=Math.max(2,Math.min(r.size,n-2)/2-o/2),l=n/2,h=r.rotationDeg?` transform="rotate(${Un(r.rotationDeg)} ${l} ${l})"`:"";if(r.shape==="icon"){const d=r.icon?Yp(r.icon):void 0;if(d){const p=jp(d.source)?`data:image/svg+xml;charset=utf-8,${encodeURIComponent(d.source)}`:d.source;return`${s}<image href="${Tt(p)}" x="${l-a}" y="${l-a}" width="${a*2}" height="${a*2}" opacity="${Un(r.opacity)}"${h}/></svg>`}}const f=r.shape==="icon"?"circle":r.shape;return`${s}<path d="${Ax(f,l,l,a)}" fill="${Tt(r.color)}" fill-opacity="${Un(r.opacity)}" stroke="${Tt(r.strokeColor)}" stroke-width="${Un(o)}"${h}/></svg>`}class XO{constructor(t,e={}){Y(this,"legendTools");Y(this,"container",null);Y(this,"unsubscriber",null);Y(this,"options");Y(this,"handleClick",t=>{var h,f,d,p,y,_;const e=t.target,n=e.closest("[data-action]"),s=n==null?void 0:n.dataset.action,r=(n==null?void 0:n.dataset.id)??"",o=this.legendTools;switch(s){case"add-group":{const E=typeof prompt=="function"?prompt("Group name:","New group"):"New group";E&&o.addGroup(E);return}case"group-expand":o.toggleGroupExpanded(r);return;case"group-up":o.moveGroupUp(r);return;case"group-down":o.moveGroupDown(r);return;case"group-remove":o.removeGroup(r);return;case"layer-pin":t.stopPropagation(),o.toggleLayerPinned(r);return;case"import":(f=(h=this.options).onImport)==null||f.call(h);return;case"layer-export":t.stopPropagation(),(p=(d=this.options).onExportLayer)==null||p.call(d,r);return;case"layer-style":t.stopPropagation(),(_=(y=this.options).onEditSymbology)==null||_.call(y,r);return;case"layer-up":t.stopPropagation(),o.moveLayerUp(r);return;case"layer-down":t.stopPropagation(),o.moveLayerDown(r);return}if(e.closest("input, select, button, label"))return;const a=e.closest(".ofs-legend-layer"),l=a==null?void 0:a.dataset.layerId;l&&o.setActiveLayer(l)});Y(this,"handleChange",t=>{const e=t.target,n=e.dataset.id??"";switch(e.dataset.action){case"layer-visible":this.legendTools.toggleLayerVisibility(n);return;case"group-visible":this.legendTools.toggleGroupVisibility(n);return;case"class-visible":this.legendTools.setClassVisible(n,Number(e.dataset.index),e.checked);return;case"layer-group":this.legendTools.moveLayerToGroup(n,e.value||null);return;case"layer-opacity":e.blur(),this.legendTools.notifyUpdate();return}});Y(this,"handleDoubleClick",t=>{const e=t.target.closest('[data-action="group-rename"]'),n=e==null?void 0:e.dataset.id;if(!n||typeof prompt!="function")return;const s=this.legendTools.getDataSource().getLayerGroup(n),r=prompt("Group name:",(s==null?void 0:s.name)??"");r&&this.legendTools.renameGroup(n,r)});Y(this,"handleInput",t=>{const e=t.target;e.dataset.action==="layer-opacity"&&e.dataset.id&&this.legendTools.setLayerOpacity(e.dataset.id,parseFloat(e.value))});this.legendTools=t,this.options=e}mount(t){const e=typeof t=="string"?document.getElementById(t):t;if(!e)throw new Error(`Target container for LegendWidget not found: ${t}`);this.container=e,this.container.classList.add("ofs-legend-container"),this.container.addEventListener("click",this.handleClick),this.container.addEventListener("change",this.handleChange),this.container.addEventListener("input",this.handleInput),this.container.addEventListener("dblclick",this.handleDoubleClick),this.unsubscriber=this.legendTools.on("legend:updated",({snapshot:n})=>{this.render(n)}),this.render(this.legendTools.getSnapshot())}unmount(){this.unsubscriber&&(this.unsubscriber(),this.unsubscriber=null),this.container&&(this.container.removeEventListener("click",this.handleClick),this.container.removeEventListener("change",this.handleChange),this.container.removeEventListener("input",this.handleInput),this.container.removeEventListener("dblclick",this.handleDoubleClick),this.container.innerHTML="",this.container=null)}render(t){var n;if(!this.container)return;const e=document.activeElement;if(e&&this.container.contains(e)&&e.classList.contains("ofs-opacity-slider")){const s=(n=e.parentElement)==null?void 0:n.querySelector(".ofs-opacity-val");s&&(s.textContent=`${Math.round(Number(e.value)*100)}%`);return}if(t.layers.length===0&&t.groups.length===0){this.container.innerHTML=`
|
|
27
|
+
<div class="ofs-legend-empty">
|
|
28
|
+
<div class="ofs-empty-icon">🗺️</div>
|
|
29
|
+
<div class="ofs-empty-text">No layers loaded</div>
|
|
30
|
+
</div>
|
|
31
|
+
`;return}this.container.innerHTML=`
|
|
32
|
+
<div class="ofs-legend-card">
|
|
33
|
+
<div class="ofs-legend-header">
|
|
34
|
+
<span class="ofs-legend-title">Layers & Symbology</span>
|
|
35
|
+
<span class="ofs-legend-actions">
|
|
36
|
+
${this.options.onImport?'<button class="ofs-btn-mini" data-action="import" title="Import GeoJSON, Shapefile, KML/KMZ, CSV, DXF">⭳ Import</button>':""}
|
|
37
|
+
<button class="ofs-btn-mini" data-action="add-group" title="New group">+ Group</button>
|
|
38
|
+
<span class="ofs-legend-badge">${t.totalLayers}</span>
|
|
39
|
+
</span>
|
|
40
|
+
</div>
|
|
41
|
+
<div class="ofs-legend-list">
|
|
42
|
+
${t.tree.map(s=>this.renderNode(s,t)).join("")}
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
`}renderNode(t,e){if(t.kind==="layer")return this.renderLayer(t.layer,e);const n=t.group,s=Tt(n.id);return`
|
|
46
|
+
<div class="ofs-legend-group ${n.rendered?"":"ofs-muted"}" data-group-id="${s}">
|
|
47
|
+
<div class="ofs-group-header">
|
|
48
|
+
<button class="ofs-btn-mini ofs-caret" data-action="group-expand" data-id="${s}" title="Expand / collapse">${n.expanded?"▾":"▸"}</button>
|
|
49
|
+
<input type="checkbox" data-action="group-visible" data-id="${s}" ${n.visible?"checked":""} />
|
|
50
|
+
<span class="ofs-group-name" data-action="group-rename" data-id="${s}" title="Double-click to rename">📁 ${Tt(n.name)}</span>
|
|
51
|
+
<span class="ofs-layer-actions">
|
|
52
|
+
<button class="ofs-btn-mini" data-action="group-up" data-id="${s}" title="Move Up">▲</button>
|
|
53
|
+
<button class="ofs-btn-mini" data-action="group-down" data-id="${s}" title="Move Down">▼</button>
|
|
54
|
+
<button class="ofs-btn-mini" data-action="group-remove" data-id="${s}" title="Ungroup">✕</button>
|
|
55
|
+
</span>
|
|
56
|
+
</div>
|
|
57
|
+
${n.expanded?`<div class="ofs-group-children">${t.children.map(r=>this.renderNode(r,e)).join("")||'<div class="ofs-group-empty">Empty group</div>'}</div>`:""}
|
|
58
|
+
</div>
|
|
59
|
+
`}renderLayer(t,e){const n=t.id===e.activeLayerId,s=Tt(t.id),r=['<option value="">(no group)</option>',...e.groups.map(a=>`<option value="${Tt(a.id)}" ${a.id===t.groupId?"selected":""}>${Tt(a.name)}</option>`)].join(""),o=t.thematicType==="simple";return`
|
|
60
|
+
<div class="ofs-legend-layer ${n?"ofs-layer-active":""} ${t.rendered?"":"ofs-muted"}" data-layer-id="${s}">
|
|
61
|
+
<div class="ofs-layer-header">
|
|
62
|
+
<label class="ofs-checkbox-label">
|
|
63
|
+
<input type="checkbox" class="ofs-layer-vis" data-action="layer-visible" data-id="${s}" ${t.visible?"checked":""} />
|
|
64
|
+
${o&&t.items[0]?bf(t.items[0].symbol,t.type,16):""}
|
|
65
|
+
<span class="ofs-layer-name" title="${Tt(t.name)}">${Tt(t.name)}</span>
|
|
66
|
+
</label>
|
|
67
|
+
<div class="ofs-layer-actions">
|
|
68
|
+
<span class="ofs-layer-count">${t.featureCount}</span>
|
|
69
|
+
<button class="ofs-btn-mini ${t.pinned?"ofs-pinned":""}" data-action="layer-pin" data-id="${s}" title="${t.pinned?"Unpin":"Pin (prevent removal)"}">📌</button>
|
|
70
|
+
${this.options.onEditSymbology?`<button class="ofs-btn-mini" data-action="layer-style" data-id="${s}" title="Symbology">🎨</button>`:""}
|
|
71
|
+
${this.options.onExportLayer?`<button class="ofs-btn-mini" data-action="layer-export" data-id="${s}" title="Export">⭱</button>`:""}
|
|
72
|
+
<button class="ofs-btn-mini ofs-btn-up" data-action="layer-up" data-id="${s}" title="Move Up">▲</button>
|
|
73
|
+
<button class="ofs-btn-mini ofs-btn-down" data-action="layer-down" data-id="${s}" title="Move Down">▼</button>
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
|
|
77
|
+
<div class="ofs-layer-body">
|
|
78
|
+
<div class="ofs-opacity-row">
|
|
79
|
+
<span class="ofs-label-small">Opacity</span>
|
|
80
|
+
<input type="range" class="ofs-opacity-slider" data-action="layer-opacity" data-id="${s}" min="0" max="1" step="0.05" value="${t.opacity}" />
|
|
81
|
+
<span class="ofs-opacity-val">${Math.round(t.opacity*100)}%</span>
|
|
82
|
+
</div>
|
|
83
|
+
${e.groups.length>0?`<div class="ofs-opacity-row"><span class="ofs-label-small">Group</span><select class="ofs-group-select" data-action="layer-group" data-id="${s}">${r}</select></div>`:""}
|
|
84
|
+
${o?"":`<div class="ofs-swatches">
|
|
85
|
+
${t.fieldName?`<div class="ofs-swatch-field">${Tt(t.fieldName)}</div>`:""}
|
|
86
|
+
${t.items.map(a=>`
|
|
87
|
+
<label class="ofs-swatch-item ${a.visible?"":"ofs-muted"}">
|
|
88
|
+
<input type="checkbox" data-action="class-visible" data-id="${s}" data-index="${a.index}" ${a.visible?"checked":""} />
|
|
89
|
+
${bf(a.symbol,t.type,16)}
|
|
90
|
+
<span class="ofs-swatch-label" title="${Tt(a.label)}">${Tt(a.label)}</span>
|
|
91
|
+
${a.count!==void 0?`<span class="ofs-swatch-count">${a.count}</span>`:""}
|
|
92
|
+
</label>`).join("")}
|
|
93
|
+
</div>`}
|
|
94
|
+
</div>
|
|
95
|
+
</div>
|
|
96
|
+
`}}const W_=[{name:"Solid",dash:[]},{name:"Dash",dash:[6,3]},{name:"Dot",dash:[1,3]},{name:"Dash dot",dash:[6,3,1,3]},{name:"Long dash",dash:[12,4]}],jO=[{id:"quantile",name:"Equal Count (Quantile)"},{id:"equal_interval",name:"Equal Interval"},{id:"natural_breaks",name:"Natural Breaks (Jenks)"},{id:"pretty_breaks",name:"Pretty Breaks"}];function uh(i){return ee.valid(i)?ee(i).hex("rgb"):"#000000"}function bg(i){return(i??[]).join(",")}function K_(i){const t=i.trim();if(!t)return[];const e=t.split(/[\s,]+/).map(Number);return e.every(n=>Number.isFinite(n)&&n>=0)?e:null}class VO{constructor(t,e={}){Y(this,"legendTools");Y(this,"container",null);Y(this,"layerId",null);Y(this,"unsubscribers",[]);Y(this,"options");Y(this,"draft",{});Y(this,"handleClick",t=>{var s,r,o;const e=(s=t.target.closest("[data-action]"))==null?void 0:s.dataset.action,n=this.layerId;if(e){if(e==="close"){(o=(r=this.options).onClose)==null||o.call(r);return}if(n)switch(e){case"classify":this.classify();break;case"reclassify":this.legendTools.reclassify(n);break;case"all-on":this.legendTools.setAllClassesVisible(n,!0);break;case"all-off":this.legendTools.setAllClassesVisible(n,!1);break}}});Y(this,"handleChange",t=>{var P;const e=t.target,n=e.dataset.field,s=this.layerId;if(!n||!s)return;const r=e.value,o=e.checked,a=Number(r),l=this.legendTools,h=this.theme,f=Fo(h),d=e.dataset.class!==void 0?Number(e.dataset.class):NaN,p=N=>l.updateBaseSymbol(s,N),y=N=>p({fill:N}),_=N=>p({line:N}),E=N=>p({marker:N}),w=N=>y({pattern:{...f.fill.pattern??{...Da,color:f.fill.color},...N}}),L=N=>{const S=n.endsWith("-custom")?K_(r):r==="custom"?null:K_(r);S&&N(S)},b=N=>Number.isFinite(a)&&r!==""&&N(a);if(n.startsWith("label-")){const N=h.label;if(n==="label-on"){if(!o)l.setLabel(s,null);else{const C=(P=this.layer)==null?void 0:P.getPropertyFields().find(T=>!T.name.startsWith("_ofs_"));if(!C){this.render();return}l.setLabel(s,{field:(N==null?void 0:N.field)??C.name,enabled:!0})}this.render();return}if(n==="label-field"){l.setLabel(s,r==="__expression__"?{expression:(N==null?void 0:N.expression)||((N==null?void 0:N.field)??"")}:{field:r}),this.render();return}if(n==="label-expression"){r.trim()&&l.setLabel(s,{expression:r.trim()});return}const S={};n==="label-size"?b(C=>S.size=C):n==="label-color"?S.color=r:n==="label-halo"?S.haloColor=r:n==="label-halo-width"?b(C=>S.haloWidth=C):n==="label-decimals"?S.decimals=r===""?void 0:a:n==="label-min-zoom"?S.minZoom=r===""?void 0:a:n==="label-overlap"?S.allowOverlap=o:n==="label-placement"&&(S.placement=o?"line":"point"),Object.keys(S).length>0&&l.setLabel(s,S);return}switch(n){case"renderer":this.draft={renderer:r},r==="single"&&h.type!=="simple"&&l.setThematicSimple(s,f.fill.color),this.render();return;case"field":case"ramp":this.draft[n]=r,this.render();return;case"method":this.draft.method=r;return;case"classes":b(N=>this.draft.classes=Math.max(1,Math.min(32,Math.round(N))));return;case"reverse":this.draft.reverse=o,this.render();return;case"mode":this.draft.mode=r,this.render();return;case"sizeMin":case"sizeMax":b(N=>this.draft[n]=N);return;case"class-visible":l.setClassVisible(s,d,o);return;case"class-color":l.updateClass(s,d,{color:r});return;case"class-label":l.updateClass(s,d,{label:r});return;case"class-min":b(N=>l.updateClass(s,d,{min:N}));return;case"class-max":b(N=>l.updateClass(s,d,{max:N}));return;case"class-size":b(N=>l.updateClass(s,d,{size:N}));return;case"fill-style":y(r==="solid"||r==="none"?{style:r}:{style:"pattern",pattern:{...f.fill.pattern??{...Da,color:f.fill.color},kind:r}});return;case"fill-color":y({color:r});return;case"fill-opacity":y({opacity:a});return;case"hatch-color":w({color:r});return;case"hatch-angle":b(N=>w({angleDeg:N}));return;case"hatch-spacing":b(N=>N>=1&&w({spacing:N}));return;case"hatch-width":b(N=>N>0&&w({lineWidth:N}));return;case"hatch-dash":case"hatch-dash-custom":L(N=>w({dash:N}));return;case"fill-background":y({patternBackground:o});return;case"outline-color":y({outlineColor:r});return;case"outline-width":b(N=>y({outlineWidth:Math.max(0,N)}));return;case"outline-dash":case"outline-dash-custom":L(N=>y({outlineDash:N}));return;case"fill-offset-x":b(N=>{var S;return y({offset:[N,((S=f.fill.offset)==null?void 0:S[1])??0]})});return;case"fill-offset-y":b(N=>{var S;return y({offset:[((S=f.fill.offset)==null?void 0:S[0])??0,N]})});return;case"line-color":_({color:r});return;case"line-width":b(N=>_({width:Math.max(0,N)}));return;case"line-opacity":_({opacity:a});return;case"line-dash":case"line-dash-custom":L(N=>_({dash:N}));return;case"line-cap":_({cap:r});return;case"line-join":_({join:r});return;case"line-offset":b(N=>_({offset:N}));return;case"marker-shape":r.startsWith("icon:")?E({shape:"icon",icon:r.slice(5)}):E({shape:r});return;case"marker-color":E({color:r});return;case"marker-size":b(N=>E({size:Math.max(0,N)}));return;case"marker-opacity":E({opacity:a});return;case"marker-stroke":E({strokeColor:r});return;case"marker-stroke-width":b(N=>E({strokeWidth:Math.max(0,N)}));return;case"marker-rotation":b(N=>E({rotationDeg:N}));return;case"marker-anchor":E({anchor:r});return;case"marker-offset-x":b(N=>{var S;return E({offset:[N,((S=f.marker.offset)==null?void 0:S[1])??0]})});return;case"marker-offset-y":b(N=>{var S;return E({offset:[((S=f.marker.offset)==null?void 0:S[0])??0,N]})});return;case"marker-overlap":E({allowOverlap:o});return}});this.legendTools=t,this.options=e}mount(t){const e=typeof t=="string"?document.getElementById(t):t;if(!e)throw new Error(`Target container for OFSSymbologyPanel not found: ${t}`);this.unmount(),this.container=e,e.classList.add("ofs-symbology-panel"),e.addEventListener("change",this.handleChange),e.addEventListener("click",this.handleClick);const n=this.legendTools.getThematicEngine(),s=this.legendTools.getDataSource();this.unsubscribers.push(n.on("theme:changed",({layerId:r})=>r===this.layerId&&this.render()),s.on("layer:removed",({layerId:r})=>{r===this.layerId&&(this.layerId=null,this.render())})),this.render()}unmount(){this.unsubscribers.forEach(t=>t()),this.unsubscribers=[],this.container&&(this.container.removeEventListener("change",this.handleChange),this.container.removeEventListener("click",this.handleClick),this.container.innerHTML="",this.container.classList.remove("ofs-symbology-panel"),this.container=null)}open(t){this.layerId=t,this.draft={},this.render()}getLayerId(){return this.layerId}get layer(){return this.layerId?this.legendTools.getDataSource().getLayer(this.layerId):void 0}get theme(){return this.layerId?this.legendTools.getThematicEngine().getEffectiveTheme(this.layerId):void 0}render(){if(!this.container)return;const t=this.layer,e=this.theme;if(!t||!e){this.container.innerHTML='<div class="ofs-sym-empty">Select a layer to edit its symbology.</div>';return}const n=this.container.scrollTop,s=this.draft.renderer??(e.type==="simple"?"single":e.type==="categorical"?"categorized":"graduated");this.container.innerHTML=`
|
|
97
|
+
<div class="ofs-sym-header">
|
|
98
|
+
<span class="ofs-sym-title">🎨 ${Tt(t.name)} <small>(${Tt(t.type)})</small></span>
|
|
99
|
+
${this.options.onClose?'<button class="ofs-btn-mini" data-action="close" title="Close">✕</button>':""}
|
|
100
|
+
</div>
|
|
101
|
+
<div class="ofs-sym-section">
|
|
102
|
+
<label class="ofs-sym-row"><span>Renderer</span>
|
|
103
|
+
<select data-field="renderer">
|
|
104
|
+
${[["single","Single Symbol"],["categorized","Categorized"],["graduated","Graduated"]].map(([r,o])=>`<option value="${r}" ${s===r?"selected":""}>${o}</option>`).join("")}
|
|
105
|
+
</select>
|
|
106
|
+
</label>
|
|
107
|
+
${s==="single"?"":this.renderClassification(t,e,s)}
|
|
108
|
+
</div>
|
|
109
|
+
${s!=="single"&&e.type!=="simple"&&s==="categorized"==(e.type==="categorical")?this.renderClassTable(t,e):""}
|
|
110
|
+
<div class="ofs-sym-section">
|
|
111
|
+
<div class="ofs-sym-subtitle">Symbol</div>
|
|
112
|
+
${this.renderSymbolEditor(t,e)}
|
|
113
|
+
</div>
|
|
114
|
+
<div class="ofs-sym-section">
|
|
115
|
+
<div class="ofs-sym-subtitle">Labels</div>
|
|
116
|
+
${this.renderLabels(t,e)}
|
|
117
|
+
</div>
|
|
118
|
+
`,this.container.scrollTop=n}renderLabels(t,e){const n=e.label,s=!!n&&n.enabled!==!1,r=t.getPropertyFields().filter(a=>!a.name.startsWith("_ofs_")),o=!!(n!=null&&n.expression);return`
|
|
119
|
+
<label class="ofs-sym-row"><span>Show labels</span><input type="checkbox" data-field="label-on" ${s?"checked":""}/></label>
|
|
120
|
+
${s?`
|
|
121
|
+
<label class="ofs-sym-row"><span>Value</span>
|
|
122
|
+
<select data-field="label-field">
|
|
123
|
+
${r.map(a=>`<option value="${Tt(a.name)}" ${!o&&(n==null?void 0:n.field)===a.name?"selected":""}>${Tt(a.name)}</option>`).join("")}
|
|
124
|
+
<option value="__expression__" ${o?"selected":""}>Expression…</option>
|
|
125
|
+
</select>
|
|
126
|
+
</label>
|
|
127
|
+
${o?`<input type="text" data-field="label-expression" value="${Tt(n.expression??"")}" placeholder="concat(owner, ' ', rai_ngan_wa())" />`:""}
|
|
128
|
+
<label class="ofs-sym-row"><span>Size</span><input type="number" min="6" max="48" step="1" data-field="label-size" value="${(n==null?void 0:n.size)??12}"/></label>
|
|
129
|
+
<label class="ofs-sym-row"><span>Colour</span><input type="color" data-field="label-color" value="${Tt(uh((n==null?void 0:n.color)??"#1f2937"))}"/></label>
|
|
130
|
+
<label class="ofs-sym-row"><span>Halo</span><input type="color" data-field="label-halo" value="${Tt(uh((n==null?void 0:n.haloColor)??"#ffffff"))}"/></label>
|
|
131
|
+
<label class="ofs-sym-row"><span>Halo width</span><input type="number" min="0" max="5" step="0.1" data-field="label-halo-width" value="${(n==null?void 0:n.haloWidth)??1.2}"/></label>
|
|
132
|
+
<label class="ofs-sym-row"><span>Decimals</span><input type="number" min="0" max="6" step="1" data-field="label-decimals" value="${(n==null?void 0:n.decimals)??""}" placeholder="as stored"/></label>
|
|
133
|
+
<label class="ofs-sym-row"><span>From zoom</span><input type="number" min="0" max="24" step="1" data-field="label-min-zoom" value="${(n==null?void 0:n.minZoom)??""}" placeholder="any"/></label>
|
|
134
|
+
<label class="ofs-sym-row"><span>Allow overlap</span><input type="checkbox" data-field="label-overlap" ${n!=null&&n.allowOverlap?"checked":""}/></label>
|
|
135
|
+
${t.type==="line"?`<label class="ofs-sym-row"><span>Along the line</span><input type="checkbox" data-field="label-placement" ${(n==null?void 0:n.placement)==="line"?"checked":""}/></label>`:""}
|
|
136
|
+
`:""}
|
|
137
|
+
`}renderClassification(t,e,n){var E,w,L,b;const s=n==="graduated",r=t.getPropertyFields().filter(P=>!s||P.type==="number"),o=n==="graduated"&&e.type==="graduated"||n==="categorized"&&e.type==="categorical",a=this.draft.field??(o?e.fieldName:void 0)??((E=r[0])==null?void 0:E.name)??"",l=this.draft.ramp??(o?e.paletteName:void 0)??(s?"YlGn":"Set2"),h=this.draft.method??e.classificationMethod??"quantile",f=this.draft.classes??e.classCount??((w=e.breaks)==null?void 0:w.length)??5,d=this.draft.mode??e.graduatedMode??"color",[p,y]=[this.draft.sizeMin??((L=e.sizeRange)==null?void 0:L[0])??(t.type==="line"?1:4),this.draft.sizeMax??((b=e.sizeRange)==null?void 0:b[1])??(t.type==="line"?8:24)],_=["sequential","diverging","qualitative"].map(P=>`<optgroup label="${P}">${$p(P).map(N=>`<option value="${Tt(N.name)}" ${N.name.toLowerCase()===String(l).toLowerCase()?"selected":""}>${Tt(N.name)}</option>`).join("")}</optgroup>`).join("");return`
|
|
138
|
+
<label class="ofs-sym-row"><span>Value</span>
|
|
139
|
+
<select data-field="field">
|
|
140
|
+
${r.length===0?`<option value="">(no ${s?"numeric ":""}fields)</option>`:""}
|
|
141
|
+
${r.map(P=>`<option value="${Tt(P.name)}" ${P.name===a?"selected":""}>${Tt(P.name)} (${P.type})</option>`).join("")}
|
|
142
|
+
</select>
|
|
143
|
+
</label>
|
|
144
|
+
<label class="ofs-sym-row"><span>Color ramp</span>
|
|
145
|
+
<select data-field="ramp">${_}</select>
|
|
146
|
+
</label>
|
|
147
|
+
<div class="ofs-sym-ramp" style="background:${Tt(bx(String(l),this.draft.reverse??!1))}"></div>
|
|
148
|
+
<label class="ofs-sym-row"><span>Invert ramp</span><input type="checkbox" data-field="reverse" ${this.draft.reverse?"checked":""}/></label>
|
|
149
|
+
${s?`
|
|
150
|
+
<label class="ofs-sym-row"><span>Mode</span>
|
|
151
|
+
<select data-field="mode">
|
|
152
|
+
<option value="color" ${d==="color"?"selected":""}>Color</option>
|
|
153
|
+
${t.type!=="polygon"?`<option value="size" ${d==="size"?"selected":""}>Size</option>`:""}
|
|
154
|
+
</select>
|
|
155
|
+
</label>
|
|
156
|
+
${d==="size"&&t.type!=="polygon"?`<label class="ofs-sym-row"><span>Size from / to</span>
|
|
157
|
+
<span class="ofs-sym-pair"><input type="number" min="0" step="0.5" data-field="sizeMin" value="${p}"/><input type="number" min="0" step="0.5" data-field="sizeMax" value="${y}"/></span>
|
|
158
|
+
</label>`:""}
|
|
159
|
+
<label class="ofs-sym-row"><span>Method</span>
|
|
160
|
+
<select data-field="method">${jO.map(P=>`<option value="${P.id}" ${P.id===h?"selected":""}>${P.name}</option>`).join("")}
|
|
161
|
+
${h==="manual"?'<option value="manual" selected>Manual</option>':""}
|
|
162
|
+
</select>
|
|
163
|
+
</label>
|
|
164
|
+
<label class="ofs-sym-row"><span>Classes</span><input type="number" min="1" max="32" data-field="classes" value="${f}"/></label>`:""}
|
|
165
|
+
<div class="ofs-sym-actions">
|
|
166
|
+
<button class="ofs-btn" data-action="classify" ${r.length===0?"disabled":""}>Classify</button>
|
|
167
|
+
${o?'<button class="ofs-btn" data-action="reclassify" title="Recompute from current data, keeping edits">Update from data</button>':""}
|
|
168
|
+
</div>
|
|
169
|
+
`}renderClassTable(t,e){const n=this.legendTools.getSnapshot().layers.find(a=>a.id===t.id);if(!n)return"";const s=e.type==="graduated",r=s&&e.graduatedMode==="size",o=n.items.map(a=>{const l=a.index,h=s&&l>=0?e.breaks[l]:void 0,f=l>=0&&!r?`<input type="color" data-class="${l}" data-field="class-color" value="${uh(a.color)}" title="Class color"/>`:"";return`
|
|
170
|
+
<tr class="${a.visible?"":"ofs-muted"}">
|
|
171
|
+
<td><input type="checkbox" data-class="${l}" data-field="class-visible" ${a.visible?"checked":""}/></td>
|
|
172
|
+
<td class="ofs-sym-swatch">${bf(a.symbol,t.type,18)}${f}</td>
|
|
173
|
+
${s?h?`<td><input type="number" step="any" data-class="${l}" data-field="class-min" value="${h.min}"/></td>
|
|
174
|
+
<td><input type="number" step="any" data-class="${l}" data-field="class-max" value="${h.max}"/></td>`:'<td colspan="2"></td>':""}
|
|
175
|
+
${r?`<td>${h?`<input type="number" min="0" step="0.5" data-class="${l}" data-field="class-size" value="${t.type==="line"?a.symbol.line.width:a.symbol.marker.size}"/>`:""}</td>`:""}
|
|
176
|
+
<td>${l>=0?`<input type="text" data-class="${l}" data-field="class-label" value="${Tt(a.label)}"/>`:Tt(a.label)}</td>
|
|
177
|
+
<td class="ofs-sym-count">${a.count??""}</td>
|
|
178
|
+
</tr>`}).join("");return`
|
|
179
|
+
<div class="ofs-sym-section">
|
|
180
|
+
<div class="ofs-sym-subtitle">Classes <span class="ofs-sym-links"><button class="ofs-btn-mini" data-action="all-on">all on</button><button class="ofs-btn-mini" data-action="all-off">all off</button></span></div>
|
|
181
|
+
<div class="ofs-sym-table-wrap">
|
|
182
|
+
<table class="ofs-sym-table">
|
|
183
|
+
<thead><tr><th></th><th>Symbol</th>${s?"<th>From</th><th>To</th>":""}${r?"<th>Size</th>":""}<th>Legend</th><th>#</th></tr></thead>
|
|
184
|
+
<tbody>${o}</tbody>
|
|
185
|
+
</table>
|
|
186
|
+
</div>
|
|
187
|
+
</div>`}dashSelect(t,e){const n=bg(e),s=W_.find(r=>bg(r.dash)===n);return`
|
|
188
|
+
<span class="ofs-sym-pair">
|
|
189
|
+
<select data-field="${t}">
|
|
190
|
+
${W_.map(r=>`<option value="${bg(r.dash)}" ${s===r?"selected":""}>${r.name}</option>`).join("")}
|
|
191
|
+
<option value="custom" ${s?"":"selected"}>Custom</option>
|
|
192
|
+
</select>
|
|
193
|
+
<input type="text" data-field="${t}-custom" placeholder="6,3" value="${Tt(n)}" title="Dash pattern in pixels"/>
|
|
194
|
+
</span>`}renderSymbolEditor(t,e){var d,p,y,_;const n=Fo(e),s=(E,w)=>`<label class="ofs-sym-row"><span>${E}</span>${w}</label>`,r=(E,w)=>`<input type="color" data-field="${E}" value="${uh(w)}"/>`,o=(E,w,L,b,P=.5)=>`<input type="number" data-field="${E}" min="${L}" max="${b}" step="${P}" value="${w}"/>`,a=(E,w)=>`<span class="ofs-sym-pair"><input type="range" data-field="${E}" min="0" max="1" step="0.05" value="${w}"/><output>${Math.round(w*100)}%</output></span>`,l=e.type==="categorical"||e.type==="graduated"&&e.graduatedMode!=="size";if(t.type==="polygon"){const E=n.fill,w=E.pattern??{...Da,color:E.color},L=E.style==="pattern"?w.kind:E.style;return`
|
|
195
|
+
${s("Fill",`<select data-field="fill-style">${["solid","lines","cross","dots","none"].map(b=>`<option value="${b}" ${L===b?"selected":""}>${b==="none"?"No fill":b==="solid"?"Solid":`Hatch: ${b}`}</option>`).join("")}</select>`)}
|
|
196
|
+
${l&&E.style!=="pattern"?"":s(E.style==="pattern"?"Background color":"Fill color",r("fill-color",E.color))}
|
|
197
|
+
${s("Opacity",a("fill-opacity",E.opacity))}
|
|
198
|
+
${E.style==="pattern"?`${l?"":s("Hatch color",r("hatch-color",w.color))}
|
|
199
|
+
${s("Angle (°)",o("hatch-angle",w.angleDeg,-180,180,5))}
|
|
200
|
+
${s("Spacing (px)",o("hatch-spacing",w.spacing,2,100))}
|
|
201
|
+
${s(w.kind==="dots"?"Dot size (px)":"Line width (px)",o("hatch-width",w.lineWidth,.25,20,.25))}
|
|
202
|
+
${w.kind==="dots"?"":s("Hatch dash",this.dashSelect("hatch-dash",w.dash))}
|
|
203
|
+
${s("Background",`<input type="checkbox" data-field="fill-background" ${E.patternBackground?"checked":""}/>`)}`:""}
|
|
204
|
+
${s("Outline color",r("outline-color",E.outlineColor))}
|
|
205
|
+
${s("Outline width (px)",o("outline-width",E.outlineWidth,0,20,.25))}
|
|
206
|
+
${s("Outline style",this.dashSelect("outline-dash",E.outlineDash))}
|
|
207
|
+
${s("Offset x / y (px)",`<span class="ofs-sym-pair">${o("fill-offset-x",((d=E.offset)==null?void 0:d[0])??0,-50,50,1)}${o("fill-offset-y",((p=E.offset)==null?void 0:p[1])??0,-50,50,1)}</span>`)}
|
|
208
|
+
`}if(t.type==="line"){const E=n.line;return`
|
|
209
|
+
${l?"":s("Color",r("line-color",E.color))}
|
|
210
|
+
${s("Width (px)",o("line-width",E.width,0,50,.25))}
|
|
211
|
+
${s("Opacity",a("line-opacity",E.opacity))}
|
|
212
|
+
${s("Stroke style",this.dashSelect("line-dash",E.dash))}
|
|
213
|
+
${s("Cap",`<select data-field="line-cap">${["butt","round","square"].map(w=>`<option ${E.cap===w?"selected":""}>${w}</option>`).join("")}</select>`)}
|
|
214
|
+
${s("Join",`<select data-field="line-join">${["bevel","round","miter"].map(w=>`<option ${E.join===w?"selected":""}>${w}</option>`).join("")}</select>`)}
|
|
215
|
+
${s("Offset (px)",o("line-offset",E.offset??0,-50,50,.5))}
|
|
216
|
+
`}const h=n.marker,f=Xp();return`
|
|
217
|
+
${s("Shape",`<select data-field="marker-shape">${Vu.map(E=>`<option value="${E}" ${h.shape===E?"selected":""}>${E}</option>`).join("")}${f.length?`<optgroup label="icons">${f.map(E=>`<option value="icon:${Tt(E)}" ${h.shape==="icon"&&h.icon===E?"selected":""}>${Tt(E)}</option>`).join("")}</optgroup>`:""}</select>`)}
|
|
218
|
+
${l?"":s("Color",r("marker-color",h.color))}
|
|
219
|
+
${s("Size (px)",o("marker-size",h.size,1,100,.5))}
|
|
220
|
+
${s("Opacity",a("marker-opacity",h.opacity))}
|
|
221
|
+
${s("Stroke color",r("marker-stroke",h.strokeColor))}
|
|
222
|
+
${s("Stroke width (px)",o("marker-stroke-width",h.strokeWidth,0,10,.25))}
|
|
223
|
+
${s("Rotation (°)",o("marker-rotation",h.rotationDeg??0,-360,360,5))}
|
|
224
|
+
${s("Anchor",`<select data-field="marker-anchor">${["center","top","bottom","left","right","top-left","top-right","bottom-left","bottom-right"].map(E=>`<option ${(h.anchor??"center")===E?"selected":""}>${E}</option>`).join("")}</select>`)}
|
|
225
|
+
${s("Offset x / y (px)",`<span class="ofs-sym-pair">${o("marker-offset-x",((y=h.offset)==null?void 0:y[0])??0,-50,50,1)}${o("marker-offset-y",((_=h.offset)==null?void 0:_[1])??0,-50,50,1)}</span>`)}
|
|
226
|
+
${s("Allow overlap",`<input type="checkbox" data-field="marker-overlap" ${h.allowOverlap!==!1?"checked":""}/>`)}
|
|
227
|
+
`}classify(){var f,d,p;const t=this.layer,e=this.theme;if(!t||!e)return;const n=this.draft.renderer??(e.type==="categorical"?"categorized":e.type==="graduated"?"graduated":"single"),s=n==="graduated",r=t.getPropertyFields().filter(y=>!s||y.type==="number"),o=s&&e.type==="graduated"||n==="categorized"&&e.type==="categorical",a=this.draft.field??(o?e.fieldName:void 0)??((f=r[0])==null?void 0:f.name);if(!a)return;const l=this.draft.ramp??(o?e.paletteName:void 0)??(s?"YlGn":"Set2"),h=this.draft.reverse??!1;if(s){const y=t.type==="polygon"?"color":this.draft.mode??e.graduatedMode??"color",_=y==="size"?[this.draft.sizeMin??((d=e.sizeRange)==null?void 0:d[0])??(t.type==="line"?1:4),this.draft.sizeMax??((p=e.sizeRange)==null?void 0:p[1])??(t.type==="line"?8:24)]:void 0,E=this.draft.method&&this.draft.method!=="manual"?this.draft.method:e.classificationMethod&&e.classificationMethod!=="manual"?e.classificationMethod:"quantile";this.legendTools.setThematicGraduated(t.id,a,E,this.draft.classes??e.classCount??5,l,{reverse:h,mode:y,sizeRange:_})}else this.legendTools.setThematicCategorical(t.id,a,l,{reverse:h});this.draft={},this.render()}}const HO=Hu*$o*.75;function Vp(i,t){var n;const e=globalThis;if(typeof e.OffscreenCanvas=="function")return new e.OffscreenCanvas(i,t).getContext("2d");if(typeof((n=e.document)==null?void 0:n.createElement)=="function"){const s=e.document.createElement("canvas");return s.width=i,s.height=t,s.getContext("2d")}return null}function WO(){const i=globalThis.devicePixelRatio;return typeof i=="number"&&i>0?Math.min(3,Math.max(1,i)):1}function Wx(i,t=WO()){const e=$x(i.pattern,t),n=Vp(e.size,e.size);if(!n)return null;n.clearRect(0,0,e.size,e.size),n.fillStyle=e.color,n.strokeStyle=e.color,n.lineWidth=e.lineWidth,n.lineCap="butt",e.dots.length>0&&e.dots.forEach(([r,o])=>{n.beginPath(),n.arc(r,o,e.lineWidth/2,0,Math.PI*2),n.fill()}),e.segments.length>0&&(n.setLineDash(e.dash??[]),e.segments.forEach(([r,o,a,l])=>{n.beginPath(),n.moveTo(r,o),n.lineTo(a,l),n.stroke()}));const s=n.getImageData(0,0,e.size,e.size);return{width:e.size,height:e.size,data:s.data,pixelRatio:e.pixelRatio,sdf:!1}}function Kx(i,t){const e=new Uint8ClampedArray(t*t);for(let r=0;r<e.length;r++)e[r]=i[r*4+3];const n=Bx(e,t,t,HO,.25),s=new Uint8ClampedArray(t*t*4);for(let r=0;r<n.length;r++)s[r*4]=255,s[r*4+1]=255,s[r*4+2]=255,s[r*4+3]=n[r];return{width:t,height:t,data:s,pixelRatio:$o,sdf:!0}}const Zx=(Ec+Hu*2)*$o;function Jx(i){const t=Zx,e=Vp(t,t);if(!e)return null;const n=t/2,s=Ec/2*$o;e.clearRect(0,0,t,t),e.fillStyle="#000",e.beginPath();const r=zp(i.shape);return r?(r.forEach(([o,a],l)=>l===0?e.moveTo(n+o*s,n+a*s):e.lineTo(n+o*s,n+a*s)),e.closePath()):e.arc(n,n,s,0,Math.PI*2),e.fill(),Kx(e.getImageData(0,0,t,t).data,t)}function KO(i){return new Promise((t,e)=>{const n=globalThis;if(typeof n.Image!="function"){e(new Error("Image loading is not available in this environment"));return}const s=new n.Image;s.crossOrigin="anonymous",s.onload=()=>t(s),s.onerror=()=>e(new Error(`Could not load marker icon: ${i.slice(0,80)}`)),s.src=jp(i)?`data:image/svg+xml;charset=utf-8,${encodeURIComponent(i)}`:i})}async function Qx(i){const t=Yp(i);if(!t)throw new Error(`Marker icon "${i}" is not registered`);const e=await KO(t.source),n=Zx,s=Vp(n,n);if(!s)return null;const r=Ec*$o,o=e.naturalWidth||e.width||r,a=e.naturalHeight||e.height||r,l=r/Math.max(o,a);s.clearRect(0,0,n,n),s.drawImage(e,(n-o*l)/2,(n-a*l)/2,o*l,a*l);const h=s.getImageData(0,0,n,n).data;return t.sdf?Kx(h,n):{width:n,height:n,data:h,pixelRatio:$o,sdf:!1}}class tb{constructor(t){Y(this,"getMap");Y(this,"usage",new Map);Y(this,"requests",new Map);Y(this,"loadingIcons",new Set);Y(this,"boundMap",null);Y(this,"missingHandler",t=>{t!=null&&t.id&&this.requests.has(t.id)&&this.addImage(this.requests.get(t.id))});this.getMap=t}bind(t){this.boundMap===t||typeof(t==null?void 0:t.on)!="function"||(this.boundMap=t,t.on("styleimagemissing",this.missingHandler))}ensure(t,e){const n=this.getMap();!n||typeof n.hasImage!="function"||typeof n.addImage!="function"||(this.bind(n),e.forEach(s=>{this.requests.set(s.id,s),n.hasImage(s.id)||this.addImage(s)}),this.usage.set(t,new Set(e.map(s=>s.id))),this.removeUnused())}release(t){this.usage.delete(t),this.removeUnused()}refreshIcon(t){var s,r;const e=(s=Array.from(this.requests.values()).find(o=>o.kind==="icon"&&o.icon===t))==null?void 0:s.id;if(!e)return;const n=this.getMap();try{(r=n==null?void 0:n.hasImage)!=null&&r.call(n,e)&&n.removeImage(e)}catch(o){Qt("SymbolImageManager.refreshIcon",o)}this.addImage(this.requests.get(e))}isUsed(t){for(const e of this.usage.values())if(e.has(t))return!0;return!1}removeUnused(){var e;const t=this.getMap();for(const n of Array.from(this.requests.keys()))if(!this.isUsed(n)){this.requests.delete(n);try{(e=t==null?void 0:t.hasImage)!=null&&e.call(t,n)&&t.removeImage(n)}catch(s){Qt("SymbolImageManager.removeUnused",s)}}}put(t,e){const n=this.getMap();if(!(!n||!e))try{n.hasImage(t)&&n.removeImage(t),n.addImage(t,{width:e.width,height:e.height,data:e.data},{pixelRatio:e.pixelRatio,sdf:e.sdf})}catch(s){Qt("SymbolImageManager.addImage",s)}}addImage(t){try{if(t.kind==="hatch"){const e=Wx(t);if(!e)throw new Error("Canvas is not available; hatch patterns cannot be drawn");this.put(t.id,e)}else if(t.kind==="marker"){const e=Jx(t);if(!e)throw new Error("Canvas is not available; marker shapes cannot be drawn");this.put(t.id,e)}else{if(this.loadingIcons.has(t.id))return;this.loadingIcons.add(t.id),Qx(t.icon).then(e=>{var n,s;this.requests.has(t.id)&&(this.put(t.id,e),(s=(n=this.getMap())==null?void 0:n.triggerRepaint)==null||s.call(n))}).catch(e=>Qt("SymbolImageManager.icon",e)).finally(()=>this.loadingIcons.delete(t.id))}}catch(e){Qt("SymbolImageManager.addImage",e)}}destroy(){this.boundMap&&typeof this.boundMap.off=="function"&&this.boundMap.off("styleimagemissing",this.missingHandler),this.boundMap=null,this.usage.clear(),this.requests.clear()}}const Z_=6378137,J_=.00669437999014,ch=Math.PI/180;function tr(i){const t=Math.sin(i*ch),e=1-J_*t*t,n=Z_*(1-J_)/(e*Math.sqrt(e));return[Z_/Math.sqrt(e)*Math.cos(i*ch)*ch,n*ch]}function zo(i,t,e,n=tr(i[1])){const[s,r]=n,o=(e[0]-t[0])*s,a=(e[1]-t[1])*r,l=(i[0]-t[0])*s,h=(i[1]-t[1])*r,f=o*o+a*a;let d=f>0?(l*o+h*a)/f:0;d<0?d=0:d>1&&(d=1);const p=d===0?[t[0],t[1]]:d===1?[e[0],e[1]]:[t[0]+(e[0]-t[0])*d,t[1]+(e[1]-t[1])*d];return{distance:Math.hypot(l-o*d,h-a*d),t:d,point:p}}function mr(i,t){const[e,n]=tr((i[1]+t[1])/2);return Math.hypot((t[0]-i[0])*e,(t[1]-i[1])*n)}function Lo(i,t){if(!(t>0))return i;const e=Math.max(Math.abs(i[1]),Math.abs(i[3])),[n,s]=tr(Math.min(e,89.9)),r=t/n,o=t/s;return[i[0]-r,i[1]-o,i[2]+r,i[3]+o]}function vs(i){let t=1/0,e=1/0,n=-1/0,s=-1/0;return Hp(i,r=>{r[0]<t&&(t=r[0]),r[1]<e&&(e=r[1]),r[0]>n&&(n=r[0]),r[1]>s&&(s=r[1])}),[t,e,n,s]}function Hp(i,t){const e=n=>{typeof n[0]=="number"?t(n):n.forEach(e)};i.type==="GeometryCollection"?i.geometries.forEach(n=>Hp(n,t)):e(i.coordinates)}function Hi(i){return i.type==="Polygon"?[i.coordinates]:i.type==="MultiPolygon"?i.coordinates:[]}function Rr(i){return i.type==="LineString"?[i.coordinates]:i.type==="MultiLineString"?i.coordinates:[]}function oi(i){return i.type==="Polygon"||i.type==="MultiPolygon"?Hi(i).flat():Rr(i)}function eb(i){let t=0;for(let e=0,n=i.length-1;e<i.length;n=e++)t+=(i[n][0]-i[e][0])*(i[n][1]+i[e][1]);return t/2}function nb(i){let t=0;for(let e=1;e<i.length;e++)t+=Math.hypot(i[e][0]-i[e-1][0],i[e][1]-i[e-1][1]);return t}function Mi(i,t=we.forGeometries([i])){let e=0,n=0;for(const s of Hi(i))s.forEach((r,o)=>{const a=r.map(h=>t.toPlanar(h)),l=Math.abs(eb(a));e+=o===0?l:-l,n+=nb(a)});return e=Math.max(0,e),{area:e,perimeter:n,width:n>0?2*e/n:0}}function ib(i,t){return Math.abs(eb(i.map(e=>t.toPlanar(e))))}function sb(i,t,e){const n=i.map(l=>t.toPlanar(l));let s=n[0],r=n[0],o=0;for(const l of n){const h=Math.hypot(l[0]-s[0],l[1]-s[1]);h>o&&(o=h,r=l)}o=0;for(const l of n){const h=Math.hypot(l[0]-r[0],l[1]-r[1]);h>o&&(o=h,s=l)}const a=Math.hypot(r[0]-s[0],r[1]-s[1]);return a<=e?!0:n.every(l=>Math.abs((r[0]-s[0])*(l[1]-s[1])-(r[1]-s[1])*(l[0]-s[0]))/a<=e)}function Wp(i,t=we.forCoordinate(i[0])){return nb(i.map(e=>t.toPlanar(e)))}function Na(i){const t=Hi(i);let e=t[0],n=-1;if(t.length>1){const f=we.forGeometries([i]);for(const d of t){const p=ib(d[0],f);p>n&&(n=p,e=d)}}const s=e[0],r=vs({type:"Polygon",coordinates:e}),o=(r[1]+r[3])/2,a=[];for(const f of e)for(let d=1;d<f.length;d++){const[p,y]=f[d-1],[_,E]=f[d];(y<=o&&E>o||E<=o&&y>o)&&a.push(p+(o-y)/(E-y)*(_-p))}a.sort((f,d)=>f-d);let l=-1,h=[s[0][0],s[0][1]];for(let f=0;f+1<a.length;f+=2)a[f+1]-a[f]>l&&(l=a[f+1]-a[f],h=[(a[f]+a[f+1])/2,o]);return h}const pm={sqm:1,m2:1,ha:1e4,hectare:1e4,sqkm:1e6,km2:1e6,rai:1600,ngan:400,wa:4,sqwa:4},ym={m:1,meters:1,km:1e3,kilometers:1e3,wa:2},ZO=["<=",">=","<>","!=","==","||","=","<",">","+","-","*","/","%","^"],JO=/[A-Za-z_-]/,Q_=/[A-Za-z0-9_-.]/;class cn extends Error{constructor(t,e){super(t),this.position=e,this.name="ExpressionError"}}function QO(i){const t=[];let e=0;for(;e<i.length;){const n=i[e];if(/\s/.test(n)){e++;continue}const s=e;if(n==="'"){let o="";for(e++;e<i.length;){if(i[e]==="'"){if(i[e+1]==="'"){o+="'",e+=2;continue}break}o+=i[e++]}if(e>=i.length)throw new cn(`Unterminated text starting at position ${s+1}`,s);e++,t.push({type:"string",value:o,pos:s});continue}if(n==='"'){let o="";for(e++;e<i.length&&i[e]!=='"';)o+=i[e++];if(e>=i.length)throw new cn(`Unterminated field name starting at position ${s+1}`,s);e++,t.push({type:"field",value:o,pos:s});continue}if(/[0-9]/.test(n)||n==="."&&/[0-9]/.test(i[e+1]??"")){for(;e<i.length&&/[0-9.]/.test(i[e]);)e++;if(/[eE]/.test(i[e]??"")&&/[0-9+-]/.test(i[e+1]??""))for(e+=2;e<i.length&&/[0-9]/.test(i[e]);)e++;const o=i.slice(s,e);if(!Number.isFinite(Number(o)))throw new cn(`"${o}" is not a number`,s);t.push({type:"number",value:o,pos:s});continue}if(n==="$"){for(e++;e<i.length&&Q_.test(i[e]);)e++;t.push({type:"var",value:i.slice(s+1,e).toLowerCase(),pos:s});continue}if(JO.test(n)){for(;e<i.length&&Q_.test(i[e]);)e++;t.push({type:"name",value:i.slice(s,e),pos:s});continue}if(n==="("||n===")"||n===","){e++,t.push({type:"punct",value:n,pos:s});continue}const r=ZO.find(o=>i.startsWith(o,e));if(r){e+=r.length,t.push({type:"op",value:r,pos:s});continue}throw new cn(`Unexpected character "${n}" at position ${s+1}`,s)}return t.push({type:"end",value:"",pos:i.length}),t}const tv=new WeakMap;function ji(i){const t=tv.get(i);if(t)return t;let e=0,n=0,s=0,r=NaN,o=NaN;if(i.type==="Polygon"||i.type==="MultiPolygon"){const l=Mi(i);e=l.area,n=l.perimeter;const h=Na(i);r=h[0],o=h[1]}else if(i.type==="LineString"||i.type==="MultiLineString"){const l=we.forGeometries([i]);s=Rr(i).reduce((f,d)=>f+Wp(d,l),0);const h=Rr(i)[0];if(h){const f=h[Math.floor(h.length/2)];r=f[0],o=f[1]}}else i.type==="Point"?(r=i.coordinates[0],o=i.coordinates[1]):i.type==="MultiPoint"&&i.coordinates.length>0&&(r=i.coordinates[0][0],o=i.coordinates[0][1]);const a={area:e,perimeter:n,length:s,x:r,y:o};return tv.set(i,a),a}function Ga(i,t){if(i===null)return null;if(typeof i=="number")return i;if(typeof i=="boolean")return i?1:0;const e=i.trim();if(e==="")return null;const n=Number(e);if(!Number.isFinite(n))throw new cn(`${t} needs a number, got "${i}"`);return n}function ni(i){return i===null?null:typeof i=="string"?i:typeof i=="boolean"?i?"true":"false":String(i)}function Pr(i){return i===null?!1:typeof i=="boolean"?i:typeof i=="number"?i!==0:i!==""&&i.toLowerCase()!=="false"}function ev(i,t){if(i===null||t===null)return null;if(typeof i=="number"||typeof t=="number"){const e=Ga(i,"Comparison"),n=Ga(t,"Comparison");return e===null||n===null?null:e<n?-1:e>n?1:0}return typeof i=="boolean"||typeof t=="boolean"?(i?1:0)-(t?1:0):i<t?-1:i>t?1:0}function t8(i,t){let e="";for(let n=0;n<i.length;n++){const s=i[n];if(s==="\\"&&n+1<i.length){e+=i[++n].replace(/[.*+?^${}()|[\]\\]/g,"\\$&");continue}s==="%"?e+=".*":s==="_"?e+=".":e+=s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}return new RegExp(`^${e}$`,t?"i":"")}function e8(i){const t=String(i??"sqm").toLowerCase(),e=pm[t];if(!e)throw new cn(`Unknown area unit "${t}" (${Object.keys(pm).join(", ")})`);return e}function nv(i){const t=String(i??"m").toLowerCase(),e=ym[t];if(!e)throw new cn(`Unknown length unit "${t}" (${Object.keys(ym).join(", ")})`);return e}function Kp(i,t=1){const e=10**t,n=Math.round(i/4*e)/e,s=Math.floor(n/400),r=n-s*400,o=Math.floor(r/100),a=r-o*100;return`${s}-${o}-${a.toFixed(t)}`}const An=(i,t)=>Ga(i,`${t}()`),Ku={abs:{minArgs:1,maxArgs:1,help:"abs(value)",call:([i])=>{const t=An(i,"abs");return t===null?null:Math.abs(t)}},round:{minArgs:1,maxArgs:2,help:"round(value, decimals = 0)",call:([i,t])=>{const e=An(i,"round"),n=t===void 0?0:An(t,"round")??0;if(e===null)return null;const s=10**n;return Math.round(e*s)/s}},floor:{minArgs:1,maxArgs:1,help:"floor(value)",call:([i])=>{const t=An(i,"floor");return t===null?null:Math.floor(t)}},ceil:{minArgs:1,maxArgs:1,help:"ceil(value)",call:([i])=>{const t=An(i,"ceil");return t===null?null:Math.ceil(t)}},sqrt:{minArgs:1,maxArgs:1,help:"sqrt(value)",call:([i])=>{const t=An(i,"sqrt");return t===null?null:Math.sqrt(t)}},power:{minArgs:2,maxArgs:2,help:"power(base, exponent)",call:([i,t])=>{const e=An(i,"power"),n=An(t,"power");return e===null||n===null?null:e**n}},min:{minArgs:1,maxArgs:20,help:"min(a, b, …)",call:i=>{const t=i.map(e=>An(e,"min")).filter(e=>e!==null);return t.length?Math.min(...t):null}},max:{minArgs:1,maxArgs:20,help:"max(a, b, …)",call:i=>{const t=i.map(e=>An(e,"max")).filter(e=>e!==null);return t.length?Math.max(...t):null}},upper:{minArgs:1,maxArgs:1,help:"upper(text)",call:([i])=>{const t=ni(i);return t===null?null:t.toUpperCase()}},lower:{minArgs:1,maxArgs:1,help:"lower(text)",call:([i])=>{const t=ni(i);return t===null?null:t.toLowerCase()}},trim:{minArgs:1,maxArgs:1,help:"trim(text)",call:([i])=>{const t=ni(i);return t===null?null:t.trim()}},length:{minArgs:0,maxArgs:1,help:"length(text) or length() for the line length in meters",call:([i],t)=>{var e;return i===void 0?ji(t.feature.geometry).length:((e=ni(i))==null?void 0:e.length)??null}},substr:{minArgs:2,maxArgs:3,help:"substr(text, start, length) - start is 1-based",call:([i,t,e])=>{const n=ni(i),s=An(t,"substr");if(n===null||s===null)return null;const r=s>0?s-1:n.length+s,o=e===void 0?void 0:An(e,"substr")??void 0;return o===void 0?n.slice(r):n.slice(r,r+o)}},replace:{minArgs:3,maxArgs:3,help:"replace(text, search, replacement)",call:([i,t,e])=>{const n=ni(i),s=ni(t),r=ni(e)??"";return n===null||s===null?null:n.split(s).join(r)}},concat:{minArgs:1,maxArgs:20,help:"concat(a, b, …)",call:i=>i.map(t=>ni(t)??"").join("")},coalesce:{minArgs:1,maxArgs:20,help:"coalesce(a, b, …) - first value that is not NULL",call:i=>i.find(t=>t!==null)??null},if:{minArgs:3,maxArgs:3,help:"if(condition, then, else)",call:([i,t,e])=>Pr(i)?t:e},to_int:{minArgs:1,maxArgs:1,help:"to_int(value)",call:([i])=>{const t=An(i,"to_int");return t===null?null:Math.trunc(t)}},to_real:{minArgs:1,maxArgs:1,help:"to_real(value)",call:([i])=>An(i,"to_real")},to_string:{minArgs:1,maxArgs:1,help:"to_string(value)",call:([i])=>ni(i)},today:{minArgs:0,maxArgs:0,help:"today() - 'YYYY-MM-DD'",call:()=>new Date().toISOString().slice(0,10)},now:{minArgs:0,maxArgs:0,help:"now() - ISO timestamp",call:()=>new Date().toISOString()},area:{minArgs:0,maxArgs:1,help:"area(unit) - sqm (default), rai, ngan, wa, ha, km2",call:([i],t)=>ji(t.feature.geometry).area/e8(i??"sqm")},perimeter:{minArgs:0,maxArgs:1,help:"perimeter(unit) - m (default), km, wa",call:([i],t)=>ji(t.feature.geometry).perimeter/nv(i??"m")},line_length:{minArgs:0,maxArgs:1,help:"line_length(unit) - m (default), km, wa",call:([i],t)=>ji(t.feature.geometry).length/nv(i??"m")},rai_ngan_wa:{minArgs:0,maxArgs:2,help:'rai_ngan_wa(area_sqm = $area, decimals = 1) - "3-2-45.5"',call:([i,t],e)=>{const n=i===void 0?ji(e.feature.geometry).area:An(i,"rai_ngan_wa");return n===null?null:Kp(n,t===void 0?1:An(t,"rai_ngan_wa")??1)}},x:{minArgs:0,maxArgs:0,help:"x() - longitude of the feature",call:(i,t)=>ji(t.feature.geometry).x},y:{minArgs:0,maxArgs:0,help:"y() - latitude of the feature",call:(i,t)=>ji(t.feature.geometry).y},geometry_type:{minArgs:0,maxArgs:0,help:"geometry_type() - Polygon, LineString, …",call:(i,t)=>{var e;return((e=t.feature.geometry)==null?void 0:e.type)??null}}},Zp={area:i=>ji(i.feature.geometry).area,perimeter:i=>ji(i.feature.geometry).perimeter,length:i=>ji(i.feature.geometry).length,x:i=>ji(i.feature.geometry).x,y:i=>ji(i.feature.geometry).y,id:i=>i.feature.id===void 0?null:i.feature.id,row:i=>i.row??null,geometry_type:i=>{var t;return((t=i.feature.geometry)==null?void 0:t.type)??null}};function If(){return Object.entries(Ku).map(([i,t])=>({name:i,help:t.help}))}function hd(){return Object.keys(Zp).map(i=>`$${i}`)}const n8=new Set(["and","or","not","in","is","null","true","false","like","ilike"]);class i8{constructor(t,e){Y(this,"index",0);this.tokens=t,this.knownFields=e}parse(){const t=this.parseOr(),e=this.peek();if(e.type!=="end")throw new cn(`Unexpected "${e.value}" at position ${e.pos+1}`,e.pos);return t}peek(t=0){return this.tokens[Math.min(this.index+t,this.tokens.length-1)]}next(){return this.tokens[this.index++]}matchKeyword(t){const e=this.peek();return e.type==="name"&&e.value.toLowerCase()===t?(this.index++,!0):!1}matchOp(...t){const e=this.peek();return e.type==="op"&&t.includes(e.value)?(this.index++,e.value):null}parseOr(){let t=this.parseAnd();for(;this.matchKeyword("or");)t={k:"binary",op:"or",left:t,right:this.parseAnd()};return t}parseAnd(){let t=this.parseNot();for(;this.matchKeyword("and");)t={k:"binary",op:"and",left:t,right:this.parseNot()};return t}parseNot(){return this.matchKeyword("not")?{k:"unary",op:"not",operand:this.parseNot()}:this.parseComparison()}parseComparison(){const t=this.parseConcat(),e=this.matchOp("=","==","<>","!=","<","<=",">",">=");if(e)return{k:"binary",op:e==="=="?"=":e==="!="?"<>":e,left:t,right:this.parseConcat()};const n=(()=>{const s=this.index;if(this.matchKeyword("not")){if(this.peek().type==="name"&&["in","like","ilike"].includes(this.peek().value.toLowerCase()))return!0;this.index=s}return!1})();if(this.matchKeyword("in")){this.expectPunct("(","IN needs a list: field IN (1, 2, 3)");const s=[];if(this.peek().value!==")")do s.push(this.parseConcat());while(this.matchPunct(","));return this.expectPunct(")",'IN list is missing ")"'),{k:"in",value:t,list:s,negated:n}}if(this.matchKeyword("like")||this.matchKeyword("ilike")){const s=this.tokens[this.index-1].value.toLowerCase()==="ilike";return{k:"like",value:t,pattern:this.parseConcat(),caseInsensitive:s,negated:n}}if(n)throw new cn("NOT must be followed by IN or LIKE here");if(this.matchKeyword("is")){const s=this.matchKeyword("not");if(!this.matchKeyword("null"))throw new cn("IS must be followed by NULL or NOT NULL");return{k:"isnull",value:t,negated:s}}return t}parseConcat(){let t=this.parseAdditive();for(;this.matchOp("||");)t={k:"binary",op:"||",left:t,right:this.parseAdditive()};return t}parseAdditive(){let t=this.parseMultiplicative();for(;;){const e=this.matchOp("+","-");if(!e)return t;t={k:"binary",op:e,left:t,right:this.parseMultiplicative()}}}parseMultiplicative(){let t=this.parseUnary();for(;;){const e=this.matchOp("*","/","%");if(!e)return t;t={k:"binary",op:e,left:t,right:this.parseUnary()}}}parsePower(){const t=this.parsePrimary();return this.matchOp("^")?{k:"binary",op:"^",left:t,right:this.parseUnary()}:t}parseUnary(){const t=this.matchOp("-","+");return t?t==="-"?{k:"unary",op:"-",operand:this.parseUnary()}:this.parseUnary():this.parsePower()}matchPunct(t){const e=this.peek();return e.type==="punct"&&e.value===t?(this.index++,!0):!1}expectPunct(t,e){if(!this.matchPunct(t)){const n=this.peek();throw new cn(`${e} (at position ${n.pos+1})`,n.pos)}}parsePrimary(){const t=this.next();switch(t.type){case"number":return{k:"literal",value:Number(t.value)};case"string":return{k:"literal",value:t.value};case"field":return this.fieldNode(t.value,t.pos);case"var":{if(!Zp[t.value])throw new cn(`Unknown variable "$${t.value}" (available: ${hd().join(", ")})`,t.pos);return{k:"var",name:t.value}}case"punct":if(t.value==="("){const e=this.parseOr();return this.expectPunct(")",'Missing ")"'),e}throw new cn(`Unexpected "${t.value}" at position ${t.pos+1}`,t.pos);case"name":{const e=t.value.toLowerCase();if(e==="true"||e==="false")return{k:"literal",value:e==="true"};if(e==="null")return{k:"literal",value:null};if(this.peek().type==="punct"&&this.peek().value==="("){const n=Ku[e];if(!n)throw new cn(`Unknown function "${t.value}" (${Object.keys(Ku).join(", ")})`,t.pos);this.index++;const s=[];if(!(this.peek().type==="punct"&&this.peek().value===")"))do s.push(this.parseOr());while(this.matchPunct(","));if(this.expectPunct(")",`${t.value}() is missing ")"`),s.length<n.minArgs||s.length>n.maxArgs)throw new cn(`${e}() takes ${n.minArgs===n.maxArgs?n.minArgs:`${n.minArgs}–${n.maxArgs}`} arguments — ${n.help}`,t.pos);return{k:"call",name:e,args:s}}if(n8.has(e))throw new cn(`Unexpected "${t.value}" at position ${t.pos+1}`,t.pos);return this.fieldNode(t.value,t.pos)}default:throw new cn("The expression ends too early",t.pos)}}fieldNode(t,e){if(this.knownFields&&!this.knownFields.has(t)){const n=[...this.knownFields].slice(0,20).join(", ");throw new cn(`Unknown field "${t}"${n?` (fields: ${n})`:""}`,e)}return{k:"field",name:t}}}function ei(i,t){switch(i.k){case"literal":return i.value;case"field":{const e=t.feature.properties;if(!e||!Object.prototype.hasOwnProperty.call(e,i.name))return null;const n=e[i.name];return n==null?null:typeof n=="number"||typeof n=="string"||typeof n=="boolean"?n:String(n)}case"var":return Zp[i.name](t);case"call":return Ku[i.name].call(i.args.map(e=>ei(e,t)),t);case"unary":{if(i.op==="not"){const n=ei(i.operand,t);return n===null?null:!Pr(n)}const e=Ga(ei(i.operand,t),"Negation");return e===null?null:-e}case"isnull":{const e=ei(i.value,t);return i.negated?e!==null:e===null}case"in":{const e=ei(i.value,t);if(e===null)return null;const n=i.list.some(s=>ev(e,ei(s,t))===0);return i.negated?!n:n}case"like":{const e=ni(ei(i.value,t)),n=ni(ei(i.pattern,t));if(e===null||n===null)return null;const s=t8(n,i.caseInsensitive).test(e);return i.negated?!s:s}case"binary":{if(i.op==="and"||i.op==="or"){const s=ei(i.left,t);if(i.op==="and"&&s!==null&&!Pr(s))return!1;if(i.op==="or"&&s!==null&&Pr(s))return!0;const r=ei(i.right,t);return i.op==="and"?r!==null&&!Pr(r)?!1:s===null||r===null?null:!0:r!==null&&Pr(r)?!0:s===null||r===null?null:!1}const e=ei(i.left,t),n=ei(i.right,t);switch(i.op){case"||":{const s=ni(e),r=ni(n);return s===null||r===null?null:s+r}case"=":case"<>":case"<":case"<=":case">":case">=":{const s=ev(e,n);if(s===null)return null;switch(i.op){case"=":return s===0;case"<>":return s!==0;case"<":return s<0;case"<=":return s<=0;case">":return s>0;default:return s>=0}}default:{const s=Ga(e,"Arithmetic"),r=Ga(n,"Arithmetic");if(s===null||r===null)return null;switch(i.op){case"+":return s+r;case"-":return s-r;case"*":return s*r;case"/":return r===0?null:s/r;case"%":return r===0?null:s%r;default:return s**r}}}}}}function Rs(i,t){switch(i.k){case"field":t.add(i.name);break;case"call":i.args.forEach(e=>Rs(e,t));break;case"binary":Rs(i.left,t),Rs(i.right,t);break;case"unary":Rs(i.operand,t);break;case"in":Rs(i.value,t),i.list.forEach(e=>Rs(e,t));break;case"isnull":Rs(i.value,t);break;case"like":Rs(i.value,t),Rs(i.pattern,t);break}}function fd(i,t){if(!i||!i.trim())throw new cn("The expression is empty");const e=new i8(QO(i),t?new Set(t):void 0).parse(),n=new Set;return Rs(e,n),{source:i,fields:[...n],evaluate:(s,r)=>ei(e,{feature:s,row:r}),test:(s,r)=>Pr(ei(e,{feature:s,row:r}))}}function s8(i,t,e){return fd(i,e).evaluate(t)}const r8=.5;function iv(i,t){const e={...i.properties||{}};if(i.id!==void 0&&i.id!==null&&(e._ofs_id=i.id,e.id===void 0&&(e.id=i.id)),t!=null&&t.compiled)try{const n=t.compiled.evaluate(i);e[xf]=n===null?"":String(n)}catch(n){e[xf]="",Qt("BaseGLAdapter.label",n)}return{type:"Feature",id:i.id,geometry:i.geometry,properties:e}}class Jp{constructor(){Y(this,"map",null);Y(this,"_isReady",!1);Y(this,"ownsMap",!0);Y(this,"dataSource",null);Y(this,"thematicEngine",null);Y(this,"unsubscribers",[]);Y(this,"clickHandlers",new Set);Y(this,"dblClickHandlers",new Set);Y(this,"contextMenuHandlers",new Set);Y(this,"moveHandlers",new Set);Y(this,"mouseDownHandlers",new Set);Y(this,"mouseUpHandlers",new Set);Y(this,"activeFeatureStateIds",new Map);Y(this,"renderedFeatures",new Map);Y(this,"labelSources",new Map);Y(this,"pendingSourceUpdates",new Set);Y(this,"flushScheduled",!1);Y(this,"glLayers",new Map);Y(this,"glLayerOwner",new Map);Y(this,"glLayerZIndex",new Map);Y(this,"orderScheduled",!1);Y(this,"symbolImages",new tb(()=>this.map));Y(this,"unsubscribeIcons",Ox(t=>this.symbolImages.refreshIcon(t)))}get isReady(){return this._isReady}async attach(t){if(!t||typeof t.on!="function")throw new ua("attach() needs a MapLibre or Mapbox map instance");if(this.map&&this.map!==t)throw new ua("This adapter is already using another map; call destroy() first");this.map===t&&this._isReady||(this.map=t,this.ownsMap=!1,await this.whenStyleLoaded(t),this._isReady=!0,this.setupMapEventListeners(),this.dataSource&&this.syncAllLayers())}whenStyleLoaded(t){const e=()=>typeof t.isStyleLoaded=="function"?t.isStyleLoaded():!0;return e()?Promise.resolve():new Promise(n=>{const s=()=>{t.off("load",s),t.off("styledata",r),n()},r=()=>{e()&&s()};t.on("load",s),t.on("styledata",r),r()})}bindDataSource(t,e){this.dataSource=t,this.thematicEngine=e||new Wu,this.unsubscribers.push(t.on("layer:added",({layer:n})=>{this._isReady&&this.syncLayer(n)}),t.on("layer:updated",({layer:n})=>{this._isReady&&this.syncLayer(n)}),t.on("layer:removed",({layerId:n})=>{this._isReady&&this.removeLayer(n)}),t.on("features:changed",({layerId:n})=>{this._isReady&&this.scheduleSourceUpdate(n)}),t.on("selection:changed",({layerId:n,featureIds:s})=>{this._isReady&&this.updateSelectionState(n,s)})),this.thematicEngine&&this.unsubscribers.push(this.thematicEngine.on("theme:changed",({layerId:n})=>{if(this._isReady&&this.dataSource){const s=this.dataSource.getLayer(n);s&&this.syncLayer(s)}})),this._isReady&&this.syncAllLayers()}syncAllLayers(){this.dataSource&&this.dataSource.getAllLayers().forEach(t=>{this.syncLayer(t)})}syncLayer(t){if(!this.map||!this._isReady)return;const e=t.id,n=this.syncLabelSource(t),s=this.map.getSource(e);s?n?(this.pendingSourceUpdates.delete(t.id),s.setData(this.buildRenderCollection(t))):(this.pendingSourceUpdates.delete(t.id),this.updateSourceData(t)):this.map.addSource(e,{type:"geojson",data:this.buildRenderCollection(t),promoteId:"_ofs_id"});const o=(this.thematicEngine||new Wu).compile(t);this.symbolImages.ensure(t.id,o.images);const a=this.isLayerRendered(t)?"visible":"none",l=this.glLayers.get(t.id)??[];let h=!1;for(const d of l){const p=o.layers.find(y=>y.id===d.id);(!p||p.type!==d.type)&&(this.removeGLLayer(d.id),h=!0)}const f=[];o.layers.forEach((d,p)=>{const y={...d.layout,visibility:a},_=l.find(L=>L.id===d.id&&L.type===d.type);if(!_||!this.map.getLayer(d.id)){const L=o.layers.slice(p+1).map(P=>P.id).find(P=>this.map.getLayer(P))??this.drawLayerAnchor(),b={id:d.id,source:e,type:d.type,filter:d.filter,layout:y,paint:d.paint};d.minzoom!==void 0&&(b.minzoom=d.minzoom),d.maxzoom!==void 0&&(b.maxzoom=d.maxzoom),this.map.addLayer(b,L),f.push({id:d.id,type:d.type,filter:JSON.stringify(d.filter),paint:this.serialize(d.paint),layout:this.serialize(y),minzoom:d.minzoom,maxzoom:d.maxzoom}),h=!0;return}const E={..._,paint:{..._.paint},layout:{..._.layout}},w=JSON.stringify(d.filter);E.filter!==w&&typeof this.map.setFilter=="function"&&(this.safely(()=>this.map.setFilter(d.id,d.filter),"BaseGLAdapter.syncLayer"),E.filter=w),((E.minzoom??void 0)!==d.minzoom||(E.maxzoom??void 0)!==d.maxzoom)&&(this.safely(()=>this.map.setLayerZoomRange(d.id,d.minzoom??0,d.maxzoom??24),"BaseGLAdapter.syncLayer"),E.minzoom=d.minzoom,E.maxzoom=d.maxzoom),this.applyProperties(d.id,"layout",E.layout,y),this.applyProperties(d.id,"paint",E.paint,d.paint),f.push(E)}),this.glLayers.set(t.id,f),f.forEach(d=>this.glLayerOwner.set(d.id,t.id)),(h||this.glLayerZIndex.get(t.id)!==t.zIndex)&&(this.glLayerZIndex.set(t.id,t.zIndex),this.scheduleLayerOrder())}scheduleLayerOrder(){this.orderScheduled||(this.orderScheduled=!0,queueMicrotask(()=>{this.orderScheduled=!1,this.map&&this.applyLayerOrder()}))}getGLLayerIds(t){return(this.glLayers.get(t)??[]).map(e=>e.id)}dataLayerIdFor(t){return this.glLayerOwner.get(t)??t.replace(/_(stroke|pattern)$/,"")}isLayerRendered(t){const e=this.dataSource;return e&&typeof e.isLayerRendered=="function"?e.isLayerRendered(t.id):t.visible}serialize(t){const e={};return Object.entries(t).forEach(([n,s])=>e[n]=JSON.stringify(s)),e}applyProperties(t,e,n,s){const r=e==="paint"?"setPaintProperty":"setLayoutProperty";for(const[o,a]of Object.entries(s)){const l=JSON.stringify(a);n[o]!==l&&(this.safely(()=>this.map[r](t,o,a),`BaseGLAdapter.${r}(${o})`),n[o]=l)}for(const o of Object.keys(n))o in s||(this.safely(()=>this.map[r](t,o,void 0),`BaseGLAdapter.${r}(${o})`),delete n[o])}safely(t,e){try{t()}catch(n){Qt(e,n)}}drawLayerAnchor(){return this.map.getLayer("_ofs_draw_temp_fill")?"_ofs_draw_temp_fill":void 0}removeGLLayer(t){this.glLayerOwner.delete(t),this.safely(()=>{this.map.getLayer(t)&&this.map.removeLayer(t)},"BaseGLAdapter.removeLayer")}applyLayerOrder(){if(!this.map||!this.dataSource||typeof this.map.moveLayer!="function")return;const t=this.drawLayerAnchor();this.dataSource.getAllLayers().forEach(e=>{this.getGLLayerIds(e.id).forEach(n=>{this.safely(()=>{this.map.getLayer(n)&&this.map.moveLayer(n,t)},"BaseGLAdapter.applyLayerOrder")})})}removeLayer(t){if(this.renderedFeatures.delete(t),this.pendingSourceUpdates.delete(t),this.symbolImages.release(t),!this.map)return;const e=new Set([...this.getGLLayerIds(t),`${t}_stroke`,`${t}_pattern`,t]);this.glLayers.delete(t),this.glLayerZIndex.delete(t),e.forEach(n=>this.removeGLLayer(n));try{this.map.getSource(t)&&this.map.removeSource(t)}catch(n){Qt("BaseGLAdapter.removeLayer",n)}}scheduleSourceUpdate(t){if(this.pendingSourceUpdates.add(t),this.flushScheduled)return;const e=globalThis.requestAnimationFrame;if(typeof e!="function"){this.flushPendingSourceUpdates();return}this.flushScheduled=!0,e(()=>this.flushPendingSourceUpdates())}flushPendingSourceUpdates(){if(this.flushScheduled=!1,!this.map||!this.dataSource){this.pendingSourceUpdates.clear();return}const t=Array.from(this.pendingSourceUpdates);this.pendingSourceUpdates.clear(),t.forEach(e=>{const n=this.dataSource.getLayer(e);n&&this.updateSourceData(n)})}buildRenderCollection(t){const e=t.getFeatures();this.renderedFeatures.set(t.id,new Map(e.map(s=>[s.id,s])));const n=this.labelSources.get(t.id)??null;return{type:"FeatureCollection",features:e.map(s=>iv(s,n))}}syncLabelSource(t){var a;const e=(a=this.thematicEngine)==null?void 0:a.getTheme(t.id),n=e==null?void 0:e.label,s=Yx(n)?n.expression:"",r=this.labelSources.get(t.id);if(((r==null?void 0:r.source)??"")===s)return!1;if(!s)return this.labelSources.delete(t.id),!0;let o=null;try{o=fd(s)}catch(l){Qt("BaseGLAdapter.syncLabelSource",l)}return this.labelSources.set(t.id,{source:s,compiled:o}),!0}updateSourceData(t){if(!this.map)return;const e=this.map.getSource(t.id);if(!e)return;const n=this.renderedFeatures.get(t.id);if(!(this.engineName==="maplibre"&&typeof e.updateData=="function"&&n)){e.setData(this.buildRenderCollection(t));return}const r=t.getFeatures(),o=new Map,a=[],l=[];for(const f of r){o.set(f.id,f);const d=n.get(f.id);d!==f&&(d&&l.push(f.id),a.push(iv(f,this.labelSources.get(t.id)??null)))}for(const f of n.keys())o.has(f)||l.push(f);if(a.length===0&&l.length===0)return;if(new Set([...l,...a.map(f=>f.id)]).size>Math.max(r.length,n.size)*r8){e.setData(this.buildRenderCollection(t));return}this.renderedFeatures.set(t.id,o),e.updateData({remove:l,add:a})}updateSelectionState(t,e){if(!this.map)return;(this.activeFeatureStateIds.get(t)||new Set).forEach(r=>{try{this.map.setFeatureState({source:t,id:r},{selected:!1})}catch(o){Qt("BaseGLAdapter.updateSelectionState",o)}});const s=new Set;e.forEach(r=>{try{this.map.setFeatureState({source:t,id:r},{selected:!0}),s.add(r)}catch(o){Qt("BaseGLAdapter.updateSelectionState",o)}}),this.activeFeatureStateIds.set(t,s)}setFeatureState(t,e,n){if(this.map)try{this.map.setFeatureState({source:t,id:e},n)}catch(s){Qt("BaseGLAdapter.setFeatureState",s)}}getFeatureState(t,e){if(!this.map)return{};try{return this.map.getFeatureState({source:t,id:e})}catch{return{}}}setLayerVisibility(t,e){if(!this.map)return;const n=this.getGLLayerIds(t);(n.length>0?n:[t]).forEach(s=>{var o;this.safely(()=>this.map.setLayoutProperty(s,"visibility",e?"visible":"none"),"BaseGLAdapter.setLayerVisibility");const r=(o=this.glLayers.get(t))==null?void 0:o.find(a=>a.id===s);r&&(r.layout.visibility=JSON.stringify(e?"visible":"none"))})}setLayerOpacity(t,e){var s;const n=(s=this.dataSource)==null?void 0:s.getLayer(t);n&&(n.opacity!==e&&(n.opacity=Math.max(0,Math.min(1,e))),this.syncLayer(n))}setLayerZIndex(t,e){this.applyLayerOrder()}fitBounds(t,e=40){if(!this.map)throw new ua;this.map.fitBounds([[t[0],t[1]],[t[2],t[3]]],{padding:e,duration:1e3})}flyTo(t){if(!this.map)throw new ua;this.map.flyTo({center:t.center,zoom:t.zoom,pitch:t.pitch,bearing:t.bearing,duration:t.duration??1200})}getCenter(){if(!this.map)return[0,0];const t=this.map.getCenter();return[t.lng,t.lat]}setCenter(t){this.map&&this.map.setCenter([t[0],t[1]])}getZoom(){return this.map?this.map.getZoom():0}setZoom(t){this.map&&this.map.setZoom(t)}getBounds(){if(!this.map)return[0,0,0,0];const t=this.map.getBounds();return[t.getWest(),t.getSouth(),t.getEast(),t.getNorth()]}onMapClick(t){return this.clickHandlers.add(t),()=>this.clickHandlers.delete(t)}onMapDblClick(t){return this.dblClickHandlers.add(t),()=>this.dblClickHandlers.delete(t)}onContextMenu(t){return this.contextMenuHandlers.add(t),()=>this.contextMenuHandlers.delete(t)}onMouseMove(t){return this.moveHandlers.add(t),()=>this.moveHandlers.delete(t)}onMouseDown(t){return this.mouseDownHandlers.add(t),()=>this.mouseDownHandlers.delete(t)}onMouseUp(t){return this.mouseUpHandlers.add(t),()=>this.mouseUpHandlers.delete(t)}setDoubleClickZoom(t){if(this.map)try{t?this.map.doubleClickZoom.enable():this.map.doubleClickZoom.disable()}catch(e){Qt("BaseGLAdapter.setDoubleClickZoom",e)}}listen(t,e){this.map.on(t,e),this.unsubscribers.push(()=>{this.safely(()=>{var n;return(n=this.map)==null?void 0:n.off(t,e)},"BaseGLAdapter.off")})}setupMapEventListeners(){this.map&&(this.listen("click",t=>{const e=[t.lngLat.lng,t.lngLat.lat],n=[[t.point.x-6,t.point.y-6],[t.point.x+6,t.point.y+6]],r=(this.map.queryRenderedFeatures(n)||[]).filter(a=>a.layer&&!a.layer.id.startsWith("_ofs_")).map(a=>{var f;const l=this.dataLayerIdFor(a.layer.id);let h=((f=a.properties)==null?void 0:f._ofs_id)??a.id;if(h==null&&this.dataSource){const d=this.dataSource.getLayer(l),p=d?Ro.queryPoint(d,e):[];p.length>0&&(h=p[0].id)}return{id:h,layerId:l,properties:a.properties||{},geometry:a.geometry}}).filter(a=>this.dataSource?this.dataSource.hasLayer(a.layerId):!0);if(r.length===0&&this.dataSource){const a=this.dataSource.getAllLayers().filter(l=>l.visible);for(let l=a.length-1;l>=0;l--){const h=a[l],f=Ro.queryPoint(h,e);if(f.length>0){r.push({id:f[0].id,layerId:h.id,properties:f[0].properties||{},geometry:f[0].geometry});break}}}const o={coordinate:e,point:{x:t.point.x,y:t.point.y},features:r,originalEvent:t.originalEvent};[...this.clickHandlers].forEach(a=>a(o))}),this.listen("mousedown",t=>{const n={coordinate:[t.lngLat.lng,t.lngLat.lat],point:{x:t.point.x,y:t.point.y},features:[],originalEvent:t.originalEvent};[...this.mouseDownHandlers].forEach(s=>s(n))}),this.listen("mouseup",t=>{const n={coordinate:[t.lngLat.lng,t.lngLat.lat],point:{x:t.point.x,y:t.point.y},features:[],originalEvent:t.originalEvent};[...this.mouseUpHandlers].forEach(s=>s(n))}),this.listen("dblclick",t=>{const n={coordinate:[t.lngLat.lng,t.lngLat.lat],point:{x:t.point.x,y:t.point.y},features:[],originalEvent:t.originalEvent};[...this.dblClickHandlers].forEach(s=>s(n))}),this.listen("contextmenu",t=>{const n={coordinate:[t.lngLat.lng,t.lngLat.lat],point:{x:t.point.x,y:t.point.y},features:[],originalEvent:t.originalEvent};[...this.contextMenuHandlers].forEach(s=>s(n))}),this.listen("mousemove",t=>{const n={coordinate:[t.lngLat.lng,t.lngLat.lat],point:{x:t.point.x,y:t.point.y},features:[],originalEvent:t.originalEvent};[...this.moveHandlers].forEach(s=>s(n))}))}getRawMap(){if(!this.map)throw new ua;return this.map}removeOwnLayers(){this.map&&(Array.from(new Set([...this.glLayers.keys(),...this.renderedFeatures.keys()])).forEach(t=>this.removeLayer(t)),this.safely(()=>{const t=typeof this.map.getStyle=="function"?this.map.getStyle():null;t&&((t.layers||[]).forEach(e=>{typeof e.id=="string"&&e.id.startsWith("_ofs_")&&this.removeGLLayer(e.id)}),Object.keys(t.sources||{}).forEach(e=>{e.startsWith("_ofs_")&&this.map.getSource(e)&&this.map.removeSource(e)}))},"BaseGLAdapter.removeOwnLayers"))}destroy(){this.ownsMap||this.removeOwnLayers(),this.unsubscribers.forEach(t=>t()),this.unsubscribers=[],this.clickHandlers.clear(),this.dblClickHandlers.clear(),this.contextMenuHandlers.clear(),this.moveHandlers.clear(),this.mouseDownHandlers.clear(),this.mouseUpHandlers.clear(),this.renderedFeatures.clear(),this.pendingSourceUpdates.clear(),this.glLayers.clear(),this.glLayerOwner.clear(),this.symbolImages.destroy(),this.unsubscribeIcons(),this.map&&this.ownsMap&&this.map.remove(),this.map=null,this.ownsMap=!0,this._isReady=!1}}const o8=Fy.default??Fy;class rb extends Jp{constructor(){super(...arguments);Y(this,"engineName","maplibre")}async init(e,n={}){return new Promise(s=>{this.map=new o8.Map({container:e,style:n.style||"https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",center:n.center||[100.5018,13.7563],zoom:n.zoom??10,...n}),this.map.on("load",()=>{this._isReady=!0,this.setupMapEventListeners(),this.dataSource&&this.syncAllLayers(),s()})})}}class a8 extends Jp{constructor(){super(...arguments);Y(this,"engineName","mapbox")}async init(e,n={}){const s=window.mapboxgl||n.mapboxgl;if(!s)throw new Error("Mapbox GL JS is not loaded. Please pass `mapboxgl` in options or load mapbox-gl on the window.");return n.accessToken&&(s.accessToken=n.accessToken),new Promise(r=>{this.map=new s.Map({container:e,style:n.style||"mapbox://styles/mapbox/streets-v12",center:n.center||[100.5018,13.7563],zoom:n.zoom??10,...n}),this.map.on("load",()=>{this._isReady=!0,this.setupMapEventListeners(),this.dataSource&&this.syncAllLayers(),r()})})}}function ob(i,t,e=512){return 2*Math.PI*6378137*Math.cos(i*Math.PI/180)/(e*2**t)}function ab(i,t){if(!(i>0)||!(t>0))throw new Error("Scale bar needs a positive resolution and width");const e=i*t,n=10**Math.floor(Math.log10(e)),s=[5,2,1].map(r=>r*n).find(r=>r<=e)??n/2;return{meters:s,pixels:s/i,label:s>=1e3?`${Number((s/1e3).toFixed(2))} km`:`${Number(s.toFixed(2))} m`}}function lb(i,t,e,n,s={}){const r=s.color??"#111827",o=s.background??"rgba(255, 255, 255, 0.85)",a=s.fontSize??12,l=s.height??8,h=6;i.save(),i.fillStyle=o,i.fillRect(e-h,n-l-a-h*1.5,t.pixels+h*2,l+a+h*2),i.fillStyle=r,i.strokeStyle=r,i.lineWidth=1,i.fillRect(e,n-l,t.pixels/2,l),i.strokeRect(e,n-l,t.pixels,l),i.font=`${a}px sans-serif`,i.textAlign="left",i.textBaseline="alphabetic",i.fillText("0",e,n-l-4),i.textAlign="right",i.fillText(t.label,e+t.pixels,n-l-4),i.restore()}function ub(i,t,e,n=48,s=0){i.save(),i.translate(t,e),i.rotate(-s*Math.PI/180);const r=n/2;i.fillStyle="#111827",i.strokeStyle="#ffffff",i.lineWidth=2,i.beginPath(),i.moveTo(0,-r),i.lineTo(r*.45,r*.6),i.lineTo(0,r*.25),i.lineTo(-r*.45,r*.6),i.closePath(),i.stroke(),i.fill(),i.font=`${Math.round(n*.35)}px sans-serif`,i.textAlign="center",i.textBaseline="top",i.fillText("N",0,r*.65),i.restore()}function cb(i,t={}){if(typeof document>"u")throw new Error("Exporting a map image needs a browser");const e=i.getRawMap();if(!e||typeof e.getCanvas!="function")throw new Error("The map is not ready yet");const n=e.getCanvas(),s=n.getContext("webgl2")??n.getContext("webgl"),r=s&&typeof s.getContextAttributes=="function"?s.getContextAttributes():null;if(r&&r.preserveDrawingBuffer===!1)throw new Error("Create the map with preserveDrawingBuffer: true to export images (otherwise the picture is blank).");const o=Math.round(t.width??n.width),a=Math.round(t.height??n.height/n.width*o),l=document.createElement("canvas");l.width=o,l.height=a;const h=l.getContext("2d");if(!h)throw new Error("This browser cannot create a 2D canvas");h.fillStyle="#ffffff",h.fillRect(0,0,o,a),h.drawImage(n,0,0,o,a);const f=i.getCenter(),d=i.getZoom(),p=o/n.width,y=ob(f[1],d)/p;let _;if(t.scaleBar!==!1&&(_=ab(y,Math.min(240,o*.3)),lb(h,_,20,a-20)),t.northArrow!==!1){const L=typeof e.getBearing=="function"?e.getBearing():0;ub(h,o-48,56,48,L)}if(t.title&&(h.save(),h.fillStyle="rgba(255, 255, 255, 0.85)",h.fillRect(12,12,Math.min(o-24,t.title.length*11+24),34),h.fillStyle="#111827",h.font="18px sans-serif",h.textAlign="left",h.textBaseline="middle",h.fillText(t.title,24,30),h.restore()),t.attribution){h.save(),h.font="11px sans-serif",h.textAlign="right",h.textBaseline="bottom",h.fillStyle="rgba(255, 255, 255, 0.85)";const L=h.measureText(t.attribution).width;h.fillRect(o-L-12,a-20,L+8,16),h.fillStyle="#374151",h.fillText(t.attribution,o-8,a-6),h.restore()}const E=t.mimeType??"image/png",w=`${t.name??"map"}.${E==="image/jpeg"?"jpg":"png"}`;return{dataUrl:l.toDataURL(E,.92),width:o,height:a,filename:w,scaleBar:_}}function hb(i){if(typeof document>"u")throw new Error("Downloading needs a browser");const t=document.createElement("a");t.href=i.dataUrl,t.download=i.filename,document.body.appendChild(t),t.click(),t.remove()}class fb{constructor(){Y(this,"commands",new Map);Y(this,"aliasMap",new Map)}register(t){const e=t.name.toLowerCase();this.commands.set(e,t),t.aliases.forEach(n=>{this.aliasMap.set(n.toLowerCase(),e)})}get(t){const e=t.trim().toLowerCase();if(this.commands.has(e))return this.commands.get(e);const n=this.aliasMap.get(e);if(n&&this.commands.has(n))return this.commands.get(n)}getAll(){return Array.from(this.commands.values())}has(t){return!!this.get(t)}getNames(t=!0){const e=Array.from(this.commands.keys());return t?[...e,...this.aliasMap.keys()]:e}suggest(t){const e=t.trim().toLowerCase();return e?this.getNames().filter(n=>n.startsWith(e)).sort():[]}}class Ba extends Pe{constructor(t,e,n){super(`${t}: ${e.join(" · ")}${n?`. Usage: ${n}`:""}`),this.command=t,this.issues=e,this.name="ArgumentError"}}function db(i){const t=[];let e=0;for(;e<i.length;){if(/\s/.test(i[e])){e++;continue}const n=e,s=i[e];if(s==='"'||s==="'"){const r=i.indexOf(s,e+1);if(r>=0){t.push({text:i.slice(e+1,r),start:n,end:r+1,quoted:!0}),e=r+1;continue}}if(s==="["||s==="{"){const r=s==="["?"]":"}";let o=0,a=null,l=i.length;for(let h=e;h<i.length;h++){const f=i[h];if(a){f===a&&(a=null);continue}if(f==='"'||f==="'")a=f;else if(f===s)o++;else if(f===r&&--o===0){l=h+1;break}}t.push({text:i.slice(n,l),start:n,end:l,quoted:!1}),e=l;continue}for(;e<i.length&&!/\s/.test(i[e]);)e++;t.push({text:i.slice(n,e),start:n,end:e,quoted:!1})}return t}function l8(i){return db(i).map(t=>t.text)}function mn(i){return i.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}function u8(i,t){const e=Array.from({length:t.length+1},(n,s)=>[s,...Array(i.length).fill(0)]);for(let n=1;n<=i.length;n++)e[0][n]=n;for(let n=1;n<=t.length;n++)for(let s=1;s<=i.length;s++)e[n][s]=Math.min(e[n-1][s]+1,e[n][s-1]+1,e[n-1][s-1]+(i[s-1]===t[n-1]?0:1));return e[t.length][i.length]}function Uo(i,t){let e=null,n=Math.max(2,Math.floor(i.length/3));for(const s of t){const r=u8(i.toLowerCase(),s.toLowerCase());r<=n&&(n=r,e=s)}return e}function Zu(i,t){var e;return(e=i==null?void 0:i.properties)==null?void 0:e[t]}function dd(i){return i?Object.keys(i.properties??{}):[]}function gb(i,t,e){var n,s;return((n=Zu(i,t))==null?void 0:n.type)==="boolean"||!!((s=e==null?void 0:e.flags)!=null&&s.includes(t))}function Qp(i){var e,n;const t=dd(i.schema).map(mn);return Object.keys(((e=i.args)==null?void 0:e.aliases)??{}).forEach(s=>t.push(s)),Object.keys(((n=i.args)==null?void 0:n.switches)??{}).forEach(s=>t.push(s)),[...new Set(t)]}function c8(i,t,e){var r;return(r=e==null?void 0:e.aliases)!=null&&r[i]?e.aliases[i]:dd(t).find(o=>o===i||mn(o)===i)??null}function t0(i,t,e,n){const s=e==null?void 0:e.type;if(i==null||s===void 0&&!Array.isArray(e==null?void 0:e.enum))return i;if(s==="number"||s==="integer"){const o=typeof i=="number"?i:Number(String(i).trim());if(!Number.isFinite(o)){n.push(`${mn(t)} needs a number (got "${String(i)}")`);return}if(s==="integer"&&!Number.isInteger(o)){n.push(`${mn(t)} needs a whole number (got ${o})`);return}return e.minimum!==void 0&&o<e.minimum&&n.push(`${mn(t)} must be at least ${e.minimum}`),e.maximum!==void 0&&o>e.maximum&&n.push(`${mn(t)} must be at most ${e.maximum}`),o}if(s==="boolean"){if(typeof i=="boolean")return i;const o=String(i).trim().toLowerCase();if(["true","1","yes","on",""].includes(o))return!0;if(["false","0","no","off"].includes(o))return!1;n.push(`${mn(t)} needs true or false (got "${String(i)}")`);return}if(s==="array"){let o;if(Array.isArray(i))o=i;else{const a=String(i).trim();if(a.startsWith("["))try{o=JSON.parse(a)}catch{n.push(`${mn(t)} is not a valid list: ${a}`);return}else o=a.split(",").map(l=>l.trim()).filter(l=>l!=="")}if(!Array.isArray(o)){n.push(`${mn(t)} needs a list`);return}return e.items?o.map(a=>t0(a,t,e.items,n)):o}if(s==="object"){if(typeof i=="object")return i;try{return JSON.parse(String(i))}catch{n.push(`${mn(t)} needs a JSON object`);return}}const r=typeof i=="string"?i:String(i);if(Array.isArray(e==null?void 0:e.enum)&&!e.enum.includes(r)){const o=e.enum.find(l=>String(l).toLowerCase()===r.toLowerCase());if(o!==void 0)return o;const a=Uo(r,e.enum.map(String));n.push(`${mn(t)} must be one of ${e.enum.join(", ")} (got "${r}")${a?`; did you mean "${a}"?`:""}`);return}return r}function e0(i,t,e={}){const n=[],s=dd(i),r={};for(const[o,a]of Object.entries(t)){if(a===void 0)continue;const l=Zu(i,o);if(!l){if(s.length===0){r[o]=a;continue}const f=Uo(o,s);n.push(`unknown parameter "${o}"${f?`; did you mean "${f}"?`:""} (available: ${s.join(", ")})`);continue}const h=t0(a,o,l,n);h!==void 0&&(r[o]=h)}if(e.enforceRequired!==!1)for(const o of(i==null?void 0:i.required)??[])r[o]===void 0&&n.push(`${mn(o)} is required`);for(const o of s){const a=Zu(i,o);r[o]===void 0&&(a==null?void 0:a.default)!==void 0&&(r[o]=a.default)}return n.length?{ok:!1,issues:n}:{ok:!0,value:r}}function mb(i,t,e={}){var l,h,f,d;const n=(t??"").trim(),s=i.schema,r=i.args;let o={};if(n.startsWith("{"))try{o=JSON.parse(n)}catch(p){throw new Ba(i.name,[`the JSON arguments could not be read (${p instanceof Error?p.message:String(p)})`],i.usage)}else if(n){const p=db(n),y=[],_=[];for(let b=0;b<p.length;b++){const P=p[b],N=/^-[A-Za-z][A-Za-z0-9-]*(=|$)/.test(P.text);if(!P.text.startsWith("--")&&!N||P.quoted){y.push({token:P,index:b});continue}const S=N?"-":"--",[C,T]=P.text.slice(S.length).split(/=(.*)/s),I=(l=r==null?void 0:r.switches)==null?void 0:l[C];if(I){o[I.property]=T??I.value;continue}const M=c8(C,s,r);if(!M){const A=Qp(i),F=Uo(C,A),$=A.slice(0,12).map(D=>`--${D}`).join(", "),z=A.length>12?`${$}, … (${A.length} in all, see "help ${i.name}")`:$;_.push(`unknown option ${S}${C}${F?`; did you mean --${F}?`:A.length?` (available: ${z})`:""}`);continue}if(T!==void 0){o[M]=T;continue}if(gb(s,M,r)){const A=p[b+1];A&&["true","false"].includes(A.text.toLowerCase())?o[M]=p[++b].text:o[M]=!0;continue}const R=p[++b];if(R===void 0){_.push(`${S}${C} needs a value`);continue}o[M]=R.text}const E=(r==null?void 0:r.positional)??[],w=r==null?void 0:r.rest;let L=0;for(let b=0;b<y.length;b++){for(;L<E.length&&E[L]!==w&&o[E[L]]!==void 0;)L++;const P=E[L];if(w&&(P===w||L>=E.length)){const T=y.slice(b);if(o[w]!==void 0)T.forEach(I=>_.push(`too many values ("${I.token.text}")`));else if(((h=Zu(s,w))==null?void 0:h.type)==="array")o[w]=T.length===1&&T[0].token.text.startsWith("[")?T[0].token.text:T.map(I=>I.token.text);else{const I=[T[0]];for(let M=1;M<T.length&&T[M].index===I[I.length-1].index+1;M++)I.push(T[M]);o[w]=I.length===1&&I[0].token.quoted?I[0].token.text:n.slice(I[0].token.start,I[I.length-1].token.end),T.slice(I.length).forEach(M=>_.push(`too many values ("${M.token.text}")`))}break}if(!P){_.push(`too many values ("${y[b].token.text}")`);continue}const N=y[b].token.text,S=(f=r==null?void 0:r.fallback)==null?void 0:f[P],C=(d=Zu(s,P))==null?void 0:d.enum;if(S&&Array.isArray(C)&&!C.some(T=>String(T).toLowerCase()===N.toLowerCase())&&o[S]===void 0){o[S]=N,L++;continue}o[P]=N,L++}if(_.length)throw new Ba(i.name,_,i.usage)}const a=e0(s,o,{enforceRequired:e.enforceRequired??!1});if(!a.ok)throw new Ba(i.name,a.issues,i.usage);return a.value}function pb(i,t){const e=i.args,n=Object.fromEntries(Object.entries(t).filter(([,a])=>a!=null));if(!e)return Object.keys(n).length?JSON.stringify(n):"";const s=a=>{const l=Array.isArray(a)?a.some(h=>typeof h=="object"&&h!==null)?JSON.stringify(a):a.join(","):typeof a=="object"&&a!==null?JSON.stringify(a):String(a);return/\s|"/.test(l)?`"${l.replace(/"/g,'\\"')}"`:l},r=[],o=new Set;for(const a of e.positional??[]){if(n[a]===void 0)break;r.push(s(n[a])),o.add(a)}for(const[a,l]of Object.entries(n))if(!o.has(a)){if(gb(i.schema,a,e)){l&&r.push(`--${mn(a)}`);continue}r.push(`--${mn(a)}`,s(l))}return r.join(" ")}function Ju(i){var o,a,l,h,f;const t=[],e=i.aliases.length?` [${i.aliases.join(", ")}]`:"";t.push(`${i.name}${e} — ${i.description}`),i.usage&&t.push(` Usage: ${i.usage}`);const n=((o=i.schema)==null?void 0:o.properties)??{},s=new Set(((a=i.schema)==null?void 0:a.required)??[]),r=((l=i.args)==null?void 0:l.positional)??[];for(const[d,p]of Object.entries(n)){const y=[],_=p;y.push(_.type??"any"),_.enum&&y.push(`one of ${_.enum.join(" | ")}`),_.default!==void 0&&y.push(`default ${JSON.stringify(_.default)}`),s.has(d)&&y.push("required");const E=r.indexOf(d),w=E>=0?`word ${E+1} or --${mn(d)}`:`--${mn(d)}`,L=Object.entries(((h=i.args)==null?void 0:h.switches)??{}).filter(([,N])=>N.property===d).map(([N,S])=>`--${N} = ${JSON.stringify(S.value)}`),P=[...Object.entries(((f=i.args)==null?void 0:f.aliases)??{}).filter(([N,S])=>S===d&&N!==mn(d)).map(([N])=>`--${N}`),...L];t.push(` ${w}${P.length?` (also ${P.join(", ")})`:""} (${y.join(", ")})${_.description?`: ${_.description}`:""}`)}return t}class yb extends jr{constructor(e){super();Y(this,"registry",new fb);Y(this,"consoleService");Y(this,"currentAbortController",null);Y(this,"currentContext",null);this.consoleService=e}getContext(){return this.currentContext}async run(e,n=null){var r;this.cancel(),this.currentAbortController=new AbortController;const s={jobId:`job_${Date.now()}_${Math.random().toString(36).substring(2,7)}`,status:"running",commands:e,currentIndex:0,currentCommandName:null,currentPrompt:null,initialData:n,payload:n,intermediate:new Map,history:[],abortSignal:this.currentAbortController.signal};this.currentContext=s,this.emit("workflow:start",{context:s});try{return await this.executeCommands(s),s.status="completed",s.currentCommandName=null,this.emit("workflow:completed",{context:s}),s}catch(o){throw o instanceof Su||(r=s.abortSignal)!=null&&r.aborted?(s.status="cancelled",this.emit("workflow:cancelled",{context:s})):(s.status="failed",s.history.push({command:s.currentCommandName||"unknown",status:"error",durationMs:0,errorMsg:o.message}),this.emit("workflow:failed",{context:s,error:o})),o}finally{this.currentAbortController=null}}async runNested(e,n){const s={...n,commands:e,currentIndex:0,history:[],intermediate:new Map(n.intermediate)};return await this.executeCommands(s),n.history.push(...s.history),n.payload=s.payload,s}async executeCommands(e){var s;const n=e.commands;for(;e.currentIndex<n.length;e.currentIndex++){if((s=e.abortSignal)!=null&&s.aborted)throw new Su;const r=n[e.currentIndex],{cmdName:o,args:a}=this.parseCommandString(r),l=this.registry.get(o);if(!l){const p=Uo(o,this.registry.getNames());throw new Pe(`Command "${o}" not found${p?`. Did you mean "${p}"?`:'. Type "help" to list the commands.'}`)}e.currentCommandName=l.name,e.intermediate.set("_lastRawArgs",a),e.intermediate.delete("_args"),(l.args||l.schema)&&e.intermediate.set("_args",mb(l,a)),this.emit("workflow:step",{context:e,commandName:l.name});const h=Date.now();await l.execute(e,this.consoleService);const f=Date.now()-h,d={command:r,status:"success",durationMs:f};e.history.push(d)}}cancel(){this.currentAbortController&&(this.currentAbortController.abort(),this.currentAbortController=null),this.consoleService.cancel()}parseCommandString(e){const n=e.trim(),s=n.indexOf(" ");return s===-1?{cmdName:n,args:""}:{cmdName:n.substring(0,s),args:n.substring(s+1).trim()}}}function Fs(i,t){if(t&&t.isEditing()){const s=t.getActiveEditingFeature(),r=t.getActiveEditingLayerId();if(s&&s.id!==void 0&&r)return{layerId:r,featureId:s.id}}const e=i.getActiveLayerId();if(e){const s=i.getSelectedFeatureIds(e);if(s.length>0)return{layerId:e,featureId:s[0]}}const n=i.getAnySelectedFeature();return n||null}function qa(i,t){const e=i.getActiveLayerId();if(e){const s=i.getSelectedFeatureIds(e);if(s.length>0)return{layerId:e,featureIds:s}}const n=i.getAnySelectedFeatures();if(n)return n;if(t&&t.isEditing()){const s=t.getActiveEditingFeature(),r=t.getActiveEditingLayerId();if(s&&s.id!==void 0&&r)return{layerId:r,featureIds:[s.id]}}return null}function un(i,t,e){e&&t!==e&&i.print(`[Target: เลเยอร์ "${t}"] (Active Layer ปัจจุบันคือ "${e}")`,"output")}function La(i,t){const e=[],n=new Set,s=i.getActiveLayerId();if(s){const r=i.getSelectedFeatureIds(s);for(const o of r){const a=i.getFeature(s,o);if(a&&a.id!==void 0){const l=`${s}:${a.id}`;n.has(l)||(n.add(l),e.push({layerId:s,feature:a}))}}}for(const r of i.getAllLayers()){if(r.id===s)continue;const o=i.getSelectedFeatureIds(r.id);for(const a of o){const l=r.getFeature(a);if(l&&l.id!==void 0){const h=`${r.id}:${l.id}`;n.has(h)||(n.add(h),e.push({layerId:r.id,feature:l}))}}}if(e.length===0&&t&&t.isEditing()){const r=t.getActiveEditingFeature(),o=t.getActiveEditingLayerId();r&&r.id!==void 0&&o&&e.push({layerId:o,feature:r})}return e}function _m(i,t,e){const n=De(t);for(const s of i.getAllLayers())for(const r of s.queryBBox(n))if(!(r.id===t.id||!e(r))&&To(t,r))return{layerId:s.id,feature:r};return null}async function Nr(i,t,e){return typeof i.requestPointOrText=="function"?i.requestPointOrText(t,{basePoint:e}):{text:(await i.requestInput(t)).trim()}}async function Ze(i,t,e){const n=await i.requestPoint(t,{basePoint:e});if(!n)throw new Error("Command cancelled: a point is required.");return n}function Th(i,t){return La(i,t).filter(e=>e.feature.id!==void 0).map(e=>({layerId:e.layerId,featureId:e.feature.id,feature:e.feature}))}function us(i){if(!/^[-+]?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?$/i.test(i.trim()))return null;const t=Number(i);return Number.isFinite(t)?t:null}function Vt(i){return i.intermediate.get("_args")??{}}function gd(i){const t=Array.isArray(i)?i.slice(0,2).join(", "):String(i);if(Array.isArray(i)&&i.length>=2){const n=Number(i[0]),s=Number(i[1]);if(lc(n,s))return[n,s];throw new Error(qh(t))}const e=Fm(t);if(e)return e;throw new Error(qh(t))}function Rh(i){const t=Vt(i).coordinates;return!Array.isArray(t)||t.length===0?null:t.map(gd)}function _b(i,t){return[{name:"draw_line",aliases:["line","l"],description:"Draw a LineString by clicking map or specifying coordinates",usage:"line 100.5,13.7 100.6,13.8 | line [[100.5, 13.7], [100.6, 13.8]] (lng,lat)",isInteractive:!0,args:{positional:["coordinates"],rest:"coordinates"},schema:{type:"object",properties:{coordinates:{type:"array",description:"Array of [lng, lat] coordinates — longitude first, as in GeoJSON",items:{type:"array",items:{type:"number"}}}}},async execute(r,o){let a=Rh(r);if(a&&a.length<2)throw new Error("A line needs at least 2 points.");if(!a)for(o.print("Specify first point [lng,lat] or click map:","prompt"),a=[];;){const h=await o.requestPoint(a.length===0?"First point:":`Next point (${a.length}) [Press Enter to finish]:`);if(!h){if(a.length>=2)break;o.print("Line requires at least 2 points.","error");continue}a.push(h),o.print(`Point added: ${h[0].toFixed(5)}, ${h[1].toFixed(5)}`,"output")}const l=i.drawLineByCoords(a);return o.print(`Line drawn successfully with ${a.length} vertices.`,"success"),r.payload=l,r}},{name:"draw_polygon",aliases:["polygon","poly","p"],description:"Draw a Polygon by coordinates or interactive map clicking",usage:"polygon 100.5,13.7 100.6,13.7 100.6,13.8 | polygon [[100.5, 13.7], …] (lng,lat)",isInteractive:!0,args:{positional:["coordinates"],rest:"coordinates"},schema:{type:"object",properties:{coordinates:{type:"array",description:"Ring of [lng, lat] coordinates — longitude first, as in GeoJSON",items:{type:"array",items:{type:"number"}}}}},async execute(r,o){let a=Rh(r);if(a&&a.length<3)throw new Error("A polygon needs at least 3 points.");if(!a)for(o.print("Specify points for Polygon (at least 3) [lng,lat] or click map:","prompt"),a=[];;){const h=await o.requestPoint(`Point ${a.length+1} [Press Enter when done]:`);if(!h){if(a.length>=3)break;o.print("Polygon requires at least 3 points.","error");continue}a.push(h),o.print(`Vertex added: ${h[0].toFixed(5)}, ${h[1].toFixed(5)}`,"output")}const l=i.drawPolygonByCoords(a);return o.print(`Polygon drawn successfully with ${a.length} vertices.`,"success"),r.payload=l,r}},{name:"draw_point",aliases:["point","pt"],description:"Place one or more point features on the map",usage:"point 100.5018,13.7563 | point [[100.5018, 13.7563], [100.5020, 13.7565]] (lng,lat)",isInteractive:!0,args:{positional:["coordinates"],rest:"coordinates"},schema:{type:"object",properties:{coordinates:{type:"array",description:"One or more [lng, lat] coordinates — longitude first, e.g. [[100.5018, 13.7563], [100.5020, 13.7565]]. All of them are placed in one undo step.",items:{type:"array",items:{type:"number"}}}}},async execute(r,o){let a=Rh(r)??[];if(a.length===0){const h=await o.requestPoint("Specify point coordinate [lng,lat]:");h&&(a=[h])}if(a.length===0)throw new Error("No coordinate provided");if(a.length===1){const h=i.drawPointByCoords(a[0]);return o.print(`Point placed at ${a[0][0].toFixed(5)}, ${a[0][1].toFixed(5)}`,"success"),r.payload=h,r}const l=t.runTransaction(`Place ${a.length} points`,()=>a.map(h=>i.drawPointByCoords(h)));return o.print(`${l.length} points placed.`,"success"),r.payload=l,r}}]}function vb(i,t){const e={name:"ortho",aliases:["orthomode"],description:"Toggle or set orthogonal 90-degree angle locking (AutoCAD F8)",usage:"ortho [on|off]",isInteractive:!1,schema:{type:"object",properties:{state:{type:"string",enum:["on","off"],description:"Leave empty to toggle"}}},args:{positional:["state"]},async execute(tt,et){const it=Vt(tt).state,H=it?it==="on":!i.orthoEnabled;return i.setOrtho(H),et.print(`ORTHO is now ${H?"ON (Locked 90°)":"OFF"}`,"success"),tt.payload={ortho:H},tt}},n={name:"osnap",aliases:["snap"],description:"Configure object snaps (vertex/end, intersection/int, midpoint/mid, center/cen, perpendicular/per, edge/nea)",usage:"osnap [on|off|end|int|mid|cen|per|nea]",isInteractive:!1,schema:{type:"object",properties:{mode:{type:"string",description:"on, off, or a snap type: end, int, mid, cen, per, nea"}}},args:{positional:["mode"]},async execute(tt,et){const it=String(Vt(tt).mode??"").trim().toLowerCase(),H={vertex:"vertex",end:"vertex",endpoint:"vertex",intersection:"intersection",int:"intersection",midpoint:"midpoint",mid:"midpoint",center:"center",cen:"center",perpendicular:"perpendicular",per:"perpendicular",edge:"edge",nea:"edge",nearest:"edge"};if(it==="on"||it==="1")i.snapping.enabled=!0,et.print("OSNAP is now ON","success");else if(it==="off"||it==="0")i.snapping.enabled=!1,et.print("OSNAP is now OFF","output");else if(H[it]){const nt=H[it],ot=i.snapping.toggleMode(nt);et.print(`OSnap ${nt} is now ${ot?"ENABLED":"DISABLED"}`,"success")}else{const nt=i.snapping.modes,ot=Object.keys(nt).map(ut=>`${ut}: ${nt[ut]?"ON":"OFF"}`).join(", ");et.print(`OSNAP ${i.snapping.enabled?"ON":"OFF"} [${ot}] (F3 toggles OSNAP)`,"prompt")}return tt.payload={modes:i.snapping.modes,enabled:i.snapping.enabled},tt}},s={name:"polar",aliases:["polartracking"],description:"Toggle polar tracking or set its angle increment in degrees (AutoCAD F10)",usage:"polar [on|off|<increment_degrees>]",isInteractive:!1,schema:{type:"object",properties:{mode:{type:"string",description:"on, off, or the angle increment in degrees (e.g. 15)"}}},args:{positional:["mode"]},async execute(tt,et){const it=String(Vt(tt).mode??"").trim().toLowerCase(),H=us(it);if(it==="on")i.setPolarTracking({enabled:!0});else if(it==="off")i.setPolarTracking({enabled:!1});else if(H!==null){if(H<=0||H>180)throw new Error("Polar increment must be between 0 and 180 degrees.");i.setPolarTracking({enabled:!0,incrementDeg:H})}else if(!it)i.togglePolarTracking();else throw new Error("Usage: polar [on|off|<increment_degrees>]");const nt=i.polarTracking;return et.print(`POLAR is now ${nt.enabled?`ON (every ${nt.incrementDeg}°)`:"OFF"}`,"success"),tt.payload={...nt},tt}},r={name:"ucs",aliases:[],description:'Align ORTHO, polar tracking and @dx,dy input with a direction: pick 2 points along an edge, type the X-axis angle, or "world" to reset',usage:"ucs [world|<x_axis_angle>]",isInteractive:!0,schema:{type:"object",properties:{axis:{type:"string",description:'"world" to reset, or the X-axis angle in degrees; leave empty to pick two points'}}},args:{positional:["axis"]},async execute(tt,et){let it=String(Vt(tt).axis??"").trim().toLowerCase();const H=i.inputFrame;if(!it){const nt=await Nr(et,"Specify first point on the X axis, X-axis angle, or [World]:");if("point"in nt){const ot=await Ze(et,"Specify second point on the X axis:",nt.point),ut=Qe(nt.point,ot,{convention:"cad",ucsRotationDeg:0}).angle;return i.setUcsRotation(ut),et.print(`UCS aligned with picked edge (X axis ${Et(Qe(nt.point,ot,{...H,ucsRotationDeg:0}).angle,H.convention)}).`,"success"),tt.payload={...i.inputFrame},tt}it=nt.text.toLowerCase()}if(it==="world"||it==="w"||it==="")i.setUcsRotation(0),et.print("UCS reset to World (X = East, Y = North).","success");else{const nt=us(it);if(nt===null)throw new Error("Usage: ucs [world|<x_axis_angle>]");const ot=Uu(nt,{convention:H.convention,ucsRotationDeg:0});i.setUcsRotation(ot*180/Math.PI),et.print(`UCS X axis set to ${Et(nt,H.convention)}.`,"success")}return tt.payload={...i.inputFrame},tt}},o={name:"angles",aliases:["angdir","units"],description:"Choose how angles are typed: bearing (0°=North, clockwise) or cad (0°=East, counter-clockwise)",usage:"angles [bearing|cad]",isInteractive:!1,schema:{type:"object",properties:{convention:{type:"string",enum:["bearing","cad"],description:"bearing: 0° = north, clockwise"}}},args:{positional:["convention"]},async execute(tt,et){const it=String(Vt(tt).convention??"").trim().toLowerCase();if(it==="bearing"||it==="cad")i.setAngleConvention(it);else if(it)throw new Error("Usage: angles [bearing|cad]");const H=i.inputFrame.convention;return et.print(H==="bearing"?"Angles: bearing (0° = North, clockwise). Positive rotation = clockwise.":"Angles: CAD (0° = East, counter-clockwise). Positive rotation = counter-clockwise.","success"),tt.payload={convention:H},tt}};let a=10;const l={name:"offset",aliases:["o"],description:"Offset lines or polygons. No arguments: type distance (or T for Through), click objects and the side (AutoCAD). With a distance: offset the selected feature (positive = right/outward, negative = left/inward)",usage:"offset (interactive) | offset <distance_in_meters> [--copy|-c]",isInteractive:!0,schema:{type:"object",properties:{distance:{type:"number",description:"Offset distance in meters"},copy:{type:"boolean",description:"Create a new parallel feature instead of modifying in-place"}},required:["distance"]},args:{positional:["distance"],aliases:{c:"copy"}},async execute(tt,et){const it=Vt(tt);let H=it.distance,nt=!!it.copy;if(Object.keys(it).length===0)return gt(tt,et);if(!Number.isFinite(H)){const he=(await et.requestInput("Specify offset distance in meters (e.g. 15 or -15, add --copy to keep original):")).trim().split(/\s+/).filter(Boolean);if(H=parseFloat(he[0]),he.some(Ae=>["--copy","-c","copy"].includes(Ae.toLowerCase()))&&(nt=!0),!Number.isFinite(H))throw new Error("Invalid offset distance.")}const ot=Fs(t,i);if(!ot)throw new Error("Please select a feature on the map to offset.");const{layerId:ut,featureId:rt}=ot;un(et,ut,t.getActiveLayerId());const Ct=i.offsetFeature(ut,rt,H,nt);if(!Ct)throw new Error(`Failed to offset feature ${rt}.`);i.flashFeatures(Ct);const kt=H>=0?"ขวา/ขยายออก (right/outward)":"ซ้าย/ยุบเข้า (left/inward)";return nt?et.print(`Created parallel offset feature [${Ct.id}] from [${rt}] by ${H}m (${kt}).`,"success"):(et.print(`Offset feature [${rt}] by ${H}m successfully (${kt} relative to current shape).`,"success"),et.print("💡 Tip: สั่ง 'offset <dist> --copy' (หรือ -c) หากต้องการสร้างเส้นขนานใหม่โดยคงเส้นเดิมไว้ (AutoCAD style)","prompt")),tt.payload=Ct,tt}},h={name:"rotate",aliases:["ro"],description:"Rotate selected features around a base point. Positive angle follows the angle convention (bearing: clockwise)",usage:"rotate [angle_degrees] (no argument: pick base point, then angle / point / Reference)",isInteractive:!0,schema:{type:"object",properties:{angle:{type:"number",description:"Rotation in degrees around the selection center"}},required:["angle"]},args:{positional:["angle"]},async execute(tt,et){const it=wt(t,i,"rotate"),H=i.inputFrame,nt=us(Xt(tt,"angle"));let ot,ut;nt!==null?(ot=V(it),ut=nt):(ot=await Ze(et,"Specify base point:"),ut=await Gt(et,"Specify rotation angle or [Reference]:",ot,H));const rt=-(am(ut,H)*180)/Math.PI,Ct=i.transformFeatures(it,`Rotate ${it.length} feature(s) by ${ut}°`,kt=>ue.rotate(kt,rt,ot));return i.flashFeatures(Ct),et.print(`Rotated ${Ln(it)} by ${ut}° ${H.convention==="bearing"?"clockwise":"counter-clockwise"}.`,"success"),tt.payload=Ct.length===1?Ct[0]:Ct,tt}},f={name:"scale",aliases:["sc"],description:"Scale selected features around a base point by a factor, or by Reference length -> new length",usage:"scale [factor] (no argument: pick base point, then factor or Reference)",isInteractive:!0,schema:{type:"object",properties:{factor:{type:"number",description:"Scale factor around the selection center (e.g. 1.5)"}},required:["factor"]},args:{positional:["factor"]},async execute(tt,et){const it=wt(t,i,"scale"),H=us(Xt(tt,"factor"));let nt,ot;if(H!==null)nt=V(it),ot=H;else for(nt=await Ze(et,"Specify base point:"),ot=NaN;!Number.isFinite(ot);){const rt=await Nr(et,"Specify scale factor or [Reference]:",nt);if("point"in rt){et.print("Type a scale factor, or R to scale by reference lengths.","error");continue}if(rt.text.toLowerCase().startsWith("r")){const Ct=await Ut(et,"Specify reference length (meters) or pick 2 points:"),kt=await Ut(et,"Specify new length (meters) or pick 2 points:");if(Ct<=0)throw new Error("Reference length must be greater than 0.");ot=kt/Ct}else{const Ct=us(rt.text);Ct===null?et.print(`Invalid scale factor "${rt.text}".`,"error"):ot=Ct}}if(!(ot>0))throw new Error("Scale factor must be greater than 0.");const ut=i.transformFeatures(it,`Scale ${it.length} feature(s) by ${ot}`,rt=>ue.scale(rt,ot,nt));return i.flashFeatures(ut),et.print(`Scaled ${Ln(it)} by factor ${Number(ot.toFixed(6))}.`,"success"),tt.payload=ut.length===1?ut[0]:ut,tt}},d={name:"mirror",aliases:["mi"],description:"Mirror selected features across a line defined by 2 points (keeps originals unless erase is chosen)",usage:'mirror (pick 2 points of the mirror line) | mirror {"from":[lng,lat],"to":[lng,lat],"erase":false}',isInteractive:!0,schema:{type:"object",properties:{from:{type:"array",items:{type:"number"},description:"First point of mirror line [lng, lat]"},to:{type:"array",items:{type:"number"},description:"Second point of mirror line [lng, lat]"},erase:{type:"boolean",description:"Delete the source features (default false)"}},required:["from","to"]},async execute(tt,et){const it=wt(t,i,"mirror"),H=Vt(tt);let nt,ot,ut;if(H&&Array.isArray(H.from)&&Array.isArray(H.to))nt=[Number(H.from[0]),Number(H.from[1])],ot=[Number(H.to[0]),Number(H.to[1])],ut=!!H.erase;else{nt=await Ze(et,"Specify first point of mirror line:"),ot=await Ze(et,"Specify second point of mirror line:",nt);const Ct=(await et.requestInput("Erase source objects? [Yes/No] <N>:")).trim().toLowerCase();ut=Ct==="y"||Ct==="yes"}const rt=i.transformFeatures(it,`Mirror ${it.length} feature(s)`,Ct=>ue.mirror(Ct,nt,ot),!ut);return i.flashFeatures(rt),et.print(`Mirrored ${Ln(it)}${ut?" (source replaced)":""}.`,"success"),tt.payload=rt.length===1?rt[0]:rt,tt}},p={name:"explode",aliases:["x"],description:"Explode selected Polygon into separate LineStrings",isInteractive:!1,schema:{type:"object",properties:{}},async execute(tt,et){const it=Fs(t,i);if(!it)throw new Error("Please select a polygon feature to explode.");const{layerId:H,featureId:nt}=it;un(et,H,t.getActiveLayerId());const ot=i.explodeFeature(H,nt);if(!ot)throw new Error("Explode requires a Polygon feature.");return et.print(`Exploded polygon into ${ot.length} LineString segments.`,"success"),tt.payload=ot,tt}},y={name:"edit",aliases:["grip","grips"],description:"Toggle Grips editing mode on the selected feature",isInteractive:!1,schema:{type:"object",properties:{}},async execute(tt,et){const it=Fs(t,i);if(!it)return i.grips.clear(),et.print("Grips cleared. Please select a feature to edit.","output"),tt;const{layerId:H,featureId:nt}=it;return un(et,H,t.getActiveLayerId()),i.grips.editFeature(H,nt),et.print(`Grips editing active for feature [${nt}]. Drag blue vertices or midpoint handles to reshape.`,"success"),tt}},_={name:"move",aliases:["m","translate"],description:"Move selected features from a base point to a second point, or by distance and angle",usage:"move [distance_meters [angle]] (no argument: pick base point, then second point or @dx,dy)",isInteractive:!0,schema:{type:"object",properties:{distance:{type:"number",description:"Distance in meters to move"},bearing:{type:"number",description:"Direction in degrees in the current angle convention (default: East)"}},required:["distance"]},args:{positional:["distance","bearing"]},async execute(tt,et){const it=wt(t,i,"move"),H=await w(tt,et,"distance","bearing");if(!H)throw new Error("Command cancelled: a second point is required.");const nt=i.transformFeatures(it,`Move ${it.length} feature(s)`,rt=>ue.translateByVector(rt,H.from,H.to)),{distance:ot,angle:ut}=Qe(H.from,H.to,i.inputFrame);return et.print(`Moved ${Ln(it)} by ${Number(ot.toFixed(3))}m at ${Et(ut,i.inputFrame.convention)} successfully.`,"success"),tt.payload=nt.length===1?nt[0]:nt,tt}},E={name:"copy",aliases:["co","cp"],description:"Copy selected features from a base point to one or more second points, or by distance and angle",usage:"copy [distance_meters [angle]] (no argument: pick base point, then second points; Enter to finish)",isInteractive:!0,schema:{type:"object",properties:{distance:{type:"number",description:"Distance in meters to offset the copy"},bearing:{type:"number",description:"Direction in degrees in the current angle convention (default: East)"}},required:["distance"]},args:{positional:["distance","bearing"]},async execute(tt,et){const it=wt(t,i,"copy"),H=[],nt=await w(tt,et,"distance","bearing",!0);if(nt)H.push(...i.transformFeatures(it,`Copy ${it.length} feature(s)`,ot=>ue.translateByVector(ot,nt.from,nt.to),!0));else{const ot=await Ze(et,"Specify base point:");for(;;){const ut=await et.requestPoint("Specify second point or @dx,dy [Enter to finish]:",{basePoint:ot});if(!ut)break;const rt=i.transformFeatures(it,`Copy ${it.length} feature(s)`,Ct=>ue.translateByVector(Ct,ot,ut),!0);i.flashFeatures(rt),H.push(...rt)}}return et.print(`Created ${H.length} copied feature(s): ${H.map(ot=>ot.id).join(", ")}`,"success"),tt.payload=H.length===1?H[0]:H,tt}};async function w(tt,et,it,H,nt=!1){const ot=i.inputFrame,ut=Vt(tt),rt=ut[it]!==void 0?Number(ut[it]):null;if(rt!==null&&Number.isFinite(rt)){const At=ut[H],he=At!==void 0?Number(At):null,Ae=he!==null&&Number.isFinite(he)?Uu(he,ot):0,Cn=V(Th(t,i));return{from:Cn,to:Hs(Cn,rt,Ae)}}if(nt)return null;const Ct=await Ze(et,"Specify base point:"),kt=await et.requestPoint("Specify second point or @dx,dy:",{basePoint:Ct});return kt?{from:Ct,to:kt}:null}const L={name:"delete",aliases:["del","erase","e"],description:"Delete selected feature(s) from the active layer",usage:"delete",isInteractive:!1,schema:{type:"object",properties:{}},async execute(tt,et){const it=qa(t,i);if(!it||it.featureIds.length===0)throw new Error("Please select a feature on the map to delete.");const{layerId:H,featureIds:nt}=it;un(et,H,t.getActiveLayerId());let ot=0;return t.runTransaction(`Delete ${nt.length} feature(s) from ${H}`,()=>{for(const ut of nt)i.deleteFeature(H,ut)&&ot++}),et.print(`Deleted ${ot} feature(s) from layer "${H}".`,"success"),tt.payload={deletedCount:ot},tt}};let b=0;const P={name:"fillet",aliases:["f"],description:"Fillet two picked lines (trim/extend to a sharp corner, or round with a radius), or round one vertex of the selected feature by index",usage:"fillet (pick 2 lines, R to set radius) | fillet <vertex_index> [radius_meters]",isInteractive:!0,schema:{type:"object",properties:{vertexIndex:{type:"integer",minimum:0,description:"Vertex of the selected feature to round (leave empty to pick two lines)"},radius:{type:"number",minimum:0,default:5,description:"Fillet radius in meters (0 = sharp corner)"}}},args:{positional:["vertexIndex","radius"]},async execute(tt,et){const it=Vt(tt),H=it.vertexIndex!==void 0?Number(it.vertexIndex):NaN,nt=it.radius??5;if(Number.isNaN(H))for(;;){const kt=await Nr(et,`Select first line or [Radius] <R=${b} m>:`);if("text"in kt){if(kt.text.toLowerCase().startsWith("r")){const Ae=await ft(et,`Specify fillet radius (meters) <${b}>:`,b);if(Ae<0)throw new Error("Radius cannot be negative.");b=Ae;continue}if(!kt.text)throw new Error("Command cancelled.");et.print("Click a line, or type R to set the radius.","error");continue}const At=await Ze(et,"Select second line:"),he=i.filletLinesAt(kt.point,At,b);return i.flashFeatures([...he.lines,...he.arc?[he.arc]:[]]),et.print(b>0?`Filleted lines [${he.lines[0].id}] and [${he.lines[1].id}] with radius ${b} m (arc [${he.arc.id}]).`:`Joined lines [${he.lines[0].id}] and [${he.lines[1].id}] at a sharp corner.`,"success"),tt.payload=he,tt}const ot=Fs(t,i);if(!ot)throw new Error("Please select a feature on the map to fillet.");const{layerId:ut,featureId:rt}=ot;un(et,ut,t.getActiveLayerId());const Ct=i.filletFeature(ut,rt,H,nt);if(!Ct){const kt=t.getFeature(ut,rt),At=kt?ue.maxFilletRadius(kt,H):0;throw new Error(At>0?`Radius ${nt}m is too large for vertex ${H}. Maximum radius is ${At.toFixed(3)}m.`:`Vertex ${H} cannot be filleted (line endpoint, straight corner, or invalid index).`)}return et.print(`Filleted vertex [${H}] with radius ${nt}m on feature [${rt}].`,"success"),tt.payload=Ct,tt}},N={name:"simplify",aliases:["simp"],description:"Simplify polygon or line geometry by reducing vertices",usage:"simplify [tolerance]",isInteractive:!1,schema:{type:"object",properties:{tolerance:{type:"number",minimum:0,default:1e-4,description:"Douglas-Peucker tolerance in degrees (0.0001 ≈ 11 m)"}}},args:{positional:["tolerance"]},async execute(tt,et){const it=Vt(tt).tolerance??1e-4,H=Fs(t,i);if(!H)throw new Error("Please select a feature on the map to simplify.");const{layerId:nt,featureId:ot}=H;un(et,nt,t.getActiveLayerId());const ut=i.simplifyFeature(nt,ot,it);return et.print(`Simplified feature [${ot}] geometry with tolerance ${it}.`,"success"),tt.payload=ut,tt}},S={name:"smooth",aliases:["bezier"],description:"Smooth a LineString feature using Bezier interpolation",usage:"smooth [resolution]",isInteractive:!1,schema:{type:"object",properties:{resolution:{type:"integer",minimum:2,default:32,description:"Points generated per Bezier segment"}}},args:{positional:["resolution"]},async execute(tt,et){const it=Vt(tt).resolution??32,H=Fs(t,i);if(!H)throw new Error("Please select a LineString feature to smooth.");const{layerId:nt,featureId:ot}=H;un(et,nt,t.getActiveLayerId());const ut=i.smoothFeature(nt,ot,it);if(!ut)throw new Error("Smooth requires a LineString feature.");return et.print(`Smoothed LineString [${ot}] with Bezier curve.`,"success"),tt.payload=ut,tt}},C={name:"reverse",aliases:["rev"],description:"Reverse vertex direction of selected LineString",usage:"reverse",isInteractive:!1,schema:{type:"object",properties:{}},async execute(tt,et){const it=Fs(t,i);if(!it)throw new Error("Please select a LineString feature to reverse.");const{layerId:H,featureId:nt}=it;un(et,H,t.getActiveLayerId());const ot=i.reverseLine(H,nt);if(!ot)throw new Error("Reverse requires a LineString feature.");return i.flashFeatures(ot),et.print(`Reversed vertex order of LineString [${nt}].`,"success"),tt.payload=ot,tt}},T={name:"difference",aliases:["diff","subtract"],description:"Cut target polygon with cutting polygon (requires 2 selected polygons)",usage:"difference",isInteractive:!1,schema:{type:"object",properties:{}},async execute(tt,et){const it=qa(t,i);if(!it||it.featureIds.length<2)throw new Error("Difference requires 2 selected polygons: 1st is target, 2nd is cutter.");const{layerId:H,featureIds:nt}=it;un(et,H,t.getActiveLayerId());const ot=nt[0],ut=nt[1],rt=i.differenceFeature(H,ot,ut);if(!rt)throw new Error("Failed to calculate polygon difference.");return et.print(`Subtracted polygon [${ut}] from [${ot}] successfully.`,"success"),tt.payload=rt,tt}},I={name:"intersect",aliases:["int"],description:"Find intersection between 2 selected polygons",usage:"intersect",isInteractive:!1,schema:{type:"object",properties:{}},async execute(tt,et){const it=qa(t,i);if(!it||it.featureIds.length<2)throw new Error("Intersect requires 2 selected polygons.");const{layerId:H,featureIds:nt}=it;un(et,H,t.getActiveLayerId());const ot=i.intersectFeatures(H,nt[0],nt[1]);if(!ot)throw new Error("Failed to find intersection between selected polygons.");return et.print(`Generated intersection polygon [${ot.id}].`,"success"),tt.payload=ot,tt}},M={name:"split",aliases:["cut","split_polygon","split_poly"],description:"Split selected polygon using a cutting line, or split a line",usage:"split [cutter_feature_id]",isInteractive:!1,schema:{type:"object",properties:{cutterFeatureId:{type:"string",description:"Feature that cuts (default: the other selected feature)"}}},args:{positional:["cutterFeatureId"]},async execute(tt,et){var ut;const it=La(t,i),H=String(Vt(tt).cutterFeatureId??"").trim(),nt=it.find(rt=>rt.feature.geometry.type==="Polygon"||rt.feature.geometry.type==="MultiPolygon"),ot=it.find(rt=>rt.feature.geometry.type==="LineString"||rt.feature.geometry.type==="MultiLineString");if(nt&&ot&&it.length>=2){un(et,nt.layerId,t.getActiveLayerId());const rt=i.splitPolygon(nt.layerId,nt.feature.id,ot.feature.id);if(!rt||rt.length<2)throw new Error(`Failed to split polygon [${nt.feature.id}] with line [${ot.feature.id}]. Ensure the line crosses completely through the polygon.`);return i.flashFeatures(rt),t.selectFeature(nt.layerId,rt[0].id,!1),et.print(`Split polygon [${nt.feature.id}] into ${rt.length} parts with line [${ot.feature.id}].`,"success"),tt.payload=rt,tt}if(nt){un(et,nt.layerId,t.getActiveLayerId());const rt=H?H.split(/\s+/)[0]:void 0,Ct=i.splitPolygon(nt.layerId,nt.feature.id,rt);if(!Ct||Ct.length<2)throw new Error(`Failed to split polygon [${nt.feature.id}]. Make sure an intersecting line crosses through it.`);return i.flashFeatures(Ct),et.print(`Split polygon [${nt.feature.id}] into ${Ct.length} parts (auto-detected cutting line).`,"success"),tt.payload=Ct,tt}if(ot){un(et,ot.layerId,t.getActiveLayerId());const rt=it.find(At=>At.feature.id!==ot.feature.id);let Ct=rt?rt.feature.id:H?H.split(/\s+/)[0]:void 0;if(Ct||(Ct=(ut=_m(t,ot.feature,At=>At.geometry.type==="LineString"||At.geometry.type==="Point"))==null?void 0:ut.feature.id),!Ct)throw new Error("Please select a cutting line/point or specify cutter ID to split this line.");const kt=i.splitLine(ot.layerId,ot.feature.id,Ct);if(!kt||kt.length<2)throw new Error(`Failed to split line [${ot.feature.id}]. Ensure cutter intersects the line.`);return i.flashFeatures(kt),et.print(`Split line [${ot.feature.id}] into ${kt.length} segments.`,"success"),tt.payload=kt,tt}throw new Error("Please select a polygon (with a cutting line) or a line to split.")}},R={name:"split_overlap",aliases:["slice","split_overlapping","extract_overlap"],description:"Split 2 overlapping polygons into disjoint pieces (A\\B, A∩B, B\\A)",usage:"split_overlap",isInteractive:!1,schema:{type:"object",properties:{}},async execute(tt,et){const H=La(t,i).filter(Ct=>Ct.feature.geometry.type==="Polygon"||Ct.feature.geometry.type==="MultiPolygon");if(H.length<2)throw new Error("split_overlap requires at least 2 selected overlapping polygons.");const nt=H[0],ot=H[1];un(et,nt.layerId,t.getActiveLayerId());const ut=i.splitOverlappingPolygons(nt.layerId,nt.feature.id,ot.feature.id);if(!ut)throw new Error(`Polygons [${nt.feature.id}] and [${ot.feature.id}] do not overlap or could not be split.`);i.flashFeatures([...ut.pieceA,...ut.overlap,...ut.pieceB]);const rt=ut.pieceA.length+ut.overlap.length+ut.pieceB.length;return et.print(`Split overlapping polygons into ${rt} pieces: ${ut.pieceA.length} from [${nt.feature.id}], ${ut.overlap.length} overlap, ${ut.pieceB.length} from [${ot.feature.id}].`,"success"),tt.payload=ut,tt}},A={name:"split_line",aliases:["splitline"],description:"Break or split a selected LineString at an intersection point or cutter line",usage:"split_line [cutter_id]",isInteractive:!1,schema:{type:"object",properties:{cutterFeatureId:{type:"string",description:"Feature that cuts (default: the other selected feature)"}}},args:{positional:["cutterFeatureId"]},async execute(tt,et){var rt;const it=La(t,i),H=it.filter(Ct=>Ct.feature.geometry.type==="LineString"||Ct.feature.geometry.type==="MultiLineString");if(H.length===0)throw new Error("Please select a LineString to split.");const nt=H[0];un(et,nt.layerId,t.getActiveLayerId());let ot=Vt(tt).cutterFeatureId||void 0;if(!ot&&it.length>=2){const Ct=it.find(kt=>kt.feature.id!==nt.feature.id);Ct&&(ot=Ct.feature.id)}if(ot||(ot=(rt=_m(t,nt.feature,Ct=>Ct.geometry.type==="LineString"||Ct.geometry.type==="Point"))==null?void 0:rt.feature.id),!ot)throw new Error(`No intersecting cutter line/point found to split line [${nt.feature.id}].`);const ut=i.splitLine(nt.layerId,nt.feature.id,ot);if(!ut||ut.length<2)throw new Error(`Failed to split line [${nt.feature.id}]. Ensure cutter intersects the line.`);return et.print(`Split line [${nt.feature.id}] into ${ut.length} segments.`,"success"),tt.payload=ut,tt}},F={name:"join",aliases:["connect","j","join_lines"],description:"Connect 2 selected lines (preserves 1st line direction)",usage:"join [tolerance_meters]",isInteractive:!1,schema:{type:"object",properties:{toleranceMeters:{type:"number",minimum:0,description:"Join line ends closer than this (meters)"}}},args:{positional:["toleranceMeters"]},async execute(tt,et){const H=La(t,i).filter(Ct=>Ct.feature.geometry.type==="LineString"||Ct.feature.geometry.type==="MultiLineString");if(H.length<2)throw new Error("Join requires 2 selected LineString features.");const nt=H[0],ot=H[1];un(et,nt.layerId,t.getActiveLayerId());const ut=Vt(tt).toleranceMeters??20,rt=i.joinLines(nt.layerId,nt.feature.id,ot.feature.id,ut);if(!rt)throw new Error(`Failed to join lines [${nt.feature.id}] and [${ot.feature.id}]. Endpoints may exceed tolerance (${ut}m).`);return i.flashFeatures(rt),et.print(`Joined lines [${nt.feature.id}] and [${ot.feature.id}] into single line preserving direction of [${nt.feature.id}].`,"success"),tt.payload=rt,tt}},$={name:"select_box",aliases:["sbox","box_select"],description:"Activate box selection mode (click 2 corners or drag marquee)",usage:"select_box",isInteractive:!1,schema:{type:"object",properties:{}},async execute(tt,et){return i.setMode("select-box"),et.print("Box Selection Mode active. Click 2 corners or drag to select features.","system"),tt.payload={mode:"select-box"},tt}},z={name:"select_poly",aliases:["spoly","poly_select"],description:"Activate polygon boundary selection mode",usage:"select_poly",isInteractive:!1,schema:{type:"object",properties:{}},async execute(tt,et){return i.setMode("select-polygon"),et.print("Polygon Selection Mode active. Click boundary vertices and finish with double-click or Enter.","system"),tt.payload={mode:"select-polygon"},tt}},D={name:"select_all",aliases:["selall"],description:"Select all features on active layer or across all visible layers",usage:"select_all [layer_id]",isInteractive:!1,schema:{type:"object",properties:{layerId:{type:"string",description:"Layer to select in (default: active layer)"}}},args:{positional:["layerId"]},async execute(tt,et){const it=String(Vt(tt).layerId??"").trim();let H=0;if(it){const nt=t.getLayer(it);if(!nt)throw new Error(`Layer "${it}" not found.`);const ot=nt.getFeatures().map(ut=>ut.id).filter(ut=>ut!==void 0);t.selectFeatures(nt.id,ot,!0),H=ot.length,et.print(`Selected all ${H} features in layer "${nt.name}".`,"success")}else{const nt=t.getAllLayers().filter(ot=>ot.visible);for(const ot of nt){const ut=ot.getFeatures().map(rt=>rt.id).filter(rt=>rt!==void 0);t.selectFeatures(ot.id,ut,!0),H+=ut.length}et.print(`Selected all ${H} features across visible layers.`,"success")}return tt.payload={count:H},tt}},B={name:"deselect_all",aliases:["desel","clear_selection"],description:"Clear all selected features",usage:"deselect_all",isInteractive:!1,schema:{type:"object",properties:{}},async execute(tt,et){return t.clearSelection(),i.grips.clear(),et.print("Cleared all selections.","system"),tt.payload={cleared:!0},tt}},U={name:"trim",aliases:["tr"],description:"Trim lines at their intersections with other features: click the part of a line to remove",usage:'trim (click line parts to remove, Enter to finish) | trim {"picks":[[lng,lat], ...]}',isInteractive:!0,schema:{type:"object",properties:{picks:{type:"array",items:{type:"array",items:{type:"number"}},description:"Points on the line parts to remove"}},required:["picks"]},async execute(tt,et){const it=await lt(tt,et,"Select part of a line to trim [Enter to finish]:",H=>{const nt=i.trimLineAt(H);return nt?(et.print(nt.pieces.length===0?`Removed line [${nt.featureId}] (it lay between cutting edges).`:`Trimmed line [${nt.featureId}] into ${nt.pieces.length} piece(s).`,"success"),i.flashFeatures(nt.pieces),nt):"No line with a cutting edge under the pick point."});return tt.payload=it,tt}},j={name:"extend",aliases:["ex"],description:"Extend the end of a line nearest the click to the nearest boundary feature",usage:'extend (click near line ends, Enter to finish) | extend {"picks":[[lng,lat], ...]}',isInteractive:!0,schema:{type:"object",properties:{picks:{type:"array",items:{type:"array",items:{type:"number"}},description:"Points near the line ends to extend"}},required:["picks"]},async execute(tt,et){const it=await lt(tt,et,"Select a line near the end to extend [Enter to finish]:",H=>{const nt=i.extendLineAt(H);return nt?(et.print(`Extended line [${nt.feature.id}].`,"success"),i.flashFeatures(nt.feature),nt):"No line under the pick point, or no boundary in the extension direction."});return tt.payload=it,tt}},K={name:"stretch",aliases:["s"],description:"Move only the vertices inside a crossing window (selected features only when a selection exists)",usage:"stretch (pick window corners, base point, second point)",isInteractive:!0,schema:{type:"object",properties:{}},async execute(tt,et){const it=Th(t,i),H=await Ze(et,"Specify first corner of crossing window:"),nt=await Ze(et,"Specify opposite corner:",H),ot=await Ze(et,"Specify base point:"),ut=await Ze(et,"Specify second point or @dx,dy:",ot),rt=i.stretch(H,nt,ot,ut,it.length>0?it:void 0);if(rt.features.length===0)throw new Error("No vertices inside the window.");return i.flashFeatures(rt.features),et.print(`Stretched ${rt.movedVertices} vertex(es) in ${rt.features.length} feature(s)${it.length>0?" (selection only)":""}.`,"success"),tt.payload=rt,tt}},W={name:"arrayrect",aliases:["array","ar"],description:"Copy selected features in a grid of rows (along UCS Y) and columns (along UCS X) with spacing in meters",usage:'arrayrect | arrayrect {"rows":3,"columns":4,"rowSpacing":20,"columnSpacing":30}',isInteractive:!0,schema:{type:"object",properties:{rows:{type:"number",description:"Number of rows (>= 1)"},columns:{type:"number",description:"Number of columns (>= 1)"},rowSpacing:{type:"number",description:"Distance between rows in meters (negative = opposite direction)"},columnSpacing:{type:"number",description:"Distance between columns in meters (negative = opposite direction)"}},required:["rows","columns","rowSpacing","columnSpacing"]},async execute(tt,et){const it=wt(t,i,"array"),H=Vt(tt),nt=H.rows!==void 0||H.columns!==void 0,ot=nt?Number(H.rows??1):await ft(et,"Number of rows <1>:",1),ut=nt?Number(H.columns??1):await ft(et,"Number of columns <1>:",1),rt=nt?Number(H.rowSpacing??0):ot>1?await ft(et,"Row spacing (meters):"):0,Ct=nt?Number(H.columnSpacing??0):ut>1?await ft(et,"Column spacing (meters):"):0;if(!Number.isInteger(ot)||!Number.isInteger(ut)||ot<1||ut<1)throw new Error("Rows and columns must be whole numbers >= 1.");if(ot*ut<2)throw new Error("The array needs at least 2 items.");const kt=V(it),At=i.inputFrame,he=[];return t.runTransaction(`Array ${ot}x${ut}`,()=>{for(let Ae=0;Ae<ot;Ae++)for(let Cn=0;Cn<ut;Cn++){if(Ae===0&&Cn===0)continue;const Bt=ct(kt,Cn*Ct,Ae*rt,At);he.push(...i.transformFeatures(it,"Array item",Pl=>ue.translateByVector(Pl,kt,Bt),!0))}}),et.print(`Created ${he.length} feature(s) in a ${ot} x ${ut} array.`,"success"),tt.payload=he,tt}},J={name:"arraypolar",aliases:["ap"],description:"Copy selected features around a center point (count items over a fill angle)",usage:'arraypolar | arraypolar {"center":[lng,lat],"count":6,"fillAngle":360,"rotateItems":true}',isInteractive:!0,schema:{type:"object",properties:{center:{type:"array",items:{type:"number"},description:"Center point [lng, lat]"},count:{type:"number",description:"Total number of items including the original (>= 2)"},fillAngle:{type:"number",description:"Angle to fill in degrees (default 360); sign follows the angle convention"},rotateItems:{type:"boolean",description:"Rotate items as they are copied (default true)"}},required:["center","count"]},async execute(tt,et){const it=wt(t,i,"array"),H=Vt(tt),nt=i.inputFrame;let ot,ut,rt,Ct;if(H&&Array.isArray(H.center))ot=[Number(H.center[0]),Number(H.center[1])],ut=Number(H.count),rt=H.fillAngle!==void 0?Number(H.fillAngle):360,Ct=H.rotateItems!==void 0?!!H.rotateItems:!0;else{ot=await Ze(et,"Specify center point of array:"),ut=await ft(et,"Number of items (including original):"),rt=await ft(et,"Angle to fill <360>:",360);const Cn=(await et.requestInput("Rotate items as copied? [Yes/No] <Y>:")).trim().toLowerCase();Ct=!(Cn==="n"||Cn==="no")}if(!Number.isInteger(ut)||ut<2)throw new Error("Number of items must be a whole number >= 2.");if(rt===0||Math.abs(rt)>360)throw new Error("Fill angle must be between -360 and 360 (not 0).");const kt=Math.abs(Math.abs(rt)-360)<1e-9,At=rt/(kt?ut:ut-1),he=V(it),Ae=[];return t.runTransaction(`Polar array of ${ut}`,()=>{for(let Cn=1;Cn<ut;Cn++){const Bt=-(am(At*Cn,nt)*180)/Math.PI,Pl=Ct?kl=>ue.rotate(kl,Bt,ot):kl=>{const Tl=ue.rotate(St(he),Bt,ot).geometry.coordinates;return ue.translateByVector(kl,he,Tl)};Ae.push(...i.transformFeatures(it,"Polar array item",Pl,!0))}}),et.print(`Created ${Ae.length} feature(s) in a polar array of ${ut}.`,"success"),tt.payload=Ae,tt}};async function lt(tt,et,it,H){const nt=[],ot=Vt(tt);if(ot&&Array.isArray(ot.picks)){for(const ut of ot.picks){const rt=H([Number(ut[0]),Number(ut[1])]);if(typeof rt=="string")throw new Error(rt);nt.push(rt)}return nt}for(;;){const ut=await et.requestPoint(it);if(!ut)break;const rt=H(ut);typeof rt=="string"?et.print(rt,"error"):nt.push(rt)}return nt}async function ft(tt,et,it){for(;;){const H=(await tt.requestInput(et)).trim();if(!H&&it!==void 0)return it;const nt=us(H);if(nt!==null)return nt;if(!H)throw new Error("Command cancelled.");tt.print(`Invalid number "${H}".`,"error")}}function ct(tt,et,it,H){const nt=H.ucsRotationDeg*Math.PI/180,ot=et*Math.cos(nt)-it*Math.sin(nt),ut=et*Math.sin(nt)+it*Math.cos(nt),rt=Math.hypot(ot,ut);return rt===0?tt:Hs(tt,rt,Math.atan2(ut,ot))}async function gt(tt,et){const it=a==="through"?"Through":`${a}`;let H=null;for(;H===null;){const ot=await Nr(et,`Specify offset distance or [Through] <${it}>:`);if("point"in ot){const ut=await Ze(et,"Specify second point:",ot.point);H=Qe(ot.point,ut).distance}else if(!ot.text)H=a;else if(ot.text.toLowerCase().startsWith("t"))H="through";else{const ut=us(ot.text);ut!==null&&ut>0?H=ut:et.print(`Invalid offset distance "${ot.text}".`,"error")}}a=H;const nt=[];for(;;){const ot=await et.requestPoint("Select line or polygon to offset [Enter to finish]:");if(!ot)break;const ut=await Ze(et,H==="through"?"Specify through point:":"Specify point on side to offset:");try{const{result:rt,source:Ct}=i.offsetAt(ot,ut,H);i.flashFeatures(rt),nt.push(rt),et.print(`Offset [${Ct.id}] -> new feature [${rt.id}].`,"success")}catch(rt){et.print(rt.message,"error")}}return tt.payload=nt,tt}const bt={name:"break",aliases:["br"],description:"Remove the part of a line between two clicked points (click the same point twice to split there)",usage:'break (click first and second break points on a line) | break {"first":[lng,lat],"second":[lng,lat]}',isInteractive:!0,schema:{type:"object",properties:{first:{type:"array",items:{type:"number"},description:"First break point on the line [lng, lat]"},second:{type:"array",items:{type:"number"},description:"Second break point [lng, lat]; same as first to split"}},required:["first","second"]},async execute(tt,et){const it=Vt(tt),H=it!=null&&it.first?[Number(it.first[0]),Number(it.first[1])]:await Ze(et,"Select line at first break point:"),nt=it!=null&&it.second?[Number(it.second[0]),Number(it.second[1])]:await et.requestPoint("Specify second break point [Enter = break at first point]:")??H,ot=i.breakLineAt(H,nt);if(!ot)throw new Error("No line under the first break point.");return i.flashFeatures(ot.pieces),et.print(`Broke line [${ot.featureId}] into ${ot.pieces.length} piece(s).`,"success"),tt.payload=ot,tt}};let It={mode:"delta",value:1};const Q={name:"lengthen",aliases:["len"],description:"Change a line length at the clicked end: Delta meters (negative shortens), Total length, or Percent",usage:'lengthen (DE / T / P then click line ends) | lengthen {"mode":"total","value":120,"picks":[[lng,lat]]}',isInteractive:!0,schema:{type:"object",properties:{mode:{type:"string",enum:["delta","total","percent"],description:"How value is applied"},value:{type:"number",description:"Meters for delta/total, percent for percent"},picks:{type:"array",items:{type:"array",items:{type:"number"}},description:"Points near the line ends to change"}},required:["mode","value","picks"]},async execute(tt,et){const it=Vt(tt);if(it.mode!==void 0||it.value!==void 0){if(!["delta","total","percent"].includes(it.mode))throw new Error("mode must be delta, total or percent.");It={mode:it.mode,value:Number(it.value)}}else{const ut={delta:"DElta",total:"Total",percent:"Percent"}[It.mode],rt=(await et.requestInput(`Specify mode [DElta/Total/Percent] <${ut} ${It.value}>:`)).trim().toLowerCase();if(rt){const Ct=rt.startsWith("t")?"total":rt.startsWith("p")?"percent":rt.startsWith("de")?"delta":null;if(!Ct)throw new Error("Choose DE (delta), T (total) or P (percent).");It={mode:Ct,value:await ft(et,`Enter ${Ct} value (${Ct==="percent"?"percent":"meters"}):`)}}}const{mode:H,value:nt}=It,ot=await lt(tt,et,"Select a line near the end to change [Enter to finish]:",ut=>{try{const rt=i.lengthenLineAt(ut,H,nt);return rt?(i.flashFeatures(rt),et.print(`Line [${rt.id}] is now ${Yw(rt.geometry.coordinates).toFixed(3)} m long.`,"success"),rt):"No line under the pick point."}catch(rt){return rt.message}});return tt.payload=ot,tt}},jt={name:"align",aliases:["al"],description:"Move and rotate selected features so source points land on destination points (optionally scale to fit)",usage:"align (source 1, destination 1, source 2, destination 2, scale?)",isInteractive:!0,schema:{type:"object",properties:{source1:{type:"array",items:{type:"number"}},destination1:{type:"array",items:{type:"number"}},source2:{type:"array",items:{type:"number"}},destination2:{type:"array",items:{type:"number"}},scale:{type:"boolean",description:"Scale so the source distance matches the destination distance"}},required:["source1","destination1"]},async execute(tt,et){const it=wt(t,i,"align"),H=Vt(tt),nt=he=>Array.isArray(he)?[Number(he[0]),Number(he[1])]:null;let ot,ut,rt,Ct,kt;if(H.source1!==void 0){if(ot=nt(H.source1),ut=nt(H.destination1),rt=nt(H.source2),Ct=nt(H.destination2),kt=!!H.scale,!ot||!ut)throw new Error("source1 and destination1 are required.")}else if(ot=await Ze(et,"Specify first source point:"),ut=await Ze(et,"Specify first destination point:",ot),rt=await et.requestPoint("Specify second source point [Enter = move only]:"),Ct=rt?await Ze(et,"Specify second destination point:",ut):null,kt=!1,rt&&Ct){const he=(await et.requestInput("Scale objects based on alignment points? [Yes/No] <N>:")).trim().toLowerCase();kt=he==="y"||he==="yes"}const At=i.transformFeatures(it,`Align ${it.length} feature(s)`,he=>ue.align(he,ot,ut,rt,Ct,kt));return i.flashFeatures(At),et.print(`Aligned ${Ln(it)}${kt?" with scaling":""}.`,"success"),tt.payload=At.length===1?At[0]:At,tt}},Dt={name:"otrack",aliases:["tracking"],description:"Toggle object snap tracking: hover a snap point to acquire it, then follow alignment lines from it (AutoCAD F11)",usage:"otrack [on|off]",isInteractive:!1,schema:{type:"object",properties:{state:{type:"string",enum:["on","off"],description:"Leave empty to toggle"}}},args:{positional:["state"]},async execute(tt,et){const it=String(Vt(tt).state??"").trim().toLowerCase(),H=it==="on"?!0:it==="off"?!1:!i.objectTracking.enabled;return i.setObjectTracking({enabled:H}),et.print(`OTRACK is now ${H?"ON (hover a snap point to acquire it)":"OFF"}`,"success"),tt.payload={enabled:H},tt}};function wt(tt,et,it){const H=Th(tt,et);if(H.length===0)throw new Error(`Please select feature(s) on the map to ${it}.`);return H}function V(tt){if(tt.length===0)throw new Error("Nothing selected.");const et=De(ae(tt.map(it=>it.feature)));return[(et[0]+et[2])/2,(et[1]+et[3])/2]}function Xt(tt,et){const it=Vt(tt)[et];return it===void 0?"":String(it)}async function Ut(tt,et){for(;;){const it=await Nr(tt,et);if("point"in it){const nt=await Ze(tt,"Specify second point:",it.point);return Qe(it.point,nt).distance}const H=us(it.text);if(H!==null)return H;tt.print(`Invalid length "${it.text}".`,"error")}}async function Gt(tt,et,it,H,nt){for(;;){const ot=await Nr(tt,et,it);if("point"in ot)return wn(Qe(it,ot.point,H).angle);if(ot.text.toLowerCase().startsWith("r")){const rt=await dn(tt,"Specify reference angle or pick 2 points:",H);return await dn(tt,"Specify new angle or pick a point:",H,it)-rt}const ut=us(ot.text);if(ut!==null)return ut;tt.print(`Invalid angle "${ot.text}".`,"error")}}async function dn(tt,et,it,H){for(;;){const nt=await Nr(tt,et,H);if("point"in nt){const ut=H??nt.point,rt=H?nt.point:await Ze(tt,"Specify second point:",nt.point);return Qe(ut,rt,it).angle}const ot=us(nt.text);if(ot!==null)return ot;tt.print(`Invalid angle "${nt.text}".`,"error")}}function wn(tt,et){return tt>180?tt-360:tt}function Ln(tt){return tt.length===1?`feature [${tt[0].featureId}]`:`${tt.length} features`}function Et(tt,et){return`${Number(tt.toFixed(4))}° (${et})`}return[{name:"guides",aliases:["guide"],description:"Show or hide the drawing guides: crosshair across the map and measurements on the drawing",usage:"guides [on|off] [--crosshair on|off] [--dimensions on|off] [--segments on|off] [--area on|off] [--angles on|off] [--anchor cursor|vertex]",isInteractive:!1,schema:{type:"object",properties:{state:{type:"string",enum:["on","off"],description:"Switch every guide at once; leave empty to report"},crosshair:{type:"string",enum:["on","off"],description:"Dashed lines across the whole map"},dimensions:{type:"string",enum:["on","off"],description:"Lengths written on the drawing"},segments:{type:"string",enum:["on","off"],description:"Label the segments already drawn, not only the live one"},area:{type:"string",enum:["on","off"],description:"Area of the polygon being drawn"},anchor:{type:"string",enum:["cursor","vertex"],description:"What the crosshair follows"},angles:{type:"string",enum:["on","off"],description:"Arc and degrees at each corner (always the angle of 180° or less)"}}},args:{positional:["state"]},async execute(tt,et){const it=Vt(tt),H=rt=>rt===void 0?void 0:String(rt).toLowerCase()==="on",nt={};if(it.state!==void 0){const rt=H(it.state);Object.assign(nt,{crosshair:rt,dimensions:rt,segmentLabels:rt,areaLabel:rt,angles:rt})}it.crosshair!==void 0&&(nt.crosshair=H(it.crosshair)),it.dimensions!==void 0&&(nt.dimensions=H(it.dimensions)),it.segments!==void 0&&(nt.segmentLabels=H(it.segments)),it.area!==void 0&&(nt.areaLabel=H(it.area)),it.anchor!==void 0&&(nt.anchor=it.anchor),it.angles!==void 0&&(nt.angles=H(it.angles));const ot=Object.keys(nt).length>0?i.setGuides(nt):i.getGuides(),ut=rt=>rt?"on":"off";return et.print(`Guides — crosshair ${ut(ot.crosshair)} (${ot.anchor}) · dimensions ${ut(ot.dimensions)} · segments ${ut(ot.segmentLabels)} · area ${ut(ot.areaLabel)} · angles ${ut(ot.angles)}`,"success"),tt.payload=ot,tt}},e,n,s,r,o,d,U,j,bt,Q,jt,Dt,K,W,J,l,h,f,p,y,_,E,L,P,N,S,C,T,I,M,R,A,F,$,z,D,B]}function Eb(i,t){return[{name:"buffer",aliases:["b","buf"],description:"Create a buffer around the selected feature",usage:"buffer 10 meters",isInteractive:!1,schema:{type:"object",properties:{distance:{type:"number",description:"Buffer distance"},units:{type:"string",enum:["meters","kilometers"],default:"meters"}},required:["distance"]},args:{positional:["distance","units"]},async execute(a,l){const h=Vt(a);let f=Number(h.distance);const d=h.units??"meters";if(!Number.isFinite(f)){const w=await l.requestInput("Enter buffer distance in meters (e.g. 10):");if(f=parseFloat(w),!Number.isFinite(f))throw new Error("Invalid buffer distance")}const p=Fs(i,t);if(!p)throw new Error("Please select a feature on the map to buffer");const{layerId:y,featureId:_}=p;un(l,y,i.getActiveLayerId());const E=i.buffer(y,_,f,d);return E&&t.flashFeatures(E),l.print(`Buffered feature [${_}] in layer "${y}" by ${f} ${d}.`,"success"),a.payload=E,a}},{name:"area",aliases:["measure_area"],description:"Calculate area of selected polygon in Rai and Sqm",isInteractive:!1,schema:{type:"object",properties:{}},async execute(a,l){const h=Fs(i,t);if(!h)throw new Error("Please select a polygon feature to calculate area");const{layerId:f,featureId:d}=h;un(l,f,i.getActiveLayerId());const p=i.calculateArea(f,d,"rai"),y=i.calculateArea(f,d,"sqm");return l.print(`Feature [${d}] (Layer: "${f}") Area: ${p.toFixed(2)} ไร่ (${y.toLocaleString()} ตร.ม.)`,"success"),a.payload={areaRai:p,areaM2:y},a}},{name:"union",aliases:["merge"],description:"Merge 2 or more selected polygons into one (vertices closer than the snap tolerance are joined)",usage:"union [snap_tolerance_meters]",isInteractive:!1,schema:{type:"object",properties:{snapToleranceMeters:{type:"number",minimum:0,description:"Join vertices of different polygons closer than this distance in meters (default 0.001)"}}},args:{positional:["snapToleranceMeters"]},async execute(a,l){const h=Vt(a).snapToleranceMeters,f=qa(i,t);if(!f||f.featureIds.length<2)throw new Error("Union requires at least 2 selected polygons");const{layerId:d,featureIds:p}=f;un(l,d,i.getActiveLayerId());const y=i.union(d,p,{snapToleranceMeters:h});return y&&t.flashFeatures(y),l.print(`Unioned ${p.length} polygons in layer "${d}" into feature ${y.id}.`,"success"),y.geometry.type==="MultiPolygon"&&l.print(`Result has ${y.geometry.coordinates.length} separate parts. If they should touch, retry with a larger snap tolerance, e.g. 'union 0.2'.`,"prompt"),a.payload=y,a}},{name:"undo",aliases:["u"],description:"Undo last action",isInteractive:!1,schema:{type:"object",properties:{}},async execute(a,l){if(!i.canUndo())return l.print("Nothing to undo.","output"),a;const h=i.undo();return l.print(`Undid: ${h}`,"success"),a}},{name:"redo",aliases:["r"],description:"Redo previously undone action",isInteractive:!1,schema:{type:"object",properties:{}},async execute(a,l){if(!i.canRedo())return l.print("Nothing to redo.","output"),a;const h=i.redo();return l.print(`Redid: ${h}`,"success"),a}}]}function wb(i,t,e,n){return[{name:"print",aliases:["mapexport","exportmap"],description:"Save the current map view as an image with a scale bar, north arrow and title",usage:'print [--width 1600] [--title "แผนที่แปลง"] [--name farm-map] [--jpeg] [--no-scale] [--no-north] [--attribution "© OSM"]',isInteractive:!1,schema:{type:"object",properties:{width:{type:"number",minimum:1,description:"Image width in pixels (default: the map size)"},height:{type:"number",minimum:1},title:{type:"string"},name:{type:"string",description:"File name without extension"},scaleBar:{type:"boolean",default:!0},northArrow:{type:"boolean",default:!0},attribution:{type:"string"},mimeType:{type:"string",enum:["image/png","image/jpeg"]}}},args:{switches:{"no-scale":{property:"scaleBar",value:!1},"no-north":{property:"northArrow",value:!1},jpeg:{property:"mimeType",value:"image/jpeg"}}},async execute(h,f){const d={...Vt(h)},p=cb(i,d);return hb(p),f.print(`Saved ${p.filename} (${p.width} × ${p.height} px)${p.scaleBar?` · scale bar ${p.scaleBar.label}`:""}.`,"success"),h.payload={filename:p.filename,width:p.width,height:p.height,scaleBar:p.scaleBar},h}},{name:"zoom",aliases:["z","extent"],description:"Zoom to layer extent or entire map bounds",usage:"zoom [layerId]",isInteractive:!1,schema:{type:"object",properties:{layerId:{type:"string",description:"Optional layer id to zoom to"}}},args:{positional:["layerId"]},async execute(h,f){const d=Vt(h).layerId||t.getActiveLayerId()||void 0,p=t.getBoundingBox(d);return p[0]===0&&p[2]===0?(f.print("No features to zoom to.","output"),h):(i.fitBounds(p,40),f.print(`Zoomed to ${d?`layer "${d}"`:"all features"}.`,"success"),h)}},{name:"thematic",aliases:["classify","style_theme"],description:"Apply thematic classification to layer by attribute field",usage:"thematic <layerId> <field> [quantile|equal_interval|natural_breaks] [classes] [palette]",isInteractive:!1,schema:{type:"object",properties:{layerId:{type:"string",description:"Target layer id"},field:{type:"string",description:"Attribute field name"},method:{type:"string",enum:["quantile","equal_interval","natural_breaks","categorical"],default:"quantile"},classes:{type:"number",default:5},palette:{type:"string",default:"viridis"}},required:["layerId","field"]},args:{positional:["layerId","field","method","classes","palette"]},async execute(h,f){const d=Vt(h);let p=d.layerId||t.getActiveLayerId(),y=d.field;const _=d.method??"quantile",E=Number(d.classes??5),w=d.palette??"viridis";if(p||(p=await f.requestInput("Enter layer ID:")),!y){const L=t.getLayer(p),b=L?L.getPropertyFields().map(P=>P.name).join(", "):"";y=await f.requestInput(`Enter field name (${b}):`)}return _==="categorical"?e.setThematicCategorical(p,y,w):e.setThematicGraduated(p,y,_,E,w),f.print(`Applied ${_} classification on "${p}.${y}" (${E} classes, ${w}).`,"success"),h}},{name:"help",aliases:["?","commands"],description:"Display list of available commands and usage",isInteractive:!1,schema:{type:"object",properties:{command:{type:"string",description:"Show the parameters of one command"}}},args:{positional:["command"]},async execute(h,f){var y;const d=(y=Vt(h).command)==null?void 0:y.trim();if(d){const _=n.get(d);if(!_){const E=Uo(d,n.getNames());throw new Error(`No command called "${d}"${E?`. Did you mean "${E}"?`:""}`)}return Ju(_).forEach(E=>f.print(E,"output")),h.payload=_.name,h}const p=n.getAll();return f.print("=== OFSObject Command Center === (help <command> shows its parameters)","system"),p.forEach(_=>{const E=_.aliases.length>0?` [${_.aliases.join(", ")}]`:"";f.print(`${_.name}${E} - ${_.description}`,"output"),_.usage&&f.print(` Usage: ${_.usage}`,"output")}),h}},{name:"clear",aliases:["cls"],description:"Clear the terminal output",isInteractive:!1,schema:{type:"object",properties:{}},async execute(h,f){return f.clear(),h}}]}const sv={quantile:"quantile",equal_count:"quantile",equal:"equal_interval",equal_interval:"equal_interval",jenks:"natural_breaks",natural:"natural_breaks",natural_breaks:"natural_breaks",pretty:"pretty_breaks",pretty_breaks:"pretty_breaks"},xb=["center","left","right","top","bottom","top-left","top-right","bottom-left","bottom-right"];function Ca(i,t){if(typeof i!="string"||!ee.valid(i))throw new Error(`--${t} needs a color, e.g. #22c55e (got "${i}")`);return i}function xi(i,t,e=-1/0,n=1/0){const s=i===!0||Array.isArray(i)?NaN:Number(i);if(!Number.isFinite(s)||s<e||s>n)throw new Error(`--${t} needs a number${Number.isFinite(e)?` from ${e}`:""}${Number.isFinite(n)?` to ${n}`:""} (got "${i}")`);return s}function rv(i,t){return typeof i=="string"&&i.endsWith("%")?xi(i.slice(0,-1),t,0,100)/100:xi(i,t,0,1)}function Eu(i,t){if(i===!0||i==="none")return[];const e=Array.isArray(i)?i:String(i).split(",").map(n=>Number(n.trim()));if(e.some(n=>!Number.isFinite(n)||n<0))throw new Error(`--${t} needs comma-separated numbers, e.g. 6,3 (got "${i}")`);return e}function ov(i,t){if(i===!0||i==="true"||i==="on"||i==="yes")return!0;if(i===!1||i==="false"||i==="off"||i==="no")return!1;throw new Error(`--${t} needs true or false (got "${i}")`)}function ga(i,t,e){if(typeof i!="string"||!e.includes(i))throw new Error(`--${t} must be one of: ${e.join(", ")}`);return i}function bb(i,t){const e={},n={},s={};let r=null;const o=()=>r??(r={});for(const[l,h]of i)switch(l){case"color":e.color=n.color=s.color=Ca(h,l);break;case"opacity":e.opacity=n.opacity=s.opacity=rv(h,l);break;case"outline":e.outlineColor=Ca(h,l);break;case"outline-width":e.outlineWidth=xi(h,l,0,50);break;case"outline-opacity":e.outlineOpacity=rv(h,l);break;case"outline-dash":e.outlineDash=Eu(h,l);break;case"width":n.width=xi(h,l,0,100);break;case"dash":n.dash=Eu(h,l);break;case"cap":n.cap=ga(h,l,["butt","round","square"]);break;case"join":n.join=ga(h,l,["bevel","round","miter"]);break;case"offset":n.offset=xi(h,l,-100,100);break;case"fill":{const f=ga(h,l,["solid","none","lines","cross","dots"]);f==="solid"||f==="none"?e.style=f:(e.style="pattern",o().kind=f);break}case"angle":o().angleDeg=xi(h,l,-360,360);break;case"spacing":o().spacing=xi(h,l,1,200);break;case"hatch-width":o().lineWidth=xi(h,l,.1,50);break;case"hatch-dash":o().dash=Eu(h,l);break;case"hatch-color":o().color=Ca(h,l);break;case"background":e.patternBackground=ov(h,l);break;case"shape":s.shape=ga(h,l,[...Vu,"icon"]);break;case"icon":if(typeof h!="string")throw new Error("--icon needs a registered icon name");s.shape="icon",s.icon=h;break;case"size":s.size=xi(h,l,0,200);break;case"stroke":s.strokeColor=Ca(h,l);break;case"stroke-width":s.strokeWidth=xi(h,l,0,20);break;case"rotation":s.rotationDeg=xi(h,l,-360,360);break;case"anchor":s.anchor=ga(h,l,xb);break;case"allow-overlap":s.allowOverlap=ov(h,l);break;case"ramp":case"reverse":case"method":case"classes":case"mode":case"sizes":break;default:throw new Error(`Unknown option --${l}`)}if(r){const l=r,h=t.pattern??{...Da,color:e.color??t.color};e.pattern={...h,...l}}else e.color&&t.pattern&&(e.pattern={...t.pattern,color:e.color});const a={};return Object.keys(e).length&&(a.fill=e),Object.keys(n).length&&(a.line=n),Object.keys(s).length&&(a.marker=s),a}function Ah(i,t){var s,r,o,a,l,h;const e=[];if(i.type==="simple")e.push(`Single symbol on "${t.id}".`);else if(i.type==="categorical")e.push(`Categorized "${i.fieldName}" on "${t.id}": ${((s=i.categories)==null?void 0:s.length)??0} classes (${i.paletteName??"custom"}).`),(r=i.categories)==null||r.forEach((f,d)=>e.push(` ${d}. ${f.visible===!1?"[off] ":""}${f.label} ${f.color}`));else{const f=i.graduatedMode==="size"?", by size":"";e.push(`Graduated "${i.fieldName}" on "${t.id}": ${((o=i.breaks)==null?void 0:o.length)??0} classes (${i.classificationMethod}, ${i.paletteName??"custom"}${f}).`),(a=i.breaks)==null||a.forEach((d,p)=>e.push(` ${p}. ${d.visible===!1?"[off] ":""}${d.label} ${d.color}`))}const n=Fo(i);if(t.type==="polygon"){const f=n.fill,d=f.style==="pattern"&&f.pattern?` ${f.pattern.kind} ${f.pattern.angleDeg}°/${f.pattern.spacing}px`:"";e.push(` symbol: fill ${f.style}${d}, opacity ${f.opacity}, outline ${f.outlineColor} ${f.outlineWidth}px${(l=f.outlineDash)!=null&&l.length?` dash ${f.outlineDash.join(",")}`:""}`)}else if(t.type==="line"){const f=n.line;e.push(` symbol: line ${f.width}px, opacity ${f.opacity}${(h=f.dash)!=null&&h.length?`, dash ${f.dash.join(",")}`:""}`)}else{const f=n.marker;e.push(` symbol: ${f.shape}${f.icon?` (${f.icon})`:""} ${f.size}px, stroke ${f.strokeColor} ${f.strokeWidth}px`)}return e}function Ib(i,t){const e=()=>t.getThematicEngine();function n(d){const p=d??i.getActiveLayerId();if(!p)throw new Error("No layer given and no active layer.");const y=i.getLayer(p);if(!y)throw new Error(`Layer "${p}" not found.`);return y}function s(d,p,y){const _=d.getPropertyFields(),E=y?_.filter(L=>L.type==="number"):_;if(!p)throw new Error(`Field name required. Available: ${E.map(L=>L.name).join(", ")||"(none)"}`);const w=_.find(L=>L.name===p);if(!w)throw new Error(`Field "${p}" not found on "${d.id}". Available: ${E.map(L=>L.name).join(", ")}`);if(y&&w.type!=="number")throw new Error(`Field "${p}" is not numeric; use categorized.`);return p}function r(d,p){if(d===void 0)return p;if(typeof d!="string"||!ju(d))throw new Error(`Unknown color ramp "${d}". Try: symbology ramps`);return ju(d).name}function o(d){if(d===void 0)return"quantile";const p=typeof d=="string"?sv[d.toLowerCase()]:void 0;if(!p)throw new Error(`Unknown method "${d}". Use quantile, equal, jenks or pretty.`);return p}function a(d,p){const y=Fo(e().getEffectiveTheme(d.id)),_=bb(p,y.fill);Object.keys(_).length>0&&e().updateBaseSymbol(d.id,_)}function l(d,p,y,_){var b,P;const E=e().getEffectiveTheme(d.id),w=E.type==="graduated"?((b=E.breaks)==null?void 0:b.length)??0:E.type==="categorical"?((P=E.categories)==null?void 0:P.length)??0:0;if(w===0)throw new Error(`Layer "${d.id}" has no classes (single symbol).`);if(y==="on"||y==="off"){const N=y==="on";if(p==="all")return t.setAllClassesVisible(d.id,N);if(p==="other")return t.setClassVisible(d.id,-1,N)}const L=Number(p);if(!Number.isInteger(L)||L<0||L>=w)throw new Error(`Class must be 0-${w-1}, all or other (got "${p}").`);switch(y){case"on":case"off":return t.setClassVisible(d.id,L,y==="on");case"color":return t.updateClass(d.id,L,{color:Ca(_??!0,"color")});case"label":if(!_)throw new Error("Label text required.");return t.updateClass(d.id,L,{label:_});case"size":return t.updateClass(d.id,L,{size:xi(_??!0,"size",0,200)});default:throw new Error("Use: class <n|all|other> on|off, or class <n> color|label|size <value>")}}function h(d,p){var w,L,b,P,N,S;if(d.theme){const C=d.theme,T=n(C.layerId??d.layerId);e().setTheme({...C,layerId:T.id}),Ah(e().getEffectiveTheme(T.id),T).forEach(I=>p.print(I,"output"));return}const y=n(d.layerId),_=d.renderer??d.type,E=d.ramp??d.palette;if(_==="single"||_==="simple")t.setThematicSimple(y.id,d.color??((L=(w=d.symbol)==null?void 0:w.fill)==null?void 0:L.color)??((P=(b=d.symbol)==null?void 0:b.line)==null?void 0:P.color)??((S=(N=d.symbol)==null?void 0:N.marker)==null?void 0:S.color)??"#3b82f6");else if(_==="categorized"||_==="categorical")t.setThematicCategorical(y.id,s(y,d.field,!1),r(E,"category10"),{reverse:!!d.reverse});else if(_==="graduated"){const C=s(y,d.field,!0);Array.isArray(d.breaks)?(t.setThematicGraduated(y.id,C,"quantile",d.breaks.length,r(E,"viridis"),{reverse:!!d.reverse}),e().setManualBreaks(y,d.breaks.map(Number))):t.setThematicGraduated(y.id,C,o(d.method),d.classes??5,r(E,"viridis"),{reverse:!!d.reverse,mode:d.mode==="size"?"size":"color",sizeRange:Array.isArray(d.sizeRange)?[Number(d.sizeRange[0]),Number(d.sizeRange[1])]:void 0})}else if(_!==void 0)throw new Error(`Unknown renderer "${_}". Use single, categorized or graduated.`);d.symbol&&e().updateBaseSymbol(y.id,d.symbol),d.classVisibility&&typeof d.classVisibility=="object"&&Object.entries(d.classVisibility).forEach(([C,T])=>{t.setClassVisible(y.id,C==="other"?-1:Number(C),!!T)}),Ah(e().getEffectiveTheme(y.id),y).forEach(C=>p.print(C,"output"))}const f={name:"symbology",aliases:["sym","style"],description:"Layer symbology (QGIS style): single, categorized, graduated, patterns, markers, class visibility",usage:"symbology [layer] single|categorized <field>|graduated <field> [--method jenks --classes 5 --ramp YlGn --mode size] [--color --opacity --outline --dash --fill lines --angle 45 --shape star --size 14] | class <n|all|other> on|off | ramps",isInteractive:!1,schema:{type:"object",properties:{layerId:{type:"string",description:"Target layer id (defaults to the active layer)"},renderer:{type:"string",enum:["single","categorized","graduated"]},field:{type:"string",description:"Attribute field for categorized / graduated"},method:{type:"string",enum:Object.keys(sv),description:"quantile · equal · jenks (natural breaks) · pretty"},classes:{type:"number",default:5},ramp:{type:"string",description:'Color ramp name, e.g. YlGn, Viridis, Set2, RdYlGn (see "symbology ramps")'},reverse:{type:"boolean"},mode:{type:"string",enum:["color","size"],description:"Graduated: vary color or size"},sizeRange:{type:"array",items:{type:"number"},description:"Graduated size range [min, max] in px"},breaks:{type:"array",items:{type:"number"},description:"Manual class upper bounds"},symbol:{type:"object",description:'Base symbol patch: {fill:{color,opacity,style:"solid"|"pattern"|"none",pattern:{kind:"lines"|"cross"|"dots",color,spacing,angleDeg,lineWidth,dash},outlineColor,outlineWidth,outlineDash}, line:{color,width,opacity,dash,cap,join,offset}, marker:{shape,icon,size,color,opacity,strokeColor,strokeWidth,rotationDeg,anchor,allowOverlap}}'},classVisibility:{type:"object",description:'Map of class index (or "other") to visible true/false'},theme:{type:"object",description:"A complete thematic definition to set as it is"},words:{type:"array",items:{type:"string"},description:'The command as typed, e.g. "plots graduated ndvi" or "class 2 off" (the fields above are the JSON form)'},color:{type:"string",description:"Fill / line / marker color"},opacity:{description:"0-1, or a percentage such as 60%"},outline:{type:"string",description:"Polygon outline color"},outlineWidth:{type:"number"},outlineOpacity:{description:"0-1, or a percentage"},outlineDash:{type:"array",items:{type:"number"},description:'e.g. 4,2 · "none" for a solid line'},width:{type:"number",description:"Line width in px"},dash:{type:"array",items:{type:"number"}},cap:{type:"string",enum:["butt","round","square"]},join:{type:"string",enum:["bevel","round","miter"]},offset:{type:"number",description:"Line offset in px"},fill:{type:"string",enum:["solid","none","lines","cross","dots"]},angle:{type:"number",description:"Hatch angle in degrees"},spacing:{type:"number",description:"Hatch spacing in px"},hatchWidth:{type:"number"},hatchDash:{type:"array",items:{type:"number"}},hatchColor:{type:"string"},background:{type:"boolean",description:"Draw the fill color behind the hatch"},shape:{type:"string",enum:[...Vu,"icon"]},icon:{type:"string",description:'Registered icon name (see "symbology shapes")'},size:{type:"number",description:"Marker size in px"},stroke:{type:"string",description:"Marker outline color"},strokeWidth:{type:"number"},rotation:{type:"number"},anchor:{type:"string",enum:xb},allowOverlap:{type:"boolean"}}},args:{positional:["words"],rest:"words",aliases:{sizes:"sizeRange",palette:"ramp"}},async execute(d,p){const y=Vt(d),_=[...y.words??[]];if(_.length===0&&(y.theme||y.renderer||y.symbol||y.classVisibility||y.breaks))return h(y,p),d;const E=["words","layerId","renderer","field","symbol","classVisibility","theme","breaks","ramp","reverse","method","classes","mode","sizeRange"],w=new Map;for(const[S,C]of Object.entries(y))C===void 0||E.includes(S)||w.set(mn(S),C);const L=["single","simple","categorized","categorical","graduated","breaks","class","reclassify","show","ramps","shapes"];if(_[0]==="ramps"){const S=_[1];return["sequential","diverging","qualitative"].filter(C=>!S||C===S).forEach(C=>p.print(`${C}: ${$p(C).map(T=>T.name).join(", ")}`,"output")),d}if(_[0]==="shapes"){p.print(`shapes: ${Vu.join(", ")}`,"output");const S=Xp();return p.print(`icons: ${S.length?S.join(", "):"(none registered)"}`,"output"),d}let b=y.layerId;!b&&_.length>0&&!L.includes(_[0])&&(b=_.shift());const P=n(b),N=_.shift()??y.renderer??(w.size>0?"symbol":"show");switch(N){case"single":case"simple":{const S=Fo(e().getEffectiveTheme(P.id)),C=w.has("color")?Ca(w.get("color"),"color"):S.fill.color;t.setThematicSimple(P.id,C),a(P,w);break}case"categorized":case"categorical":t.setThematicCategorical(P.id,s(P,_[0]??y.field,!1),r(y.ramp,"category10"),{reverse:!!y.reverse}),a(P,w);break;case"graduated":{const S=y.sizeRange!==void 0?Eu(y.sizeRange,"sizes"):void 0;if(S&&S.length!==2)throw new Error("--sizes needs two numbers, e.g. 2,12");const C=y.mode!==void 0?ga(y.mode,"mode",["color","size"]):"color";if(C==="size"&&P.type==="polygon")throw new Error("Graduated size applies to line and point layers.");t.setThematicGraduated(P.id,s(P,_[0]??y.field,!0),o(y.method),y.classes!==void 0?xi(y.classes,"classes",1,32):5,r(y.ramp,"viridis"),{reverse:!!y.reverse,mode:C,sizeRange:S}),a(P,w);break}case"breaks":{const S=_[0]??y.breaks;if(!S)throw new Error("Give class upper bounds, e.g. symbology breaks 10,20,50");e().setManualBreaks(P,Eu(S,"breaks"));break}case"class":l(P,_[0]??"",_[1]??"",_.slice(2).join(" ")||void 0);break;case"reclassify":t.reclassify(P.id);break;case"symbol":a(P,w);break;case"show":break;default:throw new Error(`Unknown symbology action "${N}". Usage: ${f.usage}`)}return Ah(e().getEffectiveTheme(P.id),P).forEach(S=>p.print(S,"output")),d}};return[f]}function av(i){return Array.isArray(i)&&i.length>=2&&i.every(t=>typeof t=="number"&&Number.isFinite(t))}function n0(i){return i==="Point"||i==="MultiPoint"?"point":i==="LineString"||i==="MultiLineString"?"line":i==="Polygon"||i==="MultiPolygon"?"polygon":null}function vm(i,t,e,n={}){const s=(d,p,y)=>e.push({severity:d,code:p,message:y,file:n.file,featureIndex:t});if(!i)return s("warning","null-geometry",`Feature ${t} has no geometry and was skipped.`),null;if(!n0(i.type))return s("error","unsupported-geometry",`Feature ${t}: geometry type "${i.type}" is not supported.`),null;const o=i.coordinates,a=(d,p,y)=>{if(!Array.isArray(d)||!d.every(av))return s("error","invalid-coordinates",`Feature ${t}: ${y} has invalid coordinates.`),!1;if(d.length<p)return s("error","too-few-points",`Feature ${t}: ${y} has ${d.length} points (needs ${p}).`),!1;if(n.geographic&&d.some(([_,E])=>_<-180||_>180||E<-90||E>90))return s("error","out-of-range",`Feature ${t}: ${y} has coordinates outside longitude/latitude range. Is the source CRS correct?`),!1;for(let _=1;_<d.length;_++)if(d[_][0]===d[_-1][0]&&d[_][1]===d[_-1][1]){s("warning","duplicate-point",`Feature ${t}: ${y} has repeated consecutive points.`);break}return!0},l=(d,p)=>{if(!a(d,3,p))return null;const y=d,_=y[0],E=y[y.length-1];return _[0]!==E[0]||_[1]!==E[1]?n.closeRings?(s("warning","ring-closed",`Feature ${t}: ${p} was not closed; closing point added.`),[...y,[_[0],_[1]]]):(s("error","unclosed-ring",`Feature ${t}: ${p} is not closed (first and last points differ).`),null):y.length<4?(s("error","too-few-points",`Feature ${t}: ${p} needs at least 4 positions including the closing point.`),null):y},h=(d,p)=>{if(!Array.isArray(d)||d.length===0)return s("error","invalid-coordinates",`Feature ${t}: ${p} has no rings.`),null;const y=[];for(let _=0;_<d.length;_++){const E=l(d[_],`${p} ring ${_}`);if(!E)return null;y.push(E)}return y};let f=null;switch(i.type){case"Point":return av(o)?n.geographic&&(o[0]<-180||o[0]>180||o[1]<-90||o[1]>90)?(s("error","out-of-range",`Feature ${t}: point is outside longitude/latitude range. Is the source CRS correct?`),null):i:(s("error","invalid-coordinates",`Feature ${t}: point has invalid coordinates.`),null);case"MultiPoint":return a(o,1,"multipoint")?i:null;case"LineString":return a(o,2,"line")?i:null;case"MultiLineString":return!Array.isArray(o)||o.length===0?(s("error","invalid-coordinates",`Feature ${t}: multiline has no parts.`),null):o.every((d,p)=>a(d,2,`line part ${p}`))?i:null;case"Polygon":{const d=h(o,"polygon");f=d?{type:"Polygon",coordinates:d}:null;break}case"MultiPolygon":{if(!Array.isArray(o)||o.length===0)return s("error","invalid-coordinates",`Feature ${t}: multipolygon has no parts.`),null;const d=[];for(let p=0;p<o.length;p++){const y=h(o[p],`polygon part ${p}`);if(!y)return null;d.push(y)}f={type:"MultiPolygon",coordinates:d};break}}if(f)try{const d=cw({type:"Feature",properties:{},geometry:f});d.features.length>0&&s("warning","self-intersection",`Feature ${t}: polygon boundary crosses itself (${d.features.length} point(s)).`)}catch{}return f}const fl="204.4798,837.894,294.7765,0,0,0,0",lv="+a=6377276.345 +rf=300.8017",h8="+a=6377276.345",Sb={indian_1975:fl},wc=new Map;function ma(i){wc.set(i.code.toUpperCase(),i)}function f8(){ma({code:"EPSG:4326",name:"WGS 84",definition:"+proj=longlat +datum=WGS84 +no_defs",aliases:["GCS_WGS_1984","WGS 84","WGS84","CRS84","OGC:CRS84","URN:OGC:DEF:CRS:OGC:1.3:CRS84"]}),ma({code:"EPSG:3857",name:"WGS 84 / Pseudo-Mercator",definition:"+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs",aliases:["WGS_1984_Web_Mercator_Auxiliary_Sphere","WGS 84 / Pseudo-Mercator","EPSG:900913"]});for(const i of[46,47,48])ma({code:`EPSG:326${i}`,name:`WGS 84 / UTM zone ${i}N`,definition:`+proj=utm +zone=${i} +datum=WGS84 +units=m +no_defs`,aliases:[`WGS_1984_UTM_Zone_${i}N`,`WGS 84 / UTM zone ${i}N`]});for(const i of[47,48])ma({code:`EPSG:240${i}`,name:`Indian 1975 / UTM zone ${i}N`,definition:`+proj=utm +zone=${i} ${lv} +towgs84=${fl} +units=m +no_defs`,aliases:[`Indian_1975_UTM_Zone_${i}N`,`Indian 1975 / UTM zone ${i}N`]});ma({code:"EPSG:4240",name:"Indian 1975",definition:`+proj=longlat ${lv} +towgs84=${fl} +no_defs`,aliases:["GCS_Indian_1975","Indian 1975"]})}f8();function d8(i,t,e=i,n=[]){Hr.Proj(t),ma({code:i.toUpperCase(),name:e,definition:t,aliases:n})}function g8(i,t){if(t.split(",").map(Number).some(e=>!Number.isFinite(e)))throw new Error(`Invalid towgs84: ${t}`);if(Sb[i.toLowerCase()]=t,i.toLowerCase()==="indian_1975")for(const e of wc.values())e.definition.includes(h8)&&(e.definition=e.definition.replace(/\+towgs84=[^ ]+/,`+towgs84=${t}`))}function m8(){return Array.from(wc.values()).map(i=>({code:i.code,name:i.name}))}function hh(i){return i.toLowerCase().replace(/[^a-z0-9]/g,"")}function Mb(i){const t=hh(i);for(const e of wc.values())if(hh(e.code)===t||hh(e.name)===t||e.aliases.some(n=>hh(n)===t))return e}function Nb(i){try{const t=Hr.Proj(i);return t.projName==="longlat"||t.projName==="identity"}catch{return!1}}function Sf(i,t=[]){return{code:i.code,name:i.name,definition:i.definition,isGeographic:Nb(i.definition),warnings:t}}function fi(i){const t=String(i).trim();if(!t)throw new Error("Empty CRS");const e=t.match(/^(?:EPSG:{1,2}|urn:ogc:def:crs:EPSG:[^:]*:)?(\d{4,5})$/i);if(e){const s=`EPSG:${e[1]}`,r=wc.get(s);if(r)return Sf(r);const o=e[1].match(/^32([67])(\d{2})$/);if(o&&Number(o[2])>=1&&Number(o[2])<=60)return{code:s,name:`WGS 84 / UTM zone ${Number(o[2])}${o[1]==="6"?"N":"S"}`,definition:`+proj=utm +zone=${Number(o[2])} ${o[1]==="7"?"+south ":""}+datum=WGS84 +units=m +no_defs`,isGeographic:!1,warnings:[]};throw new Error(`CRS ${s} is not registered. Register it with registerCrs("${s}", "<proj4 definition>").`)}const n=Mb(t);if(n)return Sf(n);if(t.startsWith("+")){try{Hr.Proj(t)}catch(s){throw new Error(`Invalid proj4 definition: ${s.message}`)}return{code:"CUSTOM",name:t,definition:t,isGeographic:Nb(t),warnings:[]}}throw new Error(`Unknown CRS "${t}"`)}function i0(i){var d,p,y,_,E;const t=i.trim();if(!t)throw new Error("Empty .prj");const e=t.match(/AUTHORITY\[\s*"EPSG"\s*,\s*"?(\d+)"?\s*\]\s*\]\s*$/i)??t.match(/ID\[\s*"EPSG"\s*,\s*(\d+)\s*\]\s*\]\s*$/i);if(e)try{return fi(`EPSG:${e[1]}`)}catch{}const n=(d=t.match(/^\s*(?:PROJCS|GEOGCS|PROJCRS|GEOGCRS)\[\s*"([^"]+)"/i))==null?void 0:d[1],s=/TOWGS84\s*\[/i.test(t);if(n){const w=Mb(n),L=(p=t.match(/TOWGS84\s*\[([^\]]*)\]/i))==null?void 0:p[1],b=(y=w==null?void 0:w.definition.match(/\+towgs84=([^ ]+)/))==null?void 0:y[1];if(w&&s&&b&&((N,S)=>{const C=(N??"").split(",").map(Number),T=(S??"").split(",").map(Number);for(;C.length<7;)C.push(0);for(;T.length<7;)T.push(0);return C.every((I,M)=>Math.abs(I-T[M])<1e-9)})(L,b))return Sf(w);if(w&&!(s&&w.definition.includes("+towgs84"))){const N=(_=w.definition.match(/\+towgs84=([^ ]+)/))==null?void 0:_[1],S=N?[`"${n}" has no datum shift in the .prj; applied default +towgs84=${N}.`]:[];return Sf(w,S)}}let r;try{r=Hr.Proj(t)}catch(w){throw new Error(`Unusable .prj file: ${w.message}`)}const o=[],a=s,l=String(r.datumCode??"").toLowerCase(),h=!l||["wgs84","wgs_1984","d_wgs_1984","none"].includes(l)||((E=r.datum)==null?void 0:E.datum_type)===4;let f=t;if(!a&&!h){const w=Sb[l];if(!w)throw new Error(`The .prj uses datum "${r.datumCode}" without datum shift parameters. Register the CRS with registerCrs() (including +towgs84) or choose the source CRS explicitly.`);f=p8(r,w),o.push(`Datum "${r.datumCode}" has no shift in the .prj; applied default +towgs84=${w}.`)}return{code:"CUSTOM",name:n??"Custom CRS",definition:f,isGeographic:r.projName==="longlat",warnings:o}}function p8(i,t){const e=o=>o*180/Math.PI,n=`+a=${i.a} ${i.rf?`+rf=${i.rf}`:`+b=${i.b}`}`,s=`+towgs84=${t}`,r=String(i.projName).toLowerCase();if(r==="longlat")return`+proj=longlat ${n} ${s} +no_defs`;if(r==="transverse_mercator"||r==="tmerc"||r==="utm")return`+proj=tmerc +lat_0=${e(i.lat0??0)} +lon_0=${e(i.long0??0)} +k=${i.k0??1} +x_0=${i.x0??0} +y_0=${i.y0??0} ${n} ${s} +units=m +no_defs`;throw new Error(`Projection "${i.projName}" with datum "${i.datumCode}" needs an explicit CRS definition.`)}function Mf(i){var n;const t=i.code.match(/^EPSG:326(\d{2})$/);if(i.code==="EPSG:4326")return'GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]';if(t){const s=Number(t[1]);return`PROJCS["WGS_1984_UTM_Zone_${s}N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",${s*6-183}.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]`}const e=i.code.match(/^EPSG:240(\d{2})$/);if(e){const s=Number(e[1]),r=((n=i.definition.match(/\+towgs84=([^ ]+)/))==null?void 0:n[1])??fl;return`PROJCS["Indian_1975_UTM_Zone_${s}N",GEOGCS["GCS_Indian_1975",DATUM["D_Indian_1975",SPHEROID["Everest_Adjustment_1937",6377276.345,300.8017],TOWGS84[${r}]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",${s*6-183}.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]`}throw new Error(`No .prj writer for ${i.code}; export in EPSG:4326 or a WGS 84 / Indian 1975 UTM zone.`)}function Lb(i){var r;const e=`GEOGCS["Indian 1975 (project datum shift)",DATUM["Indian_1975_project_3_parameter",SPHEROID["Everest 1830 (1937 Adjustment)",6377276.345,300.8017],TOWGS84[${((r=i.definition.match(/\+towgs84=([^ ]+)/))==null?void 0:r[1])??fl}]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]]`;if(i.code==="EPSG:4240")return e;const n=i.code.match(/^EPSG:240(\d{2})$/);if(!n)throw new Error(`No OGC WKT writer for ${i.code}`);const s=Number(n[1]);return`PROJCS["Indian 1975 / UTM zone ${s}N",${e},PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",${s*6-183}],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1],AXIS["Easting",EAST],AXIS["Northing",NORTH]]`}function s0(i){return/^EPSG:(240\d{2}|4240)$/.test(i.code)}const Cb="+proj=longlat +datum=WGS84 +no_defs";function Pb(i,t){if(typeof i[0]=="number"){const e=t(i);return i.length>2?[e[0],e[1],...i.slice(2)]:[e[0],e[1]]}return i.map(e=>Pb(e,t))}function r0(i,t){return i.type==="GeometryCollection"?{...i,geometries:i.geometries.map(e=>r0(e,t))}:{...i,coordinates:Pb(i.coordinates,t)}}function kb(i,t){if(t.code==="EPSG:4326")return i;const e=Hr(t.definition,Cb);return r0(i,n=>e.forward([n[0],n[1]]))}function Tb(i,t){if(t.code==="EPSG:4326")return i;const e=Hr(Cb,t.definition);return r0(i,n=>e.forward([n[0],n[1]]))}function Rb(i,t){const e=Math.min(60,Math.max(1,Math.floor(((i+180)%360+360)%360/6)+1));return fi(`EPSG:${t>=0?326:327}${String(e).padStart(2,"0")}`)}function y8(i){const[t,e,n,s]=i;return t>=-180&&n<=180&&e>=-90&&s<=90}function Yr(i){return typeof i=="string"?new TextEncoder().encode(i):i instanceof Uint8Array?i:new Uint8Array(i)}function Qu(i,t="utf-8"){if(typeof i=="string")return i;const e=Yr(i),n=e[0]===239&&e[1]===187&&e[2]===191?3:0;return new TextDecoder(Do(t)).decode(e.subarray(n))}function dl(i){const t=i.split(/[\\/]/).pop()??i,e=t.lastIndexOf(".");return e>0?t.slice(0,e):t}function Em(i){const t=i.lastIndexOf(".");return t>=0?i.slice(t+1).toLowerCase():""}function Do(i){const t=i.trim().toLowerCase().replace(/[\s_]/g,"-");return["utf8","utf-8","65001"].includes(t)?"utf-8":["tis-620","tis620","windows-874","cp874","874","iso-8859-11","ansi-874","thai"].includes(t)?"windows-874":["windows-1252","cp1252","1252","latin1","iso-8859-1","ansi-1252"].includes(t)?"windows-1252":t}function _8(i){let t=1/0,e=1/0,n=-1/0,s=-1/0;const r=o=>{typeof(o==null?void 0:o[0])=="number"?Number.isFinite(o[0])&&Number.isFinite(o[1])&&(t=Math.min(t,o[0]),n=Math.max(n,o[0]),e=Math.min(e,o[1]),s=Math.max(s,o[1])):Array.isArray(o)&&o.forEach(r)};return i.forEach(o=>o.geometry&&r(o.geometry.coordinates)),Number.isFinite(t)?[t,e,n,s]:null}function xc(i,t,e,n,s){const r=i??(t?fi(t):null);if(r)return r.warnings.forEach(a=>s.push({severity:"warning",code:"crs",message:a,file:n})),r;const o=_8(e);return o&&(o[0]<-180||o[2]>180||o[1]<-90||o[3]>90)?(s.push({severity:"error",code:"unknown-crs",message:`Coordinates in ${n} look projected (e.g. ${o[0].toFixed(1)}, ${o[1].toFixed(1)}) but the file has no CRS. Import again with sourceCrs (e.g. "EPSG:32647").`,file:n}),null):fi("EPSG:4326")}function tc(i){const t=new Map;for(const e of i)for(const[n,s]of Object.entries(e.properties??{}))t.has(n)||t.set(n,new Set),s!=null&&t.get(n).add(typeof s=="number"?"number":typeof s=="boolean"?"boolean":"string");return Array.from(t.entries()).map(([e,n])=>({name:e,type:n.size===1?Array.from(n)[0]:"string"}))}function Sl(i,t,e,n,s,r={}){const o=new Map;i.forEach((l,h)=>{const f=vm(l.geometry,h,s,{file:n,closeRings:r.closeRings});if(!f)return;let d;try{d=kb(f,t)}catch(_){s.push({severity:"error",code:"crs-transform",message:`Feature ${h}: ${_.message}`,file:n,featureIndex:h});return}if(!vm(d,h,s,{file:n,geographic:!0,closeRings:!0}))return;const p=n0(d.type),y={type:"Feature",geometry:d,properties:{...l.properties}};l.id!==void 0&&l.id!==null&&l.id!==""&&(y.id=l.id),o.has(p)||o.set(p,[]),o.get(p).push(y)});const a=Array.from(o.keys());return a.map(l=>{const h=o.get(l);return{name:a.length>1?`${e} (${l}s)`:e,kind:l,features:h,fields:r.fields??tc(h),sourceCrs:t.code==="CUSTOM"?t.name:t.code,sourceFile:n}})}function bc(i,t,e){const n=Tb(i,t),s=Math.pow(10,e),r=o=>typeof o[0]=="number"?o.map(a=>Math.round(a*s)/s):o.map(r);return n.type==="GeometryCollection"?n:{...n,coordinates:r(n.coordinates)}}function Ic(i,t){return t??(i.isGeographic?8:3)}function Ab(i,t={}){var h,f;const e=[];let n;try{n=JSON.parse(Qu(i.data))}catch(d){return e.push({severity:"error",code:"parse",message:`${i.name} is not valid JSON: ${d.message}`,file:i.name}),{layers:[],issues:e}}const s=[],r=(d,p,y)=>{var _;if((d==null?void 0:d.type)==="GeometryCollection"){e.push({severity:"warning",code:"geometry-collection",message:`A GeometryCollection was split into ${((_=d.geometries)==null?void 0:_.length)??0} features.`,file:i.name}),(d.geometries??[]).forEach(E=>s.push({geometry:E,properties:{...p}}));return}s.push({geometry:d,properties:p,id:y})};if((n==null?void 0:n.type)==="FeatureCollection"&&Array.isArray(n.features))n.features.forEach((d,p)=>{if((d==null?void 0:d.type)!=="Feature"){e.push({severity:"error",code:"invalid-feature",message:`Item ${p} is not a Feature.`,file:i.name,featureIndex:p}),s.push({geometry:null,properties:{}});return}r(d.geometry,d.properties&&typeof d.properties=="object"?d.properties:{},d.id)});else if((n==null?void 0:n.type)==="Feature")r(n.geometry,n.properties??{},n.id);else if(typeof(n==null?void 0:n.type)=="string"&&("coordinates"in n||"geometries"in n))r(n,{});else return e.push({severity:"error",code:"not-geojson",message:`${i.name} is not a GeoJSON object.`,file:i.name}),{layers:[],issues:e};let o=null;const a=(f=(h=n==null?void 0:n.crs)==null?void 0:h.properties)==null?void 0:f.name;if(typeof a=="string")try{o=fi(a)}catch(d){return e.push({severity:"error",code:"unknown-crs",message:d.message,file:i.name}),{layers:[],issues:e}}const l=xc(o,t.sourceCrs,s,i.name,e);return l?{layers:Sl(s,l,dl(i.name),i.name,e,{closeRings:t.closeRings}),issues:e}:{layers:[],issues:e}}function Ob(i,t={}){const e=fi(t.crs??"EPSG:4326"),n=Ic(e,t.precision),s={type:"FeatureCollection",features:i.filter(r=>r.geometry).map(r=>{const o={type:"Feature",properties:{...r.properties??{}},geometry:bc(r.geometry,e,n)};return r.id!==void 0&&(o.id=r.id),o})};return e.code!=="EPSG:4326"&&(s.crs={type:"name",properties:{name:`urn:ogc:def:crs:${e.code.replace(":","::")}`}}),{filename:`${t.name??"export"}.geojson`,mimeType:"application/geo+json",data:JSON.stringify(s)}}var rn=Uint8Array,Li=Uint16Array,o0=Int32Array,md=new rn([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),pd=new rn([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),wm=new rn([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Fb=function(i,t){for(var e=new Li(31),n=0;n<31;++n)e[n]=t+=1<<i[n-1];for(var s=new o0(e[30]),n=1;n<30;++n)for(var r=e[n];r<e[n+1];++r)s[r]=r-e[n]<<5|n;return{b:e,r:s}},$b=Fb(md,2),Db=$b.b,xm=$b.r;Db[28]=258,xm[258]=28;var Gb=Fb(pd,0),v8=Gb.b,uv=Gb.r,bm=new Li(32768);for(var $e=0;$e<32768;++$e){var Mr=($e&43690)>>1|($e&21845)<<1;Mr=(Mr&52428)>>2|(Mr&13107)<<2,Mr=(Mr&61680)>>4|(Mr&3855)<<4,bm[$e]=((Mr&65280)>>8|(Mr&255)<<8)>>1}var Ks=(function(i,t,e){for(var n=i.length,s=0,r=new Li(t);s<n;++s)i[s]&&++r[i[s]-1];var o=new Li(t);for(s=1;s<t;++s)o[s]=o[s-1]+r[s-1]<<1;var a;if(e){a=new Li(1<<t);var l=15-t;for(s=0;s<n;++s)if(i[s])for(var h=s<<4|i[s],f=t-i[s],d=o[i[s]-1]++<<f,p=d|(1<<f)-1;d<=p;++d)a[bm[d]>>l]=h}else for(a=new Li(n),s=0;s<n;++s)i[s]&&(a[s]=bm[o[i[s]-1]++]>>15-i[s]);return a}),Xr=new rn(288);for(var $e=0;$e<144;++$e)Xr[$e]=8;for(var $e=144;$e<256;++$e)Xr[$e]=9;for(var $e=256;$e<280;++$e)Xr[$e]=7;for(var $e=280;$e<288;++$e)Xr[$e]=8;var ec=new rn(32);for(var $e=0;$e<32;++$e)ec[$e]=5;var E8=Ks(Xr,9,0),w8=Ks(Xr,9,1),x8=Ks(ec,5,0),b8=Ks(ec,5,1),Ig=function(i){for(var t=i[0],e=1;e<i.length;++e)i[e]>t&&(t=i[e]);return t},ls=function(i,t,e){var n=t/8|0;return(i[n]|i[n+1]<<8)>>(t&7)&e},Sg=function(i,t){var e=t/8|0;return(i[e]|i[e+1]<<8|i[e+2]<<16)>>(t&7)},a0=function(i){return(i+7)/8|0},Sc=function(i,t,e){return(t==null||t<0)&&(t=0),(e==null||e>i.length)&&(e=i.length),new rn(i.subarray(t,e))},I8=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],$n=function(i,t,e){var n=new Error(t||I8[i]);if(n.code=i,Error.captureStackTrace&&Error.captureStackTrace(n,$n),!e)throw n;return n},S8=function(i,t,e,n){var s=i.length,r=n?n.length:0;if(!s||t.f&&!t.l)return e||new rn(0);var o=!e,a=o||t.i!=2,l=t.i;o&&(e=new rn(s*3));var h=function(wt){var V=e.length;if(wt>V){var Xt=new rn(Math.max(V*2,wt));Xt.set(e),e=Xt}},f=t.f||0,d=t.p||0,p=t.b||0,y=t.l,_=t.d,E=t.m,w=t.n,L=s*8;do{if(!y){f=ls(i,d,1);var b=ls(i,d+1,3);if(d+=3,b)if(b==1)y=w8,_=b8,E=9,w=5;else if(b==2){var C=ls(i,d,31)+257,T=ls(i,d+10,15)+4,I=C+ls(i,d+5,31)+1;d+=14;for(var M=new rn(I),R=new rn(19),A=0;A<T;++A)R[wm[A]]=ls(i,d+A*3,7);d+=T*3;for(var F=Ig(R),$=(1<<F)-1,z=Ks(R,F,1),A=0;A<I;){var D=z[ls(i,d,$)];d+=D&15;var P=D>>4;if(P<16)M[A++]=P;else{var B=0,U=0;for(P==16?(U=3+ls(i,d,3),d+=2,B=M[A-1]):P==17?(U=3+ls(i,d,7),d+=3):P==18&&(U=11+ls(i,d,127),d+=7);U--;)M[A++]=B}}var j=M.subarray(0,C),K=M.subarray(C);E=Ig(j),w=Ig(K),y=Ks(j,E,1),_=Ks(K,w,1)}else $n(1);else{var P=a0(d)+4,N=i[P-4]|i[P-3]<<8,S=P+N;if(S>s){l&&$n(0);break}a&&h(p+N),e.set(i.subarray(P,S),p),t.b=p+=N,t.p=d=S*8,t.f=f;continue}if(d>L){l&&$n(0);break}}a&&h(p+131072);for(var W=(1<<E)-1,J=(1<<w)-1,lt=d;;lt=d){var B=y[Sg(i,d)&W],ft=B>>4;if(d+=B&15,d>L){l&&$n(0);break}if(B||$n(2),ft<256)e[p++]=ft;else if(ft==256){lt=d,y=null;break}else{var ct=ft-254;if(ft>264){var A=ft-257,gt=md[A];ct=ls(i,d,(1<<gt)-1)+Db[A],d+=gt}var bt=_[Sg(i,d)&J],It=bt>>4;bt||$n(3),d+=bt&15;var K=v8[It];if(It>3){var gt=pd[It];K+=Sg(i,d)&(1<<gt)-1,d+=gt}if(d>L){l&&$n(0);break}a&&h(p+131072);var Q=p+ct;if(p<K){var jt=r-K,Dt=Math.min(K,Q);for(jt+p<0&&$n(3);p<Dt;++p)e[p]=n[jt+p]}for(;p<Q;++p)e[p]=e[p-K]}}t.l=y,t.p=lt,t.b=p,t.f=f,y&&(f=1,t.m=E,t.d=_,t.n=w)}while(!f);return p!=e.length&&o?Sc(e,0,p):e.subarray(0,p)},or=function(i,t,e){e<<=t&7;var n=t/8|0;i[n]|=e,i[n+1]|=e>>8},Kl=function(i,t,e){e<<=t&7;var n=t/8|0;i[n]|=e,i[n+1]|=e>>8,i[n+2]|=e>>16},Mg=function(i,t){for(var e=[],n=0;n<i.length;++n)i[n]&&e.push({s:n,f:i[n]});var s=e.length,r=e.slice();if(!s)return{t:qb,l:0};if(s==1){var o=new rn(e[0].s+1);return o[e[0].s]=1,{t:o,l:1}}e.sort(function(S,C){return S.f-C.f}),e.push({s:-1,f:25001});var a=e[0],l=e[1],h=0,f=1,d=2;for(e[0]={s:-1,f:a.f+l.f,l:a,r:l};f!=s-1;)a=e[e[h].f<e[d].f?h++:d++],l=e[h!=f&&e[h].f<e[d].f?h++:d++],e[f++]={s:-1,f:a.f+l.f,l:a,r:l};for(var p=r[0].s,n=1;n<s;++n)r[n].s>p&&(p=r[n].s);var y=new Li(p+1),_=Im(e[f-1],y,0);if(_>t){var n=0,E=0,w=_-t,L=1<<w;for(r.sort(function(C,T){return y[T.s]-y[C.s]||C.f-T.f});n<s;++n){var b=r[n].s;if(y[b]>t)E+=L-(1<<_-y[b]),y[b]=t;else break}for(E>>=w;E>0;){var P=r[n].s;y[P]<t?E-=1<<t-y[P]++-1:++n}for(;n>=0&&E;--n){var N=r[n].s;y[N]==t&&(--y[N],++E)}_=t}return{t:new rn(y),l:_}},Im=function(i,t,e){return i.s==-1?Math.max(Im(i.l,t,e+1),Im(i.r,t,e+1)):t[i.s]=e},cv=function(i){for(var t=i.length;t&&!i[--t];);for(var e=new Li(++t),n=0,s=i[0],r=1,o=function(l){e[n++]=l},a=1;a<=t;++a)if(i[a]==s&&a!=t)++r;else{if(!s&&r>2){for(;r>138;r-=138)o(32754);r>2&&(o(r>10?r-11<<5|28690:r-3<<5|12305),r=0)}else if(r>3){for(o(s),--r;r>6;r-=6)o(8304);r>2&&(o(r-3<<5|8208),r=0)}for(;r--;)o(s);r=1,s=i[a]}return{c:e.subarray(0,n),n:t}},Zl=function(i,t){for(var e=0,n=0;n<t.length;++n)e+=i[n]*t[n];return e},Bb=function(i,t,e){var n=e.length,s=a0(t+2);i[s]=n&255,i[s+1]=n>>8,i[s+2]=i[s]^255,i[s+3]=i[s+1]^255;for(var r=0;r<n;++r)i[s+r+4]=e[r];return(s+4+n)*8},hv=function(i,t,e,n,s,r,o,a,l,h,f){or(t,f++,e),++s[256];for(var d=Mg(s,15),p=d.t,y=d.l,_=Mg(r,15),E=_.t,w=_.l,L=cv(p),b=L.c,P=L.n,N=cv(E),S=N.c,C=N.n,T=new Li(19),I=0;I<b.length;++I)++T[b[I]&31];for(var I=0;I<S.length;++I)++T[S[I]&31];for(var M=Mg(T,7),R=M.t,A=M.l,F=19;F>4&&!R[wm[F-1]];--F);var $=h+5<<3,z=Zl(s,Xr)+Zl(r,ec)+o,D=Zl(s,p)+Zl(r,E)+o+14+3*F+Zl(T,R)+2*T[16]+3*T[17]+7*T[18];if(l>=0&&$<=z&&$<=D)return Bb(t,f,i.subarray(l,l+h));var B,U,j,K;if(or(t,f,1+(D<z)),f+=2,D<z){B=Ks(p,y,0),U=p,j=Ks(E,w,0),K=E;var W=Ks(R,A,0);or(t,f,P-257),or(t,f+5,C-1),or(t,f+10,F-4),f+=14;for(var I=0;I<F;++I)or(t,f+3*I,R[wm[I]]);f+=3*F;for(var J=[b,S],lt=0;lt<2;++lt)for(var ft=J[lt],I=0;I<ft.length;++I){var ct=ft[I]&31;or(t,f,W[ct]),f+=R[ct],ct>15&&(or(t,f,ft[I]>>5&127),f+=ft[I]>>12)}}else B=E8,U=Xr,j=x8,K=ec;for(var I=0;I<a;++I){var gt=n[I];if(gt>255){var ct=gt>>18&31;Kl(t,f,B[ct+257]),f+=U[ct+257],ct>7&&(or(t,f,gt>>23&31),f+=md[ct]);var bt=gt&31;Kl(t,f,j[bt]),f+=K[bt],bt>3&&(Kl(t,f,gt>>5&8191),f+=pd[bt])}else Kl(t,f,B[gt]),f+=U[gt]}return Kl(t,f,B[256]),f+U[256]},M8=new o0([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),qb=new rn(0),N8=function(i,t,e,n,s,r){var o=r.z||i.length,a=new rn(n+o+5*(1+Math.ceil(o/7e3))+s),l=a.subarray(n,a.length-s),h=r.l,f=(r.r||0)&7;if(t){f&&(l[0]=r.r>>3);for(var d=M8[t-1],p=d>>13,y=d&8191,_=(1<<e)-1,E=r.p||new Li(32768),w=r.h||new Li(_+1),L=Math.ceil(e/3),b=2*L,P=function(Ut){return(i[Ut]^i[Ut+1]<<L^i[Ut+2]<<b)&_},N=new o0(25e3),S=new Li(288),C=new Li(32),T=0,I=0,M=r.i||0,R=0,A=r.w||0,F=0;M+2<o;++M){var $=P(M),z=M&32767,D=w[$];if(E[z]=D,w[$]=z,A<=M){var B=o-M;if((T>7e3||R>24576)&&(B>423||!h)){f=hv(i,l,0,N,S,C,I,R,F,M-F,f),R=T=I=0,F=M;for(var U=0;U<286;++U)S[U]=0;for(var U=0;U<30;++U)C[U]=0}var j=2,K=0,W=y,J=z-D&32767;if(B>2&&$==P(M-J))for(var lt=Math.min(p,B)-1,ft=Math.min(32767,M),ct=Math.min(258,B);J<=ft&&--W&&z!=D;){if(i[M+j]==i[M+j-J]){for(var gt=0;gt<ct&&i[M+gt]==i[M+gt-J];++gt);if(gt>j){if(j=gt,K=J,gt>lt)break;for(var bt=Math.min(J,gt-2),It=0,U=0;U<bt;++U){var Q=M-J+U&32767,jt=E[Q],Dt=Q-jt&32767;Dt>It&&(It=Dt,D=Q)}}}z=D,D=E[z],J+=z-D&32767}if(K){N[R++]=268435456|xm[j]<<18|uv[K];var wt=xm[j]&31,V=uv[K]&31;I+=md[wt]+pd[V],++S[257+wt],++C[V],A=M+j,++T}else N[R++]=i[M],++S[i[M]]}}for(M=Math.max(M,A);M<o;++M)N[R++]=i[M],++S[i[M]];f=hv(i,l,h,N,S,C,I,R,F,M-F,f),h||(r.r=f&7|l[f/8|0]<<3,f-=7,r.h=w,r.p=E,r.i=M,r.w=A)}else{for(var M=r.w||0;M<o+h;M+=65535){var Xt=M+65535;Xt>=o&&(l[f/8|0]=h,Xt=o),f=Bb(l,f+1,i.subarray(M,Xt))}r.i=o}return Sc(a,0,n+a0(f)+s)},L8=(function(){for(var i=new Int32Array(256),t=0;t<256;++t){for(var e=t,n=9;--n;)e=(e&1&&-306674912)^e>>>1;i[t]=e}return i})(),C8=function(){var i=-1;return{p:function(t){for(var e=i,n=0;n<t.length;++n)e=L8[e&255^t[n]]^e>>>8;i=e},d:function(){return~i}}},P8=function(i,t,e,n,s){if(!s&&(s={l:1},t.dictionary)){var r=t.dictionary.subarray(-32768),o=new rn(r.length+i.length);o.set(r),o.set(i,r.length),i=o,s.w=r.length}return N8(i,t.level==null?6:t.level,t.mem==null?s.l?Math.ceil(Math.max(8,Math.min(13,Math.log(i.length)))*1.5):20:12+t.mem,e,n,s)},zb=function(i,t){var e={};for(var n in i)e[n]=i[n];for(var n in t)e[n]=t[n];return e},Bs=function(i,t){return i[t]|i[t+1]<<8},Vi=function(i,t){return(i[t]|i[t+1]<<8|i[t+2]<<16|i[t+3]<<24)>>>0},Ng=function(i,t){return Vi(i,t)+Vi(i,t+4)*4294967296},In=function(i,t,e){for(;e;++t)i[t]=e,e>>>=8};function k8(i,t){return P8(i,t||{},0,0)}function T8(i,t){return S8(i,{i:2},t&&t.out,t&&t.dictionary)}var Ub=function(i,t,e,n){for(var s in i){var r=i[s],o=t+s,a=n;Array.isArray(r)&&(a=zb(n,r[1]),r=r[0]),ArrayBuffer.isView(r)?e[o]=[r,a]:(e[o+="/"]=[new rn(0),a],Ub(r,o,e,n))}},fv=typeof TextEncoder<"u"&&new TextEncoder,Sm=typeof TextDecoder<"u"&&new TextDecoder,R8=0;try{Sm.decode(qb,{stream:!0}),R8=1}catch{}var A8=function(i){for(var t="",e=0;;){var n=i[e++],s=(n>127)+(n>223)+(n>239);if(e+s>i.length)return{s:t,r:Sc(i,e-1)};s?s==3?(n=((n&15)<<18|(i[e++]&63)<<12|(i[e++]&63)<<6|i[e++]&63)-65536,t+=String.fromCharCode(55296|n>>10,56320|n&1023)):s&1?t+=String.fromCharCode((n&31)<<6|i[e++]&63):t+=String.fromCharCode((n&15)<<12|(i[e++]&63)<<6|i[e++]&63):t+=String.fromCharCode(n)}};function dv(i,t){var e;if(fv)return fv.encode(i);for(var n=i.length,s=new rn(i.length+(i.length>>1)),r=0,o=function(h){s[r++]=h},e=0;e<n;++e){if(r+5>s.length){var a=new rn(r+8+(n-e<<1));a.set(s),s=a}var l=i.charCodeAt(e);l<128||t?o(l):l<2048?(o(192|l>>6),o(128|l&63)):l>55295&&l<57344?(l=65536+(l&1047552)|i.charCodeAt(++e)&1023,o(240|l>>18),o(128|l>>12&63),o(128|l>>6&63),o(128|l&63)):(o(224|l>>12),o(128|l>>6&63),o(128|l&63))}return Sc(s,0,r)}function O8(i,t){if(t){for(var e="",n=0;n<i.length;n+=16384)e+=String.fromCharCode.apply(null,i.subarray(n,n+16384));return e}else{if(Sm)return Sm.decode(i);var s=A8(i),r=s.s,e=s.r;return e.length&&$n(8),r}}var F8=function(i,t){return t+30+Bs(i,t+26)+Bs(i,t+28)},$8=function(i,t,e){var n=Bs(i,t+28),s=Bs(i,t+30),r=O8(i.subarray(t+46,t+46+n),!(Bs(i,t+8)&2048)),o=t+46+n,a=D8(i,o,s,e,Vi(i,t+20),Vi(i,t+24),Vi(i,t+42)),l=a[0],h=a[1],f=a[2];return[Bs(i,t+10),l,h,r,o+s+Bs(i,t+32),f]},D8=function(i,t,e,n,s,r,o){var a=s==4294967295,l=r==4294967295,h=o==4294967295,f=t+e,d=a+l+h;if(n&&d){for(;t+4<f;t+=4+Bs(i,t+2))if(Bs(i,t)==1)return[a?Ng(i,t+4+8*l):s,l?Ng(i,t+4):r,h?Ng(i,t+4+8*(l+a)):o,1];n<2&&$n(13)}return[s,r,o,0]},Mm=function(i){var t=0;if(i)for(var e in i){var n=i[e].length;n>65535&&$n(9),t+=n+4}return t},gv=function(i,t,e,n,s,r,o,a){var l=n.length,h=e.extra,f=a&&a.length,d=Mm(h);In(i,t,o!=null?33639248:67324752),t+=4,o!=null&&(i[t++]=20,i[t++]=e.os),i[t]=20,t+=2,i[t++]=e.flag<<1|(r<0&&8),i[t++]=s&&8,i[t++]=e.compression&255,i[t++]=e.compression>>8;var p=new Date(e.mtime==null?Date.now():e.mtime),y=p.getFullYear()-1980;if((y<0||y>119)&&$n(10),In(i,t,y<<25|p.getMonth()+1<<21|p.getDate()<<16|p.getHours()<<11|p.getMinutes()<<5|p.getSeconds()>>1),t+=4,r!=-1&&(In(i,t,e.crc),In(i,t+4,r<0?-r-2:r),In(i,t+8,e.size)),In(i,t+12,l),In(i,t+14,d),t+=16,o!=null&&(In(i,t,f),In(i,t+6,e.attrs),In(i,t+10,o),t+=14),i.set(n,t),t+=l,d)for(var _ in h){var E=h[_],w=E.length;In(i,t,+_),In(i,t+2,w),i.set(E,t+4),t+=4+w}return f&&(i.set(a,t),t+=f),t},G8=function(i,t,e,n,s){In(i,t,101010256),In(i,t+8,e),In(i,t+10,e),In(i,t+12,n),In(i,t+16,s)};function Yb(i,t){t||(t={});var e={},n=[];Ub(i,"",e,t);var s=0,r=0;for(var o in e){var a=e[o],l=a[0],h=a[1],f=h.level==0?0:8,d=dv(o),p=d.length,y=h.comment,_=y&&dv(y),E=_&&_.length,w=Mm(h.extra);p>65535&&$n(11);var L=f?k8(l,h):l,b=L.length,P=C8();P.p(l),n.push(zb(h,{size:l.length,crc:P.d(),c:L,f:d,m:_,u:p!=o.length||_&&y.length!=E,o:s,compression:f})),s+=30+p+w+b,r+=76+2*(p+w)+(E||0)+b}for(var N=new rn(r+22),S=s,C=r-s,T=0;T<n.length;++T){var d=n[T];gv(N,d.o,d,d.f,d.u,d.c.length);var I=30+d.f.length+Mm(d.extra);N.set(d.c,d.o+I),gv(N,s,d,d.f,d.u,d.c.length,d.o,d.m),s+=16+I+(d.m?d.m.length:0)}return G8(N,s,n.length,C,S),N}function Xb(i,t){for(var e={},n=i.length-22;Vi(i,n)!=101010256;--n)(!n||i.length-n>65558)&&$n(13);var s=Bs(i,n+8);if(!s)return{};var r=Vi(i,n+16),o=Vi(i,n-20)==117853008;if(o){var a=Vi(i,n-12);o=Vi(i,a)==101075792,o&&(s=Vi(i,a+32),r=Vi(i,a+48))}for(var l=0;l<s;++l){var h=$8(i,r,o),f=h[0],d=h[1],p=h[2],y=h[3],_=h[4],E=h[5],w=F8(i,E);r=_,f?f==8?e[y]=T8(i.subarray(w,w+d),{out:new rn(p)}):$n(14,"unknown compression type "+f):e[y]=Sc(i,w,w+d)}return e}const mv={1:"ibm437",2:"ibm850",3:"windows-1252",87:"",124:"windows-874",240:"utf-8"};function Lg(i,t){return new TextDecoder(t).decode(i)}function B8(i){const t=new TextDecoder("utf-8",{fatal:!0});for(let e=0;e<=3&&e<i.length+1;e++)try{return t.decode(i.subarray(0,i.length-e)),!0}catch{}return!1}function l0(i){let t=0,e=0;for(const n of i)for(const s of n)s>=128&&(t++,s>=161&&s<=251&&e++);return t===0?{encoding:"utf-8",confidence:"ascii"}:i.every(n=>B8(n))?{encoding:"utf-8",confidence:"valid-utf8"}:e/t>=.9?{encoding:"windows-874",confidence:"thai-bytes"}:{encoding:"windows-1252",confidence:"guess"}}function pv(i){let t=i.length;for(;t>0&&(i[t-1]===32||i[t-1]===0);)t--;return i.subarray(0,t)}function jb(i,t={},e=[]){var L;const n=new DataView(i.buffer,i.byteOffset,i.byteLength);if(i.byteLength<32)throw new Error("DBF file is too short");const s=n.getUint32(4,!0),r=n.getUint16(8,!0),o=n.getUint16(10,!0),a=i[29],l=[];for(let b=32;b+32<=r&&i[b]!==13;b+=32){const P=i.subarray(b,b+11),N=P.indexOf(0),S=Lg(P.subarray(0,N>=0?N:11),"windows-1252").trim(),C=String.fromCharCode(i[b+11]).toUpperCase(),T=i[b+16],I=i[b+17],M=C==="L"?"boolean":C==="D"?"date":"NFIO".includes(C)?"number":"string";l.push({name:S,type:M,dbfType:C,length:T,decimals:I})}const h=[];let f=1;for(const b of l)h.push(f),f+=b.length;let d=t.encoding?Do(t.encoding):"";!d&&((L=t.cpg)!=null&&L.trim())&&(d=Do(t.cpg)),!d&&mv[a]&&(d=mv[a]);const p=Math.min(s,Math.floor((i.byteLength-r)/Math.max(o,1)));if(p<s&&e.push({severity:"warning",code:"dbf-truncated",message:`DBF declares ${s} records but contains ${p}.`,file:t.file}),!d){const b=[];for(let N=0;N<p&&b.length<5e3;N++){const S=r+N*o;l.forEach((C,T)=>{C.dbfType==="C"&&b.push(pv(i.subarray(S+h[T],S+h[T]+C.length)))})}const P=l0(b);d=P.encoding,(P.confidence==="thai-bytes"||P.confidence==="guess")&&e.push({severity:"warning",code:"encoding-detected",message:`No .cpg file: text encoding detected as ${d}${P.confidence==="guess"?" (uncertain)":""}. Import with encoding option if text looks wrong.`,file:t.file})}let y;try{y=new TextDecoder(d)}catch{e.push({severity:"warning",code:"encoding-unsupported",message:`Encoding "${d}" is not supported; using UTF-8.`,file:t.file}),d="utf-8",y=new TextDecoder("utf-8")}const _=[],E=[];let w=!1;for(let b=0;b<p;b++){const P=r+b*o;E.push(i[P]===42);const N={};l.forEach((S,C)=>{const T=i.subarray(P+h[C],P+h[C]+S.length);switch(S.dbfType){case"C":N[S.name]=y.decode(pv(T));break;case"N":case"F":{const I=Lg(T,"windows-1252").trim(),M=I===""||/^[*.]+$/.test(I)?null:Number(I);N[S.name]=M===null||Number.isNaN(M)?null:M;break}case"L":{const I=String.fromCharCode(T[0]).toUpperCase();N[S.name]="TY".includes(I)?!0:"FN".includes(I)?!1:null;break}case"D":{const I=Lg(T,"windows-1252").trim();N[S.name]=/^\d{8}$/.test(I)?`${I.slice(0,4)}-${I.slice(4,6)}-${I.slice(6,8)}`:null;break}case"I":N[S.name]=new DataView(T.buffer,T.byteOffset,4).getInt32(0,!0);break;case"O":N[S.name]=new DataView(T.buffer,T.byteOffset,8).getFloat64(0,!0);break;default:N[S.name]=null,w||(w=!0,e.push({severity:"warning",code:"dbf-field-type",message:`DBF field "${S.name}" of type ${S.dbfType} is not supported and was left empty.`,file:t.file}))}}),_.push(N)}return{fields:l,records:_,deleted:E,encoding:d}}function u0(i){const t=[];let e=!1;for(const n of i){const s=n.codePointAt(0);s<128?t.push(s):s>=3585&&s<=3675?t.push(s-3584+160):(t.push(63),e=!0)}return{bytes:Uint8Array.from(t),lossy:e}}function q8(i,t){if(i.length<=t)return i;let e=t;for(;e>0&&(i[e]&192)===128;)e--;return i.subarray(0,e)}function z8(i,t){let e=i.normalize("NFKD").replace(/[^\x21-\x7e]/g,"_").slice(0,10)||"FIELD",n=e;for(let s=1;t.has(n.toUpperCase());s++){const r=`_${s}`;n=e.slice(0,10-r.length)+r}return t.add(n.toUpperCase()),n}function yv(i){return Number.isInteger(i)?String(i):String(Number(i.toPrecision(15)))}function Vb(i,t,e="utf-8",n=[]){const s=Do(e)==="windows-874";if(!s&&Do(e)!=="utf-8")throw new Error(`DBF export supports utf-8 or tis-620, not "${e}"`);const r=new TextEncoder,o=w=>{if(!s)return r.encode(w);const{bytes:L,lossy:b}=u0(w);return b&&!a&&(a=!0,n.push({severity:"warning",code:"encoding-lossy",message:'Some characters cannot be written in TIS-620 and were replaced with "?". Export as UTF-8 to keep them.'})),L};let a=!1;const l=new Set,h=new Map,f=t.map(w=>{const L=z8(w.name,l);h.set(w.name,L),L!==w.name&&n.push({severity:"warning",code:"field-renamed",message:`Field "${w.name}" is written as "${L}" (DBF names are at most 10 ASCII characters).`});const b=i.map(T=>T[w.name]),P=b.filter(T=>T!=null);if(w.type==="boolean"&&P.every(T=>typeof T=="boolean"))return{field:w,dbfName:L,type:"L",length:1,decimals:0,cells:b.map(T=>T===!0?"T":T===!1?"F":"?")};if(w.type==="date"&&P.every(T=>typeof T=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(T)))return{field:w,dbfName:L,type:"D",length:8,decimals:0,cells:b.map(T=>T?String(T).replace(/-/g,""):"")};if(w.type==="number"&&P.every(T=>typeof T=="number"&&Number.isFinite(T))){const T=b.map(A=>typeof A=="number"?yv(A):""),I=Math.min(15,Math.max(0,...T.map(A=>A.includes(".")?A.split(".")[1].length:0))),M=b.map(A=>typeof A=="number"?I>0?A.toFixed(I):yv(A):""),R=Math.min(254,Math.max(1,...M.map(A=>A.length)));return{field:w,dbfName:L,type:"N",length:R,decimals:I,cells:M}}let N=!1;const S=b.map(T=>{if(T==null)return new Uint8Array(0);const I=typeof T=="object"?JSON.stringify(T):String(T),M=o(I),R=s?M.subarray(0,254):q8(M,254);return R.length<M.length&&(N=!0),R});N&&n.push({severity:"warning",code:"text-truncated",message:`Values of "${w.name}" longer than 254 bytes were truncated.`});const C=Math.min(254,Math.max(1,...S.map(T=>T.length)));return{field:w,dbfName:L,type:"C",length:C,decimals:0,cells:S}}),d=32+f.length*32+1,p=1+f.reduce((w,L)=>w+L.length,0),y=new Uint8Array(d+i.length*p+1),_=new DataView(y.buffer),E=new Date;return y[0]=3,y[1]=E.getFullYear()-1900,y[2]=E.getMonth()+1,y[3]=E.getDate(),_.setUint32(4,i.length,!0),_.setUint16(8,d,!0),_.setUint16(10,p,!0),y[29]=s?124:0,f.forEach((w,L)=>{const b=32+L*32;for(let P=0;P<w.dbfName.length;P++)y[b+P]=w.dbfName.charCodeAt(P);y[b+11]=w.type.charCodeAt(0),y[b+16]=w.length,y[b+17]=w.decimals}),y[d-1]=13,i.forEach((w,L)=>{let b=d+L*p;y[b++]=32,f.forEach(P=>{y.fill(32,b,b+P.length);const N=P.cells[L];if(N instanceof Uint8Array)y.set(N,b);else{const S=r.encode(N);y.set(S.subarray(0,P.length),P.type==="N"?b+P.length-Math.min(S.length,P.length):b)}b+=P.length})}),y[y.length-1]=26,{dbf:y,cpg:s?"874":"UTF-8",fieldNames:h}}const si={NULL:0,POINT:1,POLYLINE:3,POLYGON:5,MULTIPOINT:8};function Nm(i){let t=0;for(let e=0,n=i.length-1;e<i.length;n=e++)t+=(i[n][0]-i[e][0])*(i[n][1]+i[e][1]);return t/2}function wu(i){let t=1/0,e=1/0,n=-1/0,s=-1/0;for(const[r,o]of i)r<t&&(t=r),r>n&&(n=r),o<e&&(e=o),o>s&&(s=o);return[t,e,n,s]}function _v(i,t){let e=!1;for(let n=0,s=t.length-1;n<t.length;s=n++){const[r,o]=t[n],[a,l]=t[s];o>i[1]!=l>i[1]&&i[0]<(a-r)*(i[1]-o)/(l-o)+r&&(e=!e)}return e}function Hb(i,t,e,n){const s=[],r=[];for(const a of i){if(a.length===0)continue;const l=Nm(a);l<0?s.push({ring:a,area:-l,bbox:wu(a),holes:[]}):r.push(a)}for(const a of r){const[l,h,f,d]=wu(a),p=a[0];let y=null;for(const _ of s){const[E,w,L,b]=_.bbox;l<E||h<w||f>L||d>b||!_v(p,_.ring)&&!a.some(P=>_v(P,_.ring))||(!y||_.area<y.area)&&(y=_)}y?y.holes.push(a):(e.push({severity:"warning",code:"ring-orientation",message:`Feature ${t}: a counter-clockwise ring has no enclosing ring and was read as a separate polygon.`,file:n,featureIndex:t}),s.push({ring:[...a].reverse(),area:Math.abs(Nm(a)),bbox:wu(a),holes:[]}))}const o=s.map(a=>[[...a.ring].reverse(),...a.holes.map(l=>[...l].reverse())]);return o.length===0?null:o.length===1?{type:"Polygon",coordinates:o[0]}:{type:"MultiPolygon",coordinates:o}}function Wb(i,t=[],e){const n=new DataView(i.buffer,i.byteOffset,i.byteLength);if(i.byteLength<100||n.getInt32(0,!1)!==9994)throw new Error(`${e??".shp"} is not a shapefile`);const s=n.getInt32(32,!0),r=[];let o=100,a=!1;for(;o+8<=i.byteLength;){const l=n.getInt32(o+4,!1)*2,h=o+8;if(o=h+l,l<4||o>i.byteLength){o>i.byteLength&&t.push({severity:"warning",code:"shp-truncated",message:`${e}: last record is truncated.`,file:e});break}const f=r.length,d=n.getInt32(h,!0),p=d%10,y=d>10&&d<20;if(d===si.NULL){r.push({geometry:null,type:d});continue}if(d===31){a||t.push({severity:"error",code:"multipatch",message:`${e}: MultiPatch shapes are not supported.`,file:e}),a=!0,r.push({geometry:null,type:d});continue}if(p===si.POINT){const _=[n.getFloat64(h+4,!0),n.getFloat64(h+12,!0)];y&&_.push(n.getFloat64(h+20,!0)),r.push({geometry:{type:"Point",coordinates:_},type:d});continue}if(p===si.MULTIPOINT){const _=n.getInt32(h+36,!0),E=[];for(let w=0;w<_;w++)E.push([n.getFloat64(h+40+w*16,!0),n.getFloat64(h+48+w*16,!0)]);if(y){const w=h+40+_*16+16;E.forEach((L,b)=>L.push(n.getFloat64(w+b*8,!0)))}r.push({geometry:_===1?{type:"Point",coordinates:E[0]}:{type:"MultiPoint",coordinates:E},type:d});continue}if(p===si.POLYLINE||p===si.POLYGON){const _=n.getInt32(h+36,!0),E=n.getInt32(h+40,!0),w=h+44,L=w+_*4,b=[];for(let N=0;N<E;N++)b.push([n.getFloat64(L+N*16,!0),n.getFloat64(L+8+N*16,!0)]);if(y){const N=L+E*16+16;N+E*8<=h+l&&b.forEach((S,C)=>S.push(n.getFloat64(N+C*8,!0)))}const P=[];for(let N=0;N<_;N++){const S=n.getInt32(w+N*4,!0),C=N+1<_?n.getInt32(w+(N+1)*4,!0):E;P.push(b.slice(S,C))}p===si.POLYLINE?r.push({geometry:P.length===1?{type:"LineString",coordinates:P[0]}:{type:"MultiLineString",coordinates:P},type:d}):r.push({geometry:Hb(P,f,t,e),type:d});continue}t.push({severity:"error",code:"shape-type",message:`${e}: record ${f} has unsupported shape type ${d}.`,file:e,featureIndex:f}),r.push({geometry:null,type:d})}return{shapeType:s,records:r}}function Kb(i,t={}){var p;const e=[],n=`${i.name}.shp`;let s;try{s=Wb(i.shp,e,n)}catch(y){return e.push({severity:"error",code:"parse",message:y.message,file:n}),{layers:[],issues:e}}let r=null;if(i.dbf)try{r=jb(i.dbf,{encoding:t.encoding,cpg:i.cpg,file:`${i.name}.dbf`},e)}catch(y){e.push({severity:"error",code:"dbf",message:`${i.name}.dbf: ${y.message}`,file:n})}else e.push({severity:"warning",code:"no-dbf",message:`${i.name}: no .dbf file, features have no attributes.`,file:n});r&&r.records.length!==s.records.length&&e.push({severity:"warning",code:"record-count",message:`${i.name}: ${s.records.length} shapes but ${r.records.length} attribute records; attributes are matched by position.`,file:n});const o=[];let a=0;s.records.forEach((y,_)=>{if(r!=null&&r.deleted[_]){a++,o.push({geometry:null,properties:{}});return}o.push({geometry:y.geometry,properties:(r==null?void 0:r.records[_])??{}})}),a>0&&e.push({severity:"warning",code:"deleted-records",message:`${i.name}: ${a} records marked deleted in the .dbf were skipped.`,file:n});let l=null;if((p=i.prj)!=null&&p.trim())try{l=i0(i.prj)}catch(y){if(!t.sourceCrs)return e.push({severity:"error",code:"prj",message:`${i.name}.prj: ${y.message}`,file:n}),{layers:[],issues:e};e.push({severity:"warning",code:"prj",message:`${i.name}.prj could not be used (${y.message}); using ${t.sourceCrs}.`,file:n})}const h=xc(l,t.sourceCrs,o,n,e);if(!h)return{layers:[],issues:e};const f=r==null?void 0:r.fields.map(y=>({name:y.name,type:y.type}));return{layers:Sl(o,h,i.name,n,e,{closeRings:t.closeRings,fields:f}),issues:e}}function Lm(i,t={}){const e=[];for(const r of i)if(Em(r.name)==="zip"){const o=Xb(Yr(r.data));for(const[a,l]of Object.entries(o))a.startsWith("__MACOSX/")||a.endsWith("/")||e.push({name:a,data:l})}else e.push({name:r.name,data:Yr(r.data)});const n=new Map;for(const r of e){const o=Em(r.name);if(!["shp","dbf","prj","cpg"].includes(o))continue;const a=r.name.slice(0,r.name.length-o.length-1).toLowerCase(),l=n.get(a)??{name:dl(r.name)};o==="shp"&&(l.shp=r.data),o==="dbf"&&(l.dbf=r.data),o==="prj"&&(l.prj=Qu(r.data)),o==="cpg"&&(l.cpg=Qu(r.data)),n.set(a,l)}const s={layers:[],issues:[]};for(const r of n.values()){if(!r.shp){s.issues.push({severity:"error",code:"no-shp",message:`${r.name}: .shp file is missing.`,file:r.name});continue}const o=Kb(r,t);s.layers.push(...o.layers),s.issues.push(...o.issues)}return n.size===0&&s.issues.push({severity:"error",code:"no-shp",message:"No shapefile (.shp) found."}),s}class vv{constructor(t){Y(this,"buf");Y(this,"view");Y(this,"pos",0);this.buf=new Uint8Array(t),this.view=new DataView(this.buf.buffer)}int32BE(t){this.view.setInt32(this.pos,t,!1),this.pos+=4}int32LE(t){this.view.setInt32(this.pos,t,!0),this.pos+=4}float64(t){this.view.setFloat64(this.pos,t,!0),this.pos+=8}bytes(){return this.buf}setInt32BE(t,e){this.view.setInt32(t,e,!1)}}function Ev(i,t){return Nm(i)<0===t?i:[...i].reverse()}function Zb(i,t,e,n={},s=[]){const r=fi(n.crs??"EPSG:4326"),o=Ic(r,n.precision),a=i.filter(S=>{if(!S.geometry)return!1;const C=S.geometry.type;return t==="point"?C==="Point"||C==="MultiPoint":t==="line"?C==="LineString"||C==="MultiLineString":C==="Polygon"||C==="MultiPolygon"});a.length<i.length&&s.push({severity:"warning",code:"skipped-geometry",message:`${i.length-a.length} features without a ${t} geometry were not exported.`});const l=a.map(S=>bc(S.geometry,r,o)),h=S=>typeof S[0]=="number"?S.length>2:S.some(h);l.some(S=>h(S.coordinates))&&s.push({severity:"warning",code:"z-dropped",message:"Elevation (Z) values are not written; the shapefile is 2D."});const f=t==="point"&&l.some(S=>S.type==="MultiPoint"),d=t==="point"?f?si.MULTIPOINT:si.POINT:t==="line"?si.POLYLINE:si.POLYGON,p=l.map(S=>{let C;S.type==="Point"?C=[[S.coordinates]]:S.type==="MultiPoint"?C=[S.coordinates]:S.type==="LineString"?C=[S.coordinates]:S.type==="MultiLineString"?C=S.coordinates:S.type==="Polygon"?C=S.coordinates.map((I,M)=>Ev(I,M===0)):C=S.coordinates.flatMap(I=>I.map((M,R)=>Ev(M,R===0)));const T=C.flat();return{parts:C,bbox:wu(T)}}),y=S=>{const C=S.parts.reduce((T,I)=>T+I.length,0);return d===si.POINT?20:d===si.MULTIPOINT?40+C*16:44+S.parts.length*4+C*16},_=100+p.reduce((S,C)=>S+8+y(C),0),E=new vv(_),w=new vv(100+p.length*8),L=p.length>0?wu(p.map(S=>[[S.bbox[0],S.bbox[1]],[S.bbox[2],S.bbox[3]]]).flat()):[0,0,0,0],b=(S,C)=>{S.int32BE(9994);for(let T=0;T<5;T++)S.int32BE(0);S.int32BE(C/2),S.int32LE(1e3),S.int32LE(d),L.forEach(T=>S.float64(T));for(let T=0;T<4;T++)S.float64(0)};b(E,_),b(w,100+p.length*8),p.forEach((S,C)=>{const T=y(S);if(w.int32BE(E.pos/2),w.int32BE(T/2),E.int32BE(C+1),E.int32BE(T/2),E.int32LE(d),d===si.POINT){E.float64(S.parts[0][0][0]),E.float64(S.parts[0][0][1]);return}S.bbox.forEach(M=>E.float64(M));const I=S.parts.flat();if(d===si.MULTIPOINT)E.int32LE(I.length);else{E.int32LE(S.parts.length),E.int32LE(I.length);let M=0;S.parts.forEach(R=>{E.int32LE(M),M+=R.length})}I.forEach(M=>{E.float64(M[0]),E.float64(M[1])})});const{dbf:P,cpg:N}=Vb(a.map(S=>S.properties??{}),e,n.encoding??"utf-8",s);return{shp:E.bytes(),shx:w.bytes(),dbf:P,prj:Mf(r),cpg:N}}function Jb(i,t,e={},n=[]){const s=(e.name??"export").replace(/[\\/:*?"<>|]/g,"_"),r=["polygon","line","point"].filter(l=>i.some(h=>h.geometry&&(l==="point"?/Point/.test(h.geometry.type):l==="line"?/LineString/.test(h.geometry.type):/Polygon/.test(h.geometry.type)))),o={},a=new TextEncoder;if(r.forEach(l=>{const h=r.length>1?`${s}_${l}`:s,f=i.filter(p=>p.geometry&&(l==="point"?/Point/.test(p.geometry.type):l==="line"?/LineString/.test(p.geometry.type):/Polygon/.test(p.geometry.type))),d=Zb(f,l,t,e,n);o[`${h}.shp`]=d.shp,o[`${h}.shx`]=d.shx,o[`${h}.dbf`]=d.dbf,o[`${h}.prj`]=a.encode(d.prj),o[`${h}.cpg`]=a.encode(d.cpg)}),r.length===0)throw new Error("Nothing to export: no features with geometry.");return{filename:`${s}.zip`,mimeType:"application/zip",data:Yb(o)}}const U8={amp:"&",lt:"<",gt:">",quot:'"',apos:"'"};function Oh(i){return i.replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi,(t,e)=>{if(e[0]==="#"){const n=e[1].toLowerCase()==="x"?parseInt(e.slice(2),16):parseInt(e.slice(1),10);return Number.isFinite(n)?String.fromCodePoint(n):t}return U8[e.toLowerCase()]??t})}function pa(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function Ml(i){const t=i.indexOf(":");return t>=0?i.slice(t+1):i}function Qb(i){const t={name:"#document",attributes:{},children:[],text:""},e=[t];let n=0;const s=i.length;for(;n<s;){const r=i.indexOf("<",n);if(r<0){e[e.length-1].text+=Oh(i.slice(n));break}if(r>n&&(e[e.length-1].text+=Oh(i.slice(n,r))),i.startsWith("<!--",r)){const E=i.indexOf("-->",r+4);n=E<0?s:E+3;continue}if(i.startsWith("<![CDATA[",r)){const E=i.indexOf("]]>",r+9);e[e.length-1].text+=i.slice(r+9,E<0?s:E),n=E<0?s:E+3;continue}if(i.startsWith("<?",r)||i.startsWith("<!",r)){const E=i.indexOf(">",r);n=E<0?s:E+1;continue}const o=Y8(i,r);if(o<0)throw new Error(`Unclosed tag at position ${r}`);const a=i.slice(r+1,o);if(n=o+1,a[0]==="/"){const E=a.slice(1).trim();for(let w=e.length-1;w>0;w--)if(e[w].name===E){e.length=w;break}continue}const l=a.endsWith("/"),h=l?a.slice(0,-1):a,f=h.match(/^\s*([^\s/>]+)/);if(!f)continue;const d={name:f[1],attributes:{},children:[],text:""},p=/([^\s=]+)\s*=\s*("([^"]*)"|'([^']*)')/g;let y;const _=h.slice(f[0].length);for(;y=p.exec(_);)d.attributes[y[1]]=Oh(y[3]??y[4]??"");e[e.length-1].children.push(d),l||e.push(d)}return t}function Y8(i,t){let e=null;for(let n=t+1;n<i.length;n++){const s=i[n];if(e)s===e&&(e=null);else if(s==='"'||s==="'")e=s;else if(s===">")return n}return-1}function za(i,t){return i.children.filter(e=>Ml(e.name)===t)}function ps(i,t){return i.children.find(e=>Ml(e.name)===t)}function tI(i,t,e=[]){for(const n of i.children)Ml(n.name)===t&&e.push(n),tI(n,t,e);return e}function ys(i){return i?i.text+i.children.map(ys).join(""):""}function Cg(i){return i.trim().split(/\s+/).filter(Boolean).map(t=>t.split(",").map(Number)).map(t=>t.length>=3&&t[2]!==0?[t[0],t[1],t[2]]:[t[0],t[1]])}function Cm(i){const t=[];for(const e of i.children){const n=Ml(e.name);if(n==="Point"){const s=Cg(ys(ps(e,"coordinates")));t.push({type:"Point",coordinates:s[0]??[NaN,NaN]})}else if(n==="LineString"||n==="LinearRing")t.push({type:"LineString",coordinates:Cg(ys(ps(e,"coordinates")))});else if(n==="Polygon"){const s=a=>Cg(ys(ps(ps(a??e,"LinearRing")??e,"coordinates"))),r=s(ps(e,"outerBoundaryIs")),o=za(e,"innerBoundaryIs").map(a=>s(a));t.push({type:"Polygon",coordinates:[r,...o]})}else if(n==="MultiGeometry")t.push(...Cm(e));else if(n==="Track"||n==="MultiTrack"){const s=za(e,"coord").map(r=>ys(r).trim().split(/\s+/).map(Number).slice(0,2));s.length>0&&t.push({type:"LineString",coordinates:s}),n==="MultiTrack"&&t.push(...Cm(e))}}return t}function X8(i){if(i.length<=1||new Set(i.map(n=>n.type)).size!==1)return i;const e=i[0].type;return e==="Point"?[{type:"MultiPoint",coordinates:i.map(n=>n.coordinates)}]:e==="LineString"?[{type:"MultiLineString",coordinates:i.map(n=>n.coordinates)}]:e==="Polygon"?[{type:"MultiPolygon",coordinates:i.map(n=>n.coordinates)}]:i}function wv(i){const t=i.trim();return/^-?(0|[1-9]\d*)(\.\d+)?([eE][-+]?\d+)?$/.test(t)&&t.length<17?Number(t):t==="true"||t==="false"?t==="true":i}function c0(i,t,e={}){const n=[];let s;try{s=Qb(i)}catch(h){return n.push({severity:"error",code:"parse",message:`${t}: ${h.message}`,file:t}),{layers:[],issues:n}}const r=[];let o=0;const a=(h,f)=>{for(const d of h.children){const p=Ml(d.name);if(p==="Folder"||p==="Document"){const y=ys(ps(d,"name")).trim();a(d,p==="Folder"&&y?[...f,y]:f)}else if(p==="Placemark"){const y={},_=ps(d,"name");_&&(y.name=ys(_).trim());const E=ps(d,"description");E&&(y.description=ys(E).trim()),f.length&&(y.folder=f.join("/"));const w=ps(d,"ExtendedData");w&&(za(w,"Data").forEach(b=>{b.attributes.name&&(y[b.attributes.name]=wv(ys(ps(b,"value"))))}),za(w,"SchemaData").forEach(b=>za(b,"SimpleData").forEach(P=>{P.attributes.name&&(y[P.attributes.name]=wv(ys(P)))})));const L=X8(Cm(d));L.length===0&&r.push({geometry:null,properties:y,id:d.attributes.id}),L.forEach((b,P)=>r.push({geometry:b,properties:{...y},id:L.length===1?d.attributes.id:void 0}))}else["GroundOverlay","ScreenOverlay","PhotoOverlay","NetworkLink"].includes(p)?o++:p==="kml"&&a(d,f)}};return a(s,[]),o>0&&n.push({severity:"warning",code:"kml-unsupported",message:`${o} overlays / network links were ignored.`,file:t}),{layers:Sl(r,fi("EPSG:4326"),dl(t),t,n,{closeRings:e.closeRings}),issues:n}}function eI(i,t={}){return c0(Qu(i.data),i.name,t)}function nI(i,t={}){const e=Xb(Yr(i.data)),n=Object.keys(e).find(r=>r.toLowerCase()==="doc.kml")??Object.keys(e).find(r=>r.toLowerCase().endsWith(".kml"));return n?c0(new TextDecoder().decode(e[n]),i.name,t):{layers:[],issues:[{severity:"error",code:"no-kml",message:`${i.name} contains no .kml file.`,file:i.name}]}}function fh(i,t){return i.map(e=>e.slice(0,3).map(n=>Number(n.toFixed(t))).join(",")).join(" ")}function Fh(i,t){switch(i.type){case"Point":return`<Point><coordinates>${fh([i.coordinates],t)}</coordinates></Point>`;case"LineString":return`<LineString><tessellate>1</tessellate><coordinates>${fh(i.coordinates,t)}</coordinates></LineString>`;case"Polygon":return`<Polygon><outerBoundaryIs><LinearRing><coordinates>${fh(i.coordinates[0],t)}</coordinates></LinearRing></outerBoundaryIs>`+i.coordinates.slice(1).map(e=>`<innerBoundaryIs><LinearRing><coordinates>${fh(e,t)}</coordinates></LinearRing></innerBoundaryIs>`).join("")+"</Polygon>";case"MultiPoint":return`<MultiGeometry>${i.coordinates.map(e=>Fh({type:"Point",coordinates:e},t)).join("")}</MultiGeometry>`;case"MultiLineString":return`<MultiGeometry>${i.coordinates.map(e=>Fh({type:"LineString",coordinates:e},t)).join("")}</MultiGeometry>`;case"MultiPolygon":return`<MultiGeometry>${i.coordinates.map(e=>Fh({type:"Polygon",coordinates:e},t)).join("")}</MultiGeometry>`;default:return""}}function h0(i,t={}){const e=t.precision??8,n=pa(t.name??"export"),s=i.filter(r=>r.geometry).map(r=>{const o=r.properties??{},a=o.name??r.id,l=Object.entries(o).filter(([,h])=>h!=null).map(([h,f])=>`<Data name="${pa(h)}"><value>${pa(typeof f=="object"?JSON.stringify(f):String(f))}</value></Data>`).join("");return`<Placemark${r.id!==void 0?` id="${pa(String(r.id))}"`:""}>`+(a!==void 0?`<name>${pa(String(a))}</name>`:"")+(l?`<ExtendedData>${l}</ExtendedData>`:"")+Fh(r.geometry,e)+"</Placemark>"}).join(`
|
|
228
|
+
`);return`<?xml version="1.0" encoding="UTF-8"?>
|
|
229
|
+
<kml xmlns="http://www.opengis.net/kml/2.2"><Document><name>${n}</name>
|
|
230
|
+
${s}
|
|
231
|
+
</Document></kml>
|
|
232
|
+
`}function iI(i,t={}){return{filename:`${t.name??"export"}.kml`,mimeType:"application/vnd.google-earth.kml+xml",data:h0(i,t)}}function sI(i,t={}){const e=Yb({"doc.kml":new TextEncoder().encode(h0(i,t))});return{filename:`${t.name??"export"}.kmz`,mimeType:"application/vnd.google-earth.kmz",data:e}}function rI(i,t){const e=t??j8(i),n=[];let s=[],r="",o=!1;for(let a=0;a<i.length;a++){const l=i[a];o?l==='"'?i[a+1]==='"'?(r+='"',a++):o=!1:r+=l:l==='"'&&r===""?o=!0:l===e?(s.push(r),r=""):l===`
|
|
233
|
+
`||l==="\r"?(l==="\r"&&i[a+1]===`
|
|
234
|
+
`&&a++,s.push(r),r="",(s.length>1||s[0]!=="")&&n.push(s),s=[]):r+=l}return(r!==""||s.length>0)&&(s.push(r),n.push(s)),n}function j8(i){const t=i.split(/\r?\n/,1)[0]??"",e=[",",";"," ","|"].map(n=>({d:n,n:t.split(n).length-1}));return e.sort((n,s)=>s.n-n.n),e[0].n>0?e[0].d:","}function V8(i){return i===""?null:/^-?(0|[1-9]\d*)(\.\d+)?([eE][-+]?\d+)?$/.test(i.trim())&&i.trim().length<17?Number(i):i}function oI(i){const e=i.trim().replace(/^SRID=\d+;/i,"").match(/^(POINT|LINESTRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON)\s*(Z|M|ZM)?\s*(EMPTY|\(.*\))$/is);if(!e)return null;const n=e[1].toUpperCase();if(e[3].toUpperCase()==="EMPTY")return null;let s=0;const r=e[3],o=()=>{for(;s<r.length&&/\s/.test(r[s]);)s++},a=d=>{if(o(),r[s]!==d)throw new Error(`Expected "${d}" in WKT at ${s}`);s++},l=()=>{var y;o();const d=r.slice(s).match(/^[-+\d.eE]+(\s+[-+\d.eE]+)*/);if(!d)throw new Error(`Expected coordinates in WKT at ${s}`);s+=d[0].length;const p=d[0].trim().split(/\s+/).map(Number);return((y=e[2])==null?void 0:y.toUpperCase())==="M"?p.slice(0,2):p.slice(0,3)},h=d=>{a("(");const p=[d()];for(o();r[s]===",";)s++,p.push(d()),o();return a(")"),p},f=()=>{if(o(),r[s]==="("){s++;const d=l();return a(")"),d}return l()};switch(n){case"POINT":return{type:"Point",coordinates:h(l)[0]};case"LINESTRING":return{type:"LineString",coordinates:h(l)};case"POLYGON":return{type:"Polygon",coordinates:h(()=>h(l))};case"MULTIPOINT":return{type:"MultiPoint",coordinates:h(f)};case"MULTILINESTRING":return{type:"MultiLineString",coordinates:h(()=>h(l))};case"MULTIPOLYGON":return{type:"MultiPolygon",coordinates:h(()=>h(()=>h(l)))}}return null}function oa(i,t){return i.map(e=>e.map(n=>Number(n.toFixed(t))).join(" ")).join(", ")}function aI(i,t=8){switch(i.type){case"Point":return`POINT (${oa([i.coordinates],t)})`;case"LineString":return`LINESTRING (${oa(i.coordinates,t)})`;case"Polygon":return`POLYGON (${i.coordinates.map(e=>`(${oa(e,t)})`).join(", ")})`;case"MultiPoint":return`MULTIPOINT (${i.coordinates.map(e=>`(${oa([e],t)})`).join(", ")})`;case"MultiLineString":return`MULTILINESTRING (${i.coordinates.map(e=>`(${oa(e,t)})`).join(", ")})`;case"MultiPolygon":return`MULTIPOLYGON (${i.coordinates.map(e=>`(${e.map(n=>`(${oa(n,t)})`).join(", ")})`).join(", ")})`;default:return""}}const xv=["lon","lng","long","longitude","x","easting","east","e"],bv=["lat","latitude","y","northing","north","n"],H8=["wkt","geometry","geom","the_geom","shape"];function lI(i,t={}){var y,_,E,w,L,b,P,N;const e=[];let n=t.encoding?Do(t.encoding):"";if(!n&&typeof i.data!="string"){const S=l0([Yr(i.data)]);n=S.encoding,(S.confidence==="thai-bytes"||S.confidence==="guess")&&e.push({severity:"warning",code:"encoding-detected",message:`${i.name}: text encoding detected as ${n}.`,file:i.name})}const s=rI(Qu(i.data,n||"utf-8"),(y=t.csv)==null?void 0:y.delimiter);if(s.length<2)return e.push({severity:"error",code:"empty",message:`${i.name} has no data rows.`,file:i.name}),{layers:[],issues:e};const r=s[0].map(S=>S.trim()),o=(S,C)=>{if(S){const T=r.indexOf(S);if(T<0)throw new Error(`Column "${S}" not found in ${i.name}`);return T}return r.findIndex(T=>C.includes(T.toLowerCase()))};let a,l,h;try{a=o((_=t.csv)==null?void 0:_.wkt,H8),l=(E=t.csv)!=null&&E.wkt?-1:o((w=t.csv)==null?void 0:w.x,xv),h=(L=t.csv)!=null&&L.wkt?-1:o((b=t.csv)==null?void 0:b.y,bv)}catch(S){return e.push({severity:"error",code:"column",message:S.message,file:i.name}),{layers:[],issues:e}}const f=!((P=t.csv)!=null&&P.wkt)&&l>=0&&h>=0&&(a<0||((N=t.csv)==null?void 0:N.x)!==void 0);if(!f&&a<0)return e.push({severity:"error",code:"no-geometry-columns",message:`${i.name}: no coordinate columns found (looked for ${xv.join("/")} + ${bv.join("/")} or a WKT column). Set csv.x / csv.y.`,file:i.name}),{layers:[],issues:e};const d=s.slice(1).map((S,C)=>{S.length!==r.length&&e.push({severity:"warning",code:"column-count",message:`Row ${C+2} has ${S.length} columns (header has ${r.length}).`,file:i.name,featureIndex:C});const T={};r.forEach((M,R)=>{R===a||f&&(R===l||R===h)||(T[M]=V8(S[R]??""))});let I=null;if(f){const M=Number(String(S[l]??"").trim()),R=Number(String(S[h]??"").trim());I=String(S[l]??"").trim()===""||String(S[h]??"").trim()===""?null:{type:"Point",coordinates:[M,R]}}else try{I=oI(S[a]??""),!I&&(S[a]??"").trim()&&e.push({severity:"error",code:"wkt",message:`Row ${C+2}: unsupported WKT.`,file:i.name,featureIndex:C})}catch(M){e.push({severity:"error",code:"wkt",message:`Row ${C+2}: ${M.message}`,file:i.name,featureIndex:C})}return{geometry:I,properties:T}}),p=xc(null,t.sourceCrs,d,i.name,e);return p?{layers:Sl(d,p,dl(i.name),i.name,e,{closeRings:t.closeRings}),issues:e}:{layers:[],issues:e}}function Pg(i){if(i==null)return"";const t=typeof i=="object"?JSON.stringify(i):String(i);return/[",\r\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t}function uI(i,t={},e=[]){const n=fi(t.crs??"EPSG:4326"),s=Ic(n,t.precision),r=i.filter(p=>p.geometry),o=t.csvGeometry==="xy";if(o&&r.some(p=>p.geometry.type!=="Point"))throw new Error('CSV x/y export needs point features; use csvGeometry "wkt" for lines and polygons.');const a=Array.from(new Set(r.flatMap(p=>Object.keys(p.properties??{})))),h=[[...o?n.isGeographic?["lon","lat"]:["x","y"]:["wkt"],...a].map(Pg).join(",")];for(const p of r){const y=bc(p.geometry,n,s),_=o?y.coordinates.slice(0,2).map(String):[Pg(aI(y,s))];h.push([..._,...a.map(E=>{var w;return Pg((w=p.properties)==null?void 0:w[E])})].join(","))}const f=h.join(`\r
|
|
235
|
+
`)+`\r
|
|
236
|
+
`;let d;if(t.encoding&&Do(t.encoding)==="windows-874"){const{bytes:p,lossy:y}=u0(f);y&&e.push({severity:"warning",code:"encoding-lossy",message:'Some characters cannot be written in TIS-620 and were replaced with "?".'}),d=p}else d="\uFEFF"+f;return{filename:`${t.name??"export"}.csv`,mimeType:"text/csv",data:d}}function W8(i){const t=i.split(/\r?\n/),e=[];for(let n=0;n+1<t.length;n+=2){const s=parseInt(t[n].trim(),10);if(Number.isNaN(s))throw new Error(`Invalid DXF group code on line ${n+1}`);e.push({code:s,value:t[n+1]})}return e}const K8={ANSI_874:"windows-874",ANSI_1252:"windows-1252",ANSI_936:"gbk",ANSI_932:"shift_jis",UTF8:"utf-8"};function Z8(i,t){var o,a,l;if(t)return new TextDecoder(t).decode(i);const e=new TextDecoder("windows-1252").decode(i.subarray(0,Math.min(i.length,2e4))),n=(o=e.match(/\$ACADVER\s*\r?\n\s*1\s*\r?\n\s*(AC\d+)/))==null?void 0:o[1];if(n&&Number(n.slice(2))>=1021)return new TextDecoder("utf-8").decode(i);const s=(l=(a=e.match(/\$DWGCODEPAGE\s*\r?\n\s*3\s*\r?\n\s*(\S+)/))==null?void 0:a[1])==null?void 0:l.toUpperCase(),r=s&&K8[s]||"windows-1252";try{return new TextDecoder(r).decode(i)}catch{return new TextDecoder("windows-1252").decode(i)}}function J8(i,t){let e=i.replace(/\\U\+([0-9A-Fa-f]{4})/g,(n,s)=>String.fromCharCode(parseInt(s,16)));return t&&(e=e.replace(/\\P/g,`
|
|
237
|
+
`).replace(/\\[ACcFfHhQqTtWw][^;]*;/g,"").replace(/\\[LlOoKk]/g,"").replace(/[{}]/g,"")),e.replace(/%%[cC]/g,"Ø").replace(/%%[dD]/g,"°").replace(/%%[pP]/g,"±")}function cI(i,t,e,n){if(!e)return[t];const s=4*Math.atan(e),r=Math.hypot(t[0]-i[0],t[1]-i[1]);if(r===0)return[t];const o=r/(2*Math.sin(Math.abs(s)/2)),a=(i[0]+t[0])/2,l=(i[1]+t[1])/2,h=o*Math.cos(s/2),f=-(t[1]-i[1])/r,d=(t[0]-i[0])/r,p=s>0?1:-1,y=a+f*h*p,_=l+d*h*p,E=Math.atan2(i[1]-_,i[0]-y),w=Math.max(1,Math.ceil(Math.abs(s*180/Math.PI)/n)),L=[];for(let b=1;b<w;b++){const P=E+s*b/w;L.push([y+o*Math.cos(P),_+o*Math.sin(P)])}return L.push(t),L}function Iv(i,t,e,n,s,r){let o=s-n;for(;o<=0;)o+=360;const a=Math.max(1,Math.ceil(o/r));return Array.from({length:a+1},(l,h)=>{const f=(n+o*h/a)*Math.PI/180;return[i+e*Math.cos(f),t+e*Math.sin(f)]})}function Sv(i){const t=i[0],e=i[i.length-1];return t[0]===e[0]&&t[1]===e[1]?i:[...i,[t[0],t[1]]]}function hI(i,t={}){var N;const e=[],n=t.arcSegmentDegrees??5,s=t.dxfClosedAsPolygons??!0;let r;try{const S=typeof i.data=="string"?i.data:Z8(Yr(i.data),t.encoding);r=W8(S)}catch(S){return e.push({severity:"error",code:"parse",message:`${i.name}: ${S.message}`,file:i.name}),{layers:[],issues:e}}const o=r.findIndex(S=>S.code===9&&S.value.trim()==="$INSUNITS");if(o>=0){const S=Number((N=r[o+1])==null?void 0:N.value),C={1:"inches",2:"feet",4:"millimeters",5:"centimeters",7:"kilometers"};C[S]&&e.push({severity:"warning",code:"dxf-units",message:`Drawing units are ${C[S]}; coordinates are used as-is in the source CRS.`,file:i.name})}let a=-1;for(let S=0;S+1<r.length;S++)if(r[S].code===0&&r[S].value.trim()==="SECTION"&&r[S+1].code===2&&r[S+1].value.trim()==="ENTITIES"){a=S+2;break}if(a<0)return e.push({severity:"error",code:"no-entities",message:`${i.name} has no ENTITIES section.`,file:i.name}),{layers:[],issues:e};const l=[];for(let S=a;S<r.length;S++){const C=r[S];if(C.code===0){const T=C.value.trim();if(T==="ENDSEC"||T==="EOF")break;l.push({type:T,pairs:[]})}else l.length>0&&l[l.length-1].pairs.push(C)}const h=new Map,f=new Map;let d=0;const p=(S,C,T)=>{h.has(S)||h.set(S,[]),h.get(S).push({geometry:C,properties:{layer:S,...T}})},y=(S,C,T=0)=>{const I=S.pairs.find(M=>M.code===C);return I?Number(I.value):T},_=(S,C)=>{var T;return(T=S.pairs.find(I=>I.code===C))==null?void 0:T.value.trim()};for(let S=0;S<l.length;S++){const C=l[S],T=_(C,8)??"0",I={entity:C.type},M=_(C,5);M&&(I.handle=M);const R=_(C,62);switch(R!==void 0&&(I.color=Number(R)),C.type){case"POINT":p(T,{type:"Point",coordinates:[y(C,10),y(C,20)]},I);break;case"LINE":p(T,{type:"LineString",coordinates:[[y(C,10),y(C,20)],[y(C,11),y(C,21)]]},I);break;case"LWPOLYLINE":{const A=(y(C,70)&1)===1,F=[];for(const $ of C.pairs)$.code===10?F.push({p:[Number($.value),0],bulge:0}):$.code===20&&F.length?F[F.length-1].p[1]=Number($.value):$.code===42&&F.length&&(F[F.length-1].bulge=Number($.value));E(T,F,A,I);break}case"POLYLINE":{const A=y(C,70),F=[];for(;S+1<l.length&&l[S+1].type==="VERTEX";){S++;const $=l[S];if(y($,70)&128&&!(y($,70)&64))continue;const z=[y($,10),y($,20)],D=y($,30);A&8&&D&&z.push(D),F.push({p:z,bulge:y($,42)})}if(S+1<l.length&&l[S+1].type==="SEQEND"&&S++,A&80){f.set("POLYLINE mesh",(f.get("POLYLINE mesh")??0)+1);break}E(T,F,(A&1)===1,I);break}case"CIRCLE":{d++;const A=Iv(y(C,10),y(C,20),y(C,40),0,360,n);A[A.length-1]=[A[0][0],A[0][1]],p(T,s?{type:"Polygon",coordinates:[A]}:{type:"LineString",coordinates:A},{...I,radius:y(C,40)});break}case"ARC":d++,p(T,{type:"LineString",coordinates:Iv(y(C,10),y(C,20),y(C,40),y(C,50),y(C,51),n)},{...I,radius:y(C,40)});break;case"TEXT":case"MTEXT":{const A=C.pairs.filter(F=>F.code===3||F.code===1).map(F=>F.value);p(T,{type:"Point",coordinates:[y(C,10),y(C,20)]},{...I,text:J8(A.join(""),C.type==="MTEXT"),height:y(C,40)});break}case"VERTEX":case"SEQEND":break;default:f.set(C.type,(f.get(C.type)??0)+1)}}function E(S,C,T,I){if(C.length===0)return;const M=[C[0].p],R=T?C.length:C.length-1;for(let A=0;A<R;A++){const F=C[A],$=C[(A+1)%C.length];F.bulge&&d++,M.push(...cI(F.p,$.p,F.bulge,n))}T&&s&&C.length>=3?p(S,{type:"Polygon",coordinates:[Sv(M)]},I):p(S,{type:"LineString",coordinates:T?Sv(M):M},I)}d>0&&e.push({severity:"warning",code:"curves-densified",message:`${d} arcs / circles / bulges were converted to vertices (at most ${n}° per segment).`,file:i.name}),f.size>0&&e.push({severity:"warning",code:"dxf-unsupported",message:`Not imported: ${Array.from(f.entries()).map(([S,C])=>`${C} ${S}`).join(", ")}.`,file:i.name});const w=Array.from(h.values()).flat(),L=xc(null,t.sourceCrs,w,i.name,e);if(!L)return{layers:[],issues:e};const b=[],P=h.size>1;for(const[S,C]of h)b.push(...Sl(C,L,P?`${dl(i.name)} / ${S}`:dl(i.name),i.name,e,{closeRings:!0}));return{layers:b,issues:e}}function Q8(i){return i.replace(/[^\x20-\x7e]/g,t=>`\\U+${t.charCodeAt(0).toString(16).toUpperCase().padStart(4,"0")}`)}function Mv(i){return Q8(i).replace(/[<>/\\":;?*|=`]/g,"_").slice(0,255)||"0"}function fI(i,t={},e=[]){const n=i.flatMap(y=>y.features).filter(y=>y.geometry);if(n.length===0)throw new Error("Nothing to export: no features with geometry.");let s;if(t.crs)s=fi(t.crs);else{let y=0,_=0,E=0;const w=L=>{typeof L[0]=="number"?(y+=L[0],_+=L[1],E++):L.forEach(w)};n.forEach(L=>w(L.geometry.coordinates)),s=Rb(y/E,_/E)}s.isGeographic&&e.push({severity:"warning",code:"dxf-degrees",message:"DXF written in degrees; CAD measurements will not be in meters."});const r=Ic(s,t.precision),o=[],a=(y,_)=>o.push(String(y),String(_)),l=y=>Number(y.toFixed(r)).toString(),h=new Map;i.forEach(y=>{let _=Mv(y.name);for(let E=2;Array.from(h.values()).includes(_);E++)_=`${Mv(y.name)}_${E}`;h.set(y.name,_)}),a(0,"SECTION"),a(2,"HEADER"),a(9,"$ACADVER"),a(1,"AC1009"),a(9,"$INSUNITS"),a(70,s.isGeographic?0:6),a(0,"ENDSEC"),a(0,"SECTION"),a(2,"TABLES"),a(0,"TABLE"),a(2,"LAYER"),a(70,i.length),i.forEach((y,_)=>{a(0,"LAYER"),a(2,h.get(y.name)),a(70,0),a(62,_%6+1),a(6,"CONTINUOUS")}),a(0,"ENDTAB"),a(0,"ENDSEC"),a(0,"SECTION"),a(2,"ENTITIES");let f=!1;const d=(y,_,E)=>{const w=E&&_.length>1&&_[0][0]===_[_.length-1][0]&&_[0][1]===_[_.length-1][1]?_.slice(0,-1):_;a(0,"POLYLINE"),a(8,y),a(66,1),a(10,0),a(20,0),a(30,0),a(70,E?1:0),w.forEach(L=>{a(0,"VERTEX"),a(8,y),a(10,l(L[0])),a(20,l(L[1])),a(30,0)}),a(0,"SEQEND"),a(8,y)},p=(y,_)=>{a(0,"POINT"),a(8,y),a(10,l(_[0])),a(20,l(_[1])),a(30,0)};return i.forEach(y=>{const _=h.get(y.name);y.features.forEach(E=>{if(!E.geometry)return;Object.keys(E.properties??{}).length>0&&(f=!0);const w=bc(E.geometry,s,r);switch(w.type){case"Point":p(_,w.coordinates);break;case"MultiPoint":w.coordinates.forEach(L=>p(_,L));break;case"LineString":d(_,w.coordinates,!1);break;case"MultiLineString":w.coordinates.forEach(L=>d(_,L,!1));break;case"Polygon":w.coordinates.forEach(L=>d(_,L,!0));break;case"MultiPolygon":w.coordinates.forEach(L=>L.forEach(b=>d(_,b,!0)));break}})}),a(0,"ENDSEC"),a(0,"EOF"),f&&e.push({severity:"warning",code:"dxf-attributes",message:"DXF R12 has no attribute table; feature attributes were not written."}),{filename:`${t.name??"export"}.dxf`,mimeType:"application/dxf",data:o.join(`\r
|
|
238
|
+
`)+`\r
|
|
239
|
+
`,crs:s}}function dI(i,t){let e=0n;for(let n=0;n<8;n++){const s=i[t+n];if(e=e<<7n|BigInt(s&127),(s&128)===0)return[Pm(e),n+1]}return e=e<<8n|BigInt(i[t+8]),[Pm(BigInt.asIntN(64,e)),9]}function Pm(i){return i>=BigInt(Number.MIN_SAFE_INTEGER)&&i<=BigInt(Number.MAX_SAFE_INTEGER)?Number(i):i}function km(i,t){const[e,n]=dI(i,t);return[Number(e),n]}function hr(i){let t=BigInt.asUintN(64,BigInt(i));if(t>0x00ffffffffffffffn){const n=new Array(9);n[8]=Number(t&0xffn),t>>=8n;for(let s=7;s>=0;s--)n[s]=Number(t&0x7fn)|128,t>>=7n;return n}const e=[];do e.unshift(Number(t&0x7fn)),t>>=7n;while(t>0n);for(let n=0;n<e.length-1;n++)e[n]|=128;return e}function gI(i){const[t,e]=km(i,0),n=[];let s=e;for(;s<t;){const[h,f]=km(i,s);n.push(h),s+=f}const r=new DataView(i.buffer,i.byteOffset,i.byteLength),o=[];let a=t;const l=new TextDecoder;for(const h of n)switch(h){case 0:o.push(null);break;case 1:o.push(r.getInt8(a)),a+=1;break;case 2:o.push(r.getInt16(a)),a+=2;break;case 3:o.push(r.getInt8(a)<<16|r.getUint16(a+1)),a+=3;break;case 4:o.push(r.getInt32(a)),a+=4;break;case 5:o.push(r.getInt16(a)*4294967296+r.getUint32(a+2)),a+=6;break;case 6:o.push(Pm(r.getBigInt64(a))),a+=8;break;case 7:o.push(r.getFloat64(a)),a+=8;break;case 8:o.push(0);break;case 9:o.push(1);break;default:if(h>=12){const f=h%2===0?(h-12)/2:(h-13)/2,d=i.subarray(a,a+f);o.push(h%2===0?d.slice():l.decode(d)),a+=f}else throw new Error(`Unsupported SQLite serial type ${h}`)}return o}function Tm(i){const t=new TextEncoder,e=[],n=[];for(const f of i)if(f==null)e.push(0),n.push(new Uint8Array(0));else if(typeof f=="string"){const d=t.encode(f);e.push(d.length*2+13),n.push(d)}else if(f instanceof Uint8Array)e.push(f.length*2+12),n.push(f);else if(typeof f=="bigint"||Number.isInteger(f)&&Math.abs(f)<=Number.MAX_SAFE_INTEGER){const d=BigInt(f);if(d===0n)e.push(8),n.push(new Uint8Array(0));else if(d===1n)e.push(9),n.push(new Uint8Array(0));else{const p=[[1,1,0x7fn],[2,2,0x7fffn],[3,3,0x7fffffn],[4,4,0x7fffffffn],[5,6,0x7fffffffffffn],[6,8,0x7fffffffffffffffn]],[y,_]=p.find(([,,L])=>d<=L&&d>=-L-1n),E=new Uint8Array(_);let w=BigInt.asUintN(_*8,d);for(let L=_-1;L>=0;L--)E[L]=Number(w&0xffn),w>>=8n;e.push(y),n.push(E)}}else{const d=new Uint8Array(8);new DataView(d.buffer).setFloat64(0,f),e.push(7),n.push(d)}const s=e.flatMap(hr);let r=s.length+1;hr(r).length>1&&(r=s.length+hr(s.length+2).length);const o=[...hr(r),...s],a=o.length+n.reduce((f,d)=>f+d.length,0),l=new Uint8Array(a);l.set(o,0);let h=o.length;for(const f of n)l.set(f,h),h+=f.length;return l}function Nv(i){const t=i.trim();return t.startsWith('"')&&t.endsWith('"')||t.startsWith("`")&&t.endsWith("`")?t.slice(1,-1).replace(/""/g,'"'):t.startsWith("[")&&t.endsWith("]")||t.startsWith("'")&&t.endsWith("'")?t.slice(1,-1):t}function mI(i){var f,d;const t=i.indexOf("("),e=i.lastIndexOf(")");if(t<0||e<t)return{columns:[],withoutRowid:!1};const n=i.slice(t+1,e),s=[];let r=0,o=null,a="";for(const p of n){if(o){a+=p,p===o&&(o=null);continue}if(p==='"'||p==="'"||p==="`"||p==="["){o=p==="["?"]":p,a+=p;continue}p==="("&&r++,p===")"&&r--,p===","&&r===0?(s.push(a),a=""):a+=p}a.trim()&&s.push(a);const l=[];let h=null;for(const p of s){const y=p.trim();if(/^(CONSTRAINT\s+\S+\s+)?(PRIMARY\s+KEY|UNIQUE|CHECK|FOREIGN\s+KEY)\b/i.test(y)){const b=y.match(/PRIMARY\s+KEY\s*\(([^)]*)\)/i);b&&(h=b[1].split(",").map(P=>Nv(P.trim().split(/\s+/)[0])));continue}const _=y.match(/^("(?:[^"]|"")*"|`[^`]*`|\[[^\]]*\]|'[^']*'|\S+)\s*(.*)$/s);if(!_)continue;const E=_[2],w=(((f=E.match(/^([A-Za-z][A-Za-z0-9_]*(?:\s+[A-Za-z][A-Za-z0-9_]*)*(?:\s*\([^)]*\))?)/))==null?void 0:f[1])??"").replace(/\s+(PRIMARY|NOT|NULL|UNIQUE|DEFAULT|CHECK|REFERENCES|CONSTRAINT|COLLATE|GENERATED|AS)\b.*$/is,"").trim(),L=/\bPRIMARY\s+KEY\b/i.test(E)&&!/\bDESC\b/i.test(((d=E.match(/PRIMARY\s+KEY\s*(\w+)?/i))==null?void 0:d[0])??"");l.push({name:Nv(_[1]),declaredType:w,isRowidAlias:L&&w.toUpperCase()==="INTEGER"})}if(h&&h.length===1){const p=l.find(y=>y.name===h[0]);p&&p.declaredType.toUpperCase()==="INTEGER"&&(p.isRowidAlias=!0)}return{columns:l,withoutRowid:/\)\s*WITHOUT\s+ROWID\s*;?\s*$/i.test(i)}}class pI{constructor(t,e){Y(this,"pages");Y(this,"pageSize");Y(this,"usable");Y(this,"walPages",new Map);Y(this,"header");Y(this,"warnings",[]);if(new TextDecoder().decode(t.subarray(0,15))!=="SQLite format 3")throw new Error("Not an SQLite database");const s=new DataView(t.buffer,t.byteOffset,t.byteLength),r=s.getUint16(16);if(this.pageSize=r===1?65536:r,this.usable=this.pageSize-t[20],this.pages=t,this.header={applicationId:s.getUint32(68),userVersion:s.getUint32(60),walMode:t[18]===2||t[19]===2,textEncoding:s.getUint32(56)},this.header.textEncoding>1)throw new Error("Only UTF-8 SQLite databases are supported");e&&e.byteLength>32&&this.loadWal(e)}loadWal(t){const e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=e.getUint32(0);if(n!==931071618&&n!==931071619){this.warnings.push("The -wal file is not valid and was ignored.");return}const s=n===931071619,r=e.getUint32(8);if(r!==this.pageSize){this.warnings.push("The -wal file page size does not match; it was ignored.");return}const o=e.getUint32(16),a=e.getUint32(20),l=(p,y)=>{const _=new DataView(p.buffer,p.byteOffset,p.byteLength);let[E,w]=y;for(let L=0;L+8<=p.byteLength;L+=8)E=E+_.getUint32(L,!s)+w>>>0,w=w+_.getUint32(L+4,!s)+E>>>0;return[E,w]};let h=l(t.subarray(0,24),[0,0]);if(h[0]!==e.getUint32(24)||h[1]!==e.getUint32(28)){this.warnings.push("The -wal file header checksum is wrong; it was ignored.");return}const f=new Map,d=24+r;for(let p=32;p+d<=t.byteLength&&!(e.getUint32(p+8)!==o||e.getUint32(p+12)!==a||(h=l(t.subarray(p,p+8),h),h=l(t.subarray(p+24,p+d),h),h[0]!==e.getUint32(p+16)||h[1]!==e.getUint32(p+20)));p+=d)f.set(e.getUint32(p),t.subarray(p+24,p+d)),e.getUint32(p+4)!==0&&(f.forEach((y,_)=>this.walPages.set(_,y)),f.clear())}page(t){const e=this.walPages.get(t);if(e)return e;const n=(t-1)*this.pageSize;if(t<1||n+this.pageSize>this.pages.byteLength)throw new Error(`SQLite page ${t} is outside the file`);return this.pages.subarray(n,n+this.pageSize)}*scanTable(t){const e=[t],n=new Set;for(;e.length>0;){const s=e.pop();if(n.has(s))throw new Error("SQLite B-tree loop detected (corrupt file)");n.add(s);const r=this.page(s),o=s===1?100:0,a=new DataView(r.buffer,r.byteOffset,r.byteLength),l=r[o],h=a.getUint16(o+3);if(l===5){const f=[];for(let d=0;d<h;d++)f.push(a.getUint32(a.getUint16(o+12+d*2)));f.push(a.getUint32(o+8));for(let d=f.length-1;d>=0;d--)e.push(f[d])}else if(l===13)for(let f=0;f<h;f++){let d=a.getUint16(o+8+f*2);const[p,y]=km(r,d);d+=y;const[_,E]=dI(r,d);d+=E,yield{rowid:_,values:gI(this.payload(r,d,p))}}else throw new Error(`Unexpected SQLite page type ${l} in a table B-tree`)}}payload(t,e,n){const s=this.usable,r=s-35;if(n<=r)return t.subarray(e,e+n);const o=Math.floor((s-12)*32/255)-23;let a=o+(n-o)%(s-4);a>r&&(a=o);const l=new Uint8Array(n);l.set(t.subarray(e,e+a),0);let h=a,f=new DataView(t.buffer,t.byteOffset+e+a,4).getUint32(0);for(;h<n;){if(f===0)throw new Error("SQLite overflow chain ends early (corrupt file)");const d=this.page(f),p=Math.min(n-h,s-4);l.set(d.subarray(4,4+p),h),h+=p,f=new DataView(d.buffer,d.byteOffset,4).getUint32(0)}return l}tables(){const t=[];for(const{values:e}of this.scanTable(1)){const[n,s,,r,o]=e;if(n!=="table"||typeof o!="string")continue;const a=mI(o);if(a.withoutRowid){this.warnings.push(`Table "${s}" is WITHOUT ROWID and cannot be read.`);continue}/^CREATE\s+VIRTUAL\s+TABLE/i.test(o)||t.push({name:String(s),rootPage:Number(r),sql:o,columns:a.columns})}return t}*rows(t){for(const{rowid:e,values:n}of this.scanTable(t.rootPage)){const s={};t.columns.forEach((r,o)=>{s[r.name]=r.isRowidAlias?e:o<n.length?n[o]:null}),yield s}}}function tF(i,t){const e=a=>a===null?0:typeof a=="number"||typeof a=="bigint"?1:typeof a=="string"?2:3,n=e(i),s=e(t);if(n!==s)return n-s;if(n===0)return 0;if(n===1)return Number(i)<Number(t)?-1:Number(i)>Number(t)?1:0;const r=typeof i=="string"?new TextEncoder().encode(i):i,o=typeof t=="string"?new TextEncoder().encode(t):t;for(let a=0;a<Math.min(r.length,o.length);a++)if(r[a]!==o[a])return r[a]-o[a];return r.length-o.length}class yI{constructor(){Y(this,"pageSize",4096);Y(this,"pages",[])}allocate(){return this.pages.push(new Uint8Array(this.pageSize)),this.pages.length}get usable(){return this.pageSize}tableLeafCell(t,e){const n=[...hr(e.length),...hr(t)],s=this.localSize(e.length,this.usable-35);return this.cellWithOverflow(n,e,s)}indexLeafCell(t){const e=Math.floor((this.usable-12)*64/255)-23,n=this.localSize(t.length,e);return this.cellWithOverflow(hr(t.length),t,n)}localSize(t,e){if(t<=e)return t;const n=Math.floor((this.usable-12)*32/255)-23,s=n+(t-n)%(this.usable-4);return s<=e?s:n}cellWithOverflow(t,e,n){const s=n<e.length,r=new Uint8Array(t.length+n+(s?4:0));if(r.set(t,0),r.set(e.subarray(0,n),t.length),s){let o=e.subarray(n);const a=this.allocate();new DataView(r.buffer).setUint32(t.length+n,a);let l=a;for(;o.length>0;){const h=Math.min(o.length,this.usable-4),f=this.pages[l-1];if(f.set(o.subarray(0,h),4),o=o.subarray(h),o.length>0){const d=this.allocate();new DataView(f.buffer).setUint32(0,d),l=d}}}return r}writePage(t,e,n,s){const r=this.pages[t-1],o=new DataView(r.buffer),a=t===1?100:0,l=e===5||e===2?12:8;let h=this.pageSize;n.forEach((f,d)=>{h-=f.length,r.set(f,h),o.setUint16(a+l+d*2,h)}),r[a]=e,o.setUint16(a+1,0),o.setUint16(a+3,n.length),o.setUint16(a+5,h===65536?0:h),r[a+7]=0,s!==void 0&&o.setUint32(a+8,s)}capacity(t,e){return this.pageSize-(t===1?100:0)-(e?12:8)}buildTable(t,e){const s=[...e].sort((f,d)=>f.rowid-d.rowid).map(f=>({key:f.rowid,cell:this.tableLeafCell(f.rowid,Tm(f.values))}));if(((f,d,p)=>f.reduce((y,_)=>y+_.cell.length+2,0)<=this.capacity(d,p))(s,t,!1)){this.writePage(t,13,s.map(f=>f.cell));return}let o=[],a=[],l=0;const h=()=>{const f=this.allocate();this.writePage(f,13,a.map(d=>d.cell)),o.push({page:f,maxKey:a[a.length-1].key}),a=[],l=0};for(const f of s)a.length>0&&l+f.cell.length+2>this.capacity(2,!1)&&h(),a.push(f),l+=f.cell.length+2;for(a.length>0&&h();;){const f=o.map(E=>({child:E,cell:new Uint8Array([0,0,0,0,...hr(E.maxKey)])}));if(f.forEach(E=>new DataView(E.cell.buffer).setUint32(0,E.child.page)),f.reduce((E,w)=>E+w.cell.length+2,0)-(f[f.length-1].cell.length+2)<=this.capacity(t,!0)){const E=f.pop();this.writePage(t,5,f.map(w=>w.cell),E.child.page);return}const d=[[]];let p=0;for(const E of f)d[d.length-1].length>1&&p+E.cell.length+2>this.capacity(2,!0)&&(d.push([]),p=0),d[d.length-1].push(E),p+=E.cell.length+2;const y=d[d.length-1];y.length<2&&d.length>1&&y.unshift(d[d.length-2].pop()),o=d.map(E=>{const w=E[E.length-1],L=this.allocate();return this.writePage(L,5,E.slice(0,-1).map(b=>b.cell),w.child.page),{page:L,maxKey:w.child.maxKey}})}}buildIndex(t,e,n){const r=[...e].sort((o,a)=>{for(let l=0;l<o.length;l++){const h=tF(o[l],a[l]);if(h!==0)return h}return 0}).map(o=>this.indexLeafCell(Tm(o)));if(r.reduce((o,a)=>o+a.length+2,0)>this.capacity(t,!1))throw new Error(`Index of ${n} does not fit in one page`);this.writePage(t,10,r)}build(t,e){this.pages=[],this.allocate();const n=[];let s=1;for(const a of t){const l=this.allocate();n.push({rowid:s++,values:["table",a.name,a.name,l,a.sql]});const h=(a.autoIndexes??[]).map((f,d)=>{const p=this.allocate();return n.push({rowid:s++,values:["index",`sqlite_autoindex_${a.name}_${d+1}`,a.name,p,null]}),{cols:f,indexRoot:p}});this.buildTable(l,a.rows),h.forEach(({cols:f,indexRoot:d})=>this.buildIndex(d,a.rows.map(p=>[...f.map(y=>p.values[y]),p.rowid]),a.name))}this.buildTable(1,n);const r=new Uint8Array(this.pages.length*this.pageSize);this.pages.forEach((a,l)=>r.set(a,l*this.pageSize));const o=new DataView(r.buffer);return r.set(new TextEncoder().encode("SQLite format 3\0"),0),o.setUint16(16,this.pageSize),r[18]=1,r[19]=1,r[20]=0,r[21]=64,r[22]=32,r[23]=32,o.setUint32(24,1),o.setUint32(28,this.pages.length),o.setUint32(32,0),o.setUint32(36,0),o.setUint32(40,1),o.setUint32(44,4),o.setUint32(48,0),o.setUint32(52,0),o.setUint32(56,1),o.setUint32(60,e.userVersion),o.setUint32(64,0),o.setUint32(68,e.applicationId),o.setUint32(92,1),o.setUint32(96,3045e3),r}}const _I=1196444487,vI=["","Point","LineString","Polygon","MultiPoint","MultiLineString","MultiPolygon","GeometryCollection"];function f0(i,t=0){const e=new DataView(i.buffer,i.byteOffset,i.byteLength);let n=t;const s=i[n]===1;n+=1;let r=e.getUint32(n,s);n+=4;let o=(r&2147483648)!==0,a=(r&1073741824)!==0;r&536870912&&(n+=4),r&=268435455,r>=3e3?(o=a=!0,r-=3e3):r>=2e3?(a=!0,r-=2e3):r>=1e3&&(o=!0,r-=1e3);const l=vI[r];if(!l)throw new Error(`Unsupported WKB geometry type ${r} (curves and surfaces are not supported)`);const h=()=>{const E=[e.getFloat64(n,s),e.getFloat64(n+8,s)];return n+=16,o&&(E.push(e.getFloat64(n,s)),n+=8),a&&(n+=8),E},f=()=>{const E=e.getUint32(n,s);return n+=4,E},d=()=>Array.from({length:f()},h),p=()=>Array.from({length:f()},d),y=()=>Array.from({length:f()},()=>{const E=f0(i,n);return n=E.end,E.geometry});let _;switch(l){case"Point":{_={type:"Point",coordinates:h()};break}case"LineString":_={type:"LineString",coordinates:d()};break;case"Polygon":_={type:"Polygon",coordinates:p()};break;case"MultiPoint":_={type:"MultiPoint",coordinates:y().map(E=>E.coordinates)};break;case"MultiLineString":_={type:"MultiLineString",coordinates:y().map(E=>E.coordinates)};break;case"MultiPolygon":_={type:"MultiPolygon",coordinates:y().map(E=>E.coordinates)};break;default:_={type:"GeometryCollection",geometries:y()}}return{geometry:_,end:n}}function EI(i){const t=[],e=new ArrayBuffer(8),n=new DataView(e),s=l=>{n.setUint32(0,l,!0),t.push(...new Uint8Array(e,0,4))},r=l=>{n.setFloat64(0,l,!0),t.push(...new Uint8Array(e,0,8))},o=l=>typeof l[0]=="number"?l.length>2:l.length>0&&l.every(o),a=l=>{const h=l.type!=="GeometryCollection"&&o(l.coordinates),f=vI.indexOf(l.type)+(h?1e3:0),d=p=>{r(p[0]),r(p[1]),h&&r(p[2])};switch(t.push(1),s(f),l.type){case"Point":d(l.coordinates);break;case"LineString":s(l.coordinates.length),l.coordinates.forEach(d);break;case"Polygon":s(l.coordinates.length),l.coordinates.forEach(p=>{s(p.length),p.forEach(d)});break;case"MultiPoint":s(l.coordinates.length),l.coordinates.forEach(p=>a({type:"Point",coordinates:h?p:p.slice(0,2)}));break;case"MultiLineString":s(l.coordinates.length),l.coordinates.forEach(p=>a({type:"LineString",coordinates:p}));break;case"MultiPolygon":s(l.coordinates.length),l.coordinates.forEach(p=>a({type:"Polygon",coordinates:p}));break;case"GeometryCollection":s(l.geometries.length),l.geometries.forEach(a);break}};return a(i),Uint8Array.from(t)}function wI(i){if(i.length<8||i[0]!==71||i[1]!==80)throw new Error('Not a GeoPackage geometry (missing "GP" header)');const t=i[3];if(t&16)return null;const e=[0,32,48,48,64][t>>1&7];if(e===void 0)throw new Error("Invalid GeoPackage envelope indicator");if(t&32)throw new Error("Extended GeoPackage geometry types are not supported");return f0(i,8+e).geometry}function xI(i,t){const e=EI(i);let n=1/0,s=1/0,r=-1/0,o=-1/0;const a=f=>{typeof f[0]=="number"?(n=Math.min(n,f[0]),r=Math.max(r,f[0]),s=Math.min(s,f[1]),o=Math.max(o,f[1])):f.forEach(a)};i.type==="GeometryCollection"?i.geometries.forEach(f=>a(f.coordinates)):a(i.coordinates);const l=new Uint8Array(40+e.length),h=new DataView(l.buffer);return l[0]=71,l[1]=80,l[2]=0,l[3]=3,h.setInt32(4,t,!0),[n,r,s,o].forEach((f,d)=>h.setFloat64(8+d*8,f,!0)),l.set(e,40),l}function eF(i){return i===null?null:typeof i=="string"?i:i instanceof Uint8Array?null:String(i)}function bI(i,t={}){var _,E;const e=[];let n;try{n=new pI(Yr(i.data),t.wal?Yr(t.wal):void 0)}catch(w){return e.push({severity:"error",code:"parse",message:`${i.name}: ${w.message}`,file:i.name}),{layers:[],issues:e}}n.warnings.forEach(w=>e.push({severity:"warning",code:"sqlite",message:w,file:i.name}));const s=n.header.applicationId;s!==_I&&s!==1196437808&&s!==1196437809&&e.push({severity:"warning",code:"gpkg-application-id",message:`${i.name} is not marked as a GeoPackage; reading it anyway.`,file:i.name}),n.header.walMode&&!t.wal&&e.push({severity:"warning",code:"gpkg-wal",message:`${i.name} uses WAL journaling; changes still in "${i.name}-wal" are not included unless that file is imported too.`,file:i.name});let r;try{r=n.tables()}catch(w){return e.push({severity:"error",code:"parse",message:`${i.name}: ${w.message}`,file:i.name}),{layers:[],issues:e}}const o=w=>r.find(L=>L.name.toLowerCase()===w.toLowerCase()),a=o("gpkg_contents"),l=o("gpkg_geometry_columns"),h=o("gpkg_spatial_ref_sys");if(!a||!l)return e.push({severity:"error",code:"not-gpkg",message:`${i.name} has no gpkg_contents / gpkg_geometry_columns tables.`,file:i.name}),{layers:[],issues:e};const f=new Map;if(h)for(const w of n.rows(h))f.set(Number(w.srs_id),w);const d=new Map;for(const w of n.rows(l))d.set(String(w.table_name).toLowerCase(),w);const p=[],y=[];for(const w of n.rows(a)){const L=String(w.table_name);if(w.data_type!=="features"){y.push(`${L} (${w.data_type})`);continue}const b=o(L),P=d.get(L.toLowerCase());if(!b||!P){e.push({severity:"error",code:"gpkg-table",message:`Feature table "${L}" or its geometry column is missing.`,file:i.name});continue}const N=String(P.column_name),S=eF(w.identifier)||L,C=`${i.name}:${L}`;let T=null;const I=Number(P.srs_id??w.srs_id),M=f.get(I);if(M&&I>0){const U=String(M.organization??"").toUpperCase(),j=Number(M.organization_coordsys_id);try{T=fi(`${U==="EPSG"?"EPSG":U}:${j}`),s0(T)&&e.push({severity:"warning",code:"crs-datum-shift",message:`${C}: EPSG:${j} converted with the project datum shift (+towgs84=${(_=T.definition.match(/\+towgs84=([^ ]+)/))==null?void 0:_[1]}); GDAL / QGIS may use a different EPSG transformation for the same code.`,file:i.name})}catch{try{T=i0(String(M.definition??""))}catch(K){if(!t.sourceCrs){e.push({severity:"error",code:"gpkg-crs",message:`${C}: CRS ${U}:${j} is not supported (${K.message}). Import with sourceCrs.`,file:i.name});continue}}}}const R=(E=b.columns.find(U=>U.isRowidAlias))==null?void 0:E.name,A=b.columns.filter(U=>U.name!==N&&U.name!==R),F=A.map(U=>{const j=U.declaredType.toUpperCase(),K=j==="BOOLEAN"?"boolean":j==="DATE"||j==="DATETIME"?"date":/INT|REAL|FLOAT|DOUBLE|NUMERIC|DECIMAL/.test(j)?"number":"string";return{name:U.name,type:K}}),$=A.filter(U=>U.declaredType.toUpperCase()==="BLOB").map(U=>U.name);$.length>0&&e.push({severity:"warning",code:"gpkg-blob",message:`${C}: binary columns (${$.join(", ")}) were not imported.`,file:i.name});const z=[];let D=0;try{for(const U of n.rows(b)){let j=null;const K=U[N];if(K instanceof Uint8Array)try{j=wI(K)}catch(lt){D++,D===1&&e.push({severity:"error",code:"gpkg-geometry",message:`${C}: ${lt.message}`,file:i.name,featureIndex:z.length})}const W={};F.forEach(lt=>{if($.includes(lt.name))return;const ft=U[lt.name];W[lt.name]=ft instanceof Uint8Array?null:lt.type==="boolean"&&ft!==null?Number(ft)!==0:typeof ft=="bigint"?ft.toString():ft});const J=R?U[R]:void 0;z.push({geometry:j,properties:W,id:typeof J=="number"?J:typeof J=="bigint"?J.toString():void 0})}}catch(U){e.push({severity:"error",code:"parse",message:`${C}: ${U.message}`,file:i.name});continue}D>1&&e.push({severity:"error",code:"gpkg-geometry",message:`${C}: ${D} geometries could not be read.`,file:i.name});const B=xc(T,t.sourceCrs,z,C,e);B&&p.push(...Sl(z,B,S,C,e,{closeRings:t.closeRings,fields:F.filter(U=>!$.includes(U.name))}))}return y.length>0&&e.push({severity:"warning",code:"gpkg-skipped",message:`Not imported (not feature tables): ${y.join(", ")}.`,file:i.name}),{layers:p,issues:e}}function nF(i,t){let e=i.normalize("NFKC").replace(/[^\p{L}\p{N}_]+/gu,"_").replace(/^_+|_+$/g,"");(!e||/^\d/.test(e)||/^(gpkg|sqlite|rtree)_/i.test(e))&&(e=`layer_${e}`);let n=e;for(let s=2;t.has(n.toLowerCase());s++)n=`${e}_${s}`;return t.add(n.toLowerCase()),n}const Lv=i=>`"${i.replace(/"/g,'""')}"`;function II(i,t={},e=[]){var w,L;const n=fi(t.crs??"EPSG:4326"),s=Ic(n,t.precision),r=(w=n.code.match(/^EPSG:(\d+)$/))==null?void 0:w[1];if(!r)throw new Error("GeoPackage export needs an EPSG CRS");const o=s0(n),a=o?1e5+Number(r):Number(r),l=new Date().toISOString().replace(/\.\d{3}Z$/,".000Z"),h=[{rowid:-1,values:["Undefined cartesian SRS",null,"NONE",-1,"undefined","undefined cartesian coordinate reference system"]},{rowid:0,values:["Undefined geographic SRS",null,"NONE",0,"undefined","undefined geographic coordinate reference system"]},{rowid:4326,values:["WGS 84 geodetic",null,"EPSG",4326,Mf(fi("EPSG:4326")),"longitude/latitude coordinates in decimal degrees on the WGS 84 spheroid"]}];a!==4326&&h.push(o?{rowid:a,values:[n.name,null,"NONE",a,Lb(n),`${n.name} with datum shift ${(L=n.definition.match(/\+towgs84=([^ ]+)/))==null?void 0:L[1]}`]}:{rowid:a,values:[n.name,null,"EPSG",a,Mf(n),n.name]});const f=new Set,d=[],p=[],y=[];i.forEach((b,P)=>{const N=nF(b.name,f),S=b.features.filter(J=>J.geometry);S.length<b.features.length&&e.push({severity:"warning",code:"skipped-geometry",message:`${b.name}: ${b.features.length-S.length} features without geometry were not exported.`});const C=(b.fields??tc(S)).filter(J=>!["fid","geom"].includes(J.name.toLowerCase())),T=(b.fields??tc(S)).filter(J=>["fid","geom"].includes(J.name.toLowerCase()));T.length>0&&e.push({severity:"warning",code:"field-renamed",message:`${b.name}: fields named ${T.map(J=>J.name).join(", ")} are reserved and were not exported.`});const I=C.map(J=>{const lt=S.map(ct=>{var gt;return(gt=ct.properties)==null?void 0:gt[J.name]}).filter(ct=>ct!=null);let ft="TEXT";return J.type==="boolean"&<.every(ct=>typeof ct=="boolean")?ft="BOOLEAN":J.type==="number"&<.every(ct=>typeof ct=="number")?ft=lt.every(ct=>Number.isInteger(ct))?"INTEGER":"REAL":J.type==="date"&<.every(ct=>typeof ct=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(ct))&&(ft="DATE"),{name:J.name,type:ft}}),M=new Set(S.map(J=>J.geometry.type)),R=M.size===1?Array.from(M)[0].toUpperCase():M.size===2&&["Point","MultiPoint"].every(J=>M.has(J))?"MULTIPOINT":M.size===2&&["LineString","MultiLineString"].every(J=>M.has(J))?"MULTILINESTRING":M.size===2&&["Polygon","MultiPolygon"].every(J=>M.has(J))?"MULTIPOLYGON":"GEOMETRY",A=S.map(J=>J.id),F=A.every(J=>typeof J=="number"&&Number.isInteger(J)&&J>0)&&new Set(A).size===A.length;!F&&A.some(J=>J!==void 0)&&e.push({severity:"warning",code:"gpkg-fid",message:`${b.name}: feature ids are not positive integers; fid values were renumbered 1..${A.length}.`});let $=1/0,z=1/0,D=-1/0,B=-1/0;const U=J=>R==="MULTIPOINT"&&J.type==="Point"?{type:"MultiPoint",coordinates:[J.coordinates]}:R==="MULTILINESTRING"&&J.type==="LineString"?{type:"MultiLineString",coordinates:[J.coordinates]}:R==="MULTIPOLYGON"&&J.type==="Polygon"?{type:"MultiPolygon",coordinates:[J.coordinates]}:J;let j=!1;const K=S.map((J,lt)=>{const ft=U(bc(J.geometry,n,s)),ct=It=>typeof It[0]=="number"?It.length>2:It.some(ct);ct(ft.coordinates)&&(j=!0);const gt=It=>{typeof It[0]=="number"?($=Math.min($,It[0]),D=Math.max(D,It[0]),z=Math.min(z,It[1]),B=Math.max(B,It[1])):It.forEach(gt)};gt(ft.coordinates);const bt=[null,xI(ft,a),...I.map(It=>{var jt;const Q=(jt=J.properties)==null?void 0:jt[It.name];return Q==null?null:It.type==="BOOLEAN"?Q?1:0:It.type==="INTEGER"||It.type==="REAL"?Q:typeof Q=="object"?JSON.stringify(Q):String(Q)})];return{rowid:F?J.id:lt+1,values:bt}});y.push({name:N,sql:`CREATE TABLE ${Lv(N)} ("fid" INTEGER PRIMARY KEY NOT NULL, "geom" ${R}${I.map(J=>`, ${Lv(J.name)} ${J.type}`).join("")})`,rows:K});const W=Number.isFinite($);d.push({rowid:P+1,values:[N,"features",b.name,"",l,W?$:null,W?z:null,W?D:null,W?B:null,a]}),p.push({rowid:P+1,values:[N,"geom",R,a,j?2:0,0]})});const _=[{name:"gpkg_spatial_ref_sys",sql:"CREATE TABLE gpkg_spatial_ref_sys (srs_name TEXT NOT NULL, srs_id INTEGER PRIMARY KEY, organization TEXT NOT NULL, organization_coordsys_id INTEGER NOT NULL, definition TEXT NOT NULL, description TEXT)",rows:h},{name:"gpkg_contents",sql:"CREATE TABLE gpkg_contents (table_name TEXT NOT NULL PRIMARY KEY, data_type TEXT NOT NULL, identifier TEXT UNIQUE, description TEXT DEFAULT '', last_change DATETIME NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')), min_x DOUBLE, min_y DOUBLE, max_x DOUBLE, max_y DOUBLE, srs_id INTEGER, CONSTRAINT fk_gc_r_srs_id FOREIGN KEY (srs_id) REFERENCES gpkg_spatial_ref_sys(srs_id))",rows:d,autoIndexes:[[0],[2]]},{name:"gpkg_geometry_columns",sql:"CREATE TABLE gpkg_geometry_columns (table_name TEXT NOT NULL, column_name TEXT NOT NULL, geometry_type_name TEXT NOT NULL, srs_id INTEGER NOT NULL, z TINYINT NOT NULL, m TINYINT NOT NULL, CONSTRAINT pk_geom_cols PRIMARY KEY (table_name, column_name), CONSTRAINT uk_gc_table_name UNIQUE (table_name), CONSTRAINT fk_gc_tn FOREIGN KEY (table_name) REFERENCES gpkg_contents(table_name), CONSTRAINT fk_gc_srs FOREIGN KEY (srs_id) REFERENCES gpkg_spatial_ref_sys (srs_id))",rows:p,autoIndexes:[[0,1],[0]]},...y],E=new yI().build(_,{applicationId:_I,userVersion:10300});return{filename:`${t.name??"export"}.gpkg`,mimeType:"application/geopackage+sqlite3",data:E}}const SI=["geojson","json","zip","shp","dbf","prj","cpg","shx","kml","kmz","csv","txt","dxf","gpkg","gpkg-wal"];function Cv(i){const t=Em(i);return t==="gpkg"?"gpkg":t==="gpkg-wal"?"gpkg-wal":t==="geojson"||t==="json"?"geojson":t==="zip"?"shapefile":["shp","dbf","prj","cpg","shx"].includes(t)?"shapefile-part":t==="kml"?"kml":t==="kmz"?"kmz":t==="csv"||t==="txt"?"csv":t==="dxf"?"dxf":null}function MI(i,t={}){var o;const e={layers:[],issues:[]},n=a=>{e.layers.push(...a.layers),e.issues.push(...a.issues)},s=[],r=new Map(i.filter(a=>Cv(a.name)==="gpkg-wal").map(a=>[a.name.slice(0,-4).toLowerCase(),a]));for(const a of i){const l=Cv(a.name);try{switch(l){case"geojson":n(Ab(a,t));break;case"shapefile":n(Lm([a],t));break;case"shapefile-part":s.push(a);break;case"kml":n(eI(a,t));break;case"kmz":n(nI(a,t));break;case"csv":n(lI(a,t));break;case"dxf":n(hI(a,t));break;case"gpkg":n(bI(a,{...t,wal:(o=r.get(a.name.toLowerCase()))==null?void 0:o.data}));break;case"gpkg-wal":i.some(h=>h.name.toLowerCase()===a.name.slice(0,-4).toLowerCase())||e.issues.push({severity:"error",code:"format",message:`${a.name}: import it together with its .gpkg file.`,file:a.name});break;default:e.issues.push({severity:"error",code:"format",message:`${a.name}: unsupported file type.`,file:a.name})}}catch(h){e.issues.push({severity:"error",code:"import-failed",message:`${a.name}: ${h.message}`,file:a.name})}}if(s.length>0)try{n(Lm(s,t))}catch(a){e.issues.push({severity:"error",code:"import-failed",message:a.message})}return e}function iF(i,t){const e=i.normalize("NFKC").trim().replace(/\s+/g,"_").replace(/[^\p{L}\p{N}_-]/gu,"").slice(0,48)||"layer";let n=e;for(let s=2;t.hasLayer(n);s++)n=`${e}_${s}`;return n}function NI(i,t,e=[]){const n=i.getAllLayers().reduce((s,r)=>Math.max(s,r.zIndex),-1);return t.map((s,r)=>{const o=iF(s.name,i),a=new Set;let l=0;const h=s.features.map(d=>{const p=d.id===void 0?void 0:`${typeof d.id}:${d.id}`;if(p===void 0||a.has(p)){p!==void 0&&l++;const{id:y,..._}=d;return _}return a.add(p),d});l>0&&e.push({severity:"warning",code:"duplicate-id",message:`${s.name}: ${l} features had duplicate ids and were given new ids.`});const f=i.addLayer({id:o,name:s.name,type:s.kind,zIndex:n+1+r,sourceCrs:s.sourceCrs,sourceFile:s.sourceFile,fields:s.fields},h.map(d=>d.id===void 0?{...d,id:lf()}:d));return{layerId:f.id,name:s.name,featureCount:f.count,sourceCrs:s.sourceCrs}})}const d0=["geojson","shapefile","gpkg","kml","kmz","csv","dxf"],LI=i=>i.startsWith("_ofs_");function $h(i){return i.getFeatures().map(t=>{const e={};for(const[n,s]of Object.entries(t.properties??{}))LI(n)||(e[n]=s);return{...t,properties:e}})}function Pv(i){var s;const t=(s=i.fields)==null?void 0:s.filter(r=>!LI(r.name)),e=tc($h(i));if(!t)return e;const n=new Set(t.map(r=>r.name));return[...t.filter(r=>e.some(o=>o.name===r.name)),...e.filter(r=>!n.has(r.name))]}class g0{constructor(t){this.dataSource=t}import(t,e={}){const n=MI(t,e),s=[...n.issues],r=NI(this.dataSource,n.layers,s);return r.length>0&&this.dataSource.setActiveLayer(r[r.length-1].layerId),{layers:r,issues:s}}async importFileList(t,e={}){const n=await Promise.all(Array.from(t).map(async s=>({name:s.name,data:await s.arrayBuffer()})));return this.import(n,e)}export(t,e,n={}){const s=[],r=t.map(f=>{const d=this.dataSource.getLayer(f);if(!d)throw new Error(`Layer "${f}" not found`);return d});if(r.length===0)throw new Error("No layers to export");const o=n.name??(r.length===1?r[0].name:"export").replace(/[\\/:*?"<>|]/g,"_"),a={...n,name:o},l=r.flatMap(f=>$h(f));let h;switch(e){case"geojson":h=Ob(l,a);break;case"shapefile":{const f=r.length===1?Pv(r[0]):tc(l);h=Jb(l,f,a,s);break}case"gpkg":h=II(r.map(f=>({name:f.name,features:$h(f),fields:Pv(f)})),a,s);break;case"kml":h=iI(l,a);break;case"kmz":h=sI(l,a);break;case"csv":h=uI(l,a,s);break;case"dxf":{const f=fI(r.map(d=>({name:d.name,features:$h(d)})),a,s);s.push({severity:"warning",code:"dxf-crs",message:`DXF coordinates are in ${f.crs.code} (${f.crs.name}).`}),h=f;break}default:throw new Error(`Unknown export format "${e}". Use ${d0.join(", ")}.`)}return{file:h,issues:s}}static download(t){var o;const e=globalThis;if(typeof e.document>"u"||typeof((o=e.URL)==null?void 0:o.createObjectURL)!="function")throw new Error("Download is only available in a browser");const n=new Blob([t.data],{type:t.mimeType}),s=URL.createObjectURL(n),r=document.createElement("a");r.href=s,r.download=t.filename,document.body.appendChild(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(s),1e3)}}const kg={geojson:"geojson",json:"geojson",shapefile:"shapefile",shp:"shapefile",zip:"shapefile",gpkg:"gpkg",geopackage:"gpkg",kml:"kml",kmz:"kmz",csv:"csv",dxf:"dxf"};function m0(i,t,e=12){const n=new Map;t.forEach(r=>n.set(`${r.severity}:${r.code}`,[...n.get(`${r.severity}:${r.code}`)??[],r]));let s=0;for(const r of n.values()){if(s>=e){i.print(`… ${t.length-s} more issues`,"output");break}const o=r[0],a=r.length>1?` (+${r.length-1} similar)`:"";i.print(`${o.severity==="error"?"✖":"⚠"} ${o.message}${a}`,o.severity==="error"?"error":"output"),s+=1}}function CI(i,t){t.layers.length===0&&i.print("Nothing was imported.","error"),t.layers.forEach(e=>i.print(`Imported "${e.name}" → layer ${e.layerId}: ${e.featureCount} features (source ${e.sourceCrs}).`,"success")),m0(i,t.issues)}function sF(){return new Promise(i=>{const t=document.createElement("input");t.type="file",t.multiple=!0,t.accept=SI.map(e=>`.${e}`).join(","),t.style.display="none",t.addEventListener("change",()=>{i(Array.from(t.files??[])),t.remove()}),t.addEventListener("cancel",()=>{i([]),t.remove()}),document.body.appendChild(t),t.click()})}function PI(i,t,e){const n={name:"import",aliases:["open","load"],description:"Import GeoJSON, Shapefile (.zip), GeoPackage, KML/KMZ, CSV or DXF as new layers",usage:"import [url] [--crs EPSG:32647] [--encoding tis-620] [--close-rings]",isInteractive:!0,schema:{type:"object",properties:{url:{type:"string",description:"File URL (without it, a file picker opens in the browser)"},sourceCrs:{type:"string",description:"CRS when the file has none, e.g. EPSG:32647 (WGS 84 / UTM 47N) or EPSG:24047 (Indian 1975 / UTM 47N)"},encoding:{type:"string",description:"Text encoding for DBF/CSV when not detected: utf-8 or tis-620"},closeRings:{type:"boolean",description:"Close unclosed polygon rings instead of rejecting them"}}},args:{positional:["url"],aliases:{crs:"sourceCrs"}},async execute(r,o){var d;const a=Vt(r),l=a.url,h={sourceCrs:a.sourceCrs,encoding:a.encoding,closeRings:!!a.closeRings};let f;if(l){const p=await fetch(l);if(!p.ok)throw new Error(`Could not download ${l}: HTTP ${p.status}`);const y=decodeURIComponent(new URL(l,((d=globalThis.location)==null?void 0:d.href)??"http://localhost/").pathname.split("/").pop()||"download.geojson");f=t.import([{name:y,data:await p.arrayBuffer()}],h)}else{if(typeof document>"u")throw new Error("Give a URL: import <url>");o.print("Choose files (Shapefile .zip or .shp+.dbf+.prj, GeoPackage, GeoJSON, KML/KMZ, CSV, DXF)…","prompt");const p=await sF();if(p.length===0)return o.print("Import cancelled.","output"),r;f=await t.importFileList(p,h)}return CI(o,f),f.layers.length>0&&(e==null||e(f.layers.map(p=>p.layerId))),r.payload=f,r}},s={name:"export",aliases:["save","download"],description:"Export layers as GeoJSON, Shapefile (.zip), GeoPackage, KML, KMZ, CSV or DXF",usage:"export [layer[,layer2]] <geojson|shapefile|gpkg|kml|kmz|csv|dxf> [--crs EPSG:32647] [--encoding tis-620] [--name file] [--xy]",isInteractive:!1,schema:{type:"object",properties:{layerIds:{type:"array",items:{type:"string"},description:"Layers to export (default: active layer)"},format:{type:"string",enum:Object.keys(kg)},crs:{type:"string",description:"Output CRS, default EPSG:4326 (DXF: the UTM zone of the data)"},encoding:{type:"string",enum:["utf-8","tis-620"]},name:{type:"string",description:"File name without extension"},csvGeometry:{type:"string",enum:["wkt","xy"],description:"CSV: geometry as WKT (default) or x/y columns"}},required:["format"]},args:{positional:["layerIds","format"],switches:{xy:{property:"csvGeometry",value:"xy"}}},async execute(r,o){const a=Vt(r);let l=a.layerIds??[],h=a.format;const f={crs:a.crs,encoding:a.encoding,name:a.name,csvGeometry:a.csvGeometry};!h&&l.length===1&&kg[l[0].toLowerCase()]&&(h=l[0],l=[]);const d=h?kg[h.toLowerCase()]:void 0;if(!d)throw new Error(`Choose a format: ${d0.join(", ")}. Usage: ${s.usage}`);if(l.length===0){const _=i.getActiveLayerId();if(!_)throw new Error("No layer given and no active layer.");l=[_]}const{file:p,issues:y}=t.export(l,d,f);return typeof document<"u"?(g0.download(p),o.print(`Exported ${l.join(", ")} → ${p.filename}`,"success")):o.print(`Exported ${l.join(", ")} → ${p.filename} (${typeof p.data=="string"?p.data.length:p.data.byteLength} bytes)`,"success"),m0(o,y),r.payload=p,r}};return[n,s]}class kI extends jr{constructor(){super();Y(this,"container",null);Y(this,"lines",[]);Y(this,"history",[]);Y(this,"historyIndex",-1);Y(this,"engine",null);Y(this,"pointProvider",null);Y(this,"inputInterceptor",null);Y(this,"typeToFocusHandler",null);Y(this,"typeToFocusCondition",null);Y(this,"waitingInput",!1);Y(this,"currentPromptText",null);Y(this,"pendingResolve",null);Y(this,"pendingReject",null);Y(this,"outputEl",null);Y(this,"promptLabelEl",null);Y(this,"inputEl",null);this.print('OFSObject CAD/GIS Command Engine ready. Type "help" or "?" for commands.',"system")}getLines(){return this.lines}setEngine(e){this.engine=e}setPointProvider(e){this.pointProvider=e}setInputInterceptor(e){this.inputInterceptor=e}enableTypeToFocus(e){this.disableTypeToFocus(),this.typeToFocusCondition=e,this.attachTypeToFocus()}attachTypeToFocus(){const e=this.typeToFocusCondition;!e||this.typeToFocusHandler||typeof document>"u"||(this.typeToFocusHandler=n=>{if(!this.inputEl||n.ctrlKey||n.metaKey||n.altKey||n.key.length!==1)return;const s=n.target,r=s==null?void 0:s.tagName;r==="INPUT"||r==="TEXTAREA"||s!=null&&s.isContentEditable||e()&&this.inputEl.focus()},document.addEventListener("keydown",this.typeToFocusHandler,!0))}disableTypeToFocus(){this.detachTypeToFocus(),this.typeToFocusCondition=null}detachTypeToFocus(){this.typeToFocusHandler&&typeof document<"u"&&document.removeEventListener("keydown",this.typeToFocusHandler,!0),this.typeToFocusHandler=null}mount(e){const n=typeof e=="string"?document.getElementById(e):e;if(!n)throw new Error(`Console container not found: ${e}`);this.container=n,this.container.classList.add("ofs-console-container"),this.container.innerHTML=`
|
|
240
|
+
<div class="ofs-console-card">
|
|
241
|
+
<div class="ofs-console-header">
|
|
242
|
+
<span class="ofs-console-dot red"></span>
|
|
243
|
+
<span class="ofs-console-dot yellow"></span>
|
|
244
|
+
<span class="ofs-console-dot green"></span>
|
|
245
|
+
<span class="ofs-console-title">OFS Command Line</span>
|
|
246
|
+
</div>
|
|
247
|
+
<div class="ofs-console-output"></div>
|
|
248
|
+
<div class="ofs-console-input-row">
|
|
249
|
+
<span class="ofs-console-prompt">Command:</span>
|
|
250
|
+
<input type="text" class="ofs-console-input" placeholder="Type a command (e.g. poly, line, buffer 10, help)..." autocomplete="off" />
|
|
251
|
+
</div>
|
|
252
|
+
</div>
|
|
253
|
+
`,this.outputEl=this.container.querySelector(".ofs-console-output"),this.promptLabelEl=this.container.querySelector(".ofs-console-prompt"),this.inputEl=this.container.querySelector(".ofs-console-input"),this.setupListeners(),this.attachTypeToFocus(),this.renderLines()}unmount(){this.detachTypeToFocus(),this.container&&(this.container.innerHTML="",this.container=null)}focus(){this.inputEl&&this.inputEl.focus()}setInput(e){this.inputEl&&(this.inputEl.value=e,this.inputEl.focus())}print(e,n="output"){const s={kind:n,text:e,time:Date.now()};this.lines.push(s),this.renderLines(),this.emit("console:line",s)}clear(){this.lines=[],this.renderLines(),this.emit("console:cleared",void 0)}requestInput(e){return this.cancelPending(),this.waitingInput=!0,this.currentPromptText=e,this.promptLabelEl&&(this.promptLabelEl.textContent=e),this.inputEl&&(this.inputEl.placeholder="Enter value or press Enter...",this.inputEl.focus()),this.emit("console:prompt",{promptText:e}),new Promise((n,s)=>{this.pendingResolve=n,this.pendingReject=s})}async requestPointOrText(e,n={}){let s=null;const r=this.pointProvider?this.pointProvider.beginPointPick({basePoint:n.basePoint??null},o=>{s=o,this.print(`> ${o[1].toFixed(7)}, ${o[0].toFixed(7)}`,"input"),this.fulfill("")}):null;try{const o=await this.requestInput(e);return s?{point:s}:{text:o.trim()}}finally{r==null||r()}}async requestPoint(e,n={}){var r,o;const s=n.basePoint??null;for(;;){const a=await this.requestPointOrText(e,{basePoint:s});if("point"in a)return a.point;if(!a.text)return null;const l=Sp(a.text,{basePoint:s,cursor:((r=this.pointProvider)==null?void 0:r.getCursorCoordinate())??null,frame:(o=this.pointProvider)==null?void 0:o.inputFrame});if((l==null?void 0:l.kind)==="point")return l.coordinate;this.print((l==null?void 0:l.kind)==="error"?l.message:`Invalid point "${a.text}". Click the map or type lng,lat${s?", @dx,dy, @distance<angle or a distance":""}.`,"error")}}cancel(){this.cancelPending()}getPromptText(){return this.waitingInput?this.currentPromptText:null}isWaitingInput(){return this.waitingInput}fulfill(e){if(!this.pendingResolve)return!1;const n=this.pendingResolve;return this.clearPending(),n(e),!0}cancelPending(){if(this.pendingReject){const e=this.pendingReject;this.clearPending(),e(new Su)}}clearPending(){const e=this.waitingInput;this.pendingResolve=null,this.pendingReject=null,this.waitingInput=!1,this.currentPromptText=null,this.promptLabelEl&&(this.promptLabelEl.textContent="Command:"),this.inputEl&&(this.inputEl.placeholder="Type a command..."),e&&this.emit("console:prompt",{promptText:null})}submit(e){var s;if(this.waitingInput){this.print(`> ${e}`,"input"),this.fulfill(e);return}const n=(s=this.inputInterceptor)==null?void 0:s.call(this,e);if(n!=null&&n.handled){e.trim()&&this.print(`> ${e}`,"input"),n.error?this.print(n.error,"error"):n.message&&this.print(n.message,"output");return}e.trim()&&(this.history.push(e),this.historyIndex=this.history.length,this.print(`Command: ${e}`,"input"),this.engine&&this.engine.run([e]).catch(r=>{r instanceof Su||this.print(r.message,"error")}))}cancelCommand(){var n;if(!this.engine)return;const e=((n=this.engine.getContext())==null?void 0:n.status)==="running"||this.waitingInput;this.engine.cancel(),e&&this.print("*Cancel*","system")}setupListeners(){this.inputEl&&this.inputEl.addEventListener("keydown",e=>{if(e.key==="Enter"){const n=this.inputEl.value;this.inputEl.value="",this.submit(n)}else e.key==="Escape"?this.cancelCommand():e.key==="ArrowUp"?(e.preventDefault(),this.history.length>0&&this.historyIndex>0&&(this.historyIndex--,this.inputEl.value=this.history[this.historyIndex])):e.key==="ArrowDown"?(e.preventDefault(),this.historyIndex<this.history.length-1?(this.historyIndex++,this.inputEl.value=this.history[this.historyIndex]):(this.historyIndex=this.history.length,this.inputEl.value="")):e.key==="Tab"&&(e.preventDefault(),this.handleTabAutocomplete())})}handleTabAutocomplete(){if(!this.inputEl||!this.engine)return;const e=this.inputEl.value,n=e.search(/\s/),s=this.engine.registry;if(n===-1){this.completeInto(e.trim().toLowerCase(),s.suggest(e.trim()),"");return}const r=s.get(e.slice(0,n));if(!r)return;const o=e.slice(0,e.lastIndexOf(" ")+1),a=e.slice(o.length),l=Qp(r).map(h=>`--${h}`);if(a.startsWith("--")){this.completeInto(a,l.filter(h=>h.startsWith(a)),o);return}Ju(r).slice(1).forEach(h=>this.print(h,"output"))}completeInto(e,n,s){if(!this.inputEl||n.length===0)return;if(n.length===1){this.inputEl.value=`${s}${n[0]} `;return}let r=n[0];for(const o of n)for(;!o.startsWith(r);)r=r.slice(0,-1);r.length>e.length&&(this.inputEl.value=`${s}${r}`),this.print(`Autocomplete: ${n.join(", ")}`,"output")}renderLines(){this.outputEl&&(this.outputEl.innerHTML=this.lines.map(e=>`<div class="ofs-line ofs-line-${e.kind}">${this.escapeHtml(e.text)}</div>`).join(""),this.outputEl.scrollTop=this.outputEl.scrollHeight)}escapeHtml(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}}const rF={vertex:"Endpoint",intersection:"Intersection",midpoint:"Midpoint",center:"Center",perpendicular:"Perpendicular",edge:"Nearest"};function TI(i){const t=[];return i.distanceMeters!==null&&i.distanceMeters!==void 0&&t.push(`${i.distanceMeters.toFixed(3)} m`),i.angle!==null&&i.angle!==void 0&&t.push(`∠ ${i.angle.toFixed(2)}°${i.convention==="cad"?" (CAD)":""}`),i.snapType?t.push(`[${rF[i.snapType]}]`):i.constraint&&t.push(`[${i.constraint.toUpperCase()}]`),t.join(" ")}class RI{constructor(t,e){Y(this,"drawTools");Y(this,"consoleWidget");Y(this,"container",null);Y(this,"root",null);Y(this,"promptEl",null);Y(this,"labelEl",null);Y(this,"inputEl",null);Y(this,"unsubscribers",[]);Y(this,"keyHandler",null);Y(this,"state",{});Y(this,"lastCoordinate",null);Y(this,"offset",{x:18,y:18});this.drawTools=t,this.consoleWidget=e}mount(t){if(typeof document>"u")return;const e=typeof t=="string"?document.getElementById(t):t;if(!e)throw new Error(`Dynamic input container not found: ${t}`);this.unmount(),this.container=e,getComputedStyle(e).position==="static"&&(e.style.position="relative");const n=document.createElement("div");n.className="ofs-dynamic-input",Object.assign(n.style,{position:"absolute",zIndex:"50",display:"none",pointerEvents:"none",background:"rgba(15, 23, 42, 0.92)",color:"#e2e8f0",border:"1px solid rgba(148, 163, 184, 0.35)",borderRadius:"6px",padding:"4px 6px",font:"12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace",whiteSpace:"nowrap",boxShadow:"0 4px 12px rgba(0,0,0,0.3)"}),this.promptEl=document.createElement("div"),Object.assign(this.promptEl.style,{color:"#fbbf24",fontSize:"11px"}),this.labelEl=document.createElement("div"),this.inputEl=document.createElement("input"),this.inputEl.type="text",this.inputEl.autocomplete="off",this.inputEl.placeholder="@dx,dy @dist<angle dist",Object.assign(this.inputEl.style,{display:"none",marginTop:"3px",width:"180px",pointerEvents:"auto",background:"#0f172a",color:"#f8fafc",border:"1px solid #3b82f6",borderRadius:"4px",padding:"2px 4px",font:"inherit",outline:"none"}),n.append(this.promptEl,this.labelEl,this.inputEl),e.appendChild(n),this.root=n,this.bindEvents()}unmount(){var t;this.unsubscribers.forEach(e=>e()),this.unsubscribers=[],this.keyHandler&&(document.removeEventListener("keydown",this.keyHandler,!0),this.keyHandler=null),(t=this.root)==null||t.remove(),this.root=null,this.container=null}isActive(){return this.drawTools.getIsDrawing()||this.drawTools.isPickingPoint()||this.consoleWidget.isWaitingInput()}bindEvents(){this.unsubscribers.push(this.drawTools.on("draw:move",({coordinate:e,snapResult:n})=>{this.lastCoordinate=e,this.state={...this.state,snapType:(n==null?void 0:n.type)??null},this.drawTools.getReferencePoint()||(this.state.distanceMeters=null,this.state.angle=null,this.state.constraint=null),this.render()}),this.drawTools.on("draw:measure",({distanceMeters:e,angle:n,constraint:s})=>{this.state={...this.state,distanceMeters:e,angle:n,constraint:s,convention:this.drawTools.inputFrame.convention},this.render()}),this.drawTools.on("draw:mode-change",()=>this.render()),this.drawTools.on("draw:complete",()=>this.hideInput()),this.drawTools.on("draw:cancel",()=>this.hideInput()));const t=this.inputEl;t.addEventListener("keydown",e=>{if(e.key==="Enter"){e.preventDefault();const n=t.value;this.hideInput(),this.consoleWidget.submit(n)}else e.key==="Escape"&&(e.preventDefault(),t.value?this.hideInput():(this.hideInput(),this.consoleWidget.cancelCommand(),this.drawTools.cancel()));e.stopPropagation()}),this.keyHandler=e=>{if(!this.inputEl||e.ctrlKey||e.metaKey||e.altKey||e.key.length!==1)return;const n=e.target,s=n==null?void 0:n.tagName;s==="INPUT"||s==="TEXTAREA"||n!=null&&n.isContentEditable||this.isActive()&&(this.inputEl.style.display="block",this.inputEl.focus())},document.addEventListener("keydown",this.keyHandler,!0)}hideInput(){this.inputEl&&(this.inputEl.value="",this.inputEl.style.display="none",this.inputEl.blur(),this.render())}render(){var o;if(!this.root||!this.labelEl||!this.promptEl)return;const t=this.isActive(),e=TI(this.state),n=this.consoleWidget.getPromptText();if(!t||!this.lastCoordinate||!e&&!n&&((o=this.inputEl)==null?void 0:o.style.display)==="none"){this.root.style.display="none";return}let s=null;try{s=this.drawTools.getMapAdapter().getRawMap()}catch{s=null}if(!s||typeof s.project!="function")return;const r=s.project(this.lastCoordinate);this.promptEl.textContent=n??"",this.promptEl.style.display=n?"block":"none",this.labelEl.textContent=e,this.labelEl.style.display=e?"block":"none",this.root.style.left=`${r.x+this.offset.x}px`,this.root.style.top=`${r.y+this.offset.y}px`,this.root.style.display="block"}}const kv="ofs-object.macros";class AI{constructor(t){Y(this,"macros",new Map);Y(this,"recording",null);Y(this,"unsubscribe",null);this.engine=t,this.load()}load(){try{const t=typeof localStorage<"u"?localStorage.getItem(kv):null;if(!t)return;const e=JSON.parse(t);Array.isArray(e)&&e.forEach(n=>(n==null?void 0:n.name)&&this.macros.set(n.name,n))}catch{}}persist(){try{if(typeof localStorage>"u")return;localStorage.setItem(kv,JSON.stringify([...this.macros.values()]))}catch{}}isRecording(){return this.recording!==null}recordingName(){var t;return((t=this.recording)==null?void 0:t.name)??null}recordedCount(){var t;return((t=this.recording)==null?void 0:t.commands.length)??0}startRecording(t){const e=t.trim();if(!e)throw new Error("Give the macro a name");if(this.recording)throw new Error(`Already recording "${this.recording.name}". Stop it first.`);this.recording={name:e,commands:[]},this.unsubscribe=this.engine.on("workflow:step",({context:n,commandName:s})=>{if(!this.recording||s==="macro")return;const r=n.commands[n.currentIndex];typeof r=="string"&&r.trim()&&this.recording.commands.push(r.trim())})}stopRecording(){var s;if(!this.recording)throw new Error("No macro is being recorded");const{name:t,commands:e}=this.recording;if((s=this.unsubscribe)==null||s.call(this),this.unsubscribe=null,this.recording=null,e.length===0)return null;const n={name:t,commands:e,createdAt:Date.now()};return this.macros.set(t,n),this.persist(),n}cancelRecording(){var t;(t=this.unsubscribe)==null||t.call(this),this.unsubscribe=null,this.recording=null}list(){return[...this.macros.values()].sort((t,e)=>t.name.localeCompare(e.name))}get(t){return this.macros.get(t.trim())}save(t){if(!t.name.trim())throw new Error("Give the macro a name");if(!t.commands.length)throw new Error("A macro needs at least one command");const e={...t,name:t.name.trim(),createdAt:t.createdAt||Date.now()};return this.macros.set(e.name,e),this.persist(),e}remove(t){const e=this.macros.delete(t.trim());return e&&this.persist(),e}export(){return this.list()}import(t,e=!1){e&&this.macros.clear();let n=0;return t.forEach(s=>{!(s!=null&&s.name)||!Array.isArray(s.commands)||s.commands.length===0||(this.macros.set(s.name,{...s,createdAt:s.createdAt||Date.now()}),n+=1)}),this.persist(),n}}function OI(i){return i.getAll().map(t=>({type:"function",function:{name:t.name,description:[t.description,t.usage?`Usage: ${t.usage}`:"",t.aliases.length?`Also known as: ${t.aliases.join(", ")}`:""].filter(Boolean).join(". "),parameters:t.schema??{type:"object",properties:{args:{type:"string",description:`Arguments exactly as they would be typed, e.g. "${t.usage??t.name}"`}}}}}))}function oF(i){const[t,e,n,s]=i,r=(e+s)/2*(Math.PI/180);return{width:(n-t)*111320*Math.cos(r),height:(s-e)*110540}}class FI{static buildMapContext(t,e){const n=t.getAllLayers(),s=t.getActiveLayerId(),r=t.getBoundingBox();let o=`CURRENT MAP STATE:
|
|
254
|
+
`;o+=`- Active Layer: ${s||"None"}
|
|
255
|
+
`,o+=`- Bounding Box: [${r.map(l=>l.toFixed(6)).join(", ")}]
|
|
256
|
+
`,o+=`- Loaded Layers (${n.length}):
|
|
257
|
+
`,n.forEach(l=>{const h=l.getPropertyFields().map(d=>`${d.name} (${d.type})`).join(", "),f=t.getSelectedFeatureIds(l.id).length;if(o+=` * [${l.id}] "${l.name}" (${l.type}) - ${l.count} features${f?`, ${f} selected`:""}
|
|
258
|
+
`,l.count>0){const d=l.getBoundingBox(),p=oF(d);o+=` Extent: [${d.map(y=>y.toFixed(6)).join(", ")}] (about ${p.width.toFixed(0)} x ${p.height.toFixed(0)} m)
|
|
259
|
+
`}h&&(o+=` Fields: ${h}
|
|
260
|
+
`)}),o+=`
|
|
261
|
+
INSTRUCTIONS:
|
|
262
|
+
You are an intelligent GIS assistant for OFSObject (Map Tools).
|
|
263
|
+
You can inspect the map state, style thematic maps, calculate areas and distances, draw geometries, and perform buffer/union operations.
|
|
264
|
+
Coordinates are [longitude, latitude] everywhere, longitude first, and every distance and tolerance is in meters.
|
|
265
|
+
Read shapes before you reason about them: "geometry" returns features as GeoJSON with area, length and bounding box
|
|
266
|
+
(layer, --id, --selected, --limit, --bbox-only). Layer summaries above give extents only, not shapes.
|
|
267
|
+
Do not compute positions in degrees yourself: spacing and offsets in degrees change with latitude. Use the commands
|
|
268
|
+
that take meters ("buffer", "offset", "array", "move") and let them do the projection.
|
|
269
|
+
"draw_point" accepts many coordinates in one call and places them as a single undo step; "draw_line" and
|
|
270
|
+
"draw_polygon" take a coordinate array.
|
|
271
|
+
Layouts: "grid" fills a polygon with points a given number of meters apart (pattern square or triangular,
|
|
272
|
+
--rotate, --inset, --into), and "network" connects points back to a source ("rows" joins aligned points into
|
|
273
|
+
runs and links those with a trunk; "tree" is the shortest spanning tree) and reports the length of every line.
|
|
274
|
+
Both work in meters on the ground, so use them instead of placing regular points yourself.
|
|
275
|
+
For layer styling use the "symbology" tool (renderer single | categorized | graduated, field, method, classes,
|
|
276
|
+
ramp, mode color|size, symbol {fill, line, marker}, classVisibility); list ramp names with "symbology ramps".
|
|
277
|
+
Files: "import" (url, sourceCrs for files without CRS, encoding) and "export" (layerIds, format geojson|shapefile|gpkg|kml|kmz|csv|dxf, crs, encoding tis-620|utf-8).
|
|
278
|
+
Data quality: "topology" (action check with layerId and tolerances in meters, then list | zoom issueId | fix issueIds with
|
|
279
|
+
removeFrom for overlaps / mergeInto for gaps). Never fix without the user asking; report what each fix changed.
|
|
280
|
+
Attributes: "fields" (schema), "table" (rows with filter/sort), "calc" (field calculator, expressions like
|
|
281
|
+
round($area / 1600, 2) or rai_ngan_wa()), "select" (by expression), "selectloc" (spatial relation to another
|
|
282
|
+
layer), "stats" (field statistics). Areas are in m2; 1 rai = 1600 m2 = 4 ngan = 400 square wa.
|
|
283
|
+
Map output: "label" (labels from a field or expression, size/color/halo/placement/zoom range) and "measure"
|
|
284
|
+
(distance, area, angle; give coordinates to measure without clicking, or "measure feature" for the selection).
|
|
285
|
+
Call tools with appropriate parameters to fulfill the user's intent.`;const a=e==null?void 0:e.trim();return a&&(o+=`
|
|
286
|
+
|
|
287
|
+
APPLICATION INSTRUCTIONS:
|
|
288
|
+
${a}`),o}}class $I{constructor(t,e){Y(this,"engine");Y(this,"dataSource");Y(this,"instructions",null);this.engine=t,this.dataSource=e}setInstructions(t){this.instructions=t!=null&&t.trim()?t:null}getInstructions(){return this.instructions}getToolDeclarations(){return OI(this.engine.registry)}getSystemContextPrompt(){return FI.buildMapContext(this.dataSource,this.instructions??void 0)}snapshot(){const t={};return this.dataSource.getAllLayers().forEach(e=>{t[e.id]=e.count}),{activeLayerId:this.dataSource.getActiveLayerId(),totalLayers:this.dataSource.getAllLayers().length,layerFeatureCounts:t}}async executeToolCall(t,e={}){const n=this.engine.registry.get(t);if(!n){const o=Uo(t,this.engine.registry.getNames());return{success:!1,tool:t,summary:`There is no tool called "${t}"${o?`. Did you mean "${o}"?`:""}`,error:`Unknown tool "${t}"`}}const s=typeof e.args=="string"?e.args:null;let r=n.name;if(s!==null)r+=s?` ${s}`:"";else if(Object.keys(e).length>0){const o=e0(n.schema,e);if(!o.ok)return{success:!1,tool:n.name,summary:`"${n.name}" was not run: ${o.issues.join(" · ")}`,error:new Ba(n.name,o.issues,n.usage).message,help:Ju(n)};const a=pb(n,o.value);a&&(r+=` ${a}`)}try{const o=await this.engine.run([r],e);return{success:!0,tool:n.name,summary:`Successfully executed "${n.name}".`,data:o.payload,mapSnapshot:this.snapshot()}}catch(o){const a=(o==null?void 0:o.message)??String(o);return{success:!1,tool:n.name,summary:`Failed to execute "${n.name}": ${a}`,error:a,help:o instanceof Ba?Ju(n):void 0,mapSnapshot:this.snapshot()}}}}class Nf{constructor(){Nf.constructor_.apply(this,arguments)}static constructor_(){this._geometryFactory=new ze,this._geomGraph=null,this._disconnectedRingcoord=null;const t=arguments[0];this._geomGraph=t}static findDifferentPoint(t,e){for(let n=0;n<t.length;n++)if(!t[n].equals(e))return t[n];return null}visitInteriorRing(t,e){if(t.isEmpty())return null;const n=t.getCoordinates(),s=n[0],r=Nf.findDifferentPoint(n,s),o=e.findEdgeInSameDirection(s,r),a=e.findEdgeEnd(o);let l=null;a.getLabel().getLocation(0,yt.RIGHT)===q.INTERIOR?l=a:a.getSym().getLabel().getLocation(0,yt.RIGHT)===q.INTERIOR&&(l=a.getSym()),Yt.isTrue(l!==null,"unable to find dirEdge with Interior on RHS"),this.visitLinkedDirectedEdges(l)}visitShellInteriors(t,e){if(t instanceof Te){const n=t;this.visitInteriorRing(n.getExteriorRing(),e)}if(t instanceof hi){const n=t;for(let s=0;s<n.getNumGeometries();s++){const r=n.getGeometryN(s);this.visitInteriorRing(r.getExteriorRing(),e)}}}getCoordinate(){return this._disconnectedRingcoord}setInteriorEdgesInResult(t){for(let e=t.getEdgeEnds().iterator();e.hasNext();){const n=e.next();n.getLabel().getLocation(0,yt.RIGHT)===q.INTERIOR&&n.setInResult(!0)}}visitLinkedDirectedEdges(t){const e=t;let n=t;do Yt.isTrue(n!==null,"found null Directed Edge"),n.setVisited(!0),n=n.getNext();while(n!==e)}buildEdgeRings(t){const e=new vt;for(let n=t.iterator();n.hasNext();){const s=n.next();if(s.isInResult()&&s.getEdgeRing()===null){const r=new Hf(s,this._geometryFactory);r.linkDirectedEdgesForMinimalEdgeRings();const o=r.buildMinimalRings();e.addAll(o)}}return e}hasUnvisitedShellEdge(t){for(let e=0;e<t.size();e++){const n=t.get(e);if(n.isHole())continue;const s=n.getEdges();let r=s.get(0);if(r.getLabel().getLocation(0,yt.RIGHT)===q.INTERIOR){for(let o=0;o<s.size();o++)if(r=s.get(o),!r.isVisited())return this._disconnectedRingcoord=r.getCoordinate(),!0}}return!1}isInteriorsConnected(){const t=new vt;this._geomGraph.computeSplitEdges(t);const e=new qo(new gp);e.addEdges(t),this.setInteriorEdgesInResult(e),e.linkResultDirectedEdges();const n=this.buildEdgeRings(e.getEdgeEnds());return this.visitShellInteriors(this._geomGraph.getGeometry(),e),!this.hasUnvisitedShellEdge(n)}}class En{isInBoundary(t){}}class DI{isInBoundary(t){return t%2===1}get interfaces_(){return[En]}}class GI{isInBoundary(t){return t>0}get interfaces_(){return[En]}}class BI{isInBoundary(t){return t>1}get interfaces_(){return[En]}}class qI{isInBoundary(t){return t===1}get interfaces_(){return[En]}}En.Mod2BoundaryNodeRule=DI;En.EndPointBoundaryNodeRule=GI;En.MultiValentEndPointBoundaryNodeRule=BI;En.MonoValentEndPointBoundaryNodeRule=qI;En.MOD2_BOUNDARY_RULE=new DI;En.ENDPOINT_BOUNDARY_RULE=new GI;En.MULTIVALENT_ENDPOINT_BOUNDARY_RULE=new BI;En.MONOVALENT_ENDPOINT_BOUNDARY_RULE=new qI;En.OGC_SFS_BOUNDARY_RULE=En.MOD2_BOUNDARY_RULE;class Yo{constructor(){Yo.constructor_.apply(this,arguments)}static constructor_(){if(this._boundaryRule=En.OGC_SFS_BOUNDARY_RULE,this._isIn=null,this._numBoundaries=null,arguments.length!==0){if(arguments.length===1){const t=arguments[0];if(t===null)throw new Zt("Rule must be non-null");this._boundaryRule=t}}}locateInPolygonRing(t,e){return e.getEnvelopeInternal().intersects(t)?ts.locateInRing(t,e.getCoordinates()):q.EXTERIOR}intersects(t,e){return this.locate(t,e)!==q.EXTERIOR}updateLocationInfo(t){t===q.INTERIOR&&(this._isIn=!0),t===q.BOUNDARY&&this._numBoundaries++}computeLocation(t,e){if(e instanceof Ge&&this.updateLocationInfo(this.locateOnPoint(t,e)),e instanceof ce)this.updateLocationInfo(this.locateOnLineString(t,e));else if(e instanceof Te)this.updateLocationInfo(this.locateInPolygon(t,e));else if(e instanceof ns){const n=e;for(let s=0;s<n.getNumGeometries();s++){const r=n.getGeometryN(s);this.updateLocationInfo(this.locateOnLineString(t,r))}}else if(e instanceof hi){const n=e;for(let s=0;s<n.getNumGeometries();s++){const r=n.getGeometryN(s);this.updateLocationInfo(this.locateInPolygon(t,r))}}else if(e instanceof ye){const n=new Aa(e);for(;n.hasNext();){const s=n.next();s!==e&&this.computeLocation(t,s)}}}locateOnPoint(t,e){return e.getCoordinate().equals2D(t)?q.INTERIOR:q.EXTERIOR}locateOnLineString(t,e){if(!e.getEnvelopeInternal().intersects(t))return q.EXTERIOR;const n=e.getCoordinateSequence();return!e.isClosed()&&(t.equals(n.getCoordinate(0))||t.equals(n.getCoordinate(n.size()-1)))?q.BOUNDARY:ts.isOnLine(t,n)?q.INTERIOR:q.EXTERIOR}locateInPolygon(t,e){if(e.isEmpty())return q.EXTERIOR;const n=e.getExteriorRing(),s=this.locateInPolygonRing(t,n);if(s===q.EXTERIOR)return q.EXTERIOR;if(s===q.BOUNDARY)return q.BOUNDARY;for(let r=0;r<e.getNumInteriorRing();r++){const o=e.getInteriorRingN(r),a=this.locateInPolygonRing(t,o);if(a===q.INTERIOR)return q.EXTERIOR;if(a===q.BOUNDARY)return q.BOUNDARY}return q.INTERIOR}locate(t,e){return e.isEmpty()?q.EXTERIOR:e instanceof ce?this.locateOnLineString(t,e):e instanceof Te?this.locateInPolygon(t,e):(this._isIn=!1,this._numBoundaries=0,this.computeLocation(t,e),this._boundaryRule.isInBoundary(this._numBoundaries)?q.BOUNDARY:this._numBoundaries>0||this._isIn?q.INTERIOR:q.EXTERIOR)}}class p0{constructor(){p0.constructor_.apply(this,arguments)}static constructor_(){this.mce=null,this.chainIndex=null;const t=arguments[0],e=arguments[1];this.mce=t,this.chainIndex=e}computeIntersections(t,e){this.mce.computeIntersectsForChain(this.chainIndex,t.mce,t.chainIndex,e)}}class qs{constructor(){qs.constructor_.apply(this,arguments)}static constructor_(){if(this._label=null,this._xValue=null,this._eventType=null,this._insertEvent=null,this._deleteEventIndex=null,this._obj=null,arguments.length===2){const t=arguments[0],e=arguments[1];this._eventType=qs.DELETE,this._xValue=t,this._insertEvent=e}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];this._eventType=qs.INSERT,this._label=t,this._xValue=e,this._obj=n}}isDelete(){return this._eventType===qs.DELETE}setDeleteEventIndex(t){this._deleteEventIndex=t}getObject(){return this._obj}compareTo(t){const e=t;return this._xValue<e._xValue?-1:this._xValue>e._xValue?1:this._eventType<e._eventType?-1:this._eventType>e._eventType?1:0}getInsertEvent(){return this._insertEvent}isInsert(){return this._eventType===qs.INSERT}isSameLabel(t){return this._label===null?!1:this._label===t._label}getDeleteEventIndex(){return this._deleteEventIndex}get interfaces_(){return[gi]}}qs.INSERT=1;qs.DELETE=2;class aF{}class Go{constructor(){Go.constructor_.apply(this,arguments)}static constructor_(){this._hasIntersection=!1,this._hasProper=!1,this._hasProperInterior=!1,this._properIntersectionPoint=null,this._li=null,this._includeProper=null,this._recordIsolated=null,this._isSelfIntersection=null,this._numIntersections=0,this.numTests=0,this._bdyNodes=null,this._isDone=!1,this._isDoneWhenProperInt=!1;const t=arguments[0],e=arguments[1],n=arguments[2];this._li=t,this._includeProper=e,this._recordIsolated=n}static isAdjacentSegments(t,e){return Math.abs(t-e)===1}isTrivialIntersection(t,e,n,s){if(t===n&&this._li.getIntersectionNum()===1){if(Go.isAdjacentSegments(e,s))return!0;if(t.isClosed()){const r=t.getNumPoints()-1;if(e===0&&s===r||s===0&&e===r)return!0}}return!1}getProperIntersectionPoint(){return this._properIntersectionPoint}setIsDoneIfProperInt(t){this._isDoneWhenProperInt=t}hasProperInteriorIntersection(){return this._hasProperInterior}isBoundaryPointInternal(t,e){for(let n=e.iterator();n.hasNext();){const r=n.next().getCoordinate();if(t.isIntersection(r))return!0}return!1}hasProperIntersection(){return this._hasProper}hasIntersection(){return this._hasIntersection}isDone(){return this._isDone}isBoundaryPoint(t,e){return e===null?!1:!!(this.isBoundaryPointInternal(t,e[0])||this.isBoundaryPointInternal(t,e[1]))}setBoundaryNodes(t,e){this._bdyNodes=new Array(2).fill(null),this._bdyNodes[0]=t,this._bdyNodes[1]=e}addIntersections(t,e,n,s){if(t===n&&e===s)return null;this.numTests++;const r=t.getCoordinates()[e],o=t.getCoordinates()[e+1],a=n.getCoordinates()[s],l=n.getCoordinates()[s+1];this._li.computeIntersection(r,o,a,l),this._li.hasIntersection()&&(this._recordIsolated&&(t.setIsolated(!1),n.setIsolated(!1)),this._numIntersections++,this.isTrivialIntersection(t,e,n,s)||(this._hasIntersection=!0,(this._includeProper||!this._li.isProper())&&(t.addIntersections(this._li,e,0),n.addIntersections(this._li,s,1)),this._li.isProper()&&(this._properIntersectionPoint=this._li.getIntersection(0).copy(),this._hasProper=!0,this._isDoneWhenProperInt&&(this._isDone=!0),this.isBoundaryPoint(this._li,this._bdyNodes)||(this._hasProperInterior=!0))))}}class y0 extends aF{constructor(){super(),y0.constructor_.apply(this,arguments)}static constructor_(){this.events=new vt,this.nOverlaps=null}prepareEvents(){_r.sort(this.events);for(let t=0;t<this.events.size();t++){const e=this.events.get(t);e.isDelete()&&e.getInsertEvent().setDeleteEventIndex(t)}}computeIntersections(){if(arguments.length===1){const t=arguments[0];this.nOverlaps=0,this.prepareEvents();for(let e=0;e<this.events.size();e++){const n=this.events.get(e);if(n.isInsert()&&this.processOverlaps(e,n.getDeleteEventIndex(),n,t),t.isDone())break}}else if(arguments.length===3){if(arguments[2]instanceof Go&&Ot(arguments[0],Pi)&&Ot(arguments[1],Pi)){const t=arguments[0],e=arguments[1],n=arguments[2];this.addEdges(t,t),this.addEdges(e,e),this.computeIntersections(n)}else if(typeof arguments[2]=="boolean"&&Ot(arguments[0],Pi)&&arguments[1]instanceof Go){const t=arguments[0],e=arguments[1];arguments[2]?this.addEdges(t,null):this.addEdges(t),this.computeIntersections(e)}}}addEdge(t,e){const n=t.getMonotoneChainEdge(),s=n.getStartIndexes();for(let r=0;r<s.length-1;r++){const o=new p0(n,r),a=new qs(e,n.getMinX(r),o);this.events.add(a),this.events.add(new qs(n.getMaxX(r),a))}}processOverlaps(t,e,n,s){const r=n.getObject();for(let o=t;o<e;o++){const a=this.events.get(o);if(a.isInsert()){const l=a.getObject();n.isSameLabel(a)||(r.computeIntersections(l,s),this.nOverlaps++)}}}addEdges(){if(arguments.length===1){const t=arguments[0];for(let e=t.iterator();e.hasNext();){const n=e.next();this.addEdge(n,n)}}else if(arguments.length===2){const t=arguments[0],e=arguments[1];for(let n=t.iterator();n.hasNext();){const s=n.next();this.addEdge(s,e)}}}}class Nl{constructor(){Nl.constructor_.apply(this,arguments)}static constructor_(){this._min=Rt.POSITIVE_INFINITY,this._max=Rt.NEGATIVE_INFINITY}getMin(){return this._min}intersects(t,e){return!(this._min>e||this._max<t)}getMax(){return this._max}toString(){return Js.toLineString(new Z(this._min,0),new Z(this._max,0))}}class lF{compare(t,e){const n=t,s=e,r=(n._min+n._max)/2,o=(s._min+s._max)/2;return r<o?-1:r>o?1:0}get interfaces_(){return[Kr]}}Nl.NodeComparator=lF;class _0 extends Nl{constructor(){super(),_0.constructor_.apply(this,arguments)}static constructor_(){this._item=null;const t=arguments[0],e=arguments[1],n=arguments[2];this._min=t,this._max=e,this._item=n}query(t,e,n){if(!this.intersects(t,e))return null;n.visitItem(this._item)}}class v0 extends Nl{constructor(){super(),v0.constructor_.apply(this,arguments)}static constructor_(){this._node1=null,this._node2=null;const t=arguments[0],e=arguments[1];this._node1=t,this._node2=e,this.buildExtent(this._node1,this._node2)}buildExtent(t,e){this._min=Math.min(t._min,e._min),this._max=Math.max(t._max,e._max)}query(t,e,n){if(!this.intersects(t,e))return null;this._node1!==null&&this._node1.query(t,e,n),this._node2!==null&&this._node2.query(t,e,n)}}class E0{constructor(){E0.constructor_.apply(this,arguments)}static constructor_(){this._leaves=new vt,this._root=null,this._level=0}buildTree(){_r.sort(this._leaves,new Nl.NodeComparator);let t=this._leaves,e=null,n=new vt;for(;;){if(this.buildLevel(t,n),n.size()===1)return n.get(0);e=t,t=n,n=e}}insert(t,e,n){if(this._root!==null)throw new IllegalStateException("Index cannot be added to once it has been queried");this._leaves.add(new _0(t,e,n))}query(t,e,n){if(this.init(),this._root===null)return null;this._root.query(t,e,n)}buildRoot(){if(this._root!==null)return null;this._root=this.buildTree()}printNode(t){ci.out.println(Js.toLineString(new Z(t._min,this._level),new Z(t._max,this._level)))}init(){if(this._root!==null||this._leaves.size()===0)return null;this.buildRoot()}buildLevel(t,e){this._level++,e.clear();for(let n=0;n<t.size();n+=2){const s=t.get(n);if((n+1<t.size()?t.get(n):null)===null)e.add(s);else{const o=new v0(t.get(n),t.get(n+1));e.add(o)}}}}class Vn{constructor(){Vn.constructor_.apply(this,arguments)}static constructor_(){if(this._lines=null,this._isForcedToLineString=!1,arguments.length===1){const t=arguments[0];this._lines=t}else if(arguments.length===2){const t=arguments[0],e=arguments[1];this._lines=t,this._isForcedToLineString=e}}static getGeometry(){if(arguments.length===1){const t=arguments[0];return t.getFactory().buildGeometry(Vn.getLines(t))}else if(arguments.length===2){const t=arguments[0],e=arguments[1];return t.getFactory().buildGeometry(Vn.getLines(t,e))}}static getLines(){if(arguments.length===1){const t=arguments[0];return Vn.getLines(t,!1)}else if(arguments.length===2){if(Ot(arguments[0],sn)&&Ot(arguments[1],sn)){const t=arguments[0],e=arguments[1];for(let n=t.iterator();n.hasNext();){const s=n.next();Vn.getLines(s,e)}return e}else if(arguments[0]instanceof dt&&typeof arguments[1]=="boolean"){const t=arguments[0],e=arguments[1],n=new vt;return t.apply(new Vn(n,e)),n}else if(arguments[0]instanceof dt&&Ot(arguments[1],sn)){const t=arguments[0],e=arguments[1];return t instanceof ce?e.add(t):t.apply(new Vn(e)),e}}else if(arguments.length===3){if(typeof arguments[2]=="boolean"&&Ot(arguments[0],sn)&&Ot(arguments[1],sn)){const t=arguments[0],e=arguments[1],n=arguments[2];for(let s=t.iterator();s.hasNext();){const r=s.next();Vn.getLines(r,e,n)}return e}else if(typeof arguments[2]=="boolean"&&arguments[0]instanceof dt&&Ot(arguments[1],sn)){const t=arguments[0],e=arguments[1],n=arguments[2];return t.apply(new Vn(e,n)),e}}}filter(t){if(this._isForcedToLineString&&t instanceof fn){const e=t.getFactory().createLineString(t.getCoordinateSequence());return this._lines.add(e),null}t instanceof ce&&this._lines.add(t)}setForceToLineString(t){this._isForcedToLineString=t}get interfaces_(){return[pl]}}class w0{constructor(){w0.constructor_.apply(this,arguments)}static constructor_(){this._items=new vt}visitItem(t){this._items.add(t)}getItems(){return this._items}get interfaces_(){return[Kf]}}class Ll{constructor(){Ll.constructor_.apply(this,arguments)}static constructor_(){this._geom=null,this._index=null;const t=arguments[0];if(!(Ot(t,Jr)||t instanceof fn))throw new Zt("Argument must be Polygonal or LinearRing");this._geom=t}locate(t){this._index===null&&(this._index=new _d(this._geom),this._geom=null);const e=new Ra(t),n=new yd(e);return this._index.query(t.y,t.y,n),e.getLocation()}get interfaces_(){return[Fw]}}class yd{constructor(){yd.constructor_.apply(this,arguments)}static constructor_(){this._counter=null;const t=arguments[0];this._counter=t}visitItem(t){const e=t;this._counter.countSegment(e.getCoordinate(0),e.getCoordinate(1))}get interfaces_(){return[Kf]}}class _d{constructor(){_d.constructor_.apply(this,arguments)}static constructor_(){this._isEmpty=!1,this._index=new E0;const t=arguments[0];t.isEmpty()?this._isEmpty=!0:this.init(t)}init(t){const e=Vn.getLines(t);for(let n=e.iterator();n.hasNext();){const r=n.next().getCoordinates();this.addLine(r)}}addLine(t){for(let e=1;e<t.length;e++){const n=new Se(t[e-1],t[e]),s=Math.min(n.p0.y,n.p1.y),r=Math.max(n.p0.y,n.p1.y);this._index.insert(s,r,n)}}query(){if(arguments.length===2){const t=arguments[0],e=arguments[1];if(this._isEmpty)return new vt;const n=new w0;return this._index.query(t,e,n),n.getItems()}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];if(this._isEmpty)return null;this._index.query(t,e,n)}}}Ll.SegmentVisitor=yd;Ll.IntervalIndexedGeometry=_d;class Ci extends qo{constructor(){super(),Ci.constructor_.apply(this,arguments)}static constructor_(){if(this._parentGeom=null,this._lineEdgeMap=new xw,this._boundaryNodeRule=null,this._useBoundaryDeterminationRule=!0,this._argIndex=null,this._boundaryNodes=null,this._hasTooFewPoints=!1,this._invalidPoint=null,this._areaPtLocator=null,this._ptLocator=new Yo,arguments.length===2){const t=arguments[0],e=arguments[1];Ci.constructor_.call(this,t,e,En.OGC_SFS_BOUNDARY_RULE)}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];this._argIndex=t,this._parentGeom=e,this._boundaryNodeRule=n,e!==null&&this.add(e)}}static determineBoundary(t,e){return t.isInBoundary(e)?q.BOUNDARY:q.INTERIOR}insertBoundaryPoint(t,e){const s=this._nodes.addNode(e).getLabel();let r=1,o=q.NONE;o=s.getLocation(t,yt.ON),o===q.BOUNDARY&&r++;const a=Ci.determineBoundary(this._boundaryNodeRule,r);s.setLocation(t,a)}computeSelfNodes(){if(arguments.length===2){const t=arguments[0],e=arguments[1];return this.computeSelfNodes(t,e,!1)}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2],s=new Go(t,!0,!1);s.setIsDoneIfProperInt(n);const r=this.createEdgeSetIntersector(),o=this._parentGeom instanceof fn||this._parentGeom instanceof Te||this._parentGeom instanceof hi,a=e||!o;return r.computeIntersections(this._edges,s,a),this.addSelfIntersectionNodes(this._argIndex),s}}computeSplitEdges(t){for(let e=this._edges.iterator();e.hasNext();)e.next().eiList.addSplitEdges(t)}computeEdgeIntersections(t,e,n){const s=new Go(e,n,!0);return s.setBoundaryNodes(this.getBoundaryNodes(),t.getBoundaryNodes()),this.createEdgeSetIntersector().computeIntersections(this._edges,t._edges,s),s}getGeometry(){return this._parentGeom}getBoundaryNodeRule(){return this._boundaryNodeRule}hasTooFewPoints(){return this._hasTooFewPoints}addPoint(){if(arguments[0]instanceof Ge){const e=arguments[0].getCoordinate();this.insertPoint(this._argIndex,e,q.INTERIOR)}else if(arguments[0]instanceof Z){const t=arguments[0];this.insertPoint(this._argIndex,t,q.INTERIOR)}}addPolygon(t){this.addPolygonRing(t.getExteriorRing(),q.EXTERIOR,q.INTERIOR);for(let e=0;e<t.getNumInteriorRing();e++){const n=t.getInteriorRingN(e);this.addPolygonRing(n,q.INTERIOR,q.EXTERIOR)}}addEdge(t){this.insertEdge(t);const e=t.getCoordinates();this.insertPoint(this._argIndex,e[0],q.BOUNDARY),this.insertPoint(this._argIndex,e[e.length-1],q.BOUNDARY)}addLineString(t){const e=Le.removeRepeatedPoints(t.getCoordinates());if(e.length<2)return this._hasTooFewPoints=!0,this._invalidPoint=e[0],null;const n=new ms(e,new Be(this._argIndex,q.INTERIOR));this._lineEdgeMap.put(t,n),this.insertEdge(n),Yt.isTrue(e.length>=2,"found LineString with single point"),this.insertBoundaryPoint(this._argIndex,e[0]),this.insertBoundaryPoint(this._argIndex,e[e.length-1])}getInvalidPoint(){return this._invalidPoint}getBoundaryPoints(){const t=this.getBoundaryNodes(),e=new Array(t.size()).fill(null);let n=0;for(let s=t.iterator();s.hasNext();){const r=s.next();e[n++]=r.getCoordinate().copy()}return e}getBoundaryNodes(){return this._boundaryNodes===null&&(this._boundaryNodes=this._nodes.getBoundaryNodes(this._argIndex)),this._boundaryNodes}addSelfIntersectionNode(t,e,n){if(this.isBoundaryNode(t,e))return null;n===q.BOUNDARY&&this._useBoundaryDeterminationRule?this.insertBoundaryPoint(t,e):this.insertPoint(t,e,n)}addPolygonRing(t,e,n){if(t.isEmpty())return null;const s=Le.removeRepeatedPoints(t.getCoordinates());if(s.length<4)return this._hasTooFewPoints=!0,this._invalidPoint=s[0],null;let r=e,o=n;$t.isCCW(s)&&(r=n,o=e);const a=new ms(s,new Be(this._argIndex,q.BOUNDARY,r,o));this._lineEdgeMap.put(t,a),this.insertEdge(a),this.insertPoint(this._argIndex,s[0],q.BOUNDARY)}insertPoint(t,e,n){const s=this._nodes.addNode(e),r=s.getLabel();r===null?s._label=new Be(t,n):r.setLocation(t,n)}createEdgeSetIntersector(){return new y0}addSelfIntersectionNodes(t){for(let e=this._edges.iterator();e.hasNext();){const n=e.next(),s=n.getLabel().getLocation(t);for(let r=n.eiList.iterator();r.hasNext();){const o=r.next();this.addSelfIntersectionNode(t,o.coord,s)}}}add(){if(arguments.length===1&&arguments[0]instanceof dt){const t=arguments[0];if(t.isEmpty())return null;if(t instanceof hi&&(this._useBoundaryDeterminationRule=!1),t instanceof Te)this.addPolygon(t);else if(t instanceof ce)this.addLineString(t);else if(t instanceof Ge)this.addPoint(t);else if(t instanceof Ss)this.addCollection(t);else if(t instanceof ns)this.addCollection(t);else if(t instanceof hi)this.addCollection(t);else if(t instanceof ye)this.addCollection(t);else throw new ss(t.getGeometryType())}else return super.add.apply(this,arguments)}addCollection(t){for(let e=0;e<t.getNumGeometries();e++){const n=t.getGeometryN(e);this.add(n)}}locate(t){return Ot(this._parentGeom,Jr)&&this._parentGeom.getNumGeometries()>50?(this._areaPtLocator===null&&(this._areaPtLocator=new Ll(this._parentGeom)),this._areaPtLocator.locate(t)):this._ptLocator.locate(t,this._parentGeom)}findEdge(){if(arguments.length===1&&arguments[0]instanceof ce){const t=arguments[0];return this._lineEdgeMap.get(t)}else return super.findEdge.apply(this,arguments)}}class zI{createEdgeEndForNext(t,e,n,s){const r=n.segmentIndex+1;if(r>=t.getNumPoints()&&s===null)return null;let o=t.getCoordinate(r);s!==null&&s.segmentIndex===n.segmentIndex&&(o=s.coord);const a=new Xs(t,n.coord,o,new Be(t.getLabel()));e.add(a)}createEdgeEndForPrev(t,e,n,s){let r=n.segmentIndex;if(n.dist===0){if(r===0)return null;r--}let o=t.getCoordinate(r);s!==null&&s.segmentIndex>=r&&(o=s.coord);const a=new Be(t.getLabel());a.flip();const l=new Xs(t,n.coord,o,a);e.add(l)}computeEdgeEnds(){if(arguments.length===1){const t=arguments[0],e=new vt;for(let n=t;n.hasNext();){const s=n.next();this.computeEdgeEnds(s,e)}return e}else if(arguments.length===2){const t=arguments[0],e=arguments[1],n=t.getEdgeIntersectionList();n.addEndpoints();const s=n.iterator();let r=null,o=null;if(!s.hasNext())return null;let a=s.next();do r=o,o=a,a=null,s.hasNext()&&(a=s.next()),o!==null&&(this.createEdgeEndForPrev(t,e,o,r),this.createEdgeEndForNext(t,e,o,a));while(o!==null)}}}class Lf extends Xs{constructor(){super(),Lf.constructor_.apply(this,arguments)}static constructor_(){if(this._edgeEnds=new vt,arguments.length===1){const t=arguments[0];Lf.constructor_.call(this,null,t)}else if(arguments.length===2){const t=arguments[1];Xs.constructor_.call(this,t.getEdge(),t.getCoordinate(),t.getDirectedCoordinate(),new Be(t.getLabel())),this.insert(t)}}insert(t){this._edgeEnds.add(t)}print(t){t.println("EdgeEndBundle--> Label: "+this._label);for(let e=this.iterator();e.hasNext();)e.next().print(t),t.println()}iterator(){return this._edgeEnds.iterator()}getEdgeEnds(){return this._edgeEnds}computeLabelOn(t,e){let n=0,s=!1;for(let o=this.iterator();o.hasNext();){const l=o.next().getLabel().getLocation(t);l===q.BOUNDARY&&n++,l===q.INTERIOR&&(s=!0)}let r=q.NONE;s&&(r=q.INTERIOR),n>0&&(r=Ci.determineBoundary(e,n)),this._label.setLocation(t,r)}computeLabelSide(t,e){for(let n=this.iterator();n.hasNext();){const s=n.next();if(s.getLabel().isArea()){const r=s.getLabel().getLocation(t,e);if(r===q.INTERIOR)return this._label.setLocation(t,e,q.INTERIOR),null;r===q.EXTERIOR&&this._label.setLocation(t,e,q.EXTERIOR)}}}getLabel(){return this._label}computeLabelSides(t){this.computeLabelSide(t,yt.LEFT),this.computeLabelSide(t,yt.RIGHT)}updateIM(t){ms.updateIM(this._label,t)}computeLabel(t){let e=!1;for(let n=this.iterator();n.hasNext();)n.next().getLabel().isArea()&&(e=!0);e?this._label=new Be(q.NONE,q.NONE,q.NONE):this._label=new Be(q.NONE);for(let n=0;n<2;n++)this.computeLabelOn(n,t),e&&this.computeLabelSides(n)}}class uF extends nd{constructor(){super()}updateIM(t){for(let e=this.iterator();e.hasNext();)e.next().updateIM(t)}insert(t){let e=this._edgeMap.get(t);e===null?(e=new Lf(t),this.insertEdgeEnd(t,e)):e.insert(t)}}class x0 extends yr{constructor(){super(),x0.constructor_.apply(this,arguments)}static constructor_(){const t=arguments[0],e=arguments[1];yr.constructor_.call(this,t,e)}updateIMFromEdges(t){this._edges.updateIM(t)}computeIM(t){t.setAtLeastIfValid(this._label.getLocation(0),this._label.getLocation(1),0)}}class UI extends ap{constructor(){super()}createNode(t){return new x0(t,new uF)}}class b0{constructor(){b0.constructor_.apply(this,arguments)}static constructor_(){this._nodes=new ol(new UI)}insertEdgeEnds(t){for(let e=t.iterator();e.hasNext();){const n=e.next();this._nodes.add(n)}}getNodeIterator(){return this._nodes.iterator()}copyNodesAndLabels(t,e){for(let n=t.getNodeIterator();n.hasNext();){const s=n.next();this._nodes.addNode(s.getCoordinate()).setLabel(e,s.getLabel().getLocation(e))}}build(t){this.computeIntersectionNodes(t,0),this.copyNodesAndLabels(t,0);const n=new zI().computeEdgeEnds(t.getEdgeIterator());this.insertEdgeEnds(n)}computeIntersectionNodes(t,e){for(let n=t.getEdgeIterator();n.hasNext();){const s=n.next(),r=s.getLabel().getLocation(e);for(let o=s.getEdgeIntersectionList().iterator();o.hasNext();){const a=o.next(),l=this._nodes.addNode(a.coord);r===q.BOUNDARY?l.setLabelBoundary(e):l.getLabel().isNull(e)&&l.setLabel(e,q.INTERIOR)}}}}class I0{constructor(){I0.constructor_.apply(this,arguments)}static constructor_(){this._li=new Nn,this._geomGraph=null,this._nodeGraph=new b0,this._invalidPoint=null;const t=arguments[0];this._geomGraph=t}isNodeEdgeAreaLabelsConsistent(){for(let t=this._nodeGraph.getNodeIterator();t.hasNext();){const e=t.next();if(!e.getEdges().isAreaLabelsConsistent(this._geomGraph))return this._invalidPoint=e.getCoordinate().copy(),!1}return!0}getInvalidPoint(){return this._invalidPoint}hasDuplicateRings(){for(let t=this._nodeGraph.getNodeIterator();t.hasNext();){const e=t.next();for(let n=e.getEdges().iterator();n.hasNext();){const s=n.next();if(s.getEdgeEnds().size()>1)return this._invalidPoint=s.getEdge().getCoordinate(0),!0}}return!1}isNodeConsistentArea(){const t=this._geomGraph.computeSelfNodes(this._li,!0,!0);return t.hasProperIntersection()?(this._invalidPoint=t.getProperIntersectionPoint(),!1):(this._nodeGraph.build(this._geomGraph),this.isNodeEdgeAreaLabelsConsistent())}}class S0{constructor(){S0.constructor_.apply(this,arguments)}static constructor_(){this._graph=null,this._rings=new vt,this._totalEnv=new te,this._index=null,this._nestedPt=null;const t=arguments[0];this._graph=t}buildIndex(){this._index=new Je;for(let t=0;t<this._rings.size();t++){const e=this._rings.get(t),n=e.getEnvelopeInternal();this._index.insert(n,e)}}getNestedPoint(){return this._nestedPt}isNonNested(){this.buildIndex();for(let t=0;t<this._rings.size();t++){const e=this._rings.get(t),n=e.getCoordinates(),s=this._index.query(e.getEnvelopeInternal());for(let r=0;r<s.size();r++){const o=s.get(r),a=o.getCoordinates();if(e===o||!e.getEnvelopeInternal().intersects(o.getEnvelopeInternal()))continue;const l=Ii.findPtNotNode(n,o,this._graph);if(l===null)continue;if(ts.isInRing(l,a))return this._nestedPt=l,!1}}return!0}add(t){this._rings.add(t),this._totalEnv.expandToInclude(t.getEnvelopeInternal())}}class ne{constructor(){ne.constructor_.apply(this,arguments)}static constructor_(){if(this._errorType=null,this._pt=null,arguments.length===1){const t=arguments[0];ne.constructor_.call(this,t,null)}else if(arguments.length===2){const t=arguments[0],e=arguments[1];this._errorType=t,e!==null&&(this._pt=e.copy())}}getErrorType(){return this._errorType}getMessage(){return ne.errMsg[this._errorType]}getCoordinate(){return this._pt}toString(){let t="";return this._pt!==null&&(t=" at or near point "+this._pt),this.getMessage()+t}}ne.ERROR=0;ne.REPEATED_POINT=1;ne.HOLE_OUTSIDE_SHELL=2;ne.NESTED_HOLES=3;ne.DISCONNECTED_INTERIOR=4;ne.SELF_INTERSECTION=5;ne.RING_SELF_INTERSECTION=6;ne.NESTED_SHELLS=7;ne.DUPLICATE_RINGS=8;ne.TOO_FEW_POINTS=9;ne.INVALID_COORDINATE=10;ne.RING_NOT_CLOSED=11;ne.errMsg=["Topology Validation Error","Repeated Point","Hole lies outside shell","Holes are nested","Interior is disconnected","Self-intersection","Ring Self-intersection","Nested shells","Duplicate Rings","Too few distinct points in geometry component","Invalid Coordinate","Ring is not closed"];class Ii{constructor(){Ii.constructor_.apply(this,arguments)}static constructor_(){this._parentGeometry=null,this._isSelfTouchingRingFormingHoleValid=!1,this._validErr=null;const t=arguments[0];this._parentGeometry=t}static findPtNotNode(t,e,n){const r=n.findEdge(e).getEdgeIntersectionList();for(let o=0;o<t.length;o++){const a=t[o];if(!r.isIntersection(a))return a}return null}static isValid(){if(arguments[0]instanceof dt){const t=arguments[0];return new Ii(t).isValid()}else if(arguments[0]instanceof Z){const t=arguments[0];return!(Rt.isNaN(t.x)||Rt.isInfinite(t.x)||Rt.isNaN(t.y)||Rt.isInfinite(t.y))}}checkInvalidCoordinates(){if(arguments[0]instanceof Array){const t=arguments[0];for(let e=0;e<t.length;e++)if(!Ii.isValid(t[e]))return this._validErr=new ne(ne.INVALID_COORDINATE,t[e]),null}else if(arguments[0]instanceof Te){const t=arguments[0];if(this.checkInvalidCoordinates(t.getExteriorRing().getCoordinates()),this._validErr!==null)return null;for(let e=0;e<t.getNumInteriorRing();e++)if(this.checkInvalidCoordinates(t.getInteriorRingN(e).getCoordinates()),this._validErr!==null)return null}}checkHolesNotNested(t,e){if(t.getNumInteriorRing()<=0)return null;const n=new S0(e);for(let r=0;r<t.getNumInteriorRing();r++){const o=t.getInteriorRingN(r);o.isEmpty()||n.add(o)}n.isNonNested()||(this._validErr=new ne(ne.NESTED_HOLES,n.getNestedPoint()))}checkConsistentArea(t){const e=new I0(t);if(!e.isNodeConsistentArea())return this._validErr=new ne(ne.SELF_INTERSECTION,e.getInvalidPoint()),null;e.hasDuplicateRings()&&(this._validErr=new ne(ne.DUPLICATE_RINGS,e.getInvalidPoint()))}isValid(){return this.checkValid(this._parentGeometry),this._validErr===null}checkShellInsideHole(t,e,n){const s=t.getCoordinates(),r=e.getCoordinates(),o=Ii.findPtNotNode(s,e,n);if(o!==null&&!ts.isInRing(o,r))return o;const a=Ii.findPtNotNode(r,t,n);return a!==null?ts.isInRing(a,s)?a:null:(Yt.shouldNeverReachHere("points in shell and hole appear to be equal"),null)}checkNoSelfIntersectingRings(t){for(let e=t.getEdgeIterator();e.hasNext();){const n=e.next();if(this.checkNoSelfIntersectingRing(n.getEdgeIntersectionList()),this._validErr!==null)return null}}checkConnectedInteriors(t){const e=new Nf(t);e.isInteriorsConnected()||(this._validErr=new ne(ne.DISCONNECTED_INTERIOR,e.getCoordinate()))}checkNoSelfIntersectingRing(t){const e=new Ao;let n=!0;for(let s=t.iterator();s.hasNext();){const r=s.next();if(n){n=!1;continue}if(e.contains(r.coord))return this._validErr=new ne(ne.RING_SELF_INTERSECTION,r.coord),null;e.add(r.coord)}}checkHolesInShell(t,e){if(t.getNumInteriorRing()<=0)return null;const n=t.getExteriorRing(),s=n.isEmpty(),r=new Ll(n);for(let o=0;o<t.getNumInteriorRing();o++){const a=t.getInteriorRingN(o);let l=null;if(a.isEmpty())continue;if(l=Ii.findPtNotNode(a.getCoordinates(),n,e),l===null)return null;if(s||q.EXTERIOR===r.locate(l))return this._validErr=new ne(ne.HOLE_OUTSIDE_SHELL,l),null}}checkTooFewPoints(t){if(t.hasTooFewPoints())return this._validErr=new ne(ne.TOO_FEW_POINTS,t.getInvalidPoint()),null}getValidationError(){return this.checkValid(this._parentGeometry),this._validErr}checkValid(){if(arguments[0]instanceof Ge){const t=arguments[0];this.checkInvalidCoordinates(t.getCoordinates())}else if(arguments[0]instanceof Ss){const t=arguments[0];this.checkInvalidCoordinates(t.getCoordinates())}else if(arguments[0]instanceof fn){const t=arguments[0];if(this.checkInvalidCoordinates(t.getCoordinates()),this._validErr!==null||(this.checkClosedRing(t),this._validErr!==null))return null;const e=new Ci(0,t);if(this.checkTooFewPoints(e),this._validErr!==null)return null;const n=new Nn;e.computeSelfNodes(n,!0,!0),this.checkNoSelfIntersectingRings(e)}else if(arguments[0]instanceof ce){const t=arguments[0];if(this.checkInvalidCoordinates(t.getCoordinates()),this._validErr!==null)return null;const e=new Ci(0,t);this.checkTooFewPoints(e)}else if(arguments[0]instanceof Te){const t=arguments[0];if(this.checkInvalidCoordinates(t),this._validErr!==null||(this.checkClosedRings(t),this._validErr!==null))return null;const e=new Ci(0,t);if(this.checkTooFewPoints(e),this._validErr!==null||(this.checkConsistentArea(e),this._validErr!==null)||!this._isSelfTouchingRingFormingHoleValid&&(this.checkNoSelfIntersectingRings(e),this._validErr!==null)||(this.checkHolesInShell(t,e),this._validErr!==null)||(this.checkHolesNotNested(t,e),this._validErr!==null))return null;this.checkConnectedInteriors(e)}else if(arguments[0]instanceof hi){const t=arguments[0];for(let n=0;n<t.getNumGeometries();n++){const s=t.getGeometryN(n);if(this.checkInvalidCoordinates(s),this._validErr!==null||(this.checkClosedRings(s),this._validErr!==null))return null}const e=new Ci(0,t);if(this.checkTooFewPoints(e),this._validErr!==null||(this.checkConsistentArea(e),this._validErr!==null)||!this._isSelfTouchingRingFormingHoleValid&&(this.checkNoSelfIntersectingRings(e),this._validErr!==null))return null;for(let n=0;n<t.getNumGeometries();n++){const s=t.getGeometryN(n);if(this.checkHolesInShell(s,e),this._validErr!==null)return null}for(let n=0;n<t.getNumGeometries();n++){const s=t.getGeometryN(n);if(this.checkHolesNotNested(s,e),this._validErr!==null)return null}if(this.checkShellsNotNested(t,e),this._validErr!==null)return null;this.checkConnectedInteriors(e)}else if(arguments[0]instanceof ye){const t=arguments[0];for(let e=0;e<t.getNumGeometries();e++){const n=t.getGeometryN(e);if(this.checkValid(n),this._validErr!==null)return null}}else if(arguments[0]instanceof dt){const t=arguments[0];if(this._validErr=null,t.isEmpty())return null;if(t instanceof Ge)this.checkValid(t);else if(t instanceof Ss)this.checkValid(t);else if(t instanceof fn)this.checkValid(t);else if(t instanceof ce)this.checkValid(t);else if(t instanceof Te)this.checkValid(t);else if(t instanceof hi)this.checkValid(t);else if(t instanceof ye)this.checkValid(t);else throw new ss(t.getGeometryType())}}setSelfTouchingRingFormingHoleValid(t){this._isSelfTouchingRingFormingHoleValid=t}checkShellNotNested(t,e,n){const s=t.getCoordinates(),r=e.getExteriorRing();if(r.isEmpty())return null;const o=r.getCoordinates(),a=Ii.findPtNotNode(s,r,n);if(a===null||!ts.isInRing(a,o))return null;if(e.getNumInteriorRing()<=0)return this._validErr=new ne(ne.NESTED_SHELLS,a),null;let h=null;for(let f=0;f<e.getNumInteriorRing();f++){const d=e.getInteriorRingN(f);if(h=this.checkShellInsideHole(t,d,n),h===null)return null}this._validErr=new ne(ne.NESTED_SHELLS,h)}checkClosedRings(t){if(this.checkClosedRing(t.getExteriorRing()),this._validErr!==null)return null;for(let e=0;e<t.getNumInteriorRing();e++)if(this.checkClosedRing(t.getInteriorRingN(e)),this._validErr!==null)return null}checkClosedRing(t){if(t.isEmpty())return null;if(!t.isClosed()){let e=null;t.getNumPoints()>=1&&(e=t.getCoordinateN(0)),this._validErr=new ne(ne.RING_NOT_CLOSED,e)}}checkShellsNotNested(t,e){for(let n=0;n<t.getNumGeometries();n++){const r=t.getGeometryN(n).getExteriorRing();for(let o=0;o<t.getNumGeometries();o++){if(n===o)continue;const a=t.getGeometryN(o);if(this.checkShellNotNested(r,a,e),this._validErr!==null)return null}}}}class Co{constructor(){Co.constructor_.apply(this,arguments)}static constructor_(){if(this._inputGeom=null,this._isClosedEndpointsInInterior=!0,this._nonSimpleLocation=null,arguments.length===1){const t=arguments[0];this._inputGeom=t}else if(arguments.length===2){const t=arguments[0],e=arguments[1];this._inputGeom=t,this._isClosedEndpointsInInterior=!e.isInBoundary(2)}}static isSimple(){if(arguments.length===1){const t=arguments[0];return new Co(t).isSimple()}else if(arguments.length===2){const t=arguments[0],e=arguments[1];return new Co(t,e).isSimple()}}isSimpleMultiPoint(t){if(t.isEmpty())return!0;const e=new Ao;for(let n=0;n<t.getNumGeometries();n++){const r=t.getGeometryN(n).getCoordinate();if(e.contains(r))return this._nonSimpleLocation=r,!1;e.add(r)}return!0}isSimplePolygonal(t){const e=Vn.getLines(t);for(let n=e.iterator();n.hasNext();){const s=n.next();if(!this.isSimpleLinearGeometry(s))return!1}return!0}hasClosedEndpointIntersection(t){const e=new Qs;for(let n=t.getEdgeIterator();n.hasNext();){const s=n.next(),r=s.isClosed(),o=s.getCoordinate(0);this.addEndpoint(e,o,r);const a=s.getCoordinate(s.getNumPoints()-1);this.addEndpoint(e,a,r)}for(let n=e.values().iterator();n.hasNext();){const s=n.next();if(s.isClosed&&s.degree!==2)return this._nonSimpleLocation=s.getCoordinate(),!0}return!1}getNonSimpleLocation(){return this._nonSimpleLocation}isSimpleLinearGeometry(t){if(t.isEmpty())return!0;const e=new Ci(0,t),n=new Nn,s=e.computeSelfNodes(n,!0);return s.hasIntersection()?s.hasProperIntersection()?(this._nonSimpleLocation=s.getProperIntersectionPoint(),!1):!(this.hasNonEndpointIntersection(e)||this._isClosedEndpointsInInterior&&this.hasClosedEndpointIntersection(e)):!0}hasNonEndpointIntersection(t){for(let e=t.getEdgeIterator();e.hasNext();){const n=e.next(),s=n.getMaximumSegmentIndex();for(let r=n.getEdgeIntersectionList().iterator();r.hasNext();){const o=r.next();if(!o.isEndPoint(s))return this._nonSimpleLocation=o.getCoordinate(),!0}}return!1}addEndpoint(t,e,n){let s=t.get(e);s===null&&(s=new vd(e),t.put(e,s)),s.addEndpoint(n)}computeSimple(t){return this._nonSimpleLocation=null,t.isEmpty()?!0:t instanceof ce?this.isSimpleLinearGeometry(t):t instanceof ns?this.isSimpleLinearGeometry(t):t instanceof Ss?this.isSimpleMultiPoint(t):Ot(t,Jr)?this.isSimplePolygonal(t):t instanceof ye?this.isSimpleGeometryCollection(t):!0}isSimple(){return this._nonSimpleLocation=null,this.computeSimple(this._inputGeom)}isSimpleGeometryCollection(t){for(let e=0;e<t.getNumGeometries();e++){const n=t.getGeometryN(e);if(!this.computeSimple(n))return!1}return!0}}class vd{constructor(){vd.constructor_.apply(this,arguments)}static constructor_(){this.pt=null,this.isClosed=null,this.degree=null;const t=arguments[0];this.pt=t,this.isClosed=!1,this.degree=0}addEndpoint(t){this.degree++,this.isClosed|=t}getCoordinate(){return this.pt}}Co.EndpointInfo=vd;class Wi{constructor(){Wi.constructor_.apply(this,arguments)}static constructor_(){if(this._factory=null,this._isUserDataCopied=!1,arguments.length!==0){if(arguments.length===1){const t=arguments[0];this._factory=t}}}setCopyUserData(t){this._isUserDataCopied=t}edit(t,e){if(t===null)return null;const n=this.editInternal(t,e);return this._isUserDataCopied&&n.setUserData(t.getUserData()),n}editInternal(t,e){return this._factory===null&&(this._factory=t.getFactory()),t instanceof ye?this.editGeometryCollection(t,e):t instanceof Te?this.editPolygon(t,e):t instanceof Ge?e.edit(t,this._factory):t instanceof ce?e.edit(t,this._factory):(Yt.shouldNeverReachHere("Unsupported Geometry type: "+t.getGeometryType()),null)}editGeometryCollection(t,e){const n=e.edit(t,this._factory),s=new vt;for(let r=0;r<n.getNumGeometries();r++){const o=this.edit(n.getGeometryN(r),e);o===null||o.isEmpty()||s.add(o)}return n.getGeometryType()===dt.TYPENAME_MULTIPOINT?this._factory.createMultiPoint(s.toArray([])):n.getGeometryType()===dt.TYPENAME_MULTILINESTRING?this._factory.createMultiLineString(s.toArray([])):n.getGeometryType()===dt.TYPENAME_MULTIPOLYGON?this._factory.createMultiPolygon(s.toArray([])):this._factory.createGeometryCollection(s.toArray([]))}editPolygon(t,e){let n=e.edit(t,this._factory);if(n===null&&(n=this._factory.createPolygon()),n.isEmpty())return n;const s=this.edit(n.getExteriorRing(),e);if(s===null||s.isEmpty())return this._factory.createPolygon();const r=new vt;for(let o=0;o<n.getNumInteriorRing();o++){const a=this.edit(n.getInteriorRingN(o),e);a===null||a.isEmpty()||r.add(a)}return this._factory.createPolygon(s,r.toArray([]))}}function Ed(){}Wi.GeometryEditorOperation=Ed;class cF{edit(t,e){return t}get interfaces_(){return[Ed]}}class hF{edit(t,e){const n=this.edit(t.getCoordinates(),t);return t instanceof fn?n===null?e.createLinearRing():e.createLinearRing(n):t instanceof ce?n===null?e.createLineString():e.createLineString(n):t instanceof Ge?n===null||n.length===0?e.createPoint():e.createPoint(n[0]):t}get interfaces_(){return[Ed]}}class fF{edit(t,e){return t instanceof fn?e.createLinearRing(this.edit(t.getCoordinateSequence(),t)):t instanceof ce?e.createLineString(this.edit(t.getCoordinateSequence(),t)):t instanceof Ge?e.createPoint(this.edit(t.getCoordinateSequence(),t)):t}get interfaces_(){return[Ed]}}Wi.NoOpGeometryOperation=cF;Wi.CoordinateOperation=hF;Wi.CoordinateSequenceOperation=fF;class M0 extends Wi.CoordinateOperation{constructor(){super(),M0.constructor_.apply(this,arguments)}static constructor_(){this._targetPM=null,this._removeCollapsed=!0;const t=arguments[0],e=arguments[1];this._targetPM=t,this._removeCollapsed=e}edit(){if(arguments.length===2&&arguments[1]instanceof dt&&arguments[0]instanceof Array){const t=arguments[0],e=arguments[1];if(t.length===0)return null;const n=new Array(t.length).fill(null);for(let l=0;l<t.length;l++){const h=new Z(t[l]);this._targetPM.makePrecise(h),n[l]=h}const r=new Qi(n,!1).toCoordinateArray();let o=0;e instanceof ce&&(o=2),e instanceof fn&&(o=4);let a=n;return this._removeCollapsed&&(a=null),r.length<o?a:r}else return super.edit.apply(this,arguments)}}class xu{constructor(){xu.constructor_.apply(this,arguments)}static constructor_(){this._targetPM=null,this._removeCollapsed=!0,this._changePrecisionModel=!1,this._isPointwise=!1;const t=arguments[0];this._targetPM=t}static reduce(t,e){return new xu(e).reduce(t)}static reducePointwise(t,e){const n=new xu(e);return n.setPointwise(!0),n.reduce(t)}fixPolygonalTopology(t){let e=t;return this._changePrecisionModel||(e=this.changePM(t,this._targetPM)),_n.bufferOp(e,0)}reducePointwise(t){let e=null;if(this._changePrecisionModel){const r=this.createFactory(t.getFactory(),this._targetPM);e=new Wi(r)}else e=new Wi;let n=this._removeCollapsed;return t.getDimension()>=2&&(n=!0),e.edit(t,new M0(this._targetPM,n))}changePM(t,e){return this.createEditor(t.getFactory(),e).edit(t,new Wi.NoOpGeometryOperation)}setRemoveCollapsedComponents(t){this._removeCollapsed=t}createFactory(t,e){return new ze(e,t.getSRID(),t.getCoordinateSequenceFactory())}setChangePrecisionModel(t){this._changePrecisionModel=t}reduce(t){const e=this.reducePointwise(t);return this._isPointwise||!Ot(e,Jr)||Ii.isValid(e)?e:this.fixPolygonalTopology(e)}setPointwise(t){this._isPointwise=t}createEditor(t,e){if(t.getPrecisionModel()===e)return new Wi;const n=this.createFactory(t,e);return new Wi(n)}}class ds{constructor(){ds.constructor_.apply(this,arguments)}static constructor_(){this._geomFactory=null,this._skipEmpty=!1,this._inputGeoms=null;const t=arguments[0];this._geomFactory=ds.extractFactory(t),this._inputGeoms=t}static combine(){if(arguments.length===1){const t=arguments[0];return new ds(t).combine()}else if(arguments.length===2){const t=arguments[0],e=arguments[1];return new ds(ds.createList(t,e)).combine()}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];return new ds(ds.createList(t,e,n)).combine()}}static extractFactory(t){return t.isEmpty()?null:t.iterator().next().getFactory()}static createList(){if(arguments.length===2){const t=arguments[0],e=arguments[1],n=new vt;return n.add(t),n.add(e),n}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2],s=new vt;return s.add(t),s.add(e),s.add(n),s}}extractElements(t,e){if(t===null)return null;for(let n=0;n<t.getNumGeometries();n++){const s=t.getGeometryN(n);this._skipEmpty&&s.isEmpty()||e.add(s)}}combine(){const t=new vt;for(let e=this._inputGeoms.iterator();e.hasNext();){const n=e.next();this.extractElements(n,t)}return t.size()===0?this._geomFactory!==null?this._geomFactory.createGeometryCollection():null:this._geomFactory.buildGeometry(t)}}class Cf{constructor(){Cf.constructor_.apply(this,arguments)}static constructor_(){this._pointGeom=null,this._otherGeom=null,this._geomFact=null;const t=arguments[0],e=arguments[1];this._pointGeom=t,this._otherGeom=e,this._geomFact=e.getFactory()}static union(t,e){return new Cf(t,e).union()}union(){const t=new Yo,e=new Ao;for(let r=0;r<this._pointGeom.getNumGeometries();r++){const a=this._pointGeom.getGeometryN(r).getCoordinate();t.locate(a,this._otherGeom)===q.EXTERIOR&&e.add(a)}if(e.size()===0)return this._otherGeom;let n=null;const s=Le.toCoordinateArray(e);return s.length===1?n=this._geomFact.createPoint(s[0]):n=this._geomFact.createMultiPointFromCoords(s),ds.combine(n,this._otherGeom)}}class N0{constructor(){N0.constructor_.apply(this,arguments)}static constructor_(){this._inputGeom=null,this._factory=null,this._pruneEmptyGeometry=!0,this._preserveGeometryCollectionType=!0,this._preserveCollections=!1,this._preserveType=!1}transformPoint(t,e){return this._factory.createPoint(this.transformCoordinates(t.getCoordinateSequence(),t))}transformPolygon(t,e){let n=!0;const s=this.transformLinearRing(t.getExteriorRing(),t);(s===null||!(s instanceof fn)||s.isEmpty())&&(n=!1);const r=new vt;for(let o=0;o<t.getNumInteriorRing();o++){const a=this.transformLinearRing(t.getInteriorRingN(o),t);a===null||a.isEmpty()||(a instanceof fn||(n=!1),r.add(a))}if(n)return this._factory.createPolygon(s,r.toArray([]));{const o=new vt;return s!==null&&o.add(s),o.addAll(r),this._factory.buildGeometry(o)}}createCoordinateSequence(t){return this._factory.getCoordinateSequenceFactory().create(t)}getInputGeometry(){return this._inputGeom}transformMultiLineString(t,e){const n=new vt;for(let s=0;s<t.getNumGeometries();s++){const r=this.transformLineString(t.getGeometryN(s),t);r!==null&&(r.isEmpty()||n.add(r))}return this._factory.buildGeometry(n)}transformCoordinates(t,e){return this.copy(t)}transformLineString(t,e){return this._factory.createLineString(this.transformCoordinates(t.getCoordinateSequence(),t))}transformMultiPoint(t,e){const n=new vt;for(let s=0;s<t.getNumGeometries();s++){const r=this.transformPoint(t.getGeometryN(s),t);r!==null&&(r.isEmpty()||n.add(r))}return this._factory.buildGeometry(n)}transformMultiPolygon(t,e){const n=new vt;for(let s=0;s<t.getNumGeometries();s++){const r=this.transformPolygon(t.getGeometryN(s),t);r!==null&&(r.isEmpty()||n.add(r))}return this._factory.buildGeometry(n)}copy(t){return t.copy()}transformGeometryCollection(t,e){const n=new vt;for(let s=0;s<t.getNumGeometries();s++){const r=this.transform(t.getGeometryN(s));r!==null&&(this._pruneEmptyGeometry&&r.isEmpty()||n.add(r))}return this._preserveGeometryCollectionType?this._factory.createGeometryCollection(ze.toGeometryArray(n)):this._factory.buildGeometry(n)}transform(t){if(this._inputGeom=t,this._factory=t.getFactory(),t instanceof Ge)return this.transformPoint(t,null);if(t instanceof Ss)return this.transformMultiPoint(t,null);if(t instanceof fn)return this.transformLinearRing(t,null);if(t instanceof ce)return this.transformLineString(t,null);if(t instanceof ns)return this.transformMultiLineString(t,null);if(t instanceof Te)return this.transformPolygon(t,null);if(t instanceof hi)return this.transformMultiPolygon(t,null);if(t instanceof ye)return this.transformGeometryCollection(t,null);throw new Zt("Unknown Geometry subtype: "+t.getGeometryType())}transformLinearRing(t,e){const n=this.transformCoordinates(t.getCoordinateSequence(),t);if(n===null)return this._factory.createLinearRing(null);const s=n.size();return s>0&&s<4&&!this._preserveType?this._factory.createLineString(n):this._factory.createLinearRing(n)}}class bu{constructor(){bu.constructor_.apply(this,arguments)}static constructor_(){if(this._snapTolerance=0,this._srcPts=null,this._seg=new Se,this._allowSnappingToSourceVertices=!1,this._isClosed=!1,arguments[0]instanceof ce&&typeof arguments[1]=="number"){const t=arguments[0],e=arguments[1];bu.constructor_.call(this,t.getCoordinates(),e)}else if(arguments[0]instanceof Array&&typeof arguments[1]=="number"){const t=arguments[0],e=arguments[1];this._srcPts=t,this._isClosed=bu.isClosed(t),this._snapTolerance=e}}static isClosed(t){return t.length<=1?!1:t[0].equals2D(t[t.length-1])}snapVertices(t,e){const n=this._isClosed?t.size()-1:t.size();for(let s=0;s<n;s++){const r=t.get(s),o=this.findSnapForVertex(r,e);o!==null&&(t.set(s,new Z(o)),s===0&&this._isClosed&&t.set(t.size()-1,new Z(o)))}}findSnapForVertex(t,e){for(let n=0;n<e.length;n++){if(t.equals2D(e[n]))return null;if(t.distance(e[n])<this._snapTolerance)return e[n]}return null}snapTo(t){const e=new Qi(this._srcPts);return this.snapVertices(e,t),this.snapSegments(e,t),e.toCoordinateArray()}snapSegments(t,e){if(e.length===0)return null;let n=e.length;e[0].equals2D(e[e.length-1])&&(n=e.length-1);for(let s=0;s<n;s++){const r=e[s],o=this.findSegmentIndexToSnap(r,t);o>=0&&t.add(o+1,new Z(r),!1)}}findSegmentIndexToSnap(t,e){let n=Rt.MAX_VALUE,s=-1;for(let r=0;r<e.size()-1;r++){if(this._seg.p0=e.get(r),this._seg.p1=e.get(r+1),this._seg.p0.equals2D(t)||this._seg.p1.equals2D(t)){if(this._allowSnappingToSourceVertices)continue;return-1}const o=this._seg.distance(t);o<this._snapTolerance&&o<n&&(n=o,s=r)}return s}setAllowSnappingToSourceVertices(t){this._allowSnappingToSourceVertices=t}}class bi{constructor(){bi.constructor_.apply(this,arguments)}static constructor_(){this._srcGeom=null;const t=arguments[0];this._srcGeom=t}static snap(t,e,n){const s=new Array(2).fill(null),r=new bi(t);s[0]=r.snapTo(e,n);const o=new bi(e);return s[1]=o.snapTo(s[0],n),s}static computeOverlaySnapTolerance(){if(arguments.length===1){const t=arguments[0];let e=bi.computeSizeBasedSnapTolerance(t);const n=t.getPrecisionModel();if(n.getType()===Ee.FIXED){const s=1/n.getScale()*2/1.415;s>e&&(e=s)}return e}else if(arguments.length===2){const t=arguments[0],e=arguments[1];return Math.min(bi.computeOverlaySnapTolerance(t),bi.computeOverlaySnapTolerance(e))}}static computeSizeBasedSnapTolerance(t){const e=t.getEnvelopeInternal();return Math.min(e.getHeight(),e.getWidth())*bi.SNAP_PRECISION_FACTOR}static snapToSelf(t,e,n){return new bi(t).snapToSelf(e,n)}snapTo(t,e){const n=this.extractTargetCoordinates(t);return new Pf(e,n).transform(this._srcGeom)}snapToSelf(t,e){const n=this.extractTargetCoordinates(this._srcGeom),r=new Pf(t,n,!0).transform(this._srcGeom);let o=r;return e&&Ot(o,Jr)&&(o=r.buffer(0)),o}computeSnapTolerance(t){return this.computeMinimumSegmentLength(t)/10}extractTargetCoordinates(t){const e=new Ao,n=t.getCoordinates();for(let s=0;s<n.length;s++)e.add(n[s]);return e.toArray(new Array(0).fill(null))}computeMinimumSegmentLength(t){let e=Rt.MAX_VALUE;for(let n=0;n<t.length-1;n++){const s=t[n].distance(t[n+1]);s<e&&(e=s)}return e}}bi.SNAP_PRECISION_FACTOR=1e-9;class Pf extends N0{constructor(){super(),Pf.constructor_.apply(this,arguments)}static constructor_(){if(this._snapTolerance=null,this._snapPts=null,this._isSelfSnap=!1,arguments.length===2){const t=arguments[0],e=arguments[1];this._snapTolerance=t,this._snapPts=e}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];this._snapTolerance=t,this._snapPts=e,this._isSelfSnap=n}}snapLine(t,e){const n=new bu(t,this._snapTolerance);return n.setAllowSnappingToSourceVertices(this._isSelfSnap),n.snapTo(e)}transformCoordinates(t,e){const n=t.toCoordinateArray(),s=this.snapLine(n,this._snapPts);return this._factory.getCoordinateSequenceFactory().create(s)}}class $s{constructor(){this._isFirst=!0,this._commonMantissaBitsCount=53,this._commonBits=new vo,this._commonSignExp=null}getCommon(){return Rt.longBitsToDouble(this._commonBits)}add(t){const e=Rt.doubleToLongBits(t);if(this._isFirst)return this._commonBits=e,this._commonSignExp=$s.signExpBits(this._commonBits),this._isFirst=!1,null;if($s.signExpBits(e)!==this._commonSignExp)return this._commonBits.high=0,this._commonBits.low=0,null;this._commonMantissaBitsCount=$s.numCommonMostSigMantissaBits(this._commonBits,e),this._commonBits=$s.zeroLowerBits(this._commonBits,64-(12+this._commonMantissaBitsCount))}toString(){if(arguments.length===1){const t=arguments[0],e=Rt.longBitsToDouble(t),s="0000000000000000000000000000000000000000000000000000000000000000"+vo.toBinaryString(t),r=s.substring(s.length-64);return r.substring(0,1)+" "+r.substring(1,12)+"(exp) "+r.substring(12)+" [ "+e+" ]"}}getClass(){return $s}get interfaces_(){return[]}static getBit(t,e){const n=1<<e%32;return e<32?(t.low&n)!==0?1:0:(t.high&n)!==0?1:0}static signExpBits(t){return t.high>>>20}static zeroLowerBits(t,e){let n="low";if(e>32&&(t.low=0,e%=32,n="high"),e>0){const s=e<32?~((1<<e)-1):0;t[n]&=s}return t}static numCommonMostSigMantissaBits(t,e){let n=0;for(let s=52;s>=0;s--){if($s.getBit(t,s)!==$s.getBit(e,s))return n;n++}return 52}}class Mc{constructor(){Mc.constructor_.apply(this,arguments)}static constructor_(){this._commonCoord=null,this._ccFilter=new wd}addCommonBits(t){const e=new nc(this._commonCoord);t.apply(e),t.geometryChanged()}removeCommonBits(t){if(this._commonCoord.x===0&&this._commonCoord.y===0)return t;const e=new Z(this._commonCoord);e.x=-e.x,e.y=-e.y;const n=new nc(e);return t.apply(n),t.geometryChanged(),t}getCommonCoordinate(){return this._commonCoord}add(t){t.apply(this._ccFilter),this._commonCoord=this._ccFilter.getCommonCoordinate()}}class wd{constructor(){wd.constructor_.apply(this,arguments)}static constructor_(){this._commonBitsX=new $s,this._commonBitsY=new $s}filter(t){this._commonBitsX.add(t.x),this._commonBitsY.add(t.y)}getCommonCoordinate(){return new Z(this._commonBitsX.getCommon(),this._commonBitsY.getCommon())}get interfaces_(){return[yl]}}class nc{constructor(){nc.constructor_.apply(this,arguments)}static constructor_(){this.trans=null;const t=arguments[0];this.trans=t}filter(t,e){const n=t.getOrdinate(e,0)+this.trans.x,s=t.getOrdinate(e,1)+this.trans.y;t.setOrdinate(e,0,n),t.setOrdinate(e,1,s)}isDone(){return!1}isGeometryChanged(){return!0}get interfaces_(){return[_l]}}Mc.CommonCoordinateFilter=wd;Mc.Translater=nc;class L0{constructor(){L0.constructor_.apply(this,arguments)}static constructor_(){this._pts=null,this._data=null;const t=arguments[0],e=arguments[1];this._pts=t,this._data=e}getCoordinates(){return this._pts}size(){return this._pts.length}getCoordinate(t){return this._pts[t]}isClosed(){return this._pts[0].equals(this._pts[this._pts.length-1])}getSegmentOctant(t){return t===this._pts.length-1?-1:Jf.octant(this.getCoordinate(t),this.getCoordinate(t+1))}setData(t){this._data=t}getData(){return this._data}toString(){return Js.toLineString(new _s(this._pts))}get interfaces_(){return[Rw]}}class Xn{constructor(){Xn.constructor_.apply(this,arguments)}static constructor_(){this._findAllIntersections=!1,this._isCheckEndSegmentsOnly=!1,this._keepIntersections=!0,this._isInteriorIntersectionsOnly=!1,this._li=null,this._interiorIntersection=null,this._intSegments=null,this._intersections=new vt,this._intersectionCount=0;const t=arguments[0];this._li=t,this._interiorIntersection=null}static createAllIntersectionsFinder(t){const e=new Xn(t);return e.setFindAllIntersections(!0),e}static isInteriorVertexIntersection(){if(arguments.length===4){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3];return n&&s?!1:!!t.equals2D(e)}else if(arguments.length===8){const t=arguments[0],e=arguments[1],n=arguments[2],s=arguments[3],r=arguments[4],o=arguments[5],a=arguments[6],l=arguments[7];return!!(Xn.isInteriorVertexIntersection(t,n,r,a)||Xn.isInteriorVertexIntersection(t,s,r,l)||Xn.isInteriorVertexIntersection(e,n,o,a)||Xn.isInteriorVertexIntersection(e,s,o,l))}}static createInteriorIntersectionCounter(t){const e=new Xn(t);return e.setInteriorIntersectionsOnly(!0),e.setFindAllIntersections(!0),e.setKeepIntersections(!1),e}static createIntersectionCounter(t){const e=new Xn(t);return e.setFindAllIntersections(!0),e.setKeepIntersections(!1),e}static isEndSegment(t,e){return e===0||e>=t.size()-2}static createAnyIntersectionFinder(t){return new Xn(t)}static createInteriorIntersectionsFinder(t){const e=new Xn(t);return e.setFindAllIntersections(!0),e.setInteriorIntersectionsOnly(!0),e}setCheckEndSegmentsOnly(t){this._isCheckEndSegmentsOnly=t}getIntersectionSegments(){return this._intSegments}count(){return this._intersectionCount}getIntersections(){return this._intersections}setFindAllIntersections(t){this._findAllIntersections=t}setKeepIntersections(t){this._keepIntersections=t}getIntersection(){return this._interiorIntersection}processIntersections(t,e,n,s){if(!this._findAllIntersections&&this.hasIntersection())return null;const r=t===n;if(r&&e===s||this._isCheckEndSegmentsOnly&&!(Xn.isEndSegment(t,e)||Xn.isEndSegment(n,s)))return null;const a=t.getCoordinate(e),l=t.getCoordinate(e+1),h=n.getCoordinate(s),f=n.getCoordinate(s+1),d=e===0,p=e+2===t.size(),y=s===0,_=s+2===n.size();this._li.computeIntersection(a,l,h,f);const E=this._li.hasIntersection()&&this._li.isInteriorIntersection();let w=!1;this._isInteriorIntersectionsOnly||(w=!(r&&Math.abs(s-e)<=1)&&Xn.isInteriorVertexIntersection(a,l,h,f,d,p,y,_)),(E||w)&&(this._intSegments=new Array(4).fill(null),this._intSegments[0]=a,this._intSegments[1]=l,this._intSegments[2]=h,this._intSegments[3]=f,this._interiorIntersection=this._li.getIntersection(0),this._keepIntersections&&this._intersections.add(this._interiorIntersection),this._intersectionCount++)}hasIntersection(){return this._interiorIntersection!==null}isDone(){return this._findAllIntersections?!1:this._interiorIntersection!==null}setInteriorIntersectionsOnly(t){this._isInteriorIntersectionsOnly=t}get interfaces_(){return[mp]}}class kf{constructor(){kf.constructor_.apply(this,arguments)}static constructor_(){this._li=new Nn,this._segStrings=null,this._findAllIntersections=!1,this._segInt=null,this._isValid=!0;const t=arguments[0];this._segStrings=t}static computeIntersections(t){const e=new kf(t);return e.setFindAllIntersections(!0),e.isValid(),e.getIntersections()}execute(){if(this._segInt!==null)return null;this.checkInteriorIntersections()}getIntersections(){return this._segInt.getIntersections()}isValid(){return this.execute(),this._isValid}setFindAllIntersections(t){this._findAllIntersections=t}checkInteriorIntersections(){this._isValid=!0,this._segInt=new Xn(this._li),this._segInt.setFindAllIntersections(this._findAllIntersections);const t=new El;if(t.setSegmentIntersector(this._segInt),t.computeNodes(this._segStrings),this._segInt.hasIntersection())return this._isValid=!1,null}checkValid(){if(this.execute(),!this._isValid)throw new ki(this.getErrorMessage(),this._segInt.getIntersection())}getErrorMessage(){if(this._isValid)return"no intersections found";const t=this._segInt.getIntersectionSegments();return"found non-noded intersection between "+Js.toLineString(t[0],t[1])+" and "+Js.toLineString(t[2],t[3])}}class Iu{constructor(){Iu.constructor_.apply(this,arguments)}static constructor_(){this._nv=null;const t=arguments[0];this._nv=new kf(Iu.toSegmentStrings(t))}static toSegmentStrings(t){const e=new vt;for(let n=t.iterator();n.hasNext();){const s=n.next();e.add(new L0(s.getCoordinates(),s))}return e}static checkValid(t){new Iu(t).checkValid()}checkValid(){this._nv.checkValid()}}class Tf{constructor(){Tf.constructor_.apply(this,arguments)}static constructor_(){this._mapOp=null;const t=arguments[0];this._mapOp=t}static map(t,e){return new Tf(e).map(t)}map(t){const e=new vt;for(let n=0;n<t.getNumGeometries();n++){const s=this._mapOp.map(t.getGeometryN(n));s.isEmpty()||e.add(s)}return t.getFactory().createGeometryCollection(ze.toGeometryArray(e))}}class C0{constructor(){C0.constructor_.apply(this,arguments)}static constructor_(){this._op=null,this._geometryFactory=null,this._ptLocator=null,this._lineEdgesList=new vt,this._resultLineList=new vt;const t=arguments[0],e=arguments[1],n=arguments[2];this._op=t,this._geometryFactory=e,this._ptLocator=n}collectLines(t){for(let e=this._op.getGraph().getEdgeEnds().iterator();e.hasNext();){const n=e.next();this.collectLineEdge(n,t,this._lineEdgesList),this.collectBoundaryTouchEdge(n,t,this._lineEdgesList)}}labelIsolatedLine(t,e){const n=this._ptLocator.locate(t.getCoordinate(),this._op.getArgGeometry(e));t.getLabel().setLocation(e,n)}build(t){return this.findCoveredLineEdges(),this.collectLines(t),this.buildLines(t),this._resultLineList}collectLineEdge(t,e,n){const s=t.getLabel(),r=t.getEdge();t.isLineEdge()&&!t.isVisited()&&zt.isResultOfOp(s,e)&&!r.isCovered()&&(n.add(r),t.setVisitedEdge(!0))}findCoveredLineEdges(){for(let t=this._op.getGraph().getNodes().iterator();t.hasNext();)t.next().getEdges().findCoveredLineEdges();for(let t=this._op.getGraph().getEdgeEnds().iterator();t.hasNext();){const e=t.next(),n=e.getEdge();if(e.isLineEdge()&&!n.isCoveredSet()){const s=this._op.isCoveredByA(e.getCoordinate());n.setCovered(s)}}}labelIsolatedLines(t){for(let e=t.iterator();e.hasNext();){const n=e.next(),s=n.getLabel();n.isIsolated()&&(s.isNull(0)?this.labelIsolatedLine(n,0):this.labelIsolatedLine(n,1))}}buildLines(t){for(let e=this._lineEdgesList.iterator();e.hasNext();){const n=e.next(),s=this._geometryFactory.createLineString(n.getCoordinates());this._resultLineList.add(s),n.setInResult(!0)}}collectBoundaryTouchEdge(t,e,n){const s=t.getLabel();if(t.isLineEdge()||t.isVisited()||t.isInteriorAreaEdge()||t.getEdge().isInResult())return null;Yt.isTrue(!(t.isInResult()||t.getSym().isInResult())||!t.getEdge().isInResult()),zt.isResultOfOp(s,e)&&e===zt.INTERSECTION&&(n.add(t.getEdge()),t.setVisitedEdge(!0))}}class P0{constructor(){P0.constructor_.apply(this,arguments)}static constructor_(){this._op=null,this._geometryFactory=null,this._resultPointList=new vt;const t=arguments[0],e=arguments[1];this._op=t,this._geometryFactory=e}filterCoveredNodeToPoint(t){const e=t.getCoordinate();if(!this._op.isCoveredByLA(e)){const n=this._geometryFactory.createPoint(e);this._resultPointList.add(n)}}extractNonCoveredResultNodes(t){for(let e=this._op.getGraph().getNodes().iterator();e.hasNext();){const n=e.next();if(!n.isInResult()&&!n.isIncidentEdgeInResult()&&(n.getEdges().getDegree()===0||t===zt.INTERSECTION)){const s=n.getLabel();zt.isResultOfOp(s,t)&&this.filterCoveredNodeToPoint(n)}}}build(t){return this.extractNonCoveredResultNodes(t),this._resultPointList}}class $r{constructor(){$r.constructor_.apply(this,arguments)}static constructor_(){if(this._li=new Nn,this._resultPrecisionModel=null,this._arg=null,arguments.length===1){const t=arguments[0];this.setComputationPrecision(t.getPrecisionModel()),this._arg=new Array(1).fill(null),this._arg[0]=new Ci(0,t)}else if(arguments.length===2){const t=arguments[0],e=arguments[1];$r.constructor_.call(this,t,e,En.OGC_SFS_BOUNDARY_RULE)}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];t.getPrecisionModel().compareTo(e.getPrecisionModel())>=0?this.setComputationPrecision(t.getPrecisionModel()):this.setComputationPrecision(e.getPrecisionModel()),this._arg=new Array(2).fill(null),this._arg[0]=new Ci(0,t,n),this._arg[1]=new Ci(1,e,n)}}getArgGeometry(t){return this._arg[t].getGeometry()}setComputationPrecision(t){this._resultPrecisionModel=t,this._li.setPrecisionModel(this._resultPrecisionModel)}}class zt extends $r{constructor(){super(),zt.constructor_.apply(this,arguments)}static constructor_(){this._ptLocator=new Yo,this._geomFact=null,this._resultGeom=null,this._graph=null,this._edgeList=new id,this._resultPolyList=new vt,this._resultLineList=new vt,this._resultPointList=new vt;const t=arguments[0],e=arguments[1];$r.constructor_.call(this,t,e),this._graph=new qo(new gp),this._geomFact=t.getFactory()}static overlayOp(t,e,n){return new zt(t,e).getResultGeometry(n)}static union(t,e){if(t.isEmpty()||e.isEmpty()){if(t.isEmpty()&&e.isEmpty())return zt.createEmptyResult(zt.UNION,t,e,t.getFactory());if(t.isEmpty())return e.copy();if(e.isEmpty())return t.copy()}if(t.isGeometryCollection()||e.isGeometryCollection())throw new Zt("This method does not support GeometryCollection arguments");return Si.overlayOp(t,e,zt.UNION)}static intersection(t,e){if(t.isEmpty()||e.isEmpty())return zt.createEmptyResult(zt.INTERSECTION,t,e,t.getFactory());if(t.isGeometryCollection()){const n=e;return Tf.map(t,new class{get interfaces_(){return[MapOp]}map(s){return zt.intersection(s,n)}})}return Si.overlayOp(t,e,zt.INTERSECTION)}static symDifference(t,e){if(t.isEmpty()||e.isEmpty()){if(t.isEmpty()&&e.isEmpty())return zt.createEmptyResult(zt.SYMDIFFERENCE,t,e,t.getFactory());if(t.isEmpty())return e.copy();if(e.isEmpty())return t.copy()}if(t.isGeometryCollection()||e.isGeometryCollection())throw new Zt("This method does not support GeometryCollection arguments");return Si.overlayOp(t,e,zt.SYMDIFFERENCE)}static resultDimension(t,e,n){const s=e.getDimension(),r=n.getDimension();let o=-1;switch(t){case zt.INTERSECTION:o=Math.min(s,r);break;case zt.UNION:o=Math.max(s,r);break;case zt.DIFFERENCE:o=s;break;case zt.SYMDIFFERENCE:o=Math.max(s,r);break}return o}static createEmptyResult(t,e,n,s){const r=zt.resultDimension(t,e,n);return s.createEmpty(r)}static difference(t,e){if(t.isEmpty())return zt.createEmptyResult(zt.DIFFERENCE,t,e,t.getFactory());if(e.isEmpty())return t.copy();if(t.isGeometryCollection()||e.isGeometryCollection())throw new Zt("This method does not support GeometryCollection arguments");return Si.overlayOp(t,e,zt.DIFFERENCE)}static isResultOfOp(){if(arguments.length===2){const t=arguments[0],e=arguments[1],n=t.getLocation(0),s=t.getLocation(1);return zt.isResultOfOp(n,s,e)}else if(arguments.length===3){let t=arguments[0],e=arguments[1],n=arguments[2];switch(t===q.BOUNDARY&&(t=q.INTERIOR),e===q.BOUNDARY&&(e=q.INTERIOR),n){case zt.INTERSECTION:return t===q.INTERIOR&&e===q.INTERIOR;case zt.UNION:return t===q.INTERIOR||e===q.INTERIOR;case zt.DIFFERENCE:return t===q.INTERIOR&&e!==q.INTERIOR;case zt.SYMDIFFERENCE:return t===q.INTERIOR&&e!==q.INTERIOR||t!==q.INTERIOR&&e===q.INTERIOR}return!1}}insertUniqueEdge(t){const e=this._edgeList.findEqualEdge(t);if(e!==null){const n=e.getLabel();let s=t.getLabel();e.isPointwiseEqual(t)||(s=new Be(t.getLabel()),s.flip());const r=e.getDepth();r.isNull()&&r.add(n),r.add(s),n.merge(s)}else this._edgeList.add(t)}getGraph(){return this._graph}cancelDuplicateResultEdges(){for(let t=this._graph.getEdgeEnds().iterator();t.hasNext();){const e=t.next(),n=e.getSym();e.isInResult()&&n.isInResult()&&(e.setInResult(!1),n.setInResult(!1))}}isCoveredByLA(t){return!!(this.isCovered(t,this._resultLineList)||this.isCovered(t,this._resultPolyList))}computeGeometry(t,e,n,s){const r=new vt;return r.addAll(t),r.addAll(e),r.addAll(n),r.isEmpty()?zt.createEmptyResult(s,this._arg[0].getGeometry(),this._arg[1].getGeometry(),this._geomFact):this._geomFact.buildGeometry(r)}mergeSymLabels(){for(let t=this._graph.getNodes().iterator();t.hasNext();)t.next().getEdges().mergeSymLabels()}isCovered(t,e){for(let n=e.iterator();n.hasNext();){const s=n.next();if(this._ptLocator.locate(t,s)!==q.EXTERIOR)return!0}return!1}replaceCollapsedEdges(){const t=new vt;for(let e=this._edgeList.iterator();e.hasNext();){const n=e.next();n.isCollapsed()&&(e.remove(),t.add(n.getCollapsedEdge()))}this._edgeList.addAll(t)}updateNodeLabelling(){for(let t=this._graph.getNodes().iterator();t.hasNext();){const e=t.next(),n=e.getEdges().getLabel();e.getLabel().merge(n)}}getResultGeometry(t){return this.computeOverlay(t),this._resultGeom}insertUniqueEdges(t){for(let e=t.iterator();e.hasNext();){const n=e.next();this.insertUniqueEdge(n)}}computeOverlay(t){this.copyPoints(0),this.copyPoints(1),this._arg[0].computeSelfNodes(this._li,!1),this._arg[1].computeSelfNodes(this._li,!1),this._arg[0].computeEdgeIntersections(this._arg[1],this._li,!0);const e=new vt;this._arg[0].computeSplitEdges(e),this._arg[1].computeSplitEdges(e),this.insertUniqueEdges(e),this.computeLabelsFromDepths(),this.replaceCollapsedEdges(),Iu.checkValid(this._edgeList.getEdges()),this._graph.addEdges(this._edgeList.getEdges()),this.computeLabelling(),this.labelIncompleteNodes(),this.findResultAreaEdges(t),this.cancelDuplicateResultEdges();const n=new Gu(this._geomFact);n.add(this._graph),this._resultPolyList=n.getPolygons();const s=new C0(this,this._geomFact,this._ptLocator);this._resultLineList=s.build(t);const r=new P0(this,this._geomFact,this._ptLocator);this._resultPointList=r.build(t),this._resultGeom=this.computeGeometry(this._resultPointList,this._resultLineList,this._resultPolyList,t)}labelIncompleteNode(t,e){const n=this._ptLocator.locate(t.getCoordinate(),this._arg[e].getGeometry());t.getLabel().setLocation(e,n)}copyPoints(t){for(let e=this._arg[t].getNodeIterator();e.hasNext();){const n=e.next();this._graph.addNode(n.getCoordinate()).setLabel(t,n.getLabel().getLocation(t))}}findResultAreaEdges(t){for(let e=this._graph.getEdgeEnds().iterator();e.hasNext();){const n=e.next(),s=n.getLabel();s.isArea()&&!n.isInteriorAreaEdge()&&zt.isResultOfOp(s.getLocation(0,yt.RIGHT),s.getLocation(1,yt.RIGHT),t)&&n.setInResult(!0)}}computeLabelsFromDepths(){for(let t=this._edgeList.iterator();t.hasNext();){const e=t.next(),n=e.getLabel(),s=e.getDepth();if(!s.isNull()){s.normalize();for(let r=0;r<2;r++)!n.isNull(r)&&n.isArea()&&!s.isNull(r)&&(s.getDelta(r)===0?n.toLine(r):(Yt.isTrue(!s.isNull(r,yt.LEFT),"depth of LEFT side has not been initialized"),n.setLocation(r,yt.LEFT,s.getLocation(r,yt.LEFT)),Yt.isTrue(!s.isNull(r,yt.RIGHT),"depth of RIGHT side has not been initialized"),n.setLocation(r,yt.RIGHT,s.getLocation(r,yt.RIGHT))))}}}computeLabelling(){for(let t=this._graph.getNodes().iterator();t.hasNext();)t.next().getEdges().computeLabelling(this._arg);this.mergeSymLabels(),this.updateNodeLabelling()}labelIncompleteNodes(){for(let t=this._graph.getNodes().iterator();t.hasNext();){const e=t.next(),n=e.getLabel();e.isIsolated()&&(n.isNull(0)?this.labelIncompleteNode(e,0):this.labelIncompleteNode(e,1)),e.getEdges().updateLabelling(n)}}isCoveredByA(t){return!!this.isCovered(t,this._resultPolyList)}}zt.INTERSECTION=1;zt.UNION=2;zt.DIFFERENCE=3;zt.SYMDIFFERENCE=4;class Cr{constructor(){Cr.constructor_.apply(this,arguments)}static constructor_(){this._geom=new Array(2).fill(null),this._snapTolerance=null,this._cbr=null;const t=arguments[0],e=arguments[1];this._geom[0]=t,this._geom[1]=e,this.computeSnapTolerance()}static overlayOp(t,e,n){return new Cr(t,e).getResultGeometry(n)}static union(t,e){return Cr.overlayOp(t,e,zt.UNION)}static intersection(t,e){return Cr.overlayOp(t,e,zt.INTERSECTION)}static symDifference(t,e){return Cr.overlayOp(t,e,zt.SYMDIFFERENCE)}static difference(t,e){return Cr.overlayOp(t,e,zt.DIFFERENCE)}selfSnap(t){return new bi(t).snapTo(t,this._snapTolerance)}removeCommonBits(t){this._cbr=new Mc,this._cbr.add(t[0]),this._cbr.add(t[1]);const e=new Array(2).fill(null);return e[0]=this._cbr.removeCommonBits(t[0].copy()),e[1]=this._cbr.removeCommonBits(t[1].copy()),e}prepareResult(t){return this._cbr.addCommonBits(t),t}getResultGeometry(t){const e=this.snap(this._geom),n=zt.overlayOp(e[0],e[1],t);return this.prepareResult(n)}checkValid(t){t.isValid()||ci.out.println("Snapped geometry is invalid")}computeSnapTolerance(){this._snapTolerance=bi.computeOverlaySnapTolerance(this._geom[0],this._geom[1])}snap(t){const e=this.removeCommonBits(t);return bi.snap(e[0],e[1],this._snapTolerance)}}class Si{constructor(){Si.constructor_.apply(this,arguments)}static constructor_(){this._geom=new Array(2).fill(null);const t=arguments[0],e=arguments[1];this._geom[0]=t,this._geom[1]=e}static overlayOp(t,e,n){return new Si(t,e).getResultGeometry(n)}static union(t,e){return Si.overlayOp(t,e,zt.UNION)}static intersection(t,e){return Si.overlayOp(t,e,zt.INTERSECTION)}static symDifference(t,e){return Si.overlayOp(t,e,zt.SYMDIFFERENCE)}static difference(t,e){return Si.overlayOp(t,e,zt.DIFFERENCE)}getResultGeometry(t){let e=null,n=!1,s=null;try{e=zt.overlayOp(this._geom[0],this._geom[1],t),!0&&(n=!0)}catch(r){if(r instanceof ui)s=r;else throw r}finally{}if(!n)try{e=Cr.overlayOp(this._geom[0],this._geom[1],t)}catch(r){throw r instanceof ui?s:r}finally{}return e}}class Ua{constructor(){Ua.constructor_.apply(this,arguments)}static constructor_(){this._geomFactory=null,this._polygons=new vt,this._lines=new vt,this._points=new vt,this._dimension=pt.FALSE}static extract(){if(Ot(arguments[0],sn)){const t=arguments[0],e=new Ua;return e.add(t),e}else if(arguments[0]instanceof dt){const t=arguments[0],e=new Ua;return e.add(t),e}}getFactory(){return this._geomFactory}recordDimension(t){t>this._dimension&&(this._dimension=t)}getDimension(){return this._dimension}filter(t){if(this.recordDimension(t.getDimension()),t instanceof ye||t.isEmpty())return null;if(t instanceof Te)return this._polygons.add(t),null;if(t instanceof ce)return this._lines.add(t),null;if(t instanceof Ge)return this._points.add(t),null;Yt.shouldNeverReachHere("Unhandled geometry type: "+t.getGeometryType())}getExtract(t){switch(t){case 0:return this._points;case 1:return this._lines;case 2:return this._polygons}return Yt.shouldNeverReachHere("Invalid dimension: "+t),null}isEmpty(){return this._polygons.isEmpty()&&this._lines.isEmpty()&&this._points.isEmpty()}add(){if(Ot(arguments[0],sn)){const t=arguments[0];for(const e of t)this.add(e)}else if(arguments[0]instanceof dt){const t=arguments[0];this._geomFactory===null&&(this._geomFactory=t.getFactory()),t.apply(this)}}get interfaces_(){return[Zr]}}class Ya{constructor(){Ya.constructor_.apply(this,arguments)}static constructor_(){this._comps=null;const t=arguments[0];this._comps=t}static getPolygons(){if(arguments.length===1){const t=arguments[0];return Ya.getPolygons(t,new vt)}else if(arguments.length===2){const t=arguments[0],e=arguments[1];return t instanceof Te?e.add(t):t instanceof ye&&t.apply(new Ya(e)),e}}filter(t){t instanceof Te&&this._comps.add(t)}get interfaces_(){return[Zr]}}class Ei{constructor(){Ei.constructor_.apply(this,arguments)}static constructor_(){this._geomFactory=null,this._g0=null,this._g1=null,this._isUnionSafe=null;const t=arguments[0],e=arguments[1];this._g0=t,this._g1=e,this._geomFactory=t.getFactory()}static containsProperly(){if(arguments.length===2){const t=arguments[0],e=arguments[1];return t.isNull()?!1:e.getX()>t.getMinX()&&e.getX()<t.getMaxX()&&e.getY()>t.getMinY()&&e.getY()<t.getMaxY()}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];return Ei.containsProperly(t,e)&&Ei.containsProperly(t,n)}}static union(t,e){return new Ei(t,e).union()}static intersects(t,e,n){return t.intersects(e)||t.intersects(n)}static overlapEnvelope(t,e){const n=t.getEnvelopeInternal(),s=e.getEnvelopeInternal();return n.intersection(s)}static extractBorderSegments(t,e,n){t.apply(new class{get interfaces_(){return[_l]}filter(s,r){if(r<=0)return null;const o=s.getCoordinate(r-1),a=s.getCoordinate(r);if(Ei.intersects(e,o,a)&&!Ei.containsProperly(e,o,a)){const h=new Se(o,a);n.add(h)}}isDone(){return!1}isGeometryChanged(){return!1}})}static unionBuffer(t,e){return t.getFactory().createGeometryCollection([t,e]).buffer(0)}isBorderSegmentsSame(t,e){const n=this.extractBorderSegments(this._g0,this._g1,e),s=new vt;return Ei.extractBorderSegments(t,e,s),this.isEqual(n,s)}extractByEnvelope(t,e,n){const s=new vt;for(let r=0;r<e.getNumGeometries();r++){const o=e.getGeometryN(r);if(o.getEnvelopeInternal().intersects(t))s.add(o);else{const a=o.copy();n.add(a)}}return this._geomFactory.buildGeometry(s)}isEqual(t,e){if(t.size()!==e.size())return!1;const n=new _c(t);for(const s of e)if(!n.contains(s))return!1;return!0}union(){const t=Ei.overlapEnvelope(this._g0,this._g1);if(t.isNull()){const a=this._g0.copy(),l=this._g1.copy();return ds.combine(a,l)}const e=new vt,n=this.extractByEnvelope(t,this._g0,e),s=this.extractByEnvelope(t,this._g1,e),r=this.unionFull(n,s);let o=null;return this._isUnionSafe=this.isBorderSegmentsSame(r,t),this._isUnionSafe?o=this.combine(r,e):o=this.unionFull(this._g0,this._g1),o}combine(t,e){return e.size()<=0?t:(e.add(t),ds.combine(e))}unionFull(t,e){try{return t.union(e)}catch(n){if(n instanceof ki)return Ei.unionBuffer(t,e);throw n}finally{}}extractBorderSegments(t,e,n){const s=new vt;return Ei.extractBorderSegments(t,n,s),e!==null&&Ei.extractBorderSegments(e,n,s),s}isUnionOptimized(){return this._isUnionSafe}}class Ds{constructor(){Ds.constructor_.apply(this,arguments)}static constructor_(){this._inputPolys=null,this._geomFactory=null;const t=arguments[0];this._inputPolys=t,this._inputPolys===null&&(this._inputPolys=new vt)}static restrictToPolygons(t){if(Ot(t,Jr))return t;const e=Ya.getPolygons(t);return e.size()===1?e.get(0):t.getFactory().createMultiPolygon(ze.toPolygonArray(e))}static getGeometry(t,e){return e>=t.size()?null:t.get(e)}static union(t){return new Ds(t).union()}reduceToGeometries(t){const e=new vt;for(let n=t.iterator();n.hasNext();){const s=n.next();let r=null;Ot(s,Pi)?r=this.unionTree(s):s instanceof dt&&(r=s),e.add(r)}return e}union(){if(this._inputPolys===null)throw new IllegalStateException("union() method cannot be called twice");if(this._inputPolys.isEmpty())return null;this._geomFactory=this._inputPolys.iterator().next().getFactory();const t=new Je(Ds.STRTREE_NODE_CAPACITY);for(let s=this._inputPolys.iterator();s.hasNext();){const r=s.next();t.insert(r.getEnvelopeInternal(),r)}this._inputPolys=null;const e=t.itemsTree();return this.unionTree(e)}binaryUnion(){if(arguments.length===1){const t=arguments[0];return this.binaryUnion(t,0,t.size())}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];if(n-e<=1){const s=Ds.getGeometry(t,e);return this.unionSafe(s,null)}else{if(n-e===2)return this.unionSafe(Ds.getGeometry(t,e),Ds.getGeometry(t,e+1));{const s=Math.trunc((n+e)/2),r=this.binaryUnion(t,e,s),o=this.binaryUnion(t,s,n);return this.unionSafe(r,o)}}}}repeatedUnion(t){let e=null;for(let n=t.iterator();n.hasNext();){const s=n.next();e===null?e=s.copy():e=e.union(s)}return e}unionSafe(t,e){return t===null&&e===null?null:t===null?e.copy():e===null?t.copy():this.unionActual(t,e)}unionActual(t,e){const n=Ei.union(t,e);return Ds.restrictToPolygons(n)}unionTree(t){const e=this.reduceToGeometries(t);return this.binaryUnion(e)}bufferUnion(){if(arguments.length===1){const t=arguments[0];return t.get(0).getFactory().buildGeometry(t).buffer(0)}else if(arguments.length===2){const t=arguments[0],e=arguments[1];return t.getFactory().createGeometryCollection([t,e]).buffer(0)}}}Ds.STRTREE_NODE_CAPACITY=4;class wo{constructor(){wo.constructor_.apply(this,arguments)}static constructor_(){if(this._geomFact=null,this._extracter=null,arguments.length===1){if(Ot(arguments[0],sn)){const t=arguments[0];this.extract(t)}else if(arguments[0]instanceof dt){const t=arguments[0];this.extract(t)}}else if(arguments.length===2){const t=arguments[0],e=arguments[1];this._geomFact=e,this.extract(t)}}static union(){if(arguments.length===1){if(Ot(arguments[0],sn)){const t=arguments[0];return new wo(t).union()}else if(arguments[0]instanceof dt){const t=arguments[0];return new wo(t).union()}}else if(arguments.length===2){const t=arguments[0],e=arguments[1];return new wo(t,e).union()}}unionNoOpt(t){const e=this._geomFact.createPoint();return Si.overlayOp(t,e,zt.UNION)}unionWithNull(t,e){return t===null&&e===null?null:e===null?t:t===null?e:t.union(e)}extract(){if(Ot(arguments[0],sn)){const t=arguments[0];this._extracter=Ua.extract(t)}else if(arguments[0]instanceof dt){const t=arguments[0];this._extracter=Ua.extract(t)}}union(){if(this._geomFact===null&&(this._geomFact=this._extracter.getFactory()),this._geomFact===null)return null;if(this._extracter.isEmpty())return this._geomFact.createEmpty(this._extracter.getDimension());const t=this._extracter.getExtract(0),e=this._extracter.getExtract(1),n=this._extracter.getExtract(2);let s=null;if(t.size()>0){const h=this._geomFact.buildGeometry(t);s=this.unionNoOpt(h)}let r=null;if(e.size()>0){const h=this._geomFact.buildGeometry(e);r=this.unionNoOpt(h)}let o=null;n.size()>0&&(o=Ds.union(n));const a=this.unionWithNull(r,o);let l=null;return s===null?l=a:a===null?l=s:l=Cf.union(s,a),l===null?this._geomFact.createGeometryCollection():l}}class wr{constructor(){wr.constructor_.apply(this,arguments)}static constructor_(){this._interiorPoint=null,this._maxWidth=-1;const t=arguments[0];this.process(t)}static getInteriorPoint(t){return new wr(t).getInteriorPoint()}static avg(t,e){return(t+e)/2}getInteriorPoint(){return this._interiorPoint}process(t){if(t.isEmpty())return null;if(t instanceof Te)this.processPolygon(t);else if(t instanceof ye){const e=t;for(let n=0;n<e.getNumGeometries();n++)this.process(e.getGeometryN(n))}}processPolygon(t){const e=new lr(t);e.process();const n=e.getWidth();n>this._maxWidth&&(this._maxWidth=n,this._interiorPoint=e.getInteriorPoint())}}class lr{constructor(){lr.constructor_.apply(this,arguments)}static constructor_(){this._polygon=null,this._interiorPointY=null,this._interiorSectionWidth=0,this._interiorPoint=null;const t=arguments[0];this._polygon=t,this._interiorPointY=ic.getScanLineY(t)}static isEdgeCrossingCounted(t,e,n){const s=t.getY(),r=e.getY();return!(s===r||s===n&&r<n||r===n&&s<n)}static intersectsHorizontalLine(){if(arguments.length===2){const t=arguments[0],e=arguments[1];return!(e<t.getMinY()||e>t.getMaxY())}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];return!(t.getY()>n&&e.getY()>n||t.getY()<n&&e.getY()<n)}}static intersection(t,e,n){const s=t.getX(),r=e.getX();if(s===r)return s;const o=r-s,l=(e.getY()-t.getY())/o;return s+(n-t.getY())/l}findBestMidpoint(t){if(t.size()===0)return null;Yt.isTrue(t.size()%2===0,"Interior Point robustness failure: odd number of scanline crossings"),t.sort(new YI);for(let e=0;e<t.size();e+=2){const n=t.get(e),s=t.get(e+1),r=s-n;if(r>this._interiorSectionWidth){this._interiorSectionWidth=r;const o=wr.avg(n,s);this._interiorPoint=new Z(o,this._interiorPointY)}}}process(){if(this._polygon.isEmpty())return null;this._interiorPoint=new Z(this._polygon.getCoordinate());const t=new vt;this.scanRing(this._polygon.getExteriorRing(),t);for(let e=0;e<this._polygon.getNumInteriorRing();e++)this.scanRing(this._polygon.getInteriorRingN(e),t);this.findBestMidpoint(t)}scanRing(t,e){if(!lr.intersectsHorizontalLine(t.getEnvelopeInternal(),this._interiorPointY))return null;const n=t.getCoordinateSequence();for(let s=1;s<n.size();s++){const r=n.getCoordinate(s-1),o=n.getCoordinate(s);this.addEdgeCrossing(r,o,this._interiorPointY,e)}}getWidth(){return this._interiorSectionWidth}getInteriorPoint(){return this._interiorPoint}addEdgeCrossing(t,e,n,s){if(!lr.intersectsHorizontalLine(t,e,n)||!lr.isEdgeCrossingCounted(t,e,n))return null;const r=lr.intersection(t,e,n);s.add(r)}}class YI{compare(t,e){return t<e?-1:t>e?1:0}get interfaces_(){return[Kr]}}lr.DoubleComparator=YI;class ic{constructor(){ic.constructor_.apply(this,arguments)}static constructor_(){this._poly=null,this._centreY=null,this._hiY=Rt.MAX_VALUE,this._loY=-Rt.MAX_VALUE;const t=arguments[0];this._poly=t,this._hiY=t.getEnvelopeInternal().getMaxY(),this._loY=t.getEnvelopeInternal().getMinY(),this._centreY=wr.avg(this._loY,this._hiY)}static getScanLineY(t){return new ic(t).getScanLineY()}updateInterval(t){t<=this._centreY?t>this._loY&&(this._loY=t):t>this._centreY&&t<this._hiY&&(this._hiY=t)}getScanLineY(){this.process(this._poly.getExteriorRing());for(let e=0;e<this._poly.getNumInteriorRing();e++)this.process(this._poly.getInteriorRingN(e));return wr.avg(this._hiY,this._loY)}process(t){const e=t.getCoordinateSequence();for(let n=0;n<e.size();n++){const s=e.getY(n);this.updateInterval(s)}}}wr.InteriorPointPolygon=lr;wr.ScanLineYOrdinateFinder=ic;class k0{get interfaces_(){return[]}getClass(){return k0}static union(t,e){if(t.isEmpty()||e.isEmpty()){if(t.isEmpty()&&e.isEmpty())return zt.createEmptyResult(zt.UNION,t,e,t.getFactory());if(t.isEmpty())return e.copy();if(e.isEmpty())return t.copy()}return t.checkNotGeometryCollection(t),t.checkNotGeometryCollection(e),Si.overlayOp(t,e,zt.UNION)}}class Ar{constructor(){Ar.constructor_.apply(this,arguments)}static constructor_(){this._areaBasePt=null,this._triangleCent3=new Z,this._areasum2=0,this._cg3=new Z,this._lineCentSum=new Z,this._totalLength=0,this._ptCount=0,this._ptCentSum=new Z;const t=arguments[0];this._areaBasePt=null,this.add(t)}static area2(t,e,n){return(e.x-t.x)*(n.y-t.y)-(n.x-t.x)*(e.y-t.y)}static centroid3(t,e,n,s){return s.x=t.x+e.x+n.x,s.y=t.y+e.y+n.y,null}static getCentroid(t){return new Ar(t).getCentroid()}setAreaBasePoint(t){this._areaBasePt=t}addPoint(t){this._ptCount+=1,this._ptCentSum.x+=t.x,this._ptCentSum.y+=t.y}addLineSegments(t){let e=0;for(let n=0;n<t.length-1;n++){const s=t[n].distance(t[n+1]);if(s===0)continue;e+=s;const r=(t[n].x+t[n+1].x)/2;this._lineCentSum.x+=s*r;const o=(t[n].y+t[n+1].y)/2;this._lineCentSum.y+=s*o}this._totalLength+=e,e===0&&t.length>0&&this.addPoint(t[0])}addHole(t){const e=$t.isCCW(t);for(let n=0;n<t.length-1;n++)this.addTriangle(this._areaBasePt,t[n],t[n+1],e);this.addLineSegments(t)}getCentroid(){const t=new Z;if(Math.abs(this._areasum2)>0)t.x=this._cg3.x/3/this._areasum2,t.y=this._cg3.y/3/this._areasum2;else if(this._totalLength>0)t.x=this._lineCentSum.x/this._totalLength,t.y=this._lineCentSum.y/this._totalLength;else if(this._ptCount>0)t.x=this._ptCentSum.x/this._ptCount,t.y=this._ptCentSum.y/this._ptCount;else return null;return t}addShell(t){t.length>0&&this.setAreaBasePoint(t[0]);const e=!$t.isCCW(t);for(let n=0;n<t.length-1;n++)this.addTriangle(this._areaBasePt,t[n],t[n+1],e);this.addLineSegments(t)}addTriangle(t,e,n,s){const r=s?1:-1;Ar.centroid3(t,e,n,this._triangleCent3);const o=Ar.area2(t,e,n);this._cg3.x+=r*o*this._triangleCent3.x,this._cg3.y+=r*o*this._triangleCent3.y,this._areasum2+=r*o}add(){if(arguments[0]instanceof Te){const t=arguments[0];this.addShell(t.getExteriorRing().getCoordinates());for(let e=0;e<t.getNumInteriorRing();e++)this.addHole(t.getInteriorRingN(e).getCoordinates())}else if(arguments[0]instanceof dt){const t=arguments[0];if(t.isEmpty())return null;if(t instanceof Ge)this.addPoint(t.getCoordinate());else if(t instanceof ce)this.addLineSegments(t.getCoordinates());else if(t instanceof Te){const e=t;this.add(e)}else if(t instanceof ye){const e=t;for(let n=0;n<e.getNumGeometries();n++)this.add(e.getGeometryN(n))}}}}class Rf{constructor(){Rf.constructor_.apply(this,arguments)}static constructor_(){this._centroid=null,this._minDistance=Rt.MAX_VALUE,this._interiorPoint=null;const t=arguments[0];t.isEmpty()?this._centroid=null:(this._centroid=Ar.getCentroid(t),t.getPrecisionModel().makePrecise(this._centroid)),this.addInterior(t),this._interiorPoint===null&&this.addEndpoints(t)}static getInteriorPoint(t){return new Rf(t).getInteriorPoint()}addEndpoints(){if(arguments[0]instanceof dt){const t=arguments[0];if(t instanceof ce)this.addEndpoints(t.getCoordinates());else if(t instanceof ye){const e=t;for(let n=0;n<e.getNumGeometries();n++)this.addEndpoints(e.getGeometryN(n))}}else if(arguments[0]instanceof Array){const t=arguments[0];this.add(t[0]),this.add(t[t.length-1])}}getInteriorPoint(){return this._interiorPoint}addInterior(){if(arguments[0]instanceof dt){const t=arguments[0];if(t instanceof ce)this.addInterior(t.getCoordinates());else if(t instanceof ye){const e=t;for(let n=0;n<e.getNumGeometries();n++)this.addInterior(e.getGeometryN(n))}}else if(arguments[0]instanceof Array){const t=arguments[0];for(let e=1;e<t.length-1;e++)this.add(t[e])}}add(t){const e=t.distance(this._centroid);e<this._minDistance&&(this._interiorPoint=new Z(t),this._minDistance=e)}}class sc{constructor(){sc.constructor_.apply(this,arguments)}static constructor_(){this._coordSet=new _c,this._list=new vt}static filterCoordinates(t){const e=new sc;for(let n=0;n<t.length;n++)e.filter(t[n]);return e.getCoordinates()}filter(t){this._coordSet.add(t)&&this._list.add(t)}getCoordinates(){const t=new Array(this._list.size()).fill(null);return this._list.toArray(t)}get interfaces_(){return[yl]}}class Xa{constructor(){Xa.constructor_.apply(this,arguments)}static constructor_(){if(this._geomFactory=null,this._inputPts=null,arguments.length===1){const t=arguments[0];Xa.constructor_.call(this,Xa.extractCoordinates(t),t.getFactory())}else if(arguments.length===2){const t=arguments[0],e=arguments[1];this._inputPts=sc.filterCoordinates(t),this._geomFactory=e}}static extractCoordinates(t){const e=new sc;return t.apply(e),e.getCoordinates()}preSort(t){let e=null;for(let n=1;n<t.length;n++)(t[n].y<t[0].y||t[n].y===t[0].y&&t[n].x<t[0].x)&&(e=t[0],t[0]=t[n],t[n]=e);return Or.sort(t,1,t.length,new rc(t[0])),t}computeOctRing(t){const e=this.computeOctPts(t),n=new Qi;return n.add(e,!1),n.size()<3?null:(n.closeRing(),n.toCoordinateArray())}lineOrPolygon(t){if(t=this.cleanRing(t),t.length===3)return this._geomFactory.createLineString([t[0],t[1]]);const e=this._geomFactory.createLinearRing(t);return this._geomFactory.createPolygon(e)}cleanRing(t){Yt.equals(t[0],t[t.length-1]);const e=new vt;let n=null;for(let r=0;r<=t.length-2;r++){const o=t[r],a=t[r+1];o.equals(a)||n!==null&&this.isBetween(n,o,a)||(e.add(o),n=o)}e.add(t[t.length-1]);const s=new Array(e.size()).fill(null);return e.toArray(s)}isBetween(t,e,n){return $t.index(t,e,n)!==0?!1:t.x!==n.x&&(t.x<=e.x&&e.x<=n.x||n.x<=e.x&&e.x<=t.x)||t.y!==n.y&&(t.y<=e.y&&e.y<=n.y||n.y<=e.y&&e.y<=t.y)}reduce(t){const e=this.computeOctRing(t);if(e===null)return t;const n=new Ao;for(let r=0;r<e.length;r++)n.add(e[r]);for(let r=0;r<t.length;r++)ts.isInRing(t[r],e)||n.add(t[r]);const s=Le.toCoordinateArray(n);return s.length<3?this.padArray3(s):s}getConvexHull(){if(this._inputPts.length===0)return this._geomFactory.createGeometryCollection();if(this._inputPts.length===1)return this._geomFactory.createPoint(this._inputPts[0]);if(this._inputPts.length===2)return this._geomFactory.createLineString(this._inputPts);let t=this._inputPts;this._inputPts.length>50&&(t=this.reduce(this._inputPts));const e=this.preSort(t),n=this.grahamScan(e),s=this.toCoordinateArray(n);return this.lineOrPolygon(s)}padArray3(t){const e=new Array(3).fill(null);for(let n=0;n<e.length;n++)n<t.length?e[n]=t[n]:e[n]=t[0];return e}computeOctPts(t){const e=new Array(8).fill(null);for(let n=0;n<e.length;n++)e[n]=t[0];for(let n=1;n<t.length;n++)t[n].x<e[0].x&&(e[0]=t[n]),t[n].x-t[n].y<e[1].x-e[1].y&&(e[1]=t[n]),t[n].y>e[2].y&&(e[2]=t[n]),t[n].x+t[n].y>e[3].x+e[3].y&&(e[3]=t[n]),t[n].x>e[4].x&&(e[4]=t[n]),t[n].x-t[n].y>e[5].x-e[5].y&&(e[5]=t[n]),t[n].y<e[6].y&&(e[6]=t[n]),t[n].x+t[n].y<e[7].x+e[7].y&&(e[7]=t[n]);return e}toCoordinateArray(t){const e=new Array(t.size()).fill(null);for(let n=0;n<t.size();n++){const s=t.get(n);e[n]=s}return e}grahamScan(t){let e=null;const n=new kw;n.push(t[0]),n.push(t[1]),n.push(t[2]);for(let s=3;s<t.length;s++){for(e=n.pop();!n.empty()&&$t.index(n.peek(),e,t[s])>0;)e=n.pop();n.push(e),n.push(t[s])}return n.push(t[0]),n}}class rc{constructor(){rc.constructor_.apply(this,arguments)}static constructor_(){this._origin=null;const t=arguments[0];this._origin=t}static polarCompare(t,e,n){const s=e.x-t.x,r=e.y-t.y,o=n.x-t.x,a=n.y-t.y,l=$t.index(t,e,n);if(l===$t.COUNTERCLOCKWISE)return 1;if(l===$t.CLOCKWISE)return-1;const h=s*s+r*r,f=o*o+a*a;return h<f?-1:h>f?1:0}compare(t,e){const n=t,s=e;return rc.polarCompare(this._origin,n,s)}get interfaces_(){return[Kr]}}Xa.RadialComparator=rc;class Af{constructor(){Af.constructor_.apply(this,arguments)}static constructor_(){this._li=new Nn,this._ptLocator=new Yo,this._arg=null,this._nodes=new ol(new UI),this._im=null,this._isolatedEdges=new vt,this._invalidPoint=null;const t=arguments[0];this._arg=t}insertEdgeEnds(t){for(let e=t.iterator();e.hasNext();){const n=e.next();this._nodes.add(n)}}computeProperIntersectionIM(t,e){const n=this._arg[0].getGeometry().getDimension(),s=this._arg[1].getGeometry().getDimension(),r=t.hasProperIntersection(),o=t.hasProperInteriorIntersection();n===2&&s===2?r&&e.setAtLeast("212101212"):n===2&&s===1?(r&&e.setAtLeast("FFF0FFFF2"),o&&e.setAtLeast("1FFFFF1FF")):n===1&&s===2?(r&&e.setAtLeast("F0FFFFFF2"),o&&e.setAtLeast("1F1FFFFFF")):n===1&&s===1&&o&&e.setAtLeast("0FFFFFFFF")}labelIsolatedEdges(t,e){for(let n=this._arg[t].getEdgeIterator();n.hasNext();){const s=n.next();s.isIsolated()&&(this.labelIsolatedEdge(s,e,this._arg[e].getGeometry()),this._isolatedEdges.add(s))}}labelIsolatedEdge(t,e,n){if(n.getDimension()>0){const s=this._ptLocator.locate(t.getCoordinate(),n);t.getLabel().setAllLocations(e,s)}else t.getLabel().setAllLocations(e,q.EXTERIOR)}computeIM(){const t=new me;if(t.set(q.EXTERIOR,q.EXTERIOR,2),!this._arg[0].getGeometry().getEnvelopeInternal().intersects(this._arg[1].getGeometry().getEnvelopeInternal()))return this.computeDisjointIM(t),t;this._arg[0].computeSelfNodes(this._li,!1),this._arg[1].computeSelfNodes(this._li,!1);const e=this._arg[0].computeEdgeIntersections(this._arg[1],this._li,!1);this.computeIntersectionNodes(0),this.computeIntersectionNodes(1),this.copyNodesAndLabels(0),this.copyNodesAndLabels(1),this.labelIsolatedNodes(),this.computeProperIntersectionIM(e,t);const n=new zI,s=n.computeEdgeEnds(this._arg[0].getEdgeIterator());this.insertEdgeEnds(s);const r=n.computeEdgeEnds(this._arg[1].getEdgeIterator());return this.insertEdgeEnds(r),this.labelNodeEdges(),this.labelIsolatedEdges(0,1),this.labelIsolatedEdges(1,0),this.updateIM(t),t}labelNodeEdges(){for(let t=this._nodes.iterator();t.hasNext();)t.next().getEdges().computeLabelling(this._arg)}copyNodesAndLabels(t){for(let e=this._arg[t].getNodeIterator();e.hasNext();){const n=e.next();this._nodes.addNode(n.getCoordinate()).setLabel(t,n.getLabel().getLocation(t))}}labelIntersectionNodes(t){for(let e=this._arg[t].getEdgeIterator();e.hasNext();){const n=e.next(),s=n.getLabel().getLocation(t);for(let r=n.getEdgeIntersectionList().iterator();r.hasNext();){const o=r.next(),a=this._nodes.find(o.coord);a.getLabel().isNull(t)&&(s===q.BOUNDARY?a.setLabelBoundary(t):a.setLabel(t,q.INTERIOR))}}}labelIsolatedNode(t,e){const n=this._ptLocator.locate(t.getCoordinate(),this._arg[e].getGeometry());t.getLabel().setAllLocations(e,n)}computeIntersectionNodes(t){for(let e=this._arg[t].getEdgeIterator();e.hasNext();){const n=e.next(),s=n.getLabel().getLocation(t);for(let r=n.getEdgeIntersectionList().iterator();r.hasNext();){const o=r.next(),a=this._nodes.addNode(o.coord);s===q.BOUNDARY?a.setLabelBoundary(t):a.getLabel().isNull(t)&&a.setLabel(t,q.INTERIOR)}}}labelIsolatedNodes(){for(let t=this._nodes.iterator();t.hasNext();){const e=t.next(),n=e.getLabel();Yt.isTrue(n.getGeometryCount()>0,"node with empty label found"),e.isIsolated()&&(n.isNull(0)?this.labelIsolatedNode(e,0):this.labelIsolatedNode(e,1))}}updateIM(t){for(let e=this._isolatedEdges.iterator();e.hasNext();)e.next().updateIM(t);for(let e=this._nodes.iterator();e.hasNext();){const n=e.next();n.updateIM(t),n.updateIMFromEdges(t)}}computeDisjointIM(t){const e=this._arg[0].getGeometry();e.isEmpty()||(t.set(q.INTERIOR,q.EXTERIOR,e.getDimension()),t.set(q.BOUNDARY,q.EXTERIOR,e.getBoundaryDimension()));const n=this._arg[1].getGeometry();n.isEmpty()||(t.set(q.EXTERIOR,q.INTERIOR,n.getDimension()),t.set(q.EXTERIOR,q.BOUNDARY,n.getBoundaryDimension()))}}class Of{constructor(){Of.constructor_.apply(this,arguments)}static constructor_(){this._rectEnv=null;const t=arguments[0];this._rectEnv=t.getEnvelopeInternal()}static contains(t,e){return new Of(t).contains(e)}isContainedInBoundary(t){if(t instanceof Te)return!1;if(t instanceof Ge)return this.isPointContainedInBoundary(t);if(t instanceof ce)return this.isLineStringContainedInBoundary(t);for(let e=0;e<t.getNumGeometries();e++){const n=t.getGeometryN(e);if(!this.isContainedInBoundary(n))return!1}return!0}isLineSegmentContainedInBoundary(t,e){if(t.equals(e))return this.isPointContainedInBoundary(t);if(t.x===e.x){if(t.x===this._rectEnv.getMinX()||t.x===this._rectEnv.getMaxX())return!0}else if(t.y===e.y&&(t.y===this._rectEnv.getMinY()||t.y===this._rectEnv.getMaxY()))return!0;return!1}isLineStringContainedInBoundary(t){const e=t.getCoordinateSequence(),n=new Z,s=new Z;for(let r=0;r<e.size()-1;r++)if(e.getCoordinate(r,n),e.getCoordinate(r+1,s),!this.isLineSegmentContainedInBoundary(n,s))return!1;return!0}isPointContainedInBoundary(){if(arguments[0]instanceof Ge){const t=arguments[0];return this.isPointContainedInBoundary(t.getCoordinate())}else if(arguments[0]instanceof Z){const t=arguments[0];return t.x===this._rectEnv.getMinX()||t.x===this._rectEnv.getMaxX()||t.y===this._rectEnv.getMinY()||t.y===this._rectEnv.getMaxY()}}contains(t){return!(!this._rectEnv.contains(t.getEnvelopeInternal())||this.isContainedInBoundary(t))}}class T0{constructor(){T0.constructor_.apply(this,arguments)}static constructor_(){this._li=new Nn,this._rectEnv=null,this._diagUp0=null,this._diagUp1=null,this._diagDown0=null,this._diagDown1=null;const t=arguments[0];this._rectEnv=t,this._diagUp0=new Z(t.getMinX(),t.getMinY()),this._diagUp1=new Z(t.getMaxX(),t.getMaxY()),this._diagDown0=new Z(t.getMinX(),t.getMaxY()),this._diagDown1=new Z(t.getMaxX(),t.getMinY())}intersects(t,e){const n=new te(t,e);if(!this._rectEnv.intersects(n))return!1;if(this._rectEnv.intersects(t)||this._rectEnv.intersects(e))return!0;if(t.compareTo(e)>0){const r=t;t=e,e=r}let s=!1;return e.y>t.y&&(s=!0),s?this._li.computeIntersection(t,e,this._diagDown0,this._diagDown1):this._li.computeIntersection(t,e,this._diagUp0,this._diagUp1),!!this._li.hasIntersection()}}class Nc{constructor(){Nc.constructor_.apply(this,arguments)}static constructor_(){this._isDone=!1}applyTo(t){for(let e=0;e<t.getNumGeometries()&&!this._isDone;e++){const n=t.getGeometryN(e);if(n instanceof ye)this.applyTo(n);else if(this.visit(n),this.isDone())return this._isDone=!0,null}}}class oc{constructor(){oc.constructor_.apply(this,arguments)}static constructor_(){this._rectangle=null,this._rectEnv=null;const t=arguments[0];this._rectangle=t,this._rectEnv=t.getEnvelopeInternal()}static intersects(t,e){return new oc(t).intersects(e)}intersects(t){if(!this._rectEnv.intersects(t.getEnvelopeInternal()))return!1;const e=new R0(this._rectEnv);if(e.applyTo(t),e.intersects())return!0;const n=new A0(this._rectangle);if(n.applyTo(t),n.containsPoint())return!0;const s=new O0(this._rectangle);return s.applyTo(t),!!s.intersects()}}class R0 extends Nc{constructor(){super(),R0.constructor_.apply(this,arguments)}static constructor_(){this._rectEnv=null,this._intersects=!1;const t=arguments[0];this._rectEnv=t}isDone(){return this._intersects===!0}visit(t){const e=t.getEnvelopeInternal();if(!this._rectEnv.intersects(e))return null;if(this._rectEnv.contains(e))return this._intersects=!0,null;if(e.getMinX()>=this._rectEnv.getMinX()&&e.getMaxX()<=this._rectEnv.getMaxX())return this._intersects=!0,null;if(e.getMinY()>=this._rectEnv.getMinY()&&e.getMaxY()<=this._rectEnv.getMaxY())return this._intersects=!0,null}intersects(){return this._intersects}}class A0 extends Nc{constructor(){super(),A0.constructor_.apply(this,arguments)}static constructor_(){this._rectSeq=null,this._rectEnv=null,this._containsPoint=!1;const t=arguments[0];this._rectSeq=t.getExteriorRing().getCoordinateSequence(),this._rectEnv=t.getEnvelopeInternal()}isDone(){return this._containsPoint===!0}visit(t){if(!(t instanceof Te))return null;const e=t.getEnvelopeInternal();if(!this._rectEnv.intersects(e))return null;const n=new Z;for(let s=0;s<4;s++)if(this._rectSeq.getCoordinate(s,n),!!e.contains(n)&&Yi.containsPointInPolygon(n,t))return this._containsPoint=!0,null}containsPoint(){return this._containsPoint}}class O0 extends Nc{constructor(){super(),O0.constructor_.apply(this,arguments)}static constructor_(){this._rectEnv=null,this._rectIntersector=null,this._hasIntersection=!1,this._p0=new Z,this._p1=new Z;const t=arguments[0];this._rectEnv=t.getEnvelopeInternal(),this._rectIntersector=new T0(this._rectEnv)}intersects(){return this._hasIntersection}isDone(){return this._hasIntersection===!0}visit(t){const e=t.getEnvelopeInternal();if(!this._rectEnv.intersects(e))return null;const n=Vn.getLines(t);this.checkIntersectionWithLineStrings(n)}checkIntersectionWithLineStrings(t){for(let e=t.iterator();e.hasNext();){const n=e.next();if(this.checkIntersectionWithSegments(n),this._hasIntersection)return null}}checkIntersectionWithSegments(t){const e=t.getCoordinateSequence();for(let n=1;n<e.size();n++)if(e.getCoordinate(n-1,this._p0),e.getCoordinate(n,this._p1),this._rectIntersector.intersects(this._p0,this._p1))return this._hasIntersection=!0,null}}class Ue extends $r{constructor(){super(),Ue.constructor_.apply(this,arguments)}static constructor_(){if(this._relate=null,arguments.length===2){const t=arguments[0],e=arguments[1];$r.constructor_.call(this,t,e),this._relate=new Af(this._arg)}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];$r.constructor_.call(this,t,e,n),this._relate=new Af(this._arg)}}static covers(t,e){return e.getDimension()===2&&t.getDimension()<2||e.getDimension()===1&&t.getDimension()<1&&e.getLength()>0||!t.getEnvelopeInternal().covers(e.getEnvelopeInternal())?!1:t.isRectangle()?!0:new Ue(t,e).getIntersectionMatrix().isCovers()}static intersects(t,e){if(!t.getEnvelopeInternal().intersects(e.getEnvelopeInternal()))return!1;if(t.isRectangle())return oc.intersects(t,e);if(e.isRectangle())return oc.intersects(e,t);if(t.isGeometryCollection()||e.isGeometryCollection()){for(let n=0;n<t.getNumGeometries();n++)for(let s=0;s<e.getNumGeometries();s++)if(t.getGeometryN(n).intersects(e.getGeometryN(s)))return!0;return!1}return new Ue(t,e).getIntersectionMatrix().isIntersects()}static touches(t,e){return t.getEnvelopeInternal().intersects(e.getEnvelopeInternal())?new Ue(t,e).getIntersectionMatrix().isTouches(t.getDimension(),e.getDimension()):!1}static equalsTopo(t,e){return t.getEnvelopeInternal().equals(e.getEnvelopeInternal())?Ue.relate(t,e).isEquals(t.getDimension(),e.getDimension()):!1}static relate(){if(arguments.length===2){const t=arguments[0],e=arguments[1];return new Ue(t,e).getIntersectionMatrix()}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];return new Ue(t,e,n).getIntersectionMatrix()}}static overlaps(t,e){return t.getEnvelopeInternal().intersects(e.getEnvelopeInternal())?new Ue(t,e).getIntersectionMatrix().isOverlaps(t.getDimension(),e.getDimension()):!1}static crosses(t,e){return t.getEnvelopeInternal().intersects(e.getEnvelopeInternal())?new Ue(t,e).getIntersectionMatrix().isCrosses(t.getDimension(),e.getDimension()):!1}static contains(t,e){return e.getDimension()===2&&t.getDimension()<2||e.getDimension()===1&&t.getDimension()<1&&e.getLength()>0||!t.getEnvelopeInternal().contains(e.getEnvelopeInternal())?!1:t.isRectangle()?Of.contains(t,e):new Ue(t,e).getIntersectionMatrix().isContains()}getIntersectionMatrix(){return this._relate.computeIM()}}class Ff{constructor(){Ff.constructor_.apply(this,arguments)}static constructor_(){this._centroid=null,this._minDistance=Rt.MAX_VALUE,this._interiorPoint=null;const t=arguments[0];this._centroid=Ar.getCentroid(t),this.add(t)}static getInteriorPoint(t){return new Ff(t).getInteriorPoint()}getInteriorPoint(){return this._interiorPoint}add(){if(arguments[0]instanceof dt){const t=arguments[0];if(t instanceof Ge)this.add(t.getCoordinate());else if(t instanceof ye){const e=t;for(let n=0;n<e.getNumGeometries();n++)this.add(e.getGeometryN(n))}}else if(arguments[0]instanceof Z){const t=arguments[0],e=t.distance(this._centroid);e<this._minDistance&&(this._interiorPoint=new Z(t),this._minDistance=e)}}}class Hn{constructor(){Hn.constructor_.apply(this,arguments)}static constructor_(){if(this._component=null,this._segIndex=null,this._pt=null,arguments.length===2){const t=arguments[0],e=arguments[1];Hn.constructor_.call(this,t,Hn.INSIDE_AREA,e)}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];this._component=t,this._segIndex=e,this._pt=n}}getSegmentIndex(){return this._segIndex}getCoordinate(){return this._pt}isInsideArea(){return this._segIndex===Hn.INSIDE_AREA}toString(){return this._component.getGeometryType()+"["+this._segIndex+"]-"+Js.toPoint(this._pt)}getGeometryComponent(){return this._component}}Hn.INSIDE_AREA=-1;class ja{constructor(){ja.constructor_.apply(this,arguments)}static constructor_(){this._pts=null;const t=arguments[0];this._pts=t}static getPoints(){if(arguments.length===1){const t=arguments[0];return t instanceof Ge?_r.singletonList(t):ja.getPoints(t,new vt)}else if(arguments.length===2){const t=arguments[0],e=arguments[1];return t instanceof Ge?e.add(t):t instanceof ye&&t.apply(new ja(e)),e}}filter(t){t instanceof Ge&&this._pts.add(t)}get interfaces_(){return[Zr]}}class $f{constructor(){$f.constructor_.apply(this,arguments)}static constructor_(){this._locations=null;const t=arguments[0];this._locations=t}static getLocations(t){const e=new vt;return t.apply(new $f(e)),e}filter(t){if(t.isEmpty())return null;(t instanceof Ge||t instanceof ce||t instanceof Te)&&this._locations.add(new Hn(t,0,t.getCoordinate()))}get interfaces_(){return[Zr]}}class kr{constructor(){kr.constructor_.apply(this,arguments)}static constructor_(){if(this._geom=null,this._terminateDistance=0,this._ptLocator=new Yo,this._minDistanceLocation=null,this._minDistance=Rt.MAX_VALUE,arguments.length===2){const t=arguments[0],e=arguments[1];kr.constructor_.call(this,t,e,0)}else if(arguments.length===3){const t=arguments[0],e=arguments[1],n=arguments[2];this._geom=new Array(2).fill(null),this._geom[0]=t,this._geom[1]=e,this._terminateDistance=n}}static distance(t,e){return new kr(t,e).distance()}static isWithinDistance(t,e,n){return t.getEnvelopeInternal().distance(e.getEnvelopeInternal())>n?!1:new kr(t,e,n).distance()<=n}static nearestPoints(t,e){return new kr(t,e).nearestPoints()}computeContainmentDistance(){if(arguments.length===0){const t=new Array(2).fill(null);if(this.computeContainmentDistance(0,t),this._minDistance<=this._terminateDistance)return null;this.computeContainmentDistance(1,t)}else if(arguments.length===2){const t=arguments[0],e=arguments[1],n=this._geom[t];if(n.getDimension()<2)return null;const s=1-t,r=Ya.getPolygons(n);if(r.size()>0){const o=$f.getLocations(this._geom[s]);if(this.computeContainmentDistance(o,r,e),this._minDistance<=this._terminateDistance)return this._minDistanceLocation[s]=e[0],this._minDistanceLocation[t]=e[1],null}}else if(arguments.length===3){if(arguments[2]instanceof Array&&Ot(arguments[0],Pi)&&Ot(arguments[1],Pi)){const t=arguments[0],e=arguments[1],n=arguments[2];for(let s=0;s<t.size();s++){const r=t.get(s);for(let o=0;o<e.size();o++)if(this.computeContainmentDistance(r,e.get(o),n),this._minDistance<=this._terminateDistance)return null}}else if(arguments[2]instanceof Array&&arguments[0]instanceof Hn&&arguments[1]instanceof Te){const t=arguments[0],e=arguments[1],n=arguments[2],s=t.getCoordinate();if(q.EXTERIOR!==this._ptLocator.locate(s,e))return this._minDistance=0,n[0]=t,n[1]=new Hn(e,s),null}}}computeMinDistanceLinesPoints(t,e,n){for(let s=0;s<t.size();s++){const r=t.get(s);for(let o=0;o<e.size();o++){const a=e.get(o);if(this.computeMinDistance(r,a,n),this._minDistance<=this._terminateDistance)return null}}}computeFacetDistance(){const t=new Array(2).fill(null),e=Vn.getLines(this._geom[0]),n=Vn.getLines(this._geom[1]),s=ja.getPoints(this._geom[0]),r=ja.getPoints(this._geom[1]);if(this.computeMinDistanceLines(e,n,t),this.updateMinDistance(t,!1),this._minDistance<=this._terminateDistance||(t[0]=null,t[1]=null,this.computeMinDistanceLinesPoints(e,r,t),this.updateMinDistance(t,!1),this._minDistance<=this._terminateDistance)||(t[0]=null,t[1]=null,this.computeMinDistanceLinesPoints(n,s,t),this.updateMinDistance(t,!0),this._minDistance<=this._terminateDistance))return null;t[0]=null,t[1]=null,this.computeMinDistancePoints(s,r,t),this.updateMinDistance(t,!1)}nearestLocations(){return this.computeMinDistance(),this._minDistanceLocation}updateMinDistance(t,e){if(t[0]===null)return null;e?(this._minDistanceLocation[0]=t[1],this._minDistanceLocation[1]=t[0]):(this._minDistanceLocation[0]=t[0],this._minDistanceLocation[1]=t[1])}nearestPoints(){return this.computeMinDistance(),[this._minDistanceLocation[0].getCoordinate(),this._minDistanceLocation[1].getCoordinate()]}computeMinDistance(){if(arguments.length===0){if(this._minDistanceLocation!==null||(this._minDistanceLocation=new Array(2).fill(null),this.computeContainmentDistance(),this._minDistance<=this._terminateDistance))return null;this.computeFacetDistance()}else if(arguments.length===3){if(arguments[2]instanceof Array&&arguments[0]instanceof ce&&arguments[1]instanceof Ge){const t=arguments[0],e=arguments[1],n=arguments[2];if(t.getEnvelopeInternal().distance(e.getEnvelopeInternal())>this._minDistance)return null;const s=t.getCoordinates(),r=e.getCoordinate();for(let o=0;o<s.length-1;o++){const a=hn.pointToSegment(r,s[o],s[o+1]);if(a<this._minDistance){this._minDistance=a;const h=new Se(s[o],s[o+1]).closestPoint(r);n[0]=new Hn(t,o,h),n[1]=new Hn(e,0,r)}if(this._minDistance<=this._terminateDistance)return null}}else if(arguments[2]instanceof Array&&arguments[0]instanceof ce&&arguments[1]instanceof ce){const t=arguments[0],e=arguments[1],n=arguments[2];if(t.getEnvelopeInternal().distance(e.getEnvelopeInternal())>this._minDistance)return null;const s=t.getCoordinates(),r=e.getCoordinates();for(let o=0;o<s.length-1;o++){const a=new te(s[o],s[o+1]);if(!(a.distance(e.getEnvelopeInternal())>this._minDistance))for(let l=0;l<r.length-1;l++){const h=new te(r[l],r[l+1]);if(a.distance(h)>this._minDistance)continue;const f=hn.segmentToSegment(s[o],s[o+1],r[l],r[l+1]);if(f<this._minDistance){this._minDistance=f;const d=new Se(s[o],s[o+1]),p=new Se(r[l],r[l+1]),y=d.closestPoints(p);n[0]=new Hn(t,o,y[0]),n[1]=new Hn(e,l,y[1])}if(this._minDistance<=this._terminateDistance)return null}}}}}computeMinDistancePoints(t,e,n){for(let s=0;s<t.size();s++){const r=t.get(s);for(let o=0;o<e.size();o++){const a=e.get(o),l=r.getCoordinate().distance(a.getCoordinate());if(l<this._minDistance&&(this._minDistance=l,n[0]=new Hn(r,0,r.getCoordinate()),n[1]=new Hn(a,0,a.getCoordinate())),this._minDistance<=this._terminateDistance)return null}}}distance(){if(this._geom[0]===null||this._geom[1]===null)throw new Zt("null geometries are not supported");return this._geom[0].isEmpty()||this._geom[1].isEmpty()?0:(this.computeMinDistance(),this._minDistance)}computeMinDistanceLines(t,e,n){for(let s=0;s<t.size();s++){const r=t.get(s);for(let o=0;o<e.size();o++){const a=e.get(o);if(this.computeMinDistance(r,a,n),this._minDistance<=this._terminateDistance)return null}}}}class xo{constructor(){xo.constructor_.apply(this,arguments)}static constructor_(){if(this._geom=null,this._geomFact=null,this._bnRule=null,this._endpointMap=null,arguments.length===1){const t=arguments[0];xo.constructor_.call(this,t,En.MOD2_BOUNDARY_RULE)}else if(arguments.length===2){const t=arguments[0],e=arguments[1];this._geom=t,this._geomFact=t.getFactory(),this._bnRule=e}}static getBoundary(){if(arguments.length===1){const t=arguments[0];return new xo(t).getBoundary()}else if(arguments.length===2){const t=arguments[0],e=arguments[1];return new xo(t,e).getBoundary()}}boundaryMultiLineString(t){if(this._geom.isEmpty())return this.getEmptyMultiPoint();const e=this.computeBoundaryCoordinates(t);return e.length===1?this._geomFact.createPoint(e[0]):this._geomFact.createMultiPointFromCoords(e)}getBoundary(){return this._geom instanceof ce?this.boundaryLineString(this._geom):this._geom instanceof ns?this.boundaryMultiLineString(this._geom):this._geom.getBoundary()}boundaryLineString(t){return this._geom.isEmpty()?this.getEmptyMultiPoint():t.isClosed()?this._bnRule.isInBoundary(2)?t.getStartPoint():this._geomFact.createMultiPoint():this._geomFact.createMultiPoint([t.getStartPoint(),t.getEndPoint()])}getEmptyMultiPoint(){return this._geomFact.createMultiPoint()}computeBoundaryCoordinates(t){const e=new vt;this._endpointMap=new Qs;for(let n=0;n<t.getNumGeometries();n++){const s=t.getGeometryN(n);s.getNumPoints()!==0&&(this.addEndpoint(s.getCoordinateN(0)),this.addEndpoint(s.getCoordinateN(s.getNumPoints()-1)))}for(let n=this._endpointMap.entrySet().iterator();n.hasNext();){const s=n.next(),o=s.getValue().count;this._bnRule.isInBoundary(o)&&e.add(s.getKey())}return Le.toCoordinateArray(e)}addEndpoint(t){let e=this._endpointMap.get(t);e===null&&(e=new F0,this._endpointMap.put(t,e)),e.count++}}class F0{constructor(){F0.constructor_.apply(this,arguments)}static constructor_(){this.count=null}}ce.prototype.getBoundary=function(){return xo.getBoundary(this)};ns.prototype.getBoundary=function(){return xo.getBoundary(this)};dt.prototype.equalsTopo=function(i){return Ue.equalsTopo(this,i)};dt.prototype.equals=function(i){return i===null?!1:Ue.equalsTopo(this,i)};dt.prototype.union=function(){if(arguments.length===0)return wo.union(this);if(arguments.length===1){const i=arguments[0];return k0.union(this,i)}};dt.prototype.isValid=function(){return Ii.isValid(this)};dt.prototype.intersection=function(i){return zt.intersection(this,i)};dt.prototype.covers=function(i){return Ue.covers(this,i)};dt.prototype.coveredBy=function(i){return Ue.covers(i,this)};dt.prototype.touches=function(i){return Ue.touches(this,i)};dt.prototype.intersects=function(i){return Ue.intersects(this,i)};dt.prototype.within=function(i){return Ue.contains(i,this)};dt.prototype.overlaps=function(i){return Ue.overlaps(this,i)};dt.prototype.disjoint=function(i){return Ue.disjoint(this,i)};dt.prototype.crosses=function(i){return Ue.crosses(this,i)};dt.prototype.buffer=function(){if(arguments.length===1){const i=arguments[0];return _n.bufferOp(this,i)}else if(arguments.length===2){const i=arguments[0],t=arguments[1];return _n.bufferOp(this,i,t)}else if(arguments.length===3){const i=arguments[0],t=arguments[1],e=arguments[2];return _n.bufferOp(this,i,t,e)}};dt.prototype.convexHull=function(){return new Xa(this).getConvexHull()};dt.prototype.relate=function(){if(arguments.length===1){const i=arguments[0];return Ue.relate(this,i)}else if(arguments.length===2){const i=arguments[0],t=arguments[1];return Ue.relate(this,i).matches(t)}};dt.prototype.getCentroid=function(){if(this.isEmpty())return this._factory.createPoint();const i=Ar.getCentroid(this);return this.createPointFromInternalCoord(i,this)};dt.prototype.getInteriorPoint=function(){if(this.isEmpty())return this._factory.createPoint();let i=null;const t=this.getDimension();t===0?i=new Ff(this):t===1?i=new Rf(this):i=new wr(this);const e=i.getInteriorPoint();return this.createPointFromInternalCoord(e,this)};dt.prototype.symDifference=function(i){return zt.symDifference(this,i)};dt.prototype.createPointFromInternalCoord=function(i,t){return t.getPrecisionModel().makePrecise(i),t.getFactory().createPoint(i)};dt.prototype.toText=function(){return new Js().write(this)};dt.prototype.toString=function(){this.toText()};dt.prototype.contains=function(i){return Ue.contains(this,i)};dt.prototype.difference=function(i){return zt.difference(this,i)};dt.prototype.isSimple=function(){return new Co(this).isSimple()};dt.prototype.isWithinDistance=function(i,t){return this.getEnvelopeInternal().distance(i.getEnvelopeInternal())>t?!1:kr.isWithinDistance(this,i,t)};dt.prototype.distance=function(i){return kr.distance(this,i)};const XI=750;function jI(i,t,e=XI,n=6){const[s,r,o,a]=t,l=i.search({minX:s,minY:r,maxX:o,maxY:a}).length;if(l===0)return[];if(l<=e||n<=0)return[t];const h=(s+o)/2,f=(r+a)/2;return h>s&&h<o&&f>r&&f<a?[[s,r,h,f],[h,r,o,f],[s,f,h,a],[h,f,o,a]].flatMap(p=>jI(i,p,e,n-1)):[t]}function dF(i,t=0){if(i.length===0)return null;const e=new Vf,n=t>0?new Ee(1/t):null,s=i.map(l=>{const h=e.read(l);return n?xu.reduce(h,n):h}),r=new ze,o=wo.union(r.createGeometryCollection(s));if(!o)return null;const a=new Iw().write(o);return a.type==="Polygon"||a.type==="MultiPolygon"?a:null}class VI extends Pe{constructor(){super("Topology check cancelled."),this.name="TopologyCancelled"}}const Dr={checks:["validity","overlap","gap","sliver","near-vertex","duplicate-point"],vertexToleranceMeters:.001,areaToleranceSqm:.01,sliverWidthMeters:.2,nearToleranceMeters:.1,unionCellSize:XI},gF=.1,mF=10,pF=.5;function Tv(i){return i.map(t=>t.toFixed(5)).join(", ")}const yF={0:"invalid-geometry",1:"duplicate-vertex",2:"hole-outside-shell",3:"nested-holes",4:"disconnected-interior",5:"self-intersection",6:"ring-self-intersection",7:"nested-shells",8:"duplicate-rings",9:"too-few-points",10:"invalid-coordinate",11:"ring-not-closed"},Rv={"invalid-geometry":"geometry is invalid","duplicate-vertex":"repeated vertices","hole-outside-shell":"a hole lies outside its polygon","nested-holes":"a hole lies inside another hole","disconnected-interior":"holes split the polygon interior into separate pieces","self-intersection":"boundary crosses itself","ring-self-intersection":"a ring touches or crosses itself","nested-shells":"a polygon part lies inside another part","duplicate-rings":"two rings are identical","too-few-points":"a ring or line has too few distinct points","invalid-coordinate":"invalid coordinate (NaN or infinite)","ring-not-closed":"a ring is not closed"},fo=i=>(i==null?void 0:i.type)==="Polygon"||(i==null?void 0:i.type)==="MultiPolygon",dh=i=>(i==null?void 0:i.type)==="LineString"||(i==null?void 0:i.type)==="MultiLineString";function HI(i={}){const t={...Dr,checks:[...Dr.checks]},e=(n,s,r=!0)=>{if(s!==void 0){if(typeof s!="number"||!Number.isFinite(s)||s<0||!r&&s===0)throw new Error(`Topology option ${n} must be a ${r?"non-negative":"positive"} number of meters (got ${String(s)})`);t[n]=s}};if(i.checks){const n=Dr.checks,s=i.checks.filter(r=>!n.includes(r));if(s.length)throw new Error(`Unknown topology check: ${s.join(", ")} (available: ${n.join(", ")})`);t.checks=[...i.checks]}if(e("vertexToleranceMeters",i.vertexToleranceMeters),e("areaToleranceSqm",i.areaToleranceSqm),e("sliverWidthMeters",i.sliverWidthMeters),e("nearToleranceMeters",i.nearToleranceMeters),e("gapMaxAreaSqm",i.gapMaxAreaSqm,!1),e("unionCellSize",i.unionCellSize,!1),e("minAreaSqm",i.minAreaSqm,!1),t.nearToleranceMeters<t.vertexToleranceMeters)throw new Error("nearToleranceMeters must be at least vertexToleranceMeters");return t}function aa(i){return i>=1600?`${(i/1600).toFixed(2)} rai (${Math.round(i).toLocaleString("en-US")} m²)`:`${i<1?i.toPrecision(2):i.toFixed(2)} m²`}function la(i){return i<1?`${(i*100).toPrecision(3)} cm`:`${i.toFixed(3)} m`}const Di=i=>[i[0],i[1]],Tg=100;function*$0(i,t,e={}){var S;const n=Date.now(),s=HI(e),r=new Set(s.checks),o=i.filter(C=>C&&C.geometry),a=[],l={layerId:t.id,layerName:t.name??t.id,checkedAt:n,durationMs:0,options:s,featureCount:o.length,issues:[],summary:{},ignored:{overlapsBelowTolerance:0,gapsBelowTolerance:0,gapsAboveMaxArea:0,ownHoles:0},skippedFeatureIds:[],failures:[]},h=C=>o[C].id,f=C=>a.push({...C,layerId:t.id}),d=new Set,p=new Vf,y=new Map,_=C=>{let T=y.get(C);return T||(T=Mi(o[C].geometry),y.set(C,T)),T};for(let C=0;C<o.length;C++){C%Tg===0&&(yield{stage:"validity",done:C,total:o.length});const T=o[C],I=T.geometry,M=h(C),R=fo(I),A=dh(I);let F=!0;if(Mn(I,B=>{(!Number.isFinite(B[0])||!Number.isFinite(B[1]))&&(F=!1)}),!F){d.add(C),r.has("validity")&&f({check:"validity",code:"invalid-coordinate",severity:"error",featureIds:[M],message:`Feature ${M}: ${Rv["invalid-coordinate"]}.`,location:[0,0]});continue}if(!R&&!A)continue;const $=we.forGeometries([I]),z=[];for(const B of oi(I))for(let U=1;U<B.length;U++)mr(B[U-1],B[U])<=s.vertexToleranceMeters&&z.push(B[U]);let D=!1;if(R?Hi(I).forEach((B,U)=>{sb(B[0],$,s.vertexToleranceMeters)&&(D=!0,r.has("validity")&&f({check:"validity",code:"zero-area",severity:"error",featureIds:[M],message:`Feature ${M}${Hi(I).length>1?` part ${U+1}`:""}: polygon has no area (all vertices on a line or at one point).`,location:Di(B[0][0])}))}):Rr(I).forEach((B,U)=>{(B.length<2||Wp(B,$)<=s.vertexToleranceMeters)&&(D=!0,r.has("validity")&&f({check:"validity",code:"zero-length",severity:"error",featureIds:[M],message:`Feature ${M}${Rr(I).length>1?` part ${U+1}`:""}: line has no length.`,location:Di(B[0])}))}),D&&d.add(C),r.has("validity")&&z.length>0&&f({check:"validity",code:"duplicate-vertex",severity:"warning",featureIds:[M],message:`Feature ${M}: ${z.length} repeated vertex${z.length>1?"es":""} (closer than ${la(s.vertexToleranceMeters)}).`,location:Di(z[0]),geometry:{type:"MultiPoint",coordinates:z.map(Di)},vertexCount:z.length,fix:"remove-duplicate-vertices"}),!D)try{const B=p.read(I);if(R){const U=new Ii(B);if(!U.isValid()){d.add(C);const j=U.getValidationError(),K=yF[(j==null?void 0:j.getErrorType())??0]??"invalid-geometry",W=j==null?void 0:j.getCoordinate();let J=W&&Number.isFinite(W.x)?[W.x,W.y]:Di(oi(I)[0][0]),lt={type:"Point",coordinates:J},ft="";if(K==="self-intersection"||K==="ring-self-intersection")try{const ct=cw(T).features.map(gt=>gt.geometry.coordinates);ct.length>0&&(lt={type:"MultiPoint",coordinates:ct},J=ct[0],ft=` (${ct.length} crossing point${ct.length>1?"s":""})`)}catch{}r.has("validity")&&f({check:"validity",code:K,severity:"error",featureIds:[M],message:`Feature ${M}: ${Rv[K]}${ft}.`,location:J,geometry:lt})}}else{const U=new Co(B);if(!U.isSimple()&&r.has("validity")){const j=U.getNonSimpleLocation(),K=j?[j.x,j.y]:Di(oi(I)[0][0]);f({check:"validity",code:"line-self-intersection",severity:"warning",featureIds:[M],message:`Feature ${M}: line crosses or touches itself.`,location:K,geometry:{type:"Point",coordinates:K}})}}}catch(B){d.add(C),r.has("validity")&&f({check:"validity",code:"invalid-geometry",severity:"error",featureIds:[M],message:`Feature ${M}: geometry cannot be read (${B instanceof Error?B.message:String(B)}).`,location:Di(((S=oi(I)[0])==null?void 0:S[0])??[0,0])})}}const E=o.map((C,T)=>fo(C.geometry)?T:-1).filter(C=>C>=0),w=E.filter(C=>!d.has(C));if((r.has("overlap")||r.has("gap"))&&(l.skippedFeatureIds=E.filter(C=>d.has(C)).map(h)),r.has("sliver"))for(const C of w){const T=Hi(o[C].geometry);T.forEach((I,M)=>{const R={type:"Polygon",coordinates:I},A=T.length===1?_(C):Mi(R),F=T.length>1?` part ${M+1}`:"";A.width<s.sliverWidthMeters?f({check:"sliver",code:"sliver",severity:"warning",featureIds:[h(C)],message:`Feature ${h(C)}${F}: sliver polygon, mean width ${la(A.width)} (area ${aa(A.area)}).`,location:Na(R),areaSqm:A.area,widthMeters:A.width}):s.minAreaSqm!==void 0&&A.area<s.minAreaSqm&&f({check:"sliver",code:"small-area",severity:"warning",featureIds:[h(C)],message:`Feature ${h(C)}${F}: small polygon, ${aa(A.area)} (minimum ${aa(s.minAreaSqm)}).`,location:Na(R),areaSqm:A.area,widthMeters:A.width})})}if(r.has("overlap")&&w.length>1){const C=new ha;C.load(w.map(M=>{const[R,A,F,$]=vs(o[M].geometry);return{minX:R,minY:A,maxX:F,maxY:$,index:M}}));let T=0,I=0;for(const M of w){I++%Tg===0&&(yield{stage:"overlap",done:I,total:w.length});const[R,A,F,$]=vs(o[M].geometry);for(const z of C.search({minX:R,minY:A,maxX:F,maxY:$})){const D=z.index;if(D<=M)continue;let B;try{B=of(ae([o[M],o[D]]))}catch(ft){T++<5&&l.failures.push({check:"overlap",message:`Features ${h(M)} and ${h(D)}: ${ft instanceof Error?ft.message:String(ft)}`});continue}if(!B)continue;const U=Mi(B.geometry);if(U.area<=s.areaToleranceSqm){U.area>0&&(l.ignored.overlapsBelowTolerance+=1);continue}const j=_(M).area,K=_(D).area,W=s.areaToleranceSqm,J=Math.abs(j-U.area)<=W&&Math.abs(K-U.area)<=W,lt=Math.abs(j-U.area)<=W?h(M):Math.abs(K-U.area)<=W?h(D):null;f({check:"overlap",code:J?"duplicate-geometry":"overlap",severity:"error",featureIds:[h(M),h(D)],message:J?`Features ${h(M)} and ${h(D)} have the same shape (${aa(U.area)}).`:`Features ${h(M)} and ${h(D)} overlap by ${aa(U.area)}, mean width ${la(U.width)}${lt!==null?` (feature ${lt} lies entirely inside the other)`:""}.`,location:Na(B.geometry),geometry:B.geometry,areaSqm:U.area,widthMeters:U.width,fix:J?void 0:"remove-overlap"})}}T>5&&l.failures.push({check:"overlap",message:`… ${T-5} more feature pairs could not be intersected`})}let b=null;const P=()=>{if(b)return b;const C=[];return o.forEach((T,I)=>{if(!(d.has(I)||!(fo(T.geometry)||dh(T.geometry))))for(const M of oi(T.geometry))for(let R=1;R<M.length;R++){const A=M[R-1],F=M[R];C.push({minX:Math.min(A[0],F[0]),minY:Math.min(A[1],F[1]),maxX:Math.max(A[0],F[0]),maxY:Math.max(A[1],F[1]),feature:I,a:A,b:F})}}),b=new ha,b.load(C),b},N=(C,T,I)=>{const[M,R,A,F]=Lo([C[0],C[1],C[0],C[1]],T),$=tr(C[1]),z=new Map;for(const D of P().search({minX:M,minY:R,maxX:A,maxY:F})){if(!I(D.feature))continue;const B=zo(C,D.a,D.b,$);if(B.distance>T)continue;const U=z.get(D.feature);(!U||B.distance<U.distance)&&z.set(D.feature,{distance:B.distance,point:B.point})}return z};if(r.has("gap")&&w.length>1){const C=new ha;C.load(w.map(F=>{const[$,z,D,B]=vs(o[F].geometry);return{minX:$,minY:z,maxX:D,maxY:B,index:F}}));const T=[C.toJSON().minX,C.toJSON().minY,C.toJSON().maxX,C.toJSON().maxY],I=jI(C,T,s.unionCellSize),M=new ha,R=[],A=new Set;for(let F=0;F<I.length;F++){yield{stage:"gap",done:F,total:I.length};const $=I[F],z=Math.max($[2]-$[0],$[3]-$[1])*gF,D={minX:$[0]-z,minY:$[1]-z,maxX:$[2]+z,maxY:$[3]+z},B=C.search(D);if(B.length<2)continue;if(B.length>s.unionCellSize*mF){l.failures.push({check:"gap",message:`Gap check skipped ${B.length} features around ${Tv($)}: they sit too close together to split into areas of ${s.unionCellSize}. Check a smaller area, or fix the duplicate geometries first.`});continue}const U=new Set(B.map(K=>K.index));let j;try{j=dF(B.map(K=>o[K.index].geometry))}catch(K){l.failures.push({check:"gap",message:`Gap check could not union the ${B.length} features around ${Tv($)}: ${K instanceof Error?K.message:String(K)}`});continue}for(const K of j?Hi(j):[])for(const W of K.slice(1)){const J={type:"Polygon",coordinates:[W.slice().reverse()]},lt=Na(J),ft=`${lt[0].toFixed(6)},${lt[1].toFixed(6)}`,[ct,gt,bt,It]=vs(J);if(C.search({minX:ct,minY:gt,maxX:bt,maxY:It}).some(Ut=>!U.has(Ut.index))){(bt-ct>D.maxX-D.minX||It-gt>D.maxY-D.minY)&&!A.has(ft)&&(A.add(ft),l.failures.push({check:"gap",message:`An empty area around ${lt.map(Gt=>Gt.toFixed(5)).join(", ")} is larger than the ${s.unionCellSize}-feature area the check works on, so it was not checked. Raise unionCellSize to include it.`}));continue}const jt=Mi(J),Dt=Lo([lt[0],lt[1],lt[0],lt[1]],pF);if(M.search({minX:Dt[0],minY:Dt[1],maxX:Dt[2],maxY:Dt[3]}).some(Ut=>Math.abs(R[Ut.index]-jt.area)<=Math.max(jt.area,R[Ut.index])*.05))continue;if(M.insert({minX:lt[0],minY:lt[1],maxX:lt[0],maxY:lt[1],index:R.length}),R.push(jt.area),jt.area<=s.areaToleranceSqm){l.ignored.gapsBelowTolerance+=1;continue}const V=new Set;for(const Ut of W)N(Ut,s.vertexToleranceMeters,Gt=>fo(o[Gt].geometry)).forEach((Gt,dn)=>V.add(dn));if(V.size<=1){l.ignored.ownHoles+=1;continue}if(s.gapMaxAreaSqm!==void 0&&jt.area>s.gapMaxAreaSqm){l.ignored.gapsAboveMaxArea+=1;continue}const Xt=[...V].sort((Ut,Gt)=>Ut-Gt).map(h);f({check:"gap",code:"gap",severity:"error",featureIds:Xt,message:`Gap of ${aa(jt.area)} (mean width ${la(jt.width)}) between features ${Xt.join(", ")}.`,location:lt,geometry:J,areaSqm:jt.area,widthMeters:jt.width,fix:"fill-gap"})}}}if(r.has("near-vertex")){const C=s.nearToleranceMeters,T=s.vertexToleranceMeters;for(let I=0;I<o.length;I++){if(I%Tg===0&&(yield{stage:"near-vertex",done:I,total:o.length}),d.has(I))continue;const M=o[I].geometry;if(fo(M)){const R=new Map;for(const A of Hi(M))for(const F of A)for(let $=0;$<F.length-1;$++)N(F[$],C,z=>z!==I&&fo(o[z].geometry)).forEach((z,D)=>{if(z.distance<=T)return;const B=R.get(D)??{points:[],max:0};B.points.push(Di(F[$])),B.max=Math.max(B.max,z.distance),R.set(D,B)});[...R.entries()].sort((A,F)=>A[0]-F[0]).forEach(([A,F])=>{f({check:"near-vertex",code:"near-vertex",severity:"warning",featureIds:[h(I),h(A)],message:`Feature ${h(I)}: ${F.points.length} vertex${F.points.length>1?"es":""} within ${la(F.max)} of feature ${h(A)} without touching it.`,location:F.points[0],geometry:{type:"MultiPoint",coordinates:F.points},distanceMeters:F.max,vertexCount:F.points.length,fix:"snap-vertices"})})}else dh(M)&&Rr(M).forEach((R,A)=>{const F=R[0],$=R[R.length-1];mr(F,$)<=T||[F,$].forEach(z=>{const D=N(z,C,j=>j!==I&&(dh(o[j].geometry)||fo(o[j].geometry)));if(D.size===0||[...D.values()].some(j=>j.distance<=T))return;const[B,U]=[...D.entries()].sort((j,K)=>j[1].distance-K[1].distance)[0];f({check:"near-vertex",code:"undershoot",severity:"warning",featureIds:[h(I),h(B)],message:`Feature ${h(I)}${Rr(M).length>1?` part ${A+1}`:""}: line end stops ${la(U.distance)} short of feature ${h(B)}.`,location:Di(z),geometry:{type:"Point",coordinates:Di(z)},distanceMeters:U.distance,fix:"snap-line-end"})})})}}if(r.has("duplicate-point")){const C=[];if(o.forEach((T,I)=>{T.geometry.type==="Point"?C.push({feature:I,p:T.geometry.coordinates}):T.geometry.type==="MultiPoint"&&T.geometry.coordinates.forEach(M=>C.push({feature:I,p:M}))}),C.length>1){const T=new ha;T.load(C.map((M,R)=>({minX:M.p[0],minY:M.p[1],maxX:M.p[0],maxY:M.p[1],index:R})));const I=new Set;C.forEach((M,R)=>{if(I.has(R))return;const[A,F,$,z]=Lo([M.p[0],M.p[1],M.p[0],M.p[1]],s.vertexToleranceMeters),D=T.search({minX:A,minY:F,maxX:$,maxY:z}).map(j=>j.index).filter(j=>!I.has(j)&&mr(M.p,C[j].p)<=s.vertexToleranceMeters),B=[...new Set(D.map(j=>C[j].feature))];if(D.length<2)return;D.forEach(j=>I.add(j));const U=B.sort((j,K)=>j-K).map(h);f({check:"duplicate-point",code:"duplicate-point",severity:"warning",featureIds:U,message:B.length>1?`Features ${U.join(", ")} are at the same location.`:`Feature ${U[0]} repeats a point.`,location:Di(M.p),geometry:{type:"Point",coordinates:Di(M.p)},vertexCount:D.length})})}}l.issues=a.map((C,T)=>({id:T+1,...C}));for(const C of l.issues)l.summary[C.code]=(l.summary[C.code]??0)+1;return l.durationMs=Date.now()-n,l}function WI(i,t,e={}){const n=$0(i,t,e);let s=n.next();for(;!s.done;)s=n.next();return s.value}async function KI(i,t,e={},n={}){var l,h;const s=n.sliceMs??60,r=$0(i,t,e);let o=r.next(),a=Date.now();for(;!o.done;){if((l=n.signal)!=null&&l.aborted)throw r.return(void 0),new VI;(h=n.onProgress)==null||h.call(n,o.value),Date.now()-a>=s&&(await new Promise(f=>setTimeout(f,0)),a=Date.now()),o=r.next()}return o.value}const ZI=1e-6,_F=new Vf;function Lc(i,t){const e=new Ii(_F.read(i));if(!e.isValid()){const n=e.getValidationError(),s=n==null?void 0:n.getCoordinate();throw new Error(`${t} would be invalid: ${(n==null?void 0:n.getMessage())??"invalid geometry"}${s?` near ${s.x.toFixed(7)}, ${s.y.toFixed(7)}`:""}. No changes were made.`)}}function D0(i,t){switch(i.type){case"Polygon":return{...i,coordinates:i.coordinates.map(e=>t(e,!0))};case"MultiPolygon":return{...i,coordinates:i.coordinates.map(e=>e.map(n=>t(n,!0)))};case"LineString":return{...i,coordinates:t(i.coordinates,!1)};case"MultiLineString":return{...i,coordinates:i.coordinates.map(e=>t(e,!1))};default:return i}}function JI(i,t){for(const e of Hi(i))for(const n of e)if(n.length<4)throw new Error(`${t} would collapse a ring to fewer than 3 points. No changes were made.`);if(i.type==="LineString"||i.type==="MultiLineString"){for(const e of oi(i))if(e.length<2)throw new Error(`${t} would collapse a line to one point. No changes were made.`)}}function QI(i,t){let e=0;const n=D0(i,(s,r)=>{const o=[s[0]];for(let a=1;a<s.length;a++){const l=r&&a===s.length-1;if(mr(o[o.length-1],s[a])<=t){l?(o.length>1&&(o.pop(),e+=1),o.push(s[a])):e+=1;continue}o.push(s[a])}return o});return JI(n,"Removing repeated vertices"),(n.type==="Polygon"||n.type==="MultiPolygon")&&Lc(n,"Removing repeated vertices"),{geometry:n,removed:e}}function tS(i){const t=[],e=[];for(const n of oi(i))n.forEach((s,r)=>{r>0&&e.push([n[r-1],s]),t.push(s)});return{vertices:t,segments:e}}function vF(i,t,e){let n=null,s=e;for(const a of t.vertices){const l=mr(i,a);l<=s&&(s=l,n=a)}if(n)return{point:n,distance:s};const r=tr(i[1]);let o=null;for(const[a,l]of t.segments){const h=zo(i,a,l,r);h.distance<=e&&(!o||h.distance<o.distance)&&(o={point:h.point,distance:h.distance})}return o}function eS(i,t,e,n={}){const s=tS(t);let r=0,o=0,a=0;const l=D0(i,(h,f)=>{const d=f?h.length-1:h.length,p=[];for(let E=0;E<d;E++){const w=h[E],L=E===0||E===d-1,b=n.endpointsOnly&&(f||!L)?null:vF(w,s,e);b&&b.distance>0&&(b.point[0]!==w[0]||b.point[1]!==w[1])?(p.push([b.point[0],b.point[1],...w.slice(2)]),r+=1,a=Math.max(a,b.distance)):p.push(w)}let y=p;if(n.insertVertices!==!1&&!n.endpointsOnly){y=[];const E=f?p.length:p.length-1;for(let w=0;w<p.length;w++){if(y.push(p[w]),w>=E)continue;const L=p[w],b=p[(w+1)%p.length],P=tr(L[1]),N=[];for(const S of s.vertices){if(mr(S,L)<=e||mr(S,b)<=e)continue;const C=zo(S,L,b,P);C.t>0&&C.t<1&&C.distance<=e&&!N.some(T=>T.p[0]===S[0]&&T.p[1]===S[1])&&N.push({t:C.t,p:S})}N.sort((S,C)=>S.t-C.t).forEach(S=>y.push([S.p[0],S.p[1]])),o+=N.length}}const _=y.filter((E,w)=>w===0||E[0]!==y[w-1][0]||E[1]!==y[w-1][1]);if(f){for(;_.length>1&&_[_.length-1][0]===_[0][0]&&_[_.length-1][1]===_[0][1];)_.pop();_.push(_[0])}return _});return JI(l,"Snapping"),(l.type==="Polygon"||l.type==="MultiPolygon")&&Lc(l,"Snapping"),{geometry:l,movedVertices:r,insertedVertices:o,maxMoveMeters:a}}function G0(i,t){const e=Lo(vs(i),1),n=[],s=new Set;for(const a of t)for(const l of oi(a))for(const h of l){if(h[0]<e[0]||h[0]>e[2]||h[1]<e[1]||h[1]>e[3])continue;const f=`${h[0]},${h[1]}`;s.has(f)||(s.add(f),n.push(h))}let r=0;return{geometry:D0(i,a=>{const l=new Set(a.map(f=>`${f[0]},${f[1]}`)),h=[];for(let f=0;f<a.length-1;f++){const d=a[f],p=a[f+1];h.push(d);const y=Math.min(d[0],p[0]),_=Math.max(d[0],p[0]),E=Math.min(d[1],p[1]),w=Math.max(d[1],p[1]),L=tr(d[1]),b=[];for(const P of n){if(l.has(`${P[0]},${P[1]}`)||P[0]<y-1e-7||P[0]>_+1e-7||P[1]<E-1e-7||P[1]>w+1e-7)continue;const N=zo(P,d,p,L);N.t>0&&N.t<1&&N.distance<=ZI&&b.push({t:N.t,p:P})}b.sort((P,N)=>P.t-N.t).forEach(P=>{h.push(P.p),l.add(`${P.p[0]},${P.p[1]}`)}),r+=b.length}return h.push(a[a.length-1]),h}),restored:r}}function Df(i){return{type:"Feature",properties:{},geometry:i}}function nS(i,t){const e=ba(ae([Df(i),Df(t)]));if(!e)throw new Error("Removing the overlap would delete the whole feature (it lies entirely inside the other). No changes were made.");const{geometry:n}=G0(e.geometry,[i,t]);return Lc(n,"Removing the overlap"),n}function iS(i,t,e=[]){const n=gw(ae([Df(i),Df(t)]));if(!n)throw new Error("Filling the gap produced an empty geometry. No changes were made.");if(Hi(n.geometry).length>Hi(i).length)throw new Error("The gap does not touch the chosen feature. No changes were made.");const{geometry:s}=G0(n.geometry,[i,t,...e]);return Lc(s,"Filling the gap"),s}function sS(i,t,e){const n=tS(t),s=o=>{const a=tr(o[1]);return n.segments.some(([l,h])=>zo(o,l,h,a).distance<=e)};let r=0;for(let o=1;o<i.length;o++){const a=i[o-1],l=i[o],h=[(a[0]+l[0])/2,(a[1]+l[1])/2];s(a)&&s(l)&&s(h)&&(r+=mr(a,l))}return r}const ya="topology-errors",po="topology-errors-area",yo="topology-errors-point",gh="#e11d48";class mh extends Error{}const EF=i=>(i==null?void 0:i.type)==="Polygon"||(i==null?void 0:i.type)==="MultiPolygon";class rS{constructor(t,e){Y(this,"reports",new Map);Y(this,"listeners",new Set);Y(this,"issueLayersFor",null);this.dataSource=t,this.thematicEngine=e,this.dataSource.on("layer:removed",({layerId:n})=>{if(n===po||n===yo){!this.dataSource.hasLayer(po)&&!this.dataSource.hasLayer(yo)&&(this.issueLayersFor=null);return}this.reports.delete(n)&&(this.issueLayersFor===n&&this.hideIssues(),this.emit(null,n))})}onChange(t){return this.listeners.add(t),()=>this.listeners.delete(t)}emit(t,e){this.listeners.forEach(n=>n(t,e))}check(t,e={}){const{features:n,layer:s}=this.checkTarget(t);return this.storeReport(t,e,n,WI(n,{id:s.id,name:s.name},e))}async checkAsync(t,e={},n={}){const{features:s,layer:r}=this.checkTarget(t),o=await KI(s,{id:r.id,name:r.name},e,n);return this.storeReport(t,e,s,o)}checkTarget(t){const e=this.dataSource.getLayer(t);if(!e)throw new Error(`Layer "${t}" not found`);if(t===po||t===yo)throw new Error("Cannot check the topology issue layers themselves");return{layer:e,features:e.getFeatures()}}storeReport(t,e,n,s){return this.reports.set(t,{report:s,options:e,geometries:new Map(n.map(r=>[r.id,r.geometry]))}),this.issueLayersFor===t&&this.showIssues(t),this.emit(s,t),s}recheck(t){const e=this.reports.get(t);return this.check(t,(e==null?void 0:e.options)??{})}getReport(t){var n;if(t)return(n=this.reports.get(t))==null?void 0:n.report;let e;return this.reports.forEach(({report:s})=>{(!e||s.checkedAt>=e.checkedAt)&&(e=s)}),e}getIssue(t,e){var n;return(n=this.getReport(e))==null?void 0:n.issues.find(s=>s.id===t)}clear(t){(t?[t]:[...this.reports.keys()]).forEach(n=>{this.reports.delete(n)&&this.emit(null,n)}),(!t||this.issueLayersFor===t)&&this.hideIssues()}issueBBox(t,e=5){const n=t.geometry?vs(t.geometry):[t.location[0],t.location[1],t.location[0],t.location[1]];return Lo(n,e)}showIssues(t){const e=this.getReport(t);if(!e)throw new Error("Run a topology check first");const n=this.dataSource,s=a=>({issue:a.id,code:a.code,severity:a.severity,message:a.message,features:a.featureIds.join(", "),...a.areaSqm!==void 0?{area_sqm:Number(a.areaSqm.toFixed(4))}:{},...a.distanceMeters!==void 0?{distance_m:Number(a.distanceMeters.toFixed(4))}:{}}),r=e.issues.filter(a=>a.geometry&&EF(a.geometry)).map(a=>({type:"Feature",id:`issue-${a.id}`,properties:s(a),geometry:a.geometry})),o=e.issues.map(a=>({type:"Feature",id:`issue-${a.id}`,properties:s(a),geometry:a.geometry&&(a.geometry.type==="MultiPoint"||a.geometry.type==="Point")?a.geometry:{type:"Point",coordinates:a.location}}));{n.getLayerGroup(ya)||n.addLayerGroup({id:ya,name:"Topology errors"});const a=Math.max(0,...n.getAllLayers().filter(h=>h.id!==po&&h.id!==yo).map(h=>h.zIndex)),l=(h,f,d,p,y)=>{const _=n.getLayer(h);_?(_.setFeatures(p),_.name=d,n.emit("features:changed",{layerId:h})):n.addLayer({id:h,name:d,type:f,zIndex:y,groupId:ya,tag:"topology"},p),this.thematicEngine&&!this.thematicEngine.getTheme(h)&&this.thematicEngine.createSimpleTheme(h,f==="polygon"?{fillColor:gh,fillOpacity:.35,strokeColor:gh,strokeWidth:2}:{circleColor:gh,circleRadius:6,strokeColor:"#ffffff",strokeWidth:2},gh)};l(po,"polygon",`Topology areas: ${e.layerName}`,r,a+1),l(yo,"point",`Topology issues: ${e.layerName}`,o,a+2)}this.issueLayersFor=e.layerId}hideIssues(){const t=this.dataSource;this.issueLayersFor=null,[po,yo].forEach(e=>{var n;t.hasLayer(e)&&t.removeLayer(e),(n=this.thematicEngine)==null||n.removeTheme(e)}),t.getLayerGroup(ya)&&t.removeLayerGroup(ya)}isShowingIssues(){return this.issueLayersFor!==null}fixIssue(t,e={},n){const{stored:s,issue:r}=this.resolveIssue(t,n);this.assertCurrent(s,r,new Map);const o=this.dataSource.runTransaction(`Topology fix #${r.id} (${r.code})`,()=>this.applyFix(s,r,e,new Map));return this.recheck(s.report.layerId),o}fixIssues(t,e={},n){const s=this.storedFor(n),r={results:[],skipped:[],failed:[]},o=t.map(l=>{const h=s.report.issues.find(f=>f.id===l);if(!h)throw new Error(`Issue #${l} not found in the last report of "${s.report.layerName}"`);return h}),a=new Map;return this.dataSource.runTransaction(`Topology fix ${o.length} issues`,()=>{for(const l of o){try{this.assertCurrent(s,l,a)}catch(h){r.failed.push({issueId:l.id,message:h instanceof Error?h.message:String(h)});continue}if(l.fix==="fill-gap"&&l.featureIds.some(h=>a.has(h))){r.skipped.push({issueId:l.id,reason:"A feature around the gap was changed by an earlier fix; re-check to get the new gap."});continue}try{r.results.push(this.applyFix(s,l,e,a))}catch(h){const f=h instanceof Error?h.message:String(h);h instanceof mh?r.skipped.push({issueId:l.id,reason:f}):r.failed.push({issueId:l.id,message:f})}}}),this.recheck(s.report.layerId),r}storedFor(t){const e=this.getReport(t),n=e&&this.reports.get(e.layerId);if(!n)throw new Error(t?`No topology report for layer "${t}". Run a check first.`:"Run a topology check first");return n}resolveIssue(t,e){const n=this.storedFor(e),s=n.report.issues.find(r=>r.id===t);if(!s)throw new Error(`Issue #${t} not found in the last report of "${n.report.layerName}"`);return{stored:n,issue:s}}assertCurrent(t,e,n){const s=this.dataSource.getLayer(t.report.layerId);for(const r of e.featureIds){const o=s==null?void 0:s.getFeature(r);if(!o||o.geometry!==t.geometries.get(r)&&o.geometry!==n.get(r))throw new Error(`Feature ${r} changed after the check. Run the topology check again.`)}}applyFix(t,e,n,s){const r=t.report.layerId,o=t.report.options,a=this.dataSource,l=p=>a.getFeature(r,p),h=(p,y)=>{const _=l(p);a.updateFeature(r,{..._,geometry:y}),s.set(p,a.getFeature(r,p).geometry)},f={issueId:e.id,code:e.code},d=(p,y)=>String(p)===String(y);switch(e.fix){case"remove-duplicate-vertices":{const p=e.featureIds[0],{geometry:y,removed:_}=QI(l(p).geometry,o.vertexToleranceMeters);if(_===0)throw new mh("No repeated vertices left. No changes were made.");return h(p,y),{...f,changedFeatureIds:[p],message:`Removed ${_} repeated vertices from feature ${p}.`}}case"snap-vertices":case"snap-line-end":{const[p,y]=e.featureIds,_=n.moveFeatureId??p;if(!e.featureIds.some(b=>d(b,_)))throw new Error(`Feature ${_} is not part of issue #${e.id}`);const E=d(_,p)?y:p,w=l(_).geometry,L=eS(w,l(E).geometry,o.nearToleranceMeters,{endpointsOnly:e.fix==="snap-line-end"});if(L.movedVertices===0&&L.insertedVertices===0)throw new mh("Nothing to snap (no vertex within the tolerance). No changes were made.");return h(_,L.geometry),{...f,changedFeatureIds:[_],movedVertices:L.movedVertices,maxMoveMeters:L.maxMoveMeters,message:`Feature ${_}: moved ${L.movedVertices} vertices (max ${(L.maxMoveMeters*100).toFixed(1)} cm)${L.insertedVertices?`, added ${L.insertedVertices} vertices`:""} onto feature ${E}.`}}case"remove-overlap":{const[p,y]=e.featureIds,_=n.removeFrom;if(_===void 0)throw new Error(`Choose the feature that gives up the overlap: removeFrom = ${p}, ${y}, "smaller" or "larger"`);let E;if(_==="smaller"||_==="larger"){const S=Mi(l(p).geometry).area,C=Mi(l(y).geometry).area;E=_==="smaller"==S<=C?p:y}else if(d(_,p)||d(_,y))E=d(_,p)?p:y;else throw new Error(`Feature ${_} is not part of issue #${e.id} (${p}, ${y})`);const w=d(E,p)?y:p,L=l(E).geometry,b=l(w).geometry,P=of(ae([vn(L),vn(b)]));if(!P||Mi(P.geometry).area<=o.areaToleranceSqm)throw new mh("The features no longer overlap. No changes were made.");const N=nS(L,b);return h(E,N),{...f,changedFeatureIds:[E],message:`Removed the overlap from feature ${E} (kept in feature ${w}).`}}case"fill-gap":{const p=e.geometry,y=n.mergeInto??"longest-boundary";let _;if(y==="longest-boundary"||y==="largest")_=e.featureIds.map(b=>({id:b,score:y==="largest"?Mi(l(b).geometry).area:sS(p.coordinates[0],l(b).geometry,o.vertexToleranceMeters)})).sort((b,P)=>P.score-b.score)[0].id;else{const L=e.featureIds.find(b=>d(b,y));if(L===void 0)throw new Error(`Feature ${y} does not border gap #${e.id} (${e.featureIds.join(", ")})`);_=L}const E=e.featureIds.filter(L=>!d(L,_)).map(L=>l(L).geometry),w=iS(l(_).geometry,p,E);return h(_,w),{...f,changedFeatureIds:[_],message:`Merged the gap (${p?Mi(p).area.toFixed(2):"?"} m²) into feature ${_}.`}}default:throw new Error(`Issue #${e.id} (${e.code}) has no automatic fix`)}}}const wF={validity:"Invalid geometry",overlap:"Overlaps",gap:"Gaps",sliver:"Slivers / small parcels","near-vertex":"Near-miss vertices","duplicate-point":"Duplicate points"},xF=[{key:"vertexToleranceMeters",label:"Same point",unit:"m"},{key:"nearToleranceMeters",label:"Near miss",unit:"m"},{key:"areaToleranceSqm",label:"Ignore areas up to",unit:"m²"},{key:"gapMaxAreaSqm",label:"Gap max area",unit:"m²"},{key:"sliverWidthMeters",label:"Sliver width",unit:"m"},{key:"minAreaSqm",label:"Min parcel area",unit:"m²"}];class bF{constructor(t,e,n={}){Y(this,"container",null);Y(this,"unsubscribers",[]);Y(this,"layerId",null);Y(this,"options",{});Y(this,"disabledChecks",new Set);Y(this,"busy",!1);Y(this,"running",null);Y(this,"progress",null);Y(this,"message",null);Y(this,"stale",!1);Y(this,"handleChange",t=>{const e=t.target;if(e.getAttribute("data-field")==="layer"){this.layerId=e.value,this.message=null,this.render();return}const s=e.getAttribute("data-check");if(s){e.checked?this.disabledChecks.delete(s):this.disabledChecks.add(s);return}const r=e.getAttribute("data-tolerance");if(r){const o=e.value.trim();if(o==="")delete this.options[r];else{const a=Number(o);if(!Number.isFinite(a)||a<0){this.message={text:`${r} must be a non-negative number`,kind:"error"},this.render();return}this.options[r]=a}}});Y(this,"handleClick",t=>{var o,a,l,h;const e=t.target.closest("[data-action], [data-issue]");if(!e)return;const n=e.getAttribute("data-action"),s=this.currentReport();if(n==="close"){(a=(o=this.panelOptions).onClose)==null||a.call(o);return}if(n==="check"){this.running?this.running.abort():this.runCheck();return}if(n==="toggle-show"){this.topology.isShowingIssues()?this.topology.hideIssues():s&&this.topology.showIssues(s.layerId),this.render();return}if(n==="fix"||n==="fix-all"){this.runFix(n==="fix-all"?e.getAttribute("data-code"):Number(e.getAttribute("data-issue")));return}const r=Number(e.getAttribute("data-issue"));if(s&&Number.isInteger(r)){const f=s.issues.find(y=>y.id===r);if(!f)return;const d=this.dataSource.getLayer(s.layerId),p=f.featureIds.filter(y=>d==null?void 0:d.hasFeature(y));p.length&&this.dataSource.selectFeatures(s.layerId,p,!1),(h=(l=this.panelOptions).onZoom)==null||h.call(l,f,s)}});this.dataSource=t,this.topology=e,this.panelOptions=n}mount(t){const e=typeof t=="string"?document.getElementById(t):t;if(!e)throw new Error(`Target container for OFSTopologyPanel not found: ${t}`);this.unmount(),this.container=e,e.classList.add("ofs-topology-panel"),e.addEventListener("click",this.handleClick),e.addEventListener("change",this.handleChange),this.unsubscribers.push(this.dataSource.on("layer:added",()=>this.render()),this.dataSource.on("layer:removed",()=>this.render()),this.dataSource.on("features:changed",({layerId:n})=>{var s;n===((s=this.currentReport())==null?void 0:s.layerId)&&!this.busy&&(this.stale=!0,this.render())}),this.topology.onChange(()=>{this.stale=!1,this.render()})),this.render()}unmount(){this.unsubscribers.forEach(t=>t()),this.unsubscribers=[],this.container&&(this.container.removeEventListener("click",this.handleClick),this.container.removeEventListener("change",this.handleChange),this.container.innerHTML="",this.container.classList.remove("ofs-topology-panel"),this.container=null)}open(t){this.layerId=t,this.render()}dataLayers(){return this.dataSource.getAllLayers().filter(t=>t.tag!=="topology")}currentLayerId(){var e;const t=this.dataLayers();return this.layerId&&t.some(n=>n.id===this.layerId)?this.layerId:this.dataSource.getActiveLayerId()??((e=t[0])==null?void 0:e.id)??null}currentReport(){const t=this.currentLayerId();return t?this.topology.getReport(t):void 0}render(){if(!this.container)return;const t=this.currentLayerId(),e=this.currentReport(),n=this.dataLayers();this.container.innerHTML=`
|
|
289
|
+
<div class="ofs-topo-header">
|
|
290
|
+
<span class="ofs-topo-title">🔍 Topology</span>
|
|
291
|
+
${this.panelOptions.onClose?'<button class="ofs-btn-mini" data-action="close" title="Close">✕</button>':""}
|
|
292
|
+
</div>
|
|
293
|
+
<label class="ofs-topo-row"><span>Layer</span>
|
|
294
|
+
<select data-field="layer">
|
|
295
|
+
${n.map(s=>`<option value="${Tt(s.id)}" ${s.id===t?"selected":""}>${Tt(s.name)} (${s.count})</option>`).join("")}
|
|
296
|
+
</select>
|
|
297
|
+
</label>
|
|
298
|
+
<div class="ofs-topo-checks">
|
|
299
|
+
${Dr.checks.map(s=>`<label class="ofs-topo-check"><input type="checkbox" data-check="${s}" ${this.disabledChecks.has(s)?"":"checked"}/> ${Tt(wF[s])}</label>`).join("")}
|
|
300
|
+
</div>
|
|
301
|
+
<div class="ofs-topo-tolerances">
|
|
302
|
+
${xF.map(s=>{const r=this.options[s.key],o=Dr[s.key];return`<label class="ofs-topo-row"><span>${Tt(s.label)}</span>
|
|
303
|
+
<input type="number" min="0" step="any" data-tolerance="${s.key}" value="${r===void 0?"":r}" placeholder="${o===void 0?"off":o}"/>
|
|
304
|
+
<small>${s.unit}</small></label>`}).join("")}
|
|
305
|
+
</div>
|
|
306
|
+
<div class="ofs-topo-actions">
|
|
307
|
+
<button class="ofs-btn" data-action="check" ${t?"":"disabled"}>${this.busy?`Stop${this.progress?` (${this.progress})`:""}`:"Check"}</button>
|
|
308
|
+
<button class="ofs-btn-secondary" data-action="toggle-show" ${e?"":"disabled"}>${this.topology.isShowingIssues()?"Hide on map":"Show on map"}</button>
|
|
309
|
+
</div>
|
|
310
|
+
${this.message?`<div class="ofs-topo-message ${this.message.kind}">${Tt(this.message.text)}</div>`:""}
|
|
311
|
+
${e?this.renderReport(e):'<div class="ofs-topo-empty">Run a check to list geometry and topology problems.</div>'}
|
|
312
|
+
`}renderReport(t){const e=t.issues.filter(a=>a.severity==="error").length,n=t.issues.length-e,s=new Map;t.issues.forEach(a=>s.set(a.code,[...s.get(a.code)??[],a]));const r=`<div class="ofs-topo-summary">
|
|
313
|
+
${t.featureCount} features · <b class="error">${e}</b> errors · <b class="warning">${n}</b> warnings
|
|
314
|
+
${this.stale?'<span class="ofs-topo-stale">data changed — check again</span>':""}
|
|
315
|
+
</div>`;if(t.issues.length===0)return`${r}<div class="ofs-topo-empty">No problems found.</div>`;const o=[...s.entries()].map(([a,l])=>{const h=l.filter(p=>p.fix),f=`<div class="ofs-topo-group-head">
|
|
316
|
+
<span>${Tt(a)} <small>(${l.length})</small></span>
|
|
317
|
+
${h.length>1?`<button class="ofs-btn-mini" data-action="fix-all" data-code="${Tt(a)}" title="Fix all ${Tt(a)} issues">Fix all</button>`:""}
|
|
318
|
+
</div>`,d=l.map(p=>`<li class="ofs-topo-issue ${p.severity}" data-issue="${p.id}" title="Zoom to issue ${p.id}">
|
|
319
|
+
<span class="ofs-topo-issue-text">#${p.id} ${Tt(p.message)}</span>
|
|
320
|
+
${p.fix?`<button class="ofs-btn-mini" data-action="fix" data-issue="${p.id}" title="Fix this issue">🛠</button>`:""}
|
|
321
|
+
</li>`).join("");return`<div class="ofs-topo-group">${f}<ul class="ofs-topo-list">${d}</ul></div>`}).join("");return r+o}async runCheck(){const t=this.currentLayerId();if(t){this.busy=!0,this.message=null,this.progress=null,this.running=new AbortController,this.render();try{const e=Dr.checks.filter(n=>!this.disabledChecks.has(n));await this.topology.checkAsync(t,{...this.options,checks:e},{signal:this.running.signal,onProgress:n=>{const s=n.total>0?Math.round(n.done/n.total*100):0,r=`${n.stage} ${s}%`;r!==this.progress&&(this.progress=r,this.render())}})}catch(e){const n=e instanceof Error&&e.name==="TopologyCancelled";this.message={text:e instanceof Error?e.message:String(e),kind:n?"info":"error"}}finally{this.busy=!1,this.running=null,this.progress=null,this.render()}}}runFix(t){const e=this.currentReport();if(!e||t===null)return;const n=typeof t=="number"?e.issues.filter(r=>r.id===t):e.issues.filter(r=>r.fix&&r.code===t);if(n.length===0)return;const s={};if(n.some(r=>r.fix==="remove-overlap")){const r=this.ask('Which feature gives up the overlapping area? Type a feature id, "smaller" or "larger".',typeof t=="number"?String(n[0].featureIds[0]):"smaller");if(r===null)return;s.removeFrom=r.trim()}if(!(n.length>1&&!(this.panelOptions.confirmFix?this.panelOptions.confirmFix(n.length,e):typeof window<"u"&&window.confirm(`Fix ${n.length} "${String(t)}" issues in "${e.layerName}" as one undo step?`)))){this.busy=!0;try{if(n.length===1){const r=this.topology.fixIssue(n[0].id,s,e.layerId);this.message={text:r.message,kind:"info"}}else{const r=this.topology.fixIssues(n.map(a=>a.id),s,e.layerId),o=[`Fixed ${r.results.length} of ${n.length}`];r.skipped.length&&o.push(`${r.skipped.length} skipped (check again)`),r.failed.length&&o.push(`${r.failed.length} refused: ${r.failed[0].message}`),this.message={text:o.join(" · "),kind:r.failed.length?"error":"info"}}}catch(r){this.message={text:r instanceof Error?r.message:String(r),kind:"error"}}finally{this.busy=!1,this.stale=!1,this.render()}}}ask(t,e){return typeof window>"u"||!window.prompt?e:window.prompt(t,e)}}const B0="_ofs_";function xd(i){return i.startsWith(B0)}const IF=/^\d{4}-\d{2}-\d{2}$/;function q0(i){if(!IF.test(i))return!1;const[t,e,n]=i.split("-").map(Number),s=new Date(Date.UTC(t,e-1,n));return s.getUTCFullYear()===t&&s.getUTCMonth()===e-1&&s.getUTCDate()===n}function SF(i){return i==null||i===""?null:typeof i=="number"?Number.isFinite(i)?"number":null:typeof i=="boolean"?"boolean":i instanceof Date||typeof i=="string"&&q0(i)?"date":"string"}function oS(i){const t=new Set;return i.forEach(e=>{const n=SF(e);n&&t.add(n)}),t.size===0?"string":t.size===1?[...t][0]:t.has("string")||t.has("date")?"string":t.has("number")?"number":"string"}function Gf(i){const t=new Map;for(const e of i)for(const[n,s]of Object.entries(e.properties??{})){if(xd(n))continue;const r=t.get(n);r?r.push(s):t.set(n,[s])}return[...t.entries()].map(([e,n])=>({name:e,type:oS(n)}))}function aS(i){const t=i.fields??[],e=new Set(t.map(s=>s.name)),n=Gf(i.getFeatures()).filter(s=>!e.has(s.name));return[...t.map(s=>({...s})),...n]}function Lr(i,t){return i.find(e=>e.name===t)}function Dh(i,t){if(t==null||typeof t=="string"&&t.trim()==="")return i.required?{ok:!1,error:`"${i.name}" cannot be empty`}:{ok:!0,value:null};let n;switch(i.type){case"number":{const s=typeof t=="number"?t:typeof t=="boolean"?t?1:0:Number(String(t).trim());if(!Number.isFinite(s))return{ok:!1,error:`"${i.name}" needs a number, got "${String(t)}"`};if(i.min!==void 0&&s<i.min)return{ok:!1,error:`"${i.name}" must be at least ${i.min}`};if(i.max!==void 0&&s>i.max)return{ok:!1,error:`"${i.name}" must be at most ${i.max}`};n=s;break}case"boolean":{if(typeof t=="boolean")n=t;else{const s=String(t).trim().toLowerCase();if(["true","1","yes","y","t"].includes(s))n=!0;else if(["false","0","no","n","f"].includes(s))n=!1;else return{ok:!1,error:`"${i.name}" needs true or false, got "${String(t)}"`}}break}case"date":{if(t instanceof Date){if(Number.isNaN(t.getTime()))return{ok:!1,error:`"${i.name}" got an invalid date`};n=t.toISOString().slice(0,10)}else{const s=String(t).trim(),r=s.length>10&&!Number.isNaN(Date.parse(s))?new Date(s).toISOString().slice(0,10):s;if(!q0(r))return{ok:!1,error:`"${i.name}" needs a date as YYYY-MM-DD, got "${s}"`};n=r}break}default:{const s=typeof t=="string"?t:String(t);if(i.length!==void 0&&[...s].length>i.length)return{ok:!1,error:`"${i.name}" allows ${i.length} characters, got ${[...s].length}`};n=s}}return i.allowedValues&&i.allowedValues.length>0&&!i.allowedValues.some(s=>s===n)?{ok:!1,error:`"${i.name}" allows only: ${i.allowedValues.join(", ")}`}:{ok:!0,value:n}}function z0(i,t){return t==null?"":typeof t=="boolean"?t?"true":"false":typeof t=="number"&&(i==null?void 0:i.precision)!==void 0?t.toFixed(i.precision):String(t)}function Gh(i,t){const e=i.trim();return e?xd(e)?`Field names cannot start with "${B0}" (reserved)`:t.some(n=>n.name===e)?`Field "${e}" already exists`:null:"Give the field a name"}const Jl=i=>i==null||i==="";function MF(i,t){return typeof i=="number"&&typeof t=="number"?i-t:typeof i=="boolean"&&typeof t=="boolean"?(i?1:0)-(t?1:0):String(i).localeCompare(String(t),"th")}function lS(i,t){try{if(To(i,t))return 0}catch{}const e=oi(i.geometry).length?oi(i.geometry):Av(i.geometry),n=oi(t.geometry).length?oi(t.geometry):Av(t.geometry);let s=1/0;const r=(o,a)=>{for(const l of o)for(const h of l){const f=tr(h[1]);for(const d of a){if(d.length===1){const p=Math.hypot((d[0][0]-h[0])*f[0],(d[0][1]-h[1])*f[1]);p<s&&(s=p);continue}for(let p=1;p<d.length;p++){const y=zo(h,d[p-1],d[p],f).distance;y<s&&(s=y)}}}};return r(e,n),r(n,e),s}function Av(i){return i.type==="Point"?[[i.coordinates]]:i.type==="MultiPoint"?i.coordinates.map(t=>[t]):[]}class uS{constructor(t){this.dataSource=t}layerOrThrow(t){const e=this.dataSource.getLayer(t);if(!e)throw new Error(`Layer "${t}" not found`);return e}getSchema(t){return aS(this.layerOrThrow(t))}setSchema(t,e){const n=this.layerOrThrow(t),s=n.fields?n.fields.map(a=>({...a})):void 0,r=e.map(a=>({...a})),o=a=>{n.fields=a?a.map(l=>({...l})):void 0,this.dataSource.emit("layer:updated",{layer:n})};o(r),this.dataSource.transactions.record({description:`Change the field schema of ${n.name}`,undo:()=>o(s),redo:()=>o(r)})}updateField(t,e,n){const s=this.getSchema(t),r=Lr(s,e);if(!r)throw new Error(`Field "${e}" not found in layer "${t}"`);return n.name&&n.name!==e?(this.renameField(t,e,n.name),this.updateField(t,n.name,{...n,name:void 0})):(Object.assign(r,n,{name:r.name}),this.setSchema(t,s),r)}addField(t,e,n={}){const s=this.layerOrThrow(t),r=this.getSchema(t),o=Gh(e.name,r);if(o)throw new Error(o);const a={...e,name:e.name.trim()};return this.dataSource.runTransaction(`Add field "${a.name}" to ${s.name}`,()=>{if(this.setSchema(t,[...r,a]),n.expression)return this.calculateField(t,a.name,n.expression);const l=Dh(a,a.defaultValue??null);if(!l.ok)throw new Error(l.error);const h=this.dataSource.updateFeaturePropertiesBatch(t,s.getFeatures().map(f=>({featureId:f.id,patch:{[a.name]:l.value}})),!0,`Fill field "${a.name}" in ${s.name}`);return{field:a.name,updated:h,skipped:0,errors:[]}})}deleteField(t,e){const n=this.layerOrThrow(t),s=this.getSchema(t);if(!Lr(s,e))throw new Error(`Field "${e}" not found in layer "${n.name}"`);return this.dataSource.runTransaction(`Delete field "${e}" from ${n.name}`,()=>(this.setSchema(t,s.filter(r=>r.name!==e)),this.dataSource.updateFeaturePropertiesBatch(t,n.getFeatures().filter(r=>r.properties&&e in r.properties).map(r=>({featureId:r.id,patch:{[e]:void 0}})),!0,`Remove field "${e}" from ${n.name}`)))}renameField(t,e,n){const s=this.layerOrThrow(t),r=this.getSchema(t);if(!Lr(r,e))throw new Error(`Field "${e}" not found in layer "${s.name}"`);const a=Gh(n,r.filter(h=>h.name!==e));if(a)throw new Error(a);const l=n.trim();return this.dataSource.runTransaction(`Rename field "${e}" to "${l}" in ${s.name}`,()=>(this.setSchema(t,r.map(f=>f.name===e?{...f,name:l,sourceName:f.sourceName??e}:f)),this.dataSource.updateFeaturePropertiesBatch(t,s.getFeatures().filter(f=>f.properties&&e in f.properties).map(f=>({featureId:f.id,patch:{[e]:void 0,[l]:f.properties[e]}})),!0,`Rename field "${e}" to "${l}" in ${s.name}`)))}defaultProperties(t){const e={};for(const n of this.getSchema(t))n.defaultValue!==void 0&&(e[n.name]=n.defaultValue);return e}query(t,e={}){const n=this.layerOrThrow(t),s=this.getSchema(t),r=new Set(this.dataSource.getSelectedFeatureIds(t).map(String));let o=n.getFeatures();const a=o.length;if(e.onlySelected&&(o=o.filter(p=>r.has(String(p.id)))),e.filter&&e.filter.trim()){const p=this.compile(t,e.filter);o=o.filter((y,_)=>p.test(y,_))}const l=o.length;if(e.sortBy){const p=e.sortBy,y=e.sortDescending?-1:1;o=[...o].sort((_,E)=>{var b,P;const w=(b=_.properties)==null?void 0:b[p],L=(P=E.properties)==null?void 0:P[p];return Jl(w)||Jl(L)?Jl(w)&&Jl(L)?0:Jl(w)?1:-1:y*MF(w,L)})}const h=Math.max(0,e.offset??0),f=e.limit??o.length,d=o.slice(h,h+f).map(p=>{var _;const y={};for(const E of s)y[E.name]=((_=p.properties)==null?void 0:_[E.name])??null;return{featureId:p.id,selected:r.has(String(p.id)),values:y}});return{layerId:t,fields:s,rows:d,total:a,filtered:l}}setValue(t,e,n,s){return this.setValues(t,[{featureId:e,field:n,value:s}])[0]}setValues(t,e){const n=this.layerOrThrow(t),s=this.getSchema(t),r=e.map(o=>{const a=Lr(s,o.field);if(!a)throw new Error(`Field "${o.field}" not found in layer "${n.name}"`);if(a.readOnly)throw new Error(`Field "${a.name}" is read-only`);const l=n.getFeature(o.featureId);if(!l)throw new Error(`Feature ${o.featureId} not found in layer "${n.name}"`);const h=Dh(a,o.value);if(!h.ok)throw new Error(h.error);return{feature:l,field:a,value:h.value}});return this.dataSource.runTransaction(e.length===1?`Edit ${e[0].field} of feature ${e[0].featureId}`:`Edit ${e.length} attribute values in ${n.name}`,()=>r.map(({feature:o,field:a,value:l})=>(this.dataSource.updateFeatureProperties(t,o.id,{[a.name]:l}),l)))}compile(t,e){const n=this.layerOrThrow(t),s=new Set(this.getSchema(t).map(r=>r.name));return Gf(n.getFeatures()).forEach(r=>s.add(r.name)),fd(e,s)}validateExpression(t,e){try{return{ok:!0,fields:this.compile(t,e).fields}}catch(n){return{ok:!1,error:n instanceof Error?n.message:String(n)}}}previewExpression(t,e,n){const s=this.layerOrThrow(t),r=n!==void 0?s.getFeature(n):s.getFeatures()[0];if(!r)throw new Error(`Layer "${s.name}" has no features`);return this.compile(t,e).evaluate(r)}calculateField(t,e,n,s={}){const r=this.layerOrThrow(t);let o=this.getSchema(t),a=Lr(o,e);const l=this.compile(t,n),h=new Set(this.dataSource.getSelectedFeatureIds(t).map(String)),f=s.onlySelected?r.getFeatures().filter(w=>h.has(String(w.id))):r.getFeatures();if(s.onlySelected&&f.length===0)throw new Error("No features are selected");const d=[],p=[];let y=0;if(!a){if(!s.createField)throw new Error(`Field "${e}" not found in layer "${r.name}" (use createField to add it)`);const w=f.map((N,S)=>{try{return l.evaluate(N,S)}catch{return null}}).find(N=>N!==null),L=typeof w=="number"?"number":typeof w=="boolean"?"boolean":"string",b=typeof s.createField=="object"?s.createField:void 0;a={...b,name:e,type:(b==null?void 0:b.type)??L};const P=Gh(a.name,o);if(P)throw new Error(P);o=[...o,a]}if(a.readOnly)throw new Error(`Field "${a.name}" is read-only`);if(f.forEach((w,L)=>{let b;try{b=l.evaluate(w,L)}catch(N){p.push({featureId:w.id,message:N instanceof Error?N.message:String(N)});return}const P=Dh(a,b);if(!P.ok){p.push({featureId:w.id,message:P.error});return}d.push({feature:w,value:P.value})}),p.length>0&&!s.skipErrors){const w=p[0];throw new Error(`${p.length} of ${f.length} features could not be calculated (feature ${w.featureId}: ${w.message}). Nothing was changed.`)}y=p.length;const _=!Lr(this.getSchema(t),a.name),E=a;return this.dataSource.runTransaction(`Calculate "${E.name}" in ${r.name}`,()=>(_&&this.setSchema(t,o),this.dataSource.updateFeaturePropertiesBatch(t,d.map(({feature:w,value:L})=>({featureId:w.id,patch:{[E.name]:L}})),!0,`Calculate "${E.name}" in ${r.name}`),{field:E.name,updated:d.length,skipped:y,errors:p}))}applySelection(t,e,n){const s=this.dataSource.getSelectedFeatureIds(t),r=new Set(s.map(String)),o=new Set(e.map(String));let a;switch(n){case"add":a=[...s,...e.filter(l=>!r.has(String(l)))];break;case"remove":a=s.filter(l=>!o.has(String(l)));break;case"intersect":a=s.filter(l=>o.has(String(l)));break;default:a=e}return this.dataSource.selectFeatures(t,a,!1),a}selectByExpression(t,e,n="new"){const s=this.layerOrThrow(t),r=this.compile(t,e),o=s.getFeatures().filter((a,l)=>r.test(a,l)).map(a=>a.id);return this.applySelection(t,o,n)}selectByLocation(t,e,n,s={}){var f;const r=this.layerOrThrow(t),o=this.layerOrThrow(n);let a=o.getFeatures();if((f=s.referenceFeatureIds)!=null&&f.length){const d=new Set(s.referenceFeatureIds.map(String));a=a.filter(p=>d.has(String(p.id)))}else if(s.onlySelectedReference){const d=new Set(this.dataSource.getSelectedFeatureIds(n).map(String));a=a.filter(p=>d.has(String(p.id)))}if(a.length===0)throw new Error(`No reference features in layer "${o.name}"`);if(e==="within-distance"&&!(s.distanceMeters>0))throw new Error("within-distance needs distanceMeters greater than 0");const l=s.distanceMeters??0,h=[];for(const d of r.getFeatures()){if(!d.geometry)continue;const p=vs(d.geometry),y=e==="within-distance"?Lo(p,l):p,_=e==="disjoint"?a:a.filter(E=>{const w=vs(E.geometry);return!(w[2]<y[0]||w[0]>y[2]||w[3]<y[1]||w[1]>y[3])});this.matchesPredicate(d,_,e,l)&&h.push(d.id)}return this.applySelection(t,h,s.mode??"new")}matchesPredicate(t,e,n,s){const r=(o,a=!1)=>{try{return a?e.every(o):e.some(o)}catch{return!1}};switch(n){case"intersects":return r(o=>To(t,o));case"disjoint":return r(o=>!To(t,o),!0);case"within":return r(o=>(o.geometry.type==="Polygon"||o.geometry.type==="MultiPolygon")&&TT(t,o));case"contains":return r(o=>(t.geometry.type==="Polygon"||t.geometry.type==="MultiPolygon")&&RE(t,o));case"touches":return r(o=>kT(t,o));case"crosses":return r(o=>wT(t,o));default:return e.some(o=>lS(t,o)<=s)}}selectionBBox(t){const e=this.dataSource.getSelectedFeatures(t);if(e.length===0)return null;const n=e.filter(s=>s.geometry).map(s=>vs(s.geometry));return n.length===0?null:[Math.min(...n.map(s=>s[0])),Math.min(...n.map(s=>s[1])),Math.max(...n.map(s=>s[2])),Math.max(...n.map(s=>s[3]))]}statistics(t,e,n={}){const s=this.layerOrThrow(t),r=this.getSchema(t),o=Lr(r,e);if(!o)throw new Error(`Field "${e}" not found in layer "${s.name}"`);const a=new Set(this.dataSource.getSelectedFeatureIds(t).map(String)),l=n.onlySelected?s.getFeatures().filter(_=>a.has(String(_.id))):s.getFeatures(),h=l.map(_=>{var E;return(E=_.properties)==null?void 0:E[e]}).filter(_=>_!=null&&_!==""),f={field:e,type:o.type,count:h.length,nullCount:l.length-h.length};if(o.type==="number"){const _=h.map(Number).filter(E=>Number.isFinite(E)).sort((E,w)=>E-w);if(_.length>0){const E=_.reduce((b,P)=>b+P,0),w=E/_.length,L=Math.floor(_.length/2);f.min=_[0],f.max=_[_.length-1],f.sum=E,f.mean=w,f.median=_.length%2?_[L]:(_[L-1]+_[L])/2,f.stdDev=Math.sqrt(_.reduce((b,P)=>b+(P-w)**2,0)/_.length)}return f.distinct=new Set(_).size,f}const d=new Map;h.forEach(_=>{const E=String(_);d.set(E,(d.get(E)??0)+1)});const p=[...d.entries()].sort((_,E)=>E[1]-_[1]||_[0].localeCompare(E[0],"th"));f.distinct=d.size,f.topValues=p.slice(0,10).map(([_,E])=>({value:_,count:E}));const y=[...d.keys()].sort((_,E)=>_.localeCompare(E,"th"));return y.length&&(f.min=y[0],f.max=y[y.length-1]),f}undeclaredFields(t){const e=this.layerOrThrow(t),n=new Set((e.fields??[]).map(s=>s.name));return Gf(e.getFeatures()).map(s=>s.name).filter(s=>!n.has(s)&&!xd(s))}}const Ql=50,NF=["string","number","boolean","date"];class LF{constructor(t,e,n={}){Y(this,"container",null);Y(this,"unsubscribers",[]);Y(this,"layerId",null);Y(this,"filter","");Y(this,"onlySelected",!1);Y(this,"sortBy",null);Y(this,"sortDescending",!1);Y(this,"page",0);Y(this,"editing",null);Y(this,"message",null);Y(this,"dialog",null);Y(this,"handleChange",t=>{var o,a,l;const e=t.target,n=e.getAttribute("data-field"),s=this.currentLayerId();if(n==="layer"){this.open(e.value);return}if(n==="only-selected"){this.onlySelected=e.checked,this.page=0,this.render();return}if(n==="filter"){this.filter=e.value,this.page=0,this.render();return}if(n==="calc-field"&&((o=this.dialog)==null?void 0:o.kind)==="calculator"){const h=e.value;this.dialog.field=h==="__new__"?(window.prompt("Name of the new field")??"").trim():h,this.render();return}if(n==="calc-expression"&&((a=this.dialog)==null?void 0:a.kind)==="calculator"){this.dialog.expression=e.value,this.render();return}if(n==="calc-selected"&&((l=this.dialog)==null?void 0:l.kind)==="calculator"){this.dialog.onlySelected=e.checked;return}const r=e.getAttribute("data-edit");if(r&&this.editing&&s){const h=e.value,{featureId:f}=this.editing;this.editing=null,this.run(()=>{this.attributes.setValue(s,f,r,h)})}});Y(this,"handleKeyDown",t=>{const e=t.target;if(e.getAttribute("data-field")==="filter"&&t.key==="Enter"){this.filter=e.value,this.page=0,this.render();return}e.getAttribute("data-edit")&&(t.key==="Escape"?(this.editing=null,this.render()):t.key==="Enter"&&e.blur())});Y(this,"handleDoubleClick",t=>{var o,a,l,h;const e=t.target.closest("[data-row]"),n=this.currentLayerId();if(!e||!n)return;const s=e.getAttribute("data-row"),r=t.target.closest("[data-cell]");if(r){const f=r.getAttribute("data-cell"),d=this.attributes.getSchema(n).find(p=>p.name===f);if(d&&!d.readOnly){this.editing={featureId:s,field:f},this.render(),(a=(o=this.container)==null?void 0:o.querySelector("[data-edit]"))==null||a.focus();return}}(h=(l=this.options).onZoom)==null||h.call(l,n,s)});Y(this,"handleClick",t=>{var l,h,f,d,p;const e=t.target.closest("[data-action], [data-sort], [data-row]"),n=this.currentLayerId();if(!e||!n)return;const s=e.getAttribute("data-action"),r=((l=this.dataSource.getLayer(n))==null?void 0:l.name)??n;switch(s){case"close":(f=(h=this.options).onClose)==null||f.call(h);return;case"prev":this.page=Math.max(0,this.page-1),this.render();return;case"next":this.page+=1,this.render();return;case"calculator":this.dialog={kind:"calculator",field:((d=this.attributes.getSchema(n).find(y=>!y.readOnly))==null?void 0:d.name)??"",expression:"",onlySelected:this.onlySelected},this.render();return;case"add-field":this.dialog={kind:"add-field"},this.render();return;case"dialog-close":this.dialog=null,this.render();return;case"calc-apply":{const y=this.dialog,_=this.value("calc-expression"),E=this.checked("calc-selected"),w=y.field;this.run(()=>{if(!w)throw new Error("Choose a field");const L=this.attributes.getSchema(n).some(P=>P.name===w),b=this.attributes.calculateField(n,w,_,{onlySelected:E,createField:!L});return this.dialog=null,`"${b.field}" updated for ${b.updated} features (undo to revert)`});return}case"add-field-apply":{const y=this.value("new-name").trim(),_=this.value("new-type"),E=this.value("new-default").trim(),w=this.value("new-expression").trim();this.run(()=>{const L=E===""?void 0:_==="number"?Number(E):_==="boolean"?E==="true":E,b=this.attributes.addField(n,{name:y,type:_,defaultValue:L},{expression:w||void 0});return this.dialog=null,`Added "${b.field}" (${b.updated} features)`});return}case"delete-field":{const y=e.getAttribute("data-field-name"),_=this.attributes.getSchema(n).find(w=>w.name===y);if(!_||!(this.options.confirmDelete?this.options.confirmDelete(_,r):typeof window>"u"||window.confirm(`Delete field "${y}" from "${r}"? (undo restores it)`)))return;this.run(()=>`Deleted "${y}" from ${this.attributes.deleteField(n,y)} features (undo to restore)`);return}case"field-stats":{const y=e.getAttribute("data-field-name");this.run(()=>{const _=this.attributes.statistics(n,y,{onlySelected:this.onlySelected});return _.type==="number"&&_.sum!==void 0?`${y}: n=${_.count} · min ${_.min} · max ${_.max} · sum ${_.sum} · mean ${_.mean.toFixed(3)} · median ${_.median}`:`${y}: n=${_.count} · ${_.distinct} distinct · empty ${_.nullCount}`});return}}const o=e.getAttribute("data-sort");if(o){this.sortBy===o?this.sortDescending=!this.sortDescending:(this.sortBy=o,this.sortDescending=!1),this.page=0,this.render();return}const a=e.getAttribute("data-row");if(a!==null){const y=t.ctrlKey||t.metaKey,_=this.dataSource.getLayer(n),E=((p=_==null?void 0:_.getFeature(a))==null?void 0:p.id)??a;y?this.dataSource.toggleFeatureSelection(n,E):this.dataSource.selectFeatures(n,[E],!1)}});this.dataSource=t,this.attributes=e,this.options=n}mount(t){const e=typeof t=="string"?document.getElementById(t):t;if(!e)throw new Error(`Target container for OFSAttributeTable not found: ${t}`);this.unmount(),this.container=e,e.classList.add("ofs-attribute-table"),e.addEventListener("click",this.handleClick),e.addEventListener("change",this.handleChange),e.addEventListener("keydown",this.handleKeyDown),e.addEventListener("dblclick",this.handleDoubleClick),this.unsubscribers.push(this.dataSource.on("features:changed",({layerId:n})=>n===this.currentLayerId()&&this.render()),this.dataSource.on("selection:changed",({layerId:n})=>n===this.currentLayerId()&&this.render()),this.dataSource.on("layer:updated",({layer:n})=>n.id===this.currentLayerId()&&this.render()),this.dataSource.on("layer:added",()=>this.render()),this.dataSource.on("layer:removed",()=>this.render())),this.render()}unmount(){this.unsubscribers.forEach(t=>t()),this.unsubscribers=[],this.container&&(this.container.removeEventListener("click",this.handleClick),this.container.removeEventListener("change",this.handleChange),this.container.removeEventListener("keydown",this.handleKeyDown),this.container.removeEventListener("dblclick",this.handleDoubleClick),this.container.innerHTML="",this.container.classList.remove("ofs-attribute-table"),this.container=null)}open(t){t!==this.layerId&&(this.layerId=t,this.page=0,this.sortBy=null,this.filter="",this.editing=null,this.message=null),this.render()}getLayerId(){return this.currentLayerId()}dataLayers(){return this.dataSource.getAllLayers().filter(t=>t.tag!=="topology")}currentLayerId(){var e;const t=this.dataLayers();return this.layerId&&t.some(n=>n.id===this.layerId)?this.layerId:this.dataSource.getActiveLayerId()??((e=t[0])==null?void 0:e.id)??null}render(){if(!this.container)return;const t=this.currentLayerId();if(!t){this.container.innerHTML='<div class="ofs-attr-empty">No layers yet.</div>';return}let e,n=null;try{e=this.attributes.query(t,{filter:this.filter,onlySelected:this.onlySelected,sortBy:this.sortBy??void 0,sortDescending:this.sortDescending,offset:this.page*Ql,limit:Ql})}catch(o){n=o instanceof Error?o.message:String(o),e=this.attributes.query(t,{offset:this.page*Ql,limit:Ql})}const s=this.dataLayers(),r=Math.max(1,Math.ceil(e.filtered/Ql));this.container.innerHTML=`
|
|
322
|
+
<div class="ofs-attr-header">
|
|
323
|
+
<span class="ofs-attr-title">🧾 Attributes</span>
|
|
324
|
+
<select data-field="layer">
|
|
325
|
+
${s.map(o=>`<option value="${Tt(o.id)}" ${o.id===t?"selected":""}>${Tt(o.name)} (${o.count})</option>`).join("")}
|
|
326
|
+
</select>
|
|
327
|
+
${this.options.onClose?'<button class="ofs-btn-mini" data-action="close" title="Close">✕</button>':""}
|
|
328
|
+
</div>
|
|
329
|
+
<div class="ofs-attr-toolbar">
|
|
330
|
+
<input type="text" data-field="filter" value="${Tt(this.filter)}" placeholder="Filter, e.g. crop = 'ข้าว' AND $area > 1600" />
|
|
331
|
+
<label class="ofs-attr-check"><input type="checkbox" data-field="only-selected" ${this.onlySelected?"checked":""}/> selected</label>
|
|
332
|
+
<button class="ofs-btn-mini" data-action="calculator" title="Field calculator">ƒx</button>
|
|
333
|
+
<button class="ofs-btn-mini" data-action="add-field" title="Add field">+</button>
|
|
334
|
+
</div>
|
|
335
|
+
${n?`<div class="ofs-attr-message error">${Tt(n)}</div>`:""}
|
|
336
|
+
${this.message?`<div class="ofs-attr-message ${this.message.kind}">${Tt(this.message.text)}</div>`:""}
|
|
337
|
+
${this.dialog?this.renderDialog(e.fields):""}
|
|
338
|
+
<div class="ofs-attr-scroll">
|
|
339
|
+
<table>
|
|
340
|
+
<thead><tr><th class="ofs-attr-id">id</th>${e.fields.map(o=>this.renderHeader(o)).join("")}</tr></thead>
|
|
341
|
+
<tbody>${e.rows.map(o=>this.renderRow(o.featureId,o.selected,o.values,e.fields)).join("")}</tbody>
|
|
342
|
+
</table>
|
|
343
|
+
</div>
|
|
344
|
+
<div class="ofs-attr-footer">
|
|
345
|
+
<span>${e.filtered} of ${e.total} features${this.filter||this.onlySelected?" (filtered)":""}</span>
|
|
346
|
+
<span class="ofs-attr-pager">
|
|
347
|
+
<button class="ofs-btn-mini" data-action="prev" ${this.page===0?"disabled":""}>◀</button>
|
|
348
|
+
${this.page+1} / ${r}
|
|
349
|
+
<button class="ofs-btn-mini" data-action="next" ${this.page+1>=r?"disabled":""}>▶</button>
|
|
350
|
+
</span>
|
|
351
|
+
</div>
|
|
352
|
+
`}renderHeader(t){const e=this.sortBy===t.name?this.sortDescending?" ▼":" ▲":"",n=[t.name,t.type,t.readOnly?"read-only":"",t.required?"required":""].filter(Boolean).join(" · ");return`<th data-sort="${Tt(t.name)}" title="${Tt(n)}">
|
|
353
|
+
${Tt(t.alias??t.name)}${e}
|
|
354
|
+
<button class="ofs-attr-field-menu" data-action="field-stats" data-field-name="${Tt(t.name)}" title="Statistics">Σ</button>
|
|
355
|
+
<button class="ofs-attr-field-menu" data-action="delete-field" data-field-name="${Tt(t.name)}" title="Delete field">✕</button>
|
|
356
|
+
</th>`}renderRow(t,e,n,s){const r=s.map(o=>{var h;const a=n[o.name];if(this.editing&&String(this.editing.featureId)===String(t)&&this.editing.field===o.name)return`<td class="editing">${(h=o.allowedValues)!=null&&h.length?`<select data-edit="${Tt(o.name)}">${["",...o.allowedValues.map(String)].map(d=>`<option value="${Tt(d)}" ${String(a??"")===d?"selected":""}>${Tt(d||"(empty)")}</option>`).join("")}</select>`:`<input data-edit="${Tt(o.name)}" type="${o.type==="number"?"number":o.type==="date"?"date":"text"}" step="any" value="${Tt(a==null?"":String(a))}" />`}</td>`;const l=z0(o,a);return`<td data-cell="${Tt(o.name)}" class="${o.readOnly?"readonly":""} ${o.type==="number"?"num":""}" title="${Tt(l)}">${Tt(l)}</td>`}).join("");return`<tr data-row="${Tt(String(t))}" class="${e?"selected":""}"><td class="ofs-attr-id">${Tt(String(t))}</td>${r}</tr>`}renderDialog(t){const e=this.dialog;if((e==null?void 0:e.kind)==="calculator"){const n=(()=>{const s=this.currentLayerId();if(!s||!e.expression.trim())return"";try{const r=this.attributes.previewExpression(s,e.expression);return`First feature: ${r===null?"NULL":String(r)}`}catch(r){return r instanceof Error?r.message:String(r)}})();return`<div class="ofs-attr-dialog">
|
|
357
|
+
<div class="ofs-attr-dialog-title">Field calculator</div>
|
|
358
|
+
<label class="ofs-attr-row"><span>Field</span>
|
|
359
|
+
<select data-field="calc-field">
|
|
360
|
+
${t.filter(s=>!s.readOnly).map(s=>`<option value="${Tt(s.name)}" ${s.name===e.field?"selected":""}>${Tt(s.name)}</option>`).join("")}
|
|
361
|
+
<option value="__new__">➕ new field…</option>
|
|
362
|
+
</select>
|
|
363
|
+
</label>
|
|
364
|
+
<textarea data-field="calc-expression" rows="2" placeholder="round($area / 1600, 2)">${Tt(e.expression)}</textarea>
|
|
365
|
+
<label class="ofs-attr-check"><input type="checkbox" data-field="calc-selected" ${e.onlySelected?"checked":""}/> only selected features</label>
|
|
366
|
+
<div class="ofs-attr-preview">${Tt(n)}</div>
|
|
367
|
+
<details><summary>Functions</summary><div class="ofs-attr-help">${Tt(hd().join(", "))}<br/>${If().map(s=>Tt(s.help)).join("<br/>")}</div></details>
|
|
368
|
+
<div class="ofs-attr-dialog-actions">
|
|
369
|
+
<button class="ofs-btn" data-action="calc-apply">Apply</button>
|
|
370
|
+
<button class="ofs-btn-secondary" data-action="dialog-close">Cancel</button>
|
|
371
|
+
</div>
|
|
372
|
+
</div>`}return(e==null?void 0:e.kind)==="add-field"?`<div class="ofs-attr-dialog">
|
|
373
|
+
<div class="ofs-attr-dialog-title">New field</div>
|
|
374
|
+
<label class="ofs-attr-row"><span>Name</span><input type="text" data-field="new-name" /></label>
|
|
375
|
+
<label class="ofs-attr-row"><span>Type</span>
|
|
376
|
+
<select data-field="new-type">${NF.map(n=>`<option value="${n}">${n}</option>`).join("")}</select>
|
|
377
|
+
</label>
|
|
378
|
+
<label class="ofs-attr-row"><span>Default</span><input type="text" data-field="new-default" /></label>
|
|
379
|
+
<label class="ofs-attr-row"><span>Expression</span><input type="text" data-field="new-expression" placeholder="optional, e.g. round($area / 1600, 2)" /></label>
|
|
380
|
+
<div class="ofs-attr-dialog-actions">
|
|
381
|
+
<button class="ofs-btn" data-action="add-field-apply">Add</button>
|
|
382
|
+
<button class="ofs-btn-secondary" data-action="dialog-close">Cancel</button>
|
|
383
|
+
</div>
|
|
384
|
+
</div>`:""}value(t){var n;const e=(n=this.container)==null?void 0:n.querySelector(`[data-field="${t}"]`);return(e==null?void 0:e.value)??""}checked(t){var n;const e=(n=this.container)==null?void 0:n.querySelector(`[data-field="${t}"]`);return!!(e!=null&&e.checked)}run(t){try{const e=t();this.message=e?{text:e,kind:"info"}:null}catch(e){this.message={text:e instanceof Error?e.message:String(e),kind:"error"}}this.render()}}const Bf=1600,Rm=400,cS=4;function hS(i){return we.forGeometries([{type:"LineString",coordinates:i}])}function ac(i,t=Ur){if(i.length<2)throw new Error("Measuring a distance needs at least 2 points");const e=hS(i),n=i.map(l=>e.toPlanar(l)),s=[];let r=0;for(let l=1;l<i.length;l++){const h=n[l][0]-n[l-1][0],f=n[l][1]-n[l-1][1],d=Math.hypot(h,f);r+=d,s.push({from:i[l-1],to:i[l],meters:d,angleDeg:ul(Math.atan2(f,h),t)})}const o=n[0],a=n[n.length-1];return{segments:s,totalMeters:r,closingMeters:Math.hypot(a[0]-o[0],a[1]-o[1])}}function fS(i){if(i.length<3)throw new Error("Measuring an area needs at least 3 points");const t=i[0],e=i[i.length-1],n=t[0]===e[0]&&t[1]===e[1]?i:[...i,t],s=Mi({type:"Polygon",coordinates:[n]});return{areaSqm:s.area,perimeterMeters:s.perimeter,...bd(s.area)}}function bd(i){const t=Math.floor(i/Bf),e=i-t*Bf,n=Math.floor(e/Rm),s=(e-n*Rm)/cS;return{rai:t,ngan:n,squareWa:s,raiNganWa:Kp(i,1)}}function dS(i,t,e,n=Ur){const s=hS([i,t,e]),r=s.toPlanar(t),o=s.toPlanar(i),a=s.toPlanar(e),l=[o[0]-r[0],o[1]-r[1]],h=[a[0]-r[0],a[1]-r[1]],f=Math.hypot(l[0],l[1]),d=Math.hypot(h[0],h[1]);if(f===0||d===0)throw new Error("Measuring an angle needs three different points");const p=(l[0]*h[0]+l[1]*h[1])/(f*d);return{degrees:Math.acos(Math.max(-1,Math.min(1,p)))*180/Math.PI,firstAngleDeg:ul(Math.atan2(l[1],l[0]),n),secondAngleDeg:ul(Math.atan2(h[1],h[0]),n),firstMeters:f,secondMeters:d}}function gS(i,t=Ur){const e=i.geometry;if(e.type==="Polygon"||e.type==="MultiPolygon"){const n=Mi(e);return{area:{areaSqm:n.area,perimeterMeters:n.perimeter,...bd(n.area)}}}if(e.type==="LineString"||e.type==="MultiLineString"){const n=oi(e),s=[];let r=0;n.forEach(h=>{const f=ac(h,t);s.push(...f.segments),r+=f.totalMeters});const o=n[0],a=n[n.length-1],l=ac([o[0],a[a.length-1]],t).totalMeters;return{length:{segments:s,totalMeters:r,closingMeters:l}}}return{}}const qf=(i,t)=>i.toLocaleString("en-US",{minimumFractionDigits:t,maximumFractionDigits:t});function cs(i,t=3){return Math.abs(i)>=1e3?`${qf(i/1e3,Math.min(t,3))} km`:`${qf(i,t)} m`}function Bh(i,t=2){const e=bd(i);return`${qf(i,t)} m² · ${qf(i/Bf,t)} rai · ${e.raiNganWa} (rai-ngan-wa)`}function _a(i,t="bearing"){if(t==="decimal")return`${i.toFixed(4)}°`;const e=Math.abs(i),n=Math.floor(e),s=(e-n)*60,r=Math.floor(s),o=(s-r)*60;return`${i<0?"-":""}${n}°${String(r).padStart(2,"0")}'${o.toFixed(1).padStart(4,"0")}"`}const U0=5e4,CF=Math.sqrt(3)/2;class mS extends Pe{constructor(t,e,n){super(`A ${n} m grid over this boundary would be about ${t.toLocaleString()} points, above the limit of ${e.toLocaleString()}. Use a larger spacing, a smaller boundary, or raise the limit deliberately.`),this.name="GridTooLargeError"}}function PF(i,t,e,n){const s=i[0]-t[0],r=i[1]-t[1];return[t[0]+s*e-r*n,t[1]+s*n+r*e]}function kF(i){let t=1/0,e=1/0,n=-1/0,s=-1/0;const r=o=>o.forEach(([a,l])=>{a<t&&(t=a),l<e&&(e=l),a>n&&(n=a),l>s&&(s=l)});return i.forEach(o=>{o.type==="Polygon"?o.coordinates.forEach(r):o.coordinates.forEach(a=>a.forEach(r))}),[t,e,n,s]}function pS(i,t){const e=t.spacingMeters;if(!Number.isFinite(e)||e<=0)throw new Pe("Grid spacing must be a positive number of meters.");if(i.length===0)throw new Pe("The boundary has no polygons.");const n=t.pattern??"square",s=t.insetMeters??0,r=t.maxPoints??U0,o=n==="triangular"?e*CF:t.rowSpacingMeters??e;if(o<=0)throw new Pe("Row spacing must be a positive number of meters.");const a=we.forGeometries(i);let l=i.map(A=>a.projectGeometry(A));if(s!==0&&(l=l.map(A=>Dw(A,-Math.abs(s))).filter(A=>A!==null),l.length===0))throw new Pe(`An inset of ${Math.abs(s)} m leaves no area inside the boundary.`);const h=l.map(A=>A.type==="Polygon"?Ce(A.coordinates):bo(A.coordinates)),[f,d,p,y]=kF(l),_=[(f+p)/2,(d+y)/2],E=(t.rotateDegrees??0)*Math.PI/180,w=Math.cos(E),L=Math.sin(E),b=E===0?0:Math.hypot(p-f,y-d)/2,P=p-f+b*2,N=y-d+b*2,S=Math.floor(P/e)+1,C=Math.floor(N/o)+1,T=_[0]-(S-1)*e/2,I=_[1]-(C-1)*o/2,M=S*C;if(M>r)throw new mS(M,r,e);const R=[];for(let A=0;A<C;A++){const F=I+A*o,$=n==="triangular"&&A%2===1?e/2:0;for(let z=0;z<S;z++){const D=PF([T+z*e+$,F],_,w,L);h.some(B=>mk(D,B))&&R.push(a.toGeographic(D))}}return{points:R,candidates:M,pattern:n,spacingMeters:e,rowSpacingMeters:o}}const Y0=5e3;class yS extends Pe{constructor(t,e){super(`Connecting ${t.toLocaleString()} points is above the limit of ${e.toLocaleString()}; the spanning tree compares every pair. Work in smaller blocks or raise the limit deliberately.`),this.name="NetworkTooLargeError"}}const Va=(i,t)=>Math.hypot(t[0]-i[0],t[1]-i[1]);function Ov(i){const t=[];if(i.length<2)return t;const e=new Array(i.length).fill(!1),n=new Array(i.length).fill(0),s=i.map(r=>Va(i[0],r));e[0]=!0;for(let r=1;r<i.length;r++){let o=-1;for(let a=0;a<i.length;a++)!e[a]&&(o===-1||s[a]<s[o])&&(o=a);if(o===-1)break;e[o]=!0,t.push([n[o],o]);for(let a=0;a<i.length;a++){if(e[a])continue;const l=Va(i[o],i[a]);l<s[a]&&(s[a]=l,n[a]=o)}}return t}function TF(i){if(i.length<2)return 0;const t=new Map;i.forEach((n,s)=>{let r=-1,o=1/0;if(i.forEach((p,y)=>{if(s===y)return;const _=Va(n,p);_<o&&(o=_,r=y)}),r===-1)return;const a=i[r][0]-n[0],l=i[r][1]-n[1];let h=Math.atan2(l,a)*180/Math.PI;h<0&&(h+=180),h>=180&&(h-=180);const f=Math.round(h/5)*5,d=t.get(f)??{count:0,sum:0};d.count+=1,d.sum+=h,t.set(f,d)});let e={count:0,sum:0};return t.forEach(n=>{n.count>e.count&&(e=n)}),e.count===0?0:e.sum/e.count}function RF(i,t,e){const n=t*Math.PI/180,s=[Math.cos(n),Math.sin(n)],r=[-s[1],s[0]],o=i.map(h=>({point:h,offset:h[0]*r[0]+h[1]*r[1],position:h[0]*s[0]+h[1]*s[1]}));o.sort((h,f)=>h.offset-f.offset);const a=[];let l=[];return o.forEach(h=>{l.length>0&&Math.abs(h.offset-l[l.length-1].offset)>e&&(a.push(l.sort((f,d)=>f.position-d.position).map(f=>f.point)),l=[]),l.push(h)}),l.length>0&&a.push(l.sort((h,f)=>h.position-f.position).map(h=>h.point)),a}function AF(i,t){const e=t*Math.PI/180,n=[-Math.sin(e),Math.cos(e)],s=i.map(o=>o[0]*n[0]+o[1]*n[1]).sort((o,a)=>o-a),r=[];for(let o=1;o<s.length;o++){const a=s[o]-s[o-1];a>1e-6&&r.push(a)}return r.length===0?0:(r.sort((o,a)=>o-a),r[Math.floor(r.length/2)])}function _S(i,t,e={}){if(i.length===0)throw new Pe("There are no points to connect.");const n=e.maxPoints??Y0;if(i.length>n)throw new yS(i.length,n);const s=e.mode??"rows",r=we.forGeometries([{type:"MultiPoint",coordinates:[...i,t]}]),o=i.map(_=>r.toPlanar(_)),a=r.toPlanar(t),l=[],h=(_,E)=>{if(E.length<2)return;let w=0;for(let L=1;L<E.length;L++)w+=Va(E[L-1],E[L]);w<=0||l.push({role:_,coordinates:E.map(L=>r.toGeographic(L)),lengthMeters:w})};let f=0,d=null;if(s==="tree"){const _=[a,...o];Ov(_).forEach(([E,w])=>h("trunk",[_[E],_[w]]))}else{d=e.angleDegrees??TF(o);const _=AF(o,d),E=e.toleranceMeters??Math.max(_/4,.01),w=RF(o,d,E);f=w.length;const L=[];w.forEach(P=>{h("branch",P);const N=P[0],S=P[P.length-1];L.push(Va(a,N)<=Va(a,S)?N:S)});const b=[a,...L];Ov(b).forEach(([P,N])=>h("trunk",[b[P],b[N]]))}const p=l.filter(_=>_.role==="branch").reduce((_,E)=>_+E.lengthMeters,0),y=l.filter(_=>_.role==="trunk").reduce((_,E)=>_+E.lengthMeters,0);return{lines:l,totalLengthMeters:p+y,branchLengthMeters:p,trunkLengthMeters:y,runCount:f,mode:s,angleDegrees:d}}const OF=["check","list","zoom","fix","show","hide","clear"],Rg=30,FF=5e3,$F=700;function Am(i){const t=i.fix?" [fixable]":"";return`#${i.id} ${i.severity==="error"?"✖":"⚠"} ${i.code}: ${i.message}${t}`}function DF(i,t,e=15){const n=t.issues.filter(h=>h.severity==="error").length,s=t.issues.length-n,r=(t.durationMs/1e3).toFixed(2);i.print(`Topology of "${t.layerName}": ${t.featureCount} features checked in ${r} s — ${n} errors, ${s} warnings.`,t.issues.length===0?"success":n>0?"error":"output");const o=Object.entries(t.summary).map(([h,f])=>`${h} ${f}`);o.length&&i.print(` ${o.join(" · ")}`,"output");const a=t.ignored,l=[];a.overlapsBelowTolerance&&l.push(`${a.overlapsBelowTolerance} overlaps ≤ ${t.options.areaToleranceSqm} m²`),a.gapsBelowTolerance&&l.push(`${a.gapsBelowTolerance} gaps ≤ ${t.options.areaToleranceSqm} m²`),a.gapsAboveMaxArea&&l.push(`${a.gapsAboveMaxArea} open areas > ${t.options.gapMaxAreaSqm} m²`),a.ownHoles&&l.push(`${a.ownHoles} holes inside single features`),l.length&&i.print(` Not reported: ${l.join(", ")}.`,"output"),t.skippedFeatureIds.length&&i.print(` ${t.skippedFeatureIds.length} invalid features were left out of the overlap / gap checks (fix them first).`,"output"),t.failures.forEach(h=>i.print(` ✖ ${h.check} check: ${h.message}`,"error")),t.issues.slice(0,e).forEach(h=>i.print(Am(h),h.severity==="error"?"error":"output")),t.issues.length>e&&i.print(`… ${t.issues.length-e} more (topology list)`,"output")}function GF(i,t,e){function n(){const h=t.getReport();if(!h)throw new Error('Run "topology check" first.');return h}function s(h){const f=h??i.getActiveLayerId();if(!f)throw new Error("No layer given and no active layer.");const d=i.getLayer(f)??i.getAllLayers().find(p=>p.name===f);if(!d)throw new Error(`Layer "${f}" not found.`);return d.id}async function r(h,f,d,p,y){var b;const _=((b=i.getLayer(h))==null?void 0:b.count)??0;let E=0;const w=_<FF?void 0:P=>{const N=Date.now();if(N-E<$F)return;E=N;const S=P.total>0?Math.round(P.done/P.total*100):0;p.print(` ${P.stage}: ${S}% (${P.done.toLocaleString("en-US")} of ${P.total.toLocaleString("en-US")}) — Esc to stop`,"output")},L=await t.checkAsync(h,f,{onProgress:w,signal:y});return DF(p,L),d&&(t.showIssues(h),p.print('Issues are shown in the "Topology errors" layer group (topology hide to remove).',"output")),L}function o(h,f){const d=n(),p=d.issues.find(E=>E.id===h);if(!p)throw new Error(`Issue #${h} not found (1–${d.issues.length}).`);const y=i.getLayer(d.layerId),_=p.featureIds.filter(E=>y==null?void 0:y.hasFeature(E));return _.length&&i.selectFeatures(d.layerId,_,!1),e==null||e(t.issueBBox(p)),f.print(Am(p),p.severity==="error"?"error":"output"),p}async function a(h,f,d,p){const y=n();if(h.length===0)return p.print("No fixable issues match.","output"),null;if(h.length===1){const E=t.fixIssue(h[0],f,y.layerId);p.print(`#${E.issueId} ${E.message} (undo to revert)`,"success")}else{if(d){const w=await p.requestInput(`Fix ${h.length} issues in "${y.layerName}" as one undo step? (y/N)`);if(!/^y(es)?$/i.test(w.trim()))return p.print("Cancelled.","output"),null}const E=t.fixIssues(h,f,y.layerId);p.print(`Fixed ${E.results.length} of ${h.length} issues (undo reverts all).`,E.results.length?"success":"output"),E.results.slice(0,10).forEach(w=>p.print(` #${w.issueId} ${w.message}`,"output")),E.skipped.forEach(w=>p.print(` #${w.issueId} skipped: ${w.reason}`,"output")),E.failed.forEach(w=>p.print(` #${w.issueId} ✖ ${w.message}`,"error"))}const _=t.getReport(y.layerId);return p.print(`Re-checked: ${_.issues.length} issues remain.`,"output"),_}const l={name:"topology",aliases:["topo","checkgeom"],description:"Check a layer for invalid geometry, overlaps, gaps, slivers and near-miss vertices; zoom to and fix issues",usage:"topology [check] [layer] [--near 0.1] [--show] | list | zoom <n> | fix <n|all|code> [--from id|smaller|larger] [--into id|longest|largest] | show | hide | clear",isInteractive:!0,schema:{type:"object",properties:{action:{type:"string",enum:OF,default:"check"},layerId:{type:"string",description:"Layer to check (default: active layer)"},checks:{type:"array",items:{type:"string",enum:Dr.checks}},vertexToleranceMeters:{type:"number",minimum:0,description:"Points closer than this are the same point (default 0.001)"},areaToleranceSqm:{type:"number",minimum:0,description:"Overlaps / gaps up to this area are not reported (default 0.01)"},gapMaxAreaSqm:{type:"number",minimum:0,description:"Enclosed empty areas larger than this are intentional (default: no limit)"},sliverWidthMeters:{type:"number",minimum:0,description:"Polygons with a mean width below this are slivers (default 0.2)"},minAreaSqm:{type:"number",minimum:0,description:"Report polygons smaller than this (default: off)"},nearToleranceMeters:{type:"number",minimum:0,description:"Report vertices / line ends this close to another feature without touching (default 0.1)"},show:{type:"boolean",description:"Show issues as map layers"},yes:{type:"boolean",description:"Fix several issues without asking first"},target:{type:"string",description:"What the action works on: the layer (check), the issue number (zoom), or n[,n…] | all | code (fix, list)"},issueId:{type:"number"},issueIds:{type:"array",items:{type:"number"}},removeFrom:{type:"string",description:'Overlap fix: feature id that gives up the overlap, or "smaller" / "larger"'},mergeInto:{type:"string",description:'Gap fix: feature id that receives the gap, or "longest-boundary" (default) / "largest"'},moveFeatureId:{type:"string",description:"Snap fix: feature whose vertices move (default: first feature of the issue)"}}},args:{positional:["action","target"],aliases:{layer:"layerId","vertex-tol":"vertexToleranceMeters","area-tol":"areaToleranceSqm","gap-max":"gapMaxAreaSqm","sliver-width":"sliverWidthMeters","min-area":"minAreaSqm",near:"nearToleranceMeters",from:"removeFrom",into:"mergeInto",move:"moveFeatureId"},fallback:{action:"layerId"}},async execute(h,f){const d=Vt(h),p=d.action??"check",y=d.target;switch(p){case"check":{const _={checks:d.checks,vertexToleranceMeters:d.vertexToleranceMeters,areaToleranceSqm:d.areaToleranceSqm,gapMaxAreaSqm:d.gapMaxAreaSqm,sliverWidthMeters:d.sliverWidthMeters,minAreaSqm:d.minAreaSqm,nearToleranceMeters:d.nearToleranceMeters};return h.payload=await r(s(d.layerId??y),_,!!d.show,f,h.abortSignal),h}case"list":{const _=n(),E=y,w=E?_.issues.filter(L=>L.code===E||L.check===E):_.issues;return f.print(`${w.length} issues in "${_.layerName}"${E?` (${E})`:""}:`,"output"),w.slice(0,Rg).forEach(L=>f.print(Am(L),L.severity==="error"?"error":"output")),w.length>Rg&&f.print(`… ${w.length-Rg} more`,"output"),h.payload=w,h}case"zoom":{const _=Number(d.issueId??y);if(!Number.isInteger(_))throw new Error("Usage: topology zoom <issue number>");return h.payload=o(_,f),h}case"fix":{const _=n(),E=d.issueIds??(d.issueId!==void 0?[Number(d.issueId)]:null);if(!E&&!y)throw new Error("Usage: topology fix <n[,n…]|all|code> [--from id|smaller|larger] [--into id|longest|largest] [--move id] [--yes]");let w;E?w=E:/^\d+(,\d+)*$/.test(y)?w=y.split(",").map(Number):y==="all"?w=_.issues.filter(P=>P.fix).map(P=>P.id):w=_.issues.filter(P=>P.fix&&(P.code===y||P.check===y)).map(P=>P.id);const L=d.mergeInto,b={removeFrom:d.removeFrom,mergeInto:L==="longest"?"longest-boundary":L,moveFeatureId:d.moveFeatureId};return h.payload=await a(w,b,!d.yes&&!E,f),h}case"show":return t.showIssues(),f.print('Issues are shown in the "Topology errors" layer group.',"success"),h;case"hide":return t.hideIssues(),f.print("Topology issue layers removed.","success"),h;case"clear":return t.clear(),f.print("Topology reports cleared.","success"),h}throw new Error(`Unknown topology action. Usage: ${l.usage}`)}};return[l]}const ph=["string","number","boolean","date"],Ag=["intersects","within","contains","disjoint","touches","crosses","within-distance"],Fv=["new","add","remove","intersect"],$v={add:{property:"mode",value:"add"},remove:{property:"mode",value:"remove"},intersect:{property:"mode",value:"intersect"}},vS=10,Om=200,BF=6;function qF(i){const t=typeof i=="number"?Math.round(i):BF;return Math.max(0,Math.min(t,12))}function zF(i){const t=typeof i=="number"?Math.round(i):vS;if(t<1)throw new Error("--limit must be at least 1.");if(t>Om)throw new Error(`--limit is capped at ${Om} features; export the layer instead of reading it all.`);return t}function ES(i,t){const e=10**t,n=s=>typeof s=="number"?Math.round(s*e)/e:Array.isArray(s)?s.map(n):s;return i.type==="GeometryCollection"?{type:"GeometryCollection",geometries:i.geometries.map(s=>ES(s,t))}:{...i,coordinates:n(i.coordinates)}}function wS(i){return Array.isArray(i)?typeof i[0]=="number"?1:i.reduce((t,e)=>t+wS(e),0):0}function UF(i,t,e){const n=i.geometry,[s,r,o,a]=De(i),l={id:i.id,type:n.type,vertexCount:n.type==="GeometryCollection"?0:wS(n.coordinates),bbox:[Number(s.toFixed(t)),Number(r.toFixed(t)),Number(o.toFixed(t)),Number(a.toFixed(t))]};return n.type==="Polygon"||n.type==="MultiPolygon"?(l.areaSqm=Tu(i),l.lengthMeters=el(Ka(i),{units:"meters"})):(n.type==="LineString"||n.type==="MultiLineString")&&(l.lengthMeters=el(i,{units:"meters"})),e||(l.geometry=ES(n,t)),l}function Dv(i){const t=i.trim();return/^-?\d+(\.\d+)?$/.test(t)?Number(t):t.toLowerCase()==="true"?!0:t.toLowerCase()==="false"?!1:i}function Gv(i){var e;const t=[`${i.name} (${i.type})`];return i.alias&&t.push(`alias "${i.alias}"`),i.defaultValue!==void 0&&i.defaultValue!==null&&t.push(`default ${i.defaultValue}`),(e=i.allowedValues)!=null&&e.length&&t.push(`values: ${i.allowedValues.join(", ")}`),i.required&&t.push("required"),i.precision!==void 0&&t.push(`${i.precision} decimals`),i.length!==void 0&&t.push(`max ${i.length} chars`),i.min!==void 0&&t.push(`min ${i.min}`),i.max!==void 0&&t.push(`max ${i.max}`),i.readOnly&&t.push("read-only"),i.sourceName&&i.sourceName!==i.name&&t.push(`from "${i.sourceName}"`),t.join(" · ")}function YF(i,t,e=24){const n=i.map((r,o)=>Math.min(e,Math.max(r.length,...t.map(a=>(a[o]??"").length)))),s=(r,o)=>r.length>o?`${r.slice(0,o-1)}…`:r.padEnd(o);return[i.map((r,o)=>s(r,n[o])).join(" │ "),n.map(r=>"─".repeat(r)).join("─┼─"),...t.map(r=>r.map((o,a)=>s(o??"",n[a])).join(" │ "))]}function XF(i,t,e){function n(p){const _=(typeof p=="string"&&p?p:void 0)??i.getActiveLayerId();if(!_)throw new Error("No layer given and no active layer.");const E=i.getLayer(_)??i.getAllLayers().find(w=>w.name===_);if(!E)throw new Error(`Layer "${_}" not found.`);return E.id}function s(p,y,_,E){p.print(`${_.length} features selected in "${i.getLayer(y).name}" (${E}).`,_.length?"success":"output");const w=t.selectionBBox(y);w&&e&&e(w)}const r={name:"fields",aliases:["schema","field"],description:"Show or edit the attribute schema of a layer (name, type, alias, default, allowed values, limits)",usage:'fields [layer] | fields add <name> <type> [--default v] [--values a,b] [--expr "…"] | fields delete <name> | fields rename <old> <new> | fields set <name> [--alias …]',isInteractive:!1,schema:{type:"object",properties:{action:{type:"string",enum:["list","add","delete","remove","rename","set"],default:"list"},layerId:{type:"string"},name:{type:"string"},newName:{type:"string",description:"rename: the new name · add: the field type when it is not given as --type"},type:{type:"string",enum:ph},alias:{type:"string"},defaultValue:{description:"Value for features that have none"},allowedValues:{type:"array"},required:{type:"boolean"},precision:{type:"number"},length:{type:"number"},min:{type:"number"},max:{type:"number"},readOnly:{type:"boolean"},expression:{type:"string",description:"Value for a new field, e.g. round($area / 1600, 2)"}}},args:{positional:["action","name","newName"],aliases:{layer:"layerId",expr:"expression",default:"defaultValue",values:"allowedValues",readonly:"readOnly"},fallback:{action:"layerId"}},async execute(p,y){var C;const _=Vt(p);let E=_.action??"list";const w=n(_.layerId),L=_.name;let b=_.newName;const P=_.expression;E==="remove"&&(E="delete");const N={type:_.type,alias:_.alias,defaultValue:typeof _.defaultValue=="string"?Dv(_.defaultValue):_.defaultValue,allowedValues:(C=_.allowedValues)==null?void 0:C.map(T=>typeof T=="string"?Dv(T):T),required:_.required,precision:_.precision,length:_.length,min:_.min,max:_.max,readOnly:_.readOnly};if(Object.keys(N).forEach(T=>N[T]===void 0&&delete N[T]),E==="add"&&!N.type&&b){const T=b.toLowerCase();if(!ph.includes(T))throw new Error(`Field type must be one of ${ph.join(", ")} (got "${b}")`);N.type=T,b=void 0}const S=i.getLayer(w).name;switch(E){case"add":{if(!L)throw new Error('Usage: fields add <name> <string|number|boolean|date> [--default v] [--expr "…"]');const T=t.addField(w,{name:L,type:N.type??"string",...N},{expression:P});return y.print(`Added field "${T.field}" to "${S}" (${T.updated} features filled${T.skipped?`, ${T.skipped} skipped`:""}).`,"success"),p.payload=T,p}case"delete":{if(!L)throw new Error("Usage: fields delete <name>");const T=t.deleteField(w,L);return y.print(`Deleted field "${L}" from "${S}" (${T} features changed). Undo to restore.`,"success"),p.payload=T,p}case"rename":{if(!L||!b)throw new Error("Usage: fields rename <old> <new>");const T=t.renameField(w,L,b);return y.print(`Renamed "${L}" to "${b}" in "${S}" (${T} features changed).`,"success"),p.payload=T,p}case"set":{if(!L)throw new Error("Usage: fields set <name> [--alias x] [--default v] [--values a,b] [--required] [--precision 2]");const T=t.updateField(w,L,N);return y.print(`${Gv(T)}`,"success"),p.payload=T,p}default:{const T=t.getSchema(w);y.print(`"${S}" has ${T.length} fields:`,"output"),T.forEach(M=>y.print(` ${Gv(M)}`,"output"));const I=t.undeclaredFields(w);return I.length&&y.print(` (found in the data only: ${I.join(", ")})`,"output"),p.payload=T,p}}}},o={name:"table",aliases:["attributes","attr"],description:"Show the attribute table of a layer (filter, sort, selected only)",usage:'table [layer] [--filter "area > 1600"] [--fields a,b] [--sort field] [--desc] [--limit 20] [--offset 0] [--selected]',isInteractive:!1,schema:{type:"object",properties:{layerId:{type:"string"},filter:{type:"string",description:"Expression, e.g. crop = 'ข้าว' AND $area > 1600"},fields:{type:"array",items:{type:"string"}},sortBy:{type:"string"},sortDescending:{type:"boolean"},limit:{type:"number",default:20},offset:{type:"number"},onlySelected:{type:"boolean"}}},args:{positional:["layerId"],aliases:{layer:"layerId",sort:"sortBy",desc:"sortDescending",selected:"onlySelected"}},async execute(p,y){const _=Vt(p),E=n(_.layerId),w=_.fields,L={filter:_.filter,sortBy:_.sortBy,sortDescending:!!_.sortDescending,limit:_.limit??20,offset:_.offset,onlySelected:!!_.onlySelected},b=t.query(E,L),P=w?b.fields.filter(C=>w.includes(C.name)):b.fields;if(w){const C=w.filter(T=>!b.fields.some(I=>I.name===T));if(C.length)throw new Error(`Unknown field(s): ${C.join(", ")}`)}const N=["id",...P.map(C=>C.alias??C.name)],S=b.rows.map(C=>[String(C.featureId),...P.map(T=>z0(T,C.values[T.name]))]);return y.print(`"${i.getLayer(E).name}": showing ${b.rows.length} of ${b.filtered}${b.filtered!==b.total?` (filtered from ${b.total})`:""} features`,"output"),YF(N,S).forEach(C=>y.print(C,"output")),p.payload=b,p}},a={name:"calc",aliases:["calculate","fieldcalc"],description:"Field calculator: write an expression into a field for all or the selected features",usage:"calc <field> = <expression> [--layer L] [--selected] [--create] [--type number] [--skip-errors] · calc functions",isInteractive:!1,schema:{type:"object",properties:{layerId:{type:"string"},field:{type:"string"},expression:{type:"string",description:"e.g. round($area / 1600, 2) · rai_ngan_wa() · upper(owner)"},onlySelected:{type:"boolean"},createField:{type:"boolean"},type:{type:"string",enum:ph},skipErrors:{type:"boolean"}},required:["field","expression"]},args:{positional:["field","expression"],rest:"expression",aliases:{layer:"layerId",selected:"onlySelected",create:"createField"}},async execute(p,y){const _=Vt(p),E=_.field;if(E&&!_.expression&&/^(functions|help|list)$/i.test(E))return y.print(`Variables: ${hd().join(", ")}`,"output"),If().forEach(S=>y.print(` ${S.help}`,"output")),p.payload=If(),p;const w=n(_.layerId),L=String(_.expression??"").replace(/^\s*=\s*/,"").trim();if(!E||!L)throw new Error(`Usage: ${a.usage}`);const b=_.type,P={onlySelected:!!_.onlySelected,skipErrors:!!_.skipErrors,createField:_.createField||b?b?{name:E,type:b}:!0:void 0},N=t.calculateField(w,E,L,P);return y.print(`"${N.field}" updated for ${N.updated} features in "${i.getLayer(w).name}"${N.skipped?`, ${N.skipped} skipped`:""}. Undo to revert.`,"success"),N.errors.slice(0,5).forEach(S=>y.print(` ⚠ feature ${S.featureId}: ${S.message}`,"output")),p.payload=N,p}},l={name:"select",aliases:["query","selectattr"],description:"Select features by an attribute expression",usage:`select <expression> [--layer L] [--add|--remove|--intersect] e.g. select "crop = 'ข้าว' AND $area > 1600"`,isInteractive:!1,schema:{type:"object",properties:{layerId:{type:"string"},expression:{type:"string"},mode:{type:"string",enum:Fv,default:"new"}},required:["expression"]},args:{positional:["expression"],rest:"expression",aliases:{layer:"layerId"},switches:$v},async execute(p,y){const _=Vt(p),E=n(_.layerId),w=String(_.expression??"").trim(),L=_.mode??"new";if(!w)throw new Error(`Usage: ${l.usage}`);const b=t.selectByExpression(E,w,L);return s(y,E,b,w),p.payload=b,p}},h={name:"selectloc",aliases:["select_location","selectby"],description:"Select features by their spatial relation to another layer",usage:"selectloc <intersects|within|contains|disjoint|touches|crosses|within-distance> <reference layer> [--layer L] [--distance 50] [--selected-ref] [--add|--remove]",isInteractive:!1,schema:{type:"object",properties:{layerId:{type:"string"},predicate:{type:"string",enum:Ag},referenceLayerId:{type:"string"},distanceMeters:{type:"number"},onlySelectedReference:{type:"boolean"},mode:{type:"string",enum:Fv,default:"new"}},required:["predicate","referenceLayerId"]},args:{positional:["predicate","referenceLayerId"],aliases:{layer:"layerId",distance:"distanceMeters","selected-ref":"onlySelectedReference"},switches:$v},async execute(p,y){var C;const _=Vt(p),E=(C=_.predicate)==null?void 0:C.toLowerCase();if(!_.referenceLayerId)throw new Error(`Usage: ${h.usage}`);const w=n(_.referenceLayerId),L=n(_.layerId),b=_.distanceMeters,P=!!_.onlySelectedReference,N=_.mode??"new";if(!Ag.includes(E))throw new Error(`Predicate must be one of ${Ag.join(", ")}`);if(L===w)throw new Error("Choose a different reference layer than the layer being selected");const S=t.selectByLocation(L,E,w,{distanceMeters:b,onlySelectedReference:P,mode:N});return s(y,L,S,`${E} ${i.getLayer(w).name}`),p.payload=S,p}},f={name:"stats",aliases:["statistics","summary"],description:"Statistics of a field (count, sum, mean, median, min/max, distinct values)",usage:"stats <field> [--layer L] [--selected]",isInteractive:!1,schema:{type:"object",properties:{layerId:{type:"string"},field:{type:"string"},onlySelected:{type:"boolean"}},required:["field"]},args:{positional:["field"],aliases:{layer:"layerId",selected:"onlySelected"}},async execute(p,y){var N;const _=Vt(p),E=_.field,w=n(_.layerId),L=!!_.onlySelected;if(!E)throw new Error(`Usage: ${f.usage}`);const b=t.statistics(w,E,{onlySelected:L}),P=`"${E}" (${b.type}) in "${i.getLayer(w).name}"${L?" [selected only]":""}: ${b.count} values, ${b.nullCount} empty`;return y.print(P,"output"),b.type==="number"&&b.sum!==void 0?y.print(` min ${b.min} · max ${b.max} · sum ${b.sum} · mean ${b.mean.toFixed(3)} · median ${b.median} · sd ${b.stdDev.toFixed(3)} · distinct ${b.distinct}`,"output"):(y.print(` distinct ${b.distinct}`,"output"),(N=b.topValues)==null||N.forEach(S=>y.print(` ${S.value}: ${S.count}`,"output"))),p.payload=b,p}},d={name:"geometry",aliases:["geom","shape"],description:"Read the geometry of features as GeoJSON, with area, length and bounding box in meters",usage:"geometry [layer] [--id F] [--selected] [--limit 10] [--precision 6] [--bbox-only]",isInteractive:!1,schema:{type:"object",properties:{layerId:{type:"string"},featureId:{type:"string",description:"A single feature; without it the first features of the layer are read"},onlySelected:{type:"boolean"},limit:{type:"number",description:`How many features to read (default ${vS}, max ${Om})`},precision:{type:"number",description:"Decimal places for coordinates (default 6, about 0.1 m)"},bboxOnly:{type:"boolean",description:"Only measurements and bounding boxes, no coordinates"}}},args:{positional:["layerId"],aliases:{layer:"layerId",id:"featureId",selected:"onlySelected","bbox-only":"bboxOnly"},flags:["onlySelected","bboxOnly"]},async execute(p,y){const _=Vt(p),E=n(_.layerId),w=i.getLayer(E),L=qF(_.precision),b=!!_.bboxOnly;let P=w.getFeatures();if(_.featureId!==void 0){const M=String(_.featureId);if(P=P.filter(R=>String(R.id)===M),P.length===0)throw new Error(`Feature "${M}" not found in "${w.name}".`)}else if(_.onlySelected){const M=new Set(i.getSelectedFeatureIds(E).map(R=>String(R)));if(M.size===0)throw new Error(`Nothing is selected in "${w.name}".`);P=P.filter(R=>M.has(String(R.id)))}const N=P.length,S=zF(_.limit),C=P.slice(0,S),T=C.map(M=>UF(M,L,b)),I=w.getBoundingBox();return y.print(`"${w.name}" (${w.type}) — reading ${C.length} of ${N} features · layer bbox [${I.map(M=>M.toFixed(L)).join(", ")}]`,"output"),T.forEach(M=>{const R=[M.areaSqm!==void 0?`area ${M.areaSqm.toFixed(2)} m²`:"",M.lengthMeters!==void 0?`length ${M.lengthMeters.toFixed(2)} m`:"",`${M.vertexCount} vertices`].filter(Boolean).join(" · ");y.print(` [${M.id}] ${M.type} — ${R}`,"output"),b||y.print(` ${JSON.stringify(M.geometry)}`,"output")}),N>C.length&&y.print(` … ${N-C.length} more; raise --limit or narrow with --id / --selected.`,"output"),p.payload={layerId:E,layerName:w.name,layerType:w.type,featureCount:N,bbox:I,features:T},p}};return[r,o,a,l,h,f,d]}const Og=["distance","area","angle","feature"],jF=["center","left","right","top","bottom","top-left","top-right","bottom-left","bottom-right"];function VF(i,t,e){function n(l,h){const f=ac(h,t.inputFrame);return f.segments.forEach((d,p)=>l.print(` ${p+1}. ${cs(d.meters)} · ${_a(d.angleDeg)} (${t.inputFrame.convention})`,"output")),l.print(`Total ${cs(f.totalMeters)}${f.segments.length>1?` · straight ${cs(f.closingMeters)}`:""}`,"success"),f}function s(l,h){const f=fS(h);return l.print(`Area ${Bh(f.areaSqm)}`,"success"),l.print(`Perimeter ${cs(f.perimeterMeters)} · ${h.length} points`,"output"),f}function r(l,h){const f=dS(h[0],h[1],h[2],t.inputFrame);return l.print(`Angle ${_a(f.degrees)} (${f.degrees.toFixed(4)}°)`,"success"),l.print(` leg 1 ${cs(f.firstMeters)} at ${_a(f.firstAngleDeg)} · leg 2 ${cs(f.secondMeters)} at ${_a(f.secondAngleDeg)}`,"output"),f}const o={name:"measure",aliases:["dist","mea"],description:"Measure distance, area or angle on the map (ground distances, area also in rai-ngan-wa)",usage:"measure [distance|area|angle|feature] [lng,lat lng,lat …]",isInteractive:!0,schema:{type:"object",properties:{mode:{type:"string",enum:Og,default:"distance"},coordinates:{type:"array",items:{},description:"[[lng, lat], …] — on the command line: lng,lat lng,lat …"}}},args:{positional:["coordinates"],rest:"coordinates"},async execute(l,h){const f=Vt(l),d=[...f.coordinates??[]];let p=f.mode??"distance";if(typeof d[0]=="string"&&!/^[-+.\d]/.test(d[0])){const w=String(d.shift()).toLowerCase();if(!Og.includes(w))throw new Error(`Measure mode must be one of ${Og.join(", ")} (got "${w}")`);p=w}let y=d.map(gd);if(p==="feature"){const w=qa(i,t);if(!w)throw new Error("Select the features to measure first");let L=0,b=0;return w.featureIds.forEach(P=>{const N=i.getFeature(w.layerId,P);if(!N)return;const S=gS(N,t.inputFrame);S.area?(L+=S.area.areaSqm,h.print(`[${P}] ${Bh(S.area.areaSqm)} · perimeter ${cs(S.area.perimeterMeters)}`,"output")):S.length?(b+=S.length.totalMeters,h.print(`[${P}] ${cs(S.length.totalMeters)} (${S.length.segments.length} segments)`,"output")):h.print(`[${P}] point — nothing to measure`,"output")}),w.featureIds.length>1&&(L>0&&h.print(`Total area ${Bh(L)}`,"success"),b>0&&h.print(`Total length ${cs(b)}`,"success")),l.payload={areaSqm:L,lengthMeters:b},l}const _=p==="distance"?2:3;if(y.length===0){const w=p==="angle"?["Specify the first point:","Specify the corner point:","Specify the second point:"]:["Specify the first point:",`Specify the next point${p==="area"?"":" [Enter to finish]"}:`],L=[];for(;;){const b=p==="angle"?w[L.length]:L.length===0?w[0]:w[1],P=await h.requestPoint(b);if(!P)break;if(L.push(P),L.length>=2&&p!=="angle"){const N=ac(L.slice(-2),t.inputFrame).segments[0];h.print(` +${cs(N.meters)} at ${_a(N.angleDeg)}`,"output")}if(p==="angle"&&L.length>=3)break}if(y=L,y.length<_)return h.print("Measurement cancelled.","output"),l}if(y.length<_)throw new Error(`${p} needs at least ${_} points`);const E=p==="area"?{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[...y,y[0]]]}}:{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:y}};return t.flashFeatures(E,2500),l.payload=p==="area"?s(h,y):p==="angle"?r(h,y):n(h,y),l}},a={name:"label",aliases:["labels","annotate"],description:"Draw labels for a layer from a field or an expression",usage:'label [layer] <field> [--size 12] [--color #111] [--halo #fff] [--offset 0,1] [--placement line] [--decimals 2] [--min-zoom 12] [--overlap] · label [layer] --expr "…" · label [layer] off',isInteractive:!1,schema:{type:"object",properties:{action:{type:"string",enum:["set","off","show"],default:"set",description:"set the labels, remove them (off) or report them (show)"},layerId:{type:"string"},field:{type:"string"},expression:{type:"string",description:"Attribute expression, e.g. concat(owner, ' ', rai_ngan_wa())"},enabled:{type:"boolean",description:'false removes the labels, the same as action "off"'},size:{type:"number"},color:{type:"string"},haloColor:{type:"string"},haloWidth:{type:"number"},decimals:{type:"number"},offset:{type:"array",items:{type:"number"}},anchor:{type:"string",enum:jF},placement:{type:"string",enum:["point","line"]},allowOverlap:{type:"boolean"},minZoom:{type:"number"},maxZoom:{type:"number"},transform:{type:"string",enum:["none","uppercase","lowercase"]},font:{type:"array",items:{type:"string"}},priorityField:{type:"string"},opacity:{type:"number"}}},args:{positional:["layerId","field"],aliases:{layer:"layerId",expr:"expression",halo:"haloColor",priority:"priorityField",overlap:"allowOverlap"},switches:{off:{property:"action",value:"off"},show:{property:"action",value:"show"}}},async execute(l,h){const f=Vt(l),d=T=>{const M=(typeof T=="string"&&T?T:void 0)??i.getActiveLayerId();if(!M)throw new Error("No layer given and no active layer.");const R=i.getLayer(M)??i.getAllLayers().find(A=>A.name===M);if(!R)throw new Error(`Layer "${M}" not found.`);return R.id};let p=f.enabled===!1?"off":f.action??"set";const y=[f.layerId,f.field].filter(T=>typeof T=="string"&&T!==""),_=[];y.forEach(T=>{const I=T.toLowerCase();I==="off"?p="off":I==="show"?p="show":_.push(T)});const E=T=>!!(i.getLayer(T)||i.getAllLayers().find(I=>I.name===T));let w,L=f.field;_.length>=2?(w=d(_[0]),L=_[1]):_.length===1?E(_[0])&&(f.expression||p!=="set")?(w=d(_[0]),L=void 0):(w=d(void 0),L=_[0]):(w=d(void 0),L=void 0);const b=f.offset;if(b&&(b.length!==2||b.some(T=>!Number.isFinite(T))))throw new Error("--offset needs two numbers, e.g. --offset 0,1");const P={field:p==="set"?L:void 0,expression:f.expression,size:f.size,color:f.color,haloColor:f.haloColor,haloWidth:f.haloWidth,opacity:f.opacity,decimals:f.decimals,offset:b,anchor:f.anchor,placement:f.placement,allowOverlap:f.allowOverlap,minZoom:f.minZoom,maxZoom:f.maxZoom,transform:f.transform,font:f.font,priorityField:f.priorityField},N=i.getLayer(w).name;if(p==="show"){const T=e.getLabel(w);return T?h.print(`"${N}" labels: ${T.expression?`expression ${T.expression}`:`field ${T.field}`} · size ${T.size??12}${T.enabled===!1?" (off)":""}`,"output"):h.print(`"${N}" has no labels.`,"output"),l.payload=T??null,l}if(p==="off")return e.setLabel(w,null),h.print(`Labels removed from "${N}".`,"success"),l.payload=null,l;const S=Object.fromEntries(Object.entries(P).filter(([,T])=>T!==void 0));if(!S.field&&!S.expression&&!e.getLabel(w))throw new Error(`Give a field or an expression: ${a.usage}`);if(S.field){const T=i.getLayer(w).getPropertyFields().map(I=>I.name);if(T.length&&!T.includes(S.field))throw new Error(`Field "${S.field}" not found in "${N}" (fields: ${T.join(", ")})`)}S.enabled=!0,e.setLabel(w,S);const C=e.getLabel(w);return h.print(`Labels on "${N}": ${C.expression?C.expression:C.field} (size ${C.size??12}).`,"success"),l.payload=C,l}};return[o,a]}const HF=["record","stop","cancel","list","show","play","delete","export","import"];function WF(i,t){return[{name:"macro",aliases:["script"],description:"Record a series of commands and play them back",usage:"macro record <name> | stop | cancel | list | show <name> | play <name> [--times 2] | delete <name> | export | import <json> [--replace]",isInteractive:!0,schema:{type:"object",properties:{action:{type:"string",enum:HF,default:"list"},name:{type:"string",description:"Macro name"},times:{type:"integer",minimum:1,default:1,description:"How often to play the macro"},json:{type:"string",description:"Macros as JSON (for import)"},replace:{type:"boolean",description:"Import replaces the existing macros"}}},args:{positional:["action","name"],rest:"name"},async execute(n,s){const r=Vt(n),o=r.action??"list",a=r.name??"";switch(o){case"record":return t.startRecording(a),s.print(`Recording "${a}". Run the commands, then "macro stop".`,"success"),n;case"stop":{const l=t.stopRecording();return l?s.print(`Saved "${l.name}" with ${l.commands.length} commands.`,"success"):s.print("Nothing was recorded; the macro was not saved.","output"),n.payload=l,n}case"cancel":return t.cancelRecording(),s.print("Recording cancelled.","output"),n;case"show":{const l=t.get(a);if(!l)throw new Error(`Macro "${a}" not found`);return s.print(`${l.name} (${l.commands.length} commands):`,"output"),l.commands.forEach((h,f)=>s.print(` ${f+1}. ${h}`,"output")),n.payload=l,n}case"play":{const l=t.get(a);if(!l){const f=t.list().map(d=>d.name);throw new Error(`Macro "${a}" not found${f.length?` (have: ${f.join(", ")})`:""}`)}const h=Number(r.times??1);s.print(`Playing "${l.name}" (${l.commands.length} commands${h>1?` × ${h}`:""})…`,"output");for(let f=0;f<h;f++)await i.runNested(l.commands,n);return s.print(`Finished "${l.name}".`,"success"),n}case"delete":{if(!t.remove(a))throw new Error(`Macro "${a}" not found`);return s.print(`Deleted "${a}".`,"success"),n}case"export":{const l=t.export();return s.print(JSON.stringify(l),"output"),n.payload=l,n}case"import":{const l=r.json??a;if(!l)throw new Error("Usage: macro import <json> [--replace]");let h;try{h=JSON.parse(l)}catch(d){throw new Error(`The macros could not be read: ${d instanceof Error?d.message:String(d)}`)}const f=t.import(Array.isArray(h)?h:[h],!!r.replace);return s.print(`Imported ${f} macros.`,"success"),n.payload=f,n}default:{const l=t.list();return t.isRecording()&&s.print(`Recording "${t.recordingName()}" — ${t.recordedCount()} commands so far.`,"prompt"),l.length===0?s.print('No macros yet. Use "macro record <name>".',"output"):l.forEach(h=>s.print(` ${h.name} — ${h.commands.length} commands`,"output")),n.payload=l,n}}}}]}const KF=["square","triangular"],ZF=["rows","tree"];function JF(i){function t(o,a){const h=(typeof o=="string"&&o?o:void 0)??i.getActiveLayerId();if(!h)throw new Pe(`No ${a} layer given and no active layer.`);const f=i.getLayer(h)??i.getAllLayers().find(d=>d.name===h);if(!f)throw new Pe(`Layer "${h}" not found.`);return f.id}function e(o,a){const l=i.getLayer(o);if(!a)return l.getFeatures();const h=new Set(i.getSelectedFeatureIds(o).map(f=>String(f)));if(h.size===0)throw new Pe(`Nothing is selected in "${l.name}".`);return l.getFeatures().filter(f=>h.has(String(f.id)))}function n(o,a,l){const h=typeof o=="string"&&o?o:a,f=i.getLayer(h);if(!f)return i.addLayer({id:h,name:h,type:l}),h;if(f.type!==l)throw new Pe(`Layer "${h}" holds ${f.type} features; --into needs a ${l} layer or a new name.`);return h}const s={name:"grid",aliases:["points_in_polygon"],description:"Fill a polygon with points at a regular spacing in meters, clipped to the boundary",usage:"grid <boundary> --spacing 10 [--pattern square|triangular] [--rotate 30] [--inset 2] [--into L]",isInteractive:!1,schema:{type:"object",properties:{layerId:{type:"string",description:"Polygon layer the points are placed inside"},spacingMeters:{type:"number",description:"Distance between neighbouring points, in meters"},rowSpacingMeters:{type:"number",description:"Row spacing when it differs from the column spacing (square only)"},pattern:{type:"string",enum:KF,default:"square",description:"square = rows and columns; triangular = alternate rows shifted by half a spacing, every point equidistant from six neighbours"},rotateDegrees:{type:"number",description:"Turn the pattern counter-clockwise from east"},insetMeters:{type:"number",description:"Keep points at least this far inside the boundary"},onlySelected:{type:"boolean",description:"Use only the selected polygons of the layer"},intoLayerId:{type:"string",description:"Destination point layer (created when missing)"},maxPoints:{type:"number",description:`Refuse above this many points (default ${U0})`}},required:["spacingMeters"]},args:{positional:["layerId"],aliases:{layer:"layerId",spacing:"spacingMeters","row-spacing":"rowSpacingMeters",rotate:"rotateDegrees",inset:"insetMeters",selected:"onlySelected",into:"intoLayerId",max:"maxPoints"},flags:["onlySelected"]},async execute(o,a){const l=Vt(o),h=t(l.layerId,"boundary"),f=i.getLayer(h),d=e(h,!!l.onlySelected).map(E=>E.geometry).filter(E=>E.type==="Polygon"||E.type==="MultiPolygon");if(d.length===0)throw new Pe(`"${f.name}" has no polygons to fill.`);const p=pS(d,{spacingMeters:Number(l.spacingMeters),rowSpacingMeters:l.rowSpacingMeters===void 0?void 0:Number(l.rowSpacingMeters),pattern:l.pattern??"square",rotateDegrees:l.rotateDegrees===void 0?void 0:Number(l.rotateDegrees),insetMeters:l.insetMeters===void 0?void 0:Number(l.insetMeters),maxPoints:l.maxPoints===void 0?void 0:Number(l.maxPoints)});if(p.points.length===0)throw new Pe(`A ${p.spacingMeters} m grid put no points inside "${f.name}" — the spacing is larger than the area, or the inset removed it.`);const y=n(l.intoLayerId,`${h}_grid`,"point");i.runTransaction(`Grid of ${p.points.length} points`,()=>{p.points.forEach((E,w)=>i.addFeature(y,St(E,{grid_index:w+1})))});const _=p.pattern==="triangular"?` (rows ${p.rowSpacingMeters.toFixed(2)} m apart)`:"";return a.print(`${p.points.length} points placed in "${i.getLayer(y).name}" — ${p.pattern}, ${p.spacingMeters} m spacing${_}.`,"success"),o.payload={layerId:y,...p},o}},r={name:"network",aliases:["connect"],description:"Connect points into a network from a source: runs through aligned points, joined back by a trunk",usage:"network <points> --from 100.5,13.7 [--mode rows|tree] [--angle 30] [--tolerance 1] [--into L]",isInteractive:!1,schema:{type:"object",properties:{layerId:{type:"string",description:"Point layer to connect"},source:{type:"array",description:"Where the network starts, as [lng, lat] — longitude first",items:{type:"number"}},sourceLayerId:{type:"string",description:"Take the source from the first point of this layer instead"},mode:{type:"string",enum:ZF,default:"rows",description:"rows = one line per row of aligned points plus a trunk; tree = shortest spanning tree over every point"},angleDegrees:{type:"number",description:"rows: direction of the runs, counter-clockwise from east (found from the points when absent)"},toleranceMeters:{type:"number",description:"rows: how far off a line a point may sit and still belong to it"},onlySelected:{type:"boolean"},intoLayerId:{type:"string",description:"Destination line layer (created when missing)"},maxPoints:{type:"number",description:`Refuse above this many points (default ${Y0})`}}},args:{positional:["layerId"],aliases:{layer:"layerId",from:"source","from-layer":"sourceLayerId",angle:"angleDegrees",tolerance:"toleranceMeters",selected:"onlySelected",into:"intoLayerId",max:"maxPoints"},flags:["onlySelected"]},async execute(o,a){const l=Vt(o),h=t(l.layerId,"point"),f=i.getLayer(h),d=e(h,!!l.onlySelected).filter(w=>w.geometry.type==="Point").map(w=>w.geometry.coordinates);if(d.length===0)throw new Pe(`"${f.name}" has no points to connect.`);let p;if(l.source!==void 0)p=gd(l.source);else if(l.sourceLayerId!==void 0){const w=t(l.sourceLayerId,"source"),L=i.getLayer(w).getFeatures().find(b=>b.geometry.type==="Point");if(!L)throw new Pe(`Layer "${w}" has no point to start from.`);p=L.geometry.coordinates}else throw new Pe("Give the starting point with --from <lng,lat> or --from-layer <layer>.");const y=_S(d,p,{mode:l.mode??"rows",angleDegrees:l.angleDegrees===void 0?void 0:Number(l.angleDegrees),toleranceMeters:l.toleranceMeters===void 0?void 0:Number(l.toleranceMeters),maxPoints:l.maxPoints===void 0?void 0:Number(l.maxPoints)}),_=n(l.intoLayerId,`${h}_network`,"line");i.runTransaction(`Network of ${y.lines.length} lines`,()=>{y.lines.forEach((w,L)=>i.addFeature(_,re(w.coordinates,{role:w.role,length_m:Number(w.lengthMeters.toFixed(3)),network_index:L+1})))});const E=y.mode==="rows"?`${y.runCount} runs at ${y.angleDegrees.toFixed(1)}° · `:"";return a.print(`${y.lines.length} lines in "${i.getLayer(_).name}" — ${E}branches ${y.branchLengthMeters.toFixed(1)} m · trunk ${y.trunkLengthMeters.toFixed(1)} m · total ${y.totalLengthMeters.toFixed(1)} m.`,"success"),o.payload={layerId:_,...y},o}};return[s,r]}class QF{constructor(t={}){Y(this,"dataSource");Y(this,"thematicEngine");Y(this,"mapAdapter");Y(this,"drawTools");Y(this,"legendTools");Y(this,"consoleWidget");Y(this,"console");Y(this,"commandEngine");Y(this,"aiBridge");Y(this,"io");Y(this,"topology");Y(this,"attributes");Y(this,"macros");Y(this,"dynamicInput",null);Y(this,"hostMap");if(this.hostMap=t.map,this.dataSource=new Bw,this.io=new g0(this.dataSource),this.thematicEngine=new Wu,this.topology=new rS(this.dataSource,this.thematicEngine),this.attributes=new uS(this.dataSource),this.mapAdapter=t.mapAdapter||new rb,this.drawTools=new jw(this.dataSource,this.mapAdapter),this.legendTools=new Hx(this.dataSource,this.thematicEngine),this.consoleWidget=t.console?null:new kI,this.console=t.console??this.consoleWidget,this.commandEngine=new yb(this.console),this.consoleWidget){const e=this.consoleWidget;e.setEngine(this.commandEngine),e.setPointProvider(this.drawTools),e.setInputInterceptor(n=>this.drawTools.submitInput(n)),e.enableTypeToFocus(()=>this.drawTools.getIsDrawing()||this.drawTools.isPickingPoint()||e.isWaitingInput())}this.macros=new AI(this.commandEngine),this.aiBridge=new $I(this.commandEngine,this.dataSource),this.registerDefaultCommands()}async init(t,e){this.hostMap?await this.mapAdapter.attach(this.hostMap):t&&await this.mapAdapter.init(t,e),this.mapAdapter.bindDataSource(this.dataSource,this.thematicEngine),this.drawTools.setupTempDrawingLayer()}enableDynamicInput(t){if(!this.consoleWidget)throw new Pe("The dynamic input HUD needs the built-in console; it is not available with a custom config.console");this.disableDynamicInput();const e=t??this.mapAdapter.getRawMap().getContainer(),n=new RI(this.drawTools,this.consoleWidget);return n.mount(e),this.consoleWidget.disableTypeToFocus(),this.dynamicInput=n,n}disableDynamicInput(){if(!this.dynamicInput)return;this.dynamicInput.unmount(),this.dynamicInput=null;const t=this.consoleWidget;t==null||t.enableTypeToFocus(()=>this.drawTools.getIsDrawing()||this.drawTools.isPickingPoint()||t.isWaitingInput())}isDynamicInputEnabled(){return this.dynamicInput!==null}registerDefaultCommands(){const t=_b(this.drawTools,this.dataSource),e=vb(this.drawTools,this.dataSource),n=Eb(this.dataSource,this.drawTools),s=wb(this.mapAdapter,this.dataSource,this.legendTools,this.commandEngine.registry),r=Ib(this.dataSource,this.legendTools),o=PI(this.dataSource,this.io,p=>{const y=p.map(_=>this.dataSource.getBoundingBox(_)).filter(_=>_[0]!==0||_[2]!==0);y.length===0||!this.mapAdapter.isReady||this.mapAdapter.fitBounds([Math.min(...y.map(_=>_[0])),Math.min(...y.map(_=>_[1])),Math.max(...y.map(_=>_[2])),Math.max(...y.map(_=>_[3]))],40)}),a=GF(this.dataSource,this.topology,p=>{this.mapAdapter.isReady&&this.mapAdapter.fitBounds(p,60)}),l=XF(this.dataSource,this.attributes,p=>{this.mapAdapter.isReady&&this.mapAdapter.fitBounds(p,60)}),h=VF(this.dataSource,this.drawTools,this.legendTools),f=WF(this.commandEngine,this.macros),d=JF(this.dataSource);[...t,...e,...n,...s,...r,...o,...a,...l,...h,...f,...d].forEach(p=>{this.commandEngine.registry.register(p)})}destroy(){var t;this.disableDynamicInput(),this.drawTools.destroy(),this.legendTools.destroy(),this.mapAdapter.destroy(),(t=this.consoleWidget)==null||t.unmount()}}exports.AREA_UNITS=pm;exports.ArgumentError=Ba;exports.BUILTIN_MARKER_SHAPES=Vu;exports.BaseGLAdapter=Jp;exports.CADOperations=ue;exports.COLLINEAR_RESTORE_METERS=ZI;exports.CommandCancelledError=Su;exports.DEFAULT_COLLINEAR_TOLERANCE_METERS=rm;exports.DEFAULT_DRAW_GUIDES=Xw;exports.DEFAULT_HATCH=Da;exports.DEFAULT_INPUT_FRAME=Ur;exports.DEFAULT_MAX_GRID_POINTS=U0;exports.DEFAULT_MAX_NETWORK_POINTS=Y0;exports.DEFAULT_POLAR_TRACKING=bp;exports.DEFAULT_SYMBOL_COLOR=cd;exports.DEFAULT_TOPOLOGY_OPTIONS=Dr;exports.DuplicateFeatureIdError=zv;exports.EXPORT_FORMATS=d0;exports.EXPRESSION_FUNCTIONS=Ku;exports.ExpressionError=cn;exports.FeatureNotFoundError=$g;exports.GridTooLargeError=mS;exports.IMPORT_EXTENSIONS=SI;exports.INDIAN_1975_TOWGS84=fl;exports.INTERNAL_PROPERTY_PREFIX=B0;exports.InvalidCoordinateError=M2;exports.InvalidGeometryError=yh;exports.LABEL_PROPERTY=xf;exports.LENGTH_UNITS=ym;exports.LayerNotFoundError=Fg;exports.LegendWidget=XO;exports.MARKER_ICON_BUFFER_CSS=Hu;exports.MARKER_ICON_PIXEL_RATIO=$o;exports.MARKER_ICON_SHAPE_CSS=Ec;exports.MapEngineNotInitializedError=ua;exports.MapLibreAdapter=rb;exports.MapboxAdapter=a8;exports.NATURAL_BREAKS_MAX_SAMPLE=Ch;exports.NetworkTooLargeError=yS;exports.OFSAiBridge=$I;exports.OFSAttributeTable=LF;exports.OFSAttributeTools=uS;exports.OFSCommandEngine=yb;exports.OFSCommandRegistry=fb;exports.OFSDataSource=Bw;exports.OFSDrawTools=jw;exports.OFSDynamicInputWidget=RI;exports.OFSError=Pe;exports.OFSFileIO=g0;exports.OFSGripsEditor=qw;exports.OFSLayerData=Yf;exports.OFSLegendTools=Hx;exports.OFSMacroStore=AI;exports.OFSObject=QF;exports.OFSSymbologyPanel=VO;exports.OFSThematicEngine=Wu;exports.OFSTopologyPanel=bF;exports.OFSTopologyTools=rS;exports.OFSWebConsoleWidget=kI;exports.OrthoEngine=a4;exports.PALETTES=hm;exports.PlanarProjection=we;exports.PromptBuilder=FI;exports.SQM_PER_NGAN=Rm;exports.SQM_PER_RAI=Bf;exports.SQM_PER_SQUARE_WA=cS;exports.SnappingEngine=zu;exports.SpatialIndexHelper=Ro;exports.SqliteReader=pI;exports.SqliteWriter=yI;exports.StyleCompiler=Ux;exports.SymbolImageManager=tb;exports.TOPOLOGY_AREA_LAYER_ID=po;exports.TOPOLOGY_GROUP_ID=ya;exports.TOPOLOGY_POINT_LAYER_ID=yo;exports.TopologyCancelled=VI;exports.TransactionManager=mw;exports.TypedEventEmitter=jr;exports.addImportedLayers=NI;exports.alphaToSdf=Bx;exports.applyClassSymbol=Ph;exports.askPointOrText=Nr;exports.askRequiredPoint=Ze;exports.assertValidPolygon=Lc;exports.buildBreaks=Er;exports.buildClassIndexExpression=zx;exports.buildNetwork=_S;exports.bulgePoints=cI;exports.calculateBBox=k2;exports.categoryIndexForValue=Ix;exports.checkTopology=WI;exports.checkTopologyAsync=KI;exports.childNamed=ps;exports.childrenNamed=za;exports.classIndexForValue=Dp;exports.classLabelPrecision=Gp;exports.classifyByMethod=fm;exports.classifyEqualInterval=Sx;exports.classifyManual=Cx;exports.classifyNaturalBreaks=Nx;exports.classifyPrettyBreaks=Lx;exports.classifyQuantile=Mx;exports.classifyUniqueValues=dm;exports.coerceFieldValue=Dh;exports.coerceValue=t0;exports.colorRampGradientCss=bx;exports.compareCategoryValues=Px;exports.compileExpression=fd;exports.compileLabelLayer=jx;exports.computeClassCounts=Vx;exports.constrainToAngle=Mp;exports.coordinateProblem=qh;exports.createCadCommands=vb;exports.createDrawCommands=_b;exports.createIoCommands=PI;exports.createMapCommands=wb;exports.createSpatialCommands=Eb;exports.createSymbologyCommands=Ib;exports.crsToOgcWkt=Lb;exports.crsToPrj=Mf;exports.decodeEntities=Oh;exports.decodeRecord=gI;exports.defaultSymbolStyle=kx;exports.descendantsNamed=tI;exports.describeCommand=Ju;exports.describeTheme=Ah;exports.detectTextEncoding=l0;exports.discoverFields=Gf;exports.downloadMapImage=hb;exports.drawNorthArrow=ub;exports.drawScaleBar=lb;exports.encodeRecord=Tm;exports.encodeTis620=u0;exports.encodeVarint=hr;exports.escapeHtml=Tt;exports.escapeXml=pa;exports.euclideanDistance=C2;exports.evaluateExpression=s8;exports.expandBBox=Lo;exports.exportCsv=uI;exports.exportDxf=fI;exports.exportGeoJSON=Ob;exports.exportGeoPackage=II;exports.exportKml=iI;exports.exportKmlText=h0;exports.exportKmz=sI;exports.exportMapImage=cb;exports.exportShapefileZip=Jb;exports.fillGap=iS;exports.findField=Lr;exports.findIntersectingFeature=_m;exports.forEachPosition=Hp;exports.formatAngle=_a;exports.formatArea=Bh;exports.formatClassLabel=Bp;exports.formatCommandArgs=pb;exports.formatCoordinate=L2;exports.formatDynamicInputLabel=TI;exports.formatFieldValue=z0;exports.formatLength=cs;exports.formatRaiNganWa=Kp;exports.generateAiToolDeclarations=OI;exports.generateBezierCurve=Yv;exports.generateColors=ud;exports.generateFeatureId=lf;exports.geometryBBox=vs;exports.geometryFromWgs84=Tb;exports.geometryKind=n0;exports.geometryToWgs84=kb;exports.getColorRamp=ju;exports.getLayerSchema=aS;exports.getMarkerIcon=Yp;exports.gridPoints=pS;exports.hasProjectDatumShift=s0;exports.hashString=Dx;exports.hatchImageId=Gx;exports.haversineDistance=_o;exports.importCsv=lI;exports.importDxf=hI;exports.importFiles=MI;exports.importGeoJSON=Ab;exports.importGeoPackage=bI;exports.importKml=eI;exports.importKmlText=c0;exports.importKmz=nI;exports.importShapefileParts=Kb;exports.importShapefiles=Lm;exports.inferFieldType=oS;exports.interiorPoint=Na;exports.isDateText=q0;exports.isInlineSvg=jp;exports.isInternalProperty=xd;exports.isTruthy=Pr;exports.isValidLngLat=lc;exports.labelIsActive=Xx;exports.labelNeedsComputedText=Yx;exports.lineLength=Wp;exports.linesOf=Rr;exports.listColorRamps=$p;exports.listCrs=m8;exports.listExpressionFunctions=If;exports.listExpressionVariables=hd;exports.listMarkerIcons=Xp;exports.localName=Ml;exports.looksGeographic=y8;exports.markerImageId=qx;exports.markerShapePolygon=zp;exports.markerSvgPath=Ax;exports.measure=Qe;exports.measureAngle=dS;exports.measureArea=fS;exports.measureDistance=ac;exports.measureFeature=gS;exports.measurePolygon=Mi;exports.mergeSymbolStyle=Tx;exports.metersPerDegree=tr;exports.metersPerPixel=ob;exports.midpoint=P2;exports.minDistanceMeters=lS;exports.notifyTargetLayer=un;exports.numericFieldValues=kh;exports.offsetByPolar=Hs;exports.onMarkerIconRegistered=Ox;exports.optionName=mn;exports.optionSpellings=Qp;exports.parseCommandArgs=mb;exports.parseCoordinateArray=N2;exports.parseCoordinateInput=Sp;exports.parseCreateTable=mI;exports.parseCsv=rI;exports.parseGpkgGeometry=wI;exports.parseLngLat=Fm;exports.parseNumber=us;exports.parseWkb=f0;exports.parseWkt=oI;exports.parseXml=Qb;exports.pathsOf=oi;exports.planHatchTile=$x;exports.planScaleBar=ab;exports.pointDistance=mr;exports.pointSegmentDistance=zo;exports.polygonsOf=Hi;exports.printImportResult=CI;exports.printIssues=m0;exports.rasterizeHatch=Wx;exports.rasterizeIcon=Qx;exports.rasterizeMarker=Jx;exports.readCoordinate=gd;exports.readDbf=jb;exports.readShp=Wb;exports.registerColorRamp=TO;exports.registerCrs=d8;exports.registerMarkerIcon=GO;exports.removeDuplicateVertices=QI;exports.removeOverlap=nS;exports.renderSymbolSwatchSvg=bf;exports.reportInternalError=Qt;exports.resolveAllSelectedFeatures=La;exports.resolveBaseSymbol=Fo;exports.resolveCrs=fi;exports.resolvePrj=i0;exports.resolveTargetFeature=Fs;exports.resolveTargetFeatures=qa;exports.resolveThemeClasses=qp;exports.resolveTopologyOptions=HI;exports.resolveTransformTargets=Th;exports.restoreCollinearVertices=G0;exports.ringArea=ib;exports.ringIsCollapsed=sb;exports.ringsToPolygons=Hb;exports.runTopologyChecks=$0;exports.schemaProperties=dd;exports.setDatumShift=g8;exports.setDiagnosticHandler=zP;exports.sharedBoundaryLength=sS;exports.snapHatchDirection=Fx;exports.snapToReference=eS;exports.suggestName=Uo;exports.swappedLngLat=$m;exports.symbolPart=Rx;exports.symbolPatchFromOptions=bb;exports.textContent=ys;exports.toThaiUnits=bd;exports.toWkt=aI;exports.tokenizeArgs=l8;exports.typedArgs=Vt;exports.typedCoordinates=Rh;exports.userAngleToWorldRad=Uu;exports.userRotationToWorldRad=am;exports.utmCrsFor=Rb;exports.validateArgs=e0;exports.validateFieldName=Gh;exports.validateGeometry=vm;exports.worldRadToUserAngle=ul;exports.writeDbf=Vb;exports.writeGpkgGeometry=xI;exports.writeShapefile=Zb;exports.writeWkb=EI;
|