@zwishing/emap 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/emap.mjs CHANGED
@@ -1 +1 @@
1
- import t from"./mapshaper-vendor.mjs";function e(t,e){return e.forEach(function(e){e&&"string"!=typeof e&&!Array.isArray(e)&&Object.keys(e).forEach(function(i){if("default"!==i&&!(i in t)){var s=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,s.get?s:{enumerable:!0,get:function(){return e[i]}})}})}),Object.freeze(t)}function i(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function s(t){if(t.__esModule)return t;var e=t.default;if("function"==typeof e){var i=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};i.prototype=e.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(t).forEach(function(e){var s=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(i,e,s.get?s:{enumerable:!0,get:function(){return t[e]}})}),i}var n={exports:{}},r=s(Object.freeze({__proto__:null,default:{}}));function a(t,e){for(var i=0,s=t.length-1;s>=0;s--){var n=t[s];"."===n?t.splice(s,1):".."===n?(t.splice(s,1),i++):i&&(t.splice(s,1),i--)}if(e)for(;i--;i)t.unshift("..");return t}var o=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,h=function(t){return o.exec(t).slice(1)};function l(){for(var t="",e=!1,i=arguments.length-1;i>=-1&&!e;i--){var s=i>=0?arguments[i]:"/";if("string"!=typeof s)throw new TypeError("Arguments to path.resolve must be strings");s&&(t=s+"/"+t,e="/"===s.charAt(0))}return(e?"/":"")+(t=a(g(t.split("/"),function(t){return!!t}),!e).join("/"))||"."}function c(t){var e=u(t),i="/"===x(t,-1);return(t=a(g(t.split("/"),function(t){return!!t}),!e).join("/"))||e||(t="."),t&&i&&(t+="/"),(e?"/":"")+t}function u(t){return"/"===t.charAt(0)}function p(){return c(g(Array.prototype.slice.call(arguments,0),function(t,e){if("string"!=typeof t)throw new TypeError("Arguments to path.join must be strings");return t}).join("/"))}function _(t,e){function i(t){for(var e=0;e<t.length&&""===t[e];e++);for(var i=t.length-1;i>=0&&""===t[i];i--);return e>i?[]:t.slice(e,i-e+1)}t=l(t).substr(1),e=l(e).substr(1);for(var s=i(t.split("/")),n=i(e.split("/")),r=Math.min(s.length,n.length),a=r,o=0;o<r;o++)if(s[o]!==n[o]){a=o;break}var h=[];for(o=a;o<s.length;o++)h.push("..");return(h=h.concat(n.slice(a))).join("/")}function d(t){var e=h(t),i=e[0],s=e[1];return i||s?(s&&(s=s.substr(0,s.length-1)),i+s):"."}function f(t,e){var i=h(t)[2];return e&&i.substr(-1*e.length)===e&&(i=i.substr(0,i.length-e.length)),i}function m(t){return h(t)[3]}var y={extname:m,basename:f,dirname:d,sep:"/",delimiter:":",relative:_,join:p,isAbsolute:u,normalize:c,resolve:l};function g(t,e){if(t.filter)return t.filter(e);for(var i=[],s=0;s<t.length;s++)e(t[s],s,t)&&i.push(t[s]);return i}var v,x="b"==="ab".substr(-1)?function(t,e,i){return t.substr(e,i)}:function(t,e,i){return e<0&&(e=t.length+e),t.substr(e,i)},b=s(Object.freeze({__proto__:null,basename:f,default:y,delimiter:":",dirname:d,extname:m,isAbsolute:u,join:p,normalize:c,relative:_,resolve:l,sep:"/"}));v=n,function(){var t=Math.abs,e=Math.floor,i=Math.sin,s=Math.cos,n=Math.tan,a=Math.asin,o=Math.acos,h=Math.atan,l=Math.atan2,c=Math.sqrt,u=Math.pow,p=Math.exp,_=Math.log,d=Math.hypot,f=Math.sinh,m=Math.cosh,y=Math.min,g=Math.max,x=1/0,w=Math.PI,S=57.29577951308232,C=.017453292519943295,A=6378137,E=.0066943799901413165,M=w/4,k=w/2,I=1.5*w,D=2*w,P=2/w,T=-45,L=-47,F=1e-10,N={last_errno:0,debug_level:0,logger:null},R=["no arguments in initialization list","no options found in 'init' file","invalid init= string","projection not named","unknown projection id","effective eccentricity = 1","unknown unit conversion id","invalid boolean param argument","unknown elliptical parameter name","reciprocal flattening (1/f) = 0","|radius reference latitude| > 90","squared eccentricity < 0","major axis or radius = 0 or not given","latitude or longitude exceeded limits","invalid x or y","improperly formed DMS value","non-convergent inverse meridional dist","non-convergent inverse phi2","acos/asin: |arg| >1+1e-14","tolerance condition error","conic lat_1 = -lat_2","lat_1 >= 90","lat_1 = 0","lat_ts >= 90","no distance between control points","projection not selected to be rotated","W <= 0 or M <= 0","lsat not in 1-5 range","path not in range","h <= 0","k <= 0","lat_0 = 0 or 90 or alpha = 90","lat_1=lat_2 or lat_1=0 or lat_2=90","elliptical usage required","invalid UTM zone number","arg(s) out of range for Tcheby eval","failed to find projection to be rotated","failed to load datum shift file","both n & m must be spec'd and > 0","n <= 0, n > 1 or not specified","lat_1 or lat_2 not specified","|lat_1| == |lat_2|","lat_0 is pi/2 from mean lat","unparseable coordinate system definition","geocentric transformation missing z or ellps","unknown prime meridian conversion id","illegal axis orientation combination","point not within available datum shift grids","invalid sweep axis, choose x or y","invalid value for h","point outside of projection domain"];function O(){var t=N.last_errno;t&&(t>0||!function(t){return G.indexOf(t)>-1}(t))&&U(t)}var G=[-14,-15,-17,-18,-19,-20,-27,-48];function z(t){N.last_errno=t}function q(){z(-20)}function j(){z(-20)}function B(t){U(t)}function U(t){z(t),$()}function $(t,e){var i;throw e||(e={}),e.code||(e.code=N.last_errno||0),t||(i=e.code,t=R[~i]||"unknown error"),N.last_errno=0,new V(t,e)}function V(t,e){var i=new Error(t);return i.name="ProjError",Object.keys(e).forEach(function(t){i[t]=e[t]}),i}function W(t){return H(t)*C}function H(t){var e=/(-?[0-9.]+)d?([0-9.]*)'?([0-9.]*)"?([nsew]?)$/i.exec(t),i=NaN;return e&&(i=+(e[1]||"0")+ +(e[2]||"0")/60+ +(e[3]||"0")/3600,/[ws]/i.test(e[4])&&(i=-i)),isNaN(i)&&U(-16),i}function K(t){return Z(t)}function Z(t){return parseFloat(t)}function X(t,e){var i,s,n=e[0],r=t[e.substr(1)],a=void 0!==r;return"t"==n?i=a:a?(s=r.param,r.used=!0,"i"==n?i=parseInt(s):"d"==n?i=K(s):"r"==n?i=W(s):"s"==n?i=String(s):"b"==n&&("T"==s||"t"==s||!0===s?i=!0:("F"==s||"f"==s||z(-8),i=!1))):i={i:0,b:!1,d:0,r:0,s:""}[n],void 0===i&&$("invalid request to pj_param, fatal"),i}function J(t){for(var e,i=/\+([a-z][a-z0-9_]*(?:=[^\s]*)?)/gi,s={};e=i.exec(t);)Y(s,e[1]);return s}function Y(t,e){var i,s,n=e.split("=");1==n.length?(i=e,s=!0):(i=n[0],s=e.substr(n[0].length+1)),t[i]={used:!1,param:s}}var Q={};function tt(t,e,i,s){Q[e]={init:t,name:i,description:s}}function et(t){return!t||t.is_latlong}function it(t){var e=!1,i="";return"datum"in t.params?(e=!0,i+=nt(t,"datum")):"R"in t.params?i+=nt(t,"R"):"ellps"in t.params?i+=nt(t,"ellps"):"a"in t.params?(i+=nt(t,"a"),"b"in t.params?i+=nt(t,"b"):"es"in t.params?i+=nt(t,"es"):"f"in t.params?i+=nt(t,"f"):i+=" +es="+t.es):B(-13),e||(i+=nt(t,"towgs84"),i+=nt(t,"nadgrids")),i+=nt(t,"R_A"),i+=nt(t,"R_V"),i+=nt(t,"R_a"),i+=nt(t,"R_lat_a"),i+=nt(t,"R_lat_g"),i+=nt(t,"pm")}function st(t){var e="datum,ellps,a,b,es,rf,f,towgs84,nadgrids,R,R_A,R_V,R_a,R_lat_a,R_lat_g,pm,init,no_defs".split(","),i="";return Object.keys(t.params).forEach(function(s){-1==e.indexOf(s)&&(i+=nt(t,s))}),(i+=it(t)).trim()}function nt(t,e){var i="";return e in t.params&&(i=" +"+e,!0!==t.params[e].param&&(i+="="+X(t.params,"s"+e))),i}var rt=[["WGS84","towgs84=0,0,0","WGS84","WGS_1984"],["GGRS87","towgs84=-199.87,74.79,246.62","GRS80","Greek_Geodetic_Reference_System_1987"],["NAD83","towgs84=0,0,0","GRS80","North_American_Datum_1983"],["NAD27","nadgrids=@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat","clrk66","North_American_Datum_1927"],["potsdam","towgs84=598.1,73.7,418.2,0.202,0.045,-2.455,6.7","bessel","Potsdam Rauenberg 1950 DHDN"],["carthage","towgs84=-263.0,6.0,431.0","clrk80ign","Carthage 1934 Tunisia"],["hermannskogel","towgs84=577.326,90.129,463.919,5.137,1.474,5.297,2.4232","bessel","Hermannskogel"],["ire65","towgs84=482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15","mod_airy","Ireland 1965"],["nzgd49","towgs84=59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993","intl","New Zealand Geodetic Datum 1949"],["OSGB36","towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894","airy","OSGB 1936"],[null,null,null,null]],at=[["greenwich","0dE"],["lisbon","9d07'54.862\"W"],["paris","2d20'14.025\"E"],["bogota","74d04'51.3\"W"],["madrid","3d41'16.58\"W"],["rome","12d27'8.4\"E"],["bern","7d26'22.5\"E"],["jakarta","106d48'27.79\"E"],["ferro","17d40'W"],["brussels","4d22'4.71\"E"],["stockholm","18d3'29.8\"E"],["athens","23d42'58.815\"E"],["oslo","10d43'22.5\"E"],[null,null]];function ot(t){var e=rt.reduce(function(e,i){return i[0]===t?i:e},null);return e?{id:e[0],defn:e[1],ellipse_id:e[2],name:e[3]}:null}var ht=[["MERIT","a=6378137.0","rf=298.257","MERIT 1983"],["SGS85","a=6378136.0","rf=298.257","Soviet Geodetic System 85"],["GRS80","a=6378137.0","rf=298.257222101","GRS 1980(IUGG, 1980)"],["IAU76","a=6378140.0","rf=298.257","IAU 1976"],["airy","a=6377563.396","b=6356256.910","Airy 1830"],["APL4.9","a=6378137.0","rf=298.25","Appl. Physics. 1965"],["NWL9D","a=6378145.0","rf=298.25","Naval Weapons Lab., 1965"],["mod_airy","a=6377340.189","b=6356034.446","Modified Airy"],["andrae","a=6377104.43","rf=300.0","Andrae 1876 (Den., Iclnd.)"],["aust_SA","a=6378160.0","rf=298.25","Australian Natl & S. Amer. 1969"],["GRS67","a=6378160.0","rf=298.2471674270","GRS 67(IUGG 1967)"],["bessel","a=6377397.155","rf=299.1528128","Bessel 1841"],["bess_nam","a=6377483.865","rf=299.1528128","Bessel 1841 (Namibia)"],["clrk66","a=6378206.4","b=6356583.8","Clarke 1866"],["clrk80","a=6378249.145","rf=293.4663","Clarke 1880 mod."],["clrk80ign","a=6378249.2","rf=293.4660212936269","Clarke 1880 (IGN)."],["CPM","a=6375738.7","rf=334.29","Comm. des Poids et Mesures 1799"],["delmbr","a=6376428","rf=311.5","Delambre 1810 (Belgium)"],["engelis","a=6378136.05","rf=298.2566","Engelis 1985"],["evrst30","a=6377276.345","rf=300.8017","Everest 1830"],["evrst48","a=6377304.063","rf=300.8017","Everest 1948"],["evrst56","a=6377301.243","rf=300.8017","Everest 1956"],["evrst69","a=6377295.664","rf=300.8017","Everest 1969"],["evrstSS","a=6377298.556","rf=300.8017","Everest (Sabah & Sarawak)"],["fschr60","a=6378166","rf=298.3","Fischer (Mercury Datum) 1960"],["fschr60m","a=6378155","rf=298.3","Modified Fischer 1960"],["fschr68","a=6378150","rf=298.3","Fischer 1968"],["helmert","a=6378200","rf=298.3","Helmert 1906"],["hough","a=6378270.0","rf=297","Hough"],["intl","a=6378388.0","rf=297","International 1909 (Hayford)"],["krass","a=6378245.0","rf=298.3","Krasovsky 1940"],["kaula","a=6378163","rf=298.24","Kaula 1961"],["lerch","a=6378139","rf=298.257","Lerch 1979"],["mprts","a=6397300","rf=191","Maupertius 1738"],["new_intl","a=6378157.5","b=6356772.2","New International 1967"],["plessis","a=6376523","b=6355863","Plessis 1817 (France)"],["SEasia","a=6378155.0","b=6356773.3205","Southeast Asia"],["walbeck","a=6376896.0","b=6355834.8467","Walbeck"],["WGS60","a=6378165.0","rf=298.3","WGS 60"],["WGS66","a=6378145.0","rf=298.25","WGS 66"],["WGS72","a=6378135.0","rf=298.26","WGS 72"],["WGS84","a=6378137.0","rf=298.257223563","WGS 84"],["sphere","a=6370997.0","b=6370997.0","Normal Sphere (r=6370997)"],[null,null,null,null]];function lt(t){var e=ht.reduce(function(e,i){return i[0]===t?i:e},null);return e?{id:e[0],major:e[1],ell:e[2],name:e[3]}:null}var ct=[["km","1000","Kilometer"],["m","1","Meter"],["dm","1/10","Decimeter"],["cm","1/100","Centimeter"],["mm","1/1000","Millimeter"],["kmi","1852.0","International Nautical Mile"],["in","0.0254","International Inch"],["ft","0.3048","International Foot"],["yd","0.9144","International Yard"],["mi","1609.344","International Statute Mile"],["fath","1.8288","International Fathom"],["ch","20.1168","International Chain"],["link","0.201168","International Link"],["us-in","1/39.37","U.S. Surveyor's Inch"],["us-ft","0.304800609601219","U.S. Surveyor's Foot"],["us-yd","0.914401828803658","U.S. Surveyor's Yard"],["us-ch","20.11684023368047","U.S. Surveyor's Chain"],["us-mi","1609.347218694437","U.S. Surveyor's Statute Mile"],["ind-yd","0.91439523","Indian Yard"],["ind-ft","0.30479841","Indian Foot"],["ind-ch","20.11669506","Indian Chain"],[null,null,null]];function ut(t){var e=ct.reduce(function(e,i){return t===i[0]?i:e},null);return e?{id:e[0],to_meter:e[1],name:e[2]}:null}var pt={},_t={};function dt(t){return _t[t]||null}function ft(t){var e,i,s,n,a,o,h,l,c=t.split(":"),u=c[0],p=c[1];return p&&u||B(-3),(e=dt(u=u.toLowerCase()))||(i=u,n=r,o=(a=b).join(a.dirname("/Users/zhang/code/emap/node_modules/mproj/dist"),"../nad"),h=a.join(o,i.toUpperCase()),l=a.join(o,i.toLowerCase()),n.existsSync(h)?s=n.readFileSync(h,"utf8"):n.existsSync(l)?s=n.readFileSync(l,"utf8"):$("unable to read from 'init' file named "+i),e=s,_t[u]=e),e?function(t,e){var i,s,n="",r="";return(i=t.indexOf("<"+e+">"))>-1&&((s=t.lastIndexOf("#",i))>-1&&(r=t.substring(s+1,i).trim(),/\n/.test(r)&&(r="")),n=(n=(n=" "+(n=(n=(n=(n=(n=t.substr(i+e.length+2)).substr(0,n.indexOf("<"))).replace(/#.*/g,"")).replace(/[\s]+/g," ")).replace(/\+title=[^+]*[^ +]/g,function(t){return t.replace(/ /g,"\t")}))).replace(/ (?=[a-z])/gi," +")).replace(/\t/g," ").trim()),n?{opts:n,comment:r}:null}(e,p):null}function mt(e){var s,n,r=J(e),a={params:r,is_latlong:!1,is_geocent:!1,is_long_wrap_set:!1,long_wrap_center:0,axis:"enu",gridlist:null,gridlist_count:0,vgridlist_geoid:null,vgridlist_geoid_count:0};return Object.keys(r).length||B(-1),X(r,"tinit")&&function(t,e){var i=pt[e.toLowerCase()]||null;i||function(t,e){pt[t.toLowerCase()]=e}(e,i=ft(e)),i||B(-2),yt(t,i.opts)}(r,X(r,"sinit")),(s=X(r,"sproj"))||B(-4),(n=Q[s])||B(-5),X(r,"bno_defs")||function(t){yt(t,"+ellps=WGS84")}(a.params),function(t){var e,i,s,n,r=484813681109536e-20,a=t.datum_params=[0,0,0,0,0,0,0];t.datum_type=0,(e=X(t.params,"sdatum"))&&((i=ot(e))||B(-9),i.ellipse_id&&Y(t.params,"ellps="+i.ellipse_id),i.defn&&Y(t.params,i.defn)),(s=X(t.params,"snadgrids"))&&"@null"!=s&&$("+nadgrids is not implemented"),X(t.params,"scatalog")&&$("+catalog is not implemented"),(n=X(t.params,"stowgs84"))&&(n.split(",").forEach(function(t,e){a[e]=K(t)||0}),0!=a[3]||0!=a[4]||0!=a[5]||0!=a[6]?(t.datum_type=2,a[3]*=r,a[4]*=r,a[5]*=r,a[6]=a[6]/1e6+1):t.datum_type=1)}(a),function(e){var s,n,r,a,o,h=.16666666666666666,l=e.params,u=0,p=0;X(l,"tR")?u=X(l,"dR"):((s=X(l,"sellps"))&&((n=lt(s))||B(-9),Y(l,n.major),Y(l,n.ell)),u=X(l,"da"),X(l,"tes")?p=X(l,"des"):X(l,"te")?p=(r=X(l,"de"))*r:X(l,"trf")?((r=X(l,"drf"))||B(-10),p=(r=1/r)*(2-r)):X(l,"tf")?p=(r=X(l,"df"))*(2-r):X(l,"tb")&&(p=1-(a=X(l,"db"))*a/(u*u)),a||(a=u*c(1-p)),X(l,"bR_A")?(u*=1-p*(h+p*(.04722222222222222+.022156084656084655*p)),p=0):X(l,"bR_V")?u*=1-p*(h+p*(.06944444444444445+.04243827160493827*p)):X(l,"bR_a")?(u=.5*(u+a),p=0):X(l,"bR_g")?(u=c(u*a),p=0):X(l,"bR_h")?(u+a===0&&B(-20),u=2*u*a/(u+a),p=0):(o=X(l,"tR_lat_a")||X(l,"tR_lat_g"))&&(r=i(X(l,o?"rR_lat_a":"rR_lat_g")),t(r)>k&&B(-11),r=1-p*r*r,u*=o?.5*(1-p+r)/(r*c(r)):c(1-p)/r,p=0)),p<0&&B(-12),u<=0&&B(-13),e.es=p,e.a=u}(a),a.a_orig=a.a,a.es_orig=a.es,a.e=c(a.es),a.ra=1/a.a,a.one_es=1-a.es,a.one_es||B(-6),a.rone_es=1/a.one_es,function(t){return 1==t.datum_type&&t.datum_params[0]==t.datum_params[1]==t.datum_params[2]===0&&6378137==t.a&&Math.abs(t.es-.00669437999)<5e-11}(a)&&(a.datum_type=4),a.geoc=!!a.es&&X(r,"bgeoc"),a.over=X(r,"bover"),a.has_geoid_vgrids=X(r,"tgeoidgrids"),a.has_geoid_vgrids&&X(r,"sgeoidgrids"),a.is_long_wrap_set=X(r,"tlon_wrap"),a.is_long_wrap_set&&(a.long_wrap_center=X(r,"rlon_wrap"),t(a.long_wrap_center)<10*D==0&&B(-14)),X(r,"saxis")&&function(t){var e="ewnsud",i=X(t.params,"saxis");3!=i.length&&B(L),-1!=e.indexOf(i[0])&&-1!=e.indexOf(i[1])&&-1!=e.indexOf(i[2])||B(L),t.axis=i}(a),a.lam0=X(r,"rlon_0"),a.phi0=X(r,"rlat_0"),a.x0=X(r,"dx_0"),a.y0=X(r,"dy_0"),X(r,"tk_0")?a.k0=X(r,"dk_0"):X(r,"tk")?a.k0=X(r,"dk"):a.k0=1,a.k0<=0&&B(-31),function(t){var e,i,s,n=t.params;(e=X(n,"sunits"))&&((s=ut(e))||B(-7),i=s.to_meter),i||(i=X(n,"sto_meter"))?(t.to_meter=gt(i),t.fr_meter=1/t.to_meter):t.to_meter=t.fr_meter=1,i=null,(e=X(n,"svunits"))&&((s=ut(e))||B(-7),i=s.to_meter),i||X(n,"svto_meter")?(t.vto_meter=gt(i),t.vfr_meter=1/t.vto_meter):(t.vto_meter=t.to_meter,t.vfr_meter=t.fr_meter)}(a),function(t){var e,i,s,n=t.params;(e=X(n,"spm"))?(i=function(t){var e=at.reduce(function(e,i){return i[0]===t?i:e},null);return e?{id:e[0],definition:e[1]}:null}(e),s=W(i?i.definition:e),isNaN(s)&&B(-46),t.from_greenwich=s):t.from_greenwich=0}(a),n.init(a),a}function yt(t,e){var i=J(e),s=["datum","ellps","a","b","rf","f"].reduce(function(e,i){return e||i in t},!1);Object.keys(i).forEach(function(e){e in t||"ellps"==e&&s||(t[e]=i[e])})}function gt(t){var e=t.split("/"),i=Z(e[0]);return e.length>1&&(i/=Z(e[1])),i}function vt(t,e){var i=0,s=t*t,n=e*e;return t<=0&&(i|=4),e<=0&&(i|=8),t<e&&(i|=16),i?null:{a:t,b:e,a2:s,b2:n,e2:(s-n)/s,ep2:(s-n)/n}}function xt(t,e,n,r,a){var o,h,l,u,p=0,_=n[e],d=r[e],f=a[e];return d<-k&&d>-1.001*k?d=-k:d>k&&d<1.001*k?d=k:(d<-k||d>k)&&(p|=1),p||(_>w&&(_-=2*w),h=i(d),u=s(d),l=h*h,o=t.a/c(1-t.e2*l),n[e]=(o+f)*u*s(_),r[e]=(o+f)*u*i(_),a[e]=(o*(1-t.e2)+f)*h),p}function bt(e,i,s,n,r){var a,o,u,p,_,d,f,m,y,g,v,x,b,w,S,C,A=1e-12,E=s[i],M=n[i],I=r[i];if(p=c(E*E+M*M),_=c(E*E+M*M+I*I),p/e.a<A){if(o=0,_/e.a<A)return s[i]=0,n[i]=k,r[i]=-e.b,0}else o=l(M,E);d=I/_,f=p/_,m=1/c(1-e.e2*(2-e.e2)*f*f),v=f*(1-e.e2)*m,x=d*m,C=0;do{C++,u=p*v+I*x-(y=e.a/c(1-e.e2*x*x))*(1-e.e2*x*x),g=e.e2*y/(y+u),S=(w=d*(m=1/c(1-g*(2-g)*f*f)))*v-(b=f*(1-g)*m)*x,v=b,x=w}while(S*S>1e-24&&C<30);a=h(w/t(b)),s[i]=o,n[i]=a,r[i]=u}function wt(t,e,i){var s=i.length>2,n=[i[0]],r=[i[1]],a=[s?i[2]:0];t.is_latlong&&(n[0]*=C,r[0]*=C),N.last_errno=0,St(t,e,n,r,a),(N.last_errno||n[0]==x)&&$(null,{point:i}),e.is_latlong&&(n[0]*=S,r[0]*=S),i[0]=n[0],i[1]=r[0],s&&(i[2]=a[0])}function St(t,e,i,s,n){var r,a,o=i.length,h={},l={};if("enu"!=t.axis&&Ct(t.axis,!1,i,s,n),1!=t.vto_meter&&n)for(r=0;r<o;r++)n[r]*=t.vto_meter;if(t.is_geocent){if(n||B(T),1!=t.to_meter)for(r=0;r<o;r++)i[r]!=x&&(i[r]*=t.to_meter,s[r]*=t.to_meter);At(t.a_orig,t.es_orig,i,s,n)}else if(!t.is_latlong)if(t.inv3d||t.inv||$("source projection not invertible"),t.inv3d)$("inverse 3d transformations not supported");else for(r=0;r<o;r++)l.x=i[r],l.y=s[r],a=It(l,t),i[r]=a.lam,s[r]=a.phi,O();if(0!==t.from_greenwich)for(r=0;r<o;r++)i[r]!=x&&(i[r]+=t.from_greenwich);if(t.has_geoid_vgrids&&n&&$("vgrid transformation not supported"),function(t,e,i,s,n){var r,a,o,h,l=i.length;0!=t.datum_type&&0!=e.datum_type&&(function(t,e){return t.datum_type==e.datum_type&&(!(t.a_orig!=e.a_orig||Math.abs(t.es_orig-e.es_orig)>5e-11)&&(1==t.datum_type?t.datum_params[0]==e.datum_params[0]&&t.datum_params[1]==e.datum_params[1]&&t.datum_params[2]==e.datum_params[2]:2==t.datum_type?t.datum_params[0]==e.datum_params[0]&&t.datum_params[1]==e.datum_params[1]&&t.datum_params[2]==e.datum_params[2]&&t.datum_params[3]==e.datum_params[3]&&t.datum_params[4]==e.datum_params[4]&&t.datum_params[5]==e.datum_params[5]&&t.datum_params[6]==e.datum_params[6]:3!=t.datum_type||X(t.params,"snadgrids")==X(e.params,"snadgrids")))}(t,e)||(r=t.a_orig,a=t.es_orig,o=e.a_orig,h=e.es_orig,n||(n=new Float64Array(l)),3==t.datum_type&&($("gridshift not implemented"),r=A,a=E),3==e.datum_type&&(o=A,h=E),a==h&&r==o&&1!=t.datum_type&&2!=t.datum_type&&1!=e.datum_type&&2!=e.datum_type||(Et(r,a,i,s,n),1!=t.datum_type&&2!=t.datum_type||function(t,e,i,s){var n,r,a,o,h,l,c,u,p=e.length,_=t.datum_params,d=_[0],f=_[1],m=_[2];if(1==t.datum_type)for(u=0;u<p;u++)e[u]!=x&&(e[u]+=d,i[u]+=f,s[u]+=m);else if(2==t.datum_type)for(o=_[3],h=_[4],l=_[5],c=_[6],u=0;u<p;u++)e[u]!=x&&(n=c*(e[u]-l*i[u]+h*s[u])+d,r=c*(l*e[u]+i[u]-o*s[u])+f,a=c*(-h*e[u]+o*i[u]+s[u])+m,e[u]=n,i[u]=r,s[u]=a)}(t,i,s,n),1!=e.datum_type&&2!=e.datum_type||function(t,e,i,s){var n,r,a,o,h,l,c,u,p=e.length,_=t.datum_params,d=_[0],f=_[1],m=_[2];if(1==t.datum_type)for(u=0;u<p;u++)e[u]!=x&&(e[u]-=d,i[u]-=f,s[u]-=m);else if(2==t.datum_type)for(o=_[3],h=_[4],l=_[5],c=_[6],u=0;u<p;u++)e[u]!=x&&(n=(e[u]-d)/c,r=(i[u]-f)/c,a=(s[u]-m)/c,e[u]=n+l*r-h*a,i[u]=-l*n+r+o*a,s[u]=h*n-o*r+a)}(e,i,s,n),At(o,h,i,s,n),3==e.datum_type&&pj_apply_gridshift_2(e,1,i,s,n))))}(t,e,i,s,n),e.has_geoid_vgrids&&n&&$("vgrid transformation not supported"),0!==e.from_greenwich)for(r=0;r<o;r++)i[r]!=x&&(i[r]-=e.from_greenwich);if(e.is_geocent){if(n||B(T),Et(e.a_orig,e.es_orig,i,s,n),1!=e.fr_meter)for(r=0;r<o;r++)i[r]!=x&&(i[r]*=e.fr_meter,s[r]*=e.fr_meter)}else if(e.is_latlong){if(e.is_latlong&&e.is_long_wrap_set)for(r=0;r<o;r++)if(i[r]!=x){for(;i[r]<e.long_wrap_center-w;)i[r]+=D;for(;i[r]>e.long_wrap_center+w;)i[r]-=D}}else if(e.fwd3d)$("3d transformation not supported");else for(r=0;r<o;r++)h.lam=i[r],h.phi=s[r],a=kt(h,e),i[r]=a.x,s[r]=a.y,O();if(1!=e.vto_meter&&n)for(r=0;r<o;r++)n[r]*=e.vfr_meter;return"enu"!=e.axis&&Ct(e.axis,!0,i,s,n),1==o?N.last_errno:0}function Ct(t,e,i,s,n){var r,a,o,h,l,c,u=i.length,p=0;if(e){for(o=0;o<u;o++)if(r=i[o],a=s[o],r!=x)for(n&&(p=n[o]),h=0;h<3;h++)if(2!=h||n)switch(c=0==h?i:1==h?s:n,t[h]){case"e":c[o]=r;break;case"w":c[o]=-r;break;case"n":c[o]=a;break;case"s":c[o]=-a;break;case"u":c[o]=p;break;case"d":c[o]=-p;break;default:B(L)}}else for(o=0;o<u;o++)if(r=i[o],a=s[o],r!=x)for(n&&(p=n[o]),h=0;h<3;h++)switch(l=0==h?r:1==h?a:p,t[h]){case"e":i[o]=l;break;case"w":i[o]=-l;break;case"n":s[o]=l;break;case"s":s[o]=-l;break;case"u":n&&(n[o]=l);break;case"d":n&&(n[o]=-l);break;default:B(L)}}function At(t,e,i,s,n){var r,a,o=i.length;for((a=vt(t,0==e?t:t*c(1-e)))||B(T),r=0;r<o;r++)i[r]!=x&&bt(a,r,i,s,n)}function Et(t,e,i,s,n){var r,a,o=i.length;for((a=vt(t,0===e?t:t*c(1-e)))||B(T),r=0;r<o;r++)i[r]!=x&&xt(a,r,i,s,n)&&(i[r]=s[r]=x)}function Mt(i){var s=6.283185307179586,n=3.141592653589793;return t(i)>3.14159265359&&(i+=n,i-=s*e(i/s),i-=n),i}function kt(e,i){var s={x:0,y:0},r=t(e.phi)-k;return r<=1e-12&&t(e.lam)<=10?(N.last_errno=0,t(r)<=1e-12?e.phi=e.phi<0?-k:k:i.geoc&&(e.phi=h(i.rone_es*n(e.phi))),e.lam-=i.lam0,i.over||(e.lam=Mt(e.lam)),i.fwd?(i.fwd(e,s),s.x=i.fr_meter*(i.a*s.x+i.x0),s.y=i.fr_meter*(i.a*s.y+i.y0)):s.x=s.y=x):z(-14),!N.last_errno&&isFinite(s.x)&&isFinite(s.y)||(s.x=s.y=x),s}function It(e,i){var s={lam:0,phi:0};return e.x<x&&e.y<x?(N.last_errno=0,i.inv?(e.x=(e.x*i.to_meter-i.x0)*i.ra,e.y=(e.y*i.to_meter-i.y0)*i.ra,i.inv(e,s),s.lam+=i.lam0,i.over||(s.lam=Mt(s.lam)),i.geoc&&t(t(s.phi)-k)>1e-12&&(s.phi=h(i.one_es*n(s.phi)))):s.lam=s.phi=x):z(-15),!N.last_errno&&isFinite(s.lam)&&isFinite(s.phi)||(s.lam=s.phi=x),s}function Dt(t,i,s,n){var r,a,o;for((t<0||t>=9)&&(t=3),r=1,o=0;o<t;o++)r*=10;return a=3600*r,function(o){var h,l,c,u,p="",_="",d="";return o===x||isNaN(o)?"":(o<0?(o=-o,(c=n||"")||(p="-")):c=s||"",l=(o=e(o*a+.5))/r%60,h=(o=e(o/(60*r)))%60,u=e(o/60)+"d",d=l.toFixed(t),d=(l=parseFloat(d))?(i?d:String(l))+'"':"",(l||h)&&2==(_=String(h)+"'").length&&i&&(_="0"+_),p+u+_+d+c)}}function Pt(t,e,i){var s,n,r,a,o,h;return"string"!=typeof t?Ti:("string"!=typeof e?(n="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs",r=t,s=e):(n=t,r=e,s=i),h=Tt(a=mt(n),o=mt(r)),s?h(s):{forward:h,inverse:Tt(o,a)})}function Tt(t,e){return function(i){var s=Array.isArray(i);return i=s?i.concat():[i.x,i.y],wt(t,e,i),s||(i={x:i[0],y:i[1]}),i}}function Lt(t){var e=t.proj in Q?Q[t.proj].name:"",i=st(t),s=Yt(t);return{PROJCS:{NAME:e?s.NAME+" / "+e:"unnamed",GEOGCS:s,PROJECTION:"custom_proj4",PARAMETER:[],UNIT:Wt(t),EXTENSION:["PROJ4",i+" +wktext"]}}}function Ft(t){var e=t.EXTENSION;return e&&"PROJ4"==e[0]?(e[1]||"").replace(" +wktext",""):null}Pt.WGS84="+proj=longlat +datum=WGS84",Pt.toPoint=function(t){var e={x:t[0],y:t[1]};return t.length>2&&(e.z=t[2]),t.length>3&&(e.m=t[3]),e};var Nt=[],Rt=[];function Ot(t){return"string"==typeof t}function Gt(t){var e=qt(t,Rt);return e||(e=function(t){return Ft(t)?Ft:null}(t)),e||$t("unsupported WKT definition: "+(t.NAME||"[unknown]")),e}function zt(t){var e=qt(t,Nt);return e||(e=Lt),e||$t("unsupported projection: "+function(t){return jt(t)||"[unknown]"}(t)),e}function qt(t,e){for(var i=0;i<e.length;i++)if((0,e[i][0])(t))return e[i][1];return null}function jt(t){return X(t.params,"sproj")}function Bt(t){return t.replace(/[-_ \/]+/g,"_").toLowerCase()}function Ut(t){var e;return Array.isArray(t)?e=t:t&&t.length>0&&(e=t.split(",")),e}function $t(t){throw new Error(t)}function Vt(t){return{to_meter:t.UNIT[1]}}function Wt(t){return["Meter",t.to_meter||1]}function Ht(t,e){var i,s,n=t.DATUM,r=n.SPHEROID,a=function(t){var e,i={northamerican1983:"NAD83",newzealand1949:"nzgd49"},s=Kt(t.NAME);if(s in i)return i[s];for(var n=0;n<rt.length&&Kt((e=rt[n])[3])!=s&&Kt(e[0])!=s;n++);return e?e[0]:null}(n),o=function(t){var e,i={international1924:"intl"},s=Kt(t[0]);if(s in i)return i[s];if(/^grs1980/.test(s))return"GRS80";if("sphere"==s)return null;for(var n=0;n<ht.length&&Kt((e=ht[n])[3])!=s&&Kt(e[0])!=s;n++);return e?e[0]:null}(r),h=e&&e.aux_sphere,l=r[1],c=r[2];return Zt(t.UNIT,"degree"),h?i="+a="+r[1]:a?i="+datum="+a:o?i="+ellps="+o:(i="+a="+l,c>0&&(i+=" +rf="+c)),!n.TOWGS84||h||a||(i+=" +towgs84="+n.TOWGS84.join(",")),((s=t.PRIMEM?t.PRIMEM[1]:0)>0||s<0)&&(i+=" +pm="+s),i}function Kt(t){return(t||"").replace(/^(GCS|D)_/i,"").replace(/[ _]/g,"").toLowerCase()}function Zt(t,e){t&&t[0].toLowerCase()!=e&&$t("unexpected geographic units: "+geogcs.UNIT[0])}function Xt(t){return function(){return"+proj="+t}}function Jt(t){return function(e){var i,s;return[t.PROJECTION(e),t.PARAMETER(e),t.GEOGCS?t.GEOGCS(e):Ht(e.GEOGCS),(i=Vt(e),s="",1!=i.to_meter&&(s="+to_meter="+i.to_meter),s),"+no_defs"].filter(function(t){return!!t}).join(" ")}}function Yt(t){return{NAME:ee(t),DATUM:Qt(t),PRIMEM:["Greenwich",0],UNIT:["degree",.017453292519943295]}}function Qt(t){var e={NAME:se(t),SPHEROID:te(t)},i=X(t.params,"stowgs84");return/[1-9]/.test(i)&&(e.TOWGS84=i),e}function te(t){var e;return e=X(t.params,"trf")?X(t.params,"drf"):t.es?1/(1-Math.sqrt(1-t.es)):0,[ie(t),t.a,e]}function ee(t){var e;return et(t)&&(e=he(t)),e||(e=ne(t),e=/^[a-z]+$/.test(e)?e[0].toUpperCase()+e.substr(1):e.toUpperCase()),e||"UNK"}function ie(t){var e=lt(function(t){var e=ne(t),i=e?ot(e):null;return(i?i.ellipse_id:X(t.params,"sellps"))||""}(t));return e?e.name:"Unknown ellipsoid"}function se(t){var e=ot(ne(t));return e&&e.name||"Unknown datum"}function ne(t){return X(t.params,"sdatum")}function re(t){return zt(t)(t)}function ae(t,e){return oe({PROJECTION:t,PARAMETER:Pe(e)})}function oe(t){return function(e){var i={GEOGCS:t.GEOGCS&&t.GEOGCS(e)||Yt(e),PROJECTION:Ot(t.PROJECTION)?t.PROJECTION:t.PROJECTION(e),PARAMETER:t.PARAMETER(e),UNIT:Wt(e)};return i.NAME=t.NAME&&t.NAME(e,i)||function(t,e){var i=he(t);return i||e.GEOGCS.NAME+" / "+e.PROJECTION}(e,i),{PROJCS:i}}}function he(t){var e;return X(t.params,"tinit")&&(e=ft(X(t.params,"sinit"))),e?e.comment:""}function le(t,e,i){var s=ue(e),n=function(t,e){return Jt({PROJECTION:Xt(t),PARAMETER:De(e)})}(t,i);_e(s,n)}function ce(t,e,i){de(pe(t),ae(e,i))}function ue(t){var e=Ut(t).map(Bt);return function(t){var i=t.PROJECTION[0];return e.indexOf(Bt(i))>-1}}function pe(t){return function(e){var i=jt(e);return i&&i==t}}function _e(t,e){"function"!=typeof t&&$t("Missing WKT parser test"),"function"!=typeof e&&$t("Missing WKT parse function"),Rt.push([t,e])}function de(t,e){"function"!=typeof t&&$t("Missing WKT maker test"),"function"!=typeof e&&$t("Missing WKT maker function"),Nt.push([t,e])}_e(function(t){return fe.test(Bt(t.NAME))},function(t){return Jt({PROJECTION:Xt("utm"),PARAMETER:function(t){var e=fe.exec(Bt(t.NAME)),i="+zone="+e[1];return"s"==e[2].toLowerCase()&&(i+=" +south"),i}})(t)}),_e(function(t){return me.test(Bt(t.NAME))},function(t){return Jt({PROJECTION:Xt("ups"),PARAMETER:function(t){var e=me.exec(Bt(t.NAME));return"south"==e[1].toLowerCase()?"+south":""}})(t)}),de(pe("utm"),function(t){return oe({NAME:ye,PROJECTION:function(){return"Transverse_Mercator"},PARAMETER:ve})(t)}),de(pe("ups"),function(t){return oe({NAME:ge,PROJECTION:function(){return"Polar_Stereographic"},PARAMETER:xe})(t)});var fe=/UTM_zone_([0-9]{1,2})(N|S)/i,me=/UPS_(North|South)/i;function ye(t,e){return e.GEOGCS.NAME+" / UTM zone "+X(t.params,"szone")+(X(t.params,"tsouth")?"S":"N")}function ge(t,e){return e.GEOGCS.NAME+" / UPS "+(X(t.params,"tsouth")?"South":"North")}function ve(t){return[["latitude_of_origin",0],["central_meridian",180*t.lam0/w],["scale_factor",t.k0],["false_easting",t.x0],["false_northing",t.y0]]}function xe(t){return[["latitude_of_origin",-90],["central_meridian",0],["scale_factor",.994],["false_easting",2e6],["false_northing",2e6]]}function be(t){return X(t.params,"tlat_ts")&&0!=X(t.params,"dlat_ts")}function we(t){return 0===t.es&&6378137==t.a}_e(ue("Mercator_2SP,Mercator_1SP,Mercator,Mercator_Auxiliary_Sphere"),Jt({GEOGCS:function(t){var e=function(t){return/(Web_Mercator|Pseudo_Mercator)/i.test(Bt(t.NAME))}(t)?{aux_sphere:!0}:null;return Ht(t.GEOGCS,e)},PROJECTION:Xt("merc"),PARAMETER:function(t){return De(function(t){var e=ke(t,"standard_parallel_1");return e&&0!=e[1]}(t)?"lat_ts,lat_0b":"lat_tsb,lat_ts")(t)}})),de(pe("merc"),oe({GEOGCS:function(t){return we(t)?Yt(mt("+proj=longlat +datum=WGS84")):null},PROJECTION:function(t){return be(t)?"Mercator_2SP":"Mercator_1SP"},PARAMETER:function(t){return Pe(be(t)?"lat_ts,lat_0b":"lat_tsb")(t)},NAME:function(t){return we(t)?"WGS 84 / Pseudo-Mercator":null}}));var Se=[["x_0","false_easting","m"],["y_0","false_northing","m"],["k_0","scale_factor","f"],["lat_0","latitude_of_center"],["lon_0","central_meridian"]],Ce={lat_0b:["lat_0","latitude_of_origin"],lat_0c:["lat_0",null],lat_0d:["lat_0","standard_parallel_1"],lat_1:["lat_1","standard_parallel_1"],lat_1b:["lat_1","latitude_of_point_1"],lat_1c:["lat_1","latitude_of_origin"],lat_2:["lat_2","standard_parallel_2"],lat_2b:["lat_2","latitude_of_point_2"],lat_ts:["lat_ts","standard_parallel_1"],lat_tsb:["lat_ts","latitude_of_origin"],lonc:["lonc","central_meridian"],lon_1:["lon_1","longitude_of_point_1"],lon_2:["lon_2","longitude_of_point_2"],alpha:["alpha","azimuth"],gamma:["gamma","rectified_grid_angle"],h:["h","height","f"]},Ae={longitude_of_center:"central_meridian",latitude_of_origin:"latitude_of_center",latitude_of_center:"latitude_of_origin",longitude_of_1st_point:"longitude_of_point_1",longitude_of_2nd_point:"longitude_of_point_2",latitude_of_1st_point:"latitude_of_point_1",latitude_of_2nd_point:"latitude_of_point_2",k:"k_0"};function Ee(t,e,i){for(var s=0;s<i.length;s++)if(i[s][e]===t)return i[s];return null}function Me(t,e,i){var s=null;return!(s=Ee(t=t.toLowerCase(),e,i))&&t in Ae&&(s=Ee(Ae[t],e,i)),s}function ke(t,e){for(var i,s=t.PARAMETER||[],n=0;n<s.length;n++)if(e===(i=s[n][0].toLowerCase())||e===Ae[i])return s[n];return null}function Ie(t){var e=null;return t&&(e=Ut(t).reduce(function(t,e){var i=Ce[e];return i||$t("missing parameter rule: "+e),t.push(i),t},[])),(e||[]).concat(Se)}function De(t){return function(e){var i=[],s=Ie(t),n=Vt(e);return(e.PARAMETER||[]).forEach(function(t){var e,r,a=Me(t[0],1,s);a?(e=function(t,e,i){var s=t[0];if("m"==t[2]&&(e*=i.to_meter),!("x_0,y_0,lat_0,lon_0".indexOf(s)>-1&&0===e||"k_0"==s&&1==e))return"+"+s+"="+e}(a,t[1],n),e&&i.push(e)):(r="unhandled parameter: "+t[0],console.error("[wkt] "+r))}),i.join(" ")}}function Pe(t){return function(e){var i=[],s=Ie(t);return Object.keys(e.params).forEach(function(t){var n,r=Me(t,0,s);r&&r[1]&&(n=X(e.params,"s"+t),i.push(function(t,e,i){var s,n=t[2];return s="m"==n?parseFloat(e)/i:"f"==n?parseFloat(e):H(e),[t[1],s]}(r,n,e.to_meter)))}),i}}function Te(t){return!("lat_1"in t.params&&"lat_2"in t.params)}function Le(t){return"omerc"==jt(t)&&("alpha"in t.params||"gamma"in t.params)}function Fe(t){return Le(t)&&("no_uoff"in t.params||"no_off"in t.params)}function Ne(t){return X(t.params,"tlat_ts")}function Re(t){var e=JSON.stringify(Ge(t));return e=(e=e.replace(/\["([A-Z0-9]+)",/g,"$1[")).replace(/"(EAST|NORTH|SOUTH|WEST)"/g,"$1")}function Oe(t){return"NAME,PROJCS,GEOGCS,GEOCCS,DATUM,SPHEROID,PRIMEM,PROJECTION,PARAMETER,UNIT,AXIS".indexOf(t)+1||999}function Ge(t,e){var i,s=[];return e=e||0,function(t){return Object.keys(t).sort(function(t,e){return Oe(t)-Oe(e)})}(t).forEach(function(n){var r=t[n];!function(t){return!!t&&"object"==typeof t&&!Array.isArray(t)}(r)?"NAME"==n?s.push(Ot(r)?r:r[0]):"PARAMETER"==n||"AXIS"==n?r.forEach(function(t){s.push([n].concat(t))}):Ot(r)?s.push([n,r]):Array.isArray(r)?s.push([n].concat(r)):((i={})[n]=r,$t("Incorrectly formatted WKT element: "+JSON.stringify(i))):s.push([n].concat(Ge(r,e+1)))}),0===e&&1==s.length&&(s=s[0]),s}function ze(t){var e={};return qe(t).forEach(function(t){Be(t,e)}),e}function qe(t){var e;t="["+(t=(t=(t=je(t)).replace(/([A-Z0-9]+)\[(?![^"]*[^\[,"]")/g,'["$1",')).replace(/, *([a-zA-Z]+) *(?=[,\]])/g,',"$1"'))+"]";try{e=JSON.parse(t)}catch(t){$t("unparsable WKT format")}return e}function je(t){var e=0;return t.replace(/"+/g,function(t){var i=e%2==0;return e+=t.length,'"'==t||'""'==t&&i?t:i?'"'+t.substring(1).replace(/""/g,'\\"'):t.replace(/""/g,'\\"')})}function Be(t,e){var i,s=t[0];if("GEOGCS"==s||"GEOCCS"==s||"PROJCS"==s||"DATUM"==s||"VERTCS"==s)for(e[s]={NAME:t[1]},i=2;i<t.length;i++){if(!Array.isArray(t[i]))throw $t("WKT parse error");Be(t[i],e[s])}else"AXIS"==s||"PARAMETER"==s?(s in e==0&&(e[s]=[]),e[s].push(t.slice(1))):e[s]=t.slice(1);return e}_e(ue("Lambert_Conformal_Conic,Lambert_Conformal_Conic_1SP,Lambert_Conformal_Conic_2SP"),Jt({PROJECTION:Xt("lcc"),PARAMETER:function(t){return De(function(t){return!ke(t,"standard_parallel_2")}(t)?"lat_1c":"lat_0b,lat_1,lat_2")(t)}})),de(pe("lcc"),oe({PROJECTION:function(t){return Te(t)?"Lambert_Conformal_Conic_1SP":"Lambert_Conformal_Conic_2SP"},PARAMETER:function(t){return Pe(Te(t)?"lat_1c,lat_0c":"lat_0b,lat_1,lat_2")(t)}})),_e(ue("Hotine_Oblique_Mercator,Hotine_Oblique_Mercator_Azimuth_Natural_Origin"),Jt({PROJECTION:Xt("omerc"),PARAMETER:function(t){return De("alpha,gamma,lonc")(t)+" +no_uoff"}})),de(Fe,ae("Hotine_Oblique_Mercator","alpha,gamma,lonc")),le("omerc","Oblique_Mercator,Hotine_Oblique_Mercator_Azimuth_Center","alpha,gamma,lonc"),de(function(t){return Le(t)&&!Fe(t)},ae("Oblique_Mercator","alpha,gamma,lonc")),le("omerc","Hotine_Oblique_Mercator_Two_Point_Natural_Origin","lat_1b,lat_2b,lon_1,lon_2"),de(function(t){return"omerc"==jt(t)&&"lat_2"in t.params&&"lon_2"in t.params},ae("Hotine_Oblique_Mercator_Two_Point_Natural_Origin","lat_1b,lat_2b,lon_1,lon_2")),_e(ue("Stereographic,Polar_Stereographic,Stereographic_North_Pole,Stereographic_South_Pole"),Jt({PROJECTION:Xt("stere"),PARAMETER:function(t){var e=De("lat_ts,lat_tsb")(t),i=/lat_ts=([^ ]+)/.exec(e);return i&&-1==e.indexOf("lat_0=")&&(e="+lat_0="+(parseFloat(i[1])<0?-90:90)+" "+e),e}})),de(pe("stere"),oe({PROJECTION:function(t){return Ne(t)?"Polar_Stereographic":"Stereographic"},PARAMETER:function(t){return Ne(t)?Pe("lat_tsb,lat_0c")(t):Pe("lat_0b")(t)}})),ce("vandg","VanDerGrinten"),_e(ue("VanDerGrinten,Van_der_Grinten_I"),Jt({PROJECTION:Xt("vandg"),PARAMETER:function(t){var e=De("")(t);return e&&(e+=" "),e+"+R_A"}})),[["aitoff","Aitoff","lat1"],["aea","Albers_Conic_Equal_Area,Albers","lat_1,lat_2"],["aeqd","Azimuthal_Equidistant"],["bonne","Bonne","lat_1"],["cass","Cassini_Soldner,Cassini"],["cea","Cylindrical_Equal_Area","lat_ts"],["eck1","Eckert_I"],["eck2","Eckert_II"],["eck3","Eckert_III"],["eck4","Eckert_IV"],["eck5","Eckert_V"],["eck6","Eckert_VI"],["eqdc","Equidistant_Conic","lat_1,lat_2"],["eqc","Plate_Carree,Equirectangular,Equidistant_Cylindrical","lat_ts"],["gall","Gall_Stereographic"],["gnom","Gnomonic"],["laea","Lambert_Azimuthal_Equal_Area"],["loxim","Loximuthal","lat_1"],["mill","Miller_Cylindrical"],["moll","Mollweide"],["nsper","Vertical_Near_Side_Perspective","h"],["nzmg","New_Zealand_Map_Grid","lat_0b"],["ortho","Orthographic","lat_0b"],["poly","Polyconic"],["robin","Robinson"],["sinu","Sinusoidal"],["sterea","Oblique_Stereographic,Double_Stereographic"],["tmerc","Transverse_Mercator,Gauss_Kruger","lat_0b"],["tpeqd","Two_Point_Equidistant","lat_1b,lat_2b,lon_1,lon_2"],["wag1","Wagner_I"],["wag2","Wagner_II"],["wag3","Wagner_III","lat_ts"],["wag4","Wagner_IV"],["wag5","Wagner_V"],["wag6","Wagner_VI"],["wag7","Wagner_VII"],["wink1","Winkel_I","lat_ts"],["wink2","Winkel_II"],["wintri","Winkel_Tripel","lat_1"]].forEach(function(t){var e=t[2]||null;le(t[0],t[1],e),ce(t[0],t[1].split(",")[0],e)});var Ue,$e,Ve={};function We(t,e,i){var s;return e>=1e-7?i*(t/(1-(s=e*t)*s)-.5/e*_((1-s)/(1+s))):t+t}function He(t,e,i){return e/c(1-i*t*t)}function Ke(e,n,r){var o,h,u,p,f,m,y,g,v,b,w,S,C,A;e.fwd=function(t,n){var r,a=t.lam;(r=u-(y?h*We(i(t.phi),e.e,e.one_es):f*i(t.phi)))<0&&q(),r=p*c(r),n.x=r*i(a*=h),n.y=m-r*s(a)},e.inv=function(n,r){var c=n.x,g=m-n.y,v=d(c,g);0!=v?(h<0&&(v=-v,c=-c,g=-g),r.phi=v/p,y?(r.phi=(u-r.phi*r.phi)/h,t(o-t(r.phi))>1e-7?(r.phi=function(e,n,r){var o,h,l,c,u,p,d=15,f=1e-7,m=1e-10;if(o=a(.5*e),n<f)return o;p=d;do{o+=u=.5*(c=1-(l=n*(h=i(o)))*l)*c/s(o)*(e/r-h/c+.5/n*_((1-l)/(1+l)))}while(t(u)>m&&--p);return p?o:x}(r.phi,e.e,e.one_es))==x&&j():r.phi=r.phi<0?-k:k):t(r.phi=(u-r.phi*r.phi)/f)<=1?r.phi=a(r.phi):r.phi=r.phi<0?-k:k,r.lam=l(c,g)/h):(r.lam=0,r.phi=h>0?k:-k)},t(n+r)<F&&U(-21),h=v=i(n),g=s(n),b=t(n-r)>=F,(y=e.es>0)?(Ze(e.es),A=He(v,g,e.es),C=We(v,e.e,e.one_es),b&&(S=He(v=i(r),g=s(r),e.es),w=We(v,e.e,e.one_es),h=(A*A-S*S)/(w-C)),o=1-.5*e.one_es*_((1-e.e)/(1+e.e))/e.e,m=(p=1/h)*c((u=A*A+h*C)-h*We(i(e.phi0),e.e,e.one_es))):(b&&(h=.5*(h+i(r))),m=(p=1/h)*c((u=g*g+(f=h+h)*v)-f*i(e.phi0)))}function Ze(t){var e,i=.046875,s=.01953125,n=.01068115234375,r=[];return r[0]=1-t*(.25+t*(i+t*(s+t*n))),r[1]=t*(.75-t*(i+t*(s+t*n))),r[2]=(e=t*t)*(.46875-t*(.013020833333333334+.007120768229166667*t)),r[3]=(e*=t)*(.3645833333333333-.005696614583333333*t),r[4]=e*t*.3076171875,r}function Xe(t,e,i,s){return i*=e,e*=e,s[0]*t-i*(s[1]+e*(s[2]+e*(s[3]+e*s[4])))}function Je(e,n,r){var a,o,h,l=1/(1-n);h=e;for(var u=10;u>0;--u)if(o=1-n*(a=i(h))*a,h-=o=(Xe(h,a,s(h),r)-e)*(o*c(o))*l,t(o)<1e-11)return h;return z(N),h}function Ye(e){var i=t(e);return i>=1?(i>1.00000000000001&&z(-19),e<0?-k:k):a(e)}function Qe(e){var i=t(e);return i>=1?(i>1.00000000000001&&z(-19),e<0?w:0):o(e)}function ti(t){return t<=0?0:c(t)}function ei(e,i){return t(e)<1e-50&&t(i)<1e-50?0:l(e,i)}function ii(e){var n=e.opaque||{mode:0};e.inv=function(e,r){var a,h,l,c,p,_,d,f,m,y,g,v,x,b,S,C,A,E=1e-12,M=0;if(t(e.x)<E&&t(e.y)<E)return r.phi=0,void(r.lam=0);r.phi=e.y,r.lam=e.x;do{a=0;do{for(v=i(.5*r.lam),S=s(.5*r.lam),x=i(r.phi),l=1-(h=(b=s(r.phi))*S)*h,c=2*(h=o(h)/u(l,1.5))*l*b*v,p=h*l*x,_=2*(v*S*x*b/l-h*x*v),d=b*b*v*v/l+h*b*S*x*x,f=x*x*S/l+h*v*v*b,m=.5*(x*b*v/l-h*x*b*b*v*S),n.mode&&(c=.5*(c+r.lam*n.cosphi1),p=.5*(p+r.phi),_*=.5,d=.5*(d+n.cosphi1),f=.5*(f+1),m*=.5),c-=e.x,g=((p-=e.y)*_-c*f)/(y=_*m-f*d),y=(c*m-p*d)/y;g>w;)g-=w;for(;g<-w;)g+=w;r.phi-=y,r.lam-=g}while((t(y)>E||t(g)>E)&&a++<10);r.phi>k&&(r.phi-=2*(r.phi-k)),r.phi<-k&&(r.phi-=2*(r.phi+k)),t(t(r.phi)-k)<E&&!n.mode&&(r.lam=0),(h=o(s(r.phi)*s(l=.5*r.lam)))?(C=2*h*s(r.phi)*i(l)*(A=1/i(h)),A*=h*i(r.phi)):C=A=0,n.mode&&(C=.5*(C+r.lam*n.cosphi1),A=.5*(A+r.phi))}while((t(e.x-C)>E||t(e.y-A)>E)&&M++<20)},e.fwd=function(t,e){var r,a;(a=o(s(t.phi)*s(r=.5*t.lam)))?(e.x=2*a*s(t.phi)*i(r)*(e.y=1/i(a)),e.y*=a*i(t.phi)):e.x=e.y=0,n.mode&&(e.x=.5*(e.x+t.lam*n.cosphi1),e.y=.5*(e.y+t.phi))},e.es=0}function si(e,s,n){e.es=0,e.fwd=function(e,r){var a,o,h=2.4674011002723395;r.y=s?k*i(e.phi):e.phi,(a=t(e.lam))>=1e-10?(n&&a>=k?r.x=c(h-e.phi*e.phi+1e-10)+a-k:(o=.5*(h/a+a),r.x=a-o+c(o*o-r.y*r.y)),e.lam<0&&(r.x=-r.x)):r.x=0}}function ni(t){var e,i=[];return i[0]=.3333333333333333*t,e=t*t,i[0]+=.17222222222222222*e,i[1]=.06388888888888888*e,e*=t,i[0]+=.10257936507936508*e,i[1]+=.0664021164021164*e,i[2]=.01677689594356261*e,i}function ri(t,e){var s=t+t;return t+e[0]*i(s)+e[1]*i(s+s)+e[2]*i(s+s+s)}function ai(t,e){t.es=0,t.fwd=function(t,i){i.y=e.C_y*t.phi,i.x=e.C_x*t.lam*(e.A+ti(1-e.B*t.phi*t.phi))},t.inv=function(t,i){i.phi=t.y/e.C_y,i.lam=t.x/(e.C_x*(e.A+ti(1-e.B*i.phi*i.phi)))}}function oi(e){var r,a,o,u,p,y,g=[],v=[],b=[],w=[];function S(t,e){for(var n,r=2*s(2*e),a=t.length-1,o=t[a],h=0;--a>=0;)n=r*o-h+t[a],h=o,o=n;return e+n*i(2*e)}function C(t,e,n){for(var r,a,o=i(e),h=s(e),l=f(n),c=m(n),u=2*h*c,p=-2*o*l,_=t.length-1,d=t[_],y=0,g=0,v=0;--_>=0;)r=g,a=y,d=u*(g=d)-r-p*(y=v)+t[_],v=p*g-a+u*y;return[(u=o*c)*d-(p=h*l)*v,u*v+p*d]}e.es<=0&&U(-34),p=u=(o=e.es/(1+c(1-e.es)))/(2-o),g[0]=u*(2+u*(-2/3+u*(u*(116/45+u*(26/45+u*(-2854/675)))-2))),v[0]=u*(u*(2/3+u*(4/3+u*(-82/45+u*(32/45+u*(4642/4725)))))-2),p*=u,g[1]=p*(7/3+u*(u*(-227/45+u*(2704/315+u*(2323/945)))-1.6)),v[1]=p*(5/3+u*(-16/15+u*(-13/9+u*(904/315+u*(-1522/945))))),p*=u,g[2]=p*(56/15+u*(-136/35+u*(-1262/105+u*(73814/2835)))),v[2]=p*(-26/15+u*(34/21+u*(1.6+u*(-12686/2835)))),p*=u,g[3]=p*(4279/630+u*(-332/35+u*(-399572/14175))),v[3]=p*(1237/630+u*(u*(-24832/14175)-2.4)),p*=u,g[4]=p*(4174/315+u*(-144838/6237)),v[4]=p*(-734/315+u*(109598/31185)),p*=u,g[5]=p*(601676/22275),v[5]=p*(444337/155925),p=u*u,r=e.k0/(1+u)*(1+p*(1/4+p*(1/64+p/256))),b[0]=u*(u*(2/3+u*(-37/96+u*(1/360+u*(81/512+u*(-96199/604800)))))-.5),w[0]=u*(.5+u*(-2/3+u*(5/16+u*(41/180+u*(-127/288+u*(7891/37800)))))),b[1]=p*(-1/48+u*(-1/15+u*(437/1440+u*(-46/105+u*(1118711/3870720))))),w[1]=p*(13/48+u*(u*(557/1440+u*(281/630+u*(-1983433/1935360)))-.6)),p*=u,b[2]=p*(-17/480+u*(37/840+u*(209/4480+u*(-5569/90720)))),w[2]=p*(61/240+u*(-103/140+u*(15061/26880+u*(167603/181440)))),p*=u,b[3]=p*(-4397/161280+u*(11/504+u*(830251/7257600))),w[3]=p*(49561/161280+u*(-179/168+u*(6601661/7257600))),p*=u,b[4]=p*(-4583/161280+u*(108847/3991680)),w[4]=p*(34729/80640+u*(-3418889/1995840)),p*=u,b[5]=p*(-20648693/638668800),w[5]=.6650675310896665*p,y=S(v,e.phi0),a=-r*(y+function(t,e){for(var n,r=2*s(e),a=t.length-1,o=t[a],h=0;--a>=0;)n=r*o-h+t[a],h=o,o=n;return i(e)*n}(w,2*y)),e.fwd=function(e,o){var h,c,u,p,f,m=e.phi,y=e.lam;m=S(v,m),h=i(m),c=s(m),p=i(y),u=s(y),m=l(h,u*c),y=l(p*c,d(h,c*u)),y=function(e){var i=t(e);return i=function(t){var e=1+t,i=e-1;return 0===i?t:t*_(e)/i}(i*(1+i/(d(1,i)+1))),e<0?-i:i}(n(y)),f=C(w,2*m,2*y),m+=f[0],y+=f[1],t(y)<=2.623395162778?(o.y=r*m+a,o.x=r*y):o.x=o.y=x},e.inv=function(e,n){var o,c,u,p,_,m=e.y,y=e.x;m=(m-a)/r,t(y/=r)<=2.623395162778?(m+=(_=C(b,2*m,2*y))[0],y+=_[1],y=h(f(y)),o=i(m),c=s(m),p=i(y),u=s(y),y=l(p,u*c),m=l(o*u,d(p,u*c)),n.phi=S(g,m),n.lam=y):n.phi=n.lam=x}}function hi(e){var n;e.es?(n=Ze(e.es),e.fwd=function(t,r){var a,o;r.y=Xe(t.phi,a=i(t.phi),o=s(t.phi),n),r.x=t.lam*o/c(1-e.es*a*a)},e.inv=function(r,a){var o=t(a.phi=Je(r.y,e.es,n));o<k?(o=i(a.phi),a.lam=r.x*c(1-e.es*o*o)/s(a.phi)):o-F<k?a.lam=0:j()}):li(e,0,1)}function li(e,n,r){var a,o;a=(o=c((n+1)/r))/(n+1),e.es=0,e.fwd=function(e,h){var l,c,u;if(n){for(l=r*i(e.phi),u=8;u&&(e.phi-=c=(n*e.phi+i(e.phi)-l)/(n+s(e.phi)),!(t(c)<1e-7));--u);u||q()}else e.phi=1!=r?Ye(r*i(e.phi)):e.phi;h.x=a*e.lam*(n+s(e.phi)),h.y=o*e.phi},e.inv=function(t,e){t.y/=o,e.phi=n?Ye((n*t.y+i(t.y))/r):1!=r?Ye(i(t.y)/r):t.y,e.lam=t.x/(a*(n+s(t.y)))}}function ci(t){pi(t,ui(0,k))}function ui(t,e){var s=i(e),n=e+e,r=c(D*s/(n+i(n)));return{C_x:2*r/w,C_y:r/s,C_p:n+i(n)}}function pi(e,n){e.fwd=function(e,r){var a,o,h;for(a=n.C_p*i(e.phi),h=10;h&&(e.phi-=o=(e.phi+i(e.phi)-a)/(1+s(e.phi)),!(t(o)<1e-7));--h);h?e.phi*=.5:e.phi=e.phi<0?-k:k,r.x=n.C_x*e.lam*s(e.phi),r.y=n.C_y*i(e.phi)},e.inv=function(e,r){r.phi=Ye(e.y/n.C_y),r.lam=e.x/(n.C_x*s(r.phi)),t(r.lam)-w<F?(r.phi+=r.phi,r.phi=Ye((r.phi+i(r.phi))/n.C_p)):r.lam=r.phi=x},e.es=0}function _i(s,n){var r,o,h,l,p,_=[[0,-1],[1,0]],d=[[-1,0],[0,-1]],f=[[0,1],[-1,0]],m=[[[1,0],[0,1]],_,d,f,f,d,_],v=1e-15;function b(s,n){var r=s.lam,o=s.phi,h=a(2/3);if(t(o)<=h)n.x=r,n.y=3*w/8*i(o);else{var l,u=c(3*(1-t(i(o)))),p=e(2*r/w+2);p>=4&&(p=3),l=-3*M+k*p,n.x=l+(r-l)*u,n.y=C(o)*M*(2-u)}}function S(i,s){var n=i.x,r=i.y,o=M;if(t(r)<=o)s.lam=n,s.phi=a(8*r/(3*w));else if(t(r)<k){var h,l,c=e(2*n/w+2);c>=4&&(c=3),h=-3*M+k*c,l=2-4*t(r)/w,s.lam=h+(n-h)/l,s.phi=C(r)*a(1-u(l,2)/3)}else s.lam=-w,s.phi=C(r)*k}function C(t){return t>0?1:t<0?-1:0}function A(t){switch(t){case 0:return 0;case 1:return 1;case 2:return 2;case 3:return 3;case-1:return 4;case-2:return 5;case-3:return 6}return 0}function E(t,e){return function(t,e,i){var s,n,r,a,o,h=0,l=t.length;for(o=0;o<l;o++)if(e==t[o][0]&&i==t[o][1])return!0;for(s=t[0][0],n=t[0][1],o=1;o<l;o++)r=t[o%l][0],a=t[o%l][1],i>y(n,a)&&i<=g(n,a)&&e<=g(s,r)&&n!=a&&(s==r||e<=(i-n)*(r-s)/(a-n)+s)&&h++,s=r,n=a;return h%2!=0}(p,t,e)}function I(e,s,n){if(n)return ri(s,l);var r=We(i(s),e.e,1-e.es)/h;return t(r)>1&&(r=C(r)),a(r)}function D(t,e,i,s){var n,r,a,o,h,l,c=0,u=function(t,e,i,s,n){var r,a={};if(a.x=t,a.y=e,n){if(e>M)a.region="north",a.x=-3*M+i*k,a.y=k,t-=i*k;else{if(!(e<-M))return a.region="equatorial",a.cn=0,a;a.region="south",a.x=-3*M+s*k,a.y=-k,t-=s*k}"north"==a.region?a.cn=e>=-t-M-v&&e<t+5*M-v?(i+1)%4:e>-t-M+v&&e>=t+5*M-v?(i+2)%4:e<=-t-M+v&&e>t+5*M+v?(i+3)%4:i:"south"==a.region&&(a.cn=e<=t+M+v&&e>-t-5*M+v?(s+1)%4:e<t+M-v&&e<=-t-5*M+v?(s+2)%4:e>=t+M-v&&e<-t-5*M-v?(s+3)%4:s)}else{if(e>M)a.region="north",r=k;else{if(!(e<-M))return a.region="equatorial",a.cn=0,a;a.region="south",r=-k}t<-k?(a.cn=0,a.x=-3*M,a.y=r):t>=-k&&t<0?(a.cn=1,a.x=-M,a.y=r):t>=0&&t<k?(a.cn=2,a.x=M,a.y=r):(a.cn=3,a.x=3*M,a.y=r)}return a}(t.x,t.y,e,i,s);if("equatorial"==u.region)return t.x=u.x,void(t.y=u.y);n=[t.x,t.y],r=[u.x,u.y],s?"north"==u.region?(c=e,l=m[A(-1*(u.cn-c))]):(c=i,l=m[A(u.cn-c)]):"north"==u.region?(c=e,l=m[A(u.cn-c)]):(c=i,l=m[A(-1*(u.cn-c))]),o=function(t,e){return[t[0]-e[0],t[1]-e[1]]}(n,r),h=function(t,e){var i,s,n=[0,0];for(i=0;i<2;i++)for(s=0;s<2;s++)n[i]+=t[i][s]*e[s];return n}(l,o),a=function(t,e){return[t[0]+e[0],t[1]+e[1]]}(h,[-3*M+(s?u.cn:0)*k,k]),t.x=a[0],t.y=a[1]}n?(r=X(s.params,"inorth_square"),o=X(s.params,"isouth_square"),(r<0||r>3)&&U(-47),(o<0||o>3)&&U(-47),p=[[-w-v,M+v],[r*k-w-v,M+v],[r*k-w-v,3*M+v],[(r+1)*k-w+v,3*M+v],[(r+1)*k-w+v,M+v],[w+v,M+v],[w+v,-M-v],[(o+1)*k-w+v,-M-v],[(o+1)*k-w+v,-3*M-v],[o*k-w-v,-3*M-v],[o*k-w-v,-M-v],[-w-v,-M-v]],0!=s.es?(l=ni(s.es),h=We(1,s.e,s.one_es),s.a=s.a*c(.5*h),s.ra=1/s.a,s.fwd=function(t,e){return t.phi=I(s,t.phi,0),b(t,e),D(e,r,o,0)},s.inv=function(t,e){if(!E(t.x,t.y))return e.lam=x,e.phi=x,void z(-15);D(t,r,o,1),S(t,e),e.phi=I(s,e.phi,1)}):(s.fwd=function(t,e){b(t,e),D(e,r,o,0)},s.inv=function(t,e){if(!E(t.x,t.y))return e.lam=x,e.phi=x,void z(-15);D(t,r,o,1),S(t,e)})):(p=[[-w-v,M],[-3*M,k+v],[-k,M+v],[-M,k+v],[0,M+v],[M,k+v],[k,M+v],[3*M,k+v],[w+v,M],[w+v,-M],[3*M,-k-v],[k,-M-v],[M,-k-v],[0,-M-v],[-M,-k-v],[-k,-M-v],[-3*M,-k-v],[-w-v,-M]],0!=s.es?(l=ni(s.es),h=We(1,s.e,s.one_es),s.a=s.a*c(.5*h),s.ra=1/s.a,s.fwd=function(t,e){t.phi=I(s,t.phi,0),b(t,e)},s.inv=function(t,e){if(!E(t.x,t.y))return e.lam=x,e.phi=x,void z(-15);S(t,e),e.phi=I(s,e.phi,1)}):(s.fwd=function(t,e){b(t,e)},s.inv=function(t,e){if(!E(t.x,t.y))return e.lam=x,e.phi=x,void z(-15);S(t,e)}))}function di(t){t.x0=0,t.y0=0,t.is_latlong=!0,t.fwd=function(e,i){i.x=e.lam/t.a,i.y=e.phi/t.a},t.inv=function(e,i){i.lam=e.x*t.a,i.phi=e.y*t.a}}function fi(t,e,i){return e*=i,n(.5*(k-t))/u((1-e)/(1+e),.5*i)}function mi(e,s){var n,r,a=.5*s,o=k-2*h(e),l=15;do{n=s*i(o),o+=r=k-2*h(e*u((1-n)/(1+n),a))-o}while(t(r)>1e-10&&--l);return l<=0&&z(-18),o}function yi(t,e){var i,s,n,r=e.length-1;for(s=e[r][0],n=e[r][1];--r>=0;)i=s,s=e[r][0]+t.r*i-t.i*n,n=e[r][1]+t.r*n+t.i*i;return{r:t.r*s-t.i*n,i:t.r*n+t.i*s}}function gi(t,e,i){var s,n,r,a,o,h=!0,l=e.length-1;for(n=a=e[l][0],s=r=e[l][1];--l>=0;)h?h=!1:(a=n+t.r*(o=a)-t.i*r,r=s+t.r*r+t.i*o),n=e[l][0]+t.r*(o=n)-t.i*s,s=e[l][1]+t.r*s+t.i*o;return i.r=n+t.r*a-t.i*r,i.i=s+t.r*r+t.i*a,{r:t.r*n-t.i*s,i:t.r*s+t.i*n}}function vi(e,r){var a,o,c,p,_=1e-12;0!=e.es?(a=e.e*i(e.phi0),o=2*h(n(.5*(k+e.phi0))*u((1-a)/(1+a),.5*e.e))-k):o=e.phi0,p=i(o),c=s(o),e.inv=function(a,o){var f,m,y,g,v,b,w,S={},C={},A={},E=0,M=0,I=0,D=0;for(S.r=a.x,S.i=a.y,f=20;f&&((m=gi(S,r,C)).r-=a.x,m.i-=a.y,y=C.r*C.r+C.i*C.i,A.r=-(m.r*C.r+m.i*C.i)/y,A.i=-(m.i*C.r-m.r*C.i)/y,S.r+=A.r,S.i+=A.i,!(t(A.r)+t(A.i)<=_));--f);if(f){if(E=d(S.r,S.i),g=2*h(.5*E),M=i(g),I=s(g),o.lam=e.lam0,t(E)<=_)return o.lam=0,void(o.phi=e.phi0);for(D=v=Ye(I*p+S.i*M*c/E),f=20;f&&(b=e.e*i(D),D+=w=2*h(n(.5*(k+v))*u((1+b)/(1-b),.5*e.e))-k-D,!(t(w)<=_));--f);}f?(o.phi=D,o.lam=l(S.r*M,E*c*I-S.i*p*M)):o.lam=o.phi=x},e.fwd=function(t,a){var o,l,_,d,f,m,y,g={};o=i(t.lam),l=s(t.lam),_=e.e*i(t.phi),d=2*h(n(.5*(k+t.phi))*u((1-_)/(1+_),.5*e.e))-k,f=i(d),m=s(d),y=2/(1+p*f+c*m*l),g.r=y*m*o,g.i=y*(c*f-p*m*l),g=yi(g,r),a.x=g.r,a.y=g.i}}function xi(e,n,r,o){var h,u,p,_,f,m,y,g,v,x,b,w,S=!isNaN(r)&&!isNaN(o);n<=0&&U(-30),S&&(v=s(o),x=i(o),w=s(r),b=i(r)),t(t(e.phi0)-k)<F?h=e.phi0<0?1:0:t(e.phi0)<F?h=2:(h=3,u=i(e.phi0),p=s(e.phi0)),m=n/e.a,f=1/(_=1+m),y=(_+1)*(g=1/m),e.fwd=function(t,e){var n,r,a,o,l;switch(a=i(t.phi),r=s(t.phi),n=s(t.lam),h){case 3:e.y=u*a+p*r*n;break;case 2:e.y=r*n;break;case 1:e.y=-a;break;case 0:e.y=a}switch(e.y<f&&q(),e.y=m/(_-e.y),e.x=e.y*r*i(t.lam),h){case 3:e.y*=p*a-u*r*n;break;case 2:e.y*=a;break;case 0:n=-n;case 1:e.y*=r*n}S&&(l=1/((o=e.y*v+e.x*x)*b*g+w),e.x=(e.x*v-e.y*x)*w*l,e.y=o*l)},e.inv=function(s,n){var r,o,f,g,C,A;if(S&&(A=1/(m-s.y*b),g=m*s.x*A,C=m*s.y*w*A,s.x=g*v+C*x,s.y=C*v-g*x),r=d(s.x,s.y),(f=1-r*r*y)<0&&j(),f=(_-c(f))/(m/r+r/m),o=c(1-f*f),t(r)<=F)n.lam=0,n.phi=e.phi0;else{switch(h){case 3:n.phi=a(o*u+s.y*f*p/r),s.y=(o-u*i(n.phi))*r,s.x*=f*p;break;case 2:n.phi=a(s.y*f/r),s.y=o*r,s.x*=f;break;case 0:n.phi=a(o),s.y=-s.y;break;case 1:n.phi=-a(o)}n.lam=l(s.x,s.y)}},e.es=0}function bi(t,e){var i=.79788456,s=.1013211836*(e?2:4);t.es=0,t.fwd=function(t,e){e.x=i*t.lam*(1-s*t.phi*t.phi),e.y=i*t.phi},t.inv=function(t,e){e.phi=t.y/i,e.lam=t.x/(i*(1-s*e.phi*e.phi))}}function wi(t,e,n){t.es=0,t.fwd=function(t,r){t.phi=Ye(.883883476*i(t.phi)),r.x=e*t.lam*s(t.phi),r.x/=s(t.phi*=.333333333333333),r.y=n*i(t.phi)},t.inv=function(t,r){r.phi=Ye(t.y/n),r.lam=t.x*s(r.phi)/e,r.phi*=3,r.lam/=s(r.phi),r.phi=Ye(1.13137085*i(r.phi))}}function Si(t,e){var i=e?1.5:2,s=e?.5:1,n=1.01346,r=1.2158542;t.es=0,t.fwd=function(t,e){e.x=n*t.lam*(i-s*c(1+r*t.phi*t.phi)),e.y=n*t.phi},t.inv=function(t,e){e.phi=t.y/n,e.lam=t.x/(n*(i-s*c(1+r*e.phi*e.phi)))}}function Ci(e,s){var n,r,a,o,h,l=1.732050807568877;s?(a=.44329,o=.80404,n=6,r=5.61125,h=3):(a=1.01346,o=.9191,n=4,r=2.147143718212938,h=2),e.es=0,e.fwd=function(e,s){var u,p,d,f;for(u=r*i(e.phi),e.phi*=1.10265779,f=10;f&&(p=c(1+e.phi*e.phi),e.phi-=d=((n-p)*e.phi-_(e.phi+p)-u)/(n-2*p),!(t(d)<1e-10));--f);f||(e.phi=u<0?-l:l),s.x=a*e.lam*(h-c(1+e.phi*e.phi)),s.y=o*e.phi},e.inv=function(t,e){var i;e.phi=t.y/o,i=c(1+e.phi*e.phi),e.lam=t.x/(a*(h-i)),e.phi=Ye(((n-i)*e.phi-_(e.phi+i))/r)}}function Ai(e){return function(r){!function(e,r){var a,o,u,p,_,f,m,y,g,v,x=1e-10;switch(X(e.params,"tlat_1")&&X(e.params,"tlat_2")?(u=X(e.params,"rlat_1"),p=X(e.params,"rlat_2"),y=.5*(p+u),(t(a=.5*(p-u))<x||t(y)<x)&&U(-42)):U(-41),r){case"TISSOT":_=i(y),o=s(a),m=c(((f=_/o+o/_)-2*i(e.phi0))/_);break;case"MURD1":f=i(a)/(a*n(y))+y,m=f-e.phi0,_=i(y);break;case"MURD2":f=(o=c(s(a)))/n(y),m=f+n(y-e.phi0),_=i(y)*o;break;case"MURD3":f=a/(n(y)*n(a))+y,m=f-e.phi0,_=i(y)*i(a)*n(a)/(a*a);break;case"EULER":_=i(y)*i(a)/a,f=(a*=.5)/(n(a)*n(y))+y,m=f-e.phi0;break;case"PCONIC":_=i(y),v=s(a),g=1/n(y),t(a=e.phi0-y)-x>=k&&U(-43),m=v*(g-n(a));break;case"VITK1":_=(o=n(a))*i(y)/a,f=a/(o*n(y))+y,m=f-e.phi0}function b(t,e){var a;switch(r){case"MURD2":a=f+n(y-t.phi);break;case"PCONIC":a=v*(g-n(t.phi-y));break;default:a=f-t.phi}e.x=a*i(t.lam*=_),e.y=m-a*s(t.lam)}function w(t,e){var i;switch(i=d(t.x,t.y=m-t.y),_<0&&(i=-i,t.x=-t.x,t.y=-t.y),e.lam=l(t.x,t.y)/_,r){case"PCONIC":e.phi=h(g-i/v)+y;break;case"MURD2":e.phi=y-h(i-f);break;default:e.phi=f-i}}e.inv=w,e.fwd=b,e.es=0}(r,e)}}function Ei(e,r){var o,p,_,f,m,y,g,v,x=1e-10;if(v=t((p=t(e.phi0))-k)<x?e.phi0<0?0:1:p>x?2:3,r=t(r),e.es){switch(v){case 1:case 0:t(r-k)<x?g=2*e.k0/c(u(1+e.e,1+e.e)*u(1-e.e,1-e.e)):(g=s(r)/fi(r,p=i(r),e.e),p*=e.e,g/=c(1-p*p));break;case 3:case 2:p=i(e.phi0),o=2*h(b(e.phi0,p,e.e))-k,p*=e.e,g=2*e.k0*s(e.phi0)/c(1-p*p),m=i(o),y=s(o)}e.fwd=function(t,n){var r,a,o,l,c,u=0,p=0;switch(r=s(t.lam),a=i(t.lam),c=i(t.phi),(2==v||3==v)&&(u=i(o=2*h(b(t.phi,c,e.e))-k),p=s(o)),v){case 2:l=g/(y*(1+m*u+y*p*r)),n.y=l*(y*u-m*p*r),n.x=l*p;break;case 3:l=g/(1+p*r),n.y=l*u,n.x=l*p;break;case 0:t.phi=-t.phi,r=-r,c=-c;case 1:n.x=g*fi(t.phi,c,e.e),n.y=-n.x*r}n.x=n.x*a},e.inv=function(r,o){o.phi;var c,p,_,f,x=0,b=0,w=0,S=0;switch(_=d(r.x,r.y),v){case 2:case 3:c=s(x=2*l(_*y,g)),p=i(x),b=a(0==_?c*m:c*m+r.y*p*y/_),x=n(.5*(k+b)),r.x*=p,r.y=_*y*c-r.y*m*p,S=k,w=.5*e.e;break;case 1:r.y=-r.y;case 0:b=k-2*h(x=-_/g),S=-k,w=-.5*e.e}for(f=0;f<8;f++,b=o.phi)if(p=e.e*i(b),o.phi=2*h(x*u((1+p)/(1-p),w))-S,t(b-o.phi)<1e-10)return 0==v&&(o.phi=-o.phi),void(o.lam=0==r.x&&0==r.y?0:l(r.x,r.y));j()}}else{switch(v){case 2:_=i(e.phi0),f=s(e.phi0);case 3:g=2*e.k0;break;case 0:case 1:g=t(r-k)>=x?s(r)/n(M-.5*r):2*e.k0}e.fwd=function(e,r){var a=e.phi,o=i(a),h=s(a),l=s(e.lam),c=i(e.lam);switch(v){case 3:case 2:r.y=3==v?1+h*l:1+_*o+f*h*l,r.y<=x&&q(),r.x=(r.y=g/r.y)*h*c,r.y*=3==v?o:f*o-_*h*l;break;case 1:l=-l,a=-a;case 0:t(a-k)<1e-8&&q(),r.x=c*(r.y=g*n(M+.5*a)),r.y*=l}},e.inv=function(n,r){var o,c,u,p;switch(u=i(o=2*h((c=d(n.x,n.y))/g)),p=s(o),r.lam=0,v){case 3:t(c)<=x?r.phi=0:r.phi=a(n.y*u/c),0==p&&0==n.x||(r.lam=l(n.x*u,p*c));break;case 2:t(c)<=x?r.phi=e.phi0:r.phi=a(p*_+n.y*u*f/c),0==(o=p-_*i(r.phi))&&0==n.x||(r.lam=l(n.x*u*f,o*c));break;case 1:n.y=-n.y;case 0:t(c)<=x?r.phi=e.phi0:r.phi=a(0==v?-p:p),r.lam=0==n.x&&0==n.y?0:l(n.x,n.y)}}}function b(t,e,i){return e*=i,n(.5*(k+t))*u((1-e)/(1+e),.5*i)}}function Mi(t,e){return u((1-t)/(1+t),e)}function ki(t,e,r,a){var o=r/e,l=e,c=1/r;t.inv=function(t,e){var i;t.y/=l,i=s(e.phi=a?h(t.y):Ye(t.y)),e.phi/=c,e.lam=t.x/(o*s(e.phi)),a?e.lam/=i*i:e.lam*=i},t.fwd=function(t,e){var r;e.x=o*t.lam*s(t.phi),e.y=l,t.phi*=c,r=s(t.phi),a?(e.x*=r*r,e.y*=n(t.phi)):(e.x/=r,e.y*=i(t.phi))},t.es=0}function Ii(e){var n,r,h,u=1e-10,d=.5,f=.16666666666666666,m=.08333333333333333,y=.05,g=.03333333333333333,v=.023809523809523808,x=.017857142857142856;e.es?((h=Ze(e.es))||e_error_0(),r=Xe(e.phi0,i(e.phi0),s(e.phi0),h),n=e.es/(1-e.es),e.fwd=function(a,o){var l,p,_,d,b,w;a.lam<-k||a.lam>k?z(-14):(l=i(a.phi),p=s(a.phi),_=t(p)>u?l/p:0,_*=_,d=p*a.lam,b=d*d,d/=c(1-e.es*l*l),w=n*p*p,o.x=e.k0*d*(1+f*b*(1-_+w+y*b*(5+_*(_-18)+w*(14-58*_)+v*b*(61+_*(_*(179-_)-479))))),o.y=e.k0*(Xe(a.phi,l,p,h)-r+l*d*a.lam*.5*(1+m*b*(5-_+w*(9+4*w)+g*b*(61+_*(_-58)+w*(270-330*_)+x*b*(1385+_*(_*(543-_)-3111)))))))},e.inv=function(a,o){var l,u,p,_,b,w,S;o.phi=Je(r+a.y/e.k0,e.es,h),t(o.phi)>=k?(o.phi=a.y<0?-k:k,o.lam=0):(w=i(o.phi),p=s(o.phi),S=t(p)>1e-10?w/p:0,l=n*p*p,_=a.x*c(u=1-e.es*w*w)/e.k0,u*=S,S*=S,b=_*_,o.phi-=u*b/(1-e.es)*d*(1-b*m*(5+S*(3-9*l)+l*(1-4*l)-b*g*(61+S*(90-252*l+45*S)+46*l-b*x*(1385+S*(3633+S*(4095+1575*S)))))),o.lam=_*(1-b*f*(1+2*S+l-b*y*(5+S*(28+24*S+8*l)+6*l-b*v*(61+S*(662+S*(1320+720*S))))))/p)}):(n=e.k0,r=.5*n,e.fwd=function(a,h){var l,p;a.lam<-k||a.lam>k?z(-14):(p=s(a.phi),l=p*i(a.lam),t(t(l)-1)<=u&&q(),h.x=r*_((1+l)/(1-l)),h.y=p*s(a.lam)/c(1-l*l),(l=t(h.y))>=1?l-1>u?q():h.y=0:h.y=o(h.y),a.phi<0&&(h.y=-h.y),h.y=n*(h.y-e.phi0))},e.inv=function(t,i){var r=p(t.x/n),o=.5*(r-1/r);r=s(e.phi0+t.y/n),i.phi=a(c((1-r*r)/(1+o*o))),t.y<0&&-i.phi+e.phi0<0&&(i.phi=-i.phi),i.lam=o||r?l(o,r):0})}function Di(t,e){var n=.8773826753,r=1.139753528477/e;t.es=0,t.fwd=function(t,a){var o=Ye(e*i(t.phi));a.x=n*t.lam*s(o),a.y=r*o},t.inv=function(t,a){t.y/=r,a.phi=Ye(i(t.y)/e),a.lam=t.x/(n*s(t.y))}}function Pi(e,i){e.fwd=function(e,s){var n,r,a,o;a=t(P*e.phi),o=(o=1-a*a)<0?0:c(o),t(e.lam)<1e-10?(s.x=0,s.y=w*(e.phi<0?-a:a)/(1+o)):(r=.5*t(w/e.lam-e.lam/w),i?(n=a/(1+o),s.x=w*(c(r*r+1-n*n)-r),s.y=w*n):(n=(o*c(1+r*r)-r*o*o)/(1+r*r*a*a),s.x=w*n,s.y=w*c(1-n*(n+2*r)+1e-10)),e.lam<0&&(s.x=-s.x),e.phi<0&&(s.y=-s.y))},e.es=0}Ve.Constants={},Ve.Math={},Ve.Accumulator={},(Ue=Ve.Constants).WGS84={a:6378137,f:1/298.257223563},Ue.version={major:1,minor:48,patch:0},Ue.version_string="1.48",($e=Ve.Math).digits=53,$e.epsilon=Math.pow(.5,$e.digits-1),$e.degree=Math.PI/180,$e.sq=function(t){return t*t},$e.hypot=function(t,e){var i,s;return t=Math.abs(t),e=Math.abs(e),i=Math.max(t,e),s=Math.min(t,e)/(i||1),i*Math.sqrt(1+s*s)},$e.cbrt=function(t){var e=Math.pow(Math.abs(t),1/3);return t<0?-e:e},$e.log1p=function(t){var e=1+t,i=e-1;return 0===i?t:t*Math.log(e)/i},$e.atanh=function(t){var e=Math.abs(t);return e=$e.log1p(2*e/(1-e))/2,t<0?-e:e},$e.copysign=function(t,e){return Math.abs(t)*(e<0||0===e&&1/e<0?-1:1)},$e.sum=function(t,e){var i=t+e,s=i-e,n=i-s;return{s:i,t:-((s-=t)+(n-=e))}},$e.polyval=function(t,e,i,s){for(var n=t<0?0:e[i++];--t>=0;)n=n*s+e[i++];return n},$e.AngRound=function(t){if(0===t)return t;var e=1/16,i=Math.abs(t);return i=i<e?e-(e-i):i,t<0?-i:i},$e.AngNormalize=function(t){return(t%=360)<=-180?t+360:t<=180?t:t-360},$e.LatFix=function(t){return Math.abs(t)>90?Number.NaN:t},$e.AngDiff=function(t,e){var i=$e.sum($e.AngNormalize(-t),$e.AngNormalize(e)),s=$e.AngNormalize(i.s),n=i.t;return $e.sum(180===s&&n>0?-180:s,n)},$e.sincosd=function(t){var e,i,s,n,r,a;switch(e=t%360,e-=90*(i=Math.floor(e/90+.5)),e*=this.degree,s=Math.sin(e),n=Math.cos(e),3&i){case 0:r=s,a=n;break;case 1:r=n,a=-s;break;case 2:r=-s,a=-n;break;default:r=-n,a=s}return t&&(r+=0,a+=0),{s:r,c:a}},$e.atan2d=function(t,e){var i,s,n=0;switch(Math.abs(t)>Math.abs(e)&&(i=e,e=t,t=i,n=2),e<0&&(e=-e,++n),s=Math.atan2(t,e)/this.degree,n){case 1:s=(t>=0?180:-180)-s;break;case 2:s=90-s;break;case 3:s=-90+s}return s},function(t,e){t.Accumulator=function(t){this.Set(t)},t.Accumulator.prototype.Set=function(e){e||(e=0),e.constructor===t.Accumulator?(this._s=e._s,this._t=e._t):(this._s=e,this._t=0)},t.Accumulator.prototype.Add=function(t){var i=e.sum(t,this._t),s=e.sum(i.s,this._s);i=i.t,this._s=s.s,this._t=s.t,0===this._s?this._s=i:this._t+=i},t.Accumulator.prototype.Sum=function(e){var i;return e?((i=new t.Accumulator(this)).Add(e),i._s):this._s},t.Accumulator.prototype.Negate=function(){this._s*=-1,this._t*=-1}}(Ve.Accumulator,Ve.Math),Ve.Geodesic={},Ve.GeodesicLine={},Ve.PolygonArea={},function(t,e,i,s,n){var r,a,o,h,l,c,u,p,_,d,f,m=20+s.digits+10,y=s.epsilon,g=200*y,v=Math.sqrt(y),x=y*g,b=1e3*v;t.tiny_=Math.sqrt(Number.MIN_VALUE),t.nC1_=6,t.nC1p_=6,t.nC2_=6,t.nC3_=6,t.nC4_=6,r=t.nC3_*(t.nC3_-1)/2,a=t.nC4_*(t.nC4_+1)/2,t.CAP_C1=1,t.CAP_C1p=2,t.CAP_C2=4,t.CAP_C3=8,t.CAP_C4=16,t.NONE=0,t.ARC=64,t.LATITUDE=128,t.LONGITUDE=256|t.CAP_C3,t.AZIMUTH=512,t.DISTANCE=1024|t.CAP_C1,t.STANDARD=t.LATITUDE|t.LONGITUDE|t.AZIMUTH|t.DISTANCE,t.DISTANCE_IN=2048|t.CAP_C1|t.CAP_C1p,t.REDUCEDLENGTH=4096|t.CAP_C1|t.CAP_C2,t.GEODESICSCALE=8192|t.CAP_C1|t.CAP_C2,t.AREA=16384|t.CAP_C4,t.ALL=32671,t.LONG_UNROLL=32768,t.OUT_MASK=32640|t.LONG_UNROLL,t.SinCosSeries=function(t,e,i,s){var n=s.length,r=n-(t?1:0),a=2*(i-e)*(i+e),o=1&r?s[--n]:0,h=0;for(r=Math.floor(r/2);r--;)o=a*(h=a*o-h+s[--n])-o+s[--n];return t?2*e*i*o:i*(o-h)},o=function(t,e){var i,n,r,a,o,h,l,c,u,p,_,d,f=s.sq(t),m=s.sq(e),y=(f+m-1)/6;return 0===m&&y<=0?i=0:(h=y,(o=(n=f*m/4)*(n+2*(a=y*(r=s.sq(y)))))>=0?(l=n+a,l+=l<0?-Math.sqrt(o):Math.sqrt(o),h+=(c=s.cbrt(l))+(0!==c?r/c:0)):(u=Math.atan2(Math.sqrt(-o),-(n+a)),h+=2*y*Math.cos(u/3)),p=Math.sqrt(s.sq(h)+m),d=((_=h<0?m/(p-h):h+p)-m)/(2*p),i=_/(Math.sqrt(_+s.sq(d))+d)),i},h=[1,4,64,0,256],t.A1m1f=function(t){var e=Math.floor(3);return(s.polyval(e,h,0,s.sq(t))/h[e+1]+t)/(1-t)},l=[-1,6,-16,32,-9,64,-128,2048,9,-16,768,3,-5,512,-7,1280,-7,2048],t.C1f=function(e,i){var n,r,a=s.sq(e),o=e,h=0;for(n=1;n<=t.nC1_;++n)r=Math.floor((t.nC1_-n)/2),i[n]=o*s.polyval(r,l,h,a)/l[h+r+1],h+=r+2,o*=e},c=[205,-432,768,1536,4005,-4736,3840,12288,-225,116,384,-7173,2695,7680,3467,7680,38081,61440],t.C1pf=function(e,i){var n,r,a=s.sq(e),o=e,h=0;for(n=1;n<=t.nC1p_;++n)r=Math.floor((t.nC1p_-n)/2),i[n]=o*s.polyval(r,c,h,a)/c[h+r+1],h+=r+2,o*=e},u=[-11,-28,-192,0,256],t.A2m1f=function(t){var e=Math.floor(3);return(s.polyval(e,u,0,s.sq(t))/u[e+1]-t)/(1+t)},p=[1,2,16,32,35,64,384,2048,15,80,768,7,35,512,63,1280,77,2048],t.C2f=function(e,i){var n,r,a=s.sq(e),o=e,h=0;for(n=1;n<=t.nC2_;++n)r=Math.floor((t.nC2_-n)/2),i[n]=o*s.polyval(r,p,h,a)/p[h+r+1],h+=r+2,o*=e},t.Geodesic=function(t,e){if(this.a=t,this.f=e,this._f1=1-this.f,this._e2=this.f*(2-this.f),this._ep2=this._e2/s.sq(this._f1),this._n=this.f/(2-this.f),this._b=this.a*this._f1,this._c2=(s.sq(this.a)+s.sq(this._b)*(0===this._e2?1:(this._e2>0?s.atanh(Math.sqrt(this._e2)):Math.atan(Math.sqrt(-this._e2)))/Math.sqrt(Math.abs(this._e2))))/2,this._etol2=.1*v/Math.sqrt(Math.max(.001,Math.abs(this.f))*Math.min(1,1-this.f/2)/2),!(isFinite(this.a)&&this.a>0))throw new Error("Equatorial radius is not positive");if(!(isFinite(this._b)&&this._b>0))throw new Error("Polar semi-axis is not positive");this._A3x=new Array(6),this._C3x=new Array(r),this._C4x=new Array(a),this.A3coeff(),this.C3coeff(),this.C4coeff()},_=[-3,128,-2,-3,64,-1,-3,-1,16,3,-1,-2,8,1,-1,2,1,1],t.Geodesic.prototype.A3coeff=function(){var t,e,i=0,n=0;for(t=5;t>=0;--t)e=Math.min(6-t-1,t),this._A3x[n++]=s.polyval(e,_,i,this._n)/_[i+e+1],i+=e+2},d=[3,128,2,5,128,-1,3,3,64,-1,0,1,8,-1,1,4,5,256,1,3,128,-3,-2,3,64,1,-3,2,32,7,512,-10,9,384,5,-9,5,192,7,512,-14,7,512,21,2560],t.Geodesic.prototype.C3coeff=function(){var e,i,n,r=0,a=0;for(e=1;e<t.nC3_;++e)for(i=t.nC3_-1;i>=e;--i)n=Math.min(t.nC3_-i-1,i),this._C3x[a++]=s.polyval(n,d,r,this._n)/d[r+n+1],r+=n+2},f=[97,15015,1088,156,45045,-224,-4784,1573,45045,-10656,14144,-4576,-858,45045,64,624,-4576,6864,-3003,15015,100,208,572,3432,-12012,30030,45045,1,9009,-2944,468,135135,5792,1040,-1287,135135,5952,-11648,9152,-2574,135135,-64,-624,4576,-6864,3003,135135,8,10725,1856,-936,225225,-8448,4992,-1144,225225,-1440,4160,-4576,1716,225225,-136,63063,1024,-208,105105,3584,-3328,1144,315315,-128,135135,-2560,832,405405,128,99099],t.Geodesic.prototype.C4coeff=function(){var e,i,n,r=0,a=0;for(e=0;e<t.nC4_;++e)for(i=t.nC4_-1;i>=e;--i)n=t.nC4_-i-1,this._C4x[a++]=s.polyval(n,f,r,this._n)/f[r+n+1],r+=n+2},t.Geodesic.prototype.A3f=function(t){return s.polyval(5,this._A3x,0,t)},t.Geodesic.prototype.C3f=function(e,i){var n,r,a=1,o=0;for(n=1;n<t.nC3_;++n)r=t.nC3_-n-1,a*=e,i[n]=a*s.polyval(r,this._C3x,o,e),o+=r+1},t.Geodesic.prototype.C4f=function(e,i){var n,r,a=1,o=0;for(n=0;n<t.nC4_;++n)r=t.nC4_-n-1,i[n]=a*s.polyval(r,this._C4x,o,e),o+=r+1,a*=e},t.Geodesic.prototype.Lengths=function(e,i,s,n,r,a,o,h,l,c,u,p,_){var d,f,m,y,g={},v=0,x=0,b=0,w=0;if((u&=t.OUT_MASK)&(t.DISTANCE|t.REDUCEDLENGTH|t.GEODESICSCALE)&&(b=t.A1m1f(e),t.C1f(e,p),u&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(w=t.A2m1f(e),t.C2f(e,_),v=b-w,w=1+w),b=1+b),u&t.DISTANCE)d=t.SinCosSeries(!0,a,o,p)-t.SinCosSeries(!0,s,n,p),g.s12b=b*(i+d),u&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(x=v*i+(b*d-w*(t.SinCosSeries(!0,a,o,_)-t.SinCosSeries(!0,s,n,_))));else if(u&(t.REDUCEDLENGTH|t.GEODESICSCALE)){for(f=1;f<=t.nC2_;++f)_[f]=b*p[f]-w*_[f];x=v*i+(t.SinCosSeries(!0,a,o,_)-t.SinCosSeries(!0,s,n,_))}return u&t.REDUCEDLENGTH&&(g.m0=v,g.m12b=h*(n*a)-r*(s*o)-n*o*x),u&t.GEODESICSCALE&&(m=n*o+s*a,y=this._ep2*(l-c)*(l+c)/(r+h),g.M12=m+(y*a-o*x)*s/r,g.M21=m-(y*s-n*x)*a/h),g},t.Geodesic.prototype.InverseStart=function(e,i,n,r,a,h,l,c,u,p,_){var d,f,m,y,v,x,w,S,C,A,E,M,k,I,D,P,T,L,F,N,R={},O=r*i-a*e,G=a*i+r*e;return R.sig12=-1,d=r*i,d+=a*e,(f=G>=0&&O<.5&&a*l<.5)?(y=s.sq(e+r),y/=y+s.sq(i+a),R.dnm=Math.sqrt(1+this._ep2*y),m=l/(this._f1*R.dnm),v=Math.sin(m),x=Math.cos(m)):(v=c,x=u),R.salp1=a*v,R.calp1=x>=0?O+a*e*s.sq(v)/(1+x):d-a*e*s.sq(v)/(1-x),S=s.hypot(R.salp1,R.calp1),C=e*r+i*a*x,f&&S<this._etol2?(R.salp2=i*v,R.calp2=O-i*r*(x>=0?s.sq(v)/(1+x):1-x),w=s.hypot(R.salp2,R.calp2),R.salp2/=w,R.calp2/=w,R.sig12=Math.atan2(S,C)):Math.abs(this._n)>.1||C>=0||S>=6*Math.abs(this._n)*Math.PI*s.sq(i)||(N=Math.atan2(-c,-u),this.f>=0?(I=(k=s.sq(e)*this._ep2)/(2*(1+Math.sqrt(1+k))+k),A=N/(M=this.f*i*this.A3f(I)*Math.PI),E=d/(M*i)):(D=a*i-r*e,P=Math.atan2(d,D),E=l/(M=((A=(T=this.Lengths(this._n,Math.PI+P,e,-i,n,r,a,h,i,a,t.REDUCEDLENGTH,p,_)).m12b/(i*a*T.m0*Math.PI)-1)<-.01?d/A:-this.f*s.sq(i)*Math.PI)/i)),E>-g&&A>-1-b?this.f>=0?(R.salp1=Math.min(1,-A),R.calp1=-Math.sqrt(1-s.sq(R.salp1))):(R.calp1=Math.max(A>-g?0:-1,A),R.salp1=Math.sqrt(1-s.sq(R.calp1))):(L=o(A,E),F=M*(this.f>=0?-A*L/(1+L):-E*(1+L)/L),v=Math.sin(F),x=-Math.cos(F),R.salp1=a*v,R.calp1=d-a*e*s.sq(v)/(1-x))),R.salp1<=0?(R.salp1=1,R.calp1=0):(w=s.hypot(R.salp1,R.calp1),R.salp1/=w,R.calp1/=w),R},t.Geodesic.prototype.Lambda12=function(e,i,n,r,a,o,h,l,c,u,p,_,d,f){var m,y,g,v,x,b,w,S,C,A,E,M,k,I={};return 0===e&&0===l&&(l=-t.tiny_),y=h*i,g=s.hypot(l,h*e),I.ssig1=e,v=y*e,I.csig1=x=l*i,m=s.hypot(I.ssig1,I.csig1),I.ssig1/=m,I.csig1/=m,I.salp2=a!==i?y/a:h,I.calp2=a!==i||Math.abs(r)!==-e?Math.sqrt(s.sq(l*i)+(i<-e?(a-i)*(i+a):(e-r)*(e+r)))/a:Math.abs(l),I.ssig2=r,b=y*r,I.csig2=w=I.calp2*a,m=s.hypot(I.ssig2,I.csig2),I.ssig2/=m,I.csig2/=m,I.sig12=Math.atan2(Math.max(0,I.csig1*I.ssig2-I.ssig1*I.csig2),I.csig1*I.csig2+I.ssig1*I.ssig2),S=Math.max(0,x*b-v*w),C=x*w+v*b,E=Math.atan2(S*u-C*c,C*u+S*c),M=s.sq(g)*this._ep2,I.eps=M/(2*(1+Math.sqrt(1+M))+M),this.C3f(I.eps,f),A=t.SinCosSeries(!0,I.ssig2,I.csig2,f)-t.SinCosSeries(!0,I.ssig1,I.csig1,f),I.domg12=-this.f*this.A3f(I.eps)*y*(I.sig12+A),I.lam12=E+I.domg12,p&&(0===I.calp2?I.dlam12=-2*this._f1*n/e:(k=this.Lengths(I.eps,I.sig12,I.ssig1,I.csig1,n,I.ssig2,I.csig2,o,i,a,t.REDUCEDLENGTH,_,d),I.dlam12=k.m12b,I.dlam12*=this._f1/(I.calp2*a))),I},t.Geodesic.prototype.Inverse=function(e,i,n,r,a){var o,h;return a||(a=t.STANDARD),a===t.LONG_UNROLL&&(a|=t.STANDARD),a&=t.OUT_MASK,h=(o=this.InverseInt(e,i,n,r,a)).vals,a&t.AZIMUTH&&(h.azi1=s.atan2d(o.salp1,o.calp1),h.azi2=s.atan2d(o.salp2,o.calp2)),h},t.Geodesic.prototype.InverseInt=function(e,i,n,r,a){var o,h,l,c,u,p,_,d,f,g,v,b,w,S,C,A,E,M,k,I,D,P,T,L,F,N,R,O,G,z,q,j,B,U,$,V,W,H,K,Z,X,J,Y,Q,tt,et,it,st,nt,rt,at,ot,ht,lt,ct,ut,pt,_t,dt,ft,mt,yt,gt,vt,xt,bt={};if(bt.lat1=e=s.LatFix(e),bt.lat2=n=s.LatFix(n),e=s.AngRound(e),n=s.AngRound(n),h=(o=s.AngDiff(i,r)).t,o=o.s,a&t.LONG_UNROLL?(bt.lon1=i,bt.lon2=i+o+h):(bt.lon1=s.AngNormalize(i),bt.lon2=s.AngNormalize(r)),o=(l=o>=0?1:-1)*s.AngRound(o),h=s.AngRound(180-o-l*h),C=o*s.degree,A=(c=s.sincosd(o>90?h:o)).s,E=(o>90?-1:1)*c.c,(u=Math.abs(e)<Math.abs(n)?-1:1)<0&&(l*=-1,c=e,e=n,n=c),e*=p=e<0?1:-1,n*=p,c=s.sincosd(e),_=this._f1*c.s,d=c.c,_/=c=s.hypot(_,d),d/=c,d=Math.max(t.tiny_,d),c=s.sincosd(n),f=this._f1*c.s,g=c.c,f/=c=s.hypot(f,g),g/=c,g=Math.max(t.tiny_,g),d<-_?g===d&&(f=f<0?_:-_):Math.abs(f)===-_&&(g=d),w=Math.sqrt(1+this._ep2*s.sq(_)),S=Math.sqrt(1+this._ep2*s.sq(f)),T=new Array(t.nC1_+1),L=new Array(t.nC2_+1),F=new Array(t.nC3_),(N=-90===e||0===A)&&(I=A,P=0,O=_,G=(k=E)*d,z=f,q=(D=1)*g,M=Math.atan2(Math.max(0,G*z-O*q),G*q+O*z),v=(R=this.Lengths(this._n,M,O,G,w,z,q,S,d,g,a|t.DISTANCE|t.REDUCEDLENGTH,T,L)).s12b,b=R.m12b,0!==(a&t.GEODESICSCALE)&&(bt.M12=R.M12,bt.M21=R.M21),M<1||b>=0?(M<3*t.tiny_&&(M=b=v=0),b*=this._b,v*=this._b,bt.a12=M/s.degree):N=!1),pt=2,!N&&0===_&&(this.f<=0||h>=180*this.f))k=D=0,I=P=1,v=this.a*C,M=B=C/this._f1,b=this._b*Math.sin(M),a&t.GEODESICSCALE&&(bt.M12=bt.M21=Math.cos(M)),bt.a12=o/this._f1;else if(!N)if(M=(R=this.InverseStart(_,d,w,f,g,S,C,A,E,T,L)).sig12,I=R.salp1,k=R.calp1,M>=0)P=R.salp2,D=R.calp2,U=R.dnm,v=M*this._b*U,b=s.sq(U)*this._b*Math.sin(M/U),a&t.GEODESICSCALE&&(bt.M12=bt.M21=Math.cos(M/U)),bt.a12=M/s.degree,B=C/(this._f1*U);else{for($=0,V=t.tiny_,W=1,H=t.tiny_,K=-1,Z=!1,X=!1;$<m&&(J=(R=this.Lambda12(_,d,w,f,g,S,I,k,A,E,$<20,T,L,F)).lam12,P=R.salp2,D=R.calp2,M=R.sig12,O=R.ssig1,G=R.csig1,z=R.ssig2,q=R.csig2,j=R.eps,dt=R.domg12,Y=R.dlam12,!X&&Math.abs(J)>=(Z?8:1)*y);++$)J>0&&($<20||k/I>K/H)?(H=I,K=k):J<0&&($<20||k/I<W/V)&&(V=I,W=k),$<20&&Y>0&&(Q=-J/Y,tt=Math.sin(Q),(it=I*(et=Math.cos(Q))+k*tt)>0&&Math.abs(Q)<Math.PI)?(k=k*et-I*tt,I=it,I/=c=s.hypot(I,k),k/=c,Z=Math.abs(J)<=16*y):(I=(V+H)/2,k=(W+K)/2,I/=c=s.hypot(I,k),k/=c,Z=!1,X=Math.abs(V-I)+(W-k)<x||Math.abs(I-H)+(k-K)<x);st=a|(a&(t.REDUCEDLENGTH|t.GEODESICSCALE)?t.DISTANCE:t.NONE),v=(R=this.Lengths(j,M,O,G,w,z,q,S,d,g,st,T,L)).s12b,b=R.m12b,0!==(a&t.GEODESICSCALE)&&(bt.M12=R.M12,bt.M21=R.M21),b*=this._b,v*=this._b,bt.a12=M/s.degree,a&t.AREA&&(vt=Math.sin(dt),pt=A*(xt=Math.cos(dt))-E*vt,_t=E*xt+A*vt)}return a&t.DISTANCE&&(bt.s12=0+v),a&t.REDUCEDLENGTH&&(bt.m12=0+b),a&t.AREA&&(nt=I*d,0!==(rt=s.hypot(k,I*_))&&0!==nt?(O=_,G=k*d,z=f,q=D*g,j=(ot=s.sq(rt)*this._ep2)/(2*(1+Math.sqrt(1+ot))+ot),ht=s.sq(this.a)*rt*nt*this._e2,O/=c=s.hypot(O,G),G/=c,z/=c=s.hypot(z,q),q/=c,lt=new Array(t.nC4_),this.C4f(j,lt),ct=t.SinCosSeries(!1,O,G,lt),ut=t.SinCosSeries(!1,z,q,lt),bt.S12=ht*(ut-ct)):bt.S12=0,!N&&pt>1&&(pt=Math.sin(B),_t=Math.cos(B)),!N&&_t>-.7071&&f-_<1.75?(dt=1+_t,ft=1+d,mt=1+g,at=2*Math.atan2(pt*(_*mt+f*ft),dt*(_*f+ft*mt))):(gt=D*k+P*I,0===(yt=P*k-D*I)&&gt<0&&(yt=t.tiny_*k,gt=-1),at=Math.atan2(yt,gt)),bt.S12+=this._c2*at,bt.S12*=u*l*p,bt.S12+=0),u<0&&(c=I,I=P,P=c,c=k,k=D,D=c,a&t.GEODESICSCALE&&(c=bt.M12,bt.M12=bt.M21,bt.M21=c)),{vals:bt,salp1:I*=u*l,calp1:k*=u*p,salp2:P*=u*l,calp2:D*=u*p}},t.Geodesic.prototype.GenDirect=function(i,s,n,r,a,o){return o?o===t.LONG_UNROLL&&(o|=t.STANDARD):o=t.STANDARD,r||(o|=t.DISTANCE_IN),new e.GeodesicLine(this,i,s,n,o).GenPosition(r,a,o)},t.Geodesic.prototype.Direct=function(t,e,i,s,n){return this.GenDirect(t,e,i,!1,s,n)},t.Geodesic.prototype.ArcDirect=function(t,e,i,s,n){return this.GenDirect(t,e,i,!0,s,n)},t.Geodesic.prototype.Line=function(t,i,s,n){return new e.GeodesicLine(this,t,i,s,n)},t.Geodesic.prototype.DirectLine=function(t,e,i,s,n){return this.GenDirectLine(t,e,i,!1,s,n)},t.Geodesic.prototype.ArcDirectLine=function(t,e,i,s,n){return this.GenDirectLine(t,e,i,!0,s,n)},t.Geodesic.prototype.GenDirectLine=function(i,s,n,r,a,o){var h;return o||(o=t.STANDARD|t.DISTANCE_IN),r||(o|=t.DISTANCE_IN),(h=new e.GeodesicLine(this,i,s,n,o)).GenSetDistance(r,a),h},t.Geodesic.prototype.InverseLine=function(i,n,r,a,o){var h,l,c;return o||(o=t.STANDARD|t.DISTANCE_IN),h=this.InverseInt(i,n,r,a,t.ARC),c=s.atan2d(h.salp1,h.calp1),o&t.OUT_MASK&t.DISTANCE_IN&&(o|=t.DISTANCE),(l=new e.GeodesicLine(this,i,n,c,o,h.salp1,h.calp1)).SetArc(h.vals.a12),l},t.Geodesic.prototype.Polygon=function(t){return new i.PolygonArea(this,t)},t.WGS84=new t.Geodesic(n.WGS84.a,n.WGS84.f)}(Ve.Geodesic,Ve.GeodesicLine,Ve.PolygonArea,Ve.Math,Ve.Constants),function(t,e,i){e.GeodesicLine=function(e,s,n,r,a,o,h){var l,c,u,p,_,d;a||(a=t.STANDARD|t.DISTANCE_IN),this.a=e.a,this.f=e.f,this._b=e._b,this._c2=e._c2,this._f1=e._f1,this.caps=a|t.LATITUDE|t.AZIMUTH|t.LONG_UNROLL,this.lat1=i.LatFix(s),this.lon1=n,void 0===o||void 0===h?(this.azi1=i.AngNormalize(r),l=i.sincosd(i.AngRound(this.azi1)),this.salp1=l.s,this.calp1=l.c):(this.azi1=r,this.salp1=o,this.calp1=h),l=i.sincosd(i.AngRound(this.lat1)),u=this._f1*l.s,c=l.c,u/=l=i.hypot(u,c),c/=l,c=Math.max(t.tiny_,c),this._dn1=Math.sqrt(1+e._ep2*i.sq(u)),this._salp0=this.salp1*c,this._calp0=i.hypot(this.calp1,this.salp1*u),this._ssig1=u,this._somg1=this._salp0*u,this._csig1=this._comg1=0!==u||0!==this.calp1?c*this.calp1:1,l=i.hypot(this._ssig1,this._csig1),this._ssig1/=l,this._csig1/=l,this._k2=i.sq(this._calp0)*e._ep2,p=this._k2/(2*(1+Math.sqrt(1+this._k2))+this._k2),this.caps&t.CAP_C1&&(this._A1m1=t.A1m1f(p),this._C1a=new Array(t.nC1_+1),t.C1f(p,this._C1a),this._B11=t.SinCosSeries(!0,this._ssig1,this._csig1,this._C1a),_=Math.sin(this._B11),d=Math.cos(this._B11),this._stau1=this._ssig1*d+this._csig1*_,this._ctau1=this._csig1*d-this._ssig1*_),this.caps&t.CAP_C1p&&(this._C1pa=new Array(t.nC1p_+1),t.C1pf(p,this._C1pa)),this.caps&t.CAP_C2&&(this._A2m1=t.A2m1f(p),this._C2a=new Array(t.nC2_+1),t.C2f(p,this._C2a),this._B21=t.SinCosSeries(!0,this._ssig1,this._csig1,this._C2a)),this.caps&t.CAP_C3&&(this._C3a=new Array(t.nC3_),e.C3f(p,this._C3a),this._A3c=-this.f*this._salp0*e.A3f(p),this._B31=t.SinCosSeries(!0,this._ssig1,this._csig1,this._C3a)),this.caps&t.CAP_C4&&(this._C4a=new Array(t.nC4_),e.C4f(p,this._C4a),this._A4=i.sq(this.a)*this._calp0*this._salp0*e._e2,this._B41=t.SinCosSeries(!1,this._ssig1,this._csig1,this._C4a)),this.a13=this.s13=Number.NaN},e.GeodesicLine.prototype.GenPosition=function(e,s,n){var r,a,o,h,l,c,u,p,_,d,f,m,y,g,v,x,b,w,S,C,A,E,M,k,I,D,P={};return n?n===t.LONG_UNROLL&&(n|=t.STANDARD):n=t.STANDARD,n&=this.caps&t.OUT_MASK,P.lat1=this.lat1,P.azi1=this.azi1,P.lon1=n&t.LONG_UNROLL?this.lon1:i.AngNormalize(this.lon1),e?P.a12=s:P.s12=s,e||this.caps&t.DISTANCE_IN&t.OUT_MASK?(h=0,l=0,e?(r=s*i.degree,a=(M=i.sincosd(s)).s,o=M.c):(p=s/(this._b*(1+this._A1m1)),_=Math.sin(p),d=Math.cos(p),r=p-((h=-t.SinCosSeries(!0,this._stau1*d+this._ctau1*_,this._ctau1*d-this._stau1*_,this._C1pa))-this._B11),a=Math.sin(r),o=Math.cos(r),Math.abs(this.f)>.01&&(c=this._ssig1*o+this._csig1*a,u=this._csig1*o-this._ssig1*a,h=t.SinCosSeries(!0,c,u,this._C1a),r-=((1+this._A1m1)*(r+(h-this._B11))-s/this._b)/Math.sqrt(1+this._k2*i.sq(c)),a=Math.sin(r),o=Math.cos(r))),c=this._ssig1*o+this._csig1*a,u=this._csig1*o-this._ssig1*a,S=Math.sqrt(1+this._k2*i.sq(c)),n&(t.DISTANCE|t.REDUCEDLENGTH|t.GEODESICSCALE)&&((e||Math.abs(this.f)>.01)&&(h=t.SinCosSeries(!0,c,u,this._C1a)),l=(1+this._A1m1)*(h-this._B11)),y=this._calp0*c,0===(g=i.hypot(this._salp0,this._calp0*u))&&(g=u=t.tiny_),b=this._salp0,w=this._calp0*u,e&&n&t.DISTANCE&&(P.s12=this._b*((1+this._A1m1)*r+l)),n&t.LONGITUDE&&(v=this._salp0*c,x=u,m=i.copysign(1,this._salp0),f=((n&t.LONG_UNROLL?m*(r-(Math.atan2(c,u)-Math.atan2(this._ssig1,this._csig1))+(Math.atan2(m*v,x)-Math.atan2(m*this._somg1,this._comg1))):Math.atan2(v*this._comg1-x*this._somg1,x*this._comg1+v*this._somg1))+this._A3c*(r+(t.SinCosSeries(!0,c,u,this._C3a)-this._B31)))/i.degree,P.lon2=n&t.LONG_UNROLL?this.lon1+f:i.AngNormalize(i.AngNormalize(this.lon1)+i.AngNormalize(f))),n&t.LATITUDE&&(P.lat2=i.atan2d(y,this._f1*g)),n&t.AZIMUTH&&(P.azi2=i.atan2d(b,w)),n&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(C=t.SinCosSeries(!0,c,u,this._C2a),A=(1+this._A2m1)*(C-this._B21),E=(this._A1m1-this._A2m1)*r+(l-A),n&t.REDUCEDLENGTH&&(P.m12=this._b*(S*(this._csig1*c)-this._dn1*(this._ssig1*u)-this._csig1*u*E)),n&t.GEODESICSCALE&&(M=this._k2*(c-this._ssig1)*(c+this._ssig1)/(this._dn1+S),P.M12=o+(M*c-u*E)*this._ssig1/this._dn1,P.M21=o-(M*this._ssig1-this._csig1*E)*c/S)),n&t.AREA&&(k=t.SinCosSeries(!1,c,u,this._C4a),0===this._calp0||0===this._salp0?(I=b*this.calp1-w*this.salp1,D=w*this.calp1+b*this.salp1):(I=this._calp0*this._salp0*(o<=0?this._csig1*(1-o)+a*this._ssig1:a*(this._csig1*a/(1+o)+this._ssig1)),D=i.sq(this._salp0)+i.sq(this._calp0)*this._csig1*u),P.S12=this._c2*Math.atan2(I,D)+this._A4*(k-this._B41)),e||(P.a12=r/i.degree),P):(P.a12=Number.NaN,P)},e.GeodesicLine.prototype.Position=function(t,e){return this.GenPosition(!1,t,e)},e.GeodesicLine.prototype.ArcPosition=function(t,e){return this.GenPosition(!0,t,e)},e.GeodesicLine.prototype.GenSetDistance=function(t,e){t?this.SetArc(e):this.SetDistance(e)},e.GeodesicLine.prototype.SetDistance=function(e){var i;this.s13=e,i=this.GenPosition(!1,this.s13,t.ARC),this.a13=0+i.a12},e.GeodesicLine.prototype.SetArc=function(e){var i;this.a13=e,i=this.GenPosition(!0,this.a13,t.DISTANCE),this.s13=0+i.s12}}(Ve.Geodesic,Ve.GeodesicLine,Ve.Math),function(t,e,i,s){var n,r;n=function(t,e){var s;return t=i.AngNormalize(t),e=i.AngNormalize(e),s=i.AngDiff(t,e).s,t<=0&&e>0&&s>0?1:e<=0&&t>0&&s<0?-1:0},r=function(t,e){return((e%=720)>=0&&e<360||e<-360?0:1)-((t%=720)>=0&&t<360||t<-360?0:1)},t.PolygonArea=function(t,i){this._geod=t,this.a=this._geod.a,this.f=this._geod.f,this._area0=4*Math.PI*t._c2,this.polyline=i||!1,this._mask=e.LATITUDE|e.LONGITUDE|e.DISTANCE|(this.polyline?e.NONE:e.AREA|e.LONG_UNROLL),this.polyline||(this._areasum=new s.Accumulator(0)),this._perimetersum=new s.Accumulator(0),this.Clear()},t.PolygonArea.prototype.Clear=function(){this.num=0,this._crossings=0,this.polyline||this._areasum.Set(0),this._perimetersum.Set(0),this._lat0=this._lon0=this.lat=this.lon=Number.NaN},t.PolygonArea.prototype.AddPoint=function(t,e){var i;0===this.num?(this._lat0=this.lat=t,this._lon0=this.lon=e):(i=this._geod.Inverse(this.lat,this.lon,t,e,this._mask),this._perimetersum.Add(i.s12),this.polyline||(this._areasum.Add(i.S12),this._crossings+=n(this.lon,e)),this.lat=t,this.lon=e),++this.num},t.PolygonArea.prototype.AddEdge=function(t,e){var i;this.num&&(i=this._geod.Direct(this.lat,this.lon,t,e,this._mask),this._perimetersum.Add(e),this.polyline||(this._areasum.Add(i.S12),this._crossings+=r(this.lon,i.lon2)),this.lat=i.lat2,this.lon=i.lon2),++this.num},t.PolygonArea.prototype.Compute=function(t,e){var i,r,a={number:this.num};return this.num<2?(a.perimeter=0,this.polyline||(a.area=0),a):this.polyline?(a.perimeter=this._perimetersum.Sum(),a):(i=this._geod.Inverse(this.lat,this.lon,this._lat0,this._lon0,this._mask),a.perimeter=this._perimetersum.Sum(i.s12),(r=new s.Accumulator(this._areasum)).Add(i.S12),1&this._crossings+n(this.lon,this._lon0)&&r.Add((r.Sum()<0?1:-1)*this._area0/2),t||r.Negate(),e?r.Sum()>this._area0/2?r.Add(-this._area0):r.Sum()<=-this._area0/2&&r.Add(+this._area0):(r.Sum()>=this._area0||r<0)&&r.Add(-this._area0),a.area=r.Sum(),a)},t.PolygonArea.prototype.TestPoint=function(t,e,i,s){var r,a,o,h,l={number:this.num+1};if(0===this.num)return l.perimeter=0,this.polyline||(l.area=0),l;for(l.perimeter=this._perimetersum.Sum(),a=this.polyline?0:this._areasum.Sum(),o=this._crossings,h=0;h<(this.polyline?1:2);++h)r=this._geod.Inverse(0===h?this.lat:t,0===h?this.lon:e,0!==h?this._lat0:t,0!==h?this._lon0:e,this._mask),l.perimeter+=r.s12,this.polyline||(a+=r.S12,o+=n(0===h?this.lon:e,0!==h?this._lon0:e));return this.polyline||(1&o&&(a+=(a<0?1:-1)*this._area0/2),i||(a*=-1),s?a>this._area0/2?a-=this._area0:a<=-this._area0/2&&(a+=this._area0):a>=this._area0?a-=this._area0:a<0&&(a+=this._area0),l.area=a),l},t.PolygonArea.prototype.TestEdge=function(t,e,i,s){var a,o,h,l={number:this.num?this.num+1:0};return 0===this.num||(l.perimeter=this._perimetersum.Sum()+e,this.polyline||(o=this._areasum.Sum(),h=this._crossings,o+=(a=this._geod.Direct(this.lat,this.lon,t,e,this._mask)).S12,h+=r(this.lon,a.lon2),a=this._geod.Inverse(a.lat2,a.lon2,this._lat0,this._lon0,this._mask),l.perimeter+=a.s12,o+=a.S12,1&(h+=n(a.lon2,this._lon0))&&(o+=(o<0?1:-1)*this._area0/2),i||(o*=-1),s?o>this._area0/2?o-=this._area0:o<=-this._area0/2&&(o+=this._area0):o>=this._area0?o-=this._area0:o<0&&(o+=this._area0),l.area=o)),l}}(Ve.PolygonArea,Ve.Geodesic,Ve.Math,Ve.Accumulator),tt(function(t){var e=X(t.params,"rlat_1"),i=X(t.params,"rlat_2");Ke(t,e,i)},"aea","Albers Equal Area","Conic Sph&Ell\nlat_1= lat_2="),tt(function(t){var e=X(t.params,"rlat_1"),i=X(t.params,"bsouth")?-k:k;Ke(t,e,i)},"leac","Lambert Equal Area Conic","Conic, Sph&Ell\nlat_1= south"),tt(function(e){var r,a,h,u,p,_,f,m=1e-10;if(e.phi0=X(e.params,"rlat_0"),t(t(e.phi0)-k)<m?(p=e.phi0<0?1:0,r=e.phi0<0?-1:1,a=0):t(e.phi0)<m?(p=2,r=0,a=1):(p=3,r=i(e.phi0),a=s(e.phi0)),e.es)if(f=new Ve.Geodesic.Geodesic(e.a,e.es/(1+c(e.one_es))),_=Ze(e.es),X(e.params,"bguam"))h=Xe(e.phi0,r,a,_),e.inv=function(t,r){var a,o,l;for(a=.5*t.x*t.x,r.phi=e.phi0,l=0;l<3;++l)o=e.e*i(r.phi),r.phi=Je(h+t.y-a*n(r.phi)*(o=c(1-o*o)),e.es,_);r.lam=t.x*o/s(r.phi)},e.fwd=function(t,n){var r,a,o;r=s(t.phi),a=i(t.phi),o=1/c(1-e.es*a*a),n.x=t.lam*r*o,n.y=Xe(t.phi,a,r,_)-h+.5*t.lam*t.lam*r*a*o};else{switch(p){case 0:u=Xe(k,1,0,_);break;case 1:u=Xe(-k,-1,0,_);break;case 2:case 3:e.inv=g,e.fwd=y,c(1-e.es*r*r),e.e,c(e.one_es)}e.inv=g,e.fwd=y}else e.inv=function(t,n){var o,h,c,u=t.x,_=t.y;if((h=d(u,_))>w)h-m>w&&j(),h=w;else if(h<m)return n.phi=e.phi0,void(n.lam=0);3==p||2==p?(c=i(h),o=s(h),2==p?(n.phi=Ye(_*c/h),u*=c,_=o*h):(n.phi=Ye(o*r+_*c*a/h),_=(o-r*i(n.phi))*h,u*=c*a),n.lam=0==_?0:l(u,_)):0==p?(n.phi=k-h,n.lam=l(u,-_)):(n.phi=h-k,n.lam=l(u,_))},e.fwd=function(e,n){var h,l,c;switch(c=i(e.phi),l=s(e.phi),h=s(e.lam),p){case 2:case 3:n.y=2==p?l*h:r*c+a*l*h,t(t(n.y)-1)<1e-14?n.y<0?q():n.x=n.y=0:(n.y=o(n.y),n.y/=i(n.y),n.x=n.y*l*i(e.lam),n.y*=2==p?c:a*c-r*l*h);break;case 0:e.phi=-e.phi,h=-h;case 1:t(e.phi-k)<m&&q(),n.x=(n.y=k+e.phi)*i(e.lam),n.y*=h}};function y(n,r){var a,o,h,l,c,d,y,g,v,x,b;switch(a=s(n.lam),o=s(n.phi),h=i(n.phi),p){case 0:a=-a;case 1:r.x=(l=t(u-Xe(n.phi,h,o,_)))*i(n.lam),r.y=l*a;break;case 2:case 3:if(t(n.lam)<m&&t(n.phi-e.phi0)<m){r.x=r.y=0;break}g=e.phi0/C,y=e.lam0/C,x=n.phi/C,v=(n.lam+e.lam0)/C,c=(b=f.Inverse(g,y,x,v,f.AZIMUTH)).azi1*C,d=b.s12,r.x=d*i(c)/e.a,r.y=d*s(c)/e.a}}function g(t,i){var s,n,r,a,o,h,y,g;if((s=d(t.x,t.y))<m)return i.phi=e.phi0,i.lam=0,i;3==p||2==p?(a=t.x*e.a,o=t.y*e.a,h=e.phi0/C,y=e.lam0/C,n=l(a,o)/C,r=c(a*a+o*o),g=f.Direct(h,y,n,r,f.STANDARD),i.phi=g.lat2*C,i.lam=g.lon2*C,i.lam-=e.lam0):(i.phi=Je(0==p?u-s:u+s,e.es,_),i.lam=l(t.x,0==p?-t.y:t.y))}},"aeqd","Azimuthal Equidistant","Azi, Sph&Ell\nlat_0 guam"),tt(function(e){var r,a,o,h,l,c,u=1e-10;e.es=0,e.fwd=function(e,c){var p,d,f,m,y,g,v,x;switch(p=i(e.lam),d=s(e.lam),h){case 2:case 3:m=i(e.phi),x=(f=s(e.phi))*d,3==h&&(x=r*m+a*x),!l&&x<-u&&q(),v=t(g=1-x)>u?-_(y=.5*(1+x))/g-o/y:.5-o,c.x=v*f*p,c.y=3==h?v*(a*m-r*f*d):v*m;break;case 1:case 0:e.phi=t(p_halfpi-e.phi),!l&&e.phi-u>k&&q(),(e.phi*=.5)>u?(y=n(e.phi),v=-2*(_(s(e.phi))/y+y*o),c.x=v*p,c.y=v*d,0==h&&(c.y=-c.y)):c.x=c.y=0}},l=X(e.params,"bno_cut"),c=.5*(k-X(e.params,"rlat_b")),t(c)<u?o=-.5:(o=1/n(c),o*=o*_(s(c))),t(t(e.phi0)-k)<u?e.phi0<0?(p_halfpi=-k,h=1):(p_halfpi=k,h=0):t(e.phi0)<u?h=2:(h=3,r=i(e.phi0),a=s(e.phi0))},"airy","Airy","Misc Sph, no inv.\nno_cut lat_b="),tt(function(t){var e=t.opaque={mode:1};X(t.params,"tlat_1")?0===(e.cosphi1=s(X(t.params,"rlat_1")))&&U(-22):e.cosphi1=.6366197723675814,ii(t)},"wintri","Winkel Tripel","Misc Sph\nlat_1"),tt(ii,"aitoff","Aitoff","Misc Sph"),tt(function(t){t.fwd=function(t,e){var r,a,o,h,l,u,p,_=4/3,d=t.lam;r=n(.5*t.phi),o=1+(a=c(1-r*r))*s(d*=.5),h=i(d)*a/o,u=r/o,e.x=_*h*(3+(l=h*h)-3*(p=u*u)),e.y=_*u*(3+3*l-p)},t.es=0},"august","August Epicycloidal","Misc Sph, no inv."),tt(function(t){si(t,!1,!1)},"apian","Apian Globular I","Misc Sph, no inv."),tt(function(t){si(t,!1,!0)},"ortel","Ortelius Oval","Misc Sph, no inv."),tt(function(t){si(t,!0,!1)},"bacon","Bacon Globular","Misc Sph, no inv."),tt(function(t){var e,n,r,o;t.es=0,t.fwd=function(t,h){var u,p,_,d,f,m;return t.lam+=-16.5*C,p=s(t.phi),_=s(t.lam)*p,d=i(t.lam)*p,m=(f=i(t.phi))*e+_*n,t.lam=l(d*r-m*o,_*e-f*n),m=m*r+d*o,t.phi=a(m),t.lam=Mt(t.lam),t.lam+t.phi<-1.4&&(u=(t.lam-t.phi+1.6)*(t.lam+t.phi+1.4)/8,t.lam+=u,t.phi-=.8*u*i(t.phi+w/2)),p=s(t.phi),u=c(2/(1+p*s(t.lam/2))),h.x=1.68*u*p*i(t.lam/2),h.y=u*i(t.phi),u=(1-s(t.lam*t.phi))/12,h.y<0&&(h.x*=1+u),h.y>0&&(h.y*=1+u/1.5*h.x*h.x),h},t.lam0=0,t.phi0=-42*C,e=s(t.phi0),n=i(t.phi0),r=1,o=0},"bertin1953","Bertin 1953","Misc., Sph., NoInv."),tt(function(e){var n=c(2);e.fwd=function(e,r){var a,o,h,l;if(a=e.phi,t(t(e.phi)-k)<1e-7)r.x=0;else{for(h=i(a)*w,l=20;l&&(a-=o=(a+i(a)-h)/(1+s(a)),!(t(o)<1e-7));--l);a*=.5,r.x=2.00276*e.lam/(1/s(e.phi)+1.11072/s(a))}r.y=.49931*(e.phi+n*i(a))},e.es=0},"boggs","Boggs Eumorphic","PCyl., no inv., Sph."),tt(function(e){var r,a,o,h,u,p,_=1e-10;r=X(e.params,"rlat_1"),t(r)<_&&U(-23),e.es?(u=Ze(e.es),h=Xe(r,o=i(r),p=s(r),u),o=p/(c(1-e.es*o*o)*o),e.inv=function(n,r){var a,p;p=d(n.x,n.y=o-n.y),r.phi=Je(o+h-p,e.es,u),(a=t(r.phi))<k?(a=i(r.phi),r.lam=p*l(n.x,n.y)*c(1-e.es*a*a)/s(r.phi)):t(a-k)<=_?r.lam=0:j()},e.fwd=function(t,n){var r,a,l;r=o+h-Xe(t.phi,a=i(t.phi),l=s(t.phi),u),a=l*t.lam/(r*c(1-e.es*a*a)),n.x=r*i(a),n.y=o-r*s(a)}):(a=t(r)+_>=k?0:1/n(r),e.inv=function(e,i){var n=d(e.x,e.y=a-e.y);i.phi=a+r-n,t(i.phi)>k&&j(),t(t(i.phi)-k)<=_?i.lam=0:i.lam=n*l(e.x,e.y)/s(i.phi)},e.fwd=function(e,n){var o,h;h=a+r-e.phi,t(h)>_?(n.x=h*i(o=e.lam*s(e.phi)/h),n.y=a-h*s(o)):n.x=n.y=0})},"bonne","Bonne (Werner lat_1=90)","Conic Sph&Ell\nlat_1="),tt(function(t){var e,r,o=.16666666666666666,h=.008333333333333333,u=.041666666666666664,p=.06666666666666667;t.es?(r=Ze(t.es),e=Xe(t.phi0,i(t.phi0),s(t.phi0),r),t.fwd=function(a,l){var p,_,d,f,m,y;l.y=Xe(a.phi,p=i(a.phi),f=s(a.phi),r),p=1/c(1-t.es*p*p),y=n(a.phi),_=y*y,d=a.lam*f,f*=t.es*f/(1-t.es),m=d*d,l.x=p*d*(1-m*_*(o-(8-_+8*f)*m*h)),l.y-=e-p*y*m*(.5+(5-_+6*f)*m*u)},t.inv=function(a,o){var h,l,_,d,f,m,y;y=Je(e+a.y,t.es,r),m=n(y),l=m*m,h=i(y),_=1/(1-t.es*h*h),h=c(_),_*=(1-t.es)*h,d=a.x/h,f=d*d,o.phi=y-h*m/_*f*(.5-(1+3*l)*f*u),o.lam=d*(1+l*f*((1+3*l)*f*p-.3333333333333333))/s(y)}):(t.fwd=function(e,r){r.x=a(s(e.phi)*i(e.lam)),r.y=l(n(e.phi),s(e.lam))-t.phi0},t.inv=function(e,r){var o=e.y+t.phi0;r.phi=a(i(o)*s(e.x)),r.lam=l(n(e.x),s(o))})},"cass","Cassini","Cyl, Sph&Ell"),tt(function(e){var n,r,o=0;X(e.params,"tlat_ts")&&(e.k0=s(o=X(e.params,"rlat_ts")),e.k0<0&&U(-24)),e.es?(o=i(o),e.k0/=c(1-e.es*o*o),e.e=c(e.es),(r=ni(e.es))||e_error_0(),n=We(1,e.e,e.one_es),e.fwd=function(t,s){s.x=e.k0*t.lam,s.y=.5*We(i(t.phi),e.e,e.one_es)/e.k0},e.inv=function(t,i){i.phi=ri(a(2*t.y*e.k0/n),r),i.lam=t.x/e.k0}):(e.fwd=function(t,s){s.x=e.k0*t.lam,s.y=i(t.phi)/e.k0},e.inv=function(i,s){var n,r=i.x,o=i.y;(n=t(o*=e.k0))-F<=1?(s.phi=n>=1?o<0?-k:k:a(o),s.lam=r/e.k0):j()})},"cea","Equal Area Cylindrical","Cyl, Sph&Ell\nlat_ts="),tt(function(e){var n,r,a,o,h,u,p,_=1/3,d=[];for(u=0;u<3;++u)d[u]={p:{}},d[u].phi=X(e.params,"rlat_"+(u+1)),d[u].lam=X(e.params,"rlon_"+(u+1)),d[u].lam=Mt(d[u].lam-e.lam0),d[u].cosphi=s(d[u].phi),d[u].sinphi=i(d[u].phi);for(u=0;u<3;++u)p=2==u?0:u+1,d[u].v=f(d[p].phi-d[u].phi,d[u].cosphi,d[u].sinphi,d[p].cosphi,d[p].sinphi,d[p].lam-d[u].lam),d[u].v.r||U(-25);function f(e,n,r,a,o,h){var u,p,_,d={};return u=s(h),t(e)>1||t(h)>1?d.r=Qe(cs1*o+n*a*u):(p=i(.5*e),_=i(.5*h),d.r=2*Ye(c(p*p+n*a*_*_))),t(d.r)>1e-9?d.Az=l(a*i(h),n*o-r*a*u):d.r=d.Az=0,d}function m(t,e,i){return Qe(.5*(t*t+e*e-i*i)/(t*e))}a=m(d[0].v.r,d[2].v.r,d[1].v.r),o=m(d[0].v.r,d[1].v.r,d[2].v.r),h=w-a,r=2*(d[0].p.y=d[1].p.y=d[2].v.r*i(a)),d[2].p.y=0,d[0].p.x=-(d[1].p.x=.5*d[0].v.r),n=d[2].p.x=d[0].p.x+d[2].v.r*s(a),e.es=0,e.fwd=function(t,e){var a,l,c,u,p,y,g,v=[];for(a=i(t.phi),l=s(t.phi),u=0;u<3&&(v[u]=f(t.phi-d[u].phi,d[u].cosphi,d[u].sinphi,l,a,t.lam-d[u].lam),v[u].r);++u)v[u].Az=Mt(v[u].Az-d[u].v.Az);if(u<3)y=d[u].p.x,g=d[u].p.y;else{for(y=n,g=r,u=0;u<3;++u)p=2==u?0:u+1,c=m(d[u].v.r,v[u].r,v[p].r),v[u].Az<0&&(c=-c),u?1==u?(c=o-c,y-=v[u].r*s(c),g-=v[u].r*i(c)):(c=h-c,y+=v[u].r*s(c),g+=v[u].r*i(c)):(y+=v[u].r*s(c),g-=v[u].r*i(c));y*=_,g*=_}e.x=y,e.y=g}},"chamb","Chamberlin Trimetric","Misc Sph, no inv.\nlat_1= lon_1= lat_2= lon_2= lat_3= lon_3="),tt(function(t){var e=1/3;t.inv=function(t,i){i.phi=3*a(.32573500793527993*t.y),i.lam=1.0233267079464885*t.x/(2*s((i.phi+i.phi)*e)-1)},t.fwd=function(t,n){t.phi*=e,n.x=.9772050238058398*t.lam*(2*s(t.phi+t.phi)-1),n.y=3.0699801238394655*i(t.phi)},t.es=0},"crast","Craster Parabolic (Putnins P4)","PCyl., Sph."),tt(function(t){var e=.5253,n=.7264,r=1/Math.sqrt(e*n),o=.9701,h=_(22*C),l=d(0),u=i(h),p=s(h);function _(t){return a(n*i(t)+.4188*c(e*n))}function d(t){return e*t}X(t.params,"tlon_0")||(t.lam0=11.023*C),t.es=0,t.fwd=function(t,e){var n=_(t.phi),a=d(t.lam),f=i(n),m=s(n),y=i(a-l),g=s(a-l),v=c(2/(1+i(h)*f+p*m*g));e.x=r*v*m*y*o,e.y=r*v*(p*f-u*m*g)/o}},"cupola","Cupola","PCyl., Sph., NoInv."),tt(function(e){e.fwd=function(e,i){var n=t(e.lam);i.y=e.phi,i.x=e.lam,i.x*=s((.95+n*(n*n*.0016666666666666666-.08333333333333333))*(e.phi*(.9+.03*e.phi*e.phi*e.phi*e.phi)))},e.es=0},"denoy","Denoyer Semi-Elliptical","PCyl, Sph., no inv."),tt(function(e){var i=.9213177319235613,s=.3183098861837907;e.es=0,e.fwd=function(e,n){n.x=i*e.lam*(1-s*t(e.phi)),n.y=i*e.phi},e.inv=function(e,n){n.phi=e.y/i,n.lam=e.x/(i*(1-s*t(n.phi)))}},"eck1","Eckert I","PCyl Sph"),tt(function(e){var s=.46065886596178063,n=1.4472025091165353;e.es=0,e.fwd=function(e,r){r.x=s*e.lam*(r.y=c(4-3*i(t(e.phi)))),r.y=n*(2-r.y),e.phi<0&&(r.y=-r.y)},e.inv=function(e,i){i.lam=e.x/(s*(i.phi=2-t(e.y)/n)),i.phi=.3333333333333333*(4-i.phi*i.phi),t(i.phi)>=1?t(i.phi)>1.0000001?j():i.phi=i.phi<0?-k:k:i.phi=a(i.phi),e.y<0&&(i.phi=-i.phi)}},"eck2","Eckert II","PCyl Sph"),tt(function(t){ai(t,{C_x:.4222382003157712,C_y:.8444764006315424,A:1,B:.4052847345693511})},"eck3","Eckert III","PCyl Sph"),tt(function(t){ai(t,{C_x:.94745,C_y:.94745,A:0,B:.3039635509270133})},"wag6","Wagner VI","PCyl Sph"),tt(function(t){ai(t,{C_x:.8660254037844,C_y:1,A:0,B:.3039635509270133})},"kav7","Kavraisky VII","PCyl Sph"),tt(function(t){ai(t,{C_x:1.8949,C_y:.94745,A:-.5,B:.3039635509270133})},"putp1","Putnins P1","PCyl Sph"),tt(function(e){var n=.4222382003157712,r=1.3265004281770023,a=3.5707963267948966;e.es=0,e.fwd=function(e,o){var h,l,c,u,p;for(h=a*i(e.phi),l=e.phi*e.phi,e.phi*=.895168+l*(.0218849+.00826809*l),p=6;p&&(u=s(e.phi),c=i(e.phi),e.phi-=l=(e.phi+c*(u+2)-h)/(1+u*(u+2)-c*c),!(t(l)<1e-7));--p);p?(o.x=n*e.lam*(1+s(e.phi)),o.y=r*i(e.phi)):(o.x=n*e.lam,o.y=e.phi<0?-r:r)},e.inv=function(t,e){var o;e.phi=Ye(t.y/r),e.lam=t.x/(n*(1+(o=s(e.phi)))),e.phi=Ye((e.phi+i(e.phi)*(o+2))/a)}},"eck4","Eckert IV","PCyl Sph"),tt(function(t){t.es=0,t.fwd=function(t,e){e.x=.4410127717245515*(1+s(t.phi))*t.lam,e.y=.882025543449103*t.phi},t.inv=function(t,e){e.lam=2.267508027238226*t.x/(1+s(e.phi=1.133754013619113*t.y))}},"eck5","Eckert V","PCyl Sph"),tt(function(t){var e=s(X(t.params,"rlat_ts"));e<=0&&U(-24),t.es=0,t.fwd=function(i,s){s.x=e*i.lam,s.y=i.phi-t.phi0},t.inv=function(i,s){s.lam=i.x/e,s.phi=i.y+t.phi0}},"eqc","Equidistant Cylindrical (Plate Caree)","Cyl, Sph\nlat_ts=[, lat_0=0]"),tt(function(e){var n,r,a,o,h,c,u,p,_,f,m,y,g;n=X(e.params,"rlat_1"),r=X(e.params,"rlat_2"),t(n+r)<F&&U(-21),(u=Ze(e.es))||e_error_0(),a=f=i(n),_=s(n),m=t(n-r)>=F,(p=e.es>0)?(g=He(f,_,e.es),y=Xe(n,f,_,u),m&&(f=i(r),_=s(r),a=(g-He(f,_,e.es))/(Xe(r,f,_,u)-y)),h=(c=y+g/a)-Xe(e.phi0,i(e.phi0),s(e.phi0),u)):(m&&(a=(_-s(r))/(r-n)),c=n+s(n)/a,h=c-e.phi0),e.fwd=function(t,e){o=c-(p?Xe(t.phi,i(t.phi),s(t.phi),u):t.phi),e.x=o*i(t.lam*=a),e.y=h-o*s(t.lam)},e.inv=function(t,i){0!=(o=d(t.x,t.y=h-t.y))?(a<0&&(o=-o,t.x=-t.x,t.y=-t.y),i.phi=c-o,p&&(i.phi=Je(i.phi,e.es,u)),i.lam=l(t.x,t.y)/a):(i.lam=0,i.phi=a>0?k:-k)}},"eqdc","Equidistant Conic","Conic, Sph&Ell\nlat_1= lat_2="),tt(function(t){var e=1.340264,i=-.081106,s=893e-6,n=.003796,r=Math.sqrt(3)/2;t.es=0,t.fwd=function(t,a){var o=Math.asin(r*Math.sin(t.phi)),h=o*o,l=h*h*h;a.x=t.lam*Math.cos(o)/(r*(e+3*i*h+l*(7*s+9*n*h))),a.y=o*(e+i*h+l*(s+n*h))},t.inv=function(t,a){var o,h,l,c,u=t.y;for(c=0;c<12&&(u-=l=(u*(e+i*(o=u*u)+(h=o*o*o)*(s+n*o))-t.y)/(e+3*i*o+h*(7*s+9*n*o)),!(Math.abs(l)<1e-9));++c);h=(o=u*u)*o*o,a.lam=r*t.x*(e+3*i*o+h*(7*s+9*n*o))/Math.cos(u),a.phi=Math.asin(Math.sin(u)/r)}},"eqearth","Equal Earth","PCyl., Sph."),tt(oi,"etmerc","Extended Transverse Mercator","Cyl, Sph\nlat_ts=(0)\nlat_0=(0)"),tt(function(t){t.fwd=function(t,e){e.x=.7071067811865476*t.lam,e.y=1.7071067811865475*n(.5*t.phi)},t.inv=function(t,e){e.lam=1.4142135623730951*t.x,e.phi=2*h(.585786437626905*t.y)},t.es=0},"gall","Gall (Gall Stereographic)","Cyl, Sph"),tt(function(t){t.is_geocent=!0,t.x0=0,t.y0=0,t.fwd=function(t,e){e.x=t.lam,e.y=t.phi},t.inv=function(t,e){e.phi=t.y,e.lam=t.x}},"geocent","Geocentric",""),tt(function(t){var e,r,a,o,u,p,_,f=X(t.params,"dh"),m=X(t.params,"ssweep");m?"x"==m?_=1:"y"==m?_=0:U(-49):_=0,((u=f/t.a)<=0||u>1e10)&&U(-50),p=(o=1+u)*o-1,0!=t.es?(e=c(t.one_es),r=t.one_es,a=t.rone_es,t.inv=function(t,i){var r,f,m,y,g,v;r=-1,_?(m=n(t.y/u),f=n(t.x/u)*d(1,m)):(f=n(t.x/u),m=n(t.y/u)*d(1,f));var x=(g=2*o*r)*g-4*(y=f*f+(y=m/e)*y+r*r)*p;x<0&&U(-51),v=(-g-c(x))/(2*y),r=o+v*r,f*=v,m*=v,i.lam=l(f,r),i.phi=h(m*s(i.lam)/r),i.phi=h(a*n(i.phi))},t.fwd=function(t,l){var c,p,f,m,y;t.phi=h(r*n(t.phi)),c=e/d(e*s(t.phi),i(t.phi)),p=c*s(t.lam)*s(t.phi),f=c*i(t.lam)*s(t.phi),m=c*i(t.phi),(o-p)*p-f*f-m*m*a<0&&U(-51),y=o-p,_?(l.x=u*h(f/d(m,y)),l.y=u*h(m/y)):(l.x=u*h(f/y),l.y=u*h(m/d(f,y)))}):(e=r=a=1,t.inv=function(t,e){var i,r,a,d,f,m;i=-1,_?(a=n(t.y/u),r=n(t.x/u)*c(1+a*a)):(r=n(t.x/u),a=n(t.y/u)*c(1+r*r));var y=(f=2*o*i)*f-4*(d=r*r+a*a+i*i)*p;y<0&&U(-51),m=(-f-c(y))/(2*d),i=o+m*i,r*=m,a*=m,e.lam=l(r,i),e.phi=h(a*s(e.lam)/i)},t.fwd=function(t,e){var n=s(t.phi),r=s(t.lam)*n,a=i(t.lam)*n,l=i(t.phi);n=o-r,_?(e.x=u*h(a/d(l,n)),e.y=u*h(l/n)):(e.x=u*h(a/n),e.y=u*h(l/d(a,n)))})},"geos","Geostationary Satellite View","Azi, Sph&Ell"),tt(function(t){var e=o(X(t.params,"tlat_1")?X(t.params,"rlat_1"):0),r=i(e),a=s(e);function o(t){return Ye(n(.5*t))}t.fwd=function(t,e){var n=.5*t.lam,h=o(t.phi),l=i(h),c=s(h),u=s(n);r*l+a*c*u>=0?(e.x=c*i(n),e.y=a*l-r*c*u):q()},t.es=0},"gilbert","Gilbert Two World Perspective","PCyl., Sph., NoInv.\nlat_1="),tt(function(t){t.fwd=function(t,e){var i=t.phi*t.phi;e.y=t.phi*(1+.08333333333333333*i),e.x=t.lam*(1-.162388*i),i=t.lam*t.lam,e.x*=.87-952426e-9*i*i},t.es=0},"gins8","Ginsburg VIII (TsNIIGAiK)","PCyl, Sph., no inv."),tt(function(t){X(t.params,"tn"),X(t.params,"tm")?li(t,X(t.params,"dm"),X(t.params,"dn")):U(-99)},"gn_sinu","General Sinusoidal Series","PCyl, Sph.\nm= n="),tt(hi,"sinu","Sinusoidal (Sanson-Flamsteed)","PCyl, Sph&Ell"),tt(function(t){li(t,1,2.5707963267948966)},"eck6","Eckert VI","PCyl, Sph.\nm= n="),tt(function(t){li(t,.5,1.7853981633974483)},"mbtfps","McBryde-Thomas Flat-Polar Sinusoidal","PCyl, Sph."),tt(function(e){var n,r,o=1e-10;t(t(e.phi0)-k)<o?r=e.phi0<0?1:0:t(e.phi0)<o?r=2:(r=3,sinph0=i(e.phi0),n=s(e.phi0)),e.inv=function(s,u){var p,_,f,m=s.x,y=s.y;if(p=d(m,y),f=i(u.phi=h(p)),_=c(1-f*f),t(p)<=o)u.phi=e.phi0,u.lam=0;else{switch(r){case 3:u.phi=_*sinph0+y*f*n/p,t(u.phi)>=1?u.phi=u.phi>0?k:-k:u.phi=a(u.phi),y=(_-sinph0*i(u.phi))*p,m*=f*n;break;case 2:u.phi=y*f/p,t(u.phi)>=1?u.phi=u.phi>0?k:-k:u.phi=a(u.phi),y=_*p,m*=f;break;case 1:u.phi-=k;break;case 0:u.phi=k-u.phi,y=-y}u.lam=l(m,y)}},e.fwd=function(t,e){var a,h,l;switch(l=i(t.phi),h=s(t.phi),a=s(t.lam),r){case 2:e.y=h*a;break;case 3:e.y=sinph0*l+n*h*a;break;case 1:e.y=-l;break;case 0:e.y=l}switch(e.y<=o&&q(),e.x=(e.y=1/e.y)*h*i(t.lam),r){case 2:e.y*=l;break;case 3:e.y*=n*l-sinph0*h*a;break;case 0:a=-a;case 1:e.y*=h*a}},e.es=0},"gnom","Gnomonic","Azi, Sph."),tt(ci,"moll","Mollweide","PCyl Sph"),tt(function(t){pi(t,ui(0,w/3))},"wag4","Wagner IV","PCyl Sph"),tt(function(t){pi(t,{C_x:.90977,C_y:1.65014,C_p:3.00896})},"wag5","Wagner V","PCyl Sph"),tt(function(e){var i,s,n,r,a=.0528,o=.7109307819790236;e.es=0,hi(e),i=e.fwd,s=e.inv,ci(e),n=e.fwd,r=e.inv,e.fwd=function(e,s){t(e.phi)<o?i(e,s):(n(e,s),s.y-=e.phi>0?a:-a)},e.inv=function(e,i){t(e.y)<=o?s(e,i):(e.y+=e.y>0?a:-a,r(e,i))}},"goode","Goode Homolosine","PCyl, Sph."),tt(function(e){var n,r,a;e.inv=function(e,i){var s=c(1-.25*n*n*e.x*e.x-.25*e.y*e.y);t(2*s*s-1)<1e-10?(i.lam=x,i.phi=x,pj_errno=-14):(i.lam=ei(n*e.x*s,2*s*s-1)/n,i.phi=Ye(s*e.y))},e.fwd=function(t,e){var o,h;h=c(2/(1+(o=s(t.phi))*s(t.lam*=n))),e.x=r*h*o*i(t.lam),e.y=a*h*i(t.phi)},e.es=0,X(e.params,"tW")?(n=t(X(e.params,"dW")))<=0&&U(-27):n=.5,X(e.params,"tM")?(r=t(X(e.params,"dM")))<=0&&U(-27):r=1,a=1/r,r/=n},"hammer","Hammer & Eckert-Greifendorff","Misc Sph,\nW= M="),tt(function(e){var n=1.000001;e.inv=function(e,r){var o=e.y*(e.y<0?.5179951515653813:.5686373742600607);t(o)>1?t(o)>n?j():o=o>0?k:-k:o=a(o),r.lam=1.1764705882352942*e.x/s(o),o+=o,r.phi=(o+i(o))*(e.y<0?.4102345310814193:.3736990601468637),t(r.phi)>1?t(r.phi)>n?j():r.phi=r.phi>0?k:-k:r.phi=a(r.phi)},e.fwd=function(e,n){var r,a,o;for(a=i(e.phi)*(e.phi<0?2.43763:2.67595),o=20;o&&(e.phi-=r=(e.phi+i(e.phi)-a)/(1+s(e.phi)),!(t(r)<1e-7));--o);n.x=.85*e.lam*s(e.phi*=.5),n.y=i(e.phi)*(e.phi<0?1.93052:1.75859)},e.es=0},"hatano","Hatano Asymmetrical Equal Area","PCyl., Sph."),tt(_i,"healpix","HEALPix","Sph., Ellps."),tt(function(t){_i(t,!0)},"rhealpix","rHEALPix","Sph., Ellps.\nnorth_square= south_square="),tt(function(e){var n,r=i(.5),h=a(r),u=2*c(w/(n=w+4*h*2)),p=.5*u*(2+c(3));e.es=0,e.fwd=function(e,r){var a,o,_=1-i(e.phi);if(_&&_<2){var d,f,m,y,g,v=k-e.phi,x=25;do{f=i(v),m=s(v),g=h+l(f,2-m),v-=d=(v-1*h-2*f+(y=5-4*m)*g-.5*_*n)/(4*f*g)}while(t(d)>1e-12&&--x>0);a=u*c(y),o=e.lam*g/w}else a=u*(1+_),o=e.lam*h/w;r.x=a*i(o),r.y=p-a*s(o)},e.inv=function(t,e){var s=t.x,r=t.y,_=s*s+(r-=p)*r,d=(5-_/(u*u))/4,f=o(d),m=i(f),y=h+l(m,2-d);e.lam=a(s/c(_))*w/y,e.phi=a(1-2*(f-1*h-2*m+(5-4*d)*y)/n)}},"hill","Hill Eucyclic","PCyl., Sph."),tt(function(e){var r,o,p,_,d,f,m,y,g,v=.785398163397448,x=1.37008346281555;e.a=6377397.155,e.e=c(e.es=.006674372230614),X(e.params,"tlat_0")||(e.phi0=.863937979737193),X(e.params,"tlon_0")||(e.lam0=.4334234309119251),X(e.params,"tk")||(e.k0=.9999),g=1,X(e.params,"tczech")||(g=-1),_=c(1+e.es*u(s(e.phi0),4)/(1-e.es)),r=a(i(e.phi0)/_),p=u((1+e.e*i(e.phi0))/(1-e.e*i(e.phi0)),_*e.e/2),d=n(r/2+v)/u(n(e.phi0/2+v),_)*p,o=c(1-e.es)/(1-e.es*u(i(e.phi0),2)),f=i(x),m=e.k0*o/n(x),y=.5286277629901559,e.inv=function(r,o){var p,b,w,S,C,A,E,M;E=r.x,r.x=r.y,r.y=E,r.x*=g,r.y*=g,C=c(r.x*r.x+r.y*r.y),S=l(r.y,r.x)/i(x),w=2*(h(u(m/C,1/f)*n(x/2+v))-v),p=a(s(y)*i(w)-i(y)*s(w)*s(S)),b=a(s(w)*i(S)/s(p)),o.lam=e.lam0-b/_,A=p,M=0;do{o.phi=2*(h(u(d,-1/_)*u(n(p/2+v),1/_)*u((1+e.e*i(A))/(1-e.e*i(A)),e.e/2))-v),t(A-o.phi)<1e-15&&(M=1),A=o.phi}while(0===M);o.lam-=e.lam0},e.fwd=function(t,r){var o,l,c,p,b,w,S;o=u((1+e.e*i(t.phi))/(1-e.e*i(t.phi)),_*e.e/2),l=2*(h(d*u(n(t.phi/2+v),_)/o)-v),c=-t.lam*_,p=a(s(y)*i(l)+i(y)*s(l)*s(c)),b=a(s(l)*i(c)/s(p)),w=f*b,S=m*u(n(x/2+v),f)/u(n(p/2+v),f),r.y=S*s(w),r.x=S*i(w),r.y*=g,r.x*=g}},"krovak","Krovak","PCyl., Ellps."),tt(function(e){var n,r,o,h,u,p,_,f,m,y,g,v=1e-10;if(y=t(e.phi0),m=t(y-k)<v?e.phi0<0?1:0:t(y)<v?2:3,e.es){switch(e.e=c(e.es),u=We(1,e.e,e.one_es),e.es,f=ni(e.es),m){case 0:case 1:p=1;break;case 2:p=1/(_=c(.5*u)),o=1,h=.5*u;break;case 3:_=c(.5*u),g=i(e.phi0),n=We(g,e.e,e.one_es)/u,r=c(1-n*n),p=s(e.phi0)/(c(1-e.es*g*g)*_*r),h=(o=_)/p,o*=p}e.inv=function(t,o){var h,c,y,g,x=0;switch(m){case 2:case 3:if(t.x/=p,t.y*=p,(g=d(t.x,t.y))<v)return o.lam=0,o.phi=e.phi0,o;c=2*a(.5*g/_),h=s(c),c=i(c),t.x*=c,3==m?(x=h*n+t.y*c*r/g,t.y=g*r*h-t.y*n*c):(x=t.y*c/g,t.y=g*h);break;case 0:t.y=-t.y;case 1:if(!(y=t.x*t.x+t.y*t.y))return o.lam=0,o.phi=e.phi0,o;x=1-y/u,1==m&&(x=-x)}return o.lam=l(t.x,t.y),o.phi=ri(a(x),f),o},e.fwd=function(a,l){var p,_,d,f,y=0,g=0,x=0;switch(p=s(a.lam),_=i(a.lam),d=i(a.phi),f=We(d,e.e,e.one_es),(3==m||2==m)&&(g=c(1-(y=f/u)*y)),m){case 3:x=1+n*y+r*g*p;break;case 2:x=1+g*p;break;case 0:x=k+a.phi,f=u-f;break;case 1:x=a.phi-k,f=u+f}switch(t(x)<v&&q(),m){case 3:case 2:3==m?(x=c(2/x),l.y=h*x*(r*y-n*g*p)):(x=c(2/(1+g*p)),l.y=x*y*h),l.x=o*x*g*_;break;case 0:case 1:f>=0?(x=c(f),l.x=x*_,l.y=p*(1==m?x:-x)):l.x=l.y=0}}}else 3==m&&(n=i(e.phi0),r=s(e.phi0)),e.inv=function(o,h){var c,u=0,p=0;switch(c=d(o.x,o.y),(h.phi=.5*c)>1&&j(),h.phi=2*a(h.phi),(3==m||2==m)&&(p=i(h.phi),u=s(h.phi)),m){case 2:h.phi=t(c)<=v?0:a(o.y*p/c),o.x*=p,o.y=u*c;break;case 3:h.phi=t(c)<=v?e.phi0:a(u*n+o.y*p*r/c),o.x*=p*r,o.y=(u-i(h.phi)*n)*c;break;case 0:o.y=-o.y,h.phi=k-h.phi;break;case 1:h.phi-=k}h.lam=0!=o.y||2!=m&&3!=m?l(o.x,o.y):0},e.fwd=function(a,o){var h,l,u;switch(u=i(a.phi),l=s(a.phi),h=s(a.lam),m){case 2:case 3:o.y=2==m?1+l*h:1+n*u+r*l*h,o.y<=v&&q(),o.y=c(2/o.y),o.x=o.y*l*i(a.lam),o.y*=2==m?u:r*u-n*l*h;break;case 0:h=-h;case 1:t(a.phi+e.phi0)<v&&q(),o.y=M-.5*a.phi,o.y=2*(1==m?s(o.y):i(o.y)),o.x=o.y*i(a.lam),o.y*=h}}},"laea","Lambert Azimuthal Equal Area","Azi, Sph&Ell"),tt(di,"lonlat","Lat/long (Geodetic)",""),tt(di,"longlat","Lat/long (Geodetic alias)",""),tt(di,"latlon","Lat/long (Geodetic alias)",""),tt(di,"latlong","Lat/long (Geodetic alias)",""),tt(function(e){var r,a,o,p,f,m,y,g,v,b,w,S=1e-10;e.inv=function(t,i){var s,n=t.x,r=t.y;n/=e.k0,r/=e.k0,0!=(s=d(n,r=y-r))?(m<0&&(s=-s,n=-n,r=-r),v?(i.phi=mi(u(s/g,1/m),e.e),i.phi==x&&j()):i.phi=2*h(u(g/s,1/m))-k,i.lam=l(n,r)/m):(i.lam=0,i.phi=m>0?k:-k)},e.fwd=function(r,a){var o,h=r.lam;t(t(r.phi)-k)<S?(r.phi*m<=0&&q(),o=0):o=g*(v?u(fi(r.phi,i(r.phi),e.e),m):u(n(M+.5*r.phi),-m)),h*=m,a.x=e.k0*(o*i(h)),a.y=e.k0*(y-o*s(h))},p=X(e.params,"rlat_1"),X(e.params,"tlat_2")?f=X(e.params,"rlat_2"):(f=p,X(e.params,"tlat_0")||(e.phi0=p)),t(p+f)<S&&U(-21),m=a=i(p),r=s(p),o=t(p-f)>=S,(v=0!=e.es)?(e.e=c(e.es),w=He(a,r,e.es),b=fi(p,a,e.e),o&&(a=i(f),m=_(w/He(a,s(f),e.es)),m/=_(b/fi(f,a,e.e))),g=y=w*u(b,-m)/m,y*=t(t(e.phi0)-k)<S?0:u(fi(e.phi0,i(e.phi0),e.e),m)):(o&&(m=_(r/s(f))/_(n(M+.5*f)/n(M+.5*p))),g=r*u(n(M+.5*p),m)/m,y=t(t(e.phi0)-k)<S?0:g*u(n(M+.5*e.phi0),-m))},"lcc","Lambert Conformal Conic","Conic, Sph&Ell\nlat_1= and lat_2= or lat_0="),tt(function(e){var i,r,a,o=1e-8;i=X(e.params,"rlat_1"),r=s(i),a=n(M+.5*i),r<o&&U(-22),e.fwd=function(e,s){s.y=e.phi-i,t(s.y)<o?s.x=e.lam*r:(s.x=M+.5*e.phi,t(s.x)<o||t(t(s.x)-k)<o?s.x=0:s.x=e.lam*s.y/_(n(s.x)/a))},e.inv=function(e,s){s.phi=e.y+i,t(e.y)<o?s.lam=e.x/r:(s.lam=M+.5*s.phi,t(s.lam)<o||t(t(s.lam)-k)<o?s.lam=0:s.lam=e.x*_(n(s.lam)/a)/e.y)},e.es=0},"loxim","Loximuthal","PCyl Sph"),tt(function(e){var n=.9525793444156804,r=.9258200997725514,o=3.401680257083045,h=2/3,l=1/3,c=1.0000001;e.fwd=function(t,e){t.phi=a(n*i(t.phi)),e.x=r*t.lam*(2*s(h*t.phi)-1),e.y=o*i(l*t.phi)},e.inv=function(e,l){l.phi=e.y/o,t(l.phi)>=1?t(l.phi)>c?j():l.phi=l.phi<0?-k:k:l.phi=a(l.phi),l.lam=e.x/(r*(2*s(h*(l.phi*=3))-1)),t(l.phi=i(l.phi)/n)>=1?t(l.phi)>c?j():l.phi=l.phi<0?-k:k:l.phi=a(l.phi)},e.es=0},"mbt_fpp","McBride-Thomas Flat-Polar Parabolic","Cyl., Sph."),tt(function(e){var n=1.000001;e.fwd=function(e,n){var r,a,o;for(a=1.7071067811865475*i(e.phi),o=20;o&&(e.phi-=r=(i(.5*e.phi)+i(e.phi)-a)/(.5*s(.5*e.phi)+s(e.phi)),!(t(r)<1e-7));--o);n.x=.3124597141037825*e.lam*(1+2*s(e.phi)/s(.5*e.phi)),n.y=1.874758284622695*i(.5*e.phi)},e.inv=function(e,r){var o;r.phi=.533402096794177*e.y,t(r.phi)>1?t(r.phi)>n?j():r.phi<0?(o=-1,r.phi=-w):(o=1,r.phi=w):r.phi=2*a(o=r.phi),r.lam=3.2004125807650623*e.x/(1+2*s(r.phi)/s(.5*r.phi)),r.phi=.585786437626905*(o+i(r.phi)),t(r.phi)>1?t(r.phi)>n?j():r.phi=r.phi<0?-k:k:r.phi=a(r.phi)},e.es=0},"mbt_fpq","McBryde-Thomas Flat-Polar Quartic","Cyl., Sph."),tt(function(e){var n=.45503,r=1.36509,a=1.41546,o=.22248,h=1.44492,l=1/3;e.fwd=function(e,c){var u,p,_,d;for(u=a*i(e.phi),d=10;d&&(_=e.phi/r,e.phi-=p=(n*i(_)+i(e.phi)-u)/(l*s(_)+s(e.phi)),!(t(p)<1e-7));--d);_=e.phi/r,c.x=o*e.lam*(1+3*s(e.phi)/s(_)),c.y=h*i(_)},e.inv=function(t,e){var l;e.phi=r*(l=Ye(t.y/h)),e.lam=t.x/(o*(1+3*s(e.phi)/s(l))),e.phi=Ye((n*i(l)+i(e.phi))/a)},e.es=0},"mbt_fps","McBryde-Thomas Flat-Pole Sine (No. 2)","Cyl., Sph."),tt(function(e){var r=1e-10,a=0,o=X(e.params,"tlat_ts");o&&(a=X(e.params,"rlat_ts"))>=k&&U(-24),e.es?(o&&(e.k0=He(i(a),s(a),e.es)),e.inv=function(t,i){i.phi=mi(p(-t.y/e.k0),e.e),i.phi===x&&j(),i.lam=t.x/e.k0},e.fwd=function(s,n){t(t(s.phi)-k)<=r&&q(),n.x=e.k0*s.lam,n.y=-e.k0*_(fi(s.phi,i(s.phi),e.e))}):(e.inv=function(t,i){i.phi=k-2*h(p(-t.y/e.k0)),i.lam=t.x/e.k0},e.fwd=function(i,s){t(t(i.phi)-k)<=r&&q(),s.x=e.k0*i.lam,s.y=e.k0*_(n(M+.5*i.phi))})},"merc","Mercator","Cyl, Sph&Ell\nlat_ts="),tt(function(e){e.k0=1,e.inv=function(t,i){i.phi=k-2*h(p(-t.y/e.k0)),i.lam=t.x/e.k0},e.fwd=function(i,s){t(t(i.phi)-k)<=F&&q(),s.x=e.k0*i.lam,s.y=e.k0*_(n(M+.5*i.phi))}},"webmerc","Web Mercator / Pseudo Mercator","Cyl, Ell"),tt(function(t){t.fwd=function(t,e){e.x=t.lam,e.y=1.25*_(n(M+.4*t.phi))},t.inv=function(t,e){e.lam=t.x,e.phi=2.5*(h(p(.8*t.y))-M)},t.es=0},"mill","Miller Cylindrical","Cyl, Sph"),tt(function(t){t.lam0=20*C,t.phi0=18*C,t.es=0,vi(t,[[.9245,0],[0,0],[.01943,0]])},"mil_os","Miller Oblated Stereographic","Azi(mod)"),tt(function(t){t.lam0=-165*C,t.phi0=-10*C,t.es=0,vi(t,[[.721316,0],[0,0],[-.0088162,-.00617325]])},"lee_os","Lee Oblated Stereographic","Azi(mod)"),tt(function(t){t.lam0=-96*C,t.phi0=39*C,t.es=0,t.a=6370997,vi(t,[[.98879,0],[0,0],[-.050909,0],[0,0],[.075528,0]])},"gs48","Mod Stereographic of 48 U.S.","Azi(mod)"),tt(function(t){var e;t.lam0=-152*C,t.phi0=64*C,0!=t.es?(e=[[.9945303,0],[.0052083,-.0027404],[.0072721,.0048181],[-.0151089,-.1932526],[.0642675,-.1381226],[.3582802,-.2884586]],t.a=6378206.4,t.e=c(t.es=.00676866)):(e=[[.9972523,0],[.0052513,-.0041175],[.0074606,.0048125],[-.0153783,-.1968253],[.0636871,-.1408027],[.3660976,-.2937382]],t.a=6370997),vi(t,e)},"alsk","Mod Stereographic of Alaska","Azi(mod)"),tt(function(t){var e;t.lam0=-120*C,t.phi0=45*C,0!=t.es?(e=[[.9827497,0],[.0210669,.0053804],[-.1031415,-.0571664],[-.0323337,-.0322847],[.0502303,.1211983],[.0251805,.0895678],[-.0012315,-.1416121],[.0072202,-.1317091],[-.0194029,.0759677],[-.0210072,.0834037]],t.a=6378206.4,t.e=c(t.es=.00676866)):(e=[[.984299,0],[.0211642,.0037608],[-.1036018,-.0575102],[-.0329095,-.0320119],[.0499471,.1223335],[.026046,.0899805],[7388e-7,-.1435792],[.0075848,-.1334108],[-.0216473,.0776645],[-.0225161,.0853673]],t.a=6370997),vi(t,e)},"gs50","Mod Stereographic of 50 U.S.","Azi(mod)"),tt(function(e){var i=.8707,s=-.131979,n=-.013791,r=.003971,a=-.001529,o=1.007226,h=.015085,l=-.044475,c=.028874,u=-.005916,p=o,_=3*h,d=7*l,f=9*c,m=11*u,y=.8707*.52*w;e.es=0,e.fwd=function(t,e){var p,_;_=(p=t.phi*t.phi)*p,e.x=t.lam*(i+p*(s+p*(n+_*p*(r+p*a)))),e.y=t.phi*(o+p*(h+_*(l+c*p+u*_)))},e.inv=function(e,g){var v,x,b,w,S=e.x,C=e.y;for(C>y?C=y:C<-y&&(C=-y),v=C;v-=x=(v*(o+(b=v*v)*(h+(w=b*b)*(l+c*b+u*w)))-C)/(p+b*(_+w*(d+f*b+m*w))),!(t(x)<1e-11););g.phi=v,b=v*v,g.lam=S/(i+b*(s+b*(n+b*b*b*(r+b*a))))}},"natearth","Natural Earth","PCyl., Sph."),tt(function(e){var i=.84719,s=-.13063,n=-.04515,r=.05494,a=-.02326,o=.00331,h=1.01183,l=-.02625,c=.01926,u=-.00396,p=h,_=9*l,d=.45334622460635143*w;e.es=0,e.fwd=function(t,e){var p,_,d;d=(p=t.phi*t.phi)*(_=p*p),e.x=t.lam*(i+s*p+d*d*(n+r*p+a*_+o*d)),e.y=t.phi*(h+_*_*(l+c*p+u*_))},e.inv=function(e,f){var m,y,g,v,x,b=e.x,w=e.y;for(w>d?w=d:w<-d&&(w=-d),m=w;m-=y=(m*(h+(v=(g=m*m)*g)*v*(l+c*g+u*v))-w)/(p+v*v*(_+.21186*g+-.05148*v)),!(t(y)<1e-11););f.phi=m,x=(g=m*m)*(v=g*g),f.lam=b/(i+s*g+x*x*(n+r*g+a*v+o*x))}},"natearth2","Natural Earth 2","PCyl., Sph."),tt(function(e){e.inv=function(t,e){e.lam=2*t.x/(1+s(t.y)),e.phi=Ye(.5*(t.y+i(t.y)))},e.fwd=function(e,n){var r,a,o;for(r=2*i(e.phi),a=e.phi*e.phi,e.phi*=1.00371+a*(-.011412*a-.0935382),o=10;o&&(e.phi-=a=(e.phi+i(e.phi)-r)/(1+s(e.phi)),!(t(a)<1e-7));--o);n.x=.5*e.lam*(1+s(e.phi)),n.y=e.phi},e.es=0},"nell","Nell","PCyl., Sph."),tt(function(e){e.es=0,e.fwd=function(t,e){e.x=.5*t.lam*(1+s(t.phi)),e.y=2*(t.phi-n(.5*t.phi))},e.inv=function(e,i){var r,a,o,h;for(o=.5*e.y,h=9;h>0&&(a=s(.5*i.phi),i.phi-=r=(i.phi-n(i.phi/2)-o)/(1-.5/(a*a)),!(t(r)<1e-7));--h);h?i.lam=2*e.x/(1+s(i.phi)):(i.phi=o<0?-k:k,i.lam=2*e.x)}},"nell_h","Nell-Hammer","PCyl., Sph."),tt(function(e){e.es=0,e.fwd=function(e,n){var r=1e-10;if(t(e.lam)<r)n.x=0,n.y=e.phi;else if(t(e.phi)<r)n.x=e.lam,n.y=0;else if(t(t(e.lam)-k)<r)n.x=e.lam*s(e.phi),n.y=k*i(e.phi);else if(t(t(e.phi)-k)<r)n.x=0,n.y=e.phi;else{var a=k/e.lam-e.lam/k,o=e.phi/k,h=i(e.phi),l=(1-o*o)/(h-o),u=a/l,p=(a*h/l-.5*a)/(1+(u*=u)),_=(h/u+.5*l)/(1+1/u);n.x=s(e.phi),n.x=c(p*p+n.x*n.x/(1+u)),n.x=k*(p+(e.lam<0?-n.x:n.x)),n.y=c(_*_-(h*h/u+l*h-1)/(1+1/u)),n.y=k*(_+(e.phi<0?n.y:-n.y))}}},"nicol","Nicolosi Globular","Misc Sph, no inv"),tt(function(t){xi(t,X(t.params,"dh"))},"nsper","Near-sided perspective","Azi, Sph\nh="),tt(function(t){var e=X(t.params,"dtilt")*C,i=X(t.params,"dazi")*C,s=X(t.params,"dh");xi(t,s,e,i)},"tpers","Tilted perspective","Azi, Sph\ntilt= azi= h="),tt(function(e){var i=[[.7557853228,0],[.249204646,.003371507],[-.001541739,.04105856],[-.10162907,.01727609],[-.26623489,-.36249218],[-.6870983,-1.1651967]],s=[1.5627014243,.5185406398,-.03333098,-.1052906,-.0368594,.007317,.0122,.00394,-.0013],n=[.6399175073,-.1358797613,.063294409,-.02526853,.0117879,-.0055161,.0026906,-.001333,67e-5,-34e-5];e.ra=1/(e.a=6378388),e.lam0=173*C,e.phi0=-41*C,e.x0=251e4,e.y0=6023150,e.inv=function(n,r){var a,o,h,l,c,u,p={r:n.y,i:n.x},_={};for(a=20;a>0&&((c=gi(p,i,_)).r-=n.y,c.i-=n.x,u=_.r*_.r+_.i*_.i,p.r+=h=-(c.r*_.r+c.i*_.i)/u,p.i+=l=-(c.i*_.r-c.r*_.i)/u,!(t(h)+t(l)<=1e-10));--a);if(a>0){for(r.lam=p.i,o=s.length-1,r.phi=s[o],--o;o>=0;--o)r.phi=s[o]+p.r*r.phi;r.phi=e.phi0+p.r*r.phi*.484813681109536}else r.lam=r.phi=x},e.fwd=function(t,s){var r=n.length-1,a={r:n[r]},o=2.0626480624709638*(t.phi-e.phi0);for(--r;r>=0;--r)a.r=n[r]+o*a.r;a.r*=o,a.i=t.lam,a=yi(a,i),s.x=a.i,s.y=a.r}},"nzmg","New Zealand Map Grid","fixed Earth"),tt(function(e){var r,a,o,c,u,p,_,d,f,m,y,g,v,b,w,A=1e-10;r=X(e.params,"so_proj"),a=Q[r],r||U(-26),a&&"ob_tran"!=r||U(-37),e.es=0,o={},Object.keys(e).forEach(function(t){o[t]=e[t]}),a.init(o),o.is_latlong&&1==e.to_meter&&(e.to_meter=C,e.fr_meter=S),X(e.params,"to_alpha")?(d=X(e.params,"ro_lon_c"),f=X(e.params,"ro_lat_c"),m=X(e.params,"ro_alpha"),t(t(f)-k)<=A&&U(-32),c=d+ei(-s(m),-i(m)*i(f)),_=Ye(s(f)*i(m))):X(e.params,"to_lat_p")?(c=X(e.params,"ro_lon_p"),_=X(e.params,"ro_lat_p")):(y=X(e.params,"ro_lon_1"),v=X(e.params,"ro_lat_1"),g=X(e.params,"ro_lon_2"),b=X(e.params,"ro_lat_2"),(t(v-b)<=A||(w=t(v))<=A||t(w-k)<=A||t(t(b)-k)<=A)&&U(-33),c=l(s(v)*i(b)*s(y)-i(v)*s(b)*s(g),i(v)*s(b)*i(g)-s(v)*i(b)*i(y)),_=h(-s(c-y)/n(v))),t(_)>A?(u=s(_),p=i(_),e.fwd=function(t,e){var n,r,a;n=s(t.lam),r=i(t.phi),a=s(t.phi),t.lam=Mt(ei(a*i(t.lam),p*a*n+u*r)+c),t.phi=Ye(p*r-u*a*n),o.fwd(t,e)},e.inv=o.inv?function(t,e){var n,r,a;o.inv(t,e),e.lam!=x&&(n=s(e.lam-=c),r=i(e.phi),a=s(e.phi),e.phi=Ye(p*r+u*a*n),e.lam=ei(a*i(e.lam),p*a*n-u*r))}:null):(e.fwd=function(t,e){var n,r;n=s(t.phi),r=s(t.lam),t.lam=Mt(ei(n*i(t.lam),i(t.phi))+c),t.phi=Ye(-n*r),o.fwd(t,e)},e.inv=o.inv?function(t,e){var n,r;o.inv(t,e),e.lam!=x&&(n=s(e.phi),r=e.lam-c,e.lam=ei(n*i(r),-i(e.phi)),e.phi=Ye(n*s(r)))}:null)},"ob_tran","General Oblique Transformation","Misc Sph\no_proj= plus parameters for projection\no_lat_p= o_lon_p= (new pole) or\no_alpha= o_lon_c= o_lat_c= or\no_lon_1= o_lat_1= o_lon_2= o_lat_2="),tt(function(t){var e,r,o,u,p,_,d,f,m,y,g;d=1/t.k0,f=t.k0,X(t.params,"talpha")?(_=X(t.params,"ralpha"),p=X(t.params,"rlonc"),g=h(-s(_)/(-i(0)*i(_)))+p,m=a(s(0)*i(_))):(e=X(t.params,"rlat_1"),r=X(t.params,"rlat_2"),o=X(t.params,"rlon_1"),u=X(t.params,"rlon_2"),g=l(s(e)*i(r)*s(o)-i(e)*s(r)*s(u),i(e)*s(r)*i(u)-s(e)*i(r)*i(o)),o==-k&&(g=-g),m=h(-s(g-o)/n(e))),t.lam0=g+k,y=s(m),m=i(m),g=i(g),t.es=0,t.fwd=function(t,e){var r;e.y=i(t.lam),r=s(t.lam),e.x=h((n(t.phi)*y+m*e.y)/r),r<0&&(e.x+=w),e.x*=f,e.y=d*(m*i(t.phi)-y*s(t.phi)*e.y)},t.inv=function(t,e){var n,r;t.y/=d,t.x/=f,n=c(1-t.y*t.y),e.phi=a(t.y*m+n*y*(r=i(t.x))),e.lam=l(n*m*r-t.y*y,n*s(t.x))}},"ocea","Oblique Cylindrical Equal Area","Cyl, Sph lonc= alpha= or\nlat_1= lat_2= lon_1= lon_2="),tt(function(e){var r,o,d,f,m,y,g,v,b,S,C,A,E,I,P,T,L,N,R,O,G,z,B,$,V,W,H,K=1e-7,Z=0,J=0,Y=0,Q=0,tt=0,et=0,it=0,st=0;H=X(e.params,"tno_rot"),0!=(A=X(e.params,"talpha"))&&(it=X(e.params,"ralpha")),0!=(E=X(e.params,"tgamma"))&&(Z=X(e.params,"rgamma")),A||E?(J=X(e.params,"rlonc"),(st=X(e.params,"tno_off")||X(e.params,"tno_uoff"))&&(X(e.params,"sno_uoff"),X(e.params,"sno_off"))):(Y=X(e.params,"rlon_1"),tt=X(e.params,"rlat_1"),Q=X(e.params,"rlon_2"),et=X(e.params,"rlat_2"),(t(tt-et)<=K||(r=t(tt))<=K||t(r-k)<=K||t(t(e.phi0)-k)<=K||t(t(et)-k)<=K)&&U(-33)),o=c(e.one_es),t(e.phi0)>F?(v=i(e.phi0),d=s(e.phi0),r=1-e.es*v*v,P=d*d,P=c(1+e.es*P*P/e.one_es),I=P*e.k0*o/r,(m=(f=P*o/(d*c(r)))*f-1)<=0?m=0:(m=c(m),e.phi0<0&&(m=-m)),T=m+=f,T*=u(fi(e.phi0,v,e.e),P)):(P=1/o,I=e.k0,T=f=m=1),A||E?(A?(C=a(i(it)/f),E||(Z=it)):it=a(f*i(C=Z)),e.lam0=J-a(.5*(m-1/m)*n(C))/P):(y=u(fi(tt,i(tt),e.e),P),g=u(fi(et,i(et),e.e),P),m=T/y,b=(g-y)/(g+y),S=((S=T*T)-g*y)/(S+g*y),(r=Y-Q)<-w?Q-=D:r>w&&(Q+=D),e.lam0=Mt(.5*(Y+Q)-h(S*n(.5*P*(Y-Q))/b)/P),C=h(2*i(P*Mt(Y-e.lam0))/(m-1/m)),Z=it=a(f*i(C))),O=i(C),G=s(C),z=i(Z),B=s(Z),N=1/(L=I*(R=1/P)),st?W=0:(W=t(L*h(c(f*f-1)/s(it))),e.phi0<0&&(W=-W)),$=L*_(n(M-(m=.5*C))),V=L*_(n(M+m)),e.fwd=function(n,r){var a,o,h,c,p,d,f,m;t(t(n.phi)-k)>F?(a=.5*((p=T/u(fi(n.phi,i(n.phi),e.e),P))-(d=1/p)),o=.5*(p+d),c=i(P*n.lam),t(t(h=(a*O-c*G)/o)-1)<F&&q(),m=.5*L*_((1-h)/(1+h)),d=s(P*n.lam),f=t(d)<K?I*n.lam:L*l(a*G+c*O,d)):(m=n.phi>0?$:V,f=L*n.phi),H?(r.x=f,r.y=m):(f-=W,r.x=m*B+f*z,r.y=f*B-m*z)},e.inv=function(n,r){var a,o,h,_,d,f,m;H?(o=n.y,a=n.x):(o=n.x*B-n.y*z,a=n.y*B+n.x*z+W),_=.5*((h=p(-N*o))-1/h),d=.5*(h+1/h),f=i(N*a),t(t(m=(f*G+_*O)/d)-1)<F?(r.lam=0,r.phi=m<0?-k:k):(r.phi=T/c((1+m)/(1-m)),(r.phi=mi(u(r.phi,1/P),e.e))==x&&j(),r.lam=-R*l(_*G-f*O,s(N*a)))}},"omerc","Oblique Mercator","Cyl, Sph&Ell no_rot\nalpha= [gamma=] [no_off] lonc= or\nlon_1= lat_1= lon_2= lat_2="),tt(function(e){var n=1e-10,r={};t(t(e.phi0)-k)<=n?r.mode=e.phi0<0?1:0:t(e.phi0)>n?(r.mode=3,r.sinph0=i(e.phi0),r.cosph0=s(e.phi0)):r.mode=2,e.fwd=function(a,o){var h,l,c;switch(l=s(a.phi),h=s(a.lam),r.mode){case 2:l*h<-1e-10&&q(),o.y=i(a.phi);break;case 3:r.sinph0*(c=i(a.phi))+r.cosph0*l*h<-1e-10&&q(),o.y=r.cosph0*c-r.sinph0*l*h;break;case 0:h=-h;case 1:t(a.phi-e.phi0)-n>k&&q(),o.y=l*h}o.x=l*i(a.lam)},e.inv=function(i,s){var h,u,p;if((p=h=d(i.x,i.y))>1&&(p-1>n&&j(),p=1),u=c(1-p*p),t(h)<=n)s.phi=e.phi0,s.lam=0;else{switch(r.mode){case 0:i.y=-i.y,s.phi=o(p);break;case 1:s.phi=-o(p);break;case 2:case 3:2==r.mode?(s.phi=i.y*p/h,i.x*=p,i.y=u*h):(s.phi=u*r.sinph0+i.y*p*r.cosph0/h,i.y=(u-r.sinph0*s.phi)*h,i.x*=p*r.cosph0),t(s.phi)>=1?s.phi=s.phi<0?-k:k:s.phi=a(s.phi)}s.lam=0!=i.y||3!=r.mode&&2!=r.mode?l(i.x,i.y):0==i.x?0:i.x<0?-k:k}},e.es=0},"ortho","Orthographic","Azi, Sph."),tt(function(e){var i=1.0148,s=.23185,n=-.14499,r=.02406,a=i,o=5*s,h=7*n,l=908571831.7;e.es=0,e.fwd=function(t,e){var a=t.phi*t.phi;e.x=t.lam,e.y=t.phi*(i+a*a*(s+a*(n+r*a)))},e.inv=function(e,c){var u,p,_,d;for(u=e.y,e.y>l?e.y=l:e.y<-l&&(e.y=-l),d=100;d&&(u-=p=(u*(i+(_=u*u)*_*(s+_*(n+r*_)))-e.y)/(a+_*_*(o+_*(h+.21654*_))),!(t(p)<1e-11));--d);c.phi=u,c.lam=e.x}},"patterson","Patterson Cylindrical","Cyl., Sph."),tt(function(e){var r,o,h=1e-10,l=1e-12;e.es?(o=Ze(e.es),r=Xe(e.phi0,i(e.phi0),s(e.phi0),o),e.fwd=function(n,a){var l,c,u;t(n.phi)<=h?(a.x=n.lam,a.y=-r):(c=i(n.phi),l=t(u=s(n.phi))>h?He(c,u,e.es)/c:0,a.x=l*i(n.lam*=c),a.y=Xe(n.phi,c,u,o)-r+l*(1-s(n.lam)))},e.inv=function(u,p){var _,d,f,m,y,g,v,x,b,w,S=u.x,C=u.y;if(t(C+=r)<=h)p.lam=S,p.phi=0;else{for(_=C*C+S*S,p.phi=C,w=20;w>0&&(y=(f=i(p.phi))*(m=s(p.phi)),t(m)<l&&j(),d=f*(x=c(1-e.es*f*f))/m,v=(g=Xe(p.phi,f,m,o))*g+_,x=e.one_es/(x*x*x),p.phi+=b=(g+g+d*v-2*C*(d*g+1))/(e.es*y*(v-2*C*g)/d+2*(C-g)*(d*x-1/y)-x-x),!(t(b)<=l));--w);w||j(),d=i(p.phi),p.lam=a(S*n(p.phi)*c(1-e.es*d*d))/i(p.phi)}}):(r=-e.phi0,e.fwd=function(a,o){var l,c;t(a.phi)<=h?(o.x=a.lam,o.y=r):(l=1/n(a.phi),o.x=i(c=a.lam*i(a.phi))*l,o.y=a.phi-e.phi0+l*(1-s(c)))},e.inv=function(s,r){var o,l,c,u;if(t(s.y=e.phi0+s.y)<=h)r.lam=s.x,r.phi=0;else{r.phi=s.y,o=s.x*s.x+s.y*s.y,u=10;do{c=n(r.phi),r.phi-=l=(s.y*(r.phi*c+1)-r.phi-.5*(r.phi*r.phi+o)*c)/((r.phi-s.y)/c-1)}while(t(l)>1e-10&&--u);u||j(),r.lam=a(s.x*n(r.phi))/i(r.phi)}})},"poly","Polyconic (American)","Conic, Sph&Ell"),tt(function(e){var n=1.8949,r=1.71848,a=.6141848493043784,o=1.0471975511965976;e.es=0,e.fwd=function(e,h){var l,c,u,p,_;for(l=a*i(e.phi),u=e.phi*e.phi,e.phi*=.615709+u*(.00909953+.0046292*u),_=10;_&&(c=s(e.phi),u=i(e.phi),e.phi-=p=(e.phi+u*(c-1)-l)/(1+c*(c-1)-u*u),!(t(p)<1e-10));--_);_||(e.phi=e.phi<0?-o:o),h.x=n*e.lam*(s(e.phi)-.5),h.y=r*i(e.phi)},e.inv=function(t,e){var o;e.phi=Ye(t.y/r),e.lam=t.x/(n*((o=s(e.phi))-.5)),e.phi=Ye((e.phi+i(e.phi)*(o-1))/a)}},"putp2","Putnins P2","PCyl., Sph."),tt(bi,"putp3","Putnins P3","PCyl., Sph."),tt(function(t){bi(t,!0)},"putp3p","Putnins P3'","PCyl., Sph."),tt(function(t){wi(t,.874038744,3.883251825)},"putp4p","Putnins P4'","PCyl., Sph."),tt(function(t){wi(t,1,4.442882938)},"weren","Werenskiold I","PCyl., Sph."),tt(Si,"putp5","Putnins P5","PCyl., Sph."),tt(function(t){Si(t,!0)},"putp5p","Putnins P5'","PCyl., Sph."),tt(Ci,"putp6","Putnins P6","PCyl., Sph."),tt(function(t){Ci(t,!0)},"putp6p","Putnins P6'","PCyl., Sph."),tt(function(e){var r,a,u,p;function _(e,i,s){var n,r;return e<1e-10?(n=0,r=0):(r=l(i,s),t(r)<=M?n=0:r>M&&r<=k+M?(n=1,r-=k):r>k+M||r<=-(k+M)?(n=2,r=r>=0?r-w:r+w):(n=3,r+=k)),{area:n,theta:r}}function d(t,e){var i=t+e;return i<-w?i+=D:i>+w&&(i-=D),i}r=e.phi0>=k-M/2?4:e.phi0<=-(k-M/2)?5:t(e.lam0)<=M?0:t(e.lam0)<=k+M?e.lam0>0?1:3:2,0!==e.es&&(e.a,e.a,a=e.a*c(1-e.es),u=1-(e.a-a)/e.a,p=u*u),e.fwd=function(t,a){var l,u,f,m,y,g,v,x,b,S,C,A,E,D;l=0!==e.es?h(p*n(t.phi)):t.phi,u=t.lam,4==r?(m=k-l,u>=M&&u<=k+M?(v=0,f=u-k):u>k+M||u<=-(k+M)?(v=1,f=u>0?u-w:u+w):u>-(k+M)&&u<=-M?(v=2,f=u+k):(v=3,f=u)):5==r?(m=k+l,u>=M&&u<=k+M?(v=0,f=-u+k):u<M&&u>=-M?(v=1,f=-u):u<-M&&u>=-(k+M)?(v=2,f=-u-k):(v=3,f=u>0?-u+w:-u-w)):(1==r?u=d(u,+k):2==r?u=d(u,+w):3==r&&(u=d(u,-k)),C=i(l),A=s(l),E=i(u),x=A*s(u),b=A*E,S=C,0==r?D=_(m=o(x),S,b):1==r?D=_(m=o(b),S,-x):2==r?D=_(m=o(-x),S,-b):3==r?D=_(m=o(-b),S,x):(m=0,D={area:0,theta:0}),f=D.theta,v=D.area),g=h(12/w*(f+o(i(f)*s(M))-k)),y=c((1-s(m))/(s(g)*s(g))/(1-s(h(1/s(f))))),1==v?g+=k:2==v?g+=w:3==v&&(g+=I),a.x=y*s(g),a.y=y*i(g)},e.inv=function(_,f){var m,y,g,v,x,b,S,C,A,E,M,I,D;if(y=h(c(_.x*_.x+_.y*_.y)),m=l(_.y,_.x),_.x>=0&&_.x>=t(_.y)?E=0:_.y>=0&&_.y>=t(_.x)?(E=1,m-=k):_.x<0&&-_.x>=t(_.y)?(E=2,m=m<0?m+w:m-w):(E=3,m+=k),A=w/12*n(m),x=i(A)/(s(A)-1/c(2)),b=h(x),(S=1-(g=s(m))*g*(v=n(y))*v*(1-s(h(1/s(b)))))<-1?S=-1:S>1&&(S=1),4==r)C=o(S),f.phi=k-C,f.lam=0==E?b+k:1==E?b<0?b+w:b-w:2==E?b-k:b;else if(5==r)C=o(S),f.phi=C-k,f.lam=0==E?-b+k:1==E?-b:2==E?-b-k:b<0?-b-w:-b+w;else{var P,T,L;A=(P=S)*P,T=(A+=(L=A>=1?0:c(1-A)*i(b))*L)>=1?0:c(1-A),1==E?(A=T,T=-L,L=A):2==E?(T=-T,L=-L):3==E&&(A=T,T=L,L=-A),1==r?(A=P,P=-T,T=A):2==r?(P=-P,T=-T):3==r&&(A=P,P=T,T=-A),f.phi=o(-L)-k,f.lam=l(T,P),1==r?f.lam=d(f.lam,-k):2==r?f.lam=d(f.lam,-w):3==r&&(f.lam=d(f.lam,+k))}0!==e.es&&(M=f.phi<0?1:0,I=n(f.phi),D=a/c(I*I+p),f.phi=h(c(e.a*e.a-D*D)/(u*D)),M&&(f.phi=-f.phi))}},"qsc","Quadrilateralized Spherical Cube","Azi, Sph."),tt(function(i){var s=l([[1,22199e-21,-715515e-10,31103e-10],[.9986,-482243e-9,-24897e-9,-13309e-10],[.9954,-83103e-8,-448605e-10,-9.86701e-7],[.99,-.00135364,-59661e-9,36777e-10],[.9822,-.00167442,-449547e-11,-572411e-11],[.973,-.00214868,-903571e-10,1.8736e-8],[.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,9.34959e-7],[.7986,-.00755338,-500009e-10,9.35324e-7],[.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]]),n=l([[-520417e-23,.0124,121431e-23,-845284e-16],[.062,.0124,-1.26793e-9,4.22642e-10],[.124,.0124,5.07171e-9,-1.60604e-9],[.186,.0123999,-1.90189e-8,6.00152e-9],[.248,.0124002,7.10039e-8,-2.24e-8],[.31,.0123992,-2.64997e-7,8.35986e-8],[.372,.0124029,9.88983e-7,-3.11994e-7],[.434,.0123893,-369093e-11,-4.35621e-7],[.4958,.0123198,-102252e-10,-3.45523e-7],[.5571,.0121916,-154081e-10,-5.82288e-7],[.6176,.0119938,-241424e-10,-5.25327e-7],[.6769,.011713,-320223e-10,-5.16405e-7],[.7346,.0113541,-397684e-10,-6.09052e-7],[.7903,.0109107,-489042e-10,-104739e-11],[.8435,.0103431,-64615e-9,-1.40374e-9],[.8936,.00969686,-64636e-9,-8547e-9],[.9394,.00840947,-192841e-9,-42106e-10],[.9761,.00616527,-256e-6,-42106e-10],[1,.00328947,-319159e-9,-42106e-10]]),r=.8487,a=1.3523;function o(t,e){return t[0]+e*(t[1]+e*(t[2]+e*t[3]))}function h(t,e){return t[1]+e*(t[2]+t[2]+3*e*t[3])}function l(t){return t.map(function(t){return new Float32Array(t)})}i.es=0,i.fwd=function(i,h){var l,c;(l=e(11.459155902616464*(c=t(i.phi))))<0&&q(),l>=18&&(l=17),c=S*(c-.08726646259971647*l),h.x=o(s[l],c)*r*i.lam,h.y=o(n[l],c)*a,i.phi<0&&(h.y=-h.y)},i.inv=function(i,l){var c,u,p,_;if(l.lam=i.x/r,l.phi=t(i.y/a),l.phi>=1)l.phi>1.000001?j():(l.phi=i.y<0?-k:k,l.lam/=s[18][0]);else{if((_=e(18*l.phi))<0||_>=18)return j();for(;;)if(n[_][0]>l.phi)--_;else{if(!(n[_+1][0]<=l.phi))break;++_}for(p=new Float32Array(n[_]),c=5*(l.phi-p[0])/(n[_+1][0]-p[0]),p[0]-=l.phi;c-=u=o(p,c)/h(p,c),!(t(u)<1e-8););l.phi=(5*_+c)*C,i.y<0&&(l.phi=-l.phi),l.lam/=o(s[_],c)}}},"robin","Robinson","PCyl., Sph."),tt(Ai("EULER"),"euler","Euler","Conic, Sph\nlat_1= and lat_2="),tt(Ai("MURD1"),"murd1","Murdoch I","Conic, Sph\nlat_1= and lat_2="),tt(Ai("MURD2"),"murd2","Murdoch II","Conic, Sph\nlat_1= and lat_2="),tt(Ai("MURD3"),"murd3","Murdoch III","Conic, Sph\nlat_1= and lat_2="),tt(Ai("PCONIC"),"pconic","Perspective Conic","Conic, Sph\nlat_1= and lat_2="),tt(Ai("TISSOT"),"tissot","Tissot","Conic, Sph\nlat_1= and lat_2="),tt(Ai("VITK1"),"vitk1","Vitkovsky I","Conic, Sph\nlat_1= and lat_2="),tt(function(e){var r,a,o,l,u,d,f,m,y;o=.5*e.e,f=s(e.phi0),f*=f,a=c(1+e.es*f*f*e.rone_es),y=i(e.phi0),u=s(m=Ye(d=y/a)),y*=e.e,r=_(n(M+.5*m))-a*(_(n(M+.5*e.phi0))-o*_((1+y)/(1-y))),l=e.k0*c(e.one_es)/(1-y*y),e.inv=function(c,f){var m,y,g,v,x,b,w,S,C;for(g=2*(h(p(c.y/l))-M),v=c.x/l,x=s(g),m=Ye(u*i(g)+d*x*s(v)),y=Ye(x*i(v)/s(m)),w=(r-_(n(M+.5*m)))/a,C=6;C&&(b=e.e*i(m),m-=S=(w+_(n(M+.5*m))-o*_((1+b)/(1-b)))*(1-b*b)*s(m)*e.rone_es,!(t(S)<1e-10));--C);C?(f.phi=m,f.lam=y/a):j()},e.fwd=function(t,c){var f,m,y,g,v,x;v=e.e*i(t.phi),f=2*h(p(a*(_(n(M+.5*t.phi))-o*_((1+v)/(1-v)))+r))-k,m=a*t.lam,x=s(f),y=Ye(u*i(f)-d*x*s(m)),g=Ye(x*i(m)/s(y)),c.x=l*g,c.y=l*_(n(M+.5*y))}},"somerc","Swiss. Obl. Mercator","Cyl, Ell\nFor CH1903"),tt(function(t){var e=X(t.params,"tlat_ts")?X(t.params,"rlat_ts"):k;Ei(t,e)},"stere","Stereographic","Azi, Sph&Ell\nlat_ts="),tt(function(t){t.phi0=X(t.params,"bsouth")?-k:k,t.k0=.994,t.x0=2e6,t.y0=2e6,t.lam0=0,t.es||U(-34),Ei(t,k)},"ups","Universal Polar Stereographic","Azi, Sph&Ell\nsouth"),tt(function(e){var r,o,p,_,f,m,y,g,v,x=(r=e.e,o=e.phi0,p=r*r,_=i(o),f=s(o),m=c(1-p)/(1-p*_*_),y=c(1+p*f*f*f*f/(1-p)),g=a(_/y),v=.5*y*r,{e:r,K:n(.5*g+M)/(u(n(.5*o+M),y)*Mi(r*_,v)),C:y,chi:g,ratexp:v,rc:m}),b=x.chi,w=2*x.rc,S=i(b),C=s(b);e.fwd=function(t,r){var a,o,l,c;t=function(t,e){return{phi:2*h(e.K*u(n(.5*t.phi+M),e.C)*Mi(e.e*i(t.phi),e.ratexp))-k,lam:e.C*t.lam}}(t,x),o=i(t.phi),a=s(t.phi),l=s(t.lam),c=e.k0*w/(1+S*o+C*a*l),r.x=c*a*i(t.lam),r.y=c*(C*o-S*a*l)},e.inv=function(r,o){var c,p,_,f,m=r.x/e.k0,y=r.y/e.k0;(c=d(m,y))?(p=2*l(c,w),_=i(p),f=s(p),o.phi=a(f*S+y*_*C/c),o.lam=l(m*_,c*C*f-y*S*_)):(o.phi=b,o.lam=0),function(e,s){e.phi;var r,a,o=u(n(.5*e.phi+M)/s.K,1/s.C);for(e.lam/=s.C,r=20;r>0&&(a=2*h(o*Mi(s.e*i(e.phi),-.5*s.e))-k,!(t(a-e.phi)<1e-14));--r)e.phi=a;r||z(-17)}(o,x)}},"sterea","Oblique Stereographic Alternative","Azimuthal, Sph&Ell"),tt(function(t){ki(t,1.50488,1.35439,!1)},"kav5","Kavraisky V","PCyl., Sph."),tt(function(t){ki(t,2,2,!1)},"qua_aut","Quartic Authalic","PCyl., Sph."),tt(function(t){ki(t,2,2,!0)},"fouc","Foucaut","PCyl., Sph."),tt(function(t){ki(t,1.48875,1.36509,!1)},"mbt_s","McBryde-Thomas Flat-Polar Sine (No. 1)","PCyl., Sph."),tt(function(t){t.es=0,t.fwd=function(e,r){r.x=s(e.phi)*i(e.lam)/t.k0,r.y=t.k0*(l(n(e.phi),s(e.lam))-t.phi0)},t.inv=function(e,n){var r;e.y=e.y/t.k0+t.phi0,e.x*=t.k0,r=c(1-e.x*e.x),n.phi=a(r*i(e.y)),n.lam=l(e.x,r*s(e.y))}},"tcea","Transverse Cylindrical Equal Area","Cyl, Sph"),tt(function(t){t.es=0,t.fwd=function(t,e){var s=n(t.phi/2),r=i(M*s);e.x=t.lam*(.74482-.34588*r*r),e.y=1.70711*s},t.inv=function(t,e){var s=t.y/1.70711,n=i(M*s);e.lam=t.x/(.74482-.34588*n*n),e.phi=2*h(s)}},"times","Times","Cyl, Sph"),tt(function(e){X(e.params,"bapprox")?Ii(e):function(e){if(0===e.es)return Ii(e);oi(e);var i=e.fwd,s=e.inv;Ii(e);var n=e.fwd,r=e.inv;e.fwd=function(e,s){t(e.lam)>3*C?i(e,s):n(e,s)},e.inv=function(e,i){t(e.x)>.053-.022*e.y*e.y?s(e,i):r(e,i)}}(e)},"tmerc","Transverse Mercator","Cyl, Sph&Ell"),tt(function(t){var i;t.es||U(-34),t.y0=X(t.params,"bsouth")?1e7:0,t.x0=5e5,X(t.params,"tzone")?(i=X(t.params,"izone"))>0&&i<=60?--i:U(-35):(i=e(30*(Mt(t.lam0)+w)/w))<0?i=0:i>=60&&(i=59),t.lam0=(i+.5)*w/30-w,t.k0=.9996,t.phi0=0,oi(t)},"utm","Universal Transverse Mercator (UTM)","Cyl, Sph\nzone= south"),tt(function(t){var e,r,a,o,h,c,u,p,_,f,m,y,g,v,x,b,w,S,C,A,E,M,I;A=X(t.params,"rlat_1"),S=X(t.params,"rlon_1"),E=X(t.params,"rlat_2"),C=X(t.params,"rlon_2"),A==E&&S==C&&U(-25),t.lam0=Mt(.5*(S+C)),f=Mt(C-S),e=s(A),a=s(E),r=i(A),o=i(E),c=e*o,u=r*a,h=e*a*i(f),_=Qe(r*o+e*a*s(f)),m=.5*_,M=l(a*i(f),e*o-r*a*s(f)),v=s(I=Ye(e*i(M))),x=i(I),b=Mt(l(e*s(M),r)-m),f*=.5,w=k-l(i(M)*r,s(M))-f,y=n(m),g=.5/i(m),p=.5/_,_*=_,t.fwd=function(t,n){var l,d,m,y,g,v,x;v=i(t.phi),x=s(t.phi),d=Qe(r*v+e*x*s(y=t.lam+f)),m=Qe(o*v+a*x*s(g=t.lam-f)),d*=d,m*=m,n.x=p*(l=d-m),l=_-l,n.y=p*ti(4*_*m-l*l),h*v-x*(c*i(y)-u*i(g))<0&&(n.y=-n.y)},t.inv=function(t,e){var n,r,a,o,h,c;a=(n=s(d(t.y,t.x+m)))+(r=s(d(t.y,t.x-m))),o=n-r,e.lam=-l(o,a*y),e.phi=Qe(d(y*a,o)*g),t.y<0&&(e.phi=-e.phi),c=i(e.phi),h=s(e.phi),e.phi=Ye(x*c+v*h*(a=s(e.lam-=b))),e.lam=l(h*i(e.lam),x*h*a-v*c)+w},t.es=0},"tpeqd","Two Point Equidistant","Misc Sph\nlat_1= lon_1= lat_2= lon_2="),tt(function(t){var e,n,r,a,o,h;(a=X(t.params,"dn"))>0&&a<=1==0&&U(-40),r=X(t.params,"dq")/3,o=X(t.params,"ralpha"),h=a*i(o),e=s(o)/c(1-h*h),n=1/(e*a),t.fwd=function(t,o){var h=t.phi=Ye(a*i(t.phi));o.x=e*t.lam*s(t.phi),h*=h,o.y=t.phi*(1+h*r)*n},t.es=0},"urm5","Urmaev V","PCyl., Sph., no inv.\nn= q= alpha="),tt(function(t){var e=X(t.params,"dn");(e<=0||e>1)&&U(-40),Di(t,e)},"urmfps","Urmaev Flat-Polar Sinusoidal","PCyl, Sph.\nn="),tt(function(t){Di(t,.8660254037844386)},"wag1","Wagner I (Kavraisky VI)","PCyl, Sph."),tt(function(e){var i=1e-10,r=.3333333333333333,h=9.869604401089358,l=19.739208802178716,u=4.934802200544679;e.fwd=function(e,s){var r,o,h,l,u;(u=t(e.phi/k))-i>1&&q(),u>1&&(u=1),t(e.phi)<=i?(s.x=e.lam,s.y=0):t(e.lam)<=i||t(u-1)<i?(s.x=0,s.y=w*n(.5*a(u)),e.phi<0&&(s.y=-s.y)):(o=(r=.5*t(w/e.lam-e.lam/w))*r,h=c(1-u*u),l=(h/=u+h-1)*h,u=h*(2/u-1),u*=u,s.x=h-u,h=u+o,s.x=w*(r*s.x+c(o*s.x*s.x-h*(l-u)))/h,e.lam<0&&(s.x=-s.x),s.y=t(s.x/w),s.y=1-s.y*(s.y+2*r),s.y<-i&&q(),s.y<0?s.y=0:s.y=c(s.y)*(e.phi<0?-w:w))},e.inv=function(e,n){var a,p,_,d,f,m,y,g,v,x,b,S,C;if(S=e.x*e.x,(b=t(e.y))<i)return n.phi=0,a=S*S+l*(S+u),n.lam=t(e.x)<=i?0:.5*(S-h+c(a))/e.x,n;C=e.y*e.y,d=(_=-w*b*((g=S+C)+h))+h*(g-3*C),p=w*b,v=2*c(-r*(m=_/(f=(y=g*g)+D*(b*g+w*(C+w*(b+k))))-r*(d/=f)*d)),(a=t(x=3*(x=.07407407407407407*d*d*d+(p*p-r*d*_)/f)/(m*v)))-i<=1?(x=a>1?x>0?0:w:o(x),n.phi=w*(v*s(x*r+4.188790204786391)-r*d),e.y<0&&(n.phi=-n.phi),a=y+l*(S-C+u),n.lam=t(e.x)<=i?0:.5*(g-h+(a<=0?0:c(a)))/e.x):j()}},"vandg","van der Grinten (I)","Misc Sph"),tt(function(t){Pi(t,!1)},"vandg2","van der Grinten II","Misc Sph, no inv."),tt(function(t){Pi(t,!0)},"vandg3","van der Grinten III","Misc Sph, no inv."),tt(function(e){e.es=0,e.fwd=function(e,i){var s,n,r,a,o,h,l,u,p=1e-10;t(e.phi)<p?(i.x=e.lam,i.y=0):t(e.lam)<p||t(t(e.phi)-k)<p?(i.x=0,i.y=e.phi):(h=(a=.5*((r=t(P*e.phi))*(8-r*(2+(o=r*r)))-5)/(o*(r-1)))*a,l=P*e.lam,l=c((l+=1/l)*l-4),t(e.lam)-k<0&&(l=-l),s=r+a,s=(l*((s*=s)+h-1)+2*c(s*(o+h*(u=l*l)-1)+(1-o)*(o*((n=r+3*a)*n+4*h)+h*(12*r*a+4*h))))/(4*s+u),i.x=k*s,i.y=k*c(1+l*t(s)-s*s),e.lam<0&&(i.x=-i.x),e.phi<0&&(i.y=-i.y))}},"vandg4","van der Grinten IV","Misc Sph, no inv."),tt(function(t){var e=.92483,n=1.38725,r=.88022,a=.8855;t.fwd=function(t,o){t.phi=Ye(r*i(a*t.phi)),o.x=e*t.lam*s(t.phi),o.y=n*t.phi},t.inv=function(t,o){o.phi=t.y/n,o.lam=t.x/(e*s(o.phi)),o.phi=Ye(i(o.phi)/r)/a}},"wag2","Wagner II","PCyl., Sph."),tt(function(t){var e=.6666666666666666,i=X(t.params,"rlat_ts"),n=s(i)/s(2*i/3);t.es=0,t.fwd=function(t,i){i.x=n*t.lam*s(e*t.phi),i.y=t.phi},t.inv=function(t,i){i.phi=t.y,i.lam=t.x/(n*s(e*i.phi))}},"wag3","Wagner III","PCyl., Sph.\nlat_ts="),tt(function(t){t.es=0,t.fwd=function(t,e){var n,r,o;n=a(e.y=.9063077870366499*i(t.phi)),e.x=2.66723*(r=s(n))*i(t.lam/=3),e.y*=1.24104*(o=1/c(.5*(1+r*s(t.lam)))),e.x*=o}},"wag7","Wagner VII","Misc Sph, no inv."),tt(function(t){var e=s(X(t.params,"rlat_ts"));t.fwd=function(t,i){i.x=.5*t.lam*(e+s(t.phi)),i.y=t.phi},t.inv=function(t,i){i.phi=t.y,i.lam=2*t.x/(e+s(i.phi))},t.es=0},"wink1","Winkel I","PCyl., Sph.\nlat_ts="),tt(function(e){var n=s(X(e.params,"rlat_1"));e.fwd=function(e,r){var a,o,h,l=e.phi;for(r.y=l*P,a=w*i(l),l*=1.8,h=10;h&&(l-=o=(l+i(l)-a)/(1+s(l)),!(t(o)<1e-7));--h);h?l*=.5:l=l<0?-k:k,r.x=.5*e.lam*(s(l)+n),r.y=M*(i(l)+r.y)},e.inv=null,e.es=0},"wink2","Winkel II","PCyl., Sph., no inv.\nlat_1=");var Ti=Pt;Ti.pj_init=mt,Ti.pj_fwd=kt,Ti.pj_inv=It,Ti.pj_transform=St,Ti.pj_add=tt,Ti.pj_fwd_deg=function(t,e){return kt({lam:t.lam*C,phi:t.phi*C},e)},Ti.pj_inv_deg=function(t,e){var i=It(t,e);return{lam:i.lam*S,phi:i.phi*S}},Ti.pj_transform_point=wt,Ti.internal={dmstod:H,dmstor:W,get_rtodms:function(t,e,i,s){var n=Dt(t,e,i,s);return function(t){return n(t*S)}},get_dtodms:Dt,get_proj_defn:st,pj_latlong_from_proj:function(t){return mt("+proj=latlong"+it(t))},pj_get_params:J,pj_datums:rt,pj_list:Q,pj_ellps:ht,pj_units:ct,pj_read_init_opts:ft,find_datum:ot,DEG_TO_RAD:C,RAD_TO_DEG:S,wkt_parse:ze,wkt_unpack:qe,convert_wkt_quotes:je,wkt_to_proj4:function(t){var e,i,s=ze(t);return s.PROJCS?e=Gt(i=s.PROJCS)(i):s.GEOGCS?e="+proj=longlat "+Ht(s.GEOGCS):s.GEOCCS?$t("geocentric coordinates are not supported"):$t("missing a supported WKT CS type"),e},wkt_from_proj4:function(t){return t.length&&(t=mt(t)),Re(et(t)?{GEOGCS:Yt(t)}:re(t))},wkt_make_projcs:re,wkt_get_geogcs_name:ee,wkt_stringify:Re,mproj_insert_libcache:function(t,e){_t[t]=e},mproj_search_libcache:dt,GeographicLib:Ve},v.exports=Ti}();var w=n.exports,S=e({__proto__:null,default:i(w)},[w]);class C{constructor(){this.ids=[],this.values=[],this.length=0}clear(){this.length=0}push(t,e){let i=this.length++;for(;i>0;){const t=i-1>>1,s=this.values[t];if(e>=s)break;this.ids[i]=this.ids[t],this.values[i]=s,i=t}this.ids[i]=t,this.values[i]=e}pop(){if(0===this.length)return;const t=this.ids,e=this.values,i=t[0],s=--this.length;if(s>0){const i=t[s],n=e[s];let r=0;const a=s>>1;for(;r<a;){const i=1+(r<<1),a=i+1,o=i+(+(a<s)&+(e[a]<e[i]));if(e[o]>=n)break;t[r]=t[o],e[r]=e[o],r=o}t[r]=i,e[r]=n}return i}peek(){return this.length>0?this.ids[0]:void 0}peekValue(){return this.length>0?this.values[0]:void 0}shrink(){this.ids.length=this.values.length=this.length}}const A=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class E{static from(t,e=0){if(e%8!=0)throw new Error("byteOffset must be 8-byte aligned.");if(!t||void 0===t.byteLength||t.buffer)throw new Error("Data must be an instance of ArrayBuffer or SharedArrayBuffer.");const[i,s]=new Uint8Array(t,e+0,2);if(251!==i)throw new Error("Data does not appear to be in a Flatbush format.");const n=s>>4;if(3!==n)throw new Error(`Got v${n} data when expected v3.`);const r=A[15&s];if(!r)throw new Error("Unrecognized array type.");const[a]=new Uint16Array(t,e+2,1),[o]=new Uint32Array(t,e+4,1);return new E(o,a,r,void 0,t,e)}constructor(t,e=16,i=Float64Array,s=ArrayBuffer,n,r=0){if(void 0===t)throw new Error("Missing required argument: numItems.");if(isNaN(t)||t<=0)throw new Error(`Unexpected numItems value: ${t}.`);this.numItems=+t,this.nodeSize=Math.min(Math.max(+e,2),65535),this.byteOffset=r;let a=t,o=a;this._levelBounds=[4*a];do{a=Math.ceil(a/this.nodeSize),o+=a,this._levelBounds.push(4*o)}while(1!==a);this.ArrayType=i,this.IndexArrayType=o<16384?Uint16Array:Uint32Array;const h=A.indexOf(i),l=4*o*i.BYTES_PER_ELEMENT;if(h<0)throw new Error(`Unexpected typed array class: ${i}.`);if(n)this.data=n,this._boxes=new i(n,r+8,4*o),this._indices=new this.IndexArrayType(n,r+8+l,o),this._pos=4*o,this.minX=this._boxes[this._pos-4],this.minY=this._boxes[this._pos-3],this.maxX=this._boxes[this._pos-2],this.maxY=this._boxes[this._pos-1];else{const n=this.data=new s(8+l+o*this.IndexArrayType.BYTES_PER_ELEMENT);this._boxes=new i(n,8,4*o),this._indices=new this.IndexArrayType(n,8+l,o),this._pos=0,this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,new Uint8Array(n,0,2).set([251,48+h]),new Uint16Array(n,2,1)[0]=e,new Uint32Array(n,4,1)[0]=t}this._queue=new C}add(t,e,i=t,s=e){const n=this._pos>>2,r=this._boxes;return this._indices[n]=n,r[this._pos++]=t,r[this._pos++]=e,r[this._pos++]=i,r[this._pos++]=s,t<this.minX&&(this.minX=t),e<this.minY&&(this.minY=e),i>this.maxX&&(this.maxX=i),s>this.maxY&&(this.maxY=s),n}finish(){if(this._pos>>2!==this.numItems)throw new Error(`Added ${this._pos>>2} items when expected ${this.numItems}.`);const t=this._boxes;if(this.numItems<=this.nodeSize)return t[this._pos++]=this.minX,t[this._pos++]=this.minY,t[this._pos++]=this.maxX,void(t[this._pos++]=this.maxY);const e=this.maxX-this.minX||1,i=this.maxY-this.minY||1,s=new Uint32Array(this.numItems);for(let n=0,r=0;n<this.numItems;n++){const a=t[r++],o=t[r++],h=t[r++],l=t[r++],c=Math.floor(65535*((a+h)/2-this.minX)/e),u=Math.floor(65535*((o+l)/2-this.minY)/i);s[n]=D(c,u)}k(s,t,this._indices,0,this.numItems-1,this.nodeSize);for(let e=0,i=0;e<this._levelBounds.length-1;e++){const s=this._levelBounds[e];for(;i<s;){const e=i;let n=t[i++],r=t[i++],a=t[i++],o=t[i++];for(let e=1;e<this.nodeSize&&i<s;e++)n=Math.min(n,t[i++]),r=Math.min(r,t[i++]),a=Math.max(a,t[i++]),o=Math.max(o,t[i++]);this._indices[this._pos>>2]=e,t[this._pos++]=n,t[this._pos++]=r,t[this._pos++]=a,t[this._pos++]=o}}}search(t,e,i,s,n){if(this._pos!==this._boxes.length)throw new Error("Data not yet indexed - call index.finish().");let r=this._boxes.length-4;const a=[],o=[];for(;void 0!==r;){const h=Math.min(r+4*this.nodeSize,M(r,this._levelBounds));for(let l=r;l<h;l+=4){const h=this._boxes[l];if(i<h)continue;const c=this._boxes[l+1];if(s<c)continue;const u=this._boxes[l+2];if(t>u)continue;const p=this._boxes[l+3];if(e>p)continue;const _=0|this._indices[l>>2];r>=4*this.numItems?a.push(_):(void 0===n||n(_,h,c,u,p))&&o.push(_)}r=a.pop()}return o}neighbors(t,e,i=1/0,s=1/0,n){if(this._pos!==this._boxes.length)throw new Error("Data not yet indexed - call index.finish().");let r=this._boxes.length-4;const a=this._queue,o=[],h=s*s;t:for(;void 0!==r;){const s=Math.min(r+4*this.nodeSize,M(r,this._levelBounds));for(let i=r;i<s;i+=4){const s=0|this._indices[i>>2],o=this._boxes[i],l=this._boxes[i+1],c=this._boxes[i+2],u=this._boxes[i+3],p=t<o?o-t:t>c?t-c:0,_=e<l?l-e:e>u?e-u:0,d=p*p+_*_;d>h||(r>=4*this.numItems?a.push(s<<1,d):(void 0===n||n(s))&&a.push(1+(s<<1),d))}for(;a.length&&1&a.peek();){if(a.peekValue()>h)break t;if(o.push(a.pop()>>1),o.length===i)break t}r=a.length?a.pop()>>1:void 0}return a.clear(),o}}function M(t,e){let i=0,s=e.length-1;for(;i<s;){const n=i+s>>1;e[n]>t?s=n:i=n+1}return e[i]}function k(t,e,i,s,n,r){if(Math.floor(s/r)>=Math.floor(n/r))return;const a=t[s],o=t[s+n>>1],h=t[n];let l=h;const c=Math.max(a,o);h>c?l=c:c===a?l=Math.max(o,h):c===o&&(l=Math.max(a,h));let u=s-1,p=n+1;for(;;){do{u++}while(t[u]<l);do{p--}while(t[p]>l);if(u>=p)break;I(t,e,i,u,p)}k(t,e,i,s,p,r),k(t,e,i,p+1,n,r)}function I(t,e,i,s,n){const r=t[s];t[s]=t[n],t[n]=r;const a=4*s,o=4*n,h=e[a],l=e[a+1],c=e[a+2],u=e[a+3];e[a]=e[o],e[a+1]=e[o+1],e[a+2]=e[o+2],e[a+3]=e[o+3],e[o]=h,e[o+1]=l,e[o+2]=c,e[o+3]=u;const p=i[s];i[s]=i[n],i[n]=p}function D(t,e){let i=t^e,s=65535^i,n=65535^(t|e),r=t&(65535^e),a=i|s>>1,o=i>>1^i,h=n>>1^s&r>>1^n,l=i&n>>1^r>>1^r;i=a,s=o,n=h,r=l,a=i&i>>2^s&s>>2,o=i&s>>2^s&(i^s)>>2,h^=i&n>>2^s&r>>2,l^=s&n>>2^(i^s)&r>>2,i=a,s=o,n=h,r=l,a=i&i>>4^s&s>>4,o=i&s>>4^s&(i^s)>>4,h^=i&n>>4^s&r>>4,l^=s&n>>4^(i^s)&r>>4,i=a,s=o,n=h,r=l,h^=i&n>>8^s&r>>8,l^=s&n>>8^(i^s)&r>>8,i=h^h>>1,s=l^l>>1;let c=t^e,u=s|65535^(c|i);return c=16711935&(c|c<<8),c=252645135&(c|c<<4),c=858993459&(c|c<<2),c=1431655765&(c|c<<1),u=16711935&(u|u<<8),u=252645135&(u|u<<4),u=858993459&(u|u<<2),u=1431655765&(u|u<<1),(u<<1|c)>>>0}const P=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class T{static from(t){if(!(t instanceof ArrayBuffer))throw new Error("Data must be an instance of ArrayBuffer.");const[e,i]=new Uint8Array(t,0,2);if(219!==e)throw new Error("Data does not appear to be in a KDBush format.");const s=i>>4;if(1!==s)throw new Error(`Got v${s} data when expected v1.`);const n=P[15&i];if(!n)throw new Error("Unrecognized array type.");const[r]=new Uint16Array(t,2,1),[a]=new Uint32Array(t,4,1);return new T(a,r,n,t)}constructor(t,e=64,i=Float64Array,s){if(isNaN(t)||t<0)throw new Error(`Unpexpected numItems value: ${t}.`);this.numItems=+t,this.nodeSize=Math.min(Math.max(+e,2),65535),this.ArrayType=i,this.IndexArrayType=t<65536?Uint16Array:Uint32Array;const n=P.indexOf(this.ArrayType),r=2*t*this.ArrayType.BYTES_PER_ELEMENT,a=t*this.IndexArrayType.BYTES_PER_ELEMENT,o=(8-a%8)%8;if(n<0)throw new Error(`Unexpected typed array class: ${i}.`);s&&s instanceof ArrayBuffer?(this.data=s,this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+a+o,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+r+a+o),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+a+o,2*t),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+n]),new Uint16Array(this.data,2,1)[0]=e,new Uint32Array(this.data,4,1)[0]=t)}add(t,e){const i=this._pos>>1;return this.ids[i]=i,this.coords[this._pos++]=t,this.coords[this._pos++]=e,i}finish(){const t=this._pos>>1;if(t!==this.numItems)throw new Error(`Added ${t} items when expected ${this.numItems}.`);return L(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}range(t,e,i,s){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:n,coords:r,nodeSize:a}=this,o=[0,n.length-1,0],h=[];for(;o.length;){const l=o.pop()||0,c=o.pop()||0,u=o.pop()||0;if(c-u<=a){for(let a=u;a<=c;a++){const o=r[2*a],l=r[2*a+1];o>=t&&o<=i&&l>=e&&l<=s&&h.push(n[a])}continue}const p=u+c>>1,_=r[2*p],d=r[2*p+1];_>=t&&_<=i&&d>=e&&d<=s&&h.push(n[p]),(0===l?t<=_:e<=d)&&(o.push(u),o.push(p-1),o.push(1-l)),(0===l?i>=_:s>=d)&&(o.push(p+1),o.push(c),o.push(1-l))}return h}within(t,e,i){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:s,coords:n,nodeSize:r}=this,a=[0,s.length-1,0],o=[],h=i*i;for(;a.length;){const l=a.pop()||0,c=a.pop()||0,u=a.pop()||0;if(c-u<=r){for(let i=u;i<=c;i++)O(n[2*i],n[2*i+1],t,e)<=h&&o.push(s[i]);continue}const p=u+c>>1,_=n[2*p],d=n[2*p+1];O(_,d,t,e)<=h&&o.push(s[p]),(0===l?t-i<=_:e-i<=d)&&(a.push(u),a.push(p-1),a.push(1-l)),(0===l?t+i>=_:e+i>=d)&&(a.push(p+1),a.push(c),a.push(1-l))}return o}}function L(t,e,i,s,n,r){if(n-s<=i)return;const a=s+n>>1;F(t,e,a,s,n,r),L(t,e,i,s,a-1,1-r),L(t,e,i,a+1,n,1-r)}function F(t,e,i,s,n,r){for(;n>s;){if(n-s>600){const a=n-s+1,o=i-s+1,h=Math.log(a),l=.5*Math.exp(2*h/3),c=.5*Math.sqrt(h*l*(a-l)/a)*(o-a/2<0?-1:1);F(t,e,i,Math.max(s,Math.floor(i-o*l/a+c)),Math.min(n,Math.floor(i+(a-o)*l/a+c)),r)}const a=e[2*i+r];let o=s,h=n;for(N(t,e,s,i),e[2*n+r]>a&&N(t,e,s,n);o<h;){for(N(t,e,o,h),o++,h--;e[2*o+r]<a;)o++;for(;e[2*h+r]>a;)h--}e[2*s+r]===a?N(t,e,s,h):(h++,N(t,e,h,n)),h<=i&&(s=h+1),i<=h&&(n=h-1)}}function N(t,e,i,s){R(t,i,s),R(e,2*i,2*s),R(e,2*i+1,2*s+1)}function R(t,e,i){const s=t[e];t[e]=t[i],t[i]=s}function O(t,e,i,s){const n=t-i,r=e-s;return n*n+r*r}var G={exports:{}};!function(t){var e,i,s,n;(n={}).Constants={},n.Math={},n.Accumulator={},(e=n.Constants).WGS84={a:6378137,f:1/298.257223563},e.version={major:2,minor:2,patch:0},e.version_string="2.2.0",(i=n.Math).digits=53,i.epsilon=Math.pow(.5,i.digits-1),i.degree=Math.PI/180,i.sq=function(t){return t*t},i.hypot=function(t,e){return Math.sqrt(t*t+e*e)},i.cbrt=Math.cbrt||function(t){var e=Math.pow(Math.abs(t),1/3);return t>0?e:t<0?-e:t},i.log1p=Math.log1p||function(t){var e=1+t,i=e-1;return 0===i?t:t*Math.log(e)/i},i.atanh=Math.atanh||function(t){var e=Math.abs(t);return e=i.log1p(2*e/(1-e))/2,t>0?e:t<0?-e:t},i.copysign=function(t,e){return Math.abs(t)*(e<0||0===e&&1/e<0?-1:1)},i.sum=function(t,e){var i=t+e,s=i-e,n=i-s;return s-=t,{s:i,t:i?0-(s+(n-=e)):i}},i.polyval=function(t,e,i,s){for(var n=t<0?0:e[i++];--t>=0;)n=n*s+e[i++];return n},i.AngRound=function(t){var e=1/16,s=Math.abs(t);return s=s<e?e-(e-s):s,i.copysign(s,t)},i.remainder=function(t,e){return(t%=e)<-e/2?t+e:t<e/2?t:t-e},i.AngNormalize=function(t){var e=i.remainder(t,360);return 180===Math.abs(e)?i.copysign(180,t):e},i.LatFix=function(t){return Math.abs(t)>90?NaN:t},i.AngDiff=function(t,e){var s,n,r=i.sum(i.remainder(-t,360),i.remainder(e,360));return s=(r=i.sum(i.remainder(r.s,360),r.t)).s,n=r.t,0!==s&&180!==Math.abs(s)||(s=i.copysign(s,0===n?e-t:-n)),{d:s,e:n}},i.sincosd=function(t){var e,s,n,r,a,o,h;switch(e=t%360,s=(e-=90*(n=Math.round(e/90)))*this.degree,r=Math.sin(s),a=Math.cos(s),45===Math.abs(e)?(a=Math.sqrt(.5),r=i.copysign(a,s)):30===Math.abs(e)&&(a=Math.sqrt(.75),r=i.copysign(.5,s)),3&n){case 0:o=r,h=a;break;case 1:o=a,h=-r;break;case 2:o=-r,h=-a;break;default:o=-a,h=r}return h+=0,0===o&&(o=i.copysign(o,t)),{s:o,c:h}},i.sincosde=function(t,e){var s,n,r,a,o,h,l;switch(s=t%360,r=Math.round(s/90),n=(s=i.AngRound(s-90*r+e))*this.degree,a=Math.sin(n),o=Math.cos(n),45===Math.abs(s)?(o=Math.sqrt(.5),a=i.copysign(o,n)):30===Math.abs(s)&&(o=Math.sqrt(.75),a=i.copysign(.5,n)),3&r){case 0:h=a,l=o;break;case 1:h=o,l=-a;break;case 2:h=-a,l=-o;break;default:h=-o,l=a}return l+=0,0===h&&(h=i.copysign(h,t+e)),{s:h,c:l}},i.atan2d=function(t,e){var s,n=0;switch(Math.abs(t)>Math.abs(e)&&([t,e]=[e,t],n=2),i.copysign(1,e)<0&&(e=-e,++n),s=Math.atan2(t,e)/this.degree,n){case 1:s=i.copysign(180,t)-s;break;case 2:s=90-s;break;case 3:s=-90+s}return s},function(t,e){t.Accumulator=function(t){this.Set(t)},t.Accumulator.prototype.Set=function(e){e||(e=0),e.constructor===t.Accumulator?(this._s=e._s,this._t=e._t):(this._s=e,this._t=0)},t.Accumulator.prototype.Add=function(t){var i=e.sum(t,this._t),s=e.sum(i.s,this._s);i=i.t,this._s=s.s,this._t=s.t,0===this._s?this._s=i:this._t+=i},t.Accumulator.prototype.Sum=function(e){var i;return e?((i=new t.Accumulator(this)).Add(e),i._s):this._s},t.Accumulator.prototype.Negate=function(){this._s*=-1,this._t*=-1},t.Accumulator.prototype.Remainder=function(t){this._s=e.remainder(this._s,t),this.Add(0)}}(n.Accumulator,n.Math),n.Geodesic={},n.GeodesicLine={},n.PolygonArea={},function(t,e,i,s,n){var r,a,o,h,l,c,u,p,_,d,f,m=20+s.digits+10,y=s.epsilon,g=200*y,v=Math.sqrt(y),x=y,b=1e3*v;t.tiny_=Math.sqrt(Number.MIN_VALUE/Number.EPSILON),t.nC1_=6,t.nC1p_=6,t.nC2_=6,t.nC3_=6,t.nC4_=6,r=t.nC3_*(t.nC3_-1)/2,a=t.nC4_*(t.nC4_+1)/2,t.CAP_C1=1,t.CAP_C1p=2,t.CAP_C2=4,t.CAP_C3=8,t.CAP_C4=16,t.NONE=0,t.ARC=64,t.LATITUDE=128,t.LONGITUDE=256|t.CAP_C3,t.AZIMUTH=512,t.DISTANCE=1024|t.CAP_C1,t.STANDARD=t.LATITUDE|t.LONGITUDE|t.AZIMUTH|t.DISTANCE,t.DISTANCE_IN=2048|t.CAP_C1|t.CAP_C1p,t.REDUCEDLENGTH=4096|t.CAP_C1|t.CAP_C2,t.GEODESICSCALE=8192|t.CAP_C1|t.CAP_C2,t.AREA=16384|t.CAP_C4,t.ALL=32671,t.LONG_UNROLL=32768,t.OUT_MASK=32640|t.LONG_UNROLL,t.SinCosSeries=function(t,e,i,s){var n=s.length,r=n-(t?1:0),a=2*(i-e)*(i+e),o=1&r?s[--n]:0,h=0;for(r=Math.floor(r/2);r--;)o=a*(h=a*o-h+s[--n])-o+s[--n];return t?2*e*i*o:i*(o-h)},o=function(t,e){var i,n,r,a,o,h,l,c,u,p,_,d,f=s.sq(t),m=s.sq(e),y=(f+m-1)/6;return 0===m&&y<=0?i=0:(h=y,(o=(n=f*m/4)*(n+2*(a=y*(r=s.sq(y)))))>=0?(l=n+a,l+=l<0?-Math.sqrt(o):Math.sqrt(o),h+=(c=s.cbrt(l))+(0!==c?r/c:0)):(u=Math.atan2(Math.sqrt(-o),-(n+a)),h+=2*y*Math.cos(u/3)),p=Math.sqrt(s.sq(h)+m),d=((_=h<0?m/(p-h):h+p)-m)/(2*p),i=_/(Math.sqrt(_+s.sq(d))+d)),i},h=[1,4,64,0,256],t.A1m1f=function(t){var e=Math.floor(3);return(s.polyval(e,h,0,s.sq(t))/h[e+1]+t)/(1-t)},l=[-1,6,-16,32,-9,64,-128,2048,9,-16,768,3,-5,512,-7,1280,-7,2048],t.C1f=function(e,i){var n,r,a=s.sq(e),o=e,h=0;for(n=1;n<=t.nC1_;++n)r=Math.floor((t.nC1_-n)/2),i[n]=o*s.polyval(r,l,h,a)/l[h+r+1],h+=r+2,o*=e},c=[205,-432,768,1536,4005,-4736,3840,12288,-225,116,384,-7173,2695,7680,3467,7680,38081,61440],t.C1pf=function(e,i){var n,r,a=s.sq(e),o=e,h=0;for(n=1;n<=t.nC1p_;++n)r=Math.floor((t.nC1p_-n)/2),i[n]=o*s.polyval(r,c,h,a)/c[h+r+1],h+=r+2,o*=e},u=[-11,-28,-192,0,256],t.A2m1f=function(t){var e=Math.floor(3);return(s.polyval(e,u,0,s.sq(t))/u[e+1]-t)/(1+t)},p=[1,2,16,32,35,64,384,2048,15,80,768,7,35,512,63,1280,77,2048],t.C2f=function(e,i){var n,r,a=s.sq(e),o=e,h=0;for(n=1;n<=t.nC2_;++n)r=Math.floor((t.nC2_-n)/2),i[n]=o*s.polyval(r,p,h,a)/p[h+r+1],h+=r+2,o*=e},t.Geodesic=function(t,e){if(this.a=t,this.f=e,this._f1=1-this.f,this._e2=this.f*(2-this.f),this._ep2=this._e2/s.sq(this._f1),this._n=this.f/(2-this.f),this._b=this.a*this._f1,this._c2=(s.sq(this.a)+s.sq(this._b)*(0===this._e2?1:(this._e2>0?s.atanh(Math.sqrt(this._e2)):Math.atan(Math.sqrt(-this._e2)))/Math.sqrt(Math.abs(this._e2))))/2,this._etol2=.1*v/Math.sqrt(Math.max(.001,Math.abs(this.f))*Math.min(1,1-this.f/2)/2),!(isFinite(this.a)&&this.a>0))throw new Error("Equatorial radius is not positive");if(!(isFinite(this._b)&&this._b>0))throw new Error("Polar semi-axis is not positive");this._A3x=new Array(6),this._C3x=new Array(r),this._C4x=new Array(a),this.A3coeff(),this.C3coeff(),this.C4coeff()},_=[-3,128,-2,-3,64,-1,-3,-1,16,3,-1,-2,8,1,-1,2,1,1],t.Geodesic.prototype.A3coeff=function(){var t,e,i=0,n=0;for(t=5;t>=0;--t)e=Math.min(6-t-1,t),this._A3x[n++]=s.polyval(e,_,i,this._n)/_[i+e+1],i+=e+2},d=[3,128,2,5,128,-1,3,3,64,-1,0,1,8,-1,1,4,5,256,1,3,128,-3,-2,3,64,1,-3,2,32,7,512,-10,9,384,5,-9,5,192,7,512,-14,7,512,21,2560],t.Geodesic.prototype.C3coeff=function(){var e,i,n,r=0,a=0;for(e=1;e<t.nC3_;++e)for(i=t.nC3_-1;i>=e;--i)n=Math.min(t.nC3_-i-1,i),this._C3x[a++]=s.polyval(n,d,r,this._n)/d[r+n+1],r+=n+2},f=[97,15015,1088,156,45045,-224,-4784,1573,45045,-10656,14144,-4576,-858,45045,64,624,-4576,6864,-3003,15015,100,208,572,3432,-12012,30030,45045,1,9009,-2944,468,135135,5792,1040,-1287,135135,5952,-11648,9152,-2574,135135,-64,-624,4576,-6864,3003,135135,8,10725,1856,-936,225225,-8448,4992,-1144,225225,-1440,4160,-4576,1716,225225,-136,63063,1024,-208,105105,3584,-3328,1144,315315,-128,135135,-2560,832,405405,128,99099],t.Geodesic.prototype.C4coeff=function(){var e,i,n,r=0,a=0;for(e=0;e<t.nC4_;++e)for(i=t.nC4_-1;i>=e;--i)n=t.nC4_-i-1,this._C4x[a++]=s.polyval(n,f,r,this._n)/f[r+n+1],r+=n+2},t.Geodesic.prototype.A3f=function(t){return s.polyval(5,this._A3x,0,t)},t.Geodesic.prototype.C3f=function(e,i){var n,r,a=1,o=0;for(n=1;n<t.nC3_;++n)r=t.nC3_-n-1,a*=e,i[n]=a*s.polyval(r,this._C3x,o,e),o+=r+1},t.Geodesic.prototype.C4f=function(e,i){var n,r,a=1,o=0;for(n=0;n<t.nC4_;++n)r=t.nC4_-n-1,i[n]=a*s.polyval(r,this._C4x,o,e),o+=r+1,a*=e},t.Geodesic.prototype.Lengths=function(e,i,s,n,r,a,o,h,l,c,u,p,_){var d,f,m,y,g={},v=0,x=0,b=0,w=0;if((u&=t.OUT_MASK)&(t.DISTANCE|t.REDUCEDLENGTH|t.GEODESICSCALE)&&(b=t.A1m1f(e),t.C1f(e,p),u&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(w=t.A2m1f(e),t.C2f(e,_),v=b-w,w=1+w),b=1+b),u&t.DISTANCE)d=t.SinCosSeries(!0,a,o,p)-t.SinCosSeries(!0,s,n,p),g.s12b=b*(i+d),u&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(x=v*i+(b*d-w*(t.SinCosSeries(!0,a,o,_)-t.SinCosSeries(!0,s,n,_))));else if(u&(t.REDUCEDLENGTH|t.GEODESICSCALE)){for(f=1;f<=t.nC2_;++f)_[f]=b*p[f]-w*_[f];x=v*i+(t.SinCosSeries(!0,a,o,_)-t.SinCosSeries(!0,s,n,_))}return u&t.REDUCEDLENGTH?(g.m0=v,g.m12b=h*(n*a)-r*(s*o)-n*o*x):g.m12b=NaN,u&t.GEODESICSCALE&&(m=n*o+s*a,y=this._ep2*(l-c)*(l+c)/(r+h),g.M12=m+(y*a-o*x)*s/r,g.M21=m-(y*s-n*x)*a/h),g},t.Geodesic.prototype.InverseStart=function(e,i,n,r,a,h,l,c,u,p,_){var d,f,m,y,v,x,w,S,C,A,E,M,k,I,D,P,T,L,F,N,R={},O=r*i-a*e,G=a*i+r*e;return R.sig12=-1,d=r*i,d+=a*e,(f=G>=0&&O<.5&&a*l<.5)?(y=s.sq(e+r),y/=y+s.sq(i+a),R.dnm=Math.sqrt(1+this._ep2*y),m=l/(this._f1*R.dnm),v=Math.sin(m),x=Math.cos(m)):(v=c,x=u),R.salp1=a*v,R.calp1=x>=0?O+a*e*s.sq(v)/(1+x):d-a*e*s.sq(v)/(1-x),S=s.hypot(R.salp1,R.calp1),C=e*r+i*a*x,f&&S<this._etol2?(R.salp2=i*v,R.calp2=O-i*r*(x>=0?s.sq(v)/(1+x):1-x),w=s.hypot(R.salp2,R.calp2),R.salp2/=w,R.calp2/=w,R.sig12=Math.atan2(S,C)):Math.abs(this._n)>.1||C>=0||S>=6*Math.abs(this._n)*Math.PI*s.sq(i)||(N=Math.atan2(-c,-u),this.f>=0?(I=(k=s.sq(e)*this._ep2)/(2*(1+Math.sqrt(1+k))+k),A=N/(M=this.f*i*this.A3f(I)*Math.PI),E=d/(M*i)):(D=a*i-r*e,P=Math.atan2(d,D),E=l/(M=((A=(T=this.Lengths(this._n,Math.PI+P,e,-i,n,r,a,h,i,a,t.REDUCEDLENGTH,p,_)).m12b/(i*a*T.m0*Math.PI)-1)<-.01?d/A:-this.f*s.sq(i)*Math.PI)/i)),E>-g&&A>-1-b?this.f>=0?(R.salp1=Math.min(1,-A),R.calp1=-Math.sqrt(1-s.sq(R.salp1))):(R.calp1=Math.max(A>-g?0:-1,A),R.salp1=Math.sqrt(1-s.sq(R.calp1))):(L=o(A,E),F=M*(this.f>=0?-A*L/(1+L):-E*(1+L)/L),v=Math.sin(F),x=-Math.cos(F),R.salp1=a*v,R.calp1=d-a*e*s.sq(v)/(1-x))),R.salp1<=0?(R.salp1=1,R.calp1=0):(w=s.hypot(R.salp1,R.calp1),R.salp1/=w,R.calp1/=w),R},t.Geodesic.prototype.Lambda12=function(e,i,n,r,a,o,h,l,c,u,p,_,d,f){var m,y,g,v,x,b,w,S,C,A,E,M,k,I={};return 0===e&&0===l&&(l=-t.tiny_),y=h*i,g=s.hypot(l,h*e),I.ssig1=e,v=y*e,I.csig1=x=l*i,m=s.hypot(I.ssig1,I.csig1),I.ssig1/=m,I.csig1/=m,I.salp2=a!==i?y/a:h,I.calp2=a!==i||Math.abs(r)!==-e?Math.sqrt(s.sq(l*i)+(i<-e?(a-i)*(i+a):(e-r)*(e+r)))/a:Math.abs(l),I.ssig2=r,b=y*r,I.csig2=w=I.calp2*a,m=s.hypot(I.ssig2,I.csig2),I.ssig2/=m,I.csig2/=m,I.sig12=Math.atan2(Math.max(0,I.csig1*I.ssig2-I.ssig1*I.csig2),I.csig1*I.csig2+I.ssig1*I.ssig2),S=Math.max(0,x*b-v*w),C=x*w+v*b,E=Math.atan2(S*u-C*c,C*u+S*c),M=s.sq(g)*this._ep2,I.eps=M/(2*(1+Math.sqrt(1+M))+M),this.C3f(I.eps,f),A=t.SinCosSeries(!0,I.ssig2,I.csig2,f)-t.SinCosSeries(!0,I.ssig1,I.csig1,f),I.domg12=-this.f*this.A3f(I.eps)*y*(I.sig12+A),I.lam12=E+I.domg12,p&&(0===I.calp2?I.dlam12=-2*this._f1*n/e:(k=this.Lengths(I.eps,I.sig12,I.ssig1,I.csig1,n,I.ssig2,I.csig2,o,i,a,t.REDUCEDLENGTH,_,d),I.dlam12=k.m12b,I.dlam12*=this._f1/(I.calp2*a))),I},t.Geodesic.prototype.Inverse=function(e,i,n,r,a){var o,h;return a||(a=t.STANDARD),a===t.LONG_UNROLL&&(a|=t.STANDARD),a&=t.OUT_MASK,h=(o=this.InverseInt(e,i,n,r,a)).vals,a&t.AZIMUTH&&(h.azi1=s.atan2d(o.salp1,o.calp1),h.azi2=s.atan2d(o.salp2,o.calp2)),h},t.Geodesic.prototype.InverseInt=function(e,i,n,r,a){var o,h,l,c,u,p,_,d,f,g,b,w,S,C,A,E,M,k,I,D,P,T,L,F,N,R,O,G,z,q,j,B,U,$,V,W,H,K,Z,X,J,Y,Q,tt,et,it,st,nt,rt,at,ot,ht,lt,ct,ut,pt,_t,dt,ft,mt,yt,gt,vt,xt,bt,wt={};if(wt.lat1=e=s.LatFix(e),wt.lat2=n=s.LatFix(n),e=s.AngRound(e),n=s.AngRound(n),h=(o=s.AngDiff(i,r)).e,o=o.d,a&t.LONG_UNROLL?(wt.lon1=i,wt.lon2=i+o+h):(wt.lon1=s.AngNormalize(i),wt.lon2=s.AngNormalize(r)),h*=l=s.copysign(1,o),A=(o*=l)*s.degree,E=(c=s.sincosde(o,h)).s,M=c.c,h=180-o-h,(u=Math.abs(e)<Math.abs(n)||isNaN(n)?-1:1)<0&&(l*=-1,[n,e]=[e,n]),e*=p=s.copysign(1,-e),n*=p,c=s.sincosd(e),_=this._f1*c.s,d=c.c,_/=c=s.hypot(_,d),d/=c,d=Math.max(t.tiny_,d),c=s.sincosd(n),f=this._f1*c.s,g=c.c,f/=c=s.hypot(f,g),g/=c,g=Math.max(t.tiny_,g),d<-_?g===d&&(f=s.copysign(_,f)):Math.abs(f)===-_&&(g=d),S=Math.sqrt(1+this._ep2*s.sq(_)),C=Math.sqrt(1+this._ep2*s.sq(f)),L=new Array(t.nC1_+1),F=new Array(t.nC2_+1),N=new Array(t.nC3_),(R=-90===e||0===E)&&(D=E,T=0,G=_,z=(I=M)*d,q=f,j=(P=1)*g,k=Math.atan2(Math.max(0,z*q-G*j),z*j+G*q),b=(O=this.Lengths(this._n,k,G,z,S,q,j,C,d,g,a|t.DISTANCE|t.REDUCEDLENGTH,L,F)).s12b,w=O.m12b,a&t.GEODESICSCALE&&(wt.M12=O.M12,wt.M21=O.M21),k<v||w>=0?((k<3*t.tiny_||k<y&&(b<0||w<0))&&(k=w=b=0),w*=this._b,b*=this._b,wt.a12=k/s.degree):R=!1),_t=2,!R&&0===_&&(this.f<=0||h>=180*this.f))I=P=0,D=T=1,b=this.a*A,k=U=A/this._f1,w=this._b*Math.sin(k),a&t.GEODESICSCALE&&(wt.M12=wt.M21=Math.cos(k)),wt.a12=o/this._f1;else if(!R)if(k=(O=this.InverseStart(_,d,S,f,g,C,A,E,M,L,F)).sig12,D=O.salp1,I=O.calp1,k>=0)T=O.salp2,P=O.calp2,$=O.dnm,b=k*this._b*$,w=s.sq($)*this._b*Math.sin(k/$),a&t.GEODESICSCALE&&(wt.M12=wt.M21=Math.cos(k/$)),wt.a12=k/s.degree,U=A/(this._f1*$);else{for(V=0,W=t.tiny_,H=1,K=t.tiny_,Z=-1,X=!1,J=!1;Y=(O=this.Lambda12(_,d,S,f,g,C,D,I,E,M,V<20,L,F,N)).lam12,T=O.salp2,P=O.calp2,k=O.sig12,G=O.ssig1,z=O.csig1,q=O.ssig2,j=O.csig2,B=O.eps,ft=O.domg12,Q=O.dlam12,!J&&Math.abs(Y)>=(X?8:1)*y&&V!=m;++V)Y>0&&(V<20||I/D>Z/K)?(K=D,Z=I):Y<0&&(V<20||I/D<H/W)&&(W=D,H=I),V<20&&Q>0&&(tt=-Y/Q,Math.abs(tt)<Math.PI&&(et=Math.sin(tt),(st=D*(it=Math.cos(tt))+I*et)>0))?(I=I*it-D*et,D=st,D/=c=s.hypot(D,I),I/=c,X=Math.abs(Y)<=16*y):(D=(W+K)/2,I=(H+Z)/2,D/=c=s.hypot(D,I),I/=c,X=!1,J=Math.abs(W-D)+(H-I)<x||Math.abs(D-K)+(I-Z)<x);nt=a|(a&(t.REDUCEDLENGTH|t.GEODESICSCALE)?t.DISTANCE:t.NONE),b=(O=this.Lengths(B,k,G,z,S,q,j,C,d,g,nt,L,F)).s12b,w=O.m12b,a&t.GEODESICSCALE&&(wt.M12=O.M12,wt.M21=O.M21),w*=this._b,b*=this._b,wt.a12=k/s.degree,a&t.AREA&&(xt=Math.sin(ft),_t=E*(bt=Math.cos(ft))-M*xt,dt=M*bt+E*xt)}return a&t.DISTANCE&&(wt.s12=0+b),a&t.REDUCEDLENGTH&&(wt.m12=0+w),a&t.AREA&&(rt=D*d,0!==(at=s.hypot(I,D*_))&&0!==rt?(G=_,z=I*d,q=f,j=P*g,B=(ht=s.sq(at)*this._ep2)/(2*(1+Math.sqrt(1+ht))+ht),lt=s.sq(this.a)*at*rt*this._e2,G/=c=s.hypot(G,z),z/=c,q/=c=s.hypot(q,j),j/=c,ct=new Array(t.nC4_),this.C4f(B,ct),ut=t.SinCosSeries(!1,G,z,ct),pt=t.SinCosSeries(!1,q,j,ct),wt.S12=lt*(pt-ut)):wt.S12=0,R||2!=_t||(_t=Math.sin(U),dt=Math.cos(U)),!R&&dt>-.7071&&f-_<1.75?(ft=1+dt,mt=1+d,yt=1+g,ot=2*Math.atan2(_t*(_*yt+f*mt),ft*(_*f+mt*yt))):(vt=P*I+T*D,0===(gt=T*I-P*D)&&vt<0&&(gt=t.tiny_*I,vt=-1),ot=Math.atan2(gt,vt)),wt.S12+=this._c2*ot,wt.S12*=u*l*p,wt.S12+=0),u<0&&([T,D]=[D,T],[P,I]=[I,P],a&t.GEODESICSCALE&&([wt.M21,wt.M12]=[wt.M12,wt.M21])),{vals:wt,salp1:D*=u*l,calp1:I*=u*p,salp2:T*=u*l,calp2:P*=u*p}},t.Geodesic.prototype.GenDirect=function(i,s,n,r,a,o){return o?o===t.LONG_UNROLL&&(o|=t.STANDARD):o=t.STANDARD,r||(o|=t.DISTANCE_IN),new e.GeodesicLine(this,i,s,n,o).GenPosition(r,a,o)},t.Geodesic.prototype.Direct=function(t,e,i,s,n){return this.GenDirect(t,e,i,!1,s,n)},t.Geodesic.prototype.ArcDirect=function(t,e,i,s,n){return this.GenDirect(t,e,i,!0,s,n)},t.Geodesic.prototype.Line=function(t,i,s,n){return new e.GeodesicLine(this,t,i,s,n)},t.Geodesic.prototype.DirectLine=function(t,e,i,s,n){return this.GenDirectLine(t,e,i,!1,s,n)},t.Geodesic.prototype.ArcDirectLine=function(t,e,i,s,n){return this.GenDirectLine(t,e,i,!0,s,n)},t.Geodesic.prototype.GenDirectLine=function(i,s,n,r,a,o){var h;return o||(o=t.STANDARD|t.DISTANCE_IN),r||(o|=t.DISTANCE_IN),(h=new e.GeodesicLine(this,i,s,n,o)).GenSetDistance(r,a),h},t.Geodesic.prototype.InverseLine=function(i,n,r,a,o){var h,l,c;return o||(o=t.STANDARD|t.DISTANCE_IN),h=this.InverseInt(i,n,r,a,t.ARC),c=s.atan2d(h.salp1,h.calp1),o&t.OUT_MASK&t.DISTANCE_IN&&(o|=t.DISTANCE),(l=new e.GeodesicLine(this,i,n,c,o,h.salp1,h.calp1)).SetArc(h.vals.a12),l},t.Geodesic.prototype.Polygon=function(t){return new i.PolygonArea(this,t)},t.WGS84=new t.Geodesic(n.WGS84.a,n.WGS84.f)}(n.Geodesic,n.GeodesicLine,n.PolygonArea,n.Math,n.Constants),function(t,e,i){e.GeodesicLine=function(e,s,n,r,a,o,h){var l,c,u,p,_,d;a||(a=t.STANDARD|t.DISTANCE_IN),this.a=e.a,this.f=e.f,this._b=e._b,this._c2=e._c2,this._f1=e._f1,this.caps=a|t.LATITUDE|t.AZIMUTH|t.LONG_UNROLL,this.lat1=i.LatFix(s),this.lon1=n,void 0===o||void 0===h?(this.azi1=i.AngNormalize(r),l=i.sincosd(i.AngRound(this.azi1)),this.salp1=l.s,this.calp1=l.c):(this.azi1=r,this.salp1=o,this.calp1=h),l=i.sincosd(i.AngRound(this.lat1)),u=this._f1*l.s,c=l.c,u/=l=i.hypot(u,c),c/=l,c=Math.max(t.tiny_,c),this._dn1=Math.sqrt(1+e._ep2*i.sq(u)),this._salp0=this.salp1*c,this._calp0=i.hypot(this.calp1,this.salp1*u),this._ssig1=u,this._somg1=this._salp0*u,this._csig1=this._comg1=0!==u||0!==this.calp1?c*this.calp1:1,l=i.hypot(this._ssig1,this._csig1),this._ssig1/=l,this._csig1/=l,this._k2=i.sq(this._calp0)*e._ep2,p=this._k2/(2*(1+Math.sqrt(1+this._k2))+this._k2),this.caps&t.CAP_C1&&(this._A1m1=t.A1m1f(p),this._C1a=new Array(t.nC1_+1),t.C1f(p,this._C1a),this._B11=t.SinCosSeries(!0,this._ssig1,this._csig1,this._C1a),_=Math.sin(this._B11),d=Math.cos(this._B11),this._stau1=this._ssig1*d+this._csig1*_,this._ctau1=this._csig1*d-this._ssig1*_),this.caps&t.CAP_C1p&&(this._C1pa=new Array(t.nC1p_+1),t.C1pf(p,this._C1pa)),this.caps&t.CAP_C2&&(this._A2m1=t.A2m1f(p),this._C2a=new Array(t.nC2_+1),t.C2f(p,this._C2a),this._B21=t.SinCosSeries(!0,this._ssig1,this._csig1,this._C2a)),this.caps&t.CAP_C3&&(this._C3a=new Array(t.nC3_),e.C3f(p,this._C3a),this._A3c=-this.f*this._salp0*e.A3f(p),this._B31=t.SinCosSeries(!0,this._ssig1,this._csig1,this._C3a)),this.caps&t.CAP_C4&&(this._C4a=new Array(t.nC4_),e.C4f(p,this._C4a),this._A4=i.sq(this.a)*this._calp0*this._salp0*e._e2,this._B41=t.SinCosSeries(!1,this._ssig1,this._csig1,this._C4a)),this.a13=this.s13=NaN},e.GeodesicLine.prototype.GenPosition=function(e,s,n){var r,a,o,h,l,c,u,p,_,d,f,m,y,g,v,x,b,w,S,C,A,E,M,k,I,D,P={};return n?n===t.LONG_UNROLL&&(n|=t.STANDARD):n=t.STANDARD,n&=this.caps&t.OUT_MASK,P.lat1=this.lat1,P.azi1=this.azi1,P.lon1=n&t.LONG_UNROLL?this.lon1:i.AngNormalize(this.lon1),e?P.a12=s:P.s12=s,e||this.caps&t.DISTANCE_IN&t.OUT_MASK?(h=0,l=0,e?(r=s*i.degree,a=(M=i.sincosd(s)).s,o=M.c):(p=s/(this._b*(1+this._A1m1)),_=Math.sin(p),d=Math.cos(p),r=p-((h=-t.SinCosSeries(!0,this._stau1*d+this._ctau1*_,this._ctau1*d-this._stau1*_,this._C1pa))-this._B11),a=Math.sin(r),o=Math.cos(r),Math.abs(this.f)>.01&&(c=this._ssig1*o+this._csig1*a,u=this._csig1*o-this._ssig1*a,h=t.SinCosSeries(!0,c,u,this._C1a),r-=((1+this._A1m1)*(r+(h-this._B11))-s/this._b)/Math.sqrt(1+this._k2*i.sq(c)),a=Math.sin(r),o=Math.cos(r))),c=this._ssig1*o+this._csig1*a,u=this._csig1*o-this._ssig1*a,S=Math.sqrt(1+this._k2*i.sq(c)),n&(t.DISTANCE|t.REDUCEDLENGTH|t.GEODESICSCALE)&&((e||Math.abs(this.f)>.01)&&(h=t.SinCosSeries(!0,c,u,this._C1a)),l=(1+this._A1m1)*(h-this._B11)),y=this._calp0*c,0===(g=i.hypot(this._salp0,this._calp0*u))&&(g=u=t.tiny_),b=this._salp0,w=this._calp0*u,e&&n&t.DISTANCE&&(P.s12=this._b*((1+this._A1m1)*r+l)),n&t.LONGITUDE&&(v=this._salp0*c,x=u,m=i.copysign(1,this._salp0),f=((n&t.LONG_UNROLL?m*(r-(Math.atan2(c,u)-Math.atan2(this._ssig1,this._csig1))+(Math.atan2(m*v,x)-Math.atan2(m*this._somg1,this._comg1))):Math.atan2(v*this._comg1-x*this._somg1,x*this._comg1+v*this._somg1))+this._A3c*(r+(t.SinCosSeries(!0,c,u,this._C3a)-this._B31)))/i.degree,P.lon2=n&t.LONG_UNROLL?this.lon1+f:i.AngNormalize(i.AngNormalize(this.lon1)+i.AngNormalize(f))),n&t.LATITUDE&&(P.lat2=i.atan2d(y,this._f1*g)),n&t.AZIMUTH&&(P.azi2=i.atan2d(b,w)),n&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(C=t.SinCosSeries(!0,c,u,this._C2a),A=(1+this._A2m1)*(C-this._B21),E=(this._A1m1-this._A2m1)*r+(l-A),n&t.REDUCEDLENGTH&&(P.m12=this._b*(S*(this._csig1*c)-this._dn1*(this._ssig1*u)-this._csig1*u*E)),n&t.GEODESICSCALE&&(M=this._k2*(c-this._ssig1)*(c+this._ssig1)/(this._dn1+S),P.M12=o+(M*c-u*E)*this._ssig1/this._dn1,P.M21=o-(M*this._ssig1-this._csig1*E)*c/S)),n&t.AREA&&(k=t.SinCosSeries(!1,c,u,this._C4a),0===this._calp0||0===this._salp0?(I=b*this.calp1-w*this.salp1,D=w*this.calp1+b*this.salp1):(I=this._calp0*this._salp0*(o<=0?this._csig1*(1-o)+a*this._ssig1:a*(this._csig1*a/(1+o)+this._ssig1)),D=i.sq(this._salp0)+i.sq(this._calp0)*this._csig1*u),P.S12=this._c2*Math.atan2(I,D)+this._A4*(k-this._B41)),e||(P.a12=r/i.degree),P):(P.a12=NaN,P)},e.GeodesicLine.prototype.Position=function(t,e){return this.GenPosition(!1,t,e)},e.GeodesicLine.prototype.ArcPosition=function(t,e){return this.GenPosition(!0,t,e)},e.GeodesicLine.prototype.GenSetDistance=function(t,e){t?this.SetArc(e):this.SetDistance(e)},e.GeodesicLine.prototype.SetDistance=function(e){var i;this.s13=e,i=this.GenPosition(!1,this.s13,t.ARC),this.a13=0+i.a12},e.GeodesicLine.prototype.SetArc=function(e){var i;this.a13=e,i=this.GenPosition(!0,this.a13,t.DISTANCE),this.s13=0+i.s12}}(n.Geodesic,n.GeodesicLine,n.Math),function(t,e,i,s){var n,r,a,o;n=function(t,e){var s=i.AngDiff(t,e).d;return t=i.AngNormalize(t),e=i.AngNormalize(e),s>0&&(t<0&&e>=0||t>0&&0===e)?1:s<0&&t>=0&&e<0?-1:0},r=function(t,e){return(0<=(e%=720)&&e<360||e<-360?0:1)-(0<=(t%=720)&&t<360||t<-360?0:1)},a=function(t,e,i,s,n){return t.Remainder(e),1&i&&t.Add((t.Sum()<0?1:-1)*e/2),s||t.Negate(),n?t.Sum()>e/2?t.Add(-e):t.Sum()<=-e/2&&t.Add(+e):t.Sum()>=e?t.Add(-e):t.Sum()<0&&t.Add(+e),0+t.Sum()},o=function(t,e,s,n,r){return t=i.remainder(t,e),1&s&&(t+=(t<0?1:-1)*e/2),n||(t*=-1),r?t>e/2?t-=e:t<=-e/2&&(t+=e):t>=e?t-=e:t<0&&(t+=e),0+t},t.PolygonArea=function(t,i){this._geod=t,this.a=this._geod.a,this.f=this._geod.f,this._area0=4*Math.PI*t._c2,this.polyline=i||!1,this._mask=e.LATITUDE|e.LONGITUDE|e.DISTANCE|(this.polyline?e.NONE:e.AREA|e.LONG_UNROLL),this.polyline||(this._areasum=new s.Accumulator(0)),this._perimetersum=new s.Accumulator(0),this.Clear()},t.PolygonArea.prototype.Clear=function(){this.num=0,this._crossings=0,this.polyline||this._areasum.Set(0),this._perimetersum.Set(0),this._lat0=this._lon0=this.lat=this.lon=NaN},t.PolygonArea.prototype.AddPoint=function(t,e){var i;0===this.num?(this._lat0=this.lat=t,this._lon0=this.lon=e):(i=this._geod.Inverse(this.lat,this.lon,t,e,this._mask),this._perimetersum.Add(i.s12),this.polyline||(this._areasum.Add(i.S12),this._crossings+=n(this.lon,e)),this.lat=t,this.lon=e),++this.num},t.PolygonArea.prototype.AddEdge=function(t,e){var i;this.num&&(i=this._geod.Direct(this.lat,this.lon,t,e,this._mask),this._perimetersum.Add(e),this.polyline||(this._areasum.Add(i.S12),this._crossings+=r(this.lon,i.lon2)),this.lat=i.lat2,this.lon=i.lon2),++this.num},t.PolygonArea.prototype.Compute=function(t,e){var i,r,o={number:this.num};return this.num<2?(o.perimeter=0,this.polyline||(o.area=0),o):this.polyline?(o.perimeter=this._perimetersum.Sum(),o):(i=this._geod.Inverse(this.lat,this.lon,this._lat0,this._lon0,this._mask),o.perimeter=this._perimetersum.Sum(i.s12),(r=new s.Accumulator(this._areasum)).Add(i.S12),o.area=a(r,this._area0,this._crossings+n(this.lon,this._lon0),t,e),o)},t.PolygonArea.prototype.TestPoint=function(t,e,i,s){var r,a,h,l,c={number:this.num+1};if(0===this.num)return c.perimeter=0,this.polyline||(c.area=0),c;for(c.perimeter=this._perimetersum.Sum(),a=this.polyline?0:this._areasum.Sum(),h=this._crossings,l=0;l<(this.polyline?1:2);++l)r=this._geod.Inverse(0===l?this.lat:t,0===l?this.lon:e,0!==l?this._lat0:t,0!==l?this._lon0:e,this._mask),c.perimeter+=r.s12,this.polyline||(a+=r.S12,h+=n(0===l?this.lon:e,0!==l?this._lon0:e));return this.polyline||(c.area=o(a,this._area0,h,i,s)),c},t.PolygonArea.prototype.TestEdge=function(t,e,i,s){var a,h,l,c={number:this.num?this.num+1:0};return 0===this.num||(c.perimeter=this._perimetersum.Sum()+e,this.polyline||(h=this._areasum.Sum(),l=this._crossings,h+=(a=this._geod.Direct(this.lat,this.lon,t,e,this._mask)).S12,l+=r(this.lon,a.lon2),l+=n(a.lon2,this._lon0),a=this._geod.Inverse(a.lat2,a.lon2,this._lat0,this._lon0,this._mask),c.perimeter+=a.s12,h+=a.S12,c.area=o(h,this._area0,l,i,s))),c}}(n.PolygonArea,n.Geodesic,n.Math,n.Accumulator),s=n,t.exports?t.exports=s:window.geodesic=s}(G);var z=G.exports,q=e({__proto__:null,default:i(z)},[z]);const j=globalThis;"undefined"==typeof window&&(j.window=j.window||{},j.window.document||(j.window.document={}));const B=j.window.modules=j.window.modules||{};B.mproj=S,B.flatbush=E,B.kdbush=T,B["geographiclib-geodesic"]=q;class U{_listeners={};on(t,e){return this._listeners[t]||(this._listeners[t]=[]),this._listeners[t].push(e),this}once(t,e){const i=s=>{this.off(t,i),e(s)};return this.on(t,i)}off(t,e){return this._listeners[t]?(this._listeners[t]=this._listeners[t].filter(t=>t!==e),this):this}fire(t,e){if(!this._listeners[t])return this;const i={type:t,...e};return this._listeners[t].forEach(t=>t(i)),this}}class ${mx;my;bx;by;constructor(t=1,e=1,i=0,s=0){this.mx=t,this.my=e,this.bx=i,this.by=s}static fromBounds(t,e,i=!1){const s=e.width/t.width||1,n=(i?-e.height/t.height:e.height/t.height)||1,r=e.xmin-s*t.xmin,a=i?e.ymax-n*t.ymin:e.ymin-n*t.ymin;return new $(s,n,r,a)}project(t,e){return[t*this.mx+this.bx,e*this.my+this.by]}unproject(t,e){return[(t-this.bx)/this.mx,(e-this.by)/this.my]}translate(t,e){this.bx+=t,this.by+=e}scale(t,e,i){this.bx=e*(1-t)+this.bx*t,this.by=i*(1-t)+this.by*t,this.mx*=t,this.my*=t}clone(){return new $(this.mx,this.my,this.bx,this.by)}}class V{xmin;ymin;xmax;ymax;constructor(t=1/0,e=1/0,i=-1/0,s=-1/0){this.xmin=t,this.ymin=e,this.xmax=i,this.ymax=s}static fromArray(t){return new V(t[0],t[1],t[2],t[3])}get width(){return this.xmax-this.xmin}get height(){return this.ymax-this.ymin}get centerX(){return.5*(this.xmin+this.xmax)}get centerY(){return.5*(this.ymin+this.ymax)}hasBounds(){return this.xmin<=this.xmax&&this.ymin<=this.ymax}clone(){return new V(this.xmin,this.ymin,this.xmax,this.ymax)}mergePoint(t,e){t<this.xmin&&(this.xmin=t),t>this.xmax&&(this.xmax=t),e<this.ymin&&(this.ymin=e),e>this.ymax&&(this.ymax=e)}merge(t){t.hasBounds()&&(t.xmin<this.xmin&&(this.xmin=t.xmin),t.xmax>this.xmax&&(this.xmax=t.xmax),t.ymin<this.ymin&&(this.ymin=t.ymin),t.ymax>this.ymax&&(this.ymax=t.ymax))}fillOut(t,e=.5,i=.5){const s=this.width,n=this.height;let r;return s/n<t?(r=n*t-s,this.xmin-=(1-e)*r,this.xmax+=e*r):(r=s/t-n,this.ymin-=(1-i)*r,this.ymax+=i*r),this}scale(t){const e=this.centerX,i=this.centerY,s=this.width*t,n=this.height*t;this.xmin=e-s/2,this.xmax=e+s/2,this.ymin=i-n/2,this.ymax=i+n/2}}class W extends U{_running=!1;_busy=!1;_tickTime=0;_startTime=0;_duration=1/0;_frame=null;constructor(){super()}start(t){const e=Date.now();this._duration=t||1/0,this._startTime=e,this._running=!0,this._busy||this._startTick(e)}stop(){var t;this._running=!1,null!==this._frame&&(t=this._frame,"function"==typeof cancelAnimationFrame?cancelAnimationFrame(t):clearTimeout(t),this._frame=null),this._busy=!1}_startTick(t){var e;this._busy=!0,this._tickTime=t,this._frame=(e=()=>{this._frame=null,this._onTick()},"function"==typeof requestAnimationFrame?requestAnimationFrame(e):setTimeout(e,25))}_onTick(){const t=Date.now(),e=t-this._startTime,i=Math.min((e+10)/this._duration,1),s=i>=1;this._running?(s&&(this._running=!1),this.fire("tick",{elapsed:e,pct:i,done:s,time:t,tickTime:t-this._tickTime}),this._busy=!1,this._running&&this._startTick(t)):this._busy=!1}}class H extends U{_timer=new W;_startValue=0;_endValue=0;_ease;constructor(t){super(),this._ease=t||null,this._timer.on("tick",t=>this._onTick(t))}start(t,e,i){this._startValue=t,this._endValue=e,this._timer.start(i||500)}stop(){this._timer.stop()}_onTick(t){const e=this._ease?this._ease(t.pct):t.pct,i=this._endValue*e+this._startValue*(1-e);this.fire("change",{value:i})}static sineInOut(t){return.5-Math.cos(t*Math.PI)/2}static quadraticOut(t){return 1-Math.pow(1-t,2)}}const K=18485274.7;class Z{_transform=new $;_extent=new V;_width=0;_height=0;_initialMX=0;_initialExtent=null;_zoomTween=new H(H.sineInOut);_zoomFocus=[0,0];_animatingTransform=null;onViewChange=null;_crs="EPSG:4326";setCRS(t){this._crs=t}get transform(){return this._transform}get extent(){return this._extent}get width(){return this._width}get height(){return this._height}get initialMX(){return this._initialMX}updateSize(t,e){this._width=t,this._height=e}setExtent(t){this._extent=t.clone(),this._initialExtent||(this._initialExtent=t.clone()),this._updateTransform()}reset(){this._initialExtent&&this.setExtent(this._initialExtent)}getCameraState(){const t=this._transform;return{center:[(this._width/2-t.bx)/t.mx,(this._height/2-t.by)/t.my],scale:Math.abs(t.mx)}}applyCameraState(t,e){const i=e,s=-e,n=this._width/2-i*t[0],r=this._height/2-s*t[1];this._transform=new $(i,s,n,r),this._applyConstraints()}clearInitialState(){this._initialExtent=null,this._initialMX=0}_updateTransform(){if(!this._extent.hasBounds())return;const t=this._width/this._height,e=this._extent.clone().fillOut(t),i=new V(0,0,this._width,this._height);this._transform=$.fromBounds(e,i,!0),0===this._initialMX&&(this._initialMX=Math.abs(this._transform.mx),this._initialExtent=e)}pan(t,e){this._transform.translate(t,e),this._applyConstraints()}cancelZoomAnimation(){this._zoomTween.stop(),this._animatingTransform=null}applyWheelZoom(t,e,i,s){const n=1+.12*e,r=t>0?n:1/n;this._transform.scale(r,i,s),this._applyConstraints()}zoomIn(){this._zoomTo(1.15)}zoomOut(){this._zoomTo(1/1.15)}_zoomTo(t){const e=[this._width/2,this._height/2],i=Math.abs(this._transform.mx),s=i*t;this._zoomFocus=e,this._animatingTransform=this._transform.clone(),this._zoomTween.start(i,s,200)}initZoomTween(){this._zoomTween.on("change",t=>{if(!this._animatingTransform)return;const e=t.value/this._animatingTransform.mx,i=this._animatingTransform.clone();i.scale(e,this._zoomFocus[0],this._zoomFocus[1]),this._transform=i,this.onViewChange?.(),t.done&&(this._animatingTransform=null)})}project(t,e){return this._transform.project(t,e)}unproject(t,e){return this._transform.unproject(t,e)}getLineScale(){if(0===this._initialMX)return 1;const t=Math.abs(this._transform.mx)/this._initialMX;let e=1;return t<.5?e*=Math.pow(t+.5,.35):t>30&&(e*=Math.pow(t-29,.065)),e}getArcFilter(t){const e=.1*(1/Math.abs(this._transform.mx)),i=this._initialMX>0?Math.abs(this._transform.mx)/this._initialMX:1,s=i<1?e*i:e,n=this._getViewBounds();return e=>!t.arcIsSmaller?.(e,s)&&!(n&&t.arcIntersectsBBox&&!t.arcIntersectsBBox(e,n))}getViewBounds(){return this._getViewBounds()}_getViewBounds(){if(!this._transform||0===this._width)return null;const t=this._transform,e=-t.bx/t.mx,i=(this._width-t.bx)/t.mx,s=-t.by/t.my,n=(this._height-t.by)/t.my;return[Math.min(e,i),Math.min(s,n),Math.max(e,i),Math.max(s,n)]}_applyConstraints(){const t=this._transform;let e=Math.abs(t.mx);const i=this._getMinMX(),s=this._getMaxMX();(this._crs.toLowerCase().includes("3857")||this._crs.toLowerCase().includes("webmercator"))&&e<i&&(e=i),e>s&&(e=s);const n=t.my>0?e:-e,r=this._getStrictBounds(),a=(this._width/2-t.bx)/t.mx;let o=(this._height/2-t.by)/t.my;if(r){const t=this._height/(2*e),i=r.ymax-t,s=r.ymin+t;s>i?o=(r.ymin+r.ymax)/2:o>i?o=i:o<s&&(o=s)}const h=this._width/2-a*e,l=this._height/2-o*n;this._transform=new $(e,n,h,l)}_getMaxMX(){if(!this._initialExtent)return 1/0;const t=this._initialExtent,e=(...t)=>Math.max(...t.map(Math.abs)),i=e(t.xmin,t.xmax,t.centerX),s=e(t.ymin,t.ymax,t.centerY),n=t.width/this._width/(1e-16*i),r=t.height/this._height/(1e-16*s);return Math.max(n,r)}_getStrictBounds(){const t=this._crs.toLowerCase();return"epsg:3857"===t||"webmercator"===t?new V(-1/0,-18485274.7,1/0,K):null}_getMinMX(){const t=this._crs.toLowerCase();let e;if("epsg:3857"===t||"webmercator"===t)e=36970549.4;else{if("epsg:4326"!==t&&"wgs84"!==t)return.01*this._initialMX;e=180}return this._height/e}}const X=1e-6;class J{_host;_tween=null;_activeEnd=null;constructor(t){this._host=t}_resolve(t){const e=this._host.getCameraState(),i=t.center??e.center;if(s=i,!Number.isFinite(s[0])||!Number.isFinite(s[1]))throw new Error("camera: center must be finite");var s;let n=e.scale;if(void 0!==t.scale)n=t.scale;else if(void 0!==t.zoom){if(!Number.isFinite(t.zoom))throw new Error("camera: zoom must be finite");const e=this._host.scaleFromZoom(t.zoom);if(!Number.isFinite(e))throw new Error("camera: zoom is not meaningful for this CRS — pass { scale } instead");n=e}if(!Number.isFinite(n)||n<=0)throw new Error("camera: scale must be a finite positive number");return{center:[i[0],i[1]],scale:n}}_payload(t){return{center:[t.center[0],t.center[1]],zoom:Math.log2(t.scale),originalEvent:null}}isMoving(){return null!==this._tween}jumpTo(t){const e=this._resolve(t),i=this._host.getCameraState(),s=e.scale!==i.scale;this._cancel();const n=this._payload(e);this._host.fire("movestart",n),s&&this._host.fire("zoomstart",n),this._host.applyCameraState(e.center,e.scale),this._host.requestRender(),this._host.fire("move",n),s&&this._host.fire("zoom",n),this._host.fire("moveend",n),s&&this._host.fire("zoomend",n)}easeTo(t){if(!1===t.animate||0===t.duration)return void this.jumpTo(t);const e=this._resolve(t),i=t.duration??1e3;if(!Number.isFinite(i)||i<0)throw new Error("camera: duration must be a finite non-negative number");const s=t.easing??H.sineInOut;this._cancel();const n=this._host.getCameraState(),r=e.scale!==n.scale,a=Math.log(n.scale),o=Math.log(e.scale),h=this._payload(n);this._host.fire("movestart",h),r&&this._host.fire("zoomstart",h);let l=n;const c=()=>{const t=this._payload(l);this._host.fire("moveend",t),r&&this._host.fire("zoomend",t)};this._activeEnd=c;const u=new H(s);this._tween=u,u.on("change",t=>{const i=t.value;if(i>=1)l=e;else{const t=n.center[0]+(e.center[0]-n.center[0])*i,s=n.center[1]+(e.center[1]-n.center[1])*i,r=Math.exp(a+(o-a)*i);l={center:[t,s],scale:r}}this._host.applyCameraState(l.center,l.scale),this._host.requestRender();const s=this._payload(l);this._host.fire("move",s),r&&this._host.fire("zoom",s),i>=1&&(this._tween=null,this._activeEnd=null,c())}),u.start(0,1,i)}setCenter(t){this.jumpTo({center:t})}setZoom(t){this.jumpTo({zoom:t})}zoomTo(t,e={}){this.easeTo({zoom:t,...e})}panTo(t,e={}){this.easeTo({center:t,...e})}panBy(t,e={}){const{center:i,scale:s}=this._host.getCameraState(),n=[i[0]+t[0]/s,i[1]+t[1]/-s];this.easeTo({center:n,...e})}fitBounds(t,e={}){const{width:i,height:s}=this._host.getViewportSize(),n=e.padding??0,r=Math.max(1,i-2*n),a=Math.max(1,s-2*n),o=[t.centerX,t.centerY],h=t.width,l=t.height;let c;if(!t.hasBounds()||h<=0&&l<=0)c=this._host.getCameraState().scale;else{const t=h>0?r/h:1/0,e=l>0?a/l:1/0;c=Math.min(t,e)}void 0!==e.maxScale&&(c=Math.min(c,e.maxScale)),(!Number.isFinite(c)||c<=0)&&(c=this._host.getCameraState().scale),this.easeTo({center:o,scale:c,...e})}flyTo(t){const e=this._resolve(t);if(!1===t.animate||0===t.duration)return void this.jumpTo(t);let i=t.duration??1e3;if(!Number.isFinite(i)||i<0)throw new Error("camera: duration must be a finite non-negative number");if(null!=t.speed&&(!Number.isFinite(t.speed)||t.speed<=0))throw new Error("camera: speed must be a finite positive number");const s=t.easing??H.sineInOut,n=t.curve??1.42,{width:r}=this._host.getViewportSize();this._cancel();const a=this._host.getCameraState(),o=e.scale!==a.scale,h=Math.hypot(e.center[0]-a.center[0],e.center[1]-a.center[1])*Math.max(a.scale,1e-9),l=r/a.scale,c=r/e.scale,u=n*n;function p(t,e){const i=h||1e-9,s=(c*c-l*l+e*u*u*i*i)/(2*t*u*i);return Math.log(Math.sqrt(s*s+1)-s)}const _=p(l,1),d=p(c,-1),f=h<X?Math.abs(Math.log(c/l))/n:(d-_)/n;null!=t.speed&&(i=1e3*f/t.speed);const m=this._payload(a);this._host.fire("movestart",m),o&&this._host.fire("zoomstart",m);let y=a;const g=()=>{const t=this._payload(y);this._host.fire("moveend",t),o&&this._host.fire("zoomend",t)};this._activeEnd=g;const v=new H(s);this._tween=v,v.on("change",t=>{const i=t.value;let s,c,u;if(h<X){const t=Math.log(a.scale),n=Math.log(e.scale);u=Math.exp(t+(n-t)*i),s=a.center[0]+(e.center[0]-a.center[0])*i,c=a.center[1]+(e.center[1]-a.center[1])*i}else{const t=i*f,o=l*(Math.cosh(_)/Math.cosh(n*t+_));u=r/o,s=a.center[0]+(e.center[0]-a.center[0])*i,c=a.center[1]+(e.center[1]-a.center[1])*i}y={center:[s,c],scale:u},this._host.applyCameraState(y.center,y.scale),this._host.requestRender();const p=this._payload(y);this._host.fire("move",p),o&&this._host.fire("zoom",p),i>=1&&(y=e,this._host.applyCameraState(e.center,e.scale),this._tween=null,this._activeEnd=null,g())}),v.start(0,1,i)}_cancel(){if(this._host.cancelZoomAnimation?.(),this._tween&&(this._tween.stop(),this._tween=null),this._activeEnd){const t=this._activeEnd;this._activeEnd=null,t()}}stop(){this._cancel()}}class Y{snapVertices(e,i,s){t.internal.snapVerticesToPoint(e,i,s)}insertVertex(e,i,s){t.internal.insertVertex(e,i,s)}deleteVertex(e,i){t.internal.deleteVertex(e,i)}appendEmptyArc(e){t.internal.appendEmptyArc(e)}appendVertex(e,i){t.internal.appendVertex(e,i)}deleteLastArc(e){t.internal.deleteLastArc(e)}findNearestVertices(e,i,s){return t.internal.findNearestVertices(e,i,s)}findArcIdFromVertexId(e,i){return t.internal.findArcIdFromVertexId(e,i)}vertexIsArcEndpoint(e,i){return t.internal.vertexIsArcEndpoint(e,i)}forEachSegmentInShape(e,i,s){t.internal.forEachSegmentInShape(e,i,s)}findClosestPointOnSeg(e,i,s,n,r,a,o){return t.internal.findClosestPointOnSeg(e,i,s,n,r,a,o)}addIntersectionCuts(e,i){t.internal.addIntersectionCuts(e,i)}findSegmentIntersections(e,i){return t.internal.findSegmentIntersections(e,i)}getIntersectionLayer(e,i,s){return t.internal.getIntersectionLayer(e,i,s)}getAvgSegment(e){return t.internal.getAvgSegment(e)}simplifyArcsFast(e,i){return t.internal.simplifyArcsFast(e,i)}layerHasGeometry(e){return t.internal.layerHasGeometry(e)}getLayerBounds(e,i){const s=t.internal.getLayerBounds(e,i);return s?{xmin:s.xmin,ymin:s.ymin,xmax:s.xmax,ymax:s.ymax}:{xmin:NaN,ymin:NaN,xmax:NaN,ymax:NaN}}getDatasetBounds(e){const i=t.internal.getDatasetBounds(e);return{xmin:i.xmin,ymin:i.ymin,xmax:i.xmax,ymax:i.ymax}}exportDatasetsToPack(e,i){return t.internal.exportDatasetsToPack(e,i??{})}restoreSessionData(e){return t.internal.restoreSessionData(e)}pack(e){return t.internal.pack(e)}unpackSessionData(e){return t.internal.unpackSessionData(e)}exportPackedDatasets(e,i){return t.internal.exportPackedDatasets(e,i??{})}exportFileContent(e,i){return t.internal.exportFileContent(e,i)}copyDataset(e){return t.internal.copyDataset(e)}runImport(e,i){const s=t.internal.parseCommands(e);return s.length>0&&"i"===s[0].name&&(s[0].options.input=i),new Promise((e,i)=>{t.internal.runParsedCommands(s,new t.internal.Job,(t,s)=>{if(t)return void i(t);const n=s.catalog.getDefaultTargets();0!==n.length?e(n[0].dataset):i(new Error("No layers found in dataset"))})})}runOnDataset(e,i,s){return new Promise((n,r)=>{const a=new t.internal.Job;a.catalog.addDataset(i);const o=t.internal.parseCommands(e);if(s)for(const t of o)t.options&&(t.options.input=s);t.internal.runParsedCommands(o,a,(t,e)=>{if(t)return void r(t);const i=e.catalog.getDefaultTargets();0!==i.length?n(i[0].dataset):r(new Error("mapshaper command completed but produced no default target"))})})}runOnDatasetParsed(e,i,s){return new Promise((n,r)=>{const a=new t.internal.Job;if(a.catalog.addDataset(i),s)for(const t of e)t.options&&(t.options.input=s);t.internal.runParsedCommands(e,a,(t,e)=>{if(t)return void r(t);const i=e.catalog.getDefaultTargets();0!==i.length?n(i[0].dataset):r(new Error("mapshaper command completed but produced no default target"))})})}}let Q=null;function tt(){return Q??(Q=new Y)}function et(t){Q=t}const it=6378137,st=40075016.6855;class nt{_crs="EPSG:4326";get crs(){return this._crs}setCRS(t){this._crs=t}getCenter(t,e){const i=this._crs.toLowerCase();return"epsg:3857"===i||"webmercator"===i?this._webMercatorToLatLng(t,e):[t,e]}getZoom(t){const e=this._crs.toLowerCase();return"epsg:3857"===e||"webmercator"===e?Math.log2(t*st/512):0}getScale(t){const e=this._crs.toLowerCase();return"epsg:3857"===e||"webmercator"===e?512*Math.pow(2,t)/st:NaN}async reproject(t,e){for(const i of e.values())i.reproject&&await i.reproject(t);this._crs=t;const i=tt(),s=new V;for(const t of e.values()){const e=t.getDataset();if(e?.layers)for(const t of e.layers)if(i.layerHasGeometry(t)){const n=i.getLayerBounds(t,e.arcs);n&&s.merge(new V(n.xmin,n.ymin,n.xmax,n.ymax))}}return s.hasBounds()&&s.scale(1.07),s}_webMercatorToLatLng(t,e){const i=180/Math.PI;return[t/it*i,i*(.5*Math.PI-2*Math.atan(Math.exp(-e/it)))]}}function rt(t,e){return t?.name?String(t.name):t?.id?String(t.id):`layer-${e}`}function at(t){return t&&Array.isArray(t)?"number"==typeof t[0]?[t]:Array.isArray(t[0])?t:[]:[]}class ot{_canvas;_ctx;_transform=new $;_pixelRatio=window.devicePixelRatio||1;constructor(t){this._canvas=t;const e=t.getContext("2d");if(!e)throw new Error("Failed to get 2D context");this._ctx=e}setTransform(t){this._transform=t}setPixelRatio(t){this._pixelRatio=t}drawPaths(t,e,i){if(0===e.width)return;const s=this._ctx;s.strokeStyle=e.color||"#333",s.lineWidth=(e.width??1)*this._pixelRatio,s.lineCap="round",s.lineJoin="round";let n=0;s.beginPath(),t.forEach(t=>{t&&t.forEach(t=>{t.forEach(t=>{n>0&&n%25==0&&(s.stroke(),s.beginPath());const e=i.getArcIter(t);this.drawPathSnapping(e,s),n++})})}),s.stroke()}drawArcs(t,e,i){if(0===e.width)return;const s=this._ctx,n=t.size();s.strokeStyle=e.color||"#333",s.lineWidth=(e.width??1)*this._pixelRatio,s.lineCap="round",s.lineJoin="round";let r=0;s.beginPath();for(let e=0;e<n;e++){if(i&&!i(e))continue;r>0&&r%25==0&&(s.stroke(),s.beginPath());const n=t.getArcIter(e);this.drawPathSnapping(n,s),r++}s.stroke()}drawPathSnapping(t,e){const i=this._transform.mx*this._pixelRatio,s=this._transform.my*this._pixelRatio,n=this._transform.bx*this._pixelRatio,r=this._transform.by*this._pixelRatio;let a,o,h,l,c=0;if(t.hasNext()){for(a=2*(t.x*i+n)|0,o=2*(t.y*s+r)|0,e.moveTo(a/2,o/2);t.hasNext();)h=a,l=o,a=2*(t.x*i+n)|0,o=2*(t.y*s+r)|0,a===h&&o===l||(e.lineTo(a/2,o/2),c++);0===c&&e.lineTo(a/2+.1,o/2)}}drawPoints(t,e){const i=this._ctx,s=this._pixelRatio,n=this._transform.mx*s,r=this._transform.my*s,a=this._transform.bx*s,o=this._transform.by*s,h=(Number(e?.radius)||4)*s,l=e?.color||"#333",c=!1!==e?.fill;i.beginPath(),i.fillStyle=l,i.strokeStyle=l,t.forEach(t=>{if(!t)return;at(t).forEach(t=>{const e=t[0]*n+a,s=t[1]*r+o;i.moveTo(e+h,s),i.arc(e,s,h,0,2*Math.PI)})}),c?i.fill():i.stroke()}drawVertexDots(t,e,i={}){const s=this._ctx,n=this._pixelRatio,r=this._transform.mx*n,a=this._transform.my*n,o=this._transform.bx*n,h=this._transform.by*n,l=i.dotColor||"#333",c=(i.dotRadius||3)*n,u=i.hoverColor||"#cc6acc",p=(i.hoverRadius||6)*n,_=i.hoverVertex;let d=null;_&&(d=[_[0]*r+o,_[1]*a+h]),s.fillStyle=l,s.beginPath(),t.forEach(t=>{t&&t.forEach(t=>{t.forEach(t=>{const i=t>=0?t:~t,n=e.getArcIter(i);for(;n.hasNext();){const t=n.x*r+o,e=n.y*a+h;d&&Math.abs(t-d[0])<1&&Math.abs(e-d[1])<1||(s.moveTo(t+c,e),s.arc(t,e,c,0,2*Math.PI))}})})}),s.fill(),d&&(s.fillStyle=u,s.beginPath(),"interpolated"===i.hoverType?s.rect(d[0]-p,d[1]-p,2*p,2*p):s.arc(d[0],d[1],p,0,2*Math.PI),s.fill())}drawPolygonFill(t,e,i,s,n){if(!e.getShapeIter)return;const r=this._ctx,a=this._pixelRatio,o=this._transform.mx*a,h=this._transform.my*a,l=this._transform.bx*a,c=this._transform.by*a;r.fillStyle=i;const u="number"==typeof n&&1!==n,p=r.globalAlpha;u&&(r.globalAlpha=p*Math.max(0,Math.min(1,n)));let _=0;r.beginPath();for(let i=0;i<t.length;i++){const n=t[i];if(!n)continue;let a=!0;if(s){a=!1;for(const t of n){for(const e of t){if(s(e>=0?e:~e)){a=!0;break}}if(a)break}}if(a){_>0&&_>=100&&(r.fill("evenodd"),r.beginPath(),_=0);for(const t of n){const i=e.getShapeIter(t);if(!i.hasNext())continue;let s,n,a=2*(i.x*o+l)|0,u=2*(i.y*h+c)|0;for(r.moveTo(a/2,u/2);i.hasNext();)s=a,n=u,a=2*(i.x*o+l)|0,u=2*(i.y*h+c)|0,a===s&&u===n||r.lineTo(a/2,u/2);r.closePath()}_++}}_>0&&r.fill("evenodd"),u&&(r.globalAlpha=p)}drawDrawingOverlay(t){const e=this._ctx,i=this._pixelRatio,s=this._transform.mx*i,n=this._transform.my*i,r=this._transform.bx*i,a=this._transform.by*i,o=t.drawColor||"#0078ff",h=t.vertices,l=t.cursorCoord,c=t=>[t[0]*s+r,t[1]*n+a];if(h.length>0){e.strokeStyle=o,e.lineWidth=2*i,e.lineJoin="round",e.lineCap="round",e.setLineDash([]),e.beginPath();const t=c(h[0]);e.moveTo(t[0],t[1]);for(let t=1;t<h.length;t++){const i=c(h[t]);e.lineTo(i[0],i[1])}e.stroke()}if(h.length>0&&l){const s=c(h[h.length-1]),n=c(l);if(e.strokeStyle=o,e.lineWidth=1.5*i,e.setLineDash([6*i,4*i]),e.beginPath(),e.moveTo(s[0],s[1]),e.lineTo(n[0],n[1]),"polygon"===t.geometryType&&h.length>=2){const t=c(h[0]);e.moveTo(n[0],n[1]),e.lineTo(t[0],t[1])}e.stroke(),e.setLineDash([])}if(h.length>0){const t=4*i;e.fillStyle=o,e.beginPath();for(const i of h){const s=c(i);e.moveTo(s[0]+t,s[1]),e.arc(s[0],s[1],t,0,2*Math.PI)}e.fill()}if(t.snapCoord){const s=c(t.snapCoord),n=7*i;e.strokeStyle="#ff4444",e.lineWidth=2*i,e.beginPath(),"edge"===t.snapKind?e.rect(s[0]-n,s[1]-n,2*n,2*n):e.arc(s[0],s[1],n,0,2*Math.PI),e.stroke()}}clear(){this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height)}resize(t,e){const i=this._pixelRatio;this._canvas.width=t*i,this._canvas.height=e*i,this._canvas.style.width=t+"px",this._canvas.style.height=e+"px"}}class ht{_painter;constructor(t){this._painter=t}render(t,e,i){"vertex"===t&&e?this._renderVertexOverlay(e):"draw"===t&&i&&this._painter.drawDrawingOverlay(i)}_renderVertexOverlay(t){const e=t.arcs;"polygon"===t.geometryType&&t.polygonFill&&this._painter.drawPolygonFill(t.shapes,e,t.polygonFill),this._painter.drawVertexDots(t.shapes,e,{dotColor:"#333",dotRadius:3,hoverVertex:t.hoverVertex,hoverType:t.hoverType??"vertex",hoverColor:"#cc6acc",hoverRadius:6})}}class lt{opts;label;invalidatesPriorCommands=!0;constructor(t){this.opts=t,this.label=t.label}do(){this.opts.source.setDataset(this.opts.after)}undo(){this.opts.source.setDataset(this.opts.before)}}const ct=Object.freeze({ok:!0,value:void 0});function ut(t){return{ok:!0,value:t}}const pt=Object.freeze({notFound:(t,e)=>({ok:!1,error:{kind:"not-found",what:t,id:e}}),validation:(t,e)=>({ok:!1,error:{kind:"validation",field:t,reason:e}}),expressionDisabled:t=>({ok:!1,error:{kind:"expression-disabled",operation:t}}),mapshaper:(t,e)=>({ok:!1,error:{kind:"mapshaper",cause:t,...e??{}}}),hostRemoved:()=>({ok:!1,error:{kind:"host-removed"}})}),_t=new Set(["rename-fields","rename-layers","sort","sort-features","filter-fields","drop","target","uniq","unique-features"]),dt=new Set(["buffer","clean","dissolve","mosaic","union","snap","check-geometry","simplify"]);function ft(t){const e=[],i=/(?:^|\s)-([a-z][a-z-]*)/gi;let s;for(;null!==(s=i.exec(t));)e.push(s[1].toLowerCase());return e}function mt(t,e,i,s){if(!1===i)return!1;if(!0===i)return!0;if(0===t.length)return e>=s;if(t.every(t=>_t.has(t)))return!1;return e>=(t.some(t=>dt.has(t))?Math.floor(.5*s):s)}const yt={clip:"shape-count",erase:"shape-count",dissolve:"shape-count",explode:"shape-count",filter:"shape-count","filter-geom":"shape-count","filter-islands":"shape-count","filter-slivers":"shape-count","merge-layers":"shape-count",mosaic:"shape-count",union:"shape-count",divide:"shape-count",points:"shape-count",lines:"shape-count",polygons:"shape-count",innerlines:"shape-count",split:"shape-count","split-layer":"shape-count",uniq:"shape-count",buffer:"shape-count",drop:"shape-count","intersection-points":"shape-count",clean:"topology-only",snap:"topology-only",simplify:"topology-only","rebuild-topology":"topology-only",each:"attribute-only",join:"attribute-only","rename-fields":"attribute-only","rename-layers":"attribute-only","filter-fields":"attribute-only","data-fill":"attribute-only",sort:"attribute-only",proj:"crs-only",project:"crs-only",affine:"crs-only"};function gt(t){let e="attribute-only",i=!1;for(const s of t){if("target"===s)continue;const t=yt[s];if(void 0===t)return"unknown";i=!0,e=xt(e,t)}return i?e:"unknown"}const vt={"attribute-only":0,"crs-only":1,"topology-only":2,"shape-count":3,unknown:3};function xt(t,e){return vt[t]>=vt[e]?t:e}async function bt(t,e,i,s,n){if(t._removed)return pt.hostRemoved();const r=t._sources.get(e);if(!r)return pt.notFound("source",e);const a=r.getDataset();if(!a)return pt.notFound("source",e);const o=tt().copyDataset(a);let h,l=!1;if(t._workerPool){const e=a.arcs?.getPointCount?.()??0,s=function(t,e,i,s){return!1!==i&&(!0===i||mt(ft(t),e,i,s))}(i,e,t._workerMode,t._workerThreshold),n=t._workerRouting;l=n?n({cmd:i,heads:ft(i),vertexCount:e,mode:t._workerMode,threshold:t._workerThreshold,defaultDecision:s}):s}try{h=l?await async function(t,e,i,s,n){if(!t._workerPool)throw new Error("_runViaWorker: worker pool not available");const r=t._workerPool.reserveId(),a=e.arcs?.getPointCount?.()??0,o="undefined"!=typeof performance?performance.now():Date.now();t.fire("workerjobstart",{id:r,cmd:i,label:s,datasetVertexCount:a});try{const s=await tt().exportDatasetsToPack([e],{compact:!1}),a=Ct(s),h=t._workerPool.dispatchWithId(r,i,s,n,a),l=await h,c=await tt().restoreSessionData(l);if(!c.datasets||0===c.datasets.length)throw new Error("worker: no dataset in response");const u=("undefined"!=typeof performance?performance.now():Date.now())-o;return t.fire("workerjobend",{id:r,ok:!0,durationMs:u}),c.datasets[0]}catch(e){const i=("undefined"!=typeof performance?performance.now():Date.now())-o;throw t.fire("workerjobend",{id:r,ok:!1,durationMs:i,errorMessage:e?.message??String(e)}),e}}(t,a,i,s,n):await tt().runOnDataset(i,a,n)}catch(e){return t._removed?pt.hostRemoved():(t.fire("error",{error:e}),pt.mapshaper(e,{cmd:i,operation:s}))}return t._removed?pt.hostRemoved():St(t,e,o,h,s,function(t){return gt(ft(t))}(i))}async function wt(t,e,i,s,n){if(t._removed)return pt.hostRemoved();const r=t._sources.get(e);if(!r)return pt.notFound("source",e);const a=r.getDataset();if(!a)return pt.notFound("source",e);const o=tt().copyDataset(a),h=i.map(t=>t.name);let l,c=!1;if(t._workerPool){const e=a.arcs?.getPointCount?.()??0,i=mt(h,e,t._workerMode,t._workerThreshold),s=t._workerRouting;c=s?s({cmd:h.map(t=>`-${t}`).join(" "),heads:h,vertexCount:e,mode:t._workerMode,threshold:t._workerThreshold,defaultDecision:i}):i}try{l=c?await async function(t,e,i,s,n){if(!t._workerPool)throw new Error("_runViaWorkerParsed: worker pool not available");const r=t._workerPool.reserveId(),a=e.arcs?.getPointCount?.()??0,o="undefined"!=typeof performance?performance.now():Date.now(),h=i.map(t=>`-${t.name}`).join(" ");t.fire("workerjobstart",{id:r,cmd:h,label:s,datasetVertexCount:a});try{const s=await tt().exportDatasetsToPack([e],{compact:!1}),a=Ct(s),h=t._workerPool.dispatchWithId(r,i,s,n,a),l=await h,c=await tt().restoreSessionData(l);if(!c.datasets||0===c.datasets.length)throw new Error("worker: no dataset in response");const u=("undefined"!=typeof performance?performance.now():Date.now())-o;return t.fire("workerjobend",{id:r,ok:!0,durationMs:u}),c.datasets[0]}catch(e){const i=("undefined"!=typeof performance?performance.now():Date.now())-o;throw t.fire("workerjobend",{id:r,ok:!1,durationMs:i,errorMessage:e?.message??String(e)}),e}}(t,a,i,s,n):await tt().runOnDatasetParsed(i,a,n)}catch(e){return t._removed?pt.hostRemoved():(t.fire("error",{error:e}),pt.mapshaper(e,{operation:s}))}return t._removed?pt.hostRemoved():St(t,e,o,l,s,gt(h))}function St(t,e,i,s,n,r="unknown"){const a=t._sources.get(e);return a?(t._activeTransaction&&t._activeTransaction._captureFirstTouch(e,i),a.setDataset(s),t._history.push(new lt({source:a,before:i,after:s,label:n})),t._history.isCapturing()||t._fireHistoryChange(),function(t){return"shape-count"===t||"topology-only"===t||"unknown"===t}(r)&&t._fireSelectionChange(t._selection.clear()),t._scheduleRender(),ct):pt.notFound("source",e)}function Ct(t){const e=[],i=new Set,s=t=>{if(t&&"object"==typeof t){if(t instanceof Uint8Array){const s=t.buffer;return void(s instanceof ArrayBuffer&&!i.has(s)&&(i.add(s),e.push(s)))}if(t instanceof ArrayBuffer)i.has(t)||(i.add(t),e.push(t));else if(Array.isArray(t))for(const e of t)s(e);else for(const e of Object.keys(t))s(t[e])}};return s(t),e}function At(t,e){for(let i=0;i<t.length;i++){const s=t[i];if(s){if(rt(s,i)===e)return s;if(s.name===e)return s;if(s.id===e)return s}}return null}class Et{_sources;constructor(t){this._sources=t}resolve(t,e){const i=this._sources.get(t);return i?At(i.getLayers(),e):null}resolveInLayers(t,e){return At(t,e)}}async function Mt(t,e,i){const s=t.host._sources.get(e.source);if(!s)return pt.notFound("source",e.source);const n=s.getDataset();if(!n)return pt.notFound("source",e.source);if(!At(n.layers,e.target))return pt.notFound("layer",e.target);const r="string"==typeof e.mask&&e.mask.length>0;if(r===Array.isArray(e.bbox))return pt.validation(r?"mask":"bbox","must supply exactly one of `mask` or `bbox`");if(r){if(!At(n.layers,e.mask))return pt.notFound("mask",e.mask)}else{const t=e.bbox;if(4!==t.length||!t.every(t=>Number.isFinite(t)))return pt.validation("bbox","must be [xmin, ymin, xmax, ymax] of finite numbers");if(t[0]>=t[2]||t[1]>=t[3])return pt.validation("bbox","must satisfy xmin<xmax and ymin<ymax")}const a=r?{source:e.mask}:{bbox:e.bbox};e.cleanup&&(a.cleanup=!0),e.removeSlivers&&(a.remove_slivers=!0);const o="clip"===i?"Clip":"Erase";return t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:i,options:a}],`${o} ${e.target}`)}const kt="__emap_merge";async function It(t){const e=t.host._selection.getAll();if(0===e.length)return pt.validation("selection","selection is empty");const i=e[0].source,s=e[0].layer;for(const t of e)if(t.source!==i||t.layer!==s)return pt.validation("selection","selection spans multiple sources or layers");const n=t.host.layers.resolve(i,s);if(!n)return pt.notFound("layer",s);if(!function(t,e){const i=t.data?.getRecords?.();if(!i||0===i.length)return!1;const s=new Set(e);for(let t=0;t<i.length;t++){const e=i[t]??{};e[kt]=s.has(t)?"M":`k_${t}`,i[t]=e}return!0}(n,e.map(t=>t.id).slice().sort((t,e)=>t-e)))return pt.validation("layer","layer has no data table; cannot stamp discriminator");const r=function(t,e){const i={fields:[kt]},s=e.data?.getFields?.();if(s&&s.length>0){const t=s.filter(t=>t!==kt&&!t.includes(","));t.length>0&&(i.copy_fields=t)}return[{name:"target",options:{target:t}},{name:"dissolve",options:i},{name:"filter-fields",options:{fields:[kt],invert:!0}}]}(s,n),a=`Merge ${e.length} feature${e.length>1?"s":""}`,o=await t.runDatasetCommandParsed(i,r,a);return o.ok||function(t){const e=t.data?.getRecords?.();if(!e)return;for(const t of e)t&&kt in t&&delete t[kt]}(n),o}const Dt=new Set(["left","right","outer","inner"]),Pt=new Set(["flat","round"]),Tt=/^-?\d+(\.\d+)?$/;function Lt(t){return"number"==typeof t&&Number.isInteger(t)&&t>0}async function Ft(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);const n=At(s.layers,e.target);if(!n)return pt.notFound("layer",e.target);if("number"==typeof e.radius){if(!Number.isFinite(e.radius)||e.radius<=0)return pt.validation("radius","must be a positive finite number")}else{if("string"!=typeof e.radius||0===e.radius.trim().length)return pt.validation("radius","must be a positive number or non-empty expression");if(Tt.test(e.radius)&&Number(e.radius)<=0)return pt.validation("radius","numeric string must be a positive number")}if("string"==typeof e.radius&&!t.host._allowExpressionEvaluation([e.radius],"bufferLayer"))return pt.expressionDisabled("bufferLayer");if(void 0!==e.vertices&&!Lt(e.vertices))return pt.validation("vertices","must be a positive integer");if(void 0!==e.arcQuality&&!Lt(e.arcQuality))return pt.validation("arcQuality","must be a positive integer");if(void 0!==e.sliceLength&&!Lt(e.sliceLength))return pt.validation("sliceLength","must be a positive integer");if(void 0!==e.backtrack&&!Lt(e.backtrack))return pt.validation("backtrack","must be a positive integer");if(void 0!==e.tolerance&&!("number"==typeof(r=e.tolerance)&&Number.isFinite(r)&&r>0))return pt.validation("tolerance","must be a positive finite number");var r;if(void 0!==e.type&&!Dt.has(e.type))return pt.validation("type","must be one of: left, right, outer, inner");if(void 0!==e.capStyle&&!Pt.has(e.capStyle))return pt.validation("capStyle","must be one of: flat, round");void 0!==e.type&&"polygon"===n.geometry_type&&console.warn(`bufferLayer: type="${e.type}" is intended for polyline layers; applying to polygon layer "${e.target}" may produce unexpected output.`);const a={radius:String(e.radius)};void 0!==e.capStyle&&(a.cap_style=e.capStyle),void 0!==e.vertices&&(a.vertices=e.vertices),void 0!==e.arcQuality&&(a.arc_quality=e.arcQuality),void 0!==e.tolerance&&(a.tolerance=e.tolerance),void 0!==e.type&&(a.type=e.type),!0===e.planar&&(a.planar=!0),!0===e.v2&&(a.v2=!0),void 0!==e.sliceLength&&(a.slice_length=e.sliceLength),void 0!==e.backtrack&&(a.backtrack=e.backtrack);const o=[{name:"target",options:{target:e.target}},{name:"buffer",options:a}];return t.runDatasetCommandParsed(e.source,o,`Buffer ${e.target}`)}class Nt{_emap;constructor(t){this._emap=t}get _ctx(){return{host:this._emap,runDatasetCommand:(t,e,i,s)=>bt(this._emap,t,e,i,s),runDatasetCommandParsed:(t,e,i,s)=>wt(this._emap,t,e,i,s),applyDatasetReplace:(t,e,i,s)=>St(this._emap,t,e,i,s)}}clipLayer(t){return async function(t,e){return Mt(t,e,"clip")}(this._ctx,t)}eraseLayer(t){return async function(t,e){return Mt(t,e,"erase")}(this._ctx,t)}dissolveLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);const n=Array.isArray(e.fields)&&e.fields.length>0;if(void 0!==e.field&&n)return pt.validation("field","`field` and `fields` are mutually exclusive");if(void 0!==e.field&&("string"!=typeof e.field||e.field.includes(",")))return pt.validation("field","field name must be a string without `,`");if(!t.host._allowExpressionEvaluation([e.calc,e.where],"dissolveLayer"))return pt.expressionDisabled("dissolveLayer");const r={};if(e.field)r.fields=[e.field];else if(n){const t=e.fields.filter(t=>"string"==typeof t&&!t.includes(","));t.length>0&&(r.fields=t)}const a=t=>Array.isArray(t)?t.filter(t=>"string"==typeof t&&!t.includes(",")):[],o=a(e.sumFields);o.length>0&&(r.sum_fields=o);const h=a(e.copyFields);return h.length>0&&(r.copy_fields=h),e.calc&&e.calc.trim()&&(r.calc=e.calc),e.where&&e.where.trim()&&(r.where=e.where),e.multipart&&(r.multipart=!0),e.name&&e.name.trim()&&(r.name=e.name),e.noReplace&&(r.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"dissolve",options:r}],`Dissolve ${e.target}`)}(this._ctx,t)}bufferLayer(t){return Ft(this._ctx,t)}applyExpression(t){return async function(t,e){if(!e.expression||!e.expression.trim())return pt.validation("expression","must be a non-empty expression");const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.expression,e.where],"applyExpression"))return pt.expressionDisabled("applyExpression");const n={expression:e.expression};return e.where&&e.where.trim()&&(n.where=e.where),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"each",options:n}],`Update ${e.target}`)}(this._ctx,t)}filterFeatures(t){return async function(t,e){const i=!(!e.expression||!e.expression.trim());if(!i&&!e.removeEmpty)return pt.validation("expression","must supply `expression` or `removeEmpty: true`");const s=t.host._sources.get(e.source);if(!s)return pt.notFound("source",e.source);const n=s.getDataset();if(!n)return pt.notFound("source",e.source);if(!At(n.layers,e.target))return pt.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.expression],"filterFeatures"))return pt.expressionDisabled("filterFeatures");const r={};return i&&(r.expression=e.expression),e.invert&&(r.invert=!0),e.removeEmpty&&(r.remove_empty=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"filter",options:r}],`Filter ${e.target}`)}(this._ctx,t)}filterIslands(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);const n="number"==typeof e.minArea&&Number.isFinite(e.minArea),r="number"==typeof e.minVertices&&Number.isInteger(e.minVertices)&&e.minVertices>0;if(!n&&!r)return pt.validation("minArea","must supply at least one of `minArea` or `minVertices`");if(n&&e.minArea<0)return pt.validation("minArea","must be non-negative");const a={};return n&&(a.min_area=String(e.minArea)),r&&(a.min_vertices=e.minVertices),e.removeEmpty&&(a.remove_empty=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"filter-islands",options:a}],`Filter islands ${e.target}`)}(this._ctx,t)}filterSlivers(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);if("number"!=typeof e.minArea||!Number.isFinite(e.minArea)||e.minArea<=0)return pt.validation("minArea","must be a positive finite number");const n={min_area:String(e.minArea)};return e.weighted&&(n.weighted=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"filter-slivers",options:n}],`Filter slivers ${e.target}`)}(this._ctx,t)}filterGeom(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);const n=e.bbox;return Array.isArray(n)&&4===n.length&&n.every(t=>Number.isFinite(t))?n[0]>=n[2]||n[1]>=n[3]?pt.validation("bbox","must satisfy xmin<xmax and ymin<ymax"):t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"filter-geom",options:{bbox:[n[0],n[1],n[2],n[3]]}}],`Filter geom ${e.target}`):pt.validation("bbox","must be [xmin, ymin, xmax, ymax] of finite numbers")}(this._ctx,t)}explodeLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();return s?At(s.layers,e.target)?t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"explode",options:{}}],`Explode ${e.target}`):pt.notFound("layer",e.target):pt.notFound("source",e.source)}(this._ctx,t)}innerlinesLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.where],"innerlinesLayer"))return pt.expressionDisabled("innerlinesLayer");const n={};return e.where&&e.where.trim()&&(n.where=e.where),e.name&&e.name.trim()&&(n.name=e.name),e.noReplace&&(n.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"innerlines",options:n}],`Innerlines ${e.target}`)}(this._ctx,t)}snapLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);const n={};return"number"==typeof e.interval&&(n.interval=String(e.interval)),e.endpoints&&(n.endpoints=!0),"number"==typeof e.precision&&(n.precision=e.precision),e.fixGeometry&&(n.fix_geometry=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"snap",options:n}],`Snap ${e.target}`)}(this._ctx,t)}cleanLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);const n=t=>void 0===t||"number"==typeof t&&Number.isFinite(t)&&t>=0;if(!n(e.gapFillArea))return pt.validation("gapFillArea","must be a finite non-negative number");if(!n(e.sliverControl))return pt.validation("sliverControl","must be a finite non-negative number");if(!n(e.snapInterval))return pt.validation("snapInterval","must be a finite non-negative number");if(void 0!==e.overlapRule){const t=["min-id","max-id","min-area","max-area"];if(!t.includes(e.overlapRule))return pt.validation("overlapRule",`must be one of ${t.join(", ")}`)}const r={};return void 0!==e.gapFillArea&&(r.gap_fill_area=String(e.gapFillArea)),void 0!==e.sliverControl&&(r.sliver_control=e.sliverControl),void 0!==e.snapInterval&&(r.snap_interval=String(e.snapInterval)),e.noSnap&&(r.no_snap=!0),e.allowOverlaps&&(r.allow_overlaps=!0),void 0!==e.overlapRule&&(r.overlap_rule=e.overlapRule),e.allowEmpty&&(r.allow_empty=!0),e.rewind&&(r.rewind=!0),e.onlyArcs&&(r.only_arcs=!0),e.noArcDissolve&&(r.no_arc_dissolve=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"clean",options:r}],`Clean ${e.target}`)}(this._ctx,t)}mosaicLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.calc],"mosaicLayer"))return pt.expressionDisabled("mosaicLayer");const n={};return"number"==typeof e.snapInterval&&(n.snap_interval=String(e.snapInterval)),e.noSnap&&(n.no_snap=!0),e.noReplace&&(n.no_replace=!0),e.name&&e.name.trim()&&(n.name=e.name),e.calc&&e.calc.trim()&&(n.calc=e.calc),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"mosaic",options:n}],`Mosaic ${e.target}`)}(this._ctx,t)}unionLayers(t){return async function(t,e){if(!e.targets||e.targets.length<2)return pt.validation("targets","must supply at least 2 target layers");const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);for(const t of e.targets){if("string"!=typeof t||t.includes(","))return pt.validation("targets",`target name must not contain ',': ${String(t)}`);if(!At(s.layers,t))return pt.notFound("layer",t)}const n=e.targets.join(","),r={};if(e.fields&&e.fields.length>0){const t=e.fields.filter(t=>!t.includes(","));t.length>0&&(r.fields=t)}return e.name&&e.name.trim()&&(r.name=e.name),e.noReplace&&(r.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:n}},{name:"union",options:r}],`Union ${n}`)}(this._ctx,t)}divideLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);const n=At(s.layers,e.target);if(!n)return pt.notFound("layer",e.target);if("polyline"!==n.geometry_type)return pt.validation("target",`expected polyline layer, got ${n.geometry_type??"unknown"}`);const r=At(s.layers,e.divider);if(!r)return pt.notFound("divider",e.divider);if("polygon"!==r.geometry_type)return pt.validation("divider",`expected polygon layer, got ${r.geometry_type??"unknown"}`);const a={source:e.divider};if(e.fields&&e.fields.length>0){const t=e.fields.filter(t=>!t.includes(","));t.length>0&&(a.fields=t)}return e.force&&(a.force=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"divide",options:a}],`Divide ${e.target}`)}(this._ctx,t)}pointsLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);const n=At(s.layers,e.target);if(!n)return pt.notFound("layer",e.target);const r=n.geometry_type;switch(e.type){case"centroid":case"inner":if("polygon"!==r)return pt.validation("type",`${e.type} requires polygon target, got ${r??"unknown"}`);break;case"midpoints":case"interpolated":if("polyline"!==r)return pt.validation("type",`${e.type} requires polyline target, got ${r??"unknown"}`);break;case"vertices":case"endpoints":if("polygon"!==r&&"polyline"!==r)return pt.validation("type",`${e.type} requires polygon/polyline target, got ${r??"unknown"}`);break;default:return pt.validation("type",`unknown type: ${String(e.type)}`)}if("interpolated"===e.type&&!("number"==typeof e.interval&&e.interval>0))return pt.validation("interval","interpolated points require a positive interval");const a={[e.type]:!0};return"interpolated"===e.type&&(a.interval=String(e.interval)),e.name&&e.name.trim()&&(a.name=e.name),e.noReplace&&(a.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"points",options:a}],`Points ${e.target}`)}(this._ctx,t)}linesLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);const n=At(s.layers,e.target);if(!n)return pt.notFound("layer",e.target);if("polygon"!==n.geometry_type)return pt.validation("target",`expected polygon layer, got ${n.geometry_type??"unknown"}`);const r={},a=e.fields?.filter(t=>"string"==typeof t&&!t.includes(","));return a&&a.length>0&&(r.fields=a),e.name&&e.name.trim()&&(r.name=e.name),e.noReplace&&(r.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"lines",options:r}],`Lines ${e.target}`)}(this._ctx,t)}polygonsLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);const n=At(s.layers,e.target);if(!n)return pt.notFound("layer",e.target);if("polyline"!==n.geometry_type)return pt.validation("target",`expected polyline layer, got ${n.geometry_type??"unknown"}`);const r={};return"number"==typeof e.gapTolerance&&e.gapTolerance>0&&(r.gap_tolerance=String(e.gapTolerance)),e.fromRings&&(r.from_rings=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"polygons",options:r}],`Polygons ${e.target}`)}(this._ctx,t)}simplifyLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(void 0!==e.target&&!At(s.layers,e.target))return pt.notFound("layer",e.target);if(1!==[void 0!==e.percentage,void 0!==e.interval,void 0!==e.resolution].filter(Boolean).length)return pt.validation("threshold","must supply exactly one of percentage, interval, resolution");const n={};if(void 0!==e.percentage){const t=e.percentage;if(!Number.isFinite(t)||t<0||t>100)return pt.validation("percentage","must be a finite number in [0, 100]");n.percentage=`${t}%`}else if(void 0!==e.interval){const t=e.interval;if(!Number.isFinite(t)||t<=0)return pt.validation("interval","must be a positive finite number");n.interval=String(t)}else{const t=e.resolution;if(!/^\d+x\d+$/.test(t))return pt.validation("resolution","must match `WIDTHxHEIGHT` (digits)");n.resolution=t}if(void 0!==e.weighting&&void 0!==e.method&&"weighted"!==e.method)return pt.validation("weighting",`weighting only applies to method='weighted', not ${e.method}`);e.method&&(n.method=e.method),"number"==typeof e.weighting&&Number.isFinite(e.weighting)&&(n.weighting=e.weighting),e.planar&&(n.planar=!0),e.keepShapes&&(n.keep_shapes=!0),e.lockBox&&(n.lock_box=!0),e.noRepair&&(n.no_repair=!0);const r=[];e.target&&r.push({name:"target",options:{target:e.target}}),r.push({name:"simplify",options:n});const a=`Simplify ${e.target??e.source}`;return t.runDatasetCommandParsed(e.source,r,a)}(this._ctx,t)}projectLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(void 0!==e.target&&!At(s.layers,e.target))return pt.notFound("layer",e.target);const n=(e.crs??"").trim();if(0===n.length)return pt.validation("crs","must be a non-empty CRS string");const r={crs:n};e.init&&e.init.trim()&&(r.init=e.init),e.densify&&(r.densify=!0);const a=[];e.target&&a.push({name:"target",options:{target:e.target}}),a.push({name:"proj",options:r});const o=`Project ${e.target??e.source}`;return t.runDatasetCommandParsed(e.source,a,o)}(this._ctx,t)}affineLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(void 0!==e.target&&!At(s.layers,e.target))return pt.notFound("layer",e.target);const n=Array.isArray(e.shift),r="number"==typeof e.rotate&&0!==e.rotate,a=void 0!==e.scale&&("number"==typeof e.scale?1!==e.scale:Array.isArray(e.scale));if(!n&&!r&&!a)return pt.validation("shift","must supply at least one of `shift`, `rotate`, or `scale`");if(n){const t=e.shift;if(2!==t.length||!t.every(t=>Number.isFinite(t)))return pt.validation("shift","must be [dx, dy] of finite numbers")}if(r&&!Number.isFinite(e.rotate))return pt.validation("rotate","must be a finite number (degrees)");if(a&&Array.isArray(e.scale)){const t=e.scale;if(2!==t.length||!t.every(t=>Number.isFinite(t)&&0!==t))return pt.validation("scale","must be [sx, sy] of nonzero finite numbers")}else if(a&&"number"==typeof e.scale&&(!Number.isFinite(e.scale)||0===e.scale))return pt.validation("scale","must be a nonzero finite number");if(!(void 0===e.anchor||Array.isArray(e.anchor)&&2===e.anchor.length&&e.anchor.every(t=>Number.isFinite(t))))return pt.validation("anchor","must be [x, y] of finite numbers");if(!t.host._allowExpressionEvaluation([e.where],"affineLayer"))return pt.expressionDisabled("affineLayer");const o={};n&&(o.shift=[String(e.shift[0]),String(e.shift[1])]),r&&(o.rotate=e.rotate),a&&(o.scale=(e.scale,e.scale)),e.anchor&&(o.anchor=[e.anchor[0],e.anchor[1]]),e.where&&e.where.trim()&&(o.where=e.where);const h=[];e.target&&h.push({name:"target",options:{target:e.target}}),h.push({name:"affine",options:o});const l=`Affine ${e.target??e.source}`;return t.runDatasetCommandParsed(e.source,h,l)}(this._ctx,t)}renameLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);const n=(e.name??"").trim();if(0===n.length)return pt.validation("name","must be a non-empty string");if(n.includes(","))return pt.validation("name","must not contain `,`");if(n!==e.target&&s.layers.some(t=>(t?.name??"")===n))return pt.validation("name",`another layer already named '${n}'`);return t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"rename-layers",options:{names:[n]}}],`Rename ${e.target} → ${n}`)}(this._ctx,t)}mergeLayers(t){return async function(t,e){if(!e.targets||e.targets.length<2)return pt.validation("targets","must supply at least 2 target layers");const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);for(const t of e.targets)if("string"!=typeof t||t.includes(","))return pt.validation("targets",`target name must not contain ',': ${String(t)}`);const n=e.targets.map(t=>At(s.layers,t));for(let t=0;t<n.length;t++)if(!n[t])return pt.notFound("layer",e.targets[t]);if(!e.force){const t=n[0]?.geometry_type;if(!n.every(e=>e?.geometry_type===t))return pt.validation("targets","targets have mixed geometry types; pass `force: true` to merge anyway")}const r=e.targets.join(","),a={};return e.name&&e.name.trim()&&(a.name=e.name),e.force&&(a.force=!0),e.flatten&&(a.flatten=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:r}},{name:"merge-layers",options:a}],`Merge ${r}`)}(this._ctx,t)}splitLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);const n=(e.expression??"").trim();if(0===n.length)return pt.validation("expression","must be a non-empty expression");if(!t.host._allowExpressionEvaluation([n],"splitLayer"))return pt.expressionDisabled("splitLayer");const r={expression:n};return e.noReplace&&(r.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"split",options:r}],`Split ${e.target}`)}(this._ctx,t)}dropLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();return s?At(s.layers,e.target)?t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"drop",options:{}}],`Drop ${e.target}`):pt.notFound("layer",e.target):pt.notFound("source",e.source)}(this._ctx,t)}sortFeatures(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);const n=(e.expression??"").trim();if(0===n.length)return pt.validation("expression","must be a non-empty expression");if(!t.host._allowExpressionEvaluation([n],"sortFeatures"))return pt.expressionDisabled("sortFeatures");const r={expression:n};return e.descending&&(r.descending=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"sort",options:r}],`Sort ${e.target}`)}(this._ctx,t)}uniqueFeatures(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);const n=(e.expression??"").trim();if(0===n.length)return pt.validation("expression","must be a non-empty expression");if(!t.host._allowExpressionEvaluation([n],"uniqueFeatures"))return pt.expressionDisabled("uniqueFeatures");if(void 0!==e.maxCount&&!("number"==typeof e.maxCount&&e.maxCount>0))return pt.validation("maxCount","must be a positive number");const r={expression:n};return void 0!==e.maxCount&&(r.max_count=e.maxCount),e.invert&&(r.invert=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"uniq",options:r}],`Uniq ${e.target}`)}(this._ctx,t)}filterFields(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);if(!Array.isArray(e.fields)||0===e.fields.length)return pt.validation("fields","must be a non-empty array");for(const t of e.fields){if("string"!=typeof t||0===t.trim().length)return pt.validation("fields",`field name must be a non-empty string: ${String(t)}`);if(t.includes(","))return pt.validation("fields",`field name must not contain ',': ${t}`)}const n={fields:e.fields.slice()};return e.invert&&(n.invert=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"filter-fields",options:n}],`Filter fields ${e.target}`)}(this._ctx,t)}renameFields(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);if(!e.mapping||"object"!=typeof e.mapping)return pt.validation("mapping","must be an object of { oldName: newName }");const n=Object.entries(e.mapping);if(0===n.length)return pt.validation("mapping","must contain at least one rename pair");const r=[];for(const[t,e]of n){const i=(t??"").trim(),s=(e??"").trim();if(0===i.length||0===s.length)return pt.validation("mapping",`field names must be non-empty: ${t}=${e}`);if(i.includes(",")||i.includes("=")||s.includes(",")||s.includes("="))return pt.validation("mapping",`field names must not contain ',' or '=': ${t}=${e}`);r.push(`${i}=${s}`)}return t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"rename-fields",options:{fields:r}}],`Rename fields ${e.target}`)}(this._ctx,t)}joinTable(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);if(!Array.isArray(e.keys)||2!==e.keys.length)return pt.validation("keys","must be a 2-element [targetKey, sourceKey] array");const[n,r]=e.keys.map(t=>"string"==typeof t?t.trim():"");if(0===n.length||0===r.length)return pt.validation("keys","both keys must be non-empty strings");if(n.includes(",")||r.includes(","))return pt.validation("keys","keys must not contain `,`");let a,o;const h=e.data;if(!h||"object"!=typeof h)return pt.validation("data","must be { csv } | { json } | { layer }");if("layer"in h&&"string"==typeof h.layer&&h.layer.trim().length>0)a=h.layer.trim();else if("csv"in h&&("string"==typeof h.csv||h.csv instanceof Uint8Array)){const t=".emap-join.csv";a=t,o={[t]:h.csv}}else{if(!("json"in h)||void 0===h.json)return pt.validation("data","must contain one of `csv`, `json`, or `layer`");{const t=".emap-join.json";let e;e="string"==typeof h.json||h.json instanceof Uint8Array?h.json:JSON.stringify(h.json),a=t,o={[t]:e}}}if(!t.host._allowExpressionEvaluation([e.where,e.calc],"joinTable"))return pt.expressionDisabled("joinTable");const l={source:a,keys:[n,r]};if(e.fields&&e.fields.length>0){const t=e.fields.filter(t=>"string"==typeof t&&!t.includes(","));t.length>0&&(l.fields=t)}return e.prefix&&e.prefix.length>0&&(l.prefix=e.prefix),e.where&&e.where.trim().length>0&&(l.where=e.where),e.calc&&e.calc.trim().length>0&&(l.calc=e.calc),e.unjoined&&(l.unjoined=!0),e.unmatched&&(l.unmatched=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"join",options:l}],`Join ${e.target}`,o)}(this._ctx,t)}dataFill(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);if("string"!=typeof e.field||0===e.field.trim().length)return pt.validation("field","must be a non-empty string");if(e.field.includes(",")||e.field.includes("="))return pt.validation("field","must not contain `,` or `=`");if(void 0!==e.weightField){if("string"!=typeof e.weightField||0===e.weightField.trim().length)return pt.validation("weightField","must be a non-empty string when supplied");if(e.weightField.includes(",")||e.weightField.includes("="))return pt.validation("weightField","must not contain `,` or `=`")}const n={field:e.field};return e.weightField&&(n.weight_field=e.weightField),e.contiguous&&(n.contiguous=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"data-fill",options:n}],`Data fill ${e.target}.${e.field}`)}(this._ctx,t)}rebuildTopology(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!s.arcs)return ct;const n=tt(),r=n.copyDataset(s),a=n.copyDataset(s);try{n.addIntersectionCuts(a,{snap_interval:e.snapInterval,no_snap:e.noSnap,rebuild_topology:e.rebuildTopology})}catch(e){return t.host.fire("error",{error:e}),pt.mapshaper(e,{operation:"rebuildTopology"})}return t.applyDatasetReplace(e.source,r,a,"Rebuild topology")}(this._ctx,t)}checkGeometry(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(void 0!==e.target&&!At(s.layers,e.target))return pt.notFound("layer",e.target);if(!s.arcs)return ut({ok:!0,intersections:[],intersectionCount:0});const n={};void 0!==e.tolerance&&(n.tolerance=e.tolerance);const r=tt().findSegmentIntersections(s.arcs,n).map(t=>({x:t.x,y:t.y}));return ut({ok:0===r.length,intersections:r,intersectionCount:r.length})}(this._ctx,t)}intersectionPointsLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);const n=At(s.layers,e.target);if(!n)return pt.notFound("layer",e.target);if("polygon"!==n.geometry_type&&"polyline"!==n.geometry_type)return pt.validation("target",`expected polygon/polyline target, got ${n.geometry_type??"unknown"}`);if(!s.arcs)return pt.validation("source","source has no arcs");const r=e.name&&e.name.trim()||`${e.target}-intersections`;if(s.layers.some(t=>t?.name===r))return pt.validation("name",`another layer already named '${r}'`);if(void 0!==e.tolerance&&("number"!=typeof e.tolerance||!Number.isFinite(e.tolerance)||e.tolerance<=0))return pt.validation("tolerance","must be a positive finite number");const a={};void 0!==e.tolerance&&(a.tolerance=e.tolerance);const o=tt(),h=o.copyDataset(s),l=o.copyDataset(s);let c;try{const t=o.findSegmentIntersections(l.arcs,a),i=At(l.layers,e.target);if(!i)throw new Error("intersectionPointsLayer: target lost in copyDataset");c=o.getIntersectionLayer(t,i,l.arcs),c.name=r,l.layers.push(c)}catch(e){return t.host.fire("error",{error:e}),pt.mapshaper(e,{operation:"intersectionPointsLayer"})}return t.applyDatasetReplace(e.source,h,l,`Intersection points ${e.target}`)}(this._ctx,t)}mergeSelected(){return It(this._ctx)}}class Rt{children;label;constructor(t,e){this.children=t,this.label=e}do(){for(const t of this.children)t.do()}undo(){for(let t=this.children.length-1;t>=0;t--)this.children[t].undo()}}function Ot(t){return"polygon"===t.geometry_type||"polyline"===t.geometry_type}function Gt(t){return"point"===t.geometry_type}function zt(t){t&&(t.editVersion=(t.editVersion??0)+1)}class qt{opts;label;_mergeAt=Date.now();constructor(t){this.opts=t;const e=t.arcIds.length+t.pointFeatures.length;this.label=`Translate ${e} feature${1===e?"":"s"}`}do(){this._apply(this.opts.dx,this.opts.dy)}undo(){this._apply(-this.opts.dx,-this.opts.dy)}mergeable(t){if(!(t instanceof qt))return!1;if(t.opts.source!==this.opts.source)return!1;if(Date.now()-t._mergeAt>500)return!1;const e=t.opts.arcIds,i=this.opts.arcIds;if(e.length!==i.length)return!1;for(let t=0;t<e.length;t++)if(e[t]!==i[t])return!1;const s=t.opts.pointFeatures,n=this.opts.pointFeatures;if(s.length!==n.length)return!1;for(let t=0;t<s.length;t++){if(s[t].featureId!==n[t].featureId)return!1;if(s[t].layer!==n[t].layer)return!1}return!0}merge(t){t instanceof qt&&(this.opts.dx+=t.opts.dx,this.opts.dy+=t.opts.dy,this._mergeAt=Date.now())}_apply(t,e){const{arcs:i,arcIds:s,pointFeatures:n,source:r}=this.opts;if(i&&s.length>0){const n=i.getVertexData?.();if(n){const{xx:r,yy:a,ii:o,nn:h}=n;for(const n of s){const s=o[n],l=h[n];for(let i=s;i<s+l;i++)r[i]+=t,a[i]+=e;i.updateArcBounds?.(n)}}}for(const i of n){const s=i.layer.shapes?.[i.featureId];if(s)for(const i of at(s))i&&i.length>=2&&(i[0]+=t,i[1]+=e)}r.markDisplayArcsDirty?.(),zt(r.getDataset?.())}}class jt{opts;label;constructor(t){this.opts=t;const e=t.arcIds.length+t.pointFeatures.length;this.label=t.label??`Transform ${e} feature${1===e?"":"s"}`}do(){this._apply(this.opts.matrix)}undo(){this._apply(Wt(this.opts.matrix))}_apply(t){const{arcs:e,arcIds:i,pointFeatures:s,source:n}=this.opts;if(e&&i.length>0){const s=e.getVertexData?.();if(s){const{xx:n,yy:r,ii:a,nn:o}=s;for(const s of i){const i=a[s],h=o[s];for(let e=i;e<i+h;e++){const i=n[e],s=r[e];n[e]=t.a*i+t.c*s+t.tx,r[e]=t.b*i+t.d*s+t.ty}e.updateArcBounds?.(s)}}}for(const e of s){const i=e.layer.shapes?.[e.featureId];if(i)for(const e of at(i))if(e&&e.length>=2){const i=e[0],s=e[1];e[0]=t.a*i+t.c*s+t.tx,e[1]=t.b*i+t.d*s+t.ty}}n.markDisplayArcsDirty?.(),zt(n.getDataset?.())}}function Bt(t,e=0,i=0){const s=Math.cos(t),n=Math.sin(t);return{a:s,b:n,c:-n,d:s,tx:e-s*e+n*i,ty:i-n*e-s*i}}function Ut(t,e,i=0,s=0){return{a:t,b:0,c:0,d:e,tx:i-t*i,ty:s-e*s}}function $t(t,e){return{a:t.a*e.a+t.c*e.b,b:t.b*e.a+t.d*e.b,c:t.a*e.c+t.c*e.d,d:t.b*e.c+t.d*e.d,tx:t.a*e.tx+t.c*e.ty+t.tx,ty:t.b*e.tx+t.d*e.ty+t.ty}}const Vt={a:1,b:0,c:0,d:1,tx:0,ty:0};function Wt(t){const e=t.a*t.d-t.b*t.c;if(0===e)throw new Error("FeatureAffineCommand: matrix is singular (det=0)");const i=t.d/e,s=-t.b/e,n=-t.c/e,r=t.a/e;return{a:i,b:s,c:n,d:r,tx:-(i*t.tx+n*t.ty),ty:-(s*t.tx+r*t.ty)}}class Ht{opts;label;constructor(t){this.opts=t,this.label=`Split ${t.appendedArcs.length} shared arc${1===t.appendedArcs.length?"":"s"}`}do(){const t=this.opts.source.getArcs();if(t){!function(t,e){const i=t.getVertexData?.();if(!i)return;const{xx:s,yy:n,zz:r,nn:a}=i,o=!!r&&e.every(t=>t.zz);let h=0;for(const t of e)h+=t.xx.length;const l=new Float64Array(s.length+h),c=new Float64Array(n.length+h),u=o?new Float64Array(r.length+h):null;l.set(s),c.set(n),u&&r&&u.set(r);let p=s.length;for(const t of e)l.set(t.xx,p),c.set(t.yy,p),u&&t.zz&&u.set(t.zz,p),p+=t.xx.length;const _=new Int32Array(a.length+e.length);_.set(a);for(let t=0;t<e.length;t++)_[a.length+t]=e[t].xx.length;t.updateVertexData(_,l,c,u)}(t,this.opts.appendedArcs);for(const t of this.opts.remaps)t.layer.shapes[t.featureId]=Xt(t.newShape);this.opts.source.markDisplayArcsDirty?.(),zt(this.opts.source.getDataset?.())}}undo(){const t=this.opts.source.getArcs();if(t){!function(t,e){const i=t.getVertexData?.();if(!i)return;const{xx:s,yy:n,zz:r,nn:a}=i;if(a.length===e)return;if(e>a.length)return;let o=0;for(let t=0;t<e;t++)o+=a[t];const h=new Int32Array(e);h.set(a.subarray(0,e));const l=new Float64Array(s.subarray(0,o)),c=new Float64Array(n.subarray(0,o)),u=r?new Float64Array(r.subarray(0,o)):null;t.updateVertexData(h,l,c,u)}(t,this.opts.originalArcCount);for(const t of this.opts.remaps)t.layer.shapes[t.featureId]=Xt(t.originalShape);this.opts.source.markDisplayArcsDirty?.(),zt(this.opts.source.getDataset?.())}}}function Kt(t,e,i){const s=t.getArcs();if(!s)return null;const n=s.size();if(0===n||0===e.length)return null;const r=new Uint32Array(n),a=new Uint32Array(n),o=new Set;for(const t of e)o.add(Zt(t.layer,t.featureId));for(const t of i){if(!t.shapes)continue;if(!Ot(t))continue;const e=t.shapes;for(let i=0;i<e.length;i++){const s=e[i];if(!s)continue;const h=o.has(Zt(t,i));for(const t of s)if(Array.isArray(t))for(const e of t){if("number"!=typeof e)continue;const t=e>=0?e:~e;t<0||t>=n||(h?r[t]++:a[t]++)}}}const h=[];for(let t=0;t<n;t++)r[t]>0&&a[t]>0&&h.push(t);if(0===h.length)return null;const l=new globalThis.Map;for(let t=0;t<h.length;t++)l.set(h[t],n+t);const c=s.getVertexData?.();if(!c)return null;const{xx:u,yy:p,zz:_,ii:d,nn:f}=c,m=h.map(t=>{const e=d[t],i=f[t];return{xx:new Float64Array(u.subarray(e,e+i)),yy:new Float64Array(p.subarray(e,e+i)),zz:_?new Float64Array(_.subarray(e,e+i)):null}}),y=[];for(const t of e){if(!Ot(t.layer))continue;const e=t.layer.shapes?.[t.featureId];if(!e)continue;let i=!1;const s=e.map(t=>t.map(t=>{const e=t>=0?t:~t,s=l.get(e);return void 0===s?t:(i=!0,t>=0?s:~s)}));i&&y.push({layer:t.layer,featureId:t.featureId,originalShape:Xt(e),newShape:s})}return 0===y.length?null:{source:t,remaps:y,appendedArcs:m,originalArcCount:n}}function Zt(t,e){return`${t.name??""}#${e}`}function Xt(t){return t.map(t=>t.slice())}class Jt{_emap;constructor(t){this._emap=t}translateSelected(t,e){if(0===t&&0===e)return pt.validation("offset","dx and dy are both 0 (no-op)");const i=this._emap._selection.getAll();if(0===i.length)return pt.validation("selection","selection is empty");const s=new globalThis.Map;for(const t of i){const e=this._emap.layers.resolve(t.source,t.layer);if(!e?.shapes)continue;const i=e.shapes[t.id];if(!i)continue;let n=s.get(t.source);if(n||(n={arcIdSet:new Set,pointFeatures:[]},s.set(t.source,n)),"point"===e.geometry_type)n.pointFeatures.push({layer:e,featureId:t.id});else{const t=i;for(const e of t)if(Array.isArray(e))for(const t of e)"number"==typeof t&&n.arcIdSet.add(t>=0?t:~t)}}if(0===s.size)return pt.validation("selection","no resolvable layers in selection");const n=[],r=[];for(const[i,a]of s){const s=this._emap._sources.get(i);if(!s)continue;if(0===a.arcIdSet.size&&0===a.pointFeatures.length)continue;const o=new qt({source:s,arcs:s.getArcs(),dx:t,dy:e,arcIds:Array.from(a.arcIdSet),pointFeatures:a.pointFeatures});o.do(),n.push(o),r.push(i)}if(0===n.length)return pt.validation("selection","every resolved layer was empty");const a=1===n.length?n[0]:new Rt(n,`Translate ${i.length} features`);return this._emap._history.push(a),this._emap._fireHistoryChange(),this._emap._clearSpatialIndexesForSources(r),this._emap._scheduleRender(),ct}_buildSelectionBuckets(t){const e=this._emap._selection.getAll();if(0===e.length)return null;const i=new globalThis.Map;for(const t of e){const e=this._emap.layers.resolve(t.source,t.layer);if(!e?.shapes)continue;if(!e.shapes[t.id])continue;const s=this._emap._sources.get(t.source);if(!s)continue;let n=i.get(t.source);n||(n={sourceId:t.source,source:s,arcIds:[],pointFeatures:[],pathFeatures:[]},i.set(t.source,n)),"point"===e.geometry_type?n.pointFeatures.push({layer:e,featureId:t.id}):n.pathFeatures.push({layer:e,featureId:t.id})}if(0===i.size)return null;const s=[];if(t)for(const t of i.values()){if(0===t.pathFeatures.length)continue;const e=Kt(t.source,t.pathFeatures,t.source.getLayers());if(!e)continue;const i=new Ht(e);i.do(),s.push(i),this._emap._invalidateShapeCachesForSources([t.sourceId])}for(const t of i.values()){const e=new Set;for(const i of t.pathFeatures){const s=i.layer.shapes?.[i.featureId];if(s)for(const i of s)if(Array.isArray(i))for(const s of i){if("number"!=typeof s)continue;const i=s>=0?s:~s;e.has(i)||(e.add(i),t.arcIds.push(i))}}}return{buckets:Array.from(i.values()).map(t=>({sourceId:t.sourceId,source:t.source,arcIds:t.arcIds,pointFeatures:t.pointFeatures})),splitCmds:s}}beginTranslateSession(t){const e=this._buildSelectionBuckets(!1!==t?.splitSharedArcs);if(!e)return null;const{buckets:i,splitCmds:s}=e;let n=0,r=0,a=!1;const o=(t,e)=>{for(const s of i)0===s.arcIds.length&&0===s.pointFeatures.length||new qt({source:s.source,arcs:s.source.getArcs(),dx:t,dy:e,arcIds:s.arcIds,pointFeatures:s.pointFeatures}).do()};return{move:(t,e)=>{a||0===t&&0===e||(o(t,e),n+=t,r+=e,this._emap._scheduleRender())},commit:()=>{if(a)return!1;a=!0;if(!!(0===n&&0===r)){for(let t=s.length-1;t>=0;t--)s[t].undo();return s.length>0&&this._emap._scheduleRender(),!1}const t=i.map(t=>new qt({source:t.source,arcs:t.source.getArcs(),dx:n,dy:r,arcIds:t.arcIds,pointFeatures:t.pointFeatures})),e=i.reduce((t,e)=>t+e.arcIds.length+e.pointFeatures.length,0),o=[...s,...t],h=1===o.length?o[0]:new Rt(o,`Translate ${e} features`);return this._emap._history.push(h),this._emap._fireHistoryChange(),this._emap._invalidateShapeCachesForSources(i.map(t=>t.sourceId)),this._emap._scheduleRender(),!0},cancel:()=>{if(!a){a=!0,0===n&&0===r||o(-n,-r);for(let t=s.length-1;t>=0;t--)s[t].undo();n=0,r=0,s.length>0&&this._emap._invalidateShapeCachesForSources(i.map(t=>t.sourceId)),this._emap._scheduleRender()}},getAccumulated:()=>[n,r]}}beginAffineSession(t,e){const i=this._buildSelectionBuckets(!1!==e?.splitSharedArcs);if(!i)return null;const{buckets:s,splitCmds:n}=i;let r,a;if(t)[r,a]=t;else{const t=new globalThis.Map;for(const e of s)t.set(e.sourceId,{arcIdSet:new Set(e.arcIds),pointFeatures:e.pointFeatures});const e=this._computeSelectionCentroid(t);if(!e){for(let t=n.length-1;t>=0;t--)n[t].undo();return null}[r,a]=e}if(!Number.isFinite(r)||!Number.isFinite(a)){for(let t=n.length-1;t>=0;t--)n[t].undo();return null}const o=[r,a];let h={...Vt},l=!1;const c=t=>1===t.a&&0===t.b&&0===t.c&&1===t.d&&0===t.tx&&0===t.ty,u=t=>{for(const e of s)0===e.arcIds.length&&0===e.pointFeatures.length||new jt({source:e.source,arcs:e.source.getArcs(),matrix:t,arcIds:e.arcIds,pointFeatures:e.pointFeatures}).do()};return{origin:o,applyDelta:t=>{l||c(t)||(u(t),h=$t(t,h),this._emap._scheduleRender())},commit:t=>{if(l)return!1;if(l=!0,c(h)){for(let t=n.length-1;t>=0;t--)n[t].undo();return n.length>0&&this._emap._scheduleRender(),!1}const e=s.reduce((t,e)=>t+e.arcIds.length+e.pointFeatures.length,0),i=s.map(e=>new jt({source:e.source,arcs:e.source.getArcs(),matrix:h,arcIds:e.arcIds,pointFeatures:e.pointFeatures,label:t})),r=[...n,...i],a=1===r.length?r[0]:new Rt(r,t??`Transform ${e} feature${1===e?"":"s"}`);return this._emap._history.push(a),this._emap._fireHistoryChange(),this._emap._invalidateShapeCachesForSources(s.map(t=>t.sourceId)),this._emap._scheduleRender(),!0},cancel:()=>{if(!l){l=!0,c(h)||u(Wt(h));for(let t=n.length-1;t>=0;t--)n[t].undo();h={...Vt},n.length>0&&this._emap._invalidateShapeCachesForSources(s.map(t=>t.sourceId)),this._emap._scheduleRender()}},getCumulative:()=>({...h})}}rotateSelected(t,e){if(0===t)return pt.validation("angleDegrees","angle is 0 (no-op)");const i=t*Math.PI/180;return this._applyAffineToSelection((t,e)=>Bt(i,t,e),e,t=>`Rotate ${t} feature${1===t?"":"s"}`)}scaleSelected(t,e,i){const s=t,n=e??t;return 1===s&&1===n?pt.validation("scale","sx and sy are both 1 (no-op)"):this._applyAffineToSelection((t,e)=>Ut(s,n,t,e),i,t=>`Scale ${t} feature${1===t?"":"s"}`)}_applyAffineToSelection(t,e,i){const s=this._emap._selection.getAll();if(0===s.length)return pt.validation("selection","selection is empty");const n=new globalThis.Map;for(const t of s){const e=this._emap.layers.resolve(t.source,t.layer);if(!e?.shapes)continue;const i=e.shapes[t.id];if(!i)continue;let s=n.get(t.source);if(s||(s={arcIdSet:new Set,pointFeatures:[]},n.set(t.source,s)),"point"===e.geometry_type)s.pointFeatures.push({layer:e,featureId:t.id});else{const t=i;for(const e of t)if(Array.isArray(e))for(const t of e)"number"==typeof t&&s.arcIdSet.add(t>=0?t:~t)}}if(0===n.size)return pt.validation("selection","no resolvable layers in selection");let r,a;if(e)r=e[0],a=e[1];else{const t=this._computeSelectionCentroid(n);if(!t)return pt.validation("origin","no vertices in selection; cannot compute centroid");[r,a]=t}if(!Number.isFinite(r)||!Number.isFinite(a))return pt.validation("origin","computed origin is not finite");const o=t(r,a),h=[],l=[];for(const[t,e]of n){const i=this._emap._sources.get(t);if(!i)continue;if(0===e.arcIdSet.size&&0===e.pointFeatures.length)continue;const s=new jt({source:i,arcs:i.getArcs(),matrix:o,arcIds:Array.from(e.arcIdSet),pointFeatures:e.pointFeatures});s.do(),h.push(s),l.push(t)}if(0===h.length)return pt.validation("selection","every resolved layer was empty");const c=1===h.length?h[0]:new Rt(h,i(s.length));return this._emap._history.push(c),this._emap._fireHistoryChange(),this._emap._clearSpatialIndexesForSources(l),this._emap._scheduleRender(),ct}_computeSelectionCentroid(t){let e=1/0,i=1/0,s=-1/0,n=-1/0,r=!1;for(const[a,o]of t){const t=this._emap._sources.get(a);if(!t)continue;const h=t.getArcs(),l=h?.getVertexData?.();if(l&&o.arcIdSet.size>0){const{xx:t,yy:a,ii:h,nn:c}=l;for(const l of o.arcIdSet){const o=h[l],u=c[l];for(let h=o;h<o+u;h++){const o=t[h],l=a[h];o<e&&(e=o),o>s&&(s=o),l<i&&(i=l),l>n&&(n=l),r=!0}}}for(const t of o.pointFeatures){const a=t.layer.shapes?.[t.featureId];if(a)for(const t of at(a)){if(!t||t.length<2)continue;const a=t[0],o=t[1];a<e&&(e=a),a>s&&(s=a),o<i&&(i=o),o>n&&(n=o),r=!0}}}return r?[(e+s)/2,(i+n)/2]:null}}class Yt{opts;label;constructor(t){this.opts=t,this.label=t.label??"Edit properties"}do(){Qt(this.opts.layer,this.opts.featureId,this.opts.prev,this.opts.next)}undo(){Qt(this.opts.layer,this.opts.featureId,this.opts.next,this.opts.prev)}}function Qt(t,e,i,s){const n=t.data?.getRecords?.(),r=n?.[e];if(r){for(const t of Object.keys(s))r[t]=s[t];for(const t of Object.keys(i))t in s||delete r[t]}}class te{opts;label;_addedIndices=[];constructor(t){this.opts=t,this.label=`Add field ${t.field}`}do(){const t=this.opts.layer.data?.getRecords?.();if(!t)return;const e=this.opts.defaultValue??null;this._addedIndices=[];for(let i=0;i<t.length;i++)t[i]&&!(this.opts.field in t[i])&&(t[i][this.opts.field]=e,this._addedIndices.push(i))}undo(){const t=this.opts.layer.data?.getRecords?.();if(t){for(const e of this._addedIndices)delete t[e]?.[this.opts.field];this._addedIndices=[]}}}class ee{opts;label;_snapshot=new globalThis.Map;constructor(t){this.opts=t,this.label=`Remove field ${t.field}`}do(){const t=this.opts.layer.data?.getRecords?.();if(t){this._snapshot.clear();for(let e=0;e<t.length;e++){const i=t[e];i&&this.opts.field in i&&(this._snapshot.set(e,i[this.opts.field]),delete i[this.opts.field])}}}undo(){const t=this.opts.layer.data?.getRecords?.();if(t)for(const[e,i]of this._snapshot){const s=t[e];s&&(s[this.opts.field]=i)}}}class ie{opts;label;constructor(t){this.opts=t,this.label=`Rename field ${t.from} → ${t.to}`}do(){se(this.opts.layer,this.opts.from,this.opts.to)}undo(){se(this.opts.layer,this.opts.to,this.opts.from)}}function se(t,e,i){const s=t.data?.getRecords?.();if(s)for(const t of s)t&&e in t&&(t[i]=t[e],delete t[e])}class ne{_emap;constructor(t){this._emap=t}setFeatureProperty(t,e,i){return this.setFeatureProperties(t,{[e]:i})}setFeatureProperties(t,e){const i=this._emap.layers.resolve(t.source,t.layer);if(!i)return pt.notFound("layer",t.layer);const s=i.data?.getRecords?.(),n=s?.[t.id];if(!n)return pt.notFound("field",`record#${t.id}`);const r={},a={};for(const t of Object.keys(e)){const i=t in n,s=i?n[t]:void 0,o=e[t];(void 0!==o||i)&&(void 0!==o&&i&&n[t]===o||(i&&(r[t]=s),void 0!==o&&(a[t]=o)))}if(0===Object.keys(r).length&&0===Object.keys(a).length)return pt.validation("props","no-op: every requested value already matches the record");const o=new Yt({layer:i,featureId:t.id,prev:r,next:a});return o.do(),this._emap._history.push(o),this._emap._fireHistoryChange(),this._emap._scheduleRender(),ct}addField(t){const e=this._emap.layers.resolve(t.source,t.target);if(!e)return pt.notFound("layer",t.target);if(!e.data)return pt.validation("target","layer has no data table");const i=new te({layer:e,field:t.field,defaultValue:t.defaultValue});return i.do(),this._emap._history.push(i),this._emap._fireHistoryChange(),this._emap._scheduleRender(),ct}removeField(t){const e=this._emap.layers.resolve(t.source,t.target);if(!e)return pt.notFound("layer",t.target);if(!e.data)return pt.validation("target","layer has no data table");const i=new ee({layer:e,field:t.field});return i.do(),this._emap._history.push(i),this._emap._fireHistoryChange(),this._emap._scheduleRender(),ct}renameField(t){const e=this._emap.layers.resolve(t.source,t.target);if(!e)return pt.notFound("layer",t.target);if(!e.data)return pt.validation("target","layer has no data table");const i=e.data.getRecords?.();if(!i)return pt.validation("target","data table has no records");if(t.from===t.to)return pt.validation("to","`from` and `to` are identical");for(const e of i)if(e&&t.from in e&&t.to in e)return pt.validation("to",`would overwrite existing '${t.to}' on at least one record`);const s=new ie({layer:e,from:t.from,to:t.to});return s.do(),this._emap._history.push(s),this._emap._fireHistoryChange(),this._emap._scheduleRender(),ct}}class re{_onChange;_mode="none";_vertex=null;_draw=null;constructor(t){this._onChange=t}get mode(){return this._mode}get vertex(){return this._vertex}get draw(){return this._draw}setMode(t){if(t===this._mode)return;const e=this._mode;this._mode=t,"vertex"!==t&&(this._vertex=null),"draw"!==t&&(this._draw=null),this._fire(e)}setVertex(t){this._vertex!==t&&(this._vertex=t,this._fire(this._mode))}clearVertex(){null!==this._vertex&&(this._vertex=null,this._fire(this._mode))}setDraw(t){this._draw!==t&&(this._draw=t,this._fire(this._mode))}clearDraw(){null!==this._draw&&(this._draw=null,this._fire(this._mode))}_fire(t){this._onChange({current:{mode:this._mode,vertex:this._vertex,draw:this._draw},previousMode:t,modeChanged:t!==this._mode})}}var ae={},oe=Uint8Array,he=Uint16Array,le=Int32Array,ce=new oe([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]),ue=new oe([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]),pe=new oe([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),_e=function(t,e){for(var i=new he(31),s=0;s<31;++s)i[s]=e+=1<<t[s-1];var n=new le(i[30]);for(s=1;s<30;++s)for(var r=i[s];r<i[s+1];++r)n[r]=r-i[s]<<5|s;return{b:i,r:n}},de=_e(ce,2),fe=de.b,me=de.r;fe[28]=258,me[258]=28;for(var ye=_e(ue,0),ge=ye.b,ve=ye.r,xe=new he(32768),be=0;be<32768;++be){var we=(43690&be)>>1|(21845&be)<<1;we=(61680&(we=(52428&we)>>2|(13107&we)<<2))>>4|(3855&we)<<4,xe[be]=((65280&we)>>8|(255&we)<<8)>>1}var Se=function(t,e,i){for(var s=t.length,n=0,r=new he(e);n<s;++n)t[n]&&++r[t[n]-1];var a,o=new he(e);for(n=1;n<e;++n)o[n]=o[n-1]+r[n-1]<<1;if(i){a=new he(1<<e);var h=15-e;for(n=0;n<s;++n)if(t[n])for(var l=n<<4|t[n],c=e-t[n],u=o[t[n]-1]++<<c,p=u|(1<<c)-1;u<=p;++u)a[xe[u]>>h]=l}else for(a=new he(s),n=0;n<s;++n)t[n]&&(a[n]=xe[o[t[n]-1]++]>>15-t[n]);return a},Ce=new oe(288);for(be=0;be<144;++be)Ce[be]=8;for(be=144;be<256;++be)Ce[be]=9;for(be=256;be<280;++be)Ce[be]=7;for(be=280;be<288;++be)Ce[be]=8;var Ae=new oe(32);for(be=0;be<32;++be)Ae[be]=5;var Ee=Se(Ce,9,0),Me=Se(Ce,9,1),ke=Se(Ae,5,0),Ie=Se(Ae,5,1),De=function(t){for(var e=t[0],i=1;i<t.length;++i)t[i]>e&&(e=t[i]);return e},Pe=function(t,e,i){var s=e/8|0;return(t[s]|t[s+1]<<8)>>(7&e)&i},Te=function(t,e){var i=e/8|0;return(t[i]|t[i+1]<<8|t[i+2]<<16)>>(7&e)},Le=function(t){return(t+7)/8|0},Fe=function(t,e,i){return(null==e||e<0)&&(e=0),(null==i||i>t.length)&&(i=t.length),new oe(t.subarray(e,i))},Ne=["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"],Re=function(t,e,i){var s=new Error(e||Ne[t]);if(s.code=t,Error.captureStackTrace&&Error.captureStackTrace(s,Re),!i)throw s;return s},Oe=function(t,e,i,s){var n=t.length,r=s?s.length:0;if(!n||e.f&&!e.l)return i||new oe(0);var a=!i,o=a||2!=e.i,h=e.i;a&&(i=new oe(3*n));var l=function(t){var e=i.length;if(t>e){var s=new oe(Math.max(2*e,t));s.set(i),i=s}},c=e.f||0,u=e.p||0,p=e.b||0,_=e.l,d=e.d,f=e.m,m=e.n,y=8*n;do{if(!_){c=Pe(t,u,1);var g=Pe(t,u+1,3);if(u+=3,!g){var v=t[(D=Le(u)+4)-4]|t[D-3]<<8,x=D+v;if(x>n){h&&Re(0);break}o&&l(p+v),i.set(t.subarray(D,x),p),e.b=p+=v,e.p=u=8*x,e.f=c;continue}if(1==g)_=Me,d=Ie,f=9,m=5;else if(2==g){var b=Pe(t,u,31)+257,w=Pe(t,u+10,15)+4,S=b+Pe(t,u+5,31)+1;u+=14;for(var C=new oe(S),A=new oe(19),E=0;E<w;++E)A[pe[E]]=Pe(t,u+3*E,7);u+=3*w;var M=De(A),k=(1<<M)-1,I=Se(A,M,1);for(E=0;E<S;){var D,P=I[Pe(t,u,k)];if(u+=15&P,(D=P>>4)<16)C[E++]=D;else{var T=0,L=0;for(16==D?(L=3+Pe(t,u,3),u+=2,T=C[E-1]):17==D?(L=3+Pe(t,u,7),u+=3):18==D&&(L=11+Pe(t,u,127),u+=7);L--;)C[E++]=T}}var F=C.subarray(0,b),N=C.subarray(b);f=De(F),m=De(N),_=Se(F,f,1),d=Se(N,m,1)}else Re(1);if(u>y){h&&Re(0);break}}o&&l(p+131072);for(var R=(1<<f)-1,O=(1<<m)-1,G=u;;G=u){var z=(T=_[Te(t,u)&R])>>4;if((u+=15&T)>y){h&&Re(0);break}if(T||Re(2),z<256)i[p++]=z;else{if(256==z){G=u,_=null;break}var q=z-254;if(z>264){var j=ce[E=z-257];q=Pe(t,u,(1<<j)-1)+fe[E],u+=j}var B=d[Te(t,u)&O],U=B>>4;B||Re(3),u+=15&B;N=ge[U];if(U>3){j=ue[U];N+=Te(t,u)&(1<<j)-1,u+=j}if(u>y){h&&Re(0);break}o&&l(p+131072);var $=p+q;if(p<N){var V=r-N,W=Math.min(N,$);for(V+p<0&&Re(3);p<W;++p)i[p]=s[V+p]}for(;p<$;++p)i[p]=i[p-N]}}e.l=_,e.p=G,e.b=p,e.f=c,_&&(c=1,e.m=f,e.d=d,e.n=m)}while(!c);return p!=i.length&&a?Fe(i,0,p):i.subarray(0,p)},Ge=function(t,e,i){i<<=7&e;var s=e/8|0;t[s]|=i,t[s+1]|=i>>8},ze=function(t,e,i){i<<=7&e;var s=e/8|0;t[s]|=i,t[s+1]|=i>>8,t[s+2]|=i>>16},qe=function(t,e){for(var i=[],s=0;s<t.length;++s)t[s]&&i.push({s:s,f:t[s]});var n=i.length,r=i.slice();if(!n)return{t:He,l:0};if(1==n){var a=new oe(i[0].s+1);return a[i[0].s]=1,{t:a,l:1}}i.sort(function(t,e){return t.f-e.f}),i.push({s:-1,f:25001});var o=i[0],h=i[1],l=0,c=1,u=2;for(i[0]={s:-1,f:o.f+h.f,l:o,r:h};c!=n-1;)o=i[i[l].f<i[u].f?l++:u++],h=i[l!=c&&i[l].f<i[u].f?l++:u++],i[c++]={s:-1,f:o.f+h.f,l:o,r:h};var p=r[0].s;for(s=1;s<n;++s)r[s].s>p&&(p=r[s].s);var _=new he(p+1),d=je(i[c-1],_,0);if(d>e){s=0;var f=0,m=d-e,y=1<<m;for(r.sort(function(t,e){return _[e.s]-_[t.s]||t.f-e.f});s<n;++s){var g=r[s].s;if(!(_[g]>e))break;f+=y-(1<<d-_[g]),_[g]=e}for(f>>=m;f>0;){var v=r[s].s;_[v]<e?f-=1<<e-_[v]++-1:++s}for(;s>=0&&f;--s){var x=r[s].s;_[x]==e&&(--_[x],++f)}d=e}return{t:new oe(_),l:d}},je=function(t,e,i){return-1==t.s?Math.max(je(t.l,e,i+1),je(t.r,e,i+1)):e[t.s]=i},Be=function(t){for(var e=t.length;e&&!t[--e];);for(var i=new he(++e),s=0,n=t[0],r=1,a=function(t){i[s++]=t},o=1;o<=e;++o)if(t[o]==n&&o!=e)++r;else{if(!n&&r>2){for(;r>138;r-=138)a(32754);r>2&&(a(r>10?r-11<<5|28690:r-3<<5|12305),r=0)}else if(r>3){for(a(n),--r;r>6;r-=6)a(8304);r>2&&(a(r-3<<5|8208),r=0)}for(;r--;)a(n);r=1,n=t[o]}return{c:i.subarray(0,s),n:e}},Ue=function(t,e){for(var i=0,s=0;s<e.length;++s)i+=t[s]*e[s];return i},$e=function(t,e,i){var s=i.length,n=Le(e+2);t[n]=255&s,t[n+1]=s>>8,t[n+2]=255^t[n],t[n+3]=255^t[n+1];for(var r=0;r<s;++r)t[n+r+4]=i[r];return 8*(n+4+s)},Ve=function(t,e,i,s,n,r,a,o,h,l,c){Ge(e,c++,i),++n[256];for(var u=qe(n,15),p=u.t,_=u.l,d=qe(r,15),f=d.t,m=d.l,y=Be(p),g=y.c,v=y.n,x=Be(f),b=x.c,w=x.n,S=new he(19),C=0;C<g.length;++C)++S[31&g[C]];for(C=0;C<b.length;++C)++S[31&b[C]];for(var A=qe(S,7),E=A.t,M=A.l,k=19;k>4&&!E[pe[k-1]];--k);var I,D,P,T,L=l+5<<3,F=Ue(n,Ce)+Ue(r,Ae)+a,N=Ue(n,p)+Ue(r,f)+a+14+3*k+Ue(S,E)+2*S[16]+3*S[17]+7*S[18];if(h>=0&&L<=F&&L<=N)return $e(e,c,t.subarray(h,h+l));if(Ge(e,c,1+(N<F)),c+=2,N<F){I=Se(p,_,0),D=p,P=Se(f,m,0),T=f;var R=Se(E,M,0);Ge(e,c,v-257),Ge(e,c+5,w-1),Ge(e,c+10,k-4),c+=14;for(C=0;C<k;++C)Ge(e,c+3*C,E[pe[C]]);c+=3*k;for(var O=[g,b],G=0;G<2;++G){var z=O[G];for(C=0;C<z.length;++C){var q=31&z[C];Ge(e,c,R[q]),c+=E[q],q>15&&(Ge(e,c,z[C]>>5&127),c+=z[C]>>12)}}}else I=Ee,D=Ce,P=ke,T=Ae;for(C=0;C<o;++C){var j=s[C];if(j>255){ze(e,c,I[(q=j>>18&31)+257]),c+=D[q+257],q>7&&(Ge(e,c,j>>23&31),c+=ce[q]);var B=31&j;ze(e,c,P[B]),c+=T[B],B>3&&(ze(e,c,j>>5&8191),c+=ue[B])}else ze(e,c,I[j]),c+=D[j]}return ze(e,c,I[256]),c+D[256]},We=new le([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),He=new oe(0),Ke=function(){for(var t=new Int32Array(256),e=0;e<256;++e){for(var i=e,s=9;--s;)i=(1&i&&-306674912)^i>>>1;t[e]=i}return t}(),Ze=function(){var t=-1;return{p:function(e){for(var i=t,s=0;s<e.length;++s)i=Ke[255&i^e[s]]^i>>>8;t=i},d:function(){return~t}}},Xe=function(t,e,i,s,n){if(!n&&(n={l:1},e.dictionary)){var r=e.dictionary.subarray(-32768),a=new oe(r.length+t.length);a.set(r),a.set(t,r.length),t=a,n.w=r.length}return function(t,e,i,s,n,r){var a=r.z||t.length,o=new oe(s+a+5*(1+Math.ceil(a/7e3))+n),h=o.subarray(s,o.length-n),l=r.l,c=7&(r.r||0);if(e){c&&(h[0]=r.r>>3);for(var u=We[e-1],p=u>>13,_=8191&u,d=(1<<i)-1,f=r.p||new he(32768),m=r.h||new he(d+1),y=Math.ceil(i/3),g=2*y,v=function(e){return(t[e]^t[e+1]<<y^t[e+2]<<g)&d},x=new le(25e3),b=new he(288),w=new he(32),S=0,C=0,A=r.i||0,E=0,M=r.w||0,k=0;A+2<a;++A){var I=v(A),D=32767&A,P=m[I];if(f[D]=P,m[I]=D,M<=A){var T=a-A;if((S>7e3||E>24576)&&(T>423||!l)){c=Ve(t,h,0,x,b,w,C,E,k,A-k,c),E=S=C=0,k=A;for(var L=0;L<286;++L)b[L]=0;for(L=0;L<30;++L)w[L]=0}var F=2,N=0,R=_,O=D-P&32767;if(T>2&&I==v(A-O))for(var G=Math.min(p,T)-1,z=Math.min(32767,A),q=Math.min(258,T);O<=z&&--R&&D!=P;){if(t[A+F]==t[A+F-O]){for(var j=0;j<q&&t[A+j]==t[A+j-O];++j);if(j>F){if(F=j,N=O,j>G)break;var B=Math.min(O,j-2),U=0;for(L=0;L<B;++L){var $=A-O+L&32767,V=$-f[$]&32767;V>U&&(U=V,P=$)}}}O+=(D=P)-(P=f[D])&32767}if(N){x[E++]=268435456|me[F]<<18|ve[N];var W=31&me[F],H=31&ve[N];C+=ce[W]+ue[H],++b[257+W],++w[H],M=A+F,++S}else x[E++]=t[A],++b[t[A]]}}for(A=Math.max(A,M);A<a;++A)x[E++]=t[A],++b[t[A]];c=Ve(t,h,l,x,b,w,C,E,k,A-k,c),l||(r.r=7&c|h[c/8|0]<<3,c-=7,r.h=m,r.p=f,r.i=A,r.w=M)}else{for(A=r.w||0;A<a+l;A+=65535){var K=A+65535;K>=a&&(h[c/8|0]=l,K=a),c=$e(h,c+1,t.subarray(A,K))}r.i=a}return Fe(o,0,s+Le(c)+n)}(t,null==e.level?6:e.level,null==e.mem?n.l?Math.ceil(1.5*Math.max(8,Math.min(13,Math.log(t.length)))):20:12+e.mem,i,s,n)},Je=function(t,e){var i={};for(var s in t)i[s]=t[s];for(var s in e)i[s]=e[s];return i},Ye=function(t,e,i){for(var s=t(),n=t.toString(),r=n.slice(n.indexOf("[")+1,n.lastIndexOf("]")).replace(/\s+/g,"").split(","),a=0;a<s.length;++a){var o=s[a],h=r[a];if("function"==typeof o){e+=";"+h+"=";var l=o.toString();if(o.prototype)if(-1!=l.indexOf("[native code]")){var c=l.indexOf(" ",8)+1;e+=l.slice(c,l.indexOf("(",c))}else for(var u in e+=l,o.prototype)e+=";"+h+".prototype."+u+"="+o.prototype[u].toString();else e+=l}else i[h]=o}return e},Qe=[],ti=function(t,e,i,s){if(!Qe[i]){for(var n="",r={},a=t.length-1,o=0;o<a;++o)n=Ye(t[o],n,r);Qe[i]={c:Ye(t[a],n,r),e:r}}var h=Je({},Qe[i].e);return function(t,e,i,s,n){var r=new Worker(ae[e]||(ae[e]=URL.createObjectURL(new Blob([t+';addEventListener("error",function(e){e=e.error;postMessage({$e$:[e.message,e.code,e.stack]})})'],{type:"text/javascript"}))));return r.onmessage=function(t){var e=t.data,i=e.$e$;if(i){var s=new Error(i[0]);s.code=i[1],s.stack=i[2],n(s,null)}else n(null,e)},r.postMessage(i,s),r}(Qe[i].c+";onmessage=function(e){for(var k in e.data)self[k]=e.data[k];onmessage="+e.toString()+"}",i,h,function(t){var e=[];for(var i in t)t[i].buffer&&e.push((t[i]=new t[i].constructor(t[i])).buffer);return e}(h),s)},ei=function(){return[oe,he,le,ce,ue,pe,fe,ge,Me,Ie,xe,Ne,Se,De,Pe,Te,Le,Fe,Re,Oe,ci,ii,si]},ii=function(t){return postMessage(t,[t.buffer])},si=function(t){return t&&{out:t.size&&new oe(t.size),dictionary:t.dictionary}},ni=function(t,e){return t[e]|t[e+1]<<8},ri=function(t,e){return(t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24)>>>0},ai=function(t,e){return ri(t,e)+4294967296*ri(t,e+4)},oi=function(t,e,i){for(;i;++e)t[e]=i,i>>>=8};function hi(t,e){return Xe(t,e||{},0,0)}function li(t,e,i){return i||(i=e,e={}),"function"!=typeof i&&Re(7),function(t,e,i,s,n,r){var a=ti(i,s,n,function(t,e){a.terminate(),r(t,e)});return a.postMessage([t,e],e.consume?[t.buffer]:[]),function(){a.terminate()}}(t,e,[ei],function(t){return ii(ci(t.data[0],si(t.data[1])))},1,i)}function ci(t,e){return Oe(t,{i:2},e&&e.out,e&&e.dictionary)}var ui=function(t,e,i,s){for(var n in t){var r=t[n],a=e+n,o=s;Array.isArray(r)&&(o=Je(s,r[1]),r=r[0]),r instanceof oe?i[a]=[r,o]:(i[a+="/"]=[new oe(0),o],ui(r,a,i,s))}},pi="undefined"!=typeof TextEncoder&&new TextEncoder,_i="undefined"!=typeof TextDecoder&&new TextDecoder;try{_i.decode(He,{stream:!0})}catch(t){}function di(t,e){if(pi)return pi.encode(t);for(var i=t.length,s=new oe(t.length+(t.length>>1)),n=0,r=function(t){s[n++]=t},a=0;a<i;++a){if(n+5>s.length){var o=new oe(n+8+(i-a<<1));o.set(s),s=o}var h=t.charCodeAt(a);h<128||e?r(h):h<2048?(r(192|h>>6),r(128|63&h)):h>55295&&h<57344?(r(240|(h=65536+(1047552&h)|1023&t.charCodeAt(++a))>>18),r(128|h>>12&63),r(128|h>>6&63),r(128|63&h)):(r(224|h>>12),r(128|h>>6&63),r(128|63&h))}return Fe(s,0,n)}function fi(t,e){if(e){for(var i="",s=0;s<t.length;s+=16384)i+=String.fromCharCode.apply(null,t.subarray(s,s+16384));return i}if(_i)return _i.decode(t);var n=function(t){for(var e="",i=0;;){var s=t[i++],n=(s>127)+(s>223)+(s>239);if(i+n>t.length)return{s:e,r:Fe(t,i-1)};n?3==n?(s=((15&s)<<18|(63&t[i++])<<12|(63&t[i++])<<6|63&t[i++])-65536,e+=String.fromCharCode(55296|s>>10,56320|1023&s)):e+=1&n?String.fromCharCode((31&s)<<6|63&t[i++]):String.fromCharCode((15&s)<<12|(63&t[i++])<<6|63&t[i++]):e+=String.fromCharCode(s)}}(t),r=n.s;return(i=n.r).length&&Re(8),r}var mi=function(t,e){for(;1!=ni(t,e);e+=4+ni(t,e+2));return[ai(t,e+12),ai(t,e+4),ai(t,e+20)]},yi=function(t){var e=0;if(t)for(var i in t){var s=t[i].length;s>65535&&Re(9),e+=s+4}return e},gi=function(t,e,i,s,n,r,a,o){var h=s.length,l=i.extra,c=o&&o.length,u=yi(l);oi(t,e,null!=a?33639248:67324752),e+=4,null!=a&&(t[e++]=20,t[e++]=i.os),t[e]=20,e+=2,t[e++]=i.flag<<1|(r<0&&8),t[e++]=n&&8,t[e++]=255&i.compression,t[e++]=i.compression>>8;var p=new Date(null==i.mtime?Date.now():i.mtime),_=p.getFullYear()-1980;if((_<0||_>119)&&Re(10),oi(t,e,_<<25|p.getMonth()+1<<21|p.getDate()<<16|p.getHours()<<11|p.getMinutes()<<5|p.getSeconds()>>1),e+=4,-1!=r&&(oi(t,e,i.crc),oi(t,e+4,r<0?-r-2:r),oi(t,e+8,i.size)),oi(t,e+12,h),oi(t,e+14,u),e+=16,null!=a&&(oi(t,e,c),oi(t,e+6,i.attrs),oi(t,e+10,a),e+=14),t.set(s,e),e+=h,u)for(var d in l){var f=l[d],m=f.length;oi(t,e,+d),oi(t,e+2,m),t.set(f,e+4),e+=4+m}return c&&(t.set(o,e),e+=c),e};function vi(t,e){e||(e={});var i={},s=[];ui(t,"",i,e);var n=0,r=0;for(var a in i){var o=i[a],h=o[0],l=o[1],c=0==l.level?0:8,u=(S=di(a)).length,p=l.comment,_=p&&di(p),d=_&&_.length,f=yi(l.extra);u>65535&&Re(11);var m=c?hi(h,l):h,y=m.length,g=Ze();g.p(h),s.push(Je(l,{size:h.length,crc:g.d(),c:m,f:S,m:_,u:u!=a.length||_&&p.length!=d,o:n,compression:c})),n+=30+u+f+y,r+=76+2*(u+f)+(d||0)+y}for(var v=new oe(r+22),x=n,b=r-n,w=0;w<s.length;++w){var S=s[w];gi(v,S.o,S,S.f,S.u,S.c.length);var C=30+S.f.length+yi(S.extra);v.set(S.c,S.o+C),gi(v,n,S,S.f,S.u,S.c.length,S.o,S.m),n+=16+C+(S.m?S.m.length:0)}return function(t,e,i,s,n){oi(t,e,101010256),oi(t,e+8,i),oi(t,e+10,i),oi(t,e+12,s),oi(t,e+16,n)}(v,n,s.length,b,x),v}var xi="function"==typeof queueMicrotask?queueMicrotask:"function"==typeof setTimeout?setTimeout:function(t){t()};function bi(t,e,i){i||(i=e,e={}),"function"!=typeof i&&Re(7);var s=[],n=function(){for(var t=0;t<s.length;++t)s[t]()},r={},a=function(t,e){xi(function(){i(t,e)})};xi(function(){a=i});for(var o=t.length-22;101010256!=ri(t,o);--o)if(!o||t.length-o>65558)return a(Re(13,0,1),null),n;var h=ni(t,o+8);if(h){var l=h,c=ri(t,o+16),u=4294967295==c||65535==l;if(u){var p=ri(t,o-12);(u=101075792==ri(t,p))&&(l=h=ri(t,p+32),c=ri(t,p+48))}for(var _=e&&e.filter,d=function(e){var i=function(t,e,i){var s=ni(t,e+28),n=fi(t.subarray(e+46,e+46+s),!(2048&ni(t,e+8))),r=e+46+s,a=ri(t,e+20),o=i&&4294967295==a?mi(t,r):[a,ri(t,e+24),ri(t,e+42)],h=o[0],l=o[1],c=o[2];return[ni(t,e+10),h,l,n,r+ni(t,e+30)+ni(t,e+32),c]}(t,c,u),o=i[0],l=i[1],p=i[2],d=i[3],f=i[4],m=i[5],y=function(t,e){return e+30+ni(t,e+26)+ni(t,e+28)}(t,m);c=f;var g=function(t,e){t?(n(),a(t,null)):(e&&(r[d]=e),--h||a(null,r))};if(!_||_({name:d,size:l,originalSize:p,compression:o}))if(o)if(8==o){var v=t.subarray(y,y+l);if(p<524288||l>.8*p)try{g(null,ci(v,{out:new oe(p)}))}catch(t){g(t,null)}else s.push(li(v,{size:p},g))}else g(Re(14,"unknown compression type "+o,1),null);else g(null,Fe(t,y,y+l));else g(null,null)},f=0;f<l;++f)d()}else a(null,{});return n}const wi=5e5;class Si{_unfilteredArcs;_filteredArcs=null;_filteredSegLen=0;_dirty=!1;constructor(t){this._unfilteredArcs=t;(t.getPointCount?.()??0)>wi&&this._initFilteredArcs()}markDirty(){this._dirty=!0}_initFilteredArcs(){const t=this._unfilteredArcs,e=t.getVertexData?.();if(e?.zz){const e=.08,i=Math.ceil((t.getPointCount?.()??0)/wi),s=t.getRetainedInterval?.()??0,n=t.getThresholdByPct?.(e,i)??0;this._filteredArcs=t.setRetainedInterval?.(n)?.getFilteredCopy?.()??null,t.setRetainedInterval?.(s),this._filteredArcs&&(this._filteredSegLen=tt().getAvgSegment(this._filteredArcs))}else{const e=tt();this._filteredSegLen=4*e.getAvgSegment(t),this._filteredArcs=e.simplifyArcsFast(t,this._filteredSegLen)}}getScaledArcs(t){const e=null!==this._filteredArcs&&t>1.5*this._filteredSegLen;if(this._filteredArcs){(this._filteredArcs.size()!==this._unfilteredArcs.size()||this._dirty&&e)&&(this._initFilteredArcs(),this._dirty=!1)}else if(this._dirty){(this._unfilteredArcs.getPointCount?.()??0)>wi&&this._initFilteredArcs(),this._dirty=!1}this._filteredArcs&&this._filteredArcs.setRetainedInterval?.(this._unfilteredArcs.getRetainedInterval?.()??0);return this._filteredArcs&&t>1.5*this._filteredSegLen?this._filteredArcs:this._unfilteredArcs}getArcs(){return this._unfilteredArcs}hasLOD(){return null!==this._filteredArcs}}class Ci{_adapter;constructor(t=tt()){this._adapter=t}async runImport(t,e){return this._adapter.runImport(t,e)}}let Ai=null;const Ei="EPSG:4326";function Mi(t){if(!t)return Ei;const e=t.info;if(!e)return Ei;if(e.crs_string)return ki(e.crs_string);if(e.prj){const t=Ii(e.prj);if(t)return t}if(e.crs){if(e.crs.is_latlong)return"EPSG:4326";if("merc"===e.crs.projName&&6378137===e.crs.a)return"EPSG:3857"}return Ei}function ki(t){const e=t.toLowerCase();return"wgs84"===e||e.includes("4326")?"EPSG:4326":e.includes("3857")||"webmercator"===e?"EPSG:3857":(/^epsg:\d+$/i.test(t),t.toUpperCase())}function Ii(t){const e=t.match(/AUTHORITY\["EPSG"\s*,\s*"(\d+)"\]/i);return e?`EPSG:${e[1]}`:/Mercator.*WGS.*84.*Pseudo/i.test(t)||/WGS.*84.*Pseudo.*Mercator/i.test(t)||/Web_Mercator/i.test(t)?"EPSG:3857":/DATUM\["WGS_1984"/i.test(t)&&/GEOGCS/i.test(t)?"EPSG:4326":null}const Di={geojson:"application/geo+json",topojson:"application/json",shapefile:"application/zip",msx:"application/octet-stream"};function Pi(t){return"string"==typeof t?(new TextEncoder).encode(t):t instanceof Uint8Array?t:new Uint8Array(t)}const Ti={maxBytes:209715200,maxEntries:5e3,maxRatio:100};class Li extends U{id;type="topology";_dataset;_displayArcs=null;_options;_data;_loadVersion=0;_abortController=null;_pending=null;_simplifyFloor=0;_runner;getSimplifyFloor(){return this._simplifyFloor}constructor(t,e){super(),this.id=t,this._options=e||{},this._data=this._options.data,this._runner=this._options.mapshaperRunner??Ai??(Ai=new Ci),this._data&&this._updateData()}static async fromUrl(t,e,i){const s=new Li(t,i);return await s.setData(e),s}static async fromBytes(t,e,i){const{filename:s=`${t}.geojson`,...n}=i??{},r=e instanceof Uint8Array?e:new Uint8Array(e),a=new Li(t,n);return await a.setData({filename:s,content:r}),a}setData(t){this._loadVersion++;const e=this._loadVersion;this._abortController?.abort(),this._abortController=null,this._data=t,this._pending?.resolve(this);const i=new Promise((t,i)=>{this._pending={version:e,resolve:t,reject:i}});return i.catch(()=>{}),this._updateData(),i}async _updateData(){if(!this._data)return;const t=this._loadVersion,e=new AbortController;this._abortController=e,this.fire("dataloading");try{const i={},s=[];if(Array.isArray(this._data)){if(0===this._data.length)throw new Error("setData received an empty array; nothing to import");for(const t of this._data)if(this._isZipFile(t.filename)){const e=await this._extractZip(t.content),n=this._findPrimaryFile(e);if(!n)throw new Error(`No importable file found in zip archive: ${t.filename}`);for(const[t,s]of Object.entries(e))i[t]=s;s.push(n)}else i[t.filename]=t.content,s.push(t.filename)}else{let t;if("string"==typeof this._data){const i=this._data,s=await fetch(i,{signal:e.signal});if(!s.ok)throw new Error(`Failed to fetch ${i}: HTTP ${s.status}`);const n=await s.arrayBuffer(),r=new Uint8Array(n);let a=new URL(i).pathname.split("/").pop()||"";if(!this._hasSupportedExtension(a)){const t=s.headers.get("Content-Type")||"";a=this._filenameFromContentType(t,a)}a||(a="data.json"),t={filename:a,content:r}}else t=this._data;if(this._isZipFile(t.filename)){const e=await this._extractZip(t.content),n=this._findPrimaryFile(e);if(!n)throw new Error("No importable file found in zip archive");for(const[t,s]of Object.entries(e))i[t]=s;s.push(n)}else i[t.filename]=t.content,s.push(t.filename)}const n=`-i ${s.map(t=>`"${t.replace(/"/g,'\\"')}"`).join(" ")}`,r=await this._runner.runImport(n,i);if(t!==this._loadVersion)return;this._dataset=r,this._dataset?.arcs&&(this._displayArcs=new Si(this._dataset.arcs)),this._simplifyFloor=this._dataset?.arcs?.getRetainedInterval?.()??0,this.fire("data",{reason:"load"}),this._resolvePending(t)}catch(e){if(t!==this._loadVersion)return;if("AbortError"===e?.name)return;this.fire("error",{error:e}),this._rejectPending(t,e??new Error("setData import failed"))}}_resolvePending(t){if(this._pending?.version!==t)return;const e=this._pending;this._pending=null,e.resolve(this)}_rejectPending(t,e){if(this._pending?.version!==t)return;const i=this._pending;this._pending=null,i.reject(e)}_hasSupportedExtension(t){return/\.(json|geojson|topojson|zip|shp|kml|msx)$/i.test(t)}_filenameFromContentType(t,e){return(e||"data")+({"application/json":".json","application/geo+json":".geojson","application/vnd.geo+json":".geojson","application/topojson+json":".topojson","application/zip":".zip","application/x-zip-compressed":".zip","application/octet-stream":".zip","application/vnd.google-earth.kml+xml":".kml","text/plain":".json"}[t.toLowerCase().split(";")[0].trim()]||".json")}getDataset(){return this._dataset}getCRS(){return Mi(this._dataset)}async reproject(t){if(!this._dataset)return;this._dataset?.arcs?.setRetainedInterval&&this._dataset.arcs.setRetainedInterval(0),this._dataset.info&&(delete this._dataset.info.crs_string,delete this._dataset.info.prj,delete this._dataset.info.wkt1);const e=`-proj ${t}`,i=await tt().runOnDataset(e,this._dataset);this._dataset=i,this._dataset?.arcs&&(this._displayArcs=new Si(this._dataset.arcs))}getExtent(){if(!this._dataset)return new V;const t=tt().getDatasetBounds(this._dataset);return new V(t.xmin,t.ymin,t.xmax,t.ymax)}getArcs(){return this._dataset?.arcs}getDisplayArcs(){return this._displayArcs}markDisplayArcsDirty(){this._displayArcs?.markDirty()}refreshDisplayArcs(){this._dataset?.arcs&&(this._displayArcs=new Si(this._dataset.arcs))}setDataset(t){this._dataset=t,t.arcs?this._displayArcs=new Si(t.arcs):this._displayArcs=null,this._simplifyFloor=t.arcs?.getRetainedInterval?.()??0,this.fire("data",{reason:"replace"})}async export(t){if(!this._dataset)throw new Error("TopologySource has no dataset to export");const e=this._dataset.arcs,i=e?.getRetainedInterval?.()??0;i&&e?.setRetainedInterval&&e.setRetainedInterval(0);try{const e=tt(),i="msx"===t.format?await e.exportPackedDatasets([this._dataset],{compact:!0}):e.exportFileContent(this._dataset,{format:t.format});return this._filesToBlob(i,t.format)}finally{i&&e?.setRetainedInterval&&e.setRetainedInterval(i)}}_filesToBlob(t,e){if(0===t.length)throw new Error(`mapshaper produced no output for format=${e}`);if("shapefile"===e){const e={};for(const i of t)e[i.filename]=Pi(i.content);const i=vi(e);return new Blob([i],{type:Di.shapefile})}return new Blob([t[0].content],{type:Di[e]})}getLayers(){return this._dataset?.layers||[]}_isZipFile(t){return/\.zip$/i.test(t)}async _extractZip(t){const e={...Ti,...this._options.zipLimits};let i=0,s=0;const n=await new Promise((n,r)=>{bi(t,{filter:n=>{if(s++,s>e.maxEntries)throw new Error(`ZIP extraction limit exceeded: ${s} entries > maxEntries ${e.maxEntries}`);if(i+=n.originalSize,i>e.maxBytes)throw new Error(`ZIP extraction limit exceeded: uncompressed total ${i} > maxBytes ${e.maxBytes}`);if(t.byteLength>0){const s=i/t.byteLength;if(s>e.maxRatio)throw new Error(`ZIP extraction limit exceeded: ratio ${s.toFixed(1)} > maxRatio ${e.maxRatio}`)}return!(/^__MACOSX/.test(n.name)||n.name.split("/").pop()?.startsWith("."))}},(t,e)=>{t?r(t):n(e)})}),r={};for(const t of Object.keys(n)){const e=n[t],i=t.split("/").pop()||t;this._isTextFile(i)?r[i]=fi(e):r[i]=e}return r}_isTextFile(t){return/\.(prj|cpg|csv|json|geojson|kml|txt)$/i.test(t)}_findPrimaryFile(t){const e=Object.keys(t),i=[".shp",".geojson",".json",".kml",".topojson"];for(const t of i){const i=e.find(e=>e.toLowerCase().endsWith(t));if(i)return i}return e.find(t=>!this._isAuxiliaryFile(t))||""}_isAuxiliaryFile(t){return/\.(prj|shx|dbf)$/i.test(t)}}function Fi(t){const e=[];return function(i){e.push(i),e.length>t&&e.shift();return e.reduce((t,e)=>t+e,0)/e.length}}class Ni extends U{_element;_active=!1;_timer=new W;_sustainInterval=150;_fadeDelay=70;_eventTime=0;_getAverageRate=Fi(10);_getWheelDirection=function(){let t=0,e=null;return function(i,s){const n=i>0?1:i<0?-1:0;(!e||s-t>300)&&(e=Fi(3)),t=s;const r=e(n)||n;return r>0?1:r<0?-1:0}}();_wheelDirection=0;_mouseX=0;_mouseY=0;_wheelHandler=t=>this._handleWheel(t);constructor(t){super(),this._element=t,this._timer.on("tick",t=>this._onTick(t)),this._element.addEventListener("wheel",this._wheelHandler,{passive:!1})}destroy(){this._element.removeEventListener("wheel",this._wheelHandler),this._timer.stop()}_updateSustainInterval(t){this._fadeDelay=t+50,this._sustainInterval=this._fadeDelay+80}_handleWheel(t){const e=Date.now();if(this._wheelDirection=this._getWheelDirection(-t.deltaY,e),0===this._wheelDirection)return;t.preventDefault();const i=this._element.getBoundingClientRect();this._mouseX=t.clientX-i.left,this._mouseY=t.clientY-i.top,this._active?this._updateSustainInterval(this._getAverageRate(e-this._eventTime)):(this._active=!0,this.fire("mousewheelstart")),this._eventTime=e,this._timer.start(this._sustainInterval)}_onTick(t){const e=t.time-this._eventTime;let i=t.tickTime/25,s=0;e>this._fadeDelay&&(s=Math.min(1,(e-this._fadeDelay)/(this._sustainInterval-this._fadeDelay))),t.done?(this._active=!1,this.fire("mousewheelend")):(s>0&&(i*=H.quadraticOut(1-s)),this.fire("mousewheel",{direction:this._wheelDirection,multiplier:i,x:this._mouseX,y:this._mouseY}))}}class Ri extends U{name="scrollZoom";_wheel;_enabled=!0;_onGestureStart;constructor(t,e){super(),this._onGestureStart=e,this._wheel=new Ni(t),this._wheel.on("mousewheel",t=>{this._onGestureStart?.(),this._enabled&&this.fire("mousewheel",t)})}enable(){this._enabled=!0}disable(){this._enabled=!1}isEnabled(){return this._enabled}setOptions(t){}getOptions(){return{}}handlePointer(t){return"passthrough"}destroy(){this._wheel.destroy()}}const Oi={skipShiftDrag:!0};class Gi extends U{name="dragPan";_opts;_enabled=!0;_dragging=!1;_last={x:0,y:0};_hoverPoint=null;_onGestureStart;_isHoveringSelected;constructor(t,e,i){super(),this._opts={...Oi,...t},this._onGestureStart=e,this._isHoveringSelected=i}enable(){this._enabled=!0}disable(){this._enabled=!1,this._dragging&&(this._dragging=!1,this.fire("panend"))}isEnabled(){return this._enabled}setOptions(t){this._opts={...this._opts,...t}}getOptions(){return this._opts}getCursor(){return this._enabled?this._dragging?"grabbing":this._hoverPoint&&this._isHoveringSelected?.(this._hoverPoint)?"move":"grab":null}handlePointer(t){if(!this._enabled)return"passthrough";if("down"===t.kind)return 0!==t.button||this._opts.skipShiftDrag&&t.modifiers.shift?"passthrough":(this._onGestureStart?.(),this._dragging=!0,this._last={x:t.point.x,y:t.point.y},this.fire("panstart"),"exclusive");if("move"===t.kind&&!this._dragging)return this._hoverPoint={x:t.point.x,y:t.point.y},"passthrough";if("move"===t.kind&&this._dragging){const e=t.point.x-this._last.x,i=t.point.y-this._last.y;return this._last={x:t.point.x,y:t.point.y},this.fire("pan",{dx:e,dy:i}),"exclusive"}return"up"===t.kind&&this._dragging?(this._dragging=!1,this.fire("panend"),"passthrough"):"passthrough"}}const zi=["shift","ctrl","alt","meta"];function qi(t,e,i){const s=i?function(t){return"none"===t?new Set:new Set(t.split("+"))}(i):new Set,n=t.ctrl&&!s.has("ctrl"),r=t.meta&&!s.has("meta"),a=function(t){const e=zi.filter(e=>t[e]);return 0===e.length?"none":e.join("+")}({shift:t.shift&&!s.has("shift"),ctrl:n||r,alt:t.alt&&!s.has("alt"),meta:!1});for(const t of["replace","add","toggle"]){const i=e[t];if(i&&i===a)return t}return"replace"}function ji(t,e){const[i,s]=t;let n=!1;const r=e.length;for(let t=0,a=r-1;t<r;a=t++){const[r,o]=e[t],[h,l]=e[a];o>s!=l>s&&i<(h-r)*(s-o)/(l-o)+r&&(n=!n)}return n}function Bi(t,e,i,s){const n=function(t,e){const i=t.getSource(e.source);if(!i)return null;let s=t.layers?.resolve(e.source,e.layer);if(!s){const t=i.getDataset?.();s=t?.layers.find((t,i)=>rt(t,i)===e.layer||t?.name===e.layer||t?.id===e.layer)}if(!s?.shapes)return null;const n=s.shapes?.[e.id];return n?{layer:s,shape:n,arcs:i.getArcs?.()}:null}(t,e);if(!n)return!1;if("point"===n.layer.geometry_type){const e=at(n.shape);if(0===e.length)return!1;const r=e.map(([e,i])=>t.project(e,i));return s?r.some(t=>$i(t,i)):r.every(t=>$i(t,i))}if(!n.arcs)return!1;const r=function(t,e,i){const s=[];for(const n of e){const e=[],r=i.getShapeIter?.(n);if(r)for(;r.hasNext();)e.push(t.project(r.x,r.y));else for(const s of n){const n=s>=0?s:~s,r=i.getArcIter(n);for(;r.hasNext();)e.push(t.project(r.x,r.y))}e.length>0&&s.push(e)}return s}(t,n.shape,n.arcs);if(0===r.length)return!1;const a="polygon"===n.layer.geometry_type;return s?function(t,e,i){for(const s of t){if(s.some(t=>$i(t,e)))return!0;if(Ui(s,e,i))return!0}return!(!i||!e.some(e=>function(t,e){let i=!1;for(const s of e){if(Vi(t,s))return!0;ji(t,s)&&(i=!i)}return i}(e,t)))}(r,i,a):function(t,e,i){for(const s of t){if(!s.every(t=>$i(t,e)))return!1;if(Ui(s,e,i))return!1}return!0}(r,i,a)}function Ui(t,e,i){const s=i?Wi(t):t,n=Wi(e);for(let t=0;t<s.length-1;t++){const e=s[t],i=s[t+1];for(let t=0;t<n.length-1;t++){if(Hi(e,i,n[t],n[t+1]))return!0}}return!1}function $i(t,e){return Vi(t,e)||ji(t,e)}function Vi(t,e){const i=Wi(e);for(let e=0;e<i.length-1;e++)if(Ki(t,i[e],i[e+1]))return!0;return!1}function Wi(t){if(t.length<2)return t;const e=t[0],i=t[t.length-1];return s=e,n=i,Math.abs(s[0]-n[0])<=Ji&&Math.abs(s[1]-n[1])<=Ji?t:[...t,e];var s,n}function Hi(t,e,i,s){const n=Zi(t,e,i),r=Zi(t,e,s),a=Zi(i,s,t),o=Zi(i,s,e);return!(!Xi(n)||!Ki(i,t,e))||(!(!Xi(r)||!Ki(s,t,e))||(!(!Xi(a)||!Ki(t,i,s))||(!(!Xi(o)||!Ki(e,i,s))||n>0!=r>0&&a>0!=o>0)))}function Ki(t,e,i){return!!Xi(Zi(e,i,t))&&(t[0]>=Math.min(e[0],i[0])-Ji&&t[0]<=Math.max(e[0],i[0])+Ji&&t[1]>=Math.min(e[1],i[1])-Ji&&t[1]<=Math.max(e[1],i[1])+Ji)}function Zi(t,e,i){return(e[0]-t[0])*(i[1]-t[1])-(e[1]-t[1])*(i[0]-t[0])}function Xi(t){return Math.abs(t)<=Ji}const Ji=1e-9;function Yi(t){const e=new Set,i=[];for(const s of t){const t=`${s.source}|${s.layer}|${s.id}`;e.has(t)||(e.add(t),i.push({source:s.source,layer:s.layer,id:s.id}))}return i}const Qi={replace:"none",add:"shift",toggle:"shift+alt"};class ts extends U{_map;name="clickSelect";_enabled=!1;_opts={};constructor(t){super(),this._map=t}enable(){this._enabled=!0}disable(){this._enabled=!1}isEnabled(){return this._enabled}setOptions(t){this._opts={...this._opts,...t}}getOptions(){return this._opts}handlePointer(t){if(!this._enabled||"click"!==t.kind||0!==t.button)return"passthrough";const e=qi(t.modifiers,this._opts.modifiers??Qi),i=Yi(this._map.queryFeatures([t.point.x,t.point.y],this._opts.layers?{layers:this._opts.layers}:void 0));return 0===i.length?("replace"===e&&this._map.select([],{mode:"replace"}),"consumed"):(this._map.select(i,{mode:e}),"consumed")}}const es={replace:"none",add:"shift",toggle:"shift+alt"};class is extends U{_map;name="boxSelect";_enabled=!1;_opts={};_start=null;_overlay=null;_manager;constructor(t){super(),this._map=t}enable(){if(this._manager?.isEnabledByName("lassoSelect"))throw new Error("cannot enable boxSelect: lassoSelect is enabled (both consume selection drag gestures); disable it first");this._enabled=!0}disable(){this._enabled=!1,this._start&&this._cancel()}isEnabled(){return this._enabled}setOptions(t){this._opts={...this._opts,...t}}getOptions(){return this._opts}getCursor(){return this._enabled?"crosshair":null}get _threshold(){return this._opts.dragThreshold??4}get _activator(){return this._opts.dragActivator??"none"}_ensureOverlay(){if(this._overlay)return this._overlay;const t=document.createElement("div");t.className="emap-box-select",t.style.position="absolute",t.style.pointerEvents="none",t.style.display="none",t.style.boxSizing="border-box";const e=this._opts.style??{};return t.style.border=`${e.strokeWidth??1.5}px solid ${e.stroke??"#0078ff"}`,t.style.background=e.fill??"rgba(0, 120, 255, 0.1)",this._map.getCanvasContainer().appendChild(t),this._overlay=t,t}_cancel(){this._overlay&&(this._overlay.style.display="none"),this._start=null}handlePointer(t){if(!this._enabled)return"passthrough";if("down"===t.kind){if(0!==t.button||(e=t.modifiers,"none"!==(i=this._activator)&&!i.split("+").every(t=>!0===e[t])))return"passthrough";this._start={x:t.point.x,y:t.point.y};const s=this._ensureOverlay();return s.style.left=`${t.point.x}px`,s.style.top=`${t.point.y}px`,s.style.width="0",s.style.height="0",s.style.display="block","exclusive"}var e,i;if("move"===t.kind&&this._start){const e=this._ensureOverlay(),i=Math.min(this._start.x,t.point.x),s=Math.min(this._start.y,t.point.y);return e.style.left=`${i}px`,e.style.top=`${s}px`,e.style.width=`${Math.abs(t.point.x-this._start.x)}px`,e.style.height=`${Math.abs(t.point.y-this._start.y)}px`,"exclusive"}if("up"===t.kind&&this._start){const e=this._start,{x:i,y:s}=t.point;if(this._cancel(),Math.hypot(i-e.x,s-e.y)<this._threshold)return"passthrough";const n=Math.min(e.x,i),r=Math.min(e.y,s),a=Math.max(e.x,i),o=Math.max(e.y,s),h=this._map.queryFeatures([[n,r],[a,o]],this._opts.layers?{layers:this._opts.layers}:void 0),l=qi(t.modifiers,this._opts.modifiers??es,this._activator);return this._map.select(Yi(h),{mode:l}),"passthrough"}return"passthrough"}}const ss={replace:"none",add:"ctrl",toggle:"alt"},ns="http://www.w3.org/2000/svg";class rs extends U{_map;name="lassoSelect";_enabled=!1;_opts={};_path=null;_svg=null;_poly=null;_manager;constructor(t){super(),this._map=t}enable(){if(this._manager?.isEnabledByName("boxSelect"))throw new Error("cannot enable lassoSelect: boxSelect is enabled (both consume selection drag gestures); disable it first");this._enabled=!0}disable(){this._enabled=!1,this._path&&this._cancel()}isEnabled(){return this._enabled}setOptions(t){this._opts={...this._opts,...t}}getOptions(){return this._opts}getCursor(){return this._enabled?"crosshair":null}get _threshold(){return this._opts.dragThreshold??4}get _activator(){return this._opts.dragActivator??"shift"}_ensureSvg(){if(this._svg&&this._poly)return{svg:this._svg,poly:this._poly};const t=document.createElementNS(ns,"svg");t.style.position="absolute",t.style.left="0",t.style.top="0",t.style.width="100%",t.style.height="100%",t.style.pointerEvents="none",t.style.display="none",t.setAttribute("class","emap-lasso-select");const e=document.createElementNS(ns,"polyline"),i=this._opts.style??{};return e.setAttribute("fill",i.fill??"rgba(0, 120, 255, 0.1)"),e.setAttribute("stroke",i.stroke??"#0078ff"),e.setAttribute("stroke-width",String(i.strokeWidth??1.5)),e.setAttribute("stroke-dasharray",i.strokeDasharray??"4 3"),e.setAttribute("points",""),t.appendChild(e),this._map.getCanvasContainer().appendChild(t),this._svg=t,this._poly=e,{svg:t,poly:e}}_cancel(){this._svg&&(this._svg.style.display="none"),this._path=null}handlePointer(t){if(!this._enabled)return"passthrough";if("down"===t.kind){if(0!==t.button||(e=t.modifiers,"none"!==(i=this._activator)&&!i.split("+").every(t=>!0===e[t])))return"passthrough";const{svg:s,poly:n}=this._ensureSvg();return this._path=[[t.point.x,t.point.y]],n.setAttribute("points",`${t.point.x},${t.point.y}`),s.style.display="block","exclusive"}var e,i;if("move"===t.kind&&this._path)return this._path.push([t.point.x,t.point.y]),this._poly?.setAttribute("points",this._path.map(t=>`${t[0]},${t[1]}`).join(" ")),"exclusive";if("up"===t.kind&&this._path){const e=this._path;if(this._cancel(),e.length<3)return"passthrough";const i=function(t){let e=1/0,i=1/0,s=-1/0,n=-1/0;for(const[r,a]of t)r<e&&(e=r),a<i&&(i=a),r>s&&(s=r),a>n&&(n=a);return[e,i,s,n]}(e);if(Math.hypot(i[2]-i[0],i[3]-i[1])<this._threshold)return"passthrough";const s=e.slice();s.push(e[0]);const n=this._map.queryFeatures([[i[0],i[1]],[i[2],i[3]]],this._opts.layers?{layers:this._opts.layers}:void 0),r=!1!==this._opts.includeIntersecting,a=[],o=new Set;for(const t of n){const e=`${t.source}|${t.layer}|${t.id}`;o.has(e)||Bi(this._map,t,s,r)&&(o.add(e),a.push({source:t.source,layer:t.layer,id:t.id}))}const h=qi(t.modifiers,this._opts.modifiers??ss,this._activator);return this._map.select(a,{mode:h}),"passthrough"}return"passthrough"}}class as{opts;label="Move vertex";_mergeAt=Date.now();constructor(t){this.opts=t}do(){(this.opts.adapter??tt()).snapVertices(this.opts.vertexIds,this.opts.to,this.opts.arcs),this.opts.source.markDisplayArcsDirty?.(),zt(this.opts.source.getDataset?.())}undo(){(this.opts.adapter??tt()).snapVertices(this.opts.vertexIds,this.opts.from,this.opts.arcs),this.opts.source.markDisplayArcsDirty?.(),zt(this.opts.source.getDataset?.())}mergeable(t){if(!(t instanceof as))return!1;if(t.opts.source!==this.opts.source)return!1;if(Date.now()-t._mergeAt>500)return!1;const e=t.opts.vertexIds,i=this.opts.vertexIds;if(e.length!==i.length)return!1;for(let t=0;t<e.length;t++)if(e[t]!==i[t])return!1;return!0}merge(t){t instanceof as&&(this.opts.to=t.opts.to,this._mergeAt=Date.now())}}class os{opts;label="Insert vertex";constructor(t){this.opts=t}do(){(this.opts.adapter??tt()).insertVertex(this.opts.arcs,this.opts.insertionId,this.opts.point),this.opts.source.markDisplayArcsDirty?.(),zt(this.opts.source.getDataset?.())}undo(){(this.opts.adapter??tt()).deleteVertex(this.opts.arcs,this.opts.insertionId),this.opts.source.markDisplayArcsDirty?.(),zt(this.opts.source.getDataset?.())}}class hs{opts;label="Delete vertex";constructor(t){this.opts=t}do(){(this.opts.adapter??tt()).deleteVertex(this.opts.arcs,this.opts.vertexIndex),this.opts.source.markDisplayArcsDirty?.(),zt(this.opts.source.getDataset?.())}undo(){(this.opts.adapter??tt()).insertVertex(this.opts.arcs,this.opts.vertexIndex,this.opts.coords),this.opts.source.markDisplayArcsDirty?.(),zt(this.opts.source.getDataset?.())}}class ls{name="vertexEdit";_map;_enabled=!1;_manager;_polygonFillColor;_hoveredFeature=null;_hoverVertexCoords=null;_hoverVertexIds=[];_hoverType=null;_hoverInsertionId=-1;_dragging=!1;_neighborShapes=[];_dragFromCoords=null;_onMapMoveBound=()=>this._onMapMove();constructor(t,e={}){this._map=t,this._polygonFillColor=void 0!==e.polygonFillColor?e.polygonFillColor:"rgba(0,0,0,0.15)"}isEnabled(){return this._enabled}enable(){this._enabled||(this._enabled=!0,this._map.setEditMode("vertex"),this._map.on("move",this._onMapMoveBound),this._manager?.refreshCursor())}getCursor(){return this._enabled?"crosshair":null}disable(){this._enabled&&(this._enabled=!1,this._hoveredFeature=null,this._hoverVertexCoords=null,this._hoverVertexIds=[],this._hoverType=null,this._hoverInsertionId=-1,this._neighborShapes=[],this._dragging=!1,this._map.setEditMode("none"),this._map.clearEditVertexState(),this._map.off("move",this._onMapMoveBound),this._manager?.refreshCursor(),this._map.render())}setOptions(t){void 0!==t.polygonFillColor&&(this._polygonFillColor=t.polygonFillColor)}getOptions(){return{polygonFillColor:this._polygonFillColor??void 0}}handlePointer(t){if(!this._enabled)return"passthrough";const e=t.point.x,i=t.point.y;return"move"===t.kind?this._dragging?(this._handleDrag(e,i),"exclusive"):(this._onMouseMove(e,i),"passthrough"):"down"===t.kind?0!==t.button?"passthrough":(this._onMouseDown(e,i),this._dragging?"exclusive":"passthrough"):"up"===t.kind?this._dragging?(this._finishDrag(e,i),"passthrough"):"passthrough":"contextmenu"===t.kind?(this._onContextMenu(t.originalEvent),"consumed"):"passthrough"}_onMapMove(){this._hoveredFeature&&!this._dragging&&(this._updateEditState(),this._map.render())}_onContextMenu(t){if(t.preventDefault(),this._dragging)return;if("vertex"!==this._hoverType||0===this._hoverVertexIds.length)return;if(!this._hoveredFeature)return;const e=this._hoverVertexIds[0],i=this._hoveredFeature.arcs;tt().vertexIsArcEndpoint(e,i)||this._showContextMenu(t.clientX,t.clientY,()=>{this._deleteHoveredVertex()})}_deleteHoveredVertex(){if(!this._hoveredFeature||0===this._hoverVertexIds.length)return;const t=this._hoveredFeature.arcs,e=this._hoverVertexIds[0],i=this._hoveredFeature.source,s=t.getVertex2(e);if(tt().deleteVertex(t,e),this._refreshSourceDisplayArcs(i),this._bumpSourceEditVersion(i),s){const n=this._map.getSource(i);n&&this._map.pushCommand(new hs({vertexIndex:e,coords:[s[0],s[1]],arcs:t,source:n}))}this._hoverVertexCoords=null,this._hoverVertexIds=[],this._hoverType=null,this._hoverInsertionId=-1,this._neighborShapes=[],this._map.clearEditVertexState(),this._map.render()}_refreshSourceDisplayArcs(t){this._map.getSource(t)?.refreshDisplayArcs()}_bumpSourceEditVersion(t){const e=this._map.getSource(t);zt(e?.getDataset?.()??null)}_showContextMenu(t,e,i){document.getElementById("emap-ctx-menu")?.remove();const s=document.createElement("div");s.id="emap-ctx-menu",s.className="emap-ctx-menu",s.style.left=`${t}px`,s.style.top=`${e}px`;const n=document.createElement("div");n.className="emap-ctx-menu-item",n.textContent="删除节点",n.addEventListener("click",t=>{t.stopPropagation(),s.remove(),document.removeEventListener("click",r),i()}),s.appendChild(n),document.body.appendChild(s);const r=()=>{s.remove(),document.removeEventListener("click",r)};setTimeout(()=>document.addEventListener("click",r),0)}_onMouseMove(t,e){const i=this._map.queryFeatures([t,e]);if(0===i.length)return this._hoveredFeature=null,this._hoverVertexCoords=null,this._hoverVertexIds=[],this._hoverType=null,this._hoverInsertionId=-1,this._neighborShapes=[],this._map.clearEditVertexState(),void this._map.render();const s=i[0];if("point"===s.geometryType)return this._hoveredFeature=null,this._hoverVertexCoords=null,this._hoverVertexIds=[],this._hoverType=null,this._hoverInsertionId=-1,this._neighborShapes=[],this._map.clearEditVertexState(),void this._map.render();const n=this._map.getSource(s.source);if(!n)return;const r=n.getLayers(),a=n.getArcs();if(!a)return;let o=null;for(const t of r)if(Ot(t)&&t.shapes&&t.shapes[s.id]){o=t.shapes[s.id];break}o&&(this._hoveredFeature={source:s.source,layer:s.layer,id:s.id,shape:o,arcs:a,geometryType:s.geometryType,allLayers:r},this._findNearestVertices(o,a,t,e),this._hoverVertexCoords||this._findInterpolatedPoint(o,a,t,e),this._findNeighborShapes(a),this._updateEditState(),this._map.render())}_findNearestVertices(t,e,i,s){const n=this._map.unproject(i,s),r=tt().findNearestVertices(n,t,e);if(!r||0===r.length)return this._hoverVertexCoords=null,void(this._hoverVertexIds=[]);const a=e.getVertex2(r[0]);if(!a)return this._hoverVertexCoords=null,void(this._hoverVertexIds=[]);const o=this._map.project(a[0],a[1]);Math.sqrt((o[0]-i)*(o[0]-i)+(o[1]-s)*(o[1]-s))<=10?(this._hoverVertexCoords=[a[0],a[1]],this._hoverVertexIds=r,this._hoverType="vertex",this._hoverInsertionId=-1):(this._hoverVertexCoords=null,this._hoverVertexIds=[],this._hoverType=null,this._hoverInsertionId=-1)}_findInterpolatedPoint(t,e,i,s){const n=this._map.unproject(i,s);let r=1/0,a=null;const o=tt();if(o.forEachSegmentInShape(t,e,(t,e,i,s)=>{const h=i[t],l=s[t],c=i[e],u=s[e],p=o.findClosestPointOnSeg(n[0],n[1],h,l,c,u,0),_=p[0]-n[0],d=p[1]-n[1],f=Math.sqrt(_*_+d*d);f<r&&(r=f,a={insertionId:(t<e?t:e)+1,point:[p[0],p[1]]})}),!a)return;const h=a,l=this._map.project(h.point[0],h.point[1]);Math.sqrt((l[0]-i)*(l[0]-i)+(l[1]-s)*(l[1]-s))<=10&&(this._hoverVertexCoords=h.point,this._hoverVertexIds=[],this._hoverType="interpolated",this._hoverInsertionId=h.insertionId)}_findNeighborShapes(t){if(this._neighborShapes=[],!this._hoveredFeature||"polygon"!==this._hoveredFeature.geometryType)return;const{ii:e}=t.getVertexData(),i=this._hoveredFeature.id,s=new Set;if(this._hoverVertexIds.length>0)for(const t of this._hoverVertexIds)s.add(tt().findArcIdFromVertexId(t,e));else"interpolated"===this._hoverType&&this._hoverInsertionId>0&&s.add(tt().findArcIdFromVertexId(this._hoverInsertionId-1,e));if(0===s.size)return;const n=[];for(const t of this._hoveredFeature.allLayers)if(t.shapes)for(let e=0;e<t.shapes.length;e++){if(e===i)continue;const r=t.shapes[e];if(!r)continue;let a=!1;for(const t of r){for(const e of t){const t=e>=0?e:~e;if(s.has(t)){a=!0;break}}if(a)break}a&&n.push(r)}this._neighborShapes=n}_updateEditState(){if(!this._hoveredFeature)return;const t=this._hoveredFeature.geometryType,e=this._neighborShapes.length>0?[this._hoveredFeature.shape,...this._neighborShapes]:[this._hoveredFeature.shape];this._map.setEditVertexState({shapes:e,arcs:this._hoveredFeature.arcs,hoverVertex:this._hoverVertexCoords,hoverType:this._hoverType,geometryType:t,polygonFill:"polygon"===t?this._polygonFillColor:null,neighborShapes:this._neighborShapes.length>0?this._neighborShapes:void 0})}_onMouseDown(t,e){if(this._hoverVertexCoords&&this._hoveredFeature){if("interpolated"===this._hoverType&&this._hoverInsertionId>=0){const t=this._hoveredFeature.arcs,e=[this._hoverVertexCoords[0],this._hoverVertexCoords[1]];tt().insertVertex(t,this._hoverInsertionId,e),this._hoverVertexIds=[this._hoverInsertionId],this._hoverType="vertex",this._bumpSourceEditVersion(this._hoveredFeature.source),this._pushVertexInsertCommand(this._hoverInsertionId,e)}this._dragFromCoords=this._hoverVertexCoords?[this._hoverVertexCoords[0],this._hoverVertexCoords[1]]:null,this._dragging=!0}}_pushVertexInsertCommand(t,e){if(!this._hoveredFeature)return;const i=this._map.getSource(this._hoveredFeature.source);i&&this._map.pushCommand(new os({insertionId:t,point:e,arcs:this._hoveredFeature.arcs,source:i}))}_handleDrag(t,e){if(!this._hoveredFeature||0===this._hoverVertexIds.length)return;const i=this._map.unproject(t,e),s=this._hoveredFeature.arcs;tt().snapVertices(this._hoverVertexIds,[i[0],i[1]],s),this._hoverVertexCoords=[i[0],i[1]],this._updateEditState(),this._map.render()}_finishDrag(t,e){if(!this._dragging||!this._hoveredFeature)return;this._dragging=!1;const i=this._map.unproject(t,e),s=this._hoveredFeature.source,n=this._hoveredFeature.arcs;n.transformPoints&&n.transformPoints(function(){}),this._refreshSourceDisplayArcs(s),this._bumpSourceEditVersion(s);const r=this._dragFromCoords;if(r&&(r[0]!==i[0]||r[1]!==i[1])&&this._hoverVertexIds.length>0){const t=this._map.getSource(s);t&&this._map.pushCommand(new as({vertexIds:[...this._hoverVertexIds],from:[r[0],r[1]],to:[i[0],i[1]],arcs:n,source:t}))}this._dragFromCoords=null,this._map.fire("vertex_moved",{id:this._hoveredFeature.id,source:s,layer:this._hoveredFeature.layer,vertexIndex:this._hoverVertexIds[0]??null,vertexIds:this._hoverVertexIds,coords:i}),this._map.render()}}class cs{opts;label;constructor(t){this.opts=t,this.label=`Draw ${t.geometryType}`}do(){const t=this.opts,e=t.adapter??tt();if("point"!==t.geometryType){if(!t.arcs||!t.arcVertices)throw new Error("FeatureCreateCommand: path features require arcs and arcVertices");e.appendEmptyArc(t.arcs);for(const i of t.arcVertices)e.appendVertex(t.arcs,i)}if(t.layer.shapes||(t.layer.shapes=[]),t.layer.shapes.push(t.appendedShape),null!==t.appendedRecord){const e=t.layer.data?.getRecords?.();e?.push(t.appendedRecord)}t.source.markDisplayArcsDirty?.(),zt(t.source.getDataset?.())}undo(){const t=this.opts,e=t.adapter??tt();if(t.layer.shapes?.pop(),null!==t.appendedRecord){const e=t.layer.data?.getRecords?.();e?.pop()}"point"!==t.geometryType&&t.arcs&&e.deleteLastArc(t.arcs),t.source.markDisplayArcsDirty?.(),zt(t.source.getDataset?.())}}class us{name="drawFeature";_map;_enabled=!1;_opts;_manager;_vertices=[];_cursorCoord=null;_snapCoord=null;_snapKind=null;_snapThreshold;_onMapMoveBound=()=>this._onMapMove();_onKeyDownBound=t=>this._onKeyDown(t);constructor(t,e){this._map=t,this._opts={...e??{}},this._snapThreshold=this._opts.snapThreshold??10,this._map.on("editmodechange",t=>{"draw"!==t.mode&&this._enabled&&this._quietDisable()})}isEnabled(){return this._enabled}setOptions(t){this._opts={...this._opts,...t},void 0!==t.snapThreshold&&(this._snapThreshold=t.snapThreshold)}getCursor(){return this._enabled?"crosshair":null}getOptions(){return{...this._opts}}enable(){if(!this._enabled){if(!this._opts.source||!this._opts.type)throw new Error("drawFeature: source+type required; call setOptions({source,type}) first");this._enabled=!0,this._map.setEditMode("draw"),window.addEventListener("keydown",this._onKeyDownBound),this._map.on("move",this._onMapMoveBound),this._manager?.refreshCursor()}}disable(){this._enabled&&(this._enabled=!1,this._clearDrawState(),window.removeEventListener("keydown",this._onKeyDownBound),this._map.off("move",this._onMapMoveBound),this._map.setEditMode("none"),this._map.clearEditDrawState(),this._manager?.refreshCursor(),this._map.render())}_quietDisable(){this._enabled=!1,window.removeEventListener("keydown",this._onKeyDownBound),this._map.off("move",this._onMapMoveBound),this._map.clearEditDrawState(),this._manager?.refreshCursor(),this._map.render()}handlePointer(t){if(!this._enabled)return"passthrough";const e=t.point.x,i=t.point.y;return"move"===t.kind?(this._onMouseMove(e,i),"passthrough"):"click"===t.kind?0!==t.button?"passthrough":(this._onClick(e,i),"consumed"):"dblclick"===t.kind?(this._onDblClick(t.originalEvent),"consumed"):"passthrough"}_onMapMove(){this._vertices.length>0&&(this._updateDrawState(),this._map.render())}_onMouseMove(t,e){const i=this._map.unproject(t,e);this._cursorCoord=[i[0],i[1]];const s=this._findSnapTarget(t,e);this._snapCoord=s?.coord??null,this._snapKind=s?.kind??null,(this._vertices.length>0||this._snapCoord)&&(this._updateDrawState(),this._map.render())}_onClick(t,e){const i=this._snapCoord?[this._snapCoord[0],this._snapCoord[1]]:this._map.unproject(t,e);if("point"===this._opts.type)return this._vertices=[i],void this._commitFeature();if("polygon"===this._opts.type&&this._vertices.length>=3){const i=this._vertices[0],s=this._map.project(i[0],i[1]);if(Math.hypot(s[0]-t,s[1]-e)<=12)return void this._commitFeature()}this._vertices.push(i),this._updateDrawState(),this._map.render()}_onDblClick(t){t.preventDefault(),t.stopPropagation(),"point"!==this._opts.type&&("polyline"===this._opts.type&&this._vertices.length>=2||"polygon"===this._opts.type&&this._vertices.length>=3)&&this._commitFeature()}_onKeyDown(t){"Escape"===t.key&&(this._clearDrawState(),this._map.clearEditDrawState(),this._map.render())}_findSnapTarget(t,e){const i=this._map,s=this._opts.snapSources??[this._opts.source],n=!1!==this._opts.snapToVertex,r=!1!==this._opts.snapToEdge;let a=this._snapThreshold,o=null,h=null;for(const l of s){const s=i.getSource(l);if(!s)continue;const c=s.getArcs();if(!c?.getVertexData)continue;const u=c.getVertexData();if(!u)continue;const p=u.xx,_=u.yy;if(n)for(let s=0;s<p.length;s++){const n=i.project(p[s],_[s]),r=Math.hypot(n[0]-t,n[1]-e);r<a&&(a=r,o=[p[s],_[s]],h="vertex")}r&&c.forEachSegment&&c.forEachSegment((s,n,r,l)=>{const c=i.project(r[s],l[s]),u=i.project(r[n],l[n]),p=ps([t,e],c,u);p.dist<a&&(a=p.dist,o=i.unproject(p.point[0],p.point[1]),h="edge")})}if(n)for(const s of this._vertices){const n=i.project(s[0],s[1]),r=Math.hypot(n[0]-t,n[1]-e);r<a&&(a=r,o=[s[0],s[1]],h="vertex")}return o?{coord:o,kind:h}:null}_commitFeature(){if(0===this._vertices.length)return;const t=this._map.getSource(this._opts.source);if(!t)return;const e=t.getDataset();if(!e)return;const i=this._resolveTargetLayer(e.layers);if(!i)return;const s=e.layers.indexOf(i);let n,r,a;if(i.shapes||(i.shapes=[]),"point"===this._opts.type)n=[this._vertices[0]],i.shapes.push(n);else{if(r="polygon"===this._opts.type?[...this._vertices,this._vertices[0]]:[...this._vertices],a=e.arcs,!a)return;n=[[this._appendArc(a,r)]],i.shapes.push(n)}let o=null;if(i.data){const t=i.data.getRecords?.();t&&(o={},t.push(o))}t.refreshDisplayArcs(),this._map.pushCommand(new cs({geometryType:this._opts.type,layer:i,source:t,appendedShape:n,appendedRecord:o,arcVertices:r,arcs:a}));const h=i.shapes.length-1,l=rt(i,s>=0?s:0);this._map.fire("feature_created",{id:h,source:this._opts.source,layer:l,geometryType:this._opts.type,properties:{}}),this._clearDrawState(),this._map.clearEditDrawState(),t.fire("data",{reason:"edit"})}_resolveTargetLayer(t){if(!t.length)return null;if(this._opts.sourceLayer)for(let e=0;e<t.length;e++){if(rt(t[e],e)===this._opts.sourceLayer)return t[e]}const e="polygon"===this._opts.type?"polygon":"polyline"===this._opts.type?"polyline":"point";for(const i of t)if(i.geometry_type===e)return i;return t[0]}_appendArc(t,e){const i=t.getVertexData(),s=i.xx,n=i.yy,r=i.nn,a=i.zz,o=s.length,h=r.length,l=e.length,c=new Float64Array(o+l),u=new Float64Array(o+l),p=new Int32Array(h+1);c.set(s),u.set(n),p.set(r);for(let t=0;t<l;t++)c[o+t]=e[t][0],u[o+t]=e[t][1];p[h]=l;let _=null;if(a){_=new Float64Array(o+l),_.set(a);for(let t=0;t<l;t++)_[o+t]=1/0}return t.updateVertexData(p,c,u,_),h}_updateDrawState(){this._map.setEditDrawState({vertices:[...this._vertices],cursorCoord:this._snapCoord||this._cursorCoord,snapCoord:this._snapCoord,snapKind:this._snapKind,geometryType:this._opts.type,drawColor:this._opts.drawColor||"#0078ff"})}_clearDrawState(){this._vertices=[],this._cursorCoord=null,this._snapCoord=null,this._snapKind=null}}function ps(t,e,i){const s=e[0],n=e[1],r=i[0],a=i[1],o=t[0],h=t[1],l=r-s,c=a-n,u=l*l+c*c;if(0===u){const t=o-s,e=h-n;return{point:[s,n],dist:Math.hypot(t,e)}}let p=((o-s)*l+(h-n)*c)/u;p<0?p=0:p>1&&(p=1);const _=s+p*l,d=n+p*c;return{point:[_,d],dist:Math.hypot(o-_,h-d)}}class _s{_map;name="transformFeature";_enabled=!1;_opts={};_translate=null;_affine=null;_lastMap=null;_hoveringSelected=!1;_manager;_prevAngle=0;_prevDist=1;_onKeyDownBound=t=>this._onKeyDown(t);constructor(t){this._map=t,this._map.on("editmodechange",t=>{"transform"!==t.mode&&this._enabled&&this._quietDisable()})}get _mode(){return this._opts.mode??"translate"}enable(){this._enabled||(this._enabled=!0,this._map.setEditMode("transform"),window.addEventListener("keydown",this._onKeyDownBound),this._manager?.refreshCursor())}disable(){this._enabled&&(this._enabled=!1,this._cancelSession(),this._hoveringSelected=!1,window.removeEventListener("keydown",this._onKeyDownBound),this._map.setEditMode("none"),this._manager?.refreshCursor(),this._map.render())}_quietDisable(){this._enabled=!1,this._cancelSession(),this._hoveringSelected=!1,window.removeEventListener("keydown",this._onKeyDownBound),this._manager?.refreshCursor(),this._map.render()}isEnabled(){return this._enabled}setOptions(t){this._opts={...this._opts,...t}}getOptions(){return this._opts}getCursor(){return this._enabled&&(this._translate||"translate"===this._mode&&this._hoveringSelected)?"move":null}_cancelSession(){this._translate&&(this._translate.cancel(),this._translate=null),this._affine&&(this._affine.cancel(),this._affine=null),this._lastMap=null}_onKeyDown(t){"Escape"===t.key&&(this._translate||this._affine)&&this._cancelSession()}handlePointer(t){if(!this._enabled)return"passthrough";if("down"===t.kind){if(0!==t.button)return"passthrough";const e=this._map.queryFeatures([t.point.x,t.point.y]);if("translate"===this._mode&&(this._hoveringSelected=e.length>0),!e.length||!this._map.isSelected(e[0]))return"passthrough";const i=this._map.unproject(t.point.x,t.point.y);if("translate"===this._mode){if(this._translate=this._map.editSession.beginTranslateSession(this._opts.session),!this._translate)return"passthrough";this._lastMap=i}else{if(this._affine=this._map.editSession.beginAffineSession(void 0,this._opts.session),!this._affine)return"passthrough";const[t,e]=this._affine.origin;this._prevAngle=Math.atan2(i[1]-e,i[0]-t),this._prevDist=Math.hypot(i[0]-t,i[1]-e)||1}return"exclusive"}if("move"===t.kind){if(!this._translate&&!this._affine){const e=this._map.queryFeatures([t.point.x,t.point.y]);return this._hoveringSelected=e.some(t=>this._map.isSelected(t)),"passthrough"}const e=this._map.unproject(t.point.x,t.point.y);if(this._translate)this._lastMap&&this._translate.move(e[0]-this._lastMap[0],e[1]-this._lastMap[1]),this._lastMap=e;else if(this._affine){const[t,i]=this._affine.origin;if("rotate"===this._mode){const s=Math.atan2(e[1]-i,e[0]-t),n=s-this._prevAngle;0!==n&&this._affine.applyDelta(Bt(n,t,i)),this._prevAngle=s}else{const s=Math.hypot(e[0]-t,e[1]-i)||1,n=s/this._prevDist;1!==n&&this._affine.applyDelta(Ut(n,n,t,i)),this._prevDist=s}}return"exclusive"}return"up"===t.kind&&(this._translate||this._affine)?(this._translate&&(this._translate.commit(),this._translate=null),this._affine&&(this._affine.commit(),this._affine=null),this._lastMap=null,this._hoveringSelected=!1,"passthrough"):"passthrough"}}function ds(t){if(!t||"object"!=typeof t)return!1;const e=t;return"string"==typeof e.name&&"function"==typeof e.enable&&"function"==typeof e.disable&&"function"==typeof e.isEnabled&&"function"==typeof e.setOptions&&"function"==typeof e.getOptions&&"function"==typeof e.handlePointer}const fs=["lassoSelect","boxSelect","clickSelect","transformFeature","drawFeature","vertexEdit","dragPan"];class ms{_handlers=new Map;_element=null;_exclusive=null;_pointerSink=null;_onDown=t=>this._dispatch(this._norm(t,"down"));_onMove=t=>this._dispatch(this._norm(t,"move"));_onUp=t=>this._dispatch(this._norm(t,"up"));_onClick=t=>this._dispatch(this._norm(t,"click"));_onContextMenu=t=>this._dispatch(this._norm(t,"contextmenu"));_onDblClick=t=>this._dispatch(this._norm(t,"dblclick"));register(t){if(!ds(t))throw new Error("HandlerManager.register: argument is not a valid Handler");this._handlers.set(t.name,t),t._manager=this}isEnabledByName(t){const e=this._handlers.get(t);return!!e&&e.isEnabled()}get(t){return this._handlers.get(t)}applyInteractive(t){for(const e of["dragPan","scrollZoom"]){const i=this._handlers.get(e);i&&(t?i.enable():i.disable())}}attach(t){this.detach(),this._element=t,t.addEventListener("pointerdown",this._onDown),window.addEventListener("pointermove",this._onMove),window.addEventListener("pointerup",this._onUp),t.addEventListener("click",this._onClick),t.addEventListener("contextmenu",this._onContextMenu),t.addEventListener("dblclick",this._onDblClick)}detach(){this._element&&(this._element.removeEventListener("pointerdown",this._onDown),window.removeEventListener("pointermove",this._onMove),window.removeEventListener("pointerup",this._onUp),this._element.removeEventListener("click",this._onClick),this._element.removeEventListener("contextmenu",this._onContextMenu),this._element.removeEventListener("dblclick",this._onDblClick),this._element.style.cursor="",this._element=null,this._exclusive=null,this._pointerSink=null)}setPointerSink(t){this._pointerSink=t}_norm(t,e){const i=this._element.getBoundingClientRect();return{kind:e,point:{x:t.clientX-i.left,y:t.clientY-i.top},modifiers:{shift:t.shiftKey,ctrl:t.ctrlKey,alt:t.altKey,meta:t.metaKey},button:"button"in t?t.button:0,originalEvent:t}}_orderedEnabled(){const t=[];for(const e of fs){const i=this._handlers.get(e);i&&i.isEnabled()&&t.push(i)}return t}_dispatch(t){this._dispatchInner(t),this._applyCursor()}_dispatchInner(t){if(this._pointerSink&&("click"===t.kind||"move"===t.kind&&!this._exclusive)&&this._pointerSink(t),this._exclusive&&("move"===t.kind||"up"===t.kind)){return void("exclusive"!==this._exclusive.handlePointer(t)&&(this._exclusive=null))}for(const e of this._orderedEnabled()){const i=e.handlePointer(t);if("exclusive"===i)return void(this._exclusive=e);if("consumed"===i)return}}_applyCursor(){if(!this._element)return;let t=null;const e=this._exclusive;if(e&&e.isEnabled()&&(t=e.getCursor?.()??null),!t)for(const e of this._orderedEnabled()){const i=e.getCursor?.();if(i){t=i;break}}const i=t??"";this._element.style.cursor!==i&&(this._element.style.cursor=i)}refreshCursor(){this._applyCursor()}}class ys{_workerUrl;_WorkerCtor;_slots;_pending=new Map;_nextId=1;_rrCursor=0;_destroyed=!1;constructor(t){this._workerUrl=t.workerUrl,this._WorkerCtor=t.WorkerCtor??globalThis.Worker;const e=Math.max(1,Math.floor(t.poolSize??1));this._slots=Array.from({length:e},()=>({worker:null,epoch:0,pendingCount:0}))}run(t,e,i){return this.runWithId(t,e,i).promise}runWithId(t,e,i){const s=this.reserveId();return{id:s,promise:this.dispatchWithId(s,t,e,i)}}reserveId(){return this._nextId++}dispatchWithId(t,e,i,s,n){if(this._destroyed)return Promise.reject(new Error("MapshaperWorkerPool: destroyed"));const r=this._pickWorker();let a;try{a=this._ensureWorker(r)}catch(t){return Promise.reject(t)}const o=this._slots[r],h=o.epoch;return o.pendingCount++,new Promise((o,l)=>{this._pending.set(t,{resolve:o,reject:l,workerIndex:r,epoch:h});const c={id:t,type:"run",packed:i};"string"==typeof e?c.cmd=e:c.commands=e,s&&(c.inputFiles=s),n&&n.length>0?a.postMessage(c,n):a.postMessage(c)})}destroy(){this._destroyed||(this._destroyed=!0,this._terminateAll(new Error("MapshaperWorkerPool: destroyed")))}cancelAll(){this._destroyed||this._terminateAll(new Error("MapshaperWorkerPool: cancelled"))}isWorkerSpawned(){return this._slots.some(t=>null!==t.worker)}get poolSize(){return this._slots.length}_pickWorker(){let t=0,e=1/0,i=!1;const s=this._slots.length;for(let n=0;n<s;n++){const r=(this._rrCursor+n)%s,a=this._slots[r],o=null!==a.worker;(a.pendingCount<e||a.pendingCount===e&&o&&!i)&&(t=r,e=a.pendingCount,i=o)}return this._rrCursor=(t+1)%s,t}_terminateAll(t){for(const t of this._slots)t.worker&&(t.worker.terminate(),t.worker=null),t.epoch++,t.pendingCount=0;for(const{reject:e}of this._pending.values())e(t);this._pending.clear()}_ensureWorker(t){const e=this._slots[t];if(e.worker)return e.worker;if(!this._WorkerCtor)throw new Error("MapshaperWorkerPool: Worker constructor not available in this environment");const i=new this._WorkerCtor(this._workerUrl);return i.onmessage=e=>this._onMessage(t,e.data),i.onerror=e=>this._onWorkerError(t,e),e.worker=i,i}_onMessage(t,e){if(!e||"number"!=typeof e.id)return;const i=this._pending.get(e.id);if(!i)return;const s=this._slots[t];i.workerIndex===t&&i.epoch===s.epoch&&(this._pending.delete(e.id),s.pendingCount=Math.max(0,s.pendingCount-1),"ok"===e.type?i.resolve(e.packed):i.reject(new Error(e.message||"mapshaper worker error")))}_onWorkerError(t,e){const i=new Error(`mapshaper worker error: ${e.message||"unknown"}`),s=this._slots[t];s.worker&&(s.worker.terminate(),s.worker=null),s.epoch++,s.pendingCount=0;const n=[];for(const[e,i]of this._pending)i.workerIndex===t&&n.push(e);for(const t of n){const e=this._pending.get(t);this._pending.delete(t),e?.reject(i)}}}const gs=["feature:click","feature:hover","feature:enter","feature:leave"];function vs(t){return gs.includes(t)}function xs(t,e){return!t||(!t.source||t.source===e.source)&&!(t.layers&&!t.layers.includes(e.layer))}class bs{_host;_reg={"feature:click":[],"feature:hover":[],"feature:enter":[],"feature:leave":[]};_lastKey=null;_lastRef=null;_onceWrap=new Map;_onChange;constructor(t){this._host=t}setOnChange(t){this._onChange=t}hasListeners(){return gs.some(t=>this._reg[t].length>0)}on(t,e,i){vs(t)&&(this._reg[t].push({filter:e,cb:i}),this._onChange?.())}once(t,e,i){if(!vs(t))return;const s=e=>{this.off(t,i),i(e)};this._onceWrap.set(i,s),this._reg[t].push({filter:e,cb:s}),this._onChange?.()}off(t,e){if(!vs(t))return;const i=this._onceWrap.get(e);this._reg[t]=this._reg[t].filter(t=>t.cb!==e&&(void 0===i||t.cb!==i)),this._onceWrap.delete(e),this._onChange?.()}_hit(t,e){let i=[];for(const t of gs){for(const e of this._reg[t]){if(!e.filter?.layers){i=void 0;break}i.push(...e.filter.layers)}if(void 0===i)break}const s=this._host.queryFeatures([t,e],i&&i.length?{layers:i}:void 0);if(0===s.length)return null;const n=s[0];return{source:n.source,layer:n.layer,id:n.id}}_emit(t,e,i){const s=this._reg[t];if(0===s.length)return;let n=null;for(const r of s)if(xs(r.filter,e)){if(!n){const s=this._host.features.get(e);if(!s)return;n={type:t,feature:s,ref:e,point:{x:i.point.x,y:i.point.y},lngLat:this._host.unproject(i.point.x,i.point.y),modifiers:{...i.modifiers},originalEvent:i.originalEvent}}r.cb(n)}}dispatch(t){if(!this.hasListeners())return;if("click"===t.kind){const e=this._hit(t.point.x,t.point.y);return void(e&&this._emit("feature:click",e,t))}if("move"!==t.kind)return;const e=this._hit(t.point.x,t.point.y),i=e?`${(s=e).source}|${s.layer}|${s.id}`:null;var s;i!==this._lastKey&&(this._lastRef&&this._emit("feature:leave",this._lastRef,t),e&&this._emit("feature:enter",e,t),this._lastKey=i,this._lastRef=e),e&&this._emit("feature:hover",e,t)}}const ws=["mousemove"];function Ss(t){return ws.includes(t)}class Cs{_host;_reg={mousemove:[]};_onceWrap=new Map;_onChange;constructor(t){this._host=t}setOnChange(t){this._onChange=t}hasListeners(){return ws.some(t=>this._reg[t].length>0)}on(t,e){Ss(t)&&(this._reg[t].push(e),this._onChange?.())}once(t,e){if(!Ss(t))return;const i=i=>{this.off(t,e),e(i)};this._onceWrap.set(e,i),this._reg[t].push(i),this._onChange?.()}off(t,e){if(!Ss(t))return;const i=this._onceWrap.get(e);this._reg[t]=this._reg[t].filter(t=>t!==e&&(void 0===i||t!==i)),this._onceWrap.delete(e),this._onChange?.()}dispatch(t){if(!this.hasListeners())return;if("move"!==t.kind)return;const e=this._reg.mousemove,i={point:{x:t.point.x,y:t.point.y},mapCoord:this._host.unproject(t.point.x,t.point.y),originalEvent:t.originalEvent};for(const t of e.slice())t(i)}}class As{_sources;_getTransform;_getSize;_getInitialMX;_indexCache=new globalThis.Map;constructor(t,e,i,s){this._sources=t,this._getTransform=e,this._getSize=i,this._getInitialMX=s}prebuild(t){if(void 0!==t){const e=this._sources.get(t);return void(e&&this._prebuildSource(t,e))}for(const[t,e]of this._sources)this._prebuildSource(t,e)}clear(t){if(void 0===t)return void this._indexCache.clear();const e=`${t}|`,i=[];for(const t of this._indexCache.keys())t.startsWith(e)&&i.push(t);for(const t of i)this._indexCache.delete(t)}_prebuildSource(t,e){if("topology"!==e.type)return;const i=e.getLayers(),s=e.getArcs(),n=e.getDataset?.();for(let e=0;e<i.length;e++)this._getOrBuildIndex(t,e,i[e],s,n)}_getOrBuildIndex(t,e,i,s,n){const r=i?.shapes;if(!r||0===r.length)return null;const a=s?.size?.()??0,o=n?.editVersion??0,h=`${t}|${e}|${r.length}|${a}|${o}`,l=this._indexCache.get(h);if(void 0!==l)return l;const c=`${t}|${e}|`,u=[];for(const t of this._indexCache.keys())t!==h&&t.startsWith(c)&&u.push(t);for(const t of u)this._indexCache.delete(t);const p="point"===i.geometry_type,_=new E(r.length),d=[];for(let t=0;t<r.length;t++){const e=r[t];if(!e){_.add(0,0,0,0);continue}let i=1/0,n=1/0,a=-1/0,o=-1/0;if(p)for(const t of at(e))!t||t.length<2||(t[0]<i&&(i=t[0]),t[0]>a&&(a=t[0]),t[1]<n&&(n=t[1]),t[1]>o&&(o=t[1]));else if(s?.getSimpleShapeBbox){const t=e;for(let e=0;e<t.length;e++)s.getSimpleShapeBbox(t[e],d),d[0]<i&&(i=d[0]),d[1]<n&&(n=d[1]),d[2]>a&&(a=d[2]),d[3]>o&&(o=d[3])}i!==1/0?_.add(i,n,a,o):_.add(0,0,0,0)}_.finish();const f={index:_,shapeCount:r.length};return this._indexCache.set(h,f),f}query(t,e,i){const{width:s,height:n}=this._getSize(),r=Array.isArray(t),a=r?t:[[0,0],[s,n]],o=e||(r?{}:t)||{};if(Array.isArray(a)&&"number"==typeof a[0]){const t=a;return this._queryFeaturesAtPoint(t,o,i)}const h=a;return this._queryFeaturesInBBox(h,o,i)}_layerMatchesFilter(t,e,i){if(!i||0===i.length)return!0;const s=rt(t,e);return!!i.includes(s)||(!(!t?.name||!i.includes(t.name))||!(!t?.id||!i.includes(t.id)))}_unproject(t,e){return this._getTransform().unproject(t,e)}_getHitBuffer(t){return t/Math.abs(this._getTransform().mx||1)}_getZoomAdjustedHitBuffer(t,e){const i=this._getTransform(),s=this._getInitialMX(),n=Math.abs(i.mx)/(s||Math.abs(i.mx)||1);return n<1&&(t*=n),e>0&&t<e&&(t=e),this._getHitBuffer(t)}_findHitCandidates(t,e,i,s,n,r,a,o){const h=[],l={},c=[],u=i.shapes;if(!u)return h;const p=this._getOrBuildIndex(t,e,i,s,o),_=p?p.index.search(n-a,r-a,n+a,r+a):null,d=null!==_?_.length:u.length;for(let t=0;t<d;t++){const e=null!==_?_[t]:t,i=u[e];if(i)for(let t=0;t<i.length;t++){const o=i[t];if(s.getSimpleShapeBbox(o,c),n+a<c[0]||n-a>c[2]||r+a<c[1]||r-a>c[3])continue;let u=l[e];u||(u=l[e]={shape:[],id:e,dist:0},h.push(u)),u.shape.push(o)}}return h}_sortByDistance(e,i,s,n){const r=t.geom;for(const t of s)t.info=r.getPointToShapeInfo(e,i,t.shape,n),t.dist=t.info.distance;s.sort((t,e)=>t.dist-e.dist)}_pickNearestCandidates(t,e,i){const s=[];let n=0;for(let r=0;r<t.length;r++){const a=t[r];if(!(a.dist<i))break;if(0===r)n=a.dist;else if(a.dist-n>e)break;s.push(a)}return s}_pointTest(e,i,s,n,r,a){const o=t.geom,h=Math.abs(this._getTransform().mx||1);let l=-1,c=1/0,u=25;const p=s.shapes;if(!p)return[];const _=u/(h||1),d=this._getOrBuildIndex(e,i,s,void 0,a),f=d?d.index.search(n-_,r-_,n+_,r+_):null,m=null!==f?f.length:p.length;for(let t=0;t<m;t++){const e=null!==f?f[t]:t,i=p[e];if(i)for(const t of at(i)){if(!t)continue;const i=o.distance2D(n,r,t[0],t[1])*h;i>u||(i<u&&u>2&&(u=Math.max(2,i)),i<c&&(c=i,l=e))}}return-1===l?[]:[l]}_polylineTest(t,e,i,s,n,r,a,o){const h=this._getZoomAdjustedHitBuffer(15,2),l=a>=0?a:.05,c=this._getZoomAdjustedHitBuffer(l,0);let u=this._findHitCandidates(t,e,i,s,n,r,h,o);return this._sortByDistance(n,r,u,s),u=this._pickNearestCandidates(u,c,h),u.length?[u[0].id]:[]}_polygonTest(e,i,s,n,r,a,o){const h=t.geom,l=this._getZoomAdjustedHitBuffer(10,1),c=this._findHitCandidates(e,i,s,n,r,a,l,o);let u=[];for(const t of c)h.testPointInPolygon(r,a,t.shape,n)&&u.push(t);return c.length>0&&0===u.length?(this._sortByDistance(r,a,c,n),u=this._pickNearestCandidates(c,0,l)):u.length>1&&this._sortByDistance(r,a,u,n),u.length?[u[0].id]:[]}_polygonVertexTest(t,e,i,s,n,r,a){const o=this._polygonTest(t,e,i,s,n,r,a),h=this._polylineTest(t,e,i,s,n,r,5,a);return o.length?o:h}_queryFeaturesAtPoint(t,e,i){const s=this._getTransform(),n=[],[r,a]=this._unproject(t[0],t[1]),o=1/Math.abs(s.mx||1);for(const[t,s]of this._sources){const h=s.getLayers(),l=s.getDisplayArcs(),c=l?l.getScaledArcs(o):s.getArcs(),u=s.getDataset?.();for(let s=0;s<h.length;s++){const o=h[s];if(!o?.shapes)continue;if(!this._layerMatchesFilter(o,s,e.layers))continue;const l=rt(o,s);if(i&&!i.has(`${t}:${l}`))continue;const p=o.geometry_type;let _=[];if("point"===p?_=this._pointTest(t,s,o,r,a,u):"polyline"===p&&c?_=this._polylineTest(t,s,o,c,r,a,-1,u):"polygon"===p&&c&&(_=this._polygonVertexTest(t,s,o,c,r,a,u)),0!==_.length)for(const e of _){const i=o.data,s=i?.getRecordAt?.(e)??i?.getRecords?.()?.[e]??{};n.push({id:e,source:t,layer:l,geometryType:p||"unknown",properties:{...s}})}}}return n}_queryFeaturesInBBox(t,e,i){const s=this._getTransform(),n=[],[r,a]=t,o=this._unproject(r[0],r[1]),h=this._unproject(a[0],a[1]),l=Math.min(o[0],h[0]),c=Math.min(o[1],h[1]),u=Math.max(o[0],h[0]),p=Math.max(o[1],h[1]),_=1/Math.abs(s.mx||1);for(const[t,s]of this._sources){const r=s.getLayers(),a=s.getDisplayArcs(),o=a?a.getScaledArcs(_):s.getArcs(),h=s.getDataset?.();for(let s=0;s<r.length;s++){const a=r[s];if(!a?.shapes)continue;if(!this._layerMatchesFilter(a,s,e.layers))continue;const _=rt(a,s);if(i&&!i.has(`${t}:${_}`))continue;const d=a.geometry_type,f=a.data,m=[],y=this._getOrBuildIndex(t,s,a,o,h),g=y?y.index.search(l,c,u,p):null,v=null!==g?g.length:a.shapes.length;for(let e=0;e<v;e++){const i=null!==g?g[e]:e,s=a.shapes[i];if(!s)continue;let r=!1;if("point"===d)r=at(s).some(t=>t[0]>=l&&t[0]<=u&&t[1]>=c&&t[1]<=p);else if(o){const t=s;for(let e=0;e<t.length;e++)if(o.getSimpleShapeBbox(t[e],m),!(u<m[0]||l>m[2]||p<m[1]||c>m[3])){r=!0;break}}if(!r)continue;const h=f?.getRecordAt?.(i)??f?.getRecords?.()?.[i]??{};n.push({id:i,source:t,layer:_,geometryType:d||"unknown",properties:{...h}})}}}return n}}class Es{_host;constructor(t){this._host=t}get(t){const e=this._host.layers.resolve(t.source,t.layer);if(!e)return null;if(!Number.isInteger(t.id)||t.id<0)return null;const i=e.shapes??null;if(!i||t.id>=i.length)return null;const s=i[t.id],n=e.data?.getRecords?.()??[];return{ref:t,geometry:s,properties:Object.freeze({...n[t.id]??{}})}}*iter(t,e){const i=this._host.layers.resolve(t,e);if(!i||!i.shapes)return;const s=i.shapes,n=i.data?.getRecords?.()??[];for(let i=0;i<s.length;i++)yield{ref:{source:t,layer:e,id:i},geometry:s[i],properties:Object.freeze({...n[i]??{}})}}count(t,e){const i=this._host.layers.resolve(t,e);return i?.shapes?.length??0}}class Ms{_all=new globalThis.Set;get size(){return this._all.size}register(t){return this._all.add(t),()=>{this._all.delete(t)}}unregisterAll(){this._all.clear()}async runFor(t,e,i){if(0===this._all.size)return[];const s=[];for(const e of this._all)e.phase===t&&s.push(e);if(0===s.length)return[];const n=await Promise.allSettled(s.map(t=>t.run(e,i))),r=[];for(let t=0;t<s.length;t++){const e=s[t],i=n[t];let a;a="fulfilled"===i.status?i.value:{ok:!1,issues:[{severity:"error",message:`validator '${e.name}' threw: ${i.reason instanceof Error?i.reason.message:String(i.reason)}`}]},r.push({validator:e.name,report:a})}return r}}class ks{_highlighted=new globalThis.Map;_highlightStyle={color:"#ff7a00",width:2.2,radius:6,fill:!0};get size(){return this._highlighted.size}setHighlightedFeatures(t,e){this._highlighted.clear(),e&&(this._highlightStyle={...this._highlightStyle,...e});for(const e of t){const t=this._highlighted.get(e.source)||new globalThis.Map,i=t.get(e.layer)||new Set;i.add(e.id),t.set(e.layer,i),this._highlighted.set(e.source,t)}}clearHighlightedFeatures(){return 0!==this._highlighted.size&&(this._highlighted.clear(),!0)}setHighlightStyle(t){return this._highlightStyle={...this._highlightStyle,...t},this._highlighted.size>0}renderHighlights(t,e,i,s,n){if(0===this._highlighted.size)return;const r=this._highlightStyle.color||"#ff7a00",a=(this._highlightStyle.width??2.2)*s,o=this._highlightStyle.radius??6,h=!1!==this._highlightStyle.fill,l=1/Math.abs(i.mx||1);for(const[i,s]of e){const e=this._highlighted.get(i);if(!e)continue;const c=s.getLayers(),u=s.getDisplayArcs(),p=u?u.getScaledArcs(l):s.getArcs();for(let s=0;s<c.length;s++){const l=c[s];if(!l?.shapes)continue;const u=rt(l,s);if(n&&!n.has(`${i}:${u}`))continue;const _=e.get(u);if(!_||0===_.size)continue;const d=[];for(const t of _){const e=l.shapes[t];e&&d.push(e)}0!==d.length&&("point"===l.geometry_type?t.drawPoints(d,{color:r,radius:o,fill:h}):p&&t.drawPaths(d,{color:r,width:a},p))}}}}class Is{_byKey=new globalThis.Map;_size=0;get size(){return this._size}has(t){return this._byKey.get(t.source)?.get(t.layer)?.has(t.id)??!1}getAll(){const t=[];for(const[e,i]of this._byKey)for(const[s,n]of i)for(const i of n)t.push({source:e,layer:s,id:i});return t}getByLayer(t,e){const i=this._byKey.get(t)?.get(e);return i?Array.from(i):[]}clear(){if(0===this._size)return{added:[],removed:[],changed:!1};const t=this.getAll();return this._byKey.clear(),this._size=0,{added:[],removed:t,changed:!0}}apply(t,e){const i=Ls(t);if("replace"===e){const t=this._refSetSnapshot();this._byKey.clear(),this._size=0;for(const t of i)this._addOne(t);return Ts(t,this._refSetSnapshot())}const s=[],n=[];if("add"===e)for(const t of i)this._addOne(t)&&s.push(t);else for(const t of i)this.has(t)?this._removeOne(t)&&n.push(t):this._addOne(t)&&s.push(t);return{added:s,removed:n,changed:s.length>0||n.length>0}}remove(t){const e=[];for(const i of Ls(t))this._removeOne(i)&&e.push(i);return{added:[],removed:e,changed:e.length>0}}snapshot(){return this._refSetSnapshot()}restore(t){const e=this._refSetSnapshot();this._byKey.clear(),this._size=0;for(const e of t)this._addOne(Ps(e));return Ts(e,t)}_addOne(t){let e=this._byKey.get(t.source);e||(e=new globalThis.Map,this._byKey.set(t.source,e));let i=e.get(t.layer);return i||(i=new Set,e.set(t.layer,i)),!i.has(t.id)&&(i.add(t.id),this._size++,!0)}_removeOne(t){const e=this._byKey.get(t.source),i=e?.get(t.layer);return!!i?.has(t.id)&&(i.delete(t.id),this._size--,0===i.size&&(e.delete(t.layer),0===e.size&&this._byKey.delete(t.source)),!0)}_refSetSnapshot(){const t=new Set;for(const[e,i]of this._byKey)for(const[s,n]of i)for(const i of n)t.add(Ds(e,s,i));return t}}function Ds(t,e,i){return JSON.stringify([t,e,i])}function Ps(t){const[e,i,s]=JSON.parse(t);return{source:e,layer:i,id:s}}function Ts(t,e){const i=[],s=[];for(const s of e)t.has(s)||i.push(Ps(s));for(const i of t)e.has(i)||s.push(Ps(i));return{added:i,removed:s,changed:i.length>0||s.length>0}}function Ls(t){const e=new Set,i=[];for(const s of t){const t=Ds(s.source,s.layer,s.id);e.has(t)||(e.add(t),i.push(s))}return i}class Fs{_undoStack=[];_redoStack=[];_maxSize;_lastSkippedStale=!1;_captureBuffer=null;constructor(t={}){if(this._maxSize=t.maxSize??200,this._maxSize<1)throw new Error("EditHistory: maxSize must be >= 1")}push(t){if(this._captureBuffer)return void this._captureBuffer.push(t);const e=this._undoStack[this._undoStack.length-1];if(e&&!e.stale&&e.merge&&t.mergeable?.(e))return e.merge(t),void(this._redoStack.length=0);if(t.invalidatesPriorCommands){for(const t of this._undoStack)t.stale=!0;this._redoStack.length=0}this._undoStack.push(t),this._redoStack.length=0,this._undoStack.length>this._maxSize&&this._undoStack.shift()}beginCapture(){if(this._captureBuffer)throw new Error("EditHistory: nested capture not supported");this._captureBuffer=[]}endCapture(){const t=this._captureBuffer;return this._captureBuffer=null,t??[]}isCapturing(){return null!==this._captureBuffer}undo(){const t=this._undoStack.pop();return t?(t.stale?this._lastSkippedStale=!0:(t.undo(),this._lastSkippedStale=!1),this._redoStack.push(t),t):null}redo(){const t=this._redoStack.pop();return t?(t.stale?this._lastSkippedStale=!0:(t.do(),this._lastSkippedStale=!1),this._undoStack.push(t),t):null}clear(){this._undoStack.length=0,this._redoStack.length=0,this._lastSkippedStale=!1}canUndo(){return this._undoStack.length>0}canRedo(){return this._redoStack.length>0}size(){return this._undoStack.length}snapshot(){const t=this._undoStack[this._undoStack.length-1];let e=0;for(const t of this._undoStack)t.stale&&e++;const i={canUndo:this._undoStack.length>0,canRedo:this._redoStack.length>0,label:t?.label,staleCount:e,topIsStale:!!t?.stale};return this._lastSkippedStale&&(i.skippedStale=!0),i}}class Ns{_host;_datasetSnapshots=new globalThis.Map;_selectionSnapshot;_closed=!1;constructor(t){if(t._activeTransaction)throw new Error("Transaction: another transaction is already active");this._host=t,this._selectionSnapshot=t._selection.snapshot(),t._history.beginCapture(),t._activeTransaction=this}_captureFirstTouch(t,e){this._datasetSnapshots.has(t)||this._datasetSnapshots.set(t,e)}get isOpen(){return!this._closed}async commit(t){this._end();const e=this._host._history.endCapture();if(0===e.length)return ct;const i=new Rt(e,t);return this._host._history.push(i),this._host._fireHistoryChange(),ct}rollback(){this._end(),this._host._history.endCapture();for(const[t,e]of this._datasetSnapshots){const i=this._host._sources.get(t);i&&i.setDataset(e)}const t=this._host._selection.restore(this._selectionSnapshot);t.changed&&this._host._fireSelectionChange(t),this._host._fireHistoryChange(),this._host._scheduleRender()}_end(){if(this._closed)throw new Error("Transaction: already committed or rolled back");this._closed=!0,this._host._activeTransaction=null}}class Rs{opts;label="Delete feature";constructor(t){this.opts=t}do(){const{layer:t,featureId:e}=this.opts;if(!t.shapes)return;t.shapes.splice(e,1);const i=t.data?.getRecords?.();i?.splice(e,1)}undo(){const{layer:t,featureId:e,shape:i,record:s}=this.opts;if(t.shapes||(t.shapes=[]),t.shapes.splice(e,0,i),null!==s){const i=t.data?.getRecords?.();i?.splice(e,0,s)}}}class Os{opts;label;constructor(t){this.opts=t,this.label=`Delete ${t.snapshots.length} feature${1===t.snapshots.length?"":"s"}`}do(){const{layer:t,snapshots:e}=this.opts;if(!t.shapes||0===e.length)return;const i=new Set;for(const t of e)i.add(t.id);const s=t.shapes,n=new Array(s.length-i.size);let r=0;for(let t=0;t<s.length;t++)i.has(t)||(n[r++]=s[t]);t.shapes=n;const a=t.data?.getRecords?.();if(a){let t=0;for(let e=0;e<a.length;e++)i.has(e)||(a[t++]=a[e]);a.length=t}}undo(){const{layer:t,snapshots:e}=this.opts;t.shapes||(t.shapes=[]);const i=[...e].sort((t,e)=>t.id-e.id),s=t.data?.getRecords?.();for(const e of i)t.shapes.splice(e.id,0,e.shape),s&&null!==e.record&&s.splice(e.id,0,e.record)}}function Gs(t,e){const i=t||{};return{color:i["line-color"]||i["fill-color"]||"#333",width:(i["line-width"]??.8)*e}}function zs(t){const e=t||{};return{color:e["circle-color"]||"#333",radius:e["circle-radius"]??4,fill:!1!==e["circle-fill"]}}class qs extends U{_container;_canvasContainer;_canvas;_painter;_editOverlay;_viewport=new Z;_projection=new nt;_camera;_sources=new globalThis.Map;_layersCache;get layers(){return this._layersCache??(this._layersCache=new Et(this._sources))}_sourceListeners=new globalThis.Map;_layers=[];_effectiveLayersCache=[];_defaultLayersDirty=!0;_layerArcFlagsCache=new globalThis.Map;_handlers;_featureEvents;_pointerEvents;_scrollZoom;_dragPan;_clickSelect;_boxSelect;_lassoSelect;_vertexEdit;_drawFeature;_transformFeature;_pendingRender=0;_rafId=0;_controlContainers=new globalThis.Map;_controls=[];_highlightManager=new ks;_featureQuery;features;_selection=new Is;_history=new Fs;_activeTransaction=null;_validators=new Ms;get validators(){return this._validators}_historyShortcutUnbind=null;_ops;_editSession;_attributes;get ops(){return this._ops??(this._ops=new Nt(this))}get editSession(){return this._editSession??(this._editSession=new Jt(this))}get attributes(){return this._attributes??(this._attributes=new ne(this))}_editState=new re(t=>{if(t.modeChanged){"vertex"===t.current.mode||"draw"===t.current.mode?this._dragPan?.disable():this._dragPan?.enable(),this.fire("editmodechange",{mode:t.current.mode})}this._scheduleRender()});_workerPool=null;_workerMode=!1;_workerThreshold=5e4;_workerRouting;_expressionPolicy="disabled";constructor(t){if(super(),"string"==typeof t.container){const e=document.getElementById(t.container);if(!e)throw new Error(`Container #${t.container} not found`);this._container=e}else this._container=t.container;this._canvasContainer=this._createCanvasContainer(),this._container.appendChild(this._canvasContainer),this._canvas=document.createElement("canvas"),this._canvas.style.position="absolute",this._canvas.style.top="0",this._canvas.style.left="0",this._canvasContainer.appendChild(this._canvas),this._painter=new ot(this._canvas),this._painter.setPixelRatio(window.devicePixelRatio||1),this._editOverlay=new ht(this._painter),this._updateSize(),this._viewport.onViewChange=()=>this.fire("move"),this._viewport.initZoomTween(),this._camera=new J({getCameraState:()=>this._viewport.getCameraState(),applyCameraState:(t,e)=>this._viewport.applyCameraState(t,e),scaleFromZoom:t=>this._projection.getScale(t),getViewportSize:()=>({width:this._viewport.width,height:this._viewport.height}),fire:(t,e)=>this.fire(t,e),requestRender:()=>this._scheduleRender(),cancelZoomAnimation:()=>this._viewport.cancelZoomAnimation()}),this._handlers=new ms,this._scrollZoom=new Ri(this._canvasContainer,()=>this.stop()),this._dragPan=new Gi(void 0,()=>this.stop(),t=>this.queryFeatures([t.x,t.y]).some(t=>this.isSelected(t))),this._handlers.register(this._dragPan),this._handlers.register(this._scrollZoom),this._clickSelect=new ts(this),this._boxSelect=new is(this),this._lassoSelect=new rs(this),this._handlers.register(this._clickSelect),this._handlers.register(this._boxSelect),this._handlers.register(this._lassoSelect),this._vertexEdit=new ls(this),this._handlers.register(this._vertexEdit),this._drawFeature=new us(this),this._handlers.register(this._drawFeature),this._transformFeature=new _s(this),this._handlers.register(this._transformFeature),this._handlers.attach(this._canvasContainer),!1===t.interactive&&this._handlers.applyInteractive(!1),this._featureQuery=new As(this._sources,()=>this._viewport.transform,()=>({width:this._viewport.width,height:this._viewport.height}),()=>this._viewport.initialMX),this.features=new Es(this);const e=this;this._featureEvents=new bs({queryFeatures:(t,i)=>e.queryFeatures(t,i),unproject:(t,i)=>e.unproject(t,i),get features(){return e.features}}),this._pointerEvents=new Cs({unproject:(t,i)=>e.unproject(t,i)}),this._featureEvents.setOnChange(()=>this._syncPointerSink()),this._pointerEvents.setOnChange(()=>this._syncPointerSink()),this._attachEventListeners(),this.on("move",()=>this._scheduleRender()),this.on("resize",()=>this._scheduleRender()),this.on("reset",()=>this.reset()),this.on("historychange",()=>this._runAfterCommitValidators()),this._expressionPolicy=t.expressionPolicy??"disabled",this._workerMode=t.useWorker??t.workerMode??!1,"number"==typeof t.workerThreshold&&t.workerThreshold>=0&&(this._workerThreshold=t.workerThreshold),this._workerRouting=t.workerRouting,(!1!==this._workerMode||t.workerPool)&&(t.workerPool?this._workerPool=t.workerPool:this._workerPool=new ys({workerUrl:t.workerUrl??"emap-worker.js",poolSize:t.workerPoolSize}))}cancelWorkerJobs(){this._workerPool?.cancelAll()}setExpressionPolicy(t){this._expressionPolicy=t}getExpressionPolicy(){return this._expressionPolicy??"disabled"}_allowExpressionEvaluation(t,e){return!t.some(t=>"string"==typeof t&&t.trim().length>0)||"trusted"===this.getExpressionPolicy()||(this.fire("error",{error:new Error(`${e}: expression evaluation is disabled`)}),!1)}on(t,e,i){if("mousemove"===t)return this._pointerEvents.on(t,e),this;if(t.startsWith("feature:")){const s=i??e,n=i?e:void 0;return this._featureEvents.on(t,n,s),this}return super.on(t,e)}off(t,e){return"mousemove"===t?(this._pointerEvents.off(t,e),this):t.startsWith("feature:")?(this._featureEvents.off(t,e),this):super.off(t,e)}once(t,e,i){if("mousemove"===t)return this._pointerEvents.once(t,e),this;if(t.startsWith("feature:")){const s=i??e,n=i?e:void 0;return this._featureEvents.once(t,n,s),this}return super.once(t,e)}_syncPointerSink(){this._featureEvents.hasListeners()||this._pointerEvents.hasListeners()?this._handlers.setPointerSink(t=>{this._featureEvents.dispatch(t),this._pointerEvents.dispatch(t)}):this._handlers.setPointerSink(null)}getCanvasContainer(){return this._canvasContainer}getEditMode(){return this._editState.mode}setEditMode(t){this._editState.setMode(t)}setEditVertexState(t){this._editState.setVertex(t)}clearEditVertexState(){this._editState.clearVertex()}setEditDrawState(t){this._editState.setDraw(t)}clearEditDrawState(){this._editState.clearDraw()}_attachEventListeners(){this._dragPan.on("pan",t=>{this._viewport.pan(t.dx,t.dy),this.fire("move")}),this._dragPan.on("panstart",()=>{this._viewport.cancelZoomAnimation()}),this._scrollZoom.on("mousewheel",t=>{this._viewport.applyWheelZoom(t.direction,t.multiplier,t.x,t.y),this.fire("move")})}_createCanvasContainer(){const t=document.createElement("div");t.style.position="relative",t.style.width="100%",t.style.height="100%",t.style.overflow="hidden",t.className="emap-canvas-container";const e=["top-left","top-right","bottom-left","bottom-right"];for(const i of e){const e=document.createElement("div");e.className=`emap-ctrl-${i}`,e.style.position="absolute",e.style.pointerEvents="none",e.style.zIndex="10";const[s,n]=i.split("-");e.style[s]="10px",e.style[n]="10px",e.style.display="flex",e.style.flexDirection="column",e.style.gap="8px";const r=t=>t.stopPropagation();for(const t of["click","mousedown","mouseup","dblclick","contextmenu"])e.addEventListener(t,r);e.addEventListener("wheel",r,{passive:!0}),t.appendChild(e),this._controlContainers.set(i,e)}return t}_updateSize(){const t=this._container.clientWidth,e=this._container.clientHeight;this._viewport.updateSize(t,e),this._painter.resize(t,e)}addSource(t,e){this._sources.set(t,e);const i=i=>{if(1===this._sources.size&&e.getCRS){const t=e.getCRS();t&&this._projection.crs!==t&&(this._projection.setCRS(t),this._viewport.setCRS(t),this.fire("crschange"))}this.fire("data",{sourceId:t,...i}),this._defaultLayersDirty=!0,this._layerArcFlagsCache.clear(),this._scheduleRender()};this._sourceListeners.set(t,i),e.on("data",i),e.getDataset&&e.getDataset()&&i({type:"data"})}removeSource(t){const e=this._sources.get(t);if(e){const i=this._sourceListeners.get(t);i&&(e.off("data",i),this._sourceListeners.delete(t)),this._sources.delete(t),this._defaultLayersDirty=!0,this._layerArcFlagsCache.delete(t);for(const e of this._layerArcFlagsCache.keys())e.startsWith(`${t}:`)&&this._layerArcFlagsCache.delete(e);this._scheduleRender()}}getSource(t){return this._sources.get(t)}async exportSnapshot(t={}){const e=!1!==t.compact,i=[],s=[];for(const[t,e]of this._sources){if("topology"!==e.type)continue;const n=e.getDataset?.();n&&(i.push(t),s.push(n))}const n=tt(),r=await n.exportDatasetsToPack(s,{compact:e});r.emap={version:1,sources:i.map(t=>({id:t}))};const a=n.pack(r);return new Blob([a],{type:"application/octet-stream"})}async loadSnapshot(t,e={}){const i=!1!==e.replace,s=e.idPrefix??"",n=e.defaultIds??[];let r;if(t instanceof Uint8Array)r=t;else if(t instanceof ArrayBuffer)r=new Uint8Array(t);else{if(!("undefined"!=typeof Blob&&t instanceof Blob))throw new Error("loadSnapshot: input must be Blob, Uint8Array, or ArrayBuffer");r=new Uint8Array(await t.arrayBuffer())}if(!function(t){if(!t||0===t.length)return!1;const e=t[0];return e>=128&&e<=143||222===e||223===e}(r))throw new Error("loadSnapshot: input does not look like a mapshaper .msx snapshot (expected msgpack map marker as the first byte)");const a=await tt().unpackSessionData(r),o=a.datasets??[],h=a.emap,l=h?.sources?.map(t=>t?.id).filter(t=>"string"==typeof t)??[],c=o.map((t,e)=>{const i=l[e],r=n[e]??`snapshot-${e}`;return s+(i??r)});if(!i)for(const t of c)if(this._sources.has(t))throw new Error(`loadSnapshot: source "${t}" already exists (pass { replace: true } to overwrite)`);this._history.clear(),this._fireSelectionChange(this._selection.clear()),this.fire("historychange");const u=[];for(let t=0;t<o.length;t++){const e=c[t];i&&this._sources.has(e)&&this.removeSource(e);const s=new Li(e);s.setDataset(o[t]),this.addSource(e,s),u.push(e)}return u}addLayer(t,e){if(!this._sources.has(t.source))throw new Error(`Source "${t.source}" not found`);if(this._layers.some(e=>e.id===t.id))throw new Error(`Layer "${t.id}" already exists`);if(e){const i=this._layers.findIndex(t=>t.id===e);if(-1===i)throw new Error(`Layer "${e}" not found`);this._layers.splice(i,0,{...t})}else this._layers.push({...t});this._defaultLayersDirty=!0,this._scheduleRender()}removeLayer(t){const e=this._layers.findIndex(e=>e.id===t);-1!==e&&(this._layers.splice(e,1),this._defaultLayersDirty=!0,this._scheduleRender())}getLayer(t){return this._layers.find(e=>e.id===t)}getLayers(){return[...this._layers]}setLayerVisibility(t,e){const i=this._layers.find(e=>e.id===t);i&&(i.layout||(i.layout={}),i.layout.visibility=e,this._scheduleRender())}setPaintProperty(t,e,i){const s=this._layers.find(e=>e.id===t);s&&(s.paint||(s.paint={}),s.paint[e]=i,this._scheduleRender())}moveLayer(t,e){const i=this._layers.findIndex(e=>e.id===t);if(-1===i)return;const[s]=this._layers.splice(i,1);if(e){const t=this._layers.findIndex(t=>t.id===e);-1===t?this._layers.push(s):this._layers.splice(t,0,s)}else this._layers.push(s);this._defaultLayersDirty=!0,this._scheduleRender()}_getEffectiveLayers(){if(this._layers.length>0)return this._layers;if(!this._defaultLayersDirty)return this._effectiveLayersCache;const t=[];for(const[e,i]of this._sources){const s=i.getLayers();if(0===s.length)t.push({id:`${e}:default`,type:"line",source:e,paint:{"line-color":"#333","line-width":.8}});else for(let i=0;i<s.length;i++){const n=s[i],r=rt(n,i),a=n.geometry_type;t.push({id:`${e}:${r}`,type:"point"===a?"circle":"line",source:e,"source-layer":r,paint:"point"===a?{"circle-color":"#333","circle-radius":4}:{"line-color":"#333","line-width":.8}})}}return this._effectiveLayersCache=t,this._defaultLayersDirty=!1,t}_resolveSourceLayer(t,e){const i=t.getLayers();if(!i.length)return null;if(!e)return i[0];for(let t=0;t<i.length;t++){if(rt(i[t],t)===e)return i[t]}return null}_getLayerArcFlags(t,e,i){if(!t||!t.shapes||!e)return null;let s=this._layerArcFlagsCache.get(i);if(s)return s;const n=e.size();s=new Uint8Array(n);const r=t.shapes;for(const t of r)if(t)for(const e of t)for(const t of e){s[t>=0?t:~t]=1}return this._layerArcFlagsCache.set(i,s),s}_getVisibleLayerKeys(){const t=new Set,e=this._getEffectiveLayers();for(const i of e){if("none"===i.layout?.visibility)continue;const e=this._sources.get(i.source);if(!e)continue;const s=this._resolveSourceLayer(e,i["source-layer"]);if(s){const n=e.getLayers().indexOf(s),r=rt(s,n>=0?n:0);t.add(`${i.source}:${r}`)}}return t}getPainter(){return this._painter}getCRS(){return this._projection.crs}setCRS(t){this._projection.setCRS(t),this._viewport.setCRS(t),this.fire("crschange")}async reproject(t){if(this._projection.crs===t)return;const e=await this._projection.reproject(t,this._sources);this._viewport.setCRS(t),this._viewport.clearInitialState(),e.hasBounds()&&this.setExtent(e),this.fire("crschange"),this.fire("data",{reason:"reproject"})}getCenter(){const t=this._viewport.transform,e=(this._viewport.width/2-t.bx)/t.mx,i=(this._viewport.height/2-t.by)/t.my;return this._projection.getCenter(e,i)}getZoom(){return this._projection.getZoom(Math.abs(this._viewport.transform.mx))}get dragPan(){return this._dragPan}get scrollZoom(){return this._scrollZoom}get clickSelect(){return this._clickSelect}get boxSelect(){return this._boxSelect}get lassoSelect(){return this._lassoSelect}get vertexEdit(){return this._vertexEdit}get drawFeature(){return this._drawFeature}get transformFeature(){return this._transformFeature}getTransform(){return this._viewport.transform}getExtent(){return this._viewport.extent}setExtent(t){this._viewport.setExtent(t),this.fire("move")}reset(){this._viewport.reset()}addControl(t,e="top-left"){const i=t.onAdd(this);i.style.pointerEvents="auto",this._controlContainers.get(e)?.appendChild(i),this._controls.push(t)}removeControl(t){t.onRemove(this);const e=this._controls.indexOf(t);-1!==e&&this._controls.splice(e,1)}zoomIn(){this._viewport.zoomIn()}zoomOut(){this._viewport.zoomOut()}jumpTo(t){return this._camera.jumpTo(t),this}setCenter(t){return this._camera.setCenter(t),this}setZoom(t){return this._camera.setZoom(t),this}easeTo(t){return this._camera.easeTo(t),this}panTo(t,e={}){return this._camera.panTo(t,e),this}panBy(t,e={}){return this._camera.panBy(t,e),this}zoomTo(t,e={}){return this._camera.zoomTo(t,e),this}flyTo(t){return this._camera.flyTo(t),this}fitBounds(t,e={}){return this._camera.fitBounds(t,e),this}stop(){return this._camera.stop(),this}_scheduleRender(){this._removed||(this._pendingRender++,0===this._rafId&&(this._rafId=requestAnimationFrame(()=>this._doRender())))}_doRender(){this._rafId=0,this._pendingRender>0&&(this._pendingRender=0,this.render())}render(){const t=this._viewport.transform;this._painter.setTransform(t),this._painter.clear();const e=this._viewport.getLineScale(),i=1/Math.abs(t.mx);this._renderLayers(i,e),this._renderHighlight(t,e),this._editOverlay.render(this._editState.mode,this._editState.vertex,this._editState.draw)}_renderLayers(t,e){const i=this._getEffectiveLayers();for(const s of i){if("none"===s.layout?.visibility)continue;const i=this._sources.get(s.source);if(!i)continue;const n=i.getDisplayArcs(),r=n?n.getScaledArcs(t):i.getArcs();if(r&&r.setRetainedInterval&&("function"!=typeof r.isFlat||!r.isFlat())){const e=i.getSimplifyFloor?.()??0;r.setRetainedInterval(Math.max(e,.5*t))}const a=this._resolveSourceLayer(i,s["source-layer"]),o=`${s.source}:${s["source-layer"]||"default"}`;if("line"===s.type&&r)this._renderLineLayer(s,a,r,o,e);else if("fill"===s.type&&r&&a?.shapes)this._renderFillLayer(s,a,r,o,e);else if("circle"===s.type&&a?.shapes){const t=zs(s.paint);this._painter.drawPoints(a.shapes,t)}}}_renderLineLayer(t,e,i,s,n){const r=Gs(t.paint,n);if(e?.shapes){const t=this._getLayerArcFlags(e,i,s),n=this._combineArcFilters(t,this._viewport.getArcFilter(i));this._painter.drawArcs(i,r,n)}else this._painter.drawArcs(i,r,this._viewport.getArcFilter(i))}_renderFillLayer(t,e,i,s,n){const r=t.paint,a=r?.["fill-color"]||"rgba(200, 200, 200, 0.4)",o=r?.["fill-opacity"],h=this._viewport.getArcFilter(i);this._painter.drawPolygonFill(e.shapes,i,a,h,o);const l=Gs(t.paint,n),c=this._getLayerArcFlags(e,i,s);this._painter.drawArcs(i,l,this._combineArcFilters(c,h))}_combineArcFilters(t,e){return t&&e?i=>1===t[i]&&e(i):t?e=>1===t[e]:e}_renderHighlight(t,e){const i=this._getVisibleLayerKeys();this._highlightManager.renderHighlights(this._painter,this._sources,t,e,i)}project(t,e){return this._viewport.project(t,e)}unproject(t,e){return this._viewport.unproject(t,e)}resize(){this._updateSize(),this._viewport.setExtent(this._viewport.extent),this.fire("resize")}queryFeatures(t,e){const i=this._getVisibleLayerKeys();return this._featureQuery.query(t,e,i)}prebuildSpatialIndex(t){this._featureQuery.prebuild(t)}clearSpatialIndex(t){this._featureQuery.clear(t)}_clearSpatialIndexesForSources(t){for(const e of t)this._featureQuery?.clear(e)}setHighlightedFeatures(t,e){this._highlightManager.setHighlightedFeatures(t,e),this._scheduleRender()}clearHighlightedFeatures(){this._highlightManager.clearHighlightedFeatures()&&this._scheduleRender()}setHighlightStyle(t){this._highlightManager.setHighlightStyle(t)&&this._scheduleRender()}select(t,e){const i=e?.mode??"replace",s=this._selection.apply(t,i);this._fireSelectionChange(s)}deselect(t){const e=this._selection.remove(t);this._fireSelectionChange(e)}clearSelection(){const t=this._selection.clear();this._fireSelectionChange(t)}getSelection(){return this._selection.getAll()}isSelected(t){return this._selection.has(t)}_fireSelectionChange(t){t.changed&&(this.fire("selectionchange",{selected:this._selection.getAll(),added:t.added,removed:t.removed}),this._handlers?.refreshCursor())}deleteSelected(){const t=this._selection.getAll();if(0===t.length)return!1;const e=new globalThis.Map;for(const i of t){let t=e.get(i.source);t||(t=new globalThis.Map,e.set(i.source,t));const s=t.get(i.layer)??[];s.push(i.id),t.set(i.layer,s)}const i=[];let s=0;for(const[t,n]of e){const e=this._sources.get(t);if(!e)continue;const r=e.getLayers();for(const[t,e]of n){let n=null;for(let e=0;e<r.length;e++)if(rt(r[e],e)===t){n=r[e];break}if(!n?.shapes)continue;const a=n.data?.getRecords?.(),o=[],h=new Set;for(const t of e){if(h.has(t))continue;h.add(t);const e=n.shapes[t];if(void 0===e)continue;const i=a?a[t]:null;o.push({id:t,shape:e,record:i??null})}if(0===o.length)continue;const l=new Os({layer:n,snapshots:o});l.do(),i.push(l),s+=o.length}}if(0===i.length)return!1;const n=new Rt(i,`Delete ${s} feature${s>1?"s":""}`);return this._history.push(n),this._fireHistoryChange(),this._invalidateShapeCachesForSources(e.keys()),this._fireSelectionChange(this._selection.clear()),this._scheduleRender(),!0}_invalidateShapeCachesForSources(t){for(const e of t){const t=`${e}:`;for(const e of this._layerArcFlagsCache.keys())e.startsWith(t)&&this._layerArcFlagsCache.delete(e);this._featureQuery?.clear(e)}}pushCommand(t){this._history.push(t),this._fireHistoryChange()}undo(){return!!this._history.undo()&&(this._fireHistoryChange(),this._invalidateAllShapeCaches(),this._scheduleRender(),!0)}redo(){return!!this._history.redo()&&(this._fireHistoryChange(),this._invalidateAllShapeCaches(),this._scheduleRender(),!0)}_invalidateAllShapeCaches(){this._layerArcFlagsCache.clear();for(const t of this._sources.keys())this._featureQuery?.clear(t)}canUndo(){return this._history.canUndo()}canRedo(){return this._history.canRedo()}clearHistory(){const t=this._history.canUndo()||this._history.canRedo();this._history.clear(),t&&this._fireHistoryChange()}beginTransaction(){return new Ns(this)}bindHistoryShortcuts(t){this._historyShortcutUnbind?.();const e=t??this._canvasContainer;e.hasAttribute("tabindex")||e.setAttribute("tabindex","-1");const i=t=>{if(!(t.ctrlKey||t.metaKey))return;const e="z"===t.key||"Z"===t.key,i="y"===t.key||"Y"===t.key;e&&!t.shiftKey?(t.preventDefault(),this.undo()):(e&&t.shiftKey||i)&&(t.preventDefault(),this.redo())};e.addEventListener("keydown",i);const s=()=>{e.removeEventListener("keydown",i),this._historyShortcutUnbind===s&&(this._historyShortcutUnbind=null)};return this._historyShortcutUnbind=s,s}_fireHistoryChange(){const t=this._history.snapshot();this.fire("historychange",t)}_runAfterCommitValidators(){if(0===this._validators.size)return;const t={label:this._history.snapshot().label??""};this._validators.runFor("after-commit",this,t).then(e=>{if(this._removed)return;const i=e.filter(t=>!t.report.ok);i.length>0&&this.fire("validationfailed",{results:i,label:t.label})})}_resolveLayer(t,e){return this.layers.resolve(t,e)}remove(){if(this._removed)return;this._removed=!0,0!==this._rafId&&(cancelAnimationFrame(this._rafId),this._rafId=0),this._pendingRender=0,this._handlers?.detach(),this._scrollZoom?.destroy(),this._historyShortcutUnbind?.(),this._historyShortcutUnbind=null,this._workerPool&&(this._workerPool.cancelAll(),this._workerPool.destroy(),this._workerPool=null);for(const[t,e]of this._sourceListeners){const i=this._sources.get(t);i?.off("data",e)}this._sourceListeners.clear();for(const t of this._sources.keys())this._featureQuery?.clear(t);this._layerArcFlagsCache.clear(),this._sources.clear();const t=this._controls??[];for(const e of[...t])try{e.onRemove(this)}catch(t){this.fire("error",{error:t})}t.length=0,this._controlContainers?.clear(),this._editState?.setMode("none"),this._container&&this._canvasContainer&&this._container.removeChild(this._canvasContainer)}_removed=!1}function js(t){return`"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/\0/g,"\\0")}"`}const Bs=/^[A-Za-z0-9_\-:.一-鿿][A-Za-z0-9_\-:. 一-鿿]*$/,Us=/^[A-Za-z0-9_\-.一-鿿][A-Za-z0-9_\-. 一-鿿]*$/;function $s(t){return"string"==typeof t&&t.length>0&&Bs.test(t)}function Vs(t){return"string"==typeof t&&t.length>0&&Us.test(t)}function Ws(t){for(const e of t)if(!Vs(e))return"string"==typeof e?e:String(e);return null}function Hs(t={}){const e=t.severity??"error";return{name:"topology",phase:"after-commit",async run(i){const s=tt(),n=t.sources??Array.from(i._sources.keys()),r=[];for(const a of n){const n=i._sources.get(a)?.getDataset();if(!n||!n.arcs)continue;const o={};void 0!==t.tolerance&&(o.tolerance=t.tolerance);const h=s.findSegmentIntersections(n.arcs,o);h.length>0&&r.push({severity:e,message:`${a}: ${h.length} self-intersection${1===h.length?"":"s"}`})}return{ok:0===r.length,issues:r}}}}class Ks{_map=null;_container=null;_options;constructor(t={}){this._options={showZoom:!0,showHome:!0,...t}}onAdd(t){return this._map=t,this._container=document.createElement("div"),this._container.className=`emap-ctrl emap-ctrl-group ${this._options.className||""}`,this._options.showZoom&&(this._createButton("zoom-in","+","Zoom In",()=>{this._map?.zoomIn()}),this._createButton("zoom-out","-","Zoom Out",()=>{this._map?.zoomOut()})),this._options.showHome&&this._createButton("home","⌂","Reset View",()=>{this._map?.fire("reset")}),this._container}_createButton(t,e,i,s){const n=document.createElement("button");n.className=`emap-ctrl-${t}`,n.type="button",n.title=i;const r=document.createElement("span");r.className="emap-ctrl-icon",r.textContent=e,n.appendChild(r),n.addEventListener("click",s),this._container?.appendChild(n)}onRemove(){this._container&&this._container.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._container=null}}class Zs{_map=null;_container=null;_options;_mousePosEl=null;_epsgEl=null;_onMoveBound;_onUpdateEPSGBound;_rafPending=!1;constructor(t={}){this._options={showMousePos:!0,showEPSG:!0,alignment:"left",...t},this._onMoveBound=this._onMove.bind(this),this._onUpdateEPSGBound=this._updateEPSG.bind(this)}onAdd(t){return this._map=t,this._container=document.createElement("div"),this._container.className=`emap-ctrl emap-status-ctrl emap-align-${this._options.alignment} ${this._options.className||""}`,this._options.showMousePos&&(this._mousePosEl=document.createElement("span"),this._mousePosEl.className="emap-status-mousepos",this._container.appendChild(this._mousePosEl)),this._options.showEPSG&&(this._epsgEl=document.createElement("span"),this._epsgEl.className="emap-status-epsg",this._container.appendChild(this._epsgEl),this._updateEPSG()),this._map.on("crschange",this._onUpdateEPSGBound),this._options.showMousePos&&this._map.on("mousemove",this._onMoveBound),this._container}_onMove(t){if(!this._map||!this._mousePosEl||!this._options.showMousePos)return;if(this._rafPending)return;this._rafPending=!0;const[e,i]=t.mapCoord;requestAnimationFrame(()=>{this._rafPending=!1,this._map&&this._mousePosEl&&(this._mousePosEl.textContent=` ${e.toFixed(4)}, ${i.toFixed(4)}`)})}_updateEPSG(){if(!this._map||!this._epsgEl)return;const t=this._map.getCRS();this._epsgEl.textContent=` | ${t}`}onRemove(){this._map&&(this._options.showMousePos&&this._map.off("mousemove",this._onMoveBound),this._map.off("crschange",this._onUpdateEPSGBound)),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._container=null}}const Xs=[{name:"OSM",url:"https://tile.openstreetmap.org/{z}/{x}/{y}.png",type:"raster"},{name:"CartoDB Light",url:"https://basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png",type:"raster"},{name:"CartoDB Dark",url:"https://basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png",type:"raster"}];class Js{_map=null;_container=null;_basemapContainer=null;_maplibre=null;_maplibreMap=null;_styles;_activeStyle=null;_isOn=!1;_syncBasemapBound;constructor(t={}){this._styles=t.styles||Xs,this._syncBasemapBound=this._syncBasemap.bind(this)}onAdd(t){return this._map=t,this._container=document.createElement("div"),this._container.className="emap-ctrl emap-basemap-ctrl",this._styles.forEach(t=>{const e=document.createElement("button");e.className="emap-basemap-btn",e.textContent=t.name,e.onclick=()=>this._toggleStyle(t),this._container.appendChild(e)}),this._createBasemapLayer(),this._map.on("move",this._syncBasemapBound),this._container}_createBasemapLayer(){if(!this._map)return;const t=this._map.getCanvasContainer();this._basemapContainer=document.createElement("div"),this._basemapContainer.className="emap-basemap",this._basemapContainer.style.cssText="\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n z-index: 0;\n display: none;\n ",t.insertBefore(this._basemapContainer,t.firstChild)}_toggleStyle(t){this._activeStyle===t?this._turnOff():this._showBasemap(t),this._updateButtons()}async _showBasemap(t){if(this._activeStyle=t,this._isOn=!0,!this._basemapContainer||!this._map)return;this._basemapContainer.style.display="block";const e=(this._map.getCRS()||"").toLowerCase();"webmercator"!==e&&"epsg:3857"!==e&&this._map.reproject&&await this._map.reproject("webmercator"),this._maplibreMap?(this._maplibreMap.resize(),this._setStyle(t),this._syncBasemap()):await this._initMapLibre(t)}async _initMapLibre(t){if(!this._basemapContainer||!this._map)return;const e=await this._loadMapLibre(),i=this._createMapLibreStyle(t);this._maplibreMap=new e.Map({container:this._basemapContainer,style:i,center:this._map.getCenter(),zoom:this._map.getZoom(),interactive:!1,attributionControl:!1,maxPitch:0,renderWorldCopies:!0}),this._maplibreMap.on("load",()=>{this._syncBasemap()})}async _loadMapLibre(){return this._maplibre||(this._maplibre=await import("maplibre-gl")),this._maplibre}_setStyle(t){if(!this._maplibreMap)return;const e=this._createMapLibreStyle(t);this._maplibreMap.setStyle(e)}_createMapLibreStyle(t){return"raster"===t.type||t.url.includes("{z}")?{version:8,sources:{"basemap-tiles":{type:"raster",tiles:[t.url],tileSize:512}},layers:[{id:"basemap-layer",type:"raster",source:"basemap-tiles",minzoom:0,maxzoom:22}]}:t.url}_syncBasemap(){if(this._maplibreMap&&this._map&&this._isOn)try{this._maplibreMap.jumpTo({center:this._map.getCenter(),zoom:this._map.getZoom()})}catch(t){console.warn("Sync basemap failed:",t)}}_turnOff(){this._activeStyle=null,this._isOn=!1,this._basemapContainer&&(this._basemapContainer.style.display="none")}_updateButtons(){if(!this._container)return;this._container.querySelectorAll(".emap-basemap-btn").forEach((t,e)=>{const i=this._styles[e]===this._activeStyle;t.classList.toggle("active",i)})}isOn(){return this._isOn}onRemove(){this._map&&this._map.off("move",this._syncBasemapBound),this._maplibreMap&&(this._maplibreMap.remove(),this._maplibreMap=null),this._basemapContainer?.parentNode&&this._basemapContainer.parentNode.removeChild(this._basemapContainer),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null}}class Ys{_map=null;_container=null;_btn=null;_opts;constructor(t={}){this._opts=t}onAdd(t){return this._map=t,void 0!==this._opts.polygonFillColor&&t.vertexEdit.setOptions({polygonFillColor:this._opts.polygonFillColor}),this._container=document.createElement("div"),this._container.className="emap-ctrl emap-ctrl-group",this._btn=document.createElement("button"),this._btn.className="emap-ctrl-edit",this._btn.type="button",this._btn.title="Edit Vertices",this._btn.innerHTML='<span class="emap-ctrl-icon">✏</span>',this._btn.addEventListener("click",()=>this._toggle()),this._container.appendChild(this._btn),this._container}onRemove(){this._map&&this._map.vertexEdit.isEnabled()&&this._map.vertexEdit.disable(),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._container=null,this._btn=null}_toggle(){if(!this._map)return;const t=this._map.vertexEdit;t.isEnabled()?(t.disable(),this._btn?.classList.remove("active")):(t.enable(),this._btn?.classList.add("active"))}}const Qs={polygon:"▢",polyline:"╱",point:"●"},tn={polygon:"Draw Polygon",polyline:"Draw Polyline",point:"Draw Point"};class en{_opts;_map=null;_container=null;_btn=null;constructor(t){this._opts=t}onAdd(t){this._map=t,this._container=document.createElement("div"),this._container.className="emap-ctrl emap-ctrl-group",this._btn=document.createElement("button"),this._btn.className="emap-ctrl-draw",this._btn.type="button",this._btn.title=tn[this._opts.type];const e=document.createElement("span");e.className="emap-ctrl-icon";const i=this._opts.icon??Qs[this._opts.type];"string"==typeof i?e.textContent=i:e.appendChild(i),this._btn.replaceChildren(e),this._btn.addEventListener("click",()=>this._toggle()),this._container.appendChild(this._btn);const{icon:s,...n}=this._opts;return t.drawFeature.setOptions(n),t.on("editmodechange",t=>{"draw"!==t.mode&&this._btn?.classList.remove("active")}),this._container}onRemove(){this._map&&this._map.drawFeature.isEnabled()&&this._map.drawFeature.disable(),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._container=null,this._btn=null}_toggle(){if(!this._map)return;const t=this._map.drawFeature;t.isEnabled()?(t.disable(),this._btn?.classList.remove("active")):(t.enable(),this._btn?.classList.add("active"))}}class sn{_container=null;_vertexEditControl;_drawControls=[];_options;constructor(t){this._options=t||{},this._vertexEditControl=new Ys,this._options.drawSource&&(this._drawControls=[new en({source:this._options.drawSource,sourceLayer:this._options.drawSourceLayer,type:"polygon"}),new en({source:this._options.drawSource,sourceLayer:this._options.drawSourceLayer,type:"polyline"}),new en({source:this._options.drawSource,sourceLayer:this._options.drawSourceLayer,type:"point"})])}onAdd(t){const e=this._vertexEditControl.onAdd(t);this._container=document.createElement("div"),this._container.className="emap-ctrl emap-ctrl-group emap-edit-toolbar";const i=e.querySelector("button");i&&this._container.appendChild(i);for(const e of this._drawControls){const i=e.onAdd(t).querySelector("button");i&&this._container.appendChild(i)}return this._container}onRemove(){this._vertexEditControl.onRemove();for(const t of this._drawControls)t.onRemove();this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._container=null}}class nn{_map=null;_container=null;_undoBtn=null;_redoBtn=null;_options;_onHistoryChange=null;constructor(t={}){this._options=t}onAdd(t){return this._map=t,this._container=document.createElement("div"),this._container.className=`emap-ctrl emap-ctrl-group ${this._options.className||""}`.trim(),this._undoBtn=this._createButton("undo","↶",this._options.undoTitle??"Undo (Ctrl+Z)",()=>{this._map?.undo()}),this._redoBtn=this._createButton("redo","↷",this._options.redoTitle??"Redo (Ctrl+Shift+Z)",()=>{this._map?.redo()}),this._setEnabled(t.canUndo(),t.canRedo()),this._onHistoryChange=t=>this._setEnabled(t.canUndo,t.canRedo),t.on("historychange",this._onHistoryChange),this._container}onRemove(){this._map&&this._onHistoryChange&&this._map.off("historychange",this._onHistoryChange),this._onHistoryChange=null,this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._container=null,this._undoBtn=null,this._redoBtn=null}_setEnabled(t,e){this._undoBtn&&(this._undoBtn.disabled=!t),this._redoBtn&&(this._redoBtn.disabled=!e)}_createButton(t,e,i,s){const n=document.createElement("button");n.className=`emap-ctrl-${t}`,n.type="button",n.title=i,n.disabled=!0;const r=document.createElement("span");return r.className="emap-ctrl-icon",r.textContent=e,n.appendChild(r),n.addEventListener("click",s),this._container?.appendChild(n),n}}class rn{_options;_enabled=!0;_handler=null;_container=null;constructor(t={}){this._options=t}onAdd(t){this._handler=t.boxSelect,this._handler.setOptions({layers:this._options.layers,dragThreshold:this._options.dragThreshold,dragActivator:this._options.dragActivator,style:this._options.style}),this._enabled&&this._handler.enable();const e=document.createElement("div");return e.className="emap-ctrl emap-box-select-anchor",e.style.width="0",e.style.height="0",e.style.pointerEvents="none",this._container=e,e}onRemove(){this._handler?.disable(),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._handler=null,this._container=null}disable(){this._enabled=!1,this._handler?.disable()}enable(){this._enabled=!0,this._handler?.enable()}isEnabled(){return this._handler?this._handler.isEnabled():this._enabled}}class an{_options;_enabled=!0;_handler=null;_container=null;constructor(t={}){this._options=t}onAdd(t){this._handler=t.lassoSelect,this._handler.setOptions({layers:this._options.layers,dragThreshold:this._options.dragThreshold,includeIntersecting:this._options.includeIntersecting,style:this._options.style}),this._enabled&&this._handler.enable();const e=document.createElement("div");return e.className="emap-ctrl emap-lasso-select-anchor",e.style.width="0",e.style.height="0",e.style.pointerEvents="none",this._container=e,e}onRemove(){this._handler?.disable(),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._handler=null,this._container=null}disable(){this._enabled=!1,this._handler?.disable()}enable(){this._enabled=!0,this._handler?.enable()}isEnabled(){return this._handler?this._handler.isEnabled():this._enabled}}const on=[{value:"",label:"weighted (default)"},{value:"weighted",label:"weighted"},{value:"visvalingam",label:"visvalingam"},{value:"dp",label:"dp (Douglas–Peucker)"}];class hn{_opts;_map=null;_container=null;_btn=null;_popup=null;_percentageInput=null;_percentageLabel=null;_methodSel=null;_keepShapes=null;_planar=null;_applyBtn=null;_statusEl=null;_onDocClick=null;_onDocKey=null;constructor(t){this._opts=t}onAdd(t){return this._map=t,this._container=document.createElement("div"),this._container.className="emap-ctrl emap-ctrl-group emap-ctrl-simplify-wrap",this._btn=document.createElement("button"),this._btn.type="button",this._btn.className="emap-ctrl-simplify",this._btn.innerHTML='<span class="emap-ctrl-icon">≈</span>',this._btn.title=this._opts.title??"Simplify geometry",this._btn.onclick=t=>{t.stopPropagation(),this._togglePopup()},this._container.appendChild(this._btn),this._popup=this._buildPopup(),this._container.appendChild(this._popup),this._container}onRemove(){this._teardownDocListeners(),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._container=null,this._btn=null,this._popup=null,this._percentageInput=null,this._percentageLabel=null,this._methodSel=null,this._keepShapes=null,this._planar=null,this._applyBtn=null,this._statusEl=null,this._map=null}_buildPopup(){const t=document.createElement("div");t.className="emap-simplify-popup",t.style.display="none",t.style.cssText+="\n position:absolute; top:36px; left:0; min-width:240px; padding:10px;\n background:#fff; border:1px solid #ccc; border-radius:4px;\n box-shadow:0 2px 8px rgba(0,0,0,.15); font-size:13px;\n z-index:10; color:#222;",t.onclick=t=>t.stopPropagation();const e=this._opts.initialPercentage??10,i=this._opts.initialMethod??"";return t.innerHTML=`\n <div style="margin-bottom:8px;">\n <label style="display:flex; align-items:center; gap:6px;">\n <span>Percentage:</span>\n <input type="range" min="0" max="100" step="0.1" value="${e}" style="flex:1;" />\n <span class="value" style="min-width:48px; text-align:right;">${e}%</span>\n </label>\n </div>\n <div style="margin-bottom:8px;">\n <label style="display:flex; align-items:center; gap:6px;">\n <span>Method:</span>\n <select style="flex:1;">\n ${on.map(t=>`<option value="${t.value}"${t.value===i?" selected":""}>${t.label}</option>`).join("")}\n </select>\n </label>\n </div>\n <div style="margin-bottom:8px; display:flex; gap:12px; flex-wrap:wrap;">\n <label><input type="checkbox" data-flag="keep-shapes" checked /> keep-shapes</label>\n <label><input type="checkbox" data-flag="planar" /> planar</label>\n </div>\n <div style="display:flex; gap:6px; align-items:center;">\n <button type="button" class="apply" style="padding:4px 12px;">Apply</button>\n <span class="status" style="opacity:.8; font-size:12px;"></span>\n </div>\n `,this._percentageInput=t.querySelector("input[type=range]"),this._percentageLabel=t.querySelector(".value"),this._methodSel=t.querySelector("select"),this._keepShapes=t.querySelector("input[data-flag=keep-shapes]"),this._planar=t.querySelector("input[data-flag=planar]"),this._applyBtn=t.querySelector("button.apply"),this._statusEl=t.querySelector(".status"),this._percentageInput.oninput=()=>{this._percentageLabel&&this._percentageInput&&(this._percentageLabel.textContent=`${this._percentageInput.value}%`)},this._applyBtn.onclick=()=>this._apply(),t}_togglePopup(){if(!this._popup)return;const t="none"===this._popup.style.display;this._popup.style.display=t?"block":"none",this._btn?.classList.toggle("active",t),t?(this._setupDocListeners(),this._setStatus("")):this._teardownDocListeners()}_setupDocListeners(){this._onDocClick=t=>{this._container&&!this._container.contains(t.target)&&this._togglePopup()},this._onDocKey=t=>{"Escape"===t.key&&this._togglePopup()},document.addEventListener("mousedown",this._onDocClick),document.addEventListener("keydown",this._onDocKey)}_teardownDocListeners(){this._onDocClick&&document.removeEventListener("mousedown",this._onDocClick),this._onDocKey&&document.removeEventListener("keydown",this._onDocKey),this._onDocClick=null,this._onDocKey=null}_setStatus(t){this._statusEl&&(this._statusEl.textContent=t)}async _apply(){if(!this._map||!this._percentageInput||!this._methodSel)return;const t=Number(this._percentageInput.value),e=this._methodSel.value,i={source:this._opts.source,percentage:t};this._opts.target&&(i.target=this._opts.target),e&&(i.method=e),this._keepShapes?.checked&&(i.keepShapes=!0),this._planar?.checked&&(i.planar=!0),this._applyBtn&&(this._applyBtn.disabled=!0),this._setStatus("Running…");try{const e=await this._map.ops.simplifyLayer(i);if(e?.ok)this._setStatus(`Simplified at ${t}%`);else{const t=e?.error,i=t?`${t.kind}${t.field?" field="+t.field:""}`:"unknown";this._setStatus(`Failed: ${i}`)}}catch(t){this._setStatus(`Error: ${t?.message??t}`)}finally{this._applyBtn&&(this._applyBtn.disabled=!1)}}}export{$ as AffineTransform,Js as BasemapControl,V as Bounds,rn as BoxSelectControl,is as BoxSelectHandler,Os as BulkFeatureDeleteCommand,ot as CanvasPainter,ts as ClickSelectHandler,Rt as CompositeCommand,Ei as DEFAULT_CRS,lt as DatasetReplaceCommand,Y as DefaultMapshaperAdapter,Gi as DragPanHandler,en as DrawFeatureControl,us as DrawFeatureHandler,Fs as EditHistory,ht as EditOverlayRenderer,sn as EditToolbar,qs as Emap,pt as Err,U as EventDispatcher,Es as FeatureAccessor,jt as FeatureAffineCommand,cs as FeatureCreateCommand,Rs as FeatureDeleteCommand,Yt as FeaturePropertyChangeCommand,As as FeatureQuery,qt as FeatureTranslateCommand,te as FieldAddCommand,ee as FieldRemoveCommand,ie as FieldRenameCommand,ms as HandlerManager,ks as HighlightManager,nn as HistoryControl,Vt as IDENTITY_MATRIX,an as LassoSelectControl,rs as LassoSelectHandler,ys as MapshaperWorkerPool,Ks as NavigationControl,ct as OK,nt as Projection,Ri as ScrollZoomHandler,Is as Selection,hn as SimplifyControl,Ht as SplitSharedArcsCommand,Zs as StatusControl,Li as TopologySource,Ns as Transaction,$ as Transform,_s as TransformFeatureHandler,Ms as ValidatorRegistry,hs as VertexDeleteCommand,Ys as VertexEditControl,ls as VertexEditHandler,os as VertexInsertCommand,as as VertexMoveCommand,Z as Viewport,zt as bumpEditVersion,$t as composeMatrix,Bi as featureMatchesLasso,Ws as findInvalidFieldName,tt as getDefaultMapshaperAdapter,Ii as inferFromPrj,Wt as invertMatrix,ds as isHandler,Ot as isPathLayer,Gt as isPointLayer,Vs as isValidFieldName,$s as isValidLayerName,ki as normalizeCrsString,ut as okValue,Kt as planSharedArcSplit,ji as pointInPolygon,js as quoteCliArg,Mi as resolveDatasetCRS,qi as resolveMode,zs as resolvePointStyle,Gs as resolveStrokeStyle,Bt as rotateMatrix,Ut as scaleMatrix,et as setDefaultMapshaperAdapter,Hs as topologyValidator};
1
+ import t from"./mapshaper-vendor.mjs";function e(t,e){return e.forEach(function(e){e&&"string"!=typeof e&&!Array.isArray(e)&&Object.keys(e).forEach(function(n){if("default"!==n&&!(n in t)){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})}),Object.freeze(t)}var n=Math.abs,r=Math.floor,i=Math.sin,s=Math.cos,a=Math.tan,o=Math.asin,l=Math.acos,h=Math.atan,c=Math.atan2,u=Math.sqrt,p=Math.pow,_=Math.exp,d=Math.log,f=Math.hypot,m=Math.sinh,g=Math.cosh,y=Math.min,v=Math.max,w=1/0,S=Math.PI,x=57.29577951308232,b=.017453292519943295,C=6378137,E=.0066943799901413165,A=S/4,k=S/2,M=1.5*S,I=2*S,T=2/S,D=-45,P=-47,N=1e-10,R={last_errno:0,debug_level:0,logger:null},L=["no arguments in initialization list","no options found in 'init' file","invalid init= string","projection not named","unknown projection id","effective eccentricity = 1","unknown unit conversion id","invalid boolean param argument","unknown elliptical parameter name","reciprocal flattening (1/f) = 0","|radius reference latitude| > 90","squared eccentricity < 0","major axis or radius = 0 or not given","latitude or longitude exceeded limits","invalid x or y","improperly formed DMS value","non-convergent inverse meridional dist","non-convergent inverse phi2","acos/asin: |arg| >1+1e-14","tolerance condition error","conic lat_1 = -lat_2","lat_1 >= 90","lat_1 = 0","lat_ts >= 90","no distance between control points","projection not selected to be rotated","W <= 0 or M <= 0","lsat not in 1-5 range","path not in range","h <= 0","k <= 0","lat_0 = 0 or 90 or alpha = 90","lat_1=lat_2 or lat_1=0 or lat_2=90","elliptical usage required","invalid UTM zone number","arg(s) out of range for Tcheby eval","failed to find projection to be rotated","failed to load datum shift file","both n & m must be spec'd and > 0","n <= 0, n > 1 or not specified","lat_1 or lat_2 not specified","|lat_1| == |lat_2|","lat_0 is pi/2 from mean lat","unparseable coordinate system definition","geocentric transformation missing z or ellps","unknown prime meridian conversion id","illegal axis orientation combination","point not within available datum shift grids","invalid sweep axis, choose x or y","invalid value for h","point outside of projection domain"];function G(){var t=R.last_errno;t&&(t>0||!function(t){return O.indexOf(t)>-1}(t))&&z(t)}var O=[-14,-15,-17,-18,-19,-20,-27,-48];function F(t){R.last_errno=t}function U(){F(-20)}function q(){F(-20)}function j(t){z(t)}function z(t){F(t),B()}function B(t,e){var n;throw e||(e={}),e.code||(e.code=R.last_errno||0),t||(n=e.code,t=L[~n]||"unknown error"),R.last_errno=0,new V(t,e)}function V(t,e){var n=new Error(t);return n.name="ProjError",Object.keys(e).forEach(function(t){n[t]=e[t]}),n}function $(t){return W(t)*b}function W(t){var e=/(-?[0-9.]+)d?([0-9.]*)'?([0-9.]*)"?([nsew]?)$/i.exec(t),n=NaN;return e&&(n=+(e[1]||"0")+ +(e[2]||"0")/60+ +(e[3]||"0")/3600,/[ws]/i.test(e[4])&&(n=-n)),isNaN(n)&&z(-16),n}function H(t){return K(t)}function K(t){return parseFloat(t)}function Z(t,e){var n,r,i=e[0],s=t[e.substr(1)],a=void 0!==s;return"t"==i?n=a:a?(r=s.param,s.used=!0,"i"==i?n=parseInt(r):"d"==i?n=H(r):"r"==i?n=$(r):"s"==i?n=String(r):"b"==i&&("T"==r||"t"==r||!0===r?n=!0:("F"==r||"f"==r||F(-8),n=!1))):n={i:0,b:!1,d:0,r:0,s:""}[i],void 0===n&&B("invalid request to pj_param, fatal"),n}function J(t){for(var e,n=/\+([a-z][a-z0-9_]*(?:=[^\s]*)?)/gi,r={};e=n.exec(t);)X(r,e[1]);return r}function X(t,e){var n,r,i=e.split("=");1==i.length?(n=e,r=!0):(n=i[0],r=e.substr(i[0].length+1)),t[n]={used:!1,param:r}}var Y={};function Q(t,e,n,r){Y[e]={init:t,name:n,description:r}}function tt(t){return!t||t.is_latlong}function et(t){var e=!1,n="";return"datum"in t.params?(e=!0,n+=rt(t,"datum")):"R"in t.params?n+=rt(t,"R"):"ellps"in t.params?n+=rt(t,"ellps"):"a"in t.params?(n+=rt(t,"a"),"b"in t.params?n+=rt(t,"b"):"es"in t.params?n+=rt(t,"es"):"f"in t.params?n+=rt(t,"f"):n+=" +es="+t.es):j(-13),e||(n+=rt(t,"towgs84"),n+=rt(t,"nadgrids")),n+=rt(t,"R_A"),n+=rt(t,"R_V"),n+=rt(t,"R_a"),n+=rt(t,"R_lat_a"),n+=rt(t,"R_lat_g"),n+=rt(t,"pm")}function nt(t){var e="datum,ellps,a,b,es,rf,f,towgs84,nadgrids,R,R_A,R_V,R_a,R_lat_a,R_lat_g,pm,init,no_defs".split(","),n="";return Object.keys(t.params).forEach(function(r){-1==e.indexOf(r)&&(n+=rt(t,r))}),(n+=et(t)).trim()}function rt(t,e){var n="";return e in t.params&&(n=" +"+e,!0!==t.params[e].param&&(n+="="+Z(t.params,"s"+e))),n}var it=[["WGS84","towgs84=0,0,0","WGS84","WGS_1984"],["GGRS87","towgs84=-199.87,74.79,246.62","GRS80","Greek_Geodetic_Reference_System_1987"],["NAD83","towgs84=0,0,0","GRS80","North_American_Datum_1983"],["NAD27","nadgrids=@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat","clrk66","North_American_Datum_1927"],["potsdam","towgs84=598.1,73.7,418.2,0.202,0.045,-2.455,6.7","bessel","Potsdam Rauenberg 1950 DHDN"],["carthage","towgs84=-263.0,6.0,431.0","clrk80ign","Carthage 1934 Tunisia"],["hermannskogel","towgs84=577.326,90.129,463.919,5.137,1.474,5.297,2.4232","bessel","Hermannskogel"],["ire65","towgs84=482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15","mod_airy","Ireland 1965"],["nzgd49","towgs84=59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993","intl","New Zealand Geodetic Datum 1949"],["OSGB36","towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894","airy","OSGB 1936"],[null,null,null,null]],st=[["greenwich","0dE"],["lisbon","9d07'54.862\"W"],["paris","2d20'14.025\"E"],["bogota","74d04'51.3\"W"],["madrid","3d41'16.58\"W"],["rome","12d27'8.4\"E"],["bern","7d26'22.5\"E"],["jakarta","106d48'27.79\"E"],["ferro","17d40'W"],["brussels","4d22'4.71\"E"],["stockholm","18d3'29.8\"E"],["athens","23d42'58.815\"E"],["oslo","10d43'22.5\"E"],[null,null]];function at(t){var e=it.reduce(function(e,n){return n[0]===t?n:e},null);return e?{id:e[0],defn:e[1],ellipse_id:e[2],name:e[3]}:null}var ot=[["MERIT","a=6378137.0","rf=298.257","MERIT 1983"],["SGS85","a=6378136.0","rf=298.257","Soviet Geodetic System 85"],["GRS80","a=6378137.0","rf=298.257222101","GRS 1980(IUGG, 1980)"],["IAU76","a=6378140.0","rf=298.257","IAU 1976"],["airy","a=6377563.396","b=6356256.910","Airy 1830"],["APL4.9","a=6378137.0","rf=298.25","Appl. Physics. 1965"],["NWL9D","a=6378145.0","rf=298.25","Naval Weapons Lab., 1965"],["mod_airy","a=6377340.189","b=6356034.446","Modified Airy"],["andrae","a=6377104.43","rf=300.0","Andrae 1876 (Den., Iclnd.)"],["aust_SA","a=6378160.0","rf=298.25","Australian Natl & S. Amer. 1969"],["GRS67","a=6378160.0","rf=298.2471674270","GRS 67(IUGG 1967)"],["bessel","a=6377397.155","rf=299.1528128","Bessel 1841"],["bess_nam","a=6377483.865","rf=299.1528128","Bessel 1841 (Namibia)"],["clrk66","a=6378206.4","b=6356583.8","Clarke 1866"],["clrk80","a=6378249.145","rf=293.4663","Clarke 1880 mod."],["clrk80ign","a=6378249.2","rf=293.4660212936269","Clarke 1880 (IGN)."],["CPM","a=6375738.7","rf=334.29","Comm. des Poids et Mesures 1799"],["delmbr","a=6376428","rf=311.5","Delambre 1810 (Belgium)"],["engelis","a=6378136.05","rf=298.2566","Engelis 1985"],["evrst30","a=6377276.345","rf=300.8017","Everest 1830"],["evrst48","a=6377304.063","rf=300.8017","Everest 1948"],["evrst56","a=6377301.243","rf=300.8017","Everest 1956"],["evrst69","a=6377295.664","rf=300.8017","Everest 1969"],["evrstSS","a=6377298.556","rf=300.8017","Everest (Sabah & Sarawak)"],["fschr60","a=6378166","rf=298.3","Fischer (Mercury Datum) 1960"],["fschr60m","a=6378155","rf=298.3","Modified Fischer 1960"],["fschr68","a=6378150","rf=298.3","Fischer 1968"],["helmert","a=6378200","rf=298.3","Helmert 1906"],["hough","a=6378270.0","rf=297","Hough"],["intl","a=6378388.0","rf=297","International 1909 (Hayford)"],["krass","a=6378245.0","rf=298.3","Krasovsky 1940"],["kaula","a=6378163","rf=298.24","Kaula 1961"],["lerch","a=6378139","rf=298.257","Lerch 1979"],["mprts","a=6397300","rf=191","Maupertius 1738"],["new_intl","a=6378157.5","b=6356772.2","New International 1967"],["plessis","a=6376523","b=6355863","Plessis 1817 (France)"],["SEasia","a=6378155.0","b=6356773.3205","Southeast Asia"],["walbeck","a=6376896.0","b=6355834.8467","Walbeck"],["WGS60","a=6378165.0","rf=298.3","WGS 60"],["WGS66","a=6378145.0","rf=298.25","WGS 66"],["WGS72","a=6378135.0","rf=298.26","WGS 72"],["WGS84","a=6378137.0","rf=298.257223563","WGS 84"],["sphere","a=6370997.0","b=6370997.0","Normal Sphere (r=6370997)"],[null,null,null,null]];function lt(t){var e=ot.reduce(function(e,n){return n[0]===t?n:e},null);return e?{id:e[0],major:e[1],ell:e[2],name:e[3]}:null}var ht=[["km","1000","Kilometer"],["m","1","Meter"],["dm","1/10","Decimeter"],["cm","1/100","Centimeter"],["mm","1/1000","Millimeter"],["kmi","1852.0","International Nautical Mile"],["in","0.0254","International Inch"],["ft","0.3048","International Foot"],["yd","0.9144","International Yard"],["mi","1609.344","International Statute Mile"],["fath","1.8288","International Fathom"],["ch","20.1168","International Chain"],["link","0.201168","International Link"],["us-in","1/39.37","U.S. Surveyor's Inch"],["us-ft","0.304800609601219","U.S. Surveyor's Foot"],["us-yd","0.914401828803658","U.S. Surveyor's Yard"],["us-ch","20.11684023368047","U.S. Surveyor's Chain"],["us-mi","1609.347218694437","U.S. Surveyor's Statute Mile"],["ind-yd","0.91439523","Indian Yard"],["ind-ft","0.30479841","Indian Foot"],["ind-ch","20.11669506","Indian Chain"],[null,null,null]];function ct(t){var e=ht.reduce(function(e,n){return t===n[0]?n:e},null);return e?{id:e[0],to_meter:e[1],name:e[2]}:null}var ut={};var pt={};function _t(t){return pt[t]||null}function dt(t){var e,n=t.split(":"),r=n[0],i=n[1];return i&&r||j(-3),(e=_t(r=r.toLowerCase()))||(e=void B("unable to read from 'init' file named "+r),pt[r]=e),e?function(t,e){var n,r,i="",s="";(n=t.indexOf("<"+e+">"))>-1&&((r=t.lastIndexOf("#",n))>-1&&(s=t.substring(r+1,n).trim(),/\n/.test(s)&&(s="")),i=(i=(i=" "+(i=(i=(i=(i=(i=t.substr(n+e.length+2)).substr(0,i.indexOf("<"))).replace(/#.*/g,"")).replace(/[\s]+/g," ")).replace(/\+title=[^+]*[^ +]/g,function(t){return t.replace(/ /g,"\t")}))).replace(/ (?=[a-z])/gi," +")).replace(/\t/g," ").trim());return i?{opts:i,comment:s}:null}(e,i):null}function ft(t){var e,r,s=J(t),a={params:s,is_latlong:!1,is_geocent:!1,is_long_wrap_set:!1,long_wrap_center:0,axis:"enu",gridlist:null,gridlist_count:0,vgridlist_geoid:null,vgridlist_geoid_count:0};return Object.keys(s).length||j(-1),Z(s,"tinit")&&function(t,e){var n=(r=e,ut[r.toLowerCase()]||null);var r;n||function(t,e){ut[t.toLowerCase()]=e}(e,n=dt(e));n||j(-2);mt(t,n.opts)}(s,Z(s,"sinit")),(e=Z(s,"sproj"))||j(-4),(r=Y[e])||j(-5),Z(s,"bno_defs")||function(t){mt(t,"+ellps=WGS84")}(a.params),function(t){var e,n,r,i,s=484813681109536e-20,a=t.datum_params=[0,0,0,0,0,0,0];t.datum_type=0,(e=Z(t.params,"sdatum"))&&((n=at(e))||j(-9),n.ellipse_id&&X(t.params,"ellps="+n.ellipse_id),n.defn&&X(t.params,n.defn)),(r=Z(t.params,"snadgrids"))&&"@null"!=r&&B("+nadgrids is not implemented"),Z(t.params,"scatalog")&&B("+catalog is not implemented"),(i=Z(t.params,"stowgs84"))&&(i.split(",").forEach(function(t,e){a[e]=H(t)||0}),0!=a[3]||0!=a[4]||0!=a[5]||0!=a[6]?(t.datum_type=2,a[3]*=s,a[4]*=s,a[5]*=s,a[6]=a[6]/1e6+1):t.datum_type=1)}(a),function(t){var e,r,s,a,o,l=.16666666666666666,h=t.params,c=0,p=0;Z(h,"tR")?c=Z(h,"dR"):((e=Z(h,"sellps"))&&((r=lt(e))||j(-9),X(h,r.major),X(h,r.ell)),c=Z(h,"da"),Z(h,"tes")?p=Z(h,"des"):Z(h,"te")?p=(s=Z(h,"de"))*s:Z(h,"trf")?((s=Z(h,"drf"))||j(-10),p=(s=1/s)*(2-s)):Z(h,"tf")?p=(s=Z(h,"df"))*(2-s):Z(h,"tb")&&(p=1-(a=Z(h,"db"))*a/(c*c)),a||(a=c*u(1-p)),Z(h,"bR_A")?(c*=1-p*(l+p*(.04722222222222222+.022156084656084655*p)),p=0):Z(h,"bR_V")?c*=1-p*(l+p*(.06944444444444445+.04243827160493827*p)):Z(h,"bR_a")?(c=.5*(c+a),p=0):Z(h,"bR_g")?(c=u(c*a),p=0):Z(h,"bR_h")?(c+a===0&&j(-20),c=2*c*a/(c+a),p=0):(o=Z(h,"tR_lat_a")||Z(h,"tR_lat_g"))&&(s=i(Z(h,o?"rR_lat_a":"rR_lat_g")),n(s)>k&&j(-11),s=1-p*s*s,c*=o?.5*(1-p+s)/(s*u(s)):u(1-p)/s,p=0)),p<0&&j(-12),c<=0&&j(-13),t.es=p,t.a=c}(a),a.a_orig=a.a,a.es_orig=a.es,a.e=u(a.es),a.ra=1/a.a,a.one_es=1-a.es,a.one_es||j(-6),a.rone_es=1/a.one_es,function(t){return 1==t.datum_type&&t.datum_params[0]==t.datum_params[1]==t.datum_params[2]===0&&6378137==t.a&&Math.abs(t.es-.00669437999)<5e-11}(a)&&(a.datum_type=4),a.geoc=!!a.es&&Z(s,"bgeoc"),a.over=Z(s,"bover"),a.has_geoid_vgrids=Z(s,"tgeoidgrids"),a.has_geoid_vgrids&&Z(s,"sgeoidgrids"),a.is_long_wrap_set=Z(s,"tlon_wrap"),a.is_long_wrap_set&&(a.long_wrap_center=Z(s,"rlon_wrap"),n(a.long_wrap_center)<10*I==!1&&j(-14)),Z(s,"saxis")&&function(t){var e="ewnsud",n=Z(t.params,"saxis");3!=n.length&&j(P);-1!=e.indexOf(n[0])&&-1!=e.indexOf(n[1])&&-1!=e.indexOf(n[2])||j(P);t.axis=n}(a),a.lam0=Z(s,"rlon_0"),a.phi0=Z(s,"rlat_0"),a.x0=Z(s,"dx_0"),a.y0=Z(s,"dy_0"),Z(s,"tk_0")?a.k0=Z(s,"dk_0"):Z(s,"tk")?a.k0=Z(s,"dk"):a.k0=1,a.k0<=0&&j(-31),function(t){var e,n,r,i=t.params;(e=Z(i,"sunits"))&&((r=ct(e))||j(-7),n=r.to_meter);n||(n=Z(i,"sto_meter"))?(t.to_meter=gt(n),t.fr_meter=1/t.to_meter):t.to_meter=t.fr_meter=1;n=null,(e=Z(i,"svunits"))&&((r=ct(e))||j(-7),n=r.to_meter);n||Z(i,"svto_meter")?(t.vto_meter=gt(n),t.vfr_meter=1/t.vto_meter):(t.vto_meter=t.to_meter,t.vfr_meter=t.fr_meter)}(a),function(t){var e,n,r,i=t.params;e=Z(i,"spm"),e?(n=function(t){var e=st.reduce(function(e,n){return n[0]===t?n:e},null);return e?{id:e[0],definition:e[1]}:null}(e),r=$(n?n.definition:e),isNaN(r)&&j(-46),t.from_greenwich=r):t.from_greenwich=0}(a),r.init(a),a}function mt(t,e){var n=J(e),r=["datum","ellps","a","b","rf","f"].reduce(function(e,n){return e||n in t},!1);Object.keys(n).forEach(function(e){e in t||"ellps"==e&&r||(t[e]=n[e])})}function gt(t){var e=t.split("/"),n=K(e[0]);return e.length>1&&(n/=K(e[1])),n}function yt(t,e){var n=0,r=t*t,i=e*e;return t<=0&&(n|=4),e<=0&&(n|=8),t<e&&(n|=16),n?null:{a:t,b:e,a2:r,b2:i,e2:(r-i)/r,ep2:(r-i)/i}}function vt(t,e,n,r,a){var o,l,h,c,p=0,_=n[e],d=r[e],f=a[e];return d<-k&&d>-1.001*k?d=-k:d>k&&d<1.001*k?d=k:(d<-k||d>k)&&(p|=1),p||(_>S&&(_-=2*S),l=i(d),c=s(d),h=l*l,o=t.a/u(1-t.e2*h),n[e]=(o+f)*c*s(_),r[e]=(o+f)*c*i(_),a[e]=(o*(1-t.e2)+f)*l),p}function wt(t,e,r,i,s){var a,o,l,p,_,d,f,m,g,y,v,w,S,x,b,C,E=1e-12,A=r[e],M=i[e],I=s[e];if(p=u(A*A+M*M),_=u(A*A+M*M+I*I),p/t.a<E){if(o=0,_/t.a<E)return r[e]=0,i[e]=k,s[e]=-t.b,0}else o=c(M,A);d=I/_,f=p/_,m=1/u(1-t.e2*(2-t.e2)*f*f),v=f*(1-t.e2)*m,w=d*m,C=0;do{C++,l=p*v+I*w-(g=t.a/u(1-t.e2*w*w))*(1-t.e2*w*w),y=t.e2*g/(g+l),b=(x=d*(m=1/u(1-y*(2-y)*f*f)))*v-(S=f*(1-y)*m)*w,v=S,w=x}while(b*b>1e-24&&C<30);a=h(x/n(S)),r[e]=o,i[e]=a,s[e]=l}function St(t,e,n){var r=n.length>2,i=[n[0]],s=[n[1]],a=[r?n[2]:0];t.is_latlong&&(i[0]*=b,s[0]*=b),R.last_errno=0,xt(t,e,i,s,a),(R.last_errno||i[0]==w)&&B(null,{point:n}),e.is_latlong&&(i[0]*=x,s[0]*=x),n[0]=i[0],n[1]=s[0],r&&(n[2]=a[0])}function xt(t,e,n,r,i){var s,a,o=n.length,l={},h={};if("enu"!=t.axis&&bt(t.axis,!1,n,r,i),1!=t.vto_meter&&i)for(s=0;s<o;s++)i[s]*=t.vto_meter;if(t.is_geocent){if(i||j(D),1!=t.to_meter)for(s=0;s<o;s++)n[s]!=w&&(n[s]*=t.to_meter,r[s]*=t.to_meter);Ct(t.a_orig,t.es_orig,n,r,i)}else if(!t.is_latlong)if(t.inv3d||t.inv||B("source projection not invertible"),t.inv3d)B("inverse 3d transformations not supported");else for(s=0;s<o;s++)h.x=n[s],h.y=r[s],a=Mt(h,t),n[s]=a.lam,r[s]=a.phi,G();if(0!==t.from_greenwich)for(s=0;s<o;s++)n[s]!=w&&(n[s]+=t.from_greenwich);if(t.has_geoid_vgrids&&i&&B("vgrid transformation not supported"),function(t,e,n,r,i){var s,a,o,l,h=n.length;if(0==t.datum_type||0==e.datum_type)return;if(function(t,e){if(t.datum_type!=e.datum_type)return!1;if(t.a_orig!=e.a_orig||Math.abs(t.es_orig-e.es_orig)>5e-11)return!1;if(1==t.datum_type)return t.datum_params[0]==e.datum_params[0]&&t.datum_params[1]==e.datum_params[1]&&t.datum_params[2]==e.datum_params[2];if(2==t.datum_type)return t.datum_params[0]==e.datum_params[0]&&t.datum_params[1]==e.datum_params[1]&&t.datum_params[2]==e.datum_params[2]&&t.datum_params[3]==e.datum_params[3]&&t.datum_params[4]==e.datum_params[4]&&t.datum_params[5]==e.datum_params[5]&&t.datum_params[6]==e.datum_params[6];if(3==t.datum_type)return Z(t.params,"snadgrids")==Z(e.params,"snadgrids");return!0}(t,e))return;s=t.a_orig,a=t.es_orig,o=e.a_orig,l=e.es_orig,i||(i=new Float64Array(h));3==t.datum_type&&(B("gridshift not implemented"),s=C,a=E);3==e.datum_type&&(o=C,l=E);a==l&&s==o&&1!=t.datum_type&&2!=t.datum_type&&1!=e.datum_type&&2!=e.datum_type||(Et(s,a,n,r,i),1!=t.datum_type&&2!=t.datum_type||function(t,e,n,r){var i,s,a,o,l,h,c,u,p=e.length,_=t.datum_params,d=_[0],f=_[1],m=_[2];if(1==t.datum_type)for(u=0;u<p;u++)e[u]!=w&&(e[u]+=d,n[u]+=f,r[u]+=m);else if(2==t.datum_type)for(o=_[3],l=_[4],h=_[5],c=_[6],u=0;u<p;u++)e[u]!=w&&(i=c*(e[u]-h*n[u]+l*r[u])+d,s=c*(h*e[u]+n[u]-o*r[u])+f,a=c*(-l*e[u]+o*n[u]+r[u])+m,e[u]=i,n[u]=s,r[u]=a)}(t,n,r,i),1!=e.datum_type&&2!=e.datum_type||function(t,e,n,r){var i,s,a,o,l,h,c,u,p=e.length,_=t.datum_params,d=_[0],f=_[1],m=_[2];if(1==t.datum_type)for(u=0;u<p;u++)e[u]!=w&&(e[u]-=d,n[u]-=f,r[u]-=m);else if(2==t.datum_type)for(o=_[3],l=_[4],h=_[5],c=_[6],u=0;u<p;u++)e[u]!=w&&(i=(e[u]-d)/c,s=(n[u]-f)/c,a=(r[u]-m)/c,e[u]=i+h*s-l*a,n[u]=-h*i+s+o*a,r[u]=l*i-o*s+a)}(e,n,r,i),Ct(o,l,n,r,i),3==e.datum_type&&pj_apply_gridshift_2(e,1,n,r,i))}(t,e,n,r,i),e.has_geoid_vgrids&&i&&B("vgrid transformation not supported"),0!==e.from_greenwich)for(s=0;s<o;s++)n[s]!=w&&(n[s]-=e.from_greenwich);if(e.is_geocent){if(i||j(D),Et(e.a_orig,e.es_orig,n,r,i),1!=e.fr_meter)for(s=0;s<o;s++)n[s]!=w&&(n[s]*=e.fr_meter,r[s]*=e.fr_meter)}else if(e.is_latlong){if(e.is_latlong&&e.is_long_wrap_set)for(s=0;s<o;s++)if(n[s]!=w){for(;n[s]<e.long_wrap_center-S;)n[s]+=I;for(;n[s]>e.long_wrap_center+S;)n[s]-=I}}else if(e.fwd3d)B("3d transformation not supported");else for(s=0;s<o;s++)l.lam=n[s],l.phi=r[s],a=kt(l,e),n[s]=a.x,r[s]=a.y,G();if(1!=e.vto_meter&&i)for(s=0;s<o;s++)i[s]*=e.vfr_meter;return"enu"!=e.axis&&bt(e.axis,!0,n,r,i),1==o?R.last_errno:0}function bt(t,e,n,r,i){var s,a,o,l,h,c,u=n.length,p=0;if(e){for(o=0;o<u;o++)if(s=n[o],a=r[o],s!=w)for(i&&(p=i[o]),l=0;l<3;l++)if(2!=l||i)switch(c=0==l?n:1==l?r:i,t[l]){case"e":c[o]=s;break;case"w":c[o]=-s;break;case"n":c[o]=a;break;case"s":c[o]=-a;break;case"u":c[o]=p;break;case"d":c[o]=-p;break;default:j(P)}}else for(o=0;o<u;o++)if(s=n[o],a=r[o],s!=w)for(i&&(p=i[o]),l=0;l<3;l++)switch(h=0==l?s:1==l?a:p,t[l]){case"e":n[o]=h;break;case"w":n[o]=-h;break;case"n":r[o]=h;break;case"s":r[o]=-h;break;case"u":i&&(i[o]=h);break;case"d":i&&(i[o]=-h);break;default:j(P)}}function Ct(t,e,n,r,i){var s,a,o=n.length;for((a=yt(t,0==e?t:t*u(1-e)))||j(D),s=0;s<o;s++)n[s]!=w&&wt(a,s,n,r,i)}function Et(t,e,n,r,i){var s,a,o=n.length;for((a=yt(t,0===e?t:t*u(1-e)))||j(D),s=0;s<o;s++)n[s]!=w&&vt(a,s,n,r,i)&&(n[s]=r[s]=w)}function At(t){var e=6.283185307179586,i=3.141592653589793;return n(t)>3.14159265359&&(t+=i,t-=e*r(t/e),t-=i),t}function kt(t,e){var r={x:0,y:0},i=n(t.phi)-k;return i<=1e-12&&n(t.lam)<=10?(R.last_errno=0,n(i)<=1e-12?t.phi=t.phi<0?-k:k:e.geoc&&(t.phi=h(e.rone_es*a(t.phi))),t.lam-=e.lam0,e.over||(t.lam=At(t.lam)),e.fwd?(e.fwd(t,r),r.x=e.fr_meter*(e.a*r.x+e.x0),r.y=e.fr_meter*(e.a*r.y+e.y0)):r.x=r.y=w):F(-14),!R.last_errno&&isFinite(r.x)&&isFinite(r.y)||(r.x=r.y=w),r}function Mt(t,e){var r={lam:0,phi:0};return t.x<w&&t.y<w?(R.last_errno=0,e.inv?(t.x=(t.x*e.to_meter-e.x0)*e.ra,t.y=(t.y*e.to_meter-e.y0)*e.ra,e.inv(t,r),r.lam+=e.lam0,e.over||(r.lam=At(r.lam)),e.geoc&&n(n(r.phi)-k)>1e-12&&(r.phi=h(e.one_es*a(r.phi)))):r.lam=r.phi=w):F(-15),!R.last_errno&&isFinite(r.lam)&&isFinite(r.phi)||(r.lam=r.phi=w),r}function It(t,e,n,i){var s,a,o;for((t<0||t>=9)&&(t=3),s=1,o=0;o<t;o++)s*=10;return a=3600*s,function(o){var l,h,c,u,p="",_="",d="";return o===w||isNaN(o)?"":(o<0?(o=-o,(c=i||"")||(p="-")):c=n||"",h=(o=r(o*a+.5))/s%60,l=(o=r(o/(60*s)))%60,u=r(o/60)+"d",d=h.toFixed(t),d=(h=parseFloat(d))?(e?d:String(h))+'"':"",(h||l)&&2==(_=String(l)+"'").length&&e&&(_="0"+_),p+u+_+d+c)}}function Tt(t,e,n){var r,i,s,a,o,l;return"string"!=typeof t?Wr:("string"!=typeof e?(i="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs",s=t,r=e):(i=t,s=e,r=n),l=Dt(a=ft(i),o=ft(s)),r?l(r):{forward:l,inverse:Dt(o,a)})}function Dt(t,e){return function(n){var r=Array.isArray(n);return n=r?n.concat():[n.x,n.y],St(t,e,n),r||(n={x:n[0],y:n[1]}),n}}function Pt(t){var e=t.proj in Y?Y[t.proj].name:"",n=nt(t),r=Qt(t);return{PROJCS:{NAME:e?r.NAME+" / "+e:"unnamed",GEOGCS:r,PROJECTION:"custom_proj4",PARAMETER:[],UNIT:Wt(t),EXTENSION:["PROJ4",n+" +wktext"]}}}function Nt(t){var e=t.EXTENSION;return e&&"PROJ4"==e[0]?(e[1]||"").replace(" +wktext",""):null}Tt.WGS84="+proj=longlat +datum=WGS84",Tt.toPoint=function(t){var e={x:t[0],y:t[1]};return t.length>2&&(e.z=t[2]),t.length>3&&(e.m=t[3]),e};var Rt=[],Lt=[];function Gt(t){return"string"==typeof t}function Ot(t){var e=Ut(t,Lt);return e||(e=function(t){return Nt(t)?Nt:null}(t)),e||Bt("unsupported WKT definition: "+(t.NAME||"[unknown]")),e}function Ft(t){var e=Ut(t,Rt);return e||(e=Pt),e||Bt("unsupported projection: "+function(t){return qt(t)||"[unknown]"}(t)),e}function Ut(t,e){for(var n=0;n<e.length;n++)if((0,e[n][0])(t))return e[n][1];return null}function qt(t){return Z(t.params,"sproj")}function jt(t){return t.replace(/[-_ \/]+/g,"_").toLowerCase()}function zt(t){var e;return Array.isArray(t)?e=t:t&&t.length>0&&(e=t.split(",")),e}function Bt(t){throw new Error(t)}function Vt(t){console.error("[wkt] "+t)}function $t(t){return{to_meter:t.UNIT[1]}}function Wt(t){return["Meter",t.to_meter||1]}function Ht(t,e){var n,r,i=t.DATUM,s=i.SPHEROID,a=function(t){var e,n={northamerican1983:"NAD83",newzealand1949:"nzgd49"},r=Kt(t.NAME);if(r in n)return n[r];for(var i=0;i<it.length&&(Kt((e=it[i])[3])!=r&&Kt(e[0])!=r);i++);return e?e[0]:null}(i),o=function(t){var e,n={international1924:"intl"},r=Kt(t[0]);if(r in n)return n[r];if(/^grs1980/.test(r))return"GRS80";if("sphere"==r)return null;for(var i=0;i<ot.length&&(Kt((e=ot[i])[3])!=r&&Kt(e[0])!=r);i++);return e?e[0]:null}(s),l=e&&e.aux_sphere,h=s[1],c=s[2];return Zt(t.UNIT,"degree"),l?n="+a="+s[1]:a?n="+datum="+a:o?n="+ellps="+o:(n="+a="+h,c>0&&(n+=" +rf="+c)),!i.TOWGS84||l||a||(n+=" +towgs84="+i.TOWGS84.join(",")),((r=t.PRIMEM?t.PRIMEM[1]:0)>0||r<0)&&(n+=" +pm="+r),n}function Kt(t){return(t||"").replace(/^(GCS|D)_/i,"").replace(/[ _]/g,"").toLowerCase()}function Zt(t,e){t&&t[0].toLowerCase()!=e&&Bt("unexpected geographic units: "+geogcs.UNIT[0])}function Jt(t){return Ot(t)(t)}function Xt(t){return function(){return"+proj="+t}}function Yt(t){return function(e){var n,r;return[t.PROJECTION(e),t.PARAMETER(e),t.GEOGCS?t.GEOGCS(e):Ht(e.GEOGCS),(n=$t(e),r="",1!=n.to_meter&&(r="+to_meter="+n.to_meter),r),"+no_defs"].filter(function(t){return!!t}).join(" ")}}function Qt(t){return{NAME:ne(t),DATUM:te(t),PRIMEM:["Greenwich",0],UNIT:["degree",.017453292519943295]}}function te(t){var e={NAME:ie(t),SPHEROID:ee(t)},n=Z(t.params,"stowgs84");return/[1-9]/.test(n)&&(e.TOWGS84=n),e}function ee(t){var e;return e=Z(t.params,"trf")?Z(t.params,"drf"):t.es?1/(1-Math.sqrt(1-t.es)):0,[re(t),t.a,e]}function ne(t){var e;return tt(t)&&(e=he(t)),e||(e=se(t),e=/^[a-z]+$/.test(e)?e[0].toUpperCase()+e.substr(1):e.toUpperCase()),e||"UNK"}function re(t){var e=lt(function(t){var e,n=se(t),r=n?at(n):null;e=r?r.ellipse_id:Z(t.params,"sellps");return e||""}(t));return e?e.name:"Unknown ellipsoid"}function ie(t){var e=at(se(t));return e&&e.name||"Unknown datum"}function se(t){return Z(t.params,"sdatum")}function ae(t){return Ft(t)(t)}function oe(t,e){return le({PROJECTION:t,PARAMETER:Pe(e)})}function le(t){return function(e){var n={GEOGCS:t.GEOGCS&&t.GEOGCS(e)||Qt(e),PROJECTION:Gt(t.PROJECTION)?t.PROJECTION:t.PROJECTION(e),PARAMETER:t.PARAMETER(e),UNIT:Wt(e)};return n.NAME=t.NAME&&t.NAME(e,n)||function(t,e){var n=he(t);return n||e.GEOGCS.NAME+" / "+e.PROJECTION}(e,n),{PROJCS:n}}}function he(t){var e;return Z(t.params,"tinit")&&(e=dt(Z(t.params,"sinit"))),e?e.comment:""}function ce(t,e,n){var r=pe(e),i=function(t,e){return Yt({PROJECTION:Xt(t),PARAMETER:De(e)})}(t,n);de(r,i)}function ue(t,e,n){fe(_e(t),oe(e,n))}function pe(t){var e=zt(t).map(jt);return function(t){var n=t.PROJECTION[0];return e.indexOf(jt(n))>-1}}function _e(t){return function(e){var n=qt(e);return n&&n==t}}function de(t,e){"function"!=typeof t&&Bt("Missing WKT parser test"),"function"!=typeof e&&Bt("Missing WKT parse function"),Lt.push([t,e])}function fe(t,e){"function"!=typeof t&&Bt("Missing WKT maker test"),"function"!=typeof e&&Bt("Missing WKT maker function"),Rt.push([t,e])}de(function(t){return me.test(jt(t.NAME))},function(t){return Yt({PROJECTION:Xt("utm"),PARAMETER:function(t){var e=me.exec(jt(t.NAME)),n="+zone="+e[1];"s"==e[2].toLowerCase()&&(n+=" +south");return n}})(t)}),de(function(t){return ge.test(jt(t.NAME))},function(t){return Yt({PROJECTION:Xt("ups"),PARAMETER:function(t){var e=ge.exec(jt(t.NAME));return"south"==e[1].toLowerCase()?"+south":""}})(t)}),fe(_e("utm"),function(t){return le({NAME:ye,PROJECTION:function(){return"Transverse_Mercator"},PARAMETER:we})(t)}),fe(_e("ups"),function(t){return le({NAME:ve,PROJECTION:function(){return"Polar_Stereographic"},PARAMETER:Se})(t)});var me=/UTM_zone_([0-9]{1,2})(N|S)/i,ge=/UPS_(North|South)/i;function ye(t,e){return e.GEOGCS.NAME+" / UTM zone "+Z(t.params,"szone")+(Z(t.params,"tsouth")?"S":"N")}function ve(t,e){return e.GEOGCS.NAME+" / UPS "+(Z(t.params,"tsouth")?"South":"North")}function we(t){return[["latitude_of_origin",0],["central_meridian",180*t.lam0/S],["scale_factor",t.k0],["false_easting",t.x0],["false_northing",t.y0]]}function Se(t){return[["latitude_of_origin",-90],["central_meridian",0],["scale_factor",.994],["false_easting",2e6],["false_northing",2e6]]}function xe(t){return Z(t.params,"tlat_ts")&&0!=Z(t.params,"dlat_ts")}function be(t){return 0===t.es&&6378137==t.a}de(pe("Mercator_2SP,Mercator_1SP,Mercator,Mercator_Auxiliary_Sphere"),Yt({GEOGCS:function(t){var e=function(t){return/(Web_Mercator|Pseudo_Mercator)/i.test(jt(t.NAME))}(t)?{aux_sphere:!0}:null;return Ht(t.GEOGCS,e)},PROJECTION:Xt("merc"),PARAMETER:function(t){return De(function(t){var e=Ie(t,"standard_parallel_1");return e&&0!=e[1]}(t)?"lat_ts,lat_0b":"lat_tsb,lat_ts")(t)}})),fe(_e("merc"),le({GEOGCS:function(t){if(be(t))return Qt(ft("+proj=longlat +datum=WGS84"));return null},PROJECTION:function(t){return xe(t)?"Mercator_2SP":"Mercator_1SP"},PARAMETER:function(t){return Pe(xe(t)?"lat_ts,lat_0b":"lat_tsb")(t)},NAME:function(t){return be(t)?"WGS 84 / Pseudo-Mercator":null}}));var Ce=[["x_0","false_easting","m"],["y_0","false_northing","m"],["k_0","scale_factor","f"],["lat_0","latitude_of_center"],["lon_0","central_meridian"]],Ee={lat_0b:["lat_0","latitude_of_origin"],lat_0c:["lat_0",null],lat_0d:["lat_0","standard_parallel_1"],lat_1:["lat_1","standard_parallel_1"],lat_1b:["lat_1","latitude_of_point_1"],lat_1c:["lat_1","latitude_of_origin"],lat_2:["lat_2","standard_parallel_2"],lat_2b:["lat_2","latitude_of_point_2"],lat_ts:["lat_ts","standard_parallel_1"],lat_tsb:["lat_ts","latitude_of_origin"],lonc:["lonc","central_meridian"],lon_1:["lon_1","longitude_of_point_1"],lon_2:["lon_2","longitude_of_point_2"],alpha:["alpha","azimuth"],gamma:["gamma","rectified_grid_angle"],h:["h","height","f"]},Ae={longitude_of_center:"central_meridian",latitude_of_origin:"latitude_of_center",latitude_of_center:"latitude_of_origin",longitude_of_1st_point:"longitude_of_point_1",longitude_of_2nd_point:"longitude_of_point_2",latitude_of_1st_point:"latitude_of_point_1",latitude_of_2nd_point:"latitude_of_point_2",k:"k_0"};function ke(t,e,n){for(var r=0;r<n.length;r++)if(n[r][e]===t)return n[r];return null}function Me(t,e,n){var r=null;return!(r=ke(t=t.toLowerCase(),e,n))&&t in Ae&&(r=ke(Ae[t],e,n)),r}function Ie(t,e){for(var n,r=t.PARAMETER||[],i=0;i<r.length;i++)if(e===(n=r[i][0].toLowerCase())||e===Ae[n])return r[i];return null}function Te(t){var e=null;return t&&(e=zt(t).reduce(function(t,e){var n=Ee[e];return n||Bt("missing parameter rule: "+e),t.push(n),t},[])),(e||[]).concat(Ce)}function De(t){return function(e){var n=[],r=Te(t),i=$t(e);return(e.PARAMETER||[]).forEach(function(t){var e,s=Me(t[0],1,r);s?(e=function(t,e,n){var r=t[0];if("m"==t[2]&&(e*=n.to_meter),!("x_0,y_0,lat_0,lon_0".indexOf(r)>-1&&0===e||"k_0"==r&&1==e))return"+"+r+"="+e}(s,t[1],i),e&&n.push(e)):Vt("unhandled parameter: "+t[0])}),n.join(" ")}}function Pe(t){return function(e){var n=[],r=Te(t);return Object.keys(e.params).forEach(function(t){var i,s=Me(t,0,r);s&&s[1]&&(i=Z(e.params,"s"+t),n.push(function(t,e,n){var r,i=t[2];return r="m"==i?parseFloat(e)/n:"f"==i?parseFloat(e):W(e),[t[1],r]}(s,i,e.to_meter)))}),n}}function Ne(t){return!("lat_1"in t.params&&"lat_2"in t.params)}function Re(t){return"omerc"==qt(t)&&("alpha"in t.params||"gamma"in t.params)}function Le(t){return Re(t)&&("no_uoff"in t.params||"no_off"in t.params)}function Ge(t){return Z(t.params,"tlat_ts")}function Oe(t){var e=JSON.stringify(Ue(t));return e=(e=e.replace(/\["([A-Z0-9]+)",/g,"$1[")).replace(/"(EAST|NORTH|SOUTH|WEST)"/g,"$1")}function Fe(t){return"NAME,PROJCS,GEOGCS,GEOCCS,DATUM,SPHEROID,PRIMEM,PROJECTION,PARAMETER,UNIT,AXIS".indexOf(t)+1||999}function Ue(t,e){var n,r=[];return e=e||0,function(t){return Object.keys(t).sort(function(t,e){return Fe(t)-Fe(e)})}(t).forEach(function(i){var s=t[i];!function(t){return!!t&&"object"==typeof t&&!Array.isArray(t)}(s)?"NAME"==i?r.push(Gt(s)?s:s[0]):"PARAMETER"==i||"AXIS"==i?s.forEach(function(t){r.push([i].concat(t))}):Gt(s)?r.push([i,s]):Array.isArray(s)?r.push([i].concat(s)):((n={})[i]=s,Bt("Incorrectly formatted WKT element: "+JSON.stringify(n))):r.push([i].concat(Ue(s,e+1)))}),0===e&&1==r.length&&(r=r[0]),r}function qe(t){var e={};return je(t).forEach(function(t){Be(t,e)}),e}function je(t){var e;t="["+(t=(t=(t=ze(t)).replace(/([A-Z0-9]+)\[(?![^"]*[^\[,"]")/g,'["$1",')).replace(/, *([a-zA-Z]+) *(?=[,\]])/g,',"$1"'))+"]";try{e=JSON.parse(t)}catch(t){Bt("unparsable WKT format")}return e}function ze(t){var e=0;return t.replace(/"+/g,function(t){var n=e%2==0;return e+=t.length,'"'==t||'""'==t&&n?t:n?'"'+t.substring(1).replace(/""/g,'\\"'):t.replace(/""/g,'\\"')})}function Be(t,e){var n,r=t[0];if("GEOGCS"==r||"GEOCCS"==r||"PROJCS"==r||"DATUM"==r||"VERTCS"==r)for(e[r]={NAME:t[1]},n=2;n<t.length;n++){if(!Array.isArray(t[n]))throw Bt("WKT parse error");Be(t[n],e[r])}else"AXIS"==r||"PARAMETER"==r?(r in e==!1&&(e[r]=[]),e[r].push(t.slice(1))):e[r]=t.slice(1);return e}de(pe("Lambert_Conformal_Conic,Lambert_Conformal_Conic_1SP,Lambert_Conformal_Conic_2SP"),Yt({PROJECTION:Xt("lcc"),PARAMETER:function(t){return De(function(t){return!Ie(t,"standard_parallel_2")}(t)?"lat_1c":"lat_0b,lat_1,lat_2")(t)}})),fe(_e("lcc"),le({PROJECTION:function(t){return Ne(t)?"Lambert_Conformal_Conic_1SP":"Lambert_Conformal_Conic_2SP"},PARAMETER:function(t){return Pe(Ne(t)?"lat_1c,lat_0c":"lat_0b,lat_1,lat_2")(t)}})),de(pe("Hotine_Oblique_Mercator,Hotine_Oblique_Mercator_Azimuth_Natural_Origin"),Yt({PROJECTION:Xt("omerc"),PARAMETER:function(t){return De("alpha,gamma,lonc")(t)+" +no_uoff"}})),fe(Le,oe("Hotine_Oblique_Mercator","alpha,gamma,lonc")),ce("omerc","Oblique_Mercator,Hotine_Oblique_Mercator_Azimuth_Center","alpha,gamma,lonc"),fe(function(t){return Re(t)&&!Le(t)},oe("Oblique_Mercator","alpha,gamma,lonc")),ce("omerc","Hotine_Oblique_Mercator_Two_Point_Natural_Origin","lat_1b,lat_2b,lon_1,lon_2"),fe(function(t){return"omerc"==qt(t)&&"lat_2"in t.params&&"lon_2"in t.params},oe("Hotine_Oblique_Mercator_Two_Point_Natural_Origin","lat_1b,lat_2b,lon_1,lon_2")),de(pe("Stereographic,Polar_Stereographic,Stereographic_North_Pole,Stereographic_South_Pole"),Yt({PROJECTION:Xt("stere"),PARAMETER:function(t){var e=De("lat_ts,lat_tsb")(t),n=/lat_ts=([^ ]+)/.exec(e);n&&-1==e.indexOf("lat_0=")&&(e="+lat_0="+(parseFloat(n[1])<0?-90:90)+" "+e);return e}})),fe(_e("stere"),le({PROJECTION:function(t){return Ge(t)?"Polar_Stereographic":"Stereographic"},PARAMETER:function(t){return Ge(t)?Pe("lat_tsb,lat_0c")(t):Pe("lat_0b")(t)}})),ue("vandg","VanDerGrinten"),de(pe("VanDerGrinten,Van_der_Grinten_I"),Yt({PROJECTION:Xt("vandg"),PARAMETER:function(t){var e=De("")(t);return e&&(e+=" "),e+"+R_A"}})),[["aitoff","Aitoff","lat1"],["aea","Albers_Conic_Equal_Area,Albers","lat_1,lat_2"],["aeqd","Azimuthal_Equidistant"],["bonne","Bonne","lat_1"],["cass","Cassini_Soldner,Cassini"],["cea","Cylindrical_Equal_Area","lat_ts"],["eck1","Eckert_I"],["eck2","Eckert_II"],["eck3","Eckert_III"],["eck4","Eckert_IV"],["eck5","Eckert_V"],["eck6","Eckert_VI"],["eqdc","Equidistant_Conic","lat_1,lat_2"],["eqc","Plate_Carree,Equirectangular,Equidistant_Cylindrical","lat_ts"],["gall","Gall_Stereographic"],["gnom","Gnomonic"],["laea","Lambert_Azimuthal_Equal_Area"],["loxim","Loximuthal","lat_1"],["mill","Miller_Cylindrical"],["moll","Mollweide"],["nsper","Vertical_Near_Side_Perspective","h"],["nzmg","New_Zealand_Map_Grid","lat_0b"],["ortho","Orthographic","lat_0b"],["poly","Polyconic"],["robin","Robinson"],["sinu","Sinusoidal"],["sterea","Oblique_Stereographic,Double_Stereographic"],["tmerc","Transverse_Mercator,Gauss_Kruger","lat_0b"],["tpeqd","Two_Point_Equidistant","lat_1b,lat_2b,lon_1,lon_2"],["wag1","Wagner_I"],["wag2","Wagner_II"],["wag3","Wagner_III","lat_ts"],["wag4","Wagner_IV"],["wag5","Wagner_V"],["wag6","Wagner_VI"],["wag7","Wagner_VII"],["wink1","Winkel_I","lat_ts"],["wink2","Winkel_II"],["wintri","Winkel_Tripel","lat_1"]].forEach(function(t){var e=t[2]||null;ce(t[0],t[1],e),ue(t[0],t[1].split(",")[0],e)});var Ve={Transverse_Mercator:{epsg:9807,name:"Transverse Mercator",params:["tm_lat_0","tm_lon_0","tm_k","tm_fe","tm_fn"]},Gauss_Kruger:{epsg:9807,name:"Transverse Mercator",params:["tm_lat_0","tm_lon_0","tm_k","tm_fe","tm_fn"]},Lambert_Conformal_Conic_1SP:{epsg:9801,name:"Lambert Conic Conformal (1SP)",params:["tm_lat_0","tm_lon_0","tm_k","tm_fe","tm_fn"]},Lambert_Conformal_Conic_2SP:{epsg:9802,name:"Lambert Conic Conformal (2SP)",params:["lcc2_lat_f","lcc2_lon_f","lcc2_sp1","lcc2_sp2","lcc2_fe","lcc2_fn"]},Lambert_Conformal_Conic:{epsg:9802,name:"Lambert Conic Conformal (2SP)",params:["lcc2_lat_f","lcc2_lon_f","lcc2_sp1","lcc2_sp2","lcc2_fe","lcc2_fn"]},Mercator_1SP:{epsg:9804,name:"Mercator (variant A)",params:["tm_lat_0","tm_lon_0","tm_k","tm_fe","tm_fn"]},Mercator_2SP:{epsg:9805,name:"Mercator (variant B)",params:["merc2_sp1","tm_lon_0","tm_fe","tm_fn"]},Mercator_Auxiliary_Sphere:{epsg:1024,name:"Popular Visualisation Pseudo Mercator",params:["tm_lat_0","tm_lon_0","tm_fe","tm_fn"]},Lambert_Azimuthal_Equal_Area:{epsg:9820,name:"Lambert Azimuthal Equal Area",params:["laea_lat_0","laea_lon_0","tm_fe","tm_fn"]},Albers_Conic_Equal_Area:{epsg:9822,name:"Albers Equal Area",params:["aea_lat_f","aea_lon_f","lcc2_sp1","lcc2_sp2","lcc2_fe","lcc2_fn"]},Albers:{epsg:9822,name:"Albers Equal Area",params:["aea_lat_f","aea_lon_f","lcc2_sp1","lcc2_sp2","lcc2_fe","lcc2_fn"]},Polar_Stereographic:{epsg:9810,name:"Polar Stereographic (variant A)",params:["tm_lat_0","tm_lon_0","tm_k","tm_fe","tm_fn"]},Stereographic_North_Pole:{epsg:9829,name:"Polar Stereographic (variant B)",params:["ps_sp","ps_lon_0","tm_fe","tm_fn"]},Stereographic_South_Pole:{epsg:9829,name:"Polar Stereographic (variant B)",params:["ps_sp","ps_lon_0","tm_fe","tm_fn"]},Oblique_Stereographic:{epsg:9809,name:"Oblique Stereographic",params:["tm_lat_0","tm_lon_0","tm_k","tm_fe","tm_fn"]},Stereographic:{epsg:9809,name:"Oblique Stereographic",params:["tm_lat_0","tm_lon_0","tm_k","tm_fe","tm_fn"]},Hotine_Oblique_Mercator:{epsg:9812,name:"Hotine Oblique Mercator (variant A)",params:["omerc_lat_0","omerc_lon_0","omerc_az","omerc_ra","omerc_k","tm_fe","tm_fn"]},Krovak:{epsg:1041,name:"Krovak (North Orientated)",params:["omerc_lat_0","ps_lon_0","krovak_alpha","krovak_sp","krovak_k","tm_fe","tm_fn"]},Azimuthal_Equidistant:{name:"Modified Azimuthal Equidistant",epsg:9832,params:["tm_lat_0","tm_lon_0","tm_fe","tm_fn"]},Cassini_Soldner:{name:"Cassini-Soldner",epsg:9806,params:["tm_lat_0","tm_lon_0","tm_fe","tm_fn"]},Cassini:{name:"Cassini-Soldner",epsg:9806,params:["tm_lat_0","tm_lon_0","tm_fe","tm_fn"]},Equidistant_Conic:{name:"Equidistant Conic",params:["tm_lat_0","tm_lon_0","lcc2_sp1","lcc2_sp2","tm_fe","tm_fn"]},Equirectangular:{name:"Equidistant Cylindrical",epsg:1028,params:["ps_sp","tm_lon_0","tm_fe","tm_fn"]},Equidistant_Cylindrical:{name:"Equidistant Cylindrical",epsg:1028,params:["ps_sp","tm_lon_0","tm_fe","tm_fn"]},Plate_Carree:{name:"Equidistant Cylindrical",epsg:1028,params:["ps_sp","tm_lon_0","tm_fe","tm_fn"]},Mollweide:{name:"Mollweide",params:["tm_lon_0","tm_fe","tm_fn"]},Sinusoidal:{name:"Sinusoidal",params:["tm_lon_0","tm_fe","tm_fn"]},Robinson:{name:"Robinson",params:["tm_lon_0","tm_fe","tm_fn"]},Gnomonic:{name:"Gnomonic",params:["tm_lat_0","tm_lon_0","tm_fe","tm_fn"]},Orthographic:{name:"Orthographic",epsg:9840,params:["tm_lat_0","tm_lon_0","tm_fe","tm_fn"]},Polyconic:{name:"American Polyconic",epsg:9818,params:["tm_lat_0","tm_lon_0","tm_fe","tm_fn"]},Aitoff:{name:"Aitoff",params:["tm_lon_0","tm_fe","tm_fn"]},Bonne:{name:"Bonne",epsg:9827,params:["tm_lat_0","tm_lon_0","tm_fe","tm_fn"]},Cylindrical_Equal_Area:{name:"Lambert Cylindrical Equal Area",epsg:9835,params:["ps_sp","tm_lon_0","tm_fe","tm_fn"]},Gall_Stereographic:{name:"Gall Stereographic",params:["tm_lon_0","tm_fe","tm_fn"]},Miller_Cylindrical:{name:"Miller Cylindrical",params:["tm_lon_0","tm_fe","tm_fn"]},Loximuthal:{name:"Loximuthal",params:["tm_lon_0","tm_fe","tm_fn"]},New_Zealand_Map_Grid:{name:"New Zealand Map Grid",epsg:9811,params:["tm_lat_0","tm_lon_0","tm_fe","tm_fn"]},Vertical_Near_Side_Perspective:{name:"Vertical Perspective",epsg:9838,params:["tm_lat_0","tm_lon_0","tm_height","tm_fe","tm_fn"]},VanDerGrinten:{name:"Van der Grinten",params:["tm_lon_0","tm_fe","tm_fn"]},Van_der_Grinten_I:{name:"Van der Grinten I",params:["tm_lon_0","tm_fe","tm_fn"]},Winkel_Tripel:{name:"Winkel Tripel",params:["ps_sp","tm_lon_0","tm_fe","tm_fn"]},Winkel_I:{name:"Winkel I",params:["ps_sp","tm_lon_0","tm_fe","tm_fn"]},Winkel_II:{name:"Winkel II",params:["tm_lon_0","tm_fe","tm_fn"]},Eckert_I:{name:"Eckert I",params:["tm_lon_0","tm_fe","tm_fn"]},Eckert_II:{name:"Eckert II",params:["tm_lon_0","tm_fe","tm_fn"]},Eckert_III:{name:"Eckert III",params:["tm_lon_0","tm_fe","tm_fn"]},Eckert_IV:{name:"Eckert IV",params:["tm_lon_0","tm_fe","tm_fn"]},Eckert_V:{name:"Eckert V",params:["tm_lon_0","tm_fe","tm_fn"]},Eckert_VI:{name:"Eckert VI",params:["tm_lon_0","tm_fe","tm_fn"]},Wagner_I:{name:"Wagner I",params:["tm_lon_0","tm_fe","tm_fn"]},Wagner_II:{name:"Wagner II",params:["tm_lon_0","tm_fe","tm_fn"]},Wagner_III:{name:"Wagner III",params:["ps_sp","tm_lon_0","tm_fe","tm_fn"]},Wagner_IV:{name:"Wagner IV",params:["tm_lon_0","tm_fe","tm_fn"]},Wagner_V:{name:"Wagner V",params:["tm_lon_0","tm_fe","tm_fn"]},Wagner_VI:{name:"Wagner VI",params:["tm_lon_0","tm_fe","tm_fn"]},Wagner_VII:{name:"Wagner VII",params:["tm_lon_0","tm_fe","tm_fn"]},Two_Point_Equidistant:{name:"Two Point Equidistant",params:["tpeqd_lat_1","tpeqd_lon_1","tpeqd_lat_2","tpeqd_lon_2","tm_fe","tm_fn"]},Hotine_Oblique_Mercator_Two_Point_Natural_Origin:{name:"Hotine Oblique Mercator Two Point Natural Origin",params:["tm_lat_0","tpeqd_lat_1","tpeqd_lon_1","tpeqd_lat_2","tpeqd_lon_2","tm_fe","tm_fn"]},Oblique_Mercator:{name:"Hotine Oblique Mercator (variant B)",epsg:9815,params:["omerc_lat_0","omerc_lon_0","omerc_az","omerc_ra","omerc_k","omerc_fe","omerc_fn"]},Double_Stereographic:{name:"Oblique Stereographic",epsg:9809,params:["tm_lat_0","tm_lon_0","tm_k","tm_fe","tm_fn"]}},$e={tm_lat_0:{wkt1:"latitude_of_origin",wkt2:"Latitude of natural origin",epsg:8801,unit:"angle",default:0,wkt1_fallback:"latitude_of_center"},tm_lon_0:{wkt1:"central_meridian",wkt2:"Longitude of natural origin",epsg:8802,unit:"angle",default:0,wkt1_fallback:"longitude_of_center"},tm_k:{wkt1:"scale_factor",wkt2:"Scale factor at natural origin",epsg:8805,unit:"scale",default:1},tm_fe:{wkt1:"false_easting",wkt2:"False easting",epsg:8806,unit:"length",default:0},tm_fn:{wkt1:"false_northing",wkt2:"False northing",epsg:8807,unit:"length",default:0},lcc2_lat_f:{wkt1:"latitude_of_origin",wkt2:"Latitude of false origin",epsg:8821,unit:"angle",default:0},lcc2_lon_f:{wkt1:"central_meridian",wkt2:"Longitude of false origin",epsg:8822,unit:"angle",default:0},lcc2_sp1:{wkt1:"standard_parallel_1",wkt2:"Latitude of 1st standard parallel",epsg:8823,unit:"angle",default:0},lcc2_sp2:{wkt1:"standard_parallel_2",wkt2:"Latitude of 2nd standard parallel",epsg:8824,unit:"angle",default:0},lcc2_fe:{wkt1:"false_easting",wkt2:"Easting at false origin",epsg:8826,unit:"length",default:0},lcc2_fn:{wkt1:"false_northing",wkt2:"Northing at false origin",epsg:8827,unit:"length",default:0},laea_lat_0:{wkt1:"latitude_of_center",wkt2:"Latitude of natural origin",epsg:8801,unit:"angle",default:0,wkt1_fallback:"latitude_of_origin"},laea_lon_0:{wkt1:"longitude_of_center",wkt2:"Longitude of natural origin",epsg:8802,unit:"angle",default:0,wkt1_fallback:"central_meridian"},aea_lat_f:{wkt1:"latitude_of_center",wkt2:"Latitude of false origin",epsg:8821,unit:"angle",default:0,wkt1_fallback:"latitude_of_origin"},aea_lon_f:{wkt1:"central_meridian",wkt2:"Longitude of false origin",epsg:8822,unit:"angle",default:0,wkt1_fallback:"longitude_of_center"},merc2_sp1:{wkt1:"standard_parallel_1",wkt2:"Latitude of 1st standard parallel",epsg:8823,unit:"angle",default:0},ps_sp:{wkt1:"standard_parallel_1",wkt2:"Latitude of standard parallel",epsg:8832,unit:"angle",default:0},ps_lon_0:{wkt1:"central_meridian",wkt2:"Longitude of origin",epsg:8833,unit:"angle",default:0},omerc_lat_0:{wkt1:"latitude_of_center",wkt2:"Latitude of projection centre",epsg:8811,unit:"angle",default:0,wkt1_fallback:"latitude_of_origin"},omerc_lon_0:{wkt1:"longitude_of_center",wkt2:"Longitude of projection centre",epsg:8812,unit:"angle",default:0,wkt1_fallback:"central_meridian"},omerc_az:{wkt1:"azimuth",wkt2:"Azimuth of initial line",epsg:8813,unit:"angle",default:0},omerc_ra:{wkt1:"rectified_grid_angle",wkt2:"Angle from Rectified to Skew Grid",epsg:8814,unit:"angle",default:0,skipIfAbsent:!0},omerc_k:{wkt1:"scale_factor",wkt2:"Scale factor on initial line",epsg:8815,unit:"scale",default:1},omerc_fe:{wkt1:"false_easting",wkt2:"Easting at projection centre",epsg:8816,unit:"length",default:0},omerc_fn:{wkt1:"false_northing",wkt2:"Northing at projection centre",epsg:8817,unit:"length",default:0},tm_height:{wkt1:"height",wkt2:"Viewpoint height",epsg:8840,unit:"length",default:1e6},tpeqd_lat_1:{wkt1:"latitude_of_point_1",wkt2:"Latitude of 1st point",unit:"angle",default:0},tpeqd_lon_1:{wkt1:"longitude_of_point_1",wkt2:"Longitude of 1st point",unit:"angle",default:0},tpeqd_lat_2:{wkt1:"latitude_of_point_2",wkt2:"Latitude of 2nd point",unit:"angle",default:0},tpeqd_lon_2:{wkt1:"longitude_of_point_2",wkt2:"Longitude of 2nd point",unit:"angle",default:0},krovak_alpha:{wkt1:"azimuth",wkt2:"Co-latitude of cone axis",epsg:1036,unit:"angle",default:30.2881397527778},krovak_sp:{wkt1:"pseudo_standard_parallel_1",wkt2:"Latitude of pseudo standard parallel",epsg:8818,unit:"angle",default:78.5},krovak_k:{wkt1:"scale_factor",wkt2:"Scale factor on pseudo standard parallel",epsg:8819,unit:"scale",default:1}},We={WGS84:{baseGeogCrsId:4326,baseGeogCrsName:"WGS 84",ensemble:!0,ensembleId:6326,ensembleName:"World Geodetic System 1984 ensemble",datumName:"World Geodetic System 1984"},NAD83:{baseGeogCrsId:4269,baseGeogCrsName:"NAD83",datumName:"North American Datum 1983"},NAD27:{baseGeogCrsId:4267,baseGeogCrsName:"NAD27",datumName:"North American Datum 1927"},OSGB36:{baseGeogCrsId:4277,baseGeogCrsName:"OSGB36",datumName:"OSGB 1936"},potsdam:{baseGeogCrsId:4314,baseGeogCrsName:"DHDN",datumName:"Deutsches Hauptdreiecksnetz"},GGRS87:{baseGeogCrsId:4121,baseGeogCrsName:"GGRS87",datumName:"Greek Geodetic Reference System 1987"},hermannskogel:{baseGeogCrsId:4312,baseGeogCrsName:"MGI",datumName:"Militar-Geographische Institut"},ire65:{baseGeogCrsId:4299,baseGeogCrsName:"TM65",datumName:"Geodetic Datum of 1965"},nzgd49:{baseGeogCrsId:4272,baseGeogCrsName:"NZGD49",datumName:"New Zealand Geodetic Datum 1949"},carthage:{baseGeogCrsId:4223,baseGeogCrsName:"Carthage",datumName:"Carthage"}},He={WGS84:{epsg:7030,name:"WGS 84"},GRS80:{epsg:7019,name:"GRS 1980"},GRS67:{epsg:7036,name:"GRS 1967"},airy:{epsg:7001,name:"Airy 1830"},mod_airy:{epsg:7002,name:"Airy Modified 1849"},bessel:{epsg:7004,name:"Bessel 1841"},bess_nam:{epsg:7046,name:"Bessel Namibia (GLM)"},clrk66:{epsg:7008,name:"Clarke 1866"},clrk80:{epsg:7034,name:"Clarke 1880"},clrk80ign:{epsg:7011,name:"Clarke 1880 (IGN)"},intl:{epsg:7022,name:"International 1924"},WGS72:{epsg:7043,name:"WGS 72"},krass:{epsg:7024,name:"Krassowsky 1940"},aust_SA:{epsg:7003,name:"Australian National Spheroid"},evrstSS:{epsg:7016,name:"Everest 1830 (1967 Definition)"},helmert:{epsg:7020,name:"Helmert 1906"},hough:{epsg:7053,name:"Hough 1960"},engelis:{epsg:7054,name:"Engelis 1985"}},Ke={greenwich:{epsg:8901,name:"Greenwich",longitude:0},lisbon:{epsg:8902,name:"Lisbon",longitude:-9.0754862},paris:{epsg:8903,name:"Paris",longitude:2.5969213},bogota:{epsg:8904,name:"Bogota",longitude:-74.08091666666667},madrid:{epsg:8905,name:"Madrid",longitude:-3.687938888888889},rome:{epsg:8906,name:"Rome",longitude:12.45233333333333},bern:{epsg:8907,name:"Bern",longitude:7.439583333333333},jakarta:{epsg:8908,name:"Jakarta",longitude:106.8077194444444},ferro:{epsg:8909,name:"Ferro",longitude:-17.66666666666667},brussels:{epsg:8910,name:"Brussels",longitude:4.367975},stockholm:{epsg:8911,name:"Stockholm",longitude:18.05827777777778},athens:{epsg:8912,name:"Athens",longitude:23.7163375},oslo:{epsg:8913,name:"Oslo",longitude:10.72291666666667}},Ze=["ANGLEUNIT","degree",.0174532925199433],Je=["ANGLEUNIT","arc-second",484813681109536e-20],Xe=["LENGTHUNIT","metre",1],Ye=["SCALEUNIT","unity",1],Qe=["SCALEUNIT","parts per million",1e-6];function tn(t){var e=tt(t)?function(t){return nn(t,"GEOGCRS",!0)}(t):function(t){var e=Z(t.params,"sproj");if("somerc"===e)return function(t){var e=Z(t.params,"dlat_0")||0,n=Z(t.params,"dlon_0")||0,r=Z(t.params,"dk_0")||Z(t.params,"dk")||1,i=Z(t.params,"dx_0")||0,s=Z(t.params,"dy_0")||0,a=["CONVERSION","Swiss Oblique Mercator",["METHOD","Hotine Oblique Mercator (variant B)",["ID","EPSG",9815]],["PARAMETER","Latitude of projection centre",e,Ze,["ID","EPSG",8811]],["PARAMETER","Longitude of projection centre",n,Ze,["ID","EPSG",8812]],["PARAMETER","Azimuth of initial line",90,Ze,["ID","EPSG",8813]],["PARAMETER","Angle from Rectified to Skew Grid",90,Ze,["ID","EPSG",8814]],["PARAMETER","Scale factor on initial line",r,Ye,["ID","EPSG",8815]],["PARAMETER","Easting at projection centre",i,Xe,["ID","EPSG",8816]],["PARAMETER","Northing at projection centre",s,Xe,["ID","EPSG",8817]]];return rn(t,"Swiss Oblique Mercator",a)}(t);if("krovak"===e)return function(t){var e=Z(t.params,"dlat_0")||49.5,n=Z(t.params,"dlon_0")||24.8333333333333,r=Z(t.params,"dalpha")||30.2881397527778,i=Z(t.params,"dlat_ts")||78.5,s=Z(t.params,"dk_0")||Z(t.params,"dk")||1,a=Z(t.params,"dx_0")||0,o=Z(t.params,"dy_0")||0,l=["CONVERSION","Krovak",["METHOD","Krovak (North Orientated)",["ID","EPSG",1041]],["PARAMETER","Latitude of projection centre",e,Ze,["ID","EPSG",8811]],["PARAMETER","Longitude of origin",n,Ze,["ID","EPSG",8833]],["PARAMETER","Co-latitude of cone axis",r,Ze,["ID","EPSG",1036]],["PARAMETER","Latitude of pseudo standard parallel",i,Ze,["ID","EPSG",8818]],["PARAMETER","Scale factor on pseudo standard parallel",s,Ye,["ID","EPSG",8819]],["PARAMETER","False easting",a,Xe,["ID","EPSG",8806]],["PARAMETER","False northing",o,Xe,["ID","EPSG",8807]]];return rn(t,"Krovak",l)}(t);var n=ae(t).PROJCS,r=n.PROJECTION,i=Ve[r];i||Bt("wkt2_from_proj4: unsupported WKT1 projection: "+r);var s=en(t),a=function(t){if(!t)return Xe;var e=String(t[0]||"metre"),n=null==t[1]?1:t[1];/^meter$/i.test(e)&&(e="metre");return["LENGTHUNIT",e,n]}(n.UNIT),o=function(t,e,n){var r=["CONVERSION",t.name],i=["METHOD",t.name];t.epsg&&i.push(["ID","EPSG",t.epsg]);return r.push(i),t.params.forEach(function(t){var i=$e[t];i||Bt("wkt2_make: missing param def for "+t);var s,a=function(t,e){if(!t)return null;for(var n=0;n<t.length;n++){if(t[n][0]===e.wkt1)return t[n][1];if(e.wkt1_fallback&&t[n][0]===e.wkt1_fallback)return t[n][1]}return null}(e,i);if(null==a){if(i.skipIfAbsent)return;a=i.default}s="angle"===i.unit?Ze:"length"===i.unit?n:Ye;var o=["PARAMETER",i.wkt2,a,s];i.epsg&&o.push(["ID","EPSG",i.epsg]),r.push(o)}),r}(i,n.PARAMETER,a),l=["PROJCRS",n.NAME?n.NAME.replace(/_/g," "):"unknown",s,o];return l.push(["CS","Cartesian",2]),l.push(["AXIS","(E)","east",["ORDER",1],a]),l.push(["AXIS","(N)","north",["ORDER",2],a]),l}(t),n=function(t){var e=Z(t.params,"stowgs84");if(!e)return null;var n=String(e).split(",").map(function(t){return parseFloat(t)});for(;n.length<7;)n.push(0);return n.some(function(t){return 0!==t})?n:null}(t);return n?function(t,e){var n=["GEOGCRS","WGS 84",["ENSEMBLE","World Geodetic System 1984 ensemble",["MEMBER","World Geodetic System 1984"],["ELLIPSOID","WGS 84",6378137,298.257223563,Xe,["ID","EPSG",7030]],["ENSEMBLEACCURACY",2],["ID","EPSG",6326]],["PRIMEM","Greenwich",0,Ze,["ID","EPSG",8901]],["CS","ellipsoidal",2],["AXIS","geodetic latitude (Lat)","north",["ORDER",1],Ze],["AXIS","geodetic longitude (Lon)","east",["ORDER",2],Ze],["ID","EPSG",4326]],r=["ABRIDGEDTRANSFORMATION","Transformation to WGS 84",["METHOD","Position Vector transformation (geog2D domain)",["ID","EPSG",9606]],["PARAMETER","X-axis translation",e[0],Xe,["ID","EPSG",8605]],["PARAMETER","Y-axis translation",e[1],Xe,["ID","EPSG",8606]],["PARAMETER","Z-axis translation",e[2],Xe,["ID","EPSG",8607]],["PARAMETER","X-axis rotation",e[3],Je,["ID","EPSG",8608]],["PARAMETER","Y-axis rotation",e[4],Je,["ID","EPSG",8609]],["PARAMETER","Z-axis rotation",e[5],Je,["ID","EPSG",8610]],["PARAMETER","Scale difference",e[6],Qe,["ID","EPSG",8611]]];return["BOUNDCRS",["SOURCECRS",t],["TARGETCRS",n],r]}(e,n):e}function en(t){return nn(t,"BASEGEOGCRS",!1)}function nn(t,e,n){var r,i=Z(t.params,"sdatum"),s=i?We[i]:null,a=function(t){var e=Z(t.params,"sellps");if(!e){var n=Z(t.params,"sdatum"),r=n?at(n):null;e=r?r.ellipse_id:""}var i=e&&He[e],s=i?i.name:lt(e)?lt(e).name:"Unknown";s=s.replace(/_/g," ");var a,o=t.a;a=Z(t.params,"trf")?Z(t.params,"drf"):t.es?1/(1-Math.sqrt(1-t.es)):0;var l=["ELLIPSOID",s,o,a,Xe];i&&i.epsg&&l.push(["ID","EPSG",i.epsg]);return l}(t),o=function(t){var e=null;if(t)if(Ke[t])e=Ke[t];else{var n=parseFloat(t);isFinite(n)&&(Object.keys(Ke).forEach(function(t){var r=Ke[t];!e&&Math.abs(r.longitude-n)<1e-5&&(e=r)}),e||(e={epsg:null,name:"Reference meridian",longitude:n}))}e||(e=Ke.greenwich);var r=["PRIMEM",e.name,e.longitude,Ze];e.epsg&&r.push(["ID","EPSG",e.epsg]);return r}(Z(t.params,"spm"));r=s?s.baseGeogCrsName:(r=ne(t)).replace(/_/g," ");var l=function(t,e,n){if(e&&e.ensemble){var r=["ENSEMBLE",e.ensembleName];return r.push(["MEMBER",e.datumName]),r.push(n),r.push(["ENSEMBLEACCURACY",2]),e.ensembleId&&r.push(["ID","EPSG",e.ensembleId]),r}var i=Z(t.params,"sdatum"),s=e?e.datumName:i&&(at(i)||{}).name||"Unknown";return["DATUM",s=s.replace(/_/g," "),n]}(t,s,a),h=[e,r,l,o];return n&&(h.push(["CS","ellipsoidal",2]),h.push(["AXIS","geodetic latitude (Lat)","north",["ORDER",1],Ze]),h.push(["AXIS","geodetic longitude (Lon)","east",["ORDER",2],Ze])),s&&s.baseGeogCrsId&&h.push(["ID","EPSG",s.baseGeogCrsId]),h}function rn(t,e,n){var r=en(t);return["PROJCRS",e,r,n,["CS","Cartesian",2],["AXIS","(E)","east",["ORDER",1],Xe],["AXIS","(N)","north",["ORDER",2],Xe]]}var sn={Cartesian:1,ellipsoidal:1,spherical:1,vertical:1,polar:1,cylindrical:1,linear:1,parametric:1,affine:1,temporal:1,east:1,north:1,south:1,west:1,up:1,down:1,geocentricX:1,geocentricY:1,geocentricZ:1,clockwise:1,counterClockwise:1,columnPositive:1,columnNegative:1,rowPositive:1,rowNegative:1,displayRight:1,displayLeft:1,displayUp:1,displayDown:1,forward:1,aft:1,port:1,starboard:1,future:1,past:1,awayFrom:1,towards:1,unspecified:1,exact:1,wraparound:1,cellCenter:1,cellCorner:1};function an(t,e){var n=(e=e||{}).indent||" ";return on(t,!!e.pretty?0:-1,n)}function on(t,e,n){if(!Array.isArray(t))return function(t){if("number"==typeof t)return function(t){isFinite(t)||Bt("wkt2_stringify: non-finite number");return String(t)}(t);if("string"==typeof t)return sn[t]?t:'"'+t.replace(/"/g,'""')+'"';return null==t?'""':String(t)}(t);var r=t[0],i=t.slice(1),s=i.map(function(t){return on(t,e>=0?e+1:-1,n)});if(e<0)return r+"["+s.join(",")+"]";if(!i.some(function(t){return Array.isArray(t)}))return r+"["+s.join(",")+"]";ln(n,e);for(var a=ln(n,e+1),o=[],l=[],h=!1,c=0;c<i.length;c++)Array.isArray(i[c])?(h=!0,l.push(s[c])):h?l.push(s[c]):o.push(s[c]);return r+"["+(o.length?o.join(",")+",":"")+"\n"+a+l.join(",\n"+a)+"]"}function ln(t,e){for(var n="",r=0;r<e;r++)n+=t;return n}function hn(t){var e=function(t){var e,n=[],r=0,i=t.length;for(;r<i;)if(" "===(e=t.charAt(r))||"\t"===e||"\n"===e||"\r"===e)r++;else if("["===e||"("===e)n.push({type:cn.OPEN,value:e,pos:r}),r++;else if("]"===e||")"===e)n.push({type:cn.CLOSE,value:e,pos:r}),r++;else if(","===e)n.push({type:cn.COMMA,value:e,pos:r}),r++;else if('"'===e){var s=r,a="";for(r++;r<i;)if('"'===(e=t.charAt(r))){if(!(r+1<i&&'"'===t.charAt(r+1))){r++;break}a+='"',r+=2}else a+=e,r++;n.push({type:cn.STRING,value:a,pos:s})}else if("-"===e||"+"===e||"."===e||e>="0"&&e<="9"){var o=r;for("-"!==e&&"+"!==e||r++;r<i&&t.charAt(r)>="0"&&t.charAt(r)<="9";)r++;if(r<i&&"."===t.charAt(r))for(r++;r<i&&t.charAt(r)>="0"&&t.charAt(r)<="9";)r++;if(r<i&&("e"===t.charAt(r)||"E"===t.charAt(r)))for(++r<i&&("+"===t.charAt(r)||"-"===t.charAt(r))&&r++;r<i&&t.charAt(r)>="0"&&t.charAt(r)<="9";)r++;var l=parseFloat(t.substring(o,r));isNaN(l)&&Bt("WKT2 parse error: bad number at "+o+": "+t.substring(o,r)),n.push({type:cn.NUMBER,value:l,pos:o})}else if(e>="A"&&e<="Z"||e>="a"&&e<="z"||"_"===e){for(var h=r;r<i;){var c=t.charAt(r);if(!(c>="A"&&c<="Z"||c>="a"&&c<="z"||c>="0"&&c<="9"||"_"===c))break;r++}n.push({type:cn.IDENT,value:t.substring(h,r),pos:h})}else Bt("WKT2 parse error: unexpected character "+JSON.stringify(e)+" at "+r);return n}(t),n={i:0},r=_n(e,n);return n.i<e.length&&Bt("WKT2 parse error: unexpected trailing content at token "+n.i),r}var cn={STRING:"STRING",NUMBER:"NUMBER",IDENT:"IDENT",OPEN:"OPEN",CLOSE:"CLOSE",COMMA:"COMMA"};function un(t,e){return t[e.i]}function pn(t,e,n){var r=t[e.i];return r||Bt("WKT2 parse error: unexpected end of input (wanted "+n+")"),n&&r.type!==n&&Bt("WKT2 parse error: expected "+n+" but got "+r.type+" ("+JSON.stringify(r.value)+") at token "+e.i),e.i++,r}function _n(t,e){var n=[pn(t,e,cn.IDENT).value.toUpperCase()];if(pn(t,e,cn.OPEN),un(t,e)&&un(t,e).type!==cn.CLOSE)for(n.push(dn(t,e));un(t,e)&&un(t,e).type===cn.COMMA;)pn(t,e,cn.COMMA),n.push(dn(t,e));return pn(t,e,cn.CLOSE),n}function dn(t,e){var n=un(t,e);switch(n||Bt("WKT2 parse error: unexpected end of input reading arg"),n.type){case cn.STRING:case cn.NUMBER:return e.i++,n.value;case cn.IDENT:var r=t[e.i+1];return r&&r.type===cn.OPEN?_n(t,e):(e.i++,n.value);default:Bt("WKT2 parse error: unexpected token "+n.type+" at position "+n.pos)}}function fn(t,e){if(!Array.isArray(t))return null;e=e.toUpperCase();for(var n=1;n<t.length;n++)if(Array.isArray(t[n])&&t[n][0]===e)return t[n];return null}function mn(t,e){var n=[];if(!Array.isArray(t))return n;e=e.toUpperCase();for(var r=1;r<t.length;r++)Array.isArray(t[r])&&t[r][0]===e&&n.push(t[r]);return n}function gn(t){if(!Array.isArray(t))return null;for(var e=1;e<t.length;e++)if("string"==typeof t[e]||"number"==typeof t[e])return t[e];return null}function yn(t){var e=fn(t,"ID");if(!e)return null;var n=e[2];if("number"==typeof n)return n;if("string"==typeof n){var r=parseFloat(n);return isNaN(r)?null:r}return null}var vn={9807:{wkt1:"Transverse_Mercator"},9808:{wkt1:"Transverse_Mercator_South_Orientated"},9804:{wkt1:"Mercator_1SP"},9805:{wkt1:"Mercator_2SP"},1024:{wkt1:"Mercator_Auxiliary_Sphere",special:"aux_sphere"},1026:{wkt1:"Mercator_1SP"},9801:{wkt1:"Lambert_Conformal_Conic_1SP"},9802:{wkt1:"Lambert_Conformal_Conic_2SP"},9803:{wkt1:"Lambert_Conformal_Conic_2SP"},9822:{wkt1:"Albers_Conic_Equal_Area"},9820:{wkt1:"Lambert_Azimuthal_Equal_Area"},1027:{wkt1:"Lambert_Azimuthal_Equal_Area"},9809:{wkt1:"Oblique_Stereographic"},9810:{wkt1:"Polar_Stereographic"},9829:{wkt1:"Polar_Stereographic"},9830:{wkt1:"Polar_Stereographic"},9819:{wkt1:"Krovak",special:"krovak"},1041:{wkt1:"Krovak",special:"krovak_north"},9812:{wkt1:"Hotine_Oblique_Mercator"},9815:{special:"somerc"},9825:{wkt1:"Plate_Carree"},1028:{wkt1:"Equidistant_Cylindrical"},1029:{wkt1:"Equidistant_Cylindrical"},9834:{wkt1:"Cylindrical_Equal_Area"},9835:{wkt1:"Cylindrical_Equal_Area"},1119:{wkt1:"Equidistant_Conic"},1125:{wkt1:"Azimuthal_Equidistant"},9832:{wkt1:"Azimuthal_Equidistant"},9838:{wkt1:"Vertical_Near_Side_Perspective"},9839:{wkt1:"Vertical_Near_Side_Perspective"},9811:{wkt1:"New_Zealand_Map_Grid"}},wn={transversemercator:"Transverse_Mercator",mercator1sp:"Mercator_1SP",mercator2sp:"Mercator_2SP",mercatorvarianta:"Mercator_1SP",mercatorvariantb:"Mercator_2SP",popularvisualisationpseudomercator:"Mercator_Auxiliary_Sphere",lambertconicconformal1sp:"Lambert_Conformal_Conic_1SP",lambertconicconformal2sp:"Lambert_Conformal_Conic_2SP",lambertconicconformal:"Lambert_Conformal_Conic",lambertazimuthalequalarea:"Lambert_Azimuthal_Equal_Area",albersequalarea:"Albers_Conic_Equal_Area",obliquestereographic:"Oblique_Stereographic",polarstereographicvarianta:"Polar_Stereographic",polarstereographicvariantb:"Polar_Stereographic",polarstereographicvariantc:"Polar_Stereographic",polarstereographic:"Polar_Stereographic",hotineobliquemercator:"Hotine_Oblique_Mercator",hotineobliquemercatorvarianta:"Hotine_Oblique_Mercator",hotineobliquemercatorvariantb:"Oblique_Mercator",obliquemercator:"Oblique_Mercator",krovak:"Krovak",krovaknorthorientated:"Krovak",newzealandmapgrid:"New_Zealand_Map_Grid",cassinisoldner:"Cassini_Soldner",cassini:"Cassini_Soldner",equidistantconic:"Equidistant_Conic",equidistantcylindrical:"Equidistant_Cylindrical",mollweide:"Mollweide",sinusoidal:"Sinusoidal",robinson:"Robinson",vandergrinten:"VanDerGrinten",vandergrinteni:"VanDerGrinten",winkeltripel:"Winkel_Tripel",aitoff:"Aitoff",bonne:"Bonne",lambertcylindricalequalarea:"Cylindrical_Equal_Area",gallstereographic:"Gall_Stereographic",millercylindrical:"Miller_Cylindrical",loximuthal:"Loximuthal",orthographic:"Orthographic",americanpolyconic:"Polyconic",polyconic:"Polyconic",gnomonic:"Gnomonic",eckerti:"Eckert_I",eckertii:"Eckert_II",eckertiii:"Eckert_III",eckertiv:"Eckert_IV",eckertv:"Eckert_V",eckertvi:"Eckert_VI",wagneri:"Wagner_I",wagnerii:"Wagner_II",wagneriii:"Wagner_III",wagneriv:"Wagner_IV",wagnerv:"Wagner_V",wagnervi:"Wagner_VI",wagnervii:"Wagner_VII",winkeli:"Winkel_I",winkelii:"Winkel_II",twopointequidistant:"Two_Point_Equidistant",hotineobliquemercatortwopointnaturalorigin:"Hotine_Oblique_Mercator_Two_Point_Natural_Origin",verticalperspective:"Vertical_Near_Side_Perspective",verticalnearsideperspective:"Vertical_Near_Side_Perspective"},Sn={8801:"latitude_of_origin",8802:"central_meridian",8805:"scale_factor",8806:"false_easting",8807:"false_northing",8821:"latitude_of_origin",8822:"central_meridian",8823:"standard_parallel_1",8824:"standard_parallel_2",8826:"false_easting",8827:"false_northing",8811:"latitude_of_center",8812:"longitude_of_center",8813:"azimuth",8814:"rectified_grid_angle",8815:"scale_factor",8816:"false_easting",8817:"false_northing",8818:"pseudo_standard_parallel_1",8819:"scale_factor",8832:"standard_parallel_1",8833:"central_meridian",1036:"azimuth",1051:"azimuth",8840:"height"},xn={latitudeofnaturalorigin:"latitude_of_origin",longitudeofnaturalorigin:"central_meridian",scalefactoratnaturalorigin:"scale_factor",falseeasting:"false_easting",falsenorthing:"false_northing",latitudeoffalseorigin:"latitude_of_origin",longitudeoffalseorigin:"central_meridian",latitudeof1ststandardparallel:"standard_parallel_1",latitudeof2ndstandardparallel:"standard_parallel_2",eastingatfalseorigin:"false_easting",northingatfalseorigin:"false_northing",latitudeofprojectioncentre:"latitude_of_center",longitudeofprojectioncentre:"longitude_of_center",azimuthofinitialline:"azimuth",azimuthatprojectioncentre:"azimuth",anglefromrectifiedtoskewgrid:"rectified_grid_angle",scalefactoratprojectioncentre:"scale_factor",eastingatprojectioncentre:"false_easting",northingatprojectioncentre:"false_northing",latitudeofpseudostandardparallel:"pseudo_standard_parallel_1",scalefactoronpseudostandardparallel:"scale_factor",latitudeofstandardparallel:"standard_parallel_1",longitudeoforigin:"central_meridian",colatitudeofconeaxis:"azimuth",viewpointheight:"height",latitudeof1stpoint:"latitude_of_point_1",longitudeof1stpoint:"longitude_of_point_1",latitudeof2ndpoint:"latitude_of_point_2",longitudeof2ndpoint:"longitude_of_point_2"};function bn(t){return(t||"").replace(/[^A-Za-z0-9]/g,"").toLowerCase()}function Cn(t){if(!t)return null;var e,n=(e=fn(t,"ID"))&&e[1]||null,r=yn(t);if(null!=r&&(!n||/^EPSG$/i.test(n))&&vn[r])return vn[r];var i=bn(gn(t));return wn[i]?{wkt1:wn[i]}:null}function En(t){Array.isArray(t)||Bt("WKT2 normalize error: not a parsed node");var e=t[0];switch(e){case"PROJCRS":case"PROJECTEDCRS":return{PROJCS:Pn(t)};case"GEOGCRS":case"GEODCRS":case"GEODETICCRS":case"GEOGRAPHICCRS":return{GEOGCS:kn(t)};case"BOUNDCRS":var n=fn(t,"SOURCECRS");n||Bt("BOUNDCRS missing SOURCECRS");for(var r=null,i=1;i<n.length;i++)if(Array.isArray(n[i])){r=n[i];break}r||Bt("BOUNDCRS SOURCECRS has no inner CRS");var s=En(r),a=fn(t,"ABRIDGEDTRANSFORMATION");return a&&function(t,e){var n=fn(e,"METHOD");Cn(n);var r=mn(e,"PARAMETER"),i=t.PROJCS?t.PROJCS.GEOGCS:t.GEOGCS;if(!i)return;var s=yn(n);if(9601===s)return;for(var a={},o=0;o<r.length;o++){for(var l=yn(r[o]),h=null,c=1;c<r[o].length;c++)if("number"==typeof r[o][c]){h=r[o][c];break}null!=l&&null!=h&&(a[l]=h)}for(var u=[8605,8606,8607,8608,8609,8610,8611],p=[],_=0,d=0;d<u.length;d++)u[d]in a?(p.push(a[u[d]]),_++):p.push(0);_>=3&&(9607===s&&(p[3]=-p[3],p[4]=-p[4],p[5]=-p[5]),i.DATUM.TOWGS84=p)}(s,a),s;case"COMPOUNDCRS":var o=function(t){for(var e={PROJCRS:1,PROJECTEDCRS:1,GEOGCRS:1,GEODCRS:1,GEODETICCRS:1,GEOGRAPHICCRS:1,BOUNDCRS:1},n=1;n<t.length;n++){var r=t[n];if(Array.isArray(r)&&e[r[0]])return r}for(var i=1;i<t.length;i++){var s=An(t[i],e);if(s)return s}return null}(t);return o||Bt("COMPOUNDCRS missing supported horizontal component"),En(o);case"VERTCRS":case"VERTICALCRS":Bt("VERTCRS not supported");case"ENGCRS":case"ENGINEERINGCRS":Bt("ENGINEERINGCRS not supported");default:Bt("Unsupported WKT2 root element: "+e)}}function An(t,e){if(!Array.isArray(t))return null;if(e[t[0]])return t;for(var n=1;n<t.length;n++)if(Array.isArray(t[n])){var r=An(t[n],e);if(r)return r}return null}function kn(t,e){var n=gn(t),r=fn(t,"DATUM")||fn(t,"GEODETICDATUM")||fn(t,"ENSEMBLE"),i=fn(t,"PRIMEM")||fn(t,"PRIMEMERIDIAN");return{NAME:n||"Unknown",DATUM:In(r),PRIMEM:Dn(i),UNIT:["degree",.0174532925199433]}}var Mn={worldgeodeticsystem1984:"WGS_1984",worldgeodeticsystem1984ensemble:"WGS_1984"};function In(t){t||Bt("WKT2 normalize: missing DATUM");var e=gn(t);"ENSEMBLE"===t[0]&&/\s+ensemble$/i.test(e)&&(e=e.replace(/\s+ensemble$/i,""));var n=bn(e);Mn[n]&&(e=Mn[n]);var r=fn(t,"ELLIPSOID")||fn(t,"SPHEROID");r||Bt("WKT2 normalize: DATUM/ENSEMBLE missing ELLIPSOID");var i=function(t){var e=gn(t),n=bn(e);Tn[n]&&(e=Tn[n]);for(var r=null,i=null,s=0,a=1;a<t.length;a++)"number"==typeof t[a]&&(1===++s?r=t[a]:2===s&&(i=t[a]));null==r&&Bt("WKT2 normalize: ELLIPSOID missing semi-major axis");var o=fn(t,"LENGTHUNIT");if(o){var l=Ln(o);l&&1!==l&&(r*=l)}return[e||"Unknown",r,null==i?0:i]}(r);return{NAME:e||"Unknown",SPHEROID:i}}var Tn={clarke1880ign:"Clarke 1880 (IGN).",clarke1858:"Clarke 1858",krassowsky1940:"Krasovsky 1940"};function Dn(t){if(!t)return["Greenwich",0];for(var e=gn(t),n=0,r=1;r<t.length;r++)if("number"==typeof t[r]){n=t[r];break}var i=fn(t,"ANGLEUNIT")||fn(t,"UNIT");if(i){var s=Ln(i);if(s){var a=.0174532925199433;Math.abs(s-a)>1e-15&&(n=n*s/a)}}return[e||"Greenwich",n]}function Pn(t){var e=gn(t),n=fn(t,"BASEGEOGCRS")||fn(t,"BASEGEODCRS");n||Bt("PROJCRS missing BASEGEOGCRS");var r=fn(t,"CONVERSION");r||Bt("PROJCRS missing CONVERSION");var i=fn(r,"METHOD")||fn(r,"PROJECTION"),s=Cn(i);s||Bt("Unsupported WKT2 projection method: "+(gn(i)||"[unknown]")),fn(t,"CS");for(var a=mn(t,"AXIS"),o=function(t,e){var n=fn(t,"LENGTHUNIT");!n&&e.length>0&&(n=fn(e[0],"LENGTHUNIT"));if(!n)return["metre",1];var r=gn(n)||"metre";return[r,Ln(n)||1]}(t,a),l=mn(r,"PARAMETER"),h=[],c=0;c<l.length;c++){var u=Nn(l[c]);u&&h.push(u)}var p={NAME:e,GEOGCS:kn(n),PROJECTION:[s.wkt1||"Unknown"],PARAMETER:h,UNIT:o};if(i){var _=yn(i);if(9804===_||1026===_)for(var d=h.length-1;d>=0;d--)"latitude_of_origin"===h[d][0]&&0===h[d][1]&&h.splice(d,1)}return"aux_sphere"===s.special?p._direct_proj4=function(t){var e=Gn(t,"central_meridian"),n=Gn(t,"false_easting"),r=Gn(t,"false_northing"),i=["+proj=merc"];i.push("+a=6378137"),e&&i.push("+lon_0="+e);n&&i.push("+x_0="+n);r&&i.push("+y_0="+r);return i.push("+no_defs"),i.join(" ")}(p):"somerc"===s.special?p._direct_proj4=function(t){var e=["+proj=somerc"],n=Gn(t,"latitude_of_center"),r=Gn(t,"longitude_of_center"),i=Gn(t,"scale_factor"),s=Gn(t,"false_easting"),a=Gn(t,"false_northing");null!=n&&e.push("+lat_0="+n);null!=r&&e.push("+lon_0="+r);null!=i&&e.push("+k_0="+i);null!=s&&e.push("+x_0="+s);null!=a&&e.push("+y_0="+a);return e.push(On(t.GEOGCS)),e.push("+no_defs"),e.filter(function(t){return!!t}).join(" ")}(p):"krovak"!==s.special&&"krovak_north"!==s.special||(p._direct_proj4=function(t){var e=["+proj=krovak"],n=Gn(t,"latitude_of_center"),r=Gn(t,"central_meridian")||Gn(t,"longitude_of_center"),i=Gn(t,"azimuth"),s=Gn(t,"scale_factor"),a=Gn(t,"false_easting"),o=Gn(t,"false_northing");null!=n&&e.push("+lat_0="+n);null!=r&&e.push("+lon_0="+r);null!=i&&e.push("+alpha="+i);null!=s&&e.push("+k="+s);a&&e.push("+x_0="+a);o&&e.push("+y_0="+o);return e.push(On(t.GEOGCS)),e.push("+no_defs"),e.filter(function(t){return!!t}).join(" ")}(p,s.special)),a.length>0&&(p.AXIS=a.map(function(t){return[gn(t),Rn(t)]})),p}function Nn(t){var e=function(t){var e=yn(t);if(null!=e&&Sn[e])return Sn[e];var n=bn(gn(t));return xn[n]?xn[n]:null}(t);if(!e)return Vt("WKT2: unknown parameter: "+gn(t)),null;for(var n=null,r=1;r<t.length;r++)if("number"==typeof t[r]){n=t[r];break}null==n&&Bt("WKT2: parameter missing numeric value: "+e);var i=fn(t,"ANGLEUNIT");if(i){var s=Ln(i),a=.0174532925199433;s&&Math.abs(s-a)>1e-15&&(n=n*s/a)}return[e,n]}function Rn(t){for(var e=2;e<t.length;e++)if("string"==typeof t[e])return t[e];return"unknown"}function Ln(t){for(var e=1;e<t.length;e++)if("number"==typeof t[e])return t[e];return null}function Gn(t,e){for(var n=0;n<t.PARAMETER.length;n++)if(t.PARAMETER[n][0]===e)return t.PARAMETER[n][1]}function On(t){return Ht(t)}function Fn(t){var e=En(hn(t));return e.PROJCS?e.PROJCS._direct_proj4?function(t,e){var n=e.GEOGCS;n&&n.DATUM&&n.DATUM.TOWGS84&&-1===t.indexOf("+towgs84")&&(t=t.replace(/\+no_defs$/,"+towgs84="+n.DATUM.TOWGS84.join(",")+" +no_defs"));return t}(e.PROJCS._direct_proj4,e.PROJCS):Jt(e.PROJCS):e.GEOGCS?"+proj=longlat "+Ht(e.GEOGCS):void Bt("WKT2 to Proj4: unsupported CRS type")}function Un(t,e){return("string"==typeof t||t instanceof String)&&(t=ft(String(t))),an(tn(t),e)}function qn(t){t&&"object"==typeof t||Bt("projjson_to_proj4: missing or invalid PROJJSON object");var e=t.type||"";return"GeographicCRS"===e||"GeodeticCRS"===e?jn(t,"GEOGCRS",!0):"ProjectedCRS"===e?function(t){var e=t.name||"Unknown",n=jn(t.base_crs||{},"BASEGEOGCRS",!1),r=function(t){var e=t.name||"Unknown conversion",n=["CONVERSION",e];return n.push(Bn(t.method||{})),(t.parameters||[]).forEach(function(t){n.push(Vn(t))}),n}(t.conversion||{}),i=t.coordinate_system||{},s=function(t){for(var e=t.axis||t.axes||[],n=0;n<e.length;n++){var r=Hn(e[n].unit,"length");if(r&&"LENGTHUNIT"===r[0])return r}return null}(i)||["LENGTHUNIT","metre",1],a=["PROJCRS",e,n,r];a.push(["CS","Cartesian",2]),a.push($n(i,0,"(E)","east",s)),a.push($n(i,1,"(N)","north",s));var o=Wn(t.id);o&&a.push(o);return a}(t):"BoundCRS"===e?function(t){var e=qn(t.source_crs||{}),n=qn(t.target_crs||{}),r=function(t){var e=t.name||"Transformation",n=["ABRIDGEDTRANSFORMATION",e],r=t.method||{};return n.push(Bn(r)),(t.parameters||[]).forEach(function(t){n.push(Vn(t))}),n}(t.transformation||{});return["BOUNDCRS",["SOURCECRS",e],["TARGETCRS",n],r]}(t):void Bt("projjson_to_proj4: unsupported PROJJSON type: "+e)}function jn(t,e,n){var r=t.name||"Unknown",i=function(t){var e=t.datum_ensemble||t.datumEnsemble,n=t.datum;if(e){var r=["ENSEMBLE",e.name||"Unknown ensemble"];(e.members||[]).forEach(function(t){r.push(["MEMBER",t.name||"Unknown"])}),r.push(zn(e.ellipsoid||{})),null!=e.accuracy&&r.push(["ENSEMBLEACCURACY",parseFloat(e.accuracy)]);var i=Wn(e.id);return i&&r.push(i),r}if(n){var s=["DATUM",n.name||"Unknown",zn(n.ellipsoid||{})],a=Wn(n.id);return a&&s.push(a),s}return["DATUM","Unknown",zn({name:"WGS 84",semi_major_axis:6378137,inverse_flattening:298.257223563})]}(t),s=function(t){var e=Hn((t=t||{name:"Greenwich",longitude:0}).unit,"angle")||["ANGLEUNIT","degree",.0174532925199433],n=["PRIMEM",t.name||"Greenwich",null==t.longitude?0:t.longitude,e],r=Wn(t.id);r&&n.push(r);return n}(t.prime_meridian),a=[e||"GEOGCRS",r,i,s];if(n){var o=t.coordinate_system||{},l=function(t){for(var e=t.axis||t.axes||[],n=0;n<e.length;n++){var r=Hn(e[n].unit,"angle");if(r&&"ANGLEUNIT"===r[0])return r}return null}(o)||["ANGLEUNIT","degree",.0174532925199433];a.push(["CS","ellipsoidal",2]),a.push($n(o,0,"geodetic latitude (Lat)","north",l)),a.push($n(o,1,"geodetic longitude (Lon)","east",l))}var h=Wn(t.id);return h&&a.push(h),a}function zn(t){var e=["ELLIPSOID",t.name||"Unknown",null!=t.semi_major_axis?t.semi_major_axis:6378137,null!=t.inverse_flattening?t.inverse_flattening:298.257223563,Hn(t.unit,"length")||["LENGTHUNIT","metre",1]],n=Wn(t.id);return n&&e.push(n),e}function Bn(t){var e=["METHOD",t.name||"Unknown method"],n=Wn(t.id);return n&&e.push(n),e}function Vn(t){var e="scale";t.unit&&"object"==typeof t.unit?"AngularUnit"===t.unit.type?e="angle":"LinearUnit"===t.unit.type?e="length":"ScaleUnit"===t.unit.type&&(e="scale"):e="scale";var n=Hn(t.unit,e),r=["PARAMETER",t.name||"Unknown parameter",null==t.value?0:t.value,n||["SCALEUNIT","unity",1]],i=Wn(t.id);return i&&r.push(i),r}function $n(t,e,n,r,i){var s,a=(t.axis||t.axes||[])[e]||{};return["AXIS",a.name||n,a.direction||r,["ORDER",e+1],Hn(a.unit,(s=i)&&Array.isArray(s)?"ANGLEUNIT"===s[0]?"angle":"SCALEUNIT"===s[0]?"scale":"length":"length")||i]}function Wn(t){return t&&t.authority&&null!=t.code?["ID",t.authority,t.code]:null}function Hn(t,e){var n="angle"===e?"ANGLEUNIT":"scale"===e?"SCALEUNIT":"LENGTHUNIT";return t?"string"==typeof t?/^degree$/i.test(t)?["ANGLEUNIT","degree",.0174532925199433]:/^met(er|re)$/i.test(t)?["LENGTHUNIT","metre",1]:/^unity$/i.test(t)?["SCALEUNIT","unity",1]:[n,t,1]:[n,t.name||t.abbreviation||("length"===e?"metre":"angle"===e?"degree":"unity"),null==t.conversion_factor?1:t.conversion_factor]:"angle"===e?["ANGLEUNIT","degree",.0174532925199433]:"scale"===e?["SCALEUNIT","unity",1]:["LENGTHUNIT","metre",1]}function Kn(t){switch(Array.isArray(t)||Bt("projjson_from_proj4: invalid WKT2 tree"),t[0]){case"PROJCRS":return function(t){var e={type:"ProjectedCRS",name:gn(t)||"Unknown",base_crs:Zn(fn(t,"BASEGEOGCRS")||fn(t,"BASEGEODCRS")),conversion:Xn(fn(t,"CONVERSION"))},n=Qn(t);n&&(e.coordinate_system=n);var r=er(t);r&&(e.id=r);return e}(t);case"GEOGCRS":case"GEODCRS":case"GEOGRAPHICCRS":case"GEODETICCRS":case"BASEGEOGCRS":case"BASEGEODCRS":return Zn(t);case"BOUNDCRS":return function(t){var e=fn(t,"SOURCECRS"),n=fn(t,"TARGETCRS"),r=fn(t,"ABRIDGEDTRANSFORMATION"),i=null,s=null;if(e)for(var a=1;a<e.length;a++)if(Array.isArray(e[a])){i=e[a];break}if(n)for(var o=1;o<n.length;o++)if(Array.isArray(n[o])){s=n[o];break}return{type:"BoundCRS",source_crs:i?Kn(i):null,target_crs:s?Kn(s):null,transformation:Jn(r)}}(t);default:Bt("projjson_from_proj4: unsupported WKT2 root: "+t[0])}}function Zn(t){t||Bt("projjson_from_proj4: missing GEOGCRS node");var e={type:"GeographicCRS",name:gn(t)||"Unknown"},n=fn(t,"ENSEMBLE"),r=fn(t,"DATUM")||fn(t,"GEODETICDATUM");n?e.datum_ensemble=function(t){var e={name:gn(t)||"Unknown ensemble"};e.members=mn(t,"MEMBER").map(function(t){return{name:gn(t)}});var n=fn(t,"ELLIPSOID")||fn(t,"SPHEROID");n&&(e.ellipsoid=Yn(n));var r=fn(t,"ENSEMBLEACCURACY");r&&(e.accuracy=String(nr(r)));var i=er(t);i&&(e.id=i);return e}(n):r&&(e.datum=function(t){var e={type:"GeodeticReferenceFrame",name:gn(t)||"Unknown"},n=fn(t,"ELLIPSOID")||fn(t,"SPHEROID");n&&(e.ellipsoid=Yn(n));var r=er(t);r&&(e.id=r);return e}(r));var i=fn(t,"PRIMEM")||fn(t,"PRIMEMERIDIAN");i&&(e.prime_meridian=function(t){var e={name:gn(t)||"Greenwich",longitude:nr(t)},n=tr(fn(t,"ANGLEUNIT"));n&&(e.unit=n);var r=er(t);r&&(e.id=r);return e}(i));var s=Qn(t);s&&(e.coordinate_system=s);var a=er(t);return a&&(e.id=a),e}function Jn(t){if(!t)return null;var e={name:gn(t)||"Transformation"},n=fn(t,"METHOD");if(n){e.method={name:gn(n)||"Unknown method"};var r=er(n);r&&(e.method.id=r)}var i=mn(t,"PARAMETER");return e.parameters=i.map(function(t){var e={name:gn(t),value:nr(t)},n=tr(fn(t,"ANGLEUNIT")||fn(t,"LENGTHUNIT")||fn(t,"SCALEUNIT"));n&&(e.unit=n);var r=er(t);return r&&(e.id=r),e}),e}function Xn(t){if(!t)return null;var e={name:gn(t)||"Conversion"},n=fn(t,"METHOD");e.method={name:n?gn(n):"Unknown method"};var r=n?er(n):null;r&&(e.method.id=r);var i=mn(t,"PARAMETER");return e.parameters=i.map(function(t){var e={name:gn(t),value:nr(t)},n=tr(fn(t,"ANGLEUNIT")||fn(t,"LENGTHUNIT")||fn(t,"SCALEUNIT"));n&&(e.unit=n);var r=er(t);return r&&(e.id=r),e}),e}function Yn(t){for(var e=[],n=1;n<t.length;n++)"number"==typeof t[n]&&e.push(t[n]);var r={name:gn(t)||"Unknown",semi_major_axis:e.length>0?e[0]:6378137,inverse_flattening:e.length>1?e[1]:298.257223563},i=tr(fn(t,"LENGTHUNIT"));i&&(r.unit=i);var s=er(t);return s&&(r.id=s),r}function Qn(t){var e=fn(t,"CS"),n=mn(t,"AXIS");return e||0!==n.length?{subtype:e&&e[1]?String(e[1]).toLowerCase():"ellipsoidal",axis:n.map(function(t){var e={name:gn(t),direction:Rn(t)},n=tr(fn(t,"ANGLEUNIT")||fn(t,"LENGTHUNIT")||fn(t,"SCALEUNIT"));return n&&("degree"===n.name&&.0174532925199433===n.conversion_factor?e.unit="degree":"metre"===n.name&&1===n.conversion_factor?e.unit="metre":"unity"===n.name&&1===n.conversion_factor?e.unit="unity":e.unit=n),e})}:null}function tr(t){if(!t)return null;var e="ANGLEUNIT"===t[0]?"AngularUnit":"SCALEUNIT"===t[0]?"ScaleUnit":"LinearUnit";return{type:e,name:t[1]||("LinearUnit"===e?"metre":"AngularUnit"===e?"degree":"unity"),conversion_factor:null==t[2]?1:t[2]}}function er(t){var e=fn(t,"ID");return!e||e.length<3?null:{authority:e[1],code:e[2]}}function nr(t){if(!t)return null;for(var e=1;e<t.length;e++)if("number"==typeof t[e])return t[e];return null}var rr,ir,sr={};function ar(t,e,n){var r;return e>=1e-7?n*(t/(1-(r=e*t)*r)-.5/e*d((1-r)/(1+r))):t+t}function or(t,e,n){return e/u(1-n*t*t)}function lr(t,e,r){var a,l,h,p,_,m,g,y,v,S,x,b,C,E;t.fwd=function(e,n){var r,a=e.lam;(r=h-(g?l*ar(i(e.phi),t.e,t.one_es):_*i(e.phi)))<0&&U();r=p*u(r),n.x=r*i(a*=l),n.y=m-r*s(a)},t.inv=function(e,r){var u=e.x,y=m-e.y,v=f(u,y);0!=v?(l<0&&(v=-v,u=-u,y=-y),r.phi=v/p,g?(r.phi=(h-r.phi*r.phi)/l,n(a-n(r.phi))>1e-7?(r.phi=function(t,e,r){var a,l,h,c,u,p,_=15,f=1e-7,m=1e-10;if(a=o(.5*t),e<f)return a;p=_;do{a+=u=.5*(c=1-(h=e*(l=i(a)))*h)*c/s(a)*(t/r-l/c+.5/e*d((1-h)/(1+h)))}while(n(u)>m&&--p);return p?a:w}(r.phi,t.e,t.one_es))==w&&q():r.phi=r.phi<0?-k:k):n(r.phi=(h-r.phi*r.phi)/_)<=1?r.phi=o(r.phi):r.phi=r.phi<0?-k:k,r.lam=c(u,y)/l):(r.lam=0,r.phi=l>0?k:-k)},n(e+r)<N&&z(-21),l=v=i(e),y=s(e),S=n(e-r)>=N,(g=t.es>0)?(hr(t.es),E=or(v,y,t.es),C=ar(v,t.e,t.one_es),S&&(b=or(v=i(r),y=s(r),t.es),x=ar(v,t.e,t.one_es),l=(E*E-b*b)/(x-C)),a=1-.5*t.one_es*d((1-t.e)/(1+t.e))/t.e,m=(p=1/l)*u((h=E*E+l*C)-l*ar(i(t.phi0),t.e,t.one_es))):(S&&(l=.5*(l+i(r))),m=(p=1/l)*u((h=y*y+(_=l+l)*v)-_*i(t.phi0)))}function hr(t){var e,n=.046875,r=.01953125,i=.01068115234375,s=[];return s[0]=1-t*(.25+t*(n+t*(r+t*i))),s[1]=t*(.75-t*(n+t*(r+t*i))),s[2]=(e=t*t)*(.46875-t*(.013020833333333334+.007120768229166667*t)),s[3]=(e*=t)*(.3645833333333333-.005696614583333333*t),s[4]=e*t*.3076171875,s}function cr(t,e,n,r){return n*=e,e*=e,r[0]*t-n*(r[1]+e*(r[2]+e*(r[3]+e*r[4])))}function ur(t,e,r){var a,o,l,h=1/(1-e);l=t;for(var c=10;c>0;--c)if(o=1-e*(a=i(l))*a,l-=o=(cr(l,a,s(l),r)-t)*(o*u(o))*h,n(o)<1e-11)return l;return F(R),l}function pr(t){var e=n(t);return e>=1?(e>1.00000000000001&&F(-19),t<0?-k:k):o(t)}function _r(t){var e=n(t);return e>=1?(e>1.00000000000001&&F(-19),t<0?S:0):l(t)}function dr(t){return t<=0?0:u(t)}function fr(t,e){return n(t)<1e-50&&n(e)<1e-50?0:c(t,e)}function mr(t){var e=t.opaque||{mode:0};t.inv=function(t,r){var a,o,h,c,u,_,d,f,m,g,y,v,w,x,b,C,E,A=1e-12,M=0;if(n(t.x)<A&&n(t.y)<A)return r.phi=0,void(r.lam=0);r.phi=t.y,r.lam=t.x;do{a=0;do{for(v=i(.5*r.lam),b=s(.5*r.lam),w=i(r.phi),h=1-(o=(x=s(r.phi))*b)*o,c=2*(o=l(o)/p(h,1.5))*h*x*v,u=o*h*w,_=2*(v*b*w*x/h-o*w*v),d=x*x*v*v/h+o*x*b*w*w,f=w*w*b/h+o*v*v*x,m=.5*(w*x*v/h-o*w*x*x*v*b),e.mode&&(c=.5*(c+r.lam*e.cosphi1),u=.5*(u+r.phi),_*=.5,d=.5*(d+e.cosphi1),f=.5*(f+1),m*=.5),c-=t.x,y=((u-=t.y)*_-c*f)/(g=_*m-f*d),g=(c*m-u*d)/g;y>S;)y-=S;for(;y<-S;)y+=S;r.phi-=g,r.lam-=y}while((n(g)>A||n(y)>A)&&a++<10);r.phi>k&&(r.phi-=2*(r.phi-k)),r.phi<-k&&(r.phi-=2*(r.phi+k)),n(n(r.phi)-k)<A&&!e.mode&&(r.lam=0),(o=l(s(r.phi)*s(h=.5*r.lam)))?(C=2*o*s(r.phi)*i(h)*(E=1/i(o)),E*=o*i(r.phi)):C=E=0,e.mode&&(C=.5*(C+r.lam*e.cosphi1),E=.5*(E+r.phi))}while((n(t.x-C)>A||n(t.y-E)>A)&&M++<20)},t.fwd=function(t,n){var r,a;(a=l(s(t.phi)*s(r=.5*t.lam)))?(n.x=2*a*s(t.phi)*i(r)*(n.y=1/i(a)),n.y*=a*i(t.phi)):n.x=n.y=0;e.mode&&(n.x=.5*(n.x+t.lam*e.cosphi1),n.y=.5*(n.y+t.phi))},t.es=0}function gr(t,e,r){t.es=0,t.fwd=function(t,s){var a,o,l=2.4674011002723395;s.y=e?k*i(t.phi):t.phi,(a=n(t.lam))>=1e-10?(r&&a>=k?s.x=u(l-t.phi*t.phi+1e-10)+a-k:(o=.5*(l/a+a),s.x=a-o+u(o*o-s.y*s.y)),t.lam<0&&(s.x=-s.x)):s.x=0}}function yr(t){var e,n=[];return n[0]=.3333333333333333*t,e=t*t,n[0]+=.17222222222222222*e,n[1]=.06388888888888888*e,e*=t,n[0]+=.10257936507936508*e,n[1]+=.0664021164021164*e,n[2]=.01677689594356261*e,n}function vr(t,e){var n=t+t;return t+e[0]*i(n)+e[1]*i(n+n)+e[2]*i(n+n+n)}function wr(t,e){t.es=0,t.fwd=function(t,n){n.y=e.C_y*t.phi,n.x=e.C_x*t.lam*(e.A+dr(1-e.B*t.phi*t.phi))},t.inv=function(t,n){n.phi=t.y/e.C_y,n.lam=t.x/(e.C_x*(e.A+dr(1-e.B*n.phi*n.phi)))}}function Sr(t){var e,r,o,l,p,_,y=[],v=[],S=[],x=[];function b(t,e){for(var n,r=2*s(2*e),a=t.length-1,o=t[a],l=0;--a>=0;)n=r*o-l+t[a],l=o,o=n;return e+n*i(2*e)}function C(t,e,n){for(var r,a,o=i(e),l=s(e),h=m(n),c=g(n),u=2*l*c,p=-2*o*h,_=t.length-1,d=t[_],f=0,y=0,v=0;--_>=0;)r=y,a=f,d=u*(y=d)-r-p*(f=v)+t[_],v=p*y-a+u*f;return[(u=o*c)*d-(p=l*h)*v,u*v+p*d]}t.es<=0&&z(-34),p=l=(o=t.es/(1+u(1-t.es)))/(2-o),y[0]=l*(2+l*(-2/3+l*(l*(116/45+l*(26/45+l*(-2854/675)))-2))),v[0]=l*(l*(2/3+l*(4/3+l*(-82/45+l*(32/45+l*(4642/4725)))))-2),p*=l,y[1]=p*(7/3+l*(l*(-227/45+l*(2704/315+l*(2323/945)))-1.6)),v[1]=p*(5/3+l*(-16/15+l*(-13/9+l*(904/315+l*(-1522/945))))),p*=l,y[2]=p*(56/15+l*(-136/35+l*(-1262/105+l*(73814/2835)))),v[2]=p*(-26/15+l*(34/21+l*(1.6+l*(-12686/2835)))),p*=l,y[3]=p*(4279/630+l*(-332/35+l*(-399572/14175))),v[3]=p*(1237/630+l*(l*(-24832/14175)-2.4)),p*=l,y[4]=p*(4174/315+l*(-144838/6237)),v[4]=p*(-734/315+l*(109598/31185)),p*=l,y[5]=p*(601676/22275),v[5]=p*(444337/155925),p=l*l,e=t.k0/(1+l)*(1+p*(1/4+p*(1/64+p/256))),S[0]=l*(l*(2/3+l*(-37/96+l*(1/360+l*(81/512+l*(-96199/604800)))))-.5),x[0]=l*(.5+l*(-2/3+l*(5/16+l*(41/180+l*(-127/288+l*(7891/37800)))))),S[1]=p*(-1/48+l*(-1/15+l*(437/1440+l*(-46/105+l*(1118711/3870720))))),x[1]=p*(13/48+l*(l*(557/1440+l*(281/630+l*(-1983433/1935360)))-.6)),p*=l,S[2]=p*(-17/480+l*(37/840+l*(209/4480+l*(-5569/90720)))),x[2]=p*(61/240+l*(-103/140+l*(15061/26880+l*(167603/181440)))),p*=l,S[3]=p*(-4397/161280+l*(11/504+l*(830251/7257600))),x[3]=p*(49561/161280+l*(-179/168+l*(6601661/7257600))),p*=l,S[4]=p*(-4583/161280+l*(108847/3991680)),x[4]=p*(34729/80640+l*(-3418889/1995840)),p*=l,S[5]=p*(-20648693/638668800),x[5]=.6650675310896665*p,_=b(v,t.phi0),r=-e*(_+function(t,e){var n,r=2*s(e),a=t.length-1,o=t[a],l=0;for(;--a>=0;)n=r*o-l+t[a],l=o,o=n;return i(e)*n}(x,2*_)),t.fwd=function(t,o){var l,h,u,p,_,m=t.phi,g=t.lam;m=b(v,m),l=i(m),h=s(m),p=i(g),u=s(g),m=c(l,u*h),g=c(p*h,f(l,h*u)),g=function(t){var e=n(t);return e=function(t){var e=1+t,n=e-1;return 0===n?t:t*d(e)/n}(e*(1+e/(f(1,e)+1))),t<0?-e:e}(a(g)),_=C(x,2*m,2*g),m+=_[0],g+=_[1],n(g)<=2.623395162778?(o.y=e*m+r,o.x=e*g):o.x=o.y=w},t.inv=function(t,a){var o,l,u,p,_,d=t.y,g=t.x;d=(d-r)/e,n(g/=e)<=2.623395162778?(d+=(_=C(S,2*d,2*g))[0],g+=_[1],g=h(m(g)),o=i(d),l=s(d),p=i(g),u=s(g),g=c(p,u*l),d=c(o*u,f(p,u*l)),a.phi=b(y,d),a.lam=g):a.phi=a.lam=w}}function xr(t){var e;t.es?(e=hr(t.es),t.fwd=function(n,r){var a,o;r.y=cr(n.phi,a=i(n.phi),o=s(n.phi),e),r.x=n.lam*o/u(1-t.es*a*a)},t.inv=function(r,a){var o=n(a.phi=ur(r.y,t.es,e));o<k?(o=i(a.phi),a.lam=r.x*u(1-t.es*o*o)/s(a.phi)):o-N<k?a.lam=0:q()}):br(t,0,1)}function br(t,e,r){var a,o;a=(o=u((e+1)/r))/(e+1),t.es=0,t.fwd=function(t,l){var h,c,u;if(e){for(h=r*i(t.phi),u=8;u&&(t.phi-=c=(e*t.phi+i(t.phi)-h)/(e+s(t.phi)),!(n(c)<1e-7));--u);u||U()}else t.phi=1!=r?pr(r*i(t.phi)):t.phi;l.x=a*t.lam*(e+s(t.phi)),l.y=o*t.phi},t.inv=function(t,n){t.y/=o,n.phi=e?pr((e*t.y+i(t.y))/r):1!=r?pr(i(t.y)/r):t.y,n.lam=t.x/(a*(e+s(t.y)))}}function Cr(t){Ar(t,Er(t,k))}function Er(t,e){var n=i(e),r=e+e,s=u(I*n/(r+i(r)));return{C_x:2*s/S,C_y:s/n,C_p:r+i(r)}}function Ar(t,e){t.fwd=function(t,r){var a,o,l;for(a=e.C_p*i(t.phi),l=10;l&&(t.phi-=o=(t.phi+i(t.phi)-a)/(1+s(t.phi)),!(n(o)<1e-7));--l);l?t.phi*=.5:t.phi=t.phi<0?-k:k;r.x=e.C_x*t.lam*s(t.phi),r.y=e.C_y*i(t.phi)},t.inv=function(t,r){r.phi=pr(t.y/e.C_y),r.lam=t.x/(e.C_x*s(r.phi)),n(r.lam)-S<N?(r.phi+=r.phi,r.phi=pr((r.phi+i(r.phi))/e.C_p)):r.lam=r.phi=w},t.es=0}function kr(t,e){var s,a,l,h,c,_=[[0,-1],[1,0]],d=[[-1,0],[0,-1]],f=[[0,1],[-1,0]],m=[[[1,0],[0,1]],_,d,f,f,d,_],g=1e-15;function x(t,e){var s=t.lam,a=t.phi,l=o(2/3);if(n(a)<=l)e.x=s,e.y=3*S/8*i(a);else{var h,c=u(3*(1-n(i(a)))),p=r(2*s/S+2);p>=4&&(p=3),h=-3*A+k*p,e.x=h+(s-h)*c,e.y=C(a)*A*(2-c)}}function b(t,e){var i=t.x,s=t.y,a=A;if(n(s)<=a)e.lam=i,e.phi=o(8*s/(3*S));else if(n(s)<k){var l,h,c=r(2*i/S+2);c>=4&&(c=3),l=-3*A+k*c,h=2-4*n(s)/S,e.lam=l+(i-l)/h,e.phi=C(s)*o(1-p(h,2)/3)}else e.lam=-S,e.phi=C(s)*k}function C(t){return t>0?1:t<0?-1:0}function E(t){switch(t){case 0:return 0;case 1:return 1;case 2:return 2;case 3:return 3;case-1:return 4;case-2:return 5;case-3:return 6}return 0}function M(t,e){return function(t,e,n){var r,i,s,a,o,l=0,h=t.length;for(o=0;o<h;o++)if(e==t[o][0]&&n==t[o][1])return!0;for(r=t[0][0],i=t[0][1],o=1;o<h;o++)s=t[o%h][0],a=t[o%h][1],n>y(i,a)&&n<=v(i,a)&&e<=v(r,s)&&i!=a&&(r==s||e<=(n-i)*(s-r)/(a-i)+r)&&l++,r=s,i=a;return l%2!=0}(c,t,e)}function I(t,e,r){if(r)return vr(e,h);var s=ar(i(e),t.e,1-t.es)/l;return n(s)>1&&(s=C(s)),o(s)}function T(t,e,n,r){var i,s,a,o,l,h,c=0,u=function(t,e,n,r,i){var s,a={};if(a.x=t,a.y=e,i){if(e>A)a.region="north",a.x=-3*A+n*k,a.y=k,t-=n*k;else{if(!(e<-A))return a.region="equatorial",a.cn=0,a;a.region="south",a.x=-3*A+r*k,a.y=-k,t-=r*k}"north"==a.region?a.cn=e>=-t-A-g&&e<t+5*A-g?(n+1)%4:e>-t-A+g&&e>=t+5*A-g?(n+2)%4:e<=-t-A+g&&e>t+5*A+g?(n+3)%4:n:"south"==a.region&&(a.cn=e<=t+A+g&&e>-t-5*A+g?(r+1)%4:e<t+A-g&&e<=-t-5*A+g?(r+2)%4:e>=t+A-g&&e<-t-5*A-g?(r+3)%4:r)}else{if(e>A)a.region="north",s=k;else{if(!(e<-A))return a.region="equatorial",a.cn=0,a;a.region="south",s=-k}t<-k?(a.cn=0,a.x=-3*A,a.y=s):t>=-k&&t<0?(a.cn=1,a.x=-A,a.y=s):t>=0&&t<k?(a.cn=2,a.x=A,a.y=s):(a.cn=3,a.x=3*A,a.y=s)}return a}(t.x,t.y,e,n,r);if("equatorial"==u.region)return t.x=u.x,void(t.y=u.y);i=[t.x,t.y],s=[u.x,u.y],r?"north"==u.region?(c=e,h=m[E(-1*(u.cn-c))]):(c=n,h=m[E(u.cn-c)]):"north"==u.region?(c=e,h=m[E(u.cn-c)]):(c=n,h=m[E(-1*(u.cn-c))]),o=function(t,e){return[t[0]-e[0],t[1]-e[1]]}(i,s),l=function(t,e){var n,r,i=[0,0];for(n=0;n<2;n++)for(r=0;r<2;r++)i[n]+=t[n][r]*e[r];return i}(h,o),a=function(t,e){return[t[0]+e[0],t[1]+e[1]]}(l,[-3*A+(r?u.cn:0)*k,k]),t.x=a[0],t.y=a[1]}e?(s=Z(t.params,"inorth_square"),a=Z(t.params,"isouth_square"),(s<0||s>3)&&z(-47),(a<0||a>3)&&z(-47),c=[[-S-g,A+g],[s*k-S-g,A+g],[s*k-S-g,3*A+g],[(s+1)*k-S+g,3*A+g],[(s+1)*k-S+g,A+g],[S+g,A+g],[S+g,-A-g],[(a+1)*k-S+g,-A-g],[(a+1)*k-S+g,-3*A-g],[a*k-S-g,-3*A-g],[a*k-S-g,-A-g],[-S-g,-A-g]],0!=t.es?(h=yr(t.es),l=ar(1,t.e,t.one_es),t.a=t.a*u(.5*l),t.ra=1/t.a,t.fwd=function(e,n){return e.phi=I(t,e.phi,0),x(e,n),T(n,s,a,0)},t.inv=function(e,n){if(!M(e.x,e.y))return n.lam=w,n.phi=w,void F(-15);T(e,s,a,1),b(e,n),n.phi=I(t,n.phi,1)}):(t.fwd=function(t,e){x(t,e),T(e,s,a,0)},t.inv=function(t,e){if(!M(t.x,t.y))return e.lam=w,e.phi=w,void F(-15);T(t,s,a,1),b(t,e)})):(c=[[-S-g,A],[-3*A,k+g],[-k,A+g],[-A,k+g],[0,A+g],[A,k+g],[k,A+g],[3*A,k+g],[S+g,A],[S+g,-A],[3*A,-k-g],[k,-A-g],[A,-k-g],[0,-A-g],[-A,-k-g],[-k,-A-g],[-3*A,-k-g],[-S-g,-A]],0!=t.es?(h=yr(t.es),l=ar(1,t.e,t.one_es),t.a=t.a*u(.5*l),t.ra=1/t.a,t.fwd=function(e,n){e.phi=I(t,e.phi,0),x(e,n)},t.inv=function(e,n){if(!M(e.x,e.y))return n.lam=w,n.phi=w,void F(-15);b(e,n),n.phi=I(t,n.phi,1)}):(t.fwd=function(t,e){x(t,e)},t.inv=function(t,e){if(!M(t.x,t.y))return e.lam=w,e.phi=w,void F(-15);b(t,e)}))}function Mr(t){t.x0=0,t.y0=0,t.is_latlong=!0,t.fwd=function(e,n){n.x=e.lam/t.a,n.y=e.phi/t.a},t.inv=function(e,n){n.lam=e.x*t.a,n.phi=e.y*t.a}}function Ir(t,e,n){return e*=n,a(.5*(k-t))/p((1-e)/(1+e),.5*n)}function Tr(t,e){var r,s,a=.5*e,o=k-2*h(t),l=15;do{r=e*i(o),o+=s=k-2*h(t*p((1-r)/(1+r),a))-o}while(n(s)>1e-10&&--l);return l<=0&&F(-18),o}function Dr(t,e){var n,r,i,s=e.length-1;for(r=e[s][0],i=e[s][1];--s>=0;)n=r,r=e[s][0]+t.r*n-t.i*i,i=e[s][1]+t.r*i+t.i*n;return{r:t.r*r-t.i*i,i:t.r*i+t.i*r}}function Pr(t,e,n){var r,i,s,a,o,l=!0,h=e.length-1;for(i=a=e[h][0],r=s=e[h][1];--h>=0;)l?l=!1:(a=i+t.r*(o=a)-t.i*s,s=r+t.r*s+t.i*o),i=e[h][0]+t.r*(o=i)-t.i*r,r=e[h][1]+t.r*r+t.i*o;return n.r=i+t.r*a-t.i*s,n.i=r+t.r*s+t.i*a,{r:t.r*i-t.i*r,i:t.r*r+t.i*i}}function Nr(t,e){var r,o,l,u,_=1e-12;0!=t.es?(r=t.e*i(t.phi0),o=2*h(a(.5*(k+t.phi0))*p((1-r)/(1+r),.5*t.e))-k):o=t.phi0,u=i(o),l=s(o),t.inv=function(r,o){var d,m,g,y,v,S,x,b={},C={},E={},A=0,M=0,I=0,T=0;for(b.r=r.x,b.i=r.y,d=20;d&&((m=Pr(b,e,C)).r-=r.x,m.i-=r.y,g=C.r*C.r+C.i*C.i,E.r=-(m.r*C.r+m.i*C.i)/g,E.i=-(m.i*C.r-m.r*C.i)/g,b.r+=E.r,b.i+=E.i,!(n(E.r)+n(E.i)<=_));--d);if(d){if(A=f(b.r,b.i),y=2*h(.5*A),M=i(y),I=s(y),o.lam=t.lam0,n(A)<=_)return o.lam=0,void(o.phi=t.phi0);for(T=v=pr(I*u+b.i*M*l/A),d=20;d&&(S=t.e*i(T),T+=x=2*h(a(.5*(k+v))*p((1+S)/(1-S),.5*t.e))-k-T,!(n(x)<=_));--d);}d?(o.phi=T,o.lam=c(b.r*M,A*l*I-b.i*u*M)):o.lam=o.phi=w},t.fwd=function(n,r){var o,c,_,d,f,m,g,y={};o=i(n.lam),c=s(n.lam),_=t.e*i(n.phi),d=2*h(a(.5*(k+n.phi))*p((1-_)/(1+_),.5*t.e))-k,f=i(d),m=s(d),g=2/(1+u*f+l*m*c),y.r=g*m*o,y.i=g*(l*f-u*m*c),y=Dr(y,e),r.x=y.r,r.y=y.i}}function Rr(t,e,r,a){var l,h,p,_,d,m,g,y,v,w,S,x,b=!isNaN(r)&&!isNaN(a);e<=0&&z(-30),b&&(v=s(a),w=i(a),x=s(r),S=i(r)),n(n(t.phi0)-k)<N?l=t.phi0<0?1:0:n(t.phi0)<N?l=2:(l=3,h=i(t.phi0),p=s(t.phi0)),m=e/t.a,d=1/(_=1+m),g=(_+1)*(y=1/m),t.fwd=function(t,e){var n,r,a,o,c;switch(a=i(t.phi),r=s(t.phi),n=s(t.lam),l){case 3:e.y=h*a+p*r*n;break;case 2:e.y=r*n;break;case 1:e.y=-a;break;case 0:e.y=a}e.y<d&&U();switch(e.y=m/(_-e.y),e.x=e.y*r*i(t.lam),l){case 3:e.y*=p*a-h*r*n;break;case 2:e.y*=a;break;case 0:n=-n;case 1:e.y*=r*n}b&&(c=1/((o=e.y*v+e.x*w)*S*y+x),e.x=(e.x*v-e.y*w)*x*c,e.y=o*c)},t.inv=function(e,r){var s,a,d,y,C,E;b&&(E=1/(m-e.y*S),y=m*e.x*E,C=m*e.y*x*E,e.x=y*v+C*w,e.y=C*v-y*w);s=f(e.x,e.y),(d=1-s*s*g)<0&&q();if(d=(_-u(d))/(m/s+s/m),a=u(1-d*d),n(s)<=N)r.lam=0,r.phi=t.phi0;else{switch(l){case 3:r.phi=o(a*h+e.y*d*p/s),e.y=(a-h*i(r.phi))*s,e.x*=d*p;break;case 2:r.phi=o(e.y*d/s),e.y=a*s,e.x*=d;break;case 0:r.phi=o(a),e.y=-e.y;break;case 1:r.phi=-o(a)}r.lam=c(e.x,e.y)}},t.es=0}function Lr(t,e){var n=.79788456,r=.1013211836*(e?2:4);t.es=0,t.fwd=function(t,e){e.x=n*t.lam*(1-r*t.phi*t.phi),e.y=n*t.phi},t.inv=function(t,e){e.phi=t.y/n,e.lam=t.x/(n*(1-r*e.phi*e.phi))}}function Gr(t,e,n){t.es=0,t.fwd=function(t,r){t.phi=pr(.883883476*i(t.phi)),r.x=e*t.lam*s(t.phi),r.x/=s(t.phi*=.333333333333333),r.y=n*i(t.phi)},t.inv=function(t,r){r.phi=pr(t.y/n),r.lam=t.x*s(r.phi)/e,r.phi*=3,r.lam/=s(r.phi),r.phi=pr(1.13137085*i(r.phi))}}function Or(t,e){var n=e?1.5:2,r=e?.5:1,i=1.01346,s=1.2158542;t.es=0,t.fwd=function(t,e){e.x=i*t.lam*(n-r*u(1+s*t.phi*t.phi)),e.y=i*t.phi},t.inv=function(t,e){e.phi=t.y/i,e.lam=t.x/(i*(n-r*u(1+s*e.phi*e.phi)))}}function Fr(t,e){var r,s,a,o,l,h=1.732050807568877;e?(a=.44329,o=.80404,r=6,s=5.61125,l=3):(a=1.01346,o=.9191,r=4,s=2.147143718212938,l=2),t.es=0,t.fwd=function(t,e){var c,p,_,f;for(c=s*i(t.phi),t.phi*=1.10265779,f=10;f&&(p=u(1+t.phi*t.phi),t.phi-=_=((r-p)*t.phi-d(t.phi+p)-c)/(r-2*p),!(n(_)<1e-10));--f);f||(t.phi=c<0?-h:h);e.x=a*t.lam*(l-u(1+t.phi*t.phi)),e.y=o*t.phi},t.inv=function(t,e){var n;e.phi=t.y/o,n=u(1+e.phi*e.phi),e.lam=t.x/(a*(l-n)),e.phi=pr(((r-n)*e.phi-d(e.phi+n))/s)}}function Ur(t){return function(e){!function(t,e){var r,o,l,p,_,d,m,g,y,v,w=1e-10;Z(t.params,"tlat_1")&&Z(t.params,"tlat_2")?(l=Z(t.params,"rlat_1"),p=Z(t.params,"rlat_2"),g=.5*(p+l),(n(r=.5*(p-l))<w||n(g)<w)&&z(-42)):z(-41);switch(e){case"TISSOT":_=i(g),o=s(r),m=u(((d=_/o+o/_)-2*i(t.phi0))/_);break;case"MURD1":d=i(r)/(r*a(g))+g,m=d-t.phi0,_=i(g);break;case"MURD2":d=(o=u(s(r)))/a(g),m=d+a(g-t.phi0),_=i(g)*o;break;case"MURD3":d=r/(a(g)*a(r))+g,m=d-t.phi0,_=i(g)*i(r)*a(r)/(r*r);break;case"EULER":_=i(g)*i(r)/r,d=(r*=.5)/(a(r)*a(g))+g,m=d-t.phi0;break;case"PCONIC":_=i(g),v=s(r),y=1/a(g),n(r=t.phi0-g)-w>=k&&z(-43),m=v*(y-a(r));break;case"VITK1":_=(o=a(r))*i(g)/r,d=r/(o*a(g))+g,m=d-t.phi0}function S(t,n){var r;switch(e){case"MURD2":r=d+a(g-t.phi);break;case"PCONIC":r=v*(y-a(t.phi-g));break;default:r=d-t.phi}n.x=r*i(t.lam*=_),n.y=m-r*s(t.lam)}function x(t,n){var r;switch(r=f(t.x,t.y=m-t.y),_<0&&(r=-r,t.x=-t.x,t.y=-t.y),n.lam=c(t.x,t.y)/_,e){case"PCONIC":n.phi=h(y-r/v)+g;break;case"MURD2":n.phi=g-h(r-d);break;default:n.phi=d-r}}t.inv=x,t.fwd=S,t.es=0}(e,t)}}function qr(t,e){var r,l,_,d,m,g,y,v,w=1e-10;if(v=n((l=n(t.phi0))-k)<w?t.phi0<0?0:1:l>w?2:3,e=n(e),t.es){switch(v){case 1:case 0:n(e-k)<w?y=2*t.k0/u(p(1+t.e,1+t.e)*p(1-t.e,1-t.e)):(y=s(e)/Ir(e,l=i(e),t.e),l*=t.e,y/=u(1-l*l));break;case 3:case 2:l=i(t.phi0),r=2*h(S(t.phi0,l,t.e))-k,l*=t.e,y=2*t.k0*s(t.phi0)/u(1-l*l),m=i(r),g=s(r)}t.fwd=function(e,n){var r,a,o,l,c,u=0,p=0;r=s(e.lam),a=i(e.lam),c=i(e.phi),(2==v||3==v)&&(u=i(o=2*h(S(e.phi,c,t.e))-k),p=s(o));switch(v){case 2:l=y/(g*(1+m*u+g*p*r)),n.y=l*(g*u-m*p*r),n.x=l*p;break;case 3:l=y/(1+p*r),n.y=l*u,n.x=l*p;break;case 0:e.phi=-e.phi,r=-r,c=-c;case 1:n.x=y*Ir(e.phi,c,t.e),n.y=-n.x*r}n.x=n.x*a},t.inv=function(e,r){r.phi;var l,u,_,d,w=0,S=0,x=0,b=0;switch(_=f(e.x,e.y),v){case 2:case 3:l=s(w=2*c(_*g,y)),u=i(w),S=o(0==_?l*m:l*m+e.y*u*g/_),w=a(.5*(k+S)),e.x*=u,e.y=_*g*l-e.y*m*u,b=k,x=.5*t.e;break;case 1:e.y=-e.y;case 0:S=k-2*h(w=-_/y),b=-k,x=-.5*t.e}for(d=0;d<8;d++,S=r.phi)if(u=t.e*i(S),r.phi=2*h(w*p((1+u)/(1-u),x))-b,n(S-r.phi)<1e-10)return 0==v&&(r.phi=-r.phi),void(r.lam=0==e.x&&0==e.y?0:c(e.x,e.y));q()}}else{switch(v){case 2:_=i(t.phi0),d=s(t.phi0);case 3:y=2*t.k0;break;case 0:case 1:y=n(e-k)>=w?s(e)/a(A-.5*e):2*t.k0}t.fwd=function(t,e){var r=t.phi,o=i(r),l=s(r),h=s(t.lam),c=i(t.lam);switch(v){case 3:case 2:e.y=3==v?1+l*h:1+_*o+d*l*h,e.y<=w&&U(),e.x=(e.y=y/e.y)*l*c,e.y*=3==v?o:d*o-_*l*h;break;case 1:h=-h,r=-r;case 0:n(r-k)<1e-8&&U(),e.x=c*(e.y=y*a(A+.5*r)),e.y*=h}},t.inv=function(e,r){var a,l,u,p;switch(u=i(a=2*h((l=f(e.x,e.y))/y)),p=s(a),r.lam=0,v){case 3:n(l)<=w?r.phi=0:r.phi=o(e.y*u/l),0==p&&0==e.x||(r.lam=c(e.x*u,p*l));break;case 2:n(l)<=w?r.phi=t.phi0:r.phi=o(p*_+e.y*u*d/l),0==(a=p-_*i(r.phi))&&0==e.x||(r.lam=c(e.x*u*d,a*l));break;case 1:e.y=-e.y;case 0:n(l)<=w?r.phi=t.phi0:r.phi=o(0==v?-p:p),r.lam=0==e.x&&0==e.y?0:c(e.x,e.y)}}}function S(t,e,n){return e*=n,a(.5*(k+t))*p((1-e)/(1+e),.5*n)}}function jr(t,e){return p((1-t)/(1+t),e)}function zr(t,e,n,r){var o=n/e,l=e,c=1/n;t.inv=function(t,e){var n;t.y/=l,n=s(e.phi=r?h(t.y):pr(t.y)),e.phi/=c,e.lam=t.x/(o*s(e.phi)),r?e.lam/=n*n:e.lam*=n},t.fwd=function(t,e){var n;e.x=o*t.lam*s(t.phi),e.y=l,t.phi*=c,n=s(t.phi),r?(e.x*=n*n,e.y*=a(t.phi)):(e.x/=n,e.y*=i(t.phi))},t.es=0}function Br(t){var e,r,a,h=1e-10,p=.5,f=.16666666666666666,m=.08333333333333333,g=.05,y=.03333333333333333,v=.023809523809523808,w=.017857142857142856;t.es?((a=hr(t.es))||e_error_0(),r=cr(t.phi0,i(t.phi0),s(t.phi0),a),e=t.es/(1-t.es),t.fwd=function(o,l){var c,p,_,d,S,x;if(o.lam<-k||o.lam>k)return void F(-14);c=i(o.phi),p=s(o.phi),_=n(p)>h?c/p:0,_*=_,d=p*o.lam,S=d*d,d/=u(1-t.es*c*c),x=e*p*p,l.x=t.k0*d*(1+f*S*(1-_+x+g*S*(5+_*(_-18)+x*(14-58*_)+v*S*(61+_*(_*(179-_)-479))))),l.y=t.k0*(cr(o.phi,c,p,a)-r+c*d*o.lam*.5*(1+m*S*(5-_+x*(9+4*x)+y*S*(61+_*(_-58)+x*(270-330*_)+w*S*(1385+_*(_*(543-_)-3111))))))},t.inv=function(o,l){var h,c,_,d,S,x,b;l.phi=ur(r+o.y/t.k0,t.es,a),n(l.phi)>=k?(l.phi=o.y<0?-k:k,l.lam=0):(x=i(l.phi),_=s(l.phi),b=n(_)>1e-10?x/_:0,h=e*_*_,d=o.x*u(c=1-t.es*x*x)/t.k0,c*=b,b*=b,S=d*d,l.phi-=c*S/(1-t.es)*p*(1-S*m*(5+b*(3-9*h)+h*(1-4*h)-S*y*(61+b*(90-252*h+45*b)+46*h-S*w*(1385+b*(3633+b*(4095+1575*b)))))),l.lam=d*(1-S*f*(1+2*b+h-S*g*(5+b*(28+24*b+8*h)+6*h-S*v*(61+b*(662+b*(1320+720*b))))))/_)}):(e=t.k0,r=.5*e,t.fwd=function(a,o){var c,p;if(a.lam<-k||a.lam>k)return void F(-14);p=s(a.phi),c=p*i(a.lam),n(n(c)-1)<=h&&U();o.x=r*d((1+c)/(1-c)),o.y=p*s(a.lam)/u(1-c*c),(c=n(o.y))>=1?c-1>h?U():o.y=0:o.y=l(o.y);a.phi<0&&(o.y=-o.y);o.y=e*(o.y-t.phi0)},t.inv=function(n,r){var i=_(n.x/e),a=.5*(i-1/i);i=s(t.phi0+n.y/e),r.phi=o(u((1-i*i)/(1+a*a))),n.y<0&&-r.phi+t.phi0<0&&(r.phi=-r.phi);r.lam=a||i?c(a,i):0})}function Vr(t,e){var n=.8773826753,r=1.139753528477/e;t.es=0,t.fwd=function(t,a){var o=pr(e*i(t.phi));a.x=n*t.lam*s(o),a.y=r*o},t.inv=function(t,a){t.y/=r,a.phi=pr(i(t.y)/e),a.lam=t.x/(n*s(t.y))}}function $r(t,e){t.fwd=function(t,r){var i,s,a,o;a=n(T*t.phi),o=(o=1-a*a)<0?0:u(o);n(t.lam)<1e-10?(r.x=0,r.y=S*(t.phi<0?-a:a)/(1+o)):(s=.5*n(S/t.lam-t.lam/S),e?(i=a/(1+o),r.x=S*(u(s*s+1-i*i)-s),r.y=S*i):(i=(o*u(1+s*s)-s*o*o)/(1+s*s*a*a),r.x=S*i,r.y=S*u(1-i*(i+2*s)+1e-10)),t.lam<0&&(r.x=-r.x),t.phi<0&&(r.y=-r.y))},t.es=0}sr.Constants={},sr.Math={},sr.Accumulator={},(rr=sr.Constants).WGS84={a:6378137,f:1/298.257223563},rr.version={major:1,minor:48,patch:0},rr.version_string="1.48",(ir=sr.Math).digits=53,ir.epsilon=Math.pow(.5,ir.digits-1),ir.degree=Math.PI/180,ir.sq=function(t){return t*t},ir.hypot=function(t,e){var n,r;return t=Math.abs(t),e=Math.abs(e),n=Math.max(t,e),r=Math.min(t,e)/(n||1),n*Math.sqrt(1+r*r)},ir.cbrt=function(t){var e=Math.pow(Math.abs(t),1/3);return t<0?-e:e},ir.log1p=function(t){var e=1+t,n=e-1;return 0===n?t:t*Math.log(e)/n},ir.atanh=function(t){var e=Math.abs(t);return e=ir.log1p(2*e/(1-e))/2,t<0?-e:e},ir.copysign=function(t,e){return Math.abs(t)*(e<0||0===e&&1/e<0?-1:1)},ir.sum=function(t,e){var n=t+e,r=n-e,i=n-r;return{s:n,t:-((r-=t)+(i-=e))}},ir.polyval=function(t,e,n,r){for(var i=t<0?0:e[n++];--t>=0;)i=i*r+e[n++];return i},ir.AngRound=function(t){if(0===t)return t;var e=1/16,n=Math.abs(t);return n=n<e?e-(e-n):n,t<0?-n:n},ir.AngNormalize=function(t){return(t%=360)<=-180?t+360:t<=180?t:t-360},ir.LatFix=function(t){return Math.abs(t)>90?Number.NaN:t},ir.AngDiff=function(t,e){var n=ir.sum(ir.AngNormalize(-t),ir.AngNormalize(e)),r=ir.AngNormalize(n.s),i=n.t;return ir.sum(180===r&&i>0?-180:r,i)},ir.sincosd=function(t){var e,n,r,i,s,a;switch(e=t%360,e-=90*(n=Math.floor(e/90+.5)),e*=this.degree,r=Math.sin(e),i=Math.cos(e),3&n){case 0:s=r,a=i;break;case 1:s=i,a=-r;break;case 2:s=-r,a=-i;break;default:s=-i,a=r}return t&&(s+=0,a+=0),{s:s,c:a}},ir.atan2d=function(t,e){var n,r,i=0;switch(Math.abs(t)>Math.abs(e)&&(n=e,e=t,t=n,i=2),e<0&&(e=-e,++i),r=Math.atan2(t,e)/this.degree,i){case 1:r=(t>=0?180:-180)-r;break;case 2:r=90-r;break;case 3:r=-90+r}return r},function(t,e){t.Accumulator=function(t){this.Set(t)},t.Accumulator.prototype.Set=function(e){e||(e=0),e.constructor===t.Accumulator?(this._s=e._s,this._t=e._t):(this._s=e,this._t=0)},t.Accumulator.prototype.Add=function(t){var n=e.sum(t,this._t),r=e.sum(n.s,this._s);n=n.t,this._s=r.s,this._t=r.t,0===this._s?this._s=n:this._t+=n},t.Accumulator.prototype.Sum=function(e){var n;return e?((n=new t.Accumulator(this)).Add(e),n._s):this._s},t.Accumulator.prototype.Negate=function(){this._s*=-1,this._t*=-1}}(sr.Accumulator,sr.Math),sr.Geodesic={},sr.GeodesicLine={},sr.PolygonArea={},function(t,e,n,r,i){var s,a,o,l,h,c,u,p,_,d,f,m=20+r.digits+10,g=r.epsilon,y=200*g,v=Math.sqrt(g),w=g*y,S=1e3*v;t.tiny_=Math.sqrt(Number.MIN_VALUE),t.nC1_=6,t.nC1p_=6,t.nC2_=6,t.nC3_=6,t.nC4_=6,s=t.nC3_*(t.nC3_-1)/2,a=t.nC4_*(t.nC4_+1)/2,t.CAP_C1=1,t.CAP_C1p=2,t.CAP_C2=4,t.CAP_C3=8,t.CAP_C4=16,t.NONE=0,t.ARC=64,t.LATITUDE=128,t.LONGITUDE=256|t.CAP_C3,t.AZIMUTH=512,t.DISTANCE=1024|t.CAP_C1,t.STANDARD=t.LATITUDE|t.LONGITUDE|t.AZIMUTH|t.DISTANCE,t.DISTANCE_IN=2048|t.CAP_C1|t.CAP_C1p,t.REDUCEDLENGTH=4096|t.CAP_C1|t.CAP_C2,t.GEODESICSCALE=8192|t.CAP_C1|t.CAP_C2,t.AREA=16384|t.CAP_C4,t.ALL=32671,t.LONG_UNROLL=32768,t.OUT_MASK=32640|t.LONG_UNROLL,t.SinCosSeries=function(t,e,n,r){var i=r.length,s=i-(t?1:0),a=2*(n-e)*(n+e),o=1&s?r[--i]:0,l=0;for(s=Math.floor(s/2);s--;)o=a*(l=a*o-l+r[--i])-o+r[--i];return t?2*e*n*o:n*(o-l)},o=function(t,e){var n,i,s,a,o,l,h,c,u,p,_,d,f=r.sq(t),m=r.sq(e),g=(f+m-1)/6;return 0===m&&g<=0?n=0:(l=g,(o=(i=f*m/4)*(i+2*(a=g*(s=r.sq(g)))))>=0?(h=i+a,h+=h<0?-Math.sqrt(o):Math.sqrt(o),l+=(c=r.cbrt(h))+(0!==c?s/c:0)):(u=Math.atan2(Math.sqrt(-o),-(i+a)),l+=2*g*Math.cos(u/3)),p=Math.sqrt(r.sq(l)+m),d=((_=l<0?m/(p-l):l+p)-m)/(2*p),n=_/(Math.sqrt(_+r.sq(d))+d)),n},l=[1,4,64,0,256],t.A1m1f=function(t){var e=Math.floor(3);return(r.polyval(e,l,0,r.sq(t))/l[e+1]+t)/(1-t)},h=[-1,6,-16,32,-9,64,-128,2048,9,-16,768,3,-5,512,-7,1280,-7,2048],t.C1f=function(e,n){var i,s,a=r.sq(e),o=e,l=0;for(i=1;i<=t.nC1_;++i)s=Math.floor((t.nC1_-i)/2),n[i]=o*r.polyval(s,h,l,a)/h[l+s+1],l+=s+2,o*=e},c=[205,-432,768,1536,4005,-4736,3840,12288,-225,116,384,-7173,2695,7680,3467,7680,38081,61440],t.C1pf=function(e,n){var i,s,a=r.sq(e),o=e,l=0;for(i=1;i<=t.nC1p_;++i)s=Math.floor((t.nC1p_-i)/2),n[i]=o*r.polyval(s,c,l,a)/c[l+s+1],l+=s+2,o*=e},u=[-11,-28,-192,0,256],t.A2m1f=function(t){var e=Math.floor(3);return(r.polyval(e,u,0,r.sq(t))/u[e+1]-t)/(1+t)},p=[1,2,16,32,35,64,384,2048,15,80,768,7,35,512,63,1280,77,2048],t.C2f=function(e,n){var i,s,a=r.sq(e),o=e,l=0;for(i=1;i<=t.nC2_;++i)s=Math.floor((t.nC2_-i)/2),n[i]=o*r.polyval(s,p,l,a)/p[l+s+1],l+=s+2,o*=e},t.Geodesic=function(t,e){if(this.a=t,this.f=e,this._f1=1-this.f,this._e2=this.f*(2-this.f),this._ep2=this._e2/r.sq(this._f1),this._n=this.f/(2-this.f),this._b=this.a*this._f1,this._c2=(r.sq(this.a)+r.sq(this._b)*(0===this._e2?1:(this._e2>0?r.atanh(Math.sqrt(this._e2)):Math.atan(Math.sqrt(-this._e2)))/Math.sqrt(Math.abs(this._e2))))/2,this._etol2=.1*v/Math.sqrt(Math.max(.001,Math.abs(this.f))*Math.min(1,1-this.f/2)/2),!(isFinite(this.a)&&this.a>0))throw new Error("Equatorial radius is not positive");if(!(isFinite(this._b)&&this._b>0))throw new Error("Polar semi-axis is not positive");this._A3x=new Array(6),this._C3x=new Array(s),this._C4x=new Array(a),this.A3coeff(),this.C3coeff(),this.C4coeff()},_=[-3,128,-2,-3,64,-1,-3,-1,16,3,-1,-2,8,1,-1,2,1,1],t.Geodesic.prototype.A3coeff=function(){var t,e,n=0,i=0;for(t=5;t>=0;--t)e=Math.min(6-t-1,t),this._A3x[i++]=r.polyval(e,_,n,this._n)/_[n+e+1],n+=e+2},d=[3,128,2,5,128,-1,3,3,64,-1,0,1,8,-1,1,4,5,256,1,3,128,-3,-2,3,64,1,-3,2,32,7,512,-10,9,384,5,-9,5,192,7,512,-14,7,512,21,2560],t.Geodesic.prototype.C3coeff=function(){var e,n,i,s=0,a=0;for(e=1;e<t.nC3_;++e)for(n=t.nC3_-1;n>=e;--n)i=Math.min(t.nC3_-n-1,n),this._C3x[a++]=r.polyval(i,d,s,this._n)/d[s+i+1],s+=i+2},f=[97,15015,1088,156,45045,-224,-4784,1573,45045,-10656,14144,-4576,-858,45045,64,624,-4576,6864,-3003,15015,100,208,572,3432,-12012,30030,45045,1,9009,-2944,468,135135,5792,1040,-1287,135135,5952,-11648,9152,-2574,135135,-64,-624,4576,-6864,3003,135135,8,10725,1856,-936,225225,-8448,4992,-1144,225225,-1440,4160,-4576,1716,225225,-136,63063,1024,-208,105105,3584,-3328,1144,315315,-128,135135,-2560,832,405405,128,99099],t.Geodesic.prototype.C4coeff=function(){var e,n,i,s=0,a=0;for(e=0;e<t.nC4_;++e)for(n=t.nC4_-1;n>=e;--n)i=t.nC4_-n-1,this._C4x[a++]=r.polyval(i,f,s,this._n)/f[s+i+1],s+=i+2},t.Geodesic.prototype.A3f=function(t){return r.polyval(5,this._A3x,0,t)},t.Geodesic.prototype.C3f=function(e,n){var i,s,a=1,o=0;for(i=1;i<t.nC3_;++i)s=t.nC3_-i-1,a*=e,n[i]=a*r.polyval(s,this._C3x,o,e),o+=s+1},t.Geodesic.prototype.C4f=function(e,n){var i,s,a=1,o=0;for(i=0;i<t.nC4_;++i)s=t.nC4_-i-1,n[i]=a*r.polyval(s,this._C4x,o,e),o+=s+1,a*=e},t.Geodesic.prototype.Lengths=function(e,n,r,i,s,a,o,l,h,c,u,p,_){var d,f,m,g,y={},v=0,w=0,S=0,x=0;if((u&=t.OUT_MASK)&(t.DISTANCE|t.REDUCEDLENGTH|t.GEODESICSCALE)&&(S=t.A1m1f(e),t.C1f(e,p),u&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(x=t.A2m1f(e),t.C2f(e,_),v=S-x,x=1+x),S=1+S),u&t.DISTANCE)d=t.SinCosSeries(!0,a,o,p)-t.SinCosSeries(!0,r,i,p),y.s12b=S*(n+d),u&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(w=v*n+(S*d-x*(t.SinCosSeries(!0,a,o,_)-t.SinCosSeries(!0,r,i,_))));else if(u&(t.REDUCEDLENGTH|t.GEODESICSCALE)){for(f=1;f<=t.nC2_;++f)_[f]=S*p[f]-x*_[f];w=v*n+(t.SinCosSeries(!0,a,o,_)-t.SinCosSeries(!0,r,i,_))}return u&t.REDUCEDLENGTH&&(y.m0=v,y.m12b=l*(i*a)-s*(r*o)-i*o*w),u&t.GEODESICSCALE&&(m=i*o+r*a,g=this._ep2*(h-c)*(h+c)/(s+l),y.M12=m+(g*a-o*w)*r/s,y.M21=m-(g*r-i*w)*a/l),y},t.Geodesic.prototype.InverseStart=function(e,n,i,s,a,l,h,c,u,p,_){var d,f,m,g,v,w,x,b,C,E,A,k,M,I,T,D,P,N,R,L,G={},O=s*n-a*e,F=a*n+s*e;return G.sig12=-1,d=s*n,d+=a*e,(f=F>=0&&O<.5&&a*h<.5)?(g=r.sq(e+s),g/=g+r.sq(n+a),G.dnm=Math.sqrt(1+this._ep2*g),m=h/(this._f1*G.dnm),v=Math.sin(m),w=Math.cos(m)):(v=c,w=u),G.salp1=a*v,G.calp1=w>=0?O+a*e*r.sq(v)/(1+w):d-a*e*r.sq(v)/(1-w),b=r.hypot(G.salp1,G.calp1),C=e*s+n*a*w,f&&b<this._etol2?(G.salp2=n*v,G.calp2=O-n*s*(w>=0?r.sq(v)/(1+w):1-w),x=r.hypot(G.salp2,G.calp2),G.salp2/=x,G.calp2/=x,G.sig12=Math.atan2(b,C)):Math.abs(this._n)>.1||C>=0||b>=6*Math.abs(this._n)*Math.PI*r.sq(n)||(L=Math.atan2(-c,-u),this.f>=0?(I=(M=r.sq(e)*this._ep2)/(2*(1+Math.sqrt(1+M))+M),E=L/(k=this.f*n*this.A3f(I)*Math.PI),A=d/(k*n)):(T=a*n-s*e,D=Math.atan2(d,T),A=h/(k=((E=(P=this.Lengths(this._n,Math.PI+D,e,-n,i,s,a,l,n,a,t.REDUCEDLENGTH,p,_)).m12b/(n*a*P.m0*Math.PI)-1)<-.01?d/E:-this.f*r.sq(n)*Math.PI)/n)),A>-y&&E>-1-S?this.f>=0?(G.salp1=Math.min(1,-E),G.calp1=-Math.sqrt(1-r.sq(G.salp1))):(G.calp1=Math.max(E>-y?0:-1,E),G.salp1=Math.sqrt(1-r.sq(G.calp1))):(N=o(E,A),R=k*(this.f>=0?-E*N/(1+N):-A*(1+N)/N),v=Math.sin(R),w=-Math.cos(R),G.salp1=a*v,G.calp1=d-a*e*r.sq(v)/(1-w))),G.salp1<=0?(G.salp1=1,G.calp1=0):(x=r.hypot(G.salp1,G.calp1),G.salp1/=x,G.calp1/=x),G},t.Geodesic.prototype.Lambda12=function(e,n,i,s,a,o,l,h,c,u,p,_,d,f){var m,g,y,v,w,S,x,b,C,E,A,k,M,I={};return 0===e&&0===h&&(h=-t.tiny_),g=l*n,y=r.hypot(h,l*e),I.ssig1=e,v=g*e,I.csig1=w=h*n,m=r.hypot(I.ssig1,I.csig1),I.ssig1/=m,I.csig1/=m,I.salp2=a!==n?g/a:l,I.calp2=a!==n||Math.abs(s)!==-e?Math.sqrt(r.sq(h*n)+(n<-e?(a-n)*(n+a):(e-s)*(e+s)))/a:Math.abs(h),I.ssig2=s,S=g*s,I.csig2=x=I.calp2*a,m=r.hypot(I.ssig2,I.csig2),I.ssig2/=m,I.csig2/=m,I.sig12=Math.atan2(Math.max(0,I.csig1*I.ssig2-I.ssig1*I.csig2),I.csig1*I.csig2+I.ssig1*I.ssig2),b=Math.max(0,w*S-v*x),C=w*x+v*S,A=Math.atan2(b*u-C*c,C*u+b*c),k=r.sq(y)*this._ep2,I.eps=k/(2*(1+Math.sqrt(1+k))+k),this.C3f(I.eps,f),E=t.SinCosSeries(!0,I.ssig2,I.csig2,f)-t.SinCosSeries(!0,I.ssig1,I.csig1,f),I.domg12=-this.f*this.A3f(I.eps)*g*(I.sig12+E),I.lam12=A+I.domg12,p&&(0===I.calp2?I.dlam12=-2*this._f1*i/e:(M=this.Lengths(I.eps,I.sig12,I.ssig1,I.csig1,i,I.ssig2,I.csig2,o,n,a,t.REDUCEDLENGTH,_,d),I.dlam12=M.m12b,I.dlam12*=this._f1/(I.calp2*a))),I},t.Geodesic.prototype.Inverse=function(e,n,i,s,a){var o,l;return a||(a=t.STANDARD),a===t.LONG_UNROLL&&(a|=t.STANDARD),a&=t.OUT_MASK,l=(o=this.InverseInt(e,n,i,s,a)).vals,a&t.AZIMUTH&&(l.azi1=r.atan2d(o.salp1,o.calp1),l.azi2=r.atan2d(o.salp2,o.calp2)),l},t.Geodesic.prototype.InverseInt=function(e,n,i,s,a){var o,l,h,c,u,p,_,d,f,y,v,S,x,b,C,E,A,k,M,I,T,D,P,N,R,L,G,O,F,U,q,j,z,B,V,$,W,H,K,Z,J,X,Y,Q,tt,et,nt,rt,it,st,at,ot,lt,ht,ct,ut,pt,_t,dt,ft,mt,gt,yt,vt,wt,St={};if(St.lat1=e=r.LatFix(e),St.lat2=i=r.LatFix(i),e=r.AngRound(e),i=r.AngRound(i),l=(o=r.AngDiff(n,s)).t,o=o.s,a&t.LONG_UNROLL?(St.lon1=n,St.lon2=n+o+l):(St.lon1=r.AngNormalize(n),St.lon2=r.AngNormalize(s)),o=(h=o>=0?1:-1)*r.AngRound(o),l=r.AngRound(180-o-h*l),C=o*r.degree,E=(c=r.sincosd(o>90?l:o)).s,A=(o>90?-1:1)*c.c,(u=Math.abs(e)<Math.abs(i)?-1:1)<0&&(h*=-1,c=e,e=i,i=c),e*=p=e<0?1:-1,i*=p,c=r.sincosd(e),_=this._f1*c.s,d=c.c,_/=c=r.hypot(_,d),d/=c,d=Math.max(t.tiny_,d),c=r.sincosd(i),f=this._f1*c.s,y=c.c,f/=c=r.hypot(f,y),y/=c,y=Math.max(t.tiny_,y),d<-_?y===d&&(f=f<0?_:-_):Math.abs(f)===-_&&(y=d),x=Math.sqrt(1+this._ep2*r.sq(_)),b=Math.sqrt(1+this._ep2*r.sq(f)),P=new Array(t.nC1_+1),N=new Array(t.nC2_+1),R=new Array(t.nC3_),(L=-90===e||0===E)&&(I=E,D=0,O=_,F=(M=A)*d,U=f,q=(T=1)*y,k=Math.atan2(Math.max(0,F*U-O*q),F*q+O*U),v=(G=this.Lengths(this._n,k,O,F,x,U,q,b,d,y,a|t.DISTANCE|t.REDUCEDLENGTH,P,N)).s12b,S=G.m12b,0!==(a&t.GEODESICSCALE)&&(St.M12=G.M12,St.M21=G.M21),k<1||S>=0?(k<3*t.tiny_&&(k=S=v=0),S*=this._b,v*=this._b,St.a12=k/r.degree):L=!1),pt=2,!L&&0===_&&(this.f<=0||l>=180*this.f))M=T=0,I=D=1,v=this.a*C,k=z=C/this._f1,S=this._b*Math.sin(k),a&t.GEODESICSCALE&&(St.M12=St.M21=Math.cos(k)),St.a12=o/this._f1;else if(!L)if(k=(G=this.InverseStart(_,d,x,f,y,b,C,E,A,P,N)).sig12,I=G.salp1,M=G.calp1,k>=0)D=G.salp2,T=G.calp2,B=G.dnm,v=k*this._b*B,S=r.sq(B)*this._b*Math.sin(k/B),a&t.GEODESICSCALE&&(St.M12=St.M21=Math.cos(k/B)),St.a12=k/r.degree,z=C/(this._f1*B);else{for(V=0,$=t.tiny_,W=1,H=t.tiny_,K=-1,Z=!1,J=!1;V<m&&(X=(G=this.Lambda12(_,d,x,f,y,b,I,M,E,A,V<20,P,N,R)).lam12,D=G.salp2,T=G.calp2,k=G.sig12,O=G.ssig1,F=G.csig1,U=G.ssig2,q=G.csig2,j=G.eps,dt=G.domg12,Y=G.dlam12,!J&&Math.abs(X)>=(Z?8:1)*g);++V)X>0&&(V<20||M/I>K/H)?(H=I,K=M):X<0&&(V<20||M/I<W/$)&&($=I,W=M),V<20&&Y>0&&(Q=-X/Y,tt=Math.sin(Q),(nt=I*(et=Math.cos(Q))+M*tt)>0&&Math.abs(Q)<Math.PI)?(M=M*et-I*tt,I=nt,I/=c=r.hypot(I,M),M/=c,Z=Math.abs(X)<=16*g):(I=($+H)/2,M=(W+K)/2,I/=c=r.hypot(I,M),M/=c,Z=!1,J=Math.abs($-I)+(W-M)<w||Math.abs(I-H)+(M-K)<w);rt=a|(a&(t.REDUCEDLENGTH|t.GEODESICSCALE)?t.DISTANCE:t.NONE),v=(G=this.Lengths(j,k,O,F,x,U,q,b,d,y,rt,P,N)).s12b,S=G.m12b,0!==(a&t.GEODESICSCALE)&&(St.M12=G.M12,St.M21=G.M21),S*=this._b,v*=this._b,St.a12=k/r.degree,a&t.AREA&&(vt=Math.sin(dt),pt=E*(wt=Math.cos(dt))-A*vt,_t=A*wt+E*vt)}return a&t.DISTANCE&&(St.s12=0+v),a&t.REDUCEDLENGTH&&(St.m12=0+S),a&t.AREA&&(it=I*d,0!==(st=r.hypot(M,I*_))&&0!==it?(O=_,F=M*d,U=f,q=T*y,j=(ot=r.sq(st)*this._ep2)/(2*(1+Math.sqrt(1+ot))+ot),lt=r.sq(this.a)*st*it*this._e2,O/=c=r.hypot(O,F),F/=c,U/=c=r.hypot(U,q),q/=c,ht=new Array(t.nC4_),this.C4f(j,ht),ct=t.SinCosSeries(!1,O,F,ht),ut=t.SinCosSeries(!1,U,q,ht),St.S12=lt*(ut-ct)):St.S12=0,!L&&pt>1&&(pt=Math.sin(z),_t=Math.cos(z)),!L&&_t>-.7071&&f-_<1.75?(dt=1+_t,ft=1+d,mt=1+y,at=2*Math.atan2(pt*(_*mt+f*ft),dt*(_*f+ft*mt))):(yt=T*M+D*I,0===(gt=D*M-T*I)&&yt<0&&(gt=t.tiny_*M,yt=-1),at=Math.atan2(gt,yt)),St.S12+=this._c2*at,St.S12*=u*h*p,St.S12+=0),u<0&&(c=I,I=D,D=c,c=M,M=T,T=c,a&t.GEODESICSCALE&&(c=St.M12,St.M12=St.M21,St.M21=c)),{vals:St,salp1:I*=u*h,calp1:M*=u*p,salp2:D*=u*h,calp2:T*=u*p}},t.Geodesic.prototype.GenDirect=function(n,r,i,s,a,o){return o?o===t.LONG_UNROLL&&(o|=t.STANDARD):o=t.STANDARD,s||(o|=t.DISTANCE_IN),new e.GeodesicLine(this,n,r,i,o).GenPosition(s,a,o)},t.Geodesic.prototype.Direct=function(t,e,n,r,i){return this.GenDirect(t,e,n,!1,r,i)},t.Geodesic.prototype.ArcDirect=function(t,e,n,r,i){return this.GenDirect(t,e,n,!0,r,i)},t.Geodesic.prototype.Line=function(t,n,r,i){return new e.GeodesicLine(this,t,n,r,i)},t.Geodesic.prototype.DirectLine=function(t,e,n,r,i){return this.GenDirectLine(t,e,n,!1,r,i)},t.Geodesic.prototype.ArcDirectLine=function(t,e,n,r,i){return this.GenDirectLine(t,e,n,!0,r,i)},t.Geodesic.prototype.GenDirectLine=function(n,r,i,s,a,o){var l;return o||(o=t.STANDARD|t.DISTANCE_IN),s||(o|=t.DISTANCE_IN),(l=new e.GeodesicLine(this,n,r,i,o)).GenSetDistance(s,a),l},t.Geodesic.prototype.InverseLine=function(n,i,s,a,o){var l,h,c;return o||(o=t.STANDARD|t.DISTANCE_IN),l=this.InverseInt(n,i,s,a,t.ARC),c=r.atan2d(l.salp1,l.calp1),o&t.OUT_MASK&t.DISTANCE_IN&&(o|=t.DISTANCE),(h=new e.GeodesicLine(this,n,i,c,o,l.salp1,l.calp1)).SetArc(l.vals.a12),h},t.Geodesic.prototype.Polygon=function(t){return new n.PolygonArea(this,t)},t.WGS84=new t.Geodesic(i.WGS84.a,i.WGS84.f)}(sr.Geodesic,sr.GeodesicLine,sr.PolygonArea,sr.Math,sr.Constants),function(t,e,n){e.GeodesicLine=function(e,r,i,s,a,o,l){var h,c,u,p,_,d;a||(a=t.STANDARD|t.DISTANCE_IN),this.a=e.a,this.f=e.f,this._b=e._b,this._c2=e._c2,this._f1=e._f1,this.caps=a|t.LATITUDE|t.AZIMUTH|t.LONG_UNROLL,this.lat1=n.LatFix(r),this.lon1=i,void 0===o||void 0===l?(this.azi1=n.AngNormalize(s),h=n.sincosd(n.AngRound(this.azi1)),this.salp1=h.s,this.calp1=h.c):(this.azi1=s,this.salp1=o,this.calp1=l),h=n.sincosd(n.AngRound(this.lat1)),u=this._f1*h.s,c=h.c,u/=h=n.hypot(u,c),c/=h,c=Math.max(t.tiny_,c),this._dn1=Math.sqrt(1+e._ep2*n.sq(u)),this._salp0=this.salp1*c,this._calp0=n.hypot(this.calp1,this.salp1*u),this._ssig1=u,this._somg1=this._salp0*u,this._csig1=this._comg1=0!==u||0!==this.calp1?c*this.calp1:1,h=n.hypot(this._ssig1,this._csig1),this._ssig1/=h,this._csig1/=h,this._k2=n.sq(this._calp0)*e._ep2,p=this._k2/(2*(1+Math.sqrt(1+this._k2))+this._k2),this.caps&t.CAP_C1&&(this._A1m1=t.A1m1f(p),this._C1a=new Array(t.nC1_+1),t.C1f(p,this._C1a),this._B11=t.SinCosSeries(!0,this._ssig1,this._csig1,this._C1a),_=Math.sin(this._B11),d=Math.cos(this._B11),this._stau1=this._ssig1*d+this._csig1*_,this._ctau1=this._csig1*d-this._ssig1*_),this.caps&t.CAP_C1p&&(this._C1pa=new Array(t.nC1p_+1),t.C1pf(p,this._C1pa)),this.caps&t.CAP_C2&&(this._A2m1=t.A2m1f(p),this._C2a=new Array(t.nC2_+1),t.C2f(p,this._C2a),this._B21=t.SinCosSeries(!0,this._ssig1,this._csig1,this._C2a)),this.caps&t.CAP_C3&&(this._C3a=new Array(t.nC3_),e.C3f(p,this._C3a),this._A3c=-this.f*this._salp0*e.A3f(p),this._B31=t.SinCosSeries(!0,this._ssig1,this._csig1,this._C3a)),this.caps&t.CAP_C4&&(this._C4a=new Array(t.nC4_),e.C4f(p,this._C4a),this._A4=n.sq(this.a)*this._calp0*this._salp0*e._e2,this._B41=t.SinCosSeries(!1,this._ssig1,this._csig1,this._C4a)),this.a13=this.s13=Number.NaN},e.GeodesicLine.prototype.GenPosition=function(e,r,i){var s,a,o,l,h,c,u,p,_,d,f,m,g,y,v,w,S,x,b,C,E,A,k,M,I,T,D={};return i?i===t.LONG_UNROLL&&(i|=t.STANDARD):i=t.STANDARD,i&=this.caps&t.OUT_MASK,D.lat1=this.lat1,D.azi1=this.azi1,D.lon1=i&t.LONG_UNROLL?this.lon1:n.AngNormalize(this.lon1),e?D.a12=r:D.s12=r,e||this.caps&t.DISTANCE_IN&t.OUT_MASK?(l=0,h=0,e?(s=r*n.degree,a=(k=n.sincosd(r)).s,o=k.c):(p=r/(this._b*(1+this._A1m1)),_=Math.sin(p),d=Math.cos(p),s=p-((l=-t.SinCosSeries(!0,this._stau1*d+this._ctau1*_,this._ctau1*d-this._stau1*_,this._C1pa))-this._B11),a=Math.sin(s),o=Math.cos(s),Math.abs(this.f)>.01&&(c=this._ssig1*o+this._csig1*a,u=this._csig1*o-this._ssig1*a,l=t.SinCosSeries(!0,c,u,this._C1a),s-=((1+this._A1m1)*(s+(l-this._B11))-r/this._b)/Math.sqrt(1+this._k2*n.sq(c)),a=Math.sin(s),o=Math.cos(s))),c=this._ssig1*o+this._csig1*a,u=this._csig1*o-this._ssig1*a,b=Math.sqrt(1+this._k2*n.sq(c)),i&(t.DISTANCE|t.REDUCEDLENGTH|t.GEODESICSCALE)&&((e||Math.abs(this.f)>.01)&&(l=t.SinCosSeries(!0,c,u,this._C1a)),h=(1+this._A1m1)*(l-this._B11)),g=this._calp0*c,0===(y=n.hypot(this._salp0,this._calp0*u))&&(y=u=t.tiny_),S=this._salp0,x=this._calp0*u,e&&i&t.DISTANCE&&(D.s12=this._b*((1+this._A1m1)*s+h)),i&t.LONGITUDE&&(v=this._salp0*c,w=u,m=n.copysign(1,this._salp0),f=((i&t.LONG_UNROLL?m*(s-(Math.atan2(c,u)-Math.atan2(this._ssig1,this._csig1))+(Math.atan2(m*v,w)-Math.atan2(m*this._somg1,this._comg1))):Math.atan2(v*this._comg1-w*this._somg1,w*this._comg1+v*this._somg1))+this._A3c*(s+(t.SinCosSeries(!0,c,u,this._C3a)-this._B31)))/n.degree,D.lon2=i&t.LONG_UNROLL?this.lon1+f:n.AngNormalize(n.AngNormalize(this.lon1)+n.AngNormalize(f))),i&t.LATITUDE&&(D.lat2=n.atan2d(g,this._f1*y)),i&t.AZIMUTH&&(D.azi2=n.atan2d(S,x)),i&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(C=t.SinCosSeries(!0,c,u,this._C2a),E=(1+this._A2m1)*(C-this._B21),A=(this._A1m1-this._A2m1)*s+(h-E),i&t.REDUCEDLENGTH&&(D.m12=this._b*(b*(this._csig1*c)-this._dn1*(this._ssig1*u)-this._csig1*u*A)),i&t.GEODESICSCALE&&(k=this._k2*(c-this._ssig1)*(c+this._ssig1)/(this._dn1+b),D.M12=o+(k*c-u*A)*this._ssig1/this._dn1,D.M21=o-(k*this._ssig1-this._csig1*A)*c/b)),i&t.AREA&&(M=t.SinCosSeries(!1,c,u,this._C4a),0===this._calp0||0===this._salp0?(I=S*this.calp1-x*this.salp1,T=x*this.calp1+S*this.salp1):(I=this._calp0*this._salp0*(o<=0?this._csig1*(1-o)+a*this._ssig1:a*(this._csig1*a/(1+o)+this._ssig1)),T=n.sq(this._salp0)+n.sq(this._calp0)*this._csig1*u),D.S12=this._c2*Math.atan2(I,T)+this._A4*(M-this._B41)),e||(D.a12=s/n.degree),D):(D.a12=Number.NaN,D)},e.GeodesicLine.prototype.Position=function(t,e){return this.GenPosition(!1,t,e)},e.GeodesicLine.prototype.ArcPosition=function(t,e){return this.GenPosition(!0,t,e)},e.GeodesicLine.prototype.GenSetDistance=function(t,e){t?this.SetArc(e):this.SetDistance(e)},e.GeodesicLine.prototype.SetDistance=function(e){var n;this.s13=e,n=this.GenPosition(!1,this.s13,t.ARC),this.a13=0+n.a12},e.GeodesicLine.prototype.SetArc=function(e){var n;this.a13=e,n=this.GenPosition(!0,this.a13,t.DISTANCE),this.s13=0+n.s12}}(sr.Geodesic,sr.GeodesicLine,sr.Math),function(t,e,n,r){var i,s;i=function(t,e){var r;return t=n.AngNormalize(t),e=n.AngNormalize(e),r=n.AngDiff(t,e).s,t<=0&&e>0&&r>0?1:e<=0&&t>0&&r<0?-1:0},s=function(t,e){return((e%=720)>=0&&e<360||e<-360?0:1)-((t%=720)>=0&&t<360||t<-360?0:1)},t.PolygonArea=function(t,n){this._geod=t,this.a=this._geod.a,this.f=this._geod.f,this._area0=4*Math.PI*t._c2,this.polyline=n||!1,this._mask=e.LATITUDE|e.LONGITUDE|e.DISTANCE|(this.polyline?e.NONE:e.AREA|e.LONG_UNROLL),this.polyline||(this._areasum=new r.Accumulator(0)),this._perimetersum=new r.Accumulator(0),this.Clear()},t.PolygonArea.prototype.Clear=function(){this.num=0,this._crossings=0,this.polyline||this._areasum.Set(0),this._perimetersum.Set(0),this._lat0=this._lon0=this.lat=this.lon=Number.NaN},t.PolygonArea.prototype.AddPoint=function(t,e){var n;0===this.num?(this._lat0=this.lat=t,this._lon0=this.lon=e):(n=this._geod.Inverse(this.lat,this.lon,t,e,this._mask),this._perimetersum.Add(n.s12),this.polyline||(this._areasum.Add(n.S12),this._crossings+=i(this.lon,e)),this.lat=t,this.lon=e),++this.num},t.PolygonArea.prototype.AddEdge=function(t,e){var n;this.num&&(n=this._geod.Direct(this.lat,this.lon,t,e,this._mask),this._perimetersum.Add(e),this.polyline||(this._areasum.Add(n.S12),this._crossings+=s(this.lon,n.lon2)),this.lat=n.lat2,this.lon=n.lon2),++this.num},t.PolygonArea.prototype.Compute=function(t,e){var n,s,a={number:this.num};return this.num<2?(a.perimeter=0,this.polyline||(a.area=0),a):this.polyline?(a.perimeter=this._perimetersum.Sum(),a):(n=this._geod.Inverse(this.lat,this.lon,this._lat0,this._lon0,this._mask),a.perimeter=this._perimetersum.Sum(n.s12),(s=new r.Accumulator(this._areasum)).Add(n.S12),1&this._crossings+i(this.lon,this._lon0)&&s.Add((s.Sum()<0?1:-1)*this._area0/2),t||s.Negate(),e?s.Sum()>this._area0/2?s.Add(-this._area0):s.Sum()<=-this._area0/2&&s.Add(+this._area0):(s.Sum()>=this._area0||s<0)&&s.Add(-this._area0),a.area=s.Sum(),a)},t.PolygonArea.prototype.TestPoint=function(t,e,n,r){var s,a,o,l,h={number:this.num+1};if(0===this.num)return h.perimeter=0,this.polyline||(h.area=0),h;for(h.perimeter=this._perimetersum.Sum(),a=this.polyline?0:this._areasum.Sum(),o=this._crossings,l=0;l<(this.polyline?1:2);++l)s=this._geod.Inverse(0===l?this.lat:t,0===l?this.lon:e,0!==l?this._lat0:t,0!==l?this._lon0:e,this._mask),h.perimeter+=s.s12,this.polyline||(a+=s.S12,o+=i(0===l?this.lon:e,0!==l?this._lon0:e));return this.polyline||(1&o&&(a+=(a<0?1:-1)*this._area0/2),n||(a*=-1),r?a>this._area0/2?a-=this._area0:a<=-this._area0/2&&(a+=this._area0):a>=this._area0?a-=this._area0:a<0&&(a+=this._area0),h.area=a),h},t.PolygonArea.prototype.TestEdge=function(t,e,n,r){var a,o,l,h={number:this.num?this.num+1:0};return 0===this.num?h:(h.perimeter=this._perimetersum.Sum()+e,this.polyline||(o=this._areasum.Sum(),l=this._crossings,o+=(a=this._geod.Direct(this.lat,this.lon,t,e,this._mask)).S12,l+=s(this.lon,a.lon2),a=this._geod.Inverse(a.lat2,a.lon2,this._lat0,this._lon0,this._mask),h.perimeter+=a.s12,o+=a.S12,1&(l+=i(a.lon2,this._lon0))&&(o+=(o<0?1:-1)*this._area0/2),n||(o*=-1),r?o>this._area0/2?o-=this._area0:o<=-this._area0/2&&(o+=this._area0):o>=this._area0?o-=this._area0:o<0&&(o+=this._area0),h.area=o),h)}}(sr.PolygonArea,sr.Geodesic,sr.Math,sr.Accumulator),Q(function(t){var e=Z(t.params,"rlat_1"),n=Z(t.params,"rlat_2");lr(t,e,n)},"aea","Albers Equal Area","Conic Sph&Ell\nlat_1= lat_2="),Q(function(t){var e=Z(t.params,"rlat_1"),n=Z(t.params,"bsouth")?-k:k;lr(t,e,n)},"leac","Lambert Equal Area Conic","Conic, Sph&Ell\nlat_1= south"),Q(function(t){var e,r,o,h,p,_,d,m=1e-10;t.phi0=Z(t.params,"rlat_0"),n(n(t.phi0)-k)<m?(p=t.phi0<0?1:0,e=t.phi0<0?-1:1,r=0):n(t.phi0)<m?(p=2,e=0,r=1):(p=3,e=i(t.phi0),r=s(t.phi0));if(t.es)if(d=new sr.Geodesic.Geodesic(t.a,t.es/(1+u(t.one_es))),_=hr(t.es),Z(t.params,"bguam"))o=cr(t.phi0,e,r,_),t.inv=function(e,n){var r,l,h;for(r=.5*e.x*e.x,n.phi=t.phi0,h=0;h<3;++h)l=t.e*i(n.phi),n.phi=ur(o+e.y-r*a(n.phi)*(l=u(1-l*l)),t.es,_);n.lam=e.x*l/s(n.phi)},t.fwd=function(e,n){var r,a,l;r=s(e.phi),a=i(e.phi),l=1/u(1-t.es*a*a),n.x=e.lam*r*l,n.y=cr(e.phi,a,r,_)-o+.5*e.lam*e.lam*r*a*l};else{switch(p){case 0:h=cr(k,1,0,_);break;case 1:h=cr(-k,-1,0,_);break;case 2:case 3:t.inv=y,t.fwd=g,u(1-t.es*e*e),t.e,u(t.one_es)}t.inv=y,t.fwd=g}else t.inv=function(n,a){var o,l,h,u=n.x,_=n.y;if((l=f(u,_))>S)l-m>S&&q(),l=S;else if(l<m)return a.phi=t.phi0,void(a.lam=0);3==p||2==p?(h=i(l),o=s(l),2==p?(a.phi=pr(_*h/l),u*=h,_=o*l):(a.phi=pr(o*e+_*h*r/l),_=(o-e*i(a.phi))*l,u*=h*r),a.lam=0==_?0:c(u,_)):0==p?(a.phi=k-l,a.lam=c(u,-_)):(a.phi=l-k,a.lam=c(u,_))},t.fwd=function(t,a){var o,h,c;switch(c=i(t.phi),h=s(t.phi),o=s(t.lam),p){case 2:case 3:a.y=2==p?h*o:e*c+r*h*o,n(n(a.y)-1)<1e-14?a.y<0?U():a.x=a.y=0:(a.y=l(a.y),a.y/=i(a.y),a.x=a.y*h*i(t.lam),a.y*=2==p?c:r*c-e*h*o);break;case 0:t.phi=-t.phi,o=-o;case 1:n(t.phi-k)<m&&U(),a.x=(a.y=k+t.phi)*i(t.lam),a.y*=o}};function g(e,r){var a,o,l,c,u,f,g,y,v,w,S;switch(a=s(e.lam),o=s(e.phi),l=i(e.phi),p){case 0:a=-a;case 1:r.x=(c=n(h-cr(e.phi,l,o,_)))*i(e.lam),r.y=c*a;break;case 2:case 3:if(n(e.lam)<m&&n(e.phi-t.phi0)<m){r.x=r.y=0;break}y=t.phi0/b,g=t.lam0/b,w=e.phi/b,v=(e.lam+t.lam0)/b,u=(S=d.Inverse(y,g,w,v,d.AZIMUTH)).azi1*b,f=S.s12,r.x=f*i(u)/t.a,r.y=f*s(u)/t.a}}function y(e,n){var r,i,s,a,o,l,g,y;if((r=f(e.x,e.y))<m)return n.phi=t.phi0,n.lam=0,n;3==p||2==p?(a=e.x*t.a,o=e.y*t.a,l=t.phi0/b,g=t.lam0/b,i=c(a,o)/b,s=u(a*a+o*o),y=d.Direct(l,g,i,s,d.STANDARD),n.phi=y.lat2*b,n.lam=y.lon2*b,n.lam-=t.lam0):(n.phi=ur(0==p?h-r:h+r,t.es,_),n.lam=c(e.x,0==p?-e.y:e.y))}},"aeqd","Azimuthal Equidistant","Azi, Sph&Ell\nlat_0 guam"),Q(function(t){var e,r,o,l,h,c,u=1e-10;t.es=0,t.fwd=function(t,c){var p,_,f,m,g,y,v,w;switch(p=i(t.lam),_=s(t.lam),l){case 2:case 3:m=i(t.phi),w=(f=s(t.phi))*_,3==l&&(w=e*m+r*w),!h&&w<-u&&U(),v=n(y=1-w)>u?-d(g=.5*(1+w))/y-o/g:.5-o,c.x=v*f*p,c.y=3==l?v*(r*m-e*f*_):v*m;break;case 1:case 0:t.phi=n(p_halfpi-t.phi),!h&&t.phi-u>k&&U(),(t.phi*=.5)>u?(g=a(t.phi),v=-2*(d(s(t.phi))/g+g*o),c.x=v*p,c.y=v*_,0==l&&(c.y=-c.y)):c.x=c.y=0}},h=Z(t.params,"bno_cut"),c=.5*(k-Z(t.params,"rlat_b")),n(c)<u?o=-.5:(o=1/a(c),o*=o*d(s(c)));n(n(t.phi0)-k)<u?t.phi0<0?(p_halfpi=-k,l=1):(p_halfpi=k,l=0):n(t.phi0)<u?l=2:(l=3,e=i(t.phi0),r=s(t.phi0))},"airy","Airy","Misc Sph, no inv.\nno_cut lat_b="),Q(function(t){var e=t.opaque={mode:1};Z(t.params,"tlat_1")?0===(e.cosphi1=s(Z(t.params,"rlat_1")))&&z(-22):e.cosphi1=.6366197723675814;mr(t)},"wintri","Winkel Tripel","Misc Sph\nlat_1"),Q(mr,"aitoff","Aitoff","Misc Sph"),Q(function(t){t.fwd=function(t,e){var n,r,o,l,h,c,p,_=4/3,d=t.lam;n=a(.5*t.phi),o=1+(r=u(1-n*n))*s(d*=.5),l=i(d)*r/o,c=n/o,e.x=_*l*(3+(h=l*l)-3*(p=c*c)),e.y=_*c*(3+3*h-p)},t.es=0},"august","August Epicycloidal","Misc Sph, no inv."),Q(function(t){gr(t,!1,!1)},"apian","Apian Globular I","Misc Sph, no inv."),Q(function(t){gr(t,!1,!0)},"ortel","Ortelius Oval","Misc Sph, no inv."),Q(function(t){gr(t,!0,!1)},"bacon","Bacon Globular","Misc Sph, no inv."),Q(function(t){var e,n,r,a;t.es=0,t.fwd=function(t,l){var h,p,_,d,f,m;return t.lam+=-16.5*b,p=s(t.phi),_=s(t.lam)*p,d=i(t.lam)*p,m=(f=i(t.phi))*e+_*n,t.lam=c(d*r-m*a,_*e-f*n),m=m*r+d*a,t.phi=o(m),t.lam=At(t.lam),t.lam+t.phi<-1.4&&(h=(t.lam-t.phi+1.6)*(t.lam+t.phi+1.4)/8,t.lam+=h,t.phi-=.8*h*i(t.phi+S/2)),p=s(t.phi),h=u(2/(1+p*s(t.lam/2))),l.x=1.68*h*p*i(t.lam/2),l.y=h*i(t.phi),h=(1-s(t.lam*t.phi))/12,l.y<0&&(l.x*=1+h),l.y>0&&(l.y*=1+h/1.5*l.x*l.x),l},t.lam0=0,t.phi0=-42*b,e=s(t.phi0),n=i(t.phi0),r=1,a=0},"bertin1953","Bertin 1953","Misc., Sph., NoInv."),Q(function(t){var e=u(2);t.fwd=function(t,r){var a,o,l,h;if(a=t.phi,n(n(t.phi)-k)<1e-7)r.x=0;else{for(l=i(a)*S,h=20;h&&(a-=o=(a+i(a)-l)/(1+s(a)),!(n(o)<1e-7));--h);a*=.5,r.x=2.00276*t.lam/(1/s(t.phi)+1.11072/s(a))}r.y=.49931*(t.phi+e*i(a))},t.es=0},"boggs","Boggs Eumorphic","PCyl., no inv., Sph."),Q(function(t){var e,r,o,l,h,p,_=1e-10;e=Z(t.params,"rlat_1"),n(e)<_&&z(-23);t.es?(h=hr(t.es),l=cr(e,o=i(e),p=s(e),h),o=p/(u(1-t.es*o*o)*o),t.inv=function(e,r){var a,p;p=f(e.x,e.y=o-e.y),r.phi=ur(o+l-p,t.es,h),(a=n(r.phi))<k?(a=i(r.phi),r.lam=p*c(e.x,e.y)*u(1-t.es*a*a)/s(r.phi)):n(a-k)<=_?r.lam=0:q()},t.fwd=function(e,n){var r,a,c;r=o+l-cr(e.phi,a=i(e.phi),c=s(e.phi),h),a=c*e.lam/(r*u(1-t.es*a*a)),n.x=r*i(a),n.y=o-r*s(a)}):(r=n(e)+_>=k?0:1/a(e),t.inv=function(t,i){var a=f(t.x,t.y=r-t.y);i.phi=r+e-a,n(i.phi)>k&&q();n(n(i.phi)-k)<=_?i.lam=0:i.lam=a*c(t.x,t.y)/s(i.phi)},t.fwd=function(t,a){var o,l;l=r+e-t.phi,n(l)>_?(a.x=l*i(o=t.lam*s(t.phi)/l),a.y=r-l*s(o)):a.x=a.y=0})},"bonne","Bonne (Werner lat_1=90)","Conic Sph&Ell\nlat_1="),Q(function(t){var e,n,r=.16666666666666666,l=.008333333333333333,h=.041666666666666664,p=.06666666666666667;t.es?(n=hr(t.es),e=cr(t.phi0,i(t.phi0),s(t.phi0),n),t.fwd=function(o,c){var p,_,d,f,m,g;c.y=cr(o.phi,p=i(o.phi),f=s(o.phi),n),p=1/u(1-t.es*p*p),g=a(o.phi),_=g*g,d=o.lam*f,f*=t.es*f/(1-t.es),m=d*d,c.x=p*d*(1-m*_*(r-(8-_+8*f)*m*l)),c.y-=e-p*g*m*(.5+(5-_+6*f)*m*h)},t.inv=function(r,o){var l,c,_,d,f,m,g;g=ur(e+r.y,t.es,n),m=a(g),c=m*m,l=i(g),_=1/(1-t.es*l*l),l=u(_),_*=(1-t.es)*l,d=r.x/l,f=d*d,o.phi=g-l*m/_*f*(.5-(1+3*c)*f*h),o.lam=d*(1+c*f*((1+3*c)*f*p-.3333333333333333))/s(g)}):(t.fwd=function(e,n){n.x=o(s(e.phi)*i(e.lam)),n.y=c(a(e.phi),s(e.lam))-t.phi0},t.inv=function(e,n){var r=e.y+t.phi0;n.phi=o(i(r)*s(e.x)),n.lam=c(a(e.x),s(r))})},"cass","Cassini","Cyl, Sph&Ell"),Q(function(t){var e,r,a=0;Z(t.params,"tlat_ts")&&(t.k0=s(a=Z(t.params,"rlat_ts")),t.k0<0&&z(-24));t.es?(a=i(a),t.k0/=u(1-t.es*a*a),t.e=u(t.es),(r=yr(t.es))||e_error_0(),e=ar(1,t.e,t.one_es),t.fwd=function(e,n){n.x=t.k0*e.lam,n.y=.5*ar(i(e.phi),t.e,t.one_es)/t.k0},t.inv=function(n,i){i.phi=vr(o(2*n.y*t.k0/e),r),i.lam=n.x/t.k0}):(t.fwd=function(e,n){n.x=t.k0*e.lam,n.y=i(e.phi)/t.k0},t.inv=function(e,r){var i,s=e.x,a=e.y;(i=n(a*=t.k0))-N<=1?(r.phi=i>=1?a<0?-k:k:o(a),r.lam=s/t.k0):q()})},"cea","Equal Area Cylindrical","Cyl, Sph&Ell\nlat_ts="),Q(function(t){var e,r,a,o,l,h,p,_=1/3,d=[];for(h=0;h<3;++h)d[h]={p:{}},d[h].phi=Z(t.params,"rlat_"+(h+1)),d[h].lam=Z(t.params,"rlon_"+(h+1)),d[h].lam=At(d[h].lam-t.lam0),d[h].cosphi=s(d[h].phi),d[h].sinphi=i(d[h].phi);for(h=0;h<3;++h)p=2==h?0:h+1,d[h].v=f(d[p].phi-d[h].phi,d[h].cosphi,d[h].sinphi,d[p].cosphi,d[p].sinphi,d[p].lam-d[h].lam),d[h].v.r||z(-25);function f(t,e,r,a,o,l){var h,p,_,d={};return h=s(l),n(t)>1||n(l)>1?d.r=_r(cs1*o+e*a*h):(p=i(.5*t),_=i(.5*l),d.r=2*pr(u(p*p+e*a*_*_))),n(d.r)>1e-9?d.Az=c(a*i(l),e*o-r*a*h):d.r=d.Az=0,d}function m(t,e,n){return _r(.5*(t*t+e*e-n*n)/(t*e))}a=m(d[0].v.r,d[2].v.r,d[1].v.r),o=m(d[0].v.r,d[1].v.r,d[2].v.r),l=S-a,r=2*(d[0].p.y=d[1].p.y=d[2].v.r*i(a)),d[2].p.y=0,d[0].p.x=-(d[1].p.x=.5*d[0].v.r),e=d[2].p.x=d[0].p.x+d[2].v.r*s(a),t.es=0,t.fwd=function(t,n){var a,h,c,u,p,g,y,v=[];for(a=i(t.phi),h=s(t.phi),u=0;u<3&&(v[u]=f(t.phi-d[u].phi,d[u].cosphi,d[u].sinphi,h,a,t.lam-d[u].lam),v[u].r);++u)v[u].Az=At(v[u].Az-d[u].v.Az);if(u<3)g=d[u].p.x,y=d[u].p.y;else{for(g=e,y=r,u=0;u<3;++u)p=2==u?0:u+1,c=m(d[u].v.r,v[u].r,v[p].r),v[u].Az<0&&(c=-c),u?1==u?(c=o-c,g-=v[u].r*s(c),y-=v[u].r*i(c)):(c=l-c,g+=v[u].r*s(c),y+=v[u].r*i(c)):(g+=v[u].r*s(c),y-=v[u].r*i(c));g*=_,y*=_}n.x=g,n.y=y}},"chamb","Chamberlin Trimetric","Misc Sph, no inv.\nlat_1= lon_1= lat_2= lon_2= lat_3= lon_3="),Q(function(t){var e=1/3;t.inv=function(t,n){n.phi=3*o(.32573500793527993*t.y),n.lam=1.0233267079464885*t.x/(2*s((n.phi+n.phi)*e)-1)},t.fwd=function(t,n){t.phi*=e,n.x=.9772050238058398*t.lam*(2*s(t.phi+t.phi)-1),n.y=3.0699801238394655*i(t.phi)},t.es=0},"crast","Craster Parabolic (Putnins P4)","PCyl., Sph."),Q(function(t){var e=.5253,n=.7264,r=1/Math.sqrt(e*n),a=.9701,l=_(22*b),h=d(0),c=i(l),p=s(l);Z(t.params,"tlon_0")||(t.lam0=11.023*b);function _(t){return o(n*i(t)+.4188*u(e*n))}function d(t){return e*t}t.es=0,t.fwd=function(t,e){var n=_(t.phi),o=d(t.lam),f=i(n),m=s(n),g=i(o-h),y=s(o-h),v=u(2/(1+i(l)*f+p*m*y));e.x=r*v*m*g*a,e.y=r*v*(p*f-c*m*y)/a}},"cupola","Cupola","PCyl., Sph., NoInv."),Q(function(t){t.fwd=function(t,e){var r=n(t.lam);e.y=t.phi,e.x=t.lam,e.x*=s((.95+r*(r*r*.0016666666666666666-.08333333333333333))*(t.phi*(.9+.03*t.phi*t.phi*t.phi*t.phi)))},t.es=0},"denoy","Denoyer Semi-Elliptical","PCyl, Sph., no inv."),Q(function(t){var e=.9213177319235613,r=.3183098861837907;t.es=0,t.fwd=function(t,i){i.x=e*t.lam*(1-r*n(t.phi)),i.y=e*t.phi},t.inv=function(t,i){i.phi=t.y/e,i.lam=t.x/(e*(1-r*n(i.phi)))}},"eck1","Eckert I","PCyl Sph"),Q(function(t){var e=.46065886596178063,r=1.4472025091165353;t.es=0,t.fwd=function(t,s){s.x=e*t.lam*(s.y=u(4-3*i(n(t.phi)))),s.y=r*(2-s.y),t.phi<0&&(s.y=-s.y)},t.inv=function(t,i){i.lam=t.x/(e*(i.phi=2-n(t.y)/r)),i.phi=.3333333333333333*(4-i.phi*i.phi),n(i.phi)>=1?n(i.phi)>1.0000001?q():i.phi=i.phi<0?-k:k:i.phi=o(i.phi),t.y<0&&(i.phi=-i.phi)}},"eck2","Eckert II","PCyl Sph"),Q(function(t){wr(t,{C_x:.4222382003157712,C_y:.8444764006315424,A:1,B:.4052847345693511})},"eck3","Eckert III","PCyl Sph"),Q(function(t){wr(t,{C_x:.94745,C_y:.94745,A:0,B:.3039635509270133})},"wag6","Wagner VI","PCyl Sph"),Q(function(t){wr(t,{C_x:.8660254037844,C_y:1,A:0,B:.3039635509270133})},"kav7","Kavraisky VII","PCyl Sph"),Q(function(t){wr(t,{C_x:1.8949,C_y:.94745,A:-.5,B:.3039635509270133})},"putp1","Putnins P1","PCyl Sph"),Q(function(t){var e=.4222382003157712,r=1.3265004281770023,a=3.5707963267948966;t.es=0,t.fwd=function(t,o){var l,h,c,u,p;for(l=a*i(t.phi),h=t.phi*t.phi,t.phi*=.895168+h*(.0218849+.00826809*h),p=6;p&&(u=s(t.phi),c=i(t.phi),t.phi-=h=(t.phi+c*(u+2)-l)/(1+u*(u+2)-c*c),!(n(h)<1e-7));--p);p?(o.x=e*t.lam*(1+s(t.phi)),o.y=r*i(t.phi)):(o.x=e*t.lam,o.y=t.phi<0?-r:r)},t.inv=function(t,n){var o;n.phi=pr(t.y/r),n.lam=t.x/(e*(1+(o=s(n.phi)))),n.phi=pr((n.phi+i(n.phi)*(o+2))/a)}},"eck4","Eckert IV","PCyl Sph"),Q(function(t){t.es=0,t.fwd=function(t,e){e.x=.4410127717245515*(1+s(t.phi))*t.lam,e.y=.882025543449103*t.phi},t.inv=function(t,e){e.lam=2.267508027238226*t.x/(1+s(e.phi=1.133754013619113*t.y))}},"eck5","Eckert V","PCyl Sph"),Q(function(t){var e=s(Z(t.params,"rlat_ts"));e<=0&&z(-24);t.es=0,t.fwd=function(n,r){r.x=e*n.lam,r.y=n.phi-t.phi0},t.inv=function(n,r){r.lam=n.x/e,r.phi=n.y+t.phi0}},"eqc","Equidistant Cylindrical (Plate Caree)","Cyl, Sph\nlat_ts=[, lat_0=0]"),Q(function(t){var e,r,a,o,l,h,u,p,_,d,m,g,y;e=Z(t.params,"rlat_1"),r=Z(t.params,"rlat_2"),n(e+r)<N&&z(-21);(u=hr(t.es))||e_error_0();a=d=i(e),_=s(e),m=n(e-r)>=N,(p=t.es>0)?(y=or(d,_,t.es),g=cr(e,d,_,u),m&&(d=i(r),_=s(r),a=(y-or(d,_,t.es))/(cr(r,d,_,u)-g)),l=(h=g+y/a)-cr(t.phi0,i(t.phi0),s(t.phi0),u)):(m&&(a=(_-s(r))/(r-e)),h=e+s(e)/a,l=h-t.phi0);t.fwd=function(t,e){o=h-(p?cr(t.phi,i(t.phi),s(t.phi),u):t.phi),e.x=o*i(t.lam*=a),e.y=l-o*s(t.lam)},t.inv=function(e,n){0!=(o=f(e.x,e.y=l-e.y))?(a<0&&(o=-o,e.x=-e.x,e.y=-e.y),n.phi=h-o,p&&(n.phi=ur(n.phi,t.es,u)),n.lam=c(e.x,e.y)/a):(n.lam=0,n.phi=a>0?k:-k)}},"eqdc","Equidistant Conic","Conic, Sph&Ell\nlat_1= lat_2="),Q(function(t){var e=1.340264,n=-.081106,r=893e-6,i=.003796,s=Math.sqrt(3)/2;t.es=0,t.fwd=function(t,a){var o=Math.asin(s*Math.sin(t.phi)),l=o*o,h=l*l*l;a.x=t.lam*Math.cos(o)/(s*(e+3*n*l+h*(7*r+9*i*l))),a.y=o*(e+n*l+h*(r+i*l))},t.inv=function(t,a){var o,l,h,c,u=t.y;for(c=0;c<12&&(u-=h=(u*(e+n*(o=u*u)+(l=o*o*o)*(r+i*o))-t.y)/(e+3*n*o+l*(7*r+9*i*o)),!(Math.abs(h)<1e-9));++c);l=(o=u*u)*o*o,a.lam=s*t.x*(e+3*n*o+l*(7*r+9*i*o))/Math.cos(u),a.phi=Math.asin(Math.sin(u)/s)}},"eqearth","Equal Earth","PCyl., Sph."),Q(Sr,"etmerc","Extended Transverse Mercator","Cyl, Sph\nlat_ts=(0)\nlat_0=(0)"),Q(function(t){t.fwd=function(t,e){e.x=.7071067811865476*t.lam,e.y=1.7071067811865475*a(.5*t.phi)},t.inv=function(t,e){e.lam=1.4142135623730951*t.x,e.phi=2*h(.585786437626905*t.y)},t.es=0},"gall","Gall (Gall Stereographic)","Cyl, Sph"),Q(function(t){t.is_geocent=!0,t.x0=0,t.y0=0,t.fwd=function(t,e){e.x=t.lam,e.y=t.phi},t.inv=function(t,e){e.phi=t.y,e.lam=t.x}},"geocent","Geocentric",""),Q(function(t){var e,n,r,o,l,p,_,d=Z(t.params,"dh"),m=Z(t.params,"ssweep");m?"x"==m?_=1:"y"==m?_=0:z(-49):_=0;((l=d/t.a)<=0||l>1e10)&&z(-50);p=(o=1+l)*o-1,0!=t.es?(e=u(t.one_es),n=t.one_es,r=t.rone_es,t.inv=function(t,n){var i,d,m,g,y,v;i=-1,_?(m=a(t.y/l),d=a(t.x/l)*f(1,m)):(d=a(t.x/l),m=a(t.y/l)*f(1,d));var w=(y=2*o*i)*y-4*(g=d*d+(g=m/e)*g+i*i)*p;w<0&&z(-51);v=(-y-u(w))/(2*g),i=o+v*i,d*=v,m*=v,n.lam=c(d,i),n.phi=h(m*s(n.lam)/i),n.phi=h(r*a(n.phi))},t.fwd=function(t,c){var u,p,d,m,g;t.phi=h(n*a(t.phi)),u=e/f(e*s(t.phi),i(t.phi)),p=u*s(t.lam)*s(t.phi),d=u*i(t.lam)*s(t.phi),m=u*i(t.phi),(o-p)*p-d*d-m*m*r<0&&z(-51);g=o-p,_?(c.x=l*h(d/f(m,g)),c.y=l*h(m/g)):(c.x=l*h(d/g),c.y=l*h(m/f(d,g)))}):(e=n=r=1,t.inv=function(t,e){var n,r,i,d,f,m;n=-1,_?(i=a(t.y/l),r=a(t.x/l)*u(1+i*i)):(r=a(t.x/l),i=a(t.y/l)*u(1+r*r));var g=(f=2*o*n)*f-4*(d=r*r+i*i+n*n)*p;g<0&&z(-51);m=(-f-u(g))/(2*d),n=o+m*n,r*=m,i*=m,e.lam=c(r,n),e.phi=h(i*s(e.lam)/n)},t.fwd=function(t,e){var n=s(t.phi),r=s(t.lam)*n,a=i(t.lam)*n,c=i(t.phi);n=o-r,_?(e.x=l*h(a/f(c,n)),e.y=l*h(c/n)):(e.x=l*h(a/n),e.y=l*h(c/f(a,n)))})},"geos","Geostationary Satellite View","Azi, Sph&Ell"),Q(function(t){var e=o(Z(t.params,"tlat_1")?Z(t.params,"rlat_1"):0),n=i(e),r=s(e);function o(t){return pr(a(.5*t))}t.fwd=function(t,e){var a=.5*t.lam,l=o(t.phi),h=i(l),c=s(l),u=s(a);n*h+r*c*u>=0?(e.x=c*i(a),e.y=r*h-n*c*u):U()},t.es=0},"gilbert","Gilbert Two World Perspective","PCyl., Sph., NoInv.\nlat_1="),Q(function(t){t.fwd=function(t,e){var n=t.phi*t.phi;e.y=t.phi*(1+.08333333333333333*n),e.x=t.lam*(1-.162388*n),n=t.lam*t.lam,e.x*=.87-952426e-9*n*n},t.es=0},"gins8","Ginsburg VIII (TsNIIGAiK)","PCyl, Sph., no inv."),Q(function(t){Z(t.params,"tn"),Z(t.params,"tm")?br(t,Z(t.params,"dm"),Z(t.params,"dn")):z(-99)},"gn_sinu","General Sinusoidal Series","PCyl, Sph.\nm= n="),Q(xr,"sinu","Sinusoidal (Sanson-Flamsteed)","PCyl, Sph&Ell"),Q(function(t){br(t,1,2.5707963267948966)},"eck6","Eckert VI","PCyl, Sph.\nm= n="),Q(function(t){br(t,.5,1.7853981633974483)},"mbtfps","McBryde-Thomas Flat-Polar Sinusoidal","PCyl, Sph."),Q(function(t){var e,r,a=1e-10;n(n(t.phi0)-k)<a?r=t.phi0<0?1:0:n(t.phi0)<a?r=2:(r=3,sinph0=i(t.phi0),e=s(t.phi0));t.inv=function(s,l){var p,_,d,m=s.x,g=s.y;if(p=f(m,g),d=i(l.phi=h(p)),_=u(1-d*d),n(p)<=a)l.phi=t.phi0,l.lam=0;else{switch(r){case 3:l.phi=_*sinph0+g*d*e/p,n(l.phi)>=1?l.phi=l.phi>0?k:-k:l.phi=o(l.phi),g=(_-sinph0*i(l.phi))*p,m*=d*e;break;case 2:l.phi=g*d/p,n(l.phi)>=1?l.phi=l.phi>0?k:-k:l.phi=o(l.phi),g=_*p,m*=d;break;case 1:l.phi-=k;break;case 0:l.phi=k-l.phi,g=-g}l.lam=c(m,g)}},t.fwd=function(t,n){var o,l,h;switch(h=i(t.phi),l=s(t.phi),o=s(t.lam),r){case 2:n.y=l*o;break;case 3:n.y=sinph0*h+e*l*o;break;case 1:n.y=-h;break;case 0:n.y=h}switch(n.y<=a&&U(),n.x=(n.y=1/n.y)*l*i(t.lam),r){case 2:n.y*=h;break;case 3:n.y*=e*h-sinph0*l*o;break;case 0:o=-o;case 1:n.y*=l*o}},t.es=0},"gnom","Gnomonic","Azi, Sph."),Q(Cr,"moll","Mollweide","PCyl Sph"),Q(function(t){Ar(t,Er(t,S/3))},"wag4","Wagner IV","PCyl Sph"),Q(function(t){Ar(t,{C_x:.90977,C_y:1.65014,C_p:3.00896})},"wag5","Wagner V","PCyl Sph"),Q(function(t){var e,r,i,s,a=.0528,o=.7109307819790236;t.es=0,xr(t),e=t.fwd,r=t.inv,Cr(t),i=t.fwd,s=t.inv,t.fwd=function(t,r){n(t.phi)<o?e(t,r):(i(t,r),r.y-=t.phi>0?a:-a)},t.inv=function(t,e){n(t.y)<=o?r(t,e):(t.y+=t.y>0?a:-a,s(t,e))}},"goode","Goode Homolosine","PCyl, Sph."),Q(function(t){var e,r,a;t.inv=function(t,r){var i=u(1-.25*e*e*t.x*t.x-.25*t.y*t.y);n(2*i*i-1)<1e-10?(r.lam=w,r.phi=w,pj_errno=-14):(r.lam=fr(e*t.x*i,2*i*i-1)/e,r.phi=pr(i*t.y))},t.fwd=o,t.es=0,Z(t.params,"tW")?(e=n(Z(t.params,"dW")))<=0&&z(-27):e=.5;Z(t.params,"tM")?(r=n(Z(t.params,"dM")))<=0&&z(-27):r=1;function o(t,n){var o,l;l=u(2/(1+(o=s(t.phi))*s(t.lam*=e))),n.x=r*l*o*i(t.lam),n.y=a*l*i(t.phi)}a=1/r,r/=e},"hammer","Hammer & Eckert-Greifendorff","Misc Sph,\nW= M="),Q(function(t){var e=1.000001;t.inv=function(t,r){var a=t.y*(t.y<0?.5179951515653813:.5686373742600607);n(a)>1?n(a)>e?q():a=a>0?k:-k:a=o(a),r.lam=1.1764705882352942*t.x/s(a),a+=a,r.phi=(a+i(a))*(t.y<0?.4102345310814193:.3736990601468637),n(r.phi)>1?n(r.phi)>e?q():r.phi=r.phi>0?k:-k:r.phi=o(r.phi)},t.fwd=function(t,e){var r,a,o;for(a=i(t.phi)*(t.phi<0?2.43763:2.67595),o=20;o&&(t.phi-=r=(t.phi+i(t.phi)-a)/(1+s(t.phi)),!(n(r)<1e-7));--o);e.x=.85*t.lam*s(t.phi*=.5),e.y=i(t.phi)*(t.phi<0?1.93052:1.75859)},t.es=0},"hatano","Hatano Asymmetrical Equal Area","PCyl., Sph."),Q(kr,"healpix","HEALPix","Sph., Ellps."),Q(function(t){kr(t,!0)},"rhealpix","rHEALPix","Sph., Ellps.\nnorth_square= south_square="),Q(function(t){var e,r=i(.5),a=o(r),h=2*u(S/(e=S+4*a*2)),p=.5*h*(2+u(3));t.es=0,t.fwd=function(t,r){var o,l,_=1-i(t.phi);if(_&&_<2){var d,f,m,g,y,v=k-t.phi,w=25;do{f=i(v),m=s(v),y=a+c(f,2-m),v-=d=(v-1*a-2*f+(g=5-4*m)*y-.5*_*e)/(4*f*y)}while(n(d)>1e-12&&--w>0);o=h*u(g),l=t.lam*y/S}else o=h*(1+_),l=t.lam*a/S;r.x=o*i(l),r.y=p-o*s(l)},t.inv=function(t,n){var r=t.x,s=t.y,_=r*r+(s-=p)*s,d=(5-_/(h*h))/4,f=l(d),m=i(f),g=a+c(m,2-d);n.lam=o(r/u(_))*S/g,n.phi=o(1-2*(f-1*a-2*m+(5-4*d)*g)/e)}},"hill","Hill Eucyclic","PCyl., Sph."),Q(function(t){var e,r,l,_,d,f,m,g,y,v=.785398163397448,w=1.37008346281555;t.a=6377397.155,t.e=u(t.es=.006674372230614),Z(t.params,"tlat_0")||(t.phi0=.863937979737193);Z(t.params,"tlon_0")||(t.lam0=.4334234309119251);Z(t.params,"tk")||(t.k0=.9999);y=1,Z(t.params,"tczech")||(y=-1);_=u(1+t.es*p(s(t.phi0),4)/(1-t.es)),e=o(i(t.phi0)/_),l=p((1+t.e*i(t.phi0))/(1-t.e*i(t.phi0)),_*t.e/2),d=a(e/2+v)/p(a(t.phi0/2+v),_)*l,r=u(1-t.es)/(1-t.es*p(i(t.phi0),2)),f=i(w),m=t.k0*r/a(w),g=.5286277629901559,t.inv=function(e,r){var l,S,x,b,C,E,A,k;A=e.x,e.x=e.y,e.y=A,e.x*=y,e.y*=y,C=u(e.x*e.x+e.y*e.y),b=c(e.y,e.x)/i(w),x=2*(h(p(m/C,1/f)*a(w/2+v))-v),l=o(s(g)*i(x)-i(g)*s(x)*s(b)),S=o(s(x)*i(b)/s(l)),r.lam=t.lam0-S/_,E=l,k=0;do{r.phi=2*(h(p(d,-1/_)*p(a(l/2+v),1/_)*p((1+t.e*i(E))/(1-t.e*i(E)),t.e/2))-v),n(E-r.phi)<1e-15&&(k=1),E=r.phi}while(0===k);r.lam-=t.lam0},t.fwd=function(e,n){var r,l,c,u,S,x,b;r=p((1+t.e*i(e.phi))/(1-t.e*i(e.phi)),_*t.e/2),l=2*(h(d*p(a(e.phi/2+v),_)/r)-v),c=-e.lam*_,u=o(s(g)*i(l)+i(g)*s(l)*s(c)),S=o(s(l)*i(c)/s(u)),x=f*S,b=m*p(a(w/2+v),f)/p(a(u/2+v),f),n.y=b*s(x),n.x=b*i(x),n.y*=y,n.x*=y}},"krovak","Krovak","PCyl., Ellps."),Q(function(t){var e,r,a,l,h,p,_,d,m,g,y,v=1e-10;g=n(t.phi0),m=n(g-k)<v?t.phi0<0?1:0:n(g)<v?2:3;if(t.es){switch(t.e=u(t.es),h=ar(1,t.e,t.one_es),t.es,d=yr(t.es),m){case 0:case 1:p=1;break;case 2:p=1/(_=u(.5*h)),a=1,l=.5*h;break;case 3:_=u(.5*h),y=i(t.phi0),e=ar(y,t.e,t.one_es)/h,r=u(1-e*e),p=s(t.phi0)/(u(1-t.es*y*y)*_*r),l=(a=_)/p,a*=p}t.inv=function(n,a){var l,u,g,y,w=0;switch(m){case 2:case 3:if(n.x/=p,n.y*=p,(y=f(n.x,n.y))<v)return a.lam=0,a.phi=t.phi0,a;u=2*o(.5*y/_),l=s(u),u=i(u),n.x*=u,3==m?(w=l*e+n.y*u*r/y,n.y=y*r*l-n.y*e*u):(w=n.y*u/y,n.y=y*l);break;case 0:n.y=-n.y;case 1:if(!(g=n.x*n.x+n.y*n.y))return a.lam=0,a.phi=t.phi0,a;w=1-g/h,1==m&&(w=-w)}return a.lam=c(n.x,n.y),a.phi=vr(o(w),d),a},t.fwd=function(o,c){var p,_,d,f,g=0,y=0,w=0;p=s(o.lam),_=i(o.lam),d=i(o.phi),f=ar(d,t.e,t.one_es),(3==m||2==m)&&(y=u(1-(g=f/h)*g));switch(m){case 3:w=1+e*g+r*y*p;break;case 2:w=1+y*p;break;case 0:w=k+o.phi,f=h-f;break;case 1:w=o.phi-k,f=h+f}n(w)<v&&U();switch(m){case 3:case 2:3==m?(w=u(2/w),c.y=l*w*(r*g-e*y*p)):(w=u(2/(1+y*p)),c.y=w*g*l),c.x=a*w*y*_;break;case 0:case 1:f>=0?(w=u(f),c.x=w*_,c.y=p*(1==m?w:-w)):c.x=c.y=0}}}else 3==m&&(e=i(t.phi0),r=s(t.phi0)),t.inv=function(a,l){var h,u=0,p=0;h=f(a.x,a.y),(l.phi=.5*h)>1&&q();l.phi=2*o(l.phi),(3==m||2==m)&&(p=i(l.phi),u=s(l.phi));switch(m){case 2:l.phi=n(h)<=v?0:o(a.y*p/h),a.x*=p,a.y=u*h;break;case 3:l.phi=n(h)<=v?t.phi0:o(u*e+a.y*p*r/h),a.x*=p*r,a.y=(u-i(l.phi)*e)*h;break;case 0:a.y=-a.y,l.phi=k-l.phi;break;case 1:l.phi-=k}l.lam=0!=a.y||2!=m&&3!=m?c(a.x,a.y):0},t.fwd=function(a,o){var l,h,c;switch(c=i(a.phi),h=s(a.phi),l=s(a.lam),m){case 2:case 3:o.y=2==m?1+h*l:1+e*c+r*h*l,o.y<=v&&U(),o.y=u(2/o.y),o.x=o.y*h*i(a.lam),o.y*=2==m?c:r*c-e*h*l;break;case 0:l=-l;case 1:n(a.phi+t.phi0)<v&&U(),o.y=A-.5*a.phi,o.y=2*(1==m?s(o.y):i(o.y)),o.x=o.y*i(a.lam),o.y*=l}}},"laea","Lambert Azimuthal Equal Area","Azi, Sph&Ell"),Q(Mr,"lonlat","Lat/long (Geodetic)",""),Q(Mr,"longlat","Lat/long (Geodetic alias)",""),Q(Mr,"latlon","Lat/long (Geodetic alias)",""),Q(Mr,"latlong","Lat/long (Geodetic alias)",""),Q(function(t){var e,r,o,l,_,m,g,y,v,S,x,b=1e-10;t.inv=E,t.fwd=C,l=Z(t.params,"rlat_1"),Z(t.params,"tlat_2")?_=Z(t.params,"rlat_2"):(_=l,Z(t.params,"tlat_0")||(t.phi0=l));n(l+_)<b&&z(-21);m=r=i(l),e=s(l),o=n(l-_)>=b,(v=0!=t.es)?(t.e=u(t.es),x=or(r,e,t.es),S=Ir(l,r,t.e),o&&(r=i(_),m=d(x/or(r,s(_),t.es)),m/=d(S/Ir(_,r,t.e))),y=g=x*p(S,-m)/m,g*=n(n(t.phi0)-k)<b?0:p(Ir(t.phi0,i(t.phi0),t.e),m)):(o&&(m=d(e/s(_))/d(a(A+.5*_)/a(A+.5*l))),y=e*p(a(A+.5*l),m)/m,g=n(n(t.phi0)-k)<b?0:y*p(a(A+.5*t.phi0),-m));function C(e,r){var o,l=e.lam;n(n(e.phi)-k)<b?(e.phi*m<=0&&U(),o=0):o=y*(v?p(Ir(e.phi,i(e.phi),t.e),m):p(a(A+.5*e.phi),-m)),l*=m,r.x=t.k0*(o*i(l)),r.y=t.k0*(g-o*s(l))}function E(e,n){var r,i=e.x,s=e.y;i/=t.k0,s/=t.k0,0!=(r=f(i,s=g-s))?(m<0&&(r=-r,i=-i,s=-s),v?(n.phi=Tr(p(r/y,1/m),t.e),n.phi==w&&q()):n.phi=2*h(p(y/r,1/m))-k,n.lam=c(i,s)/m):(n.lam=0,n.phi=m>0?k:-k)}},"lcc","Lambert Conformal Conic","Conic, Sph&Ell\nlat_1= and lat_2= or lat_0="),Q(function(t){var e,r,i,o=1e-8;e=Z(t.params,"rlat_1"),r=s(e),i=a(A+.5*e),r<o&&z(-22);t.fwd=function(t,s){s.y=t.phi-e,n(s.y)<o?s.x=t.lam*r:(s.x=A+.5*t.phi,n(s.x)<o||n(n(s.x)-k)<o?s.x=0:s.x=t.lam*s.y/d(a(s.x)/i))},t.inv=function(t,s){s.phi=t.y+e,n(t.y)<o?s.lam=t.x/r:(s.lam=A+.5*s.phi,n(s.lam)<o||n(n(s.lam)-k)<o?s.lam=0:s.lam=t.x*d(a(s.lam)/i)/t.y)},t.es=0},"loxim","Loximuthal","PCyl Sph"),Q(function(t){var e=.9525793444156804,r=.9258200997725514,a=3.401680257083045,l=2/3,h=1/3,c=1.0000001;t.fwd=function(t,n){t.phi=o(e*i(t.phi)),n.x=r*t.lam*(2*s(l*t.phi)-1),n.y=a*i(h*t.phi)},t.inv=function(t,h){h.phi=t.y/a,n(h.phi)>=1?n(h.phi)>c?q():h.phi=h.phi<0?-k:k:h.phi=o(h.phi),h.lam=t.x/(r*(2*s(l*(h.phi*=3))-1)),n(h.phi=i(h.phi)/e)>=1?n(h.phi)>c?q():h.phi=h.phi<0?-k:k:h.phi=o(h.phi)},t.es=0},"mbt_fpp","McBride-Thomas Flat-Polar Parabolic","Cyl., Sph."),Q(function(t){var e=1.000001;t.fwd=function(t,e){var r,a,o;for(a=1.7071067811865475*i(t.phi),o=20;o&&(t.phi-=r=(i(.5*t.phi)+i(t.phi)-a)/(.5*s(.5*t.phi)+s(t.phi)),!(n(r)<1e-7));--o);e.x=.3124597141037825*t.lam*(1+2*s(t.phi)/s(.5*t.phi)),e.y=1.874758284622695*i(.5*t.phi)},t.inv=function(t,r){var a;r.phi=.533402096794177*t.y,n(r.phi)>1?n(r.phi)>e?q():r.phi<0?(a=-1,r.phi=-S):(a=1,r.phi=S):r.phi=2*o(a=r.phi),r.lam=3.2004125807650623*t.x/(1+2*s(r.phi)/s(.5*r.phi)),r.phi=.585786437626905*(a+i(r.phi)),n(r.phi)>1?n(r.phi)>e?q():r.phi=r.phi<0?-k:k:r.phi=o(r.phi)},t.es=0},"mbt_fpq","McBryde-Thomas Flat-Polar Quartic","Cyl., Sph."),Q(function(t){var e=.45503,r=1.36509,a=1.41546,o=.22248,l=1.44492,h=1/3;t.fwd=function(t,c){var u,p,_,d;for(u=a*i(t.phi),d=10;d&&(_=t.phi/r,t.phi-=p=(e*i(_)+i(t.phi)-u)/(h*s(_)+s(t.phi)),!(n(p)<1e-7));--d);_=t.phi/r,c.x=o*t.lam*(1+3*s(t.phi)/s(_)),c.y=l*i(_)},t.inv=function(t,n){var h;n.phi=r*(h=pr(t.y/l)),n.lam=t.x/(o*(1+3*s(n.phi)/s(h))),n.phi=pr((e*i(h)+i(n.phi))/a)},t.es=0},"mbt_fps","McBryde-Thomas Flat-Pole Sine (No. 2)","Cyl., Sph."),Q(function(t){var e=1e-10,r=0,o=Z(t.params,"tlat_ts");o&&(r=Z(t.params,"rlat_ts"))>=k&&z(-24);t.es?(o&&(t.k0=or(i(r),s(r),t.es)),t.inv=function(e,n){n.phi=Tr(_(-e.y/t.k0),t.e),n.phi===w&&q();n.lam=e.x/t.k0},t.fwd=function(r,s){n(n(r.phi)-k)<=e&&U();s.x=t.k0*r.lam,s.y=-t.k0*d(Ir(r.phi,i(r.phi),t.e))}):(t.inv=function(e,n){n.phi=k-2*h(_(-e.y/t.k0)),n.lam=e.x/t.k0},t.fwd=function(r,i){n(n(r.phi)-k)<=e&&U();i.x=t.k0*r.lam,i.y=t.k0*d(a(A+.5*r.phi))})},"merc","Mercator","Cyl, Sph&Ell\nlat_ts="),Q(function(t){t.k0=1,t.inv=function(e,n){n.phi=k-2*h(_(-e.y/t.k0)),n.lam=e.x/t.k0},t.fwd=function(e,r){n(n(e.phi)-k)<=N&&U(),r.x=t.k0*e.lam,r.y=t.k0*d(a(A+.5*e.phi))}},"webmerc","Web Mercator / Pseudo Mercator","Cyl, Ell"),Q(function(t){t.fwd=function(t,e){e.x=t.lam,e.y=1.25*d(a(A+.4*t.phi))},t.inv=function(t,e){e.lam=t.x,e.phi=2.5*(h(_(.8*t.y))-A)},t.es=0},"mill","Miller Cylindrical","Cyl, Sph"),Q(function(t){t.lam0=20*b,t.phi0=18*b,t.es=0,Nr(t,[[.9245,0],[0,0],[.01943,0]])},"mil_os","Miller Oblated Stereographic","Azi(mod)"),Q(function(t){t.lam0=-165*b,t.phi0=-10*b,t.es=0,Nr(t,[[.721316,0],[0,0],[-.0088162,-.00617325]])},"lee_os","Lee Oblated Stereographic","Azi(mod)"),Q(function(t){t.lam0=-96*b,t.phi0=39*b,t.es=0,t.a=6370997,Nr(t,[[.98879,0],[0,0],[-.050909,0],[0,0],[.075528,0]])},"gs48","Mod Stereographic of 48 U.S.","Azi(mod)"),Q(function(t){var e;t.lam0=-152*b,t.phi0=64*b,0!=t.es?(e=[[.9945303,0],[.0052083,-.0027404],[.0072721,.0048181],[-.0151089,-.1932526],[.0642675,-.1381226],[.3582802,-.2884586]],t.a=6378206.4,t.e=u(t.es=.00676866)):(e=[[.9972523,0],[.0052513,-.0041175],[.0074606,.0048125],[-.0153783,-.1968253],[.0636871,-.1408027],[.3660976,-.2937382]],t.a=6370997);Nr(t,e)},"alsk","Mod Stereographic of Alaska","Azi(mod)"),Q(function(t){var e;t.lam0=-120*b,t.phi0=45*b,0!=t.es?(e=[[.9827497,0],[.0210669,.0053804],[-.1031415,-.0571664],[-.0323337,-.0322847],[.0502303,.1211983],[.0251805,.0895678],[-.0012315,-.1416121],[.0072202,-.1317091],[-.0194029,.0759677],[-.0210072,.0834037]],t.a=6378206.4,t.e=u(t.es=.00676866)):(e=[[.984299,0],[.0211642,.0037608],[-.1036018,-.0575102],[-.0329095,-.0320119],[.0499471,.1223335],[.026046,.0899805],[7388e-7,-.1435792],[.0075848,-.1334108],[-.0216473,.0776645],[-.0225161,.0853673]],t.a=6370997);Nr(t,e)},"gs50","Mod Stereographic of 50 U.S.","Azi(mod)"),Q(function(t){var e=.8707,r=-.131979,i=-.013791,s=.003971,a=-.001529,o=1.007226,l=.015085,h=-.044475,c=.028874,u=-.005916,p=o,_=3*l,d=7*h,f=9*c,m=11*u,g=.8707*.52*S;t.es=0,t.fwd=function(t,n){var p,_;_=(p=t.phi*t.phi)*p,n.x=t.lam*(e+p*(r+p*(i+_*p*(s+p*a)))),n.y=t.phi*(o+p*(l+_*(h+c*p+u*_)))},t.inv=function(t,y){var v,w,S,x,b=t.x,C=t.y;for(C>g?C=g:C<-g&&(C=-g),v=C;v-=w=(v*(o+(S=v*v)*(l+(x=S*S)*(h+c*S+u*x)))-C)/(p+S*(_+x*(d+f*S+m*x))),!(n(w)<1e-11););y.phi=v,S=v*v,y.lam=b/(e+S*(r+S*(i+S*S*S*(s+S*a))))}},"natearth","Natural Earth","PCyl., Sph."),Q(function(t){var e=.84719,r=-.13063,i=-.04515,s=.05494,a=-.02326,o=.00331,l=1.01183,h=-.02625,c=.01926,u=-.00396,p=l,_=9*h,d=.45334622460635143*S;t.es=0,t.fwd=function(t,n){var p,_,d;d=(p=t.phi*t.phi)*(_=p*p),n.x=t.lam*(e+r*p+d*d*(i+s*p+a*_+o*d)),n.y=t.phi*(l+_*_*(h+c*p+u*_))},t.inv=function(t,f){var m,g,y,v,w,S=t.x,x=t.y;for(x>d?x=d:x<-d&&(x=-d),m=x;m-=g=(m*(l+(v=(y=m*m)*y)*v*(h+c*y+u*v))-x)/(p+v*v*(_+.21186*y+-.05148*v)),!(n(g)<1e-11););f.phi=m,w=(y=m*m)*(v=y*y),f.lam=S/(e+r*y+w*w*(i+s*y+a*v+o*w))}},"natearth2","Natural Earth 2","PCyl., Sph."),Q(function(t){t.inv=function(t,e){e.lam=2*t.x/(1+s(t.y)),e.phi=pr(.5*(t.y+i(t.y)))},t.fwd=function(t,e){var r,a,o;for(r=2*i(t.phi),a=t.phi*t.phi,t.phi*=1.00371+a*(-.011412*a-.0935382),o=10;o&&(t.phi-=a=(t.phi+i(t.phi)-r)/(1+s(t.phi)),!(n(a)<1e-7));--o);e.x=.5*t.lam*(1+s(t.phi)),e.y=t.phi},t.es=0},"nell","Nell","PCyl., Sph."),Q(function(t){t.es=0,t.fwd=function(t,e){e.x=.5*t.lam*(1+s(t.phi)),e.y=2*(t.phi-a(.5*t.phi))},t.inv=function(t,e){var r,i,o,l;for(o=.5*t.y,l=9;l>0&&(i=s(.5*e.phi),e.phi-=r=(e.phi-a(e.phi/2)-o)/(1-.5/(i*i)),!(n(r)<1e-7));--l);l?e.lam=2*t.x/(1+s(e.phi)):(e.phi=o<0?-k:k,e.lam=2*t.x)}},"nell_h","Nell-Hammer","PCyl., Sph."),Q(function(t){t.es=0,t.fwd=function(t,e){var r=1e-10;if(n(t.lam)<r)e.x=0,e.y=t.phi;else if(n(t.phi)<r)e.x=t.lam,e.y=0;else if(n(n(t.lam)-k)<r)e.x=t.lam*s(t.phi),e.y=k*i(t.phi);else if(n(n(t.phi)-k)<r)e.x=0,e.y=t.phi;else{var a=k/t.lam-t.lam/k,o=t.phi/k,l=i(t.phi),h=(1-o*o)/(l-o),c=a/h,p=(a*l/h-.5*a)/(1+(c*=c)),_=(l/c+.5*h)/(1+1/c);e.x=s(t.phi),e.x=u(p*p+e.x*e.x/(1+c)),e.x=k*(p+(t.lam<0?-e.x:e.x)),e.y=u(_*_-(l*l/c+h*l-1)/(1+1/c)),e.y=k*(_+(t.phi<0?e.y:-e.y))}}},"nicol","Nicolosi Globular","Misc Sph, no inv"),Q(function(t){Rr(t,Z(t.params,"dh"))},"nsper","Near-sided perspective","Azi, Sph\nh="),Q(function(t){var e=Z(t.params,"dtilt")*b,n=Z(t.params,"dazi")*b,r=Z(t.params,"dh");Rr(t,r,e,n)},"tpers","Tilted perspective","Azi, Sph\ntilt= azi= h="),Q(function(t){var e=[[.7557853228,0],[.249204646,.003371507],[-.001541739,.04105856],[-.10162907,.01727609],[-.26623489,-.36249218],[-.6870983,-1.1651967]],r=[1.5627014243,.5185406398,-.03333098,-.1052906,-.0368594,.007317,.0122,.00394,-.0013],i=[.6399175073,-.1358797613,.063294409,-.02526853,.0117879,-.0055161,.0026906,-.001333,67e-5,-34e-5];t.ra=1/(t.a=6378388),t.lam0=173*b,t.phi0=-41*b,t.x0=251e4,t.y0=6023150,t.inv=function(i,s){var a,o,l,h,c,u,p={r:i.y,i:i.x},_={};for(a=20;a>0&&((c=Pr(p,e,_)).r-=i.y,c.i-=i.x,u=_.r*_.r+_.i*_.i,p.r+=l=-(c.r*_.r+c.i*_.i)/u,p.i+=h=-(c.i*_.r-c.r*_.i)/u,!(n(l)+n(h)<=1e-10));--a);if(a>0){for(s.lam=p.i,o=r.length-1,s.phi=r[o],--o;o>=0;--o)s.phi=r[o]+p.r*s.phi;s.phi=t.phi0+p.r*s.phi*.484813681109536}else s.lam=s.phi=w},t.fwd=function(n,r){var s=i.length-1,a={r:i[s]},o=2.0626480624709638*(n.phi-t.phi0);for(--s;s>=0;--s)a.r=i[s]+o*a.r;a.r*=o,a.i=n.lam,a=Dr(a,e),r.x=a.i,r.y=a.r}},"nzmg","New Zealand Map Grid","fixed Earth"),Q(function(t){var e,r,o,l,u,p,_,d,f,m,g,y,v,S,C,E=1e-10;e=Z(t.params,"so_proj"),r=Y[e],e||z(-26);r&&"ob_tran"!=e||z(-37);t.es=0,o={},Object.keys(t).forEach(function(e){o[e]=t[e]}),r.init(o),o.is_latlong&&1==t.to_meter&&(t.to_meter=b,t.fr_meter=x);Z(t.params,"to_alpha")?(d=Z(t.params,"ro_lon_c"),f=Z(t.params,"ro_lat_c"),m=Z(t.params,"ro_alpha"),n(n(f)-k)<=E&&z(-32),l=d+fr(-s(m),-i(m)*i(f)),_=pr(s(f)*i(m))):Z(t.params,"to_lat_p")?(l=Z(t.params,"ro_lon_p"),_=Z(t.params,"ro_lat_p")):(g=Z(t.params,"ro_lon_1"),v=Z(t.params,"ro_lat_1"),y=Z(t.params,"ro_lon_2"),S=Z(t.params,"ro_lat_2"),(n(v-S)<=E||(C=n(v))<=E||n(C-k)<=E||n(n(S)-k)<=E)&&z(-33),l=c(s(v)*i(S)*s(g)-i(v)*s(S)*s(y),i(v)*s(S)*i(y)-s(v)*i(S)*i(g)),_=h(-s(l-g)/a(v)));n(_)>E?(u=s(_),p=i(_),t.fwd=function(t,e){var n,r,a;n=s(t.lam),r=i(t.phi),a=s(t.phi),t.lam=At(fr(a*i(t.lam),p*a*n+u*r)+l),t.phi=pr(p*r-u*a*n),o.fwd(t,e)},t.inv=o.inv?function(t,e){var n,r,a;o.inv(t,e),e.lam!=w&&(n=s(e.lam-=l),r=i(e.phi),a=s(e.phi),e.phi=pr(p*r+u*a*n),e.lam=fr(a*i(e.lam),p*a*n-u*r))}:null):(t.fwd=function(t,e){var n,r;n=s(t.phi),r=s(t.lam),t.lam=At(fr(n*i(t.lam),i(t.phi))+l),t.phi=pr(-n*r),o.fwd(t,e)},t.inv=o.inv?function(t,e){var n,r;o.inv(t,e),e.lam!=w&&(n=s(e.phi),r=e.lam-l,e.lam=fr(n*i(r),-i(e.phi)),e.phi=pr(n*s(r)))}:null)},"ob_tran","General Oblique Transformation","Misc Sph\no_proj= plus parameters for projection\no_lat_p= o_lon_p= (new pole) or\no_alpha= o_lon_c= o_lat_c= or\no_lon_1= o_lat_1= o_lon_2= o_lat_2="),Q(function(t){var e,n,r,l,p,_,d,f,m,g,y;d=1/t.k0,f=t.k0,Z(t.params,"talpha")?(_=Z(t.params,"ralpha"),p=Z(t.params,"rlonc"),y=h(-s(_)/(-i(0)*i(_)))+p,m=o(s(0)*i(_))):(e=Z(t.params,"rlat_1"),n=Z(t.params,"rlat_2"),r=Z(t.params,"rlon_1"),l=Z(t.params,"rlon_2"),y=c(s(e)*i(n)*s(r)-i(e)*s(n)*s(l),i(e)*s(n)*i(l)-s(e)*i(n)*i(r)),r==-k&&(y=-y),m=h(-s(y-r)/a(e)));t.lam0=y+k,g=s(m),m=i(m),y=i(y),t.es=0,t.fwd=function(t,e){var n;e.y=i(t.lam),n=s(t.lam),e.x=h((a(t.phi)*g+m*e.y)/n),n<0&&(e.x+=S),e.x*=f,e.y=d*(m*i(t.phi)-g*s(t.phi)*e.y)},t.inv=function(t,e){var n,r;t.y/=d,t.x/=f,n=u(1-t.y*t.y),e.phi=o(t.y*m+n*g*(r=i(t.x))),e.lam=c(n*m*r-t.y*g,n*s(t.x))}},"ocea","Oblique Cylindrical Equal Area","Cyl, Sph lonc= alpha= or\nlat_1= lat_2= lon_1= lon_2="),Q(function(t){var e,r,l,f,m,g,y,v,x,b,C,E,M,T,D,P,R,L,G,O,F,j,B,V,$,W,H,K=1e-7,J=0,X=0,Y=0,Q=0,tt=0,et=0,nt=0,rt=0;H=Z(t.params,"tno_rot"),0!=(E=Z(t.params,"talpha"))&&(nt=Z(t.params,"ralpha"));0!=(M=Z(t.params,"tgamma"))&&(J=Z(t.params,"rgamma"));E||M?(X=Z(t.params,"rlonc"),(rt=Z(t.params,"tno_off")||Z(t.params,"tno_uoff"))&&(Z(t.params,"sno_uoff"),Z(t.params,"sno_off"))):(Y=Z(t.params,"rlon_1"),tt=Z(t.params,"rlat_1"),Q=Z(t.params,"rlon_2"),et=Z(t.params,"rlat_2"),(n(tt-et)<=K||(e=n(tt))<=K||n(e-k)<=K||n(n(t.phi0)-k)<=K||n(n(et)-k)<=K)&&z(-33));r=u(t.one_es),n(t.phi0)>N?(v=i(t.phi0),l=s(t.phi0),e=1-t.es*v*v,D=l*l,D=u(1+t.es*D*D/t.one_es),T=D*t.k0*r/e,(m=(f=D*r/(l*u(e)))*f-1)<=0?m=0:(m=u(m),t.phi0<0&&(m=-m)),P=m+=f,P*=p(Ir(t.phi0,v,t.e),D)):(D=1/r,T=t.k0,P=f=m=1);E||M?(E?(C=o(i(nt)/f),M||(J=nt)):nt=o(f*i(C=J)),t.lam0=X-o(.5*(m-1/m)*a(C))/D):(g=p(Ir(tt,i(tt),t.e),D),y=p(Ir(et,i(et),t.e),D),m=P/g,x=(y-g)/(y+g),b=((b=P*P)-y*g)/(b+y*g),(e=Y-Q)<-S?Q-=I:e>S&&(Q+=I),t.lam0=At(.5*(Y+Q)-h(b*a(.5*D*(Y-Q))/x)/D),C=h(2*i(D*At(Y-t.lam0))/(m-1/m)),J=nt=o(f*i(C)));O=i(C),F=s(C),j=i(J),B=s(J),L=1/(R=T*(G=1/D)),rt?W=0:(W=n(R*h(u(f*f-1)/s(nt))),t.phi0<0&&(W=-W));V=R*d(a(A-(m=.5*C))),$=R*d(a(A+m)),t.fwd=function(e,r){var a,o,l,h,u,_,f,m;n(n(e.phi)-k)>N?(a=.5*((u=P/p(Ir(e.phi,i(e.phi),t.e),D))-(_=1/u)),o=.5*(u+_),h=i(D*e.lam),n(n(l=(a*O-h*F)/o)-1)<N&&U(),m=.5*R*d((1-l)/(1+l)),_=s(D*e.lam),f=n(_)<K?T*e.lam:R*c(a*F+h*O,_)):(m=e.phi>0?V:$,f=R*e.phi),H?(r.x=f,r.y=m):(f-=W,r.x=m*B+f*j,r.y=f*B-m*j)},t.inv=function(e,r){var a,o,l,h,d,f,m;H?(o=e.y,a=e.x):(o=e.x*B-e.y*j,a=e.y*B+e.x*j+W),h=.5*((l=_(-L*o))-1/l),d=.5*(l+1/l),f=i(L*a),n(n(m=(f*F+h*O)/d)-1)<N?(r.lam=0,r.phi=m<0?-k:k):(r.phi=P/u((1+m)/(1-m)),(r.phi=Tr(p(r.phi,1/D),t.e))==w&&q(),r.lam=-G*c(h*F-f*O,s(L*a)))}},"omerc","Oblique Mercator","Cyl, Sph&Ell no_rot\nalpha= [gamma=] [no_off] lonc= or\nlon_1= lat_1= lon_2= lat_2="),Q(function(t){var e=1e-10,r={};n(n(t.phi0)-k)<=e?r.mode=t.phi0<0?1:0:n(t.phi0)>e?(r.mode=3,r.sinph0=i(t.phi0),r.cosph0=s(t.phi0)):r.mode=2;t.fwd=function(a,o){var l,h,c;switch(h=s(a.phi),l=s(a.lam),r.mode){case 2:h*l<-1e-10&&U(),o.y=i(a.phi);break;case 3:r.sinph0*(c=i(a.phi))+r.cosph0*h*l<-1e-10&&U(),o.y=r.cosph0*c-r.sinph0*h*l;break;case 0:l=-l;case 1:n(a.phi-t.phi0)-e>k&&U(),o.y=h*l}o.x=h*i(a.lam)},t.inv=function(i,s){var a,h,p;if((p=a=f(i.x,i.y))>1&&(p-1>e&&q(),p=1),h=u(1-p*p),n(a)<=e)s.phi=t.phi0,s.lam=0;else{switch(r.mode){case 0:i.y=-i.y,s.phi=l(p);break;case 1:s.phi=-l(p);break;case 2:case 3:2==r.mode?(s.phi=i.y*p/a,i.x*=p,i.y=h*a):(s.phi=h*r.sinph0+i.y*p*r.cosph0/a,i.y=(h-r.sinph0*s.phi)*a,i.x*=p*r.cosph0),n(s.phi)>=1?s.phi=s.phi<0?-k:k:s.phi=o(s.phi)}s.lam=0!=i.y||3!=r.mode&&2!=r.mode?c(i.x,i.y):0==i.x?0:i.x<0?-k:k}},t.es=0},"ortho","Orthographic","Azi, Sph."),Q(function(t){var e=1.0148,r=.23185,i=-.14499,s=.02406,a=e,o=5*r,l=7*i,h=908571831.7;t.es=0,t.fwd=function(t,n){var a=t.phi*t.phi;n.x=t.lam,n.y=t.phi*(e+a*a*(r+a*(i+s*a)))},t.inv=function(t,c){var u,p,_,d;for(u=t.y,t.y>h?t.y=h:t.y<-h&&(t.y=-h),d=100;d&&(u-=p=(u*(e+(_=u*u)*_*(r+_*(i+s*_)))-t.y)/(a+_*_*(o+_*(l+.21654*_))),!(n(p)<1e-11));--d);c.phi=u,c.lam=t.x}},"patterson","Patterson Cylindrical","Cyl., Sph."),Q(function(t){var e,r,l=1e-10,h=1e-12;t.es?(r=hr(t.es),e=cr(t.phi0,i(t.phi0),s(t.phi0),r),t.fwd=function(a,o){var h,c,u;n(a.phi)<=l?(o.x=a.lam,o.y=-e):(c=i(a.phi),h=n(u=s(a.phi))>l?or(c,u,t.es)/c:0,o.x=h*i(a.lam*=c),o.y=cr(a.phi,c,u,r)-e+h*(1-s(a.lam)))},t.inv=function(c,p){var _,d,f,m,g,y,v,w,S,x,b=c.x,C=c.y;if(n(C+=e)<=l)p.lam=b,p.phi=0;else{for(_=C*C+b*b,p.phi=C,x=20;x>0&&(g=(f=i(p.phi))*(m=s(p.phi)),n(m)<h&&q(),d=f*(w=u(1-t.es*f*f))/m,v=(y=cr(p.phi,f,m,r))*y+_,w=t.one_es/(w*w*w),p.phi+=S=(y+y+d*v-2*C*(d*y+1))/(t.es*g*(v-2*C*y)/d+2*(C-y)*(d*w-1/g)-w-w),!(n(S)<=h));--x);x||q(),d=i(p.phi),p.lam=o(b*a(p.phi)*u(1-t.es*d*d))/i(p.phi)}}):(e=-t.phi0,t.fwd=function(r,o){var h,c;n(r.phi)<=l?(o.x=r.lam,o.y=e):(h=1/a(r.phi),o.x=i(c=r.lam*i(r.phi))*h,o.y=r.phi-t.phi0+h*(1-s(c)))},t.inv=function(e,r){var s,h,c,u;if(n(e.y=t.phi0+e.y)<=l)r.lam=e.x,r.phi=0;else{r.phi=e.y,s=e.x*e.x+e.y*e.y,u=10;do{c=a(r.phi),r.phi-=h=(e.y*(r.phi*c+1)-r.phi-.5*(r.phi*r.phi+s)*c)/((r.phi-e.y)/c-1)}while(n(h)>1e-10&&--u);u||q(),r.lam=o(e.x*a(r.phi))/i(r.phi)}})},"poly","Polyconic (American)","Conic, Sph&Ell"),Q(function(t){var e=1.8949,r=1.71848,a=.6141848493043784,o=1.0471975511965976;t.es=0,t.fwd=function(t,l){var h,c,u,p,_;for(h=a*i(t.phi),u=t.phi*t.phi,t.phi*=.615709+u*(.00909953+.0046292*u),_=10;_&&(c=s(t.phi),u=i(t.phi),t.phi-=p=(t.phi+u*(c-1)-h)/(1+c*(c-1)-u*u),!(n(p)<1e-10));--_);_||(t.phi=t.phi<0?-o:o),l.x=e*t.lam*(s(t.phi)-.5),l.y=r*i(t.phi)},t.inv=function(t,n){var o;n.phi=pr(t.y/r),n.lam=t.x/(e*((o=s(n.phi))-.5)),n.phi=pr((n.phi+i(n.phi)*(o-1))/a)}},"putp2","Putnins P2","PCyl., Sph."),Q(Lr,"putp3","Putnins P3","PCyl., Sph."),Q(function(t){Lr(t,!0)},"putp3p","Putnins P3'","PCyl., Sph."),Q(function(t){Gr(t,.874038744,3.883251825)},"putp4p","Putnins P4'","PCyl., Sph."),Q(function(t){Gr(t,1,4.442882938)},"weren","Werenskiold I","PCyl., Sph."),Q(Or,"putp5","Putnins P5","PCyl., Sph."),Q(function(t){Or(t,!0)},"putp5p","Putnins P5'","PCyl., Sph."),Q(Fr,"putp6","Putnins P6","PCyl., Sph."),Q(function(t){Fr(t,!0)},"putp6p","Putnins P6'","PCyl., Sph."),Q(function(t){var e,r,o,p;e=t.phi0>=k-A/2?4:t.phi0<=-(k-A/2)?5:n(t.lam0)<=A?0:n(t.lam0)<=k+A?t.lam0>0?1:3:2;0!==t.es&&(t.a,t.a,r=t.a*u(1-t.es),o=1-(t.a-r)/t.a,p=o*o);function _(t,e,r){var i,s;return t<1e-10?(i=0,s=0):(s=c(e,r),n(s)<=A?i=0:s>A&&s<=k+A?(i=1,s-=k):s>k+A||s<=-(k+A)?(i=2,s=s>=0?s-S:s+S):(i=3,s+=k)),{area:i,theta:s}}function d(t,e){var n=t+e;return n<-S?n+=I:n>+S&&(n-=I),n}t.fwd=function(n,r){var o,c,f,m,g,y,v,w,x,b,C,E,I,T;o=0!==t.es?h(p*a(n.phi)):n.phi,c=n.lam,4==e?(m=k-o,c>=A&&c<=k+A?(v=0,f=c-k):c>k+A||c<=-(k+A)?(v=1,f=c>0?c-S:c+S):c>-(k+A)&&c<=-A?(v=2,f=c+k):(v=3,f=c)):5==e?(m=k+o,c>=A&&c<=k+A?(v=0,f=-c+k):c<A&&c>=-A?(v=1,f=-c):c<-A&&c>=-(k+A)?(v=2,f=-c-k):(v=3,f=c>0?-c+S:-c-S)):(1==e?c=d(c,+k):2==e?c=d(c,+S):3==e&&(c=d(c,-k)),C=i(o),E=s(o),I=i(c),w=E*s(c),x=E*I,b=C,0==e?T=_(m=l(w),b,x):1==e?T=_(m=l(x),b,-w):2==e?T=_(m=l(-w),b,-x):3==e?T=_(m=l(-x),b,w):(m=0,T={area:0,theta:0}),f=T.theta,v=T.area),y=h(12/S*(f+l(i(f)*s(A))-k)),g=u((1-s(m))/(s(y)*s(y))/(1-s(h(1/s(f))))),1==v?y+=k:2==v?y+=S:3==v&&(y+=M),r.x=g*s(y),r.y=g*i(y)},t.inv=function(_,f){var m,g,y,v,w,x,b,C,E,A,M,I,T;if(g=h(u(_.x*_.x+_.y*_.y)),m=c(_.y,_.x),_.x>=0&&_.x>=n(_.y)?A=0:_.y>=0&&_.y>=n(_.x)?(A=1,m-=k):_.x<0&&-_.x>=n(_.y)?(A=2,m=m<0?m+S:m-S):(A=3,m+=k),E=S/12*a(m),w=i(E)/(s(E)-1/u(2)),x=h(w),(b=1-(y=s(m))*y*(v=a(g))*v*(1-s(h(1/s(x)))))<-1?b=-1:b>1&&(b=1),4==e)C=l(b),f.phi=k-C,f.lam=0==A?x+k:1==A?x<0?x+S:x-S:2==A?x-k:x;else if(5==e)C=l(b),f.phi=C-k,f.lam=0==A?-x+k:1==A?-x:2==A?-x-k:x<0?-x-S:-x+S;else{var D,P,N;E=(D=b)*D,P=(E+=(N=E>=1?0:u(1-E)*i(x))*N)>=1?0:u(1-E),1==A?(E=P,P=-N,N=E):2==A?(P=-P,N=-N):3==A&&(E=P,P=N,N=-E),1==e?(E=D,D=-P,P=E):2==e?(D=-D,P=-P):3==e&&(E=D,D=P,P=-E),f.phi=l(-N)-k,f.lam=c(P,D),1==e?f.lam=d(f.lam,-k):2==e?f.lam=d(f.lam,-S):3==e&&(f.lam=d(f.lam,+k))}0!==t.es&&(M=f.phi<0?1:0,I=a(f.phi),T=r/u(I*I+p),f.phi=h(u(t.a*t.a-T*T)/(o*T)),M&&(f.phi=-f.phi))}},"qsc","Quadrilateralized Spherical Cube","Azi, Sph."),Q(function(t){var e=h([[1,22199e-21,-715515e-10,31103e-10],[.9986,-482243e-9,-24897e-9,-13309e-10],[.9954,-83103e-8,-448605e-10,-9.86701e-7],[.99,-.00135364,-59661e-9,36777e-10],[.9822,-.00167442,-449547e-11,-572411e-11],[.973,-.00214868,-903571e-10,1.8736e-8],[.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,9.34959e-7],[.7986,-.00755338,-500009e-10,9.35324e-7],[.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]]),i=h([[-520417e-23,.0124,121431e-23,-845284e-16],[.062,.0124,-1.26793e-9,4.22642e-10],[.124,.0124,5.07171e-9,-1.60604e-9],[.186,.0123999,-1.90189e-8,6.00152e-9],[.248,.0124002,7.10039e-8,-2.24e-8],[.31,.0123992,-2.64997e-7,8.35986e-8],[.372,.0124029,9.88983e-7,-3.11994e-7],[.434,.0123893,-369093e-11,-4.35621e-7],[.4958,.0123198,-102252e-10,-3.45523e-7],[.5571,.0121916,-154081e-10,-5.82288e-7],[.6176,.0119938,-241424e-10,-5.25327e-7],[.6769,.011713,-320223e-10,-5.16405e-7],[.7346,.0113541,-397684e-10,-6.09052e-7],[.7903,.0109107,-489042e-10,-104739e-11],[.8435,.0103431,-64615e-9,-1.40374e-9],[.8936,.00969686,-64636e-9,-8547e-9],[.9394,.00840947,-192841e-9,-42106e-10],[.9761,.00616527,-256e-6,-42106e-10],[1,.00328947,-319159e-9,-42106e-10]]),s=.8487,a=1.3523;function o(t,e){return t[0]+e*(t[1]+e*(t[2]+e*t[3]))}function l(t,e){return t[1]+e*(t[2]+t[2]+3*e*t[3])}function h(t){return t.map(function(t){return new Float32Array(t)})}t.es=0,t.fwd=function(t,l){var h,c;(h=r(11.459155902616464*(c=n(t.phi))))<0&&U(),h>=18&&(h=17),c=x*(c-.08726646259971647*h),l.x=o(e[h],c)*s*t.lam,l.y=o(i[h],c)*a,t.phi<0&&(l.y=-l.y)},t.inv=function(t,h){var c,u,p,_;if(h.lam=t.x/s,h.phi=n(t.y/a),h.phi>=1)h.phi>1.000001?q():(h.phi=t.y<0?-k:k,h.lam/=e[18][0]);else{if((_=r(18*h.phi))<0||_>=18)return q();for(;;)if(i[_][0]>h.phi)--_;else{if(!(i[_+1][0]<=h.phi))break;++_}for(p=new Float32Array(i[_]),c=5*(h.phi-p[0])/(i[_+1][0]-p[0]),p[0]-=h.phi;c-=u=o(p,c)/l(p,c),!(n(u)<1e-8););h.phi=(5*_+c)*b,t.y<0&&(h.phi=-h.phi),h.lam/=o(e[_],c)}}},"robin","Robinson","PCyl., Sph."),Q(Ur("EULER"),"euler","Euler","Conic, Sph\nlat_1= and lat_2="),Q(Ur("MURD1"),"murd1","Murdoch I","Conic, Sph\nlat_1= and lat_2="),Q(Ur("MURD2"),"murd2","Murdoch II","Conic, Sph\nlat_1= and lat_2="),Q(Ur("MURD3"),"murd3","Murdoch III","Conic, Sph\nlat_1= and lat_2="),Q(Ur("PCONIC"),"pconic","Perspective Conic","Conic, Sph\nlat_1= and lat_2="),Q(Ur("TISSOT"),"tissot","Tissot","Conic, Sph\nlat_1= and lat_2="),Q(Ur("VITK1"),"vitk1","Vitkovsky I","Conic, Sph\nlat_1= and lat_2="),Q(function(t){var e,r,o,l,c,p,f,m,g;o=.5*t.e,f=s(t.phi0),f*=f,r=u(1+t.es*f*f*t.rone_es),g=i(t.phi0),c=s(m=pr(p=g/r)),g*=t.e,e=d(a(A+.5*m))-r*(d(a(A+.5*t.phi0))-o*d((1+g)/(1-g))),l=t.k0*u(t.one_es)/(1-g*g),t.inv=function(u,f){var m,g,y,v,w,S,x,b,C;for(y=2*(h(_(u.y/l))-A),v=u.x/l,w=s(y),m=pr(c*i(y)+p*w*s(v)),g=pr(w*i(v)/s(m)),x=(e-d(a(A+.5*m)))/r,C=6;C&&(S=t.e*i(m),m-=b=(x+d(a(A+.5*m))-o*d((1+S)/(1-S)))*(1-S*S)*s(m)*t.rone_es,!(n(b)<1e-10));--C);C?(f.phi=m,f.lam=g/r):q()},t.fwd=function(n,u){var f,m,g,y,v,w;v=t.e*i(n.phi),f=2*h(_(r*(d(a(A+.5*n.phi))-o*d((1+v)/(1-v)))+e))-k,m=r*n.lam,w=s(f),g=pr(c*i(f)-p*w*s(m)),y=pr(w*i(m)/s(g)),u.x=l*y,u.y=l*d(a(A+.5*g))}},"somerc","Swiss. Obl. Mercator","Cyl, Ell\nFor CH1903"),Q(function(t){var e=Z(t.params,"tlat_ts")?Z(t.params,"rlat_ts"):k;qr(t,e)},"stere","Stereographic","Azi, Sph&Ell\nlat_ts="),Q(function(t){t.phi0=Z(t.params,"bsouth")?-k:k,t.k0=.994,t.x0=2e6,t.y0=2e6,t.lam0=0,t.es||z(-34);qr(t,k)},"ups","Universal Polar Stereographic","Azi, Sph&Ell\nsouth"),Q(function(t){var e=(m=t.e,g=t.phi0,y=m*m,v=i(g),w=s(g),S=u(1-y)/(1-y*v*v),x=u(1+y*w*w*w*w/(1-y)),b=o(v/x),C=.5*x*m,{e:m,K:a(.5*b+A)/(p(a(.5*g+A),x)*jr(m*v,C)),C:x,chi:b,ratexp:C,rc:S}),r=e.chi,l=2*e.rc,_=i(r),d=s(r);var m,g,y,v,w,S,x,b,C;t.fwd=function(n,r){var o,c,u,f;n=function(t,e){return{phi:2*h(e.K*p(a(.5*t.phi+A),e.C)*jr(e.e*i(t.phi),e.ratexp))-k,lam:e.C*t.lam}}(n,e),c=i(n.phi),o=s(n.phi),u=s(n.lam),f=t.k0*l/(1+_*c+d*o*u),r.x=f*o*i(n.lam),r.y=f*(d*c-_*o*u)},t.inv=function(u,m){var g,y,v,w,S=u.x/t.k0,x=u.y/t.k0;(g=f(S,x))?(y=2*c(g,l),v=i(y),w=s(y),m.phi=o(w*_+x*v*d/g),m.lam=c(S*v,g*d*w-x*_*v)):(m.phi=r,m.lam=0),function(t,e){t.phi;var r,s,o=p(a(.5*t.phi+A)/e.K,1/e.C);for(t.lam/=e.C,r=20;r>0&&(s=2*h(o*jr(e.e*i(t.phi),-.5*e.e))-k,!(n(s-t.phi)<1e-14));--r)t.phi=s;r||F(-17)}(m,e)}},"sterea","Oblique Stereographic Alternative","Azimuthal, Sph&Ell"),Q(function(t){zr(t,1.50488,1.35439,!1)},"kav5","Kavraisky V","PCyl., Sph."),Q(function(t){zr(t,2,2,!1)},"qua_aut","Quartic Authalic","PCyl., Sph."),Q(function(t){zr(t,2,2,!0)},"fouc","Foucaut","PCyl., Sph."),Q(function(t){zr(t,1.48875,1.36509,!1)},"mbt_s","McBryde-Thomas Flat-Polar Sine (No. 1)","PCyl., Sph."),Q(function(t){t.es=0,t.fwd=function(e,n){n.x=s(e.phi)*i(e.lam)/t.k0,n.y=t.k0*(c(a(e.phi),s(e.lam))-t.phi0)},t.inv=function(e,n){var r;e.y=e.y/t.k0+t.phi0,e.x*=t.k0,r=u(1-e.x*e.x),n.phi=o(r*i(e.y)),n.lam=c(e.x,r*s(e.y))}},"tcea","Transverse Cylindrical Equal Area","Cyl, Sph"),Q(function(t){t.es=0,t.fwd=function(t,e){var n=a(t.phi/2),r=i(A*n);e.x=t.lam*(.74482-.34588*r*r),e.y=1.70711*n},t.inv=function(t,e){var n=t.y/1.70711,r=i(A*n);e.lam=t.x/(.74482-.34588*r*r),e.phi=2*h(n)}},"times","Times","Cyl, Sph"),Q(function(t){Z(t.params,"bapprox")?Br(t):function(t){if(0===t.es)return Br(t);Sr(t);var e=t.fwd,r=t.inv;Br(t);var i=t.fwd,s=t.inv;t.fwd=function(t,r){n(t.lam)>3*b?e(t,r):i(t,r)},t.inv=function(t,e){n(t.x)>.053-.022*t.y*t.y?r(t,e):s(t,e)}}(t)},"tmerc","Transverse Mercator","Cyl, Sph&Ell"),Q(function(t){var e;t.es||z(-34);t.y0=Z(t.params,"bsouth")?1e7:0,t.x0=5e5,Z(t.params,"tzone")?(e=Z(t.params,"izone"))>0&&e<=60?--e:z(-35):(e=r(30*(At(t.lam0)+S)/S))<0?e=0:e>=60&&(e=59);t.lam0=(e+.5)*S/30-S,t.k0=.9996,t.phi0=0,Sr(t)},"utm","Universal Transverse Mercator (UTM)","Cyl, Sph\nzone= south"),Q(function(t){var e,n,r,o,l,h,u,p,_,d,m,g,y,v,w,S,x,b,C,E,A,M,I;E=Z(t.params,"rlat_1"),b=Z(t.params,"rlon_1"),A=Z(t.params,"rlat_2"),C=Z(t.params,"rlon_2"),E==A&&b==C&&z(-25);t.lam0=At(.5*(b+C)),d=At(C-b),e=s(E),r=s(A),n=i(E),o=i(A),h=e*o,u=n*r,l=e*r*i(d),_=_r(n*o+e*r*s(d)),m=.5*_,M=c(r*i(d),e*o-n*r*s(d)),v=s(I=pr(e*i(M))),w=i(I),S=At(c(e*s(M),n)-m),d*=.5,x=k-c(i(M)*n,s(M))-d,g=a(m),y=.5/i(m),p=.5/_,_*=_,t.fwd=function(t,a){var c,f,m,g,y,v,w;v=i(t.phi),w=s(t.phi),f=_r(n*v+e*w*s(g=t.lam+d)),m=_r(o*v+r*w*s(y=t.lam-d)),f*=f,m*=m,a.x=p*(c=f-m),c=_-c,a.y=p*dr(4*_*m-c*c),l*v-w*(h*i(g)-u*i(y))<0&&(a.y=-a.y)},t.inv=function(t,e){var n,r,a,o,l,h;a=(n=s(f(t.y,t.x+m)))+(r=s(f(t.y,t.x-m))),o=n-r,e.lam=-c(o,a*g),e.phi=_r(f(g*a,o)*y),t.y<0&&(e.phi=-e.phi),h=i(e.phi),l=s(e.phi),e.phi=pr(w*h+v*l*(a=s(e.lam-=S))),e.lam=c(l*i(e.lam),w*l*a-v*h)+x},t.es=0},"tpeqd","Two Point Equidistant","Misc Sph\nlat_1= lon_1= lat_2= lon_2="),Q(function(t){var e,n,r,a,o,l;(a=Z(t.params,"dn"))>0&&a<=1==!1&&z(-40);r=Z(t.params,"dq")/3,o=Z(t.params,"ralpha"),l=a*i(o),e=s(o)/u(1-l*l),n=1/(e*a),t.fwd=function(t,o){var l=t.phi=pr(a*i(t.phi));o.x=e*t.lam*s(t.phi),l*=l,o.y=t.phi*(1+l*r)*n},t.es=0},"urm5","Urmaev V","PCyl., Sph., no inv.\nn= q= alpha="),Q(function(t){var e=Z(t.params,"dn");(e<=0||e>1)&&z(-40);Vr(t,e)},"urmfps","Urmaev Flat-Polar Sinusoidal","PCyl, Sph.\nn="),Q(function(t){Vr(t,.8660254037844386)},"wag1","Wagner I (Kavraisky VI)","PCyl, Sph."),Q(function(t){var e=1e-10,r=.3333333333333333,i=9.869604401089358,h=19.739208802178716,c=4.934802200544679;t.fwd=function(t,r){var i,s,l,h,c;(c=n(t.phi/k))-e>1&&U(),c>1&&(c=1),n(t.phi)<=e?(r.x=t.lam,r.y=0):n(t.lam)<=e||n(c-1)<e?(r.x=0,r.y=S*a(.5*o(c)),t.phi<0&&(r.y=-r.y)):(s=(i=.5*n(S/t.lam-t.lam/S))*i,l=u(1-c*c),h=(l/=c+l-1)*l,c=l*(2/c-1),c*=c,r.x=l-c,l=c+s,r.x=S*(i*r.x+u(s*r.x*r.x-l*(h-c)))/l,t.lam<0&&(r.x=-r.x),r.y=n(r.x/S),r.y=1-r.y*(r.y+2*i),r.y<-e&&U(),r.y<0?r.y=0:r.y=u(r.y)*(t.phi<0?-S:S))},t.inv=function(t,a){var o,p,_,d,f,m,g,y,v,w,x,b,C;if(b=t.x*t.x,(x=n(t.y))<e)return a.phi=0,o=b*b+h*(b+c),a.lam=n(t.x)<=e?0:.5*(b-i+u(o))/t.x,a;C=t.y*t.y,d=(_=-S*x*((y=b+C)+i))+i*(y-3*C),p=S*x,v=2*u(-r*(m=_/(f=(g=y*y)+I*(x*y+S*(C+S*(x+k))))-r*(d/=f)*d)),(o=n(w=3*(w=.07407407407407407*d*d*d+(p*p-r*d*_)/f)/(m*v)))-e<=1?(w=o>1?w>0?0:S:l(w),a.phi=S*(v*s(w*r+4.188790204786391)-r*d),t.y<0&&(a.phi=-a.phi),o=g+h*(b-C+c),a.lam=n(t.x)<=e?0:.5*(y-i+(o<=0?0:u(o)))/t.x):q()}},"vandg","van der Grinten (I)","Misc Sph"),Q(function(t){$r(t,!1)},"vandg2","van der Grinten II","Misc Sph, no inv."),Q(function(t){$r(t,!0)},"vandg3","van der Grinten III","Misc Sph, no inv."),Q(function(t){t.es=0,t.fwd=function(t,e){var r,i,s,a,o,l,h,c,p=1e-10;n(t.phi)<p?(e.x=t.lam,e.y=0):n(t.lam)<p||n(n(t.phi)-k)<p?(e.x=0,e.y=t.phi):(l=(a=.5*((s=n(T*t.phi))*(8-s*(2+(o=s*s)))-5)/(o*(s-1)))*a,h=T*t.lam,h=u((h+=1/h)*h-4),n(t.lam)-k<0&&(h=-h),r=s+a,r=(h*((r*=r)+l-1)+2*u(r*(o+l*(c=h*h)-1)+(1-o)*(o*((i=s+3*a)*i+4*l)+l*(12*s*a+4*l))))/(4*r+c),e.x=k*r,e.y=k*u(1+h*n(r)-r*r),t.lam<0&&(e.x=-e.x),t.phi<0&&(e.y=-e.y))}},"vandg4","van der Grinten IV","Misc Sph, no inv."),Q(function(t){var e=.92483,n=1.38725,r=.88022,a=.8855;t.fwd=function(t,o){t.phi=pr(r*i(a*t.phi)),o.x=e*t.lam*s(t.phi),o.y=n*t.phi},t.inv=function(t,o){o.phi=t.y/n,o.lam=t.x/(e*s(o.phi)),o.phi=pr(i(o.phi)/r)/a}},"wag2","Wagner II","PCyl., Sph."),Q(function(t){var e=.6666666666666666,n=Z(t.params,"rlat_ts"),r=s(n)/s(2*n/3);t.es=0,t.fwd=function(t,n){n.x=r*t.lam*s(e*t.phi),n.y=t.phi},t.inv=function(t,n){n.phi=t.y,n.lam=t.x/(r*s(e*n.phi))}},"wag3","Wagner III","PCyl., Sph.\nlat_ts="),Q(function(t){t.es=0,t.fwd=function(t,e){var n,r,a;n=o(e.y=.9063077870366499*i(t.phi)),e.x=2.66723*(r=s(n))*i(t.lam/=3),e.y*=1.24104*(a=1/u(.5*(1+r*s(t.lam)))),e.x*=a}},"wag7","Wagner VII","Misc Sph, no inv."),Q(function(t){var e=s(Z(t.params,"rlat_ts"));t.fwd=function(t,n){n.x=.5*t.lam*(e+s(t.phi)),n.y=t.phi},t.inv=function(t,n){n.phi=t.y,n.lam=2*t.x/(e+s(n.phi))},t.es=0},"wink1","Winkel I","PCyl., Sph.\nlat_ts="),Q(function(t){var e=s(Z(t.params,"rlat_1"));t.fwd=function(t,r){var a,o,l,h=t.phi;for(r.y=h*T,a=S*i(h),h*=1.8,l=10;l&&(h-=o=(h+i(h)-a)/(1+s(h)),!(n(o)<1e-7));--l);l?h*=.5:h=h<0?-k:k,r.x=.5*t.lam*(s(h)+e),r.y=A*(i(h)+r.y)},t.inv=null,t.es=0},"wink2","Winkel II","PCyl., Sph., no inv.\nlat_1=");var Wr=Tt;Wr.pj_init=ft,Wr.pj_fwd=kt,Wr.pj_inv=Mt,Wr.pj_transform=xt,Wr.pj_add=Q,Wr.pj_fwd_deg=function(t,e){return kt({lam:t.lam*b,phi:t.phi*b},e)},Wr.pj_inv_deg=function(t,e){var n=Mt(t,e);return{lam:n.lam*x,phi:n.phi*x}},Wr.pj_transform_point=St,Wr.internal={dmstod:W,dmstor:$,get_rtodms:function(t,e,n,r){var i=It(t,e,n,r);return function(t){return i(t*x)}},get_dtodms:It,get_proj_defn:nt,pj_latlong_from_proj:function(t){return ft("+proj=latlong"+et(t))},pj_get_params:J,pj_datums:it,pj_list:Y,pj_ellps:ot,pj_units:ht,pj_read_init_opts:dt,find_datum:at,DEG_TO_RAD:b,RAD_TO_DEG:x,wkt_parse:qe,wkt_unpack:je,convert_wkt_quotes:ze,wkt_to_proj4:function(t){var e,n=qe(t);return n.PROJCS?e=Jt(n.PROJCS):n.GEOGCS?e="+proj=longlat "+Ht(n.GEOGCS):n.GEOCCS?Bt("geocentric coordinates are not supported"):Bt("missing a supported WKT CS type"),e},wkt_from_proj4:function(t){return t.length&&(t=ft(t)),Oe(tt(t)?{GEOGCS:Qt(t)}:ae(t))},wkt2_to_proj4:Fn,wkt2_from_proj4:Un,projjson_to_proj4:function(t){return Fn(an(qn("string"==typeof t||t instanceof String?JSON.parse(String(t)):t)))},projjson_from_proj4:function(t,e){var n,r=hn(Un(t)),i=((n=Kn(r)).$schema="https://proj.org/schemas/v0.7/projjson.schema.json",n);return e&&e.as_object?i:JSON.stringify(i,null,e&&e.pretty?2:0)},wkt2_parse:hn,wkt2_normalize:En,wkt_make_projcs:ae,wkt_get_geogcs_name:ne,wkt_stringify:Oe,mproj_insert_libcache:function(t,e){pt[t]=e},mproj_search_libcache:_t,GeographicLib:sr};class Hr{constructor(){this.ids=[],this.values=[],this.length=0}clear(){this.length=0}push(t,e){let n=this.length++;for(;n>0;){const t=n-1>>1,r=this.values[t];if(e>=r)break;this.ids[n]=this.ids[t],this.values[n]=r,n=t}this.ids[n]=t,this.values[n]=e}pop(){if(0===this.length)return;const t=this.ids,e=this.values,n=t[0],r=--this.length;if(r>0){const n=t[r],i=e[r];let s=0;const a=r>>1;for(;s<a;){const n=1+(s<<1),a=n+1,o=n+(+(a<r)&+(e[a]<e[n]));if(e[o]>=i)break;t[s]=t[o],e[s]=e[o],s=o}t[s]=n,e[s]=i}return n}peek(){return this.length>0?this.ids[0]:void 0}peekValue(){return this.length>0?this.values[0]:void 0}shrink(){this.ids.length=this.values.length=this.length}}const Kr=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class Zr{static from(t,e=0){if(e%8!=0)throw new Error("byteOffset must be 8-byte aligned.");if(!t||void 0===t.byteLength||t.buffer)throw new Error("Data must be an instance of ArrayBuffer or SharedArrayBuffer.");const[n,r]=new Uint8Array(t,e+0,2);if(251!==n)throw new Error("Data does not appear to be in a Flatbush format.");const i=r>>4;if(3!==i)throw new Error(`Got v${i} data when expected v3.`);const s=Kr[15&r];if(!s)throw new Error("Unrecognized array type.");const[a]=new Uint16Array(t,e+2,1),[o]=new Uint32Array(t,e+4,1);return new Zr(o,a,s,void 0,t,e)}constructor(t,e=16,n=Float64Array,r=ArrayBuffer,i,s=0){if(void 0===t)throw new Error("Missing required argument: numItems.");if(isNaN(t)||t<=0)throw new Error(`Unexpected numItems value: ${t}.`);this.numItems=+t,this.nodeSize=Math.min(Math.max(+e,2),65535),this.byteOffset=s;let a=t,o=a;this._levelBounds=[4*a];do{a=Math.ceil(a/this.nodeSize),o+=a,this._levelBounds.push(4*o)}while(1!==a);this.ArrayType=n,this.IndexArrayType=o<16384?Uint16Array:Uint32Array;const l=Kr.indexOf(n),h=4*o*n.BYTES_PER_ELEMENT;if(l<0)throw new Error(`Unexpected typed array class: ${n}.`);if(i)this.data=i,this._boxes=new n(i,s+8,4*o),this._indices=new this.IndexArrayType(i,s+8+h,o),this._pos=4*o,this.minX=this._boxes[this._pos-4],this.minY=this._boxes[this._pos-3],this.maxX=this._boxes[this._pos-2],this.maxY=this._boxes[this._pos-1];else{const i=this.data=new r(8+h+o*this.IndexArrayType.BYTES_PER_ELEMENT);this._boxes=new n(i,8,4*o),this._indices=new this.IndexArrayType(i,8+h,o),this._pos=0,this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,new Uint8Array(i,0,2).set([251,48+l]),new Uint16Array(i,2,1)[0]=e,new Uint32Array(i,4,1)[0]=t}this._queue=new Hr}add(t,e,n=t,r=e){const i=this._pos>>2,s=this._boxes;return this._indices[i]=i,s[this._pos++]=t,s[this._pos++]=e,s[this._pos++]=n,s[this._pos++]=r,t<this.minX&&(this.minX=t),e<this.minY&&(this.minY=e),n>this.maxX&&(this.maxX=n),r>this.maxY&&(this.maxY=r),i}finish(){if(this._pos>>2!==this.numItems)throw new Error(`Added ${this._pos>>2} items when expected ${this.numItems}.`);const t=this._boxes;if(this.numItems<=this.nodeSize)return t[this._pos++]=this.minX,t[this._pos++]=this.minY,t[this._pos++]=this.maxX,void(t[this._pos++]=this.maxY);const e=this.maxX-this.minX||1,n=this.maxY-this.minY||1,r=new Uint32Array(this.numItems);for(let i=0,s=0;i<this.numItems;i++){const a=t[s++],o=t[s++],l=t[s++],h=t[s++],c=Math.floor(65535*((a+l)/2-this.minX)/e),u=Math.floor(65535*((o+h)/2-this.minY)/n);r[i]=Qr(c,u)}Xr(r,t,this._indices,0,this.numItems-1,this.nodeSize);for(let e=0,n=0;e<this._levelBounds.length-1;e++){const r=this._levelBounds[e];for(;n<r;){const e=n;let i=t[n++],s=t[n++],a=t[n++],o=t[n++];for(let e=1;e<this.nodeSize&&n<r;e++)i=Math.min(i,t[n++]),s=Math.min(s,t[n++]),a=Math.max(a,t[n++]),o=Math.max(o,t[n++]);this._indices[this._pos>>2]=e,t[this._pos++]=i,t[this._pos++]=s,t[this._pos++]=a,t[this._pos++]=o}}}search(t,e,n,r,i){if(this._pos!==this._boxes.length)throw new Error("Data not yet indexed - call index.finish().");let s=this._boxes.length-4;const a=[],o=[];for(;void 0!==s;){const l=Math.min(s+4*this.nodeSize,Jr(s,this._levelBounds));for(let h=s;h<l;h+=4){const l=this._boxes[h];if(n<l)continue;const c=this._boxes[h+1];if(r<c)continue;const u=this._boxes[h+2];if(t>u)continue;const p=this._boxes[h+3];if(e>p)continue;const _=0|this._indices[h>>2];s>=4*this.numItems?a.push(_):(void 0===i||i(_,l,c,u,p))&&o.push(_)}s=a.pop()}return o}neighbors(t,e,n=1/0,r=1/0,i){if(this._pos!==this._boxes.length)throw new Error("Data not yet indexed - call index.finish().");let s=this._boxes.length-4;const a=this._queue,o=[],l=r*r;t:for(;void 0!==s;){const r=Math.min(s+4*this.nodeSize,Jr(s,this._levelBounds));for(let n=s;n<r;n+=4){const r=0|this._indices[n>>2],o=this._boxes[n],h=this._boxes[n+1],c=this._boxes[n+2],u=this._boxes[n+3],p=t<o?o-t:t>c?t-c:0,_=e<h?h-e:e>u?e-u:0,d=p*p+_*_;d>l||(s>=4*this.numItems?a.push(r<<1,d):(void 0===i||i(r))&&a.push(1+(r<<1),d))}for(;a.length&&1&a.peek();){if(a.peekValue()>l)break t;if(o.push(a.pop()>>1),o.length===n)break t}s=a.length?a.pop()>>1:void 0}return a.clear(),o}}function Jr(t,e){let n=0,r=e.length-1;for(;n<r;){const i=n+r>>1;e[i]>t?r=i:n=i+1}return e[n]}function Xr(t,e,n,r,i,s){if(Math.floor(r/s)>=Math.floor(i/s))return;const a=t[r],o=t[r+i>>1],l=t[i];let h=l;const c=Math.max(a,o);l>c?h=c:c===a?h=Math.max(o,l):c===o&&(h=Math.max(a,l));let u=r-1,p=i+1;for(;;){do{u++}while(t[u]<h);do{p--}while(t[p]>h);if(u>=p)break;Yr(t,e,n,u,p)}Xr(t,e,n,r,p,s),Xr(t,e,n,p+1,i,s)}function Yr(t,e,n,r,i){const s=t[r];t[r]=t[i],t[i]=s;const a=4*r,o=4*i,l=e[a],h=e[a+1],c=e[a+2],u=e[a+3];e[a]=e[o],e[a+1]=e[o+1],e[a+2]=e[o+2],e[a+3]=e[o+3],e[o]=l,e[o+1]=h,e[o+2]=c,e[o+3]=u;const p=n[r];n[r]=n[i],n[i]=p}function Qr(t,e){let n=t^e,r=65535^n,i=65535^(t|e),s=t&(65535^e),a=n|r>>1,o=n>>1^n,l=i>>1^r&s>>1^i,h=n&i>>1^s>>1^s;n=a,r=o,i=l,s=h,a=n&n>>2^r&r>>2,o=n&r>>2^r&(n^r)>>2,l^=n&i>>2^r&s>>2,h^=r&i>>2^(n^r)&s>>2,n=a,r=o,i=l,s=h,a=n&n>>4^r&r>>4,o=n&r>>4^r&(n^r)>>4,l^=n&i>>4^r&s>>4,h^=r&i>>4^(n^r)&s>>4,n=a,r=o,i=l,s=h,l^=n&i>>8^r&s>>8,h^=r&i>>8^(n^r)&s>>8,n=l^l>>1,r=h^h>>1;let c=t^e,u=r|65535^(c|n);return c=16711935&(c|c<<8),c=252645135&(c|c<<4),c=858993459&(c|c<<2),c=1431655765&(c|c<<1),u=16711935&(u|u<<8),u=252645135&(u|u<<4),u=858993459&(u|u<<2),u=1431655765&(u|u<<1),(u<<1|c)>>>0}const ti=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class ei{static from(t){if(!(t instanceof ArrayBuffer))throw new Error("Data must be an instance of ArrayBuffer.");const[e,n]=new Uint8Array(t,0,2);if(219!==e)throw new Error("Data does not appear to be in a KDBush format.");const r=n>>4;if(1!==r)throw new Error(`Got v${r} data when expected v1.`);const i=ti[15&n];if(!i)throw new Error("Unrecognized array type.");const[s]=new Uint16Array(t,2,1),[a]=new Uint32Array(t,4,1);return new ei(a,s,i,t)}constructor(t,e=64,n=Float64Array,r){if(isNaN(t)||t<0)throw new Error(`Unpexpected numItems value: ${t}.`);this.numItems=+t,this.nodeSize=Math.min(Math.max(+e,2),65535),this.ArrayType=n,this.IndexArrayType=t<65536?Uint16Array:Uint32Array;const i=ti.indexOf(this.ArrayType),s=2*t*this.ArrayType.BYTES_PER_ELEMENT,a=t*this.IndexArrayType.BYTES_PER_ELEMENT,o=(8-a%8)%8;if(i<0)throw new Error(`Unexpected typed array class: ${n}.`);r&&r instanceof ArrayBuffer?(this.data=r,this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+a+o,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+s+a+o),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+a+o,2*t),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+i]),new Uint16Array(this.data,2,1)[0]=e,new Uint32Array(this.data,4,1)[0]=t)}add(t,e){const n=this._pos>>1;return this.ids[n]=n,this.coords[this._pos++]=t,this.coords[this._pos++]=e,n}finish(){const t=this._pos>>1;if(t!==this.numItems)throw new Error(`Added ${t} items when expected ${this.numItems}.`);return ni(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}range(t,e,n,r){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:i,coords:s,nodeSize:a}=this,o=[0,i.length-1,0],l=[];for(;o.length;){const h=o.pop()||0,c=o.pop()||0,u=o.pop()||0;if(c-u<=a){for(let a=u;a<=c;a++){const o=s[2*a],h=s[2*a+1];o>=t&&o<=n&&h>=e&&h<=r&&l.push(i[a])}continue}const p=u+c>>1,_=s[2*p],d=s[2*p+1];_>=t&&_<=n&&d>=e&&d<=r&&l.push(i[p]),(0===h?t<=_:e<=d)&&(o.push(u),o.push(p-1),o.push(1-h)),(0===h?n>=_:r>=d)&&(o.push(p+1),o.push(c),o.push(1-h))}return l}within(t,e,n){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:r,coords:i,nodeSize:s}=this,a=[0,r.length-1,0],o=[],l=n*n;for(;a.length;){const h=a.pop()||0,c=a.pop()||0,u=a.pop()||0;if(c-u<=s){for(let n=u;n<=c;n++)ai(i[2*n],i[2*n+1],t,e)<=l&&o.push(r[n]);continue}const p=u+c>>1,_=i[2*p],d=i[2*p+1];ai(_,d,t,e)<=l&&o.push(r[p]),(0===h?t-n<=_:e-n<=d)&&(a.push(u),a.push(p-1),a.push(1-h)),(0===h?t+n>=_:e+n>=d)&&(a.push(p+1),a.push(c),a.push(1-h))}return o}}function ni(t,e,n,r,i,s){if(i-r<=n)return;const a=r+i>>1;ri(t,e,a,r,i,s),ni(t,e,n,r,a-1,1-s),ni(t,e,n,a+1,i,1-s)}function ri(t,e,n,r,i,s){for(;i>r;){if(i-r>600){const a=i-r+1,o=n-r+1,l=Math.log(a),h=.5*Math.exp(2*l/3),c=.5*Math.sqrt(l*h*(a-h)/a)*(o-a/2<0?-1:1);ri(t,e,n,Math.max(r,Math.floor(n-o*h/a+c)),Math.min(i,Math.floor(n+(a-o)*h/a+c)),s)}const a=e[2*n+s];let o=r,l=i;for(ii(t,e,r,n),e[2*i+s]>a&&ii(t,e,r,i);o<l;){for(ii(t,e,o,l),o++,l--;e[2*o+s]<a;)o++;for(;e[2*l+s]>a;)l--}e[2*r+s]===a?ii(t,e,r,l):(l++,ii(t,e,l,i)),l<=n&&(r=l+1),n<=l&&(i=l-1)}}function ii(t,e,n,r){si(t,n,r),si(e,2*n,2*r),si(e,2*n+1,2*r+1)}function si(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}function ai(t,e,n,r){const i=t-n,s=e-r;return i*i+s*s}function oi(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var li,hi,ci,ui={exports:{}};li=ui,(ci={}).Constants={},ci.Math={},ci.Accumulator={},function(t){t.WGS84={a:6378137,f:1/298.257223563},t.version={major:2,minor:2,patch:0},t.version_string="2.2.0"}(ci.Constants),function(t){t.digits=53,t.epsilon=Math.pow(.5,t.digits-1),t.degree=Math.PI/180,t.sq=function(t){return t*t},t.hypot=function(t,e){return Math.sqrt(t*t+e*e)},t.cbrt=Math.cbrt||function(t){var e=Math.pow(Math.abs(t),1/3);return t>0?e:t<0?-e:t},t.log1p=Math.log1p||function(t){var e=1+t,n=e-1;return 0===n?t:t*Math.log(e)/n},t.atanh=Math.atanh||function(e){var n=Math.abs(e);return n=t.log1p(2*n/(1-n))/2,e>0?n:e<0?-n:e},t.copysign=function(t,e){return Math.abs(t)*(e<0||0===e&&1/e<0?-1:1)},t.sum=function(t,e){var n=t+e,r=n-e,i=n-r;return r-=t,{s:n,t:n?0-(r+(i-=e)):n}},t.polyval=function(t,e,n,r){for(var i=t<0?0:e[n++];--t>=0;)i=i*r+e[n++];return i},t.AngRound=function(e){var n=1/16,r=Math.abs(e);return r=r<n?n-(n-r):r,t.copysign(r,e)},t.remainder=function(t,e){return(t%=e)<-e/2?t+e:t<e/2?t:t-e},t.AngNormalize=function(e){var n=t.remainder(e,360);return 180===Math.abs(n)?t.copysign(180,e):n},t.LatFix=function(t){return Math.abs(t)>90?NaN:t},t.AngDiff=function(e,n){var r,i,s=t.sum(t.remainder(-e,360),t.remainder(n,360));return r=(s=t.sum(t.remainder(s.s,360),s.t)).s,i=s.t,0!==r&&180!==Math.abs(r)||(r=t.copysign(r,0===i?n-e:-i)),{d:r,e:i}},t.sincosd=function(e){var n,r,i,s,a,o,l;switch(n=e%360,r=(n-=90*(i=Math.round(n/90)))*this.degree,s=Math.sin(r),a=Math.cos(r),45===Math.abs(n)?(a=Math.sqrt(.5),s=t.copysign(a,r)):30===Math.abs(n)&&(a=Math.sqrt(.75),s=t.copysign(.5,r)),3&i){case 0:o=s,l=a;break;case 1:o=a,l=-s;break;case 2:o=-s,l=-a;break;default:o=-a,l=s}return l+=0,0===o&&(o=t.copysign(o,e)),{s:o,c:l}},t.sincosde=function(e,n){var r,i,s,a,o,l,h;switch(r=e%360,s=Math.round(r/90),i=(r=t.AngRound(r-90*s+n))*this.degree,a=Math.sin(i),o=Math.cos(i),45===Math.abs(r)?(o=Math.sqrt(.5),a=t.copysign(o,i)):30===Math.abs(r)&&(o=Math.sqrt(.75),a=t.copysign(.5,i)),3&s){case 0:l=a,h=o;break;case 1:l=o,h=-a;break;case 2:l=-a,h=-o;break;default:l=-o,h=a}return h+=0,0===l&&(l=t.copysign(l,e+n)),{s:l,c:h}},t.atan2d=function(e,n){var r,i=0;switch(Math.abs(e)>Math.abs(n)&&([e,n]=[n,e],i=2),t.copysign(1,n)<0&&(n=-n,++i),r=Math.atan2(e,n)/this.degree,i){case 1:r=t.copysign(180,e)-r;break;case 2:r=90-r;break;case 3:r=-90+r}return r}}(ci.Math),function(t,e){t.Accumulator=function(t){this.Set(t)},t.Accumulator.prototype.Set=function(e){e||(e=0),e.constructor===t.Accumulator?(this._s=e._s,this._t=e._t):(this._s=e,this._t=0)},t.Accumulator.prototype.Add=function(t){var n=e.sum(t,this._t),r=e.sum(n.s,this._s);n=n.t,this._s=r.s,this._t=r.t,0===this._s?this._s=n:this._t+=n},t.Accumulator.prototype.Sum=function(e){var n;return e?((n=new t.Accumulator(this)).Add(e),n._s):this._s},t.Accumulator.prototype.Negate=function(){this._s*=-1,this._t*=-1},t.Accumulator.prototype.Remainder=function(t){this._s=e.remainder(this._s,t),this.Add(0)}}(ci.Accumulator,ci.Math),ci.Geodesic={},ci.GeodesicLine={},ci.PolygonArea={},function(t,e,n,r,i){var s,a,o,l,h,c,u,p,_,d,f,m=20+r.digits+10,g=r.epsilon,y=200*g,v=Math.sqrt(g),w=g,S=1e3*v;t.tiny_=Math.sqrt(Number.MIN_VALUE/Number.EPSILON),t.nC1_=6,t.nC1p_=6,t.nC2_=6,t.nC3_=6,t.nC4_=6,s=t.nC3_*(t.nC3_-1)/2,a=t.nC4_*(t.nC4_+1)/2,t.CAP_C1=1,t.CAP_C1p=2,t.CAP_C2=4,t.CAP_C3=8,t.CAP_C4=16,t.NONE=0,t.ARC=64,t.LATITUDE=128,t.LONGITUDE=256|t.CAP_C3,t.AZIMUTH=512,t.DISTANCE=1024|t.CAP_C1,t.STANDARD=t.LATITUDE|t.LONGITUDE|t.AZIMUTH|t.DISTANCE,t.DISTANCE_IN=2048|t.CAP_C1|t.CAP_C1p,t.REDUCEDLENGTH=4096|t.CAP_C1|t.CAP_C2,t.GEODESICSCALE=8192|t.CAP_C1|t.CAP_C2,t.AREA=16384|t.CAP_C4,t.ALL=32671,t.LONG_UNROLL=32768,t.OUT_MASK=32640|t.LONG_UNROLL,t.SinCosSeries=function(t,e,n,r){var i=r.length,s=i-(t?1:0),a=2*(n-e)*(n+e),o=1&s?r[--i]:0,l=0;for(s=Math.floor(s/2);s--;)o=a*(l=a*o-l+r[--i])-o+r[--i];return t?2*e*n*o:n*(o-l)},o=function(t,e){var n,i,s,a,o,l,h,c,u,p,_,d,f=r.sq(t),m=r.sq(e),g=(f+m-1)/6;return 0===m&&g<=0?n=0:(l=g,(o=(i=f*m/4)*(i+2*(a=g*(s=r.sq(g)))))>=0?(h=i+a,h+=h<0?-Math.sqrt(o):Math.sqrt(o),l+=(c=r.cbrt(h))+(0!==c?s/c:0)):(u=Math.atan2(Math.sqrt(-o),-(i+a)),l+=2*g*Math.cos(u/3)),p=Math.sqrt(r.sq(l)+m),d=((_=l<0?m/(p-l):l+p)-m)/(2*p),n=_/(Math.sqrt(_+r.sq(d))+d)),n},l=[1,4,64,0,256],t.A1m1f=function(t){var e=Math.floor(3);return(r.polyval(e,l,0,r.sq(t))/l[e+1]+t)/(1-t)},h=[-1,6,-16,32,-9,64,-128,2048,9,-16,768,3,-5,512,-7,1280,-7,2048],t.C1f=function(e,n){var i,s,a=r.sq(e),o=e,l=0;for(i=1;i<=t.nC1_;++i)s=Math.floor((t.nC1_-i)/2),n[i]=o*r.polyval(s,h,l,a)/h[l+s+1],l+=s+2,o*=e},c=[205,-432,768,1536,4005,-4736,3840,12288,-225,116,384,-7173,2695,7680,3467,7680,38081,61440],t.C1pf=function(e,n){var i,s,a=r.sq(e),o=e,l=0;for(i=1;i<=t.nC1p_;++i)s=Math.floor((t.nC1p_-i)/2),n[i]=o*r.polyval(s,c,l,a)/c[l+s+1],l+=s+2,o*=e},u=[-11,-28,-192,0,256],t.A2m1f=function(t){var e=Math.floor(3);return(r.polyval(e,u,0,r.sq(t))/u[e+1]-t)/(1+t)},p=[1,2,16,32,35,64,384,2048,15,80,768,7,35,512,63,1280,77,2048],t.C2f=function(e,n){var i,s,a=r.sq(e),o=e,l=0;for(i=1;i<=t.nC2_;++i)s=Math.floor((t.nC2_-i)/2),n[i]=o*r.polyval(s,p,l,a)/p[l+s+1],l+=s+2,o*=e},t.Geodesic=function(t,e){if(this.a=t,this.f=e,this._f1=1-this.f,this._e2=this.f*(2-this.f),this._ep2=this._e2/r.sq(this._f1),this._n=this.f/(2-this.f),this._b=this.a*this._f1,this._c2=(r.sq(this.a)+r.sq(this._b)*(0===this._e2?1:(this._e2>0?r.atanh(Math.sqrt(this._e2)):Math.atan(Math.sqrt(-this._e2)))/Math.sqrt(Math.abs(this._e2))))/2,this._etol2=.1*v/Math.sqrt(Math.max(.001,Math.abs(this.f))*Math.min(1,1-this.f/2)/2),!(isFinite(this.a)&&this.a>0))throw new Error("Equatorial radius is not positive");if(!(isFinite(this._b)&&this._b>0))throw new Error("Polar semi-axis is not positive");this._A3x=new Array(6),this._C3x=new Array(s),this._C4x=new Array(a),this.A3coeff(),this.C3coeff(),this.C4coeff()},_=[-3,128,-2,-3,64,-1,-3,-1,16,3,-1,-2,8,1,-1,2,1,1],t.Geodesic.prototype.A3coeff=function(){var t,e,n=0,i=0;for(t=5;t>=0;--t)e=Math.min(6-t-1,t),this._A3x[i++]=r.polyval(e,_,n,this._n)/_[n+e+1],n+=e+2},d=[3,128,2,5,128,-1,3,3,64,-1,0,1,8,-1,1,4,5,256,1,3,128,-3,-2,3,64,1,-3,2,32,7,512,-10,9,384,5,-9,5,192,7,512,-14,7,512,21,2560],t.Geodesic.prototype.C3coeff=function(){var e,n,i,s=0,a=0;for(e=1;e<t.nC3_;++e)for(n=t.nC3_-1;n>=e;--n)i=Math.min(t.nC3_-n-1,n),this._C3x[a++]=r.polyval(i,d,s,this._n)/d[s+i+1],s+=i+2},f=[97,15015,1088,156,45045,-224,-4784,1573,45045,-10656,14144,-4576,-858,45045,64,624,-4576,6864,-3003,15015,100,208,572,3432,-12012,30030,45045,1,9009,-2944,468,135135,5792,1040,-1287,135135,5952,-11648,9152,-2574,135135,-64,-624,4576,-6864,3003,135135,8,10725,1856,-936,225225,-8448,4992,-1144,225225,-1440,4160,-4576,1716,225225,-136,63063,1024,-208,105105,3584,-3328,1144,315315,-128,135135,-2560,832,405405,128,99099],t.Geodesic.prototype.C4coeff=function(){var e,n,i,s=0,a=0;for(e=0;e<t.nC4_;++e)for(n=t.nC4_-1;n>=e;--n)i=t.nC4_-n-1,this._C4x[a++]=r.polyval(i,f,s,this._n)/f[s+i+1],s+=i+2},t.Geodesic.prototype.A3f=function(t){return r.polyval(5,this._A3x,0,t)},t.Geodesic.prototype.C3f=function(e,n){var i,s,a=1,o=0;for(i=1;i<t.nC3_;++i)s=t.nC3_-i-1,a*=e,n[i]=a*r.polyval(s,this._C3x,o,e),o+=s+1},t.Geodesic.prototype.C4f=function(e,n){var i,s,a=1,o=0;for(i=0;i<t.nC4_;++i)s=t.nC4_-i-1,n[i]=a*r.polyval(s,this._C4x,o,e),o+=s+1,a*=e},t.Geodesic.prototype.Lengths=function(e,n,r,i,s,a,o,l,h,c,u,p,_){var d,f,m,g,y={},v=0,w=0,S=0,x=0;if((u&=t.OUT_MASK)&(t.DISTANCE|t.REDUCEDLENGTH|t.GEODESICSCALE)&&(S=t.A1m1f(e),t.C1f(e,p),u&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(x=t.A2m1f(e),t.C2f(e,_),v=S-x,x=1+x),S=1+S),u&t.DISTANCE)d=t.SinCosSeries(!0,a,o,p)-t.SinCosSeries(!0,r,i,p),y.s12b=S*(n+d),u&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(w=v*n+(S*d-x*(t.SinCosSeries(!0,a,o,_)-t.SinCosSeries(!0,r,i,_))));else if(u&(t.REDUCEDLENGTH|t.GEODESICSCALE)){for(f=1;f<=t.nC2_;++f)_[f]=S*p[f]-x*_[f];w=v*n+(t.SinCosSeries(!0,a,o,_)-t.SinCosSeries(!0,r,i,_))}return u&t.REDUCEDLENGTH?(y.m0=v,y.m12b=l*(i*a)-s*(r*o)-i*o*w):y.m12b=NaN,u&t.GEODESICSCALE&&(m=i*o+r*a,g=this._ep2*(h-c)*(h+c)/(s+l),y.M12=m+(g*a-o*w)*r/s,y.M21=m-(g*r-i*w)*a/l),y},t.Geodesic.prototype.InverseStart=function(e,n,i,s,a,l,h,c,u,p,_){var d,f,m,g,v,w,x,b,C,E,A,k,M,I,T,D,P,N,R,L,G={},O=s*n-a*e,F=a*n+s*e;return G.sig12=-1,d=s*n,d+=a*e,(f=F>=0&&O<.5&&a*h<.5)?(g=r.sq(e+s),g/=g+r.sq(n+a),G.dnm=Math.sqrt(1+this._ep2*g),m=h/(this._f1*G.dnm),v=Math.sin(m),w=Math.cos(m)):(v=c,w=u),G.salp1=a*v,G.calp1=w>=0?O+a*e*r.sq(v)/(1+w):d-a*e*r.sq(v)/(1-w),b=r.hypot(G.salp1,G.calp1),C=e*s+n*a*w,f&&b<this._etol2?(G.salp2=n*v,G.calp2=O-n*s*(w>=0?r.sq(v)/(1+w):1-w),x=r.hypot(G.salp2,G.calp2),G.salp2/=x,G.calp2/=x,G.sig12=Math.atan2(b,C)):Math.abs(this._n)>.1||C>=0||b>=6*Math.abs(this._n)*Math.PI*r.sq(n)||(L=Math.atan2(-c,-u),this.f>=0?(I=(M=r.sq(e)*this._ep2)/(2*(1+Math.sqrt(1+M))+M),E=L/(k=this.f*n*this.A3f(I)*Math.PI),A=d/(k*n)):(T=a*n-s*e,D=Math.atan2(d,T),A=h/(k=((E=(P=this.Lengths(this._n,Math.PI+D,e,-n,i,s,a,l,n,a,t.REDUCEDLENGTH,p,_)).m12b/(n*a*P.m0*Math.PI)-1)<-.01?d/E:-this.f*r.sq(n)*Math.PI)/n)),A>-y&&E>-1-S?this.f>=0?(G.salp1=Math.min(1,-E),G.calp1=-Math.sqrt(1-r.sq(G.salp1))):(G.calp1=Math.max(E>-y?0:-1,E),G.salp1=Math.sqrt(1-r.sq(G.calp1))):(N=o(E,A),R=k*(this.f>=0?-E*N/(1+N):-A*(1+N)/N),v=Math.sin(R),w=-Math.cos(R),G.salp1=a*v,G.calp1=d-a*e*r.sq(v)/(1-w))),G.salp1<=0?(G.salp1=1,G.calp1=0):(x=r.hypot(G.salp1,G.calp1),G.salp1/=x,G.calp1/=x),G},t.Geodesic.prototype.Lambda12=function(e,n,i,s,a,o,l,h,c,u,p,_,d,f){var m,g,y,v,w,S,x,b,C,E,A,k,M,I={};return 0===e&&0===h&&(h=-t.tiny_),g=l*n,y=r.hypot(h,l*e),I.ssig1=e,v=g*e,I.csig1=w=h*n,m=r.hypot(I.ssig1,I.csig1),I.ssig1/=m,I.csig1/=m,I.salp2=a!==n?g/a:l,I.calp2=a!==n||Math.abs(s)!==-e?Math.sqrt(r.sq(h*n)+(n<-e?(a-n)*(n+a):(e-s)*(e+s)))/a:Math.abs(h),I.ssig2=s,S=g*s,I.csig2=x=I.calp2*a,m=r.hypot(I.ssig2,I.csig2),I.ssig2/=m,I.csig2/=m,I.sig12=Math.atan2(Math.max(0,I.csig1*I.ssig2-I.ssig1*I.csig2),I.csig1*I.csig2+I.ssig1*I.ssig2),b=Math.max(0,w*S-v*x),C=w*x+v*S,A=Math.atan2(b*u-C*c,C*u+b*c),k=r.sq(y)*this._ep2,I.eps=k/(2*(1+Math.sqrt(1+k))+k),this.C3f(I.eps,f),E=t.SinCosSeries(!0,I.ssig2,I.csig2,f)-t.SinCosSeries(!0,I.ssig1,I.csig1,f),I.domg12=-this.f*this.A3f(I.eps)*g*(I.sig12+E),I.lam12=A+I.domg12,p&&(0===I.calp2?I.dlam12=-2*this._f1*i/e:(M=this.Lengths(I.eps,I.sig12,I.ssig1,I.csig1,i,I.ssig2,I.csig2,o,n,a,t.REDUCEDLENGTH,_,d),I.dlam12=M.m12b,I.dlam12*=this._f1/(I.calp2*a))),I},t.Geodesic.prototype.Inverse=function(e,n,i,s,a){var o,l;return a||(a=t.STANDARD),a===t.LONG_UNROLL&&(a|=t.STANDARD),a&=t.OUT_MASK,l=(o=this.InverseInt(e,n,i,s,a)).vals,a&t.AZIMUTH&&(l.azi1=r.atan2d(o.salp1,o.calp1),l.azi2=r.atan2d(o.salp2,o.calp2)),l},t.Geodesic.prototype.InverseInt=function(e,n,i,s,a){var o,l,h,c,u,p,_,d,f,y,S,x,b,C,E,A,k,M,I,T,D,P,N,R,L,G,O,F,U,q,j,z,B,V,$,W,H,K,Z,J,X,Y,Q,tt,et,nt,rt,it,st,at,ot,lt,ht,ct,ut,pt,_t,dt,ft,mt,gt,yt,vt,wt,St,xt={};if(xt.lat1=e=r.LatFix(e),xt.lat2=i=r.LatFix(i),e=r.AngRound(e),i=r.AngRound(i),l=(o=r.AngDiff(n,s)).e,o=o.d,a&t.LONG_UNROLL?(xt.lon1=n,xt.lon2=n+o+l):(xt.lon1=r.AngNormalize(n),xt.lon2=r.AngNormalize(s)),l*=h=r.copysign(1,o),E=(o*=h)*r.degree,A=(c=r.sincosde(o,l)).s,k=c.c,l=180-o-l,(u=Math.abs(e)<Math.abs(i)||isNaN(i)?-1:1)<0&&(h*=-1,[i,e]=[e,i]),e*=p=r.copysign(1,-e),i*=p,c=r.sincosd(e),_=this._f1*c.s,d=c.c,_/=c=r.hypot(_,d),d/=c,d=Math.max(t.tiny_,d),c=r.sincosd(i),f=this._f1*c.s,y=c.c,f/=c=r.hypot(f,y),y/=c,y=Math.max(t.tiny_,y),d<-_?y===d&&(f=r.copysign(_,f)):Math.abs(f)===-_&&(y=d),b=Math.sqrt(1+this._ep2*r.sq(_)),C=Math.sqrt(1+this._ep2*r.sq(f)),N=new Array(t.nC1_+1),R=new Array(t.nC2_+1),L=new Array(t.nC3_),(G=-90===e||0===A)&&(T=A,P=0,F=_,U=(I=k)*d,q=f,j=(D=1)*y,M=Math.atan2(Math.max(0,U*q-F*j),U*j+F*q),S=(O=this.Lengths(this._n,M,F,U,b,q,j,C,d,y,a|t.DISTANCE|t.REDUCEDLENGTH,N,R)).s12b,x=O.m12b,a&t.GEODESICSCALE&&(xt.M12=O.M12,xt.M21=O.M21),M<v||x>=0?((M<3*t.tiny_||M<g&&(S<0||x<0))&&(M=x=S=0),x*=this._b,S*=this._b,xt.a12=M/r.degree):G=!1),_t=2,!G&&0===_&&(this.f<=0||l>=180*this.f))I=D=0,T=P=1,S=this.a*E,M=B=E/this._f1,x=this._b*Math.sin(M),a&t.GEODESICSCALE&&(xt.M12=xt.M21=Math.cos(M)),xt.a12=o/this._f1;else if(!G)if(M=(O=this.InverseStart(_,d,b,f,y,C,E,A,k,N,R)).sig12,T=O.salp1,I=O.calp1,M>=0)P=O.salp2,D=O.calp2,V=O.dnm,S=M*this._b*V,x=r.sq(V)*this._b*Math.sin(M/V),a&t.GEODESICSCALE&&(xt.M12=xt.M21=Math.cos(M/V)),xt.a12=M/r.degree,B=E/(this._f1*V);else{for($=0,W=t.tiny_,H=1,K=t.tiny_,Z=-1,J=!1,X=!1;Y=(O=this.Lambda12(_,d,b,f,y,C,T,I,A,k,$<20,N,R,L)).lam12,P=O.salp2,D=O.calp2,M=O.sig12,F=O.ssig1,U=O.csig1,q=O.ssig2,j=O.csig2,z=O.eps,ft=O.domg12,Q=O.dlam12,!X&&Math.abs(Y)>=(J?8:1)*g&&$!=m;++$)Y>0&&($<20||I/T>Z/K)?(K=T,Z=I):Y<0&&($<20||I/T<H/W)&&(W=T,H=I),$<20&&Q>0&&(tt=-Y/Q,Math.abs(tt)<Math.PI&&(et=Math.sin(tt),(rt=T*(nt=Math.cos(tt))+I*et)>0))?(I=I*nt-T*et,T=rt,T/=c=r.hypot(T,I),I/=c,J=Math.abs(Y)<=16*g):(T=(W+K)/2,I=(H+Z)/2,T/=c=r.hypot(T,I),I/=c,J=!1,X=Math.abs(W-T)+(H-I)<w||Math.abs(T-K)+(I-Z)<w);it=a|(a&(t.REDUCEDLENGTH|t.GEODESICSCALE)?t.DISTANCE:t.NONE),S=(O=this.Lengths(z,M,F,U,b,q,j,C,d,y,it,N,R)).s12b,x=O.m12b,a&t.GEODESICSCALE&&(xt.M12=O.M12,xt.M21=O.M21),x*=this._b,S*=this._b,xt.a12=M/r.degree,a&t.AREA&&(wt=Math.sin(ft),_t=A*(St=Math.cos(ft))-k*wt,dt=k*St+A*wt)}return a&t.DISTANCE&&(xt.s12=0+S),a&t.REDUCEDLENGTH&&(xt.m12=0+x),a&t.AREA&&(st=T*d,0!==(at=r.hypot(I,T*_))&&0!==st?(F=_,U=I*d,q=f,j=D*y,z=(lt=r.sq(at)*this._ep2)/(2*(1+Math.sqrt(1+lt))+lt),ht=r.sq(this.a)*at*st*this._e2,F/=c=r.hypot(F,U),U/=c,q/=c=r.hypot(q,j),j/=c,ct=new Array(t.nC4_),this.C4f(z,ct),ut=t.SinCosSeries(!1,F,U,ct),pt=t.SinCosSeries(!1,q,j,ct),xt.S12=ht*(pt-ut)):xt.S12=0,G||2!=_t||(_t=Math.sin(B),dt=Math.cos(B)),!G&&dt>-.7071&&f-_<1.75?(ft=1+dt,mt=1+d,gt=1+y,ot=2*Math.atan2(_t*(_*gt+f*mt),ft*(_*f+mt*gt))):(vt=D*I+P*T,0===(yt=P*I-D*T)&&vt<0&&(yt=t.tiny_*I,vt=-1),ot=Math.atan2(yt,vt)),xt.S12+=this._c2*ot,xt.S12*=u*h*p,xt.S12+=0),u<0&&([P,T]=[T,P],[D,I]=[I,D],a&t.GEODESICSCALE&&([xt.M21,xt.M12]=[xt.M12,xt.M21])),{vals:xt,salp1:T*=u*h,calp1:I*=u*p,salp2:P*=u*h,calp2:D*=u*p}},t.Geodesic.prototype.GenDirect=function(n,r,i,s,a,o){return o?o===t.LONG_UNROLL&&(o|=t.STANDARD):o=t.STANDARD,s||(o|=t.DISTANCE_IN),new e.GeodesicLine(this,n,r,i,o).GenPosition(s,a,o)},t.Geodesic.prototype.Direct=function(t,e,n,r,i){return this.GenDirect(t,e,n,!1,r,i)},t.Geodesic.prototype.ArcDirect=function(t,e,n,r,i){return this.GenDirect(t,e,n,!0,r,i)},t.Geodesic.prototype.Line=function(t,n,r,i){return new e.GeodesicLine(this,t,n,r,i)},t.Geodesic.prototype.DirectLine=function(t,e,n,r,i){return this.GenDirectLine(t,e,n,!1,r,i)},t.Geodesic.prototype.ArcDirectLine=function(t,e,n,r,i){return this.GenDirectLine(t,e,n,!0,r,i)},t.Geodesic.prototype.GenDirectLine=function(n,r,i,s,a,o){var l;return o||(o=t.STANDARD|t.DISTANCE_IN),s||(o|=t.DISTANCE_IN),(l=new e.GeodesicLine(this,n,r,i,o)).GenSetDistance(s,a),l},t.Geodesic.prototype.InverseLine=function(n,i,s,a,o){var l,h,c;return o||(o=t.STANDARD|t.DISTANCE_IN),l=this.InverseInt(n,i,s,a,t.ARC),c=r.atan2d(l.salp1,l.calp1),o&t.OUT_MASK&t.DISTANCE_IN&&(o|=t.DISTANCE),(h=new e.GeodesicLine(this,n,i,c,o,l.salp1,l.calp1)).SetArc(l.vals.a12),h},t.Geodesic.prototype.Polygon=function(t){return new n.PolygonArea(this,t)},t.WGS84=new t.Geodesic(i.WGS84.a,i.WGS84.f)}(ci.Geodesic,ci.GeodesicLine,ci.PolygonArea,ci.Math,ci.Constants),function(t,e,n){e.GeodesicLine=function(e,r,i,s,a,o,l){var h,c,u,p,_,d;a||(a=t.STANDARD|t.DISTANCE_IN),this.a=e.a,this.f=e.f,this._b=e._b,this._c2=e._c2,this._f1=e._f1,this.caps=a|t.LATITUDE|t.AZIMUTH|t.LONG_UNROLL,this.lat1=n.LatFix(r),this.lon1=i,void 0===o||void 0===l?(this.azi1=n.AngNormalize(s),h=n.sincosd(n.AngRound(this.azi1)),this.salp1=h.s,this.calp1=h.c):(this.azi1=s,this.salp1=o,this.calp1=l),h=n.sincosd(n.AngRound(this.lat1)),u=this._f1*h.s,c=h.c,u/=h=n.hypot(u,c),c/=h,c=Math.max(t.tiny_,c),this._dn1=Math.sqrt(1+e._ep2*n.sq(u)),this._salp0=this.salp1*c,this._calp0=n.hypot(this.calp1,this.salp1*u),this._ssig1=u,this._somg1=this._salp0*u,this._csig1=this._comg1=0!==u||0!==this.calp1?c*this.calp1:1,h=n.hypot(this._ssig1,this._csig1),this._ssig1/=h,this._csig1/=h,this._k2=n.sq(this._calp0)*e._ep2,p=this._k2/(2*(1+Math.sqrt(1+this._k2))+this._k2),this.caps&t.CAP_C1&&(this._A1m1=t.A1m1f(p),this._C1a=new Array(t.nC1_+1),t.C1f(p,this._C1a),this._B11=t.SinCosSeries(!0,this._ssig1,this._csig1,this._C1a),_=Math.sin(this._B11),d=Math.cos(this._B11),this._stau1=this._ssig1*d+this._csig1*_,this._ctau1=this._csig1*d-this._ssig1*_),this.caps&t.CAP_C1p&&(this._C1pa=new Array(t.nC1p_+1),t.C1pf(p,this._C1pa)),this.caps&t.CAP_C2&&(this._A2m1=t.A2m1f(p),this._C2a=new Array(t.nC2_+1),t.C2f(p,this._C2a),this._B21=t.SinCosSeries(!0,this._ssig1,this._csig1,this._C2a)),this.caps&t.CAP_C3&&(this._C3a=new Array(t.nC3_),e.C3f(p,this._C3a),this._A3c=-this.f*this._salp0*e.A3f(p),this._B31=t.SinCosSeries(!0,this._ssig1,this._csig1,this._C3a)),this.caps&t.CAP_C4&&(this._C4a=new Array(t.nC4_),e.C4f(p,this._C4a),this._A4=n.sq(this.a)*this._calp0*this._salp0*e._e2,this._B41=t.SinCosSeries(!1,this._ssig1,this._csig1,this._C4a)),this.a13=this.s13=NaN},e.GeodesicLine.prototype.GenPosition=function(e,r,i){var s,a,o,l,h,c,u,p,_,d,f,m,g,y,v,w,S,x,b,C,E,A,k,M,I,T,D={};return i?i===t.LONG_UNROLL&&(i|=t.STANDARD):i=t.STANDARD,i&=this.caps&t.OUT_MASK,D.lat1=this.lat1,D.azi1=this.azi1,D.lon1=i&t.LONG_UNROLL?this.lon1:n.AngNormalize(this.lon1),e?D.a12=r:D.s12=r,e||this.caps&t.DISTANCE_IN&t.OUT_MASK?(l=0,h=0,e?(s=r*n.degree,a=(k=n.sincosd(r)).s,o=k.c):(p=r/(this._b*(1+this._A1m1)),_=Math.sin(p),d=Math.cos(p),s=p-((l=-t.SinCosSeries(!0,this._stau1*d+this._ctau1*_,this._ctau1*d-this._stau1*_,this._C1pa))-this._B11),a=Math.sin(s),o=Math.cos(s),Math.abs(this.f)>.01&&(c=this._ssig1*o+this._csig1*a,u=this._csig1*o-this._ssig1*a,l=t.SinCosSeries(!0,c,u,this._C1a),s-=((1+this._A1m1)*(s+(l-this._B11))-r/this._b)/Math.sqrt(1+this._k2*n.sq(c)),a=Math.sin(s),o=Math.cos(s))),c=this._ssig1*o+this._csig1*a,u=this._csig1*o-this._ssig1*a,b=Math.sqrt(1+this._k2*n.sq(c)),i&(t.DISTANCE|t.REDUCEDLENGTH|t.GEODESICSCALE)&&((e||Math.abs(this.f)>.01)&&(l=t.SinCosSeries(!0,c,u,this._C1a)),h=(1+this._A1m1)*(l-this._B11)),g=this._calp0*c,0===(y=n.hypot(this._salp0,this._calp0*u))&&(y=u=t.tiny_),S=this._salp0,x=this._calp0*u,e&&i&t.DISTANCE&&(D.s12=this._b*((1+this._A1m1)*s+h)),i&t.LONGITUDE&&(v=this._salp0*c,w=u,m=n.copysign(1,this._salp0),f=((i&t.LONG_UNROLL?m*(s-(Math.atan2(c,u)-Math.atan2(this._ssig1,this._csig1))+(Math.atan2(m*v,w)-Math.atan2(m*this._somg1,this._comg1))):Math.atan2(v*this._comg1-w*this._somg1,w*this._comg1+v*this._somg1))+this._A3c*(s+(t.SinCosSeries(!0,c,u,this._C3a)-this._B31)))/n.degree,D.lon2=i&t.LONG_UNROLL?this.lon1+f:n.AngNormalize(n.AngNormalize(this.lon1)+n.AngNormalize(f))),i&t.LATITUDE&&(D.lat2=n.atan2d(g,this._f1*y)),i&t.AZIMUTH&&(D.azi2=n.atan2d(S,x)),i&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(C=t.SinCosSeries(!0,c,u,this._C2a),E=(1+this._A2m1)*(C-this._B21),A=(this._A1m1-this._A2m1)*s+(h-E),i&t.REDUCEDLENGTH&&(D.m12=this._b*(b*(this._csig1*c)-this._dn1*(this._ssig1*u)-this._csig1*u*A)),i&t.GEODESICSCALE&&(k=this._k2*(c-this._ssig1)*(c+this._ssig1)/(this._dn1+b),D.M12=o+(k*c-u*A)*this._ssig1/this._dn1,D.M21=o-(k*this._ssig1-this._csig1*A)*c/b)),i&t.AREA&&(M=t.SinCosSeries(!1,c,u,this._C4a),0===this._calp0||0===this._salp0?(I=S*this.calp1-x*this.salp1,T=x*this.calp1+S*this.salp1):(I=this._calp0*this._salp0*(o<=0?this._csig1*(1-o)+a*this._ssig1:a*(this._csig1*a/(1+o)+this._ssig1)),T=n.sq(this._salp0)+n.sq(this._calp0)*this._csig1*u),D.S12=this._c2*Math.atan2(I,T)+this._A4*(M-this._B41)),e||(D.a12=s/n.degree),D):(D.a12=NaN,D)},e.GeodesicLine.prototype.Position=function(t,e){return this.GenPosition(!1,t,e)},e.GeodesicLine.prototype.ArcPosition=function(t,e){return this.GenPosition(!0,t,e)},e.GeodesicLine.prototype.GenSetDistance=function(t,e){t?this.SetArc(e):this.SetDistance(e)},e.GeodesicLine.prototype.SetDistance=function(e){var n;this.s13=e,n=this.GenPosition(!1,this.s13,t.ARC),this.a13=0+n.a12},e.GeodesicLine.prototype.SetArc=function(e){var n;this.a13=e,n=this.GenPosition(!0,this.a13,t.DISTANCE),this.s13=0+n.s12}}(ci.Geodesic,ci.GeodesicLine,ci.Math),function(t,e,n,r){var i,s,a,o;i=function(t,e){var r=n.AngDiff(t,e).d;return t=n.AngNormalize(t),e=n.AngNormalize(e),r>0&&(t<0&&e>=0||t>0&&0===e)?1:r<0&&t>=0&&e<0?-1:0},s=function(t,e){return(0<=(e%=720)&&e<360||e<-360?0:1)-(0<=(t%=720)&&t<360||t<-360?0:1)},a=function(t,e,n,r,i){return t.Remainder(e),1&n&&t.Add((t.Sum()<0?1:-1)*e/2),r||t.Negate(),i?t.Sum()>e/2?t.Add(-e):t.Sum()<=-e/2&&t.Add(+e):t.Sum()>=e?t.Add(-e):t.Sum()<0&&t.Add(+e),0+t.Sum()},o=function(t,e,r,i,s){return t=n.remainder(t,e),1&r&&(t+=(t<0?1:-1)*e/2),i||(t*=-1),s?t>e/2?t-=e:t<=-e/2&&(t+=e):t>=e?t-=e:t<0&&(t+=e),0+t},t.PolygonArea=function(t,n){this._geod=t,this.a=this._geod.a,this.f=this._geod.f,this._area0=4*Math.PI*t._c2,this.polyline=n||!1,this._mask=e.LATITUDE|e.LONGITUDE|e.DISTANCE|(this.polyline?e.NONE:e.AREA|e.LONG_UNROLL),this.polyline||(this._areasum=new r.Accumulator(0)),this._perimetersum=new r.Accumulator(0),this.Clear()},t.PolygonArea.prototype.Clear=function(){this.num=0,this._crossings=0,this.polyline||this._areasum.Set(0),this._perimetersum.Set(0),this._lat0=this._lon0=this.lat=this.lon=NaN},t.PolygonArea.prototype.AddPoint=function(t,e){var n;0===this.num?(this._lat0=this.lat=t,this._lon0=this.lon=e):(n=this._geod.Inverse(this.lat,this.lon,t,e,this._mask),this._perimetersum.Add(n.s12),this.polyline||(this._areasum.Add(n.S12),this._crossings+=i(this.lon,e)),this.lat=t,this.lon=e),++this.num},t.PolygonArea.prototype.AddEdge=function(t,e){var n;this.num&&(n=this._geod.Direct(this.lat,this.lon,t,e,this._mask),this._perimetersum.Add(e),this.polyline||(this._areasum.Add(n.S12),this._crossings+=s(this.lon,n.lon2)),this.lat=n.lat2,this.lon=n.lon2),++this.num},t.PolygonArea.prototype.Compute=function(t,e){var n,s,o={number:this.num};return this.num<2?(o.perimeter=0,this.polyline||(o.area=0),o):this.polyline?(o.perimeter=this._perimetersum.Sum(),o):(n=this._geod.Inverse(this.lat,this.lon,this._lat0,this._lon0,this._mask),o.perimeter=this._perimetersum.Sum(n.s12),(s=new r.Accumulator(this._areasum)).Add(n.S12),o.area=a(s,this._area0,this._crossings+i(this.lon,this._lon0),t,e),o)},t.PolygonArea.prototype.TestPoint=function(t,e,n,r){var s,a,l,h,c={number:this.num+1};if(0===this.num)return c.perimeter=0,this.polyline||(c.area=0),c;for(c.perimeter=this._perimetersum.Sum(),a=this.polyline?0:this._areasum.Sum(),l=this._crossings,h=0;h<(this.polyline?1:2);++h)s=this._geod.Inverse(0===h?this.lat:t,0===h?this.lon:e,0!==h?this._lat0:t,0!==h?this._lon0:e,this._mask),c.perimeter+=s.s12,this.polyline||(a+=s.S12,l+=i(0===h?this.lon:e,0!==h?this._lon0:e));return this.polyline||(c.area=o(a,this._area0,l,n,r)),c},t.PolygonArea.prototype.TestEdge=function(t,e,n,r){var a,l,h,c={number:this.num?this.num+1:0};return 0===this.num||(c.perimeter=this._perimetersum.Sum()+e,this.polyline||(l=this._areasum.Sum(),h=this._crossings,l+=(a=this._geod.Direct(this.lat,this.lon,t,e,this._mask)).S12,h+=s(this.lon,a.lon2),h+=i(a.lon2,this._lon0),a=this._geod.Inverse(a.lat2,a.lon2,this._lat0,this._lon0,this._mask),c.perimeter+=a.s12,l+=a.S12,c.area=o(l,this._area0,h,n,r))),c}}(ci.PolygonArea,ci.Geodesic,ci.Math,ci.Accumulator),hi=ci,li.exports?li.exports=hi:window.geodesic=hi;var pi=ui.exports,_i=e({__proto__:null,default:oi(pi)},[pi]);const di=globalThis;"undefined"==typeof window&&(di.window=di.window||{},di.window.document||(di.window.document={}));const fi=di.window.modules=di.window.modules||{};fi.mproj=Wr,fi.flatbush=Zr,fi.kdbush=ei,fi["geographiclib-geodesic"]=_i;class mi{_listeners={};on(t,e){return this._listeners[t]||(this._listeners[t]=[]),this._listeners[t].push(e),this}once(t,e){const n=r=>{this.off(t,n),e(r)};return this.on(t,n)}off(t,e){return this._listeners[t]?(this._listeners[t]=this._listeners[t].filter(t=>t!==e),this):this}fire(t,e){if(!this._listeners[t])return this;const n={type:t,...e};return this._listeners[t].forEach(t=>t(n)),this}}class gi{mx;my;bx;by;constructor(t=1,e=1,n=0,r=0){this.mx=t,this.my=e,this.bx=n,this.by=r}static fromBounds(t,e,n=!1){const r=e.width/t.width||1,i=(n?-e.height/t.height:e.height/t.height)||1,s=e.xmin-r*t.xmin,a=n?e.ymax-i*t.ymin:e.ymin-i*t.ymin;return new gi(r,i,s,a)}project(t,e){return[t*this.mx+this.bx,e*this.my+this.by]}unproject(t,e){return[(t-this.bx)/this.mx,(e-this.by)/this.my]}translate(t,e){this.bx+=t,this.by+=e}scale(t,e,n){this.bx=e*(1-t)+this.bx*t,this.by=n*(1-t)+this.by*t,this.mx*=t,this.my*=t}clone(){return new gi(this.mx,this.my,this.bx,this.by)}}class yi{xmin;ymin;xmax;ymax;constructor(t=1/0,e=1/0,n=-1/0,r=-1/0){this.xmin=t,this.ymin=e,this.xmax=n,this.ymax=r}static fromArray(t){return new yi(t[0],t[1],t[2],t[3])}get width(){return this.xmax-this.xmin}get height(){return this.ymax-this.ymin}get centerX(){return.5*(this.xmin+this.xmax)}get centerY(){return.5*(this.ymin+this.ymax)}hasBounds(){return this.xmin<=this.xmax&&this.ymin<=this.ymax}clone(){return new yi(this.xmin,this.ymin,this.xmax,this.ymax)}mergePoint(t,e){t<this.xmin&&(this.xmin=t),t>this.xmax&&(this.xmax=t),e<this.ymin&&(this.ymin=e),e>this.ymax&&(this.ymax=e)}merge(t){t.hasBounds()&&(t.xmin<this.xmin&&(this.xmin=t.xmin),t.xmax>this.xmax&&(this.xmax=t.xmax),t.ymin<this.ymin&&(this.ymin=t.ymin),t.ymax>this.ymax&&(this.ymax=t.ymax))}fillOut(t,e=.5,n=.5){const r=this.width,i=this.height;let s;return r/i<t?(s=i*t-r,this.xmin-=(1-e)*s,this.xmax+=e*s):(s=r/t-i,this.ymin-=(1-n)*s,this.ymax+=n*s),this}scale(t){const e=this.centerX,n=this.centerY,r=this.width*t,i=this.height*t;this.xmin=e-r/2,this.xmax=e+r/2,this.ymin=n-i/2,this.ymax=n+i/2}}class vi extends mi{_running=!1;_busy=!1;_tickTime=0;_startTime=0;_duration=1/0;_frame=null;constructor(){super()}start(t){const e=Date.now();this._duration=t||1/0,this._startTime=e,this._running=!0,this._busy||this._startTick(e)}stop(){var t;this._running=!1,null!==this._frame&&(t=this._frame,"function"==typeof cancelAnimationFrame?cancelAnimationFrame(t):clearTimeout(t),this._frame=null),this._busy=!1}_startTick(t){var e;this._busy=!0,this._tickTime=t,this._frame=(e=()=>{this._frame=null,this._onTick()},"function"==typeof requestAnimationFrame?requestAnimationFrame(e):setTimeout(e,25))}_onTick(){const t=Date.now(),e=t-this._startTime,n=Math.min((e+10)/this._duration,1),r=n>=1;this._running?(r&&(this._running=!1),this.fire("tick",{elapsed:e,pct:n,done:r,time:t,tickTime:t-this._tickTime}),this._busy=!1,this._running&&this._startTick(t)):this._busy=!1}}class wi extends mi{_timer=new vi;_startValue=0;_endValue=0;_ease;constructor(t){super(),this._ease=t||null,this._timer.on("tick",t=>this._onTick(t))}start(t,e,n){this._startValue=t,this._endValue=e,this._timer.start(n||500)}stop(){this._timer.stop()}_onTick(t){const e=this._ease?this._ease(t.pct):t.pct,n=this._endValue*e+this._startValue*(1-e);this.fire("change",{value:n})}static sineInOut(t){return.5-Math.cos(t*Math.PI)/2}static quadraticOut(t){return 1-Math.pow(1-t,2)}}const Si=18485274.7;class xi{_transform=new gi;_extent=new yi;_width=0;_height=0;_initialMX=0;_initialExtent=null;_zoomTween=new wi(wi.sineInOut);_zoomFocus=[0,0];_animatingTransform=null;onViewChange=null;_crs="EPSG:4326";setCRS(t){this._crs=t}get transform(){return this._transform}get extent(){return this._extent}get width(){return this._width}get height(){return this._height}get initialMX(){return this._initialMX}updateSize(t,e){this._width=t,this._height=e}setExtent(t){this._extent=t.clone(),this._initialExtent||(this._initialExtent=t.clone()),this._updateTransform()}reset(){this._initialExtent&&this.setExtent(this._initialExtent)}getCameraState(){const t=this._transform;return{center:[(this._width/2-t.bx)/t.mx,(this._height/2-t.by)/t.my],scale:Math.abs(t.mx)}}applyCameraState(t,e){const n=e,r=-e,i=this._width/2-n*t[0],s=this._height/2-r*t[1];this._transform=new gi(n,r,i,s),this._applyConstraints()}clearInitialState(){this._initialExtent=null,this._initialMX=0}_updateTransform(){if(!this._extent.hasBounds())return;const t=this._width/this._height,e=this._extent.clone().fillOut(t),n=new yi(0,0,this._width,this._height);this._transform=gi.fromBounds(e,n,!0),0===this._initialMX&&(this._initialMX=Math.abs(this._transform.mx),this._initialExtent=e)}pan(t,e){this._transform.translate(t,e),this._applyConstraints()}cancelZoomAnimation(){this._zoomTween.stop(),this._animatingTransform=null}applyWheelZoom(t,e,n,r){const i=1+.12*e,s=t>0?i:1/i;this._transform.scale(s,n,r),this._applyConstraints()}zoomIn(){this._zoomTo(1.15)}zoomOut(){this._zoomTo(1/1.15)}_zoomTo(t){const e=[this._width/2,this._height/2],n=Math.abs(this._transform.mx),r=n*t;this._zoomFocus=e,this._animatingTransform=this._transform.clone(),this._zoomTween.start(n,r,200)}initZoomTween(){this._zoomTween.on("change",t=>{if(!this._animatingTransform)return;const e=t.value/this._animatingTransform.mx,n=this._animatingTransform.clone();n.scale(e,this._zoomFocus[0],this._zoomFocus[1]),this._transform=n,this.onViewChange?.(),t.done&&(this._animatingTransform=null)})}project(t,e){return this._transform.project(t,e)}unproject(t,e){return this._transform.unproject(t,e)}getLineScale(){if(0===this._initialMX)return 1;const t=Math.abs(this._transform.mx)/this._initialMX;let e=1;return t<.5?e*=Math.pow(t+.5,.35):t>30&&(e*=Math.pow(t-29,.065)),e}getArcFilter(t){const e=this._initialMX>0?Math.abs(this._transform.mx)/this._initialMX:1;if(e<1.1)return t=>!0;const n=.35*(1/Math.abs(this._transform.mx)),r=e<1?n*e:n,i=this._getViewBounds();return e=>!t.arcIsSmaller?.(e,r)&&!(i&&t.arcIntersectsBBox&&!t.arcIntersectsBBox(e,i))}getViewBounds(){return this._getViewBounds()}_getViewBounds(){if(!this._transform||0===this._width)return null;const t=this._transform,e=-t.bx/t.mx,n=(this._width-t.bx)/t.mx,r=-t.by/t.my,i=(this._height-t.by)/t.my;return[Math.min(e,n),Math.min(r,i),Math.max(e,n),Math.max(r,i)]}_applyConstraints(){const t=this._transform;let e=Math.abs(t.mx);const n=this._getMinMX(),r=this._getMaxMX();(this._crs.toLowerCase().includes("3857")||this._crs.toLowerCase().includes("webmercator"))&&e<n&&(e=n),e>r&&(e=r);const i=t.my>0?e:-e,s=this._getStrictBounds(),a=(this._width/2-t.bx)/t.mx;let o=(this._height/2-t.by)/t.my;if(s){const t=this._height/(2*e),n=s.ymax-t,r=s.ymin+t;r>n?o=(s.ymin+s.ymax)/2:o>n?o=n:o<r&&(o=r)}const l=this._width/2-a*e,h=this._height/2-o*i;this._transform=new gi(e,i,l,h)}_getMaxMX(){if(!this._initialExtent)return 1/0;const t=this._initialExtent,e=(...t)=>Math.max(...t.map(Math.abs)),n=e(t.xmin,t.xmax,t.centerX),r=e(t.ymin,t.ymax,t.centerY),i=t.width/this._width/(1e-16*n),s=t.height/this._height/(1e-16*r);return Math.max(i,s)}_getStrictBounds(){const t=this._crs.toLowerCase();return"epsg:3857"===t||"webmercator"===t?new yi(-1/0,-18485274.7,1/0,Si):null}_getMinMX(){const t=this._crs.toLowerCase();let e;if("epsg:3857"===t||"webmercator"===t)e=36970549.4;else{if("epsg:4326"!==t&&"wgs84"!==t)return.01*this._initialMX;e=180}return this._height/e}}const bi=1e-6;class Ci{_host;_tween=null;_activeEnd=null;constructor(t){this._host=t}_resolve(t){const e=this._host.getCameraState(),n=t.center??e.center;if(r=n,!Number.isFinite(r[0])||!Number.isFinite(r[1]))throw new Error("camera: center must be finite");var r;let i=e.scale;if(void 0!==t.scale)i=t.scale;else if(void 0!==t.zoom){if(!Number.isFinite(t.zoom))throw new Error("camera: zoom must be finite");const e=this._host.scaleFromZoom(t.zoom);if(!Number.isFinite(e))throw new Error("camera: zoom is not meaningful for this CRS — pass { scale } instead");i=e}if(!Number.isFinite(i)||i<=0)throw new Error("camera: scale must be a finite positive number");return{center:[n[0],n[1]],scale:i}}_payload(t){return{center:[t.center[0],t.center[1]],zoom:Math.log2(t.scale),originalEvent:null}}isMoving(){return null!==this._tween}jumpTo(t){const e=this._resolve(t),n=this._host.getCameraState(),r=e.scale!==n.scale;this._cancel();const i=this._payload(e);this._host.fire("movestart",i),r&&this._host.fire("zoomstart",i),this._host.applyCameraState(e.center,e.scale),this._host.requestRender(),this._host.fire("move",i),r&&this._host.fire("zoom",i),this._host.fire("moveend",i),r&&this._host.fire("zoomend",i)}easeTo(t){if(!1===t.animate||0===t.duration)return void this.jumpTo(t);const e=this._resolve(t),n=t.duration??1e3;if(!Number.isFinite(n)||n<0)throw new Error("camera: duration must be a finite non-negative number");const r=t.easing??wi.sineInOut;this._cancel();const i=this._host.getCameraState(),s=e.scale!==i.scale,a=Math.log(i.scale),o=Math.log(e.scale),l=this._payload(i);this._host.fire("movestart",l),s&&this._host.fire("zoomstart",l);let h=i;const c=()=>{const t=this._payload(h);this._host.fire("moveend",t),s&&this._host.fire("zoomend",t)};this._activeEnd=c;const u=new wi(r);this._tween=u,u.on("change",t=>{const n=t.value;if(n>=1)h=e;else{const t=i.center[0]+(e.center[0]-i.center[0])*n,r=i.center[1]+(e.center[1]-i.center[1])*n,s=Math.exp(a+(o-a)*n);h={center:[t,r],scale:s}}this._host.applyCameraState(h.center,h.scale),this._host.requestRender();const r=this._payload(h);this._host.fire("move",r),s&&this._host.fire("zoom",r),n>=1&&(this._tween=null,this._activeEnd=null,c())}),u.start(0,1,n)}setCenter(t){this.jumpTo({center:t})}setZoom(t){this.jumpTo({zoom:t})}zoomTo(t,e={}){this.easeTo({zoom:t,...e})}panTo(t,e={}){this.easeTo({center:t,...e})}panBy(t,e={}){const{center:n,scale:r}=this._host.getCameraState(),i=[n[0]+t[0]/r,n[1]+t[1]/-r];this.easeTo({center:i,...e})}fitBounds(t,e={}){const{width:n,height:r}=this._host.getViewportSize(),i=e.padding??0,s=Math.max(1,n-2*i),a=Math.max(1,r-2*i),o=[t.centerX,t.centerY],l=t.width,h=t.height;let c;if(!t.hasBounds()||l<=0&&h<=0)c=this._host.getCameraState().scale;else{const t=l>0?s/l:1/0,e=h>0?a/h:1/0;c=Math.min(t,e)}void 0!==e.maxScale&&(c=Math.min(c,e.maxScale)),(!Number.isFinite(c)||c<=0)&&(c=this._host.getCameraState().scale),this.easeTo({center:o,scale:c,...e})}flyTo(t){const e=this._resolve(t);if(!1===t.animate||0===t.duration)return void this.jumpTo(t);let n=t.duration??1e3;if(!Number.isFinite(n)||n<0)throw new Error("camera: duration must be a finite non-negative number");if(null!=t.speed&&(!Number.isFinite(t.speed)||t.speed<=0))throw new Error("camera: speed must be a finite positive number");const r=t.easing??wi.sineInOut,i=t.curve??1.42,{width:s}=this._host.getViewportSize();this._cancel();const a=this._host.getCameraState(),o=e.scale!==a.scale,l=Math.hypot(e.center[0]-a.center[0],e.center[1]-a.center[1])*Math.max(a.scale,1e-9),h=s/a.scale,c=s/e.scale,u=i*i;function p(t,e){const n=l||1e-9,r=(c*c-h*h+e*u*u*n*n)/(2*t*u*n);return Math.log(Math.sqrt(r*r+1)-r)}const _=p(h,1),d=p(c,-1),f=l<bi?Math.abs(Math.log(c/h))/i:(d-_)/i;null!=t.speed&&(n=1e3*f/t.speed);const m=this._payload(a);this._host.fire("movestart",m),o&&this._host.fire("zoomstart",m);let g=a;const y=()=>{const t=this._payload(g);this._host.fire("moveend",t),o&&this._host.fire("zoomend",t)};this._activeEnd=y;const v=new wi(r);this._tween=v,v.on("change",t=>{const n=t.value;let r,c,u;if(l<bi){const t=Math.log(a.scale),i=Math.log(e.scale);u=Math.exp(t+(i-t)*n),r=a.center[0]+(e.center[0]-a.center[0])*n,c=a.center[1]+(e.center[1]-a.center[1])*n}else{const t=n*f,o=h*(Math.cosh(_)/Math.cosh(i*t+_));u=s/o,r=a.center[0]+(e.center[0]-a.center[0])*n,c=a.center[1]+(e.center[1]-a.center[1])*n}g={center:[r,c],scale:u},this._host.applyCameraState(g.center,g.scale),this._host.requestRender();const p=this._payload(g);this._host.fire("move",p),o&&this._host.fire("zoom",p),n>=1&&(g=e,this._host.applyCameraState(e.center,e.scale),this._tween=null,this._activeEnd=null,y())}),v.start(0,1,n)}_cancel(){if(this._host.cancelZoomAnimation?.(),this._tween&&(this._tween.stop(),this._tween=null),this._activeEnd){const t=this._activeEnd;this._activeEnd=null,t()}}stop(){this._cancel()}}class Ei{snapVertices(e,n,r){t.internal.snapVerticesToPoint(e,n,r)}insertVertex(e,n,r){t.internal.insertVertex(e,n,r)}deleteVertex(e,n){t.internal.deleteVertex(e,n)}appendEmptyArc(e){t.internal.appendEmptyArc(e)}appendVertex(e,n){t.internal.appendVertex(e,n)}deleteLastArc(e){t.internal.deleteLastArc(e)}findNearestVertices(e,n,r){return t.internal.findNearestVertices(e,n,r)}findArcIdFromVertexId(e,n){return t.internal.findArcIdFromVertexId(e,n)}vertexIsArcEndpoint(e,n){return t.internal.vertexIsArcEndpoint(e,n)}forEachSegmentInShape(e,n,r){t.internal.forEachSegmentInShape(e,n,r)}findClosestPointOnSeg(e,n,r,i,s,a,o){return t.internal.findClosestPointOnSeg(e,n,r,i,s,a,o)}addIntersectionCuts(e,n){t.internal.addIntersectionCuts(e,n)}findSegmentIntersections(e,n){return t.internal.findSegmentIntersections(e,n)}getIntersectionLayer(e,n,r){return t.internal.getIntersectionLayer(e,n,r)}getAvgSegment(e){return t.internal.getAvgSegment(e)}simplifyArcsFast(e,n){return t.internal.simplifyArcsFast(e,n)}layerHasGeometry(e){return t.internal.layerHasGeometry(e)}getLayerBounds(e,n){const r=t.internal.getLayerBounds(e,n);return r?{xmin:r.xmin,ymin:r.ymin,xmax:r.xmax,ymax:r.ymax}:{xmin:NaN,ymin:NaN,xmax:NaN,ymax:NaN}}getDatasetBounds(e){const n=t.internal.getDatasetBounds(e);return{xmin:n.xmin,ymin:n.ymin,xmax:n.xmax,ymax:n.ymax}}exportDatasetsToPack(e,n){return t.internal.exportDatasetsToPack(e,n??{})}restoreSessionData(e){return t.internal.restoreSessionData(e)}pack(e){return t.internal.pack(e)}unpackSessionData(e){return t.internal.unpackSessionData(e)}exportPackedDatasets(e,n){return t.internal.exportPackedDatasets(e,n??{})}exportFileContent(e,n){return t.internal.exportFileContent(e,n)}copyDataset(e){return t.internal.copyDataset(e)}runImport(e,n){const r=t.internal.parseCommands(e);return r.length>0&&"i"===r[0].name&&(r[0].options.input=n),new Promise((e,n)=>{t.internal.runParsedCommands(r,new t.internal.Job,(t,r)=>{if(t)return void n(t);const i=r.catalog.getDefaultTargets();0!==i.length?e(i[0].dataset):n(new Error("No layers found in dataset"))})})}runOnDataset(e,n,r){return new Promise((i,s)=>{const a=new t.internal.Job;a.catalog.addDataset(n);const o=t.internal.parseCommands(e);if(r)for(const t of o)t.options&&(t.options.input=r);t.internal.runParsedCommands(o,a,(t,e)=>{if(t)return void s(t);const n=e.catalog.getDefaultTargets();0!==n.length?i(n[0].dataset):s(new Error("mapshaper command completed but produced no default target"))})})}runOnDatasetParsed(e,n,r){return new Promise((i,s)=>{const a=new t.internal.Job;if(a.catalog.addDataset(n),r)for(const t of e)t.options&&(t.options.input=r);t.internal.runParsedCommands(e,a,(t,e)=>{if(t)return void s(t);const n=e.catalog.getDefaultTargets();0!==n.length?i(n[0].dataset):s(new Error("mapshaper command completed but produced no default target"))})})}}let Ai=null;function ki(){return Ai??(Ai=new Ei)}function Mi(t){Ai=t}const Ii=6378137,Ti=40075016.6855;class Di{_crs="EPSG:4326";get crs(){return this._crs}setCRS(t){this._crs=t}getCenter(t,e){const n=this._crs.toLowerCase();return"epsg:3857"===n||"webmercator"===n?this._webMercatorToLatLng(t,e):[t,e]}getZoom(t){const e=this._crs.toLowerCase();return"epsg:3857"===e||"webmercator"===e?Math.log2(t*Ti/512):0}getScale(t){const e=this._crs.toLowerCase();return"epsg:3857"===e||"webmercator"===e?512*Math.pow(2,t)/Ti:NaN}async reproject(t,e){for(const n of e.values())n.reproject&&await n.reproject(t);this._crs=t;const n=ki(),r=new yi;for(const t of e.values()){const e=t.getDataset();if(e?.layers)for(const t of e.layers)if(n.layerHasGeometry(t)){const i=n.getLayerBounds(t,e.arcs);i&&r.merge(new yi(i.xmin,i.ymin,i.xmax,i.ymax))}}return r.hasBounds()&&r.scale(1.07),r}_webMercatorToLatLng(t,e){const n=180/Math.PI;return[t/Ii*n,n*(.5*Math.PI-2*Math.atan(Math.exp(-e/Ii)))]}}function Pi(t,e){return t?.name?String(t.name):t?.id?String(t.id):`layer-${e}`}function Ni(t){return t&&Array.isArray(t)?"number"==typeof t[0]?[t]:Array.isArray(t[0])?t:[]:[]}class Ri{_canvas;_ctx;_transform=new gi;_pixelRatio=window.devicePixelRatio||1;constructor(t){this._canvas=t;const e=t.getContext("2d");if(!e)throw new Error("Failed to get 2D context");this._ctx=e}setTransform(t){this._transform=t}setPixelRatio(t){this._pixelRatio=t}drawPaths(t,e,n){if(0===e.width)return;const r=this._ctx;r.strokeStyle=e.color||"#333",r.lineWidth=(e.width??1)*this._pixelRatio,r.lineCap="round",r.lineJoin="round";let i=0;r.beginPath(),t.forEach(t=>{t&&t.forEach(t=>{t.forEach(t=>{i>0&&i%100==0&&(r.stroke(),r.beginPath());const e=n.getArcIter(t);this.drawPathSnapping(e,r),i++})})}),r.stroke()}drawArcs(t,e,n){if(0===e.width)return;const r=this._ctx,i=t.size();r.strokeStyle=e.color||"#333",r.lineWidth=(e.width??1)*this._pixelRatio,r.lineCap="round",r.lineJoin="round";let s=0;r.beginPath();for(let e=0;e<i;e++){if(n&&!n(e))continue;s>0&&s%100==0&&(r.stroke(),r.beginPath());const i=t.getArcIter(e);this.drawPathSnapping(i,r),s++}r.stroke()}drawPathSnapping(t,e){const n=this._transform.mx*this._pixelRatio,r=this._transform.my*this._pixelRatio,i=this._transform.bx*this._pixelRatio,s=this._transform.by*this._pixelRatio;let a,o,l,h,c=0;if(t.hasNext()){for(a=2*(t.x*n+i)|0,o=2*(t.y*r+s)|0,e.moveTo(a/2,o/2);t.hasNext();)l=a,h=o,a=2*(t.x*n+i)|0,o=2*(t.y*r+s)|0,a===l&&o===h||(e.lineTo(a/2,o/2),c++);0===c&&e.lineTo(a/2+.1,o/2)}}drawPoints(t,e){const n=this._ctx,r=this._pixelRatio,i=this._transform.mx*r,s=this._transform.my*r,a=this._transform.bx*r,o=this._transform.by*r,l=(Number(e?.radius)||4)*r,h=e?.color||"#333",c=!1!==e?.fill;n.beginPath(),n.fillStyle=h,n.strokeStyle=h,t.forEach(t=>{if(!t)return;Ni(t).forEach(t=>{const e=t[0]*i+a,r=t[1]*s+o;n.moveTo(e+l,r),n.arc(e,r,l,0,2*Math.PI)})}),c?n.fill():n.stroke()}drawVertexDots(t,e,n={}){const r=this._ctx,i=this._pixelRatio,s=this._transform.mx*i,a=this._transform.my*i,o=this._transform.bx*i,l=this._transform.by*i,h=n.dotColor||"#333",c=(n.dotRadius||3)*i,u=n.hoverColor||"#cc6acc",p=(n.hoverRadius||6)*i,_=n.hoverVertex;let d=null;_&&(d=[_[0]*s+o,_[1]*a+l]),r.fillStyle=h,r.beginPath(),t.forEach(t=>{t&&t.forEach(t=>{t.forEach(t=>{const n=t>=0?t:~t,i=e.getArcIter(n);for(;i.hasNext();){const t=i.x*s+o,e=i.y*a+l;d&&Math.abs(t-d[0])<1&&Math.abs(e-d[1])<1||(r.moveTo(t+c,e),r.arc(t,e,c,0,2*Math.PI))}})})}),r.fill(),d&&(r.fillStyle=u,r.beginPath(),"interpolated"===n.hoverType?r.rect(d[0]-p,d[1]-p,2*p,2*p):r.arc(d[0],d[1],p,0,2*Math.PI),r.fill())}drawPolygonFill(t,e,n,r,i){if(!e.getShapeIter)return;const s=this._ctx,a=this._pixelRatio,o=this._transform.mx*a,l=this._transform.my*a,h=this._transform.bx*a,c=this._transform.by*a;s.fillStyle=n;const u="number"==typeof i&&1!==i,p=s.globalAlpha;u&&(s.globalAlpha=p*Math.max(0,Math.min(1,i)));let _=0;s.beginPath();for(let n=0;n<t.length;n++){const i=t[n];if(!i)continue;let a=!0;if(r){a=!1;for(const t of i){for(const e of t){if(r(e>=0?e:~e)){a=!0;break}}if(a)break}}if(a){_>0&&_>=100&&(s.fill("evenodd"),s.beginPath(),_=0);for(const t of i){const n=e.getShapeIter(t);if(!n.hasNext())continue;let r,i,a=2*(n.x*o+h)|0,u=2*(n.y*l+c)|0;for(s.moveTo(a/2,u/2);n.hasNext();)r=a,i=u,a=2*(n.x*o+h)|0,u=2*(n.y*l+c)|0,a===r&&u===i||s.lineTo(a/2,u/2);s.closePath()}_++}}_>0&&s.fill("evenodd"),u&&(s.globalAlpha=p)}drawDrawingOverlay(t){const e=this._ctx,n=this._pixelRatio,r=this._transform.mx*n,i=this._transform.my*n,s=this._transform.bx*n,a=this._transform.by*n,o=t.drawColor||"#0078ff",l=t.vertices,h=t.cursorCoord,c=t=>[t[0]*r+s,t[1]*i+a];if(l.length>0){e.strokeStyle=o,e.lineWidth=2*n,e.lineJoin="round",e.lineCap="round",e.setLineDash([]),e.beginPath();const t=c(l[0]);e.moveTo(t[0],t[1]);for(let t=1;t<l.length;t++){const n=c(l[t]);e.lineTo(n[0],n[1])}e.stroke()}if(l.length>0&&h){const r=c(l[l.length-1]),i=c(h);if(e.strokeStyle=o,e.lineWidth=1.5*n,e.setLineDash([6*n,4*n]),e.beginPath(),e.moveTo(r[0],r[1]),e.lineTo(i[0],i[1]),"polygon"===t.geometryType&&l.length>=2){const t=c(l[0]);e.moveTo(i[0],i[1]),e.lineTo(t[0],t[1])}e.stroke(),e.setLineDash([])}if(l.length>0){const t=4*n;e.fillStyle=o,e.beginPath();for(const n of l){const r=c(n);e.moveTo(r[0]+t,r[1]),e.arc(r[0],r[1],t,0,2*Math.PI)}e.fill()}if(t.snapCoord){const r=c(t.snapCoord),i=7*n;e.strokeStyle="#ff4444",e.lineWidth=2*n,e.beginPath(),"edge"===t.snapKind?e.rect(r[0]-i,r[1]-i,2*i,2*i):e.arc(r[0],r[1],i,0,2*Math.PI),e.stroke()}}clear(){this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height)}resize(t,e){const n=this._pixelRatio;this._canvas.width=t*n,this._canvas.height=e*n,this._canvas.style.width=t+"px",this._canvas.style.height=e+"px"}}class Li{_painter;constructor(t){this._painter=t}render(t,e,n){"vertex"===t&&e?this._renderVertexOverlay(e):"draw"===t&&n&&this._painter.drawDrawingOverlay(n)}_renderVertexOverlay(t){const e=t.arcs;"polygon"===t.geometryType&&t.polygonFill&&this._painter.drawPolygonFill(t.shapes,e,t.polygonFill),this._painter.drawVertexDots(t.shapes,e,{dotColor:"#333",dotRadius:3,hoverVertex:t.hoverVertex,hoverType:t.hoverType??"vertex",hoverColor:"#cc6acc",hoverRadius:6})}}class Gi{_callbacks;_lastFrameMs=0;_snapshot=null;_fastActive=!1;_settleRequested=!1;_settleTimer=null;constructor(t){this._callbacks=t}schedule(t={}){if("nav"===(t.action??"redraw")&&t.navDelta&&this._shouldUseFastNav())return this._fastActive=!0,this._callbacks.fastNav(t.navDelta),void this._markRedrawPending();this._fullRedrawNow()}recordFrame(t,e){this._lastFrameMs=t,this._snapshot=e}notifyInteractionEnd(t=!1){this._fastActive?this._fullRedrawNow():t&&(this._settleRequested=!0)}dispose(){this._cancelSettle()}get lastFrameMs(){return this._lastFrameMs}get fastActive(){return this._fastActive}_fullRedrawNow(){this._fastActive=!1,this._settleRequested=!1,this._cancelSettle(),this._callbacks.fullRedraw()}_shouldUseFastNav(){if(!this._snapshot)return!1;if(this._lastFrameMs<=100)return!1;const t=this._callbacks.getSnapshot();return t.canvasWidth===this._snapshot.canvasWidth&&(t.canvasHeight===this._snapshot.canvasHeight&&t.pixelRatio===this._snapshot.pixelRatio)}_markRedrawPending(){this._cancelSettle(),this._settleRequested?this._fullRedrawNow():this._settleTimer=setTimeout(()=>{this._fastActive&&this._fullRedrawNow()},2e3)}_cancelSettle(){null!==this._settleTimer&&(clearTimeout(this._settleTimer),this._settleTimer=null)}}class Oi{opts;label;invalidatesPriorCommands=!0;constructor(t){this.opts=t,this.label=t.label}do(){this.opts.source.setDataset(this.opts.after)}undo(){this.opts.source.setDataset(this.opts.before)}}const Fi=Object.freeze({ok:!0,value:void 0});function Ui(t){return{ok:!0,value:t}}const qi=Object.freeze({notFound:(t,e)=>({ok:!1,error:{kind:"not-found",what:t,id:e}}),validation:(t,e)=>({ok:!1,error:{kind:"validation",field:t,reason:e}}),expressionDisabled:t=>({ok:!1,error:{kind:"expression-disabled",operation:t}}),mapshaper:(t,e)=>({ok:!1,error:{kind:"mapshaper",cause:t,...e??{}}}),hostRemoved:()=>({ok:!1,error:{kind:"host-removed"}})}),ji=new Set(["rename-fields","rename-layers","sort","sort-features","filter-fields","drop","target","uniq","unique-features"]),zi=new Set(["buffer","clean","dissolve","mosaic","union","snap","check-geometry","simplify"]);function Bi(t){const e=[],n=/(?:^|\s)-([a-z][a-z-]*)/gi;let r;for(;null!==(r=n.exec(t));)e.push(r[1].toLowerCase());return e}function Vi(t,e,n,r){if(!1===n)return!1;if(!0===n)return!0;if(0===t.length)return e>=r;if(t.every(t=>ji.has(t)))return!1;return e>=(t.some(t=>zi.has(t))?Math.floor(.5*r):r)}const $i={clip:"shape-count",erase:"shape-count",dissolve:"shape-count",explode:"shape-count",filter:"shape-count","filter-geom":"shape-count","filter-islands":"shape-count","filter-slivers":"shape-count","merge-layers":"shape-count",mosaic:"shape-count",union:"shape-count",divide:"shape-count",points:"shape-count",lines:"shape-count",polygons:"shape-count",innerlines:"shape-count",split:"shape-count","split-layer":"shape-count",uniq:"shape-count",buffer:"shape-count",drop:"shape-count","intersection-points":"shape-count",clean:"topology-only",snap:"topology-only",simplify:"topology-only","rebuild-topology":"topology-only",each:"attribute-only",join:"attribute-only","rename-fields":"attribute-only","rename-layers":"attribute-only","filter-fields":"attribute-only","data-fill":"attribute-only",sort:"attribute-only",proj:"crs-only",project:"crs-only",affine:"crs-only"};function Wi(t){let e="attribute-only",n=!1;for(const r of t){if("target"===r)continue;const t=$i[r];if(void 0===t)return"unknown";n=!0,e=Ki(e,t)}return n?e:"unknown"}const Hi={"attribute-only":0,"crs-only":1,"topology-only":2,"shape-count":3,unknown:3};function Ki(t,e){return Hi[t]>=Hi[e]?t:e}async function Zi(t,e,n,r,i){if(t._removed)return qi.hostRemoved();const s=t._sources.get(e);if(!s)return qi.notFound("source",e);const a=s.getDataset();if(!a)return qi.notFound("source",e);const o=ki().copyDataset(a);let l,h=!1;if(t._workerPool){const e=a.arcs?.getPointCount?.()??0,r=function(t,e,n,r){return!1!==n&&(!0===n||Vi(Bi(t),e,n,r))}(n,e,t._workerMode,t._workerThreshold),i=t._workerRouting;h=i?i({cmd:n,heads:Bi(n),vertexCount:e,mode:t._workerMode,threshold:t._workerThreshold,defaultDecision:r}):r}try{l=h?await async function(t,e,n,r,i){if(!t._workerPool)throw new Error("_runViaWorker: worker pool not available");const s=t._workerPool.reserveId(),a=e.arcs?.getPointCount?.()??0,o="undefined"!=typeof performance?performance.now():Date.now();t.fire("workerjobstart",{id:s,cmd:n,label:r,datasetVertexCount:a});try{const r=await ki().exportDatasetsToPack([e],{compact:!1}),a=Yi(r),l=t._workerPool.dispatchWithId(s,n,r,i,a),h=await l,c=await ki().restoreSessionData(h);if(!c.datasets||0===c.datasets.length)throw new Error("worker: no dataset in response");const u=("undefined"!=typeof performance?performance.now():Date.now())-o;return t.fire("workerjobend",{id:s,ok:!0,durationMs:u}),c.datasets[0]}catch(e){const n=("undefined"!=typeof performance?performance.now():Date.now())-o;throw t.fire("workerjobend",{id:s,ok:!1,durationMs:n,errorMessage:e?.message??String(e)}),e}}(t,a,n,r,i):await ki().runOnDataset(n,a,i)}catch(e){return t._removed?qi.hostRemoved():(t.fire("error",{error:e}),qi.mapshaper(e,{cmd:n,operation:r}))}return t._removed?qi.hostRemoved():Xi(t,e,o,l,r,function(t){return Wi(Bi(t))}(n))}async function Ji(t,e,n,r,i){if(t._removed)return qi.hostRemoved();const s=t._sources.get(e);if(!s)return qi.notFound("source",e);const a=s.getDataset();if(!a)return qi.notFound("source",e);const o=ki().copyDataset(a),l=n.map(t=>t.name);let h,c=!1;if(t._workerPool){const e=a.arcs?.getPointCount?.()??0,n=Vi(l,e,t._workerMode,t._workerThreshold),r=t._workerRouting;c=r?r({cmd:l.map(t=>`-${t}`).join(" "),heads:l,vertexCount:e,mode:t._workerMode,threshold:t._workerThreshold,defaultDecision:n}):n}try{h=c?await async function(t,e,n,r,i){if(!t._workerPool)throw new Error("_runViaWorkerParsed: worker pool not available");const s=t._workerPool.reserveId(),a=e.arcs?.getPointCount?.()??0,o="undefined"!=typeof performance?performance.now():Date.now(),l=n.map(t=>`-${t.name}`).join(" ");t.fire("workerjobstart",{id:s,cmd:l,label:r,datasetVertexCount:a});try{const r=await ki().exportDatasetsToPack([e],{compact:!1}),a=Yi(r),l=t._workerPool.dispatchWithId(s,n,r,i,a),h=await l,c=await ki().restoreSessionData(h);if(!c.datasets||0===c.datasets.length)throw new Error("worker: no dataset in response");const u=("undefined"!=typeof performance?performance.now():Date.now())-o;return t.fire("workerjobend",{id:s,ok:!0,durationMs:u}),c.datasets[0]}catch(e){const n=("undefined"!=typeof performance?performance.now():Date.now())-o;throw t.fire("workerjobend",{id:s,ok:!1,durationMs:n,errorMessage:e?.message??String(e)}),e}}(t,a,n,r,i):await ki().runOnDatasetParsed(n,a,i)}catch(e){return t._removed?qi.hostRemoved():(t.fire("error",{error:e}),qi.mapshaper(e,{operation:r}))}return t._removed?qi.hostRemoved():Xi(t,e,o,h,r,Wi(l))}function Xi(t,e,n,r,i,s="unknown"){const a=t._sources.get(e);return a?(t._activeTransaction&&t._activeTransaction._captureFirstTouch(e,n),a.setDataset(r),t._history.push(new Oi({source:a,before:n,after:r,label:i})),t._history.isCapturing()||t._fireHistoryChange(),function(t){return"shape-count"===t||"topology-only"===t||"unknown"===t}(s)&&t._fireSelectionChange(t._selection.clear()),t._scheduleRender(),Fi):qi.notFound("source",e)}function Yi(t){const e=[],n=new Set,r=t=>{if(t&&"object"==typeof t){if(t instanceof Uint8Array){const r=t.buffer;return void(r instanceof ArrayBuffer&&!n.has(r)&&(n.add(r),e.push(r)))}if(t instanceof ArrayBuffer)n.has(t)||(n.add(t),e.push(t));else if(Array.isArray(t))for(const e of t)r(e);else for(const e of Object.keys(t))r(t[e])}};return r(t),e}function Qi(t,e){for(let n=0;n<t.length;n++){const r=t[n];if(r){if(Pi(r,n)===e)return r;if(r.name===e)return r;if(r.id===e)return r}}return null}class ts{_sources;constructor(t){this._sources=t}resolve(t,e){const n=this._sources.get(t);return n?Qi(n.getLayers(),e):null}resolveInLayers(t,e){return Qi(t,e)}}async function es(t,e,n){const r=t.host._sources.get(e.source);if(!r)return qi.notFound("source",e.source);const i=r.getDataset();if(!i)return qi.notFound("source",e.source);if(!Qi(i.layers,e.target))return qi.notFound("layer",e.target);const s="string"==typeof e.mask&&e.mask.length>0;if(s===Array.isArray(e.bbox))return qi.validation(s?"mask":"bbox","must supply exactly one of `mask` or `bbox`");if(s){if(!Qi(i.layers,e.mask))return qi.notFound("mask",e.mask)}else{const t=e.bbox;if(4!==t.length||!t.every(t=>Number.isFinite(t)))return qi.validation("bbox","must be [xmin, ymin, xmax, ymax] of finite numbers");if(t[0]>=t[2]||t[1]>=t[3])return qi.validation("bbox","must satisfy xmin<xmax and ymin<ymax")}const a=s?{source:e.mask}:{bbox:e.bbox};e.cleanup&&(a.cleanup=!0),e.removeSlivers&&(a.remove_slivers=!0);const o="clip"===n?"Clip":"Erase";return t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:n,options:a}],`${o} ${e.target}`)}const ns="__emap_merge";async function rs(t){const e=t.host._selection.getAll();if(0===e.length)return qi.validation("selection","selection is empty");const n=e[0].source,r=e[0].layer;for(const t of e)if(t.source!==n||t.layer!==r)return qi.validation("selection","selection spans multiple sources or layers");const i=t.host.layers.resolve(n,r);if(!i)return qi.notFound("layer",r);if(!function(t,e){const n=t.data?.getRecords?.();if(!n||0===n.length)return!1;const r=new Set(e);for(let t=0;t<n.length;t++){const e=n[t]??{};e[ns]=r.has(t)?"M":`k_${t}`,n[t]=e}return!0}(i,e.map(t=>t.id).slice().sort((t,e)=>t-e)))return qi.validation("layer","layer has no data table; cannot stamp discriminator");const s=function(t,e){const n={fields:[ns]},r=e.data?.getFields?.();if(r&&r.length>0){const t=r.filter(t=>t!==ns&&!t.includes(","));t.length>0&&(n.copy_fields=t)}return[{name:"target",options:{target:t}},{name:"dissolve",options:n},{name:"filter-fields",options:{fields:[ns],invert:!0}}]}(r,i),a=`Merge ${e.length} feature${e.length>1?"s":""}`,o=await t.runDatasetCommandParsed(n,s,a);return o.ok||function(t){const e=t.data?.getRecords?.();if(!e)return;for(const t of e)t&&ns in t&&delete t[ns]}(i),o}const is=new Set(["left","right","outer","inner"]),ss=new Set(["flat","round"]),as=/^-?\d+(\.\d+)?$/;function os(t){return"number"==typeof t&&Number.isInteger(t)&&t>0}async function ls(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);const i=Qi(r.layers,e.target);if(!i)return qi.notFound("layer",e.target);if("number"==typeof e.radius){if(!Number.isFinite(e.radius)||e.radius<=0)return qi.validation("radius","must be a positive finite number")}else{if("string"!=typeof e.radius||0===e.radius.trim().length)return qi.validation("radius","must be a positive number or non-empty expression");if(as.test(e.radius)&&Number(e.radius)<=0)return qi.validation("radius","numeric string must be a positive number")}if("string"==typeof e.radius&&!t.host._allowExpressionEvaluation([e.radius],"bufferLayer"))return qi.expressionDisabled("bufferLayer");if(void 0!==e.vertices&&!os(e.vertices))return qi.validation("vertices","must be a positive integer");if(void 0!==e.arcQuality&&!os(e.arcQuality))return qi.validation("arcQuality","must be a positive integer");if(void 0!==e.sliceLength&&!os(e.sliceLength))return qi.validation("sliceLength","must be a positive integer");if(void 0!==e.backtrack&&!os(e.backtrack))return qi.validation("backtrack","must be a positive integer");if(void 0!==e.tolerance&&!("number"==typeof(s=e.tolerance)&&Number.isFinite(s)&&s>0))return qi.validation("tolerance","must be a positive finite number");var s;if(void 0!==e.type&&!is.has(e.type))return qi.validation("type","must be one of: left, right, outer, inner");if(void 0!==e.capStyle&&!ss.has(e.capStyle))return qi.validation("capStyle","must be one of: flat, round");void 0!==e.type&&"polygon"===i.geometry_type&&console.warn(`bufferLayer: type="${e.type}" is intended for polyline layers; applying to polygon layer "${e.target}" may produce unexpected output.`);const a={radius:String(e.radius)};void 0!==e.capStyle&&(a.cap_style=e.capStyle),void 0!==e.vertices&&(a.vertices=e.vertices),void 0!==e.arcQuality&&(a.arc_quality=e.arcQuality),void 0!==e.tolerance&&(a.tolerance=e.tolerance),void 0!==e.type&&(a.type=e.type),!0===e.planar&&(a.planar=!0),!0===e.v2&&(a.v2=!0),void 0!==e.sliceLength&&(a.slice_length=e.sliceLength),void 0!==e.backtrack&&(a.backtrack=e.backtrack);const o=[{name:"target",options:{target:e.target}},{name:"buffer",options:a}];return t.runDatasetCommandParsed(e.source,o,`Buffer ${e.target}`)}function hs(t){const e=t.trim(),n=e.toLowerCase();return"epsg:3857"===n||"epsg:900913"===n||"epsg:102100"===n?"webmercator":"epsg:4326"===n?"wgs84":e}class cs{_emap;constructor(t){this._emap=t}get _ctx(){return{host:this._emap,runDatasetCommand:(t,e,n,r)=>Zi(this._emap,t,e,n,r),runDatasetCommandParsed:(t,e,n,r)=>Ji(this._emap,t,e,n,r),applyDatasetReplace:(t,e,n,r)=>Xi(this._emap,t,e,n,r)}}clipLayer(t){return async function(t,e){return es(t,e,"clip")}(this._ctx,t)}eraseLayer(t){return async function(t,e){return es(t,e,"erase")}(this._ctx,t)}dissolveLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);if(!Qi(r.layers,e.target))return qi.notFound("layer",e.target);const i=Array.isArray(e.fields)&&e.fields.length>0;if(void 0!==e.field&&i)return qi.validation("field","`field` and `fields` are mutually exclusive");if(void 0!==e.field&&("string"!=typeof e.field||e.field.includes(",")))return qi.validation("field","field name must be a string without `,`");if(!t.host._allowExpressionEvaluation([e.calc,e.where],"dissolveLayer"))return qi.expressionDisabled("dissolveLayer");const s={};if(e.field)s.fields=[e.field];else if(i){const t=e.fields.filter(t=>"string"==typeof t&&!t.includes(","));t.length>0&&(s.fields=t)}const a=t=>Array.isArray(t)?t.filter(t=>"string"==typeof t&&!t.includes(",")):[],o=a(e.sumFields);o.length>0&&(s.sum_fields=o);const l=a(e.copyFields);return l.length>0&&(s.copy_fields=l),e.calc&&e.calc.trim()&&(s.calc=e.calc),e.where&&e.where.trim()&&(s.where=e.where),e.multipart&&(s.multipart=!0),e.name&&e.name.trim()&&(s.name=e.name),e.noReplace&&(s.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"dissolve",options:s}],`Dissolve ${e.target}`)}(this._ctx,t)}bufferLayer(t){return ls(this._ctx,t)}applyExpression(t){return async function(t,e){if(!e.expression||!e.expression.trim())return qi.validation("expression","must be a non-empty expression");const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);if(!Qi(r.layers,e.target))return qi.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.expression,e.where],"applyExpression"))return qi.expressionDisabled("applyExpression");const i={expression:e.expression};return e.where&&e.where.trim()&&(i.where=e.where),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"each",options:i}],`Update ${e.target}`)}(this._ctx,t)}filterFeatures(t){return async function(t,e){const n=!(!e.expression||!e.expression.trim());if(!n&&!e.removeEmpty)return qi.validation("expression","must supply `expression` or `removeEmpty: true`");const r=t.host._sources.get(e.source);if(!r)return qi.notFound("source",e.source);const i=r.getDataset();if(!i)return qi.notFound("source",e.source);if(!Qi(i.layers,e.target))return qi.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.expression],"filterFeatures"))return qi.expressionDisabled("filterFeatures");const s={};return n&&(s.expression=e.expression),e.invert&&(s.invert=!0),e.removeEmpty&&(s.remove_empty=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"filter",options:s}],`Filter ${e.target}`)}(this._ctx,t)}filterIslands(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);if(!Qi(r.layers,e.target))return qi.notFound("layer",e.target);const i="number"==typeof e.minArea&&Number.isFinite(e.minArea),s="number"==typeof e.minVertices&&Number.isInteger(e.minVertices)&&e.minVertices>0;if(!i&&!s)return qi.validation("minArea","must supply at least one of `minArea` or `minVertices`");if(i&&e.minArea<0)return qi.validation("minArea","must be non-negative");const a={};return i&&(a.min_area=String(e.minArea)),s&&(a.min_vertices=e.minVertices),e.removeEmpty&&(a.remove_empty=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"filter-islands",options:a}],`Filter islands ${e.target}`)}(this._ctx,t)}filterSlivers(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);if(!Qi(r.layers,e.target))return qi.notFound("layer",e.target);if("number"!=typeof e.minArea||!Number.isFinite(e.minArea)||e.minArea<=0)return qi.validation("minArea","must be a positive finite number");const i={min_area:String(e.minArea)};return e.weighted&&(i.weighted=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"filter-slivers",options:i}],`Filter slivers ${e.target}`)}(this._ctx,t)}filterGeom(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);if(!Qi(r.layers,e.target))return qi.notFound("layer",e.target);const i=e.bbox;return Array.isArray(i)&&4===i.length&&i.every(t=>Number.isFinite(t))?i[0]>=i[2]||i[1]>=i[3]?qi.validation("bbox","must satisfy xmin<xmax and ymin<ymax"):t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"filter-geom",options:{bbox:[i[0],i[1],i[2],i[3]]}}],`Filter geom ${e.target}`):qi.validation("bbox","must be [xmin, ymin, xmax, ymax] of finite numbers")}(this._ctx,t)}explodeLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();return r?Qi(r.layers,e.target)?t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"explode",options:{}}],`Explode ${e.target}`):qi.notFound("layer",e.target):qi.notFound("source",e.source)}(this._ctx,t)}innerlinesLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);if(!Qi(r.layers,e.target))return qi.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.where],"innerlinesLayer"))return qi.expressionDisabled("innerlinesLayer");const i={};return e.where&&e.where.trim()&&(i.where=e.where),e.name&&e.name.trim()&&(i.name=e.name),e.noReplace&&(i.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"innerlines",options:i}],`Innerlines ${e.target}`)}(this._ctx,t)}snapLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);if(!Qi(r.layers,e.target))return qi.notFound("layer",e.target);const i={};return"number"==typeof e.interval&&(i.interval=String(e.interval)),e.endpoints&&(i.endpoints=!0),"number"==typeof e.precision&&(i.precision=e.precision),e.fixGeometry&&(i.fix_geometry=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"snap",options:i}],`Snap ${e.target}`)}(this._ctx,t)}cleanLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);if(!Qi(r.layers,e.target))return qi.notFound("layer",e.target);const i=t=>void 0===t||"number"==typeof t&&Number.isFinite(t)&&t>=0;if(!i(e.gapFillArea))return qi.validation("gapFillArea","must be a finite non-negative number");if(!i(e.sliverControl))return qi.validation("sliverControl","must be a finite non-negative number");if(!i(e.snapInterval))return qi.validation("snapInterval","must be a finite non-negative number");if(void 0!==e.overlapRule){const t=["min-id","max-id","min-area","max-area"];if(!t.includes(e.overlapRule))return qi.validation("overlapRule",`must be one of ${t.join(", ")}`)}const s={};return void 0!==e.gapFillArea&&(s.gap_fill_area=String(e.gapFillArea)),void 0!==e.sliverControl&&(s.sliver_control=e.sliverControl),void 0!==e.snapInterval&&(s.snap_interval=String(e.snapInterval)),e.noSnap&&(s.no_snap=!0),e.allowOverlaps&&(s.allow_overlaps=!0),void 0!==e.overlapRule&&(s.overlap_rule=e.overlapRule),e.allowEmpty&&(s.allow_empty=!0),e.rewind&&(s.rewind=!0),e.onlyArcs&&(s.only_arcs=!0),e.noArcDissolve&&(s.no_arc_dissolve=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"clean",options:s}],`Clean ${e.target}`)}(this._ctx,t)}mosaicLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);if(!Qi(r.layers,e.target))return qi.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.calc],"mosaicLayer"))return qi.expressionDisabled("mosaicLayer");const i={};return"number"==typeof e.snapInterval&&(i.snap_interval=String(e.snapInterval)),e.noSnap&&(i.no_snap=!0),e.noReplace&&(i.no_replace=!0),e.name&&e.name.trim()&&(i.name=e.name),e.calc&&e.calc.trim()&&(i.calc=e.calc),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"mosaic",options:i}],`Mosaic ${e.target}`)}(this._ctx,t)}unionLayers(t){return async function(t,e){if(!e.targets||e.targets.length<2)return qi.validation("targets","must supply at least 2 target layers");const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);for(const t of e.targets){if("string"!=typeof t||t.includes(","))return qi.validation("targets",`target name must not contain ',': ${String(t)}`);if(!Qi(r.layers,t))return qi.notFound("layer",t)}const i=e.targets.join(","),s={};if(e.fields&&e.fields.length>0){const t=e.fields.filter(t=>!t.includes(","));t.length>0&&(s.fields=t)}return e.name&&e.name.trim()&&(s.name=e.name),e.noReplace&&(s.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:i}},{name:"union",options:s}],`Union ${i}`)}(this._ctx,t)}divideLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);const i=Qi(r.layers,e.target);if(!i)return qi.notFound("layer",e.target);if("polyline"!==i.geometry_type)return qi.validation("target",`expected polyline layer, got ${i.geometry_type??"unknown"}`);const s=Qi(r.layers,e.divider);if(!s)return qi.notFound("divider",e.divider);if("polygon"!==s.geometry_type)return qi.validation("divider",`expected polygon layer, got ${s.geometry_type??"unknown"}`);const a={source:e.divider};if(e.fields&&e.fields.length>0){const t=e.fields.filter(t=>!t.includes(","));t.length>0&&(a.fields=t)}return e.force&&(a.force=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"divide",options:a}],`Divide ${e.target}`)}(this._ctx,t)}pointsLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);const i=Qi(r.layers,e.target);if(!i)return qi.notFound("layer",e.target);const s=i.geometry_type;switch(e.type){case"centroid":case"inner":if("polygon"!==s)return qi.validation("type",`${e.type} requires polygon target, got ${s??"unknown"}`);break;case"midpoints":case"interpolated":if("polyline"!==s)return qi.validation("type",`${e.type} requires polyline target, got ${s??"unknown"}`);break;case"vertices":case"endpoints":if("polygon"!==s&&"polyline"!==s)return qi.validation("type",`${e.type} requires polygon/polyline target, got ${s??"unknown"}`);break;default:return qi.validation("type",`unknown type: ${String(e.type)}`)}if("interpolated"===e.type&&!("number"==typeof e.interval&&e.interval>0))return qi.validation("interval","interpolated points require a positive interval");const a={[e.type]:!0};return"interpolated"===e.type&&(a.interval=String(e.interval)),e.name&&e.name.trim()&&(a.name=e.name),e.noReplace&&(a.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"points",options:a}],`Points ${e.target}`)}(this._ctx,t)}linesLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);const i=Qi(r.layers,e.target);if(!i)return qi.notFound("layer",e.target);if("polygon"!==i.geometry_type)return qi.validation("target",`expected polygon layer, got ${i.geometry_type??"unknown"}`);const s={},a=e.fields?.filter(t=>"string"==typeof t&&!t.includes(","));return a&&a.length>0&&(s.fields=a),e.name&&e.name.trim()&&(s.name=e.name),e.noReplace&&(s.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"lines",options:s}],`Lines ${e.target}`)}(this._ctx,t)}polygonsLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);const i=Qi(r.layers,e.target);if(!i)return qi.notFound("layer",e.target);if("polyline"!==i.geometry_type)return qi.validation("target",`expected polyline layer, got ${i.geometry_type??"unknown"}`);const s={};return"number"==typeof e.gapTolerance&&e.gapTolerance>0&&(s.gap_tolerance=String(e.gapTolerance)),e.fromRings&&(s.from_rings=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"polygons",options:s}],`Polygons ${e.target}`)}(this._ctx,t)}simplifyLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);if(void 0!==e.target&&!Qi(r.layers,e.target))return qi.notFound("layer",e.target);if(1!==[void 0!==e.percentage,void 0!==e.interval,void 0!==e.resolution].filter(Boolean).length)return qi.validation("threshold","must supply exactly one of percentage, interval, resolution");const i={};if(void 0!==e.percentage){const t=e.percentage;if(!Number.isFinite(t)||t<0||t>100)return qi.validation("percentage","must be a finite number in [0, 100]");i.percentage=`${t}%`}else if(void 0!==e.interval){const t=e.interval;if(!Number.isFinite(t)||t<=0)return qi.validation("interval","must be a positive finite number");i.interval=String(t)}else{const t=e.resolution;if(!/^\d+x\d+$/.test(t))return qi.validation("resolution","must match `WIDTHxHEIGHT` (digits)");i.resolution=t}if(void 0!==e.weighting&&void 0!==e.method&&"weighted"!==e.method)return qi.validation("weighting",`weighting only applies to method='weighted', not ${e.method}`);e.method&&(i.method=e.method),"number"==typeof e.weighting&&Number.isFinite(e.weighting)&&(i.weighting=e.weighting),e.planar&&(i.planar=!0),e.keepShapes&&(i.keep_shapes=!0),e.lockBox&&(i.lock_box=!0),e.noRepair&&(i.no_repair=!0);const s=[];e.target&&s.push({name:"target",options:{target:e.target}}),s.push({name:"simplify",options:i});const a=`Simplify ${e.target??e.source}`;return t.runDatasetCommandParsed(e.source,s,a)}(this._ctx,t)}projectLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);if(void 0!==e.target&&!Qi(r.layers,e.target))return qi.notFound("layer",e.target);const i=hs(e.crs??"");if(0===i.length)return qi.validation("crs","must be a non-empty CRS string");const s={crs:i};e.init&&e.init.trim()&&(s.init=hs(e.init)),e.densify&&(s.densify=!0);const a=[];e.target&&a.push({name:"target",options:{target:e.target}}),a.push({name:"proj",options:s});const o=`Project ${e.target??e.source}`;return t.runDatasetCommandParsed(e.source,a,o)}(this._ctx,t)}affineLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);if(void 0!==e.target&&!Qi(r.layers,e.target))return qi.notFound("layer",e.target);const i=Array.isArray(e.shift),s="number"==typeof e.rotate&&0!==e.rotate,a=void 0!==e.scale&&("number"==typeof e.scale?1!==e.scale:Array.isArray(e.scale));if(!i&&!s&&!a)return qi.validation("shift","must supply at least one of `shift`, `rotate`, or `scale`");if(i){const t=e.shift;if(2!==t.length||!t.every(t=>Number.isFinite(t)))return qi.validation("shift","must be [dx, dy] of finite numbers")}if(s&&!Number.isFinite(e.rotate))return qi.validation("rotate","must be a finite number (degrees)");if(a&&Array.isArray(e.scale)){const t=e.scale;if(2!==t.length||!t.every(t=>Number.isFinite(t)&&0!==t))return qi.validation("scale","must be [sx, sy] of nonzero finite numbers")}else if(a&&"number"==typeof e.scale&&(!Number.isFinite(e.scale)||0===e.scale))return qi.validation("scale","must be a nonzero finite number");if(!(void 0===e.anchor||Array.isArray(e.anchor)&&2===e.anchor.length&&e.anchor.every(t=>Number.isFinite(t))))return qi.validation("anchor","must be [x, y] of finite numbers");if(!t.host._allowExpressionEvaluation([e.where],"affineLayer"))return qi.expressionDisabled("affineLayer");const o={};i&&(o.shift=[String(e.shift[0]),String(e.shift[1])]),s&&(o.rotate=e.rotate),a&&(o.scale=(e.scale,e.scale)),e.anchor&&(o.anchor=[e.anchor[0],e.anchor[1]]),e.where&&e.where.trim()&&(o.where=e.where);const l=[];e.target&&l.push({name:"target",options:{target:e.target}}),l.push({name:"affine",options:o});const h=`Affine ${e.target??e.source}`;return t.runDatasetCommandParsed(e.source,l,h)}(this._ctx,t)}renameLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);if(!Qi(r.layers,e.target))return qi.notFound("layer",e.target);const i=(e.name??"").trim();if(0===i.length)return qi.validation("name","must be a non-empty string");if(i.includes(","))return qi.validation("name","must not contain `,`");if(i!==e.target&&r.layers.some(t=>(t?.name??"")===i))return qi.validation("name",`another layer already named '${i}'`);return t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"rename-layers",options:{names:[i]}}],`Rename ${e.target} → ${i}`)}(this._ctx,t)}mergeLayers(t){return async function(t,e){if(!e.targets||e.targets.length<2)return qi.validation("targets","must supply at least 2 target layers");const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);for(const t of e.targets)if("string"!=typeof t||t.includes(","))return qi.validation("targets",`target name must not contain ',': ${String(t)}`);const i=e.targets.map(t=>Qi(r.layers,t));for(let t=0;t<i.length;t++)if(!i[t])return qi.notFound("layer",e.targets[t]);if(!e.force){const t=i[0]?.geometry_type;if(!i.every(e=>e?.geometry_type===t))return qi.validation("targets","targets have mixed geometry types; pass `force: true` to merge anyway")}const s=e.targets.join(","),a={};return e.name&&e.name.trim()&&(a.name=e.name),e.force&&(a.force=!0),e.flatten&&(a.flatten=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:s}},{name:"merge-layers",options:a}],`Merge ${s}`)}(this._ctx,t)}splitLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);if(!Qi(r.layers,e.target))return qi.notFound("layer",e.target);const i=(e.expression??"").trim();if(0===i.length)return qi.validation("expression","must be a non-empty expression");if(!t.host._allowExpressionEvaluation([i],"splitLayer"))return qi.expressionDisabled("splitLayer");const s={expression:i};return e.noReplace&&(s.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"split",options:s}],`Split ${e.target}`)}(this._ctx,t)}dropLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();return r?Qi(r.layers,e.target)?t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"drop",options:{}}],`Drop ${e.target}`):qi.notFound("layer",e.target):qi.notFound("source",e.source)}(this._ctx,t)}sortFeatures(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);if(!Qi(r.layers,e.target))return qi.notFound("layer",e.target);const i=(e.expression??"").trim();if(0===i.length)return qi.validation("expression","must be a non-empty expression");if(!t.host._allowExpressionEvaluation([i],"sortFeatures"))return qi.expressionDisabled("sortFeatures");const s={expression:i};return e.descending&&(s.descending=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"sort",options:s}],`Sort ${e.target}`)}(this._ctx,t)}uniqueFeatures(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);if(!Qi(r.layers,e.target))return qi.notFound("layer",e.target);const i=(e.expression??"").trim();if(0===i.length)return qi.validation("expression","must be a non-empty expression");if(!t.host._allowExpressionEvaluation([i],"uniqueFeatures"))return qi.expressionDisabled("uniqueFeatures");if(void 0!==e.maxCount&&!("number"==typeof e.maxCount&&e.maxCount>0))return qi.validation("maxCount","must be a positive number");const s={expression:i};return void 0!==e.maxCount&&(s.max_count=e.maxCount),e.invert&&(s.invert=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"uniq",options:s}],`Uniq ${e.target}`)}(this._ctx,t)}filterFields(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);if(!Qi(r.layers,e.target))return qi.notFound("layer",e.target);if(!Array.isArray(e.fields)||0===e.fields.length)return qi.validation("fields","must be a non-empty array");for(const t of e.fields){if("string"!=typeof t||0===t.trim().length)return qi.validation("fields",`field name must be a non-empty string: ${String(t)}`);if(t.includes(","))return qi.validation("fields",`field name must not contain ',': ${t}`)}const i={fields:e.fields.slice()};return e.invert&&(i.invert=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"filter-fields",options:i}],`Filter fields ${e.target}`)}(this._ctx,t)}renameFields(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);if(!Qi(r.layers,e.target))return qi.notFound("layer",e.target);if(!e.mapping||"object"!=typeof e.mapping)return qi.validation("mapping","must be an object of { oldName: newName }");const i=Object.entries(e.mapping);if(0===i.length)return qi.validation("mapping","must contain at least one rename pair");const s=[];for(const[t,e]of i){const n=(t??"").trim(),r=(e??"").trim();if(0===n.length||0===r.length)return qi.validation("mapping",`field names must be non-empty: ${t}=${e}`);if(n.includes(",")||n.includes("=")||r.includes(",")||r.includes("="))return qi.validation("mapping",`field names must not contain ',' or '=': ${t}=${e}`);s.push(`${n}=${r}`)}return t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"rename-fields",options:{fields:s}}],`Rename fields ${e.target}`)}(this._ctx,t)}joinTable(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);if(!Qi(r.layers,e.target))return qi.notFound("layer",e.target);if(!Array.isArray(e.keys)||2!==e.keys.length)return qi.validation("keys","must be a 2-element [targetKey, sourceKey] array");const[i,s]=e.keys.map(t=>"string"==typeof t?t.trim():"");if(0===i.length||0===s.length)return qi.validation("keys","both keys must be non-empty strings");if(i.includes(",")||s.includes(","))return qi.validation("keys","keys must not contain `,`");let a,o;const l=e.data;if(!l||"object"!=typeof l)return qi.validation("data","must be { csv } | { json } | { layer }");if("layer"in l&&"string"==typeof l.layer&&l.layer.trim().length>0)a=l.layer.trim();else if("csv"in l&&("string"==typeof l.csv||l.csv instanceof Uint8Array)){const t=".emap-join.csv";a=t,o={[t]:l.csv}}else{if(!("json"in l)||void 0===l.json)return qi.validation("data","must contain one of `csv`, `json`, or `layer`");{const t=".emap-join.json";let e;e="string"==typeof l.json||l.json instanceof Uint8Array?l.json:JSON.stringify(l.json),a=t,o={[t]:e}}}if(!t.host._allowExpressionEvaluation([e.where,e.calc],"joinTable"))return qi.expressionDisabled("joinTable");const h={source:a,keys:[i,s]};if(e.fields&&e.fields.length>0){const t=e.fields.filter(t=>"string"==typeof t&&!t.includes(","));t.length>0&&(h.fields=t)}return e.prefix&&e.prefix.length>0&&(h.prefix=e.prefix),e.where&&e.where.trim().length>0&&(h.where=e.where),e.calc&&e.calc.trim().length>0&&(h.calc=e.calc),e.unjoined&&(h.unjoined=!0),e.unmatched&&(h.unmatched=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"join",options:h}],`Join ${e.target}`,o)}(this._ctx,t)}dataFill(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);if(!Qi(r.layers,e.target))return qi.notFound("layer",e.target);if("string"!=typeof e.field||0===e.field.trim().length)return qi.validation("field","must be a non-empty string");if(e.field.includes(",")||e.field.includes("="))return qi.validation("field","must not contain `,` or `=`");if(void 0!==e.weightField){if("string"!=typeof e.weightField||0===e.weightField.trim().length)return qi.validation("weightField","must be a non-empty string when supplied");if(e.weightField.includes(",")||e.weightField.includes("="))return qi.validation("weightField","must not contain `,` or `=`")}const i={field:e.field};return e.weightField&&(i.weight_field=e.weightField),e.contiguous&&(i.contiguous=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"data-fill",options:i}],`Data fill ${e.target}.${e.field}`)}(this._ctx,t)}rebuildTopology(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);if(!r.arcs)return Fi;const i=ki(),s=i.copyDataset(r),a=i.copyDataset(r);try{i.addIntersectionCuts(a,{snap_interval:e.snapInterval,no_snap:e.noSnap,rebuild_topology:e.rebuildTopology})}catch(e){return t.host.fire("error",{error:e}),qi.mapshaper(e,{operation:"rebuildTopology"})}return t.applyDatasetReplace(e.source,s,a,"Rebuild topology")}(this._ctx,t)}checkGeometry(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);if(void 0!==e.target&&!Qi(r.layers,e.target))return qi.notFound("layer",e.target);if(!r.arcs)return Ui({ok:!0,intersections:[],intersectionCount:0});const i={};void 0!==e.tolerance&&(i.tolerance=e.tolerance);const s=ki().findSegmentIntersections(r.arcs,i).map(t=>({x:t.x,y:t.y}));return Ui({ok:0===s.length,intersections:s,intersectionCount:s.length})}(this._ctx,t)}intersectionPointsLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return qi.notFound("source",e.source);const r=n.getDataset();if(!r)return qi.notFound("source",e.source);const i=Qi(r.layers,e.target);if(!i)return qi.notFound("layer",e.target);if("polygon"!==i.geometry_type&&"polyline"!==i.geometry_type)return qi.validation("target",`expected polygon/polyline target, got ${i.geometry_type??"unknown"}`);if(!r.arcs)return qi.validation("source","source has no arcs");const s=e.name&&e.name.trim()||`${e.target}-intersections`;if(r.layers.some(t=>t?.name===s))return qi.validation("name",`another layer already named '${s}'`);if(void 0!==e.tolerance&&("number"!=typeof e.tolerance||!Number.isFinite(e.tolerance)||e.tolerance<=0))return qi.validation("tolerance","must be a positive finite number");const a={};void 0!==e.tolerance&&(a.tolerance=e.tolerance);const o=ki(),l=o.copyDataset(r),h=o.copyDataset(r);let c;try{const t=o.findSegmentIntersections(h.arcs,a),n=Qi(h.layers,e.target);if(!n)throw new Error("intersectionPointsLayer: target lost in copyDataset");c=o.getIntersectionLayer(t,n,h.arcs),c.name=s,h.layers.push(c)}catch(e){return t.host.fire("error",{error:e}),qi.mapshaper(e,{operation:"intersectionPointsLayer"})}return t.applyDatasetReplace(e.source,l,h,`Intersection points ${e.target}`)}(this._ctx,t)}mergeSelected(){return rs(this._ctx)}}class us{children;label;constructor(t,e){this.children=t,this.label=e}do(){for(const t of this.children)t.do()}undo(){for(let t=this.children.length-1;t>=0;t--)this.children[t].undo()}}function ps(t){return"polygon"===t.geometry_type||"polyline"===t.geometry_type}function _s(t){return"point"===t.geometry_type}function ds(t){t&&(t.editVersion=(t.editVersion??0)+1)}class fs{opts;label;_mergeAt=Date.now();constructor(t){this.opts=t;const e=t.arcIds.length+t.pointFeatures.length;this.label=`Translate ${e} feature${1===e?"":"s"}`}do(){this._apply(this.opts.dx,this.opts.dy)}undo(){this._apply(-this.opts.dx,-this.opts.dy)}mergeable(t){if(!(t instanceof fs))return!1;if(t.opts.source!==this.opts.source)return!1;if(Date.now()-t._mergeAt>500)return!1;const e=t.opts.arcIds,n=this.opts.arcIds;if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(e[t]!==n[t])return!1;const r=t.opts.pointFeatures,i=this.opts.pointFeatures;if(r.length!==i.length)return!1;for(let t=0;t<r.length;t++){if(r[t].featureId!==i[t].featureId)return!1;if(r[t].layer!==i[t].layer)return!1}return!0}merge(t){t instanceof fs&&(this.opts.dx+=t.opts.dx,this.opts.dy+=t.opts.dy,this._mergeAt=Date.now())}_apply(t,e){const{arcs:n,arcIds:r,pointFeatures:i,source:s}=this.opts;if(n&&r.length>0){const i=n.getVertexData?.();if(i){const{xx:s,yy:a,ii:o,nn:l}=i;for(const i of r){const r=o[i],h=l[i];for(let n=r;n<r+h;n++)s[n]+=t,a[n]+=e;n.updateArcBounds?.(i)}}}for(const n of i){const r=n.layer.shapes?.[n.featureId];if(r)for(const n of Ni(r))n&&n.length>=2&&(n[0]+=t,n[1]+=e)}s.markDisplayArcsDirty?.(),ds(s.getDataset?.())}}class ms{opts;label;constructor(t){this.opts=t;const e=t.arcIds.length+t.pointFeatures.length;this.label=t.label??`Transform ${e} feature${1===e?"":"s"}`}do(){this._apply(this.opts.matrix)}undo(){this._apply(Ss(this.opts.matrix))}_apply(t){const{arcs:e,arcIds:n,pointFeatures:r,source:i}=this.opts;if(e&&n.length>0){const r=e.getVertexData?.();if(r){const{xx:i,yy:s,ii:a,nn:o}=r;for(const r of n){const n=a[r],l=o[r];for(let e=n;e<n+l;e++){const n=i[e],r=s[e];i[e]=t.a*n+t.c*r+t.tx,s[e]=t.b*n+t.d*r+t.ty}e.updateArcBounds?.(r)}}}for(const e of r){const n=e.layer.shapes?.[e.featureId];if(n)for(const e of Ni(n))if(e&&e.length>=2){const n=e[0],r=e[1];e[0]=t.a*n+t.c*r+t.tx,e[1]=t.b*n+t.d*r+t.ty}}i.markDisplayArcsDirty?.(),ds(i.getDataset?.())}}function gs(t,e=0,n=0){const r=Math.cos(t),i=Math.sin(t);return{a:r,b:i,c:-i,d:r,tx:e-r*e+i*n,ty:n-i*e-r*n}}function ys(t,e,n=0,r=0){return{a:t,b:0,c:0,d:e,tx:n-t*n,ty:r-e*r}}function vs(t,e){return{a:t.a*e.a+t.c*e.b,b:t.b*e.a+t.d*e.b,c:t.a*e.c+t.c*e.d,d:t.b*e.c+t.d*e.d,tx:t.a*e.tx+t.c*e.ty+t.tx,ty:t.b*e.tx+t.d*e.ty+t.ty}}const ws={a:1,b:0,c:0,d:1,tx:0,ty:0};function Ss(t){const e=t.a*t.d-t.b*t.c;if(0===e)throw new Error("FeatureAffineCommand: matrix is singular (det=0)");const n=t.d/e,r=-t.b/e,i=-t.c/e,s=t.a/e;return{a:n,b:r,c:i,d:s,tx:-(n*t.tx+i*t.ty),ty:-(r*t.tx+s*t.ty)}}class xs{opts;label;constructor(t){this.opts=t,this.label=`Split ${t.appendedArcs.length} shared arc${1===t.appendedArcs.length?"":"s"}`}do(){const t=this.opts.source.getArcs();if(t){!function(t,e){const n=t.getVertexData?.();if(!n)return;const{xx:r,yy:i,zz:s,nn:a}=n,o=!!s&&e.every(t=>t.zz);let l=0;for(const t of e)l+=t.xx.length;const h=new Float64Array(r.length+l),c=new Float64Array(i.length+l),u=o?new Float64Array(s.length+l):null;h.set(r),c.set(i),u&&s&&u.set(s);let p=r.length;for(const t of e)h.set(t.xx,p),c.set(t.yy,p),u&&t.zz&&u.set(t.zz,p),p+=t.xx.length;const _=new Int32Array(a.length+e.length);_.set(a);for(let t=0;t<e.length;t++)_[a.length+t]=e[t].xx.length;t.updateVertexData(_,h,c,u)}(t,this.opts.appendedArcs);for(const t of this.opts.remaps)t.layer.shapes[t.featureId]=Es(t.newShape);this.opts.source.markDisplayArcsDirty?.(),ds(this.opts.source.getDataset?.())}}undo(){const t=this.opts.source.getArcs();if(t){!function(t,e){const n=t.getVertexData?.();if(!n)return;const{xx:r,yy:i,zz:s,nn:a}=n;if(a.length===e)return;if(e>a.length)return;let o=0;for(let t=0;t<e;t++)o+=a[t];const l=new Int32Array(e);l.set(a.subarray(0,e));const h=new Float64Array(r.subarray(0,o)),c=new Float64Array(i.subarray(0,o)),u=s?new Float64Array(s.subarray(0,o)):null;t.updateVertexData(l,h,c,u)}(t,this.opts.originalArcCount);for(const t of this.opts.remaps)t.layer.shapes[t.featureId]=Es(t.originalShape);this.opts.source.markDisplayArcsDirty?.(),ds(this.opts.source.getDataset?.())}}}function bs(t,e,n){const r=t.getArcs();if(!r)return null;const i=r.size();if(0===i||0===e.length)return null;const s=new Uint32Array(i),a=new Uint32Array(i),o=new Set;for(const t of e)o.add(Cs(t.layer,t.featureId));for(const t of n){if(!t.shapes)continue;if(!ps(t))continue;const e=t.shapes;for(let n=0;n<e.length;n++){const r=e[n];if(!r)continue;const l=o.has(Cs(t,n));for(const t of r)if(Array.isArray(t))for(const e of t){if("number"!=typeof e)continue;const t=e>=0?e:~e;t<0||t>=i||(l?s[t]++:a[t]++)}}}const l=[];for(let t=0;t<i;t++)s[t]>0&&a[t]>0&&l.push(t);if(0===l.length)return null;const h=new globalThis.Map;for(let t=0;t<l.length;t++)h.set(l[t],i+t);const c=r.getVertexData?.();if(!c)return null;const{xx:u,yy:p,zz:_,ii:d,nn:f}=c,m=l.map(t=>{const e=d[t],n=f[t];return{xx:new Float64Array(u.subarray(e,e+n)),yy:new Float64Array(p.subarray(e,e+n)),zz:_?new Float64Array(_.subarray(e,e+n)):null}}),g=[];for(const t of e){if(!ps(t.layer))continue;const e=t.layer.shapes?.[t.featureId];if(!e)continue;let n=!1;const r=e.map(t=>t.map(t=>{const e=t>=0?t:~t,r=h.get(e);return void 0===r?t:(n=!0,t>=0?r:~r)}));n&&g.push({layer:t.layer,featureId:t.featureId,originalShape:Es(e),newShape:r})}return 0===g.length?null:{source:t,remaps:g,appendedArcs:m,originalArcCount:i}}function Cs(t,e){return`${t.name??""}#${e}`}function Es(t){return t.map(t=>t.slice())}class As{_emap;constructor(t){this._emap=t}translateSelected(t,e){if(0===t&&0===e)return qi.validation("offset","dx and dy are both 0 (no-op)");const n=this._emap._selection.getAll();if(0===n.length)return qi.validation("selection","selection is empty");const r=new globalThis.Map;for(const t of n){const e=this._emap.layers.resolve(t.source,t.layer);if(!e?.shapes)continue;const n=e.shapes[t.id];if(!n)continue;let i=r.get(t.source);if(i||(i={arcIdSet:new Set,pointFeatures:[]},r.set(t.source,i)),"point"===e.geometry_type)i.pointFeatures.push({layer:e,featureId:t.id});else{const t=n;for(const e of t)if(Array.isArray(e))for(const t of e)"number"==typeof t&&i.arcIdSet.add(t>=0?t:~t)}}if(0===r.size)return qi.validation("selection","no resolvable layers in selection");const i=[],s=[];for(const[n,a]of r){const r=this._emap._sources.get(n);if(!r)continue;if(0===a.arcIdSet.size&&0===a.pointFeatures.length)continue;const o=new fs({source:r,arcs:r.getArcs(),dx:t,dy:e,arcIds:Array.from(a.arcIdSet),pointFeatures:a.pointFeatures});o.do(),i.push(o),s.push(n)}if(0===i.length)return qi.validation("selection","every resolved layer was empty");const a=1===i.length?i[0]:new us(i,`Translate ${n.length} features`);return this._emap._history.push(a),this._emap._fireHistoryChange(),this._emap._clearSpatialIndexesForSources(s),this._emap._scheduleRender(),Fi}_buildSelectionBuckets(t){const e=this._emap._selection.getAll();if(0===e.length)return null;const n=new globalThis.Map;for(const t of e){const e=this._emap.layers.resolve(t.source,t.layer);if(!e?.shapes)continue;if(!e.shapes[t.id])continue;const r=this._emap._sources.get(t.source);if(!r)continue;let i=n.get(t.source);i||(i={sourceId:t.source,source:r,arcIds:[],pointFeatures:[],pathFeatures:[]},n.set(t.source,i)),"point"===e.geometry_type?i.pointFeatures.push({layer:e,featureId:t.id}):i.pathFeatures.push({layer:e,featureId:t.id})}if(0===n.size)return null;const r=[];if(t)for(const t of n.values()){if(0===t.pathFeatures.length)continue;const e=bs(t.source,t.pathFeatures,t.source.getLayers());if(!e)continue;const n=new xs(e);n.do(),r.push(n),this._emap._invalidateShapeCachesForSources([t.sourceId])}for(const t of n.values()){const e=new Set;for(const n of t.pathFeatures){const r=n.layer.shapes?.[n.featureId];if(r)for(const n of r)if(Array.isArray(n))for(const r of n){if("number"!=typeof r)continue;const n=r>=0?r:~r;e.has(n)||(e.add(n),t.arcIds.push(n))}}}return{buckets:Array.from(n.values()).map(t=>({sourceId:t.sourceId,source:t.source,arcIds:t.arcIds,pointFeatures:t.pointFeatures})),splitCmds:r}}beginTranslateSession(t){const e=this._buildSelectionBuckets(!1!==t?.splitSharedArcs);if(!e)return null;const{buckets:n,splitCmds:r}=e;let i=0,s=0,a=!1;const o=(t,e)=>{for(const r of n)0===r.arcIds.length&&0===r.pointFeatures.length||new fs({source:r.source,arcs:r.source.getArcs(),dx:t,dy:e,arcIds:r.arcIds,pointFeatures:r.pointFeatures}).do()};return{move:(t,e)=>{a||0===t&&0===e||(o(t,e),i+=t,s+=e,this._emap._scheduleRender())},commit:()=>{if(a)return!1;a=!0;if(!!(0===i&&0===s)){for(let t=r.length-1;t>=0;t--)r[t].undo();return r.length>0&&this._emap._scheduleRender(),!1}const t=n.map(t=>new fs({source:t.source,arcs:t.source.getArcs(),dx:i,dy:s,arcIds:t.arcIds,pointFeatures:t.pointFeatures})),e=n.reduce((t,e)=>t+e.arcIds.length+e.pointFeatures.length,0),o=[...r,...t],l=1===o.length?o[0]:new us(o,`Translate ${e} features`);return this._emap._history.push(l),this._emap._fireHistoryChange(),this._emap._invalidateShapeCachesForSources(n.map(t=>t.sourceId)),this._emap._scheduleRender(),!0},cancel:()=>{if(!a){a=!0,0===i&&0===s||o(-i,-s);for(let t=r.length-1;t>=0;t--)r[t].undo();i=0,s=0,r.length>0&&this._emap._invalidateShapeCachesForSources(n.map(t=>t.sourceId)),this._emap._scheduleRender()}},getAccumulated:()=>[i,s]}}beginAffineSession(t,e){const n=this._buildSelectionBuckets(!1!==e?.splitSharedArcs);if(!n)return null;const{buckets:r,splitCmds:i}=n;let s,a;if(t)[s,a]=t;else{const t=new globalThis.Map;for(const e of r)t.set(e.sourceId,{arcIdSet:new Set(e.arcIds),pointFeatures:e.pointFeatures});const e=this._computeSelectionCentroid(t);if(!e){for(let t=i.length-1;t>=0;t--)i[t].undo();return null}[s,a]=e}if(!Number.isFinite(s)||!Number.isFinite(a)){for(let t=i.length-1;t>=0;t--)i[t].undo();return null}const o=[s,a];let l={...ws},h=!1;const c=t=>1===t.a&&0===t.b&&0===t.c&&1===t.d&&0===t.tx&&0===t.ty,u=t=>{for(const e of r)0===e.arcIds.length&&0===e.pointFeatures.length||new ms({source:e.source,arcs:e.source.getArcs(),matrix:t,arcIds:e.arcIds,pointFeatures:e.pointFeatures}).do()};return{origin:o,applyDelta:t=>{h||c(t)||(u(t),l=vs(t,l),this._emap._scheduleRender())},commit:t=>{if(h)return!1;if(h=!0,c(l)){for(let t=i.length-1;t>=0;t--)i[t].undo();return i.length>0&&this._emap._scheduleRender(),!1}const e=r.reduce((t,e)=>t+e.arcIds.length+e.pointFeatures.length,0),n=r.map(e=>new ms({source:e.source,arcs:e.source.getArcs(),matrix:l,arcIds:e.arcIds,pointFeatures:e.pointFeatures,label:t})),s=[...i,...n],a=1===s.length?s[0]:new us(s,t??`Transform ${e} feature${1===e?"":"s"}`);return this._emap._history.push(a),this._emap._fireHistoryChange(),this._emap._invalidateShapeCachesForSources(r.map(t=>t.sourceId)),this._emap._scheduleRender(),!0},cancel:()=>{if(!h){h=!0,c(l)||u(Ss(l));for(let t=i.length-1;t>=0;t--)i[t].undo();l={...ws},i.length>0&&this._emap._invalidateShapeCachesForSources(r.map(t=>t.sourceId)),this._emap._scheduleRender()}},getCumulative:()=>({...l})}}rotateSelected(t,e){if(0===t)return qi.validation("angleDegrees","angle is 0 (no-op)");const n=t*Math.PI/180;return this._applyAffineToSelection((t,e)=>gs(n,t,e),e,t=>`Rotate ${t} feature${1===t?"":"s"}`)}scaleSelected(t,e,n){const r=t,i=e??t;return 1===r&&1===i?qi.validation("scale","sx and sy are both 1 (no-op)"):this._applyAffineToSelection((t,e)=>ys(r,i,t,e),n,t=>`Scale ${t} feature${1===t?"":"s"}`)}_applyAffineToSelection(t,e,n){const r=this._emap._selection.getAll();if(0===r.length)return qi.validation("selection","selection is empty");const i=new globalThis.Map;for(const t of r){const e=this._emap.layers.resolve(t.source,t.layer);if(!e?.shapes)continue;const n=e.shapes[t.id];if(!n)continue;let r=i.get(t.source);if(r||(r={arcIdSet:new Set,pointFeatures:[]},i.set(t.source,r)),"point"===e.geometry_type)r.pointFeatures.push({layer:e,featureId:t.id});else{const t=n;for(const e of t)if(Array.isArray(e))for(const t of e)"number"==typeof t&&r.arcIdSet.add(t>=0?t:~t)}}if(0===i.size)return qi.validation("selection","no resolvable layers in selection");let s,a;if(e)s=e[0],a=e[1];else{const t=this._computeSelectionCentroid(i);if(!t)return qi.validation("origin","no vertices in selection; cannot compute centroid");[s,a]=t}if(!Number.isFinite(s)||!Number.isFinite(a))return qi.validation("origin","computed origin is not finite");const o=t(s,a),l=[],h=[];for(const[t,e]of i){const n=this._emap._sources.get(t);if(!n)continue;if(0===e.arcIdSet.size&&0===e.pointFeatures.length)continue;const r=new ms({source:n,arcs:n.getArcs(),matrix:o,arcIds:Array.from(e.arcIdSet),pointFeatures:e.pointFeatures});r.do(),l.push(r),h.push(t)}if(0===l.length)return qi.validation("selection","every resolved layer was empty");const c=1===l.length?l[0]:new us(l,n(r.length));return this._emap._history.push(c),this._emap._fireHistoryChange(),this._emap._clearSpatialIndexesForSources(h),this._emap._scheduleRender(),Fi}_computeSelectionCentroid(t){let e=1/0,n=1/0,r=-1/0,i=-1/0,s=!1;for(const[a,o]of t){const t=this._emap._sources.get(a);if(!t)continue;const l=t.getArcs(),h=l?.getVertexData?.();if(h&&o.arcIdSet.size>0){const{xx:t,yy:a,ii:l,nn:c}=h;for(const h of o.arcIdSet){const o=l[h],u=c[h];for(let l=o;l<o+u;l++){const o=t[l],h=a[l];o<e&&(e=o),o>r&&(r=o),h<n&&(n=h),h>i&&(i=h),s=!0}}}for(const t of o.pointFeatures){const a=t.layer.shapes?.[t.featureId];if(a)for(const t of Ni(a)){if(!t||t.length<2)continue;const a=t[0],o=t[1];a<e&&(e=a),a>r&&(r=a),o<n&&(n=o),o>i&&(i=o),s=!0}}}return s?[(e+r)/2,(n+i)/2]:null}}class ks{opts;label;constructor(t){this.opts=t,this.label=t.label??"Edit properties"}do(){Ms(this.opts.layer,this.opts.featureId,this.opts.prev,this.opts.next)}undo(){Ms(this.opts.layer,this.opts.featureId,this.opts.next,this.opts.prev)}}function Ms(t,e,n,r){const i=t.data?.getRecords?.(),s=i?.[e];if(s){for(const t of Object.keys(r))s[t]=r[t];for(const t of Object.keys(n))t in r||delete s[t]}}class Is{opts;label;_addedIndices=[];constructor(t){this.opts=t,this.label=`Add field ${t.field}`}do(){const t=this.opts.layer.data?.getRecords?.();if(!t)return;const e=this.opts.defaultValue??null;this._addedIndices=[];for(let n=0;n<t.length;n++)t[n]&&!(this.opts.field in t[n])&&(t[n][this.opts.field]=e,this._addedIndices.push(n))}undo(){const t=this.opts.layer.data?.getRecords?.();if(t){for(const e of this._addedIndices)delete t[e]?.[this.opts.field];this._addedIndices=[]}}}class Ts{opts;label;_snapshot=new globalThis.Map;constructor(t){this.opts=t,this.label=`Remove field ${t.field}`}do(){const t=this.opts.layer.data?.getRecords?.();if(t){this._snapshot.clear();for(let e=0;e<t.length;e++){const n=t[e];n&&this.opts.field in n&&(this._snapshot.set(e,n[this.opts.field]),delete n[this.opts.field])}}}undo(){const t=this.opts.layer.data?.getRecords?.();if(t)for(const[e,n]of this._snapshot){const r=t[e];r&&(r[this.opts.field]=n)}}}class Ds{opts;label;constructor(t){this.opts=t,this.label=`Rename field ${t.from} → ${t.to}`}do(){Ps(this.opts.layer,this.opts.from,this.opts.to)}undo(){Ps(this.opts.layer,this.opts.to,this.opts.from)}}function Ps(t,e,n){const r=t.data?.getRecords?.();if(r)for(const t of r)t&&e in t&&(t[n]=t[e],delete t[e])}class Ns{_emap;constructor(t){this._emap=t}setFeatureProperty(t,e,n){return this.setFeatureProperties(t,{[e]:n})}setFeatureProperties(t,e){const n=this._emap.layers.resolve(t.source,t.layer);if(!n)return qi.notFound("layer",t.layer);const r=n.data?.getRecords?.(),i=r?.[t.id];if(!i)return qi.notFound("field",`record#${t.id}`);const s={},a={};for(const t of Object.keys(e)){const n=t in i,r=n?i[t]:void 0,o=e[t];(void 0!==o||n)&&(void 0!==o&&n&&i[t]===o||(n&&(s[t]=r),void 0!==o&&(a[t]=o)))}if(0===Object.keys(s).length&&0===Object.keys(a).length)return qi.validation("props","no-op: every requested value already matches the record");const o=new ks({layer:n,featureId:t.id,prev:s,next:a});return o.do(),this._emap._history.push(o),this._emap._fireHistoryChange(),this._emap._scheduleRender(),Fi}addField(t){const e=this._emap.layers.resolve(t.source,t.target);if(!e)return qi.notFound("layer",t.target);if(!e.data)return qi.validation("target","layer has no data table");const n=new Is({layer:e,field:t.field,defaultValue:t.defaultValue});return n.do(),this._emap._history.push(n),this._emap._fireHistoryChange(),this._emap._scheduleRender(),Fi}removeField(t){const e=this._emap.layers.resolve(t.source,t.target);if(!e)return qi.notFound("layer",t.target);if(!e.data)return qi.validation("target","layer has no data table");const n=new Ts({layer:e,field:t.field});return n.do(),this._emap._history.push(n),this._emap._fireHistoryChange(),this._emap._scheduleRender(),Fi}renameField(t){const e=this._emap.layers.resolve(t.source,t.target);if(!e)return qi.notFound("layer",t.target);if(!e.data)return qi.validation("target","layer has no data table");const n=e.data.getRecords?.();if(!n)return qi.validation("target","data table has no records");if(t.from===t.to)return qi.validation("to","`from` and `to` are identical");for(const e of n)if(e&&t.from in e&&t.to in e)return qi.validation("to",`would overwrite existing '${t.to}' on at least one record`);const r=new Ds({layer:e,from:t.from,to:t.to});return r.do(),this._emap._history.push(r),this._emap._fireHistoryChange(),this._emap._scheduleRender(),Fi}}class Rs{_onChange;_mode="none";_vertex=null;_draw=null;constructor(t){this._onChange=t}get mode(){return this._mode}get vertex(){return this._vertex}get draw(){return this._draw}setMode(t){if(t===this._mode)return;const e=this._mode;this._mode=t,"vertex"!==t&&(this._vertex=null),"draw"!==t&&(this._draw=null),this._fire(e)}setVertex(t){this._vertex!==t&&(this._vertex=t,this._fire(this._mode))}clearVertex(){null!==this._vertex&&(this._vertex=null,this._fire(this._mode))}setDraw(t){this._draw!==t&&(this._draw=t,this._fire(this._mode))}clearDraw(){null!==this._draw&&(this._draw=null,this._fire(this._mode))}_fire(t){this._onChange({current:{mode:this._mode,vertex:this._vertex,draw:this._draw},previousMode:t,modeChanged:t!==this._mode})}}var Ls={},Gs=Uint8Array,Os=Uint16Array,Fs=Int32Array,Us=new Gs([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]),qs=new Gs([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]),js=new Gs([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),zs=function(t,e){for(var n=new Os(31),r=0;r<31;++r)n[r]=e+=1<<t[r-1];var i=new Fs(n[30]);for(r=1;r<30;++r)for(var s=n[r];s<n[r+1];++s)i[s]=s-n[r]<<5|r;return{b:n,r:i}},Bs=zs(Us,2),Vs=Bs.b,$s=Bs.r;Vs[28]=258,$s[258]=28;for(var Ws=zs(qs,0),Hs=Ws.b,Ks=Ws.r,Zs=new Os(32768),Js=0;Js<32768;++Js){var Xs=(43690&Js)>>1|(21845&Js)<<1;Xs=(61680&(Xs=(52428&Xs)>>2|(13107&Xs)<<2))>>4|(3855&Xs)<<4,Zs[Js]=((65280&Xs)>>8|(255&Xs)<<8)>>1}var Ys=function(t,e,n){for(var r=t.length,i=0,s=new Os(e);i<r;++i)t[i]&&++s[t[i]-1];var a,o=new Os(e);for(i=1;i<e;++i)o[i]=o[i-1]+s[i-1]<<1;if(n){a=new Os(1<<e);var l=15-e;for(i=0;i<r;++i)if(t[i])for(var h=i<<4|t[i],c=e-t[i],u=o[t[i]-1]++<<c,p=u|(1<<c)-1;u<=p;++u)a[Zs[u]>>l]=h}else for(a=new Os(r),i=0;i<r;++i)t[i]&&(a[i]=Zs[o[t[i]-1]++]>>15-t[i]);return a},Qs=new Gs(288);for(Js=0;Js<144;++Js)Qs[Js]=8;for(Js=144;Js<256;++Js)Qs[Js]=9;for(Js=256;Js<280;++Js)Qs[Js]=7;for(Js=280;Js<288;++Js)Qs[Js]=8;var ta=new Gs(32);for(Js=0;Js<32;++Js)ta[Js]=5;var ea=Ys(Qs,9,0),na=Ys(Qs,9,1),ra=Ys(ta,5,0),ia=Ys(ta,5,1),sa=function(t){for(var e=t[0],n=1;n<t.length;++n)t[n]>e&&(e=t[n]);return e},aa=function(t,e,n){var r=e/8|0;return(t[r]|t[r+1]<<8)>>(7&e)&n},oa=function(t,e){var n=e/8|0;return(t[n]|t[n+1]<<8|t[n+2]<<16)>>(7&e)},la=function(t){return(t+7)/8|0},ha=function(t,e,n){return(null==e||e<0)&&(e=0),(null==n||n>t.length)&&(n=t.length),new Gs(t.subarray(e,n))},ca=["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"],ua=function(t,e,n){var r=new Error(e||ca[t]);if(r.code=t,Error.captureStackTrace&&Error.captureStackTrace(r,ua),!n)throw r;return r},pa=function(t,e,n,r){var i=t.length,s=r?r.length:0;if(!i||e.f&&!e.l)return n||new Gs(0);var a=!n,o=a||2!=e.i,l=e.i;a&&(n=new Gs(3*i));var h=function(t){var e=n.length;if(t>e){var r=new Gs(Math.max(2*e,t));r.set(n),n=r}},c=e.f||0,u=e.p||0,p=e.b||0,_=e.l,d=e.d,f=e.m,m=e.n,g=8*i;do{if(!_){c=aa(t,u,1);var y=aa(t,u+1,3);if(u+=3,!y){var v=t[(T=la(u)+4)-4]|t[T-3]<<8,w=T+v;if(w>i){l&&ua(0);break}o&&h(p+v),n.set(t.subarray(T,w),p),e.b=p+=v,e.p=u=8*w,e.f=c;continue}if(1==y)_=na,d=ia,f=9,m=5;else if(2==y){var S=aa(t,u,31)+257,x=aa(t,u+10,15)+4,b=S+aa(t,u+5,31)+1;u+=14;for(var C=new Gs(b),E=new Gs(19),A=0;A<x;++A)E[js[A]]=aa(t,u+3*A,7);u+=3*x;var k=sa(E),M=(1<<k)-1,I=Ys(E,k,1);for(A=0;A<b;){var T,D=I[aa(t,u,M)];if(u+=15&D,(T=D>>4)<16)C[A++]=T;else{var P=0,N=0;for(16==T?(N=3+aa(t,u,3),u+=2,P=C[A-1]):17==T?(N=3+aa(t,u,7),u+=3):18==T&&(N=11+aa(t,u,127),u+=7);N--;)C[A++]=P}}var R=C.subarray(0,S),L=C.subarray(S);f=sa(R),m=sa(L),_=Ys(R,f,1),d=Ys(L,m,1)}else ua(1);if(u>g){l&&ua(0);break}}o&&h(p+131072);for(var G=(1<<f)-1,O=(1<<m)-1,F=u;;F=u){var U=(P=_[oa(t,u)&G])>>4;if((u+=15&P)>g){l&&ua(0);break}if(P||ua(2),U<256)n[p++]=U;else{if(256==U){F=u,_=null;break}var q=U-254;if(U>264){var j=Us[A=U-257];q=aa(t,u,(1<<j)-1)+Vs[A],u+=j}var z=d[oa(t,u)&O],B=z>>4;z||ua(3),u+=15&z;L=Hs[B];if(B>3){j=qs[B];L+=oa(t,u)&(1<<j)-1,u+=j}if(u>g){l&&ua(0);break}o&&h(p+131072);var V=p+q;if(p<L){var $=s-L,W=Math.min(L,V);for($+p<0&&ua(3);p<W;++p)n[p]=r[$+p]}for(;p<V;++p)n[p]=n[p-L]}}e.l=_,e.p=F,e.b=p,e.f=c,_&&(c=1,e.m=f,e.d=d,e.n=m)}while(!c);return p!=n.length&&a?ha(n,0,p):n.subarray(0,p)},_a=function(t,e,n){n<<=7&e;var r=e/8|0;t[r]|=n,t[r+1]|=n>>8},da=function(t,e,n){n<<=7&e;var r=e/8|0;t[r]|=n,t[r+1]|=n>>8,t[r+2]|=n>>16},fa=function(t,e){for(var n=[],r=0;r<t.length;++r)t[r]&&n.push({s:r,f:t[r]});var i=n.length,s=n.slice();if(!i)return{t:xa,l:0};if(1==i){var a=new Gs(n[0].s+1);return a[n[0].s]=1,{t:a,l:1}}n.sort(function(t,e){return t.f-e.f}),n.push({s:-1,f:25001});var o=n[0],l=n[1],h=0,c=1,u=2;for(n[0]={s:-1,f:o.f+l.f,l:o,r:l};c!=i-1;)o=n[n[h].f<n[u].f?h++:u++],l=n[h!=c&&n[h].f<n[u].f?h++:u++],n[c++]={s:-1,f:o.f+l.f,l:o,r:l};var p=s[0].s;for(r=1;r<i;++r)s[r].s>p&&(p=s[r].s);var _=new Os(p+1),d=ma(n[c-1],_,0);if(d>e){r=0;var f=0,m=d-e,g=1<<m;for(s.sort(function(t,e){return _[e.s]-_[t.s]||t.f-e.f});r<i;++r){var y=s[r].s;if(!(_[y]>e))break;f+=g-(1<<d-_[y]),_[y]=e}for(f>>=m;f>0;){var v=s[r].s;_[v]<e?f-=1<<e-_[v]++-1:++r}for(;r>=0&&f;--r){var w=s[r].s;_[w]==e&&(--_[w],++f)}d=e}return{t:new Gs(_),l:d}},ma=function(t,e,n){return-1==t.s?Math.max(ma(t.l,e,n+1),ma(t.r,e,n+1)):e[t.s]=n},ga=function(t){for(var e=t.length;e&&!t[--e];);for(var n=new Os(++e),r=0,i=t[0],s=1,a=function(t){n[r++]=t},o=1;o<=e;++o)if(t[o]==i&&o!=e)++s;else{if(!i&&s>2){for(;s>138;s-=138)a(32754);s>2&&(a(s>10?s-11<<5|28690:s-3<<5|12305),s=0)}else if(s>3){for(a(i),--s;s>6;s-=6)a(8304);s>2&&(a(s-3<<5|8208),s=0)}for(;s--;)a(i);s=1,i=t[o]}return{c:n.subarray(0,r),n:e}},ya=function(t,e){for(var n=0,r=0;r<e.length;++r)n+=t[r]*e[r];return n},va=function(t,e,n){var r=n.length,i=la(e+2);t[i]=255&r,t[i+1]=r>>8,t[i+2]=255^t[i],t[i+3]=255^t[i+1];for(var s=0;s<r;++s)t[i+s+4]=n[s];return 8*(i+4+r)},wa=function(t,e,n,r,i,s,a,o,l,h,c){_a(e,c++,n),++i[256];for(var u=fa(i,15),p=u.t,_=u.l,d=fa(s,15),f=d.t,m=d.l,g=ga(p),y=g.c,v=g.n,w=ga(f),S=w.c,x=w.n,b=new Os(19),C=0;C<y.length;++C)++b[31&y[C]];for(C=0;C<S.length;++C)++b[31&S[C]];for(var E=fa(b,7),A=E.t,k=E.l,M=19;M>4&&!A[js[M-1]];--M);var I,T,D,P,N=h+5<<3,R=ya(i,Qs)+ya(s,ta)+a,L=ya(i,p)+ya(s,f)+a+14+3*M+ya(b,A)+2*b[16]+3*b[17]+7*b[18];if(l>=0&&N<=R&&N<=L)return va(e,c,t.subarray(l,l+h));if(_a(e,c,1+(L<R)),c+=2,L<R){I=Ys(p,_,0),T=p,D=Ys(f,m,0),P=f;var G=Ys(A,k,0);_a(e,c,v-257),_a(e,c+5,x-1),_a(e,c+10,M-4),c+=14;for(C=0;C<M;++C)_a(e,c+3*C,A[js[C]]);c+=3*M;for(var O=[y,S],F=0;F<2;++F){var U=O[F];for(C=0;C<U.length;++C){var q=31&U[C];_a(e,c,G[q]),c+=A[q],q>15&&(_a(e,c,U[C]>>5&127),c+=U[C]>>12)}}}else I=ea,T=Qs,D=ra,P=ta;for(C=0;C<o;++C){var j=r[C];if(j>255){da(e,c,I[(q=j>>18&31)+257]),c+=T[q+257],q>7&&(_a(e,c,j>>23&31),c+=Us[q]);var z=31&j;da(e,c,D[z]),c+=P[z],z>3&&(da(e,c,j>>5&8191),c+=qs[z])}else da(e,c,I[j]),c+=T[j]}return da(e,c,I[256]),c+T[256]},Sa=new Fs([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),xa=new Gs(0),ba=function(){for(var t=new Int32Array(256),e=0;e<256;++e){for(var n=e,r=9;--r;)n=(1&n&&-306674912)^n>>>1;t[e]=n}return t}(),Ca=function(){var t=-1;return{p:function(e){for(var n=t,r=0;r<e.length;++r)n=ba[255&n^e[r]]^n>>>8;t=n},d:function(){return~t}}},Ea=function(t,e,n,r,i){if(!i&&(i={l:1},e.dictionary)){var s=e.dictionary.subarray(-32768),a=new Gs(s.length+t.length);a.set(s),a.set(t,s.length),t=a,i.w=s.length}return function(t,e,n,r,i,s){var a=s.z||t.length,o=new Gs(r+a+5*(1+Math.ceil(a/7e3))+i),l=o.subarray(r,o.length-i),h=s.l,c=7&(s.r||0);if(e){c&&(l[0]=s.r>>3);for(var u=Sa[e-1],p=u>>13,_=8191&u,d=(1<<n)-1,f=s.p||new Os(32768),m=s.h||new Os(d+1),g=Math.ceil(n/3),y=2*g,v=function(e){return(t[e]^t[e+1]<<g^t[e+2]<<y)&d},w=new Fs(25e3),S=new Os(288),x=new Os(32),b=0,C=0,E=s.i||0,A=0,k=s.w||0,M=0;E+2<a;++E){var I=v(E),T=32767&E,D=m[I];if(f[T]=D,m[I]=T,k<=E){var P=a-E;if((b>7e3||A>24576)&&(P>423||!h)){c=wa(t,l,0,w,S,x,C,A,M,E-M,c),A=b=C=0,M=E;for(var N=0;N<286;++N)S[N]=0;for(N=0;N<30;++N)x[N]=0}var R=2,L=0,G=_,O=T-D&32767;if(P>2&&I==v(E-O))for(var F=Math.min(p,P)-1,U=Math.min(32767,E),q=Math.min(258,P);O<=U&&--G&&T!=D;){if(t[E+R]==t[E+R-O]){for(var j=0;j<q&&t[E+j]==t[E+j-O];++j);if(j>R){if(R=j,L=O,j>F)break;var z=Math.min(O,j-2),B=0;for(N=0;N<z;++N){var V=E-O+N&32767,$=V-f[V]&32767;$>B&&(B=$,D=V)}}}O+=(T=D)-(D=f[T])&32767}if(L){w[A++]=268435456|$s[R]<<18|Ks[L];var W=31&$s[R],H=31&Ks[L];C+=Us[W]+qs[H],++S[257+W],++x[H],k=E+R,++b}else w[A++]=t[E],++S[t[E]]}}for(E=Math.max(E,k);E<a;++E)w[A++]=t[E],++S[t[E]];c=wa(t,l,h,w,S,x,C,A,M,E-M,c),h||(s.r=7&c|l[c/8|0]<<3,c-=7,s.h=m,s.p=f,s.i=E,s.w=k)}else{for(E=s.w||0;E<a+h;E+=65535){var K=E+65535;K>=a&&(l[c/8|0]=h,K=a),c=va(l,c+1,t.subarray(E,K))}s.i=a}return ha(o,0,r+la(c)+i)}(t,null==e.level?6:e.level,null==e.mem?i.l?Math.ceil(1.5*Math.max(8,Math.min(13,Math.log(t.length)))):20:12+e.mem,n,r,i)},Aa=function(t,e){var n={};for(var r in t)n[r]=t[r];for(var r in e)n[r]=e[r];return n},ka=function(t,e,n){for(var r=t(),i=t.toString(),s=i.slice(i.indexOf("[")+1,i.lastIndexOf("]")).replace(/\s+/g,"").split(","),a=0;a<r.length;++a){var o=r[a],l=s[a];if("function"==typeof o){e+=";"+l+"=";var h=o.toString();if(o.prototype)if(-1!=h.indexOf("[native code]")){var c=h.indexOf(" ",8)+1;e+=h.slice(c,h.indexOf("(",c))}else for(var u in e+=h,o.prototype)e+=";"+l+".prototype."+u+"="+o.prototype[u].toString();else e+=h}else n[l]=o}return e},Ma=[],Ia=function(t,e,n,r){if(!Ma[n]){for(var i="",s={},a=t.length-1,o=0;o<a;++o)i=ka(t[o],i,s);Ma[n]={c:ka(t[a],i,s),e:s}}var l=Aa({},Ma[n].e);return function(t,e,n,r,i){var s=new Worker(Ls[e]||(Ls[e]=URL.createObjectURL(new Blob([t+';addEventListener("error",function(e){e=e.error;postMessage({$e$:[e.message,e.code,e.stack]})})'],{type:"text/javascript"}))));return s.onmessage=function(t){var e=t.data,n=e.$e$;if(n){var r=new Error(n[0]);r.code=n[1],r.stack=n[2],i(r,null)}else i(null,e)},s.postMessage(n,r),s}(Ma[n].c+";onmessage=function(e){for(var k in e.data)self[k]=e.data[k];onmessage="+e.toString()+"}",n,l,function(t){var e=[];for(var n in t)t[n].buffer&&e.push((t[n]=new t[n].constructor(t[n])).buffer);return e}(l),r)},Ta=function(){return[Gs,Os,Fs,Us,qs,js,Vs,Hs,na,ia,Zs,ca,Ys,sa,aa,oa,la,ha,ua,pa,Ua,Da,Pa]},Da=function(t){return postMessage(t,[t.buffer])},Pa=function(t){return t&&{out:t.size&&new Gs(t.size),dictionary:t.dictionary}},Na=function(t,e){return t[e]|t[e+1]<<8},Ra=function(t,e){return(t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24)>>>0},La=function(t,e){return Ra(t,e)+4294967296*Ra(t,e+4)},Ga=function(t,e,n){for(;n;++e)t[e]=n,n>>>=8};function Oa(t,e){return Ea(t,e||{},0,0)}function Fa(t,e,n){return n||(n=e,e={}),"function"!=typeof n&&ua(7),function(t,e,n,r,i,s){var a=Ia(n,r,i,function(t,e){a.terminate(),s(t,e)});return a.postMessage([t,e],e.consume?[t.buffer]:[]),function(){a.terminate()}}(t,e,[Ta],function(t){return Da(Ua(t.data[0],Pa(t.data[1])))},1,n)}function Ua(t,e){return pa(t,{i:2},e&&e.out,e&&e.dictionary)}var qa=function(t,e,n,r){for(var i in t){var s=t[i],a=e+i,o=r;Array.isArray(s)&&(o=Aa(r,s[1]),s=s[0]),s instanceof Gs?n[a]=[s,o]:(n[a+="/"]=[new Gs(0),o],qa(s,a,n,r))}},ja="undefined"!=typeof TextEncoder&&new TextEncoder,za="undefined"!=typeof TextDecoder&&new TextDecoder;try{za.decode(xa,{stream:!0})}catch(t){}function Ba(t,e){if(ja)return ja.encode(t);for(var n=t.length,r=new Gs(t.length+(t.length>>1)),i=0,s=function(t){r[i++]=t},a=0;a<n;++a){if(i+5>r.length){var o=new Gs(i+8+(n-a<<1));o.set(r),r=o}var l=t.charCodeAt(a);l<128||e?s(l):l<2048?(s(192|l>>6),s(128|63&l)):l>55295&&l<57344?(s(240|(l=65536+(1047552&l)|1023&t.charCodeAt(++a))>>18),s(128|l>>12&63),s(128|l>>6&63),s(128|63&l)):(s(224|l>>12),s(128|l>>6&63),s(128|63&l))}return ha(r,0,i)}function Va(t,e){if(e){for(var n="",r=0;r<t.length;r+=16384)n+=String.fromCharCode.apply(null,t.subarray(r,r+16384));return n}if(za)return za.decode(t);var i=function(t){for(var e="",n=0;;){var r=t[n++],i=(r>127)+(r>223)+(r>239);if(n+i>t.length)return{s:e,r:ha(t,n-1)};i?3==i?(r=((15&r)<<18|(63&t[n++])<<12|(63&t[n++])<<6|63&t[n++])-65536,e+=String.fromCharCode(55296|r>>10,56320|1023&r)):e+=1&i?String.fromCharCode((31&r)<<6|63&t[n++]):String.fromCharCode((15&r)<<12|(63&t[n++])<<6|63&t[n++]):e+=String.fromCharCode(r)}}(t),s=i.s;return(n=i.r).length&&ua(8),s}var $a=function(t,e){for(;1!=Na(t,e);e+=4+Na(t,e+2));return[La(t,e+12),La(t,e+4),La(t,e+20)]},Wa=function(t){var e=0;if(t)for(var n in t){var r=t[n].length;r>65535&&ua(9),e+=r+4}return e},Ha=function(t,e,n,r,i,s,a,o){var l=r.length,h=n.extra,c=o&&o.length,u=Wa(h);Ga(t,e,null!=a?33639248:67324752),e+=4,null!=a&&(t[e++]=20,t[e++]=n.os),t[e]=20,e+=2,t[e++]=n.flag<<1|(s<0&&8),t[e++]=i&&8,t[e++]=255&n.compression,t[e++]=n.compression>>8;var p=new Date(null==n.mtime?Date.now():n.mtime),_=p.getFullYear()-1980;if((_<0||_>119)&&ua(10),Ga(t,e,_<<25|p.getMonth()+1<<21|p.getDate()<<16|p.getHours()<<11|p.getMinutes()<<5|p.getSeconds()>>1),e+=4,-1!=s&&(Ga(t,e,n.crc),Ga(t,e+4,s<0?-s-2:s),Ga(t,e+8,n.size)),Ga(t,e+12,l),Ga(t,e+14,u),e+=16,null!=a&&(Ga(t,e,c),Ga(t,e+6,n.attrs),Ga(t,e+10,a),e+=14),t.set(r,e),e+=l,u)for(var d in h){var f=h[d],m=f.length;Ga(t,e,+d),Ga(t,e+2,m),t.set(f,e+4),e+=4+m}return c&&(t.set(o,e),e+=c),e};function Ka(t,e){e||(e={});var n={},r=[];qa(t,"",n,e);var i=0,s=0;for(var a in n){var o=n[a],l=o[0],h=o[1],c=0==h.level?0:8,u=(b=Ba(a)).length,p=h.comment,_=p&&Ba(p),d=_&&_.length,f=Wa(h.extra);u>65535&&ua(11);var m=c?Oa(l,h):l,g=m.length,y=Ca();y.p(l),r.push(Aa(h,{size:l.length,crc:y.d(),c:m,f:b,m:_,u:u!=a.length||_&&p.length!=d,o:i,compression:c})),i+=30+u+f+g,s+=76+2*(u+f)+(d||0)+g}for(var v=new Gs(s+22),w=i,S=s-i,x=0;x<r.length;++x){var b=r[x];Ha(v,b.o,b,b.f,b.u,b.c.length);var C=30+b.f.length+Wa(b.extra);v.set(b.c,b.o+C),Ha(v,i,b,b.f,b.u,b.c.length,b.o,b.m),i+=16+C+(b.m?b.m.length:0)}return function(t,e,n,r,i){Ga(t,e,101010256),Ga(t,e+8,n),Ga(t,e+10,n),Ga(t,e+12,r),Ga(t,e+16,i)}(v,i,r.length,S,w),v}var Za="function"==typeof queueMicrotask?queueMicrotask:"function"==typeof setTimeout?setTimeout:function(t){t()};function Ja(t,e,n){n||(n=e,e={}),"function"!=typeof n&&ua(7);var r=[],i=function(){for(var t=0;t<r.length;++t)r[t]()},s={},a=function(t,e){Za(function(){n(t,e)})};Za(function(){a=n});for(var o=t.length-22;101010256!=Ra(t,o);--o)if(!o||t.length-o>65558)return a(ua(13,0,1),null),i;var l=Na(t,o+8);if(l){var h=l,c=Ra(t,o+16),u=4294967295==c||65535==h;if(u){var p=Ra(t,o-12);(u=101075792==Ra(t,p))&&(h=l=Ra(t,p+32),c=Ra(t,p+48))}for(var _=e&&e.filter,d=function(e){var n=function(t,e,n){var r=Na(t,e+28),i=Va(t.subarray(e+46,e+46+r),!(2048&Na(t,e+8))),s=e+46+r,a=Ra(t,e+20),o=n&&4294967295==a?$a(t,s):[a,Ra(t,e+24),Ra(t,e+42)],l=o[0],h=o[1],c=o[2];return[Na(t,e+10),l,h,i,s+Na(t,e+30)+Na(t,e+32),c]}(t,c,u),o=n[0],h=n[1],p=n[2],d=n[3],f=n[4],m=n[5],g=function(t,e){return e+30+Na(t,e+26)+Na(t,e+28)}(t,m);c=f;var y=function(t,e){t?(i(),a(t,null)):(e&&(s[d]=e),--l||a(null,s))};if(!_||_({name:d,size:h,originalSize:p,compression:o}))if(o)if(8==o){var v=t.subarray(g,g+h);if(p<524288||h>.8*p)try{y(null,Ua(v,{out:new Gs(p)}))}catch(t){y(t,null)}else r.push(Fa(v,{size:p},y))}else y(ua(14,"unknown compression type "+o,1),null);else y(null,ha(t,g,g+h));else y(null,null)},f=0;f<h;++f)d()}else a(null,{});return i}const Xa=5e5;class Ya{_unfilteredArcs;_filteredArcs=null;_filteredSegLen=0;_dirty=!1;constructor(t){this._unfilteredArcs=t;(t.getPointCount?.()??0)>Xa&&this._initFilteredArcs()}markDirty(){this._dirty=!0}_initFilteredArcs(){const t=this._unfilteredArcs,e=t.getVertexData?.();if(e?.zz){const e=.08,n=Math.ceil((t.getPointCount?.()??0)/Xa),r=t.getRetainedInterval?.()??0,i=t.getThresholdByPct?.(e,n)??0;this._filteredArcs=t.setRetainedInterval?.(i)?.getFilteredCopy?.()??null,t.setRetainedInterval?.(r),this._filteredArcs&&(this._filteredSegLen=ki().getAvgSegment(this._filteredArcs))}else{const e=ki();this._filteredSegLen=4*e.getAvgSegment(t),this._filteredArcs=e.simplifyArcsFast(t,this._filteredSegLen)}}getScaledArcs(t){const e=null!==this._filteredArcs&&t>1.5*this._filteredSegLen;if(this._filteredArcs){(this._filteredArcs.size()!==this._unfilteredArcs.size()||this._dirty&&e)&&(this._initFilteredArcs(),this._dirty=!1)}else if(this._dirty){(this._unfilteredArcs.getPointCount?.()??0)>Xa&&this._initFilteredArcs(),this._dirty=!1}this._filteredArcs&&this._filteredArcs.setRetainedInterval?.(this._unfilteredArcs.getRetainedInterval?.()??0);return this._filteredArcs&&t>1.5*this._filteredSegLen?this._filteredArcs:this._unfilteredArcs}getArcs(){return this._unfilteredArcs}hasLOD(){return null!==this._filteredArcs}}class Qa{_adapter;constructor(t=ki()){this._adapter=t}async runImport(t,e){return this._adapter.runImport(t,e)}}let to=null;const eo="EPSG:4326";function no(t){if(!t)return eo;const e=t.info;if(!e)return eo;if(e.crs_string)return ro(e.crs_string);if(e.prj){const t=io(e.prj);if(t)return t}if(e.crs){if(e.crs.is_latlong)return"EPSG:4326";if("merc"===e.crs.projName&&6378137===e.crs.a)return"EPSG:3857"}return eo}function ro(t){const e=t.toLowerCase();return"wgs84"===e||e.includes("4326")?"EPSG:4326":e.includes("3857")||"webmercator"===e?"EPSG:3857":(/^epsg:\d+$/i.test(t),t.toUpperCase())}function io(t){const e=t.match(/AUTHORITY\["EPSG"\s*,\s*"(\d+)"\]/i);return e?`EPSG:${e[1]}`:/Mercator.*WGS.*84.*Pseudo/i.test(t)||/WGS.*84.*Pseudo.*Mercator/i.test(t)||/Web_Mercator/i.test(t)?"EPSG:3857":/DATUM\["WGS_1984"/i.test(t)&&/GEOGCS/i.test(t)?"EPSG:4326":null}const so={geojson:"application/geo+json",topojson:"application/json",shapefile:"application/zip",msx:"application/octet-stream"};function ao(t){return"string"==typeof t?(new TextEncoder).encode(t):t instanceof Uint8Array?t:new Uint8Array(t)}const oo={maxBytes:209715200,maxEntries:5e3,maxRatio:100};class lo extends mi{id;type="topology";_dataset;_displayArcs=null;_options;_data;_loadVersion=0;_abortController=null;_pending=null;_simplifyFloor=0;_runner;getSimplifyFloor(){return this._simplifyFloor}constructor(t,e){super(),this.id=t,this._options=e||{},this._data=this._options.data,this._runner=this._options.mapshaperRunner??to??(to=new Qa),this._data&&this._updateData()}static async fromUrl(t,e,n){const r=new lo(t,n);return await r.setData(e),r}static async fromBytes(t,e,n){const{filename:r=`${t}.geojson`,...i}=n??{},s=e instanceof Uint8Array?e:new Uint8Array(e),a=new lo(t,i);return await a.setData({filename:r,content:s}),a}setData(t){this._loadVersion++;const e=this._loadVersion;this._abortController?.abort(),this._abortController=null,this._data=t,this._pending?.resolve(this);const n=new Promise((t,n)=>{this._pending={version:e,resolve:t,reject:n}});return n.catch(()=>{}),this._updateData(),n}async _updateData(){if(!this._data)return;const t=this._loadVersion,e=new AbortController;this._abortController=e,this.fire("dataloading");try{const n={},r=[];if(Array.isArray(this._data)){if(0===this._data.length)throw new Error("setData received an empty array; nothing to import");for(const t of this._data)if(this._isZipFile(t.filename)){const e=await this._extractZip(t.content),i=this._findPrimaryFile(e);if(!i)throw new Error(`No importable file found in zip archive: ${t.filename}`);for(const[t,r]of Object.entries(e))n[t]=r;r.push(i)}else n[t.filename]=t.content,r.push(t.filename)}else{let t;if("string"==typeof this._data){const n=this._data,r=await fetch(n,{signal:e.signal});if(!r.ok)throw new Error(`Failed to fetch ${n}: HTTP ${r.status}`);const i=await r.arrayBuffer(),s=new Uint8Array(i);let a=new URL(n).pathname.split("/").pop()||"";if(!this._hasSupportedExtension(a)){const t=r.headers.get("Content-Type")||"";a=this._filenameFromContentType(t,a)}a||(a="data.json"),t={filename:a,content:s}}else t=this._data;if(this._isZipFile(t.filename)){const e=await this._extractZip(t.content),i=this._findPrimaryFile(e);if(!i)throw new Error("No importable file found in zip archive");for(const[t,r]of Object.entries(e))n[t]=r;r.push(i)}else n[t.filename]=t.content,r.push(t.filename)}const i=`-i ${r.map(t=>`"${t.replace(/"/g,'\\"')}"`).join(" ")}`,s=await this._runner.runImport(i,n);if(t!==this._loadVersion)return;this._dataset=s,this._dataset?.arcs&&(this._displayArcs=new Ya(this._dataset.arcs)),this._simplifyFloor=this._dataset?.arcs?.getRetainedInterval?.()??0,this.fire("data",{reason:"load"}),this._resolvePending(t)}catch(e){if(t!==this._loadVersion)return;if("AbortError"===e?.name)return;this.fire("error",{error:e}),this._rejectPending(t,e??new Error("setData import failed"))}}_resolvePending(t){if(this._pending?.version!==t)return;const e=this._pending;this._pending=null,e.resolve(this)}_rejectPending(t,e){if(this._pending?.version!==t)return;const n=this._pending;this._pending=null,n.reject(e)}_hasSupportedExtension(t){return/\.(json|geojson|topojson|zip|shp|kml|msx)$/i.test(t)}_filenameFromContentType(t,e){return(e||"data")+({"application/json":".json","application/geo+json":".geojson","application/vnd.geo+json":".geojson","application/topojson+json":".topojson","application/zip":".zip","application/x-zip-compressed":".zip","application/octet-stream":".zip","application/vnd.google-earth.kml+xml":".kml","text/plain":".json"}[t.toLowerCase().split(";")[0].trim()]||".json")}getDataset(){return this._dataset}getCRS(){return no(this._dataset)}async reproject(t){if(!this._dataset)return;this._dataset?.arcs?.setRetainedInterval&&this._dataset.arcs.setRetainedInterval(0),this._dataset.info&&(delete this._dataset.info.crs_string,delete this._dataset.info.prj,delete this._dataset.info.wkt1);const e=`-proj ${t}`,n=await ki().runOnDataset(e,this._dataset);this._dataset=n,this._dataset?.arcs&&(this._displayArcs=new Ya(this._dataset.arcs))}getExtent(){if(!this._dataset)return new yi;const t=ki().getDatasetBounds(this._dataset);return new yi(t.xmin,t.ymin,t.xmax,t.ymax)}getArcs(){return this._dataset?.arcs}getDisplayArcs(){return this._displayArcs}markDisplayArcsDirty(){this._displayArcs?.markDirty()}refreshDisplayArcs(){this._dataset?.arcs&&(this._displayArcs=new Ya(this._dataset.arcs))}setDataset(t){this._dataset=t,t.arcs?this._displayArcs=new Ya(t.arcs):this._displayArcs=null,this._simplifyFloor=t.arcs?.getRetainedInterval?.()??0,this.fire("data",{reason:"replace"})}async export(t){if(!this._dataset)throw new Error("TopologySource has no dataset to export");const e=this._dataset.arcs,n=e?.getRetainedInterval?.()??0;n&&e?.setRetainedInterval&&e.setRetainedInterval(0);try{const e=ki(),n="msx"===t.format?await e.exportPackedDatasets([this._dataset],{compact:!0}):e.exportFileContent(this._dataset,{format:t.format});return this._filesToBlob(n,t.format)}finally{n&&e?.setRetainedInterval&&e.setRetainedInterval(n)}}_filesToBlob(t,e){if(0===t.length)throw new Error(`mapshaper produced no output for format=${e}`);if("shapefile"===e){const e={};for(const n of t)e[n.filename]=ao(n.content);const n=Ka(e);return new Blob([n],{type:so.shapefile})}return new Blob([t[0].content],{type:so[e]})}getLayers(){return this._dataset?.layers||[]}_isZipFile(t){return/\.zip$/i.test(t)}async _extractZip(t){const e={...oo,...this._options.zipLimits};let n=0,r=0;const i=await new Promise((i,s)=>{Ja(t,{filter:i=>{if(r++,r>e.maxEntries)throw new Error(`ZIP extraction limit exceeded: ${r} entries > maxEntries ${e.maxEntries}`);if(n+=i.originalSize,n>e.maxBytes)throw new Error(`ZIP extraction limit exceeded: uncompressed total ${n} > maxBytes ${e.maxBytes}`);if(t.byteLength>0){const r=n/t.byteLength;if(r>e.maxRatio)throw new Error(`ZIP extraction limit exceeded: ratio ${r.toFixed(1)} > maxRatio ${e.maxRatio}`)}return!(/^__MACOSX/.test(i.name)||i.name.split("/").pop()?.startsWith("."))}},(t,e)=>{t?s(t):i(e)})}),s={};for(const t of Object.keys(i)){const e=i[t],n=t.split("/").pop()||t;this._isTextFile(n)?s[n]=Va(e):s[n]=e}return s}_isTextFile(t){return/\.(prj|cpg|csv|json|geojson|kml|txt)$/i.test(t)}_findPrimaryFile(t){const e=Object.keys(t),n=[".shp",".geojson",".json",".kml",".topojson"];for(const t of n){const n=e.find(e=>e.toLowerCase().endsWith(t));if(n)return n}return e.find(t=>!this._isAuxiliaryFile(t))||""}_isAuxiliaryFile(t){return/\.(prj|shx|dbf)$/i.test(t)}}function ho(t){const e=[];return function(n){e.push(n),e.length>t&&e.shift();return e.reduce((t,e)=>t+e,0)/e.length}}class co extends mi{_element;_active=!1;_timer=new vi;_sustainInterval=150;_fadeDelay=70;_eventTime=0;_getAverageRate=ho(10);_getWheelDirection=function(){let t=0,e=null;return function(n,r){const i=n>0?1:n<0?-1:0;(!e||r-t>300)&&(e=ho(3)),t=r;const s=e(i)||i;return s>0?1:s<0?-1:0}}();_wheelDirection=0;_mouseX=0;_mouseY=0;_wheelHandler=t=>this._handleWheel(t);constructor(t){super(),this._element=t,this._timer.on("tick",t=>this._onTick(t)),this._element.addEventListener("wheel",this._wheelHandler,{passive:!1})}destroy(){this._element.removeEventListener("wheel",this._wheelHandler),this._timer.stop()}_updateSustainInterval(t){this._fadeDelay=t+50,this._sustainInterval=this._fadeDelay+80}_handleWheel(t){const e=Date.now();if(this._wheelDirection=this._getWheelDirection(-t.deltaY,e),0===this._wheelDirection)return;t.preventDefault();const n=this._element.getBoundingClientRect();this._mouseX=t.clientX-n.left,this._mouseY=t.clientY-n.top,this._active?this._updateSustainInterval(this._getAverageRate(e-this._eventTime)):(this._active=!0,this.fire("mousewheelstart")),this._eventTime=e,this._timer.start(this._sustainInterval)}_onTick(t){const e=t.time-this._eventTime;let n=t.tickTime/25,r=0;e>this._fadeDelay&&(r=Math.min(1,(e-this._fadeDelay)/(this._sustainInterval-this._fadeDelay))),t.done?(this._active=!1,this.fire("mousewheelend")):(r>0&&(n*=wi.quadraticOut(1-r)),this.fire("mousewheel",{direction:this._wheelDirection,multiplier:n,x:this._mouseX,y:this._mouseY}))}}class uo extends mi{name="scrollZoom";_wheel;_enabled=!0;_onGestureStart;constructor(t,e){super(),this._onGestureStart=e,this._wheel=new co(t),this._wheel.on("mousewheel",t=>{this._onGestureStart?.(),this._enabled&&this.fire("mousewheel",t)})}enable(){this._enabled=!0}disable(){this._enabled=!1}isEnabled(){return this._enabled}setOptions(t){}getOptions(){return{}}handlePointer(t){return"passthrough"}destroy(){this._wheel.destroy()}}const po={skipShiftDrag:!0};class _o extends mi{name="dragPan";_opts;_enabled=!0;_dragging=!1;_last={x:0,y:0};_hoverPoint=null;_onGestureStart;_isHoveringSelected;constructor(t,e,n){super(),this._opts={...po,...t},this._onGestureStart=e,this._isHoveringSelected=n}enable(){this._enabled=!0}disable(){this._enabled=!1,this._dragging&&(this._dragging=!1,this.fire("panend"))}isEnabled(){return this._enabled}setOptions(t){this._opts={...this._opts,...t}}getOptions(){return this._opts}getCursor(){return this._enabled?this._dragging?"grabbing":this._hoverPoint&&this._isHoveringSelected?.(this._hoverPoint)?"move":"grab":null}handlePointer(t){if(!this._enabled)return"passthrough";if("down"===t.kind)return 0!==t.button||this._opts.skipShiftDrag&&t.modifiers.shift?"passthrough":(this._onGestureStart?.(),this._dragging=!0,this._last={x:t.point.x,y:t.point.y},this.fire("panstart"),"exclusive");if("move"===t.kind&&!this._dragging)return this._hoverPoint={x:t.point.x,y:t.point.y},"passthrough";if("move"===t.kind&&this._dragging){const e=t.point.x-this._last.x,n=t.point.y-this._last.y;return this._last={x:t.point.x,y:t.point.y},this.fire("pan",{dx:e,dy:n}),"exclusive"}return"up"===t.kind&&this._dragging?(this._dragging=!1,this.fire("panend"),"passthrough"):"passthrough"}}const fo=["shift","ctrl","alt","meta"];function mo(t,e,n){const r=n?function(t){return"none"===t?new Set:new Set(t.split("+"))}(n):new Set,i=t.ctrl&&!r.has("ctrl"),s=t.meta&&!r.has("meta"),a=function(t){const e=fo.filter(e=>t[e]);return 0===e.length?"none":e.join("+")}({shift:t.shift&&!r.has("shift"),ctrl:i||s,alt:t.alt&&!r.has("alt"),meta:!1});for(const t of["replace","add","toggle"]){const n=e[t];if(n&&n===a)return t}return"replace"}function go(t,e){const[n,r]=t;let i=!1;const s=e.length;for(let t=0,a=s-1;t<s;a=t++){const[s,o]=e[t],[l,h]=e[a];o>r!=h>r&&n<(l-s)*(r-o)/(h-o)+s&&(i=!i)}return i}function yo(t,e,n,r){const i=function(t,e){const n=t.getSource(e.source);if(!n)return null;let r=t.layers?.resolve(e.source,e.layer);if(!r){const t=n.getDataset?.();r=t?.layers.find((t,n)=>Pi(t,n)===e.layer||t?.name===e.layer||t?.id===e.layer)}if(!r?.shapes)return null;const i=r.shapes?.[e.id];return i?{layer:r,shape:i,arcs:n.getArcs?.()}:null}(t,e);if(!i)return!1;if("point"===i.layer.geometry_type){const e=Ni(i.shape);if(0===e.length)return!1;const s=e.map(([e,n])=>t.project(e,n));return r?s.some(t=>wo(t,n)):s.every(t=>wo(t,n))}if(!i.arcs)return!1;const s=function(t,e,n){const r=[];for(const i of e){const e=[],s=n.getShapeIter?.(i);if(s)for(;s.hasNext();)e.push(t.project(s.x,s.y));else for(const r of i){const i=r>=0?r:~r,s=n.getArcIter(i);for(;s.hasNext();)e.push(t.project(s.x,s.y))}e.length>0&&r.push(e)}return r}(t,i.shape,i.arcs);if(0===s.length)return!1;const a="polygon"===i.layer.geometry_type;return r?function(t,e,n){for(const r of t){if(r.some(t=>wo(t,e)))return!0;if(vo(r,e,n))return!0}return!(!n||!e.some(e=>function(t,e){let n=!1;for(const r of e){if(So(t,r))return!0;go(t,r)&&(n=!n)}return n}(e,t)))}(s,n,a):function(t,e,n){for(const r of t){if(!r.every(t=>wo(t,e)))return!1;if(vo(r,e,n))return!1}return!0}(s,n,a)}function vo(t,e,n){const r=n?xo(t):t,i=xo(e);for(let t=0;t<r.length-1;t++){const e=r[t],n=r[t+1];for(let t=0;t<i.length-1;t++){if(bo(e,n,i[t],i[t+1]))return!0}}return!1}function wo(t,e){return So(t,e)||go(t,e)}function So(t,e){const n=xo(e);for(let e=0;e<n.length-1;e++)if(Co(t,n[e],n[e+1]))return!0;return!1}function xo(t){if(t.length<2)return t;const e=t[0],n=t[t.length-1];return r=e,i=n,Math.abs(r[0]-i[0])<=ko&&Math.abs(r[1]-i[1])<=ko?t:[...t,e];var r,i}function bo(t,e,n,r){const i=Eo(t,e,n),s=Eo(t,e,r),a=Eo(n,r,t),o=Eo(n,r,e);return!(!Ao(i)||!Co(n,t,e))||(!(!Ao(s)||!Co(r,t,e))||(!(!Ao(a)||!Co(t,n,r))||(!(!Ao(o)||!Co(e,n,r))||i>0!=s>0&&a>0!=o>0)))}function Co(t,e,n){return!!Ao(Eo(e,n,t))&&(t[0]>=Math.min(e[0],n[0])-ko&&t[0]<=Math.max(e[0],n[0])+ko&&t[1]>=Math.min(e[1],n[1])-ko&&t[1]<=Math.max(e[1],n[1])+ko)}function Eo(t,e,n){return(e[0]-t[0])*(n[1]-t[1])-(e[1]-t[1])*(n[0]-t[0])}function Ao(t){return Math.abs(t)<=ko}const ko=1e-9;function Mo(t){const e=new Set,n=[];for(const r of t){const t=`${r.source}|${r.layer}|${r.id}`;e.has(t)||(e.add(t),n.push({source:r.source,layer:r.layer,id:r.id}))}return n}const Io={replace:"none",add:"shift",toggle:"shift+alt"};class To extends mi{_map;name="clickSelect";_enabled=!1;_opts={};constructor(t){super(),this._map=t}enable(){this._enabled=!0}disable(){this._enabled=!1}isEnabled(){return this._enabled}setOptions(t){this._opts={...this._opts,...t}}getOptions(){return this._opts}handlePointer(t){if(!this._enabled||"click"!==t.kind||0!==t.button)return"passthrough";const e=mo(t.modifiers,this._opts.modifiers??Io),n=Mo(this._map.queryFeatures([t.point.x,t.point.y],this._opts.layers?{layers:this._opts.layers}:void 0));return 0===n.length?("replace"===e&&this._map.select([],{mode:"replace"}),"consumed"):(this._map.select(n,{mode:e}),"consumed")}}const Do={replace:"none",add:"shift",toggle:"shift+alt"};class Po extends mi{_map;name="boxSelect";_enabled=!1;_opts={};_start=null;_overlay=null;_manager;constructor(t){super(),this._map=t}enable(){if(this._manager?.isEnabledByName("lassoSelect"))throw new Error("cannot enable boxSelect: lassoSelect is enabled (both consume selection drag gestures); disable it first");this._enabled=!0}disable(){this._enabled=!1,this._start&&this._cancel()}isEnabled(){return this._enabled}setOptions(t){this._opts={...this._opts,...t}}getOptions(){return this._opts}getCursor(){return this._enabled?"crosshair":null}get _threshold(){return this._opts.dragThreshold??4}get _activator(){return this._opts.dragActivator??"none"}_ensureOverlay(){if(this._overlay)return this._overlay;const t=document.createElement("div");t.className="emap-box-select",t.style.position="absolute",t.style.pointerEvents="none",t.style.display="none",t.style.boxSizing="border-box";const e=this._opts.style??{};return t.style.border=`${e.strokeWidth??1.5}px solid ${e.stroke??"#0078ff"}`,t.style.background=e.fill??"rgba(0, 120, 255, 0.1)",this._map.getCanvasContainer().appendChild(t),this._overlay=t,t}_cancel(){this._overlay&&(this._overlay.style.display="none"),this._start=null}handlePointer(t){if(!this._enabled)return"passthrough";if("down"===t.kind){if(0!==t.button||!function(t,e){return"none"===e||e.split("+").every(e=>!0===t[e])}(t.modifiers,this._activator))return"passthrough";this._start={x:t.point.x,y:t.point.y};const e=this._ensureOverlay();return e.style.left=`${t.point.x}px`,e.style.top=`${t.point.y}px`,e.style.width="0",e.style.height="0",e.style.display="block","exclusive"}if("move"===t.kind&&this._start){const e=this._ensureOverlay(),n=Math.min(this._start.x,t.point.x),r=Math.min(this._start.y,t.point.y);return e.style.left=`${n}px`,e.style.top=`${r}px`,e.style.width=`${Math.abs(t.point.x-this._start.x)}px`,e.style.height=`${Math.abs(t.point.y-this._start.y)}px`,"exclusive"}if("up"===t.kind&&this._start){const e=this._start,{x:n,y:r}=t.point;if(this._cancel(),Math.hypot(n-e.x,r-e.y)<this._threshold)return"passthrough";const i=Math.min(e.x,n),s=Math.min(e.y,r),a=Math.max(e.x,n),o=Math.max(e.y,r),l=this._map.queryFeatures([[i,s],[a,o]],this._opts.layers?{layers:this._opts.layers}:void 0),h=mo(t.modifiers,this._opts.modifiers??Do,this._activator);return this._map.select(Mo(l),{mode:h}),"passthrough"}return"passthrough"}}const No={replace:"none",add:"ctrl",toggle:"alt"},Ro="http://www.w3.org/2000/svg";class Lo extends mi{_map;name="lassoSelect";_enabled=!1;_opts={};_path=null;_svg=null;_poly=null;_manager;constructor(t){super(),this._map=t}enable(){if(this._manager?.isEnabledByName("boxSelect"))throw new Error("cannot enable lassoSelect: boxSelect is enabled (both consume selection drag gestures); disable it first");this._enabled=!0}disable(){this._enabled=!1,this._path&&this._cancel()}isEnabled(){return this._enabled}setOptions(t){this._opts={...this._opts,...t}}getOptions(){return this._opts}getCursor(){return this._enabled?"crosshair":null}get _threshold(){return this._opts.dragThreshold??4}get _activator(){return this._opts.dragActivator??"shift"}_ensureSvg(){if(this._svg&&this._poly)return{svg:this._svg,poly:this._poly};const t=document.createElementNS(Ro,"svg");t.style.position="absolute",t.style.left="0",t.style.top="0",t.style.width="100%",t.style.height="100%",t.style.pointerEvents="none",t.style.display="none",t.setAttribute("class","emap-lasso-select");const e=document.createElementNS(Ro,"polyline"),n=this._opts.style??{};return e.setAttribute("fill",n.fill??"rgba(0, 120, 255, 0.1)"),e.setAttribute("stroke",n.stroke??"#0078ff"),e.setAttribute("stroke-width",String(n.strokeWidth??1.5)),e.setAttribute("stroke-dasharray",n.strokeDasharray??"4 3"),e.setAttribute("points",""),t.appendChild(e),this._map.getCanvasContainer().appendChild(t),this._svg=t,this._poly=e,{svg:t,poly:e}}_cancel(){this._svg&&(this._svg.style.display="none"),this._path=null}handlePointer(t){if(!this._enabled)return"passthrough";if("down"===t.kind){if(0!==t.button||!function(t,e){return"none"===e||e.split("+").every(e=>!0===t[e])}(t.modifiers,this._activator))return"passthrough";const{svg:e,poly:n}=this._ensureSvg();return this._path=[[t.point.x,t.point.y]],n.setAttribute("points",`${t.point.x},${t.point.y}`),e.style.display="block","exclusive"}if("move"===t.kind&&this._path)return this._path.push([t.point.x,t.point.y]),this._poly?.setAttribute("points",this._path.map(t=>`${t[0]},${t[1]}`).join(" ")),"exclusive";if("up"===t.kind&&this._path){const e=this._path;if(this._cancel(),e.length<3)return"passthrough";const n=function(t){let e=1/0,n=1/0,r=-1/0,i=-1/0;for(const[s,a]of t)s<e&&(e=s),a<n&&(n=a),s>r&&(r=s),a>i&&(i=a);return[e,n,r,i]}(e);if(Math.hypot(n[2]-n[0],n[3]-n[1])<this._threshold)return"passthrough";const r=e.slice();r.push(e[0]);const i=this._map.queryFeatures([[n[0],n[1]],[n[2],n[3]]],this._opts.layers?{layers:this._opts.layers}:void 0),s=!1!==this._opts.includeIntersecting,a=[],o=new Set;for(const t of i){const e=`${t.source}|${t.layer}|${t.id}`;o.has(e)||yo(this._map,t,r,s)&&(o.add(e),a.push({source:t.source,layer:t.layer,id:t.id}))}const l=mo(t.modifiers,this._opts.modifiers??No,this._activator);return this._map.select(a,{mode:l}),"passthrough"}return"passthrough"}}class Go{opts;label="Move vertex";_mergeAt=Date.now();constructor(t){this.opts=t}do(){(this.opts.adapter??ki()).snapVertices(this.opts.vertexIds,this.opts.to,this.opts.arcs),this.opts.source.markDisplayArcsDirty?.(),ds(this.opts.source.getDataset?.())}undo(){(this.opts.adapter??ki()).snapVertices(this.opts.vertexIds,this.opts.from,this.opts.arcs),this.opts.source.markDisplayArcsDirty?.(),ds(this.opts.source.getDataset?.())}mergeable(t){if(!(t instanceof Go))return!1;if(t.opts.source!==this.opts.source)return!1;if(Date.now()-t._mergeAt>500)return!1;const e=t.opts.vertexIds,n=this.opts.vertexIds;if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(e[t]!==n[t])return!1;return!0}merge(t){t instanceof Go&&(this.opts.to=t.opts.to,this._mergeAt=Date.now())}}class Oo{opts;label="Insert vertex";constructor(t){this.opts=t}do(){(this.opts.adapter??ki()).insertVertex(this.opts.arcs,this.opts.insertionId,this.opts.point),this.opts.source.markDisplayArcsDirty?.(),ds(this.opts.source.getDataset?.())}undo(){(this.opts.adapter??ki()).deleteVertex(this.opts.arcs,this.opts.insertionId),this.opts.source.markDisplayArcsDirty?.(),ds(this.opts.source.getDataset?.())}}class Fo{opts;label="Delete vertex";constructor(t){this.opts=t}do(){(this.opts.adapter??ki()).deleteVertex(this.opts.arcs,this.opts.vertexIndex),this.opts.source.markDisplayArcsDirty?.(),ds(this.opts.source.getDataset?.())}undo(){(this.opts.adapter??ki()).insertVertex(this.opts.arcs,this.opts.vertexIndex,this.opts.coords),this.opts.source.markDisplayArcsDirty?.(),ds(this.opts.source.getDataset?.())}}class Uo{name="vertexEdit";_map;_enabled=!1;_manager;_polygonFillColor;_hoveredFeature=null;_hoverVertexCoords=null;_hoverVertexIds=[];_hoverType=null;_hoverInsertionId=-1;_dragging=!1;_neighborShapes=[];_dragFromCoords=null;_snapThreshold;_snapToVertex;_snapToEdge;_onMapMoveBound=()=>this._onMapMove();constructor(t,e={}){this._map=t,this._polygonFillColor=void 0!==e.polygonFillColor?e.polygonFillColor:"rgba(0,0,0,0.15)",this._snapThreshold=e.snapThreshold??10,this._snapToVertex=!1!==e.snapToVertex,this._snapToEdge=!1!==e.snapToEdge}isEnabled(){return this._enabled}enable(){this._enabled||(this._enabled=!0,this._map.setEditMode("vertex"),this._map.on("move",this._onMapMoveBound),this._manager?.refreshCursor())}getCursor(){return this._enabled?"crosshair":null}disable(){this._enabled&&(this._enabled=!1,this._hoveredFeature=null,this._hoverVertexCoords=null,this._hoverVertexIds=[],this._hoverType=null,this._hoverInsertionId=-1,this._neighborShapes=[],this._dragging=!1,this._map.setEditMode("none"),this._map.clearEditVertexState(),this._map.off("move",this._onMapMoveBound),this._manager?.refreshCursor(),this._map.render())}setOptions(t){void 0!==t.polygonFillColor&&(this._polygonFillColor=t.polygonFillColor),void 0!==t.snapThreshold&&(this._snapThreshold=t.snapThreshold),void 0!==t.snapToVertex&&(this._snapToVertex=t.snapToVertex),void 0!==t.snapToEdge&&(this._snapToEdge=t.snapToEdge)}getOptions(){return{polygonFillColor:this._polygonFillColor??void 0,snapThreshold:this._snapThreshold,snapToVertex:this._snapToVertex,snapToEdge:this._snapToEdge}}handlePointer(t){if(!this._enabled)return"passthrough";const e=t.point.x,n=t.point.y;return"move"===t.kind?this._dragging?(this._handleDrag(e,n),"exclusive"):(this._onMouseMove(e,n),"passthrough"):"down"===t.kind?0!==t.button?"passthrough":(this._onMouseDown(e,n),this._dragging?"exclusive":"passthrough"):"up"===t.kind?this._dragging?(this._finishDrag(e,n),"passthrough"):"passthrough":"contextmenu"===t.kind?(this._onContextMenu(t.originalEvent),"consumed"):"passthrough"}_onMapMove(){this._hoveredFeature&&!this._dragging&&(this._updateEditState(),this._map.render())}_onContextMenu(t){if(t.preventDefault(),this._dragging)return;if("vertex"!==this._hoverType||0===this._hoverVertexIds.length)return;if(!this._hoveredFeature)return;const e=this._hoverVertexIds[0],n=this._hoveredFeature.arcs;ki().vertexIsArcEndpoint(e,n)||this._showContextMenu(t.clientX,t.clientY,()=>{this._deleteHoveredVertex()})}_deleteHoveredVertex(){if(!this._hoveredFeature||0===this._hoverVertexIds.length)return;const t=this._hoveredFeature.arcs,e=this._hoverVertexIds[0],n=this._hoveredFeature.source,r=t.getVertex2(e);if(ki().deleteVertex(t,e),this._refreshSourceDisplayArcs(n),this._bumpSourceEditVersion(n),r){const i=this._map.getSource(n);i&&this._map.pushCommand(new Fo({vertexIndex:e,coords:[r[0],r[1]],arcs:t,source:i}))}this._hoverVertexCoords=null,this._hoverVertexIds=[],this._hoverType=null,this._hoverInsertionId=-1,this._neighborShapes=[],this._map.clearEditVertexState(),this._map.render()}_refreshSourceDisplayArcs(t){this._map.getSource(t)?.refreshDisplayArcs()}_bumpSourceEditVersion(t){const e=this._map.getSource(t);ds(e?.getDataset?.()??null)}_showContextMenu(t,e,n){document.getElementById("emap-ctx-menu")?.remove();const r=document.createElement("div");r.id="emap-ctx-menu",r.className="emap-ctx-menu",r.style.left=`${t}px`,r.style.top=`${e}px`;const i=document.createElement("div");i.className="emap-ctx-menu-item",i.textContent="删除节点",i.addEventListener("click",t=>{t.stopPropagation(),r.remove(),document.removeEventListener("click",s),n()}),r.appendChild(i),document.body.appendChild(r);const s=()=>{r.remove(),document.removeEventListener("click",s)};setTimeout(()=>document.addEventListener("click",s),0)}_onMouseMove(t,e){const n=this._map.queryFeatures([t,e]);if(0===n.length)return this._hoveredFeature=null,this._hoverVertexCoords=null,this._hoverVertexIds=[],this._hoverType=null,this._hoverInsertionId=-1,this._neighborShapes=[],this._map.clearEditVertexState(),void this._map.render();const r=n[0];if("point"===r.geometryType)return this._hoveredFeature=null,this._hoverVertexCoords=null,this._hoverVertexIds=[],this._hoverType=null,this._hoverInsertionId=-1,this._neighborShapes=[],this._map.clearEditVertexState(),void this._map.render();const i=this._map.getSource(r.source);if(!i)return;const s=i.getLayers(),a=i.getArcs();if(!a)return;let o=null;for(const t of s)if(ps(t)&&t.shapes&&t.shapes[r.id]){o=t.shapes[r.id];break}o&&(this._hoveredFeature={source:r.source,layer:r.layer,id:r.id,shape:o,arcs:a,geometryType:r.geometryType,allLayers:s},this._findNearestVertices(o,a,t,e),this._hoverVertexCoords||this._findInterpolatedPoint(o,a,t,e),this._findNeighborShapes(a),this._updateEditState(),this._map.render())}_findNearestVertices(t,e,n,r){const i=this._map.unproject(n,r),s=ki().findNearestVertices(i,t,e);if(!s||0===s.length)return this._hoverVertexCoords=null,void(this._hoverVertexIds=[]);const a=e.getVertex2(s[0]);if(!a)return this._hoverVertexCoords=null,void(this._hoverVertexIds=[]);const o=this._map.project(a[0],a[1]);Math.sqrt((o[0]-n)*(o[0]-n)+(o[1]-r)*(o[1]-r))<=10?(this._hoverVertexCoords=[a[0],a[1]],this._hoverVertexIds=s,this._hoverType="vertex",this._hoverInsertionId=-1):(this._hoverVertexCoords=null,this._hoverVertexIds=[],this._hoverType=null,this._hoverInsertionId=-1)}_findInterpolatedPoint(t,e,n,r){const i=this._map.unproject(n,r);let s=1/0,a=null;const o=ki();if(o.forEachSegmentInShape(t,e,(t,e,n,r)=>{const l=n[t],h=r[t],c=n[e],u=r[e],p=o.findClosestPointOnSeg(i[0],i[1],l,h,c,u,0),_=p[0]-i[0],d=p[1]-i[1],f=Math.sqrt(_*_+d*d);f<s&&(s=f,a={insertionId:(t<e?t:e)+1,point:[p[0],p[1]]})}),!a)return;const l=a,h=this._map.project(l.point[0],l.point[1]);Math.sqrt((h[0]-n)*(h[0]-n)+(h[1]-r)*(h[1]-r))<=10&&(this._hoverVertexCoords=l.point,this._hoverVertexIds=[],this._hoverType="interpolated",this._hoverInsertionId=l.insertionId)}_findNeighborShapes(t){if(this._neighborShapes=[],!this._hoveredFeature||"polygon"!==this._hoveredFeature.geometryType)return;const{ii:e}=t.getVertexData(),n=this._hoveredFeature.id,r=new Set;if(this._hoverVertexIds.length>0)for(const t of this._hoverVertexIds)r.add(ki().findArcIdFromVertexId(t,e));else"interpolated"===this._hoverType&&this._hoverInsertionId>0&&r.add(ki().findArcIdFromVertexId(this._hoverInsertionId-1,e));if(0===r.size)return;const i=[];for(const t of this._hoveredFeature.allLayers)if(t.shapes)for(let e=0;e<t.shapes.length;e++){if(e===n)continue;const s=t.shapes[e];if(!s)continue;let a=!1;for(const t of s){for(const e of t){const t=e>=0?e:~e;if(r.has(t)){a=!0;break}}if(a)break}a&&i.push(s)}this._neighborShapes=i}_updateEditState(){if(!this._hoveredFeature)return;const t=this._hoveredFeature.geometryType,e=this._neighborShapes.length>0?[this._hoveredFeature.shape,...this._neighborShapes]:[this._hoveredFeature.shape];this._map.setEditVertexState({shapes:e,arcs:this._hoveredFeature.arcs,hoverVertex:this._hoverVertexCoords,hoverType:this._hoverType,geometryType:t,polygonFill:"polygon"===t?this._polygonFillColor:null,neighborShapes:this._neighborShapes.length>0?this._neighborShapes:void 0})}_onMouseDown(t,e){if(this._hoverVertexCoords&&this._hoveredFeature){if("interpolated"===this._hoverType&&this._hoverInsertionId>=0){const t=this._hoveredFeature.arcs,e=[this._hoverVertexCoords[0],this._hoverVertexCoords[1]];ki().insertVertex(t,this._hoverInsertionId,e),this._hoverVertexIds=[this._hoverInsertionId],this._hoverType="vertex",this._bumpSourceEditVersion(this._hoveredFeature.source),this._pushVertexInsertCommand(this._hoverInsertionId,e)}this._dragFromCoords=this._hoverVertexCoords?[this._hoverVertexCoords[0],this._hoverVertexCoords[1]]:null,this._dragging=!0}}_pushVertexInsertCommand(t,e){if(!this._hoveredFeature)return;const n=this._map.getSource(this._hoveredFeature.source);n&&this._map.pushCommand(new Oo({insertionId:t,point:e,arcs:this._hoveredFeature.arcs,source:n}))}_handleDrag(t,e){if(!this._hoveredFeature||0===this._hoverVertexIds.length)return;const n=this._resolveDragCoords(t,e),r=this._hoveredFeature.arcs;ki().snapVertices(this._hoverVertexIds,[n[0],n[1]],r),this._hoverVertexCoords=[n[0],n[1]],this._updateEditState(),this._map.render()}_resolveDragCoords(t,e){return this._findDragSnapTarget(t,e)??this._map.unproject(t,e)}_findDragSnapTarget(t,e){if(!this._hoveredFeature||!this._snapToVertex&&!this._snapToEdge)return null;const n=this._map.getSource?.(this._hoveredFeature.source),r=n?.getLayers?.(),i=n?.getArcs?.();if(!r||!i)return null;const s=ki(),a=this._map.unproject(t,e),o=new Set(this._hoverVertexIds);let l=this._snapThreshold,h=null;const c=new Set,u=(n,r,i)=>{if(!this._snapToVertex||o.has(n)||c.has(n))return;c.add(n);const s=this._map.project(r[n],i[n]),a=Math.hypot(s[0]-t,s[1]-e);a<l&&(l=a,h=[r[n],i[n]])};for(let n=0;n<r.length;n++){const o=r[n];if(!ps(o)||!o.shapes)continue;const c=Pi(o,n);for(let n=0;n<o.shapes.length;n++){if(c===this._hoveredFeature.layer&&n===this._hoveredFeature.id)continue;const r=o.shapes[n];r&&s.forEachSegmentInShape(r,i,(n,r,i,o)=>{if(u(n,i,o),u(r,i,o),!this._snapToEdge)return;const c=s.findClosestPointOnSeg(a[0],a[1],i[n],o[n],i[r],o[r],0),p=this._map.project(c[0],c[1]),_=Math.hypot(p[0]-t,p[1]-e);_<l&&(l=_,h=[c[0],c[1]])})}}return h}_finishDrag(t,e){if(!this._dragging||!this._hoveredFeature)return;this._dragging=!1;const n=this._resolveDragCoords(t,e),r=this._hoveredFeature.source;this._hoverVertexIds.length>0&&(ki().snapVertices(this._hoverVertexIds,[n[0],n[1]],this._hoveredFeature.arcs),this._hoverVertexCoords=[n[0],n[1]]);const i=this._hoveredFeature.arcs;i.transformPoints&&i.transformPoints(function(){}),this._refreshSourceDisplayArcs(r),this._bumpSourceEditVersion(r);const s=this._dragFromCoords;if(s&&(s[0]!==n[0]||s[1]!==n[1])&&this._hoverVertexIds.length>0){const t=this._map.getSource(r);t&&this._map.pushCommand(new Go({vertexIds:[...this._hoverVertexIds],from:[s[0],s[1]],to:[n[0],n[1]],arcs:i,source:t}))}this._dragFromCoords=null,this._map.fire("vertex_moved",{id:this._hoveredFeature.id,source:r,layer:this._hoveredFeature.layer,vertexIndex:this._hoverVertexIds[0]??null,vertexIds:this._hoverVertexIds,coords:n}),this._map.render()}}class qo{opts;label;constructor(t){this.opts=t,this.label=`Draw ${t.geometryType}`}do(){const t=this.opts,e=t.adapter??ki();if("point"!==t.geometryType){if(!t.arcs||!t.arcVertices)throw new Error("FeatureCreateCommand: path features require arcs and arcVertices");e.appendEmptyArc(t.arcs);for(const n of t.arcVertices)e.appendVertex(t.arcs,n)}if(t.layer.shapes||(t.layer.shapes=[]),t.layer.shapes.push(t.appendedShape),null!==t.appendedRecord){const e=t.layer.data?.getRecords?.();e?.push(t.appendedRecord)}t.source.markDisplayArcsDirty?.(),ds(t.source.getDataset?.())}undo(){const t=this.opts,e=t.adapter??ki();if(t.layer.shapes?.pop(),null!==t.appendedRecord){const e=t.layer.data?.getRecords?.();e?.pop()}"point"!==t.geometryType&&t.arcs&&e.deleteLastArc(t.arcs),t.source.markDisplayArcsDirty?.(),ds(t.source.getDataset?.())}}class jo{name="drawFeature";_map;_enabled=!1;_opts;_manager;_vertices=[];_cursorCoord=null;_snapCoord=null;_snapKind=null;_snapThreshold;_onMapMoveBound=()=>this._onMapMove();_onKeyDownBound=t=>this._onKeyDown(t);constructor(t,e){this._map=t,this._opts={...e??{}},this._snapThreshold=this._opts.snapThreshold??10,this._map.on("editmodechange",t=>{"draw"!==t.mode&&this._enabled&&this._quietDisable()})}isEnabled(){return this._enabled}setOptions(t){this._opts={...this._opts,...t},void 0!==t.snapThreshold&&(this._snapThreshold=t.snapThreshold)}getCursor(){return this._enabled?"crosshair":null}getOptions(){return{...this._opts}}enable(){if(!this._enabled){if(!this._opts.source||!this._opts.type)throw new Error("drawFeature: source+type required; call setOptions({source,type}) first");this._enabled=!0,this._map.setEditMode("draw"),window.addEventListener("keydown",this._onKeyDownBound),this._map.on("move",this._onMapMoveBound),this._manager?.refreshCursor()}}disable(){this._enabled&&(this._enabled=!1,this._clearDrawState(),window.removeEventListener("keydown",this._onKeyDownBound),this._map.off("move",this._onMapMoveBound),this._map.setEditMode("none"),this._map.clearEditDrawState(),this._manager?.refreshCursor(),this._map.render())}_quietDisable(){this._enabled=!1,window.removeEventListener("keydown",this._onKeyDownBound),this._map.off("move",this._onMapMoveBound),this._map.clearEditDrawState(),this._manager?.refreshCursor(),this._map.render()}handlePointer(t){if(!this._enabled)return"passthrough";const e=t.point.x,n=t.point.y;return"move"===t.kind?(this._onMouseMove(e,n),"passthrough"):"click"===t.kind?0!==t.button?"passthrough":(this._onClick(e,n),"consumed"):"dblclick"===t.kind?(this._onDblClick(t.originalEvent),"consumed"):"passthrough"}_onMapMove(){this._vertices.length>0&&(this._updateDrawState(),this._map.render())}_onMouseMove(t,e){const n=this._map.unproject(t,e);this._cursorCoord=[n[0],n[1]];const r=null!==this._snapCoord,i=this._findSnapTarget(t,e);this._snapCoord=i?.coord??null,this._snapKind=i?.kind??null,(this._vertices.length>0||this._snapCoord||r)&&(this._updateDrawState(),this._map.render())}_onClick(t,e){const n=this._snapCoord?[this._snapCoord[0],this._snapCoord[1]]:this._map.unproject(t,e);if("point"===this._opts.type)return this._vertices=[n],void this._commitFeature();if("polygon"===this._opts.type&&this._vertices.length>=3){const n=this._vertices[0],r=this._map.project(n[0],n[1]);if(Math.hypot(r[0]-t,r[1]-e)<=12)return void this._commitFeature()}this._vertices.push(n),this._updateDrawState(),this._map.render()}_onDblClick(t){t.preventDefault(),t.stopPropagation(),"point"!==this._opts.type&&("polyline"===this._opts.type&&this._vertices.length>=2||"polygon"===this._opts.type&&this._vertices.length>=3)&&this._commitFeature()}_onKeyDown(t){"Escape"===t.key&&(this._clearDrawState(),this._map.clearEditDrawState(),this._map.render())}_findSnapTarget(t,e){const n=this._map,r=this._opts.snapSources??[this._opts.source],i=!1!==this._opts.snapToVertex,s=!1!==this._opts.snapToEdge;let a=this._snapThreshold,o=null,l=null;const h=this._snapThreshold,c=n.unproject(t-h,e-h),u=n.unproject(t+h,e+h),p=Math.min(c[0],u[0]),_=Math.max(c[0],u[0]),d=Math.min(c[1],u[1]),f=Math.max(c[1],u[1]);for(const h of r){const r=n.getSource(h);if(!r)continue;const c=r.getArcs();if(!c?.getVertexData)continue;const u=c.getVertexData();if(!u)continue;const m=u.xx,g=u.yy;if(i)for(let r=0;r<m.length;r++){const i=m[r],s=g[r];if(i<p||i>_||s<d||s>f)continue;const h=n.project(i,s),c=Math.hypot(h[0]-t,h[1]-e);c<a&&(a=c,o=[i,s],l="vertex")}s&&c.forEachSegment&&c.forEachSegment((r,i,s,h)=>{const c=s[r],u=h[r],m=s[i],g=h[i];if((c<m?m:c)<p||(c<m?c:m)>_||(u<g?g:u)<d||(u<g?u:g)>f)return;const y=n.project(c,u),v=n.project(m,g),w=zo([t,e],y,v);w.dist<a&&(a=w.dist,o=n.unproject(w.point[0],w.point[1]),l="edge")})}if(i)for(const r of this._vertices){const i=n.project(r[0],r[1]),s=Math.hypot(i[0]-t,i[1]-e);s<a&&(a=s,o=[r[0],r[1]],l="vertex")}return o?{coord:o,kind:l}:null}_commitFeature(){if(0===this._vertices.length)return;const t=this._map.getSource(this._opts.source);if(!t)return;const e=t.getDataset();if(!e)return;const n=this._resolveTargetLayer(e.layers);if(!n)return;const r=e.layers.indexOf(n);let i,s,a;if(n.shapes||(n.shapes=[]),"point"===this._opts.type)i=[this._vertices[0]],n.shapes.push(i);else{if(s="polygon"===this._opts.type?[...this._vertices,this._vertices[0]]:[...this._vertices],a=e.arcs,!a)return;i=[[this._appendArc(a,s)]],n.shapes.push(i)}let o=null;if(n.data){const t=n.data.getRecords?.();t&&(o={},t.push(o))}t.refreshDisplayArcs(),this._map.pushCommand(new qo({geometryType:this._opts.type,layer:n,source:t,appendedShape:i,appendedRecord:o,arcVertices:s,arcs:a}));const l=n.shapes.length-1,h=Pi(n,r>=0?r:0);this._map.fire("feature_created",{id:l,source:this._opts.source,layer:h,geometryType:this._opts.type,properties:{}}),this._clearDrawState(),this._map.clearEditDrawState(),t.fire("data",{reason:"edit"})}_resolveTargetLayer(t){if(!t.length)return null;if(this._opts.sourceLayer)for(let e=0;e<t.length;e++){if(Pi(t[e],e)===this._opts.sourceLayer)return t[e]}const e="polygon"===this._opts.type?"polygon":"polyline"===this._opts.type?"polyline":"point";for(const n of t)if(n.geometry_type===e)return n;return t[0]}_appendArc(t,e){const n=t.getVertexData(),r=n.xx,i=n.yy,s=n.nn,a=n.zz,o=r.length,l=s.length,h=e.length,c=new Float64Array(o+h),u=new Float64Array(o+h),p=new Int32Array(l+1);c.set(r),u.set(i),p.set(s);for(let t=0;t<h;t++)c[o+t]=e[t][0],u[o+t]=e[t][1];p[l]=h;let _=null;if(a){_=new Float64Array(o+h),_.set(a);for(let t=0;t<h;t++)_[o+t]=1/0}return t.updateVertexData(p,c,u,_),l}_updateDrawState(){this._map.setEditDrawState({vertices:[...this._vertices],cursorCoord:this._snapCoord||this._cursorCoord,snapCoord:this._snapCoord,snapKind:this._snapKind,geometryType:this._opts.type,drawColor:this._opts.drawColor||"#0078ff"})}_clearDrawState(){this._vertices=[],this._cursorCoord=null,this._snapCoord=null,this._snapKind=null}}function zo(t,e,n){const r=e[0],i=e[1],s=n[0],a=n[1],o=t[0],l=t[1],h=s-r,c=a-i,u=h*h+c*c;if(0===u){const t=o-r,e=l-i;return{point:[r,i],dist:Math.hypot(t,e)}}let p=((o-r)*h+(l-i)*c)/u;p<0?p=0:p>1&&(p=1);const _=r+p*h,d=i+p*c;return{point:[_,d],dist:Math.hypot(o-_,l-d)}}class Bo{_map;name="transformFeature";_enabled=!1;_opts={};_translate=null;_affine=null;_lastMap=null;_hoveringSelected=!1;_manager;_prevAngle=0;_prevDist=1;_onKeyDownBound=t=>this._onKeyDown(t);constructor(t){this._map=t,this._map.on("editmodechange",t=>{"transform"!==t.mode&&this._enabled&&this._quietDisable()})}get _mode(){return this._opts.mode??"translate"}enable(){this._enabled||(this._enabled=!0,this._map.setEditMode("transform"),window.addEventListener("keydown",this._onKeyDownBound),this._manager?.refreshCursor())}disable(){this._enabled&&(this._enabled=!1,this._cancelSession(),this._hoveringSelected=!1,window.removeEventListener("keydown",this._onKeyDownBound),this._map.setEditMode("none"),this._manager?.refreshCursor(),this._map.render())}_quietDisable(){this._enabled=!1,this._cancelSession(),this._hoveringSelected=!1,window.removeEventListener("keydown",this._onKeyDownBound),this._manager?.refreshCursor(),this._map.render()}isEnabled(){return this._enabled}setOptions(t){this._opts={...this._opts,...t}}getOptions(){return this._opts}getCursor(){return this._enabled&&(this._translate||"translate"===this._mode&&this._hoveringSelected)?"move":null}_cancelSession(){this._translate&&(this._translate.cancel(),this._translate=null),this._affine&&(this._affine.cancel(),this._affine=null),this._lastMap=null}_onKeyDown(t){"Escape"===t.key&&(this._translate||this._affine)&&this._cancelSession()}handlePointer(t){if(!this._enabled)return"passthrough";if("down"===t.kind){if(0!==t.button)return"passthrough";const e=this._map.queryFeatures([t.point.x,t.point.y]);if("translate"===this._mode&&(this._hoveringSelected=e.length>0),!e.length||!this._map.isSelected(e[0]))return"passthrough";const n=this._map.unproject(t.point.x,t.point.y);if("translate"===this._mode){if(this._translate=this._map.editSession.beginTranslateSession(this._opts.session),!this._translate)return"passthrough";this._lastMap=n}else{if(this._affine=this._map.editSession.beginAffineSession(void 0,this._opts.session),!this._affine)return"passthrough";const[t,e]=this._affine.origin;this._prevAngle=Math.atan2(n[1]-e,n[0]-t),this._prevDist=Math.hypot(n[0]-t,n[1]-e)||1}return"exclusive"}if("move"===t.kind){if(!this._translate&&!this._affine){const e=this._map.queryFeatures([t.point.x,t.point.y]);return this._hoveringSelected=e.some(t=>this._map.isSelected(t)),"passthrough"}const e=this._map.unproject(t.point.x,t.point.y);if(this._translate)this._lastMap&&this._translate.move(e[0]-this._lastMap[0],e[1]-this._lastMap[1]),this._lastMap=e;else if(this._affine){const[t,n]=this._affine.origin;if("rotate"===this._mode){const r=Math.atan2(e[1]-n,e[0]-t),i=r-this._prevAngle;0!==i&&this._affine.applyDelta(gs(i,t,n)),this._prevAngle=r}else{const r=Math.hypot(e[0]-t,e[1]-n)||1,i=r/this._prevDist;1!==i&&this._affine.applyDelta(ys(i,i,t,n)),this._prevDist=r}}return"exclusive"}return"up"===t.kind&&(this._translate||this._affine)?(this._translate&&(this._translate.commit(),this._translate=null),this._affine&&(this._affine.commit(),this._affine=null),this._lastMap=null,this._hoveringSelected=!1,"passthrough"):"passthrough"}}function Vo(t){if(!t||"object"!=typeof t)return!1;const e=t;return"string"==typeof e.name&&"function"==typeof e.enable&&"function"==typeof e.disable&&"function"==typeof e.isEnabled&&"function"==typeof e.setOptions&&"function"==typeof e.getOptions&&"function"==typeof e.handlePointer}const $o=["lassoSelect","boxSelect","clickSelect","transformFeature","drawFeature","vertexEdit","dragPan"];class Wo{_handlers=new Map;_element=null;_exclusive=null;_pointerSink=null;_onDown=t=>this._dispatch(this._norm(t,"down"));_onMove=t=>this._dispatch(this._norm(t,"move"));_onUp=t=>this._dispatch(this._norm(t,"up"));_onClick=t=>this._dispatch(this._norm(t,"click"));_onContextMenu=t=>this._dispatch(this._norm(t,"contextmenu"));_onDblClick=t=>this._dispatch(this._norm(t,"dblclick"));register(t){if(!Vo(t))throw new Error("HandlerManager.register: argument is not a valid Handler");this._handlers.set(t.name,t),t._manager=this}isEnabledByName(t){const e=this._handlers.get(t);return!!e&&e.isEnabled()}get(t){return this._handlers.get(t)}applyInteractive(t){for(const e of["dragPan","scrollZoom"]){const n=this._handlers.get(e);n&&(t?n.enable():n.disable())}}attach(t){this.detach(),this._element=t,t.addEventListener("pointerdown",this._onDown),window.addEventListener("pointermove",this._onMove),window.addEventListener("pointerup",this._onUp),t.addEventListener("click",this._onClick),t.addEventListener("contextmenu",this._onContextMenu),t.addEventListener("dblclick",this._onDblClick)}detach(){this._element&&(this._element.removeEventListener("pointerdown",this._onDown),window.removeEventListener("pointermove",this._onMove),window.removeEventListener("pointerup",this._onUp),this._element.removeEventListener("click",this._onClick),this._element.removeEventListener("contextmenu",this._onContextMenu),this._element.removeEventListener("dblclick",this._onDblClick),this._element.style.cursor="",this._element=null,this._exclusive=null,this._pointerSink=null)}setPointerSink(t){this._pointerSink=t}_norm(t,e){const n=this._element.getBoundingClientRect();return{kind:e,point:{x:t.clientX-n.left,y:t.clientY-n.top},modifiers:{shift:t.shiftKey,ctrl:t.ctrlKey,alt:t.altKey,meta:t.metaKey},button:"button"in t?t.button:0,originalEvent:t}}_orderedEnabled(){const t=[];for(const e of $o){const n=this._handlers.get(e);n&&n.isEnabled()&&t.push(n)}return t}_dispatch(t){this._dispatchInner(t),this._applyCursor()}_dispatchInner(t){if(this._pointerSink&&("click"===t.kind||"move"===t.kind&&!this._exclusive)&&this._pointerSink(t),this._exclusive&&("move"===t.kind||"up"===t.kind)){return void("exclusive"!==this._exclusive.handlePointer(t)&&(this._exclusive=null))}for(const e of this._orderedEnabled()){const n=e.handlePointer(t);if("exclusive"===n)return void(this._exclusive=e);if("consumed"===n)return}}_applyCursor(){if(!this._element)return;let t=null;const e=this._exclusive;if(e&&e.isEnabled()&&(t=e.getCursor?.()??null),!t)for(const e of this._orderedEnabled()){const n=e.getCursor?.();if(n){t=n;break}}const n=t??"";this._element.style.cursor!==n&&(this._element.style.cursor=n)}refreshCursor(){this._applyCursor()}}class Ho{_workerUrl;_WorkerCtor;_slots;_pending=new Map;_nextId=1;_rrCursor=0;_destroyed=!1;constructor(t){this._workerUrl=t.workerUrl,this._WorkerCtor=t.WorkerCtor??globalThis.Worker;const e=Math.max(1,Math.floor(t.poolSize??1));this._slots=Array.from({length:e},()=>({worker:null,epoch:0,pendingCount:0}))}run(t,e,n){return this.runWithId(t,e,n).promise}runWithId(t,e,n){const r=this.reserveId();return{id:r,promise:this.dispatchWithId(r,t,e,n)}}reserveId(){return this._nextId++}dispatchWithId(t,e,n,r,i){if(this._destroyed)return Promise.reject(new Error("MapshaperWorkerPool: destroyed"));const s=this._pickWorker();let a;try{a=this._ensureWorker(s)}catch(t){return Promise.reject(t)}const o=this._slots[s],l=o.epoch;return o.pendingCount++,new Promise((o,h)=>{this._pending.set(t,{resolve:o,reject:h,workerIndex:s,epoch:l});const c={id:t,type:"run",packed:n};"string"==typeof e?c.cmd=e:c.commands=e,r&&(c.inputFiles=r),i&&i.length>0?a.postMessage(c,i):a.postMessage(c)})}destroy(){this._destroyed||(this._destroyed=!0,this._terminateAll(new Error("MapshaperWorkerPool: destroyed")))}cancelAll(){this._destroyed||this._terminateAll(new Error("MapshaperWorkerPool: cancelled"))}isWorkerSpawned(){return this._slots.some(t=>null!==t.worker)}get poolSize(){return this._slots.length}_pickWorker(){let t=0,e=1/0,n=!1;const r=this._slots.length;for(let i=0;i<r;i++){const s=(this._rrCursor+i)%r,a=this._slots[s],o=null!==a.worker;(a.pendingCount<e||a.pendingCount===e&&o&&!n)&&(t=s,e=a.pendingCount,n=o)}return this._rrCursor=(t+1)%r,t}_terminateAll(t){for(const t of this._slots)t.worker&&(t.worker.terminate(),t.worker=null),t.epoch++,t.pendingCount=0;for(const{reject:e}of this._pending.values())e(t);this._pending.clear()}_ensureWorker(t){const e=this._slots[t];if(e.worker)return e.worker;if(!this._WorkerCtor)throw new Error("MapshaperWorkerPool: Worker constructor not available in this environment");const n=new this._WorkerCtor(this._workerUrl);return n.onmessage=e=>this._onMessage(t,e.data),n.onerror=e=>this._onWorkerError(t,e),e.worker=n,n}_onMessage(t,e){if(!e||"number"!=typeof e.id)return;const n=this._pending.get(e.id);if(!n)return;const r=this._slots[t];n.workerIndex===t&&n.epoch===r.epoch&&(this._pending.delete(e.id),r.pendingCount=Math.max(0,r.pendingCount-1),"ok"===e.type?n.resolve(e.packed):n.reject(new Error(e.message||"mapshaper worker error")))}_onWorkerError(t,e){const n=new Error(`mapshaper worker error: ${e.message||"unknown"}`),r=this._slots[t];r.worker&&(r.worker.terminate(),r.worker=null),r.epoch++,r.pendingCount=0;const i=[];for(const[e,n]of this._pending)n.workerIndex===t&&i.push(e);for(const t of i){const e=this._pending.get(t);this._pending.delete(t),e?.reject(n)}}}const Ko=["feature:click","feature:hover","feature:enter","feature:leave"];function Zo(t){return Ko.includes(t)}function Jo(t,e){return!t||(!t.source||t.source===e.source)&&!(t.layers&&!t.layers.includes(e.layer))}class Xo{_host;_reg={"feature:click":[],"feature:hover":[],"feature:enter":[],"feature:leave":[]};_lastKey=null;_lastRef=null;_onceWrap=new Map;_onChange;constructor(t){this._host=t}setOnChange(t){this._onChange=t}hasListeners(){return Ko.some(t=>this._reg[t].length>0)}on(t,e,n){Zo(t)&&(this._reg[t].push({filter:e,cb:n}),this._onChange?.())}once(t,e,n){if(!Zo(t))return;const r=e=>{this.off(t,n),n(e)};this._onceWrap.set(n,r),this._reg[t].push({filter:e,cb:r}),this._onChange?.()}off(t,e){if(!Zo(t))return;const n=this._onceWrap.get(e);this._reg[t]=this._reg[t].filter(t=>t.cb!==e&&(void 0===n||t.cb!==n)),this._onceWrap.delete(e),this._onChange?.()}_hit(t,e){let n=[];for(const t of Ko){for(const e of this._reg[t]){if(!e.filter?.layers){n=void 0;break}n.push(...e.filter.layers)}if(void 0===n)break}const r=this._host.queryFeatures([t,e],n&&n.length?{layers:n}:void 0);if(0===r.length)return null;const i=r[0];return{source:i.source,layer:i.layer,id:i.id}}_emit(t,e,n){const r=this._reg[t];if(0===r.length)return;let i=null;for(const s of r)if(Jo(s.filter,e)){if(!i){const r=this._host.features.get(e);if(!r)return;i={type:t,feature:r,ref:e,point:{x:n.point.x,y:n.point.y},lngLat:this._host.unproject(n.point.x,n.point.y),modifiers:{...n.modifiers},originalEvent:n.originalEvent}}s.cb(i)}}dispatch(t){if(!this.hasListeners())return;if("click"===t.kind){const e=this._hit(t.point.x,t.point.y);return void(e&&this._emit("feature:click",e,t))}if("move"!==t.kind)return;const e=this._hit(t.point.x,t.point.y),n=e?`${(r=e).source}|${r.layer}|${r.id}`:null;var r;n!==this._lastKey&&(this._lastRef&&this._emit("feature:leave",this._lastRef,t),e&&this._emit("feature:enter",e,t),this._lastKey=n,this._lastRef=e),e&&this._emit("feature:hover",e,t)}}const Yo=["mousemove"];function Qo(t){return Yo.includes(t)}class tl{_host;_reg={mousemove:[]};_onceWrap=new Map;_onChange;constructor(t){this._host=t}setOnChange(t){this._onChange=t}hasListeners(){return Yo.some(t=>this._reg[t].length>0)}on(t,e){Qo(t)&&(this._reg[t].push(e),this._onChange?.())}once(t,e){if(!Qo(t))return;const n=n=>{this.off(t,e),e(n)};this._onceWrap.set(e,n),this._reg[t].push(n),this._onChange?.()}off(t,e){if(!Qo(t))return;const n=this._onceWrap.get(e);this._reg[t]=this._reg[t].filter(t=>t!==e&&(void 0===n||t!==n)),this._onceWrap.delete(e),this._onChange?.()}dispatch(t){if(!this.hasListeners())return;if("move"!==t.kind)return;const e=this._reg.mousemove,n={point:{x:t.point.x,y:t.point.y},mapCoord:this._host.unproject(t.point.x,t.point.y),originalEvent:t.originalEvent};for(const t of e.slice())t(n)}}class el{_sources;_getTransform;_getSize;_getInitialMX;_indexCache=new globalThis.Map;constructor(t,e,n,r){this._sources=t,this._getTransform=e,this._getSize=n,this._getInitialMX=r}prebuild(t){if(void 0!==t){const e=this._sources.get(t);return void(e&&this._prebuildSource(t,e))}for(const[t,e]of this._sources)this._prebuildSource(t,e)}clear(t){if(void 0===t)return void this._indexCache.clear();const e=`${t}|`,n=[];for(const t of this._indexCache.keys())t.startsWith(e)&&n.push(t);for(const t of n)this._indexCache.delete(t)}_prebuildSource(t,e){if("topology"!==e.type)return;const n=e.getLayers(),r=e.getArcs(),i=e.getDataset?.();for(let e=0;e<n.length;e++)this._getOrBuildIndex(t,e,n[e],r,i)}_getOrBuildIndex(t,e,n,r,i){const s=n?.shapes;if(!s||0===s.length)return null;const a=r?.size?.()??0,o=i?.editVersion??0,l=`${t}|${e}|${s.length}|${a}|${o}`,h=this._indexCache.get(l);if(void 0!==h)return h;const c=`${t}|${e}|`,u=[];for(const t of this._indexCache.keys())t!==l&&t.startsWith(c)&&u.push(t);for(const t of u)this._indexCache.delete(t);const p="point"===n.geometry_type,_=new Zr(s.length),d=[];for(let t=0;t<s.length;t++){const e=s[t];if(!e){_.add(0,0,0,0);continue}let n=1/0,i=1/0,a=-1/0,o=-1/0;if(p)for(const t of Ni(e))!t||t.length<2||(t[0]<n&&(n=t[0]),t[0]>a&&(a=t[0]),t[1]<i&&(i=t[1]),t[1]>o&&(o=t[1]));else if(r?.getSimpleShapeBbox){const t=e;for(let e=0;e<t.length;e++)r.getSimpleShapeBbox(t[e],d),d[0]<n&&(n=d[0]),d[1]<i&&(i=d[1]),d[2]>a&&(a=d[2]),d[3]>o&&(o=d[3])}n!==1/0?_.add(n,i,a,o):_.add(0,0,0,0)}_.finish();const f={index:_,shapeCount:s.length};return this._indexCache.set(l,f),f}query(t,e,n){const{width:r,height:i}=this._getSize(),s=Array.isArray(t),a=s?t:[[0,0],[r,i]],o=e||(s?{}:t)||{};if(Array.isArray(a)&&"number"==typeof a[0]){const t=a;return this._queryFeaturesAtPoint(t,o,n)}const l=a;return this._queryFeaturesInBBox(l,o,n)}_layerMatchesFilter(t,e,n){if(!n||0===n.length)return!0;const r=Pi(t,e);return!!n.includes(r)||(!(!t?.name||!n.includes(t.name))||!(!t?.id||!n.includes(t.id)))}_unproject(t,e){return this._getTransform().unproject(t,e)}_getHitBuffer(t){return t/Math.abs(this._getTransform().mx||1)}_getZoomAdjustedHitBuffer(t,e){const n=this._getTransform(),r=this._getInitialMX(),i=Math.abs(n.mx)/(r||Math.abs(n.mx)||1);return i<1&&(t*=i),e>0&&t<e&&(t=e),this._getHitBuffer(t)}_findHitCandidates(t,e,n,r,i,s,a,o){const l=[],h={},c=[],u=n.shapes;if(!u)return l;const p=this._getOrBuildIndex(t,e,n,r,o),_=p?p.index.search(i-a,s-a,i+a,s+a):null,d=null!==_?_.length:u.length;for(let t=0;t<d;t++){const e=null!==_?_[t]:t,n=u[e];if(n)for(let t=0;t<n.length;t++){const o=n[t];if(r.getSimpleShapeBbox(o,c),i+a<c[0]||i-a>c[2]||s+a<c[1]||s-a>c[3])continue;let u=h[e];u||(u=h[e]={shape:[],id:e,dist:0},l.push(u)),u.shape.push(o)}}return l}_sortByDistance(e,n,r,i){const s=t.geom;for(const t of r)t.info=s.getPointToShapeInfo(e,n,t.shape,i),t.dist=t.info.distance;r.sort((t,e)=>t.dist-e.dist)}_pickNearestCandidates(t,e,n){const r=[];let i=0;for(let s=0;s<t.length;s++){const a=t[s];if(!(a.dist<n))break;if(0===s)i=a.dist;else if(a.dist-i>e)break;r.push(a)}return r}_pointTest(e,n,r,i,s,a){const o=t.geom,l=Math.abs(this._getTransform().mx||1);let h=-1,c=1/0,u=25;const p=r.shapes;if(!p)return[];const _=u/(l||1),d=this._getOrBuildIndex(e,n,r,void 0,a),f=d?d.index.search(i-_,s-_,i+_,s+_):null,m=null!==f?f.length:p.length;for(let t=0;t<m;t++){const e=null!==f?f[t]:t,n=p[e];if(n)for(const t of Ni(n)){if(!t)continue;const n=o.distance2D(i,s,t[0],t[1])*l;n>u||(n<u&&u>2&&(u=Math.max(2,n)),n<c&&(c=n,h=e))}}return-1===h?[]:[h]}_polylineTest(t,e,n,r,i,s,a,o){const l=this._getZoomAdjustedHitBuffer(15,2),h=a>=0?a:.05,c=this._getZoomAdjustedHitBuffer(h,0);let u=this._findHitCandidates(t,e,n,r,i,s,l,o);return this._sortByDistance(i,s,u,r),u=this._pickNearestCandidates(u,c,l),u.length?[u[0].id]:[]}_polygonTest(e,n,r,i,s,a,o){const l=t.geom,h=this._getZoomAdjustedHitBuffer(10,1),c=this._findHitCandidates(e,n,r,i,s,a,h,o);let u=[];for(const t of c)l.testPointInPolygon(s,a,t.shape,i)&&u.push(t);return c.length>0&&0===u.length?(this._sortByDistance(s,a,c,i),u=this._pickNearestCandidates(c,0,h)):u.length>1&&this._sortByDistance(s,a,u,i),u.length?[u[0].id]:[]}_polygonVertexTest(t,e,n,r,i,s,a){const o=this._polygonTest(t,e,n,r,i,s,a),l=this._polylineTest(t,e,n,r,i,s,5,a);return o.length?o:l}_queryFeaturesAtPoint(t,e,n){const r=this._getTransform(),i=[],[s,a]=this._unproject(t[0],t[1]),o=1/Math.abs(r.mx||1);for(const[t,r]of this._sources){const l=r.getLayers(),h=r.getDisplayArcs(),c=h?h.getScaledArcs(o):r.getArcs(),u=r.getDataset?.();for(let r=0;r<l.length;r++){const o=l[r];if(!o?.shapes)continue;if(!this._layerMatchesFilter(o,r,e.layers))continue;const h=Pi(o,r);if(n&&!n.has(`${t}:${h}`))continue;const p=o.geometry_type;let _=[];if("point"===p?_=this._pointTest(t,r,o,s,a,u):"polyline"===p&&c?_=this._polylineTest(t,r,o,c,s,a,-1,u):"polygon"===p&&c&&(_=this._polygonVertexTest(t,r,o,c,s,a,u)),0!==_.length)for(const e of _){const n=o.data,r=n?.getRecordAt?.(e)??n?.getRecords?.()?.[e]??{};i.push({id:e,source:t,layer:h,geometryType:p||"unknown",properties:{...r}})}}}return i}_queryFeaturesInBBox(t,e,n){const r=this._getTransform(),i=[],[s,a]=t,o=this._unproject(s[0],s[1]),l=this._unproject(a[0],a[1]),h=Math.min(o[0],l[0]),c=Math.min(o[1],l[1]),u=Math.max(o[0],l[0]),p=Math.max(o[1],l[1]),_=1/Math.abs(r.mx||1);for(const[t,r]of this._sources){const s=r.getLayers(),a=r.getDisplayArcs(),o=a?a.getScaledArcs(_):r.getArcs(),l=r.getDataset?.();for(let r=0;r<s.length;r++){const a=s[r];if(!a?.shapes)continue;if(!this._layerMatchesFilter(a,r,e.layers))continue;const _=Pi(a,r);if(n&&!n.has(`${t}:${_}`))continue;const d=a.geometry_type,f=a.data,m=[],g=this._getOrBuildIndex(t,r,a,o,l),y=g?g.index.search(h,c,u,p):null,v=null!==y?y.length:a.shapes.length;for(let e=0;e<v;e++){const n=null!==y?y[e]:e,r=a.shapes[n];if(!r)continue;let s=!1;if("point"===d)s=Ni(r).some(t=>t[0]>=h&&t[0]<=u&&t[1]>=c&&t[1]<=p);else if(o){const t=r;for(let e=0;e<t.length;e++)if(o.getSimpleShapeBbox(t[e],m),!(u<m[0]||h>m[2]||p<m[1]||c>m[3])){s=!0;break}}if(!s)continue;const l=f?.getRecordAt?.(n)??f?.getRecords?.()?.[n]??{};i.push({id:n,source:t,layer:_,geometryType:d||"unknown",properties:{...l}})}}}return i}}class nl{_host;constructor(t){this._host=t}get(t){const e=this._host.layers.resolve(t.source,t.layer);if(!e)return null;if(!Number.isInteger(t.id)||t.id<0)return null;const n=e.shapes??null;if(!n||t.id>=n.length)return null;const r=n[t.id],i=e.data?.getRecords?.()??[];return{ref:t,geometry:r,properties:Object.freeze({...i[t.id]??{}})}}*iter(t,e){const n=this._host.layers.resolve(t,e);if(!n||!n.shapes)return;const r=n.shapes,i=n.data?.getRecords?.()??[];for(let n=0;n<r.length;n++)yield{ref:{source:t,layer:e,id:n},geometry:r[n],properties:Object.freeze({...i[n]??{}})}}count(t,e){const n=this._host.layers.resolve(t,e);return n?.shapes?.length??0}}class rl{_all=new globalThis.Set;get size(){return this._all.size}register(t){return this._all.add(t),()=>{this._all.delete(t)}}unregisterAll(){this._all.clear()}async runFor(t,e,n){if(0===this._all.size)return[];const r=[];for(const e of this._all)e.phase===t&&r.push(e);if(0===r.length)return[];const i=await Promise.allSettled(r.map(t=>t.run(e,n))),s=[];for(let t=0;t<r.length;t++){const e=r[t],n=i[t];let a;a="fulfilled"===n.status?n.value:{ok:!1,issues:[{severity:"error",message:`validator '${e.name}' threw: ${n.reason instanceof Error?n.reason.message:String(n.reason)}`}]},s.push({validator:e.name,report:a})}return s}}class il{_highlighted=new globalThis.Map;_highlightStyle={color:"#ff7a00",width:2.2,radius:6,fill:!0};get size(){return this._highlighted.size}setHighlightedFeatures(t,e){this._highlighted.clear(),e&&(this._highlightStyle={...this._highlightStyle,...e});for(const e of t){const t=this._highlighted.get(e.source)||new globalThis.Map,n=t.get(e.layer)||new Set;n.add(e.id),t.set(e.layer,n),this._highlighted.set(e.source,t)}}clearHighlightedFeatures(){return 0!==this._highlighted.size&&(this._highlighted.clear(),!0)}setHighlightStyle(t){return this._highlightStyle={...this._highlightStyle,...t},this._highlighted.size>0}renderHighlights(t,e,n,r,i){if(0===this._highlighted.size)return;const s=this._highlightStyle.color||"#ff7a00",a=(this._highlightStyle.width??2.2)*r,o=this._highlightStyle.radius??6,l=!1!==this._highlightStyle.fill,h=1/Math.abs(n.mx||1);for(const[n,r]of e){const e=this._highlighted.get(n);if(!e)continue;const c=r.getLayers(),u=r.getDisplayArcs(),p=u?u.getScaledArcs(h):r.getArcs();for(let r=0;r<c.length;r++){const h=c[r];if(!h?.shapes)continue;const u=Pi(h,r);if(i&&!i.has(`${n}:${u}`))continue;const _=e.get(u);if(!_||0===_.size)continue;const d=[];for(const t of _){const e=h.shapes[t];e&&d.push(e)}0!==d.length&&("point"===h.geometry_type?t.drawPoints(d,{color:s,radius:o,fill:l}):p&&t.drawPaths(d,{color:s,width:a},p))}}}}class sl{_byKey=new globalThis.Map;_size=0;get size(){return this._size}has(t){return this._byKey.get(t.source)?.get(t.layer)?.has(t.id)??!1}getAll(){const t=[];for(const[e,n]of this._byKey)for(const[r,i]of n)for(const n of i)t.push({source:e,layer:r,id:n});return t}getByLayer(t,e){const n=this._byKey.get(t)?.get(e);return n?Array.from(n):[]}clear(){if(0===this._size)return{added:[],removed:[],changed:!1};const t=this.getAll();return this._byKey.clear(),this._size=0,{added:[],removed:t,changed:!0}}apply(t,e){const n=hl(t);if("replace"===e){const t=this._refSetSnapshot();this._byKey.clear(),this._size=0;for(const t of n)this._addOne(t);return ll(t,this._refSetSnapshot())}const r=[],i=[];if("add"===e)for(const t of n)this._addOne(t)&&r.push(t);else for(const t of n)this.has(t)?this._removeOne(t)&&i.push(t):this._addOne(t)&&r.push(t);return{added:r,removed:i,changed:r.length>0||i.length>0}}remove(t){const e=[];for(const n of hl(t))this._removeOne(n)&&e.push(n);return{added:[],removed:e,changed:e.length>0}}snapshot(){return this._refSetSnapshot()}restore(t){const e=this._refSetSnapshot();this._byKey.clear(),this._size=0;for(const e of t)this._addOne(ol(e));return ll(e,t)}_addOne(t){let e=this._byKey.get(t.source);e||(e=new globalThis.Map,this._byKey.set(t.source,e));let n=e.get(t.layer);return n||(n=new Set,e.set(t.layer,n)),!n.has(t.id)&&(n.add(t.id),this._size++,!0)}_removeOne(t){const e=this._byKey.get(t.source),n=e?.get(t.layer);return!!n?.has(t.id)&&(n.delete(t.id),this._size--,0===n.size&&(e.delete(t.layer),0===e.size&&this._byKey.delete(t.source)),!0)}_refSetSnapshot(){const t=new Set;for(const[e,n]of this._byKey)for(const[r,i]of n)for(const n of i)t.add(al(e,r,n));return t}}function al(t,e,n){return JSON.stringify([t,e,n])}function ol(t){const[e,n,r]=JSON.parse(t);return{source:e,layer:n,id:r}}function ll(t,e){const n=[],r=[];for(const r of e)t.has(r)||n.push(ol(r));for(const n of t)e.has(n)||r.push(ol(n));return{added:n,removed:r,changed:n.length>0||r.length>0}}function hl(t){const e=new Set,n=[];for(const r of t){const t=al(r.source,r.layer,r.id);e.has(t)||(e.add(t),n.push(r))}return n}class cl{_undoStack=[];_redoStack=[];_maxSize;_lastSkippedStale=!1;_captureBuffer=null;constructor(t={}){if(this._maxSize=t.maxSize??200,this._maxSize<1)throw new Error("EditHistory: maxSize must be >= 1")}push(t){if(this._captureBuffer)return void this._captureBuffer.push(t);const e=this._undoStack[this._undoStack.length-1];if(e&&!e.stale&&e.merge&&t.mergeable?.(e))return e.merge(t),void(this._redoStack.length=0);if(t.invalidatesPriorCommands){for(const t of this._undoStack)t.stale=!0;this._redoStack.length=0}this._undoStack.push(t),this._redoStack.length=0,this._undoStack.length>this._maxSize&&this._undoStack.shift()}beginCapture(){if(this._captureBuffer)throw new Error("EditHistory: nested capture not supported");this._captureBuffer=[]}endCapture(){const t=this._captureBuffer;return this._captureBuffer=null,t??[]}isCapturing(){return null!==this._captureBuffer}undo(){const t=this._undoStack.pop();return t?(t.stale?this._lastSkippedStale=!0:(t.undo(),this._lastSkippedStale=!1),this._redoStack.push(t),t):null}redo(){const t=this._redoStack.pop();return t?(t.stale?this._lastSkippedStale=!0:(t.do(),this._lastSkippedStale=!1),this._undoStack.push(t),t):null}clear(){this._undoStack.length=0,this._redoStack.length=0,this._lastSkippedStale=!1}canUndo(){return this._undoStack.length>0}canRedo(){return this._redoStack.length>0}size(){return this._undoStack.length}snapshot(){const t=this._undoStack[this._undoStack.length-1];let e=0;for(const t of this._undoStack)t.stale&&e++;const n={canUndo:this._undoStack.length>0,canRedo:this._redoStack.length>0,label:t?.label,staleCount:e,topIsStale:!!t?.stale};return this._lastSkippedStale&&(n.skippedStale=!0),n}}class ul{_host;_datasetSnapshots=new globalThis.Map;_selectionSnapshot;_closed=!1;constructor(t){if(t._activeTransaction)throw new Error("Transaction: another transaction is already active");this._host=t,this._selectionSnapshot=t._selection.snapshot(),t._history.beginCapture(),t._activeTransaction=this}_captureFirstTouch(t,e){this._datasetSnapshots.has(t)||this._datasetSnapshots.set(t,e)}get isOpen(){return!this._closed}async commit(t){this._end();const e=this._host._history.endCapture();if(0===e.length)return Fi;const n=new us(e,t);return this._host._history.push(n),this._host._fireHistoryChange(),Fi}rollback(){this._end(),this._host._history.endCapture();for(const[t,e]of this._datasetSnapshots){const n=this._host._sources.get(t);n&&n.setDataset(e)}const t=this._host._selection.restore(this._selectionSnapshot);t.changed&&this._host._fireSelectionChange(t),this._host._fireHistoryChange(),this._host._scheduleRender()}_end(){if(this._closed)throw new Error("Transaction: already committed or rolled back");this._closed=!0,this._host._activeTransaction=null}}class pl{opts;label="Delete feature";constructor(t){this.opts=t}do(){const{layer:t,featureId:e}=this.opts;if(!t.shapes)return;t.shapes.splice(e,1);const n=t.data?.getRecords?.();n?.splice(e,1)}undo(){const{layer:t,featureId:e,shape:n,record:r}=this.opts;if(t.shapes||(t.shapes=[]),t.shapes.splice(e,0,n),null!==r){const n=t.data?.getRecords?.();n?.splice(e,0,r)}}}class _l{opts;label;constructor(t){this.opts=t,this.label=`Delete ${t.snapshots.length} feature${1===t.snapshots.length?"":"s"}`}do(){const{layer:t,snapshots:e}=this.opts;if(!t.shapes||0===e.length)return;const n=new Set;for(const t of e)n.add(t.id);const r=t.shapes,i=new Array(r.length-n.size);let s=0;for(let t=0;t<r.length;t++)n.has(t)||(i[s++]=r[t]);t.shapes=i;const a=t.data?.getRecords?.();if(a){let t=0;for(let e=0;e<a.length;e++)n.has(e)||(a[t++]=a[e]);a.length=t}}undo(){const{layer:t,snapshots:e}=this.opts;t.shapes||(t.shapes=[]);const n=[...e].sort((t,e)=>t.id-e.id),r=t.data?.getRecords?.();for(const e of n)t.shapes.splice(e.id,0,e.shape),r&&null!==e.record&&r.splice(e.id,0,e.record)}}function dl(t,e){const n=t||{};return{color:n["line-color"]||n["fill-color"]||"#333",width:(n["line-width"]??.8)*e}}function fl(t){const e=t||{};return{color:e["circle-color"]||"#333",radius:e["circle-radius"]??4,fill:!1!==e["circle-fill"]}}class ml extends mi{_container;_canvasContainer;_canvas;_painter;_editOverlay;_scheduler;_viewport=new xi;_projection=new Di;_camera;_sources=new globalThis.Map;_layersCache;get layers(){return this._layersCache??(this._layersCache=new ts(this._sources))}_sourceListeners=new globalThis.Map;_layers=[];_effectiveLayersCache=[];_defaultLayersDirty=!0;_layerArcFlagsCache=new globalThis.Map;_handlers;_featureEvents;_pointerEvents;_scrollZoom;_dragPan;_clickSelect;_boxSelect;_lassoSelect;_vertexEdit;_drawFeature;_transformFeature;_pendingRender=0;_rafId=0;_pendingAction="redraw";_pendingNavDelta=null;_navSnapshotTransform=null;_wheelSettleTimer=null;static _WHEEL_SETTLE_MS=250;_controlContainers=new globalThis.Map;_controls=[];_highlightManager=new il;_featureQuery;features;_selection=new sl;_history=new cl;_activeTransaction=null;_validators=new rl;get validators(){return this._validators}_historyShortcutUnbind=null;_ops;_editSession;_attributes;get ops(){return this._ops??(this._ops=new cs(this))}get editSession(){return this._editSession??(this._editSession=new As(this))}get attributes(){return this._attributes??(this._attributes=new Ns(this))}_editState=new Rs(t=>{if(t.modeChanged){"vertex"===t.current.mode||"draw"===t.current.mode?this._dragPan?.disable():this._dragPan?.enable(),this.fire("editmodechange",{mode:t.current.mode})}this._scheduleRender()});_workerPool=null;_workerMode=!1;_workerThreshold=5e4;_workerRouting;_expressionPolicy="disabled";constructor(t){if(super(),"string"==typeof t.container){const e=document.getElementById(t.container);if(!e)throw new Error(`Container #${t.container} not found`);this._container=e}else this._container=t.container;this._canvasContainer=this._createCanvasContainer(),this._container.appendChild(this._canvasContainer),this._canvas=document.createElement("canvas"),this._canvas.style.position="absolute",this._canvas.style.top="0",this._canvas.style.left="0",this._canvasContainer.appendChild(this._canvas),this._painter=new Ri(this._canvas),this._painter.setPixelRatio(window.devicePixelRatio||1),this._editOverlay=new Li(this._painter),this._scheduler=new Gi({fullRedraw:()=>this._renderFull(),fastNav:t=>this._applyFastTransform(t),getSnapshot:()=>this._captureRenderSnapshot()}),this._updateSize(),this._viewport.onViewChange=()=>this.fire("move"),this._viewport.initZoomTween(),this._camera=new Ci({getCameraState:()=>this._viewport.getCameraState(),applyCameraState:(t,e)=>this._viewport.applyCameraState(t,e),scaleFromZoom:t=>this._projection.getScale(t),getViewportSize:()=>({width:this._viewport.width,height:this._viewport.height}),fire:(t,e)=>this.fire(t,e),requestRender:()=>this._scheduleRender(),cancelZoomAnimation:()=>this._viewport.cancelZoomAnimation()}),this._handlers=new Wo,this._scrollZoom=new uo(this._canvasContainer,()=>this.stop()),this._dragPan=new _o(void 0,()=>this.stop(),t=>this.queryFeatures([t.x,t.y]).some(t=>this.isSelected(t))),this._handlers.register(this._dragPan),this._handlers.register(this._scrollZoom),this._clickSelect=new To(this),this._boxSelect=new Po(this),this._lassoSelect=new Lo(this),this._handlers.register(this._clickSelect),this._handlers.register(this._boxSelect),this._handlers.register(this._lassoSelect),this._vertexEdit=new Uo(this),this._handlers.register(this._vertexEdit),this._drawFeature=new jo(this),this._handlers.register(this._drawFeature),this._transformFeature=new Bo(this),this._handlers.register(this._transformFeature),this._handlers.attach(this._canvasContainer),!1===t.interactive&&this._handlers.applyInteractive(!1),this._featureQuery=new el(this._sources,()=>this._viewport.transform,()=>({width:this._viewport.width,height:this._viewport.height}),()=>this._viewport.initialMX),this.features=new nl(this);const e=this;this._featureEvents=new Xo({queryFeatures:(t,n)=>e.queryFeatures(t,n),unproject:(t,n)=>e.unproject(t,n),get features(){return e.features}}),this._pointerEvents=new tl({unproject:(t,n)=>e.unproject(t,n)}),this._featureEvents.setOnChange(()=>this._syncPointerSink()),this._pointerEvents.setOnChange(()=>this._syncPointerSink()),this._attachEventListeners(),this.on("move",()=>{this._navSnapshotTransform||this._scheduleRender()}),this.on("resize",()=>this._scheduleRender()),this.on("reset",()=>this.reset()),this.on("historychange",()=>this._runAfterCommitValidators()),this._expressionPolicy=t.expressionPolicy??"disabled",this._workerMode=t.useWorker??t.workerMode??!1,"number"==typeof t.workerThreshold&&t.workerThreshold>=0&&(this._workerThreshold=t.workerThreshold),this._workerRouting=t.workerRouting,(!1!==this._workerMode||t.workerPool)&&(t.workerPool?this._workerPool=t.workerPool:this._workerPool=new Ho({workerUrl:t.workerUrl??"emap-worker.js",poolSize:t.workerPoolSize}))}cancelWorkerJobs(){this._workerPool?.cancelAll()}setExpressionPolicy(t){this._expressionPolicy=t}getExpressionPolicy(){return this._expressionPolicy??"disabled"}_allowExpressionEvaluation(t,e){return!t.some(t=>"string"==typeof t&&t.trim().length>0)||"trusted"===this.getExpressionPolicy()||(this.fire("error",{error:new Error(`${e}: expression evaluation is disabled`)}),!1)}on(t,e,n){if("mousemove"===t)return this._pointerEvents.on(t,e),this;if(t.startsWith("feature:")){const r=n??e,i=n?e:void 0;return this._featureEvents.on(t,i,r),this}return super.on(t,e)}off(t,e){return"mousemove"===t?(this._pointerEvents.off(t,e),this):t.startsWith("feature:")?(this._featureEvents.off(t,e),this):super.off(t,e)}once(t,e,n){if("mousemove"===t)return this._pointerEvents.once(t,e),this;if(t.startsWith("feature:")){const r=n??e,i=n?e:void 0;return this._featureEvents.once(t,i,r),this}return super.once(t,e)}_syncPointerSink(){this._featureEvents.hasListeners()||this._pointerEvents.hasListeners()?this._handlers.setPointerSink(t=>{this._featureEvents.dispatch(t),this._pointerEvents.dispatch(t)}):this._handlers.setPointerSink(null)}getCanvasContainer(){return this._canvasContainer}getEditMode(){return this._editState.mode}setEditMode(t){this._editState.setMode(t)}setEditVertexState(t){this._editState.setVertex(t)}clearEditVertexState(){this._editState.clearVertex()}setEditDrawState(t){this._editState.setDraw(t)}clearEditDrawState(){this._editState.clearDraw()}_attachEventListeners(){this._dragPan.on("pan",t=>{this._ensureNavSnapshot(),this._viewport.pan(t.dx,t.dy),this._scheduleRender("nav",this._computeNavDelta()),this.fire("move")}),this._dragPan.on("panstart",()=>{this._viewport.cancelZoomAnimation(),this._ensureNavSnapshot()}),this._dragPan.on("panend",()=>{this._endNavGesture()}),this._scrollZoom.on("mousewheel",t=>{this._ensureNavSnapshot(),this._viewport.applyWheelZoom(t.direction,t.multiplier,t.x,t.y),this._scheduleRender("nav",this._computeNavDelta()),this.fire("move"),null!==this._wheelSettleTimer&&clearTimeout(this._wheelSettleTimer),this._wheelSettleTimer=setTimeout(()=>{this._wheelSettleTimer=null,this._endNavGesture()},ml._WHEEL_SETTLE_MS)})}_ensureNavSnapshot(){if(this._navSnapshotTransform)return;const t=this._viewport.transform;this._navSnapshotTransform={mx:t.mx,my:t.my,bx:t.bx,by:t.by}}_computeNavDelta(){const t=this._navSnapshotTransform;if(!t)return{tx:0,ty:0,sx:1,sy:1};const e=this._viewport.transform,n=e.mx/t.mx,r=e.my/t.my;return{sx:n,sy:r,tx:e.bx-n*t.bx,ty:e.by-r*t.by}}_endNavGesture(){const t="nav"===this._pendingAction&&this._pendingRender>0;this._navSnapshotTransform=null,null!==this._wheelSettleTimer&&(clearTimeout(this._wheelSettleTimer),this._wheelSettleTimer=null),this._scheduler.notifyInteractionEnd(t),this.fire("interactionend")}_createCanvasContainer(){const t=document.createElement("div");t.style.position="relative",t.style.width="100%",t.style.height="100%",t.style.overflow="hidden",t.className="emap-canvas-container";const e=["top-left","top-right","bottom-left","bottom-right"];for(const n of e){const e=document.createElement("div");e.className=`emap-ctrl-${n}`,e.style.position="absolute",e.style.pointerEvents="none",e.style.zIndex="10";const[r,i]=n.split("-");e.style[r]="10px",e.style[i]="10px",e.style.display="flex",e.style.flexDirection="column",e.style.gap="8px";const s=t=>t.stopPropagation();for(const t of["click","mousedown","mouseup","dblclick","contextmenu"])e.addEventListener(t,s);e.addEventListener("wheel",s,{passive:!0}),t.appendChild(e),this._controlContainers.set(n,e)}return t}_updateSize(){const t=this._container.clientWidth,e=this._container.clientHeight;this._viewport.updateSize(t,e),this._painter.resize(t,e)}addSource(t,e){this._sources.set(t,e);const n=n=>{if(1===this._sources.size&&e.getCRS){const t=e.getCRS();t&&this._projection.crs!==t&&(this._projection.setCRS(t),this._viewport.setCRS(t),this.fire("crschange"))}this.fire("data",{sourceId:t,...n}),this._defaultLayersDirty=!0,this._layerArcFlagsCache.clear(),this._scheduleRender()};this._sourceListeners.set(t,n),e.on("data",n),e.getDataset&&e.getDataset()&&n({type:"data"})}removeSource(t){const e=this._sources.get(t);if(e){const n=this._sourceListeners.get(t);n&&(e.off("data",n),this._sourceListeners.delete(t)),this._sources.delete(t),this._defaultLayersDirty=!0,this._layerArcFlagsCache.delete(t);for(const e of this._layerArcFlagsCache.keys())e.startsWith(`${t}:`)&&this._layerArcFlagsCache.delete(e);this._scheduleRender()}}getSource(t){return this._sources.get(t)}async exportSnapshot(t={}){const e=!1!==t.compact,n=[],r=[];for(const[t,e]of this._sources){if("topology"!==e.type)continue;const i=e.getDataset?.();i&&(n.push(t),r.push(i))}const i=ki(),s=await i.exportDatasetsToPack(r,{compact:e});s.emap={version:1,sources:n.map(t=>({id:t}))};const a=i.pack(s);return new Blob([a],{type:"application/octet-stream"})}async loadSnapshot(t,e={}){const n=!1!==e.replace,r=e.idPrefix??"",i=e.defaultIds??[];let s;if(t instanceof Uint8Array)s=t;else if(t instanceof ArrayBuffer)s=new Uint8Array(t);else{if(!("undefined"!=typeof Blob&&t instanceof Blob))throw new Error("loadSnapshot: input must be Blob, Uint8Array, or ArrayBuffer");s=new Uint8Array(await t.arrayBuffer())}if(!function(t){if(!t||0===t.length)return!1;const e=t[0];return e>=128&&e<=143||222===e||223===e}(s))throw new Error("loadSnapshot: input does not look like a mapshaper .msx snapshot (expected msgpack map marker as the first byte)");const a=await ki().unpackSessionData(s),o=a.datasets??[],l=a.emap,h=l?.sources?.map(t=>t?.id).filter(t=>"string"==typeof t)??[],c=o.map((t,e)=>{const n=h[e],s=i[e]??`snapshot-${e}`;return r+(n??s)});if(!n)for(const t of c)if(this._sources.has(t))throw new Error(`loadSnapshot: source "${t}" already exists (pass { replace: true } to overwrite)`);this._history.clear(),this._fireSelectionChange(this._selection.clear()),this.fire("historychange");const u=[];for(let t=0;t<o.length;t++){const e=c[t];n&&this._sources.has(e)&&this.removeSource(e);const r=new lo(e);r.setDataset(o[t]),this.addSource(e,r),u.push(e)}return u}addLayer(t,e){if(!this._sources.has(t.source))throw new Error(`Source "${t.source}" not found`);if(this._layers.some(e=>e.id===t.id))throw new Error(`Layer "${t.id}" already exists`);if(e){const n=this._layers.findIndex(t=>t.id===e);if(-1===n)throw new Error(`Layer "${e}" not found`);this._layers.splice(n,0,{...t})}else this._layers.push({...t});this._defaultLayersDirty=!0,this._scheduleRender()}removeLayer(t){const e=this._layers.findIndex(e=>e.id===t);-1!==e&&(this._layers.splice(e,1),this._defaultLayersDirty=!0,this._scheduleRender())}getLayer(t){return this._layers.find(e=>e.id===t)}getLayers(){return[...this._layers]}setLayerVisibility(t,e){const n=this._layers.find(e=>e.id===t);n&&(n.layout||(n.layout={}),n.layout.visibility=e,this._scheduleRender())}setPaintProperty(t,e,n){const r=this._layers.find(e=>e.id===t);r&&(r.paint||(r.paint={}),r.paint[e]=n,this._scheduleRender())}moveLayer(t,e){const n=this._layers.findIndex(e=>e.id===t);if(-1===n)return;const[r]=this._layers.splice(n,1);if(e){const t=this._layers.findIndex(t=>t.id===e);-1===t?this._layers.push(r):this._layers.splice(t,0,r)}else this._layers.push(r);this._defaultLayersDirty=!0,this._scheduleRender()}_getEffectiveLayers(){if(this._layers.length>0)return this._layers;if(!this._defaultLayersDirty)return this._effectiveLayersCache;const t=[];for(const[e,n]of this._sources){const r=n.getLayers();if(0===r.length)t.push({id:`${e}:default`,type:"line",source:e,paint:{"line-color":"#333","line-width":.8}});else for(let n=0;n<r.length;n++){const i=r[n],s=Pi(i,n),a=i.geometry_type;t.push({id:`${e}:${s}`,type:"point"===a?"circle":"line",source:e,"source-layer":s,paint:"point"===a?{"circle-color":"#333","circle-radius":4}:{"line-color":"#333","line-width":.8}})}}return this._effectiveLayersCache=t,this._defaultLayersDirty=!1,t}_resolveSourceLayer(t,e){const n=t.getLayers();if(!n.length)return null;if(!e)return n[0];for(let t=0;t<n.length;t++){if(Pi(n[t],t)===e)return n[t]}return null}_getLayerArcFlags(t,e,n){if(!t||!t.shapes||!e)return null;let r=this._layerArcFlagsCache.get(n);if(r)return r;const i=e.size();r=new Uint8Array(i);const s=t.shapes;for(const t of s)if(t)for(const e of t)for(const t of e){r[t>=0?t:~t]=1}return this._layerArcFlagsCache.set(n,r),r}_getVisibleLayerKeys(){const t=new Set,e=this._getEffectiveLayers();for(const n of e){if("none"===n.layout?.visibility)continue;const e=this._sources.get(n.source);if(!e)continue;const r=this._resolveSourceLayer(e,n["source-layer"]);if(r){const i=e.getLayers().indexOf(r),s=Pi(r,i>=0?i:0);t.add(`${n.source}:${s}`)}}return t}getPainter(){return this._painter}getCRS(){return this._projection.crs}setCRS(t){this._projection.setCRS(t),this._viewport.setCRS(t),this.fire("crschange")}async reproject(t){if(this._projection.crs===t)return;const e=await this._projection.reproject(t,this._sources);this._viewport.setCRS(t),this._viewport.clearInitialState(),e.hasBounds()&&this.setExtent(e),this.fire("crschange"),this.fire("data",{reason:"reproject"})}getCenter(){const t=this._viewport.transform,e=(this._viewport.width/2-t.bx)/t.mx,n=(this._viewport.height/2-t.by)/t.my;return this._projection.getCenter(e,n)}getZoom(){return this._projection.getZoom(Math.abs(this._viewport.transform.mx))}get dragPan(){return this._dragPan}get scrollZoom(){return this._scrollZoom}get clickSelect(){return this._clickSelect}get boxSelect(){return this._boxSelect}get lassoSelect(){return this._lassoSelect}get vertexEdit(){return this._vertexEdit}get drawFeature(){return this._drawFeature}get transformFeature(){return this._transformFeature}getTransform(){return this._viewport.transform}getExtent(){return this._viewport.extent}setExtent(t){this._viewport.setExtent(t),this.fire("move")}reset(){this._viewport.reset()}addControl(t,e="top-left"){const n=t.onAdd(this);n.style.pointerEvents="auto",this._controlContainers.get(e)?.appendChild(n),this._controls.push(t)}removeControl(t){t.onRemove(this);const e=this._controls.indexOf(t);-1!==e&&this._controls.splice(e,1)}zoomIn(){this._viewport.zoomIn()}zoomOut(){this._viewport.zoomOut()}jumpTo(t){return this._camera.jumpTo(t),this}setCenter(t){return this._camera.setCenter(t),this}setZoom(t){return this._camera.setZoom(t),this}easeTo(t){return this._camera.easeTo(t),this}panTo(t,e={}){return this._camera.panTo(t,e),this}panBy(t,e={}){return this._camera.panBy(t,e),this}zoomTo(t,e={}){return this._camera.zoomTo(t,e),this}flyTo(t){return this._camera.flyTo(t),this}fitBounds(t,e={}){return this._camera.fitBounds(t,e),this}stop(){return this._camera.stop(),this}_scheduleRender(t="redraw",e){this._removed||(this._pendingRender++,"redraw"===this._pendingAction||"redraw"===t?(this._pendingAction="redraw",this._pendingNavDelta=null):(this._pendingAction="nav",e&&(this._pendingNavDelta={...e})),0===this._rafId&&(this._rafId=requestAnimationFrame(()=>this._doRender())))}_doRender(){if(this._rafId=0,this._pendingRender>0){this._pendingRender=0;const t={action:this._pendingAction};this._pendingNavDelta&&(t.navDelta=this._pendingNavDelta),this._pendingAction="redraw",this._pendingNavDelta=null,this.render(t)}}render(t){this._scheduler.schedule(t??{action:"redraw"})}_renderFull(){this._clearFastTransform();const t=performance.now();this._renderImpl(),this._scheduler.recordFrame(performance.now()-t,this._captureRenderSnapshot())}_renderImpl(){const t=this._viewport.transform;this._painter.setTransform(t),this._painter.clear();const e=this._viewport.getLineScale(),n=1/Math.abs(t.mx);this._renderLayers(n,e),this._renderHighlight(t,e),this._editOverlay.render(this._editState.mode,this._editState.vertex,this._editState.draw)}_captureRenderSnapshot(){return{canvasWidth:this._canvas.width,canvasHeight:this._canvas.height,pixelRatio:window.devicePixelRatio||1}}_applyFastTransform(t){this._canvas.style.transformOrigin="top left",this._canvas.style.transform=`translate(${t.tx}px,${t.ty}px) scale(${t.sx},${t.sy})`}_clearFastTransform(){this._canvas.style.transform&&(this._canvas.style.transform="",this._canvas.style.transformOrigin="")}_renderLayers(t,e){const n=this._getEffectiveLayers();for(const r of n){if("none"===r.layout?.visibility)continue;const n=this._sources.get(r.source);if(!n)continue;const i=n.getDisplayArcs(),s=i?i.getScaledArcs(t):n.getArcs();if(s&&s.setRetainedInterval&&("function"!=typeof s.isFlat||!s.isFlat())){const e=n.getSimplifyFloor?.()??0;s.setRetainedInterval(Math.max(e,.5*t))}const a=this._resolveSourceLayer(n,r["source-layer"]),o=`${r.source}:${r["source-layer"]||"default"}`;if("line"===r.type&&s)this._renderLineLayer(r,a,s,o,e);else if("fill"===r.type&&s&&a?.shapes)this._renderFillLayer(r,a,s,o,e);else if("circle"===r.type&&a?.shapes){const t=fl(r.paint);this._painter.drawPoints(a.shapes,t)}}}_renderLineLayer(t,e,n,r,i){const s=dl(t.paint,i);if(e?.shapes){const t=this._getLayerArcFlags(e,n,r),i=this._combineArcFilters(t,this._viewport.getArcFilter(n));this._painter.drawArcs(n,s,i)}else this._painter.drawArcs(n,s,this._viewport.getArcFilter(n))}_renderFillLayer(t,e,n,r,i){const s=t.paint,a=s?.["fill-color"]||"rgba(200, 200, 200, 0.4)",o=s?.["fill-opacity"],l=this._viewport.getArcFilter(n);this._painter.drawPolygonFill(e.shapes,n,a,l,o);const h=dl(t.paint,i),c=this._getLayerArcFlags(e,n,r);this._painter.drawArcs(n,h,this._combineArcFilters(c,l))}_combineArcFilters(t,e){return t&&e?n=>1===t[n]&&e(n):t?e=>1===t[e]:e}_renderHighlight(t,e){const n=this._getVisibleLayerKeys();this._highlightManager.renderHighlights(this._painter,this._sources,t,e,n)}project(t,e){return this._viewport.project(t,e)}unproject(t,e){return this._viewport.unproject(t,e)}resize(){this._updateSize(),this._viewport.setExtent(this._viewport.extent),this.fire("resize")}queryFeatures(t,e){const n=this._getVisibleLayerKeys();return this._featureQuery.query(t,e,n)}prebuildSpatialIndex(t){this._featureQuery.prebuild(t)}clearSpatialIndex(t){this._featureQuery.clear(t)}_clearSpatialIndexesForSources(t){for(const e of t)this._featureQuery?.clear(e)}setHighlightedFeatures(t,e){this._highlightManager.setHighlightedFeatures(t,e),this._scheduleRender()}clearHighlightedFeatures(){this._highlightManager.clearHighlightedFeatures()&&this._scheduleRender()}setHighlightStyle(t){this._highlightManager.setHighlightStyle(t)&&this._scheduleRender()}select(t,e){const n=e?.mode??"replace",r=this._selection.apply(t,n);this._fireSelectionChange(r)}deselect(t){const e=this._selection.remove(t);this._fireSelectionChange(e)}clearSelection(){const t=this._selection.clear();this._fireSelectionChange(t)}getSelection(){return this._selection.getAll()}isSelected(t){return this._selection.has(t)}_fireSelectionChange(t){t.changed&&(this.fire("selectionchange",{selected:this._selection.getAll(),added:t.added,removed:t.removed}),this._handlers?.refreshCursor())}deleteSelected(){const t=this._selection.getAll();if(0===t.length)return!1;const e=new globalThis.Map;for(const n of t){let t=e.get(n.source);t||(t=new globalThis.Map,e.set(n.source,t));const r=t.get(n.layer)??[];r.push(n.id),t.set(n.layer,r)}const n=[];let r=0;for(const[t,i]of e){const e=this._sources.get(t);if(!e)continue;const s=e.getLayers();for(const[t,e]of i){let i=null;for(let e=0;e<s.length;e++)if(Pi(s[e],e)===t){i=s[e];break}if(!i?.shapes)continue;const a=i.data?.getRecords?.(),o=[],l=new Set;for(const t of e){if(l.has(t))continue;l.add(t);const e=i.shapes[t];if(void 0===e)continue;const n=a?a[t]:null;o.push({id:t,shape:e,record:n??null})}if(0===o.length)continue;const h=new _l({layer:i,snapshots:o});h.do(),n.push(h),r+=o.length}}if(0===n.length)return!1;const i=new us(n,`Delete ${r} feature${r>1?"s":""}`);return this._history.push(i),this._fireHistoryChange(),this._invalidateShapeCachesForSources(e.keys()),this._fireSelectionChange(this._selection.clear()),this._scheduleRender(),!0}_invalidateShapeCachesForSources(t){for(const e of t){const t=`${e}:`;for(const e of this._layerArcFlagsCache.keys())e.startsWith(t)&&this._layerArcFlagsCache.delete(e);this._featureQuery?.clear(e)}}pushCommand(t){this._history.push(t),this._fireHistoryChange()}undo(){return!!this._history.undo()&&(this._fireHistoryChange(),this._invalidateAllShapeCaches(),this._scheduleRender(),!0)}redo(){return!!this._history.redo()&&(this._fireHistoryChange(),this._invalidateAllShapeCaches(),this._scheduleRender(),!0)}_invalidateAllShapeCaches(){this._layerArcFlagsCache.clear();for(const t of this._sources.keys())this._featureQuery?.clear(t)}canUndo(){return this._history.canUndo()}canRedo(){return this._history.canRedo()}clearHistory(){const t=this._history.canUndo()||this._history.canRedo();this._history.clear(),t&&this._fireHistoryChange()}beginTransaction(){return new ul(this)}bindHistoryShortcuts(t){this._historyShortcutUnbind?.();const e=t??this._canvasContainer;e.hasAttribute("tabindex")||e.setAttribute("tabindex","-1");const n=t=>{if(!(t.ctrlKey||t.metaKey))return;const e="z"===t.key||"Z"===t.key,n="y"===t.key||"Y"===t.key;e&&!t.shiftKey?(t.preventDefault(),this.undo()):(e&&t.shiftKey||n)&&(t.preventDefault(),this.redo())};e.addEventListener("keydown",n);const r=()=>{e.removeEventListener("keydown",n),this._historyShortcutUnbind===r&&(this._historyShortcutUnbind=null)};return this._historyShortcutUnbind=r,r}_fireHistoryChange(){const t=this._history.snapshot();this.fire("historychange",t)}_runAfterCommitValidators(){if(0===this._validators.size)return;const t={label:this._history.snapshot().label??""};this._validators.runFor("after-commit",this,t).then(e=>{if(this._removed)return;const n=e.filter(t=>!t.report.ok);n.length>0&&this.fire("validationfailed",{results:n,label:t.label})})}_resolveLayer(t,e){return this.layers.resolve(t,e)}remove(){if(this._removed)return;this._removed=!0,0!==this._rafId&&(cancelAnimationFrame(this._rafId),this._rafId=0),this._pendingRender=0,this._pendingAction="redraw",this._pendingNavDelta=null,this._navSnapshotTransform=null,null!==this._wheelSettleTimer&&(clearTimeout(this._wheelSettleTimer),this._wheelSettleTimer=null),this._scheduler?.dispose(),this._handlers?.detach(),this._scrollZoom?.destroy(),this._historyShortcutUnbind?.(),this._historyShortcutUnbind=null,this._workerPool&&(this._workerPool.cancelAll(),this._workerPool.destroy(),this._workerPool=null);for(const[t,e]of this._sourceListeners){const n=this._sources.get(t);n?.off("data",e)}this._sourceListeners.clear();for(const t of this._sources.keys())this._featureQuery?.clear(t);this._layerArcFlagsCache.clear(),this._sources.clear();const t=this._controls??[];for(const e of[...t])try{e.onRemove(this)}catch(t){this.fire("error",{error:t})}t.length=0,this._controlContainers?.clear(),this._editState?.setMode("none"),this._container&&this._canvasContainer&&this._container.removeChild(this._canvasContainer)}_removed=!1}function gl(t){return`"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/\0/g,"\\0")}"`}const yl=/^[A-Za-z0-9_\-:.一-鿿][A-Za-z0-9_\-:. 一-鿿]*$/,vl=/^[A-Za-z0-9_\-.一-鿿][A-Za-z0-9_\-. 一-鿿]*$/;function wl(t){return"string"==typeof t&&t.length>0&&yl.test(t)}function Sl(t){return"string"==typeof t&&t.length>0&&vl.test(t)}function xl(t){for(const e of t)if(!Sl(e))return"string"==typeof e?e:String(e);return null}function bl(t={}){const e=t.severity??"error";return{name:"topology",phase:"after-commit",async run(n){const r=ki(),i=t.sources??Array.from(n._sources.keys()),s=[];for(const a of i){const i=n._sources.get(a)?.getDataset();if(!i||!i.arcs)continue;const o={};void 0!==t.tolerance&&(o.tolerance=t.tolerance);const l=r.findSegmentIntersections(i.arcs,o);l.length>0&&s.push({severity:e,message:`${a}: ${l.length} self-intersection${1===l.length?"":"s"}`})}return{ok:0===s.length,issues:s}}}}class Cl{_map=null;_container=null;_options;constructor(t={}){this._options={showZoom:!0,showHome:!0,...t}}onAdd(t){return this._map=t,this._container=document.createElement("div"),this._container.className=`emap-ctrl emap-ctrl-group ${this._options.className||""}`,this._options.showZoom&&(this._createButton("zoom-in","+","Zoom In",()=>{this._map?.zoomIn()}),this._createButton("zoom-out","-","Zoom Out",()=>{this._map?.zoomOut()})),this._options.showHome&&this._createButton("home","⌂","Reset View",()=>{this._map?.fire("reset")}),this._container}_createButton(t,e,n,r){const i=document.createElement("button");i.className=`emap-ctrl-${t}`,i.type="button",i.title=n;const s=document.createElement("span");s.className="emap-ctrl-icon",s.textContent=e,i.appendChild(s),i.addEventListener("click",r),this._container?.appendChild(i)}onRemove(){this._container&&this._container.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._container=null}}class El{_map=null;_container=null;_options;_mousePosEl=null;_epsgEl=null;_onMoveBound;_onUpdateEPSGBound;_rafPending=!1;constructor(t={}){this._options={showMousePos:!0,showEPSG:!0,alignment:"left",...t},this._onMoveBound=this._onMove.bind(this),this._onUpdateEPSGBound=this._updateEPSG.bind(this)}onAdd(t){return this._map=t,this._container=document.createElement("div"),this._container.className=`emap-ctrl emap-status-ctrl emap-align-${this._options.alignment} ${this._options.className||""}`,this._options.showMousePos&&(this._mousePosEl=document.createElement("span"),this._mousePosEl.className="emap-status-mousepos",this._container.appendChild(this._mousePosEl)),this._options.showEPSG&&(this._epsgEl=document.createElement("span"),this._epsgEl.className="emap-status-epsg",this._container.appendChild(this._epsgEl),this._updateEPSG()),this._map.on("crschange",this._onUpdateEPSGBound),this._options.showMousePos&&this._map.on("mousemove",this._onMoveBound),this._container}_onMove(t){if(!this._map||!this._mousePosEl||!this._options.showMousePos)return;if(this._rafPending)return;this._rafPending=!0;const[e,n]=t.mapCoord;requestAnimationFrame(()=>{this._rafPending=!1,this._map&&this._mousePosEl&&(this._mousePosEl.textContent=` ${e.toFixed(4)}, ${n.toFixed(4)}`)})}_updateEPSG(){if(!this._map||!this._epsgEl)return;const t=this._map.getCRS();this._epsgEl.textContent=` | ${t}`}onRemove(){this._map&&(this._options.showMousePos&&this._map.off("mousemove",this._onMoveBound),this._map.off("crschange",this._onUpdateEPSGBound)),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._container=null}}const Al=[{name:"OSM",url:"https://tile.openstreetmap.org/{z}/{x}/{y}.png",type:"raster"},{name:"CartoDB Light",url:"https://basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png",type:"raster"},{name:"CartoDB Dark",url:"https://basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png",type:"raster"}];class kl{_map=null;_container=null;_basemapContainer=null;_maplibre=null;_maplibreMap=null;_styles;_activeStyle=null;_isOn=!1;_syncBasemapBound;constructor(t={}){this._styles=t.styles||Al,this._syncBasemapBound=this._syncBasemap.bind(this)}onAdd(t){return this._map=t,this._container=document.createElement("div"),this._container.className="emap-ctrl emap-basemap-ctrl",this._styles.forEach(t=>{const e=document.createElement("button");e.className="emap-basemap-btn",e.textContent=t.name,e.onclick=()=>this._toggleStyle(t),this._container.appendChild(e)}),this._createBasemapLayer(),this._map.on("move",this._syncBasemapBound),this._container}_createBasemapLayer(){if(!this._map)return;const t=this._map.getCanvasContainer();this._basemapContainer=document.createElement("div"),this._basemapContainer.className="emap-basemap",this._basemapContainer.style.cssText="\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n z-index: 0;\n display: none;\n ",t.insertBefore(this._basemapContainer,t.firstChild)}_toggleStyle(t){this._activeStyle===t?this._turnOff():this._showBasemap(t),this._updateButtons()}async _showBasemap(t){if(this._activeStyle=t,this._isOn=!0,!this._basemapContainer||!this._map)return;this._basemapContainer.style.display="block";const e=(this._map.getCRS()||"").toLowerCase();"webmercator"!==e&&"epsg:3857"!==e&&this._map.reproject&&await this._map.reproject("webmercator"),this._maplibreMap?(this._maplibreMap.resize(),this._setStyle(t),this._syncBasemap()):await this._initMapLibre(t)}async _initMapLibre(t){if(!this._basemapContainer||!this._map)return;const e=await this._loadMapLibre(),n=this._createMapLibreStyle(t);this._maplibreMap=new e.Map({container:this._basemapContainer,style:n,center:this._map.getCenter(),zoom:this._map.getZoom(),interactive:!1,attributionControl:!1,maxPitch:0,renderWorldCopies:!0}),this._maplibreMap.on("load",()=>{this._syncBasemap()})}async _loadMapLibre(){return this._maplibre||(this._maplibre=await import("maplibre-gl")),this._maplibre}_setStyle(t){if(!this._maplibreMap)return;const e=this._createMapLibreStyle(t);this._maplibreMap.setStyle(e)}_createMapLibreStyle(t){return"raster"===t.type||t.url.includes("{z}")?{version:8,sources:{"basemap-tiles":{type:"raster",tiles:[t.url],tileSize:512}},layers:[{id:"basemap-layer",type:"raster",source:"basemap-tiles",minzoom:0,maxzoom:22}]}:t.url}_syncBasemap(){if(this._maplibreMap&&this._map&&this._isOn)try{this._maplibreMap.jumpTo({center:this._map.getCenter(),zoom:this._map.getZoom()})}catch(t){console.warn("Sync basemap failed:",t)}}_turnOff(){this._activeStyle=null,this._isOn=!1,this._basemapContainer&&(this._basemapContainer.style.display="none")}_updateButtons(){if(!this._container)return;this._container.querySelectorAll(".emap-basemap-btn").forEach((t,e)=>{const n=this._styles[e]===this._activeStyle;t.classList.toggle("active",n)})}isOn(){return this._isOn}onRemove(){this._map&&this._map.off("move",this._syncBasemapBound),this._maplibreMap&&(this._maplibreMap.remove(),this._maplibreMap=null),this._basemapContainer?.parentNode&&this._basemapContainer.parentNode.removeChild(this._basemapContainer),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null}}class Ml{_map=null;_container=null;_btn=null;_opts;constructor(t={}){this._opts=t}onAdd(t){return this._map=t,void 0!==this._opts.polygonFillColor&&t.vertexEdit.setOptions({polygonFillColor:this._opts.polygonFillColor}),this._container=document.createElement("div"),this._container.className="emap-ctrl emap-ctrl-group",this._btn=document.createElement("button"),this._btn.className="emap-ctrl-edit",this._btn.type="button",this._btn.title="Edit Vertices",this._btn.innerHTML='<span class="emap-ctrl-icon">✏</span>',this._btn.addEventListener("click",()=>this._toggle()),this._container.appendChild(this._btn),this._container}onRemove(){this._map&&this._map.vertexEdit.isEnabled()&&this._map.vertexEdit.disable(),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._container=null,this._btn=null}_toggle(){if(!this._map)return;const t=this._map.vertexEdit;t.isEnabled()?(t.disable(),this._btn?.classList.remove("active")):(t.enable(),this._btn?.classList.add("active"))}}const Il={polygon:"▢",polyline:"╱",point:"●"},Tl={polygon:"Draw Polygon",polyline:"Draw Polyline",point:"Draw Point"};class Dl{_opts;_map=null;_container=null;_btn=null;constructor(t){this._opts=t}onAdd(t){this._map=t,this._container=document.createElement("div"),this._container.className="emap-ctrl emap-ctrl-group",this._btn=document.createElement("button"),this._btn.className="emap-ctrl-draw",this._btn.type="button",this._btn.title=Tl[this._opts.type];const e=document.createElement("span");e.className="emap-ctrl-icon";const n=this._opts.icon??Il[this._opts.type];return"string"==typeof n?e.textContent=n:e.appendChild(n),this._btn.replaceChildren(e),this._btn.addEventListener("click",()=>this._toggle()),this._container.appendChild(this._btn),this._applyOptions(),t.on("editmodechange",t=>{"draw"!==t.mode&&this._btn?.classList.remove("active")}),this._container}onRemove(){this._map&&this._map.drawFeature.isEnabled()&&this._map.drawFeature.disable(),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._container=null,this._btn=null}_toggle(){if(!this._map)return;const t=this._map.drawFeature;t.isEnabled()&&this._btn?.classList.contains("active")?(t.disable(),this._btn?.classList.remove("active")):(t.isEnabled()&&t.disable(),this._applyOptions(),t.enable(),this._clearPeerActiveButtons(),this._btn?.classList.add("active"))}_applyOptions(){if(!this._map)return;const{icon:t,...e}=this._opts;this._map.drawFeature.setOptions(e)}_clearPeerActiveButtons(){const t=this._btn?.closest(".emap-edit-toolbar, .emap-ctrl-group");t?.querySelectorAll(".emap-ctrl-draw.active").forEach(t=>{t!==this._btn&&t.classList.remove("active")})}}class Pl{_container=null;_controls;_options;constructor(t){this._options=t||{},this._options.controls?this._controls=this._options.controls:(this._controls=[new Ml],this._options.drawSource&&this._controls.push(new Dl({source:this._options.drawSource,sourceLayer:this._options.drawSourceLayer,type:"polygon"}),new Dl({source:this._options.drawSource,sourceLayer:this._options.drawSourceLayer,type:"polyline"}),new Dl({source:this._options.drawSource,sourceLayer:this._options.drawSourceLayer,type:"point"})))}onAdd(t){this._container=document.createElement("div"),this._container.className="emap-ctrl emap-ctrl-group emap-edit-toolbar";for(const e of this._controls){const n=e.onAdd(t).querySelectorAll("button");for(const t of n)this._container.appendChild(t)}return this._container}onRemove(){for(const t of this._controls)t.onRemove();this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._container=null}}class Nl{_map=null;_container=null;_undoBtn=null;_redoBtn=null;_options;_onHistoryChange=null;constructor(t={}){this._options=t}onAdd(t){return this._map=t,this._container=document.createElement("div"),this._container.className=`emap-ctrl emap-ctrl-group ${this._options.className||""}`.trim(),this._undoBtn=this._createButton("undo","↶",this._options.undoTitle??"Undo (Ctrl+Z)",()=>{this._map?.undo()}),this._redoBtn=this._createButton("redo","↷",this._options.redoTitle??"Redo (Ctrl+Shift+Z)",()=>{this._map?.redo()}),this._setEnabled(t.canUndo(),t.canRedo()),this._onHistoryChange=t=>this._setEnabled(t.canUndo,t.canRedo),t.on("historychange",this._onHistoryChange),this._container}onRemove(){this._map&&this._onHistoryChange&&this._map.off("historychange",this._onHistoryChange),this._onHistoryChange=null,this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._container=null,this._undoBtn=null,this._redoBtn=null}_setEnabled(t,e){this._undoBtn&&(this._undoBtn.disabled=!t),this._redoBtn&&(this._redoBtn.disabled=!e)}_createButton(t,e,n,r){const i=document.createElement("button");i.className=`emap-ctrl-${t}`,i.type="button",i.title=n,i.disabled=!0;const s=document.createElement("span");return s.className="emap-ctrl-icon",s.textContent=e,i.appendChild(s),i.addEventListener("click",r),this._container?.appendChild(i),i}}class Rl{_options;_enabled=!0;_handler=null;_container=null;constructor(t={}){this._options=t}onAdd(t){this._handler=t.boxSelect,this._handler.setOptions({layers:this._options.layers,dragThreshold:this._options.dragThreshold,dragActivator:this._options.dragActivator,style:this._options.style}),this._enabled&&this._handler.enable();const e=document.createElement("div");return e.className="emap-ctrl emap-box-select-anchor",e.style.width="0",e.style.height="0",e.style.pointerEvents="none",this._container=e,e}onRemove(){this._handler?.disable(),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._handler=null,this._container=null}disable(){this._enabled=!1,this._handler?.disable()}enable(){this._enabled=!0,this._handler?.enable()}isEnabled(){return this._handler?this._handler.isEnabled():this._enabled}}class Ll{_options;_enabled=!0;_handler=null;_container=null;constructor(t={}){this._options=t}onAdd(t){this._handler=t.lassoSelect,this._handler.setOptions({layers:this._options.layers,dragThreshold:this._options.dragThreshold,includeIntersecting:this._options.includeIntersecting,style:this._options.style}),this._enabled&&this._handler.enable();const e=document.createElement("div");return e.className="emap-ctrl emap-lasso-select-anchor",e.style.width="0",e.style.height="0",e.style.pointerEvents="none",this._container=e,e}onRemove(){this._handler?.disable(),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._handler=null,this._container=null}disable(){this._enabled=!1,this._handler?.disable()}enable(){this._enabled=!0,this._handler?.enable()}isEnabled(){return this._handler?this._handler.isEnabled():this._enabled}}const Gl=[{value:"",label:"weighted (default)"},{value:"weighted",label:"weighted"},{value:"visvalingam",label:"visvalingam"},{value:"dp",label:"dp (Douglas–Peucker)"}];class Ol{_opts;_map=null;_container=null;_btn=null;_popup=null;_percentageInput=null;_percentageLabel=null;_methodSel=null;_keepShapes=null;_planar=null;_applyBtn=null;_statusEl=null;_onDocClick=null;_onDocKey=null;constructor(t){this._opts=t}onAdd(t){return this._map=t,this._container=document.createElement("div"),this._container.className="emap-ctrl emap-ctrl-group emap-ctrl-simplify-wrap",this._btn=document.createElement("button"),this._btn.type="button",this._btn.className="emap-ctrl-simplify",this._btn.innerHTML='<span class="emap-ctrl-icon">≈</span>',this._btn.title=this._opts.title??"Simplify geometry",this._btn.onclick=t=>{t.stopPropagation(),this._togglePopup()},this._container.appendChild(this._btn),this._popup=this._buildPopup(),this._container.appendChild(this._popup),this._container}onRemove(){this._teardownDocListeners(),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._container=null,this._btn=null,this._popup=null,this._percentageInput=null,this._percentageLabel=null,this._methodSel=null,this._keepShapes=null,this._planar=null,this._applyBtn=null,this._statusEl=null,this._map=null}_buildPopup(){const t=document.createElement("div");t.className="emap-simplify-popup",t.style.display="none",t.style.cssText+="\n position:absolute; top:36px; left:0; min-width:240px; padding:10px;\n background:#fff; border:1px solid #ccc; border-radius:4px;\n box-shadow:0 2px 8px rgba(0,0,0,.15); font-size:13px;\n z-index:10; color:#222;",t.onclick=t=>t.stopPropagation();const e=this._opts.initialPercentage??10,n=this._opts.initialMethod??"";return t.innerHTML=`\n <div style="margin-bottom:8px;">\n <label style="display:flex; align-items:center; gap:6px;">\n <span>Percentage:</span>\n <input type="range" min="0" max="100" step="0.1" value="${e}" style="flex:1;" />\n <span class="value" style="min-width:48px; text-align:right;">${e}%</span>\n </label>\n </div>\n <div style="margin-bottom:8px;">\n <label style="display:flex; align-items:center; gap:6px;">\n <span>Method:</span>\n <select style="flex:1;">\n ${Gl.map(t=>`<option value="${t.value}"${t.value===n?" selected":""}>${t.label}</option>`).join("")}\n </select>\n </label>\n </div>\n <div style="margin-bottom:8px; display:flex; gap:12px; flex-wrap:wrap;">\n <label><input type="checkbox" data-flag="keep-shapes" checked /> keep-shapes</label>\n <label><input type="checkbox" data-flag="planar" /> planar</label>\n </div>\n <div style="display:flex; gap:6px; align-items:center;">\n <button type="button" class="apply" style="padding:4px 12px;">Apply</button>\n <span class="status" style="opacity:.8; font-size:12px;"></span>\n </div>\n `,this._percentageInput=t.querySelector("input[type=range]"),this._percentageLabel=t.querySelector(".value"),this._methodSel=t.querySelector("select"),this._keepShapes=t.querySelector("input[data-flag=keep-shapes]"),this._planar=t.querySelector("input[data-flag=planar]"),this._applyBtn=t.querySelector("button.apply"),this._statusEl=t.querySelector(".status"),this._percentageInput.oninput=()=>{this._percentageLabel&&this._percentageInput&&(this._percentageLabel.textContent=`${this._percentageInput.value}%`)},this._applyBtn.onclick=()=>this._apply(),t}_togglePopup(){if(!this._popup)return;const t="none"===this._popup.style.display;this._popup.style.display=t?"block":"none",this._btn?.classList.toggle("active",t),t?(this._setupDocListeners(),this._setStatus("")):this._teardownDocListeners()}_setupDocListeners(){this._onDocClick=t=>{this._container&&!this._container.contains(t.target)&&this._togglePopup()},this._onDocKey=t=>{"Escape"===t.key&&this._togglePopup()},document.addEventListener("mousedown",this._onDocClick),document.addEventListener("keydown",this._onDocKey)}_teardownDocListeners(){this._onDocClick&&document.removeEventListener("mousedown",this._onDocClick),this._onDocKey&&document.removeEventListener("keydown",this._onDocKey),this._onDocClick=null,this._onDocKey=null}_setStatus(t){this._statusEl&&(this._statusEl.textContent=t)}async _apply(){if(!this._map||!this._percentageInput||!this._methodSel)return;const t=Number(this._percentageInput.value),e=this._methodSel.value,n={source:this._opts.source,percentage:t};this._opts.target&&(n.target=this._opts.target),e&&(n.method=e),this._keepShapes?.checked&&(n.keepShapes=!0),this._planar?.checked&&(n.planar=!0),this._applyBtn&&(this._applyBtn.disabled=!0),this._setStatus("Running…");try{const e=await this._map.ops.simplifyLayer(n);if(e?.ok)this._setStatus(`Simplified at ${t}%`);else{const t=e?.error,n=t?`${t.kind}${t.field?" field="+t.field:""}`:"unknown";this._setStatus(`Failed: ${n}`)}}catch(t){this._setStatus(`Error: ${t?.message??t}`)}finally{this._applyBtn&&(this._applyBtn.disabled=!1)}}}export{gi as AffineTransform,kl as BasemapControl,yi as Bounds,Rl as BoxSelectControl,Po as BoxSelectHandler,_l as BulkFeatureDeleteCommand,Ri as CanvasPainter,To as ClickSelectHandler,us as CompositeCommand,eo as DEFAULT_CRS,Oi as DatasetReplaceCommand,Ei as DefaultMapshaperAdapter,_o as DragPanHandler,Dl as DrawFeatureControl,jo as DrawFeatureHandler,cl as EditHistory,Li as EditOverlayRenderer,Pl as EditToolbar,ml as Emap,qi as Err,mi as EventDispatcher,nl as FeatureAccessor,ms as FeatureAffineCommand,qo as FeatureCreateCommand,pl as FeatureDeleteCommand,ks as FeaturePropertyChangeCommand,el as FeatureQuery,fs as FeatureTranslateCommand,Is as FieldAddCommand,Ts as FieldRemoveCommand,Ds as FieldRenameCommand,Wo as HandlerManager,il as HighlightManager,Nl as HistoryControl,ws as IDENTITY_MATRIX,Ll as LassoSelectControl,Lo as LassoSelectHandler,Ho as MapshaperWorkerPool,Cl as NavigationControl,Fi as OK,Di as Projection,uo as ScrollZoomHandler,sl as Selection,Ol as SimplifyControl,xs as SplitSharedArcsCommand,El as StatusControl,lo as TopologySource,ul as Transaction,gi as Transform,Bo as TransformFeatureHandler,rl as ValidatorRegistry,Fo as VertexDeleteCommand,Ml as VertexEditControl,Uo as VertexEditHandler,Oo as VertexInsertCommand,Go as VertexMoveCommand,xi as Viewport,ds as bumpEditVersion,vs as composeMatrix,yo as featureMatchesLasso,xl as findInvalidFieldName,ki as getDefaultMapshaperAdapter,io as inferFromPrj,Ss as invertMatrix,Vo as isHandler,ps as isPathLayer,_s as isPointLayer,Sl as isValidFieldName,wl as isValidLayerName,ro as normalizeCrsString,Ui as okValue,bs as planSharedArcSplit,go as pointInPolygon,gl as quoteCliArg,no as resolveDatasetCRS,mo as resolveMode,fl as resolvePointStyle,dl as resolveStrokeStyle,gs as rotateMatrix,ys as scaleMatrix,Mi as setDefaultMapshaperAdapter,bl as topologyValidator};