/* @preserve * gcoord 0.1.1, a JS library for transform geographical coordinates. * Copyright (c) 2018 Jiulong Hu */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.gcoord={})}(this,function(t){"use strict";var e="WGS84",r="GCJ02",n="BD09",o="EPSG3857";function i(t,e){if(t)throw new Error(e)}function a(t){return!isNaN(t)&&null!==t&&!u(t)}function u(t){return!!t&&"[object Array]"===Object.prototype.toString.call(t)}function l(){var t=arguments,e=t.length-1;return function(){for(var r=e,n=t[e].apply(this,arguments);r--;)n=t[r].call(this,n);return n}}var f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},s=function(){return function(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return function(t,e){var r=[],n=!0,o=!1,i=void 0;try{for(var a,u=t[Symbol.iterator]();!(n=(a=u.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{!n&&u.return&&u.return()}finally{if(o)throw i}}return r}(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),c=Math.sin,y=Math.cos,d=Math.sqrt,v=Math.abs,h=Math.PI,g=6378245,b=.006693421622965823;function m(t){var e=s(t,2),r=e[0],n=e[1];if(!S(r,n))return[r,n];for(var o=r,i=n,a=p([o,i]),u=a[0]-r,l=a[1]-n;v(u)>1e-6||v(l)>1e-6;)u=(a=p([o-=u,i-=l]))[0]-r,l=a[1]-n;return[o,i]}function p(t){var e=s(t,2),r=e[0],n=e[1];if(!S(r,n))return[r,n];var o,i,a,u,l,f,m,p,G,M,P,E,B,C=(B=300+(P=(o=r)-105)+2*(E=(i=n)-35)+.1*P*P+.1*P*E+.1*d(v(P)),B+=2*(20*c(6*P*h)+20*c(2*P*h))/3,B+=2*(20*c(P*h)+40*c(P/3*h))/3,a=B+=2*(150*c(P/12*h)+300*c(P/30*h))/3,M=2*(p=o-105)-100+3*(G=i-35)+.2*G*G+.1*p*G+.2*d(v(p)),M+=2*(20*c(6*p*h)+20*c(2*p*h))/3,M+=2*(20*c(G*h)+40*c(G/3*h))/3,u=M+=2*(160*c(G/12*h)+320*c(G*h/30))/3,f=c(l=i/180*h),m=d(f=1-b*f*f),[a=180*a/(g/m*y(l)*h),u=180*u/(g*(1-b)/(f*m)*h)]);return[r+C[0],n+C[1]]}function S(t,e){return i(void 0===t||void 0===e,"lon and lat are required"),i(!a(t)||!a(e),"lon and lat must be numbers"),t>=72.004&&t<=137.8347&&e>=.8293&&e<=55.8271}var G=Math.sin,M=Math.cos,P=Math.atan2,E=Math.sqrt,B=3e3*Math.PI/180;function C(t){var e=s(t,2),r=e[0]-.0065,n=e[1]-.006,o=E(r*r+n*n)-2e-5*G(n*B),i=P(n,r)-3e-6*M(r*B);return[o*M(i),o*G(i)]}function W(t){var e=s(t,2),r=e[0],n=e[1],o=E(r*r+n*n)+2e-5*G(n*B),i=P(n,r)+3e-6*M(r*B);return[o*M(i)+.0065,o*G(i)+.006]}var j=180/Math.PI,w=Math.PI/180,D=6378137,J=20037508.342789244;function k(t){return[t[0]*j/D,(.5*Math.PI-2*Math.atan(Math.exp(-t[1]/D)))*j]}function I(t){var e=Math.abs(t[0])<=180?t[0]:t[0]-360*(t[0]<0?-1:1),r=[D*e*w,D*Math.log(Math.tan(.25*Math.PI+.5*t[1]*w))];return r[0]>J&&(r[0]=J),r[0]<-J&&(r[0]=-J),r[1]>J&&(r[1]=J),r[1]<-J&&(r[1]=-J),r}var q={to:{GCJ02:p,BD09:l(W,p),EPSG3857:I}},O={to:{WGS84:m,BD09:W,EPSG3857:l(I,m)}},x={to:{WGS84:l(m,C),GCJ02:C,EPSG3857:l(I,m,C)}},A={to:{WGS84:k,GCJ02:l(p,k),BD09:l(W,p,k)}},L=(Object.freeze||Object)({WGS84:q,GCJ02:O,BD09:x,EPSG3857:A});t.transform=function(t,e,r){i(!t,"coordinate is required"),i(!e,"original coordinate system is required"),i(!r,"target coordinate system is required");var n=L[e];i(!n,"original coordinate system is invalid");var o=n.to[r];i(!o,"target coordinate system is invalid");var l=void 0===t?"undefined":f(t);i("string"!==l&&"object"!==l,"coordinate must be an geojson or an array of position"),"string"===l&&(t=JSON.parse(t));var s=!1;u(t)&&(i(t.length<2,"position must be at 2 numbers long"),i(!a(t[0])||!a(t[1]),"position must contain numbers"),s=!0);var c=null,y=o;return s?c=y(t):(function t(e,r,n){if(null!==e)for(var o=void 0,i=void 0,a=void 0,u=void 0,l=void 0,f=void 0,s=void 0,c=0,y=0,d=void 0,v=e.type,h="FeatureCollection"===v,g="Feature"===v,b=h?e.features.length:1,m=0;m