/
Cartographic.js
211 lines (195 loc) · 7.93 KB
/
Cartographic.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*global define*/
define([
'./defaultValue',
'./DeveloperError',
'./freezeObject',
'./Math'
], function(
defaultValue,
DeveloperError,
freezeObject,
CesiumMath) {
"use strict";
/**
* A position defined by longitude, latitude, and height.
* @alias Cartographic
* @constructor
*
* @param {Number} [longitude=0.0] The longitude, in radians.
* @param {Number} [latitude=0.0] The latitude, in radians.
* @param {Number} [height=0.0] The height, in meters, above the ellipsoid.
*
* @see Ellipsoid
*/
var Cartographic = function(longitude, latitude, height) {
/**
* The longitude, in radians.
* @type Number
*/
this.longitude = defaultValue(longitude, 0.0);
/**
* The latitude, in radians.
* @type Number
*/
this.latitude = defaultValue(latitude, 0.0);
/**
* The height, in meters, above the ellipsoid.
* @type Number
*/
this.height = defaultValue(height, 0.0);
};
/**
* Creates a new Cartographic instance from longitude and latitude
* specified in degrees. The values in the resulting object will
* be in radians.
* @memberof Cartographic
*
* @param {Number} [longitude=0.0] The longitude, in degrees.
* @param {Number} [latitude=0.0] The latitude, in degrees.
* @param {Number} [height=0.0] The height, in meters, above the ellipsoid.
* @param {Cartographic} [result] The object onto which to store the result.
* @return {Cartographic} The modified result parameter or a new Cartographic instance if one was not provided.
*/
Cartographic.fromDegrees = function(longitude, latitude, height, result) {
longitude = CesiumMath.toRadians(defaultValue(longitude, 0.0));
latitude = CesiumMath.toRadians(defaultValue(latitude, 0.0));
height = defaultValue(height, 0.0);
if (typeof result === 'undefined') {
return new Cartographic(longitude, latitude, height);
}
result.longitude = longitude;
result.latitude = latitude;
result.height = height;
return result;
};
/**
* Duplicates a Cartographic instance.
* @memberof Cartographic
*
* @param {Cartographic} cartographic The cartographic to duplicate.
* @param {Cartographic} [result] The object onto which to store the result.
* @return {Cartographic} The modified result parameter or a new Cartographic instance if one was not provided.
*
* @exception {DeveloperError} cartographic is required.
*/
Cartographic.clone = function(cartographic, result) {
if (typeof cartographic === 'undefined') {
throw new DeveloperError('cartographic is required');
}
if (typeof result === 'undefined') {
return new Cartographic(cartographic.longitude, cartographic.latitude, cartographic.height);
}
result.longitude = cartographic.longitude;
result.latitude = cartographic.latitude;
result.height = cartographic.height;
return result;
};
/**
* Compares the provided cartographics componentwise and returns
* <code>true</code> if they are equal, <code>false</code> otherwise.
* @memberof Cartographic
*
* @param {Cartographic} [left] The first cartographic.
* @param {Cartographic} [right] The second cartographic.
* @return {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
*/
Cartographic.equals = function(left, right) {
return (left === right) ||
((typeof left !== 'undefined') &&
(typeof right !== 'undefined') &&
(left.longitude === right.longitude) &&
(left.latitude === right.latitude) &&
(left.height === right.height));
};
/**
* Compares the provided cartographics componentwise and returns
* <code>true</code> if they are within the provided epsilon,
* <code>false</code> otherwise.
* @memberof Cartographic
*
* @param {Cartographic} [left] The first cartographic.
* @param {Cartographic} [right] The second cartographic.
* @param {Number} epsilon The epsilon to use for equality testing.
* @return {Boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
*
* @exception {DeveloperError} epsilon is required and must be a number.
*/
Cartographic.equalsEpsilon = function(left, right, epsilon) {
if (typeof epsilon !== 'number') {
throw new DeveloperError('epsilon is required and must be a number.');
}
return (left === right) ||
((typeof left !== 'undefined') &&
(typeof right !== 'undefined') &&
(Math.abs(left.longitude - right.longitude) <= epsilon) &&
(Math.abs(left.latitude - right.latitude) <= epsilon) &&
(Math.abs(left.height - right.height) <= epsilon));
};
/**
* Creates a string representing the provided cartographic in the format '(longitude, latitude, height)'.
* @memberof Cartographic
*
* @param {Cartographic} cartographic The cartographic to stringify.
* @return {String} A string representing the provided cartographic in the format '(longitude, latitude, height)'.
*
* @exception {DeveloperError} cartographic is required.
*/
Cartographic.toString = function(cartographic) {
if (typeof cartographic === 'undefined') {
throw new DeveloperError('cartographic is required');
}
return '(' + cartographic.longitude + ', ' + cartographic.latitude + ', ' + cartographic.height + ')';
};
/**
* An immutable Cartographic instance initialized to (0.0, 0.0, 0.0).
*
* @memberof Cartographic
*/
Cartographic.ZERO = freezeObject(new Cartographic(0.0, 0.0, 0.0));
/**
* Duplicates this instance.
* @memberof Cartographic
*
* @param {Cartographic} [result] The object onto which to store the result.
* @return {Cartographic} The modified result parameter or a new Cartographic instance if one was not provided.
*/
Cartographic.prototype.clone = function(result) {
return Cartographic.clone(this, result);
};
/**
* Compares the provided against this cartographic componentwise and returns
* <code>true</code> if they are equal, <code>false</code> otherwise.
* @memberof Cartographic
*
* @param {Cartographic} [right] The second cartographic.
* @return {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
*/
Cartographic.prototype.equals = function(right) {
return Cartographic.equals(this, right);
};
/**
* Compares the provided against this cartographic componentwise and returns
* <code>true</code> if they are within the provided epsilon,
* <code>false</code> otherwise.
* @memberof Cartographic
*
* @param {Cartographic} [right] The second cartographic.
* @param {Number} epsilon The epsilon to use for equality testing.
* @return {Boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
*
* @exception {DeveloperError} epsilon is required and must be a number.
*/
Cartographic.prototype.equalsEpsilon = function(right, epsilon) {
return Cartographic.equalsEpsilon(this, right, epsilon);
};
/**
* Creates a string representing this cartographic in the format '(longitude, latitude, height)'.
* @memberof Cartographic
*
* @return {String} A string representing the provided cartographic in the format '(longitude, latitude, height)'.
*/
Cartographic.prototype.toString = function() {
return Cartographic.toString(this);
};
return Cartographic;
});