ffffng/app/bower_components/geolib/dist/geolib.min.js

11 lines
10 KiB
JavaScript
Raw Normal View History

/*! geolib 2.0.9 by Manuel Bieh
* Library to provide geo functions like distance calculation,
* conversion of decimal coordinates to sexagesimal and vice versa, etc.
* WGS 84 (World Geodetic System 1984)
*
* @author Manuel Bieh
* @url http://www.manuelbieh.com/
* @version 2.0.9
* @license MIT
**/
!function(a,b){"use strict";function c(){}var d=Object.create(c.prototype,{version:{value:"2.0.9"},radius:{value:6378137},minLat:{value:-90},maxLat:{value:90},minLon:{value:-180},maxLon:{value:180},sexagesimalPattern:{value:/^([0-9]{1,3})°\s*([0-9]{1,3}(?:\.(?:[0-9]{1,2}))?)'\s*(([0-9]{1,3}(\.([0-9]{1,2}))?)"\s*)?([NEOSW]?)$/},measures:{value:Object.create(Object.prototype,{m:{value:1},km:{value:.001},cm:{value:100},mm:{value:1e3},mi:{value:1/1609.344},sm:{value:1/1852.216},ft:{value:100/30.48},"in":{value:100/2.54},yd:{value:1/.9144}})},prototype:{value:c.prototype},extend:{value:function(a,b){for(var c in a)("undefined"==typeof d.prototype[c]||b===!0)&&(d.prototype[c]=a[c])}}});"undefined"==typeof Number.prototype.toRad&&(Number.prototype.toRad=function(){return this*Math.PI/180}),"undefined"==typeof Number.prototype.toDeg&&(Number.prototype.toDeg=function(){return 180*this/Math.PI}),d.extend({decimal:{},sexagesimal:{},distance:null,getKeys:function(a){if("[object Array]"==Object.prototype.toString.call(a))return{longitude:a.length>=1?0:b,latitude:a.length>=2?1:b,elevation:a.length>=3?2:b};var c=function(b){var c;return b.every(function(b){return"object"!=typeof a?!0:a.hasOwnProperty(b)?function(){return c=b,!1}():!0}),c},d=c(["lng","lon","longitude"]),e=c(["lat","latitude"]),f=c(["alt","altitude","elevation","elev"]);return"undefined"==typeof e&&"undefined"==typeof d&&"undefined"==typeof f?b:{latitude:e,longitude:d,elevation:f}},getLat:function(a,b){return b===!0?a[this.getKeys(a).latitude]:this.useDecimal(a[this.getKeys(a).latitude])},latitude:function(a){return this.getLat.call(this,a)},getLon:function(a,b){return b===!0?a[this.getKeys(a).longitude]:this.useDecimal(a[this.getKeys(a).longitude])},longitude:function(a){return this.getLon.call(this,a)},getElev:function(a){return a[this.getKeys(a).elevation]},elevation:function(a){return this.getElev.call(this,a)},coords:function(a,b){var c={latitude:b===!0?a[this.getKeys(a).latitude]:this.useDecimal(a[this.getKeys(a).latitude]),longitude:b===!0?a[this.getKeys(a).longitude]:this.useDecimal(a[this.getKeys(a).longitude])},d=a[this.getKeys(a).elevation];return"undefined"!=typeof d&&(c.elevation=d),c},validate:function(a){var b=this.getKeys(a);if("undefined"==typeof b||"undefined"==typeof b.latitude||"undefined"===b.longitude)return!1;var c=a[b.latitude],d=a[b.longitude];return"undefined"==typeof c||!this.isDecimal(c)&&!this.isSexagesimal(c)?!1:"undefined"==typeof d||!this.isDecimal(d)&&!this.isSexagesimal(d)?!1:(c=this.useDecimal(c),d=this.useDecimal(d),c<this.minLat||c>this.maxLat||d<this.minLon||d>this.maxLon?!1:!0)},getDistance:function(a,b,c){c=Math.floor(c)||1;var e,f,g,h,i,j,k,l=this.coords(a),m=this.coords(b),n=6378137,o=6356752.314245,p=1/298.257223563,q=(m.longitude-l.longitude).toRad(),r=Math.atan((1-p)*Math.tan(parseFloat(l.latitude).toRad())),s=Math.atan((1-p)*Math.tan(parseFloat(m.latitude).toRad())),t=Math.sin(r),u=Math.cos(r),v=Math.sin(s),w=Math.cos(s),x=q,y=100;do{var z=Math.sin(x),A=Math.cos(x);if(j=Math.sqrt(w*z*w*z+(u*v-t*w*A)*(u*v-t*w*A)),0===j)return d.distance=0;e=t*v+u*w*A,f=Math.atan2(j,e),g=u*w*z/j,h=1-g*g,i=e-2*t*v/h,isNaN(i)&&(i=0);var B=p/16*h*(4+p*(4-3*h));k=x,x=q+(1-B)*p*g*(f+B*j*(i+B*e*(-1+2*i*i)))}while(Math.abs(x-k)>1e-12&&--y>0);if(0===y)return 0/0;var C=h*(n*n-o*o)/(o*o),D=1+C/16384*(4096+C*(-768+C*(320-175*C))),E=C/1024*(256+C*(-128+C*(74-47*C))),F=E*j*(i+E/4*(e*(-1+2*i*i)-E/6*i*(-3+4*j*j)*(-3+4*i*i))),G=o*D*(f-F);if(G=G.toFixed(3),"undefined"!=typeof this.elevation(a)&&"undefined"!=typeof this.elevation(b)){var H=Math.abs(this.elevation(a)-this.elevation(b));G=Math.sqrt(G*G+H*H)}return this.distance=Math.floor(Math.round(G/c)*c)},getDistanceSimple:function(a,b,c){c=Math.floor(c)||1;var e=Math.round(Math.acos(Math.sin(this.latitude(b).toRad())*Math.sin(this.latitude(a).toRad())+Math.cos(this.latitude(b).toRad())*Math.cos(this.latitude(a).toRad())*Math.cos(this.longitude(a).toRad()-this.longitude(b).toRad()))*this.radius);return d.distance=Math.floor(Math.round(e/c)*c)},getCenter:function(a){if(!a.length)return!1;var b,c,d=function(a){