Comparing version 1.0.5 to 1.0.6
@@ -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 n=0;n<o.length;n++){var l=o[n];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(t,l.key,l)}}return function(o,n,l){return n&&t(o.prototype,n),l&&t(o,l),o}}();module.exports=function(){function t(o,n){var l=arguments.length<=2||void 0===arguments[2]?5:arguments[2];_classCallCheck(this,t),this.lat=o,this.lon=n,this.precision=l}return _createClass(t,[{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,n){if(n=Number(n),-o>n||n>o)throw t+" must be between -"+o+" and +"+o;return n}},{key:"_convert_part_to_latlon",value:function(t,o){var n=this._locator.substr(2*t,1),l=this._locator.substr(2*t+1,1);this._lat+=10*this._l2n(l)/o,this._lon+=20*this._l2n(n)/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:"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,n=0;o>n;i++){var l=t.substr(2*n,2);if(0==n){if(null==l.match(/[a-rA-R]{2}/))return!1}else if(n%2==0){if(null==l.match(/[a-xA-X]{2}/))return!1}else if(null==l.match(/[0-9]{2}/))return!1;return!0}}},{key:"toLatLon",value:function(o){var n=new t;return n.locator=o,[n.lat,n.lon]}}]),t}(); | ||
"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}(); | ||
//# sourceMappingURL=maidenhead.js.map |
{ | ||
"name": "maidenhead", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"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", |
# Maidenhead | ||
The [Maidenhead Locator](https://en.wikipedia.org/wiki/Maidenhead_Locator_System) System is a geographic co-ordinate system used by amateur radio operators. | ||
Based on [Michael Graff's maidenhead gem](https://rubygems.org/gems/maidenhead) | ||
```js | ||
var Maidenhead = require('maidenhead'); | ||
var lattitude = 50.937658; //mandatory | ||
var longitude = 4.678045; //mandatory | ||
var latitude = 50.879087; //mandatory | ||
var longitude = 4.701169; //mandatory | ||
var precision = 6; //optional defaults to 5 | ||
var townhall = new Maidenhead(latitude, longitude, precision); | ||
var trainStation = new Maidenhead(50.881264, 4.715634, 6); | ||
var m = new Maidenhead(lattitude, longitude, precision); | ||
var maidenheadLocator = m.locator; | ||
var maidenheadLocator = townhall.locator; | ||
console.log('has valid locator: ' + Maidenhead.valid(maidenheadLocator)); | ||
console.log(m.lat, m.lon, maidenheadLocator); | ||
console.log(Maidenhead.toLatLon(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')); | ||
``` |
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
25075
5
15
26