var pi=3.14159265358979,sm_a=6378137,sm_b=6356752.314,sm_EccSquared=0.00669437999013,UTMScaleFactor=0.9996;function degToRad(a){return a/180*pi}function radToDeg(a){return a/pi*180}function utmLatZone(a){return"CDEFGHJKLMNPQRSTUVWX".charAt(Math.floor((a+80)/8))}function utmLonZone(a){return Math.floor((a+180)/6)+1}
function arcLengthOfMeridian(a){var d,i,g,c,b;b=(sm_a-sm_b)/(sm_a+sm_b);d=(sm_a+sm_b)/2*(1+Math.pow(b,2)/4+Math.pow(b,4)/64);i=-3*b/2+9*Math.pow(b,3)/16+-3*Math.pow(b,5)/32;g=15*Math.pow(b,2)/16+-15*Math.pow(b,4)/32;c=-35*Math.pow(b,3)/48+105*Math.pow(b,5)/256;b=315*Math.pow(b,4)/512;return d*(a+i*Math.sin(2*a)+g*Math.sin(4*a)+c*Math.sin(6*a)+b*Math.sin(8*a))}function utmCentralMeridian(a){return degToRad(-183+a*6)}
function footpointLatitude(a){var d,i,g,c;c=(sm_a-sm_b)/(sm_a+sm_b);d=(sm_a+sm_b)/2*(1+Math.pow(c,2)/4+Math.pow(c,4)/64);a=a/d;d=3*c/2+-27*Math.pow(c,3)/32+269*Math.pow(c,5)/512;i=21*Math.pow(c,2)/16+-55*Math.pow(c,4)/32;g=151*Math.pow(c,3)/96+-417*Math.pow(c,5)/128;c=1097*Math.pow(c,4)/512;return a+d*Math.sin(2*a)+i*Math.sin(4*a)+g*Math.sin(6*a)+c*Math.sin(8*a)}
function mapLatLonToXY(a,d,i,g){var c,b,f,e,j,h,k;b=(Math.pow(sm_a,2)-Math.pow(sm_b,2))/Math.pow(sm_b,2)*Math.pow(Math.cos(a),2);c=Math.pow(sm_a,2)/(sm_b*Math.sqrt(1+b));f=Math.tan(a);e=f*f;d=d-i;i=1-e+b;j=5-e+9*b+4*b*b;h=5-18*e+e*e+14*b-58*e*b;b=61-58*e+e*e+270*b-330*e*b;k=61-479*e+179*e*e-e*e*e;e=1385-3111*e+543*e*e-e*e*e;g[0]=c*Math.cos(a)*d+c/6*Math.pow(Math.cos(a),3)*i*Math.pow(d,3)+c/120*Math.pow(Math.cos(a),5)*h*Math.pow(d,5)+c/5040*Math.pow(Math.cos(a),7)*k*Math.pow(d,7);g[1]=arcLengthOfMeridian(a)+
f/2*c*Math.pow(Math.cos(a),2)*Math.pow(d,2)+f/24*c*Math.pow(Math.cos(a),4)*j*Math.pow(d,4)+f/720*c*Math.pow(Math.cos(a),6)*b*Math.pow(d,6)+f/40320*c*Math.pow(Math.cos(a),8)*e*Math.pow(d,8)}
function mapXYToLatLon(a,d,i,g){var c,b,f,e,j,h,k,l,m,n,o,p,q,r,s,t;d=footpointLatitude(d);e=(Math.pow(sm_a,2)-Math.pow(sm_b,2))/Math.pow(sm_b,2);l=Math.cos(d);f=e*Math.pow(l,2);b=c=Math.pow(sm_a,2)/(sm_b*Math.sqrt(1+f));j=Math.tan(d);h=j*j;k=h*h;e=1/(b*l);b*=c;m=j/(2*b);b*=c;n=1/(6*b*l);b*=c;o=j/(24*b);b*=c;p=1/(120*b*l);b*=c;q=j/(720*b);b*=c;l=1/(5040*b*l);b*=c;c=j/(40320*b);b=-1-f;j=-1-2*h-f;r=5+3*h+6*f-6*h*f-3*f*f-9*h*f*f;s=5+28*h+24*k+6*f+8*h*f;f=-61-90*h-45*k-107*f+162*h*f;t=-61-662*h-1320*
k-720*k*h;h=1385+3633*h+4095*k+1575*k*h;g[0]=d+m*b*a*a+o*r*Math.pow(a,4)+q*f*Math.pow(a,6)+c*h*Math.pow(a,8);g[1]=i+e*a+n*j*Math.pow(a,3)+p*s*Math.pow(a,5)+l*t*Math.pow(a,7)}function latLonToUTMXY(a,d,i,g){mapLatLonToXY(a,d,utmCentralMeridian(i),g);g[0]=g[0]*UTMScaleFactor+5E5;g[1]*=UTMScaleFactor;if(g[1]<0)g[1]+=1E7;return i}function utmXYToLatLon(a,d,i,g,c){a-=5E5;a/=UTMScaleFactor;if(g)d-=1E7;d/=UTMScaleFactor;i=utmCentralMeridian(i);mapXYToLatLon(a,d,i,c)};

