@zwishing/emap 0.1.2 → 0.2.0
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/CHANGELOG.md +52 -1
- package/README.md +5 -0
- package/dist/emap.js +1 -1
- package/dist/emap.mjs +1 -1
- package/dist/mapshaper-vendor.js +1 -1
- package/dist/mapshaper-vendor.mjs +1 -1
- package/dist/source/topology-source.d.ts +28 -4
- package/package.json +1 -1
package/dist/emap.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var emap=function(t,e){"use strict";function i(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 r=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,r.get?r:{enumerable:!0,get:function(){return e[i]}})}})}),Object.freeze(t)}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function r(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function n(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 r=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(i,e,r.get?r:{enumerable:!0,get:function(){return t[e]}})}),i}var s={exports:{}},o=n(Object.freeze({__proto__:null,default:{}}));function a(t,e){for(var i=0,r=t.length-1;r>=0;r--){var n=t[r];"."===n?t.splice(r,1):".."===n?(t.splice(r,1),i++):i&&(t.splice(r,1),i--)}if(e)for(;i--;i)t.unshift("..");return t}var l=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,c=function(t){return l.exec(t).slice(1)};function h(){for(var t="",e=!1,i=arguments.length-1;i>=-1&&!e;i--){var r=i>=0?arguments[i]:"/";if("string"!=typeof r)throw new TypeError("Arguments to path.resolve must be strings");r&&(t=r+"/"+t,e="/"===r.charAt(0))}return(e?"/":"")+(t=a(v(t.split("/"),function(t){return!!t}),!e).join("/"))||"."}function u(t){var e=p(t),i="/"===b(t,-1);return(t=a(v(t.split("/"),function(t){return!!t}),!e).join("/"))||e||(t="."),t&&i&&(t+="/"),(e?"/":"")+t}function p(t){return"/"===t.charAt(0)}function d(){return u(v(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 f(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=h(t).substr(1),e=h(e).substr(1);for(var r=i(t.split("/")),n=i(e.split("/")),s=Math.min(r.length,n.length),o=s,a=0;a<s;a++)if(r[a]!==n[a]){o=a;break}var l=[];for(a=o;a<r.length;a++)l.push("..");return(l=l.concat(n.slice(o))).join("/")}function m(t){var e=c(t),i=e[0],r=e[1];return i||r?(r&&(r=r.substr(0,r.length-1)),i+r):"."}function _(t,e){var i=c(t)[2];return e&&i.substr(-1*e.length)===e&&(i=i.substr(0,i.length-e.length)),i}function g(t){return c(t)[3]}var y={extname:g,basename:_,dirname:m,sep:"/",delimiter:":",relative:f,join:d,isAbsolute:p,normalize:u,resolve:h};function v(t,e){if(t.filter)return t.filter(e);for(var i=[],r=0;r<t.length;r++)e(t[r],r,t)&&i.push(t[r]);return i}var x,b="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)},w=n(Object.freeze({__proto__:null,basename:_,default:y,delimiter:":",dirname:m,extname:g,isAbsolute:p,join:d,normalize:u,relative:f,resolve:h,sep:"/"}));x=s,function(){var t=Math.abs,e=Math.floor,i=Math.sin,r=Math.cos,n=Math.tan,s=Math.asin,a=Math.acos,l=Math.atan,c=Math.atan2,h=Math.sqrt,u=Math.pow,p=Math.exp,d=Math.log,f=Math.hypot,m=Math.sinh,_=Math.cosh,g=Math.min,y=Math.max,v=1/0,b=Math.PI,S=57.29577951308232,T=.017453292519943295,C=6378137,M=.0066943799901413165,A=b/4,E=b/2,I=1.5*b,P=2*b,D=2/b,k=-45,z=-47,R=1e-10,L={last_errno:0,debug_level:0,logger:null},F=["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 B(){var t=L.last_errno;t&&(t>0||!function(t){return O.indexOf(t)>-1}(t))&&U(t)}var O=[-14,-15,-17,-18,-19,-20,-27,-48];function N(t){L.last_errno=t}function V(){N(-20)}function j(){N(-20)}function G(t){U(t)}function U(t){N(t),q()}function q(t,e){var i;throw e||(e={}),e.code||(e.code=L.last_errno||0),t||(i=e.code,t=F[~i]||"unknown error"),L.last_errno=0,new $(t,e)}function $(t,e){var i=new Error(t);return i.name="ProjError",Object.keys(e).forEach(function(t){i[t]=e[t]}),i}function Z(t){return W(t)*T}function W(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 H(t){return X(t)}function X(t){return parseFloat(t)}function Y(t,e){var i,r,n=e[0],s=t[e.substr(1)],o=void 0!==s;return"t"==n?i=o:o?(r=s.param,s.used=!0,"i"==n?i=parseInt(r):"d"==n?i=H(r):"r"==n?i=Z(r):"s"==n?i=String(r):"b"==n&&("T"==r||"t"==r||!0===r?i=!0:("F"==r||"f"==r||N(-8),i=!1))):i={i:0,b:!1,d:0,r:0,s:""}[n],void 0===i&&q("invalid request to pj_param, fatal"),i}function K(t){for(var e,i=/\+([a-z][a-z0-9_]*(?:=[^\s]*)?)/gi,r={};e=i.exec(t);)J(r,e[1]);return r}function J(t,e){var i,r,n=e.split("=");1==n.length?(i=e,r=!0):(i=n[0],r=e.substr(n[0].length+1)),t[i]={used:!1,param:r}}var Q={};function tt(t,e,i,r){Q[e]={init:t,name:i,description:r}}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):G(-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 rt(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(r){-1==e.indexOf(r)&&(i+=nt(t,r))}),(i+=it(t)).trim()}function nt(t,e){var i="";return e in t.params&&(i=" +"+e,!0!==t.params[e].param&&(i+="="+Y(t.params,"s"+e))),i}var st=[["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]],ot=[["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=st.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 lt=[["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 ct(t){var e=lt.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 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 ut(t){var e=ht.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={},dt={};function ft(t){return dt[t]||null}function mt(t){var e,i,r,n,s,a,l,c,h=t.split(":"),u=h[0],p=h[1];return p&&u||G(-3),(e=ft(u=u.toLowerCase()))||(i=u,n=o,a=(s=w).join(s.dirname("/Users/zhang/code/emap/node_modules/mproj/dist"),"../nad"),l=s.join(a,i.toUpperCase()),c=s.join(a,i.toLowerCase()),n.existsSync(l)?r=n.readFileSync(l,"utf8"):n.existsSync(c)?r=n.readFileSync(c,"utf8"):q("unable to read from 'init' file named "+i),e=r,dt[u]=e),e?function(t,e){var i,r,n="",s="";return(i=t.indexOf("<"+e+">"))>-1&&((r=t.lastIndexOf("#",i))>-1&&(s=t.substring(r+1,i).trim(),/\n/.test(s)&&(s="")),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:s}:null}(e,p):null}function _t(e){var r,n,s=K(e),o={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||G(-1),Y(s,"tinit")&&function(t,e){var i=pt[e.toLowerCase()]||null;i||function(t,e){pt[t.toLowerCase()]=e}(e,i=mt(e)),i||G(-2),gt(t,i.opts)}(s,Y(s,"sinit")),(r=Y(s,"sproj"))||G(-4),(n=Q[r])||G(-5),Y(s,"bno_defs")||function(t){gt(t,"+ellps=WGS84")}(o.params),function(t){var e,i,r,n,s=484813681109536e-20,o=t.datum_params=[0,0,0,0,0,0,0];t.datum_type=0,(e=Y(t.params,"sdatum"))&&((i=at(e))||G(-9),i.ellipse_id&&J(t.params,"ellps="+i.ellipse_id),i.defn&&J(t.params,i.defn)),(r=Y(t.params,"snadgrids"))&&"@null"!=r&&q("+nadgrids is not implemented"),Y(t.params,"scatalog")&&q("+catalog is not implemented"),(n=Y(t.params,"stowgs84"))&&(n.split(",").forEach(function(t,e){o[e]=H(t)||0}),0!=o[3]||0!=o[4]||0!=o[5]||0!=o[6]?(t.datum_type=2,o[3]*=s,o[4]*=s,o[5]*=s,o[6]=o[6]/1e6+1):t.datum_type=1)}(o),function(e){var r,n,s,o,a,l=.16666666666666666,c=e.params,u=0,p=0;Y(c,"tR")?u=Y(c,"dR"):((r=Y(c,"sellps"))&&((n=ct(r))||G(-9),J(c,n.major),J(c,n.ell)),u=Y(c,"da"),Y(c,"tes")?p=Y(c,"des"):Y(c,"te")?p=(s=Y(c,"de"))*s:Y(c,"trf")?((s=Y(c,"drf"))||G(-10),p=(s=1/s)*(2-s)):Y(c,"tf")?p=(s=Y(c,"df"))*(2-s):Y(c,"tb")&&(p=1-(o=Y(c,"db"))*o/(u*u)),o||(o=u*h(1-p)),Y(c,"bR_A")?(u*=1-p*(l+p*(.04722222222222222+.022156084656084655*p)),p=0):Y(c,"bR_V")?u*=1-p*(l+p*(.06944444444444445+.04243827160493827*p)):Y(c,"bR_a")?(u=.5*(u+o),p=0):Y(c,"bR_g")?(u=h(u*o),p=0):Y(c,"bR_h")?(u+o===0&&G(-20),u=2*u*o/(u+o),p=0):(a=Y(c,"tR_lat_a")||Y(c,"tR_lat_g"))&&(s=i(Y(c,a?"rR_lat_a":"rR_lat_g")),t(s)>E&&G(-11),s=1-p*s*s,u*=a?.5*(1-p+s)/(s*h(s)):h(1-p)/s,p=0)),p<0&&G(-12),u<=0&&G(-13),e.es=p,e.a=u}(o),o.a_orig=o.a,o.es_orig=o.es,o.e=h(o.es),o.ra=1/o.a,o.one_es=1-o.es,o.one_es||G(-6),o.rone_es=1/o.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}(o)&&(o.datum_type=4),o.geoc=!!o.es&&Y(s,"bgeoc"),o.over=Y(s,"bover"),o.has_geoid_vgrids=Y(s,"tgeoidgrids"),o.has_geoid_vgrids&&Y(s,"sgeoidgrids"),o.is_long_wrap_set=Y(s,"tlon_wrap"),o.is_long_wrap_set&&(o.long_wrap_center=Y(s,"rlon_wrap"),t(o.long_wrap_center)<10*P==0&&G(-14)),Y(s,"saxis")&&function(t){var e="ewnsud",i=Y(t.params,"saxis");3!=i.length&&G(z),-1!=e.indexOf(i[0])&&-1!=e.indexOf(i[1])&&-1!=e.indexOf(i[2])||G(z),t.axis=i}(o),o.lam0=Y(s,"rlon_0"),o.phi0=Y(s,"rlat_0"),o.x0=Y(s,"dx_0"),o.y0=Y(s,"dy_0"),Y(s,"tk_0")?o.k0=Y(s,"dk_0"):Y(s,"tk")?o.k0=Y(s,"dk"):o.k0=1,o.k0<=0&&G(-31),function(t){var e,i,r,n=t.params;(e=Y(n,"sunits"))&&((r=ut(e))||G(-7),i=r.to_meter),i||(i=Y(n,"sto_meter"))?(t.to_meter=yt(i),t.fr_meter=1/t.to_meter):t.to_meter=t.fr_meter=1,i=null,(e=Y(n,"svunits"))&&((r=ut(e))||G(-7),i=r.to_meter),i||Y(n,"svto_meter")?(t.vto_meter=yt(i),t.vfr_meter=1/t.vto_meter):(t.vto_meter=t.to_meter,t.vfr_meter=t.fr_meter)}(o),function(t){var e,i,r,n=t.params;(e=Y(n,"spm"))?(i=function(t){var e=ot.reduce(function(e,i){return i[0]===t?i:e},null);return e?{id:e[0],definition:e[1]}:null}(e),r=Z(i?i.definition:e),isNaN(r)&&G(-46),t.from_greenwich=r):t.from_greenwich=0}(o),n.init(o),o}function gt(t,e){var i=K(e),r=["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&&r||(t[e]=i[e])})}function yt(t){var e=t.split("/"),i=X(e[0]);return e.length>1&&(i/=X(e[1])),i}function vt(t,e){var i=0,r=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:r,b2:n,e2:(r-n)/r,ep2:(r-n)/n}}function xt(t,e,n,s,o){var a,l,c,u,p=0,d=n[e],f=s[e],m=o[e];return f<-E&&f>-1.001*E?f=-E:f>E&&f<1.001*E?f=E:(f<-E||f>E)&&(p|=1),p||(d>b&&(d-=2*b),l=i(f),u=r(f),c=l*l,a=t.a/h(1-t.e2*c),n[e]=(a+m)*u*r(d),s[e]=(a+m)*u*i(d),o[e]=(a*(1-t.e2)+m)*l),p}function bt(e,i,r,n,s){var o,a,u,p,d,f,m,_,g,y,v,x,b,w,S,T,C=1e-12,M=r[i],A=n[i],I=s[i];if(p=h(M*M+A*A),d=h(M*M+A*A+I*I),p/e.a<C){if(a=0,d/e.a<C)return r[i]=0,n[i]=E,s[i]=-e.b,0}else a=c(A,M);f=I/d,m=p/d,_=1/h(1-e.e2*(2-e.e2)*m*m),v=m*(1-e.e2)*_,x=f*_,T=0;do{T++,u=p*v+I*x-(g=e.a/h(1-e.e2*x*x))*(1-e.e2*x*x),y=e.e2*g/(g+u),S=(w=f*(_=1/h(1-y*(2-y)*m*m)))*v-(b=m*(1-y)*_)*x,v=b,x=w}while(S*S>1e-24&&T<30);o=l(w/t(b)),r[i]=a,n[i]=o,s[i]=u}function wt(t,e,i){var r=i.length>2,n=[i[0]],s=[i[1]],o=[r?i[2]:0];t.is_latlong&&(n[0]*=T,s[0]*=T),L.last_errno=0,St(t,e,n,s,o),(L.last_errno||n[0]==v)&&q(null,{point:i}),e.is_latlong&&(n[0]*=S,s[0]*=S),i[0]=n[0],i[1]=s[0],r&&(i[2]=o[0])}function St(t,e,i,r,n){var s,o,a=i.length,l={},c={};if("enu"!=t.axis&&Tt(t.axis,!1,i,r,n),1!=t.vto_meter&&n)for(s=0;s<a;s++)n[s]*=t.vto_meter;if(t.is_geocent){if(n||G(k),1!=t.to_meter)for(s=0;s<a;s++)i[s]!=v&&(i[s]*=t.to_meter,r[s]*=t.to_meter);Ct(t.a_orig,t.es_orig,i,r,n)}else if(!t.is_latlong)if(t.inv3d||t.inv||q("source projection not invertible"),t.inv3d)q("inverse 3d transformations not supported");else for(s=0;s<a;s++)c.x=i[s],c.y=r[s],o=It(c,t),i[s]=o.lam,r[s]=o.phi,B();if(0!==t.from_greenwich)for(s=0;s<a;s++)i[s]!=v&&(i[s]+=t.from_greenwich);if(t.has_geoid_vgrids&&n&&q("vgrid transformation not supported"),function(t,e,i,r,n){var s,o,a,l,c=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||Y(t.params,"snadgrids")==Y(e.params,"snadgrids")))}(t,e)||(s=t.a_orig,o=t.es_orig,a=e.a_orig,l=e.es_orig,n||(n=new Float64Array(c)),3==t.datum_type&&(q("gridshift not implemented"),s=C,o=M),3==e.datum_type&&(a=C,l=M),o==l&&s==a&&1!=t.datum_type&&2!=t.datum_type&&1!=e.datum_type&&2!=e.datum_type||(Mt(s,o,i,r,n),1!=t.datum_type&&2!=t.datum_type||function(t,e,i,r){var n,s,o,a,l,c,h,u,p=e.length,d=t.datum_params,f=d[0],m=d[1],_=d[2];if(1==t.datum_type)for(u=0;u<p;u++)e[u]!=v&&(e[u]+=f,i[u]+=m,r[u]+=_);else if(2==t.datum_type)for(a=d[3],l=d[4],c=d[5],h=d[6],u=0;u<p;u++)e[u]!=v&&(n=h*(e[u]-c*i[u]+l*r[u])+f,s=h*(c*e[u]+i[u]-a*r[u])+m,o=h*(-l*e[u]+a*i[u]+r[u])+_,e[u]=n,i[u]=s,r[u]=o)}(t,i,r,n),1!=e.datum_type&&2!=e.datum_type||function(t,e,i,r){var n,s,o,a,l,c,h,u,p=e.length,d=t.datum_params,f=d[0],m=d[1],_=d[2];if(1==t.datum_type)for(u=0;u<p;u++)e[u]!=v&&(e[u]-=f,i[u]-=m,r[u]-=_);else if(2==t.datum_type)for(a=d[3],l=d[4],c=d[5],h=d[6],u=0;u<p;u++)e[u]!=v&&(n=(e[u]-f)/h,s=(i[u]-m)/h,o=(r[u]-_)/h,e[u]=n+c*s-l*o,i[u]=-c*n+s+a*o,r[u]=l*n-a*s+o)}(e,i,r,n),Ct(a,l,i,r,n),3==e.datum_type&&pj_apply_gridshift_2(e,1,i,r,n))))}(t,e,i,r,n),e.has_geoid_vgrids&&n&&q("vgrid transformation not supported"),0!==e.from_greenwich)for(s=0;s<a;s++)i[s]!=v&&(i[s]-=e.from_greenwich);if(e.is_geocent){if(n||G(k),Mt(e.a_orig,e.es_orig,i,r,n),1!=e.fr_meter)for(s=0;s<a;s++)i[s]!=v&&(i[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<a;s++)if(i[s]!=v){for(;i[s]<e.long_wrap_center-b;)i[s]+=P;for(;i[s]>e.long_wrap_center+b;)i[s]-=P}}else if(e.fwd3d)q("3d transformation not supported");else for(s=0;s<a;s++)l.lam=i[s],l.phi=r[s],o=Et(l,e),i[s]=o.x,r[s]=o.y,B();if(1!=e.vto_meter&&n)for(s=0;s<a;s++)n[s]*=e.vfr_meter;return"enu"!=e.axis&&Tt(e.axis,!0,i,r,n),1==a?L.last_errno:0}function Tt(t,e,i,r,n){var s,o,a,l,c,h,u=i.length,p=0;if(e){for(a=0;a<u;a++)if(s=i[a],o=r[a],s!=v)for(n&&(p=n[a]),l=0;l<3;l++)if(2!=l||n)switch(h=0==l?i:1==l?r:n,t[l]){case"e":h[a]=s;break;case"w":h[a]=-s;break;case"n":h[a]=o;break;case"s":h[a]=-o;break;case"u":h[a]=p;break;case"d":h[a]=-p;break;default:G(z)}}else for(a=0;a<u;a++)if(s=i[a],o=r[a],s!=v)for(n&&(p=n[a]),l=0;l<3;l++)switch(c=0==l?s:1==l?o:p,t[l]){case"e":i[a]=c;break;case"w":i[a]=-c;break;case"n":r[a]=c;break;case"s":r[a]=-c;break;case"u":n&&(n[a]=c);break;case"d":n&&(n[a]=-c);break;default:G(z)}}function Ct(t,e,i,r,n){var s,o,a=i.length;for((o=vt(t,0==e?t:t*h(1-e)))||G(k),s=0;s<a;s++)i[s]!=v&&bt(o,s,i,r,n)}function Mt(t,e,i,r,n){var s,o,a=i.length;for((o=vt(t,0===e?t:t*h(1-e)))||G(k),s=0;s<a;s++)i[s]!=v&&xt(o,s,i,r,n)&&(i[s]=r[s]=v)}function At(i){var r=6.283185307179586,n=3.141592653589793;return t(i)>3.14159265359&&(i+=n,i-=r*e(i/r),i-=n),i}function Et(e,i){var r={x:0,y:0},s=t(e.phi)-E;return s<=1e-12&&t(e.lam)<=10?(L.last_errno=0,t(s)<=1e-12?e.phi=e.phi<0?-E:E:i.geoc&&(e.phi=l(i.rone_es*n(e.phi))),e.lam-=i.lam0,i.over||(e.lam=At(e.lam)),i.fwd?(i.fwd(e,r),r.x=i.fr_meter*(i.a*r.x+i.x0),r.y=i.fr_meter*(i.a*r.y+i.y0)):r.x=r.y=v):N(-14),!L.last_errno&&isFinite(r.x)&&isFinite(r.y)||(r.x=r.y=v),r}function It(e,i){var r={lam:0,phi:0};return e.x<v&&e.y<v?(L.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,r),r.lam+=i.lam0,i.over||(r.lam=At(r.lam)),i.geoc&&t(t(r.phi)-E)>1e-12&&(r.phi=l(i.one_es*n(r.phi)))):r.lam=r.phi=v):N(-15),!L.last_errno&&isFinite(r.lam)&&isFinite(r.phi)||(r.lam=r.phi=v),r}function Pt(t,i,r,n){var s,o,a;for((t<0||t>=9)&&(t=3),s=1,a=0;a<t;a++)s*=10;return o=3600*s,function(a){var l,c,h,u,p="",d="",f="";return a===v||isNaN(a)?"":(a<0?(a=-a,(h=n||"")||(p="-")):h=r||"",c=(a=e(a*o+.5))/s%60,l=(a=e(a/(60*s)))%60,u=e(a/60)+"d",f=c.toFixed(t),f=(c=parseFloat(f))?(i?f:String(c))+'"':"",(c||l)&&2==(d=String(l)+"'").length&&i&&(d="0"+d),p+u+d+f+h)}}function Dt(t,e,i){var r,n,s,o,a,l;return"string"!=typeof t?ki:("string"!=typeof e?(n="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs",s=t,r=e):(n=t,s=e,r=i),l=kt(o=_t(n),a=_t(s)),r?l(r):{forward:l,inverse:kt(a,o)})}function kt(t,e){return function(i){var r=Array.isArray(i);return i=r?i.concat():[i.x,i.y],wt(t,e,i),r||(i={x:i[0],y:i[1]}),i}}function zt(t){var e=t.proj in Q?Q[t.proj].name:"",i=rt(t),r=Jt(t);return{PROJCS:{NAME:e?r.NAME+" / "+e:"unnamed",GEOGCS:r,PROJECTION:"custom_proj4",PARAMETER:[],UNIT:Zt(t),EXTENSION:["PROJ4",i+" +wktext"]}}}function Rt(t){var e=t.EXTENSION;return e&&"PROJ4"==e[0]?(e[1]||"").replace(" +wktext",""):null}Dt.WGS84="+proj=longlat +datum=WGS84",Dt.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 Lt=[],Ft=[];function Bt(t){return"string"==typeof t}function Ot(t){var e=Vt(t,Ft);return e||(e=function(t){return Rt(t)?Rt:null}(t)),e||qt("unsupported WKT definition: "+(t.NAME||"[unknown]")),e}function Nt(t){var e=Vt(t,Lt);return e||(e=zt),e||qt("unsupported projection: "+function(t){return jt(t)||"[unknown]"}(t)),e}function Vt(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 Y(t.params,"sproj")}function Gt(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 qt(t){throw new Error(t)}function $t(t){return{to_meter:t.UNIT[1]}}function Zt(t){return["Meter",t.to_meter||1]}function Wt(t,e){var i,r,n=t.DATUM,s=n.SPHEROID,o=function(t){var e,i={northamerican1983:"NAD83",newzealand1949:"nzgd49"},r=Ht(t.NAME);if(r in i)return i[r];for(var n=0;n<st.length&&Ht((e=st[n])[3])!=r&&Ht(e[0])!=r;n++);return e?e[0]:null}(n),a=function(t){var e,i={international1924:"intl"},r=Ht(t[0]);if(r in i)return i[r];if(/^grs1980/.test(r))return"GRS80";if("sphere"==r)return null;for(var n=0;n<lt.length&&Ht((e=lt[n])[3])!=r&&Ht(e[0])!=r;n++);return e?e[0]:null}(s),l=e&&e.aux_sphere,c=s[1],h=s[2];return Xt(t.UNIT,"degree"),l?i="+a="+s[1]:o?i="+datum="+o:a?i="+ellps="+a:(i="+a="+c,h>0&&(i+=" +rf="+h)),!n.TOWGS84||l||o||(i+=" +towgs84="+n.TOWGS84.join(",")),((r=t.PRIMEM?t.PRIMEM[1]:0)>0||r<0)&&(i+=" +pm="+r),i}function Ht(t){return(t||"").replace(/^(GCS|D)_/i,"").replace(/[ _]/g,"").toLowerCase()}function Xt(t,e){t&&t[0].toLowerCase()!=e&&qt("unexpected geographic units: "+geogcs.UNIT[0])}function Yt(t){return function(){return"+proj="+t}}function Kt(t){return function(e){var i,r;return[t.PROJECTION(e),t.PARAMETER(e),t.GEOGCS?t.GEOGCS(e):Wt(e.GEOGCS),(i=$t(e),r="",1!=i.to_meter&&(r="+to_meter="+i.to_meter),r),"+no_defs"].filter(function(t){return!!t}).join(" ")}}function Jt(t){return{NAME:ee(t),DATUM:Qt(t),PRIMEM:["Greenwich",0],UNIT:["degree",.017453292519943295]}}function Qt(t){var e={NAME:re(t),SPHEROID:te(t)},i=Y(t.params,"stowgs84");return/[1-9]/.test(i)&&(e.TOWGS84=i),e}function te(t){var e;return e=Y(t.params,"trf")?Y(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=le(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=ct(function(t){var e=ne(t),i=e?at(e):null;return(i?i.ellipse_id:Y(t.params,"sellps"))||""}(t));return e?e.name:"Unknown ellipsoid"}function re(t){var e=at(ne(t));return e&&e.name||"Unknown datum"}function ne(t){return Y(t.params,"sdatum")}function se(t){return Nt(t)(t)}function oe(t,e){return ae({PROJECTION:t,PARAMETER:De(e)})}function ae(t){return function(e){var i={GEOGCS:t.GEOGCS&&t.GEOGCS(e)||Jt(e),PROJECTION:Bt(t.PROJECTION)?t.PROJECTION:t.PROJECTION(e),PARAMETER:t.PARAMETER(e),UNIT:Zt(e)};return i.NAME=t.NAME&&t.NAME(e,i)||function(t,e){var i=le(t);return i||e.GEOGCS.NAME+" / "+e.PROJECTION}(e,i),{PROJCS:i}}}function le(t){var e;return Y(t.params,"tinit")&&(e=mt(Y(t.params,"sinit"))),e?e.comment:""}function ce(t,e,i){var r=ue(e),n=function(t,e){return Kt({PROJECTION:Yt(t),PARAMETER:Pe(e)})}(t,i);de(r,n)}function he(t,e,i){fe(pe(t),oe(e,i))}function ue(t){var e=Ut(t).map(Gt);return function(t){var i=t.PROJECTION[0];return e.indexOf(Gt(i))>-1}}function pe(t){return function(e){var i=jt(e);return i&&i==t}}function de(t,e){"function"!=typeof t&&qt("Missing WKT parser test"),"function"!=typeof e&&qt("Missing WKT parse function"),Ft.push([t,e])}function fe(t,e){"function"!=typeof t&&qt("Missing WKT maker test"),"function"!=typeof e&&qt("Missing WKT maker function"),Lt.push([t,e])}de(function(t){return me.test(Gt(t.NAME))},function(t){return Kt({PROJECTION:Yt("utm"),PARAMETER:function(t){var e=me.exec(Gt(t.NAME)),i="+zone="+e[1];return"s"==e[2].toLowerCase()&&(i+=" +south"),i}})(t)}),de(function(t){return _e.test(Gt(t.NAME))},function(t){return Kt({PROJECTION:Yt("ups"),PARAMETER:function(t){var e=_e.exec(Gt(t.NAME));return"south"==e[1].toLowerCase()?"+south":""}})(t)}),fe(pe("utm"),function(t){return ae({NAME:ge,PROJECTION:function(){return"Transverse_Mercator"},PARAMETER:ve})(t)}),fe(pe("ups"),function(t){return ae({NAME:ye,PROJECTION:function(){return"Polar_Stereographic"},PARAMETER:xe})(t)});var me=/UTM_zone_([0-9]{1,2})(N|S)/i,_e=/UPS_(North|South)/i;function ge(t,e){return e.GEOGCS.NAME+" / UTM zone "+Y(t.params,"szone")+(Y(t.params,"tsouth")?"S":"N")}function ye(t,e){return e.GEOGCS.NAME+" / UPS "+(Y(t.params,"tsouth")?"South":"North")}function ve(t){return[["latitude_of_origin",0],["central_meridian",180*t.lam0/b],["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 Y(t.params,"tlat_ts")&&0!=Y(t.params,"dlat_ts")}function we(t){return 0===t.es&&6378137==t.a}de(ue("Mercator_2SP,Mercator_1SP,Mercator,Mercator_Auxiliary_Sphere"),Kt({GEOGCS:function(t){var e=function(t){return/(Web_Mercator|Pseudo_Mercator)/i.test(Gt(t.NAME))}(t)?{aux_sphere:!0}:null;return Wt(t.GEOGCS,e)},PROJECTION:Yt("merc"),PARAMETER:function(t){return Pe(function(t){var e=Ee(t,"standard_parallel_1");return e&&0!=e[1]}(t)?"lat_ts,lat_0b":"lat_tsb,lat_ts")(t)}})),fe(pe("merc"),ae({GEOGCS:function(t){return we(t)?Jt(_t("+proj=longlat +datum=WGS84")):null},PROJECTION:function(t){return be(t)?"Mercator_2SP":"Mercator_1SP"},PARAMETER:function(t){return De(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"]],Te={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"]},Ce={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 Me(t,e,i){for(var r=0;r<i.length;r++)if(i[r][e]===t)return i[r];return null}function Ae(t,e,i){var r=null;return!(r=Me(t=t.toLowerCase(),e,i))&&t in Ce&&(r=Me(Ce[t],e,i)),r}function Ee(t,e){for(var i,r=t.PARAMETER||[],n=0;n<r.length;n++)if(e===(i=r[n][0].toLowerCase())||e===Ce[i])return r[n];return null}function Ie(t){var e=null;return t&&(e=Ut(t).reduce(function(t,e){var i=Te[e];return i||qt("missing parameter rule: "+e),t.push(i),t},[])),(e||[]).concat(Se)}function Pe(t){return function(e){var i=[],r=Ie(t),n=$t(e);return(e.PARAMETER||[]).forEach(function(t){var e,s,o=Ae(t[0],1,r);o?(e=function(t,e,i){var r=t[0];if("m"==t[2]&&(e*=i.to_meter),!("x_0,y_0,lat_0,lon_0".indexOf(r)>-1&&0===e||"k_0"==r&&1==e))return"+"+r+"="+e}(o,t[1],n),e&&i.push(e)):(s="unhandled parameter: "+t[0],console.error("[wkt] "+s))}),i.join(" ")}}function De(t){return function(e){var i=[],r=Ie(t);return Object.keys(e.params).forEach(function(t){var n,s=Ae(t,0,r);s&&s[1]&&(n=Y(e.params,"s"+t),i.push(function(t,e,i){var r,n=t[2];return r="m"==n?parseFloat(e)/i:"f"==n?parseFloat(e):W(e),[t[1],r]}(s,n,e.to_meter)))}),i}}function ke(t){return!("lat_1"in t.params&&"lat_2"in t.params)}function ze(t){return"omerc"==jt(t)&&("alpha"in t.params||"gamma"in t.params)}function Re(t){return ze(t)&&("no_uoff"in t.params||"no_off"in t.params)}function Le(t){return Y(t.params,"tlat_ts")}function Fe(t){var e=JSON.stringify(Oe(t));return e=(e=e.replace(/\["([A-Z0-9]+)",/g,"$1[")).replace(/"(EAST|NORTH|SOUTH|WEST)"/g,"$1")}function Be(t){return"NAME,PROJCS,GEOGCS,GEOCCS,DATUM,SPHEROID,PRIMEM,PROJECTION,PARAMETER,UNIT,AXIS".indexOf(t)+1||999}function Oe(t,e){var i,r=[];return e=e||0,function(t){return Object.keys(t).sort(function(t,e){return Be(t)-Be(e)})}(t).forEach(function(n){var s=t[n];!function(t){return!!t&&"object"==typeof t&&!Array.isArray(t)}(s)?"NAME"==n?r.push(Bt(s)?s:s[0]):"PARAMETER"==n||"AXIS"==n?s.forEach(function(t){r.push([n].concat(t))}):Bt(s)?r.push([n,s]):Array.isArray(s)?r.push([n].concat(s)):((i={})[n]=s,qt("Incorrectly formatted WKT element: "+JSON.stringify(i))):r.push([n].concat(Oe(s,e+1)))}),0===e&&1==r.length&&(r=r[0]),r}function Ne(t){var e={};return Ve(t).forEach(function(t){Ge(t,e)}),e}function Ve(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){qt("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 Ge(t,e){var i,r=t[0];if("GEOGCS"==r||"GEOCCS"==r||"PROJCS"==r||"DATUM"==r||"VERTCS"==r)for(e[r]={NAME:t[1]},i=2;i<t.length;i++){if(!Array.isArray(t[i]))throw qt("WKT parse error");Ge(t[i],e[r])}else"AXIS"==r||"PARAMETER"==r?(r in e==0&&(e[r]=[]),e[r].push(t.slice(1))):e[r]=t.slice(1);return e}de(ue("Lambert_Conformal_Conic,Lambert_Conformal_Conic_1SP,Lambert_Conformal_Conic_2SP"),Kt({PROJECTION:Yt("lcc"),PARAMETER:function(t){return Pe(function(t){return!Ee(t,"standard_parallel_2")}(t)?"lat_1c":"lat_0b,lat_1,lat_2")(t)}})),fe(pe("lcc"),ae({PROJECTION:function(t){return ke(t)?"Lambert_Conformal_Conic_1SP":"Lambert_Conformal_Conic_2SP"},PARAMETER:function(t){return De(ke(t)?"lat_1c,lat_0c":"lat_0b,lat_1,lat_2")(t)}})),de(ue("Hotine_Oblique_Mercator,Hotine_Oblique_Mercator_Azimuth_Natural_Origin"),Kt({PROJECTION:Yt("omerc"),PARAMETER:function(t){return Pe("alpha,gamma,lonc")(t)+" +no_uoff"}})),fe(Re,oe("Hotine_Oblique_Mercator","alpha,gamma,lonc")),ce("omerc","Oblique_Mercator,Hotine_Oblique_Mercator_Azimuth_Center","alpha,gamma,lonc"),fe(function(t){return ze(t)&&!Re(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"==jt(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(ue("Stereographic,Polar_Stereographic,Stereographic_North_Pole,Stereographic_South_Pole"),Kt({PROJECTION:Yt("stere"),PARAMETER:function(t){var e=Pe("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}})),fe(pe("stere"),ae({PROJECTION:function(t){return Le(t)?"Polar_Stereographic":"Stereographic"},PARAMETER:function(t){return Le(t)?De("lat_tsb,lat_0c")(t):De("lat_0b")(t)}})),he("vandg","VanDerGrinten"),de(ue("VanDerGrinten,Van_der_Grinten_I"),Kt({PROJECTION:Yt("vandg"),PARAMETER:function(t){var e=Pe("")(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),he(t[0],t[1].split(",")[0],e)});var Ue,qe,$e={};function Ze(t,e,i){var r;return e>=1e-7?i*(t/(1-(r=e*t)*r)-.5/e*d((1-r)/(1+r))):t+t}function We(t,e,i){return e/h(1-i*t*t)}function He(e,n,o){var a,l,u,p,m,_,g,y,x,b,w,S,T,C;e.fwd=function(t,n){var s,o=t.lam;(s=u-(g?l*Ze(i(t.phi),e.e,e.one_es):m*i(t.phi)))<0&&V(),s=p*h(s),n.x=s*i(o*=l),n.y=_-s*r(o)},e.inv=function(n,o){var h=n.x,y=_-n.y,x=f(h,y);0!=x?(l<0&&(x=-x,h=-h,y=-y),o.phi=x/p,g?(o.phi=(u-o.phi*o.phi)/l,t(a-t(o.phi))>1e-7?(o.phi=function(e,n,o){var a,l,c,h,u,p,f=15,m=1e-7,_=1e-10;if(a=s(.5*e),n<m)return a;p=f;do{a+=u=.5*(h=1-(c=n*(l=i(a)))*c)*h/r(a)*(e/o-l/h+.5/n*d((1-c)/(1+c)))}while(t(u)>_&&--p);return p?a:v}(o.phi,e.e,e.one_es))==v&&j():o.phi=o.phi<0?-E:E):t(o.phi=(u-o.phi*o.phi)/m)<=1?o.phi=s(o.phi):o.phi=o.phi<0?-E:E,o.lam=c(h,y)/l):(o.lam=0,o.phi=l>0?E:-E)},t(n+o)<R&&U(-21),l=x=i(n),y=r(n),b=t(n-o)>=R,(g=e.es>0)?(Xe(e.es),C=We(x,y,e.es),T=Ze(x,e.e,e.one_es),b&&(S=We(x=i(o),y=r(o),e.es),w=Ze(x,e.e,e.one_es),l=(C*C-S*S)/(w-T)),a=1-.5*e.one_es*d((1-e.e)/(1+e.e))/e.e,_=(p=1/l)*h((u=C*C+l*T)-l*Ze(i(e.phi0),e.e,e.one_es))):(b&&(l=.5*(l+i(o))),_=(p=1/l)*h((u=y*y+(m=l+l)*x)-m*i(e.phi0)))}function Xe(t){var e,i=.046875,r=.01953125,n=.01068115234375,s=[];return s[0]=1-t*(.25+t*(i+t*(r+t*n))),s[1]=t*(.75-t*(i+t*(r+t*n))),s[2]=(e=t*t)*(.46875-t*(.013020833333333334+.007120768229166667*t)),s[3]=(e*=t)*(.3645833333333333-.005696614583333333*t),s[4]=e*t*.3076171875,s}function Ye(t,e,i,r){return i*=e,e*=e,r[0]*t-i*(r[1]+e*(r[2]+e*(r[3]+e*r[4])))}function Ke(e,n,s){var o,a,l,c=1/(1-n);l=e;for(var u=10;u>0;--u)if(a=1-n*(o=i(l))*o,l-=a=(Ye(l,o,r(l),s)-e)*(a*h(a))*c,t(a)<1e-11)return l;return N(L),l}function Je(e){var i=t(e);return i>=1?(i>1.00000000000001&&N(-19),e<0?-E:E):s(e)}function Qe(e){var i=t(e);return i>=1?(i>1.00000000000001&&N(-19),e<0?b:0):a(e)}function ti(t){return t<=0?0:h(t)}function ei(e,i){return t(e)<1e-50&&t(i)<1e-50?0:c(e,i)}function ii(e){var n=e.opaque||{mode:0};e.inv=function(e,s){var o,l,c,h,p,d,f,m,_,g,y,v,x,w,S,T,C,M=1e-12,A=0;if(t(e.x)<M&&t(e.y)<M)return s.phi=0,void(s.lam=0);s.phi=e.y,s.lam=e.x;do{o=0;do{for(v=i(.5*s.lam),S=r(.5*s.lam),x=i(s.phi),c=1-(l=(w=r(s.phi))*S)*l,h=2*(l=a(l)/u(c,1.5))*c*w*v,p=l*c*x,d=2*(v*S*x*w/c-l*x*v),f=w*w*v*v/c+l*w*S*x*x,m=x*x*S/c+l*v*v*w,_=.5*(x*w*v/c-l*x*w*w*v*S),n.mode&&(h=.5*(h+s.lam*n.cosphi1),p=.5*(p+s.phi),d*=.5,f=.5*(f+n.cosphi1),m=.5*(m+1),_*=.5),h-=e.x,y=((p-=e.y)*d-h*m)/(g=d*_-m*f),g=(h*_-p*f)/g;y>b;)y-=b;for(;y<-b;)y+=b;s.phi-=g,s.lam-=y}while((t(g)>M||t(y)>M)&&o++<10);s.phi>E&&(s.phi-=2*(s.phi-E)),s.phi<-E&&(s.phi-=2*(s.phi+E)),t(t(s.phi)-E)<M&&!n.mode&&(s.lam=0),(l=a(r(s.phi)*r(c=.5*s.lam)))?(T=2*l*r(s.phi)*i(c)*(C=1/i(l)),C*=l*i(s.phi)):T=C=0,n.mode&&(T=.5*(T+s.lam*n.cosphi1),C=.5*(C+s.phi))}while((t(e.x-T)>M||t(e.y-C)>M)&&A++<20)},e.fwd=function(t,e){var s,o;(o=a(r(t.phi)*r(s=.5*t.lam)))?(e.x=2*o*r(t.phi)*i(s)*(e.y=1/i(o)),e.y*=o*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 ri(e,r,n){e.es=0,e.fwd=function(e,s){var o,a,l=2.4674011002723395;s.y=r?E*i(e.phi):e.phi,(o=t(e.lam))>=1e-10?(n&&o>=E?s.x=h(l-e.phi*e.phi+1e-10)+o-E:(a=.5*(l/o+o),s.x=o-a+h(a*a-s.y*s.y)),e.lam<0&&(s.x=-s.x)):s.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 si(t,e){var r=t+t;return t+e[0]*i(r)+e[1]*i(r+r)+e[2]*i(r+r+r)}function oi(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 ai(e){var s,o,a,u,p,g,y=[],x=[],b=[],w=[];function S(t,e){for(var n,s=2*r(2*e),o=t.length-1,a=t[o],l=0;--o>=0;)n=s*a-l+t[o],l=a,a=n;return e+n*i(2*e)}function T(t,e,n){for(var s,o,a=i(e),l=r(e),c=m(n),h=_(n),u=2*l*h,p=-2*a*c,d=t.length-1,f=t[d],g=0,y=0,v=0;--d>=0;)s=y,o=g,f=u*(y=f)-s-p*(g=v)+t[d],v=p*y-o+u*g;return[(u=a*h)*f-(p=l*c)*v,u*v+p*f]}e.es<=0&&U(-34),p=u=(a=e.es/(1+h(1-e.es)))/(2-a),y[0]=u*(2+u*(-2/3+u*(u*(116/45+u*(26/45+u*(-2854/675)))-2))),x[0]=u*(u*(2/3+u*(4/3+u*(-82/45+u*(32/45+u*(4642/4725)))))-2),p*=u,y[1]=p*(7/3+u*(u*(-227/45+u*(2704/315+u*(2323/945)))-1.6)),x[1]=p*(5/3+u*(-16/15+u*(-13/9+u*(904/315+u*(-1522/945))))),p*=u,y[2]=p*(56/15+u*(-136/35+u*(-1262/105+u*(73814/2835)))),x[2]=p*(-26/15+u*(34/21+u*(1.6+u*(-12686/2835)))),p*=u,y[3]=p*(4279/630+u*(-332/35+u*(-399572/14175))),x[3]=p*(1237/630+u*(u*(-24832/14175)-2.4)),p*=u,y[4]=p*(4174/315+u*(-144838/6237)),x[4]=p*(-734/315+u*(109598/31185)),p*=u,y[5]=p*(601676/22275),x[5]=p*(444337/155925),p=u*u,s=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,g=S(x,e.phi0),o=-s*(g+function(t,e){for(var n,s=2*r(e),o=t.length-1,a=t[o],l=0;--o>=0;)n=s*a-l+t[o],l=a,a=n;return i(e)*n}(w,2*g)),e.fwd=function(e,a){var l,h,u,p,m,_=e.phi,g=e.lam;_=S(x,_),l=i(_),h=r(_),p=i(g),u=r(g),_=c(l,u*h),g=c(p*h,f(l,h*u)),g=function(e){var i=t(e);return i=function(t){var e=1+t,i=e-1;return 0===i?t:t*d(e)/i}(i*(1+i/(f(1,i)+1))),e<0?-i:i}(n(g)),m=T(w,2*_,2*g),_+=m[0],g+=m[1],t(g)<=2.623395162778?(a.y=s*_+o,a.x=s*g):a.x=a.y=v},e.inv=function(e,n){var a,h,u,p,d,_=e.y,g=e.x;_=(_-o)/s,t(g/=s)<=2.623395162778?(_+=(d=T(b,2*_,2*g))[0],g+=d[1],g=l(m(g)),a=i(_),h=r(_),p=i(g),u=r(g),g=c(p,u*h),_=c(a*u,f(p,u*h)),n.phi=S(y,_),n.lam=g):n.phi=n.lam=v}}function li(e){var n;e.es?(n=Xe(e.es),e.fwd=function(t,s){var o,a;s.y=Ye(t.phi,o=i(t.phi),a=r(t.phi),n),s.x=t.lam*a/h(1-e.es*o*o)},e.inv=function(s,o){var a=t(o.phi=Ke(s.y,e.es,n));a<E?(a=i(o.phi),o.lam=s.x*h(1-e.es*a*a)/r(o.phi)):a-R<E?o.lam=0:j()}):ci(e,0,1)}function ci(e,n,s){var o,a;o=(a=h((n+1)/s))/(n+1),e.es=0,e.fwd=function(e,l){var c,h,u;if(n){for(c=s*i(e.phi),u=8;u&&(e.phi-=h=(n*e.phi+i(e.phi)-c)/(n+r(e.phi)),!(t(h)<1e-7));--u);u||V()}else e.phi=1!=s?Je(s*i(e.phi)):e.phi;l.x=o*e.lam*(n+r(e.phi)),l.y=a*e.phi},e.inv=function(t,e){t.y/=a,e.phi=n?Je((n*t.y+i(t.y))/s):1!=s?Je(i(t.y)/s):t.y,e.lam=t.x/(o*(n+r(t.y)))}}function hi(t){pi(t,ui(0,E))}function ui(t,e){var r=i(e),n=e+e,s=h(P*r/(n+i(n)));return{C_x:2*s/b,C_y:s/r,C_p:n+i(n)}}function pi(e,n){e.fwd=function(e,s){var o,a,l;for(o=n.C_p*i(e.phi),l=10;l&&(e.phi-=a=(e.phi+i(e.phi)-o)/(1+r(e.phi)),!(t(a)<1e-7));--l);l?e.phi*=.5:e.phi=e.phi<0?-E:E,s.x=n.C_x*e.lam*r(e.phi),s.y=n.C_y*i(e.phi)},e.inv=function(e,s){s.phi=Je(e.y/n.C_y),s.lam=e.x/(n.C_x*r(s.phi)),t(s.lam)-b<R?(s.phi+=s.phi,s.phi=Je((s.phi+i(s.phi))/n.C_p)):s.lam=s.phi=v},e.es=0}function di(r,n){var o,a,l,c,p,d=[[0,-1],[1,0]],f=[[-1,0],[0,-1]],m=[[0,1],[-1,0]],_=[[[1,0],[0,1]],d,f,m,m,f,d],x=1e-15;function w(r,n){var o=r.lam,a=r.phi,l=s(2/3);if(t(a)<=l)n.x=o,n.y=3*b/8*i(a);else{var c,u=h(3*(1-t(i(a)))),p=e(2*o/b+2);p>=4&&(p=3),c=-3*A+E*p,n.x=c+(o-c)*u,n.y=T(a)*A*(2-u)}}function S(i,r){var n=i.x,o=i.y,a=A;if(t(o)<=a)r.lam=n,r.phi=s(8*o/(3*b));else if(t(o)<E){var l,c,h=e(2*n/b+2);h>=4&&(h=3),l=-3*A+E*h,c=2-4*t(o)/b,r.lam=l+(n-l)/c,r.phi=T(o)*s(1-u(c,2)/3)}else r.lam=-b,r.phi=T(o)*E}function T(t){return t>0?1:t<0?-1:0}function C(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,i){var r,n,s,o,a,l=0,c=t.length;for(a=0;a<c;a++)if(e==t[a][0]&&i==t[a][1])return!0;for(r=t[0][0],n=t[0][1],a=1;a<c;a++)s=t[a%c][0],o=t[a%c][1],i>g(n,o)&&i<=y(n,o)&&e<=y(r,s)&&n!=o&&(r==s||e<=(i-n)*(s-r)/(o-n)+r)&&l++,r=s,n=o;return l%2!=0}(p,t,e)}function I(e,r,n){if(n)return si(r,c);var o=Ze(i(r),e.e,1-e.es)/l;return t(o)>1&&(o=T(o)),s(o)}function P(t,e,i,r){var n,s,o,a,l,c,h=0,u=function(t,e,i,r,n){var s,o={};if(o.x=t,o.y=e,n){if(e>A)o.region="north",o.x=-3*A+i*E,o.y=E,t-=i*E;else{if(!(e<-A))return o.region="equatorial",o.cn=0,o;o.region="south",o.x=-3*A+r*E,o.y=-E,t-=r*E}"north"==o.region?o.cn=e>=-t-A-x&&e<t+5*A-x?(i+1)%4:e>-t-A+x&&e>=t+5*A-x?(i+2)%4:e<=-t-A+x&&e>t+5*A+x?(i+3)%4:i:"south"==o.region&&(o.cn=e<=t+A+x&&e>-t-5*A+x?(r+1)%4:e<t+A-x&&e<=-t-5*A+x?(r+2)%4:e>=t+A-x&&e<-t-5*A-x?(r+3)%4:r)}else{if(e>A)o.region="north",s=E;else{if(!(e<-A))return o.region="equatorial",o.cn=0,o;o.region="south",s=-E}t<-E?(o.cn=0,o.x=-3*A,o.y=s):t>=-E&&t<0?(o.cn=1,o.x=-A,o.y=s):t>=0&&t<E?(o.cn=2,o.x=A,o.y=s):(o.cn=3,o.x=3*A,o.y=s)}return o}(t.x,t.y,e,i,r);if("equatorial"==u.region)return t.x=u.x,void(t.y=u.y);n=[t.x,t.y],s=[u.x,u.y],r?"north"==u.region?(h=e,c=_[C(-1*(u.cn-h))]):(h=i,c=_[C(u.cn-h)]):"north"==u.region?(h=e,c=_[C(u.cn-h)]):(h=i,c=_[C(-1*(u.cn-h))]),a=function(t,e){return[t[0]-e[0],t[1]-e[1]]}(n,s),l=function(t,e){var i,r,n=[0,0];for(i=0;i<2;i++)for(r=0;r<2;r++)n[i]+=t[i][r]*e[r];return n}(c,a),o=function(t,e){return[t[0]+e[0],t[1]+e[1]]}(l,[-3*A+(r?u.cn:0)*E,E]),t.x=o[0],t.y=o[1]}n?(o=Y(r.params,"inorth_square"),a=Y(r.params,"isouth_square"),(o<0||o>3)&&U(-47),(a<0||a>3)&&U(-47),p=[[-b-x,A+x],[o*E-b-x,A+x],[o*E-b-x,3*A+x],[(o+1)*E-b+x,3*A+x],[(o+1)*E-b+x,A+x],[b+x,A+x],[b+x,-A-x],[(a+1)*E-b+x,-A-x],[(a+1)*E-b+x,-3*A-x],[a*E-b-x,-3*A-x],[a*E-b-x,-A-x],[-b-x,-A-x]],0!=r.es?(c=ni(r.es),l=Ze(1,r.e,r.one_es),r.a=r.a*h(.5*l),r.ra=1/r.a,r.fwd=function(t,e){return t.phi=I(r,t.phi,0),w(t,e),P(e,o,a,0)},r.inv=function(t,e){if(!M(t.x,t.y))return e.lam=v,e.phi=v,void N(-15);P(t,o,a,1),S(t,e),e.phi=I(r,e.phi,1)}):(r.fwd=function(t,e){w(t,e),P(e,o,a,0)},r.inv=function(t,e){if(!M(t.x,t.y))return e.lam=v,e.phi=v,void N(-15);P(t,o,a,1),S(t,e)})):(p=[[-b-x,A],[-3*A,E+x],[-E,A+x],[-A,E+x],[0,A+x],[A,E+x],[E,A+x],[3*A,E+x],[b+x,A],[b+x,-A],[3*A,-E-x],[E,-A-x],[A,-E-x],[0,-A-x],[-A,-E-x],[-E,-A-x],[-3*A,-E-x],[-b-x,-A]],0!=r.es?(c=ni(r.es),l=Ze(1,r.e,r.one_es),r.a=r.a*h(.5*l),r.ra=1/r.a,r.fwd=function(t,e){t.phi=I(r,t.phi,0),w(t,e)},r.inv=function(t,e){if(!M(t.x,t.y))return e.lam=v,e.phi=v,void N(-15);S(t,e),e.phi=I(r,e.phi,1)}):(r.fwd=function(t,e){w(t,e)},r.inv=function(t,e){if(!M(t.x,t.y))return e.lam=v,e.phi=v,void N(-15);S(t,e)}))}function fi(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 mi(t,e,i){return e*=i,n(.5*(E-t))/u((1-e)/(1+e),.5*i)}function _i(e,r){var n,s,o=.5*r,a=E-2*l(e),c=15;do{n=r*i(a),a+=s=E-2*l(e*u((1-n)/(1+n),o))-a}while(t(s)>1e-10&&--c);return c<=0&&N(-18),a}function gi(t,e){var i,r,n,s=e.length-1;for(r=e[s][0],n=e[s][1];--s>=0;)i=r,r=e[s][0]+t.r*i-t.i*n,n=e[s][1]+t.r*n+t.i*i;return{r:t.r*r-t.i*n,i:t.r*n+t.i*r}}function yi(t,e,i){var r,n,s,o,a,l=!0,c=e.length-1;for(n=o=e[c][0],r=s=e[c][1];--c>=0;)l?l=!1:(o=n+t.r*(a=o)-t.i*s,s=r+t.r*s+t.i*a),n=e[c][0]+t.r*(a=n)-t.i*r,r=e[c][1]+t.r*r+t.i*a;return i.r=n+t.r*o-t.i*s,i.i=r+t.r*s+t.i*o,{r:t.r*n-t.i*r,i:t.r*r+t.i*n}}function vi(e,s){var o,a,h,p,d=1e-12;0!=e.es?(o=e.e*i(e.phi0),a=2*l(n(.5*(E+e.phi0))*u((1-o)/(1+o),.5*e.e))-E):a=e.phi0,p=i(a),h=r(a),e.inv=function(o,a){var m,_,g,y,x,b,w,S={},T={},C={},M=0,A=0,I=0,P=0;for(S.r=o.x,S.i=o.y,m=20;m&&((_=yi(S,s,T)).r-=o.x,_.i-=o.y,g=T.r*T.r+T.i*T.i,C.r=-(_.r*T.r+_.i*T.i)/g,C.i=-(_.i*T.r-_.r*T.i)/g,S.r+=C.r,S.i+=C.i,!(t(C.r)+t(C.i)<=d));--m);if(m){if(M=f(S.r,S.i),y=2*l(.5*M),A=i(y),I=r(y),a.lam=e.lam0,t(M)<=d)return a.lam=0,void(a.phi=e.phi0);for(P=x=Je(I*p+S.i*A*h/M),m=20;m&&(b=e.e*i(P),P+=w=2*l(n(.5*(E+x))*u((1+b)/(1-b),.5*e.e))-E-P,!(t(w)<=d));--m);}m?(a.phi=P,a.lam=c(S.r*A,M*h*I-S.i*p*A)):a.lam=a.phi=v},e.fwd=function(t,o){var a,c,d,f,m,_,g,y={};a=i(t.lam),c=r(t.lam),d=e.e*i(t.phi),f=2*l(n(.5*(E+t.phi))*u((1-d)/(1+d),.5*e.e))-E,m=i(f),_=r(f),g=2/(1+p*m+h*_*c),y.r=g*_*a,y.i=g*(h*m-p*_*c),y=gi(y,s),o.x=y.r,o.y=y.i}}function xi(e,n,o,a){var l,u,p,d,m,_,g,y,v,x,b,w,S=!isNaN(o)&&!isNaN(a);n<=0&&U(-30),S&&(v=r(a),x=i(a),w=r(o),b=i(o)),t(t(e.phi0)-E)<R?l=e.phi0<0?1:0:t(e.phi0)<R?l=2:(l=3,u=i(e.phi0),p=r(e.phi0)),_=n/e.a,m=1/(d=1+_),g=(d+1)*(y=1/_),e.fwd=function(t,e){var n,s,o,a,c;switch(o=i(t.phi),s=r(t.phi),n=r(t.lam),l){case 3:e.y=u*o+p*s*n;break;case 2:e.y=s*n;break;case 1:e.y=-o;break;case 0:e.y=o}switch(e.y<m&&V(),e.y=_/(d-e.y),e.x=e.y*s*i(t.lam),l){case 3:e.y*=p*o-u*s*n;break;case 2:e.y*=o;break;case 0:n=-n;case 1:e.y*=s*n}S&&(c=1/((a=e.y*v+e.x*x)*b*y+w),e.x=(e.x*v-e.y*x)*w*c,e.y=a*c)},e.inv=function(r,n){var o,a,m,y,T,C;if(S&&(C=1/(_-r.y*b),y=_*r.x*C,T=_*r.y*w*C,r.x=y*v+T*x,r.y=T*v-y*x),o=f(r.x,r.y),(m=1-o*o*g)<0&&j(),m=(d-h(m))/(_/o+o/_),a=h(1-m*m),t(o)<=R)n.lam=0,n.phi=e.phi0;else{switch(l){case 3:n.phi=s(a*u+r.y*m*p/o),r.y=(a-u*i(n.phi))*o,r.x*=m*p;break;case 2:n.phi=s(r.y*m/o),r.y=a*o,r.x*=m;break;case 0:n.phi=s(a),r.y=-r.y;break;case 1:n.phi=-s(a)}n.lam=c(r.x,r.y)}},e.es=0}function bi(t,e){var i=.79788456,r=.1013211836*(e?2:4);t.es=0,t.fwd=function(t,e){e.x=i*t.lam*(1-r*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-r*e.phi*e.phi))}}function wi(t,e,n){t.es=0,t.fwd=function(t,s){t.phi=Je(.883883476*i(t.phi)),s.x=e*t.lam*r(t.phi),s.x/=r(t.phi*=.333333333333333),s.y=n*i(t.phi)},t.inv=function(t,s){s.phi=Je(t.y/n),s.lam=t.x*r(s.phi)/e,s.phi*=3,s.lam/=r(s.phi),s.phi=Je(1.13137085*i(s.phi))}}function Si(t,e){var i=e?1.5:2,r=e?.5:1,n=1.01346,s=1.2158542;t.es=0,t.fwd=function(t,e){e.x=n*t.lam*(i-r*h(1+s*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-r*h(1+s*e.phi*e.phi)))}}function Ti(e,r){var n,s,o,a,l,c=1.732050807568877;r?(o=.44329,a=.80404,n=6,s=5.61125,l=3):(o=1.01346,a=.9191,n=4,s=2.147143718212938,l=2),e.es=0,e.fwd=function(e,r){var u,p,f,m;for(u=s*i(e.phi),e.phi*=1.10265779,m=10;m&&(p=h(1+e.phi*e.phi),e.phi-=f=((n-p)*e.phi-d(e.phi+p)-u)/(n-2*p),!(t(f)<1e-10));--m);m||(e.phi=u<0?-c:c),r.x=o*e.lam*(l-h(1+e.phi*e.phi)),r.y=a*e.phi},e.inv=function(t,e){var i;e.phi=t.y/a,i=h(1+e.phi*e.phi),e.lam=t.x/(o*(l-i)),e.phi=Je(((n-i)*e.phi-d(e.phi+i))/s)}}function Ci(e){return function(s){!function(e,s){var o,a,u,p,d,m,_,g,y,v,x=1e-10;switch(Y(e.params,"tlat_1")&&Y(e.params,"tlat_2")?(u=Y(e.params,"rlat_1"),p=Y(e.params,"rlat_2"),g=.5*(p+u),(t(o=.5*(p-u))<x||t(g)<x)&&U(-42)):U(-41),s){case"TISSOT":d=i(g),a=r(o),_=h(((m=d/a+a/d)-2*i(e.phi0))/d);break;case"MURD1":m=i(o)/(o*n(g))+g,_=m-e.phi0,d=i(g);break;case"MURD2":m=(a=h(r(o)))/n(g),_=m+n(g-e.phi0),d=i(g)*a;break;case"MURD3":m=o/(n(g)*n(o))+g,_=m-e.phi0,d=i(g)*i(o)*n(o)/(o*o);break;case"EULER":d=i(g)*i(o)/o,m=(o*=.5)/(n(o)*n(g))+g,_=m-e.phi0;break;case"PCONIC":d=i(g),v=r(o),y=1/n(g),t(o=e.phi0-g)-x>=E&&U(-43),_=v*(y-n(o));break;case"VITK1":d=(a=n(o))*i(g)/o,m=o/(a*n(g))+g,_=m-e.phi0}function b(t,e){var o;switch(s){case"MURD2":o=m+n(g-t.phi);break;case"PCONIC":o=v*(y-n(t.phi-g));break;default:o=m-t.phi}e.x=o*i(t.lam*=d),e.y=_-o*r(t.lam)}function w(t,e){var i;switch(i=f(t.x,t.y=_-t.y),d<0&&(i=-i,t.x=-t.x,t.y=-t.y),e.lam=c(t.x,t.y)/d,s){case"PCONIC":e.phi=l(y-i/v)+g;break;case"MURD2":e.phi=g-l(i-m);break;default:e.phi=m-i}}e.inv=w,e.fwd=b,e.es=0}(s,e)}}function Mi(e,o){var a,p,d,m,_,g,y,v,x=1e-10;if(v=t((p=t(e.phi0))-E)<x?e.phi0<0?0:1:p>x?2:3,o=t(o),e.es){switch(v){case 1:case 0:t(o-E)<x?y=2*e.k0/h(u(1+e.e,1+e.e)*u(1-e.e,1-e.e)):(y=r(o)/mi(o,p=i(o),e.e),p*=e.e,y/=h(1-p*p));break;case 3:case 2:p=i(e.phi0),a=2*l(b(e.phi0,p,e.e))-E,p*=e.e,y=2*e.k0*r(e.phi0)/h(1-p*p),_=i(a),g=r(a)}e.fwd=function(t,n){var s,o,a,c,h,u=0,p=0;switch(s=r(t.lam),o=i(t.lam),h=i(t.phi),(2==v||3==v)&&(u=i(a=2*l(b(t.phi,h,e.e))-E),p=r(a)),v){case 2:c=y/(g*(1+_*u+g*p*s)),n.y=c*(g*u-_*p*s),n.x=c*p;break;case 3:c=y/(1+p*s),n.y=c*u,n.x=c*p;break;case 0:t.phi=-t.phi,s=-s,h=-h;case 1:n.x=y*mi(t.phi,h,e.e),n.y=-n.x*s}n.x=n.x*o},e.inv=function(o,a){a.phi;var h,p,d,m,x=0,b=0,w=0,S=0;switch(d=f(o.x,o.y),v){case 2:case 3:h=r(x=2*c(d*g,y)),p=i(x),b=s(0==d?h*_:h*_+o.y*p*g/d),x=n(.5*(E+b)),o.x*=p,o.y=d*g*h-o.y*_*p,S=E,w=.5*e.e;break;case 1:o.y=-o.y;case 0:b=E-2*l(x=-d/y),S=-E,w=-.5*e.e}for(m=0;m<8;m++,b=a.phi)if(p=e.e*i(b),a.phi=2*l(x*u((1+p)/(1-p),w))-S,t(b-a.phi)<1e-10)return 0==v&&(a.phi=-a.phi),void(a.lam=0==o.x&&0==o.y?0:c(o.x,o.y));j()}}else{switch(v){case 2:d=i(e.phi0),m=r(e.phi0);case 3:y=2*e.k0;break;case 0:case 1:y=t(o-E)>=x?r(o)/n(A-.5*o):2*e.k0}e.fwd=function(e,s){var o=e.phi,a=i(o),l=r(o),c=r(e.lam),h=i(e.lam);switch(v){case 3:case 2:s.y=3==v?1+l*c:1+d*a+m*l*c,s.y<=x&&V(),s.x=(s.y=y/s.y)*l*h,s.y*=3==v?a:m*a-d*l*c;break;case 1:c=-c,o=-o;case 0:t(o-E)<1e-8&&V(),s.x=h*(s.y=y*n(A+.5*o)),s.y*=c}},e.inv=function(n,o){var a,h,u,p;switch(u=i(a=2*l((h=f(n.x,n.y))/y)),p=r(a),o.lam=0,v){case 3:t(h)<=x?o.phi=0:o.phi=s(n.y*u/h),0==p&&0==n.x||(o.lam=c(n.x*u,p*h));break;case 2:t(h)<=x?o.phi=e.phi0:o.phi=s(p*d+n.y*u*m/h),0==(a=p-d*i(o.phi))&&0==n.x||(o.lam=c(n.x*u*m,a*h));break;case 1:n.y=-n.y;case 0:t(h)<=x?o.phi=e.phi0:o.phi=s(0==v?-p:p),o.lam=0==n.x&&0==n.y?0:c(n.x,n.y)}}}function b(t,e,i){return e*=i,n(.5*(E+t))*u((1-e)/(1+e),.5*i)}}function Ai(t,e){return u((1-t)/(1+t),e)}function Ei(t,e,s,o){var a=s/e,c=e,h=1/s;t.inv=function(t,e){var i;t.y/=c,i=r(e.phi=o?l(t.y):Je(t.y)),e.phi/=h,e.lam=t.x/(a*r(e.phi)),o?e.lam/=i*i:e.lam*=i},t.fwd=function(t,e){var s;e.x=a*t.lam*r(t.phi),e.y=c,t.phi*=h,s=r(t.phi),o?(e.x*=s*s,e.y*=n(t.phi)):(e.x/=s,e.y*=i(t.phi))},t.es=0}function Ii(e){var n,o,l,u=1e-10,f=.5,m=.16666666666666666,_=.08333333333333333,g=.05,y=.03333333333333333,v=.023809523809523808,x=.017857142857142856;e.es?((l=Xe(e.es))||e_error_0(),o=Ye(e.phi0,i(e.phi0),r(e.phi0),l),n=e.es/(1-e.es),e.fwd=function(s,a){var c,p,d,f,b,w;s.lam<-E||s.lam>E?N(-14):(c=i(s.phi),p=r(s.phi),d=t(p)>u?c/p:0,d*=d,f=p*s.lam,b=f*f,f/=h(1-e.es*c*c),w=n*p*p,a.x=e.k0*f*(1+m*b*(1-d+w+g*b*(5+d*(d-18)+w*(14-58*d)+v*b*(61+d*(d*(179-d)-479))))),a.y=e.k0*(Ye(s.phi,c,p,l)-o+c*f*s.lam*.5*(1+_*b*(5-d+w*(9+4*w)+y*b*(61+d*(d-58)+w*(270-330*d)+x*b*(1385+d*(d*(543-d)-3111)))))))},e.inv=function(s,a){var c,u,p,d,b,w,S;a.phi=Ke(o+s.y/e.k0,e.es,l),t(a.phi)>=E?(a.phi=s.y<0?-E:E,a.lam=0):(w=i(a.phi),p=r(a.phi),S=t(p)>1e-10?w/p:0,c=n*p*p,d=s.x*h(u=1-e.es*w*w)/e.k0,u*=S,S*=S,b=d*d,a.phi-=u*b/(1-e.es)*f*(1-b*_*(5+S*(3-9*c)+c*(1-4*c)-b*y*(61+S*(90-252*c+45*S)+46*c-b*x*(1385+S*(3633+S*(4095+1575*S)))))),a.lam=d*(1-b*m*(1+2*S+c-b*g*(5+S*(28+24*S+8*c)+6*c-b*v*(61+S*(662+S*(1320+720*S))))))/p)}):(n=e.k0,o=.5*n,e.fwd=function(s,l){var c,p;s.lam<-E||s.lam>E?N(-14):(p=r(s.phi),c=p*i(s.lam),t(t(c)-1)<=u&&V(),l.x=o*d((1+c)/(1-c)),l.y=p*r(s.lam)/h(1-c*c),(c=t(l.y))>=1?c-1>u?V():l.y=0:l.y=a(l.y),s.phi<0&&(l.y=-l.y),l.y=n*(l.y-e.phi0))},e.inv=function(t,i){var o=p(t.x/n),a=.5*(o-1/o);o=r(e.phi0+t.y/n),i.phi=s(h((1-o*o)/(1+a*a))),t.y<0&&-i.phi+e.phi0<0&&(i.phi=-i.phi),i.lam=a||o?c(a,o):0})}function Pi(t,e){var n=.8773826753,s=1.139753528477/e;t.es=0,t.fwd=function(t,o){var a=Je(e*i(t.phi));o.x=n*t.lam*r(a),o.y=s*a},t.inv=function(t,o){t.y/=s,o.phi=Je(i(t.y)/e),o.lam=t.x/(n*r(t.y))}}function Di(e,i){e.fwd=function(e,r){var n,s,o,a;o=t(D*e.phi),a=(a=1-o*o)<0?0:h(a),t(e.lam)<1e-10?(r.x=0,r.y=b*(e.phi<0?-o:o)/(1+a)):(s=.5*t(b/e.lam-e.lam/b),i?(n=o/(1+a),r.x=b*(h(s*s+1-n*n)-s),r.y=b*n):(n=(a*h(1+s*s)-s*a*a)/(1+s*s*o*o),r.x=b*n,r.y=b*h(1-n*(n+2*s)+1e-10)),e.lam<0&&(r.x=-r.x),e.phi<0&&(r.y=-r.y))},e.es=0}$e.Constants={},$e.Math={},$e.Accumulator={},(Ue=$e.Constants).WGS84={a:6378137,f:1/298.257223563},Ue.version={major:1,minor:48,patch:0},Ue.version_string="1.48",(qe=$e.Math).digits=53,qe.epsilon=Math.pow(.5,qe.digits-1),qe.degree=Math.PI/180,qe.sq=function(t){return t*t},qe.hypot=function(t,e){var i,r;return t=Math.abs(t),e=Math.abs(e),i=Math.max(t,e),r=Math.min(t,e)/(i||1),i*Math.sqrt(1+r*r)},qe.cbrt=function(t){var e=Math.pow(Math.abs(t),1/3);return t<0?-e:e},qe.log1p=function(t){var e=1+t,i=e-1;return 0===i?t:t*Math.log(e)/i},qe.atanh=function(t){var e=Math.abs(t);return e=qe.log1p(2*e/(1-e))/2,t<0?-e:e},qe.copysign=function(t,e){return Math.abs(t)*(e<0||0===e&&1/e<0?-1:1)},qe.sum=function(t,e){var i=t+e,r=i-e,n=i-r;return{s:i,t:-((r-=t)+(n-=e))}},qe.polyval=function(t,e,i,r){for(var n=t<0?0:e[i++];--t>=0;)n=n*r+e[i++];return n},qe.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},qe.AngNormalize=function(t){return(t%=360)<=-180?t+360:t<=180?t:t-360},qe.LatFix=function(t){return Math.abs(t)>90?Number.NaN:t},qe.AngDiff=function(t,e){var i=qe.sum(qe.AngNormalize(-t),qe.AngNormalize(e)),r=qe.AngNormalize(i.s),n=i.t;return qe.sum(180===r&&n>0?-180:r,n)},qe.sincosd=function(t){var e,i,r,n,s,o;switch(e=t%360,e-=90*(i=Math.floor(e/90+.5)),e*=this.degree,r=Math.sin(e),n=Math.cos(e),3&i){case 0:s=r,o=n;break;case 1:s=n,o=-r;break;case 2:s=-r,o=-n;break;default:s=-n,o=r}return t&&(s+=0,o+=0),{s:s,c:o}},qe.atan2d=function(t,e){var i,r,n=0;switch(Math.abs(t)>Math.abs(e)&&(i=e,e=t,t=i,n=2),e<0&&(e=-e,++n),r=Math.atan2(t,e)/this.degree,n){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 i=e.sum(t,this._t),r=e.sum(i.s,this._s);i=i.t,this._s=r.s,this._t=r.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}}($e.Accumulator,$e.Math),$e.Geodesic={},$e.GeodesicLine={},$e.PolygonArea={},function(t,e,i,r,n){var s,o,a,l,c,h,u,p,d,f,m,_=20+r.digits+10,g=r.epsilon,y=200*g,v=Math.sqrt(g),x=g*y,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,s=t.nC3_*(t.nC3_-1)/2,o=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,r){var n=r.length,s=n-(t?1:0),o=2*(i-e)*(i+e),a=1&s?r[--n]:0,l=0;for(s=Math.floor(s/2);s--;)a=o*(l=o*a-l+r[--n])-a+r[--n];return t?2*e*i*a:i*(a-l)},a=function(t,e){var i,n,s,o,a,l,c,h,u,p,d,f,m=r.sq(t),_=r.sq(e),g=(m+_-1)/6;return 0===_&&g<=0?i=0:(l=g,(a=(n=m*_/4)*(n+2*(o=g*(s=r.sq(g)))))>=0?(c=n+o,c+=c<0?-Math.sqrt(a):Math.sqrt(a),l+=(h=r.cbrt(c))+(0!==h?s/h:0)):(u=Math.atan2(Math.sqrt(-a),-(n+o)),l+=2*g*Math.cos(u/3)),p=Math.sqrt(r.sq(l)+_),f=((d=l<0?_/(p-l):l+p)-_)/(2*p),i=d/(Math.sqrt(d+r.sq(f))+f)),i},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)},c=[-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,s,o=r.sq(e),a=e,l=0;for(n=1;n<=t.nC1_;++n)s=Math.floor((t.nC1_-n)/2),i[n]=a*r.polyval(s,c,l,o)/c[l+s+1],l+=s+2,a*=e},h=[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,s,o=r.sq(e),a=e,l=0;for(n=1;n<=t.nC1p_;++n)s=Math.floor((t.nC1p_-n)/2),i[n]=a*r.polyval(s,h,l,o)/h[l+s+1],l+=s+2,a*=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,i){var n,s,o=r.sq(e),a=e,l=0;for(n=1;n<=t.nC2_;++n)s=Math.floor((t.nC2_-n)/2),i[n]=a*r.polyval(s,p,l,o)/p[l+s+1],l+=s+2,a*=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(o),this.A3coeff(),this.C3coeff(),this.C4coeff()},d=[-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++]=r.polyval(e,d,i,this._n)/d[i+e+1],i+=e+2},f=[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,s=0,o=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[o++]=r.polyval(n,f,s,this._n)/f[s+n+1],s+=n+2},m=[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,s=0,o=0;for(e=0;e<t.nC4_;++e)for(i=t.nC4_-1;i>=e;--i)n=t.nC4_-i-1,this._C4x[o++]=r.polyval(n,m,s,this._n)/m[s+n+1],s+=n+2},t.Geodesic.prototype.A3f=function(t){return r.polyval(5,this._A3x,0,t)},t.Geodesic.prototype.C3f=function(e,i){var n,s,o=1,a=0;for(n=1;n<t.nC3_;++n)s=t.nC3_-n-1,o*=e,i[n]=o*r.polyval(s,this._C3x,a,e),a+=s+1},t.Geodesic.prototype.C4f=function(e,i){var n,s,o=1,a=0;for(n=0;n<t.nC4_;++n)s=t.nC4_-n-1,i[n]=o*r.polyval(s,this._C4x,a,e),a+=s+1,o*=e},t.Geodesic.prototype.Lengths=function(e,i,r,n,s,o,a,l,c,h,u,p,d){var f,m,_,g,y={},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,d),v=b-w,w=1+w),b=1+b),u&t.DISTANCE)f=t.SinCosSeries(!0,o,a,p)-t.SinCosSeries(!0,r,n,p),y.s12b=b*(i+f),u&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(x=v*i+(b*f-w*(t.SinCosSeries(!0,o,a,d)-t.SinCosSeries(!0,r,n,d))));else if(u&(t.REDUCEDLENGTH|t.GEODESICSCALE)){for(m=1;m<=t.nC2_;++m)d[m]=b*p[m]-w*d[m];x=v*i+(t.SinCosSeries(!0,o,a,d)-t.SinCosSeries(!0,r,n,d))}return u&t.REDUCEDLENGTH&&(y.m0=v,y.m12b=l*(n*o)-s*(r*a)-n*a*x),u&t.GEODESICSCALE&&(_=n*a+r*o,g=this._ep2*(c-h)*(c+h)/(s+l),y.M12=_+(g*o-a*x)*r/s,y.M21=_-(g*r-n*x)*o/l),y},t.Geodesic.prototype.InverseStart=function(e,i,n,s,o,l,c,h,u,p,d){var f,m,_,g,v,x,w,S,T,C,M,A,E,I,P,D,k,z,R,L,F={},B=s*i-o*e,O=o*i+s*e;return F.sig12=-1,f=s*i,f+=o*e,(m=O>=0&&B<.5&&o*c<.5)?(g=r.sq(e+s),g/=g+r.sq(i+o),F.dnm=Math.sqrt(1+this._ep2*g),_=c/(this._f1*F.dnm),v=Math.sin(_),x=Math.cos(_)):(v=h,x=u),F.salp1=o*v,F.calp1=x>=0?B+o*e*r.sq(v)/(1+x):f-o*e*r.sq(v)/(1-x),S=r.hypot(F.salp1,F.calp1),T=e*s+i*o*x,m&&S<this._etol2?(F.salp2=i*v,F.calp2=B-i*s*(x>=0?r.sq(v)/(1+x):1-x),w=r.hypot(F.salp2,F.calp2),F.salp2/=w,F.calp2/=w,F.sig12=Math.atan2(S,T)):Math.abs(this._n)>.1||T>=0||S>=6*Math.abs(this._n)*Math.PI*r.sq(i)||(L=Math.atan2(-h,-u),this.f>=0?(I=(E=r.sq(e)*this._ep2)/(2*(1+Math.sqrt(1+E))+E),C=L/(A=this.f*i*this.A3f(I)*Math.PI),M=f/(A*i)):(P=o*i-s*e,D=Math.atan2(f,P),M=c/(A=((C=(k=this.Lengths(this._n,Math.PI+D,e,-i,n,s,o,l,i,o,t.REDUCEDLENGTH,p,d)).m12b/(i*o*k.m0*Math.PI)-1)<-.01?f/C:-this.f*r.sq(i)*Math.PI)/i)),M>-y&&C>-1-b?this.f>=0?(F.salp1=Math.min(1,-C),F.calp1=-Math.sqrt(1-r.sq(F.salp1))):(F.calp1=Math.max(C>-y?0:-1,C),F.salp1=Math.sqrt(1-r.sq(F.calp1))):(z=a(C,M),R=A*(this.f>=0?-C*z/(1+z):-M*(1+z)/z),v=Math.sin(R),x=-Math.cos(R),F.salp1=o*v,F.calp1=f-o*e*r.sq(v)/(1-x))),F.salp1<=0?(F.salp1=1,F.calp1=0):(w=r.hypot(F.salp1,F.calp1),F.salp1/=w,F.calp1/=w),F},t.Geodesic.prototype.Lambda12=function(e,i,n,s,o,a,l,c,h,u,p,d,f,m){var _,g,y,v,x,b,w,S,T,C,M,A,E,I={};return 0===e&&0===c&&(c=-t.tiny_),g=l*i,y=r.hypot(c,l*e),I.ssig1=e,v=g*e,I.csig1=x=c*i,_=r.hypot(I.ssig1,I.csig1),I.ssig1/=_,I.csig1/=_,I.salp2=o!==i?g/o:l,I.calp2=o!==i||Math.abs(s)!==-e?Math.sqrt(r.sq(c*i)+(i<-e?(o-i)*(i+o):(e-s)*(e+s)))/o:Math.abs(c),I.ssig2=s,b=g*s,I.csig2=w=I.calp2*o,_=r.hypot(I.ssig2,I.csig2),I.ssig2/=_,I.csig2/=_,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),T=x*w+v*b,M=Math.atan2(S*u-T*h,T*u+S*h),A=r.sq(y)*this._ep2,I.eps=A/(2*(1+Math.sqrt(1+A))+A),this.C3f(I.eps,m),C=t.SinCosSeries(!0,I.ssig2,I.csig2,m)-t.SinCosSeries(!0,I.ssig1,I.csig1,m),I.domg12=-this.f*this.A3f(I.eps)*g*(I.sig12+C),I.lam12=M+I.domg12,p&&(0===I.calp2?I.dlam12=-2*this._f1*n/e:(E=this.Lengths(I.eps,I.sig12,I.ssig1,I.csig1,n,I.ssig2,I.csig2,a,i,o,t.REDUCEDLENGTH,d,f),I.dlam12=E.m12b,I.dlam12*=this._f1/(I.calp2*o))),I},t.Geodesic.prototype.Inverse=function(e,i,n,s,o){var a,l;return o||(o=t.STANDARD),o===t.LONG_UNROLL&&(o|=t.STANDARD),o&=t.OUT_MASK,l=(a=this.InverseInt(e,i,n,s,o)).vals,o&t.AZIMUTH&&(l.azi1=r.atan2d(a.salp1,a.calp1),l.azi2=r.atan2d(a.salp2,a.calp2)),l},t.Geodesic.prototype.InverseInt=function(e,i,n,s,o){var a,l,c,h,u,p,d,f,m,y,v,b,w,S,T,C,M,A,E,I,P,D,k,z,R,L,F,B,O,N,V,j,G,U,q,$,Z,W,H,X,Y,K,J,Q,tt,et,it,rt,nt,st,ot,at,lt,ct,ht,ut,pt,dt,ft,mt,_t,gt,yt,vt,xt,bt={};if(bt.lat1=e=r.LatFix(e),bt.lat2=n=r.LatFix(n),e=r.AngRound(e),n=r.AngRound(n),l=(a=r.AngDiff(i,s)).t,a=a.s,o&t.LONG_UNROLL?(bt.lon1=i,bt.lon2=i+a+l):(bt.lon1=r.AngNormalize(i),bt.lon2=r.AngNormalize(s)),a=(c=a>=0?1:-1)*r.AngRound(a),l=r.AngRound(180-a-c*l),T=a*r.degree,C=(h=r.sincosd(a>90?l:a)).s,M=(a>90?-1:1)*h.c,(u=Math.abs(e)<Math.abs(n)?-1:1)<0&&(c*=-1,h=e,e=n,n=h),e*=p=e<0?1:-1,n*=p,h=r.sincosd(e),d=this._f1*h.s,f=h.c,d/=h=r.hypot(d,f),f/=h,f=Math.max(t.tiny_,f),h=r.sincosd(n),m=this._f1*h.s,y=h.c,m/=h=r.hypot(m,y),y/=h,y=Math.max(t.tiny_,y),f<-d?y===f&&(m=m<0?d:-d):Math.abs(m)===-d&&(y=f),w=Math.sqrt(1+this._ep2*r.sq(d)),S=Math.sqrt(1+this._ep2*r.sq(m)),k=new Array(t.nC1_+1),z=new Array(t.nC2_+1),R=new Array(t.nC3_),(L=-90===e||0===C)&&(I=C,D=0,B=d,O=(E=M)*f,N=m,V=(P=1)*y,A=Math.atan2(Math.max(0,O*N-B*V),O*V+B*N),v=(F=this.Lengths(this._n,A,B,O,w,N,V,S,f,y,o|t.DISTANCE|t.REDUCEDLENGTH,k,z)).s12b,b=F.m12b,0!==(o&t.GEODESICSCALE)&&(bt.M12=F.M12,bt.M21=F.M21),A<1||b>=0?(A<3*t.tiny_&&(A=b=v=0),b*=this._b,v*=this._b,bt.a12=A/r.degree):L=!1),pt=2,!L&&0===d&&(this.f<=0||l>=180*this.f))E=P=0,I=D=1,v=this.a*T,A=G=T/this._f1,b=this._b*Math.sin(A),o&t.GEODESICSCALE&&(bt.M12=bt.M21=Math.cos(A)),bt.a12=a/this._f1;else if(!L)if(A=(F=this.InverseStart(d,f,w,m,y,S,T,C,M,k,z)).sig12,I=F.salp1,E=F.calp1,A>=0)D=F.salp2,P=F.calp2,U=F.dnm,v=A*this._b*U,b=r.sq(U)*this._b*Math.sin(A/U),o&t.GEODESICSCALE&&(bt.M12=bt.M21=Math.cos(A/U)),bt.a12=A/r.degree,G=T/(this._f1*U);else{for(q=0,$=t.tiny_,Z=1,W=t.tiny_,H=-1,X=!1,Y=!1;q<_&&(K=(F=this.Lambda12(d,f,w,m,y,S,I,E,C,M,q<20,k,z,R)).lam12,D=F.salp2,P=F.calp2,A=F.sig12,B=F.ssig1,O=F.csig1,N=F.ssig2,V=F.csig2,j=F.eps,ft=F.domg12,J=F.dlam12,!Y&&Math.abs(K)>=(X?8:1)*g);++q)K>0&&(q<20||E/I>H/W)?(W=I,H=E):K<0&&(q<20||E/I<Z/$)&&($=I,Z=E),q<20&&J>0&&(Q=-K/J,tt=Math.sin(Q),(it=I*(et=Math.cos(Q))+E*tt)>0&&Math.abs(Q)<Math.PI)?(E=E*et-I*tt,I=it,I/=h=r.hypot(I,E),E/=h,X=Math.abs(K)<=16*g):(I=($+W)/2,E=(Z+H)/2,I/=h=r.hypot(I,E),E/=h,X=!1,Y=Math.abs($-I)+(Z-E)<x||Math.abs(I-W)+(E-H)<x);rt=o|(o&(t.REDUCEDLENGTH|t.GEODESICSCALE)?t.DISTANCE:t.NONE),v=(F=this.Lengths(j,A,B,O,w,N,V,S,f,y,rt,k,z)).s12b,b=F.m12b,0!==(o&t.GEODESICSCALE)&&(bt.M12=F.M12,bt.M21=F.M21),b*=this._b,v*=this._b,bt.a12=A/r.degree,o&t.AREA&&(vt=Math.sin(ft),pt=C*(xt=Math.cos(ft))-M*vt,dt=M*xt+C*vt)}return o&t.DISTANCE&&(bt.s12=0+v),o&t.REDUCEDLENGTH&&(bt.m12=0+b),o&t.AREA&&(nt=I*f,0!==(st=r.hypot(E,I*d))&&0!==nt?(B=d,O=E*f,N=m,V=P*y,j=(at=r.sq(st)*this._ep2)/(2*(1+Math.sqrt(1+at))+at),lt=r.sq(this.a)*st*nt*this._e2,B/=h=r.hypot(B,O),O/=h,N/=h=r.hypot(N,V),V/=h,ct=new Array(t.nC4_),this.C4f(j,ct),ht=t.SinCosSeries(!1,B,O,ct),ut=t.SinCosSeries(!1,N,V,ct),bt.S12=lt*(ut-ht)):bt.S12=0,!L&&pt>1&&(pt=Math.sin(G),dt=Math.cos(G)),!L&&dt>-.7071&&m-d<1.75?(ft=1+dt,mt=1+f,_t=1+y,ot=2*Math.atan2(pt*(d*_t+m*mt),ft*(d*m+mt*_t))):(yt=P*E+D*I,0===(gt=D*E-P*I)&&yt<0&&(gt=t.tiny_*E,yt=-1),ot=Math.atan2(gt,yt)),bt.S12+=this._c2*ot,bt.S12*=u*c*p,bt.S12+=0),u<0&&(h=I,I=D,D=h,h=E,E=P,P=h,o&t.GEODESICSCALE&&(h=bt.M12,bt.M12=bt.M21,bt.M21=h)),{vals:bt,salp1:I*=u*c,calp1:E*=u*p,salp2:D*=u*c,calp2:P*=u*p}},t.Geodesic.prototype.GenDirect=function(i,r,n,s,o,a){return a?a===t.LONG_UNROLL&&(a|=t.STANDARD):a=t.STANDARD,s||(a|=t.DISTANCE_IN),new e.GeodesicLine(this,i,r,n,a).GenPosition(s,o,a)},t.Geodesic.prototype.Direct=function(t,e,i,r,n){return this.GenDirect(t,e,i,!1,r,n)},t.Geodesic.prototype.ArcDirect=function(t,e,i,r,n){return this.GenDirect(t,e,i,!0,r,n)},t.Geodesic.prototype.Line=function(t,i,r,n){return new e.GeodesicLine(this,t,i,r,n)},t.Geodesic.prototype.DirectLine=function(t,e,i,r,n){return this.GenDirectLine(t,e,i,!1,r,n)},t.Geodesic.prototype.ArcDirectLine=function(t,e,i,r,n){return this.GenDirectLine(t,e,i,!0,r,n)},t.Geodesic.prototype.GenDirectLine=function(i,r,n,s,o,a){var l;return a||(a=t.STANDARD|t.DISTANCE_IN),s||(a|=t.DISTANCE_IN),(l=new e.GeodesicLine(this,i,r,n,a)).GenSetDistance(s,o),l},t.Geodesic.prototype.InverseLine=function(i,n,s,o,a){var l,c,h;return a||(a=t.STANDARD|t.DISTANCE_IN),l=this.InverseInt(i,n,s,o,t.ARC),h=r.atan2d(l.salp1,l.calp1),a&t.OUT_MASK&t.DISTANCE_IN&&(a|=t.DISTANCE),(c=new e.GeodesicLine(this,i,n,h,a,l.salp1,l.calp1)).SetArc(l.vals.a12),c},t.Geodesic.prototype.Polygon=function(t){return new i.PolygonArea(this,t)},t.WGS84=new t.Geodesic(n.WGS84.a,n.WGS84.f)}($e.Geodesic,$e.GeodesicLine,$e.PolygonArea,$e.Math,$e.Constants),function(t,e,i){e.GeodesicLine=function(e,r,n,s,o,a,l){var c,h,u,p,d,f;o||(o=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=o|t.LATITUDE|t.AZIMUTH|t.LONG_UNROLL,this.lat1=i.LatFix(r),this.lon1=n,void 0===a||void 0===l?(this.azi1=i.AngNormalize(s),c=i.sincosd(i.AngRound(this.azi1)),this.salp1=c.s,this.calp1=c.c):(this.azi1=s,this.salp1=a,this.calp1=l),c=i.sincosd(i.AngRound(this.lat1)),u=this._f1*c.s,h=c.c,u/=c=i.hypot(u,h),h/=c,h=Math.max(t.tiny_,h),this._dn1=Math.sqrt(1+e._ep2*i.sq(u)),this._salp0=this.salp1*h,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?h*this.calp1:1,c=i.hypot(this._ssig1,this._csig1),this._ssig1/=c,this._csig1/=c,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),d=Math.sin(this._B11),f=Math.cos(this._B11),this._stau1=this._ssig1*f+this._csig1*d,this._ctau1=this._csig1*f-this._ssig1*d),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,r,n){var s,o,a,l,c,h,u,p,d,f,m,_,g,y,v,x,b,w,S,T,C,M,A,E,I,P,D={};return n?n===t.LONG_UNROLL&&(n|=t.STANDARD):n=t.STANDARD,n&=this.caps&t.OUT_MASK,D.lat1=this.lat1,D.azi1=this.azi1,D.lon1=n&t.LONG_UNROLL?this.lon1:i.AngNormalize(this.lon1),e?D.a12=r:D.s12=r,e||this.caps&t.DISTANCE_IN&t.OUT_MASK?(l=0,c=0,e?(s=r*i.degree,o=(A=i.sincosd(r)).s,a=A.c):(p=r/(this._b*(1+this._A1m1)),d=Math.sin(p),f=Math.cos(p),s=p-((l=-t.SinCosSeries(!0,this._stau1*f+this._ctau1*d,this._ctau1*f-this._stau1*d,this._C1pa))-this._B11),o=Math.sin(s),a=Math.cos(s),Math.abs(this.f)>.01&&(h=this._ssig1*a+this._csig1*o,u=this._csig1*a-this._ssig1*o,l=t.SinCosSeries(!0,h,u,this._C1a),s-=((1+this._A1m1)*(s+(l-this._B11))-r/this._b)/Math.sqrt(1+this._k2*i.sq(h)),o=Math.sin(s),a=Math.cos(s))),h=this._ssig1*a+this._csig1*o,u=this._csig1*a-this._ssig1*o,S=Math.sqrt(1+this._k2*i.sq(h)),n&(t.DISTANCE|t.REDUCEDLENGTH|t.GEODESICSCALE)&&((e||Math.abs(this.f)>.01)&&(l=t.SinCosSeries(!0,h,u,this._C1a)),c=(1+this._A1m1)*(l-this._B11)),g=this._calp0*h,0===(y=i.hypot(this._salp0,this._calp0*u))&&(y=u=t.tiny_),b=this._salp0,w=this._calp0*u,e&&n&t.DISTANCE&&(D.s12=this._b*((1+this._A1m1)*s+c)),n&t.LONGITUDE&&(v=this._salp0*h,x=u,_=i.copysign(1,this._salp0),m=((n&t.LONG_UNROLL?_*(s-(Math.atan2(h,u)-Math.atan2(this._ssig1,this._csig1))+(Math.atan2(_*v,x)-Math.atan2(_*this._somg1,this._comg1))):Math.atan2(v*this._comg1-x*this._somg1,x*this._comg1+v*this._somg1))+this._A3c*(s+(t.SinCosSeries(!0,h,u,this._C3a)-this._B31)))/i.degree,D.lon2=n&t.LONG_UNROLL?this.lon1+m:i.AngNormalize(i.AngNormalize(this.lon1)+i.AngNormalize(m))),n&t.LATITUDE&&(D.lat2=i.atan2d(g,this._f1*y)),n&t.AZIMUTH&&(D.azi2=i.atan2d(b,w)),n&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(T=t.SinCosSeries(!0,h,u,this._C2a),C=(1+this._A2m1)*(T-this._B21),M=(this._A1m1-this._A2m1)*s+(c-C),n&t.REDUCEDLENGTH&&(D.m12=this._b*(S*(this._csig1*h)-this._dn1*(this._ssig1*u)-this._csig1*u*M)),n&t.GEODESICSCALE&&(A=this._k2*(h-this._ssig1)*(h+this._ssig1)/(this._dn1+S),D.M12=a+(A*h-u*M)*this._ssig1/this._dn1,D.M21=a-(A*this._ssig1-this._csig1*M)*h/S)),n&t.AREA&&(E=t.SinCosSeries(!1,h,u,this._C4a),0===this._calp0||0===this._salp0?(I=b*this.calp1-w*this.salp1,P=w*this.calp1+b*this.salp1):(I=this._calp0*this._salp0*(a<=0?this._csig1*(1-a)+o*this._ssig1:o*(this._csig1*o/(1+a)+this._ssig1)),P=i.sq(this._salp0)+i.sq(this._calp0)*this._csig1*u),D.S12=this._c2*Math.atan2(I,P)+this._A4*(E-this._B41)),e||(D.a12=s/i.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 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}}($e.Geodesic,$e.GeodesicLine,$e.Math),function(t,e,i,r){var n,s;n=function(t,e){var r;return t=i.AngNormalize(t),e=i.AngNormalize(e),r=i.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,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 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 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+=s(this.lon,i.lon2)),this.lat=i.lat2,this.lon=i.lon2),++this.num},t.PolygonArea.prototype.Compute=function(t,e){var i,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):(i=this._geod.Inverse(this.lat,this.lon,this._lat0,this._lon0,this._mask),o.perimeter=this._perimetersum.Sum(i.s12),(s=new r.Accumulator(this._areasum)).Add(i.S12),1&this._crossings+n(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),o.area=s.Sum(),o)},t.PolygonArea.prototype.TestPoint=function(t,e,i,r){var s,o,a,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(),o=this.polyline?0:this._areasum.Sum(),a=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),c.perimeter+=s.s12,this.polyline||(o+=s.S12,a+=n(0===l?this.lon:e,0!==l?this._lon0:e));return this.polyline||(1&a&&(o+=(o<0?1:-1)*this._area0/2),i||(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),c.area=o),c},t.PolygonArea.prototype.TestEdge=function(t,e,i,r){var o,a,l,c={number:this.num?this.num+1:0};return 0===this.num||(c.perimeter=this._perimetersum.Sum()+e,this.polyline||(a=this._areasum.Sum(),l=this._crossings,a+=(o=this._geod.Direct(this.lat,this.lon,t,e,this._mask)).S12,l+=s(this.lon,o.lon2),o=this._geod.Inverse(o.lat2,o.lon2,this._lat0,this._lon0,this._mask),c.perimeter+=o.s12,a+=o.S12,1&(l+=n(o.lon2,this._lon0))&&(a+=(a<0?1:-1)*this._area0/2),i||(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),c.area=a)),c}}($e.PolygonArea,$e.Geodesic,$e.Math,$e.Accumulator),tt(function(t){var e=Y(t.params,"rlat_1"),i=Y(t.params,"rlat_2");He(t,e,i)},"aea","Albers Equal Area","Conic Sph&Ell\nlat_1= lat_2="),tt(function(t){var e=Y(t.params,"rlat_1"),i=Y(t.params,"bsouth")?-E:E;He(t,e,i)},"leac","Lambert Equal Area Conic","Conic, Sph&Ell\nlat_1= south"),tt(function(e){var s,o,l,u,p,d,m,_=1e-10;if(e.phi0=Y(e.params,"rlat_0"),t(t(e.phi0)-E)<_?(p=e.phi0<0?1:0,s=e.phi0<0?-1:1,o=0):t(e.phi0)<_?(p=2,s=0,o=1):(p=3,s=i(e.phi0),o=r(e.phi0)),e.es)if(m=new $e.Geodesic.Geodesic(e.a,e.es/(1+h(e.one_es))),d=Xe(e.es),Y(e.params,"bguam"))l=Ye(e.phi0,s,o,d),e.inv=function(t,s){var o,a,c;for(o=.5*t.x*t.x,s.phi=e.phi0,c=0;c<3;++c)a=e.e*i(s.phi),s.phi=Ke(l+t.y-o*n(s.phi)*(a=h(1-a*a)),e.es,d);s.lam=t.x*a/r(s.phi)},e.fwd=function(t,n){var s,o,a;s=r(t.phi),o=i(t.phi),a=1/h(1-e.es*o*o),n.x=t.lam*s*a,n.y=Ye(t.phi,o,s,d)-l+.5*t.lam*t.lam*s*o*a};else{switch(p){case 0:u=Ye(E,1,0,d);break;case 1:u=Ye(-E,-1,0,d);break;case 2:case 3:e.inv=y,e.fwd=g,h(1-e.es*s*s),e.e,h(e.one_es)}e.inv=y,e.fwd=g}else e.inv=function(t,n){var a,l,h,u=t.x,d=t.y;if((l=f(u,d))>b)l-_>b&&j(),l=b;else if(l<_)return n.phi=e.phi0,void(n.lam=0);3==p||2==p?(h=i(l),a=r(l),2==p?(n.phi=Je(d*h/l),u*=h,d=a*l):(n.phi=Je(a*s+d*h*o/l),d=(a-s*i(n.phi))*l,u*=h*o),n.lam=0==d?0:c(u,d)):0==p?(n.phi=E-l,n.lam=c(u,-d)):(n.phi=l-E,n.lam=c(u,d))},e.fwd=function(e,n){var l,c,h;switch(h=i(e.phi),c=r(e.phi),l=r(e.lam),p){case 2:case 3:n.y=2==p?c*l:s*h+o*c*l,t(t(n.y)-1)<1e-14?n.y<0?V():n.x=n.y=0:(n.y=a(n.y),n.y/=i(n.y),n.x=n.y*c*i(e.lam),n.y*=2==p?h:o*h-s*c*l);break;case 0:e.phi=-e.phi,l=-l;case 1:t(e.phi-E)<_&&V(),n.x=(n.y=E+e.phi)*i(e.lam),n.y*=l}};function g(n,s){var o,a,l,c,h,f,g,y,v,x,b;switch(o=r(n.lam),a=r(n.phi),l=i(n.phi),p){case 0:o=-o;case 1:s.x=(c=t(u-Ye(n.phi,l,a,d)))*i(n.lam),s.y=c*o;break;case 2:case 3:if(t(n.lam)<_&&t(n.phi-e.phi0)<_){s.x=s.y=0;break}y=e.phi0/T,g=e.lam0/T,x=n.phi/T,v=(n.lam+e.lam0)/T,h=(b=m.Inverse(y,g,x,v,m.AZIMUTH)).azi1*T,f=b.s12,s.x=f*i(h)/e.a,s.y=f*r(h)/e.a}}function y(t,i){var r,n,s,o,a,l,g,y;if((r=f(t.x,t.y))<_)return i.phi=e.phi0,i.lam=0,i;3==p||2==p?(o=t.x*e.a,a=t.y*e.a,l=e.phi0/T,g=e.lam0/T,n=c(o,a)/T,s=h(o*o+a*a),y=m.Direct(l,g,n,s,m.STANDARD),i.phi=y.lat2*T,i.lam=y.lon2*T,i.lam-=e.lam0):(i.phi=Ke(0==p?u-r:u+r,e.es,d),i.lam=c(t.x,0==p?-t.y:t.y))}},"aeqd","Azimuthal Equidistant","Azi, Sph&Ell\nlat_0 guam"),tt(function(e){var s,o,a,l,c,h,u=1e-10;e.es=0,e.fwd=function(e,h){var p,f,m,_,g,y,v,x;switch(p=i(e.lam),f=r(e.lam),l){case 2:case 3:_=i(e.phi),x=(m=r(e.phi))*f,3==l&&(x=s*_+o*x),!c&&x<-u&&V(),v=t(y=1-x)>u?-d(g=.5*(1+x))/y-a/g:.5-a,h.x=v*m*p,h.y=3==l?v*(o*_-s*m*f):v*_;break;case 1:case 0:e.phi=t(p_halfpi-e.phi),!c&&e.phi-u>E&&V(),(e.phi*=.5)>u?(g=n(e.phi),v=-2*(d(r(e.phi))/g+g*a),h.x=v*p,h.y=v*f,0==l&&(h.y=-h.y)):h.x=h.y=0}},c=Y(e.params,"bno_cut"),h=.5*(E-Y(e.params,"rlat_b")),t(h)<u?a=-.5:(a=1/n(h),a*=a*d(r(h))),t(t(e.phi0)-E)<u?e.phi0<0?(p_halfpi=-E,l=1):(p_halfpi=E,l=0):t(e.phi0)<u?l=2:(l=3,s=i(e.phi0),o=r(e.phi0))},"airy","Airy","Misc Sph, no inv.\nno_cut lat_b="),tt(function(t){var e=t.opaque={mode:1};Y(t.params,"tlat_1")?0===(e.cosphi1=r(Y(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 s,o,a,l,c,u,p,d=4/3,f=t.lam;s=n(.5*t.phi),a=1+(o=h(1-s*s))*r(f*=.5),l=i(f)*o/a,u=s/a,e.x=d*l*(3+(c=l*l)-3*(p=u*u)),e.y=d*u*(3+3*c-p)},t.es=0},"august","August Epicycloidal","Misc Sph, no inv."),tt(function(t){ri(t,!1,!1)},"apian","Apian Globular I","Misc Sph, no inv."),tt(function(t){ri(t,!1,!0)},"ortel","Ortelius Oval","Misc Sph, no inv."),tt(function(t){ri(t,!0,!1)},"bacon","Bacon Globular","Misc Sph, no inv."),tt(function(t){var e,n,o,a;t.es=0,t.fwd=function(t,l){var u,p,d,f,m,_;return t.lam+=-16.5*T,p=r(t.phi),d=r(t.lam)*p,f=i(t.lam)*p,_=(m=i(t.phi))*e+d*n,t.lam=c(f*o-_*a,d*e-m*n),_=_*o+f*a,t.phi=s(_),t.lam=At(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+b/2)),p=r(t.phi),u=h(2/(1+p*r(t.lam/2))),l.x=1.68*u*p*i(t.lam/2),l.y=u*i(t.phi),u=(1-r(t.lam*t.phi))/12,l.y<0&&(l.x*=1+u),l.y>0&&(l.y*=1+u/1.5*l.x*l.x),l},t.lam0=0,t.phi0=-42*T,e=r(t.phi0),n=i(t.phi0),o=1,a=0},"bertin1953","Bertin 1953","Misc., Sph., NoInv."),tt(function(e){var n=h(2);e.fwd=function(e,s){var o,a,l,c;if(o=e.phi,t(t(e.phi)-E)<1e-7)s.x=0;else{for(l=i(o)*b,c=20;c&&(o-=a=(o+i(o)-l)/(1+r(o)),!(t(a)<1e-7));--c);o*=.5,s.x=2.00276*e.lam/(1/r(e.phi)+1.11072/r(o))}s.y=.49931*(e.phi+n*i(o))},e.es=0},"boggs","Boggs Eumorphic","PCyl., no inv., Sph."),tt(function(e){var s,o,a,l,u,p,d=1e-10;s=Y(e.params,"rlat_1"),t(s)<d&&U(-23),e.es?(u=Xe(e.es),l=Ye(s,a=i(s),p=r(s),u),a=p/(h(1-e.es*a*a)*a),e.inv=function(n,s){var o,p;p=f(n.x,n.y=a-n.y),s.phi=Ke(a+l-p,e.es,u),(o=t(s.phi))<E?(o=i(s.phi),s.lam=p*c(n.x,n.y)*h(1-e.es*o*o)/r(s.phi)):t(o-E)<=d?s.lam=0:j()},e.fwd=function(t,n){var s,o,c;s=a+l-Ye(t.phi,o=i(t.phi),c=r(t.phi),u),o=c*t.lam/(s*h(1-e.es*o*o)),n.x=s*i(o),n.y=a-s*r(o)}):(o=t(s)+d>=E?0:1/n(s),e.inv=function(e,i){var n=f(e.x,e.y=o-e.y);i.phi=o+s-n,t(i.phi)>E&&j(),t(t(i.phi)-E)<=d?i.lam=0:i.lam=n*c(e.x,e.y)/r(i.phi)},e.fwd=function(e,n){var a,l;l=o+s-e.phi,t(l)>d?(n.x=l*i(a=e.lam*r(e.phi)/l),n.y=o-l*r(a)):n.x=n.y=0})},"bonne","Bonne (Werner lat_1=90)","Conic Sph&Ell\nlat_1="),tt(function(t){var e,o,a=.16666666666666666,l=.008333333333333333,u=.041666666666666664,p=.06666666666666667;t.es?(o=Xe(t.es),e=Ye(t.phi0,i(t.phi0),r(t.phi0),o),t.fwd=function(s,c){var p,d,f,m,_,g;c.y=Ye(s.phi,p=i(s.phi),m=r(s.phi),o),p=1/h(1-t.es*p*p),g=n(s.phi),d=g*g,f=s.lam*m,m*=t.es*m/(1-t.es),_=f*f,c.x=p*f*(1-_*d*(a-(8-d+8*m)*_*l)),c.y-=e-p*g*_*(.5+(5-d+6*m)*_*u)},t.inv=function(s,a){var l,c,d,f,m,_,g;g=Ke(e+s.y,t.es,o),_=n(g),c=_*_,l=i(g),d=1/(1-t.es*l*l),l=h(d),d*=(1-t.es)*l,f=s.x/l,m=f*f,a.phi=g-l*_/d*m*(.5-(1+3*c)*m*u),a.lam=f*(1+c*m*((1+3*c)*m*p-.3333333333333333))/r(g)}):(t.fwd=function(e,o){o.x=s(r(e.phi)*i(e.lam)),o.y=c(n(e.phi),r(e.lam))-t.phi0},t.inv=function(e,o){var a=e.y+t.phi0;o.phi=s(i(a)*r(e.x)),o.lam=c(n(e.x),r(a))})},"cass","Cassini","Cyl, Sph&Ell"),tt(function(e){var n,o,a=0;Y(e.params,"tlat_ts")&&(e.k0=r(a=Y(e.params,"rlat_ts")),e.k0<0&&U(-24)),e.es?(a=i(a),e.k0/=h(1-e.es*a*a),e.e=h(e.es),(o=ni(e.es))||e_error_0(),n=Ze(1,e.e,e.one_es),e.fwd=function(t,r){r.x=e.k0*t.lam,r.y=.5*Ze(i(t.phi),e.e,e.one_es)/e.k0},e.inv=function(t,i){i.phi=si(s(2*t.y*e.k0/n),o),i.lam=t.x/e.k0}):(e.fwd=function(t,r){r.x=e.k0*t.lam,r.y=i(t.phi)/e.k0},e.inv=function(i,r){var n,o=i.x,a=i.y;(n=t(a*=e.k0))-R<=1?(r.phi=n>=1?a<0?-E:E:s(a),r.lam=o/e.k0):j()})},"cea","Equal Area Cylindrical","Cyl, Sph&Ell\nlat_ts="),tt(function(e){var n,s,o,a,l,u,p,d=1/3,f=[];for(u=0;u<3;++u)f[u]={p:{}},f[u].phi=Y(e.params,"rlat_"+(u+1)),f[u].lam=Y(e.params,"rlon_"+(u+1)),f[u].lam=At(f[u].lam-e.lam0),f[u].cosphi=r(f[u].phi),f[u].sinphi=i(f[u].phi);for(u=0;u<3;++u)p=2==u?0:u+1,f[u].v=m(f[p].phi-f[u].phi,f[u].cosphi,f[u].sinphi,f[p].cosphi,f[p].sinphi,f[p].lam-f[u].lam),f[u].v.r||U(-25);function m(e,n,s,o,a,l){var u,p,d,f={};return u=r(l),t(e)>1||t(l)>1?f.r=Qe(cs1*a+n*o*u):(p=i(.5*e),d=i(.5*l),f.r=2*Je(h(p*p+n*o*d*d))),t(f.r)>1e-9?f.Az=c(o*i(l),n*a-s*o*u):f.r=f.Az=0,f}function _(t,e,i){return Qe(.5*(t*t+e*e-i*i)/(t*e))}o=_(f[0].v.r,f[2].v.r,f[1].v.r),a=_(f[0].v.r,f[1].v.r,f[2].v.r),l=b-o,s=2*(f[0].p.y=f[1].p.y=f[2].v.r*i(o)),f[2].p.y=0,f[0].p.x=-(f[1].p.x=.5*f[0].v.r),n=f[2].p.x=f[0].p.x+f[2].v.r*r(o),e.es=0,e.fwd=function(t,e){var o,c,h,u,p,g,y,v=[];for(o=i(t.phi),c=r(t.phi),u=0;u<3&&(v[u]=m(t.phi-f[u].phi,f[u].cosphi,f[u].sinphi,c,o,t.lam-f[u].lam),v[u].r);++u)v[u].Az=At(v[u].Az-f[u].v.Az);if(u<3)g=f[u].p.x,y=f[u].p.y;else{for(g=n,y=s,u=0;u<3;++u)p=2==u?0:u+1,h=_(f[u].v.r,v[u].r,v[p].r),v[u].Az<0&&(h=-h),u?1==u?(h=a-h,g-=v[u].r*r(h),y-=v[u].r*i(h)):(h=l-h,g+=v[u].r*r(h),y+=v[u].r*i(h)):(g+=v[u].r*r(h),y-=v[u].r*i(h));g*=d,y*=d}e.x=g,e.y=y}},"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*s(.32573500793527993*t.y),i.lam=1.0233267079464885*t.x/(2*r((i.phi+i.phi)*e)-1)},t.fwd=function(t,n){t.phi*=e,n.x=.9772050238058398*t.lam*(2*r(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,o=1/Math.sqrt(e*n),a=.9701,l=d(22*T),c=f(0),u=i(l),p=r(l);function d(t){return s(n*i(t)+.4188*h(e*n))}function f(t){return e*t}Y(t.params,"tlon_0")||(t.lam0=11.023*T),t.es=0,t.fwd=function(t,e){var n=d(t.phi),s=f(t.lam),m=i(n),_=r(n),g=i(s-c),y=r(s-c),v=h(2/(1+i(l)*m+p*_*y));e.x=o*v*_*g*a,e.y=o*v*(p*m-u*_*y)/a}},"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*=r((.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,r=.3183098861837907;e.es=0,e.fwd=function(e,n){n.x=i*e.lam*(1-r*t(e.phi)),n.y=i*e.phi},e.inv=function(e,n){n.phi=e.y/i,n.lam=e.x/(i*(1-r*t(n.phi)))}},"eck1","Eckert I","PCyl Sph"),tt(function(e){var r=.46065886596178063,n=1.4472025091165353;e.es=0,e.fwd=function(e,s){s.x=r*e.lam*(s.y=h(4-3*i(t(e.phi)))),s.y=n*(2-s.y),e.phi<0&&(s.y=-s.y)},e.inv=function(e,i){i.lam=e.x/(r*(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?-E:E:i.phi=s(i.phi),e.y<0&&(i.phi=-i.phi)}},"eck2","Eckert II","PCyl Sph"),tt(function(t){oi(t,{C_x:.4222382003157712,C_y:.8444764006315424,A:1,B:.4052847345693511})},"eck3","Eckert III","PCyl Sph"),tt(function(t){oi(t,{C_x:.94745,C_y:.94745,A:0,B:.3039635509270133})},"wag6","Wagner VI","PCyl Sph"),tt(function(t){oi(t,{C_x:.8660254037844,C_y:1,A:0,B:.3039635509270133})},"kav7","Kavraisky VII","PCyl Sph"),tt(function(t){oi(t,{C_x:1.8949,C_y:.94745,A:-.5,B:.3039635509270133})},"putp1","Putnins P1","PCyl Sph"),tt(function(e){var n=.4222382003157712,s=1.3265004281770023,o=3.5707963267948966;e.es=0,e.fwd=function(e,a){var l,c,h,u,p;for(l=o*i(e.phi),c=e.phi*e.phi,e.phi*=.895168+c*(.0218849+.00826809*c),p=6;p&&(u=r(e.phi),h=i(e.phi),e.phi-=c=(e.phi+h*(u+2)-l)/(1+u*(u+2)-h*h),!(t(c)<1e-7));--p);p?(a.x=n*e.lam*(1+r(e.phi)),a.y=s*i(e.phi)):(a.x=n*e.lam,a.y=e.phi<0?-s:s)},e.inv=function(t,e){var a;e.phi=Je(t.y/s),e.lam=t.x/(n*(1+(a=r(e.phi)))),e.phi=Je((e.phi+i(e.phi)*(a+2))/o)}},"eck4","Eckert IV","PCyl Sph"),tt(function(t){t.es=0,t.fwd=function(t,e){e.x=.4410127717245515*(1+r(t.phi))*t.lam,e.y=.882025543449103*t.phi},t.inv=function(t,e){e.lam=2.267508027238226*t.x/(1+r(e.phi=1.133754013619113*t.y))}},"eck5","Eckert V","PCyl Sph"),tt(function(t){var e=r(Y(t.params,"rlat_ts"));e<=0&&U(-24),t.es=0,t.fwd=function(i,r){r.x=e*i.lam,r.y=i.phi-t.phi0},t.inv=function(i,r){r.lam=i.x/e,r.phi=i.y+t.phi0}},"eqc","Equidistant Cylindrical (Plate Caree)","Cyl, Sph\nlat_ts=[, lat_0=0]"),tt(function(e){var n,s,o,a,l,h,u,p,d,m,_,g,y;n=Y(e.params,"rlat_1"),s=Y(e.params,"rlat_2"),t(n+s)<R&&U(-21),(u=Xe(e.es))||e_error_0(),o=m=i(n),d=r(n),_=t(n-s)>=R,(p=e.es>0)?(y=We(m,d,e.es),g=Ye(n,m,d,u),_&&(m=i(s),d=r(s),o=(y-We(m,d,e.es))/(Ye(s,m,d,u)-g)),l=(h=g+y/o)-Ye(e.phi0,i(e.phi0),r(e.phi0),u)):(_&&(o=(d-r(s))/(s-n)),h=n+r(n)/o,l=h-e.phi0),e.fwd=function(t,e){a=h-(p?Ye(t.phi,i(t.phi),r(t.phi),u):t.phi),e.x=a*i(t.lam*=o),e.y=l-a*r(t.lam)},e.inv=function(t,i){0!=(a=f(t.x,t.y=l-t.y))?(o<0&&(a=-a,t.x=-t.x,t.y=-t.y),i.phi=h-a,p&&(i.phi=Ke(i.phi,e.es,u)),i.lam=c(t.x,t.y)/o):(i.lam=0,i.phi=o>0?E:-E)}},"eqdc","Equidistant Conic","Conic, Sph&Ell\nlat_1= lat_2="),tt(function(t){var e=1.340264,i=-.081106,r=893e-6,n=.003796,s=Math.sqrt(3)/2;t.es=0,t.fwd=function(t,o){var a=Math.asin(s*Math.sin(t.phi)),l=a*a,c=l*l*l;o.x=t.lam*Math.cos(a)/(s*(e+3*i*l+c*(7*r+9*n*l))),o.y=a*(e+i*l+c*(r+n*l))},t.inv=function(t,o){var a,l,c,h,u=t.y;for(h=0;h<12&&(u-=c=(u*(e+i*(a=u*u)+(l=a*a*a)*(r+n*a))-t.y)/(e+3*i*a+l*(7*r+9*n*a)),!(Math.abs(c)<1e-9));++h);l=(a=u*u)*a*a,o.lam=s*t.x*(e+3*i*a+l*(7*r+9*n*a))/Math.cos(u),o.phi=Math.asin(Math.sin(u)/s)}},"eqearth","Equal Earth","PCyl., Sph."),tt(ai,"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*l(.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,s,o,a,u,p,d,m=Y(t.params,"dh"),_=Y(t.params,"ssweep");_?"x"==_?d=1:"y"==_?d=0:U(-49):d=0,((u=m/t.a)<=0||u>1e10)&&U(-50),p=(a=1+u)*a-1,0!=t.es?(e=h(t.one_es),s=t.one_es,o=t.rone_es,t.inv=function(t,i){var s,m,_,g,y,v;s=-1,d?(_=n(t.y/u),m=n(t.x/u)*f(1,_)):(m=n(t.x/u),_=n(t.y/u)*f(1,m));var x=(y=2*a*s)*y-4*(g=m*m+(g=_/e)*g+s*s)*p;x<0&&U(-51),v=(-y-h(x))/(2*g),s=a+v*s,m*=v,_*=v,i.lam=c(m,s),i.phi=l(_*r(i.lam)/s),i.phi=l(o*n(i.phi))},t.fwd=function(t,c){var h,p,m,_,g;t.phi=l(s*n(t.phi)),h=e/f(e*r(t.phi),i(t.phi)),p=h*r(t.lam)*r(t.phi),m=h*i(t.lam)*r(t.phi),_=h*i(t.phi),(a-p)*p-m*m-_*_*o<0&&U(-51),g=a-p,d?(c.x=u*l(m/f(_,g)),c.y=u*l(_/g)):(c.x=u*l(m/g),c.y=u*l(_/f(m,g)))}):(e=s=o=1,t.inv=function(t,e){var i,s,o,f,m,_;i=-1,d?(o=n(t.y/u),s=n(t.x/u)*h(1+o*o)):(s=n(t.x/u),o=n(t.y/u)*h(1+s*s));var g=(m=2*a*i)*m-4*(f=s*s+o*o+i*i)*p;g<0&&U(-51),_=(-m-h(g))/(2*f),i=a+_*i,s*=_,o*=_,e.lam=c(s,i),e.phi=l(o*r(e.lam)/i)},t.fwd=function(t,e){var n=r(t.phi),s=r(t.lam)*n,o=i(t.lam)*n,c=i(t.phi);n=a-s,d?(e.x=u*l(o/f(c,n)),e.y=u*l(c/n)):(e.x=u*l(o/n),e.y=u*l(c/f(o,n)))})},"geos","Geostationary Satellite View","Azi, Sph&Ell"),tt(function(t){var e=a(Y(t.params,"tlat_1")?Y(t.params,"rlat_1"):0),s=i(e),o=r(e);function a(t){return Je(n(.5*t))}t.fwd=function(t,e){var n=.5*t.lam,l=a(t.phi),c=i(l),h=r(l),u=r(n);s*c+o*h*u>=0?(e.x=h*i(n),e.y=o*c-s*h*u):V()},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){Y(t.params,"tn"),Y(t.params,"tm")?ci(t,Y(t.params,"dm"),Y(t.params,"dn")):U(-99)},"gn_sinu","General Sinusoidal Series","PCyl, Sph.\nm= n="),tt(li,"sinu","Sinusoidal (Sanson-Flamsteed)","PCyl, Sph&Ell"),tt(function(t){ci(t,1,2.5707963267948966)},"eck6","Eckert VI","PCyl, Sph.\nm= n="),tt(function(t){ci(t,.5,1.7853981633974483)},"mbtfps","McBryde-Thomas Flat-Polar Sinusoidal","PCyl, Sph."),tt(function(e){var n,o,a=1e-10;t(t(e.phi0)-E)<a?o=e.phi0<0?1:0:t(e.phi0)<a?o=2:(o=3,sinph0=i(e.phi0),n=r(e.phi0)),e.inv=function(r,u){var p,d,m,_=r.x,g=r.y;if(p=f(_,g),m=i(u.phi=l(p)),d=h(1-m*m),t(p)<=a)u.phi=e.phi0,u.lam=0;else{switch(o){case 3:u.phi=d*sinph0+g*m*n/p,t(u.phi)>=1?u.phi=u.phi>0?E:-E:u.phi=s(u.phi),g=(d-sinph0*i(u.phi))*p,_*=m*n;break;case 2:u.phi=g*m/p,t(u.phi)>=1?u.phi=u.phi>0?E:-E:u.phi=s(u.phi),g=d*p,_*=m;break;case 1:u.phi-=E;break;case 0:u.phi=E-u.phi,g=-g}u.lam=c(_,g)}},e.fwd=function(t,e){var s,l,c;switch(c=i(t.phi),l=r(t.phi),s=r(t.lam),o){case 2:e.y=l*s;break;case 3:e.y=sinph0*c+n*l*s;break;case 1:e.y=-c;break;case 0:e.y=c}switch(e.y<=a&&V(),e.x=(e.y=1/e.y)*l*i(t.lam),o){case 2:e.y*=c;break;case 3:e.y*=n*c-sinph0*l*s;break;case 0:s=-s;case 1:e.y*=l*s}},e.es=0},"gnom","Gnomonic","Azi, Sph."),tt(hi,"moll","Mollweide","PCyl Sph"),tt(function(t){pi(t,ui(0,b/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,r,n,s,o=.0528,a=.7109307819790236;e.es=0,li(e),i=e.fwd,r=e.inv,hi(e),n=e.fwd,s=e.inv,e.fwd=function(e,r){t(e.phi)<a?i(e,r):(n(e,r),r.y-=e.phi>0?o:-o)},e.inv=function(e,i){t(e.y)<=a?r(e,i):(e.y+=e.y>0?o:-o,s(e,i))}},"goode","Goode Homolosine","PCyl, Sph."),tt(function(e){var n,s,o;e.inv=function(e,i){var r=h(1-.25*n*n*e.x*e.x-.25*e.y*e.y);t(2*r*r-1)<1e-10?(i.lam=v,i.phi=v,pj_errno=-14):(i.lam=ei(n*e.x*r,2*r*r-1)/n,i.phi=Je(r*e.y))},e.fwd=function(t,e){var a,l;l=h(2/(1+(a=r(t.phi))*r(t.lam*=n))),e.x=s*l*a*i(t.lam),e.y=o*l*i(t.phi)},e.es=0,Y(e.params,"tW")?(n=t(Y(e.params,"dW")))<=0&&U(-27):n=.5,Y(e.params,"tM")?(s=t(Y(e.params,"dM")))<=0&&U(-27):s=1,o=1/s,s/=n},"hammer","Hammer & Eckert-Greifendorff","Misc Sph,\nW= M="),tt(function(e){var n=1.000001;e.inv=function(e,o){var a=e.y*(e.y<0?.5179951515653813:.5686373742600607);t(a)>1?t(a)>n?j():a=a>0?E:-E:a=s(a),o.lam=1.1764705882352942*e.x/r(a),a+=a,o.phi=(a+i(a))*(e.y<0?.4102345310814193:.3736990601468637),t(o.phi)>1?t(o.phi)>n?j():o.phi=o.phi>0?E:-E:o.phi=s(o.phi)},e.fwd=function(e,n){var s,o,a;for(o=i(e.phi)*(e.phi<0?2.43763:2.67595),a=20;a&&(e.phi-=s=(e.phi+i(e.phi)-o)/(1+r(e.phi)),!(t(s)<1e-7));--a);n.x=.85*e.lam*r(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(di,"healpix","HEALPix","Sph., Ellps."),tt(function(t){di(t,!0)},"rhealpix","rHEALPix","Sph., Ellps.\nnorth_square= south_square="),tt(function(e){var n,o=i(.5),l=s(o),u=2*h(b/(n=b+4*l*2)),p=.5*u*(2+h(3));e.es=0,e.fwd=function(e,s){var o,a,d=1-i(e.phi);if(d&&d<2){var f,m,_,g,y,v=E-e.phi,x=25;do{m=i(v),_=r(v),y=l+c(m,2-_),v-=f=(v-1*l-2*m+(g=5-4*_)*y-.5*d*n)/(4*m*y)}while(t(f)>1e-12&&--x>0);o=u*h(g),a=e.lam*y/b}else o=u*(1+d),a=e.lam*l/b;s.x=o*i(a),s.y=p-o*r(a)},e.inv=function(t,e){var r=t.x,o=t.y,d=r*r+(o-=p)*o,f=(5-d/(u*u))/4,m=a(f),_=i(m),g=l+c(_,2-f);e.lam=s(r/h(d))*b/g,e.phi=s(1-2*(m-1*l-2*_+(5-4*f)*g)/n)}},"hill","Hill Eucyclic","PCyl., Sph."),tt(function(e){var o,a,p,d,f,m,_,g,y,v=.785398163397448,x=1.37008346281555;e.a=6377397.155,e.e=h(e.es=.006674372230614),Y(e.params,"tlat_0")||(e.phi0=.863937979737193),Y(e.params,"tlon_0")||(e.lam0=.4334234309119251),Y(e.params,"tk")||(e.k0=.9999),y=1,Y(e.params,"tczech")||(y=-1),d=h(1+e.es*u(r(e.phi0),4)/(1-e.es)),o=s(i(e.phi0)/d),p=u((1+e.e*i(e.phi0))/(1-e.e*i(e.phi0)),d*e.e/2),f=n(o/2+v)/u(n(e.phi0/2+v),d)*p,a=h(1-e.es)/(1-e.es*u(i(e.phi0),2)),m=i(x),_=e.k0*a/n(x),g=.5286277629901559,e.inv=function(o,a){var p,b,w,S,T,C,M,A;M=o.x,o.x=o.y,o.y=M,o.x*=y,o.y*=y,T=h(o.x*o.x+o.y*o.y),S=c(o.y,o.x)/i(x),w=2*(l(u(_/T,1/m)*n(x/2+v))-v),p=s(r(g)*i(w)-i(g)*r(w)*r(S)),b=s(r(w)*i(S)/r(p)),a.lam=e.lam0-b/d,C=p,A=0;do{a.phi=2*(l(u(f,-1/d)*u(n(p/2+v),1/d)*u((1+e.e*i(C))/(1-e.e*i(C)),e.e/2))-v),t(C-a.phi)<1e-15&&(A=1),C=a.phi}while(0===A);a.lam-=e.lam0},e.fwd=function(t,o){var a,c,h,p,b,w,S;a=u((1+e.e*i(t.phi))/(1-e.e*i(t.phi)),d*e.e/2),c=2*(l(f*u(n(t.phi/2+v),d)/a)-v),h=-t.lam*d,p=s(r(g)*i(c)+i(g)*r(c)*r(h)),b=s(r(c)*i(h)/r(p)),w=m*b,S=_*u(n(x/2+v),m)/u(n(p/2+v),m),o.y=S*r(w),o.x=S*i(w),o.y*=y,o.x*=y}},"krovak","Krovak","PCyl., Ellps."),tt(function(e){var n,o,a,l,u,p,d,m,_,g,y,v=1e-10;if(g=t(e.phi0),_=t(g-E)<v?e.phi0<0?1:0:t(g)<v?2:3,e.es){switch(e.e=h(e.es),u=Ze(1,e.e,e.one_es),e.es,m=ni(e.es),_){case 0:case 1:p=1;break;case 2:p=1/(d=h(.5*u)),a=1,l=.5*u;break;case 3:d=h(.5*u),y=i(e.phi0),n=Ze(y,e.e,e.one_es)/u,o=h(1-n*n),p=r(e.phi0)/(h(1-e.es*y*y)*d*o),l=(a=d)/p,a*=p}e.inv=function(t,a){var l,h,g,y,x=0;switch(_){case 2:case 3:if(t.x/=p,t.y*=p,(y=f(t.x,t.y))<v)return a.lam=0,a.phi=e.phi0,a;h=2*s(.5*y/d),l=r(h),h=i(h),t.x*=h,3==_?(x=l*n+t.y*h*o/y,t.y=y*o*l-t.y*n*h):(x=t.y*h/y,t.y=y*l);break;case 0:t.y=-t.y;case 1:if(!(g=t.x*t.x+t.y*t.y))return a.lam=0,a.phi=e.phi0,a;x=1-g/u,1==_&&(x=-x)}return a.lam=c(t.x,t.y),a.phi=si(s(x),m),a},e.fwd=function(s,c){var p,d,f,m,g=0,y=0,x=0;switch(p=r(s.lam),d=i(s.lam),f=i(s.phi),m=Ze(f,e.e,e.one_es),(3==_||2==_)&&(y=h(1-(g=m/u)*g)),_){case 3:x=1+n*g+o*y*p;break;case 2:x=1+y*p;break;case 0:x=E+s.phi,m=u-m;break;case 1:x=s.phi-E,m=u+m}switch(t(x)<v&&V(),_){case 3:case 2:3==_?(x=h(2/x),c.y=l*x*(o*g-n*y*p)):(x=h(2/(1+y*p)),c.y=x*g*l),c.x=a*x*y*d;break;case 0:case 1:m>=0?(x=h(m),c.x=x*d,c.y=p*(1==_?x:-x)):c.x=c.y=0}}}else 3==_&&(n=i(e.phi0),o=r(e.phi0)),e.inv=function(a,l){var h,u=0,p=0;switch(h=f(a.x,a.y),(l.phi=.5*h)>1&&j(),l.phi=2*s(l.phi),(3==_||2==_)&&(p=i(l.phi),u=r(l.phi)),_){case 2:l.phi=t(h)<=v?0:s(a.y*p/h),a.x*=p,a.y=u*h;break;case 3:l.phi=t(h)<=v?e.phi0:s(u*n+a.y*p*o/h),a.x*=p*o,a.y=(u-i(l.phi)*n)*h;break;case 0:a.y=-a.y,l.phi=E-l.phi;break;case 1:l.phi-=E}l.lam=0!=a.y||2!=_&&3!=_?c(a.x,a.y):0},e.fwd=function(s,a){var l,c,u;switch(u=i(s.phi),c=r(s.phi),l=r(s.lam),_){case 2:case 3:a.y=2==_?1+c*l:1+n*u+o*c*l,a.y<=v&&V(),a.y=h(2/a.y),a.x=a.y*c*i(s.lam),a.y*=2==_?u:o*u-n*c*l;break;case 0:l=-l;case 1:t(s.phi+e.phi0)<v&&V(),a.y=A-.5*s.phi,a.y=2*(1==_?r(a.y):i(a.y)),a.x=a.y*i(s.lam),a.y*=l}}},"laea","Lambert Azimuthal Equal Area","Azi, Sph&Ell"),tt(fi,"lonlat","Lat/long (Geodetic)",""),tt(fi,"longlat","Lat/long (Geodetic alias)",""),tt(fi,"latlon","Lat/long (Geodetic alias)",""),tt(fi,"latlong","Lat/long (Geodetic alias)",""),tt(function(e){var s,o,a,p,m,_,g,y,x,b,w,S=1e-10;e.inv=function(t,i){var r,n=t.x,s=t.y;n/=e.k0,s/=e.k0,0!=(r=f(n,s=g-s))?(_<0&&(r=-r,n=-n,s=-s),x?(i.phi=_i(u(r/y,1/_),e.e),i.phi==v&&j()):i.phi=2*l(u(y/r,1/_))-E,i.lam=c(n,s)/_):(i.lam=0,i.phi=_>0?E:-E)},e.fwd=function(s,o){var a,l=s.lam;t(t(s.phi)-E)<S?(s.phi*_<=0&&V(),a=0):a=y*(x?u(mi(s.phi,i(s.phi),e.e),_):u(n(A+.5*s.phi),-_)),l*=_,o.x=e.k0*(a*i(l)),o.y=e.k0*(g-a*r(l))},p=Y(e.params,"rlat_1"),Y(e.params,"tlat_2")?m=Y(e.params,"rlat_2"):(m=p,Y(e.params,"tlat_0")||(e.phi0=p)),t(p+m)<S&&U(-21),_=o=i(p),s=r(p),a=t(p-m)>=S,(x=0!=e.es)?(e.e=h(e.es),w=We(o,s,e.es),b=mi(p,o,e.e),a&&(o=i(m),_=d(w/We(o,r(m),e.es)),_/=d(b/mi(m,o,e.e))),y=g=w*u(b,-_)/_,g*=t(t(e.phi0)-E)<S?0:u(mi(e.phi0,i(e.phi0),e.e),_)):(a&&(_=d(s/r(m))/d(n(A+.5*m)/n(A+.5*p))),y=s*u(n(A+.5*p),_)/_,g=t(t(e.phi0)-E)<S?0:y*u(n(A+.5*e.phi0),-_))},"lcc","Lambert Conformal Conic","Conic, Sph&Ell\nlat_1= and lat_2= or lat_0="),tt(function(e){var i,s,o,a=1e-8;i=Y(e.params,"rlat_1"),s=r(i),o=n(A+.5*i),s<a&&U(-22),e.fwd=function(e,r){r.y=e.phi-i,t(r.y)<a?r.x=e.lam*s:(r.x=A+.5*e.phi,t(r.x)<a||t(t(r.x)-E)<a?r.x=0:r.x=e.lam*r.y/d(n(r.x)/o))},e.inv=function(e,r){r.phi=e.y+i,t(e.y)<a?r.lam=e.x/s:(r.lam=A+.5*r.phi,t(r.lam)<a||t(t(r.lam)-E)<a?r.lam=0:r.lam=e.x*d(n(r.lam)/o)/e.y)},e.es=0},"loxim","Loximuthal","PCyl Sph"),tt(function(e){var n=.9525793444156804,o=.9258200997725514,a=3.401680257083045,l=2/3,c=1/3,h=1.0000001;e.fwd=function(t,e){t.phi=s(n*i(t.phi)),e.x=o*t.lam*(2*r(l*t.phi)-1),e.y=a*i(c*t.phi)},e.inv=function(e,c){c.phi=e.y/a,t(c.phi)>=1?t(c.phi)>h?j():c.phi=c.phi<0?-E:E:c.phi=s(c.phi),c.lam=e.x/(o*(2*r(l*(c.phi*=3))-1)),t(c.phi=i(c.phi)/n)>=1?t(c.phi)>h?j():c.phi=c.phi<0?-E:E:c.phi=s(c.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 s,o,a;for(o=1.7071067811865475*i(e.phi),a=20;a&&(e.phi-=s=(i(.5*e.phi)+i(e.phi)-o)/(.5*r(.5*e.phi)+r(e.phi)),!(t(s)<1e-7));--a);n.x=.3124597141037825*e.lam*(1+2*r(e.phi)/r(.5*e.phi)),n.y=1.874758284622695*i(.5*e.phi)},e.inv=function(e,o){var a;o.phi=.533402096794177*e.y,t(o.phi)>1?t(o.phi)>n?j():o.phi<0?(a=-1,o.phi=-b):(a=1,o.phi=b):o.phi=2*s(a=o.phi),o.lam=3.2004125807650623*e.x/(1+2*r(o.phi)/r(.5*o.phi)),o.phi=.585786437626905*(a+i(o.phi)),t(o.phi)>1?t(o.phi)>n?j():o.phi=o.phi<0?-E:E:o.phi=s(o.phi)},e.es=0},"mbt_fpq","McBryde-Thomas Flat-Polar Quartic","Cyl., Sph."),tt(function(e){var n=.45503,s=1.36509,o=1.41546,a=.22248,l=1.44492,c=1/3;e.fwd=function(e,h){var u,p,d,f;for(u=o*i(e.phi),f=10;f&&(d=e.phi/s,e.phi-=p=(n*i(d)+i(e.phi)-u)/(c*r(d)+r(e.phi)),!(t(p)<1e-7));--f);d=e.phi/s,h.x=a*e.lam*(1+3*r(e.phi)/r(d)),h.y=l*i(d)},e.inv=function(t,e){var c;e.phi=s*(c=Je(t.y/l)),e.lam=t.x/(a*(1+3*r(e.phi)/r(c))),e.phi=Je((n*i(c)+i(e.phi))/o)},e.es=0},"mbt_fps","McBryde-Thomas Flat-Pole Sine (No. 2)","Cyl., Sph."),tt(function(e){var s=1e-10,o=0,a=Y(e.params,"tlat_ts");a&&(o=Y(e.params,"rlat_ts"))>=E&&U(-24),e.es?(a&&(e.k0=We(i(o),r(o),e.es)),e.inv=function(t,i){i.phi=_i(p(-t.y/e.k0),e.e),i.phi===v&&j(),i.lam=t.x/e.k0},e.fwd=function(r,n){t(t(r.phi)-E)<=s&&V(),n.x=e.k0*r.lam,n.y=-e.k0*d(mi(r.phi,i(r.phi),e.e))}):(e.inv=function(t,i){i.phi=E-2*l(p(-t.y/e.k0)),i.lam=t.x/e.k0},e.fwd=function(i,r){t(t(i.phi)-E)<=s&&V(),r.x=e.k0*i.lam,r.y=e.k0*d(n(A+.5*i.phi))})},"merc","Mercator","Cyl, Sph&Ell\nlat_ts="),tt(function(e){e.k0=1,e.inv=function(t,i){i.phi=E-2*l(p(-t.y/e.k0)),i.lam=t.x/e.k0},e.fwd=function(i,r){t(t(i.phi)-E)<=R&&V(),r.x=e.k0*i.lam,r.y=e.k0*d(n(A+.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*d(n(A+.4*t.phi))},t.inv=function(t,e){e.lam=t.x,e.phi=2.5*(l(p(.8*t.y))-A)},t.es=0},"mill","Miller Cylindrical","Cyl, Sph"),tt(function(t){t.lam0=20*T,t.phi0=18*T,t.es=0,vi(t,[[.9245,0],[0,0],[.01943,0]])},"mil_os","Miller Oblated Stereographic","Azi(mod)"),tt(function(t){t.lam0=-165*T,t.phi0=-10*T,t.es=0,vi(t,[[.721316,0],[0,0],[-.0088162,-.00617325]])},"lee_os","Lee Oblated Stereographic","Azi(mod)"),tt(function(t){t.lam0=-96*T,t.phi0=39*T,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*T,t.phi0=64*T,0!=t.es?(e=[[.9945303,0],[.0052083,-.0027404],[.0072721,.0048181],[-.0151089,-.1932526],[.0642675,-.1381226],[.3582802,-.2884586]],t.a=6378206.4,t.e=h(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*T,t.phi0=45*T,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=h(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,r=-.131979,n=-.013791,s=.003971,o=-.001529,a=1.007226,l=.015085,c=-.044475,h=.028874,u=-.005916,p=a,d=3*l,f=7*c,m=9*h,_=11*u,g=.8707*.52*b;e.es=0,e.fwd=function(t,e){var p,d;d=(p=t.phi*t.phi)*p,e.x=t.lam*(i+p*(r+p*(n+d*p*(s+p*o)))),e.y=t.phi*(a+p*(l+d*(c+h*p+u*d)))},e.inv=function(e,y){var v,x,b,w,S=e.x,T=e.y;for(T>g?T=g:T<-g&&(T=-g),v=T;v-=x=(v*(a+(b=v*v)*(l+(w=b*b)*(c+h*b+u*w)))-T)/(p+b*(d+w*(f+m*b+_*w))),!(t(x)<1e-11););y.phi=v,b=v*v,y.lam=S/(i+b*(r+b*(n+b*b*b*(s+b*o))))}},"natearth","Natural Earth","PCyl., Sph."),tt(function(e){var i=.84719,r=-.13063,n=-.04515,s=.05494,o=-.02326,a=.00331,l=1.01183,c=-.02625,h=.01926,u=-.00396,p=l,d=9*c,f=.45334622460635143*b;e.es=0,e.fwd=function(t,e){var p,d,f;f=(p=t.phi*t.phi)*(d=p*p),e.x=t.lam*(i+r*p+f*f*(n+s*p+o*d+a*f)),e.y=t.phi*(l+d*d*(c+h*p+u*d))},e.inv=function(e,m){var _,g,y,v,x,b=e.x,w=e.y;for(w>f?w=f:w<-f&&(w=-f),_=w;_-=g=(_*(l+(v=(y=_*_)*y)*v*(c+h*y+u*v))-w)/(p+v*v*(d+.21186*y+-.05148*v)),!(t(g)<1e-11););m.phi=_,x=(y=_*_)*(v=y*y),m.lam=b/(i+r*y+x*x*(n+s*y+o*v+a*x))}},"natearth2","Natural Earth 2","PCyl., Sph."),tt(function(e){e.inv=function(t,e){e.lam=2*t.x/(1+r(t.y)),e.phi=Je(.5*(t.y+i(t.y)))},e.fwd=function(e,n){var s,o,a;for(s=2*i(e.phi),o=e.phi*e.phi,e.phi*=1.00371+o*(-.011412*o-.0935382),a=10;a&&(e.phi-=o=(e.phi+i(e.phi)-s)/(1+r(e.phi)),!(t(o)<1e-7));--a);n.x=.5*e.lam*(1+r(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+r(t.phi)),e.y=2*(t.phi-n(.5*t.phi))},e.inv=function(e,i){var s,o,a,l;for(a=.5*e.y,l=9;l>0&&(o=r(.5*i.phi),i.phi-=s=(i.phi-n(i.phi/2)-a)/(1-.5/(o*o)),!(t(s)<1e-7));--l);l?i.lam=2*e.x/(1+r(i.phi)):(i.phi=a<0?-E:E,i.lam=2*e.x)}},"nell_h","Nell-Hammer","PCyl., Sph."),tt(function(e){e.es=0,e.fwd=function(e,n){var s=1e-10;if(t(e.lam)<s)n.x=0,n.y=e.phi;else if(t(e.phi)<s)n.x=e.lam,n.y=0;else if(t(t(e.lam)-E)<s)n.x=e.lam*r(e.phi),n.y=E*i(e.phi);else if(t(t(e.phi)-E)<s)n.x=0,n.y=e.phi;else{var o=E/e.lam-e.lam/E,a=e.phi/E,l=i(e.phi),c=(1-a*a)/(l-a),u=o/c,p=(o*l/c-.5*o)/(1+(u*=u)),d=(l/u+.5*c)/(1+1/u);n.x=r(e.phi),n.x=h(p*p+n.x*n.x/(1+u)),n.x=E*(p+(e.lam<0?-n.x:n.x)),n.y=h(d*d-(l*l/u+c*l-1)/(1+1/u)),n.y=E*(d+(e.phi<0?n.y:-n.y))}}},"nicol","Nicolosi Globular","Misc Sph, no inv"),tt(function(t){xi(t,Y(t.params,"dh"))},"nsper","Near-sided perspective","Azi, Sph\nh="),tt(function(t){var e=Y(t.params,"dtilt")*T,i=Y(t.params,"dazi")*T,r=Y(t.params,"dh");xi(t,r,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]],r=[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*T,e.phi0=-41*T,e.x0=251e4,e.y0=6023150,e.inv=function(n,s){var o,a,l,c,h,u,p={r:n.y,i:n.x},d={};for(o=20;o>0&&((h=yi(p,i,d)).r-=n.y,h.i-=n.x,u=d.r*d.r+d.i*d.i,p.r+=l=-(h.r*d.r+h.i*d.i)/u,p.i+=c=-(h.i*d.r-h.r*d.i)/u,!(t(l)+t(c)<=1e-10));--o);if(o>0){for(s.lam=p.i,a=r.length-1,s.phi=r[a],--a;a>=0;--a)s.phi=r[a]+p.r*s.phi;s.phi=e.phi0+p.r*s.phi*.484813681109536}else s.lam=s.phi=v},e.fwd=function(t,r){var s=n.length-1,o={r:n[s]},a=2.0626480624709638*(t.phi-e.phi0);for(--s;s>=0;--s)o.r=n[s]+a*o.r;o.r*=a,o.i=t.lam,o=gi(o,i),r.x=o.i,r.y=o.r}},"nzmg","New Zealand Map Grid","fixed Earth"),tt(function(e){var s,o,a,h,u,p,d,f,m,_,g,y,x,b,w,C=1e-10;s=Y(e.params,"so_proj"),o=Q[s],s||U(-26),o&&"ob_tran"!=s||U(-37),e.es=0,a={},Object.keys(e).forEach(function(t){a[t]=e[t]}),o.init(a),a.is_latlong&&1==e.to_meter&&(e.to_meter=T,e.fr_meter=S),Y(e.params,"to_alpha")?(f=Y(e.params,"ro_lon_c"),m=Y(e.params,"ro_lat_c"),_=Y(e.params,"ro_alpha"),t(t(m)-E)<=C&&U(-32),h=f+ei(-r(_),-i(_)*i(m)),d=Je(r(m)*i(_))):Y(e.params,"to_lat_p")?(h=Y(e.params,"ro_lon_p"),d=Y(e.params,"ro_lat_p")):(g=Y(e.params,"ro_lon_1"),x=Y(e.params,"ro_lat_1"),y=Y(e.params,"ro_lon_2"),b=Y(e.params,"ro_lat_2"),(t(x-b)<=C||(w=t(x))<=C||t(w-E)<=C||t(t(b)-E)<=C)&&U(-33),h=c(r(x)*i(b)*r(g)-i(x)*r(b)*r(y),i(x)*r(b)*i(y)-r(x)*i(b)*i(g)),d=l(-r(h-g)/n(x))),t(d)>C?(u=r(d),p=i(d),e.fwd=function(t,e){var n,s,o;n=r(t.lam),s=i(t.phi),o=r(t.phi),t.lam=At(ei(o*i(t.lam),p*o*n+u*s)+h),t.phi=Je(p*s-u*o*n),a.fwd(t,e)},e.inv=a.inv?function(t,e){var n,s,o;a.inv(t,e),e.lam!=v&&(n=r(e.lam-=h),s=i(e.phi),o=r(e.phi),e.phi=Je(p*s+u*o*n),e.lam=ei(o*i(e.lam),p*o*n-u*s))}:null):(e.fwd=function(t,e){var n,s;n=r(t.phi),s=r(t.lam),t.lam=At(ei(n*i(t.lam),i(t.phi))+h),t.phi=Je(-n*s),a.fwd(t,e)},e.inv=a.inv?function(t,e){var n,s;a.inv(t,e),e.lam!=v&&(n=r(e.phi),s=e.lam-h,e.lam=ei(n*i(s),-i(e.phi)),e.phi=Je(n*r(s)))}: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,o,a,u,p,d,f,m,_,g,y;f=1/t.k0,m=t.k0,Y(t.params,"talpha")?(d=Y(t.params,"ralpha"),p=Y(t.params,"rlonc"),y=l(-r(d)/(-i(0)*i(d)))+p,_=s(r(0)*i(d))):(e=Y(t.params,"rlat_1"),o=Y(t.params,"rlat_2"),a=Y(t.params,"rlon_1"),u=Y(t.params,"rlon_2"),y=c(r(e)*i(o)*r(a)-i(e)*r(o)*r(u),i(e)*r(o)*i(u)-r(e)*i(o)*i(a)),a==-E&&(y=-y),_=l(-r(y-a)/n(e))),t.lam0=y+E,g=r(_),_=i(_),y=i(y),t.es=0,t.fwd=function(t,e){var s;e.y=i(t.lam),s=r(t.lam),e.x=l((n(t.phi)*g+_*e.y)/s),s<0&&(e.x+=b),e.x*=m,e.y=f*(_*i(t.phi)-g*r(t.phi)*e.y)},t.inv=function(t,e){var n,o;t.y/=f,t.x/=m,n=h(1-t.y*t.y),e.phi=s(t.y*_+n*g*(o=i(t.x))),e.lam=c(n*_*o-t.y*g,n*r(t.x))}},"ocea","Oblique Cylindrical Equal Area","Cyl, Sph lonc= alpha= or\nlat_1= lat_2= lon_1= lon_2="),tt(function(e){var o,a,f,m,_,g,y,x,w,S,T,C,M,I,D,k,z,L,F,B,O,N,G,q,$,Z,W,H=1e-7,X=0,K=0,J=0,Q=0,tt=0,et=0,it=0,rt=0;W=Y(e.params,"tno_rot"),0!=(C=Y(e.params,"talpha"))&&(it=Y(e.params,"ralpha")),0!=(M=Y(e.params,"tgamma"))&&(X=Y(e.params,"rgamma")),C||M?(K=Y(e.params,"rlonc"),(rt=Y(e.params,"tno_off")||Y(e.params,"tno_uoff"))&&(Y(e.params,"sno_uoff"),Y(e.params,"sno_off"))):(J=Y(e.params,"rlon_1"),tt=Y(e.params,"rlat_1"),Q=Y(e.params,"rlon_2"),et=Y(e.params,"rlat_2"),(t(tt-et)<=H||(o=t(tt))<=H||t(o-E)<=H||t(t(e.phi0)-E)<=H||t(t(et)-E)<=H)&&U(-33)),a=h(e.one_es),t(e.phi0)>R?(x=i(e.phi0),f=r(e.phi0),o=1-e.es*x*x,D=f*f,D=h(1+e.es*D*D/e.one_es),I=D*e.k0*a/o,(_=(m=D*a/(f*h(o)))*m-1)<=0?_=0:(_=h(_),e.phi0<0&&(_=-_)),k=_+=m,k*=u(mi(e.phi0,x,e.e),D)):(D=1/a,I=e.k0,k=m=_=1),C||M?(C?(T=s(i(it)/m),M||(X=it)):it=s(m*i(T=X)),e.lam0=K-s(.5*(_-1/_)*n(T))/D):(g=u(mi(tt,i(tt),e.e),D),y=u(mi(et,i(et),e.e),D),_=k/g,w=(y-g)/(y+g),S=((S=k*k)-y*g)/(S+y*g),(o=J-Q)<-b?Q-=P:o>b&&(Q+=P),e.lam0=At(.5*(J+Q)-l(S*n(.5*D*(J-Q))/w)/D),T=l(2*i(D*At(J-e.lam0))/(_-1/_)),X=it=s(m*i(T))),B=i(T),O=r(T),N=i(X),G=r(X),L=1/(z=I*(F=1/D)),rt?Z=0:(Z=t(z*l(h(m*m-1)/r(it))),e.phi0<0&&(Z=-Z)),q=z*d(n(A-(_=.5*T))),$=z*d(n(A+_)),e.fwd=function(n,s){var o,a,l,h,p,f,m,_;t(t(n.phi)-E)>R?(o=.5*((p=k/u(mi(n.phi,i(n.phi),e.e),D))-(f=1/p)),a=.5*(p+f),h=i(D*n.lam),t(t(l=(o*B-h*O)/a)-1)<R&&V(),_=.5*z*d((1-l)/(1+l)),f=r(D*n.lam),m=t(f)<H?I*n.lam:z*c(o*O+h*B,f)):(_=n.phi>0?q:$,m=z*n.phi),W?(s.x=m,s.y=_):(m-=Z,s.x=_*G+m*N,s.y=m*G-_*N)},e.inv=function(n,s){var o,a,l,d,f,m,_;W?(a=n.y,o=n.x):(a=n.x*G-n.y*N,o=n.y*G+n.x*N+Z),d=.5*((l=p(-L*a))-1/l),f=.5*(l+1/l),m=i(L*o),t(t(_=(m*O+d*B)/f)-1)<R?(s.lam=0,s.phi=_<0?-E:E):(s.phi=k/h((1+_)/(1-_)),(s.phi=_i(u(s.phi,1/D),e.e))==v&&j(),s.lam=-F*c(d*O-m*B,r(L*o)))}},"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,o={};t(t(e.phi0)-E)<=n?o.mode=e.phi0<0?1:0:t(e.phi0)>n?(o.mode=3,o.sinph0=i(e.phi0),o.cosph0=r(e.phi0)):o.mode=2,e.fwd=function(s,a){var l,c,h;switch(c=r(s.phi),l=r(s.lam),o.mode){case 2:c*l<-1e-10&&V(),a.y=i(s.phi);break;case 3:o.sinph0*(h=i(s.phi))+o.cosph0*c*l<-1e-10&&V(),a.y=o.cosph0*h-o.sinph0*c*l;break;case 0:l=-l;case 1:t(s.phi-e.phi0)-n>E&&V(),a.y=c*l}a.x=c*i(s.lam)},e.inv=function(i,r){var l,u,p;if((p=l=f(i.x,i.y))>1&&(p-1>n&&j(),p=1),u=h(1-p*p),t(l)<=n)r.phi=e.phi0,r.lam=0;else{switch(o.mode){case 0:i.y=-i.y,r.phi=a(p);break;case 1:r.phi=-a(p);break;case 2:case 3:2==o.mode?(r.phi=i.y*p/l,i.x*=p,i.y=u*l):(r.phi=u*o.sinph0+i.y*p*o.cosph0/l,i.y=(u-o.sinph0*r.phi)*l,i.x*=p*o.cosph0),t(r.phi)>=1?r.phi=r.phi<0?-E:E:r.phi=s(r.phi)}r.lam=0!=i.y||3!=o.mode&&2!=o.mode?c(i.x,i.y):0==i.x?0:i.x<0?-E:E}},e.es=0},"ortho","Orthographic","Azi, Sph."),tt(function(e){var i=1.0148,r=.23185,n=-.14499,s=.02406,o=i,a=5*r,l=7*n,c=908571831.7;e.es=0,e.fwd=function(t,e){var o=t.phi*t.phi;e.x=t.lam,e.y=t.phi*(i+o*o*(r+o*(n+s*o)))},e.inv=function(e,h){var u,p,d,f;for(u=e.y,e.y>c?e.y=c:e.y<-c&&(e.y=-c),f=100;f&&(u-=p=(u*(i+(d=u*u)*d*(r+d*(n+s*d)))-e.y)/(o+d*d*(a+d*(l+.21654*d))),!(t(p)<1e-11));--f);h.phi=u,h.lam=e.x}},"patterson","Patterson Cylindrical","Cyl., Sph."),tt(function(e){var o,a,l=1e-10,c=1e-12;e.es?(a=Xe(e.es),o=Ye(e.phi0,i(e.phi0),r(e.phi0),a),e.fwd=function(n,s){var c,h,u;t(n.phi)<=l?(s.x=n.lam,s.y=-o):(h=i(n.phi),c=t(u=r(n.phi))>l?We(h,u,e.es)/h:0,s.x=c*i(n.lam*=h),s.y=Ye(n.phi,h,u,a)-o+c*(1-r(n.lam)))},e.inv=function(u,p){var d,f,m,_,g,y,v,x,b,w,S=u.x,T=u.y;if(t(T+=o)<=l)p.lam=S,p.phi=0;else{for(d=T*T+S*S,p.phi=T,w=20;w>0&&(g=(m=i(p.phi))*(_=r(p.phi)),t(_)<c&&j(),f=m*(x=h(1-e.es*m*m))/_,v=(y=Ye(p.phi,m,_,a))*y+d,x=e.one_es/(x*x*x),p.phi+=b=(y+y+f*v-2*T*(f*y+1))/(e.es*g*(v-2*T*y)/f+2*(T-y)*(f*x-1/g)-x-x),!(t(b)<=c));--w);w||j(),f=i(p.phi),p.lam=s(S*n(p.phi)*h(1-e.es*f*f))/i(p.phi)}}):(o=-e.phi0,e.fwd=function(s,a){var c,h;t(s.phi)<=l?(a.x=s.lam,a.y=o):(c=1/n(s.phi),a.x=i(h=s.lam*i(s.phi))*c,a.y=s.phi-e.phi0+c*(1-r(h)))},e.inv=function(r,o){var a,c,h,u;if(t(r.y=e.phi0+r.y)<=l)o.lam=r.x,o.phi=0;else{o.phi=r.y,a=r.x*r.x+r.y*r.y,u=10;do{h=n(o.phi),o.phi-=c=(r.y*(o.phi*h+1)-o.phi-.5*(o.phi*o.phi+a)*h)/((o.phi-r.y)/h-1)}while(t(c)>1e-10&&--u);u||j(),o.lam=s(r.x*n(o.phi))/i(o.phi)}})},"poly","Polyconic (American)","Conic, Sph&Ell"),tt(function(e){var n=1.8949,s=1.71848,o=.6141848493043784,a=1.0471975511965976;e.es=0,e.fwd=function(e,l){var c,h,u,p,d;for(c=o*i(e.phi),u=e.phi*e.phi,e.phi*=.615709+u*(.00909953+.0046292*u),d=10;d&&(h=r(e.phi),u=i(e.phi),e.phi-=p=(e.phi+u*(h-1)-c)/(1+h*(h-1)-u*u),!(t(p)<1e-10));--d);d||(e.phi=e.phi<0?-a:a),l.x=n*e.lam*(r(e.phi)-.5),l.y=s*i(e.phi)},e.inv=function(t,e){var a;e.phi=Je(t.y/s),e.lam=t.x/(n*((a=r(e.phi))-.5)),e.phi=Je((e.phi+i(e.phi)*(a-1))/o)}},"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(Ti,"putp6","Putnins P6","PCyl., Sph."),tt(function(t){Ti(t,!0)},"putp6p","Putnins P6'","PCyl., Sph."),tt(function(e){var s,o,u,p;function d(e,i,r){var n,s;return e<1e-10?(n=0,s=0):(s=c(i,r),t(s)<=A?n=0:s>A&&s<=E+A?(n=1,s-=E):s>E+A||s<=-(E+A)?(n=2,s=s>=0?s-b:s+b):(n=3,s+=E)),{area:n,theta:s}}function f(t,e){var i=t+e;return i<-b?i+=P:i>+b&&(i-=P),i}s=e.phi0>=E-A/2?4:e.phi0<=-(E-A/2)?5:t(e.lam0)<=A?0:t(e.lam0)<=E+A?e.lam0>0?1:3:2,0!==e.es&&(e.a,e.a,o=e.a*h(1-e.es),u=1-(e.a-o)/e.a,p=u*u),e.fwd=function(t,o){var c,u,m,_,g,y,v,x,w,S,T,C,M,P;c=0!==e.es?l(p*n(t.phi)):t.phi,u=t.lam,4==s?(_=E-c,u>=A&&u<=E+A?(v=0,m=u-E):u>E+A||u<=-(E+A)?(v=1,m=u>0?u-b:u+b):u>-(E+A)&&u<=-A?(v=2,m=u+E):(v=3,m=u)):5==s?(_=E+c,u>=A&&u<=E+A?(v=0,m=-u+E):u<A&&u>=-A?(v=1,m=-u):u<-A&&u>=-(E+A)?(v=2,m=-u-E):(v=3,m=u>0?-u+b:-u-b)):(1==s?u=f(u,+E):2==s?u=f(u,+b):3==s&&(u=f(u,-E)),T=i(c),C=r(c),M=i(u),x=C*r(u),w=C*M,S=T,0==s?P=d(_=a(x),S,w):1==s?P=d(_=a(w),S,-x):2==s?P=d(_=a(-x),S,-w):3==s?P=d(_=a(-w),S,x):(_=0,P={area:0,theta:0}),m=P.theta,v=P.area),y=l(12/b*(m+a(i(m)*r(A))-E)),g=h((1-r(_))/(r(y)*r(y))/(1-r(l(1/r(m))))),1==v?y+=E:2==v?y+=b:3==v&&(y+=I),o.x=g*r(y),o.y=g*i(y)},e.inv=function(d,m){var _,g,y,v,x,w,S,T,C,M,A,I,P;if(g=l(h(d.x*d.x+d.y*d.y)),_=c(d.y,d.x),d.x>=0&&d.x>=t(d.y)?M=0:d.y>=0&&d.y>=t(d.x)?(M=1,_-=E):d.x<0&&-d.x>=t(d.y)?(M=2,_=_<0?_+b:_-b):(M=3,_+=E),C=b/12*n(_),x=i(C)/(r(C)-1/h(2)),w=l(x),(S=1-(y=r(_))*y*(v=n(g))*v*(1-r(l(1/r(w)))))<-1?S=-1:S>1&&(S=1),4==s)T=a(S),m.phi=E-T,m.lam=0==M?w+E:1==M?w<0?w+b:w-b:2==M?w-E:w;else if(5==s)T=a(S),m.phi=T-E,m.lam=0==M?-w+E:1==M?-w:2==M?-w-E:w<0?-w-b:-w+b;else{var D,k,z;C=(D=S)*D,k=(C+=(z=C>=1?0:h(1-C)*i(w))*z)>=1?0:h(1-C),1==M?(C=k,k=-z,z=C):2==M?(k=-k,z=-z):3==M&&(C=k,k=z,z=-C),1==s?(C=D,D=-k,k=C):2==s?(D=-D,k=-k):3==s&&(C=D,D=k,k=-C),m.phi=a(-z)-E,m.lam=c(k,D),1==s?m.lam=f(m.lam,-E):2==s?m.lam=f(m.lam,-b):3==s&&(m.lam=f(m.lam,+E))}0!==e.es&&(A=m.phi<0?1:0,I=n(m.phi),P=o/h(I*I+p),m.phi=l(h(e.a*e.a-P*P)/(u*P)),A&&(m.phi=-m.phi))}},"qsc","Quadrilateralized Spherical Cube","Azi, Sph."),tt(function(i){var r=c([[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=c([[-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,o=1.3523;function a(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 c(t){return t.map(function(t){return new Float32Array(t)})}i.es=0,i.fwd=function(i,l){var c,h;(c=e(11.459155902616464*(h=t(i.phi))))<0&&V(),c>=18&&(c=17),h=S*(h-.08726646259971647*c),l.x=a(r[c],h)*s*i.lam,l.y=a(n[c],h)*o,i.phi<0&&(l.y=-l.y)},i.inv=function(i,c){var h,u,p,d;if(c.lam=i.x/s,c.phi=t(i.y/o),c.phi>=1)c.phi>1.000001?j():(c.phi=i.y<0?-E:E,c.lam/=r[18][0]);else{if((d=e(18*c.phi))<0||d>=18)return j();for(;;)if(n[d][0]>c.phi)--d;else{if(!(n[d+1][0]<=c.phi))break;++d}for(p=new Float32Array(n[d]),h=5*(c.phi-p[0])/(n[d+1][0]-p[0]),p[0]-=c.phi;h-=u=a(p,h)/l(p,h),!(t(u)<1e-8););c.phi=(5*d+h)*T,i.y<0&&(c.phi=-c.phi),c.lam/=a(r[d],h)}}},"robin","Robinson","PCyl., Sph."),tt(Ci("EULER"),"euler","Euler","Conic, Sph\nlat_1= and lat_2="),tt(Ci("MURD1"),"murd1","Murdoch I","Conic, Sph\nlat_1= and lat_2="),tt(Ci("MURD2"),"murd2","Murdoch II","Conic, Sph\nlat_1= and lat_2="),tt(Ci("MURD3"),"murd3","Murdoch III","Conic, Sph\nlat_1= and lat_2="),tt(Ci("PCONIC"),"pconic","Perspective Conic","Conic, Sph\nlat_1= and lat_2="),tt(Ci("TISSOT"),"tissot","Tissot","Conic, Sph\nlat_1= and lat_2="),tt(Ci("VITK1"),"vitk1","Vitkovsky I","Conic, Sph\nlat_1= and lat_2="),tt(function(e){var s,o,a,c,u,f,m,_,g;a=.5*e.e,m=r(e.phi0),m*=m,o=h(1+e.es*m*m*e.rone_es),g=i(e.phi0),u=r(_=Je(f=g/o)),g*=e.e,s=d(n(A+.5*_))-o*(d(n(A+.5*e.phi0))-a*d((1+g)/(1-g))),c=e.k0*h(e.one_es)/(1-g*g),e.inv=function(h,m){var _,g,y,v,x,b,w,S,T;for(y=2*(l(p(h.y/c))-A),v=h.x/c,x=r(y),_=Je(u*i(y)+f*x*r(v)),g=Je(x*i(v)/r(_)),w=(s-d(n(A+.5*_)))/o,T=6;T&&(b=e.e*i(_),_-=S=(w+d(n(A+.5*_))-a*d((1+b)/(1-b)))*(1-b*b)*r(_)*e.rone_es,!(t(S)<1e-10));--T);T?(m.phi=_,m.lam=g/o):j()},e.fwd=function(t,h){var m,_,g,y,v,x;v=e.e*i(t.phi),m=2*l(p(o*(d(n(A+.5*t.phi))-a*d((1+v)/(1-v)))+s))-E,_=o*t.lam,x=r(m),g=Je(u*i(m)-f*x*r(_)),y=Je(x*i(_)/r(g)),h.x=c*y,h.y=c*d(n(A+.5*g))}},"somerc","Swiss. Obl. Mercator","Cyl, Ell\nFor CH1903"),tt(function(t){var e=Y(t.params,"tlat_ts")?Y(t.params,"rlat_ts"):E;Mi(t,e)},"stere","Stereographic","Azi, Sph&Ell\nlat_ts="),tt(function(t){t.phi0=Y(t.params,"bsouth")?-E:E,t.k0=.994,t.x0=2e6,t.y0=2e6,t.lam0=0,t.es||U(-34),Mi(t,E)},"ups","Universal Polar Stereographic","Azi, Sph&Ell\nsouth"),tt(function(e){var o,a,p,d,m,_,g,y,v,x=(o=e.e,a=e.phi0,p=o*o,d=i(a),m=r(a),_=h(1-p)/(1-p*d*d),g=h(1+p*m*m*m*m/(1-p)),y=s(d/g),v=.5*g*o,{e:o,K:n(.5*y+A)/(u(n(.5*a+A),g)*Ai(o*d,v)),C:g,chi:y,ratexp:v,rc:_}),b=x.chi,w=2*x.rc,S=i(b),T=r(b);e.fwd=function(t,s){var o,a,c,h;t=function(t,e){return{phi:2*l(e.K*u(n(.5*t.phi+A),e.C)*Ai(e.e*i(t.phi),e.ratexp))-E,lam:e.C*t.lam}}(t,x),a=i(t.phi),o=r(t.phi),c=r(t.lam),h=e.k0*w/(1+S*a+T*o*c),s.x=h*o*i(t.lam),s.y=h*(T*a-S*o*c)},e.inv=function(o,a){var h,p,d,m,_=o.x/e.k0,g=o.y/e.k0;(h=f(_,g))?(p=2*c(h,w),d=i(p),m=r(p),a.phi=s(m*S+g*d*T/h),a.lam=c(_*d,h*T*m-g*S*d)):(a.phi=b,a.lam=0),function(e,r){e.phi;var s,o,a=u(n(.5*e.phi+A)/r.K,1/r.C);for(e.lam/=r.C,s=20;s>0&&(o=2*l(a*Ai(r.e*i(e.phi),-.5*r.e))-E,!(t(o-e.phi)<1e-14));--s)e.phi=o;s||N(-17)}(a,x)}},"sterea","Oblique Stereographic Alternative","Azimuthal, Sph&Ell"),tt(function(t){Ei(t,1.50488,1.35439,!1)},"kav5","Kavraisky V","PCyl., Sph."),tt(function(t){Ei(t,2,2,!1)},"qua_aut","Quartic Authalic","PCyl., Sph."),tt(function(t){Ei(t,2,2,!0)},"fouc","Foucaut","PCyl., Sph."),tt(function(t){Ei(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,s){s.x=r(e.phi)*i(e.lam)/t.k0,s.y=t.k0*(c(n(e.phi),r(e.lam))-t.phi0)},t.inv=function(e,n){var o;e.y=e.y/t.k0+t.phi0,e.x*=t.k0,o=h(1-e.x*e.x),n.phi=s(o*i(e.y)),n.lam=c(e.x,o*r(e.y))}},"tcea","Transverse Cylindrical Equal Area","Cyl, Sph"),tt(function(t){t.es=0,t.fwd=function(t,e){var r=n(t.phi/2),s=i(A*r);e.x=t.lam*(.74482-.34588*s*s),e.y=1.70711*r},t.inv=function(t,e){var r=t.y/1.70711,n=i(A*r);e.lam=t.x/(.74482-.34588*n*n),e.phi=2*l(r)}},"times","Times","Cyl, Sph"),tt(function(e){Y(e.params,"bapprox")?Ii(e):function(e){if(0===e.es)return Ii(e);ai(e);var i=e.fwd,r=e.inv;Ii(e);var n=e.fwd,s=e.inv;e.fwd=function(e,r){t(e.lam)>3*T?i(e,r):n(e,r)},e.inv=function(e,i){t(e.x)>.053-.022*e.y*e.y?r(e,i):s(e,i)}}(e)},"tmerc","Transverse Mercator","Cyl, Sph&Ell"),tt(function(t){var i;t.es||U(-34),t.y0=Y(t.params,"bsouth")?1e7:0,t.x0=5e5,Y(t.params,"tzone")?(i=Y(t.params,"izone"))>0&&i<=60?--i:U(-35):(i=e(30*(At(t.lam0)+b)/b))<0?i=0:i>=60&&(i=59),t.lam0=(i+.5)*b/30-b,t.k0=.9996,t.phi0=0,ai(t)},"utm","Universal Transverse Mercator (UTM)","Cyl, Sph\nzone= south"),tt(function(t){var e,s,o,a,l,h,u,p,d,m,_,g,y,v,x,b,w,S,T,C,M,A,I;C=Y(t.params,"rlat_1"),S=Y(t.params,"rlon_1"),M=Y(t.params,"rlat_2"),T=Y(t.params,"rlon_2"),C==M&&S==T&&U(-25),t.lam0=At(.5*(S+T)),m=At(T-S),e=r(C),o=r(M),s=i(C),a=i(M),h=e*a,u=s*o,l=e*o*i(m),d=Qe(s*a+e*o*r(m)),_=.5*d,A=c(o*i(m),e*a-s*o*r(m)),v=r(I=Je(e*i(A))),x=i(I),b=At(c(e*r(A),s)-_),m*=.5,w=E-c(i(A)*s,r(A))-m,g=n(_),y=.5/i(_),p=.5/d,d*=d,t.fwd=function(t,n){var c,f,_,g,y,v,x;v=i(t.phi),x=r(t.phi),f=Qe(s*v+e*x*r(g=t.lam+m)),_=Qe(a*v+o*x*r(y=t.lam-m)),f*=f,_*=_,n.x=p*(c=f-_),c=d-c,n.y=p*ti(4*d*_-c*c),l*v-x*(h*i(g)-u*i(y))<0&&(n.y=-n.y)},t.inv=function(t,e){var n,s,o,a,l,h;o=(n=r(f(t.y,t.x+_)))+(s=r(f(t.y,t.x-_))),a=n-s,e.lam=-c(a,o*g),e.phi=Qe(f(g*o,a)*y),t.y<0&&(e.phi=-e.phi),h=i(e.phi),l=r(e.phi),e.phi=Je(x*h+v*l*(o=r(e.lam-=b))),e.lam=c(l*i(e.lam),x*l*o-v*h)+w},t.es=0},"tpeqd","Two Point Equidistant","Misc Sph\nlat_1= lon_1= lat_2= lon_2="),tt(function(t){var e,n,s,o,a,l;(o=Y(t.params,"dn"))>0&&o<=1==0&&U(-40),s=Y(t.params,"dq")/3,a=Y(t.params,"ralpha"),l=o*i(a),e=r(a)/h(1-l*l),n=1/(e*o),t.fwd=function(t,a){var l=t.phi=Je(o*i(t.phi));a.x=e*t.lam*r(t.phi),l*=l,a.y=t.phi*(1+l*s)*n},t.es=0},"urm5","Urmaev V","PCyl., Sph., no inv.\nn= q= alpha="),tt(function(t){var e=Y(t.params,"dn");(e<=0||e>1)&&U(-40),Pi(t,e)},"urmfps","Urmaev Flat-Polar Sinusoidal","PCyl, Sph.\nn="),tt(function(t){Pi(t,.8660254037844386)},"wag1","Wagner I (Kavraisky VI)","PCyl, Sph."),tt(function(e){var i=1e-10,o=.3333333333333333,l=9.869604401089358,c=19.739208802178716,u=4.934802200544679;e.fwd=function(e,r){var o,a,l,c,u;(u=t(e.phi/E))-i>1&&V(),u>1&&(u=1),t(e.phi)<=i?(r.x=e.lam,r.y=0):t(e.lam)<=i||t(u-1)<i?(r.x=0,r.y=b*n(.5*s(u)),e.phi<0&&(r.y=-r.y)):(a=(o=.5*t(b/e.lam-e.lam/b))*o,l=h(1-u*u),c=(l/=u+l-1)*l,u=l*(2/u-1),u*=u,r.x=l-u,l=u+a,r.x=b*(o*r.x+h(a*r.x*r.x-l*(c-u)))/l,e.lam<0&&(r.x=-r.x),r.y=t(r.x/b),r.y=1-r.y*(r.y+2*o),r.y<-i&&V(),r.y<0?r.y=0:r.y=h(r.y)*(e.phi<0?-b:b))},e.inv=function(e,n){var s,p,d,f,m,_,g,y,v,x,w,S,T;if(S=e.x*e.x,(w=t(e.y))<i)return n.phi=0,s=S*S+c*(S+u),n.lam=t(e.x)<=i?0:.5*(S-l+h(s))/e.x,n;T=e.y*e.y,f=(d=-b*w*((y=S+T)+l))+l*(y-3*T),p=b*w,v=2*h(-o*(_=d/(m=(g=y*y)+P*(w*y+b*(T+b*(w+E))))-o*(f/=m)*f)),(s=t(x=3*(x=.07407407407407407*f*f*f+(p*p-o*f*d)/m)/(_*v)))-i<=1?(x=s>1?x>0?0:b:a(x),n.phi=b*(v*r(x*o+4.188790204786391)-o*f),e.y<0&&(n.phi=-n.phi),s=g+c*(S-T+u),n.lam=t(e.x)<=i?0:.5*(y-l+(s<=0?0:h(s)))/e.x):j()}},"vandg","van der Grinten (I)","Misc Sph"),tt(function(t){Di(t,!1)},"vandg2","van der Grinten II","Misc Sph, no inv."),tt(function(t){Di(t,!0)},"vandg3","van der Grinten III","Misc Sph, no inv."),tt(function(e){e.es=0,e.fwd=function(e,i){var r,n,s,o,a,l,c,u,p=1e-10;t(e.phi)<p?(i.x=e.lam,i.y=0):t(e.lam)<p||t(t(e.phi)-E)<p?(i.x=0,i.y=e.phi):(l=(o=.5*((s=t(D*e.phi))*(8-s*(2+(a=s*s)))-5)/(a*(s-1)))*o,c=D*e.lam,c=h((c+=1/c)*c-4),t(e.lam)-E<0&&(c=-c),r=s+o,r=(c*((r*=r)+l-1)+2*h(r*(a+l*(u=c*c)-1)+(1-a)*(a*((n=s+3*o)*n+4*l)+l*(12*s*o+4*l))))/(4*r+u),i.x=E*r,i.y=E*h(1+c*t(r)-r*r),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,s=.88022,o=.8855;t.fwd=function(t,a){t.phi=Je(s*i(o*t.phi)),a.x=e*t.lam*r(t.phi),a.y=n*t.phi},t.inv=function(t,a){a.phi=t.y/n,a.lam=t.x/(e*r(a.phi)),a.phi=Je(i(a.phi)/s)/o}},"wag2","Wagner II","PCyl., Sph."),tt(function(t){var e=.6666666666666666,i=Y(t.params,"rlat_ts"),n=r(i)/r(2*i/3);t.es=0,t.fwd=function(t,i){i.x=n*t.lam*r(e*t.phi),i.y=t.phi},t.inv=function(t,i){i.phi=t.y,i.lam=t.x/(n*r(e*i.phi))}},"wag3","Wagner III","PCyl., Sph.\nlat_ts="),tt(function(t){t.es=0,t.fwd=function(t,e){var n,o,a;n=s(e.y=.9063077870366499*i(t.phi)),e.x=2.66723*(o=r(n))*i(t.lam/=3),e.y*=1.24104*(a=1/h(.5*(1+o*r(t.lam)))),e.x*=a}},"wag7","Wagner VII","Misc Sph, no inv."),tt(function(t){var e=r(Y(t.params,"rlat_ts"));t.fwd=function(t,i){i.x=.5*t.lam*(e+r(t.phi)),i.y=t.phi},t.inv=function(t,i){i.phi=t.y,i.lam=2*t.x/(e+r(i.phi))},t.es=0},"wink1","Winkel I","PCyl., Sph.\nlat_ts="),tt(function(e){var n=r(Y(e.params,"rlat_1"));e.fwd=function(e,s){var o,a,l,c=e.phi;for(s.y=c*D,o=b*i(c),c*=1.8,l=10;l&&(c-=a=(c+i(c)-o)/(1+r(c)),!(t(a)<1e-7));--l);l?c*=.5:c=c<0?-E:E,s.x=.5*e.lam*(r(c)+n),s.y=A*(i(c)+s.y)},e.inv=null,e.es=0},"wink2","Winkel II","PCyl., Sph., no inv.\nlat_1=");var ki=Dt;ki.pj_init=_t,ki.pj_fwd=Et,ki.pj_inv=It,ki.pj_transform=St,ki.pj_add=tt,ki.pj_fwd_deg=function(t,e){return Et({lam:t.lam*T,phi:t.phi*T},e)},ki.pj_inv_deg=function(t,e){var i=It(t,e);return{lam:i.lam*S,phi:i.phi*S}},ki.pj_transform_point=wt,ki.internal={dmstod:W,dmstor:Z,get_rtodms:function(t,e,i,r){var n=Pt(t,e,i,r);return function(t){return n(t*S)}},get_dtodms:Pt,get_proj_defn:rt,pj_latlong_from_proj:function(t){return _t("+proj=latlong"+it(t))},pj_get_params:K,pj_datums:st,pj_list:Q,pj_ellps:lt,pj_units:ht,pj_read_init_opts:mt,find_datum:at,DEG_TO_RAD:T,RAD_TO_DEG:S,wkt_parse:Ne,wkt_unpack:Ve,convert_wkt_quotes:je,wkt_to_proj4:function(t){var e,i,r=Ne(t);return r.PROJCS?e=Ot(i=r.PROJCS)(i):r.GEOGCS?e="+proj=longlat "+Wt(r.GEOGCS):r.GEOCCS?qt("geocentric coordinates are not supported"):qt("missing a supported WKT CS type"),e},wkt_from_proj4:function(t){return t.length&&(t=_t(t)),Fe(et(t)?{GEOGCS:Jt(t)}:se(t))},wkt_make_projcs:se,wkt_get_geogcs_name:ee,wkt_stringify:Fe,mproj_insert_libcache:function(t,e){dt[t]=e},mproj_search_libcache:ft,GeographicLib:$e},x.exports=ki}();var S=s.exports,T=i({__proto__:null,default:r(S)},[S]);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,r=this.values[t];if(e>=r)break;this.ids[i]=this.ids[t],this.values[i]=r,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],r=--this.length;if(r>0){const i=t[r],n=e[r];let s=0;const o=r>>1;for(;s<o;){const i=1+(s<<1),o=i+1,a=i+(+(o<r)&+(e[o]<e[i]));if(e[a]>=n)break;t[s]=t[a],e[s]=e[a],s=a}t[s]=i,e[s]=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 M=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class A{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,r]=new Uint8Array(t,e+0,2);if(251!==i)throw new Error("Data does not appear to be in a Flatbush format.");const n=r>>4;if(3!==n)throw new Error(`Got v${n} data when expected v3.`);const s=M[15&r];if(!s)throw new Error("Unrecognized array type.");const[o]=new Uint16Array(t,e+2,1),[a]=new Uint32Array(t,e+4,1);return new A(a,o,s,void 0,t,e)}constructor(t,e=16,i=Float64Array,r=ArrayBuffer,n,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 o=t,a=o;this._levelBounds=[4*o];do{o=Math.ceil(o/this.nodeSize),a+=o,this._levelBounds.push(4*a)}while(1!==o);this.ArrayType=i,this.IndexArrayType=a<16384?Uint16Array:Uint32Array;const l=M.indexOf(i),c=4*a*i.BYTES_PER_ELEMENT;if(l<0)throw new Error(`Unexpected typed array class: ${i}.`);if(n)this.data=n,this._boxes=new i(n,s+8,4*a),this._indices=new this.IndexArrayType(n,s+8+c,a),this._pos=4*a,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 r(8+c+a*this.IndexArrayType.BYTES_PER_ELEMENT);this._boxes=new i(n,8,4*a),this._indices=new this.IndexArrayType(n,8+c,a),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+l]),new Uint16Array(n,2,1)[0]=e,new Uint32Array(n,4,1)[0]=t}this._queue=new C}add(t,e,i=t,r=e){const n=this._pos>>2,s=this._boxes;return this._indices[n]=n,s[this._pos++]=t,s[this._pos++]=e,s[this._pos++]=i,s[this._pos++]=r,t<this.minX&&(this.minX=t),e<this.minY&&(this.minY=e),i>this.maxX&&(this.maxX=i),r>this.maxY&&(this.maxY=r),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,r=new Uint32Array(this.numItems);for(let n=0,s=0;n<this.numItems;n++){const o=t[s++],a=t[s++],l=t[s++],c=t[s++],h=Math.floor(65535*((o+l)/2-this.minX)/e),u=Math.floor(65535*((a+c)/2-this.minY)/i);r[n]=D(h,u)}I(r,t,this._indices,0,this.numItems-1,this.nodeSize);for(let e=0,i=0;e<this._levelBounds.length-1;e++){const r=this._levelBounds[e];for(;i<r;){const e=i;let n=t[i++],s=t[i++],o=t[i++],a=t[i++];for(let e=1;e<this.nodeSize&&i<r;e++)n=Math.min(n,t[i++]),s=Math.min(s,t[i++]),o=Math.max(o,t[i++]),a=Math.max(a,t[i++]);this._indices[this._pos>>2]=e,t[this._pos++]=n,t[this._pos++]=s,t[this._pos++]=o,t[this._pos++]=a}}}search(t,e,i,r,n){if(this._pos!==this._boxes.length)throw new Error("Data not yet indexed - call index.finish().");let s=this._boxes.length-4;const o=[],a=[];for(;void 0!==s;){const l=Math.min(s+4*this.nodeSize,E(s,this._levelBounds));for(let c=s;c<l;c+=4){const l=this._boxes[c];if(i<l)continue;const h=this._boxes[c+1];if(r<h)continue;const u=this._boxes[c+2];if(t>u)continue;const p=this._boxes[c+3];if(e>p)continue;const d=0|this._indices[c>>2];s>=4*this.numItems?o.push(d):(void 0===n||n(d,l,h,u,p))&&a.push(d)}s=o.pop()}return a}neighbors(t,e,i=1/0,r=1/0,n){if(this._pos!==this._boxes.length)throw new Error("Data not yet indexed - call index.finish().");let s=this._boxes.length-4;const o=this._queue,a=[],l=r*r;t:for(;void 0!==s;){const r=Math.min(s+4*this.nodeSize,E(s,this._levelBounds));for(let i=s;i<r;i+=4){const r=0|this._indices[i>>2],a=this._boxes[i],c=this._boxes[i+1],h=this._boxes[i+2],u=this._boxes[i+3],p=t<a?a-t:t>h?t-h:0,d=e<c?c-e:e>u?e-u:0,f=p*p+d*d;f>l||(s>=4*this.numItems?o.push(r<<1,f):(void 0===n||n(r))&&o.push(1+(r<<1),f))}for(;o.length&&1&o.peek();){if(o.peekValue()>l)break t;if(a.push(o.pop()>>1),a.length===i)break t}s=o.length?o.pop()>>1:void 0}return o.clear(),a}}function E(t,e){let i=0,r=e.length-1;for(;i<r;){const n=i+r>>1;e[n]>t?r=n:i=n+1}return e[i]}function I(t,e,i,r,n,s){if(Math.floor(r/s)>=Math.floor(n/s))return;const o=t[r],a=t[r+n>>1],l=t[n];let c=l;const h=Math.max(o,a);l>h?c=h:h===o?c=Math.max(a,l):h===a&&(c=Math.max(o,l));let u=r-1,p=n+1;for(;;){do{u++}while(t[u]<c);do{p--}while(t[p]>c);if(u>=p)break;P(t,e,i,u,p)}I(t,e,i,r,p,s),I(t,e,i,p+1,n,s)}function P(t,e,i,r,n){const s=t[r];t[r]=t[n],t[n]=s;const o=4*r,a=4*n,l=e[o],c=e[o+1],h=e[o+2],u=e[o+3];e[o]=e[a],e[o+1]=e[a+1],e[o+2]=e[a+2],e[o+3]=e[a+3],e[a]=l,e[a+1]=c,e[a+2]=h,e[a+3]=u;const p=i[r];i[r]=i[n],i[n]=p}function D(t,e){let i=t^e,r=65535^i,n=65535^(t|e),s=t&(65535^e),o=i|r>>1,a=i>>1^i,l=n>>1^r&s>>1^n,c=i&n>>1^s>>1^s;i=o,r=a,n=l,s=c,o=i&i>>2^r&r>>2,a=i&r>>2^r&(i^r)>>2,l^=i&n>>2^r&s>>2,c^=r&n>>2^(i^r)&s>>2,i=o,r=a,n=l,s=c,o=i&i>>4^r&r>>4,a=i&r>>4^r&(i^r)>>4,l^=i&n>>4^r&s>>4,c^=r&n>>4^(i^r)&s>>4,i=o,r=a,n=l,s=c,l^=i&n>>8^r&s>>8,c^=r&n>>8^(i^r)&s>>8,i=l^l>>1,r=c^c>>1;let h=t^e,u=r|65535^(h|i);return h=16711935&(h|h<<8),h=252645135&(h|h<<4),h=858993459&(h|h<<2),h=1431655765&(h|h<<1),u=16711935&(u|u<<8),u=252645135&(u|u<<4),u=858993459&(u|u<<2),u=1431655765&(u|u<<1),(u<<1|h)>>>0}const k=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class z{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 r=i>>4;if(1!==r)throw new Error(`Got v${r} data when expected v1.`);const n=k[15&i];if(!n)throw new Error("Unrecognized array type.");const[s]=new Uint16Array(t,2,1),[o]=new Uint32Array(t,4,1);return new z(o,s,n,t)}constructor(t,e=64,i=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=i,this.IndexArrayType=t<65536?Uint16Array:Uint32Array;const n=k.indexOf(this.ArrayType),s=2*t*this.ArrayType.BYTES_PER_ELEMENT,o=t*this.IndexArrayType.BYTES_PER_ELEMENT,a=(8-o%8)%8;if(n<0)throw new Error(`Unexpected typed array class: ${i}.`);r&&r instanceof ArrayBuffer?(this.data=r,this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+o+a,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+s+o+a),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+o+a,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 R(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}range(t,e,i,r){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:n,coords:s,nodeSize:o}=this,a=[0,n.length-1,0],l=[];for(;a.length;){const c=a.pop()||0,h=a.pop()||0,u=a.pop()||0;if(h-u<=o){for(let o=u;o<=h;o++){const a=s[2*o],c=s[2*o+1];a>=t&&a<=i&&c>=e&&c<=r&&l.push(n[o])}continue}const p=u+h>>1,d=s[2*p],f=s[2*p+1];d>=t&&d<=i&&f>=e&&f<=r&&l.push(n[p]),(0===c?t<=d:e<=f)&&(a.push(u),a.push(p-1),a.push(1-c)),(0===c?i>=d:r>=f)&&(a.push(p+1),a.push(h),a.push(1-c))}return l}within(t,e,i){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:r,coords:n,nodeSize:s}=this,o=[0,r.length-1,0],a=[],l=i*i;for(;o.length;){const c=o.pop()||0,h=o.pop()||0,u=o.pop()||0;if(h-u<=s){for(let i=u;i<=h;i++)O(n[2*i],n[2*i+1],t,e)<=l&&a.push(r[i]);continue}const p=u+h>>1,d=n[2*p],f=n[2*p+1];O(d,f,t,e)<=l&&a.push(r[p]),(0===c?t-i<=d:e-i<=f)&&(o.push(u),o.push(p-1),o.push(1-c)),(0===c?t+i>=d:e+i>=f)&&(o.push(p+1),o.push(h),o.push(1-c))}return a}}function R(t,e,i,r,n,s){if(n-r<=i)return;const o=r+n>>1;L(t,e,o,r,n,s),R(t,e,i,r,o-1,1-s),R(t,e,i,o+1,n,1-s)}function L(t,e,i,r,n,s){for(;n>r;){if(n-r>600){const o=n-r+1,a=i-r+1,l=Math.log(o),c=.5*Math.exp(2*l/3),h=.5*Math.sqrt(l*c*(o-c)/o)*(a-o/2<0?-1:1);L(t,e,i,Math.max(r,Math.floor(i-a*c/o+h)),Math.min(n,Math.floor(i+(o-a)*c/o+h)),s)}const o=e[2*i+s];let a=r,l=n;for(F(t,e,r,i),e[2*n+s]>o&&F(t,e,r,n);a<l;){for(F(t,e,a,l),a++,l--;e[2*a+s]<o;)a++;for(;e[2*l+s]>o;)l--}e[2*r+s]===o?F(t,e,r,l):(l++,F(t,e,l,n)),l<=i&&(r=l+1),i<=l&&(n=l-1)}}function F(t,e,i,r){B(t,i,r),B(e,2*i,2*r),B(e,2*i+1,2*r+1)}function B(t,e,i){const r=t[e];t[e]=t[i],t[i]=r}function O(t,e,i,r){const n=t-i,s=e-r;return n*n+s*s}var N={exports:{}};!function(t){var e,i,r,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,r=i-e,n=i-r;return r-=t,{s:i,t:i?0-(r+(n-=e)):i}},i.polyval=function(t,e,i,r){for(var n=t<0?0:e[i++];--t>=0;)n=n*r+e[i++];return n},i.AngRound=function(t){var e=1/16,r=Math.abs(t);return r=r<e?e-(e-r):r,i.copysign(r,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 r,n,s=i.sum(i.remainder(-t,360),i.remainder(e,360));return r=(s=i.sum(i.remainder(s.s,360),s.t)).s,n=s.t,0!==r&&180!==Math.abs(r)||(r=i.copysign(r,0===n?e-t:-n)),{d:r,e:n}},i.sincosd=function(t){var e,r,n,s,o,a,l;switch(e=t%360,r=(e-=90*(n=Math.round(e/90)))*this.degree,s=Math.sin(r),o=Math.cos(r),45===Math.abs(e)?(o=Math.sqrt(.5),s=i.copysign(o,r)):30===Math.abs(e)&&(o=Math.sqrt(.75),s=i.copysign(.5,r)),3&n){case 0:a=s,l=o;break;case 1:a=o,l=-s;break;case 2:a=-s,l=-o;break;default:a=-o,l=s}return l+=0,0===a&&(a=i.copysign(a,t)),{s:a,c:l}},i.sincosde=function(t,e){var r,n,s,o,a,l,c;switch(r=t%360,s=Math.round(r/90),n=(r=i.AngRound(r-90*s+e))*this.degree,o=Math.sin(n),a=Math.cos(n),45===Math.abs(r)?(a=Math.sqrt(.5),o=i.copysign(a,n)):30===Math.abs(r)&&(a=Math.sqrt(.75),o=i.copysign(.5,n)),3&s){case 0:l=o,c=a;break;case 1:l=a,c=-o;break;case 2:l=-o,c=-a;break;default:l=-a,c=o}return c+=0,0===l&&(l=i.copysign(l,t+e)),{s:l,c:c}},i.atan2d=function(t,e){var r,n=0;switch(Math.abs(t)>Math.abs(e)&&([t,e]=[e,t],n=2),i.copysign(1,e)<0&&(e=-e,++n),r=Math.atan2(t,e)/this.degree,n){case 1:r=i.copysign(180,t)-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 i=e.sum(t,this._t),r=e.sum(i.s,this._s);i=i.t,this._s=r.s,this._t=r.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,r,n){var s,o,a,l,c,h,u,p,d,f,m,_=20+r.digits+10,g=r.epsilon,y=200*g,v=Math.sqrt(g),x=g,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,s=t.nC3_*(t.nC3_-1)/2,o=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,r){var n=r.length,s=n-(t?1:0),o=2*(i-e)*(i+e),a=1&s?r[--n]:0,l=0;for(s=Math.floor(s/2);s--;)a=o*(l=o*a-l+r[--n])-a+r[--n];return t?2*e*i*a:i*(a-l)},a=function(t,e){var i,n,s,o,a,l,c,h,u,p,d,f,m=r.sq(t),_=r.sq(e),g=(m+_-1)/6;return 0===_&&g<=0?i=0:(l=g,(a=(n=m*_/4)*(n+2*(o=g*(s=r.sq(g)))))>=0?(c=n+o,c+=c<0?-Math.sqrt(a):Math.sqrt(a),l+=(h=r.cbrt(c))+(0!==h?s/h:0)):(u=Math.atan2(Math.sqrt(-a),-(n+o)),l+=2*g*Math.cos(u/3)),p=Math.sqrt(r.sq(l)+_),f=((d=l<0?_/(p-l):l+p)-_)/(2*p),i=d/(Math.sqrt(d+r.sq(f))+f)),i},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)},c=[-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,s,o=r.sq(e),a=e,l=0;for(n=1;n<=t.nC1_;++n)s=Math.floor((t.nC1_-n)/2),i[n]=a*r.polyval(s,c,l,o)/c[l+s+1],l+=s+2,a*=e},h=[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,s,o=r.sq(e),a=e,l=0;for(n=1;n<=t.nC1p_;++n)s=Math.floor((t.nC1p_-n)/2),i[n]=a*r.polyval(s,h,l,o)/h[l+s+1],l+=s+2,a*=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,i){var n,s,o=r.sq(e),a=e,l=0;for(n=1;n<=t.nC2_;++n)s=Math.floor((t.nC2_-n)/2),i[n]=a*r.polyval(s,p,l,o)/p[l+s+1],l+=s+2,a*=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(o),this.A3coeff(),this.C3coeff(),this.C4coeff()},d=[-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++]=r.polyval(e,d,i,this._n)/d[i+e+1],i+=e+2},f=[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,s=0,o=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[o++]=r.polyval(n,f,s,this._n)/f[s+n+1],s+=n+2},m=[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,s=0,o=0;for(e=0;e<t.nC4_;++e)for(i=t.nC4_-1;i>=e;--i)n=t.nC4_-i-1,this._C4x[o++]=r.polyval(n,m,s,this._n)/m[s+n+1],s+=n+2},t.Geodesic.prototype.A3f=function(t){return r.polyval(5,this._A3x,0,t)},t.Geodesic.prototype.C3f=function(e,i){var n,s,o=1,a=0;for(n=1;n<t.nC3_;++n)s=t.nC3_-n-1,o*=e,i[n]=o*r.polyval(s,this._C3x,a,e),a+=s+1},t.Geodesic.prototype.C4f=function(e,i){var n,s,o=1,a=0;for(n=0;n<t.nC4_;++n)s=t.nC4_-n-1,i[n]=o*r.polyval(s,this._C4x,a,e),a+=s+1,o*=e},t.Geodesic.prototype.Lengths=function(e,i,r,n,s,o,a,l,c,h,u,p,d){var f,m,_,g,y={},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,d),v=b-w,w=1+w),b=1+b),u&t.DISTANCE)f=t.SinCosSeries(!0,o,a,p)-t.SinCosSeries(!0,r,n,p),y.s12b=b*(i+f),u&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(x=v*i+(b*f-w*(t.SinCosSeries(!0,o,a,d)-t.SinCosSeries(!0,r,n,d))));else if(u&(t.REDUCEDLENGTH|t.GEODESICSCALE)){for(m=1;m<=t.nC2_;++m)d[m]=b*p[m]-w*d[m];x=v*i+(t.SinCosSeries(!0,o,a,d)-t.SinCosSeries(!0,r,n,d))}return u&t.REDUCEDLENGTH?(y.m0=v,y.m12b=l*(n*o)-s*(r*a)-n*a*x):y.m12b=NaN,u&t.GEODESICSCALE&&(_=n*a+r*o,g=this._ep2*(c-h)*(c+h)/(s+l),y.M12=_+(g*o-a*x)*r/s,y.M21=_-(g*r-n*x)*o/l),y},t.Geodesic.prototype.InverseStart=function(e,i,n,s,o,l,c,h,u,p,d){var f,m,_,g,v,x,w,S,T,C,M,A,E,I,P,D,k,z,R,L,F={},B=s*i-o*e,O=o*i+s*e;return F.sig12=-1,f=s*i,f+=o*e,(m=O>=0&&B<.5&&o*c<.5)?(g=r.sq(e+s),g/=g+r.sq(i+o),F.dnm=Math.sqrt(1+this._ep2*g),_=c/(this._f1*F.dnm),v=Math.sin(_),x=Math.cos(_)):(v=h,x=u),F.salp1=o*v,F.calp1=x>=0?B+o*e*r.sq(v)/(1+x):f-o*e*r.sq(v)/(1-x),S=r.hypot(F.salp1,F.calp1),T=e*s+i*o*x,m&&S<this._etol2?(F.salp2=i*v,F.calp2=B-i*s*(x>=0?r.sq(v)/(1+x):1-x),w=r.hypot(F.salp2,F.calp2),F.salp2/=w,F.calp2/=w,F.sig12=Math.atan2(S,T)):Math.abs(this._n)>.1||T>=0||S>=6*Math.abs(this._n)*Math.PI*r.sq(i)||(L=Math.atan2(-h,-u),this.f>=0?(I=(E=r.sq(e)*this._ep2)/(2*(1+Math.sqrt(1+E))+E),C=L/(A=this.f*i*this.A3f(I)*Math.PI),M=f/(A*i)):(P=o*i-s*e,D=Math.atan2(f,P),M=c/(A=((C=(k=this.Lengths(this._n,Math.PI+D,e,-i,n,s,o,l,i,o,t.REDUCEDLENGTH,p,d)).m12b/(i*o*k.m0*Math.PI)-1)<-.01?f/C:-this.f*r.sq(i)*Math.PI)/i)),M>-y&&C>-1-b?this.f>=0?(F.salp1=Math.min(1,-C),F.calp1=-Math.sqrt(1-r.sq(F.salp1))):(F.calp1=Math.max(C>-y?0:-1,C),F.salp1=Math.sqrt(1-r.sq(F.calp1))):(z=a(C,M),R=A*(this.f>=0?-C*z/(1+z):-M*(1+z)/z),v=Math.sin(R),x=-Math.cos(R),F.salp1=o*v,F.calp1=f-o*e*r.sq(v)/(1-x))),F.salp1<=0?(F.salp1=1,F.calp1=0):(w=r.hypot(F.salp1,F.calp1),F.salp1/=w,F.calp1/=w),F},t.Geodesic.prototype.Lambda12=function(e,i,n,s,o,a,l,c,h,u,p,d,f,m){var _,g,y,v,x,b,w,S,T,C,M,A,E,I={};return 0===e&&0===c&&(c=-t.tiny_),g=l*i,y=r.hypot(c,l*e),I.ssig1=e,v=g*e,I.csig1=x=c*i,_=r.hypot(I.ssig1,I.csig1),I.ssig1/=_,I.csig1/=_,I.salp2=o!==i?g/o:l,I.calp2=o!==i||Math.abs(s)!==-e?Math.sqrt(r.sq(c*i)+(i<-e?(o-i)*(i+o):(e-s)*(e+s)))/o:Math.abs(c),I.ssig2=s,b=g*s,I.csig2=w=I.calp2*o,_=r.hypot(I.ssig2,I.csig2),I.ssig2/=_,I.csig2/=_,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),T=x*w+v*b,M=Math.atan2(S*u-T*h,T*u+S*h),A=r.sq(y)*this._ep2,I.eps=A/(2*(1+Math.sqrt(1+A))+A),this.C3f(I.eps,m),C=t.SinCosSeries(!0,I.ssig2,I.csig2,m)-t.SinCosSeries(!0,I.ssig1,I.csig1,m),I.domg12=-this.f*this.A3f(I.eps)*g*(I.sig12+C),I.lam12=M+I.domg12,p&&(0===I.calp2?I.dlam12=-2*this._f1*n/e:(E=this.Lengths(I.eps,I.sig12,I.ssig1,I.csig1,n,I.ssig2,I.csig2,a,i,o,t.REDUCEDLENGTH,d,f),I.dlam12=E.m12b,I.dlam12*=this._f1/(I.calp2*o))),I},t.Geodesic.prototype.Inverse=function(e,i,n,s,o){var a,l;return o||(o=t.STANDARD),o===t.LONG_UNROLL&&(o|=t.STANDARD),o&=t.OUT_MASK,l=(a=this.InverseInt(e,i,n,s,o)).vals,o&t.AZIMUTH&&(l.azi1=r.atan2d(a.salp1,a.calp1),l.azi2=r.atan2d(a.salp2,a.calp2)),l},t.Geodesic.prototype.InverseInt=function(e,i,n,s,o){var a,l,c,h,u,p,d,f,m,y,b,w,S,T,C,M,A,E,I,P,D,k,z,R,L,F,B,O,N,V,j,G,U,q,$,Z,W,H,X,Y,K,J,Q,tt,et,it,rt,nt,st,ot,at,lt,ct,ht,ut,pt,dt,ft,mt,_t,gt,yt,vt,xt,bt,wt={};if(wt.lat1=e=r.LatFix(e),wt.lat2=n=r.LatFix(n),e=r.AngRound(e),n=r.AngRound(n),l=(a=r.AngDiff(i,s)).e,a=a.d,o&t.LONG_UNROLL?(wt.lon1=i,wt.lon2=i+a+l):(wt.lon1=r.AngNormalize(i),wt.lon2=r.AngNormalize(s)),l*=c=r.copysign(1,a),C=(a*=c)*r.degree,M=(h=r.sincosde(a,l)).s,A=h.c,l=180-a-l,(u=Math.abs(e)<Math.abs(n)||isNaN(n)?-1:1)<0&&(c*=-1,[n,e]=[e,n]),e*=p=r.copysign(1,-e),n*=p,h=r.sincosd(e),d=this._f1*h.s,f=h.c,d/=h=r.hypot(d,f),f/=h,f=Math.max(t.tiny_,f),h=r.sincosd(n),m=this._f1*h.s,y=h.c,m/=h=r.hypot(m,y),y/=h,y=Math.max(t.tiny_,y),f<-d?y===f&&(m=r.copysign(d,m)):Math.abs(m)===-d&&(y=f),S=Math.sqrt(1+this._ep2*r.sq(d)),T=Math.sqrt(1+this._ep2*r.sq(m)),z=new Array(t.nC1_+1),R=new Array(t.nC2_+1),L=new Array(t.nC3_),(F=-90===e||0===M)&&(P=M,k=0,O=d,N=(I=A)*f,V=m,j=(D=1)*y,E=Math.atan2(Math.max(0,N*V-O*j),N*j+O*V),b=(B=this.Lengths(this._n,E,O,N,S,V,j,T,f,y,o|t.DISTANCE|t.REDUCEDLENGTH,z,R)).s12b,w=B.m12b,o&t.GEODESICSCALE&&(wt.M12=B.M12,wt.M21=B.M21),E<v||w>=0?((E<3*t.tiny_||E<g&&(b<0||w<0))&&(E=w=b=0),w*=this._b,b*=this._b,wt.a12=E/r.degree):F=!1),dt=2,!F&&0===d&&(this.f<=0||l>=180*this.f))I=D=0,P=k=1,b=this.a*C,E=U=C/this._f1,w=this._b*Math.sin(E),o&t.GEODESICSCALE&&(wt.M12=wt.M21=Math.cos(E)),wt.a12=a/this._f1;else if(!F)if(E=(B=this.InverseStart(d,f,S,m,y,T,C,M,A,z,R)).sig12,P=B.salp1,I=B.calp1,E>=0)k=B.salp2,D=B.calp2,q=B.dnm,b=E*this._b*q,w=r.sq(q)*this._b*Math.sin(E/q),o&t.GEODESICSCALE&&(wt.M12=wt.M21=Math.cos(E/q)),wt.a12=E/r.degree,U=C/(this._f1*q);else{for($=0,Z=t.tiny_,W=1,H=t.tiny_,X=-1,Y=!1,K=!1;J=(B=this.Lambda12(d,f,S,m,y,T,P,I,M,A,$<20,z,R,L)).lam12,k=B.salp2,D=B.calp2,E=B.sig12,O=B.ssig1,N=B.csig1,V=B.ssig2,j=B.csig2,G=B.eps,mt=B.domg12,Q=B.dlam12,!K&&Math.abs(J)>=(Y?8:1)*g&&$!=_;++$)J>0&&($<20||I/P>X/H)?(H=P,X=I):J<0&&($<20||I/P<W/Z)&&(Z=P,W=I),$<20&&Q>0&&(tt=-J/Q,Math.abs(tt)<Math.PI&&(et=Math.sin(tt),(rt=P*(it=Math.cos(tt))+I*et)>0))?(I=I*it-P*et,P=rt,P/=h=r.hypot(P,I),I/=h,Y=Math.abs(J)<=16*g):(P=(Z+H)/2,I=(W+X)/2,P/=h=r.hypot(P,I),I/=h,Y=!1,K=Math.abs(Z-P)+(W-I)<x||Math.abs(P-H)+(I-X)<x);nt=o|(o&(t.REDUCEDLENGTH|t.GEODESICSCALE)?t.DISTANCE:t.NONE),b=(B=this.Lengths(G,E,O,N,S,V,j,T,f,y,nt,z,R)).s12b,w=B.m12b,o&t.GEODESICSCALE&&(wt.M12=B.M12,wt.M21=B.M21),w*=this._b,b*=this._b,wt.a12=E/r.degree,o&t.AREA&&(xt=Math.sin(mt),dt=M*(bt=Math.cos(mt))-A*xt,ft=A*bt+M*xt)}return o&t.DISTANCE&&(wt.s12=0+b),o&t.REDUCEDLENGTH&&(wt.m12=0+w),o&t.AREA&&(st=P*f,0!==(ot=r.hypot(I,P*d))&&0!==st?(O=d,N=I*f,V=m,j=D*y,G=(lt=r.sq(ot)*this._ep2)/(2*(1+Math.sqrt(1+lt))+lt),ct=r.sq(this.a)*ot*st*this._e2,O/=h=r.hypot(O,N),N/=h,V/=h=r.hypot(V,j),j/=h,ht=new Array(t.nC4_),this.C4f(G,ht),ut=t.SinCosSeries(!1,O,N,ht),pt=t.SinCosSeries(!1,V,j,ht),wt.S12=ct*(pt-ut)):wt.S12=0,F||2!=dt||(dt=Math.sin(U),ft=Math.cos(U)),!F&&ft>-.7071&&m-d<1.75?(mt=1+ft,_t=1+f,gt=1+y,at=2*Math.atan2(dt*(d*gt+m*_t),mt*(d*m+_t*gt))):(vt=D*I+k*P,0===(yt=k*I-D*P)&&vt<0&&(yt=t.tiny_*I,vt=-1),at=Math.atan2(yt,vt)),wt.S12+=this._c2*at,wt.S12*=u*c*p,wt.S12+=0),u<0&&([k,P]=[P,k],[D,I]=[I,D],o&t.GEODESICSCALE&&([wt.M21,wt.M12]=[wt.M12,wt.M21])),{vals:wt,salp1:P*=u*c,calp1:I*=u*p,salp2:k*=u*c,calp2:D*=u*p}},t.Geodesic.prototype.GenDirect=function(i,r,n,s,o,a){return a?a===t.LONG_UNROLL&&(a|=t.STANDARD):a=t.STANDARD,s||(a|=t.DISTANCE_IN),new e.GeodesicLine(this,i,r,n,a).GenPosition(s,o,a)},t.Geodesic.prototype.Direct=function(t,e,i,r,n){return this.GenDirect(t,e,i,!1,r,n)},t.Geodesic.prototype.ArcDirect=function(t,e,i,r,n){return this.GenDirect(t,e,i,!0,r,n)},t.Geodesic.prototype.Line=function(t,i,r,n){return new e.GeodesicLine(this,t,i,r,n)},t.Geodesic.prototype.DirectLine=function(t,e,i,r,n){return this.GenDirectLine(t,e,i,!1,r,n)},t.Geodesic.prototype.ArcDirectLine=function(t,e,i,r,n){return this.GenDirectLine(t,e,i,!0,r,n)},t.Geodesic.prototype.GenDirectLine=function(i,r,n,s,o,a){var l;return a||(a=t.STANDARD|t.DISTANCE_IN),s||(a|=t.DISTANCE_IN),(l=new e.GeodesicLine(this,i,r,n,a)).GenSetDistance(s,o),l},t.Geodesic.prototype.InverseLine=function(i,n,s,o,a){var l,c,h;return a||(a=t.STANDARD|t.DISTANCE_IN),l=this.InverseInt(i,n,s,o,t.ARC),h=r.atan2d(l.salp1,l.calp1),a&t.OUT_MASK&t.DISTANCE_IN&&(a|=t.DISTANCE),(c=new e.GeodesicLine(this,i,n,h,a,l.salp1,l.calp1)).SetArc(l.vals.a12),c},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,r,n,s,o,a,l){var c,h,u,p,d,f;o||(o=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=o|t.LATITUDE|t.AZIMUTH|t.LONG_UNROLL,this.lat1=i.LatFix(r),this.lon1=n,void 0===a||void 0===l?(this.azi1=i.AngNormalize(s),c=i.sincosd(i.AngRound(this.azi1)),this.salp1=c.s,this.calp1=c.c):(this.azi1=s,this.salp1=a,this.calp1=l),c=i.sincosd(i.AngRound(this.lat1)),u=this._f1*c.s,h=c.c,u/=c=i.hypot(u,h),h/=c,h=Math.max(t.tiny_,h),this._dn1=Math.sqrt(1+e._ep2*i.sq(u)),this._salp0=this.salp1*h,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?h*this.calp1:1,c=i.hypot(this._ssig1,this._csig1),this._ssig1/=c,this._csig1/=c,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),d=Math.sin(this._B11),f=Math.cos(this._B11),this._stau1=this._ssig1*f+this._csig1*d,this._ctau1=this._csig1*f-this._ssig1*d),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,r,n){var s,o,a,l,c,h,u,p,d,f,m,_,g,y,v,x,b,w,S,T,C,M,A,E,I,P,D={};return n?n===t.LONG_UNROLL&&(n|=t.STANDARD):n=t.STANDARD,n&=this.caps&t.OUT_MASK,D.lat1=this.lat1,D.azi1=this.azi1,D.lon1=n&t.LONG_UNROLL?this.lon1:i.AngNormalize(this.lon1),e?D.a12=r:D.s12=r,e||this.caps&t.DISTANCE_IN&t.OUT_MASK?(l=0,c=0,e?(s=r*i.degree,o=(A=i.sincosd(r)).s,a=A.c):(p=r/(this._b*(1+this._A1m1)),d=Math.sin(p),f=Math.cos(p),s=p-((l=-t.SinCosSeries(!0,this._stau1*f+this._ctau1*d,this._ctau1*f-this._stau1*d,this._C1pa))-this._B11),o=Math.sin(s),a=Math.cos(s),Math.abs(this.f)>.01&&(h=this._ssig1*a+this._csig1*o,u=this._csig1*a-this._ssig1*o,l=t.SinCosSeries(!0,h,u,this._C1a),s-=((1+this._A1m1)*(s+(l-this._B11))-r/this._b)/Math.sqrt(1+this._k2*i.sq(h)),o=Math.sin(s),a=Math.cos(s))),h=this._ssig1*a+this._csig1*o,u=this._csig1*a-this._ssig1*o,S=Math.sqrt(1+this._k2*i.sq(h)),n&(t.DISTANCE|t.REDUCEDLENGTH|t.GEODESICSCALE)&&((e||Math.abs(this.f)>.01)&&(l=t.SinCosSeries(!0,h,u,this._C1a)),c=(1+this._A1m1)*(l-this._B11)),g=this._calp0*h,0===(y=i.hypot(this._salp0,this._calp0*u))&&(y=u=t.tiny_),b=this._salp0,w=this._calp0*u,e&&n&t.DISTANCE&&(D.s12=this._b*((1+this._A1m1)*s+c)),n&t.LONGITUDE&&(v=this._salp0*h,x=u,_=i.copysign(1,this._salp0),m=((n&t.LONG_UNROLL?_*(s-(Math.atan2(h,u)-Math.atan2(this._ssig1,this._csig1))+(Math.atan2(_*v,x)-Math.atan2(_*this._somg1,this._comg1))):Math.atan2(v*this._comg1-x*this._somg1,x*this._comg1+v*this._somg1))+this._A3c*(s+(t.SinCosSeries(!0,h,u,this._C3a)-this._B31)))/i.degree,D.lon2=n&t.LONG_UNROLL?this.lon1+m:i.AngNormalize(i.AngNormalize(this.lon1)+i.AngNormalize(m))),n&t.LATITUDE&&(D.lat2=i.atan2d(g,this._f1*y)),n&t.AZIMUTH&&(D.azi2=i.atan2d(b,w)),n&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(T=t.SinCosSeries(!0,h,u,this._C2a),C=(1+this._A2m1)*(T-this._B21),M=(this._A1m1-this._A2m1)*s+(c-C),n&t.REDUCEDLENGTH&&(D.m12=this._b*(S*(this._csig1*h)-this._dn1*(this._ssig1*u)-this._csig1*u*M)),n&t.GEODESICSCALE&&(A=this._k2*(h-this._ssig1)*(h+this._ssig1)/(this._dn1+S),D.M12=a+(A*h-u*M)*this._ssig1/this._dn1,D.M21=a-(A*this._ssig1-this._csig1*M)*h/S)),n&t.AREA&&(E=t.SinCosSeries(!1,h,u,this._C4a),0===this._calp0||0===this._salp0?(I=b*this.calp1-w*this.salp1,P=w*this.calp1+b*this.salp1):(I=this._calp0*this._salp0*(a<=0?this._csig1*(1-a)+o*this._ssig1:o*(this._csig1*o/(1+a)+this._ssig1)),P=i.sq(this._salp0)+i.sq(this._calp0)*this._csig1*u),D.S12=this._c2*Math.atan2(I,P)+this._A4*(E-this._B41)),e||(D.a12=s/i.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 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,r){var n,s,o,a;n=function(t,e){var r=i.AngDiff(t,e).d;return t=i.AngNormalize(t),e=i.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)},o=function(t,e,i,r,n){return t.Remainder(e),1&i&&t.Add((t.Sum()<0?1:-1)*e/2),r||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()},a=function(t,e,r,n,s){return t=i.remainder(t,e),1&r&&(t+=(t<0?1:-1)*e/2),n||(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,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 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 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+=s(this.lon,i.lon2)),this.lat=i.lat2,this.lon=i.lon2),++this.num},t.PolygonArea.prototype.Compute=function(t,e){var i,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):(i=this._geod.Inverse(this.lat,this.lon,this._lat0,this._lon0,this._mask),a.perimeter=this._perimetersum.Sum(i.s12),(s=new r.Accumulator(this._areasum)).Add(i.S12),a.area=o(s,this._area0,this._crossings+n(this.lon,this._lon0),t,e),a)},t.PolygonArea.prototype.TestPoint=function(t,e,i,r){var s,o,l,c,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(),o=this.polyline?0:this._areasum.Sum(),l=this._crossings,c=0;c<(this.polyline?1:2);++c)s=this._geod.Inverse(0===c?this.lat:t,0===c?this.lon:e,0!==c?this._lat0:t,0!==c?this._lon0:e,this._mask),h.perimeter+=s.s12,this.polyline||(o+=s.S12,l+=n(0===c?this.lon:e,0!==c?this._lon0:e));return this.polyline||(h.area=a(o,this._area0,l,i,r)),h},t.PolygonArea.prototype.TestEdge=function(t,e,i,r){var o,l,c,h={number:this.num?this.num+1:0};return 0===this.num||(h.perimeter=this._perimetersum.Sum()+e,this.polyline||(l=this._areasum.Sum(),c=this._crossings,l+=(o=this._geod.Direct(this.lat,this.lon,t,e,this._mask)).S12,c+=s(this.lon,o.lon2),c+=n(o.lon2,this._lon0),o=this._geod.Inverse(o.lat2,o.lon2,this._lat0,this._lon0,this._mask),h.perimeter+=o.s12,l+=o.S12,h.area=a(l,this._area0,c,i,r))),h}}(n.PolygonArea,n.Geodesic,n.Math,n.Accumulator),r=n,t.exports?t.exports=r:window.geodesic=r}(N);var V=N.exports,j=i({__proto__:null,default:r(V)},[V]);const G=globalThis;"undefined"==typeof window&&(G.window=G.window||{},G.window.document||(G.window.document={}));const U=G.window.modules=G.window.modules||{};U.mproj=T,U.flatbush=A,U.kdbush=z,U["geographiclib-geodesic"]=j;class q{_listeners={};on(t,e){return this._listeners[t]||(this._listeners[t]=[]),this._listeners[t].push(e),this}once(t,e){const i=r=>{this.off(t,i),e(r)};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,r=0){this.mx=t,this.my=e,this.bx=i,this.by=r}static fromBounds(t,e,i=!1){const r=e.width/t.width||1,n=(i?-e.height/t.height:e.height/t.height)||1,s=e.xmin-r*t.xmin,o=i?e.ymax-n*t.ymin:e.ymin-n*t.ymin;return new $(r,n,s,o)}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 Z{xmin;ymin;xmax;ymax;constructor(t=1/0,e=1/0,i=-1/0,r=-1/0){this.xmin=t,this.ymin=e,this.xmax=i,this.ymax=r}static fromArray(t){return new Z(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 Z(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 r=this.width,n=this.height;let s;return r/n<t?(s=n*t-r,this.xmin-=(1-e)*s,this.xmax+=e*s):(s=r/t-n,this.ymin-=(1-i)*s,this.ymax+=i*s),this}scale(t){const e=this.centerX,i=this.centerY,r=this.width*t,n=this.height*t;this.xmin=e-r/2,this.xmax=e+r/2,this.ymin=i-n/2,this.ymax=i+n/2}}class W extends q{_running=!1;_busy=!1;_tickTime=0;_startTime=0;_duration=1/0;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(){this._running=!1}_startTick(t){this._busy=!0,this._tickTime=t,("function"==typeof requestAnimationFrame?requestAnimationFrame:t=>setTimeout(t,25))(()=>this._onTick())}_onTick(){const t=Date.now(),e=t-this._startTime,i=Math.min((e+10)/this._duration,1),r=i>=1;this._running?(r&&(this._running=!1),this.fire("tick",{elapsed:e,pct:i,done:r,time:t,tickTime:t-this._tickTime}),this._busy=!1,this._running&&this._startTick(t)):this._busy=!1}}class H extends q{_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 X=18485274.7;class Y{_transform=new $;_extent=new Z;_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)}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 Z(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,r){const n=1+.12*e,s=t>0?n:1/n;this._transform.scale(s,i,r),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),r=i*t;this._zoomFocus=e,this._animatingTransform=this._transform.clone(),this._zoomTween.start(i,r,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,r=i<1?e*i:e,n=this._getViewBounds();return e=>!t.arcIsSmaller?.(e,r)&&!(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,r=-t.by/t.my,n=(this._height-t.by)/t.my;return[Math.min(e,i),Math.min(r,n),Math.max(e,i),Math.max(r,n)]}_applyConstraints(){const t=this._transform;let e=Math.abs(t.mx);const i=this._getMinMX(),r=this._getMaxMX();(this._crs.toLowerCase().includes("3857")||this._crs.toLowerCase().includes("webmercator"))&&e<i&&(e=i),e>r&&(e=r);const n=t.my>0?e:-e,s=this._getStrictBounds(),o=(this._width/2-t.bx)/t.mx;let a=(this._height/2-t.by)/t.my;if(s){const t=this._height/(2*e),i=s.ymax-t,r=s.ymin+t;r>i?a=(s.ymin+s.ymax)/2:a>i?a=i:a<r&&(a=r)}const l=this._width/2-o*e,c=this._height/2-a*n;this._transform=new $(e,n,l,c)}_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),r=e(t.ymin,t.ymax,t.centerY),n=t.width/this._width/(1e-16*i),s=t.height/this._height/(1e-16*r);return Math.max(n,s)}_getStrictBounds(){const t=this._crs.toLowerCase();return"epsg:3857"===t||"webmercator"===t?new Z(-1/0,-18485274.7,1/0,X):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}}class K{snapVertices(t,i,r){e.internal.snapVerticesToPoint(t,i,r)}insertVertex(t,i,r){e.internal.insertVertex(t,i,r)}deleteVertex(t,i){e.internal.deleteVertex(t,i)}appendEmptyArc(t){e.internal.appendEmptyArc(t)}appendVertex(t,i){e.internal.appendVertex(t,i)}deleteLastArc(t){e.internal.deleteLastArc(t)}findNearestVertices(t,i,r){return e.internal.findNearestVertices(t,i,r)}findArcIdFromVertexId(t,i){return e.internal.findArcIdFromVertexId(t,i)}vertexIsArcEndpoint(t,i){return e.internal.vertexIsArcEndpoint(t,i)}forEachSegmentInShape(t,i,r){e.internal.forEachSegmentInShape(t,i,r)}findClosestPointOnSeg(t,i,r,n,s,o,a){return e.internal.findClosestPointOnSeg(t,i,r,n,s,o,a)}addIntersectionCuts(t,i){e.internal.addIntersectionCuts(t,i)}findSegmentIntersections(t,i){return e.internal.findSegmentIntersections(t,i)}getIntersectionLayer(t,i,r){return e.internal.getIntersectionLayer(t,i,r)}getAvgSegment(t){return e.internal.getAvgSegment(t)}simplifyArcsFast(t,i){return e.internal.simplifyArcsFast(t,i)}layerHasGeometry(t){return e.internal.layerHasGeometry(t)}getLayerBounds(t,i){const r=e.internal.getLayerBounds(t,i);return r?{xmin:r.xmin,ymin:r.ymin,xmax:r.xmax,ymax:r.ymax}:{xmin:NaN,ymin:NaN,xmax:NaN,ymax:NaN}}getDatasetBounds(t){const i=e.internal.getDatasetBounds(t);return{xmin:i.xmin,ymin:i.ymin,xmax:i.xmax,ymax:i.ymax}}exportDatasetsToPack(t,i){return e.internal.exportDatasetsToPack(t,i??{})}restoreSessionData(t){return e.internal.restoreSessionData(t)}pack(t){return e.internal.pack(t)}unpackSessionData(t){return e.internal.unpackSessionData(t)}exportPackedDatasets(t,i){return e.internal.exportPackedDatasets(t,i??{})}exportFileContent(t,i){return e.internal.exportFileContent(t,i)}copyDataset(t){return e.internal.copyDataset(t)}runImport(t,i){const r=e.internal.parseCommands(t);return r.length>0&&"i"===r[0].name&&(r[0].options.input=i),new Promise((t,i)=>{e.internal.runParsedCommands(r,new e.internal.Job,(e,r)=>{if(e)return void i(e);const n=r.catalog.getDefaultTargets();0!==n.length?t(n[0].dataset):i(new Error("No layers found in dataset"))})})}runOnDataset(t,i,r){return new Promise((n,s)=>{const o=new e.internal.Job;o.catalog.addDataset(i);const a=e.internal.parseCommands(t);if(r)for(const t of a)t.options&&(t.options.input=r);e.internal.runParsedCommands(a,o,(t,e)=>{if(t)return void s(t);const i=e.catalog.getDefaultTargets();0!==i.length?n(i[0].dataset):s(new Error("mapshaper command completed but produced no default target"))})})}runOnDatasetParsed(t,i,r){return new Promise((n,s)=>{const o=new e.internal.Job;if(o.catalog.addDataset(i),r)for(const e of t)e.options&&(e.options.input=r);e.internal.runParsedCommands(t,o,(t,e)=>{if(t)return void s(t);const i=e.catalog.getDefaultTargets();0!==i.length?n(i[0].dataset):s(new Error("mapshaper command completed but produced no default target"))})})}}let J=null;function Q(){return J??(J=new K)}const tt=6378137;class et{_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(40075016.6855*t/512):0}async reproject(t,e){for(const i of e.values())i.reproject&&await i.reproject(t);this._crs=t;const i=Q(),r=new Z;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&&r.merge(new Z(n.xmin,n.ymin,n.xmax,n.ymax))}}return r.hasBounds()&&r.scale(1.07),r}_webMercatorToLatLng(t,e){const i=180/Math.PI;return[t/tt*i,i*(.5*Math.PI-2*Math.atan(Math.exp(-e/tt)))]}}function it(t,e){return t?.name?String(t.name):t?.id?String(t.id):`layer-${e}`}function rt(t){return t&&Array.isArray(t)?"number"==typeof t[0]?[t]:Array.isArray(t[0])?t:[]:[]}class nt{_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 r=this._ctx;r.strokeStyle=e.color||"#333",r.lineWidth=(e.width??1)*this._pixelRatio,r.lineCap="round",r.lineJoin="round";let n=0;r.beginPath(),t.forEach(t=>{t&&t.forEach(t=>{t.forEach(t=>{n>0&&n%25==0&&(r.stroke(),r.beginPath());const e=i.getArcIter(t);this.drawPathSnapping(e,r),n++})})}),r.stroke()}drawArcs(t,e,i){if(0===e.width)return;const r=this._ctx,n=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<n;e++){if(i&&!i(e))continue;s>0&&s%25==0&&(r.stroke(),r.beginPath());const n=t.getArcIter(e);this.drawPathSnapping(n,r),s++}r.stroke()}drawPathSnapping(t,e){const i=this._transform.mx*this._pixelRatio,r=this._transform.my*this._pixelRatio,n=this._transform.bx*this._pixelRatio,s=this._transform.by*this._pixelRatio;let o,a,l,c,h=0;if(t.hasNext()){for(o=2*(t.x*i+n)|0,a=2*(t.y*r+s)|0,e.moveTo(o/2,a/2);t.hasNext();)l=o,c=a,o=2*(t.x*i+n)|0,a=2*(t.y*r+s)|0,o===l&&a===c||(e.lineTo(o/2,a/2),h++);0===h&&e.lineTo(o/2+.1,a/2)}}drawPoints(t,e){const i=this._ctx,r=this._pixelRatio,n=this._transform.mx*r,s=this._transform.my*r,o=this._transform.bx*r,a=this._transform.by*r,l=(Number(e?.radius)||4)*r,c=e?.color||"#333",h=!1!==e?.fill;i.beginPath(),i.fillStyle=c,i.strokeStyle=c,t.forEach(t=>{if(!t)return;rt(t).forEach(t=>{const e=t[0]*n+o,r=t[1]*s+a;i.moveTo(e+l,r),i.arc(e,r,l,0,2*Math.PI)})}),h?i.fill():i.stroke()}drawVertexDots(t,e,i={}){const r=this._ctx,n=this._pixelRatio,s=this._transform.mx*n,o=this._transform.my*n,a=this._transform.bx*n,l=this._transform.by*n,c=i.dotColor||"#333",h=(i.dotRadius||3)*n,u=i.hoverColor||"#cc6acc",p=(i.hoverRadius||6)*n,d=i.hoverVertex;let f=null;d&&(f=[d[0]*s+a,d[1]*o+l]),r.fillStyle=c,r.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*s+a,e=n.y*o+l;f&&Math.abs(t-f[0])<1&&Math.abs(e-f[1])<1||(r.moveTo(t+h,e),r.arc(t,e,h,0,2*Math.PI))}})})}),r.fill(),f&&(r.fillStyle=u,r.beginPath(),"interpolated"===i.hoverType?r.rect(f[0]-p,f[1]-p,2*p,2*p):r.arc(f[0],f[1],p,0,2*Math.PI),r.fill())}drawPolygonFill(t,e,i,r,n){if(!e.getShapeIter)return;const s=this._ctx,o=this._pixelRatio,a=this._transform.mx*o,l=this._transform.my*o,c=this._transform.bx*o,h=this._transform.by*o;s.fillStyle=i;const u="number"==typeof n&&1!==n,p=s.globalAlpha;u&&(s.globalAlpha=p*Math.max(0,Math.min(1,n)));let d=0;s.beginPath();for(let i=0;i<t.length;i++){const n=t[i];if(!n)continue;let o=!0;if(r){o=!1;for(const t of n){for(const e of t){if(r(e>=0?e:~e)){o=!0;break}}if(o)break}}if(o){d>0&&d>=100&&(s.fill("evenodd"),s.beginPath(),d=0);for(const t of n){const i=e.getShapeIter(t);if(!i.hasNext())continue;let r,n,o=2*(i.x*a+c)|0,u=2*(i.y*l+h)|0;for(s.moveTo(o/2,u/2);i.hasNext();)r=o,n=u,o=2*(i.x*a+c)|0,u=2*(i.y*l+h)|0,o===r&&u===n||s.lineTo(o/2,u/2);s.closePath()}d++}}d>0&&s.fill("evenodd"),u&&(s.globalAlpha=p)}drawDrawingOverlay(t){const e=this._ctx,i=this._pixelRatio,r=this._transform.mx*i,n=this._transform.my*i,s=this._transform.bx*i,o=this._transform.by*i,a=t.drawColor||"#0078ff",l=t.vertices,c=t.cursorCoord,h=t=>[t[0]*r+s,t[1]*n+o];if(l.length>0){e.strokeStyle=a,e.lineWidth=2*i,e.lineJoin="round",e.lineCap="round",e.setLineDash([]),e.beginPath();const t=h(l[0]);e.moveTo(t[0],t[1]);for(let t=1;t<l.length;t++){const i=h(l[t]);e.lineTo(i[0],i[1])}e.stroke()}if(l.length>0&&c){const r=h(l[l.length-1]),n=h(c);if(e.strokeStyle=a,e.lineWidth=1.5*i,e.setLineDash([6*i,4*i]),e.beginPath(),e.moveTo(r[0],r[1]),e.lineTo(n[0],n[1]),"polygon"===t.geometryType&&l.length>=2){const t=h(l[0]);e.moveTo(n[0],n[1]),e.lineTo(t[0],t[1])}e.stroke(),e.setLineDash([])}if(l.length>0){const t=4*i;e.fillStyle=a,e.beginPath();for(const i of l){const r=h(i);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=h(t.snapCoord),n=7*i;e.strokeStyle="#ff4444",e.lineWidth=2*i,e.beginPath(),"edge"===t.snapKind?e.rect(r[0]-n,r[1]-n,2*n,2*n):e.arc(r[0],r[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 st{_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 ot{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 at=Object.freeze({ok:!0,value:void 0});function lt(t){return{ok:!0,value:t}}const ct=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"}})}),ht=new Set(["rename-fields","rename-layers","sort","sort-features","filter-fields","drop","target","uniq","unique-features"]),ut=new Set(["buffer","clean","dissolve","mosaic","union","snap","check-geometry","simplify"]);function pt(t){const e=[],i=/(?:^|\s)-([a-z][a-z-]*)/gi;let r;for(;null!==(r=i.exec(t));)e.push(r[1].toLowerCase());return e}function dt(t,e,i,r){if(!1===i)return!1;if(!0===i)return!0;if(0===t.length)return e>=r;if(t.every(t=>ht.has(t)))return!1;return e>=(t.some(t=>ut.has(t))?Math.floor(.5*r):r)}const ft={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 mt(t){let e="attribute-only",i=!1;for(const r of t){if("target"===r)continue;const t=ft[r];if(void 0===t)return"unknown";i=!0,e=gt(e,t)}return i?e:"unknown"}const _t={"attribute-only":0,"crs-only":1,"topology-only":2,"shape-count":3,unknown:3};function gt(t,e){return _t[t]>=_t[e]?t:e}async function yt(t,e,i,r,n){if(t._removed)return ct.hostRemoved();const s=t._sources.get(e);if(!s)return ct.notFound("source",e);const o=s.getDataset();if(!o)return ct.notFound("source",e);const a=Q().copyDataset(o);let l,c=!1;if(t._workerPool){const e=o.arcs?.getPointCount?.()??0,r=function(t,e,i,r){return!1!==i&&(!0===i||dt(pt(t),e,i,r))}(i,e,t._workerMode,t._workerThreshold),n=t._workerRouting;c=n?n({cmd:i,heads:pt(i),vertexCount:e,mode:t._workerMode,threshold:t._workerThreshold,defaultDecision:r}):r}try{l=c?await async function(t,e,i,r,n){if(!t._workerPool)throw new Error("_runViaWorker: worker pool not available");const s=t._workerPool.reserveId(),o=e.arcs?.getPointCount?.()??0,a="undefined"!=typeof performance?performance.now():Date.now();t.fire("workerjobstart",{id:s,cmd:i,label:r,datasetVertexCount:o});try{const r=await Q().exportDatasetsToPack([e],{compact:!1}),o=bt(r),l=t._workerPool.dispatchWithId(s,i,r,n,o),c=await l,h=await Q().restoreSessionData(c);if(!h.datasets||0===h.datasets.length)throw new Error("worker: no dataset in response");const u=("undefined"!=typeof performance?performance.now():Date.now())-a;return t.fire("workerjobend",{id:s,ok:!0,durationMs:u}),h.datasets[0]}catch(e){const i=("undefined"!=typeof performance?performance.now():Date.now())-a;throw t.fire("workerjobend",{id:s,ok:!1,durationMs:i,errorMessage:e?.message??String(e)}),e}}(t,o,i,r,n):await Q().runOnDataset(i,o,n)}catch(e){return t._removed?ct.hostRemoved():(t.fire("error",{error:e}),ct.mapshaper(e,{cmd:i,operation:r}))}return t._removed?ct.hostRemoved():xt(t,e,a,l,r,function(t){return mt(pt(t))}(i))}async function vt(t,e,i,r,n){if(t._removed)return ct.hostRemoved();const s=t._sources.get(e);if(!s)return ct.notFound("source",e);const o=s.getDataset();if(!o)return ct.notFound("source",e);const a=Q().copyDataset(o),l=i.map(t=>t.name);let c,h=!1;if(t._workerPool){const e=o.arcs?.getPointCount?.()??0,i=dt(l,e,t._workerMode,t._workerThreshold),r=t._workerRouting;h=r?r({cmd:l.map(t=>`-${t}`).join(" "),heads:l,vertexCount:e,mode:t._workerMode,threshold:t._workerThreshold,defaultDecision:i}):i}try{c=h?await async function(t,e,i,r,n){if(!t._workerPool)throw new Error("_runViaWorkerParsed: worker pool not available");const s=t._workerPool.reserveId(),o=e.arcs?.getPointCount?.()??0,a="undefined"!=typeof performance?performance.now():Date.now(),l=i.map(t=>`-${t.name}`).join(" ");t.fire("workerjobstart",{id:s,cmd:l,label:r,datasetVertexCount:o});try{const r=await Q().exportDatasetsToPack([e],{compact:!1}),o=bt(r),l=t._workerPool.dispatchWithId(s,i,r,n,o),c=await l,h=await Q().restoreSessionData(c);if(!h.datasets||0===h.datasets.length)throw new Error("worker: no dataset in response");const u=("undefined"!=typeof performance?performance.now():Date.now())-a;return t.fire("workerjobend",{id:s,ok:!0,durationMs:u}),h.datasets[0]}catch(e){const i=("undefined"!=typeof performance?performance.now():Date.now())-a;throw t.fire("workerjobend",{id:s,ok:!1,durationMs:i,errorMessage:e?.message??String(e)}),e}}(t,o,i,r,n):await Q().runOnDatasetParsed(i,o,n)}catch(e){return t._removed?ct.hostRemoved():(t.fire("error",{error:e}),ct.mapshaper(e,{operation:r}))}return t._removed?ct.hostRemoved():xt(t,e,a,c,r,mt(l))}function xt(t,e,i,r,n,s="unknown"){const o=t._sources.get(e);return o?(t._activeTransaction&&t._activeTransaction._captureFirstTouch(e,i),o.setDataset(r),t._history.push(new ot({source:o,before:i,after:r,label:n})),t._history.isCapturing()||t._fireHistoryChange(),function(t){return"shape-count"===t||"topology-only"===t||"unknown"===t}(s)&&t._fireSelectionChange(t._selection.clear()),t._scheduleRender(),at):ct.notFound("source",e)}function bt(t){const e=[],i=new Set,r=t=>{if(t&&"object"==typeof t){if(t instanceof Uint8Array){const r=t.buffer;return void(r instanceof ArrayBuffer&&!i.has(r)&&(i.add(r),e.push(r)))}if(t instanceof ArrayBuffer)i.has(t)||(i.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 wt(t,e){for(let i=0;i<t.length;i++){const r=t[i];if(r){if(it(r,i)===e)return r;if(r.name===e)return r;if(r.id===e)return r}}return null}class St{_sources;constructor(t){this._sources=t}resolve(t,e){const i=this._sources.get(t);return i?wt(i.getLayers(),e):null}resolveInLayers(t,e){return wt(t,e)}}async function Tt(t,e,i){const r=t.host._sources.get(e.source);if(!r)return ct.notFound("source",e.source);const n=r.getDataset();if(!n)return ct.notFound("source",e.source);if(!wt(n.layers,e.target))return ct.notFound("layer",e.target);const s="string"==typeof e.mask&&e.mask.length>0;if(s===Array.isArray(e.bbox))return ct.validation(s?"mask":"bbox","must supply exactly one of `mask` or `bbox`");if(s){if(!wt(n.layers,e.mask))return ct.notFound("mask",e.mask)}else{const t=e.bbox;if(4!==t.length||!t.every(t=>Number.isFinite(t)))return ct.validation("bbox","must be [xmin, ymin, xmax, ymax] of finite numbers");if(t[0]>=t[2]||t[1]>=t[3])return ct.validation("bbox","must satisfy xmin<xmax and ymin<ymax")}const o=s?{source:e.mask}:{bbox:e.bbox};e.cleanup&&(o.cleanup=!0),e.removeSlivers&&(o.remove_slivers=!0);const a="clip"===i?"Clip":"Erase";return t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:i,options:o}],`${a} ${e.target}`)}const Ct="__emap_merge";async function Mt(t){const e=t.host._selection.getAll();if(0===e.length)return ct.validation("selection","selection is empty");const i=e[0].source,r=e[0].layer;for(const t of e)if(t.source!==i||t.layer!==r)return ct.validation("selection","selection spans multiple sources or layers");const n=t.host.layers.resolve(i,r);if(!n)return ct.notFound("layer",r);if(!function(t,e){const i=t.data?.getRecords?.();if(!i||0===i.length)return!1;const r=new Set(e);for(let t=0;t<i.length;t++){const e=i[t]??{};e[Ct]=r.has(t)?"M":`k_${t}`,i[t]=e}return!0}(n,e.map(t=>t.id).slice().sort((t,e)=>t-e)))return ct.validation("layer","layer has no data table; cannot stamp discriminator");const s=function(t,e){const i={fields:[Ct]},r=e.data?.getFields?.();if(r&&r.length>0){const t=r.filter(t=>t!==Ct&&!t.includes(","));t.length>0&&(i.copy_fields=t)}return[{name:"target",options:{target:t}},{name:"dissolve",options:i},{name:"filter-fields",options:{fields:[Ct],invert:!0}}]}(r,n),o=`Merge ${e.length} feature${e.length>1?"s":""}`,a=await t.runDatasetCommandParsed(i,s,o);return a.ok||function(t){const e=t.data?.getRecords?.();if(!e)return;for(const t of e)t&&Ct in t&&delete t[Ct]}(n),a}const At=new Set(["left","right","outer","inner"]),Et=new Set(["flat","round"]),It=/^-?\d+(\.\d+)?$/;function Pt(t){return"number"==typeof t&&Number.isInteger(t)&&t>0}async function Dt(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);const n=wt(r.layers,e.target);if(!n)return ct.notFound("layer",e.target);if("number"==typeof e.radius){if(!Number.isFinite(e.radius)||e.radius<=0)return ct.validation("radius","must be a positive finite number")}else{if("string"!=typeof e.radius||0===e.radius.trim().length)return ct.validation("radius","must be a positive number or non-empty expression");if(It.test(e.radius)&&Number(e.radius)<=0)return ct.validation("radius","numeric string must be a positive number")}if("string"==typeof e.radius&&!t.host._allowExpressionEvaluation([e.radius],"bufferLayer"))return ct.expressionDisabled("bufferLayer");if(void 0!==e.vertices&&!Pt(e.vertices))return ct.validation("vertices","must be a positive integer");if(void 0!==e.arcQuality&&!Pt(e.arcQuality))return ct.validation("arcQuality","must be a positive integer");if(void 0!==e.sliceLength&&!Pt(e.sliceLength))return ct.validation("sliceLength","must be a positive integer");if(void 0!==e.backtrack&&!Pt(e.backtrack))return ct.validation("backtrack","must be a positive integer");if(void 0!==e.tolerance&&!("number"==typeof(s=e.tolerance)&&Number.isFinite(s)&&s>0))return ct.validation("tolerance","must be a positive finite number");var s;if(void 0!==e.type&&!At.has(e.type))return ct.validation("type","must be one of: left, right, outer, inner");if(void 0!==e.capStyle&&!Et.has(e.capStyle))return ct.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 o={radius:String(e.radius)};void 0!==e.capStyle&&(o.cap_style=e.capStyle),void 0!==e.vertices&&(o.vertices=e.vertices),void 0!==e.arcQuality&&(o.arc_quality=e.arcQuality),void 0!==e.tolerance&&(o.tolerance=e.tolerance),void 0!==e.type&&(o.type=e.type),!0===e.planar&&(o.planar=!0),!0===e.v2&&(o.v2=!0),void 0!==e.sliceLength&&(o.slice_length=e.sliceLength),void 0!==e.backtrack&&(o.backtrack=e.backtrack);const a=[{name:"target",options:{target:e.target}},{name:"buffer",options:o}];return t.runDatasetCommandParsed(e.source,a,`Buffer ${e.target}`)}class kt{_emap;constructor(t){this._emap=t}get _ctx(){return{host:this._emap,runDatasetCommand:(t,e,i,r)=>yt(this._emap,t,e,i,r),runDatasetCommandParsed:(t,e,i,r)=>vt(this._emap,t,e,i,r),applyDatasetReplace:(t,e,i,r)=>xt(this._emap,t,e,i,r)}}clipLayer(t){return async function(t,e){return Tt(t,e,"clip")}(this._ctx,t)}eraseLayer(t){return async function(t,e){return Tt(t,e,"erase")}(this._ctx,t)}dissolveLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);const n=Array.isArray(e.fields)&&e.fields.length>0;if(void 0!==e.field&&n)return ct.validation("field","`field` and `fields` are mutually exclusive");if(void 0!==e.field&&("string"!=typeof e.field||e.field.includes(",")))return ct.validation("field","field name must be a string without `,`");if(!t.host._allowExpressionEvaluation([e.calc,e.where],"dissolveLayer"))return ct.expressionDisabled("dissolveLayer");const s={};if(e.field)s.fields=[e.field];else if(n){const t=e.fields.filter(t=>"string"==typeof t&&!t.includes(","));t.length>0&&(s.fields=t)}const o=t=>Array.isArray(t)?t.filter(t=>"string"==typeof t&&!t.includes(",")):[],a=o(e.sumFields);a.length>0&&(s.sum_fields=a);const l=o(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 Dt(this._ctx,t)}applyExpression(t){return async function(t,e){if(!e.expression||!e.expression.trim())return ct.validation("expression","must be a non-empty expression");const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.expression,e.where],"applyExpression"))return ct.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 ct.validation("expression","must supply `expression` or `removeEmpty: true`");const r=t.host._sources.get(e.source);if(!r)return ct.notFound("source",e.source);const n=r.getDataset();if(!n)return ct.notFound("source",e.source);if(!wt(n.layers,e.target))return ct.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.expression],"filterFeatures"))return ct.expressionDisabled("filterFeatures");const s={};return i&&(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 i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);const n="number"==typeof e.minArea&&Number.isFinite(e.minArea),s="number"==typeof e.minVertices&&Number.isInteger(e.minVertices)&&e.minVertices>0;if(!n&&!s)return ct.validation("minArea","must supply at least one of `minArea` or `minVertices`");if(n&&e.minArea<0)return ct.validation("minArea","must be non-negative");const o={};return n&&(o.min_area=String(e.minArea)),s&&(o.min_vertices=e.minVertices),e.removeEmpty&&(o.remove_empty=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"filter-islands",options:o}],`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 ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);if("number"!=typeof e.minArea||!Number.isFinite(e.minArea)||e.minArea<=0)return ct.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 ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.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]?ct.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}`):ct.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 ct.notFound("source",e.source);const r=i.getDataset();return r?wt(r.layers,e.target)?t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"explode",options:{}}],`Explode ${e.target}`):ct.notFound("layer",e.target):ct.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 ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.where],"innerlinesLayer"))return ct.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 ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.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 ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);const n=t=>void 0===t||"number"==typeof t&&Number.isFinite(t)&&t>=0;if(!n(e.gapFillArea))return ct.validation("gapFillArea","must be a finite non-negative number");if(!n(e.sliverControl))return ct.validation("sliverControl","must be a finite non-negative number");if(!n(e.snapInterval))return ct.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 ct.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 i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.calc],"mosaicLayer"))return ct.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 ct.validation("targets","must supply at least 2 target layers");const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);for(const t of e.targets){if("string"!=typeof t||t.includes(","))return ct.validation("targets",`target name must not contain ',': ${String(t)}`);if(!wt(r.layers,t))return ct.notFound("layer",t)}const n=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:n}},{name:"union",options:s}],`Union ${n}`)}(this._ctx,t)}divideLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);const n=wt(r.layers,e.target);if(!n)return ct.notFound("layer",e.target);if("polyline"!==n.geometry_type)return ct.validation("target",`expected polyline layer, got ${n.geometry_type??"unknown"}`);const s=wt(r.layers,e.divider);if(!s)return ct.notFound("divider",e.divider);if("polygon"!==s.geometry_type)return ct.validation("divider",`expected polygon layer, got ${s.geometry_type??"unknown"}`);const o={source:e.divider};if(e.fields&&e.fields.length>0){const t=e.fields.filter(t=>!t.includes(","));t.length>0&&(o.fields=t)}return e.force&&(o.force=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"divide",options:o}],`Divide ${e.target}`)}(this._ctx,t)}pointsLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);const n=wt(r.layers,e.target);if(!n)return ct.notFound("layer",e.target);const s=n.geometry_type;switch(e.type){case"centroid":case"inner":if("polygon"!==s)return ct.validation("type",`${e.type} requires polygon target, got ${s??"unknown"}`);break;case"midpoints":case"interpolated":if("polyline"!==s)return ct.validation("type",`${e.type} requires polyline target, got ${s??"unknown"}`);break;case"vertices":case"endpoints":if("polygon"!==s&&"polyline"!==s)return ct.validation("type",`${e.type} requires polygon/polyline target, got ${s??"unknown"}`);break;default:return ct.validation("type",`unknown type: ${String(e.type)}`)}if("interpolated"===e.type&&!("number"==typeof e.interval&&e.interval>0))return ct.validation("interval","interpolated points require a positive interval");const o={[e.type]:!0};return"interpolated"===e.type&&(o.interval=String(e.interval)),e.name&&e.name.trim()&&(o.name=e.name),e.noReplace&&(o.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"points",options:o}],`Points ${e.target}`)}(this._ctx,t)}linesLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);const n=wt(r.layers,e.target);if(!n)return ct.notFound("layer",e.target);if("polygon"!==n.geometry_type)return ct.validation("target",`expected polygon layer, got ${n.geometry_type??"unknown"}`);const s={},o=e.fields?.filter(t=>"string"==typeof t&&!t.includes(","));return o&&o.length>0&&(s.fields=o),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 i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);const n=wt(r.layers,e.target);if(!n)return ct.notFound("layer",e.target);if("polyline"!==n.geometry_type)return ct.validation("target",`expected polyline layer, got ${n.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 i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(void 0!==e.target&&!wt(r.layers,e.target))return ct.notFound("layer",e.target);if(1!==[void 0!==e.percentage,void 0!==e.interval,void 0!==e.resolution].filter(Boolean).length)return ct.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 ct.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 ct.validation("interval","must be a positive finite number");n.interval=String(t)}else{const t=e.resolution;if(!/^\d+x\d+$/.test(t))return ct.validation("resolution","must match `WIDTHxHEIGHT` (digits)");n.resolution=t}if(void 0!==e.weighting&&void 0!==e.method&&"weighted"!==e.method)return ct.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 s=[];e.target&&s.push({name:"target",options:{target:e.target}}),s.push({name:"simplify",options:n});const o=`Simplify ${e.target??e.source}`;return t.runDatasetCommandParsed(e.source,s,o)}(this._ctx,t)}projectLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(void 0!==e.target&&!wt(r.layers,e.target))return ct.notFound("layer",e.target);const n=(e.crs??"").trim();if(0===n.length)return ct.validation("crs","must be a non-empty CRS string");const s={crs:n};e.init&&e.init.trim()&&(s.init=e.init),e.densify&&(s.densify=!0);const o=[];e.target&&o.push({name:"target",options:{target:e.target}}),o.push({name:"proj",options:s});const a=`Project ${e.target??e.source}`;return t.runDatasetCommandParsed(e.source,o,a)}(this._ctx,t)}affineLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(void 0!==e.target&&!wt(r.layers,e.target))return ct.notFound("layer",e.target);const n=Array.isArray(e.shift),s="number"==typeof e.rotate&&0!==e.rotate,o=void 0!==e.scale&&("number"==typeof e.scale?1!==e.scale:Array.isArray(e.scale));if(!n&&!s&&!o)return ct.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 ct.validation("shift","must be [dx, dy] of finite numbers")}if(s&&!Number.isFinite(e.rotate))return ct.validation("rotate","must be a finite number (degrees)");if(o&&Array.isArray(e.scale)){const t=e.scale;if(2!==t.length||!t.every(t=>Number.isFinite(t)&&0!==t))return ct.validation("scale","must be [sx, sy] of nonzero finite numbers")}else if(o&&"number"==typeof e.scale&&(!Number.isFinite(e.scale)||0===e.scale))return ct.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 ct.validation("anchor","must be [x, y] of finite numbers");if(!t.host._allowExpressionEvaluation([e.where],"affineLayer"))return ct.expressionDisabled("affineLayer");const a={};n&&(a.shift=[String(e.shift[0]),String(e.shift[1])]),s&&(a.rotate=e.rotate),o&&(a.scale=(e.scale,e.scale)),e.anchor&&(a.anchor=[e.anchor[0],e.anchor[1]]),e.where&&e.where.trim()&&(a.where=e.where);const l=[];e.target&&l.push({name:"target",options:{target:e.target}}),l.push({name:"affine",options:a});const c=`Affine ${e.target??e.source}`;return t.runDatasetCommandParsed(e.source,l,c)}(this._ctx,t)}renameLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);const n=(e.name??"").trim();if(0===n.length)return ct.validation("name","must be a non-empty string");if(n.includes(","))return ct.validation("name","must not contain `,`");if(n!==e.target&&r.layers.some(t=>(t?.name??"")===n))return ct.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 ct.validation("targets","must supply at least 2 target layers");const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);for(const t of e.targets)if("string"!=typeof t||t.includes(","))return ct.validation("targets",`target name must not contain ',': ${String(t)}`);const n=e.targets.map(t=>wt(r.layers,t));for(let t=0;t<n.length;t++)if(!n[t])return ct.notFound("layer",e.targets[t]);if(!e.force){const t=n[0]?.geometry_type;if(!n.every(e=>e?.geometry_type===t))return ct.validation("targets","targets have mixed geometry types; pass `force: true` to merge anyway")}const s=e.targets.join(","),o={};return e.name&&e.name.trim()&&(o.name=e.name),e.force&&(o.force=!0),e.flatten&&(o.flatten=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:s}},{name:"merge-layers",options:o}],`Merge ${s}`)}(this._ctx,t)}splitLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);const n=(e.expression??"").trim();if(0===n.length)return ct.validation("expression","must be a non-empty expression");if(!t.host._allowExpressionEvaluation([n],"splitLayer"))return ct.expressionDisabled("splitLayer");const s={expression:n};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 i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();return r?wt(r.layers,e.target)?t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"drop",options:{}}],`Drop ${e.target}`):ct.notFound("layer",e.target):ct.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 ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);const n=(e.expression??"").trim();if(0===n.length)return ct.validation("expression","must be a non-empty expression");if(!t.host._allowExpressionEvaluation([n],"sortFeatures"))return ct.expressionDisabled("sortFeatures");const s={expression:n};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 i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);const n=(e.expression??"").trim();if(0===n.length)return ct.validation("expression","must be a non-empty expression");if(!t.host._allowExpressionEvaluation([n],"uniqueFeatures"))return ct.expressionDisabled("uniqueFeatures");if(void 0!==e.maxCount&&!("number"==typeof e.maxCount&&e.maxCount>0))return ct.validation("maxCount","must be a positive number");const s={expression:n};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 i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);if(!Array.isArray(e.fields)||0===e.fields.length)return ct.validation("fields","must be a non-empty array");for(const t of e.fields){if("string"!=typeof t||0===t.trim().length)return ct.validation("fields",`field name must be a non-empty string: ${String(t)}`);if(t.includes(","))return ct.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 ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);if(!e.mapping||"object"!=typeof e.mapping)return ct.validation("mapping","must be an object of { oldName: newName }");const n=Object.entries(e.mapping);if(0===n.length)return ct.validation("mapping","must contain at least one rename pair");const s=[];for(const[t,e]of n){const i=(t??"").trim(),r=(e??"").trim();if(0===i.length||0===r.length)return ct.validation("mapping",`field names must be non-empty: ${t}=${e}`);if(i.includes(",")||i.includes("=")||r.includes(",")||r.includes("="))return ct.validation("mapping",`field names must not contain ',' or '=': ${t}=${e}`);s.push(`${i}=${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 i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);if(!Array.isArray(e.keys)||2!==e.keys.length)return ct.validation("keys","must be a 2-element [targetKey, sourceKey] array");const[n,s]=e.keys.map(t=>"string"==typeof t?t.trim():"");if(0===n.length||0===s.length)return ct.validation("keys","both keys must be non-empty strings");if(n.includes(",")||s.includes(","))return ct.validation("keys","keys must not contain `,`");let o,a;const l=e.data;if(!l||"object"!=typeof l)return ct.validation("data","must be { csv } | { json } | { layer }");if("layer"in l&&"string"==typeof l.layer&&l.layer.trim().length>0)o=l.layer.trim();else if("csv"in l&&("string"==typeof l.csv||l.csv instanceof Uint8Array)){const t=".emap-join.csv";o=t,a={[t]:l.csv}}else{if(!("json"in l)||void 0===l.json)return ct.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),o=t,a={[t]:e}}}if(!t.host._allowExpressionEvaluation([e.where,e.calc],"joinTable"))return ct.expressionDisabled("joinTable");const c={source:o,keys:[n,s]};if(e.fields&&e.fields.length>0){const t=e.fields.filter(t=>"string"==typeof t&&!t.includes(","));t.length>0&&(c.fields=t)}return e.prefix&&e.prefix.length>0&&(c.prefix=e.prefix),e.where&&e.where.trim().length>0&&(c.where=e.where),e.calc&&e.calc.trim().length>0&&(c.calc=e.calc),e.unjoined&&(c.unjoined=!0),e.unmatched&&(c.unmatched=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"join",options:c}],`Join ${e.target}`,a)}(this._ctx,t)}dataFill(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);if("string"!=typeof e.field||0===e.field.trim().length)return ct.validation("field","must be a non-empty string");if(e.field.includes(",")||e.field.includes("="))return ct.validation("field","must not contain `,` or `=`");if(void 0!==e.weightField){if("string"!=typeof e.weightField||0===e.weightField.trim().length)return ct.validation("weightField","must be a non-empty string when supplied");if(e.weightField.includes(",")||e.weightField.includes("="))return ct.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 ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!r.arcs)return at;const n=Q(),s=n.copyDataset(r),o=n.copyDataset(r);try{n.addIntersectionCuts(o,{snap_interval:e.snapInterval,no_snap:e.noSnap,rebuild_topology:e.rebuildTopology})}catch(e){return t.host.fire("error",{error:e}),ct.mapshaper(e,{operation:"rebuildTopology"})}return t.applyDatasetReplace(e.source,s,o,"Rebuild topology")}(this._ctx,t)}checkGeometry(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(void 0!==e.target&&!wt(r.layers,e.target))return ct.notFound("layer",e.target);if(!r.arcs)return lt({ok:!0,intersections:[],intersectionCount:0});const n={};void 0!==e.tolerance&&(n.tolerance=e.tolerance);const s=Q().findSegmentIntersections(r.arcs,n).map(t=>({x:t.x,y:t.y}));return lt({ok:0===s.length,intersections:s,intersectionCount:s.length})}(this._ctx,t)}intersectionPointsLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);const n=wt(r.layers,e.target);if(!n)return ct.notFound("layer",e.target);if("polygon"!==n.geometry_type&&"polyline"!==n.geometry_type)return ct.validation("target",`expected polygon/polyline target, got ${n.geometry_type??"unknown"}`);if(!r.arcs)return ct.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 ct.validation("name",`another layer already named '${s}'`);if(void 0!==e.tolerance&&("number"!=typeof e.tolerance||!Number.isFinite(e.tolerance)||e.tolerance<=0))return ct.validation("tolerance","must be a positive finite number");const o={};void 0!==e.tolerance&&(o.tolerance=e.tolerance);const a=Q(),l=a.copyDataset(r),c=a.copyDataset(r);let h;try{const t=a.findSegmentIntersections(c.arcs,o),i=wt(c.layers,e.target);if(!i)throw new Error("intersectionPointsLayer: target lost in copyDataset");h=a.getIntersectionLayer(t,i,c.arcs),h.name=s,c.layers.push(h)}catch(e){return t.host.fire("error",{error:e}),ct.mapshaper(e,{operation:"intersectionPointsLayer"})}return t.applyDatasetReplace(e.source,l,c,`Intersection points ${e.target}`)}(this._ctx,t)}mergeSelected(){return Mt(this._ctx)}}class zt{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 Rt(t){return"polygon"===t.geometry_type||"polyline"===t.geometry_type}function Lt(t){t&&(t.editVersion=(t.editVersion??0)+1)}class Ft{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 Ft))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 r=t.opts.pointFeatures,n=this.opts.pointFeatures;if(r.length!==n.length)return!1;for(let t=0;t<r.length;t++){if(r[t].featureId!==n[t].featureId)return!1;if(r[t].layer!==n[t].layer)return!1}return!0}merge(t){t instanceof Ft&&(this.opts.dx+=t.opts.dx,this.opts.dy+=t.opts.dy,this._mergeAt=Date.now())}_apply(t,e){const{arcs:i,arcIds:r,pointFeatures:n,source:s}=this.opts;if(i&&r.length>0){const n=i.getVertexData?.();if(n){const{xx:s,yy:o,ii:a,nn:l}=n;for(const n of r){const r=a[n],c=l[n];for(let i=r;i<r+c;i++)s[i]+=t,o[i]+=e;i.updateArcBounds?.(n)}}}for(const i of n){const r=i.layer.shapes?.[i.featureId];if(r)for(const i of rt(r))i&&i.length>=2&&(i[0]+=t,i[1]+=e)}s.markDisplayArcsDirty?.(),Lt(s.getDataset?.())}}class Bt{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(Gt(this.opts.matrix))}_apply(t){const{arcs:e,arcIds:i,pointFeatures:r,source:n}=this.opts;if(e&&i.length>0){const r=e.getVertexData?.();if(r){const{xx:n,yy:s,ii:o,nn:a}=r;for(const r of i){const i=o[r],l=a[r];for(let e=i;e<i+l;e++){const i=n[e],r=s[e];n[e]=t.a*i+t.c*r+t.tx,s[e]=t.b*i+t.d*r+t.ty}e.updateArcBounds?.(r)}}}for(const e of r){const i=e.layer.shapes?.[e.featureId];if(i)for(const e of rt(i))if(e&&e.length>=2){const i=e[0],r=e[1];e[0]=t.a*i+t.c*r+t.tx,e[1]=t.b*i+t.d*r+t.ty}}n.markDisplayArcsDirty?.(),Lt(n.getDataset?.())}}function Ot(t,e=0,i=0){const r=Math.cos(t),n=Math.sin(t);return{a:r,b:n,c:-n,d:r,tx:e-r*e+n*i,ty:i-n*e-r*i}}function Nt(t,e,i=0,r=0){return{a:t,b:0,c:0,d:e,tx:i-t*i,ty:r-e*r}}function Vt(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 jt={a:1,b:0,c:0,d:1,tx:0,ty:0};function Gt(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,r=-t.b/e,n=-t.c/e,s=t.a/e;return{a:i,b:r,c:n,d:s,tx:-(i*t.tx+n*t.ty),ty:-(r*t.tx+s*t.ty)}}class Ut{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:r,yy:n,zz:s,nn:o}=i,a=!!s&&e.every(t=>t.zz);let l=0;for(const t of e)l+=t.xx.length;const c=new Float64Array(r.length+l),h=new Float64Array(n.length+l),u=a?new Float64Array(s.length+l):null;c.set(r),h.set(n),u&&s&&u.set(s);let p=r.length;for(const t of e)c.set(t.xx,p),h.set(t.yy,p),u&&t.zz&&u.set(t.zz,p),p+=t.xx.length;const d=new Int32Array(o.length+e.length);d.set(o);for(let t=0;t<e.length;t++)d[o.length+t]=e[t].xx.length;t.updateVertexData(d,c,h,u)}(t,this.opts.appendedArcs);for(const t of this.opts.remaps)t.layer.shapes[t.featureId]=Zt(t.newShape);this.opts.source.markDisplayArcsDirty?.(),Lt(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:r,yy:n,zz:s,nn:o}=i;if(o.length===e)return;if(e>o.length)return;let a=0;for(let t=0;t<e;t++)a+=o[t];const l=new Int32Array(e);l.set(o.subarray(0,e));const c=new Float64Array(r.subarray(0,a)),h=new Float64Array(n.subarray(0,a)),u=s?new Float64Array(s.subarray(0,a)):null;t.updateVertexData(l,c,h,u)}(t,this.opts.originalArcCount);for(const t of this.opts.remaps)t.layer.shapes[t.featureId]=Zt(t.originalShape);this.opts.source.markDisplayArcsDirty?.(),Lt(this.opts.source.getDataset?.())}}}function qt(t,e,i){const r=t.getArcs();if(!r)return null;const n=r.size();if(0===n||0===e.length)return null;const s=new Uint32Array(n),o=new Uint32Array(n),a=new Set;for(const t of e)a.add($t(t.layer,t.featureId));for(const t of i){if(!t.shapes)continue;if(!Rt(t))continue;const e=t.shapes;for(let i=0;i<e.length;i++){const r=e[i];if(!r)continue;const l=a.has($t(t,i));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>=n||(l?s[t]++:o[t]++)}}}const l=[];for(let t=0;t<n;t++)s[t]>0&&o[t]>0&&l.push(t);if(0===l.length)return null;const c=new globalThis.Map;for(let t=0;t<l.length;t++)c.set(l[t],n+t);const h=r.getVertexData?.();if(!h)return null;const{xx:u,yy:p,zz:d,ii:f,nn:m}=h,_=l.map(t=>{const e=f[t],i=m[t];return{xx:new Float64Array(u.subarray(e,e+i)),yy:new Float64Array(p.subarray(e,e+i)),zz:d?new Float64Array(d.subarray(e,e+i)):null}}),g=[];for(const t of e){if(!Rt(t.layer))continue;const e=t.layer.shapes?.[t.featureId];if(!e)continue;let i=!1;const r=e.map(t=>t.map(t=>{const e=t>=0?t:~t,r=c.get(e);return void 0===r?t:(i=!0,t>=0?r:~r)}));i&&g.push({layer:t.layer,featureId:t.featureId,originalShape:Zt(e),newShape:r})}return 0===g.length?null:{source:t,remaps:g,appendedArcs:_,originalArcCount:n}}function $t(t,e){return`${t.name??""}#${e}`}function Zt(t){return t.map(t=>t.slice())}class Wt{_emap;constructor(t){this._emap=t}translateSelected(t,e){if(0===t&&0===e)return ct.validation("offset","dx and dy are both 0 (no-op)");const i=this._emap._selection.getAll();if(0===i.length)return ct.validation("selection","selection is empty");const r=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=r.get(t.source);if(n||(n={arcIdSet:new Set,pointFeatures:[]},r.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===r.size)return ct.validation("selection","no resolvable layers in selection");const n=[],s=[];for(const[i,o]of r){const r=this._emap._sources.get(i);if(!r)continue;if(0===o.arcIdSet.size&&0===o.pointFeatures.length)continue;const a=new Ft({source:r,arcs:r.getArcs(),dx:t,dy:e,arcIds:Array.from(o.arcIdSet),pointFeatures:o.pointFeatures});a.do(),n.push(a),s.push(i)}if(0===n.length)return ct.validation("selection","every resolved layer was empty");const o=1===n.length?n[0]:new zt(n,`Translate ${i.length} features`);return this._emap._history.push(o),this._emap._fireHistoryChange(),this._emap._clearSpatialIndexesForSources(s),this._emap._scheduleRender(),at}_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 r=this._emap._sources.get(t.source);if(!r)continue;let n=i.get(t.source);n||(n={sourceId:t.source,source:r,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 r=[];if(t)for(const t of i.values()){if(0===t.pathFeatures.length)continue;const e=qt(t.source,t.pathFeatures,t.source.getLayers());if(!e)continue;const i=new Ut(e);i.do(),r.push(i),this._emap._invalidateShapeCachesForSources([t.sourceId])}for(const t of i.values()){const e=new Set;for(const i of t.pathFeatures){const r=i.layer.shapes?.[i.featureId];if(r)for(const i of r)if(Array.isArray(i))for(const r of i){if("number"!=typeof r)continue;const i=r>=0?r:~r;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:r}}beginTranslateSession(t){const e=this._buildSelectionBuckets(!1!==t?.splitSharedArcs);if(!e)return null;const{buckets:i,splitCmds:r}=e;let n=0,s=0,o=!1;const a=(t,e)=>{for(const r of i)0===r.arcIds.length&&0===r.pointFeatures.length||new Ft({source:r.source,arcs:r.source.getArcs(),dx:t,dy:e,arcIds:r.arcIds,pointFeatures:r.pointFeatures}).do()};return{move:(t,e)=>{o||0===t&&0===e||(a(t,e),n+=t,s+=e,this._emap._scheduleRender())},commit:()=>{if(o)return!1;o=!0;if(!!(0===n&&0===s)){for(let t=r.length-1;t>=0;t--)r[t].undo();return r.length>0&&this._emap._scheduleRender(),!1}const t=i.map(t=>new Ft({source:t.source,arcs:t.source.getArcs(),dx:n,dy:s,arcIds:t.arcIds,pointFeatures:t.pointFeatures})),e=i.reduce((t,e)=>t+e.arcIds.length+e.pointFeatures.length,0),a=[...r,...t],l=1===a.length?a[0]:new zt(a,`Translate ${e} features`);return this._emap._history.push(l),this._emap._fireHistoryChange(),this._emap._invalidateShapeCachesForSources(i.map(t=>t.sourceId)),this._emap._scheduleRender(),!0},cancel:()=>{if(!o){o=!0,0===n&&0===s||a(-n,-s);for(let t=r.length-1;t>=0;t--)r[t].undo();n=0,s=0,r.length>0&&this._emap._invalidateShapeCachesForSources(i.map(t=>t.sourceId)),this._emap._scheduleRender()}},getAccumulated:()=>[n,s]}}beginAffineSession(t,e){const i=this._buildSelectionBuckets(!1!==e?.splitSharedArcs);if(!i)return null;const{buckets:r,splitCmds:n}=i;let s,o;if(t)[s,o]=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=n.length-1;t>=0;t--)n[t].undo();return null}[s,o]=e}if(!Number.isFinite(s)||!Number.isFinite(o)){for(let t=n.length-1;t>=0;t--)n[t].undo();return null}const a=[s,o];let l={...jt},c=!1;const h=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 Bt({source:e.source,arcs:e.source.getArcs(),matrix:t,arcIds:e.arcIds,pointFeatures:e.pointFeatures}).do()};return{origin:a,applyDelta:t=>{c||h(t)||(u(t),l=Vt(t,l),this._emap._scheduleRender())},commit:t=>{if(c)return!1;if(c=!0,h(l)){for(let t=n.length-1;t>=0;t--)n[t].undo();return n.length>0&&this._emap._scheduleRender(),!1}const e=r.reduce((t,e)=>t+e.arcIds.length+e.pointFeatures.length,0),i=r.map(e=>new Bt({source:e.source,arcs:e.source.getArcs(),matrix:l,arcIds:e.arcIds,pointFeatures:e.pointFeatures,label:t})),s=[...n,...i],o=1===s.length?s[0]:new zt(s,t??`Transform ${e} feature${1===e?"":"s"}`);return this._emap._history.push(o),this._emap._fireHistoryChange(),this._emap._invalidateShapeCachesForSources(r.map(t=>t.sourceId)),this._emap._scheduleRender(),!0},cancel:()=>{if(!c){c=!0,h(l)||u(Gt(l));for(let t=n.length-1;t>=0;t--)n[t].undo();l={...jt},n.length>0&&this._emap._invalidateShapeCachesForSources(r.map(t=>t.sourceId)),this._emap._scheduleRender()}},getCumulative:()=>({...l})}}rotateSelected(t,e){if(0===t)return ct.validation("angleDegrees","angle is 0 (no-op)");const i=t*Math.PI/180;return this._applyAffineToSelection((t,e)=>Ot(i,t,e),e,t=>`Rotate ${t} feature${1===t?"":"s"}`)}scaleSelected(t,e,i){const r=t,n=e??t;return 1===r&&1===n?ct.validation("scale","sx and sy are both 1 (no-op)"):this._applyAffineToSelection((t,e)=>Nt(r,n,t,e),i,t=>`Scale ${t} feature${1===t?"":"s"}`)}_applyAffineToSelection(t,e,i){const r=this._emap._selection.getAll();if(0===r.length)return ct.validation("selection","selection is empty");const n=new globalThis.Map;for(const t of r){const e=this._emap.layers.resolve(t.source,t.layer);if(!e?.shapes)continue;const i=e.shapes[t.id];if(!i)continue;let r=n.get(t.source);if(r||(r={arcIdSet:new Set,pointFeatures:[]},n.set(t.source,r)),"point"===e.geometry_type)r.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&&r.arcIdSet.add(t>=0?t:~t)}}if(0===n.size)return ct.validation("selection","no resolvable layers in selection");let s,o;if(e)s=e[0],o=e[1];else{const t=this._computeSelectionCentroid(n);if(!t)return ct.validation("origin","no vertices in selection; cannot compute centroid");[s,o]=t}if(!Number.isFinite(s)||!Number.isFinite(o))return ct.validation("origin","computed origin is not finite");const a=t(s,o),l=[],c=[];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 r=new Bt({source:i,arcs:i.getArcs(),matrix:a,arcIds:Array.from(e.arcIdSet),pointFeatures:e.pointFeatures});r.do(),l.push(r),c.push(t)}if(0===l.length)return ct.validation("selection","every resolved layer was empty");const h=1===l.length?l[0]:new zt(l,i(r.length));return this._emap._history.push(h),this._emap._fireHistoryChange(),this._emap._clearSpatialIndexesForSources(c),this._emap._scheduleRender(),at}_computeSelectionCentroid(t){let e=1/0,i=1/0,r=-1/0,n=-1/0,s=!1;for(const[o,a]of t){const t=this._emap._sources.get(o);if(!t)continue;const l=t.getArcs(),c=l?.getVertexData?.();if(c&&a.arcIdSet.size>0){const{xx:t,yy:o,ii:l,nn:h}=c;for(const c of a.arcIdSet){const a=l[c],u=h[c];for(let l=a;l<a+u;l++){const a=t[l],c=o[l];a<e&&(e=a),a>r&&(r=a),c<i&&(i=c),c>n&&(n=c),s=!0}}}for(const t of a.pointFeatures){const o=t.layer.shapes?.[t.featureId];if(o)for(const t of rt(o)){if(!t||t.length<2)continue;const o=t[0],a=t[1];o<e&&(e=o),o>r&&(r=o),a<i&&(i=a),a>n&&(n=a),s=!0}}}return s?[(e+r)/2,(i+n)/2]:null}}class Ht{opts;label;constructor(t){this.opts=t,this.label=t.label??"Edit properties"}do(){Xt(this.opts.layer,this.opts.featureId,this.opts.prev,this.opts.next)}undo(){Xt(this.opts.layer,this.opts.featureId,this.opts.next,this.opts.prev)}}function Xt(t,e,i,r){const n=t.data?.getRecords?.(),s=n?.[e];if(s){for(const t of Object.keys(r))s[t]=r[t];for(const t of Object.keys(i))t in r||delete s[t]}}class Yt{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 Kt{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 r=t[e];r&&(r[this.opts.field]=i)}}}class Jt{opts;label;constructor(t){this.opts=t,this.label=`Rename field ${t.from} → ${t.to}`}do(){Qt(this.opts.layer,this.opts.from,this.opts.to)}undo(){Qt(this.opts.layer,this.opts.to,this.opts.from)}}function Qt(t,e,i){const r=t.data?.getRecords?.();if(r)for(const t of r)t&&e in t&&(t[i]=t[e],delete t[e])}class te{_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 ct.notFound("layer",t.layer);const r=i.data?.getRecords?.(),n=r?.[t.id];if(!n)return ct.notFound("field",`record#${t.id}`);const s={},o={};for(const t of Object.keys(e)){const i=t in n,r=i?n[t]:void 0,a=e[t];(void 0!==a||i)&&(void 0!==a&&i&&n[t]===a||(i&&(s[t]=r),void 0!==a&&(o[t]=a)))}if(0===Object.keys(s).length&&0===Object.keys(o).length)return ct.validation("props","no-op: every requested value already matches the record");const a=new Ht({layer:i,featureId:t.id,prev:s,next:o});return a.do(),this._emap._history.push(a),this._emap._fireHistoryChange(),this._emap._scheduleRender(),at}addField(t){const e=this._emap.layers.resolve(t.source,t.target);if(!e)return ct.notFound("layer",t.target);if(!e.data)return ct.validation("target","layer has no data table");const i=new Yt({layer:e,field:t.field,defaultValue:t.defaultValue});return i.do(),this._emap._history.push(i),this._emap._fireHistoryChange(),this._emap._scheduleRender(),at}removeField(t){const e=this._emap.layers.resolve(t.source,t.target);if(!e)return ct.notFound("layer",t.target);if(!e.data)return ct.validation("target","layer has no data table");const i=new Kt({layer:e,field:t.field});return i.do(),this._emap._history.push(i),this._emap._fireHistoryChange(),this._emap._scheduleRender(),at}renameField(t){const e=this._emap.layers.resolve(t.source,t.target);if(!e)return ct.notFound("layer",t.target);if(!e.data)return ct.validation("target","layer has no data table");const i=e.data.getRecords?.();if(!i)return ct.validation("target","data table has no records");if(t.from===t.to)return ct.validation("to","`from` and `to` are identical");for(const e of i)if(e&&t.from in e&&t.to in e)return ct.validation("to",`would overwrite existing '${t.to}' on at least one record`);const r=new Jt({layer:e,from:t.from,to:t.to});return r.do(),this._emap._history.push(r),this._emap._fireHistoryChange(),this._emap._scheduleRender(),at}}class ee{_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 ie={},re=Uint8Array,ne=Uint16Array,se=Int32Array,oe=new re([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]),ae=new re([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]),le=new re([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),ce=function(t,e){for(var i=new ne(31),r=0;r<31;++r)i[r]=e+=1<<t[r-1];var n=new se(i[30]);for(r=1;r<30;++r)for(var s=i[r];s<i[r+1];++s)n[s]=s-i[r]<<5|r;return{b:i,r:n}},he=ce(oe,2),ue=he.b,pe=he.r;ue[28]=258,pe[258]=28;for(var de=ce(ae,0),fe=de.b,me=de.r,_e=new ne(32768),ge=0;ge<32768;++ge){var ye=(43690&ge)>>1|(21845&ge)<<1;ye=(61680&(ye=(52428&ye)>>2|(13107&ye)<<2))>>4|(3855&ye)<<4,_e[ge]=((65280&ye)>>8|(255&ye)<<8)>>1}var ve=function(t,e,i){for(var r=t.length,n=0,s=new ne(e);n<r;++n)t[n]&&++s[t[n]-1];var o,a=new ne(e);for(n=1;n<e;++n)a[n]=a[n-1]+s[n-1]<<1;if(i){o=new ne(1<<e);var l=15-e;for(n=0;n<r;++n)if(t[n])for(var c=n<<4|t[n],h=e-t[n],u=a[t[n]-1]++<<h,p=u|(1<<h)-1;u<=p;++u)o[_e[u]>>l]=c}else for(o=new ne(r),n=0;n<r;++n)t[n]&&(o[n]=_e[a[t[n]-1]++]>>15-t[n]);return o},xe=new re(288);for(ge=0;ge<144;++ge)xe[ge]=8;for(ge=144;ge<256;++ge)xe[ge]=9;for(ge=256;ge<280;++ge)xe[ge]=7;for(ge=280;ge<288;++ge)xe[ge]=8;var be=new re(32);for(ge=0;ge<32;++ge)be[ge]=5;var we=ve(xe,9,0),Se=ve(xe,9,1),Te=ve(be,5,0),Ce=ve(be,5,1),Me=function(t){for(var e=t[0],i=1;i<t.length;++i)t[i]>e&&(e=t[i]);return e},Ae=function(t,e,i){var r=e/8|0;return(t[r]|t[r+1]<<8)>>(7&e)&i},Ee=function(t,e){var i=e/8|0;return(t[i]|t[i+1]<<8|t[i+2]<<16)>>(7&e)},Ie=function(t){return(t+7)/8|0},Pe=function(t,e,i){return(null==e||e<0)&&(e=0),(null==i||i>t.length)&&(i=t.length),new re(t.subarray(e,i))},De=["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"],ke=function(t,e,i){var r=new Error(e||De[t]);if(r.code=t,Error.captureStackTrace&&Error.captureStackTrace(r,ke),!i)throw r;return r},ze=function(t,e,i,r){var n=t.length,s=r?r.length:0;if(!n||e.f&&!e.l)return i||new re(0);var o=!i,a=o||2!=e.i,l=e.i;o&&(i=new re(3*n));var c=function(t){var e=i.length;if(t>e){var r=new re(Math.max(2*e,t));r.set(i),i=r}},h=e.f||0,u=e.p||0,p=e.b||0,d=e.l,f=e.d,m=e.m,_=e.n,g=8*n;do{if(!d){h=Ae(t,u,1);var y=Ae(t,u+1,3);if(u+=3,!y){var v=t[(P=Ie(u)+4)-4]|t[P-3]<<8,x=P+v;if(x>n){l&&ke(0);break}a&&c(p+v),i.set(t.subarray(P,x),p),e.b=p+=v,e.p=u=8*x,e.f=h;continue}if(1==y)d=Se,f=Ce,m=9,_=5;else if(2==y){var b=Ae(t,u,31)+257,w=Ae(t,u+10,15)+4,S=b+Ae(t,u+5,31)+1;u+=14;for(var T=new re(S),C=new re(19),M=0;M<w;++M)C[le[M]]=Ae(t,u+3*M,7);u+=3*w;var A=Me(C),E=(1<<A)-1,I=ve(C,A,1);for(M=0;M<S;){var P,D=I[Ae(t,u,E)];if(u+=15&D,(P=D>>4)<16)T[M++]=P;else{var k=0,z=0;for(16==P?(z=3+Ae(t,u,3),u+=2,k=T[M-1]):17==P?(z=3+Ae(t,u,7),u+=3):18==P&&(z=11+Ae(t,u,127),u+=7);z--;)T[M++]=k}}var R=T.subarray(0,b),L=T.subarray(b);m=Me(R),_=Me(L),d=ve(R,m,1),f=ve(L,_,1)}else ke(1);if(u>g){l&&ke(0);break}}a&&c(p+131072);for(var F=(1<<m)-1,B=(1<<_)-1,O=u;;O=u){var N=(k=d[Ee(t,u)&F])>>4;if((u+=15&k)>g){l&&ke(0);break}if(k||ke(2),N<256)i[p++]=N;else{if(256==N){O=u,d=null;break}var V=N-254;if(N>264){var j=oe[M=N-257];V=Ae(t,u,(1<<j)-1)+ue[M],u+=j}var G=f[Ee(t,u)&B],U=G>>4;G||ke(3),u+=15&G;L=fe[U];if(U>3){j=ae[U];L+=Ee(t,u)&(1<<j)-1,u+=j}if(u>g){l&&ke(0);break}a&&c(p+131072);var q=p+V;if(p<L){var $=s-L,Z=Math.min(L,q);for($+p<0&&ke(3);p<Z;++p)i[p]=r[$+p]}for(;p<q;++p)i[p]=i[p-L]}}e.l=d,e.p=O,e.b=p,e.f=h,d&&(h=1,e.m=m,e.d=f,e.n=_)}while(!h);return p!=i.length&&o?Pe(i,0,p):i.subarray(0,p)},Re=function(t,e,i){i<<=7&e;var r=e/8|0;t[r]|=i,t[r+1]|=i>>8},Le=function(t,e,i){i<<=7&e;var r=e/8|0;t[r]|=i,t[r+1]|=i>>8,t[r+2]|=i>>16},Fe=function(t,e){for(var i=[],r=0;r<t.length;++r)t[r]&&i.push({s:r,f:t[r]});var n=i.length,s=i.slice();if(!n)return{t:Ue,l:0};if(1==n){var o=new re(i[0].s+1);return o[i[0].s]=1,{t:o,l:1}}i.sort(function(t,e){return t.f-e.f}),i.push({s:-1,f:25001});var a=i[0],l=i[1],c=0,h=1,u=2;for(i[0]={s:-1,f:a.f+l.f,l:a,r:l};h!=n-1;)a=i[i[c].f<i[u].f?c++:u++],l=i[c!=h&&i[c].f<i[u].f?c++:u++],i[h++]={s:-1,f:a.f+l.f,l:a,r:l};var p=s[0].s;for(r=1;r<n;++r)s[r].s>p&&(p=s[r].s);var d=new ne(p+1),f=Be(i[h-1],d,0);if(f>e){r=0;var m=0,_=f-e,g=1<<_;for(s.sort(function(t,e){return d[e.s]-d[t.s]||t.f-e.f});r<n;++r){var y=s[r].s;if(!(d[y]>e))break;m+=g-(1<<f-d[y]),d[y]=e}for(m>>=_;m>0;){var v=s[r].s;d[v]<e?m-=1<<e-d[v]++-1:++r}for(;r>=0&&m;--r){var x=s[r].s;d[x]==e&&(--d[x],++m)}f=e}return{t:new re(d),l:f}},Be=function(t,e,i){return-1==t.s?Math.max(Be(t.l,e,i+1),Be(t.r,e,i+1)):e[t.s]=i},Oe=function(t){for(var e=t.length;e&&!t[--e];);for(var i=new ne(++e),r=0,n=t[0],s=1,o=function(t){i[r++]=t},a=1;a<=e;++a)if(t[a]==n&&a!=e)++s;else{if(!n&&s>2){for(;s>138;s-=138)o(32754);s>2&&(o(s>10?s-11<<5|28690:s-3<<5|12305),s=0)}else if(s>3){for(o(n),--s;s>6;s-=6)o(8304);s>2&&(o(s-3<<5|8208),s=0)}for(;s--;)o(n);s=1,n=t[a]}return{c:i.subarray(0,r),n:e}},Ne=function(t,e){for(var i=0,r=0;r<e.length;++r)i+=t[r]*e[r];return i},Ve=function(t,e,i){var r=i.length,n=Ie(e+2);t[n]=255&r,t[n+1]=r>>8,t[n+2]=255^t[n],t[n+3]=255^t[n+1];for(var s=0;s<r;++s)t[n+s+4]=i[s];return 8*(n+4+r)},je=function(t,e,i,r,n,s,o,a,l,c,h){Re(e,h++,i),++n[256];for(var u=Fe(n,15),p=u.t,d=u.l,f=Fe(s,15),m=f.t,_=f.l,g=Oe(p),y=g.c,v=g.n,x=Oe(m),b=x.c,w=x.n,S=new ne(19),T=0;T<y.length;++T)++S[31&y[T]];for(T=0;T<b.length;++T)++S[31&b[T]];for(var C=Fe(S,7),M=C.t,A=C.l,E=19;E>4&&!M[le[E-1]];--E);var I,P,D,k,z=c+5<<3,R=Ne(n,xe)+Ne(s,be)+o,L=Ne(n,p)+Ne(s,m)+o+14+3*E+Ne(S,M)+2*S[16]+3*S[17]+7*S[18];if(l>=0&&z<=R&&z<=L)return Ve(e,h,t.subarray(l,l+c));if(Re(e,h,1+(L<R)),h+=2,L<R){I=ve(p,d,0),P=p,D=ve(m,_,0),k=m;var F=ve(M,A,0);Re(e,h,v-257),Re(e,h+5,w-1),Re(e,h+10,E-4),h+=14;for(T=0;T<E;++T)Re(e,h+3*T,M[le[T]]);h+=3*E;for(var B=[y,b],O=0;O<2;++O){var N=B[O];for(T=0;T<N.length;++T){var V=31&N[T];Re(e,h,F[V]),h+=M[V],V>15&&(Re(e,h,N[T]>>5&127),h+=N[T]>>12)}}}else I=we,P=xe,D=Te,k=be;for(T=0;T<a;++T){var j=r[T];if(j>255){Le(e,h,I[(V=j>>18&31)+257]),h+=P[V+257],V>7&&(Re(e,h,j>>23&31),h+=oe[V]);var G=31&j;Le(e,h,D[G]),h+=k[G],G>3&&(Le(e,h,j>>5&8191),h+=ae[G])}else Le(e,h,I[j]),h+=P[j]}return Le(e,h,I[256]),h+P[256]},Ge=new se([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),Ue=new re(0),qe=function(){for(var t=new Int32Array(256),e=0;e<256;++e){for(var i=e,r=9;--r;)i=(1&i&&-306674912)^i>>>1;t[e]=i}return t}(),$e=function(){var t=-1;return{p:function(e){for(var i=t,r=0;r<e.length;++r)i=qe[255&i^e[r]]^i>>>8;t=i},d:function(){return~t}}},Ze=function(t,e,i,r,n){if(!n&&(n={l:1},e.dictionary)){var s=e.dictionary.subarray(-32768),o=new re(s.length+t.length);o.set(s),o.set(t,s.length),t=o,n.w=s.length}return function(t,e,i,r,n,s){var o=s.z||t.length,a=new re(r+o+5*(1+Math.ceil(o/7e3))+n),l=a.subarray(r,a.length-n),c=s.l,h=7&(s.r||0);if(e){h&&(l[0]=s.r>>3);for(var u=Ge[e-1],p=u>>13,d=8191&u,f=(1<<i)-1,m=s.p||new ne(32768),_=s.h||new ne(f+1),g=Math.ceil(i/3),y=2*g,v=function(e){return(t[e]^t[e+1]<<g^t[e+2]<<y)&f},x=new se(25e3),b=new ne(288),w=new ne(32),S=0,T=0,C=s.i||0,M=0,A=s.w||0,E=0;C+2<o;++C){var I=v(C),P=32767&C,D=_[I];if(m[P]=D,_[I]=P,A<=C){var k=o-C;if((S>7e3||M>24576)&&(k>423||!c)){h=je(t,l,0,x,b,w,T,M,E,C-E,h),M=S=T=0,E=C;for(var z=0;z<286;++z)b[z]=0;for(z=0;z<30;++z)w[z]=0}var R=2,L=0,F=d,B=P-D&32767;if(k>2&&I==v(C-B))for(var O=Math.min(p,k)-1,N=Math.min(32767,C),V=Math.min(258,k);B<=N&&--F&&P!=D;){if(t[C+R]==t[C+R-B]){for(var j=0;j<V&&t[C+j]==t[C+j-B];++j);if(j>R){if(R=j,L=B,j>O)break;var G=Math.min(B,j-2),U=0;for(z=0;z<G;++z){var q=C-B+z&32767,$=q-m[q]&32767;$>U&&(U=$,D=q)}}}B+=(P=D)-(D=m[P])&32767}if(L){x[M++]=268435456|pe[R]<<18|me[L];var Z=31&pe[R],W=31&me[L];T+=oe[Z]+ae[W],++b[257+Z],++w[W],A=C+R,++S}else x[M++]=t[C],++b[t[C]]}}for(C=Math.max(C,A);C<o;++C)x[M++]=t[C],++b[t[C]];h=je(t,l,c,x,b,w,T,M,E,C-E,h),c||(s.r=7&h|l[h/8|0]<<3,h-=7,s.h=_,s.p=m,s.i=C,s.w=A)}else{for(C=s.w||0;C<o+c;C+=65535){var H=C+65535;H>=o&&(l[h/8|0]=c,H=o),h=Ve(l,h+1,t.subarray(C,H))}s.i=o}return Pe(a,0,r+Ie(h)+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,r,n)},We=function(t,e){var i={};for(var r in t)i[r]=t[r];for(var r in e)i[r]=e[r];return i},He=function(t,e,i){for(var r=t(),n=t.toString(),s=n.slice(n.indexOf("[")+1,n.lastIndexOf("]")).replace(/\s+/g,"").split(","),o=0;o<r.length;++o){var a=r[o],l=s[o];if("function"==typeof a){e+=";"+l+"=";var c=a.toString();if(a.prototype)if(-1!=c.indexOf("[native code]")){var h=c.indexOf(" ",8)+1;e+=c.slice(h,c.indexOf("(",h))}else for(var u in e+=c,a.prototype)e+=";"+l+".prototype."+u+"="+a.prototype[u].toString();else e+=c}else i[l]=a}return e},Xe=[],Ye=function(t,e,i,r){if(!Xe[i]){for(var n="",s={},o=t.length-1,a=0;a<o;++a)n=He(t[a],n,s);Xe[i]={c:He(t[o],n,s),e:s}}var l=We({},Xe[i].e);return function(t,e,i,r,n){var s=new Worker(ie[e]||(ie[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,i=e.$e$;if(i){var r=new Error(i[0]);r.code=i[1],r.stack=i[2],n(r,null)}else n(null,e)},s.postMessage(i,r),s}(Xe[i].c+";onmessage=function(e){for(var k in e.data)self[k]=e.data[k];onmessage="+e.toString()+"}",i,l,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}(l),r)},Ke=function(){return[re,ne,se,oe,ae,le,ue,fe,Se,Ce,_e,De,ve,Me,Ae,Ee,Ie,Pe,ke,ze,oi,Je,Qe]},Je=function(t){return postMessage(t,[t.buffer])},Qe=function(t){return t&&{out:t.size&&new re(t.size),dictionary:t.dictionary}},ti=function(t,e){return t[e]|t[e+1]<<8},ei=function(t,e){return(t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24)>>>0},ii=function(t,e){return ei(t,e)+4294967296*ei(t,e+4)},ri=function(t,e,i){for(;i;++e)t[e]=i,i>>>=8};function ni(t,e){return Ze(t,e||{},0,0)}function si(t,e,i){return i||(i=e,e={}),"function"!=typeof i&&ke(7),function(t,e,i,r,n,s){var o=Ye(i,r,n,function(t,e){o.terminate(),s(t,e)});return o.postMessage([t,e],e.consume?[t.buffer]:[]),function(){o.terminate()}}(t,e,[Ke],function(t){return Je(oi(t.data[0],Qe(t.data[1])))},1,i)}function oi(t,e){return ze(t,{i:2},e&&e.out,e&&e.dictionary)}var ai=function(t,e,i,r){for(var n in t){var s=t[n],o=e+n,a=r;Array.isArray(s)&&(a=We(r,s[1]),s=s[0]),s instanceof re?i[o]=[s,a]:(i[o+="/"]=[new re(0),a],ai(s,o,i,r))}},li="undefined"!=typeof TextEncoder&&new TextEncoder,ci="undefined"!=typeof TextDecoder&&new TextDecoder;try{ci.decode(Ue,{stream:!0})}catch(t){}function hi(t,e){if(li)return li.encode(t);for(var i=t.length,r=new re(t.length+(t.length>>1)),n=0,s=function(t){r[n++]=t},o=0;o<i;++o){if(n+5>r.length){var a=new re(n+8+(i-o<<1));a.set(r),r=a}var l=t.charCodeAt(o);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(++o))>>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 Pe(r,0,n)}function ui(t,e){if(e){for(var i="",r=0;r<t.length;r+=16384)i+=String.fromCharCode.apply(null,t.subarray(r,r+16384));return i}if(ci)return ci.decode(t);var n=function(t){for(var e="",i=0;;){var r=t[i++],n=(r>127)+(r>223)+(r>239);if(i+n>t.length)return{s:e,r:Pe(t,i-1)};n?3==n?(r=((15&r)<<18|(63&t[i++])<<12|(63&t[i++])<<6|63&t[i++])-65536,e+=String.fromCharCode(55296|r>>10,56320|1023&r)):e+=1&n?String.fromCharCode((31&r)<<6|63&t[i++]):String.fromCharCode((15&r)<<12|(63&t[i++])<<6|63&t[i++]):e+=String.fromCharCode(r)}}(t),s=n.s;return(i=n.r).length&&ke(8),s}var pi=function(t,e){for(;1!=ti(t,e);e+=4+ti(t,e+2));return[ii(t,e+12),ii(t,e+4),ii(t,e+20)]},di=function(t){var e=0;if(t)for(var i in t){var r=t[i].length;r>65535&&ke(9),e+=r+4}return e},fi=function(t,e,i,r,n,s,o,a){var l=r.length,c=i.extra,h=a&&a.length,u=di(c);ri(t,e,null!=o?33639248:67324752),e+=4,null!=o&&(t[e++]=20,t[e++]=i.os),t[e]=20,e+=2,t[e++]=i.flag<<1|(s<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),d=p.getFullYear()-1980;if((d<0||d>119)&&ke(10),ri(t,e,d<<25|p.getMonth()+1<<21|p.getDate()<<16|p.getHours()<<11|p.getMinutes()<<5|p.getSeconds()>>1),e+=4,-1!=s&&(ri(t,e,i.crc),ri(t,e+4,s<0?-s-2:s),ri(t,e+8,i.size)),ri(t,e+12,l),ri(t,e+14,u),e+=16,null!=o&&(ri(t,e,h),ri(t,e+6,i.attrs),ri(t,e+10,o),e+=14),t.set(r,e),e+=l,u)for(var f in c){var m=c[f],_=m.length;ri(t,e,+f),ri(t,e+2,_),t.set(m,e+4),e+=4+_}return h&&(t.set(a,e),e+=h),e};function mi(t,e){e||(e={});var i={},r=[];ai(t,"",i,e);var n=0,s=0;for(var o in i){var a=i[o],l=a[0],c=a[1],h=0==c.level?0:8,u=(S=hi(o)).length,p=c.comment,d=p&&hi(p),f=d&&d.length,m=di(c.extra);u>65535&&ke(11);var _=h?ni(l,c):l,g=_.length,y=$e();y.p(l),r.push(We(c,{size:l.length,crc:y.d(),c:_,f:S,m:d,u:u!=o.length||d&&p.length!=f,o:n,compression:h})),n+=30+u+m+g,s+=76+2*(u+m)+(f||0)+g}for(var v=new re(s+22),x=n,b=s-n,w=0;w<r.length;++w){var S=r[w];fi(v,S.o,S,S.f,S.u,S.c.length);var T=30+S.f.length+di(S.extra);v.set(S.c,S.o+T),fi(v,n,S,S.f,S.u,S.c.length,S.o,S.m),n+=16+T+(S.m?S.m.length:0)}return function(t,e,i,r,n){ri(t,e,101010256),ri(t,e+8,i),ri(t,e+10,i),ri(t,e+12,r),ri(t,e+16,n)}(v,n,r.length,b,x),v}var _i="function"==typeof queueMicrotask?queueMicrotask:"function"==typeof setTimeout?setTimeout:function(t){t()};function gi(t,e,i){i||(i=e,e={}),"function"!=typeof i&&ke(7);var r=[],n=function(){for(var t=0;t<r.length;++t)r[t]()},s={},o=function(t,e){_i(function(){i(t,e)})};_i(function(){o=i});for(var a=t.length-22;101010256!=ei(t,a);--a)if(!a||t.length-a>65558)return o(ke(13,0,1),null),n;var l=ti(t,a+8);if(l){var c=l,h=ei(t,a+16),u=4294967295==h||65535==c;if(u){var p=ei(t,a-12);(u=101075792==ei(t,p))&&(c=l=ei(t,p+32),h=ei(t,p+48))}for(var d=e&&e.filter,f=function(e){var i=function(t,e,i){var r=ti(t,e+28),n=ui(t.subarray(e+46,e+46+r),!(2048&ti(t,e+8))),s=e+46+r,o=ei(t,e+20),a=i&&4294967295==o?pi(t,s):[o,ei(t,e+24),ei(t,e+42)],l=a[0],c=a[1],h=a[2];return[ti(t,e+10),l,c,n,s+ti(t,e+30)+ti(t,e+32),h]}(t,h,u),a=i[0],c=i[1],p=i[2],f=i[3],m=i[4],_=i[5],g=function(t,e){return e+30+ti(t,e+26)+ti(t,e+28)}(t,_);h=m;var y=function(t,e){t?(n(),o(t,null)):(e&&(s[f]=e),--l||o(null,s))};if(!d||d({name:f,size:c,originalSize:p,compression:a}))if(a)if(8==a){var v=t.subarray(g,g+c);if(p<524288||c>.8*p)try{y(null,oi(v,{out:new re(p)}))}catch(t){y(t,null)}else r.push(si(v,{size:p},y))}else y(ke(14,"unknown compression type "+a,1),null);else y(null,Pe(t,g,g+c));else y(null,null)},m=0;m<c;++m)f()}else o(null,{});return n}const yi=5e5;class vi{_unfilteredArcs;_filteredArcs=null;_filteredSegLen=0;_dirty=!1;constructor(t){this._unfilteredArcs=t;(t.getPointCount?.()??0)>yi&&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)/yi),r=t.getRetainedInterval?.()??0,n=t.getThresholdByPct?.(e,i)??0;this._filteredArcs=t.setRetainedInterval?.(n)?.getFilteredCopy?.()??null,t.setRetainedInterval?.(r),this._filteredArcs&&(this._filteredSegLen=Q().getAvgSegment(this._filteredArcs))}else{const e=Q();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)>yi&&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 xi{_adapter;constructor(t=Q()){this._adapter=t}async runImport(t,e){return this._adapter.runImport(t,e)}}let bi=null;const wi="EPSG:4326";function Si(t){if(!t)return wi;const e=t.info;if(!e)return wi;if(e.crs_string)return Ti(e.crs_string);if(e.prj){const t=Ci(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 wi}function Ti(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 Ci(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 Mi={geojson:"application/geo+json",topojson:"application/json",shapefile:"application/zip",msx:"application/octet-stream"};function Ai(t){return"string"==typeof t?(new TextEncoder).encode(t):t instanceof Uint8Array?t:new Uint8Array(t)}const Ei={maxBytes:209715200,maxEntries:5e3,maxRatio:100};class Ii extends q{id;type="topology";_dataset;_displayArcs=null;_options;_data;_loadVersion=0;_abortController=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??bi??(bi=new xi),this._data&&this._updateData()}static async fromUrl(t,e,i){const r=new Ii(t,i);return await new Promise((t,i)=>{let n,s;const o=()=>{r.off("data",n),r.off("error",s)};n=()=>{o(),t()},s=t=>{o(),i(t?.error??t)},r.on("data",n),r.on("error",s),r.setData(e)}),r}static async fromBytes(t,e,i){const{filename:r=`${t}.geojson`,...n}=i??{},s=e instanceof Uint8Array?e:new Uint8Array(e),o=new Ii(t,n);return await new Promise((t,e)=>{let i,n;const a=()=>{o.off("data",i),o.off("error",n)};i=()=>{a(),t()},n=t=>{a(),e(t?.error??t)},o.on("data",i),o.on("error",n),o.setData({filename:r,content:s})}),o}setData(t){return this._loadVersion++,this._abortController?.abort(),this._abortController=null,this._data=t,this._updateData(),this}async _updateData(){if(!this._data)return;const t=this._loadVersion,e=new AbortController;this._abortController=e,this.fire("dataloading");try{const i={},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),n=this._findPrimaryFile(e);if(!n)throw new Error(`No importable file found in zip archive: ${t.filename}`);for(const[t,r]of Object.entries(e))i[t]=r;r.push(n)}else i[t.filename]=t.content,r.push(t.filename)}else{let t;if("string"==typeof this._data){const i=this._data,r=await fetch(i,{signal:e.signal});if(!r.ok)throw new Error(`Failed to fetch ${i}: HTTP ${r.status}`);const n=await r.arrayBuffer(),s=new Uint8Array(n);let o=new URL(i).pathname.split("/").pop()||"";if(!this._hasSupportedExtension(o)){const t=r.headers.get("Content-Type")||"";o=this._filenameFromContentType(t,o)}o||(o="data.json"),t={filename:o,content:s}}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,r]of Object.entries(e))i[t]=r;r.push(n)}else i[t.filename]=t.content,r.push(t.filename)}const n=`-i ${r.map(t=>`"${t.replace(/"/g,'\\"')}"`).join(" ")}`,s=await this._runner.runImport(n,i);if(t!==this._loadVersion)return;this._dataset=s,this._dataset?.arcs&&(this._displayArcs=new vi(this._dataset.arcs)),this._simplifyFloor=this._dataset?.arcs?.getRetainedInterval?.()??0,this.fire("data",{reason:"load"})}catch(e){if(t!==this._loadVersion)return;if("AbortError"===e?.name)return;this.fire("error",{error: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 Si(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 Q().runOnDataset(e,this._dataset);this._dataset=i,this._dataset?.arcs&&(this._displayArcs=new vi(this._dataset.arcs))}getExtent(){if(!this._dataset)return new Z;const t=Q().getDatasetBounds(this._dataset);return new Z(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 vi(this._dataset.arcs))}setDataset(t){this._dataset=t,t.arcs?this._displayArcs=new vi(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=Q(),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]=Ai(i.content);const i=mi(e);return new Blob([i],{type:Mi.shapefile})}return new Blob([t[0].content],{type:Mi[e]})}getLayers(){return this._dataset?.layers||[]}_isZipFile(t){return/\.zip$/i.test(t)}async _extractZip(t){const e={...Ei,...this._options.zipLimits};let i=0,r=0;const n=await new Promise((n,s)=>{gi(t,{filter:n=>{if(r++,r>e.maxEntries)throw new Error(`ZIP extraction limit exceeded: ${r} 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 r=i/t.byteLength;if(r>e.maxRatio)throw new Error(`ZIP extraction limit exceeded: ratio ${r.toFixed(1)} > maxRatio ${e.maxRatio}`)}return!(/^__MACOSX/.test(n.name)||n.name.split("/").pop()?.startsWith("."))}},(t,e)=>{t?s(t):n(e)})}),s={};for(const t of Object.keys(n)){const e=n[t],i=t.split("/").pop()||t;this._isTextFile(i)?s[i]=ui(e):s[i]=e}return s}_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 Pi(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 Di extends q{_element;_active=!1;_timer=new W;_sustainInterval=150;_fadeDelay=70;_eventTime=0;_getAverageRate=Pi(10);_getWheelDirection=function(){let t=0,e=null;return function(i,r){const n=i>0?1:i<0?-1:0;(!e||r-t>300)&&(e=Pi(3)),t=r;const s=e(n)||n;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 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,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&&(i*=H.quadraticOut(1-r)),this.fire("mousewheel",{direction:this._wheelDirection,multiplier:i,x:this._mouseX,y:this._mouseY}))}}class ki extends q{_element;_isDragging=!1;_lastMousePos=[0,0];_enabled=!0;_onMouseDownBound;_onMouseMoveBound;_onMouseUpBound;constructor(t){super(),this._element=t,this._onMouseDownBound=this._onMouseDown.bind(this),this._onMouseMoveBound=this._onMouseMove.bind(this),this._onMouseUpBound=this._onMouseUp.bind(this),t.addEventListener("mousedown",this._onMouseDownBound),window.addEventListener("mousemove",this._onMouseMoveBound),window.addEventListener("mouseup",this._onMouseUpBound)}setEnabled(t){this._enabled=t,!t&&this._isDragging&&(this._isDragging=!1,this.fire("panend"))}isEnabled(){return this._enabled}isDragging(){return this._isDragging}destroy(){this._element.removeEventListener("mousedown",this._onMouseDownBound),window.removeEventListener("mousemove",this._onMouseMoveBound),window.removeEventListener("mouseup",this._onMouseUpBound)}_onMouseDown(t){this._enabled&&(t.shiftKey||(this._isDragging=!0,this._lastMousePos=[t.clientX,t.clientY],this.fire("panstart")))}_onMouseMove(t){if(!this._isDragging)return;const e=t.clientX-this._lastMousePos[0],i=t.clientY-this._lastMousePos[1];this._lastMousePos=[t.clientX,t.clientY],this.fire("pan",{dx:e,dy:i})}_onMouseUp(){this._isDragging&&(this._isDragging=!1,this.fire("panend"))}}class zi{_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 r=this.reserveId();return{id:r,promise:this.dispatchWithId(r,t,e,i)}}reserveId(){return this._nextId++}dispatchWithId(t,e,i,r,n){if(this._destroyed)return Promise.reject(new Error("MapshaperWorkerPool: destroyed"));const s=this._pickWorker();let o;try{o=this._ensureWorker(s)}catch(t){return Promise.reject(t)}const a=this._slots[s],l=a.epoch;return a.pendingCount++,new Promise((a,c)=>{this._pending.set(t,{resolve:a,reject:c,workerIndex:s,epoch:l});const h={id:t,type:"run",packed:i};"string"==typeof e?h.cmd=e:h.commands=e,r&&(h.inputFiles=r),n&&n.length>0?o.postMessage(h,n):o.postMessage(h)})}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 r=this._slots.length;for(let n=0;n<r;n++){const s=(this._rrCursor+n)%r,o=this._slots[s],a=null!==o.worker;(o.pendingCount<e||o.pendingCount===e&&a&&!i)&&(t=s,e=o.pendingCount,i=a)}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 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 r=this._slots[t];i.workerIndex===t&&i.epoch===r.epoch&&(this._pending.delete(e.id),r.pendingCount=Math.max(0,r.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"}`),r=this._slots[t];r.worker&&(r.worker.terminate(),r.worker=null),r.epoch++,r.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)}}}class Ri{_sources;_getTransform;_getSize;_getInitialMX;_indexCache=new globalThis.Map;constructor(t,e,i,r){this._sources=t,this._getTransform=e,this._getSize=i,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}|`,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(),r=e.getArcs(),n=e.getDataset?.();for(let e=0;e<i.length;e++)this._getOrBuildIndex(t,e,i[e],r,n)}_getOrBuildIndex(t,e,i,r,n){const s=i?.shapes;if(!s||0===s.length)return null;const o=r?.size?.()??0,a=n?.editVersion??0,l=`${t}|${e}|${s.length}|${o}|${a}`,c=this._indexCache.get(l);if(void 0!==c)return c;const h=`${t}|${e}|`,u=[];for(const t of this._indexCache.keys())t!==l&&t.startsWith(h)&&u.push(t);for(const t of u)this._indexCache.delete(t);const p="point"===i.geometry_type,d=new A(s.length),f=[];for(let t=0;t<s.length;t++){const e=s[t];if(!e){d.add(0,0,0,0);continue}let i=1/0,n=1/0,o=-1/0,a=-1/0;if(p)for(const t of rt(e))!t||t.length<2||(t[0]<i&&(i=t[0]),t[0]>o&&(o=t[0]),t[1]<n&&(n=t[1]),t[1]>a&&(a=t[1]));else if(r?.getSimpleShapeBbox){const t=e;for(let e=0;e<t.length;e++)r.getSimpleShapeBbox(t[e],f),f[0]<i&&(i=f[0]),f[1]<n&&(n=f[1]),f[2]>o&&(o=f[2]),f[3]>a&&(a=f[3])}i!==1/0?d.add(i,n,o,a):d.add(0,0,0,0)}d.finish();const m={index:d,shapeCount:s.length};return this._indexCache.set(l,m),m}query(t,e,i){const{width:r,height:n}=this._getSize(),s=Array.isArray(t),o=s?t:[[0,0],[r,n]],a=e||(s?{}:t)||{};if(Array.isArray(o)&&"number"==typeof o[0]){const t=o;return this._queryFeaturesAtPoint(t,a,i)}const l=o;return this._queryFeaturesInBBox(l,a,i)}_layerMatchesFilter(t,e,i){if(!i||0===i.length)return!0;const r=it(t,e);return!!i.includes(r)||(!(!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(),r=this._getInitialMX(),n=Math.abs(i.mx)/(r||Math.abs(i.mx)||1);return n<1&&(t*=n),e>0&&t<e&&(t=e),this._getHitBuffer(t)}_findHitCandidates(t,e,i,r,n,s,o,a){const l=[],c={},h=[],u=i.shapes;if(!u)return l;const p=this._getOrBuildIndex(t,e,i,r,a),d=p?p.index.search(n-o,s-o,n+o,s+o):null,f=null!==d?d.length:u.length;for(let t=0;t<f;t++){const e=null!==d?d[t]:t,i=u[e];if(i)for(let t=0;t<i.length;t++){const a=i[t];if(r.getSimpleShapeBbox(a,h),n+o<h[0]||n-o>h[2]||s+o<h[1]||s-o>h[3])continue;let u=c[e];u||(u=c[e]={shape:[],id:e,dist:0},l.push(u)),u.shape.push(a)}}return l}_sortByDistance(t,i,r,n){const s=e.geom;for(const e of r)e.info=s.getPointToShapeInfo(t,i,e.shape,n),e.dist=e.info.distance;r.sort((t,e)=>t.dist-e.dist)}_pickNearestCandidates(t,e,i){const r=[];let n=0;for(let s=0;s<t.length;s++){const o=t[s];if(!(o.dist<i))break;if(0===s)n=o.dist;else if(o.dist-n>e)break;r.push(o)}return r}_pointTest(t,i,r,n,s,o){const a=e.geom,l=Math.abs(this._getTransform().mx||1);let c=-1,h=1/0,u=25;const p=r.shapes;if(!p)return[];const d=u/(l||1),f=this._getOrBuildIndex(t,i,r,void 0,o),m=f?f.index.search(n-d,s-d,n+d,s+d):null,_=null!==m?m.length:p.length;for(let t=0;t<_;t++){const e=null!==m?m[t]:t,i=p[e];if(i)for(const t of rt(i)){if(!t)continue;const i=a.distance2D(n,s,t[0],t[1])*l;i>u||(i<u&&u>2&&(u=Math.max(2,i)),i<h&&(h=i,c=e))}}return-1===c?[]:[c]}_polylineTest(t,e,i,r,n,s,o,a){const l=this._getZoomAdjustedHitBuffer(15,2),c=o>=0?o:.05,h=this._getZoomAdjustedHitBuffer(c,0);let u=this._findHitCandidates(t,e,i,r,n,s,l,a);return this._sortByDistance(n,s,u,r),u=this._pickNearestCandidates(u,h,l),u.length?[u[0].id]:[]}_polygonTest(t,i,r,n,s,o,a){const l=e.geom,c=this._getZoomAdjustedHitBuffer(10,1),h=this._findHitCandidates(t,i,r,n,s,o,c,a);let u=[];for(const t of h)l.testPointInPolygon(s,o,t.shape,n)&&u.push(t);return h.length>0&&0===u.length?(this._sortByDistance(s,o,h,n),u=this._pickNearestCandidates(h,0,c)):u.length>1&&this._sortByDistance(s,o,u,n),u.length?[u[0].id]:[]}_polygonVertexTest(t,e,i,r,n,s,o){const a=this._polygonTest(t,e,i,r,n,s,o),l=this._polylineTest(t,e,i,r,n,s,5,o);return a.length?a:l}_queryFeaturesAtPoint(t,e,i){const r=this._getTransform(),n=[],[s,o]=this._unproject(t[0],t[1]),a=1/Math.abs(r.mx||1);for(const[t,r]of this._sources){const l=r.getLayers(),c=r.getDisplayArcs(),h=c?c.getScaledArcs(a):r.getArcs(),u=r.getDataset?.();for(let r=0;r<l.length;r++){const a=l[r];if(!a?.shapes)continue;if(!this._layerMatchesFilter(a,r,e.layers))continue;const c=it(a,r);if(i&&!i.has(`${t}:${c}`))continue;const p=a.geometry_type;let d=[];if("point"===p?d=this._pointTest(t,r,a,s,o,u):"polyline"===p&&h?d=this._polylineTest(t,r,a,h,s,o,-1,u):"polygon"===p&&h&&(d=this._polygonVertexTest(t,r,a,h,s,o,u)),0!==d.length)for(const e of d){const i=a.data,r=i?.getRecordAt?.(e)??i?.getRecords?.()?.[e]??{};n.push({id:e,source:t,layer:c,geometryType:p||"unknown",properties:{...r}})}}}return n}_queryFeaturesInBBox(t,e,i){const r=this._getTransform(),n=[],[s,o]=t,a=this._unproject(s[0],s[1]),l=this._unproject(o[0],o[1]),c=Math.min(a[0],l[0]),h=Math.min(a[1],l[1]),u=Math.max(a[0],l[0]),p=Math.max(a[1],l[1]),d=1/Math.abs(r.mx||1);for(const[t,r]of this._sources){const s=r.getLayers(),o=r.getDisplayArcs(),a=o?o.getScaledArcs(d):r.getArcs(),l=r.getDataset?.();for(let r=0;r<s.length;r++){const o=s[r];if(!o?.shapes)continue;if(!this._layerMatchesFilter(o,r,e.layers))continue;const d=it(o,r);if(i&&!i.has(`${t}:${d}`))continue;const f=o.geometry_type,m=o.data,_=[],g=this._getOrBuildIndex(t,r,o,a,l),y=g?g.index.search(c,h,u,p):null,v=null!==y?y.length:o.shapes.length;for(let e=0;e<v;e++){const i=null!==y?y[e]:e,r=o.shapes[i];if(!r)continue;let s=!1;if("point"===f)s=rt(r).some(t=>t[0]>=c&&t[0]<=u&&t[1]>=h&&t[1]<=p);else if(a){const t=r;for(let e=0;e<t.length;e++)if(a.getSimpleShapeBbox(t[e],_),!(u<_[0]||c>_[2]||p<_[1]||h>_[3])){s=!0;break}}if(!s)continue;const l=m?.getRecordAt?.(i)??m?.getRecords?.()?.[i]??{};n.push({id:i,source:t,layer:d,geometryType:f||"unknown",properties:{...l}})}}}return n}}class Li{_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 r=i[t.id],n=e.data?.getRecords?.()??[];return{ref:t,geometry:r,properties:Object.freeze({...n[t.id]??{}})}}*iter(t,e){const i=this._host.layers.resolve(t,e);if(!i||!i.shapes)return;const r=i.shapes,n=i.data?.getRecords?.()??[];for(let i=0;i<r.length;i++)yield{ref:{source:t,layer:e,id:i},geometry:r[i],properties:Object.freeze({...n[i]??{}})}}count(t,e){const i=this._host.layers.resolve(t,e);return i?.shapes?.length??0}}class Fi{_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 r=[];for(const e of this._all)e.phase===t&&r.push(e);if(0===r.length)return[];const n=await Promise.allSettled(r.map(t=>t.run(e,i))),s=[];for(let t=0;t<r.length;t++){const e=r[t],i=n[t];let o;o="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)}`}]},s.push({validator:e.name,report:o})}return s}}class Bi{_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,r,n){if(0===this._highlighted.size)return;const s=this._highlightStyle.color||"#ff7a00",o=(this._highlightStyle.width??2.2)*r,a=this._highlightStyle.radius??6,l=!1!==this._highlightStyle.fill,c=1/Math.abs(i.mx||1);for(const[i,r]of e){const e=this._highlighted.get(i);if(!e)continue;const h=r.getLayers(),u=r.getDisplayArcs(),p=u?u.getScaledArcs(c):r.getArcs();for(let r=0;r<h.length;r++){const c=h[r];if(!c?.shapes)continue;const u=it(c,r);if(n&&!n.has(`${i}:${u}`))continue;const d=e.get(u);if(!d||0===d.size)continue;const f=[];for(const t of d){const e=c.shapes[t];e&&f.push(e)}0!==f.length&&("point"===c.geometry_type?t.drawPoints(f,{color:s,radius:a,fill:l}):p&&t.drawPaths(f,{color:s,width:o},p))}}}}class Oi{_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[r,n]of i)for(const i of n)t.push({source:e,layer:r,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=Gi(t);if("replace"===e){const t=this._refSetSnapshot();this._byKey.clear(),this._size=0;for(const t of i)this._addOne(t);return ji(t,this._refSetSnapshot())}const r=[],n=[];if("add"===e)for(const t of i)this._addOne(t)&&r.push(t);else for(const t of i)this.has(t)?this._removeOne(t)&&n.push(t):this._addOne(t)&&r.push(t);return{added:r,removed:n,changed:r.length>0||n.length>0}}remove(t){const e=[];for(const i of Gi(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(Vi(e));return ji(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[r,n]of i)for(const i of n)t.add(Ni(e,r,i));return t}}function Ni(t,e,i){return JSON.stringify([t,e,i])}function Vi(t){const[e,i,r]=JSON.parse(t);return{source:e,layer:i,id:r}}function ji(t,e){const i=[],r=[];for(const r of e)t.has(r)||i.push(Vi(r));for(const i of t)e.has(i)||r.push(Vi(i));return{added:i,removed:r,changed:i.length>0||r.length>0}}function Gi(t){const e=new Set,i=[];for(const r of t){const t=Ni(r.source,r.layer,r.id);e.has(t)||(e.add(t),i.push(r))}return i}class Ui{_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 qi{_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 at;const i=new zt(e,t);return this._host._history.push(i),this._host._fireHistoryChange(),at}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 $i{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 r=t.shapes,n=new Array(r.length-i.size);let s=0;for(let t=0;t<r.length;t++)i.has(t)||(n[s++]=r[t]);t.shapes=n;const o=t.data?.getRecords?.();if(o){let t=0;for(let e=0;e<o.length;e++)i.has(e)||(o[t++]=o[e]);o.length=t}}undo(){const{layer:t,snapshots:e}=this.opts;t.shapes||(t.shapes=[]);const i=[...e].sort((t,e)=>t.id-e.id),r=t.data?.getRecords?.();for(const e of i)t.shapes.splice(e.id,0,e.shape),r&&null!==e.record&&r.splice(e.id,0,e.record)}}function Zi(t,e){const i=t||{};return{color:i["line-color"]||i["fill-color"]||"#333",width:(i["line-width"]??.8)*e}}function Wi(t){const e=t||{};return{color:e["circle-color"]||"#333",radius:e["circle-radius"]??4,fill:!1!==e["circle-fill"]}}const Hi=/^[A-Za-z0-9_\-:.一-鿿][A-Za-z0-9_\-:. 一-鿿]*$/,Xi=/^[A-Za-z0-9_\-.一-鿿][A-Za-z0-9_\-. 一-鿿]*$/;function Yi(t){return"string"==typeof t&&t.length>0&&Xi.test(t)}class Ki{opts;label="Move vertex";_mergeAt=Date.now();constructor(t){this.opts=t}do(){(this.opts.adapter??Q()).snapVertices(this.opts.vertexIds,this.opts.to,this.opts.arcs),this.opts.source.markDisplayArcsDirty?.(),Lt(this.opts.source.getDataset?.())}undo(){(this.opts.adapter??Q()).snapVertices(this.opts.vertexIds,this.opts.from,this.opts.arcs),this.opts.source.markDisplayArcsDirty?.(),Lt(this.opts.source.getDataset?.())}mergeable(t){if(!(t instanceof Ki))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 Ki&&(this.opts.to=t.opts.to,this._mergeAt=Date.now())}}class Ji{opts;label="Insert vertex";constructor(t){this.opts=t}do(){(this.opts.adapter??Q()).insertVertex(this.opts.arcs,this.opts.insertionId,this.opts.point),this.opts.source.markDisplayArcsDirty?.(),Lt(this.opts.source.getDataset?.())}undo(){(this.opts.adapter??Q()).deleteVertex(this.opts.arcs,this.opts.insertionId),this.opts.source.markDisplayArcsDirty?.(),Lt(this.opts.source.getDataset?.())}}class Qi{opts;label="Delete vertex";constructor(t){this.opts=t}do(){(this.opts.adapter??Q()).deleteVertex(this.opts.arcs,this.opts.vertexIndex),this.opts.source.markDisplayArcsDirty?.(),Lt(this.opts.source.getDataset?.())}undo(){(this.opts.adapter??Q()).insertVertex(this.opts.arcs,this.opts.vertexIndex,this.opts.coords),this.opts.source.markDisplayArcsDirty?.(),Lt(this.opts.source.getDataset?.())}}class tr{opts;label;constructor(t){this.opts=t,this.label=`Draw ${t.geometryType}`}do(){const t=this.opts,e=t.adapter??Q();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?.(),Lt(t.source.getDataset?.())}undo(){const t=this.opts,e=t.adapter??Q();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?.(),Lt(t.source.getDataset?.())}}const er=[{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 ir{_map=null;_container=null;_btn=null;_active=!1;_polygonFillColor;_hoveredFeature=null;_hoverVertexCoords=null;_hoverVertexIds=[];_hoverType=null;_hoverInsertionId=-1;_dragging=!1;_neighborShapes=[];_dragFromCoords=null;_onMouseMoveBound;_onMouseDownBound;_onMouseUpBound;_onMoveHandlerBound;_onContextMenuBound;constructor(t={}){this._polygonFillColor=void 0!==t.polygonFillColor?t.polygonFillColor:"rgba(0,0,0,0.15)",this._onMouseMoveBound=this._onMouseMove.bind(this),this._onMouseDownBound=this._onMouseDown.bind(this),this._onMouseUpBound=this._onMouseUp.bind(this),this._onMoveHandlerBound=this._onMapMove.bind(this),this._onContextMenuBound=this._onContextMenu.bind(this)}onAdd(t){return 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-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._deactivate(),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._container=null,this._btn=null}_toggle(){this._active?this._deactivate():this._activate()}_activate(){if(!this._map)return;this._active=!0,this._btn?.classList.add("active"),this._map.setEditMode("vertex");const t=this._map.getCanvasContainer();t.classList.add("emap-edit-active"),t.addEventListener("mousemove",this._onMouseMoveBound),t.addEventListener("mousedown",this._onMouseDownBound),t.addEventListener("contextmenu",this._onContextMenuBound),window.addEventListener("mouseup",this._onMouseUpBound),this._map.on("move",this._onMoveHandlerBound)}_deactivate(){if(!this._map)return;this._active=!1,this._btn?.classList.remove("active"),this._map.setEditMode("none"),this._map.clearEditVertexState(),this._hoveredFeature=null,this._hoverVertexCoords=null,this._hoverVertexIds=[],this._hoverType=null,this._hoverInsertionId=-1,this._neighborShapes=[],this._dragging=!1;const t=this._map.getCanvasContainer();t.classList.remove("emap-edit-active"),t.removeEventListener("mousemove",this._onMouseMoveBound),t.removeEventListener("mousedown",this._onMouseDownBound),t.removeEventListener("contextmenu",this._onContextMenuBound),window.removeEventListener("mouseup",this._onMouseUpBound),this._map.off("move",this._onMoveHandlerBound),this._map.render()}_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;Q().vertexIsArcEndpoint(e,i)||this._showContextMenu(t.clientX,t.clientY,()=>{this._deleteHoveredVertex()})}_deleteHoveredVertex(){if(!this._map||!this._hoveredFeature||0===this._hoverVertexIds.length)return;const t=this._hoveredFeature.arcs,e=this._hoverVertexIds[0],i=this._hoveredFeature.source,r=t.getVertex2(e);if(Q().deleteVertex(t,e),this._refreshSourceDisplayArcs(i),this._bumpSourceEditVersion(i),r){const n=this._map.getSource(i);n&&this._map.pushCommand(new Qi({vertexIndex:e,coords:[r[0],r[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);Lt(e?.getDataset?.()??null)}_showContextMenu(t,e,i){document.getElementById("emap-ctx-menu")?.remove();const r=document.createElement("div");r.id="emap-ctx-menu",Object.assign(r.style,{position:"fixed",left:`${t}px`,top:`${e}px`,background:"#fff",border:"1px solid #ccc",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.18)",padding:"4px 0",zIndex:"9999",minWidth:"120px",font:"13px/1.5 system-ui, sans-serif"});const n=document.createElement("div");n.textContent="删除节点",Object.assign(n.style,{padding:"6px 16px",cursor:"pointer",color:"#d32"}),n.addEventListener("mouseenter",()=>{n.style.background="#f5f5f5"}),n.addEventListener("mouseleave",()=>{n.style.background=""}),n.addEventListener("click",t=>{t.stopPropagation(),r.remove(),document.removeEventListener("click",s),i()}),r.appendChild(n),document.body.appendChild(r);const s=()=>{r.remove(),document.removeEventListener("click",s)};setTimeout(()=>document.addEventListener("click",s),0)}_onMouseMove(t){if(!this._map)return;if(this._dragging)return void this._handleDrag(t);const e=this._map.getCanvasContainer().getBoundingClientRect(),i=t.clientX-e.left,r=t.clientY-e.top,n=this._map.queryFeatures([i,r]);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 s=n[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 o=this._map.getSource(s.source);if(!o)return;const a=o.getLayers(),l=o.getArcs();if(!l)return;let c=null;for(const t of a)if(t.shapes&&t.shapes[s.id]){c=t.shapes[s.id];break}c&&(this._hoveredFeature={source:s.source,layer:s.layer,id:s.id,shape:c,arcs:l,geometryType:s.geometryType,allLayers:a},this._findNearestVertices(c,l,i,r),this._hoverVertexCoords||this._findInterpolatedPoint(c,l,i,r),this._findNeighborShapes(l),this._updateEditState(),this._map.render())}_findNearestVertices(t,e,i,r){if(!this._map)return;const n=this._map.unproject(i,r),s=Q().findNearestVertices(n,t,e);if(!s||0===s.length)return this._hoverVertexCoords=null,void(this._hoverVertexIds=[]);const o=e.getVertex2(s[0]);if(!o)return this._hoverVertexCoords=null,void(this._hoverVertexIds=[]);const a=this._map.project(o[0],o[1]);Math.sqrt((a[0]-i)*(a[0]-i)+(a[1]-r)*(a[1]-r))<=10?(this._hoverVertexCoords=[o[0],o[1]],this._hoverVertexIds=s,this._hoverType="vertex",this._hoverInsertionId=-1):(this._hoverVertexCoords=null,this._hoverVertexIds=[],this._hoverType=null,this._hoverInsertionId=-1)}_findInterpolatedPoint(t,e,i,r){if(!this._map)return;const n=this._map.unproject(i,r);let s=1/0,o=null;const a=Q();if(a.forEachSegmentInShape(t,e,(t,e,i,r)=>{const l=i[t],c=r[t],h=i[e],u=r[e],p=a.findClosestPointOnSeg(n[0],n[1],l,c,h,u,0),d=p[0]-n[0],f=p[1]-n[1],m=Math.sqrt(d*d+f*f);m<s&&(s=m,o={insertionId:(t<e?t:e)+1,point:[p[0],p[1]]})}),!o)return;const l=o,c=this._map.project(l.point[0],l.point[1]);Math.sqrt((c[0]-i)*(c[0]-i)+(c[1]-r)*(c[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(),i=this._hoveredFeature.id,r=new Set;if(this._hoverVertexIds.length>0)for(const t of this._hoverVertexIds)r.add(Q().findArcIdFromVertexId(t,e));else"interpolated"===this._hoverType&&this._hoverInsertionId>0&&r.add(Q().findArcIdFromVertexId(this._hoverInsertionId-1,e));if(0===r.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 s=t.shapes[e];if(!s)continue;let o=!1;for(const t of s){for(const e of t){const t=e>=0?e:~e;if(r.has(t)){o=!0;break}}if(o)break}o&&n.push(s)}this._neighborShapes=n}_updateEditState(){if(!this._map||!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){if(this._hoverVertexCoords&&this._hoveredFeature){if(t.preventDefault(),t.stopPropagation(),"interpolated"===this._hoverType&&this._hoverInsertionId>=0){const t=this._hoveredFeature.arcs,e=[this._hoverVertexCoords[0],this._hoverVertexCoords[1]];Q().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._map||!this._hoveredFeature)return;const i=this._map.getSource(this._hoveredFeature.source);i&&this._map.pushCommand(new Ji({insertionId:t,point:e,arcs:this._hoveredFeature.arcs,source:i}))}_handleDrag(t){if(!this._map||!this._hoveredFeature||0===this._hoverVertexIds.length)return;const e=this._map.getCanvasContainer().getBoundingClientRect(),i=t.clientX-e.left,r=t.clientY-e.top,n=this._map.unproject(i,r),s=this._hoveredFeature.arcs;Q().snapVertices(this._hoverVertexIds,[n[0],n[1]],s),this._hoverVertexCoords=[n[0],n[1]],this._updateEditState(),this._map.render()}_onMouseUp(t){if(!this._dragging||!this._map||!this._hoveredFeature)return;this._dragging=!1;const e=this._map.getCanvasContainer().getBoundingClientRect(),i=t.clientX-e.left,r=t.clientY-e.top,n=this._map.unproject(i,r),s=this._hoveredFeature.source,o=this._hoveredFeature.arcs;o.transformPoints&&o.transformPoints(function(){}),this._refreshSourceDisplayArcs(s),this._bumpSourceEditVersion(s);const a=this._dragFromCoords;if(a&&(a[0]!==n[0]||a[1]!==n[1])&&this._hoverVertexIds.length>0){const t=this._map.getSource(s);t&&this._map.pushCommand(new Ki({vertexIds:[...this._hoverVertexIds],from:[a[0],a[1]],to:[n[0],n[1]],arcs:o,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:n}),this._map.render()}}const rr={polygon:"▢",polyline:"╱",point:"●"},nr={polygon:"Draw Polygon",polyline:"Draw Polyline",point:"Draw Point"};class sr{_options;_map=null;_container=null;_btn=null;_active=!1;_vertices=[];_cursorCoord=null;_snapCoord=null;_snapKind=null;_snapThreshold;_onMouseMoveBound;_onClickBound;_onDblClickBound;_onKeyDownBound;_onMoveHandlerBound;constructor(t){this._options=t,this._snapThreshold=t.snapThreshold??10,this._onMouseMoveBound=this._onMouseMove.bind(this),this._onClickBound=this._onClick.bind(this),this._onDblClickBound=this._onDblClick.bind(this),this._onKeyDownBound=this._onKeyDown.bind(this),this._onMoveHandlerBound=this._onMapMove.bind(this)}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=nr[this._options.type];const e=document.createElement("span");e.className="emap-ctrl-icon";const i=this._options.icon??rr[this._options.type];return"string"==typeof i?e.textContent=i:e.appendChild(i),this._btn.replaceChildren(e),this._btn.addEventListener("click",()=>this._toggle()),this._container.appendChild(this._btn),t.on("editmodechange",t=>{this._active&&"draw"!==t.mode&&this._deactivateQuiet()}),this._container}onRemove(){this._deactivate(),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._container=null,this._btn=null}_toggle(){this._active?this._deactivate():this._activate()}_activate(){if(!this._map)return;this._active=!0,this._btn?.classList.add("active"),this._map.setEditMode("draw");const t=this._map.getCanvasContainer();t.classList.add("emap-draw-active"),t.addEventListener("mousemove",this._onMouseMoveBound),t.addEventListener("click",this._onClickBound),t.addEventListener("dblclick",this._onDblClickBound),window.addEventListener("keydown",this._onKeyDownBound),this._map.on("move",this._onMoveHandlerBound)}_deactivate(){this._clearDrawState(),this._deactivateQuiet(),this._map?.setEditMode("none")}_deactivateQuiet(){if(!this._map)return;this._active=!1,this._btn?.classList.remove("active");const t=this._map.getCanvasContainer();t.classList.remove("emap-draw-active"),t.removeEventListener("mousemove",this._onMouseMoveBound),t.removeEventListener("click",this._onClickBound),t.removeEventListener("dblclick",this._onDblClickBound),window.removeEventListener("keydown",this._onKeyDownBound),this._map.off("move",this._onMoveHandlerBound),this._map.clearEditDrawState(),this._map.render()}_clearDrawState(){this._vertices=[],this._cursorCoord=null,this._snapCoord=null,this._snapKind=null}_onMapMove(){this._vertices.length>0&&(this._updateDrawState(),this._map?.render())}_onMouseMove(t){if(!this._map)return;const e=this._map.getCanvasContainer().getBoundingClientRect(),i=t.clientX-e.left,r=t.clientY-e.top,n=this._map.unproject(i,r);this._cursorCoord=[n[0],n[1]];const s=this._findSnapTarget(i,r);this._snapCoord=s?.coord??null,this._snapKind=s?.kind??null,(this._vertices.length>0||this._snapCoord)&&(this._updateDrawState(),this._map.render())}_onClick(t){if(!this._map)return;const e=this._map.getCanvasContainer().getBoundingClientRect(),i=t.clientX-e.left,r=t.clientY-e.top,n=this._snapCoord?[this._snapCoord[0],this._snapCoord[1]]:this._map.unproject(i,r);if("point"===this._options.type)return this._vertices=[n],void this._commitFeature();if("polygon"===this._options.type&&this._vertices.length>=3){const t=this._vertices[0],e=this._map.project(t[0],t[1]);if(Math.hypot(e[0]-i,e[1]-r)<=12)return void this._commitFeature()}this._vertices.push(n),this._updateDrawState(),this._map.render()}_onDblClick(t){this._map&&(t.preventDefault(),t.stopPropagation(),"point"!==this._options.type&&("polyline"===this._options.type&&this._vertices.length>=2||"polygon"===this._options.type&&this._vertices.length>=3)&&this._commitFeature())}_onKeyDown(t){"Escape"===t.key&&(this._clearDrawState(),this._map?.clearEditDrawState(),this._map?.render())}_findSnapTarget(t,e){if(!this._map)return null;const i=this._map,r=this._options.snapSources??[this._options.source],n=!1!==this._options.snapToVertex,s=!1!==this._options.snapToEdge;let o=this._snapThreshold,a=null,l=null;for(const c of r){const r=i.getSource(c);if(!r)continue;const h=r.getArcs();if(!h?.getVertexData)continue;const u=h.getVertexData();if(!u)continue;const p=u.xx,d=u.yy;if(n)for(let r=0;r<p.length;r++){const n=i.project(p[r],d[r]),s=Math.hypot(n[0]-t,n[1]-e);s<o&&(o=s,a=[p[r],d[r]],l="vertex")}s&&h.forEachSegment&&h.forEachSegment((r,n,s,c)=>{const h=i.project(s[r],c[r]),u=i.project(s[n],c[n]),p=or([t,e],h,u);p.dist<o&&(o=p.dist,a=i.unproject(p.point[0],p.point[1]),l="edge")})}if(n)for(const r of this._vertices){const n=i.project(r[0],r[1]),s=Math.hypot(n[0]-t,n[1]-e);s<o&&(o=s,a=[r[0],r[1]],l="vertex")}return a?{coord:a,kind:l}:null}_commitFeature(){if(!this._map||0===this._vertices.length)return;const t=this._map.getSource(this._options.source);if(!t)return;const e=t.getDataset();if(!e)return;const i=this._resolveTargetLayer(e.layers);if(!i)return;const r=e.layers.indexOf(i);let n,s,o;if(i.shapes||(i.shapes=[]),"point"===this._options.type)n=[this._vertices[0]],i.shapes.push(n);else{if(s="polygon"===this._options.type?[...this._vertices,this._vertices[0]]:[...this._vertices],o=e.arcs,!o)return;n=[[this._appendArc(o,s)]],i.shapes.push(n)}let a=null;if(i.data){const t=i.data.getRecords?.();t&&(a={},t.push(a))}t.refreshDisplayArcs(),this._map.pushCommand(new tr({geometryType:this._options.type,layer:i,source:t,appendedShape:n,appendedRecord:a,arcVertices:s,arcs:o}));const l=i.shapes.length-1,c=it(i,r>=0?r:0);this._map.fire("feature_created",{id:l,source:this._options.source,layer:c,geometryType:this._options.type,properties:{}}),this._clearDrawState(),this._map.clearEditDrawState(),t.fire("data",{reason:"edit"})}_resolveTargetLayer(t){if(!t.length)return null;if(this._options.sourceLayer)for(let e=0;e<t.length;e++){if(it(t[e],e)===this._options.sourceLayer)return t[e]}const e="polygon"===this._options.type?"polygon":"polyline"===this._options.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(),r=i.xx,n=i.yy,s=i.nn,o=i.zz,a=r.length,l=s.length,c=e.length,h=new Float64Array(a+c),u=new Float64Array(a+c),p=new Int32Array(l+1);h.set(r),u.set(n),p.set(s);for(let t=0;t<c;t++)h[a+t]=e[t][0],u[a+t]=e[t][1];p[l]=c;let d=null;if(o){d=new Float64Array(a+c),d.set(o);for(let t=0;t<c;t++)d[a+t]=1/0}return t.updateVertexData(p,h,u,d),l}_updateDrawState(){this._map&&this._map.setEditDrawState({vertices:[...this._vertices],cursorCoord:this._snapCoord||this._cursorCoord,snapCoord:this._snapCoord,snapKind:this._snapKind,geometryType:this._options.type,drawColor:this._options.drawColor||"#0078ff"})}}function or(t,e,i){const r=e[0],n=e[1],s=i[0],o=i[1],a=t[0],l=t[1],c=s-r,h=o-n,u=c*c+h*h;if(0===u){const t=a-r,e=l-n;return{point:[r,n],dist:Math.hypot(t,e)}}let p=((a-r)*c+(l-n)*h)/u;p<0?p=0:p>1&&(p=1);const d=r+p*c,f=n+p*h;return{point:[d,f],dist:Math.hypot(a-d,l-f)}}function ar(t,e){const[i,r]=t;let n=!1;const s=e.length;for(let t=0,o=s-1;t<s;o=t++){const[s,a]=e[t],[l,c]=e[o];a>r!=c>r&&i<(l-s)*(r-a)/(c-a)+s&&(n=!n)}return n}function lr(t,e,i,r){const n=function(t,e){const i=t.getSource(e.source);if(!i)return null;let r=t.layers?.resolve(e.source,e.layer);if(!r){const t=i.getDataset?.();r=t?.layers.find((t,i)=>it(t,i)===e.layer||t?.name===e.layer||t?.id===e.layer)}if(!r?.shapes)return null;const n=r.shapes?.[e.id];return n?{layer:r,shape:n,arcs:i.getArcs?.()}:null}(t,e);if(!n)return!1;if("point"===n.layer.geometry_type){const e=rt(n.shape);if(0===e.length)return!1;const s=e.map(([e,i])=>t.project(e,i));return r?s.some(t=>hr(t,i)):s.every(t=>hr(t,i))}if(!n.arcs)return!1;const s=function(t,e,i){const r=[];for(const n of e){const e=[],s=i.getShapeIter?.(n);if(s)for(;s.hasNext();)e.push(t.project(s.x,s.y));else for(const r of n){const n=r>=0?r:~r,s=i.getArcIter(n);for(;s.hasNext();)e.push(t.project(s.x,s.y))}e.length>0&&r.push(e)}return r}(t,n.shape,n.arcs);if(0===s.length)return!1;const o="polygon"===n.layer.geometry_type;return r?function(t,e,i){for(const r of t){if(r.some(t=>hr(t,e)))return!0;if(cr(r,e,i))return!0}return!(!i||!e.some(e=>function(t,e){let i=!1;for(const r of e){if(ur(t,r))return!0;ar(t,r)&&(i=!i)}return i}(e,t)))}(s,i,o):function(t,e,i){for(const r of t){if(!r.every(t=>hr(t,e)))return!1;if(cr(r,e,i))return!1}return!0}(s,i,o)}function cr(t,e,i){const r=i?pr(t):t,n=pr(e);for(let t=0;t<r.length-1;t++){const e=r[t],i=r[t+1];for(let t=0;t<n.length-1;t++){if(dr(e,i,n[t],n[t+1]))return!0}}return!1}function hr(t,e){return ur(t,e)||ar(t,e)}function ur(t,e){const i=pr(e);for(let e=0;e<i.length-1;e++)if(fr(t,i[e],i[e+1]))return!0;return!1}function pr(t){if(t.length<2)return t;const e=t[0],i=t[t.length-1];return r=e,n=i,Math.abs(r[0]-n[0])<=gr&&Math.abs(r[1]-n[1])<=gr?t:[...t,e];var r,n}function dr(t,e,i,r){const n=mr(t,e,i),s=mr(t,e,r),o=mr(i,r,t),a=mr(i,r,e);return!(!_r(n)||!fr(i,t,e))||(!(!_r(s)||!fr(r,t,e))||(!(!_r(o)||!fr(t,i,r))||(!(!_r(a)||!fr(e,i,r))||n>0!=s>0&&o>0!=a>0)))}function fr(t,e,i){return!!_r(mr(e,i,t))&&(t[0]>=Math.min(e[0],i[0])-gr&&t[0]<=Math.max(e[0],i[0])+gr&&t[1]>=Math.min(e[1],i[1])-gr&&t[1]<=Math.max(e[1],i[1])+gr)}function mr(t,e,i){return(e[0]-t[0])*(i[1]-t[1])-(e[1]-t[1])*(i[0]-t[0])}function _r(t){return Math.abs(t)<=gr}const gr=1e-9;const yr=[{value:"",label:"weighted (default)"},{value:"weighted",label:"weighted"},{value:"visvalingam",label:"visvalingam"},{value:"dp",label:"dp (Douglas–Peucker)"}];var vr={exports:{}};
|
|
1
|
+
var emap=function(t,e){"use strict";function i(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 r=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,r.get?r:{enumerable:!0,get:function(){return e[i]}})}})}),Object.freeze(t)}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function r(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function n(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 r=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(i,e,r.get?r:{enumerable:!0,get:function(){return t[e]}})}),i}var s={exports:{}},o=n(Object.freeze({__proto__:null,default:{}}));function a(t,e){for(var i=0,r=t.length-1;r>=0;r--){var n=t[r];"."===n?t.splice(r,1):".."===n?(t.splice(r,1),i++):i&&(t.splice(r,1),i--)}if(e)for(;i--;i)t.unshift("..");return t}var l=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,c=function(t){return l.exec(t).slice(1)};function h(){for(var t="",e=!1,i=arguments.length-1;i>=-1&&!e;i--){var r=i>=0?arguments[i]:"/";if("string"!=typeof r)throw new TypeError("Arguments to path.resolve must be strings");r&&(t=r+"/"+t,e="/"===r.charAt(0))}return(e?"/":"")+(t=a(v(t.split("/"),function(t){return!!t}),!e).join("/"))||"."}function u(t){var e=p(t),i="/"===b(t,-1);return(t=a(v(t.split("/"),function(t){return!!t}),!e).join("/"))||e||(t="."),t&&i&&(t+="/"),(e?"/":"")+t}function p(t){return"/"===t.charAt(0)}function d(){return u(v(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 f(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=h(t).substr(1),e=h(e).substr(1);for(var r=i(t.split("/")),n=i(e.split("/")),s=Math.min(r.length,n.length),o=s,a=0;a<s;a++)if(r[a]!==n[a]){o=a;break}var l=[];for(a=o;a<r.length;a++)l.push("..");return(l=l.concat(n.slice(o))).join("/")}function m(t){var e=c(t),i=e[0],r=e[1];return i||r?(r&&(r=r.substr(0,r.length-1)),i+r):"."}function _(t,e){var i=c(t)[2];return e&&i.substr(-1*e.length)===e&&(i=i.substr(0,i.length-e.length)),i}function g(t){return c(t)[3]}var y={extname:g,basename:_,dirname:m,sep:"/",delimiter:":",relative:f,join:d,isAbsolute:p,normalize:u,resolve:h};function v(t,e){if(t.filter)return t.filter(e);for(var i=[],r=0;r<t.length;r++)e(t[r],r,t)&&i.push(t[r]);return i}var x,b="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)},w=n(Object.freeze({__proto__:null,basename:_,default:y,delimiter:":",dirname:m,extname:g,isAbsolute:p,join:d,normalize:u,relative:f,resolve:h,sep:"/"}));x=s,function(){var t=Math.abs,e=Math.floor,i=Math.sin,r=Math.cos,n=Math.tan,s=Math.asin,a=Math.acos,l=Math.atan,c=Math.atan2,h=Math.sqrt,u=Math.pow,p=Math.exp,d=Math.log,f=Math.hypot,m=Math.sinh,_=Math.cosh,g=Math.min,y=Math.max,v=1/0,b=Math.PI,S=57.29577951308232,T=.017453292519943295,C=6378137,M=.0066943799901413165,A=b/4,E=b/2,I=1.5*b,P=2*b,D=2/b,k=-45,z=-47,R=1e-10,L={last_errno:0,debug_level:0,logger:null},F=["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 B(){var t=L.last_errno;t&&(t>0||!function(t){return O.indexOf(t)>-1}(t))&&U(t)}var O=[-14,-15,-17,-18,-19,-20,-27,-48];function N(t){L.last_errno=t}function V(){N(-20)}function j(){N(-20)}function G(t){U(t)}function U(t){N(t),q()}function q(t,e){var i;throw e||(e={}),e.code||(e.code=L.last_errno||0),t||(i=e.code,t=F[~i]||"unknown error"),L.last_errno=0,new $(t,e)}function $(t,e){var i=new Error(t);return i.name="ProjError",Object.keys(e).forEach(function(t){i[t]=e[t]}),i}function Z(t){return W(t)*T}function W(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 H(t){return X(t)}function X(t){return parseFloat(t)}function Y(t,e){var i,r,n=e[0],s=t[e.substr(1)],o=void 0!==s;return"t"==n?i=o:o?(r=s.param,s.used=!0,"i"==n?i=parseInt(r):"d"==n?i=H(r):"r"==n?i=Z(r):"s"==n?i=String(r):"b"==n&&("T"==r||"t"==r||!0===r?i=!0:("F"==r||"f"==r||N(-8),i=!1))):i={i:0,b:!1,d:0,r:0,s:""}[n],void 0===i&&q("invalid request to pj_param, fatal"),i}function K(t){for(var e,i=/\+([a-z][a-z0-9_]*(?:=[^\s]*)?)/gi,r={};e=i.exec(t);)J(r,e[1]);return r}function J(t,e){var i,r,n=e.split("=");1==n.length?(i=e,r=!0):(i=n[0],r=e.substr(n[0].length+1)),t[i]={used:!1,param:r}}var Q={};function tt(t,e,i,r){Q[e]={init:t,name:i,description:r}}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):G(-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 rt(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(r){-1==e.indexOf(r)&&(i+=nt(t,r))}),(i+=it(t)).trim()}function nt(t,e){var i="";return e in t.params&&(i=" +"+e,!0!==t.params[e].param&&(i+="="+Y(t.params,"s"+e))),i}var st=[["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]],ot=[["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=st.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 lt=[["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 ct(t){var e=lt.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 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 ut(t){var e=ht.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={},dt={};function ft(t){return dt[t]||null}function mt(t){var e,i,r,n,s,a,l,c,h=t.split(":"),u=h[0],p=h[1];return p&&u||G(-3),(e=ft(u=u.toLowerCase()))||(i=u,n=o,a=(s=w).join(s.dirname("/Users/zhang/code/emap/node_modules/mproj/dist"),"../nad"),l=s.join(a,i.toUpperCase()),c=s.join(a,i.toLowerCase()),n.existsSync(l)?r=n.readFileSync(l,"utf8"):n.existsSync(c)?r=n.readFileSync(c,"utf8"):q("unable to read from 'init' file named "+i),e=r,dt[u]=e),e?function(t,e){var i,r,n="",s="";return(i=t.indexOf("<"+e+">"))>-1&&((r=t.lastIndexOf("#",i))>-1&&(s=t.substring(r+1,i).trim(),/\n/.test(s)&&(s="")),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:s}:null}(e,p):null}function _t(e){var r,n,s=K(e),o={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||G(-1),Y(s,"tinit")&&function(t,e){var i=pt[e.toLowerCase()]||null;i||function(t,e){pt[t.toLowerCase()]=e}(e,i=mt(e)),i||G(-2),gt(t,i.opts)}(s,Y(s,"sinit")),(r=Y(s,"sproj"))||G(-4),(n=Q[r])||G(-5),Y(s,"bno_defs")||function(t){gt(t,"+ellps=WGS84")}(o.params),function(t){var e,i,r,n,s=484813681109536e-20,o=t.datum_params=[0,0,0,0,0,0,0];t.datum_type=0,(e=Y(t.params,"sdatum"))&&((i=at(e))||G(-9),i.ellipse_id&&J(t.params,"ellps="+i.ellipse_id),i.defn&&J(t.params,i.defn)),(r=Y(t.params,"snadgrids"))&&"@null"!=r&&q("+nadgrids is not implemented"),Y(t.params,"scatalog")&&q("+catalog is not implemented"),(n=Y(t.params,"stowgs84"))&&(n.split(",").forEach(function(t,e){o[e]=H(t)||0}),0!=o[3]||0!=o[4]||0!=o[5]||0!=o[6]?(t.datum_type=2,o[3]*=s,o[4]*=s,o[5]*=s,o[6]=o[6]/1e6+1):t.datum_type=1)}(o),function(e){var r,n,s,o,a,l=.16666666666666666,c=e.params,u=0,p=0;Y(c,"tR")?u=Y(c,"dR"):((r=Y(c,"sellps"))&&((n=ct(r))||G(-9),J(c,n.major),J(c,n.ell)),u=Y(c,"da"),Y(c,"tes")?p=Y(c,"des"):Y(c,"te")?p=(s=Y(c,"de"))*s:Y(c,"trf")?((s=Y(c,"drf"))||G(-10),p=(s=1/s)*(2-s)):Y(c,"tf")?p=(s=Y(c,"df"))*(2-s):Y(c,"tb")&&(p=1-(o=Y(c,"db"))*o/(u*u)),o||(o=u*h(1-p)),Y(c,"bR_A")?(u*=1-p*(l+p*(.04722222222222222+.022156084656084655*p)),p=0):Y(c,"bR_V")?u*=1-p*(l+p*(.06944444444444445+.04243827160493827*p)):Y(c,"bR_a")?(u=.5*(u+o),p=0):Y(c,"bR_g")?(u=h(u*o),p=0):Y(c,"bR_h")?(u+o===0&&G(-20),u=2*u*o/(u+o),p=0):(a=Y(c,"tR_lat_a")||Y(c,"tR_lat_g"))&&(s=i(Y(c,a?"rR_lat_a":"rR_lat_g")),t(s)>E&&G(-11),s=1-p*s*s,u*=a?.5*(1-p+s)/(s*h(s)):h(1-p)/s,p=0)),p<0&&G(-12),u<=0&&G(-13),e.es=p,e.a=u}(o),o.a_orig=o.a,o.es_orig=o.es,o.e=h(o.es),o.ra=1/o.a,o.one_es=1-o.es,o.one_es||G(-6),o.rone_es=1/o.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}(o)&&(o.datum_type=4),o.geoc=!!o.es&&Y(s,"bgeoc"),o.over=Y(s,"bover"),o.has_geoid_vgrids=Y(s,"tgeoidgrids"),o.has_geoid_vgrids&&Y(s,"sgeoidgrids"),o.is_long_wrap_set=Y(s,"tlon_wrap"),o.is_long_wrap_set&&(o.long_wrap_center=Y(s,"rlon_wrap"),t(o.long_wrap_center)<10*P==0&&G(-14)),Y(s,"saxis")&&function(t){var e="ewnsud",i=Y(t.params,"saxis");3!=i.length&&G(z),-1!=e.indexOf(i[0])&&-1!=e.indexOf(i[1])&&-1!=e.indexOf(i[2])||G(z),t.axis=i}(o),o.lam0=Y(s,"rlon_0"),o.phi0=Y(s,"rlat_0"),o.x0=Y(s,"dx_0"),o.y0=Y(s,"dy_0"),Y(s,"tk_0")?o.k0=Y(s,"dk_0"):Y(s,"tk")?o.k0=Y(s,"dk"):o.k0=1,o.k0<=0&&G(-31),function(t){var e,i,r,n=t.params;(e=Y(n,"sunits"))&&((r=ut(e))||G(-7),i=r.to_meter),i||(i=Y(n,"sto_meter"))?(t.to_meter=yt(i),t.fr_meter=1/t.to_meter):t.to_meter=t.fr_meter=1,i=null,(e=Y(n,"svunits"))&&((r=ut(e))||G(-7),i=r.to_meter),i||Y(n,"svto_meter")?(t.vto_meter=yt(i),t.vfr_meter=1/t.vto_meter):(t.vto_meter=t.to_meter,t.vfr_meter=t.fr_meter)}(o),function(t){var e,i,r,n=t.params;(e=Y(n,"spm"))?(i=function(t){var e=ot.reduce(function(e,i){return i[0]===t?i:e},null);return e?{id:e[0],definition:e[1]}:null}(e),r=Z(i?i.definition:e),isNaN(r)&&G(-46),t.from_greenwich=r):t.from_greenwich=0}(o),n.init(o),o}function gt(t,e){var i=K(e),r=["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&&r||(t[e]=i[e])})}function yt(t){var e=t.split("/"),i=X(e[0]);return e.length>1&&(i/=X(e[1])),i}function vt(t,e){var i=0,r=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:r,b2:n,e2:(r-n)/r,ep2:(r-n)/n}}function xt(t,e,n,s,o){var a,l,c,u,p=0,d=n[e],f=s[e],m=o[e];return f<-E&&f>-1.001*E?f=-E:f>E&&f<1.001*E?f=E:(f<-E||f>E)&&(p|=1),p||(d>b&&(d-=2*b),l=i(f),u=r(f),c=l*l,a=t.a/h(1-t.e2*c),n[e]=(a+m)*u*r(d),s[e]=(a+m)*u*i(d),o[e]=(a*(1-t.e2)+m)*l),p}function bt(e,i,r,n,s){var o,a,u,p,d,f,m,_,g,y,v,x,b,w,S,T,C=1e-12,M=r[i],A=n[i],I=s[i];if(p=h(M*M+A*A),d=h(M*M+A*A+I*I),p/e.a<C){if(a=0,d/e.a<C)return r[i]=0,n[i]=E,s[i]=-e.b,0}else a=c(A,M);f=I/d,m=p/d,_=1/h(1-e.e2*(2-e.e2)*m*m),v=m*(1-e.e2)*_,x=f*_,T=0;do{T++,u=p*v+I*x-(g=e.a/h(1-e.e2*x*x))*(1-e.e2*x*x),y=e.e2*g/(g+u),S=(w=f*(_=1/h(1-y*(2-y)*m*m)))*v-(b=m*(1-y)*_)*x,v=b,x=w}while(S*S>1e-24&&T<30);o=l(w/t(b)),r[i]=a,n[i]=o,s[i]=u}function wt(t,e,i){var r=i.length>2,n=[i[0]],s=[i[1]],o=[r?i[2]:0];t.is_latlong&&(n[0]*=T,s[0]*=T),L.last_errno=0,St(t,e,n,s,o),(L.last_errno||n[0]==v)&&q(null,{point:i}),e.is_latlong&&(n[0]*=S,s[0]*=S),i[0]=n[0],i[1]=s[0],r&&(i[2]=o[0])}function St(t,e,i,r,n){var s,o,a=i.length,l={},c={};if("enu"!=t.axis&&Tt(t.axis,!1,i,r,n),1!=t.vto_meter&&n)for(s=0;s<a;s++)n[s]*=t.vto_meter;if(t.is_geocent){if(n||G(k),1!=t.to_meter)for(s=0;s<a;s++)i[s]!=v&&(i[s]*=t.to_meter,r[s]*=t.to_meter);Ct(t.a_orig,t.es_orig,i,r,n)}else if(!t.is_latlong)if(t.inv3d||t.inv||q("source projection not invertible"),t.inv3d)q("inverse 3d transformations not supported");else for(s=0;s<a;s++)c.x=i[s],c.y=r[s],o=It(c,t),i[s]=o.lam,r[s]=o.phi,B();if(0!==t.from_greenwich)for(s=0;s<a;s++)i[s]!=v&&(i[s]+=t.from_greenwich);if(t.has_geoid_vgrids&&n&&q("vgrid transformation not supported"),function(t,e,i,r,n){var s,o,a,l,c=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||Y(t.params,"snadgrids")==Y(e.params,"snadgrids")))}(t,e)||(s=t.a_orig,o=t.es_orig,a=e.a_orig,l=e.es_orig,n||(n=new Float64Array(c)),3==t.datum_type&&(q("gridshift not implemented"),s=C,o=M),3==e.datum_type&&(a=C,l=M),o==l&&s==a&&1!=t.datum_type&&2!=t.datum_type&&1!=e.datum_type&&2!=e.datum_type||(Mt(s,o,i,r,n),1!=t.datum_type&&2!=t.datum_type||function(t,e,i,r){var n,s,o,a,l,c,h,u,p=e.length,d=t.datum_params,f=d[0],m=d[1],_=d[2];if(1==t.datum_type)for(u=0;u<p;u++)e[u]!=v&&(e[u]+=f,i[u]+=m,r[u]+=_);else if(2==t.datum_type)for(a=d[3],l=d[4],c=d[5],h=d[6],u=0;u<p;u++)e[u]!=v&&(n=h*(e[u]-c*i[u]+l*r[u])+f,s=h*(c*e[u]+i[u]-a*r[u])+m,o=h*(-l*e[u]+a*i[u]+r[u])+_,e[u]=n,i[u]=s,r[u]=o)}(t,i,r,n),1!=e.datum_type&&2!=e.datum_type||function(t,e,i,r){var n,s,o,a,l,c,h,u,p=e.length,d=t.datum_params,f=d[0],m=d[1],_=d[2];if(1==t.datum_type)for(u=0;u<p;u++)e[u]!=v&&(e[u]-=f,i[u]-=m,r[u]-=_);else if(2==t.datum_type)for(a=d[3],l=d[4],c=d[5],h=d[6],u=0;u<p;u++)e[u]!=v&&(n=(e[u]-f)/h,s=(i[u]-m)/h,o=(r[u]-_)/h,e[u]=n+c*s-l*o,i[u]=-c*n+s+a*o,r[u]=l*n-a*s+o)}(e,i,r,n),Ct(a,l,i,r,n),3==e.datum_type&&pj_apply_gridshift_2(e,1,i,r,n))))}(t,e,i,r,n),e.has_geoid_vgrids&&n&&q("vgrid transformation not supported"),0!==e.from_greenwich)for(s=0;s<a;s++)i[s]!=v&&(i[s]-=e.from_greenwich);if(e.is_geocent){if(n||G(k),Mt(e.a_orig,e.es_orig,i,r,n),1!=e.fr_meter)for(s=0;s<a;s++)i[s]!=v&&(i[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<a;s++)if(i[s]!=v){for(;i[s]<e.long_wrap_center-b;)i[s]+=P;for(;i[s]>e.long_wrap_center+b;)i[s]-=P}}else if(e.fwd3d)q("3d transformation not supported");else for(s=0;s<a;s++)l.lam=i[s],l.phi=r[s],o=Et(l,e),i[s]=o.x,r[s]=o.y,B();if(1!=e.vto_meter&&n)for(s=0;s<a;s++)n[s]*=e.vfr_meter;return"enu"!=e.axis&&Tt(e.axis,!0,i,r,n),1==a?L.last_errno:0}function Tt(t,e,i,r,n){var s,o,a,l,c,h,u=i.length,p=0;if(e){for(a=0;a<u;a++)if(s=i[a],o=r[a],s!=v)for(n&&(p=n[a]),l=0;l<3;l++)if(2!=l||n)switch(h=0==l?i:1==l?r:n,t[l]){case"e":h[a]=s;break;case"w":h[a]=-s;break;case"n":h[a]=o;break;case"s":h[a]=-o;break;case"u":h[a]=p;break;case"d":h[a]=-p;break;default:G(z)}}else for(a=0;a<u;a++)if(s=i[a],o=r[a],s!=v)for(n&&(p=n[a]),l=0;l<3;l++)switch(c=0==l?s:1==l?o:p,t[l]){case"e":i[a]=c;break;case"w":i[a]=-c;break;case"n":r[a]=c;break;case"s":r[a]=-c;break;case"u":n&&(n[a]=c);break;case"d":n&&(n[a]=-c);break;default:G(z)}}function Ct(t,e,i,r,n){var s,o,a=i.length;for((o=vt(t,0==e?t:t*h(1-e)))||G(k),s=0;s<a;s++)i[s]!=v&&bt(o,s,i,r,n)}function Mt(t,e,i,r,n){var s,o,a=i.length;for((o=vt(t,0===e?t:t*h(1-e)))||G(k),s=0;s<a;s++)i[s]!=v&&xt(o,s,i,r,n)&&(i[s]=r[s]=v)}function At(i){var r=6.283185307179586,n=3.141592653589793;return t(i)>3.14159265359&&(i+=n,i-=r*e(i/r),i-=n),i}function Et(e,i){var r={x:0,y:0},s=t(e.phi)-E;return s<=1e-12&&t(e.lam)<=10?(L.last_errno=0,t(s)<=1e-12?e.phi=e.phi<0?-E:E:i.geoc&&(e.phi=l(i.rone_es*n(e.phi))),e.lam-=i.lam0,i.over||(e.lam=At(e.lam)),i.fwd?(i.fwd(e,r),r.x=i.fr_meter*(i.a*r.x+i.x0),r.y=i.fr_meter*(i.a*r.y+i.y0)):r.x=r.y=v):N(-14),!L.last_errno&&isFinite(r.x)&&isFinite(r.y)||(r.x=r.y=v),r}function It(e,i){var r={lam:0,phi:0};return e.x<v&&e.y<v?(L.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,r),r.lam+=i.lam0,i.over||(r.lam=At(r.lam)),i.geoc&&t(t(r.phi)-E)>1e-12&&(r.phi=l(i.one_es*n(r.phi)))):r.lam=r.phi=v):N(-15),!L.last_errno&&isFinite(r.lam)&&isFinite(r.phi)||(r.lam=r.phi=v),r}function Pt(t,i,r,n){var s,o,a;for((t<0||t>=9)&&(t=3),s=1,a=0;a<t;a++)s*=10;return o=3600*s,function(a){var l,c,h,u,p="",d="",f="";return a===v||isNaN(a)?"":(a<0?(a=-a,(h=n||"")||(p="-")):h=r||"",c=(a=e(a*o+.5))/s%60,l=(a=e(a/(60*s)))%60,u=e(a/60)+"d",f=c.toFixed(t),f=(c=parseFloat(f))?(i?f:String(c))+'"':"",(c||l)&&2==(d=String(l)+"'").length&&i&&(d="0"+d),p+u+d+f+h)}}function Dt(t,e,i){var r,n,s,o,a,l;return"string"!=typeof t?ki:("string"!=typeof e?(n="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs",s=t,r=e):(n=t,s=e,r=i),l=kt(o=_t(n),a=_t(s)),r?l(r):{forward:l,inverse:kt(a,o)})}function kt(t,e){return function(i){var r=Array.isArray(i);return i=r?i.concat():[i.x,i.y],wt(t,e,i),r||(i={x:i[0],y:i[1]}),i}}function zt(t){var e=t.proj in Q?Q[t.proj].name:"",i=rt(t),r=Jt(t);return{PROJCS:{NAME:e?r.NAME+" / "+e:"unnamed",GEOGCS:r,PROJECTION:"custom_proj4",PARAMETER:[],UNIT:Zt(t),EXTENSION:["PROJ4",i+" +wktext"]}}}function Rt(t){var e=t.EXTENSION;return e&&"PROJ4"==e[0]?(e[1]||"").replace(" +wktext",""):null}Dt.WGS84="+proj=longlat +datum=WGS84",Dt.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 Lt=[],Ft=[];function Bt(t){return"string"==typeof t}function Ot(t){var e=Vt(t,Ft);return e||(e=function(t){return Rt(t)?Rt:null}(t)),e||qt("unsupported WKT definition: "+(t.NAME||"[unknown]")),e}function Nt(t){var e=Vt(t,Lt);return e||(e=zt),e||qt("unsupported projection: "+function(t){return jt(t)||"[unknown]"}(t)),e}function Vt(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 Y(t.params,"sproj")}function Gt(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 qt(t){throw new Error(t)}function $t(t){return{to_meter:t.UNIT[1]}}function Zt(t){return["Meter",t.to_meter||1]}function Wt(t,e){var i,r,n=t.DATUM,s=n.SPHEROID,o=function(t){var e,i={northamerican1983:"NAD83",newzealand1949:"nzgd49"},r=Ht(t.NAME);if(r in i)return i[r];for(var n=0;n<st.length&&Ht((e=st[n])[3])!=r&&Ht(e[0])!=r;n++);return e?e[0]:null}(n),a=function(t){var e,i={international1924:"intl"},r=Ht(t[0]);if(r in i)return i[r];if(/^grs1980/.test(r))return"GRS80";if("sphere"==r)return null;for(var n=0;n<lt.length&&Ht((e=lt[n])[3])!=r&&Ht(e[0])!=r;n++);return e?e[0]:null}(s),l=e&&e.aux_sphere,c=s[1],h=s[2];return Xt(t.UNIT,"degree"),l?i="+a="+s[1]:o?i="+datum="+o:a?i="+ellps="+a:(i="+a="+c,h>0&&(i+=" +rf="+h)),!n.TOWGS84||l||o||(i+=" +towgs84="+n.TOWGS84.join(",")),((r=t.PRIMEM?t.PRIMEM[1]:0)>0||r<0)&&(i+=" +pm="+r),i}function Ht(t){return(t||"").replace(/^(GCS|D)_/i,"").replace(/[ _]/g,"").toLowerCase()}function Xt(t,e){t&&t[0].toLowerCase()!=e&&qt("unexpected geographic units: "+geogcs.UNIT[0])}function Yt(t){return function(){return"+proj="+t}}function Kt(t){return function(e){var i,r;return[t.PROJECTION(e),t.PARAMETER(e),t.GEOGCS?t.GEOGCS(e):Wt(e.GEOGCS),(i=$t(e),r="",1!=i.to_meter&&(r="+to_meter="+i.to_meter),r),"+no_defs"].filter(function(t){return!!t}).join(" ")}}function Jt(t){return{NAME:ee(t),DATUM:Qt(t),PRIMEM:["Greenwich",0],UNIT:["degree",.017453292519943295]}}function Qt(t){var e={NAME:re(t),SPHEROID:te(t)},i=Y(t.params,"stowgs84");return/[1-9]/.test(i)&&(e.TOWGS84=i),e}function te(t){var e;return e=Y(t.params,"trf")?Y(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=le(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=ct(function(t){var e=ne(t),i=e?at(e):null;return(i?i.ellipse_id:Y(t.params,"sellps"))||""}(t));return e?e.name:"Unknown ellipsoid"}function re(t){var e=at(ne(t));return e&&e.name||"Unknown datum"}function ne(t){return Y(t.params,"sdatum")}function se(t){return Nt(t)(t)}function oe(t,e){return ae({PROJECTION:t,PARAMETER:De(e)})}function ae(t){return function(e){var i={GEOGCS:t.GEOGCS&&t.GEOGCS(e)||Jt(e),PROJECTION:Bt(t.PROJECTION)?t.PROJECTION:t.PROJECTION(e),PARAMETER:t.PARAMETER(e),UNIT:Zt(e)};return i.NAME=t.NAME&&t.NAME(e,i)||function(t,e){var i=le(t);return i||e.GEOGCS.NAME+" / "+e.PROJECTION}(e,i),{PROJCS:i}}}function le(t){var e;return Y(t.params,"tinit")&&(e=mt(Y(t.params,"sinit"))),e?e.comment:""}function ce(t,e,i){var r=ue(e),n=function(t,e){return Kt({PROJECTION:Yt(t),PARAMETER:Pe(e)})}(t,i);de(r,n)}function he(t,e,i){fe(pe(t),oe(e,i))}function ue(t){var e=Ut(t).map(Gt);return function(t){var i=t.PROJECTION[0];return e.indexOf(Gt(i))>-1}}function pe(t){return function(e){var i=jt(e);return i&&i==t}}function de(t,e){"function"!=typeof t&&qt("Missing WKT parser test"),"function"!=typeof e&&qt("Missing WKT parse function"),Ft.push([t,e])}function fe(t,e){"function"!=typeof t&&qt("Missing WKT maker test"),"function"!=typeof e&&qt("Missing WKT maker function"),Lt.push([t,e])}de(function(t){return me.test(Gt(t.NAME))},function(t){return Kt({PROJECTION:Yt("utm"),PARAMETER:function(t){var e=me.exec(Gt(t.NAME)),i="+zone="+e[1];return"s"==e[2].toLowerCase()&&(i+=" +south"),i}})(t)}),de(function(t){return _e.test(Gt(t.NAME))},function(t){return Kt({PROJECTION:Yt("ups"),PARAMETER:function(t){var e=_e.exec(Gt(t.NAME));return"south"==e[1].toLowerCase()?"+south":""}})(t)}),fe(pe("utm"),function(t){return ae({NAME:ge,PROJECTION:function(){return"Transverse_Mercator"},PARAMETER:ve})(t)}),fe(pe("ups"),function(t){return ae({NAME:ye,PROJECTION:function(){return"Polar_Stereographic"},PARAMETER:xe})(t)});var me=/UTM_zone_([0-9]{1,2})(N|S)/i,_e=/UPS_(North|South)/i;function ge(t,e){return e.GEOGCS.NAME+" / UTM zone "+Y(t.params,"szone")+(Y(t.params,"tsouth")?"S":"N")}function ye(t,e){return e.GEOGCS.NAME+" / UPS "+(Y(t.params,"tsouth")?"South":"North")}function ve(t){return[["latitude_of_origin",0],["central_meridian",180*t.lam0/b],["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 Y(t.params,"tlat_ts")&&0!=Y(t.params,"dlat_ts")}function we(t){return 0===t.es&&6378137==t.a}de(ue("Mercator_2SP,Mercator_1SP,Mercator,Mercator_Auxiliary_Sphere"),Kt({GEOGCS:function(t){var e=function(t){return/(Web_Mercator|Pseudo_Mercator)/i.test(Gt(t.NAME))}(t)?{aux_sphere:!0}:null;return Wt(t.GEOGCS,e)},PROJECTION:Yt("merc"),PARAMETER:function(t){return Pe(function(t){var e=Ee(t,"standard_parallel_1");return e&&0!=e[1]}(t)?"lat_ts,lat_0b":"lat_tsb,lat_ts")(t)}})),fe(pe("merc"),ae({GEOGCS:function(t){return we(t)?Jt(_t("+proj=longlat +datum=WGS84")):null},PROJECTION:function(t){return be(t)?"Mercator_2SP":"Mercator_1SP"},PARAMETER:function(t){return De(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"]],Te={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"]},Ce={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 Me(t,e,i){for(var r=0;r<i.length;r++)if(i[r][e]===t)return i[r];return null}function Ae(t,e,i){var r=null;return!(r=Me(t=t.toLowerCase(),e,i))&&t in Ce&&(r=Me(Ce[t],e,i)),r}function Ee(t,e){for(var i,r=t.PARAMETER||[],n=0;n<r.length;n++)if(e===(i=r[n][0].toLowerCase())||e===Ce[i])return r[n];return null}function Ie(t){var e=null;return t&&(e=Ut(t).reduce(function(t,e){var i=Te[e];return i||qt("missing parameter rule: "+e),t.push(i),t},[])),(e||[]).concat(Se)}function Pe(t){return function(e){var i=[],r=Ie(t),n=$t(e);return(e.PARAMETER||[]).forEach(function(t){var e,s,o=Ae(t[0],1,r);o?(e=function(t,e,i){var r=t[0];if("m"==t[2]&&(e*=i.to_meter),!("x_0,y_0,lat_0,lon_0".indexOf(r)>-1&&0===e||"k_0"==r&&1==e))return"+"+r+"="+e}(o,t[1],n),e&&i.push(e)):(s="unhandled parameter: "+t[0],console.error("[wkt] "+s))}),i.join(" ")}}function De(t){return function(e){var i=[],r=Ie(t);return Object.keys(e.params).forEach(function(t){var n,s=Ae(t,0,r);s&&s[1]&&(n=Y(e.params,"s"+t),i.push(function(t,e,i){var r,n=t[2];return r="m"==n?parseFloat(e)/i:"f"==n?parseFloat(e):W(e),[t[1],r]}(s,n,e.to_meter)))}),i}}function ke(t){return!("lat_1"in t.params&&"lat_2"in t.params)}function ze(t){return"omerc"==jt(t)&&("alpha"in t.params||"gamma"in t.params)}function Re(t){return ze(t)&&("no_uoff"in t.params||"no_off"in t.params)}function Le(t){return Y(t.params,"tlat_ts")}function Fe(t){var e=JSON.stringify(Oe(t));return e=(e=e.replace(/\["([A-Z0-9]+)",/g,"$1[")).replace(/"(EAST|NORTH|SOUTH|WEST)"/g,"$1")}function Be(t){return"NAME,PROJCS,GEOGCS,GEOCCS,DATUM,SPHEROID,PRIMEM,PROJECTION,PARAMETER,UNIT,AXIS".indexOf(t)+1||999}function Oe(t,e){var i,r=[];return e=e||0,function(t){return Object.keys(t).sort(function(t,e){return Be(t)-Be(e)})}(t).forEach(function(n){var s=t[n];!function(t){return!!t&&"object"==typeof t&&!Array.isArray(t)}(s)?"NAME"==n?r.push(Bt(s)?s:s[0]):"PARAMETER"==n||"AXIS"==n?s.forEach(function(t){r.push([n].concat(t))}):Bt(s)?r.push([n,s]):Array.isArray(s)?r.push([n].concat(s)):((i={})[n]=s,qt("Incorrectly formatted WKT element: "+JSON.stringify(i))):r.push([n].concat(Oe(s,e+1)))}),0===e&&1==r.length&&(r=r[0]),r}function Ne(t){var e={};return Ve(t).forEach(function(t){Ge(t,e)}),e}function Ve(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){qt("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 Ge(t,e){var i,r=t[0];if("GEOGCS"==r||"GEOCCS"==r||"PROJCS"==r||"DATUM"==r||"VERTCS"==r)for(e[r]={NAME:t[1]},i=2;i<t.length;i++){if(!Array.isArray(t[i]))throw qt("WKT parse error");Ge(t[i],e[r])}else"AXIS"==r||"PARAMETER"==r?(r in e==0&&(e[r]=[]),e[r].push(t.slice(1))):e[r]=t.slice(1);return e}de(ue("Lambert_Conformal_Conic,Lambert_Conformal_Conic_1SP,Lambert_Conformal_Conic_2SP"),Kt({PROJECTION:Yt("lcc"),PARAMETER:function(t){return Pe(function(t){return!Ee(t,"standard_parallel_2")}(t)?"lat_1c":"lat_0b,lat_1,lat_2")(t)}})),fe(pe("lcc"),ae({PROJECTION:function(t){return ke(t)?"Lambert_Conformal_Conic_1SP":"Lambert_Conformal_Conic_2SP"},PARAMETER:function(t){return De(ke(t)?"lat_1c,lat_0c":"lat_0b,lat_1,lat_2")(t)}})),de(ue("Hotine_Oblique_Mercator,Hotine_Oblique_Mercator_Azimuth_Natural_Origin"),Kt({PROJECTION:Yt("omerc"),PARAMETER:function(t){return Pe("alpha,gamma,lonc")(t)+" +no_uoff"}})),fe(Re,oe("Hotine_Oblique_Mercator","alpha,gamma,lonc")),ce("omerc","Oblique_Mercator,Hotine_Oblique_Mercator_Azimuth_Center","alpha,gamma,lonc"),fe(function(t){return ze(t)&&!Re(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"==jt(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(ue("Stereographic,Polar_Stereographic,Stereographic_North_Pole,Stereographic_South_Pole"),Kt({PROJECTION:Yt("stere"),PARAMETER:function(t){var e=Pe("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}})),fe(pe("stere"),ae({PROJECTION:function(t){return Le(t)?"Polar_Stereographic":"Stereographic"},PARAMETER:function(t){return Le(t)?De("lat_tsb,lat_0c")(t):De("lat_0b")(t)}})),he("vandg","VanDerGrinten"),de(ue("VanDerGrinten,Van_der_Grinten_I"),Kt({PROJECTION:Yt("vandg"),PARAMETER:function(t){var e=Pe("")(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),he(t[0],t[1].split(",")[0],e)});var Ue,qe,$e={};function Ze(t,e,i){var r;return e>=1e-7?i*(t/(1-(r=e*t)*r)-.5/e*d((1-r)/(1+r))):t+t}function We(t,e,i){return e/h(1-i*t*t)}function He(e,n,o){var a,l,u,p,m,_,g,y,x,b,w,S,T,C;e.fwd=function(t,n){var s,o=t.lam;(s=u-(g?l*Ze(i(t.phi),e.e,e.one_es):m*i(t.phi)))<0&&V(),s=p*h(s),n.x=s*i(o*=l),n.y=_-s*r(o)},e.inv=function(n,o){var h=n.x,y=_-n.y,x=f(h,y);0!=x?(l<0&&(x=-x,h=-h,y=-y),o.phi=x/p,g?(o.phi=(u-o.phi*o.phi)/l,t(a-t(o.phi))>1e-7?(o.phi=function(e,n,o){var a,l,c,h,u,p,f=15,m=1e-7,_=1e-10;if(a=s(.5*e),n<m)return a;p=f;do{a+=u=.5*(h=1-(c=n*(l=i(a)))*c)*h/r(a)*(e/o-l/h+.5/n*d((1-c)/(1+c)))}while(t(u)>_&&--p);return p?a:v}(o.phi,e.e,e.one_es))==v&&j():o.phi=o.phi<0?-E:E):t(o.phi=(u-o.phi*o.phi)/m)<=1?o.phi=s(o.phi):o.phi=o.phi<0?-E:E,o.lam=c(h,y)/l):(o.lam=0,o.phi=l>0?E:-E)},t(n+o)<R&&U(-21),l=x=i(n),y=r(n),b=t(n-o)>=R,(g=e.es>0)?(Xe(e.es),C=We(x,y,e.es),T=Ze(x,e.e,e.one_es),b&&(S=We(x=i(o),y=r(o),e.es),w=Ze(x,e.e,e.one_es),l=(C*C-S*S)/(w-T)),a=1-.5*e.one_es*d((1-e.e)/(1+e.e))/e.e,_=(p=1/l)*h((u=C*C+l*T)-l*Ze(i(e.phi0),e.e,e.one_es))):(b&&(l=.5*(l+i(o))),_=(p=1/l)*h((u=y*y+(m=l+l)*x)-m*i(e.phi0)))}function Xe(t){var e,i=.046875,r=.01953125,n=.01068115234375,s=[];return s[0]=1-t*(.25+t*(i+t*(r+t*n))),s[1]=t*(.75-t*(i+t*(r+t*n))),s[2]=(e=t*t)*(.46875-t*(.013020833333333334+.007120768229166667*t)),s[3]=(e*=t)*(.3645833333333333-.005696614583333333*t),s[4]=e*t*.3076171875,s}function Ye(t,e,i,r){return i*=e,e*=e,r[0]*t-i*(r[1]+e*(r[2]+e*(r[3]+e*r[4])))}function Ke(e,n,s){var o,a,l,c=1/(1-n);l=e;for(var u=10;u>0;--u)if(a=1-n*(o=i(l))*o,l-=a=(Ye(l,o,r(l),s)-e)*(a*h(a))*c,t(a)<1e-11)return l;return N(L),l}function Je(e){var i=t(e);return i>=1?(i>1.00000000000001&&N(-19),e<0?-E:E):s(e)}function Qe(e){var i=t(e);return i>=1?(i>1.00000000000001&&N(-19),e<0?b:0):a(e)}function ti(t){return t<=0?0:h(t)}function ei(e,i){return t(e)<1e-50&&t(i)<1e-50?0:c(e,i)}function ii(e){var n=e.opaque||{mode:0};e.inv=function(e,s){var o,l,c,h,p,d,f,m,_,g,y,v,x,w,S,T,C,M=1e-12,A=0;if(t(e.x)<M&&t(e.y)<M)return s.phi=0,void(s.lam=0);s.phi=e.y,s.lam=e.x;do{o=0;do{for(v=i(.5*s.lam),S=r(.5*s.lam),x=i(s.phi),c=1-(l=(w=r(s.phi))*S)*l,h=2*(l=a(l)/u(c,1.5))*c*w*v,p=l*c*x,d=2*(v*S*x*w/c-l*x*v),f=w*w*v*v/c+l*w*S*x*x,m=x*x*S/c+l*v*v*w,_=.5*(x*w*v/c-l*x*w*w*v*S),n.mode&&(h=.5*(h+s.lam*n.cosphi1),p=.5*(p+s.phi),d*=.5,f=.5*(f+n.cosphi1),m=.5*(m+1),_*=.5),h-=e.x,y=((p-=e.y)*d-h*m)/(g=d*_-m*f),g=(h*_-p*f)/g;y>b;)y-=b;for(;y<-b;)y+=b;s.phi-=g,s.lam-=y}while((t(g)>M||t(y)>M)&&o++<10);s.phi>E&&(s.phi-=2*(s.phi-E)),s.phi<-E&&(s.phi-=2*(s.phi+E)),t(t(s.phi)-E)<M&&!n.mode&&(s.lam=0),(l=a(r(s.phi)*r(c=.5*s.lam)))?(T=2*l*r(s.phi)*i(c)*(C=1/i(l)),C*=l*i(s.phi)):T=C=0,n.mode&&(T=.5*(T+s.lam*n.cosphi1),C=.5*(C+s.phi))}while((t(e.x-T)>M||t(e.y-C)>M)&&A++<20)},e.fwd=function(t,e){var s,o;(o=a(r(t.phi)*r(s=.5*t.lam)))?(e.x=2*o*r(t.phi)*i(s)*(e.y=1/i(o)),e.y*=o*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 ri(e,r,n){e.es=0,e.fwd=function(e,s){var o,a,l=2.4674011002723395;s.y=r?E*i(e.phi):e.phi,(o=t(e.lam))>=1e-10?(n&&o>=E?s.x=h(l-e.phi*e.phi+1e-10)+o-E:(a=.5*(l/o+o),s.x=o-a+h(a*a-s.y*s.y)),e.lam<0&&(s.x=-s.x)):s.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 si(t,e){var r=t+t;return t+e[0]*i(r)+e[1]*i(r+r)+e[2]*i(r+r+r)}function oi(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 ai(e){var s,o,a,u,p,g,y=[],x=[],b=[],w=[];function S(t,e){for(var n,s=2*r(2*e),o=t.length-1,a=t[o],l=0;--o>=0;)n=s*a-l+t[o],l=a,a=n;return e+n*i(2*e)}function T(t,e,n){for(var s,o,a=i(e),l=r(e),c=m(n),h=_(n),u=2*l*h,p=-2*a*c,d=t.length-1,f=t[d],g=0,y=0,v=0;--d>=0;)s=y,o=g,f=u*(y=f)-s-p*(g=v)+t[d],v=p*y-o+u*g;return[(u=a*h)*f-(p=l*c)*v,u*v+p*f]}e.es<=0&&U(-34),p=u=(a=e.es/(1+h(1-e.es)))/(2-a),y[0]=u*(2+u*(-2/3+u*(u*(116/45+u*(26/45+u*(-2854/675)))-2))),x[0]=u*(u*(2/3+u*(4/3+u*(-82/45+u*(32/45+u*(4642/4725)))))-2),p*=u,y[1]=p*(7/3+u*(u*(-227/45+u*(2704/315+u*(2323/945)))-1.6)),x[1]=p*(5/3+u*(-16/15+u*(-13/9+u*(904/315+u*(-1522/945))))),p*=u,y[2]=p*(56/15+u*(-136/35+u*(-1262/105+u*(73814/2835)))),x[2]=p*(-26/15+u*(34/21+u*(1.6+u*(-12686/2835)))),p*=u,y[3]=p*(4279/630+u*(-332/35+u*(-399572/14175))),x[3]=p*(1237/630+u*(u*(-24832/14175)-2.4)),p*=u,y[4]=p*(4174/315+u*(-144838/6237)),x[4]=p*(-734/315+u*(109598/31185)),p*=u,y[5]=p*(601676/22275),x[5]=p*(444337/155925),p=u*u,s=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,g=S(x,e.phi0),o=-s*(g+function(t,e){for(var n,s=2*r(e),o=t.length-1,a=t[o],l=0;--o>=0;)n=s*a-l+t[o],l=a,a=n;return i(e)*n}(w,2*g)),e.fwd=function(e,a){var l,h,u,p,m,_=e.phi,g=e.lam;_=S(x,_),l=i(_),h=r(_),p=i(g),u=r(g),_=c(l,u*h),g=c(p*h,f(l,h*u)),g=function(e){var i=t(e);return i=function(t){var e=1+t,i=e-1;return 0===i?t:t*d(e)/i}(i*(1+i/(f(1,i)+1))),e<0?-i:i}(n(g)),m=T(w,2*_,2*g),_+=m[0],g+=m[1],t(g)<=2.623395162778?(a.y=s*_+o,a.x=s*g):a.x=a.y=v},e.inv=function(e,n){var a,h,u,p,d,_=e.y,g=e.x;_=(_-o)/s,t(g/=s)<=2.623395162778?(_+=(d=T(b,2*_,2*g))[0],g+=d[1],g=l(m(g)),a=i(_),h=r(_),p=i(g),u=r(g),g=c(p,u*h),_=c(a*u,f(p,u*h)),n.phi=S(y,_),n.lam=g):n.phi=n.lam=v}}function li(e){var n;e.es?(n=Xe(e.es),e.fwd=function(t,s){var o,a;s.y=Ye(t.phi,o=i(t.phi),a=r(t.phi),n),s.x=t.lam*a/h(1-e.es*o*o)},e.inv=function(s,o){var a=t(o.phi=Ke(s.y,e.es,n));a<E?(a=i(o.phi),o.lam=s.x*h(1-e.es*a*a)/r(o.phi)):a-R<E?o.lam=0:j()}):ci(e,0,1)}function ci(e,n,s){var o,a;o=(a=h((n+1)/s))/(n+1),e.es=0,e.fwd=function(e,l){var c,h,u;if(n){for(c=s*i(e.phi),u=8;u&&(e.phi-=h=(n*e.phi+i(e.phi)-c)/(n+r(e.phi)),!(t(h)<1e-7));--u);u||V()}else e.phi=1!=s?Je(s*i(e.phi)):e.phi;l.x=o*e.lam*(n+r(e.phi)),l.y=a*e.phi},e.inv=function(t,e){t.y/=a,e.phi=n?Je((n*t.y+i(t.y))/s):1!=s?Je(i(t.y)/s):t.y,e.lam=t.x/(o*(n+r(t.y)))}}function hi(t){pi(t,ui(0,E))}function ui(t,e){var r=i(e),n=e+e,s=h(P*r/(n+i(n)));return{C_x:2*s/b,C_y:s/r,C_p:n+i(n)}}function pi(e,n){e.fwd=function(e,s){var o,a,l;for(o=n.C_p*i(e.phi),l=10;l&&(e.phi-=a=(e.phi+i(e.phi)-o)/(1+r(e.phi)),!(t(a)<1e-7));--l);l?e.phi*=.5:e.phi=e.phi<0?-E:E,s.x=n.C_x*e.lam*r(e.phi),s.y=n.C_y*i(e.phi)},e.inv=function(e,s){s.phi=Je(e.y/n.C_y),s.lam=e.x/(n.C_x*r(s.phi)),t(s.lam)-b<R?(s.phi+=s.phi,s.phi=Je((s.phi+i(s.phi))/n.C_p)):s.lam=s.phi=v},e.es=0}function di(r,n){var o,a,l,c,p,d=[[0,-1],[1,0]],f=[[-1,0],[0,-1]],m=[[0,1],[-1,0]],_=[[[1,0],[0,1]],d,f,m,m,f,d],x=1e-15;function w(r,n){var o=r.lam,a=r.phi,l=s(2/3);if(t(a)<=l)n.x=o,n.y=3*b/8*i(a);else{var c,u=h(3*(1-t(i(a)))),p=e(2*o/b+2);p>=4&&(p=3),c=-3*A+E*p,n.x=c+(o-c)*u,n.y=T(a)*A*(2-u)}}function S(i,r){var n=i.x,o=i.y,a=A;if(t(o)<=a)r.lam=n,r.phi=s(8*o/(3*b));else if(t(o)<E){var l,c,h=e(2*n/b+2);h>=4&&(h=3),l=-3*A+E*h,c=2-4*t(o)/b,r.lam=l+(n-l)/c,r.phi=T(o)*s(1-u(c,2)/3)}else r.lam=-b,r.phi=T(o)*E}function T(t){return t>0?1:t<0?-1:0}function C(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,i){var r,n,s,o,a,l=0,c=t.length;for(a=0;a<c;a++)if(e==t[a][0]&&i==t[a][1])return!0;for(r=t[0][0],n=t[0][1],a=1;a<c;a++)s=t[a%c][0],o=t[a%c][1],i>g(n,o)&&i<=y(n,o)&&e<=y(r,s)&&n!=o&&(r==s||e<=(i-n)*(s-r)/(o-n)+r)&&l++,r=s,n=o;return l%2!=0}(p,t,e)}function I(e,r,n){if(n)return si(r,c);var o=Ze(i(r),e.e,1-e.es)/l;return t(o)>1&&(o=T(o)),s(o)}function P(t,e,i,r){var n,s,o,a,l,c,h=0,u=function(t,e,i,r,n){var s,o={};if(o.x=t,o.y=e,n){if(e>A)o.region="north",o.x=-3*A+i*E,o.y=E,t-=i*E;else{if(!(e<-A))return o.region="equatorial",o.cn=0,o;o.region="south",o.x=-3*A+r*E,o.y=-E,t-=r*E}"north"==o.region?o.cn=e>=-t-A-x&&e<t+5*A-x?(i+1)%4:e>-t-A+x&&e>=t+5*A-x?(i+2)%4:e<=-t-A+x&&e>t+5*A+x?(i+3)%4:i:"south"==o.region&&(o.cn=e<=t+A+x&&e>-t-5*A+x?(r+1)%4:e<t+A-x&&e<=-t-5*A+x?(r+2)%4:e>=t+A-x&&e<-t-5*A-x?(r+3)%4:r)}else{if(e>A)o.region="north",s=E;else{if(!(e<-A))return o.region="equatorial",o.cn=0,o;o.region="south",s=-E}t<-E?(o.cn=0,o.x=-3*A,o.y=s):t>=-E&&t<0?(o.cn=1,o.x=-A,o.y=s):t>=0&&t<E?(o.cn=2,o.x=A,o.y=s):(o.cn=3,o.x=3*A,o.y=s)}return o}(t.x,t.y,e,i,r);if("equatorial"==u.region)return t.x=u.x,void(t.y=u.y);n=[t.x,t.y],s=[u.x,u.y],r?"north"==u.region?(h=e,c=_[C(-1*(u.cn-h))]):(h=i,c=_[C(u.cn-h)]):"north"==u.region?(h=e,c=_[C(u.cn-h)]):(h=i,c=_[C(-1*(u.cn-h))]),a=function(t,e){return[t[0]-e[0],t[1]-e[1]]}(n,s),l=function(t,e){var i,r,n=[0,0];for(i=0;i<2;i++)for(r=0;r<2;r++)n[i]+=t[i][r]*e[r];return n}(c,a),o=function(t,e){return[t[0]+e[0],t[1]+e[1]]}(l,[-3*A+(r?u.cn:0)*E,E]),t.x=o[0],t.y=o[1]}n?(o=Y(r.params,"inorth_square"),a=Y(r.params,"isouth_square"),(o<0||o>3)&&U(-47),(a<0||a>3)&&U(-47),p=[[-b-x,A+x],[o*E-b-x,A+x],[o*E-b-x,3*A+x],[(o+1)*E-b+x,3*A+x],[(o+1)*E-b+x,A+x],[b+x,A+x],[b+x,-A-x],[(a+1)*E-b+x,-A-x],[(a+1)*E-b+x,-3*A-x],[a*E-b-x,-3*A-x],[a*E-b-x,-A-x],[-b-x,-A-x]],0!=r.es?(c=ni(r.es),l=Ze(1,r.e,r.one_es),r.a=r.a*h(.5*l),r.ra=1/r.a,r.fwd=function(t,e){return t.phi=I(r,t.phi,0),w(t,e),P(e,o,a,0)},r.inv=function(t,e){if(!M(t.x,t.y))return e.lam=v,e.phi=v,void N(-15);P(t,o,a,1),S(t,e),e.phi=I(r,e.phi,1)}):(r.fwd=function(t,e){w(t,e),P(e,o,a,0)},r.inv=function(t,e){if(!M(t.x,t.y))return e.lam=v,e.phi=v,void N(-15);P(t,o,a,1),S(t,e)})):(p=[[-b-x,A],[-3*A,E+x],[-E,A+x],[-A,E+x],[0,A+x],[A,E+x],[E,A+x],[3*A,E+x],[b+x,A],[b+x,-A],[3*A,-E-x],[E,-A-x],[A,-E-x],[0,-A-x],[-A,-E-x],[-E,-A-x],[-3*A,-E-x],[-b-x,-A]],0!=r.es?(c=ni(r.es),l=Ze(1,r.e,r.one_es),r.a=r.a*h(.5*l),r.ra=1/r.a,r.fwd=function(t,e){t.phi=I(r,t.phi,0),w(t,e)},r.inv=function(t,e){if(!M(t.x,t.y))return e.lam=v,e.phi=v,void N(-15);S(t,e),e.phi=I(r,e.phi,1)}):(r.fwd=function(t,e){w(t,e)},r.inv=function(t,e){if(!M(t.x,t.y))return e.lam=v,e.phi=v,void N(-15);S(t,e)}))}function fi(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 mi(t,e,i){return e*=i,n(.5*(E-t))/u((1-e)/(1+e),.5*i)}function _i(e,r){var n,s,o=.5*r,a=E-2*l(e),c=15;do{n=r*i(a),a+=s=E-2*l(e*u((1-n)/(1+n),o))-a}while(t(s)>1e-10&&--c);return c<=0&&N(-18),a}function gi(t,e){var i,r,n,s=e.length-1;for(r=e[s][0],n=e[s][1];--s>=0;)i=r,r=e[s][0]+t.r*i-t.i*n,n=e[s][1]+t.r*n+t.i*i;return{r:t.r*r-t.i*n,i:t.r*n+t.i*r}}function yi(t,e,i){var r,n,s,o,a,l=!0,c=e.length-1;for(n=o=e[c][0],r=s=e[c][1];--c>=0;)l?l=!1:(o=n+t.r*(a=o)-t.i*s,s=r+t.r*s+t.i*a),n=e[c][0]+t.r*(a=n)-t.i*r,r=e[c][1]+t.r*r+t.i*a;return i.r=n+t.r*o-t.i*s,i.i=r+t.r*s+t.i*o,{r:t.r*n-t.i*r,i:t.r*r+t.i*n}}function vi(e,s){var o,a,h,p,d=1e-12;0!=e.es?(o=e.e*i(e.phi0),a=2*l(n(.5*(E+e.phi0))*u((1-o)/(1+o),.5*e.e))-E):a=e.phi0,p=i(a),h=r(a),e.inv=function(o,a){var m,_,g,y,x,b,w,S={},T={},C={},M=0,A=0,I=0,P=0;for(S.r=o.x,S.i=o.y,m=20;m&&((_=yi(S,s,T)).r-=o.x,_.i-=o.y,g=T.r*T.r+T.i*T.i,C.r=-(_.r*T.r+_.i*T.i)/g,C.i=-(_.i*T.r-_.r*T.i)/g,S.r+=C.r,S.i+=C.i,!(t(C.r)+t(C.i)<=d));--m);if(m){if(M=f(S.r,S.i),y=2*l(.5*M),A=i(y),I=r(y),a.lam=e.lam0,t(M)<=d)return a.lam=0,void(a.phi=e.phi0);for(P=x=Je(I*p+S.i*A*h/M),m=20;m&&(b=e.e*i(P),P+=w=2*l(n(.5*(E+x))*u((1+b)/(1-b),.5*e.e))-E-P,!(t(w)<=d));--m);}m?(a.phi=P,a.lam=c(S.r*A,M*h*I-S.i*p*A)):a.lam=a.phi=v},e.fwd=function(t,o){var a,c,d,f,m,_,g,y={};a=i(t.lam),c=r(t.lam),d=e.e*i(t.phi),f=2*l(n(.5*(E+t.phi))*u((1-d)/(1+d),.5*e.e))-E,m=i(f),_=r(f),g=2/(1+p*m+h*_*c),y.r=g*_*a,y.i=g*(h*m-p*_*c),y=gi(y,s),o.x=y.r,o.y=y.i}}function xi(e,n,o,a){var l,u,p,d,m,_,g,y,v,x,b,w,S=!isNaN(o)&&!isNaN(a);n<=0&&U(-30),S&&(v=r(a),x=i(a),w=r(o),b=i(o)),t(t(e.phi0)-E)<R?l=e.phi0<0?1:0:t(e.phi0)<R?l=2:(l=3,u=i(e.phi0),p=r(e.phi0)),_=n/e.a,m=1/(d=1+_),g=(d+1)*(y=1/_),e.fwd=function(t,e){var n,s,o,a,c;switch(o=i(t.phi),s=r(t.phi),n=r(t.lam),l){case 3:e.y=u*o+p*s*n;break;case 2:e.y=s*n;break;case 1:e.y=-o;break;case 0:e.y=o}switch(e.y<m&&V(),e.y=_/(d-e.y),e.x=e.y*s*i(t.lam),l){case 3:e.y*=p*o-u*s*n;break;case 2:e.y*=o;break;case 0:n=-n;case 1:e.y*=s*n}S&&(c=1/((a=e.y*v+e.x*x)*b*y+w),e.x=(e.x*v-e.y*x)*w*c,e.y=a*c)},e.inv=function(r,n){var o,a,m,y,T,C;if(S&&(C=1/(_-r.y*b),y=_*r.x*C,T=_*r.y*w*C,r.x=y*v+T*x,r.y=T*v-y*x),o=f(r.x,r.y),(m=1-o*o*g)<0&&j(),m=(d-h(m))/(_/o+o/_),a=h(1-m*m),t(o)<=R)n.lam=0,n.phi=e.phi0;else{switch(l){case 3:n.phi=s(a*u+r.y*m*p/o),r.y=(a-u*i(n.phi))*o,r.x*=m*p;break;case 2:n.phi=s(r.y*m/o),r.y=a*o,r.x*=m;break;case 0:n.phi=s(a),r.y=-r.y;break;case 1:n.phi=-s(a)}n.lam=c(r.x,r.y)}},e.es=0}function bi(t,e){var i=.79788456,r=.1013211836*(e?2:4);t.es=0,t.fwd=function(t,e){e.x=i*t.lam*(1-r*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-r*e.phi*e.phi))}}function wi(t,e,n){t.es=0,t.fwd=function(t,s){t.phi=Je(.883883476*i(t.phi)),s.x=e*t.lam*r(t.phi),s.x/=r(t.phi*=.333333333333333),s.y=n*i(t.phi)},t.inv=function(t,s){s.phi=Je(t.y/n),s.lam=t.x*r(s.phi)/e,s.phi*=3,s.lam/=r(s.phi),s.phi=Je(1.13137085*i(s.phi))}}function Si(t,e){var i=e?1.5:2,r=e?.5:1,n=1.01346,s=1.2158542;t.es=0,t.fwd=function(t,e){e.x=n*t.lam*(i-r*h(1+s*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-r*h(1+s*e.phi*e.phi)))}}function Ti(e,r){var n,s,o,a,l,c=1.732050807568877;r?(o=.44329,a=.80404,n=6,s=5.61125,l=3):(o=1.01346,a=.9191,n=4,s=2.147143718212938,l=2),e.es=0,e.fwd=function(e,r){var u,p,f,m;for(u=s*i(e.phi),e.phi*=1.10265779,m=10;m&&(p=h(1+e.phi*e.phi),e.phi-=f=((n-p)*e.phi-d(e.phi+p)-u)/(n-2*p),!(t(f)<1e-10));--m);m||(e.phi=u<0?-c:c),r.x=o*e.lam*(l-h(1+e.phi*e.phi)),r.y=a*e.phi},e.inv=function(t,e){var i;e.phi=t.y/a,i=h(1+e.phi*e.phi),e.lam=t.x/(o*(l-i)),e.phi=Je(((n-i)*e.phi-d(e.phi+i))/s)}}function Ci(e){return function(s){!function(e,s){var o,a,u,p,d,m,_,g,y,v,x=1e-10;switch(Y(e.params,"tlat_1")&&Y(e.params,"tlat_2")?(u=Y(e.params,"rlat_1"),p=Y(e.params,"rlat_2"),g=.5*(p+u),(t(o=.5*(p-u))<x||t(g)<x)&&U(-42)):U(-41),s){case"TISSOT":d=i(g),a=r(o),_=h(((m=d/a+a/d)-2*i(e.phi0))/d);break;case"MURD1":m=i(o)/(o*n(g))+g,_=m-e.phi0,d=i(g);break;case"MURD2":m=(a=h(r(o)))/n(g),_=m+n(g-e.phi0),d=i(g)*a;break;case"MURD3":m=o/(n(g)*n(o))+g,_=m-e.phi0,d=i(g)*i(o)*n(o)/(o*o);break;case"EULER":d=i(g)*i(o)/o,m=(o*=.5)/(n(o)*n(g))+g,_=m-e.phi0;break;case"PCONIC":d=i(g),v=r(o),y=1/n(g),t(o=e.phi0-g)-x>=E&&U(-43),_=v*(y-n(o));break;case"VITK1":d=(a=n(o))*i(g)/o,m=o/(a*n(g))+g,_=m-e.phi0}function b(t,e){var o;switch(s){case"MURD2":o=m+n(g-t.phi);break;case"PCONIC":o=v*(y-n(t.phi-g));break;default:o=m-t.phi}e.x=o*i(t.lam*=d),e.y=_-o*r(t.lam)}function w(t,e){var i;switch(i=f(t.x,t.y=_-t.y),d<0&&(i=-i,t.x=-t.x,t.y=-t.y),e.lam=c(t.x,t.y)/d,s){case"PCONIC":e.phi=l(y-i/v)+g;break;case"MURD2":e.phi=g-l(i-m);break;default:e.phi=m-i}}e.inv=w,e.fwd=b,e.es=0}(s,e)}}function Mi(e,o){var a,p,d,m,_,g,y,v,x=1e-10;if(v=t((p=t(e.phi0))-E)<x?e.phi0<0?0:1:p>x?2:3,o=t(o),e.es){switch(v){case 1:case 0:t(o-E)<x?y=2*e.k0/h(u(1+e.e,1+e.e)*u(1-e.e,1-e.e)):(y=r(o)/mi(o,p=i(o),e.e),p*=e.e,y/=h(1-p*p));break;case 3:case 2:p=i(e.phi0),a=2*l(b(e.phi0,p,e.e))-E,p*=e.e,y=2*e.k0*r(e.phi0)/h(1-p*p),_=i(a),g=r(a)}e.fwd=function(t,n){var s,o,a,c,h,u=0,p=0;switch(s=r(t.lam),o=i(t.lam),h=i(t.phi),(2==v||3==v)&&(u=i(a=2*l(b(t.phi,h,e.e))-E),p=r(a)),v){case 2:c=y/(g*(1+_*u+g*p*s)),n.y=c*(g*u-_*p*s),n.x=c*p;break;case 3:c=y/(1+p*s),n.y=c*u,n.x=c*p;break;case 0:t.phi=-t.phi,s=-s,h=-h;case 1:n.x=y*mi(t.phi,h,e.e),n.y=-n.x*s}n.x=n.x*o},e.inv=function(o,a){a.phi;var h,p,d,m,x=0,b=0,w=0,S=0;switch(d=f(o.x,o.y),v){case 2:case 3:h=r(x=2*c(d*g,y)),p=i(x),b=s(0==d?h*_:h*_+o.y*p*g/d),x=n(.5*(E+b)),o.x*=p,o.y=d*g*h-o.y*_*p,S=E,w=.5*e.e;break;case 1:o.y=-o.y;case 0:b=E-2*l(x=-d/y),S=-E,w=-.5*e.e}for(m=0;m<8;m++,b=a.phi)if(p=e.e*i(b),a.phi=2*l(x*u((1+p)/(1-p),w))-S,t(b-a.phi)<1e-10)return 0==v&&(a.phi=-a.phi),void(a.lam=0==o.x&&0==o.y?0:c(o.x,o.y));j()}}else{switch(v){case 2:d=i(e.phi0),m=r(e.phi0);case 3:y=2*e.k0;break;case 0:case 1:y=t(o-E)>=x?r(o)/n(A-.5*o):2*e.k0}e.fwd=function(e,s){var o=e.phi,a=i(o),l=r(o),c=r(e.lam),h=i(e.lam);switch(v){case 3:case 2:s.y=3==v?1+l*c:1+d*a+m*l*c,s.y<=x&&V(),s.x=(s.y=y/s.y)*l*h,s.y*=3==v?a:m*a-d*l*c;break;case 1:c=-c,o=-o;case 0:t(o-E)<1e-8&&V(),s.x=h*(s.y=y*n(A+.5*o)),s.y*=c}},e.inv=function(n,o){var a,h,u,p;switch(u=i(a=2*l((h=f(n.x,n.y))/y)),p=r(a),o.lam=0,v){case 3:t(h)<=x?o.phi=0:o.phi=s(n.y*u/h),0==p&&0==n.x||(o.lam=c(n.x*u,p*h));break;case 2:t(h)<=x?o.phi=e.phi0:o.phi=s(p*d+n.y*u*m/h),0==(a=p-d*i(o.phi))&&0==n.x||(o.lam=c(n.x*u*m,a*h));break;case 1:n.y=-n.y;case 0:t(h)<=x?o.phi=e.phi0:o.phi=s(0==v?-p:p),o.lam=0==n.x&&0==n.y?0:c(n.x,n.y)}}}function b(t,e,i){return e*=i,n(.5*(E+t))*u((1-e)/(1+e),.5*i)}}function Ai(t,e){return u((1-t)/(1+t),e)}function Ei(t,e,s,o){var a=s/e,c=e,h=1/s;t.inv=function(t,e){var i;t.y/=c,i=r(e.phi=o?l(t.y):Je(t.y)),e.phi/=h,e.lam=t.x/(a*r(e.phi)),o?e.lam/=i*i:e.lam*=i},t.fwd=function(t,e){var s;e.x=a*t.lam*r(t.phi),e.y=c,t.phi*=h,s=r(t.phi),o?(e.x*=s*s,e.y*=n(t.phi)):(e.x/=s,e.y*=i(t.phi))},t.es=0}function Ii(e){var n,o,l,u=1e-10,f=.5,m=.16666666666666666,_=.08333333333333333,g=.05,y=.03333333333333333,v=.023809523809523808,x=.017857142857142856;e.es?((l=Xe(e.es))||e_error_0(),o=Ye(e.phi0,i(e.phi0),r(e.phi0),l),n=e.es/(1-e.es),e.fwd=function(s,a){var c,p,d,f,b,w;s.lam<-E||s.lam>E?N(-14):(c=i(s.phi),p=r(s.phi),d=t(p)>u?c/p:0,d*=d,f=p*s.lam,b=f*f,f/=h(1-e.es*c*c),w=n*p*p,a.x=e.k0*f*(1+m*b*(1-d+w+g*b*(5+d*(d-18)+w*(14-58*d)+v*b*(61+d*(d*(179-d)-479))))),a.y=e.k0*(Ye(s.phi,c,p,l)-o+c*f*s.lam*.5*(1+_*b*(5-d+w*(9+4*w)+y*b*(61+d*(d-58)+w*(270-330*d)+x*b*(1385+d*(d*(543-d)-3111)))))))},e.inv=function(s,a){var c,u,p,d,b,w,S;a.phi=Ke(o+s.y/e.k0,e.es,l),t(a.phi)>=E?(a.phi=s.y<0?-E:E,a.lam=0):(w=i(a.phi),p=r(a.phi),S=t(p)>1e-10?w/p:0,c=n*p*p,d=s.x*h(u=1-e.es*w*w)/e.k0,u*=S,S*=S,b=d*d,a.phi-=u*b/(1-e.es)*f*(1-b*_*(5+S*(3-9*c)+c*(1-4*c)-b*y*(61+S*(90-252*c+45*S)+46*c-b*x*(1385+S*(3633+S*(4095+1575*S)))))),a.lam=d*(1-b*m*(1+2*S+c-b*g*(5+S*(28+24*S+8*c)+6*c-b*v*(61+S*(662+S*(1320+720*S))))))/p)}):(n=e.k0,o=.5*n,e.fwd=function(s,l){var c,p;s.lam<-E||s.lam>E?N(-14):(p=r(s.phi),c=p*i(s.lam),t(t(c)-1)<=u&&V(),l.x=o*d((1+c)/(1-c)),l.y=p*r(s.lam)/h(1-c*c),(c=t(l.y))>=1?c-1>u?V():l.y=0:l.y=a(l.y),s.phi<0&&(l.y=-l.y),l.y=n*(l.y-e.phi0))},e.inv=function(t,i){var o=p(t.x/n),a=.5*(o-1/o);o=r(e.phi0+t.y/n),i.phi=s(h((1-o*o)/(1+a*a))),t.y<0&&-i.phi+e.phi0<0&&(i.phi=-i.phi),i.lam=a||o?c(a,o):0})}function Pi(t,e){var n=.8773826753,s=1.139753528477/e;t.es=0,t.fwd=function(t,o){var a=Je(e*i(t.phi));o.x=n*t.lam*r(a),o.y=s*a},t.inv=function(t,o){t.y/=s,o.phi=Je(i(t.y)/e),o.lam=t.x/(n*r(t.y))}}function Di(e,i){e.fwd=function(e,r){var n,s,o,a;o=t(D*e.phi),a=(a=1-o*o)<0?0:h(a),t(e.lam)<1e-10?(r.x=0,r.y=b*(e.phi<0?-o:o)/(1+a)):(s=.5*t(b/e.lam-e.lam/b),i?(n=o/(1+a),r.x=b*(h(s*s+1-n*n)-s),r.y=b*n):(n=(a*h(1+s*s)-s*a*a)/(1+s*s*o*o),r.x=b*n,r.y=b*h(1-n*(n+2*s)+1e-10)),e.lam<0&&(r.x=-r.x),e.phi<0&&(r.y=-r.y))},e.es=0}$e.Constants={},$e.Math={},$e.Accumulator={},(Ue=$e.Constants).WGS84={a:6378137,f:1/298.257223563},Ue.version={major:1,minor:48,patch:0},Ue.version_string="1.48",(qe=$e.Math).digits=53,qe.epsilon=Math.pow(.5,qe.digits-1),qe.degree=Math.PI/180,qe.sq=function(t){return t*t},qe.hypot=function(t,e){var i,r;return t=Math.abs(t),e=Math.abs(e),i=Math.max(t,e),r=Math.min(t,e)/(i||1),i*Math.sqrt(1+r*r)},qe.cbrt=function(t){var e=Math.pow(Math.abs(t),1/3);return t<0?-e:e},qe.log1p=function(t){var e=1+t,i=e-1;return 0===i?t:t*Math.log(e)/i},qe.atanh=function(t){var e=Math.abs(t);return e=qe.log1p(2*e/(1-e))/2,t<0?-e:e},qe.copysign=function(t,e){return Math.abs(t)*(e<0||0===e&&1/e<0?-1:1)},qe.sum=function(t,e){var i=t+e,r=i-e,n=i-r;return{s:i,t:-((r-=t)+(n-=e))}},qe.polyval=function(t,e,i,r){for(var n=t<0?0:e[i++];--t>=0;)n=n*r+e[i++];return n},qe.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},qe.AngNormalize=function(t){return(t%=360)<=-180?t+360:t<=180?t:t-360},qe.LatFix=function(t){return Math.abs(t)>90?Number.NaN:t},qe.AngDiff=function(t,e){var i=qe.sum(qe.AngNormalize(-t),qe.AngNormalize(e)),r=qe.AngNormalize(i.s),n=i.t;return qe.sum(180===r&&n>0?-180:r,n)},qe.sincosd=function(t){var e,i,r,n,s,o;switch(e=t%360,e-=90*(i=Math.floor(e/90+.5)),e*=this.degree,r=Math.sin(e),n=Math.cos(e),3&i){case 0:s=r,o=n;break;case 1:s=n,o=-r;break;case 2:s=-r,o=-n;break;default:s=-n,o=r}return t&&(s+=0,o+=0),{s:s,c:o}},qe.atan2d=function(t,e){var i,r,n=0;switch(Math.abs(t)>Math.abs(e)&&(i=e,e=t,t=i,n=2),e<0&&(e=-e,++n),r=Math.atan2(t,e)/this.degree,n){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 i=e.sum(t,this._t),r=e.sum(i.s,this._s);i=i.t,this._s=r.s,this._t=r.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}}($e.Accumulator,$e.Math),$e.Geodesic={},$e.GeodesicLine={},$e.PolygonArea={},function(t,e,i,r,n){var s,o,a,l,c,h,u,p,d,f,m,_=20+r.digits+10,g=r.epsilon,y=200*g,v=Math.sqrt(g),x=g*y,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,s=t.nC3_*(t.nC3_-1)/2,o=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,r){var n=r.length,s=n-(t?1:0),o=2*(i-e)*(i+e),a=1&s?r[--n]:0,l=0;for(s=Math.floor(s/2);s--;)a=o*(l=o*a-l+r[--n])-a+r[--n];return t?2*e*i*a:i*(a-l)},a=function(t,e){var i,n,s,o,a,l,c,h,u,p,d,f,m=r.sq(t),_=r.sq(e),g=(m+_-1)/6;return 0===_&&g<=0?i=0:(l=g,(a=(n=m*_/4)*(n+2*(o=g*(s=r.sq(g)))))>=0?(c=n+o,c+=c<0?-Math.sqrt(a):Math.sqrt(a),l+=(h=r.cbrt(c))+(0!==h?s/h:0)):(u=Math.atan2(Math.sqrt(-a),-(n+o)),l+=2*g*Math.cos(u/3)),p=Math.sqrt(r.sq(l)+_),f=((d=l<0?_/(p-l):l+p)-_)/(2*p),i=d/(Math.sqrt(d+r.sq(f))+f)),i},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)},c=[-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,s,o=r.sq(e),a=e,l=0;for(n=1;n<=t.nC1_;++n)s=Math.floor((t.nC1_-n)/2),i[n]=a*r.polyval(s,c,l,o)/c[l+s+1],l+=s+2,a*=e},h=[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,s,o=r.sq(e),a=e,l=0;for(n=1;n<=t.nC1p_;++n)s=Math.floor((t.nC1p_-n)/2),i[n]=a*r.polyval(s,h,l,o)/h[l+s+1],l+=s+2,a*=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,i){var n,s,o=r.sq(e),a=e,l=0;for(n=1;n<=t.nC2_;++n)s=Math.floor((t.nC2_-n)/2),i[n]=a*r.polyval(s,p,l,o)/p[l+s+1],l+=s+2,a*=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(o),this.A3coeff(),this.C3coeff(),this.C4coeff()},d=[-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++]=r.polyval(e,d,i,this._n)/d[i+e+1],i+=e+2},f=[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,s=0,o=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[o++]=r.polyval(n,f,s,this._n)/f[s+n+1],s+=n+2},m=[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,s=0,o=0;for(e=0;e<t.nC4_;++e)for(i=t.nC4_-1;i>=e;--i)n=t.nC4_-i-1,this._C4x[o++]=r.polyval(n,m,s,this._n)/m[s+n+1],s+=n+2},t.Geodesic.prototype.A3f=function(t){return r.polyval(5,this._A3x,0,t)},t.Geodesic.prototype.C3f=function(e,i){var n,s,o=1,a=0;for(n=1;n<t.nC3_;++n)s=t.nC3_-n-1,o*=e,i[n]=o*r.polyval(s,this._C3x,a,e),a+=s+1},t.Geodesic.prototype.C4f=function(e,i){var n,s,o=1,a=0;for(n=0;n<t.nC4_;++n)s=t.nC4_-n-1,i[n]=o*r.polyval(s,this._C4x,a,e),a+=s+1,o*=e},t.Geodesic.prototype.Lengths=function(e,i,r,n,s,o,a,l,c,h,u,p,d){var f,m,_,g,y={},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,d),v=b-w,w=1+w),b=1+b),u&t.DISTANCE)f=t.SinCosSeries(!0,o,a,p)-t.SinCosSeries(!0,r,n,p),y.s12b=b*(i+f),u&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(x=v*i+(b*f-w*(t.SinCosSeries(!0,o,a,d)-t.SinCosSeries(!0,r,n,d))));else if(u&(t.REDUCEDLENGTH|t.GEODESICSCALE)){for(m=1;m<=t.nC2_;++m)d[m]=b*p[m]-w*d[m];x=v*i+(t.SinCosSeries(!0,o,a,d)-t.SinCosSeries(!0,r,n,d))}return u&t.REDUCEDLENGTH&&(y.m0=v,y.m12b=l*(n*o)-s*(r*a)-n*a*x),u&t.GEODESICSCALE&&(_=n*a+r*o,g=this._ep2*(c-h)*(c+h)/(s+l),y.M12=_+(g*o-a*x)*r/s,y.M21=_-(g*r-n*x)*o/l),y},t.Geodesic.prototype.InverseStart=function(e,i,n,s,o,l,c,h,u,p,d){var f,m,_,g,v,x,w,S,T,C,M,A,E,I,P,D,k,z,R,L,F={},B=s*i-o*e,O=o*i+s*e;return F.sig12=-1,f=s*i,f+=o*e,(m=O>=0&&B<.5&&o*c<.5)?(g=r.sq(e+s),g/=g+r.sq(i+o),F.dnm=Math.sqrt(1+this._ep2*g),_=c/(this._f1*F.dnm),v=Math.sin(_),x=Math.cos(_)):(v=h,x=u),F.salp1=o*v,F.calp1=x>=0?B+o*e*r.sq(v)/(1+x):f-o*e*r.sq(v)/(1-x),S=r.hypot(F.salp1,F.calp1),T=e*s+i*o*x,m&&S<this._etol2?(F.salp2=i*v,F.calp2=B-i*s*(x>=0?r.sq(v)/(1+x):1-x),w=r.hypot(F.salp2,F.calp2),F.salp2/=w,F.calp2/=w,F.sig12=Math.atan2(S,T)):Math.abs(this._n)>.1||T>=0||S>=6*Math.abs(this._n)*Math.PI*r.sq(i)||(L=Math.atan2(-h,-u),this.f>=0?(I=(E=r.sq(e)*this._ep2)/(2*(1+Math.sqrt(1+E))+E),C=L/(A=this.f*i*this.A3f(I)*Math.PI),M=f/(A*i)):(P=o*i-s*e,D=Math.atan2(f,P),M=c/(A=((C=(k=this.Lengths(this._n,Math.PI+D,e,-i,n,s,o,l,i,o,t.REDUCEDLENGTH,p,d)).m12b/(i*o*k.m0*Math.PI)-1)<-.01?f/C:-this.f*r.sq(i)*Math.PI)/i)),M>-y&&C>-1-b?this.f>=0?(F.salp1=Math.min(1,-C),F.calp1=-Math.sqrt(1-r.sq(F.salp1))):(F.calp1=Math.max(C>-y?0:-1,C),F.salp1=Math.sqrt(1-r.sq(F.calp1))):(z=a(C,M),R=A*(this.f>=0?-C*z/(1+z):-M*(1+z)/z),v=Math.sin(R),x=-Math.cos(R),F.salp1=o*v,F.calp1=f-o*e*r.sq(v)/(1-x))),F.salp1<=0?(F.salp1=1,F.calp1=0):(w=r.hypot(F.salp1,F.calp1),F.salp1/=w,F.calp1/=w),F},t.Geodesic.prototype.Lambda12=function(e,i,n,s,o,a,l,c,h,u,p,d,f,m){var _,g,y,v,x,b,w,S,T,C,M,A,E,I={};return 0===e&&0===c&&(c=-t.tiny_),g=l*i,y=r.hypot(c,l*e),I.ssig1=e,v=g*e,I.csig1=x=c*i,_=r.hypot(I.ssig1,I.csig1),I.ssig1/=_,I.csig1/=_,I.salp2=o!==i?g/o:l,I.calp2=o!==i||Math.abs(s)!==-e?Math.sqrt(r.sq(c*i)+(i<-e?(o-i)*(i+o):(e-s)*(e+s)))/o:Math.abs(c),I.ssig2=s,b=g*s,I.csig2=w=I.calp2*o,_=r.hypot(I.ssig2,I.csig2),I.ssig2/=_,I.csig2/=_,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),T=x*w+v*b,M=Math.atan2(S*u-T*h,T*u+S*h),A=r.sq(y)*this._ep2,I.eps=A/(2*(1+Math.sqrt(1+A))+A),this.C3f(I.eps,m),C=t.SinCosSeries(!0,I.ssig2,I.csig2,m)-t.SinCosSeries(!0,I.ssig1,I.csig1,m),I.domg12=-this.f*this.A3f(I.eps)*g*(I.sig12+C),I.lam12=M+I.domg12,p&&(0===I.calp2?I.dlam12=-2*this._f1*n/e:(E=this.Lengths(I.eps,I.sig12,I.ssig1,I.csig1,n,I.ssig2,I.csig2,a,i,o,t.REDUCEDLENGTH,d,f),I.dlam12=E.m12b,I.dlam12*=this._f1/(I.calp2*o))),I},t.Geodesic.prototype.Inverse=function(e,i,n,s,o){var a,l;return o||(o=t.STANDARD),o===t.LONG_UNROLL&&(o|=t.STANDARD),o&=t.OUT_MASK,l=(a=this.InverseInt(e,i,n,s,o)).vals,o&t.AZIMUTH&&(l.azi1=r.atan2d(a.salp1,a.calp1),l.azi2=r.atan2d(a.salp2,a.calp2)),l},t.Geodesic.prototype.InverseInt=function(e,i,n,s,o){var a,l,c,h,u,p,d,f,m,y,v,b,w,S,T,C,M,A,E,I,P,D,k,z,R,L,F,B,O,N,V,j,G,U,q,$,Z,W,H,X,Y,K,J,Q,tt,et,it,rt,nt,st,ot,at,lt,ct,ht,ut,pt,dt,ft,mt,_t,gt,yt,vt,xt,bt={};if(bt.lat1=e=r.LatFix(e),bt.lat2=n=r.LatFix(n),e=r.AngRound(e),n=r.AngRound(n),l=(a=r.AngDiff(i,s)).t,a=a.s,o&t.LONG_UNROLL?(bt.lon1=i,bt.lon2=i+a+l):(bt.lon1=r.AngNormalize(i),bt.lon2=r.AngNormalize(s)),a=(c=a>=0?1:-1)*r.AngRound(a),l=r.AngRound(180-a-c*l),T=a*r.degree,C=(h=r.sincosd(a>90?l:a)).s,M=(a>90?-1:1)*h.c,(u=Math.abs(e)<Math.abs(n)?-1:1)<0&&(c*=-1,h=e,e=n,n=h),e*=p=e<0?1:-1,n*=p,h=r.sincosd(e),d=this._f1*h.s,f=h.c,d/=h=r.hypot(d,f),f/=h,f=Math.max(t.tiny_,f),h=r.sincosd(n),m=this._f1*h.s,y=h.c,m/=h=r.hypot(m,y),y/=h,y=Math.max(t.tiny_,y),f<-d?y===f&&(m=m<0?d:-d):Math.abs(m)===-d&&(y=f),w=Math.sqrt(1+this._ep2*r.sq(d)),S=Math.sqrt(1+this._ep2*r.sq(m)),k=new Array(t.nC1_+1),z=new Array(t.nC2_+1),R=new Array(t.nC3_),(L=-90===e||0===C)&&(I=C,D=0,B=d,O=(E=M)*f,N=m,V=(P=1)*y,A=Math.atan2(Math.max(0,O*N-B*V),O*V+B*N),v=(F=this.Lengths(this._n,A,B,O,w,N,V,S,f,y,o|t.DISTANCE|t.REDUCEDLENGTH,k,z)).s12b,b=F.m12b,0!==(o&t.GEODESICSCALE)&&(bt.M12=F.M12,bt.M21=F.M21),A<1||b>=0?(A<3*t.tiny_&&(A=b=v=0),b*=this._b,v*=this._b,bt.a12=A/r.degree):L=!1),pt=2,!L&&0===d&&(this.f<=0||l>=180*this.f))E=P=0,I=D=1,v=this.a*T,A=G=T/this._f1,b=this._b*Math.sin(A),o&t.GEODESICSCALE&&(bt.M12=bt.M21=Math.cos(A)),bt.a12=a/this._f1;else if(!L)if(A=(F=this.InverseStart(d,f,w,m,y,S,T,C,M,k,z)).sig12,I=F.salp1,E=F.calp1,A>=0)D=F.salp2,P=F.calp2,U=F.dnm,v=A*this._b*U,b=r.sq(U)*this._b*Math.sin(A/U),o&t.GEODESICSCALE&&(bt.M12=bt.M21=Math.cos(A/U)),bt.a12=A/r.degree,G=T/(this._f1*U);else{for(q=0,$=t.tiny_,Z=1,W=t.tiny_,H=-1,X=!1,Y=!1;q<_&&(K=(F=this.Lambda12(d,f,w,m,y,S,I,E,C,M,q<20,k,z,R)).lam12,D=F.salp2,P=F.calp2,A=F.sig12,B=F.ssig1,O=F.csig1,N=F.ssig2,V=F.csig2,j=F.eps,ft=F.domg12,J=F.dlam12,!Y&&Math.abs(K)>=(X?8:1)*g);++q)K>0&&(q<20||E/I>H/W)?(W=I,H=E):K<0&&(q<20||E/I<Z/$)&&($=I,Z=E),q<20&&J>0&&(Q=-K/J,tt=Math.sin(Q),(it=I*(et=Math.cos(Q))+E*tt)>0&&Math.abs(Q)<Math.PI)?(E=E*et-I*tt,I=it,I/=h=r.hypot(I,E),E/=h,X=Math.abs(K)<=16*g):(I=($+W)/2,E=(Z+H)/2,I/=h=r.hypot(I,E),E/=h,X=!1,Y=Math.abs($-I)+(Z-E)<x||Math.abs(I-W)+(E-H)<x);rt=o|(o&(t.REDUCEDLENGTH|t.GEODESICSCALE)?t.DISTANCE:t.NONE),v=(F=this.Lengths(j,A,B,O,w,N,V,S,f,y,rt,k,z)).s12b,b=F.m12b,0!==(o&t.GEODESICSCALE)&&(bt.M12=F.M12,bt.M21=F.M21),b*=this._b,v*=this._b,bt.a12=A/r.degree,o&t.AREA&&(vt=Math.sin(ft),pt=C*(xt=Math.cos(ft))-M*vt,dt=M*xt+C*vt)}return o&t.DISTANCE&&(bt.s12=0+v),o&t.REDUCEDLENGTH&&(bt.m12=0+b),o&t.AREA&&(nt=I*f,0!==(st=r.hypot(E,I*d))&&0!==nt?(B=d,O=E*f,N=m,V=P*y,j=(at=r.sq(st)*this._ep2)/(2*(1+Math.sqrt(1+at))+at),lt=r.sq(this.a)*st*nt*this._e2,B/=h=r.hypot(B,O),O/=h,N/=h=r.hypot(N,V),V/=h,ct=new Array(t.nC4_),this.C4f(j,ct),ht=t.SinCosSeries(!1,B,O,ct),ut=t.SinCosSeries(!1,N,V,ct),bt.S12=lt*(ut-ht)):bt.S12=0,!L&&pt>1&&(pt=Math.sin(G),dt=Math.cos(G)),!L&&dt>-.7071&&m-d<1.75?(ft=1+dt,mt=1+f,_t=1+y,ot=2*Math.atan2(pt*(d*_t+m*mt),ft*(d*m+mt*_t))):(yt=P*E+D*I,0===(gt=D*E-P*I)&&yt<0&&(gt=t.tiny_*E,yt=-1),ot=Math.atan2(gt,yt)),bt.S12+=this._c2*ot,bt.S12*=u*c*p,bt.S12+=0),u<0&&(h=I,I=D,D=h,h=E,E=P,P=h,o&t.GEODESICSCALE&&(h=bt.M12,bt.M12=bt.M21,bt.M21=h)),{vals:bt,salp1:I*=u*c,calp1:E*=u*p,salp2:D*=u*c,calp2:P*=u*p}},t.Geodesic.prototype.GenDirect=function(i,r,n,s,o,a){return a?a===t.LONG_UNROLL&&(a|=t.STANDARD):a=t.STANDARD,s||(a|=t.DISTANCE_IN),new e.GeodesicLine(this,i,r,n,a).GenPosition(s,o,a)},t.Geodesic.prototype.Direct=function(t,e,i,r,n){return this.GenDirect(t,e,i,!1,r,n)},t.Geodesic.prototype.ArcDirect=function(t,e,i,r,n){return this.GenDirect(t,e,i,!0,r,n)},t.Geodesic.prototype.Line=function(t,i,r,n){return new e.GeodesicLine(this,t,i,r,n)},t.Geodesic.prototype.DirectLine=function(t,e,i,r,n){return this.GenDirectLine(t,e,i,!1,r,n)},t.Geodesic.prototype.ArcDirectLine=function(t,e,i,r,n){return this.GenDirectLine(t,e,i,!0,r,n)},t.Geodesic.prototype.GenDirectLine=function(i,r,n,s,o,a){var l;return a||(a=t.STANDARD|t.DISTANCE_IN),s||(a|=t.DISTANCE_IN),(l=new e.GeodesicLine(this,i,r,n,a)).GenSetDistance(s,o),l},t.Geodesic.prototype.InverseLine=function(i,n,s,o,a){var l,c,h;return a||(a=t.STANDARD|t.DISTANCE_IN),l=this.InverseInt(i,n,s,o,t.ARC),h=r.atan2d(l.salp1,l.calp1),a&t.OUT_MASK&t.DISTANCE_IN&&(a|=t.DISTANCE),(c=new e.GeodesicLine(this,i,n,h,a,l.salp1,l.calp1)).SetArc(l.vals.a12),c},t.Geodesic.prototype.Polygon=function(t){return new i.PolygonArea(this,t)},t.WGS84=new t.Geodesic(n.WGS84.a,n.WGS84.f)}($e.Geodesic,$e.GeodesicLine,$e.PolygonArea,$e.Math,$e.Constants),function(t,e,i){e.GeodesicLine=function(e,r,n,s,o,a,l){var c,h,u,p,d,f;o||(o=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=o|t.LATITUDE|t.AZIMUTH|t.LONG_UNROLL,this.lat1=i.LatFix(r),this.lon1=n,void 0===a||void 0===l?(this.azi1=i.AngNormalize(s),c=i.sincosd(i.AngRound(this.azi1)),this.salp1=c.s,this.calp1=c.c):(this.azi1=s,this.salp1=a,this.calp1=l),c=i.sincosd(i.AngRound(this.lat1)),u=this._f1*c.s,h=c.c,u/=c=i.hypot(u,h),h/=c,h=Math.max(t.tiny_,h),this._dn1=Math.sqrt(1+e._ep2*i.sq(u)),this._salp0=this.salp1*h,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?h*this.calp1:1,c=i.hypot(this._ssig1,this._csig1),this._ssig1/=c,this._csig1/=c,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),d=Math.sin(this._B11),f=Math.cos(this._B11),this._stau1=this._ssig1*f+this._csig1*d,this._ctau1=this._csig1*f-this._ssig1*d),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,r,n){var s,o,a,l,c,h,u,p,d,f,m,_,g,y,v,x,b,w,S,T,C,M,A,E,I,P,D={};return n?n===t.LONG_UNROLL&&(n|=t.STANDARD):n=t.STANDARD,n&=this.caps&t.OUT_MASK,D.lat1=this.lat1,D.azi1=this.azi1,D.lon1=n&t.LONG_UNROLL?this.lon1:i.AngNormalize(this.lon1),e?D.a12=r:D.s12=r,e||this.caps&t.DISTANCE_IN&t.OUT_MASK?(l=0,c=0,e?(s=r*i.degree,o=(A=i.sincosd(r)).s,a=A.c):(p=r/(this._b*(1+this._A1m1)),d=Math.sin(p),f=Math.cos(p),s=p-((l=-t.SinCosSeries(!0,this._stau1*f+this._ctau1*d,this._ctau1*f-this._stau1*d,this._C1pa))-this._B11),o=Math.sin(s),a=Math.cos(s),Math.abs(this.f)>.01&&(h=this._ssig1*a+this._csig1*o,u=this._csig1*a-this._ssig1*o,l=t.SinCosSeries(!0,h,u,this._C1a),s-=((1+this._A1m1)*(s+(l-this._B11))-r/this._b)/Math.sqrt(1+this._k2*i.sq(h)),o=Math.sin(s),a=Math.cos(s))),h=this._ssig1*a+this._csig1*o,u=this._csig1*a-this._ssig1*o,S=Math.sqrt(1+this._k2*i.sq(h)),n&(t.DISTANCE|t.REDUCEDLENGTH|t.GEODESICSCALE)&&((e||Math.abs(this.f)>.01)&&(l=t.SinCosSeries(!0,h,u,this._C1a)),c=(1+this._A1m1)*(l-this._B11)),g=this._calp0*h,0===(y=i.hypot(this._salp0,this._calp0*u))&&(y=u=t.tiny_),b=this._salp0,w=this._calp0*u,e&&n&t.DISTANCE&&(D.s12=this._b*((1+this._A1m1)*s+c)),n&t.LONGITUDE&&(v=this._salp0*h,x=u,_=i.copysign(1,this._salp0),m=((n&t.LONG_UNROLL?_*(s-(Math.atan2(h,u)-Math.atan2(this._ssig1,this._csig1))+(Math.atan2(_*v,x)-Math.atan2(_*this._somg1,this._comg1))):Math.atan2(v*this._comg1-x*this._somg1,x*this._comg1+v*this._somg1))+this._A3c*(s+(t.SinCosSeries(!0,h,u,this._C3a)-this._B31)))/i.degree,D.lon2=n&t.LONG_UNROLL?this.lon1+m:i.AngNormalize(i.AngNormalize(this.lon1)+i.AngNormalize(m))),n&t.LATITUDE&&(D.lat2=i.atan2d(g,this._f1*y)),n&t.AZIMUTH&&(D.azi2=i.atan2d(b,w)),n&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(T=t.SinCosSeries(!0,h,u,this._C2a),C=(1+this._A2m1)*(T-this._B21),M=(this._A1m1-this._A2m1)*s+(c-C),n&t.REDUCEDLENGTH&&(D.m12=this._b*(S*(this._csig1*h)-this._dn1*(this._ssig1*u)-this._csig1*u*M)),n&t.GEODESICSCALE&&(A=this._k2*(h-this._ssig1)*(h+this._ssig1)/(this._dn1+S),D.M12=a+(A*h-u*M)*this._ssig1/this._dn1,D.M21=a-(A*this._ssig1-this._csig1*M)*h/S)),n&t.AREA&&(E=t.SinCosSeries(!1,h,u,this._C4a),0===this._calp0||0===this._salp0?(I=b*this.calp1-w*this.salp1,P=w*this.calp1+b*this.salp1):(I=this._calp0*this._salp0*(a<=0?this._csig1*(1-a)+o*this._ssig1:o*(this._csig1*o/(1+a)+this._ssig1)),P=i.sq(this._salp0)+i.sq(this._calp0)*this._csig1*u),D.S12=this._c2*Math.atan2(I,P)+this._A4*(E-this._B41)),e||(D.a12=s/i.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 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}}($e.Geodesic,$e.GeodesicLine,$e.Math),function(t,e,i,r){var n,s;n=function(t,e){var r;return t=i.AngNormalize(t),e=i.AngNormalize(e),r=i.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,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 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 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+=s(this.lon,i.lon2)),this.lat=i.lat2,this.lon=i.lon2),++this.num},t.PolygonArea.prototype.Compute=function(t,e){var i,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):(i=this._geod.Inverse(this.lat,this.lon,this._lat0,this._lon0,this._mask),o.perimeter=this._perimetersum.Sum(i.s12),(s=new r.Accumulator(this._areasum)).Add(i.S12),1&this._crossings+n(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),o.area=s.Sum(),o)},t.PolygonArea.prototype.TestPoint=function(t,e,i,r){var s,o,a,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(),o=this.polyline?0:this._areasum.Sum(),a=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),c.perimeter+=s.s12,this.polyline||(o+=s.S12,a+=n(0===l?this.lon:e,0!==l?this._lon0:e));return this.polyline||(1&a&&(o+=(o<0?1:-1)*this._area0/2),i||(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),c.area=o),c},t.PolygonArea.prototype.TestEdge=function(t,e,i,r){var o,a,l,c={number:this.num?this.num+1:0};return 0===this.num||(c.perimeter=this._perimetersum.Sum()+e,this.polyline||(a=this._areasum.Sum(),l=this._crossings,a+=(o=this._geod.Direct(this.lat,this.lon,t,e,this._mask)).S12,l+=s(this.lon,o.lon2),o=this._geod.Inverse(o.lat2,o.lon2,this._lat0,this._lon0,this._mask),c.perimeter+=o.s12,a+=o.S12,1&(l+=n(o.lon2,this._lon0))&&(a+=(a<0?1:-1)*this._area0/2),i||(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),c.area=a)),c}}($e.PolygonArea,$e.Geodesic,$e.Math,$e.Accumulator),tt(function(t){var e=Y(t.params,"rlat_1"),i=Y(t.params,"rlat_2");He(t,e,i)},"aea","Albers Equal Area","Conic Sph&Ell\nlat_1= lat_2="),tt(function(t){var e=Y(t.params,"rlat_1"),i=Y(t.params,"bsouth")?-E:E;He(t,e,i)},"leac","Lambert Equal Area Conic","Conic, Sph&Ell\nlat_1= south"),tt(function(e){var s,o,l,u,p,d,m,_=1e-10;if(e.phi0=Y(e.params,"rlat_0"),t(t(e.phi0)-E)<_?(p=e.phi0<0?1:0,s=e.phi0<0?-1:1,o=0):t(e.phi0)<_?(p=2,s=0,o=1):(p=3,s=i(e.phi0),o=r(e.phi0)),e.es)if(m=new $e.Geodesic.Geodesic(e.a,e.es/(1+h(e.one_es))),d=Xe(e.es),Y(e.params,"bguam"))l=Ye(e.phi0,s,o,d),e.inv=function(t,s){var o,a,c;for(o=.5*t.x*t.x,s.phi=e.phi0,c=0;c<3;++c)a=e.e*i(s.phi),s.phi=Ke(l+t.y-o*n(s.phi)*(a=h(1-a*a)),e.es,d);s.lam=t.x*a/r(s.phi)},e.fwd=function(t,n){var s,o,a;s=r(t.phi),o=i(t.phi),a=1/h(1-e.es*o*o),n.x=t.lam*s*a,n.y=Ye(t.phi,o,s,d)-l+.5*t.lam*t.lam*s*o*a};else{switch(p){case 0:u=Ye(E,1,0,d);break;case 1:u=Ye(-E,-1,0,d);break;case 2:case 3:e.inv=y,e.fwd=g,h(1-e.es*s*s),e.e,h(e.one_es)}e.inv=y,e.fwd=g}else e.inv=function(t,n){var a,l,h,u=t.x,d=t.y;if((l=f(u,d))>b)l-_>b&&j(),l=b;else if(l<_)return n.phi=e.phi0,void(n.lam=0);3==p||2==p?(h=i(l),a=r(l),2==p?(n.phi=Je(d*h/l),u*=h,d=a*l):(n.phi=Je(a*s+d*h*o/l),d=(a-s*i(n.phi))*l,u*=h*o),n.lam=0==d?0:c(u,d)):0==p?(n.phi=E-l,n.lam=c(u,-d)):(n.phi=l-E,n.lam=c(u,d))},e.fwd=function(e,n){var l,c,h;switch(h=i(e.phi),c=r(e.phi),l=r(e.lam),p){case 2:case 3:n.y=2==p?c*l:s*h+o*c*l,t(t(n.y)-1)<1e-14?n.y<0?V():n.x=n.y=0:(n.y=a(n.y),n.y/=i(n.y),n.x=n.y*c*i(e.lam),n.y*=2==p?h:o*h-s*c*l);break;case 0:e.phi=-e.phi,l=-l;case 1:t(e.phi-E)<_&&V(),n.x=(n.y=E+e.phi)*i(e.lam),n.y*=l}};function g(n,s){var o,a,l,c,h,f,g,y,v,x,b;switch(o=r(n.lam),a=r(n.phi),l=i(n.phi),p){case 0:o=-o;case 1:s.x=(c=t(u-Ye(n.phi,l,a,d)))*i(n.lam),s.y=c*o;break;case 2:case 3:if(t(n.lam)<_&&t(n.phi-e.phi0)<_){s.x=s.y=0;break}y=e.phi0/T,g=e.lam0/T,x=n.phi/T,v=(n.lam+e.lam0)/T,h=(b=m.Inverse(y,g,x,v,m.AZIMUTH)).azi1*T,f=b.s12,s.x=f*i(h)/e.a,s.y=f*r(h)/e.a}}function y(t,i){var r,n,s,o,a,l,g,y;if((r=f(t.x,t.y))<_)return i.phi=e.phi0,i.lam=0,i;3==p||2==p?(o=t.x*e.a,a=t.y*e.a,l=e.phi0/T,g=e.lam0/T,n=c(o,a)/T,s=h(o*o+a*a),y=m.Direct(l,g,n,s,m.STANDARD),i.phi=y.lat2*T,i.lam=y.lon2*T,i.lam-=e.lam0):(i.phi=Ke(0==p?u-r:u+r,e.es,d),i.lam=c(t.x,0==p?-t.y:t.y))}},"aeqd","Azimuthal Equidistant","Azi, Sph&Ell\nlat_0 guam"),tt(function(e){var s,o,a,l,c,h,u=1e-10;e.es=0,e.fwd=function(e,h){var p,f,m,_,g,y,v,x;switch(p=i(e.lam),f=r(e.lam),l){case 2:case 3:_=i(e.phi),x=(m=r(e.phi))*f,3==l&&(x=s*_+o*x),!c&&x<-u&&V(),v=t(y=1-x)>u?-d(g=.5*(1+x))/y-a/g:.5-a,h.x=v*m*p,h.y=3==l?v*(o*_-s*m*f):v*_;break;case 1:case 0:e.phi=t(p_halfpi-e.phi),!c&&e.phi-u>E&&V(),(e.phi*=.5)>u?(g=n(e.phi),v=-2*(d(r(e.phi))/g+g*a),h.x=v*p,h.y=v*f,0==l&&(h.y=-h.y)):h.x=h.y=0}},c=Y(e.params,"bno_cut"),h=.5*(E-Y(e.params,"rlat_b")),t(h)<u?a=-.5:(a=1/n(h),a*=a*d(r(h))),t(t(e.phi0)-E)<u?e.phi0<0?(p_halfpi=-E,l=1):(p_halfpi=E,l=0):t(e.phi0)<u?l=2:(l=3,s=i(e.phi0),o=r(e.phi0))},"airy","Airy","Misc Sph, no inv.\nno_cut lat_b="),tt(function(t){var e=t.opaque={mode:1};Y(t.params,"tlat_1")?0===(e.cosphi1=r(Y(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 s,o,a,l,c,u,p,d=4/3,f=t.lam;s=n(.5*t.phi),a=1+(o=h(1-s*s))*r(f*=.5),l=i(f)*o/a,u=s/a,e.x=d*l*(3+(c=l*l)-3*(p=u*u)),e.y=d*u*(3+3*c-p)},t.es=0},"august","August Epicycloidal","Misc Sph, no inv."),tt(function(t){ri(t,!1,!1)},"apian","Apian Globular I","Misc Sph, no inv."),tt(function(t){ri(t,!1,!0)},"ortel","Ortelius Oval","Misc Sph, no inv."),tt(function(t){ri(t,!0,!1)},"bacon","Bacon Globular","Misc Sph, no inv."),tt(function(t){var e,n,o,a;t.es=0,t.fwd=function(t,l){var u,p,d,f,m,_;return t.lam+=-16.5*T,p=r(t.phi),d=r(t.lam)*p,f=i(t.lam)*p,_=(m=i(t.phi))*e+d*n,t.lam=c(f*o-_*a,d*e-m*n),_=_*o+f*a,t.phi=s(_),t.lam=At(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+b/2)),p=r(t.phi),u=h(2/(1+p*r(t.lam/2))),l.x=1.68*u*p*i(t.lam/2),l.y=u*i(t.phi),u=(1-r(t.lam*t.phi))/12,l.y<0&&(l.x*=1+u),l.y>0&&(l.y*=1+u/1.5*l.x*l.x),l},t.lam0=0,t.phi0=-42*T,e=r(t.phi0),n=i(t.phi0),o=1,a=0},"bertin1953","Bertin 1953","Misc., Sph., NoInv."),tt(function(e){var n=h(2);e.fwd=function(e,s){var o,a,l,c;if(o=e.phi,t(t(e.phi)-E)<1e-7)s.x=0;else{for(l=i(o)*b,c=20;c&&(o-=a=(o+i(o)-l)/(1+r(o)),!(t(a)<1e-7));--c);o*=.5,s.x=2.00276*e.lam/(1/r(e.phi)+1.11072/r(o))}s.y=.49931*(e.phi+n*i(o))},e.es=0},"boggs","Boggs Eumorphic","PCyl., no inv., Sph."),tt(function(e){var s,o,a,l,u,p,d=1e-10;s=Y(e.params,"rlat_1"),t(s)<d&&U(-23),e.es?(u=Xe(e.es),l=Ye(s,a=i(s),p=r(s),u),a=p/(h(1-e.es*a*a)*a),e.inv=function(n,s){var o,p;p=f(n.x,n.y=a-n.y),s.phi=Ke(a+l-p,e.es,u),(o=t(s.phi))<E?(o=i(s.phi),s.lam=p*c(n.x,n.y)*h(1-e.es*o*o)/r(s.phi)):t(o-E)<=d?s.lam=0:j()},e.fwd=function(t,n){var s,o,c;s=a+l-Ye(t.phi,o=i(t.phi),c=r(t.phi),u),o=c*t.lam/(s*h(1-e.es*o*o)),n.x=s*i(o),n.y=a-s*r(o)}):(o=t(s)+d>=E?0:1/n(s),e.inv=function(e,i){var n=f(e.x,e.y=o-e.y);i.phi=o+s-n,t(i.phi)>E&&j(),t(t(i.phi)-E)<=d?i.lam=0:i.lam=n*c(e.x,e.y)/r(i.phi)},e.fwd=function(e,n){var a,l;l=o+s-e.phi,t(l)>d?(n.x=l*i(a=e.lam*r(e.phi)/l),n.y=o-l*r(a)):n.x=n.y=0})},"bonne","Bonne (Werner lat_1=90)","Conic Sph&Ell\nlat_1="),tt(function(t){var e,o,a=.16666666666666666,l=.008333333333333333,u=.041666666666666664,p=.06666666666666667;t.es?(o=Xe(t.es),e=Ye(t.phi0,i(t.phi0),r(t.phi0),o),t.fwd=function(s,c){var p,d,f,m,_,g;c.y=Ye(s.phi,p=i(s.phi),m=r(s.phi),o),p=1/h(1-t.es*p*p),g=n(s.phi),d=g*g,f=s.lam*m,m*=t.es*m/(1-t.es),_=f*f,c.x=p*f*(1-_*d*(a-(8-d+8*m)*_*l)),c.y-=e-p*g*_*(.5+(5-d+6*m)*_*u)},t.inv=function(s,a){var l,c,d,f,m,_,g;g=Ke(e+s.y,t.es,o),_=n(g),c=_*_,l=i(g),d=1/(1-t.es*l*l),l=h(d),d*=(1-t.es)*l,f=s.x/l,m=f*f,a.phi=g-l*_/d*m*(.5-(1+3*c)*m*u),a.lam=f*(1+c*m*((1+3*c)*m*p-.3333333333333333))/r(g)}):(t.fwd=function(e,o){o.x=s(r(e.phi)*i(e.lam)),o.y=c(n(e.phi),r(e.lam))-t.phi0},t.inv=function(e,o){var a=e.y+t.phi0;o.phi=s(i(a)*r(e.x)),o.lam=c(n(e.x),r(a))})},"cass","Cassini","Cyl, Sph&Ell"),tt(function(e){var n,o,a=0;Y(e.params,"tlat_ts")&&(e.k0=r(a=Y(e.params,"rlat_ts")),e.k0<0&&U(-24)),e.es?(a=i(a),e.k0/=h(1-e.es*a*a),e.e=h(e.es),(o=ni(e.es))||e_error_0(),n=Ze(1,e.e,e.one_es),e.fwd=function(t,r){r.x=e.k0*t.lam,r.y=.5*Ze(i(t.phi),e.e,e.one_es)/e.k0},e.inv=function(t,i){i.phi=si(s(2*t.y*e.k0/n),o),i.lam=t.x/e.k0}):(e.fwd=function(t,r){r.x=e.k0*t.lam,r.y=i(t.phi)/e.k0},e.inv=function(i,r){var n,o=i.x,a=i.y;(n=t(a*=e.k0))-R<=1?(r.phi=n>=1?a<0?-E:E:s(a),r.lam=o/e.k0):j()})},"cea","Equal Area Cylindrical","Cyl, Sph&Ell\nlat_ts="),tt(function(e){var n,s,o,a,l,u,p,d=1/3,f=[];for(u=0;u<3;++u)f[u]={p:{}},f[u].phi=Y(e.params,"rlat_"+(u+1)),f[u].lam=Y(e.params,"rlon_"+(u+1)),f[u].lam=At(f[u].lam-e.lam0),f[u].cosphi=r(f[u].phi),f[u].sinphi=i(f[u].phi);for(u=0;u<3;++u)p=2==u?0:u+1,f[u].v=m(f[p].phi-f[u].phi,f[u].cosphi,f[u].sinphi,f[p].cosphi,f[p].sinphi,f[p].lam-f[u].lam),f[u].v.r||U(-25);function m(e,n,s,o,a,l){var u,p,d,f={};return u=r(l),t(e)>1||t(l)>1?f.r=Qe(cs1*a+n*o*u):(p=i(.5*e),d=i(.5*l),f.r=2*Je(h(p*p+n*o*d*d))),t(f.r)>1e-9?f.Az=c(o*i(l),n*a-s*o*u):f.r=f.Az=0,f}function _(t,e,i){return Qe(.5*(t*t+e*e-i*i)/(t*e))}o=_(f[0].v.r,f[2].v.r,f[1].v.r),a=_(f[0].v.r,f[1].v.r,f[2].v.r),l=b-o,s=2*(f[0].p.y=f[1].p.y=f[2].v.r*i(o)),f[2].p.y=0,f[0].p.x=-(f[1].p.x=.5*f[0].v.r),n=f[2].p.x=f[0].p.x+f[2].v.r*r(o),e.es=0,e.fwd=function(t,e){var o,c,h,u,p,g,y,v=[];for(o=i(t.phi),c=r(t.phi),u=0;u<3&&(v[u]=m(t.phi-f[u].phi,f[u].cosphi,f[u].sinphi,c,o,t.lam-f[u].lam),v[u].r);++u)v[u].Az=At(v[u].Az-f[u].v.Az);if(u<3)g=f[u].p.x,y=f[u].p.y;else{for(g=n,y=s,u=0;u<3;++u)p=2==u?0:u+1,h=_(f[u].v.r,v[u].r,v[p].r),v[u].Az<0&&(h=-h),u?1==u?(h=a-h,g-=v[u].r*r(h),y-=v[u].r*i(h)):(h=l-h,g+=v[u].r*r(h),y+=v[u].r*i(h)):(g+=v[u].r*r(h),y-=v[u].r*i(h));g*=d,y*=d}e.x=g,e.y=y}},"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*s(.32573500793527993*t.y),i.lam=1.0233267079464885*t.x/(2*r((i.phi+i.phi)*e)-1)},t.fwd=function(t,n){t.phi*=e,n.x=.9772050238058398*t.lam*(2*r(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,o=1/Math.sqrt(e*n),a=.9701,l=d(22*T),c=f(0),u=i(l),p=r(l);function d(t){return s(n*i(t)+.4188*h(e*n))}function f(t){return e*t}Y(t.params,"tlon_0")||(t.lam0=11.023*T),t.es=0,t.fwd=function(t,e){var n=d(t.phi),s=f(t.lam),m=i(n),_=r(n),g=i(s-c),y=r(s-c),v=h(2/(1+i(l)*m+p*_*y));e.x=o*v*_*g*a,e.y=o*v*(p*m-u*_*y)/a}},"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*=r((.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,r=.3183098861837907;e.es=0,e.fwd=function(e,n){n.x=i*e.lam*(1-r*t(e.phi)),n.y=i*e.phi},e.inv=function(e,n){n.phi=e.y/i,n.lam=e.x/(i*(1-r*t(n.phi)))}},"eck1","Eckert I","PCyl Sph"),tt(function(e){var r=.46065886596178063,n=1.4472025091165353;e.es=0,e.fwd=function(e,s){s.x=r*e.lam*(s.y=h(4-3*i(t(e.phi)))),s.y=n*(2-s.y),e.phi<0&&(s.y=-s.y)},e.inv=function(e,i){i.lam=e.x/(r*(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?-E:E:i.phi=s(i.phi),e.y<0&&(i.phi=-i.phi)}},"eck2","Eckert II","PCyl Sph"),tt(function(t){oi(t,{C_x:.4222382003157712,C_y:.8444764006315424,A:1,B:.4052847345693511})},"eck3","Eckert III","PCyl Sph"),tt(function(t){oi(t,{C_x:.94745,C_y:.94745,A:0,B:.3039635509270133})},"wag6","Wagner VI","PCyl Sph"),tt(function(t){oi(t,{C_x:.8660254037844,C_y:1,A:0,B:.3039635509270133})},"kav7","Kavraisky VII","PCyl Sph"),tt(function(t){oi(t,{C_x:1.8949,C_y:.94745,A:-.5,B:.3039635509270133})},"putp1","Putnins P1","PCyl Sph"),tt(function(e){var n=.4222382003157712,s=1.3265004281770023,o=3.5707963267948966;e.es=0,e.fwd=function(e,a){var l,c,h,u,p;for(l=o*i(e.phi),c=e.phi*e.phi,e.phi*=.895168+c*(.0218849+.00826809*c),p=6;p&&(u=r(e.phi),h=i(e.phi),e.phi-=c=(e.phi+h*(u+2)-l)/(1+u*(u+2)-h*h),!(t(c)<1e-7));--p);p?(a.x=n*e.lam*(1+r(e.phi)),a.y=s*i(e.phi)):(a.x=n*e.lam,a.y=e.phi<0?-s:s)},e.inv=function(t,e){var a;e.phi=Je(t.y/s),e.lam=t.x/(n*(1+(a=r(e.phi)))),e.phi=Je((e.phi+i(e.phi)*(a+2))/o)}},"eck4","Eckert IV","PCyl Sph"),tt(function(t){t.es=0,t.fwd=function(t,e){e.x=.4410127717245515*(1+r(t.phi))*t.lam,e.y=.882025543449103*t.phi},t.inv=function(t,e){e.lam=2.267508027238226*t.x/(1+r(e.phi=1.133754013619113*t.y))}},"eck5","Eckert V","PCyl Sph"),tt(function(t){var e=r(Y(t.params,"rlat_ts"));e<=0&&U(-24),t.es=0,t.fwd=function(i,r){r.x=e*i.lam,r.y=i.phi-t.phi0},t.inv=function(i,r){r.lam=i.x/e,r.phi=i.y+t.phi0}},"eqc","Equidistant Cylindrical (Plate Caree)","Cyl, Sph\nlat_ts=[, lat_0=0]"),tt(function(e){var n,s,o,a,l,h,u,p,d,m,_,g,y;n=Y(e.params,"rlat_1"),s=Y(e.params,"rlat_2"),t(n+s)<R&&U(-21),(u=Xe(e.es))||e_error_0(),o=m=i(n),d=r(n),_=t(n-s)>=R,(p=e.es>0)?(y=We(m,d,e.es),g=Ye(n,m,d,u),_&&(m=i(s),d=r(s),o=(y-We(m,d,e.es))/(Ye(s,m,d,u)-g)),l=(h=g+y/o)-Ye(e.phi0,i(e.phi0),r(e.phi0),u)):(_&&(o=(d-r(s))/(s-n)),h=n+r(n)/o,l=h-e.phi0),e.fwd=function(t,e){a=h-(p?Ye(t.phi,i(t.phi),r(t.phi),u):t.phi),e.x=a*i(t.lam*=o),e.y=l-a*r(t.lam)},e.inv=function(t,i){0!=(a=f(t.x,t.y=l-t.y))?(o<0&&(a=-a,t.x=-t.x,t.y=-t.y),i.phi=h-a,p&&(i.phi=Ke(i.phi,e.es,u)),i.lam=c(t.x,t.y)/o):(i.lam=0,i.phi=o>0?E:-E)}},"eqdc","Equidistant Conic","Conic, Sph&Ell\nlat_1= lat_2="),tt(function(t){var e=1.340264,i=-.081106,r=893e-6,n=.003796,s=Math.sqrt(3)/2;t.es=0,t.fwd=function(t,o){var a=Math.asin(s*Math.sin(t.phi)),l=a*a,c=l*l*l;o.x=t.lam*Math.cos(a)/(s*(e+3*i*l+c*(7*r+9*n*l))),o.y=a*(e+i*l+c*(r+n*l))},t.inv=function(t,o){var a,l,c,h,u=t.y;for(h=0;h<12&&(u-=c=(u*(e+i*(a=u*u)+(l=a*a*a)*(r+n*a))-t.y)/(e+3*i*a+l*(7*r+9*n*a)),!(Math.abs(c)<1e-9));++h);l=(a=u*u)*a*a,o.lam=s*t.x*(e+3*i*a+l*(7*r+9*n*a))/Math.cos(u),o.phi=Math.asin(Math.sin(u)/s)}},"eqearth","Equal Earth","PCyl., Sph."),tt(ai,"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*l(.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,s,o,a,u,p,d,m=Y(t.params,"dh"),_=Y(t.params,"ssweep");_?"x"==_?d=1:"y"==_?d=0:U(-49):d=0,((u=m/t.a)<=0||u>1e10)&&U(-50),p=(a=1+u)*a-1,0!=t.es?(e=h(t.one_es),s=t.one_es,o=t.rone_es,t.inv=function(t,i){var s,m,_,g,y,v;s=-1,d?(_=n(t.y/u),m=n(t.x/u)*f(1,_)):(m=n(t.x/u),_=n(t.y/u)*f(1,m));var x=(y=2*a*s)*y-4*(g=m*m+(g=_/e)*g+s*s)*p;x<0&&U(-51),v=(-y-h(x))/(2*g),s=a+v*s,m*=v,_*=v,i.lam=c(m,s),i.phi=l(_*r(i.lam)/s),i.phi=l(o*n(i.phi))},t.fwd=function(t,c){var h,p,m,_,g;t.phi=l(s*n(t.phi)),h=e/f(e*r(t.phi),i(t.phi)),p=h*r(t.lam)*r(t.phi),m=h*i(t.lam)*r(t.phi),_=h*i(t.phi),(a-p)*p-m*m-_*_*o<0&&U(-51),g=a-p,d?(c.x=u*l(m/f(_,g)),c.y=u*l(_/g)):(c.x=u*l(m/g),c.y=u*l(_/f(m,g)))}):(e=s=o=1,t.inv=function(t,e){var i,s,o,f,m,_;i=-1,d?(o=n(t.y/u),s=n(t.x/u)*h(1+o*o)):(s=n(t.x/u),o=n(t.y/u)*h(1+s*s));var g=(m=2*a*i)*m-4*(f=s*s+o*o+i*i)*p;g<0&&U(-51),_=(-m-h(g))/(2*f),i=a+_*i,s*=_,o*=_,e.lam=c(s,i),e.phi=l(o*r(e.lam)/i)},t.fwd=function(t,e){var n=r(t.phi),s=r(t.lam)*n,o=i(t.lam)*n,c=i(t.phi);n=a-s,d?(e.x=u*l(o/f(c,n)),e.y=u*l(c/n)):(e.x=u*l(o/n),e.y=u*l(c/f(o,n)))})},"geos","Geostationary Satellite View","Azi, Sph&Ell"),tt(function(t){var e=a(Y(t.params,"tlat_1")?Y(t.params,"rlat_1"):0),s=i(e),o=r(e);function a(t){return Je(n(.5*t))}t.fwd=function(t,e){var n=.5*t.lam,l=a(t.phi),c=i(l),h=r(l),u=r(n);s*c+o*h*u>=0?(e.x=h*i(n),e.y=o*c-s*h*u):V()},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){Y(t.params,"tn"),Y(t.params,"tm")?ci(t,Y(t.params,"dm"),Y(t.params,"dn")):U(-99)},"gn_sinu","General Sinusoidal Series","PCyl, Sph.\nm= n="),tt(li,"sinu","Sinusoidal (Sanson-Flamsteed)","PCyl, Sph&Ell"),tt(function(t){ci(t,1,2.5707963267948966)},"eck6","Eckert VI","PCyl, Sph.\nm= n="),tt(function(t){ci(t,.5,1.7853981633974483)},"mbtfps","McBryde-Thomas Flat-Polar Sinusoidal","PCyl, Sph."),tt(function(e){var n,o,a=1e-10;t(t(e.phi0)-E)<a?o=e.phi0<0?1:0:t(e.phi0)<a?o=2:(o=3,sinph0=i(e.phi0),n=r(e.phi0)),e.inv=function(r,u){var p,d,m,_=r.x,g=r.y;if(p=f(_,g),m=i(u.phi=l(p)),d=h(1-m*m),t(p)<=a)u.phi=e.phi0,u.lam=0;else{switch(o){case 3:u.phi=d*sinph0+g*m*n/p,t(u.phi)>=1?u.phi=u.phi>0?E:-E:u.phi=s(u.phi),g=(d-sinph0*i(u.phi))*p,_*=m*n;break;case 2:u.phi=g*m/p,t(u.phi)>=1?u.phi=u.phi>0?E:-E:u.phi=s(u.phi),g=d*p,_*=m;break;case 1:u.phi-=E;break;case 0:u.phi=E-u.phi,g=-g}u.lam=c(_,g)}},e.fwd=function(t,e){var s,l,c;switch(c=i(t.phi),l=r(t.phi),s=r(t.lam),o){case 2:e.y=l*s;break;case 3:e.y=sinph0*c+n*l*s;break;case 1:e.y=-c;break;case 0:e.y=c}switch(e.y<=a&&V(),e.x=(e.y=1/e.y)*l*i(t.lam),o){case 2:e.y*=c;break;case 3:e.y*=n*c-sinph0*l*s;break;case 0:s=-s;case 1:e.y*=l*s}},e.es=0},"gnom","Gnomonic","Azi, Sph."),tt(hi,"moll","Mollweide","PCyl Sph"),tt(function(t){pi(t,ui(0,b/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,r,n,s,o=.0528,a=.7109307819790236;e.es=0,li(e),i=e.fwd,r=e.inv,hi(e),n=e.fwd,s=e.inv,e.fwd=function(e,r){t(e.phi)<a?i(e,r):(n(e,r),r.y-=e.phi>0?o:-o)},e.inv=function(e,i){t(e.y)<=a?r(e,i):(e.y+=e.y>0?o:-o,s(e,i))}},"goode","Goode Homolosine","PCyl, Sph."),tt(function(e){var n,s,o;e.inv=function(e,i){var r=h(1-.25*n*n*e.x*e.x-.25*e.y*e.y);t(2*r*r-1)<1e-10?(i.lam=v,i.phi=v,pj_errno=-14):(i.lam=ei(n*e.x*r,2*r*r-1)/n,i.phi=Je(r*e.y))},e.fwd=function(t,e){var a,l;l=h(2/(1+(a=r(t.phi))*r(t.lam*=n))),e.x=s*l*a*i(t.lam),e.y=o*l*i(t.phi)},e.es=0,Y(e.params,"tW")?(n=t(Y(e.params,"dW")))<=0&&U(-27):n=.5,Y(e.params,"tM")?(s=t(Y(e.params,"dM")))<=0&&U(-27):s=1,o=1/s,s/=n},"hammer","Hammer & Eckert-Greifendorff","Misc Sph,\nW= M="),tt(function(e){var n=1.000001;e.inv=function(e,o){var a=e.y*(e.y<0?.5179951515653813:.5686373742600607);t(a)>1?t(a)>n?j():a=a>0?E:-E:a=s(a),o.lam=1.1764705882352942*e.x/r(a),a+=a,o.phi=(a+i(a))*(e.y<0?.4102345310814193:.3736990601468637),t(o.phi)>1?t(o.phi)>n?j():o.phi=o.phi>0?E:-E:o.phi=s(o.phi)},e.fwd=function(e,n){var s,o,a;for(o=i(e.phi)*(e.phi<0?2.43763:2.67595),a=20;a&&(e.phi-=s=(e.phi+i(e.phi)-o)/(1+r(e.phi)),!(t(s)<1e-7));--a);n.x=.85*e.lam*r(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(di,"healpix","HEALPix","Sph., Ellps."),tt(function(t){di(t,!0)},"rhealpix","rHEALPix","Sph., Ellps.\nnorth_square= south_square="),tt(function(e){var n,o=i(.5),l=s(o),u=2*h(b/(n=b+4*l*2)),p=.5*u*(2+h(3));e.es=0,e.fwd=function(e,s){var o,a,d=1-i(e.phi);if(d&&d<2){var f,m,_,g,y,v=E-e.phi,x=25;do{m=i(v),_=r(v),y=l+c(m,2-_),v-=f=(v-1*l-2*m+(g=5-4*_)*y-.5*d*n)/(4*m*y)}while(t(f)>1e-12&&--x>0);o=u*h(g),a=e.lam*y/b}else o=u*(1+d),a=e.lam*l/b;s.x=o*i(a),s.y=p-o*r(a)},e.inv=function(t,e){var r=t.x,o=t.y,d=r*r+(o-=p)*o,f=(5-d/(u*u))/4,m=a(f),_=i(m),g=l+c(_,2-f);e.lam=s(r/h(d))*b/g,e.phi=s(1-2*(m-1*l-2*_+(5-4*f)*g)/n)}},"hill","Hill Eucyclic","PCyl., Sph."),tt(function(e){var o,a,p,d,f,m,_,g,y,v=.785398163397448,x=1.37008346281555;e.a=6377397.155,e.e=h(e.es=.006674372230614),Y(e.params,"tlat_0")||(e.phi0=.863937979737193),Y(e.params,"tlon_0")||(e.lam0=.4334234309119251),Y(e.params,"tk")||(e.k0=.9999),y=1,Y(e.params,"tczech")||(y=-1),d=h(1+e.es*u(r(e.phi0),4)/(1-e.es)),o=s(i(e.phi0)/d),p=u((1+e.e*i(e.phi0))/(1-e.e*i(e.phi0)),d*e.e/2),f=n(o/2+v)/u(n(e.phi0/2+v),d)*p,a=h(1-e.es)/(1-e.es*u(i(e.phi0),2)),m=i(x),_=e.k0*a/n(x),g=.5286277629901559,e.inv=function(o,a){var p,b,w,S,T,C,M,A;M=o.x,o.x=o.y,o.y=M,o.x*=y,o.y*=y,T=h(o.x*o.x+o.y*o.y),S=c(o.y,o.x)/i(x),w=2*(l(u(_/T,1/m)*n(x/2+v))-v),p=s(r(g)*i(w)-i(g)*r(w)*r(S)),b=s(r(w)*i(S)/r(p)),a.lam=e.lam0-b/d,C=p,A=0;do{a.phi=2*(l(u(f,-1/d)*u(n(p/2+v),1/d)*u((1+e.e*i(C))/(1-e.e*i(C)),e.e/2))-v),t(C-a.phi)<1e-15&&(A=1),C=a.phi}while(0===A);a.lam-=e.lam0},e.fwd=function(t,o){var a,c,h,p,b,w,S;a=u((1+e.e*i(t.phi))/(1-e.e*i(t.phi)),d*e.e/2),c=2*(l(f*u(n(t.phi/2+v),d)/a)-v),h=-t.lam*d,p=s(r(g)*i(c)+i(g)*r(c)*r(h)),b=s(r(c)*i(h)/r(p)),w=m*b,S=_*u(n(x/2+v),m)/u(n(p/2+v),m),o.y=S*r(w),o.x=S*i(w),o.y*=y,o.x*=y}},"krovak","Krovak","PCyl., Ellps."),tt(function(e){var n,o,a,l,u,p,d,m,_,g,y,v=1e-10;if(g=t(e.phi0),_=t(g-E)<v?e.phi0<0?1:0:t(g)<v?2:3,e.es){switch(e.e=h(e.es),u=Ze(1,e.e,e.one_es),e.es,m=ni(e.es),_){case 0:case 1:p=1;break;case 2:p=1/(d=h(.5*u)),a=1,l=.5*u;break;case 3:d=h(.5*u),y=i(e.phi0),n=Ze(y,e.e,e.one_es)/u,o=h(1-n*n),p=r(e.phi0)/(h(1-e.es*y*y)*d*o),l=(a=d)/p,a*=p}e.inv=function(t,a){var l,h,g,y,x=0;switch(_){case 2:case 3:if(t.x/=p,t.y*=p,(y=f(t.x,t.y))<v)return a.lam=0,a.phi=e.phi0,a;h=2*s(.5*y/d),l=r(h),h=i(h),t.x*=h,3==_?(x=l*n+t.y*h*o/y,t.y=y*o*l-t.y*n*h):(x=t.y*h/y,t.y=y*l);break;case 0:t.y=-t.y;case 1:if(!(g=t.x*t.x+t.y*t.y))return a.lam=0,a.phi=e.phi0,a;x=1-g/u,1==_&&(x=-x)}return a.lam=c(t.x,t.y),a.phi=si(s(x),m),a},e.fwd=function(s,c){var p,d,f,m,g=0,y=0,x=0;switch(p=r(s.lam),d=i(s.lam),f=i(s.phi),m=Ze(f,e.e,e.one_es),(3==_||2==_)&&(y=h(1-(g=m/u)*g)),_){case 3:x=1+n*g+o*y*p;break;case 2:x=1+y*p;break;case 0:x=E+s.phi,m=u-m;break;case 1:x=s.phi-E,m=u+m}switch(t(x)<v&&V(),_){case 3:case 2:3==_?(x=h(2/x),c.y=l*x*(o*g-n*y*p)):(x=h(2/(1+y*p)),c.y=x*g*l),c.x=a*x*y*d;break;case 0:case 1:m>=0?(x=h(m),c.x=x*d,c.y=p*(1==_?x:-x)):c.x=c.y=0}}}else 3==_&&(n=i(e.phi0),o=r(e.phi0)),e.inv=function(a,l){var h,u=0,p=0;switch(h=f(a.x,a.y),(l.phi=.5*h)>1&&j(),l.phi=2*s(l.phi),(3==_||2==_)&&(p=i(l.phi),u=r(l.phi)),_){case 2:l.phi=t(h)<=v?0:s(a.y*p/h),a.x*=p,a.y=u*h;break;case 3:l.phi=t(h)<=v?e.phi0:s(u*n+a.y*p*o/h),a.x*=p*o,a.y=(u-i(l.phi)*n)*h;break;case 0:a.y=-a.y,l.phi=E-l.phi;break;case 1:l.phi-=E}l.lam=0!=a.y||2!=_&&3!=_?c(a.x,a.y):0},e.fwd=function(s,a){var l,c,u;switch(u=i(s.phi),c=r(s.phi),l=r(s.lam),_){case 2:case 3:a.y=2==_?1+c*l:1+n*u+o*c*l,a.y<=v&&V(),a.y=h(2/a.y),a.x=a.y*c*i(s.lam),a.y*=2==_?u:o*u-n*c*l;break;case 0:l=-l;case 1:t(s.phi+e.phi0)<v&&V(),a.y=A-.5*s.phi,a.y=2*(1==_?r(a.y):i(a.y)),a.x=a.y*i(s.lam),a.y*=l}}},"laea","Lambert Azimuthal Equal Area","Azi, Sph&Ell"),tt(fi,"lonlat","Lat/long (Geodetic)",""),tt(fi,"longlat","Lat/long (Geodetic alias)",""),tt(fi,"latlon","Lat/long (Geodetic alias)",""),tt(fi,"latlong","Lat/long (Geodetic alias)",""),tt(function(e){var s,o,a,p,m,_,g,y,x,b,w,S=1e-10;e.inv=function(t,i){var r,n=t.x,s=t.y;n/=e.k0,s/=e.k0,0!=(r=f(n,s=g-s))?(_<0&&(r=-r,n=-n,s=-s),x?(i.phi=_i(u(r/y,1/_),e.e),i.phi==v&&j()):i.phi=2*l(u(y/r,1/_))-E,i.lam=c(n,s)/_):(i.lam=0,i.phi=_>0?E:-E)},e.fwd=function(s,o){var a,l=s.lam;t(t(s.phi)-E)<S?(s.phi*_<=0&&V(),a=0):a=y*(x?u(mi(s.phi,i(s.phi),e.e),_):u(n(A+.5*s.phi),-_)),l*=_,o.x=e.k0*(a*i(l)),o.y=e.k0*(g-a*r(l))},p=Y(e.params,"rlat_1"),Y(e.params,"tlat_2")?m=Y(e.params,"rlat_2"):(m=p,Y(e.params,"tlat_0")||(e.phi0=p)),t(p+m)<S&&U(-21),_=o=i(p),s=r(p),a=t(p-m)>=S,(x=0!=e.es)?(e.e=h(e.es),w=We(o,s,e.es),b=mi(p,o,e.e),a&&(o=i(m),_=d(w/We(o,r(m),e.es)),_/=d(b/mi(m,o,e.e))),y=g=w*u(b,-_)/_,g*=t(t(e.phi0)-E)<S?0:u(mi(e.phi0,i(e.phi0),e.e),_)):(a&&(_=d(s/r(m))/d(n(A+.5*m)/n(A+.5*p))),y=s*u(n(A+.5*p),_)/_,g=t(t(e.phi0)-E)<S?0:y*u(n(A+.5*e.phi0),-_))},"lcc","Lambert Conformal Conic","Conic, Sph&Ell\nlat_1= and lat_2= or lat_0="),tt(function(e){var i,s,o,a=1e-8;i=Y(e.params,"rlat_1"),s=r(i),o=n(A+.5*i),s<a&&U(-22),e.fwd=function(e,r){r.y=e.phi-i,t(r.y)<a?r.x=e.lam*s:(r.x=A+.5*e.phi,t(r.x)<a||t(t(r.x)-E)<a?r.x=0:r.x=e.lam*r.y/d(n(r.x)/o))},e.inv=function(e,r){r.phi=e.y+i,t(e.y)<a?r.lam=e.x/s:(r.lam=A+.5*r.phi,t(r.lam)<a||t(t(r.lam)-E)<a?r.lam=0:r.lam=e.x*d(n(r.lam)/o)/e.y)},e.es=0},"loxim","Loximuthal","PCyl Sph"),tt(function(e){var n=.9525793444156804,o=.9258200997725514,a=3.401680257083045,l=2/3,c=1/3,h=1.0000001;e.fwd=function(t,e){t.phi=s(n*i(t.phi)),e.x=o*t.lam*(2*r(l*t.phi)-1),e.y=a*i(c*t.phi)},e.inv=function(e,c){c.phi=e.y/a,t(c.phi)>=1?t(c.phi)>h?j():c.phi=c.phi<0?-E:E:c.phi=s(c.phi),c.lam=e.x/(o*(2*r(l*(c.phi*=3))-1)),t(c.phi=i(c.phi)/n)>=1?t(c.phi)>h?j():c.phi=c.phi<0?-E:E:c.phi=s(c.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 s,o,a;for(o=1.7071067811865475*i(e.phi),a=20;a&&(e.phi-=s=(i(.5*e.phi)+i(e.phi)-o)/(.5*r(.5*e.phi)+r(e.phi)),!(t(s)<1e-7));--a);n.x=.3124597141037825*e.lam*(1+2*r(e.phi)/r(.5*e.phi)),n.y=1.874758284622695*i(.5*e.phi)},e.inv=function(e,o){var a;o.phi=.533402096794177*e.y,t(o.phi)>1?t(o.phi)>n?j():o.phi<0?(a=-1,o.phi=-b):(a=1,o.phi=b):o.phi=2*s(a=o.phi),o.lam=3.2004125807650623*e.x/(1+2*r(o.phi)/r(.5*o.phi)),o.phi=.585786437626905*(a+i(o.phi)),t(o.phi)>1?t(o.phi)>n?j():o.phi=o.phi<0?-E:E:o.phi=s(o.phi)},e.es=0},"mbt_fpq","McBryde-Thomas Flat-Polar Quartic","Cyl., Sph."),tt(function(e){var n=.45503,s=1.36509,o=1.41546,a=.22248,l=1.44492,c=1/3;e.fwd=function(e,h){var u,p,d,f;for(u=o*i(e.phi),f=10;f&&(d=e.phi/s,e.phi-=p=(n*i(d)+i(e.phi)-u)/(c*r(d)+r(e.phi)),!(t(p)<1e-7));--f);d=e.phi/s,h.x=a*e.lam*(1+3*r(e.phi)/r(d)),h.y=l*i(d)},e.inv=function(t,e){var c;e.phi=s*(c=Je(t.y/l)),e.lam=t.x/(a*(1+3*r(e.phi)/r(c))),e.phi=Je((n*i(c)+i(e.phi))/o)},e.es=0},"mbt_fps","McBryde-Thomas Flat-Pole Sine (No. 2)","Cyl., Sph."),tt(function(e){var s=1e-10,o=0,a=Y(e.params,"tlat_ts");a&&(o=Y(e.params,"rlat_ts"))>=E&&U(-24),e.es?(a&&(e.k0=We(i(o),r(o),e.es)),e.inv=function(t,i){i.phi=_i(p(-t.y/e.k0),e.e),i.phi===v&&j(),i.lam=t.x/e.k0},e.fwd=function(r,n){t(t(r.phi)-E)<=s&&V(),n.x=e.k0*r.lam,n.y=-e.k0*d(mi(r.phi,i(r.phi),e.e))}):(e.inv=function(t,i){i.phi=E-2*l(p(-t.y/e.k0)),i.lam=t.x/e.k0},e.fwd=function(i,r){t(t(i.phi)-E)<=s&&V(),r.x=e.k0*i.lam,r.y=e.k0*d(n(A+.5*i.phi))})},"merc","Mercator","Cyl, Sph&Ell\nlat_ts="),tt(function(e){e.k0=1,e.inv=function(t,i){i.phi=E-2*l(p(-t.y/e.k0)),i.lam=t.x/e.k0},e.fwd=function(i,r){t(t(i.phi)-E)<=R&&V(),r.x=e.k0*i.lam,r.y=e.k0*d(n(A+.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*d(n(A+.4*t.phi))},t.inv=function(t,e){e.lam=t.x,e.phi=2.5*(l(p(.8*t.y))-A)},t.es=0},"mill","Miller Cylindrical","Cyl, Sph"),tt(function(t){t.lam0=20*T,t.phi0=18*T,t.es=0,vi(t,[[.9245,0],[0,0],[.01943,0]])},"mil_os","Miller Oblated Stereographic","Azi(mod)"),tt(function(t){t.lam0=-165*T,t.phi0=-10*T,t.es=0,vi(t,[[.721316,0],[0,0],[-.0088162,-.00617325]])},"lee_os","Lee Oblated Stereographic","Azi(mod)"),tt(function(t){t.lam0=-96*T,t.phi0=39*T,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*T,t.phi0=64*T,0!=t.es?(e=[[.9945303,0],[.0052083,-.0027404],[.0072721,.0048181],[-.0151089,-.1932526],[.0642675,-.1381226],[.3582802,-.2884586]],t.a=6378206.4,t.e=h(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*T,t.phi0=45*T,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=h(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,r=-.131979,n=-.013791,s=.003971,o=-.001529,a=1.007226,l=.015085,c=-.044475,h=.028874,u=-.005916,p=a,d=3*l,f=7*c,m=9*h,_=11*u,g=.8707*.52*b;e.es=0,e.fwd=function(t,e){var p,d;d=(p=t.phi*t.phi)*p,e.x=t.lam*(i+p*(r+p*(n+d*p*(s+p*o)))),e.y=t.phi*(a+p*(l+d*(c+h*p+u*d)))},e.inv=function(e,y){var v,x,b,w,S=e.x,T=e.y;for(T>g?T=g:T<-g&&(T=-g),v=T;v-=x=(v*(a+(b=v*v)*(l+(w=b*b)*(c+h*b+u*w)))-T)/(p+b*(d+w*(f+m*b+_*w))),!(t(x)<1e-11););y.phi=v,b=v*v,y.lam=S/(i+b*(r+b*(n+b*b*b*(s+b*o))))}},"natearth","Natural Earth","PCyl., Sph."),tt(function(e){var i=.84719,r=-.13063,n=-.04515,s=.05494,o=-.02326,a=.00331,l=1.01183,c=-.02625,h=.01926,u=-.00396,p=l,d=9*c,f=.45334622460635143*b;e.es=0,e.fwd=function(t,e){var p,d,f;f=(p=t.phi*t.phi)*(d=p*p),e.x=t.lam*(i+r*p+f*f*(n+s*p+o*d+a*f)),e.y=t.phi*(l+d*d*(c+h*p+u*d))},e.inv=function(e,m){var _,g,y,v,x,b=e.x,w=e.y;for(w>f?w=f:w<-f&&(w=-f),_=w;_-=g=(_*(l+(v=(y=_*_)*y)*v*(c+h*y+u*v))-w)/(p+v*v*(d+.21186*y+-.05148*v)),!(t(g)<1e-11););m.phi=_,x=(y=_*_)*(v=y*y),m.lam=b/(i+r*y+x*x*(n+s*y+o*v+a*x))}},"natearth2","Natural Earth 2","PCyl., Sph."),tt(function(e){e.inv=function(t,e){e.lam=2*t.x/(1+r(t.y)),e.phi=Je(.5*(t.y+i(t.y)))},e.fwd=function(e,n){var s,o,a;for(s=2*i(e.phi),o=e.phi*e.phi,e.phi*=1.00371+o*(-.011412*o-.0935382),a=10;a&&(e.phi-=o=(e.phi+i(e.phi)-s)/(1+r(e.phi)),!(t(o)<1e-7));--a);n.x=.5*e.lam*(1+r(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+r(t.phi)),e.y=2*(t.phi-n(.5*t.phi))},e.inv=function(e,i){var s,o,a,l;for(a=.5*e.y,l=9;l>0&&(o=r(.5*i.phi),i.phi-=s=(i.phi-n(i.phi/2)-a)/(1-.5/(o*o)),!(t(s)<1e-7));--l);l?i.lam=2*e.x/(1+r(i.phi)):(i.phi=a<0?-E:E,i.lam=2*e.x)}},"nell_h","Nell-Hammer","PCyl., Sph."),tt(function(e){e.es=0,e.fwd=function(e,n){var s=1e-10;if(t(e.lam)<s)n.x=0,n.y=e.phi;else if(t(e.phi)<s)n.x=e.lam,n.y=0;else if(t(t(e.lam)-E)<s)n.x=e.lam*r(e.phi),n.y=E*i(e.phi);else if(t(t(e.phi)-E)<s)n.x=0,n.y=e.phi;else{var o=E/e.lam-e.lam/E,a=e.phi/E,l=i(e.phi),c=(1-a*a)/(l-a),u=o/c,p=(o*l/c-.5*o)/(1+(u*=u)),d=(l/u+.5*c)/(1+1/u);n.x=r(e.phi),n.x=h(p*p+n.x*n.x/(1+u)),n.x=E*(p+(e.lam<0?-n.x:n.x)),n.y=h(d*d-(l*l/u+c*l-1)/(1+1/u)),n.y=E*(d+(e.phi<0?n.y:-n.y))}}},"nicol","Nicolosi Globular","Misc Sph, no inv"),tt(function(t){xi(t,Y(t.params,"dh"))},"nsper","Near-sided perspective","Azi, Sph\nh="),tt(function(t){var e=Y(t.params,"dtilt")*T,i=Y(t.params,"dazi")*T,r=Y(t.params,"dh");xi(t,r,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]],r=[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*T,e.phi0=-41*T,e.x0=251e4,e.y0=6023150,e.inv=function(n,s){var o,a,l,c,h,u,p={r:n.y,i:n.x},d={};for(o=20;o>0&&((h=yi(p,i,d)).r-=n.y,h.i-=n.x,u=d.r*d.r+d.i*d.i,p.r+=l=-(h.r*d.r+h.i*d.i)/u,p.i+=c=-(h.i*d.r-h.r*d.i)/u,!(t(l)+t(c)<=1e-10));--o);if(o>0){for(s.lam=p.i,a=r.length-1,s.phi=r[a],--a;a>=0;--a)s.phi=r[a]+p.r*s.phi;s.phi=e.phi0+p.r*s.phi*.484813681109536}else s.lam=s.phi=v},e.fwd=function(t,r){var s=n.length-1,o={r:n[s]},a=2.0626480624709638*(t.phi-e.phi0);for(--s;s>=0;--s)o.r=n[s]+a*o.r;o.r*=a,o.i=t.lam,o=gi(o,i),r.x=o.i,r.y=o.r}},"nzmg","New Zealand Map Grid","fixed Earth"),tt(function(e){var s,o,a,h,u,p,d,f,m,_,g,y,x,b,w,C=1e-10;s=Y(e.params,"so_proj"),o=Q[s],s||U(-26),o&&"ob_tran"!=s||U(-37),e.es=0,a={},Object.keys(e).forEach(function(t){a[t]=e[t]}),o.init(a),a.is_latlong&&1==e.to_meter&&(e.to_meter=T,e.fr_meter=S),Y(e.params,"to_alpha")?(f=Y(e.params,"ro_lon_c"),m=Y(e.params,"ro_lat_c"),_=Y(e.params,"ro_alpha"),t(t(m)-E)<=C&&U(-32),h=f+ei(-r(_),-i(_)*i(m)),d=Je(r(m)*i(_))):Y(e.params,"to_lat_p")?(h=Y(e.params,"ro_lon_p"),d=Y(e.params,"ro_lat_p")):(g=Y(e.params,"ro_lon_1"),x=Y(e.params,"ro_lat_1"),y=Y(e.params,"ro_lon_2"),b=Y(e.params,"ro_lat_2"),(t(x-b)<=C||(w=t(x))<=C||t(w-E)<=C||t(t(b)-E)<=C)&&U(-33),h=c(r(x)*i(b)*r(g)-i(x)*r(b)*r(y),i(x)*r(b)*i(y)-r(x)*i(b)*i(g)),d=l(-r(h-g)/n(x))),t(d)>C?(u=r(d),p=i(d),e.fwd=function(t,e){var n,s,o;n=r(t.lam),s=i(t.phi),o=r(t.phi),t.lam=At(ei(o*i(t.lam),p*o*n+u*s)+h),t.phi=Je(p*s-u*o*n),a.fwd(t,e)},e.inv=a.inv?function(t,e){var n,s,o;a.inv(t,e),e.lam!=v&&(n=r(e.lam-=h),s=i(e.phi),o=r(e.phi),e.phi=Je(p*s+u*o*n),e.lam=ei(o*i(e.lam),p*o*n-u*s))}:null):(e.fwd=function(t,e){var n,s;n=r(t.phi),s=r(t.lam),t.lam=At(ei(n*i(t.lam),i(t.phi))+h),t.phi=Je(-n*s),a.fwd(t,e)},e.inv=a.inv?function(t,e){var n,s;a.inv(t,e),e.lam!=v&&(n=r(e.phi),s=e.lam-h,e.lam=ei(n*i(s),-i(e.phi)),e.phi=Je(n*r(s)))}: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,o,a,u,p,d,f,m,_,g,y;f=1/t.k0,m=t.k0,Y(t.params,"talpha")?(d=Y(t.params,"ralpha"),p=Y(t.params,"rlonc"),y=l(-r(d)/(-i(0)*i(d)))+p,_=s(r(0)*i(d))):(e=Y(t.params,"rlat_1"),o=Y(t.params,"rlat_2"),a=Y(t.params,"rlon_1"),u=Y(t.params,"rlon_2"),y=c(r(e)*i(o)*r(a)-i(e)*r(o)*r(u),i(e)*r(o)*i(u)-r(e)*i(o)*i(a)),a==-E&&(y=-y),_=l(-r(y-a)/n(e))),t.lam0=y+E,g=r(_),_=i(_),y=i(y),t.es=0,t.fwd=function(t,e){var s;e.y=i(t.lam),s=r(t.lam),e.x=l((n(t.phi)*g+_*e.y)/s),s<0&&(e.x+=b),e.x*=m,e.y=f*(_*i(t.phi)-g*r(t.phi)*e.y)},t.inv=function(t,e){var n,o;t.y/=f,t.x/=m,n=h(1-t.y*t.y),e.phi=s(t.y*_+n*g*(o=i(t.x))),e.lam=c(n*_*o-t.y*g,n*r(t.x))}},"ocea","Oblique Cylindrical Equal Area","Cyl, Sph lonc= alpha= or\nlat_1= lat_2= lon_1= lon_2="),tt(function(e){var o,a,f,m,_,g,y,x,w,S,T,C,M,I,D,k,z,L,F,B,O,N,G,q,$,Z,W,H=1e-7,X=0,K=0,J=0,Q=0,tt=0,et=0,it=0,rt=0;W=Y(e.params,"tno_rot"),0!=(C=Y(e.params,"talpha"))&&(it=Y(e.params,"ralpha")),0!=(M=Y(e.params,"tgamma"))&&(X=Y(e.params,"rgamma")),C||M?(K=Y(e.params,"rlonc"),(rt=Y(e.params,"tno_off")||Y(e.params,"tno_uoff"))&&(Y(e.params,"sno_uoff"),Y(e.params,"sno_off"))):(J=Y(e.params,"rlon_1"),tt=Y(e.params,"rlat_1"),Q=Y(e.params,"rlon_2"),et=Y(e.params,"rlat_2"),(t(tt-et)<=H||(o=t(tt))<=H||t(o-E)<=H||t(t(e.phi0)-E)<=H||t(t(et)-E)<=H)&&U(-33)),a=h(e.one_es),t(e.phi0)>R?(x=i(e.phi0),f=r(e.phi0),o=1-e.es*x*x,D=f*f,D=h(1+e.es*D*D/e.one_es),I=D*e.k0*a/o,(_=(m=D*a/(f*h(o)))*m-1)<=0?_=0:(_=h(_),e.phi0<0&&(_=-_)),k=_+=m,k*=u(mi(e.phi0,x,e.e),D)):(D=1/a,I=e.k0,k=m=_=1),C||M?(C?(T=s(i(it)/m),M||(X=it)):it=s(m*i(T=X)),e.lam0=K-s(.5*(_-1/_)*n(T))/D):(g=u(mi(tt,i(tt),e.e),D),y=u(mi(et,i(et),e.e),D),_=k/g,w=(y-g)/(y+g),S=((S=k*k)-y*g)/(S+y*g),(o=J-Q)<-b?Q-=P:o>b&&(Q+=P),e.lam0=At(.5*(J+Q)-l(S*n(.5*D*(J-Q))/w)/D),T=l(2*i(D*At(J-e.lam0))/(_-1/_)),X=it=s(m*i(T))),B=i(T),O=r(T),N=i(X),G=r(X),L=1/(z=I*(F=1/D)),rt?Z=0:(Z=t(z*l(h(m*m-1)/r(it))),e.phi0<0&&(Z=-Z)),q=z*d(n(A-(_=.5*T))),$=z*d(n(A+_)),e.fwd=function(n,s){var o,a,l,h,p,f,m,_;t(t(n.phi)-E)>R?(o=.5*((p=k/u(mi(n.phi,i(n.phi),e.e),D))-(f=1/p)),a=.5*(p+f),h=i(D*n.lam),t(t(l=(o*B-h*O)/a)-1)<R&&V(),_=.5*z*d((1-l)/(1+l)),f=r(D*n.lam),m=t(f)<H?I*n.lam:z*c(o*O+h*B,f)):(_=n.phi>0?q:$,m=z*n.phi),W?(s.x=m,s.y=_):(m-=Z,s.x=_*G+m*N,s.y=m*G-_*N)},e.inv=function(n,s){var o,a,l,d,f,m,_;W?(a=n.y,o=n.x):(a=n.x*G-n.y*N,o=n.y*G+n.x*N+Z),d=.5*((l=p(-L*a))-1/l),f=.5*(l+1/l),m=i(L*o),t(t(_=(m*O+d*B)/f)-1)<R?(s.lam=0,s.phi=_<0?-E:E):(s.phi=k/h((1+_)/(1-_)),(s.phi=_i(u(s.phi,1/D),e.e))==v&&j(),s.lam=-F*c(d*O-m*B,r(L*o)))}},"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,o={};t(t(e.phi0)-E)<=n?o.mode=e.phi0<0?1:0:t(e.phi0)>n?(o.mode=3,o.sinph0=i(e.phi0),o.cosph0=r(e.phi0)):o.mode=2,e.fwd=function(s,a){var l,c,h;switch(c=r(s.phi),l=r(s.lam),o.mode){case 2:c*l<-1e-10&&V(),a.y=i(s.phi);break;case 3:o.sinph0*(h=i(s.phi))+o.cosph0*c*l<-1e-10&&V(),a.y=o.cosph0*h-o.sinph0*c*l;break;case 0:l=-l;case 1:t(s.phi-e.phi0)-n>E&&V(),a.y=c*l}a.x=c*i(s.lam)},e.inv=function(i,r){var l,u,p;if((p=l=f(i.x,i.y))>1&&(p-1>n&&j(),p=1),u=h(1-p*p),t(l)<=n)r.phi=e.phi0,r.lam=0;else{switch(o.mode){case 0:i.y=-i.y,r.phi=a(p);break;case 1:r.phi=-a(p);break;case 2:case 3:2==o.mode?(r.phi=i.y*p/l,i.x*=p,i.y=u*l):(r.phi=u*o.sinph0+i.y*p*o.cosph0/l,i.y=(u-o.sinph0*r.phi)*l,i.x*=p*o.cosph0),t(r.phi)>=1?r.phi=r.phi<0?-E:E:r.phi=s(r.phi)}r.lam=0!=i.y||3!=o.mode&&2!=o.mode?c(i.x,i.y):0==i.x?0:i.x<0?-E:E}},e.es=0},"ortho","Orthographic","Azi, Sph."),tt(function(e){var i=1.0148,r=.23185,n=-.14499,s=.02406,o=i,a=5*r,l=7*n,c=908571831.7;e.es=0,e.fwd=function(t,e){var o=t.phi*t.phi;e.x=t.lam,e.y=t.phi*(i+o*o*(r+o*(n+s*o)))},e.inv=function(e,h){var u,p,d,f;for(u=e.y,e.y>c?e.y=c:e.y<-c&&(e.y=-c),f=100;f&&(u-=p=(u*(i+(d=u*u)*d*(r+d*(n+s*d)))-e.y)/(o+d*d*(a+d*(l+.21654*d))),!(t(p)<1e-11));--f);h.phi=u,h.lam=e.x}},"patterson","Patterson Cylindrical","Cyl., Sph."),tt(function(e){var o,a,l=1e-10,c=1e-12;e.es?(a=Xe(e.es),o=Ye(e.phi0,i(e.phi0),r(e.phi0),a),e.fwd=function(n,s){var c,h,u;t(n.phi)<=l?(s.x=n.lam,s.y=-o):(h=i(n.phi),c=t(u=r(n.phi))>l?We(h,u,e.es)/h:0,s.x=c*i(n.lam*=h),s.y=Ye(n.phi,h,u,a)-o+c*(1-r(n.lam)))},e.inv=function(u,p){var d,f,m,_,g,y,v,x,b,w,S=u.x,T=u.y;if(t(T+=o)<=l)p.lam=S,p.phi=0;else{for(d=T*T+S*S,p.phi=T,w=20;w>0&&(g=(m=i(p.phi))*(_=r(p.phi)),t(_)<c&&j(),f=m*(x=h(1-e.es*m*m))/_,v=(y=Ye(p.phi,m,_,a))*y+d,x=e.one_es/(x*x*x),p.phi+=b=(y+y+f*v-2*T*(f*y+1))/(e.es*g*(v-2*T*y)/f+2*(T-y)*(f*x-1/g)-x-x),!(t(b)<=c));--w);w||j(),f=i(p.phi),p.lam=s(S*n(p.phi)*h(1-e.es*f*f))/i(p.phi)}}):(o=-e.phi0,e.fwd=function(s,a){var c,h;t(s.phi)<=l?(a.x=s.lam,a.y=o):(c=1/n(s.phi),a.x=i(h=s.lam*i(s.phi))*c,a.y=s.phi-e.phi0+c*(1-r(h)))},e.inv=function(r,o){var a,c,h,u;if(t(r.y=e.phi0+r.y)<=l)o.lam=r.x,o.phi=0;else{o.phi=r.y,a=r.x*r.x+r.y*r.y,u=10;do{h=n(o.phi),o.phi-=c=(r.y*(o.phi*h+1)-o.phi-.5*(o.phi*o.phi+a)*h)/((o.phi-r.y)/h-1)}while(t(c)>1e-10&&--u);u||j(),o.lam=s(r.x*n(o.phi))/i(o.phi)}})},"poly","Polyconic (American)","Conic, Sph&Ell"),tt(function(e){var n=1.8949,s=1.71848,o=.6141848493043784,a=1.0471975511965976;e.es=0,e.fwd=function(e,l){var c,h,u,p,d;for(c=o*i(e.phi),u=e.phi*e.phi,e.phi*=.615709+u*(.00909953+.0046292*u),d=10;d&&(h=r(e.phi),u=i(e.phi),e.phi-=p=(e.phi+u*(h-1)-c)/(1+h*(h-1)-u*u),!(t(p)<1e-10));--d);d||(e.phi=e.phi<0?-a:a),l.x=n*e.lam*(r(e.phi)-.5),l.y=s*i(e.phi)},e.inv=function(t,e){var a;e.phi=Je(t.y/s),e.lam=t.x/(n*((a=r(e.phi))-.5)),e.phi=Je((e.phi+i(e.phi)*(a-1))/o)}},"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(Ti,"putp6","Putnins P6","PCyl., Sph."),tt(function(t){Ti(t,!0)},"putp6p","Putnins P6'","PCyl., Sph."),tt(function(e){var s,o,u,p;function d(e,i,r){var n,s;return e<1e-10?(n=0,s=0):(s=c(i,r),t(s)<=A?n=0:s>A&&s<=E+A?(n=1,s-=E):s>E+A||s<=-(E+A)?(n=2,s=s>=0?s-b:s+b):(n=3,s+=E)),{area:n,theta:s}}function f(t,e){var i=t+e;return i<-b?i+=P:i>+b&&(i-=P),i}s=e.phi0>=E-A/2?4:e.phi0<=-(E-A/2)?5:t(e.lam0)<=A?0:t(e.lam0)<=E+A?e.lam0>0?1:3:2,0!==e.es&&(e.a,e.a,o=e.a*h(1-e.es),u=1-(e.a-o)/e.a,p=u*u),e.fwd=function(t,o){var c,u,m,_,g,y,v,x,w,S,T,C,M,P;c=0!==e.es?l(p*n(t.phi)):t.phi,u=t.lam,4==s?(_=E-c,u>=A&&u<=E+A?(v=0,m=u-E):u>E+A||u<=-(E+A)?(v=1,m=u>0?u-b:u+b):u>-(E+A)&&u<=-A?(v=2,m=u+E):(v=3,m=u)):5==s?(_=E+c,u>=A&&u<=E+A?(v=0,m=-u+E):u<A&&u>=-A?(v=1,m=-u):u<-A&&u>=-(E+A)?(v=2,m=-u-E):(v=3,m=u>0?-u+b:-u-b)):(1==s?u=f(u,+E):2==s?u=f(u,+b):3==s&&(u=f(u,-E)),T=i(c),C=r(c),M=i(u),x=C*r(u),w=C*M,S=T,0==s?P=d(_=a(x),S,w):1==s?P=d(_=a(w),S,-x):2==s?P=d(_=a(-x),S,-w):3==s?P=d(_=a(-w),S,x):(_=0,P={area:0,theta:0}),m=P.theta,v=P.area),y=l(12/b*(m+a(i(m)*r(A))-E)),g=h((1-r(_))/(r(y)*r(y))/(1-r(l(1/r(m))))),1==v?y+=E:2==v?y+=b:3==v&&(y+=I),o.x=g*r(y),o.y=g*i(y)},e.inv=function(d,m){var _,g,y,v,x,w,S,T,C,M,A,I,P;if(g=l(h(d.x*d.x+d.y*d.y)),_=c(d.y,d.x),d.x>=0&&d.x>=t(d.y)?M=0:d.y>=0&&d.y>=t(d.x)?(M=1,_-=E):d.x<0&&-d.x>=t(d.y)?(M=2,_=_<0?_+b:_-b):(M=3,_+=E),C=b/12*n(_),x=i(C)/(r(C)-1/h(2)),w=l(x),(S=1-(y=r(_))*y*(v=n(g))*v*(1-r(l(1/r(w)))))<-1?S=-1:S>1&&(S=1),4==s)T=a(S),m.phi=E-T,m.lam=0==M?w+E:1==M?w<0?w+b:w-b:2==M?w-E:w;else if(5==s)T=a(S),m.phi=T-E,m.lam=0==M?-w+E:1==M?-w:2==M?-w-E:w<0?-w-b:-w+b;else{var D,k,z;C=(D=S)*D,k=(C+=(z=C>=1?0:h(1-C)*i(w))*z)>=1?0:h(1-C),1==M?(C=k,k=-z,z=C):2==M?(k=-k,z=-z):3==M&&(C=k,k=z,z=-C),1==s?(C=D,D=-k,k=C):2==s?(D=-D,k=-k):3==s&&(C=D,D=k,k=-C),m.phi=a(-z)-E,m.lam=c(k,D),1==s?m.lam=f(m.lam,-E):2==s?m.lam=f(m.lam,-b):3==s&&(m.lam=f(m.lam,+E))}0!==e.es&&(A=m.phi<0?1:0,I=n(m.phi),P=o/h(I*I+p),m.phi=l(h(e.a*e.a-P*P)/(u*P)),A&&(m.phi=-m.phi))}},"qsc","Quadrilateralized Spherical Cube","Azi, Sph."),tt(function(i){var r=c([[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=c([[-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,o=1.3523;function a(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 c(t){return t.map(function(t){return new Float32Array(t)})}i.es=0,i.fwd=function(i,l){var c,h;(c=e(11.459155902616464*(h=t(i.phi))))<0&&V(),c>=18&&(c=17),h=S*(h-.08726646259971647*c),l.x=a(r[c],h)*s*i.lam,l.y=a(n[c],h)*o,i.phi<0&&(l.y=-l.y)},i.inv=function(i,c){var h,u,p,d;if(c.lam=i.x/s,c.phi=t(i.y/o),c.phi>=1)c.phi>1.000001?j():(c.phi=i.y<0?-E:E,c.lam/=r[18][0]);else{if((d=e(18*c.phi))<0||d>=18)return j();for(;;)if(n[d][0]>c.phi)--d;else{if(!(n[d+1][0]<=c.phi))break;++d}for(p=new Float32Array(n[d]),h=5*(c.phi-p[0])/(n[d+1][0]-p[0]),p[0]-=c.phi;h-=u=a(p,h)/l(p,h),!(t(u)<1e-8););c.phi=(5*d+h)*T,i.y<0&&(c.phi=-c.phi),c.lam/=a(r[d],h)}}},"robin","Robinson","PCyl., Sph."),tt(Ci("EULER"),"euler","Euler","Conic, Sph\nlat_1= and lat_2="),tt(Ci("MURD1"),"murd1","Murdoch I","Conic, Sph\nlat_1= and lat_2="),tt(Ci("MURD2"),"murd2","Murdoch II","Conic, Sph\nlat_1= and lat_2="),tt(Ci("MURD3"),"murd3","Murdoch III","Conic, Sph\nlat_1= and lat_2="),tt(Ci("PCONIC"),"pconic","Perspective Conic","Conic, Sph\nlat_1= and lat_2="),tt(Ci("TISSOT"),"tissot","Tissot","Conic, Sph\nlat_1= and lat_2="),tt(Ci("VITK1"),"vitk1","Vitkovsky I","Conic, Sph\nlat_1= and lat_2="),tt(function(e){var s,o,a,c,u,f,m,_,g;a=.5*e.e,m=r(e.phi0),m*=m,o=h(1+e.es*m*m*e.rone_es),g=i(e.phi0),u=r(_=Je(f=g/o)),g*=e.e,s=d(n(A+.5*_))-o*(d(n(A+.5*e.phi0))-a*d((1+g)/(1-g))),c=e.k0*h(e.one_es)/(1-g*g),e.inv=function(h,m){var _,g,y,v,x,b,w,S,T;for(y=2*(l(p(h.y/c))-A),v=h.x/c,x=r(y),_=Je(u*i(y)+f*x*r(v)),g=Je(x*i(v)/r(_)),w=(s-d(n(A+.5*_)))/o,T=6;T&&(b=e.e*i(_),_-=S=(w+d(n(A+.5*_))-a*d((1+b)/(1-b)))*(1-b*b)*r(_)*e.rone_es,!(t(S)<1e-10));--T);T?(m.phi=_,m.lam=g/o):j()},e.fwd=function(t,h){var m,_,g,y,v,x;v=e.e*i(t.phi),m=2*l(p(o*(d(n(A+.5*t.phi))-a*d((1+v)/(1-v)))+s))-E,_=o*t.lam,x=r(m),g=Je(u*i(m)-f*x*r(_)),y=Je(x*i(_)/r(g)),h.x=c*y,h.y=c*d(n(A+.5*g))}},"somerc","Swiss. Obl. Mercator","Cyl, Ell\nFor CH1903"),tt(function(t){var e=Y(t.params,"tlat_ts")?Y(t.params,"rlat_ts"):E;Mi(t,e)},"stere","Stereographic","Azi, Sph&Ell\nlat_ts="),tt(function(t){t.phi0=Y(t.params,"bsouth")?-E:E,t.k0=.994,t.x0=2e6,t.y0=2e6,t.lam0=0,t.es||U(-34),Mi(t,E)},"ups","Universal Polar Stereographic","Azi, Sph&Ell\nsouth"),tt(function(e){var o,a,p,d,m,_,g,y,v,x=(o=e.e,a=e.phi0,p=o*o,d=i(a),m=r(a),_=h(1-p)/(1-p*d*d),g=h(1+p*m*m*m*m/(1-p)),y=s(d/g),v=.5*g*o,{e:o,K:n(.5*y+A)/(u(n(.5*a+A),g)*Ai(o*d,v)),C:g,chi:y,ratexp:v,rc:_}),b=x.chi,w=2*x.rc,S=i(b),T=r(b);e.fwd=function(t,s){var o,a,c,h;t=function(t,e){return{phi:2*l(e.K*u(n(.5*t.phi+A),e.C)*Ai(e.e*i(t.phi),e.ratexp))-E,lam:e.C*t.lam}}(t,x),a=i(t.phi),o=r(t.phi),c=r(t.lam),h=e.k0*w/(1+S*a+T*o*c),s.x=h*o*i(t.lam),s.y=h*(T*a-S*o*c)},e.inv=function(o,a){var h,p,d,m,_=o.x/e.k0,g=o.y/e.k0;(h=f(_,g))?(p=2*c(h,w),d=i(p),m=r(p),a.phi=s(m*S+g*d*T/h),a.lam=c(_*d,h*T*m-g*S*d)):(a.phi=b,a.lam=0),function(e,r){e.phi;var s,o,a=u(n(.5*e.phi+A)/r.K,1/r.C);for(e.lam/=r.C,s=20;s>0&&(o=2*l(a*Ai(r.e*i(e.phi),-.5*r.e))-E,!(t(o-e.phi)<1e-14));--s)e.phi=o;s||N(-17)}(a,x)}},"sterea","Oblique Stereographic Alternative","Azimuthal, Sph&Ell"),tt(function(t){Ei(t,1.50488,1.35439,!1)},"kav5","Kavraisky V","PCyl., Sph."),tt(function(t){Ei(t,2,2,!1)},"qua_aut","Quartic Authalic","PCyl., Sph."),tt(function(t){Ei(t,2,2,!0)},"fouc","Foucaut","PCyl., Sph."),tt(function(t){Ei(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,s){s.x=r(e.phi)*i(e.lam)/t.k0,s.y=t.k0*(c(n(e.phi),r(e.lam))-t.phi0)},t.inv=function(e,n){var o;e.y=e.y/t.k0+t.phi0,e.x*=t.k0,o=h(1-e.x*e.x),n.phi=s(o*i(e.y)),n.lam=c(e.x,o*r(e.y))}},"tcea","Transverse Cylindrical Equal Area","Cyl, Sph"),tt(function(t){t.es=0,t.fwd=function(t,e){var r=n(t.phi/2),s=i(A*r);e.x=t.lam*(.74482-.34588*s*s),e.y=1.70711*r},t.inv=function(t,e){var r=t.y/1.70711,n=i(A*r);e.lam=t.x/(.74482-.34588*n*n),e.phi=2*l(r)}},"times","Times","Cyl, Sph"),tt(function(e){Y(e.params,"bapprox")?Ii(e):function(e){if(0===e.es)return Ii(e);ai(e);var i=e.fwd,r=e.inv;Ii(e);var n=e.fwd,s=e.inv;e.fwd=function(e,r){t(e.lam)>3*T?i(e,r):n(e,r)},e.inv=function(e,i){t(e.x)>.053-.022*e.y*e.y?r(e,i):s(e,i)}}(e)},"tmerc","Transverse Mercator","Cyl, Sph&Ell"),tt(function(t){var i;t.es||U(-34),t.y0=Y(t.params,"bsouth")?1e7:0,t.x0=5e5,Y(t.params,"tzone")?(i=Y(t.params,"izone"))>0&&i<=60?--i:U(-35):(i=e(30*(At(t.lam0)+b)/b))<0?i=0:i>=60&&(i=59),t.lam0=(i+.5)*b/30-b,t.k0=.9996,t.phi0=0,ai(t)},"utm","Universal Transverse Mercator (UTM)","Cyl, Sph\nzone= south"),tt(function(t){var e,s,o,a,l,h,u,p,d,m,_,g,y,v,x,b,w,S,T,C,M,A,I;C=Y(t.params,"rlat_1"),S=Y(t.params,"rlon_1"),M=Y(t.params,"rlat_2"),T=Y(t.params,"rlon_2"),C==M&&S==T&&U(-25),t.lam0=At(.5*(S+T)),m=At(T-S),e=r(C),o=r(M),s=i(C),a=i(M),h=e*a,u=s*o,l=e*o*i(m),d=Qe(s*a+e*o*r(m)),_=.5*d,A=c(o*i(m),e*a-s*o*r(m)),v=r(I=Je(e*i(A))),x=i(I),b=At(c(e*r(A),s)-_),m*=.5,w=E-c(i(A)*s,r(A))-m,g=n(_),y=.5/i(_),p=.5/d,d*=d,t.fwd=function(t,n){var c,f,_,g,y,v,x;v=i(t.phi),x=r(t.phi),f=Qe(s*v+e*x*r(g=t.lam+m)),_=Qe(a*v+o*x*r(y=t.lam-m)),f*=f,_*=_,n.x=p*(c=f-_),c=d-c,n.y=p*ti(4*d*_-c*c),l*v-x*(h*i(g)-u*i(y))<0&&(n.y=-n.y)},t.inv=function(t,e){var n,s,o,a,l,h;o=(n=r(f(t.y,t.x+_)))+(s=r(f(t.y,t.x-_))),a=n-s,e.lam=-c(a,o*g),e.phi=Qe(f(g*o,a)*y),t.y<0&&(e.phi=-e.phi),h=i(e.phi),l=r(e.phi),e.phi=Je(x*h+v*l*(o=r(e.lam-=b))),e.lam=c(l*i(e.lam),x*l*o-v*h)+w},t.es=0},"tpeqd","Two Point Equidistant","Misc Sph\nlat_1= lon_1= lat_2= lon_2="),tt(function(t){var e,n,s,o,a,l;(o=Y(t.params,"dn"))>0&&o<=1==0&&U(-40),s=Y(t.params,"dq")/3,a=Y(t.params,"ralpha"),l=o*i(a),e=r(a)/h(1-l*l),n=1/(e*o),t.fwd=function(t,a){var l=t.phi=Je(o*i(t.phi));a.x=e*t.lam*r(t.phi),l*=l,a.y=t.phi*(1+l*s)*n},t.es=0},"urm5","Urmaev V","PCyl., Sph., no inv.\nn= q= alpha="),tt(function(t){var e=Y(t.params,"dn");(e<=0||e>1)&&U(-40),Pi(t,e)},"urmfps","Urmaev Flat-Polar Sinusoidal","PCyl, Sph.\nn="),tt(function(t){Pi(t,.8660254037844386)},"wag1","Wagner I (Kavraisky VI)","PCyl, Sph."),tt(function(e){var i=1e-10,o=.3333333333333333,l=9.869604401089358,c=19.739208802178716,u=4.934802200544679;e.fwd=function(e,r){var o,a,l,c,u;(u=t(e.phi/E))-i>1&&V(),u>1&&(u=1),t(e.phi)<=i?(r.x=e.lam,r.y=0):t(e.lam)<=i||t(u-1)<i?(r.x=0,r.y=b*n(.5*s(u)),e.phi<0&&(r.y=-r.y)):(a=(o=.5*t(b/e.lam-e.lam/b))*o,l=h(1-u*u),c=(l/=u+l-1)*l,u=l*(2/u-1),u*=u,r.x=l-u,l=u+a,r.x=b*(o*r.x+h(a*r.x*r.x-l*(c-u)))/l,e.lam<0&&(r.x=-r.x),r.y=t(r.x/b),r.y=1-r.y*(r.y+2*o),r.y<-i&&V(),r.y<0?r.y=0:r.y=h(r.y)*(e.phi<0?-b:b))},e.inv=function(e,n){var s,p,d,f,m,_,g,y,v,x,w,S,T;if(S=e.x*e.x,(w=t(e.y))<i)return n.phi=0,s=S*S+c*(S+u),n.lam=t(e.x)<=i?0:.5*(S-l+h(s))/e.x,n;T=e.y*e.y,f=(d=-b*w*((y=S+T)+l))+l*(y-3*T),p=b*w,v=2*h(-o*(_=d/(m=(g=y*y)+P*(w*y+b*(T+b*(w+E))))-o*(f/=m)*f)),(s=t(x=3*(x=.07407407407407407*f*f*f+(p*p-o*f*d)/m)/(_*v)))-i<=1?(x=s>1?x>0?0:b:a(x),n.phi=b*(v*r(x*o+4.188790204786391)-o*f),e.y<0&&(n.phi=-n.phi),s=g+c*(S-T+u),n.lam=t(e.x)<=i?0:.5*(y-l+(s<=0?0:h(s)))/e.x):j()}},"vandg","van der Grinten (I)","Misc Sph"),tt(function(t){Di(t,!1)},"vandg2","van der Grinten II","Misc Sph, no inv."),tt(function(t){Di(t,!0)},"vandg3","van der Grinten III","Misc Sph, no inv."),tt(function(e){e.es=0,e.fwd=function(e,i){var r,n,s,o,a,l,c,u,p=1e-10;t(e.phi)<p?(i.x=e.lam,i.y=0):t(e.lam)<p||t(t(e.phi)-E)<p?(i.x=0,i.y=e.phi):(l=(o=.5*((s=t(D*e.phi))*(8-s*(2+(a=s*s)))-5)/(a*(s-1)))*o,c=D*e.lam,c=h((c+=1/c)*c-4),t(e.lam)-E<0&&(c=-c),r=s+o,r=(c*((r*=r)+l-1)+2*h(r*(a+l*(u=c*c)-1)+(1-a)*(a*((n=s+3*o)*n+4*l)+l*(12*s*o+4*l))))/(4*r+u),i.x=E*r,i.y=E*h(1+c*t(r)-r*r),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,s=.88022,o=.8855;t.fwd=function(t,a){t.phi=Je(s*i(o*t.phi)),a.x=e*t.lam*r(t.phi),a.y=n*t.phi},t.inv=function(t,a){a.phi=t.y/n,a.lam=t.x/(e*r(a.phi)),a.phi=Je(i(a.phi)/s)/o}},"wag2","Wagner II","PCyl., Sph."),tt(function(t){var e=.6666666666666666,i=Y(t.params,"rlat_ts"),n=r(i)/r(2*i/3);t.es=0,t.fwd=function(t,i){i.x=n*t.lam*r(e*t.phi),i.y=t.phi},t.inv=function(t,i){i.phi=t.y,i.lam=t.x/(n*r(e*i.phi))}},"wag3","Wagner III","PCyl., Sph.\nlat_ts="),tt(function(t){t.es=0,t.fwd=function(t,e){var n,o,a;n=s(e.y=.9063077870366499*i(t.phi)),e.x=2.66723*(o=r(n))*i(t.lam/=3),e.y*=1.24104*(a=1/h(.5*(1+o*r(t.lam)))),e.x*=a}},"wag7","Wagner VII","Misc Sph, no inv."),tt(function(t){var e=r(Y(t.params,"rlat_ts"));t.fwd=function(t,i){i.x=.5*t.lam*(e+r(t.phi)),i.y=t.phi},t.inv=function(t,i){i.phi=t.y,i.lam=2*t.x/(e+r(i.phi))},t.es=0},"wink1","Winkel I","PCyl., Sph.\nlat_ts="),tt(function(e){var n=r(Y(e.params,"rlat_1"));e.fwd=function(e,s){var o,a,l,c=e.phi;for(s.y=c*D,o=b*i(c),c*=1.8,l=10;l&&(c-=a=(c+i(c)-o)/(1+r(c)),!(t(a)<1e-7));--l);l?c*=.5:c=c<0?-E:E,s.x=.5*e.lam*(r(c)+n),s.y=A*(i(c)+s.y)},e.inv=null,e.es=0},"wink2","Winkel II","PCyl., Sph., no inv.\nlat_1=");var ki=Dt;ki.pj_init=_t,ki.pj_fwd=Et,ki.pj_inv=It,ki.pj_transform=St,ki.pj_add=tt,ki.pj_fwd_deg=function(t,e){return Et({lam:t.lam*T,phi:t.phi*T},e)},ki.pj_inv_deg=function(t,e){var i=It(t,e);return{lam:i.lam*S,phi:i.phi*S}},ki.pj_transform_point=wt,ki.internal={dmstod:W,dmstor:Z,get_rtodms:function(t,e,i,r){var n=Pt(t,e,i,r);return function(t){return n(t*S)}},get_dtodms:Pt,get_proj_defn:rt,pj_latlong_from_proj:function(t){return _t("+proj=latlong"+it(t))},pj_get_params:K,pj_datums:st,pj_list:Q,pj_ellps:lt,pj_units:ht,pj_read_init_opts:mt,find_datum:at,DEG_TO_RAD:T,RAD_TO_DEG:S,wkt_parse:Ne,wkt_unpack:Ve,convert_wkt_quotes:je,wkt_to_proj4:function(t){var e,i,r=Ne(t);return r.PROJCS?e=Ot(i=r.PROJCS)(i):r.GEOGCS?e="+proj=longlat "+Wt(r.GEOGCS):r.GEOCCS?qt("geocentric coordinates are not supported"):qt("missing a supported WKT CS type"),e},wkt_from_proj4:function(t){return t.length&&(t=_t(t)),Fe(et(t)?{GEOGCS:Jt(t)}:se(t))},wkt_make_projcs:se,wkt_get_geogcs_name:ee,wkt_stringify:Fe,mproj_insert_libcache:function(t,e){dt[t]=e},mproj_search_libcache:ft,GeographicLib:$e},x.exports=ki}();var S=s.exports,T=i({__proto__:null,default:r(S)},[S]);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,r=this.values[t];if(e>=r)break;this.ids[i]=this.ids[t],this.values[i]=r,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],r=--this.length;if(r>0){const i=t[r],n=e[r];let s=0;const o=r>>1;for(;s<o;){const i=1+(s<<1),o=i+1,a=i+(+(o<r)&+(e[o]<e[i]));if(e[a]>=n)break;t[s]=t[a],e[s]=e[a],s=a}t[s]=i,e[s]=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 M=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class A{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,r]=new Uint8Array(t,e+0,2);if(251!==i)throw new Error("Data does not appear to be in a Flatbush format.");const n=r>>4;if(3!==n)throw new Error(`Got v${n} data when expected v3.`);const s=M[15&r];if(!s)throw new Error("Unrecognized array type.");const[o]=new Uint16Array(t,e+2,1),[a]=new Uint32Array(t,e+4,1);return new A(a,o,s,void 0,t,e)}constructor(t,e=16,i=Float64Array,r=ArrayBuffer,n,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 o=t,a=o;this._levelBounds=[4*o];do{o=Math.ceil(o/this.nodeSize),a+=o,this._levelBounds.push(4*a)}while(1!==o);this.ArrayType=i,this.IndexArrayType=a<16384?Uint16Array:Uint32Array;const l=M.indexOf(i),c=4*a*i.BYTES_PER_ELEMENT;if(l<0)throw new Error(`Unexpected typed array class: ${i}.`);if(n)this.data=n,this._boxes=new i(n,s+8,4*a),this._indices=new this.IndexArrayType(n,s+8+c,a),this._pos=4*a,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 r(8+c+a*this.IndexArrayType.BYTES_PER_ELEMENT);this._boxes=new i(n,8,4*a),this._indices=new this.IndexArrayType(n,8+c,a),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+l]),new Uint16Array(n,2,1)[0]=e,new Uint32Array(n,4,1)[0]=t}this._queue=new C}add(t,e,i=t,r=e){const n=this._pos>>2,s=this._boxes;return this._indices[n]=n,s[this._pos++]=t,s[this._pos++]=e,s[this._pos++]=i,s[this._pos++]=r,t<this.minX&&(this.minX=t),e<this.minY&&(this.minY=e),i>this.maxX&&(this.maxX=i),r>this.maxY&&(this.maxY=r),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,r=new Uint32Array(this.numItems);for(let n=0,s=0;n<this.numItems;n++){const o=t[s++],a=t[s++],l=t[s++],c=t[s++],h=Math.floor(65535*((o+l)/2-this.minX)/e),u=Math.floor(65535*((a+c)/2-this.minY)/i);r[n]=D(h,u)}I(r,t,this._indices,0,this.numItems-1,this.nodeSize);for(let e=0,i=0;e<this._levelBounds.length-1;e++){const r=this._levelBounds[e];for(;i<r;){const e=i;let n=t[i++],s=t[i++],o=t[i++],a=t[i++];for(let e=1;e<this.nodeSize&&i<r;e++)n=Math.min(n,t[i++]),s=Math.min(s,t[i++]),o=Math.max(o,t[i++]),a=Math.max(a,t[i++]);this._indices[this._pos>>2]=e,t[this._pos++]=n,t[this._pos++]=s,t[this._pos++]=o,t[this._pos++]=a}}}search(t,e,i,r,n){if(this._pos!==this._boxes.length)throw new Error("Data not yet indexed - call index.finish().");let s=this._boxes.length-4;const o=[],a=[];for(;void 0!==s;){const l=Math.min(s+4*this.nodeSize,E(s,this._levelBounds));for(let c=s;c<l;c+=4){const l=this._boxes[c];if(i<l)continue;const h=this._boxes[c+1];if(r<h)continue;const u=this._boxes[c+2];if(t>u)continue;const p=this._boxes[c+3];if(e>p)continue;const d=0|this._indices[c>>2];s>=4*this.numItems?o.push(d):(void 0===n||n(d,l,h,u,p))&&a.push(d)}s=o.pop()}return a}neighbors(t,e,i=1/0,r=1/0,n){if(this._pos!==this._boxes.length)throw new Error("Data not yet indexed - call index.finish().");let s=this._boxes.length-4;const o=this._queue,a=[],l=r*r;t:for(;void 0!==s;){const r=Math.min(s+4*this.nodeSize,E(s,this._levelBounds));for(let i=s;i<r;i+=4){const r=0|this._indices[i>>2],a=this._boxes[i],c=this._boxes[i+1],h=this._boxes[i+2],u=this._boxes[i+3],p=t<a?a-t:t>h?t-h:0,d=e<c?c-e:e>u?e-u:0,f=p*p+d*d;f>l||(s>=4*this.numItems?o.push(r<<1,f):(void 0===n||n(r))&&o.push(1+(r<<1),f))}for(;o.length&&1&o.peek();){if(o.peekValue()>l)break t;if(a.push(o.pop()>>1),a.length===i)break t}s=o.length?o.pop()>>1:void 0}return o.clear(),a}}function E(t,e){let i=0,r=e.length-1;for(;i<r;){const n=i+r>>1;e[n]>t?r=n:i=n+1}return e[i]}function I(t,e,i,r,n,s){if(Math.floor(r/s)>=Math.floor(n/s))return;const o=t[r],a=t[r+n>>1],l=t[n];let c=l;const h=Math.max(o,a);l>h?c=h:h===o?c=Math.max(a,l):h===a&&(c=Math.max(o,l));let u=r-1,p=n+1;for(;;){do{u++}while(t[u]<c);do{p--}while(t[p]>c);if(u>=p)break;P(t,e,i,u,p)}I(t,e,i,r,p,s),I(t,e,i,p+1,n,s)}function P(t,e,i,r,n){const s=t[r];t[r]=t[n],t[n]=s;const o=4*r,a=4*n,l=e[o],c=e[o+1],h=e[o+2],u=e[o+3];e[o]=e[a],e[o+1]=e[a+1],e[o+2]=e[a+2],e[o+3]=e[a+3],e[a]=l,e[a+1]=c,e[a+2]=h,e[a+3]=u;const p=i[r];i[r]=i[n],i[n]=p}function D(t,e){let i=t^e,r=65535^i,n=65535^(t|e),s=t&(65535^e),o=i|r>>1,a=i>>1^i,l=n>>1^r&s>>1^n,c=i&n>>1^s>>1^s;i=o,r=a,n=l,s=c,o=i&i>>2^r&r>>2,a=i&r>>2^r&(i^r)>>2,l^=i&n>>2^r&s>>2,c^=r&n>>2^(i^r)&s>>2,i=o,r=a,n=l,s=c,o=i&i>>4^r&r>>4,a=i&r>>4^r&(i^r)>>4,l^=i&n>>4^r&s>>4,c^=r&n>>4^(i^r)&s>>4,i=o,r=a,n=l,s=c,l^=i&n>>8^r&s>>8,c^=r&n>>8^(i^r)&s>>8,i=l^l>>1,r=c^c>>1;let h=t^e,u=r|65535^(h|i);return h=16711935&(h|h<<8),h=252645135&(h|h<<4),h=858993459&(h|h<<2),h=1431655765&(h|h<<1),u=16711935&(u|u<<8),u=252645135&(u|u<<4),u=858993459&(u|u<<2),u=1431655765&(u|u<<1),(u<<1|h)>>>0}const k=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class z{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 r=i>>4;if(1!==r)throw new Error(`Got v${r} data when expected v1.`);const n=k[15&i];if(!n)throw new Error("Unrecognized array type.");const[s]=new Uint16Array(t,2,1),[o]=new Uint32Array(t,4,1);return new z(o,s,n,t)}constructor(t,e=64,i=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=i,this.IndexArrayType=t<65536?Uint16Array:Uint32Array;const n=k.indexOf(this.ArrayType),s=2*t*this.ArrayType.BYTES_PER_ELEMENT,o=t*this.IndexArrayType.BYTES_PER_ELEMENT,a=(8-o%8)%8;if(n<0)throw new Error(`Unexpected typed array class: ${i}.`);r&&r instanceof ArrayBuffer?(this.data=r,this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+o+a,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+s+o+a),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+o+a,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 R(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}range(t,e,i,r){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:n,coords:s,nodeSize:o}=this,a=[0,n.length-1,0],l=[];for(;a.length;){const c=a.pop()||0,h=a.pop()||0,u=a.pop()||0;if(h-u<=o){for(let o=u;o<=h;o++){const a=s[2*o],c=s[2*o+1];a>=t&&a<=i&&c>=e&&c<=r&&l.push(n[o])}continue}const p=u+h>>1,d=s[2*p],f=s[2*p+1];d>=t&&d<=i&&f>=e&&f<=r&&l.push(n[p]),(0===c?t<=d:e<=f)&&(a.push(u),a.push(p-1),a.push(1-c)),(0===c?i>=d:r>=f)&&(a.push(p+1),a.push(h),a.push(1-c))}return l}within(t,e,i){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:r,coords:n,nodeSize:s}=this,o=[0,r.length-1,0],a=[],l=i*i;for(;o.length;){const c=o.pop()||0,h=o.pop()||0,u=o.pop()||0;if(h-u<=s){for(let i=u;i<=h;i++)O(n[2*i],n[2*i+1],t,e)<=l&&a.push(r[i]);continue}const p=u+h>>1,d=n[2*p],f=n[2*p+1];O(d,f,t,e)<=l&&a.push(r[p]),(0===c?t-i<=d:e-i<=f)&&(o.push(u),o.push(p-1),o.push(1-c)),(0===c?t+i>=d:e+i>=f)&&(o.push(p+1),o.push(h),o.push(1-c))}return a}}function R(t,e,i,r,n,s){if(n-r<=i)return;const o=r+n>>1;L(t,e,o,r,n,s),R(t,e,i,r,o-1,1-s),R(t,e,i,o+1,n,1-s)}function L(t,e,i,r,n,s){for(;n>r;){if(n-r>600){const o=n-r+1,a=i-r+1,l=Math.log(o),c=.5*Math.exp(2*l/3),h=.5*Math.sqrt(l*c*(o-c)/o)*(a-o/2<0?-1:1);L(t,e,i,Math.max(r,Math.floor(i-a*c/o+h)),Math.min(n,Math.floor(i+(o-a)*c/o+h)),s)}const o=e[2*i+s];let a=r,l=n;for(F(t,e,r,i),e[2*n+s]>o&&F(t,e,r,n);a<l;){for(F(t,e,a,l),a++,l--;e[2*a+s]<o;)a++;for(;e[2*l+s]>o;)l--}e[2*r+s]===o?F(t,e,r,l):(l++,F(t,e,l,n)),l<=i&&(r=l+1),i<=l&&(n=l-1)}}function F(t,e,i,r){B(t,i,r),B(e,2*i,2*r),B(e,2*i+1,2*r+1)}function B(t,e,i){const r=t[e];t[e]=t[i],t[i]=r}function O(t,e,i,r){const n=t-i,s=e-r;return n*n+s*s}var N={exports:{}};!function(t){var e,i,r,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,r=i-e,n=i-r;return r-=t,{s:i,t:i?0-(r+(n-=e)):i}},i.polyval=function(t,e,i,r){for(var n=t<0?0:e[i++];--t>=0;)n=n*r+e[i++];return n},i.AngRound=function(t){var e=1/16,r=Math.abs(t);return r=r<e?e-(e-r):r,i.copysign(r,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 r,n,s=i.sum(i.remainder(-t,360),i.remainder(e,360));return r=(s=i.sum(i.remainder(s.s,360),s.t)).s,n=s.t,0!==r&&180!==Math.abs(r)||(r=i.copysign(r,0===n?e-t:-n)),{d:r,e:n}},i.sincosd=function(t){var e,r,n,s,o,a,l;switch(e=t%360,r=(e-=90*(n=Math.round(e/90)))*this.degree,s=Math.sin(r),o=Math.cos(r),45===Math.abs(e)?(o=Math.sqrt(.5),s=i.copysign(o,r)):30===Math.abs(e)&&(o=Math.sqrt(.75),s=i.copysign(.5,r)),3&n){case 0:a=s,l=o;break;case 1:a=o,l=-s;break;case 2:a=-s,l=-o;break;default:a=-o,l=s}return l+=0,0===a&&(a=i.copysign(a,t)),{s:a,c:l}},i.sincosde=function(t,e){var r,n,s,o,a,l,c;switch(r=t%360,s=Math.round(r/90),n=(r=i.AngRound(r-90*s+e))*this.degree,o=Math.sin(n),a=Math.cos(n),45===Math.abs(r)?(a=Math.sqrt(.5),o=i.copysign(a,n)):30===Math.abs(r)&&(a=Math.sqrt(.75),o=i.copysign(.5,n)),3&s){case 0:l=o,c=a;break;case 1:l=a,c=-o;break;case 2:l=-o,c=-a;break;default:l=-a,c=o}return c+=0,0===l&&(l=i.copysign(l,t+e)),{s:l,c:c}},i.atan2d=function(t,e){var r,n=0;switch(Math.abs(t)>Math.abs(e)&&([t,e]=[e,t],n=2),i.copysign(1,e)<0&&(e=-e,++n),r=Math.atan2(t,e)/this.degree,n){case 1:r=i.copysign(180,t)-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 i=e.sum(t,this._t),r=e.sum(i.s,this._s);i=i.t,this._s=r.s,this._t=r.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,r,n){var s,o,a,l,c,h,u,p,d,f,m,_=20+r.digits+10,g=r.epsilon,y=200*g,v=Math.sqrt(g),x=g,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,s=t.nC3_*(t.nC3_-1)/2,o=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,r){var n=r.length,s=n-(t?1:0),o=2*(i-e)*(i+e),a=1&s?r[--n]:0,l=0;for(s=Math.floor(s/2);s--;)a=o*(l=o*a-l+r[--n])-a+r[--n];return t?2*e*i*a:i*(a-l)},a=function(t,e){var i,n,s,o,a,l,c,h,u,p,d,f,m=r.sq(t),_=r.sq(e),g=(m+_-1)/6;return 0===_&&g<=0?i=0:(l=g,(a=(n=m*_/4)*(n+2*(o=g*(s=r.sq(g)))))>=0?(c=n+o,c+=c<0?-Math.sqrt(a):Math.sqrt(a),l+=(h=r.cbrt(c))+(0!==h?s/h:0)):(u=Math.atan2(Math.sqrt(-a),-(n+o)),l+=2*g*Math.cos(u/3)),p=Math.sqrt(r.sq(l)+_),f=((d=l<0?_/(p-l):l+p)-_)/(2*p),i=d/(Math.sqrt(d+r.sq(f))+f)),i},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)},c=[-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,s,o=r.sq(e),a=e,l=0;for(n=1;n<=t.nC1_;++n)s=Math.floor((t.nC1_-n)/2),i[n]=a*r.polyval(s,c,l,o)/c[l+s+1],l+=s+2,a*=e},h=[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,s,o=r.sq(e),a=e,l=0;for(n=1;n<=t.nC1p_;++n)s=Math.floor((t.nC1p_-n)/2),i[n]=a*r.polyval(s,h,l,o)/h[l+s+1],l+=s+2,a*=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,i){var n,s,o=r.sq(e),a=e,l=0;for(n=1;n<=t.nC2_;++n)s=Math.floor((t.nC2_-n)/2),i[n]=a*r.polyval(s,p,l,o)/p[l+s+1],l+=s+2,a*=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(o),this.A3coeff(),this.C3coeff(),this.C4coeff()},d=[-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++]=r.polyval(e,d,i,this._n)/d[i+e+1],i+=e+2},f=[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,s=0,o=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[o++]=r.polyval(n,f,s,this._n)/f[s+n+1],s+=n+2},m=[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,s=0,o=0;for(e=0;e<t.nC4_;++e)for(i=t.nC4_-1;i>=e;--i)n=t.nC4_-i-1,this._C4x[o++]=r.polyval(n,m,s,this._n)/m[s+n+1],s+=n+2},t.Geodesic.prototype.A3f=function(t){return r.polyval(5,this._A3x,0,t)},t.Geodesic.prototype.C3f=function(e,i){var n,s,o=1,a=0;for(n=1;n<t.nC3_;++n)s=t.nC3_-n-1,o*=e,i[n]=o*r.polyval(s,this._C3x,a,e),a+=s+1},t.Geodesic.prototype.C4f=function(e,i){var n,s,o=1,a=0;for(n=0;n<t.nC4_;++n)s=t.nC4_-n-1,i[n]=o*r.polyval(s,this._C4x,a,e),a+=s+1,o*=e},t.Geodesic.prototype.Lengths=function(e,i,r,n,s,o,a,l,c,h,u,p,d){var f,m,_,g,y={},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,d),v=b-w,w=1+w),b=1+b),u&t.DISTANCE)f=t.SinCosSeries(!0,o,a,p)-t.SinCosSeries(!0,r,n,p),y.s12b=b*(i+f),u&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(x=v*i+(b*f-w*(t.SinCosSeries(!0,o,a,d)-t.SinCosSeries(!0,r,n,d))));else if(u&(t.REDUCEDLENGTH|t.GEODESICSCALE)){for(m=1;m<=t.nC2_;++m)d[m]=b*p[m]-w*d[m];x=v*i+(t.SinCosSeries(!0,o,a,d)-t.SinCosSeries(!0,r,n,d))}return u&t.REDUCEDLENGTH?(y.m0=v,y.m12b=l*(n*o)-s*(r*a)-n*a*x):y.m12b=NaN,u&t.GEODESICSCALE&&(_=n*a+r*o,g=this._ep2*(c-h)*(c+h)/(s+l),y.M12=_+(g*o-a*x)*r/s,y.M21=_-(g*r-n*x)*o/l),y},t.Geodesic.prototype.InverseStart=function(e,i,n,s,o,l,c,h,u,p,d){var f,m,_,g,v,x,w,S,T,C,M,A,E,I,P,D,k,z,R,L,F={},B=s*i-o*e,O=o*i+s*e;return F.sig12=-1,f=s*i,f+=o*e,(m=O>=0&&B<.5&&o*c<.5)?(g=r.sq(e+s),g/=g+r.sq(i+o),F.dnm=Math.sqrt(1+this._ep2*g),_=c/(this._f1*F.dnm),v=Math.sin(_),x=Math.cos(_)):(v=h,x=u),F.salp1=o*v,F.calp1=x>=0?B+o*e*r.sq(v)/(1+x):f-o*e*r.sq(v)/(1-x),S=r.hypot(F.salp1,F.calp1),T=e*s+i*o*x,m&&S<this._etol2?(F.salp2=i*v,F.calp2=B-i*s*(x>=0?r.sq(v)/(1+x):1-x),w=r.hypot(F.salp2,F.calp2),F.salp2/=w,F.calp2/=w,F.sig12=Math.atan2(S,T)):Math.abs(this._n)>.1||T>=0||S>=6*Math.abs(this._n)*Math.PI*r.sq(i)||(L=Math.atan2(-h,-u),this.f>=0?(I=(E=r.sq(e)*this._ep2)/(2*(1+Math.sqrt(1+E))+E),C=L/(A=this.f*i*this.A3f(I)*Math.PI),M=f/(A*i)):(P=o*i-s*e,D=Math.atan2(f,P),M=c/(A=((C=(k=this.Lengths(this._n,Math.PI+D,e,-i,n,s,o,l,i,o,t.REDUCEDLENGTH,p,d)).m12b/(i*o*k.m0*Math.PI)-1)<-.01?f/C:-this.f*r.sq(i)*Math.PI)/i)),M>-y&&C>-1-b?this.f>=0?(F.salp1=Math.min(1,-C),F.calp1=-Math.sqrt(1-r.sq(F.salp1))):(F.calp1=Math.max(C>-y?0:-1,C),F.salp1=Math.sqrt(1-r.sq(F.calp1))):(z=a(C,M),R=A*(this.f>=0?-C*z/(1+z):-M*(1+z)/z),v=Math.sin(R),x=-Math.cos(R),F.salp1=o*v,F.calp1=f-o*e*r.sq(v)/(1-x))),F.salp1<=0?(F.salp1=1,F.calp1=0):(w=r.hypot(F.salp1,F.calp1),F.salp1/=w,F.calp1/=w),F},t.Geodesic.prototype.Lambda12=function(e,i,n,s,o,a,l,c,h,u,p,d,f,m){var _,g,y,v,x,b,w,S,T,C,M,A,E,I={};return 0===e&&0===c&&(c=-t.tiny_),g=l*i,y=r.hypot(c,l*e),I.ssig1=e,v=g*e,I.csig1=x=c*i,_=r.hypot(I.ssig1,I.csig1),I.ssig1/=_,I.csig1/=_,I.salp2=o!==i?g/o:l,I.calp2=o!==i||Math.abs(s)!==-e?Math.sqrt(r.sq(c*i)+(i<-e?(o-i)*(i+o):(e-s)*(e+s)))/o:Math.abs(c),I.ssig2=s,b=g*s,I.csig2=w=I.calp2*o,_=r.hypot(I.ssig2,I.csig2),I.ssig2/=_,I.csig2/=_,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),T=x*w+v*b,M=Math.atan2(S*u-T*h,T*u+S*h),A=r.sq(y)*this._ep2,I.eps=A/(2*(1+Math.sqrt(1+A))+A),this.C3f(I.eps,m),C=t.SinCosSeries(!0,I.ssig2,I.csig2,m)-t.SinCosSeries(!0,I.ssig1,I.csig1,m),I.domg12=-this.f*this.A3f(I.eps)*g*(I.sig12+C),I.lam12=M+I.domg12,p&&(0===I.calp2?I.dlam12=-2*this._f1*n/e:(E=this.Lengths(I.eps,I.sig12,I.ssig1,I.csig1,n,I.ssig2,I.csig2,a,i,o,t.REDUCEDLENGTH,d,f),I.dlam12=E.m12b,I.dlam12*=this._f1/(I.calp2*o))),I},t.Geodesic.prototype.Inverse=function(e,i,n,s,o){var a,l;return o||(o=t.STANDARD),o===t.LONG_UNROLL&&(o|=t.STANDARD),o&=t.OUT_MASK,l=(a=this.InverseInt(e,i,n,s,o)).vals,o&t.AZIMUTH&&(l.azi1=r.atan2d(a.salp1,a.calp1),l.azi2=r.atan2d(a.salp2,a.calp2)),l},t.Geodesic.prototype.InverseInt=function(e,i,n,s,o){var a,l,c,h,u,p,d,f,m,y,b,w,S,T,C,M,A,E,I,P,D,k,z,R,L,F,B,O,N,V,j,G,U,q,$,Z,W,H,X,Y,K,J,Q,tt,et,it,rt,nt,st,ot,at,lt,ct,ht,ut,pt,dt,ft,mt,_t,gt,yt,vt,xt,bt,wt={};if(wt.lat1=e=r.LatFix(e),wt.lat2=n=r.LatFix(n),e=r.AngRound(e),n=r.AngRound(n),l=(a=r.AngDiff(i,s)).e,a=a.d,o&t.LONG_UNROLL?(wt.lon1=i,wt.lon2=i+a+l):(wt.lon1=r.AngNormalize(i),wt.lon2=r.AngNormalize(s)),l*=c=r.copysign(1,a),C=(a*=c)*r.degree,M=(h=r.sincosde(a,l)).s,A=h.c,l=180-a-l,(u=Math.abs(e)<Math.abs(n)||isNaN(n)?-1:1)<0&&(c*=-1,[n,e]=[e,n]),e*=p=r.copysign(1,-e),n*=p,h=r.sincosd(e),d=this._f1*h.s,f=h.c,d/=h=r.hypot(d,f),f/=h,f=Math.max(t.tiny_,f),h=r.sincosd(n),m=this._f1*h.s,y=h.c,m/=h=r.hypot(m,y),y/=h,y=Math.max(t.tiny_,y),f<-d?y===f&&(m=r.copysign(d,m)):Math.abs(m)===-d&&(y=f),S=Math.sqrt(1+this._ep2*r.sq(d)),T=Math.sqrt(1+this._ep2*r.sq(m)),z=new Array(t.nC1_+1),R=new Array(t.nC2_+1),L=new Array(t.nC3_),(F=-90===e||0===M)&&(P=M,k=0,O=d,N=(I=A)*f,V=m,j=(D=1)*y,E=Math.atan2(Math.max(0,N*V-O*j),N*j+O*V),b=(B=this.Lengths(this._n,E,O,N,S,V,j,T,f,y,o|t.DISTANCE|t.REDUCEDLENGTH,z,R)).s12b,w=B.m12b,o&t.GEODESICSCALE&&(wt.M12=B.M12,wt.M21=B.M21),E<v||w>=0?((E<3*t.tiny_||E<g&&(b<0||w<0))&&(E=w=b=0),w*=this._b,b*=this._b,wt.a12=E/r.degree):F=!1),dt=2,!F&&0===d&&(this.f<=0||l>=180*this.f))I=D=0,P=k=1,b=this.a*C,E=U=C/this._f1,w=this._b*Math.sin(E),o&t.GEODESICSCALE&&(wt.M12=wt.M21=Math.cos(E)),wt.a12=a/this._f1;else if(!F)if(E=(B=this.InverseStart(d,f,S,m,y,T,C,M,A,z,R)).sig12,P=B.salp1,I=B.calp1,E>=0)k=B.salp2,D=B.calp2,q=B.dnm,b=E*this._b*q,w=r.sq(q)*this._b*Math.sin(E/q),o&t.GEODESICSCALE&&(wt.M12=wt.M21=Math.cos(E/q)),wt.a12=E/r.degree,U=C/(this._f1*q);else{for($=0,Z=t.tiny_,W=1,H=t.tiny_,X=-1,Y=!1,K=!1;J=(B=this.Lambda12(d,f,S,m,y,T,P,I,M,A,$<20,z,R,L)).lam12,k=B.salp2,D=B.calp2,E=B.sig12,O=B.ssig1,N=B.csig1,V=B.ssig2,j=B.csig2,G=B.eps,mt=B.domg12,Q=B.dlam12,!K&&Math.abs(J)>=(Y?8:1)*g&&$!=_;++$)J>0&&($<20||I/P>X/H)?(H=P,X=I):J<0&&($<20||I/P<W/Z)&&(Z=P,W=I),$<20&&Q>0&&(tt=-J/Q,Math.abs(tt)<Math.PI&&(et=Math.sin(tt),(rt=P*(it=Math.cos(tt))+I*et)>0))?(I=I*it-P*et,P=rt,P/=h=r.hypot(P,I),I/=h,Y=Math.abs(J)<=16*g):(P=(Z+H)/2,I=(W+X)/2,P/=h=r.hypot(P,I),I/=h,Y=!1,K=Math.abs(Z-P)+(W-I)<x||Math.abs(P-H)+(I-X)<x);nt=o|(o&(t.REDUCEDLENGTH|t.GEODESICSCALE)?t.DISTANCE:t.NONE),b=(B=this.Lengths(G,E,O,N,S,V,j,T,f,y,nt,z,R)).s12b,w=B.m12b,o&t.GEODESICSCALE&&(wt.M12=B.M12,wt.M21=B.M21),w*=this._b,b*=this._b,wt.a12=E/r.degree,o&t.AREA&&(xt=Math.sin(mt),dt=M*(bt=Math.cos(mt))-A*xt,ft=A*bt+M*xt)}return o&t.DISTANCE&&(wt.s12=0+b),o&t.REDUCEDLENGTH&&(wt.m12=0+w),o&t.AREA&&(st=P*f,0!==(ot=r.hypot(I,P*d))&&0!==st?(O=d,N=I*f,V=m,j=D*y,G=(lt=r.sq(ot)*this._ep2)/(2*(1+Math.sqrt(1+lt))+lt),ct=r.sq(this.a)*ot*st*this._e2,O/=h=r.hypot(O,N),N/=h,V/=h=r.hypot(V,j),j/=h,ht=new Array(t.nC4_),this.C4f(G,ht),ut=t.SinCosSeries(!1,O,N,ht),pt=t.SinCosSeries(!1,V,j,ht),wt.S12=ct*(pt-ut)):wt.S12=0,F||2!=dt||(dt=Math.sin(U),ft=Math.cos(U)),!F&&ft>-.7071&&m-d<1.75?(mt=1+ft,_t=1+f,gt=1+y,at=2*Math.atan2(dt*(d*gt+m*_t),mt*(d*m+_t*gt))):(vt=D*I+k*P,0===(yt=k*I-D*P)&&vt<0&&(yt=t.tiny_*I,vt=-1),at=Math.atan2(yt,vt)),wt.S12+=this._c2*at,wt.S12*=u*c*p,wt.S12+=0),u<0&&([k,P]=[P,k],[D,I]=[I,D],o&t.GEODESICSCALE&&([wt.M21,wt.M12]=[wt.M12,wt.M21])),{vals:wt,salp1:P*=u*c,calp1:I*=u*p,salp2:k*=u*c,calp2:D*=u*p}},t.Geodesic.prototype.GenDirect=function(i,r,n,s,o,a){return a?a===t.LONG_UNROLL&&(a|=t.STANDARD):a=t.STANDARD,s||(a|=t.DISTANCE_IN),new e.GeodesicLine(this,i,r,n,a).GenPosition(s,o,a)},t.Geodesic.prototype.Direct=function(t,e,i,r,n){return this.GenDirect(t,e,i,!1,r,n)},t.Geodesic.prototype.ArcDirect=function(t,e,i,r,n){return this.GenDirect(t,e,i,!0,r,n)},t.Geodesic.prototype.Line=function(t,i,r,n){return new e.GeodesicLine(this,t,i,r,n)},t.Geodesic.prototype.DirectLine=function(t,e,i,r,n){return this.GenDirectLine(t,e,i,!1,r,n)},t.Geodesic.prototype.ArcDirectLine=function(t,e,i,r,n){return this.GenDirectLine(t,e,i,!0,r,n)},t.Geodesic.prototype.GenDirectLine=function(i,r,n,s,o,a){var l;return a||(a=t.STANDARD|t.DISTANCE_IN),s||(a|=t.DISTANCE_IN),(l=new e.GeodesicLine(this,i,r,n,a)).GenSetDistance(s,o),l},t.Geodesic.prototype.InverseLine=function(i,n,s,o,a){var l,c,h;return a||(a=t.STANDARD|t.DISTANCE_IN),l=this.InverseInt(i,n,s,o,t.ARC),h=r.atan2d(l.salp1,l.calp1),a&t.OUT_MASK&t.DISTANCE_IN&&(a|=t.DISTANCE),(c=new e.GeodesicLine(this,i,n,h,a,l.salp1,l.calp1)).SetArc(l.vals.a12),c},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,r,n,s,o,a,l){var c,h,u,p,d,f;o||(o=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=o|t.LATITUDE|t.AZIMUTH|t.LONG_UNROLL,this.lat1=i.LatFix(r),this.lon1=n,void 0===a||void 0===l?(this.azi1=i.AngNormalize(s),c=i.sincosd(i.AngRound(this.azi1)),this.salp1=c.s,this.calp1=c.c):(this.azi1=s,this.salp1=a,this.calp1=l),c=i.sincosd(i.AngRound(this.lat1)),u=this._f1*c.s,h=c.c,u/=c=i.hypot(u,h),h/=c,h=Math.max(t.tiny_,h),this._dn1=Math.sqrt(1+e._ep2*i.sq(u)),this._salp0=this.salp1*h,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?h*this.calp1:1,c=i.hypot(this._ssig1,this._csig1),this._ssig1/=c,this._csig1/=c,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),d=Math.sin(this._B11),f=Math.cos(this._B11),this._stau1=this._ssig1*f+this._csig1*d,this._ctau1=this._csig1*f-this._ssig1*d),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,r,n){var s,o,a,l,c,h,u,p,d,f,m,_,g,y,v,x,b,w,S,T,C,M,A,E,I,P,D={};return n?n===t.LONG_UNROLL&&(n|=t.STANDARD):n=t.STANDARD,n&=this.caps&t.OUT_MASK,D.lat1=this.lat1,D.azi1=this.azi1,D.lon1=n&t.LONG_UNROLL?this.lon1:i.AngNormalize(this.lon1),e?D.a12=r:D.s12=r,e||this.caps&t.DISTANCE_IN&t.OUT_MASK?(l=0,c=0,e?(s=r*i.degree,o=(A=i.sincosd(r)).s,a=A.c):(p=r/(this._b*(1+this._A1m1)),d=Math.sin(p),f=Math.cos(p),s=p-((l=-t.SinCosSeries(!0,this._stau1*f+this._ctau1*d,this._ctau1*f-this._stau1*d,this._C1pa))-this._B11),o=Math.sin(s),a=Math.cos(s),Math.abs(this.f)>.01&&(h=this._ssig1*a+this._csig1*o,u=this._csig1*a-this._ssig1*o,l=t.SinCosSeries(!0,h,u,this._C1a),s-=((1+this._A1m1)*(s+(l-this._B11))-r/this._b)/Math.sqrt(1+this._k2*i.sq(h)),o=Math.sin(s),a=Math.cos(s))),h=this._ssig1*a+this._csig1*o,u=this._csig1*a-this._ssig1*o,S=Math.sqrt(1+this._k2*i.sq(h)),n&(t.DISTANCE|t.REDUCEDLENGTH|t.GEODESICSCALE)&&((e||Math.abs(this.f)>.01)&&(l=t.SinCosSeries(!0,h,u,this._C1a)),c=(1+this._A1m1)*(l-this._B11)),g=this._calp0*h,0===(y=i.hypot(this._salp0,this._calp0*u))&&(y=u=t.tiny_),b=this._salp0,w=this._calp0*u,e&&n&t.DISTANCE&&(D.s12=this._b*((1+this._A1m1)*s+c)),n&t.LONGITUDE&&(v=this._salp0*h,x=u,_=i.copysign(1,this._salp0),m=((n&t.LONG_UNROLL?_*(s-(Math.atan2(h,u)-Math.atan2(this._ssig1,this._csig1))+(Math.atan2(_*v,x)-Math.atan2(_*this._somg1,this._comg1))):Math.atan2(v*this._comg1-x*this._somg1,x*this._comg1+v*this._somg1))+this._A3c*(s+(t.SinCosSeries(!0,h,u,this._C3a)-this._B31)))/i.degree,D.lon2=n&t.LONG_UNROLL?this.lon1+m:i.AngNormalize(i.AngNormalize(this.lon1)+i.AngNormalize(m))),n&t.LATITUDE&&(D.lat2=i.atan2d(g,this._f1*y)),n&t.AZIMUTH&&(D.azi2=i.atan2d(b,w)),n&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(T=t.SinCosSeries(!0,h,u,this._C2a),C=(1+this._A2m1)*(T-this._B21),M=(this._A1m1-this._A2m1)*s+(c-C),n&t.REDUCEDLENGTH&&(D.m12=this._b*(S*(this._csig1*h)-this._dn1*(this._ssig1*u)-this._csig1*u*M)),n&t.GEODESICSCALE&&(A=this._k2*(h-this._ssig1)*(h+this._ssig1)/(this._dn1+S),D.M12=a+(A*h-u*M)*this._ssig1/this._dn1,D.M21=a-(A*this._ssig1-this._csig1*M)*h/S)),n&t.AREA&&(E=t.SinCosSeries(!1,h,u,this._C4a),0===this._calp0||0===this._salp0?(I=b*this.calp1-w*this.salp1,P=w*this.calp1+b*this.salp1):(I=this._calp0*this._salp0*(a<=0?this._csig1*(1-a)+o*this._ssig1:o*(this._csig1*o/(1+a)+this._ssig1)),P=i.sq(this._salp0)+i.sq(this._calp0)*this._csig1*u),D.S12=this._c2*Math.atan2(I,P)+this._A4*(E-this._B41)),e||(D.a12=s/i.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 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,r){var n,s,o,a;n=function(t,e){var r=i.AngDiff(t,e).d;return t=i.AngNormalize(t),e=i.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)},o=function(t,e,i,r,n){return t.Remainder(e),1&i&&t.Add((t.Sum()<0?1:-1)*e/2),r||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()},a=function(t,e,r,n,s){return t=i.remainder(t,e),1&r&&(t+=(t<0?1:-1)*e/2),n||(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,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 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 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+=s(this.lon,i.lon2)),this.lat=i.lat2,this.lon=i.lon2),++this.num},t.PolygonArea.prototype.Compute=function(t,e){var i,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):(i=this._geod.Inverse(this.lat,this.lon,this._lat0,this._lon0,this._mask),a.perimeter=this._perimetersum.Sum(i.s12),(s=new r.Accumulator(this._areasum)).Add(i.S12),a.area=o(s,this._area0,this._crossings+n(this.lon,this._lon0),t,e),a)},t.PolygonArea.prototype.TestPoint=function(t,e,i,r){var s,o,l,c,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(),o=this.polyline?0:this._areasum.Sum(),l=this._crossings,c=0;c<(this.polyline?1:2);++c)s=this._geod.Inverse(0===c?this.lat:t,0===c?this.lon:e,0!==c?this._lat0:t,0!==c?this._lon0:e,this._mask),h.perimeter+=s.s12,this.polyline||(o+=s.S12,l+=n(0===c?this.lon:e,0!==c?this._lon0:e));return this.polyline||(h.area=a(o,this._area0,l,i,r)),h},t.PolygonArea.prototype.TestEdge=function(t,e,i,r){var o,l,c,h={number:this.num?this.num+1:0};return 0===this.num||(h.perimeter=this._perimetersum.Sum()+e,this.polyline||(l=this._areasum.Sum(),c=this._crossings,l+=(o=this._geod.Direct(this.lat,this.lon,t,e,this._mask)).S12,c+=s(this.lon,o.lon2),c+=n(o.lon2,this._lon0),o=this._geod.Inverse(o.lat2,o.lon2,this._lat0,this._lon0,this._mask),h.perimeter+=o.s12,l+=o.S12,h.area=a(l,this._area0,c,i,r))),h}}(n.PolygonArea,n.Geodesic,n.Math,n.Accumulator),r=n,t.exports?t.exports=r:window.geodesic=r}(N);var V=N.exports,j=i({__proto__:null,default:r(V)},[V]);const G=globalThis;"undefined"==typeof window&&(G.window=G.window||{},G.window.document||(G.window.document={}));const U=G.window.modules=G.window.modules||{};U.mproj=T,U.flatbush=A,U.kdbush=z,U["geographiclib-geodesic"]=j;class q{_listeners={};on(t,e){return this._listeners[t]||(this._listeners[t]=[]),this._listeners[t].push(e),this}once(t,e){const i=r=>{this.off(t,i),e(r)};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,r=0){this.mx=t,this.my=e,this.bx=i,this.by=r}static fromBounds(t,e,i=!1){const r=e.width/t.width||1,n=(i?-e.height/t.height:e.height/t.height)||1,s=e.xmin-r*t.xmin,o=i?e.ymax-n*t.ymin:e.ymin-n*t.ymin;return new $(r,n,s,o)}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 Z{xmin;ymin;xmax;ymax;constructor(t=1/0,e=1/0,i=-1/0,r=-1/0){this.xmin=t,this.ymin=e,this.xmax=i,this.ymax=r}static fromArray(t){return new Z(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 Z(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 r=this.width,n=this.height;let s;return r/n<t?(s=n*t-r,this.xmin-=(1-e)*s,this.xmax+=e*s):(s=r/t-n,this.ymin-=(1-i)*s,this.ymax+=i*s),this}scale(t){const e=this.centerX,i=this.centerY,r=this.width*t,n=this.height*t;this.xmin=e-r/2,this.xmax=e+r/2,this.ymin=i-n/2,this.ymax=i+n/2}}class W extends q{_running=!1;_busy=!1;_tickTime=0;_startTime=0;_duration=1/0;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(){this._running=!1}_startTick(t){this._busy=!0,this._tickTime=t,("function"==typeof requestAnimationFrame?requestAnimationFrame:t=>setTimeout(t,25))(()=>this._onTick())}_onTick(){const t=Date.now(),e=t-this._startTime,i=Math.min((e+10)/this._duration,1),r=i>=1;this._running?(r&&(this._running=!1),this.fire("tick",{elapsed:e,pct:i,done:r,time:t,tickTime:t-this._tickTime}),this._busy=!1,this._running&&this._startTick(t)):this._busy=!1}}class H extends q{_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 X=18485274.7;class Y{_transform=new $;_extent=new Z;_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)}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 Z(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,r){const n=1+.12*e,s=t>0?n:1/n;this._transform.scale(s,i,r),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),r=i*t;this._zoomFocus=e,this._animatingTransform=this._transform.clone(),this._zoomTween.start(i,r,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,r=i<1?e*i:e,n=this._getViewBounds();return e=>!t.arcIsSmaller?.(e,r)&&!(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,r=-t.by/t.my,n=(this._height-t.by)/t.my;return[Math.min(e,i),Math.min(r,n),Math.max(e,i),Math.max(r,n)]}_applyConstraints(){const t=this._transform;let e=Math.abs(t.mx);const i=this._getMinMX(),r=this._getMaxMX();(this._crs.toLowerCase().includes("3857")||this._crs.toLowerCase().includes("webmercator"))&&e<i&&(e=i),e>r&&(e=r);const n=t.my>0?e:-e,s=this._getStrictBounds(),o=(this._width/2-t.bx)/t.mx;let a=(this._height/2-t.by)/t.my;if(s){const t=this._height/(2*e),i=s.ymax-t,r=s.ymin+t;r>i?a=(s.ymin+s.ymax)/2:a>i?a=i:a<r&&(a=r)}const l=this._width/2-o*e,c=this._height/2-a*n;this._transform=new $(e,n,l,c)}_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),r=e(t.ymin,t.ymax,t.centerY),n=t.width/this._width/(1e-16*i),s=t.height/this._height/(1e-16*r);return Math.max(n,s)}_getStrictBounds(){const t=this._crs.toLowerCase();return"epsg:3857"===t||"webmercator"===t?new Z(-1/0,-18485274.7,1/0,X):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}}class K{snapVertices(t,i,r){e.internal.snapVerticesToPoint(t,i,r)}insertVertex(t,i,r){e.internal.insertVertex(t,i,r)}deleteVertex(t,i){e.internal.deleteVertex(t,i)}appendEmptyArc(t){e.internal.appendEmptyArc(t)}appendVertex(t,i){e.internal.appendVertex(t,i)}deleteLastArc(t){e.internal.deleteLastArc(t)}findNearestVertices(t,i,r){return e.internal.findNearestVertices(t,i,r)}findArcIdFromVertexId(t,i){return e.internal.findArcIdFromVertexId(t,i)}vertexIsArcEndpoint(t,i){return e.internal.vertexIsArcEndpoint(t,i)}forEachSegmentInShape(t,i,r){e.internal.forEachSegmentInShape(t,i,r)}findClosestPointOnSeg(t,i,r,n,s,o,a){return e.internal.findClosestPointOnSeg(t,i,r,n,s,o,a)}addIntersectionCuts(t,i){e.internal.addIntersectionCuts(t,i)}findSegmentIntersections(t,i){return e.internal.findSegmentIntersections(t,i)}getIntersectionLayer(t,i,r){return e.internal.getIntersectionLayer(t,i,r)}getAvgSegment(t){return e.internal.getAvgSegment(t)}simplifyArcsFast(t,i){return e.internal.simplifyArcsFast(t,i)}layerHasGeometry(t){return e.internal.layerHasGeometry(t)}getLayerBounds(t,i){const r=e.internal.getLayerBounds(t,i);return r?{xmin:r.xmin,ymin:r.ymin,xmax:r.xmax,ymax:r.ymax}:{xmin:NaN,ymin:NaN,xmax:NaN,ymax:NaN}}getDatasetBounds(t){const i=e.internal.getDatasetBounds(t);return{xmin:i.xmin,ymin:i.ymin,xmax:i.xmax,ymax:i.ymax}}exportDatasetsToPack(t,i){return e.internal.exportDatasetsToPack(t,i??{})}restoreSessionData(t){return e.internal.restoreSessionData(t)}pack(t){return e.internal.pack(t)}unpackSessionData(t){return e.internal.unpackSessionData(t)}exportPackedDatasets(t,i){return e.internal.exportPackedDatasets(t,i??{})}exportFileContent(t,i){return e.internal.exportFileContent(t,i)}copyDataset(t){return e.internal.copyDataset(t)}runImport(t,i){const r=e.internal.parseCommands(t);return r.length>0&&"i"===r[0].name&&(r[0].options.input=i),new Promise((t,i)=>{e.internal.runParsedCommands(r,new e.internal.Job,(e,r)=>{if(e)return void i(e);const n=r.catalog.getDefaultTargets();0!==n.length?t(n[0].dataset):i(new Error("No layers found in dataset"))})})}runOnDataset(t,i,r){return new Promise((n,s)=>{const o=new e.internal.Job;o.catalog.addDataset(i);const a=e.internal.parseCommands(t);if(r)for(const t of a)t.options&&(t.options.input=r);e.internal.runParsedCommands(a,o,(t,e)=>{if(t)return void s(t);const i=e.catalog.getDefaultTargets();0!==i.length?n(i[0].dataset):s(new Error("mapshaper command completed but produced no default target"))})})}runOnDatasetParsed(t,i,r){return new Promise((n,s)=>{const o=new e.internal.Job;if(o.catalog.addDataset(i),r)for(const e of t)e.options&&(e.options.input=r);e.internal.runParsedCommands(t,o,(t,e)=>{if(t)return void s(t);const i=e.catalog.getDefaultTargets();0!==i.length?n(i[0].dataset):s(new Error("mapshaper command completed but produced no default target"))})})}}let J=null;function Q(){return J??(J=new K)}const tt=6378137;class et{_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(40075016.6855*t/512):0}async reproject(t,e){for(const i of e.values())i.reproject&&await i.reproject(t);this._crs=t;const i=Q(),r=new Z;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&&r.merge(new Z(n.xmin,n.ymin,n.xmax,n.ymax))}}return r.hasBounds()&&r.scale(1.07),r}_webMercatorToLatLng(t,e){const i=180/Math.PI;return[t/tt*i,i*(.5*Math.PI-2*Math.atan(Math.exp(-e/tt)))]}}function it(t,e){return t?.name?String(t.name):t?.id?String(t.id):`layer-${e}`}function rt(t){return t&&Array.isArray(t)?"number"==typeof t[0]?[t]:Array.isArray(t[0])?t:[]:[]}class nt{_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 r=this._ctx;r.strokeStyle=e.color||"#333",r.lineWidth=(e.width??1)*this._pixelRatio,r.lineCap="round",r.lineJoin="round";let n=0;r.beginPath(),t.forEach(t=>{t&&t.forEach(t=>{t.forEach(t=>{n>0&&n%25==0&&(r.stroke(),r.beginPath());const e=i.getArcIter(t);this.drawPathSnapping(e,r),n++})})}),r.stroke()}drawArcs(t,e,i){if(0===e.width)return;const r=this._ctx,n=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<n;e++){if(i&&!i(e))continue;s>0&&s%25==0&&(r.stroke(),r.beginPath());const n=t.getArcIter(e);this.drawPathSnapping(n,r),s++}r.stroke()}drawPathSnapping(t,e){const i=this._transform.mx*this._pixelRatio,r=this._transform.my*this._pixelRatio,n=this._transform.bx*this._pixelRatio,s=this._transform.by*this._pixelRatio;let o,a,l,c,h=0;if(t.hasNext()){for(o=2*(t.x*i+n)|0,a=2*(t.y*r+s)|0,e.moveTo(o/2,a/2);t.hasNext();)l=o,c=a,o=2*(t.x*i+n)|0,a=2*(t.y*r+s)|0,o===l&&a===c||(e.lineTo(o/2,a/2),h++);0===h&&e.lineTo(o/2+.1,a/2)}}drawPoints(t,e){const i=this._ctx,r=this._pixelRatio,n=this._transform.mx*r,s=this._transform.my*r,o=this._transform.bx*r,a=this._transform.by*r,l=(Number(e?.radius)||4)*r,c=e?.color||"#333",h=!1!==e?.fill;i.beginPath(),i.fillStyle=c,i.strokeStyle=c,t.forEach(t=>{if(!t)return;rt(t).forEach(t=>{const e=t[0]*n+o,r=t[1]*s+a;i.moveTo(e+l,r),i.arc(e,r,l,0,2*Math.PI)})}),h?i.fill():i.stroke()}drawVertexDots(t,e,i={}){const r=this._ctx,n=this._pixelRatio,s=this._transform.mx*n,o=this._transform.my*n,a=this._transform.bx*n,l=this._transform.by*n,c=i.dotColor||"#333",h=(i.dotRadius||3)*n,u=i.hoverColor||"#cc6acc",p=(i.hoverRadius||6)*n,d=i.hoverVertex;let f=null;d&&(f=[d[0]*s+a,d[1]*o+l]),r.fillStyle=c,r.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*s+a,e=n.y*o+l;f&&Math.abs(t-f[0])<1&&Math.abs(e-f[1])<1||(r.moveTo(t+h,e),r.arc(t,e,h,0,2*Math.PI))}})})}),r.fill(),f&&(r.fillStyle=u,r.beginPath(),"interpolated"===i.hoverType?r.rect(f[0]-p,f[1]-p,2*p,2*p):r.arc(f[0],f[1],p,0,2*Math.PI),r.fill())}drawPolygonFill(t,e,i,r,n){if(!e.getShapeIter)return;const s=this._ctx,o=this._pixelRatio,a=this._transform.mx*o,l=this._transform.my*o,c=this._transform.bx*o,h=this._transform.by*o;s.fillStyle=i;const u="number"==typeof n&&1!==n,p=s.globalAlpha;u&&(s.globalAlpha=p*Math.max(0,Math.min(1,n)));let d=0;s.beginPath();for(let i=0;i<t.length;i++){const n=t[i];if(!n)continue;let o=!0;if(r){o=!1;for(const t of n){for(const e of t){if(r(e>=0?e:~e)){o=!0;break}}if(o)break}}if(o){d>0&&d>=100&&(s.fill("evenodd"),s.beginPath(),d=0);for(const t of n){const i=e.getShapeIter(t);if(!i.hasNext())continue;let r,n,o=2*(i.x*a+c)|0,u=2*(i.y*l+h)|0;for(s.moveTo(o/2,u/2);i.hasNext();)r=o,n=u,o=2*(i.x*a+c)|0,u=2*(i.y*l+h)|0,o===r&&u===n||s.lineTo(o/2,u/2);s.closePath()}d++}}d>0&&s.fill("evenodd"),u&&(s.globalAlpha=p)}drawDrawingOverlay(t){const e=this._ctx,i=this._pixelRatio,r=this._transform.mx*i,n=this._transform.my*i,s=this._transform.bx*i,o=this._transform.by*i,a=t.drawColor||"#0078ff",l=t.vertices,c=t.cursorCoord,h=t=>[t[0]*r+s,t[1]*n+o];if(l.length>0){e.strokeStyle=a,e.lineWidth=2*i,e.lineJoin="round",e.lineCap="round",e.setLineDash([]),e.beginPath();const t=h(l[0]);e.moveTo(t[0],t[1]);for(let t=1;t<l.length;t++){const i=h(l[t]);e.lineTo(i[0],i[1])}e.stroke()}if(l.length>0&&c){const r=h(l[l.length-1]),n=h(c);if(e.strokeStyle=a,e.lineWidth=1.5*i,e.setLineDash([6*i,4*i]),e.beginPath(),e.moveTo(r[0],r[1]),e.lineTo(n[0],n[1]),"polygon"===t.geometryType&&l.length>=2){const t=h(l[0]);e.moveTo(n[0],n[1]),e.lineTo(t[0],t[1])}e.stroke(),e.setLineDash([])}if(l.length>0){const t=4*i;e.fillStyle=a,e.beginPath();for(const i of l){const r=h(i);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=h(t.snapCoord),n=7*i;e.strokeStyle="#ff4444",e.lineWidth=2*i,e.beginPath(),"edge"===t.snapKind?e.rect(r[0]-n,r[1]-n,2*n,2*n):e.arc(r[0],r[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 st{_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 ot{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 at=Object.freeze({ok:!0,value:void 0});function lt(t){return{ok:!0,value:t}}const ct=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"}})}),ht=new Set(["rename-fields","rename-layers","sort","sort-features","filter-fields","drop","target","uniq","unique-features"]),ut=new Set(["buffer","clean","dissolve","mosaic","union","snap","check-geometry","simplify"]);function pt(t){const e=[],i=/(?:^|\s)-([a-z][a-z-]*)/gi;let r;for(;null!==(r=i.exec(t));)e.push(r[1].toLowerCase());return e}function dt(t,e,i,r){if(!1===i)return!1;if(!0===i)return!0;if(0===t.length)return e>=r;if(t.every(t=>ht.has(t)))return!1;return e>=(t.some(t=>ut.has(t))?Math.floor(.5*r):r)}const ft={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 mt(t){let e="attribute-only",i=!1;for(const r of t){if("target"===r)continue;const t=ft[r];if(void 0===t)return"unknown";i=!0,e=gt(e,t)}return i?e:"unknown"}const _t={"attribute-only":0,"crs-only":1,"topology-only":2,"shape-count":3,unknown:3};function gt(t,e){return _t[t]>=_t[e]?t:e}async function yt(t,e,i,r,n){if(t._removed)return ct.hostRemoved();const s=t._sources.get(e);if(!s)return ct.notFound("source",e);const o=s.getDataset();if(!o)return ct.notFound("source",e);const a=Q().copyDataset(o);let l,c=!1;if(t._workerPool){const e=o.arcs?.getPointCount?.()??0,r=function(t,e,i,r){return!1!==i&&(!0===i||dt(pt(t),e,i,r))}(i,e,t._workerMode,t._workerThreshold),n=t._workerRouting;c=n?n({cmd:i,heads:pt(i),vertexCount:e,mode:t._workerMode,threshold:t._workerThreshold,defaultDecision:r}):r}try{l=c?await async function(t,e,i,r,n){if(!t._workerPool)throw new Error("_runViaWorker: worker pool not available");const s=t._workerPool.reserveId(),o=e.arcs?.getPointCount?.()??0,a="undefined"!=typeof performance?performance.now():Date.now();t.fire("workerjobstart",{id:s,cmd:i,label:r,datasetVertexCount:o});try{const r=await Q().exportDatasetsToPack([e],{compact:!1}),o=bt(r),l=t._workerPool.dispatchWithId(s,i,r,n,o),c=await l,h=await Q().restoreSessionData(c);if(!h.datasets||0===h.datasets.length)throw new Error("worker: no dataset in response");const u=("undefined"!=typeof performance?performance.now():Date.now())-a;return t.fire("workerjobend",{id:s,ok:!0,durationMs:u}),h.datasets[0]}catch(e){const i=("undefined"!=typeof performance?performance.now():Date.now())-a;throw t.fire("workerjobend",{id:s,ok:!1,durationMs:i,errorMessage:e?.message??String(e)}),e}}(t,o,i,r,n):await Q().runOnDataset(i,o,n)}catch(e){return t._removed?ct.hostRemoved():(t.fire("error",{error:e}),ct.mapshaper(e,{cmd:i,operation:r}))}return t._removed?ct.hostRemoved():xt(t,e,a,l,r,function(t){return mt(pt(t))}(i))}async function vt(t,e,i,r,n){if(t._removed)return ct.hostRemoved();const s=t._sources.get(e);if(!s)return ct.notFound("source",e);const o=s.getDataset();if(!o)return ct.notFound("source",e);const a=Q().copyDataset(o),l=i.map(t=>t.name);let c,h=!1;if(t._workerPool){const e=o.arcs?.getPointCount?.()??0,i=dt(l,e,t._workerMode,t._workerThreshold),r=t._workerRouting;h=r?r({cmd:l.map(t=>`-${t}`).join(" "),heads:l,vertexCount:e,mode:t._workerMode,threshold:t._workerThreshold,defaultDecision:i}):i}try{c=h?await async function(t,e,i,r,n){if(!t._workerPool)throw new Error("_runViaWorkerParsed: worker pool not available");const s=t._workerPool.reserveId(),o=e.arcs?.getPointCount?.()??0,a="undefined"!=typeof performance?performance.now():Date.now(),l=i.map(t=>`-${t.name}`).join(" ");t.fire("workerjobstart",{id:s,cmd:l,label:r,datasetVertexCount:o});try{const r=await Q().exportDatasetsToPack([e],{compact:!1}),o=bt(r),l=t._workerPool.dispatchWithId(s,i,r,n,o),c=await l,h=await Q().restoreSessionData(c);if(!h.datasets||0===h.datasets.length)throw new Error("worker: no dataset in response");const u=("undefined"!=typeof performance?performance.now():Date.now())-a;return t.fire("workerjobend",{id:s,ok:!0,durationMs:u}),h.datasets[0]}catch(e){const i=("undefined"!=typeof performance?performance.now():Date.now())-a;throw t.fire("workerjobend",{id:s,ok:!1,durationMs:i,errorMessage:e?.message??String(e)}),e}}(t,o,i,r,n):await Q().runOnDatasetParsed(i,o,n)}catch(e){return t._removed?ct.hostRemoved():(t.fire("error",{error:e}),ct.mapshaper(e,{operation:r}))}return t._removed?ct.hostRemoved():xt(t,e,a,c,r,mt(l))}function xt(t,e,i,r,n,s="unknown"){const o=t._sources.get(e);return o?(t._activeTransaction&&t._activeTransaction._captureFirstTouch(e,i),o.setDataset(r),t._history.push(new ot({source:o,before:i,after:r,label:n})),t._history.isCapturing()||t._fireHistoryChange(),function(t){return"shape-count"===t||"topology-only"===t||"unknown"===t}(s)&&t._fireSelectionChange(t._selection.clear()),t._scheduleRender(),at):ct.notFound("source",e)}function bt(t){const e=[],i=new Set,r=t=>{if(t&&"object"==typeof t){if(t instanceof Uint8Array){const r=t.buffer;return void(r instanceof ArrayBuffer&&!i.has(r)&&(i.add(r),e.push(r)))}if(t instanceof ArrayBuffer)i.has(t)||(i.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 wt(t,e){for(let i=0;i<t.length;i++){const r=t[i];if(r){if(it(r,i)===e)return r;if(r.name===e)return r;if(r.id===e)return r}}return null}class St{_sources;constructor(t){this._sources=t}resolve(t,e){const i=this._sources.get(t);return i?wt(i.getLayers(),e):null}resolveInLayers(t,e){return wt(t,e)}}async function Tt(t,e,i){const r=t.host._sources.get(e.source);if(!r)return ct.notFound("source",e.source);const n=r.getDataset();if(!n)return ct.notFound("source",e.source);if(!wt(n.layers,e.target))return ct.notFound("layer",e.target);const s="string"==typeof e.mask&&e.mask.length>0;if(s===Array.isArray(e.bbox))return ct.validation(s?"mask":"bbox","must supply exactly one of `mask` or `bbox`");if(s){if(!wt(n.layers,e.mask))return ct.notFound("mask",e.mask)}else{const t=e.bbox;if(4!==t.length||!t.every(t=>Number.isFinite(t)))return ct.validation("bbox","must be [xmin, ymin, xmax, ymax] of finite numbers");if(t[0]>=t[2]||t[1]>=t[3])return ct.validation("bbox","must satisfy xmin<xmax and ymin<ymax")}const o=s?{source:e.mask}:{bbox:e.bbox};e.cleanup&&(o.cleanup=!0),e.removeSlivers&&(o.remove_slivers=!0);const a="clip"===i?"Clip":"Erase";return t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:i,options:o}],`${a} ${e.target}`)}const Ct="__emap_merge";async function Mt(t){const e=t.host._selection.getAll();if(0===e.length)return ct.validation("selection","selection is empty");const i=e[0].source,r=e[0].layer;for(const t of e)if(t.source!==i||t.layer!==r)return ct.validation("selection","selection spans multiple sources or layers");const n=t.host.layers.resolve(i,r);if(!n)return ct.notFound("layer",r);if(!function(t,e){const i=t.data?.getRecords?.();if(!i||0===i.length)return!1;const r=new Set(e);for(let t=0;t<i.length;t++){const e=i[t]??{};e[Ct]=r.has(t)?"M":`k_${t}`,i[t]=e}return!0}(n,e.map(t=>t.id).slice().sort((t,e)=>t-e)))return ct.validation("layer","layer has no data table; cannot stamp discriminator");const s=function(t,e){const i={fields:[Ct]},r=e.data?.getFields?.();if(r&&r.length>0){const t=r.filter(t=>t!==Ct&&!t.includes(","));t.length>0&&(i.copy_fields=t)}return[{name:"target",options:{target:t}},{name:"dissolve",options:i},{name:"filter-fields",options:{fields:[Ct],invert:!0}}]}(r,n),o=`Merge ${e.length} feature${e.length>1?"s":""}`,a=await t.runDatasetCommandParsed(i,s,o);return a.ok||function(t){const e=t.data?.getRecords?.();if(!e)return;for(const t of e)t&&Ct in t&&delete t[Ct]}(n),a}const At=new Set(["left","right","outer","inner"]),Et=new Set(["flat","round"]),It=/^-?\d+(\.\d+)?$/;function Pt(t){return"number"==typeof t&&Number.isInteger(t)&&t>0}async function Dt(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);const n=wt(r.layers,e.target);if(!n)return ct.notFound("layer",e.target);if("number"==typeof e.radius){if(!Number.isFinite(e.radius)||e.radius<=0)return ct.validation("radius","must be a positive finite number")}else{if("string"!=typeof e.radius||0===e.radius.trim().length)return ct.validation("radius","must be a positive number or non-empty expression");if(It.test(e.radius)&&Number(e.radius)<=0)return ct.validation("radius","numeric string must be a positive number")}if("string"==typeof e.radius&&!t.host._allowExpressionEvaluation([e.radius],"bufferLayer"))return ct.expressionDisabled("bufferLayer");if(void 0!==e.vertices&&!Pt(e.vertices))return ct.validation("vertices","must be a positive integer");if(void 0!==e.arcQuality&&!Pt(e.arcQuality))return ct.validation("arcQuality","must be a positive integer");if(void 0!==e.sliceLength&&!Pt(e.sliceLength))return ct.validation("sliceLength","must be a positive integer");if(void 0!==e.backtrack&&!Pt(e.backtrack))return ct.validation("backtrack","must be a positive integer");if(void 0!==e.tolerance&&!("number"==typeof(s=e.tolerance)&&Number.isFinite(s)&&s>0))return ct.validation("tolerance","must be a positive finite number");var s;if(void 0!==e.type&&!At.has(e.type))return ct.validation("type","must be one of: left, right, outer, inner");if(void 0!==e.capStyle&&!Et.has(e.capStyle))return ct.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 o={radius:String(e.radius)};void 0!==e.capStyle&&(o.cap_style=e.capStyle),void 0!==e.vertices&&(o.vertices=e.vertices),void 0!==e.arcQuality&&(o.arc_quality=e.arcQuality),void 0!==e.tolerance&&(o.tolerance=e.tolerance),void 0!==e.type&&(o.type=e.type),!0===e.planar&&(o.planar=!0),!0===e.v2&&(o.v2=!0),void 0!==e.sliceLength&&(o.slice_length=e.sliceLength),void 0!==e.backtrack&&(o.backtrack=e.backtrack);const a=[{name:"target",options:{target:e.target}},{name:"buffer",options:o}];return t.runDatasetCommandParsed(e.source,a,`Buffer ${e.target}`)}class kt{_emap;constructor(t){this._emap=t}get _ctx(){return{host:this._emap,runDatasetCommand:(t,e,i,r)=>yt(this._emap,t,e,i,r),runDatasetCommandParsed:(t,e,i,r)=>vt(this._emap,t,e,i,r),applyDatasetReplace:(t,e,i,r)=>xt(this._emap,t,e,i,r)}}clipLayer(t){return async function(t,e){return Tt(t,e,"clip")}(this._ctx,t)}eraseLayer(t){return async function(t,e){return Tt(t,e,"erase")}(this._ctx,t)}dissolveLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);const n=Array.isArray(e.fields)&&e.fields.length>0;if(void 0!==e.field&&n)return ct.validation("field","`field` and `fields` are mutually exclusive");if(void 0!==e.field&&("string"!=typeof e.field||e.field.includes(",")))return ct.validation("field","field name must be a string without `,`");if(!t.host._allowExpressionEvaluation([e.calc,e.where],"dissolveLayer"))return ct.expressionDisabled("dissolveLayer");const s={};if(e.field)s.fields=[e.field];else if(n){const t=e.fields.filter(t=>"string"==typeof t&&!t.includes(","));t.length>0&&(s.fields=t)}const o=t=>Array.isArray(t)?t.filter(t=>"string"==typeof t&&!t.includes(",")):[],a=o(e.sumFields);a.length>0&&(s.sum_fields=a);const l=o(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 Dt(this._ctx,t)}applyExpression(t){return async function(t,e){if(!e.expression||!e.expression.trim())return ct.validation("expression","must be a non-empty expression");const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.expression,e.where],"applyExpression"))return ct.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 ct.validation("expression","must supply `expression` or `removeEmpty: true`");const r=t.host._sources.get(e.source);if(!r)return ct.notFound("source",e.source);const n=r.getDataset();if(!n)return ct.notFound("source",e.source);if(!wt(n.layers,e.target))return ct.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.expression],"filterFeatures"))return ct.expressionDisabled("filterFeatures");const s={};return i&&(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 i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);const n="number"==typeof e.minArea&&Number.isFinite(e.minArea),s="number"==typeof e.minVertices&&Number.isInteger(e.minVertices)&&e.minVertices>0;if(!n&&!s)return ct.validation("minArea","must supply at least one of `minArea` or `minVertices`");if(n&&e.minArea<0)return ct.validation("minArea","must be non-negative");const o={};return n&&(o.min_area=String(e.minArea)),s&&(o.min_vertices=e.minVertices),e.removeEmpty&&(o.remove_empty=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"filter-islands",options:o}],`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 ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);if("number"!=typeof e.minArea||!Number.isFinite(e.minArea)||e.minArea<=0)return ct.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 ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.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]?ct.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}`):ct.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 ct.notFound("source",e.source);const r=i.getDataset();return r?wt(r.layers,e.target)?t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"explode",options:{}}],`Explode ${e.target}`):ct.notFound("layer",e.target):ct.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 ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.where],"innerlinesLayer"))return ct.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 ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.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 ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);const n=t=>void 0===t||"number"==typeof t&&Number.isFinite(t)&&t>=0;if(!n(e.gapFillArea))return ct.validation("gapFillArea","must be a finite non-negative number");if(!n(e.sliverControl))return ct.validation("sliverControl","must be a finite non-negative number");if(!n(e.snapInterval))return ct.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 ct.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 i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.calc],"mosaicLayer"))return ct.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 ct.validation("targets","must supply at least 2 target layers");const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);for(const t of e.targets){if("string"!=typeof t||t.includes(","))return ct.validation("targets",`target name must not contain ',': ${String(t)}`);if(!wt(r.layers,t))return ct.notFound("layer",t)}const n=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:n}},{name:"union",options:s}],`Union ${n}`)}(this._ctx,t)}divideLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);const n=wt(r.layers,e.target);if(!n)return ct.notFound("layer",e.target);if("polyline"!==n.geometry_type)return ct.validation("target",`expected polyline layer, got ${n.geometry_type??"unknown"}`);const s=wt(r.layers,e.divider);if(!s)return ct.notFound("divider",e.divider);if("polygon"!==s.geometry_type)return ct.validation("divider",`expected polygon layer, got ${s.geometry_type??"unknown"}`);const o={source:e.divider};if(e.fields&&e.fields.length>0){const t=e.fields.filter(t=>!t.includes(","));t.length>0&&(o.fields=t)}return e.force&&(o.force=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"divide",options:o}],`Divide ${e.target}`)}(this._ctx,t)}pointsLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);const n=wt(r.layers,e.target);if(!n)return ct.notFound("layer",e.target);const s=n.geometry_type;switch(e.type){case"centroid":case"inner":if("polygon"!==s)return ct.validation("type",`${e.type} requires polygon target, got ${s??"unknown"}`);break;case"midpoints":case"interpolated":if("polyline"!==s)return ct.validation("type",`${e.type} requires polyline target, got ${s??"unknown"}`);break;case"vertices":case"endpoints":if("polygon"!==s&&"polyline"!==s)return ct.validation("type",`${e.type} requires polygon/polyline target, got ${s??"unknown"}`);break;default:return ct.validation("type",`unknown type: ${String(e.type)}`)}if("interpolated"===e.type&&!("number"==typeof e.interval&&e.interval>0))return ct.validation("interval","interpolated points require a positive interval");const o={[e.type]:!0};return"interpolated"===e.type&&(o.interval=String(e.interval)),e.name&&e.name.trim()&&(o.name=e.name),e.noReplace&&(o.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"points",options:o}],`Points ${e.target}`)}(this._ctx,t)}linesLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);const n=wt(r.layers,e.target);if(!n)return ct.notFound("layer",e.target);if("polygon"!==n.geometry_type)return ct.validation("target",`expected polygon layer, got ${n.geometry_type??"unknown"}`);const s={},o=e.fields?.filter(t=>"string"==typeof t&&!t.includes(","));return o&&o.length>0&&(s.fields=o),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 i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);const n=wt(r.layers,e.target);if(!n)return ct.notFound("layer",e.target);if("polyline"!==n.geometry_type)return ct.validation("target",`expected polyline layer, got ${n.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 i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(void 0!==e.target&&!wt(r.layers,e.target))return ct.notFound("layer",e.target);if(1!==[void 0!==e.percentage,void 0!==e.interval,void 0!==e.resolution].filter(Boolean).length)return ct.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 ct.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 ct.validation("interval","must be a positive finite number");n.interval=String(t)}else{const t=e.resolution;if(!/^\d+x\d+$/.test(t))return ct.validation("resolution","must match `WIDTHxHEIGHT` (digits)");n.resolution=t}if(void 0!==e.weighting&&void 0!==e.method&&"weighted"!==e.method)return ct.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 s=[];e.target&&s.push({name:"target",options:{target:e.target}}),s.push({name:"simplify",options:n});const o=`Simplify ${e.target??e.source}`;return t.runDatasetCommandParsed(e.source,s,o)}(this._ctx,t)}projectLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(void 0!==e.target&&!wt(r.layers,e.target))return ct.notFound("layer",e.target);const n=(e.crs??"").trim();if(0===n.length)return ct.validation("crs","must be a non-empty CRS string");const s={crs:n};e.init&&e.init.trim()&&(s.init=e.init),e.densify&&(s.densify=!0);const o=[];e.target&&o.push({name:"target",options:{target:e.target}}),o.push({name:"proj",options:s});const a=`Project ${e.target??e.source}`;return t.runDatasetCommandParsed(e.source,o,a)}(this._ctx,t)}affineLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(void 0!==e.target&&!wt(r.layers,e.target))return ct.notFound("layer",e.target);const n=Array.isArray(e.shift),s="number"==typeof e.rotate&&0!==e.rotate,o=void 0!==e.scale&&("number"==typeof e.scale?1!==e.scale:Array.isArray(e.scale));if(!n&&!s&&!o)return ct.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 ct.validation("shift","must be [dx, dy] of finite numbers")}if(s&&!Number.isFinite(e.rotate))return ct.validation("rotate","must be a finite number (degrees)");if(o&&Array.isArray(e.scale)){const t=e.scale;if(2!==t.length||!t.every(t=>Number.isFinite(t)&&0!==t))return ct.validation("scale","must be [sx, sy] of nonzero finite numbers")}else if(o&&"number"==typeof e.scale&&(!Number.isFinite(e.scale)||0===e.scale))return ct.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 ct.validation("anchor","must be [x, y] of finite numbers");if(!t.host._allowExpressionEvaluation([e.where],"affineLayer"))return ct.expressionDisabled("affineLayer");const a={};n&&(a.shift=[String(e.shift[0]),String(e.shift[1])]),s&&(a.rotate=e.rotate),o&&(a.scale=(e.scale,e.scale)),e.anchor&&(a.anchor=[e.anchor[0],e.anchor[1]]),e.where&&e.where.trim()&&(a.where=e.where);const l=[];e.target&&l.push({name:"target",options:{target:e.target}}),l.push({name:"affine",options:a});const c=`Affine ${e.target??e.source}`;return t.runDatasetCommandParsed(e.source,l,c)}(this._ctx,t)}renameLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);const n=(e.name??"").trim();if(0===n.length)return ct.validation("name","must be a non-empty string");if(n.includes(","))return ct.validation("name","must not contain `,`");if(n!==e.target&&r.layers.some(t=>(t?.name??"")===n))return ct.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 ct.validation("targets","must supply at least 2 target layers");const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);for(const t of e.targets)if("string"!=typeof t||t.includes(","))return ct.validation("targets",`target name must not contain ',': ${String(t)}`);const n=e.targets.map(t=>wt(r.layers,t));for(let t=0;t<n.length;t++)if(!n[t])return ct.notFound("layer",e.targets[t]);if(!e.force){const t=n[0]?.geometry_type;if(!n.every(e=>e?.geometry_type===t))return ct.validation("targets","targets have mixed geometry types; pass `force: true` to merge anyway")}const s=e.targets.join(","),o={};return e.name&&e.name.trim()&&(o.name=e.name),e.force&&(o.force=!0),e.flatten&&(o.flatten=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:s}},{name:"merge-layers",options:o}],`Merge ${s}`)}(this._ctx,t)}splitLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);const n=(e.expression??"").trim();if(0===n.length)return ct.validation("expression","must be a non-empty expression");if(!t.host._allowExpressionEvaluation([n],"splitLayer"))return ct.expressionDisabled("splitLayer");const s={expression:n};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 i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();return r?wt(r.layers,e.target)?t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"drop",options:{}}],`Drop ${e.target}`):ct.notFound("layer",e.target):ct.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 ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);const n=(e.expression??"").trim();if(0===n.length)return ct.validation("expression","must be a non-empty expression");if(!t.host._allowExpressionEvaluation([n],"sortFeatures"))return ct.expressionDisabled("sortFeatures");const s={expression:n};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 i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);const n=(e.expression??"").trim();if(0===n.length)return ct.validation("expression","must be a non-empty expression");if(!t.host._allowExpressionEvaluation([n],"uniqueFeatures"))return ct.expressionDisabled("uniqueFeatures");if(void 0!==e.maxCount&&!("number"==typeof e.maxCount&&e.maxCount>0))return ct.validation("maxCount","must be a positive number");const s={expression:n};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 i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);if(!Array.isArray(e.fields)||0===e.fields.length)return ct.validation("fields","must be a non-empty array");for(const t of e.fields){if("string"!=typeof t||0===t.trim().length)return ct.validation("fields",`field name must be a non-empty string: ${String(t)}`);if(t.includes(","))return ct.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 ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);if(!e.mapping||"object"!=typeof e.mapping)return ct.validation("mapping","must be an object of { oldName: newName }");const n=Object.entries(e.mapping);if(0===n.length)return ct.validation("mapping","must contain at least one rename pair");const s=[];for(const[t,e]of n){const i=(t??"").trim(),r=(e??"").trim();if(0===i.length||0===r.length)return ct.validation("mapping",`field names must be non-empty: ${t}=${e}`);if(i.includes(",")||i.includes("=")||r.includes(",")||r.includes("="))return ct.validation("mapping",`field names must not contain ',' or '=': ${t}=${e}`);s.push(`${i}=${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 i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);if(!Array.isArray(e.keys)||2!==e.keys.length)return ct.validation("keys","must be a 2-element [targetKey, sourceKey] array");const[n,s]=e.keys.map(t=>"string"==typeof t?t.trim():"");if(0===n.length||0===s.length)return ct.validation("keys","both keys must be non-empty strings");if(n.includes(",")||s.includes(","))return ct.validation("keys","keys must not contain `,`");let o,a;const l=e.data;if(!l||"object"!=typeof l)return ct.validation("data","must be { csv } | { json } | { layer }");if("layer"in l&&"string"==typeof l.layer&&l.layer.trim().length>0)o=l.layer.trim();else if("csv"in l&&("string"==typeof l.csv||l.csv instanceof Uint8Array)){const t=".emap-join.csv";o=t,a={[t]:l.csv}}else{if(!("json"in l)||void 0===l.json)return ct.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),o=t,a={[t]:e}}}if(!t.host._allowExpressionEvaluation([e.where,e.calc],"joinTable"))return ct.expressionDisabled("joinTable");const c={source:o,keys:[n,s]};if(e.fields&&e.fields.length>0){const t=e.fields.filter(t=>"string"==typeof t&&!t.includes(","));t.length>0&&(c.fields=t)}return e.prefix&&e.prefix.length>0&&(c.prefix=e.prefix),e.where&&e.where.trim().length>0&&(c.where=e.where),e.calc&&e.calc.trim().length>0&&(c.calc=e.calc),e.unjoined&&(c.unjoined=!0),e.unmatched&&(c.unmatched=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"join",options:c}],`Join ${e.target}`,a)}(this._ctx,t)}dataFill(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!wt(r.layers,e.target))return ct.notFound("layer",e.target);if("string"!=typeof e.field||0===e.field.trim().length)return ct.validation("field","must be a non-empty string");if(e.field.includes(",")||e.field.includes("="))return ct.validation("field","must not contain `,` or `=`");if(void 0!==e.weightField){if("string"!=typeof e.weightField||0===e.weightField.trim().length)return ct.validation("weightField","must be a non-empty string when supplied");if(e.weightField.includes(",")||e.weightField.includes("="))return ct.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 ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(!r.arcs)return at;const n=Q(),s=n.copyDataset(r),o=n.copyDataset(r);try{n.addIntersectionCuts(o,{snap_interval:e.snapInterval,no_snap:e.noSnap,rebuild_topology:e.rebuildTopology})}catch(e){return t.host.fire("error",{error:e}),ct.mapshaper(e,{operation:"rebuildTopology"})}return t.applyDatasetReplace(e.source,s,o,"Rebuild topology")}(this._ctx,t)}checkGeometry(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);if(void 0!==e.target&&!wt(r.layers,e.target))return ct.notFound("layer",e.target);if(!r.arcs)return lt({ok:!0,intersections:[],intersectionCount:0});const n={};void 0!==e.tolerance&&(n.tolerance=e.tolerance);const s=Q().findSegmentIntersections(r.arcs,n).map(t=>({x:t.x,y:t.y}));return lt({ok:0===s.length,intersections:s,intersectionCount:s.length})}(this._ctx,t)}intersectionPointsLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return ct.notFound("source",e.source);const r=i.getDataset();if(!r)return ct.notFound("source",e.source);const n=wt(r.layers,e.target);if(!n)return ct.notFound("layer",e.target);if("polygon"!==n.geometry_type&&"polyline"!==n.geometry_type)return ct.validation("target",`expected polygon/polyline target, got ${n.geometry_type??"unknown"}`);if(!r.arcs)return ct.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 ct.validation("name",`another layer already named '${s}'`);if(void 0!==e.tolerance&&("number"!=typeof e.tolerance||!Number.isFinite(e.tolerance)||e.tolerance<=0))return ct.validation("tolerance","must be a positive finite number");const o={};void 0!==e.tolerance&&(o.tolerance=e.tolerance);const a=Q(),l=a.copyDataset(r),c=a.copyDataset(r);let h;try{const t=a.findSegmentIntersections(c.arcs,o),i=wt(c.layers,e.target);if(!i)throw new Error("intersectionPointsLayer: target lost in copyDataset");h=a.getIntersectionLayer(t,i,c.arcs),h.name=s,c.layers.push(h)}catch(e){return t.host.fire("error",{error:e}),ct.mapshaper(e,{operation:"intersectionPointsLayer"})}return t.applyDatasetReplace(e.source,l,c,`Intersection points ${e.target}`)}(this._ctx,t)}mergeSelected(){return Mt(this._ctx)}}class zt{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 Rt(t){return"polygon"===t.geometry_type||"polyline"===t.geometry_type}function Lt(t){t&&(t.editVersion=(t.editVersion??0)+1)}class Ft{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 Ft))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 r=t.opts.pointFeatures,n=this.opts.pointFeatures;if(r.length!==n.length)return!1;for(let t=0;t<r.length;t++){if(r[t].featureId!==n[t].featureId)return!1;if(r[t].layer!==n[t].layer)return!1}return!0}merge(t){t instanceof Ft&&(this.opts.dx+=t.opts.dx,this.opts.dy+=t.opts.dy,this._mergeAt=Date.now())}_apply(t,e){const{arcs:i,arcIds:r,pointFeatures:n,source:s}=this.opts;if(i&&r.length>0){const n=i.getVertexData?.();if(n){const{xx:s,yy:o,ii:a,nn:l}=n;for(const n of r){const r=a[n],c=l[n];for(let i=r;i<r+c;i++)s[i]+=t,o[i]+=e;i.updateArcBounds?.(n)}}}for(const i of n){const r=i.layer.shapes?.[i.featureId];if(r)for(const i of rt(r))i&&i.length>=2&&(i[0]+=t,i[1]+=e)}s.markDisplayArcsDirty?.(),Lt(s.getDataset?.())}}class Bt{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(Gt(this.opts.matrix))}_apply(t){const{arcs:e,arcIds:i,pointFeatures:r,source:n}=this.opts;if(e&&i.length>0){const r=e.getVertexData?.();if(r){const{xx:n,yy:s,ii:o,nn:a}=r;for(const r of i){const i=o[r],l=a[r];for(let e=i;e<i+l;e++){const i=n[e],r=s[e];n[e]=t.a*i+t.c*r+t.tx,s[e]=t.b*i+t.d*r+t.ty}e.updateArcBounds?.(r)}}}for(const e of r){const i=e.layer.shapes?.[e.featureId];if(i)for(const e of rt(i))if(e&&e.length>=2){const i=e[0],r=e[1];e[0]=t.a*i+t.c*r+t.tx,e[1]=t.b*i+t.d*r+t.ty}}n.markDisplayArcsDirty?.(),Lt(n.getDataset?.())}}function Ot(t,e=0,i=0){const r=Math.cos(t),n=Math.sin(t);return{a:r,b:n,c:-n,d:r,tx:e-r*e+n*i,ty:i-n*e-r*i}}function Nt(t,e,i=0,r=0){return{a:t,b:0,c:0,d:e,tx:i-t*i,ty:r-e*r}}function Vt(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 jt={a:1,b:0,c:0,d:1,tx:0,ty:0};function Gt(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,r=-t.b/e,n=-t.c/e,s=t.a/e;return{a:i,b:r,c:n,d:s,tx:-(i*t.tx+n*t.ty),ty:-(r*t.tx+s*t.ty)}}class Ut{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:r,yy:n,zz:s,nn:o}=i,a=!!s&&e.every(t=>t.zz);let l=0;for(const t of e)l+=t.xx.length;const c=new Float64Array(r.length+l),h=new Float64Array(n.length+l),u=a?new Float64Array(s.length+l):null;c.set(r),h.set(n),u&&s&&u.set(s);let p=r.length;for(const t of e)c.set(t.xx,p),h.set(t.yy,p),u&&t.zz&&u.set(t.zz,p),p+=t.xx.length;const d=new Int32Array(o.length+e.length);d.set(o);for(let t=0;t<e.length;t++)d[o.length+t]=e[t].xx.length;t.updateVertexData(d,c,h,u)}(t,this.opts.appendedArcs);for(const t of this.opts.remaps)t.layer.shapes[t.featureId]=Zt(t.newShape);this.opts.source.markDisplayArcsDirty?.(),Lt(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:r,yy:n,zz:s,nn:o}=i;if(o.length===e)return;if(e>o.length)return;let a=0;for(let t=0;t<e;t++)a+=o[t];const l=new Int32Array(e);l.set(o.subarray(0,e));const c=new Float64Array(r.subarray(0,a)),h=new Float64Array(n.subarray(0,a)),u=s?new Float64Array(s.subarray(0,a)):null;t.updateVertexData(l,c,h,u)}(t,this.opts.originalArcCount);for(const t of this.opts.remaps)t.layer.shapes[t.featureId]=Zt(t.originalShape);this.opts.source.markDisplayArcsDirty?.(),Lt(this.opts.source.getDataset?.())}}}function qt(t,e,i){const r=t.getArcs();if(!r)return null;const n=r.size();if(0===n||0===e.length)return null;const s=new Uint32Array(n),o=new Uint32Array(n),a=new Set;for(const t of e)a.add($t(t.layer,t.featureId));for(const t of i){if(!t.shapes)continue;if(!Rt(t))continue;const e=t.shapes;for(let i=0;i<e.length;i++){const r=e[i];if(!r)continue;const l=a.has($t(t,i));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>=n||(l?s[t]++:o[t]++)}}}const l=[];for(let t=0;t<n;t++)s[t]>0&&o[t]>0&&l.push(t);if(0===l.length)return null;const c=new globalThis.Map;for(let t=0;t<l.length;t++)c.set(l[t],n+t);const h=r.getVertexData?.();if(!h)return null;const{xx:u,yy:p,zz:d,ii:f,nn:m}=h,_=l.map(t=>{const e=f[t],i=m[t];return{xx:new Float64Array(u.subarray(e,e+i)),yy:new Float64Array(p.subarray(e,e+i)),zz:d?new Float64Array(d.subarray(e,e+i)):null}}),g=[];for(const t of e){if(!Rt(t.layer))continue;const e=t.layer.shapes?.[t.featureId];if(!e)continue;let i=!1;const r=e.map(t=>t.map(t=>{const e=t>=0?t:~t,r=c.get(e);return void 0===r?t:(i=!0,t>=0?r:~r)}));i&&g.push({layer:t.layer,featureId:t.featureId,originalShape:Zt(e),newShape:r})}return 0===g.length?null:{source:t,remaps:g,appendedArcs:_,originalArcCount:n}}function $t(t,e){return`${t.name??""}#${e}`}function Zt(t){return t.map(t=>t.slice())}class Wt{_emap;constructor(t){this._emap=t}translateSelected(t,e){if(0===t&&0===e)return ct.validation("offset","dx and dy are both 0 (no-op)");const i=this._emap._selection.getAll();if(0===i.length)return ct.validation("selection","selection is empty");const r=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=r.get(t.source);if(n||(n={arcIdSet:new Set,pointFeatures:[]},r.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===r.size)return ct.validation("selection","no resolvable layers in selection");const n=[],s=[];for(const[i,o]of r){const r=this._emap._sources.get(i);if(!r)continue;if(0===o.arcIdSet.size&&0===o.pointFeatures.length)continue;const a=new Ft({source:r,arcs:r.getArcs(),dx:t,dy:e,arcIds:Array.from(o.arcIdSet),pointFeatures:o.pointFeatures});a.do(),n.push(a),s.push(i)}if(0===n.length)return ct.validation("selection","every resolved layer was empty");const o=1===n.length?n[0]:new zt(n,`Translate ${i.length} features`);return this._emap._history.push(o),this._emap._fireHistoryChange(),this._emap._clearSpatialIndexesForSources(s),this._emap._scheduleRender(),at}_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 r=this._emap._sources.get(t.source);if(!r)continue;let n=i.get(t.source);n||(n={sourceId:t.source,source:r,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 r=[];if(t)for(const t of i.values()){if(0===t.pathFeatures.length)continue;const e=qt(t.source,t.pathFeatures,t.source.getLayers());if(!e)continue;const i=new Ut(e);i.do(),r.push(i),this._emap._invalidateShapeCachesForSources([t.sourceId])}for(const t of i.values()){const e=new Set;for(const i of t.pathFeatures){const r=i.layer.shapes?.[i.featureId];if(r)for(const i of r)if(Array.isArray(i))for(const r of i){if("number"!=typeof r)continue;const i=r>=0?r:~r;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:r}}beginTranslateSession(t){const e=this._buildSelectionBuckets(!1!==t?.splitSharedArcs);if(!e)return null;const{buckets:i,splitCmds:r}=e;let n=0,s=0,o=!1;const a=(t,e)=>{for(const r of i)0===r.arcIds.length&&0===r.pointFeatures.length||new Ft({source:r.source,arcs:r.source.getArcs(),dx:t,dy:e,arcIds:r.arcIds,pointFeatures:r.pointFeatures}).do()};return{move:(t,e)=>{o||0===t&&0===e||(a(t,e),n+=t,s+=e,this._emap._scheduleRender())},commit:()=>{if(o)return!1;o=!0;if(!!(0===n&&0===s)){for(let t=r.length-1;t>=0;t--)r[t].undo();return r.length>0&&this._emap._scheduleRender(),!1}const t=i.map(t=>new Ft({source:t.source,arcs:t.source.getArcs(),dx:n,dy:s,arcIds:t.arcIds,pointFeatures:t.pointFeatures})),e=i.reduce((t,e)=>t+e.arcIds.length+e.pointFeatures.length,0),a=[...r,...t],l=1===a.length?a[0]:new zt(a,`Translate ${e} features`);return this._emap._history.push(l),this._emap._fireHistoryChange(),this._emap._invalidateShapeCachesForSources(i.map(t=>t.sourceId)),this._emap._scheduleRender(),!0},cancel:()=>{if(!o){o=!0,0===n&&0===s||a(-n,-s);for(let t=r.length-1;t>=0;t--)r[t].undo();n=0,s=0,r.length>0&&this._emap._invalidateShapeCachesForSources(i.map(t=>t.sourceId)),this._emap._scheduleRender()}},getAccumulated:()=>[n,s]}}beginAffineSession(t,e){const i=this._buildSelectionBuckets(!1!==e?.splitSharedArcs);if(!i)return null;const{buckets:r,splitCmds:n}=i;let s,o;if(t)[s,o]=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=n.length-1;t>=0;t--)n[t].undo();return null}[s,o]=e}if(!Number.isFinite(s)||!Number.isFinite(o)){for(let t=n.length-1;t>=0;t--)n[t].undo();return null}const a=[s,o];let l={...jt},c=!1;const h=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 Bt({source:e.source,arcs:e.source.getArcs(),matrix:t,arcIds:e.arcIds,pointFeatures:e.pointFeatures}).do()};return{origin:a,applyDelta:t=>{c||h(t)||(u(t),l=Vt(t,l),this._emap._scheduleRender())},commit:t=>{if(c)return!1;if(c=!0,h(l)){for(let t=n.length-1;t>=0;t--)n[t].undo();return n.length>0&&this._emap._scheduleRender(),!1}const e=r.reduce((t,e)=>t+e.arcIds.length+e.pointFeatures.length,0),i=r.map(e=>new Bt({source:e.source,arcs:e.source.getArcs(),matrix:l,arcIds:e.arcIds,pointFeatures:e.pointFeatures,label:t})),s=[...n,...i],o=1===s.length?s[0]:new zt(s,t??`Transform ${e} feature${1===e?"":"s"}`);return this._emap._history.push(o),this._emap._fireHistoryChange(),this._emap._invalidateShapeCachesForSources(r.map(t=>t.sourceId)),this._emap._scheduleRender(),!0},cancel:()=>{if(!c){c=!0,h(l)||u(Gt(l));for(let t=n.length-1;t>=0;t--)n[t].undo();l={...jt},n.length>0&&this._emap._invalidateShapeCachesForSources(r.map(t=>t.sourceId)),this._emap._scheduleRender()}},getCumulative:()=>({...l})}}rotateSelected(t,e){if(0===t)return ct.validation("angleDegrees","angle is 0 (no-op)");const i=t*Math.PI/180;return this._applyAffineToSelection((t,e)=>Ot(i,t,e),e,t=>`Rotate ${t} feature${1===t?"":"s"}`)}scaleSelected(t,e,i){const r=t,n=e??t;return 1===r&&1===n?ct.validation("scale","sx and sy are both 1 (no-op)"):this._applyAffineToSelection((t,e)=>Nt(r,n,t,e),i,t=>`Scale ${t} feature${1===t?"":"s"}`)}_applyAffineToSelection(t,e,i){const r=this._emap._selection.getAll();if(0===r.length)return ct.validation("selection","selection is empty");const n=new globalThis.Map;for(const t of r){const e=this._emap.layers.resolve(t.source,t.layer);if(!e?.shapes)continue;const i=e.shapes[t.id];if(!i)continue;let r=n.get(t.source);if(r||(r={arcIdSet:new Set,pointFeatures:[]},n.set(t.source,r)),"point"===e.geometry_type)r.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&&r.arcIdSet.add(t>=0?t:~t)}}if(0===n.size)return ct.validation("selection","no resolvable layers in selection");let s,o;if(e)s=e[0],o=e[1];else{const t=this._computeSelectionCentroid(n);if(!t)return ct.validation("origin","no vertices in selection; cannot compute centroid");[s,o]=t}if(!Number.isFinite(s)||!Number.isFinite(o))return ct.validation("origin","computed origin is not finite");const a=t(s,o),l=[],c=[];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 r=new Bt({source:i,arcs:i.getArcs(),matrix:a,arcIds:Array.from(e.arcIdSet),pointFeatures:e.pointFeatures});r.do(),l.push(r),c.push(t)}if(0===l.length)return ct.validation("selection","every resolved layer was empty");const h=1===l.length?l[0]:new zt(l,i(r.length));return this._emap._history.push(h),this._emap._fireHistoryChange(),this._emap._clearSpatialIndexesForSources(c),this._emap._scheduleRender(),at}_computeSelectionCentroid(t){let e=1/0,i=1/0,r=-1/0,n=-1/0,s=!1;for(const[o,a]of t){const t=this._emap._sources.get(o);if(!t)continue;const l=t.getArcs(),c=l?.getVertexData?.();if(c&&a.arcIdSet.size>0){const{xx:t,yy:o,ii:l,nn:h}=c;for(const c of a.arcIdSet){const a=l[c],u=h[c];for(let l=a;l<a+u;l++){const a=t[l],c=o[l];a<e&&(e=a),a>r&&(r=a),c<i&&(i=c),c>n&&(n=c),s=!0}}}for(const t of a.pointFeatures){const o=t.layer.shapes?.[t.featureId];if(o)for(const t of rt(o)){if(!t||t.length<2)continue;const o=t[0],a=t[1];o<e&&(e=o),o>r&&(r=o),a<i&&(i=a),a>n&&(n=a),s=!0}}}return s?[(e+r)/2,(i+n)/2]:null}}class Ht{opts;label;constructor(t){this.opts=t,this.label=t.label??"Edit properties"}do(){Xt(this.opts.layer,this.opts.featureId,this.opts.prev,this.opts.next)}undo(){Xt(this.opts.layer,this.opts.featureId,this.opts.next,this.opts.prev)}}function Xt(t,e,i,r){const n=t.data?.getRecords?.(),s=n?.[e];if(s){for(const t of Object.keys(r))s[t]=r[t];for(const t of Object.keys(i))t in r||delete s[t]}}class Yt{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 Kt{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 r=t[e];r&&(r[this.opts.field]=i)}}}class Jt{opts;label;constructor(t){this.opts=t,this.label=`Rename field ${t.from} → ${t.to}`}do(){Qt(this.opts.layer,this.opts.from,this.opts.to)}undo(){Qt(this.opts.layer,this.opts.to,this.opts.from)}}function Qt(t,e,i){const r=t.data?.getRecords?.();if(r)for(const t of r)t&&e in t&&(t[i]=t[e],delete t[e])}class te{_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 ct.notFound("layer",t.layer);const r=i.data?.getRecords?.(),n=r?.[t.id];if(!n)return ct.notFound("field",`record#${t.id}`);const s={},o={};for(const t of Object.keys(e)){const i=t in n,r=i?n[t]:void 0,a=e[t];(void 0!==a||i)&&(void 0!==a&&i&&n[t]===a||(i&&(s[t]=r),void 0!==a&&(o[t]=a)))}if(0===Object.keys(s).length&&0===Object.keys(o).length)return ct.validation("props","no-op: every requested value already matches the record");const a=new Ht({layer:i,featureId:t.id,prev:s,next:o});return a.do(),this._emap._history.push(a),this._emap._fireHistoryChange(),this._emap._scheduleRender(),at}addField(t){const e=this._emap.layers.resolve(t.source,t.target);if(!e)return ct.notFound("layer",t.target);if(!e.data)return ct.validation("target","layer has no data table");const i=new Yt({layer:e,field:t.field,defaultValue:t.defaultValue});return i.do(),this._emap._history.push(i),this._emap._fireHistoryChange(),this._emap._scheduleRender(),at}removeField(t){const e=this._emap.layers.resolve(t.source,t.target);if(!e)return ct.notFound("layer",t.target);if(!e.data)return ct.validation("target","layer has no data table");const i=new Kt({layer:e,field:t.field});return i.do(),this._emap._history.push(i),this._emap._fireHistoryChange(),this._emap._scheduleRender(),at}renameField(t){const e=this._emap.layers.resolve(t.source,t.target);if(!e)return ct.notFound("layer",t.target);if(!e.data)return ct.validation("target","layer has no data table");const i=e.data.getRecords?.();if(!i)return ct.validation("target","data table has no records");if(t.from===t.to)return ct.validation("to","`from` and `to` are identical");for(const e of i)if(e&&t.from in e&&t.to in e)return ct.validation("to",`would overwrite existing '${t.to}' on at least one record`);const r=new Jt({layer:e,from:t.from,to:t.to});return r.do(),this._emap._history.push(r),this._emap._fireHistoryChange(),this._emap._scheduleRender(),at}}class ee{_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 ie={},re=Uint8Array,ne=Uint16Array,se=Int32Array,oe=new re([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]),ae=new re([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]),le=new re([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),ce=function(t,e){for(var i=new ne(31),r=0;r<31;++r)i[r]=e+=1<<t[r-1];var n=new se(i[30]);for(r=1;r<30;++r)for(var s=i[r];s<i[r+1];++s)n[s]=s-i[r]<<5|r;return{b:i,r:n}},he=ce(oe,2),ue=he.b,pe=he.r;ue[28]=258,pe[258]=28;for(var de=ce(ae,0),fe=de.b,me=de.r,_e=new ne(32768),ge=0;ge<32768;++ge){var ye=(43690&ge)>>1|(21845&ge)<<1;ye=(61680&(ye=(52428&ye)>>2|(13107&ye)<<2))>>4|(3855&ye)<<4,_e[ge]=((65280&ye)>>8|(255&ye)<<8)>>1}var ve=function(t,e,i){for(var r=t.length,n=0,s=new ne(e);n<r;++n)t[n]&&++s[t[n]-1];var o,a=new ne(e);for(n=1;n<e;++n)a[n]=a[n-1]+s[n-1]<<1;if(i){o=new ne(1<<e);var l=15-e;for(n=0;n<r;++n)if(t[n])for(var c=n<<4|t[n],h=e-t[n],u=a[t[n]-1]++<<h,p=u|(1<<h)-1;u<=p;++u)o[_e[u]>>l]=c}else for(o=new ne(r),n=0;n<r;++n)t[n]&&(o[n]=_e[a[t[n]-1]++]>>15-t[n]);return o},xe=new re(288);for(ge=0;ge<144;++ge)xe[ge]=8;for(ge=144;ge<256;++ge)xe[ge]=9;for(ge=256;ge<280;++ge)xe[ge]=7;for(ge=280;ge<288;++ge)xe[ge]=8;var be=new re(32);for(ge=0;ge<32;++ge)be[ge]=5;var we=ve(xe,9,0),Se=ve(xe,9,1),Te=ve(be,5,0),Ce=ve(be,5,1),Me=function(t){for(var e=t[0],i=1;i<t.length;++i)t[i]>e&&(e=t[i]);return e},Ae=function(t,e,i){var r=e/8|0;return(t[r]|t[r+1]<<8)>>(7&e)&i},Ee=function(t,e){var i=e/8|0;return(t[i]|t[i+1]<<8|t[i+2]<<16)>>(7&e)},Ie=function(t){return(t+7)/8|0},Pe=function(t,e,i){return(null==e||e<0)&&(e=0),(null==i||i>t.length)&&(i=t.length),new re(t.subarray(e,i))},De=["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"],ke=function(t,e,i){var r=new Error(e||De[t]);if(r.code=t,Error.captureStackTrace&&Error.captureStackTrace(r,ke),!i)throw r;return r},ze=function(t,e,i,r){var n=t.length,s=r?r.length:0;if(!n||e.f&&!e.l)return i||new re(0);var o=!i,a=o||2!=e.i,l=e.i;o&&(i=new re(3*n));var c=function(t){var e=i.length;if(t>e){var r=new re(Math.max(2*e,t));r.set(i),i=r}},h=e.f||0,u=e.p||0,p=e.b||0,d=e.l,f=e.d,m=e.m,_=e.n,g=8*n;do{if(!d){h=Ae(t,u,1);var y=Ae(t,u+1,3);if(u+=3,!y){var v=t[(P=Ie(u)+4)-4]|t[P-3]<<8,x=P+v;if(x>n){l&&ke(0);break}a&&c(p+v),i.set(t.subarray(P,x),p),e.b=p+=v,e.p=u=8*x,e.f=h;continue}if(1==y)d=Se,f=Ce,m=9,_=5;else if(2==y){var b=Ae(t,u,31)+257,w=Ae(t,u+10,15)+4,S=b+Ae(t,u+5,31)+1;u+=14;for(var T=new re(S),C=new re(19),M=0;M<w;++M)C[le[M]]=Ae(t,u+3*M,7);u+=3*w;var A=Me(C),E=(1<<A)-1,I=ve(C,A,1);for(M=0;M<S;){var P,D=I[Ae(t,u,E)];if(u+=15&D,(P=D>>4)<16)T[M++]=P;else{var k=0,z=0;for(16==P?(z=3+Ae(t,u,3),u+=2,k=T[M-1]):17==P?(z=3+Ae(t,u,7),u+=3):18==P&&(z=11+Ae(t,u,127),u+=7);z--;)T[M++]=k}}var R=T.subarray(0,b),L=T.subarray(b);m=Me(R),_=Me(L),d=ve(R,m,1),f=ve(L,_,1)}else ke(1);if(u>g){l&&ke(0);break}}a&&c(p+131072);for(var F=(1<<m)-1,B=(1<<_)-1,O=u;;O=u){var N=(k=d[Ee(t,u)&F])>>4;if((u+=15&k)>g){l&&ke(0);break}if(k||ke(2),N<256)i[p++]=N;else{if(256==N){O=u,d=null;break}var V=N-254;if(N>264){var j=oe[M=N-257];V=Ae(t,u,(1<<j)-1)+ue[M],u+=j}var G=f[Ee(t,u)&B],U=G>>4;G||ke(3),u+=15&G;L=fe[U];if(U>3){j=ae[U];L+=Ee(t,u)&(1<<j)-1,u+=j}if(u>g){l&&ke(0);break}a&&c(p+131072);var q=p+V;if(p<L){var $=s-L,Z=Math.min(L,q);for($+p<0&&ke(3);p<Z;++p)i[p]=r[$+p]}for(;p<q;++p)i[p]=i[p-L]}}e.l=d,e.p=O,e.b=p,e.f=h,d&&(h=1,e.m=m,e.d=f,e.n=_)}while(!h);return p!=i.length&&o?Pe(i,0,p):i.subarray(0,p)},Re=function(t,e,i){i<<=7&e;var r=e/8|0;t[r]|=i,t[r+1]|=i>>8},Le=function(t,e,i){i<<=7&e;var r=e/8|0;t[r]|=i,t[r+1]|=i>>8,t[r+2]|=i>>16},Fe=function(t,e){for(var i=[],r=0;r<t.length;++r)t[r]&&i.push({s:r,f:t[r]});var n=i.length,s=i.slice();if(!n)return{t:Ue,l:0};if(1==n){var o=new re(i[0].s+1);return o[i[0].s]=1,{t:o,l:1}}i.sort(function(t,e){return t.f-e.f}),i.push({s:-1,f:25001});var a=i[0],l=i[1],c=0,h=1,u=2;for(i[0]={s:-1,f:a.f+l.f,l:a,r:l};h!=n-1;)a=i[i[c].f<i[u].f?c++:u++],l=i[c!=h&&i[c].f<i[u].f?c++:u++],i[h++]={s:-1,f:a.f+l.f,l:a,r:l};var p=s[0].s;for(r=1;r<n;++r)s[r].s>p&&(p=s[r].s);var d=new ne(p+1),f=Be(i[h-1],d,0);if(f>e){r=0;var m=0,_=f-e,g=1<<_;for(s.sort(function(t,e){return d[e.s]-d[t.s]||t.f-e.f});r<n;++r){var y=s[r].s;if(!(d[y]>e))break;m+=g-(1<<f-d[y]),d[y]=e}for(m>>=_;m>0;){var v=s[r].s;d[v]<e?m-=1<<e-d[v]++-1:++r}for(;r>=0&&m;--r){var x=s[r].s;d[x]==e&&(--d[x],++m)}f=e}return{t:new re(d),l:f}},Be=function(t,e,i){return-1==t.s?Math.max(Be(t.l,e,i+1),Be(t.r,e,i+1)):e[t.s]=i},Oe=function(t){for(var e=t.length;e&&!t[--e];);for(var i=new ne(++e),r=0,n=t[0],s=1,o=function(t){i[r++]=t},a=1;a<=e;++a)if(t[a]==n&&a!=e)++s;else{if(!n&&s>2){for(;s>138;s-=138)o(32754);s>2&&(o(s>10?s-11<<5|28690:s-3<<5|12305),s=0)}else if(s>3){for(o(n),--s;s>6;s-=6)o(8304);s>2&&(o(s-3<<5|8208),s=0)}for(;s--;)o(n);s=1,n=t[a]}return{c:i.subarray(0,r),n:e}},Ne=function(t,e){for(var i=0,r=0;r<e.length;++r)i+=t[r]*e[r];return i},Ve=function(t,e,i){var r=i.length,n=Ie(e+2);t[n]=255&r,t[n+1]=r>>8,t[n+2]=255^t[n],t[n+3]=255^t[n+1];for(var s=0;s<r;++s)t[n+s+4]=i[s];return 8*(n+4+r)},je=function(t,e,i,r,n,s,o,a,l,c,h){Re(e,h++,i),++n[256];for(var u=Fe(n,15),p=u.t,d=u.l,f=Fe(s,15),m=f.t,_=f.l,g=Oe(p),y=g.c,v=g.n,x=Oe(m),b=x.c,w=x.n,S=new ne(19),T=0;T<y.length;++T)++S[31&y[T]];for(T=0;T<b.length;++T)++S[31&b[T]];for(var C=Fe(S,7),M=C.t,A=C.l,E=19;E>4&&!M[le[E-1]];--E);var I,P,D,k,z=c+5<<3,R=Ne(n,xe)+Ne(s,be)+o,L=Ne(n,p)+Ne(s,m)+o+14+3*E+Ne(S,M)+2*S[16]+3*S[17]+7*S[18];if(l>=0&&z<=R&&z<=L)return Ve(e,h,t.subarray(l,l+c));if(Re(e,h,1+(L<R)),h+=2,L<R){I=ve(p,d,0),P=p,D=ve(m,_,0),k=m;var F=ve(M,A,0);Re(e,h,v-257),Re(e,h+5,w-1),Re(e,h+10,E-4),h+=14;for(T=0;T<E;++T)Re(e,h+3*T,M[le[T]]);h+=3*E;for(var B=[y,b],O=0;O<2;++O){var N=B[O];for(T=0;T<N.length;++T){var V=31&N[T];Re(e,h,F[V]),h+=M[V],V>15&&(Re(e,h,N[T]>>5&127),h+=N[T]>>12)}}}else I=we,P=xe,D=Te,k=be;for(T=0;T<a;++T){var j=r[T];if(j>255){Le(e,h,I[(V=j>>18&31)+257]),h+=P[V+257],V>7&&(Re(e,h,j>>23&31),h+=oe[V]);var G=31&j;Le(e,h,D[G]),h+=k[G],G>3&&(Le(e,h,j>>5&8191),h+=ae[G])}else Le(e,h,I[j]),h+=P[j]}return Le(e,h,I[256]),h+P[256]},Ge=new se([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),Ue=new re(0),qe=function(){for(var t=new Int32Array(256),e=0;e<256;++e){for(var i=e,r=9;--r;)i=(1&i&&-306674912)^i>>>1;t[e]=i}return t}(),$e=function(){var t=-1;return{p:function(e){for(var i=t,r=0;r<e.length;++r)i=qe[255&i^e[r]]^i>>>8;t=i},d:function(){return~t}}},Ze=function(t,e,i,r,n){if(!n&&(n={l:1},e.dictionary)){var s=e.dictionary.subarray(-32768),o=new re(s.length+t.length);o.set(s),o.set(t,s.length),t=o,n.w=s.length}return function(t,e,i,r,n,s){var o=s.z||t.length,a=new re(r+o+5*(1+Math.ceil(o/7e3))+n),l=a.subarray(r,a.length-n),c=s.l,h=7&(s.r||0);if(e){h&&(l[0]=s.r>>3);for(var u=Ge[e-1],p=u>>13,d=8191&u,f=(1<<i)-1,m=s.p||new ne(32768),_=s.h||new ne(f+1),g=Math.ceil(i/3),y=2*g,v=function(e){return(t[e]^t[e+1]<<g^t[e+2]<<y)&f},x=new se(25e3),b=new ne(288),w=new ne(32),S=0,T=0,C=s.i||0,M=0,A=s.w||0,E=0;C+2<o;++C){var I=v(C),P=32767&C,D=_[I];if(m[P]=D,_[I]=P,A<=C){var k=o-C;if((S>7e3||M>24576)&&(k>423||!c)){h=je(t,l,0,x,b,w,T,M,E,C-E,h),M=S=T=0,E=C;for(var z=0;z<286;++z)b[z]=0;for(z=0;z<30;++z)w[z]=0}var R=2,L=0,F=d,B=P-D&32767;if(k>2&&I==v(C-B))for(var O=Math.min(p,k)-1,N=Math.min(32767,C),V=Math.min(258,k);B<=N&&--F&&P!=D;){if(t[C+R]==t[C+R-B]){for(var j=0;j<V&&t[C+j]==t[C+j-B];++j);if(j>R){if(R=j,L=B,j>O)break;var G=Math.min(B,j-2),U=0;for(z=0;z<G;++z){var q=C-B+z&32767,$=q-m[q]&32767;$>U&&(U=$,D=q)}}}B+=(P=D)-(D=m[P])&32767}if(L){x[M++]=268435456|pe[R]<<18|me[L];var Z=31&pe[R],W=31&me[L];T+=oe[Z]+ae[W],++b[257+Z],++w[W],A=C+R,++S}else x[M++]=t[C],++b[t[C]]}}for(C=Math.max(C,A);C<o;++C)x[M++]=t[C],++b[t[C]];h=je(t,l,c,x,b,w,T,M,E,C-E,h),c||(s.r=7&h|l[h/8|0]<<3,h-=7,s.h=_,s.p=m,s.i=C,s.w=A)}else{for(C=s.w||0;C<o+c;C+=65535){var H=C+65535;H>=o&&(l[h/8|0]=c,H=o),h=Ve(l,h+1,t.subarray(C,H))}s.i=o}return Pe(a,0,r+Ie(h)+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,r,n)},We=function(t,e){var i={};for(var r in t)i[r]=t[r];for(var r in e)i[r]=e[r];return i},He=function(t,e,i){for(var r=t(),n=t.toString(),s=n.slice(n.indexOf("[")+1,n.lastIndexOf("]")).replace(/\s+/g,"").split(","),o=0;o<r.length;++o){var a=r[o],l=s[o];if("function"==typeof a){e+=";"+l+"=";var c=a.toString();if(a.prototype)if(-1!=c.indexOf("[native code]")){var h=c.indexOf(" ",8)+1;e+=c.slice(h,c.indexOf("(",h))}else for(var u in e+=c,a.prototype)e+=";"+l+".prototype."+u+"="+a.prototype[u].toString();else e+=c}else i[l]=a}return e},Xe=[],Ye=function(t,e,i,r){if(!Xe[i]){for(var n="",s={},o=t.length-1,a=0;a<o;++a)n=He(t[a],n,s);Xe[i]={c:He(t[o],n,s),e:s}}var l=We({},Xe[i].e);return function(t,e,i,r,n){var s=new Worker(ie[e]||(ie[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,i=e.$e$;if(i){var r=new Error(i[0]);r.code=i[1],r.stack=i[2],n(r,null)}else n(null,e)},s.postMessage(i,r),s}(Xe[i].c+";onmessage=function(e){for(var k in e.data)self[k]=e.data[k];onmessage="+e.toString()+"}",i,l,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}(l),r)},Ke=function(){return[re,ne,se,oe,ae,le,ue,fe,Se,Ce,_e,De,ve,Me,Ae,Ee,Ie,Pe,ke,ze,oi,Je,Qe]},Je=function(t){return postMessage(t,[t.buffer])},Qe=function(t){return t&&{out:t.size&&new re(t.size),dictionary:t.dictionary}},ti=function(t,e){return t[e]|t[e+1]<<8},ei=function(t,e){return(t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24)>>>0},ii=function(t,e){return ei(t,e)+4294967296*ei(t,e+4)},ri=function(t,e,i){for(;i;++e)t[e]=i,i>>>=8};function ni(t,e){return Ze(t,e||{},0,0)}function si(t,e,i){return i||(i=e,e={}),"function"!=typeof i&&ke(7),function(t,e,i,r,n,s){var o=Ye(i,r,n,function(t,e){o.terminate(),s(t,e)});return o.postMessage([t,e],e.consume?[t.buffer]:[]),function(){o.terminate()}}(t,e,[Ke],function(t){return Je(oi(t.data[0],Qe(t.data[1])))},1,i)}function oi(t,e){return ze(t,{i:2},e&&e.out,e&&e.dictionary)}var ai=function(t,e,i,r){for(var n in t){var s=t[n],o=e+n,a=r;Array.isArray(s)&&(a=We(r,s[1]),s=s[0]),s instanceof re?i[o]=[s,a]:(i[o+="/"]=[new re(0),a],ai(s,o,i,r))}},li="undefined"!=typeof TextEncoder&&new TextEncoder,ci="undefined"!=typeof TextDecoder&&new TextDecoder;try{ci.decode(Ue,{stream:!0})}catch(t){}function hi(t,e){if(li)return li.encode(t);for(var i=t.length,r=new re(t.length+(t.length>>1)),n=0,s=function(t){r[n++]=t},o=0;o<i;++o){if(n+5>r.length){var a=new re(n+8+(i-o<<1));a.set(r),r=a}var l=t.charCodeAt(o);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(++o))>>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 Pe(r,0,n)}function ui(t,e){if(e){for(var i="",r=0;r<t.length;r+=16384)i+=String.fromCharCode.apply(null,t.subarray(r,r+16384));return i}if(ci)return ci.decode(t);var n=function(t){for(var e="",i=0;;){var r=t[i++],n=(r>127)+(r>223)+(r>239);if(i+n>t.length)return{s:e,r:Pe(t,i-1)};n?3==n?(r=((15&r)<<18|(63&t[i++])<<12|(63&t[i++])<<6|63&t[i++])-65536,e+=String.fromCharCode(55296|r>>10,56320|1023&r)):e+=1&n?String.fromCharCode((31&r)<<6|63&t[i++]):String.fromCharCode((15&r)<<12|(63&t[i++])<<6|63&t[i++]):e+=String.fromCharCode(r)}}(t),s=n.s;return(i=n.r).length&&ke(8),s}var pi=function(t,e){for(;1!=ti(t,e);e+=4+ti(t,e+2));return[ii(t,e+12),ii(t,e+4),ii(t,e+20)]},di=function(t){var e=0;if(t)for(var i in t){var r=t[i].length;r>65535&&ke(9),e+=r+4}return e},fi=function(t,e,i,r,n,s,o,a){var l=r.length,c=i.extra,h=a&&a.length,u=di(c);ri(t,e,null!=o?33639248:67324752),e+=4,null!=o&&(t[e++]=20,t[e++]=i.os),t[e]=20,e+=2,t[e++]=i.flag<<1|(s<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),d=p.getFullYear()-1980;if((d<0||d>119)&&ke(10),ri(t,e,d<<25|p.getMonth()+1<<21|p.getDate()<<16|p.getHours()<<11|p.getMinutes()<<5|p.getSeconds()>>1),e+=4,-1!=s&&(ri(t,e,i.crc),ri(t,e+4,s<0?-s-2:s),ri(t,e+8,i.size)),ri(t,e+12,l),ri(t,e+14,u),e+=16,null!=o&&(ri(t,e,h),ri(t,e+6,i.attrs),ri(t,e+10,o),e+=14),t.set(r,e),e+=l,u)for(var f in c){var m=c[f],_=m.length;ri(t,e,+f),ri(t,e+2,_),t.set(m,e+4),e+=4+_}return h&&(t.set(a,e),e+=h),e};function mi(t,e){e||(e={});var i={},r=[];ai(t,"",i,e);var n=0,s=0;for(var o in i){var a=i[o],l=a[0],c=a[1],h=0==c.level?0:8,u=(S=hi(o)).length,p=c.comment,d=p&&hi(p),f=d&&d.length,m=di(c.extra);u>65535&&ke(11);var _=h?ni(l,c):l,g=_.length,y=$e();y.p(l),r.push(We(c,{size:l.length,crc:y.d(),c:_,f:S,m:d,u:u!=o.length||d&&p.length!=f,o:n,compression:h})),n+=30+u+m+g,s+=76+2*(u+m)+(f||0)+g}for(var v=new re(s+22),x=n,b=s-n,w=0;w<r.length;++w){var S=r[w];fi(v,S.o,S,S.f,S.u,S.c.length);var T=30+S.f.length+di(S.extra);v.set(S.c,S.o+T),fi(v,n,S,S.f,S.u,S.c.length,S.o,S.m),n+=16+T+(S.m?S.m.length:0)}return function(t,e,i,r,n){ri(t,e,101010256),ri(t,e+8,i),ri(t,e+10,i),ri(t,e+12,r),ri(t,e+16,n)}(v,n,r.length,b,x),v}var _i="function"==typeof queueMicrotask?queueMicrotask:"function"==typeof setTimeout?setTimeout:function(t){t()};function gi(t,e,i){i||(i=e,e={}),"function"!=typeof i&&ke(7);var r=[],n=function(){for(var t=0;t<r.length;++t)r[t]()},s={},o=function(t,e){_i(function(){i(t,e)})};_i(function(){o=i});for(var a=t.length-22;101010256!=ei(t,a);--a)if(!a||t.length-a>65558)return o(ke(13,0,1),null),n;var l=ti(t,a+8);if(l){var c=l,h=ei(t,a+16),u=4294967295==h||65535==c;if(u){var p=ei(t,a-12);(u=101075792==ei(t,p))&&(c=l=ei(t,p+32),h=ei(t,p+48))}for(var d=e&&e.filter,f=function(e){var i=function(t,e,i){var r=ti(t,e+28),n=ui(t.subarray(e+46,e+46+r),!(2048&ti(t,e+8))),s=e+46+r,o=ei(t,e+20),a=i&&4294967295==o?pi(t,s):[o,ei(t,e+24),ei(t,e+42)],l=a[0],c=a[1],h=a[2];return[ti(t,e+10),l,c,n,s+ti(t,e+30)+ti(t,e+32),h]}(t,h,u),a=i[0],c=i[1],p=i[2],f=i[3],m=i[4],_=i[5],g=function(t,e){return e+30+ti(t,e+26)+ti(t,e+28)}(t,_);h=m;var y=function(t,e){t?(n(),o(t,null)):(e&&(s[f]=e),--l||o(null,s))};if(!d||d({name:f,size:c,originalSize:p,compression:a}))if(a)if(8==a){var v=t.subarray(g,g+c);if(p<524288||c>.8*p)try{y(null,oi(v,{out:new re(p)}))}catch(t){y(t,null)}else r.push(si(v,{size:p},y))}else y(ke(14,"unknown compression type "+a,1),null);else y(null,Pe(t,g,g+c));else y(null,null)},m=0;m<c;++m)f()}else o(null,{});return n}const yi=5e5;class vi{_unfilteredArcs;_filteredArcs=null;_filteredSegLen=0;_dirty=!1;constructor(t){this._unfilteredArcs=t;(t.getPointCount?.()??0)>yi&&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)/yi),r=t.getRetainedInterval?.()??0,n=t.getThresholdByPct?.(e,i)??0;this._filteredArcs=t.setRetainedInterval?.(n)?.getFilteredCopy?.()??null,t.setRetainedInterval?.(r),this._filteredArcs&&(this._filteredSegLen=Q().getAvgSegment(this._filteredArcs))}else{const e=Q();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)>yi&&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 xi{_adapter;constructor(t=Q()){this._adapter=t}async runImport(t,e){return this._adapter.runImport(t,e)}}let bi=null;const wi="EPSG:4326";function Si(t){if(!t)return wi;const e=t.info;if(!e)return wi;if(e.crs_string)return Ti(e.crs_string);if(e.prj){const t=Ci(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 wi}function Ti(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 Ci(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 Mi={geojson:"application/geo+json",topojson:"application/json",shapefile:"application/zip",msx:"application/octet-stream"};function Ai(t){return"string"==typeof t?(new TextEncoder).encode(t):t instanceof Uint8Array?t:new Uint8Array(t)}const Ei={maxBytes:209715200,maxEntries:5e3,maxRatio:100};class Ii extends q{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??bi??(bi=new xi),this._data&&this._updateData()}static async fromUrl(t,e,i){const r=new Ii(t,i);return await r.setData(e),r}static async fromBytes(t,e,i){const{filename:r=`${t}.geojson`,...n}=i??{},s=e instanceof Uint8Array?e:new Uint8Array(e),o=new Ii(t,n);return await o.setData({filename:r,content:s}),o}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={},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),n=this._findPrimaryFile(e);if(!n)throw new Error(`No importable file found in zip archive: ${t.filename}`);for(const[t,r]of Object.entries(e))i[t]=r;r.push(n)}else i[t.filename]=t.content,r.push(t.filename)}else{let t;if("string"==typeof this._data){const i=this._data,r=await fetch(i,{signal:e.signal});if(!r.ok)throw new Error(`Failed to fetch ${i}: HTTP ${r.status}`);const n=await r.arrayBuffer(),s=new Uint8Array(n);let o=new URL(i).pathname.split("/").pop()||"";if(!this._hasSupportedExtension(o)){const t=r.headers.get("Content-Type")||"";o=this._filenameFromContentType(t,o)}o||(o="data.json"),t={filename:o,content:s}}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,r]of Object.entries(e))i[t]=r;r.push(n)}else i[t.filename]=t.content,r.push(t.filename)}const n=`-i ${r.map(t=>`"${t.replace(/"/g,'\\"')}"`).join(" ")}`,s=await this._runner.runImport(n,i);if(t!==this._loadVersion)return;this._dataset=s,this._dataset?.arcs&&(this._displayArcs=new vi(this._dataset.arcs)),this._simplifyFloor=this._dataset?.arcs?.getRetainedInterval?.()??0,this.fire("data",{reason:"load"}),this._settlePending(t,null)}catch(e){if(t!==this._loadVersion)return;if("AbortError"===e?.name)return;this.fire("error",{error:e}),this._settlePending(t,e??new Error("setData import failed"))}}_settlePending(t,e){if(this._pending?.version!==t)return;const i=this._pending;this._pending=null,null===e?i.resolve(this):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 Si(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 Q().runOnDataset(e,this._dataset);this._dataset=i,this._dataset?.arcs&&(this._displayArcs=new vi(this._dataset.arcs))}getExtent(){if(!this._dataset)return new Z;const t=Q().getDatasetBounds(this._dataset);return new Z(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 vi(this._dataset.arcs))}setDataset(t){this._dataset=t,t.arcs?this._displayArcs=new vi(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=Q(),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]=Ai(i.content);const i=mi(e);return new Blob([i],{type:Mi.shapefile})}return new Blob([t[0].content],{type:Mi[e]})}getLayers(){return this._dataset?.layers||[]}_isZipFile(t){return/\.zip$/i.test(t)}async _extractZip(t){const e={...Ei,...this._options.zipLimits};let i=0,r=0;const n=await new Promise((n,s)=>{gi(t,{filter:n=>{if(r++,r>e.maxEntries)throw new Error(`ZIP extraction limit exceeded: ${r} 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 r=i/t.byteLength;if(r>e.maxRatio)throw new Error(`ZIP extraction limit exceeded: ratio ${r.toFixed(1)} > maxRatio ${e.maxRatio}`)}return!(/^__MACOSX/.test(n.name)||n.name.split("/").pop()?.startsWith("."))}},(t,e)=>{t?s(t):n(e)})}),s={};for(const t of Object.keys(n)){const e=n[t],i=t.split("/").pop()||t;this._isTextFile(i)?s[i]=ui(e):s[i]=e}return s}_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 Pi(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 Di extends q{_element;_active=!1;_timer=new W;_sustainInterval=150;_fadeDelay=70;_eventTime=0;_getAverageRate=Pi(10);_getWheelDirection=function(){let t=0,e=null;return function(i,r){const n=i>0?1:i<0?-1:0;(!e||r-t>300)&&(e=Pi(3)),t=r;const s=e(n)||n;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 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,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&&(i*=H.quadraticOut(1-r)),this.fire("mousewheel",{direction:this._wheelDirection,multiplier:i,x:this._mouseX,y:this._mouseY}))}}class ki extends q{_element;_isDragging=!1;_lastMousePos=[0,0];_enabled=!0;_onMouseDownBound;_onMouseMoveBound;_onMouseUpBound;constructor(t){super(),this._element=t,this._onMouseDownBound=this._onMouseDown.bind(this),this._onMouseMoveBound=this._onMouseMove.bind(this),this._onMouseUpBound=this._onMouseUp.bind(this),t.addEventListener("mousedown",this._onMouseDownBound),window.addEventListener("mousemove",this._onMouseMoveBound),window.addEventListener("mouseup",this._onMouseUpBound)}setEnabled(t){this._enabled=t,!t&&this._isDragging&&(this._isDragging=!1,this.fire("panend"))}isEnabled(){return this._enabled}isDragging(){return this._isDragging}destroy(){this._element.removeEventListener("mousedown",this._onMouseDownBound),window.removeEventListener("mousemove",this._onMouseMoveBound),window.removeEventListener("mouseup",this._onMouseUpBound)}_onMouseDown(t){this._enabled&&(t.shiftKey||(this._isDragging=!0,this._lastMousePos=[t.clientX,t.clientY],this.fire("panstart")))}_onMouseMove(t){if(!this._isDragging)return;const e=t.clientX-this._lastMousePos[0],i=t.clientY-this._lastMousePos[1];this._lastMousePos=[t.clientX,t.clientY],this.fire("pan",{dx:e,dy:i})}_onMouseUp(){this._isDragging&&(this._isDragging=!1,this.fire("panend"))}}class zi{_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 r=this.reserveId();return{id:r,promise:this.dispatchWithId(r,t,e,i)}}reserveId(){return this._nextId++}dispatchWithId(t,e,i,r,n){if(this._destroyed)return Promise.reject(new Error("MapshaperWorkerPool: destroyed"));const s=this._pickWorker();let o;try{o=this._ensureWorker(s)}catch(t){return Promise.reject(t)}const a=this._slots[s],l=a.epoch;return a.pendingCount++,new Promise((a,c)=>{this._pending.set(t,{resolve:a,reject:c,workerIndex:s,epoch:l});const h={id:t,type:"run",packed:i};"string"==typeof e?h.cmd=e:h.commands=e,r&&(h.inputFiles=r),n&&n.length>0?o.postMessage(h,n):o.postMessage(h)})}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 r=this._slots.length;for(let n=0;n<r;n++){const s=(this._rrCursor+n)%r,o=this._slots[s],a=null!==o.worker;(o.pendingCount<e||o.pendingCount===e&&a&&!i)&&(t=s,e=o.pendingCount,i=a)}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 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 r=this._slots[t];i.workerIndex===t&&i.epoch===r.epoch&&(this._pending.delete(e.id),r.pendingCount=Math.max(0,r.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"}`),r=this._slots[t];r.worker&&(r.worker.terminate(),r.worker=null),r.epoch++,r.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)}}}class Ri{_sources;_getTransform;_getSize;_getInitialMX;_indexCache=new globalThis.Map;constructor(t,e,i,r){this._sources=t,this._getTransform=e,this._getSize=i,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}|`,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(),r=e.getArcs(),n=e.getDataset?.();for(let e=0;e<i.length;e++)this._getOrBuildIndex(t,e,i[e],r,n)}_getOrBuildIndex(t,e,i,r,n){const s=i?.shapes;if(!s||0===s.length)return null;const o=r?.size?.()??0,a=n?.editVersion??0,l=`${t}|${e}|${s.length}|${o}|${a}`,c=this._indexCache.get(l);if(void 0!==c)return c;const h=`${t}|${e}|`,u=[];for(const t of this._indexCache.keys())t!==l&&t.startsWith(h)&&u.push(t);for(const t of u)this._indexCache.delete(t);const p="point"===i.geometry_type,d=new A(s.length),f=[];for(let t=0;t<s.length;t++){const e=s[t];if(!e){d.add(0,0,0,0);continue}let i=1/0,n=1/0,o=-1/0,a=-1/0;if(p)for(const t of rt(e))!t||t.length<2||(t[0]<i&&(i=t[0]),t[0]>o&&(o=t[0]),t[1]<n&&(n=t[1]),t[1]>a&&(a=t[1]));else if(r?.getSimpleShapeBbox){const t=e;for(let e=0;e<t.length;e++)r.getSimpleShapeBbox(t[e],f),f[0]<i&&(i=f[0]),f[1]<n&&(n=f[1]),f[2]>o&&(o=f[2]),f[3]>a&&(a=f[3])}i!==1/0?d.add(i,n,o,a):d.add(0,0,0,0)}d.finish();const m={index:d,shapeCount:s.length};return this._indexCache.set(l,m),m}query(t,e,i){const{width:r,height:n}=this._getSize(),s=Array.isArray(t),o=s?t:[[0,0],[r,n]],a=e||(s?{}:t)||{};if(Array.isArray(o)&&"number"==typeof o[0]){const t=o;return this._queryFeaturesAtPoint(t,a,i)}const l=o;return this._queryFeaturesInBBox(l,a,i)}_layerMatchesFilter(t,e,i){if(!i||0===i.length)return!0;const r=it(t,e);return!!i.includes(r)||(!(!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(),r=this._getInitialMX(),n=Math.abs(i.mx)/(r||Math.abs(i.mx)||1);return n<1&&(t*=n),e>0&&t<e&&(t=e),this._getHitBuffer(t)}_findHitCandidates(t,e,i,r,n,s,o,a){const l=[],c={},h=[],u=i.shapes;if(!u)return l;const p=this._getOrBuildIndex(t,e,i,r,a),d=p?p.index.search(n-o,s-o,n+o,s+o):null,f=null!==d?d.length:u.length;for(let t=0;t<f;t++){const e=null!==d?d[t]:t,i=u[e];if(i)for(let t=0;t<i.length;t++){const a=i[t];if(r.getSimpleShapeBbox(a,h),n+o<h[0]||n-o>h[2]||s+o<h[1]||s-o>h[3])continue;let u=c[e];u||(u=c[e]={shape:[],id:e,dist:0},l.push(u)),u.shape.push(a)}}return l}_sortByDistance(t,i,r,n){const s=e.geom;for(const e of r)e.info=s.getPointToShapeInfo(t,i,e.shape,n),e.dist=e.info.distance;r.sort((t,e)=>t.dist-e.dist)}_pickNearestCandidates(t,e,i){const r=[];let n=0;for(let s=0;s<t.length;s++){const o=t[s];if(!(o.dist<i))break;if(0===s)n=o.dist;else if(o.dist-n>e)break;r.push(o)}return r}_pointTest(t,i,r,n,s,o){const a=e.geom,l=Math.abs(this._getTransform().mx||1);let c=-1,h=1/0,u=25;const p=r.shapes;if(!p)return[];const d=u/(l||1),f=this._getOrBuildIndex(t,i,r,void 0,o),m=f?f.index.search(n-d,s-d,n+d,s+d):null,_=null!==m?m.length:p.length;for(let t=0;t<_;t++){const e=null!==m?m[t]:t,i=p[e];if(i)for(const t of rt(i)){if(!t)continue;const i=a.distance2D(n,s,t[0],t[1])*l;i>u||(i<u&&u>2&&(u=Math.max(2,i)),i<h&&(h=i,c=e))}}return-1===c?[]:[c]}_polylineTest(t,e,i,r,n,s,o,a){const l=this._getZoomAdjustedHitBuffer(15,2),c=o>=0?o:.05,h=this._getZoomAdjustedHitBuffer(c,0);let u=this._findHitCandidates(t,e,i,r,n,s,l,a);return this._sortByDistance(n,s,u,r),u=this._pickNearestCandidates(u,h,l),u.length?[u[0].id]:[]}_polygonTest(t,i,r,n,s,o,a){const l=e.geom,c=this._getZoomAdjustedHitBuffer(10,1),h=this._findHitCandidates(t,i,r,n,s,o,c,a);let u=[];for(const t of h)l.testPointInPolygon(s,o,t.shape,n)&&u.push(t);return h.length>0&&0===u.length?(this._sortByDistance(s,o,h,n),u=this._pickNearestCandidates(h,0,c)):u.length>1&&this._sortByDistance(s,o,u,n),u.length?[u[0].id]:[]}_polygonVertexTest(t,e,i,r,n,s,o){const a=this._polygonTest(t,e,i,r,n,s,o),l=this._polylineTest(t,e,i,r,n,s,5,o);return a.length?a:l}_queryFeaturesAtPoint(t,e,i){const r=this._getTransform(),n=[],[s,o]=this._unproject(t[0],t[1]),a=1/Math.abs(r.mx||1);for(const[t,r]of this._sources){const l=r.getLayers(),c=r.getDisplayArcs(),h=c?c.getScaledArcs(a):r.getArcs(),u=r.getDataset?.();for(let r=0;r<l.length;r++){const a=l[r];if(!a?.shapes)continue;if(!this._layerMatchesFilter(a,r,e.layers))continue;const c=it(a,r);if(i&&!i.has(`${t}:${c}`))continue;const p=a.geometry_type;let d=[];if("point"===p?d=this._pointTest(t,r,a,s,o,u):"polyline"===p&&h?d=this._polylineTest(t,r,a,h,s,o,-1,u):"polygon"===p&&h&&(d=this._polygonVertexTest(t,r,a,h,s,o,u)),0!==d.length)for(const e of d){const i=a.data,r=i?.getRecordAt?.(e)??i?.getRecords?.()?.[e]??{};n.push({id:e,source:t,layer:c,geometryType:p||"unknown",properties:{...r}})}}}return n}_queryFeaturesInBBox(t,e,i){const r=this._getTransform(),n=[],[s,o]=t,a=this._unproject(s[0],s[1]),l=this._unproject(o[0],o[1]),c=Math.min(a[0],l[0]),h=Math.min(a[1],l[1]),u=Math.max(a[0],l[0]),p=Math.max(a[1],l[1]),d=1/Math.abs(r.mx||1);for(const[t,r]of this._sources){const s=r.getLayers(),o=r.getDisplayArcs(),a=o?o.getScaledArcs(d):r.getArcs(),l=r.getDataset?.();for(let r=0;r<s.length;r++){const o=s[r];if(!o?.shapes)continue;if(!this._layerMatchesFilter(o,r,e.layers))continue;const d=it(o,r);if(i&&!i.has(`${t}:${d}`))continue;const f=o.geometry_type,m=o.data,_=[],g=this._getOrBuildIndex(t,r,o,a,l),y=g?g.index.search(c,h,u,p):null,v=null!==y?y.length:o.shapes.length;for(let e=0;e<v;e++){const i=null!==y?y[e]:e,r=o.shapes[i];if(!r)continue;let s=!1;if("point"===f)s=rt(r).some(t=>t[0]>=c&&t[0]<=u&&t[1]>=h&&t[1]<=p);else if(a){const t=r;for(let e=0;e<t.length;e++)if(a.getSimpleShapeBbox(t[e],_),!(u<_[0]||c>_[2]||p<_[1]||h>_[3])){s=!0;break}}if(!s)continue;const l=m?.getRecordAt?.(i)??m?.getRecords?.()?.[i]??{};n.push({id:i,source:t,layer:d,geometryType:f||"unknown",properties:{...l}})}}}return n}}class Li{_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 r=i[t.id],n=e.data?.getRecords?.()??[];return{ref:t,geometry:r,properties:Object.freeze({...n[t.id]??{}})}}*iter(t,e){const i=this._host.layers.resolve(t,e);if(!i||!i.shapes)return;const r=i.shapes,n=i.data?.getRecords?.()??[];for(let i=0;i<r.length;i++)yield{ref:{source:t,layer:e,id:i},geometry:r[i],properties:Object.freeze({...n[i]??{}})}}count(t,e){const i=this._host.layers.resolve(t,e);return i?.shapes?.length??0}}class Fi{_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 r=[];for(const e of this._all)e.phase===t&&r.push(e);if(0===r.length)return[];const n=await Promise.allSettled(r.map(t=>t.run(e,i))),s=[];for(let t=0;t<r.length;t++){const e=r[t],i=n[t];let o;o="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)}`}]},s.push({validator:e.name,report:o})}return s}}class Bi{_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,r,n){if(0===this._highlighted.size)return;const s=this._highlightStyle.color||"#ff7a00",o=(this._highlightStyle.width??2.2)*r,a=this._highlightStyle.radius??6,l=!1!==this._highlightStyle.fill,c=1/Math.abs(i.mx||1);for(const[i,r]of e){const e=this._highlighted.get(i);if(!e)continue;const h=r.getLayers(),u=r.getDisplayArcs(),p=u?u.getScaledArcs(c):r.getArcs();for(let r=0;r<h.length;r++){const c=h[r];if(!c?.shapes)continue;const u=it(c,r);if(n&&!n.has(`${i}:${u}`))continue;const d=e.get(u);if(!d||0===d.size)continue;const f=[];for(const t of d){const e=c.shapes[t];e&&f.push(e)}0!==f.length&&("point"===c.geometry_type?t.drawPoints(f,{color:s,radius:a,fill:l}):p&&t.drawPaths(f,{color:s,width:o},p))}}}}class Oi{_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[r,n]of i)for(const i of n)t.push({source:e,layer:r,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=Gi(t);if("replace"===e){const t=this._refSetSnapshot();this._byKey.clear(),this._size=0;for(const t of i)this._addOne(t);return ji(t,this._refSetSnapshot())}const r=[],n=[];if("add"===e)for(const t of i)this._addOne(t)&&r.push(t);else for(const t of i)this.has(t)?this._removeOne(t)&&n.push(t):this._addOne(t)&&r.push(t);return{added:r,removed:n,changed:r.length>0||n.length>0}}remove(t){const e=[];for(const i of Gi(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(Vi(e));return ji(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[r,n]of i)for(const i of n)t.add(Ni(e,r,i));return t}}function Ni(t,e,i){return JSON.stringify([t,e,i])}function Vi(t){const[e,i,r]=JSON.parse(t);return{source:e,layer:i,id:r}}function ji(t,e){const i=[],r=[];for(const r of e)t.has(r)||i.push(Vi(r));for(const i of t)e.has(i)||r.push(Vi(i));return{added:i,removed:r,changed:i.length>0||r.length>0}}function Gi(t){const e=new Set,i=[];for(const r of t){const t=Ni(r.source,r.layer,r.id);e.has(t)||(e.add(t),i.push(r))}return i}class Ui{_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 qi{_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 at;const i=new zt(e,t);return this._host._history.push(i),this._host._fireHistoryChange(),at}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 $i{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 r=t.shapes,n=new Array(r.length-i.size);let s=0;for(let t=0;t<r.length;t++)i.has(t)||(n[s++]=r[t]);t.shapes=n;const o=t.data?.getRecords?.();if(o){let t=0;for(let e=0;e<o.length;e++)i.has(e)||(o[t++]=o[e]);o.length=t}}undo(){const{layer:t,snapshots:e}=this.opts;t.shapes||(t.shapes=[]);const i=[...e].sort((t,e)=>t.id-e.id),r=t.data?.getRecords?.();for(const e of i)t.shapes.splice(e.id,0,e.shape),r&&null!==e.record&&r.splice(e.id,0,e.record)}}function Zi(t,e){const i=t||{};return{color:i["line-color"]||i["fill-color"]||"#333",width:(i["line-width"]??.8)*e}}function Wi(t){const e=t||{};return{color:e["circle-color"]||"#333",radius:e["circle-radius"]??4,fill:!1!==e["circle-fill"]}}const Hi=/^[A-Za-z0-9_\-:.一-鿿][A-Za-z0-9_\-:. 一-鿿]*$/,Xi=/^[A-Za-z0-9_\-.一-鿿][A-Za-z0-9_\-. 一-鿿]*$/;function Yi(t){return"string"==typeof t&&t.length>0&&Xi.test(t)}class Ki{opts;label="Move vertex";_mergeAt=Date.now();constructor(t){this.opts=t}do(){(this.opts.adapter??Q()).snapVertices(this.opts.vertexIds,this.opts.to,this.opts.arcs),this.opts.source.markDisplayArcsDirty?.(),Lt(this.opts.source.getDataset?.())}undo(){(this.opts.adapter??Q()).snapVertices(this.opts.vertexIds,this.opts.from,this.opts.arcs),this.opts.source.markDisplayArcsDirty?.(),Lt(this.opts.source.getDataset?.())}mergeable(t){if(!(t instanceof Ki))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 Ki&&(this.opts.to=t.opts.to,this._mergeAt=Date.now())}}class Ji{opts;label="Insert vertex";constructor(t){this.opts=t}do(){(this.opts.adapter??Q()).insertVertex(this.opts.arcs,this.opts.insertionId,this.opts.point),this.opts.source.markDisplayArcsDirty?.(),Lt(this.opts.source.getDataset?.())}undo(){(this.opts.adapter??Q()).deleteVertex(this.opts.arcs,this.opts.insertionId),this.opts.source.markDisplayArcsDirty?.(),Lt(this.opts.source.getDataset?.())}}class Qi{opts;label="Delete vertex";constructor(t){this.opts=t}do(){(this.opts.adapter??Q()).deleteVertex(this.opts.arcs,this.opts.vertexIndex),this.opts.source.markDisplayArcsDirty?.(),Lt(this.opts.source.getDataset?.())}undo(){(this.opts.adapter??Q()).insertVertex(this.opts.arcs,this.opts.vertexIndex,this.opts.coords),this.opts.source.markDisplayArcsDirty?.(),Lt(this.opts.source.getDataset?.())}}class tr{opts;label;constructor(t){this.opts=t,this.label=`Draw ${t.geometryType}`}do(){const t=this.opts,e=t.adapter??Q();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?.(),Lt(t.source.getDataset?.())}undo(){const t=this.opts,e=t.adapter??Q();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?.(),Lt(t.source.getDataset?.())}}const er=[{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 ir{_map=null;_container=null;_btn=null;_active=!1;_polygonFillColor;_hoveredFeature=null;_hoverVertexCoords=null;_hoverVertexIds=[];_hoverType=null;_hoverInsertionId=-1;_dragging=!1;_neighborShapes=[];_dragFromCoords=null;_onMouseMoveBound;_onMouseDownBound;_onMouseUpBound;_onMoveHandlerBound;_onContextMenuBound;constructor(t={}){this._polygonFillColor=void 0!==t.polygonFillColor?t.polygonFillColor:"rgba(0,0,0,0.15)",this._onMouseMoveBound=this._onMouseMove.bind(this),this._onMouseDownBound=this._onMouseDown.bind(this),this._onMouseUpBound=this._onMouseUp.bind(this),this._onMoveHandlerBound=this._onMapMove.bind(this),this._onContextMenuBound=this._onContextMenu.bind(this)}onAdd(t){return 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-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._deactivate(),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._container=null,this._btn=null}_toggle(){this._active?this._deactivate():this._activate()}_activate(){if(!this._map)return;this._active=!0,this._btn?.classList.add("active"),this._map.setEditMode("vertex");const t=this._map.getCanvasContainer();t.classList.add("emap-edit-active"),t.addEventListener("mousemove",this._onMouseMoveBound),t.addEventListener("mousedown",this._onMouseDownBound),t.addEventListener("contextmenu",this._onContextMenuBound),window.addEventListener("mouseup",this._onMouseUpBound),this._map.on("move",this._onMoveHandlerBound)}_deactivate(){if(!this._map)return;this._active=!1,this._btn?.classList.remove("active"),this._map.setEditMode("none"),this._map.clearEditVertexState(),this._hoveredFeature=null,this._hoverVertexCoords=null,this._hoverVertexIds=[],this._hoverType=null,this._hoverInsertionId=-1,this._neighborShapes=[],this._dragging=!1;const t=this._map.getCanvasContainer();t.classList.remove("emap-edit-active"),t.removeEventListener("mousemove",this._onMouseMoveBound),t.removeEventListener("mousedown",this._onMouseDownBound),t.removeEventListener("contextmenu",this._onContextMenuBound),window.removeEventListener("mouseup",this._onMouseUpBound),this._map.off("move",this._onMoveHandlerBound),this._map.render()}_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;Q().vertexIsArcEndpoint(e,i)||this._showContextMenu(t.clientX,t.clientY,()=>{this._deleteHoveredVertex()})}_deleteHoveredVertex(){if(!this._map||!this._hoveredFeature||0===this._hoverVertexIds.length)return;const t=this._hoveredFeature.arcs,e=this._hoverVertexIds[0],i=this._hoveredFeature.source,r=t.getVertex2(e);if(Q().deleteVertex(t,e),this._refreshSourceDisplayArcs(i),this._bumpSourceEditVersion(i),r){const n=this._map.getSource(i);n&&this._map.pushCommand(new Qi({vertexIndex:e,coords:[r[0],r[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);Lt(e?.getDataset?.()??null)}_showContextMenu(t,e,i){document.getElementById("emap-ctx-menu")?.remove();const r=document.createElement("div");r.id="emap-ctx-menu",Object.assign(r.style,{position:"fixed",left:`${t}px`,top:`${e}px`,background:"#fff",border:"1px solid #ccc",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.18)",padding:"4px 0",zIndex:"9999",minWidth:"120px",font:"13px/1.5 system-ui, sans-serif"});const n=document.createElement("div");n.textContent="删除节点",Object.assign(n.style,{padding:"6px 16px",cursor:"pointer",color:"#d32"}),n.addEventListener("mouseenter",()=>{n.style.background="#f5f5f5"}),n.addEventListener("mouseleave",()=>{n.style.background=""}),n.addEventListener("click",t=>{t.stopPropagation(),r.remove(),document.removeEventListener("click",s),i()}),r.appendChild(n),document.body.appendChild(r);const s=()=>{r.remove(),document.removeEventListener("click",s)};setTimeout(()=>document.addEventListener("click",s),0)}_onMouseMove(t){if(!this._map)return;if(this._dragging)return void this._handleDrag(t);const e=this._map.getCanvasContainer().getBoundingClientRect(),i=t.clientX-e.left,r=t.clientY-e.top,n=this._map.queryFeatures([i,r]);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 s=n[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 o=this._map.getSource(s.source);if(!o)return;const a=o.getLayers(),l=o.getArcs();if(!l)return;let c=null;for(const t of a)if(t.shapes&&t.shapes[s.id]){c=t.shapes[s.id];break}c&&(this._hoveredFeature={source:s.source,layer:s.layer,id:s.id,shape:c,arcs:l,geometryType:s.geometryType,allLayers:a},this._findNearestVertices(c,l,i,r),this._hoverVertexCoords||this._findInterpolatedPoint(c,l,i,r),this._findNeighborShapes(l),this._updateEditState(),this._map.render())}_findNearestVertices(t,e,i,r){if(!this._map)return;const n=this._map.unproject(i,r),s=Q().findNearestVertices(n,t,e);if(!s||0===s.length)return this._hoverVertexCoords=null,void(this._hoverVertexIds=[]);const o=e.getVertex2(s[0]);if(!o)return this._hoverVertexCoords=null,void(this._hoverVertexIds=[]);const a=this._map.project(o[0],o[1]);Math.sqrt((a[0]-i)*(a[0]-i)+(a[1]-r)*(a[1]-r))<=10?(this._hoverVertexCoords=[o[0],o[1]],this._hoverVertexIds=s,this._hoverType="vertex",this._hoverInsertionId=-1):(this._hoverVertexCoords=null,this._hoverVertexIds=[],this._hoverType=null,this._hoverInsertionId=-1)}_findInterpolatedPoint(t,e,i,r){if(!this._map)return;const n=this._map.unproject(i,r);let s=1/0,o=null;const a=Q();if(a.forEachSegmentInShape(t,e,(t,e,i,r)=>{const l=i[t],c=r[t],h=i[e],u=r[e],p=a.findClosestPointOnSeg(n[0],n[1],l,c,h,u,0),d=p[0]-n[0],f=p[1]-n[1],m=Math.sqrt(d*d+f*f);m<s&&(s=m,o={insertionId:(t<e?t:e)+1,point:[p[0],p[1]]})}),!o)return;const l=o,c=this._map.project(l.point[0],l.point[1]);Math.sqrt((c[0]-i)*(c[0]-i)+(c[1]-r)*(c[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(),i=this._hoveredFeature.id,r=new Set;if(this._hoverVertexIds.length>0)for(const t of this._hoverVertexIds)r.add(Q().findArcIdFromVertexId(t,e));else"interpolated"===this._hoverType&&this._hoverInsertionId>0&&r.add(Q().findArcIdFromVertexId(this._hoverInsertionId-1,e));if(0===r.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 s=t.shapes[e];if(!s)continue;let o=!1;for(const t of s){for(const e of t){const t=e>=0?e:~e;if(r.has(t)){o=!0;break}}if(o)break}o&&n.push(s)}this._neighborShapes=n}_updateEditState(){if(!this._map||!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){if(this._hoverVertexCoords&&this._hoveredFeature){if(t.preventDefault(),t.stopPropagation(),"interpolated"===this._hoverType&&this._hoverInsertionId>=0){const t=this._hoveredFeature.arcs,e=[this._hoverVertexCoords[0],this._hoverVertexCoords[1]];Q().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._map||!this._hoveredFeature)return;const i=this._map.getSource(this._hoveredFeature.source);i&&this._map.pushCommand(new Ji({insertionId:t,point:e,arcs:this._hoveredFeature.arcs,source:i}))}_handleDrag(t){if(!this._map||!this._hoveredFeature||0===this._hoverVertexIds.length)return;const e=this._map.getCanvasContainer().getBoundingClientRect(),i=t.clientX-e.left,r=t.clientY-e.top,n=this._map.unproject(i,r),s=this._hoveredFeature.arcs;Q().snapVertices(this._hoverVertexIds,[n[0],n[1]],s),this._hoverVertexCoords=[n[0],n[1]],this._updateEditState(),this._map.render()}_onMouseUp(t){if(!this._dragging||!this._map||!this._hoveredFeature)return;this._dragging=!1;const e=this._map.getCanvasContainer().getBoundingClientRect(),i=t.clientX-e.left,r=t.clientY-e.top,n=this._map.unproject(i,r),s=this._hoveredFeature.source,o=this._hoveredFeature.arcs;o.transformPoints&&o.transformPoints(function(){}),this._refreshSourceDisplayArcs(s),this._bumpSourceEditVersion(s);const a=this._dragFromCoords;if(a&&(a[0]!==n[0]||a[1]!==n[1])&&this._hoverVertexIds.length>0){const t=this._map.getSource(s);t&&this._map.pushCommand(new Ki({vertexIds:[...this._hoverVertexIds],from:[a[0],a[1]],to:[n[0],n[1]],arcs:o,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:n}),this._map.render()}}const rr={polygon:"▢",polyline:"╱",point:"●"},nr={polygon:"Draw Polygon",polyline:"Draw Polyline",point:"Draw Point"};class sr{_options;_map=null;_container=null;_btn=null;_active=!1;_vertices=[];_cursorCoord=null;_snapCoord=null;_snapKind=null;_snapThreshold;_onMouseMoveBound;_onClickBound;_onDblClickBound;_onKeyDownBound;_onMoveHandlerBound;constructor(t){this._options=t,this._snapThreshold=t.snapThreshold??10,this._onMouseMoveBound=this._onMouseMove.bind(this),this._onClickBound=this._onClick.bind(this),this._onDblClickBound=this._onDblClick.bind(this),this._onKeyDownBound=this._onKeyDown.bind(this),this._onMoveHandlerBound=this._onMapMove.bind(this)}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=nr[this._options.type];const e=document.createElement("span");e.className="emap-ctrl-icon";const i=this._options.icon??rr[this._options.type];return"string"==typeof i?e.textContent=i:e.appendChild(i),this._btn.replaceChildren(e),this._btn.addEventListener("click",()=>this._toggle()),this._container.appendChild(this._btn),t.on("editmodechange",t=>{this._active&&"draw"!==t.mode&&this._deactivateQuiet()}),this._container}onRemove(){this._deactivate(),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._container=null,this._btn=null}_toggle(){this._active?this._deactivate():this._activate()}_activate(){if(!this._map)return;this._active=!0,this._btn?.classList.add("active"),this._map.setEditMode("draw");const t=this._map.getCanvasContainer();t.classList.add("emap-draw-active"),t.addEventListener("mousemove",this._onMouseMoveBound),t.addEventListener("click",this._onClickBound),t.addEventListener("dblclick",this._onDblClickBound),window.addEventListener("keydown",this._onKeyDownBound),this._map.on("move",this._onMoveHandlerBound)}_deactivate(){this._clearDrawState(),this._deactivateQuiet(),this._map?.setEditMode("none")}_deactivateQuiet(){if(!this._map)return;this._active=!1,this._btn?.classList.remove("active");const t=this._map.getCanvasContainer();t.classList.remove("emap-draw-active"),t.removeEventListener("mousemove",this._onMouseMoveBound),t.removeEventListener("click",this._onClickBound),t.removeEventListener("dblclick",this._onDblClickBound),window.removeEventListener("keydown",this._onKeyDownBound),this._map.off("move",this._onMoveHandlerBound),this._map.clearEditDrawState(),this._map.render()}_clearDrawState(){this._vertices=[],this._cursorCoord=null,this._snapCoord=null,this._snapKind=null}_onMapMove(){this._vertices.length>0&&(this._updateDrawState(),this._map?.render())}_onMouseMove(t){if(!this._map)return;const e=this._map.getCanvasContainer().getBoundingClientRect(),i=t.clientX-e.left,r=t.clientY-e.top,n=this._map.unproject(i,r);this._cursorCoord=[n[0],n[1]];const s=this._findSnapTarget(i,r);this._snapCoord=s?.coord??null,this._snapKind=s?.kind??null,(this._vertices.length>0||this._snapCoord)&&(this._updateDrawState(),this._map.render())}_onClick(t){if(!this._map)return;const e=this._map.getCanvasContainer().getBoundingClientRect(),i=t.clientX-e.left,r=t.clientY-e.top,n=this._snapCoord?[this._snapCoord[0],this._snapCoord[1]]:this._map.unproject(i,r);if("point"===this._options.type)return this._vertices=[n],void this._commitFeature();if("polygon"===this._options.type&&this._vertices.length>=3){const t=this._vertices[0],e=this._map.project(t[0],t[1]);if(Math.hypot(e[0]-i,e[1]-r)<=12)return void this._commitFeature()}this._vertices.push(n),this._updateDrawState(),this._map.render()}_onDblClick(t){this._map&&(t.preventDefault(),t.stopPropagation(),"point"!==this._options.type&&("polyline"===this._options.type&&this._vertices.length>=2||"polygon"===this._options.type&&this._vertices.length>=3)&&this._commitFeature())}_onKeyDown(t){"Escape"===t.key&&(this._clearDrawState(),this._map?.clearEditDrawState(),this._map?.render())}_findSnapTarget(t,e){if(!this._map)return null;const i=this._map,r=this._options.snapSources??[this._options.source],n=!1!==this._options.snapToVertex,s=!1!==this._options.snapToEdge;let o=this._snapThreshold,a=null,l=null;for(const c of r){const r=i.getSource(c);if(!r)continue;const h=r.getArcs();if(!h?.getVertexData)continue;const u=h.getVertexData();if(!u)continue;const p=u.xx,d=u.yy;if(n)for(let r=0;r<p.length;r++){const n=i.project(p[r],d[r]),s=Math.hypot(n[0]-t,n[1]-e);s<o&&(o=s,a=[p[r],d[r]],l="vertex")}s&&h.forEachSegment&&h.forEachSegment((r,n,s,c)=>{const h=i.project(s[r],c[r]),u=i.project(s[n],c[n]),p=or([t,e],h,u);p.dist<o&&(o=p.dist,a=i.unproject(p.point[0],p.point[1]),l="edge")})}if(n)for(const r of this._vertices){const n=i.project(r[0],r[1]),s=Math.hypot(n[0]-t,n[1]-e);s<o&&(o=s,a=[r[0],r[1]],l="vertex")}return a?{coord:a,kind:l}:null}_commitFeature(){if(!this._map||0===this._vertices.length)return;const t=this._map.getSource(this._options.source);if(!t)return;const e=t.getDataset();if(!e)return;const i=this._resolveTargetLayer(e.layers);if(!i)return;const r=e.layers.indexOf(i);let n,s,o;if(i.shapes||(i.shapes=[]),"point"===this._options.type)n=[this._vertices[0]],i.shapes.push(n);else{if(s="polygon"===this._options.type?[...this._vertices,this._vertices[0]]:[...this._vertices],o=e.arcs,!o)return;n=[[this._appendArc(o,s)]],i.shapes.push(n)}let a=null;if(i.data){const t=i.data.getRecords?.();t&&(a={},t.push(a))}t.refreshDisplayArcs(),this._map.pushCommand(new tr({geometryType:this._options.type,layer:i,source:t,appendedShape:n,appendedRecord:a,arcVertices:s,arcs:o}));const l=i.shapes.length-1,c=it(i,r>=0?r:0);this._map.fire("feature_created",{id:l,source:this._options.source,layer:c,geometryType:this._options.type,properties:{}}),this._clearDrawState(),this._map.clearEditDrawState(),t.fire("data",{reason:"edit"})}_resolveTargetLayer(t){if(!t.length)return null;if(this._options.sourceLayer)for(let e=0;e<t.length;e++){if(it(t[e],e)===this._options.sourceLayer)return t[e]}const e="polygon"===this._options.type?"polygon":"polyline"===this._options.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(),r=i.xx,n=i.yy,s=i.nn,o=i.zz,a=r.length,l=s.length,c=e.length,h=new Float64Array(a+c),u=new Float64Array(a+c),p=new Int32Array(l+1);h.set(r),u.set(n),p.set(s);for(let t=0;t<c;t++)h[a+t]=e[t][0],u[a+t]=e[t][1];p[l]=c;let d=null;if(o){d=new Float64Array(a+c),d.set(o);for(let t=0;t<c;t++)d[a+t]=1/0}return t.updateVertexData(p,h,u,d),l}_updateDrawState(){this._map&&this._map.setEditDrawState({vertices:[...this._vertices],cursorCoord:this._snapCoord||this._cursorCoord,snapCoord:this._snapCoord,snapKind:this._snapKind,geometryType:this._options.type,drawColor:this._options.drawColor||"#0078ff"})}}function or(t,e,i){const r=e[0],n=e[1],s=i[0],o=i[1],a=t[0],l=t[1],c=s-r,h=o-n,u=c*c+h*h;if(0===u){const t=a-r,e=l-n;return{point:[r,n],dist:Math.hypot(t,e)}}let p=((a-r)*c+(l-n)*h)/u;p<0?p=0:p>1&&(p=1);const d=r+p*c,f=n+p*h;return{point:[d,f],dist:Math.hypot(a-d,l-f)}}function ar(t,e){const[i,r]=t;let n=!1;const s=e.length;for(let t=0,o=s-1;t<s;o=t++){const[s,a]=e[t],[l,c]=e[o];a>r!=c>r&&i<(l-s)*(r-a)/(c-a)+s&&(n=!n)}return n}function lr(t,e,i,r){const n=function(t,e){const i=t.getSource(e.source);if(!i)return null;let r=t.layers?.resolve(e.source,e.layer);if(!r){const t=i.getDataset?.();r=t?.layers.find((t,i)=>it(t,i)===e.layer||t?.name===e.layer||t?.id===e.layer)}if(!r?.shapes)return null;const n=r.shapes?.[e.id];return n?{layer:r,shape:n,arcs:i.getArcs?.()}:null}(t,e);if(!n)return!1;if("point"===n.layer.geometry_type){const e=rt(n.shape);if(0===e.length)return!1;const s=e.map(([e,i])=>t.project(e,i));return r?s.some(t=>hr(t,i)):s.every(t=>hr(t,i))}if(!n.arcs)return!1;const s=function(t,e,i){const r=[];for(const n of e){const e=[],s=i.getShapeIter?.(n);if(s)for(;s.hasNext();)e.push(t.project(s.x,s.y));else for(const r of n){const n=r>=0?r:~r,s=i.getArcIter(n);for(;s.hasNext();)e.push(t.project(s.x,s.y))}e.length>0&&r.push(e)}return r}(t,n.shape,n.arcs);if(0===s.length)return!1;const o="polygon"===n.layer.geometry_type;return r?function(t,e,i){for(const r of t){if(r.some(t=>hr(t,e)))return!0;if(cr(r,e,i))return!0}return!(!i||!e.some(e=>function(t,e){let i=!1;for(const r of e){if(ur(t,r))return!0;ar(t,r)&&(i=!i)}return i}(e,t)))}(s,i,o):function(t,e,i){for(const r of t){if(!r.every(t=>hr(t,e)))return!1;if(cr(r,e,i))return!1}return!0}(s,i,o)}function cr(t,e,i){const r=i?pr(t):t,n=pr(e);for(let t=0;t<r.length-1;t++){const e=r[t],i=r[t+1];for(let t=0;t<n.length-1;t++){if(dr(e,i,n[t],n[t+1]))return!0}}return!1}function hr(t,e){return ur(t,e)||ar(t,e)}function ur(t,e){const i=pr(e);for(let e=0;e<i.length-1;e++)if(fr(t,i[e],i[e+1]))return!0;return!1}function pr(t){if(t.length<2)return t;const e=t[0],i=t[t.length-1];return r=e,n=i,Math.abs(r[0]-n[0])<=gr&&Math.abs(r[1]-n[1])<=gr?t:[...t,e];var r,n}function dr(t,e,i,r){const n=mr(t,e,i),s=mr(t,e,r),o=mr(i,r,t),a=mr(i,r,e);return!(!_r(n)||!fr(i,t,e))||(!(!_r(s)||!fr(r,t,e))||(!(!_r(o)||!fr(t,i,r))||(!(!_r(a)||!fr(e,i,r))||n>0!=s>0&&o>0!=a>0)))}function fr(t,e,i){return!!_r(mr(e,i,t))&&(t[0]>=Math.min(e[0],i[0])-gr&&t[0]<=Math.max(e[0],i[0])+gr&&t[1]>=Math.min(e[1],i[1])-gr&&t[1]<=Math.max(e[1],i[1])+gr)}function mr(t,e,i){return(e[0]-t[0])*(i[1]-t[1])-(e[1]-t[1])*(i[0]-t[0])}function _r(t){return Math.abs(t)<=gr}const gr=1e-9;const yr=[{value:"",label:"weighted (default)"},{value:"weighted",label:"weighted"},{value:"visvalingam",label:"visvalingam"},{value:"dp",label:"dp (Douglas–Peucker)"}];var vr={exports:{}};
|
|
2
2
|
/**
|
|
3
3
|
* MapLibre GL JS
|
|
4
4
|
* @license 3-Clause BSD. Full text of license: https://github.com/maplibre/maplibre-gl-js/blob/v5.17.0/LICENSE.txt
|