@zwishing/emap 0.2.0 → 0.3.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 +212 -1
- package/FEATURES.md +455 -0
- package/README.md +415 -210
- package/dist/core/event-map.d.ts +67 -0
- package/dist/core/feature-event-dispatcher.d.ts +70 -0
- package/dist/core/handler-manager.d.ts +49 -0
- package/dist/core/handler.d.ts +48 -0
- package/dist/core/handlers/box-select.d.ts +54 -0
- package/dist/core/handlers/click-select.d.ts +31 -0
- package/dist/core/handlers/drag-pan.d.ts +28 -0
- package/dist/core/handlers/draw-feature.d.ts +76 -0
- package/dist/core/handlers/lasso-select.d.ts +57 -0
- package/dist/core/handlers/scroll-zoom.d.ts +24 -0
- package/dist/core/handlers/select-geometry.d.ts +24 -0
- package/dist/core/handlers/select-mode.d.ts +14 -0
- package/dist/core/handlers/transform-feature.d.ts +41 -0
- package/dist/core/handlers/vertex-edit.d.ts +98 -0
- package/dist/core/pointer-event-dispatcher.d.ts +40 -0
- package/dist/core/tween.d.ts +1 -0
- package/dist/emap.css +42 -8
- package/dist/emap.js +2 -2
- package/dist/emap.mjs +1 -1
- package/dist/geo/camera.d.ts +100 -0
- package/dist/geo/projection.d.ts +8 -1
- package/dist/geo/viewport.d.ts +18 -0
- package/dist/index.d.ts +26 -2
- package/dist/map/edit-state-store.d.ts +1 -1
- package/dist/map/map.d.ts +89 -2
- package/dist/map/selection.d.ts +5 -2
- package/dist/renderer/edit-overlay-renderer.d.ts +2 -1
- package/dist/source/source.d.ts +2 -2
- package/dist/source/topology-source.d.ts +7 -2
- package/dist/ui/box-select-control.d.ts +13 -37
- package/dist/ui/draw-feature-control.d.ts +6 -71
- package/dist/ui/lasso-select-control.d.ts +14 -61
- package/dist/ui/status-control.d.ts +2 -2
- package/dist/ui/vertex-edit-control.d.ts +5 -100
- package/package.json +5 -1
- package/dist/core/drag-pan-handler.d.ts +0 -28
package/dist/emap.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"./mapshaper-vendor.mjs";function e(t,e){return e.forEach(function(e){e&&"string"!=typeof e&&!Array.isArray(e)&&Object.keys(e).forEach(function(n){if("default"!==n&&!(n in t)){var i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,i.get?i:{enumerable:!0,get:function(){return e[n]}})}})}),Object.freeze(t)}function n(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function i(t){if(t.__esModule)return t;var e=t.default;if("function"==typeof e){var n=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};n.prototype=e.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(t).forEach(function(e){var i=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(n,e,i.get?i:{enumerable:!0,get:function(){return t[e]}})}),n}var s={exports:{}},r=i(Object.freeze({__proto__:null,default:{}}));function o(t,e){for(var n=0,i=t.length-1;i>=0;i--){var s=t[i];"."===s?t.splice(i,1):".."===s?(t.splice(i,1),n++):n&&(t.splice(i,1),n--)}if(e)for(;n--;n)t.unshift("..");return t}var a=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,h=function(t){return a.exec(t).slice(1)};function l(){for(var t="",e=!1,n=arguments.length-1;n>=-1&&!e;n--){var i=n>=0?arguments[n]:"/";if("string"!=typeof i)throw new TypeError("Arguments to path.resolve must be strings");i&&(t=i+"/"+t,e="/"===i.charAt(0))}return(e?"/":"")+(t=o(g(t.split("/"),function(t){return!!t}),!e).join("/"))||"."}function c(t){var e=u(t),n="/"===x(t,-1);return(t=o(g(t.split("/"),function(t){return!!t}),!e).join("/"))||e||(t="."),t&&n&&(t+="/"),(e?"/":"")+t}function u(t){return"/"===t.charAt(0)}function p(){return c(g(Array.prototype.slice.call(arguments,0),function(t,e){if("string"!=typeof t)throw new TypeError("Arguments to path.join must be strings");return t}).join("/"))}function d(t,e){function n(t){for(var e=0;e<t.length&&""===t[e];e++);for(var n=t.length-1;n>=0&&""===t[n];n--);return e>n?[]:t.slice(e,n-e+1)}t=l(t).substr(1),e=l(e).substr(1);for(var i=n(t.split("/")),s=n(e.split("/")),r=Math.min(i.length,s.length),o=r,a=0;a<r;a++)if(i[a]!==s[a]){o=a;break}var h=[];for(a=o;a<i.length;a++)h.push("..");return(h=h.concat(s.slice(o))).join("/")}function _(t){var e=h(t),n=e[0],i=e[1];return n||i?(i&&(i=i.substr(0,i.length-1)),n+i):"."}function f(t,e){var n=h(t)[2];return e&&n.substr(-1*e.length)===e&&(n=n.substr(0,n.length-e.length)),n}function m(t){return h(t)[3]}var y={extname:m,basename:f,dirname:_,sep:"/",delimiter:":",relative:d,join:p,isAbsolute:u,normalize:c,resolve:l};function g(t,e){if(t.filter)return t.filter(e);for(var n=[],i=0;i<t.length;i++)e(t[i],i,t)&&n.push(t[i]);return n}var v,x="b"==="ab".substr(-1)?function(t,e,n){return t.substr(e,n)}:function(t,e,n){return e<0&&(e=t.length+e),t.substr(e,n)},w=i(Object.freeze({__proto__:null,basename:f,default:y,delimiter:":",dirname:_,extname:m,isAbsolute:u,join:p,normalize:c,relative:d,resolve:l,sep:"/"}));v=s,function(){var t=Math.abs,e=Math.floor,n=Math.sin,i=Math.cos,s=Math.tan,o=Math.asin,a=Math.acos,h=Math.atan,l=Math.atan2,c=Math.sqrt,u=Math.pow,p=Math.exp,d=Math.log,_=Math.hypot,f=Math.sinh,m=Math.cosh,y=Math.min,g=Math.max,x=1/0,b=Math.PI,C=57.29577951308232,S=.017453292519943295,A=6378137,M=.0066943799901413165,E=b/4,k=b/2,D=1.5*b,I=2*b,P=2/b,T=-45,L=-47,N=1e-10,R={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 G(){var t=R.last_errno;t&&(t>0||!function(t){return O.indexOf(t)>-1}(t))&&j(t)}var O=[-14,-15,-17,-18,-19,-20,-27,-48];function B(t){R.last_errno=t}function z(){B(-20)}function U(){B(-20)}function q(t){j(t)}function j(t){B(t),$()}function $(t,e){var n;throw e||(e={}),e.code||(e.code=R.last_errno||0),t||(n=e.code,t=F[~n]||"unknown error"),R.last_errno=0,new V(t,e)}function V(t,e){var n=new Error(t);return n.name="ProjError",Object.keys(e).forEach(function(t){n[t]=e[t]}),n}function H(t){return W(t)*S}function W(t){var e=/(-?[0-9.]+)d?([0-9.]*)'?([0-9.]*)"?([nsew]?)$/i.exec(t),n=NaN;return e&&(n=+(e[1]||"0")+ +(e[2]||"0")/60+ +(e[3]||"0")/3600,/[ws]/i.test(e[4])&&(n=-n)),isNaN(n)&&j(-16),n}function K(t){return X(t)}function X(t){return parseFloat(t)}function Z(t,e){var n,i,s=e[0],r=t[e.substr(1)],o=void 0!==r;return"t"==s?n=o:o?(i=r.param,r.used=!0,"i"==s?n=parseInt(i):"d"==s?n=K(i):"r"==s?n=H(i):"s"==s?n=String(i):"b"==s&&("T"==i||"t"==i||!0===i?n=!0:("F"==i||"f"==i||B(-8),n=!1))):n={i:0,b:!1,d:0,r:0,s:""}[s],void 0===n&&$("invalid request to pj_param, fatal"),n}function J(t){for(var e,n=/\+([a-z][a-z0-9_]*(?:=[^\s]*)?)/gi,i={};e=n.exec(t);)Y(i,e[1]);return i}function Y(t,e){var n,i,s=e.split("=");1==s.length?(n=e,i=!0):(n=s[0],i=e.substr(s[0].length+1)),t[n]={used:!1,param:i}}var Q={};function tt(t,e,n,i){Q[e]={init:t,name:n,description:i}}function et(t){return!t||t.is_latlong}function nt(t){var e=!1,n="";return"datum"in t.params?(e=!0,n+=st(t,"datum")):"R"in t.params?n+=st(t,"R"):"ellps"in t.params?n+=st(t,"ellps"):"a"in t.params?(n+=st(t,"a"),"b"in t.params?n+=st(t,"b"):"es"in t.params?n+=st(t,"es"):"f"in t.params?n+=st(t,"f"):n+=" +es="+t.es):q(-13),e||(n+=st(t,"towgs84"),n+=st(t,"nadgrids")),n+=st(t,"R_A"),n+=st(t,"R_V"),n+=st(t,"R_a"),n+=st(t,"R_lat_a"),n+=st(t,"R_lat_g"),n+=st(t,"pm")}function it(t){var e="datum,ellps,a,b,es,rf,f,towgs84,nadgrids,R,R_A,R_V,R_a,R_lat_a,R_lat_g,pm,init,no_defs".split(","),n="";return Object.keys(t.params).forEach(function(i){-1==e.indexOf(i)&&(n+=st(t,i))}),(n+=nt(t)).trim()}function st(t,e){var n="";return e in t.params&&(n=" +"+e,!0!==t.params[e].param&&(n+="="+Z(t.params,"s"+e))),n}var rt=[["WGS84","towgs84=0,0,0","WGS84","WGS_1984"],["GGRS87","towgs84=-199.87,74.79,246.62","GRS80","Greek_Geodetic_Reference_System_1987"],["NAD83","towgs84=0,0,0","GRS80","North_American_Datum_1983"],["NAD27","nadgrids=@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat","clrk66","North_American_Datum_1927"],["potsdam","towgs84=598.1,73.7,418.2,0.202,0.045,-2.455,6.7","bessel","Potsdam Rauenberg 1950 DHDN"],["carthage","towgs84=-263.0,6.0,431.0","clrk80ign","Carthage 1934 Tunisia"],["hermannskogel","towgs84=577.326,90.129,463.919,5.137,1.474,5.297,2.4232","bessel","Hermannskogel"],["ire65","towgs84=482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15","mod_airy","Ireland 1965"],["nzgd49","towgs84=59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993","intl","New Zealand Geodetic Datum 1949"],["OSGB36","towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894","airy","OSGB 1936"],[null,null,null,null]],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=rt.reduce(function(e,n){return n[0]===t?n:e},null);return e?{id:e[0],defn:e[1],ellipse_id:e[2],name:e[3]}:null}var ht=[["MERIT","a=6378137.0","rf=298.257","MERIT 1983"],["SGS85","a=6378136.0","rf=298.257","Soviet Geodetic System 85"],["GRS80","a=6378137.0","rf=298.257222101","GRS 1980(IUGG, 1980)"],["IAU76","a=6378140.0","rf=298.257","IAU 1976"],["airy","a=6377563.396","b=6356256.910","Airy 1830"],["APL4.9","a=6378137.0","rf=298.25","Appl. Physics. 1965"],["NWL9D","a=6378145.0","rf=298.25","Naval Weapons Lab., 1965"],["mod_airy","a=6377340.189","b=6356034.446","Modified Airy"],["andrae","a=6377104.43","rf=300.0","Andrae 1876 (Den., Iclnd.)"],["aust_SA","a=6378160.0","rf=298.25","Australian Natl & S. Amer. 1969"],["GRS67","a=6378160.0","rf=298.2471674270","GRS 67(IUGG 1967)"],["bessel","a=6377397.155","rf=299.1528128","Bessel 1841"],["bess_nam","a=6377483.865","rf=299.1528128","Bessel 1841 (Namibia)"],["clrk66","a=6378206.4","b=6356583.8","Clarke 1866"],["clrk80","a=6378249.145","rf=293.4663","Clarke 1880 mod."],["clrk80ign","a=6378249.2","rf=293.4660212936269","Clarke 1880 (IGN)."],["CPM","a=6375738.7","rf=334.29","Comm. des Poids et Mesures 1799"],["delmbr","a=6376428","rf=311.5","Delambre 1810 (Belgium)"],["engelis","a=6378136.05","rf=298.2566","Engelis 1985"],["evrst30","a=6377276.345","rf=300.8017","Everest 1830"],["evrst48","a=6377304.063","rf=300.8017","Everest 1948"],["evrst56","a=6377301.243","rf=300.8017","Everest 1956"],["evrst69","a=6377295.664","rf=300.8017","Everest 1969"],["evrstSS","a=6377298.556","rf=300.8017","Everest (Sabah & Sarawak)"],["fschr60","a=6378166","rf=298.3","Fischer (Mercury Datum) 1960"],["fschr60m","a=6378155","rf=298.3","Modified Fischer 1960"],["fschr68","a=6378150","rf=298.3","Fischer 1968"],["helmert","a=6378200","rf=298.3","Helmert 1906"],["hough","a=6378270.0","rf=297","Hough"],["intl","a=6378388.0","rf=297","International 1909 (Hayford)"],["krass","a=6378245.0","rf=298.3","Krasovsky 1940"],["kaula","a=6378163","rf=298.24","Kaula 1961"],["lerch","a=6378139","rf=298.257","Lerch 1979"],["mprts","a=6397300","rf=191","Maupertius 1738"],["new_intl","a=6378157.5","b=6356772.2","New International 1967"],["plessis","a=6376523","b=6355863","Plessis 1817 (France)"],["SEasia","a=6378155.0","b=6356773.3205","Southeast Asia"],["walbeck","a=6376896.0","b=6355834.8467","Walbeck"],["WGS60","a=6378165.0","rf=298.3","WGS 60"],["WGS66","a=6378145.0","rf=298.25","WGS 66"],["WGS72","a=6378135.0","rf=298.26","WGS 72"],["WGS84","a=6378137.0","rf=298.257223563","WGS 84"],["sphere","a=6370997.0","b=6370997.0","Normal Sphere (r=6370997)"],[null,null,null,null]];function lt(t){var e=ht.reduce(function(e,n){return n[0]===t?n:e},null);return e?{id:e[0],major:e[1],ell:e[2],name:e[3]}:null}var ct=[["km","1000","Kilometer"],["m","1","Meter"],["dm","1/10","Decimeter"],["cm","1/100","Centimeter"],["mm","1/1000","Millimeter"],["kmi","1852.0","International Nautical Mile"],["in","0.0254","International Inch"],["ft","0.3048","International Foot"],["yd","0.9144","International Yard"],["mi","1609.344","International Statute Mile"],["fath","1.8288","International Fathom"],["ch","20.1168","International Chain"],["link","0.201168","International Link"],["us-in","1/39.37","U.S. Surveyor's Inch"],["us-ft","0.304800609601219","U.S. Surveyor's Foot"],["us-yd","0.914401828803658","U.S. Surveyor's Yard"],["us-ch","20.11684023368047","U.S. Surveyor's Chain"],["us-mi","1609.347218694437","U.S. Surveyor's Statute Mile"],["ind-yd","0.91439523","Indian Yard"],["ind-ft","0.30479841","Indian Foot"],["ind-ch","20.11669506","Indian Chain"],[null,null,null]];function ut(t){var e=ct.reduce(function(e,n){return t===n[0]?n:e},null);return e?{id:e[0],to_meter:e[1],name:e[2]}:null}var pt={},dt={};function _t(t){return dt[t]||null}function ft(t){var e,n,i,s,o,a,h,l,c=t.split(":"),u=c[0],p=c[1];return p&&u||q(-3),(e=_t(u=u.toLowerCase()))||(n=u,s=r,a=(o=w).join(o.dirname("/Users/zhang/code/emap/node_modules/mproj/dist"),"../nad"),h=o.join(a,n.toUpperCase()),l=o.join(a,n.toLowerCase()),s.existsSync(h)?i=s.readFileSync(h,"utf8"):s.existsSync(l)?i=s.readFileSync(l,"utf8"):$("unable to read from 'init' file named "+n),e=i,dt[u]=e),e?function(t,e){var n,i,s="",r="";return(n=t.indexOf("<"+e+">"))>-1&&((i=t.lastIndexOf("#",n))>-1&&(r=t.substring(i+1,n).trim(),/\n/.test(r)&&(r="")),s=(s=(s=" "+(s=(s=(s=(s=(s=t.substr(n+e.length+2)).substr(0,s.indexOf("<"))).replace(/#.*/g,"")).replace(/[\s]+/g," ")).replace(/\+title=[^+]*[^ +]/g,function(t){return t.replace(/ /g,"\t")}))).replace(/ (?=[a-z])/gi," +")).replace(/\t/g," ").trim()),s?{opts:s,comment:r}:null}(e,p):null}function mt(e){var i,s,r=J(e),o={params:r,is_latlong:!1,is_geocent:!1,is_long_wrap_set:!1,long_wrap_center:0,axis:"enu",gridlist:null,gridlist_count:0,vgridlist_geoid:null,vgridlist_geoid_count:0};return Object.keys(r).length||q(-1),Z(r,"tinit")&&function(t,e){var n=pt[e.toLowerCase()]||null;n||function(t,e){pt[t.toLowerCase()]=e}(e,n=ft(e)),n||q(-2),yt(t,n.opts)}(r,Z(r,"sinit")),(i=Z(r,"sproj"))||q(-4),(s=Q[i])||q(-5),Z(r,"bno_defs")||function(t){yt(t,"+ellps=WGS84")}(o.params),function(t){var e,n,i,s,r=484813681109536e-20,o=t.datum_params=[0,0,0,0,0,0,0];t.datum_type=0,(e=Z(t.params,"sdatum"))&&((n=at(e))||q(-9),n.ellipse_id&&Y(t.params,"ellps="+n.ellipse_id),n.defn&&Y(t.params,n.defn)),(i=Z(t.params,"snadgrids"))&&"@null"!=i&&$("+nadgrids is not implemented"),Z(t.params,"scatalog")&&$("+catalog is not implemented"),(s=Z(t.params,"stowgs84"))&&(s.split(",").forEach(function(t,e){o[e]=K(t)||0}),0!=o[3]||0!=o[4]||0!=o[5]||0!=o[6]?(t.datum_type=2,o[3]*=r,o[4]*=r,o[5]*=r,o[6]=o[6]/1e6+1):t.datum_type=1)}(o),function(e){var i,s,r,o,a,h=.16666666666666666,l=e.params,u=0,p=0;Z(l,"tR")?u=Z(l,"dR"):((i=Z(l,"sellps"))&&((s=lt(i))||q(-9),Y(l,s.major),Y(l,s.ell)),u=Z(l,"da"),Z(l,"tes")?p=Z(l,"des"):Z(l,"te")?p=(r=Z(l,"de"))*r:Z(l,"trf")?((r=Z(l,"drf"))||q(-10),p=(r=1/r)*(2-r)):Z(l,"tf")?p=(r=Z(l,"df"))*(2-r):Z(l,"tb")&&(p=1-(o=Z(l,"db"))*o/(u*u)),o||(o=u*c(1-p)),Z(l,"bR_A")?(u*=1-p*(h+p*(.04722222222222222+.022156084656084655*p)),p=0):Z(l,"bR_V")?u*=1-p*(h+p*(.06944444444444445+.04243827160493827*p)):Z(l,"bR_a")?(u=.5*(u+o),p=0):Z(l,"bR_g")?(u=c(u*o),p=0):Z(l,"bR_h")?(u+o===0&&q(-20),u=2*u*o/(u+o),p=0):(a=Z(l,"tR_lat_a")||Z(l,"tR_lat_g"))&&(r=n(Z(l,a?"rR_lat_a":"rR_lat_g")),t(r)>k&&q(-11),r=1-p*r*r,u*=a?.5*(1-p+r)/(r*c(r)):c(1-p)/r,p=0)),p<0&&q(-12),u<=0&&q(-13),e.es=p,e.a=u}(o),o.a_orig=o.a,o.es_orig=o.es,o.e=c(o.es),o.ra=1/o.a,o.one_es=1-o.es,o.one_es||q(-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&&Z(r,"bgeoc"),o.over=Z(r,"bover"),o.has_geoid_vgrids=Z(r,"tgeoidgrids"),o.has_geoid_vgrids&&Z(r,"sgeoidgrids"),o.is_long_wrap_set=Z(r,"tlon_wrap"),o.is_long_wrap_set&&(o.long_wrap_center=Z(r,"rlon_wrap"),t(o.long_wrap_center)<10*I==0&&q(-14)),Z(r,"saxis")&&function(t){var e="ewnsud",n=Z(t.params,"saxis");3!=n.length&&q(L),-1!=e.indexOf(n[0])&&-1!=e.indexOf(n[1])&&-1!=e.indexOf(n[2])||q(L),t.axis=n}(o),o.lam0=Z(r,"rlon_0"),o.phi0=Z(r,"rlat_0"),o.x0=Z(r,"dx_0"),o.y0=Z(r,"dy_0"),Z(r,"tk_0")?o.k0=Z(r,"dk_0"):Z(r,"tk")?o.k0=Z(r,"dk"):o.k0=1,o.k0<=0&&q(-31),function(t){var e,n,i,s=t.params;(e=Z(s,"sunits"))&&((i=ut(e))||q(-7),n=i.to_meter),n||(n=Z(s,"sto_meter"))?(t.to_meter=gt(n),t.fr_meter=1/t.to_meter):t.to_meter=t.fr_meter=1,n=null,(e=Z(s,"svunits"))&&((i=ut(e))||q(-7),n=i.to_meter),n||Z(s,"svto_meter")?(t.vto_meter=gt(n),t.vfr_meter=1/t.vto_meter):(t.vto_meter=t.to_meter,t.vfr_meter=t.fr_meter)}(o),function(t){var e,n,i,s=t.params;(e=Z(s,"spm"))?(n=function(t){var e=ot.reduce(function(e,n){return n[0]===t?n:e},null);return e?{id:e[0],definition:e[1]}:null}(e),i=H(n?n.definition:e),isNaN(i)&&q(-46),t.from_greenwich=i):t.from_greenwich=0}(o),s.init(o),o}function yt(t,e){var n=J(e),i=["datum","ellps","a","b","rf","f"].reduce(function(e,n){return e||n in t},!1);Object.keys(n).forEach(function(e){e in t||"ellps"==e&&i||(t[e]=n[e])})}function gt(t){var e=t.split("/"),n=X(e[0]);return e.length>1&&(n/=X(e[1])),n}function vt(t,e){var n=0,i=t*t,s=e*e;return t<=0&&(n|=4),e<=0&&(n|=8),t<e&&(n|=16),n?null:{a:t,b:e,a2:i,b2:s,e2:(i-s)/i,ep2:(i-s)/s}}function xt(t,e,s,r,o){var a,h,l,u,p=0,d=s[e],_=r[e],f=o[e];return _<-k&&_>-1.001*k?_=-k:_>k&&_<1.001*k?_=k:(_<-k||_>k)&&(p|=1),p||(d>b&&(d-=2*b),h=n(_),u=i(_),l=h*h,a=t.a/c(1-t.e2*l),s[e]=(a+f)*u*i(d),r[e]=(a+f)*u*n(d),o[e]=(a*(1-t.e2)+f)*h),p}function wt(e,n,i,s,r){var o,a,u,p,d,_,f,m,y,g,v,x,w,b,C,S,A=1e-12,M=i[n],E=s[n],D=r[n];if(p=c(M*M+E*E),d=c(M*M+E*E+D*D),p/e.a<A){if(a=0,d/e.a<A)return i[n]=0,s[n]=k,r[n]=-e.b,0}else a=l(E,M);_=D/d,f=p/d,m=1/c(1-e.e2*(2-e.e2)*f*f),v=f*(1-e.e2)*m,x=_*m,S=0;do{S++,u=p*v+D*x-(y=e.a/c(1-e.e2*x*x))*(1-e.e2*x*x),g=e.e2*y/(y+u),C=(b=_*(m=1/c(1-g*(2-g)*f*f)))*v-(w=f*(1-g)*m)*x,v=w,x=b}while(C*C>1e-24&&S<30);o=h(b/t(w)),i[n]=a,s[n]=o,r[n]=u}function bt(t,e,n){var i=n.length>2,s=[n[0]],r=[n[1]],o=[i?n[2]:0];t.is_latlong&&(s[0]*=S,r[0]*=S),R.last_errno=0,Ct(t,e,s,r,o),(R.last_errno||s[0]==x)&&$(null,{point:n}),e.is_latlong&&(s[0]*=C,r[0]*=C),n[0]=s[0],n[1]=r[0],i&&(n[2]=o[0])}function Ct(t,e,n,i,s){var r,o,a=n.length,h={},l={};if("enu"!=t.axis&&St(t.axis,!1,n,i,s),1!=t.vto_meter&&s)for(r=0;r<a;r++)s[r]*=t.vto_meter;if(t.is_geocent){if(s||q(T),1!=t.to_meter)for(r=0;r<a;r++)n[r]!=x&&(n[r]*=t.to_meter,i[r]*=t.to_meter);At(t.a_orig,t.es_orig,n,i,s)}else if(!t.is_latlong)if(t.inv3d||t.inv||$("source projection not invertible"),t.inv3d)$("inverse 3d transformations not supported");else for(r=0;r<a;r++)l.x=n[r],l.y=i[r],o=Dt(l,t),n[r]=o.lam,i[r]=o.phi,G();if(0!==t.from_greenwich)for(r=0;r<a;r++)n[r]!=x&&(n[r]+=t.from_greenwich);if(t.has_geoid_vgrids&&s&&$("vgrid transformation not supported"),function(t,e,n,i,s){var r,o,a,h,l=n.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||Z(t.params,"snadgrids")==Z(e.params,"snadgrids")))}(t,e)||(r=t.a_orig,o=t.es_orig,a=e.a_orig,h=e.es_orig,s||(s=new Float64Array(l)),3==t.datum_type&&($("gridshift not implemented"),r=A,o=M),3==e.datum_type&&(a=A,h=M),o==h&&r==a&&1!=t.datum_type&&2!=t.datum_type&&1!=e.datum_type&&2!=e.datum_type||(Mt(r,o,n,i,s),1!=t.datum_type&&2!=t.datum_type||function(t,e,n,i){var s,r,o,a,h,l,c,u,p=e.length,d=t.datum_params,_=d[0],f=d[1],m=d[2];if(1==t.datum_type)for(u=0;u<p;u++)e[u]!=x&&(e[u]+=_,n[u]+=f,i[u]+=m);else if(2==t.datum_type)for(a=d[3],h=d[4],l=d[5],c=d[6],u=0;u<p;u++)e[u]!=x&&(s=c*(e[u]-l*n[u]+h*i[u])+_,r=c*(l*e[u]+n[u]-a*i[u])+f,o=c*(-h*e[u]+a*n[u]+i[u])+m,e[u]=s,n[u]=r,i[u]=o)}(t,n,i,s),1!=e.datum_type&&2!=e.datum_type||function(t,e,n,i){var s,r,o,a,h,l,c,u,p=e.length,d=t.datum_params,_=d[0],f=d[1],m=d[2];if(1==t.datum_type)for(u=0;u<p;u++)e[u]!=x&&(e[u]-=_,n[u]-=f,i[u]-=m);else if(2==t.datum_type)for(a=d[3],h=d[4],l=d[5],c=d[6],u=0;u<p;u++)e[u]!=x&&(s=(e[u]-_)/c,r=(n[u]-f)/c,o=(i[u]-m)/c,e[u]=s+l*r-h*o,n[u]=-l*s+r+a*o,i[u]=h*s-a*r+o)}(e,n,i,s),At(a,h,n,i,s),3==e.datum_type&&pj_apply_gridshift_2(e,1,n,i,s))))}(t,e,n,i,s),e.has_geoid_vgrids&&s&&$("vgrid transformation not supported"),0!==e.from_greenwich)for(r=0;r<a;r++)n[r]!=x&&(n[r]-=e.from_greenwich);if(e.is_geocent){if(s||q(T),Mt(e.a_orig,e.es_orig,n,i,s),1!=e.fr_meter)for(r=0;r<a;r++)n[r]!=x&&(n[r]*=e.fr_meter,i[r]*=e.fr_meter)}else if(e.is_latlong){if(e.is_latlong&&e.is_long_wrap_set)for(r=0;r<a;r++)if(n[r]!=x){for(;n[r]<e.long_wrap_center-b;)n[r]+=I;for(;n[r]>e.long_wrap_center+b;)n[r]-=I}}else if(e.fwd3d)$("3d transformation not supported");else for(r=0;r<a;r++)h.lam=n[r],h.phi=i[r],o=kt(h,e),n[r]=o.x,i[r]=o.y,G();if(1!=e.vto_meter&&s)for(r=0;r<a;r++)s[r]*=e.vfr_meter;return"enu"!=e.axis&&St(e.axis,!0,n,i,s),1==a?R.last_errno:0}function St(t,e,n,i,s){var r,o,a,h,l,c,u=n.length,p=0;if(e){for(a=0;a<u;a++)if(r=n[a],o=i[a],r!=x)for(s&&(p=s[a]),h=0;h<3;h++)if(2!=h||s)switch(c=0==h?n:1==h?i:s,t[h]){case"e":c[a]=r;break;case"w":c[a]=-r;break;case"n":c[a]=o;break;case"s":c[a]=-o;break;case"u":c[a]=p;break;case"d":c[a]=-p;break;default:q(L)}}else for(a=0;a<u;a++)if(r=n[a],o=i[a],r!=x)for(s&&(p=s[a]),h=0;h<3;h++)switch(l=0==h?r:1==h?o:p,t[h]){case"e":n[a]=l;break;case"w":n[a]=-l;break;case"n":i[a]=l;break;case"s":i[a]=-l;break;case"u":s&&(s[a]=l);break;case"d":s&&(s[a]=-l);break;default:q(L)}}function At(t,e,n,i,s){var r,o,a=n.length;for((o=vt(t,0==e?t:t*c(1-e)))||q(T),r=0;r<a;r++)n[r]!=x&&wt(o,r,n,i,s)}function Mt(t,e,n,i,s){var r,o,a=n.length;for((o=vt(t,0===e?t:t*c(1-e)))||q(T),r=0;r<a;r++)n[r]!=x&&xt(o,r,n,i,s)&&(n[r]=i[r]=x)}function Et(n){var i=6.283185307179586,s=3.141592653589793;return t(n)>3.14159265359&&(n+=s,n-=i*e(n/i),n-=s),n}function kt(e,n){var i={x:0,y:0},r=t(e.phi)-k;return r<=1e-12&&t(e.lam)<=10?(R.last_errno=0,t(r)<=1e-12?e.phi=e.phi<0?-k:k:n.geoc&&(e.phi=h(n.rone_es*s(e.phi))),e.lam-=n.lam0,n.over||(e.lam=Et(e.lam)),n.fwd?(n.fwd(e,i),i.x=n.fr_meter*(n.a*i.x+n.x0),i.y=n.fr_meter*(n.a*i.y+n.y0)):i.x=i.y=x):B(-14),!R.last_errno&&isFinite(i.x)&&isFinite(i.y)||(i.x=i.y=x),i}function Dt(e,n){var i={lam:0,phi:0};return e.x<x&&e.y<x?(R.last_errno=0,n.inv?(e.x=(e.x*n.to_meter-n.x0)*n.ra,e.y=(e.y*n.to_meter-n.y0)*n.ra,n.inv(e,i),i.lam+=n.lam0,n.over||(i.lam=Et(i.lam)),n.geoc&&t(t(i.phi)-k)>1e-12&&(i.phi=h(n.one_es*s(i.phi)))):i.lam=i.phi=x):B(-15),!R.last_errno&&isFinite(i.lam)&&isFinite(i.phi)||(i.lam=i.phi=x),i}function It(t,n,i,s){var r,o,a;for((t<0||t>=9)&&(t=3),r=1,a=0;a<t;a++)r*=10;return o=3600*r,function(a){var h,l,c,u,p="",d="",_="";return a===x||isNaN(a)?"":(a<0?(a=-a,(c=s||"")||(p="-")):c=i||"",l=(a=e(a*o+.5))/r%60,h=(a=e(a/(60*r)))%60,u=e(a/60)+"d",_=l.toFixed(t),_=(l=parseFloat(_))?(n?_:String(l))+'"':"",(l||h)&&2==(d=String(h)+"'").length&&n&&(d="0"+d),p+u+d+_+c)}}function Pt(t,e,n){var i,s,r,o,a,h;return"string"!=typeof t?Ln:("string"!=typeof e?(s="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs",r=t,i=e):(s=t,r=e,i=n),h=Tt(o=mt(s),a=mt(r)),i?h(i):{forward:h,inverse:Tt(a,o)})}function Tt(t,e){return function(n){var i=Array.isArray(n);return n=i?n.concat():[n.x,n.y],bt(t,e,n),i||(n={x:n[0],y:n[1]}),n}}function Lt(t){var e=t.proj in Q?Q[t.proj].name:"",n=it(t),i=Yt(t);return{PROJCS:{NAME:e?i.NAME+" / "+e:"unnamed",GEOGCS:i,PROJECTION:"custom_proj4",PARAMETER:[],UNIT:Ht(t),EXTENSION:["PROJ4",n+" +wktext"]}}}function Nt(t){var e=t.EXTENSION;return e&&"PROJ4"==e[0]?(e[1]||"").replace(" +wktext",""):null}Pt.WGS84="+proj=longlat +datum=WGS84",Pt.toPoint=function(t){var e={x:t[0],y:t[1]};return t.length>2&&(e.z=t[2]),t.length>3&&(e.m=t[3]),e};var Rt=[],Ft=[];function Gt(t){return"string"==typeof t}function Ot(t){var e=zt(t,Ft);return e||(e=function(t){return Nt(t)?Nt:null}(t)),e||$t("unsupported WKT definition: "+(t.NAME||"[unknown]")),e}function Bt(t){var e=zt(t,Rt);return e||(e=Lt),e||$t("unsupported projection: "+function(t){return Ut(t)||"[unknown]"}(t)),e}function zt(t,e){for(var n=0;n<e.length;n++)if((0,e[n][0])(t))return e[n][1];return null}function Ut(t){return Z(t.params,"sproj")}function qt(t){return t.replace(/[-_ \/]+/g,"_").toLowerCase()}function jt(t){var e;return Array.isArray(t)?e=t:t&&t.length>0&&(e=t.split(",")),e}function $t(t){throw new Error(t)}function Vt(t){return{to_meter:t.UNIT[1]}}function Ht(t){return["Meter",t.to_meter||1]}function Wt(t,e){var n,i,s=t.DATUM,r=s.SPHEROID,o=function(t){var e,n={northamerican1983:"NAD83",newzealand1949:"nzgd49"},i=Kt(t.NAME);if(i in n)return n[i];for(var s=0;s<rt.length&&Kt((e=rt[s])[3])!=i&&Kt(e[0])!=i;s++);return e?e[0]:null}(s),a=function(t){var e,n={international1924:"intl"},i=Kt(t[0]);if(i in n)return n[i];if(/^grs1980/.test(i))return"GRS80";if("sphere"==i)return null;for(var s=0;s<ht.length&&Kt((e=ht[s])[3])!=i&&Kt(e[0])!=i;s++);return e?e[0]:null}(r),h=e&&e.aux_sphere,l=r[1],c=r[2];return Xt(t.UNIT,"degree"),h?n="+a="+r[1]:o?n="+datum="+o:a?n="+ellps="+a:(n="+a="+l,c>0&&(n+=" +rf="+c)),!s.TOWGS84||h||o||(n+=" +towgs84="+s.TOWGS84.join(",")),((i=t.PRIMEM?t.PRIMEM[1]:0)>0||i<0)&&(n+=" +pm="+i),n}function Kt(t){return(t||"").replace(/^(GCS|D)_/i,"").replace(/[ _]/g,"").toLowerCase()}function Xt(t,e){t&&t[0].toLowerCase()!=e&&$t("unexpected geographic units: "+geogcs.UNIT[0])}function Zt(t){return function(){return"+proj="+t}}function Jt(t){return function(e){var n,i;return[t.PROJECTION(e),t.PARAMETER(e),t.GEOGCS?t.GEOGCS(e):Wt(e.GEOGCS),(n=Vt(e),i="",1!=n.to_meter&&(i="+to_meter="+n.to_meter),i),"+no_defs"].filter(function(t){return!!t}).join(" ")}}function Yt(t){return{NAME:ee(t),DATUM:Qt(t),PRIMEM:["Greenwich",0],UNIT:["degree",.017453292519943295]}}function Qt(t){var e={NAME:ie(t),SPHEROID:te(t)},n=Z(t.params,"stowgs84");return/[1-9]/.test(n)&&(e.TOWGS84=n),e}function te(t){var e;return e=Z(t.params,"trf")?Z(t.params,"drf"):t.es?1/(1-Math.sqrt(1-t.es)):0,[ne(t),t.a,e]}function ee(t){var e;return et(t)&&(e=he(t)),e||(e=se(t),e=/^[a-z]+$/.test(e)?e[0].toUpperCase()+e.substr(1):e.toUpperCase()),e||"UNK"}function ne(t){var e=lt(function(t){var e=se(t),n=e?at(e):null;return(n?n.ellipse_id:Z(t.params,"sellps"))||""}(t));return e?e.name:"Unknown ellipsoid"}function ie(t){var e=at(se(t));return e&&e.name||"Unknown datum"}function se(t){return Z(t.params,"sdatum")}function re(t){return Bt(t)(t)}function oe(t,e){return ae({PROJECTION:t,PARAMETER:Pe(e)})}function ae(t){return function(e){var n={GEOGCS:t.GEOGCS&&t.GEOGCS(e)||Yt(e),PROJECTION:Gt(t.PROJECTION)?t.PROJECTION:t.PROJECTION(e),PARAMETER:t.PARAMETER(e),UNIT:Ht(e)};return n.NAME=t.NAME&&t.NAME(e,n)||function(t,e){var n=he(t);return n||e.GEOGCS.NAME+" / "+e.PROJECTION}(e,n),{PROJCS:n}}}function he(t){var e;return Z(t.params,"tinit")&&(e=ft(Z(t.params,"sinit"))),e?e.comment:""}function le(t,e,n){var i=ue(e),s=function(t,e){return Jt({PROJECTION:Zt(t),PARAMETER:Ie(e)})}(t,n);de(i,s)}function ce(t,e,n){_e(pe(t),oe(e,n))}function ue(t){var e=jt(t).map(qt);return function(t){var n=t.PROJECTION[0];return e.indexOf(qt(n))>-1}}function pe(t){return function(e){var n=Ut(e);return n&&n==t}}function de(t,e){"function"!=typeof t&&$t("Missing WKT parser test"),"function"!=typeof e&&$t("Missing WKT parse function"),Ft.push([t,e])}function _e(t,e){"function"!=typeof t&&$t("Missing WKT maker test"),"function"!=typeof e&&$t("Missing WKT maker function"),Rt.push([t,e])}de(function(t){return fe.test(qt(t.NAME))},function(t){return Jt({PROJECTION:Zt("utm"),PARAMETER:function(t){var e=fe.exec(qt(t.NAME)),n="+zone="+e[1];return"s"==e[2].toLowerCase()&&(n+=" +south"),n}})(t)}),de(function(t){return me.test(qt(t.NAME))},function(t){return Jt({PROJECTION:Zt("ups"),PARAMETER:function(t){var e=me.exec(qt(t.NAME));return"south"==e[1].toLowerCase()?"+south":""}})(t)}),_e(pe("utm"),function(t){return ae({NAME:ye,PROJECTION:function(){return"Transverse_Mercator"},PARAMETER:ve})(t)}),_e(pe("ups"),function(t){return ae({NAME:ge,PROJECTION:function(){return"Polar_Stereographic"},PARAMETER:xe})(t)});var fe=/UTM_zone_([0-9]{1,2})(N|S)/i,me=/UPS_(North|South)/i;function ye(t,e){return e.GEOGCS.NAME+" / UTM zone "+Z(t.params,"szone")+(Z(t.params,"tsouth")?"S":"N")}function ge(t,e){return e.GEOGCS.NAME+" / UPS "+(Z(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 we(t){return Z(t.params,"tlat_ts")&&0!=Z(t.params,"dlat_ts")}function be(t){return 0===t.es&&6378137==t.a}de(ue("Mercator_2SP,Mercator_1SP,Mercator,Mercator_Auxiliary_Sphere"),Jt({GEOGCS:function(t){var e=function(t){return/(Web_Mercator|Pseudo_Mercator)/i.test(qt(t.NAME))}(t)?{aux_sphere:!0}:null;return Wt(t.GEOGCS,e)},PROJECTION:Zt("merc"),PARAMETER:function(t){return Ie(function(t){var e=ke(t,"standard_parallel_1");return e&&0!=e[1]}(t)?"lat_ts,lat_0b":"lat_tsb,lat_ts")(t)}})),_e(pe("merc"),ae({GEOGCS:function(t){return be(t)?Yt(mt("+proj=longlat +datum=WGS84")):null},PROJECTION:function(t){return we(t)?"Mercator_2SP":"Mercator_1SP"},PARAMETER:function(t){return Pe(we(t)?"lat_ts,lat_0b":"lat_tsb")(t)},NAME:function(t){return be(t)?"WGS 84 / Pseudo-Mercator":null}}));var Ce=[["x_0","false_easting","m"],["y_0","false_northing","m"],["k_0","scale_factor","f"],["lat_0","latitude_of_center"],["lon_0","central_meridian"]],Se={lat_0b:["lat_0","latitude_of_origin"],lat_0c:["lat_0",null],lat_0d:["lat_0","standard_parallel_1"],lat_1:["lat_1","standard_parallel_1"],lat_1b:["lat_1","latitude_of_point_1"],lat_1c:["lat_1","latitude_of_origin"],lat_2:["lat_2","standard_parallel_2"],lat_2b:["lat_2","latitude_of_point_2"],lat_ts:["lat_ts","standard_parallel_1"],lat_tsb:["lat_ts","latitude_of_origin"],lonc:["lonc","central_meridian"],lon_1:["lon_1","longitude_of_point_1"],lon_2:["lon_2","longitude_of_point_2"],alpha:["alpha","azimuth"],gamma:["gamma","rectified_grid_angle"],h:["h","height","f"]},Ae={longitude_of_center:"central_meridian",latitude_of_origin:"latitude_of_center",latitude_of_center:"latitude_of_origin",longitude_of_1st_point:"longitude_of_point_1",longitude_of_2nd_point:"longitude_of_point_2",latitude_of_1st_point:"latitude_of_point_1",latitude_of_2nd_point:"latitude_of_point_2",k:"k_0"};function Me(t,e,n){for(var i=0;i<n.length;i++)if(n[i][e]===t)return n[i];return null}function Ee(t,e,n){var i=null;return!(i=Me(t=t.toLowerCase(),e,n))&&t in Ae&&(i=Me(Ae[t],e,n)),i}function ke(t,e){for(var n,i=t.PARAMETER||[],s=0;s<i.length;s++)if(e===(n=i[s][0].toLowerCase())||e===Ae[n])return i[s];return null}function De(t){var e=null;return t&&(e=jt(t).reduce(function(t,e){var n=Se[e];return n||$t("missing parameter rule: "+e),t.push(n),t},[])),(e||[]).concat(Ce)}function Ie(t){return function(e){var n=[],i=De(t),s=Vt(e);return(e.PARAMETER||[]).forEach(function(t){var e,r,o=Ee(t[0],1,i);o?(e=function(t,e,n){var i=t[0];if("m"==t[2]&&(e*=n.to_meter),!("x_0,y_0,lat_0,lon_0".indexOf(i)>-1&&0===e||"k_0"==i&&1==e))return"+"+i+"="+e}(o,t[1],s),e&&n.push(e)):(r="unhandled parameter: "+t[0],console.error("[wkt] "+r))}),n.join(" ")}}function Pe(t){return function(e){var n=[],i=De(t);return Object.keys(e.params).forEach(function(t){var s,r=Ee(t,0,i);r&&r[1]&&(s=Z(e.params,"s"+t),n.push(function(t,e,n){var i,s=t[2];return i="m"==s?parseFloat(e)/n:"f"==s?parseFloat(e):W(e),[t[1],i]}(r,s,e.to_meter)))}),n}}function Te(t){return!("lat_1"in t.params&&"lat_2"in t.params)}function Le(t){return"omerc"==Ut(t)&&("alpha"in t.params||"gamma"in t.params)}function Ne(t){return Le(t)&&("no_uoff"in t.params||"no_off"in t.params)}function Re(t){return Z(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 Ge(t){return"NAME,PROJCS,GEOGCS,GEOCCS,DATUM,SPHEROID,PRIMEM,PROJECTION,PARAMETER,UNIT,AXIS".indexOf(t)+1||999}function Oe(t,e){var n,i=[];return e=e||0,function(t){return Object.keys(t).sort(function(t,e){return Ge(t)-Ge(e)})}(t).forEach(function(s){var r=t[s];!function(t){return!!t&&"object"==typeof t&&!Array.isArray(t)}(r)?"NAME"==s?i.push(Gt(r)?r:r[0]):"PARAMETER"==s||"AXIS"==s?r.forEach(function(t){i.push([s].concat(t))}):Gt(r)?i.push([s,r]):Array.isArray(r)?i.push([s].concat(r)):((n={})[s]=r,$t("Incorrectly formatted WKT element: "+JSON.stringify(n))):i.push([s].concat(Oe(r,e+1)))}),0===e&&1==i.length&&(i=i[0]),i}function Be(t){var e={};return ze(t).forEach(function(t){qe(t,e)}),e}function ze(t){var e;t="["+(t=(t=(t=Ue(t)).replace(/([A-Z0-9]+)\[(?![^"]*[^\[,"]")/g,'["$1",')).replace(/, *([a-zA-Z]+) *(?=[,\]])/g,',"$1"'))+"]";try{e=JSON.parse(t)}catch(t){$t("unparsable WKT format")}return e}function Ue(t){var e=0;return t.replace(/"+/g,function(t){var n=e%2==0;return e+=t.length,'"'==t||'""'==t&&n?t:n?'"'+t.substring(1).replace(/""/g,'\\"'):t.replace(/""/g,'\\"')})}function qe(t,e){var n,i=t[0];if("GEOGCS"==i||"GEOCCS"==i||"PROJCS"==i||"DATUM"==i||"VERTCS"==i)for(e[i]={NAME:t[1]},n=2;n<t.length;n++){if(!Array.isArray(t[n]))throw $t("WKT parse error");qe(t[n],e[i])}else"AXIS"==i||"PARAMETER"==i?(i in e==0&&(e[i]=[]),e[i].push(t.slice(1))):e[i]=t.slice(1);return e}de(ue("Lambert_Conformal_Conic,Lambert_Conformal_Conic_1SP,Lambert_Conformal_Conic_2SP"),Jt({PROJECTION:Zt("lcc"),PARAMETER:function(t){return Ie(function(t){return!ke(t,"standard_parallel_2")}(t)?"lat_1c":"lat_0b,lat_1,lat_2")(t)}})),_e(pe("lcc"),ae({PROJECTION:function(t){return Te(t)?"Lambert_Conformal_Conic_1SP":"Lambert_Conformal_Conic_2SP"},PARAMETER:function(t){return Pe(Te(t)?"lat_1c,lat_0c":"lat_0b,lat_1,lat_2")(t)}})),de(ue("Hotine_Oblique_Mercator,Hotine_Oblique_Mercator_Azimuth_Natural_Origin"),Jt({PROJECTION:Zt("omerc"),PARAMETER:function(t){return Ie("alpha,gamma,lonc")(t)+" +no_uoff"}})),_e(Ne,oe("Hotine_Oblique_Mercator","alpha,gamma,lonc")),le("omerc","Oblique_Mercator,Hotine_Oblique_Mercator_Azimuth_Center","alpha,gamma,lonc"),_e(function(t){return Le(t)&&!Ne(t)},oe("Oblique_Mercator","alpha,gamma,lonc")),le("omerc","Hotine_Oblique_Mercator_Two_Point_Natural_Origin","lat_1b,lat_2b,lon_1,lon_2"),_e(function(t){return"omerc"==Ut(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"),Jt({PROJECTION:Zt("stere"),PARAMETER:function(t){var e=Ie("lat_ts,lat_tsb")(t),n=/lat_ts=([^ ]+)/.exec(e);return n&&-1==e.indexOf("lat_0=")&&(e="+lat_0="+(parseFloat(n[1])<0?-90:90)+" "+e),e}})),_e(pe("stere"),ae({PROJECTION:function(t){return Re(t)?"Polar_Stereographic":"Stereographic"},PARAMETER:function(t){return Re(t)?Pe("lat_tsb,lat_0c")(t):Pe("lat_0b")(t)}})),ce("vandg","VanDerGrinten"),de(ue("VanDerGrinten,Van_der_Grinten_I"),Jt({PROJECTION:Zt("vandg"),PARAMETER:function(t){var e=Ie("")(t);return e&&(e+=" "),e+"+R_A"}})),[["aitoff","Aitoff","lat1"],["aea","Albers_Conic_Equal_Area,Albers","lat_1,lat_2"],["aeqd","Azimuthal_Equidistant"],["bonne","Bonne","lat_1"],["cass","Cassini_Soldner,Cassini"],["cea","Cylindrical_Equal_Area","lat_ts"],["eck1","Eckert_I"],["eck2","Eckert_II"],["eck3","Eckert_III"],["eck4","Eckert_IV"],["eck5","Eckert_V"],["eck6","Eckert_VI"],["eqdc","Equidistant_Conic","lat_1,lat_2"],["eqc","Plate_Carree,Equirectangular,Equidistant_Cylindrical","lat_ts"],["gall","Gall_Stereographic"],["gnom","Gnomonic"],["laea","Lambert_Azimuthal_Equal_Area"],["loxim","Loximuthal","lat_1"],["mill","Miller_Cylindrical"],["moll","Mollweide"],["nsper","Vertical_Near_Side_Perspective","h"],["nzmg","New_Zealand_Map_Grid","lat_0b"],["ortho","Orthographic","lat_0b"],["poly","Polyconic"],["robin","Robinson"],["sinu","Sinusoidal"],["sterea","Oblique_Stereographic,Double_Stereographic"],["tmerc","Transverse_Mercator,Gauss_Kruger","lat_0b"],["tpeqd","Two_Point_Equidistant","lat_1b,lat_2b,lon_1,lon_2"],["wag1","Wagner_I"],["wag2","Wagner_II"],["wag3","Wagner_III","lat_ts"],["wag4","Wagner_IV"],["wag5","Wagner_V"],["wag6","Wagner_VI"],["wag7","Wagner_VII"],["wink1","Winkel_I","lat_ts"],["wink2","Winkel_II"],["wintri","Winkel_Tripel","lat_1"]].forEach(function(t){var e=t[2]||null;le(t[0],t[1],e),ce(t[0],t[1].split(",")[0],e)});var je,$e,Ve={};function He(t,e,n){var i;return e>=1e-7?n*(t/(1-(i=e*t)*i)-.5/e*d((1-i)/(1+i))):t+t}function We(t,e,n){return e/c(1-n*t*t)}function Ke(e,s,r){var a,h,u,p,f,m,y,g,v,w,b,C,S,A;e.fwd=function(t,s){var r,o=t.lam;(r=u-(y?h*He(n(t.phi),e.e,e.one_es):f*n(t.phi)))<0&&z(),r=p*c(r),s.x=r*n(o*=h),s.y=m-r*i(o)},e.inv=function(s,r){var c=s.x,g=m-s.y,v=_(c,g);0!=v?(h<0&&(v=-v,c=-c,g=-g),r.phi=v/p,y?(r.phi=(u-r.phi*r.phi)/h,t(a-t(r.phi))>1e-7?(r.phi=function(e,s,r){var a,h,l,c,u,p,_=15,f=1e-7,m=1e-10;if(a=o(.5*e),s<f)return a;p=_;do{a+=u=.5*(c=1-(l=s*(h=n(a)))*l)*c/i(a)*(e/r-h/c+.5/s*d((1-l)/(1+l)))}while(t(u)>m&&--p);return p?a:x}(r.phi,e.e,e.one_es))==x&&U():r.phi=r.phi<0?-k:k):t(r.phi=(u-r.phi*r.phi)/f)<=1?r.phi=o(r.phi):r.phi=r.phi<0?-k:k,r.lam=l(c,g)/h):(r.lam=0,r.phi=h>0?k:-k)},t(s+r)<N&&j(-21),h=v=n(s),g=i(s),w=t(s-r)>=N,(y=e.es>0)?(Xe(e.es),A=We(v,g,e.es),S=He(v,e.e,e.one_es),w&&(C=We(v=n(r),g=i(r),e.es),b=He(v,e.e,e.one_es),h=(A*A-C*C)/(b-S)),a=1-.5*e.one_es*d((1-e.e)/(1+e.e))/e.e,m=(p=1/h)*c((u=A*A+h*S)-h*He(n(e.phi0),e.e,e.one_es))):(w&&(h=.5*(h+n(r))),m=(p=1/h)*c((u=g*g+(f=h+h)*v)-f*n(e.phi0)))}function Xe(t){var e,n=.046875,i=.01953125,s=.01068115234375,r=[];return r[0]=1-t*(.25+t*(n+t*(i+t*s))),r[1]=t*(.75-t*(n+t*(i+t*s))),r[2]=(e=t*t)*(.46875-t*(.013020833333333334+.007120768229166667*t)),r[3]=(e*=t)*(.3645833333333333-.005696614583333333*t),r[4]=e*t*.3076171875,r}function Ze(t,e,n,i){return n*=e,e*=e,i[0]*t-n*(i[1]+e*(i[2]+e*(i[3]+e*i[4])))}function Je(e,s,r){var o,a,h,l=1/(1-s);h=e;for(var u=10;u>0;--u)if(a=1-s*(o=n(h))*o,h-=a=(Ze(h,o,i(h),r)-e)*(a*c(a))*l,t(a)<1e-11)return h;return B(R),h}function Ye(e){var n=t(e);return n>=1?(n>1.00000000000001&&B(-19),e<0?-k:k):o(e)}function Qe(e){var n=t(e);return n>=1?(n>1.00000000000001&&B(-19),e<0?b:0):a(e)}function tn(t){return t<=0?0:c(t)}function en(e,n){return t(e)<1e-50&&t(n)<1e-50?0:l(e,n)}function nn(e){var s=e.opaque||{mode:0};e.inv=function(e,r){var o,h,l,c,p,d,_,f,m,y,g,v,x,w,C,S,A,M=1e-12,E=0;if(t(e.x)<M&&t(e.y)<M)return r.phi=0,void(r.lam=0);r.phi=e.y,r.lam=e.x;do{o=0;do{for(v=n(.5*r.lam),C=i(.5*r.lam),x=n(r.phi),l=1-(h=(w=i(r.phi))*C)*h,c=2*(h=a(h)/u(l,1.5))*l*w*v,p=h*l*x,d=2*(v*C*x*w/l-h*x*v),_=w*w*v*v/l+h*w*C*x*x,f=x*x*C/l+h*v*v*w,m=.5*(x*w*v/l-h*x*w*w*v*C),s.mode&&(c=.5*(c+r.lam*s.cosphi1),p=.5*(p+r.phi),d*=.5,_=.5*(_+s.cosphi1),f=.5*(f+1),m*=.5),c-=e.x,g=((p-=e.y)*d-c*f)/(y=d*m-f*_),y=(c*m-p*_)/y;g>b;)g-=b;for(;g<-b;)g+=b;r.phi-=y,r.lam-=g}while((t(y)>M||t(g)>M)&&o++<10);r.phi>k&&(r.phi-=2*(r.phi-k)),r.phi<-k&&(r.phi-=2*(r.phi+k)),t(t(r.phi)-k)<M&&!s.mode&&(r.lam=0),(h=a(i(r.phi)*i(l=.5*r.lam)))?(S=2*h*i(r.phi)*n(l)*(A=1/n(h)),A*=h*n(r.phi)):S=A=0,s.mode&&(S=.5*(S+r.lam*s.cosphi1),A=.5*(A+r.phi))}while((t(e.x-S)>M||t(e.y-A)>M)&&E++<20)},e.fwd=function(t,e){var r,o;(o=a(i(t.phi)*i(r=.5*t.lam)))?(e.x=2*o*i(t.phi)*n(r)*(e.y=1/n(o)),e.y*=o*n(t.phi)):e.x=e.y=0,s.mode&&(e.x=.5*(e.x+t.lam*s.cosphi1),e.y=.5*(e.y+t.phi))},e.es=0}function sn(e,i,s){e.es=0,e.fwd=function(e,r){var o,a,h=2.4674011002723395;r.y=i?k*n(e.phi):e.phi,(o=t(e.lam))>=1e-10?(s&&o>=k?r.x=c(h-e.phi*e.phi+1e-10)+o-k:(a=.5*(h/o+o),r.x=o-a+c(a*a-r.y*r.y)),e.lam<0&&(r.x=-r.x)):r.x=0}}function rn(t){var e,n=[];return n[0]=.3333333333333333*t,e=t*t,n[0]+=.17222222222222222*e,n[1]=.06388888888888888*e,e*=t,n[0]+=.10257936507936508*e,n[1]+=.0664021164021164*e,n[2]=.01677689594356261*e,n}function on(t,e){var i=t+t;return t+e[0]*n(i)+e[1]*n(i+i)+e[2]*n(i+i+i)}function an(t,e){t.es=0,t.fwd=function(t,n){n.y=e.C_y*t.phi,n.x=e.C_x*t.lam*(e.A+tn(1-e.B*t.phi*t.phi))},t.inv=function(t,n){n.phi=t.y/e.C_y,n.lam=t.x/(e.C_x*(e.A+tn(1-e.B*n.phi*n.phi)))}}function hn(e){var r,o,a,u,p,y,g=[],v=[],w=[],b=[];function C(t,e){for(var s,r=2*i(2*e),o=t.length-1,a=t[o],h=0;--o>=0;)s=r*a-h+t[o],h=a,a=s;return e+s*n(2*e)}function S(t,e,s){for(var r,o,a=n(e),h=i(e),l=f(s),c=m(s),u=2*h*c,p=-2*a*l,d=t.length-1,_=t[d],y=0,g=0,v=0;--d>=0;)r=g,o=y,_=u*(g=_)-r-p*(y=v)+t[d],v=p*g-o+u*y;return[(u=a*c)*_-(p=h*l)*v,u*v+p*_]}e.es<=0&&j(-34),p=u=(a=e.es/(1+c(1-e.es)))/(2-a),g[0]=u*(2+u*(-2/3+u*(u*(116/45+u*(26/45+u*(-2854/675)))-2))),v[0]=u*(u*(2/3+u*(4/3+u*(-82/45+u*(32/45+u*(4642/4725)))))-2),p*=u,g[1]=p*(7/3+u*(u*(-227/45+u*(2704/315+u*(2323/945)))-1.6)),v[1]=p*(5/3+u*(-16/15+u*(-13/9+u*(904/315+u*(-1522/945))))),p*=u,g[2]=p*(56/15+u*(-136/35+u*(-1262/105+u*(73814/2835)))),v[2]=p*(-26/15+u*(34/21+u*(1.6+u*(-12686/2835)))),p*=u,g[3]=p*(4279/630+u*(-332/35+u*(-399572/14175))),v[3]=p*(1237/630+u*(u*(-24832/14175)-2.4)),p*=u,g[4]=p*(4174/315+u*(-144838/6237)),v[4]=p*(-734/315+u*(109598/31185)),p*=u,g[5]=p*(601676/22275),v[5]=p*(444337/155925),p=u*u,r=e.k0/(1+u)*(1+p*(1/4+p*(1/64+p/256))),w[0]=u*(u*(2/3+u*(-37/96+u*(1/360+u*(81/512+u*(-96199/604800)))))-.5),b[0]=u*(.5+u*(-2/3+u*(5/16+u*(41/180+u*(-127/288+u*(7891/37800)))))),w[1]=p*(-1/48+u*(-1/15+u*(437/1440+u*(-46/105+u*(1118711/3870720))))),b[1]=p*(13/48+u*(u*(557/1440+u*(281/630+u*(-1983433/1935360)))-.6)),p*=u,w[2]=p*(-17/480+u*(37/840+u*(209/4480+u*(-5569/90720)))),b[2]=p*(61/240+u*(-103/140+u*(15061/26880+u*(167603/181440)))),p*=u,w[3]=p*(-4397/161280+u*(11/504+u*(830251/7257600))),b[3]=p*(49561/161280+u*(-179/168+u*(6601661/7257600))),p*=u,w[4]=p*(-4583/161280+u*(108847/3991680)),b[4]=p*(34729/80640+u*(-3418889/1995840)),p*=u,w[5]=p*(-20648693/638668800),b[5]=.6650675310896665*p,y=C(v,e.phi0),o=-r*(y+function(t,e){for(var s,r=2*i(e),o=t.length-1,a=t[o],h=0;--o>=0;)s=r*a-h+t[o],h=a,a=s;return n(e)*s}(b,2*y)),e.fwd=function(e,a){var h,c,u,p,f,m=e.phi,y=e.lam;m=C(v,m),h=n(m),c=i(m),p=n(y),u=i(y),m=l(h,u*c),y=l(p*c,_(h,c*u)),y=function(e){var n=t(e);return n=function(t){var e=1+t,n=e-1;return 0===n?t:t*d(e)/n}(n*(1+n/(_(1,n)+1))),e<0?-n:n}(s(y)),f=S(b,2*m,2*y),m+=f[0],y+=f[1],t(y)<=2.623395162778?(a.y=r*m+o,a.x=r*y):a.x=a.y=x},e.inv=function(e,s){var a,c,u,p,d,m=e.y,y=e.x;m=(m-o)/r,t(y/=r)<=2.623395162778?(m+=(d=S(w,2*m,2*y))[0],y+=d[1],y=h(f(y)),a=n(m),c=i(m),p=n(y),u=i(y),y=l(p,u*c),m=l(a*u,_(p,u*c)),s.phi=C(g,m),s.lam=y):s.phi=s.lam=x}}function ln(e){var s;e.es?(s=Xe(e.es),e.fwd=function(t,r){var o,a;r.y=Ze(t.phi,o=n(t.phi),a=i(t.phi),s),r.x=t.lam*a/c(1-e.es*o*o)},e.inv=function(r,o){var a=t(o.phi=Je(r.y,e.es,s));a<k?(a=n(o.phi),o.lam=r.x*c(1-e.es*a*a)/i(o.phi)):a-N<k?o.lam=0:U()}):cn(e,0,1)}function cn(e,s,r){var o,a;o=(a=c((s+1)/r))/(s+1),e.es=0,e.fwd=function(e,h){var l,c,u;if(s){for(l=r*n(e.phi),u=8;u&&(e.phi-=c=(s*e.phi+n(e.phi)-l)/(s+i(e.phi)),!(t(c)<1e-7));--u);u||z()}else e.phi=1!=r?Ye(r*n(e.phi)):e.phi;h.x=o*e.lam*(s+i(e.phi)),h.y=a*e.phi},e.inv=function(t,e){t.y/=a,e.phi=s?Ye((s*t.y+n(t.y))/r):1!=r?Ye(n(t.y)/r):t.y,e.lam=t.x/(o*(s+i(t.y)))}}function un(t){dn(t,pn(0,k))}function pn(t,e){var i=n(e),s=e+e,r=c(I*i/(s+n(s)));return{C_x:2*r/b,C_y:r/i,C_p:s+n(s)}}function dn(e,s){e.fwd=function(e,r){var o,a,h;for(o=s.C_p*n(e.phi),h=10;h&&(e.phi-=a=(e.phi+n(e.phi)-o)/(1+i(e.phi)),!(t(a)<1e-7));--h);h?e.phi*=.5:e.phi=e.phi<0?-k:k,r.x=s.C_x*e.lam*i(e.phi),r.y=s.C_y*n(e.phi)},e.inv=function(e,r){r.phi=Ye(e.y/s.C_y),r.lam=e.x/(s.C_x*i(r.phi)),t(r.lam)-b<N?(r.phi+=r.phi,r.phi=Ye((r.phi+n(r.phi))/s.C_p)):r.lam=r.phi=x},e.es=0}function _n(i,s){var r,a,h,l,p,d=[[0,-1],[1,0]],_=[[-1,0],[0,-1]],f=[[0,1],[-1,0]],m=[[[1,0],[0,1]],d,_,f,f,_,d],v=1e-15;function w(i,s){var r=i.lam,a=i.phi,h=o(2/3);if(t(a)<=h)s.x=r,s.y=3*b/8*n(a);else{var l,u=c(3*(1-t(n(a)))),p=e(2*r/b+2);p>=4&&(p=3),l=-3*E+k*p,s.x=l+(r-l)*u,s.y=S(a)*E*(2-u)}}function C(n,i){var s=n.x,r=n.y,a=E;if(t(r)<=a)i.lam=s,i.phi=o(8*r/(3*b));else if(t(r)<k){var h,l,c=e(2*s/b+2);c>=4&&(c=3),h=-3*E+k*c,l=2-4*t(r)/b,i.lam=h+(s-h)/l,i.phi=S(r)*o(1-u(l,2)/3)}else i.lam=-b,i.phi=S(r)*k}function S(t){return t>0?1:t<0?-1:0}function A(t){switch(t){case 0:return 0;case 1:return 1;case 2:return 2;case 3:return 3;case-1:return 4;case-2:return 5;case-3:return 6}return 0}function M(t,e){return function(t,e,n){var i,s,r,o,a,h=0,l=t.length;for(a=0;a<l;a++)if(e==t[a][0]&&n==t[a][1])return!0;for(i=t[0][0],s=t[0][1],a=1;a<l;a++)r=t[a%l][0],o=t[a%l][1],n>y(s,o)&&n<=g(s,o)&&e<=g(i,r)&&s!=o&&(i==r||e<=(n-s)*(r-i)/(o-s)+i)&&h++,i=r,s=o;return h%2!=0}(p,t,e)}function D(e,i,s){if(s)return on(i,l);var r=He(n(i),e.e,1-e.es)/h;return t(r)>1&&(r=S(r)),o(r)}function I(t,e,n,i){var s,r,o,a,h,l,c=0,u=function(t,e,n,i,s){var r,o={};if(o.x=t,o.y=e,s){if(e>E)o.region="north",o.x=-3*E+n*k,o.y=k,t-=n*k;else{if(!(e<-E))return o.region="equatorial",o.cn=0,o;o.region="south",o.x=-3*E+i*k,o.y=-k,t-=i*k}"north"==o.region?o.cn=e>=-t-E-v&&e<t+5*E-v?(n+1)%4:e>-t-E+v&&e>=t+5*E-v?(n+2)%4:e<=-t-E+v&&e>t+5*E+v?(n+3)%4:n:"south"==o.region&&(o.cn=e<=t+E+v&&e>-t-5*E+v?(i+1)%4:e<t+E-v&&e<=-t-5*E+v?(i+2)%4:e>=t+E-v&&e<-t-5*E-v?(i+3)%4:i)}else{if(e>E)o.region="north",r=k;else{if(!(e<-E))return o.region="equatorial",o.cn=0,o;o.region="south",r=-k}t<-k?(o.cn=0,o.x=-3*E,o.y=r):t>=-k&&t<0?(o.cn=1,o.x=-E,o.y=r):t>=0&&t<k?(o.cn=2,o.x=E,o.y=r):(o.cn=3,o.x=3*E,o.y=r)}return o}(t.x,t.y,e,n,i);if("equatorial"==u.region)return t.x=u.x,void(t.y=u.y);s=[t.x,t.y],r=[u.x,u.y],i?"north"==u.region?(c=e,l=m[A(-1*(u.cn-c))]):(c=n,l=m[A(u.cn-c)]):"north"==u.region?(c=e,l=m[A(u.cn-c)]):(c=n,l=m[A(-1*(u.cn-c))]),a=function(t,e){return[t[0]-e[0],t[1]-e[1]]}(s,r),h=function(t,e){var n,i,s=[0,0];for(n=0;n<2;n++)for(i=0;i<2;i++)s[n]+=t[n][i]*e[i];return s}(l,a),o=function(t,e){return[t[0]+e[0],t[1]+e[1]]}(h,[-3*E+(i?u.cn:0)*k,k]),t.x=o[0],t.y=o[1]}s?(r=Z(i.params,"inorth_square"),a=Z(i.params,"isouth_square"),(r<0||r>3)&&j(-47),(a<0||a>3)&&j(-47),p=[[-b-v,E+v],[r*k-b-v,E+v],[r*k-b-v,3*E+v],[(r+1)*k-b+v,3*E+v],[(r+1)*k-b+v,E+v],[b+v,E+v],[b+v,-E-v],[(a+1)*k-b+v,-E-v],[(a+1)*k-b+v,-3*E-v],[a*k-b-v,-3*E-v],[a*k-b-v,-E-v],[-b-v,-E-v]],0!=i.es?(l=rn(i.es),h=He(1,i.e,i.one_es),i.a=i.a*c(.5*h),i.ra=1/i.a,i.fwd=function(t,e){return t.phi=D(i,t.phi,0),w(t,e),I(e,r,a,0)},i.inv=function(t,e){if(!M(t.x,t.y))return e.lam=x,e.phi=x,void B(-15);I(t,r,a,1),C(t,e),e.phi=D(i,e.phi,1)}):(i.fwd=function(t,e){w(t,e),I(e,r,a,0)},i.inv=function(t,e){if(!M(t.x,t.y))return e.lam=x,e.phi=x,void B(-15);I(t,r,a,1),C(t,e)})):(p=[[-b-v,E],[-3*E,k+v],[-k,E+v],[-E,k+v],[0,E+v],[E,k+v],[k,E+v],[3*E,k+v],[b+v,E],[b+v,-E],[3*E,-k-v],[k,-E-v],[E,-k-v],[0,-E-v],[-E,-k-v],[-k,-E-v],[-3*E,-k-v],[-b-v,-E]],0!=i.es?(l=rn(i.es),h=He(1,i.e,i.one_es),i.a=i.a*c(.5*h),i.ra=1/i.a,i.fwd=function(t,e){t.phi=D(i,t.phi,0),w(t,e)},i.inv=function(t,e){if(!M(t.x,t.y))return e.lam=x,e.phi=x,void B(-15);C(t,e),e.phi=D(i,e.phi,1)}):(i.fwd=function(t,e){w(t,e)},i.inv=function(t,e){if(!M(t.x,t.y))return e.lam=x,e.phi=x,void B(-15);C(t,e)}))}function fn(t){t.x0=0,t.y0=0,t.is_latlong=!0,t.fwd=function(e,n){n.x=e.lam/t.a,n.y=e.phi/t.a},t.inv=function(e,n){n.lam=e.x*t.a,n.phi=e.y*t.a}}function mn(t,e,n){return e*=n,s(.5*(k-t))/u((1-e)/(1+e),.5*n)}function yn(e,i){var s,r,o=.5*i,a=k-2*h(e),l=15;do{s=i*n(a),a+=r=k-2*h(e*u((1-s)/(1+s),o))-a}while(t(r)>1e-10&&--l);return l<=0&&B(-18),a}function gn(t,e){var n,i,s,r=e.length-1;for(i=e[r][0],s=e[r][1];--r>=0;)n=i,i=e[r][0]+t.r*n-t.i*s,s=e[r][1]+t.r*s+t.i*n;return{r:t.r*i-t.i*s,i:t.r*s+t.i*i}}function vn(t,e,n){var i,s,r,o,a,h=!0,l=e.length-1;for(s=o=e[l][0],i=r=e[l][1];--l>=0;)h?h=!1:(o=s+t.r*(a=o)-t.i*r,r=i+t.r*r+t.i*a),s=e[l][0]+t.r*(a=s)-t.i*i,i=e[l][1]+t.r*i+t.i*a;return n.r=s+t.r*o-t.i*r,n.i=i+t.r*r+t.i*o,{r:t.r*s-t.i*i,i:t.r*i+t.i*s}}function xn(e,r){var o,a,c,p,d=1e-12;0!=e.es?(o=e.e*n(e.phi0),a=2*h(s(.5*(k+e.phi0))*u((1-o)/(1+o),.5*e.e))-k):a=e.phi0,p=n(a),c=i(a),e.inv=function(o,a){var f,m,y,g,v,w,b,C={},S={},A={},M=0,E=0,D=0,I=0;for(C.r=o.x,C.i=o.y,f=20;f&&((m=vn(C,r,S)).r-=o.x,m.i-=o.y,y=S.r*S.r+S.i*S.i,A.r=-(m.r*S.r+m.i*S.i)/y,A.i=-(m.i*S.r-m.r*S.i)/y,C.r+=A.r,C.i+=A.i,!(t(A.r)+t(A.i)<=d));--f);if(f){if(M=_(C.r,C.i),g=2*h(.5*M),E=n(g),D=i(g),a.lam=e.lam0,t(M)<=d)return a.lam=0,void(a.phi=e.phi0);for(I=v=Ye(D*p+C.i*E*c/M),f=20;f&&(w=e.e*n(I),I+=b=2*h(s(.5*(k+v))*u((1+w)/(1-w),.5*e.e))-k-I,!(t(b)<=d));--f);}f?(a.phi=I,a.lam=l(C.r*E,M*c*D-C.i*p*E)):a.lam=a.phi=x},e.fwd=function(t,o){var a,l,d,_,f,m,y,g={};a=n(t.lam),l=i(t.lam),d=e.e*n(t.phi),_=2*h(s(.5*(k+t.phi))*u((1-d)/(1+d),.5*e.e))-k,f=n(_),m=i(_),y=2/(1+p*f+c*m*l),g.r=y*m*a,g.i=y*(c*f-p*m*l),g=gn(g,r),o.x=g.r,o.y=g.i}}function wn(e,s,r,a){var h,u,p,d,f,m,y,g,v,x,w,b,C=!isNaN(r)&&!isNaN(a);s<=0&&j(-30),C&&(v=i(a),x=n(a),b=i(r),w=n(r)),t(t(e.phi0)-k)<N?h=e.phi0<0?1:0:t(e.phi0)<N?h=2:(h=3,u=n(e.phi0),p=i(e.phi0)),m=s/e.a,f=1/(d=1+m),y=(d+1)*(g=1/m),e.fwd=function(t,e){var s,r,o,a,l;switch(o=n(t.phi),r=i(t.phi),s=i(t.lam),h){case 3:e.y=u*o+p*r*s;break;case 2:e.y=r*s;break;case 1:e.y=-o;break;case 0:e.y=o}switch(e.y<f&&z(),e.y=m/(d-e.y),e.x=e.y*r*n(t.lam),h){case 3:e.y*=p*o-u*r*s;break;case 2:e.y*=o;break;case 0:s=-s;case 1:e.y*=r*s}C&&(l=1/((a=e.y*v+e.x*x)*w*g+b),e.x=(e.x*v-e.y*x)*b*l,e.y=a*l)},e.inv=function(i,s){var r,a,f,g,S,A;if(C&&(A=1/(m-i.y*w),g=m*i.x*A,S=m*i.y*b*A,i.x=g*v+S*x,i.y=S*v-g*x),r=_(i.x,i.y),(f=1-r*r*y)<0&&U(),f=(d-c(f))/(m/r+r/m),a=c(1-f*f),t(r)<=N)s.lam=0,s.phi=e.phi0;else{switch(h){case 3:s.phi=o(a*u+i.y*f*p/r),i.y=(a-u*n(s.phi))*r,i.x*=f*p;break;case 2:s.phi=o(i.y*f/r),i.y=a*r,i.x*=f;break;case 0:s.phi=o(a),i.y=-i.y;break;case 1:s.phi=-o(a)}s.lam=l(i.x,i.y)}},e.es=0}function bn(t,e){var n=.79788456,i=.1013211836*(e?2:4);t.es=0,t.fwd=function(t,e){e.x=n*t.lam*(1-i*t.phi*t.phi),e.y=n*t.phi},t.inv=function(t,e){e.phi=t.y/n,e.lam=t.x/(n*(1-i*e.phi*e.phi))}}function Cn(t,e,s){t.es=0,t.fwd=function(t,r){t.phi=Ye(.883883476*n(t.phi)),r.x=e*t.lam*i(t.phi),r.x/=i(t.phi*=.333333333333333),r.y=s*n(t.phi)},t.inv=function(t,r){r.phi=Ye(t.y/s),r.lam=t.x*i(r.phi)/e,r.phi*=3,r.lam/=i(r.phi),r.phi=Ye(1.13137085*n(r.phi))}}function Sn(t,e){var n=e?1.5:2,i=e?.5:1,s=1.01346,r=1.2158542;t.es=0,t.fwd=function(t,e){e.x=s*t.lam*(n-i*c(1+r*t.phi*t.phi)),e.y=s*t.phi},t.inv=function(t,e){e.phi=t.y/s,e.lam=t.x/(s*(n-i*c(1+r*e.phi*e.phi)))}}function An(e,i){var s,r,o,a,h,l=1.732050807568877;i?(o=.44329,a=.80404,s=6,r=5.61125,h=3):(o=1.01346,a=.9191,s=4,r=2.147143718212938,h=2),e.es=0,e.fwd=function(e,i){var u,p,_,f;for(u=r*n(e.phi),e.phi*=1.10265779,f=10;f&&(p=c(1+e.phi*e.phi),e.phi-=_=((s-p)*e.phi-d(e.phi+p)-u)/(s-2*p),!(t(_)<1e-10));--f);f||(e.phi=u<0?-l:l),i.x=o*e.lam*(h-c(1+e.phi*e.phi)),i.y=a*e.phi},e.inv=function(t,e){var n;e.phi=t.y/a,n=c(1+e.phi*e.phi),e.lam=t.x/(o*(h-n)),e.phi=Ye(((s-n)*e.phi-d(e.phi+n))/r)}}function Mn(e){return function(r){!function(e,r){var o,a,u,p,d,f,m,y,g,v,x=1e-10;switch(Z(e.params,"tlat_1")&&Z(e.params,"tlat_2")?(u=Z(e.params,"rlat_1"),p=Z(e.params,"rlat_2"),y=.5*(p+u),(t(o=.5*(p-u))<x||t(y)<x)&&j(-42)):j(-41),r){case"TISSOT":d=n(y),a=i(o),m=c(((f=d/a+a/d)-2*n(e.phi0))/d);break;case"MURD1":f=n(o)/(o*s(y))+y,m=f-e.phi0,d=n(y);break;case"MURD2":f=(a=c(i(o)))/s(y),m=f+s(y-e.phi0),d=n(y)*a;break;case"MURD3":f=o/(s(y)*s(o))+y,m=f-e.phi0,d=n(y)*n(o)*s(o)/(o*o);break;case"EULER":d=n(y)*n(o)/o,f=(o*=.5)/(s(o)*s(y))+y,m=f-e.phi0;break;case"PCONIC":d=n(y),v=i(o),g=1/s(y),t(o=e.phi0-y)-x>=k&&j(-43),m=v*(g-s(o));break;case"VITK1":d=(a=s(o))*n(y)/o,f=o/(a*s(y))+y,m=f-e.phi0}function w(t,e){var o;switch(r){case"MURD2":o=f+s(y-t.phi);break;case"PCONIC":o=v*(g-s(t.phi-y));break;default:o=f-t.phi}e.x=o*n(t.lam*=d),e.y=m-o*i(t.lam)}function b(t,e){var n;switch(n=_(t.x,t.y=m-t.y),d<0&&(n=-n,t.x=-t.x,t.y=-t.y),e.lam=l(t.x,t.y)/d,r){case"PCONIC":e.phi=h(g-n/v)+y;break;case"MURD2":e.phi=y-h(n-f);break;default:e.phi=f-n}}e.inv=b,e.fwd=w,e.es=0}(r,e)}}function En(e,r){var a,p,d,f,m,y,g,v,x=1e-10;if(v=t((p=t(e.phi0))-k)<x?e.phi0<0?0:1:p>x?2:3,r=t(r),e.es){switch(v){case 1:case 0:t(r-k)<x?g=2*e.k0/c(u(1+e.e,1+e.e)*u(1-e.e,1-e.e)):(g=i(r)/mn(r,p=n(r),e.e),p*=e.e,g/=c(1-p*p));break;case 3:case 2:p=n(e.phi0),a=2*h(w(e.phi0,p,e.e))-k,p*=e.e,g=2*e.k0*i(e.phi0)/c(1-p*p),m=n(a),y=i(a)}e.fwd=function(t,s){var r,o,a,l,c,u=0,p=0;switch(r=i(t.lam),o=n(t.lam),c=n(t.phi),(2==v||3==v)&&(u=n(a=2*h(w(t.phi,c,e.e))-k),p=i(a)),v){case 2:l=g/(y*(1+m*u+y*p*r)),s.y=l*(y*u-m*p*r),s.x=l*p;break;case 3:l=g/(1+p*r),s.y=l*u,s.x=l*p;break;case 0:t.phi=-t.phi,r=-r,c=-c;case 1:s.x=g*mn(t.phi,c,e.e),s.y=-s.x*r}s.x=s.x*o},e.inv=function(r,a){a.phi;var c,p,d,f,x=0,w=0,b=0,C=0;switch(d=_(r.x,r.y),v){case 2:case 3:c=i(x=2*l(d*y,g)),p=n(x),w=o(0==d?c*m:c*m+r.y*p*y/d),x=s(.5*(k+w)),r.x*=p,r.y=d*y*c-r.y*m*p,C=k,b=.5*e.e;break;case 1:r.y=-r.y;case 0:w=k-2*h(x=-d/g),C=-k,b=-.5*e.e}for(f=0;f<8;f++,w=a.phi)if(p=e.e*n(w),a.phi=2*h(x*u((1+p)/(1-p),b))-C,t(w-a.phi)<1e-10)return 0==v&&(a.phi=-a.phi),void(a.lam=0==r.x&&0==r.y?0:l(r.x,r.y));U()}}else{switch(v){case 2:d=n(e.phi0),f=i(e.phi0);case 3:g=2*e.k0;break;case 0:case 1:g=t(r-k)>=x?i(r)/s(E-.5*r):2*e.k0}e.fwd=function(e,r){var o=e.phi,a=n(o),h=i(o),l=i(e.lam),c=n(e.lam);switch(v){case 3:case 2:r.y=3==v?1+h*l:1+d*a+f*h*l,r.y<=x&&z(),r.x=(r.y=g/r.y)*h*c,r.y*=3==v?a:f*a-d*h*l;break;case 1:l=-l,o=-o;case 0:t(o-k)<1e-8&&z(),r.x=c*(r.y=g*s(E+.5*o)),r.y*=l}},e.inv=function(s,r){var a,c,u,p;switch(u=n(a=2*h((c=_(s.x,s.y))/g)),p=i(a),r.lam=0,v){case 3:t(c)<=x?r.phi=0:r.phi=o(s.y*u/c),0==p&&0==s.x||(r.lam=l(s.x*u,p*c));break;case 2:t(c)<=x?r.phi=e.phi0:r.phi=o(p*d+s.y*u*f/c),0==(a=p-d*n(r.phi))&&0==s.x||(r.lam=l(s.x*u*f,a*c));break;case 1:s.y=-s.y;case 0:t(c)<=x?r.phi=e.phi0:r.phi=o(0==v?-p:p),r.lam=0==s.x&&0==s.y?0:l(s.x,s.y)}}}function w(t,e,n){return e*=n,s(.5*(k+t))*u((1-e)/(1+e),.5*n)}}function kn(t,e){return u((1-t)/(1+t),e)}function Dn(t,e,r,o){var a=r/e,l=e,c=1/r;t.inv=function(t,e){var n;t.y/=l,n=i(e.phi=o?h(t.y):Ye(t.y)),e.phi/=c,e.lam=t.x/(a*i(e.phi)),o?e.lam/=n*n:e.lam*=n},t.fwd=function(t,e){var r;e.x=a*t.lam*i(t.phi),e.y=l,t.phi*=c,r=i(t.phi),o?(e.x*=r*r,e.y*=s(t.phi)):(e.x/=r,e.y*=n(t.phi))},t.es=0}function In(e){var s,r,h,u=1e-10,_=.5,f=.16666666666666666,m=.08333333333333333,y=.05,g=.03333333333333333,v=.023809523809523808,x=.017857142857142856;e.es?((h=Xe(e.es))||e_error_0(),r=Ze(e.phi0,n(e.phi0),i(e.phi0),h),s=e.es/(1-e.es),e.fwd=function(o,a){var l,p,d,_,w,b;o.lam<-k||o.lam>k?B(-14):(l=n(o.phi),p=i(o.phi),d=t(p)>u?l/p:0,d*=d,_=p*o.lam,w=_*_,_/=c(1-e.es*l*l),b=s*p*p,a.x=e.k0*_*(1+f*w*(1-d+b+y*w*(5+d*(d-18)+b*(14-58*d)+v*w*(61+d*(d*(179-d)-479))))),a.y=e.k0*(Ze(o.phi,l,p,h)-r+l*_*o.lam*.5*(1+m*w*(5-d+b*(9+4*b)+g*w*(61+d*(d-58)+b*(270-330*d)+x*w*(1385+d*(d*(543-d)-3111)))))))},e.inv=function(o,a){var l,u,p,d,w,b,C;a.phi=Je(r+o.y/e.k0,e.es,h),t(a.phi)>=k?(a.phi=o.y<0?-k:k,a.lam=0):(b=n(a.phi),p=i(a.phi),C=t(p)>1e-10?b/p:0,l=s*p*p,d=o.x*c(u=1-e.es*b*b)/e.k0,u*=C,C*=C,w=d*d,a.phi-=u*w/(1-e.es)*_*(1-w*m*(5+C*(3-9*l)+l*(1-4*l)-w*g*(61+C*(90-252*l+45*C)+46*l-w*x*(1385+C*(3633+C*(4095+1575*C)))))),a.lam=d*(1-w*f*(1+2*C+l-w*y*(5+C*(28+24*C+8*l)+6*l-w*v*(61+C*(662+C*(1320+720*C))))))/p)}):(s=e.k0,r=.5*s,e.fwd=function(o,h){var l,p;o.lam<-k||o.lam>k?B(-14):(p=i(o.phi),l=p*n(o.lam),t(t(l)-1)<=u&&z(),h.x=r*d((1+l)/(1-l)),h.y=p*i(o.lam)/c(1-l*l),(l=t(h.y))>=1?l-1>u?z():h.y=0:h.y=a(h.y),o.phi<0&&(h.y=-h.y),h.y=s*(h.y-e.phi0))},e.inv=function(t,n){var r=p(t.x/s),a=.5*(r-1/r);r=i(e.phi0+t.y/s),n.phi=o(c((1-r*r)/(1+a*a))),t.y<0&&-n.phi+e.phi0<0&&(n.phi=-n.phi),n.lam=a||r?l(a,r):0})}function Pn(t,e){var s=.8773826753,r=1.139753528477/e;t.es=0,t.fwd=function(t,o){var a=Ye(e*n(t.phi));o.x=s*t.lam*i(a),o.y=r*a},t.inv=function(t,o){t.y/=r,o.phi=Ye(n(t.y)/e),o.lam=t.x/(s*i(t.y))}}function Tn(e,n){e.fwd=function(e,i){var s,r,o,a;o=t(P*e.phi),a=(a=1-o*o)<0?0:c(a),t(e.lam)<1e-10?(i.x=0,i.y=b*(e.phi<0?-o:o)/(1+a)):(r=.5*t(b/e.lam-e.lam/b),n?(s=o/(1+a),i.x=b*(c(r*r+1-s*s)-r),i.y=b*s):(s=(a*c(1+r*r)-r*a*a)/(1+r*r*o*o),i.x=b*s,i.y=b*c(1-s*(s+2*r)+1e-10)),e.lam<0&&(i.x=-i.x),e.phi<0&&(i.y=-i.y))},e.es=0}Ve.Constants={},Ve.Math={},Ve.Accumulator={},(je=Ve.Constants).WGS84={a:6378137,f:1/298.257223563},je.version={major:1,minor:48,patch:0},je.version_string="1.48",($e=Ve.Math).digits=53,$e.epsilon=Math.pow(.5,$e.digits-1),$e.degree=Math.PI/180,$e.sq=function(t){return t*t},$e.hypot=function(t,e){var n,i;return t=Math.abs(t),e=Math.abs(e),n=Math.max(t,e),i=Math.min(t,e)/(n||1),n*Math.sqrt(1+i*i)},$e.cbrt=function(t){var e=Math.pow(Math.abs(t),1/3);return t<0?-e:e},$e.log1p=function(t){var e=1+t,n=e-1;return 0===n?t:t*Math.log(e)/n},$e.atanh=function(t){var e=Math.abs(t);return e=$e.log1p(2*e/(1-e))/2,t<0?-e:e},$e.copysign=function(t,e){return Math.abs(t)*(e<0||0===e&&1/e<0?-1:1)},$e.sum=function(t,e){var n=t+e,i=n-e,s=n-i;return{s:n,t:-((i-=t)+(s-=e))}},$e.polyval=function(t,e,n,i){for(var s=t<0?0:e[n++];--t>=0;)s=s*i+e[n++];return s},$e.AngRound=function(t){if(0===t)return t;var e=1/16,n=Math.abs(t);return n=n<e?e-(e-n):n,t<0?-n:n},$e.AngNormalize=function(t){return(t%=360)<=-180?t+360:t<=180?t:t-360},$e.LatFix=function(t){return Math.abs(t)>90?Number.NaN:t},$e.AngDiff=function(t,e){var n=$e.sum($e.AngNormalize(-t),$e.AngNormalize(e)),i=$e.AngNormalize(n.s),s=n.t;return $e.sum(180===i&&s>0?-180:i,s)},$e.sincosd=function(t){var e,n,i,s,r,o;switch(e=t%360,e-=90*(n=Math.floor(e/90+.5)),e*=this.degree,i=Math.sin(e),s=Math.cos(e),3&n){case 0:r=i,o=s;break;case 1:r=s,o=-i;break;case 2:r=-i,o=-s;break;default:r=-s,o=i}return t&&(r+=0,o+=0),{s:r,c:o}},$e.atan2d=function(t,e){var n,i,s=0;switch(Math.abs(t)>Math.abs(e)&&(n=e,e=t,t=n,s=2),e<0&&(e=-e,++s),i=Math.atan2(t,e)/this.degree,s){case 1:i=(t>=0?180:-180)-i;break;case 2:i=90-i;break;case 3:i=-90+i}return i},function(t,e){t.Accumulator=function(t){this.Set(t)},t.Accumulator.prototype.Set=function(e){e||(e=0),e.constructor===t.Accumulator?(this._s=e._s,this._t=e._t):(this._s=e,this._t=0)},t.Accumulator.prototype.Add=function(t){var n=e.sum(t,this._t),i=e.sum(n.s,this._s);n=n.t,this._s=i.s,this._t=i.t,0===this._s?this._s=n:this._t+=n},t.Accumulator.prototype.Sum=function(e){var n;return e?((n=new t.Accumulator(this)).Add(e),n._s):this._s},t.Accumulator.prototype.Negate=function(){this._s*=-1,this._t*=-1}}(Ve.Accumulator,Ve.Math),Ve.Geodesic={},Ve.GeodesicLine={},Ve.PolygonArea={},function(t,e,n,i,s){var r,o,a,h,l,c,u,p,d,_,f,m=20+i.digits+10,y=i.epsilon,g=200*y,v=Math.sqrt(y),x=y*g,w=1e3*v;t.tiny_=Math.sqrt(Number.MIN_VALUE),t.nC1_=6,t.nC1p_=6,t.nC2_=6,t.nC3_=6,t.nC4_=6,r=t.nC3_*(t.nC3_-1)/2,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,n,i){var s=i.length,r=s-(t?1:0),o=2*(n-e)*(n+e),a=1&r?i[--s]:0,h=0;for(r=Math.floor(r/2);r--;)a=o*(h=o*a-h+i[--s])-a+i[--s];return t?2*e*n*a:n*(a-h)},a=function(t,e){var n,s,r,o,a,h,l,c,u,p,d,_,f=i.sq(t),m=i.sq(e),y=(f+m-1)/6;return 0===m&&y<=0?n=0:(h=y,(a=(s=f*m/4)*(s+2*(o=y*(r=i.sq(y)))))>=0?(l=s+o,l+=l<0?-Math.sqrt(a):Math.sqrt(a),h+=(c=i.cbrt(l))+(0!==c?r/c:0)):(u=Math.atan2(Math.sqrt(-a),-(s+o)),h+=2*y*Math.cos(u/3)),p=Math.sqrt(i.sq(h)+m),_=((d=h<0?m/(p-h):h+p)-m)/(2*p),n=d/(Math.sqrt(d+i.sq(_))+_)),n},h=[1,4,64,0,256],t.A1m1f=function(t){var e=Math.floor(3);return(i.polyval(e,h,0,i.sq(t))/h[e+1]+t)/(1-t)},l=[-1,6,-16,32,-9,64,-128,2048,9,-16,768,3,-5,512,-7,1280,-7,2048],t.C1f=function(e,n){var s,r,o=i.sq(e),a=e,h=0;for(s=1;s<=t.nC1_;++s)r=Math.floor((t.nC1_-s)/2),n[s]=a*i.polyval(r,l,h,o)/l[h+r+1],h+=r+2,a*=e},c=[205,-432,768,1536,4005,-4736,3840,12288,-225,116,384,-7173,2695,7680,3467,7680,38081,61440],t.C1pf=function(e,n){var s,r,o=i.sq(e),a=e,h=0;for(s=1;s<=t.nC1p_;++s)r=Math.floor((t.nC1p_-s)/2),n[s]=a*i.polyval(r,c,h,o)/c[h+r+1],h+=r+2,a*=e},u=[-11,-28,-192,0,256],t.A2m1f=function(t){var e=Math.floor(3);return(i.polyval(e,u,0,i.sq(t))/u[e+1]-t)/(1+t)},p=[1,2,16,32,35,64,384,2048,15,80,768,7,35,512,63,1280,77,2048],t.C2f=function(e,n){var s,r,o=i.sq(e),a=e,h=0;for(s=1;s<=t.nC2_;++s)r=Math.floor((t.nC2_-s)/2),n[s]=a*i.polyval(r,p,h,o)/p[h+r+1],h+=r+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/i.sq(this._f1),this._n=this.f/(2-this.f),this._b=this.a*this._f1,this._c2=(i.sq(this.a)+i.sq(this._b)*(0===this._e2?1:(this._e2>0?i.atanh(Math.sqrt(this._e2)):Math.atan(Math.sqrt(-this._e2)))/Math.sqrt(Math.abs(this._e2))))/2,this._etol2=.1*v/Math.sqrt(Math.max(.001,Math.abs(this.f))*Math.min(1,1-this.f/2)/2),!(isFinite(this.a)&&this.a>0))throw new Error("Equatorial radius is not positive");if(!(isFinite(this._b)&&this._b>0))throw new Error("Polar semi-axis is not positive");this._A3x=new Array(6),this._C3x=new Array(r),this._C4x=new Array(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,n=0,s=0;for(t=5;t>=0;--t)e=Math.min(6-t-1,t),this._A3x[s++]=i.polyval(e,d,n,this._n)/d[n+e+1],n+=e+2},_=[3,128,2,5,128,-1,3,3,64,-1,0,1,8,-1,1,4,5,256,1,3,128,-3,-2,3,64,1,-3,2,32,7,512,-10,9,384,5,-9,5,192,7,512,-14,7,512,21,2560],t.Geodesic.prototype.C3coeff=function(){var e,n,s,r=0,o=0;for(e=1;e<t.nC3_;++e)for(n=t.nC3_-1;n>=e;--n)s=Math.min(t.nC3_-n-1,n),this._C3x[o++]=i.polyval(s,_,r,this._n)/_[r+s+1],r+=s+2},f=[97,15015,1088,156,45045,-224,-4784,1573,45045,-10656,14144,-4576,-858,45045,64,624,-4576,6864,-3003,15015,100,208,572,3432,-12012,30030,45045,1,9009,-2944,468,135135,5792,1040,-1287,135135,5952,-11648,9152,-2574,135135,-64,-624,4576,-6864,3003,135135,8,10725,1856,-936,225225,-8448,4992,-1144,225225,-1440,4160,-4576,1716,225225,-136,63063,1024,-208,105105,3584,-3328,1144,315315,-128,135135,-2560,832,405405,128,99099],t.Geodesic.prototype.C4coeff=function(){var e,n,s,r=0,o=0;for(e=0;e<t.nC4_;++e)for(n=t.nC4_-1;n>=e;--n)s=t.nC4_-n-1,this._C4x[o++]=i.polyval(s,f,r,this._n)/f[r+s+1],r+=s+2},t.Geodesic.prototype.A3f=function(t){return i.polyval(5,this._A3x,0,t)},t.Geodesic.prototype.C3f=function(e,n){var s,r,o=1,a=0;for(s=1;s<t.nC3_;++s)r=t.nC3_-s-1,o*=e,n[s]=o*i.polyval(r,this._C3x,a,e),a+=r+1},t.Geodesic.prototype.C4f=function(e,n){var s,r,o=1,a=0;for(s=0;s<t.nC4_;++s)r=t.nC4_-s-1,n[s]=o*i.polyval(r,this._C4x,a,e),a+=r+1,o*=e},t.Geodesic.prototype.Lengths=function(e,n,i,s,r,o,a,h,l,c,u,p,d){var _,f,m,y,g={},v=0,x=0,w=0,b=0;if((u&=t.OUT_MASK)&(t.DISTANCE|t.REDUCEDLENGTH|t.GEODESICSCALE)&&(w=t.A1m1f(e),t.C1f(e,p),u&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(b=t.A2m1f(e),t.C2f(e,d),v=w-b,b=1+b),w=1+w),u&t.DISTANCE)_=t.SinCosSeries(!0,o,a,p)-t.SinCosSeries(!0,i,s,p),g.s12b=w*(n+_),u&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(x=v*n+(w*_-b*(t.SinCosSeries(!0,o,a,d)-t.SinCosSeries(!0,i,s,d))));else if(u&(t.REDUCEDLENGTH|t.GEODESICSCALE)){for(f=1;f<=t.nC2_;++f)d[f]=w*p[f]-b*d[f];x=v*n+(t.SinCosSeries(!0,o,a,d)-t.SinCosSeries(!0,i,s,d))}return u&t.REDUCEDLENGTH&&(g.m0=v,g.m12b=h*(s*o)-r*(i*a)-s*a*x),u&t.GEODESICSCALE&&(m=s*a+i*o,y=this._ep2*(l-c)*(l+c)/(r+h),g.M12=m+(y*o-a*x)*i/r,g.M21=m-(y*i-s*x)*o/h),g},t.Geodesic.prototype.InverseStart=function(e,n,s,r,o,h,l,c,u,p,d){var _,f,m,y,v,x,b,C,S,A,M,E,k,D,I,P,T,L,N,R,F={},G=r*n-o*e,O=o*n+r*e;return F.sig12=-1,_=r*n,_+=o*e,(f=O>=0&&G<.5&&o*l<.5)?(y=i.sq(e+r),y/=y+i.sq(n+o),F.dnm=Math.sqrt(1+this._ep2*y),m=l/(this._f1*F.dnm),v=Math.sin(m),x=Math.cos(m)):(v=c,x=u),F.salp1=o*v,F.calp1=x>=0?G+o*e*i.sq(v)/(1+x):_-o*e*i.sq(v)/(1-x),C=i.hypot(F.salp1,F.calp1),S=e*r+n*o*x,f&&C<this._etol2?(F.salp2=n*v,F.calp2=G-n*r*(x>=0?i.sq(v)/(1+x):1-x),b=i.hypot(F.salp2,F.calp2),F.salp2/=b,F.calp2/=b,F.sig12=Math.atan2(C,S)):Math.abs(this._n)>.1||S>=0||C>=6*Math.abs(this._n)*Math.PI*i.sq(n)||(R=Math.atan2(-c,-u),this.f>=0?(D=(k=i.sq(e)*this._ep2)/(2*(1+Math.sqrt(1+k))+k),A=R/(E=this.f*n*this.A3f(D)*Math.PI),M=_/(E*n)):(I=o*n-r*e,P=Math.atan2(_,I),M=l/(E=((A=(T=this.Lengths(this._n,Math.PI+P,e,-n,s,r,o,h,n,o,t.REDUCEDLENGTH,p,d)).m12b/(n*o*T.m0*Math.PI)-1)<-.01?_/A:-this.f*i.sq(n)*Math.PI)/n)),M>-g&&A>-1-w?this.f>=0?(F.salp1=Math.min(1,-A),F.calp1=-Math.sqrt(1-i.sq(F.salp1))):(F.calp1=Math.max(A>-g?0:-1,A),F.salp1=Math.sqrt(1-i.sq(F.calp1))):(L=a(A,M),N=E*(this.f>=0?-A*L/(1+L):-M*(1+L)/L),v=Math.sin(N),x=-Math.cos(N),F.salp1=o*v,F.calp1=_-o*e*i.sq(v)/(1-x))),F.salp1<=0?(F.salp1=1,F.calp1=0):(b=i.hypot(F.salp1,F.calp1),F.salp1/=b,F.calp1/=b),F},t.Geodesic.prototype.Lambda12=function(e,n,s,r,o,a,h,l,c,u,p,d,_,f){var m,y,g,v,x,w,b,C,S,A,M,E,k,D={};return 0===e&&0===l&&(l=-t.tiny_),y=h*n,g=i.hypot(l,h*e),D.ssig1=e,v=y*e,D.csig1=x=l*n,m=i.hypot(D.ssig1,D.csig1),D.ssig1/=m,D.csig1/=m,D.salp2=o!==n?y/o:h,D.calp2=o!==n||Math.abs(r)!==-e?Math.sqrt(i.sq(l*n)+(n<-e?(o-n)*(n+o):(e-r)*(e+r)))/o:Math.abs(l),D.ssig2=r,w=y*r,D.csig2=b=D.calp2*o,m=i.hypot(D.ssig2,D.csig2),D.ssig2/=m,D.csig2/=m,D.sig12=Math.atan2(Math.max(0,D.csig1*D.ssig2-D.ssig1*D.csig2),D.csig1*D.csig2+D.ssig1*D.ssig2),C=Math.max(0,x*w-v*b),S=x*b+v*w,M=Math.atan2(C*u-S*c,S*u+C*c),E=i.sq(g)*this._ep2,D.eps=E/(2*(1+Math.sqrt(1+E))+E),this.C3f(D.eps,f),A=t.SinCosSeries(!0,D.ssig2,D.csig2,f)-t.SinCosSeries(!0,D.ssig1,D.csig1,f),D.domg12=-this.f*this.A3f(D.eps)*y*(D.sig12+A),D.lam12=M+D.domg12,p&&(0===D.calp2?D.dlam12=-2*this._f1*s/e:(k=this.Lengths(D.eps,D.sig12,D.ssig1,D.csig1,s,D.ssig2,D.csig2,a,n,o,t.REDUCEDLENGTH,d,_),D.dlam12=k.m12b,D.dlam12*=this._f1/(D.calp2*o))),D},t.Geodesic.prototype.Inverse=function(e,n,s,r,o){var a,h;return o||(o=t.STANDARD),o===t.LONG_UNROLL&&(o|=t.STANDARD),o&=t.OUT_MASK,h=(a=this.InverseInt(e,n,s,r,o)).vals,o&t.AZIMUTH&&(h.azi1=i.atan2d(a.salp1,a.calp1),h.azi2=i.atan2d(a.salp2,a.calp2)),h},t.Geodesic.prototype.InverseInt=function(e,n,s,r,o){var a,h,l,c,u,p,d,_,f,g,v,w,b,C,S,A,M,E,k,D,I,P,T,L,N,R,F,G,O,B,z,U,q,j,$,V,H,W,K,X,Z,J,Y,Q,tt,et,nt,it,st,rt,ot,at,ht,lt,ct,ut,pt,dt,_t,ft,mt,yt,gt,vt,xt,wt={};if(wt.lat1=e=i.LatFix(e),wt.lat2=s=i.LatFix(s),e=i.AngRound(e),s=i.AngRound(s),h=(a=i.AngDiff(n,r)).t,a=a.s,o&t.LONG_UNROLL?(wt.lon1=n,wt.lon2=n+a+h):(wt.lon1=i.AngNormalize(n),wt.lon2=i.AngNormalize(r)),a=(l=a>=0?1:-1)*i.AngRound(a),h=i.AngRound(180-a-l*h),S=a*i.degree,A=(c=i.sincosd(a>90?h:a)).s,M=(a>90?-1:1)*c.c,(u=Math.abs(e)<Math.abs(s)?-1:1)<0&&(l*=-1,c=e,e=s,s=c),e*=p=e<0?1:-1,s*=p,c=i.sincosd(e),d=this._f1*c.s,_=c.c,d/=c=i.hypot(d,_),_/=c,_=Math.max(t.tiny_,_),c=i.sincosd(s),f=this._f1*c.s,g=c.c,f/=c=i.hypot(f,g),g/=c,g=Math.max(t.tiny_,g),_<-d?g===_&&(f=f<0?d:-d):Math.abs(f)===-d&&(g=_),b=Math.sqrt(1+this._ep2*i.sq(d)),C=Math.sqrt(1+this._ep2*i.sq(f)),T=new Array(t.nC1_+1),L=new Array(t.nC2_+1),N=new Array(t.nC3_),(R=-90===e||0===A)&&(D=A,P=0,G=d,O=(k=M)*_,B=f,z=(I=1)*g,E=Math.atan2(Math.max(0,O*B-G*z),O*z+G*B),v=(F=this.Lengths(this._n,E,G,O,b,B,z,C,_,g,o|t.DISTANCE|t.REDUCEDLENGTH,T,L)).s12b,w=F.m12b,0!==(o&t.GEODESICSCALE)&&(wt.M12=F.M12,wt.M21=F.M21),E<1||w>=0?(E<3*t.tiny_&&(E=w=v=0),w*=this._b,v*=this._b,wt.a12=E/i.degree):R=!1),pt=2,!R&&0===d&&(this.f<=0||h>=180*this.f))k=I=0,D=P=1,v=this.a*S,E=q=S/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(!R)if(E=(F=this.InverseStart(d,_,b,f,g,C,S,A,M,T,L)).sig12,D=F.salp1,k=F.calp1,E>=0)P=F.salp2,I=F.calp2,j=F.dnm,v=E*this._b*j,w=i.sq(j)*this._b*Math.sin(E/j),o&t.GEODESICSCALE&&(wt.M12=wt.M21=Math.cos(E/j)),wt.a12=E/i.degree,q=S/(this._f1*j);else{for($=0,V=t.tiny_,H=1,W=t.tiny_,K=-1,X=!1,Z=!1;$<m&&(J=(F=this.Lambda12(d,_,b,f,g,C,D,k,A,M,$<20,T,L,N)).lam12,P=F.salp2,I=F.calp2,E=F.sig12,G=F.ssig1,O=F.csig1,B=F.ssig2,z=F.csig2,U=F.eps,_t=F.domg12,Y=F.dlam12,!Z&&Math.abs(J)>=(X?8:1)*y);++$)J>0&&($<20||k/D>K/W)?(W=D,K=k):J<0&&($<20||k/D<H/V)&&(V=D,H=k),$<20&&Y>0&&(Q=-J/Y,tt=Math.sin(Q),(nt=D*(et=Math.cos(Q))+k*tt)>0&&Math.abs(Q)<Math.PI)?(k=k*et-D*tt,D=nt,D/=c=i.hypot(D,k),k/=c,X=Math.abs(J)<=16*y):(D=(V+W)/2,k=(H+K)/2,D/=c=i.hypot(D,k),k/=c,X=!1,Z=Math.abs(V-D)+(H-k)<x||Math.abs(D-W)+(k-K)<x);it=o|(o&(t.REDUCEDLENGTH|t.GEODESICSCALE)?t.DISTANCE:t.NONE),v=(F=this.Lengths(U,E,G,O,b,B,z,C,_,g,it,T,L)).s12b,w=F.m12b,0!==(o&t.GEODESICSCALE)&&(wt.M12=F.M12,wt.M21=F.M21),w*=this._b,v*=this._b,wt.a12=E/i.degree,o&t.AREA&&(vt=Math.sin(_t),pt=A*(xt=Math.cos(_t))-M*vt,dt=M*xt+A*vt)}return o&t.DISTANCE&&(wt.s12=0+v),o&t.REDUCEDLENGTH&&(wt.m12=0+w),o&t.AREA&&(st=D*_,0!==(rt=i.hypot(k,D*d))&&0!==st?(G=d,O=k*_,B=f,z=I*g,U=(at=i.sq(rt)*this._ep2)/(2*(1+Math.sqrt(1+at))+at),ht=i.sq(this.a)*rt*st*this._e2,G/=c=i.hypot(G,O),O/=c,B/=c=i.hypot(B,z),z/=c,lt=new Array(t.nC4_),this.C4f(U,lt),ct=t.SinCosSeries(!1,G,O,lt),ut=t.SinCosSeries(!1,B,z,lt),wt.S12=ht*(ut-ct)):wt.S12=0,!R&&pt>1&&(pt=Math.sin(q),dt=Math.cos(q)),!R&&dt>-.7071&&f-d<1.75?(_t=1+dt,ft=1+_,mt=1+g,ot=2*Math.atan2(pt*(d*mt+f*ft),_t*(d*f+ft*mt))):(gt=I*k+P*D,0===(yt=P*k-I*D)&><0&&(yt=t.tiny_*k,gt=-1),ot=Math.atan2(yt,gt)),wt.S12+=this._c2*ot,wt.S12*=u*l*p,wt.S12+=0),u<0&&(c=D,D=P,P=c,c=k,k=I,I=c,o&t.GEODESICSCALE&&(c=wt.M12,wt.M12=wt.M21,wt.M21=c)),{vals:wt,salp1:D*=u*l,calp1:k*=u*p,salp2:P*=u*l,calp2:I*=u*p}},t.Geodesic.prototype.GenDirect=function(n,i,s,r,o,a){return a?a===t.LONG_UNROLL&&(a|=t.STANDARD):a=t.STANDARD,r||(a|=t.DISTANCE_IN),new e.GeodesicLine(this,n,i,s,a).GenPosition(r,o,a)},t.Geodesic.prototype.Direct=function(t,e,n,i,s){return this.GenDirect(t,e,n,!1,i,s)},t.Geodesic.prototype.ArcDirect=function(t,e,n,i,s){return this.GenDirect(t,e,n,!0,i,s)},t.Geodesic.prototype.Line=function(t,n,i,s){return new e.GeodesicLine(this,t,n,i,s)},t.Geodesic.prototype.DirectLine=function(t,e,n,i,s){return this.GenDirectLine(t,e,n,!1,i,s)},t.Geodesic.prototype.ArcDirectLine=function(t,e,n,i,s){return this.GenDirectLine(t,e,n,!0,i,s)},t.Geodesic.prototype.GenDirectLine=function(n,i,s,r,o,a){var h;return a||(a=t.STANDARD|t.DISTANCE_IN),r||(a|=t.DISTANCE_IN),(h=new e.GeodesicLine(this,n,i,s,a)).GenSetDistance(r,o),h},t.Geodesic.prototype.InverseLine=function(n,s,r,o,a){var h,l,c;return a||(a=t.STANDARD|t.DISTANCE_IN),h=this.InverseInt(n,s,r,o,t.ARC),c=i.atan2d(h.salp1,h.calp1),a&t.OUT_MASK&t.DISTANCE_IN&&(a|=t.DISTANCE),(l=new e.GeodesicLine(this,n,s,c,a,h.salp1,h.calp1)).SetArc(h.vals.a12),l},t.Geodesic.prototype.Polygon=function(t){return new n.PolygonArea(this,t)},t.WGS84=new t.Geodesic(s.WGS84.a,s.WGS84.f)}(Ve.Geodesic,Ve.GeodesicLine,Ve.PolygonArea,Ve.Math,Ve.Constants),function(t,e,n){e.GeodesicLine=function(e,i,s,r,o,a,h){var l,c,u,p,d,_;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=n.LatFix(i),this.lon1=s,void 0===a||void 0===h?(this.azi1=n.AngNormalize(r),l=n.sincosd(n.AngRound(this.azi1)),this.salp1=l.s,this.calp1=l.c):(this.azi1=r,this.salp1=a,this.calp1=h),l=n.sincosd(n.AngRound(this.lat1)),u=this._f1*l.s,c=l.c,u/=l=n.hypot(u,c),c/=l,c=Math.max(t.tiny_,c),this._dn1=Math.sqrt(1+e._ep2*n.sq(u)),this._salp0=this.salp1*c,this._calp0=n.hypot(this.calp1,this.salp1*u),this._ssig1=u,this._somg1=this._salp0*u,this._csig1=this._comg1=0!==u||0!==this.calp1?c*this.calp1:1,l=n.hypot(this._ssig1,this._csig1),this._ssig1/=l,this._csig1/=l,this._k2=n.sq(this._calp0)*e._ep2,p=this._k2/(2*(1+Math.sqrt(1+this._k2))+this._k2),this.caps&t.CAP_C1&&(this._A1m1=t.A1m1f(p),this._C1a=new Array(t.nC1_+1),t.C1f(p,this._C1a),this._B11=t.SinCosSeries(!0,this._ssig1,this._csig1,this._C1a),d=Math.sin(this._B11),_=Math.cos(this._B11),this._stau1=this._ssig1*_+this._csig1*d,this._ctau1=this._csig1*_-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=n.sq(this.a)*this._calp0*this._salp0*e._e2,this._B41=t.SinCosSeries(!1,this._ssig1,this._csig1,this._C4a)),this.a13=this.s13=Number.NaN},e.GeodesicLine.prototype.GenPosition=function(e,i,s){var r,o,a,h,l,c,u,p,d,_,f,m,y,g,v,x,w,b,C,S,A,M,E,k,D,I,P={};return s?s===t.LONG_UNROLL&&(s|=t.STANDARD):s=t.STANDARD,s&=this.caps&t.OUT_MASK,P.lat1=this.lat1,P.azi1=this.azi1,P.lon1=s&t.LONG_UNROLL?this.lon1:n.AngNormalize(this.lon1),e?P.a12=i:P.s12=i,e||this.caps&t.DISTANCE_IN&t.OUT_MASK?(h=0,l=0,e?(r=i*n.degree,o=(E=n.sincosd(i)).s,a=E.c):(p=i/(this._b*(1+this._A1m1)),d=Math.sin(p),_=Math.cos(p),r=p-((h=-t.SinCosSeries(!0,this._stau1*_+this._ctau1*d,this._ctau1*_-this._stau1*d,this._C1pa))-this._B11),o=Math.sin(r),a=Math.cos(r),Math.abs(this.f)>.01&&(c=this._ssig1*a+this._csig1*o,u=this._csig1*a-this._ssig1*o,h=t.SinCosSeries(!0,c,u,this._C1a),r-=((1+this._A1m1)*(r+(h-this._B11))-i/this._b)/Math.sqrt(1+this._k2*n.sq(c)),o=Math.sin(r),a=Math.cos(r))),c=this._ssig1*a+this._csig1*o,u=this._csig1*a-this._ssig1*o,C=Math.sqrt(1+this._k2*n.sq(c)),s&(t.DISTANCE|t.REDUCEDLENGTH|t.GEODESICSCALE)&&((e||Math.abs(this.f)>.01)&&(h=t.SinCosSeries(!0,c,u,this._C1a)),l=(1+this._A1m1)*(h-this._B11)),y=this._calp0*c,0===(g=n.hypot(this._salp0,this._calp0*u))&&(g=u=t.tiny_),w=this._salp0,b=this._calp0*u,e&&s&t.DISTANCE&&(P.s12=this._b*((1+this._A1m1)*r+l)),s&t.LONGITUDE&&(v=this._salp0*c,x=u,m=n.copysign(1,this._salp0),f=((s&t.LONG_UNROLL?m*(r-(Math.atan2(c,u)-Math.atan2(this._ssig1,this._csig1))+(Math.atan2(m*v,x)-Math.atan2(m*this._somg1,this._comg1))):Math.atan2(v*this._comg1-x*this._somg1,x*this._comg1+v*this._somg1))+this._A3c*(r+(t.SinCosSeries(!0,c,u,this._C3a)-this._B31)))/n.degree,P.lon2=s&t.LONG_UNROLL?this.lon1+f:n.AngNormalize(n.AngNormalize(this.lon1)+n.AngNormalize(f))),s&t.LATITUDE&&(P.lat2=n.atan2d(y,this._f1*g)),s&t.AZIMUTH&&(P.azi2=n.atan2d(w,b)),s&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(S=t.SinCosSeries(!0,c,u,this._C2a),A=(1+this._A2m1)*(S-this._B21),M=(this._A1m1-this._A2m1)*r+(l-A),s&t.REDUCEDLENGTH&&(P.m12=this._b*(C*(this._csig1*c)-this._dn1*(this._ssig1*u)-this._csig1*u*M)),s&t.GEODESICSCALE&&(E=this._k2*(c-this._ssig1)*(c+this._ssig1)/(this._dn1+C),P.M12=a+(E*c-u*M)*this._ssig1/this._dn1,P.M21=a-(E*this._ssig1-this._csig1*M)*c/C)),s&t.AREA&&(k=t.SinCosSeries(!1,c,u,this._C4a),0===this._calp0||0===this._salp0?(D=w*this.calp1-b*this.salp1,I=b*this.calp1+w*this.salp1):(D=this._calp0*this._salp0*(a<=0?this._csig1*(1-a)+o*this._ssig1:o*(this._csig1*o/(1+a)+this._ssig1)),I=n.sq(this._salp0)+n.sq(this._calp0)*this._csig1*u),P.S12=this._c2*Math.atan2(D,I)+this._A4*(k-this._B41)),e||(P.a12=r/n.degree),P):(P.a12=Number.NaN,P)},e.GeodesicLine.prototype.Position=function(t,e){return this.GenPosition(!1,t,e)},e.GeodesicLine.prototype.ArcPosition=function(t,e){return this.GenPosition(!0,t,e)},e.GeodesicLine.prototype.GenSetDistance=function(t,e){t?this.SetArc(e):this.SetDistance(e)},e.GeodesicLine.prototype.SetDistance=function(e){var n;this.s13=e,n=this.GenPosition(!1,this.s13,t.ARC),this.a13=0+n.a12},e.GeodesicLine.prototype.SetArc=function(e){var n;this.a13=e,n=this.GenPosition(!0,this.a13,t.DISTANCE),this.s13=0+n.s12}}(Ve.Geodesic,Ve.GeodesicLine,Ve.Math),function(t,e,n,i){var s,r;s=function(t,e){var i;return t=n.AngNormalize(t),e=n.AngNormalize(e),i=n.AngDiff(t,e).s,t<=0&&e>0&&i>0?1:e<=0&&t>0&&i<0?-1:0},r=function(t,e){return((e%=720)>=0&&e<360||e<-360?0:1)-((t%=720)>=0&&t<360||t<-360?0:1)},t.PolygonArea=function(t,n){this._geod=t,this.a=this._geod.a,this.f=this._geod.f,this._area0=4*Math.PI*t._c2,this.polyline=n||!1,this._mask=e.LATITUDE|e.LONGITUDE|e.DISTANCE|(this.polyline?e.NONE:e.AREA|e.LONG_UNROLL),this.polyline||(this._areasum=new i.Accumulator(0)),this._perimetersum=new i.Accumulator(0),this.Clear()},t.PolygonArea.prototype.Clear=function(){this.num=0,this._crossings=0,this.polyline||this._areasum.Set(0),this._perimetersum.Set(0),this._lat0=this._lon0=this.lat=this.lon=Number.NaN},t.PolygonArea.prototype.AddPoint=function(t,e){var n;0===this.num?(this._lat0=this.lat=t,this._lon0=this.lon=e):(n=this._geod.Inverse(this.lat,this.lon,t,e,this._mask),this._perimetersum.Add(n.s12),this.polyline||(this._areasum.Add(n.S12),this._crossings+=s(this.lon,e)),this.lat=t,this.lon=e),++this.num},t.PolygonArea.prototype.AddEdge=function(t,e){var n;this.num&&(n=this._geod.Direct(this.lat,this.lon,t,e,this._mask),this._perimetersum.Add(e),this.polyline||(this._areasum.Add(n.S12),this._crossings+=r(this.lon,n.lon2)),this.lat=n.lat2,this.lon=n.lon2),++this.num},t.PolygonArea.prototype.Compute=function(t,e){var n,r,o={number:this.num};return this.num<2?(o.perimeter=0,this.polyline||(o.area=0),o):this.polyline?(o.perimeter=this._perimetersum.Sum(),o):(n=this._geod.Inverse(this.lat,this.lon,this._lat0,this._lon0,this._mask),o.perimeter=this._perimetersum.Sum(n.s12),(r=new i.Accumulator(this._areasum)).Add(n.S12),1&this._crossings+s(this.lon,this._lon0)&&r.Add((r.Sum()<0?1:-1)*this._area0/2),t||r.Negate(),e?r.Sum()>this._area0/2?r.Add(-this._area0):r.Sum()<=-this._area0/2&&r.Add(+this._area0):(r.Sum()>=this._area0||r<0)&&r.Add(-this._area0),o.area=r.Sum(),o)},t.PolygonArea.prototype.TestPoint=function(t,e,n,i){var r,o,a,h,l={number:this.num+1};if(0===this.num)return l.perimeter=0,this.polyline||(l.area=0),l;for(l.perimeter=this._perimetersum.Sum(),o=this.polyline?0:this._areasum.Sum(),a=this._crossings,h=0;h<(this.polyline?1:2);++h)r=this._geod.Inverse(0===h?this.lat:t,0===h?this.lon:e,0!==h?this._lat0:t,0!==h?this._lon0:e,this._mask),l.perimeter+=r.s12,this.polyline||(o+=r.S12,a+=s(0===h?this.lon:e,0!==h?this._lon0:e));return this.polyline||(1&a&&(o+=(o<0?1:-1)*this._area0/2),n||(o*=-1),i?o>this._area0/2?o-=this._area0:o<=-this._area0/2&&(o+=this._area0):o>=this._area0?o-=this._area0:o<0&&(o+=this._area0),l.area=o),l},t.PolygonArea.prototype.TestEdge=function(t,e,n,i){var o,a,h,l={number:this.num?this.num+1:0};return 0===this.num||(l.perimeter=this._perimetersum.Sum()+e,this.polyline||(a=this._areasum.Sum(),h=this._crossings,a+=(o=this._geod.Direct(this.lat,this.lon,t,e,this._mask)).S12,h+=r(this.lon,o.lon2),o=this._geod.Inverse(o.lat2,o.lon2,this._lat0,this._lon0,this._mask),l.perimeter+=o.s12,a+=o.S12,1&(h+=s(o.lon2,this._lon0))&&(a+=(a<0?1:-1)*this._area0/2),n||(a*=-1),i?a>this._area0/2?a-=this._area0:a<=-this._area0/2&&(a+=this._area0):a>=this._area0?a-=this._area0:a<0&&(a+=this._area0),l.area=a)),l}}(Ve.PolygonArea,Ve.Geodesic,Ve.Math,Ve.Accumulator),tt(function(t){var e=Z(t.params,"rlat_1"),n=Z(t.params,"rlat_2");Ke(t,e,n)},"aea","Albers Equal Area","Conic Sph&Ell\nlat_1= lat_2="),tt(function(t){var e=Z(t.params,"rlat_1"),n=Z(t.params,"bsouth")?-k:k;Ke(t,e,n)},"leac","Lambert Equal Area Conic","Conic, Sph&Ell\nlat_1= south"),tt(function(e){var r,o,h,u,p,d,f,m=1e-10;if(e.phi0=Z(e.params,"rlat_0"),t(t(e.phi0)-k)<m?(p=e.phi0<0?1:0,r=e.phi0<0?-1:1,o=0):t(e.phi0)<m?(p=2,r=0,o=1):(p=3,r=n(e.phi0),o=i(e.phi0)),e.es)if(f=new Ve.Geodesic.Geodesic(e.a,e.es/(1+c(e.one_es))),d=Xe(e.es),Z(e.params,"bguam"))h=Ze(e.phi0,r,o,d),e.inv=function(t,r){var o,a,l;for(o=.5*t.x*t.x,r.phi=e.phi0,l=0;l<3;++l)a=e.e*n(r.phi),r.phi=Je(h+t.y-o*s(r.phi)*(a=c(1-a*a)),e.es,d);r.lam=t.x*a/i(r.phi)},e.fwd=function(t,s){var r,o,a;r=i(t.phi),o=n(t.phi),a=1/c(1-e.es*o*o),s.x=t.lam*r*a,s.y=Ze(t.phi,o,r,d)-h+.5*t.lam*t.lam*r*o*a};else{switch(p){case 0:u=Ze(k,1,0,d);break;case 1:u=Ze(-k,-1,0,d);break;case 2:case 3:e.inv=g,e.fwd=y,c(1-e.es*r*r),e.e,c(e.one_es)}e.inv=g,e.fwd=y}else e.inv=function(t,s){var a,h,c,u=t.x,d=t.y;if((h=_(u,d))>b)h-m>b&&U(),h=b;else if(h<m)return s.phi=e.phi0,void(s.lam=0);3==p||2==p?(c=n(h),a=i(h),2==p?(s.phi=Ye(d*c/h),u*=c,d=a*h):(s.phi=Ye(a*r+d*c*o/h),d=(a-r*n(s.phi))*h,u*=c*o),s.lam=0==d?0:l(u,d)):0==p?(s.phi=k-h,s.lam=l(u,-d)):(s.phi=h-k,s.lam=l(u,d))},e.fwd=function(e,s){var h,l,c;switch(c=n(e.phi),l=i(e.phi),h=i(e.lam),p){case 2:case 3:s.y=2==p?l*h:r*c+o*l*h,t(t(s.y)-1)<1e-14?s.y<0?z():s.x=s.y=0:(s.y=a(s.y),s.y/=n(s.y),s.x=s.y*l*n(e.lam),s.y*=2==p?c:o*c-r*l*h);break;case 0:e.phi=-e.phi,h=-h;case 1:t(e.phi-k)<m&&z(),s.x=(s.y=k+e.phi)*n(e.lam),s.y*=h}};function y(s,r){var o,a,h,l,c,_,y,g,v,x,w;switch(o=i(s.lam),a=i(s.phi),h=n(s.phi),p){case 0:o=-o;case 1:r.x=(l=t(u-Ze(s.phi,h,a,d)))*n(s.lam),r.y=l*o;break;case 2:case 3:if(t(s.lam)<m&&t(s.phi-e.phi0)<m){r.x=r.y=0;break}g=e.phi0/S,y=e.lam0/S,x=s.phi/S,v=(s.lam+e.lam0)/S,c=(w=f.Inverse(g,y,x,v,f.AZIMUTH)).azi1*S,_=w.s12,r.x=_*n(c)/e.a,r.y=_*i(c)/e.a}}function g(t,n){var i,s,r,o,a,h,y,g;if((i=_(t.x,t.y))<m)return n.phi=e.phi0,n.lam=0,n;3==p||2==p?(o=t.x*e.a,a=t.y*e.a,h=e.phi0/S,y=e.lam0/S,s=l(o,a)/S,r=c(o*o+a*a),g=f.Direct(h,y,s,r,f.STANDARD),n.phi=g.lat2*S,n.lam=g.lon2*S,n.lam-=e.lam0):(n.phi=Je(0==p?u-i:u+i,e.es,d),n.lam=l(t.x,0==p?-t.y:t.y))}},"aeqd","Azimuthal Equidistant","Azi, Sph&Ell\nlat_0 guam"),tt(function(e){var r,o,a,h,l,c,u=1e-10;e.es=0,e.fwd=function(e,c){var p,_,f,m,y,g,v,x;switch(p=n(e.lam),_=i(e.lam),h){case 2:case 3:m=n(e.phi),x=(f=i(e.phi))*_,3==h&&(x=r*m+o*x),!l&&x<-u&&z(),v=t(g=1-x)>u?-d(y=.5*(1+x))/g-a/y:.5-a,c.x=v*f*p,c.y=3==h?v*(o*m-r*f*_):v*m;break;case 1:case 0:e.phi=t(p_halfpi-e.phi),!l&&e.phi-u>k&&z(),(e.phi*=.5)>u?(y=s(e.phi),v=-2*(d(i(e.phi))/y+y*a),c.x=v*p,c.y=v*_,0==h&&(c.y=-c.y)):c.x=c.y=0}},l=Z(e.params,"bno_cut"),c=.5*(k-Z(e.params,"rlat_b")),t(c)<u?a=-.5:(a=1/s(c),a*=a*d(i(c))),t(t(e.phi0)-k)<u?e.phi0<0?(p_halfpi=-k,h=1):(p_halfpi=k,h=0):t(e.phi0)<u?h=2:(h=3,r=n(e.phi0),o=i(e.phi0))},"airy","Airy","Misc Sph, no inv.\nno_cut lat_b="),tt(function(t){var e=t.opaque={mode:1};Z(t.params,"tlat_1")?0===(e.cosphi1=i(Z(t.params,"rlat_1")))&&j(-22):e.cosphi1=.6366197723675814,nn(t)},"wintri","Winkel Tripel","Misc Sph\nlat_1"),tt(nn,"aitoff","Aitoff","Misc Sph"),tt(function(t){t.fwd=function(t,e){var r,o,a,h,l,u,p,d=4/3,_=t.lam;r=s(.5*t.phi),a=1+(o=c(1-r*r))*i(_*=.5),h=n(_)*o/a,u=r/a,e.x=d*h*(3+(l=h*h)-3*(p=u*u)),e.y=d*u*(3+3*l-p)},t.es=0},"august","August Epicycloidal","Misc Sph, no inv."),tt(function(t){sn(t,!1,!1)},"apian","Apian Globular I","Misc Sph, no inv."),tt(function(t){sn(t,!1,!0)},"ortel","Ortelius Oval","Misc Sph, no inv."),tt(function(t){sn(t,!0,!1)},"bacon","Bacon Globular","Misc Sph, no inv."),tt(function(t){var e,s,r,a;t.es=0,t.fwd=function(t,h){var u,p,d,_,f,m;return t.lam+=-16.5*S,p=i(t.phi),d=i(t.lam)*p,_=n(t.lam)*p,m=(f=n(t.phi))*e+d*s,t.lam=l(_*r-m*a,d*e-f*s),m=m*r+_*a,t.phi=o(m),t.lam=Et(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*n(t.phi+b/2)),p=i(t.phi),u=c(2/(1+p*i(t.lam/2))),h.x=1.68*u*p*n(t.lam/2),h.y=u*n(t.phi),u=(1-i(t.lam*t.phi))/12,h.y<0&&(h.x*=1+u),h.y>0&&(h.y*=1+u/1.5*h.x*h.x),h},t.lam0=0,t.phi0=-42*S,e=i(t.phi0),s=n(t.phi0),r=1,a=0},"bertin1953","Bertin 1953","Misc., Sph., NoInv."),tt(function(e){var s=c(2);e.fwd=function(e,r){var o,a,h,l;if(o=e.phi,t(t(e.phi)-k)<1e-7)r.x=0;else{for(h=n(o)*b,l=20;l&&(o-=a=(o+n(o)-h)/(1+i(o)),!(t(a)<1e-7));--l);o*=.5,r.x=2.00276*e.lam/(1/i(e.phi)+1.11072/i(o))}r.y=.49931*(e.phi+s*n(o))},e.es=0},"boggs","Boggs Eumorphic","PCyl., no inv., Sph."),tt(function(e){var r,o,a,h,u,p,d=1e-10;r=Z(e.params,"rlat_1"),t(r)<d&&j(-23),e.es?(u=Xe(e.es),h=Ze(r,a=n(r),p=i(r),u),a=p/(c(1-e.es*a*a)*a),e.inv=function(s,r){var o,p;p=_(s.x,s.y=a-s.y),r.phi=Je(a+h-p,e.es,u),(o=t(r.phi))<k?(o=n(r.phi),r.lam=p*l(s.x,s.y)*c(1-e.es*o*o)/i(r.phi)):t(o-k)<=d?r.lam=0:U()},e.fwd=function(t,s){var r,o,l;r=a+h-Ze(t.phi,o=n(t.phi),l=i(t.phi),u),o=l*t.lam/(r*c(1-e.es*o*o)),s.x=r*n(o),s.y=a-r*i(o)}):(o=t(r)+d>=k?0:1/s(r),e.inv=function(e,n){var s=_(e.x,e.y=o-e.y);n.phi=o+r-s,t(n.phi)>k&&U(),t(t(n.phi)-k)<=d?n.lam=0:n.lam=s*l(e.x,e.y)/i(n.phi)},e.fwd=function(e,s){var a,h;h=o+r-e.phi,t(h)>d?(s.x=h*n(a=e.lam*i(e.phi)/h),s.y=o-h*i(a)):s.x=s.y=0})},"bonne","Bonne (Werner lat_1=90)","Conic Sph&Ell\nlat_1="),tt(function(t){var e,r,a=.16666666666666666,h=.008333333333333333,u=.041666666666666664,p=.06666666666666667;t.es?(r=Xe(t.es),e=Ze(t.phi0,n(t.phi0),i(t.phi0),r),t.fwd=function(o,l){var p,d,_,f,m,y;l.y=Ze(o.phi,p=n(o.phi),f=i(o.phi),r),p=1/c(1-t.es*p*p),y=s(o.phi),d=y*y,_=o.lam*f,f*=t.es*f/(1-t.es),m=_*_,l.x=p*_*(1-m*d*(a-(8-d+8*f)*m*h)),l.y-=e-p*y*m*(.5+(5-d+6*f)*m*u)},t.inv=function(o,a){var h,l,d,_,f,m,y;y=Je(e+o.y,t.es,r),m=s(y),l=m*m,h=n(y),d=1/(1-t.es*h*h),h=c(d),d*=(1-t.es)*h,_=o.x/h,f=_*_,a.phi=y-h*m/d*f*(.5-(1+3*l)*f*u),a.lam=_*(1+l*f*((1+3*l)*f*p-.3333333333333333))/i(y)}):(t.fwd=function(e,r){r.x=o(i(e.phi)*n(e.lam)),r.y=l(s(e.phi),i(e.lam))-t.phi0},t.inv=function(e,r){var a=e.y+t.phi0;r.phi=o(n(a)*i(e.x)),r.lam=l(s(e.x),i(a))})},"cass","Cassini","Cyl, Sph&Ell"),tt(function(e){var s,r,a=0;Z(e.params,"tlat_ts")&&(e.k0=i(a=Z(e.params,"rlat_ts")),e.k0<0&&j(-24)),e.es?(a=n(a),e.k0/=c(1-e.es*a*a),e.e=c(e.es),(r=rn(e.es))||e_error_0(),s=He(1,e.e,e.one_es),e.fwd=function(t,i){i.x=e.k0*t.lam,i.y=.5*He(n(t.phi),e.e,e.one_es)/e.k0},e.inv=function(t,n){n.phi=on(o(2*t.y*e.k0/s),r),n.lam=t.x/e.k0}):(e.fwd=function(t,i){i.x=e.k0*t.lam,i.y=n(t.phi)/e.k0},e.inv=function(n,i){var s,r=n.x,a=n.y;(s=t(a*=e.k0))-N<=1?(i.phi=s>=1?a<0?-k:k:o(a),i.lam=r/e.k0):U()})},"cea","Equal Area Cylindrical","Cyl, Sph&Ell\nlat_ts="),tt(function(e){var s,r,o,a,h,u,p,d=1/3,_=[];for(u=0;u<3;++u)_[u]={p:{}},_[u].phi=Z(e.params,"rlat_"+(u+1)),_[u].lam=Z(e.params,"rlon_"+(u+1)),_[u].lam=Et(_[u].lam-e.lam0),_[u].cosphi=i(_[u].phi),_[u].sinphi=n(_[u].phi);for(u=0;u<3;++u)p=2==u?0:u+1,_[u].v=f(_[p].phi-_[u].phi,_[u].cosphi,_[u].sinphi,_[p].cosphi,_[p].sinphi,_[p].lam-_[u].lam),_[u].v.r||j(-25);function f(e,s,r,o,a,h){var u,p,d,_={};return u=i(h),t(e)>1||t(h)>1?_.r=Qe(cs1*a+s*o*u):(p=n(.5*e),d=n(.5*h),_.r=2*Ye(c(p*p+s*o*d*d))),t(_.r)>1e-9?_.Az=l(o*n(h),s*a-r*o*u):_.r=_.Az=0,_}function m(t,e,n){return Qe(.5*(t*t+e*e-n*n)/(t*e))}o=m(_[0].v.r,_[2].v.r,_[1].v.r),a=m(_[0].v.r,_[1].v.r,_[2].v.r),h=b-o,r=2*(_[0].p.y=_[1].p.y=_[2].v.r*n(o)),_[2].p.y=0,_[0].p.x=-(_[1].p.x=.5*_[0].v.r),s=_[2].p.x=_[0].p.x+_[2].v.r*i(o),e.es=0,e.fwd=function(t,e){var o,l,c,u,p,y,g,v=[];for(o=n(t.phi),l=i(t.phi),u=0;u<3&&(v[u]=f(t.phi-_[u].phi,_[u].cosphi,_[u].sinphi,l,o,t.lam-_[u].lam),v[u].r);++u)v[u].Az=Et(v[u].Az-_[u].v.Az);if(u<3)y=_[u].p.x,g=_[u].p.y;else{for(y=s,g=r,u=0;u<3;++u)p=2==u?0:u+1,c=m(_[u].v.r,v[u].r,v[p].r),v[u].Az<0&&(c=-c),u?1==u?(c=a-c,y-=v[u].r*i(c),g-=v[u].r*n(c)):(c=h-c,y+=v[u].r*i(c),g+=v[u].r*n(c)):(y+=v[u].r*i(c),g-=v[u].r*n(c));y*=d,g*=d}e.x=y,e.y=g}},"chamb","Chamberlin Trimetric","Misc Sph, no inv.\nlat_1= lon_1= lat_2= lon_2= lat_3= lon_3="),tt(function(t){var e=1/3;t.inv=function(t,n){n.phi=3*o(.32573500793527993*t.y),n.lam=1.0233267079464885*t.x/(2*i((n.phi+n.phi)*e)-1)},t.fwd=function(t,s){t.phi*=e,s.x=.9772050238058398*t.lam*(2*i(t.phi+t.phi)-1),s.y=3.0699801238394655*n(t.phi)},t.es=0},"crast","Craster Parabolic (Putnins P4)","PCyl., Sph."),tt(function(t){var e=.5253,s=.7264,r=1/Math.sqrt(e*s),a=.9701,h=d(22*S),l=_(0),u=n(h),p=i(h);function d(t){return o(s*n(t)+.4188*c(e*s))}function _(t){return e*t}Z(t.params,"tlon_0")||(t.lam0=11.023*S),t.es=0,t.fwd=function(t,e){var s=d(t.phi),o=_(t.lam),f=n(s),m=i(s),y=n(o-l),g=i(o-l),v=c(2/(1+n(h)*f+p*m*g));e.x=r*v*m*y*a,e.y=r*v*(p*f-u*m*g)/a}},"cupola","Cupola","PCyl., Sph., NoInv."),tt(function(e){e.fwd=function(e,n){var s=t(e.lam);n.y=e.phi,n.x=e.lam,n.x*=i((.95+s*(s*s*.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 n=.9213177319235613,i=.3183098861837907;e.es=0,e.fwd=function(e,s){s.x=n*e.lam*(1-i*t(e.phi)),s.y=n*e.phi},e.inv=function(e,s){s.phi=e.y/n,s.lam=e.x/(n*(1-i*t(s.phi)))}},"eck1","Eckert I","PCyl Sph"),tt(function(e){var i=.46065886596178063,s=1.4472025091165353;e.es=0,e.fwd=function(e,r){r.x=i*e.lam*(r.y=c(4-3*n(t(e.phi)))),r.y=s*(2-r.y),e.phi<0&&(r.y=-r.y)},e.inv=function(e,n){n.lam=e.x/(i*(n.phi=2-t(e.y)/s)),n.phi=.3333333333333333*(4-n.phi*n.phi),t(n.phi)>=1?t(n.phi)>1.0000001?U():n.phi=n.phi<0?-k:k:n.phi=o(n.phi),e.y<0&&(n.phi=-n.phi)}},"eck2","Eckert II","PCyl Sph"),tt(function(t){an(t,{C_x:.4222382003157712,C_y:.8444764006315424,A:1,B:.4052847345693511})},"eck3","Eckert III","PCyl Sph"),tt(function(t){an(t,{C_x:.94745,C_y:.94745,A:0,B:.3039635509270133})},"wag6","Wagner VI","PCyl Sph"),tt(function(t){an(t,{C_x:.8660254037844,C_y:1,A:0,B:.3039635509270133})},"kav7","Kavraisky VII","PCyl Sph"),tt(function(t){an(t,{C_x:1.8949,C_y:.94745,A:-.5,B:.3039635509270133})},"putp1","Putnins P1","PCyl Sph"),tt(function(e){var s=.4222382003157712,r=1.3265004281770023,o=3.5707963267948966;e.es=0,e.fwd=function(e,a){var h,l,c,u,p;for(h=o*n(e.phi),l=e.phi*e.phi,e.phi*=.895168+l*(.0218849+.00826809*l),p=6;p&&(u=i(e.phi),c=n(e.phi),e.phi-=l=(e.phi+c*(u+2)-h)/(1+u*(u+2)-c*c),!(t(l)<1e-7));--p);p?(a.x=s*e.lam*(1+i(e.phi)),a.y=r*n(e.phi)):(a.x=s*e.lam,a.y=e.phi<0?-r:r)},e.inv=function(t,e){var a;e.phi=Ye(t.y/r),e.lam=t.x/(s*(1+(a=i(e.phi)))),e.phi=Ye((e.phi+n(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+i(t.phi))*t.lam,e.y=.882025543449103*t.phi},t.inv=function(t,e){e.lam=2.267508027238226*t.x/(1+i(e.phi=1.133754013619113*t.y))}},"eck5","Eckert V","PCyl Sph"),tt(function(t){var e=i(Z(t.params,"rlat_ts"));e<=0&&j(-24),t.es=0,t.fwd=function(n,i){i.x=e*n.lam,i.y=n.phi-t.phi0},t.inv=function(n,i){i.lam=n.x/e,i.phi=n.y+t.phi0}},"eqc","Equidistant Cylindrical (Plate Caree)","Cyl, Sph\nlat_ts=[, lat_0=0]"),tt(function(e){var s,r,o,a,h,c,u,p,d,f,m,y,g;s=Z(e.params,"rlat_1"),r=Z(e.params,"rlat_2"),t(s+r)<N&&j(-21),(u=Xe(e.es))||e_error_0(),o=f=n(s),d=i(s),m=t(s-r)>=N,(p=e.es>0)?(g=We(f,d,e.es),y=Ze(s,f,d,u),m&&(f=n(r),d=i(r),o=(g-We(f,d,e.es))/(Ze(r,f,d,u)-y)),h=(c=y+g/o)-Ze(e.phi0,n(e.phi0),i(e.phi0),u)):(m&&(o=(d-i(r))/(r-s)),c=s+i(s)/o,h=c-e.phi0),e.fwd=function(t,e){a=c-(p?Ze(t.phi,n(t.phi),i(t.phi),u):t.phi),e.x=a*n(t.lam*=o),e.y=h-a*i(t.lam)},e.inv=function(t,n){0!=(a=_(t.x,t.y=h-t.y))?(o<0&&(a=-a,t.x=-t.x,t.y=-t.y),n.phi=c-a,p&&(n.phi=Je(n.phi,e.es,u)),n.lam=l(t.x,t.y)/o):(n.lam=0,n.phi=o>0?k:-k)}},"eqdc","Equidistant Conic","Conic, Sph&Ell\nlat_1= lat_2="),tt(function(t){var e=1.340264,n=-.081106,i=893e-6,s=.003796,r=Math.sqrt(3)/2;t.es=0,t.fwd=function(t,o){var a=Math.asin(r*Math.sin(t.phi)),h=a*a,l=h*h*h;o.x=t.lam*Math.cos(a)/(r*(e+3*n*h+l*(7*i+9*s*h))),o.y=a*(e+n*h+l*(i+s*h))},t.inv=function(t,o){var a,h,l,c,u=t.y;for(c=0;c<12&&(u-=l=(u*(e+n*(a=u*u)+(h=a*a*a)*(i+s*a))-t.y)/(e+3*n*a+h*(7*i+9*s*a)),!(Math.abs(l)<1e-9));++c);h=(a=u*u)*a*a,o.lam=r*t.x*(e+3*n*a+h*(7*i+9*s*a))/Math.cos(u),o.phi=Math.asin(Math.sin(u)/r)}},"eqearth","Equal Earth","PCyl., Sph."),tt(hn,"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*s(.5*t.phi)},t.inv=function(t,e){e.lam=1.4142135623730951*t.x,e.phi=2*h(.585786437626905*t.y)},t.es=0},"gall","Gall (Gall Stereographic)","Cyl, Sph"),tt(function(t){t.is_geocent=!0,t.x0=0,t.y0=0,t.fwd=function(t,e){e.x=t.lam,e.y=t.phi},t.inv=function(t,e){e.phi=t.y,e.lam=t.x}},"geocent","Geocentric",""),tt(function(t){var e,r,o,a,u,p,d,f=Z(t.params,"dh"),m=Z(t.params,"ssweep");m?"x"==m?d=1:"y"==m?d=0:j(-49):d=0,((u=f/t.a)<=0||u>1e10)&&j(-50),p=(a=1+u)*a-1,0!=t.es?(e=c(t.one_es),r=t.one_es,o=t.rone_es,t.inv=function(t,n){var r,f,m,y,g,v;r=-1,d?(m=s(t.y/u),f=s(t.x/u)*_(1,m)):(f=s(t.x/u),m=s(t.y/u)*_(1,f));var x=(g=2*a*r)*g-4*(y=f*f+(y=m/e)*y+r*r)*p;x<0&&j(-51),v=(-g-c(x))/(2*y),r=a+v*r,f*=v,m*=v,n.lam=l(f,r),n.phi=h(m*i(n.lam)/r),n.phi=h(o*s(n.phi))},t.fwd=function(t,l){var c,p,f,m,y;t.phi=h(r*s(t.phi)),c=e/_(e*i(t.phi),n(t.phi)),p=c*i(t.lam)*i(t.phi),f=c*n(t.lam)*i(t.phi),m=c*n(t.phi),(a-p)*p-f*f-m*m*o<0&&j(-51),y=a-p,d?(l.x=u*h(f/_(m,y)),l.y=u*h(m/y)):(l.x=u*h(f/y),l.y=u*h(m/_(f,y)))}):(e=r=o=1,t.inv=function(t,e){var n,r,o,_,f,m;n=-1,d?(o=s(t.y/u),r=s(t.x/u)*c(1+o*o)):(r=s(t.x/u),o=s(t.y/u)*c(1+r*r));var y=(f=2*a*n)*f-4*(_=r*r+o*o+n*n)*p;y<0&&j(-51),m=(-f-c(y))/(2*_),n=a+m*n,r*=m,o*=m,e.lam=l(r,n),e.phi=h(o*i(e.lam)/n)},t.fwd=function(t,e){var s=i(t.phi),r=i(t.lam)*s,o=n(t.lam)*s,l=n(t.phi);s=a-r,d?(e.x=u*h(o/_(l,s)),e.y=u*h(l/s)):(e.x=u*h(o/s),e.y=u*h(l/_(o,s)))})},"geos","Geostationary Satellite View","Azi, Sph&Ell"),tt(function(t){var e=a(Z(t.params,"tlat_1")?Z(t.params,"rlat_1"):0),r=n(e),o=i(e);function a(t){return Ye(s(.5*t))}t.fwd=function(t,e){var s=.5*t.lam,h=a(t.phi),l=n(h),c=i(h),u=i(s);r*l+o*c*u>=0?(e.x=c*n(s),e.y=o*l-r*c*u):z()},t.es=0},"gilbert","Gilbert Two World Perspective","PCyl., Sph., NoInv.\nlat_1="),tt(function(t){t.fwd=function(t,e){var n=t.phi*t.phi;e.y=t.phi*(1+.08333333333333333*n),e.x=t.lam*(1-.162388*n),n=t.lam*t.lam,e.x*=.87-952426e-9*n*n},t.es=0},"gins8","Ginsburg VIII (TsNIIGAiK)","PCyl, Sph., no inv."),tt(function(t){Z(t.params,"tn"),Z(t.params,"tm")?cn(t,Z(t.params,"dm"),Z(t.params,"dn")):j(-99)},"gn_sinu","General Sinusoidal Series","PCyl, Sph.\nm= n="),tt(ln,"sinu","Sinusoidal (Sanson-Flamsteed)","PCyl, Sph&Ell"),tt(function(t){cn(t,1,2.5707963267948966)},"eck6","Eckert VI","PCyl, Sph.\nm= n="),tt(function(t){cn(t,.5,1.7853981633974483)},"mbtfps","McBryde-Thomas Flat-Polar Sinusoidal","PCyl, Sph."),tt(function(e){var s,r,a=1e-10;t(t(e.phi0)-k)<a?r=e.phi0<0?1:0:t(e.phi0)<a?r=2:(r=3,sinph0=n(e.phi0),s=i(e.phi0)),e.inv=function(i,u){var p,d,f,m=i.x,y=i.y;if(p=_(m,y),f=n(u.phi=h(p)),d=c(1-f*f),t(p)<=a)u.phi=e.phi0,u.lam=0;else{switch(r){case 3:u.phi=d*sinph0+y*f*s/p,t(u.phi)>=1?u.phi=u.phi>0?k:-k:u.phi=o(u.phi),y=(d-sinph0*n(u.phi))*p,m*=f*s;break;case 2:u.phi=y*f/p,t(u.phi)>=1?u.phi=u.phi>0?k:-k:u.phi=o(u.phi),y=d*p,m*=f;break;case 1:u.phi-=k;break;case 0:u.phi=k-u.phi,y=-y}u.lam=l(m,y)}},e.fwd=function(t,e){var o,h,l;switch(l=n(t.phi),h=i(t.phi),o=i(t.lam),r){case 2:e.y=h*o;break;case 3:e.y=sinph0*l+s*h*o;break;case 1:e.y=-l;break;case 0:e.y=l}switch(e.y<=a&&z(),e.x=(e.y=1/e.y)*h*n(t.lam),r){case 2:e.y*=l;break;case 3:e.y*=s*l-sinph0*h*o;break;case 0:o=-o;case 1:e.y*=h*o}},e.es=0},"gnom","Gnomonic","Azi, Sph."),tt(un,"moll","Mollweide","PCyl Sph"),tt(function(t){dn(t,pn(0,b/3))},"wag4","Wagner IV","PCyl Sph"),tt(function(t){dn(t,{C_x:.90977,C_y:1.65014,C_p:3.00896})},"wag5","Wagner V","PCyl Sph"),tt(function(e){var n,i,s,r,o=.0528,a=.7109307819790236;e.es=0,ln(e),n=e.fwd,i=e.inv,un(e),s=e.fwd,r=e.inv,e.fwd=function(e,i){t(e.phi)<a?n(e,i):(s(e,i),i.y-=e.phi>0?o:-o)},e.inv=function(e,n){t(e.y)<=a?i(e,n):(e.y+=e.y>0?o:-o,r(e,n))}},"goode","Goode Homolosine","PCyl, Sph."),tt(function(e){var s,r,o;e.inv=function(e,n){var i=c(1-.25*s*s*e.x*e.x-.25*e.y*e.y);t(2*i*i-1)<1e-10?(n.lam=x,n.phi=x,pj_errno=-14):(n.lam=en(s*e.x*i,2*i*i-1)/s,n.phi=Ye(i*e.y))},e.fwd=function(t,e){var a,h;h=c(2/(1+(a=i(t.phi))*i(t.lam*=s))),e.x=r*h*a*n(t.lam),e.y=o*h*n(t.phi)},e.es=0,Z(e.params,"tW")?(s=t(Z(e.params,"dW")))<=0&&j(-27):s=.5,Z(e.params,"tM")?(r=t(Z(e.params,"dM")))<=0&&j(-27):r=1,o=1/r,r/=s},"hammer","Hammer & Eckert-Greifendorff","Misc Sph,\nW= M="),tt(function(e){var s=1.000001;e.inv=function(e,r){var a=e.y*(e.y<0?.5179951515653813:.5686373742600607);t(a)>1?t(a)>s?U():a=a>0?k:-k:a=o(a),r.lam=1.1764705882352942*e.x/i(a),a+=a,r.phi=(a+n(a))*(e.y<0?.4102345310814193:.3736990601468637),t(r.phi)>1?t(r.phi)>s?U():r.phi=r.phi>0?k:-k:r.phi=o(r.phi)},e.fwd=function(e,s){var r,o,a;for(o=n(e.phi)*(e.phi<0?2.43763:2.67595),a=20;a&&(e.phi-=r=(e.phi+n(e.phi)-o)/(1+i(e.phi)),!(t(r)<1e-7));--a);s.x=.85*e.lam*i(e.phi*=.5),s.y=n(e.phi)*(e.phi<0?1.93052:1.75859)},e.es=0},"hatano","Hatano Asymmetrical Equal Area","PCyl., Sph."),tt(_n,"healpix","HEALPix","Sph., Ellps."),tt(function(t){_n(t,!0)},"rhealpix","rHEALPix","Sph., Ellps.\nnorth_square= south_square="),tt(function(e){var s,r=n(.5),h=o(r),u=2*c(b/(s=b+4*h*2)),p=.5*u*(2+c(3));e.es=0,e.fwd=function(e,r){var o,a,d=1-n(e.phi);if(d&&d<2){var _,f,m,y,g,v=k-e.phi,x=25;do{f=n(v),m=i(v),g=h+l(f,2-m),v-=_=(v-1*h-2*f+(y=5-4*m)*g-.5*d*s)/(4*f*g)}while(t(_)>1e-12&&--x>0);o=u*c(y),a=e.lam*g/b}else o=u*(1+d),a=e.lam*h/b;r.x=o*n(a),r.y=p-o*i(a)},e.inv=function(t,e){var i=t.x,r=t.y,d=i*i+(r-=p)*r,_=(5-d/(u*u))/4,f=a(_),m=n(f),y=h+l(m,2-_);e.lam=o(i/c(d))*b/y,e.phi=o(1-2*(f-1*h-2*m+(5-4*_)*y)/s)}},"hill","Hill Eucyclic","PCyl., Sph."),tt(function(e){var r,a,p,d,_,f,m,y,g,v=.785398163397448,x=1.37008346281555;e.a=6377397.155,e.e=c(e.es=.006674372230614),Z(e.params,"tlat_0")||(e.phi0=.863937979737193),Z(e.params,"tlon_0")||(e.lam0=.4334234309119251),Z(e.params,"tk")||(e.k0=.9999),g=1,Z(e.params,"tczech")||(g=-1),d=c(1+e.es*u(i(e.phi0),4)/(1-e.es)),r=o(n(e.phi0)/d),p=u((1+e.e*n(e.phi0))/(1-e.e*n(e.phi0)),d*e.e/2),_=s(r/2+v)/u(s(e.phi0/2+v),d)*p,a=c(1-e.es)/(1-e.es*u(n(e.phi0),2)),f=n(x),m=e.k0*a/s(x),y=.5286277629901559,e.inv=function(r,a){var p,w,b,C,S,A,M,E;M=r.x,r.x=r.y,r.y=M,r.x*=g,r.y*=g,S=c(r.x*r.x+r.y*r.y),C=l(r.y,r.x)/n(x),b=2*(h(u(m/S,1/f)*s(x/2+v))-v),p=o(i(y)*n(b)-n(y)*i(b)*i(C)),w=o(i(b)*n(C)/i(p)),a.lam=e.lam0-w/d,A=p,E=0;do{a.phi=2*(h(u(_,-1/d)*u(s(p/2+v),1/d)*u((1+e.e*n(A))/(1-e.e*n(A)),e.e/2))-v),t(A-a.phi)<1e-15&&(E=1),A=a.phi}while(0===E);a.lam-=e.lam0},e.fwd=function(t,r){var a,l,c,p,w,b,C;a=u((1+e.e*n(t.phi))/(1-e.e*n(t.phi)),d*e.e/2),l=2*(h(_*u(s(t.phi/2+v),d)/a)-v),c=-t.lam*d,p=o(i(y)*n(l)+n(y)*i(l)*i(c)),w=o(i(l)*n(c)/i(p)),b=f*w,C=m*u(s(x/2+v),f)/u(s(p/2+v),f),r.y=C*i(b),r.x=C*n(b),r.y*=g,r.x*=g}},"krovak","Krovak","PCyl., Ellps."),tt(function(e){var s,r,a,h,u,p,d,f,m,y,g,v=1e-10;if(y=t(e.phi0),m=t(y-k)<v?e.phi0<0?1:0:t(y)<v?2:3,e.es){switch(e.e=c(e.es),u=He(1,e.e,e.one_es),e.es,f=rn(e.es),m){case 0:case 1:p=1;break;case 2:p=1/(d=c(.5*u)),a=1,h=.5*u;break;case 3:d=c(.5*u),g=n(e.phi0),s=He(g,e.e,e.one_es)/u,r=c(1-s*s),p=i(e.phi0)/(c(1-e.es*g*g)*d*r),h=(a=d)/p,a*=p}e.inv=function(t,a){var h,c,y,g,x=0;switch(m){case 2:case 3:if(t.x/=p,t.y*=p,(g=_(t.x,t.y))<v)return a.lam=0,a.phi=e.phi0,a;c=2*o(.5*g/d),h=i(c),c=n(c),t.x*=c,3==m?(x=h*s+t.y*c*r/g,t.y=g*r*h-t.y*s*c):(x=t.y*c/g,t.y=g*h);break;case 0:t.y=-t.y;case 1:if(!(y=t.x*t.x+t.y*t.y))return a.lam=0,a.phi=e.phi0,a;x=1-y/u,1==m&&(x=-x)}return a.lam=l(t.x,t.y),a.phi=on(o(x),f),a},e.fwd=function(o,l){var p,d,_,f,y=0,g=0,x=0;switch(p=i(o.lam),d=n(o.lam),_=n(o.phi),f=He(_,e.e,e.one_es),(3==m||2==m)&&(g=c(1-(y=f/u)*y)),m){case 3:x=1+s*y+r*g*p;break;case 2:x=1+g*p;break;case 0:x=k+o.phi,f=u-f;break;case 1:x=o.phi-k,f=u+f}switch(t(x)<v&&z(),m){case 3:case 2:3==m?(x=c(2/x),l.y=h*x*(r*y-s*g*p)):(x=c(2/(1+g*p)),l.y=x*y*h),l.x=a*x*g*d;break;case 0:case 1:f>=0?(x=c(f),l.x=x*d,l.y=p*(1==m?x:-x)):l.x=l.y=0}}}else 3==m&&(s=n(e.phi0),r=i(e.phi0)),e.inv=function(a,h){var c,u=0,p=0;switch(c=_(a.x,a.y),(h.phi=.5*c)>1&&U(),h.phi=2*o(h.phi),(3==m||2==m)&&(p=n(h.phi),u=i(h.phi)),m){case 2:h.phi=t(c)<=v?0:o(a.y*p/c),a.x*=p,a.y=u*c;break;case 3:h.phi=t(c)<=v?e.phi0:o(u*s+a.y*p*r/c),a.x*=p*r,a.y=(u-n(h.phi)*s)*c;break;case 0:a.y=-a.y,h.phi=k-h.phi;break;case 1:h.phi-=k}h.lam=0!=a.y||2!=m&&3!=m?l(a.x,a.y):0},e.fwd=function(o,a){var h,l,u;switch(u=n(o.phi),l=i(o.phi),h=i(o.lam),m){case 2:case 3:a.y=2==m?1+l*h:1+s*u+r*l*h,a.y<=v&&z(),a.y=c(2/a.y),a.x=a.y*l*n(o.lam),a.y*=2==m?u:r*u-s*l*h;break;case 0:h=-h;case 1:t(o.phi+e.phi0)<v&&z(),a.y=E-.5*o.phi,a.y=2*(1==m?i(a.y):n(a.y)),a.x=a.y*n(o.lam),a.y*=h}}},"laea","Lambert Azimuthal Equal Area","Azi, Sph&Ell"),tt(fn,"lonlat","Lat/long (Geodetic)",""),tt(fn,"longlat","Lat/long (Geodetic alias)",""),tt(fn,"latlon","Lat/long (Geodetic alias)",""),tt(fn,"latlong","Lat/long (Geodetic alias)",""),tt(function(e){var r,o,a,p,f,m,y,g,v,w,b,C=1e-10;e.inv=function(t,n){var i,s=t.x,r=t.y;s/=e.k0,r/=e.k0,0!=(i=_(s,r=y-r))?(m<0&&(i=-i,s=-s,r=-r),v?(n.phi=yn(u(i/g,1/m),e.e),n.phi==x&&U()):n.phi=2*h(u(g/i,1/m))-k,n.lam=l(s,r)/m):(n.lam=0,n.phi=m>0?k:-k)},e.fwd=function(r,o){var a,h=r.lam;t(t(r.phi)-k)<C?(r.phi*m<=0&&z(),a=0):a=g*(v?u(mn(r.phi,n(r.phi),e.e),m):u(s(E+.5*r.phi),-m)),h*=m,o.x=e.k0*(a*n(h)),o.y=e.k0*(y-a*i(h))},p=Z(e.params,"rlat_1"),Z(e.params,"tlat_2")?f=Z(e.params,"rlat_2"):(f=p,Z(e.params,"tlat_0")||(e.phi0=p)),t(p+f)<C&&j(-21),m=o=n(p),r=i(p),a=t(p-f)>=C,(v=0!=e.es)?(e.e=c(e.es),b=We(o,r,e.es),w=mn(p,o,e.e),a&&(o=n(f),m=d(b/We(o,i(f),e.es)),m/=d(w/mn(f,o,e.e))),g=y=b*u(w,-m)/m,y*=t(t(e.phi0)-k)<C?0:u(mn(e.phi0,n(e.phi0),e.e),m)):(a&&(m=d(r/i(f))/d(s(E+.5*f)/s(E+.5*p))),g=r*u(s(E+.5*p),m)/m,y=t(t(e.phi0)-k)<C?0:g*u(s(E+.5*e.phi0),-m))},"lcc","Lambert Conformal Conic","Conic, Sph&Ell\nlat_1= and lat_2= or lat_0="),tt(function(e){var n,r,o,a=1e-8;n=Z(e.params,"rlat_1"),r=i(n),o=s(E+.5*n),r<a&&j(-22),e.fwd=function(e,i){i.y=e.phi-n,t(i.y)<a?i.x=e.lam*r:(i.x=E+.5*e.phi,t(i.x)<a||t(t(i.x)-k)<a?i.x=0:i.x=e.lam*i.y/d(s(i.x)/o))},e.inv=function(e,i){i.phi=e.y+n,t(e.y)<a?i.lam=e.x/r:(i.lam=E+.5*i.phi,t(i.lam)<a||t(t(i.lam)-k)<a?i.lam=0:i.lam=e.x*d(s(i.lam)/o)/e.y)},e.es=0},"loxim","Loximuthal","PCyl Sph"),tt(function(e){var s=.9525793444156804,r=.9258200997725514,a=3.401680257083045,h=2/3,l=1/3,c=1.0000001;e.fwd=function(t,e){t.phi=o(s*n(t.phi)),e.x=r*t.lam*(2*i(h*t.phi)-1),e.y=a*n(l*t.phi)},e.inv=function(e,l){l.phi=e.y/a,t(l.phi)>=1?t(l.phi)>c?U():l.phi=l.phi<0?-k:k:l.phi=o(l.phi),l.lam=e.x/(r*(2*i(h*(l.phi*=3))-1)),t(l.phi=n(l.phi)/s)>=1?t(l.phi)>c?U():l.phi=l.phi<0?-k:k:l.phi=o(l.phi)},e.es=0},"mbt_fpp","McBride-Thomas Flat-Polar Parabolic","Cyl., Sph."),tt(function(e){var s=1.000001;e.fwd=function(e,s){var r,o,a;for(o=1.7071067811865475*n(e.phi),a=20;a&&(e.phi-=r=(n(.5*e.phi)+n(e.phi)-o)/(.5*i(.5*e.phi)+i(e.phi)),!(t(r)<1e-7));--a);s.x=.3124597141037825*e.lam*(1+2*i(e.phi)/i(.5*e.phi)),s.y=1.874758284622695*n(.5*e.phi)},e.inv=function(e,r){var a;r.phi=.533402096794177*e.y,t(r.phi)>1?t(r.phi)>s?U():r.phi<0?(a=-1,r.phi=-b):(a=1,r.phi=b):r.phi=2*o(a=r.phi),r.lam=3.2004125807650623*e.x/(1+2*i(r.phi)/i(.5*r.phi)),r.phi=.585786437626905*(a+n(r.phi)),t(r.phi)>1?t(r.phi)>s?U():r.phi=r.phi<0?-k:k:r.phi=o(r.phi)},e.es=0},"mbt_fpq","McBryde-Thomas Flat-Polar Quartic","Cyl., Sph."),tt(function(e){var s=.45503,r=1.36509,o=1.41546,a=.22248,h=1.44492,l=1/3;e.fwd=function(e,c){var u,p,d,_;for(u=o*n(e.phi),_=10;_&&(d=e.phi/r,e.phi-=p=(s*n(d)+n(e.phi)-u)/(l*i(d)+i(e.phi)),!(t(p)<1e-7));--_);d=e.phi/r,c.x=a*e.lam*(1+3*i(e.phi)/i(d)),c.y=h*n(d)},e.inv=function(t,e){var l;e.phi=r*(l=Ye(t.y/h)),e.lam=t.x/(a*(1+3*i(e.phi)/i(l))),e.phi=Ye((s*n(l)+n(e.phi))/o)},e.es=0},"mbt_fps","McBryde-Thomas Flat-Pole Sine (No. 2)","Cyl., Sph."),tt(function(e){var r=1e-10,o=0,a=Z(e.params,"tlat_ts");a&&(o=Z(e.params,"rlat_ts"))>=k&&j(-24),e.es?(a&&(e.k0=We(n(o),i(o),e.es)),e.inv=function(t,n){n.phi=yn(p(-t.y/e.k0),e.e),n.phi===x&&U(),n.lam=t.x/e.k0},e.fwd=function(i,s){t(t(i.phi)-k)<=r&&z(),s.x=e.k0*i.lam,s.y=-e.k0*d(mn(i.phi,n(i.phi),e.e))}):(e.inv=function(t,n){n.phi=k-2*h(p(-t.y/e.k0)),n.lam=t.x/e.k0},e.fwd=function(n,i){t(t(n.phi)-k)<=r&&z(),i.x=e.k0*n.lam,i.y=e.k0*d(s(E+.5*n.phi))})},"merc","Mercator","Cyl, Sph&Ell\nlat_ts="),tt(function(e){e.k0=1,e.inv=function(t,n){n.phi=k-2*h(p(-t.y/e.k0)),n.lam=t.x/e.k0},e.fwd=function(n,i){t(t(n.phi)-k)<=N&&z(),i.x=e.k0*n.lam,i.y=e.k0*d(s(E+.5*n.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(s(E+.4*t.phi))},t.inv=function(t,e){e.lam=t.x,e.phi=2.5*(h(p(.8*t.y))-E)},t.es=0},"mill","Miller Cylindrical","Cyl, Sph"),tt(function(t){t.lam0=20*S,t.phi0=18*S,t.es=0,xn(t,[[.9245,0],[0,0],[.01943,0]])},"mil_os","Miller Oblated Stereographic","Azi(mod)"),tt(function(t){t.lam0=-165*S,t.phi0=-10*S,t.es=0,xn(t,[[.721316,0],[0,0],[-.0088162,-.00617325]])},"lee_os","Lee Oblated Stereographic","Azi(mod)"),tt(function(t){t.lam0=-96*S,t.phi0=39*S,t.es=0,t.a=6370997,xn(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*S,t.phi0=64*S,0!=t.es?(e=[[.9945303,0],[.0052083,-.0027404],[.0072721,.0048181],[-.0151089,-.1932526],[.0642675,-.1381226],[.3582802,-.2884586]],t.a=6378206.4,t.e=c(t.es=.00676866)):(e=[[.9972523,0],[.0052513,-.0041175],[.0074606,.0048125],[-.0153783,-.1968253],[.0636871,-.1408027],[.3660976,-.2937382]],t.a=6370997),xn(t,e)},"alsk","Mod Stereographic of Alaska","Azi(mod)"),tt(function(t){var e;t.lam0=-120*S,t.phi0=45*S,0!=t.es?(e=[[.9827497,0],[.0210669,.0053804],[-.1031415,-.0571664],[-.0323337,-.0322847],[.0502303,.1211983],[.0251805,.0895678],[-.0012315,-.1416121],[.0072202,-.1317091],[-.0194029,.0759677],[-.0210072,.0834037]],t.a=6378206.4,t.e=c(t.es=.00676866)):(e=[[.984299,0],[.0211642,.0037608],[-.1036018,-.0575102],[-.0329095,-.0320119],[.0499471,.1223335],[.026046,.0899805],[7388e-7,-.1435792],[.0075848,-.1334108],[-.0216473,.0776645],[-.0225161,.0853673]],t.a=6370997),xn(t,e)},"gs50","Mod Stereographic of 50 U.S.","Azi(mod)"),tt(function(e){var n=.8707,i=-.131979,s=-.013791,r=.003971,o=-.001529,a=1.007226,h=.015085,l=-.044475,c=.028874,u=-.005916,p=a,d=3*h,_=7*l,f=9*c,m=11*u,y=.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*(n+p*(i+p*(s+d*p*(r+p*o)))),e.y=t.phi*(a+p*(h+d*(l+c*p+u*d)))},e.inv=function(e,g){var v,x,w,b,C=e.x,S=e.y;for(S>y?S=y:S<-y&&(S=-y),v=S;v-=x=(v*(a+(w=v*v)*(h+(b=w*w)*(l+c*w+u*b)))-S)/(p+w*(d+b*(_+f*w+m*b))),!(t(x)<1e-11););g.phi=v,w=v*v,g.lam=C/(n+w*(i+w*(s+w*w*w*(r+w*o))))}},"natearth","Natural Earth","PCyl., Sph."),tt(function(e){var n=.84719,i=-.13063,s=-.04515,r=.05494,o=-.02326,a=.00331,h=1.01183,l=-.02625,c=.01926,u=-.00396,p=h,d=9*l,_=.45334622460635143*b;e.es=0,e.fwd=function(t,e){var p,d,_;_=(p=t.phi*t.phi)*(d=p*p),e.x=t.lam*(n+i*p+_*_*(s+r*p+o*d+a*_)),e.y=t.phi*(h+d*d*(l+c*p+u*d))},e.inv=function(e,f){var m,y,g,v,x,w=e.x,b=e.y;for(b>_?b=_:b<-_&&(b=-_),m=b;m-=y=(m*(h+(v=(g=m*m)*g)*v*(l+c*g+u*v))-b)/(p+v*v*(d+.21186*g+-.05148*v)),!(t(y)<1e-11););f.phi=m,x=(g=m*m)*(v=g*g),f.lam=w/(n+i*g+x*x*(s+r*g+o*v+a*x))}},"natearth2","Natural Earth 2","PCyl., Sph."),tt(function(e){e.inv=function(t,e){e.lam=2*t.x/(1+i(t.y)),e.phi=Ye(.5*(t.y+n(t.y)))},e.fwd=function(e,s){var r,o,a;for(r=2*n(e.phi),o=e.phi*e.phi,e.phi*=1.00371+o*(-.011412*o-.0935382),a=10;a&&(e.phi-=o=(e.phi+n(e.phi)-r)/(1+i(e.phi)),!(t(o)<1e-7));--a);s.x=.5*e.lam*(1+i(e.phi)),s.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+i(t.phi)),e.y=2*(t.phi-s(.5*t.phi))},e.inv=function(e,n){var r,o,a,h;for(a=.5*e.y,h=9;h>0&&(o=i(.5*n.phi),n.phi-=r=(n.phi-s(n.phi/2)-a)/(1-.5/(o*o)),!(t(r)<1e-7));--h);h?n.lam=2*e.x/(1+i(n.phi)):(n.phi=a<0?-k:k,n.lam=2*e.x)}},"nell_h","Nell-Hammer","PCyl., Sph."),tt(function(e){e.es=0,e.fwd=function(e,s){var r=1e-10;if(t(e.lam)<r)s.x=0,s.y=e.phi;else if(t(e.phi)<r)s.x=e.lam,s.y=0;else if(t(t(e.lam)-k)<r)s.x=e.lam*i(e.phi),s.y=k*n(e.phi);else if(t(t(e.phi)-k)<r)s.x=0,s.y=e.phi;else{var o=k/e.lam-e.lam/k,a=e.phi/k,h=n(e.phi),l=(1-a*a)/(h-a),u=o/l,p=(o*h/l-.5*o)/(1+(u*=u)),d=(h/u+.5*l)/(1+1/u);s.x=i(e.phi),s.x=c(p*p+s.x*s.x/(1+u)),s.x=k*(p+(e.lam<0?-s.x:s.x)),s.y=c(d*d-(h*h/u+l*h-1)/(1+1/u)),s.y=k*(d+(e.phi<0?s.y:-s.y))}}},"nicol","Nicolosi Globular","Misc Sph, no inv"),tt(function(t){wn(t,Z(t.params,"dh"))},"nsper","Near-sided perspective","Azi, Sph\nh="),tt(function(t){var e=Z(t.params,"dtilt")*S,n=Z(t.params,"dazi")*S,i=Z(t.params,"dh");wn(t,i,e,n)},"tpers","Tilted perspective","Azi, Sph\ntilt= azi= h="),tt(function(e){var n=[[.7557853228,0],[.249204646,.003371507],[-.001541739,.04105856],[-.10162907,.01727609],[-.26623489,-.36249218],[-.6870983,-1.1651967]],i=[1.5627014243,.5185406398,-.03333098,-.1052906,-.0368594,.007317,.0122,.00394,-.0013],s=[.6399175073,-.1358797613,.063294409,-.02526853,.0117879,-.0055161,.0026906,-.001333,67e-5,-34e-5];e.ra=1/(e.a=6378388),e.lam0=173*S,e.phi0=-41*S,e.x0=251e4,e.y0=6023150,e.inv=function(s,r){var o,a,h,l,c,u,p={r:s.y,i:s.x},d={};for(o=20;o>0&&((c=vn(p,n,d)).r-=s.y,c.i-=s.x,u=d.r*d.r+d.i*d.i,p.r+=h=-(c.r*d.r+c.i*d.i)/u,p.i+=l=-(c.i*d.r-c.r*d.i)/u,!(t(h)+t(l)<=1e-10));--o);if(o>0){for(r.lam=p.i,a=i.length-1,r.phi=i[a],--a;a>=0;--a)r.phi=i[a]+p.r*r.phi;r.phi=e.phi0+p.r*r.phi*.484813681109536}else r.lam=r.phi=x},e.fwd=function(t,i){var r=s.length-1,o={r:s[r]},a=2.0626480624709638*(t.phi-e.phi0);for(--r;r>=0;--r)o.r=s[r]+a*o.r;o.r*=a,o.i=t.lam,o=gn(o,n),i.x=o.i,i.y=o.r}},"nzmg","New Zealand Map Grid","fixed Earth"),tt(function(e){var r,o,a,c,u,p,d,_,f,m,y,g,v,w,b,A=1e-10;r=Z(e.params,"so_proj"),o=Q[r],r||j(-26),o&&"ob_tran"!=r||j(-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=S,e.fr_meter=C),Z(e.params,"to_alpha")?(_=Z(e.params,"ro_lon_c"),f=Z(e.params,"ro_lat_c"),m=Z(e.params,"ro_alpha"),t(t(f)-k)<=A&&j(-32),c=_+en(-i(m),-n(m)*n(f)),d=Ye(i(f)*n(m))):Z(e.params,"to_lat_p")?(c=Z(e.params,"ro_lon_p"),d=Z(e.params,"ro_lat_p")):(y=Z(e.params,"ro_lon_1"),v=Z(e.params,"ro_lat_1"),g=Z(e.params,"ro_lon_2"),w=Z(e.params,"ro_lat_2"),(t(v-w)<=A||(b=t(v))<=A||t(b-k)<=A||t(t(w)-k)<=A)&&j(-33),c=l(i(v)*n(w)*i(y)-n(v)*i(w)*i(g),n(v)*i(w)*n(g)-i(v)*n(w)*n(y)),d=h(-i(c-y)/s(v))),t(d)>A?(u=i(d),p=n(d),e.fwd=function(t,e){var s,r,o;s=i(t.lam),r=n(t.phi),o=i(t.phi),t.lam=Et(en(o*n(t.lam),p*o*s+u*r)+c),t.phi=Ye(p*r-u*o*s),a.fwd(t,e)},e.inv=a.inv?function(t,e){var s,r,o;a.inv(t,e),e.lam!=x&&(s=i(e.lam-=c),r=n(e.phi),o=i(e.phi),e.phi=Ye(p*r+u*o*s),e.lam=en(o*n(e.lam),p*o*s-u*r))}:null):(e.fwd=function(t,e){var s,r;s=i(t.phi),r=i(t.lam),t.lam=Et(en(s*n(t.lam),n(t.phi))+c),t.phi=Ye(-s*r),a.fwd(t,e)},e.inv=a.inv?function(t,e){var s,r;a.inv(t,e),e.lam!=x&&(s=i(e.phi),r=e.lam-c,e.lam=en(s*n(r),-n(e.phi)),e.phi=Ye(s*i(r)))}:null)},"ob_tran","General Oblique Transformation","Misc Sph\no_proj= plus parameters for projection\no_lat_p= o_lon_p= (new pole) or\no_alpha= o_lon_c= o_lat_c= or\no_lon_1= o_lat_1= o_lon_2= o_lat_2="),tt(function(t){var e,r,a,u,p,d,_,f,m,y,g;_=1/t.k0,f=t.k0,Z(t.params,"talpha")?(d=Z(t.params,"ralpha"),p=Z(t.params,"rlonc"),g=h(-i(d)/(-n(0)*n(d)))+p,m=o(i(0)*n(d))):(e=Z(t.params,"rlat_1"),r=Z(t.params,"rlat_2"),a=Z(t.params,"rlon_1"),u=Z(t.params,"rlon_2"),g=l(i(e)*n(r)*i(a)-n(e)*i(r)*i(u),n(e)*i(r)*n(u)-i(e)*n(r)*n(a)),a==-k&&(g=-g),m=h(-i(g-a)/s(e))),t.lam0=g+k,y=i(m),m=n(m),g=n(g),t.es=0,t.fwd=function(t,e){var r;e.y=n(t.lam),r=i(t.lam),e.x=h((s(t.phi)*y+m*e.y)/r),r<0&&(e.x+=b),e.x*=f,e.y=_*(m*n(t.phi)-y*i(t.phi)*e.y)},t.inv=function(t,e){var s,r;t.y/=_,t.x/=f,s=c(1-t.y*t.y),e.phi=o(t.y*m+s*y*(r=n(t.x))),e.lam=l(s*m*r-t.y*y,s*i(t.x))}},"ocea","Oblique Cylindrical Equal Area","Cyl, Sph lonc= alpha= or\nlat_1= lat_2= lon_1= lon_2="),tt(function(e){var r,a,_,f,m,y,g,v,w,C,S,A,M,D,P,T,L,R,F,G,O,B,q,$,V,H,W,K=1e-7,X=0,J=0,Y=0,Q=0,tt=0,et=0,nt=0,it=0;W=Z(e.params,"tno_rot"),0!=(A=Z(e.params,"talpha"))&&(nt=Z(e.params,"ralpha")),0!=(M=Z(e.params,"tgamma"))&&(X=Z(e.params,"rgamma")),A||M?(J=Z(e.params,"rlonc"),(it=Z(e.params,"tno_off")||Z(e.params,"tno_uoff"))&&(Z(e.params,"sno_uoff"),Z(e.params,"sno_off"))):(Y=Z(e.params,"rlon_1"),tt=Z(e.params,"rlat_1"),Q=Z(e.params,"rlon_2"),et=Z(e.params,"rlat_2"),(t(tt-et)<=K||(r=t(tt))<=K||t(r-k)<=K||t(t(e.phi0)-k)<=K||t(t(et)-k)<=K)&&j(-33)),a=c(e.one_es),t(e.phi0)>N?(v=n(e.phi0),_=i(e.phi0),r=1-e.es*v*v,P=_*_,P=c(1+e.es*P*P/e.one_es),D=P*e.k0*a/r,(m=(f=P*a/(_*c(r)))*f-1)<=0?m=0:(m=c(m),e.phi0<0&&(m=-m)),T=m+=f,T*=u(mn(e.phi0,v,e.e),P)):(P=1/a,D=e.k0,T=f=m=1),A||M?(A?(S=o(n(nt)/f),M||(X=nt)):nt=o(f*n(S=X)),e.lam0=J-o(.5*(m-1/m)*s(S))/P):(y=u(mn(tt,n(tt),e.e),P),g=u(mn(et,n(et),e.e),P),m=T/y,w=(g-y)/(g+y),C=((C=T*T)-g*y)/(C+g*y),(r=Y-Q)<-b?Q-=I:r>b&&(Q+=I),e.lam0=Et(.5*(Y+Q)-h(C*s(.5*P*(Y-Q))/w)/P),S=h(2*n(P*Et(Y-e.lam0))/(m-1/m)),X=nt=o(f*n(S))),G=n(S),O=i(S),B=n(X),q=i(X),R=1/(L=D*(F=1/P)),it?H=0:(H=t(L*h(c(f*f-1)/i(nt))),e.phi0<0&&(H=-H)),$=L*d(s(E-(m=.5*S))),V=L*d(s(E+m)),e.fwd=function(s,r){var o,a,h,c,p,_,f,m;t(t(s.phi)-k)>N?(o=.5*((p=T/u(mn(s.phi,n(s.phi),e.e),P))-(_=1/p)),a=.5*(p+_),c=n(P*s.lam),t(t(h=(o*G-c*O)/a)-1)<N&&z(),m=.5*L*d((1-h)/(1+h)),_=i(P*s.lam),f=t(_)<K?D*s.lam:L*l(o*O+c*G,_)):(m=s.phi>0?$:V,f=L*s.phi),W?(r.x=f,r.y=m):(f-=H,r.x=m*q+f*B,r.y=f*q-m*B)},e.inv=function(s,r){var o,a,h,d,_,f,m;W?(a=s.y,o=s.x):(a=s.x*q-s.y*B,o=s.y*q+s.x*B+H),d=.5*((h=p(-R*a))-1/h),_=.5*(h+1/h),f=n(R*o),t(t(m=(f*O+d*G)/_)-1)<N?(r.lam=0,r.phi=m<0?-k:k):(r.phi=T/c((1+m)/(1-m)),(r.phi=yn(u(r.phi,1/P),e.e))==x&&U(),r.lam=-F*l(d*O-f*G,i(R*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 s=1e-10,r={};t(t(e.phi0)-k)<=s?r.mode=e.phi0<0?1:0:t(e.phi0)>s?(r.mode=3,r.sinph0=n(e.phi0),r.cosph0=i(e.phi0)):r.mode=2,e.fwd=function(o,a){var h,l,c;switch(l=i(o.phi),h=i(o.lam),r.mode){case 2:l*h<-1e-10&&z(),a.y=n(o.phi);break;case 3:r.sinph0*(c=n(o.phi))+r.cosph0*l*h<-1e-10&&z(),a.y=r.cosph0*c-r.sinph0*l*h;break;case 0:h=-h;case 1:t(o.phi-e.phi0)-s>k&&z(),a.y=l*h}a.x=l*n(o.lam)},e.inv=function(n,i){var h,u,p;if((p=h=_(n.x,n.y))>1&&(p-1>s&&U(),p=1),u=c(1-p*p),t(h)<=s)i.phi=e.phi0,i.lam=0;else{switch(r.mode){case 0:n.y=-n.y,i.phi=a(p);break;case 1:i.phi=-a(p);break;case 2:case 3:2==r.mode?(i.phi=n.y*p/h,n.x*=p,n.y=u*h):(i.phi=u*r.sinph0+n.y*p*r.cosph0/h,n.y=(u-r.sinph0*i.phi)*h,n.x*=p*r.cosph0),t(i.phi)>=1?i.phi=i.phi<0?-k:k:i.phi=o(i.phi)}i.lam=0!=n.y||3!=r.mode&&2!=r.mode?l(n.x,n.y):0==n.x?0:n.x<0?-k:k}},e.es=0},"ortho","Orthographic","Azi, Sph."),tt(function(e){var n=1.0148,i=.23185,s=-.14499,r=.02406,o=n,a=5*i,h=7*s,l=908571831.7;e.es=0,e.fwd=function(t,e){var o=t.phi*t.phi;e.x=t.lam,e.y=t.phi*(n+o*o*(i+o*(s+r*o)))},e.inv=function(e,c){var u,p,d,_;for(u=e.y,e.y>l?e.y=l:e.y<-l&&(e.y=-l),_=100;_&&(u-=p=(u*(n+(d=u*u)*d*(i+d*(s+r*d)))-e.y)/(o+d*d*(a+d*(h+.21654*d))),!(t(p)<1e-11));--_);c.phi=u,c.lam=e.x}},"patterson","Patterson Cylindrical","Cyl., Sph."),tt(function(e){var r,a,h=1e-10,l=1e-12;e.es?(a=Xe(e.es),r=Ze(e.phi0,n(e.phi0),i(e.phi0),a),e.fwd=function(s,o){var l,c,u;t(s.phi)<=h?(o.x=s.lam,o.y=-r):(c=n(s.phi),l=t(u=i(s.phi))>h?We(c,u,e.es)/c:0,o.x=l*n(s.lam*=c),o.y=Ze(s.phi,c,u,a)-r+l*(1-i(s.lam)))},e.inv=function(u,p){var d,_,f,m,y,g,v,x,w,b,C=u.x,S=u.y;if(t(S+=r)<=h)p.lam=C,p.phi=0;else{for(d=S*S+C*C,p.phi=S,b=20;b>0&&(y=(f=n(p.phi))*(m=i(p.phi)),t(m)<l&&U(),_=f*(x=c(1-e.es*f*f))/m,v=(g=Ze(p.phi,f,m,a))*g+d,x=e.one_es/(x*x*x),p.phi+=w=(g+g+_*v-2*S*(_*g+1))/(e.es*y*(v-2*S*g)/_+2*(S-g)*(_*x-1/y)-x-x),!(t(w)<=l));--b);b||U(),_=n(p.phi),p.lam=o(C*s(p.phi)*c(1-e.es*_*_))/n(p.phi)}}):(r=-e.phi0,e.fwd=function(o,a){var l,c;t(o.phi)<=h?(a.x=o.lam,a.y=r):(l=1/s(o.phi),a.x=n(c=o.lam*n(o.phi))*l,a.y=o.phi-e.phi0+l*(1-i(c)))},e.inv=function(i,r){var a,l,c,u;if(t(i.y=e.phi0+i.y)<=h)r.lam=i.x,r.phi=0;else{r.phi=i.y,a=i.x*i.x+i.y*i.y,u=10;do{c=s(r.phi),r.phi-=l=(i.y*(r.phi*c+1)-r.phi-.5*(r.phi*r.phi+a)*c)/((r.phi-i.y)/c-1)}while(t(l)>1e-10&&--u);u||U(),r.lam=o(i.x*s(r.phi))/n(r.phi)}})},"poly","Polyconic (American)","Conic, Sph&Ell"),tt(function(e){var s=1.8949,r=1.71848,o=.6141848493043784,a=1.0471975511965976;e.es=0,e.fwd=function(e,h){var l,c,u,p,d;for(l=o*n(e.phi),u=e.phi*e.phi,e.phi*=.615709+u*(.00909953+.0046292*u),d=10;d&&(c=i(e.phi),u=n(e.phi),e.phi-=p=(e.phi+u*(c-1)-l)/(1+c*(c-1)-u*u),!(t(p)<1e-10));--d);d||(e.phi=e.phi<0?-a:a),h.x=s*e.lam*(i(e.phi)-.5),h.y=r*n(e.phi)},e.inv=function(t,e){var a;e.phi=Ye(t.y/r),e.lam=t.x/(s*((a=i(e.phi))-.5)),e.phi=Ye((e.phi+n(e.phi)*(a-1))/o)}},"putp2","Putnins P2","PCyl., Sph."),tt(bn,"putp3","Putnins P3","PCyl., Sph."),tt(function(t){bn(t,!0)},"putp3p","Putnins P3'","PCyl., Sph."),tt(function(t){Cn(t,.874038744,3.883251825)},"putp4p","Putnins P4'","PCyl., Sph."),tt(function(t){Cn(t,1,4.442882938)},"weren","Werenskiold I","PCyl., Sph."),tt(Sn,"putp5","Putnins P5","PCyl., Sph."),tt(function(t){Sn(t,!0)},"putp5p","Putnins P5'","PCyl., Sph."),tt(An,"putp6","Putnins P6","PCyl., Sph."),tt(function(t){An(t,!0)},"putp6p","Putnins P6'","PCyl., Sph."),tt(function(e){var r,o,u,p;function d(e,n,i){var s,r;return e<1e-10?(s=0,r=0):(r=l(n,i),t(r)<=E?s=0:r>E&&r<=k+E?(s=1,r-=k):r>k+E||r<=-(k+E)?(s=2,r=r>=0?r-b:r+b):(s=3,r+=k)),{area:s,theta:r}}function _(t,e){var n=t+e;return n<-b?n+=I:n>+b&&(n-=I),n}r=e.phi0>=k-E/2?4:e.phi0<=-(k-E/2)?5:t(e.lam0)<=E?0:t(e.lam0)<=k+E?e.lam0>0?1:3:2,0!==e.es&&(e.a,e.a,o=e.a*c(1-e.es),u=1-(e.a-o)/e.a,p=u*u),e.fwd=function(t,o){var l,u,f,m,y,g,v,x,w,C,S,A,M,I;l=0!==e.es?h(p*s(t.phi)):t.phi,u=t.lam,4==r?(m=k-l,u>=E&&u<=k+E?(v=0,f=u-k):u>k+E||u<=-(k+E)?(v=1,f=u>0?u-b:u+b):u>-(k+E)&&u<=-E?(v=2,f=u+k):(v=3,f=u)):5==r?(m=k+l,u>=E&&u<=k+E?(v=0,f=-u+k):u<E&&u>=-E?(v=1,f=-u):u<-E&&u>=-(k+E)?(v=2,f=-u-k):(v=3,f=u>0?-u+b:-u-b)):(1==r?u=_(u,+k):2==r?u=_(u,+b):3==r&&(u=_(u,-k)),S=n(l),A=i(l),M=n(u),x=A*i(u),w=A*M,C=S,0==r?I=d(m=a(x),C,w):1==r?I=d(m=a(w),C,-x):2==r?I=d(m=a(-x),C,-w):3==r?I=d(m=a(-w),C,x):(m=0,I={area:0,theta:0}),f=I.theta,v=I.area),g=h(12/b*(f+a(n(f)*i(E))-k)),y=c((1-i(m))/(i(g)*i(g))/(1-i(h(1/i(f))))),1==v?g+=k:2==v?g+=b:3==v&&(g+=D),o.x=y*i(g),o.y=y*n(g)},e.inv=function(d,f){var m,y,g,v,x,w,C,S,A,M,E,D,I;if(y=h(c(d.x*d.x+d.y*d.y)),m=l(d.y,d.x),d.x>=0&&d.x>=t(d.y)?M=0:d.y>=0&&d.y>=t(d.x)?(M=1,m-=k):d.x<0&&-d.x>=t(d.y)?(M=2,m=m<0?m+b:m-b):(M=3,m+=k),A=b/12*s(m),x=n(A)/(i(A)-1/c(2)),w=h(x),(C=1-(g=i(m))*g*(v=s(y))*v*(1-i(h(1/i(w)))))<-1?C=-1:C>1&&(C=1),4==r)S=a(C),f.phi=k-S,f.lam=0==M?w+k:1==M?w<0?w+b:w-b:2==M?w-k:w;else if(5==r)S=a(C),f.phi=S-k,f.lam=0==M?-w+k:1==M?-w:2==M?-w-k:w<0?-w-b:-w+b;else{var P,T,L;A=(P=C)*P,T=(A+=(L=A>=1?0:c(1-A)*n(w))*L)>=1?0:c(1-A),1==M?(A=T,T=-L,L=A):2==M?(T=-T,L=-L):3==M&&(A=T,T=L,L=-A),1==r?(A=P,P=-T,T=A):2==r?(P=-P,T=-T):3==r&&(A=P,P=T,T=-A),f.phi=a(-L)-k,f.lam=l(T,P),1==r?f.lam=_(f.lam,-k):2==r?f.lam=_(f.lam,-b):3==r&&(f.lam=_(f.lam,+k))}0!==e.es&&(E=f.phi<0?1:0,D=s(f.phi),I=o/c(D*D+p),f.phi=h(c(e.a*e.a-I*I)/(u*I)),E&&(f.phi=-f.phi))}},"qsc","Quadrilateralized Spherical Cube","Azi, Sph."),tt(function(n){var i=l([[1,22199e-21,-715515e-10,31103e-10],[.9986,-482243e-9,-24897e-9,-13309e-10],[.9954,-83103e-8,-448605e-10,-9.86701e-7],[.99,-.00135364,-59661e-9,36777e-10],[.9822,-.00167442,-449547e-11,-572411e-11],[.973,-.00214868,-903571e-10,1.8736e-8],[.96,-.00305085,-900761e-10,164917e-11],[.9427,-.00382792,-653386e-10,-26154e-10],[.9216,-.00467746,-10457e-8,481243e-11],[.8962,-.00536223,-323831e-10,-543432e-11],[.8679,-.00609363,-113898e-9,332484e-11],[.835,-.00698325,-640253e-10,9.34959e-7],[.7986,-.00755338,-500009e-10,9.35324e-7],[.7597,-.00798324,-35971e-9,-227626e-11],[.7186,-.00851367,-701149e-10,-86303e-10],[.6732,-.00986209,-199569e-9,191974e-10],[.6213,-.010418,883923e-10,624051e-11],[.5722,-.00906601,182e-6,624051e-11],[.5322,-.00677797,275608e-9,624051e-11]]),s=l([[-520417e-23,.0124,121431e-23,-845284e-16],[.062,.0124,-1.26793e-9,4.22642e-10],[.124,.0124,5.07171e-9,-1.60604e-9],[.186,.0123999,-1.90189e-8,6.00152e-9],[.248,.0124002,7.10039e-8,-2.24e-8],[.31,.0123992,-2.64997e-7,8.35986e-8],[.372,.0124029,9.88983e-7,-3.11994e-7],[.434,.0123893,-369093e-11,-4.35621e-7],[.4958,.0123198,-102252e-10,-3.45523e-7],[.5571,.0121916,-154081e-10,-5.82288e-7],[.6176,.0119938,-241424e-10,-5.25327e-7],[.6769,.011713,-320223e-10,-5.16405e-7],[.7346,.0113541,-397684e-10,-6.09052e-7],[.7903,.0109107,-489042e-10,-104739e-11],[.8435,.0103431,-64615e-9,-1.40374e-9],[.8936,.00969686,-64636e-9,-8547e-9],[.9394,.00840947,-192841e-9,-42106e-10],[.9761,.00616527,-256e-6,-42106e-10],[1,.00328947,-319159e-9,-42106e-10]]),r=.8487,o=1.3523;function a(t,e){return t[0]+e*(t[1]+e*(t[2]+e*t[3]))}function h(t,e){return t[1]+e*(t[2]+t[2]+3*e*t[3])}function l(t){return t.map(function(t){return new Float32Array(t)})}n.es=0,n.fwd=function(n,h){var l,c;(l=e(11.459155902616464*(c=t(n.phi))))<0&&z(),l>=18&&(l=17),c=C*(c-.08726646259971647*l),h.x=a(i[l],c)*r*n.lam,h.y=a(s[l],c)*o,n.phi<0&&(h.y=-h.y)},n.inv=function(n,l){var c,u,p,d;if(l.lam=n.x/r,l.phi=t(n.y/o),l.phi>=1)l.phi>1.000001?U():(l.phi=n.y<0?-k:k,l.lam/=i[18][0]);else{if((d=e(18*l.phi))<0||d>=18)return U();for(;;)if(s[d][0]>l.phi)--d;else{if(!(s[d+1][0]<=l.phi))break;++d}for(p=new Float32Array(s[d]),c=5*(l.phi-p[0])/(s[d+1][0]-p[0]),p[0]-=l.phi;c-=u=a(p,c)/h(p,c),!(t(u)<1e-8););l.phi=(5*d+c)*S,n.y<0&&(l.phi=-l.phi),l.lam/=a(i[d],c)}}},"robin","Robinson","PCyl., Sph."),tt(Mn("EULER"),"euler","Euler","Conic, Sph\nlat_1= and lat_2="),tt(Mn("MURD1"),"murd1","Murdoch I","Conic, Sph\nlat_1= and lat_2="),tt(Mn("MURD2"),"murd2","Murdoch II","Conic, Sph\nlat_1= and lat_2="),tt(Mn("MURD3"),"murd3","Murdoch III","Conic, Sph\nlat_1= and lat_2="),tt(Mn("PCONIC"),"pconic","Perspective Conic","Conic, Sph\nlat_1= and lat_2="),tt(Mn("TISSOT"),"tissot","Tissot","Conic, Sph\nlat_1= and lat_2="),tt(Mn("VITK1"),"vitk1","Vitkovsky I","Conic, Sph\nlat_1= and lat_2="),tt(function(e){var r,o,a,l,u,_,f,m,y;a=.5*e.e,f=i(e.phi0),f*=f,o=c(1+e.es*f*f*e.rone_es),y=n(e.phi0),u=i(m=Ye(_=y/o)),y*=e.e,r=d(s(E+.5*m))-o*(d(s(E+.5*e.phi0))-a*d((1+y)/(1-y))),l=e.k0*c(e.one_es)/(1-y*y),e.inv=function(c,f){var m,y,g,v,x,w,b,C,S;for(g=2*(h(p(c.y/l))-E),v=c.x/l,x=i(g),m=Ye(u*n(g)+_*x*i(v)),y=Ye(x*n(v)/i(m)),b=(r-d(s(E+.5*m)))/o,S=6;S&&(w=e.e*n(m),m-=C=(b+d(s(E+.5*m))-a*d((1+w)/(1-w)))*(1-w*w)*i(m)*e.rone_es,!(t(C)<1e-10));--S);S?(f.phi=m,f.lam=y/o):U()},e.fwd=function(t,c){var f,m,y,g,v,x;v=e.e*n(t.phi),f=2*h(p(o*(d(s(E+.5*t.phi))-a*d((1+v)/(1-v)))+r))-k,m=o*t.lam,x=i(f),y=Ye(u*n(f)-_*x*i(m)),g=Ye(x*n(m)/i(y)),c.x=l*g,c.y=l*d(s(E+.5*y))}},"somerc","Swiss. Obl. Mercator","Cyl, Ell\nFor CH1903"),tt(function(t){var e=Z(t.params,"tlat_ts")?Z(t.params,"rlat_ts"):k;En(t,e)},"stere","Stereographic","Azi, Sph&Ell\nlat_ts="),tt(function(t){t.phi0=Z(t.params,"bsouth")?-k:k,t.k0=.994,t.x0=2e6,t.y0=2e6,t.lam0=0,t.es||j(-34),En(t,k)},"ups","Universal Polar Stereographic","Azi, Sph&Ell\nsouth"),tt(function(e){var r,a,p,d,f,m,y,g,v,x=(r=e.e,a=e.phi0,p=r*r,d=n(a),f=i(a),m=c(1-p)/(1-p*d*d),y=c(1+p*f*f*f*f/(1-p)),g=o(d/y),v=.5*y*r,{e:r,K:s(.5*g+E)/(u(s(.5*a+E),y)*kn(r*d,v)),C:y,chi:g,ratexp:v,rc:m}),w=x.chi,b=2*x.rc,C=n(w),S=i(w);e.fwd=function(t,r){var o,a,l,c;t=function(t,e){return{phi:2*h(e.K*u(s(.5*t.phi+E),e.C)*kn(e.e*n(t.phi),e.ratexp))-k,lam:e.C*t.lam}}(t,x),a=n(t.phi),o=i(t.phi),l=i(t.lam),c=e.k0*b/(1+C*a+S*o*l),r.x=c*o*n(t.lam),r.y=c*(S*a-C*o*l)},e.inv=function(r,a){var c,p,d,f,m=r.x/e.k0,y=r.y/e.k0;(c=_(m,y))?(p=2*l(c,b),d=n(p),f=i(p),a.phi=o(f*C+y*d*S/c),a.lam=l(m*d,c*S*f-y*C*d)):(a.phi=w,a.lam=0),function(e,i){e.phi;var r,o,a=u(s(.5*e.phi+E)/i.K,1/i.C);for(e.lam/=i.C,r=20;r>0&&(o=2*h(a*kn(i.e*n(e.phi),-.5*i.e))-k,!(t(o-e.phi)<1e-14));--r)e.phi=o;r||B(-17)}(a,x)}},"sterea","Oblique Stereographic Alternative","Azimuthal, Sph&Ell"),tt(function(t){Dn(t,1.50488,1.35439,!1)},"kav5","Kavraisky V","PCyl., Sph."),tt(function(t){Dn(t,2,2,!1)},"qua_aut","Quartic Authalic","PCyl., Sph."),tt(function(t){Dn(t,2,2,!0)},"fouc","Foucaut","PCyl., Sph."),tt(function(t){Dn(t,1.48875,1.36509,!1)},"mbt_s","McBryde-Thomas Flat-Polar Sine (No. 1)","PCyl., Sph."),tt(function(t){t.es=0,t.fwd=function(e,r){r.x=i(e.phi)*n(e.lam)/t.k0,r.y=t.k0*(l(s(e.phi),i(e.lam))-t.phi0)},t.inv=function(e,s){var r;e.y=e.y/t.k0+t.phi0,e.x*=t.k0,r=c(1-e.x*e.x),s.phi=o(r*n(e.y)),s.lam=l(e.x,r*i(e.y))}},"tcea","Transverse Cylindrical Equal Area","Cyl, Sph"),tt(function(t){t.es=0,t.fwd=function(t,e){var i=s(t.phi/2),r=n(E*i);e.x=t.lam*(.74482-.34588*r*r),e.y=1.70711*i},t.inv=function(t,e){var i=t.y/1.70711,s=n(E*i);e.lam=t.x/(.74482-.34588*s*s),e.phi=2*h(i)}},"times","Times","Cyl, Sph"),tt(function(e){Z(e.params,"bapprox")?In(e):function(e){if(0===e.es)return In(e);hn(e);var n=e.fwd,i=e.inv;In(e);var s=e.fwd,r=e.inv;e.fwd=function(e,i){t(e.lam)>3*S?n(e,i):s(e,i)},e.inv=function(e,n){t(e.x)>.053-.022*e.y*e.y?i(e,n):r(e,n)}}(e)},"tmerc","Transverse Mercator","Cyl, Sph&Ell"),tt(function(t){var n;t.es||j(-34),t.y0=Z(t.params,"bsouth")?1e7:0,t.x0=5e5,Z(t.params,"tzone")?(n=Z(t.params,"izone"))>0&&n<=60?--n:j(-35):(n=e(30*(Et(t.lam0)+b)/b))<0?n=0:n>=60&&(n=59),t.lam0=(n+.5)*b/30-b,t.k0=.9996,t.phi0=0,hn(t)},"utm","Universal Transverse Mercator (UTM)","Cyl, Sph\nzone= south"),tt(function(t){var e,r,o,a,h,c,u,p,d,f,m,y,g,v,x,w,b,C,S,A,M,E,D;A=Z(t.params,"rlat_1"),C=Z(t.params,"rlon_1"),M=Z(t.params,"rlat_2"),S=Z(t.params,"rlon_2"),A==M&&C==S&&j(-25),t.lam0=Et(.5*(C+S)),f=Et(S-C),e=i(A),o=i(M),r=n(A),a=n(M),c=e*a,u=r*o,h=e*o*n(f),d=Qe(r*a+e*o*i(f)),m=.5*d,E=l(o*n(f),e*a-r*o*i(f)),v=i(D=Ye(e*n(E))),x=n(D),w=Et(l(e*i(E),r)-m),f*=.5,b=k-l(n(E)*r,i(E))-f,y=s(m),g=.5/n(m),p=.5/d,d*=d,t.fwd=function(t,s){var l,_,m,y,g,v,x;v=n(t.phi),x=i(t.phi),_=Qe(r*v+e*x*i(y=t.lam+f)),m=Qe(a*v+o*x*i(g=t.lam-f)),_*=_,m*=m,s.x=p*(l=_-m),l=d-l,s.y=p*tn(4*d*m-l*l),h*v-x*(c*n(y)-u*n(g))<0&&(s.y=-s.y)},t.inv=function(t,e){var s,r,o,a,h,c;o=(s=i(_(t.y,t.x+m)))+(r=i(_(t.y,t.x-m))),a=s-r,e.lam=-l(a,o*y),e.phi=Qe(_(y*o,a)*g),t.y<0&&(e.phi=-e.phi),c=n(e.phi),h=i(e.phi),e.phi=Ye(x*c+v*h*(o=i(e.lam-=w))),e.lam=l(h*n(e.lam),x*h*o-v*c)+b},t.es=0},"tpeqd","Two Point Equidistant","Misc Sph\nlat_1= lon_1= lat_2= lon_2="),tt(function(t){var e,s,r,o,a,h;(o=Z(t.params,"dn"))>0&&o<=1==0&&j(-40),r=Z(t.params,"dq")/3,a=Z(t.params,"ralpha"),h=o*n(a),e=i(a)/c(1-h*h),s=1/(e*o),t.fwd=function(t,a){var h=t.phi=Ye(o*n(t.phi));a.x=e*t.lam*i(t.phi),h*=h,a.y=t.phi*(1+h*r)*s},t.es=0},"urm5","Urmaev V","PCyl., Sph., no inv.\nn= q= alpha="),tt(function(t){var e=Z(t.params,"dn");(e<=0||e>1)&&j(-40),Pn(t,e)},"urmfps","Urmaev Flat-Polar Sinusoidal","PCyl, Sph.\nn="),tt(function(t){Pn(t,.8660254037844386)},"wag1","Wagner I (Kavraisky VI)","PCyl, Sph."),tt(function(e){var n=1e-10,r=.3333333333333333,h=9.869604401089358,l=19.739208802178716,u=4.934802200544679;e.fwd=function(e,i){var r,a,h,l,u;(u=t(e.phi/k))-n>1&&z(),u>1&&(u=1),t(e.phi)<=n?(i.x=e.lam,i.y=0):t(e.lam)<=n||t(u-1)<n?(i.x=0,i.y=b*s(.5*o(u)),e.phi<0&&(i.y=-i.y)):(a=(r=.5*t(b/e.lam-e.lam/b))*r,h=c(1-u*u),l=(h/=u+h-1)*h,u=h*(2/u-1),u*=u,i.x=h-u,h=u+a,i.x=b*(r*i.x+c(a*i.x*i.x-h*(l-u)))/h,e.lam<0&&(i.x=-i.x),i.y=t(i.x/b),i.y=1-i.y*(i.y+2*r),i.y<-n&&z(),i.y<0?i.y=0:i.y=c(i.y)*(e.phi<0?-b:b))},e.inv=function(e,s){var o,p,d,_,f,m,y,g,v,x,w,C,S;if(C=e.x*e.x,(w=t(e.y))<n)return s.phi=0,o=C*C+l*(C+u),s.lam=t(e.x)<=n?0:.5*(C-h+c(o))/e.x,s;S=e.y*e.y,_=(d=-b*w*((g=C+S)+h))+h*(g-3*S),p=b*w,v=2*c(-r*(m=d/(f=(y=g*g)+I*(w*g+b*(S+b*(w+k))))-r*(_/=f)*_)),(o=t(x=3*(x=.07407407407407407*_*_*_+(p*p-r*_*d)/f)/(m*v)))-n<=1?(x=o>1?x>0?0:b:a(x),s.phi=b*(v*i(x*r+4.188790204786391)-r*_),e.y<0&&(s.phi=-s.phi),o=y+l*(C-S+u),s.lam=t(e.x)<=n?0:.5*(g-h+(o<=0?0:c(o)))/e.x):U()}},"vandg","van der Grinten (I)","Misc Sph"),tt(function(t){Tn(t,!1)},"vandg2","van der Grinten II","Misc Sph, no inv."),tt(function(t){Tn(t,!0)},"vandg3","van der Grinten III","Misc Sph, no inv."),tt(function(e){e.es=0,e.fwd=function(e,n){var i,s,r,o,a,h,l,u,p=1e-10;t(e.phi)<p?(n.x=e.lam,n.y=0):t(e.lam)<p||t(t(e.phi)-k)<p?(n.x=0,n.y=e.phi):(h=(o=.5*((r=t(P*e.phi))*(8-r*(2+(a=r*r)))-5)/(a*(r-1)))*o,l=P*e.lam,l=c((l+=1/l)*l-4),t(e.lam)-k<0&&(l=-l),i=r+o,i=(l*((i*=i)+h-1)+2*c(i*(a+h*(u=l*l)-1)+(1-a)*(a*((s=r+3*o)*s+4*h)+h*(12*r*o+4*h))))/(4*i+u),n.x=k*i,n.y=k*c(1+l*t(i)-i*i),e.lam<0&&(n.x=-n.x),e.phi<0&&(n.y=-n.y))}},"vandg4","van der Grinten IV","Misc Sph, no inv."),tt(function(t){var e=.92483,s=1.38725,r=.88022,o=.8855;t.fwd=function(t,a){t.phi=Ye(r*n(o*t.phi)),a.x=e*t.lam*i(t.phi),a.y=s*t.phi},t.inv=function(t,a){a.phi=t.y/s,a.lam=t.x/(e*i(a.phi)),a.phi=Ye(n(a.phi)/r)/o}},"wag2","Wagner II","PCyl., Sph."),tt(function(t){var e=.6666666666666666,n=Z(t.params,"rlat_ts"),s=i(n)/i(2*n/3);t.es=0,t.fwd=function(t,n){n.x=s*t.lam*i(e*t.phi),n.y=t.phi},t.inv=function(t,n){n.phi=t.y,n.lam=t.x/(s*i(e*n.phi))}},"wag3","Wagner III","PCyl., Sph.\nlat_ts="),tt(function(t){t.es=0,t.fwd=function(t,e){var s,r,a;s=o(e.y=.9063077870366499*n(t.phi)),e.x=2.66723*(r=i(s))*n(t.lam/=3),e.y*=1.24104*(a=1/c(.5*(1+r*i(t.lam)))),e.x*=a}},"wag7","Wagner VII","Misc Sph, no inv."),tt(function(t){var e=i(Z(t.params,"rlat_ts"));t.fwd=function(t,n){n.x=.5*t.lam*(e+i(t.phi)),n.y=t.phi},t.inv=function(t,n){n.phi=t.y,n.lam=2*t.x/(e+i(n.phi))},t.es=0},"wink1","Winkel I","PCyl., Sph.\nlat_ts="),tt(function(e){var s=i(Z(e.params,"rlat_1"));e.fwd=function(e,r){var o,a,h,l=e.phi;for(r.y=l*P,o=b*n(l),l*=1.8,h=10;h&&(l-=a=(l+n(l)-o)/(1+i(l)),!(t(a)<1e-7));--h);h?l*=.5:l=l<0?-k:k,r.x=.5*e.lam*(i(l)+s),r.y=E*(n(l)+r.y)},e.inv=null,e.es=0},"wink2","Winkel II","PCyl., Sph., no inv.\nlat_1=");var Ln=Pt;Ln.pj_init=mt,Ln.pj_fwd=kt,Ln.pj_inv=Dt,Ln.pj_transform=Ct,Ln.pj_add=tt,Ln.pj_fwd_deg=function(t,e){return kt({lam:t.lam*S,phi:t.phi*S},e)},Ln.pj_inv_deg=function(t,e){var n=Dt(t,e);return{lam:n.lam*C,phi:n.phi*C}},Ln.pj_transform_point=bt,Ln.internal={dmstod:W,dmstor:H,get_rtodms:function(t,e,n,i){var s=It(t,e,n,i);return function(t){return s(t*C)}},get_dtodms:It,get_proj_defn:it,pj_latlong_from_proj:function(t){return mt("+proj=latlong"+nt(t))},pj_get_params:J,pj_datums:rt,pj_list:Q,pj_ellps:ht,pj_units:ct,pj_read_init_opts:ft,find_datum:at,DEG_TO_RAD:S,RAD_TO_DEG:C,wkt_parse:Be,wkt_unpack:ze,convert_wkt_quotes:Ue,wkt_to_proj4:function(t){var e,n,i=Be(t);return i.PROJCS?e=Ot(n=i.PROJCS)(n):i.GEOGCS?e="+proj=longlat "+Wt(i.GEOGCS):i.GEOCCS?$t("geocentric coordinates are not supported"):$t("missing a supported WKT CS type"),e},wkt_from_proj4:function(t){return t.length&&(t=mt(t)),Fe(et(t)?{GEOGCS:Yt(t)}:re(t))},wkt_make_projcs:re,wkt_get_geogcs_name:ee,wkt_stringify:Fe,mproj_insert_libcache:function(t,e){dt[t]=e},mproj_search_libcache:_t,GeographicLib:Ve},v.exports=Ln}();var b=s.exports,C=e({__proto__:null,default:n(b)},[b]);class S{constructor(){this.ids=[],this.values=[],this.length=0}clear(){this.length=0}push(t,e){let n=this.length++;for(;n>0;){const t=n-1>>1,i=this.values[t];if(e>=i)break;this.ids[n]=this.ids[t],this.values[n]=i,n=t}this.ids[n]=t,this.values[n]=e}pop(){if(0===this.length)return;const t=this.ids,e=this.values,n=t[0],i=--this.length;if(i>0){const n=t[i],s=e[i];let r=0;const o=i>>1;for(;r<o;){const n=1+(r<<1),o=n+1,a=n+(+(o<i)&+(e[o]<e[n]));if(e[a]>=s)break;t[r]=t[a],e[r]=e[a],r=a}t[r]=n,e[r]=s}return n}peek(){return this.length>0?this.ids[0]:void 0}peekValue(){return this.length>0?this.values[0]:void 0}shrink(){this.ids.length=this.values.length=this.length}}const A=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class M{static from(t,e=0){if(e%8!=0)throw new Error("byteOffset must be 8-byte aligned.");if(!t||void 0===t.byteLength||t.buffer)throw new Error("Data must be an instance of ArrayBuffer or SharedArrayBuffer.");const[n,i]=new Uint8Array(t,e+0,2);if(251!==n)throw new Error("Data does not appear to be in a Flatbush format.");const s=i>>4;if(3!==s)throw new Error(`Got v${s} data when expected v3.`);const r=A[15&i];if(!r)throw new Error("Unrecognized array type.");const[o]=new Uint16Array(t,e+2,1),[a]=new Uint32Array(t,e+4,1);return new M(a,o,r,void 0,t,e)}constructor(t,e=16,n=Float64Array,i=ArrayBuffer,s,r=0){if(void 0===t)throw new Error("Missing required argument: numItems.");if(isNaN(t)||t<=0)throw new Error(`Unexpected numItems value: ${t}.`);this.numItems=+t,this.nodeSize=Math.min(Math.max(+e,2),65535),this.byteOffset=r;let 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=n,this.IndexArrayType=a<16384?Uint16Array:Uint32Array;const h=A.indexOf(n),l=4*a*n.BYTES_PER_ELEMENT;if(h<0)throw new Error(`Unexpected typed array class: ${n}.`);if(s)this.data=s,this._boxes=new n(s,r+8,4*a),this._indices=new this.IndexArrayType(s,r+8+l,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 s=this.data=new i(8+l+a*this.IndexArrayType.BYTES_PER_ELEMENT);this._boxes=new n(s,8,4*a),this._indices=new this.IndexArrayType(s,8+l,a),this._pos=0,this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,new Uint8Array(s,0,2).set([251,48+h]),new Uint16Array(s,2,1)[0]=e,new Uint32Array(s,4,1)[0]=t}this._queue=new S}add(t,e,n=t,i=e){const s=this._pos>>2,r=this._boxes;return this._indices[s]=s,r[this._pos++]=t,r[this._pos++]=e,r[this._pos++]=n,r[this._pos++]=i,t<this.minX&&(this.minX=t),e<this.minY&&(this.minY=e),n>this.maxX&&(this.maxX=n),i>this.maxY&&(this.maxY=i),s}finish(){if(this._pos>>2!==this.numItems)throw new Error(`Added ${this._pos>>2} items when expected ${this.numItems}.`);const t=this._boxes;if(this.numItems<=this.nodeSize)return t[this._pos++]=this.minX,t[this._pos++]=this.minY,t[this._pos++]=this.maxX,void(t[this._pos++]=this.maxY);const e=this.maxX-this.minX||1,n=this.maxY-this.minY||1,i=new Uint32Array(this.numItems);for(let s=0,r=0;s<this.numItems;s++){const o=t[r++],a=t[r++],h=t[r++],l=t[r++],c=Math.floor(65535*((o+h)/2-this.minX)/e),u=Math.floor(65535*((a+l)/2-this.minY)/n);i[s]=I(c,u)}k(i,t,this._indices,0,this.numItems-1,this.nodeSize);for(let e=0,n=0;e<this._levelBounds.length-1;e++){const i=this._levelBounds[e];for(;n<i;){const e=n;let s=t[n++],r=t[n++],o=t[n++],a=t[n++];for(let e=1;e<this.nodeSize&&n<i;e++)s=Math.min(s,t[n++]),r=Math.min(r,t[n++]),o=Math.max(o,t[n++]),a=Math.max(a,t[n++]);this._indices[this._pos>>2]=e,t[this._pos++]=s,t[this._pos++]=r,t[this._pos++]=o,t[this._pos++]=a}}}search(t,e,n,i,s){if(this._pos!==this._boxes.length)throw new Error("Data not yet indexed - call index.finish().");let r=this._boxes.length-4;const o=[],a=[];for(;void 0!==r;){const h=Math.min(r+4*this.nodeSize,E(r,this._levelBounds));for(let l=r;l<h;l+=4){const h=this._boxes[l];if(n<h)continue;const c=this._boxes[l+1];if(i<c)continue;const u=this._boxes[l+2];if(t>u)continue;const p=this._boxes[l+3];if(e>p)continue;const d=0|this._indices[l>>2];r>=4*this.numItems?o.push(d):(void 0===s||s(d,h,c,u,p))&&a.push(d)}r=o.pop()}return a}neighbors(t,e,n=1/0,i=1/0,s){if(this._pos!==this._boxes.length)throw new Error("Data not yet indexed - call index.finish().");let r=this._boxes.length-4;const o=this._queue,a=[],h=i*i;t:for(;void 0!==r;){const i=Math.min(r+4*this.nodeSize,E(r,this._levelBounds));for(let n=r;n<i;n+=4){const i=0|this._indices[n>>2],a=this._boxes[n],l=this._boxes[n+1],c=this._boxes[n+2],u=this._boxes[n+3],p=t<a?a-t:t>c?t-c:0,d=e<l?l-e:e>u?e-u:0,_=p*p+d*d;_>h||(r>=4*this.numItems?o.push(i<<1,_):(void 0===s||s(i))&&o.push(1+(i<<1),_))}for(;o.length&&1&o.peek();){if(o.peekValue()>h)break t;if(a.push(o.pop()>>1),a.length===n)break t}r=o.length?o.pop()>>1:void 0}return o.clear(),a}}function E(t,e){let n=0,i=e.length-1;for(;n<i;){const s=n+i>>1;e[s]>t?i=s:n=s+1}return e[n]}function k(t,e,n,i,s,r){if(Math.floor(i/r)>=Math.floor(s/r))return;const o=t[i],a=t[i+s>>1],h=t[s];let l=h;const c=Math.max(o,a);h>c?l=c:c===o?l=Math.max(a,h):c===a&&(l=Math.max(o,h));let u=i-1,p=s+1;for(;;){do{u++}while(t[u]<l);do{p--}while(t[p]>l);if(u>=p)break;D(t,e,n,u,p)}k(t,e,n,i,p,r),k(t,e,n,p+1,s,r)}function D(t,e,n,i,s){const r=t[i];t[i]=t[s],t[s]=r;const o=4*i,a=4*s,h=e[o],l=e[o+1],c=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]=h,e[a+1]=l,e[a+2]=c,e[a+3]=u;const p=n[i];n[i]=n[s],n[s]=p}function I(t,e){let n=t^e,i=65535^n,s=65535^(t|e),r=t&(65535^e),o=n|i>>1,a=n>>1^n,h=s>>1^i&r>>1^s,l=n&s>>1^r>>1^r;n=o,i=a,s=h,r=l,o=n&n>>2^i&i>>2,a=n&i>>2^i&(n^i)>>2,h^=n&s>>2^i&r>>2,l^=i&s>>2^(n^i)&r>>2,n=o,i=a,s=h,r=l,o=n&n>>4^i&i>>4,a=n&i>>4^i&(n^i)>>4,h^=n&s>>4^i&r>>4,l^=i&s>>4^(n^i)&r>>4,n=o,i=a,s=h,r=l,h^=n&s>>8^i&r>>8,l^=i&s>>8^(n^i)&r>>8,n=h^h>>1,i=l^l>>1;let c=t^e,u=i|65535^(c|n);return c=16711935&(c|c<<8),c=252645135&(c|c<<4),c=858993459&(c|c<<2),c=1431655765&(c|c<<1),u=16711935&(u|u<<8),u=252645135&(u|u<<4),u=858993459&(u|u<<2),u=1431655765&(u|u<<1),(u<<1|c)>>>0}const P=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class T{static from(t){if(!(t instanceof ArrayBuffer))throw new Error("Data must be an instance of ArrayBuffer.");const[e,n]=new Uint8Array(t,0,2);if(219!==e)throw new Error("Data does not appear to be in a KDBush format.");const i=n>>4;if(1!==i)throw new Error(`Got v${i} data when expected v1.`);const s=P[15&n];if(!s)throw new Error("Unrecognized array type.");const[r]=new Uint16Array(t,2,1),[o]=new Uint32Array(t,4,1);return new T(o,r,s,t)}constructor(t,e=64,n=Float64Array,i){if(isNaN(t)||t<0)throw new Error(`Unpexpected numItems value: ${t}.`);this.numItems=+t,this.nodeSize=Math.min(Math.max(+e,2),65535),this.ArrayType=n,this.IndexArrayType=t<65536?Uint16Array:Uint32Array;const s=P.indexOf(this.ArrayType),r=2*t*this.ArrayType.BYTES_PER_ELEMENT,o=t*this.IndexArrayType.BYTES_PER_ELEMENT,a=(8-o%8)%8;if(s<0)throw new Error(`Unexpected typed array class: ${n}.`);i&&i instanceof ArrayBuffer?(this.data=i,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+r+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+s]),new Uint16Array(this.data,2,1)[0]=e,new Uint32Array(this.data,4,1)[0]=t)}add(t,e){const n=this._pos>>1;return this.ids[n]=n,this.coords[this._pos++]=t,this.coords[this._pos++]=e,n}finish(){const t=this._pos>>1;if(t!==this.numItems)throw new Error(`Added ${t} items when expected ${this.numItems}.`);return L(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}range(t,e,n,i){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:s,coords:r,nodeSize:o}=this,a=[0,s.length-1,0],h=[];for(;a.length;){const l=a.pop()||0,c=a.pop()||0,u=a.pop()||0;if(c-u<=o){for(let o=u;o<=c;o++){const a=r[2*o],l=r[2*o+1];a>=t&&a<=n&&l>=e&&l<=i&&h.push(s[o])}continue}const p=u+c>>1,d=r[2*p],_=r[2*p+1];d>=t&&d<=n&&_>=e&&_<=i&&h.push(s[p]),(0===l?t<=d:e<=_)&&(a.push(u),a.push(p-1),a.push(1-l)),(0===l?n>=d:i>=_)&&(a.push(p+1),a.push(c),a.push(1-l))}return h}within(t,e,n){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:i,coords:s,nodeSize:r}=this,o=[0,i.length-1,0],a=[],h=n*n;for(;o.length;){const l=o.pop()||0,c=o.pop()||0,u=o.pop()||0;if(c-u<=r){for(let n=u;n<=c;n++)G(s[2*n],s[2*n+1],t,e)<=h&&a.push(i[n]);continue}const p=u+c>>1,d=s[2*p],_=s[2*p+1];G(d,_,t,e)<=h&&a.push(i[p]),(0===l?t-n<=d:e-n<=_)&&(o.push(u),o.push(p-1),o.push(1-l)),(0===l?t+n>=d:e+n>=_)&&(o.push(p+1),o.push(c),o.push(1-l))}return a}}function L(t,e,n,i,s,r){if(s-i<=n)return;const o=i+s>>1;N(t,e,o,i,s,r),L(t,e,n,i,o-1,1-r),L(t,e,n,o+1,s,1-r)}function N(t,e,n,i,s,r){for(;s>i;){if(s-i>600){const o=s-i+1,a=n-i+1,h=Math.log(o),l=.5*Math.exp(2*h/3),c=.5*Math.sqrt(h*l*(o-l)/o)*(a-o/2<0?-1:1);N(t,e,n,Math.max(i,Math.floor(n-a*l/o+c)),Math.min(s,Math.floor(n+(o-a)*l/o+c)),r)}const o=e[2*n+r];let a=i,h=s;for(R(t,e,i,n),e[2*s+r]>o&&R(t,e,i,s);a<h;){for(R(t,e,a,h),a++,h--;e[2*a+r]<o;)a++;for(;e[2*h+r]>o;)h--}e[2*i+r]===o?R(t,e,i,h):(h++,R(t,e,h,s)),h<=n&&(i=h+1),n<=h&&(s=h-1)}}function R(t,e,n,i){F(t,n,i),F(e,2*n,2*i),F(e,2*n+1,2*i+1)}function F(t,e,n){const i=t[e];t[e]=t[n],t[n]=i}function G(t,e,n,i){const s=t-n,r=e-i;return s*s+r*r}var O={exports:{}};!function(t){var e,n,i,s;(s={}).Constants={},s.Math={},s.Accumulator={},(e=s.Constants).WGS84={a:6378137,f:1/298.257223563},e.version={major:2,minor:2,patch:0},e.version_string="2.2.0",(n=s.Math).digits=53,n.epsilon=Math.pow(.5,n.digits-1),n.degree=Math.PI/180,n.sq=function(t){return t*t},n.hypot=function(t,e){return Math.sqrt(t*t+e*e)},n.cbrt=Math.cbrt||function(t){var e=Math.pow(Math.abs(t),1/3);return t>0?e:t<0?-e:t},n.log1p=Math.log1p||function(t){var e=1+t,n=e-1;return 0===n?t:t*Math.log(e)/n},n.atanh=Math.atanh||function(t){var e=Math.abs(t);return e=n.log1p(2*e/(1-e))/2,t>0?e:t<0?-e:t},n.copysign=function(t,e){return Math.abs(t)*(e<0||0===e&&1/e<0?-1:1)},n.sum=function(t,e){var n=t+e,i=n-e,s=n-i;return i-=t,{s:n,t:n?0-(i+(s-=e)):n}},n.polyval=function(t,e,n,i){for(var s=t<0?0:e[n++];--t>=0;)s=s*i+e[n++];return s},n.AngRound=function(t){var e=1/16,i=Math.abs(t);return i=i<e?e-(e-i):i,n.copysign(i,t)},n.remainder=function(t,e){return(t%=e)<-e/2?t+e:t<e/2?t:t-e},n.AngNormalize=function(t){var e=n.remainder(t,360);return 180===Math.abs(e)?n.copysign(180,t):e},n.LatFix=function(t){return Math.abs(t)>90?NaN:t},n.AngDiff=function(t,e){var i,s,r=n.sum(n.remainder(-t,360),n.remainder(e,360));return i=(r=n.sum(n.remainder(r.s,360),r.t)).s,s=r.t,0!==i&&180!==Math.abs(i)||(i=n.copysign(i,0===s?e-t:-s)),{d:i,e:s}},n.sincosd=function(t){var e,i,s,r,o,a,h;switch(e=t%360,i=(e-=90*(s=Math.round(e/90)))*this.degree,r=Math.sin(i),o=Math.cos(i),45===Math.abs(e)?(o=Math.sqrt(.5),r=n.copysign(o,i)):30===Math.abs(e)&&(o=Math.sqrt(.75),r=n.copysign(.5,i)),3&s){case 0:a=r,h=o;break;case 1:a=o,h=-r;break;case 2:a=-r,h=-o;break;default:a=-o,h=r}return h+=0,0===a&&(a=n.copysign(a,t)),{s:a,c:h}},n.sincosde=function(t,e){var i,s,r,o,a,h,l;switch(i=t%360,r=Math.round(i/90),s=(i=n.AngRound(i-90*r+e))*this.degree,o=Math.sin(s),a=Math.cos(s),45===Math.abs(i)?(a=Math.sqrt(.5),o=n.copysign(a,s)):30===Math.abs(i)&&(a=Math.sqrt(.75),o=n.copysign(.5,s)),3&r){case 0:h=o,l=a;break;case 1:h=a,l=-o;break;case 2:h=-o,l=-a;break;default:h=-a,l=o}return l+=0,0===h&&(h=n.copysign(h,t+e)),{s:h,c:l}},n.atan2d=function(t,e){var i,s=0;switch(Math.abs(t)>Math.abs(e)&&([t,e]=[e,t],s=2),n.copysign(1,e)<0&&(e=-e,++s),i=Math.atan2(t,e)/this.degree,s){case 1:i=n.copysign(180,t)-i;break;case 2:i=90-i;break;case 3:i=-90+i}return i},function(t,e){t.Accumulator=function(t){this.Set(t)},t.Accumulator.prototype.Set=function(e){e||(e=0),e.constructor===t.Accumulator?(this._s=e._s,this._t=e._t):(this._s=e,this._t=0)},t.Accumulator.prototype.Add=function(t){var n=e.sum(t,this._t),i=e.sum(n.s,this._s);n=n.t,this._s=i.s,this._t=i.t,0===this._s?this._s=n:this._t+=n},t.Accumulator.prototype.Sum=function(e){var n;return e?((n=new t.Accumulator(this)).Add(e),n._s):this._s},t.Accumulator.prototype.Negate=function(){this._s*=-1,this._t*=-1},t.Accumulator.prototype.Remainder=function(t){this._s=e.remainder(this._s,t),this.Add(0)}}(s.Accumulator,s.Math),s.Geodesic={},s.GeodesicLine={},s.PolygonArea={},function(t,e,n,i,s){var r,o,a,h,l,c,u,p,d,_,f,m=20+i.digits+10,y=i.epsilon,g=200*y,v=Math.sqrt(y),x=y,w=1e3*v;t.tiny_=Math.sqrt(Number.MIN_VALUE/Number.EPSILON),t.nC1_=6,t.nC1p_=6,t.nC2_=6,t.nC3_=6,t.nC4_=6,r=t.nC3_*(t.nC3_-1)/2,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,n,i){var s=i.length,r=s-(t?1:0),o=2*(n-e)*(n+e),a=1&r?i[--s]:0,h=0;for(r=Math.floor(r/2);r--;)a=o*(h=o*a-h+i[--s])-a+i[--s];return t?2*e*n*a:n*(a-h)},a=function(t,e){var n,s,r,o,a,h,l,c,u,p,d,_,f=i.sq(t),m=i.sq(e),y=(f+m-1)/6;return 0===m&&y<=0?n=0:(h=y,(a=(s=f*m/4)*(s+2*(o=y*(r=i.sq(y)))))>=0?(l=s+o,l+=l<0?-Math.sqrt(a):Math.sqrt(a),h+=(c=i.cbrt(l))+(0!==c?r/c:0)):(u=Math.atan2(Math.sqrt(-a),-(s+o)),h+=2*y*Math.cos(u/3)),p=Math.sqrt(i.sq(h)+m),_=((d=h<0?m/(p-h):h+p)-m)/(2*p),n=d/(Math.sqrt(d+i.sq(_))+_)),n},h=[1,4,64,0,256],t.A1m1f=function(t){var e=Math.floor(3);return(i.polyval(e,h,0,i.sq(t))/h[e+1]+t)/(1-t)},l=[-1,6,-16,32,-9,64,-128,2048,9,-16,768,3,-5,512,-7,1280,-7,2048],t.C1f=function(e,n){var s,r,o=i.sq(e),a=e,h=0;for(s=1;s<=t.nC1_;++s)r=Math.floor((t.nC1_-s)/2),n[s]=a*i.polyval(r,l,h,o)/l[h+r+1],h+=r+2,a*=e},c=[205,-432,768,1536,4005,-4736,3840,12288,-225,116,384,-7173,2695,7680,3467,7680,38081,61440],t.C1pf=function(e,n){var s,r,o=i.sq(e),a=e,h=0;for(s=1;s<=t.nC1p_;++s)r=Math.floor((t.nC1p_-s)/2),n[s]=a*i.polyval(r,c,h,o)/c[h+r+1],h+=r+2,a*=e},u=[-11,-28,-192,0,256],t.A2m1f=function(t){var e=Math.floor(3);return(i.polyval(e,u,0,i.sq(t))/u[e+1]-t)/(1+t)},p=[1,2,16,32,35,64,384,2048,15,80,768,7,35,512,63,1280,77,2048],t.C2f=function(e,n){var s,r,o=i.sq(e),a=e,h=0;for(s=1;s<=t.nC2_;++s)r=Math.floor((t.nC2_-s)/2),n[s]=a*i.polyval(r,p,h,o)/p[h+r+1],h+=r+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/i.sq(this._f1),this._n=this.f/(2-this.f),this._b=this.a*this._f1,this._c2=(i.sq(this.a)+i.sq(this._b)*(0===this._e2?1:(this._e2>0?i.atanh(Math.sqrt(this._e2)):Math.atan(Math.sqrt(-this._e2)))/Math.sqrt(Math.abs(this._e2))))/2,this._etol2=.1*v/Math.sqrt(Math.max(.001,Math.abs(this.f))*Math.min(1,1-this.f/2)/2),!(isFinite(this.a)&&this.a>0))throw new Error("Equatorial radius is not positive");if(!(isFinite(this._b)&&this._b>0))throw new Error("Polar semi-axis is not positive");this._A3x=new Array(6),this._C3x=new Array(r),this._C4x=new Array(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,n=0,s=0;for(t=5;t>=0;--t)e=Math.min(6-t-1,t),this._A3x[s++]=i.polyval(e,d,n,this._n)/d[n+e+1],n+=e+2},_=[3,128,2,5,128,-1,3,3,64,-1,0,1,8,-1,1,4,5,256,1,3,128,-3,-2,3,64,1,-3,2,32,7,512,-10,9,384,5,-9,5,192,7,512,-14,7,512,21,2560],t.Geodesic.prototype.C3coeff=function(){var e,n,s,r=0,o=0;for(e=1;e<t.nC3_;++e)for(n=t.nC3_-1;n>=e;--n)s=Math.min(t.nC3_-n-1,n),this._C3x[o++]=i.polyval(s,_,r,this._n)/_[r+s+1],r+=s+2},f=[97,15015,1088,156,45045,-224,-4784,1573,45045,-10656,14144,-4576,-858,45045,64,624,-4576,6864,-3003,15015,100,208,572,3432,-12012,30030,45045,1,9009,-2944,468,135135,5792,1040,-1287,135135,5952,-11648,9152,-2574,135135,-64,-624,4576,-6864,3003,135135,8,10725,1856,-936,225225,-8448,4992,-1144,225225,-1440,4160,-4576,1716,225225,-136,63063,1024,-208,105105,3584,-3328,1144,315315,-128,135135,-2560,832,405405,128,99099],t.Geodesic.prototype.C4coeff=function(){var e,n,s,r=0,o=0;for(e=0;e<t.nC4_;++e)for(n=t.nC4_-1;n>=e;--n)s=t.nC4_-n-1,this._C4x[o++]=i.polyval(s,f,r,this._n)/f[r+s+1],r+=s+2},t.Geodesic.prototype.A3f=function(t){return i.polyval(5,this._A3x,0,t)},t.Geodesic.prototype.C3f=function(e,n){var s,r,o=1,a=0;for(s=1;s<t.nC3_;++s)r=t.nC3_-s-1,o*=e,n[s]=o*i.polyval(r,this._C3x,a,e),a+=r+1},t.Geodesic.prototype.C4f=function(e,n){var s,r,o=1,a=0;for(s=0;s<t.nC4_;++s)r=t.nC4_-s-1,n[s]=o*i.polyval(r,this._C4x,a,e),a+=r+1,o*=e},t.Geodesic.prototype.Lengths=function(e,n,i,s,r,o,a,h,l,c,u,p,d){var _,f,m,y,g={},v=0,x=0,w=0,b=0;if((u&=t.OUT_MASK)&(t.DISTANCE|t.REDUCEDLENGTH|t.GEODESICSCALE)&&(w=t.A1m1f(e),t.C1f(e,p),u&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(b=t.A2m1f(e),t.C2f(e,d),v=w-b,b=1+b),w=1+w),u&t.DISTANCE)_=t.SinCosSeries(!0,o,a,p)-t.SinCosSeries(!0,i,s,p),g.s12b=w*(n+_),u&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(x=v*n+(w*_-b*(t.SinCosSeries(!0,o,a,d)-t.SinCosSeries(!0,i,s,d))));else if(u&(t.REDUCEDLENGTH|t.GEODESICSCALE)){for(f=1;f<=t.nC2_;++f)d[f]=w*p[f]-b*d[f];x=v*n+(t.SinCosSeries(!0,o,a,d)-t.SinCosSeries(!0,i,s,d))}return u&t.REDUCEDLENGTH?(g.m0=v,g.m12b=h*(s*o)-r*(i*a)-s*a*x):g.m12b=NaN,u&t.GEODESICSCALE&&(m=s*a+i*o,y=this._ep2*(l-c)*(l+c)/(r+h),g.M12=m+(y*o-a*x)*i/r,g.M21=m-(y*i-s*x)*o/h),g},t.Geodesic.prototype.InverseStart=function(e,n,s,r,o,h,l,c,u,p,d){var _,f,m,y,v,x,b,C,S,A,M,E,k,D,I,P,T,L,N,R,F={},G=r*n-o*e,O=o*n+r*e;return F.sig12=-1,_=r*n,_+=o*e,(f=O>=0&&G<.5&&o*l<.5)?(y=i.sq(e+r),y/=y+i.sq(n+o),F.dnm=Math.sqrt(1+this._ep2*y),m=l/(this._f1*F.dnm),v=Math.sin(m),x=Math.cos(m)):(v=c,x=u),F.salp1=o*v,F.calp1=x>=0?G+o*e*i.sq(v)/(1+x):_-o*e*i.sq(v)/(1-x),C=i.hypot(F.salp1,F.calp1),S=e*r+n*o*x,f&&C<this._etol2?(F.salp2=n*v,F.calp2=G-n*r*(x>=0?i.sq(v)/(1+x):1-x),b=i.hypot(F.salp2,F.calp2),F.salp2/=b,F.calp2/=b,F.sig12=Math.atan2(C,S)):Math.abs(this._n)>.1||S>=0||C>=6*Math.abs(this._n)*Math.PI*i.sq(n)||(R=Math.atan2(-c,-u),this.f>=0?(D=(k=i.sq(e)*this._ep2)/(2*(1+Math.sqrt(1+k))+k),A=R/(E=this.f*n*this.A3f(D)*Math.PI),M=_/(E*n)):(I=o*n-r*e,P=Math.atan2(_,I),M=l/(E=((A=(T=this.Lengths(this._n,Math.PI+P,e,-n,s,r,o,h,n,o,t.REDUCEDLENGTH,p,d)).m12b/(n*o*T.m0*Math.PI)-1)<-.01?_/A:-this.f*i.sq(n)*Math.PI)/n)),M>-g&&A>-1-w?this.f>=0?(F.salp1=Math.min(1,-A),F.calp1=-Math.sqrt(1-i.sq(F.salp1))):(F.calp1=Math.max(A>-g?0:-1,A),F.salp1=Math.sqrt(1-i.sq(F.calp1))):(L=a(A,M),N=E*(this.f>=0?-A*L/(1+L):-M*(1+L)/L),v=Math.sin(N),x=-Math.cos(N),F.salp1=o*v,F.calp1=_-o*e*i.sq(v)/(1-x))),F.salp1<=0?(F.salp1=1,F.calp1=0):(b=i.hypot(F.salp1,F.calp1),F.salp1/=b,F.calp1/=b),F},t.Geodesic.prototype.Lambda12=function(e,n,s,r,o,a,h,l,c,u,p,d,_,f){var m,y,g,v,x,w,b,C,S,A,M,E,k,D={};return 0===e&&0===l&&(l=-t.tiny_),y=h*n,g=i.hypot(l,h*e),D.ssig1=e,v=y*e,D.csig1=x=l*n,m=i.hypot(D.ssig1,D.csig1),D.ssig1/=m,D.csig1/=m,D.salp2=o!==n?y/o:h,D.calp2=o!==n||Math.abs(r)!==-e?Math.sqrt(i.sq(l*n)+(n<-e?(o-n)*(n+o):(e-r)*(e+r)))/o:Math.abs(l),D.ssig2=r,w=y*r,D.csig2=b=D.calp2*o,m=i.hypot(D.ssig2,D.csig2),D.ssig2/=m,D.csig2/=m,D.sig12=Math.atan2(Math.max(0,D.csig1*D.ssig2-D.ssig1*D.csig2),D.csig1*D.csig2+D.ssig1*D.ssig2),C=Math.max(0,x*w-v*b),S=x*b+v*w,M=Math.atan2(C*u-S*c,S*u+C*c),E=i.sq(g)*this._ep2,D.eps=E/(2*(1+Math.sqrt(1+E))+E),this.C3f(D.eps,f),A=t.SinCosSeries(!0,D.ssig2,D.csig2,f)-t.SinCosSeries(!0,D.ssig1,D.csig1,f),D.domg12=-this.f*this.A3f(D.eps)*y*(D.sig12+A),D.lam12=M+D.domg12,p&&(0===D.calp2?D.dlam12=-2*this._f1*s/e:(k=this.Lengths(D.eps,D.sig12,D.ssig1,D.csig1,s,D.ssig2,D.csig2,a,n,o,t.REDUCEDLENGTH,d,_),D.dlam12=k.m12b,D.dlam12*=this._f1/(D.calp2*o))),D},t.Geodesic.prototype.Inverse=function(e,n,s,r,o){var a,h;return o||(o=t.STANDARD),o===t.LONG_UNROLL&&(o|=t.STANDARD),o&=t.OUT_MASK,h=(a=this.InverseInt(e,n,s,r,o)).vals,o&t.AZIMUTH&&(h.azi1=i.atan2d(a.salp1,a.calp1),h.azi2=i.atan2d(a.salp2,a.calp2)),h},t.Geodesic.prototype.InverseInt=function(e,n,s,r,o){var a,h,l,c,u,p,d,_,f,g,w,b,C,S,A,M,E,k,D,I,P,T,L,N,R,F,G,O,B,z,U,q,j,$,V,H,W,K,X,Z,J,Y,Q,tt,et,nt,it,st,rt,ot,at,ht,lt,ct,ut,pt,dt,_t,ft,mt,yt,gt,vt,xt,wt,bt={};if(bt.lat1=e=i.LatFix(e),bt.lat2=s=i.LatFix(s),e=i.AngRound(e),s=i.AngRound(s),h=(a=i.AngDiff(n,r)).e,a=a.d,o&t.LONG_UNROLL?(bt.lon1=n,bt.lon2=n+a+h):(bt.lon1=i.AngNormalize(n),bt.lon2=i.AngNormalize(r)),h*=l=i.copysign(1,a),A=(a*=l)*i.degree,M=(c=i.sincosde(a,h)).s,E=c.c,h=180-a-h,(u=Math.abs(e)<Math.abs(s)||isNaN(s)?-1:1)<0&&(l*=-1,[s,e]=[e,s]),e*=p=i.copysign(1,-e),s*=p,c=i.sincosd(e),d=this._f1*c.s,_=c.c,d/=c=i.hypot(d,_),_/=c,_=Math.max(t.tiny_,_),c=i.sincosd(s),f=this._f1*c.s,g=c.c,f/=c=i.hypot(f,g),g/=c,g=Math.max(t.tiny_,g),_<-d?g===_&&(f=i.copysign(d,f)):Math.abs(f)===-d&&(g=_),C=Math.sqrt(1+this._ep2*i.sq(d)),S=Math.sqrt(1+this._ep2*i.sq(f)),L=new Array(t.nC1_+1),N=new Array(t.nC2_+1),R=new Array(t.nC3_),(F=-90===e||0===M)&&(I=M,T=0,O=d,B=(D=E)*_,z=f,U=(P=1)*g,k=Math.atan2(Math.max(0,B*z-O*U),B*U+O*z),w=(G=this.Lengths(this._n,k,O,B,C,z,U,S,_,g,o|t.DISTANCE|t.REDUCEDLENGTH,L,N)).s12b,b=G.m12b,o&t.GEODESICSCALE&&(bt.M12=G.M12,bt.M21=G.M21),k<v||b>=0?((k<3*t.tiny_||k<y&&(w<0||b<0))&&(k=b=w=0),b*=this._b,w*=this._b,bt.a12=k/i.degree):F=!1),dt=2,!F&&0===d&&(this.f<=0||h>=180*this.f))D=P=0,I=T=1,w=this.a*A,k=j=A/this._f1,b=this._b*Math.sin(k),o&t.GEODESICSCALE&&(bt.M12=bt.M21=Math.cos(k)),bt.a12=a/this._f1;else if(!F)if(k=(G=this.InverseStart(d,_,C,f,g,S,A,M,E,L,N)).sig12,I=G.salp1,D=G.calp1,k>=0)T=G.salp2,P=G.calp2,$=G.dnm,w=k*this._b*$,b=i.sq($)*this._b*Math.sin(k/$),o&t.GEODESICSCALE&&(bt.M12=bt.M21=Math.cos(k/$)),bt.a12=k/i.degree,j=A/(this._f1*$);else{for(V=0,H=t.tiny_,W=1,K=t.tiny_,X=-1,Z=!1,J=!1;Y=(G=this.Lambda12(d,_,C,f,g,S,I,D,M,E,V<20,L,N,R)).lam12,T=G.salp2,P=G.calp2,k=G.sig12,O=G.ssig1,B=G.csig1,z=G.ssig2,U=G.csig2,q=G.eps,ft=G.domg12,Q=G.dlam12,!J&&Math.abs(Y)>=(Z?8:1)*y&&V!=m;++V)Y>0&&(V<20||D/I>X/K)?(K=I,X=D):Y<0&&(V<20||D/I<W/H)&&(H=I,W=D),V<20&&Q>0&&(tt=-Y/Q,Math.abs(tt)<Math.PI&&(et=Math.sin(tt),(it=I*(nt=Math.cos(tt))+D*et)>0))?(D=D*nt-I*et,I=it,I/=c=i.hypot(I,D),D/=c,Z=Math.abs(Y)<=16*y):(I=(H+K)/2,D=(W+X)/2,I/=c=i.hypot(I,D),D/=c,Z=!1,J=Math.abs(H-I)+(W-D)<x||Math.abs(I-K)+(D-X)<x);st=o|(o&(t.REDUCEDLENGTH|t.GEODESICSCALE)?t.DISTANCE:t.NONE),w=(G=this.Lengths(q,k,O,B,C,z,U,S,_,g,st,L,N)).s12b,b=G.m12b,o&t.GEODESICSCALE&&(bt.M12=G.M12,bt.M21=G.M21),b*=this._b,w*=this._b,bt.a12=k/i.degree,o&t.AREA&&(xt=Math.sin(ft),dt=M*(wt=Math.cos(ft))-E*xt,_t=E*wt+M*xt)}return o&t.DISTANCE&&(bt.s12=0+w),o&t.REDUCEDLENGTH&&(bt.m12=0+b),o&t.AREA&&(rt=I*_,0!==(ot=i.hypot(D,I*d))&&0!==rt?(O=d,B=D*_,z=f,U=P*g,q=(ht=i.sq(ot)*this._ep2)/(2*(1+Math.sqrt(1+ht))+ht),lt=i.sq(this.a)*ot*rt*this._e2,O/=c=i.hypot(O,B),B/=c,z/=c=i.hypot(z,U),U/=c,ct=new Array(t.nC4_),this.C4f(q,ct),ut=t.SinCosSeries(!1,O,B,ct),pt=t.SinCosSeries(!1,z,U,ct),bt.S12=lt*(pt-ut)):bt.S12=0,F||2!=dt||(dt=Math.sin(j),_t=Math.cos(j)),!F&&_t>-.7071&&f-d<1.75?(ft=1+_t,mt=1+_,yt=1+g,at=2*Math.atan2(dt*(d*yt+f*mt),ft*(d*f+mt*yt))):(vt=P*D+T*I,0===(gt=T*D-P*I)&&vt<0&&(gt=t.tiny_*D,vt=-1),at=Math.atan2(gt,vt)),bt.S12+=this._c2*at,bt.S12*=u*l*p,bt.S12+=0),u<0&&([T,I]=[I,T],[P,D]=[D,P],o&t.GEODESICSCALE&&([bt.M21,bt.M12]=[bt.M12,bt.M21])),{vals:bt,salp1:I*=u*l,calp1:D*=u*p,salp2:T*=u*l,calp2:P*=u*p}},t.Geodesic.prototype.GenDirect=function(n,i,s,r,o,a){return a?a===t.LONG_UNROLL&&(a|=t.STANDARD):a=t.STANDARD,r||(a|=t.DISTANCE_IN),new e.GeodesicLine(this,n,i,s,a).GenPosition(r,o,a)},t.Geodesic.prototype.Direct=function(t,e,n,i,s){return this.GenDirect(t,e,n,!1,i,s)},t.Geodesic.prototype.ArcDirect=function(t,e,n,i,s){return this.GenDirect(t,e,n,!0,i,s)},t.Geodesic.prototype.Line=function(t,n,i,s){return new e.GeodesicLine(this,t,n,i,s)},t.Geodesic.prototype.DirectLine=function(t,e,n,i,s){return this.GenDirectLine(t,e,n,!1,i,s)},t.Geodesic.prototype.ArcDirectLine=function(t,e,n,i,s){return this.GenDirectLine(t,e,n,!0,i,s)},t.Geodesic.prototype.GenDirectLine=function(n,i,s,r,o,a){var h;return a||(a=t.STANDARD|t.DISTANCE_IN),r||(a|=t.DISTANCE_IN),(h=new e.GeodesicLine(this,n,i,s,a)).GenSetDistance(r,o),h},t.Geodesic.prototype.InverseLine=function(n,s,r,o,a){var h,l,c;return a||(a=t.STANDARD|t.DISTANCE_IN),h=this.InverseInt(n,s,r,o,t.ARC),c=i.atan2d(h.salp1,h.calp1),a&t.OUT_MASK&t.DISTANCE_IN&&(a|=t.DISTANCE),(l=new e.GeodesicLine(this,n,s,c,a,h.salp1,h.calp1)).SetArc(h.vals.a12),l},t.Geodesic.prototype.Polygon=function(t){return new n.PolygonArea(this,t)},t.WGS84=new t.Geodesic(s.WGS84.a,s.WGS84.f)}(s.Geodesic,s.GeodesicLine,s.PolygonArea,s.Math,s.Constants),function(t,e,n){e.GeodesicLine=function(e,i,s,r,o,a,h){var l,c,u,p,d,_;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=n.LatFix(i),this.lon1=s,void 0===a||void 0===h?(this.azi1=n.AngNormalize(r),l=n.sincosd(n.AngRound(this.azi1)),this.salp1=l.s,this.calp1=l.c):(this.azi1=r,this.salp1=a,this.calp1=h),l=n.sincosd(n.AngRound(this.lat1)),u=this._f1*l.s,c=l.c,u/=l=n.hypot(u,c),c/=l,c=Math.max(t.tiny_,c),this._dn1=Math.sqrt(1+e._ep2*n.sq(u)),this._salp0=this.salp1*c,this._calp0=n.hypot(this.calp1,this.salp1*u),this._ssig1=u,this._somg1=this._salp0*u,this._csig1=this._comg1=0!==u||0!==this.calp1?c*this.calp1:1,l=n.hypot(this._ssig1,this._csig1),this._ssig1/=l,this._csig1/=l,this._k2=n.sq(this._calp0)*e._ep2,p=this._k2/(2*(1+Math.sqrt(1+this._k2))+this._k2),this.caps&t.CAP_C1&&(this._A1m1=t.A1m1f(p),this._C1a=new Array(t.nC1_+1),t.C1f(p,this._C1a),this._B11=t.SinCosSeries(!0,this._ssig1,this._csig1,this._C1a),d=Math.sin(this._B11),_=Math.cos(this._B11),this._stau1=this._ssig1*_+this._csig1*d,this._ctau1=this._csig1*_-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=n.sq(this.a)*this._calp0*this._salp0*e._e2,this._B41=t.SinCosSeries(!1,this._ssig1,this._csig1,this._C4a)),this.a13=this.s13=NaN},e.GeodesicLine.prototype.GenPosition=function(e,i,s){var r,o,a,h,l,c,u,p,d,_,f,m,y,g,v,x,w,b,C,S,A,M,E,k,D,I,P={};return s?s===t.LONG_UNROLL&&(s|=t.STANDARD):s=t.STANDARD,s&=this.caps&t.OUT_MASK,P.lat1=this.lat1,P.azi1=this.azi1,P.lon1=s&t.LONG_UNROLL?this.lon1:n.AngNormalize(this.lon1),e?P.a12=i:P.s12=i,e||this.caps&t.DISTANCE_IN&t.OUT_MASK?(h=0,l=0,e?(r=i*n.degree,o=(E=n.sincosd(i)).s,a=E.c):(p=i/(this._b*(1+this._A1m1)),d=Math.sin(p),_=Math.cos(p),r=p-((h=-t.SinCosSeries(!0,this._stau1*_+this._ctau1*d,this._ctau1*_-this._stau1*d,this._C1pa))-this._B11),o=Math.sin(r),a=Math.cos(r),Math.abs(this.f)>.01&&(c=this._ssig1*a+this._csig1*o,u=this._csig1*a-this._ssig1*o,h=t.SinCosSeries(!0,c,u,this._C1a),r-=((1+this._A1m1)*(r+(h-this._B11))-i/this._b)/Math.sqrt(1+this._k2*n.sq(c)),o=Math.sin(r),a=Math.cos(r))),c=this._ssig1*a+this._csig1*o,u=this._csig1*a-this._ssig1*o,C=Math.sqrt(1+this._k2*n.sq(c)),s&(t.DISTANCE|t.REDUCEDLENGTH|t.GEODESICSCALE)&&((e||Math.abs(this.f)>.01)&&(h=t.SinCosSeries(!0,c,u,this._C1a)),l=(1+this._A1m1)*(h-this._B11)),y=this._calp0*c,0===(g=n.hypot(this._salp0,this._calp0*u))&&(g=u=t.tiny_),w=this._salp0,b=this._calp0*u,e&&s&t.DISTANCE&&(P.s12=this._b*((1+this._A1m1)*r+l)),s&t.LONGITUDE&&(v=this._salp0*c,x=u,m=n.copysign(1,this._salp0),f=((s&t.LONG_UNROLL?m*(r-(Math.atan2(c,u)-Math.atan2(this._ssig1,this._csig1))+(Math.atan2(m*v,x)-Math.atan2(m*this._somg1,this._comg1))):Math.atan2(v*this._comg1-x*this._somg1,x*this._comg1+v*this._somg1))+this._A3c*(r+(t.SinCosSeries(!0,c,u,this._C3a)-this._B31)))/n.degree,P.lon2=s&t.LONG_UNROLL?this.lon1+f:n.AngNormalize(n.AngNormalize(this.lon1)+n.AngNormalize(f))),s&t.LATITUDE&&(P.lat2=n.atan2d(y,this._f1*g)),s&t.AZIMUTH&&(P.azi2=n.atan2d(w,b)),s&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(S=t.SinCosSeries(!0,c,u,this._C2a),A=(1+this._A2m1)*(S-this._B21),M=(this._A1m1-this._A2m1)*r+(l-A),s&t.REDUCEDLENGTH&&(P.m12=this._b*(C*(this._csig1*c)-this._dn1*(this._ssig1*u)-this._csig1*u*M)),s&t.GEODESICSCALE&&(E=this._k2*(c-this._ssig1)*(c+this._ssig1)/(this._dn1+C),P.M12=a+(E*c-u*M)*this._ssig1/this._dn1,P.M21=a-(E*this._ssig1-this._csig1*M)*c/C)),s&t.AREA&&(k=t.SinCosSeries(!1,c,u,this._C4a),0===this._calp0||0===this._salp0?(D=w*this.calp1-b*this.salp1,I=b*this.calp1+w*this.salp1):(D=this._calp0*this._salp0*(a<=0?this._csig1*(1-a)+o*this._ssig1:o*(this._csig1*o/(1+a)+this._ssig1)),I=n.sq(this._salp0)+n.sq(this._calp0)*this._csig1*u),P.S12=this._c2*Math.atan2(D,I)+this._A4*(k-this._B41)),e||(P.a12=r/n.degree),P):(P.a12=NaN,P)},e.GeodesicLine.prototype.Position=function(t,e){return this.GenPosition(!1,t,e)},e.GeodesicLine.prototype.ArcPosition=function(t,e){return this.GenPosition(!0,t,e)},e.GeodesicLine.prototype.GenSetDistance=function(t,e){t?this.SetArc(e):this.SetDistance(e)},e.GeodesicLine.prototype.SetDistance=function(e){var n;this.s13=e,n=this.GenPosition(!1,this.s13,t.ARC),this.a13=0+n.a12},e.GeodesicLine.prototype.SetArc=function(e){var n;this.a13=e,n=this.GenPosition(!0,this.a13,t.DISTANCE),this.s13=0+n.s12}}(s.Geodesic,s.GeodesicLine,s.Math),function(t,e,n,i){var s,r,o,a;s=function(t,e){var i=n.AngDiff(t,e).d;return t=n.AngNormalize(t),e=n.AngNormalize(e),i>0&&(t<0&&e>=0||t>0&&0===e)?1:i<0&&t>=0&&e<0?-1:0},r=function(t,e){return(0<=(e%=720)&&e<360||e<-360?0:1)-(0<=(t%=720)&&t<360||t<-360?0:1)},o=function(t,e,n,i,s){return t.Remainder(e),1&n&&t.Add((t.Sum()<0?1:-1)*e/2),i||t.Negate(),s?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,i,s,r){return t=n.remainder(t,e),1&i&&(t+=(t<0?1:-1)*e/2),s||(t*=-1),r?t>e/2?t-=e:t<=-e/2&&(t+=e):t>=e?t-=e:t<0&&(t+=e),0+t},t.PolygonArea=function(t,n){this._geod=t,this.a=this._geod.a,this.f=this._geod.f,this._area0=4*Math.PI*t._c2,this.polyline=n||!1,this._mask=e.LATITUDE|e.LONGITUDE|e.DISTANCE|(this.polyline?e.NONE:e.AREA|e.LONG_UNROLL),this.polyline||(this._areasum=new i.Accumulator(0)),this._perimetersum=new i.Accumulator(0),this.Clear()},t.PolygonArea.prototype.Clear=function(){this.num=0,this._crossings=0,this.polyline||this._areasum.Set(0),this._perimetersum.Set(0),this._lat0=this._lon0=this.lat=this.lon=NaN},t.PolygonArea.prototype.AddPoint=function(t,e){var n;0===this.num?(this._lat0=this.lat=t,this._lon0=this.lon=e):(n=this._geod.Inverse(this.lat,this.lon,t,e,this._mask),this._perimetersum.Add(n.s12),this.polyline||(this._areasum.Add(n.S12),this._crossings+=s(this.lon,e)),this.lat=t,this.lon=e),++this.num},t.PolygonArea.prototype.AddEdge=function(t,e){var n;this.num&&(n=this._geod.Direct(this.lat,this.lon,t,e,this._mask),this._perimetersum.Add(e),this.polyline||(this._areasum.Add(n.S12),this._crossings+=r(this.lon,n.lon2)),this.lat=n.lat2,this.lon=n.lon2),++this.num},t.PolygonArea.prototype.Compute=function(t,e){var n,r,a={number:this.num};return this.num<2?(a.perimeter=0,this.polyline||(a.area=0),a):this.polyline?(a.perimeter=this._perimetersum.Sum(),a):(n=this._geod.Inverse(this.lat,this.lon,this._lat0,this._lon0,this._mask),a.perimeter=this._perimetersum.Sum(n.s12),(r=new i.Accumulator(this._areasum)).Add(n.S12),a.area=o(r,this._area0,this._crossings+s(this.lon,this._lon0),t,e),a)},t.PolygonArea.prototype.TestPoint=function(t,e,n,i){var r,o,h,l,c={number:this.num+1};if(0===this.num)return c.perimeter=0,this.polyline||(c.area=0),c;for(c.perimeter=this._perimetersum.Sum(),o=this.polyline?0:this._areasum.Sum(),h=this._crossings,l=0;l<(this.polyline?1:2);++l)r=this._geod.Inverse(0===l?this.lat:t,0===l?this.lon:e,0!==l?this._lat0:t,0!==l?this._lon0:e,this._mask),c.perimeter+=r.s12,this.polyline||(o+=r.S12,h+=s(0===l?this.lon:e,0!==l?this._lon0:e));return this.polyline||(c.area=a(o,this._area0,h,n,i)),c},t.PolygonArea.prototype.TestEdge=function(t,e,n,i){var o,h,l,c={number:this.num?this.num+1:0};return 0===this.num||(c.perimeter=this._perimetersum.Sum()+e,this.polyline||(h=this._areasum.Sum(),l=this._crossings,h+=(o=this._geod.Direct(this.lat,this.lon,t,e,this._mask)).S12,l+=r(this.lon,o.lon2),l+=s(o.lon2,this._lon0),o=this._geod.Inverse(o.lat2,o.lon2,this._lat0,this._lon0,this._mask),c.perimeter+=o.s12,h+=o.S12,c.area=a(h,this._area0,l,n,i))),c}}(s.PolygonArea,s.Geodesic,s.Math,s.Accumulator),i=s,t.exports?t.exports=i:window.geodesic=i}(O);var B=O.exports,z=e({__proto__:null,default:n(B)},[B]);const U=globalThis;"undefined"==typeof window&&(U.window=U.window||{},U.window.document||(U.window.document={}));const q=U.window.modules=U.window.modules||{};q.mproj=C,q.flatbush=M,q.kdbush=T,q["geographiclib-geodesic"]=z;class j{_listeners={};on(t,e){return this._listeners[t]||(this._listeners[t]=[]),this._listeners[t].push(e),this}once(t,e){const n=i=>{this.off(t,n),e(i)};return this.on(t,n)}off(t,e){return this._listeners[t]?(this._listeners[t]=this._listeners[t].filter(t=>t!==e),this):this}fire(t,e){if(!this._listeners[t])return this;const n={type:t,...e};return this._listeners[t].forEach(t=>t(n)),this}}class ${mx;my;bx;by;constructor(t=1,e=1,n=0,i=0){this.mx=t,this.my=e,this.bx=n,this.by=i}static fromBounds(t,e,n=!1){const i=e.width/t.width||1,s=(n?-e.height/t.height:e.height/t.height)||1,r=e.xmin-i*t.xmin,o=n?e.ymax-s*t.ymin:e.ymin-s*t.ymin;return new $(i,s,r,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,n){this.bx=e*(1-t)+this.bx*t,this.by=n*(1-t)+this.by*t,this.mx*=t,this.my*=t}clone(){return new $(this.mx,this.my,this.bx,this.by)}}class V{xmin;ymin;xmax;ymax;constructor(t=1/0,e=1/0,n=-1/0,i=-1/0){this.xmin=t,this.ymin=e,this.xmax=n,this.ymax=i}static fromArray(t){return new V(t[0],t[1],t[2],t[3])}get width(){return this.xmax-this.xmin}get height(){return this.ymax-this.ymin}get centerX(){return.5*(this.xmin+this.xmax)}get centerY(){return.5*(this.ymin+this.ymax)}hasBounds(){return this.xmin<=this.xmax&&this.ymin<=this.ymax}clone(){return new V(this.xmin,this.ymin,this.xmax,this.ymax)}mergePoint(t,e){t<this.xmin&&(this.xmin=t),t>this.xmax&&(this.xmax=t),e<this.ymin&&(this.ymin=e),e>this.ymax&&(this.ymax=e)}merge(t){t.hasBounds()&&(t.xmin<this.xmin&&(this.xmin=t.xmin),t.xmax>this.xmax&&(this.xmax=t.xmax),t.ymin<this.ymin&&(this.ymin=t.ymin),t.ymax>this.ymax&&(this.ymax=t.ymax))}fillOut(t,e=.5,n=.5){const i=this.width,s=this.height;let r;return i/s<t?(r=s*t-i,this.xmin-=(1-e)*r,this.xmax+=e*r):(r=i/t-s,this.ymin-=(1-n)*r,this.ymax+=n*r),this}scale(t){const e=this.centerX,n=this.centerY,i=this.width*t,s=this.height*t;this.xmin=e-i/2,this.xmax=e+i/2,this.ymin=n-s/2,this.ymax=n+s/2}}class H extends j{_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,n=Math.min((e+10)/this._duration,1),i=n>=1;this._running?(i&&(this._running=!1),this.fire("tick",{elapsed:e,pct:n,done:i,time:t,tickTime:t-this._tickTime}),this._busy=!1,this._running&&this._startTick(t)):this._busy=!1}}class W extends j{_timer=new H;_startValue=0;_endValue=0;_ease;constructor(t){super(),this._ease=t||null,this._timer.on("tick",t=>this._onTick(t))}start(t,e,n){this._startValue=t,this._endValue=e,this._timer.start(n||500)}stop(){this._timer.stop()}_onTick(t){const e=this._ease?this._ease(t.pct):t.pct,n=this._endValue*e+this._startValue*(1-e);this.fire("change",{value:n})}static sineInOut(t){return.5-Math.cos(t*Math.PI)/2}static quadraticOut(t){return 1-Math.pow(1-t,2)}}const K=18485274.7;class X{_transform=new $;_extent=new V;_width=0;_height=0;_initialMX=0;_initialExtent=null;_zoomTween=new W(W.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),n=new V(0,0,this._width,this._height);this._transform=$.fromBounds(e,n,!0),0===this._initialMX&&(this._initialMX=Math.abs(this._transform.mx),this._initialExtent=e)}pan(t,e){this._transform.translate(t,e),this._applyConstraints()}cancelZoomAnimation(){this._zoomTween.stop(),this._animatingTransform=null}applyWheelZoom(t,e,n,i){const s=1+.12*e,r=t>0?s:1/s;this._transform.scale(r,n,i),this._applyConstraints()}zoomIn(){this._zoomTo(1.15)}zoomOut(){this._zoomTo(1/1.15)}_zoomTo(t){const e=[this._width/2,this._height/2],n=Math.abs(this._transform.mx),i=n*t;this._zoomFocus=e,this._animatingTransform=this._transform.clone(),this._zoomTween.start(n,i,200)}initZoomTween(){this._zoomTween.on("change",t=>{if(!this._animatingTransform)return;const e=t.value/this._animatingTransform.mx,n=this._animatingTransform.clone();n.scale(e,this._zoomFocus[0],this._zoomFocus[1]),this._transform=n,this.onViewChange?.(),t.done&&(this._animatingTransform=null)})}project(t,e){return this._transform.project(t,e)}unproject(t,e){return this._transform.unproject(t,e)}getLineScale(){if(0===this._initialMX)return 1;const t=Math.abs(this._transform.mx)/this._initialMX;let e=1;return t<.5?e*=Math.pow(t+.5,.35):t>30&&(e*=Math.pow(t-29,.065)),e}getArcFilter(t){const e=.1*(1/Math.abs(this._transform.mx)),n=this._initialMX>0?Math.abs(this._transform.mx)/this._initialMX:1,i=n<1?e*n:e,s=this._getViewBounds();return e=>!t.arcIsSmaller?.(e,i)&&!(s&&t.arcIntersectsBBox&&!t.arcIntersectsBBox(e,s))}getViewBounds(){return this._getViewBounds()}_getViewBounds(){if(!this._transform||0===this._width)return null;const t=this._transform,e=-t.bx/t.mx,n=(this._width-t.bx)/t.mx,i=-t.by/t.my,s=(this._height-t.by)/t.my;return[Math.min(e,n),Math.min(i,s),Math.max(e,n),Math.max(i,s)]}_applyConstraints(){const t=this._transform;let e=Math.abs(t.mx);const n=this._getMinMX(),i=this._getMaxMX();(this._crs.toLowerCase().includes("3857")||this._crs.toLowerCase().includes("webmercator"))&&e<n&&(e=n),e>i&&(e=i);const s=t.my>0?e:-e,r=this._getStrictBounds(),o=(this._width/2-t.bx)/t.mx;let a=(this._height/2-t.by)/t.my;if(r){const t=this._height/(2*e),n=r.ymax-t,i=r.ymin+t;i>n?a=(r.ymin+r.ymax)/2:a>n?a=n:a<i&&(a=i)}const h=this._width/2-o*e,l=this._height/2-a*s;this._transform=new $(e,s,h,l)}_getMaxMX(){if(!this._initialExtent)return 1/0;const t=this._initialExtent,e=(...t)=>Math.max(...t.map(Math.abs)),n=e(t.xmin,t.xmax,t.centerX),i=e(t.ymin,t.ymax,t.centerY),s=t.width/this._width/(1e-16*n),r=t.height/this._height/(1e-16*i);return Math.max(s,r)}_getStrictBounds(){const t=this._crs.toLowerCase();return"epsg:3857"===t||"webmercator"===t?new V(-1/0,-18485274.7,1/0,K):null}_getMinMX(){const t=this._crs.toLowerCase();let e;if("epsg:3857"===t||"webmercator"===t)e=36970549.4;else{if("epsg:4326"!==t&&"wgs84"!==t)return.01*this._initialMX;e=180}return this._height/e}}class Z{snapVertices(e,n,i){t.internal.snapVerticesToPoint(e,n,i)}insertVertex(e,n,i){t.internal.insertVertex(e,n,i)}deleteVertex(e,n){t.internal.deleteVertex(e,n)}appendEmptyArc(e){t.internal.appendEmptyArc(e)}appendVertex(e,n){t.internal.appendVertex(e,n)}deleteLastArc(e){t.internal.deleteLastArc(e)}findNearestVertices(e,n,i){return t.internal.findNearestVertices(e,n,i)}findArcIdFromVertexId(e,n){return t.internal.findArcIdFromVertexId(e,n)}vertexIsArcEndpoint(e,n){return t.internal.vertexIsArcEndpoint(e,n)}forEachSegmentInShape(e,n,i){t.internal.forEachSegmentInShape(e,n,i)}findClosestPointOnSeg(e,n,i,s,r,o,a){return t.internal.findClosestPointOnSeg(e,n,i,s,r,o,a)}addIntersectionCuts(e,n){t.internal.addIntersectionCuts(e,n)}findSegmentIntersections(e,n){return t.internal.findSegmentIntersections(e,n)}getIntersectionLayer(e,n,i){return t.internal.getIntersectionLayer(e,n,i)}getAvgSegment(e){return t.internal.getAvgSegment(e)}simplifyArcsFast(e,n){return t.internal.simplifyArcsFast(e,n)}layerHasGeometry(e){return t.internal.layerHasGeometry(e)}getLayerBounds(e,n){const i=t.internal.getLayerBounds(e,n);return i?{xmin:i.xmin,ymin:i.ymin,xmax:i.xmax,ymax:i.ymax}:{xmin:NaN,ymin:NaN,xmax:NaN,ymax:NaN}}getDatasetBounds(e){const n=t.internal.getDatasetBounds(e);return{xmin:n.xmin,ymin:n.ymin,xmax:n.xmax,ymax:n.ymax}}exportDatasetsToPack(e,n){return t.internal.exportDatasetsToPack(e,n??{})}restoreSessionData(e){return t.internal.restoreSessionData(e)}pack(e){return t.internal.pack(e)}unpackSessionData(e){return t.internal.unpackSessionData(e)}exportPackedDatasets(e,n){return t.internal.exportPackedDatasets(e,n??{})}exportFileContent(e,n){return t.internal.exportFileContent(e,n)}copyDataset(e){return t.internal.copyDataset(e)}runImport(e,n){const i=t.internal.parseCommands(e);return i.length>0&&"i"===i[0].name&&(i[0].options.input=n),new Promise((e,n)=>{t.internal.runParsedCommands(i,new t.internal.Job,(t,i)=>{if(t)return void n(t);const s=i.catalog.getDefaultTargets();0!==s.length?e(s[0].dataset):n(new Error("No layers found in dataset"))})})}runOnDataset(e,n,i){return new Promise((s,r)=>{const o=new t.internal.Job;o.catalog.addDataset(n);const a=t.internal.parseCommands(e);if(i)for(const t of a)t.options&&(t.options.input=i);t.internal.runParsedCommands(a,o,(t,e)=>{if(t)return void r(t);const n=e.catalog.getDefaultTargets();0!==n.length?s(n[0].dataset):r(new Error("mapshaper command completed but produced no default target"))})})}runOnDatasetParsed(e,n,i){return new Promise((s,r)=>{const o=new t.internal.Job;if(o.catalog.addDataset(n),i)for(const t of e)t.options&&(t.options.input=i);t.internal.runParsedCommands(e,o,(t,e)=>{if(t)return void r(t);const n=e.catalog.getDefaultTargets();0!==n.length?s(n[0].dataset):r(new Error("mapshaper command completed but produced no default target"))})})}}let J=null;function Y(){return J??(J=new Z)}function Q(t){J=t}const tt=6378137;class et{_crs="EPSG:4326";get crs(){return this._crs}setCRS(t){this._crs=t}getCenter(t,e){const n=this._crs.toLowerCase();return"epsg:3857"===n||"webmercator"===n?this._webMercatorToLatLng(t,e):[t,e]}getZoom(t){const e=this._crs.toLowerCase();return"epsg:3857"===e||"webmercator"===e?Math.log2(40075016.6855*t/512):0}async reproject(t,e){for(const n of e.values())n.reproject&&await n.reproject(t);this._crs=t;const n=Y(),i=new V;for(const t of e.values()){const e=t.getDataset();if(e?.layers)for(const t of e.layers)if(n.layerHasGeometry(t)){const s=n.getLayerBounds(t,e.arcs);s&&i.merge(new V(s.xmin,s.ymin,s.xmax,s.ymax))}}return i.hasBounds()&&i.scale(1.07),i}_webMercatorToLatLng(t,e){const n=180/Math.PI;return[t/tt*n,n*(.5*Math.PI-2*Math.atan(Math.exp(-e/tt)))]}}function nt(t,e){return t?.name?String(t.name):t?.id?String(t.id):`layer-${e}`}function it(t){return t&&Array.isArray(t)?"number"==typeof t[0]?[t]:Array.isArray(t[0])?t:[]:[]}class st{_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,n){if(0===e.width)return;const i=this._ctx;i.strokeStyle=e.color||"#333",i.lineWidth=(e.width??1)*this._pixelRatio,i.lineCap="round",i.lineJoin="round";let s=0;i.beginPath(),t.forEach(t=>{t&&t.forEach(t=>{t.forEach(t=>{s>0&&s%25==0&&(i.stroke(),i.beginPath());const e=n.getArcIter(t);this.drawPathSnapping(e,i),s++})})}),i.stroke()}drawArcs(t,e,n){if(0===e.width)return;const i=this._ctx,s=t.size();i.strokeStyle=e.color||"#333",i.lineWidth=(e.width??1)*this._pixelRatio,i.lineCap="round",i.lineJoin="round";let r=0;i.beginPath();for(let e=0;e<s;e++){if(n&&!n(e))continue;r>0&&r%25==0&&(i.stroke(),i.beginPath());const s=t.getArcIter(e);this.drawPathSnapping(s,i),r++}i.stroke()}drawPathSnapping(t,e){const n=this._transform.mx*this._pixelRatio,i=this._transform.my*this._pixelRatio,s=this._transform.bx*this._pixelRatio,r=this._transform.by*this._pixelRatio;let o,a,h,l,c=0;if(t.hasNext()){for(o=2*(t.x*n+s)|0,a=2*(t.y*i+r)|0,e.moveTo(o/2,a/2);t.hasNext();)h=o,l=a,o=2*(t.x*n+s)|0,a=2*(t.y*i+r)|0,o===h&&a===l||(e.lineTo(o/2,a/2),c++);0===c&&e.lineTo(o/2+.1,a/2)}}drawPoints(t,e){const n=this._ctx,i=this._pixelRatio,s=this._transform.mx*i,r=this._transform.my*i,o=this._transform.bx*i,a=this._transform.by*i,h=(Number(e?.radius)||4)*i,l=e?.color||"#333",c=!1!==e?.fill;n.beginPath(),n.fillStyle=l,n.strokeStyle=l,t.forEach(t=>{if(!t)return;it(t).forEach(t=>{const e=t[0]*s+o,i=t[1]*r+a;n.moveTo(e+h,i),n.arc(e,i,h,0,2*Math.PI)})}),c?n.fill():n.stroke()}drawVertexDots(t,e,n={}){const i=this._ctx,s=this._pixelRatio,r=this._transform.mx*s,o=this._transform.my*s,a=this._transform.bx*s,h=this._transform.by*s,l=n.dotColor||"#333",c=(n.dotRadius||3)*s,u=n.hoverColor||"#cc6acc",p=(n.hoverRadius||6)*s,d=n.hoverVertex;let _=null;d&&(_=[d[0]*r+a,d[1]*o+h]),i.fillStyle=l,i.beginPath(),t.forEach(t=>{t&&t.forEach(t=>{t.forEach(t=>{const n=t>=0?t:~t,s=e.getArcIter(n);for(;s.hasNext();){const t=s.x*r+a,e=s.y*o+h;_&&Math.abs(t-_[0])<1&&Math.abs(e-_[1])<1||(i.moveTo(t+c,e),i.arc(t,e,c,0,2*Math.PI))}})})}),i.fill(),_&&(i.fillStyle=u,i.beginPath(),"interpolated"===n.hoverType?i.rect(_[0]-p,_[1]-p,2*p,2*p):i.arc(_[0],_[1],p,0,2*Math.PI),i.fill())}drawPolygonFill(t,e,n,i,s){if(!e.getShapeIter)return;const r=this._ctx,o=this._pixelRatio,a=this._transform.mx*o,h=this._transform.my*o,l=this._transform.bx*o,c=this._transform.by*o;r.fillStyle=n;const u="number"==typeof s&&1!==s,p=r.globalAlpha;u&&(r.globalAlpha=p*Math.max(0,Math.min(1,s)));let d=0;r.beginPath();for(let n=0;n<t.length;n++){const s=t[n];if(!s)continue;let o=!0;if(i){o=!1;for(const t of s){for(const e of t){if(i(e>=0?e:~e)){o=!0;break}}if(o)break}}if(o){d>0&&d>=100&&(r.fill("evenodd"),r.beginPath(),d=0);for(const t of s){const n=e.getShapeIter(t);if(!n.hasNext())continue;let i,s,o=2*(n.x*a+l)|0,u=2*(n.y*h+c)|0;for(r.moveTo(o/2,u/2);n.hasNext();)i=o,s=u,o=2*(n.x*a+l)|0,u=2*(n.y*h+c)|0,o===i&&u===s||r.lineTo(o/2,u/2);r.closePath()}d++}}d>0&&r.fill("evenodd"),u&&(r.globalAlpha=p)}drawDrawingOverlay(t){const e=this._ctx,n=this._pixelRatio,i=this._transform.mx*n,s=this._transform.my*n,r=this._transform.bx*n,o=this._transform.by*n,a=t.drawColor||"#0078ff",h=t.vertices,l=t.cursorCoord,c=t=>[t[0]*i+r,t[1]*s+o];if(h.length>0){e.strokeStyle=a,e.lineWidth=2*n,e.lineJoin="round",e.lineCap="round",e.setLineDash([]),e.beginPath();const t=c(h[0]);e.moveTo(t[0],t[1]);for(let t=1;t<h.length;t++){const n=c(h[t]);e.lineTo(n[0],n[1])}e.stroke()}if(h.length>0&&l){const i=c(h[h.length-1]),s=c(l);if(e.strokeStyle=a,e.lineWidth=1.5*n,e.setLineDash([6*n,4*n]),e.beginPath(),e.moveTo(i[0],i[1]),e.lineTo(s[0],s[1]),"polygon"===t.geometryType&&h.length>=2){const t=c(h[0]);e.moveTo(s[0],s[1]),e.lineTo(t[0],t[1])}e.stroke(),e.setLineDash([])}if(h.length>0){const t=4*n;e.fillStyle=a,e.beginPath();for(const n of h){const i=c(n);e.moveTo(i[0]+t,i[1]),e.arc(i[0],i[1],t,0,2*Math.PI)}e.fill()}if(t.snapCoord){const i=c(t.snapCoord),s=7*n;e.strokeStyle="#ff4444",e.lineWidth=2*n,e.beginPath(),"edge"===t.snapKind?e.rect(i[0]-s,i[1]-s,2*s,2*s):e.arc(i[0],i[1],s,0,2*Math.PI),e.stroke()}}clear(){this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height)}resize(t,e){const n=this._pixelRatio;this._canvas.width=t*n,this._canvas.height=e*n,this._canvas.style.width=t+"px",this._canvas.style.height=e+"px"}}class rt{_painter;constructor(t){this._painter=t}render(t,e,n){"vertex"===t&&e?this._renderVertexOverlay(e):"draw"===t&&n&&this._painter.drawDrawingOverlay(n)}_renderVertexOverlay(t){const e=t.arcs;"polygon"===t.geometryType&&t.polygonFill&&this._painter.drawPolygonFill(t.shapes,e,t.polygonFill),this._painter.drawVertexDots(t.shapes,e,{dotColor:"#333",dotRadius:3,hoverVertex:t.hoverVertex,hoverType:t.hoverType??"vertex",hoverColor:"#cc6acc",hoverRadius:6})}}class 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 ht(t){return{ok:!0,value:t}}const lt=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"}})}),ct=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=[],n=/(?:^|\s)-([a-z][a-z-]*)/gi;let i;for(;null!==(i=n.exec(t));)e.push(i[1].toLowerCase());return e}function dt(t,e,n,i){if(!1===n)return!1;if(!0===n)return!0;if(0===t.length)return e>=i;if(t.every(t=>ct.has(t)))return!1;return e>=(t.some(t=>ut.has(t))?Math.floor(.5*i):i)}const _t={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 ft(t){let e="attribute-only",n=!1;for(const i of t){if("target"===i)continue;const t=_t[i];if(void 0===t)return"unknown";n=!0,e=yt(e,t)}return n?e:"unknown"}const mt={"attribute-only":0,"crs-only":1,"topology-only":2,"shape-count":3,unknown:3};function yt(t,e){return mt[t]>=mt[e]?t:e}async function gt(t,e,n,i,s){if(t._removed)return lt.hostRemoved();const r=t._sources.get(e);if(!r)return lt.notFound("source",e);const o=r.getDataset();if(!o)return lt.notFound("source",e);const a=Y().copyDataset(o);let h,l=!1;if(t._workerPool){const e=o.arcs?.getPointCount?.()??0,i=function(t,e,n,i){return!1!==n&&(!0===n||dt(pt(t),e,n,i))}(n,e,t._workerMode,t._workerThreshold),s=t._workerRouting;l=s?s({cmd:n,heads:pt(n),vertexCount:e,mode:t._workerMode,threshold:t._workerThreshold,defaultDecision:i}):i}try{h=l?await async function(t,e,n,i,s){if(!t._workerPool)throw new Error("_runViaWorker: worker pool not available");const r=t._workerPool.reserveId(),o=e.arcs?.getPointCount?.()??0,a="undefined"!=typeof performance?performance.now():Date.now();t.fire("workerjobstart",{id:r,cmd:n,label:i,datasetVertexCount:o});try{const i=await Y().exportDatasetsToPack([e],{compact:!1}),o=wt(i),h=t._workerPool.dispatchWithId(r,n,i,s,o),l=await h,c=await Y().restoreSessionData(l);if(!c.datasets||0===c.datasets.length)throw new Error("worker: no dataset in response");const u=("undefined"!=typeof performance?performance.now():Date.now())-a;return t.fire("workerjobend",{id:r,ok:!0,durationMs:u}),c.datasets[0]}catch(e){const n=("undefined"!=typeof performance?performance.now():Date.now())-a;throw t.fire("workerjobend",{id:r,ok:!1,durationMs:n,errorMessage:e?.message??String(e)}),e}}(t,o,n,i,s):await Y().runOnDataset(n,o,s)}catch(e){return t._removed?lt.hostRemoved():(t.fire("error",{error:e}),lt.mapshaper(e,{cmd:n,operation:i}))}return t._removed?lt.hostRemoved():xt(t,e,a,h,i,function(t){return ft(pt(t))}(n))}async function vt(t,e,n,i,s){if(t._removed)return lt.hostRemoved();const r=t._sources.get(e);if(!r)return lt.notFound("source",e);const o=r.getDataset();if(!o)return lt.notFound("source",e);const a=Y().copyDataset(o),h=n.map(t=>t.name);let l,c=!1;if(t._workerPool){const e=o.arcs?.getPointCount?.()??0,n=dt(h,e,t._workerMode,t._workerThreshold),i=t._workerRouting;c=i?i({cmd:h.map(t=>`-${t}`).join(" "),heads:h,vertexCount:e,mode:t._workerMode,threshold:t._workerThreshold,defaultDecision:n}):n}try{l=c?await async function(t,e,n,i,s){if(!t._workerPool)throw new Error("_runViaWorkerParsed: worker pool not available");const r=t._workerPool.reserveId(),o=e.arcs?.getPointCount?.()??0,a="undefined"!=typeof performance?performance.now():Date.now(),h=n.map(t=>`-${t.name}`).join(" ");t.fire("workerjobstart",{id:r,cmd:h,label:i,datasetVertexCount:o});try{const i=await Y().exportDatasetsToPack([e],{compact:!1}),o=wt(i),h=t._workerPool.dispatchWithId(r,n,i,s,o),l=await h,c=await Y().restoreSessionData(l);if(!c.datasets||0===c.datasets.length)throw new Error("worker: no dataset in response");const u=("undefined"!=typeof performance?performance.now():Date.now())-a;return t.fire("workerjobend",{id:r,ok:!0,durationMs:u}),c.datasets[0]}catch(e){const n=("undefined"!=typeof performance?performance.now():Date.now())-a;throw t.fire("workerjobend",{id:r,ok:!1,durationMs:n,errorMessage:e?.message??String(e)}),e}}(t,o,n,i,s):await Y().runOnDatasetParsed(n,o,s)}catch(e){return t._removed?lt.hostRemoved():(t.fire("error",{error:e}),lt.mapshaper(e,{operation:i}))}return t._removed?lt.hostRemoved():xt(t,e,a,l,i,ft(h))}function xt(t,e,n,i,s,r="unknown"){const o=t._sources.get(e);return o?(t._activeTransaction&&t._activeTransaction._captureFirstTouch(e,n),o.setDataset(i),t._history.push(new ot({source:o,before:n,after:i,label:s})),t._history.isCapturing()||t._fireHistoryChange(),function(t){return"shape-count"===t||"topology-only"===t||"unknown"===t}(r)&&t._fireSelectionChange(t._selection.clear()),t._scheduleRender(),at):lt.notFound("source",e)}function wt(t){const e=[],n=new Set,i=t=>{if(t&&"object"==typeof t){if(t instanceof Uint8Array){const i=t.buffer;return void(i instanceof ArrayBuffer&&!n.has(i)&&(n.add(i),e.push(i)))}if(t instanceof ArrayBuffer)n.has(t)||(n.add(t),e.push(t));else if(Array.isArray(t))for(const e of t)i(e);else for(const e of Object.keys(t))i(t[e])}};return i(t),e}function bt(t,e){for(let n=0;n<t.length;n++){const i=t[n];if(i){if(nt(i,n)===e)return i;if(i.name===e)return i;if(i.id===e)return i}}return null}class Ct{_sources;constructor(t){this._sources=t}resolve(t,e){const n=this._sources.get(t);return n?bt(n.getLayers(),e):null}resolveInLayers(t,e){return bt(t,e)}}async function St(t,e,n){const i=t.host._sources.get(e.source);if(!i)return lt.notFound("source",e.source);const s=i.getDataset();if(!s)return lt.notFound("source",e.source);if(!bt(s.layers,e.target))return lt.notFound("layer",e.target);const r="string"==typeof e.mask&&e.mask.length>0;if(r===Array.isArray(e.bbox))return lt.validation(r?"mask":"bbox","must supply exactly one of `mask` or `bbox`");if(r){if(!bt(s.layers,e.mask))return lt.notFound("mask",e.mask)}else{const t=e.bbox;if(4!==t.length||!t.every(t=>Number.isFinite(t)))return lt.validation("bbox","must be [xmin, ymin, xmax, ymax] of finite numbers");if(t[0]>=t[2]||t[1]>=t[3])return lt.validation("bbox","must satisfy xmin<xmax and ymin<ymax")}const o=r?{source:e.mask}:{bbox:e.bbox};e.cleanup&&(o.cleanup=!0),e.removeSlivers&&(o.remove_slivers=!0);const a="clip"===n?"Clip":"Erase";return t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:n,options:o}],`${a} ${e.target}`)}const At="__emap_merge";async function Mt(t){const e=t.host._selection.getAll();if(0===e.length)return lt.validation("selection","selection is empty");const n=e[0].source,i=e[0].layer;for(const t of e)if(t.source!==n||t.layer!==i)return lt.validation("selection","selection spans multiple sources or layers");const s=t.host.layers.resolve(n,i);if(!s)return lt.notFound("layer",i);if(!function(t,e){const n=t.data?.getRecords?.();if(!n||0===n.length)return!1;const i=new Set(e);for(let t=0;t<n.length;t++){const e=n[t]??{};e[At]=i.has(t)?"M":`k_${t}`,n[t]=e}return!0}(s,e.map(t=>t.id).slice().sort((t,e)=>t-e)))return lt.validation("layer","layer has no data table; cannot stamp discriminator");const r=function(t,e){const n={fields:[At]},i=e.data?.getFields?.();if(i&&i.length>0){const t=i.filter(t=>t!==At&&!t.includes(","));t.length>0&&(n.copy_fields=t)}return[{name:"target",options:{target:t}},{name:"dissolve",options:n},{name:"filter-fields",options:{fields:[At],invert:!0}}]}(i,s),o=`Merge ${e.length} feature${e.length>1?"s":""}`,a=await t.runDatasetCommandParsed(n,r,o);return a.ok||function(t){const e=t.data?.getRecords?.();if(!e)return;for(const t of e)t&&At in t&&delete t[At]}(s),a}const Et=new Set(["left","right","outer","inner"]),kt=new Set(["flat","round"]),Dt=/^-?\d+(\.\d+)?$/;function It(t){return"number"==typeof t&&Number.isInteger(t)&&t>0}async function Pt(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);const s=bt(i.layers,e.target);if(!s)return lt.notFound("layer",e.target);if("number"==typeof e.radius){if(!Number.isFinite(e.radius)||e.radius<=0)return lt.validation("radius","must be a positive finite number")}else{if("string"!=typeof e.radius||0===e.radius.trim().length)return lt.validation("radius","must be a positive number or non-empty expression");if(Dt.test(e.radius)&&Number(e.radius)<=0)return lt.validation("radius","numeric string must be a positive number")}if("string"==typeof e.radius&&!t.host._allowExpressionEvaluation([e.radius],"bufferLayer"))return lt.expressionDisabled("bufferLayer");if(void 0!==e.vertices&&!It(e.vertices))return lt.validation("vertices","must be a positive integer");if(void 0!==e.arcQuality&&!It(e.arcQuality))return lt.validation("arcQuality","must be a positive integer");if(void 0!==e.sliceLength&&!It(e.sliceLength))return lt.validation("sliceLength","must be a positive integer");if(void 0!==e.backtrack&&!It(e.backtrack))return lt.validation("backtrack","must be a positive integer");if(void 0!==e.tolerance&&!("number"==typeof(r=e.tolerance)&&Number.isFinite(r)&&r>0))return lt.validation("tolerance","must be a positive finite number");var r;if(void 0!==e.type&&!Et.has(e.type))return lt.validation("type","must be one of: left, right, outer, inner");if(void 0!==e.capStyle&&!kt.has(e.capStyle))return lt.validation("capStyle","must be one of: flat, round");void 0!==e.type&&"polygon"===s.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 Tt{_emap;constructor(t){this._emap=t}get _ctx(){return{host:this._emap,runDatasetCommand:(t,e,n,i)=>gt(this._emap,t,e,n,i),runDatasetCommandParsed:(t,e,n,i)=>vt(this._emap,t,e,n,i),applyDatasetReplace:(t,e,n,i)=>xt(this._emap,t,e,n,i)}}clipLayer(t){return async function(t,e){return St(t,e,"clip")}(this._ctx,t)}eraseLayer(t){return async function(t,e){return St(t,e,"erase")}(this._ctx,t)}dissolveLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);if(!bt(i.layers,e.target))return lt.notFound("layer",e.target);const s=Array.isArray(e.fields)&&e.fields.length>0;if(void 0!==e.field&&s)return lt.validation("field","`field` and `fields` are mutually exclusive");if(void 0!==e.field&&("string"!=typeof e.field||e.field.includes(",")))return lt.validation("field","field name must be a string without `,`");if(!t.host._allowExpressionEvaluation([e.calc,e.where],"dissolveLayer"))return lt.expressionDisabled("dissolveLayer");const r={};if(e.field)r.fields=[e.field];else if(s){const t=e.fields.filter(t=>"string"==typeof t&&!t.includes(","));t.length>0&&(r.fields=t)}const o=t=>Array.isArray(t)?t.filter(t=>"string"==typeof t&&!t.includes(",")):[],a=o(e.sumFields);a.length>0&&(r.sum_fields=a);const h=o(e.copyFields);return h.length>0&&(r.copy_fields=h),e.calc&&e.calc.trim()&&(r.calc=e.calc),e.where&&e.where.trim()&&(r.where=e.where),e.multipart&&(r.multipart=!0),e.name&&e.name.trim()&&(r.name=e.name),e.noReplace&&(r.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"dissolve",options:r}],`Dissolve ${e.target}`)}(this._ctx,t)}bufferLayer(t){return Pt(this._ctx,t)}applyExpression(t){return async function(t,e){if(!e.expression||!e.expression.trim())return lt.validation("expression","must be a non-empty expression");const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);if(!bt(i.layers,e.target))return lt.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.expression,e.where],"applyExpression"))return lt.expressionDisabled("applyExpression");const s={expression:e.expression};return e.where&&e.where.trim()&&(s.where=e.where),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"each",options:s}],`Update ${e.target}`)}(this._ctx,t)}filterFeatures(t){return async function(t,e){const n=!(!e.expression||!e.expression.trim());if(!n&&!e.removeEmpty)return lt.validation("expression","must supply `expression` or `removeEmpty: true`");const i=t.host._sources.get(e.source);if(!i)return lt.notFound("source",e.source);const s=i.getDataset();if(!s)return lt.notFound("source",e.source);if(!bt(s.layers,e.target))return lt.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.expression],"filterFeatures"))return lt.expressionDisabled("filterFeatures");const r={};return n&&(r.expression=e.expression),e.invert&&(r.invert=!0),e.removeEmpty&&(r.remove_empty=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"filter",options:r}],`Filter ${e.target}`)}(this._ctx,t)}filterIslands(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);if(!bt(i.layers,e.target))return lt.notFound("layer",e.target);const s="number"==typeof e.minArea&&Number.isFinite(e.minArea),r="number"==typeof e.minVertices&&Number.isInteger(e.minVertices)&&e.minVertices>0;if(!s&&!r)return lt.validation("minArea","must supply at least one of `minArea` or `minVertices`");if(s&&e.minArea<0)return lt.validation("minArea","must be non-negative");const o={};return s&&(o.min_area=String(e.minArea)),r&&(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 n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);if(!bt(i.layers,e.target))return lt.notFound("layer",e.target);if("number"!=typeof e.minArea||!Number.isFinite(e.minArea)||e.minArea<=0)return lt.validation("minArea","must be a positive finite number");const s={min_area:String(e.minArea)};return e.weighted&&(s.weighted=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"filter-slivers",options:s}],`Filter slivers ${e.target}`)}(this._ctx,t)}filterGeom(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);if(!bt(i.layers,e.target))return lt.notFound("layer",e.target);const s=e.bbox;return Array.isArray(s)&&4===s.length&&s.every(t=>Number.isFinite(t))?s[0]>=s[2]||s[1]>=s[3]?lt.validation("bbox","must satisfy xmin<xmax and ymin<ymax"):t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"filter-geom",options:{bbox:[s[0],s[1],s[2],s[3]]}}],`Filter geom ${e.target}`):lt.validation("bbox","must be [xmin, ymin, xmax, ymax] of finite numbers")}(this._ctx,t)}explodeLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();return i?bt(i.layers,e.target)?t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"explode",options:{}}],`Explode ${e.target}`):lt.notFound("layer",e.target):lt.notFound("source",e.source)}(this._ctx,t)}innerlinesLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);if(!bt(i.layers,e.target))return lt.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.where],"innerlinesLayer"))return lt.expressionDisabled("innerlinesLayer");const s={};return e.where&&e.where.trim()&&(s.where=e.where),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:"innerlines",options:s}],`Innerlines ${e.target}`)}(this._ctx,t)}snapLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);if(!bt(i.layers,e.target))return lt.notFound("layer",e.target);const s={};return"number"==typeof e.interval&&(s.interval=String(e.interval)),e.endpoints&&(s.endpoints=!0),"number"==typeof e.precision&&(s.precision=e.precision),e.fixGeometry&&(s.fix_geometry=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"snap",options:s}],`Snap ${e.target}`)}(this._ctx,t)}cleanLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);if(!bt(i.layers,e.target))return lt.notFound("layer",e.target);const s=t=>void 0===t||"number"==typeof t&&Number.isFinite(t)&&t>=0;if(!s(e.gapFillArea))return lt.validation("gapFillArea","must be a finite non-negative number");if(!s(e.sliverControl))return lt.validation("sliverControl","must be a finite non-negative number");if(!s(e.snapInterval))return lt.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 lt.validation("overlapRule",`must be one of ${t.join(", ")}`)}const r={};return void 0!==e.gapFillArea&&(r.gap_fill_area=String(e.gapFillArea)),void 0!==e.sliverControl&&(r.sliver_control=e.sliverControl),void 0!==e.snapInterval&&(r.snap_interval=String(e.snapInterval)),e.noSnap&&(r.no_snap=!0),e.allowOverlaps&&(r.allow_overlaps=!0),void 0!==e.overlapRule&&(r.overlap_rule=e.overlapRule),e.allowEmpty&&(r.allow_empty=!0),e.rewind&&(r.rewind=!0),e.onlyArcs&&(r.only_arcs=!0),e.noArcDissolve&&(r.no_arc_dissolve=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"clean",options:r}],`Clean ${e.target}`)}(this._ctx,t)}mosaicLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);if(!bt(i.layers,e.target))return lt.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.calc],"mosaicLayer"))return lt.expressionDisabled("mosaicLayer");const s={};return"number"==typeof e.snapInterval&&(s.snap_interval=String(e.snapInterval)),e.noSnap&&(s.no_snap=!0),e.noReplace&&(s.no_replace=!0),e.name&&e.name.trim()&&(s.name=e.name),e.calc&&e.calc.trim()&&(s.calc=e.calc),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"mosaic",options:s}],`Mosaic ${e.target}`)}(this._ctx,t)}unionLayers(t){return async function(t,e){if(!e.targets||e.targets.length<2)return lt.validation("targets","must supply at least 2 target layers");const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);for(const t of e.targets){if("string"!=typeof t||t.includes(","))return lt.validation("targets",`target name must not contain ',': ${String(t)}`);if(!bt(i.layers,t))return lt.notFound("layer",t)}const s=e.targets.join(","),r={};if(e.fields&&e.fields.length>0){const t=e.fields.filter(t=>!t.includes(","));t.length>0&&(r.fields=t)}return e.name&&e.name.trim()&&(r.name=e.name),e.noReplace&&(r.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:s}},{name:"union",options:r}],`Union ${s}`)}(this._ctx,t)}divideLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);const s=bt(i.layers,e.target);if(!s)return lt.notFound("layer",e.target);if("polyline"!==s.geometry_type)return lt.validation("target",`expected polyline layer, got ${s.geometry_type??"unknown"}`);const r=bt(i.layers,e.divider);if(!r)return lt.notFound("divider",e.divider);if("polygon"!==r.geometry_type)return lt.validation("divider",`expected polygon layer, got ${r.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 n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);const s=bt(i.layers,e.target);if(!s)return lt.notFound("layer",e.target);const r=s.geometry_type;switch(e.type){case"centroid":case"inner":if("polygon"!==r)return lt.validation("type",`${e.type} requires polygon target, got ${r??"unknown"}`);break;case"midpoints":case"interpolated":if("polyline"!==r)return lt.validation("type",`${e.type} requires polyline target, got ${r??"unknown"}`);break;case"vertices":case"endpoints":if("polygon"!==r&&"polyline"!==r)return lt.validation("type",`${e.type} requires polygon/polyline target, got ${r??"unknown"}`);break;default:return lt.validation("type",`unknown type: ${String(e.type)}`)}if("interpolated"===e.type&&!("number"==typeof e.interval&&e.interval>0))return lt.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 n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);const s=bt(i.layers,e.target);if(!s)return lt.notFound("layer",e.target);if("polygon"!==s.geometry_type)return lt.validation("target",`expected polygon layer, got ${s.geometry_type??"unknown"}`);const r={},o=e.fields?.filter(t=>"string"==typeof t&&!t.includes(","));return o&&o.length>0&&(r.fields=o),e.name&&e.name.trim()&&(r.name=e.name),e.noReplace&&(r.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"lines",options:r}],`Lines ${e.target}`)}(this._ctx,t)}polygonsLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);const s=bt(i.layers,e.target);if(!s)return lt.notFound("layer",e.target);if("polyline"!==s.geometry_type)return lt.validation("target",`expected polyline layer, got ${s.geometry_type??"unknown"}`);const r={};return"number"==typeof e.gapTolerance&&e.gapTolerance>0&&(r.gap_tolerance=String(e.gapTolerance)),e.fromRings&&(r.from_rings=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"polygons",options:r}],`Polygons ${e.target}`)}(this._ctx,t)}simplifyLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);if(void 0!==e.target&&!bt(i.layers,e.target))return lt.notFound("layer",e.target);if(1!==[void 0!==e.percentage,void 0!==e.interval,void 0!==e.resolution].filter(Boolean).length)return lt.validation("threshold","must supply exactly one of percentage, interval, resolution");const s={};if(void 0!==e.percentage){const t=e.percentage;if(!Number.isFinite(t)||t<0||t>100)return lt.validation("percentage","must be a finite number in [0, 100]");s.percentage=`${t}%`}else if(void 0!==e.interval){const t=e.interval;if(!Number.isFinite(t)||t<=0)return lt.validation("interval","must be a positive finite number");s.interval=String(t)}else{const t=e.resolution;if(!/^\d+x\d+$/.test(t))return lt.validation("resolution","must match `WIDTHxHEIGHT` (digits)");s.resolution=t}if(void 0!==e.weighting&&void 0!==e.method&&"weighted"!==e.method)return lt.validation("weighting",`weighting only applies to method='weighted', not ${e.method}`);e.method&&(s.method=e.method),"number"==typeof e.weighting&&Number.isFinite(e.weighting)&&(s.weighting=e.weighting),e.planar&&(s.planar=!0),e.keepShapes&&(s.keep_shapes=!0),e.lockBox&&(s.lock_box=!0),e.noRepair&&(s.no_repair=!0);const r=[];e.target&&r.push({name:"target",options:{target:e.target}}),r.push({name:"simplify",options:s});const o=`Simplify ${e.target??e.source}`;return t.runDatasetCommandParsed(e.source,r,o)}(this._ctx,t)}projectLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);if(void 0!==e.target&&!bt(i.layers,e.target))return lt.notFound("layer",e.target);const s=(e.crs??"").trim();if(0===s.length)return lt.validation("crs","must be a non-empty CRS string");const r={crs:s};e.init&&e.init.trim()&&(r.init=e.init),e.densify&&(r.densify=!0);const o=[];e.target&&o.push({name:"target",options:{target:e.target}}),o.push({name:"proj",options:r});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 n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);if(void 0!==e.target&&!bt(i.layers,e.target))return lt.notFound("layer",e.target);const s=Array.isArray(e.shift),r="number"==typeof e.rotate&&0!==e.rotate,o=void 0!==e.scale&&("number"==typeof e.scale?1!==e.scale:Array.isArray(e.scale));if(!s&&!r&&!o)return lt.validation("shift","must supply at least one of `shift`, `rotate`, or `scale`");if(s){const t=e.shift;if(2!==t.length||!t.every(t=>Number.isFinite(t)))return lt.validation("shift","must be [dx, dy] of finite numbers")}if(r&&!Number.isFinite(e.rotate))return lt.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 lt.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 lt.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 lt.validation("anchor","must be [x, y] of finite numbers");if(!t.host._allowExpressionEvaluation([e.where],"affineLayer"))return lt.expressionDisabled("affineLayer");const a={};s&&(a.shift=[String(e.shift[0]),String(e.shift[1])]),r&&(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 h=[];e.target&&h.push({name:"target",options:{target:e.target}}),h.push({name:"affine",options:a});const l=`Affine ${e.target??e.source}`;return t.runDatasetCommandParsed(e.source,h,l)}(this._ctx,t)}renameLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);if(!bt(i.layers,e.target))return lt.notFound("layer",e.target);const s=(e.name??"").trim();if(0===s.length)return lt.validation("name","must be a non-empty string");if(s.includes(","))return lt.validation("name","must not contain `,`");if(s!==e.target&&i.layers.some(t=>(t?.name??"")===s))return lt.validation("name",`another layer already named '${s}'`);return t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"rename-layers",options:{names:[s]}}],`Rename ${e.target} → ${s}`)}(this._ctx,t)}mergeLayers(t){return async function(t,e){if(!e.targets||e.targets.length<2)return lt.validation("targets","must supply at least 2 target layers");const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);for(const t of e.targets)if("string"!=typeof t||t.includes(","))return lt.validation("targets",`target name must not contain ',': ${String(t)}`);const s=e.targets.map(t=>bt(i.layers,t));for(let t=0;t<s.length;t++)if(!s[t])return lt.notFound("layer",e.targets[t]);if(!e.force){const t=s[0]?.geometry_type;if(!s.every(e=>e?.geometry_type===t))return lt.validation("targets","targets have mixed geometry types; pass `force: true` to merge anyway")}const r=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:r}},{name:"merge-layers",options:o}],`Merge ${r}`)}(this._ctx,t)}splitLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);if(!bt(i.layers,e.target))return lt.notFound("layer",e.target);const s=(e.expression??"").trim();if(0===s.length)return lt.validation("expression","must be a non-empty expression");if(!t.host._allowExpressionEvaluation([s],"splitLayer"))return lt.expressionDisabled("splitLayer");const r={expression:s};return e.noReplace&&(r.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"split",options:r}],`Split ${e.target}`)}(this._ctx,t)}dropLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();return i?bt(i.layers,e.target)?t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"drop",options:{}}],`Drop ${e.target}`):lt.notFound("layer",e.target):lt.notFound("source",e.source)}(this._ctx,t)}sortFeatures(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);if(!bt(i.layers,e.target))return lt.notFound("layer",e.target);const s=(e.expression??"").trim();if(0===s.length)return lt.validation("expression","must be a non-empty expression");if(!t.host._allowExpressionEvaluation([s],"sortFeatures"))return lt.expressionDisabled("sortFeatures");const r={expression:s};return e.descending&&(r.descending=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"sort",options:r}],`Sort ${e.target}`)}(this._ctx,t)}uniqueFeatures(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);if(!bt(i.layers,e.target))return lt.notFound("layer",e.target);const s=(e.expression??"").trim();if(0===s.length)return lt.validation("expression","must be a non-empty expression");if(!t.host._allowExpressionEvaluation([s],"uniqueFeatures"))return lt.expressionDisabled("uniqueFeatures");if(void 0!==e.maxCount&&!("number"==typeof e.maxCount&&e.maxCount>0))return lt.validation("maxCount","must be a positive number");const r={expression:s};return void 0!==e.maxCount&&(r.max_count=e.maxCount),e.invert&&(r.invert=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"uniq",options:r}],`Uniq ${e.target}`)}(this._ctx,t)}filterFields(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);if(!bt(i.layers,e.target))return lt.notFound("layer",e.target);if(!Array.isArray(e.fields)||0===e.fields.length)return lt.validation("fields","must be a non-empty array");for(const t of e.fields){if("string"!=typeof t||0===t.trim().length)return lt.validation("fields",`field name must be a non-empty string: ${String(t)}`);if(t.includes(","))return lt.validation("fields",`field name must not contain ',': ${t}`)}const s={fields:e.fields.slice()};return e.invert&&(s.invert=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"filter-fields",options:s}],`Filter fields ${e.target}`)}(this._ctx,t)}renameFields(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);if(!bt(i.layers,e.target))return lt.notFound("layer",e.target);if(!e.mapping||"object"!=typeof e.mapping)return lt.validation("mapping","must be an object of { oldName: newName }");const s=Object.entries(e.mapping);if(0===s.length)return lt.validation("mapping","must contain at least one rename pair");const r=[];for(const[t,e]of s){const n=(t??"").trim(),i=(e??"").trim();if(0===n.length||0===i.length)return lt.validation("mapping",`field names must be non-empty: ${t}=${e}`);if(n.includes(",")||n.includes("=")||i.includes(",")||i.includes("="))return lt.validation("mapping",`field names must not contain ',' or '=': ${t}=${e}`);r.push(`${n}=${i}`)}return t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"rename-fields",options:{fields:r}}],`Rename fields ${e.target}`)}(this._ctx,t)}joinTable(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);if(!bt(i.layers,e.target))return lt.notFound("layer",e.target);if(!Array.isArray(e.keys)||2!==e.keys.length)return lt.validation("keys","must be a 2-element [targetKey, sourceKey] array");const[s,r]=e.keys.map(t=>"string"==typeof t?t.trim():"");if(0===s.length||0===r.length)return lt.validation("keys","both keys must be non-empty strings");if(s.includes(",")||r.includes(","))return lt.validation("keys","keys must not contain `,`");let o,a;const h=e.data;if(!h||"object"!=typeof h)return lt.validation("data","must be { csv } | { json } | { layer }");if("layer"in h&&"string"==typeof h.layer&&h.layer.trim().length>0)o=h.layer.trim();else if("csv"in h&&("string"==typeof h.csv||h.csv instanceof Uint8Array)){const t=".emap-join.csv";o=t,a={[t]:h.csv}}else{if(!("json"in h)||void 0===h.json)return lt.validation("data","must contain one of `csv`, `json`, or `layer`");{const t=".emap-join.json";let e;e="string"==typeof h.json||h.json instanceof Uint8Array?h.json:JSON.stringify(h.json),o=t,a={[t]:e}}}if(!t.host._allowExpressionEvaluation([e.where,e.calc],"joinTable"))return lt.expressionDisabled("joinTable");const l={source:o,keys:[s,r]};if(e.fields&&e.fields.length>0){const t=e.fields.filter(t=>"string"==typeof t&&!t.includes(","));t.length>0&&(l.fields=t)}return e.prefix&&e.prefix.length>0&&(l.prefix=e.prefix),e.where&&e.where.trim().length>0&&(l.where=e.where),e.calc&&e.calc.trim().length>0&&(l.calc=e.calc),e.unjoined&&(l.unjoined=!0),e.unmatched&&(l.unmatched=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"join",options:l}],`Join ${e.target}`,a)}(this._ctx,t)}dataFill(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);if(!bt(i.layers,e.target))return lt.notFound("layer",e.target);if("string"!=typeof e.field||0===e.field.trim().length)return lt.validation("field","must be a non-empty string");if(e.field.includes(",")||e.field.includes("="))return lt.validation("field","must not contain `,` or `=`");if(void 0!==e.weightField){if("string"!=typeof e.weightField||0===e.weightField.trim().length)return lt.validation("weightField","must be a non-empty string when supplied");if(e.weightField.includes(",")||e.weightField.includes("="))return lt.validation("weightField","must not contain `,` or `=`")}const s={field:e.field};return e.weightField&&(s.weight_field=e.weightField),e.contiguous&&(s.contiguous=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"data-fill",options:s}],`Data fill ${e.target}.${e.field}`)}(this._ctx,t)}rebuildTopology(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);if(!i.arcs)return at;const s=Y(),r=s.copyDataset(i),o=s.copyDataset(i);try{s.addIntersectionCuts(o,{snap_interval:e.snapInterval,no_snap:e.noSnap,rebuild_topology:e.rebuildTopology})}catch(e){return t.host.fire("error",{error:e}),lt.mapshaper(e,{operation:"rebuildTopology"})}return t.applyDatasetReplace(e.source,r,o,"Rebuild topology")}(this._ctx,t)}checkGeometry(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);if(void 0!==e.target&&!bt(i.layers,e.target))return lt.notFound("layer",e.target);if(!i.arcs)return ht({ok:!0,intersections:[],intersectionCount:0});const s={};void 0!==e.tolerance&&(s.tolerance=e.tolerance);const r=Y().findSegmentIntersections(i.arcs,s).map(t=>({x:t.x,y:t.y}));return ht({ok:0===r.length,intersections:r,intersectionCount:r.length})}(this._ctx,t)}intersectionPointsLayer(t){return async function(t,e){const n=t.host._sources.get(e.source);if(!n)return lt.notFound("source",e.source);const i=n.getDataset();if(!i)return lt.notFound("source",e.source);const s=bt(i.layers,e.target);if(!s)return lt.notFound("layer",e.target);if("polygon"!==s.geometry_type&&"polyline"!==s.geometry_type)return lt.validation("target",`expected polygon/polyline target, got ${s.geometry_type??"unknown"}`);if(!i.arcs)return lt.validation("source","source has no arcs");const r=e.name&&e.name.trim()||`${e.target}-intersections`;if(i.layers.some(t=>t?.name===r))return lt.validation("name",`another layer already named '${r}'`);if(void 0!==e.tolerance&&("number"!=typeof e.tolerance||!Number.isFinite(e.tolerance)||e.tolerance<=0))return lt.validation("tolerance","must be a positive finite number");const o={};void 0!==e.tolerance&&(o.tolerance=e.tolerance);const a=Y(),h=a.copyDataset(i),l=a.copyDataset(i);let c;try{const t=a.findSegmentIntersections(l.arcs,o),n=bt(l.layers,e.target);if(!n)throw new Error("intersectionPointsLayer: target lost in copyDataset");c=a.getIntersectionLayer(t,n,l.arcs),c.name=r,l.layers.push(c)}catch(e){return t.host.fire("error",{error:e}),lt.mapshaper(e,{operation:"intersectionPointsLayer"})}return t.applyDatasetReplace(e.source,h,l,`Intersection points ${e.target}`)}(this._ctx,t)}mergeSelected(){return Mt(this._ctx)}}class Lt{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 Nt(t){return"polygon"===t.geometry_type||"polyline"===t.geometry_type}function Rt(t){return"point"===t.geometry_type}function Ft(t){t&&(t.editVersion=(t.editVersion??0)+1)}class Gt{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 Gt))return!1;if(t.opts.source!==this.opts.source)return!1;if(Date.now()-t._mergeAt>500)return!1;const e=t.opts.arcIds,n=this.opts.arcIds;if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(e[t]!==n[t])return!1;const i=t.opts.pointFeatures,s=this.opts.pointFeatures;if(i.length!==s.length)return!1;for(let t=0;t<i.length;t++){if(i[t].featureId!==s[t].featureId)return!1;if(i[t].layer!==s[t].layer)return!1}return!0}merge(t){t instanceof Gt&&(this.opts.dx+=t.opts.dx,this.opts.dy+=t.opts.dy,this._mergeAt=Date.now())}_apply(t,e){const{arcs:n,arcIds:i,pointFeatures:s,source:r}=this.opts;if(n&&i.length>0){const s=n.getVertexData?.();if(s){const{xx:r,yy:o,ii:a,nn:h}=s;for(const s of i){const i=a[s],l=h[s];for(let n=i;n<i+l;n++)r[n]+=t,o[n]+=e;n.updateArcBounds?.(s)}}}for(const n of s){const i=n.layer.shapes?.[n.featureId];if(i)for(const n of it(i))n&&n.length>=2&&(n[0]+=t,n[1]+=e)}r.markDisplayArcsDirty?.(),Ft(r.getDataset?.())}}class Ot{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(jt(this.opts.matrix))}_apply(t){const{arcs:e,arcIds:n,pointFeatures:i,source:s}=this.opts;if(e&&n.length>0){const i=e.getVertexData?.();if(i){const{xx:s,yy:r,ii:o,nn:a}=i;for(const i of n){const n=o[i],h=a[i];for(let e=n;e<n+h;e++){const n=s[e],i=r[e];s[e]=t.a*n+t.c*i+t.tx,r[e]=t.b*n+t.d*i+t.ty}e.updateArcBounds?.(i)}}}for(const e of i){const n=e.layer.shapes?.[e.featureId];if(n)for(const e of it(n))if(e&&e.length>=2){const n=e[0],i=e[1];e[0]=t.a*n+t.c*i+t.tx,e[1]=t.b*n+t.d*i+t.ty}}s.markDisplayArcsDirty?.(),Ft(s.getDataset?.())}}function Bt(t,e=0,n=0){const i=Math.cos(t),s=Math.sin(t);return{a:i,b:s,c:-s,d:i,tx:e-i*e+s*n,ty:n-s*e-i*n}}function zt(t,e,n=0,i=0){return{a:t,b:0,c:0,d:e,tx:n-t*n,ty:i-e*i}}function Ut(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 qt={a:1,b:0,c:0,d:1,tx:0,ty:0};function jt(t){const e=t.a*t.d-t.b*t.c;if(0===e)throw new Error("FeatureAffineCommand: matrix is singular (det=0)");const n=t.d/e,i=-t.b/e,s=-t.c/e,r=t.a/e;return{a:n,b:i,c:s,d:r,tx:-(n*t.tx+s*t.ty),ty:-(i*t.tx+r*t.ty)}}class $t{opts;label;constructor(t){this.opts=t,this.label=`Split ${t.appendedArcs.length} shared arc${1===t.appendedArcs.length?"":"s"}`}do(){const t=this.opts.source.getArcs();if(t){!function(t,e){const n=t.getVertexData?.();if(!n)return;const{xx:i,yy:s,zz:r,nn:o}=n,a=!!r&&e.every(t=>t.zz);let h=0;for(const t of e)h+=t.xx.length;const l=new Float64Array(i.length+h),c=new Float64Array(s.length+h),u=a?new Float64Array(r.length+h):null;l.set(i),c.set(s),u&&r&&u.set(r);let p=i.length;for(const t of e)l.set(t.xx,p),c.set(t.yy,p),u&&t.zz&&u.set(t.zz,p),p+=t.xx.length;const 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,l,c,u)}(t,this.opts.appendedArcs);for(const t of this.opts.remaps)t.layer.shapes[t.featureId]=Wt(t.newShape);this.opts.source.markDisplayArcsDirty?.(),Ft(this.opts.source.getDataset?.())}}undo(){const t=this.opts.source.getArcs();if(t){!function(t,e){const n=t.getVertexData?.();if(!n)return;const{xx:i,yy:s,zz:r,nn:o}=n;if(o.length===e)return;if(e>o.length)return;let a=0;for(let t=0;t<e;t++)a+=o[t];const h=new Int32Array(e);h.set(o.subarray(0,e));const l=new Float64Array(i.subarray(0,a)),c=new Float64Array(s.subarray(0,a)),u=r?new Float64Array(r.subarray(0,a)):null;t.updateVertexData(h,l,c,u)}(t,this.opts.originalArcCount);for(const t of this.opts.remaps)t.layer.shapes[t.featureId]=Wt(t.originalShape);this.opts.source.markDisplayArcsDirty?.(),Ft(this.opts.source.getDataset?.())}}}function Vt(t,e,n){const i=t.getArcs();if(!i)return null;const s=i.size();if(0===s||0===e.length)return null;const r=new Uint32Array(s),o=new Uint32Array(s),a=new Set;for(const t of e)a.add(Ht(t.layer,t.featureId));for(const t of n){if(!t.shapes)continue;if(!Nt(t))continue;const e=t.shapes;for(let n=0;n<e.length;n++){const i=e[n];if(!i)continue;const h=a.has(Ht(t,n));for(const t of i)if(Array.isArray(t))for(const e of t){if("number"!=typeof e)continue;const t=e>=0?e:~e;t<0||t>=s||(h?r[t]++:o[t]++)}}}const h=[];for(let t=0;t<s;t++)r[t]>0&&o[t]>0&&h.push(t);if(0===h.length)return null;const l=new globalThis.Map;for(let t=0;t<h.length;t++)l.set(h[t],s+t);const c=i.getVertexData?.();if(!c)return null;const{xx:u,yy:p,zz:d,ii:_,nn:f}=c,m=h.map(t=>{const e=_[t],n=f[t];return{xx:new Float64Array(u.subarray(e,e+n)),yy:new Float64Array(p.subarray(e,e+n)),zz:d?new Float64Array(d.subarray(e,e+n)):null}}),y=[];for(const t of e){if(!Nt(t.layer))continue;const e=t.layer.shapes?.[t.featureId];if(!e)continue;let n=!1;const i=e.map(t=>t.map(t=>{const e=t>=0?t:~t,i=l.get(e);return void 0===i?t:(n=!0,t>=0?i:~i)}));n&&y.push({layer:t.layer,featureId:t.featureId,originalShape:Wt(e),newShape:i})}return 0===y.length?null:{source:t,remaps:y,appendedArcs:m,originalArcCount:s}}function Ht(t,e){return`${t.name??""}#${e}`}function Wt(t){return t.map(t=>t.slice())}class Kt{_emap;constructor(t){this._emap=t}translateSelected(t,e){if(0===t&&0===e)return lt.validation("offset","dx and dy are both 0 (no-op)");const n=this._emap._selection.getAll();if(0===n.length)return lt.validation("selection","selection is empty");const i=new globalThis.Map;for(const t of n){const e=this._emap.layers.resolve(t.source,t.layer);if(!e?.shapes)continue;const n=e.shapes[t.id];if(!n)continue;let s=i.get(t.source);if(s||(s={arcIdSet:new Set,pointFeatures:[]},i.set(t.source,s)),"point"===e.geometry_type)s.pointFeatures.push({layer:e,featureId:t.id});else{const t=n;for(const e of t)if(Array.isArray(e))for(const t of e)"number"==typeof t&&s.arcIdSet.add(t>=0?t:~t)}}if(0===i.size)return lt.validation("selection","no resolvable layers in selection");const s=[],r=[];for(const[n,o]of i){const i=this._emap._sources.get(n);if(!i)continue;if(0===o.arcIdSet.size&&0===o.pointFeatures.length)continue;const a=new Gt({source:i,arcs:i.getArcs(),dx:t,dy:e,arcIds:Array.from(o.arcIdSet),pointFeatures:o.pointFeatures});a.do(),s.push(a),r.push(n)}if(0===s.length)return lt.validation("selection","every resolved layer was empty");const o=1===s.length?s[0]:new Lt(s,`Translate ${n.length} features`);return this._emap._history.push(o),this._emap._fireHistoryChange(),this._emap._clearSpatialIndexesForSources(r),this._emap._scheduleRender(),at}_buildSelectionBuckets(t){const e=this._emap._selection.getAll();if(0===e.length)return null;const n=new globalThis.Map;for(const t of e){const e=this._emap.layers.resolve(t.source,t.layer);if(!e?.shapes)continue;if(!e.shapes[t.id])continue;const i=this._emap._sources.get(t.source);if(!i)continue;let s=n.get(t.source);s||(s={sourceId:t.source,source:i,arcIds:[],pointFeatures:[],pathFeatures:[]},n.set(t.source,s)),"point"===e.geometry_type?s.pointFeatures.push({layer:e,featureId:t.id}):s.pathFeatures.push({layer:e,featureId:t.id})}if(0===n.size)return null;const i=[];if(t)for(const t of n.values()){if(0===t.pathFeatures.length)continue;const e=Vt(t.source,t.pathFeatures,t.source.getLayers());if(!e)continue;const n=new $t(e);n.do(),i.push(n),this._emap._invalidateShapeCachesForSources([t.sourceId])}for(const t of n.values()){const e=new Set;for(const n of t.pathFeatures){const i=n.layer.shapes?.[n.featureId];if(i)for(const n of i)if(Array.isArray(n))for(const i of n){if("number"!=typeof i)continue;const n=i>=0?i:~i;e.has(n)||(e.add(n),t.arcIds.push(n))}}}return{buckets:Array.from(n.values()).map(t=>({sourceId:t.sourceId,source:t.source,arcIds:t.arcIds,pointFeatures:t.pointFeatures})),splitCmds:i}}beginTranslateSession(t){const e=this._buildSelectionBuckets(!1!==t?.splitSharedArcs);if(!e)return null;const{buckets:n,splitCmds:i}=e;let s=0,r=0,o=!1;const a=(t,e)=>{for(const i of n)0===i.arcIds.length&&0===i.pointFeatures.length||new Gt({source:i.source,arcs:i.source.getArcs(),dx:t,dy:e,arcIds:i.arcIds,pointFeatures:i.pointFeatures}).do()};return{move:(t,e)=>{o||0===t&&0===e||(a(t,e),s+=t,r+=e,this._emap._scheduleRender())},commit:()=>{if(o)return!1;o=!0;if(!!(0===s&&0===r)){for(let t=i.length-1;t>=0;t--)i[t].undo();return i.length>0&&this._emap._scheduleRender(),!1}const t=n.map(t=>new Gt({source:t.source,arcs:t.source.getArcs(),dx:s,dy:r,arcIds:t.arcIds,pointFeatures:t.pointFeatures})),e=n.reduce((t,e)=>t+e.arcIds.length+e.pointFeatures.length,0),a=[...i,...t],h=1===a.length?a[0]:new Lt(a,`Translate ${e} features`);return this._emap._history.push(h),this._emap._fireHistoryChange(),this._emap._invalidateShapeCachesForSources(n.map(t=>t.sourceId)),this._emap._scheduleRender(),!0},cancel:()=>{if(!o){o=!0,0===s&&0===r||a(-s,-r);for(let t=i.length-1;t>=0;t--)i[t].undo();s=0,r=0,i.length>0&&this._emap._invalidateShapeCachesForSources(n.map(t=>t.sourceId)),this._emap._scheduleRender()}},getAccumulated:()=>[s,r]}}beginAffineSession(t,e){const n=this._buildSelectionBuckets(!1!==e?.splitSharedArcs);if(!n)return null;const{buckets:i,splitCmds:s}=n;let r,o;if(t)[r,o]=t;else{const t=new globalThis.Map;for(const e of i)t.set(e.sourceId,{arcIdSet:new Set(e.arcIds),pointFeatures:e.pointFeatures});const e=this._computeSelectionCentroid(t);if(!e){for(let t=s.length-1;t>=0;t--)s[t].undo();return null}[r,o]=e}if(!Number.isFinite(r)||!Number.isFinite(o)){for(let t=s.length-1;t>=0;t--)s[t].undo();return null}const a=[r,o];let h={...qt},l=!1;const c=t=>1===t.a&&0===t.b&&0===t.c&&1===t.d&&0===t.tx&&0===t.ty,u=t=>{for(const e of i)0===e.arcIds.length&&0===e.pointFeatures.length||new Ot({source:e.source,arcs:e.source.getArcs(),matrix:t,arcIds:e.arcIds,pointFeatures:e.pointFeatures}).do()};return{origin:a,applyDelta:t=>{l||c(t)||(u(t),h=Ut(t,h),this._emap._scheduleRender())},commit:t=>{if(l)return!1;if(l=!0,c(h)){for(let t=s.length-1;t>=0;t--)s[t].undo();return s.length>0&&this._emap._scheduleRender(),!1}const e=i.reduce((t,e)=>t+e.arcIds.length+e.pointFeatures.length,0),n=i.map(e=>new Ot({source:e.source,arcs:e.source.getArcs(),matrix:h,arcIds:e.arcIds,pointFeatures:e.pointFeatures,label:t})),r=[...s,...n],o=1===r.length?r[0]:new Lt(r,t??`Transform ${e} feature${1===e?"":"s"}`);return this._emap._history.push(o),this._emap._fireHistoryChange(),this._emap._invalidateShapeCachesForSources(i.map(t=>t.sourceId)),this._emap._scheduleRender(),!0},cancel:()=>{if(!l){l=!0,c(h)||u(jt(h));for(let t=s.length-1;t>=0;t--)s[t].undo();h={...qt},s.length>0&&this._emap._invalidateShapeCachesForSources(i.map(t=>t.sourceId)),this._emap._scheduleRender()}},getCumulative:()=>({...h})}}rotateSelected(t,e){if(0===t)return lt.validation("angleDegrees","angle is 0 (no-op)");const n=t*Math.PI/180;return this._applyAffineToSelection((t,e)=>Bt(n,t,e),e,t=>`Rotate ${t} feature${1===t?"":"s"}`)}scaleSelected(t,e,n){const i=t,s=e??t;return 1===i&&1===s?lt.validation("scale","sx and sy are both 1 (no-op)"):this._applyAffineToSelection((t,e)=>zt(i,s,t,e),n,t=>`Scale ${t} feature${1===t?"":"s"}`)}_applyAffineToSelection(t,e,n){const i=this._emap._selection.getAll();if(0===i.length)return lt.validation("selection","selection is empty");const s=new globalThis.Map;for(const t of i){const e=this._emap.layers.resolve(t.source,t.layer);if(!e?.shapes)continue;const n=e.shapes[t.id];if(!n)continue;let i=s.get(t.source);if(i||(i={arcIdSet:new Set,pointFeatures:[]},s.set(t.source,i)),"point"===e.geometry_type)i.pointFeatures.push({layer:e,featureId:t.id});else{const t=n;for(const e of t)if(Array.isArray(e))for(const t of e)"number"==typeof t&&i.arcIdSet.add(t>=0?t:~t)}}if(0===s.size)return lt.validation("selection","no resolvable layers in selection");let r,o;if(e)r=e[0],o=e[1];else{const t=this._computeSelectionCentroid(s);if(!t)return lt.validation("origin","no vertices in selection; cannot compute centroid");[r,o]=t}if(!Number.isFinite(r)||!Number.isFinite(o))return lt.validation("origin","computed origin is not finite");const a=t(r,o),h=[],l=[];for(const[t,e]of s){const n=this._emap._sources.get(t);if(!n)continue;if(0===e.arcIdSet.size&&0===e.pointFeatures.length)continue;const i=new Ot({source:n,arcs:n.getArcs(),matrix:a,arcIds:Array.from(e.arcIdSet),pointFeatures:e.pointFeatures});i.do(),h.push(i),l.push(t)}if(0===h.length)return lt.validation("selection","every resolved layer was empty");const c=1===h.length?h[0]:new Lt(h,n(i.length));return this._emap._history.push(c),this._emap._fireHistoryChange(),this._emap._clearSpatialIndexesForSources(l),this._emap._scheduleRender(),at}_computeSelectionCentroid(t){let e=1/0,n=1/0,i=-1/0,s=-1/0,r=!1;for(const[o,a]of t){const t=this._emap._sources.get(o);if(!t)continue;const h=t.getArcs(),l=h?.getVertexData?.();if(l&&a.arcIdSet.size>0){const{xx:t,yy:o,ii:h,nn:c}=l;for(const l of a.arcIdSet){const a=h[l],u=c[l];for(let h=a;h<a+u;h++){const a=t[h],l=o[h];a<e&&(e=a),a>i&&(i=a),l<n&&(n=l),l>s&&(s=l),r=!0}}}for(const t of a.pointFeatures){const o=t.layer.shapes?.[t.featureId];if(o)for(const t of it(o)){if(!t||t.length<2)continue;const o=t[0],a=t[1];o<e&&(e=o),o>i&&(i=o),a<n&&(n=a),a>s&&(s=a),r=!0}}}return r?[(e+i)/2,(n+s)/2]:null}}class Xt{opts;label;constructor(t){this.opts=t,this.label=t.label??"Edit properties"}do(){Zt(this.opts.layer,this.opts.featureId,this.opts.prev,this.opts.next)}undo(){Zt(this.opts.layer,this.opts.featureId,this.opts.next,this.opts.prev)}}function Zt(t,e,n,i){const s=t.data?.getRecords?.(),r=s?.[e];if(r){for(const t of Object.keys(i))r[t]=i[t];for(const t of Object.keys(n))t in i||delete r[t]}}class Jt{opts;label;_addedIndices=[];constructor(t){this.opts=t,this.label=`Add field ${t.field}`}do(){const t=this.opts.layer.data?.getRecords?.();if(!t)return;const e=this.opts.defaultValue??null;this._addedIndices=[];for(let n=0;n<t.length;n++)t[n]&&!(this.opts.field in t[n])&&(t[n][this.opts.field]=e,this._addedIndices.push(n))}undo(){const t=this.opts.layer.data?.getRecords?.();if(t){for(const e of this._addedIndices)delete t[e]?.[this.opts.field];this._addedIndices=[]}}}class Yt{opts;label;_snapshot=new globalThis.Map;constructor(t){this.opts=t,this.label=`Remove field ${t.field}`}do(){const t=this.opts.layer.data?.getRecords?.();if(t){this._snapshot.clear();for(let e=0;e<t.length;e++){const n=t[e];n&&this.opts.field in n&&(this._snapshot.set(e,n[this.opts.field]),delete n[this.opts.field])}}}undo(){const t=this.opts.layer.data?.getRecords?.();if(t)for(const[e,n]of this._snapshot){const i=t[e];i&&(i[this.opts.field]=n)}}}class Qt{opts;label;constructor(t){this.opts=t,this.label=`Rename field ${t.from} → ${t.to}`}do(){te(this.opts.layer,this.opts.from,this.opts.to)}undo(){te(this.opts.layer,this.opts.to,this.opts.from)}}function te(t,e,n){const i=t.data?.getRecords?.();if(i)for(const t of i)t&&e in t&&(t[n]=t[e],delete t[e])}class ee{_emap;constructor(t){this._emap=t}setFeatureProperty(t,e,n){return this.setFeatureProperties(t,{[e]:n})}setFeatureProperties(t,e){const n=this._emap.layers.resolve(t.source,t.layer);if(!n)return lt.notFound("layer",t.layer);const i=n.data?.getRecords?.(),s=i?.[t.id];if(!s)return lt.notFound("field",`record#${t.id}`);const r={},o={};for(const t of Object.keys(e)){const n=t in s,i=n?s[t]:void 0,a=e[t];(void 0!==a||n)&&(void 0!==a&&n&&s[t]===a||(n&&(r[t]=i),void 0!==a&&(o[t]=a)))}if(0===Object.keys(r).length&&0===Object.keys(o).length)return lt.validation("props","no-op: every requested value already matches the record");const a=new Xt({layer:n,featureId:t.id,prev:r,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 lt.notFound("layer",t.target);if(!e.data)return lt.validation("target","layer has no data table");const n=new Jt({layer:e,field:t.field,defaultValue:t.defaultValue});return n.do(),this._emap._history.push(n),this._emap._fireHistoryChange(),this._emap._scheduleRender(),at}removeField(t){const e=this._emap.layers.resolve(t.source,t.target);if(!e)return lt.notFound("layer",t.target);if(!e.data)return lt.validation("target","layer has no data table");const n=new Yt({layer:e,field:t.field});return n.do(),this._emap._history.push(n),this._emap._fireHistoryChange(),this._emap._scheduleRender(),at}renameField(t){const e=this._emap.layers.resolve(t.source,t.target);if(!e)return lt.notFound("layer",t.target);if(!e.data)return lt.validation("target","layer has no data table");const n=e.data.getRecords?.();if(!n)return lt.validation("target","data table has no records");if(t.from===t.to)return lt.validation("to","`from` and `to` are identical");for(const e of n)if(e&&t.from in e&&t.to in e)return lt.validation("to",`would overwrite existing '${t.to}' on at least one record`);const i=new Qt({layer:e,from:t.from,to:t.to});return i.do(),this._emap._history.push(i),this._emap._fireHistoryChange(),this._emap._scheduleRender(),at}}class ne{_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={},se=Uint8Array,re=Uint16Array,oe=Int32Array,ae=new se([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]),he=new se([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 se([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 n=new re(31),i=0;i<31;++i)n[i]=e+=1<<t[i-1];var s=new oe(n[30]);for(i=1;i<30;++i)for(var r=n[i];r<n[i+1];++r)s[r]=r-n[i]<<5|i;return{b:n,r:s}},ue=ce(ae,2),pe=ue.b,de=ue.r;pe[28]=258,de[258]=28;for(var _e=ce(he,0),fe=_e.b,me=_e.r,ye=new re(32768),ge=0;ge<32768;++ge){var ve=(43690&ge)>>1|(21845&ge)<<1;ve=(61680&(ve=(52428&ve)>>2|(13107&ve)<<2))>>4|(3855&ve)<<4,ye[ge]=((65280&ve)>>8|(255&ve)<<8)>>1}var xe=function(t,e,n){for(var i=t.length,s=0,r=new re(e);s<i;++s)t[s]&&++r[t[s]-1];var o,a=new re(e);for(s=1;s<e;++s)a[s]=a[s-1]+r[s-1]<<1;if(n){o=new re(1<<e);var h=15-e;for(s=0;s<i;++s)if(t[s])for(var l=s<<4|t[s],c=e-t[s],u=a[t[s]-1]++<<c,p=u|(1<<c)-1;u<=p;++u)o[ye[u]>>h]=l}else for(o=new re(i),s=0;s<i;++s)t[s]&&(o[s]=ye[a[t[s]-1]++]>>15-t[s]);return o},we=new se(288);for(ge=0;ge<144;++ge)we[ge]=8;for(ge=144;ge<256;++ge)we[ge]=9;for(ge=256;ge<280;++ge)we[ge]=7;for(ge=280;ge<288;++ge)we[ge]=8;var be=new se(32);for(ge=0;ge<32;++ge)be[ge]=5;var Ce=xe(we,9,0),Se=xe(we,9,1),Ae=xe(be,5,0),Me=xe(be,5,1),Ee=function(t){for(var e=t[0],n=1;n<t.length;++n)t[n]>e&&(e=t[n]);return e},ke=function(t,e,n){var i=e/8|0;return(t[i]|t[i+1]<<8)>>(7&e)&n},De=function(t,e){var n=e/8|0;return(t[n]|t[n+1]<<8|t[n+2]<<16)>>(7&e)},Ie=function(t){return(t+7)/8|0},Pe=function(t,e,n){return(null==e||e<0)&&(e=0),(null==n||n>t.length)&&(n=t.length),new se(t.subarray(e,n))},Te=["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"],Le=function(t,e,n){var i=new Error(e||Te[t]);if(i.code=t,Error.captureStackTrace&&Error.captureStackTrace(i,Le),!n)throw i;return i},Ne=function(t,e,n,i){var s=t.length,r=i?i.length:0;if(!s||e.f&&!e.l)return n||new se(0);var o=!n,a=o||2!=e.i,h=e.i;o&&(n=new se(3*s));var l=function(t){var e=n.length;if(t>e){var i=new se(Math.max(2*e,t));i.set(n),n=i}},c=e.f||0,u=e.p||0,p=e.b||0,d=e.l,_=e.d,f=e.m,m=e.n,y=8*s;do{if(!d){c=ke(t,u,1);var g=ke(t,u+1,3);if(u+=3,!g){var v=t[(I=Ie(u)+4)-4]|t[I-3]<<8,x=I+v;if(x>s){h&&Le(0);break}a&&l(p+v),n.set(t.subarray(I,x),p),e.b=p+=v,e.p=u=8*x,e.f=c;continue}if(1==g)d=Se,_=Me,f=9,m=5;else if(2==g){var w=ke(t,u,31)+257,b=ke(t,u+10,15)+4,C=w+ke(t,u+5,31)+1;u+=14;for(var S=new se(C),A=new se(19),M=0;M<b;++M)A[le[M]]=ke(t,u+3*M,7);u+=3*b;var E=Ee(A),k=(1<<E)-1,D=xe(A,E,1);for(M=0;M<C;){var I,P=D[ke(t,u,k)];if(u+=15&P,(I=P>>4)<16)S[M++]=I;else{var T=0,L=0;for(16==I?(L=3+ke(t,u,3),u+=2,T=S[M-1]):17==I?(L=3+ke(t,u,7),u+=3):18==I&&(L=11+ke(t,u,127),u+=7);L--;)S[M++]=T}}var N=S.subarray(0,w),R=S.subarray(w);f=Ee(N),m=Ee(R),d=xe(N,f,1),_=xe(R,m,1)}else Le(1);if(u>y){h&&Le(0);break}}a&&l(p+131072);for(var F=(1<<f)-1,G=(1<<m)-1,O=u;;O=u){var B=(T=d[De(t,u)&F])>>4;if((u+=15&T)>y){h&&Le(0);break}if(T||Le(2),B<256)n[p++]=B;else{if(256==B){O=u,d=null;break}var z=B-254;if(B>264){var U=ae[M=B-257];z=ke(t,u,(1<<U)-1)+pe[M],u+=U}var q=_[De(t,u)&G],j=q>>4;q||Le(3),u+=15&q;R=fe[j];if(j>3){U=he[j];R+=De(t,u)&(1<<U)-1,u+=U}if(u>y){h&&Le(0);break}a&&l(p+131072);var $=p+z;if(p<R){var V=r-R,H=Math.min(R,$);for(V+p<0&&Le(3);p<H;++p)n[p]=i[V+p]}for(;p<$;++p)n[p]=n[p-R]}}e.l=d,e.p=O,e.b=p,e.f=c,d&&(c=1,e.m=f,e.d=_,e.n=m)}while(!c);return p!=n.length&&o?Pe(n,0,p):n.subarray(0,p)},Re=function(t,e,n){n<<=7&e;var i=e/8|0;t[i]|=n,t[i+1]|=n>>8},Fe=function(t,e,n){n<<=7&e;var i=e/8|0;t[i]|=n,t[i+1]|=n>>8,t[i+2]|=n>>16},Ge=function(t,e){for(var n=[],i=0;i<t.length;++i)t[i]&&n.push({s:i,f:t[i]});var s=n.length,r=n.slice();if(!s)return{t:$e,l:0};if(1==s){var o=new se(n[0].s+1);return o[n[0].s]=1,{t:o,l:1}}n.sort(function(t,e){return t.f-e.f}),n.push({s:-1,f:25001});var a=n[0],h=n[1],l=0,c=1,u=2;for(n[0]={s:-1,f:a.f+h.f,l:a,r:h};c!=s-1;)a=n[n[l].f<n[u].f?l++:u++],h=n[l!=c&&n[l].f<n[u].f?l++:u++],n[c++]={s:-1,f:a.f+h.f,l:a,r:h};var p=r[0].s;for(i=1;i<s;++i)r[i].s>p&&(p=r[i].s);var d=new re(p+1),_=Oe(n[c-1],d,0);if(_>e){i=0;var f=0,m=_-e,y=1<<m;for(r.sort(function(t,e){return d[e.s]-d[t.s]||t.f-e.f});i<s;++i){var g=r[i].s;if(!(d[g]>e))break;f+=y-(1<<_-d[g]),d[g]=e}for(f>>=m;f>0;){var v=r[i].s;d[v]<e?f-=1<<e-d[v]++-1:++i}for(;i>=0&&f;--i){var x=r[i].s;d[x]==e&&(--d[x],++f)}_=e}return{t:new se(d),l:_}},Oe=function(t,e,n){return-1==t.s?Math.max(Oe(t.l,e,n+1),Oe(t.r,e,n+1)):e[t.s]=n},Be=function(t){for(var e=t.length;e&&!t[--e];);for(var n=new re(++e),i=0,s=t[0],r=1,o=function(t){n[i++]=t},a=1;a<=e;++a)if(t[a]==s&&a!=e)++r;else{if(!s&&r>2){for(;r>138;r-=138)o(32754);r>2&&(o(r>10?r-11<<5|28690:r-3<<5|12305),r=0)}else if(r>3){for(o(s),--r;r>6;r-=6)o(8304);r>2&&(o(r-3<<5|8208),r=0)}for(;r--;)o(s);r=1,s=t[a]}return{c:n.subarray(0,i),n:e}},ze=function(t,e){for(var n=0,i=0;i<e.length;++i)n+=t[i]*e[i];return n},Ue=function(t,e,n){var i=n.length,s=Ie(e+2);t[s]=255&i,t[s+1]=i>>8,t[s+2]=255^t[s],t[s+3]=255^t[s+1];for(var r=0;r<i;++r)t[s+r+4]=n[r];return 8*(s+4+i)},qe=function(t,e,n,i,s,r,o,a,h,l,c){Re(e,c++,n),++s[256];for(var u=Ge(s,15),p=u.t,d=u.l,_=Ge(r,15),f=_.t,m=_.l,y=Be(p),g=y.c,v=y.n,x=Be(f),w=x.c,b=x.n,C=new re(19),S=0;S<g.length;++S)++C[31&g[S]];for(S=0;S<w.length;++S)++C[31&w[S]];for(var A=Ge(C,7),M=A.t,E=A.l,k=19;k>4&&!M[le[k-1]];--k);var D,I,P,T,L=l+5<<3,N=ze(s,we)+ze(r,be)+o,R=ze(s,p)+ze(r,f)+o+14+3*k+ze(C,M)+2*C[16]+3*C[17]+7*C[18];if(h>=0&&L<=N&&L<=R)return Ue(e,c,t.subarray(h,h+l));if(Re(e,c,1+(R<N)),c+=2,R<N){D=xe(p,d,0),I=p,P=xe(f,m,0),T=f;var F=xe(M,E,0);Re(e,c,v-257),Re(e,c+5,b-1),Re(e,c+10,k-4),c+=14;for(S=0;S<k;++S)Re(e,c+3*S,M[le[S]]);c+=3*k;for(var G=[g,w],O=0;O<2;++O){var B=G[O];for(S=0;S<B.length;++S){var z=31&B[S];Re(e,c,F[z]),c+=M[z],z>15&&(Re(e,c,B[S]>>5&127),c+=B[S]>>12)}}}else D=Ce,I=we,P=Ae,T=be;for(S=0;S<a;++S){var U=i[S];if(U>255){Fe(e,c,D[(z=U>>18&31)+257]),c+=I[z+257],z>7&&(Re(e,c,U>>23&31),c+=ae[z]);var q=31&U;Fe(e,c,P[q]),c+=T[q],q>3&&(Fe(e,c,U>>5&8191),c+=he[q])}else Fe(e,c,D[U]),c+=I[U]}return Fe(e,c,D[256]),c+I[256]},je=new oe([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),$e=new se(0),Ve=function(){for(var t=new Int32Array(256),e=0;e<256;++e){for(var n=e,i=9;--i;)n=(1&n&&-306674912)^n>>>1;t[e]=n}return t}(),He=function(){var t=-1;return{p:function(e){for(var n=t,i=0;i<e.length;++i)n=Ve[255&n^e[i]]^n>>>8;t=n},d:function(){return~t}}},We=function(t,e,n,i,s){if(!s&&(s={l:1},e.dictionary)){var r=e.dictionary.subarray(-32768),o=new se(r.length+t.length);o.set(r),o.set(t,r.length),t=o,s.w=r.length}return function(t,e,n,i,s,r){var o=r.z||t.length,a=new se(i+o+5*(1+Math.ceil(o/7e3))+s),h=a.subarray(i,a.length-s),l=r.l,c=7&(r.r||0);if(e){c&&(h[0]=r.r>>3);for(var u=je[e-1],p=u>>13,d=8191&u,_=(1<<n)-1,f=r.p||new re(32768),m=r.h||new re(_+1),y=Math.ceil(n/3),g=2*y,v=function(e){return(t[e]^t[e+1]<<y^t[e+2]<<g)&_},x=new oe(25e3),w=new re(288),b=new re(32),C=0,S=0,A=r.i||0,M=0,E=r.w||0,k=0;A+2<o;++A){var D=v(A),I=32767&A,P=m[D];if(f[I]=P,m[D]=I,E<=A){var T=o-A;if((C>7e3||M>24576)&&(T>423||!l)){c=qe(t,h,0,x,w,b,S,M,k,A-k,c),M=C=S=0,k=A;for(var L=0;L<286;++L)w[L]=0;for(L=0;L<30;++L)b[L]=0}var N=2,R=0,F=d,G=I-P&32767;if(T>2&&D==v(A-G))for(var O=Math.min(p,T)-1,B=Math.min(32767,A),z=Math.min(258,T);G<=B&&--F&&I!=P;){if(t[A+N]==t[A+N-G]){for(var U=0;U<z&&t[A+U]==t[A+U-G];++U);if(U>N){if(N=U,R=G,U>O)break;var q=Math.min(G,U-2),j=0;for(L=0;L<q;++L){var $=A-G+L&32767,V=$-f[$]&32767;V>j&&(j=V,P=$)}}}G+=(I=P)-(P=f[I])&32767}if(R){x[M++]=268435456|de[N]<<18|me[R];var H=31&de[N],W=31&me[R];S+=ae[H]+he[W],++w[257+H],++b[W],E=A+N,++C}else x[M++]=t[A],++w[t[A]]}}for(A=Math.max(A,E);A<o;++A)x[M++]=t[A],++w[t[A]];c=qe(t,h,l,x,w,b,S,M,k,A-k,c),l||(r.r=7&c|h[c/8|0]<<3,c-=7,r.h=m,r.p=f,r.i=A,r.w=E)}else{for(A=r.w||0;A<o+l;A+=65535){var K=A+65535;K>=o&&(h[c/8|0]=l,K=o),c=Ue(h,c+1,t.subarray(A,K))}r.i=o}return Pe(a,0,i+Ie(c)+s)}(t,null==e.level?6:e.level,null==e.mem?s.l?Math.ceil(1.5*Math.max(8,Math.min(13,Math.log(t.length)))):20:12+e.mem,n,i,s)},Ke=function(t,e){var n={};for(var i in t)n[i]=t[i];for(var i in e)n[i]=e[i];return n},Xe=function(t,e,n){for(var i=t(),s=t.toString(),r=s.slice(s.indexOf("[")+1,s.lastIndexOf("]")).replace(/\s+/g,"").split(","),o=0;o<i.length;++o){var a=i[o],h=r[o];if("function"==typeof a){e+=";"+h+"=";var l=a.toString();if(a.prototype)if(-1!=l.indexOf("[native code]")){var c=l.indexOf(" ",8)+1;e+=l.slice(c,l.indexOf("(",c))}else for(var u in e+=l,a.prototype)e+=";"+h+".prototype."+u+"="+a.prototype[u].toString();else e+=l}else n[h]=a}return e},Ze=[],Je=function(t,e,n,i){if(!Ze[n]){for(var s="",r={},o=t.length-1,a=0;a<o;++a)s=Xe(t[a],s,r);Ze[n]={c:Xe(t[o],s,r),e:r}}var h=Ke({},Ze[n].e);return function(t,e,n,i,s){var r=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 r.onmessage=function(t){var e=t.data,n=e.$e$;if(n){var i=new Error(n[0]);i.code=n[1],i.stack=n[2],s(i,null)}else s(null,e)},r.postMessage(n,i),r}(Ze[n].c+";onmessage=function(e){for(var k in e.data)self[k]=e.data[k];onmessage="+e.toString()+"}",n,h,function(t){var e=[];for(var n in t)t[n].buffer&&e.push((t[n]=new t[n].constructor(t[n])).buffer);return e}(h),i)},Ye=function(){return[se,re,oe,ae,he,le,pe,fe,Se,Me,ye,Te,xe,Ee,ke,De,Ie,Pe,Le,Ne,hn,Qe,tn]},Qe=function(t){return postMessage(t,[t.buffer])},tn=function(t){return t&&{out:t.size&&new se(t.size),dictionary:t.dictionary}},en=function(t,e){return t[e]|t[e+1]<<8},nn=function(t,e){return(t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24)>>>0},sn=function(t,e){return nn(t,e)+4294967296*nn(t,e+4)},rn=function(t,e,n){for(;n;++e)t[e]=n,n>>>=8};function on(t,e){return We(t,e||{},0,0)}function an(t,e,n){return n||(n=e,e={}),"function"!=typeof n&&Le(7),function(t,e,n,i,s,r){var o=Je(n,i,s,function(t,e){o.terminate(),r(t,e)});return o.postMessage([t,e],e.consume?[t.buffer]:[]),function(){o.terminate()}}(t,e,[Ye],function(t){return Qe(hn(t.data[0],tn(t.data[1])))},1,n)}function hn(t,e){return Ne(t,{i:2},e&&e.out,e&&e.dictionary)}var ln=function(t,e,n,i){for(var s in t){var r=t[s],o=e+s,a=i;Array.isArray(r)&&(a=Ke(i,r[1]),r=r[0]),r instanceof se?n[o]=[r,a]:(n[o+="/"]=[new se(0),a],ln(r,o,n,i))}},cn="undefined"!=typeof TextEncoder&&new TextEncoder,un="undefined"!=typeof TextDecoder&&new TextDecoder;try{un.decode($e,{stream:!0})}catch(t){}function pn(t,e){if(cn)return cn.encode(t);for(var n=t.length,i=new se(t.length+(t.length>>1)),s=0,r=function(t){i[s++]=t},o=0;o<n;++o){if(s+5>i.length){var a=new se(s+8+(n-o<<1));a.set(i),i=a}var h=t.charCodeAt(o);h<128||e?r(h):h<2048?(r(192|h>>6),r(128|63&h)):h>55295&&h<57344?(r(240|(h=65536+(1047552&h)|1023&t.charCodeAt(++o))>>18),r(128|h>>12&63),r(128|h>>6&63),r(128|63&h)):(r(224|h>>12),r(128|h>>6&63),r(128|63&h))}return Pe(i,0,s)}function dn(t,e){if(e){for(var n="",i=0;i<t.length;i+=16384)n+=String.fromCharCode.apply(null,t.subarray(i,i+16384));return n}if(un)return un.decode(t);var s=function(t){for(var e="",n=0;;){var i=t[n++],s=(i>127)+(i>223)+(i>239);if(n+s>t.length)return{s:e,r:Pe(t,n-1)};s?3==s?(i=((15&i)<<18|(63&t[n++])<<12|(63&t[n++])<<6|63&t[n++])-65536,e+=String.fromCharCode(55296|i>>10,56320|1023&i)):e+=1&s?String.fromCharCode((31&i)<<6|63&t[n++]):String.fromCharCode((15&i)<<12|(63&t[n++])<<6|63&t[n++]):e+=String.fromCharCode(i)}}(t),r=s.s;return(n=s.r).length&&Le(8),r}var _n=function(t,e){for(;1!=en(t,e);e+=4+en(t,e+2));return[sn(t,e+12),sn(t,e+4),sn(t,e+20)]},fn=function(t){var e=0;if(t)for(var n in t){var i=t[n].length;i>65535&&Le(9),e+=i+4}return e},mn=function(t,e,n,i,s,r,o,a){var h=i.length,l=n.extra,c=a&&a.length,u=fn(l);rn(t,e,null!=o?33639248:67324752),e+=4,null!=o&&(t[e++]=20,t[e++]=n.os),t[e]=20,e+=2,t[e++]=n.flag<<1|(r<0&&8),t[e++]=s&&8,t[e++]=255&n.compression,t[e++]=n.compression>>8;var p=new Date(null==n.mtime?Date.now():n.mtime),d=p.getFullYear()-1980;if((d<0||d>119)&&Le(10),rn(t,e,d<<25|p.getMonth()+1<<21|p.getDate()<<16|p.getHours()<<11|p.getMinutes()<<5|p.getSeconds()>>1),e+=4,-1!=r&&(rn(t,e,n.crc),rn(t,e+4,r<0?-r-2:r),rn(t,e+8,n.size)),rn(t,e+12,h),rn(t,e+14,u),e+=16,null!=o&&(rn(t,e,c),rn(t,e+6,n.attrs),rn(t,e+10,o),e+=14),t.set(i,e),e+=h,u)for(var _ in l){var f=l[_],m=f.length;rn(t,e,+_),rn(t,e+2,m),t.set(f,e+4),e+=4+m}return c&&(t.set(a,e),e+=c),e};function yn(t,e){e||(e={});var n={},i=[];ln(t,"",n,e);var s=0,r=0;for(var o in n){var a=n[o],h=a[0],l=a[1],c=0==l.level?0:8,u=(C=pn(o)).length,p=l.comment,d=p&&pn(p),_=d&&d.length,f=fn(l.extra);u>65535&&Le(11);var m=c?on(h,l):h,y=m.length,g=He();g.p(h),i.push(Ke(l,{size:h.length,crc:g.d(),c:m,f:C,m:d,u:u!=o.length||d&&p.length!=_,o:s,compression:c})),s+=30+u+f+y,r+=76+2*(u+f)+(_||0)+y}for(var v=new se(r+22),x=s,w=r-s,b=0;b<i.length;++b){var C=i[b];mn(v,C.o,C,C.f,C.u,C.c.length);var S=30+C.f.length+fn(C.extra);v.set(C.c,C.o+S),mn(v,s,C,C.f,C.u,C.c.length,C.o,C.m),s+=16+S+(C.m?C.m.length:0)}return function(t,e,n,i,s){rn(t,e,101010256),rn(t,e+8,n),rn(t,e+10,n),rn(t,e+12,i),rn(t,e+16,s)}(v,s,i.length,w,x),v}var gn="function"==typeof queueMicrotask?queueMicrotask:"function"==typeof setTimeout?setTimeout:function(t){t()};function vn(t,e,n){n||(n=e,e={}),"function"!=typeof n&&Le(7);var i=[],s=function(){for(var t=0;t<i.length;++t)i[t]()},r={},o=function(t,e){gn(function(){n(t,e)})};gn(function(){o=n});for(var a=t.length-22;101010256!=nn(t,a);--a)if(!a||t.length-a>65558)return o(Le(13,0,1),null),s;var h=en(t,a+8);if(h){var l=h,c=nn(t,a+16),u=4294967295==c||65535==l;if(u){var p=nn(t,a-12);(u=101075792==nn(t,p))&&(l=h=nn(t,p+32),c=nn(t,p+48))}for(var d=e&&e.filter,_=function(e){var n=function(t,e,n){var i=en(t,e+28),s=dn(t.subarray(e+46,e+46+i),!(2048&en(t,e+8))),r=e+46+i,o=nn(t,e+20),a=n&&4294967295==o?_n(t,r):[o,nn(t,e+24),nn(t,e+42)],h=a[0],l=a[1],c=a[2];return[en(t,e+10),h,l,s,r+en(t,e+30)+en(t,e+32),c]}(t,c,u),a=n[0],l=n[1],p=n[2],_=n[3],f=n[4],m=n[5],y=function(t,e){return e+30+en(t,e+26)+en(t,e+28)}(t,m);c=f;var g=function(t,e){t?(s(),o(t,null)):(e&&(r[_]=e),--h||o(null,r))};if(!d||d({name:_,size:l,originalSize:p,compression:a}))if(a)if(8==a){var v=t.subarray(y,y+l);if(p<524288||l>.8*p)try{g(null,hn(v,{out:new se(p)}))}catch(t){g(t,null)}else i.push(an(v,{size:p},g))}else g(Le(14,"unknown compression type "+a,1),null);else g(null,Pe(t,y,y+l));else g(null,null)},f=0;f<l;++f)_()}else o(null,{});return s}const xn=5e5;class wn{_unfilteredArcs;_filteredArcs=null;_filteredSegLen=0;_dirty=!1;constructor(t){this._unfilteredArcs=t;(t.getPointCount?.()??0)>xn&&this._initFilteredArcs()}markDirty(){this._dirty=!0}_initFilteredArcs(){const t=this._unfilteredArcs,e=t.getVertexData?.();if(e?.zz){const e=.08,n=Math.ceil((t.getPointCount?.()??0)/xn),i=t.getRetainedInterval?.()??0,s=t.getThresholdByPct?.(e,n)??0;this._filteredArcs=t.setRetainedInterval?.(s)?.getFilteredCopy?.()??null,t.setRetainedInterval?.(i),this._filteredArcs&&(this._filteredSegLen=Y().getAvgSegment(this._filteredArcs))}else{const e=Y();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)>xn&&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 bn{_adapter;constructor(t=Y()){this._adapter=t}async runImport(t,e){return this._adapter.runImport(t,e)}}let Cn=null;const Sn="EPSG:4326";function An(t){if(!t)return Sn;const e=t.info;if(!e)return Sn;if(e.crs_string)return Mn(e.crs_string);if(e.prj){const t=En(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 Sn}function Mn(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 En(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 kn={geojson:"application/geo+json",topojson:"application/json",shapefile:"application/zip",msx:"application/octet-stream"};function Dn(t){return"string"==typeof t?(new TextEncoder).encode(t):t instanceof Uint8Array?t:new Uint8Array(t)}const In={maxBytes:209715200,maxEntries:5e3,maxRatio:100};class Pn extends j{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??Cn??(Cn=new bn),this._data&&this._updateData()}static async fromUrl(t,e,n){const i=new Pn(t,n);return await i.setData(e),i}static async fromBytes(t,e,n){const{filename:i=`${t}.geojson`,...s}=n??{},r=e instanceof Uint8Array?e:new Uint8Array(e),o=new Pn(t,s);return await o.setData({filename:i,content:r}),o}setData(t){this._loadVersion++;const e=this._loadVersion;this._abortController?.abort(),this._abortController=null,this._data=t,this._pending?.resolve(this);const n=new Promise((t,n)=>{this._pending={version:e,resolve:t,reject:n}});return n.catch(()=>{}),this._updateData(),n}async _updateData(){if(!this._data)return;const t=this._loadVersion,e=new AbortController;this._abortController=e,this.fire("dataloading");try{const n={},i=[];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),s=this._findPrimaryFile(e);if(!s)throw new Error(`No importable file found in zip archive: ${t.filename}`);for(const[t,i]of Object.entries(e))n[t]=i;i.push(s)}else n[t.filename]=t.content,i.push(t.filename)}else{let t;if("string"==typeof this._data){const n=this._data,i=await fetch(n,{signal:e.signal});if(!i.ok)throw new Error(`Failed to fetch ${n}: HTTP ${i.status}`);const s=await i.arrayBuffer(),r=new Uint8Array(s);let o=new URL(n).pathname.split("/").pop()||"";if(!this._hasSupportedExtension(o)){const t=i.headers.get("Content-Type")||"";o=this._filenameFromContentType(t,o)}o||(o="data.json"),t={filename:o,content:r}}else t=this._data;if(this._isZipFile(t.filename)){const e=await this._extractZip(t.content),s=this._findPrimaryFile(e);if(!s)throw new Error("No importable file found in zip archive");for(const[t,i]of Object.entries(e))n[t]=i;i.push(s)}else n[t.filename]=t.content,i.push(t.filename)}const s=`-i ${i.map(t=>`"${t.replace(/"/g,'\\"')}"`).join(" ")}`,r=await this._runner.runImport(s,n);if(t!==this._loadVersion)return;this._dataset=r,this._dataset?.arcs&&(this._displayArcs=new wn(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 n=this._pending;this._pending=null,null===e?n.resolve(this):n.reject(e)}_hasSupportedExtension(t){return/\.(json|geojson|topojson|zip|shp|kml|msx)$/i.test(t)}_filenameFromContentType(t,e){return(e||"data")+({"application/json":".json","application/geo+json":".geojson","application/vnd.geo+json":".geojson","application/topojson+json":".topojson","application/zip":".zip","application/x-zip-compressed":".zip","application/octet-stream":".zip","application/vnd.google-earth.kml+xml":".kml","text/plain":".json"}[t.toLowerCase().split(";")[0].trim()]||".json")}getDataset(){return this._dataset}getCRS(){return An(this._dataset)}async reproject(t){if(!this._dataset)return;this._dataset?.arcs?.setRetainedInterval&&this._dataset.arcs.setRetainedInterval(0),this._dataset.info&&(delete this._dataset.info.crs_string,delete this._dataset.info.prj,delete this._dataset.info.wkt1);const e=`-proj ${t}`,n=await Y().runOnDataset(e,this._dataset);this._dataset=n,this._dataset?.arcs&&(this._displayArcs=new wn(this._dataset.arcs))}getExtent(){if(!this._dataset)return new V;const t=Y().getDatasetBounds(this._dataset);return new V(t.xmin,t.ymin,t.xmax,t.ymax)}getArcs(){return this._dataset?.arcs}getDisplayArcs(){return this._displayArcs}markDisplayArcsDirty(){this._displayArcs?.markDirty()}refreshDisplayArcs(){this._dataset?.arcs&&(this._displayArcs=new wn(this._dataset.arcs))}setDataset(t){this._dataset=t,t.arcs?this._displayArcs=new wn(t.arcs):this._displayArcs=null,this._simplifyFloor=t.arcs?.getRetainedInterval?.()??0,this.fire("data",{reason:"replace"})}async export(t){if(!this._dataset)throw new Error("TopologySource has no dataset to export");const e=this._dataset.arcs,n=e?.getRetainedInterval?.()??0;n&&e?.setRetainedInterval&&e.setRetainedInterval(0);try{const e=Y(),n="msx"===t.format?await e.exportPackedDatasets([this._dataset],{compact:!0}):e.exportFileContent(this._dataset,{format:t.format});return this._filesToBlob(n,t.format)}finally{n&&e?.setRetainedInterval&&e.setRetainedInterval(n)}}_filesToBlob(t,e){if(0===t.length)throw new Error(`mapshaper produced no output for format=${e}`);if("shapefile"===e){const e={};for(const n of t)e[n.filename]=Dn(n.content);const n=yn(e);return new Blob([n],{type:kn.shapefile})}return new Blob([t[0].content],{type:kn[e]})}getLayers(){return this._dataset?.layers||[]}_isZipFile(t){return/\.zip$/i.test(t)}async _extractZip(t){const e={...In,...this._options.zipLimits};let n=0,i=0;const s=await new Promise((s,r)=>{vn(t,{filter:s=>{if(i++,i>e.maxEntries)throw new Error(`ZIP extraction limit exceeded: ${i} entries > maxEntries ${e.maxEntries}`);if(n+=s.originalSize,n>e.maxBytes)throw new Error(`ZIP extraction limit exceeded: uncompressed total ${n} > maxBytes ${e.maxBytes}`);if(t.byteLength>0){const i=n/t.byteLength;if(i>e.maxRatio)throw new Error(`ZIP extraction limit exceeded: ratio ${i.toFixed(1)} > maxRatio ${e.maxRatio}`)}return!(/^__MACOSX/.test(s.name)||s.name.split("/").pop()?.startsWith("."))}},(t,e)=>{t?r(t):s(e)})}),r={};for(const t of Object.keys(s)){const e=s[t],n=t.split("/").pop()||t;this._isTextFile(n)?r[n]=dn(e):r[n]=e}return r}_isTextFile(t){return/\.(prj|cpg|csv|json|geojson|kml|txt)$/i.test(t)}_findPrimaryFile(t){const e=Object.keys(t),n=[".shp",".geojson",".json",".kml",".topojson"];for(const t of n){const n=e.find(e=>e.toLowerCase().endsWith(t));if(n)return n}return e.find(t=>!this._isAuxiliaryFile(t))||""}_isAuxiliaryFile(t){return/\.(prj|shx|dbf)$/i.test(t)}}function Tn(t){const e=[];return function(n){e.push(n),e.length>t&&e.shift();return e.reduce((t,e)=>t+e,0)/e.length}}class Ln extends j{_element;_active=!1;_timer=new H;_sustainInterval=150;_fadeDelay=70;_eventTime=0;_getAverageRate=Tn(10);_getWheelDirection=function(){let t=0,e=null;return function(n,i){const s=n>0?1:n<0?-1:0;(!e||i-t>300)&&(e=Tn(3)),t=i;const r=e(s)||s;return r>0?1:r<0?-1:0}}();_wheelDirection=0;_mouseX=0;_mouseY=0;_wheelHandler=t=>this._handleWheel(t);constructor(t){super(),this._element=t,this._timer.on("tick",t=>this._onTick(t)),this._element.addEventListener("wheel",this._wheelHandler,{passive:!1})}destroy(){this._element.removeEventListener("wheel",this._wheelHandler),this._timer.stop()}_updateSustainInterval(t){this._fadeDelay=t+50,this._sustainInterval=this._fadeDelay+80}_handleWheel(t){const e=Date.now();if(this._wheelDirection=this._getWheelDirection(-t.deltaY,e),0===this._wheelDirection)return;t.preventDefault();const n=this._element.getBoundingClientRect();this._mouseX=t.clientX-n.left,this._mouseY=t.clientY-n.top,this._active?this._updateSustainInterval(this._getAverageRate(e-this._eventTime)):(this._active=!0,this.fire("mousewheelstart")),this._eventTime=e,this._timer.start(this._sustainInterval)}_onTick(t){const e=t.time-this._eventTime;let n=t.tickTime/25,i=0;e>this._fadeDelay&&(i=Math.min(1,(e-this._fadeDelay)/(this._sustainInterval-this._fadeDelay))),t.done?(this._active=!1,this.fire("mousewheelend")):(i>0&&(n*=W.quadraticOut(1-i)),this.fire("mousewheel",{direction:this._wheelDirection,multiplier:n,x:this._mouseX,y:this._mouseY}))}}class Nn extends j{_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],n=t.clientY-this._lastMousePos[1];this._lastMousePos=[t.clientX,t.clientY],this.fire("pan",{dx:e,dy:n})}_onMouseUp(){this._isDragging&&(this._isDragging=!1,this.fire("panend"))}}class Rn{_workerUrl;_WorkerCtor;_slots;_pending=new Map;_nextId=1;_rrCursor=0;_destroyed=!1;constructor(t){this._workerUrl=t.workerUrl,this._WorkerCtor=t.WorkerCtor??globalThis.Worker;const e=Math.max(1,Math.floor(t.poolSize??1));this._slots=Array.from({length:e},()=>({worker:null,epoch:0,pendingCount:0}))}run(t,e,n){return this.runWithId(t,e,n).promise}runWithId(t,e,n){const i=this.reserveId();return{id:i,promise:this.dispatchWithId(i,t,e,n)}}reserveId(){return this._nextId++}dispatchWithId(t,e,n,i,s){if(this._destroyed)return Promise.reject(new Error("MapshaperWorkerPool: destroyed"));const r=this._pickWorker();let o;try{o=this._ensureWorker(r)}catch(t){return Promise.reject(t)}const a=this._slots[r],h=a.epoch;return a.pendingCount++,new Promise((a,l)=>{this._pending.set(t,{resolve:a,reject:l,workerIndex:r,epoch:h});const c={id:t,type:"run",packed:n};"string"==typeof e?c.cmd=e:c.commands=e,i&&(c.inputFiles=i),s&&s.length>0?o.postMessage(c,s):o.postMessage(c)})}destroy(){this._destroyed||(this._destroyed=!0,this._terminateAll(new Error("MapshaperWorkerPool: destroyed")))}cancelAll(){this._destroyed||this._terminateAll(new Error("MapshaperWorkerPool: cancelled"))}isWorkerSpawned(){return this._slots.some(t=>null!==t.worker)}get poolSize(){return this._slots.length}_pickWorker(){let t=0,e=1/0,n=!1;const i=this._slots.length;for(let s=0;s<i;s++){const r=(this._rrCursor+s)%i,o=this._slots[r],a=null!==o.worker;(o.pendingCount<e||o.pendingCount===e&&a&&!n)&&(t=r,e=o.pendingCount,n=a)}return this._rrCursor=(t+1)%i,t}_terminateAll(t){for(const t of this._slots)t.worker&&(t.worker.terminate(),t.worker=null),t.epoch++,t.pendingCount=0;for(const{reject:e}of this._pending.values())e(t);this._pending.clear()}_ensureWorker(t){const e=this._slots[t];if(e.worker)return e.worker;if(!this._WorkerCtor)throw new Error("MapshaperWorkerPool: Worker constructor not available in this environment");const n=new this._WorkerCtor(this._workerUrl);return n.onmessage=e=>this._onMessage(t,e.data),n.onerror=e=>this._onWorkerError(t,e),e.worker=n,n}_onMessage(t,e){if(!e||"number"!=typeof e.id)return;const n=this._pending.get(e.id);if(!n)return;const i=this._slots[t];n.workerIndex===t&&n.epoch===i.epoch&&(this._pending.delete(e.id),i.pendingCount=Math.max(0,i.pendingCount-1),"ok"===e.type?n.resolve(e.packed):n.reject(new Error(e.message||"mapshaper worker error")))}_onWorkerError(t,e){const n=new Error(`mapshaper worker error: ${e.message||"unknown"}`),i=this._slots[t];i.worker&&(i.worker.terminate(),i.worker=null),i.epoch++,i.pendingCount=0;const s=[];for(const[e,n]of this._pending)n.workerIndex===t&&s.push(e);for(const t of s){const e=this._pending.get(t);this._pending.delete(t),e?.reject(n)}}}class Fn{_sources;_getTransform;_getSize;_getInitialMX;_indexCache=new globalThis.Map;constructor(t,e,n,i){this._sources=t,this._getTransform=e,this._getSize=n,this._getInitialMX=i}prebuild(t){if(void 0!==t){const e=this._sources.get(t);return void(e&&this._prebuildSource(t,e))}for(const[t,e]of this._sources)this._prebuildSource(t,e)}clear(t){if(void 0===t)return void this._indexCache.clear();const e=`${t}|`,n=[];for(const t of this._indexCache.keys())t.startsWith(e)&&n.push(t);for(const t of n)this._indexCache.delete(t)}_prebuildSource(t,e){if("topology"!==e.type)return;const n=e.getLayers(),i=e.getArcs(),s=e.getDataset?.();for(let e=0;e<n.length;e++)this._getOrBuildIndex(t,e,n[e],i,s)}_getOrBuildIndex(t,e,n,i,s){const r=n?.shapes;if(!r||0===r.length)return null;const o=i?.size?.()??0,a=s?.editVersion??0,h=`${t}|${e}|${r.length}|${o}|${a}`,l=this._indexCache.get(h);if(void 0!==l)return l;const c=`${t}|${e}|`,u=[];for(const t of this._indexCache.keys())t!==h&&t.startsWith(c)&&u.push(t);for(const t of u)this._indexCache.delete(t);const p="point"===n.geometry_type,d=new M(r.length),_=[];for(let t=0;t<r.length;t++){const e=r[t];if(!e){d.add(0,0,0,0);continue}let n=1/0,s=1/0,o=-1/0,a=-1/0;if(p)for(const t of it(e))!t||t.length<2||(t[0]<n&&(n=t[0]),t[0]>o&&(o=t[0]),t[1]<s&&(s=t[1]),t[1]>a&&(a=t[1]));else if(i?.getSimpleShapeBbox){const t=e;for(let e=0;e<t.length;e++)i.getSimpleShapeBbox(t[e],_),_[0]<n&&(n=_[0]),_[1]<s&&(s=_[1]),_[2]>o&&(o=_[2]),_[3]>a&&(a=_[3])}n!==1/0?d.add(n,s,o,a):d.add(0,0,0,0)}d.finish();const f={index:d,shapeCount:r.length};return this._indexCache.set(h,f),f}query(t,e,n){const{width:i,height:s}=this._getSize(),r=Array.isArray(t),o=r?t:[[0,0],[i,s]],a=e||(r?{}:t)||{};if(Array.isArray(o)&&"number"==typeof o[0]){const t=o;return this._queryFeaturesAtPoint(t,a,n)}const h=o;return this._queryFeaturesInBBox(h,a,n)}_layerMatchesFilter(t,e,n){if(!n||0===n.length)return!0;const i=nt(t,e);return!!n.includes(i)||(!(!t?.name||!n.includes(t.name))||!(!t?.id||!n.includes(t.id)))}_unproject(t,e){return this._getTransform().unproject(t,e)}_getHitBuffer(t){return t/Math.abs(this._getTransform().mx||1)}_getZoomAdjustedHitBuffer(t,e){const n=this._getTransform(),i=this._getInitialMX(),s=Math.abs(n.mx)/(i||Math.abs(n.mx)||1);return s<1&&(t*=s),e>0&&t<e&&(t=e),this._getHitBuffer(t)}_findHitCandidates(t,e,n,i,s,r,o,a){const h=[],l={},c=[],u=n.shapes;if(!u)return h;const p=this._getOrBuildIndex(t,e,n,i,a),d=p?p.index.search(s-o,r-o,s+o,r+o):null,_=null!==d?d.length:u.length;for(let t=0;t<_;t++){const e=null!==d?d[t]:t,n=u[e];if(n)for(let t=0;t<n.length;t++){const a=n[t];if(i.getSimpleShapeBbox(a,c),s+o<c[0]||s-o>c[2]||r+o<c[1]||r-o>c[3])continue;let u=l[e];u||(u=l[e]={shape:[],id:e,dist:0},h.push(u)),u.shape.push(a)}}return h}_sortByDistance(e,n,i,s){const r=t.geom;for(const t of i)t.info=r.getPointToShapeInfo(e,n,t.shape,s),t.dist=t.info.distance;i.sort((t,e)=>t.dist-e.dist)}_pickNearestCandidates(t,e,n){const i=[];let s=0;for(let r=0;r<t.length;r++){const o=t[r];if(!(o.dist<n))break;if(0===r)s=o.dist;else if(o.dist-s>e)break;i.push(o)}return i}_pointTest(e,n,i,s,r,o){const a=t.geom,h=Math.abs(this._getTransform().mx||1);let l=-1,c=1/0,u=25;const p=i.shapes;if(!p)return[];const d=u/(h||1),_=this._getOrBuildIndex(e,n,i,void 0,o),f=_?_.index.search(s-d,r-d,s+d,r+d):null,m=null!==f?f.length:p.length;for(let t=0;t<m;t++){const e=null!==f?f[t]:t,n=p[e];if(n)for(const t of it(n)){if(!t)continue;const n=a.distance2D(s,r,t[0],t[1])*h;n>u||(n<u&&u>2&&(u=Math.max(2,n)),n<c&&(c=n,l=e))}}return-1===l?[]:[l]}_polylineTest(t,e,n,i,s,r,o,a){const h=this._getZoomAdjustedHitBuffer(15,2),l=o>=0?o:.05,c=this._getZoomAdjustedHitBuffer(l,0);let u=this._findHitCandidates(t,e,n,i,s,r,h,a);return this._sortByDistance(s,r,u,i),u=this._pickNearestCandidates(u,c,h),u.length?[u[0].id]:[]}_polygonTest(e,n,i,s,r,o,a){const h=t.geom,l=this._getZoomAdjustedHitBuffer(10,1),c=this._findHitCandidates(e,n,i,s,r,o,l,a);let u=[];for(const t of c)h.testPointInPolygon(r,o,t.shape,s)&&u.push(t);return c.length>0&&0===u.length?(this._sortByDistance(r,o,c,s),u=this._pickNearestCandidates(c,0,l)):u.length>1&&this._sortByDistance(r,o,u,s),u.length?[u[0].id]:[]}_polygonVertexTest(t,e,n,i,s,r,o){const a=this._polygonTest(t,e,n,i,s,r,o),h=this._polylineTest(t,e,n,i,s,r,5,o);return a.length?a:h}_queryFeaturesAtPoint(t,e,n){const i=this._getTransform(),s=[],[r,o]=this._unproject(t[0],t[1]),a=1/Math.abs(i.mx||1);for(const[t,i]of this._sources){const h=i.getLayers(),l=i.getDisplayArcs(),c=l?l.getScaledArcs(a):i.getArcs(),u=i.getDataset?.();for(let i=0;i<h.length;i++){const a=h[i];if(!a?.shapes)continue;if(!this._layerMatchesFilter(a,i,e.layers))continue;const l=nt(a,i);if(n&&!n.has(`${t}:${l}`))continue;const p=a.geometry_type;let d=[];if("point"===p?d=this._pointTest(t,i,a,r,o,u):"polyline"===p&&c?d=this._polylineTest(t,i,a,c,r,o,-1,u):"polygon"===p&&c&&(d=this._polygonVertexTest(t,i,a,c,r,o,u)),0!==d.length)for(const e of d){const n=a.data,i=n?.getRecordAt?.(e)??n?.getRecords?.()?.[e]??{};s.push({id:e,source:t,layer:l,geometryType:p||"unknown",properties:{...i}})}}}return s}_queryFeaturesInBBox(t,e,n){const i=this._getTransform(),s=[],[r,o]=t,a=this._unproject(r[0],r[1]),h=this._unproject(o[0],o[1]),l=Math.min(a[0],h[0]),c=Math.min(a[1],h[1]),u=Math.max(a[0],h[0]),p=Math.max(a[1],h[1]),d=1/Math.abs(i.mx||1);for(const[t,i]of this._sources){const r=i.getLayers(),o=i.getDisplayArcs(),a=o?o.getScaledArcs(d):i.getArcs(),h=i.getDataset?.();for(let i=0;i<r.length;i++){const o=r[i];if(!o?.shapes)continue;if(!this._layerMatchesFilter(o,i,e.layers))continue;const d=nt(o,i);if(n&&!n.has(`${t}:${d}`))continue;const _=o.geometry_type,f=o.data,m=[],y=this._getOrBuildIndex(t,i,o,a,h),g=y?y.index.search(l,c,u,p):null,v=null!==g?g.length:o.shapes.length;for(let e=0;e<v;e++){const n=null!==g?g[e]:e,i=o.shapes[n];if(!i)continue;let r=!1;if("point"===_)r=it(i).some(t=>t[0]>=l&&t[0]<=u&&t[1]>=c&&t[1]<=p);else if(a){const t=i;for(let e=0;e<t.length;e++)if(a.getSimpleShapeBbox(t[e],m),!(u<m[0]||l>m[2]||p<m[1]||c>m[3])){r=!0;break}}if(!r)continue;const h=f?.getRecordAt?.(n)??f?.getRecords?.()?.[n]??{};s.push({id:n,source:t,layer:d,geometryType:_||"unknown",properties:{...h}})}}}return s}}class Gn{_host;constructor(t){this._host=t}get(t){const e=this._host.layers.resolve(t.source,t.layer);if(!e)return null;if(!Number.isInteger(t.id)||t.id<0)return null;const n=e.shapes??null;if(!n||t.id>=n.length)return null;const i=n[t.id],s=e.data?.getRecords?.()??[];return{ref:t,geometry:i,properties:Object.freeze({...s[t.id]??{}})}}*iter(t,e){const n=this._host.layers.resolve(t,e);if(!n||!n.shapes)return;const i=n.shapes,s=n.data?.getRecords?.()??[];for(let n=0;n<i.length;n++)yield{ref:{source:t,layer:e,id:n},geometry:i[n],properties:Object.freeze({...s[n]??{}})}}count(t,e){const n=this._host.layers.resolve(t,e);return n?.shapes?.length??0}}class On{_all=new globalThis.Set;get size(){return this._all.size}register(t){return this._all.add(t),()=>{this._all.delete(t)}}unregisterAll(){this._all.clear()}async runFor(t,e,n){if(0===this._all.size)return[];const i=[];for(const e of this._all)e.phase===t&&i.push(e);if(0===i.length)return[];const s=await Promise.allSettled(i.map(t=>t.run(e,n))),r=[];for(let t=0;t<i.length;t++){const e=i[t],n=s[t];let o;o="fulfilled"===n.status?n.value:{ok:!1,issues:[{severity:"error",message:`validator '${e.name}' threw: ${n.reason instanceof Error?n.reason.message:String(n.reason)}`}]},r.push({validator:e.name,report:o})}return r}}class Bn{_highlighted=new globalThis.Map;_highlightStyle={color:"#ff7a00",width:2.2,radius:6,fill:!0};get size(){return this._highlighted.size}setHighlightedFeatures(t,e){this._highlighted.clear(),e&&(this._highlightStyle={...this._highlightStyle,...e});for(const e of t){const t=this._highlighted.get(e.source)||new globalThis.Map,n=t.get(e.layer)||new Set;n.add(e.id),t.set(e.layer,n),this._highlighted.set(e.source,t)}}clearHighlightedFeatures(){return 0!==this._highlighted.size&&(this._highlighted.clear(),!0)}setHighlightStyle(t){return this._highlightStyle={...this._highlightStyle,...t},this._highlighted.size>0}renderHighlights(t,e,n,i,s){if(0===this._highlighted.size)return;const r=this._highlightStyle.color||"#ff7a00",o=(this._highlightStyle.width??2.2)*i,a=this._highlightStyle.radius??6,h=!1!==this._highlightStyle.fill,l=1/Math.abs(n.mx||1);for(const[n,i]of e){const e=this._highlighted.get(n);if(!e)continue;const c=i.getLayers(),u=i.getDisplayArcs(),p=u?u.getScaledArcs(l):i.getArcs();for(let i=0;i<c.length;i++){const l=c[i];if(!l?.shapes)continue;const u=nt(l,i);if(s&&!s.has(`${n}:${u}`))continue;const d=e.get(u);if(!d||0===d.size)continue;const _=[];for(const t of d){const e=l.shapes[t];e&&_.push(e)}0!==_.length&&("point"===l.geometry_type?t.drawPoints(_,{color:r,radius:a,fill:h}):p&&t.drawPaths(_,{color:r,width:o},p))}}}}class zn{_byKey=new globalThis.Map;_size=0;get size(){return this._size}has(t){return this._byKey.get(t.source)?.get(t.layer)?.has(t.id)??!1}getAll(){const t=[];for(const[e,n]of this._byKey)for(const[i,s]of n)for(const n of s)t.push({source:e,layer:i,id:n});return t}getByLayer(t,e){const n=this._byKey.get(t)?.get(e);return n?Array.from(n):[]}clear(){if(0===this._size)return{added:[],removed:[],changed:!1};const t=this.getAll();return this._byKey.clear(),this._size=0,{added:[],removed:t,changed:!0}}apply(t,e){const n=$n(t);if("replace"===e){const t=this._refSetSnapshot();this._byKey.clear(),this._size=0;for(const t of n)this._addOne(t);return jn(t,this._refSetSnapshot())}const i=[],s=[];if("add"===e)for(const t of n)this._addOne(t)&&i.push(t);else for(const t of n)this.has(t)?this._removeOne(t)&&s.push(t):this._addOne(t)&&i.push(t);return{added:i,removed:s,changed:i.length>0||s.length>0}}remove(t){const e=[];for(const n of $n(t))this._removeOne(n)&&e.push(n);return{added:[],removed:e,changed:e.length>0}}snapshot(){return this._refSetSnapshot()}restore(t){const e=this._refSetSnapshot();this._byKey.clear(),this._size=0;for(const e of t)this._addOne(qn(e));return jn(e,t)}_addOne(t){let e=this._byKey.get(t.source);e||(e=new globalThis.Map,this._byKey.set(t.source,e));let n=e.get(t.layer);return n||(n=new Set,e.set(t.layer,n)),!n.has(t.id)&&(n.add(t.id),this._size++,!0)}_removeOne(t){const e=this._byKey.get(t.source),n=e?.get(t.layer);return!!n?.has(t.id)&&(n.delete(t.id),this._size--,0===n.size&&(e.delete(t.layer),0===e.size&&this._byKey.delete(t.source)),!0)}_refSetSnapshot(){const t=new Set;for(const[e,n]of this._byKey)for(const[i,s]of n)for(const n of s)t.add(Un(e,i,n));return t}}function Un(t,e,n){return JSON.stringify([t,e,n])}function qn(t){const[e,n,i]=JSON.parse(t);return{source:e,layer:n,id:i}}function jn(t,e){const n=[],i=[];for(const i of e)t.has(i)||n.push(qn(i));for(const n of t)e.has(n)||i.push(qn(n));return{added:n,removed:i,changed:n.length>0||i.length>0}}function $n(t){const e=new Set,n=[];for(const i of t){const t=Un(i.source,i.layer,i.id);e.has(t)||(e.add(t),n.push(i))}return n}class Vn{_undoStack=[];_redoStack=[];_maxSize;_lastSkippedStale=!1;_captureBuffer=null;constructor(t={}){if(this._maxSize=t.maxSize??200,this._maxSize<1)throw new Error("EditHistory: maxSize must be >= 1")}push(t){if(this._captureBuffer)return void this._captureBuffer.push(t);const e=this._undoStack[this._undoStack.length-1];if(e&&!e.stale&&e.merge&&t.mergeable?.(e))return e.merge(t),void(this._redoStack.length=0);if(t.invalidatesPriorCommands){for(const t of this._undoStack)t.stale=!0;this._redoStack.length=0}this._undoStack.push(t),this._redoStack.length=0,this._undoStack.length>this._maxSize&&this._undoStack.shift()}beginCapture(){if(this._captureBuffer)throw new Error("EditHistory: nested capture not supported");this._captureBuffer=[]}endCapture(){const t=this._captureBuffer;return this._captureBuffer=null,t??[]}isCapturing(){return null!==this._captureBuffer}undo(){const t=this._undoStack.pop();return t?(t.stale?this._lastSkippedStale=!0:(t.undo(),this._lastSkippedStale=!1),this._redoStack.push(t),t):null}redo(){const t=this._redoStack.pop();return t?(t.stale?this._lastSkippedStale=!0:(t.do(),this._lastSkippedStale=!1),this._undoStack.push(t),t):null}clear(){this._undoStack.length=0,this._redoStack.length=0,this._lastSkippedStale=!1}canUndo(){return this._undoStack.length>0}canRedo(){return this._redoStack.length>0}size(){return this._undoStack.length}snapshot(){const t=this._undoStack[this._undoStack.length-1];let e=0;for(const t of this._undoStack)t.stale&&e++;const n={canUndo:this._undoStack.length>0,canRedo:this._redoStack.length>0,label:t?.label,staleCount:e,topIsStale:!!t?.stale};return this._lastSkippedStale&&(n.skippedStale=!0),n}}class Hn{_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 n=new Lt(e,t);return this._host._history.push(n),this._host._fireHistoryChange(),at}rollback(){this._end(),this._host._history.endCapture();for(const[t,e]of this._datasetSnapshots){const n=this._host._sources.get(t);n&&n.setDataset(e)}const t=this._host._selection.restore(this._selectionSnapshot);t.changed&&this._host._fireSelectionChange(t),this._host._fireHistoryChange(),this._host._scheduleRender()}_end(){if(this._closed)throw new Error("Transaction: already committed or rolled back");this._closed=!0,this._host._activeTransaction=null}}class Wn{opts;label="Delete feature";constructor(t){this.opts=t}do(){const{layer:t,featureId:e}=this.opts;if(!t.shapes)return;t.shapes.splice(e,1);const n=t.data?.getRecords?.();n?.splice(e,1)}undo(){const{layer:t,featureId:e,shape:n,record:i}=this.opts;if(t.shapes||(t.shapes=[]),t.shapes.splice(e,0,n),null!==i){const n=t.data?.getRecords?.();n?.splice(e,0,i)}}}class Kn{opts;label;constructor(t){this.opts=t,this.label=`Delete ${t.snapshots.length} feature${1===t.snapshots.length?"":"s"}`}do(){const{layer:t,snapshots:e}=this.opts;if(!t.shapes||0===e.length)return;const n=new Set;for(const t of e)n.add(t.id);const i=t.shapes,s=new Array(i.length-n.size);let r=0;for(let t=0;t<i.length;t++)n.has(t)||(s[r++]=i[t]);t.shapes=s;const o=t.data?.getRecords?.();if(o){let t=0;for(let e=0;e<o.length;e++)n.has(e)||(o[t++]=o[e]);o.length=t}}undo(){const{layer:t,snapshots:e}=this.opts;t.shapes||(t.shapes=[]);const n=[...e].sort((t,e)=>t.id-e.id),i=t.data?.getRecords?.();for(const e of n)t.shapes.splice(e.id,0,e.shape),i&&null!==e.record&&i.splice(e.id,0,e.record)}}function Xn(t,e){const n=t||{};return{color:n["line-color"]||n["fill-color"]||"#333",width:(n["line-width"]??.8)*e}}function Zn(t){const e=t||{};return{color:e["circle-color"]||"#333",radius:e["circle-radius"]??4,fill:!1!==e["circle-fill"]}}class Jn extends j{_container;_canvasContainer;_canvas;_painter;_editOverlay;_viewport=new X;_projection=new et;_sources=new globalThis.Map;_layersCache;get layers(){return this._layersCache??(this._layersCache=new Ct(this._sources))}_sourceListeners=new globalThis.Map;_layers=[];_effectiveLayersCache=[];_defaultLayersDirty=!0;_layerArcFlagsCache=new globalThis.Map;_mouseWheel;_dragPan;_pendingRender=0;_rafId=0;_controlContainers=new globalThis.Map;_controls=[];_highlightManager=new Bn;_featureQuery;features;_selection=new zn;_history=new Vn;_activeTransaction=null;_validators=new On;get validators(){return this._validators}_historyShortcutUnbind=null;_ops;_editSession;_attributes;get ops(){return this._ops??(this._ops=new Tt(this))}get editSession(){return this._editSession??(this._editSession=new Kt(this))}get attributes(){return this._attributes??(this._attributes=new ee(this))}_editState=new ne(t=>{t.modeChanged&&(this._dragPan?.setEnabled("none"===t.current.mode),this.fire("editmodechange",{mode:t.current.mode})),this._scheduleRender()});_workerPool=null;_workerMode=!1;_workerThreshold=5e4;_workerRouting;_expressionPolicy="disabled";constructor(t){if(super(),"string"==typeof t.container){const e=document.getElementById(t.container);if(!e)throw new Error(`Container #${t.container} not found`);this._container=e}else this._container=t.container;this._canvasContainer=this._createCanvasContainer(),this._container.appendChild(this._canvasContainer),this._canvas=document.createElement("canvas"),this._canvas.style.position="absolute",this._canvas.style.top="0",this._canvas.style.left="0",this._canvasContainer.appendChild(this._canvas),this._painter=new st(this._canvas),this._painter.setPixelRatio(window.devicePixelRatio||1),this._editOverlay=new rt(this._painter),this._updateSize(),this._viewport.onViewChange=()=>this.fire("move"),this._viewport.initZoomTween(),this._mouseWheel=new Ln(this._canvasContainer),this._dragPan=new Nn(this._canvasContainer),this._featureQuery=new Fn(this._sources,()=>this._viewport.transform,()=>({width:this._viewport.width,height:this._viewport.height}),()=>this._viewport.initialMX),this.features=new Gn(this),this._attachEventListeners(),this.on("move",()=>this._scheduleRender()),this.on("resize",()=>this._scheduleRender()),this.on("reset",()=>this.reset()),this.on("historychange",()=>this._runAfterCommitValidators()),this._expressionPolicy=t.expressionPolicy??"disabled",this._workerMode=t.useWorker??t.workerMode??!1,"number"==typeof t.workerThreshold&&t.workerThreshold>=0&&(this._workerThreshold=t.workerThreshold),this._workerRouting=t.workerRouting,(!1!==this._workerMode||t.workerPool)&&(t.workerPool?this._workerPool=t.workerPool:this._workerPool=new Rn({workerUrl:t.workerUrl??"emap-worker.js",poolSize:t.workerPoolSize}))}cancelWorkerJobs(){this._workerPool?.cancelAll()}setExpressionPolicy(t){this._expressionPolicy=t}getExpressionPolicy(){return this._expressionPolicy??"disabled"}_allowExpressionEvaluation(t,e){return!t.some(t=>"string"==typeof t&&t.trim().length>0)||"trusted"===this.getExpressionPolicy()||(this.fire("error",{error:new Error(`${e}: expression evaluation is disabled`)}),!1)}getCanvasContainer(){return this._canvasContainer}getEditMode(){return this._editState.mode}setEditMode(t){this._editState.setMode(t)}setEditVertexState(t){this._editState.setVertex(t)}clearEditVertexState(){this._editState.clearVertex()}setEditDrawState(t){this._editState.setDraw(t)}clearEditDrawState(){this._editState.clearDraw()}_attachEventListeners(){this._dragPan.on("pan",t=>{this._viewport.pan(t.dx,t.dy),this.fire("move")}),this._dragPan.on("panstart",()=>{this._viewport.cancelZoomAnimation()}),this._mouseWheel.on("mousewheel",t=>{this._viewport.applyWheelZoom(t.direction,t.multiplier,t.x,t.y),this.fire("move")})}_createCanvasContainer(){const t=document.createElement("div");t.style.position="relative",t.style.width="100%",t.style.height="100%",t.style.overflow="hidden",t.className="emap-canvas-container";const e=["top-left","top-right","bottom-left","bottom-right"];for(const n of e){const e=document.createElement("div");e.className=`emap-ctrl-${n}`,e.style.position="absolute",e.style.pointerEvents="none",e.style.zIndex="10";const[i,s]=n.split("-");e.style[i]="10px",e.style[s]="10px",e.style.display="flex",e.style.flexDirection="column",e.style.gap="8px";const r=t=>t.stopPropagation();for(const t of["click","mousedown","mouseup","dblclick","contextmenu"])e.addEventListener(t,r);e.addEventListener("wheel",r,{passive:!0}),t.appendChild(e),this._controlContainers.set(n,e)}return t}_updateSize(){const t=this._container.clientWidth,e=this._container.clientHeight;this._viewport.updateSize(t,e),this._painter.resize(t,e)}addSource(t,e){this._sources.set(t,e);const n=n=>{if(1===this._sources.size&&e.getCRS){const t=e.getCRS();t&&this._projection.crs!==t&&(this._projection.setCRS(t),this._viewport.setCRS(t),this.fire("crschange"))}this.fire("data",{sourceId:t,...n}),this._defaultLayersDirty=!0,this._layerArcFlagsCache.clear(),this._scheduleRender()};this._sourceListeners.set(t,n),e.on("data",n),e.getDataset&&e.getDataset()&&n({type:"data"})}removeSource(t){const e=this._sources.get(t);if(e){const n=this._sourceListeners.get(t);n&&(e.off("data",n),this._sourceListeners.delete(t)),this._sources.delete(t),this._defaultLayersDirty=!0,this._layerArcFlagsCache.delete(t);for(const e of this._layerArcFlagsCache.keys())e.startsWith(`${t}:`)&&this._layerArcFlagsCache.delete(e);this._scheduleRender()}}getSource(t){return this._sources.get(t)}async exportSnapshot(t={}){const e=!1!==t.compact,n=[],i=[];for(const[t,e]of this._sources){if("topology"!==e.type)continue;const s=e.getDataset?.();s&&(n.push(t),i.push(s))}const s=Y(),r=await s.exportDatasetsToPack(i,{compact:e});r.emap={version:1,sources:n.map(t=>({id:t}))};const o=s.pack(r);return new Blob([o],{type:"application/octet-stream"})}async loadSnapshot(t,e={}){const n=!1!==e.replace,i=e.idPrefix??"",s=e.defaultIds??[];let r;if(t instanceof Uint8Array)r=t;else if(t instanceof ArrayBuffer)r=new Uint8Array(t);else{if(!("undefined"!=typeof Blob&&t instanceof Blob))throw new Error("loadSnapshot: input must be Blob, Uint8Array, or ArrayBuffer");r=new Uint8Array(await t.arrayBuffer())}if(!function(t){if(!t||0===t.length)return!1;const e=t[0];return e>=128&&e<=143||222===e||223===e}(r))throw new Error("loadSnapshot: input does not look like a mapshaper .msx snapshot (expected msgpack map marker as the first byte)");const o=await Y().unpackSessionData(r),a=o.datasets??[],h=o.emap,l=h?.sources?.map(t=>t?.id).filter(t=>"string"==typeof t)??[],c=a.map((t,e)=>{const n=l[e],r=s[e]??`snapshot-${e}`;return i+(n??r)});if(!n)for(const t of c)if(this._sources.has(t))throw new Error(`loadSnapshot: source "${t}" already exists (pass { replace: true } to overwrite)`);this._history.clear(),this._fireSelectionChange(this._selection.clear()),this.fire("historychange");const u=[];for(let t=0;t<a.length;t++){const e=c[t];n&&this._sources.has(e)&&this.removeSource(e);const i=new Pn(e);i.setDataset(a[t]),this.addSource(e,i),u.push(e)}return u}addLayer(t,e){if(!this._sources.has(t.source))throw new Error(`Source "${t.source}" not found`);if(this._layers.some(e=>e.id===t.id))throw new Error(`Layer "${t.id}" already exists`);if(e){const n=this._layers.findIndex(t=>t.id===e);if(-1===n)throw new Error(`Layer "${e}" not found`);this._layers.splice(n,0,{...t})}else this._layers.push({...t});this._defaultLayersDirty=!0,this._scheduleRender()}removeLayer(t){const e=this._layers.findIndex(e=>e.id===t);-1!==e&&(this._layers.splice(e,1),this._defaultLayersDirty=!0,this._scheduleRender())}getLayer(t){return this._layers.find(e=>e.id===t)}getLayers(){return[...this._layers]}setLayerVisibility(t,e){const n=this._layers.find(e=>e.id===t);n&&(n.layout||(n.layout={}),n.layout.visibility=e,this._scheduleRender())}setPaintProperty(t,e,n){const i=this._layers.find(e=>e.id===t);i&&(i.paint||(i.paint={}),i.paint[e]=n,this._scheduleRender())}moveLayer(t,e){const n=this._layers.findIndex(e=>e.id===t);if(-1===n)return;const[i]=this._layers.splice(n,1);if(e){const t=this._layers.findIndex(t=>t.id===e);-1===t?this._layers.push(i):this._layers.splice(t,0,i)}else this._layers.push(i);this._defaultLayersDirty=!0,this._scheduleRender()}_getEffectiveLayers(){if(this._layers.length>0)return this._layers;if(!this._defaultLayersDirty)return this._effectiveLayersCache;const t=[];for(const[e,n]of this._sources){const i=n.getLayers();if(0===i.length)t.push({id:`${e}:default`,type:"line",source:e,paint:{"line-color":"#333","line-width":.8}});else for(let n=0;n<i.length;n++){const s=i[n],r=nt(s,n),o=s.geometry_type;t.push({id:`${e}:${r}`,type:"point"===o?"circle":"line",source:e,"source-layer":r,paint:"point"===o?{"circle-color":"#333","circle-radius":4}:{"line-color":"#333","line-width":.8}})}}return this._effectiveLayersCache=t,this._defaultLayersDirty=!1,t}_resolveSourceLayer(t,e){const n=t.getLayers();if(!n.length)return null;if(!e)return n[0];for(let t=0;t<n.length;t++){if(nt(n[t],t)===e)return n[t]}return null}_getLayerArcFlags(t,e,n){if(!t||!t.shapes||!e)return null;let i=this._layerArcFlagsCache.get(n);if(i)return i;const s=e.size();i=new Uint8Array(s);const r=t.shapes;for(const t of r)if(t)for(const e of t)for(const t of e){i[t>=0?t:~t]=1}return this._layerArcFlagsCache.set(n,i),i}_getVisibleLayerKeys(){const t=new Set,e=this._getEffectiveLayers();for(const n of e){if("none"===n.layout?.visibility)continue;const e=this._sources.get(n.source);if(!e)continue;const i=this._resolveSourceLayer(e,n["source-layer"]);if(i){const s=e.getLayers().indexOf(i),r=nt(i,s>=0?s:0);t.add(`${n.source}:${r}`)}}return t}getPainter(){return this._painter}getCRS(){return this._projection.crs}setCRS(t){this._projection.setCRS(t),this._viewport.setCRS(t),this.fire("crschange")}async reproject(t){if(this._projection.crs===t)return;const e=await this._projection.reproject(t,this._sources);this._viewport.setCRS(t),this._viewport.clearInitialState(),e.hasBounds()&&this.setExtent(e),this.fire("crschange"),this.fire("data",{reason:"reproject"})}getCenter(){const t=this._viewport.transform,e=(this._viewport.width/2-t.bx)/t.mx,n=(this._viewport.height/2-t.by)/t.my;return this._projection.getCenter(e,n)}getZoom(){return this._projection.getZoom(Math.abs(this._viewport.transform.mx))}getTransform(){return this._viewport.transform}getExtent(){return this._viewport.extent}setExtent(t){this._viewport.setExtent(t),this.fire("move")}reset(){this._viewport.reset()}addControl(t,e="top-left"){const n=t.onAdd(this);n.style.pointerEvents="auto",this._controlContainers.get(e)?.appendChild(n),this._controls.push(t)}removeControl(t){t.onRemove(this);const e=this._controls.indexOf(t);-1!==e&&this._controls.splice(e,1)}zoomIn(){this._viewport.zoomIn()}zoomOut(){this._viewport.zoomOut()}_scheduleRender(){this._removed||(this._pendingRender++,0===this._rafId&&(this._rafId=requestAnimationFrame(()=>this._doRender())))}_doRender(){this._rafId=0,this._pendingRender>0&&(this._pendingRender=0,this.render())}render(){const t=this._viewport.transform;this._painter.setTransform(t),this._painter.clear();const e=this._viewport.getLineScale(),n=1/Math.abs(t.mx);this._renderLayers(n,e),this._renderHighlight(t,e),this._editOverlay.render(this._editState.mode,this._editState.vertex,this._editState.draw)}_renderLayers(t,e){const n=this._getEffectiveLayers();for(const i of n){if("none"===i.layout?.visibility)continue;const n=this._sources.get(i.source);if(!n)continue;const s=n.getDisplayArcs(),r=s?s.getScaledArcs(t):n.getArcs();if(r&&r.setRetainedInterval&&("function"!=typeof r.isFlat||!r.isFlat())){const e=n.getSimplifyFloor?.()??0;r.setRetainedInterval(Math.max(e,.5*t))}const o=this._resolveSourceLayer(n,i["source-layer"]),a=`${i.source}:${i["source-layer"]||"default"}`;if("line"===i.type&&r)this._renderLineLayer(i,o,r,a,e);else if("fill"===i.type&&r&&o?.shapes)this._renderFillLayer(i,o,r,a,e);else if("circle"===i.type&&o?.shapes){const t=Zn(i.paint);this._painter.drawPoints(o.shapes,t)}}}_renderLineLayer(t,e,n,i,s){const r=Xn(t.paint,s);if(e?.shapes){const t=this._getLayerArcFlags(e,n,i),s=this._combineArcFilters(t,this._viewport.getArcFilter(n));this._painter.drawArcs(n,r,s)}else this._painter.drawArcs(n,r,this._viewport.getArcFilter(n))}_renderFillLayer(t,e,n,i,s){const r=t.paint,o=r?.["fill-color"]||"rgba(200, 200, 200, 0.4)",a=r?.["fill-opacity"],h=this._viewport.getArcFilter(n);this._painter.drawPolygonFill(e.shapes,n,o,h,a);const l=Xn(t.paint,s),c=this._getLayerArcFlags(e,n,i);this._painter.drawArcs(n,l,this._combineArcFilters(c,h))}_combineArcFilters(t,e){return t&&e?n=>1===t[n]&&e(n):t?e=>1===t[e]:e}_renderHighlight(t,e){const n=this._getVisibleLayerKeys();this._highlightManager.renderHighlights(this._painter,this._sources,t,e,n)}project(t,e){return this._viewport.project(t,e)}unproject(t,e){return this._viewport.unproject(t,e)}resize(){this._updateSize(),this._viewport.setExtent(this._viewport.extent),this.fire("resize")}queryFeatures(t,e){const n=this._getVisibleLayerKeys();return this._featureQuery.query(t,e,n)}prebuildSpatialIndex(t){this._featureQuery.prebuild(t)}clearSpatialIndex(t){this._featureQuery.clear(t)}_clearSpatialIndexesForSources(t){for(const e of t)this._featureQuery?.clear(e)}setHighlightedFeatures(t,e){this._highlightManager.setHighlightedFeatures(t,e),this._scheduleRender()}clearHighlightedFeatures(){this._highlightManager.clearHighlightedFeatures()&&this._scheduleRender()}setHighlightStyle(t){this._highlightManager.setHighlightStyle(t)&&this._scheduleRender()}select(t,e){const n=e?.mode??"replace",i=this._selection.apply(t,n);this._fireSelectionChange(i)}deselect(t){const e=this._selection.remove(t);this._fireSelectionChange(e)}clearSelection(){const t=this._selection.clear();this._fireSelectionChange(t)}getSelection(){return this._selection.getAll()}isSelected(t){return this._selection.has(t)}_fireSelectionChange(t){t.changed&&this.fire("selectionchange",{selected:this._selection.getAll(),added:t.added,removed:t.removed})}deleteSelected(){const t=this._selection.getAll();if(0===t.length)return!1;const e=new globalThis.Map;for(const n of t){let t=e.get(n.source);t||(t=new globalThis.Map,e.set(n.source,t));const i=t.get(n.layer)??[];i.push(n.id),t.set(n.layer,i)}const n=[];let i=0;for(const[t,s]of e){const e=this._sources.get(t);if(!e)continue;const r=e.getLayers();for(const[t,e]of s){let s=null;for(let e=0;e<r.length;e++)if(nt(r[e],e)===t){s=r[e];break}if(!s?.shapes)continue;const o=s.data?.getRecords?.(),a=[],h=new Set;for(const t of e){if(h.has(t))continue;h.add(t);const e=s.shapes[t];if(void 0===e)continue;const n=o?o[t]:null;a.push({id:t,shape:e,record:n??null})}if(0===a.length)continue;const l=new Kn({layer:s,snapshots:a});l.do(),n.push(l),i+=a.length}}if(0===n.length)return!1;const s=new Lt(n,`Delete ${i} feature${i>1?"s":""}`);return this._history.push(s),this._fireHistoryChange(),this._invalidateShapeCachesForSources(e.keys()),this._fireSelectionChange(this._selection.clear()),this._scheduleRender(),!0}_invalidateShapeCachesForSources(t){for(const e of t){const t=`${e}:`;for(const e of this._layerArcFlagsCache.keys())e.startsWith(t)&&this._layerArcFlagsCache.delete(e);this._featureQuery?.clear(e)}}pushCommand(t){this._history.push(t),this._fireHistoryChange()}undo(){return!!this._history.undo()&&(this._fireHistoryChange(),this._invalidateAllShapeCaches(),this._scheduleRender(),!0)}redo(){return!!this._history.redo()&&(this._fireHistoryChange(),this._invalidateAllShapeCaches(),this._scheduleRender(),!0)}_invalidateAllShapeCaches(){this._layerArcFlagsCache.clear();for(const t of this._sources.keys())this._featureQuery?.clear(t)}canUndo(){return this._history.canUndo()}canRedo(){return this._history.canRedo()}clearHistory(){const t=this._history.canUndo()||this._history.canRedo();this._history.clear(),t&&this._fireHistoryChange()}beginTransaction(){return new Hn(this)}bindHistoryShortcuts(t){this._historyShortcutUnbind?.();const e=t??this._canvasContainer;e.hasAttribute("tabindex")||e.setAttribute("tabindex","-1");const n=t=>{if(!(t.ctrlKey||t.metaKey))return;const e="z"===t.key||"Z"===t.key,n="y"===t.key||"Y"===t.key;e&&!t.shiftKey?(t.preventDefault(),this.undo()):(e&&t.shiftKey||n)&&(t.preventDefault(),this.redo())};e.addEventListener("keydown",n);const i=()=>{e.removeEventListener("keydown",n),this._historyShortcutUnbind===i&&(this._historyShortcutUnbind=null)};return this._historyShortcutUnbind=i,i}_fireHistoryChange(){const t=this._history.snapshot();this.fire("historychange",t)}_runAfterCommitValidators(){if(0===this._validators.size)return;const t={label:this._history.snapshot().label??""};this._validators.runFor("after-commit",this,t).then(e=>{if(this._removed)return;const n=e.filter(t=>!t.report.ok);n.length>0&&this.fire("validationfailed",{results:n,label:t.label})})}_resolveLayer(t,e){return this.layers.resolve(t,e)}remove(){if(this._removed)return;this._removed=!0,0!==this._rafId&&(cancelAnimationFrame(this._rafId),this._rafId=0),this._pendingRender=0,this._dragPan.destroy(),this._mouseWheel.destroy(),this._historyShortcutUnbind?.(),this._historyShortcutUnbind=null,this._workerPool&&(this._workerPool.cancelAll(),this._workerPool.destroy(),this._workerPool=null);for(const[t,e]of this._sourceListeners){const n=this._sources.get(t);n?.off("data",e)}this._sourceListeners.clear();for(const t of this._sources.keys())this._featureQuery?.clear(t);this._layerArcFlagsCache.clear(),this._sources.clear();const t=this._controls??[];for(const e of[...t])try{e.onRemove(this)}catch(t){this.fire("error",{error:t})}t.length=0,this._controlContainers?.clear(),this._editState?.setMode("none"),this._container&&this._canvasContainer&&this._container.removeChild(this._canvasContainer)}_removed=!1}function Yn(t){return`"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/\0/g,"\\0")}"`}const Qn=/^[A-Za-z0-9_\-:.一-鿿][A-Za-z0-9_\-:. 一-鿿]*$/,ti=/^[A-Za-z0-9_\-.一-鿿][A-Za-z0-9_\-. 一-鿿]*$/;function ei(t){return"string"==typeof t&&t.length>0&&Qn.test(t)}function ni(t){return"string"==typeof t&&t.length>0&&ti.test(t)}function ii(t){for(const e of t)if(!ni(e))return"string"==typeof e?e:String(e);return null}function si(t={}){const e=t.severity??"error";return{name:"topology",phase:"after-commit",async run(n){const i=Y(),s=t.sources??Array.from(n._sources.keys()),r=[];for(const o of s){const s=n._sources.get(o)?.getDataset();if(!s||!s.arcs)continue;const a={};void 0!==t.tolerance&&(a.tolerance=t.tolerance);const h=i.findSegmentIntersections(s.arcs,a);h.length>0&&r.push({severity:e,message:`${o}: ${h.length} self-intersection${1===h.length?"":"s"}`})}return{ok:0===r.length,issues:r}}}}class ri{opts;label="Move vertex";_mergeAt=Date.now();constructor(t){this.opts=t}do(){(this.opts.adapter??Y()).snapVertices(this.opts.vertexIds,this.opts.to,this.opts.arcs),this.opts.source.markDisplayArcsDirty?.(),Ft(this.opts.source.getDataset?.())}undo(){(this.opts.adapter??Y()).snapVertices(this.opts.vertexIds,this.opts.from,this.opts.arcs),this.opts.source.markDisplayArcsDirty?.(),Ft(this.opts.source.getDataset?.())}mergeable(t){if(!(t instanceof ri))return!1;if(t.opts.source!==this.opts.source)return!1;if(Date.now()-t._mergeAt>500)return!1;const e=t.opts.vertexIds,n=this.opts.vertexIds;if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(e[t]!==n[t])return!1;return!0}merge(t){t instanceof ri&&(this.opts.to=t.opts.to,this._mergeAt=Date.now())}}class oi{opts;label="Insert vertex";constructor(t){this.opts=t}do(){(this.opts.adapter??Y()).insertVertex(this.opts.arcs,this.opts.insertionId,this.opts.point),this.opts.source.markDisplayArcsDirty?.(),Ft(this.opts.source.getDataset?.())}undo(){(this.opts.adapter??Y()).deleteVertex(this.opts.arcs,this.opts.insertionId),this.opts.source.markDisplayArcsDirty?.(),Ft(this.opts.source.getDataset?.())}}class ai{opts;label="Delete vertex";constructor(t){this.opts=t}do(){(this.opts.adapter??Y()).deleteVertex(this.opts.arcs,this.opts.vertexIndex),this.opts.source.markDisplayArcsDirty?.(),Ft(this.opts.source.getDataset?.())}undo(){(this.opts.adapter??Y()).insertVertex(this.opts.arcs,this.opts.vertexIndex,this.opts.coords),this.opts.source.markDisplayArcsDirty?.(),Ft(this.opts.source.getDataset?.())}}class hi{opts;label;constructor(t){this.opts=t,this.label=`Draw ${t.geometryType}`}do(){const t=this.opts,e=t.adapter??Y();if("point"!==t.geometryType){if(!t.arcs||!t.arcVertices)throw new Error("FeatureCreateCommand: path features require arcs and arcVertices");e.appendEmptyArc(t.arcs);for(const n of t.arcVertices)e.appendVertex(t.arcs,n)}if(t.layer.shapes||(t.layer.shapes=[]),t.layer.shapes.push(t.appendedShape),null!==t.appendedRecord){const e=t.layer.data?.getRecords?.();e?.push(t.appendedRecord)}t.source.markDisplayArcsDirty?.(),Ft(t.source.getDataset?.())}undo(){const t=this.opts,e=t.adapter??Y();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?.(),Ft(t.source.getDataset?.())}}class li{_map=null;_container=null;_options;constructor(t={}){this._options={showZoom:!0,showHome:!0,...t}}onAdd(t){return this._map=t,this._container=document.createElement("div"),this._container.className=`emap-ctrl emap-ctrl-group ${this._options.className||""}`,this._options.showZoom&&(this._createButton("zoom-in","+","Zoom In",()=>{this._map?.zoomIn()}),this._createButton("zoom-out","-","Zoom Out",()=>{this._map?.zoomOut()})),this._options.showHome&&this._createButton("home","⌂","Reset View",()=>{this._map?.fire("reset")}),this._container}_createButton(t,e,n,i){const s=document.createElement("button");s.className=`emap-ctrl-${t}`,s.type="button",s.title=n;const r=document.createElement("span");r.className="emap-ctrl-icon",r.textContent=e,s.appendChild(r),s.addEventListener("click",i),this._container?.appendChild(s)}onRemove(){this._container&&this._container.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._container=null}}class ci{_map=null;_container=null;_options;_mousePosEl=null;_epsgEl=null;_onMouseMoveBound;_onUpdateEPSGBound;_rafPending=!1;constructor(t={}){this._options={showMousePos:!0,showEPSG:!0,alignment:"left",...t},this._onMouseMoveBound=this._onMouseMove.bind(this),this._onUpdateEPSGBound=this._updateEPSG.bind(this)}onAdd(t){return this._map=t,this._container=document.createElement("div"),this._container.className=`emap-ctrl emap-status-ctrl emap-align-${this._options.alignment} ${this._options.className||""}`,this._options.showMousePos&&(this._mousePosEl=document.createElement("span"),this._mousePosEl.className="emap-status-mousepos",this._container.appendChild(this._mousePosEl)),this._options.showEPSG&&(this._epsgEl=document.createElement("span"),this._epsgEl.className="emap-status-epsg",this._container.appendChild(this._epsgEl),this._updateEPSG()),this._map.on("crschange",this._onUpdateEPSGBound),this._map.getCanvasContainer().addEventListener("mousemove",this._onMouseMoveBound),this._container}_onMouseMove(t){if(!this._map||!this._mousePosEl||!this._options.showMousePos)return;if(this._rafPending)return;this._rafPending=!0;const e=t.clientX,n=t.clientY;requestAnimationFrame(()=>{if(this._rafPending=!1,!this._map||!this._mousePosEl)return;const t=this._map.getCanvasContainer().getBoundingClientRect(),i=e-t.left,s=n-t.top,[r,o]=this._map.unproject(i,s);this._mousePosEl.textContent=` ${r.toFixed(4)}, ${o.toFixed(4)}`})}_updateEPSG(){if(!this._map||!this._epsgEl)return;const t=this._map.getCRS();this._epsgEl.textContent=` | ${t}`}onRemove(){this._map&&(this._map.getCanvasContainer().removeEventListener("mousemove",this._onMouseMoveBound),this._map.off("crschange",this._onUpdateEPSGBound)),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._container=null}}const ui=[{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 pi{_map=null;_container=null;_basemapContainer=null;_maplibre=null;_maplibreMap=null;_styles;_activeStyle=null;_isOn=!1;_syncBasemapBound;constructor(t={}){this._styles=t.styles||ui,this._syncBasemapBound=this._syncBasemap.bind(this)}onAdd(t){return this._map=t,this._container=document.createElement("div"),this._container.className="emap-ctrl emap-basemap-ctrl",this._styles.forEach(t=>{const e=document.createElement("button");e.className="emap-basemap-btn",e.textContent=t.name,e.onclick=()=>this._toggleStyle(t),this._container.appendChild(e)}),this._createBasemapLayer(),this._map.on("move",this._syncBasemapBound),this._container}_createBasemapLayer(){if(!this._map)return;const t=this._map.getCanvasContainer();this._basemapContainer=document.createElement("div"),this._basemapContainer.className="emap-basemap",this._basemapContainer.style.cssText="\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n z-index: 0;\n display: none;\n ",t.insertBefore(this._basemapContainer,t.firstChild)}_toggleStyle(t){this._activeStyle===t?this._turnOff():this._showBasemap(t),this._updateButtons()}async _showBasemap(t){if(this._activeStyle=t,this._isOn=!0,!this._basemapContainer||!this._map)return;this._basemapContainer.style.display="block";const e=(this._map.getCRS()||"").toLowerCase();"webmercator"!==e&&"epsg:3857"!==e&&this._map.reproject&&await this._map.reproject("webmercator"),this._maplibreMap?(this._maplibreMap.resize(),this._setStyle(t),this._syncBasemap()):await this._initMapLibre(t)}async _initMapLibre(t){if(!this._basemapContainer||!this._map)return;const e=await this._loadMapLibre(),n=this._createMapLibreStyle(t);this._maplibreMap=new e.Map({container:this._basemapContainer,style:n,center:this._map.getCenter(),zoom:this._map.getZoom(),interactive:!1,attributionControl:!1,maxPitch:0,renderWorldCopies:!0}),this._maplibreMap.on("load",()=>{this._syncBasemap()})}async _loadMapLibre(){return this._maplibre||(this._maplibre=await import("maplibre-gl")),this._maplibre}_setStyle(t){if(!this._maplibreMap)return;const e=this._createMapLibreStyle(t);this._maplibreMap.setStyle(e)}_createMapLibreStyle(t){return"raster"===t.type||t.url.includes("{z}")?{version:8,sources:{"basemap-tiles":{type:"raster",tiles:[t.url],tileSize:512}},layers:[{id:"basemap-layer",type:"raster",source:"basemap-tiles",minzoom:0,maxzoom:22}]}:t.url}_syncBasemap(){if(this._maplibreMap&&this._map&&this._isOn)try{this._maplibreMap.jumpTo({center:this._map.getCenter(),zoom:this._map.getZoom()})}catch(t){console.warn("Sync basemap failed:",t)}}_turnOff(){this._activeStyle=null,this._isOn=!1,this._basemapContainer&&(this._basemapContainer.style.display="none")}_updateButtons(){if(!this._container)return;this._container.querySelectorAll(".emap-basemap-btn").forEach((t,e)=>{const n=this._styles[e]===this._activeStyle;t.classList.toggle("active",n)})}isOn(){return this._isOn}onRemove(){this._map&&this._map.off("move",this._syncBasemapBound),this._maplibreMap&&(this._maplibreMap.remove(),this._maplibreMap=null),this._basemapContainer?.parentNode&&this._basemapContainer.parentNode.removeChild(this._basemapContainer),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null}}class di{_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],n=this._hoveredFeature.arcs;Y().vertexIsArcEndpoint(e,n)||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],n=this._hoveredFeature.source,i=t.getVertex2(e);if(Y().deleteVertex(t,e),this._refreshSourceDisplayArcs(n),this._bumpSourceEditVersion(n),i){const s=this._map.getSource(n);s&&this._map.pushCommand(new ai({vertexIndex:e,coords:[i[0],i[1]],arcs:t,source:s}))}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);Ft(e?.getDataset?.()??null)}_showContextMenu(t,e,n){document.getElementById("emap-ctx-menu")?.remove();const i=document.createElement("div");i.id="emap-ctx-menu",Object.assign(i.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 s=document.createElement("div");s.textContent="删除节点",Object.assign(s.style,{padding:"6px 16px",cursor:"pointer",color:"#d32"}),s.addEventListener("mouseenter",()=>{s.style.background="#f5f5f5"}),s.addEventListener("mouseleave",()=>{s.style.background=""}),s.addEventListener("click",t=>{t.stopPropagation(),i.remove(),document.removeEventListener("click",r),n()}),i.appendChild(s),document.body.appendChild(i);const r=()=>{i.remove(),document.removeEventListener("click",r)};setTimeout(()=>document.addEventListener("click",r),0)}_onMouseMove(t){if(!this._map)return;if(this._dragging)return void this._handleDrag(t);const e=this._map.getCanvasContainer().getBoundingClientRect(),n=t.clientX-e.left,i=t.clientY-e.top,s=this._map.queryFeatures([n,i]);if(0===s.length)return this._hoveredFeature=null,this._hoverVertexCoords=null,this._hoverVertexIds=[],this._hoverType=null,this._hoverInsertionId=-1,this._neighborShapes=[],this._map.clearEditVertexState(),void this._map.render();const r=s[0];if("point"===r.geometryType)return this._hoveredFeature=null,this._hoverVertexCoords=null,this._hoverVertexIds=[],this._hoverType=null,this._hoverInsertionId=-1,this._neighborShapes=[],this._map.clearEditVertexState(),void this._map.render();const o=this._map.getSource(r.source);if(!o)return;const a=o.getLayers(),h=o.getArcs();if(!h)return;let l=null;for(const t of a)if(t.shapes&&t.shapes[r.id]){l=t.shapes[r.id];break}l&&(this._hoveredFeature={source:r.source,layer:r.layer,id:r.id,shape:l,arcs:h,geometryType:r.geometryType,allLayers:a},this._findNearestVertices(l,h,n,i),this._hoverVertexCoords||this._findInterpolatedPoint(l,h,n,i),this._findNeighborShapes(h),this._updateEditState(),this._map.render())}_findNearestVertices(t,e,n,i){if(!this._map)return;const s=this._map.unproject(n,i),r=Y().findNearestVertices(s,t,e);if(!r||0===r.length)return this._hoverVertexCoords=null,void(this._hoverVertexIds=[]);const o=e.getVertex2(r[0]);if(!o)return this._hoverVertexCoords=null,void(this._hoverVertexIds=[]);const a=this._map.project(o[0],o[1]);Math.sqrt((a[0]-n)*(a[0]-n)+(a[1]-i)*(a[1]-i))<=10?(this._hoverVertexCoords=[o[0],o[1]],this._hoverVertexIds=r,this._hoverType="vertex",this._hoverInsertionId=-1):(this._hoverVertexCoords=null,this._hoverVertexIds=[],this._hoverType=null,this._hoverInsertionId=-1)}_findInterpolatedPoint(t,e,n,i){if(!this._map)return;const s=this._map.unproject(n,i);let r=1/0,o=null;const a=Y();if(a.forEachSegmentInShape(t,e,(t,e,n,i)=>{const h=n[t],l=i[t],c=n[e],u=i[e],p=a.findClosestPointOnSeg(s[0],s[1],h,l,c,u,0),d=p[0]-s[0],_=p[1]-s[1],f=Math.sqrt(d*d+_*_);f<r&&(r=f,o={insertionId:(t<e?t:e)+1,point:[p[0],p[1]]})}),!o)return;const h=o,l=this._map.project(h.point[0],h.point[1]);Math.sqrt((l[0]-n)*(l[0]-n)+(l[1]-i)*(l[1]-i))<=10&&(this._hoverVertexCoords=h.point,this._hoverVertexIds=[],this._hoverType="interpolated",this._hoverInsertionId=h.insertionId)}_findNeighborShapes(t){if(this._neighborShapes=[],!this._hoveredFeature||"polygon"!==this._hoveredFeature.geometryType)return;const{ii:e}=t.getVertexData(),n=this._hoveredFeature.id,i=new Set;if(this._hoverVertexIds.length>0)for(const t of this._hoverVertexIds)i.add(Y().findArcIdFromVertexId(t,e));else"interpolated"===this._hoverType&&this._hoverInsertionId>0&&i.add(Y().findArcIdFromVertexId(this._hoverInsertionId-1,e));if(0===i.size)return;const s=[];for(const t of this._hoveredFeature.allLayers)if(t.shapes)for(let e=0;e<t.shapes.length;e++){if(e===n)continue;const r=t.shapes[e];if(!r)continue;let o=!1;for(const t of r){for(const e of t){const t=e>=0?e:~e;if(i.has(t)){o=!0;break}}if(o)break}o&&s.push(r)}this._neighborShapes=s}_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]];Y().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 n=this._map.getSource(this._hoveredFeature.source);n&&this._map.pushCommand(new oi({insertionId:t,point:e,arcs:this._hoveredFeature.arcs,source:n}))}_handleDrag(t){if(!this._map||!this._hoveredFeature||0===this._hoverVertexIds.length)return;const e=this._map.getCanvasContainer().getBoundingClientRect(),n=t.clientX-e.left,i=t.clientY-e.top,s=this._map.unproject(n,i),r=this._hoveredFeature.arcs;Y().snapVertices(this._hoverVertexIds,[s[0],s[1]],r),this._hoverVertexCoords=[s[0],s[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(),n=t.clientX-e.left,i=t.clientY-e.top,s=this._map.unproject(n,i),r=this._hoveredFeature.source,o=this._hoveredFeature.arcs;o.transformPoints&&o.transformPoints(function(){}),this._refreshSourceDisplayArcs(r),this._bumpSourceEditVersion(r);const a=this._dragFromCoords;if(a&&(a[0]!==s[0]||a[1]!==s[1])&&this._hoverVertexIds.length>0){const t=this._map.getSource(r);t&&this._map.pushCommand(new ri({vertexIds:[...this._hoverVertexIds],from:[a[0],a[1]],to:[s[0],s[1]],arcs:o,source:t}))}this._dragFromCoords=null,this._map.fire("vertex_moved",{id:this._hoveredFeature.id,source:r,layer:this._hoveredFeature.layer,vertexIndex:this._hoverVertexIds[0]??null,vertexIds:this._hoverVertexIds,coords:s}),this._map.render()}}const _i={polygon:"▢",polyline:"╱",point:"●"},fi={polygon:"Draw Polygon",polyline:"Draw Polyline",point:"Draw Point"};class mi{_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=fi[this._options.type];const e=document.createElement("span");e.className="emap-ctrl-icon";const n=this._options.icon??_i[this._options.type];return"string"==typeof n?e.textContent=n:e.appendChild(n),this._btn.replaceChildren(e),this._btn.addEventListener("click",()=>this._toggle()),this._container.appendChild(this._btn),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(),n=t.clientX-e.left,i=t.clientY-e.top,s=this._map.unproject(n,i);this._cursorCoord=[s[0],s[1]];const r=this._findSnapTarget(n,i);this._snapCoord=r?.coord??null,this._snapKind=r?.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(),n=t.clientX-e.left,i=t.clientY-e.top,s=this._snapCoord?[this._snapCoord[0],this._snapCoord[1]]:this._map.unproject(n,i);if("point"===this._options.type)return this._vertices=[s],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]-n,e[1]-i)<=12)return void this._commitFeature()}this._vertices.push(s),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 n=this._map,i=this._options.snapSources??[this._options.source],s=!1!==this._options.snapToVertex,r=!1!==this._options.snapToEdge;let o=this._snapThreshold,a=null,h=null;for(const l of i){const i=n.getSource(l);if(!i)continue;const c=i.getArcs();if(!c?.getVertexData)continue;const u=c.getVertexData();if(!u)continue;const p=u.xx,d=u.yy;if(s)for(let i=0;i<p.length;i++){const s=n.project(p[i],d[i]),r=Math.hypot(s[0]-t,s[1]-e);r<o&&(o=r,a=[p[i],d[i]],h="vertex")}r&&c.forEachSegment&&c.forEachSegment((i,s,r,l)=>{const c=n.project(r[i],l[i]),u=n.project(r[s],l[s]),p=yi([t,e],c,u);p.dist<o&&(o=p.dist,a=n.unproject(p.point[0],p.point[1]),h="edge")})}if(s)for(const i of this._vertices){const s=n.project(i[0],i[1]),r=Math.hypot(s[0]-t,s[1]-e);r<o&&(o=r,a=[i[0],i[1]],h="vertex")}return a?{coord:a,kind:h}: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 n=this._resolveTargetLayer(e.layers);if(!n)return;const i=e.layers.indexOf(n);let s,r,o;if(n.shapes||(n.shapes=[]),"point"===this._options.type)s=[this._vertices[0]],n.shapes.push(s);else{if(r="polygon"===this._options.type?[...this._vertices,this._vertices[0]]:[...this._vertices],o=e.arcs,!o)return;s=[[this._appendArc(o,r)]],n.shapes.push(s)}let a=null;if(n.data){const t=n.data.getRecords?.();t&&(a={},t.push(a))}t.refreshDisplayArcs(),this._map.pushCommand(new hi({geometryType:this._options.type,layer:n,source:t,appendedShape:s,appendedRecord:a,arcVertices:r,arcs:o}));const h=n.shapes.length-1,l=nt(n,i>=0?i:0);this._map.fire("feature_created",{id:h,source:this._options.source,layer:l,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(nt(t[e],e)===this._options.sourceLayer)return t[e]}const e="polygon"===this._options.type?"polygon":"polyline"===this._options.type?"polyline":"point";for(const n of t)if(n.geometry_type===e)return n;return t[0]}_appendArc(t,e){const n=t.getVertexData(),i=n.xx,s=n.yy,r=n.nn,o=n.zz,a=i.length,h=r.length,l=e.length,c=new Float64Array(a+l),u=new Float64Array(a+l),p=new Int32Array(h+1);c.set(i),u.set(s),p.set(r);for(let t=0;t<l;t++)c[a+t]=e[t][0],u[a+t]=e[t][1];p[h]=l;let d=null;if(o){d=new Float64Array(a+l),d.set(o);for(let t=0;t<l;t++)d[a+t]=1/0}return t.updateVertexData(p,c,u,d),h}_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 yi(t,e,n){const i=e[0],s=e[1],r=n[0],o=n[1],a=t[0],h=t[1],l=r-i,c=o-s,u=l*l+c*c;if(0===u){const t=a-i,e=h-s;return{point:[i,s],dist:Math.hypot(t,e)}}let p=((a-i)*l+(h-s)*c)/u;p<0?p=0:p>1&&(p=1);const d=i+p*l,_=s+p*c;return{point:[d,_],dist:Math.hypot(a-d,h-_)}}class gi{_container=null;_vertexEditControl;_drawControls=[];_options;constructor(t){this._options=t||{},this._vertexEditControl=new di,this._options.drawSource&&(this._drawControls=[new mi({source:this._options.drawSource,sourceLayer:this._options.drawSourceLayer,type:"polygon"}),new mi({source:this._options.drawSource,sourceLayer:this._options.drawSourceLayer,type:"polyline"}),new mi({source:this._options.drawSource,sourceLayer:this._options.drawSourceLayer,type:"point"})])}onAdd(t){const e=this._vertexEditControl.onAdd(t);this._container=document.createElement("div"),this._container.className="emap-ctrl emap-ctrl-group emap-edit-toolbar";const n=e.querySelector("button");n&&this._container.appendChild(n);for(const e of this._drawControls){const n=e.onAdd(t).querySelector("button");n&&this._container.appendChild(n)}return this._container}onRemove(){this._vertexEditControl.onRemove();for(const t of this._drawControls)t.onRemove();this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._container=null}}class vi{_map=null;_container=null;_undoBtn=null;_redoBtn=null;_options;_onHistoryChange=null;constructor(t={}){this._options=t}onAdd(t){return this._map=t,this._container=document.createElement("div"),this._container.className=`emap-ctrl emap-ctrl-group ${this._options.className||""}`.trim(),this._undoBtn=this._createButton("undo","↶",this._options.undoTitle??"Undo (Ctrl+Z)",()=>{this._map?.undo()}),this._redoBtn=this._createButton("redo","↷",this._options.redoTitle??"Redo (Ctrl+Shift+Z)",()=>{this._map?.redo()}),this._setEnabled(t.canUndo(),t.canRedo()),this._onHistoryChange=t=>this._setEnabled(t.canUndo,t.canRedo),t.on("historychange",this._onHistoryChange),this._container}onRemove(){this._map&&this._onHistoryChange&&this._map.off("historychange",this._onHistoryChange),this._onHistoryChange=null,this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._container=null,this._undoBtn=null,this._redoBtn=null}_setEnabled(t,e){this._undoBtn&&(this._undoBtn.disabled=!t),this._redoBtn&&(this._redoBtn.disabled=!e)}_createButton(t,e,n,i){const s=document.createElement("button");s.className=`emap-ctrl-${t}`,s.type="button",s.title=n,s.disabled=!0;const r=document.createElement("span");return r.className="emap-ctrl-icon",r.textContent=e,s.appendChild(r),s.addEventListener("click",i),this._container?.appendChild(s),s}}class xi{_options;_dragThreshold;_enabled=!0;_map=null;_container=null;_overlay=null;_canvasContainer=null;_startPx=null;_onMouseDownBound;_onMouseMoveBound;_onMouseUpBound;constructor(t={}){this._options=t,this._dragThreshold=t.dragThreshold??4,this._onMouseDownBound=this._onMouseDown.bind(this),this._onMouseMoveBound=this._onMouseMove.bind(this),this._onMouseUpBound=this._onMouseUp.bind(this)}onAdd(t){this._map=t,this._canvasContainer=t.getCanvasContainer();const e=document.createElement("div");e.className="emap-box-select",e.style.position="absolute",e.style.pointerEvents="none",e.style.display="none",e.style.left="0",e.style.top="0",e.style.width="0",e.style.height="0";const n=this._options.style??{};e.style.border=`${n.strokeWidth??1.5}px solid ${n.stroke??"#0078ff"}`,e.style.background=n.fill??"rgba(0, 120, 255, 0.1)",e.style.boxSizing="border-box",this._canvasContainer.appendChild(e),this._overlay=e,this._canvasContainer.addEventListener("mousedown",this._onMouseDownBound);const i=document.createElement("div");return i.className="emap-ctrl emap-box-select-anchor",i.style.width="0",i.style.height="0",i.style.pointerEvents="none",this._container=i,i}onRemove(){this._canvasContainer&&this._canvasContainer.removeEventListener("mousedown",this._onMouseDownBound),window.removeEventListener("mousemove",this._onMouseMoveBound),window.removeEventListener("mouseup",this._onMouseUpBound),this._overlay?.parentNode&&this._overlay.parentNode.removeChild(this._overlay),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._canvasContainer=null,this._overlay=null,this._container=null,this._startPx=null}disable(){this._enabled=!1,this._startPx&&this._cancelDrag()}enable(){this._enabled=!0}isEnabled(){return this._enabled}_onMouseDown(t){if(!this._enabled)return;if(!t.shiftKey)return;if(0!==t.button)return;if(!this._canvasContainer||!this._overlay)return;t.preventDefault();const[e,n]=this._eventToContainerPx(t);this._startPx=[e,n],this._overlay.style.left=`${e}px`,this._overlay.style.top=`${n}px`,this._overlay.style.width="0",this._overlay.style.height="0",this._overlay.style.display="block",window.addEventListener("mousemove",this._onMouseMoveBound),window.addEventListener("mouseup",this._onMouseUpBound)}_onMouseMove(t){if(!this._startPx||!this._overlay)return;const[e,n]=this._eventToContainerPx(t),[i,s]=this._startPx,r=Math.min(i,e),o=Math.min(s,n),a=Math.abs(e-i),h=Math.abs(n-s);this._overlay.style.left=`${r}px`,this._overlay.style.top=`${o}px`,this._overlay.style.width=`${a}px`,this._overlay.style.height=`${h}px`}_onMouseUp(t){if(!this._startPx||!this._map||!this._overlay)return void this._cleanupDrag();const[e,n]=this._startPx,[i,s]=this._eventToContainerPx(t),r=i-e,o=s-n,a=Math.hypot(r,o);if(this._overlay.style.display="none",a<this._dragThreshold)return void this._cleanupDrag();const h=Math.min(e,i),l=Math.min(n,s),c=Math.max(e,i),u=Math.max(n,s),p=function(t){const e=new Set,n=[];for(const i of t){const t=`${i.source}|${i.layer}|${i.id}`;e.has(t)||(e.add(t),n.push({source:i.source,layer:i.layer,id:i.id}))}return n}(this._map.queryFeatures([[h,l],[c,u]],this._options.layers?{layers:this._options.layers}:void 0)),d=this._modeFromEvent(t);this._map.select(p,{mode:d}),this._cleanupDrag()}_cancelDrag(){this._overlay&&(this._overlay.style.display="none"),this._cleanupDrag()}_cleanupDrag(){this._startPx=null,window.removeEventListener("mousemove",this._onMouseMoveBound),window.removeEventListener("mouseup",this._onMouseUpBound)}_eventToContainerPx(t){if(!this._canvasContainer)return[0,0];const e=this._canvasContainer.getBoundingClientRect();return[t.clientX-e.left,t.clientY-e.top]}_modeFromEvent(t){return t.altKey?"toggle":t.ctrlKey||t.metaKey?"add":"replace"}}class wi{_options;_dragThreshold;_enabled=!0;_map=null;_container=null;_svg=null;_polyline=null;_canvasContainer=null;_path=null;_onMouseDownBound;_onMouseMoveBound;_onMouseUpBound;constructor(t={}){this._options=t,this._dragThreshold=t.dragThreshold??4,this._onMouseDownBound=this._onMouseDown.bind(this),this._onMouseMoveBound=this._onMouseMove.bind(this),this._onMouseUpBound=this._onMouseUp.bind(this)}onAdd(t){this._map=t,this._canvasContainer=t.getCanvasContainer();const e="http://www.w3.org/2000/svg",n=document.createElementNS(e,"svg");n.setAttribute("class","emap-lasso-select"),n.style.position="absolute",n.style.left="0",n.style.top="0",n.style.width="100%",n.style.height="100%",n.style.pointerEvents="none",n.style.display="none";const i=document.createElementNS(e,"polyline"),s=this._options.style??{};i.setAttribute("stroke",s.stroke??"#0078ff"),i.setAttribute("stroke-width",String(s.strokeWidth??1.5)),i.setAttribute("fill",s.fill??"rgba(0, 120, 255, 0.1)"),i.setAttribute("stroke-dasharray",s.strokeDasharray??"4 3"),i.setAttribute("points",""),n.appendChild(i),this._canvasContainer.appendChild(n),this._svg=n,this._polyline=i,this._canvasContainer.addEventListener("mousedown",this._onMouseDownBound);const r=document.createElement("div");return r.className="emap-ctrl emap-lasso-select-anchor",r.style.width="0",r.style.height="0",r.style.pointerEvents="none",this._container=r,r}onRemove(){this._canvasContainer&&this._canvasContainer.removeEventListener("mousedown",this._onMouseDownBound),window.removeEventListener("mousemove",this._onMouseMoveBound),window.removeEventListener("mouseup",this._onMouseUpBound),this._svg?.parentNode&&this._svg.parentNode.removeChild(this._svg),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._canvasContainer=null,this._svg=null,this._polyline=null,this._container=null,this._path=null}disable(){this._enabled=!1,this._path&&this._cancelDrag()}enable(){this._enabled=!0}isEnabled(){return this._enabled}_onMouseDown(t){if(!this._enabled)return;if(!t.shiftKey)return;if(0!==t.button)return;if(!this._canvasContainer||!this._svg||!this._polyline)return;t.preventDefault();const e=this._eventToContainerPx(t);this._path=[e],this._polyline.setAttribute("points",`${e[0]},${e[1]}`),this._svg.style.display="block",window.addEventListener("mousemove",this._onMouseMoveBound),window.addEventListener("mouseup",this._onMouseUpBound)}_onMouseMove(t){if(!this._path||!this._polyline)return;const e=this._eventToContainerPx(t);this._path.push(e),this._polyline.setAttribute("points",this._path.map(t=>`${t[0]},${t[1]}`).join(" "))}_onMouseUp(t){const e=this._path;if(!e||!this._map||!this._svg)return void this._cleanupDrag();if(this._svg.style.display="none",e.length<3)return void this._cleanupDrag();const n=function(t){let e=1/0,n=1/0,i=-1/0,s=-1/0;for(const[r,o]of t)r<e&&(e=r),o<n&&(n=o),r>i&&(i=r),o>s&&(s=o);return[e,n,i,s]}(e),i=n[2]-n[0],s=n[3]-n[1];if(Math.hypot(i,s)<this._dragThreshold)return void this._cleanupDrag();const r=e.slice();r.push(e[0]);const o=this._map.queryFeatures([[n[0],n[1]],[n[2],n[3]]],this._options.layers?{layers:this._options.layers}:void 0),a=[],h=new Set,l=!1!==this._options.includeIntersecting;for(const t of o){const e=`${t.source}|${t.layer}|${t.id}`;h.has(e)||Ci(this._map,t,r,l)&&(h.add(e),a.push({source:t.source,layer:t.layer,id:t.id}))}const c=function(t){return t.altKey?"toggle":t.ctrlKey||t.metaKey?"add":"replace"}(t);this._map.select(a,{mode:c}),this._cleanupDrag()}_cancelDrag(){this._svg&&(this._svg.style.display="none"),this._cleanupDrag()}_cleanupDrag(){this._path=null,window.removeEventListener("mousemove",this._onMouseMoveBound),window.removeEventListener("mouseup",this._onMouseUpBound)}_eventToContainerPx(t){if(!this._canvasContainer)return[0,0];const e=this._canvasContainer.getBoundingClientRect();return[t.clientX-e.left,t.clientY-e.top]}}function bi(t,e){const[n,i]=t;let s=!1;const r=e.length;for(let t=0,o=r-1;t<r;o=t++){const[r,a]=e[t],[h,l]=e[o];a>i!=l>i&&n<(h-r)*(i-a)/(l-a)+r&&(s=!s)}return s}function Ci(t,e,n,i){const s=function(t,e){const n=t.getSource(e.source);if(!n)return null;let i=t.layers?.resolve(e.source,e.layer);if(!i){const t=n.getDataset?.();i=t?.layers.find((t,n)=>nt(t,n)===e.layer||t?.name===e.layer||t?.id===e.layer)}if(!i?.shapes)return null;const s=i.shapes?.[e.id];return s?{layer:i,shape:s,arcs:n.getArcs?.()}:null}(t,e);if(!s)return!1;if("point"===s.layer.geometry_type){const e=it(s.shape);if(0===e.length)return!1;const r=e.map(([e,n])=>t.project(e,n));return i?r.some(t=>Ai(t,n)):r.every(t=>Ai(t,n))}if(!s.arcs)return!1;const r=function(t,e,n){const i=[];for(const s of e){const e=[],r=n.getShapeIter?.(s);if(r)for(;r.hasNext();)e.push(t.project(r.x,r.y));else for(const i of s){const s=i>=0?i:~i,r=n.getArcIter(s);for(;r.hasNext();)e.push(t.project(r.x,r.y))}e.length>0&&i.push(e)}return i}(t,s.shape,s.arcs);if(0===r.length)return!1;const o="polygon"===s.layer.geometry_type;return i?function(t,e,n){for(const i of t){if(i.some(t=>Ai(t,e)))return!0;if(Si(i,e,n))return!0}return!(!n||!e.some(e=>function(t,e){let n=!1;for(const i of e){if(Mi(t,i))return!0;bi(t,i)&&(n=!n)}return n}(e,t)))}(r,n,o):function(t,e,n){for(const i of t){if(!i.every(t=>Ai(t,e)))return!1;if(Si(i,e,n))return!1}return!0}(r,n,o)}function Si(t,e,n){const i=n?Ei(t):t,s=Ei(e);for(let t=0;t<i.length-1;t++){const e=i[t],n=i[t+1];for(let t=0;t<s.length-1;t++){if(ki(e,n,s[t],s[t+1]))return!0}}return!1}function Ai(t,e){return Mi(t,e)||bi(t,e)}function Mi(t,e){const n=Ei(e);for(let e=0;e<n.length-1;e++)if(Di(t,n[e],n[e+1]))return!0;return!1}function Ei(t){if(t.length<2)return t;const e=t[0],n=t[t.length-1];return i=e,s=n,Math.abs(i[0]-s[0])<=Ti&&Math.abs(i[1]-s[1])<=Ti?t:[...t,e];var i,s}function ki(t,e,n,i){const s=Ii(t,e,n),r=Ii(t,e,i),o=Ii(n,i,t),a=Ii(n,i,e);return!(!Pi(s)||!Di(n,t,e))||(!(!Pi(r)||!Di(i,t,e))||(!(!Pi(o)||!Di(t,n,i))||(!(!Pi(a)||!Di(e,n,i))||s>0!=r>0&&o>0!=a>0)))}function Di(t,e,n){return!!Pi(Ii(e,n,t))&&(t[0]>=Math.min(e[0],n[0])-Ti&&t[0]<=Math.max(e[0],n[0])+Ti&&t[1]>=Math.min(e[1],n[1])-Ti&&t[1]<=Math.max(e[1],n[1])+Ti)}function Ii(t,e,n){return(e[0]-t[0])*(n[1]-t[1])-(e[1]-t[1])*(n[0]-t[0])}function Pi(t){return Math.abs(t)<=Ti}const Ti=1e-9;const Li=[{value:"",label:"weighted (default)"},{value:"weighted",label:"weighted"},{value:"visvalingam",label:"visvalingam"},{value:"dp",label:"dp (Douglas–Peucker)"}];class Ni{_opts;_map=null;_container=null;_btn=null;_popup=null;_percentageInput=null;_percentageLabel=null;_methodSel=null;_keepShapes=null;_planar=null;_applyBtn=null;_statusEl=null;_onDocClick=null;_onDocKey=null;constructor(t){this._opts=t}onAdd(t){return this._map=t,this._container=document.createElement("div"),this._container.className="emap-ctrl emap-ctrl-group emap-ctrl-simplify-wrap",this._btn=document.createElement("button"),this._btn.type="button",this._btn.className="emap-ctrl-simplify",this._btn.innerHTML='<span class="emap-ctrl-icon">≈</span>',this._btn.title=this._opts.title??"Simplify geometry",this._btn.onclick=t=>{t.stopPropagation(),this._togglePopup()},this._container.appendChild(this._btn),this._popup=this._buildPopup(),this._container.appendChild(this._popup),this._container}onRemove(){this._teardownDocListeners(),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._container=null,this._btn=null,this._popup=null,this._percentageInput=null,this._percentageLabel=null,this._methodSel=null,this._keepShapes=null,this._planar=null,this._applyBtn=null,this._statusEl=null,this._map=null}_buildPopup(){const t=document.createElement("div");t.className="emap-simplify-popup",t.style.display="none",t.style.cssText+="\n position:absolute; top:36px; left:0; min-width:240px; padding:10px;\n background:#fff; border:1px solid #ccc; border-radius:4px;\n box-shadow:0 2px 8px rgba(0,0,0,.15); font-size:13px;\n z-index:10; color:#222;",t.onclick=t=>t.stopPropagation();const e=this._opts.initialPercentage??10,n=this._opts.initialMethod??"";return t.innerHTML=`\n <div style="margin-bottom:8px;">\n <label style="display:flex; align-items:center; gap:6px;">\n <span>Percentage:</span>\n <input type="range" min="0" max="100" step="0.1" value="${e}" style="flex:1;" />\n <span class="value" style="min-width:48px; text-align:right;">${e}%</span>\n </label>\n </div>\n <div style="margin-bottom:8px;">\n <label style="display:flex; align-items:center; gap:6px;">\n <span>Method:</span>\n <select style="flex:1;">\n ${Li.map(t=>`<option value="${t.value}"${t.value===n?" selected":""}>${t.label}</option>`).join("")}\n </select>\n </label>\n </div>\n <div style="margin-bottom:8px; display:flex; gap:12px; flex-wrap:wrap;">\n <label><input type="checkbox" data-flag="keep-shapes" checked /> keep-shapes</label>\n <label><input type="checkbox" data-flag="planar" /> planar</label>\n </div>\n <div style="display:flex; gap:6px; align-items:center;">\n <button type="button" class="apply" style="padding:4px 12px;">Apply</button>\n <span class="status" style="opacity:.8; font-size:12px;"></span>\n </div>\n `,this._percentageInput=t.querySelector("input[type=range]"),this._percentageLabel=t.querySelector(".value"),this._methodSel=t.querySelector("select"),this._keepShapes=t.querySelector("input[data-flag=keep-shapes]"),this._planar=t.querySelector("input[data-flag=planar]"),this._applyBtn=t.querySelector("button.apply"),this._statusEl=t.querySelector(".status"),this._percentageInput.oninput=()=>{this._percentageLabel&&this._percentageInput&&(this._percentageLabel.textContent=`${this._percentageInput.value}%`)},this._applyBtn.onclick=()=>this._apply(),t}_togglePopup(){if(!this._popup)return;const t="none"===this._popup.style.display;this._popup.style.display=t?"block":"none",this._btn?.classList.toggle("active",t),t?(this._setupDocListeners(),this._setStatus("")):this._teardownDocListeners()}_setupDocListeners(){this._onDocClick=t=>{this._container&&!this._container.contains(t.target)&&this._togglePopup()},this._onDocKey=t=>{"Escape"===t.key&&this._togglePopup()},document.addEventListener("mousedown",this._onDocClick),document.addEventListener("keydown",this._onDocKey)}_teardownDocListeners(){this._onDocClick&&document.removeEventListener("mousedown",this._onDocClick),this._onDocKey&&document.removeEventListener("keydown",this._onDocKey),this._onDocClick=null,this._onDocKey=null}_setStatus(t){this._statusEl&&(this._statusEl.textContent=t)}async _apply(){if(!this._map||!this._percentageInput||!this._methodSel)return;const t=Number(this._percentageInput.value),e=this._methodSel.value,n={source:this._opts.source,percentage:t};this._opts.target&&(n.target=this._opts.target),e&&(n.method=e),this._keepShapes?.checked&&(n.keepShapes=!0),this._planar?.checked&&(n.planar=!0),this._applyBtn&&(this._applyBtn.disabled=!0),this._setStatus("Running…");try{const e=await this._map.ops.simplifyLayer(n);if(e?.ok)this._setStatus(`Simplified at ${t}%`);else{const t=e?.error,n=t?`${t.kind}${t.field?" field="+t.field:""}`:"unknown";this._setStatus(`Failed: ${n}`)}}catch(t){this._setStatus(`Error: ${t?.message??t}`)}finally{this._applyBtn&&(this._applyBtn.disabled=!1)}}}export{$ as AffineTransform,pi as BasemapControl,V as Bounds,xi as BoxSelectControl,Kn as BulkFeatureDeleteCommand,st as CanvasPainter,Lt as CompositeCommand,Sn as DEFAULT_CRS,ot as DatasetReplaceCommand,Z as DefaultMapshaperAdapter,Nn as DragPanHandler,mi as DrawFeatureControl,Vn as EditHistory,rt as EditOverlayRenderer,gi as EditToolbar,Jn as Emap,lt as Err,j as EventDispatcher,Gn as FeatureAccessor,Ot as FeatureAffineCommand,hi as FeatureCreateCommand,Wn as FeatureDeleteCommand,Xt as FeaturePropertyChangeCommand,Fn as FeatureQuery,Gt as FeatureTranslateCommand,Jt as FieldAddCommand,Yt as FieldRemoveCommand,Qt as FieldRenameCommand,Bn as HighlightManager,vi as HistoryControl,qt as IDENTITY_MATRIX,wi as LassoSelectControl,Rn as MapshaperWorkerPool,li as NavigationControl,at as OK,et as Projection,zn as Selection,Ni as SimplifyControl,$t as SplitSharedArcsCommand,ci as StatusControl,Pn as TopologySource,Hn as Transaction,$ as Transform,On as ValidatorRegistry,ai as VertexDeleteCommand,di as VertexEditControl,oi as VertexInsertCommand,ri as VertexMoveCommand,X as Viewport,Ft as bumpEditVersion,Ut as composeMatrix,Ci as featureMatchesLasso,ii as findInvalidFieldName,Y as getDefaultMapshaperAdapter,En as inferFromPrj,jt as invertMatrix,Nt as isPathLayer,Rt as isPointLayer,ni as isValidFieldName,ei as isValidLayerName,Mn as normalizeCrsString,ht as okValue,Vt as planSharedArcSplit,bi as pointInPolygon,Yn as quoteCliArg,An as resolveDatasetCRS,Zn as resolvePointStyle,Xn as resolveStrokeStyle,Bt as rotateMatrix,zt as scaleMatrix,Q as setDefaultMapshaperAdapter,si as topologyValidator};
|
|
1
|
+
import t from"./mapshaper-vendor.mjs";function e(t,e){return e.forEach(function(e){e&&"string"!=typeof e&&!Array.isArray(e)&&Object.keys(e).forEach(function(i){if("default"!==i&&!(i in t)){var s=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,s.get?s:{enumerable:!0,get:function(){return e[i]}})}})}),Object.freeze(t)}function i(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function s(t){if(t.__esModule)return t;var e=t.default;if("function"==typeof e){var i=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};i.prototype=e.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(t).forEach(function(e){var s=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(i,e,s.get?s:{enumerable:!0,get:function(){return t[e]}})}),i}var n={exports:{}},r=s(Object.freeze({__proto__:null,default:{}}));function a(t,e){for(var i=0,s=t.length-1;s>=0;s--){var n=t[s];"."===n?t.splice(s,1):".."===n?(t.splice(s,1),i++):i&&(t.splice(s,1),i--)}if(e)for(;i--;i)t.unshift("..");return t}var o=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,h=function(t){return o.exec(t).slice(1)};function l(){for(var t="",e=!1,i=arguments.length-1;i>=-1&&!e;i--){var s=i>=0?arguments[i]:"/";if("string"!=typeof s)throw new TypeError("Arguments to path.resolve must be strings");s&&(t=s+"/"+t,e="/"===s.charAt(0))}return(e?"/":"")+(t=a(g(t.split("/"),function(t){return!!t}),!e).join("/"))||"."}function c(t){var e=u(t),i="/"===x(t,-1);return(t=a(g(t.split("/"),function(t){return!!t}),!e).join("/"))||e||(t="."),t&&i&&(t+="/"),(e?"/":"")+t}function u(t){return"/"===t.charAt(0)}function p(){return c(g(Array.prototype.slice.call(arguments,0),function(t,e){if("string"!=typeof t)throw new TypeError("Arguments to path.join must be strings");return t}).join("/"))}function _(t,e){function i(t){for(var e=0;e<t.length&&""===t[e];e++);for(var i=t.length-1;i>=0&&""===t[i];i--);return e>i?[]:t.slice(e,i-e+1)}t=l(t).substr(1),e=l(e).substr(1);for(var s=i(t.split("/")),n=i(e.split("/")),r=Math.min(s.length,n.length),a=r,o=0;o<r;o++)if(s[o]!==n[o]){a=o;break}var h=[];for(o=a;o<s.length;o++)h.push("..");return(h=h.concat(n.slice(a))).join("/")}function d(t){var e=h(t),i=e[0],s=e[1];return i||s?(s&&(s=s.substr(0,s.length-1)),i+s):"."}function f(t,e){var i=h(t)[2];return e&&i.substr(-1*e.length)===e&&(i=i.substr(0,i.length-e.length)),i}function m(t){return h(t)[3]}var y={extname:m,basename:f,dirname:d,sep:"/",delimiter:":",relative:_,join:p,isAbsolute:u,normalize:c,resolve:l};function g(t,e){if(t.filter)return t.filter(e);for(var i=[],s=0;s<t.length;s++)e(t[s],s,t)&&i.push(t[s]);return i}var v,x="b"==="ab".substr(-1)?function(t,e,i){return t.substr(e,i)}:function(t,e,i){return e<0&&(e=t.length+e),t.substr(e,i)},b=s(Object.freeze({__proto__:null,basename:f,default:y,delimiter:":",dirname:d,extname:m,isAbsolute:u,join:p,normalize:c,relative:_,resolve:l,sep:"/"}));v=n,function(){var t=Math.abs,e=Math.floor,i=Math.sin,s=Math.cos,n=Math.tan,a=Math.asin,o=Math.acos,h=Math.atan,l=Math.atan2,c=Math.sqrt,u=Math.pow,p=Math.exp,_=Math.log,d=Math.hypot,f=Math.sinh,m=Math.cosh,y=Math.min,g=Math.max,x=1/0,w=Math.PI,S=57.29577951308232,C=.017453292519943295,A=6378137,E=.0066943799901413165,M=w/4,k=w/2,I=1.5*w,D=2*w,P=2/w,T=-45,L=-47,F=1e-10,N={last_errno:0,debug_level:0,logger:null},R=["no arguments in initialization list","no options found in 'init' file","invalid init= string","projection not named","unknown projection id","effective eccentricity = 1","unknown unit conversion id","invalid boolean param argument","unknown elliptical parameter name","reciprocal flattening (1/f) = 0","|radius reference latitude| > 90","squared eccentricity < 0","major axis or radius = 0 or not given","latitude or longitude exceeded limits","invalid x or y","improperly formed DMS value","non-convergent inverse meridional dist","non-convergent inverse phi2","acos/asin: |arg| >1+1e-14","tolerance condition error","conic lat_1 = -lat_2","lat_1 >= 90","lat_1 = 0","lat_ts >= 90","no distance between control points","projection not selected to be rotated","W <= 0 or M <= 0","lsat not in 1-5 range","path not in range","h <= 0","k <= 0","lat_0 = 0 or 90 or alpha = 90","lat_1=lat_2 or lat_1=0 or lat_2=90","elliptical usage required","invalid UTM zone number","arg(s) out of range for Tcheby eval","failed to find projection to be rotated","failed to load datum shift file","both n & m must be spec'd and > 0","n <= 0, n > 1 or not specified","lat_1 or lat_2 not specified","|lat_1| == |lat_2|","lat_0 is pi/2 from mean lat","unparseable coordinate system definition","geocentric transformation missing z or ellps","unknown prime meridian conversion id","illegal axis orientation combination","point not within available datum shift grids","invalid sweep axis, choose x or y","invalid value for h","point outside of projection domain"];function O(){var t=N.last_errno;t&&(t>0||!function(t){return G.indexOf(t)>-1}(t))&&U(t)}var G=[-14,-15,-17,-18,-19,-20,-27,-48];function z(t){N.last_errno=t}function q(){z(-20)}function j(){z(-20)}function B(t){U(t)}function U(t){z(t),$()}function $(t,e){var i;throw e||(e={}),e.code||(e.code=N.last_errno||0),t||(i=e.code,t=R[~i]||"unknown error"),N.last_errno=0,new V(t,e)}function V(t,e){var i=new Error(t);return i.name="ProjError",Object.keys(e).forEach(function(t){i[t]=e[t]}),i}function W(t){return H(t)*C}function H(t){var e=/(-?[0-9.]+)d?([0-9.]*)'?([0-9.]*)"?([nsew]?)$/i.exec(t),i=NaN;return e&&(i=+(e[1]||"0")+ +(e[2]||"0")/60+ +(e[3]||"0")/3600,/[ws]/i.test(e[4])&&(i=-i)),isNaN(i)&&U(-16),i}function K(t){return Z(t)}function Z(t){return parseFloat(t)}function X(t,e){var i,s,n=e[0],r=t[e.substr(1)],a=void 0!==r;return"t"==n?i=a:a?(s=r.param,r.used=!0,"i"==n?i=parseInt(s):"d"==n?i=K(s):"r"==n?i=W(s):"s"==n?i=String(s):"b"==n&&("T"==s||"t"==s||!0===s?i=!0:("F"==s||"f"==s||z(-8),i=!1))):i={i:0,b:!1,d:0,r:0,s:""}[n],void 0===i&&$("invalid request to pj_param, fatal"),i}function J(t){for(var e,i=/\+([a-z][a-z0-9_]*(?:=[^\s]*)?)/gi,s={};e=i.exec(t);)Y(s,e[1]);return s}function Y(t,e){var i,s,n=e.split("=");1==n.length?(i=e,s=!0):(i=n[0],s=e.substr(n[0].length+1)),t[i]={used:!1,param:s}}var Q={};function tt(t,e,i,s){Q[e]={init:t,name:i,description:s}}function et(t){return!t||t.is_latlong}function it(t){var e=!1,i="";return"datum"in t.params?(e=!0,i+=nt(t,"datum")):"R"in t.params?i+=nt(t,"R"):"ellps"in t.params?i+=nt(t,"ellps"):"a"in t.params?(i+=nt(t,"a"),"b"in t.params?i+=nt(t,"b"):"es"in t.params?i+=nt(t,"es"):"f"in t.params?i+=nt(t,"f"):i+=" +es="+t.es):B(-13),e||(i+=nt(t,"towgs84"),i+=nt(t,"nadgrids")),i+=nt(t,"R_A"),i+=nt(t,"R_V"),i+=nt(t,"R_a"),i+=nt(t,"R_lat_a"),i+=nt(t,"R_lat_g"),i+=nt(t,"pm")}function st(t){var e="datum,ellps,a,b,es,rf,f,towgs84,nadgrids,R,R_A,R_V,R_a,R_lat_a,R_lat_g,pm,init,no_defs".split(","),i="";return Object.keys(t.params).forEach(function(s){-1==e.indexOf(s)&&(i+=nt(t,s))}),(i+=it(t)).trim()}function nt(t,e){var i="";return e in t.params&&(i=" +"+e,!0!==t.params[e].param&&(i+="="+X(t.params,"s"+e))),i}var rt=[["WGS84","towgs84=0,0,0","WGS84","WGS_1984"],["GGRS87","towgs84=-199.87,74.79,246.62","GRS80","Greek_Geodetic_Reference_System_1987"],["NAD83","towgs84=0,0,0","GRS80","North_American_Datum_1983"],["NAD27","nadgrids=@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat","clrk66","North_American_Datum_1927"],["potsdam","towgs84=598.1,73.7,418.2,0.202,0.045,-2.455,6.7","bessel","Potsdam Rauenberg 1950 DHDN"],["carthage","towgs84=-263.0,6.0,431.0","clrk80ign","Carthage 1934 Tunisia"],["hermannskogel","towgs84=577.326,90.129,463.919,5.137,1.474,5.297,2.4232","bessel","Hermannskogel"],["ire65","towgs84=482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15","mod_airy","Ireland 1965"],["nzgd49","towgs84=59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993","intl","New Zealand Geodetic Datum 1949"],["OSGB36","towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894","airy","OSGB 1936"],[null,null,null,null]],at=[["greenwich","0dE"],["lisbon","9d07'54.862\"W"],["paris","2d20'14.025\"E"],["bogota","74d04'51.3\"W"],["madrid","3d41'16.58\"W"],["rome","12d27'8.4\"E"],["bern","7d26'22.5\"E"],["jakarta","106d48'27.79\"E"],["ferro","17d40'W"],["brussels","4d22'4.71\"E"],["stockholm","18d3'29.8\"E"],["athens","23d42'58.815\"E"],["oslo","10d43'22.5\"E"],[null,null]];function ot(t){var e=rt.reduce(function(e,i){return i[0]===t?i:e},null);return e?{id:e[0],defn:e[1],ellipse_id:e[2],name:e[3]}:null}var ht=[["MERIT","a=6378137.0","rf=298.257","MERIT 1983"],["SGS85","a=6378136.0","rf=298.257","Soviet Geodetic System 85"],["GRS80","a=6378137.0","rf=298.257222101","GRS 1980(IUGG, 1980)"],["IAU76","a=6378140.0","rf=298.257","IAU 1976"],["airy","a=6377563.396","b=6356256.910","Airy 1830"],["APL4.9","a=6378137.0","rf=298.25","Appl. Physics. 1965"],["NWL9D","a=6378145.0","rf=298.25","Naval Weapons Lab., 1965"],["mod_airy","a=6377340.189","b=6356034.446","Modified Airy"],["andrae","a=6377104.43","rf=300.0","Andrae 1876 (Den., Iclnd.)"],["aust_SA","a=6378160.0","rf=298.25","Australian Natl & S. Amer. 1969"],["GRS67","a=6378160.0","rf=298.2471674270","GRS 67(IUGG 1967)"],["bessel","a=6377397.155","rf=299.1528128","Bessel 1841"],["bess_nam","a=6377483.865","rf=299.1528128","Bessel 1841 (Namibia)"],["clrk66","a=6378206.4","b=6356583.8","Clarke 1866"],["clrk80","a=6378249.145","rf=293.4663","Clarke 1880 mod."],["clrk80ign","a=6378249.2","rf=293.4660212936269","Clarke 1880 (IGN)."],["CPM","a=6375738.7","rf=334.29","Comm. des Poids et Mesures 1799"],["delmbr","a=6376428","rf=311.5","Delambre 1810 (Belgium)"],["engelis","a=6378136.05","rf=298.2566","Engelis 1985"],["evrst30","a=6377276.345","rf=300.8017","Everest 1830"],["evrst48","a=6377304.063","rf=300.8017","Everest 1948"],["evrst56","a=6377301.243","rf=300.8017","Everest 1956"],["evrst69","a=6377295.664","rf=300.8017","Everest 1969"],["evrstSS","a=6377298.556","rf=300.8017","Everest (Sabah & Sarawak)"],["fschr60","a=6378166","rf=298.3","Fischer (Mercury Datum) 1960"],["fschr60m","a=6378155","rf=298.3","Modified Fischer 1960"],["fschr68","a=6378150","rf=298.3","Fischer 1968"],["helmert","a=6378200","rf=298.3","Helmert 1906"],["hough","a=6378270.0","rf=297","Hough"],["intl","a=6378388.0","rf=297","International 1909 (Hayford)"],["krass","a=6378245.0","rf=298.3","Krasovsky 1940"],["kaula","a=6378163","rf=298.24","Kaula 1961"],["lerch","a=6378139","rf=298.257","Lerch 1979"],["mprts","a=6397300","rf=191","Maupertius 1738"],["new_intl","a=6378157.5","b=6356772.2","New International 1967"],["plessis","a=6376523","b=6355863","Plessis 1817 (France)"],["SEasia","a=6378155.0","b=6356773.3205","Southeast Asia"],["walbeck","a=6376896.0","b=6355834.8467","Walbeck"],["WGS60","a=6378165.0","rf=298.3","WGS 60"],["WGS66","a=6378145.0","rf=298.25","WGS 66"],["WGS72","a=6378135.0","rf=298.26","WGS 72"],["WGS84","a=6378137.0","rf=298.257223563","WGS 84"],["sphere","a=6370997.0","b=6370997.0","Normal Sphere (r=6370997)"],[null,null,null,null]];function lt(t){var e=ht.reduce(function(e,i){return i[0]===t?i:e},null);return e?{id:e[0],major:e[1],ell:e[2],name:e[3]}:null}var ct=[["km","1000","Kilometer"],["m","1","Meter"],["dm","1/10","Decimeter"],["cm","1/100","Centimeter"],["mm","1/1000","Millimeter"],["kmi","1852.0","International Nautical Mile"],["in","0.0254","International Inch"],["ft","0.3048","International Foot"],["yd","0.9144","International Yard"],["mi","1609.344","International Statute Mile"],["fath","1.8288","International Fathom"],["ch","20.1168","International Chain"],["link","0.201168","International Link"],["us-in","1/39.37","U.S. Surveyor's Inch"],["us-ft","0.304800609601219","U.S. Surveyor's Foot"],["us-yd","0.914401828803658","U.S. Surveyor's Yard"],["us-ch","20.11684023368047","U.S. Surveyor's Chain"],["us-mi","1609.347218694437","U.S. Surveyor's Statute Mile"],["ind-yd","0.91439523","Indian Yard"],["ind-ft","0.30479841","Indian Foot"],["ind-ch","20.11669506","Indian Chain"],[null,null,null]];function ut(t){var e=ct.reduce(function(e,i){return t===i[0]?i:e},null);return e?{id:e[0],to_meter:e[1],name:e[2]}:null}var pt={},_t={};function dt(t){return _t[t]||null}function ft(t){var e,i,s,n,a,o,h,l,c=t.split(":"),u=c[0],p=c[1];return p&&u||B(-3),(e=dt(u=u.toLowerCase()))||(i=u,n=r,o=(a=b).join(a.dirname("/Users/zhang/code/emap/node_modules/mproj/dist"),"../nad"),h=a.join(o,i.toUpperCase()),l=a.join(o,i.toLowerCase()),n.existsSync(h)?s=n.readFileSync(h,"utf8"):n.existsSync(l)?s=n.readFileSync(l,"utf8"):$("unable to read from 'init' file named "+i),e=s,_t[u]=e),e?function(t,e){var i,s,n="",r="";return(i=t.indexOf("<"+e+">"))>-1&&((s=t.lastIndexOf("#",i))>-1&&(r=t.substring(s+1,i).trim(),/\n/.test(r)&&(r="")),n=(n=(n=" "+(n=(n=(n=(n=(n=t.substr(i+e.length+2)).substr(0,n.indexOf("<"))).replace(/#.*/g,"")).replace(/[\s]+/g," ")).replace(/\+title=[^+]*[^ +]/g,function(t){return t.replace(/ /g,"\t")}))).replace(/ (?=[a-z])/gi," +")).replace(/\t/g," ").trim()),n?{opts:n,comment:r}:null}(e,p):null}function mt(e){var s,n,r=J(e),a={params:r,is_latlong:!1,is_geocent:!1,is_long_wrap_set:!1,long_wrap_center:0,axis:"enu",gridlist:null,gridlist_count:0,vgridlist_geoid:null,vgridlist_geoid_count:0};return Object.keys(r).length||B(-1),X(r,"tinit")&&function(t,e){var i=pt[e.toLowerCase()]||null;i||function(t,e){pt[t.toLowerCase()]=e}(e,i=ft(e)),i||B(-2),yt(t,i.opts)}(r,X(r,"sinit")),(s=X(r,"sproj"))||B(-4),(n=Q[s])||B(-5),X(r,"bno_defs")||function(t){yt(t,"+ellps=WGS84")}(a.params),function(t){var e,i,s,n,r=484813681109536e-20,a=t.datum_params=[0,0,0,0,0,0,0];t.datum_type=0,(e=X(t.params,"sdatum"))&&((i=ot(e))||B(-9),i.ellipse_id&&Y(t.params,"ellps="+i.ellipse_id),i.defn&&Y(t.params,i.defn)),(s=X(t.params,"snadgrids"))&&"@null"!=s&&$("+nadgrids is not implemented"),X(t.params,"scatalog")&&$("+catalog is not implemented"),(n=X(t.params,"stowgs84"))&&(n.split(",").forEach(function(t,e){a[e]=K(t)||0}),0!=a[3]||0!=a[4]||0!=a[5]||0!=a[6]?(t.datum_type=2,a[3]*=r,a[4]*=r,a[5]*=r,a[6]=a[6]/1e6+1):t.datum_type=1)}(a),function(e){var s,n,r,a,o,h=.16666666666666666,l=e.params,u=0,p=0;X(l,"tR")?u=X(l,"dR"):((s=X(l,"sellps"))&&((n=lt(s))||B(-9),Y(l,n.major),Y(l,n.ell)),u=X(l,"da"),X(l,"tes")?p=X(l,"des"):X(l,"te")?p=(r=X(l,"de"))*r:X(l,"trf")?((r=X(l,"drf"))||B(-10),p=(r=1/r)*(2-r)):X(l,"tf")?p=(r=X(l,"df"))*(2-r):X(l,"tb")&&(p=1-(a=X(l,"db"))*a/(u*u)),a||(a=u*c(1-p)),X(l,"bR_A")?(u*=1-p*(h+p*(.04722222222222222+.022156084656084655*p)),p=0):X(l,"bR_V")?u*=1-p*(h+p*(.06944444444444445+.04243827160493827*p)):X(l,"bR_a")?(u=.5*(u+a),p=0):X(l,"bR_g")?(u=c(u*a),p=0):X(l,"bR_h")?(u+a===0&&B(-20),u=2*u*a/(u+a),p=0):(o=X(l,"tR_lat_a")||X(l,"tR_lat_g"))&&(r=i(X(l,o?"rR_lat_a":"rR_lat_g")),t(r)>k&&B(-11),r=1-p*r*r,u*=o?.5*(1-p+r)/(r*c(r)):c(1-p)/r,p=0)),p<0&&B(-12),u<=0&&B(-13),e.es=p,e.a=u}(a),a.a_orig=a.a,a.es_orig=a.es,a.e=c(a.es),a.ra=1/a.a,a.one_es=1-a.es,a.one_es||B(-6),a.rone_es=1/a.one_es,function(t){return 1==t.datum_type&&t.datum_params[0]==t.datum_params[1]==t.datum_params[2]===0&&6378137==t.a&&Math.abs(t.es-.00669437999)<5e-11}(a)&&(a.datum_type=4),a.geoc=!!a.es&&X(r,"bgeoc"),a.over=X(r,"bover"),a.has_geoid_vgrids=X(r,"tgeoidgrids"),a.has_geoid_vgrids&&X(r,"sgeoidgrids"),a.is_long_wrap_set=X(r,"tlon_wrap"),a.is_long_wrap_set&&(a.long_wrap_center=X(r,"rlon_wrap"),t(a.long_wrap_center)<10*D==0&&B(-14)),X(r,"saxis")&&function(t){var e="ewnsud",i=X(t.params,"saxis");3!=i.length&&B(L),-1!=e.indexOf(i[0])&&-1!=e.indexOf(i[1])&&-1!=e.indexOf(i[2])||B(L),t.axis=i}(a),a.lam0=X(r,"rlon_0"),a.phi0=X(r,"rlat_0"),a.x0=X(r,"dx_0"),a.y0=X(r,"dy_0"),X(r,"tk_0")?a.k0=X(r,"dk_0"):X(r,"tk")?a.k0=X(r,"dk"):a.k0=1,a.k0<=0&&B(-31),function(t){var e,i,s,n=t.params;(e=X(n,"sunits"))&&((s=ut(e))||B(-7),i=s.to_meter),i||(i=X(n,"sto_meter"))?(t.to_meter=gt(i),t.fr_meter=1/t.to_meter):t.to_meter=t.fr_meter=1,i=null,(e=X(n,"svunits"))&&((s=ut(e))||B(-7),i=s.to_meter),i||X(n,"svto_meter")?(t.vto_meter=gt(i),t.vfr_meter=1/t.vto_meter):(t.vto_meter=t.to_meter,t.vfr_meter=t.fr_meter)}(a),function(t){var e,i,s,n=t.params;(e=X(n,"spm"))?(i=function(t){var e=at.reduce(function(e,i){return i[0]===t?i:e},null);return e?{id:e[0],definition:e[1]}:null}(e),s=W(i?i.definition:e),isNaN(s)&&B(-46),t.from_greenwich=s):t.from_greenwich=0}(a),n.init(a),a}function yt(t,e){var i=J(e),s=["datum","ellps","a","b","rf","f"].reduce(function(e,i){return e||i in t},!1);Object.keys(i).forEach(function(e){e in t||"ellps"==e&&s||(t[e]=i[e])})}function gt(t){var e=t.split("/"),i=Z(e[0]);return e.length>1&&(i/=Z(e[1])),i}function vt(t,e){var i=0,s=t*t,n=e*e;return t<=0&&(i|=4),e<=0&&(i|=8),t<e&&(i|=16),i?null:{a:t,b:e,a2:s,b2:n,e2:(s-n)/s,ep2:(s-n)/n}}function xt(t,e,n,r,a){var o,h,l,u,p=0,_=n[e],d=r[e],f=a[e];return d<-k&&d>-1.001*k?d=-k:d>k&&d<1.001*k?d=k:(d<-k||d>k)&&(p|=1),p||(_>w&&(_-=2*w),h=i(d),u=s(d),l=h*h,o=t.a/c(1-t.e2*l),n[e]=(o+f)*u*s(_),r[e]=(o+f)*u*i(_),a[e]=(o*(1-t.e2)+f)*h),p}function bt(e,i,s,n,r){var a,o,u,p,_,d,f,m,y,g,v,x,b,w,S,C,A=1e-12,E=s[i],M=n[i],I=r[i];if(p=c(E*E+M*M),_=c(E*E+M*M+I*I),p/e.a<A){if(o=0,_/e.a<A)return s[i]=0,n[i]=k,r[i]=-e.b,0}else o=l(M,E);d=I/_,f=p/_,m=1/c(1-e.e2*(2-e.e2)*f*f),v=f*(1-e.e2)*m,x=d*m,C=0;do{C++,u=p*v+I*x-(y=e.a/c(1-e.e2*x*x))*(1-e.e2*x*x),g=e.e2*y/(y+u),S=(w=d*(m=1/c(1-g*(2-g)*f*f)))*v-(b=f*(1-g)*m)*x,v=b,x=w}while(S*S>1e-24&&C<30);a=h(w/t(b)),s[i]=o,n[i]=a,r[i]=u}function wt(t,e,i){var s=i.length>2,n=[i[0]],r=[i[1]],a=[s?i[2]:0];t.is_latlong&&(n[0]*=C,r[0]*=C),N.last_errno=0,St(t,e,n,r,a),(N.last_errno||n[0]==x)&&$(null,{point:i}),e.is_latlong&&(n[0]*=S,r[0]*=S),i[0]=n[0],i[1]=r[0],s&&(i[2]=a[0])}function St(t,e,i,s,n){var r,a,o=i.length,h={},l={};if("enu"!=t.axis&&Ct(t.axis,!1,i,s,n),1!=t.vto_meter&&n)for(r=0;r<o;r++)n[r]*=t.vto_meter;if(t.is_geocent){if(n||B(T),1!=t.to_meter)for(r=0;r<o;r++)i[r]!=x&&(i[r]*=t.to_meter,s[r]*=t.to_meter);At(t.a_orig,t.es_orig,i,s,n)}else if(!t.is_latlong)if(t.inv3d||t.inv||$("source projection not invertible"),t.inv3d)$("inverse 3d transformations not supported");else for(r=0;r<o;r++)l.x=i[r],l.y=s[r],a=It(l,t),i[r]=a.lam,s[r]=a.phi,O();if(0!==t.from_greenwich)for(r=0;r<o;r++)i[r]!=x&&(i[r]+=t.from_greenwich);if(t.has_geoid_vgrids&&n&&$("vgrid transformation not supported"),function(t,e,i,s,n){var r,a,o,h,l=i.length;0!=t.datum_type&&0!=e.datum_type&&(function(t,e){return t.datum_type==e.datum_type&&(!(t.a_orig!=e.a_orig||Math.abs(t.es_orig-e.es_orig)>5e-11)&&(1==t.datum_type?t.datum_params[0]==e.datum_params[0]&&t.datum_params[1]==e.datum_params[1]&&t.datum_params[2]==e.datum_params[2]:2==t.datum_type?t.datum_params[0]==e.datum_params[0]&&t.datum_params[1]==e.datum_params[1]&&t.datum_params[2]==e.datum_params[2]&&t.datum_params[3]==e.datum_params[3]&&t.datum_params[4]==e.datum_params[4]&&t.datum_params[5]==e.datum_params[5]&&t.datum_params[6]==e.datum_params[6]:3!=t.datum_type||X(t.params,"snadgrids")==X(e.params,"snadgrids")))}(t,e)||(r=t.a_orig,a=t.es_orig,o=e.a_orig,h=e.es_orig,n||(n=new Float64Array(l)),3==t.datum_type&&($("gridshift not implemented"),r=A,a=E),3==e.datum_type&&(o=A,h=E),a==h&&r==o&&1!=t.datum_type&&2!=t.datum_type&&1!=e.datum_type&&2!=e.datum_type||(Et(r,a,i,s,n),1!=t.datum_type&&2!=t.datum_type||function(t,e,i,s){var n,r,a,o,h,l,c,u,p=e.length,_=t.datum_params,d=_[0],f=_[1],m=_[2];if(1==t.datum_type)for(u=0;u<p;u++)e[u]!=x&&(e[u]+=d,i[u]+=f,s[u]+=m);else if(2==t.datum_type)for(o=_[3],h=_[4],l=_[5],c=_[6],u=0;u<p;u++)e[u]!=x&&(n=c*(e[u]-l*i[u]+h*s[u])+d,r=c*(l*e[u]+i[u]-o*s[u])+f,a=c*(-h*e[u]+o*i[u]+s[u])+m,e[u]=n,i[u]=r,s[u]=a)}(t,i,s,n),1!=e.datum_type&&2!=e.datum_type||function(t,e,i,s){var n,r,a,o,h,l,c,u,p=e.length,_=t.datum_params,d=_[0],f=_[1],m=_[2];if(1==t.datum_type)for(u=0;u<p;u++)e[u]!=x&&(e[u]-=d,i[u]-=f,s[u]-=m);else if(2==t.datum_type)for(o=_[3],h=_[4],l=_[5],c=_[6],u=0;u<p;u++)e[u]!=x&&(n=(e[u]-d)/c,r=(i[u]-f)/c,a=(s[u]-m)/c,e[u]=n+l*r-h*a,i[u]=-l*n+r+o*a,s[u]=h*n-o*r+a)}(e,i,s,n),At(o,h,i,s,n),3==e.datum_type&&pj_apply_gridshift_2(e,1,i,s,n))))}(t,e,i,s,n),e.has_geoid_vgrids&&n&&$("vgrid transformation not supported"),0!==e.from_greenwich)for(r=0;r<o;r++)i[r]!=x&&(i[r]-=e.from_greenwich);if(e.is_geocent){if(n||B(T),Et(e.a_orig,e.es_orig,i,s,n),1!=e.fr_meter)for(r=0;r<o;r++)i[r]!=x&&(i[r]*=e.fr_meter,s[r]*=e.fr_meter)}else if(e.is_latlong){if(e.is_latlong&&e.is_long_wrap_set)for(r=0;r<o;r++)if(i[r]!=x){for(;i[r]<e.long_wrap_center-w;)i[r]+=D;for(;i[r]>e.long_wrap_center+w;)i[r]-=D}}else if(e.fwd3d)$("3d transformation not supported");else for(r=0;r<o;r++)h.lam=i[r],h.phi=s[r],a=kt(h,e),i[r]=a.x,s[r]=a.y,O();if(1!=e.vto_meter&&n)for(r=0;r<o;r++)n[r]*=e.vfr_meter;return"enu"!=e.axis&&Ct(e.axis,!0,i,s,n),1==o?N.last_errno:0}function Ct(t,e,i,s,n){var r,a,o,h,l,c,u=i.length,p=0;if(e){for(o=0;o<u;o++)if(r=i[o],a=s[o],r!=x)for(n&&(p=n[o]),h=0;h<3;h++)if(2!=h||n)switch(c=0==h?i:1==h?s:n,t[h]){case"e":c[o]=r;break;case"w":c[o]=-r;break;case"n":c[o]=a;break;case"s":c[o]=-a;break;case"u":c[o]=p;break;case"d":c[o]=-p;break;default:B(L)}}else for(o=0;o<u;o++)if(r=i[o],a=s[o],r!=x)for(n&&(p=n[o]),h=0;h<3;h++)switch(l=0==h?r:1==h?a:p,t[h]){case"e":i[o]=l;break;case"w":i[o]=-l;break;case"n":s[o]=l;break;case"s":s[o]=-l;break;case"u":n&&(n[o]=l);break;case"d":n&&(n[o]=-l);break;default:B(L)}}function At(t,e,i,s,n){var r,a,o=i.length;for((a=vt(t,0==e?t:t*c(1-e)))||B(T),r=0;r<o;r++)i[r]!=x&&bt(a,r,i,s,n)}function Et(t,e,i,s,n){var r,a,o=i.length;for((a=vt(t,0===e?t:t*c(1-e)))||B(T),r=0;r<o;r++)i[r]!=x&&xt(a,r,i,s,n)&&(i[r]=s[r]=x)}function Mt(i){var s=6.283185307179586,n=3.141592653589793;return t(i)>3.14159265359&&(i+=n,i-=s*e(i/s),i-=n),i}function kt(e,i){var s={x:0,y:0},r=t(e.phi)-k;return r<=1e-12&&t(e.lam)<=10?(N.last_errno=0,t(r)<=1e-12?e.phi=e.phi<0?-k:k:i.geoc&&(e.phi=h(i.rone_es*n(e.phi))),e.lam-=i.lam0,i.over||(e.lam=Mt(e.lam)),i.fwd?(i.fwd(e,s),s.x=i.fr_meter*(i.a*s.x+i.x0),s.y=i.fr_meter*(i.a*s.y+i.y0)):s.x=s.y=x):z(-14),!N.last_errno&&isFinite(s.x)&&isFinite(s.y)||(s.x=s.y=x),s}function It(e,i){var s={lam:0,phi:0};return e.x<x&&e.y<x?(N.last_errno=0,i.inv?(e.x=(e.x*i.to_meter-i.x0)*i.ra,e.y=(e.y*i.to_meter-i.y0)*i.ra,i.inv(e,s),s.lam+=i.lam0,i.over||(s.lam=Mt(s.lam)),i.geoc&&t(t(s.phi)-k)>1e-12&&(s.phi=h(i.one_es*n(s.phi)))):s.lam=s.phi=x):z(-15),!N.last_errno&&isFinite(s.lam)&&isFinite(s.phi)||(s.lam=s.phi=x),s}function Dt(t,i,s,n){var r,a,o;for((t<0||t>=9)&&(t=3),r=1,o=0;o<t;o++)r*=10;return a=3600*r,function(o){var h,l,c,u,p="",_="",d="";return o===x||isNaN(o)?"":(o<0?(o=-o,(c=n||"")||(p="-")):c=s||"",l=(o=e(o*a+.5))/r%60,h=(o=e(o/(60*r)))%60,u=e(o/60)+"d",d=l.toFixed(t),d=(l=parseFloat(d))?(i?d:String(l))+'"':"",(l||h)&&2==(_=String(h)+"'").length&&i&&(_="0"+_),p+u+_+d+c)}}function Pt(t,e,i){var s,n,r,a,o,h;return"string"!=typeof t?Ti:("string"!=typeof e?(n="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs",r=t,s=e):(n=t,r=e,s=i),h=Tt(a=mt(n),o=mt(r)),s?h(s):{forward:h,inverse:Tt(o,a)})}function Tt(t,e){return function(i){var s=Array.isArray(i);return i=s?i.concat():[i.x,i.y],wt(t,e,i),s||(i={x:i[0],y:i[1]}),i}}function Lt(t){var e=t.proj in Q?Q[t.proj].name:"",i=st(t),s=Yt(t);return{PROJCS:{NAME:e?s.NAME+" / "+e:"unnamed",GEOGCS:s,PROJECTION:"custom_proj4",PARAMETER:[],UNIT:Wt(t),EXTENSION:["PROJ4",i+" +wktext"]}}}function Ft(t){var e=t.EXTENSION;return e&&"PROJ4"==e[0]?(e[1]||"").replace(" +wktext",""):null}Pt.WGS84="+proj=longlat +datum=WGS84",Pt.toPoint=function(t){var e={x:t[0],y:t[1]};return t.length>2&&(e.z=t[2]),t.length>3&&(e.m=t[3]),e};var Nt=[],Rt=[];function Ot(t){return"string"==typeof t}function Gt(t){var e=qt(t,Rt);return e||(e=function(t){return Ft(t)?Ft:null}(t)),e||$t("unsupported WKT definition: "+(t.NAME||"[unknown]")),e}function zt(t){var e=qt(t,Nt);return e||(e=Lt),e||$t("unsupported projection: "+function(t){return jt(t)||"[unknown]"}(t)),e}function qt(t,e){for(var i=0;i<e.length;i++)if((0,e[i][0])(t))return e[i][1];return null}function jt(t){return X(t.params,"sproj")}function Bt(t){return t.replace(/[-_ \/]+/g,"_").toLowerCase()}function Ut(t){var e;return Array.isArray(t)?e=t:t&&t.length>0&&(e=t.split(",")),e}function $t(t){throw new Error(t)}function Vt(t){return{to_meter:t.UNIT[1]}}function Wt(t){return["Meter",t.to_meter||1]}function Ht(t,e){var i,s,n=t.DATUM,r=n.SPHEROID,a=function(t){var e,i={northamerican1983:"NAD83",newzealand1949:"nzgd49"},s=Kt(t.NAME);if(s in i)return i[s];for(var n=0;n<rt.length&&Kt((e=rt[n])[3])!=s&&Kt(e[0])!=s;n++);return e?e[0]:null}(n),o=function(t){var e,i={international1924:"intl"},s=Kt(t[0]);if(s in i)return i[s];if(/^grs1980/.test(s))return"GRS80";if("sphere"==s)return null;for(var n=0;n<ht.length&&Kt((e=ht[n])[3])!=s&&Kt(e[0])!=s;n++);return e?e[0]:null}(r),h=e&&e.aux_sphere,l=r[1],c=r[2];return Zt(t.UNIT,"degree"),h?i="+a="+r[1]:a?i="+datum="+a:o?i="+ellps="+o:(i="+a="+l,c>0&&(i+=" +rf="+c)),!n.TOWGS84||h||a||(i+=" +towgs84="+n.TOWGS84.join(",")),((s=t.PRIMEM?t.PRIMEM[1]:0)>0||s<0)&&(i+=" +pm="+s),i}function Kt(t){return(t||"").replace(/^(GCS|D)_/i,"").replace(/[ _]/g,"").toLowerCase()}function Zt(t,e){t&&t[0].toLowerCase()!=e&&$t("unexpected geographic units: "+geogcs.UNIT[0])}function Xt(t){return function(){return"+proj="+t}}function Jt(t){return function(e){var i,s;return[t.PROJECTION(e),t.PARAMETER(e),t.GEOGCS?t.GEOGCS(e):Ht(e.GEOGCS),(i=Vt(e),s="",1!=i.to_meter&&(s="+to_meter="+i.to_meter),s),"+no_defs"].filter(function(t){return!!t}).join(" ")}}function Yt(t){return{NAME:ee(t),DATUM:Qt(t),PRIMEM:["Greenwich",0],UNIT:["degree",.017453292519943295]}}function Qt(t){var e={NAME:se(t),SPHEROID:te(t)},i=X(t.params,"stowgs84");return/[1-9]/.test(i)&&(e.TOWGS84=i),e}function te(t){var e;return e=X(t.params,"trf")?X(t.params,"drf"):t.es?1/(1-Math.sqrt(1-t.es)):0,[ie(t),t.a,e]}function ee(t){var e;return et(t)&&(e=he(t)),e||(e=ne(t),e=/^[a-z]+$/.test(e)?e[0].toUpperCase()+e.substr(1):e.toUpperCase()),e||"UNK"}function ie(t){var e=lt(function(t){var e=ne(t),i=e?ot(e):null;return(i?i.ellipse_id:X(t.params,"sellps"))||""}(t));return e?e.name:"Unknown ellipsoid"}function se(t){var e=ot(ne(t));return e&&e.name||"Unknown datum"}function ne(t){return X(t.params,"sdatum")}function re(t){return zt(t)(t)}function ae(t,e){return oe({PROJECTION:t,PARAMETER:Pe(e)})}function oe(t){return function(e){var i={GEOGCS:t.GEOGCS&&t.GEOGCS(e)||Yt(e),PROJECTION:Ot(t.PROJECTION)?t.PROJECTION:t.PROJECTION(e),PARAMETER:t.PARAMETER(e),UNIT:Wt(e)};return i.NAME=t.NAME&&t.NAME(e,i)||function(t,e){var i=he(t);return i||e.GEOGCS.NAME+" / "+e.PROJECTION}(e,i),{PROJCS:i}}}function he(t){var e;return X(t.params,"tinit")&&(e=ft(X(t.params,"sinit"))),e?e.comment:""}function le(t,e,i){var s=ue(e),n=function(t,e){return Jt({PROJECTION:Xt(t),PARAMETER:De(e)})}(t,i);_e(s,n)}function ce(t,e,i){de(pe(t),ae(e,i))}function ue(t){var e=Ut(t).map(Bt);return function(t){var i=t.PROJECTION[0];return e.indexOf(Bt(i))>-1}}function pe(t){return function(e){var i=jt(e);return i&&i==t}}function _e(t,e){"function"!=typeof t&&$t("Missing WKT parser test"),"function"!=typeof e&&$t("Missing WKT parse function"),Rt.push([t,e])}function de(t,e){"function"!=typeof t&&$t("Missing WKT maker test"),"function"!=typeof e&&$t("Missing WKT maker function"),Nt.push([t,e])}_e(function(t){return fe.test(Bt(t.NAME))},function(t){return Jt({PROJECTION:Xt("utm"),PARAMETER:function(t){var e=fe.exec(Bt(t.NAME)),i="+zone="+e[1];return"s"==e[2].toLowerCase()&&(i+=" +south"),i}})(t)}),_e(function(t){return me.test(Bt(t.NAME))},function(t){return Jt({PROJECTION:Xt("ups"),PARAMETER:function(t){var e=me.exec(Bt(t.NAME));return"south"==e[1].toLowerCase()?"+south":""}})(t)}),de(pe("utm"),function(t){return oe({NAME:ye,PROJECTION:function(){return"Transverse_Mercator"},PARAMETER:ve})(t)}),de(pe("ups"),function(t){return oe({NAME:ge,PROJECTION:function(){return"Polar_Stereographic"},PARAMETER:xe})(t)});var fe=/UTM_zone_([0-9]{1,2})(N|S)/i,me=/UPS_(North|South)/i;function ye(t,e){return e.GEOGCS.NAME+" / UTM zone "+X(t.params,"szone")+(X(t.params,"tsouth")?"S":"N")}function ge(t,e){return e.GEOGCS.NAME+" / UPS "+(X(t.params,"tsouth")?"South":"North")}function ve(t){return[["latitude_of_origin",0],["central_meridian",180*t.lam0/w],["scale_factor",t.k0],["false_easting",t.x0],["false_northing",t.y0]]}function xe(t){return[["latitude_of_origin",-90],["central_meridian",0],["scale_factor",.994],["false_easting",2e6],["false_northing",2e6]]}function be(t){return X(t.params,"tlat_ts")&&0!=X(t.params,"dlat_ts")}function we(t){return 0===t.es&&6378137==t.a}_e(ue("Mercator_2SP,Mercator_1SP,Mercator,Mercator_Auxiliary_Sphere"),Jt({GEOGCS:function(t){var e=function(t){return/(Web_Mercator|Pseudo_Mercator)/i.test(Bt(t.NAME))}(t)?{aux_sphere:!0}:null;return Ht(t.GEOGCS,e)},PROJECTION:Xt("merc"),PARAMETER:function(t){return De(function(t){var e=ke(t,"standard_parallel_1");return e&&0!=e[1]}(t)?"lat_ts,lat_0b":"lat_tsb,lat_ts")(t)}})),de(pe("merc"),oe({GEOGCS:function(t){return we(t)?Yt(mt("+proj=longlat +datum=WGS84")):null},PROJECTION:function(t){return be(t)?"Mercator_2SP":"Mercator_1SP"},PARAMETER:function(t){return Pe(be(t)?"lat_ts,lat_0b":"lat_tsb")(t)},NAME:function(t){return we(t)?"WGS 84 / Pseudo-Mercator":null}}));var Se=[["x_0","false_easting","m"],["y_0","false_northing","m"],["k_0","scale_factor","f"],["lat_0","latitude_of_center"],["lon_0","central_meridian"]],Ce={lat_0b:["lat_0","latitude_of_origin"],lat_0c:["lat_0",null],lat_0d:["lat_0","standard_parallel_1"],lat_1:["lat_1","standard_parallel_1"],lat_1b:["lat_1","latitude_of_point_1"],lat_1c:["lat_1","latitude_of_origin"],lat_2:["lat_2","standard_parallel_2"],lat_2b:["lat_2","latitude_of_point_2"],lat_ts:["lat_ts","standard_parallel_1"],lat_tsb:["lat_ts","latitude_of_origin"],lonc:["lonc","central_meridian"],lon_1:["lon_1","longitude_of_point_1"],lon_2:["lon_2","longitude_of_point_2"],alpha:["alpha","azimuth"],gamma:["gamma","rectified_grid_angle"],h:["h","height","f"]},Ae={longitude_of_center:"central_meridian",latitude_of_origin:"latitude_of_center",latitude_of_center:"latitude_of_origin",longitude_of_1st_point:"longitude_of_point_1",longitude_of_2nd_point:"longitude_of_point_2",latitude_of_1st_point:"latitude_of_point_1",latitude_of_2nd_point:"latitude_of_point_2",k:"k_0"};function Ee(t,e,i){for(var s=0;s<i.length;s++)if(i[s][e]===t)return i[s];return null}function Me(t,e,i){var s=null;return!(s=Ee(t=t.toLowerCase(),e,i))&&t in Ae&&(s=Ee(Ae[t],e,i)),s}function ke(t,e){for(var i,s=t.PARAMETER||[],n=0;n<s.length;n++)if(e===(i=s[n][0].toLowerCase())||e===Ae[i])return s[n];return null}function Ie(t){var e=null;return t&&(e=Ut(t).reduce(function(t,e){var i=Ce[e];return i||$t("missing parameter rule: "+e),t.push(i),t},[])),(e||[]).concat(Se)}function De(t){return function(e){var i=[],s=Ie(t),n=Vt(e);return(e.PARAMETER||[]).forEach(function(t){var e,r,a=Me(t[0],1,s);a?(e=function(t,e,i){var s=t[0];if("m"==t[2]&&(e*=i.to_meter),!("x_0,y_0,lat_0,lon_0".indexOf(s)>-1&&0===e||"k_0"==s&&1==e))return"+"+s+"="+e}(a,t[1],n),e&&i.push(e)):(r="unhandled parameter: "+t[0],console.error("[wkt] "+r))}),i.join(" ")}}function Pe(t){return function(e){var i=[],s=Ie(t);return Object.keys(e.params).forEach(function(t){var n,r=Me(t,0,s);r&&r[1]&&(n=X(e.params,"s"+t),i.push(function(t,e,i){var s,n=t[2];return s="m"==n?parseFloat(e)/i:"f"==n?parseFloat(e):H(e),[t[1],s]}(r,n,e.to_meter)))}),i}}function Te(t){return!("lat_1"in t.params&&"lat_2"in t.params)}function Le(t){return"omerc"==jt(t)&&("alpha"in t.params||"gamma"in t.params)}function Fe(t){return Le(t)&&("no_uoff"in t.params||"no_off"in t.params)}function Ne(t){return X(t.params,"tlat_ts")}function Re(t){var e=JSON.stringify(Ge(t));return e=(e=e.replace(/\["([A-Z0-9]+)",/g,"$1[")).replace(/"(EAST|NORTH|SOUTH|WEST)"/g,"$1")}function Oe(t){return"NAME,PROJCS,GEOGCS,GEOCCS,DATUM,SPHEROID,PRIMEM,PROJECTION,PARAMETER,UNIT,AXIS".indexOf(t)+1||999}function Ge(t,e){var i,s=[];return e=e||0,function(t){return Object.keys(t).sort(function(t,e){return Oe(t)-Oe(e)})}(t).forEach(function(n){var r=t[n];!function(t){return!!t&&"object"==typeof t&&!Array.isArray(t)}(r)?"NAME"==n?s.push(Ot(r)?r:r[0]):"PARAMETER"==n||"AXIS"==n?r.forEach(function(t){s.push([n].concat(t))}):Ot(r)?s.push([n,r]):Array.isArray(r)?s.push([n].concat(r)):((i={})[n]=r,$t("Incorrectly formatted WKT element: "+JSON.stringify(i))):s.push([n].concat(Ge(r,e+1)))}),0===e&&1==s.length&&(s=s[0]),s}function ze(t){var e={};return qe(t).forEach(function(t){Be(t,e)}),e}function qe(t){var e;t="["+(t=(t=(t=je(t)).replace(/([A-Z0-9]+)\[(?![^"]*[^\[,"]")/g,'["$1",')).replace(/, *([a-zA-Z]+) *(?=[,\]])/g,',"$1"'))+"]";try{e=JSON.parse(t)}catch(t){$t("unparsable WKT format")}return e}function je(t){var e=0;return t.replace(/"+/g,function(t){var i=e%2==0;return e+=t.length,'"'==t||'""'==t&&i?t:i?'"'+t.substring(1).replace(/""/g,'\\"'):t.replace(/""/g,'\\"')})}function Be(t,e){var i,s=t[0];if("GEOGCS"==s||"GEOCCS"==s||"PROJCS"==s||"DATUM"==s||"VERTCS"==s)for(e[s]={NAME:t[1]},i=2;i<t.length;i++){if(!Array.isArray(t[i]))throw $t("WKT parse error");Be(t[i],e[s])}else"AXIS"==s||"PARAMETER"==s?(s in e==0&&(e[s]=[]),e[s].push(t.slice(1))):e[s]=t.slice(1);return e}_e(ue("Lambert_Conformal_Conic,Lambert_Conformal_Conic_1SP,Lambert_Conformal_Conic_2SP"),Jt({PROJECTION:Xt("lcc"),PARAMETER:function(t){return De(function(t){return!ke(t,"standard_parallel_2")}(t)?"lat_1c":"lat_0b,lat_1,lat_2")(t)}})),de(pe("lcc"),oe({PROJECTION:function(t){return Te(t)?"Lambert_Conformal_Conic_1SP":"Lambert_Conformal_Conic_2SP"},PARAMETER:function(t){return Pe(Te(t)?"lat_1c,lat_0c":"lat_0b,lat_1,lat_2")(t)}})),_e(ue("Hotine_Oblique_Mercator,Hotine_Oblique_Mercator_Azimuth_Natural_Origin"),Jt({PROJECTION:Xt("omerc"),PARAMETER:function(t){return De("alpha,gamma,lonc")(t)+" +no_uoff"}})),de(Fe,ae("Hotine_Oblique_Mercator","alpha,gamma,lonc")),le("omerc","Oblique_Mercator,Hotine_Oblique_Mercator_Azimuth_Center","alpha,gamma,lonc"),de(function(t){return Le(t)&&!Fe(t)},ae("Oblique_Mercator","alpha,gamma,lonc")),le("omerc","Hotine_Oblique_Mercator_Two_Point_Natural_Origin","lat_1b,lat_2b,lon_1,lon_2"),de(function(t){return"omerc"==jt(t)&&"lat_2"in t.params&&"lon_2"in t.params},ae("Hotine_Oblique_Mercator_Two_Point_Natural_Origin","lat_1b,lat_2b,lon_1,lon_2")),_e(ue("Stereographic,Polar_Stereographic,Stereographic_North_Pole,Stereographic_South_Pole"),Jt({PROJECTION:Xt("stere"),PARAMETER:function(t){var e=De("lat_ts,lat_tsb")(t),i=/lat_ts=([^ ]+)/.exec(e);return i&&-1==e.indexOf("lat_0=")&&(e="+lat_0="+(parseFloat(i[1])<0?-90:90)+" "+e),e}})),de(pe("stere"),oe({PROJECTION:function(t){return Ne(t)?"Polar_Stereographic":"Stereographic"},PARAMETER:function(t){return Ne(t)?Pe("lat_tsb,lat_0c")(t):Pe("lat_0b")(t)}})),ce("vandg","VanDerGrinten"),_e(ue("VanDerGrinten,Van_der_Grinten_I"),Jt({PROJECTION:Xt("vandg"),PARAMETER:function(t){var e=De("")(t);return e&&(e+=" "),e+"+R_A"}})),[["aitoff","Aitoff","lat1"],["aea","Albers_Conic_Equal_Area,Albers","lat_1,lat_2"],["aeqd","Azimuthal_Equidistant"],["bonne","Bonne","lat_1"],["cass","Cassini_Soldner,Cassini"],["cea","Cylindrical_Equal_Area","lat_ts"],["eck1","Eckert_I"],["eck2","Eckert_II"],["eck3","Eckert_III"],["eck4","Eckert_IV"],["eck5","Eckert_V"],["eck6","Eckert_VI"],["eqdc","Equidistant_Conic","lat_1,lat_2"],["eqc","Plate_Carree,Equirectangular,Equidistant_Cylindrical","lat_ts"],["gall","Gall_Stereographic"],["gnom","Gnomonic"],["laea","Lambert_Azimuthal_Equal_Area"],["loxim","Loximuthal","lat_1"],["mill","Miller_Cylindrical"],["moll","Mollweide"],["nsper","Vertical_Near_Side_Perspective","h"],["nzmg","New_Zealand_Map_Grid","lat_0b"],["ortho","Orthographic","lat_0b"],["poly","Polyconic"],["robin","Robinson"],["sinu","Sinusoidal"],["sterea","Oblique_Stereographic,Double_Stereographic"],["tmerc","Transverse_Mercator,Gauss_Kruger","lat_0b"],["tpeqd","Two_Point_Equidistant","lat_1b,lat_2b,lon_1,lon_2"],["wag1","Wagner_I"],["wag2","Wagner_II"],["wag3","Wagner_III","lat_ts"],["wag4","Wagner_IV"],["wag5","Wagner_V"],["wag6","Wagner_VI"],["wag7","Wagner_VII"],["wink1","Winkel_I","lat_ts"],["wink2","Winkel_II"],["wintri","Winkel_Tripel","lat_1"]].forEach(function(t){var e=t[2]||null;le(t[0],t[1],e),ce(t[0],t[1].split(",")[0],e)});var Ue,$e,Ve={};function We(t,e,i){var s;return e>=1e-7?i*(t/(1-(s=e*t)*s)-.5/e*_((1-s)/(1+s))):t+t}function He(t,e,i){return e/c(1-i*t*t)}function Ke(e,n,r){var o,h,u,p,f,m,y,g,v,b,w,S,C,A;e.fwd=function(t,n){var r,a=t.lam;(r=u-(y?h*We(i(t.phi),e.e,e.one_es):f*i(t.phi)))<0&&q(),r=p*c(r),n.x=r*i(a*=h),n.y=m-r*s(a)},e.inv=function(n,r){var c=n.x,g=m-n.y,v=d(c,g);0!=v?(h<0&&(v=-v,c=-c,g=-g),r.phi=v/p,y?(r.phi=(u-r.phi*r.phi)/h,t(o-t(r.phi))>1e-7?(r.phi=function(e,n,r){var o,h,l,c,u,p,d=15,f=1e-7,m=1e-10;if(o=a(.5*e),n<f)return o;p=d;do{o+=u=.5*(c=1-(l=n*(h=i(o)))*l)*c/s(o)*(e/r-h/c+.5/n*_((1-l)/(1+l)))}while(t(u)>m&&--p);return p?o:x}(r.phi,e.e,e.one_es))==x&&j():r.phi=r.phi<0?-k:k):t(r.phi=(u-r.phi*r.phi)/f)<=1?r.phi=a(r.phi):r.phi=r.phi<0?-k:k,r.lam=l(c,g)/h):(r.lam=0,r.phi=h>0?k:-k)},t(n+r)<F&&U(-21),h=v=i(n),g=s(n),b=t(n-r)>=F,(y=e.es>0)?(Ze(e.es),A=He(v,g,e.es),C=We(v,e.e,e.one_es),b&&(S=He(v=i(r),g=s(r),e.es),w=We(v,e.e,e.one_es),h=(A*A-S*S)/(w-C)),o=1-.5*e.one_es*_((1-e.e)/(1+e.e))/e.e,m=(p=1/h)*c((u=A*A+h*C)-h*We(i(e.phi0),e.e,e.one_es))):(b&&(h=.5*(h+i(r))),m=(p=1/h)*c((u=g*g+(f=h+h)*v)-f*i(e.phi0)))}function Ze(t){var e,i=.046875,s=.01953125,n=.01068115234375,r=[];return r[0]=1-t*(.25+t*(i+t*(s+t*n))),r[1]=t*(.75-t*(i+t*(s+t*n))),r[2]=(e=t*t)*(.46875-t*(.013020833333333334+.007120768229166667*t)),r[3]=(e*=t)*(.3645833333333333-.005696614583333333*t),r[4]=e*t*.3076171875,r}function Xe(t,e,i,s){return i*=e,e*=e,s[0]*t-i*(s[1]+e*(s[2]+e*(s[3]+e*s[4])))}function Je(e,n,r){var a,o,h,l=1/(1-n);h=e;for(var u=10;u>0;--u)if(o=1-n*(a=i(h))*a,h-=o=(Xe(h,a,s(h),r)-e)*(o*c(o))*l,t(o)<1e-11)return h;return z(N),h}function Ye(e){var i=t(e);return i>=1?(i>1.00000000000001&&z(-19),e<0?-k:k):a(e)}function Qe(e){var i=t(e);return i>=1?(i>1.00000000000001&&z(-19),e<0?w:0):o(e)}function ti(t){return t<=0?0:c(t)}function ei(e,i){return t(e)<1e-50&&t(i)<1e-50?0:l(e,i)}function ii(e){var n=e.opaque||{mode:0};e.inv=function(e,r){var a,h,l,c,p,_,d,f,m,y,g,v,x,b,S,C,A,E=1e-12,M=0;if(t(e.x)<E&&t(e.y)<E)return r.phi=0,void(r.lam=0);r.phi=e.y,r.lam=e.x;do{a=0;do{for(v=i(.5*r.lam),S=s(.5*r.lam),x=i(r.phi),l=1-(h=(b=s(r.phi))*S)*h,c=2*(h=o(h)/u(l,1.5))*l*b*v,p=h*l*x,_=2*(v*S*x*b/l-h*x*v),d=b*b*v*v/l+h*b*S*x*x,f=x*x*S/l+h*v*v*b,m=.5*(x*b*v/l-h*x*b*b*v*S),n.mode&&(c=.5*(c+r.lam*n.cosphi1),p=.5*(p+r.phi),_*=.5,d=.5*(d+n.cosphi1),f=.5*(f+1),m*=.5),c-=e.x,g=((p-=e.y)*_-c*f)/(y=_*m-f*d),y=(c*m-p*d)/y;g>w;)g-=w;for(;g<-w;)g+=w;r.phi-=y,r.lam-=g}while((t(y)>E||t(g)>E)&&a++<10);r.phi>k&&(r.phi-=2*(r.phi-k)),r.phi<-k&&(r.phi-=2*(r.phi+k)),t(t(r.phi)-k)<E&&!n.mode&&(r.lam=0),(h=o(s(r.phi)*s(l=.5*r.lam)))?(C=2*h*s(r.phi)*i(l)*(A=1/i(h)),A*=h*i(r.phi)):C=A=0,n.mode&&(C=.5*(C+r.lam*n.cosphi1),A=.5*(A+r.phi))}while((t(e.x-C)>E||t(e.y-A)>E)&&M++<20)},e.fwd=function(t,e){var r,a;(a=o(s(t.phi)*s(r=.5*t.lam)))?(e.x=2*a*s(t.phi)*i(r)*(e.y=1/i(a)),e.y*=a*i(t.phi)):e.x=e.y=0,n.mode&&(e.x=.5*(e.x+t.lam*n.cosphi1),e.y=.5*(e.y+t.phi))},e.es=0}function si(e,s,n){e.es=0,e.fwd=function(e,r){var a,o,h=2.4674011002723395;r.y=s?k*i(e.phi):e.phi,(a=t(e.lam))>=1e-10?(n&&a>=k?r.x=c(h-e.phi*e.phi+1e-10)+a-k:(o=.5*(h/a+a),r.x=a-o+c(o*o-r.y*r.y)),e.lam<0&&(r.x=-r.x)):r.x=0}}function ni(t){var e,i=[];return i[0]=.3333333333333333*t,e=t*t,i[0]+=.17222222222222222*e,i[1]=.06388888888888888*e,e*=t,i[0]+=.10257936507936508*e,i[1]+=.0664021164021164*e,i[2]=.01677689594356261*e,i}function ri(t,e){var s=t+t;return t+e[0]*i(s)+e[1]*i(s+s)+e[2]*i(s+s+s)}function ai(t,e){t.es=0,t.fwd=function(t,i){i.y=e.C_y*t.phi,i.x=e.C_x*t.lam*(e.A+ti(1-e.B*t.phi*t.phi))},t.inv=function(t,i){i.phi=t.y/e.C_y,i.lam=t.x/(e.C_x*(e.A+ti(1-e.B*i.phi*i.phi)))}}function oi(e){var r,a,o,u,p,y,g=[],v=[],b=[],w=[];function S(t,e){for(var n,r=2*s(2*e),a=t.length-1,o=t[a],h=0;--a>=0;)n=r*o-h+t[a],h=o,o=n;return e+n*i(2*e)}function C(t,e,n){for(var r,a,o=i(e),h=s(e),l=f(n),c=m(n),u=2*h*c,p=-2*o*l,_=t.length-1,d=t[_],y=0,g=0,v=0;--_>=0;)r=g,a=y,d=u*(g=d)-r-p*(y=v)+t[_],v=p*g-a+u*y;return[(u=o*c)*d-(p=h*l)*v,u*v+p*d]}e.es<=0&&U(-34),p=u=(o=e.es/(1+c(1-e.es)))/(2-o),g[0]=u*(2+u*(-2/3+u*(u*(116/45+u*(26/45+u*(-2854/675)))-2))),v[0]=u*(u*(2/3+u*(4/3+u*(-82/45+u*(32/45+u*(4642/4725)))))-2),p*=u,g[1]=p*(7/3+u*(u*(-227/45+u*(2704/315+u*(2323/945)))-1.6)),v[1]=p*(5/3+u*(-16/15+u*(-13/9+u*(904/315+u*(-1522/945))))),p*=u,g[2]=p*(56/15+u*(-136/35+u*(-1262/105+u*(73814/2835)))),v[2]=p*(-26/15+u*(34/21+u*(1.6+u*(-12686/2835)))),p*=u,g[3]=p*(4279/630+u*(-332/35+u*(-399572/14175))),v[3]=p*(1237/630+u*(u*(-24832/14175)-2.4)),p*=u,g[4]=p*(4174/315+u*(-144838/6237)),v[4]=p*(-734/315+u*(109598/31185)),p*=u,g[5]=p*(601676/22275),v[5]=p*(444337/155925),p=u*u,r=e.k0/(1+u)*(1+p*(1/4+p*(1/64+p/256))),b[0]=u*(u*(2/3+u*(-37/96+u*(1/360+u*(81/512+u*(-96199/604800)))))-.5),w[0]=u*(.5+u*(-2/3+u*(5/16+u*(41/180+u*(-127/288+u*(7891/37800)))))),b[1]=p*(-1/48+u*(-1/15+u*(437/1440+u*(-46/105+u*(1118711/3870720))))),w[1]=p*(13/48+u*(u*(557/1440+u*(281/630+u*(-1983433/1935360)))-.6)),p*=u,b[2]=p*(-17/480+u*(37/840+u*(209/4480+u*(-5569/90720)))),w[2]=p*(61/240+u*(-103/140+u*(15061/26880+u*(167603/181440)))),p*=u,b[3]=p*(-4397/161280+u*(11/504+u*(830251/7257600))),w[3]=p*(49561/161280+u*(-179/168+u*(6601661/7257600))),p*=u,b[4]=p*(-4583/161280+u*(108847/3991680)),w[4]=p*(34729/80640+u*(-3418889/1995840)),p*=u,b[5]=p*(-20648693/638668800),w[5]=.6650675310896665*p,y=S(v,e.phi0),a=-r*(y+function(t,e){for(var n,r=2*s(e),a=t.length-1,o=t[a],h=0;--a>=0;)n=r*o-h+t[a],h=o,o=n;return i(e)*n}(w,2*y)),e.fwd=function(e,o){var h,c,u,p,f,m=e.phi,y=e.lam;m=S(v,m),h=i(m),c=s(m),p=i(y),u=s(y),m=l(h,u*c),y=l(p*c,d(h,c*u)),y=function(e){var i=t(e);return i=function(t){var e=1+t,i=e-1;return 0===i?t:t*_(e)/i}(i*(1+i/(d(1,i)+1))),e<0?-i:i}(n(y)),f=C(w,2*m,2*y),m+=f[0],y+=f[1],t(y)<=2.623395162778?(o.y=r*m+a,o.x=r*y):o.x=o.y=x},e.inv=function(e,n){var o,c,u,p,_,m=e.y,y=e.x;m=(m-a)/r,t(y/=r)<=2.623395162778?(m+=(_=C(b,2*m,2*y))[0],y+=_[1],y=h(f(y)),o=i(m),c=s(m),p=i(y),u=s(y),y=l(p,u*c),m=l(o*u,d(p,u*c)),n.phi=S(g,m),n.lam=y):n.phi=n.lam=x}}function hi(e){var n;e.es?(n=Ze(e.es),e.fwd=function(t,r){var a,o;r.y=Xe(t.phi,a=i(t.phi),o=s(t.phi),n),r.x=t.lam*o/c(1-e.es*a*a)},e.inv=function(r,a){var o=t(a.phi=Je(r.y,e.es,n));o<k?(o=i(a.phi),a.lam=r.x*c(1-e.es*o*o)/s(a.phi)):o-F<k?a.lam=0:j()}):li(e,0,1)}function li(e,n,r){var a,o;a=(o=c((n+1)/r))/(n+1),e.es=0,e.fwd=function(e,h){var l,c,u;if(n){for(l=r*i(e.phi),u=8;u&&(e.phi-=c=(n*e.phi+i(e.phi)-l)/(n+s(e.phi)),!(t(c)<1e-7));--u);u||q()}else e.phi=1!=r?Ye(r*i(e.phi)):e.phi;h.x=a*e.lam*(n+s(e.phi)),h.y=o*e.phi},e.inv=function(t,e){t.y/=o,e.phi=n?Ye((n*t.y+i(t.y))/r):1!=r?Ye(i(t.y)/r):t.y,e.lam=t.x/(a*(n+s(t.y)))}}function ci(t){pi(t,ui(0,k))}function ui(t,e){var s=i(e),n=e+e,r=c(D*s/(n+i(n)));return{C_x:2*r/w,C_y:r/s,C_p:n+i(n)}}function pi(e,n){e.fwd=function(e,r){var a,o,h;for(a=n.C_p*i(e.phi),h=10;h&&(e.phi-=o=(e.phi+i(e.phi)-a)/(1+s(e.phi)),!(t(o)<1e-7));--h);h?e.phi*=.5:e.phi=e.phi<0?-k:k,r.x=n.C_x*e.lam*s(e.phi),r.y=n.C_y*i(e.phi)},e.inv=function(e,r){r.phi=Ye(e.y/n.C_y),r.lam=e.x/(n.C_x*s(r.phi)),t(r.lam)-w<F?(r.phi+=r.phi,r.phi=Ye((r.phi+i(r.phi))/n.C_p)):r.lam=r.phi=x},e.es=0}function _i(s,n){var r,o,h,l,p,_=[[0,-1],[1,0]],d=[[-1,0],[0,-1]],f=[[0,1],[-1,0]],m=[[[1,0],[0,1]],_,d,f,f,d,_],v=1e-15;function b(s,n){var r=s.lam,o=s.phi,h=a(2/3);if(t(o)<=h)n.x=r,n.y=3*w/8*i(o);else{var l,u=c(3*(1-t(i(o)))),p=e(2*r/w+2);p>=4&&(p=3),l=-3*M+k*p,n.x=l+(r-l)*u,n.y=C(o)*M*(2-u)}}function S(i,s){var n=i.x,r=i.y,o=M;if(t(r)<=o)s.lam=n,s.phi=a(8*r/(3*w));else if(t(r)<k){var h,l,c=e(2*n/w+2);c>=4&&(c=3),h=-3*M+k*c,l=2-4*t(r)/w,s.lam=h+(n-h)/l,s.phi=C(r)*a(1-u(l,2)/3)}else s.lam=-w,s.phi=C(r)*k}function C(t){return t>0?1:t<0?-1:0}function A(t){switch(t){case 0:return 0;case 1:return 1;case 2:return 2;case 3:return 3;case-1:return 4;case-2:return 5;case-3:return 6}return 0}function E(t,e){return function(t,e,i){var s,n,r,a,o,h=0,l=t.length;for(o=0;o<l;o++)if(e==t[o][0]&&i==t[o][1])return!0;for(s=t[0][0],n=t[0][1],o=1;o<l;o++)r=t[o%l][0],a=t[o%l][1],i>y(n,a)&&i<=g(n,a)&&e<=g(s,r)&&n!=a&&(s==r||e<=(i-n)*(r-s)/(a-n)+s)&&h++,s=r,n=a;return h%2!=0}(p,t,e)}function I(e,s,n){if(n)return ri(s,l);var r=We(i(s),e.e,1-e.es)/h;return t(r)>1&&(r=C(r)),a(r)}function D(t,e,i,s){var n,r,a,o,h,l,c=0,u=function(t,e,i,s,n){var r,a={};if(a.x=t,a.y=e,n){if(e>M)a.region="north",a.x=-3*M+i*k,a.y=k,t-=i*k;else{if(!(e<-M))return a.region="equatorial",a.cn=0,a;a.region="south",a.x=-3*M+s*k,a.y=-k,t-=s*k}"north"==a.region?a.cn=e>=-t-M-v&&e<t+5*M-v?(i+1)%4:e>-t-M+v&&e>=t+5*M-v?(i+2)%4:e<=-t-M+v&&e>t+5*M+v?(i+3)%4:i:"south"==a.region&&(a.cn=e<=t+M+v&&e>-t-5*M+v?(s+1)%4:e<t+M-v&&e<=-t-5*M+v?(s+2)%4:e>=t+M-v&&e<-t-5*M-v?(s+3)%4:s)}else{if(e>M)a.region="north",r=k;else{if(!(e<-M))return a.region="equatorial",a.cn=0,a;a.region="south",r=-k}t<-k?(a.cn=0,a.x=-3*M,a.y=r):t>=-k&&t<0?(a.cn=1,a.x=-M,a.y=r):t>=0&&t<k?(a.cn=2,a.x=M,a.y=r):(a.cn=3,a.x=3*M,a.y=r)}return a}(t.x,t.y,e,i,s);if("equatorial"==u.region)return t.x=u.x,void(t.y=u.y);n=[t.x,t.y],r=[u.x,u.y],s?"north"==u.region?(c=e,l=m[A(-1*(u.cn-c))]):(c=i,l=m[A(u.cn-c)]):"north"==u.region?(c=e,l=m[A(u.cn-c)]):(c=i,l=m[A(-1*(u.cn-c))]),o=function(t,e){return[t[0]-e[0],t[1]-e[1]]}(n,r),h=function(t,e){var i,s,n=[0,0];for(i=0;i<2;i++)for(s=0;s<2;s++)n[i]+=t[i][s]*e[s];return n}(l,o),a=function(t,e){return[t[0]+e[0],t[1]+e[1]]}(h,[-3*M+(s?u.cn:0)*k,k]),t.x=a[0],t.y=a[1]}n?(r=X(s.params,"inorth_square"),o=X(s.params,"isouth_square"),(r<0||r>3)&&U(-47),(o<0||o>3)&&U(-47),p=[[-w-v,M+v],[r*k-w-v,M+v],[r*k-w-v,3*M+v],[(r+1)*k-w+v,3*M+v],[(r+1)*k-w+v,M+v],[w+v,M+v],[w+v,-M-v],[(o+1)*k-w+v,-M-v],[(o+1)*k-w+v,-3*M-v],[o*k-w-v,-3*M-v],[o*k-w-v,-M-v],[-w-v,-M-v]],0!=s.es?(l=ni(s.es),h=We(1,s.e,s.one_es),s.a=s.a*c(.5*h),s.ra=1/s.a,s.fwd=function(t,e){return t.phi=I(s,t.phi,0),b(t,e),D(e,r,o,0)},s.inv=function(t,e){if(!E(t.x,t.y))return e.lam=x,e.phi=x,void z(-15);D(t,r,o,1),S(t,e),e.phi=I(s,e.phi,1)}):(s.fwd=function(t,e){b(t,e),D(e,r,o,0)},s.inv=function(t,e){if(!E(t.x,t.y))return e.lam=x,e.phi=x,void z(-15);D(t,r,o,1),S(t,e)})):(p=[[-w-v,M],[-3*M,k+v],[-k,M+v],[-M,k+v],[0,M+v],[M,k+v],[k,M+v],[3*M,k+v],[w+v,M],[w+v,-M],[3*M,-k-v],[k,-M-v],[M,-k-v],[0,-M-v],[-M,-k-v],[-k,-M-v],[-3*M,-k-v],[-w-v,-M]],0!=s.es?(l=ni(s.es),h=We(1,s.e,s.one_es),s.a=s.a*c(.5*h),s.ra=1/s.a,s.fwd=function(t,e){t.phi=I(s,t.phi,0),b(t,e)},s.inv=function(t,e){if(!E(t.x,t.y))return e.lam=x,e.phi=x,void z(-15);S(t,e),e.phi=I(s,e.phi,1)}):(s.fwd=function(t,e){b(t,e)},s.inv=function(t,e){if(!E(t.x,t.y))return e.lam=x,e.phi=x,void z(-15);S(t,e)}))}function di(t){t.x0=0,t.y0=0,t.is_latlong=!0,t.fwd=function(e,i){i.x=e.lam/t.a,i.y=e.phi/t.a},t.inv=function(e,i){i.lam=e.x*t.a,i.phi=e.y*t.a}}function fi(t,e,i){return e*=i,n(.5*(k-t))/u((1-e)/(1+e),.5*i)}function mi(e,s){var n,r,a=.5*s,o=k-2*h(e),l=15;do{n=s*i(o),o+=r=k-2*h(e*u((1-n)/(1+n),a))-o}while(t(r)>1e-10&&--l);return l<=0&&z(-18),o}function yi(t,e){var i,s,n,r=e.length-1;for(s=e[r][0],n=e[r][1];--r>=0;)i=s,s=e[r][0]+t.r*i-t.i*n,n=e[r][1]+t.r*n+t.i*i;return{r:t.r*s-t.i*n,i:t.r*n+t.i*s}}function gi(t,e,i){var s,n,r,a,o,h=!0,l=e.length-1;for(n=a=e[l][0],s=r=e[l][1];--l>=0;)h?h=!1:(a=n+t.r*(o=a)-t.i*r,r=s+t.r*r+t.i*o),n=e[l][0]+t.r*(o=n)-t.i*s,s=e[l][1]+t.r*s+t.i*o;return i.r=n+t.r*a-t.i*r,i.i=s+t.r*r+t.i*a,{r:t.r*n-t.i*s,i:t.r*s+t.i*n}}function vi(e,r){var a,o,c,p,_=1e-12;0!=e.es?(a=e.e*i(e.phi0),o=2*h(n(.5*(k+e.phi0))*u((1-a)/(1+a),.5*e.e))-k):o=e.phi0,p=i(o),c=s(o),e.inv=function(a,o){var f,m,y,g,v,b,w,S={},C={},A={},E=0,M=0,I=0,D=0;for(S.r=a.x,S.i=a.y,f=20;f&&((m=gi(S,r,C)).r-=a.x,m.i-=a.y,y=C.r*C.r+C.i*C.i,A.r=-(m.r*C.r+m.i*C.i)/y,A.i=-(m.i*C.r-m.r*C.i)/y,S.r+=A.r,S.i+=A.i,!(t(A.r)+t(A.i)<=_));--f);if(f){if(E=d(S.r,S.i),g=2*h(.5*E),M=i(g),I=s(g),o.lam=e.lam0,t(E)<=_)return o.lam=0,void(o.phi=e.phi0);for(D=v=Ye(I*p+S.i*M*c/E),f=20;f&&(b=e.e*i(D),D+=w=2*h(n(.5*(k+v))*u((1+b)/(1-b),.5*e.e))-k-D,!(t(w)<=_));--f);}f?(o.phi=D,o.lam=l(S.r*M,E*c*I-S.i*p*M)):o.lam=o.phi=x},e.fwd=function(t,a){var o,l,_,d,f,m,y,g={};o=i(t.lam),l=s(t.lam),_=e.e*i(t.phi),d=2*h(n(.5*(k+t.phi))*u((1-_)/(1+_),.5*e.e))-k,f=i(d),m=s(d),y=2/(1+p*f+c*m*l),g.r=y*m*o,g.i=y*(c*f-p*m*l),g=yi(g,r),a.x=g.r,a.y=g.i}}function xi(e,n,r,o){var h,u,p,_,f,m,y,g,v,x,b,w,S=!isNaN(r)&&!isNaN(o);n<=0&&U(-30),S&&(v=s(o),x=i(o),w=s(r),b=i(r)),t(t(e.phi0)-k)<F?h=e.phi0<0?1:0:t(e.phi0)<F?h=2:(h=3,u=i(e.phi0),p=s(e.phi0)),m=n/e.a,f=1/(_=1+m),y=(_+1)*(g=1/m),e.fwd=function(t,e){var n,r,a,o,l;switch(a=i(t.phi),r=s(t.phi),n=s(t.lam),h){case 3:e.y=u*a+p*r*n;break;case 2:e.y=r*n;break;case 1:e.y=-a;break;case 0:e.y=a}switch(e.y<f&&q(),e.y=m/(_-e.y),e.x=e.y*r*i(t.lam),h){case 3:e.y*=p*a-u*r*n;break;case 2:e.y*=a;break;case 0:n=-n;case 1:e.y*=r*n}S&&(l=1/((o=e.y*v+e.x*x)*b*g+w),e.x=(e.x*v-e.y*x)*w*l,e.y=o*l)},e.inv=function(s,n){var r,o,f,g,C,A;if(S&&(A=1/(m-s.y*b),g=m*s.x*A,C=m*s.y*w*A,s.x=g*v+C*x,s.y=C*v-g*x),r=d(s.x,s.y),(f=1-r*r*y)<0&&j(),f=(_-c(f))/(m/r+r/m),o=c(1-f*f),t(r)<=F)n.lam=0,n.phi=e.phi0;else{switch(h){case 3:n.phi=a(o*u+s.y*f*p/r),s.y=(o-u*i(n.phi))*r,s.x*=f*p;break;case 2:n.phi=a(s.y*f/r),s.y=o*r,s.x*=f;break;case 0:n.phi=a(o),s.y=-s.y;break;case 1:n.phi=-a(o)}n.lam=l(s.x,s.y)}},e.es=0}function bi(t,e){var i=.79788456,s=.1013211836*(e?2:4);t.es=0,t.fwd=function(t,e){e.x=i*t.lam*(1-s*t.phi*t.phi),e.y=i*t.phi},t.inv=function(t,e){e.phi=t.y/i,e.lam=t.x/(i*(1-s*e.phi*e.phi))}}function wi(t,e,n){t.es=0,t.fwd=function(t,r){t.phi=Ye(.883883476*i(t.phi)),r.x=e*t.lam*s(t.phi),r.x/=s(t.phi*=.333333333333333),r.y=n*i(t.phi)},t.inv=function(t,r){r.phi=Ye(t.y/n),r.lam=t.x*s(r.phi)/e,r.phi*=3,r.lam/=s(r.phi),r.phi=Ye(1.13137085*i(r.phi))}}function Si(t,e){var i=e?1.5:2,s=e?.5:1,n=1.01346,r=1.2158542;t.es=0,t.fwd=function(t,e){e.x=n*t.lam*(i-s*c(1+r*t.phi*t.phi)),e.y=n*t.phi},t.inv=function(t,e){e.phi=t.y/n,e.lam=t.x/(n*(i-s*c(1+r*e.phi*e.phi)))}}function Ci(e,s){var n,r,a,o,h,l=1.732050807568877;s?(a=.44329,o=.80404,n=6,r=5.61125,h=3):(a=1.01346,o=.9191,n=4,r=2.147143718212938,h=2),e.es=0,e.fwd=function(e,s){var u,p,d,f;for(u=r*i(e.phi),e.phi*=1.10265779,f=10;f&&(p=c(1+e.phi*e.phi),e.phi-=d=((n-p)*e.phi-_(e.phi+p)-u)/(n-2*p),!(t(d)<1e-10));--f);f||(e.phi=u<0?-l:l),s.x=a*e.lam*(h-c(1+e.phi*e.phi)),s.y=o*e.phi},e.inv=function(t,e){var i;e.phi=t.y/o,i=c(1+e.phi*e.phi),e.lam=t.x/(a*(h-i)),e.phi=Ye(((n-i)*e.phi-_(e.phi+i))/r)}}function Ai(e){return function(r){!function(e,r){var a,o,u,p,_,f,m,y,g,v,x=1e-10;switch(X(e.params,"tlat_1")&&X(e.params,"tlat_2")?(u=X(e.params,"rlat_1"),p=X(e.params,"rlat_2"),y=.5*(p+u),(t(a=.5*(p-u))<x||t(y)<x)&&U(-42)):U(-41),r){case"TISSOT":_=i(y),o=s(a),m=c(((f=_/o+o/_)-2*i(e.phi0))/_);break;case"MURD1":f=i(a)/(a*n(y))+y,m=f-e.phi0,_=i(y);break;case"MURD2":f=(o=c(s(a)))/n(y),m=f+n(y-e.phi0),_=i(y)*o;break;case"MURD3":f=a/(n(y)*n(a))+y,m=f-e.phi0,_=i(y)*i(a)*n(a)/(a*a);break;case"EULER":_=i(y)*i(a)/a,f=(a*=.5)/(n(a)*n(y))+y,m=f-e.phi0;break;case"PCONIC":_=i(y),v=s(a),g=1/n(y),t(a=e.phi0-y)-x>=k&&U(-43),m=v*(g-n(a));break;case"VITK1":_=(o=n(a))*i(y)/a,f=a/(o*n(y))+y,m=f-e.phi0}function b(t,e){var a;switch(r){case"MURD2":a=f+n(y-t.phi);break;case"PCONIC":a=v*(g-n(t.phi-y));break;default:a=f-t.phi}e.x=a*i(t.lam*=_),e.y=m-a*s(t.lam)}function w(t,e){var i;switch(i=d(t.x,t.y=m-t.y),_<0&&(i=-i,t.x=-t.x,t.y=-t.y),e.lam=l(t.x,t.y)/_,r){case"PCONIC":e.phi=h(g-i/v)+y;break;case"MURD2":e.phi=y-h(i-f);break;default:e.phi=f-i}}e.inv=w,e.fwd=b,e.es=0}(r,e)}}function Ei(e,r){var o,p,_,f,m,y,g,v,x=1e-10;if(v=t((p=t(e.phi0))-k)<x?e.phi0<0?0:1:p>x?2:3,r=t(r),e.es){switch(v){case 1:case 0:t(r-k)<x?g=2*e.k0/c(u(1+e.e,1+e.e)*u(1-e.e,1-e.e)):(g=s(r)/fi(r,p=i(r),e.e),p*=e.e,g/=c(1-p*p));break;case 3:case 2:p=i(e.phi0),o=2*h(b(e.phi0,p,e.e))-k,p*=e.e,g=2*e.k0*s(e.phi0)/c(1-p*p),m=i(o),y=s(o)}e.fwd=function(t,n){var r,a,o,l,c,u=0,p=0;switch(r=s(t.lam),a=i(t.lam),c=i(t.phi),(2==v||3==v)&&(u=i(o=2*h(b(t.phi,c,e.e))-k),p=s(o)),v){case 2:l=g/(y*(1+m*u+y*p*r)),n.y=l*(y*u-m*p*r),n.x=l*p;break;case 3:l=g/(1+p*r),n.y=l*u,n.x=l*p;break;case 0:t.phi=-t.phi,r=-r,c=-c;case 1:n.x=g*fi(t.phi,c,e.e),n.y=-n.x*r}n.x=n.x*a},e.inv=function(r,o){o.phi;var c,p,_,f,x=0,b=0,w=0,S=0;switch(_=d(r.x,r.y),v){case 2:case 3:c=s(x=2*l(_*y,g)),p=i(x),b=a(0==_?c*m:c*m+r.y*p*y/_),x=n(.5*(k+b)),r.x*=p,r.y=_*y*c-r.y*m*p,S=k,w=.5*e.e;break;case 1:r.y=-r.y;case 0:b=k-2*h(x=-_/g),S=-k,w=-.5*e.e}for(f=0;f<8;f++,b=o.phi)if(p=e.e*i(b),o.phi=2*h(x*u((1+p)/(1-p),w))-S,t(b-o.phi)<1e-10)return 0==v&&(o.phi=-o.phi),void(o.lam=0==r.x&&0==r.y?0:l(r.x,r.y));j()}}else{switch(v){case 2:_=i(e.phi0),f=s(e.phi0);case 3:g=2*e.k0;break;case 0:case 1:g=t(r-k)>=x?s(r)/n(M-.5*r):2*e.k0}e.fwd=function(e,r){var a=e.phi,o=i(a),h=s(a),l=s(e.lam),c=i(e.lam);switch(v){case 3:case 2:r.y=3==v?1+h*l:1+_*o+f*h*l,r.y<=x&&q(),r.x=(r.y=g/r.y)*h*c,r.y*=3==v?o:f*o-_*h*l;break;case 1:l=-l,a=-a;case 0:t(a-k)<1e-8&&q(),r.x=c*(r.y=g*n(M+.5*a)),r.y*=l}},e.inv=function(n,r){var o,c,u,p;switch(u=i(o=2*h((c=d(n.x,n.y))/g)),p=s(o),r.lam=0,v){case 3:t(c)<=x?r.phi=0:r.phi=a(n.y*u/c),0==p&&0==n.x||(r.lam=l(n.x*u,p*c));break;case 2:t(c)<=x?r.phi=e.phi0:r.phi=a(p*_+n.y*u*f/c),0==(o=p-_*i(r.phi))&&0==n.x||(r.lam=l(n.x*u*f,o*c));break;case 1:n.y=-n.y;case 0:t(c)<=x?r.phi=e.phi0:r.phi=a(0==v?-p:p),r.lam=0==n.x&&0==n.y?0:l(n.x,n.y)}}}function b(t,e,i){return e*=i,n(.5*(k+t))*u((1-e)/(1+e),.5*i)}}function Mi(t,e){return u((1-t)/(1+t),e)}function ki(t,e,r,a){var o=r/e,l=e,c=1/r;t.inv=function(t,e){var i;t.y/=l,i=s(e.phi=a?h(t.y):Ye(t.y)),e.phi/=c,e.lam=t.x/(o*s(e.phi)),a?e.lam/=i*i:e.lam*=i},t.fwd=function(t,e){var r;e.x=o*t.lam*s(t.phi),e.y=l,t.phi*=c,r=s(t.phi),a?(e.x*=r*r,e.y*=n(t.phi)):(e.x/=r,e.y*=i(t.phi))},t.es=0}function Ii(e){var n,r,h,u=1e-10,d=.5,f=.16666666666666666,m=.08333333333333333,y=.05,g=.03333333333333333,v=.023809523809523808,x=.017857142857142856;e.es?((h=Ze(e.es))||e_error_0(),r=Xe(e.phi0,i(e.phi0),s(e.phi0),h),n=e.es/(1-e.es),e.fwd=function(a,o){var l,p,_,d,b,w;a.lam<-k||a.lam>k?z(-14):(l=i(a.phi),p=s(a.phi),_=t(p)>u?l/p:0,_*=_,d=p*a.lam,b=d*d,d/=c(1-e.es*l*l),w=n*p*p,o.x=e.k0*d*(1+f*b*(1-_+w+y*b*(5+_*(_-18)+w*(14-58*_)+v*b*(61+_*(_*(179-_)-479))))),o.y=e.k0*(Xe(a.phi,l,p,h)-r+l*d*a.lam*.5*(1+m*b*(5-_+w*(9+4*w)+g*b*(61+_*(_-58)+w*(270-330*_)+x*b*(1385+_*(_*(543-_)-3111)))))))},e.inv=function(a,o){var l,u,p,_,b,w,S;o.phi=Je(r+a.y/e.k0,e.es,h),t(o.phi)>=k?(o.phi=a.y<0?-k:k,o.lam=0):(w=i(o.phi),p=s(o.phi),S=t(p)>1e-10?w/p:0,l=n*p*p,_=a.x*c(u=1-e.es*w*w)/e.k0,u*=S,S*=S,b=_*_,o.phi-=u*b/(1-e.es)*d*(1-b*m*(5+S*(3-9*l)+l*(1-4*l)-b*g*(61+S*(90-252*l+45*S)+46*l-b*x*(1385+S*(3633+S*(4095+1575*S)))))),o.lam=_*(1-b*f*(1+2*S+l-b*y*(5+S*(28+24*S+8*l)+6*l-b*v*(61+S*(662+S*(1320+720*S))))))/p)}):(n=e.k0,r=.5*n,e.fwd=function(a,h){var l,p;a.lam<-k||a.lam>k?z(-14):(p=s(a.phi),l=p*i(a.lam),t(t(l)-1)<=u&&q(),h.x=r*_((1+l)/(1-l)),h.y=p*s(a.lam)/c(1-l*l),(l=t(h.y))>=1?l-1>u?q():h.y=0:h.y=o(h.y),a.phi<0&&(h.y=-h.y),h.y=n*(h.y-e.phi0))},e.inv=function(t,i){var r=p(t.x/n),o=.5*(r-1/r);r=s(e.phi0+t.y/n),i.phi=a(c((1-r*r)/(1+o*o))),t.y<0&&-i.phi+e.phi0<0&&(i.phi=-i.phi),i.lam=o||r?l(o,r):0})}function Di(t,e){var n=.8773826753,r=1.139753528477/e;t.es=0,t.fwd=function(t,a){var o=Ye(e*i(t.phi));a.x=n*t.lam*s(o),a.y=r*o},t.inv=function(t,a){t.y/=r,a.phi=Ye(i(t.y)/e),a.lam=t.x/(n*s(t.y))}}function Pi(e,i){e.fwd=function(e,s){var n,r,a,o;a=t(P*e.phi),o=(o=1-a*a)<0?0:c(o),t(e.lam)<1e-10?(s.x=0,s.y=w*(e.phi<0?-a:a)/(1+o)):(r=.5*t(w/e.lam-e.lam/w),i?(n=a/(1+o),s.x=w*(c(r*r+1-n*n)-r),s.y=w*n):(n=(o*c(1+r*r)-r*o*o)/(1+r*r*a*a),s.x=w*n,s.y=w*c(1-n*(n+2*r)+1e-10)),e.lam<0&&(s.x=-s.x),e.phi<0&&(s.y=-s.y))},e.es=0}Ve.Constants={},Ve.Math={},Ve.Accumulator={},(Ue=Ve.Constants).WGS84={a:6378137,f:1/298.257223563},Ue.version={major:1,minor:48,patch:0},Ue.version_string="1.48",($e=Ve.Math).digits=53,$e.epsilon=Math.pow(.5,$e.digits-1),$e.degree=Math.PI/180,$e.sq=function(t){return t*t},$e.hypot=function(t,e){var i,s;return t=Math.abs(t),e=Math.abs(e),i=Math.max(t,e),s=Math.min(t,e)/(i||1),i*Math.sqrt(1+s*s)},$e.cbrt=function(t){var e=Math.pow(Math.abs(t),1/3);return t<0?-e:e},$e.log1p=function(t){var e=1+t,i=e-1;return 0===i?t:t*Math.log(e)/i},$e.atanh=function(t){var e=Math.abs(t);return e=$e.log1p(2*e/(1-e))/2,t<0?-e:e},$e.copysign=function(t,e){return Math.abs(t)*(e<0||0===e&&1/e<0?-1:1)},$e.sum=function(t,e){var i=t+e,s=i-e,n=i-s;return{s:i,t:-((s-=t)+(n-=e))}},$e.polyval=function(t,e,i,s){for(var n=t<0?0:e[i++];--t>=0;)n=n*s+e[i++];return n},$e.AngRound=function(t){if(0===t)return t;var e=1/16,i=Math.abs(t);return i=i<e?e-(e-i):i,t<0?-i:i},$e.AngNormalize=function(t){return(t%=360)<=-180?t+360:t<=180?t:t-360},$e.LatFix=function(t){return Math.abs(t)>90?Number.NaN:t},$e.AngDiff=function(t,e){var i=$e.sum($e.AngNormalize(-t),$e.AngNormalize(e)),s=$e.AngNormalize(i.s),n=i.t;return $e.sum(180===s&&n>0?-180:s,n)},$e.sincosd=function(t){var e,i,s,n,r,a;switch(e=t%360,e-=90*(i=Math.floor(e/90+.5)),e*=this.degree,s=Math.sin(e),n=Math.cos(e),3&i){case 0:r=s,a=n;break;case 1:r=n,a=-s;break;case 2:r=-s,a=-n;break;default:r=-n,a=s}return t&&(r+=0,a+=0),{s:r,c:a}},$e.atan2d=function(t,e){var i,s,n=0;switch(Math.abs(t)>Math.abs(e)&&(i=e,e=t,t=i,n=2),e<0&&(e=-e,++n),s=Math.atan2(t,e)/this.degree,n){case 1:s=(t>=0?180:-180)-s;break;case 2:s=90-s;break;case 3:s=-90+s}return s},function(t,e){t.Accumulator=function(t){this.Set(t)},t.Accumulator.prototype.Set=function(e){e||(e=0),e.constructor===t.Accumulator?(this._s=e._s,this._t=e._t):(this._s=e,this._t=0)},t.Accumulator.prototype.Add=function(t){var i=e.sum(t,this._t),s=e.sum(i.s,this._s);i=i.t,this._s=s.s,this._t=s.t,0===this._s?this._s=i:this._t+=i},t.Accumulator.prototype.Sum=function(e){var i;return e?((i=new t.Accumulator(this)).Add(e),i._s):this._s},t.Accumulator.prototype.Negate=function(){this._s*=-1,this._t*=-1}}(Ve.Accumulator,Ve.Math),Ve.Geodesic={},Ve.GeodesicLine={},Ve.PolygonArea={},function(t,e,i,s,n){var r,a,o,h,l,c,u,p,_,d,f,m=20+s.digits+10,y=s.epsilon,g=200*y,v=Math.sqrt(y),x=y*g,b=1e3*v;t.tiny_=Math.sqrt(Number.MIN_VALUE),t.nC1_=6,t.nC1p_=6,t.nC2_=6,t.nC3_=6,t.nC4_=6,r=t.nC3_*(t.nC3_-1)/2,a=t.nC4_*(t.nC4_+1)/2,t.CAP_C1=1,t.CAP_C1p=2,t.CAP_C2=4,t.CAP_C3=8,t.CAP_C4=16,t.NONE=0,t.ARC=64,t.LATITUDE=128,t.LONGITUDE=256|t.CAP_C3,t.AZIMUTH=512,t.DISTANCE=1024|t.CAP_C1,t.STANDARD=t.LATITUDE|t.LONGITUDE|t.AZIMUTH|t.DISTANCE,t.DISTANCE_IN=2048|t.CAP_C1|t.CAP_C1p,t.REDUCEDLENGTH=4096|t.CAP_C1|t.CAP_C2,t.GEODESICSCALE=8192|t.CAP_C1|t.CAP_C2,t.AREA=16384|t.CAP_C4,t.ALL=32671,t.LONG_UNROLL=32768,t.OUT_MASK=32640|t.LONG_UNROLL,t.SinCosSeries=function(t,e,i,s){var n=s.length,r=n-(t?1:0),a=2*(i-e)*(i+e),o=1&r?s[--n]:0,h=0;for(r=Math.floor(r/2);r--;)o=a*(h=a*o-h+s[--n])-o+s[--n];return t?2*e*i*o:i*(o-h)},o=function(t,e){var i,n,r,a,o,h,l,c,u,p,_,d,f=s.sq(t),m=s.sq(e),y=(f+m-1)/6;return 0===m&&y<=0?i=0:(h=y,(o=(n=f*m/4)*(n+2*(a=y*(r=s.sq(y)))))>=0?(l=n+a,l+=l<0?-Math.sqrt(o):Math.sqrt(o),h+=(c=s.cbrt(l))+(0!==c?r/c:0)):(u=Math.atan2(Math.sqrt(-o),-(n+a)),h+=2*y*Math.cos(u/3)),p=Math.sqrt(s.sq(h)+m),d=((_=h<0?m/(p-h):h+p)-m)/(2*p),i=_/(Math.sqrt(_+s.sq(d))+d)),i},h=[1,4,64,0,256],t.A1m1f=function(t){var e=Math.floor(3);return(s.polyval(e,h,0,s.sq(t))/h[e+1]+t)/(1-t)},l=[-1,6,-16,32,-9,64,-128,2048,9,-16,768,3,-5,512,-7,1280,-7,2048],t.C1f=function(e,i){var n,r,a=s.sq(e),o=e,h=0;for(n=1;n<=t.nC1_;++n)r=Math.floor((t.nC1_-n)/2),i[n]=o*s.polyval(r,l,h,a)/l[h+r+1],h+=r+2,o*=e},c=[205,-432,768,1536,4005,-4736,3840,12288,-225,116,384,-7173,2695,7680,3467,7680,38081,61440],t.C1pf=function(e,i){var n,r,a=s.sq(e),o=e,h=0;for(n=1;n<=t.nC1p_;++n)r=Math.floor((t.nC1p_-n)/2),i[n]=o*s.polyval(r,c,h,a)/c[h+r+1],h+=r+2,o*=e},u=[-11,-28,-192,0,256],t.A2m1f=function(t){var e=Math.floor(3);return(s.polyval(e,u,0,s.sq(t))/u[e+1]-t)/(1+t)},p=[1,2,16,32,35,64,384,2048,15,80,768,7,35,512,63,1280,77,2048],t.C2f=function(e,i){var n,r,a=s.sq(e),o=e,h=0;for(n=1;n<=t.nC2_;++n)r=Math.floor((t.nC2_-n)/2),i[n]=o*s.polyval(r,p,h,a)/p[h+r+1],h+=r+2,o*=e},t.Geodesic=function(t,e){if(this.a=t,this.f=e,this._f1=1-this.f,this._e2=this.f*(2-this.f),this._ep2=this._e2/s.sq(this._f1),this._n=this.f/(2-this.f),this._b=this.a*this._f1,this._c2=(s.sq(this.a)+s.sq(this._b)*(0===this._e2?1:(this._e2>0?s.atanh(Math.sqrt(this._e2)):Math.atan(Math.sqrt(-this._e2)))/Math.sqrt(Math.abs(this._e2))))/2,this._etol2=.1*v/Math.sqrt(Math.max(.001,Math.abs(this.f))*Math.min(1,1-this.f/2)/2),!(isFinite(this.a)&&this.a>0))throw new Error("Equatorial radius is not positive");if(!(isFinite(this._b)&&this._b>0))throw new Error("Polar semi-axis is not positive");this._A3x=new Array(6),this._C3x=new Array(r),this._C4x=new Array(a),this.A3coeff(),this.C3coeff(),this.C4coeff()},_=[-3,128,-2,-3,64,-1,-3,-1,16,3,-1,-2,8,1,-1,2,1,1],t.Geodesic.prototype.A3coeff=function(){var t,e,i=0,n=0;for(t=5;t>=0;--t)e=Math.min(6-t-1,t),this._A3x[n++]=s.polyval(e,_,i,this._n)/_[i+e+1],i+=e+2},d=[3,128,2,5,128,-1,3,3,64,-1,0,1,8,-1,1,4,5,256,1,3,128,-3,-2,3,64,1,-3,2,32,7,512,-10,9,384,5,-9,5,192,7,512,-14,7,512,21,2560],t.Geodesic.prototype.C3coeff=function(){var e,i,n,r=0,a=0;for(e=1;e<t.nC3_;++e)for(i=t.nC3_-1;i>=e;--i)n=Math.min(t.nC3_-i-1,i),this._C3x[a++]=s.polyval(n,d,r,this._n)/d[r+n+1],r+=n+2},f=[97,15015,1088,156,45045,-224,-4784,1573,45045,-10656,14144,-4576,-858,45045,64,624,-4576,6864,-3003,15015,100,208,572,3432,-12012,30030,45045,1,9009,-2944,468,135135,5792,1040,-1287,135135,5952,-11648,9152,-2574,135135,-64,-624,4576,-6864,3003,135135,8,10725,1856,-936,225225,-8448,4992,-1144,225225,-1440,4160,-4576,1716,225225,-136,63063,1024,-208,105105,3584,-3328,1144,315315,-128,135135,-2560,832,405405,128,99099],t.Geodesic.prototype.C4coeff=function(){var e,i,n,r=0,a=0;for(e=0;e<t.nC4_;++e)for(i=t.nC4_-1;i>=e;--i)n=t.nC4_-i-1,this._C4x[a++]=s.polyval(n,f,r,this._n)/f[r+n+1],r+=n+2},t.Geodesic.prototype.A3f=function(t){return s.polyval(5,this._A3x,0,t)},t.Geodesic.prototype.C3f=function(e,i){var n,r,a=1,o=0;for(n=1;n<t.nC3_;++n)r=t.nC3_-n-1,a*=e,i[n]=a*s.polyval(r,this._C3x,o,e),o+=r+1},t.Geodesic.prototype.C4f=function(e,i){var n,r,a=1,o=0;for(n=0;n<t.nC4_;++n)r=t.nC4_-n-1,i[n]=a*s.polyval(r,this._C4x,o,e),o+=r+1,a*=e},t.Geodesic.prototype.Lengths=function(e,i,s,n,r,a,o,h,l,c,u,p,_){var d,f,m,y,g={},v=0,x=0,b=0,w=0;if((u&=t.OUT_MASK)&(t.DISTANCE|t.REDUCEDLENGTH|t.GEODESICSCALE)&&(b=t.A1m1f(e),t.C1f(e,p),u&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(w=t.A2m1f(e),t.C2f(e,_),v=b-w,w=1+w),b=1+b),u&t.DISTANCE)d=t.SinCosSeries(!0,a,o,p)-t.SinCosSeries(!0,s,n,p),g.s12b=b*(i+d),u&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(x=v*i+(b*d-w*(t.SinCosSeries(!0,a,o,_)-t.SinCosSeries(!0,s,n,_))));else if(u&(t.REDUCEDLENGTH|t.GEODESICSCALE)){for(f=1;f<=t.nC2_;++f)_[f]=b*p[f]-w*_[f];x=v*i+(t.SinCosSeries(!0,a,o,_)-t.SinCosSeries(!0,s,n,_))}return u&t.REDUCEDLENGTH&&(g.m0=v,g.m12b=h*(n*a)-r*(s*o)-n*o*x),u&t.GEODESICSCALE&&(m=n*o+s*a,y=this._ep2*(l-c)*(l+c)/(r+h),g.M12=m+(y*a-o*x)*s/r,g.M21=m-(y*s-n*x)*a/h),g},t.Geodesic.prototype.InverseStart=function(e,i,n,r,a,h,l,c,u,p,_){var d,f,m,y,v,x,w,S,C,A,E,M,k,I,D,P,T,L,F,N,R={},O=r*i-a*e,G=a*i+r*e;return R.sig12=-1,d=r*i,d+=a*e,(f=G>=0&&O<.5&&a*l<.5)?(y=s.sq(e+r),y/=y+s.sq(i+a),R.dnm=Math.sqrt(1+this._ep2*y),m=l/(this._f1*R.dnm),v=Math.sin(m),x=Math.cos(m)):(v=c,x=u),R.salp1=a*v,R.calp1=x>=0?O+a*e*s.sq(v)/(1+x):d-a*e*s.sq(v)/(1-x),S=s.hypot(R.salp1,R.calp1),C=e*r+i*a*x,f&&S<this._etol2?(R.salp2=i*v,R.calp2=O-i*r*(x>=0?s.sq(v)/(1+x):1-x),w=s.hypot(R.salp2,R.calp2),R.salp2/=w,R.calp2/=w,R.sig12=Math.atan2(S,C)):Math.abs(this._n)>.1||C>=0||S>=6*Math.abs(this._n)*Math.PI*s.sq(i)||(N=Math.atan2(-c,-u),this.f>=0?(I=(k=s.sq(e)*this._ep2)/(2*(1+Math.sqrt(1+k))+k),A=N/(M=this.f*i*this.A3f(I)*Math.PI),E=d/(M*i)):(D=a*i-r*e,P=Math.atan2(d,D),E=l/(M=((A=(T=this.Lengths(this._n,Math.PI+P,e,-i,n,r,a,h,i,a,t.REDUCEDLENGTH,p,_)).m12b/(i*a*T.m0*Math.PI)-1)<-.01?d/A:-this.f*s.sq(i)*Math.PI)/i)),E>-g&&A>-1-b?this.f>=0?(R.salp1=Math.min(1,-A),R.calp1=-Math.sqrt(1-s.sq(R.salp1))):(R.calp1=Math.max(A>-g?0:-1,A),R.salp1=Math.sqrt(1-s.sq(R.calp1))):(L=o(A,E),F=M*(this.f>=0?-A*L/(1+L):-E*(1+L)/L),v=Math.sin(F),x=-Math.cos(F),R.salp1=a*v,R.calp1=d-a*e*s.sq(v)/(1-x))),R.salp1<=0?(R.salp1=1,R.calp1=0):(w=s.hypot(R.salp1,R.calp1),R.salp1/=w,R.calp1/=w),R},t.Geodesic.prototype.Lambda12=function(e,i,n,r,a,o,h,l,c,u,p,_,d,f){var m,y,g,v,x,b,w,S,C,A,E,M,k,I={};return 0===e&&0===l&&(l=-t.tiny_),y=h*i,g=s.hypot(l,h*e),I.ssig1=e,v=y*e,I.csig1=x=l*i,m=s.hypot(I.ssig1,I.csig1),I.ssig1/=m,I.csig1/=m,I.salp2=a!==i?y/a:h,I.calp2=a!==i||Math.abs(r)!==-e?Math.sqrt(s.sq(l*i)+(i<-e?(a-i)*(i+a):(e-r)*(e+r)))/a:Math.abs(l),I.ssig2=r,b=y*r,I.csig2=w=I.calp2*a,m=s.hypot(I.ssig2,I.csig2),I.ssig2/=m,I.csig2/=m,I.sig12=Math.atan2(Math.max(0,I.csig1*I.ssig2-I.ssig1*I.csig2),I.csig1*I.csig2+I.ssig1*I.ssig2),S=Math.max(0,x*b-v*w),C=x*w+v*b,E=Math.atan2(S*u-C*c,C*u+S*c),M=s.sq(g)*this._ep2,I.eps=M/(2*(1+Math.sqrt(1+M))+M),this.C3f(I.eps,f),A=t.SinCosSeries(!0,I.ssig2,I.csig2,f)-t.SinCosSeries(!0,I.ssig1,I.csig1,f),I.domg12=-this.f*this.A3f(I.eps)*y*(I.sig12+A),I.lam12=E+I.domg12,p&&(0===I.calp2?I.dlam12=-2*this._f1*n/e:(k=this.Lengths(I.eps,I.sig12,I.ssig1,I.csig1,n,I.ssig2,I.csig2,o,i,a,t.REDUCEDLENGTH,_,d),I.dlam12=k.m12b,I.dlam12*=this._f1/(I.calp2*a))),I},t.Geodesic.prototype.Inverse=function(e,i,n,r,a){var o,h;return a||(a=t.STANDARD),a===t.LONG_UNROLL&&(a|=t.STANDARD),a&=t.OUT_MASK,h=(o=this.InverseInt(e,i,n,r,a)).vals,a&t.AZIMUTH&&(h.azi1=s.atan2d(o.salp1,o.calp1),h.azi2=s.atan2d(o.salp2,o.calp2)),h},t.Geodesic.prototype.InverseInt=function(e,i,n,r,a){var o,h,l,c,u,p,_,d,f,g,v,b,w,S,C,A,E,M,k,I,D,P,T,L,F,N,R,O,G,z,q,j,B,U,$,V,W,H,K,Z,X,J,Y,Q,tt,et,it,st,nt,rt,at,ot,ht,lt,ct,ut,pt,_t,dt,ft,mt,yt,gt,vt,xt,bt={};if(bt.lat1=e=s.LatFix(e),bt.lat2=n=s.LatFix(n),e=s.AngRound(e),n=s.AngRound(n),h=(o=s.AngDiff(i,r)).t,o=o.s,a&t.LONG_UNROLL?(bt.lon1=i,bt.lon2=i+o+h):(bt.lon1=s.AngNormalize(i),bt.lon2=s.AngNormalize(r)),o=(l=o>=0?1:-1)*s.AngRound(o),h=s.AngRound(180-o-l*h),C=o*s.degree,A=(c=s.sincosd(o>90?h:o)).s,E=(o>90?-1:1)*c.c,(u=Math.abs(e)<Math.abs(n)?-1:1)<0&&(l*=-1,c=e,e=n,n=c),e*=p=e<0?1:-1,n*=p,c=s.sincosd(e),_=this._f1*c.s,d=c.c,_/=c=s.hypot(_,d),d/=c,d=Math.max(t.tiny_,d),c=s.sincosd(n),f=this._f1*c.s,g=c.c,f/=c=s.hypot(f,g),g/=c,g=Math.max(t.tiny_,g),d<-_?g===d&&(f=f<0?_:-_):Math.abs(f)===-_&&(g=d),w=Math.sqrt(1+this._ep2*s.sq(_)),S=Math.sqrt(1+this._ep2*s.sq(f)),T=new Array(t.nC1_+1),L=new Array(t.nC2_+1),F=new Array(t.nC3_),(N=-90===e||0===A)&&(I=A,P=0,O=_,G=(k=E)*d,z=f,q=(D=1)*g,M=Math.atan2(Math.max(0,G*z-O*q),G*q+O*z),v=(R=this.Lengths(this._n,M,O,G,w,z,q,S,d,g,a|t.DISTANCE|t.REDUCEDLENGTH,T,L)).s12b,b=R.m12b,0!==(a&t.GEODESICSCALE)&&(bt.M12=R.M12,bt.M21=R.M21),M<1||b>=0?(M<3*t.tiny_&&(M=b=v=0),b*=this._b,v*=this._b,bt.a12=M/s.degree):N=!1),pt=2,!N&&0===_&&(this.f<=0||h>=180*this.f))k=D=0,I=P=1,v=this.a*C,M=B=C/this._f1,b=this._b*Math.sin(M),a&t.GEODESICSCALE&&(bt.M12=bt.M21=Math.cos(M)),bt.a12=o/this._f1;else if(!N)if(M=(R=this.InverseStart(_,d,w,f,g,S,C,A,E,T,L)).sig12,I=R.salp1,k=R.calp1,M>=0)P=R.salp2,D=R.calp2,U=R.dnm,v=M*this._b*U,b=s.sq(U)*this._b*Math.sin(M/U),a&t.GEODESICSCALE&&(bt.M12=bt.M21=Math.cos(M/U)),bt.a12=M/s.degree,B=C/(this._f1*U);else{for($=0,V=t.tiny_,W=1,H=t.tiny_,K=-1,Z=!1,X=!1;$<m&&(J=(R=this.Lambda12(_,d,w,f,g,S,I,k,A,E,$<20,T,L,F)).lam12,P=R.salp2,D=R.calp2,M=R.sig12,O=R.ssig1,G=R.csig1,z=R.ssig2,q=R.csig2,j=R.eps,dt=R.domg12,Y=R.dlam12,!X&&Math.abs(J)>=(Z?8:1)*y);++$)J>0&&($<20||k/I>K/H)?(H=I,K=k):J<0&&($<20||k/I<W/V)&&(V=I,W=k),$<20&&Y>0&&(Q=-J/Y,tt=Math.sin(Q),(it=I*(et=Math.cos(Q))+k*tt)>0&&Math.abs(Q)<Math.PI)?(k=k*et-I*tt,I=it,I/=c=s.hypot(I,k),k/=c,Z=Math.abs(J)<=16*y):(I=(V+H)/2,k=(W+K)/2,I/=c=s.hypot(I,k),k/=c,Z=!1,X=Math.abs(V-I)+(W-k)<x||Math.abs(I-H)+(k-K)<x);st=a|(a&(t.REDUCEDLENGTH|t.GEODESICSCALE)?t.DISTANCE:t.NONE),v=(R=this.Lengths(j,M,O,G,w,z,q,S,d,g,st,T,L)).s12b,b=R.m12b,0!==(a&t.GEODESICSCALE)&&(bt.M12=R.M12,bt.M21=R.M21),b*=this._b,v*=this._b,bt.a12=M/s.degree,a&t.AREA&&(vt=Math.sin(dt),pt=A*(xt=Math.cos(dt))-E*vt,_t=E*xt+A*vt)}return a&t.DISTANCE&&(bt.s12=0+v),a&t.REDUCEDLENGTH&&(bt.m12=0+b),a&t.AREA&&(nt=I*d,0!==(rt=s.hypot(k,I*_))&&0!==nt?(O=_,G=k*d,z=f,q=D*g,j=(ot=s.sq(rt)*this._ep2)/(2*(1+Math.sqrt(1+ot))+ot),ht=s.sq(this.a)*rt*nt*this._e2,O/=c=s.hypot(O,G),G/=c,z/=c=s.hypot(z,q),q/=c,lt=new Array(t.nC4_),this.C4f(j,lt),ct=t.SinCosSeries(!1,O,G,lt),ut=t.SinCosSeries(!1,z,q,lt),bt.S12=ht*(ut-ct)):bt.S12=0,!N&&pt>1&&(pt=Math.sin(B),_t=Math.cos(B)),!N&&_t>-.7071&&f-_<1.75?(dt=1+_t,ft=1+d,mt=1+g,at=2*Math.atan2(pt*(_*mt+f*ft),dt*(_*f+ft*mt))):(gt=D*k+P*I,0===(yt=P*k-D*I)&><0&&(yt=t.tiny_*k,gt=-1),at=Math.atan2(yt,gt)),bt.S12+=this._c2*at,bt.S12*=u*l*p,bt.S12+=0),u<0&&(c=I,I=P,P=c,c=k,k=D,D=c,a&t.GEODESICSCALE&&(c=bt.M12,bt.M12=bt.M21,bt.M21=c)),{vals:bt,salp1:I*=u*l,calp1:k*=u*p,salp2:P*=u*l,calp2:D*=u*p}},t.Geodesic.prototype.GenDirect=function(i,s,n,r,a,o){return o?o===t.LONG_UNROLL&&(o|=t.STANDARD):o=t.STANDARD,r||(o|=t.DISTANCE_IN),new e.GeodesicLine(this,i,s,n,o).GenPosition(r,a,o)},t.Geodesic.prototype.Direct=function(t,e,i,s,n){return this.GenDirect(t,e,i,!1,s,n)},t.Geodesic.prototype.ArcDirect=function(t,e,i,s,n){return this.GenDirect(t,e,i,!0,s,n)},t.Geodesic.prototype.Line=function(t,i,s,n){return new e.GeodesicLine(this,t,i,s,n)},t.Geodesic.prototype.DirectLine=function(t,e,i,s,n){return this.GenDirectLine(t,e,i,!1,s,n)},t.Geodesic.prototype.ArcDirectLine=function(t,e,i,s,n){return this.GenDirectLine(t,e,i,!0,s,n)},t.Geodesic.prototype.GenDirectLine=function(i,s,n,r,a,o){var h;return o||(o=t.STANDARD|t.DISTANCE_IN),r||(o|=t.DISTANCE_IN),(h=new e.GeodesicLine(this,i,s,n,o)).GenSetDistance(r,a),h},t.Geodesic.prototype.InverseLine=function(i,n,r,a,o){var h,l,c;return o||(o=t.STANDARD|t.DISTANCE_IN),h=this.InverseInt(i,n,r,a,t.ARC),c=s.atan2d(h.salp1,h.calp1),o&t.OUT_MASK&t.DISTANCE_IN&&(o|=t.DISTANCE),(l=new e.GeodesicLine(this,i,n,c,o,h.salp1,h.calp1)).SetArc(h.vals.a12),l},t.Geodesic.prototype.Polygon=function(t){return new i.PolygonArea(this,t)},t.WGS84=new t.Geodesic(n.WGS84.a,n.WGS84.f)}(Ve.Geodesic,Ve.GeodesicLine,Ve.PolygonArea,Ve.Math,Ve.Constants),function(t,e,i){e.GeodesicLine=function(e,s,n,r,a,o,h){var l,c,u,p,_,d;a||(a=t.STANDARD|t.DISTANCE_IN),this.a=e.a,this.f=e.f,this._b=e._b,this._c2=e._c2,this._f1=e._f1,this.caps=a|t.LATITUDE|t.AZIMUTH|t.LONG_UNROLL,this.lat1=i.LatFix(s),this.lon1=n,void 0===o||void 0===h?(this.azi1=i.AngNormalize(r),l=i.sincosd(i.AngRound(this.azi1)),this.salp1=l.s,this.calp1=l.c):(this.azi1=r,this.salp1=o,this.calp1=h),l=i.sincosd(i.AngRound(this.lat1)),u=this._f1*l.s,c=l.c,u/=l=i.hypot(u,c),c/=l,c=Math.max(t.tiny_,c),this._dn1=Math.sqrt(1+e._ep2*i.sq(u)),this._salp0=this.salp1*c,this._calp0=i.hypot(this.calp1,this.salp1*u),this._ssig1=u,this._somg1=this._salp0*u,this._csig1=this._comg1=0!==u||0!==this.calp1?c*this.calp1:1,l=i.hypot(this._ssig1,this._csig1),this._ssig1/=l,this._csig1/=l,this._k2=i.sq(this._calp0)*e._ep2,p=this._k2/(2*(1+Math.sqrt(1+this._k2))+this._k2),this.caps&t.CAP_C1&&(this._A1m1=t.A1m1f(p),this._C1a=new Array(t.nC1_+1),t.C1f(p,this._C1a),this._B11=t.SinCosSeries(!0,this._ssig1,this._csig1,this._C1a),_=Math.sin(this._B11),d=Math.cos(this._B11),this._stau1=this._ssig1*d+this._csig1*_,this._ctau1=this._csig1*d-this._ssig1*_),this.caps&t.CAP_C1p&&(this._C1pa=new Array(t.nC1p_+1),t.C1pf(p,this._C1pa)),this.caps&t.CAP_C2&&(this._A2m1=t.A2m1f(p),this._C2a=new Array(t.nC2_+1),t.C2f(p,this._C2a),this._B21=t.SinCosSeries(!0,this._ssig1,this._csig1,this._C2a)),this.caps&t.CAP_C3&&(this._C3a=new Array(t.nC3_),e.C3f(p,this._C3a),this._A3c=-this.f*this._salp0*e.A3f(p),this._B31=t.SinCosSeries(!0,this._ssig1,this._csig1,this._C3a)),this.caps&t.CAP_C4&&(this._C4a=new Array(t.nC4_),e.C4f(p,this._C4a),this._A4=i.sq(this.a)*this._calp0*this._salp0*e._e2,this._B41=t.SinCosSeries(!1,this._ssig1,this._csig1,this._C4a)),this.a13=this.s13=Number.NaN},e.GeodesicLine.prototype.GenPosition=function(e,s,n){var r,a,o,h,l,c,u,p,_,d,f,m,y,g,v,x,b,w,S,C,A,E,M,k,I,D,P={};return n?n===t.LONG_UNROLL&&(n|=t.STANDARD):n=t.STANDARD,n&=this.caps&t.OUT_MASK,P.lat1=this.lat1,P.azi1=this.azi1,P.lon1=n&t.LONG_UNROLL?this.lon1:i.AngNormalize(this.lon1),e?P.a12=s:P.s12=s,e||this.caps&t.DISTANCE_IN&t.OUT_MASK?(h=0,l=0,e?(r=s*i.degree,a=(M=i.sincosd(s)).s,o=M.c):(p=s/(this._b*(1+this._A1m1)),_=Math.sin(p),d=Math.cos(p),r=p-((h=-t.SinCosSeries(!0,this._stau1*d+this._ctau1*_,this._ctau1*d-this._stau1*_,this._C1pa))-this._B11),a=Math.sin(r),o=Math.cos(r),Math.abs(this.f)>.01&&(c=this._ssig1*o+this._csig1*a,u=this._csig1*o-this._ssig1*a,h=t.SinCosSeries(!0,c,u,this._C1a),r-=((1+this._A1m1)*(r+(h-this._B11))-s/this._b)/Math.sqrt(1+this._k2*i.sq(c)),a=Math.sin(r),o=Math.cos(r))),c=this._ssig1*o+this._csig1*a,u=this._csig1*o-this._ssig1*a,S=Math.sqrt(1+this._k2*i.sq(c)),n&(t.DISTANCE|t.REDUCEDLENGTH|t.GEODESICSCALE)&&((e||Math.abs(this.f)>.01)&&(h=t.SinCosSeries(!0,c,u,this._C1a)),l=(1+this._A1m1)*(h-this._B11)),y=this._calp0*c,0===(g=i.hypot(this._salp0,this._calp0*u))&&(g=u=t.tiny_),b=this._salp0,w=this._calp0*u,e&&n&t.DISTANCE&&(P.s12=this._b*((1+this._A1m1)*r+l)),n&t.LONGITUDE&&(v=this._salp0*c,x=u,m=i.copysign(1,this._salp0),f=((n&t.LONG_UNROLL?m*(r-(Math.atan2(c,u)-Math.atan2(this._ssig1,this._csig1))+(Math.atan2(m*v,x)-Math.atan2(m*this._somg1,this._comg1))):Math.atan2(v*this._comg1-x*this._somg1,x*this._comg1+v*this._somg1))+this._A3c*(r+(t.SinCosSeries(!0,c,u,this._C3a)-this._B31)))/i.degree,P.lon2=n&t.LONG_UNROLL?this.lon1+f:i.AngNormalize(i.AngNormalize(this.lon1)+i.AngNormalize(f))),n&t.LATITUDE&&(P.lat2=i.atan2d(y,this._f1*g)),n&t.AZIMUTH&&(P.azi2=i.atan2d(b,w)),n&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(C=t.SinCosSeries(!0,c,u,this._C2a),A=(1+this._A2m1)*(C-this._B21),E=(this._A1m1-this._A2m1)*r+(l-A),n&t.REDUCEDLENGTH&&(P.m12=this._b*(S*(this._csig1*c)-this._dn1*(this._ssig1*u)-this._csig1*u*E)),n&t.GEODESICSCALE&&(M=this._k2*(c-this._ssig1)*(c+this._ssig1)/(this._dn1+S),P.M12=o+(M*c-u*E)*this._ssig1/this._dn1,P.M21=o-(M*this._ssig1-this._csig1*E)*c/S)),n&t.AREA&&(k=t.SinCosSeries(!1,c,u,this._C4a),0===this._calp0||0===this._salp0?(I=b*this.calp1-w*this.salp1,D=w*this.calp1+b*this.salp1):(I=this._calp0*this._salp0*(o<=0?this._csig1*(1-o)+a*this._ssig1:a*(this._csig1*a/(1+o)+this._ssig1)),D=i.sq(this._salp0)+i.sq(this._calp0)*this._csig1*u),P.S12=this._c2*Math.atan2(I,D)+this._A4*(k-this._B41)),e||(P.a12=r/i.degree),P):(P.a12=Number.NaN,P)},e.GeodesicLine.prototype.Position=function(t,e){return this.GenPosition(!1,t,e)},e.GeodesicLine.prototype.ArcPosition=function(t,e){return this.GenPosition(!0,t,e)},e.GeodesicLine.prototype.GenSetDistance=function(t,e){t?this.SetArc(e):this.SetDistance(e)},e.GeodesicLine.prototype.SetDistance=function(e){var i;this.s13=e,i=this.GenPosition(!1,this.s13,t.ARC),this.a13=0+i.a12},e.GeodesicLine.prototype.SetArc=function(e){var i;this.a13=e,i=this.GenPosition(!0,this.a13,t.DISTANCE),this.s13=0+i.s12}}(Ve.Geodesic,Ve.GeodesicLine,Ve.Math),function(t,e,i,s){var n,r;n=function(t,e){var s;return t=i.AngNormalize(t),e=i.AngNormalize(e),s=i.AngDiff(t,e).s,t<=0&&e>0&&s>0?1:e<=0&&t>0&&s<0?-1:0},r=function(t,e){return((e%=720)>=0&&e<360||e<-360?0:1)-((t%=720)>=0&&t<360||t<-360?0:1)},t.PolygonArea=function(t,i){this._geod=t,this.a=this._geod.a,this.f=this._geod.f,this._area0=4*Math.PI*t._c2,this.polyline=i||!1,this._mask=e.LATITUDE|e.LONGITUDE|e.DISTANCE|(this.polyline?e.NONE:e.AREA|e.LONG_UNROLL),this.polyline||(this._areasum=new s.Accumulator(0)),this._perimetersum=new s.Accumulator(0),this.Clear()},t.PolygonArea.prototype.Clear=function(){this.num=0,this._crossings=0,this.polyline||this._areasum.Set(0),this._perimetersum.Set(0),this._lat0=this._lon0=this.lat=this.lon=Number.NaN},t.PolygonArea.prototype.AddPoint=function(t,e){var i;0===this.num?(this._lat0=this.lat=t,this._lon0=this.lon=e):(i=this._geod.Inverse(this.lat,this.lon,t,e,this._mask),this._perimetersum.Add(i.s12),this.polyline||(this._areasum.Add(i.S12),this._crossings+=n(this.lon,e)),this.lat=t,this.lon=e),++this.num},t.PolygonArea.prototype.AddEdge=function(t,e){var i;this.num&&(i=this._geod.Direct(this.lat,this.lon,t,e,this._mask),this._perimetersum.Add(e),this.polyline||(this._areasum.Add(i.S12),this._crossings+=r(this.lon,i.lon2)),this.lat=i.lat2,this.lon=i.lon2),++this.num},t.PolygonArea.prototype.Compute=function(t,e){var i,r,a={number:this.num};return this.num<2?(a.perimeter=0,this.polyline||(a.area=0),a):this.polyline?(a.perimeter=this._perimetersum.Sum(),a):(i=this._geod.Inverse(this.lat,this.lon,this._lat0,this._lon0,this._mask),a.perimeter=this._perimetersum.Sum(i.s12),(r=new s.Accumulator(this._areasum)).Add(i.S12),1&this._crossings+n(this.lon,this._lon0)&&r.Add((r.Sum()<0?1:-1)*this._area0/2),t||r.Negate(),e?r.Sum()>this._area0/2?r.Add(-this._area0):r.Sum()<=-this._area0/2&&r.Add(+this._area0):(r.Sum()>=this._area0||r<0)&&r.Add(-this._area0),a.area=r.Sum(),a)},t.PolygonArea.prototype.TestPoint=function(t,e,i,s){var r,a,o,h,l={number:this.num+1};if(0===this.num)return l.perimeter=0,this.polyline||(l.area=0),l;for(l.perimeter=this._perimetersum.Sum(),a=this.polyline?0:this._areasum.Sum(),o=this._crossings,h=0;h<(this.polyline?1:2);++h)r=this._geod.Inverse(0===h?this.lat:t,0===h?this.lon:e,0!==h?this._lat0:t,0!==h?this._lon0:e,this._mask),l.perimeter+=r.s12,this.polyline||(a+=r.S12,o+=n(0===h?this.lon:e,0!==h?this._lon0:e));return this.polyline||(1&o&&(a+=(a<0?1:-1)*this._area0/2),i||(a*=-1),s?a>this._area0/2?a-=this._area0:a<=-this._area0/2&&(a+=this._area0):a>=this._area0?a-=this._area0:a<0&&(a+=this._area0),l.area=a),l},t.PolygonArea.prototype.TestEdge=function(t,e,i,s){var a,o,h,l={number:this.num?this.num+1:0};return 0===this.num||(l.perimeter=this._perimetersum.Sum()+e,this.polyline||(o=this._areasum.Sum(),h=this._crossings,o+=(a=this._geod.Direct(this.lat,this.lon,t,e,this._mask)).S12,h+=r(this.lon,a.lon2),a=this._geod.Inverse(a.lat2,a.lon2,this._lat0,this._lon0,this._mask),l.perimeter+=a.s12,o+=a.S12,1&(h+=n(a.lon2,this._lon0))&&(o+=(o<0?1:-1)*this._area0/2),i||(o*=-1),s?o>this._area0/2?o-=this._area0:o<=-this._area0/2&&(o+=this._area0):o>=this._area0?o-=this._area0:o<0&&(o+=this._area0),l.area=o)),l}}(Ve.PolygonArea,Ve.Geodesic,Ve.Math,Ve.Accumulator),tt(function(t){var e=X(t.params,"rlat_1"),i=X(t.params,"rlat_2");Ke(t,e,i)},"aea","Albers Equal Area","Conic Sph&Ell\nlat_1= lat_2="),tt(function(t){var e=X(t.params,"rlat_1"),i=X(t.params,"bsouth")?-k:k;Ke(t,e,i)},"leac","Lambert Equal Area Conic","Conic, Sph&Ell\nlat_1= south"),tt(function(e){var r,a,h,u,p,_,f,m=1e-10;if(e.phi0=X(e.params,"rlat_0"),t(t(e.phi0)-k)<m?(p=e.phi0<0?1:0,r=e.phi0<0?-1:1,a=0):t(e.phi0)<m?(p=2,r=0,a=1):(p=3,r=i(e.phi0),a=s(e.phi0)),e.es)if(f=new Ve.Geodesic.Geodesic(e.a,e.es/(1+c(e.one_es))),_=Ze(e.es),X(e.params,"bguam"))h=Xe(e.phi0,r,a,_),e.inv=function(t,r){var a,o,l;for(a=.5*t.x*t.x,r.phi=e.phi0,l=0;l<3;++l)o=e.e*i(r.phi),r.phi=Je(h+t.y-a*n(r.phi)*(o=c(1-o*o)),e.es,_);r.lam=t.x*o/s(r.phi)},e.fwd=function(t,n){var r,a,o;r=s(t.phi),a=i(t.phi),o=1/c(1-e.es*a*a),n.x=t.lam*r*o,n.y=Xe(t.phi,a,r,_)-h+.5*t.lam*t.lam*r*a*o};else{switch(p){case 0:u=Xe(k,1,0,_);break;case 1:u=Xe(-k,-1,0,_);break;case 2:case 3:e.inv=g,e.fwd=y,c(1-e.es*r*r),e.e,c(e.one_es)}e.inv=g,e.fwd=y}else e.inv=function(t,n){var o,h,c,u=t.x,_=t.y;if((h=d(u,_))>w)h-m>w&&j(),h=w;else if(h<m)return n.phi=e.phi0,void(n.lam=0);3==p||2==p?(c=i(h),o=s(h),2==p?(n.phi=Ye(_*c/h),u*=c,_=o*h):(n.phi=Ye(o*r+_*c*a/h),_=(o-r*i(n.phi))*h,u*=c*a),n.lam=0==_?0:l(u,_)):0==p?(n.phi=k-h,n.lam=l(u,-_)):(n.phi=h-k,n.lam=l(u,_))},e.fwd=function(e,n){var h,l,c;switch(c=i(e.phi),l=s(e.phi),h=s(e.lam),p){case 2:case 3:n.y=2==p?l*h:r*c+a*l*h,t(t(n.y)-1)<1e-14?n.y<0?q():n.x=n.y=0:(n.y=o(n.y),n.y/=i(n.y),n.x=n.y*l*i(e.lam),n.y*=2==p?c:a*c-r*l*h);break;case 0:e.phi=-e.phi,h=-h;case 1:t(e.phi-k)<m&&q(),n.x=(n.y=k+e.phi)*i(e.lam),n.y*=h}};function y(n,r){var a,o,h,l,c,d,y,g,v,x,b;switch(a=s(n.lam),o=s(n.phi),h=i(n.phi),p){case 0:a=-a;case 1:r.x=(l=t(u-Xe(n.phi,h,o,_)))*i(n.lam),r.y=l*a;break;case 2:case 3:if(t(n.lam)<m&&t(n.phi-e.phi0)<m){r.x=r.y=0;break}g=e.phi0/C,y=e.lam0/C,x=n.phi/C,v=(n.lam+e.lam0)/C,c=(b=f.Inverse(g,y,x,v,f.AZIMUTH)).azi1*C,d=b.s12,r.x=d*i(c)/e.a,r.y=d*s(c)/e.a}}function g(t,i){var s,n,r,a,o,h,y,g;if((s=d(t.x,t.y))<m)return i.phi=e.phi0,i.lam=0,i;3==p||2==p?(a=t.x*e.a,o=t.y*e.a,h=e.phi0/C,y=e.lam0/C,n=l(a,o)/C,r=c(a*a+o*o),g=f.Direct(h,y,n,r,f.STANDARD),i.phi=g.lat2*C,i.lam=g.lon2*C,i.lam-=e.lam0):(i.phi=Je(0==p?u-s:u+s,e.es,_),i.lam=l(t.x,0==p?-t.y:t.y))}},"aeqd","Azimuthal Equidistant","Azi, Sph&Ell\nlat_0 guam"),tt(function(e){var r,a,o,h,l,c,u=1e-10;e.es=0,e.fwd=function(e,c){var p,d,f,m,y,g,v,x;switch(p=i(e.lam),d=s(e.lam),h){case 2:case 3:m=i(e.phi),x=(f=s(e.phi))*d,3==h&&(x=r*m+a*x),!l&&x<-u&&q(),v=t(g=1-x)>u?-_(y=.5*(1+x))/g-o/y:.5-o,c.x=v*f*p,c.y=3==h?v*(a*m-r*f*d):v*m;break;case 1:case 0:e.phi=t(p_halfpi-e.phi),!l&&e.phi-u>k&&q(),(e.phi*=.5)>u?(y=n(e.phi),v=-2*(_(s(e.phi))/y+y*o),c.x=v*p,c.y=v*d,0==h&&(c.y=-c.y)):c.x=c.y=0}},l=X(e.params,"bno_cut"),c=.5*(k-X(e.params,"rlat_b")),t(c)<u?o=-.5:(o=1/n(c),o*=o*_(s(c))),t(t(e.phi0)-k)<u?e.phi0<0?(p_halfpi=-k,h=1):(p_halfpi=k,h=0):t(e.phi0)<u?h=2:(h=3,r=i(e.phi0),a=s(e.phi0))},"airy","Airy","Misc Sph, no inv.\nno_cut lat_b="),tt(function(t){var e=t.opaque={mode:1};X(t.params,"tlat_1")?0===(e.cosphi1=s(X(t.params,"rlat_1")))&&U(-22):e.cosphi1=.6366197723675814,ii(t)},"wintri","Winkel Tripel","Misc Sph\nlat_1"),tt(ii,"aitoff","Aitoff","Misc Sph"),tt(function(t){t.fwd=function(t,e){var r,a,o,h,l,u,p,_=4/3,d=t.lam;r=n(.5*t.phi),o=1+(a=c(1-r*r))*s(d*=.5),h=i(d)*a/o,u=r/o,e.x=_*h*(3+(l=h*h)-3*(p=u*u)),e.y=_*u*(3+3*l-p)},t.es=0},"august","August Epicycloidal","Misc Sph, no inv."),tt(function(t){si(t,!1,!1)},"apian","Apian Globular I","Misc Sph, no inv."),tt(function(t){si(t,!1,!0)},"ortel","Ortelius Oval","Misc Sph, no inv."),tt(function(t){si(t,!0,!1)},"bacon","Bacon Globular","Misc Sph, no inv."),tt(function(t){var e,n,r,o;t.es=0,t.fwd=function(t,h){var u,p,_,d,f,m;return t.lam+=-16.5*C,p=s(t.phi),_=s(t.lam)*p,d=i(t.lam)*p,m=(f=i(t.phi))*e+_*n,t.lam=l(d*r-m*o,_*e-f*n),m=m*r+d*o,t.phi=a(m),t.lam=Mt(t.lam),t.lam+t.phi<-1.4&&(u=(t.lam-t.phi+1.6)*(t.lam+t.phi+1.4)/8,t.lam+=u,t.phi-=.8*u*i(t.phi+w/2)),p=s(t.phi),u=c(2/(1+p*s(t.lam/2))),h.x=1.68*u*p*i(t.lam/2),h.y=u*i(t.phi),u=(1-s(t.lam*t.phi))/12,h.y<0&&(h.x*=1+u),h.y>0&&(h.y*=1+u/1.5*h.x*h.x),h},t.lam0=0,t.phi0=-42*C,e=s(t.phi0),n=i(t.phi0),r=1,o=0},"bertin1953","Bertin 1953","Misc., Sph., NoInv."),tt(function(e){var n=c(2);e.fwd=function(e,r){var a,o,h,l;if(a=e.phi,t(t(e.phi)-k)<1e-7)r.x=0;else{for(h=i(a)*w,l=20;l&&(a-=o=(a+i(a)-h)/(1+s(a)),!(t(o)<1e-7));--l);a*=.5,r.x=2.00276*e.lam/(1/s(e.phi)+1.11072/s(a))}r.y=.49931*(e.phi+n*i(a))},e.es=0},"boggs","Boggs Eumorphic","PCyl., no inv., Sph."),tt(function(e){var r,a,o,h,u,p,_=1e-10;r=X(e.params,"rlat_1"),t(r)<_&&U(-23),e.es?(u=Ze(e.es),h=Xe(r,o=i(r),p=s(r),u),o=p/(c(1-e.es*o*o)*o),e.inv=function(n,r){var a,p;p=d(n.x,n.y=o-n.y),r.phi=Je(o+h-p,e.es,u),(a=t(r.phi))<k?(a=i(r.phi),r.lam=p*l(n.x,n.y)*c(1-e.es*a*a)/s(r.phi)):t(a-k)<=_?r.lam=0:j()},e.fwd=function(t,n){var r,a,l;r=o+h-Xe(t.phi,a=i(t.phi),l=s(t.phi),u),a=l*t.lam/(r*c(1-e.es*a*a)),n.x=r*i(a),n.y=o-r*s(a)}):(a=t(r)+_>=k?0:1/n(r),e.inv=function(e,i){var n=d(e.x,e.y=a-e.y);i.phi=a+r-n,t(i.phi)>k&&j(),t(t(i.phi)-k)<=_?i.lam=0:i.lam=n*l(e.x,e.y)/s(i.phi)},e.fwd=function(e,n){var o,h;h=a+r-e.phi,t(h)>_?(n.x=h*i(o=e.lam*s(e.phi)/h),n.y=a-h*s(o)):n.x=n.y=0})},"bonne","Bonne (Werner lat_1=90)","Conic Sph&Ell\nlat_1="),tt(function(t){var e,r,o=.16666666666666666,h=.008333333333333333,u=.041666666666666664,p=.06666666666666667;t.es?(r=Ze(t.es),e=Xe(t.phi0,i(t.phi0),s(t.phi0),r),t.fwd=function(a,l){var p,_,d,f,m,y;l.y=Xe(a.phi,p=i(a.phi),f=s(a.phi),r),p=1/c(1-t.es*p*p),y=n(a.phi),_=y*y,d=a.lam*f,f*=t.es*f/(1-t.es),m=d*d,l.x=p*d*(1-m*_*(o-(8-_+8*f)*m*h)),l.y-=e-p*y*m*(.5+(5-_+6*f)*m*u)},t.inv=function(a,o){var h,l,_,d,f,m,y;y=Je(e+a.y,t.es,r),m=n(y),l=m*m,h=i(y),_=1/(1-t.es*h*h),h=c(_),_*=(1-t.es)*h,d=a.x/h,f=d*d,o.phi=y-h*m/_*f*(.5-(1+3*l)*f*u),o.lam=d*(1+l*f*((1+3*l)*f*p-.3333333333333333))/s(y)}):(t.fwd=function(e,r){r.x=a(s(e.phi)*i(e.lam)),r.y=l(n(e.phi),s(e.lam))-t.phi0},t.inv=function(e,r){var o=e.y+t.phi0;r.phi=a(i(o)*s(e.x)),r.lam=l(n(e.x),s(o))})},"cass","Cassini","Cyl, Sph&Ell"),tt(function(e){var n,r,o=0;X(e.params,"tlat_ts")&&(e.k0=s(o=X(e.params,"rlat_ts")),e.k0<0&&U(-24)),e.es?(o=i(o),e.k0/=c(1-e.es*o*o),e.e=c(e.es),(r=ni(e.es))||e_error_0(),n=We(1,e.e,e.one_es),e.fwd=function(t,s){s.x=e.k0*t.lam,s.y=.5*We(i(t.phi),e.e,e.one_es)/e.k0},e.inv=function(t,i){i.phi=ri(a(2*t.y*e.k0/n),r),i.lam=t.x/e.k0}):(e.fwd=function(t,s){s.x=e.k0*t.lam,s.y=i(t.phi)/e.k0},e.inv=function(i,s){var n,r=i.x,o=i.y;(n=t(o*=e.k0))-F<=1?(s.phi=n>=1?o<0?-k:k:a(o),s.lam=r/e.k0):j()})},"cea","Equal Area Cylindrical","Cyl, Sph&Ell\nlat_ts="),tt(function(e){var n,r,a,o,h,u,p,_=1/3,d=[];for(u=0;u<3;++u)d[u]={p:{}},d[u].phi=X(e.params,"rlat_"+(u+1)),d[u].lam=X(e.params,"rlon_"+(u+1)),d[u].lam=Mt(d[u].lam-e.lam0),d[u].cosphi=s(d[u].phi),d[u].sinphi=i(d[u].phi);for(u=0;u<3;++u)p=2==u?0:u+1,d[u].v=f(d[p].phi-d[u].phi,d[u].cosphi,d[u].sinphi,d[p].cosphi,d[p].sinphi,d[p].lam-d[u].lam),d[u].v.r||U(-25);function f(e,n,r,a,o,h){var u,p,_,d={};return u=s(h),t(e)>1||t(h)>1?d.r=Qe(cs1*o+n*a*u):(p=i(.5*e),_=i(.5*h),d.r=2*Ye(c(p*p+n*a*_*_))),t(d.r)>1e-9?d.Az=l(a*i(h),n*o-r*a*u):d.r=d.Az=0,d}function m(t,e,i){return Qe(.5*(t*t+e*e-i*i)/(t*e))}a=m(d[0].v.r,d[2].v.r,d[1].v.r),o=m(d[0].v.r,d[1].v.r,d[2].v.r),h=w-a,r=2*(d[0].p.y=d[1].p.y=d[2].v.r*i(a)),d[2].p.y=0,d[0].p.x=-(d[1].p.x=.5*d[0].v.r),n=d[2].p.x=d[0].p.x+d[2].v.r*s(a),e.es=0,e.fwd=function(t,e){var a,l,c,u,p,y,g,v=[];for(a=i(t.phi),l=s(t.phi),u=0;u<3&&(v[u]=f(t.phi-d[u].phi,d[u].cosphi,d[u].sinphi,l,a,t.lam-d[u].lam),v[u].r);++u)v[u].Az=Mt(v[u].Az-d[u].v.Az);if(u<3)y=d[u].p.x,g=d[u].p.y;else{for(y=n,g=r,u=0;u<3;++u)p=2==u?0:u+1,c=m(d[u].v.r,v[u].r,v[p].r),v[u].Az<0&&(c=-c),u?1==u?(c=o-c,y-=v[u].r*s(c),g-=v[u].r*i(c)):(c=h-c,y+=v[u].r*s(c),g+=v[u].r*i(c)):(y+=v[u].r*s(c),g-=v[u].r*i(c));y*=_,g*=_}e.x=y,e.y=g}},"chamb","Chamberlin Trimetric","Misc Sph, no inv.\nlat_1= lon_1= lat_2= lon_2= lat_3= lon_3="),tt(function(t){var e=1/3;t.inv=function(t,i){i.phi=3*a(.32573500793527993*t.y),i.lam=1.0233267079464885*t.x/(2*s((i.phi+i.phi)*e)-1)},t.fwd=function(t,n){t.phi*=e,n.x=.9772050238058398*t.lam*(2*s(t.phi+t.phi)-1),n.y=3.0699801238394655*i(t.phi)},t.es=0},"crast","Craster Parabolic (Putnins P4)","PCyl., Sph."),tt(function(t){var e=.5253,n=.7264,r=1/Math.sqrt(e*n),o=.9701,h=_(22*C),l=d(0),u=i(h),p=s(h);function _(t){return a(n*i(t)+.4188*c(e*n))}function d(t){return e*t}X(t.params,"tlon_0")||(t.lam0=11.023*C),t.es=0,t.fwd=function(t,e){var n=_(t.phi),a=d(t.lam),f=i(n),m=s(n),y=i(a-l),g=s(a-l),v=c(2/(1+i(h)*f+p*m*g));e.x=r*v*m*y*o,e.y=r*v*(p*f-u*m*g)/o}},"cupola","Cupola","PCyl., Sph., NoInv."),tt(function(e){e.fwd=function(e,i){var n=t(e.lam);i.y=e.phi,i.x=e.lam,i.x*=s((.95+n*(n*n*.0016666666666666666-.08333333333333333))*(e.phi*(.9+.03*e.phi*e.phi*e.phi*e.phi)))},e.es=0},"denoy","Denoyer Semi-Elliptical","PCyl, Sph., no inv."),tt(function(e){var i=.9213177319235613,s=.3183098861837907;e.es=0,e.fwd=function(e,n){n.x=i*e.lam*(1-s*t(e.phi)),n.y=i*e.phi},e.inv=function(e,n){n.phi=e.y/i,n.lam=e.x/(i*(1-s*t(n.phi)))}},"eck1","Eckert I","PCyl Sph"),tt(function(e){var s=.46065886596178063,n=1.4472025091165353;e.es=0,e.fwd=function(e,r){r.x=s*e.lam*(r.y=c(4-3*i(t(e.phi)))),r.y=n*(2-r.y),e.phi<0&&(r.y=-r.y)},e.inv=function(e,i){i.lam=e.x/(s*(i.phi=2-t(e.y)/n)),i.phi=.3333333333333333*(4-i.phi*i.phi),t(i.phi)>=1?t(i.phi)>1.0000001?j():i.phi=i.phi<0?-k:k:i.phi=a(i.phi),e.y<0&&(i.phi=-i.phi)}},"eck2","Eckert II","PCyl Sph"),tt(function(t){ai(t,{C_x:.4222382003157712,C_y:.8444764006315424,A:1,B:.4052847345693511})},"eck3","Eckert III","PCyl Sph"),tt(function(t){ai(t,{C_x:.94745,C_y:.94745,A:0,B:.3039635509270133})},"wag6","Wagner VI","PCyl Sph"),tt(function(t){ai(t,{C_x:.8660254037844,C_y:1,A:0,B:.3039635509270133})},"kav7","Kavraisky VII","PCyl Sph"),tt(function(t){ai(t,{C_x:1.8949,C_y:.94745,A:-.5,B:.3039635509270133})},"putp1","Putnins P1","PCyl Sph"),tt(function(e){var n=.4222382003157712,r=1.3265004281770023,a=3.5707963267948966;e.es=0,e.fwd=function(e,o){var h,l,c,u,p;for(h=a*i(e.phi),l=e.phi*e.phi,e.phi*=.895168+l*(.0218849+.00826809*l),p=6;p&&(u=s(e.phi),c=i(e.phi),e.phi-=l=(e.phi+c*(u+2)-h)/(1+u*(u+2)-c*c),!(t(l)<1e-7));--p);p?(o.x=n*e.lam*(1+s(e.phi)),o.y=r*i(e.phi)):(o.x=n*e.lam,o.y=e.phi<0?-r:r)},e.inv=function(t,e){var o;e.phi=Ye(t.y/r),e.lam=t.x/(n*(1+(o=s(e.phi)))),e.phi=Ye((e.phi+i(e.phi)*(o+2))/a)}},"eck4","Eckert IV","PCyl Sph"),tt(function(t){t.es=0,t.fwd=function(t,e){e.x=.4410127717245515*(1+s(t.phi))*t.lam,e.y=.882025543449103*t.phi},t.inv=function(t,e){e.lam=2.267508027238226*t.x/(1+s(e.phi=1.133754013619113*t.y))}},"eck5","Eckert V","PCyl Sph"),tt(function(t){var e=s(X(t.params,"rlat_ts"));e<=0&&U(-24),t.es=0,t.fwd=function(i,s){s.x=e*i.lam,s.y=i.phi-t.phi0},t.inv=function(i,s){s.lam=i.x/e,s.phi=i.y+t.phi0}},"eqc","Equidistant Cylindrical (Plate Caree)","Cyl, Sph\nlat_ts=[, lat_0=0]"),tt(function(e){var n,r,a,o,h,c,u,p,_,f,m,y,g;n=X(e.params,"rlat_1"),r=X(e.params,"rlat_2"),t(n+r)<F&&U(-21),(u=Ze(e.es))||e_error_0(),a=f=i(n),_=s(n),m=t(n-r)>=F,(p=e.es>0)?(g=He(f,_,e.es),y=Xe(n,f,_,u),m&&(f=i(r),_=s(r),a=(g-He(f,_,e.es))/(Xe(r,f,_,u)-y)),h=(c=y+g/a)-Xe(e.phi0,i(e.phi0),s(e.phi0),u)):(m&&(a=(_-s(r))/(r-n)),c=n+s(n)/a,h=c-e.phi0),e.fwd=function(t,e){o=c-(p?Xe(t.phi,i(t.phi),s(t.phi),u):t.phi),e.x=o*i(t.lam*=a),e.y=h-o*s(t.lam)},e.inv=function(t,i){0!=(o=d(t.x,t.y=h-t.y))?(a<0&&(o=-o,t.x=-t.x,t.y=-t.y),i.phi=c-o,p&&(i.phi=Je(i.phi,e.es,u)),i.lam=l(t.x,t.y)/a):(i.lam=0,i.phi=a>0?k:-k)}},"eqdc","Equidistant Conic","Conic, Sph&Ell\nlat_1= lat_2="),tt(function(t){var e=1.340264,i=-.081106,s=893e-6,n=.003796,r=Math.sqrt(3)/2;t.es=0,t.fwd=function(t,a){var o=Math.asin(r*Math.sin(t.phi)),h=o*o,l=h*h*h;a.x=t.lam*Math.cos(o)/(r*(e+3*i*h+l*(7*s+9*n*h))),a.y=o*(e+i*h+l*(s+n*h))},t.inv=function(t,a){var o,h,l,c,u=t.y;for(c=0;c<12&&(u-=l=(u*(e+i*(o=u*u)+(h=o*o*o)*(s+n*o))-t.y)/(e+3*i*o+h*(7*s+9*n*o)),!(Math.abs(l)<1e-9));++c);h=(o=u*u)*o*o,a.lam=r*t.x*(e+3*i*o+h*(7*s+9*n*o))/Math.cos(u),a.phi=Math.asin(Math.sin(u)/r)}},"eqearth","Equal Earth","PCyl., Sph."),tt(oi,"etmerc","Extended Transverse Mercator","Cyl, Sph\nlat_ts=(0)\nlat_0=(0)"),tt(function(t){t.fwd=function(t,e){e.x=.7071067811865476*t.lam,e.y=1.7071067811865475*n(.5*t.phi)},t.inv=function(t,e){e.lam=1.4142135623730951*t.x,e.phi=2*h(.585786437626905*t.y)},t.es=0},"gall","Gall (Gall Stereographic)","Cyl, Sph"),tt(function(t){t.is_geocent=!0,t.x0=0,t.y0=0,t.fwd=function(t,e){e.x=t.lam,e.y=t.phi},t.inv=function(t,e){e.phi=t.y,e.lam=t.x}},"geocent","Geocentric",""),tt(function(t){var e,r,a,o,u,p,_,f=X(t.params,"dh"),m=X(t.params,"ssweep");m?"x"==m?_=1:"y"==m?_=0:U(-49):_=0,((u=f/t.a)<=0||u>1e10)&&U(-50),p=(o=1+u)*o-1,0!=t.es?(e=c(t.one_es),r=t.one_es,a=t.rone_es,t.inv=function(t,i){var r,f,m,y,g,v;r=-1,_?(m=n(t.y/u),f=n(t.x/u)*d(1,m)):(f=n(t.x/u),m=n(t.y/u)*d(1,f));var x=(g=2*o*r)*g-4*(y=f*f+(y=m/e)*y+r*r)*p;x<0&&U(-51),v=(-g-c(x))/(2*y),r=o+v*r,f*=v,m*=v,i.lam=l(f,r),i.phi=h(m*s(i.lam)/r),i.phi=h(a*n(i.phi))},t.fwd=function(t,l){var c,p,f,m,y;t.phi=h(r*n(t.phi)),c=e/d(e*s(t.phi),i(t.phi)),p=c*s(t.lam)*s(t.phi),f=c*i(t.lam)*s(t.phi),m=c*i(t.phi),(o-p)*p-f*f-m*m*a<0&&U(-51),y=o-p,_?(l.x=u*h(f/d(m,y)),l.y=u*h(m/y)):(l.x=u*h(f/y),l.y=u*h(m/d(f,y)))}):(e=r=a=1,t.inv=function(t,e){var i,r,a,d,f,m;i=-1,_?(a=n(t.y/u),r=n(t.x/u)*c(1+a*a)):(r=n(t.x/u),a=n(t.y/u)*c(1+r*r));var y=(f=2*o*i)*f-4*(d=r*r+a*a+i*i)*p;y<0&&U(-51),m=(-f-c(y))/(2*d),i=o+m*i,r*=m,a*=m,e.lam=l(r,i),e.phi=h(a*s(e.lam)/i)},t.fwd=function(t,e){var n=s(t.phi),r=s(t.lam)*n,a=i(t.lam)*n,l=i(t.phi);n=o-r,_?(e.x=u*h(a/d(l,n)),e.y=u*h(l/n)):(e.x=u*h(a/n),e.y=u*h(l/d(a,n)))})},"geos","Geostationary Satellite View","Azi, Sph&Ell"),tt(function(t){var e=o(X(t.params,"tlat_1")?X(t.params,"rlat_1"):0),r=i(e),a=s(e);function o(t){return Ye(n(.5*t))}t.fwd=function(t,e){var n=.5*t.lam,h=o(t.phi),l=i(h),c=s(h),u=s(n);r*l+a*c*u>=0?(e.x=c*i(n),e.y=a*l-r*c*u):q()},t.es=0},"gilbert","Gilbert Two World Perspective","PCyl., Sph., NoInv.\nlat_1="),tt(function(t){t.fwd=function(t,e){var i=t.phi*t.phi;e.y=t.phi*(1+.08333333333333333*i),e.x=t.lam*(1-.162388*i),i=t.lam*t.lam,e.x*=.87-952426e-9*i*i},t.es=0},"gins8","Ginsburg VIII (TsNIIGAiK)","PCyl, Sph., no inv."),tt(function(t){X(t.params,"tn"),X(t.params,"tm")?li(t,X(t.params,"dm"),X(t.params,"dn")):U(-99)},"gn_sinu","General Sinusoidal Series","PCyl, Sph.\nm= n="),tt(hi,"sinu","Sinusoidal (Sanson-Flamsteed)","PCyl, Sph&Ell"),tt(function(t){li(t,1,2.5707963267948966)},"eck6","Eckert VI","PCyl, Sph.\nm= n="),tt(function(t){li(t,.5,1.7853981633974483)},"mbtfps","McBryde-Thomas Flat-Polar Sinusoidal","PCyl, Sph."),tt(function(e){var n,r,o=1e-10;t(t(e.phi0)-k)<o?r=e.phi0<0?1:0:t(e.phi0)<o?r=2:(r=3,sinph0=i(e.phi0),n=s(e.phi0)),e.inv=function(s,u){var p,_,f,m=s.x,y=s.y;if(p=d(m,y),f=i(u.phi=h(p)),_=c(1-f*f),t(p)<=o)u.phi=e.phi0,u.lam=0;else{switch(r){case 3:u.phi=_*sinph0+y*f*n/p,t(u.phi)>=1?u.phi=u.phi>0?k:-k:u.phi=a(u.phi),y=(_-sinph0*i(u.phi))*p,m*=f*n;break;case 2:u.phi=y*f/p,t(u.phi)>=1?u.phi=u.phi>0?k:-k:u.phi=a(u.phi),y=_*p,m*=f;break;case 1:u.phi-=k;break;case 0:u.phi=k-u.phi,y=-y}u.lam=l(m,y)}},e.fwd=function(t,e){var a,h,l;switch(l=i(t.phi),h=s(t.phi),a=s(t.lam),r){case 2:e.y=h*a;break;case 3:e.y=sinph0*l+n*h*a;break;case 1:e.y=-l;break;case 0:e.y=l}switch(e.y<=o&&q(),e.x=(e.y=1/e.y)*h*i(t.lam),r){case 2:e.y*=l;break;case 3:e.y*=n*l-sinph0*h*a;break;case 0:a=-a;case 1:e.y*=h*a}},e.es=0},"gnom","Gnomonic","Azi, Sph."),tt(ci,"moll","Mollweide","PCyl Sph"),tt(function(t){pi(t,ui(0,w/3))},"wag4","Wagner IV","PCyl Sph"),tt(function(t){pi(t,{C_x:.90977,C_y:1.65014,C_p:3.00896})},"wag5","Wagner V","PCyl Sph"),tt(function(e){var i,s,n,r,a=.0528,o=.7109307819790236;e.es=0,hi(e),i=e.fwd,s=e.inv,ci(e),n=e.fwd,r=e.inv,e.fwd=function(e,s){t(e.phi)<o?i(e,s):(n(e,s),s.y-=e.phi>0?a:-a)},e.inv=function(e,i){t(e.y)<=o?s(e,i):(e.y+=e.y>0?a:-a,r(e,i))}},"goode","Goode Homolosine","PCyl, Sph."),tt(function(e){var n,r,a;e.inv=function(e,i){var s=c(1-.25*n*n*e.x*e.x-.25*e.y*e.y);t(2*s*s-1)<1e-10?(i.lam=x,i.phi=x,pj_errno=-14):(i.lam=ei(n*e.x*s,2*s*s-1)/n,i.phi=Ye(s*e.y))},e.fwd=function(t,e){var o,h;h=c(2/(1+(o=s(t.phi))*s(t.lam*=n))),e.x=r*h*o*i(t.lam),e.y=a*h*i(t.phi)},e.es=0,X(e.params,"tW")?(n=t(X(e.params,"dW")))<=0&&U(-27):n=.5,X(e.params,"tM")?(r=t(X(e.params,"dM")))<=0&&U(-27):r=1,a=1/r,r/=n},"hammer","Hammer & Eckert-Greifendorff","Misc Sph,\nW= M="),tt(function(e){var n=1.000001;e.inv=function(e,r){var o=e.y*(e.y<0?.5179951515653813:.5686373742600607);t(o)>1?t(o)>n?j():o=o>0?k:-k:o=a(o),r.lam=1.1764705882352942*e.x/s(o),o+=o,r.phi=(o+i(o))*(e.y<0?.4102345310814193:.3736990601468637),t(r.phi)>1?t(r.phi)>n?j():r.phi=r.phi>0?k:-k:r.phi=a(r.phi)},e.fwd=function(e,n){var r,a,o;for(a=i(e.phi)*(e.phi<0?2.43763:2.67595),o=20;o&&(e.phi-=r=(e.phi+i(e.phi)-a)/(1+s(e.phi)),!(t(r)<1e-7));--o);n.x=.85*e.lam*s(e.phi*=.5),n.y=i(e.phi)*(e.phi<0?1.93052:1.75859)},e.es=0},"hatano","Hatano Asymmetrical Equal Area","PCyl., Sph."),tt(_i,"healpix","HEALPix","Sph., Ellps."),tt(function(t){_i(t,!0)},"rhealpix","rHEALPix","Sph., Ellps.\nnorth_square= south_square="),tt(function(e){var n,r=i(.5),h=a(r),u=2*c(w/(n=w+4*h*2)),p=.5*u*(2+c(3));e.es=0,e.fwd=function(e,r){var a,o,_=1-i(e.phi);if(_&&_<2){var d,f,m,y,g,v=k-e.phi,x=25;do{f=i(v),m=s(v),g=h+l(f,2-m),v-=d=(v-1*h-2*f+(y=5-4*m)*g-.5*_*n)/(4*f*g)}while(t(d)>1e-12&&--x>0);a=u*c(y),o=e.lam*g/w}else a=u*(1+_),o=e.lam*h/w;r.x=a*i(o),r.y=p-a*s(o)},e.inv=function(t,e){var s=t.x,r=t.y,_=s*s+(r-=p)*r,d=(5-_/(u*u))/4,f=o(d),m=i(f),y=h+l(m,2-d);e.lam=a(s/c(_))*w/y,e.phi=a(1-2*(f-1*h-2*m+(5-4*d)*y)/n)}},"hill","Hill Eucyclic","PCyl., Sph."),tt(function(e){var r,o,p,_,d,f,m,y,g,v=.785398163397448,x=1.37008346281555;e.a=6377397.155,e.e=c(e.es=.006674372230614),X(e.params,"tlat_0")||(e.phi0=.863937979737193),X(e.params,"tlon_0")||(e.lam0=.4334234309119251),X(e.params,"tk")||(e.k0=.9999),g=1,X(e.params,"tczech")||(g=-1),_=c(1+e.es*u(s(e.phi0),4)/(1-e.es)),r=a(i(e.phi0)/_),p=u((1+e.e*i(e.phi0))/(1-e.e*i(e.phi0)),_*e.e/2),d=n(r/2+v)/u(n(e.phi0/2+v),_)*p,o=c(1-e.es)/(1-e.es*u(i(e.phi0),2)),f=i(x),m=e.k0*o/n(x),y=.5286277629901559,e.inv=function(r,o){var p,b,w,S,C,A,E,M;E=r.x,r.x=r.y,r.y=E,r.x*=g,r.y*=g,C=c(r.x*r.x+r.y*r.y),S=l(r.y,r.x)/i(x),w=2*(h(u(m/C,1/f)*n(x/2+v))-v),p=a(s(y)*i(w)-i(y)*s(w)*s(S)),b=a(s(w)*i(S)/s(p)),o.lam=e.lam0-b/_,A=p,M=0;do{o.phi=2*(h(u(d,-1/_)*u(n(p/2+v),1/_)*u((1+e.e*i(A))/(1-e.e*i(A)),e.e/2))-v),t(A-o.phi)<1e-15&&(M=1),A=o.phi}while(0===M);o.lam-=e.lam0},e.fwd=function(t,r){var o,l,c,p,b,w,S;o=u((1+e.e*i(t.phi))/(1-e.e*i(t.phi)),_*e.e/2),l=2*(h(d*u(n(t.phi/2+v),_)/o)-v),c=-t.lam*_,p=a(s(y)*i(l)+i(y)*s(l)*s(c)),b=a(s(l)*i(c)/s(p)),w=f*b,S=m*u(n(x/2+v),f)/u(n(p/2+v),f),r.y=S*s(w),r.x=S*i(w),r.y*=g,r.x*=g}},"krovak","Krovak","PCyl., Ellps."),tt(function(e){var n,r,o,h,u,p,_,f,m,y,g,v=1e-10;if(y=t(e.phi0),m=t(y-k)<v?e.phi0<0?1:0:t(y)<v?2:3,e.es){switch(e.e=c(e.es),u=We(1,e.e,e.one_es),e.es,f=ni(e.es),m){case 0:case 1:p=1;break;case 2:p=1/(_=c(.5*u)),o=1,h=.5*u;break;case 3:_=c(.5*u),g=i(e.phi0),n=We(g,e.e,e.one_es)/u,r=c(1-n*n),p=s(e.phi0)/(c(1-e.es*g*g)*_*r),h=(o=_)/p,o*=p}e.inv=function(t,o){var h,c,y,g,x=0;switch(m){case 2:case 3:if(t.x/=p,t.y*=p,(g=d(t.x,t.y))<v)return o.lam=0,o.phi=e.phi0,o;c=2*a(.5*g/_),h=s(c),c=i(c),t.x*=c,3==m?(x=h*n+t.y*c*r/g,t.y=g*r*h-t.y*n*c):(x=t.y*c/g,t.y=g*h);break;case 0:t.y=-t.y;case 1:if(!(y=t.x*t.x+t.y*t.y))return o.lam=0,o.phi=e.phi0,o;x=1-y/u,1==m&&(x=-x)}return o.lam=l(t.x,t.y),o.phi=ri(a(x),f),o},e.fwd=function(a,l){var p,_,d,f,y=0,g=0,x=0;switch(p=s(a.lam),_=i(a.lam),d=i(a.phi),f=We(d,e.e,e.one_es),(3==m||2==m)&&(g=c(1-(y=f/u)*y)),m){case 3:x=1+n*y+r*g*p;break;case 2:x=1+g*p;break;case 0:x=k+a.phi,f=u-f;break;case 1:x=a.phi-k,f=u+f}switch(t(x)<v&&q(),m){case 3:case 2:3==m?(x=c(2/x),l.y=h*x*(r*y-n*g*p)):(x=c(2/(1+g*p)),l.y=x*y*h),l.x=o*x*g*_;break;case 0:case 1:f>=0?(x=c(f),l.x=x*_,l.y=p*(1==m?x:-x)):l.x=l.y=0}}}else 3==m&&(n=i(e.phi0),r=s(e.phi0)),e.inv=function(o,h){var c,u=0,p=0;switch(c=d(o.x,o.y),(h.phi=.5*c)>1&&j(),h.phi=2*a(h.phi),(3==m||2==m)&&(p=i(h.phi),u=s(h.phi)),m){case 2:h.phi=t(c)<=v?0:a(o.y*p/c),o.x*=p,o.y=u*c;break;case 3:h.phi=t(c)<=v?e.phi0:a(u*n+o.y*p*r/c),o.x*=p*r,o.y=(u-i(h.phi)*n)*c;break;case 0:o.y=-o.y,h.phi=k-h.phi;break;case 1:h.phi-=k}h.lam=0!=o.y||2!=m&&3!=m?l(o.x,o.y):0},e.fwd=function(a,o){var h,l,u;switch(u=i(a.phi),l=s(a.phi),h=s(a.lam),m){case 2:case 3:o.y=2==m?1+l*h:1+n*u+r*l*h,o.y<=v&&q(),o.y=c(2/o.y),o.x=o.y*l*i(a.lam),o.y*=2==m?u:r*u-n*l*h;break;case 0:h=-h;case 1:t(a.phi+e.phi0)<v&&q(),o.y=M-.5*a.phi,o.y=2*(1==m?s(o.y):i(o.y)),o.x=o.y*i(a.lam),o.y*=h}}},"laea","Lambert Azimuthal Equal Area","Azi, Sph&Ell"),tt(di,"lonlat","Lat/long (Geodetic)",""),tt(di,"longlat","Lat/long (Geodetic alias)",""),tt(di,"latlon","Lat/long (Geodetic alias)",""),tt(di,"latlong","Lat/long (Geodetic alias)",""),tt(function(e){var r,a,o,p,f,m,y,g,v,b,w,S=1e-10;e.inv=function(t,i){var s,n=t.x,r=t.y;n/=e.k0,r/=e.k0,0!=(s=d(n,r=y-r))?(m<0&&(s=-s,n=-n,r=-r),v?(i.phi=mi(u(s/g,1/m),e.e),i.phi==x&&j()):i.phi=2*h(u(g/s,1/m))-k,i.lam=l(n,r)/m):(i.lam=0,i.phi=m>0?k:-k)},e.fwd=function(r,a){var o,h=r.lam;t(t(r.phi)-k)<S?(r.phi*m<=0&&q(),o=0):o=g*(v?u(fi(r.phi,i(r.phi),e.e),m):u(n(M+.5*r.phi),-m)),h*=m,a.x=e.k0*(o*i(h)),a.y=e.k0*(y-o*s(h))},p=X(e.params,"rlat_1"),X(e.params,"tlat_2")?f=X(e.params,"rlat_2"):(f=p,X(e.params,"tlat_0")||(e.phi0=p)),t(p+f)<S&&U(-21),m=a=i(p),r=s(p),o=t(p-f)>=S,(v=0!=e.es)?(e.e=c(e.es),w=He(a,r,e.es),b=fi(p,a,e.e),o&&(a=i(f),m=_(w/He(a,s(f),e.es)),m/=_(b/fi(f,a,e.e))),g=y=w*u(b,-m)/m,y*=t(t(e.phi0)-k)<S?0:u(fi(e.phi0,i(e.phi0),e.e),m)):(o&&(m=_(r/s(f))/_(n(M+.5*f)/n(M+.5*p))),g=r*u(n(M+.5*p),m)/m,y=t(t(e.phi0)-k)<S?0:g*u(n(M+.5*e.phi0),-m))},"lcc","Lambert Conformal Conic","Conic, Sph&Ell\nlat_1= and lat_2= or lat_0="),tt(function(e){var i,r,a,o=1e-8;i=X(e.params,"rlat_1"),r=s(i),a=n(M+.5*i),r<o&&U(-22),e.fwd=function(e,s){s.y=e.phi-i,t(s.y)<o?s.x=e.lam*r:(s.x=M+.5*e.phi,t(s.x)<o||t(t(s.x)-k)<o?s.x=0:s.x=e.lam*s.y/_(n(s.x)/a))},e.inv=function(e,s){s.phi=e.y+i,t(e.y)<o?s.lam=e.x/r:(s.lam=M+.5*s.phi,t(s.lam)<o||t(t(s.lam)-k)<o?s.lam=0:s.lam=e.x*_(n(s.lam)/a)/e.y)},e.es=0},"loxim","Loximuthal","PCyl Sph"),tt(function(e){var n=.9525793444156804,r=.9258200997725514,o=3.401680257083045,h=2/3,l=1/3,c=1.0000001;e.fwd=function(t,e){t.phi=a(n*i(t.phi)),e.x=r*t.lam*(2*s(h*t.phi)-1),e.y=o*i(l*t.phi)},e.inv=function(e,l){l.phi=e.y/o,t(l.phi)>=1?t(l.phi)>c?j():l.phi=l.phi<0?-k:k:l.phi=a(l.phi),l.lam=e.x/(r*(2*s(h*(l.phi*=3))-1)),t(l.phi=i(l.phi)/n)>=1?t(l.phi)>c?j():l.phi=l.phi<0?-k:k:l.phi=a(l.phi)},e.es=0},"mbt_fpp","McBride-Thomas Flat-Polar Parabolic","Cyl., Sph."),tt(function(e){var n=1.000001;e.fwd=function(e,n){var r,a,o;for(a=1.7071067811865475*i(e.phi),o=20;o&&(e.phi-=r=(i(.5*e.phi)+i(e.phi)-a)/(.5*s(.5*e.phi)+s(e.phi)),!(t(r)<1e-7));--o);n.x=.3124597141037825*e.lam*(1+2*s(e.phi)/s(.5*e.phi)),n.y=1.874758284622695*i(.5*e.phi)},e.inv=function(e,r){var o;r.phi=.533402096794177*e.y,t(r.phi)>1?t(r.phi)>n?j():r.phi<0?(o=-1,r.phi=-w):(o=1,r.phi=w):r.phi=2*a(o=r.phi),r.lam=3.2004125807650623*e.x/(1+2*s(r.phi)/s(.5*r.phi)),r.phi=.585786437626905*(o+i(r.phi)),t(r.phi)>1?t(r.phi)>n?j():r.phi=r.phi<0?-k:k:r.phi=a(r.phi)},e.es=0},"mbt_fpq","McBryde-Thomas Flat-Polar Quartic","Cyl., Sph."),tt(function(e){var n=.45503,r=1.36509,a=1.41546,o=.22248,h=1.44492,l=1/3;e.fwd=function(e,c){var u,p,_,d;for(u=a*i(e.phi),d=10;d&&(_=e.phi/r,e.phi-=p=(n*i(_)+i(e.phi)-u)/(l*s(_)+s(e.phi)),!(t(p)<1e-7));--d);_=e.phi/r,c.x=o*e.lam*(1+3*s(e.phi)/s(_)),c.y=h*i(_)},e.inv=function(t,e){var l;e.phi=r*(l=Ye(t.y/h)),e.lam=t.x/(o*(1+3*s(e.phi)/s(l))),e.phi=Ye((n*i(l)+i(e.phi))/a)},e.es=0},"mbt_fps","McBryde-Thomas Flat-Pole Sine (No. 2)","Cyl., Sph."),tt(function(e){var r=1e-10,a=0,o=X(e.params,"tlat_ts");o&&(a=X(e.params,"rlat_ts"))>=k&&U(-24),e.es?(o&&(e.k0=He(i(a),s(a),e.es)),e.inv=function(t,i){i.phi=mi(p(-t.y/e.k0),e.e),i.phi===x&&j(),i.lam=t.x/e.k0},e.fwd=function(s,n){t(t(s.phi)-k)<=r&&q(),n.x=e.k0*s.lam,n.y=-e.k0*_(fi(s.phi,i(s.phi),e.e))}):(e.inv=function(t,i){i.phi=k-2*h(p(-t.y/e.k0)),i.lam=t.x/e.k0},e.fwd=function(i,s){t(t(i.phi)-k)<=r&&q(),s.x=e.k0*i.lam,s.y=e.k0*_(n(M+.5*i.phi))})},"merc","Mercator","Cyl, Sph&Ell\nlat_ts="),tt(function(e){e.k0=1,e.inv=function(t,i){i.phi=k-2*h(p(-t.y/e.k0)),i.lam=t.x/e.k0},e.fwd=function(i,s){t(t(i.phi)-k)<=F&&q(),s.x=e.k0*i.lam,s.y=e.k0*_(n(M+.5*i.phi))}},"webmerc","Web Mercator / Pseudo Mercator","Cyl, Ell"),tt(function(t){t.fwd=function(t,e){e.x=t.lam,e.y=1.25*_(n(M+.4*t.phi))},t.inv=function(t,e){e.lam=t.x,e.phi=2.5*(h(p(.8*t.y))-M)},t.es=0},"mill","Miller Cylindrical","Cyl, Sph"),tt(function(t){t.lam0=20*C,t.phi0=18*C,t.es=0,vi(t,[[.9245,0],[0,0],[.01943,0]])},"mil_os","Miller Oblated Stereographic","Azi(mod)"),tt(function(t){t.lam0=-165*C,t.phi0=-10*C,t.es=0,vi(t,[[.721316,0],[0,0],[-.0088162,-.00617325]])},"lee_os","Lee Oblated Stereographic","Azi(mod)"),tt(function(t){t.lam0=-96*C,t.phi0=39*C,t.es=0,t.a=6370997,vi(t,[[.98879,0],[0,0],[-.050909,0],[0,0],[.075528,0]])},"gs48","Mod Stereographic of 48 U.S.","Azi(mod)"),tt(function(t){var e;t.lam0=-152*C,t.phi0=64*C,0!=t.es?(e=[[.9945303,0],[.0052083,-.0027404],[.0072721,.0048181],[-.0151089,-.1932526],[.0642675,-.1381226],[.3582802,-.2884586]],t.a=6378206.4,t.e=c(t.es=.00676866)):(e=[[.9972523,0],[.0052513,-.0041175],[.0074606,.0048125],[-.0153783,-.1968253],[.0636871,-.1408027],[.3660976,-.2937382]],t.a=6370997),vi(t,e)},"alsk","Mod Stereographic of Alaska","Azi(mod)"),tt(function(t){var e;t.lam0=-120*C,t.phi0=45*C,0!=t.es?(e=[[.9827497,0],[.0210669,.0053804],[-.1031415,-.0571664],[-.0323337,-.0322847],[.0502303,.1211983],[.0251805,.0895678],[-.0012315,-.1416121],[.0072202,-.1317091],[-.0194029,.0759677],[-.0210072,.0834037]],t.a=6378206.4,t.e=c(t.es=.00676866)):(e=[[.984299,0],[.0211642,.0037608],[-.1036018,-.0575102],[-.0329095,-.0320119],[.0499471,.1223335],[.026046,.0899805],[7388e-7,-.1435792],[.0075848,-.1334108],[-.0216473,.0776645],[-.0225161,.0853673]],t.a=6370997),vi(t,e)},"gs50","Mod Stereographic of 50 U.S.","Azi(mod)"),tt(function(e){var i=.8707,s=-.131979,n=-.013791,r=.003971,a=-.001529,o=1.007226,h=.015085,l=-.044475,c=.028874,u=-.005916,p=o,_=3*h,d=7*l,f=9*c,m=11*u,y=.8707*.52*w;e.es=0,e.fwd=function(t,e){var p,_;_=(p=t.phi*t.phi)*p,e.x=t.lam*(i+p*(s+p*(n+_*p*(r+p*a)))),e.y=t.phi*(o+p*(h+_*(l+c*p+u*_)))},e.inv=function(e,g){var v,x,b,w,S=e.x,C=e.y;for(C>y?C=y:C<-y&&(C=-y),v=C;v-=x=(v*(o+(b=v*v)*(h+(w=b*b)*(l+c*b+u*w)))-C)/(p+b*(_+w*(d+f*b+m*w))),!(t(x)<1e-11););g.phi=v,b=v*v,g.lam=S/(i+b*(s+b*(n+b*b*b*(r+b*a))))}},"natearth","Natural Earth","PCyl., Sph."),tt(function(e){var i=.84719,s=-.13063,n=-.04515,r=.05494,a=-.02326,o=.00331,h=1.01183,l=-.02625,c=.01926,u=-.00396,p=h,_=9*l,d=.45334622460635143*w;e.es=0,e.fwd=function(t,e){var p,_,d;d=(p=t.phi*t.phi)*(_=p*p),e.x=t.lam*(i+s*p+d*d*(n+r*p+a*_+o*d)),e.y=t.phi*(h+_*_*(l+c*p+u*_))},e.inv=function(e,f){var m,y,g,v,x,b=e.x,w=e.y;for(w>d?w=d:w<-d&&(w=-d),m=w;m-=y=(m*(h+(v=(g=m*m)*g)*v*(l+c*g+u*v))-w)/(p+v*v*(_+.21186*g+-.05148*v)),!(t(y)<1e-11););f.phi=m,x=(g=m*m)*(v=g*g),f.lam=b/(i+s*g+x*x*(n+r*g+a*v+o*x))}},"natearth2","Natural Earth 2","PCyl., Sph."),tt(function(e){e.inv=function(t,e){e.lam=2*t.x/(1+s(t.y)),e.phi=Ye(.5*(t.y+i(t.y)))},e.fwd=function(e,n){var r,a,o;for(r=2*i(e.phi),a=e.phi*e.phi,e.phi*=1.00371+a*(-.011412*a-.0935382),o=10;o&&(e.phi-=a=(e.phi+i(e.phi)-r)/(1+s(e.phi)),!(t(a)<1e-7));--o);n.x=.5*e.lam*(1+s(e.phi)),n.y=e.phi},e.es=0},"nell","Nell","PCyl., Sph."),tt(function(e){e.es=0,e.fwd=function(t,e){e.x=.5*t.lam*(1+s(t.phi)),e.y=2*(t.phi-n(.5*t.phi))},e.inv=function(e,i){var r,a,o,h;for(o=.5*e.y,h=9;h>0&&(a=s(.5*i.phi),i.phi-=r=(i.phi-n(i.phi/2)-o)/(1-.5/(a*a)),!(t(r)<1e-7));--h);h?i.lam=2*e.x/(1+s(i.phi)):(i.phi=o<0?-k:k,i.lam=2*e.x)}},"nell_h","Nell-Hammer","PCyl., Sph."),tt(function(e){e.es=0,e.fwd=function(e,n){var r=1e-10;if(t(e.lam)<r)n.x=0,n.y=e.phi;else if(t(e.phi)<r)n.x=e.lam,n.y=0;else if(t(t(e.lam)-k)<r)n.x=e.lam*s(e.phi),n.y=k*i(e.phi);else if(t(t(e.phi)-k)<r)n.x=0,n.y=e.phi;else{var a=k/e.lam-e.lam/k,o=e.phi/k,h=i(e.phi),l=(1-o*o)/(h-o),u=a/l,p=(a*h/l-.5*a)/(1+(u*=u)),_=(h/u+.5*l)/(1+1/u);n.x=s(e.phi),n.x=c(p*p+n.x*n.x/(1+u)),n.x=k*(p+(e.lam<0?-n.x:n.x)),n.y=c(_*_-(h*h/u+l*h-1)/(1+1/u)),n.y=k*(_+(e.phi<0?n.y:-n.y))}}},"nicol","Nicolosi Globular","Misc Sph, no inv"),tt(function(t){xi(t,X(t.params,"dh"))},"nsper","Near-sided perspective","Azi, Sph\nh="),tt(function(t){var e=X(t.params,"dtilt")*C,i=X(t.params,"dazi")*C,s=X(t.params,"dh");xi(t,s,e,i)},"tpers","Tilted perspective","Azi, Sph\ntilt= azi= h="),tt(function(e){var i=[[.7557853228,0],[.249204646,.003371507],[-.001541739,.04105856],[-.10162907,.01727609],[-.26623489,-.36249218],[-.6870983,-1.1651967]],s=[1.5627014243,.5185406398,-.03333098,-.1052906,-.0368594,.007317,.0122,.00394,-.0013],n=[.6399175073,-.1358797613,.063294409,-.02526853,.0117879,-.0055161,.0026906,-.001333,67e-5,-34e-5];e.ra=1/(e.a=6378388),e.lam0=173*C,e.phi0=-41*C,e.x0=251e4,e.y0=6023150,e.inv=function(n,r){var a,o,h,l,c,u,p={r:n.y,i:n.x},_={};for(a=20;a>0&&((c=gi(p,i,_)).r-=n.y,c.i-=n.x,u=_.r*_.r+_.i*_.i,p.r+=h=-(c.r*_.r+c.i*_.i)/u,p.i+=l=-(c.i*_.r-c.r*_.i)/u,!(t(h)+t(l)<=1e-10));--a);if(a>0){for(r.lam=p.i,o=s.length-1,r.phi=s[o],--o;o>=0;--o)r.phi=s[o]+p.r*r.phi;r.phi=e.phi0+p.r*r.phi*.484813681109536}else r.lam=r.phi=x},e.fwd=function(t,s){var r=n.length-1,a={r:n[r]},o=2.0626480624709638*(t.phi-e.phi0);for(--r;r>=0;--r)a.r=n[r]+o*a.r;a.r*=o,a.i=t.lam,a=yi(a,i),s.x=a.i,s.y=a.r}},"nzmg","New Zealand Map Grid","fixed Earth"),tt(function(e){var r,a,o,c,u,p,_,d,f,m,y,g,v,b,w,A=1e-10;r=X(e.params,"so_proj"),a=Q[r],r||U(-26),a&&"ob_tran"!=r||U(-37),e.es=0,o={},Object.keys(e).forEach(function(t){o[t]=e[t]}),a.init(o),o.is_latlong&&1==e.to_meter&&(e.to_meter=C,e.fr_meter=S),X(e.params,"to_alpha")?(d=X(e.params,"ro_lon_c"),f=X(e.params,"ro_lat_c"),m=X(e.params,"ro_alpha"),t(t(f)-k)<=A&&U(-32),c=d+ei(-s(m),-i(m)*i(f)),_=Ye(s(f)*i(m))):X(e.params,"to_lat_p")?(c=X(e.params,"ro_lon_p"),_=X(e.params,"ro_lat_p")):(y=X(e.params,"ro_lon_1"),v=X(e.params,"ro_lat_1"),g=X(e.params,"ro_lon_2"),b=X(e.params,"ro_lat_2"),(t(v-b)<=A||(w=t(v))<=A||t(w-k)<=A||t(t(b)-k)<=A)&&U(-33),c=l(s(v)*i(b)*s(y)-i(v)*s(b)*s(g),i(v)*s(b)*i(g)-s(v)*i(b)*i(y)),_=h(-s(c-y)/n(v))),t(_)>A?(u=s(_),p=i(_),e.fwd=function(t,e){var n,r,a;n=s(t.lam),r=i(t.phi),a=s(t.phi),t.lam=Mt(ei(a*i(t.lam),p*a*n+u*r)+c),t.phi=Ye(p*r-u*a*n),o.fwd(t,e)},e.inv=o.inv?function(t,e){var n,r,a;o.inv(t,e),e.lam!=x&&(n=s(e.lam-=c),r=i(e.phi),a=s(e.phi),e.phi=Ye(p*r+u*a*n),e.lam=ei(a*i(e.lam),p*a*n-u*r))}:null):(e.fwd=function(t,e){var n,r;n=s(t.phi),r=s(t.lam),t.lam=Mt(ei(n*i(t.lam),i(t.phi))+c),t.phi=Ye(-n*r),o.fwd(t,e)},e.inv=o.inv?function(t,e){var n,r;o.inv(t,e),e.lam!=x&&(n=s(e.phi),r=e.lam-c,e.lam=ei(n*i(r),-i(e.phi)),e.phi=Ye(n*s(r)))}:null)},"ob_tran","General Oblique Transformation","Misc Sph\no_proj= plus parameters for projection\no_lat_p= o_lon_p= (new pole) or\no_alpha= o_lon_c= o_lat_c= or\no_lon_1= o_lat_1= o_lon_2= o_lat_2="),tt(function(t){var e,r,o,u,p,_,d,f,m,y,g;d=1/t.k0,f=t.k0,X(t.params,"talpha")?(_=X(t.params,"ralpha"),p=X(t.params,"rlonc"),g=h(-s(_)/(-i(0)*i(_)))+p,m=a(s(0)*i(_))):(e=X(t.params,"rlat_1"),r=X(t.params,"rlat_2"),o=X(t.params,"rlon_1"),u=X(t.params,"rlon_2"),g=l(s(e)*i(r)*s(o)-i(e)*s(r)*s(u),i(e)*s(r)*i(u)-s(e)*i(r)*i(o)),o==-k&&(g=-g),m=h(-s(g-o)/n(e))),t.lam0=g+k,y=s(m),m=i(m),g=i(g),t.es=0,t.fwd=function(t,e){var r;e.y=i(t.lam),r=s(t.lam),e.x=h((n(t.phi)*y+m*e.y)/r),r<0&&(e.x+=w),e.x*=f,e.y=d*(m*i(t.phi)-y*s(t.phi)*e.y)},t.inv=function(t,e){var n,r;t.y/=d,t.x/=f,n=c(1-t.y*t.y),e.phi=a(t.y*m+n*y*(r=i(t.x))),e.lam=l(n*m*r-t.y*y,n*s(t.x))}},"ocea","Oblique Cylindrical Equal Area","Cyl, Sph lonc= alpha= or\nlat_1= lat_2= lon_1= lon_2="),tt(function(e){var r,o,d,f,m,y,g,v,b,S,C,A,E,I,P,T,L,N,R,O,G,z,B,$,V,W,H,K=1e-7,Z=0,J=0,Y=0,Q=0,tt=0,et=0,it=0,st=0;H=X(e.params,"tno_rot"),0!=(A=X(e.params,"talpha"))&&(it=X(e.params,"ralpha")),0!=(E=X(e.params,"tgamma"))&&(Z=X(e.params,"rgamma")),A||E?(J=X(e.params,"rlonc"),(st=X(e.params,"tno_off")||X(e.params,"tno_uoff"))&&(X(e.params,"sno_uoff"),X(e.params,"sno_off"))):(Y=X(e.params,"rlon_1"),tt=X(e.params,"rlat_1"),Q=X(e.params,"rlon_2"),et=X(e.params,"rlat_2"),(t(tt-et)<=K||(r=t(tt))<=K||t(r-k)<=K||t(t(e.phi0)-k)<=K||t(t(et)-k)<=K)&&U(-33)),o=c(e.one_es),t(e.phi0)>F?(v=i(e.phi0),d=s(e.phi0),r=1-e.es*v*v,P=d*d,P=c(1+e.es*P*P/e.one_es),I=P*e.k0*o/r,(m=(f=P*o/(d*c(r)))*f-1)<=0?m=0:(m=c(m),e.phi0<0&&(m=-m)),T=m+=f,T*=u(fi(e.phi0,v,e.e),P)):(P=1/o,I=e.k0,T=f=m=1),A||E?(A?(C=a(i(it)/f),E||(Z=it)):it=a(f*i(C=Z)),e.lam0=J-a(.5*(m-1/m)*n(C))/P):(y=u(fi(tt,i(tt),e.e),P),g=u(fi(et,i(et),e.e),P),m=T/y,b=(g-y)/(g+y),S=((S=T*T)-g*y)/(S+g*y),(r=Y-Q)<-w?Q-=D:r>w&&(Q+=D),e.lam0=Mt(.5*(Y+Q)-h(S*n(.5*P*(Y-Q))/b)/P),C=h(2*i(P*Mt(Y-e.lam0))/(m-1/m)),Z=it=a(f*i(C))),O=i(C),G=s(C),z=i(Z),B=s(Z),N=1/(L=I*(R=1/P)),st?W=0:(W=t(L*h(c(f*f-1)/s(it))),e.phi0<0&&(W=-W)),$=L*_(n(M-(m=.5*C))),V=L*_(n(M+m)),e.fwd=function(n,r){var a,o,h,c,p,d,f,m;t(t(n.phi)-k)>F?(a=.5*((p=T/u(fi(n.phi,i(n.phi),e.e),P))-(d=1/p)),o=.5*(p+d),c=i(P*n.lam),t(t(h=(a*O-c*G)/o)-1)<F&&q(),m=.5*L*_((1-h)/(1+h)),d=s(P*n.lam),f=t(d)<K?I*n.lam:L*l(a*G+c*O,d)):(m=n.phi>0?$:V,f=L*n.phi),H?(r.x=f,r.y=m):(f-=W,r.x=m*B+f*z,r.y=f*B-m*z)},e.inv=function(n,r){var a,o,h,_,d,f,m;H?(o=n.y,a=n.x):(o=n.x*B-n.y*z,a=n.y*B+n.x*z+W),_=.5*((h=p(-N*o))-1/h),d=.5*(h+1/h),f=i(N*a),t(t(m=(f*G+_*O)/d)-1)<F?(r.lam=0,r.phi=m<0?-k:k):(r.phi=T/c((1+m)/(1-m)),(r.phi=mi(u(r.phi,1/P),e.e))==x&&j(),r.lam=-R*l(_*G-f*O,s(N*a)))}},"omerc","Oblique Mercator","Cyl, Sph&Ell no_rot\nalpha= [gamma=] [no_off] lonc= or\nlon_1= lat_1= lon_2= lat_2="),tt(function(e){var n=1e-10,r={};t(t(e.phi0)-k)<=n?r.mode=e.phi0<0?1:0:t(e.phi0)>n?(r.mode=3,r.sinph0=i(e.phi0),r.cosph0=s(e.phi0)):r.mode=2,e.fwd=function(a,o){var h,l,c;switch(l=s(a.phi),h=s(a.lam),r.mode){case 2:l*h<-1e-10&&q(),o.y=i(a.phi);break;case 3:r.sinph0*(c=i(a.phi))+r.cosph0*l*h<-1e-10&&q(),o.y=r.cosph0*c-r.sinph0*l*h;break;case 0:h=-h;case 1:t(a.phi-e.phi0)-n>k&&q(),o.y=l*h}o.x=l*i(a.lam)},e.inv=function(i,s){var h,u,p;if((p=h=d(i.x,i.y))>1&&(p-1>n&&j(),p=1),u=c(1-p*p),t(h)<=n)s.phi=e.phi0,s.lam=0;else{switch(r.mode){case 0:i.y=-i.y,s.phi=o(p);break;case 1:s.phi=-o(p);break;case 2:case 3:2==r.mode?(s.phi=i.y*p/h,i.x*=p,i.y=u*h):(s.phi=u*r.sinph0+i.y*p*r.cosph0/h,i.y=(u-r.sinph0*s.phi)*h,i.x*=p*r.cosph0),t(s.phi)>=1?s.phi=s.phi<0?-k:k:s.phi=a(s.phi)}s.lam=0!=i.y||3!=r.mode&&2!=r.mode?l(i.x,i.y):0==i.x?0:i.x<0?-k:k}},e.es=0},"ortho","Orthographic","Azi, Sph."),tt(function(e){var i=1.0148,s=.23185,n=-.14499,r=.02406,a=i,o=5*s,h=7*n,l=908571831.7;e.es=0,e.fwd=function(t,e){var a=t.phi*t.phi;e.x=t.lam,e.y=t.phi*(i+a*a*(s+a*(n+r*a)))},e.inv=function(e,c){var u,p,_,d;for(u=e.y,e.y>l?e.y=l:e.y<-l&&(e.y=-l),d=100;d&&(u-=p=(u*(i+(_=u*u)*_*(s+_*(n+r*_)))-e.y)/(a+_*_*(o+_*(h+.21654*_))),!(t(p)<1e-11));--d);c.phi=u,c.lam=e.x}},"patterson","Patterson Cylindrical","Cyl., Sph."),tt(function(e){var r,o,h=1e-10,l=1e-12;e.es?(o=Ze(e.es),r=Xe(e.phi0,i(e.phi0),s(e.phi0),o),e.fwd=function(n,a){var l,c,u;t(n.phi)<=h?(a.x=n.lam,a.y=-r):(c=i(n.phi),l=t(u=s(n.phi))>h?He(c,u,e.es)/c:0,a.x=l*i(n.lam*=c),a.y=Xe(n.phi,c,u,o)-r+l*(1-s(n.lam)))},e.inv=function(u,p){var _,d,f,m,y,g,v,x,b,w,S=u.x,C=u.y;if(t(C+=r)<=h)p.lam=S,p.phi=0;else{for(_=C*C+S*S,p.phi=C,w=20;w>0&&(y=(f=i(p.phi))*(m=s(p.phi)),t(m)<l&&j(),d=f*(x=c(1-e.es*f*f))/m,v=(g=Xe(p.phi,f,m,o))*g+_,x=e.one_es/(x*x*x),p.phi+=b=(g+g+d*v-2*C*(d*g+1))/(e.es*y*(v-2*C*g)/d+2*(C-g)*(d*x-1/y)-x-x),!(t(b)<=l));--w);w||j(),d=i(p.phi),p.lam=a(S*n(p.phi)*c(1-e.es*d*d))/i(p.phi)}}):(r=-e.phi0,e.fwd=function(a,o){var l,c;t(a.phi)<=h?(o.x=a.lam,o.y=r):(l=1/n(a.phi),o.x=i(c=a.lam*i(a.phi))*l,o.y=a.phi-e.phi0+l*(1-s(c)))},e.inv=function(s,r){var o,l,c,u;if(t(s.y=e.phi0+s.y)<=h)r.lam=s.x,r.phi=0;else{r.phi=s.y,o=s.x*s.x+s.y*s.y,u=10;do{c=n(r.phi),r.phi-=l=(s.y*(r.phi*c+1)-r.phi-.5*(r.phi*r.phi+o)*c)/((r.phi-s.y)/c-1)}while(t(l)>1e-10&&--u);u||j(),r.lam=a(s.x*n(r.phi))/i(r.phi)}})},"poly","Polyconic (American)","Conic, Sph&Ell"),tt(function(e){var n=1.8949,r=1.71848,a=.6141848493043784,o=1.0471975511965976;e.es=0,e.fwd=function(e,h){var l,c,u,p,_;for(l=a*i(e.phi),u=e.phi*e.phi,e.phi*=.615709+u*(.00909953+.0046292*u),_=10;_&&(c=s(e.phi),u=i(e.phi),e.phi-=p=(e.phi+u*(c-1)-l)/(1+c*(c-1)-u*u),!(t(p)<1e-10));--_);_||(e.phi=e.phi<0?-o:o),h.x=n*e.lam*(s(e.phi)-.5),h.y=r*i(e.phi)},e.inv=function(t,e){var o;e.phi=Ye(t.y/r),e.lam=t.x/(n*((o=s(e.phi))-.5)),e.phi=Ye((e.phi+i(e.phi)*(o-1))/a)}},"putp2","Putnins P2","PCyl., Sph."),tt(bi,"putp3","Putnins P3","PCyl., Sph."),tt(function(t){bi(t,!0)},"putp3p","Putnins P3'","PCyl., Sph."),tt(function(t){wi(t,.874038744,3.883251825)},"putp4p","Putnins P4'","PCyl., Sph."),tt(function(t){wi(t,1,4.442882938)},"weren","Werenskiold I","PCyl., Sph."),tt(Si,"putp5","Putnins P5","PCyl., Sph."),tt(function(t){Si(t,!0)},"putp5p","Putnins P5'","PCyl., Sph."),tt(Ci,"putp6","Putnins P6","PCyl., Sph."),tt(function(t){Ci(t,!0)},"putp6p","Putnins P6'","PCyl., Sph."),tt(function(e){var r,a,u,p;function _(e,i,s){var n,r;return e<1e-10?(n=0,r=0):(r=l(i,s),t(r)<=M?n=0:r>M&&r<=k+M?(n=1,r-=k):r>k+M||r<=-(k+M)?(n=2,r=r>=0?r-w:r+w):(n=3,r+=k)),{area:n,theta:r}}function d(t,e){var i=t+e;return i<-w?i+=D:i>+w&&(i-=D),i}r=e.phi0>=k-M/2?4:e.phi0<=-(k-M/2)?5:t(e.lam0)<=M?0:t(e.lam0)<=k+M?e.lam0>0?1:3:2,0!==e.es&&(e.a,e.a,a=e.a*c(1-e.es),u=1-(e.a-a)/e.a,p=u*u),e.fwd=function(t,a){var l,u,f,m,y,g,v,x,b,S,C,A,E,D;l=0!==e.es?h(p*n(t.phi)):t.phi,u=t.lam,4==r?(m=k-l,u>=M&&u<=k+M?(v=0,f=u-k):u>k+M||u<=-(k+M)?(v=1,f=u>0?u-w:u+w):u>-(k+M)&&u<=-M?(v=2,f=u+k):(v=3,f=u)):5==r?(m=k+l,u>=M&&u<=k+M?(v=0,f=-u+k):u<M&&u>=-M?(v=1,f=-u):u<-M&&u>=-(k+M)?(v=2,f=-u-k):(v=3,f=u>0?-u+w:-u-w)):(1==r?u=d(u,+k):2==r?u=d(u,+w):3==r&&(u=d(u,-k)),C=i(l),A=s(l),E=i(u),x=A*s(u),b=A*E,S=C,0==r?D=_(m=o(x),S,b):1==r?D=_(m=o(b),S,-x):2==r?D=_(m=o(-x),S,-b):3==r?D=_(m=o(-b),S,x):(m=0,D={area:0,theta:0}),f=D.theta,v=D.area),g=h(12/w*(f+o(i(f)*s(M))-k)),y=c((1-s(m))/(s(g)*s(g))/(1-s(h(1/s(f))))),1==v?g+=k:2==v?g+=w:3==v&&(g+=I),a.x=y*s(g),a.y=y*i(g)},e.inv=function(_,f){var m,y,g,v,x,b,S,C,A,E,M,I,D;if(y=h(c(_.x*_.x+_.y*_.y)),m=l(_.y,_.x),_.x>=0&&_.x>=t(_.y)?E=0:_.y>=0&&_.y>=t(_.x)?(E=1,m-=k):_.x<0&&-_.x>=t(_.y)?(E=2,m=m<0?m+w:m-w):(E=3,m+=k),A=w/12*n(m),x=i(A)/(s(A)-1/c(2)),b=h(x),(S=1-(g=s(m))*g*(v=n(y))*v*(1-s(h(1/s(b)))))<-1?S=-1:S>1&&(S=1),4==r)C=o(S),f.phi=k-C,f.lam=0==E?b+k:1==E?b<0?b+w:b-w:2==E?b-k:b;else if(5==r)C=o(S),f.phi=C-k,f.lam=0==E?-b+k:1==E?-b:2==E?-b-k:b<0?-b-w:-b+w;else{var P,T,L;A=(P=S)*P,T=(A+=(L=A>=1?0:c(1-A)*i(b))*L)>=1?0:c(1-A),1==E?(A=T,T=-L,L=A):2==E?(T=-T,L=-L):3==E&&(A=T,T=L,L=-A),1==r?(A=P,P=-T,T=A):2==r?(P=-P,T=-T):3==r&&(A=P,P=T,T=-A),f.phi=o(-L)-k,f.lam=l(T,P),1==r?f.lam=d(f.lam,-k):2==r?f.lam=d(f.lam,-w):3==r&&(f.lam=d(f.lam,+k))}0!==e.es&&(M=f.phi<0?1:0,I=n(f.phi),D=a/c(I*I+p),f.phi=h(c(e.a*e.a-D*D)/(u*D)),M&&(f.phi=-f.phi))}},"qsc","Quadrilateralized Spherical Cube","Azi, Sph."),tt(function(i){var s=l([[1,22199e-21,-715515e-10,31103e-10],[.9986,-482243e-9,-24897e-9,-13309e-10],[.9954,-83103e-8,-448605e-10,-9.86701e-7],[.99,-.00135364,-59661e-9,36777e-10],[.9822,-.00167442,-449547e-11,-572411e-11],[.973,-.00214868,-903571e-10,1.8736e-8],[.96,-.00305085,-900761e-10,164917e-11],[.9427,-.00382792,-653386e-10,-26154e-10],[.9216,-.00467746,-10457e-8,481243e-11],[.8962,-.00536223,-323831e-10,-543432e-11],[.8679,-.00609363,-113898e-9,332484e-11],[.835,-.00698325,-640253e-10,9.34959e-7],[.7986,-.00755338,-500009e-10,9.35324e-7],[.7597,-.00798324,-35971e-9,-227626e-11],[.7186,-.00851367,-701149e-10,-86303e-10],[.6732,-.00986209,-199569e-9,191974e-10],[.6213,-.010418,883923e-10,624051e-11],[.5722,-.00906601,182e-6,624051e-11],[.5322,-.00677797,275608e-9,624051e-11]]),n=l([[-520417e-23,.0124,121431e-23,-845284e-16],[.062,.0124,-1.26793e-9,4.22642e-10],[.124,.0124,5.07171e-9,-1.60604e-9],[.186,.0123999,-1.90189e-8,6.00152e-9],[.248,.0124002,7.10039e-8,-2.24e-8],[.31,.0123992,-2.64997e-7,8.35986e-8],[.372,.0124029,9.88983e-7,-3.11994e-7],[.434,.0123893,-369093e-11,-4.35621e-7],[.4958,.0123198,-102252e-10,-3.45523e-7],[.5571,.0121916,-154081e-10,-5.82288e-7],[.6176,.0119938,-241424e-10,-5.25327e-7],[.6769,.011713,-320223e-10,-5.16405e-7],[.7346,.0113541,-397684e-10,-6.09052e-7],[.7903,.0109107,-489042e-10,-104739e-11],[.8435,.0103431,-64615e-9,-1.40374e-9],[.8936,.00969686,-64636e-9,-8547e-9],[.9394,.00840947,-192841e-9,-42106e-10],[.9761,.00616527,-256e-6,-42106e-10],[1,.00328947,-319159e-9,-42106e-10]]),r=.8487,a=1.3523;function o(t,e){return t[0]+e*(t[1]+e*(t[2]+e*t[3]))}function h(t,e){return t[1]+e*(t[2]+t[2]+3*e*t[3])}function l(t){return t.map(function(t){return new Float32Array(t)})}i.es=0,i.fwd=function(i,h){var l,c;(l=e(11.459155902616464*(c=t(i.phi))))<0&&q(),l>=18&&(l=17),c=S*(c-.08726646259971647*l),h.x=o(s[l],c)*r*i.lam,h.y=o(n[l],c)*a,i.phi<0&&(h.y=-h.y)},i.inv=function(i,l){var c,u,p,_;if(l.lam=i.x/r,l.phi=t(i.y/a),l.phi>=1)l.phi>1.000001?j():(l.phi=i.y<0?-k:k,l.lam/=s[18][0]);else{if((_=e(18*l.phi))<0||_>=18)return j();for(;;)if(n[_][0]>l.phi)--_;else{if(!(n[_+1][0]<=l.phi))break;++_}for(p=new Float32Array(n[_]),c=5*(l.phi-p[0])/(n[_+1][0]-p[0]),p[0]-=l.phi;c-=u=o(p,c)/h(p,c),!(t(u)<1e-8););l.phi=(5*_+c)*C,i.y<0&&(l.phi=-l.phi),l.lam/=o(s[_],c)}}},"robin","Robinson","PCyl., Sph."),tt(Ai("EULER"),"euler","Euler","Conic, Sph\nlat_1= and lat_2="),tt(Ai("MURD1"),"murd1","Murdoch I","Conic, Sph\nlat_1= and lat_2="),tt(Ai("MURD2"),"murd2","Murdoch II","Conic, Sph\nlat_1= and lat_2="),tt(Ai("MURD3"),"murd3","Murdoch III","Conic, Sph\nlat_1= and lat_2="),tt(Ai("PCONIC"),"pconic","Perspective Conic","Conic, Sph\nlat_1= and lat_2="),tt(Ai("TISSOT"),"tissot","Tissot","Conic, Sph\nlat_1= and lat_2="),tt(Ai("VITK1"),"vitk1","Vitkovsky I","Conic, Sph\nlat_1= and lat_2="),tt(function(e){var r,a,o,l,u,d,f,m,y;o=.5*e.e,f=s(e.phi0),f*=f,a=c(1+e.es*f*f*e.rone_es),y=i(e.phi0),u=s(m=Ye(d=y/a)),y*=e.e,r=_(n(M+.5*m))-a*(_(n(M+.5*e.phi0))-o*_((1+y)/(1-y))),l=e.k0*c(e.one_es)/(1-y*y),e.inv=function(c,f){var m,y,g,v,x,b,w,S,C;for(g=2*(h(p(c.y/l))-M),v=c.x/l,x=s(g),m=Ye(u*i(g)+d*x*s(v)),y=Ye(x*i(v)/s(m)),w=(r-_(n(M+.5*m)))/a,C=6;C&&(b=e.e*i(m),m-=S=(w+_(n(M+.5*m))-o*_((1+b)/(1-b)))*(1-b*b)*s(m)*e.rone_es,!(t(S)<1e-10));--C);C?(f.phi=m,f.lam=y/a):j()},e.fwd=function(t,c){var f,m,y,g,v,x;v=e.e*i(t.phi),f=2*h(p(a*(_(n(M+.5*t.phi))-o*_((1+v)/(1-v)))+r))-k,m=a*t.lam,x=s(f),y=Ye(u*i(f)-d*x*s(m)),g=Ye(x*i(m)/s(y)),c.x=l*g,c.y=l*_(n(M+.5*y))}},"somerc","Swiss. Obl. Mercator","Cyl, Ell\nFor CH1903"),tt(function(t){var e=X(t.params,"tlat_ts")?X(t.params,"rlat_ts"):k;Ei(t,e)},"stere","Stereographic","Azi, Sph&Ell\nlat_ts="),tt(function(t){t.phi0=X(t.params,"bsouth")?-k:k,t.k0=.994,t.x0=2e6,t.y0=2e6,t.lam0=0,t.es||U(-34),Ei(t,k)},"ups","Universal Polar Stereographic","Azi, Sph&Ell\nsouth"),tt(function(e){var r,o,p,_,f,m,y,g,v,x=(r=e.e,o=e.phi0,p=r*r,_=i(o),f=s(o),m=c(1-p)/(1-p*_*_),y=c(1+p*f*f*f*f/(1-p)),g=a(_/y),v=.5*y*r,{e:r,K:n(.5*g+M)/(u(n(.5*o+M),y)*Mi(r*_,v)),C:y,chi:g,ratexp:v,rc:m}),b=x.chi,w=2*x.rc,S=i(b),C=s(b);e.fwd=function(t,r){var a,o,l,c;t=function(t,e){return{phi:2*h(e.K*u(n(.5*t.phi+M),e.C)*Mi(e.e*i(t.phi),e.ratexp))-k,lam:e.C*t.lam}}(t,x),o=i(t.phi),a=s(t.phi),l=s(t.lam),c=e.k0*w/(1+S*o+C*a*l),r.x=c*a*i(t.lam),r.y=c*(C*o-S*a*l)},e.inv=function(r,o){var c,p,_,f,m=r.x/e.k0,y=r.y/e.k0;(c=d(m,y))?(p=2*l(c,w),_=i(p),f=s(p),o.phi=a(f*S+y*_*C/c),o.lam=l(m*_,c*C*f-y*S*_)):(o.phi=b,o.lam=0),function(e,s){e.phi;var r,a,o=u(n(.5*e.phi+M)/s.K,1/s.C);for(e.lam/=s.C,r=20;r>0&&(a=2*h(o*Mi(s.e*i(e.phi),-.5*s.e))-k,!(t(a-e.phi)<1e-14));--r)e.phi=a;r||z(-17)}(o,x)}},"sterea","Oblique Stereographic Alternative","Azimuthal, Sph&Ell"),tt(function(t){ki(t,1.50488,1.35439,!1)},"kav5","Kavraisky V","PCyl., Sph."),tt(function(t){ki(t,2,2,!1)},"qua_aut","Quartic Authalic","PCyl., Sph."),tt(function(t){ki(t,2,2,!0)},"fouc","Foucaut","PCyl., Sph."),tt(function(t){ki(t,1.48875,1.36509,!1)},"mbt_s","McBryde-Thomas Flat-Polar Sine (No. 1)","PCyl., Sph."),tt(function(t){t.es=0,t.fwd=function(e,r){r.x=s(e.phi)*i(e.lam)/t.k0,r.y=t.k0*(l(n(e.phi),s(e.lam))-t.phi0)},t.inv=function(e,n){var r;e.y=e.y/t.k0+t.phi0,e.x*=t.k0,r=c(1-e.x*e.x),n.phi=a(r*i(e.y)),n.lam=l(e.x,r*s(e.y))}},"tcea","Transverse Cylindrical Equal Area","Cyl, Sph"),tt(function(t){t.es=0,t.fwd=function(t,e){var s=n(t.phi/2),r=i(M*s);e.x=t.lam*(.74482-.34588*r*r),e.y=1.70711*s},t.inv=function(t,e){var s=t.y/1.70711,n=i(M*s);e.lam=t.x/(.74482-.34588*n*n),e.phi=2*h(s)}},"times","Times","Cyl, Sph"),tt(function(e){X(e.params,"bapprox")?Ii(e):function(e){if(0===e.es)return Ii(e);oi(e);var i=e.fwd,s=e.inv;Ii(e);var n=e.fwd,r=e.inv;e.fwd=function(e,s){t(e.lam)>3*C?i(e,s):n(e,s)},e.inv=function(e,i){t(e.x)>.053-.022*e.y*e.y?s(e,i):r(e,i)}}(e)},"tmerc","Transverse Mercator","Cyl, Sph&Ell"),tt(function(t){var i;t.es||U(-34),t.y0=X(t.params,"bsouth")?1e7:0,t.x0=5e5,X(t.params,"tzone")?(i=X(t.params,"izone"))>0&&i<=60?--i:U(-35):(i=e(30*(Mt(t.lam0)+w)/w))<0?i=0:i>=60&&(i=59),t.lam0=(i+.5)*w/30-w,t.k0=.9996,t.phi0=0,oi(t)},"utm","Universal Transverse Mercator (UTM)","Cyl, Sph\nzone= south"),tt(function(t){var e,r,a,o,h,c,u,p,_,f,m,y,g,v,x,b,w,S,C,A,E,M,I;A=X(t.params,"rlat_1"),S=X(t.params,"rlon_1"),E=X(t.params,"rlat_2"),C=X(t.params,"rlon_2"),A==E&&S==C&&U(-25),t.lam0=Mt(.5*(S+C)),f=Mt(C-S),e=s(A),a=s(E),r=i(A),o=i(E),c=e*o,u=r*a,h=e*a*i(f),_=Qe(r*o+e*a*s(f)),m=.5*_,M=l(a*i(f),e*o-r*a*s(f)),v=s(I=Ye(e*i(M))),x=i(I),b=Mt(l(e*s(M),r)-m),f*=.5,w=k-l(i(M)*r,s(M))-f,y=n(m),g=.5/i(m),p=.5/_,_*=_,t.fwd=function(t,n){var l,d,m,y,g,v,x;v=i(t.phi),x=s(t.phi),d=Qe(r*v+e*x*s(y=t.lam+f)),m=Qe(o*v+a*x*s(g=t.lam-f)),d*=d,m*=m,n.x=p*(l=d-m),l=_-l,n.y=p*ti(4*_*m-l*l),h*v-x*(c*i(y)-u*i(g))<0&&(n.y=-n.y)},t.inv=function(t,e){var n,r,a,o,h,c;a=(n=s(d(t.y,t.x+m)))+(r=s(d(t.y,t.x-m))),o=n-r,e.lam=-l(o,a*y),e.phi=Qe(d(y*a,o)*g),t.y<0&&(e.phi=-e.phi),c=i(e.phi),h=s(e.phi),e.phi=Ye(x*c+v*h*(a=s(e.lam-=b))),e.lam=l(h*i(e.lam),x*h*a-v*c)+w},t.es=0},"tpeqd","Two Point Equidistant","Misc Sph\nlat_1= lon_1= lat_2= lon_2="),tt(function(t){var e,n,r,a,o,h;(a=X(t.params,"dn"))>0&&a<=1==0&&U(-40),r=X(t.params,"dq")/3,o=X(t.params,"ralpha"),h=a*i(o),e=s(o)/c(1-h*h),n=1/(e*a),t.fwd=function(t,o){var h=t.phi=Ye(a*i(t.phi));o.x=e*t.lam*s(t.phi),h*=h,o.y=t.phi*(1+h*r)*n},t.es=0},"urm5","Urmaev V","PCyl., Sph., no inv.\nn= q= alpha="),tt(function(t){var e=X(t.params,"dn");(e<=0||e>1)&&U(-40),Di(t,e)},"urmfps","Urmaev Flat-Polar Sinusoidal","PCyl, Sph.\nn="),tt(function(t){Di(t,.8660254037844386)},"wag1","Wagner I (Kavraisky VI)","PCyl, Sph."),tt(function(e){var i=1e-10,r=.3333333333333333,h=9.869604401089358,l=19.739208802178716,u=4.934802200544679;e.fwd=function(e,s){var r,o,h,l,u;(u=t(e.phi/k))-i>1&&q(),u>1&&(u=1),t(e.phi)<=i?(s.x=e.lam,s.y=0):t(e.lam)<=i||t(u-1)<i?(s.x=0,s.y=w*n(.5*a(u)),e.phi<0&&(s.y=-s.y)):(o=(r=.5*t(w/e.lam-e.lam/w))*r,h=c(1-u*u),l=(h/=u+h-1)*h,u=h*(2/u-1),u*=u,s.x=h-u,h=u+o,s.x=w*(r*s.x+c(o*s.x*s.x-h*(l-u)))/h,e.lam<0&&(s.x=-s.x),s.y=t(s.x/w),s.y=1-s.y*(s.y+2*r),s.y<-i&&q(),s.y<0?s.y=0:s.y=c(s.y)*(e.phi<0?-w:w))},e.inv=function(e,n){var a,p,_,d,f,m,y,g,v,x,b,S,C;if(S=e.x*e.x,(b=t(e.y))<i)return n.phi=0,a=S*S+l*(S+u),n.lam=t(e.x)<=i?0:.5*(S-h+c(a))/e.x,n;C=e.y*e.y,d=(_=-w*b*((g=S+C)+h))+h*(g-3*C),p=w*b,v=2*c(-r*(m=_/(f=(y=g*g)+D*(b*g+w*(C+w*(b+k))))-r*(d/=f)*d)),(a=t(x=3*(x=.07407407407407407*d*d*d+(p*p-r*d*_)/f)/(m*v)))-i<=1?(x=a>1?x>0?0:w:o(x),n.phi=w*(v*s(x*r+4.188790204786391)-r*d),e.y<0&&(n.phi=-n.phi),a=y+l*(S-C+u),n.lam=t(e.x)<=i?0:.5*(g-h+(a<=0?0:c(a)))/e.x):j()}},"vandg","van der Grinten (I)","Misc Sph"),tt(function(t){Pi(t,!1)},"vandg2","van der Grinten II","Misc Sph, no inv."),tt(function(t){Pi(t,!0)},"vandg3","van der Grinten III","Misc Sph, no inv."),tt(function(e){e.es=0,e.fwd=function(e,i){var s,n,r,a,o,h,l,u,p=1e-10;t(e.phi)<p?(i.x=e.lam,i.y=0):t(e.lam)<p||t(t(e.phi)-k)<p?(i.x=0,i.y=e.phi):(h=(a=.5*((r=t(P*e.phi))*(8-r*(2+(o=r*r)))-5)/(o*(r-1)))*a,l=P*e.lam,l=c((l+=1/l)*l-4),t(e.lam)-k<0&&(l=-l),s=r+a,s=(l*((s*=s)+h-1)+2*c(s*(o+h*(u=l*l)-1)+(1-o)*(o*((n=r+3*a)*n+4*h)+h*(12*r*a+4*h))))/(4*s+u),i.x=k*s,i.y=k*c(1+l*t(s)-s*s),e.lam<0&&(i.x=-i.x),e.phi<0&&(i.y=-i.y))}},"vandg4","van der Grinten IV","Misc Sph, no inv."),tt(function(t){var e=.92483,n=1.38725,r=.88022,a=.8855;t.fwd=function(t,o){t.phi=Ye(r*i(a*t.phi)),o.x=e*t.lam*s(t.phi),o.y=n*t.phi},t.inv=function(t,o){o.phi=t.y/n,o.lam=t.x/(e*s(o.phi)),o.phi=Ye(i(o.phi)/r)/a}},"wag2","Wagner II","PCyl., Sph."),tt(function(t){var e=.6666666666666666,i=X(t.params,"rlat_ts"),n=s(i)/s(2*i/3);t.es=0,t.fwd=function(t,i){i.x=n*t.lam*s(e*t.phi),i.y=t.phi},t.inv=function(t,i){i.phi=t.y,i.lam=t.x/(n*s(e*i.phi))}},"wag3","Wagner III","PCyl., Sph.\nlat_ts="),tt(function(t){t.es=0,t.fwd=function(t,e){var n,r,o;n=a(e.y=.9063077870366499*i(t.phi)),e.x=2.66723*(r=s(n))*i(t.lam/=3),e.y*=1.24104*(o=1/c(.5*(1+r*s(t.lam)))),e.x*=o}},"wag7","Wagner VII","Misc Sph, no inv."),tt(function(t){var e=s(X(t.params,"rlat_ts"));t.fwd=function(t,i){i.x=.5*t.lam*(e+s(t.phi)),i.y=t.phi},t.inv=function(t,i){i.phi=t.y,i.lam=2*t.x/(e+s(i.phi))},t.es=0},"wink1","Winkel I","PCyl., Sph.\nlat_ts="),tt(function(e){var n=s(X(e.params,"rlat_1"));e.fwd=function(e,r){var a,o,h,l=e.phi;for(r.y=l*P,a=w*i(l),l*=1.8,h=10;h&&(l-=o=(l+i(l)-a)/(1+s(l)),!(t(o)<1e-7));--h);h?l*=.5:l=l<0?-k:k,r.x=.5*e.lam*(s(l)+n),r.y=M*(i(l)+r.y)},e.inv=null,e.es=0},"wink2","Winkel II","PCyl., Sph., no inv.\nlat_1=");var Ti=Pt;Ti.pj_init=mt,Ti.pj_fwd=kt,Ti.pj_inv=It,Ti.pj_transform=St,Ti.pj_add=tt,Ti.pj_fwd_deg=function(t,e){return kt({lam:t.lam*C,phi:t.phi*C},e)},Ti.pj_inv_deg=function(t,e){var i=It(t,e);return{lam:i.lam*S,phi:i.phi*S}},Ti.pj_transform_point=wt,Ti.internal={dmstod:H,dmstor:W,get_rtodms:function(t,e,i,s){var n=Dt(t,e,i,s);return function(t){return n(t*S)}},get_dtodms:Dt,get_proj_defn:st,pj_latlong_from_proj:function(t){return mt("+proj=latlong"+it(t))},pj_get_params:J,pj_datums:rt,pj_list:Q,pj_ellps:ht,pj_units:ct,pj_read_init_opts:ft,find_datum:ot,DEG_TO_RAD:C,RAD_TO_DEG:S,wkt_parse:ze,wkt_unpack:qe,convert_wkt_quotes:je,wkt_to_proj4:function(t){var e,i,s=ze(t);return s.PROJCS?e=Gt(i=s.PROJCS)(i):s.GEOGCS?e="+proj=longlat "+Ht(s.GEOGCS):s.GEOCCS?$t("geocentric coordinates are not supported"):$t("missing a supported WKT CS type"),e},wkt_from_proj4:function(t){return t.length&&(t=mt(t)),Re(et(t)?{GEOGCS:Yt(t)}:re(t))},wkt_make_projcs:re,wkt_get_geogcs_name:ee,wkt_stringify:Re,mproj_insert_libcache:function(t,e){_t[t]=e},mproj_search_libcache:dt,GeographicLib:Ve},v.exports=Ti}();var w=n.exports,S=e({__proto__:null,default:i(w)},[w]);class C{constructor(){this.ids=[],this.values=[],this.length=0}clear(){this.length=0}push(t,e){let i=this.length++;for(;i>0;){const t=i-1>>1,s=this.values[t];if(e>=s)break;this.ids[i]=this.ids[t],this.values[i]=s,i=t}this.ids[i]=t,this.values[i]=e}pop(){if(0===this.length)return;const t=this.ids,e=this.values,i=t[0],s=--this.length;if(s>0){const i=t[s],n=e[s];let r=0;const a=s>>1;for(;r<a;){const i=1+(r<<1),a=i+1,o=i+(+(a<s)&+(e[a]<e[i]));if(e[o]>=n)break;t[r]=t[o],e[r]=e[o],r=o}t[r]=i,e[r]=n}return i}peek(){return this.length>0?this.ids[0]:void 0}peekValue(){return this.length>0?this.values[0]:void 0}shrink(){this.ids.length=this.values.length=this.length}}const A=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class E{static from(t,e=0){if(e%8!=0)throw new Error("byteOffset must be 8-byte aligned.");if(!t||void 0===t.byteLength||t.buffer)throw new Error("Data must be an instance of ArrayBuffer or SharedArrayBuffer.");const[i,s]=new Uint8Array(t,e+0,2);if(251!==i)throw new Error("Data does not appear to be in a Flatbush format.");const n=s>>4;if(3!==n)throw new Error(`Got v${n} data when expected v3.`);const r=A[15&s];if(!r)throw new Error("Unrecognized array type.");const[a]=new Uint16Array(t,e+2,1),[o]=new Uint32Array(t,e+4,1);return new E(o,a,r,void 0,t,e)}constructor(t,e=16,i=Float64Array,s=ArrayBuffer,n,r=0){if(void 0===t)throw new Error("Missing required argument: numItems.");if(isNaN(t)||t<=0)throw new Error(`Unexpected numItems value: ${t}.`);this.numItems=+t,this.nodeSize=Math.min(Math.max(+e,2),65535),this.byteOffset=r;let a=t,o=a;this._levelBounds=[4*a];do{a=Math.ceil(a/this.nodeSize),o+=a,this._levelBounds.push(4*o)}while(1!==a);this.ArrayType=i,this.IndexArrayType=o<16384?Uint16Array:Uint32Array;const h=A.indexOf(i),l=4*o*i.BYTES_PER_ELEMENT;if(h<0)throw new Error(`Unexpected typed array class: ${i}.`);if(n)this.data=n,this._boxes=new i(n,r+8,4*o),this._indices=new this.IndexArrayType(n,r+8+l,o),this._pos=4*o,this.minX=this._boxes[this._pos-4],this.minY=this._boxes[this._pos-3],this.maxX=this._boxes[this._pos-2],this.maxY=this._boxes[this._pos-1];else{const n=this.data=new s(8+l+o*this.IndexArrayType.BYTES_PER_ELEMENT);this._boxes=new i(n,8,4*o),this._indices=new this.IndexArrayType(n,8+l,o),this._pos=0,this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,new Uint8Array(n,0,2).set([251,48+h]),new Uint16Array(n,2,1)[0]=e,new Uint32Array(n,4,1)[0]=t}this._queue=new C}add(t,e,i=t,s=e){const n=this._pos>>2,r=this._boxes;return this._indices[n]=n,r[this._pos++]=t,r[this._pos++]=e,r[this._pos++]=i,r[this._pos++]=s,t<this.minX&&(this.minX=t),e<this.minY&&(this.minY=e),i>this.maxX&&(this.maxX=i),s>this.maxY&&(this.maxY=s),n}finish(){if(this._pos>>2!==this.numItems)throw new Error(`Added ${this._pos>>2} items when expected ${this.numItems}.`);const t=this._boxes;if(this.numItems<=this.nodeSize)return t[this._pos++]=this.minX,t[this._pos++]=this.minY,t[this._pos++]=this.maxX,void(t[this._pos++]=this.maxY);const e=this.maxX-this.minX||1,i=this.maxY-this.minY||1,s=new Uint32Array(this.numItems);for(let n=0,r=0;n<this.numItems;n++){const a=t[r++],o=t[r++],h=t[r++],l=t[r++],c=Math.floor(65535*((a+h)/2-this.minX)/e),u=Math.floor(65535*((o+l)/2-this.minY)/i);s[n]=D(c,u)}k(s,t,this._indices,0,this.numItems-1,this.nodeSize);for(let e=0,i=0;e<this._levelBounds.length-1;e++){const s=this._levelBounds[e];for(;i<s;){const e=i;let n=t[i++],r=t[i++],a=t[i++],o=t[i++];for(let e=1;e<this.nodeSize&&i<s;e++)n=Math.min(n,t[i++]),r=Math.min(r,t[i++]),a=Math.max(a,t[i++]),o=Math.max(o,t[i++]);this._indices[this._pos>>2]=e,t[this._pos++]=n,t[this._pos++]=r,t[this._pos++]=a,t[this._pos++]=o}}}search(t,e,i,s,n){if(this._pos!==this._boxes.length)throw new Error("Data not yet indexed - call index.finish().");let r=this._boxes.length-4;const a=[],o=[];for(;void 0!==r;){const h=Math.min(r+4*this.nodeSize,M(r,this._levelBounds));for(let l=r;l<h;l+=4){const h=this._boxes[l];if(i<h)continue;const c=this._boxes[l+1];if(s<c)continue;const u=this._boxes[l+2];if(t>u)continue;const p=this._boxes[l+3];if(e>p)continue;const _=0|this._indices[l>>2];r>=4*this.numItems?a.push(_):(void 0===n||n(_,h,c,u,p))&&o.push(_)}r=a.pop()}return o}neighbors(t,e,i=1/0,s=1/0,n){if(this._pos!==this._boxes.length)throw new Error("Data not yet indexed - call index.finish().");let r=this._boxes.length-4;const a=this._queue,o=[],h=s*s;t:for(;void 0!==r;){const s=Math.min(r+4*this.nodeSize,M(r,this._levelBounds));for(let i=r;i<s;i+=4){const s=0|this._indices[i>>2],o=this._boxes[i],l=this._boxes[i+1],c=this._boxes[i+2],u=this._boxes[i+3],p=t<o?o-t:t>c?t-c:0,_=e<l?l-e:e>u?e-u:0,d=p*p+_*_;d>h||(r>=4*this.numItems?a.push(s<<1,d):(void 0===n||n(s))&&a.push(1+(s<<1),d))}for(;a.length&&1&a.peek();){if(a.peekValue()>h)break t;if(o.push(a.pop()>>1),o.length===i)break t}r=a.length?a.pop()>>1:void 0}return a.clear(),o}}function M(t,e){let i=0,s=e.length-1;for(;i<s;){const n=i+s>>1;e[n]>t?s=n:i=n+1}return e[i]}function k(t,e,i,s,n,r){if(Math.floor(s/r)>=Math.floor(n/r))return;const a=t[s],o=t[s+n>>1],h=t[n];let l=h;const c=Math.max(a,o);h>c?l=c:c===a?l=Math.max(o,h):c===o&&(l=Math.max(a,h));let u=s-1,p=n+1;for(;;){do{u++}while(t[u]<l);do{p--}while(t[p]>l);if(u>=p)break;I(t,e,i,u,p)}k(t,e,i,s,p,r),k(t,e,i,p+1,n,r)}function I(t,e,i,s,n){const r=t[s];t[s]=t[n],t[n]=r;const a=4*s,o=4*n,h=e[a],l=e[a+1],c=e[a+2],u=e[a+3];e[a]=e[o],e[a+1]=e[o+1],e[a+2]=e[o+2],e[a+3]=e[o+3],e[o]=h,e[o+1]=l,e[o+2]=c,e[o+3]=u;const p=i[s];i[s]=i[n],i[n]=p}function D(t,e){let i=t^e,s=65535^i,n=65535^(t|e),r=t&(65535^e),a=i|s>>1,o=i>>1^i,h=n>>1^s&r>>1^n,l=i&n>>1^r>>1^r;i=a,s=o,n=h,r=l,a=i&i>>2^s&s>>2,o=i&s>>2^s&(i^s)>>2,h^=i&n>>2^s&r>>2,l^=s&n>>2^(i^s)&r>>2,i=a,s=o,n=h,r=l,a=i&i>>4^s&s>>4,o=i&s>>4^s&(i^s)>>4,h^=i&n>>4^s&r>>4,l^=s&n>>4^(i^s)&r>>4,i=a,s=o,n=h,r=l,h^=i&n>>8^s&r>>8,l^=s&n>>8^(i^s)&r>>8,i=h^h>>1,s=l^l>>1;let c=t^e,u=s|65535^(c|i);return c=16711935&(c|c<<8),c=252645135&(c|c<<4),c=858993459&(c|c<<2),c=1431655765&(c|c<<1),u=16711935&(u|u<<8),u=252645135&(u|u<<4),u=858993459&(u|u<<2),u=1431655765&(u|u<<1),(u<<1|c)>>>0}const P=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class T{static from(t){if(!(t instanceof ArrayBuffer))throw new Error("Data must be an instance of ArrayBuffer.");const[e,i]=new Uint8Array(t,0,2);if(219!==e)throw new Error("Data does not appear to be in a KDBush format.");const s=i>>4;if(1!==s)throw new Error(`Got v${s} data when expected v1.`);const n=P[15&i];if(!n)throw new Error("Unrecognized array type.");const[r]=new Uint16Array(t,2,1),[a]=new Uint32Array(t,4,1);return new T(a,r,n,t)}constructor(t,e=64,i=Float64Array,s){if(isNaN(t)||t<0)throw new Error(`Unpexpected numItems value: ${t}.`);this.numItems=+t,this.nodeSize=Math.min(Math.max(+e,2),65535),this.ArrayType=i,this.IndexArrayType=t<65536?Uint16Array:Uint32Array;const n=P.indexOf(this.ArrayType),r=2*t*this.ArrayType.BYTES_PER_ELEMENT,a=t*this.IndexArrayType.BYTES_PER_ELEMENT,o=(8-a%8)%8;if(n<0)throw new Error(`Unexpected typed array class: ${i}.`);s&&s instanceof ArrayBuffer?(this.data=s,this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+a+o,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+r+a+o),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+a+o,2*t),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+n]),new Uint16Array(this.data,2,1)[0]=e,new Uint32Array(this.data,4,1)[0]=t)}add(t,e){const i=this._pos>>1;return this.ids[i]=i,this.coords[this._pos++]=t,this.coords[this._pos++]=e,i}finish(){const t=this._pos>>1;if(t!==this.numItems)throw new Error(`Added ${t} items when expected ${this.numItems}.`);return L(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}range(t,e,i,s){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:n,coords:r,nodeSize:a}=this,o=[0,n.length-1,0],h=[];for(;o.length;){const l=o.pop()||0,c=o.pop()||0,u=o.pop()||0;if(c-u<=a){for(let a=u;a<=c;a++){const o=r[2*a],l=r[2*a+1];o>=t&&o<=i&&l>=e&&l<=s&&h.push(n[a])}continue}const p=u+c>>1,_=r[2*p],d=r[2*p+1];_>=t&&_<=i&&d>=e&&d<=s&&h.push(n[p]),(0===l?t<=_:e<=d)&&(o.push(u),o.push(p-1),o.push(1-l)),(0===l?i>=_:s>=d)&&(o.push(p+1),o.push(c),o.push(1-l))}return h}within(t,e,i){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:s,coords:n,nodeSize:r}=this,a=[0,s.length-1,0],o=[],h=i*i;for(;a.length;){const l=a.pop()||0,c=a.pop()||0,u=a.pop()||0;if(c-u<=r){for(let i=u;i<=c;i++)O(n[2*i],n[2*i+1],t,e)<=h&&o.push(s[i]);continue}const p=u+c>>1,_=n[2*p],d=n[2*p+1];O(_,d,t,e)<=h&&o.push(s[p]),(0===l?t-i<=_:e-i<=d)&&(a.push(u),a.push(p-1),a.push(1-l)),(0===l?t+i>=_:e+i>=d)&&(a.push(p+1),a.push(c),a.push(1-l))}return o}}function L(t,e,i,s,n,r){if(n-s<=i)return;const a=s+n>>1;F(t,e,a,s,n,r),L(t,e,i,s,a-1,1-r),L(t,e,i,a+1,n,1-r)}function F(t,e,i,s,n,r){for(;n>s;){if(n-s>600){const a=n-s+1,o=i-s+1,h=Math.log(a),l=.5*Math.exp(2*h/3),c=.5*Math.sqrt(h*l*(a-l)/a)*(o-a/2<0?-1:1);F(t,e,i,Math.max(s,Math.floor(i-o*l/a+c)),Math.min(n,Math.floor(i+(a-o)*l/a+c)),r)}const a=e[2*i+r];let o=s,h=n;for(N(t,e,s,i),e[2*n+r]>a&&N(t,e,s,n);o<h;){for(N(t,e,o,h),o++,h--;e[2*o+r]<a;)o++;for(;e[2*h+r]>a;)h--}e[2*s+r]===a?N(t,e,s,h):(h++,N(t,e,h,n)),h<=i&&(s=h+1),i<=h&&(n=h-1)}}function N(t,e,i,s){R(t,i,s),R(e,2*i,2*s),R(e,2*i+1,2*s+1)}function R(t,e,i){const s=t[e];t[e]=t[i],t[i]=s}function O(t,e,i,s){const n=t-i,r=e-s;return n*n+r*r}var G={exports:{}};!function(t){var e,i,s,n;(n={}).Constants={},n.Math={},n.Accumulator={},(e=n.Constants).WGS84={a:6378137,f:1/298.257223563},e.version={major:2,minor:2,patch:0},e.version_string="2.2.0",(i=n.Math).digits=53,i.epsilon=Math.pow(.5,i.digits-1),i.degree=Math.PI/180,i.sq=function(t){return t*t},i.hypot=function(t,e){return Math.sqrt(t*t+e*e)},i.cbrt=Math.cbrt||function(t){var e=Math.pow(Math.abs(t),1/3);return t>0?e:t<0?-e:t},i.log1p=Math.log1p||function(t){var e=1+t,i=e-1;return 0===i?t:t*Math.log(e)/i},i.atanh=Math.atanh||function(t){var e=Math.abs(t);return e=i.log1p(2*e/(1-e))/2,t>0?e:t<0?-e:t},i.copysign=function(t,e){return Math.abs(t)*(e<0||0===e&&1/e<0?-1:1)},i.sum=function(t,e){var i=t+e,s=i-e,n=i-s;return s-=t,{s:i,t:i?0-(s+(n-=e)):i}},i.polyval=function(t,e,i,s){for(var n=t<0?0:e[i++];--t>=0;)n=n*s+e[i++];return n},i.AngRound=function(t){var e=1/16,s=Math.abs(t);return s=s<e?e-(e-s):s,i.copysign(s,t)},i.remainder=function(t,e){return(t%=e)<-e/2?t+e:t<e/2?t:t-e},i.AngNormalize=function(t){var e=i.remainder(t,360);return 180===Math.abs(e)?i.copysign(180,t):e},i.LatFix=function(t){return Math.abs(t)>90?NaN:t},i.AngDiff=function(t,e){var s,n,r=i.sum(i.remainder(-t,360),i.remainder(e,360));return s=(r=i.sum(i.remainder(r.s,360),r.t)).s,n=r.t,0!==s&&180!==Math.abs(s)||(s=i.copysign(s,0===n?e-t:-n)),{d:s,e:n}},i.sincosd=function(t){var e,s,n,r,a,o,h;switch(e=t%360,s=(e-=90*(n=Math.round(e/90)))*this.degree,r=Math.sin(s),a=Math.cos(s),45===Math.abs(e)?(a=Math.sqrt(.5),r=i.copysign(a,s)):30===Math.abs(e)&&(a=Math.sqrt(.75),r=i.copysign(.5,s)),3&n){case 0:o=r,h=a;break;case 1:o=a,h=-r;break;case 2:o=-r,h=-a;break;default:o=-a,h=r}return h+=0,0===o&&(o=i.copysign(o,t)),{s:o,c:h}},i.sincosde=function(t,e){var s,n,r,a,o,h,l;switch(s=t%360,r=Math.round(s/90),n=(s=i.AngRound(s-90*r+e))*this.degree,a=Math.sin(n),o=Math.cos(n),45===Math.abs(s)?(o=Math.sqrt(.5),a=i.copysign(o,n)):30===Math.abs(s)&&(o=Math.sqrt(.75),a=i.copysign(.5,n)),3&r){case 0:h=a,l=o;break;case 1:h=o,l=-a;break;case 2:h=-a,l=-o;break;default:h=-o,l=a}return l+=0,0===h&&(h=i.copysign(h,t+e)),{s:h,c:l}},i.atan2d=function(t,e){var s,n=0;switch(Math.abs(t)>Math.abs(e)&&([t,e]=[e,t],n=2),i.copysign(1,e)<0&&(e=-e,++n),s=Math.atan2(t,e)/this.degree,n){case 1:s=i.copysign(180,t)-s;break;case 2:s=90-s;break;case 3:s=-90+s}return s},function(t,e){t.Accumulator=function(t){this.Set(t)},t.Accumulator.prototype.Set=function(e){e||(e=0),e.constructor===t.Accumulator?(this._s=e._s,this._t=e._t):(this._s=e,this._t=0)},t.Accumulator.prototype.Add=function(t){var i=e.sum(t,this._t),s=e.sum(i.s,this._s);i=i.t,this._s=s.s,this._t=s.t,0===this._s?this._s=i:this._t+=i},t.Accumulator.prototype.Sum=function(e){var i;return e?((i=new t.Accumulator(this)).Add(e),i._s):this._s},t.Accumulator.prototype.Negate=function(){this._s*=-1,this._t*=-1},t.Accumulator.prototype.Remainder=function(t){this._s=e.remainder(this._s,t),this.Add(0)}}(n.Accumulator,n.Math),n.Geodesic={},n.GeodesicLine={},n.PolygonArea={},function(t,e,i,s,n){var r,a,o,h,l,c,u,p,_,d,f,m=20+s.digits+10,y=s.epsilon,g=200*y,v=Math.sqrt(y),x=y,b=1e3*v;t.tiny_=Math.sqrt(Number.MIN_VALUE/Number.EPSILON),t.nC1_=6,t.nC1p_=6,t.nC2_=6,t.nC3_=6,t.nC4_=6,r=t.nC3_*(t.nC3_-1)/2,a=t.nC4_*(t.nC4_+1)/2,t.CAP_C1=1,t.CAP_C1p=2,t.CAP_C2=4,t.CAP_C3=8,t.CAP_C4=16,t.NONE=0,t.ARC=64,t.LATITUDE=128,t.LONGITUDE=256|t.CAP_C3,t.AZIMUTH=512,t.DISTANCE=1024|t.CAP_C1,t.STANDARD=t.LATITUDE|t.LONGITUDE|t.AZIMUTH|t.DISTANCE,t.DISTANCE_IN=2048|t.CAP_C1|t.CAP_C1p,t.REDUCEDLENGTH=4096|t.CAP_C1|t.CAP_C2,t.GEODESICSCALE=8192|t.CAP_C1|t.CAP_C2,t.AREA=16384|t.CAP_C4,t.ALL=32671,t.LONG_UNROLL=32768,t.OUT_MASK=32640|t.LONG_UNROLL,t.SinCosSeries=function(t,e,i,s){var n=s.length,r=n-(t?1:0),a=2*(i-e)*(i+e),o=1&r?s[--n]:0,h=0;for(r=Math.floor(r/2);r--;)o=a*(h=a*o-h+s[--n])-o+s[--n];return t?2*e*i*o:i*(o-h)},o=function(t,e){var i,n,r,a,o,h,l,c,u,p,_,d,f=s.sq(t),m=s.sq(e),y=(f+m-1)/6;return 0===m&&y<=0?i=0:(h=y,(o=(n=f*m/4)*(n+2*(a=y*(r=s.sq(y)))))>=0?(l=n+a,l+=l<0?-Math.sqrt(o):Math.sqrt(o),h+=(c=s.cbrt(l))+(0!==c?r/c:0)):(u=Math.atan2(Math.sqrt(-o),-(n+a)),h+=2*y*Math.cos(u/3)),p=Math.sqrt(s.sq(h)+m),d=((_=h<0?m/(p-h):h+p)-m)/(2*p),i=_/(Math.sqrt(_+s.sq(d))+d)),i},h=[1,4,64,0,256],t.A1m1f=function(t){var e=Math.floor(3);return(s.polyval(e,h,0,s.sq(t))/h[e+1]+t)/(1-t)},l=[-1,6,-16,32,-9,64,-128,2048,9,-16,768,3,-5,512,-7,1280,-7,2048],t.C1f=function(e,i){var n,r,a=s.sq(e),o=e,h=0;for(n=1;n<=t.nC1_;++n)r=Math.floor((t.nC1_-n)/2),i[n]=o*s.polyval(r,l,h,a)/l[h+r+1],h+=r+2,o*=e},c=[205,-432,768,1536,4005,-4736,3840,12288,-225,116,384,-7173,2695,7680,3467,7680,38081,61440],t.C1pf=function(e,i){var n,r,a=s.sq(e),o=e,h=0;for(n=1;n<=t.nC1p_;++n)r=Math.floor((t.nC1p_-n)/2),i[n]=o*s.polyval(r,c,h,a)/c[h+r+1],h+=r+2,o*=e},u=[-11,-28,-192,0,256],t.A2m1f=function(t){var e=Math.floor(3);return(s.polyval(e,u,0,s.sq(t))/u[e+1]-t)/(1+t)},p=[1,2,16,32,35,64,384,2048,15,80,768,7,35,512,63,1280,77,2048],t.C2f=function(e,i){var n,r,a=s.sq(e),o=e,h=0;for(n=1;n<=t.nC2_;++n)r=Math.floor((t.nC2_-n)/2),i[n]=o*s.polyval(r,p,h,a)/p[h+r+1],h+=r+2,o*=e},t.Geodesic=function(t,e){if(this.a=t,this.f=e,this._f1=1-this.f,this._e2=this.f*(2-this.f),this._ep2=this._e2/s.sq(this._f1),this._n=this.f/(2-this.f),this._b=this.a*this._f1,this._c2=(s.sq(this.a)+s.sq(this._b)*(0===this._e2?1:(this._e2>0?s.atanh(Math.sqrt(this._e2)):Math.atan(Math.sqrt(-this._e2)))/Math.sqrt(Math.abs(this._e2))))/2,this._etol2=.1*v/Math.sqrt(Math.max(.001,Math.abs(this.f))*Math.min(1,1-this.f/2)/2),!(isFinite(this.a)&&this.a>0))throw new Error("Equatorial radius is not positive");if(!(isFinite(this._b)&&this._b>0))throw new Error("Polar semi-axis is not positive");this._A3x=new Array(6),this._C3x=new Array(r),this._C4x=new Array(a),this.A3coeff(),this.C3coeff(),this.C4coeff()},_=[-3,128,-2,-3,64,-1,-3,-1,16,3,-1,-2,8,1,-1,2,1,1],t.Geodesic.prototype.A3coeff=function(){var t,e,i=0,n=0;for(t=5;t>=0;--t)e=Math.min(6-t-1,t),this._A3x[n++]=s.polyval(e,_,i,this._n)/_[i+e+1],i+=e+2},d=[3,128,2,5,128,-1,3,3,64,-1,0,1,8,-1,1,4,5,256,1,3,128,-3,-2,3,64,1,-3,2,32,7,512,-10,9,384,5,-9,5,192,7,512,-14,7,512,21,2560],t.Geodesic.prototype.C3coeff=function(){var e,i,n,r=0,a=0;for(e=1;e<t.nC3_;++e)for(i=t.nC3_-1;i>=e;--i)n=Math.min(t.nC3_-i-1,i),this._C3x[a++]=s.polyval(n,d,r,this._n)/d[r+n+1],r+=n+2},f=[97,15015,1088,156,45045,-224,-4784,1573,45045,-10656,14144,-4576,-858,45045,64,624,-4576,6864,-3003,15015,100,208,572,3432,-12012,30030,45045,1,9009,-2944,468,135135,5792,1040,-1287,135135,5952,-11648,9152,-2574,135135,-64,-624,4576,-6864,3003,135135,8,10725,1856,-936,225225,-8448,4992,-1144,225225,-1440,4160,-4576,1716,225225,-136,63063,1024,-208,105105,3584,-3328,1144,315315,-128,135135,-2560,832,405405,128,99099],t.Geodesic.prototype.C4coeff=function(){var e,i,n,r=0,a=0;for(e=0;e<t.nC4_;++e)for(i=t.nC4_-1;i>=e;--i)n=t.nC4_-i-1,this._C4x[a++]=s.polyval(n,f,r,this._n)/f[r+n+1],r+=n+2},t.Geodesic.prototype.A3f=function(t){return s.polyval(5,this._A3x,0,t)},t.Geodesic.prototype.C3f=function(e,i){var n,r,a=1,o=0;for(n=1;n<t.nC3_;++n)r=t.nC3_-n-1,a*=e,i[n]=a*s.polyval(r,this._C3x,o,e),o+=r+1},t.Geodesic.prototype.C4f=function(e,i){var n,r,a=1,o=0;for(n=0;n<t.nC4_;++n)r=t.nC4_-n-1,i[n]=a*s.polyval(r,this._C4x,o,e),o+=r+1,a*=e},t.Geodesic.prototype.Lengths=function(e,i,s,n,r,a,o,h,l,c,u,p,_){var d,f,m,y,g={},v=0,x=0,b=0,w=0;if((u&=t.OUT_MASK)&(t.DISTANCE|t.REDUCEDLENGTH|t.GEODESICSCALE)&&(b=t.A1m1f(e),t.C1f(e,p),u&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(w=t.A2m1f(e),t.C2f(e,_),v=b-w,w=1+w),b=1+b),u&t.DISTANCE)d=t.SinCosSeries(!0,a,o,p)-t.SinCosSeries(!0,s,n,p),g.s12b=b*(i+d),u&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(x=v*i+(b*d-w*(t.SinCosSeries(!0,a,o,_)-t.SinCosSeries(!0,s,n,_))));else if(u&(t.REDUCEDLENGTH|t.GEODESICSCALE)){for(f=1;f<=t.nC2_;++f)_[f]=b*p[f]-w*_[f];x=v*i+(t.SinCosSeries(!0,a,o,_)-t.SinCosSeries(!0,s,n,_))}return u&t.REDUCEDLENGTH?(g.m0=v,g.m12b=h*(n*a)-r*(s*o)-n*o*x):g.m12b=NaN,u&t.GEODESICSCALE&&(m=n*o+s*a,y=this._ep2*(l-c)*(l+c)/(r+h),g.M12=m+(y*a-o*x)*s/r,g.M21=m-(y*s-n*x)*a/h),g},t.Geodesic.prototype.InverseStart=function(e,i,n,r,a,h,l,c,u,p,_){var d,f,m,y,v,x,w,S,C,A,E,M,k,I,D,P,T,L,F,N,R={},O=r*i-a*e,G=a*i+r*e;return R.sig12=-1,d=r*i,d+=a*e,(f=G>=0&&O<.5&&a*l<.5)?(y=s.sq(e+r),y/=y+s.sq(i+a),R.dnm=Math.sqrt(1+this._ep2*y),m=l/(this._f1*R.dnm),v=Math.sin(m),x=Math.cos(m)):(v=c,x=u),R.salp1=a*v,R.calp1=x>=0?O+a*e*s.sq(v)/(1+x):d-a*e*s.sq(v)/(1-x),S=s.hypot(R.salp1,R.calp1),C=e*r+i*a*x,f&&S<this._etol2?(R.salp2=i*v,R.calp2=O-i*r*(x>=0?s.sq(v)/(1+x):1-x),w=s.hypot(R.salp2,R.calp2),R.salp2/=w,R.calp2/=w,R.sig12=Math.atan2(S,C)):Math.abs(this._n)>.1||C>=0||S>=6*Math.abs(this._n)*Math.PI*s.sq(i)||(N=Math.atan2(-c,-u),this.f>=0?(I=(k=s.sq(e)*this._ep2)/(2*(1+Math.sqrt(1+k))+k),A=N/(M=this.f*i*this.A3f(I)*Math.PI),E=d/(M*i)):(D=a*i-r*e,P=Math.atan2(d,D),E=l/(M=((A=(T=this.Lengths(this._n,Math.PI+P,e,-i,n,r,a,h,i,a,t.REDUCEDLENGTH,p,_)).m12b/(i*a*T.m0*Math.PI)-1)<-.01?d/A:-this.f*s.sq(i)*Math.PI)/i)),E>-g&&A>-1-b?this.f>=0?(R.salp1=Math.min(1,-A),R.calp1=-Math.sqrt(1-s.sq(R.salp1))):(R.calp1=Math.max(A>-g?0:-1,A),R.salp1=Math.sqrt(1-s.sq(R.calp1))):(L=o(A,E),F=M*(this.f>=0?-A*L/(1+L):-E*(1+L)/L),v=Math.sin(F),x=-Math.cos(F),R.salp1=a*v,R.calp1=d-a*e*s.sq(v)/(1-x))),R.salp1<=0?(R.salp1=1,R.calp1=0):(w=s.hypot(R.salp1,R.calp1),R.salp1/=w,R.calp1/=w),R},t.Geodesic.prototype.Lambda12=function(e,i,n,r,a,o,h,l,c,u,p,_,d,f){var m,y,g,v,x,b,w,S,C,A,E,M,k,I={};return 0===e&&0===l&&(l=-t.tiny_),y=h*i,g=s.hypot(l,h*e),I.ssig1=e,v=y*e,I.csig1=x=l*i,m=s.hypot(I.ssig1,I.csig1),I.ssig1/=m,I.csig1/=m,I.salp2=a!==i?y/a:h,I.calp2=a!==i||Math.abs(r)!==-e?Math.sqrt(s.sq(l*i)+(i<-e?(a-i)*(i+a):(e-r)*(e+r)))/a:Math.abs(l),I.ssig2=r,b=y*r,I.csig2=w=I.calp2*a,m=s.hypot(I.ssig2,I.csig2),I.ssig2/=m,I.csig2/=m,I.sig12=Math.atan2(Math.max(0,I.csig1*I.ssig2-I.ssig1*I.csig2),I.csig1*I.csig2+I.ssig1*I.ssig2),S=Math.max(0,x*b-v*w),C=x*w+v*b,E=Math.atan2(S*u-C*c,C*u+S*c),M=s.sq(g)*this._ep2,I.eps=M/(2*(1+Math.sqrt(1+M))+M),this.C3f(I.eps,f),A=t.SinCosSeries(!0,I.ssig2,I.csig2,f)-t.SinCosSeries(!0,I.ssig1,I.csig1,f),I.domg12=-this.f*this.A3f(I.eps)*y*(I.sig12+A),I.lam12=E+I.domg12,p&&(0===I.calp2?I.dlam12=-2*this._f1*n/e:(k=this.Lengths(I.eps,I.sig12,I.ssig1,I.csig1,n,I.ssig2,I.csig2,o,i,a,t.REDUCEDLENGTH,_,d),I.dlam12=k.m12b,I.dlam12*=this._f1/(I.calp2*a))),I},t.Geodesic.prototype.Inverse=function(e,i,n,r,a){var o,h;return a||(a=t.STANDARD),a===t.LONG_UNROLL&&(a|=t.STANDARD),a&=t.OUT_MASK,h=(o=this.InverseInt(e,i,n,r,a)).vals,a&t.AZIMUTH&&(h.azi1=s.atan2d(o.salp1,o.calp1),h.azi2=s.atan2d(o.salp2,o.calp2)),h},t.Geodesic.prototype.InverseInt=function(e,i,n,r,a){var o,h,l,c,u,p,_,d,f,g,b,w,S,C,A,E,M,k,I,D,P,T,L,F,N,R,O,G,z,q,j,B,U,$,V,W,H,K,Z,X,J,Y,Q,tt,et,it,st,nt,rt,at,ot,ht,lt,ct,ut,pt,_t,dt,ft,mt,yt,gt,vt,xt,bt,wt={};if(wt.lat1=e=s.LatFix(e),wt.lat2=n=s.LatFix(n),e=s.AngRound(e),n=s.AngRound(n),h=(o=s.AngDiff(i,r)).e,o=o.d,a&t.LONG_UNROLL?(wt.lon1=i,wt.lon2=i+o+h):(wt.lon1=s.AngNormalize(i),wt.lon2=s.AngNormalize(r)),h*=l=s.copysign(1,o),A=(o*=l)*s.degree,E=(c=s.sincosde(o,h)).s,M=c.c,h=180-o-h,(u=Math.abs(e)<Math.abs(n)||isNaN(n)?-1:1)<0&&(l*=-1,[n,e]=[e,n]),e*=p=s.copysign(1,-e),n*=p,c=s.sincosd(e),_=this._f1*c.s,d=c.c,_/=c=s.hypot(_,d),d/=c,d=Math.max(t.tiny_,d),c=s.sincosd(n),f=this._f1*c.s,g=c.c,f/=c=s.hypot(f,g),g/=c,g=Math.max(t.tiny_,g),d<-_?g===d&&(f=s.copysign(_,f)):Math.abs(f)===-_&&(g=d),S=Math.sqrt(1+this._ep2*s.sq(_)),C=Math.sqrt(1+this._ep2*s.sq(f)),L=new Array(t.nC1_+1),F=new Array(t.nC2_+1),N=new Array(t.nC3_),(R=-90===e||0===E)&&(D=E,T=0,G=_,z=(I=M)*d,q=f,j=(P=1)*g,k=Math.atan2(Math.max(0,z*q-G*j),z*j+G*q),b=(O=this.Lengths(this._n,k,G,z,S,q,j,C,d,g,a|t.DISTANCE|t.REDUCEDLENGTH,L,F)).s12b,w=O.m12b,a&t.GEODESICSCALE&&(wt.M12=O.M12,wt.M21=O.M21),k<v||w>=0?((k<3*t.tiny_||k<y&&(b<0||w<0))&&(k=w=b=0),w*=this._b,b*=this._b,wt.a12=k/s.degree):R=!1),_t=2,!R&&0===_&&(this.f<=0||h>=180*this.f))I=P=0,D=T=1,b=this.a*A,k=U=A/this._f1,w=this._b*Math.sin(k),a&t.GEODESICSCALE&&(wt.M12=wt.M21=Math.cos(k)),wt.a12=o/this._f1;else if(!R)if(k=(O=this.InverseStart(_,d,S,f,g,C,A,E,M,L,F)).sig12,D=O.salp1,I=O.calp1,k>=0)T=O.salp2,P=O.calp2,$=O.dnm,b=k*this._b*$,w=s.sq($)*this._b*Math.sin(k/$),a&t.GEODESICSCALE&&(wt.M12=wt.M21=Math.cos(k/$)),wt.a12=k/s.degree,U=A/(this._f1*$);else{for(V=0,W=t.tiny_,H=1,K=t.tiny_,Z=-1,X=!1,J=!1;Y=(O=this.Lambda12(_,d,S,f,g,C,D,I,E,M,V<20,L,F,N)).lam12,T=O.salp2,P=O.calp2,k=O.sig12,G=O.ssig1,z=O.csig1,q=O.ssig2,j=O.csig2,B=O.eps,ft=O.domg12,Q=O.dlam12,!J&&Math.abs(Y)>=(X?8:1)*y&&V!=m;++V)Y>0&&(V<20||I/D>Z/K)?(K=D,Z=I):Y<0&&(V<20||I/D<H/W)&&(W=D,H=I),V<20&&Q>0&&(tt=-Y/Q,Math.abs(tt)<Math.PI&&(et=Math.sin(tt),(st=D*(it=Math.cos(tt))+I*et)>0))?(I=I*it-D*et,D=st,D/=c=s.hypot(D,I),I/=c,X=Math.abs(Y)<=16*y):(D=(W+K)/2,I=(H+Z)/2,D/=c=s.hypot(D,I),I/=c,X=!1,J=Math.abs(W-D)+(H-I)<x||Math.abs(D-K)+(I-Z)<x);nt=a|(a&(t.REDUCEDLENGTH|t.GEODESICSCALE)?t.DISTANCE:t.NONE),b=(O=this.Lengths(B,k,G,z,S,q,j,C,d,g,nt,L,F)).s12b,w=O.m12b,a&t.GEODESICSCALE&&(wt.M12=O.M12,wt.M21=O.M21),w*=this._b,b*=this._b,wt.a12=k/s.degree,a&t.AREA&&(xt=Math.sin(ft),_t=E*(bt=Math.cos(ft))-M*xt,dt=M*bt+E*xt)}return a&t.DISTANCE&&(wt.s12=0+b),a&t.REDUCEDLENGTH&&(wt.m12=0+w),a&t.AREA&&(rt=D*d,0!==(at=s.hypot(I,D*_))&&0!==rt?(G=_,z=I*d,q=f,j=P*g,B=(ht=s.sq(at)*this._ep2)/(2*(1+Math.sqrt(1+ht))+ht),lt=s.sq(this.a)*at*rt*this._e2,G/=c=s.hypot(G,z),z/=c,q/=c=s.hypot(q,j),j/=c,ct=new Array(t.nC4_),this.C4f(B,ct),ut=t.SinCosSeries(!1,G,z,ct),pt=t.SinCosSeries(!1,q,j,ct),wt.S12=lt*(pt-ut)):wt.S12=0,R||2!=_t||(_t=Math.sin(U),dt=Math.cos(U)),!R&&dt>-.7071&&f-_<1.75?(ft=1+dt,mt=1+d,yt=1+g,ot=2*Math.atan2(_t*(_*yt+f*mt),ft*(_*f+mt*yt))):(vt=P*I+T*D,0===(gt=T*I-P*D)&&vt<0&&(gt=t.tiny_*I,vt=-1),ot=Math.atan2(gt,vt)),wt.S12+=this._c2*ot,wt.S12*=u*l*p,wt.S12+=0),u<0&&([T,D]=[D,T],[P,I]=[I,P],a&t.GEODESICSCALE&&([wt.M21,wt.M12]=[wt.M12,wt.M21])),{vals:wt,salp1:D*=u*l,calp1:I*=u*p,salp2:T*=u*l,calp2:P*=u*p}},t.Geodesic.prototype.GenDirect=function(i,s,n,r,a,o){return o?o===t.LONG_UNROLL&&(o|=t.STANDARD):o=t.STANDARD,r||(o|=t.DISTANCE_IN),new e.GeodesicLine(this,i,s,n,o).GenPosition(r,a,o)},t.Geodesic.prototype.Direct=function(t,e,i,s,n){return this.GenDirect(t,e,i,!1,s,n)},t.Geodesic.prototype.ArcDirect=function(t,e,i,s,n){return this.GenDirect(t,e,i,!0,s,n)},t.Geodesic.prototype.Line=function(t,i,s,n){return new e.GeodesicLine(this,t,i,s,n)},t.Geodesic.prototype.DirectLine=function(t,e,i,s,n){return this.GenDirectLine(t,e,i,!1,s,n)},t.Geodesic.prototype.ArcDirectLine=function(t,e,i,s,n){return this.GenDirectLine(t,e,i,!0,s,n)},t.Geodesic.prototype.GenDirectLine=function(i,s,n,r,a,o){var h;return o||(o=t.STANDARD|t.DISTANCE_IN),r||(o|=t.DISTANCE_IN),(h=new e.GeodesicLine(this,i,s,n,o)).GenSetDistance(r,a),h},t.Geodesic.prototype.InverseLine=function(i,n,r,a,o){var h,l,c;return o||(o=t.STANDARD|t.DISTANCE_IN),h=this.InverseInt(i,n,r,a,t.ARC),c=s.atan2d(h.salp1,h.calp1),o&t.OUT_MASK&t.DISTANCE_IN&&(o|=t.DISTANCE),(l=new e.GeodesicLine(this,i,n,c,o,h.salp1,h.calp1)).SetArc(h.vals.a12),l},t.Geodesic.prototype.Polygon=function(t){return new i.PolygonArea(this,t)},t.WGS84=new t.Geodesic(n.WGS84.a,n.WGS84.f)}(n.Geodesic,n.GeodesicLine,n.PolygonArea,n.Math,n.Constants),function(t,e,i){e.GeodesicLine=function(e,s,n,r,a,o,h){var l,c,u,p,_,d;a||(a=t.STANDARD|t.DISTANCE_IN),this.a=e.a,this.f=e.f,this._b=e._b,this._c2=e._c2,this._f1=e._f1,this.caps=a|t.LATITUDE|t.AZIMUTH|t.LONG_UNROLL,this.lat1=i.LatFix(s),this.lon1=n,void 0===o||void 0===h?(this.azi1=i.AngNormalize(r),l=i.sincosd(i.AngRound(this.azi1)),this.salp1=l.s,this.calp1=l.c):(this.azi1=r,this.salp1=o,this.calp1=h),l=i.sincosd(i.AngRound(this.lat1)),u=this._f1*l.s,c=l.c,u/=l=i.hypot(u,c),c/=l,c=Math.max(t.tiny_,c),this._dn1=Math.sqrt(1+e._ep2*i.sq(u)),this._salp0=this.salp1*c,this._calp0=i.hypot(this.calp1,this.salp1*u),this._ssig1=u,this._somg1=this._salp0*u,this._csig1=this._comg1=0!==u||0!==this.calp1?c*this.calp1:1,l=i.hypot(this._ssig1,this._csig1),this._ssig1/=l,this._csig1/=l,this._k2=i.sq(this._calp0)*e._ep2,p=this._k2/(2*(1+Math.sqrt(1+this._k2))+this._k2),this.caps&t.CAP_C1&&(this._A1m1=t.A1m1f(p),this._C1a=new Array(t.nC1_+1),t.C1f(p,this._C1a),this._B11=t.SinCosSeries(!0,this._ssig1,this._csig1,this._C1a),_=Math.sin(this._B11),d=Math.cos(this._B11),this._stau1=this._ssig1*d+this._csig1*_,this._ctau1=this._csig1*d-this._ssig1*_),this.caps&t.CAP_C1p&&(this._C1pa=new Array(t.nC1p_+1),t.C1pf(p,this._C1pa)),this.caps&t.CAP_C2&&(this._A2m1=t.A2m1f(p),this._C2a=new Array(t.nC2_+1),t.C2f(p,this._C2a),this._B21=t.SinCosSeries(!0,this._ssig1,this._csig1,this._C2a)),this.caps&t.CAP_C3&&(this._C3a=new Array(t.nC3_),e.C3f(p,this._C3a),this._A3c=-this.f*this._salp0*e.A3f(p),this._B31=t.SinCosSeries(!0,this._ssig1,this._csig1,this._C3a)),this.caps&t.CAP_C4&&(this._C4a=new Array(t.nC4_),e.C4f(p,this._C4a),this._A4=i.sq(this.a)*this._calp0*this._salp0*e._e2,this._B41=t.SinCosSeries(!1,this._ssig1,this._csig1,this._C4a)),this.a13=this.s13=NaN},e.GeodesicLine.prototype.GenPosition=function(e,s,n){var r,a,o,h,l,c,u,p,_,d,f,m,y,g,v,x,b,w,S,C,A,E,M,k,I,D,P={};return n?n===t.LONG_UNROLL&&(n|=t.STANDARD):n=t.STANDARD,n&=this.caps&t.OUT_MASK,P.lat1=this.lat1,P.azi1=this.azi1,P.lon1=n&t.LONG_UNROLL?this.lon1:i.AngNormalize(this.lon1),e?P.a12=s:P.s12=s,e||this.caps&t.DISTANCE_IN&t.OUT_MASK?(h=0,l=0,e?(r=s*i.degree,a=(M=i.sincosd(s)).s,o=M.c):(p=s/(this._b*(1+this._A1m1)),_=Math.sin(p),d=Math.cos(p),r=p-((h=-t.SinCosSeries(!0,this._stau1*d+this._ctau1*_,this._ctau1*d-this._stau1*_,this._C1pa))-this._B11),a=Math.sin(r),o=Math.cos(r),Math.abs(this.f)>.01&&(c=this._ssig1*o+this._csig1*a,u=this._csig1*o-this._ssig1*a,h=t.SinCosSeries(!0,c,u,this._C1a),r-=((1+this._A1m1)*(r+(h-this._B11))-s/this._b)/Math.sqrt(1+this._k2*i.sq(c)),a=Math.sin(r),o=Math.cos(r))),c=this._ssig1*o+this._csig1*a,u=this._csig1*o-this._ssig1*a,S=Math.sqrt(1+this._k2*i.sq(c)),n&(t.DISTANCE|t.REDUCEDLENGTH|t.GEODESICSCALE)&&((e||Math.abs(this.f)>.01)&&(h=t.SinCosSeries(!0,c,u,this._C1a)),l=(1+this._A1m1)*(h-this._B11)),y=this._calp0*c,0===(g=i.hypot(this._salp0,this._calp0*u))&&(g=u=t.tiny_),b=this._salp0,w=this._calp0*u,e&&n&t.DISTANCE&&(P.s12=this._b*((1+this._A1m1)*r+l)),n&t.LONGITUDE&&(v=this._salp0*c,x=u,m=i.copysign(1,this._salp0),f=((n&t.LONG_UNROLL?m*(r-(Math.atan2(c,u)-Math.atan2(this._ssig1,this._csig1))+(Math.atan2(m*v,x)-Math.atan2(m*this._somg1,this._comg1))):Math.atan2(v*this._comg1-x*this._somg1,x*this._comg1+v*this._somg1))+this._A3c*(r+(t.SinCosSeries(!0,c,u,this._C3a)-this._B31)))/i.degree,P.lon2=n&t.LONG_UNROLL?this.lon1+f:i.AngNormalize(i.AngNormalize(this.lon1)+i.AngNormalize(f))),n&t.LATITUDE&&(P.lat2=i.atan2d(y,this._f1*g)),n&t.AZIMUTH&&(P.azi2=i.atan2d(b,w)),n&(t.REDUCEDLENGTH|t.GEODESICSCALE)&&(C=t.SinCosSeries(!0,c,u,this._C2a),A=(1+this._A2m1)*(C-this._B21),E=(this._A1m1-this._A2m1)*r+(l-A),n&t.REDUCEDLENGTH&&(P.m12=this._b*(S*(this._csig1*c)-this._dn1*(this._ssig1*u)-this._csig1*u*E)),n&t.GEODESICSCALE&&(M=this._k2*(c-this._ssig1)*(c+this._ssig1)/(this._dn1+S),P.M12=o+(M*c-u*E)*this._ssig1/this._dn1,P.M21=o-(M*this._ssig1-this._csig1*E)*c/S)),n&t.AREA&&(k=t.SinCosSeries(!1,c,u,this._C4a),0===this._calp0||0===this._salp0?(I=b*this.calp1-w*this.salp1,D=w*this.calp1+b*this.salp1):(I=this._calp0*this._salp0*(o<=0?this._csig1*(1-o)+a*this._ssig1:a*(this._csig1*a/(1+o)+this._ssig1)),D=i.sq(this._salp0)+i.sq(this._calp0)*this._csig1*u),P.S12=this._c2*Math.atan2(I,D)+this._A4*(k-this._B41)),e||(P.a12=r/i.degree),P):(P.a12=NaN,P)},e.GeodesicLine.prototype.Position=function(t,e){return this.GenPosition(!1,t,e)},e.GeodesicLine.prototype.ArcPosition=function(t,e){return this.GenPosition(!0,t,e)},e.GeodesicLine.prototype.GenSetDistance=function(t,e){t?this.SetArc(e):this.SetDistance(e)},e.GeodesicLine.prototype.SetDistance=function(e){var i;this.s13=e,i=this.GenPosition(!1,this.s13,t.ARC),this.a13=0+i.a12},e.GeodesicLine.prototype.SetArc=function(e){var i;this.a13=e,i=this.GenPosition(!0,this.a13,t.DISTANCE),this.s13=0+i.s12}}(n.Geodesic,n.GeodesicLine,n.Math),function(t,e,i,s){var n,r,a,o;n=function(t,e){var s=i.AngDiff(t,e).d;return t=i.AngNormalize(t),e=i.AngNormalize(e),s>0&&(t<0&&e>=0||t>0&&0===e)?1:s<0&&t>=0&&e<0?-1:0},r=function(t,e){return(0<=(e%=720)&&e<360||e<-360?0:1)-(0<=(t%=720)&&t<360||t<-360?0:1)},a=function(t,e,i,s,n){return t.Remainder(e),1&i&&t.Add((t.Sum()<0?1:-1)*e/2),s||t.Negate(),n?t.Sum()>e/2?t.Add(-e):t.Sum()<=-e/2&&t.Add(+e):t.Sum()>=e?t.Add(-e):t.Sum()<0&&t.Add(+e),0+t.Sum()},o=function(t,e,s,n,r){return t=i.remainder(t,e),1&s&&(t+=(t<0?1:-1)*e/2),n||(t*=-1),r?t>e/2?t-=e:t<=-e/2&&(t+=e):t>=e?t-=e:t<0&&(t+=e),0+t},t.PolygonArea=function(t,i){this._geod=t,this.a=this._geod.a,this.f=this._geod.f,this._area0=4*Math.PI*t._c2,this.polyline=i||!1,this._mask=e.LATITUDE|e.LONGITUDE|e.DISTANCE|(this.polyline?e.NONE:e.AREA|e.LONG_UNROLL),this.polyline||(this._areasum=new s.Accumulator(0)),this._perimetersum=new s.Accumulator(0),this.Clear()},t.PolygonArea.prototype.Clear=function(){this.num=0,this._crossings=0,this.polyline||this._areasum.Set(0),this._perimetersum.Set(0),this._lat0=this._lon0=this.lat=this.lon=NaN},t.PolygonArea.prototype.AddPoint=function(t,e){var i;0===this.num?(this._lat0=this.lat=t,this._lon0=this.lon=e):(i=this._geod.Inverse(this.lat,this.lon,t,e,this._mask),this._perimetersum.Add(i.s12),this.polyline||(this._areasum.Add(i.S12),this._crossings+=n(this.lon,e)),this.lat=t,this.lon=e),++this.num},t.PolygonArea.prototype.AddEdge=function(t,e){var i;this.num&&(i=this._geod.Direct(this.lat,this.lon,t,e,this._mask),this._perimetersum.Add(e),this.polyline||(this._areasum.Add(i.S12),this._crossings+=r(this.lon,i.lon2)),this.lat=i.lat2,this.lon=i.lon2),++this.num},t.PolygonArea.prototype.Compute=function(t,e){var i,r,o={number:this.num};return this.num<2?(o.perimeter=0,this.polyline||(o.area=0),o):this.polyline?(o.perimeter=this._perimetersum.Sum(),o):(i=this._geod.Inverse(this.lat,this.lon,this._lat0,this._lon0,this._mask),o.perimeter=this._perimetersum.Sum(i.s12),(r=new s.Accumulator(this._areasum)).Add(i.S12),o.area=a(r,this._area0,this._crossings+n(this.lon,this._lon0),t,e),o)},t.PolygonArea.prototype.TestPoint=function(t,e,i,s){var r,a,h,l,c={number:this.num+1};if(0===this.num)return c.perimeter=0,this.polyline||(c.area=0),c;for(c.perimeter=this._perimetersum.Sum(),a=this.polyline?0:this._areasum.Sum(),h=this._crossings,l=0;l<(this.polyline?1:2);++l)r=this._geod.Inverse(0===l?this.lat:t,0===l?this.lon:e,0!==l?this._lat0:t,0!==l?this._lon0:e,this._mask),c.perimeter+=r.s12,this.polyline||(a+=r.S12,h+=n(0===l?this.lon:e,0!==l?this._lon0:e));return this.polyline||(c.area=o(a,this._area0,h,i,s)),c},t.PolygonArea.prototype.TestEdge=function(t,e,i,s){var a,h,l,c={number:this.num?this.num+1:0};return 0===this.num||(c.perimeter=this._perimetersum.Sum()+e,this.polyline||(h=this._areasum.Sum(),l=this._crossings,h+=(a=this._geod.Direct(this.lat,this.lon,t,e,this._mask)).S12,l+=r(this.lon,a.lon2),l+=n(a.lon2,this._lon0),a=this._geod.Inverse(a.lat2,a.lon2,this._lat0,this._lon0,this._mask),c.perimeter+=a.s12,h+=a.S12,c.area=o(h,this._area0,l,i,s))),c}}(n.PolygonArea,n.Geodesic,n.Math,n.Accumulator),s=n,t.exports?t.exports=s:window.geodesic=s}(G);var z=G.exports,q=e({__proto__:null,default:i(z)},[z]);const j=globalThis;"undefined"==typeof window&&(j.window=j.window||{},j.window.document||(j.window.document={}));const B=j.window.modules=j.window.modules||{};B.mproj=S,B.flatbush=E,B.kdbush=T,B["geographiclib-geodesic"]=q;class U{_listeners={};on(t,e){return this._listeners[t]||(this._listeners[t]=[]),this._listeners[t].push(e),this}once(t,e){const i=s=>{this.off(t,i),e(s)};return this.on(t,i)}off(t,e){return this._listeners[t]?(this._listeners[t]=this._listeners[t].filter(t=>t!==e),this):this}fire(t,e){if(!this._listeners[t])return this;const i={type:t,...e};return this._listeners[t].forEach(t=>t(i)),this}}class ${mx;my;bx;by;constructor(t=1,e=1,i=0,s=0){this.mx=t,this.my=e,this.bx=i,this.by=s}static fromBounds(t,e,i=!1){const s=e.width/t.width||1,n=(i?-e.height/t.height:e.height/t.height)||1,r=e.xmin-s*t.xmin,a=i?e.ymax-n*t.ymin:e.ymin-n*t.ymin;return new $(s,n,r,a)}project(t,e){return[t*this.mx+this.bx,e*this.my+this.by]}unproject(t,e){return[(t-this.bx)/this.mx,(e-this.by)/this.my]}translate(t,e){this.bx+=t,this.by+=e}scale(t,e,i){this.bx=e*(1-t)+this.bx*t,this.by=i*(1-t)+this.by*t,this.mx*=t,this.my*=t}clone(){return new $(this.mx,this.my,this.bx,this.by)}}class V{xmin;ymin;xmax;ymax;constructor(t=1/0,e=1/0,i=-1/0,s=-1/0){this.xmin=t,this.ymin=e,this.xmax=i,this.ymax=s}static fromArray(t){return new V(t[0],t[1],t[2],t[3])}get width(){return this.xmax-this.xmin}get height(){return this.ymax-this.ymin}get centerX(){return.5*(this.xmin+this.xmax)}get centerY(){return.5*(this.ymin+this.ymax)}hasBounds(){return this.xmin<=this.xmax&&this.ymin<=this.ymax}clone(){return new V(this.xmin,this.ymin,this.xmax,this.ymax)}mergePoint(t,e){t<this.xmin&&(this.xmin=t),t>this.xmax&&(this.xmax=t),e<this.ymin&&(this.ymin=e),e>this.ymax&&(this.ymax=e)}merge(t){t.hasBounds()&&(t.xmin<this.xmin&&(this.xmin=t.xmin),t.xmax>this.xmax&&(this.xmax=t.xmax),t.ymin<this.ymin&&(this.ymin=t.ymin),t.ymax>this.ymax&&(this.ymax=t.ymax))}fillOut(t,e=.5,i=.5){const s=this.width,n=this.height;let r;return s/n<t?(r=n*t-s,this.xmin-=(1-e)*r,this.xmax+=e*r):(r=s/t-n,this.ymin-=(1-i)*r,this.ymax+=i*r),this}scale(t){const e=this.centerX,i=this.centerY,s=this.width*t,n=this.height*t;this.xmin=e-s/2,this.xmax=e+s/2,this.ymin=i-n/2,this.ymax=i+n/2}}class W extends U{_running=!1;_busy=!1;_tickTime=0;_startTime=0;_duration=1/0;_frame=null;constructor(){super()}start(t){const e=Date.now();this._duration=t||1/0,this._startTime=e,this._running=!0,this._busy||this._startTick(e)}stop(){var t;this._running=!1,null!==this._frame&&(t=this._frame,"function"==typeof cancelAnimationFrame?cancelAnimationFrame(t):clearTimeout(t),this._frame=null),this._busy=!1}_startTick(t){var e;this._busy=!0,this._tickTime=t,this._frame=(e=()=>{this._frame=null,this._onTick()},"function"==typeof requestAnimationFrame?requestAnimationFrame(e):setTimeout(e,25))}_onTick(){const t=Date.now(),e=t-this._startTime,i=Math.min((e+10)/this._duration,1),s=i>=1;this._running?(s&&(this._running=!1),this.fire("tick",{elapsed:e,pct:i,done:s,time:t,tickTime:t-this._tickTime}),this._busy=!1,this._running&&this._startTick(t)):this._busy=!1}}class H extends U{_timer=new W;_startValue=0;_endValue=0;_ease;constructor(t){super(),this._ease=t||null,this._timer.on("tick",t=>this._onTick(t))}start(t,e,i){this._startValue=t,this._endValue=e,this._timer.start(i||500)}stop(){this._timer.stop()}_onTick(t){const e=this._ease?this._ease(t.pct):t.pct,i=this._endValue*e+this._startValue*(1-e);this.fire("change",{value:i})}static sineInOut(t){return.5-Math.cos(t*Math.PI)/2}static quadraticOut(t){return 1-Math.pow(1-t,2)}}const K=18485274.7;class Z{_transform=new $;_extent=new V;_width=0;_height=0;_initialMX=0;_initialExtent=null;_zoomTween=new H(H.sineInOut);_zoomFocus=[0,0];_animatingTransform=null;onViewChange=null;_crs="EPSG:4326";setCRS(t){this._crs=t}get transform(){return this._transform}get extent(){return this._extent}get width(){return this._width}get height(){return this._height}get initialMX(){return this._initialMX}updateSize(t,e){this._width=t,this._height=e}setExtent(t){this._extent=t.clone(),this._initialExtent||(this._initialExtent=t.clone()),this._updateTransform()}reset(){this._initialExtent&&this.setExtent(this._initialExtent)}getCameraState(){const t=this._transform;return{center:[(this._width/2-t.bx)/t.mx,(this._height/2-t.by)/t.my],scale:Math.abs(t.mx)}}applyCameraState(t,e){const i=e,s=-e,n=this._width/2-i*t[0],r=this._height/2-s*t[1];this._transform=new $(i,s,n,r),this._applyConstraints()}clearInitialState(){this._initialExtent=null,this._initialMX=0}_updateTransform(){if(!this._extent.hasBounds())return;const t=this._width/this._height,e=this._extent.clone().fillOut(t),i=new V(0,0,this._width,this._height);this._transform=$.fromBounds(e,i,!0),0===this._initialMX&&(this._initialMX=Math.abs(this._transform.mx),this._initialExtent=e)}pan(t,e){this._transform.translate(t,e),this._applyConstraints()}cancelZoomAnimation(){this._zoomTween.stop(),this._animatingTransform=null}applyWheelZoom(t,e,i,s){const n=1+.12*e,r=t>0?n:1/n;this._transform.scale(r,i,s),this._applyConstraints()}zoomIn(){this._zoomTo(1.15)}zoomOut(){this._zoomTo(1/1.15)}_zoomTo(t){const e=[this._width/2,this._height/2],i=Math.abs(this._transform.mx),s=i*t;this._zoomFocus=e,this._animatingTransform=this._transform.clone(),this._zoomTween.start(i,s,200)}initZoomTween(){this._zoomTween.on("change",t=>{if(!this._animatingTransform)return;const e=t.value/this._animatingTransform.mx,i=this._animatingTransform.clone();i.scale(e,this._zoomFocus[0],this._zoomFocus[1]),this._transform=i,this.onViewChange?.(),t.done&&(this._animatingTransform=null)})}project(t,e){return this._transform.project(t,e)}unproject(t,e){return this._transform.unproject(t,e)}getLineScale(){if(0===this._initialMX)return 1;const t=Math.abs(this._transform.mx)/this._initialMX;let e=1;return t<.5?e*=Math.pow(t+.5,.35):t>30&&(e*=Math.pow(t-29,.065)),e}getArcFilter(t){const e=.1*(1/Math.abs(this._transform.mx)),i=this._initialMX>0?Math.abs(this._transform.mx)/this._initialMX:1,s=i<1?e*i:e,n=this._getViewBounds();return e=>!t.arcIsSmaller?.(e,s)&&!(n&&t.arcIntersectsBBox&&!t.arcIntersectsBBox(e,n))}getViewBounds(){return this._getViewBounds()}_getViewBounds(){if(!this._transform||0===this._width)return null;const t=this._transform,e=-t.bx/t.mx,i=(this._width-t.bx)/t.mx,s=-t.by/t.my,n=(this._height-t.by)/t.my;return[Math.min(e,i),Math.min(s,n),Math.max(e,i),Math.max(s,n)]}_applyConstraints(){const t=this._transform;let e=Math.abs(t.mx);const i=this._getMinMX(),s=this._getMaxMX();(this._crs.toLowerCase().includes("3857")||this._crs.toLowerCase().includes("webmercator"))&&e<i&&(e=i),e>s&&(e=s);const n=t.my>0?e:-e,r=this._getStrictBounds(),a=(this._width/2-t.bx)/t.mx;let o=(this._height/2-t.by)/t.my;if(r){const t=this._height/(2*e),i=r.ymax-t,s=r.ymin+t;s>i?o=(r.ymin+r.ymax)/2:o>i?o=i:o<s&&(o=s)}const h=this._width/2-a*e,l=this._height/2-o*n;this._transform=new $(e,n,h,l)}_getMaxMX(){if(!this._initialExtent)return 1/0;const t=this._initialExtent,e=(...t)=>Math.max(...t.map(Math.abs)),i=e(t.xmin,t.xmax,t.centerX),s=e(t.ymin,t.ymax,t.centerY),n=t.width/this._width/(1e-16*i),r=t.height/this._height/(1e-16*s);return Math.max(n,r)}_getStrictBounds(){const t=this._crs.toLowerCase();return"epsg:3857"===t||"webmercator"===t?new V(-1/0,-18485274.7,1/0,K):null}_getMinMX(){const t=this._crs.toLowerCase();let e;if("epsg:3857"===t||"webmercator"===t)e=36970549.4;else{if("epsg:4326"!==t&&"wgs84"!==t)return.01*this._initialMX;e=180}return this._height/e}}const X=1e-6;class J{_host;_tween=null;_activeEnd=null;constructor(t){this._host=t}_resolve(t){const e=this._host.getCameraState(),i=t.center??e.center;if(s=i,!Number.isFinite(s[0])||!Number.isFinite(s[1]))throw new Error("camera: center must be finite");var s;let n=e.scale;if(void 0!==t.scale)n=t.scale;else if(void 0!==t.zoom){if(!Number.isFinite(t.zoom))throw new Error("camera: zoom must be finite");const e=this._host.scaleFromZoom(t.zoom);if(!Number.isFinite(e))throw new Error("camera: zoom is not meaningful for this CRS — pass { scale } instead");n=e}if(!Number.isFinite(n)||n<=0)throw new Error("camera: scale must be a finite positive number");return{center:[i[0],i[1]],scale:n}}_payload(t){return{center:[t.center[0],t.center[1]],zoom:Math.log2(t.scale),originalEvent:null}}isMoving(){return null!==this._tween}jumpTo(t){const e=this._resolve(t),i=this._host.getCameraState(),s=e.scale!==i.scale;this._cancel();const n=this._payload(e);this._host.fire("movestart",n),s&&this._host.fire("zoomstart",n),this._host.applyCameraState(e.center,e.scale),this._host.requestRender(),this._host.fire("move",n),s&&this._host.fire("zoom",n),this._host.fire("moveend",n),s&&this._host.fire("zoomend",n)}easeTo(t){if(!1===t.animate||0===t.duration)return void this.jumpTo(t);const e=this._resolve(t),i=t.duration??1e3;if(!Number.isFinite(i)||i<0)throw new Error("camera: duration must be a finite non-negative number");const s=t.easing??H.sineInOut;this._cancel();const n=this._host.getCameraState(),r=e.scale!==n.scale,a=Math.log(n.scale),o=Math.log(e.scale),h=this._payload(n);this._host.fire("movestart",h),r&&this._host.fire("zoomstart",h);let l=n;const c=()=>{const t=this._payload(l);this._host.fire("moveend",t),r&&this._host.fire("zoomend",t)};this._activeEnd=c;const u=new H(s);this._tween=u,u.on("change",t=>{const i=t.value;if(i>=1)l=e;else{const t=n.center[0]+(e.center[0]-n.center[0])*i,s=n.center[1]+(e.center[1]-n.center[1])*i,r=Math.exp(a+(o-a)*i);l={center:[t,s],scale:r}}this._host.applyCameraState(l.center,l.scale),this._host.requestRender();const s=this._payload(l);this._host.fire("move",s),r&&this._host.fire("zoom",s),i>=1&&(this._tween=null,this._activeEnd=null,c())}),u.start(0,1,i)}setCenter(t){this.jumpTo({center:t})}setZoom(t){this.jumpTo({zoom:t})}zoomTo(t,e={}){this.easeTo({zoom:t,...e})}panTo(t,e={}){this.easeTo({center:t,...e})}panBy(t,e={}){const{center:i,scale:s}=this._host.getCameraState(),n=[i[0]+t[0]/s,i[1]+t[1]/-s];this.easeTo({center:n,...e})}fitBounds(t,e={}){const{width:i,height:s}=this._host.getViewportSize(),n=e.padding??0,r=Math.max(1,i-2*n),a=Math.max(1,s-2*n),o=[t.centerX,t.centerY],h=t.width,l=t.height;let c;if(!t.hasBounds()||h<=0&&l<=0)c=this._host.getCameraState().scale;else{const t=h>0?r/h:1/0,e=l>0?a/l:1/0;c=Math.min(t,e)}void 0!==e.maxScale&&(c=Math.min(c,e.maxScale)),(!Number.isFinite(c)||c<=0)&&(c=this._host.getCameraState().scale),this.easeTo({center:o,scale:c,...e})}flyTo(t){const e=this._resolve(t);if(!1===t.animate||0===t.duration)return void this.jumpTo(t);let i=t.duration??1e3;if(!Number.isFinite(i)||i<0)throw new Error("camera: duration must be a finite non-negative number");if(null!=t.speed&&(!Number.isFinite(t.speed)||t.speed<=0))throw new Error("camera: speed must be a finite positive number");const s=t.easing??H.sineInOut,n=t.curve??1.42,{width:r}=this._host.getViewportSize();this._cancel();const a=this._host.getCameraState(),o=e.scale!==a.scale,h=Math.hypot(e.center[0]-a.center[0],e.center[1]-a.center[1])*Math.max(a.scale,1e-9),l=r/a.scale,c=r/e.scale,u=n*n;function p(t,e){const i=h||1e-9,s=(c*c-l*l+e*u*u*i*i)/(2*t*u*i);return Math.log(Math.sqrt(s*s+1)-s)}const _=p(l,1),d=p(c,-1),f=h<X?Math.abs(Math.log(c/l))/n:(d-_)/n;null!=t.speed&&(i=1e3*f/t.speed);const m=this._payload(a);this._host.fire("movestart",m),o&&this._host.fire("zoomstart",m);let y=a;const g=()=>{const t=this._payload(y);this._host.fire("moveend",t),o&&this._host.fire("zoomend",t)};this._activeEnd=g;const v=new H(s);this._tween=v,v.on("change",t=>{const i=t.value;let s,c,u;if(h<X){const t=Math.log(a.scale),n=Math.log(e.scale);u=Math.exp(t+(n-t)*i),s=a.center[0]+(e.center[0]-a.center[0])*i,c=a.center[1]+(e.center[1]-a.center[1])*i}else{const t=i*f,o=l*(Math.cosh(_)/Math.cosh(n*t+_));u=r/o,s=a.center[0]+(e.center[0]-a.center[0])*i,c=a.center[1]+(e.center[1]-a.center[1])*i}y={center:[s,c],scale:u},this._host.applyCameraState(y.center,y.scale),this._host.requestRender();const p=this._payload(y);this._host.fire("move",p),o&&this._host.fire("zoom",p),i>=1&&(y=e,this._host.applyCameraState(e.center,e.scale),this._tween=null,this._activeEnd=null,g())}),v.start(0,1,i)}_cancel(){if(this._host.cancelZoomAnimation?.(),this._tween&&(this._tween.stop(),this._tween=null),this._activeEnd){const t=this._activeEnd;this._activeEnd=null,t()}}stop(){this._cancel()}}class Y{snapVertices(e,i,s){t.internal.snapVerticesToPoint(e,i,s)}insertVertex(e,i,s){t.internal.insertVertex(e,i,s)}deleteVertex(e,i){t.internal.deleteVertex(e,i)}appendEmptyArc(e){t.internal.appendEmptyArc(e)}appendVertex(e,i){t.internal.appendVertex(e,i)}deleteLastArc(e){t.internal.deleteLastArc(e)}findNearestVertices(e,i,s){return t.internal.findNearestVertices(e,i,s)}findArcIdFromVertexId(e,i){return t.internal.findArcIdFromVertexId(e,i)}vertexIsArcEndpoint(e,i){return t.internal.vertexIsArcEndpoint(e,i)}forEachSegmentInShape(e,i,s){t.internal.forEachSegmentInShape(e,i,s)}findClosestPointOnSeg(e,i,s,n,r,a,o){return t.internal.findClosestPointOnSeg(e,i,s,n,r,a,o)}addIntersectionCuts(e,i){t.internal.addIntersectionCuts(e,i)}findSegmentIntersections(e,i){return t.internal.findSegmentIntersections(e,i)}getIntersectionLayer(e,i,s){return t.internal.getIntersectionLayer(e,i,s)}getAvgSegment(e){return t.internal.getAvgSegment(e)}simplifyArcsFast(e,i){return t.internal.simplifyArcsFast(e,i)}layerHasGeometry(e){return t.internal.layerHasGeometry(e)}getLayerBounds(e,i){const s=t.internal.getLayerBounds(e,i);return s?{xmin:s.xmin,ymin:s.ymin,xmax:s.xmax,ymax:s.ymax}:{xmin:NaN,ymin:NaN,xmax:NaN,ymax:NaN}}getDatasetBounds(e){const i=t.internal.getDatasetBounds(e);return{xmin:i.xmin,ymin:i.ymin,xmax:i.xmax,ymax:i.ymax}}exportDatasetsToPack(e,i){return t.internal.exportDatasetsToPack(e,i??{})}restoreSessionData(e){return t.internal.restoreSessionData(e)}pack(e){return t.internal.pack(e)}unpackSessionData(e){return t.internal.unpackSessionData(e)}exportPackedDatasets(e,i){return t.internal.exportPackedDatasets(e,i??{})}exportFileContent(e,i){return t.internal.exportFileContent(e,i)}copyDataset(e){return t.internal.copyDataset(e)}runImport(e,i){const s=t.internal.parseCommands(e);return s.length>0&&"i"===s[0].name&&(s[0].options.input=i),new Promise((e,i)=>{t.internal.runParsedCommands(s,new t.internal.Job,(t,s)=>{if(t)return void i(t);const n=s.catalog.getDefaultTargets();0!==n.length?e(n[0].dataset):i(new Error("No layers found in dataset"))})})}runOnDataset(e,i,s){return new Promise((n,r)=>{const a=new t.internal.Job;a.catalog.addDataset(i);const o=t.internal.parseCommands(e);if(s)for(const t of o)t.options&&(t.options.input=s);t.internal.runParsedCommands(o,a,(t,e)=>{if(t)return void r(t);const i=e.catalog.getDefaultTargets();0!==i.length?n(i[0].dataset):r(new Error("mapshaper command completed but produced no default target"))})})}runOnDatasetParsed(e,i,s){return new Promise((n,r)=>{const a=new t.internal.Job;if(a.catalog.addDataset(i),s)for(const t of e)t.options&&(t.options.input=s);t.internal.runParsedCommands(e,a,(t,e)=>{if(t)return void r(t);const i=e.catalog.getDefaultTargets();0!==i.length?n(i[0].dataset):r(new Error("mapshaper command completed but produced no default target"))})})}}let Q=null;function tt(){return Q??(Q=new Y)}function et(t){Q=t}const it=6378137,st=40075016.6855;class nt{_crs="EPSG:4326";get crs(){return this._crs}setCRS(t){this._crs=t}getCenter(t,e){const i=this._crs.toLowerCase();return"epsg:3857"===i||"webmercator"===i?this._webMercatorToLatLng(t,e):[t,e]}getZoom(t){const e=this._crs.toLowerCase();return"epsg:3857"===e||"webmercator"===e?Math.log2(t*st/512):0}getScale(t){const e=this._crs.toLowerCase();return"epsg:3857"===e||"webmercator"===e?512*Math.pow(2,t)/st:NaN}async reproject(t,e){for(const i of e.values())i.reproject&&await i.reproject(t);this._crs=t;const i=tt(),s=new V;for(const t of e.values()){const e=t.getDataset();if(e?.layers)for(const t of e.layers)if(i.layerHasGeometry(t)){const n=i.getLayerBounds(t,e.arcs);n&&s.merge(new V(n.xmin,n.ymin,n.xmax,n.ymax))}}return s.hasBounds()&&s.scale(1.07),s}_webMercatorToLatLng(t,e){const i=180/Math.PI;return[t/it*i,i*(.5*Math.PI-2*Math.atan(Math.exp(-e/it)))]}}function rt(t,e){return t?.name?String(t.name):t?.id?String(t.id):`layer-${e}`}function at(t){return t&&Array.isArray(t)?"number"==typeof t[0]?[t]:Array.isArray(t[0])?t:[]:[]}class ot{_canvas;_ctx;_transform=new $;_pixelRatio=window.devicePixelRatio||1;constructor(t){this._canvas=t;const e=t.getContext("2d");if(!e)throw new Error("Failed to get 2D context");this._ctx=e}setTransform(t){this._transform=t}setPixelRatio(t){this._pixelRatio=t}drawPaths(t,e,i){if(0===e.width)return;const s=this._ctx;s.strokeStyle=e.color||"#333",s.lineWidth=(e.width??1)*this._pixelRatio,s.lineCap="round",s.lineJoin="round";let n=0;s.beginPath(),t.forEach(t=>{t&&t.forEach(t=>{t.forEach(t=>{n>0&&n%25==0&&(s.stroke(),s.beginPath());const e=i.getArcIter(t);this.drawPathSnapping(e,s),n++})})}),s.stroke()}drawArcs(t,e,i){if(0===e.width)return;const s=this._ctx,n=t.size();s.strokeStyle=e.color||"#333",s.lineWidth=(e.width??1)*this._pixelRatio,s.lineCap="round",s.lineJoin="round";let r=0;s.beginPath();for(let e=0;e<n;e++){if(i&&!i(e))continue;r>0&&r%25==0&&(s.stroke(),s.beginPath());const n=t.getArcIter(e);this.drawPathSnapping(n,s),r++}s.stroke()}drawPathSnapping(t,e){const i=this._transform.mx*this._pixelRatio,s=this._transform.my*this._pixelRatio,n=this._transform.bx*this._pixelRatio,r=this._transform.by*this._pixelRatio;let a,o,h,l,c=0;if(t.hasNext()){for(a=2*(t.x*i+n)|0,o=2*(t.y*s+r)|0,e.moveTo(a/2,o/2);t.hasNext();)h=a,l=o,a=2*(t.x*i+n)|0,o=2*(t.y*s+r)|0,a===h&&o===l||(e.lineTo(a/2,o/2),c++);0===c&&e.lineTo(a/2+.1,o/2)}}drawPoints(t,e){const i=this._ctx,s=this._pixelRatio,n=this._transform.mx*s,r=this._transform.my*s,a=this._transform.bx*s,o=this._transform.by*s,h=(Number(e?.radius)||4)*s,l=e?.color||"#333",c=!1!==e?.fill;i.beginPath(),i.fillStyle=l,i.strokeStyle=l,t.forEach(t=>{if(!t)return;at(t).forEach(t=>{const e=t[0]*n+a,s=t[1]*r+o;i.moveTo(e+h,s),i.arc(e,s,h,0,2*Math.PI)})}),c?i.fill():i.stroke()}drawVertexDots(t,e,i={}){const s=this._ctx,n=this._pixelRatio,r=this._transform.mx*n,a=this._transform.my*n,o=this._transform.bx*n,h=this._transform.by*n,l=i.dotColor||"#333",c=(i.dotRadius||3)*n,u=i.hoverColor||"#cc6acc",p=(i.hoverRadius||6)*n,_=i.hoverVertex;let d=null;_&&(d=[_[0]*r+o,_[1]*a+h]),s.fillStyle=l,s.beginPath(),t.forEach(t=>{t&&t.forEach(t=>{t.forEach(t=>{const i=t>=0?t:~t,n=e.getArcIter(i);for(;n.hasNext();){const t=n.x*r+o,e=n.y*a+h;d&&Math.abs(t-d[0])<1&&Math.abs(e-d[1])<1||(s.moveTo(t+c,e),s.arc(t,e,c,0,2*Math.PI))}})})}),s.fill(),d&&(s.fillStyle=u,s.beginPath(),"interpolated"===i.hoverType?s.rect(d[0]-p,d[1]-p,2*p,2*p):s.arc(d[0],d[1],p,0,2*Math.PI),s.fill())}drawPolygonFill(t,e,i,s,n){if(!e.getShapeIter)return;const r=this._ctx,a=this._pixelRatio,o=this._transform.mx*a,h=this._transform.my*a,l=this._transform.bx*a,c=this._transform.by*a;r.fillStyle=i;const u="number"==typeof n&&1!==n,p=r.globalAlpha;u&&(r.globalAlpha=p*Math.max(0,Math.min(1,n)));let _=0;r.beginPath();for(let i=0;i<t.length;i++){const n=t[i];if(!n)continue;let a=!0;if(s){a=!1;for(const t of n){for(const e of t){if(s(e>=0?e:~e)){a=!0;break}}if(a)break}}if(a){_>0&&_>=100&&(r.fill("evenodd"),r.beginPath(),_=0);for(const t of n){const i=e.getShapeIter(t);if(!i.hasNext())continue;let s,n,a=2*(i.x*o+l)|0,u=2*(i.y*h+c)|0;for(r.moveTo(a/2,u/2);i.hasNext();)s=a,n=u,a=2*(i.x*o+l)|0,u=2*(i.y*h+c)|0,a===s&&u===n||r.lineTo(a/2,u/2);r.closePath()}_++}}_>0&&r.fill("evenodd"),u&&(r.globalAlpha=p)}drawDrawingOverlay(t){const e=this._ctx,i=this._pixelRatio,s=this._transform.mx*i,n=this._transform.my*i,r=this._transform.bx*i,a=this._transform.by*i,o=t.drawColor||"#0078ff",h=t.vertices,l=t.cursorCoord,c=t=>[t[0]*s+r,t[1]*n+a];if(h.length>0){e.strokeStyle=o,e.lineWidth=2*i,e.lineJoin="round",e.lineCap="round",e.setLineDash([]),e.beginPath();const t=c(h[0]);e.moveTo(t[0],t[1]);for(let t=1;t<h.length;t++){const i=c(h[t]);e.lineTo(i[0],i[1])}e.stroke()}if(h.length>0&&l){const s=c(h[h.length-1]),n=c(l);if(e.strokeStyle=o,e.lineWidth=1.5*i,e.setLineDash([6*i,4*i]),e.beginPath(),e.moveTo(s[0],s[1]),e.lineTo(n[0],n[1]),"polygon"===t.geometryType&&h.length>=2){const t=c(h[0]);e.moveTo(n[0],n[1]),e.lineTo(t[0],t[1])}e.stroke(),e.setLineDash([])}if(h.length>0){const t=4*i;e.fillStyle=o,e.beginPath();for(const i of h){const s=c(i);e.moveTo(s[0]+t,s[1]),e.arc(s[0],s[1],t,0,2*Math.PI)}e.fill()}if(t.snapCoord){const s=c(t.snapCoord),n=7*i;e.strokeStyle="#ff4444",e.lineWidth=2*i,e.beginPath(),"edge"===t.snapKind?e.rect(s[0]-n,s[1]-n,2*n,2*n):e.arc(s[0],s[1],n,0,2*Math.PI),e.stroke()}}clear(){this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height)}resize(t,e){const i=this._pixelRatio;this._canvas.width=t*i,this._canvas.height=e*i,this._canvas.style.width=t+"px",this._canvas.style.height=e+"px"}}class ht{_painter;constructor(t){this._painter=t}render(t,e,i){"vertex"===t&&e?this._renderVertexOverlay(e):"draw"===t&&i&&this._painter.drawDrawingOverlay(i)}_renderVertexOverlay(t){const e=t.arcs;"polygon"===t.geometryType&&t.polygonFill&&this._painter.drawPolygonFill(t.shapes,e,t.polygonFill),this._painter.drawVertexDots(t.shapes,e,{dotColor:"#333",dotRadius:3,hoverVertex:t.hoverVertex,hoverType:t.hoverType??"vertex",hoverColor:"#cc6acc",hoverRadius:6})}}class lt{opts;label;invalidatesPriorCommands=!0;constructor(t){this.opts=t,this.label=t.label}do(){this.opts.source.setDataset(this.opts.after)}undo(){this.opts.source.setDataset(this.opts.before)}}const ct=Object.freeze({ok:!0,value:void 0});function ut(t){return{ok:!0,value:t}}const pt=Object.freeze({notFound:(t,e)=>({ok:!1,error:{kind:"not-found",what:t,id:e}}),validation:(t,e)=>({ok:!1,error:{kind:"validation",field:t,reason:e}}),expressionDisabled:t=>({ok:!1,error:{kind:"expression-disabled",operation:t}}),mapshaper:(t,e)=>({ok:!1,error:{kind:"mapshaper",cause:t,...e??{}}}),hostRemoved:()=>({ok:!1,error:{kind:"host-removed"}})}),_t=new Set(["rename-fields","rename-layers","sort","sort-features","filter-fields","drop","target","uniq","unique-features"]),dt=new Set(["buffer","clean","dissolve","mosaic","union","snap","check-geometry","simplify"]);function ft(t){const e=[],i=/(?:^|\s)-([a-z][a-z-]*)/gi;let s;for(;null!==(s=i.exec(t));)e.push(s[1].toLowerCase());return e}function mt(t,e,i,s){if(!1===i)return!1;if(!0===i)return!0;if(0===t.length)return e>=s;if(t.every(t=>_t.has(t)))return!1;return e>=(t.some(t=>dt.has(t))?Math.floor(.5*s):s)}const yt={clip:"shape-count",erase:"shape-count",dissolve:"shape-count",explode:"shape-count",filter:"shape-count","filter-geom":"shape-count","filter-islands":"shape-count","filter-slivers":"shape-count","merge-layers":"shape-count",mosaic:"shape-count",union:"shape-count",divide:"shape-count",points:"shape-count",lines:"shape-count",polygons:"shape-count",innerlines:"shape-count",split:"shape-count","split-layer":"shape-count",uniq:"shape-count",buffer:"shape-count",drop:"shape-count","intersection-points":"shape-count",clean:"topology-only",snap:"topology-only",simplify:"topology-only","rebuild-topology":"topology-only",each:"attribute-only",join:"attribute-only","rename-fields":"attribute-only","rename-layers":"attribute-only","filter-fields":"attribute-only","data-fill":"attribute-only",sort:"attribute-only",proj:"crs-only",project:"crs-only",affine:"crs-only"};function gt(t){let e="attribute-only",i=!1;for(const s of t){if("target"===s)continue;const t=yt[s];if(void 0===t)return"unknown";i=!0,e=xt(e,t)}return i?e:"unknown"}const vt={"attribute-only":0,"crs-only":1,"topology-only":2,"shape-count":3,unknown:3};function xt(t,e){return vt[t]>=vt[e]?t:e}async function bt(t,e,i,s,n){if(t._removed)return pt.hostRemoved();const r=t._sources.get(e);if(!r)return pt.notFound("source",e);const a=r.getDataset();if(!a)return pt.notFound("source",e);const o=tt().copyDataset(a);let h,l=!1;if(t._workerPool){const e=a.arcs?.getPointCount?.()??0,s=function(t,e,i,s){return!1!==i&&(!0===i||mt(ft(t),e,i,s))}(i,e,t._workerMode,t._workerThreshold),n=t._workerRouting;l=n?n({cmd:i,heads:ft(i),vertexCount:e,mode:t._workerMode,threshold:t._workerThreshold,defaultDecision:s}):s}try{h=l?await async function(t,e,i,s,n){if(!t._workerPool)throw new Error("_runViaWorker: worker pool not available");const r=t._workerPool.reserveId(),a=e.arcs?.getPointCount?.()??0,o="undefined"!=typeof performance?performance.now():Date.now();t.fire("workerjobstart",{id:r,cmd:i,label:s,datasetVertexCount:a});try{const s=await tt().exportDatasetsToPack([e],{compact:!1}),a=Ct(s),h=t._workerPool.dispatchWithId(r,i,s,n,a),l=await h,c=await tt().restoreSessionData(l);if(!c.datasets||0===c.datasets.length)throw new Error("worker: no dataset in response");const u=("undefined"!=typeof performance?performance.now():Date.now())-o;return t.fire("workerjobend",{id:r,ok:!0,durationMs:u}),c.datasets[0]}catch(e){const i=("undefined"!=typeof performance?performance.now():Date.now())-o;throw t.fire("workerjobend",{id:r,ok:!1,durationMs:i,errorMessage:e?.message??String(e)}),e}}(t,a,i,s,n):await tt().runOnDataset(i,a,n)}catch(e){return t._removed?pt.hostRemoved():(t.fire("error",{error:e}),pt.mapshaper(e,{cmd:i,operation:s}))}return t._removed?pt.hostRemoved():St(t,e,o,h,s,function(t){return gt(ft(t))}(i))}async function wt(t,e,i,s,n){if(t._removed)return pt.hostRemoved();const r=t._sources.get(e);if(!r)return pt.notFound("source",e);const a=r.getDataset();if(!a)return pt.notFound("source",e);const o=tt().copyDataset(a),h=i.map(t=>t.name);let l,c=!1;if(t._workerPool){const e=a.arcs?.getPointCount?.()??0,i=mt(h,e,t._workerMode,t._workerThreshold),s=t._workerRouting;c=s?s({cmd:h.map(t=>`-${t}`).join(" "),heads:h,vertexCount:e,mode:t._workerMode,threshold:t._workerThreshold,defaultDecision:i}):i}try{l=c?await async function(t,e,i,s,n){if(!t._workerPool)throw new Error("_runViaWorkerParsed: worker pool not available");const r=t._workerPool.reserveId(),a=e.arcs?.getPointCount?.()??0,o="undefined"!=typeof performance?performance.now():Date.now(),h=i.map(t=>`-${t.name}`).join(" ");t.fire("workerjobstart",{id:r,cmd:h,label:s,datasetVertexCount:a});try{const s=await tt().exportDatasetsToPack([e],{compact:!1}),a=Ct(s),h=t._workerPool.dispatchWithId(r,i,s,n,a),l=await h,c=await tt().restoreSessionData(l);if(!c.datasets||0===c.datasets.length)throw new Error("worker: no dataset in response");const u=("undefined"!=typeof performance?performance.now():Date.now())-o;return t.fire("workerjobend",{id:r,ok:!0,durationMs:u}),c.datasets[0]}catch(e){const i=("undefined"!=typeof performance?performance.now():Date.now())-o;throw t.fire("workerjobend",{id:r,ok:!1,durationMs:i,errorMessage:e?.message??String(e)}),e}}(t,a,i,s,n):await tt().runOnDatasetParsed(i,a,n)}catch(e){return t._removed?pt.hostRemoved():(t.fire("error",{error:e}),pt.mapshaper(e,{operation:s}))}return t._removed?pt.hostRemoved():St(t,e,o,l,s,gt(h))}function St(t,e,i,s,n,r="unknown"){const a=t._sources.get(e);return a?(t._activeTransaction&&t._activeTransaction._captureFirstTouch(e,i),a.setDataset(s),t._history.push(new lt({source:a,before:i,after:s,label:n})),t._history.isCapturing()||t._fireHistoryChange(),function(t){return"shape-count"===t||"topology-only"===t||"unknown"===t}(r)&&t._fireSelectionChange(t._selection.clear()),t._scheduleRender(),ct):pt.notFound("source",e)}function Ct(t){const e=[],i=new Set,s=t=>{if(t&&"object"==typeof t){if(t instanceof Uint8Array){const s=t.buffer;return void(s instanceof ArrayBuffer&&!i.has(s)&&(i.add(s),e.push(s)))}if(t instanceof ArrayBuffer)i.has(t)||(i.add(t),e.push(t));else if(Array.isArray(t))for(const e of t)s(e);else for(const e of Object.keys(t))s(t[e])}};return s(t),e}function At(t,e){for(let i=0;i<t.length;i++){const s=t[i];if(s){if(rt(s,i)===e)return s;if(s.name===e)return s;if(s.id===e)return s}}return null}class Et{_sources;constructor(t){this._sources=t}resolve(t,e){const i=this._sources.get(t);return i?At(i.getLayers(),e):null}resolveInLayers(t,e){return At(t,e)}}async function Mt(t,e,i){const s=t.host._sources.get(e.source);if(!s)return pt.notFound("source",e.source);const n=s.getDataset();if(!n)return pt.notFound("source",e.source);if(!At(n.layers,e.target))return pt.notFound("layer",e.target);const r="string"==typeof e.mask&&e.mask.length>0;if(r===Array.isArray(e.bbox))return pt.validation(r?"mask":"bbox","must supply exactly one of `mask` or `bbox`");if(r){if(!At(n.layers,e.mask))return pt.notFound("mask",e.mask)}else{const t=e.bbox;if(4!==t.length||!t.every(t=>Number.isFinite(t)))return pt.validation("bbox","must be [xmin, ymin, xmax, ymax] of finite numbers");if(t[0]>=t[2]||t[1]>=t[3])return pt.validation("bbox","must satisfy xmin<xmax and ymin<ymax")}const a=r?{source:e.mask}:{bbox:e.bbox};e.cleanup&&(a.cleanup=!0),e.removeSlivers&&(a.remove_slivers=!0);const o="clip"===i?"Clip":"Erase";return t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:i,options:a}],`${o} ${e.target}`)}const kt="__emap_merge";async function It(t){const e=t.host._selection.getAll();if(0===e.length)return pt.validation("selection","selection is empty");const i=e[0].source,s=e[0].layer;for(const t of e)if(t.source!==i||t.layer!==s)return pt.validation("selection","selection spans multiple sources or layers");const n=t.host.layers.resolve(i,s);if(!n)return pt.notFound("layer",s);if(!function(t,e){const i=t.data?.getRecords?.();if(!i||0===i.length)return!1;const s=new Set(e);for(let t=0;t<i.length;t++){const e=i[t]??{};e[kt]=s.has(t)?"M":`k_${t}`,i[t]=e}return!0}(n,e.map(t=>t.id).slice().sort((t,e)=>t-e)))return pt.validation("layer","layer has no data table; cannot stamp discriminator");const r=function(t,e){const i={fields:[kt]},s=e.data?.getFields?.();if(s&&s.length>0){const t=s.filter(t=>t!==kt&&!t.includes(","));t.length>0&&(i.copy_fields=t)}return[{name:"target",options:{target:t}},{name:"dissolve",options:i},{name:"filter-fields",options:{fields:[kt],invert:!0}}]}(s,n),a=`Merge ${e.length} feature${e.length>1?"s":""}`,o=await t.runDatasetCommandParsed(i,r,a);return o.ok||function(t){const e=t.data?.getRecords?.();if(!e)return;for(const t of e)t&&kt in t&&delete t[kt]}(n),o}const Dt=new Set(["left","right","outer","inner"]),Pt=new Set(["flat","round"]),Tt=/^-?\d+(\.\d+)?$/;function Lt(t){return"number"==typeof t&&Number.isInteger(t)&&t>0}async function Ft(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);const n=At(s.layers,e.target);if(!n)return pt.notFound("layer",e.target);if("number"==typeof e.radius){if(!Number.isFinite(e.radius)||e.radius<=0)return pt.validation("radius","must be a positive finite number")}else{if("string"!=typeof e.radius||0===e.radius.trim().length)return pt.validation("radius","must be a positive number or non-empty expression");if(Tt.test(e.radius)&&Number(e.radius)<=0)return pt.validation("radius","numeric string must be a positive number")}if("string"==typeof e.radius&&!t.host._allowExpressionEvaluation([e.radius],"bufferLayer"))return pt.expressionDisabled("bufferLayer");if(void 0!==e.vertices&&!Lt(e.vertices))return pt.validation("vertices","must be a positive integer");if(void 0!==e.arcQuality&&!Lt(e.arcQuality))return pt.validation("arcQuality","must be a positive integer");if(void 0!==e.sliceLength&&!Lt(e.sliceLength))return pt.validation("sliceLength","must be a positive integer");if(void 0!==e.backtrack&&!Lt(e.backtrack))return pt.validation("backtrack","must be a positive integer");if(void 0!==e.tolerance&&!("number"==typeof(r=e.tolerance)&&Number.isFinite(r)&&r>0))return pt.validation("tolerance","must be a positive finite number");var r;if(void 0!==e.type&&!Dt.has(e.type))return pt.validation("type","must be one of: left, right, outer, inner");if(void 0!==e.capStyle&&!Pt.has(e.capStyle))return pt.validation("capStyle","must be one of: flat, round");void 0!==e.type&&"polygon"===n.geometry_type&&console.warn(`bufferLayer: type="${e.type}" is intended for polyline layers; applying to polygon layer "${e.target}" may produce unexpected output.`);const a={radius:String(e.radius)};void 0!==e.capStyle&&(a.cap_style=e.capStyle),void 0!==e.vertices&&(a.vertices=e.vertices),void 0!==e.arcQuality&&(a.arc_quality=e.arcQuality),void 0!==e.tolerance&&(a.tolerance=e.tolerance),void 0!==e.type&&(a.type=e.type),!0===e.planar&&(a.planar=!0),!0===e.v2&&(a.v2=!0),void 0!==e.sliceLength&&(a.slice_length=e.sliceLength),void 0!==e.backtrack&&(a.backtrack=e.backtrack);const o=[{name:"target",options:{target:e.target}},{name:"buffer",options:a}];return t.runDatasetCommandParsed(e.source,o,`Buffer ${e.target}`)}class Nt{_emap;constructor(t){this._emap=t}get _ctx(){return{host:this._emap,runDatasetCommand:(t,e,i,s)=>bt(this._emap,t,e,i,s),runDatasetCommandParsed:(t,e,i,s)=>wt(this._emap,t,e,i,s),applyDatasetReplace:(t,e,i,s)=>St(this._emap,t,e,i,s)}}clipLayer(t){return async function(t,e){return Mt(t,e,"clip")}(this._ctx,t)}eraseLayer(t){return async function(t,e){return Mt(t,e,"erase")}(this._ctx,t)}dissolveLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);const n=Array.isArray(e.fields)&&e.fields.length>0;if(void 0!==e.field&&n)return pt.validation("field","`field` and `fields` are mutually exclusive");if(void 0!==e.field&&("string"!=typeof e.field||e.field.includes(",")))return pt.validation("field","field name must be a string without `,`");if(!t.host._allowExpressionEvaluation([e.calc,e.where],"dissolveLayer"))return pt.expressionDisabled("dissolveLayer");const r={};if(e.field)r.fields=[e.field];else if(n){const t=e.fields.filter(t=>"string"==typeof t&&!t.includes(","));t.length>0&&(r.fields=t)}const a=t=>Array.isArray(t)?t.filter(t=>"string"==typeof t&&!t.includes(",")):[],o=a(e.sumFields);o.length>0&&(r.sum_fields=o);const h=a(e.copyFields);return h.length>0&&(r.copy_fields=h),e.calc&&e.calc.trim()&&(r.calc=e.calc),e.where&&e.where.trim()&&(r.where=e.where),e.multipart&&(r.multipart=!0),e.name&&e.name.trim()&&(r.name=e.name),e.noReplace&&(r.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"dissolve",options:r}],`Dissolve ${e.target}`)}(this._ctx,t)}bufferLayer(t){return Ft(this._ctx,t)}applyExpression(t){return async function(t,e){if(!e.expression||!e.expression.trim())return pt.validation("expression","must be a non-empty expression");const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.expression,e.where],"applyExpression"))return pt.expressionDisabled("applyExpression");const n={expression:e.expression};return e.where&&e.where.trim()&&(n.where=e.where),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"each",options:n}],`Update ${e.target}`)}(this._ctx,t)}filterFeatures(t){return async function(t,e){const i=!(!e.expression||!e.expression.trim());if(!i&&!e.removeEmpty)return pt.validation("expression","must supply `expression` or `removeEmpty: true`");const s=t.host._sources.get(e.source);if(!s)return pt.notFound("source",e.source);const n=s.getDataset();if(!n)return pt.notFound("source",e.source);if(!At(n.layers,e.target))return pt.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.expression],"filterFeatures"))return pt.expressionDisabled("filterFeatures");const r={};return i&&(r.expression=e.expression),e.invert&&(r.invert=!0),e.removeEmpty&&(r.remove_empty=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"filter",options:r}],`Filter ${e.target}`)}(this._ctx,t)}filterIslands(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);const n="number"==typeof e.minArea&&Number.isFinite(e.minArea),r="number"==typeof e.minVertices&&Number.isInteger(e.minVertices)&&e.minVertices>0;if(!n&&!r)return pt.validation("minArea","must supply at least one of `minArea` or `minVertices`");if(n&&e.minArea<0)return pt.validation("minArea","must be non-negative");const a={};return n&&(a.min_area=String(e.minArea)),r&&(a.min_vertices=e.minVertices),e.removeEmpty&&(a.remove_empty=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"filter-islands",options:a}],`Filter islands ${e.target}`)}(this._ctx,t)}filterSlivers(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);if("number"!=typeof e.minArea||!Number.isFinite(e.minArea)||e.minArea<=0)return pt.validation("minArea","must be a positive finite number");const n={min_area:String(e.minArea)};return e.weighted&&(n.weighted=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"filter-slivers",options:n}],`Filter slivers ${e.target}`)}(this._ctx,t)}filterGeom(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);const n=e.bbox;return Array.isArray(n)&&4===n.length&&n.every(t=>Number.isFinite(t))?n[0]>=n[2]||n[1]>=n[3]?pt.validation("bbox","must satisfy xmin<xmax and ymin<ymax"):t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"filter-geom",options:{bbox:[n[0],n[1],n[2],n[3]]}}],`Filter geom ${e.target}`):pt.validation("bbox","must be [xmin, ymin, xmax, ymax] of finite numbers")}(this._ctx,t)}explodeLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();return s?At(s.layers,e.target)?t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"explode",options:{}}],`Explode ${e.target}`):pt.notFound("layer",e.target):pt.notFound("source",e.source)}(this._ctx,t)}innerlinesLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.where],"innerlinesLayer"))return pt.expressionDisabled("innerlinesLayer");const n={};return e.where&&e.where.trim()&&(n.where=e.where),e.name&&e.name.trim()&&(n.name=e.name),e.noReplace&&(n.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"innerlines",options:n}],`Innerlines ${e.target}`)}(this._ctx,t)}snapLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);const n={};return"number"==typeof e.interval&&(n.interval=String(e.interval)),e.endpoints&&(n.endpoints=!0),"number"==typeof e.precision&&(n.precision=e.precision),e.fixGeometry&&(n.fix_geometry=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"snap",options:n}],`Snap ${e.target}`)}(this._ctx,t)}cleanLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);const n=t=>void 0===t||"number"==typeof t&&Number.isFinite(t)&&t>=0;if(!n(e.gapFillArea))return pt.validation("gapFillArea","must be a finite non-negative number");if(!n(e.sliverControl))return pt.validation("sliverControl","must be a finite non-negative number");if(!n(e.snapInterval))return pt.validation("snapInterval","must be a finite non-negative number");if(void 0!==e.overlapRule){const t=["min-id","max-id","min-area","max-area"];if(!t.includes(e.overlapRule))return pt.validation("overlapRule",`must be one of ${t.join(", ")}`)}const r={};return void 0!==e.gapFillArea&&(r.gap_fill_area=String(e.gapFillArea)),void 0!==e.sliverControl&&(r.sliver_control=e.sliverControl),void 0!==e.snapInterval&&(r.snap_interval=String(e.snapInterval)),e.noSnap&&(r.no_snap=!0),e.allowOverlaps&&(r.allow_overlaps=!0),void 0!==e.overlapRule&&(r.overlap_rule=e.overlapRule),e.allowEmpty&&(r.allow_empty=!0),e.rewind&&(r.rewind=!0),e.onlyArcs&&(r.only_arcs=!0),e.noArcDissolve&&(r.no_arc_dissolve=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"clean",options:r}],`Clean ${e.target}`)}(this._ctx,t)}mosaicLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);if(!t.host._allowExpressionEvaluation([e.calc],"mosaicLayer"))return pt.expressionDisabled("mosaicLayer");const n={};return"number"==typeof e.snapInterval&&(n.snap_interval=String(e.snapInterval)),e.noSnap&&(n.no_snap=!0),e.noReplace&&(n.no_replace=!0),e.name&&e.name.trim()&&(n.name=e.name),e.calc&&e.calc.trim()&&(n.calc=e.calc),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"mosaic",options:n}],`Mosaic ${e.target}`)}(this._ctx,t)}unionLayers(t){return async function(t,e){if(!e.targets||e.targets.length<2)return pt.validation("targets","must supply at least 2 target layers");const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);for(const t of e.targets){if("string"!=typeof t||t.includes(","))return pt.validation("targets",`target name must not contain ',': ${String(t)}`);if(!At(s.layers,t))return pt.notFound("layer",t)}const n=e.targets.join(","),r={};if(e.fields&&e.fields.length>0){const t=e.fields.filter(t=>!t.includes(","));t.length>0&&(r.fields=t)}return e.name&&e.name.trim()&&(r.name=e.name),e.noReplace&&(r.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:n}},{name:"union",options:r}],`Union ${n}`)}(this._ctx,t)}divideLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);const n=At(s.layers,e.target);if(!n)return pt.notFound("layer",e.target);if("polyline"!==n.geometry_type)return pt.validation("target",`expected polyline layer, got ${n.geometry_type??"unknown"}`);const r=At(s.layers,e.divider);if(!r)return pt.notFound("divider",e.divider);if("polygon"!==r.geometry_type)return pt.validation("divider",`expected polygon layer, got ${r.geometry_type??"unknown"}`);const a={source:e.divider};if(e.fields&&e.fields.length>0){const t=e.fields.filter(t=>!t.includes(","));t.length>0&&(a.fields=t)}return e.force&&(a.force=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"divide",options:a}],`Divide ${e.target}`)}(this._ctx,t)}pointsLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);const n=At(s.layers,e.target);if(!n)return pt.notFound("layer",e.target);const r=n.geometry_type;switch(e.type){case"centroid":case"inner":if("polygon"!==r)return pt.validation("type",`${e.type} requires polygon target, got ${r??"unknown"}`);break;case"midpoints":case"interpolated":if("polyline"!==r)return pt.validation("type",`${e.type} requires polyline target, got ${r??"unknown"}`);break;case"vertices":case"endpoints":if("polygon"!==r&&"polyline"!==r)return pt.validation("type",`${e.type} requires polygon/polyline target, got ${r??"unknown"}`);break;default:return pt.validation("type",`unknown type: ${String(e.type)}`)}if("interpolated"===e.type&&!("number"==typeof e.interval&&e.interval>0))return pt.validation("interval","interpolated points require a positive interval");const a={[e.type]:!0};return"interpolated"===e.type&&(a.interval=String(e.interval)),e.name&&e.name.trim()&&(a.name=e.name),e.noReplace&&(a.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"points",options:a}],`Points ${e.target}`)}(this._ctx,t)}linesLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);const n=At(s.layers,e.target);if(!n)return pt.notFound("layer",e.target);if("polygon"!==n.geometry_type)return pt.validation("target",`expected polygon layer, got ${n.geometry_type??"unknown"}`);const r={},a=e.fields?.filter(t=>"string"==typeof t&&!t.includes(","));return a&&a.length>0&&(r.fields=a),e.name&&e.name.trim()&&(r.name=e.name),e.noReplace&&(r.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"lines",options:r}],`Lines ${e.target}`)}(this._ctx,t)}polygonsLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);const n=At(s.layers,e.target);if(!n)return pt.notFound("layer",e.target);if("polyline"!==n.geometry_type)return pt.validation("target",`expected polyline layer, got ${n.geometry_type??"unknown"}`);const r={};return"number"==typeof e.gapTolerance&&e.gapTolerance>0&&(r.gap_tolerance=String(e.gapTolerance)),e.fromRings&&(r.from_rings=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"polygons",options:r}],`Polygons ${e.target}`)}(this._ctx,t)}simplifyLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(void 0!==e.target&&!At(s.layers,e.target))return pt.notFound("layer",e.target);if(1!==[void 0!==e.percentage,void 0!==e.interval,void 0!==e.resolution].filter(Boolean).length)return pt.validation("threshold","must supply exactly one of percentage, interval, resolution");const n={};if(void 0!==e.percentage){const t=e.percentage;if(!Number.isFinite(t)||t<0||t>100)return pt.validation("percentage","must be a finite number in [0, 100]");n.percentage=`${t}%`}else if(void 0!==e.interval){const t=e.interval;if(!Number.isFinite(t)||t<=0)return pt.validation("interval","must be a positive finite number");n.interval=String(t)}else{const t=e.resolution;if(!/^\d+x\d+$/.test(t))return pt.validation("resolution","must match `WIDTHxHEIGHT` (digits)");n.resolution=t}if(void 0!==e.weighting&&void 0!==e.method&&"weighted"!==e.method)return pt.validation("weighting",`weighting only applies to method='weighted', not ${e.method}`);e.method&&(n.method=e.method),"number"==typeof e.weighting&&Number.isFinite(e.weighting)&&(n.weighting=e.weighting),e.planar&&(n.planar=!0),e.keepShapes&&(n.keep_shapes=!0),e.lockBox&&(n.lock_box=!0),e.noRepair&&(n.no_repair=!0);const r=[];e.target&&r.push({name:"target",options:{target:e.target}}),r.push({name:"simplify",options:n});const a=`Simplify ${e.target??e.source}`;return t.runDatasetCommandParsed(e.source,r,a)}(this._ctx,t)}projectLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(void 0!==e.target&&!At(s.layers,e.target))return pt.notFound("layer",e.target);const n=(e.crs??"").trim();if(0===n.length)return pt.validation("crs","must be a non-empty CRS string");const r={crs:n};e.init&&e.init.trim()&&(r.init=e.init),e.densify&&(r.densify=!0);const a=[];e.target&&a.push({name:"target",options:{target:e.target}}),a.push({name:"proj",options:r});const o=`Project ${e.target??e.source}`;return t.runDatasetCommandParsed(e.source,a,o)}(this._ctx,t)}affineLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(void 0!==e.target&&!At(s.layers,e.target))return pt.notFound("layer",e.target);const n=Array.isArray(e.shift),r="number"==typeof e.rotate&&0!==e.rotate,a=void 0!==e.scale&&("number"==typeof e.scale?1!==e.scale:Array.isArray(e.scale));if(!n&&!r&&!a)return pt.validation("shift","must supply at least one of `shift`, `rotate`, or `scale`");if(n){const t=e.shift;if(2!==t.length||!t.every(t=>Number.isFinite(t)))return pt.validation("shift","must be [dx, dy] of finite numbers")}if(r&&!Number.isFinite(e.rotate))return pt.validation("rotate","must be a finite number (degrees)");if(a&&Array.isArray(e.scale)){const t=e.scale;if(2!==t.length||!t.every(t=>Number.isFinite(t)&&0!==t))return pt.validation("scale","must be [sx, sy] of nonzero finite numbers")}else if(a&&"number"==typeof e.scale&&(!Number.isFinite(e.scale)||0===e.scale))return pt.validation("scale","must be a nonzero finite number");if(!(void 0===e.anchor||Array.isArray(e.anchor)&&2===e.anchor.length&&e.anchor.every(t=>Number.isFinite(t))))return pt.validation("anchor","must be [x, y] of finite numbers");if(!t.host._allowExpressionEvaluation([e.where],"affineLayer"))return pt.expressionDisabled("affineLayer");const o={};n&&(o.shift=[String(e.shift[0]),String(e.shift[1])]),r&&(o.rotate=e.rotate),a&&(o.scale=(e.scale,e.scale)),e.anchor&&(o.anchor=[e.anchor[0],e.anchor[1]]),e.where&&e.where.trim()&&(o.where=e.where);const h=[];e.target&&h.push({name:"target",options:{target:e.target}}),h.push({name:"affine",options:o});const l=`Affine ${e.target??e.source}`;return t.runDatasetCommandParsed(e.source,h,l)}(this._ctx,t)}renameLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);const n=(e.name??"").trim();if(0===n.length)return pt.validation("name","must be a non-empty string");if(n.includes(","))return pt.validation("name","must not contain `,`");if(n!==e.target&&s.layers.some(t=>(t?.name??"")===n))return pt.validation("name",`another layer already named '${n}'`);return t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"rename-layers",options:{names:[n]}}],`Rename ${e.target} → ${n}`)}(this._ctx,t)}mergeLayers(t){return async function(t,e){if(!e.targets||e.targets.length<2)return pt.validation("targets","must supply at least 2 target layers");const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);for(const t of e.targets)if("string"!=typeof t||t.includes(","))return pt.validation("targets",`target name must not contain ',': ${String(t)}`);const n=e.targets.map(t=>At(s.layers,t));for(let t=0;t<n.length;t++)if(!n[t])return pt.notFound("layer",e.targets[t]);if(!e.force){const t=n[0]?.geometry_type;if(!n.every(e=>e?.geometry_type===t))return pt.validation("targets","targets have mixed geometry types; pass `force: true` to merge anyway")}const r=e.targets.join(","),a={};return e.name&&e.name.trim()&&(a.name=e.name),e.force&&(a.force=!0),e.flatten&&(a.flatten=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:r}},{name:"merge-layers",options:a}],`Merge ${r}`)}(this._ctx,t)}splitLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);const n=(e.expression??"").trim();if(0===n.length)return pt.validation("expression","must be a non-empty expression");if(!t.host._allowExpressionEvaluation([n],"splitLayer"))return pt.expressionDisabled("splitLayer");const r={expression:n};return e.noReplace&&(r.no_replace=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"split",options:r}],`Split ${e.target}`)}(this._ctx,t)}dropLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();return s?At(s.layers,e.target)?t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"drop",options:{}}],`Drop ${e.target}`):pt.notFound("layer",e.target):pt.notFound("source",e.source)}(this._ctx,t)}sortFeatures(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);const n=(e.expression??"").trim();if(0===n.length)return pt.validation("expression","must be a non-empty expression");if(!t.host._allowExpressionEvaluation([n],"sortFeatures"))return pt.expressionDisabled("sortFeatures");const r={expression:n};return e.descending&&(r.descending=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"sort",options:r}],`Sort ${e.target}`)}(this._ctx,t)}uniqueFeatures(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);const n=(e.expression??"").trim();if(0===n.length)return pt.validation("expression","must be a non-empty expression");if(!t.host._allowExpressionEvaluation([n],"uniqueFeatures"))return pt.expressionDisabled("uniqueFeatures");if(void 0!==e.maxCount&&!("number"==typeof e.maxCount&&e.maxCount>0))return pt.validation("maxCount","must be a positive number");const r={expression:n};return void 0!==e.maxCount&&(r.max_count=e.maxCount),e.invert&&(r.invert=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"uniq",options:r}],`Uniq ${e.target}`)}(this._ctx,t)}filterFields(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);if(!Array.isArray(e.fields)||0===e.fields.length)return pt.validation("fields","must be a non-empty array");for(const t of e.fields){if("string"!=typeof t||0===t.trim().length)return pt.validation("fields",`field name must be a non-empty string: ${String(t)}`);if(t.includes(","))return pt.validation("fields",`field name must not contain ',': ${t}`)}const n={fields:e.fields.slice()};return e.invert&&(n.invert=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"filter-fields",options:n}],`Filter fields ${e.target}`)}(this._ctx,t)}renameFields(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);if(!e.mapping||"object"!=typeof e.mapping)return pt.validation("mapping","must be an object of { oldName: newName }");const n=Object.entries(e.mapping);if(0===n.length)return pt.validation("mapping","must contain at least one rename pair");const r=[];for(const[t,e]of n){const i=(t??"").trim(),s=(e??"").trim();if(0===i.length||0===s.length)return pt.validation("mapping",`field names must be non-empty: ${t}=${e}`);if(i.includes(",")||i.includes("=")||s.includes(",")||s.includes("="))return pt.validation("mapping",`field names must not contain ',' or '=': ${t}=${e}`);r.push(`${i}=${s}`)}return t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"rename-fields",options:{fields:r}}],`Rename fields ${e.target}`)}(this._ctx,t)}joinTable(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);if(!Array.isArray(e.keys)||2!==e.keys.length)return pt.validation("keys","must be a 2-element [targetKey, sourceKey] array");const[n,r]=e.keys.map(t=>"string"==typeof t?t.trim():"");if(0===n.length||0===r.length)return pt.validation("keys","both keys must be non-empty strings");if(n.includes(",")||r.includes(","))return pt.validation("keys","keys must not contain `,`");let a,o;const h=e.data;if(!h||"object"!=typeof h)return pt.validation("data","must be { csv } | { json } | { layer }");if("layer"in h&&"string"==typeof h.layer&&h.layer.trim().length>0)a=h.layer.trim();else if("csv"in h&&("string"==typeof h.csv||h.csv instanceof Uint8Array)){const t=".emap-join.csv";a=t,o={[t]:h.csv}}else{if(!("json"in h)||void 0===h.json)return pt.validation("data","must contain one of `csv`, `json`, or `layer`");{const t=".emap-join.json";let e;e="string"==typeof h.json||h.json instanceof Uint8Array?h.json:JSON.stringify(h.json),a=t,o={[t]:e}}}if(!t.host._allowExpressionEvaluation([e.where,e.calc],"joinTable"))return pt.expressionDisabled("joinTable");const l={source:a,keys:[n,r]};if(e.fields&&e.fields.length>0){const t=e.fields.filter(t=>"string"==typeof t&&!t.includes(","));t.length>0&&(l.fields=t)}return e.prefix&&e.prefix.length>0&&(l.prefix=e.prefix),e.where&&e.where.trim().length>0&&(l.where=e.where),e.calc&&e.calc.trim().length>0&&(l.calc=e.calc),e.unjoined&&(l.unjoined=!0),e.unmatched&&(l.unmatched=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"join",options:l}],`Join ${e.target}`,o)}(this._ctx,t)}dataFill(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!At(s.layers,e.target))return pt.notFound("layer",e.target);if("string"!=typeof e.field||0===e.field.trim().length)return pt.validation("field","must be a non-empty string");if(e.field.includes(",")||e.field.includes("="))return pt.validation("field","must not contain `,` or `=`");if(void 0!==e.weightField){if("string"!=typeof e.weightField||0===e.weightField.trim().length)return pt.validation("weightField","must be a non-empty string when supplied");if(e.weightField.includes(",")||e.weightField.includes("="))return pt.validation("weightField","must not contain `,` or `=`")}const n={field:e.field};return e.weightField&&(n.weight_field=e.weightField),e.contiguous&&(n.contiguous=!0),t.runDatasetCommandParsed(e.source,[{name:"target",options:{target:e.target}},{name:"data-fill",options:n}],`Data fill ${e.target}.${e.field}`)}(this._ctx,t)}rebuildTopology(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(!s.arcs)return ct;const n=tt(),r=n.copyDataset(s),a=n.copyDataset(s);try{n.addIntersectionCuts(a,{snap_interval:e.snapInterval,no_snap:e.noSnap,rebuild_topology:e.rebuildTopology})}catch(e){return t.host.fire("error",{error:e}),pt.mapshaper(e,{operation:"rebuildTopology"})}return t.applyDatasetReplace(e.source,r,a,"Rebuild topology")}(this._ctx,t)}checkGeometry(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);if(void 0!==e.target&&!At(s.layers,e.target))return pt.notFound("layer",e.target);if(!s.arcs)return ut({ok:!0,intersections:[],intersectionCount:0});const n={};void 0!==e.tolerance&&(n.tolerance=e.tolerance);const r=tt().findSegmentIntersections(s.arcs,n).map(t=>({x:t.x,y:t.y}));return ut({ok:0===r.length,intersections:r,intersectionCount:r.length})}(this._ctx,t)}intersectionPointsLayer(t){return async function(t,e){const i=t.host._sources.get(e.source);if(!i)return pt.notFound("source",e.source);const s=i.getDataset();if(!s)return pt.notFound("source",e.source);const n=At(s.layers,e.target);if(!n)return pt.notFound("layer",e.target);if("polygon"!==n.geometry_type&&"polyline"!==n.geometry_type)return pt.validation("target",`expected polygon/polyline target, got ${n.geometry_type??"unknown"}`);if(!s.arcs)return pt.validation("source","source has no arcs");const r=e.name&&e.name.trim()||`${e.target}-intersections`;if(s.layers.some(t=>t?.name===r))return pt.validation("name",`another layer already named '${r}'`);if(void 0!==e.tolerance&&("number"!=typeof e.tolerance||!Number.isFinite(e.tolerance)||e.tolerance<=0))return pt.validation("tolerance","must be a positive finite number");const a={};void 0!==e.tolerance&&(a.tolerance=e.tolerance);const o=tt(),h=o.copyDataset(s),l=o.copyDataset(s);let c;try{const t=o.findSegmentIntersections(l.arcs,a),i=At(l.layers,e.target);if(!i)throw new Error("intersectionPointsLayer: target lost in copyDataset");c=o.getIntersectionLayer(t,i,l.arcs),c.name=r,l.layers.push(c)}catch(e){return t.host.fire("error",{error:e}),pt.mapshaper(e,{operation:"intersectionPointsLayer"})}return t.applyDatasetReplace(e.source,h,l,`Intersection points ${e.target}`)}(this._ctx,t)}mergeSelected(){return It(this._ctx)}}class Rt{children;label;constructor(t,e){this.children=t,this.label=e}do(){for(const t of this.children)t.do()}undo(){for(let t=this.children.length-1;t>=0;t--)this.children[t].undo()}}function Ot(t){return"polygon"===t.geometry_type||"polyline"===t.geometry_type}function Gt(t){return"point"===t.geometry_type}function zt(t){t&&(t.editVersion=(t.editVersion??0)+1)}class qt{opts;label;_mergeAt=Date.now();constructor(t){this.opts=t;const e=t.arcIds.length+t.pointFeatures.length;this.label=`Translate ${e} feature${1===e?"":"s"}`}do(){this._apply(this.opts.dx,this.opts.dy)}undo(){this._apply(-this.opts.dx,-this.opts.dy)}mergeable(t){if(!(t instanceof qt))return!1;if(t.opts.source!==this.opts.source)return!1;if(Date.now()-t._mergeAt>500)return!1;const e=t.opts.arcIds,i=this.opts.arcIds;if(e.length!==i.length)return!1;for(let t=0;t<e.length;t++)if(e[t]!==i[t])return!1;const s=t.opts.pointFeatures,n=this.opts.pointFeatures;if(s.length!==n.length)return!1;for(let t=0;t<s.length;t++){if(s[t].featureId!==n[t].featureId)return!1;if(s[t].layer!==n[t].layer)return!1}return!0}merge(t){t instanceof qt&&(this.opts.dx+=t.opts.dx,this.opts.dy+=t.opts.dy,this._mergeAt=Date.now())}_apply(t,e){const{arcs:i,arcIds:s,pointFeatures:n,source:r}=this.opts;if(i&&s.length>0){const n=i.getVertexData?.();if(n){const{xx:r,yy:a,ii:o,nn:h}=n;for(const n of s){const s=o[n],l=h[n];for(let i=s;i<s+l;i++)r[i]+=t,a[i]+=e;i.updateArcBounds?.(n)}}}for(const i of n){const s=i.layer.shapes?.[i.featureId];if(s)for(const i of at(s))i&&i.length>=2&&(i[0]+=t,i[1]+=e)}r.markDisplayArcsDirty?.(),zt(r.getDataset?.())}}class jt{opts;label;constructor(t){this.opts=t;const e=t.arcIds.length+t.pointFeatures.length;this.label=t.label??`Transform ${e} feature${1===e?"":"s"}`}do(){this._apply(this.opts.matrix)}undo(){this._apply(Wt(this.opts.matrix))}_apply(t){const{arcs:e,arcIds:i,pointFeatures:s,source:n}=this.opts;if(e&&i.length>0){const s=e.getVertexData?.();if(s){const{xx:n,yy:r,ii:a,nn:o}=s;for(const s of i){const i=a[s],h=o[s];for(let e=i;e<i+h;e++){const i=n[e],s=r[e];n[e]=t.a*i+t.c*s+t.tx,r[e]=t.b*i+t.d*s+t.ty}e.updateArcBounds?.(s)}}}for(const e of s){const i=e.layer.shapes?.[e.featureId];if(i)for(const e of at(i))if(e&&e.length>=2){const i=e[0],s=e[1];e[0]=t.a*i+t.c*s+t.tx,e[1]=t.b*i+t.d*s+t.ty}}n.markDisplayArcsDirty?.(),zt(n.getDataset?.())}}function Bt(t,e=0,i=0){const s=Math.cos(t),n=Math.sin(t);return{a:s,b:n,c:-n,d:s,tx:e-s*e+n*i,ty:i-n*e-s*i}}function Ut(t,e,i=0,s=0){return{a:t,b:0,c:0,d:e,tx:i-t*i,ty:s-e*s}}function $t(t,e){return{a:t.a*e.a+t.c*e.b,b:t.b*e.a+t.d*e.b,c:t.a*e.c+t.c*e.d,d:t.b*e.c+t.d*e.d,tx:t.a*e.tx+t.c*e.ty+t.tx,ty:t.b*e.tx+t.d*e.ty+t.ty}}const Vt={a:1,b:0,c:0,d:1,tx:0,ty:0};function Wt(t){const e=t.a*t.d-t.b*t.c;if(0===e)throw new Error("FeatureAffineCommand: matrix is singular (det=0)");const i=t.d/e,s=-t.b/e,n=-t.c/e,r=t.a/e;return{a:i,b:s,c:n,d:r,tx:-(i*t.tx+n*t.ty),ty:-(s*t.tx+r*t.ty)}}class Ht{opts;label;constructor(t){this.opts=t,this.label=`Split ${t.appendedArcs.length} shared arc${1===t.appendedArcs.length?"":"s"}`}do(){const t=this.opts.source.getArcs();if(t){!function(t,e){const i=t.getVertexData?.();if(!i)return;const{xx:s,yy:n,zz:r,nn:a}=i,o=!!r&&e.every(t=>t.zz);let h=0;for(const t of e)h+=t.xx.length;const l=new Float64Array(s.length+h),c=new Float64Array(n.length+h),u=o?new Float64Array(r.length+h):null;l.set(s),c.set(n),u&&r&&u.set(r);let p=s.length;for(const t of e)l.set(t.xx,p),c.set(t.yy,p),u&&t.zz&&u.set(t.zz,p),p+=t.xx.length;const _=new Int32Array(a.length+e.length);_.set(a);for(let t=0;t<e.length;t++)_[a.length+t]=e[t].xx.length;t.updateVertexData(_,l,c,u)}(t,this.opts.appendedArcs);for(const t of this.opts.remaps)t.layer.shapes[t.featureId]=Xt(t.newShape);this.opts.source.markDisplayArcsDirty?.(),zt(this.opts.source.getDataset?.())}}undo(){const t=this.opts.source.getArcs();if(t){!function(t,e){const i=t.getVertexData?.();if(!i)return;const{xx:s,yy:n,zz:r,nn:a}=i;if(a.length===e)return;if(e>a.length)return;let o=0;for(let t=0;t<e;t++)o+=a[t];const h=new Int32Array(e);h.set(a.subarray(0,e));const l=new Float64Array(s.subarray(0,o)),c=new Float64Array(n.subarray(0,o)),u=r?new Float64Array(r.subarray(0,o)):null;t.updateVertexData(h,l,c,u)}(t,this.opts.originalArcCount);for(const t of this.opts.remaps)t.layer.shapes[t.featureId]=Xt(t.originalShape);this.opts.source.markDisplayArcsDirty?.(),zt(this.opts.source.getDataset?.())}}}function Kt(t,e,i){const s=t.getArcs();if(!s)return null;const n=s.size();if(0===n||0===e.length)return null;const r=new Uint32Array(n),a=new Uint32Array(n),o=new Set;for(const t of e)o.add(Zt(t.layer,t.featureId));for(const t of i){if(!t.shapes)continue;if(!Ot(t))continue;const e=t.shapes;for(let i=0;i<e.length;i++){const s=e[i];if(!s)continue;const h=o.has(Zt(t,i));for(const t of s)if(Array.isArray(t))for(const e of t){if("number"!=typeof e)continue;const t=e>=0?e:~e;t<0||t>=n||(h?r[t]++:a[t]++)}}}const h=[];for(let t=0;t<n;t++)r[t]>0&&a[t]>0&&h.push(t);if(0===h.length)return null;const l=new globalThis.Map;for(let t=0;t<h.length;t++)l.set(h[t],n+t);const c=s.getVertexData?.();if(!c)return null;const{xx:u,yy:p,zz:_,ii:d,nn:f}=c,m=h.map(t=>{const e=d[t],i=f[t];return{xx:new Float64Array(u.subarray(e,e+i)),yy:new Float64Array(p.subarray(e,e+i)),zz:_?new Float64Array(_.subarray(e,e+i)):null}}),y=[];for(const t of e){if(!Ot(t.layer))continue;const e=t.layer.shapes?.[t.featureId];if(!e)continue;let i=!1;const s=e.map(t=>t.map(t=>{const e=t>=0?t:~t,s=l.get(e);return void 0===s?t:(i=!0,t>=0?s:~s)}));i&&y.push({layer:t.layer,featureId:t.featureId,originalShape:Xt(e),newShape:s})}return 0===y.length?null:{source:t,remaps:y,appendedArcs:m,originalArcCount:n}}function Zt(t,e){return`${t.name??""}#${e}`}function Xt(t){return t.map(t=>t.slice())}class Jt{_emap;constructor(t){this._emap=t}translateSelected(t,e){if(0===t&&0===e)return pt.validation("offset","dx and dy are both 0 (no-op)");const i=this._emap._selection.getAll();if(0===i.length)return pt.validation("selection","selection is empty");const s=new globalThis.Map;for(const t of i){const e=this._emap.layers.resolve(t.source,t.layer);if(!e?.shapes)continue;const i=e.shapes[t.id];if(!i)continue;let n=s.get(t.source);if(n||(n={arcIdSet:new Set,pointFeatures:[]},s.set(t.source,n)),"point"===e.geometry_type)n.pointFeatures.push({layer:e,featureId:t.id});else{const t=i;for(const e of t)if(Array.isArray(e))for(const t of e)"number"==typeof t&&n.arcIdSet.add(t>=0?t:~t)}}if(0===s.size)return pt.validation("selection","no resolvable layers in selection");const n=[],r=[];for(const[i,a]of s){const s=this._emap._sources.get(i);if(!s)continue;if(0===a.arcIdSet.size&&0===a.pointFeatures.length)continue;const o=new qt({source:s,arcs:s.getArcs(),dx:t,dy:e,arcIds:Array.from(a.arcIdSet),pointFeatures:a.pointFeatures});o.do(),n.push(o),r.push(i)}if(0===n.length)return pt.validation("selection","every resolved layer was empty");const a=1===n.length?n[0]:new Rt(n,`Translate ${i.length} features`);return this._emap._history.push(a),this._emap._fireHistoryChange(),this._emap._clearSpatialIndexesForSources(r),this._emap._scheduleRender(),ct}_buildSelectionBuckets(t){const e=this._emap._selection.getAll();if(0===e.length)return null;const i=new globalThis.Map;for(const t of e){const e=this._emap.layers.resolve(t.source,t.layer);if(!e?.shapes)continue;if(!e.shapes[t.id])continue;const s=this._emap._sources.get(t.source);if(!s)continue;let n=i.get(t.source);n||(n={sourceId:t.source,source:s,arcIds:[],pointFeatures:[],pathFeatures:[]},i.set(t.source,n)),"point"===e.geometry_type?n.pointFeatures.push({layer:e,featureId:t.id}):n.pathFeatures.push({layer:e,featureId:t.id})}if(0===i.size)return null;const s=[];if(t)for(const t of i.values()){if(0===t.pathFeatures.length)continue;const e=Kt(t.source,t.pathFeatures,t.source.getLayers());if(!e)continue;const i=new Ht(e);i.do(),s.push(i),this._emap._invalidateShapeCachesForSources([t.sourceId])}for(const t of i.values()){const e=new Set;for(const i of t.pathFeatures){const s=i.layer.shapes?.[i.featureId];if(s)for(const i of s)if(Array.isArray(i))for(const s of i){if("number"!=typeof s)continue;const i=s>=0?s:~s;e.has(i)||(e.add(i),t.arcIds.push(i))}}}return{buckets:Array.from(i.values()).map(t=>({sourceId:t.sourceId,source:t.source,arcIds:t.arcIds,pointFeatures:t.pointFeatures})),splitCmds:s}}beginTranslateSession(t){const e=this._buildSelectionBuckets(!1!==t?.splitSharedArcs);if(!e)return null;const{buckets:i,splitCmds:s}=e;let n=0,r=0,a=!1;const o=(t,e)=>{for(const s of i)0===s.arcIds.length&&0===s.pointFeatures.length||new qt({source:s.source,arcs:s.source.getArcs(),dx:t,dy:e,arcIds:s.arcIds,pointFeatures:s.pointFeatures}).do()};return{move:(t,e)=>{a||0===t&&0===e||(o(t,e),n+=t,r+=e,this._emap._scheduleRender())},commit:()=>{if(a)return!1;a=!0;if(!!(0===n&&0===r)){for(let t=s.length-1;t>=0;t--)s[t].undo();return s.length>0&&this._emap._scheduleRender(),!1}const t=i.map(t=>new qt({source:t.source,arcs:t.source.getArcs(),dx:n,dy:r,arcIds:t.arcIds,pointFeatures:t.pointFeatures})),e=i.reduce((t,e)=>t+e.arcIds.length+e.pointFeatures.length,0),o=[...s,...t],h=1===o.length?o[0]:new Rt(o,`Translate ${e} features`);return this._emap._history.push(h),this._emap._fireHistoryChange(),this._emap._invalidateShapeCachesForSources(i.map(t=>t.sourceId)),this._emap._scheduleRender(),!0},cancel:()=>{if(!a){a=!0,0===n&&0===r||o(-n,-r);for(let t=s.length-1;t>=0;t--)s[t].undo();n=0,r=0,s.length>0&&this._emap._invalidateShapeCachesForSources(i.map(t=>t.sourceId)),this._emap._scheduleRender()}},getAccumulated:()=>[n,r]}}beginAffineSession(t,e){const i=this._buildSelectionBuckets(!1!==e?.splitSharedArcs);if(!i)return null;const{buckets:s,splitCmds:n}=i;let r,a;if(t)[r,a]=t;else{const t=new globalThis.Map;for(const e of s)t.set(e.sourceId,{arcIdSet:new Set(e.arcIds),pointFeatures:e.pointFeatures});const e=this._computeSelectionCentroid(t);if(!e){for(let t=n.length-1;t>=0;t--)n[t].undo();return null}[r,a]=e}if(!Number.isFinite(r)||!Number.isFinite(a)){for(let t=n.length-1;t>=0;t--)n[t].undo();return null}const o=[r,a];let h={...Vt},l=!1;const c=t=>1===t.a&&0===t.b&&0===t.c&&1===t.d&&0===t.tx&&0===t.ty,u=t=>{for(const e of s)0===e.arcIds.length&&0===e.pointFeatures.length||new jt({source:e.source,arcs:e.source.getArcs(),matrix:t,arcIds:e.arcIds,pointFeatures:e.pointFeatures}).do()};return{origin:o,applyDelta:t=>{l||c(t)||(u(t),h=$t(t,h),this._emap._scheduleRender())},commit:t=>{if(l)return!1;if(l=!0,c(h)){for(let t=n.length-1;t>=0;t--)n[t].undo();return n.length>0&&this._emap._scheduleRender(),!1}const e=s.reduce((t,e)=>t+e.arcIds.length+e.pointFeatures.length,0),i=s.map(e=>new jt({source:e.source,arcs:e.source.getArcs(),matrix:h,arcIds:e.arcIds,pointFeatures:e.pointFeatures,label:t})),r=[...n,...i],a=1===r.length?r[0]:new Rt(r,t??`Transform ${e} feature${1===e?"":"s"}`);return this._emap._history.push(a),this._emap._fireHistoryChange(),this._emap._invalidateShapeCachesForSources(s.map(t=>t.sourceId)),this._emap._scheduleRender(),!0},cancel:()=>{if(!l){l=!0,c(h)||u(Wt(h));for(let t=n.length-1;t>=0;t--)n[t].undo();h={...Vt},n.length>0&&this._emap._invalidateShapeCachesForSources(s.map(t=>t.sourceId)),this._emap._scheduleRender()}},getCumulative:()=>({...h})}}rotateSelected(t,e){if(0===t)return pt.validation("angleDegrees","angle is 0 (no-op)");const i=t*Math.PI/180;return this._applyAffineToSelection((t,e)=>Bt(i,t,e),e,t=>`Rotate ${t} feature${1===t?"":"s"}`)}scaleSelected(t,e,i){const s=t,n=e??t;return 1===s&&1===n?pt.validation("scale","sx and sy are both 1 (no-op)"):this._applyAffineToSelection((t,e)=>Ut(s,n,t,e),i,t=>`Scale ${t} feature${1===t?"":"s"}`)}_applyAffineToSelection(t,e,i){const s=this._emap._selection.getAll();if(0===s.length)return pt.validation("selection","selection is empty");const n=new globalThis.Map;for(const t of s){const e=this._emap.layers.resolve(t.source,t.layer);if(!e?.shapes)continue;const i=e.shapes[t.id];if(!i)continue;let s=n.get(t.source);if(s||(s={arcIdSet:new Set,pointFeatures:[]},n.set(t.source,s)),"point"===e.geometry_type)s.pointFeatures.push({layer:e,featureId:t.id});else{const t=i;for(const e of t)if(Array.isArray(e))for(const t of e)"number"==typeof t&&s.arcIdSet.add(t>=0?t:~t)}}if(0===n.size)return pt.validation("selection","no resolvable layers in selection");let r,a;if(e)r=e[0],a=e[1];else{const t=this._computeSelectionCentroid(n);if(!t)return pt.validation("origin","no vertices in selection; cannot compute centroid");[r,a]=t}if(!Number.isFinite(r)||!Number.isFinite(a))return pt.validation("origin","computed origin is not finite");const o=t(r,a),h=[],l=[];for(const[t,e]of n){const i=this._emap._sources.get(t);if(!i)continue;if(0===e.arcIdSet.size&&0===e.pointFeatures.length)continue;const s=new jt({source:i,arcs:i.getArcs(),matrix:o,arcIds:Array.from(e.arcIdSet),pointFeatures:e.pointFeatures});s.do(),h.push(s),l.push(t)}if(0===h.length)return pt.validation("selection","every resolved layer was empty");const c=1===h.length?h[0]:new Rt(h,i(s.length));return this._emap._history.push(c),this._emap._fireHistoryChange(),this._emap._clearSpatialIndexesForSources(l),this._emap._scheduleRender(),ct}_computeSelectionCentroid(t){let e=1/0,i=1/0,s=-1/0,n=-1/0,r=!1;for(const[a,o]of t){const t=this._emap._sources.get(a);if(!t)continue;const h=t.getArcs(),l=h?.getVertexData?.();if(l&&o.arcIdSet.size>0){const{xx:t,yy:a,ii:h,nn:c}=l;for(const l of o.arcIdSet){const o=h[l],u=c[l];for(let h=o;h<o+u;h++){const o=t[h],l=a[h];o<e&&(e=o),o>s&&(s=o),l<i&&(i=l),l>n&&(n=l),r=!0}}}for(const t of o.pointFeatures){const a=t.layer.shapes?.[t.featureId];if(a)for(const t of at(a)){if(!t||t.length<2)continue;const a=t[0],o=t[1];a<e&&(e=a),a>s&&(s=a),o<i&&(i=o),o>n&&(n=o),r=!0}}}return r?[(e+s)/2,(i+n)/2]:null}}class Yt{opts;label;constructor(t){this.opts=t,this.label=t.label??"Edit properties"}do(){Qt(this.opts.layer,this.opts.featureId,this.opts.prev,this.opts.next)}undo(){Qt(this.opts.layer,this.opts.featureId,this.opts.next,this.opts.prev)}}function Qt(t,e,i,s){const n=t.data?.getRecords?.(),r=n?.[e];if(r){for(const t of Object.keys(s))r[t]=s[t];for(const t of Object.keys(i))t in s||delete r[t]}}class te{opts;label;_addedIndices=[];constructor(t){this.opts=t,this.label=`Add field ${t.field}`}do(){const t=this.opts.layer.data?.getRecords?.();if(!t)return;const e=this.opts.defaultValue??null;this._addedIndices=[];for(let i=0;i<t.length;i++)t[i]&&!(this.opts.field in t[i])&&(t[i][this.opts.field]=e,this._addedIndices.push(i))}undo(){const t=this.opts.layer.data?.getRecords?.();if(t){for(const e of this._addedIndices)delete t[e]?.[this.opts.field];this._addedIndices=[]}}}class ee{opts;label;_snapshot=new globalThis.Map;constructor(t){this.opts=t,this.label=`Remove field ${t.field}`}do(){const t=this.opts.layer.data?.getRecords?.();if(t){this._snapshot.clear();for(let e=0;e<t.length;e++){const i=t[e];i&&this.opts.field in i&&(this._snapshot.set(e,i[this.opts.field]),delete i[this.opts.field])}}}undo(){const t=this.opts.layer.data?.getRecords?.();if(t)for(const[e,i]of this._snapshot){const s=t[e];s&&(s[this.opts.field]=i)}}}class ie{opts;label;constructor(t){this.opts=t,this.label=`Rename field ${t.from} → ${t.to}`}do(){se(this.opts.layer,this.opts.from,this.opts.to)}undo(){se(this.opts.layer,this.opts.to,this.opts.from)}}function se(t,e,i){const s=t.data?.getRecords?.();if(s)for(const t of s)t&&e in t&&(t[i]=t[e],delete t[e])}class ne{_emap;constructor(t){this._emap=t}setFeatureProperty(t,e,i){return this.setFeatureProperties(t,{[e]:i})}setFeatureProperties(t,e){const i=this._emap.layers.resolve(t.source,t.layer);if(!i)return pt.notFound("layer",t.layer);const s=i.data?.getRecords?.(),n=s?.[t.id];if(!n)return pt.notFound("field",`record#${t.id}`);const r={},a={};for(const t of Object.keys(e)){const i=t in n,s=i?n[t]:void 0,o=e[t];(void 0!==o||i)&&(void 0!==o&&i&&n[t]===o||(i&&(r[t]=s),void 0!==o&&(a[t]=o)))}if(0===Object.keys(r).length&&0===Object.keys(a).length)return pt.validation("props","no-op: every requested value already matches the record");const o=new Yt({layer:i,featureId:t.id,prev:r,next:a});return o.do(),this._emap._history.push(o),this._emap._fireHistoryChange(),this._emap._scheduleRender(),ct}addField(t){const e=this._emap.layers.resolve(t.source,t.target);if(!e)return pt.notFound("layer",t.target);if(!e.data)return pt.validation("target","layer has no data table");const i=new te({layer:e,field:t.field,defaultValue:t.defaultValue});return i.do(),this._emap._history.push(i),this._emap._fireHistoryChange(),this._emap._scheduleRender(),ct}removeField(t){const e=this._emap.layers.resolve(t.source,t.target);if(!e)return pt.notFound("layer",t.target);if(!e.data)return pt.validation("target","layer has no data table");const i=new ee({layer:e,field:t.field});return i.do(),this._emap._history.push(i),this._emap._fireHistoryChange(),this._emap._scheduleRender(),ct}renameField(t){const e=this._emap.layers.resolve(t.source,t.target);if(!e)return pt.notFound("layer",t.target);if(!e.data)return pt.validation("target","layer has no data table");const i=e.data.getRecords?.();if(!i)return pt.validation("target","data table has no records");if(t.from===t.to)return pt.validation("to","`from` and `to` are identical");for(const e of i)if(e&&t.from in e&&t.to in e)return pt.validation("to",`would overwrite existing '${t.to}' on at least one record`);const s=new ie({layer:e,from:t.from,to:t.to});return s.do(),this._emap._history.push(s),this._emap._fireHistoryChange(),this._emap._scheduleRender(),ct}}class re{_onChange;_mode="none";_vertex=null;_draw=null;constructor(t){this._onChange=t}get mode(){return this._mode}get vertex(){return this._vertex}get draw(){return this._draw}setMode(t){if(t===this._mode)return;const e=this._mode;this._mode=t,"vertex"!==t&&(this._vertex=null),"draw"!==t&&(this._draw=null),this._fire(e)}setVertex(t){this._vertex!==t&&(this._vertex=t,this._fire(this._mode))}clearVertex(){null!==this._vertex&&(this._vertex=null,this._fire(this._mode))}setDraw(t){this._draw!==t&&(this._draw=t,this._fire(this._mode))}clearDraw(){null!==this._draw&&(this._draw=null,this._fire(this._mode))}_fire(t){this._onChange({current:{mode:this._mode,vertex:this._vertex,draw:this._draw},previousMode:t,modeChanged:t!==this._mode})}}var ae={},oe=Uint8Array,he=Uint16Array,le=Int32Array,ce=new oe([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),ue=new oe([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),pe=new oe([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),_e=function(t,e){for(var i=new he(31),s=0;s<31;++s)i[s]=e+=1<<t[s-1];var n=new le(i[30]);for(s=1;s<30;++s)for(var r=i[s];r<i[s+1];++r)n[r]=r-i[s]<<5|s;return{b:i,r:n}},de=_e(ce,2),fe=de.b,me=de.r;fe[28]=258,me[258]=28;for(var ye=_e(ue,0),ge=ye.b,ve=ye.r,xe=new he(32768),be=0;be<32768;++be){var we=(43690&be)>>1|(21845&be)<<1;we=(61680&(we=(52428&we)>>2|(13107&we)<<2))>>4|(3855&we)<<4,xe[be]=((65280&we)>>8|(255&we)<<8)>>1}var Se=function(t,e,i){for(var s=t.length,n=0,r=new he(e);n<s;++n)t[n]&&++r[t[n]-1];var a,o=new he(e);for(n=1;n<e;++n)o[n]=o[n-1]+r[n-1]<<1;if(i){a=new he(1<<e);var h=15-e;for(n=0;n<s;++n)if(t[n])for(var l=n<<4|t[n],c=e-t[n],u=o[t[n]-1]++<<c,p=u|(1<<c)-1;u<=p;++u)a[xe[u]>>h]=l}else for(a=new he(s),n=0;n<s;++n)t[n]&&(a[n]=xe[o[t[n]-1]++]>>15-t[n]);return a},Ce=new oe(288);for(be=0;be<144;++be)Ce[be]=8;for(be=144;be<256;++be)Ce[be]=9;for(be=256;be<280;++be)Ce[be]=7;for(be=280;be<288;++be)Ce[be]=8;var Ae=new oe(32);for(be=0;be<32;++be)Ae[be]=5;var Ee=Se(Ce,9,0),Me=Se(Ce,9,1),ke=Se(Ae,5,0),Ie=Se(Ae,5,1),De=function(t){for(var e=t[0],i=1;i<t.length;++i)t[i]>e&&(e=t[i]);return e},Pe=function(t,e,i){var s=e/8|0;return(t[s]|t[s+1]<<8)>>(7&e)&i},Te=function(t,e){var i=e/8|0;return(t[i]|t[i+1]<<8|t[i+2]<<16)>>(7&e)},Le=function(t){return(t+7)/8|0},Fe=function(t,e,i){return(null==e||e<0)&&(e=0),(null==i||i>t.length)&&(i=t.length),new oe(t.subarray(e,i))},Ne=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],Re=function(t,e,i){var s=new Error(e||Ne[t]);if(s.code=t,Error.captureStackTrace&&Error.captureStackTrace(s,Re),!i)throw s;return s},Oe=function(t,e,i,s){var n=t.length,r=s?s.length:0;if(!n||e.f&&!e.l)return i||new oe(0);var a=!i,o=a||2!=e.i,h=e.i;a&&(i=new oe(3*n));var l=function(t){var e=i.length;if(t>e){var s=new oe(Math.max(2*e,t));s.set(i),i=s}},c=e.f||0,u=e.p||0,p=e.b||0,_=e.l,d=e.d,f=e.m,m=e.n,y=8*n;do{if(!_){c=Pe(t,u,1);var g=Pe(t,u+1,3);if(u+=3,!g){var v=t[(D=Le(u)+4)-4]|t[D-3]<<8,x=D+v;if(x>n){h&&Re(0);break}o&&l(p+v),i.set(t.subarray(D,x),p),e.b=p+=v,e.p=u=8*x,e.f=c;continue}if(1==g)_=Me,d=Ie,f=9,m=5;else if(2==g){var b=Pe(t,u,31)+257,w=Pe(t,u+10,15)+4,S=b+Pe(t,u+5,31)+1;u+=14;for(var C=new oe(S),A=new oe(19),E=0;E<w;++E)A[pe[E]]=Pe(t,u+3*E,7);u+=3*w;var M=De(A),k=(1<<M)-1,I=Se(A,M,1);for(E=0;E<S;){var D,P=I[Pe(t,u,k)];if(u+=15&P,(D=P>>4)<16)C[E++]=D;else{var T=0,L=0;for(16==D?(L=3+Pe(t,u,3),u+=2,T=C[E-1]):17==D?(L=3+Pe(t,u,7),u+=3):18==D&&(L=11+Pe(t,u,127),u+=7);L--;)C[E++]=T}}var F=C.subarray(0,b),N=C.subarray(b);f=De(F),m=De(N),_=Se(F,f,1),d=Se(N,m,1)}else Re(1);if(u>y){h&&Re(0);break}}o&&l(p+131072);for(var R=(1<<f)-1,O=(1<<m)-1,G=u;;G=u){var z=(T=_[Te(t,u)&R])>>4;if((u+=15&T)>y){h&&Re(0);break}if(T||Re(2),z<256)i[p++]=z;else{if(256==z){G=u,_=null;break}var q=z-254;if(z>264){var j=ce[E=z-257];q=Pe(t,u,(1<<j)-1)+fe[E],u+=j}var B=d[Te(t,u)&O],U=B>>4;B||Re(3),u+=15&B;N=ge[U];if(U>3){j=ue[U];N+=Te(t,u)&(1<<j)-1,u+=j}if(u>y){h&&Re(0);break}o&&l(p+131072);var $=p+q;if(p<N){var V=r-N,W=Math.min(N,$);for(V+p<0&&Re(3);p<W;++p)i[p]=s[V+p]}for(;p<$;++p)i[p]=i[p-N]}}e.l=_,e.p=G,e.b=p,e.f=c,_&&(c=1,e.m=f,e.d=d,e.n=m)}while(!c);return p!=i.length&&a?Fe(i,0,p):i.subarray(0,p)},Ge=function(t,e,i){i<<=7&e;var s=e/8|0;t[s]|=i,t[s+1]|=i>>8},ze=function(t,e,i){i<<=7&e;var s=e/8|0;t[s]|=i,t[s+1]|=i>>8,t[s+2]|=i>>16},qe=function(t,e){for(var i=[],s=0;s<t.length;++s)t[s]&&i.push({s:s,f:t[s]});var n=i.length,r=i.slice();if(!n)return{t:He,l:0};if(1==n){var a=new oe(i[0].s+1);return a[i[0].s]=1,{t:a,l:1}}i.sort(function(t,e){return t.f-e.f}),i.push({s:-1,f:25001});var o=i[0],h=i[1],l=0,c=1,u=2;for(i[0]={s:-1,f:o.f+h.f,l:o,r:h};c!=n-1;)o=i[i[l].f<i[u].f?l++:u++],h=i[l!=c&&i[l].f<i[u].f?l++:u++],i[c++]={s:-1,f:o.f+h.f,l:o,r:h};var p=r[0].s;for(s=1;s<n;++s)r[s].s>p&&(p=r[s].s);var _=new he(p+1),d=je(i[c-1],_,0);if(d>e){s=0;var f=0,m=d-e,y=1<<m;for(r.sort(function(t,e){return _[e.s]-_[t.s]||t.f-e.f});s<n;++s){var g=r[s].s;if(!(_[g]>e))break;f+=y-(1<<d-_[g]),_[g]=e}for(f>>=m;f>0;){var v=r[s].s;_[v]<e?f-=1<<e-_[v]++-1:++s}for(;s>=0&&f;--s){var x=r[s].s;_[x]==e&&(--_[x],++f)}d=e}return{t:new oe(_),l:d}},je=function(t,e,i){return-1==t.s?Math.max(je(t.l,e,i+1),je(t.r,e,i+1)):e[t.s]=i},Be=function(t){for(var e=t.length;e&&!t[--e];);for(var i=new he(++e),s=0,n=t[0],r=1,a=function(t){i[s++]=t},o=1;o<=e;++o)if(t[o]==n&&o!=e)++r;else{if(!n&&r>2){for(;r>138;r-=138)a(32754);r>2&&(a(r>10?r-11<<5|28690:r-3<<5|12305),r=0)}else if(r>3){for(a(n),--r;r>6;r-=6)a(8304);r>2&&(a(r-3<<5|8208),r=0)}for(;r--;)a(n);r=1,n=t[o]}return{c:i.subarray(0,s),n:e}},Ue=function(t,e){for(var i=0,s=0;s<e.length;++s)i+=t[s]*e[s];return i},$e=function(t,e,i){var s=i.length,n=Le(e+2);t[n]=255&s,t[n+1]=s>>8,t[n+2]=255^t[n],t[n+3]=255^t[n+1];for(var r=0;r<s;++r)t[n+r+4]=i[r];return 8*(n+4+s)},Ve=function(t,e,i,s,n,r,a,o,h,l,c){Ge(e,c++,i),++n[256];for(var u=qe(n,15),p=u.t,_=u.l,d=qe(r,15),f=d.t,m=d.l,y=Be(p),g=y.c,v=y.n,x=Be(f),b=x.c,w=x.n,S=new he(19),C=0;C<g.length;++C)++S[31&g[C]];for(C=0;C<b.length;++C)++S[31&b[C]];for(var A=qe(S,7),E=A.t,M=A.l,k=19;k>4&&!E[pe[k-1]];--k);var I,D,P,T,L=l+5<<3,F=Ue(n,Ce)+Ue(r,Ae)+a,N=Ue(n,p)+Ue(r,f)+a+14+3*k+Ue(S,E)+2*S[16]+3*S[17]+7*S[18];if(h>=0&&L<=F&&L<=N)return $e(e,c,t.subarray(h,h+l));if(Ge(e,c,1+(N<F)),c+=2,N<F){I=Se(p,_,0),D=p,P=Se(f,m,0),T=f;var R=Se(E,M,0);Ge(e,c,v-257),Ge(e,c+5,w-1),Ge(e,c+10,k-4),c+=14;for(C=0;C<k;++C)Ge(e,c+3*C,E[pe[C]]);c+=3*k;for(var O=[g,b],G=0;G<2;++G){var z=O[G];for(C=0;C<z.length;++C){var q=31&z[C];Ge(e,c,R[q]),c+=E[q],q>15&&(Ge(e,c,z[C]>>5&127),c+=z[C]>>12)}}}else I=Ee,D=Ce,P=ke,T=Ae;for(C=0;C<o;++C){var j=s[C];if(j>255){ze(e,c,I[(q=j>>18&31)+257]),c+=D[q+257],q>7&&(Ge(e,c,j>>23&31),c+=ce[q]);var B=31&j;ze(e,c,P[B]),c+=T[B],B>3&&(ze(e,c,j>>5&8191),c+=ue[B])}else ze(e,c,I[j]),c+=D[j]}return ze(e,c,I[256]),c+D[256]},We=new le([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),He=new oe(0),Ke=function(){for(var t=new Int32Array(256),e=0;e<256;++e){for(var i=e,s=9;--s;)i=(1&i&&-306674912)^i>>>1;t[e]=i}return t}(),Ze=function(){var t=-1;return{p:function(e){for(var i=t,s=0;s<e.length;++s)i=Ke[255&i^e[s]]^i>>>8;t=i},d:function(){return~t}}},Xe=function(t,e,i,s,n){if(!n&&(n={l:1},e.dictionary)){var r=e.dictionary.subarray(-32768),a=new oe(r.length+t.length);a.set(r),a.set(t,r.length),t=a,n.w=r.length}return function(t,e,i,s,n,r){var a=r.z||t.length,o=new oe(s+a+5*(1+Math.ceil(a/7e3))+n),h=o.subarray(s,o.length-n),l=r.l,c=7&(r.r||0);if(e){c&&(h[0]=r.r>>3);for(var u=We[e-1],p=u>>13,_=8191&u,d=(1<<i)-1,f=r.p||new he(32768),m=r.h||new he(d+1),y=Math.ceil(i/3),g=2*y,v=function(e){return(t[e]^t[e+1]<<y^t[e+2]<<g)&d},x=new le(25e3),b=new he(288),w=new he(32),S=0,C=0,A=r.i||0,E=0,M=r.w||0,k=0;A+2<a;++A){var I=v(A),D=32767&A,P=m[I];if(f[D]=P,m[I]=D,M<=A){var T=a-A;if((S>7e3||E>24576)&&(T>423||!l)){c=Ve(t,h,0,x,b,w,C,E,k,A-k,c),E=S=C=0,k=A;for(var L=0;L<286;++L)b[L]=0;for(L=0;L<30;++L)w[L]=0}var F=2,N=0,R=_,O=D-P&32767;if(T>2&&I==v(A-O))for(var G=Math.min(p,T)-1,z=Math.min(32767,A),q=Math.min(258,T);O<=z&&--R&&D!=P;){if(t[A+F]==t[A+F-O]){for(var j=0;j<q&&t[A+j]==t[A+j-O];++j);if(j>F){if(F=j,N=O,j>G)break;var B=Math.min(O,j-2),U=0;for(L=0;L<B;++L){var $=A-O+L&32767,V=$-f[$]&32767;V>U&&(U=V,P=$)}}}O+=(D=P)-(P=f[D])&32767}if(N){x[E++]=268435456|me[F]<<18|ve[N];var W=31&me[F],H=31&ve[N];C+=ce[W]+ue[H],++b[257+W],++w[H],M=A+F,++S}else x[E++]=t[A],++b[t[A]]}}for(A=Math.max(A,M);A<a;++A)x[E++]=t[A],++b[t[A]];c=Ve(t,h,l,x,b,w,C,E,k,A-k,c),l||(r.r=7&c|h[c/8|0]<<3,c-=7,r.h=m,r.p=f,r.i=A,r.w=M)}else{for(A=r.w||0;A<a+l;A+=65535){var K=A+65535;K>=a&&(h[c/8|0]=l,K=a),c=$e(h,c+1,t.subarray(A,K))}r.i=a}return Fe(o,0,s+Le(c)+n)}(t,null==e.level?6:e.level,null==e.mem?n.l?Math.ceil(1.5*Math.max(8,Math.min(13,Math.log(t.length)))):20:12+e.mem,i,s,n)},Je=function(t,e){var i={};for(var s in t)i[s]=t[s];for(var s in e)i[s]=e[s];return i},Ye=function(t,e,i){for(var s=t(),n=t.toString(),r=n.slice(n.indexOf("[")+1,n.lastIndexOf("]")).replace(/\s+/g,"").split(","),a=0;a<s.length;++a){var o=s[a],h=r[a];if("function"==typeof o){e+=";"+h+"=";var l=o.toString();if(o.prototype)if(-1!=l.indexOf("[native code]")){var c=l.indexOf(" ",8)+1;e+=l.slice(c,l.indexOf("(",c))}else for(var u in e+=l,o.prototype)e+=";"+h+".prototype."+u+"="+o.prototype[u].toString();else e+=l}else i[h]=o}return e},Qe=[],ti=function(t,e,i,s){if(!Qe[i]){for(var n="",r={},a=t.length-1,o=0;o<a;++o)n=Ye(t[o],n,r);Qe[i]={c:Ye(t[a],n,r),e:r}}var h=Je({},Qe[i].e);return function(t,e,i,s,n){var r=new Worker(ae[e]||(ae[e]=URL.createObjectURL(new Blob([t+';addEventListener("error",function(e){e=e.error;postMessage({$e$:[e.message,e.code,e.stack]})})'],{type:"text/javascript"}))));return r.onmessage=function(t){var e=t.data,i=e.$e$;if(i){var s=new Error(i[0]);s.code=i[1],s.stack=i[2],n(s,null)}else n(null,e)},r.postMessage(i,s),r}(Qe[i].c+";onmessage=function(e){for(var k in e.data)self[k]=e.data[k];onmessage="+e.toString()+"}",i,h,function(t){var e=[];for(var i in t)t[i].buffer&&e.push((t[i]=new t[i].constructor(t[i])).buffer);return e}(h),s)},ei=function(){return[oe,he,le,ce,ue,pe,fe,ge,Me,Ie,xe,Ne,Se,De,Pe,Te,Le,Fe,Re,Oe,ci,ii,si]},ii=function(t){return postMessage(t,[t.buffer])},si=function(t){return t&&{out:t.size&&new oe(t.size),dictionary:t.dictionary}},ni=function(t,e){return t[e]|t[e+1]<<8},ri=function(t,e){return(t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24)>>>0},ai=function(t,e){return ri(t,e)+4294967296*ri(t,e+4)},oi=function(t,e,i){for(;i;++e)t[e]=i,i>>>=8};function hi(t,e){return Xe(t,e||{},0,0)}function li(t,e,i){return i||(i=e,e={}),"function"!=typeof i&&Re(7),function(t,e,i,s,n,r){var a=ti(i,s,n,function(t,e){a.terminate(),r(t,e)});return a.postMessage([t,e],e.consume?[t.buffer]:[]),function(){a.terminate()}}(t,e,[ei],function(t){return ii(ci(t.data[0],si(t.data[1])))},1,i)}function ci(t,e){return Oe(t,{i:2},e&&e.out,e&&e.dictionary)}var ui=function(t,e,i,s){for(var n in t){var r=t[n],a=e+n,o=s;Array.isArray(r)&&(o=Je(s,r[1]),r=r[0]),r instanceof oe?i[a]=[r,o]:(i[a+="/"]=[new oe(0),o],ui(r,a,i,s))}},pi="undefined"!=typeof TextEncoder&&new TextEncoder,_i="undefined"!=typeof TextDecoder&&new TextDecoder;try{_i.decode(He,{stream:!0})}catch(t){}function di(t,e){if(pi)return pi.encode(t);for(var i=t.length,s=new oe(t.length+(t.length>>1)),n=0,r=function(t){s[n++]=t},a=0;a<i;++a){if(n+5>s.length){var o=new oe(n+8+(i-a<<1));o.set(s),s=o}var h=t.charCodeAt(a);h<128||e?r(h):h<2048?(r(192|h>>6),r(128|63&h)):h>55295&&h<57344?(r(240|(h=65536+(1047552&h)|1023&t.charCodeAt(++a))>>18),r(128|h>>12&63),r(128|h>>6&63),r(128|63&h)):(r(224|h>>12),r(128|h>>6&63),r(128|63&h))}return Fe(s,0,n)}function fi(t,e){if(e){for(var i="",s=0;s<t.length;s+=16384)i+=String.fromCharCode.apply(null,t.subarray(s,s+16384));return i}if(_i)return _i.decode(t);var n=function(t){for(var e="",i=0;;){var s=t[i++],n=(s>127)+(s>223)+(s>239);if(i+n>t.length)return{s:e,r:Fe(t,i-1)};n?3==n?(s=((15&s)<<18|(63&t[i++])<<12|(63&t[i++])<<6|63&t[i++])-65536,e+=String.fromCharCode(55296|s>>10,56320|1023&s)):e+=1&n?String.fromCharCode((31&s)<<6|63&t[i++]):String.fromCharCode((15&s)<<12|(63&t[i++])<<6|63&t[i++]):e+=String.fromCharCode(s)}}(t),r=n.s;return(i=n.r).length&&Re(8),r}var mi=function(t,e){for(;1!=ni(t,e);e+=4+ni(t,e+2));return[ai(t,e+12),ai(t,e+4),ai(t,e+20)]},yi=function(t){var e=0;if(t)for(var i in t){var s=t[i].length;s>65535&&Re(9),e+=s+4}return e},gi=function(t,e,i,s,n,r,a,o){var h=s.length,l=i.extra,c=o&&o.length,u=yi(l);oi(t,e,null!=a?33639248:67324752),e+=4,null!=a&&(t[e++]=20,t[e++]=i.os),t[e]=20,e+=2,t[e++]=i.flag<<1|(r<0&&8),t[e++]=n&&8,t[e++]=255&i.compression,t[e++]=i.compression>>8;var p=new Date(null==i.mtime?Date.now():i.mtime),_=p.getFullYear()-1980;if((_<0||_>119)&&Re(10),oi(t,e,_<<25|p.getMonth()+1<<21|p.getDate()<<16|p.getHours()<<11|p.getMinutes()<<5|p.getSeconds()>>1),e+=4,-1!=r&&(oi(t,e,i.crc),oi(t,e+4,r<0?-r-2:r),oi(t,e+8,i.size)),oi(t,e+12,h),oi(t,e+14,u),e+=16,null!=a&&(oi(t,e,c),oi(t,e+6,i.attrs),oi(t,e+10,a),e+=14),t.set(s,e),e+=h,u)for(var d in l){var f=l[d],m=f.length;oi(t,e,+d),oi(t,e+2,m),t.set(f,e+4),e+=4+m}return c&&(t.set(o,e),e+=c),e};function vi(t,e){e||(e={});var i={},s=[];ui(t,"",i,e);var n=0,r=0;for(var a in i){var o=i[a],h=o[0],l=o[1],c=0==l.level?0:8,u=(S=di(a)).length,p=l.comment,_=p&&di(p),d=_&&_.length,f=yi(l.extra);u>65535&&Re(11);var m=c?hi(h,l):h,y=m.length,g=Ze();g.p(h),s.push(Je(l,{size:h.length,crc:g.d(),c:m,f:S,m:_,u:u!=a.length||_&&p.length!=d,o:n,compression:c})),n+=30+u+f+y,r+=76+2*(u+f)+(d||0)+y}for(var v=new oe(r+22),x=n,b=r-n,w=0;w<s.length;++w){var S=s[w];gi(v,S.o,S,S.f,S.u,S.c.length);var C=30+S.f.length+yi(S.extra);v.set(S.c,S.o+C),gi(v,n,S,S.f,S.u,S.c.length,S.o,S.m),n+=16+C+(S.m?S.m.length:0)}return function(t,e,i,s,n){oi(t,e,101010256),oi(t,e+8,i),oi(t,e+10,i),oi(t,e+12,s),oi(t,e+16,n)}(v,n,s.length,b,x),v}var xi="function"==typeof queueMicrotask?queueMicrotask:"function"==typeof setTimeout?setTimeout:function(t){t()};function bi(t,e,i){i||(i=e,e={}),"function"!=typeof i&&Re(7);var s=[],n=function(){for(var t=0;t<s.length;++t)s[t]()},r={},a=function(t,e){xi(function(){i(t,e)})};xi(function(){a=i});for(var o=t.length-22;101010256!=ri(t,o);--o)if(!o||t.length-o>65558)return a(Re(13,0,1),null),n;var h=ni(t,o+8);if(h){var l=h,c=ri(t,o+16),u=4294967295==c||65535==l;if(u){var p=ri(t,o-12);(u=101075792==ri(t,p))&&(l=h=ri(t,p+32),c=ri(t,p+48))}for(var _=e&&e.filter,d=function(e){var i=function(t,e,i){var s=ni(t,e+28),n=fi(t.subarray(e+46,e+46+s),!(2048&ni(t,e+8))),r=e+46+s,a=ri(t,e+20),o=i&&4294967295==a?mi(t,r):[a,ri(t,e+24),ri(t,e+42)],h=o[0],l=o[1],c=o[2];return[ni(t,e+10),h,l,n,r+ni(t,e+30)+ni(t,e+32),c]}(t,c,u),o=i[0],l=i[1],p=i[2],d=i[3],f=i[4],m=i[5],y=function(t,e){return e+30+ni(t,e+26)+ni(t,e+28)}(t,m);c=f;var g=function(t,e){t?(n(),a(t,null)):(e&&(r[d]=e),--h||a(null,r))};if(!_||_({name:d,size:l,originalSize:p,compression:o}))if(o)if(8==o){var v=t.subarray(y,y+l);if(p<524288||l>.8*p)try{g(null,ci(v,{out:new oe(p)}))}catch(t){g(t,null)}else s.push(li(v,{size:p},g))}else g(Re(14,"unknown compression type "+o,1),null);else g(null,Fe(t,y,y+l));else g(null,null)},f=0;f<l;++f)d()}else a(null,{});return n}const wi=5e5;class Si{_unfilteredArcs;_filteredArcs=null;_filteredSegLen=0;_dirty=!1;constructor(t){this._unfilteredArcs=t;(t.getPointCount?.()??0)>wi&&this._initFilteredArcs()}markDirty(){this._dirty=!0}_initFilteredArcs(){const t=this._unfilteredArcs,e=t.getVertexData?.();if(e?.zz){const e=.08,i=Math.ceil((t.getPointCount?.()??0)/wi),s=t.getRetainedInterval?.()??0,n=t.getThresholdByPct?.(e,i)??0;this._filteredArcs=t.setRetainedInterval?.(n)?.getFilteredCopy?.()??null,t.setRetainedInterval?.(s),this._filteredArcs&&(this._filteredSegLen=tt().getAvgSegment(this._filteredArcs))}else{const e=tt();this._filteredSegLen=4*e.getAvgSegment(t),this._filteredArcs=e.simplifyArcsFast(t,this._filteredSegLen)}}getScaledArcs(t){const e=null!==this._filteredArcs&&t>1.5*this._filteredSegLen;if(this._filteredArcs){(this._filteredArcs.size()!==this._unfilteredArcs.size()||this._dirty&&e)&&(this._initFilteredArcs(),this._dirty=!1)}else if(this._dirty){(this._unfilteredArcs.getPointCount?.()??0)>wi&&this._initFilteredArcs(),this._dirty=!1}this._filteredArcs&&this._filteredArcs.setRetainedInterval?.(this._unfilteredArcs.getRetainedInterval?.()??0);return this._filteredArcs&&t>1.5*this._filteredSegLen?this._filteredArcs:this._unfilteredArcs}getArcs(){return this._unfilteredArcs}hasLOD(){return null!==this._filteredArcs}}class Ci{_adapter;constructor(t=tt()){this._adapter=t}async runImport(t,e){return this._adapter.runImport(t,e)}}let Ai=null;const Ei="EPSG:4326";function Mi(t){if(!t)return Ei;const e=t.info;if(!e)return Ei;if(e.crs_string)return ki(e.crs_string);if(e.prj){const t=Ii(e.prj);if(t)return t}if(e.crs){if(e.crs.is_latlong)return"EPSG:4326";if("merc"===e.crs.projName&&6378137===e.crs.a)return"EPSG:3857"}return Ei}function ki(t){const e=t.toLowerCase();return"wgs84"===e||e.includes("4326")?"EPSG:4326":e.includes("3857")||"webmercator"===e?"EPSG:3857":(/^epsg:\d+$/i.test(t),t.toUpperCase())}function Ii(t){const e=t.match(/AUTHORITY\["EPSG"\s*,\s*"(\d+)"\]/i);return e?`EPSG:${e[1]}`:/Mercator.*WGS.*84.*Pseudo/i.test(t)||/WGS.*84.*Pseudo.*Mercator/i.test(t)||/Web_Mercator/i.test(t)?"EPSG:3857":/DATUM\["WGS_1984"/i.test(t)&&/GEOGCS/i.test(t)?"EPSG:4326":null}const Di={geojson:"application/geo+json",topojson:"application/json",shapefile:"application/zip",msx:"application/octet-stream"};function Pi(t){return"string"==typeof t?(new TextEncoder).encode(t):t instanceof Uint8Array?t:new Uint8Array(t)}const Ti={maxBytes:209715200,maxEntries:5e3,maxRatio:100};class Li extends U{id;type="topology";_dataset;_displayArcs=null;_options;_data;_loadVersion=0;_abortController=null;_pending=null;_simplifyFloor=0;_runner;getSimplifyFloor(){return this._simplifyFloor}constructor(t,e){super(),this.id=t,this._options=e||{},this._data=this._options.data,this._runner=this._options.mapshaperRunner??Ai??(Ai=new Ci),this._data&&this._updateData()}static async fromUrl(t,e,i){const s=new Li(t,i);return await s.setData(e),s}static async fromBytes(t,e,i){const{filename:s=`${t}.geojson`,...n}=i??{},r=e instanceof Uint8Array?e:new Uint8Array(e),a=new Li(t,n);return await a.setData({filename:s,content:r}),a}setData(t){this._loadVersion++;const e=this._loadVersion;this._abortController?.abort(),this._abortController=null,this._data=t,this._pending?.resolve(this);const i=new Promise((t,i)=>{this._pending={version:e,resolve:t,reject:i}});return i.catch(()=>{}),this._updateData(),i}async _updateData(){if(!this._data)return;const t=this._loadVersion,e=new AbortController;this._abortController=e,this.fire("dataloading");try{const i={},s=[];if(Array.isArray(this._data)){if(0===this._data.length)throw new Error("setData received an empty array; nothing to import");for(const t of this._data)if(this._isZipFile(t.filename)){const e=await this._extractZip(t.content),n=this._findPrimaryFile(e);if(!n)throw new Error(`No importable file found in zip archive: ${t.filename}`);for(const[t,s]of Object.entries(e))i[t]=s;s.push(n)}else i[t.filename]=t.content,s.push(t.filename)}else{let t;if("string"==typeof this._data){const i=this._data,s=await fetch(i,{signal:e.signal});if(!s.ok)throw new Error(`Failed to fetch ${i}: HTTP ${s.status}`);const n=await s.arrayBuffer(),r=new Uint8Array(n);let a=new URL(i).pathname.split("/").pop()||"";if(!this._hasSupportedExtension(a)){const t=s.headers.get("Content-Type")||"";a=this._filenameFromContentType(t,a)}a||(a="data.json"),t={filename:a,content:r}}else t=this._data;if(this._isZipFile(t.filename)){const e=await this._extractZip(t.content),n=this._findPrimaryFile(e);if(!n)throw new Error("No importable file found in zip archive");for(const[t,s]of Object.entries(e))i[t]=s;s.push(n)}else i[t.filename]=t.content,s.push(t.filename)}const n=`-i ${s.map(t=>`"${t.replace(/"/g,'\\"')}"`).join(" ")}`,r=await this._runner.runImport(n,i);if(t!==this._loadVersion)return;this._dataset=r,this._dataset?.arcs&&(this._displayArcs=new Si(this._dataset.arcs)),this._simplifyFloor=this._dataset?.arcs?.getRetainedInterval?.()??0,this.fire("data",{reason:"load"}),this._resolvePending(t)}catch(e){if(t!==this._loadVersion)return;if("AbortError"===e?.name)return;this.fire("error",{error:e}),this._rejectPending(t,e??new Error("setData import failed"))}}_resolvePending(t){if(this._pending?.version!==t)return;const e=this._pending;this._pending=null,e.resolve(this)}_rejectPending(t,e){if(this._pending?.version!==t)return;const i=this._pending;this._pending=null,i.reject(e)}_hasSupportedExtension(t){return/\.(json|geojson|topojson|zip|shp|kml|msx)$/i.test(t)}_filenameFromContentType(t,e){return(e||"data")+({"application/json":".json","application/geo+json":".geojson","application/vnd.geo+json":".geojson","application/topojson+json":".topojson","application/zip":".zip","application/x-zip-compressed":".zip","application/octet-stream":".zip","application/vnd.google-earth.kml+xml":".kml","text/plain":".json"}[t.toLowerCase().split(";")[0].trim()]||".json")}getDataset(){return this._dataset}getCRS(){return Mi(this._dataset)}async reproject(t){if(!this._dataset)return;this._dataset?.arcs?.setRetainedInterval&&this._dataset.arcs.setRetainedInterval(0),this._dataset.info&&(delete this._dataset.info.crs_string,delete this._dataset.info.prj,delete this._dataset.info.wkt1);const e=`-proj ${t}`,i=await tt().runOnDataset(e,this._dataset);this._dataset=i,this._dataset?.arcs&&(this._displayArcs=new Si(this._dataset.arcs))}getExtent(){if(!this._dataset)return new V;const t=tt().getDatasetBounds(this._dataset);return new V(t.xmin,t.ymin,t.xmax,t.ymax)}getArcs(){return this._dataset?.arcs}getDisplayArcs(){return this._displayArcs}markDisplayArcsDirty(){this._displayArcs?.markDirty()}refreshDisplayArcs(){this._dataset?.arcs&&(this._displayArcs=new Si(this._dataset.arcs))}setDataset(t){this._dataset=t,t.arcs?this._displayArcs=new Si(t.arcs):this._displayArcs=null,this._simplifyFloor=t.arcs?.getRetainedInterval?.()??0,this.fire("data",{reason:"replace"})}async export(t){if(!this._dataset)throw new Error("TopologySource has no dataset to export");const e=this._dataset.arcs,i=e?.getRetainedInterval?.()??0;i&&e?.setRetainedInterval&&e.setRetainedInterval(0);try{const e=tt(),i="msx"===t.format?await e.exportPackedDatasets([this._dataset],{compact:!0}):e.exportFileContent(this._dataset,{format:t.format});return this._filesToBlob(i,t.format)}finally{i&&e?.setRetainedInterval&&e.setRetainedInterval(i)}}_filesToBlob(t,e){if(0===t.length)throw new Error(`mapshaper produced no output for format=${e}`);if("shapefile"===e){const e={};for(const i of t)e[i.filename]=Pi(i.content);const i=vi(e);return new Blob([i],{type:Di.shapefile})}return new Blob([t[0].content],{type:Di[e]})}getLayers(){return this._dataset?.layers||[]}_isZipFile(t){return/\.zip$/i.test(t)}async _extractZip(t){const e={...Ti,...this._options.zipLimits};let i=0,s=0;const n=await new Promise((n,r)=>{bi(t,{filter:n=>{if(s++,s>e.maxEntries)throw new Error(`ZIP extraction limit exceeded: ${s} entries > maxEntries ${e.maxEntries}`);if(i+=n.originalSize,i>e.maxBytes)throw new Error(`ZIP extraction limit exceeded: uncompressed total ${i} > maxBytes ${e.maxBytes}`);if(t.byteLength>0){const s=i/t.byteLength;if(s>e.maxRatio)throw new Error(`ZIP extraction limit exceeded: ratio ${s.toFixed(1)} > maxRatio ${e.maxRatio}`)}return!(/^__MACOSX/.test(n.name)||n.name.split("/").pop()?.startsWith("."))}},(t,e)=>{t?r(t):n(e)})}),r={};for(const t of Object.keys(n)){const e=n[t],i=t.split("/").pop()||t;this._isTextFile(i)?r[i]=fi(e):r[i]=e}return r}_isTextFile(t){return/\.(prj|cpg|csv|json|geojson|kml|txt)$/i.test(t)}_findPrimaryFile(t){const e=Object.keys(t),i=[".shp",".geojson",".json",".kml",".topojson"];for(const t of i){const i=e.find(e=>e.toLowerCase().endsWith(t));if(i)return i}return e.find(t=>!this._isAuxiliaryFile(t))||""}_isAuxiliaryFile(t){return/\.(prj|shx|dbf)$/i.test(t)}}function Fi(t){const e=[];return function(i){e.push(i),e.length>t&&e.shift();return e.reduce((t,e)=>t+e,0)/e.length}}class Ni extends U{_element;_active=!1;_timer=new W;_sustainInterval=150;_fadeDelay=70;_eventTime=0;_getAverageRate=Fi(10);_getWheelDirection=function(){let t=0,e=null;return function(i,s){const n=i>0?1:i<0?-1:0;(!e||s-t>300)&&(e=Fi(3)),t=s;const r=e(n)||n;return r>0?1:r<0?-1:0}}();_wheelDirection=0;_mouseX=0;_mouseY=0;_wheelHandler=t=>this._handleWheel(t);constructor(t){super(),this._element=t,this._timer.on("tick",t=>this._onTick(t)),this._element.addEventListener("wheel",this._wheelHandler,{passive:!1})}destroy(){this._element.removeEventListener("wheel",this._wheelHandler),this._timer.stop()}_updateSustainInterval(t){this._fadeDelay=t+50,this._sustainInterval=this._fadeDelay+80}_handleWheel(t){const e=Date.now();if(this._wheelDirection=this._getWheelDirection(-t.deltaY,e),0===this._wheelDirection)return;t.preventDefault();const i=this._element.getBoundingClientRect();this._mouseX=t.clientX-i.left,this._mouseY=t.clientY-i.top,this._active?this._updateSustainInterval(this._getAverageRate(e-this._eventTime)):(this._active=!0,this.fire("mousewheelstart")),this._eventTime=e,this._timer.start(this._sustainInterval)}_onTick(t){const e=t.time-this._eventTime;let i=t.tickTime/25,s=0;e>this._fadeDelay&&(s=Math.min(1,(e-this._fadeDelay)/(this._sustainInterval-this._fadeDelay))),t.done?(this._active=!1,this.fire("mousewheelend")):(s>0&&(i*=H.quadraticOut(1-s)),this.fire("mousewheel",{direction:this._wheelDirection,multiplier:i,x:this._mouseX,y:this._mouseY}))}}class Ri extends U{name="scrollZoom";_wheel;_enabled=!0;_onGestureStart;constructor(t,e){super(),this._onGestureStart=e,this._wheel=new Ni(t),this._wheel.on("mousewheel",t=>{this._onGestureStart?.(),this._enabled&&this.fire("mousewheel",t)})}enable(){this._enabled=!0}disable(){this._enabled=!1}isEnabled(){return this._enabled}setOptions(t){}getOptions(){return{}}handlePointer(t){return"passthrough"}destroy(){this._wheel.destroy()}}const Oi={skipShiftDrag:!0};class Gi extends U{name="dragPan";_opts;_enabled=!0;_dragging=!1;_last={x:0,y:0};_onGestureStart;constructor(t,e){super(),this._opts={...Oi,...t},this._onGestureStart=e}enable(){this._enabled=!0}disable(){this._enabled=!1,this._dragging&&(this._dragging=!1,this.fire("panend"))}isEnabled(){return this._enabled}setOptions(t){this._opts={...this._opts,...t}}getOptions(){return this._opts}getCursor(){return this._enabled?this._dragging?"grabbing":"grab":null}handlePointer(t){if(!this._enabled)return"passthrough";if("down"===t.kind)return 0!==t.button||this._opts.skipShiftDrag&&t.modifiers.shift?"passthrough":(this._onGestureStart?.(),this._dragging=!0,this._last={x:t.point.x,y:t.point.y},this.fire("panstart"),"exclusive");if("move"===t.kind&&this._dragging){const e=t.point.x-this._last.x,i=t.point.y-this._last.y;return this._last={x:t.point.x,y:t.point.y},this.fire("pan",{dx:e,dy:i}),"exclusive"}return"up"===t.kind&&this._dragging?(this._dragging=!1,this.fire("panend"),"passthrough"):"passthrough"}}const zi=["shift","ctrl","alt","meta"];function qi(t,e,i){const s=i?function(t){return"none"===t?new Set:new Set(t.split("+"))}(i):new Set,n=t.ctrl&&!s.has("ctrl"),r=t.meta&&!s.has("meta"),a=function(t){const e=zi.filter(e=>t[e]);return 0===e.length?"none":e.join("+")}({shift:t.shift&&!s.has("shift"),ctrl:n||r,alt:t.alt&&!s.has("alt"),meta:!1});for(const t of["replace","add","toggle"]){const i=e[t];if(i&&i===a)return t}return"replace"}function ji(t,e){const[i,s]=t;let n=!1;const r=e.length;for(let t=0,a=r-1;t<r;a=t++){const[r,o]=e[t],[h,l]=e[a];o>s!=l>s&&i<(h-r)*(s-o)/(l-o)+r&&(n=!n)}return n}function Bi(t,e,i,s){const n=function(t,e){const i=t.getSource(e.source);if(!i)return null;let s=t.layers?.resolve(e.source,e.layer);if(!s){const t=i.getDataset?.();s=t?.layers.find((t,i)=>rt(t,i)===e.layer||t?.name===e.layer||t?.id===e.layer)}if(!s?.shapes)return null;const n=s.shapes?.[e.id];return n?{layer:s,shape:n,arcs:i.getArcs?.()}:null}(t,e);if(!n)return!1;if("point"===n.layer.geometry_type){const e=at(n.shape);if(0===e.length)return!1;const r=e.map(([e,i])=>t.project(e,i));return s?r.some(t=>$i(t,i)):r.every(t=>$i(t,i))}if(!n.arcs)return!1;const r=function(t,e,i){const s=[];for(const n of e){const e=[],r=i.getShapeIter?.(n);if(r)for(;r.hasNext();)e.push(t.project(r.x,r.y));else for(const s of n){const n=s>=0?s:~s,r=i.getArcIter(n);for(;r.hasNext();)e.push(t.project(r.x,r.y))}e.length>0&&s.push(e)}return s}(t,n.shape,n.arcs);if(0===r.length)return!1;const a="polygon"===n.layer.geometry_type;return s?function(t,e,i){for(const s of t){if(s.some(t=>$i(t,e)))return!0;if(Ui(s,e,i))return!0}return!(!i||!e.some(e=>function(t,e){let i=!1;for(const s of e){if(Vi(t,s))return!0;ji(t,s)&&(i=!i)}return i}(e,t)))}(r,i,a):function(t,e,i){for(const s of t){if(!s.every(t=>$i(t,e)))return!1;if(Ui(s,e,i))return!1}return!0}(r,i,a)}function Ui(t,e,i){const s=i?Wi(t):t,n=Wi(e);for(let t=0;t<s.length-1;t++){const e=s[t],i=s[t+1];for(let t=0;t<n.length-1;t++){if(Hi(e,i,n[t],n[t+1]))return!0}}return!1}function $i(t,e){return Vi(t,e)||ji(t,e)}function Vi(t,e){const i=Wi(e);for(let e=0;e<i.length-1;e++)if(Ki(t,i[e],i[e+1]))return!0;return!1}function Wi(t){if(t.length<2)return t;const e=t[0],i=t[t.length-1];return s=e,n=i,Math.abs(s[0]-n[0])<=Ji&&Math.abs(s[1]-n[1])<=Ji?t:[...t,e];var s,n}function Hi(t,e,i,s){const n=Zi(t,e,i),r=Zi(t,e,s),a=Zi(i,s,t),o=Zi(i,s,e);return!(!Xi(n)||!Ki(i,t,e))||(!(!Xi(r)||!Ki(s,t,e))||(!(!Xi(a)||!Ki(t,i,s))||(!(!Xi(o)||!Ki(e,i,s))||n>0!=r>0&&a>0!=o>0)))}function Ki(t,e,i){return!!Xi(Zi(e,i,t))&&(t[0]>=Math.min(e[0],i[0])-Ji&&t[0]<=Math.max(e[0],i[0])+Ji&&t[1]>=Math.min(e[1],i[1])-Ji&&t[1]<=Math.max(e[1],i[1])+Ji)}function Zi(t,e,i){return(e[0]-t[0])*(i[1]-t[1])-(e[1]-t[1])*(i[0]-t[0])}function Xi(t){return Math.abs(t)<=Ji}const Ji=1e-9;function Yi(t){const e=new Set,i=[];for(const s of t){const t=`${s.source}|${s.layer}|${s.id}`;e.has(t)||(e.add(t),i.push({source:s.source,layer:s.layer,id:s.id}))}return i}const Qi={replace:"none",add:"shift",toggle:"shift+alt"};class ts extends U{_map;name="clickSelect";_enabled=!1;_opts={};constructor(t){super(),this._map=t}enable(){this._enabled=!0}disable(){this._enabled=!1}isEnabled(){return this._enabled}setOptions(t){this._opts={...this._opts,...t}}getOptions(){return this._opts}handlePointer(t){if(!this._enabled||"click"!==t.kind||0!==t.button)return"passthrough";const e=qi(t.modifiers,this._opts.modifiers??Qi),i=Yi(this._map.queryFeatures([t.point.x,t.point.y],this._opts.layers?{layers:this._opts.layers}:void 0));return 0===i.length?("replace"===e&&this._map.select([],{mode:"replace"}),"consumed"):(this._map.select(i,{mode:e}),"consumed")}}const es={replace:"none",add:"ctrl",toggle:"alt"};class is extends U{_map;name="boxSelect";_enabled=!1;_opts={};_start=null;_overlay=null;_manager;constructor(t){super(),this._map=t}enable(){if(this._manager?.isEnabledByName("lassoSelect"))throw new Error("cannot enable boxSelect: lassoSelect is enabled (both consume shift+drag); disable it first");this._enabled=!0}disable(){this._enabled=!1,this._start&&this._cancel()}isEnabled(){return this._enabled}setOptions(t){this._opts={...this._opts,...t}}getOptions(){return this._opts}getCursor(){return this._enabled?"crosshair":null}get _threshold(){return this._opts.dragThreshold??4}get _activator(){return this._opts.dragActivator??"shift"}_ensureOverlay(){if(this._overlay)return this._overlay;const t=document.createElement("div");t.className="emap-box-select",t.style.position="absolute",t.style.pointerEvents="none",t.style.display="none",t.style.boxSizing="border-box";const e=this._opts.style??{};return t.style.border=`${e.strokeWidth??1.5}px solid ${e.stroke??"#0078ff"}`,t.style.background=e.fill??"rgba(0, 120, 255, 0.1)",this._map.getCanvasContainer().appendChild(t),this._overlay=t,t}_cancel(){this._overlay&&(this._overlay.style.display="none"),this._start=null}handlePointer(t){if(!this._enabled)return"passthrough";if("down"===t.kind){if(0!==t.button||(e=t.modifiers,"none"!==(i=this._activator)&&!i.split("+").every(t=>!0===e[t])))return"passthrough";this._start={x:t.point.x,y:t.point.y};const s=this._ensureOverlay();return s.style.left=`${t.point.x}px`,s.style.top=`${t.point.y}px`,s.style.width="0",s.style.height="0",s.style.display="block","exclusive"}var e,i;if("move"===t.kind&&this._start){const e=this._ensureOverlay(),i=Math.min(this._start.x,t.point.x),s=Math.min(this._start.y,t.point.y);return e.style.left=`${i}px`,e.style.top=`${s}px`,e.style.width=`${Math.abs(t.point.x-this._start.x)}px`,e.style.height=`${Math.abs(t.point.y-this._start.y)}px`,"exclusive"}if("up"===t.kind&&this._start){const e=this._start,{x:i,y:s}=t.point;if(this._cancel(),Math.hypot(i-e.x,s-e.y)<this._threshold)return"passthrough";const n=Math.min(e.x,i),r=Math.min(e.y,s),a=Math.max(e.x,i),o=Math.max(e.y,s),h=this._map.queryFeatures([[n,r],[a,o]],this._opts.layers?{layers:this._opts.layers}:void 0),l=qi(t.modifiers,this._opts.modifiers??es,this._activator);return this._map.select(Yi(h),{mode:l}),"passthrough"}return"passthrough"}}const ss={replace:"none",add:"ctrl",toggle:"alt"},ns="http://www.w3.org/2000/svg";class rs extends U{_map;name="lassoSelect";_enabled=!1;_opts={};_path=null;_svg=null;_poly=null;_manager;constructor(t){super(),this._map=t}enable(){if(this._manager?.isEnabledByName("boxSelect"))throw new Error("cannot enable lassoSelect: boxSelect is enabled (both consume shift+drag); disable it first");this._enabled=!0}disable(){this._enabled=!1,this._path&&this._cancel()}isEnabled(){return this._enabled}setOptions(t){this._opts={...this._opts,...t}}getOptions(){return this._opts}getCursor(){return this._enabled?"crosshair":null}get _threshold(){return this._opts.dragThreshold??4}get _activator(){return this._opts.dragActivator??"shift"}_ensureSvg(){if(this._svg&&this._poly)return{svg:this._svg,poly:this._poly};const t=document.createElementNS(ns,"svg");t.style.position="absolute",t.style.left="0",t.style.top="0",t.style.width="100%",t.style.height="100%",t.style.pointerEvents="none",t.style.display="none",t.setAttribute("class","emap-lasso-select");const e=document.createElementNS(ns,"polyline"),i=this._opts.style??{};return e.setAttribute("fill",i.fill??"rgba(0, 120, 255, 0.1)"),e.setAttribute("stroke",i.stroke??"#0078ff"),e.setAttribute("stroke-width",String(i.strokeWidth??1.5)),e.setAttribute("stroke-dasharray",i.strokeDasharray??"4 3"),e.setAttribute("points",""),t.appendChild(e),this._map.getCanvasContainer().appendChild(t),this._svg=t,this._poly=e,{svg:t,poly:e}}_cancel(){this._svg&&(this._svg.style.display="none"),this._path=null}handlePointer(t){if(!this._enabled)return"passthrough";if("down"===t.kind){if(0!==t.button||(e=t.modifiers,"none"!==(i=this._activator)&&!i.split("+").every(t=>!0===e[t])))return"passthrough";const{svg:s,poly:n}=this._ensureSvg();return this._path=[[t.point.x,t.point.y]],n.setAttribute("points",`${t.point.x},${t.point.y}`),s.style.display="block","exclusive"}var e,i;if("move"===t.kind&&this._path)return this._path.push([t.point.x,t.point.y]),this._poly?.setAttribute("points",this._path.map(t=>`${t[0]},${t[1]}`).join(" ")),"exclusive";if("up"===t.kind&&this._path){const e=this._path;if(this._cancel(),e.length<3)return"passthrough";const i=function(t){let e=1/0,i=1/0,s=-1/0,n=-1/0;for(const[r,a]of t)r<e&&(e=r),a<i&&(i=a),r>s&&(s=r),a>n&&(n=a);return[e,i,s,n]}(e);if(Math.hypot(i[2]-i[0],i[3]-i[1])<this._threshold)return"passthrough";const s=e.slice();s.push(e[0]);const n=this._map.queryFeatures([[i[0],i[1]],[i[2],i[3]]],this._opts.layers?{layers:this._opts.layers}:void 0),r=!1!==this._opts.includeIntersecting,a=[],o=new Set;for(const t of n){const e=`${t.source}|${t.layer}|${t.id}`;o.has(e)||Bi(this._map,t,s,r)&&(o.add(e),a.push({source:t.source,layer:t.layer,id:t.id}))}const h=qi(t.modifiers,this._opts.modifiers??ss,this._activator);return this._map.select(a,{mode:h}),"passthrough"}return"passthrough"}}class as{opts;label="Move vertex";_mergeAt=Date.now();constructor(t){this.opts=t}do(){(this.opts.adapter??tt()).snapVertices(this.opts.vertexIds,this.opts.to,this.opts.arcs),this.opts.source.markDisplayArcsDirty?.(),zt(this.opts.source.getDataset?.())}undo(){(this.opts.adapter??tt()).snapVertices(this.opts.vertexIds,this.opts.from,this.opts.arcs),this.opts.source.markDisplayArcsDirty?.(),zt(this.opts.source.getDataset?.())}mergeable(t){if(!(t instanceof as))return!1;if(t.opts.source!==this.opts.source)return!1;if(Date.now()-t._mergeAt>500)return!1;const e=t.opts.vertexIds,i=this.opts.vertexIds;if(e.length!==i.length)return!1;for(let t=0;t<e.length;t++)if(e[t]!==i[t])return!1;return!0}merge(t){t instanceof as&&(this.opts.to=t.opts.to,this._mergeAt=Date.now())}}class os{opts;label="Insert vertex";constructor(t){this.opts=t}do(){(this.opts.adapter??tt()).insertVertex(this.opts.arcs,this.opts.insertionId,this.opts.point),this.opts.source.markDisplayArcsDirty?.(),zt(this.opts.source.getDataset?.())}undo(){(this.opts.adapter??tt()).deleteVertex(this.opts.arcs,this.opts.insertionId),this.opts.source.markDisplayArcsDirty?.(),zt(this.opts.source.getDataset?.())}}class hs{opts;label="Delete vertex";constructor(t){this.opts=t}do(){(this.opts.adapter??tt()).deleteVertex(this.opts.arcs,this.opts.vertexIndex),this.opts.source.markDisplayArcsDirty?.(),zt(this.opts.source.getDataset?.())}undo(){(this.opts.adapter??tt()).insertVertex(this.opts.arcs,this.opts.vertexIndex,this.opts.coords),this.opts.source.markDisplayArcsDirty?.(),zt(this.opts.source.getDataset?.())}}class ls{name="vertexEdit";_map;_enabled=!1;_manager;_polygonFillColor;_hoveredFeature=null;_hoverVertexCoords=null;_hoverVertexIds=[];_hoverType=null;_hoverInsertionId=-1;_dragging=!1;_neighborShapes=[];_dragFromCoords=null;_onMapMoveBound=()=>this._onMapMove();constructor(t,e={}){this._map=t,this._polygonFillColor=void 0!==e.polygonFillColor?e.polygonFillColor:"rgba(0,0,0,0.15)"}isEnabled(){return this._enabled}enable(){this._enabled||(this._enabled=!0,this._map.setEditMode("vertex"),this._map.on("move",this._onMapMoveBound),this._manager?.refreshCursor())}getCursor(){return this._enabled?"crosshair":null}disable(){this._enabled&&(this._enabled=!1,this._hoveredFeature=null,this._hoverVertexCoords=null,this._hoverVertexIds=[],this._hoverType=null,this._hoverInsertionId=-1,this._neighborShapes=[],this._dragging=!1,this._map.setEditMode("none"),this._map.clearEditVertexState(),this._map.off("move",this._onMapMoveBound),this._manager?.refreshCursor(),this._map.render())}setOptions(t){void 0!==t.polygonFillColor&&(this._polygonFillColor=t.polygonFillColor)}getOptions(){return{polygonFillColor:this._polygonFillColor??void 0}}handlePointer(t){if(!this._enabled)return"passthrough";const e=t.point.x,i=t.point.y;return"move"===t.kind?this._dragging?(this._handleDrag(e,i),"exclusive"):(this._onMouseMove(e,i),"passthrough"):"down"===t.kind?0!==t.button?"passthrough":(this._onMouseDown(e,i),this._dragging?"exclusive":"passthrough"):"up"===t.kind?this._dragging?(this._finishDrag(e,i),"passthrough"):"passthrough":"contextmenu"===t.kind?(this._onContextMenu(t.originalEvent),"consumed"):"passthrough"}_onMapMove(){this._hoveredFeature&&!this._dragging&&(this._updateEditState(),this._map.render())}_onContextMenu(t){if(t.preventDefault(),this._dragging)return;if("vertex"!==this._hoverType||0===this._hoverVertexIds.length)return;if(!this._hoveredFeature)return;const e=this._hoverVertexIds[0],i=this._hoveredFeature.arcs;tt().vertexIsArcEndpoint(e,i)||this._showContextMenu(t.clientX,t.clientY,()=>{this._deleteHoveredVertex()})}_deleteHoveredVertex(){if(!this._hoveredFeature||0===this._hoverVertexIds.length)return;const t=this._hoveredFeature.arcs,e=this._hoverVertexIds[0],i=this._hoveredFeature.source,s=t.getVertex2(e);if(tt().deleteVertex(t,e),this._refreshSourceDisplayArcs(i),this._bumpSourceEditVersion(i),s){const n=this._map.getSource(i);n&&this._map.pushCommand(new hs({vertexIndex:e,coords:[s[0],s[1]],arcs:t,source:n}))}this._hoverVertexCoords=null,this._hoverVertexIds=[],this._hoverType=null,this._hoverInsertionId=-1,this._neighborShapes=[],this._map.clearEditVertexState(),this._map.render()}_refreshSourceDisplayArcs(t){this._map.getSource(t)?.refreshDisplayArcs()}_bumpSourceEditVersion(t){const e=this._map.getSource(t);zt(e?.getDataset?.()??null)}_showContextMenu(t,e,i){document.getElementById("emap-ctx-menu")?.remove();const s=document.createElement("div");s.id="emap-ctx-menu",s.className="emap-ctx-menu",s.style.left=`${t}px`,s.style.top=`${e}px`;const n=document.createElement("div");n.className="emap-ctx-menu-item",n.textContent="删除节点",n.addEventListener("click",t=>{t.stopPropagation(),s.remove(),document.removeEventListener("click",r),i()}),s.appendChild(n),document.body.appendChild(s);const r=()=>{s.remove(),document.removeEventListener("click",r)};setTimeout(()=>document.addEventListener("click",r),0)}_onMouseMove(t,e){const i=this._map.queryFeatures([t,e]);if(0===i.length)return this._hoveredFeature=null,this._hoverVertexCoords=null,this._hoverVertexIds=[],this._hoverType=null,this._hoverInsertionId=-1,this._neighborShapes=[],this._map.clearEditVertexState(),void this._map.render();const s=i[0];if("point"===s.geometryType)return this._hoveredFeature=null,this._hoverVertexCoords=null,this._hoverVertexIds=[],this._hoverType=null,this._hoverInsertionId=-1,this._neighborShapes=[],this._map.clearEditVertexState(),void this._map.render();const n=this._map.getSource(s.source);if(!n)return;const r=n.getLayers(),a=n.getArcs();if(!a)return;let o=null;for(const t of r)if(Ot(t)&&t.shapes&&t.shapes[s.id]){o=t.shapes[s.id];break}o&&(this._hoveredFeature={source:s.source,layer:s.layer,id:s.id,shape:o,arcs:a,geometryType:s.geometryType,allLayers:r},this._findNearestVertices(o,a,t,e),this._hoverVertexCoords||this._findInterpolatedPoint(o,a,t,e),this._findNeighborShapes(a),this._updateEditState(),this._map.render())}_findNearestVertices(t,e,i,s){const n=this._map.unproject(i,s),r=tt().findNearestVertices(n,t,e);if(!r||0===r.length)return this._hoverVertexCoords=null,void(this._hoverVertexIds=[]);const a=e.getVertex2(r[0]);if(!a)return this._hoverVertexCoords=null,void(this._hoverVertexIds=[]);const o=this._map.project(a[0],a[1]);Math.sqrt((o[0]-i)*(o[0]-i)+(o[1]-s)*(o[1]-s))<=10?(this._hoverVertexCoords=[a[0],a[1]],this._hoverVertexIds=r,this._hoverType="vertex",this._hoverInsertionId=-1):(this._hoverVertexCoords=null,this._hoverVertexIds=[],this._hoverType=null,this._hoverInsertionId=-1)}_findInterpolatedPoint(t,e,i,s){const n=this._map.unproject(i,s);let r=1/0,a=null;const o=tt();if(o.forEachSegmentInShape(t,e,(t,e,i,s)=>{const h=i[t],l=s[t],c=i[e],u=s[e],p=o.findClosestPointOnSeg(n[0],n[1],h,l,c,u,0),_=p[0]-n[0],d=p[1]-n[1],f=Math.sqrt(_*_+d*d);f<r&&(r=f,a={insertionId:(t<e?t:e)+1,point:[p[0],p[1]]})}),!a)return;const h=a,l=this._map.project(h.point[0],h.point[1]);Math.sqrt((l[0]-i)*(l[0]-i)+(l[1]-s)*(l[1]-s))<=10&&(this._hoverVertexCoords=h.point,this._hoverVertexIds=[],this._hoverType="interpolated",this._hoverInsertionId=h.insertionId)}_findNeighborShapes(t){if(this._neighborShapes=[],!this._hoveredFeature||"polygon"!==this._hoveredFeature.geometryType)return;const{ii:e}=t.getVertexData(),i=this._hoveredFeature.id,s=new Set;if(this._hoverVertexIds.length>0)for(const t of this._hoverVertexIds)s.add(tt().findArcIdFromVertexId(t,e));else"interpolated"===this._hoverType&&this._hoverInsertionId>0&&s.add(tt().findArcIdFromVertexId(this._hoverInsertionId-1,e));if(0===s.size)return;const n=[];for(const t of this._hoveredFeature.allLayers)if(t.shapes)for(let e=0;e<t.shapes.length;e++){if(e===i)continue;const r=t.shapes[e];if(!r)continue;let a=!1;for(const t of r){for(const e of t){const t=e>=0?e:~e;if(s.has(t)){a=!0;break}}if(a)break}a&&n.push(r)}this._neighborShapes=n}_updateEditState(){if(!this._hoveredFeature)return;const t=this._hoveredFeature.geometryType,e=this._neighborShapes.length>0?[this._hoveredFeature.shape,...this._neighborShapes]:[this._hoveredFeature.shape];this._map.setEditVertexState({shapes:e,arcs:this._hoveredFeature.arcs,hoverVertex:this._hoverVertexCoords,hoverType:this._hoverType,geometryType:t,polygonFill:"polygon"===t?this._polygonFillColor:null,neighborShapes:this._neighborShapes.length>0?this._neighborShapes:void 0})}_onMouseDown(t,e){if(this._hoverVertexCoords&&this._hoveredFeature){if("interpolated"===this._hoverType&&this._hoverInsertionId>=0){const t=this._hoveredFeature.arcs,e=[this._hoverVertexCoords[0],this._hoverVertexCoords[1]];tt().insertVertex(t,this._hoverInsertionId,e),this._hoverVertexIds=[this._hoverInsertionId],this._hoverType="vertex",this._bumpSourceEditVersion(this._hoveredFeature.source),this._pushVertexInsertCommand(this._hoverInsertionId,e)}this._dragFromCoords=this._hoverVertexCoords?[this._hoverVertexCoords[0],this._hoverVertexCoords[1]]:null,this._dragging=!0}}_pushVertexInsertCommand(t,e){if(!this._hoveredFeature)return;const i=this._map.getSource(this._hoveredFeature.source);i&&this._map.pushCommand(new os({insertionId:t,point:e,arcs:this._hoveredFeature.arcs,source:i}))}_handleDrag(t,e){if(!this._hoveredFeature||0===this._hoverVertexIds.length)return;const i=this._map.unproject(t,e),s=this._hoveredFeature.arcs;tt().snapVertices(this._hoverVertexIds,[i[0],i[1]],s),this._hoverVertexCoords=[i[0],i[1]],this._updateEditState(),this._map.render()}_finishDrag(t,e){if(!this._dragging||!this._hoveredFeature)return;this._dragging=!1;const i=this._map.unproject(t,e),s=this._hoveredFeature.source,n=this._hoveredFeature.arcs;n.transformPoints&&n.transformPoints(function(){}),this._refreshSourceDisplayArcs(s),this._bumpSourceEditVersion(s);const r=this._dragFromCoords;if(r&&(r[0]!==i[0]||r[1]!==i[1])&&this._hoverVertexIds.length>0){const t=this._map.getSource(s);t&&this._map.pushCommand(new as({vertexIds:[...this._hoverVertexIds],from:[r[0],r[1]],to:[i[0],i[1]],arcs:n,source:t}))}this._dragFromCoords=null,this._map.fire("vertex_moved",{id:this._hoveredFeature.id,source:s,layer:this._hoveredFeature.layer,vertexIndex:this._hoverVertexIds[0]??null,vertexIds:this._hoverVertexIds,coords:i}),this._map.render()}}class cs{opts;label;constructor(t){this.opts=t,this.label=`Draw ${t.geometryType}`}do(){const t=this.opts,e=t.adapter??tt();if("point"!==t.geometryType){if(!t.arcs||!t.arcVertices)throw new Error("FeatureCreateCommand: path features require arcs and arcVertices");e.appendEmptyArc(t.arcs);for(const i of t.arcVertices)e.appendVertex(t.arcs,i)}if(t.layer.shapes||(t.layer.shapes=[]),t.layer.shapes.push(t.appendedShape),null!==t.appendedRecord){const e=t.layer.data?.getRecords?.();e?.push(t.appendedRecord)}t.source.markDisplayArcsDirty?.(),zt(t.source.getDataset?.())}undo(){const t=this.opts,e=t.adapter??tt();if(t.layer.shapes?.pop(),null!==t.appendedRecord){const e=t.layer.data?.getRecords?.();e?.pop()}"point"!==t.geometryType&&t.arcs&&e.deleteLastArc(t.arcs),t.source.markDisplayArcsDirty?.(),zt(t.source.getDataset?.())}}class us{name="drawFeature";_map;_enabled=!1;_opts;_manager;_vertices=[];_cursorCoord=null;_snapCoord=null;_snapKind=null;_snapThreshold;_onMapMoveBound=()=>this._onMapMove();_onKeyDownBound=t=>this._onKeyDown(t);constructor(t,e){this._map=t,this._opts={...e??{}},this._snapThreshold=this._opts.snapThreshold??10,this._map.on("editmodechange",t=>{"draw"!==t.mode&&this._enabled&&this._quietDisable()})}isEnabled(){return this._enabled}setOptions(t){this._opts={...this._opts,...t},void 0!==t.snapThreshold&&(this._snapThreshold=t.snapThreshold)}getCursor(){return this._enabled?"crosshair":null}getOptions(){return{...this._opts}}enable(){if(!this._enabled){if(!this._opts.source||!this._opts.type)throw new Error("drawFeature: source+type required; call setOptions({source,type}) first");this._enabled=!0,this._map.setEditMode("draw"),window.addEventListener("keydown",this._onKeyDownBound),this._map.on("move",this._onMapMoveBound),this._manager?.refreshCursor()}}disable(){this._enabled&&(this._enabled=!1,this._clearDrawState(),window.removeEventListener("keydown",this._onKeyDownBound),this._map.off("move",this._onMapMoveBound),this._map.setEditMode("none"),this._map.clearEditDrawState(),this._manager?.refreshCursor(),this._map.render())}_quietDisable(){this._enabled=!1,window.removeEventListener("keydown",this._onKeyDownBound),this._map.off("move",this._onMapMoveBound),this._map.clearEditDrawState(),this._manager?.refreshCursor(),this._map.render()}handlePointer(t){if(!this._enabled)return"passthrough";const e=t.point.x,i=t.point.y;return"move"===t.kind?(this._onMouseMove(e,i),"passthrough"):"click"===t.kind?0!==t.button?"passthrough":(this._onClick(e,i),"consumed"):"dblclick"===t.kind?(this._onDblClick(t.originalEvent),"consumed"):"passthrough"}_onMapMove(){this._vertices.length>0&&(this._updateDrawState(),this._map.render())}_onMouseMove(t,e){const i=this._map.unproject(t,e);this._cursorCoord=[i[0],i[1]];const s=this._findSnapTarget(t,e);this._snapCoord=s?.coord??null,this._snapKind=s?.kind??null,(this._vertices.length>0||this._snapCoord)&&(this._updateDrawState(),this._map.render())}_onClick(t,e){const i=this._snapCoord?[this._snapCoord[0],this._snapCoord[1]]:this._map.unproject(t,e);if("point"===this._opts.type)return this._vertices=[i],void this._commitFeature();if("polygon"===this._opts.type&&this._vertices.length>=3){const i=this._vertices[0],s=this._map.project(i[0],i[1]);if(Math.hypot(s[0]-t,s[1]-e)<=12)return void this._commitFeature()}this._vertices.push(i),this._updateDrawState(),this._map.render()}_onDblClick(t){t.preventDefault(),t.stopPropagation(),"point"!==this._opts.type&&("polyline"===this._opts.type&&this._vertices.length>=2||"polygon"===this._opts.type&&this._vertices.length>=3)&&this._commitFeature()}_onKeyDown(t){"Escape"===t.key&&(this._clearDrawState(),this._map.clearEditDrawState(),this._map.render())}_findSnapTarget(t,e){const i=this._map,s=this._opts.snapSources??[this._opts.source],n=!1!==this._opts.snapToVertex,r=!1!==this._opts.snapToEdge;let a=this._snapThreshold,o=null,h=null;for(const l of s){const s=i.getSource(l);if(!s)continue;const c=s.getArcs();if(!c?.getVertexData)continue;const u=c.getVertexData();if(!u)continue;const p=u.xx,_=u.yy;if(n)for(let s=0;s<p.length;s++){const n=i.project(p[s],_[s]),r=Math.hypot(n[0]-t,n[1]-e);r<a&&(a=r,o=[p[s],_[s]],h="vertex")}r&&c.forEachSegment&&c.forEachSegment((s,n,r,l)=>{const c=i.project(r[s],l[s]),u=i.project(r[n],l[n]),p=ps([t,e],c,u);p.dist<a&&(a=p.dist,o=i.unproject(p.point[0],p.point[1]),h="edge")})}if(n)for(const s of this._vertices){const n=i.project(s[0],s[1]),r=Math.hypot(n[0]-t,n[1]-e);r<a&&(a=r,o=[s[0],s[1]],h="vertex")}return o?{coord:o,kind:h}:null}_commitFeature(){if(0===this._vertices.length)return;const t=this._map.getSource(this._opts.source);if(!t)return;const e=t.getDataset();if(!e)return;const i=this._resolveTargetLayer(e.layers);if(!i)return;const s=e.layers.indexOf(i);let n,r,a;if(i.shapes||(i.shapes=[]),"point"===this._opts.type)n=[this._vertices[0]],i.shapes.push(n);else{if(r="polygon"===this._opts.type?[...this._vertices,this._vertices[0]]:[...this._vertices],a=e.arcs,!a)return;n=[[this._appendArc(a,r)]],i.shapes.push(n)}let o=null;if(i.data){const t=i.data.getRecords?.();t&&(o={},t.push(o))}t.refreshDisplayArcs(),this._map.pushCommand(new cs({geometryType:this._opts.type,layer:i,source:t,appendedShape:n,appendedRecord:o,arcVertices:r,arcs:a}));const h=i.shapes.length-1,l=rt(i,s>=0?s:0);this._map.fire("feature_created",{id:h,source:this._opts.source,layer:l,geometryType:this._opts.type,properties:{}}),this._clearDrawState(),this._map.clearEditDrawState(),t.fire("data",{reason:"edit"})}_resolveTargetLayer(t){if(!t.length)return null;if(this._opts.sourceLayer)for(let e=0;e<t.length;e++){if(rt(t[e],e)===this._opts.sourceLayer)return t[e]}const e="polygon"===this._opts.type?"polygon":"polyline"===this._opts.type?"polyline":"point";for(const i of t)if(i.geometry_type===e)return i;return t[0]}_appendArc(t,e){const i=t.getVertexData(),s=i.xx,n=i.yy,r=i.nn,a=i.zz,o=s.length,h=r.length,l=e.length,c=new Float64Array(o+l),u=new Float64Array(o+l),p=new Int32Array(h+1);c.set(s),u.set(n),p.set(r);for(let t=0;t<l;t++)c[o+t]=e[t][0],u[o+t]=e[t][1];p[h]=l;let _=null;if(a){_=new Float64Array(o+l),_.set(a);for(let t=0;t<l;t++)_[o+t]=1/0}return t.updateVertexData(p,c,u,_),h}_updateDrawState(){this._map.setEditDrawState({vertices:[...this._vertices],cursorCoord:this._snapCoord||this._cursorCoord,snapCoord:this._snapCoord,snapKind:this._snapKind,geometryType:this._opts.type,drawColor:this._opts.drawColor||"#0078ff"})}_clearDrawState(){this._vertices=[],this._cursorCoord=null,this._snapCoord=null,this._snapKind=null}}function ps(t,e,i){const s=e[0],n=e[1],r=i[0],a=i[1],o=t[0],h=t[1],l=r-s,c=a-n,u=l*l+c*c;if(0===u){const t=o-s,e=h-n;return{point:[s,n],dist:Math.hypot(t,e)}}let p=((o-s)*l+(h-n)*c)/u;p<0?p=0:p>1&&(p=1);const _=s+p*l,d=n+p*c;return{point:[_,d],dist:Math.hypot(o-_,h-d)}}class _s{_map;name="transformFeature";_enabled=!1;_opts={};_translate=null;_affine=null;_lastMap=null;_prevAngle=0;_prevDist=1;_onKeyDownBound=t=>this._onKeyDown(t);constructor(t){this._map=t,this._map.on("editmodechange",t=>{"transform"!==t.mode&&this._enabled&&this._quietDisable()})}get _mode(){return this._opts.mode??"translate"}enable(){this._enabled||(this._enabled=!0,this._map.setEditMode("transform"),window.addEventListener("keydown",this._onKeyDownBound))}disable(){this._enabled&&(this._enabled=!1,this._cancelSession(),window.removeEventListener("keydown",this._onKeyDownBound),this._map.setEditMode("none"),this._map.render())}_quietDisable(){this._enabled=!1,this._cancelSession(),window.removeEventListener("keydown",this._onKeyDownBound),this._map.render()}isEnabled(){return this._enabled}setOptions(t){this._opts={...this._opts,...t}}getOptions(){return this._opts}_cancelSession(){this._translate&&(this._translate.cancel(),this._translate=null),this._affine&&(this._affine.cancel(),this._affine=null),this._lastMap=null}_onKeyDown(t){"Escape"===t.key&&(this._translate||this._affine)&&this._cancelSession()}handlePointer(t){if(!this._enabled)return"passthrough";if("down"===t.kind){if(0!==t.button)return"passthrough";const e=this._map.queryFeatures([t.point.x,t.point.y]);if(!e.length||!this._map.isSelected(e[0]))return"passthrough";const i=this._map.unproject(t.point.x,t.point.y);if("translate"===this._mode){if(this._translate=this._map.editSession.beginTranslateSession(this._opts.session),!this._translate)return"passthrough";this._lastMap=i}else{if(this._affine=this._map.editSession.beginAffineSession(void 0,this._opts.session),!this._affine)return"passthrough";const[t,e]=this._affine.origin;this._prevAngle=Math.atan2(i[1]-e,i[0]-t),this._prevDist=Math.hypot(i[0]-t,i[1]-e)||1}return"exclusive"}if("move"===t.kind){if(!this._translate&&!this._affine)return"passthrough";const e=this._map.unproject(t.point.x,t.point.y);if(this._translate)this._lastMap&&this._translate.move(e[0]-this._lastMap[0],e[1]-this._lastMap[1]),this._lastMap=e;else if(this._affine){const[t,i]=this._affine.origin;if("rotate"===this._mode){const s=Math.atan2(e[1]-i,e[0]-t),n=s-this._prevAngle;0!==n&&this._affine.applyDelta(Bt(n,t,i)),this._prevAngle=s}else{const s=Math.hypot(e[0]-t,e[1]-i)||1,n=s/this._prevDist;1!==n&&this._affine.applyDelta(Ut(n,n,t,i)),this._prevDist=s}}return"exclusive"}return"up"===t.kind&&(this._translate||this._affine)?(this._translate&&(this._translate.commit(),this._translate=null),this._affine&&(this._affine.commit(),this._affine=null),this._lastMap=null,"passthrough"):"passthrough"}}function ds(t){if(!t||"object"!=typeof t)return!1;const e=t;return"string"==typeof e.name&&"function"==typeof e.enable&&"function"==typeof e.disable&&"function"==typeof e.isEnabled&&"function"==typeof e.setOptions&&"function"==typeof e.getOptions&&"function"==typeof e.handlePointer}const fs=["lassoSelect","boxSelect","clickSelect","transformFeature","drawFeature","vertexEdit","dragPan"];class ms{_handlers=new Map;_element=null;_exclusive=null;_pointerSink=null;_onDown=t=>this._dispatch(this._norm(t,"down"));_onMove=t=>this._dispatch(this._norm(t,"move"));_onUp=t=>this._dispatch(this._norm(t,"up"));_onClick=t=>this._dispatch(this._norm(t,"click"));_onContextMenu=t=>this._dispatch(this._norm(t,"contextmenu"));_onDblClick=t=>this._dispatch(this._norm(t,"dblclick"));register(t){if(!ds(t))throw new Error("HandlerManager.register: argument is not a valid Handler");this._handlers.set(t.name,t),t._manager=this}isEnabledByName(t){const e=this._handlers.get(t);return!!e&&e.isEnabled()}get(t){return this._handlers.get(t)}applyInteractive(t){for(const e of["dragPan","scrollZoom"]){const i=this._handlers.get(e);i&&(t?i.enable():i.disable())}}attach(t){this.detach(),this._element=t,t.addEventListener("pointerdown",this._onDown),window.addEventListener("pointermove",this._onMove),window.addEventListener("pointerup",this._onUp),t.addEventListener("click",this._onClick),t.addEventListener("contextmenu",this._onContextMenu),t.addEventListener("dblclick",this._onDblClick)}detach(){this._element&&(this._element.removeEventListener("pointerdown",this._onDown),window.removeEventListener("pointermove",this._onMove),window.removeEventListener("pointerup",this._onUp),this._element.removeEventListener("click",this._onClick),this._element.removeEventListener("contextmenu",this._onContextMenu),this._element.removeEventListener("dblclick",this._onDblClick),this._element.style.cursor="",this._element=null,this._exclusive=null,this._pointerSink=null)}setPointerSink(t){this._pointerSink=t}_norm(t,e){const i=this._element.getBoundingClientRect();return{kind:e,point:{x:t.clientX-i.left,y:t.clientY-i.top},modifiers:{shift:t.shiftKey,ctrl:t.ctrlKey,alt:t.altKey,meta:t.metaKey},button:"button"in t?t.button:0,originalEvent:t}}_orderedEnabled(){const t=[];for(const e of fs){const i=this._handlers.get(e);i&&i.isEnabled()&&t.push(i)}return t}_dispatch(t){this._dispatchInner(t),this._applyCursor()}_dispatchInner(t){if(this._pointerSink&&("click"===t.kind||"move"===t.kind&&!this._exclusive)&&this._pointerSink(t),this._exclusive&&("move"===t.kind||"up"===t.kind)){return void("exclusive"!==this._exclusive.handlePointer(t)&&(this._exclusive=null))}for(const e of this._orderedEnabled()){const i=e.handlePointer(t);if("exclusive"===i)return void(this._exclusive=e);if("consumed"===i)return}}_applyCursor(){if(!this._element)return;let t=null;const e=this._exclusive;if(e&&e.isEnabled()&&(t=e.getCursor?.()??null),!t)for(const e of this._orderedEnabled()){const i=e.getCursor?.();if(i){t=i;break}}const i=t??"";this._element.style.cursor!==i&&(this._element.style.cursor=i)}refreshCursor(){this._applyCursor()}}class ys{_workerUrl;_WorkerCtor;_slots;_pending=new Map;_nextId=1;_rrCursor=0;_destroyed=!1;constructor(t){this._workerUrl=t.workerUrl,this._WorkerCtor=t.WorkerCtor??globalThis.Worker;const e=Math.max(1,Math.floor(t.poolSize??1));this._slots=Array.from({length:e},()=>({worker:null,epoch:0,pendingCount:0}))}run(t,e,i){return this.runWithId(t,e,i).promise}runWithId(t,e,i){const s=this.reserveId();return{id:s,promise:this.dispatchWithId(s,t,e,i)}}reserveId(){return this._nextId++}dispatchWithId(t,e,i,s,n){if(this._destroyed)return Promise.reject(new Error("MapshaperWorkerPool: destroyed"));const r=this._pickWorker();let a;try{a=this._ensureWorker(r)}catch(t){return Promise.reject(t)}const o=this._slots[r],h=o.epoch;return o.pendingCount++,new Promise((o,l)=>{this._pending.set(t,{resolve:o,reject:l,workerIndex:r,epoch:h});const c={id:t,type:"run",packed:i};"string"==typeof e?c.cmd=e:c.commands=e,s&&(c.inputFiles=s),n&&n.length>0?a.postMessage(c,n):a.postMessage(c)})}destroy(){this._destroyed||(this._destroyed=!0,this._terminateAll(new Error("MapshaperWorkerPool: destroyed")))}cancelAll(){this._destroyed||this._terminateAll(new Error("MapshaperWorkerPool: cancelled"))}isWorkerSpawned(){return this._slots.some(t=>null!==t.worker)}get poolSize(){return this._slots.length}_pickWorker(){let t=0,e=1/0,i=!1;const s=this._slots.length;for(let n=0;n<s;n++){const r=(this._rrCursor+n)%s,a=this._slots[r],o=null!==a.worker;(a.pendingCount<e||a.pendingCount===e&&o&&!i)&&(t=r,e=a.pendingCount,i=o)}return this._rrCursor=(t+1)%s,t}_terminateAll(t){for(const t of this._slots)t.worker&&(t.worker.terminate(),t.worker=null),t.epoch++,t.pendingCount=0;for(const{reject:e}of this._pending.values())e(t);this._pending.clear()}_ensureWorker(t){const e=this._slots[t];if(e.worker)return e.worker;if(!this._WorkerCtor)throw new Error("MapshaperWorkerPool: Worker constructor not available in this environment");const i=new this._WorkerCtor(this._workerUrl);return i.onmessage=e=>this._onMessage(t,e.data),i.onerror=e=>this._onWorkerError(t,e),e.worker=i,i}_onMessage(t,e){if(!e||"number"!=typeof e.id)return;const i=this._pending.get(e.id);if(!i)return;const s=this._slots[t];i.workerIndex===t&&i.epoch===s.epoch&&(this._pending.delete(e.id),s.pendingCount=Math.max(0,s.pendingCount-1),"ok"===e.type?i.resolve(e.packed):i.reject(new Error(e.message||"mapshaper worker error")))}_onWorkerError(t,e){const i=new Error(`mapshaper worker error: ${e.message||"unknown"}`),s=this._slots[t];s.worker&&(s.worker.terminate(),s.worker=null),s.epoch++,s.pendingCount=0;const n=[];for(const[e,i]of this._pending)i.workerIndex===t&&n.push(e);for(const t of n){const e=this._pending.get(t);this._pending.delete(t),e?.reject(i)}}}const gs=["feature:click","feature:hover","feature:enter","feature:leave"];function vs(t){return gs.includes(t)}function xs(t,e){return!t||(!t.source||t.source===e.source)&&!(t.layers&&!t.layers.includes(e.layer))}class bs{_host;_reg={"feature:click":[],"feature:hover":[],"feature:enter":[],"feature:leave":[]};_lastKey=null;_lastRef=null;_onceWrap=new Map;_onChange;constructor(t){this._host=t}setOnChange(t){this._onChange=t}hasListeners(){return gs.some(t=>this._reg[t].length>0)}on(t,e,i){vs(t)&&(this._reg[t].push({filter:e,cb:i}),this._onChange?.())}once(t,e,i){if(!vs(t))return;const s=e=>{this.off(t,i),i(e)};this._onceWrap.set(i,s),this._reg[t].push({filter:e,cb:s}),this._onChange?.()}off(t,e){if(!vs(t))return;const i=this._onceWrap.get(e);this._reg[t]=this._reg[t].filter(t=>t.cb!==e&&(void 0===i||t.cb!==i)),this._onceWrap.delete(e),this._onChange?.()}_hit(t,e){let i=[];for(const t of gs){for(const e of this._reg[t]){if(!e.filter?.layers){i=void 0;break}i.push(...e.filter.layers)}if(void 0===i)break}const s=this._host.queryFeatures([t,e],i&&i.length?{layers:i}:void 0);if(0===s.length)return null;const n=s[0];return{source:n.source,layer:n.layer,id:n.id}}_emit(t,e,i){const s=this._reg[t];if(0===s.length)return;let n=null;for(const r of s)if(xs(r.filter,e)){if(!n){const s=this._host.features.get(e);if(!s)return;n={type:t,feature:s,ref:e,point:{x:i.point.x,y:i.point.y},lngLat:this._host.unproject(i.point.x,i.point.y),modifiers:{...i.modifiers},originalEvent:i.originalEvent}}r.cb(n)}}dispatch(t){if(!this.hasListeners())return;if("click"===t.kind){const e=this._hit(t.point.x,t.point.y);return void(e&&this._emit("feature:click",e,t))}if("move"!==t.kind)return;const e=this._hit(t.point.x,t.point.y),i=e?`${(s=e).source}|${s.layer}|${s.id}`:null;var s;i!==this._lastKey&&(this._lastRef&&this._emit("feature:leave",this._lastRef,t),e&&this._emit("feature:enter",e,t),this._lastKey=i,this._lastRef=e),e&&this._emit("feature:hover",e,t)}}const ws=["mousemove"];function Ss(t){return ws.includes(t)}class Cs{_host;_reg={mousemove:[]};_onceWrap=new Map;_onChange;constructor(t){this._host=t}setOnChange(t){this._onChange=t}hasListeners(){return ws.some(t=>this._reg[t].length>0)}on(t,e){Ss(t)&&(this._reg[t].push(e),this._onChange?.())}once(t,e){if(!Ss(t))return;const i=i=>{this.off(t,e),e(i)};this._onceWrap.set(e,i),this._reg[t].push(i),this._onChange?.()}off(t,e){if(!Ss(t))return;const i=this._onceWrap.get(e);this._reg[t]=this._reg[t].filter(t=>t!==e&&(void 0===i||t!==i)),this._onceWrap.delete(e),this._onChange?.()}dispatch(t){if(!this.hasListeners())return;if("move"!==t.kind)return;const e=this._reg.mousemove,i={point:{x:t.point.x,y:t.point.y},mapCoord:this._host.unproject(t.point.x,t.point.y),originalEvent:t.originalEvent};for(const t of e.slice())t(i)}}class As{_sources;_getTransform;_getSize;_getInitialMX;_indexCache=new globalThis.Map;constructor(t,e,i,s){this._sources=t,this._getTransform=e,this._getSize=i,this._getInitialMX=s}prebuild(t){if(void 0!==t){const e=this._sources.get(t);return void(e&&this._prebuildSource(t,e))}for(const[t,e]of this._sources)this._prebuildSource(t,e)}clear(t){if(void 0===t)return void this._indexCache.clear();const e=`${t}|`,i=[];for(const t of this._indexCache.keys())t.startsWith(e)&&i.push(t);for(const t of i)this._indexCache.delete(t)}_prebuildSource(t,e){if("topology"!==e.type)return;const i=e.getLayers(),s=e.getArcs(),n=e.getDataset?.();for(let e=0;e<i.length;e++)this._getOrBuildIndex(t,e,i[e],s,n)}_getOrBuildIndex(t,e,i,s,n){const r=i?.shapes;if(!r||0===r.length)return null;const a=s?.size?.()??0,o=n?.editVersion??0,h=`${t}|${e}|${r.length}|${a}|${o}`,l=this._indexCache.get(h);if(void 0!==l)return l;const c=`${t}|${e}|`,u=[];for(const t of this._indexCache.keys())t!==h&&t.startsWith(c)&&u.push(t);for(const t of u)this._indexCache.delete(t);const p="point"===i.geometry_type,_=new E(r.length),d=[];for(let t=0;t<r.length;t++){const e=r[t];if(!e){_.add(0,0,0,0);continue}let i=1/0,n=1/0,a=-1/0,o=-1/0;if(p)for(const t of at(e))!t||t.length<2||(t[0]<i&&(i=t[0]),t[0]>a&&(a=t[0]),t[1]<n&&(n=t[1]),t[1]>o&&(o=t[1]));else if(s?.getSimpleShapeBbox){const t=e;for(let e=0;e<t.length;e++)s.getSimpleShapeBbox(t[e],d),d[0]<i&&(i=d[0]),d[1]<n&&(n=d[1]),d[2]>a&&(a=d[2]),d[3]>o&&(o=d[3])}i!==1/0?_.add(i,n,a,o):_.add(0,0,0,0)}_.finish();const f={index:_,shapeCount:r.length};return this._indexCache.set(h,f),f}query(t,e,i){const{width:s,height:n}=this._getSize(),r=Array.isArray(t),a=r?t:[[0,0],[s,n]],o=e||(r?{}:t)||{};if(Array.isArray(a)&&"number"==typeof a[0]){const t=a;return this._queryFeaturesAtPoint(t,o,i)}const h=a;return this._queryFeaturesInBBox(h,o,i)}_layerMatchesFilter(t,e,i){if(!i||0===i.length)return!0;const s=rt(t,e);return!!i.includes(s)||(!(!t?.name||!i.includes(t.name))||!(!t?.id||!i.includes(t.id)))}_unproject(t,e){return this._getTransform().unproject(t,e)}_getHitBuffer(t){return t/Math.abs(this._getTransform().mx||1)}_getZoomAdjustedHitBuffer(t,e){const i=this._getTransform(),s=this._getInitialMX(),n=Math.abs(i.mx)/(s||Math.abs(i.mx)||1);return n<1&&(t*=n),e>0&&t<e&&(t=e),this._getHitBuffer(t)}_findHitCandidates(t,e,i,s,n,r,a,o){const h=[],l={},c=[],u=i.shapes;if(!u)return h;const p=this._getOrBuildIndex(t,e,i,s,o),_=p?p.index.search(n-a,r-a,n+a,r+a):null,d=null!==_?_.length:u.length;for(let t=0;t<d;t++){const e=null!==_?_[t]:t,i=u[e];if(i)for(let t=0;t<i.length;t++){const o=i[t];if(s.getSimpleShapeBbox(o,c),n+a<c[0]||n-a>c[2]||r+a<c[1]||r-a>c[3])continue;let u=l[e];u||(u=l[e]={shape:[],id:e,dist:0},h.push(u)),u.shape.push(o)}}return h}_sortByDistance(e,i,s,n){const r=t.geom;for(const t of s)t.info=r.getPointToShapeInfo(e,i,t.shape,n),t.dist=t.info.distance;s.sort((t,e)=>t.dist-e.dist)}_pickNearestCandidates(t,e,i){const s=[];let n=0;for(let r=0;r<t.length;r++){const a=t[r];if(!(a.dist<i))break;if(0===r)n=a.dist;else if(a.dist-n>e)break;s.push(a)}return s}_pointTest(e,i,s,n,r,a){const o=t.geom,h=Math.abs(this._getTransform().mx||1);let l=-1,c=1/0,u=25;const p=s.shapes;if(!p)return[];const _=u/(h||1),d=this._getOrBuildIndex(e,i,s,void 0,a),f=d?d.index.search(n-_,r-_,n+_,r+_):null,m=null!==f?f.length:p.length;for(let t=0;t<m;t++){const e=null!==f?f[t]:t,i=p[e];if(i)for(const t of at(i)){if(!t)continue;const i=o.distance2D(n,r,t[0],t[1])*h;i>u||(i<u&&u>2&&(u=Math.max(2,i)),i<c&&(c=i,l=e))}}return-1===l?[]:[l]}_polylineTest(t,e,i,s,n,r,a,o){const h=this._getZoomAdjustedHitBuffer(15,2),l=a>=0?a:.05,c=this._getZoomAdjustedHitBuffer(l,0);let u=this._findHitCandidates(t,e,i,s,n,r,h,o);return this._sortByDistance(n,r,u,s),u=this._pickNearestCandidates(u,c,h),u.length?[u[0].id]:[]}_polygonTest(e,i,s,n,r,a,o){const h=t.geom,l=this._getZoomAdjustedHitBuffer(10,1),c=this._findHitCandidates(e,i,s,n,r,a,l,o);let u=[];for(const t of c)h.testPointInPolygon(r,a,t.shape,n)&&u.push(t);return c.length>0&&0===u.length?(this._sortByDistance(r,a,c,n),u=this._pickNearestCandidates(c,0,l)):u.length>1&&this._sortByDistance(r,a,u,n),u.length?[u[0].id]:[]}_polygonVertexTest(t,e,i,s,n,r,a){const o=this._polygonTest(t,e,i,s,n,r,a),h=this._polylineTest(t,e,i,s,n,r,5,a);return o.length?o:h}_queryFeaturesAtPoint(t,e,i){const s=this._getTransform(),n=[],[r,a]=this._unproject(t[0],t[1]),o=1/Math.abs(s.mx||1);for(const[t,s]of this._sources){const h=s.getLayers(),l=s.getDisplayArcs(),c=l?l.getScaledArcs(o):s.getArcs(),u=s.getDataset?.();for(let s=0;s<h.length;s++){const o=h[s];if(!o?.shapes)continue;if(!this._layerMatchesFilter(o,s,e.layers))continue;const l=rt(o,s);if(i&&!i.has(`${t}:${l}`))continue;const p=o.geometry_type;let _=[];if("point"===p?_=this._pointTest(t,s,o,r,a,u):"polyline"===p&&c?_=this._polylineTest(t,s,o,c,r,a,-1,u):"polygon"===p&&c&&(_=this._polygonVertexTest(t,s,o,c,r,a,u)),0!==_.length)for(const e of _){const i=o.data,s=i?.getRecordAt?.(e)??i?.getRecords?.()?.[e]??{};n.push({id:e,source:t,layer:l,geometryType:p||"unknown",properties:{...s}})}}}return n}_queryFeaturesInBBox(t,e,i){const s=this._getTransform(),n=[],[r,a]=t,o=this._unproject(r[0],r[1]),h=this._unproject(a[0],a[1]),l=Math.min(o[0],h[0]),c=Math.min(o[1],h[1]),u=Math.max(o[0],h[0]),p=Math.max(o[1],h[1]),_=1/Math.abs(s.mx||1);for(const[t,s]of this._sources){const r=s.getLayers(),a=s.getDisplayArcs(),o=a?a.getScaledArcs(_):s.getArcs(),h=s.getDataset?.();for(let s=0;s<r.length;s++){const a=r[s];if(!a?.shapes)continue;if(!this._layerMatchesFilter(a,s,e.layers))continue;const _=rt(a,s);if(i&&!i.has(`${t}:${_}`))continue;const d=a.geometry_type,f=a.data,m=[],y=this._getOrBuildIndex(t,s,a,o,h),g=y?y.index.search(l,c,u,p):null,v=null!==g?g.length:a.shapes.length;for(let e=0;e<v;e++){const i=null!==g?g[e]:e,s=a.shapes[i];if(!s)continue;let r=!1;if("point"===d)r=at(s).some(t=>t[0]>=l&&t[0]<=u&&t[1]>=c&&t[1]<=p);else if(o){const t=s;for(let e=0;e<t.length;e++)if(o.getSimpleShapeBbox(t[e],m),!(u<m[0]||l>m[2]||p<m[1]||c>m[3])){r=!0;break}}if(!r)continue;const h=f?.getRecordAt?.(i)??f?.getRecords?.()?.[i]??{};n.push({id:i,source:t,layer:_,geometryType:d||"unknown",properties:{...h}})}}}return n}}class Es{_host;constructor(t){this._host=t}get(t){const e=this._host.layers.resolve(t.source,t.layer);if(!e)return null;if(!Number.isInteger(t.id)||t.id<0)return null;const i=e.shapes??null;if(!i||t.id>=i.length)return null;const s=i[t.id],n=e.data?.getRecords?.()??[];return{ref:t,geometry:s,properties:Object.freeze({...n[t.id]??{}})}}*iter(t,e){const i=this._host.layers.resolve(t,e);if(!i||!i.shapes)return;const s=i.shapes,n=i.data?.getRecords?.()??[];for(let i=0;i<s.length;i++)yield{ref:{source:t,layer:e,id:i},geometry:s[i],properties:Object.freeze({...n[i]??{}})}}count(t,e){const i=this._host.layers.resolve(t,e);return i?.shapes?.length??0}}class Ms{_all=new globalThis.Set;get size(){return this._all.size}register(t){return this._all.add(t),()=>{this._all.delete(t)}}unregisterAll(){this._all.clear()}async runFor(t,e,i){if(0===this._all.size)return[];const s=[];for(const e of this._all)e.phase===t&&s.push(e);if(0===s.length)return[];const n=await Promise.allSettled(s.map(t=>t.run(e,i))),r=[];for(let t=0;t<s.length;t++){const e=s[t],i=n[t];let a;a="fulfilled"===i.status?i.value:{ok:!1,issues:[{severity:"error",message:`validator '${e.name}' threw: ${i.reason instanceof Error?i.reason.message:String(i.reason)}`}]},r.push({validator:e.name,report:a})}return r}}class ks{_highlighted=new globalThis.Map;_highlightStyle={color:"#ff7a00",width:2.2,radius:6,fill:!0};get size(){return this._highlighted.size}setHighlightedFeatures(t,e){this._highlighted.clear(),e&&(this._highlightStyle={...this._highlightStyle,...e});for(const e of t){const t=this._highlighted.get(e.source)||new globalThis.Map,i=t.get(e.layer)||new Set;i.add(e.id),t.set(e.layer,i),this._highlighted.set(e.source,t)}}clearHighlightedFeatures(){return 0!==this._highlighted.size&&(this._highlighted.clear(),!0)}setHighlightStyle(t){return this._highlightStyle={...this._highlightStyle,...t},this._highlighted.size>0}renderHighlights(t,e,i,s,n){if(0===this._highlighted.size)return;const r=this._highlightStyle.color||"#ff7a00",a=(this._highlightStyle.width??2.2)*s,o=this._highlightStyle.radius??6,h=!1!==this._highlightStyle.fill,l=1/Math.abs(i.mx||1);for(const[i,s]of e){const e=this._highlighted.get(i);if(!e)continue;const c=s.getLayers(),u=s.getDisplayArcs(),p=u?u.getScaledArcs(l):s.getArcs();for(let s=0;s<c.length;s++){const l=c[s];if(!l?.shapes)continue;const u=rt(l,s);if(n&&!n.has(`${i}:${u}`))continue;const _=e.get(u);if(!_||0===_.size)continue;const d=[];for(const t of _){const e=l.shapes[t];e&&d.push(e)}0!==d.length&&("point"===l.geometry_type?t.drawPoints(d,{color:r,radius:o,fill:h}):p&&t.drawPaths(d,{color:r,width:a},p))}}}}class Is{_byKey=new globalThis.Map;_size=0;get size(){return this._size}has(t){return this._byKey.get(t.source)?.get(t.layer)?.has(t.id)??!1}getAll(){const t=[];for(const[e,i]of this._byKey)for(const[s,n]of i)for(const i of n)t.push({source:e,layer:s,id:i});return t}getByLayer(t,e){const i=this._byKey.get(t)?.get(e);return i?Array.from(i):[]}clear(){if(0===this._size)return{added:[],removed:[],changed:!1};const t=this.getAll();return this._byKey.clear(),this._size=0,{added:[],removed:t,changed:!0}}apply(t,e){const i=Ls(t);if("replace"===e){const t=this._refSetSnapshot();this._byKey.clear(),this._size=0;for(const t of i)this._addOne(t);return Ts(t,this._refSetSnapshot())}const s=[],n=[];if("add"===e)for(const t of i)this._addOne(t)&&s.push(t);else for(const t of i)this.has(t)?this._removeOne(t)&&n.push(t):this._addOne(t)&&s.push(t);return{added:s,removed:n,changed:s.length>0||n.length>0}}remove(t){const e=[];for(const i of Ls(t))this._removeOne(i)&&e.push(i);return{added:[],removed:e,changed:e.length>0}}snapshot(){return this._refSetSnapshot()}restore(t){const e=this._refSetSnapshot();this._byKey.clear(),this._size=0;for(const e of t)this._addOne(Ps(e));return Ts(e,t)}_addOne(t){let e=this._byKey.get(t.source);e||(e=new globalThis.Map,this._byKey.set(t.source,e));let i=e.get(t.layer);return i||(i=new Set,e.set(t.layer,i)),!i.has(t.id)&&(i.add(t.id),this._size++,!0)}_removeOne(t){const e=this._byKey.get(t.source),i=e?.get(t.layer);return!!i?.has(t.id)&&(i.delete(t.id),this._size--,0===i.size&&(e.delete(t.layer),0===e.size&&this._byKey.delete(t.source)),!0)}_refSetSnapshot(){const t=new Set;for(const[e,i]of this._byKey)for(const[s,n]of i)for(const i of n)t.add(Ds(e,s,i));return t}}function Ds(t,e,i){return JSON.stringify([t,e,i])}function Ps(t){const[e,i,s]=JSON.parse(t);return{source:e,layer:i,id:s}}function Ts(t,e){const i=[],s=[];for(const s of e)t.has(s)||i.push(Ps(s));for(const i of t)e.has(i)||s.push(Ps(i));return{added:i,removed:s,changed:i.length>0||s.length>0}}function Ls(t){const e=new Set,i=[];for(const s of t){const t=Ds(s.source,s.layer,s.id);e.has(t)||(e.add(t),i.push(s))}return i}class Fs{_undoStack=[];_redoStack=[];_maxSize;_lastSkippedStale=!1;_captureBuffer=null;constructor(t={}){if(this._maxSize=t.maxSize??200,this._maxSize<1)throw new Error("EditHistory: maxSize must be >= 1")}push(t){if(this._captureBuffer)return void this._captureBuffer.push(t);const e=this._undoStack[this._undoStack.length-1];if(e&&!e.stale&&e.merge&&t.mergeable?.(e))return e.merge(t),void(this._redoStack.length=0);if(t.invalidatesPriorCommands){for(const t of this._undoStack)t.stale=!0;this._redoStack.length=0}this._undoStack.push(t),this._redoStack.length=0,this._undoStack.length>this._maxSize&&this._undoStack.shift()}beginCapture(){if(this._captureBuffer)throw new Error("EditHistory: nested capture not supported");this._captureBuffer=[]}endCapture(){const t=this._captureBuffer;return this._captureBuffer=null,t??[]}isCapturing(){return null!==this._captureBuffer}undo(){const t=this._undoStack.pop();return t?(t.stale?this._lastSkippedStale=!0:(t.undo(),this._lastSkippedStale=!1),this._redoStack.push(t),t):null}redo(){const t=this._redoStack.pop();return t?(t.stale?this._lastSkippedStale=!0:(t.do(),this._lastSkippedStale=!1),this._undoStack.push(t),t):null}clear(){this._undoStack.length=0,this._redoStack.length=0,this._lastSkippedStale=!1}canUndo(){return this._undoStack.length>0}canRedo(){return this._redoStack.length>0}size(){return this._undoStack.length}snapshot(){const t=this._undoStack[this._undoStack.length-1];let e=0;for(const t of this._undoStack)t.stale&&e++;const i={canUndo:this._undoStack.length>0,canRedo:this._redoStack.length>0,label:t?.label,staleCount:e,topIsStale:!!t?.stale};return this._lastSkippedStale&&(i.skippedStale=!0),i}}class Ns{_host;_datasetSnapshots=new globalThis.Map;_selectionSnapshot;_closed=!1;constructor(t){if(t._activeTransaction)throw new Error("Transaction: another transaction is already active");this._host=t,this._selectionSnapshot=t._selection.snapshot(),t._history.beginCapture(),t._activeTransaction=this}_captureFirstTouch(t,e){this._datasetSnapshots.has(t)||this._datasetSnapshots.set(t,e)}get isOpen(){return!this._closed}async commit(t){this._end();const e=this._host._history.endCapture();if(0===e.length)return ct;const i=new Rt(e,t);return this._host._history.push(i),this._host._fireHistoryChange(),ct}rollback(){this._end(),this._host._history.endCapture();for(const[t,e]of this._datasetSnapshots){const i=this._host._sources.get(t);i&&i.setDataset(e)}const t=this._host._selection.restore(this._selectionSnapshot);t.changed&&this._host._fireSelectionChange(t),this._host._fireHistoryChange(),this._host._scheduleRender()}_end(){if(this._closed)throw new Error("Transaction: already committed or rolled back");this._closed=!0,this._host._activeTransaction=null}}class Rs{opts;label="Delete feature";constructor(t){this.opts=t}do(){const{layer:t,featureId:e}=this.opts;if(!t.shapes)return;t.shapes.splice(e,1);const i=t.data?.getRecords?.();i?.splice(e,1)}undo(){const{layer:t,featureId:e,shape:i,record:s}=this.opts;if(t.shapes||(t.shapes=[]),t.shapes.splice(e,0,i),null!==s){const i=t.data?.getRecords?.();i?.splice(e,0,s)}}}class Os{opts;label;constructor(t){this.opts=t,this.label=`Delete ${t.snapshots.length} feature${1===t.snapshots.length?"":"s"}`}do(){const{layer:t,snapshots:e}=this.opts;if(!t.shapes||0===e.length)return;const i=new Set;for(const t of e)i.add(t.id);const s=t.shapes,n=new Array(s.length-i.size);let r=0;for(let t=0;t<s.length;t++)i.has(t)||(n[r++]=s[t]);t.shapes=n;const a=t.data?.getRecords?.();if(a){let t=0;for(let e=0;e<a.length;e++)i.has(e)||(a[t++]=a[e]);a.length=t}}undo(){const{layer:t,snapshots:e}=this.opts;t.shapes||(t.shapes=[]);const i=[...e].sort((t,e)=>t.id-e.id),s=t.data?.getRecords?.();for(const e of i)t.shapes.splice(e.id,0,e.shape),s&&null!==e.record&&s.splice(e.id,0,e.record)}}function Gs(t,e){const i=t||{};return{color:i["line-color"]||i["fill-color"]||"#333",width:(i["line-width"]??.8)*e}}function zs(t){const e=t||{};return{color:e["circle-color"]||"#333",radius:e["circle-radius"]??4,fill:!1!==e["circle-fill"]}}class qs extends U{_container;_canvasContainer;_canvas;_painter;_editOverlay;_viewport=new Z;_projection=new nt;_camera;_sources=new globalThis.Map;_layersCache;get layers(){return this._layersCache??(this._layersCache=new Et(this._sources))}_sourceListeners=new globalThis.Map;_layers=[];_effectiveLayersCache=[];_defaultLayersDirty=!0;_layerArcFlagsCache=new globalThis.Map;_handlers;_featureEvents;_pointerEvents;_scrollZoom;_dragPan;_clickSelect;_boxSelect;_lassoSelect;_vertexEdit;_drawFeature;_transformFeature;_pendingRender=0;_rafId=0;_controlContainers=new globalThis.Map;_controls=[];_highlightManager=new ks;_featureQuery;features;_selection=new Is;_history=new Fs;_activeTransaction=null;_validators=new Ms;get validators(){return this._validators}_historyShortcutUnbind=null;_ops;_editSession;_attributes;get ops(){return this._ops??(this._ops=new Nt(this))}get editSession(){return this._editSession??(this._editSession=new Jt(this))}get attributes(){return this._attributes??(this._attributes=new ne(this))}_editState=new re(t=>{t.modeChanged&&("none"===t.current.mode?this._dragPan?.enable():this._dragPan?.disable(),this.fire("editmodechange",{mode:t.current.mode})),this._scheduleRender()});_workerPool=null;_workerMode=!1;_workerThreshold=5e4;_workerRouting;_expressionPolicy="disabled";constructor(t){if(super(),"string"==typeof t.container){const e=document.getElementById(t.container);if(!e)throw new Error(`Container #${t.container} not found`);this._container=e}else this._container=t.container;this._canvasContainer=this._createCanvasContainer(),this._container.appendChild(this._canvasContainer),this._canvas=document.createElement("canvas"),this._canvas.style.position="absolute",this._canvas.style.top="0",this._canvas.style.left="0",this._canvasContainer.appendChild(this._canvas),this._painter=new ot(this._canvas),this._painter.setPixelRatio(window.devicePixelRatio||1),this._editOverlay=new ht(this._painter),this._updateSize(),this._viewport.onViewChange=()=>this.fire("move"),this._viewport.initZoomTween(),this._camera=new J({getCameraState:()=>this._viewport.getCameraState(),applyCameraState:(t,e)=>this._viewport.applyCameraState(t,e),scaleFromZoom:t=>this._projection.getScale(t),getViewportSize:()=>({width:this._viewport.width,height:this._viewport.height}),fire:(t,e)=>this.fire(t,e),requestRender:()=>this._scheduleRender(),cancelZoomAnimation:()=>this._viewport.cancelZoomAnimation()}),this._handlers=new ms,this._scrollZoom=new Ri(this._canvasContainer,()=>this.stop()),this._dragPan=new Gi(void 0,()=>this.stop()),this._handlers.register(this._dragPan),this._handlers.register(this._scrollZoom),this._clickSelect=new ts(this),this._boxSelect=new is(this),this._lassoSelect=new rs(this),this._handlers.register(this._clickSelect),this._handlers.register(this._boxSelect),this._handlers.register(this._lassoSelect),this._vertexEdit=new ls(this),this._handlers.register(this._vertexEdit),this._drawFeature=new us(this),this._handlers.register(this._drawFeature),this._transformFeature=new _s(this),this._handlers.register(this._transformFeature),this._handlers.attach(this._canvasContainer),!1===t.interactive&&this._handlers.applyInteractive(!1),this._featureQuery=new As(this._sources,()=>this._viewport.transform,()=>({width:this._viewport.width,height:this._viewport.height}),()=>this._viewport.initialMX),this.features=new Es(this);const e=this;this._featureEvents=new bs({queryFeatures:(t,i)=>e.queryFeatures(t,i),unproject:(t,i)=>e.unproject(t,i),get features(){return e.features}}),this._pointerEvents=new Cs({unproject:(t,i)=>e.unproject(t,i)}),this._featureEvents.setOnChange(()=>this._syncPointerSink()),this._pointerEvents.setOnChange(()=>this._syncPointerSink()),this._attachEventListeners(),this.on("move",()=>this._scheduleRender()),this.on("resize",()=>this._scheduleRender()),this.on("reset",()=>this.reset()),this.on("historychange",()=>this._runAfterCommitValidators()),this._expressionPolicy=t.expressionPolicy??"disabled",this._workerMode=t.useWorker??t.workerMode??!1,"number"==typeof t.workerThreshold&&t.workerThreshold>=0&&(this._workerThreshold=t.workerThreshold),this._workerRouting=t.workerRouting,(!1!==this._workerMode||t.workerPool)&&(t.workerPool?this._workerPool=t.workerPool:this._workerPool=new ys({workerUrl:t.workerUrl??"emap-worker.js",poolSize:t.workerPoolSize}))}cancelWorkerJobs(){this._workerPool?.cancelAll()}setExpressionPolicy(t){this._expressionPolicy=t}getExpressionPolicy(){return this._expressionPolicy??"disabled"}_allowExpressionEvaluation(t,e){return!t.some(t=>"string"==typeof t&&t.trim().length>0)||"trusted"===this.getExpressionPolicy()||(this.fire("error",{error:new Error(`${e}: expression evaluation is disabled`)}),!1)}on(t,e,i){if("mousemove"===t)return this._pointerEvents.on(t,e),this;if(t.startsWith("feature:")){const s=i??e,n=i?e:void 0;return this._featureEvents.on(t,n,s),this}return super.on(t,e)}off(t,e){return"mousemove"===t?(this._pointerEvents.off(t,e),this):t.startsWith("feature:")?(this._featureEvents.off(t,e),this):super.off(t,e)}once(t,e,i){if("mousemove"===t)return this._pointerEvents.once(t,e),this;if(t.startsWith("feature:")){const s=i??e,n=i?e:void 0;return this._featureEvents.once(t,n,s),this}return super.once(t,e)}_syncPointerSink(){this._featureEvents.hasListeners()||this._pointerEvents.hasListeners()?this._handlers.setPointerSink(t=>{this._featureEvents.dispatch(t),this._pointerEvents.dispatch(t)}):this._handlers.setPointerSink(null)}getCanvasContainer(){return this._canvasContainer}getEditMode(){return this._editState.mode}setEditMode(t){this._editState.setMode(t)}setEditVertexState(t){this._editState.setVertex(t)}clearEditVertexState(){this._editState.clearVertex()}setEditDrawState(t){this._editState.setDraw(t)}clearEditDrawState(){this._editState.clearDraw()}_attachEventListeners(){this._dragPan.on("pan",t=>{this._viewport.pan(t.dx,t.dy),this.fire("move")}),this._dragPan.on("panstart",()=>{this._viewport.cancelZoomAnimation()}),this._scrollZoom.on("mousewheel",t=>{this._viewport.applyWheelZoom(t.direction,t.multiplier,t.x,t.y),this.fire("move")})}_createCanvasContainer(){const t=document.createElement("div");t.style.position="relative",t.style.width="100%",t.style.height="100%",t.style.overflow="hidden",t.className="emap-canvas-container";const e=["top-left","top-right","bottom-left","bottom-right"];for(const i of e){const e=document.createElement("div");e.className=`emap-ctrl-${i}`,e.style.position="absolute",e.style.pointerEvents="none",e.style.zIndex="10";const[s,n]=i.split("-");e.style[s]="10px",e.style[n]="10px",e.style.display="flex",e.style.flexDirection="column",e.style.gap="8px";const r=t=>t.stopPropagation();for(const t of["click","mousedown","mouseup","dblclick","contextmenu"])e.addEventListener(t,r);e.addEventListener("wheel",r,{passive:!0}),t.appendChild(e),this._controlContainers.set(i,e)}return t}_updateSize(){const t=this._container.clientWidth,e=this._container.clientHeight;this._viewport.updateSize(t,e),this._painter.resize(t,e)}addSource(t,e){this._sources.set(t,e);const i=i=>{if(1===this._sources.size&&e.getCRS){const t=e.getCRS();t&&this._projection.crs!==t&&(this._projection.setCRS(t),this._viewport.setCRS(t),this.fire("crschange"))}this.fire("data",{sourceId:t,...i}),this._defaultLayersDirty=!0,this._layerArcFlagsCache.clear(),this._scheduleRender()};this._sourceListeners.set(t,i),e.on("data",i),e.getDataset&&e.getDataset()&&i({type:"data"})}removeSource(t){const e=this._sources.get(t);if(e){const i=this._sourceListeners.get(t);i&&(e.off("data",i),this._sourceListeners.delete(t)),this._sources.delete(t),this._defaultLayersDirty=!0,this._layerArcFlagsCache.delete(t);for(const e of this._layerArcFlagsCache.keys())e.startsWith(`${t}:`)&&this._layerArcFlagsCache.delete(e);this._scheduleRender()}}getSource(t){return this._sources.get(t)}async exportSnapshot(t={}){const e=!1!==t.compact,i=[],s=[];for(const[t,e]of this._sources){if("topology"!==e.type)continue;const n=e.getDataset?.();n&&(i.push(t),s.push(n))}const n=tt(),r=await n.exportDatasetsToPack(s,{compact:e});r.emap={version:1,sources:i.map(t=>({id:t}))};const a=n.pack(r);return new Blob([a],{type:"application/octet-stream"})}async loadSnapshot(t,e={}){const i=!1!==e.replace,s=e.idPrefix??"",n=e.defaultIds??[];let r;if(t instanceof Uint8Array)r=t;else if(t instanceof ArrayBuffer)r=new Uint8Array(t);else{if(!("undefined"!=typeof Blob&&t instanceof Blob))throw new Error("loadSnapshot: input must be Blob, Uint8Array, or ArrayBuffer");r=new Uint8Array(await t.arrayBuffer())}if(!function(t){if(!t||0===t.length)return!1;const e=t[0];return e>=128&&e<=143||222===e||223===e}(r))throw new Error("loadSnapshot: input does not look like a mapshaper .msx snapshot (expected msgpack map marker as the first byte)");const a=await tt().unpackSessionData(r),o=a.datasets??[],h=a.emap,l=h?.sources?.map(t=>t?.id).filter(t=>"string"==typeof t)??[],c=o.map((t,e)=>{const i=l[e],r=n[e]??`snapshot-${e}`;return s+(i??r)});if(!i)for(const t of c)if(this._sources.has(t))throw new Error(`loadSnapshot: source "${t}" already exists (pass { replace: true } to overwrite)`);this._history.clear(),this._fireSelectionChange(this._selection.clear()),this.fire("historychange");const u=[];for(let t=0;t<o.length;t++){const e=c[t];i&&this._sources.has(e)&&this.removeSource(e);const s=new Li(e);s.setDataset(o[t]),this.addSource(e,s),u.push(e)}return u}addLayer(t,e){if(!this._sources.has(t.source))throw new Error(`Source "${t.source}" not found`);if(this._layers.some(e=>e.id===t.id))throw new Error(`Layer "${t.id}" already exists`);if(e){const i=this._layers.findIndex(t=>t.id===e);if(-1===i)throw new Error(`Layer "${e}" not found`);this._layers.splice(i,0,{...t})}else this._layers.push({...t});this._defaultLayersDirty=!0,this._scheduleRender()}removeLayer(t){const e=this._layers.findIndex(e=>e.id===t);-1!==e&&(this._layers.splice(e,1),this._defaultLayersDirty=!0,this._scheduleRender())}getLayer(t){return this._layers.find(e=>e.id===t)}getLayers(){return[...this._layers]}setLayerVisibility(t,e){const i=this._layers.find(e=>e.id===t);i&&(i.layout||(i.layout={}),i.layout.visibility=e,this._scheduleRender())}setPaintProperty(t,e,i){const s=this._layers.find(e=>e.id===t);s&&(s.paint||(s.paint={}),s.paint[e]=i,this._scheduleRender())}moveLayer(t,e){const i=this._layers.findIndex(e=>e.id===t);if(-1===i)return;const[s]=this._layers.splice(i,1);if(e){const t=this._layers.findIndex(t=>t.id===e);-1===t?this._layers.push(s):this._layers.splice(t,0,s)}else this._layers.push(s);this._defaultLayersDirty=!0,this._scheduleRender()}_getEffectiveLayers(){if(this._layers.length>0)return this._layers;if(!this._defaultLayersDirty)return this._effectiveLayersCache;const t=[];for(const[e,i]of this._sources){const s=i.getLayers();if(0===s.length)t.push({id:`${e}:default`,type:"line",source:e,paint:{"line-color":"#333","line-width":.8}});else for(let i=0;i<s.length;i++){const n=s[i],r=rt(n,i),a=n.geometry_type;t.push({id:`${e}:${r}`,type:"point"===a?"circle":"line",source:e,"source-layer":r,paint:"point"===a?{"circle-color":"#333","circle-radius":4}:{"line-color":"#333","line-width":.8}})}}return this._effectiveLayersCache=t,this._defaultLayersDirty=!1,t}_resolveSourceLayer(t,e){const i=t.getLayers();if(!i.length)return null;if(!e)return i[0];for(let t=0;t<i.length;t++){if(rt(i[t],t)===e)return i[t]}return null}_getLayerArcFlags(t,e,i){if(!t||!t.shapes||!e)return null;let s=this._layerArcFlagsCache.get(i);if(s)return s;const n=e.size();s=new Uint8Array(n);const r=t.shapes;for(const t of r)if(t)for(const e of t)for(const t of e){s[t>=0?t:~t]=1}return this._layerArcFlagsCache.set(i,s),s}_getVisibleLayerKeys(){const t=new Set,e=this._getEffectiveLayers();for(const i of e){if("none"===i.layout?.visibility)continue;const e=this._sources.get(i.source);if(!e)continue;const s=this._resolveSourceLayer(e,i["source-layer"]);if(s){const n=e.getLayers().indexOf(s),r=rt(s,n>=0?n:0);t.add(`${i.source}:${r}`)}}return t}getPainter(){return this._painter}getCRS(){return this._projection.crs}setCRS(t){this._projection.setCRS(t),this._viewport.setCRS(t),this.fire("crschange")}async reproject(t){if(this._projection.crs===t)return;const e=await this._projection.reproject(t,this._sources);this._viewport.setCRS(t),this._viewport.clearInitialState(),e.hasBounds()&&this.setExtent(e),this.fire("crschange"),this.fire("data",{reason:"reproject"})}getCenter(){const t=this._viewport.transform,e=(this._viewport.width/2-t.bx)/t.mx,i=(this._viewport.height/2-t.by)/t.my;return this._projection.getCenter(e,i)}getZoom(){return this._projection.getZoom(Math.abs(this._viewport.transform.mx))}get dragPan(){return this._dragPan}get scrollZoom(){return this._scrollZoom}get clickSelect(){return this._clickSelect}get boxSelect(){return this._boxSelect}get lassoSelect(){return this._lassoSelect}get vertexEdit(){return this._vertexEdit}get drawFeature(){return this._drawFeature}get transformFeature(){return this._transformFeature}getTransform(){return this._viewport.transform}getExtent(){return this._viewport.extent}setExtent(t){this._viewport.setExtent(t),this.fire("move")}reset(){this._viewport.reset()}addControl(t,e="top-left"){const i=t.onAdd(this);i.style.pointerEvents="auto",this._controlContainers.get(e)?.appendChild(i),this._controls.push(t)}removeControl(t){t.onRemove(this);const e=this._controls.indexOf(t);-1!==e&&this._controls.splice(e,1)}zoomIn(){this._viewport.zoomIn()}zoomOut(){this._viewport.zoomOut()}jumpTo(t){return this._camera.jumpTo(t),this}setCenter(t){return this._camera.setCenter(t),this}setZoom(t){return this._camera.setZoom(t),this}easeTo(t){return this._camera.easeTo(t),this}panTo(t,e={}){return this._camera.panTo(t,e),this}panBy(t,e={}){return this._camera.panBy(t,e),this}zoomTo(t,e={}){return this._camera.zoomTo(t,e),this}flyTo(t){return this._camera.flyTo(t),this}fitBounds(t,e={}){return this._camera.fitBounds(t,e),this}stop(){return this._camera.stop(),this}_scheduleRender(){this._removed||(this._pendingRender++,0===this._rafId&&(this._rafId=requestAnimationFrame(()=>this._doRender())))}_doRender(){this._rafId=0,this._pendingRender>0&&(this._pendingRender=0,this.render())}render(){const t=this._viewport.transform;this._painter.setTransform(t),this._painter.clear();const e=this._viewport.getLineScale(),i=1/Math.abs(t.mx);this._renderLayers(i,e),this._renderHighlight(t,e),this._editOverlay.render(this._editState.mode,this._editState.vertex,this._editState.draw)}_renderLayers(t,e){const i=this._getEffectiveLayers();for(const s of i){if("none"===s.layout?.visibility)continue;const i=this._sources.get(s.source);if(!i)continue;const n=i.getDisplayArcs(),r=n?n.getScaledArcs(t):i.getArcs();if(r&&r.setRetainedInterval&&("function"!=typeof r.isFlat||!r.isFlat())){const e=i.getSimplifyFloor?.()??0;r.setRetainedInterval(Math.max(e,.5*t))}const a=this._resolveSourceLayer(i,s["source-layer"]),o=`${s.source}:${s["source-layer"]||"default"}`;if("line"===s.type&&r)this._renderLineLayer(s,a,r,o,e);else if("fill"===s.type&&r&&a?.shapes)this._renderFillLayer(s,a,r,o,e);else if("circle"===s.type&&a?.shapes){const t=zs(s.paint);this._painter.drawPoints(a.shapes,t)}}}_renderLineLayer(t,e,i,s,n){const r=Gs(t.paint,n);if(e?.shapes){const t=this._getLayerArcFlags(e,i,s),n=this._combineArcFilters(t,this._viewport.getArcFilter(i));this._painter.drawArcs(i,r,n)}else this._painter.drawArcs(i,r,this._viewport.getArcFilter(i))}_renderFillLayer(t,e,i,s,n){const r=t.paint,a=r?.["fill-color"]||"rgba(200, 200, 200, 0.4)",o=r?.["fill-opacity"],h=this._viewport.getArcFilter(i);this._painter.drawPolygonFill(e.shapes,i,a,h,o);const l=Gs(t.paint,n),c=this._getLayerArcFlags(e,i,s);this._painter.drawArcs(i,l,this._combineArcFilters(c,h))}_combineArcFilters(t,e){return t&&e?i=>1===t[i]&&e(i):t?e=>1===t[e]:e}_renderHighlight(t,e){const i=this._getVisibleLayerKeys();this._highlightManager.renderHighlights(this._painter,this._sources,t,e,i)}project(t,e){return this._viewport.project(t,e)}unproject(t,e){return this._viewport.unproject(t,e)}resize(){this._updateSize(),this._viewport.setExtent(this._viewport.extent),this.fire("resize")}queryFeatures(t,e){const i=this._getVisibleLayerKeys();return this._featureQuery.query(t,e,i)}prebuildSpatialIndex(t){this._featureQuery.prebuild(t)}clearSpatialIndex(t){this._featureQuery.clear(t)}_clearSpatialIndexesForSources(t){for(const e of t)this._featureQuery?.clear(e)}setHighlightedFeatures(t,e){this._highlightManager.setHighlightedFeatures(t,e),this._scheduleRender()}clearHighlightedFeatures(){this._highlightManager.clearHighlightedFeatures()&&this._scheduleRender()}setHighlightStyle(t){this._highlightManager.setHighlightStyle(t)&&this._scheduleRender()}select(t,e){const i=e?.mode??"replace",s=this._selection.apply(t,i);this._fireSelectionChange(s)}deselect(t){const e=this._selection.remove(t);this._fireSelectionChange(e)}clearSelection(){const t=this._selection.clear();this._fireSelectionChange(t)}getSelection(){return this._selection.getAll()}isSelected(t){return this._selection.has(t)}_fireSelectionChange(t){t.changed&&this.fire("selectionchange",{selected:this._selection.getAll(),added:t.added,removed:t.removed})}deleteSelected(){const t=this._selection.getAll();if(0===t.length)return!1;const e=new globalThis.Map;for(const i of t){let t=e.get(i.source);t||(t=new globalThis.Map,e.set(i.source,t));const s=t.get(i.layer)??[];s.push(i.id),t.set(i.layer,s)}const i=[];let s=0;for(const[t,n]of e){const e=this._sources.get(t);if(!e)continue;const r=e.getLayers();for(const[t,e]of n){let n=null;for(let e=0;e<r.length;e++)if(rt(r[e],e)===t){n=r[e];break}if(!n?.shapes)continue;const a=n.data?.getRecords?.(),o=[],h=new Set;for(const t of e){if(h.has(t))continue;h.add(t);const e=n.shapes[t];if(void 0===e)continue;const i=a?a[t]:null;o.push({id:t,shape:e,record:i??null})}if(0===o.length)continue;const l=new Os({layer:n,snapshots:o});l.do(),i.push(l),s+=o.length}}if(0===i.length)return!1;const n=new Rt(i,`Delete ${s} feature${s>1?"s":""}`);return this._history.push(n),this._fireHistoryChange(),this._invalidateShapeCachesForSources(e.keys()),this._fireSelectionChange(this._selection.clear()),this._scheduleRender(),!0}_invalidateShapeCachesForSources(t){for(const e of t){const t=`${e}:`;for(const e of this._layerArcFlagsCache.keys())e.startsWith(t)&&this._layerArcFlagsCache.delete(e);this._featureQuery?.clear(e)}}pushCommand(t){this._history.push(t),this._fireHistoryChange()}undo(){return!!this._history.undo()&&(this._fireHistoryChange(),this._invalidateAllShapeCaches(),this._scheduleRender(),!0)}redo(){return!!this._history.redo()&&(this._fireHistoryChange(),this._invalidateAllShapeCaches(),this._scheduleRender(),!0)}_invalidateAllShapeCaches(){this._layerArcFlagsCache.clear();for(const t of this._sources.keys())this._featureQuery?.clear(t)}canUndo(){return this._history.canUndo()}canRedo(){return this._history.canRedo()}clearHistory(){const t=this._history.canUndo()||this._history.canRedo();this._history.clear(),t&&this._fireHistoryChange()}beginTransaction(){return new Ns(this)}bindHistoryShortcuts(t){this._historyShortcutUnbind?.();const e=t??this._canvasContainer;e.hasAttribute("tabindex")||e.setAttribute("tabindex","-1");const i=t=>{if(!(t.ctrlKey||t.metaKey))return;const e="z"===t.key||"Z"===t.key,i="y"===t.key||"Y"===t.key;e&&!t.shiftKey?(t.preventDefault(),this.undo()):(e&&t.shiftKey||i)&&(t.preventDefault(),this.redo())};e.addEventListener("keydown",i);const s=()=>{e.removeEventListener("keydown",i),this._historyShortcutUnbind===s&&(this._historyShortcutUnbind=null)};return this._historyShortcutUnbind=s,s}_fireHistoryChange(){const t=this._history.snapshot();this.fire("historychange",t)}_runAfterCommitValidators(){if(0===this._validators.size)return;const t={label:this._history.snapshot().label??""};this._validators.runFor("after-commit",this,t).then(e=>{if(this._removed)return;const i=e.filter(t=>!t.report.ok);i.length>0&&this.fire("validationfailed",{results:i,label:t.label})})}_resolveLayer(t,e){return this.layers.resolve(t,e)}remove(){if(this._removed)return;this._removed=!0,0!==this._rafId&&(cancelAnimationFrame(this._rafId),this._rafId=0),this._pendingRender=0,this._handlers?.detach(),this._scrollZoom?.destroy(),this._historyShortcutUnbind?.(),this._historyShortcutUnbind=null,this._workerPool&&(this._workerPool.cancelAll(),this._workerPool.destroy(),this._workerPool=null);for(const[t,e]of this._sourceListeners){const i=this._sources.get(t);i?.off("data",e)}this._sourceListeners.clear();for(const t of this._sources.keys())this._featureQuery?.clear(t);this._layerArcFlagsCache.clear(),this._sources.clear();const t=this._controls??[];for(const e of[...t])try{e.onRemove(this)}catch(t){this.fire("error",{error:t})}t.length=0,this._controlContainers?.clear(),this._editState?.setMode("none"),this._container&&this._canvasContainer&&this._container.removeChild(this._canvasContainer)}_removed=!1}function js(t){return`"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/\0/g,"\\0")}"`}const Bs=/^[A-Za-z0-9_\-:.一-鿿][A-Za-z0-9_\-:. 一-鿿]*$/,Us=/^[A-Za-z0-9_\-.一-鿿][A-Za-z0-9_\-. 一-鿿]*$/;function $s(t){return"string"==typeof t&&t.length>0&&Bs.test(t)}function Vs(t){return"string"==typeof t&&t.length>0&&Us.test(t)}function Ws(t){for(const e of t)if(!Vs(e))return"string"==typeof e?e:String(e);return null}function Hs(t={}){const e=t.severity??"error";return{name:"topology",phase:"after-commit",async run(i){const s=tt(),n=t.sources??Array.from(i._sources.keys()),r=[];for(const a of n){const n=i._sources.get(a)?.getDataset();if(!n||!n.arcs)continue;const o={};void 0!==t.tolerance&&(o.tolerance=t.tolerance);const h=s.findSegmentIntersections(n.arcs,o);h.length>0&&r.push({severity:e,message:`${a}: ${h.length} self-intersection${1===h.length?"":"s"}`})}return{ok:0===r.length,issues:r}}}}class Ks{_map=null;_container=null;_options;constructor(t={}){this._options={showZoom:!0,showHome:!0,...t}}onAdd(t){return this._map=t,this._container=document.createElement("div"),this._container.className=`emap-ctrl emap-ctrl-group ${this._options.className||""}`,this._options.showZoom&&(this._createButton("zoom-in","+","Zoom In",()=>{this._map?.zoomIn()}),this._createButton("zoom-out","-","Zoom Out",()=>{this._map?.zoomOut()})),this._options.showHome&&this._createButton("home","⌂","Reset View",()=>{this._map?.fire("reset")}),this._container}_createButton(t,e,i,s){const n=document.createElement("button");n.className=`emap-ctrl-${t}`,n.type="button",n.title=i;const r=document.createElement("span");r.className="emap-ctrl-icon",r.textContent=e,n.appendChild(r),n.addEventListener("click",s),this._container?.appendChild(n)}onRemove(){this._container&&this._container.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._container=null}}class Zs{_map=null;_container=null;_options;_mousePosEl=null;_epsgEl=null;_onMoveBound;_onUpdateEPSGBound;_rafPending=!1;constructor(t={}){this._options={showMousePos:!0,showEPSG:!0,alignment:"left",...t},this._onMoveBound=this._onMove.bind(this),this._onUpdateEPSGBound=this._updateEPSG.bind(this)}onAdd(t){return this._map=t,this._container=document.createElement("div"),this._container.className=`emap-ctrl emap-status-ctrl emap-align-${this._options.alignment} ${this._options.className||""}`,this._options.showMousePos&&(this._mousePosEl=document.createElement("span"),this._mousePosEl.className="emap-status-mousepos",this._container.appendChild(this._mousePosEl)),this._options.showEPSG&&(this._epsgEl=document.createElement("span"),this._epsgEl.className="emap-status-epsg",this._container.appendChild(this._epsgEl),this._updateEPSG()),this._map.on("crschange",this._onUpdateEPSGBound),this._options.showMousePos&&this._map.on("mousemove",this._onMoveBound),this._container}_onMove(t){if(!this._map||!this._mousePosEl||!this._options.showMousePos)return;if(this._rafPending)return;this._rafPending=!0;const[e,i]=t.mapCoord;requestAnimationFrame(()=>{this._rafPending=!1,this._map&&this._mousePosEl&&(this._mousePosEl.textContent=` ${e.toFixed(4)}, ${i.toFixed(4)}`)})}_updateEPSG(){if(!this._map||!this._epsgEl)return;const t=this._map.getCRS();this._epsgEl.textContent=` | ${t}`}onRemove(){this._map&&(this._options.showMousePos&&this._map.off("mousemove",this._onMoveBound),this._map.off("crschange",this._onUpdateEPSGBound)),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._container=null}}const Xs=[{name:"OSM",url:"https://tile.openstreetmap.org/{z}/{x}/{y}.png",type:"raster"},{name:"CartoDB Light",url:"https://basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png",type:"raster"},{name:"CartoDB Dark",url:"https://basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png",type:"raster"}];class Js{_map=null;_container=null;_basemapContainer=null;_maplibre=null;_maplibreMap=null;_styles;_activeStyle=null;_isOn=!1;_syncBasemapBound;constructor(t={}){this._styles=t.styles||Xs,this._syncBasemapBound=this._syncBasemap.bind(this)}onAdd(t){return this._map=t,this._container=document.createElement("div"),this._container.className="emap-ctrl emap-basemap-ctrl",this._styles.forEach(t=>{const e=document.createElement("button");e.className="emap-basemap-btn",e.textContent=t.name,e.onclick=()=>this._toggleStyle(t),this._container.appendChild(e)}),this._createBasemapLayer(),this._map.on("move",this._syncBasemapBound),this._container}_createBasemapLayer(){if(!this._map)return;const t=this._map.getCanvasContainer();this._basemapContainer=document.createElement("div"),this._basemapContainer.className="emap-basemap",this._basemapContainer.style.cssText="\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n z-index: 0;\n display: none;\n ",t.insertBefore(this._basemapContainer,t.firstChild)}_toggleStyle(t){this._activeStyle===t?this._turnOff():this._showBasemap(t),this._updateButtons()}async _showBasemap(t){if(this._activeStyle=t,this._isOn=!0,!this._basemapContainer||!this._map)return;this._basemapContainer.style.display="block";const e=(this._map.getCRS()||"").toLowerCase();"webmercator"!==e&&"epsg:3857"!==e&&this._map.reproject&&await this._map.reproject("webmercator"),this._maplibreMap?(this._maplibreMap.resize(),this._setStyle(t),this._syncBasemap()):await this._initMapLibre(t)}async _initMapLibre(t){if(!this._basemapContainer||!this._map)return;const e=await this._loadMapLibre(),i=this._createMapLibreStyle(t);this._maplibreMap=new e.Map({container:this._basemapContainer,style:i,center:this._map.getCenter(),zoom:this._map.getZoom(),interactive:!1,attributionControl:!1,maxPitch:0,renderWorldCopies:!0}),this._maplibreMap.on("load",()=>{this._syncBasemap()})}async _loadMapLibre(){return this._maplibre||(this._maplibre=await import("maplibre-gl")),this._maplibre}_setStyle(t){if(!this._maplibreMap)return;const e=this._createMapLibreStyle(t);this._maplibreMap.setStyle(e)}_createMapLibreStyle(t){return"raster"===t.type||t.url.includes("{z}")?{version:8,sources:{"basemap-tiles":{type:"raster",tiles:[t.url],tileSize:512}},layers:[{id:"basemap-layer",type:"raster",source:"basemap-tiles",minzoom:0,maxzoom:22}]}:t.url}_syncBasemap(){if(this._maplibreMap&&this._map&&this._isOn)try{this._maplibreMap.jumpTo({center:this._map.getCenter(),zoom:this._map.getZoom()})}catch(t){console.warn("Sync basemap failed:",t)}}_turnOff(){this._activeStyle=null,this._isOn=!1,this._basemapContainer&&(this._basemapContainer.style.display="none")}_updateButtons(){if(!this._container)return;this._container.querySelectorAll(".emap-basemap-btn").forEach((t,e)=>{const i=this._styles[e]===this._activeStyle;t.classList.toggle("active",i)})}isOn(){return this._isOn}onRemove(){this._map&&this._map.off("move",this._syncBasemapBound),this._maplibreMap&&(this._maplibreMap.remove(),this._maplibreMap=null),this._basemapContainer?.parentNode&&this._basemapContainer.parentNode.removeChild(this._basemapContainer),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null}}class Ys{_map=null;_container=null;_btn=null;_opts;constructor(t={}){this._opts=t}onAdd(t){return this._map=t,void 0!==this._opts.polygonFillColor&&t.vertexEdit.setOptions({polygonFillColor:this._opts.polygonFillColor}),this._container=document.createElement("div"),this._container.className="emap-ctrl emap-ctrl-group",this._btn=document.createElement("button"),this._btn.className="emap-ctrl-edit",this._btn.type="button",this._btn.title="Edit Vertices",this._btn.innerHTML='<span class="emap-ctrl-icon">✏</span>',this._btn.addEventListener("click",()=>this._toggle()),this._container.appendChild(this._btn),this._container}onRemove(){this._map&&this._map.vertexEdit.isEnabled()&&this._map.vertexEdit.disable(),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._container=null,this._btn=null}_toggle(){if(!this._map)return;const t=this._map.vertexEdit;t.isEnabled()?(t.disable(),this._btn?.classList.remove("active")):(t.enable(),this._btn?.classList.add("active"))}}const Qs={polygon:"▢",polyline:"╱",point:"●"},tn={polygon:"Draw Polygon",polyline:"Draw Polyline",point:"Draw Point"};class en{_opts;_map=null;_container=null;_btn=null;constructor(t){this._opts=t}onAdd(t){this._map=t,this._container=document.createElement("div"),this._container.className="emap-ctrl emap-ctrl-group",this._btn=document.createElement("button"),this._btn.className="emap-ctrl-draw",this._btn.type="button",this._btn.title=tn[this._opts.type];const e=document.createElement("span");e.className="emap-ctrl-icon";const i=this._opts.icon??Qs[this._opts.type];"string"==typeof i?e.textContent=i:e.appendChild(i),this._btn.replaceChildren(e),this._btn.addEventListener("click",()=>this._toggle()),this._container.appendChild(this._btn);const{icon:s,...n}=this._opts;return t.drawFeature.setOptions(n),t.on("editmodechange",t=>{"draw"!==t.mode&&this._btn?.classList.remove("active")}),this._container}onRemove(){this._map&&this._map.drawFeature.isEnabled()&&this._map.drawFeature.disable(),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._container=null,this._btn=null}_toggle(){if(!this._map)return;const t=this._map.drawFeature;t.isEnabled()?(t.disable(),this._btn?.classList.remove("active")):(t.enable(),this._btn?.classList.add("active"))}}class sn{_container=null;_vertexEditControl;_drawControls=[];_options;constructor(t){this._options=t||{},this._vertexEditControl=new Ys,this._options.drawSource&&(this._drawControls=[new en({source:this._options.drawSource,sourceLayer:this._options.drawSourceLayer,type:"polygon"}),new en({source:this._options.drawSource,sourceLayer:this._options.drawSourceLayer,type:"polyline"}),new en({source:this._options.drawSource,sourceLayer:this._options.drawSourceLayer,type:"point"})])}onAdd(t){const e=this._vertexEditControl.onAdd(t);this._container=document.createElement("div"),this._container.className="emap-ctrl emap-ctrl-group emap-edit-toolbar";const i=e.querySelector("button");i&&this._container.appendChild(i);for(const e of this._drawControls){const i=e.onAdd(t).querySelector("button");i&&this._container.appendChild(i)}return this._container}onRemove(){this._vertexEditControl.onRemove();for(const t of this._drawControls)t.onRemove();this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._container=null}}class nn{_map=null;_container=null;_undoBtn=null;_redoBtn=null;_options;_onHistoryChange=null;constructor(t={}){this._options=t}onAdd(t){return this._map=t,this._container=document.createElement("div"),this._container.className=`emap-ctrl emap-ctrl-group ${this._options.className||""}`.trim(),this._undoBtn=this._createButton("undo","↶",this._options.undoTitle??"Undo (Ctrl+Z)",()=>{this._map?.undo()}),this._redoBtn=this._createButton("redo","↷",this._options.redoTitle??"Redo (Ctrl+Shift+Z)",()=>{this._map?.redo()}),this._setEnabled(t.canUndo(),t.canRedo()),this._onHistoryChange=t=>this._setEnabled(t.canUndo,t.canRedo),t.on("historychange",this._onHistoryChange),this._container}onRemove(){this._map&&this._onHistoryChange&&this._map.off("historychange",this._onHistoryChange),this._onHistoryChange=null,this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._map=null,this._container=null,this._undoBtn=null,this._redoBtn=null}_setEnabled(t,e){this._undoBtn&&(this._undoBtn.disabled=!t),this._redoBtn&&(this._redoBtn.disabled=!e)}_createButton(t,e,i,s){const n=document.createElement("button");n.className=`emap-ctrl-${t}`,n.type="button",n.title=i,n.disabled=!0;const r=document.createElement("span");return r.className="emap-ctrl-icon",r.textContent=e,n.appendChild(r),n.addEventListener("click",s),this._container?.appendChild(n),n}}class rn{_options;_enabled=!0;_handler=null;_container=null;constructor(t={}){this._options=t}onAdd(t){this._handler=t.boxSelect,this._handler.setOptions({layers:this._options.layers,dragThreshold:this._options.dragThreshold,style:this._options.style}),this._enabled&&this._handler.enable();const e=document.createElement("div");return e.className="emap-ctrl emap-box-select-anchor",e.style.width="0",e.style.height="0",e.style.pointerEvents="none",this._container=e,e}onRemove(){this._handler?.disable(),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._handler=null,this._container=null}disable(){this._enabled=!1,this._handler?.disable()}enable(){this._enabled=!0,this._handler?.enable()}isEnabled(){return this._handler?this._handler.isEnabled():this._enabled}}class an{_options;_enabled=!0;_handler=null;_container=null;constructor(t={}){this._options=t}onAdd(t){this._handler=t.lassoSelect,this._handler.setOptions({layers:this._options.layers,dragThreshold:this._options.dragThreshold,includeIntersecting:this._options.includeIntersecting,style:this._options.style}),this._enabled&&this._handler.enable();const e=document.createElement("div");return e.className="emap-ctrl emap-lasso-select-anchor",e.style.width="0",e.style.height="0",e.style.pointerEvents="none",this._container=e,e}onRemove(){this._handler?.disable(),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._handler=null,this._container=null}disable(){this._enabled=!1,this._handler?.disable()}enable(){this._enabled=!0,this._handler?.enable()}isEnabled(){return this._handler?this._handler.isEnabled():this._enabled}}const on=[{value:"",label:"weighted (default)"},{value:"weighted",label:"weighted"},{value:"visvalingam",label:"visvalingam"},{value:"dp",label:"dp (Douglas–Peucker)"}];class hn{_opts;_map=null;_container=null;_btn=null;_popup=null;_percentageInput=null;_percentageLabel=null;_methodSel=null;_keepShapes=null;_planar=null;_applyBtn=null;_statusEl=null;_onDocClick=null;_onDocKey=null;constructor(t){this._opts=t}onAdd(t){return this._map=t,this._container=document.createElement("div"),this._container.className="emap-ctrl emap-ctrl-group emap-ctrl-simplify-wrap",this._btn=document.createElement("button"),this._btn.type="button",this._btn.className="emap-ctrl-simplify",this._btn.innerHTML='<span class="emap-ctrl-icon">≈</span>',this._btn.title=this._opts.title??"Simplify geometry",this._btn.onclick=t=>{t.stopPropagation(),this._togglePopup()},this._container.appendChild(this._btn),this._popup=this._buildPopup(),this._container.appendChild(this._popup),this._container}onRemove(){this._teardownDocListeners(),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._container=null,this._btn=null,this._popup=null,this._percentageInput=null,this._percentageLabel=null,this._methodSel=null,this._keepShapes=null,this._planar=null,this._applyBtn=null,this._statusEl=null,this._map=null}_buildPopup(){const t=document.createElement("div");t.className="emap-simplify-popup",t.style.display="none",t.style.cssText+="\n position:absolute; top:36px; left:0; min-width:240px; padding:10px;\n background:#fff; border:1px solid #ccc; border-radius:4px;\n box-shadow:0 2px 8px rgba(0,0,0,.15); font-size:13px;\n z-index:10; color:#222;",t.onclick=t=>t.stopPropagation();const e=this._opts.initialPercentage??10,i=this._opts.initialMethod??"";return t.innerHTML=`\n <div style="margin-bottom:8px;">\n <label style="display:flex; align-items:center; gap:6px;">\n <span>Percentage:</span>\n <input type="range" min="0" max="100" step="0.1" value="${e}" style="flex:1;" />\n <span class="value" style="min-width:48px; text-align:right;">${e}%</span>\n </label>\n </div>\n <div style="margin-bottom:8px;">\n <label style="display:flex; align-items:center; gap:6px;">\n <span>Method:</span>\n <select style="flex:1;">\n ${on.map(t=>`<option value="${t.value}"${t.value===i?" selected":""}>${t.label}</option>`).join("")}\n </select>\n </label>\n </div>\n <div style="margin-bottom:8px; display:flex; gap:12px; flex-wrap:wrap;">\n <label><input type="checkbox" data-flag="keep-shapes" checked /> keep-shapes</label>\n <label><input type="checkbox" data-flag="planar" /> planar</label>\n </div>\n <div style="display:flex; gap:6px; align-items:center;">\n <button type="button" class="apply" style="padding:4px 12px;">Apply</button>\n <span class="status" style="opacity:.8; font-size:12px;"></span>\n </div>\n `,this._percentageInput=t.querySelector("input[type=range]"),this._percentageLabel=t.querySelector(".value"),this._methodSel=t.querySelector("select"),this._keepShapes=t.querySelector("input[data-flag=keep-shapes]"),this._planar=t.querySelector("input[data-flag=planar]"),this._applyBtn=t.querySelector("button.apply"),this._statusEl=t.querySelector(".status"),this._percentageInput.oninput=()=>{this._percentageLabel&&this._percentageInput&&(this._percentageLabel.textContent=`${this._percentageInput.value}%`)},this._applyBtn.onclick=()=>this._apply(),t}_togglePopup(){if(!this._popup)return;const t="none"===this._popup.style.display;this._popup.style.display=t?"block":"none",this._btn?.classList.toggle("active",t),t?(this._setupDocListeners(),this._setStatus("")):this._teardownDocListeners()}_setupDocListeners(){this._onDocClick=t=>{this._container&&!this._container.contains(t.target)&&this._togglePopup()},this._onDocKey=t=>{"Escape"===t.key&&this._togglePopup()},document.addEventListener("mousedown",this._onDocClick),document.addEventListener("keydown",this._onDocKey)}_teardownDocListeners(){this._onDocClick&&document.removeEventListener("mousedown",this._onDocClick),this._onDocKey&&document.removeEventListener("keydown",this._onDocKey),this._onDocClick=null,this._onDocKey=null}_setStatus(t){this._statusEl&&(this._statusEl.textContent=t)}async _apply(){if(!this._map||!this._percentageInput||!this._methodSel)return;const t=Number(this._percentageInput.value),e=this._methodSel.value,i={source:this._opts.source,percentage:t};this._opts.target&&(i.target=this._opts.target),e&&(i.method=e),this._keepShapes?.checked&&(i.keepShapes=!0),this._planar?.checked&&(i.planar=!0),this._applyBtn&&(this._applyBtn.disabled=!0),this._setStatus("Running…");try{const e=await this._map.ops.simplifyLayer(i);if(e?.ok)this._setStatus(`Simplified at ${t}%`);else{const t=e?.error,i=t?`${t.kind}${t.field?" field="+t.field:""}`:"unknown";this._setStatus(`Failed: ${i}`)}}catch(t){this._setStatus(`Error: ${t?.message??t}`)}finally{this._applyBtn&&(this._applyBtn.disabled=!1)}}}export{$ as AffineTransform,Js as BasemapControl,V as Bounds,rn as BoxSelectControl,is as BoxSelectHandler,Os as BulkFeatureDeleteCommand,ot as CanvasPainter,ts as ClickSelectHandler,Rt as CompositeCommand,Ei as DEFAULT_CRS,lt as DatasetReplaceCommand,Y as DefaultMapshaperAdapter,Gi as DragPanHandler,en as DrawFeatureControl,us as DrawFeatureHandler,Fs as EditHistory,ht as EditOverlayRenderer,sn as EditToolbar,qs as Emap,pt as Err,U as EventDispatcher,Es as FeatureAccessor,jt as FeatureAffineCommand,cs as FeatureCreateCommand,Rs as FeatureDeleteCommand,Yt as FeaturePropertyChangeCommand,As as FeatureQuery,qt as FeatureTranslateCommand,te as FieldAddCommand,ee as FieldRemoveCommand,ie as FieldRenameCommand,ms as HandlerManager,ks as HighlightManager,nn as HistoryControl,Vt as IDENTITY_MATRIX,an as LassoSelectControl,rs as LassoSelectHandler,ys as MapshaperWorkerPool,Ks as NavigationControl,ct as OK,nt as Projection,Ri as ScrollZoomHandler,Is as Selection,hn as SimplifyControl,Ht as SplitSharedArcsCommand,Zs as StatusControl,Li as TopologySource,Ns as Transaction,$ as Transform,_s as TransformFeatureHandler,Ms as ValidatorRegistry,hs as VertexDeleteCommand,Ys as VertexEditControl,ls as VertexEditHandler,os as VertexInsertCommand,as as VertexMoveCommand,Z as Viewport,zt as bumpEditVersion,$t as composeMatrix,Bi as featureMatchesLasso,Ws as findInvalidFieldName,tt as getDefaultMapshaperAdapter,Ii as inferFromPrj,Wt as invertMatrix,ds as isHandler,Ot as isPathLayer,Gt as isPointLayer,Vs as isValidFieldName,$s as isValidLayerName,ki as normalizeCrsString,ut as okValue,Kt as planSharedArcSplit,ji as pointInPolygon,js as quoteCliArg,Mi as resolveDatasetCRS,qi as resolveMode,zs as resolvePointStyle,Gs as resolveStrokeStyle,Bt as rotateMatrix,Ut as scaleMatrix,et as setDefaultMapshaperAdapter,Hs as topologyValidator};
|