Comparing version 1.0.6 to 1.0.7
@@ -1,2 +0,2 @@ | ||
"use strict";function _classCallCheck(t,o){if(!(t instanceof o))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function t(t,o){for(var a=0;a<o.length;a++){var n=o[a];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(o,a,n){return a&&t(o.prototype,a),n&&t(o,n),o}}();module.exports=function(){function t(o,a){var n=arguments.length<=2||void 0===arguments[2]?5:arguments[2];_classCallCheck(this,t),this.lat=o,this.lon=a,this.precision=n}return _createClass(t,[{key:"distanceTo",value:function(t){var o=arguments.length<=1||void 0===arguments[1]?"km":arguments[1],a=6371;switch(o){case"m":a*=1e3}var n=this._deg_to_rad(this.lat),e=this._deg_to_rad(this.lon),i=this._deg_to_rad(t.lat),r=this._deg_to_rad(t.lon),l=Math.cos(e-r)*Math.cos(n)*Math.cos(i)+Math.sin(n)*Math.sin(i),s=Math.atan(Math.abs(Math.sqrt(1-l*l)/l));return 0>l&&(s=Math.PI-s),a*s}},{key:"_deg_to_rad",value:function(t){return t/180*Math.PI}},{key:"_pad_locator",value:function(){for(var t=this._locator.length/2;5>t;)t%2==1?this._locator+="55":this._locator+="LL",t=this._locator.length/2}},{key:"_range_check",value:function(t,o,a){if(a=Number(a),-o>a||a>o)throw t+" must be between -"+o+" and +"+o;return a}},{key:"_convert_part_to_latlon",value:function(t,o){var a=this._locator.substr(2*t,1),n=this._locator.substr(2*t+1,1);this._lat+=10*this._l2n(n)/o,this._lon+=20*this._l2n(a)/o}},{key:"_calculate_field",value:function(){this.__lat=this.__lat/10+1e-7,this.__lon=this.__lon/20+1e-7,this._locator+=this._n2l(Math.floor(this.__lon)).toUpperCase()+this._n2l(Math.floor(this.__lat)).toUpperCase(),this.__precision-=1}},{key:"_calculate_values",value:function(){for(var t=0;t<this.__precision;t++)t%2==0?this._compute_locator(t,10):this._compute_locator(t,24)}},{key:"_compute_locator",value:function(t,o){this.__lat=(this.__lat-Math.floor(this.__lat))*o,this.__lon=(this.__lon-Math.floor(this.__lon))*o,t%2==0?this._locator+=""+Math.floor(this.__lon)+Math.floor(this.__lat):this._locator+=this._n2l(Math.floor(this.__lon))+this._n2l(Math.floor(this.__lat))}},{key:"_l2n",value:function(t){return t.match(/[0-9]+/)?parseInt(t):t.toLowerCase().charCodeAt(0)-97}},{key:"_n2l",value:function(t){return String.fromCharCode(97+t)}},{key:"lat",get:function(){return parseFloat(this._lat.toPrecision(6))},set:function(t){this._lat=this._range_check("lat",90,t)}},{key:"lon",get:function(){return parseFloat(this._lon.toPrecision(6))},set:function(t){this._lon=this._range_check("lon",180,t)}},{key:"precision",get:function(){return this._precision},set:function(t){this._precision=t}},{key:"locator",set:function(o){if(!t.valid(o))throw"Location is not a valid Maidenhead Locator System string";this._locator=o,this._lat=-90,this._lon=-180,this._pad_locator(),this._convert_part_to_latlon(0,1),this._convert_part_to_latlon(1,10),this._convert_part_to_latlon(2,240),this._convert_part_to_latlon(3,2400),this._convert_part_to_latlon(4,57600)},get:function(){return this._locator="",this.__lat=this.lat+90,this.__lon=this.lon+180,this.__precision=this.precision,this._calculate_field(),this._calculate_values(),this._locator}}],[{key:"valid",value:function(t){if("string"!=typeof t)return!1;if(t.length<2)return!1;if(t.length%2!==0)return!1;for(var o=t.length/2,a=0;o>a;i++){var n=t.substr(2*a,2);if(0==a){if(null==n.match(/[a-rA-R]{2}/))return!1}else if(a%2==0){if(null==n.match(/[a-xA-X]{2}/))return!1}else if(null==n.match(/[0-9]{2}/))return!1;return!0}}},{key:"toLatLon",value:function(o){var a=new t;return a.locator=o,[a.lat,a.lon]}}]),t}(); | ||
"use strict";function _classCallCheck(t,a){if(!(t instanceof a))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function t(t,a){for(var e=0;e<a.length;e++){var n=a[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(a,e,n){return e&&t(a.prototype,e),n&&t(a,n),a}}();module.exports=function(){function t(a,e){var n=arguments.length<=2||void 0===arguments[2]?5:arguments[2];_classCallCheck(this,t),this.lat=a,this.lon=e,this.precision=n}return _createClass(t,[{key:"distanceTo",value:function(t){var a=arguments.length<=1||void 0===arguments[1]?"km":arguments[1],e=6371;switch(a){case"m":e*=1e3}var n=this._deg_to_rad(this.lat),o=this._deg_to_rad(this.lon),r=this._deg_to_rad(t.lat),l=this._deg_to_rad(t.lon),s=Math.cos(o-l)*Math.cos(n)*Math.cos(r)+Math.sin(n)*Math.sin(r),i=Math.atan(Math.abs(Math.sqrt(1-s*s)/s));return 0>s&&(i=Math.PI-i),e*i}},{key:"bearingTo",value:function(t){var a=arguments.length<=1||void 0===arguments[1]?!1:arguments[1],e=this._deg_to_rad(this.lat),n=this._deg_to_rad(this.lon),o=this._deg_to_rad(t.lat),r=this._deg_to_rad(t.lon),l=Math.cos(n-r)*Math.cos(e)*Math.cos(o)+Math.sin(e)*Math.sin(o),s=Math.atan(Math.abs(Math.sqrt(1-l*l)/l));0>l&&(s=Math.PI-s);var i=Math.sin(r-n)*Math.cos(o)*Math.cos(e);l=Math.sin(o)-Math.sin(e)*Math.cos(s);var _=Math.atan(Math.abs(i/l));0>l&&(_=Math.PI-_),0>i&&(_=-_),0>_&&(_+=2*Math.PI);var h=Math.round(this._rad_to_deg(_));return a&&(h=this._compass_bearing(h)),h}},{key:"_compass_bearing",value:function(t){if(t>=0&&360>=t){var a=[{label:"N",start:0,end:11},{label:"NNE",start:11,end:33},{label:"NE",start:34,end:56},{label:"ENE",start:57,end:78},{label:"E",start:79,end:101},{label:"ESE",start:102,end:123},{label:"SE",start:124,end:146},{label:"SSE",start:147,end:168},{label:"S",start:169,end:191},{label:"SSW",start:192,end:213},{label:"SW",start:214,end:236},{label:"WSW",start:237,end:258},{label:"W",start:259,end:281},{label:"WNW",start:282,end:303},{label:"NW",start:304,end:326},{label:"NNW",start:327,end:348},{label:"N",start:349,end:360}],e=a.find(function(a,e,n){return t>a.start&&t<a.end?!0:!1});return e?e.label:""}}},{key:"_deg_to_rad",value:function(t){return t/180*Math.PI}},{key:"_rad_to_deg",value:function(t){return t/Math.PI*180}},{key:"_pad_locator",value:function(){for(var t=this._locator.length/2;5>t;)t%2==1?this._locator+="55":this._locator+="LL",t=this._locator.length/2}},{key:"_range_check",value:function(t,a,e){if(e=Number(e),-a>e||e>a)throw t+" must be between -"+a+" and +"+a;return e}},{key:"_convert_part_to_latlon",value:function(t,a){var e=this._locator.substr(2*t,1),n=this._locator.substr(2*t+1,1);this._lat+=10*this._l2n(n)/a,this._lon+=20*this._l2n(e)/a}},{key:"_calculate_field",value:function(){this.__lat=this.__lat/10+1e-7,this.__lon=this.__lon/20+1e-7,this._locator+=this._n2l(Math.floor(this.__lon)).toUpperCase()+this._n2l(Math.floor(this.__lat)).toUpperCase(),this.__precision-=1}},{key:"_calculate_values",value:function(){for(var t=0;t<this.__precision;t++)t%2==0?this._compute_locator(t,10):this._compute_locator(t,24)}},{key:"_compute_locator",value:function(t,a){this.__lat=(this.__lat-Math.floor(this.__lat))*a,this.__lon=(this.__lon-Math.floor(this.__lon))*a,t%2==0?this._locator+=""+Math.floor(this.__lon)+Math.floor(this.__lat):this._locator+=this._n2l(Math.floor(this.__lon))+this._n2l(Math.floor(this.__lat))}},{key:"_l2n",value:function(t){return t.match(/[0-9]+/)?parseInt(t):t.toLowerCase().charCodeAt(0)-97}},{key:"_n2l",value:function(t){return String.fromCharCode(97+t)}},{key:"lat",get:function(){return parseFloat(this._lat.toPrecision(6))},set:function(t){this._lat=this._range_check("lat",90,t)}},{key:"lon",get:function(){return parseFloat(this._lon.toPrecision(6))},set:function(t){this._lon=this._range_check("lon",180,t)}},{key:"precision",get:function(){return this._precision},set:function(t){this._precision=t}},{key:"locator",set:function(a){if(!t.valid(a))throw"Location is not a valid Maidenhead Locator System string";this._locator=a,this._lat=-90,this._lon=-180,this._pad_locator(),this._convert_part_to_latlon(0,1),this._convert_part_to_latlon(1,10),this._convert_part_to_latlon(2,240),this._convert_part_to_latlon(3,2400),this._convert_part_to_latlon(4,57600)},get:function(){return this._locator="",this.__lat=this.lat+90,this.__lon=this.lon+180,this.__precision=this.precision,this._calculate_field(),this._calculate_values(),this._locator}}],[{key:"valid",value:function(t){if("string"!=typeof t)return!1;if(t.length<2)return!1;if(t.length%2!==0)return!1;for(var a=t.length/2,e=0;a>e;i++){var n=t.substr(2*e,2);if(0==e){if(null==n.match(/[a-rA-R]{2}/))return!1}else if(e%2==0){if(null==n.match(/[a-xA-X]{2}/))return!1}else if(null==n.match(/[0-9]{2}/))return!1;return!0}}},{key:"toLatLon",value:function(a){var e=new t;return e.locator=a,[e.lat,e.lon]}}]),t}(); | ||
//# sourceMappingURL=maidenhead.js.map |
{ | ||
"name": "maidenhead", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "The Maidenhead Locator System is a geographic co-ordinate system used by amateur radio operators. Based on Michael Graff's maidenhead gem", | ||
@@ -5,0 +5,0 @@ "main": "./lib/maidenhead.js", |
@@ -15,13 +15,18 @@ # Maidenhead | ||
var townhall = new Maidenhead(latitude, longitude, precision); | ||
var townHall = new Maidenhead(latitude, longitude, precision); | ||
var trainStation = new Maidenhead(50.881264, 4.715634, 6); | ||
var library = new Maidenhead(); | ||
library.locator = 'JO20iu16ti'; | ||
var maidenheadLocator = townhall.locator; | ||
var maidenheadLocator = townHall.locator; | ||
console.log('has valid locator: ' + Maidenhead.valid(maidenheadLocator)); | ||
console.log("latitude: %s, longitude: %s, Maidenhead: %s", townhall.lat, townhall.lon, maidenheadLocator); | ||
console.log("latitude: %s, longitude: %s, Maidenhead: %s", townHall.lat, townHall.lon, maidenheadLocator); | ||
console.log("[lat, lon] = ", Maidenhead.toLatLon(maidenheadLocator)); | ||
console.log("distance to train station in M: %s", townhall.distanceTo(trainStation, 'm')); | ||
console.log("distance to train station in M from town hall: %s", townHall.distanceTo(trainStation, 'm')); | ||
console.log("bearing to library station from town hall: %s degrees", townHall.bearingTo(library)); | ||
console.log("compass bearing to library station from town hall: %s ", townHall.bearingTo(library, true)); | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34093
20
31