-
Notifications
You must be signed in to change notification settings - Fork 9
/
coordinates.js
89 lines (73 loc) · 2.18 KB
/
coordinates.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Generated by CoffeeScript 2.5.1
var CoordinateNumber, Coordinates, Validator;
Validator = require('./validator');
CoordinateNumber = require('./coordinate-number');
Coordinates = class Coordinates {
constructor(coordinateString) {
this.coordinates = coordinateString;
this.latitudeNumbers = null;
this.longitudeNumbers = null;
this.validate();
this.parse();
}
validate() {
var validator;
validator = new Validator();
return validator.validate(this.coordinates);
}
parse() {
this.groupCoordinateNumbers();
this.latitude = this.extractLatitude();
return this.longitude = this.extractLongitude();
}
groupCoordinateNumbers() {
var coordinateNumbers, numberCountEachCoordinate;
coordinateNumbers = this.extractCoordinateNumbers(this.coordinates);
numberCountEachCoordinate = coordinateNumbers.length / 2;
this.latitudeNumbers = coordinateNumbers.slice(0, numberCountEachCoordinate);
return this.longitudeNumbers = coordinateNumbers.slice((0 - numberCountEachCoordinate));
}
extractCoordinateNumbers(coordinates) {
return coordinates.match(/-?\d+(\.\d+)?/g);
}
extractLatitude() {
var latitude;
latitude = this.coordinateNumbersToDecimal(this.latitudeNumbers);
if (this.latitudeIsNegative()) {
latitude = latitude * -1;
}
return latitude;
}
extractLongitude() {
var longitude;
longitude = this.coordinateNumbersToDecimal(this.longitudeNumbers);
if (this.longitudeIsNegative()) {
longitude = longitude * -1;
}
return longitude;
}
coordinateNumbersToDecimal(coordinateNumbers) {
var coordinate, decimalCoordinate;
coordinate = new CoordinateNumber(coordinateNumbers);
coordinate.detectSpecialFormats();
decimalCoordinate = coordinate.toDecimal();
return decimalCoordinate;
}
latitudeIsNegative() {
var isNegative;
isNegative = this.coordinates.match(/s/i);
return isNegative;
}
longitudeIsNegative() {
var isNegative;
isNegative = this.coordinates.match(/w/i);
return isNegative;
}
getLatitude() {
return this.latitude;
}
getLongitude() {
return this.longitude;
}
};
module.exports = Coordinates;