1/** 2 * dms module 3 * @module dms 4 */ 5(function (dependencies, factory) { 6 if (typeof module === 'object' && typeof module.exports === 'object') { 7 var v = factory(require, exports); if (v !== undefined) module.exports = v; 8 } 9 else if (typeof define === 'function' && define.amd) { 10 define(dependencies, factory); 11 } 12})(["require", "exports"], function (require, exports) { 13 "use strict"; 14 // Just return a value to define the module export. 15 // This example returns an object, but the module 16 // can return a function as the exported value. 17 // Matches DMS DmsCoordinates 18 // http://regexpal.com/?flags=gim®ex=^%28-%3F\d%2B%28%3F%3A\.\d%2B%29%3F%29[%C2%B0%3Ad]%3F\s%3F%28%3F%3A%28\d%2B%28%3F%3A\.\d%2B%29%3F%29[%27%E2%80%B2%3A]%3F\s%3F%28%3F%3A%28\d%2B%28%3F%3A\.\d%2B%29%3F%29[%22%E2%80%B3]%3F%29%3F%29%3F\s%3F%28[NSEW]%29%3F&input=40%3A26%3A46N%2C79%3A56%3A55W%0A40%3A26%3A46.302N%2079%3A56%3A55.903W%0A40%C2%B026%E2%80%B247%E2%80%B3N%2079%C2%B058%E2%80%B236%E2%80%B3W%0A40d%2026%E2%80%B2%2047%E2%80%B3%20N%2079d%2058%E2%80%B2%2036%E2%80%B3%20W%0A40.446195N%2079.948862W%0A40.446195%2C%20-79.948862%0A40%C2%B0%2026.7717%2C%20-79%C2%B0%2056.93172%0A 19 var dmsRe = /^(-?\d+(?:\.\d+)?)[°:d]?\s?(?:(\d+(?:\.\d+)?)['â²Ê¹:]?\s?(?:(\d+(?:\.\d+)?)["â³Êº]?)?)?\s?([NSEW])?/i; 20 /** 21 * Removes the decimal part of a number without rounding up. 22 * @param {number} n 23 * @returns {number} 24 * @private 25 */ 26 function truncate(n) { 27 return n > 0 ? Math.floor(n) : Math.ceil(n); 28 } 29 var Dms = (function () { 30 /** 31 * @constructor module:dms.Dms 32 * @param {number} dd 33 * @param {string} longOrLat 34 */ 35 function Dms(dd, longOrLat) { 36 this._dd = dd; 37 this._hemisphere = /^[WE]|(?:lon)/i.test(longOrLat) ? dd < 0 ? "W" : "E" : dd < 0 ? "S" : "N"; 38 } 39 Object.defineProperty(Dms.prototype, "dd", { 40 /** 41 * Value in decimal degrees 42 * @member {number} 43 * @readonly 44 */ 45 get: function () { 46 return this._dd; 47 }, 48 enumerable: true, 49 configurable: true 50 }); 51 Object.defineProperty(Dms.prototype, "hemisphere", { 52 /** 53 * Hemisphere 54 * @member {string} 55 * @readonly 56 */ 57 get: function () { 58 return this._hemisphere; 59 }, 60 enumerable: true, 61 configurable: true 62 }); 63 /** 64 * Returns the DMS parts as an array. 65 * The first three elements of the returned array are numbers: 66 * degrees, minutes, and seconds respectively. The fourth 67 * element is a string indicating the hemisphere: "N", "S", "E", or "W". 68 * @returns {Array.<(number|string)>} 69 * @deprecated 70 */ 71 Dms.prototype.getDmsArray = function () { 72 return this.dmsArray; 73 }; 74 ; 75 Object.defineProperty(Dms.prototype, "dmsArray", { 76 /** 77 * Returns the DMS parts as an array. 78 * The first three elements of the returned array are numbers: 79 * degrees, minutes, and seconds respectively. The fourth 80 * element is a string indicating the hemisphere: "N", "S", "E", or "W". 81 * @returns {Array.<(number|string)>} 82 */ 83 get: function () { 84 var absDD = Math.abs(this._dd); 85 var degrees = truncate(absDD); 86 var minutes = truncate((absDD - degrees) * 60); 87 var seconds = (absDD - degrees - minutes / 60) * Math.pow(60, 2); 88 return [degrees, minutes, seconds, this._hemisphere]; 89 }, 90 enumerable: true, 91 configurable: true 92 }); 93 ; 94 /** 95 * Returns the DMS value as a string. 96 * @returns {string} 97 */ 98 Dms.prototype.toString = function () { 99 var dmsArray = this.getDmsArray(); 100 return dmsArray[0] + "\u00B0" + dmsArray[1] + "\u2032" + dmsArray[2] + "\u2033 " + dmsArray[3]; 101 }; 102 ; 103 return Dms; 104 }()); 105 exports.Dms = Dms; 106 /** 107 * @typedef {Object} DmsArrays 108 * @property {Array.<(number|string)>} longitude 109 * @property {Array.<(number|string)>} latitude 110 */ 111 var DmsCoordinates = (function () { 112 /** 113 * Represents a location on the earth in WGS 1984 coordinates. 114 * @constructor module:dms.DmsCoordinates 115 * @param {number} latitude - WGS 84 Y coordinates 116 * @param {number} longitude - WGS 84 X coordinates 117 * @throws {TypeError} - latitude and longitude must be numbers. 118 * @throws {RangeError} - latitude must be between -180 and 180, and longitude between -90 and 90. Neither can be NaN. 119 */ 120 function DmsCoordinates(lat, lon) { 121 this.lat = lat; 122 this.lon = lon;
123 if (typeof lat !== "number" || typeof lon !== "number") { 124 throw TypeError("The longitude and latitude parameters must be numbers."); 125 } 126 if (isNaN(lon) || lon < -180 || lon > 180) { 127 throw RangeError("longitude must be between -180 and 180"); 128 } 129 if (isNaN(lat) || lat < -90 || lat > 90) { 130 throw RangeError("latitude must be between -90 and 90"); 131 } 132 this._longitude = new Dms(lon, "long"); 133 this._latitude = new Dms(lat, "lat"); 134 } 135 Object.defineProperty(DmsCoordinates.prototype, "longitude", { 136 /** 137 * Longitude 138 * @type {module:dms.Dms} longitude - Longitude (X coordinate); 139 */ 140 get: function () { 141 return this._longitude; 142 }, 143 enumerable: true, 144 configurable: true 145 }); 146 Object.defineProperty(DmsCoordinates.prototype, "latitude", { 147 /** 148 * Latitude 149 * @type {module:dms.Dms} longitude - Latitude (y coordinate); 150 */ 151 get: function () { 152 return this._latitude; 153 }, 154 enumerable: true, 155 configurable: true 156 }); 157 /**
158 * Returns an object containing arrays containing degree / minute / second components. 159 * @returns {DmsArrays} 160 * @deprecated 161 */ 162 DmsCoordinates.prototype.getDmsArrays = function () { 163 return this.dmsArrays; 164 }; 165 ; 166 Object.defineProperty(DmsCoordinates.prototype, "dmsArrays", { 167 /** 168 * Returns an object containing arrays containing degree / minute / second components. 169 * @type {DmsArrays} 170 */ 171 get: function () { 172 return { 173 longitude: this.longitude.getDmsArray(), 174 latitude: this.latitude.getDmsArray() 175 }; 176 }, 177 enumerable: true, 178 configurable: true 179 }); 180 /** 181 * Returns the coordinates to a comma-separated string. 182 * @returns {string} 183 */ 184 DmsCoordinates.prototype.toString = function () { 185 return [this.latitude, this.longitude].join(", "); 186 }; 187 ; 188 return DmsCoordinates; 189 }()); 190 // Results of match will be [full coords string, Degrees, minutes (if any), seconds (if any), hemisphere (if any)] 191 // E.g., ["40:26:46.302N", "40", "26", "46.302", "N"] 192 // E.g., ["40.446195N", "40.446195", undefined, undefined, "N"] 193 /** 194 * A regular expression matching DMS coordinate. 195 * Example matches: 196 * E.g., ["40:26:46.302N", "40", "26", "46.302", "N"] 197 * E.g., ["40.446195N", "40.446195", undefined, undefined, "N"] 198 * @type {RegExp} 199 * @static 200 */ 201 DmsCoordinates.dmsRe = dmsRe; 202 Object.defineProperty(exports, "__esModule", { value: true }); 203 exports.default = DmsCoordinates; 204 /** 205 * Parses a Degrees Minutes Seconds string into a Decimal Degrees number. 206 * @param {string} dmsStr A string containing a coordinate in either DMS or DD format. 207 * @return {Number} If dmsStr is a valid coordinate string, the value in decimal degrees will be returned. Otherwise NaN will be returned. 208 */ 209 function parseDms(dmsStr) { 210 var output = NaN; 211 var dmsMatch = dmsRe.exec(dmsStr); 212 if (dmsMatch) { 213 var degrees = Number(dmsMatch[1]); 214 var minutes = typeof (dmsMatch[2]) !== "undefined" ? Number(dmsMatch[2]) / 60 : 0; 215 var seconds = typeof (dmsMatch[3]) !== "undefined" ? Number(dmsMatch[3]) / 3600 : 0; 216 var hemisphere = dmsMatch[4] || null; 217 if (hemisphere !== null && /[SW]/i.test(hemisphere)) { 218 degrees = Math.abs(degrees) * -1; 219 } 220 if (degrees < 0) { 221 output = degrees - minutes - seconds; 222 } 223 else { 224 output = degrees + minutes + seconds; 225 } 226 } 227 return output; 228 } 229 exports.parseDms = parseDms; 230}); 231//# sourceMappingURL=dms.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.