ekylibre-cartography 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +3 -0
- data/Rakefile +10 -0
- data/app/assets/javascripts/cartography.coffee +535 -0
- data/app/assets/javascripts/cartography/base.coffee +11 -0
- data/app/assets/javascripts/cartography/controls.coffee +463 -0
- data/app/assets/javascripts/cartography/events.coffee +36 -0
- data/app/assets/javascripts/cartography/layers.coffee +127 -0
- data/app/assets/javascripts/cartography/layers/simple.coffee +37 -0
- data/app/assets/javascripts/cartography/leaflet/controls.coffee +420 -0
- data/app/assets/javascripts/cartography/leaflet/handlers.coffee +461 -0
- data/app/assets/javascripts/cartography/leaflet/i18n.coffee +31 -0
- data/app/assets/javascripts/cartography/leaflet/layers.coffee +60 -0
- data/app/assets/javascripts/cartography/leaflet/toolbars.coffee +450 -0
- data/app/assets/javascripts/cartography/patches.js +8 -0
- data/app/assets/javascripts/cartography/util.coffee +18 -0
- data/app/assets/javascripts/main.js +18 -0
- data/app/assets/stylesheets/cartography.css +86 -0
- data/app/helpers/cartography_helper.rb +55 -0
- data/lib/cartography.rb +1 -0
- data/lib/cartography/engine.rb +11 -0
- data/lib/cartography/version.rb +3 -0
- data/vendor/assets/components/d3-array/dist/d3-array.js +590 -0
- data/vendor/assets/components/d3-array/dist/d3-array.min.js +2 -0
- data/vendor/assets/components/geojson-equality/dist/geojson-equality.js +295 -0
- data/vendor/assets/components/geojson-equality/dist/geojson-equality.js.map +21 -0
- data/vendor/assets/components/geojson-equality/dist/geojson-equality.min.js +1 -0
- data/vendor/assets/components/leaflet-controlpanel/dist/leaflet.controlpanel.css +29 -0
- data/vendor/assets/components/leaflet-controlpanel/dist/leaflet.controlpanel.js +269 -0
- data/vendor/assets/components/leaflet-draw-cut/dist/leaflet.draw.cut.css +1 -0
- data/vendor/assets/components/leaflet-draw-cut/dist/leaflet.draw.cut.js +8 -0
- data/vendor/assets/components/leaflet-draw-merge/dist/leaflet.draw.merge.css +0 -0
- data/vendor/assets/components/leaflet-draw-merge/dist/leaflet.draw.merge.js +48026 -0
- data/vendor/assets/components/leaflet-draw/dist/leaflet.draw-src.css +326 -0
- data/vendor/assets/components/leaflet-draw/dist/leaflet.draw-src.js +4653 -0
- data/vendor/assets/components/leaflet-draw/dist/leaflet.draw-src.map +1 -0
- data/vendor/assets/components/leaflet-draw/dist/leaflet.draw.css +10 -0
- data/vendor/assets/components/leaflet-draw/dist/leaflet.draw.js +10 -0
- data/vendor/assets/components/leaflet-geographicutil/dist/leaflet.geographicutil.js +3220 -0
- data/vendor/assets/components/leaflet-reactive_measure/dist/reactive_measure.css +30 -0
- data/vendor/assets/components/leaflet-reactive_measure/dist/reactive_measure.js +3764 -0
- data/vendor/assets/components/leaflet/dist/leaflet-src.js +13609 -0
- data/vendor/assets/components/leaflet/dist/leaflet-src.js.map +1 -0
- data/vendor/assets/components/leaflet/dist/leaflet-src.map +1 -0
- data/vendor/assets/components/leaflet/dist/leaflet.css +632 -0
- data/vendor/assets/components/leaflet/dist/leaflet.js +5 -0
- data/vendor/assets/components/leaflet/dist/leaflet.js.map +1 -0
- data/vendor/assets/components/martinez-polygon-clipping/dist/martinez.min.js +9 -0
- data/vendor/assets/components/martinez-polygon-clipping/dist/martinez.umd.js +1716 -0
- data/vendor/assets/components/martinez-polygon-clipping/dist/martinez.umd.js.map +1 -0
- data/vendor/assets/components/polygon-clipping/dist/polygon-clipping.js +279 -0
- data/vendor/assets/components/polygon-clipping/dist/polygon-clipping.min.js +1 -0
- data/vendor/assets/components/rtree/dist/rtree.js +911 -0
- data/vendor/assets/components/rtree/dist/rtree.min.js +1 -0
- data/vendor/assets/components/splaytree/dist/splay.es6.js +765 -0
- data/vendor/assets/components/splaytree/dist/splay.es6.js.map +1 -0
- data/vendor/assets/components/splaytree/dist/splay.js +797 -0
- data/vendor/assets/components/splaytree/dist/splay.js.map +1 -0
- metadata +156 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
.leaflet-draw-tooltip-left {
|
2
|
+
background: #363636;
|
3
|
+
background: rgba(0, 0, 0, 0.5);
|
4
|
+
border: 1px solid transparent;
|
5
|
+
position: absolute;
|
6
|
+
visibility: hidden;
|
7
|
+
white-space: nowrap;
|
8
|
+
z-index: 6; }
|
9
|
+
.leaflet-draw-tooltip-left:before {
|
10
|
+
border: none !important; }
|
11
|
+
.leaflet-draw-tooltip-left:after {
|
12
|
+
border-left: 6px solid black;
|
13
|
+
border-left-color: rgba(0, 0, 0, 0.5);
|
14
|
+
border-top: 6px solid transparent;
|
15
|
+
border-bottom: 6px solid transparent;
|
16
|
+
content: "";
|
17
|
+
position: absolute;
|
18
|
+
top: 7px;
|
19
|
+
left: 100%; }
|
20
|
+
.leaflet-draw-tooltip-left span {
|
21
|
+
color: inherit; }
|
22
|
+
|
23
|
+
.leaflet-draw-tooltip-measure.area {
|
24
|
+
padding-left: 10px; }
|
25
|
+
|
26
|
+
.reactive-measure-control {
|
27
|
+
background: rgba(255, 255, 255, 0.6);
|
28
|
+
padding: 0 8px; }
|
29
|
+
.reactive-measure-control.selection {
|
30
|
+
background: rgba(255, 196, 136, 0.5); }
|
@@ -0,0 +1,3764 @@
|
|
1
|
+
/******/ (function(modules) { // webpackBootstrap
|
2
|
+
/******/ // The module cache
|
3
|
+
/******/ var installedModules = {};
|
4
|
+
/******/
|
5
|
+
/******/ // The require function
|
6
|
+
/******/ function __webpack_require__(moduleId) {
|
7
|
+
/******/
|
8
|
+
/******/ // Check if module is in cache
|
9
|
+
/******/ if(installedModules[moduleId]) {
|
10
|
+
/******/ return installedModules[moduleId].exports;
|
11
|
+
/******/ }
|
12
|
+
/******/ // Create a new module (and put it into the cache)
|
13
|
+
/******/ var module = installedModules[moduleId] = {
|
14
|
+
/******/ i: moduleId,
|
15
|
+
/******/ l: false,
|
16
|
+
/******/ exports: {}
|
17
|
+
/******/ };
|
18
|
+
/******/
|
19
|
+
/******/ // Execute the module function
|
20
|
+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
21
|
+
/******/
|
22
|
+
/******/ // Flag the module as loaded
|
23
|
+
/******/ module.l = true;
|
24
|
+
/******/
|
25
|
+
/******/ // Return the exports of the module
|
26
|
+
/******/ return module.exports;
|
27
|
+
/******/ }
|
28
|
+
/******/
|
29
|
+
/******/
|
30
|
+
/******/ // expose the modules object (__webpack_modules__)
|
31
|
+
/******/ __webpack_require__.m = modules;
|
32
|
+
/******/
|
33
|
+
/******/ // expose the module cache
|
34
|
+
/******/ __webpack_require__.c = installedModules;
|
35
|
+
/******/
|
36
|
+
/******/ // define getter function for harmony exports
|
37
|
+
/******/ __webpack_require__.d = function(exports, name, getter) {
|
38
|
+
/******/ if(!__webpack_require__.o(exports, name)) {
|
39
|
+
/******/ Object.defineProperty(exports, name, {
|
40
|
+
/******/ configurable: false,
|
41
|
+
/******/ enumerable: true,
|
42
|
+
/******/ get: getter
|
43
|
+
/******/ });
|
44
|
+
/******/ }
|
45
|
+
/******/ };
|
46
|
+
/******/
|
47
|
+
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
48
|
+
/******/ __webpack_require__.n = function(module) {
|
49
|
+
/******/ var getter = module && module.__esModule ?
|
50
|
+
/******/ function getDefault() { return module['default']; } :
|
51
|
+
/******/ function getModuleExports() { return module; };
|
52
|
+
/******/ __webpack_require__.d(getter, 'a', getter);
|
53
|
+
/******/ return getter;
|
54
|
+
/******/ };
|
55
|
+
/******/
|
56
|
+
/******/ // Object.prototype.hasOwnProperty.call
|
57
|
+
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
58
|
+
/******/
|
59
|
+
/******/ // __webpack_public_path__
|
60
|
+
/******/ __webpack_require__.p = "";
|
61
|
+
/******/
|
62
|
+
/******/ // Load entry module and return exports
|
63
|
+
/******/ return __webpack_require__(__webpack_require__.s = 0);
|
64
|
+
/******/ })
|
65
|
+
/************************************************************************/
|
66
|
+
/******/ ([
|
67
|
+
/* 0 */
|
68
|
+
/***/ (function(module, exports, __webpack_require__) {
|
69
|
+
|
70
|
+
__webpack_require__(1);
|
71
|
+
module.exports = __webpack_require__(4);
|
72
|
+
|
73
|
+
|
74
|
+
/***/ }),
|
75
|
+
/* 1 */
|
76
|
+
/***/ (function(module, exports, __webpack_require__) {
|
77
|
+
|
78
|
+
var L;
|
79
|
+
|
80
|
+
L = __webpack_require__(2);
|
81
|
+
|
82
|
+
__webpack_require__(3);
|
83
|
+
|
84
|
+
L.ReactiveMeasure = {};
|
85
|
+
|
86
|
+
L.ReactiveMeasure.Draw = {};
|
87
|
+
|
88
|
+
L.ReactiveMeasure.Edit = {};
|
89
|
+
|
90
|
+
L.ReactiveMeasure.Draw.Event = {};
|
91
|
+
|
92
|
+
L.ReactiveMeasure.Edit.Event = {};
|
93
|
+
|
94
|
+
L.ReactiveMeasure.Draw.Event.MOVE = "reactiveMeasure:draw:move";
|
95
|
+
|
96
|
+
L.ReactiveMeasure.Edit.Event.MOVE = "reactiveMeasure:edit:move";
|
97
|
+
|
98
|
+
module.exports = L.ReactiveMeasureControl = L.Control.extend({
|
99
|
+
options: {
|
100
|
+
position: 'bottomright',
|
101
|
+
metric: true,
|
102
|
+
feet: false,
|
103
|
+
measure: {
|
104
|
+
perimeter: 0,
|
105
|
+
area: 0
|
106
|
+
}
|
107
|
+
},
|
108
|
+
initialize: function(layers, options) {
|
109
|
+
if (options == null) {
|
110
|
+
options = {};
|
111
|
+
}
|
112
|
+
L.Util.setOptions(this, options);
|
113
|
+
this.options.measure.perimeter = 0;
|
114
|
+
this.options.measure.area = 0;
|
115
|
+
if (layers.getLayers().length > 0) {
|
116
|
+
return layers.eachLayer((function(_this) {
|
117
|
+
return function(layer) {
|
118
|
+
var m;
|
119
|
+
if (typeof layer.getMeasure === 'function') {
|
120
|
+
m = layer.getMeasure();
|
121
|
+
_this.options.measure.perimeter += m.perimeter;
|
122
|
+
return _this.options.measure.area += m.area;
|
123
|
+
}
|
124
|
+
};
|
125
|
+
})(this));
|
126
|
+
}
|
127
|
+
},
|
128
|
+
onAdd: function(map) {
|
129
|
+
this._container = L.DomUtil.create('div', "reactive-measure-control " + map._leaflet_id);
|
130
|
+
map.reactiveMeasureControl = this;
|
131
|
+
if (map && this._container) {
|
132
|
+
this.updateContent(this.options.measure);
|
133
|
+
}
|
134
|
+
return this._container;
|
135
|
+
},
|
136
|
+
updateContent: function(measure, options) {
|
137
|
+
var text;
|
138
|
+
if (measure == null) {
|
139
|
+
measure = {};
|
140
|
+
}
|
141
|
+
if (options == null) {
|
142
|
+
options = {};
|
143
|
+
}
|
144
|
+
text = '';
|
145
|
+
if (measure['perimeter']) {
|
146
|
+
text += "<span class='leaflet-draw-tooltip-measure perimeter'>" + (L.GeometryUtil.readableDistance(measure.perimeter, !!this.options.metric, !!options.feet)) + "</span>";
|
147
|
+
}
|
148
|
+
if (measure['area']) {
|
149
|
+
text += "<span class='leaflet-draw-tooltip-measure area'>" + (L.GeometryUtil.readableArea(measure.area, !!this.options.metric)) + "</span>";
|
150
|
+
}
|
151
|
+
if ((options.selection != null) && options.selection === true) {
|
152
|
+
L.DomUtil.addClass(this._container, 'selection');
|
153
|
+
} else {
|
154
|
+
L.DomUtil.removeClass(this._container, 'selection');
|
155
|
+
}
|
156
|
+
this._container.innerHTML = text;
|
157
|
+
}
|
158
|
+
});
|
159
|
+
|
160
|
+
L.FeatureGroup.include({
|
161
|
+
getMeasure: function() {
|
162
|
+
var measure;
|
163
|
+
measure = {
|
164
|
+
perimeter: 0,
|
165
|
+
area: 0
|
166
|
+
};
|
167
|
+
this.eachLayer(function(layer) {
|
168
|
+
var m;
|
169
|
+
m = layer.getMeasure();
|
170
|
+
measure.perimeter += m.perimeter;
|
171
|
+
return measure.area += m.area;
|
172
|
+
});
|
173
|
+
return measure;
|
174
|
+
}
|
175
|
+
});
|
176
|
+
|
177
|
+
L.Polygon.include({
|
178
|
+
|
179
|
+
/*
|
180
|
+
* Get centroid of the polygon in square meters
|
181
|
+
* Portage from leaflet1.0.0-rc1: https://github.com/Leaflet/Leaflet/blob/master/src/layer/vector/Polygon.js
|
182
|
+
* @return {number} polygon centroid
|
183
|
+
*/
|
184
|
+
__getCenter: function() {
|
185
|
+
var area, center, f, i, j, len, p1, p2, points, x, y;
|
186
|
+
this.__project();
|
187
|
+
points = this._rings[0];
|
188
|
+
len = points.length;
|
189
|
+
if (!len) {
|
190
|
+
return null;
|
191
|
+
}
|
192
|
+
area = x = y = 0;
|
193
|
+
i = 0;
|
194
|
+
j = len - 1;
|
195
|
+
while (i < len) {
|
196
|
+
p1 = points[i];
|
197
|
+
p2 = points[j];
|
198
|
+
f = p1.y * p2.x - (p2.y * p1.x);
|
199
|
+
x += (p1.x + p2.x) * f;
|
200
|
+
y += (p1.y + p2.y) * f;
|
201
|
+
area += f * 3;
|
202
|
+
j = i++;
|
203
|
+
}
|
204
|
+
if (area === 0) {
|
205
|
+
center = points[0];
|
206
|
+
} else {
|
207
|
+
center = [x / area, y / area];
|
208
|
+
}
|
209
|
+
return this._map.layerPointToLatLng(center);
|
210
|
+
},
|
211
|
+
|
212
|
+
/*
|
213
|
+
* Return LatLngs as array of [lat, lng] pair.
|
214
|
+
* @return {Array} [[lat,lng], [lat,lng]]
|
215
|
+
*/
|
216
|
+
getLatLngsAsArray: function() {
|
217
|
+
var arr, k, latlng, len1, ref;
|
218
|
+
arr = [];
|
219
|
+
ref = this._latlngs[0];
|
220
|
+
for (k = 0, len1 = ref.length; k < len1; k++) {
|
221
|
+
latlng = ref[k];
|
222
|
+
arr.push([latlng.lat, latlng.lng]);
|
223
|
+
}
|
224
|
+
return arr;
|
225
|
+
}
|
226
|
+
});
|
227
|
+
|
228
|
+
L.Polyline.include({
|
229
|
+
|
230
|
+
/*
|
231
|
+
* Return LatLngs as array of [lat, lng] pair.
|
232
|
+
* @return {Array} [[lat,lng], [lat,lng]]
|
233
|
+
*/
|
234
|
+
getLatLngsAsArray: function() {
|
235
|
+
var arr, k, latlng, len1, ref;
|
236
|
+
arr = [];
|
237
|
+
ref = this._latlngs;
|
238
|
+
for (k = 0, len1 = ref.length; k < len1; k++) {
|
239
|
+
latlng = ref[k];
|
240
|
+
arr.push([latlng.lat, latlng.lng]);
|
241
|
+
}
|
242
|
+
return arr;
|
243
|
+
},
|
244
|
+
|
245
|
+
/*
|
246
|
+
* Get center of the polyline in meters
|
247
|
+
* Portage from leaflet1.0.0-rc1: https://github.com/Leaflet/Leaflet/blob/master/src/layer/vector/Polyline.js
|
248
|
+
* @return {number} polyline center
|
249
|
+
*/
|
250
|
+
__getCenter: function() {
|
251
|
+
var dist, halfDist, i, len, p1, p2, points, ratio, segDist;
|
252
|
+
this.__project();
|
253
|
+
i = void 0;
|
254
|
+
halfDist = void 0;
|
255
|
+
segDist = void 0;
|
256
|
+
dist = void 0;
|
257
|
+
p1 = void 0;
|
258
|
+
p2 = void 0;
|
259
|
+
ratio = void 0;
|
260
|
+
points = this._rings[0];
|
261
|
+
len = points.length;
|
262
|
+
if (!len) {
|
263
|
+
return null;
|
264
|
+
}
|
265
|
+
i = 0;
|
266
|
+
halfDist = 0;
|
267
|
+
while (i < len - 1) {
|
268
|
+
halfDist += points[i].distanceTo(points[i + 1]) / 2;
|
269
|
+
i++;
|
270
|
+
}
|
271
|
+
if (halfDist === 0) {
|
272
|
+
return this._map.layerPointToLatLng(points[0]);
|
273
|
+
}
|
274
|
+
i = 0;
|
275
|
+
dist = 0;
|
276
|
+
while (i < len - 1) {
|
277
|
+
p1 = points[i];
|
278
|
+
p2 = points[i + 1];
|
279
|
+
segDist = p1.distanceTo(p2);
|
280
|
+
dist += segDist;
|
281
|
+
if (dist > halfDist) {
|
282
|
+
ratio = (dist - halfDist) / segDist;
|
283
|
+
return this._map.layerPointToLatLng([p2.x - (ratio * (p2.x - p1.x)), p2.y - (ratio * (p2.y - p1.y))]);
|
284
|
+
}
|
285
|
+
i++;
|
286
|
+
}
|
287
|
+
},
|
288
|
+
__project: function() {
|
289
|
+
var pxBounds;
|
290
|
+
pxBounds = new L.Bounds;
|
291
|
+
this._rings = [];
|
292
|
+
this.__projectLatlngs(this._latlngs, this._rings, pxBounds);
|
293
|
+
},
|
294
|
+
__projectLatlngs: function(latlngs, result, projectedBounds) {
|
295
|
+
var flat, i, len, ring;
|
296
|
+
flat = latlngs[0] instanceof L.LatLng;
|
297
|
+
len = latlngs.length;
|
298
|
+
i = void 0;
|
299
|
+
ring = void 0;
|
300
|
+
if (flat) {
|
301
|
+
ring = [];
|
302
|
+
i = 0;
|
303
|
+
while (i < len) {
|
304
|
+
ring[i] = this._map.latLngToLayerPoint(latlngs[i]);
|
305
|
+
projectedBounds.extend(ring[i]);
|
306
|
+
i++;
|
307
|
+
}
|
308
|
+
result.push(ring);
|
309
|
+
} else {
|
310
|
+
i = 0;
|
311
|
+
while (i < len) {
|
312
|
+
this.__projectLatlngs(latlngs[i], result, projectedBounds);
|
313
|
+
i++;
|
314
|
+
}
|
315
|
+
}
|
316
|
+
},
|
317
|
+
getMeasure: function() {
|
318
|
+
return L.GeographicUtil.Polygon(this.getLatLngsAsArray());
|
319
|
+
}
|
320
|
+
});
|
321
|
+
|
322
|
+
L.Draw.Polyline.include({
|
323
|
+
__addHooks: L.Draw.Polyline.prototype.addHooks,
|
324
|
+
__removeHooks: L.Draw.Polyline.prototype.removeHooks,
|
325
|
+
__vertexChanged: L.Draw.Polyline.prototype._vertexChanged,
|
326
|
+
_vertexChanged: function(e) {
|
327
|
+
this.__vertexChanged.apply(this, arguments);
|
328
|
+
if (!this._map.reactiveMeasureControl.options.tooltip && (this._tooltip != null)) {
|
329
|
+
L.DomUtil.setOpacity(this._tooltip._container, 0);
|
330
|
+
return L.DomUtil.setPosition(this._tooltip._container, L.point(0, 0));
|
331
|
+
}
|
332
|
+
},
|
333
|
+
__onMouseMove: function(e) {
|
334
|
+
var center, clone, k, latLng, latLngArray, len1, measure, mouseLatLng, newPos, ref;
|
335
|
+
if (!e.target.reactiveMeasureControl.options.tooltip && (this._tooltip != null)) {
|
336
|
+
L.DomUtil.setOpacity(this._tooltip._container, 0);
|
337
|
+
L.DomUtil.setPosition(this._tooltip._container, L.point(0, 0));
|
338
|
+
}
|
339
|
+
if (!(this._markers.length > 0)) {
|
340
|
+
return;
|
341
|
+
}
|
342
|
+
newPos = this._map.mouseEventToLayerPoint(e.originalEvent);
|
343
|
+
mouseLatLng = this._map.layerPointToLatLng(newPos);
|
344
|
+
latLngArray = [];
|
345
|
+
ref = this._poly.getLatLngs();
|
346
|
+
for (k = 0, len1 = ref.length; k < len1; k++) {
|
347
|
+
latLng = ref[k];
|
348
|
+
latLngArray.push(latLng);
|
349
|
+
}
|
350
|
+
latLngArray.push(mouseLatLng);
|
351
|
+
if (this._markers.length === 1) {
|
352
|
+
clone = L.polyline(latLngArray);
|
353
|
+
}
|
354
|
+
if (this._markers.length >= 2) {
|
355
|
+
clone = L.polygon(latLngArray);
|
356
|
+
}
|
357
|
+
clone._map = this._map;
|
358
|
+
center = clone.__getCenter();
|
359
|
+
measure = L.GeographicUtil.Polygon(clone.getLatLngsAsArray());
|
360
|
+
e.target.reactiveMeasureControl.updateContent(measure, {
|
361
|
+
selection: true
|
362
|
+
});
|
363
|
+
if (e.target.reactiveMeasureControl.options.tooltip != null) {
|
364
|
+
this._tooltip.__updateTooltipMeasure(center, measure, e.target.reactiveMeasureControl.options);
|
365
|
+
}
|
366
|
+
return this._map.fire(L.ReactiveMeasure.Draw.Event.MOVE, {
|
367
|
+
measure: measure
|
368
|
+
});
|
369
|
+
},
|
370
|
+
addHooks: function() {
|
371
|
+
this.__addHooks.apply(this, arguments);
|
372
|
+
this._map.on('mousemove', this.__onMouseMove, this);
|
373
|
+
},
|
374
|
+
removeHooks: function() {
|
375
|
+
var measure;
|
376
|
+
if (this._map.reactiveMeasureControl) {
|
377
|
+
measure = L.GeographicUtil.Polygon(this._poly.getLatLngsAsArray());
|
378
|
+
if (this._poly._map != null) {
|
379
|
+
this._poly._map.reactiveMeasureControl.updateContent(measure, {
|
380
|
+
selection: false
|
381
|
+
});
|
382
|
+
}
|
383
|
+
this._map.off('mousemove');
|
384
|
+
}
|
385
|
+
this.__removeHooks.apply(this, arguments);
|
386
|
+
}
|
387
|
+
});
|
388
|
+
|
389
|
+
L.Edit.Poly.include({
|
390
|
+
__addHooks: L.Edit.Poly.prototype.addHooks,
|
391
|
+
__removeHooks: L.Edit.Poly.prototype.removeHooks,
|
392
|
+
__onHandlerDrag: (function(_this) {
|
393
|
+
return function(e) {
|
394
|
+
var _poly, center, measure;
|
395
|
+
_poly = e.target.editing._poly;
|
396
|
+
center = _poly.__getCenter();
|
397
|
+
measure = L.GeographicUtil.Polygon(_poly.getLatLngsAsArray());
|
398
|
+
L.extend(L.Draw.Polyline.prototype.options, {
|
399
|
+
target: e.marker.getLatLng()
|
400
|
+
});
|
401
|
+
if (_poly._map != null) {
|
402
|
+
_poly._map.reactiveMeasureControl.updateContent(measure, {
|
403
|
+
selection: true
|
404
|
+
});
|
405
|
+
}
|
406
|
+
return _poly._map.fire(L.ReactiveMeasure.Edit.Event.MOVE, {
|
407
|
+
measure: measure
|
408
|
+
});
|
409
|
+
};
|
410
|
+
})(this),
|
411
|
+
addHooks: function() {
|
412
|
+
this.__addHooks.apply(this, arguments);
|
413
|
+
return this._poly.on('editdrag', this.__onHandlerDrag, this);
|
414
|
+
},
|
415
|
+
removeHooks: function() {
|
416
|
+
var measure;
|
417
|
+
measure = L.GeographicUtil.Polygon(this._poly.getLatLngsAsArray());
|
418
|
+
if (this._poly._map != null) {
|
419
|
+
this._poly._map.reactiveMeasureControl.updateContent(measure, {
|
420
|
+
selection: false
|
421
|
+
});
|
422
|
+
}
|
423
|
+
if (L.EditToolbar.reactiveMeasure) {
|
424
|
+
this._poly.off('editdrag');
|
425
|
+
}
|
426
|
+
return this.__removeHooks.apply(this, arguments);
|
427
|
+
}
|
428
|
+
});
|
429
|
+
|
430
|
+
L.Edit.PolyVerticesEdit.include({
|
431
|
+
__onTouchMove: L.Edit.PolyVerticesEdit.prototype._onTouchMove,
|
432
|
+
__removeMarker: L.Edit.PolyVerticesEdit.prototype._removeMarker,
|
433
|
+
_onMarkerDrag: function(e) {
|
434
|
+
var marker;
|
435
|
+
marker = e.target;
|
436
|
+
L.extend(marker._origLatLng, marker._latlng);
|
437
|
+
if (marker._middleLeft) {
|
438
|
+
marker._middleLeft.setLatLng(this._getMiddleLatLng(marker._prev, marker));
|
439
|
+
}
|
440
|
+
if (marker._middleRight) {
|
441
|
+
marker._middleRight.setLatLng(this._getMiddleLatLng(marker, marker._next));
|
442
|
+
}
|
443
|
+
this._poly.redraw();
|
444
|
+
this._poly.fire('editdrag', {
|
445
|
+
marker: e.target
|
446
|
+
});
|
447
|
+
},
|
448
|
+
_onTouchMove: function(e) {
|
449
|
+
this.__onTouchMove.apply(this, arguments);
|
450
|
+
return this._poly.fire('editdrag');
|
451
|
+
},
|
452
|
+
_removeMarker: function(marker) {
|
453
|
+
this.__removeMarker.apply(this, arguments);
|
454
|
+
return this._poly.fire('editdrag', {
|
455
|
+
marker: marker
|
456
|
+
});
|
457
|
+
}
|
458
|
+
});
|
459
|
+
|
460
|
+
L.LatLng.prototype.toArray = function() {
|
461
|
+
return [this.lat, this.lng];
|
462
|
+
};
|
463
|
+
|
464
|
+
L.Draw.Tooltip.include({
|
465
|
+
__initialize: L.Draw.Tooltip.prototype.initialize,
|
466
|
+
__dispose: L.Draw.Tooltip.prototype.dispose,
|
467
|
+
initialize: function(map, options) {
|
468
|
+
if (options == null) {
|
469
|
+
options = {};
|
470
|
+
}
|
471
|
+
return this.__initialize.apply(this, arguments);
|
472
|
+
},
|
473
|
+
dispose: function() {
|
474
|
+
this._map.off('mouseover');
|
475
|
+
return this.__dispose.apply(this, arguments);
|
476
|
+
},
|
477
|
+
__updateTooltipMeasure: function(latLng, measure, options) {
|
478
|
+
var labelText;
|
479
|
+
if (measure == null) {
|
480
|
+
measure = {};
|
481
|
+
}
|
482
|
+
if (options == null) {
|
483
|
+
options = {};
|
484
|
+
}
|
485
|
+
labelText = {
|
486
|
+
text: ''
|
487
|
+
};
|
488
|
+
if (measure['perimeter']) {
|
489
|
+
labelText['text'] += "<span class='leaflet-draw-tooltip-measure perimeter'>" + (L.GeometryUtil.readableDistance(measure.perimeter, !!options.metric, !!options.feet)) + "</span>";
|
490
|
+
}
|
491
|
+
if (measure['area']) {
|
492
|
+
labelText['text'] += "<span class='leaflet-draw-tooltip-measure area'>" + (L.GeometryUtil.readableArea(measure.area, !!options.metric)) + "</span>";
|
493
|
+
}
|
494
|
+
if (latLng) {
|
495
|
+
this.updateContent(labelText);
|
496
|
+
this.__updatePosition(latLng, options);
|
497
|
+
}
|
498
|
+
},
|
499
|
+
__updatePosition: function(latlng, options) {
|
500
|
+
var container, container_width, labelWidth, map_width, pos, styles;
|
501
|
+
if (options == null) {
|
502
|
+
options = {};
|
503
|
+
}
|
504
|
+
pos = this._map.latLngToLayerPoint(latlng);
|
505
|
+
labelWidth = this._container.offsetWidth;
|
506
|
+
map_width = this._map._container.offsetWidth;
|
507
|
+
L.DomUtil.removeClass(this._container, 'leaflet-draw-tooltip-left');
|
508
|
+
if (this._container) {
|
509
|
+
this._container.style.visibility = 'inherit';
|
510
|
+
container = this._map.layerPointToContainerPoint(pos);
|
511
|
+
styles = window.getComputedStyle(this._container);
|
512
|
+
container_width = this._container.offsetWidth + parseInt(styles.paddingLeft) + parseInt(styles.paddingRight) + parseInt(styles.marginLeft) + parseInt(styles.marginRight);
|
513
|
+
if (container.x < 0 || container.x > (map_width - container_width) || container.y < this._container.offsetHeight) {
|
514
|
+
pos = pos.add(L.point(-container_width, 0));
|
515
|
+
L.DomUtil.addClass(this._container, 'leaflet-draw-tooltip-left');
|
516
|
+
}
|
517
|
+
return L.DomUtil.setPosition(this._container, pos);
|
518
|
+
}
|
519
|
+
},
|
520
|
+
hide: function() {
|
521
|
+
return this._container.style.visibility = 'hidden';
|
522
|
+
}
|
523
|
+
});
|
524
|
+
|
525
|
+
|
526
|
+
/***/ }),
|
527
|
+
/* 2 */
|
528
|
+
/***/ (function(module, exports) {
|
529
|
+
|
530
|
+
module.exports = L;
|
531
|
+
|
532
|
+
/***/ }),
|
533
|
+
/* 3 */
|
534
|
+
/***/ (function(module, exports) {
|
535
|
+
|
536
|
+
/******/ (function(modules) { // webpackBootstrap
|
537
|
+
/******/ // The module cache
|
538
|
+
/******/ var installedModules = {};
|
539
|
+
/******/
|
540
|
+
/******/ // The require function
|
541
|
+
/******/ function __webpack_require__(moduleId) {
|
542
|
+
/******/
|
543
|
+
/******/ // Check if module is in cache
|
544
|
+
/******/ if(installedModules[moduleId]) {
|
545
|
+
/******/ return installedModules[moduleId].exports;
|
546
|
+
/******/ }
|
547
|
+
/******/ // Create a new module (and put it into the cache)
|
548
|
+
/******/ var module = installedModules[moduleId] = {
|
549
|
+
/******/ i: moduleId,
|
550
|
+
/******/ l: false,
|
551
|
+
/******/ exports: {}
|
552
|
+
/******/ };
|
553
|
+
/******/
|
554
|
+
/******/ // Execute the module function
|
555
|
+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
556
|
+
/******/
|
557
|
+
/******/ // Flag the module as loaded
|
558
|
+
/******/ module.l = true;
|
559
|
+
/******/
|
560
|
+
/******/ // Return the exports of the module
|
561
|
+
/******/ return module.exports;
|
562
|
+
/******/ }
|
563
|
+
/******/
|
564
|
+
/******/
|
565
|
+
/******/ // expose the modules object (__webpack_modules__)
|
566
|
+
/******/ __webpack_require__.m = modules;
|
567
|
+
/******/
|
568
|
+
/******/ // expose the module cache
|
569
|
+
/******/ __webpack_require__.c = installedModules;
|
570
|
+
/******/
|
571
|
+
/******/ // define getter function for harmony exports
|
572
|
+
/******/ __webpack_require__.d = function(exports, name, getter) {
|
573
|
+
/******/ if(!__webpack_require__.o(exports, name)) {
|
574
|
+
/******/ Object.defineProperty(exports, name, {
|
575
|
+
/******/ configurable: false,
|
576
|
+
/******/ enumerable: true,
|
577
|
+
/******/ get: getter
|
578
|
+
/******/ });
|
579
|
+
/******/ }
|
580
|
+
/******/ };
|
581
|
+
/******/
|
582
|
+
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
583
|
+
/******/ __webpack_require__.n = function(module) {
|
584
|
+
/******/ var getter = module && module.__esModule ?
|
585
|
+
/******/ function getDefault() { return module['default']; } :
|
586
|
+
/******/ function getModuleExports() { return module; };
|
587
|
+
/******/ __webpack_require__.d(getter, 'a', getter);
|
588
|
+
/******/ return getter;
|
589
|
+
/******/ };
|
590
|
+
/******/
|
591
|
+
/******/ // Object.prototype.hasOwnProperty.call
|
592
|
+
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
593
|
+
/******/
|
594
|
+
/******/ // __webpack_public_path__
|
595
|
+
/******/ __webpack_require__.p = "";
|
596
|
+
/******/
|
597
|
+
/******/ // Load entry module and return exports
|
598
|
+
/******/ return __webpack_require__(__webpack_require__.s = 0);
|
599
|
+
/******/ })
|
600
|
+
/************************************************************************/
|
601
|
+
/******/ ([
|
602
|
+
/* 0 */
|
603
|
+
/***/ (function(module, exports, __webpack_require__) {
|
604
|
+
|
605
|
+
module.exports = __webpack_require__(1);
|
606
|
+
|
607
|
+
|
608
|
+
/***/ }),
|
609
|
+
/* 1 */
|
610
|
+
/***/ (function(module, exports, __webpack_require__) {
|
611
|
+
|
612
|
+
var GeographicLib, L;
|
613
|
+
|
614
|
+
L = __webpack_require__(2);
|
615
|
+
|
616
|
+
GeographicLib = __webpack_require__(3);
|
617
|
+
|
618
|
+
L.GeographicUtil = (function() {
|
619
|
+
function GeographicUtil() {}
|
620
|
+
|
621
|
+
GeographicUtil.Polygon = function(points, polyline) {
|
622
|
+
var geod, i, j, len, len1, point, poly, poly2;
|
623
|
+
if (polyline == null) {
|
624
|
+
polyline = false;
|
625
|
+
}
|
626
|
+
geod = GeographicLib.Geodesic.WGS84;
|
627
|
+
poly = geod.Polygon(false);
|
628
|
+
for (i = 0, len = points.length; i < len; i++) {
|
629
|
+
point = points[i];
|
630
|
+
poly.AddPoint(point[0], point[1]);
|
631
|
+
}
|
632
|
+
poly = poly.Compute(false, true);
|
633
|
+
poly2 = geod.Polygon(true);
|
634
|
+
for (j = 0, len1 = points.length; j < len1; j++) {
|
635
|
+
point = points[j];
|
636
|
+
poly2.AddPoint(point[0], point[1]);
|
637
|
+
}
|
638
|
+
poly2 = poly2.Compute(false, true);
|
639
|
+
return {
|
640
|
+
extrapolatedPerimeter: poly.perimeter,
|
641
|
+
extrapolatedArea: Math.abs(poly.area),
|
642
|
+
perimeter: poly2.perimeter
|
643
|
+
};
|
644
|
+
};
|
645
|
+
|
646
|
+
GeographicUtil.distance = function(a, b) {
|
647
|
+
var geod, r;
|
648
|
+
geod = GeographicLib.Geodesic.WGS84;
|
649
|
+
r = geod.Inverse(a[0], a[1], b[0], b[1]);
|
650
|
+
return r.s12.toFixed(3);
|
651
|
+
};
|
652
|
+
|
653
|
+
return GeographicUtil;
|
654
|
+
|
655
|
+
})();
|
656
|
+
|
657
|
+
|
658
|
+
/***/ }),
|
659
|
+
/* 2 */
|
660
|
+
/***/ (function(module, exports) {
|
661
|
+
|
662
|
+
module.exports = L;
|
663
|
+
|
664
|
+
/***/ }),
|
665
|
+
/* 3 */
|
666
|
+
/***/ (function(module, exports, __webpack_require__) {
|
667
|
+
|
668
|
+
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*
|
669
|
+
* Geodesic routines from GeographicLib translated to JavaScript. See
|
670
|
+
* https://geographiclib.sourceforge.io/html/js/
|
671
|
+
*
|
672
|
+
* The algorithms are derived in
|
673
|
+
*
|
674
|
+
* Charles F. F. Karney,
|
675
|
+
* Algorithms for geodesics, J. Geodesy 87, 43-55 (2013),
|
676
|
+
* https://doi.org/10.1007/s00190-012-0578-z
|
677
|
+
* Addenda: https://geographiclib.sourceforge.io/geod-addenda.html
|
678
|
+
*
|
679
|
+
* This file is the concatenation and compression of the JavaScript files in
|
680
|
+
* doc/scripts/GeographicLib in the source tree for GeographicLib.
|
681
|
+
*
|
682
|
+
* Copyright (c) Charles Karney (2011-2015) <charles@karney.com> and licensed
|
683
|
+
* under the MIT/X11 License. For more information, see
|
684
|
+
* https://geographiclib.sourceforge.io/
|
685
|
+
*
|
686
|
+
* Version: 1.49
|
687
|
+
* File inventory:
|
688
|
+
* Math.js Geodesic.js GeodesicLine.js PolygonArea.js DMS.js
|
689
|
+
*/
|
690
|
+
|
691
|
+
(function(cb) {
|
692
|
+
|
693
|
+
/**************** Math.js ****************/
|
694
|
+
/*
|
695
|
+
* Math.js
|
696
|
+
* Transcription of Math.hpp, Constants.hpp, and Accumulator.hpp into
|
697
|
+
* JavaScript.
|
698
|
+
*
|
699
|
+
* Copyright (c) Charles Karney (2011-2017) <charles@karney.com> and licensed
|
700
|
+
* under the MIT/X11 License. For more information, see
|
701
|
+
* https://geographiclib.sourceforge.io/
|
702
|
+
*/
|
703
|
+
|
704
|
+
/**
|
705
|
+
* @namespace GeographicLib
|
706
|
+
* @description The parent namespace for the following modules:
|
707
|
+
* - {@link module:GeographicLib/Geodesic GeographicLib/Geodesic} The main
|
708
|
+
* engine for solving geodesic problems via the
|
709
|
+
* {@link module:GeographicLib/Geodesic.Geodesic Geodesic} class.
|
710
|
+
* - {@link module:GeographicLib/GeodesicLine GeographicLib/GeodesicLine}
|
711
|
+
* computes points along a single geodesic line via the
|
712
|
+
* {@link module:GeographicLib/GeodesicLine.GeodesicLine GeodesicLine}
|
713
|
+
* class.
|
714
|
+
* - {@link module:GeographicLib/PolygonArea GeographicLib/PolygonArea}
|
715
|
+
* computes the area of a geodesic polygon via the
|
716
|
+
* {@link module:GeographicLib/PolygonArea.PolygonArea PolygonArea}
|
717
|
+
* class.
|
718
|
+
* - {@link module:GeographicLib/DMS GeographicLib/DMS} handles the decoding
|
719
|
+
* and encoding of angles in degree, minutes, and seconds, via static
|
720
|
+
* functions in this module.
|
721
|
+
* - {@link module:GeographicLib/Constants GeographicLib/Constants} defines
|
722
|
+
* constants specifying the version numbers and the parameters for the WGS84
|
723
|
+
* ellipsoid.
|
724
|
+
*
|
725
|
+
* The following modules are used internally by the package:
|
726
|
+
* - {@link module:GeographicLib/Math GeographicLib/Math} defines various
|
727
|
+
* mathematical functions.
|
728
|
+
* - {@link module:GeographicLib/Accumulator GeographicLib/Accumulator}
|
729
|
+
* interally used by
|
730
|
+
* {@link module:GeographicLib/PolygonArea.PolygonArea PolygonArea} (via the
|
731
|
+
* {@link module:GeographicLib/Accumulator.Accumulator Accumulator} class)
|
732
|
+
* for summing the contributions to the area of a polygon.
|
733
|
+
*/
|
734
|
+
"use strict";
|
735
|
+
var GeographicLib = {};
|
736
|
+
GeographicLib.Constants = {};
|
737
|
+
GeographicLib.Math = {};
|
738
|
+
GeographicLib.Accumulator = {};
|
739
|
+
|
740
|
+
(function(
|
741
|
+
/**
|
742
|
+
* @exports GeographicLib/Constants
|
743
|
+
* @description Define constants defining the version and WGS84 parameters.
|
744
|
+
*/
|
745
|
+
c) {
|
746
|
+
|
747
|
+
/**
|
748
|
+
* @constant
|
749
|
+
* @summary WGS84 parameters.
|
750
|
+
* @property {number} a the equatorial radius (meters).
|
751
|
+
* @property {number} f the flattening.
|
752
|
+
*/
|
753
|
+
c.WGS84 = { a: 6378137, f: 1/298.257223563 };
|
754
|
+
/**
|
755
|
+
* @constant
|
756
|
+
* @summary an array of version numbers.
|
757
|
+
* @property {number} major the major version number.
|
758
|
+
* @property {number} minor the minor version number.
|
759
|
+
* @property {number} patch the patch number.
|
760
|
+
*/
|
761
|
+
c.version = { major: 1, minor: 49, patch: 0 };
|
762
|
+
/**
|
763
|
+
* @constant
|
764
|
+
* @summary version string
|
765
|
+
*/
|
766
|
+
c.version_string = "1.49";
|
767
|
+
})(GeographicLib.Constants);
|
768
|
+
|
769
|
+
(function(
|
770
|
+
/**
|
771
|
+
* @exports GeographicLib/Math
|
772
|
+
* @description Some useful mathematical constants and functions (mainly for
|
773
|
+
* internal use).
|
774
|
+
*/
|
775
|
+
m) {
|
776
|
+
|
777
|
+
/**
|
778
|
+
* @summary The number of digits of precision in floating-point numbers.
|
779
|
+
* @constant {number}
|
780
|
+
*/
|
781
|
+
m.digits = 53;
|
782
|
+
/**
|
783
|
+
* @summary The machine epsilon.
|
784
|
+
* @constant {number}
|
785
|
+
*/
|
786
|
+
m.epsilon = Math.pow(0.5, m.digits - 1);
|
787
|
+
/**
|
788
|
+
* @summary The factor to convert degrees to radians.
|
789
|
+
* @constant {number}
|
790
|
+
*/
|
791
|
+
m.degree = Math.PI/180;
|
792
|
+
|
793
|
+
/**
|
794
|
+
* @summary Square a number.
|
795
|
+
* @param {number} x the number.
|
796
|
+
* @returns {number} the square.
|
797
|
+
*/
|
798
|
+
m.sq = function(x) { return x * x; };
|
799
|
+
|
800
|
+
/**
|
801
|
+
* @summary The hypotenuse function.
|
802
|
+
* @param {number} x the first side.
|
803
|
+
* @param {number} y the second side.
|
804
|
+
* @returns {number} the hypotenuse.
|
805
|
+
*/
|
806
|
+
m.hypot = function(x, y) {
|
807
|
+
var a, b;
|
808
|
+
x = Math.abs(x);
|
809
|
+
y = Math.abs(y);
|
810
|
+
a = Math.max(x, y); b = Math.min(x, y) / (a ? a : 1);
|
811
|
+
return a * Math.sqrt(1 + b * b);
|
812
|
+
};
|
813
|
+
|
814
|
+
/**
|
815
|
+
* @summary Cube root function.
|
816
|
+
* @param {number} x the argument.
|
817
|
+
* @returns {number} the real cube root.
|
818
|
+
*/
|
819
|
+
m.cbrt = function(x) {
|
820
|
+
var y = Math.pow(Math.abs(x), 1/3);
|
821
|
+
return x < 0 ? -y : y;
|
822
|
+
};
|
823
|
+
|
824
|
+
/**
|
825
|
+
* @summary The log1p function.
|
826
|
+
* @param {number} x the argument.
|
827
|
+
* @returns {number} log(1 + x).
|
828
|
+
*/
|
829
|
+
m.log1p = function(x) {
|
830
|
+
var y = 1 + x,
|
831
|
+
z = y - 1;
|
832
|
+
// Here's the explanation for this magic: y = 1 + z, exactly, and z
|
833
|
+
// approx x, thus log(y)/z (which is nearly constant near z = 0) returns
|
834
|
+
// a good approximation to the true log(1 + x)/x. The multiplication x *
|
835
|
+
// (log(y)/z) introduces little additional error.
|
836
|
+
return z === 0 ? x : x * Math.log(y) / z;
|
837
|
+
};
|
838
|
+
|
839
|
+
/**
|
840
|
+
* @summary Inverse hyperbolic tangent.
|
841
|
+
* @param {number} x the argument.
|
842
|
+
* @returns {number} tanh<sup>−1</sup> x.
|
843
|
+
*/
|
844
|
+
m.atanh = function(x) {
|
845
|
+
var y = Math.abs(x); // Enforce odd parity
|
846
|
+
y = m.log1p(2 * y/(1 - y))/2;
|
847
|
+
return x < 0 ? -y : y;
|
848
|
+
};
|
849
|
+
|
850
|
+
/**
|
851
|
+
* @summary Copy the sign.
|
852
|
+
* @param {number} x gives the magitude of the result.
|
853
|
+
* @param {number} y gives the sign of the result.
|
854
|
+
* @returns {number} value with the magnitude of x and with the sign of y.
|
855
|
+
*/
|
856
|
+
m.copysign = function(x, y) {
|
857
|
+
return Math.abs(x) * (y < 0 || (y === 0 && 1/y < 0) ? -1 : 1);
|
858
|
+
};
|
859
|
+
|
860
|
+
/**
|
861
|
+
* @summary An error-free sum.
|
862
|
+
* @param {number} u
|
863
|
+
* @param {number} v
|
864
|
+
* @returns {object} sum with sum.s = round(u + v) and sum.t is u + v −
|
865
|
+
* round(u + v)
|
866
|
+
*/
|
867
|
+
m.sum = function(u, v) {
|
868
|
+
var s = u + v,
|
869
|
+
up = s - v,
|
870
|
+
vpp = s - up,
|
871
|
+
t;
|
872
|
+
up -= u;
|
873
|
+
vpp -= v;
|
874
|
+
t = -(up + vpp);
|
875
|
+
// u + v = s + t
|
876
|
+
// = round(u + v) + t
|
877
|
+
return {s: s, t: t};
|
878
|
+
};
|
879
|
+
|
880
|
+
/**
|
881
|
+
* @summary Evaluate a polynomial.
|
882
|
+
* @param {integer} N the order of the polynomial.
|
883
|
+
* @param {array} p the coefficient array (of size N + 1) (leading
|
884
|
+
* order coefficient first)
|
885
|
+
* @param {number} x the variable.
|
886
|
+
* @returns {number} the value of the polynomial.
|
887
|
+
*/
|
888
|
+
m.polyval = function(N, p, s, x) {
|
889
|
+
var y = N < 0 ? 0 : p[s++];
|
890
|
+
while (--N >= 0) y = y * x + p[s++];
|
891
|
+
return y;
|
892
|
+
};
|
893
|
+
|
894
|
+
/**
|
895
|
+
* @summary Coarsen a value close to zero.
|
896
|
+
* @param {number} x
|
897
|
+
* @returns {number} the coarsened value.
|
898
|
+
*/
|
899
|
+
m.AngRound = function(x) {
|
900
|
+
// The makes the smallest gap in x = 1/16 - nextafter(1/16, 0) = 1/2^57 for
|
901
|
+
// reals = 0.7 pm on the earth if x is an angle in degrees. (This is about
|
902
|
+
// 1000 times more resolution than we get with angles around 90 degrees.)
|
903
|
+
// We use this to avoid having to deal with near singular cases when x is
|
904
|
+
// non-zero but tiny (e.g., 1.0e-200). This converts -0 to +0; however
|
905
|
+
// tiny negative numbers get converted to -0.
|
906
|
+
if (x === 0) return x;
|
907
|
+
var z = 1/16,
|
908
|
+
y = Math.abs(x);
|
909
|
+
// The compiler mustn't "simplify" z - (z - y) to y
|
910
|
+
y = y < z ? z - (z - y) : y;
|
911
|
+
return x < 0 ? -y : y;
|
912
|
+
};
|
913
|
+
|
914
|
+
/**
|
915
|
+
* @summary Normalize an angle.
|
916
|
+
* @param {number} x the angle in degrees.
|
917
|
+
* @returns {number} the angle reduced to the range (−180°,
|
918
|
+
* 180°].
|
919
|
+
*/
|
920
|
+
m.AngNormalize = function(x) {
|
921
|
+
// Place angle in [-180, 180).
|
922
|
+
x = x % 360;
|
923
|
+
return x <= -180 ? x + 360 : (x <= 180 ? x : x - 360);
|
924
|
+
};
|
925
|
+
|
926
|
+
/**
|
927
|
+
* @summary Normalize a latitude.
|
928
|
+
* @param {number} x the angle in degrees.
|
929
|
+
* @returns {number} x if it is in the range [−90°, 90°],
|
930
|
+
* otherwise return NaN.
|
931
|
+
*/
|
932
|
+
m.LatFix = function(x) {
|
933
|
+
// Replace angle with NaN if outside [-90, 90].
|
934
|
+
return Math.abs(x) > 90 ? Number.NaN : x;
|
935
|
+
};
|
936
|
+
|
937
|
+
/**
|
938
|
+
* @summary The exact difference of two angles reduced to (−180°,
|
939
|
+
* 180°]
|
940
|
+
* @param {number} x the first angle in degrees.
|
941
|
+
* @param {number} y the second angle in degrees.
|
942
|
+
* @return {object} diff the exact difference, y − x.
|
943
|
+
*
|
944
|
+
* This computes z = y − x exactly, reduced to (−180°,
|
945
|
+
* 180°]; and then sets diff.s = d = round(z) and diff.t = e = z −
|
946
|
+
* round(z). If d = −180, then e > 0; If d = 180, then e ≤ 0.
|
947
|
+
*/
|
948
|
+
m.AngDiff = function(x, y) {
|
949
|
+
// Compute y - x and reduce to [-180,180] accurately.
|
950
|
+
var r = m.sum(m.AngNormalize(-x), m.AngNormalize(y)),
|
951
|
+
d = m.AngNormalize(r.s),
|
952
|
+
t = r.t;
|
953
|
+
return m.sum(d === 180 && t > 0 ? -180 : d, t);
|
954
|
+
};
|
955
|
+
|
956
|
+
/**
|
957
|
+
* @summary Evaluate the sine and cosine function with the argument in
|
958
|
+
* degrees
|
959
|
+
* @param {number} x in degrees.
|
960
|
+
* @returns {object} r with r.s = sin(x) and r.c = cos(x).
|
961
|
+
*/
|
962
|
+
m.sincosd = function(x) {
|
963
|
+
// In order to minimize round-off errors, this function exactly reduces
|
964
|
+
// the argument to the range [-45, 45] before converting it to radians.
|
965
|
+
var r, q, s, c, sinx, cosx;
|
966
|
+
r = x % 360;
|
967
|
+
q = Math.floor(r / 90 + 0.5);
|
968
|
+
r -= 90 * q;
|
969
|
+
// now abs(r) <= 45
|
970
|
+
r *= this.degree;
|
971
|
+
// Possibly could call the gnu extension sincos
|
972
|
+
s = Math.sin(r); c = Math.cos(r);
|
973
|
+
switch (q & 3) {
|
974
|
+
case 0: sinx = s; cosx = c; break;
|
975
|
+
case 1: sinx = c; cosx = -s; break;
|
976
|
+
case 2: sinx = -s; cosx = -c; break;
|
977
|
+
default: sinx = -c; cosx = s; break; // case 3
|
978
|
+
}
|
979
|
+
if (x !== 0) { sinx += 0; cosx += 0; }
|
980
|
+
return {s: sinx, c: cosx};
|
981
|
+
};
|
982
|
+
|
983
|
+
/**
|
984
|
+
* @summary Evaluate the atan2 function with the result in degrees
|
985
|
+
* @param {number} y
|
986
|
+
* @param {number} x
|
987
|
+
* @returns atan2(y, x) in degrees, in the range (−180°
|
988
|
+
* 180°].
|
989
|
+
*/
|
990
|
+
m.atan2d = function(y, x) {
|
991
|
+
// In order to minimize round-off errors, this function rearranges the
|
992
|
+
// arguments so that result of atan2 is in the range [-pi/4, pi/4] before
|
993
|
+
// converting it to degrees and mapping the result to the correct
|
994
|
+
// quadrant.
|
995
|
+
var q = 0, t, ang;
|
996
|
+
if (Math.abs(y) > Math.abs(x)) { t = x; x = y; y = t; q = 2; }
|
997
|
+
if (x < 0) { x = -x; ++q; }
|
998
|
+
// here x >= 0 and x >= abs(y), so angle is in [-pi/4, pi/4]
|
999
|
+
ang = Math.atan2(y, x) / this.degree;
|
1000
|
+
switch (q) {
|
1001
|
+
// Note that atan2d(-0.0, 1.0) will return -0. However, we expect that
|
1002
|
+
// atan2d will not be called with y = -0. If need be, include
|
1003
|
+
//
|
1004
|
+
// case 0: ang = 0 + ang; break;
|
1005
|
+
//
|
1006
|
+
// and handle mpfr as in AngRound.
|
1007
|
+
case 1: ang = (y >= 0 ? 180 : -180) - ang; break;
|
1008
|
+
case 2: ang = 90 - ang; break;
|
1009
|
+
case 3: ang = -90 + ang; break;
|
1010
|
+
}
|
1011
|
+
return ang;
|
1012
|
+
};
|
1013
|
+
})(GeographicLib.Math);
|
1014
|
+
|
1015
|
+
(function(
|
1016
|
+
/**
|
1017
|
+
* @exports GeographicLib/Accumulator
|
1018
|
+
* @description Accurate summation via the
|
1019
|
+
* {@link module:GeographicLib/Accumulator.Accumulator Accumulator} class
|
1020
|
+
* (mainly for internal use).
|
1021
|
+
*/
|
1022
|
+
a, m) {
|
1023
|
+
|
1024
|
+
/**
|
1025
|
+
* @class
|
1026
|
+
* @summary Accurate summation of many numbers.
|
1027
|
+
* @classdesc This allows many numbers to be added together with twice the
|
1028
|
+
* normal precision. In the documentation of the member functions, sum
|
1029
|
+
* stands for the value currently held in the accumulator.
|
1030
|
+
* @param {number | Accumulator} [y = 0] set sum = y.
|
1031
|
+
*/
|
1032
|
+
a.Accumulator = function(y) {
|
1033
|
+
this.Set(y);
|
1034
|
+
};
|
1035
|
+
|
1036
|
+
/**
|
1037
|
+
* @summary Set the accumulator to a number.
|
1038
|
+
* @param {number | Accumulator} [y = 0] set sum = y.
|
1039
|
+
*/
|
1040
|
+
a.Accumulator.prototype.Set = function(y) {
|
1041
|
+
if (!y) y = 0;
|
1042
|
+
if (y.constructor === a.Accumulator) {
|
1043
|
+
this._s = y._s;
|
1044
|
+
this._t = y._t;
|
1045
|
+
} else {
|
1046
|
+
this._s = y;
|
1047
|
+
this._t = 0;
|
1048
|
+
}
|
1049
|
+
};
|
1050
|
+
|
1051
|
+
/**
|
1052
|
+
* @summary Add a number to the accumulator.
|
1053
|
+
* @param {number} [y = 0] set sum += y.
|
1054
|
+
*/
|
1055
|
+
a.Accumulator.prototype.Add = function(y) {
|
1056
|
+
// Here's Shewchuk's solution...
|
1057
|
+
// Accumulate starting at least significant end
|
1058
|
+
var u = m.sum(y, this._t),
|
1059
|
+
v = m.sum(u.s, this._s);
|
1060
|
+
u = u.t;
|
1061
|
+
this._s = v.s;
|
1062
|
+
this._t = v.t;
|
1063
|
+
// Start is _s, _t decreasing and non-adjacent. Sum is now (s + t + u)
|
1064
|
+
// exactly with s, t, u non-adjacent and in decreasing order (except
|
1065
|
+
// for possible zeros). The following code tries to normalize the
|
1066
|
+
// result. Ideally, we want _s = round(s+t+u) and _u = round(s+t+u -
|
1067
|
+
// _s). The follow does an approximate job (and maintains the
|
1068
|
+
// decreasing non-adjacent property). Here are two "failures" using
|
1069
|
+
// 3-bit floats:
|
1070
|
+
//
|
1071
|
+
// Case 1: _s is not equal to round(s+t+u) -- off by 1 ulp
|
1072
|
+
// [12, -1] - 8 -> [4, 0, -1] -> [4, -1] = 3 should be [3, 0] = 3
|
1073
|
+
//
|
1074
|
+
// Case 2: _s+_t is not as close to s+t+u as it shold be
|
1075
|
+
// [64, 5] + 4 -> [64, 8, 1] -> [64, 8] = 72 (off by 1)
|
1076
|
+
// should be [80, -7] = 73 (exact)
|
1077
|
+
//
|
1078
|
+
// "Fixing" these problems is probably not worth the expense. The
|
1079
|
+
// representation inevitably leads to small errors in the accumulated
|
1080
|
+
// values. The additional errors illustrated here amount to 1 ulp of
|
1081
|
+
// the less significant word during each addition to the Accumulator
|
1082
|
+
// and an additional possible error of 1 ulp in the reported sum.
|
1083
|
+
//
|
1084
|
+
// Incidentally, the "ideal" representation described above is not
|
1085
|
+
// canonical, because _s = round(_s + _t) may not be true. For
|
1086
|
+
// example, with 3-bit floats:
|
1087
|
+
//
|
1088
|
+
// [128, 16] + 1 -> [160, -16] -- 160 = round(145).
|
1089
|
+
// But [160, 0] - 16 -> [128, 16] -- 128 = round(144).
|
1090
|
+
//
|
1091
|
+
if (this._s === 0) // This implies t == 0,
|
1092
|
+
this._s = u; // so result is u
|
1093
|
+
else
|
1094
|
+
this._t += u; // otherwise just accumulate u to t.
|
1095
|
+
};
|
1096
|
+
|
1097
|
+
/**
|
1098
|
+
* @summary Return the result of adding a number to sum (but
|
1099
|
+
* don't change sum).
|
1100
|
+
* @param {number} [y = 0] the number to be added to the sum.
|
1101
|
+
* @return sum + y.
|
1102
|
+
*/
|
1103
|
+
a.Accumulator.prototype.Sum = function(y) {
|
1104
|
+
var b;
|
1105
|
+
if (!y)
|
1106
|
+
return this._s;
|
1107
|
+
else {
|
1108
|
+
b = new a.Accumulator(this);
|
1109
|
+
b.Add(y);
|
1110
|
+
return b._s;
|
1111
|
+
}
|
1112
|
+
};
|
1113
|
+
|
1114
|
+
/**
|
1115
|
+
* @summary Set sum = −sum.
|
1116
|
+
*/
|
1117
|
+
a.Accumulator.prototype.Negate = function() {
|
1118
|
+
this._s *= -1;
|
1119
|
+
this._t *= -1;
|
1120
|
+
};
|
1121
|
+
})(GeographicLib.Accumulator, GeographicLib.Math);
|
1122
|
+
|
1123
|
+
/**************** Geodesic.js ****************/
|
1124
|
+
/*
|
1125
|
+
* Geodesic.js
|
1126
|
+
* Transcription of Geodesic.[ch]pp into JavaScript.
|
1127
|
+
*
|
1128
|
+
* See the documentation for the C++ class. The conversion is a literal
|
1129
|
+
* conversion from C++.
|
1130
|
+
*
|
1131
|
+
* The algorithms are derived in
|
1132
|
+
*
|
1133
|
+
* Charles F. F. Karney,
|
1134
|
+
* Algorithms for geodesics, J. Geodesy 87, 43-55 (2013);
|
1135
|
+
* https://doi.org/10.1007/s00190-012-0578-z
|
1136
|
+
* Addenda: https://geographiclib.sourceforge.io/geod-addenda.html
|
1137
|
+
*
|
1138
|
+
* Copyright (c) Charles Karney (2011-2017) <charles@karney.com> and licensed
|
1139
|
+
* under the MIT/X11 License. For more information, see
|
1140
|
+
* https://geographiclib.sourceforge.io/
|
1141
|
+
*/
|
1142
|
+
|
1143
|
+
// Load AFTER Math.js
|
1144
|
+
|
1145
|
+
GeographicLib.Geodesic = {};
|
1146
|
+
GeographicLib.GeodesicLine = {};
|
1147
|
+
GeographicLib.PolygonArea = {};
|
1148
|
+
|
1149
|
+
(function(
|
1150
|
+
/**
|
1151
|
+
* @exports GeographicLib/Geodesic
|
1152
|
+
* @description Solve geodesic problems via the
|
1153
|
+
* {@link module:GeographicLib/Geodesic.Geodesic Geodesic} class.
|
1154
|
+
*/
|
1155
|
+
g, l, p, m, c) {
|
1156
|
+
|
1157
|
+
var GEOGRAPHICLIB_GEODESIC_ORDER = 6,
|
1158
|
+
nA1_ = GEOGRAPHICLIB_GEODESIC_ORDER,
|
1159
|
+
nA2_ = GEOGRAPHICLIB_GEODESIC_ORDER,
|
1160
|
+
nA3_ = GEOGRAPHICLIB_GEODESIC_ORDER,
|
1161
|
+
nA3x_ = nA3_,
|
1162
|
+
nC3x_, nC4x_,
|
1163
|
+
maxit1_ = 20,
|
1164
|
+
maxit2_ = maxit1_ + m.digits + 10,
|
1165
|
+
tol0_ = m.epsilon,
|
1166
|
+
tol1_ = 200 * tol0_,
|
1167
|
+
tol2_ = Math.sqrt(tol0_),
|
1168
|
+
tolb_ = tol0_ * tol1_,
|
1169
|
+
xthresh_ = 1000 * tol2_,
|
1170
|
+
CAP_NONE = 0,
|
1171
|
+
CAP_ALL = 0x1F,
|
1172
|
+
CAP_MASK = CAP_ALL,
|
1173
|
+
OUT_ALL = 0x7F80,
|
1174
|
+
astroid,
|
1175
|
+
A1m1f_coeff, C1f_coeff, C1pf_coeff,
|
1176
|
+
A2m1f_coeff, C2f_coeff,
|
1177
|
+
A3_coeff, C3_coeff, C4_coeff;
|
1178
|
+
|
1179
|
+
g.tiny_ = Math.sqrt(Number.MIN_VALUE);
|
1180
|
+
g.nC1_ = GEOGRAPHICLIB_GEODESIC_ORDER;
|
1181
|
+
g.nC1p_ = GEOGRAPHICLIB_GEODESIC_ORDER;
|
1182
|
+
g.nC2_ = GEOGRAPHICLIB_GEODESIC_ORDER;
|
1183
|
+
g.nC3_ = GEOGRAPHICLIB_GEODESIC_ORDER;
|
1184
|
+
g.nC4_ = GEOGRAPHICLIB_GEODESIC_ORDER;
|
1185
|
+
nC3x_ = (g.nC3_ * (g.nC3_ - 1)) / 2;
|
1186
|
+
nC4x_ = (g.nC4_ * (g.nC4_ + 1)) / 2;
|
1187
|
+
g.CAP_C1 = 1<<0;
|
1188
|
+
g.CAP_C1p = 1<<1;
|
1189
|
+
g.CAP_C2 = 1<<2;
|
1190
|
+
g.CAP_C3 = 1<<3;
|
1191
|
+
g.CAP_C4 = 1<<4;
|
1192
|
+
|
1193
|
+
g.NONE = 0;
|
1194
|
+
g.ARC = 1<<6;
|
1195
|
+
g.LATITUDE = 1<<7 | CAP_NONE;
|
1196
|
+
g.LONGITUDE = 1<<8 | g.CAP_C3;
|
1197
|
+
g.AZIMUTH = 1<<9 | CAP_NONE;
|
1198
|
+
g.DISTANCE = 1<<10 | g.CAP_C1;
|
1199
|
+
g.STANDARD = g.LATITUDE | g.LONGITUDE | g.AZIMUTH | g.DISTANCE;
|
1200
|
+
g.DISTANCE_IN = 1<<11 | g.CAP_C1 | g.CAP_C1p;
|
1201
|
+
g.REDUCEDLENGTH = 1<<12 | g.CAP_C1 | g.CAP_C2;
|
1202
|
+
g.GEODESICSCALE = 1<<13 | g.CAP_C1 | g.CAP_C2;
|
1203
|
+
g.AREA = 1<<14 | g.CAP_C4;
|
1204
|
+
g.ALL = OUT_ALL| CAP_ALL;
|
1205
|
+
g.LONG_UNROLL = 1<<15;
|
1206
|
+
g.OUT_MASK = OUT_ALL| g.LONG_UNROLL;
|
1207
|
+
|
1208
|
+
g.SinCosSeries = function(sinp, sinx, cosx, c) {
|
1209
|
+
// Evaluate
|
1210
|
+
// y = sinp ? sum(c[i] * sin( 2*i * x), i, 1, n) :
|
1211
|
+
// sum(c[i] * cos((2*i+1) * x), i, 0, n-1)
|
1212
|
+
// using Clenshaw summation. N.B. c[0] is unused for sin series
|
1213
|
+
// Approx operation count = (n + 5) mult and (2 * n + 2) add
|
1214
|
+
var k = c.length, // Point to one beyond last element
|
1215
|
+
n = k - (sinp ? 1 : 0),
|
1216
|
+
ar = 2 * (cosx - sinx) * (cosx + sinx), // 2 * cos(2 * x)
|
1217
|
+
y0 = n & 1 ? c[--k] : 0, y1 = 0; // accumulators for sum
|
1218
|
+
// Now n is even
|
1219
|
+
n = Math.floor(n/2);
|
1220
|
+
while (n--) {
|
1221
|
+
// Unroll loop x 2, so accumulators return to their original role
|
1222
|
+
y1 = ar * y0 - y1 + c[--k];
|
1223
|
+
y0 = ar * y1 - y0 + c[--k];
|
1224
|
+
}
|
1225
|
+
return (sinp ? 2 * sinx * cosx * y0 : // sin(2 * x) * y0
|
1226
|
+
cosx * (y0 - y1)); // cos(x) * (y0 - y1)
|
1227
|
+
};
|
1228
|
+
|
1229
|
+
astroid = function(x, y) {
|
1230
|
+
// Solve k^4+2*k^3-(x^2+y^2-1)*k^2-2*y^2*k-y^2 = 0 for positive
|
1231
|
+
// root k. This solution is adapted from Geocentric::Reverse.
|
1232
|
+
var k,
|
1233
|
+
p = m.sq(x),
|
1234
|
+
q = m.sq(y),
|
1235
|
+
r = (p + q - 1) / 6,
|
1236
|
+
S, r2, r3, disc, u, T3, T, ang, v, uv, w;
|
1237
|
+
if ( !(q === 0 && r <= 0) ) {
|
1238
|
+
// Avoid possible division by zero when r = 0 by multiplying
|
1239
|
+
// equations for s and t by r^3 and r, resp.
|
1240
|
+
S = p * q / 4; // S = r^3 * s
|
1241
|
+
r2 = m.sq(r);
|
1242
|
+
r3 = r * r2;
|
1243
|
+
// The discriminant of the quadratic equation for T3. This is
|
1244
|
+
// zero on the evolute curve p^(1/3)+q^(1/3) = 1
|
1245
|
+
disc = S * (S + 2 * r3);
|
1246
|
+
u = r;
|
1247
|
+
if (disc >= 0) {
|
1248
|
+
T3 = S + r3;
|
1249
|
+
// Pick the sign on the sqrt to maximize abs(T3). This
|
1250
|
+
// minimizes loss of precision due to cancellation. The
|
1251
|
+
// result is unchanged because of the way the T is used
|
1252
|
+
// in definition of u.
|
1253
|
+
T3 += T3 < 0 ? -Math.sqrt(disc) : Math.sqrt(disc); // T3 = (r * t)^3
|
1254
|
+
// N.B. cbrt always returns the real root. cbrt(-8) = -2.
|
1255
|
+
T = m.cbrt(T3); // T = r * t
|
1256
|
+
// T can be zero; but then r2 / T -> 0.
|
1257
|
+
u += T + (T !== 0 ? r2 / T : 0);
|
1258
|
+
} else {
|
1259
|
+
// T is complex, but the way u is defined the result is real.
|
1260
|
+
ang = Math.atan2(Math.sqrt(-disc), -(S + r3));
|
1261
|
+
// There are three possible cube roots. We choose the
|
1262
|
+
// root which avoids cancellation. Note that disc < 0
|
1263
|
+
// implies that r < 0.
|
1264
|
+
u += 2 * r * Math.cos(ang / 3);
|
1265
|
+
}
|
1266
|
+
v = Math.sqrt(m.sq(u) + q); // guaranteed positive
|
1267
|
+
// Avoid loss of accuracy when u < 0.
|
1268
|
+
uv = u < 0 ? q / (v - u) : u + v; // u+v, guaranteed positive
|
1269
|
+
w = (uv - q) / (2 * v); // positive?
|
1270
|
+
// Rearrange expression for k to avoid loss of accuracy due to
|
1271
|
+
// subtraction. Division by 0 not possible because uv > 0, w >= 0.
|
1272
|
+
k = uv / (Math.sqrt(uv + m.sq(w)) + w); // guaranteed positive
|
1273
|
+
} else { // q == 0 && r <= 0
|
1274
|
+
// y = 0 with |x| <= 1. Handle this case directly.
|
1275
|
+
// for y small, positive root is k = abs(y)/sqrt(1-x^2)
|
1276
|
+
k = 0;
|
1277
|
+
}
|
1278
|
+
return k;
|
1279
|
+
};
|
1280
|
+
|
1281
|
+
A1m1f_coeff = [
|
1282
|
+
// (1-eps)*A1-1, polynomial in eps2 of order 3
|
1283
|
+
+1, 4, 64, 0, 256
|
1284
|
+
];
|
1285
|
+
|
1286
|
+
// The scale factor A1-1 = mean value of (d/dsigma)I1 - 1
|
1287
|
+
g.A1m1f = function(eps) {
|
1288
|
+
var p = Math.floor(nA1_/2),
|
1289
|
+
t = m.polyval(p, A1m1f_coeff, 0, m.sq(eps)) / A1m1f_coeff[p + 1];
|
1290
|
+
return (t + eps) / (1 - eps);
|
1291
|
+
};
|
1292
|
+
|
1293
|
+
C1f_coeff = [
|
1294
|
+
// C1[1]/eps^1, polynomial in eps2 of order 2
|
1295
|
+
-1, 6, -16, 32,
|
1296
|
+
// C1[2]/eps^2, polynomial in eps2 of order 2
|
1297
|
+
-9, 64, -128, 2048,
|
1298
|
+
// C1[3]/eps^3, polynomial in eps2 of order 1
|
1299
|
+
+9, -16, 768,
|
1300
|
+
// C1[4]/eps^4, polynomial in eps2 of order 1
|
1301
|
+
+3, -5, 512,
|
1302
|
+
// C1[5]/eps^5, polynomial in eps2 of order 0
|
1303
|
+
-7, 1280,
|
1304
|
+
// C1[6]/eps^6, polynomial in eps2 of order 0
|
1305
|
+
-7, 2048
|
1306
|
+
];
|
1307
|
+
|
1308
|
+
// The coefficients C1[l] in the Fourier expansion of B1
|
1309
|
+
g.C1f = function(eps, c) {
|
1310
|
+
var eps2 = m.sq(eps),
|
1311
|
+
d = eps,
|
1312
|
+
o = 0,
|
1313
|
+
l, p;
|
1314
|
+
for (l = 1; l <= g.nC1_; ++l) { // l is index of C1p[l]
|
1315
|
+
p = Math.floor((g.nC1_ - l) / 2); // order of polynomial in eps^2
|
1316
|
+
c[l] = d * m.polyval(p, C1f_coeff, o, eps2) / C1f_coeff[o + p + 1];
|
1317
|
+
o += p + 2;
|
1318
|
+
d *= eps;
|
1319
|
+
}
|
1320
|
+
};
|
1321
|
+
|
1322
|
+
C1pf_coeff = [
|
1323
|
+
// C1p[1]/eps^1, polynomial in eps2 of order 2
|
1324
|
+
+205, -432, 768, 1536,
|
1325
|
+
// C1p[2]/eps^2, polynomial in eps2 of order 2
|
1326
|
+
+4005, -4736, 3840, 12288,
|
1327
|
+
// C1p[3]/eps^3, polynomial in eps2 of order 1
|
1328
|
+
-225, 116, 384,
|
1329
|
+
// C1p[4]/eps^4, polynomial in eps2 of order 1
|
1330
|
+
-7173, 2695, 7680,
|
1331
|
+
// C1p[5]/eps^5, polynomial in eps2 of order 0
|
1332
|
+
+3467, 7680,
|
1333
|
+
// C1p[6]/eps^6, polynomial in eps2 of order 0
|
1334
|
+
+38081, 61440
|
1335
|
+
];
|
1336
|
+
|
1337
|
+
// The coefficients C1p[l] in the Fourier expansion of B1p
|
1338
|
+
g.C1pf = function(eps, c) {
|
1339
|
+
var eps2 = m.sq(eps),
|
1340
|
+
d = eps,
|
1341
|
+
o = 0,
|
1342
|
+
l, p;
|
1343
|
+
for (l = 1; l <= g.nC1p_; ++l) { // l is index of C1p[l]
|
1344
|
+
p = Math.floor((g.nC1p_ - l) / 2); // order of polynomial in eps^2
|
1345
|
+
c[l] = d * m.polyval(p, C1pf_coeff, o, eps2) / C1pf_coeff[o + p + 1];
|
1346
|
+
o += p + 2;
|
1347
|
+
d *= eps;
|
1348
|
+
}
|
1349
|
+
};
|
1350
|
+
|
1351
|
+
A2m1f_coeff = [
|
1352
|
+
// (eps+1)*A2-1, polynomial in eps2 of order 3
|
1353
|
+
-11, -28, -192, 0, 256
|
1354
|
+
];
|
1355
|
+
|
1356
|
+
// The scale factor A2-1 = mean value of (d/dsigma)I2 - 1
|
1357
|
+
g.A2m1f = function(eps) {
|
1358
|
+
var p = Math.floor(nA2_/2),
|
1359
|
+
t = m.polyval(p, A2m1f_coeff, 0, m.sq(eps)) / A2m1f_coeff[p + 1];
|
1360
|
+
return (t - eps) / (1 + eps);
|
1361
|
+
};
|
1362
|
+
|
1363
|
+
C2f_coeff = [
|
1364
|
+
// C2[1]/eps^1, polynomial in eps2 of order 2
|
1365
|
+
+1, 2, 16, 32,
|
1366
|
+
// C2[2]/eps^2, polynomial in eps2 of order 2
|
1367
|
+
+35, 64, 384, 2048,
|
1368
|
+
// C2[3]/eps^3, polynomial in eps2 of order 1
|
1369
|
+
+15, 80, 768,
|
1370
|
+
// C2[4]/eps^4, polynomial in eps2 of order 1
|
1371
|
+
+7, 35, 512,
|
1372
|
+
// C2[5]/eps^5, polynomial in eps2 of order 0
|
1373
|
+
+63, 1280,
|
1374
|
+
// C2[6]/eps^6, polynomial in eps2 of order 0
|
1375
|
+
+77, 2048
|
1376
|
+
];
|
1377
|
+
|
1378
|
+
// The coefficients C2[l] in the Fourier expansion of B2
|
1379
|
+
g.C2f = function(eps, c) {
|
1380
|
+
var eps2 = m.sq(eps),
|
1381
|
+
d = eps,
|
1382
|
+
o = 0,
|
1383
|
+
l, p;
|
1384
|
+
for (l = 1; l <= g.nC2_; ++l) { // l is index of C2[l]
|
1385
|
+
p = Math.floor((g.nC2_ - l) / 2); // order of polynomial in eps^2
|
1386
|
+
c[l] = d * m.polyval(p, C2f_coeff, o, eps2) / C2f_coeff[o + p + 1];
|
1387
|
+
o += p + 2;
|
1388
|
+
d *= eps;
|
1389
|
+
}
|
1390
|
+
};
|
1391
|
+
|
1392
|
+
/**
|
1393
|
+
* @class
|
1394
|
+
* @property {number} a the equatorial radius (meters).
|
1395
|
+
* @property {number} f the flattening.
|
1396
|
+
* @summary Initialize a Geodesic object for a specific ellipsoid.
|
1397
|
+
* @classdesc Performs geodesic calculations on an ellipsoid of revolution.
|
1398
|
+
* The routines for solving the direct and inverse problems return an
|
1399
|
+
* object with some of the following fields set: lat1, lon1, azi1, lat2,
|
1400
|
+
* lon2, azi2, s12, a12, m12, M12, M21, S12. See {@tutorial 2-interface},
|
1401
|
+
* "The results".
|
1402
|
+
* @example
|
1403
|
+
* var GeographicLib = require("geographiclib"),
|
1404
|
+
* geod = GeographicLib.Geodesic.WGS84;
|
1405
|
+
* var inv = geod.Inverse(1,2,3,4);
|
1406
|
+
* console.log("lat1 = " + inv.lat1 + ", lon1 = " + inv.lon1 +
|
1407
|
+
* ", lat2 = " + inv.lat2 + ", lon2 = " + inv.lon2 +
|
1408
|
+
* ",\nazi1 = " + inv.azi1 + ", azi2 = " + inv.azi2 +
|
1409
|
+
* ", s12 = " + inv.s12);
|
1410
|
+
* @param {number} a the equatorial radius of the ellipsoid (meters).
|
1411
|
+
* @param {number} f the flattening of the ellipsoid. Setting f = 0 gives
|
1412
|
+
* a sphere (on which geodesics are great circles). Negative f gives a
|
1413
|
+
* prolate ellipsoid.
|
1414
|
+
* @throws an error if the parameters are illegal.
|
1415
|
+
*/
|
1416
|
+
g.Geodesic = function(a, f) {
|
1417
|
+
this.a = a;
|
1418
|
+
this.f = f;
|
1419
|
+
this._f1 = 1 - this.f;
|
1420
|
+
this._e2 = this.f * (2 - this.f);
|
1421
|
+
this._ep2 = this._e2 / m.sq(this._f1); // e2 / (1 - e2)
|
1422
|
+
this._n = this.f / ( 2 - this.f);
|
1423
|
+
this._b = this.a * this._f1;
|
1424
|
+
// authalic radius squared
|
1425
|
+
this._c2 = (m.sq(this.a) + m.sq(this._b) *
|
1426
|
+
(this._e2 === 0 ? 1 :
|
1427
|
+
(this._e2 > 0 ? m.atanh(Math.sqrt(this._e2)) :
|
1428
|
+
Math.atan(Math.sqrt(-this._e2))) /
|
1429
|
+
Math.sqrt(Math.abs(this._e2))))/2;
|
1430
|
+
// The sig12 threshold for "really short". Using the auxiliary sphere
|
1431
|
+
// solution with dnm computed at (bet1 + bet2) / 2, the relative error in
|
1432
|
+
// the azimuth consistency check is sig12^2 * abs(f) * min(1, 1-f/2) / 2.
|
1433
|
+
// (Error measured for 1/100 < b/a < 100 and abs(f) >= 1/1000. For a given
|
1434
|
+
// f and sig12, the max error occurs for lines near the pole. If the old
|
1435
|
+
// rule for computing dnm = (dn1 + dn2)/2 is used, then the error increases
|
1436
|
+
// by a factor of 2.) Setting this equal to epsilon gives sig12 = etol2.
|
1437
|
+
// Here 0.1 is a safety factor (error decreased by 100) and max(0.001,
|
1438
|
+
// abs(f)) stops etol2 getting too large in the nearly spherical case.
|
1439
|
+
this._etol2 = 0.1 * tol2_ /
|
1440
|
+
Math.sqrt( Math.max(0.001, Math.abs(this.f)) *
|
1441
|
+
Math.min(1.0, 1 - this.f/2) / 2 );
|
1442
|
+
if (!(isFinite(this.a) && this.a > 0))
|
1443
|
+
throw new Error("Equatorial radius is not positive");
|
1444
|
+
if (!(isFinite(this._b) && this._b > 0))
|
1445
|
+
throw new Error("Polar semi-axis is not positive");
|
1446
|
+
this._A3x = new Array(nA3x_);
|
1447
|
+
this._C3x = new Array(nC3x_);
|
1448
|
+
this._C4x = new Array(nC4x_);
|
1449
|
+
this.A3coeff();
|
1450
|
+
this.C3coeff();
|
1451
|
+
this.C4coeff();
|
1452
|
+
};
|
1453
|
+
|
1454
|
+
A3_coeff = [
|
1455
|
+
// A3, coeff of eps^5, polynomial in n of order 0
|
1456
|
+
-3, 128,
|
1457
|
+
// A3, coeff of eps^4, polynomial in n of order 1
|
1458
|
+
-2, -3, 64,
|
1459
|
+
// A3, coeff of eps^3, polynomial in n of order 2
|
1460
|
+
-1, -3, -1, 16,
|
1461
|
+
// A3, coeff of eps^2, polynomial in n of order 2
|
1462
|
+
+3, -1, -2, 8,
|
1463
|
+
// A3, coeff of eps^1, polynomial in n of order 1
|
1464
|
+
+1, -1, 2,
|
1465
|
+
// A3, coeff of eps^0, polynomial in n of order 0
|
1466
|
+
+1, 1
|
1467
|
+
];
|
1468
|
+
|
1469
|
+
// The scale factor A3 = mean value of (d/dsigma)I3
|
1470
|
+
g.Geodesic.prototype.A3coeff = function() {
|
1471
|
+
var o = 0, k = 0,
|
1472
|
+
j, p;
|
1473
|
+
for (j = nA3_ - 1; j >= 0; --j) { // coeff of eps^j
|
1474
|
+
p = Math.min(nA3_ - j - 1, j); // order of polynomial in n
|
1475
|
+
this._A3x[k++] = m.polyval(p, A3_coeff, o, this._n) /
|
1476
|
+
A3_coeff[o + p + 1];
|
1477
|
+
o += p + 2;
|
1478
|
+
}
|
1479
|
+
};
|
1480
|
+
|
1481
|
+
C3_coeff = [
|
1482
|
+
// C3[1], coeff of eps^5, polynomial in n of order 0
|
1483
|
+
+3, 128,
|
1484
|
+
// C3[1], coeff of eps^4, polynomial in n of order 1
|
1485
|
+
+2, 5, 128,
|
1486
|
+
// C3[1], coeff of eps^3, polynomial in n of order 2
|
1487
|
+
-1, 3, 3, 64,
|
1488
|
+
// C3[1], coeff of eps^2, polynomial in n of order 2
|
1489
|
+
-1, 0, 1, 8,
|
1490
|
+
// C3[1], coeff of eps^1, polynomial in n of order 1
|
1491
|
+
-1, 1, 4,
|
1492
|
+
// C3[2], coeff of eps^5, polynomial in n of order 0
|
1493
|
+
+5, 256,
|
1494
|
+
// C3[2], coeff of eps^4, polynomial in n of order 1
|
1495
|
+
+1, 3, 128,
|
1496
|
+
// C3[2], coeff of eps^3, polynomial in n of order 2
|
1497
|
+
-3, -2, 3, 64,
|
1498
|
+
// C3[2], coeff of eps^2, polynomial in n of order 2
|
1499
|
+
+1, -3, 2, 32,
|
1500
|
+
// C3[3], coeff of eps^5, polynomial in n of order 0
|
1501
|
+
+7, 512,
|
1502
|
+
// C3[3], coeff of eps^4, polynomial in n of order 1
|
1503
|
+
-10, 9, 384,
|
1504
|
+
// C3[3], coeff of eps^3, polynomial in n of order 2
|
1505
|
+
+5, -9, 5, 192,
|
1506
|
+
// C3[4], coeff of eps^5, polynomial in n of order 0
|
1507
|
+
+7, 512,
|
1508
|
+
// C3[4], coeff of eps^4, polynomial in n of order 1
|
1509
|
+
-14, 7, 512,
|
1510
|
+
// C3[5], coeff of eps^5, polynomial in n of order 0
|
1511
|
+
+21, 2560
|
1512
|
+
];
|
1513
|
+
|
1514
|
+
// The coefficients C3[l] in the Fourier expansion of B3
|
1515
|
+
g.Geodesic.prototype.C3coeff = function() {
|
1516
|
+
var o = 0, k = 0,
|
1517
|
+
l, j, p;
|
1518
|
+
for (l = 1; l < g.nC3_; ++l) { // l is index of C3[l]
|
1519
|
+
for (j = g.nC3_ - 1; j >= l; --j) { // coeff of eps^j
|
1520
|
+
p = Math.min(g.nC3_ - j - 1, j); // order of polynomial in n
|
1521
|
+
this._C3x[k++] = m.polyval(p, C3_coeff, o, this._n) /
|
1522
|
+
C3_coeff[o + p + 1];
|
1523
|
+
o += p + 2;
|
1524
|
+
}
|
1525
|
+
}
|
1526
|
+
};
|
1527
|
+
|
1528
|
+
C4_coeff = [
|
1529
|
+
// C4[0], coeff of eps^5, polynomial in n of order 0
|
1530
|
+
+97, 15015,
|
1531
|
+
// C4[0], coeff of eps^4, polynomial in n of order 1
|
1532
|
+
+1088, 156, 45045,
|
1533
|
+
// C4[0], coeff of eps^3, polynomial in n of order 2
|
1534
|
+
-224, -4784, 1573, 45045,
|
1535
|
+
// C4[0], coeff of eps^2, polynomial in n of order 3
|
1536
|
+
-10656, 14144, -4576, -858, 45045,
|
1537
|
+
// C4[0], coeff of eps^1, polynomial in n of order 4
|
1538
|
+
+64, 624, -4576, 6864, -3003, 15015,
|
1539
|
+
// C4[0], coeff of eps^0, polynomial in n of order 5
|
1540
|
+
+100, 208, 572, 3432, -12012, 30030, 45045,
|
1541
|
+
// C4[1], coeff of eps^5, polynomial in n of order 0
|
1542
|
+
+1, 9009,
|
1543
|
+
// C4[1], coeff of eps^4, polynomial in n of order 1
|
1544
|
+
-2944, 468, 135135,
|
1545
|
+
// C4[1], coeff of eps^3, polynomial in n of order 2
|
1546
|
+
+5792, 1040, -1287, 135135,
|
1547
|
+
// C4[1], coeff of eps^2, polynomial in n of order 3
|
1548
|
+
+5952, -11648, 9152, -2574, 135135,
|
1549
|
+
// C4[1], coeff of eps^1, polynomial in n of order 4
|
1550
|
+
-64, -624, 4576, -6864, 3003, 135135,
|
1551
|
+
// C4[2], coeff of eps^5, polynomial in n of order 0
|
1552
|
+
+8, 10725,
|
1553
|
+
// C4[2], coeff of eps^4, polynomial in n of order 1
|
1554
|
+
+1856, -936, 225225,
|
1555
|
+
// C4[2], coeff of eps^3, polynomial in n of order 2
|
1556
|
+
-8448, 4992, -1144, 225225,
|
1557
|
+
// C4[2], coeff of eps^2, polynomial in n of order 3
|
1558
|
+
-1440, 4160, -4576, 1716, 225225,
|
1559
|
+
// C4[3], coeff of eps^5, polynomial in n of order 0
|
1560
|
+
-136, 63063,
|
1561
|
+
// C4[3], coeff of eps^4, polynomial in n of order 1
|
1562
|
+
+1024, -208, 105105,
|
1563
|
+
// C4[3], coeff of eps^3, polynomial in n of order 2
|
1564
|
+
+3584, -3328, 1144, 315315,
|
1565
|
+
// C4[4], coeff of eps^5, polynomial in n of order 0
|
1566
|
+
-128, 135135,
|
1567
|
+
// C4[4], coeff of eps^4, polynomial in n of order 1
|
1568
|
+
-2560, 832, 405405,
|
1569
|
+
// C4[5], coeff of eps^5, polynomial in n of order 0
|
1570
|
+
+128, 99099
|
1571
|
+
];
|
1572
|
+
|
1573
|
+
g.Geodesic.prototype.C4coeff = function() {
|
1574
|
+
var o = 0, k = 0,
|
1575
|
+
l, j, p;
|
1576
|
+
for (l = 0; l < g.nC4_; ++l) { // l is index of C4[l]
|
1577
|
+
for (j = g.nC4_ - 1; j >= l; --j) { // coeff of eps^j
|
1578
|
+
p = g.nC4_ - j - 1; // order of polynomial in n
|
1579
|
+
this._C4x[k++] = m.polyval(p, C4_coeff, o, this._n) /
|
1580
|
+
C4_coeff[o + p + 1];
|
1581
|
+
o += p + 2;
|
1582
|
+
}
|
1583
|
+
}
|
1584
|
+
};
|
1585
|
+
|
1586
|
+
g.Geodesic.prototype.A3f = function(eps) {
|
1587
|
+
// Evaluate A3
|
1588
|
+
return m.polyval(nA3x_ - 1, this._A3x, 0, eps);
|
1589
|
+
};
|
1590
|
+
|
1591
|
+
g.Geodesic.prototype.C3f = function(eps, c) {
|
1592
|
+
// Evaluate C3 coeffs
|
1593
|
+
// Elements c[1] thru c[nC3_ - 1] are set
|
1594
|
+
var mult = 1,
|
1595
|
+
o = 0,
|
1596
|
+
l, p;
|
1597
|
+
for (l = 1; l < g.nC3_; ++l) { // l is index of C3[l]
|
1598
|
+
p = g.nC3_ - l - 1; // order of polynomial in eps
|
1599
|
+
mult *= eps;
|
1600
|
+
c[l] = mult * m.polyval(p, this._C3x, o, eps);
|
1601
|
+
o += p + 1;
|
1602
|
+
}
|
1603
|
+
};
|
1604
|
+
|
1605
|
+
g.Geodesic.prototype.C4f = function(eps, c) {
|
1606
|
+
// Evaluate C4 coeffs
|
1607
|
+
// Elements c[0] thru c[g.nC4_ - 1] are set
|
1608
|
+
var mult = 1,
|
1609
|
+
o = 0,
|
1610
|
+
l, p;
|
1611
|
+
for (l = 0; l < g.nC4_; ++l) { // l is index of C4[l]
|
1612
|
+
p = g.nC4_ - l - 1; // order of polynomial in eps
|
1613
|
+
c[l] = mult * m.polyval(p, this._C4x, o, eps);
|
1614
|
+
o += p + 1;
|
1615
|
+
mult *= eps;
|
1616
|
+
}
|
1617
|
+
};
|
1618
|
+
|
1619
|
+
// return s12b, m12b, m0, M12, M21
|
1620
|
+
g.Geodesic.prototype.Lengths = function(eps, sig12,
|
1621
|
+
ssig1, csig1, dn1, ssig2, csig2, dn2,
|
1622
|
+
cbet1, cbet2, outmask,
|
1623
|
+
C1a, C2a) {
|
1624
|
+
// Return m12b = (reduced length)/_b; also calculate s12b =
|
1625
|
+
// distance/_b, and m0 = coefficient of secular term in
|
1626
|
+
// expression for reduced length.
|
1627
|
+
outmask &= g.OUT_MASK;
|
1628
|
+
var vals = {},
|
1629
|
+
m0x = 0, J12 = 0, A1 = 0, A2 = 0,
|
1630
|
+
B1, B2, l, csig12, t;
|
1631
|
+
if (outmask & (g.DISTANCE | g.REDUCEDLENGTH | g.GEODESICSCALE)) {
|
1632
|
+
A1 = g.A1m1f(eps);
|
1633
|
+
g.C1f(eps, C1a);
|
1634
|
+
if (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE)) {
|
1635
|
+
A2 = g.A2m1f(eps);
|
1636
|
+
g.C2f(eps, C2a);
|
1637
|
+
m0x = A1 - A2;
|
1638
|
+
A2 = 1 + A2;
|
1639
|
+
}
|
1640
|
+
A1 = 1 + A1;
|
1641
|
+
}
|
1642
|
+
if (outmask & g.DISTANCE) {
|
1643
|
+
B1 = g.SinCosSeries(true, ssig2, csig2, C1a) -
|
1644
|
+
g.SinCosSeries(true, ssig1, csig1, C1a);
|
1645
|
+
// Missing a factor of _b
|
1646
|
+
vals.s12b = A1 * (sig12 + B1);
|
1647
|
+
if (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE)) {
|
1648
|
+
B2 = g.SinCosSeries(true, ssig2, csig2, C2a) -
|
1649
|
+
g.SinCosSeries(true, ssig1, csig1, C2a);
|
1650
|
+
J12 = m0x * sig12 + (A1 * B1 - A2 * B2);
|
1651
|
+
}
|
1652
|
+
} else if (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE)) {
|
1653
|
+
// Assume here that nC1_ >= nC2_
|
1654
|
+
for (l = 1; l <= g.nC2_; ++l)
|
1655
|
+
C2a[l] = A1 * C1a[l] - A2 * C2a[l];
|
1656
|
+
J12 = m0x * sig12 + (g.SinCosSeries(true, ssig2, csig2, C2a) -
|
1657
|
+
g.SinCosSeries(true, ssig1, csig1, C2a));
|
1658
|
+
}
|
1659
|
+
if (outmask & g.REDUCEDLENGTH) {
|
1660
|
+
vals.m0 = m0x;
|
1661
|
+
// Missing a factor of _b.
|
1662
|
+
// Add parens around (csig1 * ssig2) and (ssig1 * csig2) to ensure
|
1663
|
+
// accurate cancellation in the case of coincident points.
|
1664
|
+
vals.m12b = dn2 * (csig1 * ssig2) - dn1 * (ssig1 * csig2) -
|
1665
|
+
csig1 * csig2 * J12;
|
1666
|
+
}
|
1667
|
+
if (outmask & g.GEODESICSCALE) {
|
1668
|
+
csig12 = csig1 * csig2 + ssig1 * ssig2;
|
1669
|
+
t = this._ep2 * (cbet1 - cbet2) * (cbet1 + cbet2) / (dn1 + dn2);
|
1670
|
+
vals.M12 = csig12 + (t * ssig2 - csig2 * J12) * ssig1 / dn1;
|
1671
|
+
vals.M21 = csig12 - (t * ssig1 - csig1 * J12) * ssig2 / dn2;
|
1672
|
+
}
|
1673
|
+
return vals;
|
1674
|
+
};
|
1675
|
+
|
1676
|
+
// return sig12, salp1, calp1, salp2, calp2, dnm
|
1677
|
+
g.Geodesic.prototype.InverseStart = function(sbet1, cbet1, dn1,
|
1678
|
+
sbet2, cbet2, dn2,
|
1679
|
+
lam12, slam12, clam12,
|
1680
|
+
C1a, C2a) {
|
1681
|
+
// Return a starting point for Newton's method in salp1 and calp1
|
1682
|
+
// (function value is -1). If Newton's method doesn't need to be
|
1683
|
+
// used, return also salp2 and calp2 and function value is sig12.
|
1684
|
+
// salp2, calp2 only updated if return val >= 0.
|
1685
|
+
var vals = {},
|
1686
|
+
// bet12 = bet2 - bet1 in [0, pi); bet12a = bet2 + bet1 in (-pi, 0]
|
1687
|
+
sbet12 = sbet2 * cbet1 - cbet2 * sbet1,
|
1688
|
+
cbet12 = cbet2 * cbet1 + sbet2 * sbet1,
|
1689
|
+
sbet12a, shortline, omg12, sbetm2, somg12, comg12, t, ssig12, csig12,
|
1690
|
+
x, y, lamscale, betscale, k2, eps, cbet12a, bet12a, m12b, m0, nvals,
|
1691
|
+
k, omg12a, lam12x;
|
1692
|
+
vals.sig12 = -1; // Return value
|
1693
|
+
// Volatile declaration needed to fix inverse cases
|
1694
|
+
// 88.202499451857 0 -88.202499451857 179.981022032992859592
|
1695
|
+
// 89.262080389218 0 -89.262080389218 179.992207982775375662
|
1696
|
+
// 89.333123580033 0 -89.333123580032997687 179.99295812360148422
|
1697
|
+
// which otherwise fail with g++ 4.4.4 x86 -O3
|
1698
|
+
sbet12a = sbet2 * cbet1;
|
1699
|
+
sbet12a += cbet2 * sbet1;
|
1700
|
+
|
1701
|
+
shortline = cbet12 >= 0 && sbet12 < 0.5 && cbet2 * lam12 < 0.5;
|
1702
|
+
if (shortline) {
|
1703
|
+
sbetm2 = m.sq(sbet1 + sbet2);
|
1704
|
+
// sin((bet1+bet2)/2)^2
|
1705
|
+
// = (sbet1 + sbet2)^2 / ((sbet1 + sbet2)^2 + (cbet1 + cbet2)^2)
|
1706
|
+
sbetm2 /= sbetm2 + m.sq(cbet1 + cbet2);
|
1707
|
+
vals.dnm = Math.sqrt(1 + this._ep2 * sbetm2);
|
1708
|
+
omg12 = lam12 / (this._f1 * vals.dnm);
|
1709
|
+
somg12 = Math.sin(omg12); comg12 = Math.cos(omg12);
|
1710
|
+
} else {
|
1711
|
+
somg12 = slam12; comg12 = clam12;
|
1712
|
+
}
|
1713
|
+
|
1714
|
+
vals.salp1 = cbet2 * somg12;
|
1715
|
+
vals.calp1 = comg12 >= 0 ?
|
1716
|
+
sbet12 + cbet2 * sbet1 * m.sq(somg12) / (1 + comg12) :
|
1717
|
+
sbet12a - cbet2 * sbet1 * m.sq(somg12) / (1 - comg12);
|
1718
|
+
|
1719
|
+
ssig12 = m.hypot(vals.salp1, vals.calp1);
|
1720
|
+
csig12 = sbet1 * sbet2 + cbet1 * cbet2 * comg12;
|
1721
|
+
if (shortline && ssig12 < this._etol2) {
|
1722
|
+
// really short lines
|
1723
|
+
vals.salp2 = cbet1 * somg12;
|
1724
|
+
vals.calp2 = sbet12 - cbet1 * sbet2 *
|
1725
|
+
(comg12 >= 0 ? m.sq(somg12) / (1 + comg12) : 1 - comg12);
|
1726
|
+
// norm(vals.salp2, vals.calp2);
|
1727
|
+
t = m.hypot(vals.salp2, vals.calp2); vals.salp2 /= t; vals.calp2 /= t;
|
1728
|
+
// Set return value
|
1729
|
+
vals.sig12 = Math.atan2(ssig12, csig12);
|
1730
|
+
} else if (Math.abs(this._n) > 0.1 || // Skip astroid calc if too eccentric
|
1731
|
+
csig12 >= 0 ||
|
1732
|
+
ssig12 >= 6 * Math.abs(this._n) * Math.PI * m.sq(cbet1)) {
|
1733
|
+
// Nothing to do, zeroth order spherical approximation is OK
|
1734
|
+
} else {
|
1735
|
+
// Scale lam12 and bet2 to x, y coordinate system where antipodal
|
1736
|
+
// point is at origin and singular point is at y = 0, x = -1.
|
1737
|
+
lam12x = Math.atan2(-slam12, -clam12); // lam12 - pi
|
1738
|
+
if (this.f >= 0) { // In fact f == 0 does not get here
|
1739
|
+
// x = dlong, y = dlat
|
1740
|
+
k2 = m.sq(sbet1) * this._ep2;
|
1741
|
+
eps = k2 / (2 * (1 + Math.sqrt(1 + k2)) + k2);
|
1742
|
+
lamscale = this.f * cbet1 * this.A3f(eps) * Math.PI;
|
1743
|
+
betscale = lamscale * cbet1;
|
1744
|
+
|
1745
|
+
x = lam12x / lamscale;
|
1746
|
+
y = sbet12a / betscale;
|
1747
|
+
} else { // f < 0
|
1748
|
+
// x = dlat, y = dlong
|
1749
|
+
cbet12a = cbet2 * cbet1 - sbet2 * sbet1;
|
1750
|
+
bet12a = Math.atan2(sbet12a, cbet12a);
|
1751
|
+
// In the case of lon12 = 180, this repeats a calculation made
|
1752
|
+
// in Inverse.
|
1753
|
+
nvals = this.Lengths(this._n, Math.PI + bet12a,
|
1754
|
+
sbet1, -cbet1, dn1, sbet2, cbet2, dn2,
|
1755
|
+
cbet1, cbet2, g.REDUCEDLENGTH, C1a, C2a);
|
1756
|
+
m12b = nvals.m12b; m0 = nvals.m0;
|
1757
|
+
x = -1 + m12b / (cbet1 * cbet2 * m0 * Math.PI);
|
1758
|
+
betscale = x < -0.01 ? sbet12a / x :
|
1759
|
+
-this.f * m.sq(cbet1) * Math.PI;
|
1760
|
+
lamscale = betscale / cbet1;
|
1761
|
+
y = lam12 / lamscale;
|
1762
|
+
}
|
1763
|
+
|
1764
|
+
if (y > -tol1_ && x > -1 - xthresh_) {
|
1765
|
+
// strip near cut
|
1766
|
+
if (this.f >= 0) {
|
1767
|
+
vals.salp1 = Math.min(1, -x);
|
1768
|
+
vals.calp1 = -Math.sqrt(1 - m.sq(vals.salp1));
|
1769
|
+
} else {
|
1770
|
+
vals.calp1 = Math.max(x > -tol1_ ? 0 : -1, x);
|
1771
|
+
vals.salp1 = Math.sqrt(1 - m.sq(vals.calp1));
|
1772
|
+
}
|
1773
|
+
} else {
|
1774
|
+
// Estimate alp1, by solving the astroid problem.
|
1775
|
+
//
|
1776
|
+
// Could estimate alpha1 = theta + pi/2, directly, i.e.,
|
1777
|
+
// calp1 = y/k; salp1 = -x/(1+k); for f >= 0
|
1778
|
+
// calp1 = x/(1+k); salp1 = -y/k; for f < 0 (need to check)
|
1779
|
+
//
|
1780
|
+
// However, it's better to estimate omg12 from astroid and use
|
1781
|
+
// spherical formula to compute alp1. This reduces the mean number of
|
1782
|
+
// Newton iterations for astroid cases from 2.24 (min 0, max 6) to 2.12
|
1783
|
+
// (min 0 max 5). The changes in the number of iterations are as
|
1784
|
+
// follows:
|
1785
|
+
//
|
1786
|
+
// change percent
|
1787
|
+
// 1 5
|
1788
|
+
// 0 78
|
1789
|
+
// -1 16
|
1790
|
+
// -2 0.6
|
1791
|
+
// -3 0.04
|
1792
|
+
// -4 0.002
|
1793
|
+
//
|
1794
|
+
// The histogram of iterations is (m = number of iterations estimating
|
1795
|
+
// alp1 directly, n = number of iterations estimating via omg12, total
|
1796
|
+
// number of trials = 148605):
|
1797
|
+
//
|
1798
|
+
// iter m n
|
1799
|
+
// 0 148 186
|
1800
|
+
// 1 13046 13845
|
1801
|
+
// 2 93315 102225
|
1802
|
+
// 3 36189 32341
|
1803
|
+
// 4 5396 7
|
1804
|
+
// 5 455 1
|
1805
|
+
// 6 56 0
|
1806
|
+
//
|
1807
|
+
// Because omg12 is near pi, estimate work with omg12a = pi - omg12
|
1808
|
+
k = astroid(x, y);
|
1809
|
+
omg12a = lamscale * ( this.f >= 0 ? -x * k/(1 + k) : -y * (1 + k)/k );
|
1810
|
+
somg12 = Math.sin(omg12a); comg12 = -Math.cos(omg12a);
|
1811
|
+
// Update spherical estimate of alp1 using omg12 instead of
|
1812
|
+
// lam12
|
1813
|
+
vals.salp1 = cbet2 * somg12;
|
1814
|
+
vals.calp1 = sbet12a -
|
1815
|
+
cbet2 * sbet1 * m.sq(somg12) / (1 - comg12);
|
1816
|
+
}
|
1817
|
+
}
|
1818
|
+
// Sanity check on starting guess. Backwards check allows NaN through.
|
1819
|
+
if (!(vals.salp1 <= 0.0)) {
|
1820
|
+
// norm(vals.salp1, vals.calp1);
|
1821
|
+
t = m.hypot(vals.salp1, vals.calp1); vals.salp1 /= t; vals.calp1 /= t;
|
1822
|
+
} else {
|
1823
|
+
vals.salp1 = 1; vals.calp1 = 0;
|
1824
|
+
}
|
1825
|
+
return vals;
|
1826
|
+
};
|
1827
|
+
|
1828
|
+
// return lam12, salp2, calp2, sig12, ssig1, csig1, ssig2, csig2, eps,
|
1829
|
+
// domg12, dlam12,
|
1830
|
+
g.Geodesic.prototype.Lambda12 = function(sbet1, cbet1, dn1,
|
1831
|
+
sbet2, cbet2, dn2,
|
1832
|
+
salp1, calp1, slam120, clam120,
|
1833
|
+
diffp, C1a, C2a, C3a) {
|
1834
|
+
var vals = {},
|
1835
|
+
t, salp0, calp0,
|
1836
|
+
somg1, comg1, somg2, comg2, somg12, comg12, B312, eta, k2, nvals;
|
1837
|
+
if (sbet1 === 0 && calp1 === 0)
|
1838
|
+
// Break degeneracy of equatorial line. This case has already been
|
1839
|
+
// handled.
|
1840
|
+
calp1 = -g.tiny_;
|
1841
|
+
|
1842
|
+
// sin(alp1) * cos(bet1) = sin(alp0)
|
1843
|
+
salp0 = salp1 * cbet1;
|
1844
|
+
calp0 = m.hypot(calp1, salp1 * sbet1); // calp0 > 0
|
1845
|
+
|
1846
|
+
// tan(bet1) = tan(sig1) * cos(alp1)
|
1847
|
+
// tan(omg1) = sin(alp0) * tan(sig1) = tan(omg1)=tan(alp1)*sin(bet1)
|
1848
|
+
vals.ssig1 = sbet1; somg1 = salp0 * sbet1;
|
1849
|
+
vals.csig1 = comg1 = calp1 * cbet1;
|
1850
|
+
// norm(vals.ssig1, vals.csig1);
|
1851
|
+
t = m.hypot(vals.ssig1, vals.csig1); vals.ssig1 /= t; vals.csig1 /= t;
|
1852
|
+
// norm(somg1, comg1); -- don't need to normalize!
|
1853
|
+
|
1854
|
+
// Enforce symmetries in the case abs(bet2) = -bet1. Need to be careful
|
1855
|
+
// about this case, since this can yield singularities in the Newton
|
1856
|
+
// iteration.
|
1857
|
+
// sin(alp2) * cos(bet2) = sin(alp0)
|
1858
|
+
vals.salp2 = cbet2 !== cbet1 ? salp0 / cbet2 : salp1;
|
1859
|
+
// calp2 = sqrt(1 - sq(salp2))
|
1860
|
+
// = sqrt(sq(calp0) - sq(sbet2)) / cbet2
|
1861
|
+
// and subst for calp0 and rearrange to give (choose positive sqrt
|
1862
|
+
// to give alp2 in [0, pi/2]).
|
1863
|
+
vals.calp2 = cbet2 !== cbet1 || Math.abs(sbet2) !== -sbet1 ?
|
1864
|
+
Math.sqrt(m.sq(calp1 * cbet1) + (cbet1 < -sbet1 ?
|
1865
|
+
(cbet2 - cbet1) * (cbet1 + cbet2) :
|
1866
|
+
(sbet1 - sbet2) * (sbet1 + sbet2))) /
|
1867
|
+
cbet2 : Math.abs(calp1);
|
1868
|
+
// tan(bet2) = tan(sig2) * cos(alp2)
|
1869
|
+
// tan(omg2) = sin(alp0) * tan(sig2).
|
1870
|
+
vals.ssig2 = sbet2; somg2 = salp0 * sbet2;
|
1871
|
+
vals.csig2 = comg2 = vals.calp2 * cbet2;
|
1872
|
+
// norm(vals.ssig2, vals.csig2);
|
1873
|
+
t = m.hypot(vals.ssig2, vals.csig2); vals.ssig2 /= t; vals.csig2 /= t;
|
1874
|
+
// norm(somg2, comg2); -- don't need to normalize!
|
1875
|
+
|
1876
|
+
// sig12 = sig2 - sig1, limit to [0, pi]
|
1877
|
+
vals.sig12 = Math.atan2(Math.max(0, vals.csig1 * vals.ssig2 -
|
1878
|
+
vals.ssig1 * vals.csig2),
|
1879
|
+
vals.csig1 * vals.csig2 +
|
1880
|
+
vals.ssig1 * vals.ssig2);
|
1881
|
+
|
1882
|
+
// omg12 = omg2 - omg1, limit to [0, pi]
|
1883
|
+
somg12 = Math.max(0, comg1 * somg2 - somg1 * comg2);
|
1884
|
+
comg12 = comg1 * comg2 + somg1 * somg2;
|
1885
|
+
// eta = omg12 - lam120
|
1886
|
+
eta = Math.atan2(somg12 * clam120 - comg12 * slam120,
|
1887
|
+
comg12 * clam120 + somg12 * slam120);
|
1888
|
+
k2 = m.sq(calp0) * this._ep2;
|
1889
|
+
vals.eps = k2 / (2 * (1 + Math.sqrt(1 + k2)) + k2);
|
1890
|
+
this.C3f(vals.eps, C3a);
|
1891
|
+
B312 = (g.SinCosSeries(true, vals.ssig2, vals.csig2, C3a) -
|
1892
|
+
g.SinCosSeries(true, vals.ssig1, vals.csig1, C3a));
|
1893
|
+
vals.domg12 = -this.f * this.A3f(vals.eps) * salp0 * (vals.sig12 + B312);
|
1894
|
+
vals.lam12 = eta + vals.domg12;
|
1895
|
+
if (diffp) {
|
1896
|
+
if (vals.calp2 === 0)
|
1897
|
+
vals.dlam12 = -2 * this._f1 * dn1 / sbet1;
|
1898
|
+
else {
|
1899
|
+
nvals = this.Lengths(vals.eps, vals.sig12,
|
1900
|
+
vals.ssig1, vals.csig1, dn1,
|
1901
|
+
vals.ssig2, vals.csig2, dn2,
|
1902
|
+
cbet1, cbet2, g.REDUCEDLENGTH, C1a, C2a);
|
1903
|
+
vals.dlam12 = nvals.m12b;
|
1904
|
+
vals.dlam12 *= this._f1 / (vals.calp2 * cbet2);
|
1905
|
+
}
|
1906
|
+
}
|
1907
|
+
return vals;
|
1908
|
+
};
|
1909
|
+
|
1910
|
+
/**
|
1911
|
+
* @summary Solve the inverse geodesic problem.
|
1912
|
+
* @param {number} lat1 the latitude of the first point in degrees.
|
1913
|
+
* @param {number} lon1 the longitude of the first point in degrees.
|
1914
|
+
* @param {number} lat2 the latitude of the second point in degrees.
|
1915
|
+
* @param {number} lon2 the longitude of the second point in degrees.
|
1916
|
+
* @param {bitmask} [outmask = STANDARD] which results to include.
|
1917
|
+
* @returns {object} the requested results
|
1918
|
+
* @description The lat1, lon1, lat2, lon2, and a12 fields of the result are
|
1919
|
+
* always set. For details on the outmask parameter, see {@tutorial
|
1920
|
+
* 2-interface}, "The outmask and caps parameters".
|
1921
|
+
*/
|
1922
|
+
g.Geodesic.prototype.Inverse = function(lat1, lon1, lat2, lon2, outmask) {
|
1923
|
+
var r, vals;
|
1924
|
+
if (!outmask) outmask = g.STANDARD;
|
1925
|
+
if (outmask === g.LONG_UNROLL) outmask |= g.STANDARD;
|
1926
|
+
outmask &= g.OUT_MASK;
|
1927
|
+
r = this.InverseInt(lat1, lon1, lat2, lon2, outmask);
|
1928
|
+
vals = r.vals;
|
1929
|
+
if (outmask & g.AZIMUTH) {
|
1930
|
+
vals.azi1 = m.atan2d(r.salp1, r.calp1);
|
1931
|
+
vals.azi2 = m.atan2d(r.salp2, r.calp2);
|
1932
|
+
}
|
1933
|
+
return vals;
|
1934
|
+
};
|
1935
|
+
|
1936
|
+
g.Geodesic.prototype.InverseInt = function(lat1, lon1, lat2, lon2, outmask) {
|
1937
|
+
var vals = {},
|
1938
|
+
lon12, lon12s, lonsign, t, swapp, latsign,
|
1939
|
+
sbet1, cbet1, sbet2, cbet2, s12x, m12x,
|
1940
|
+
dn1, dn2, lam12, slam12, clam12,
|
1941
|
+
sig12, calp1, salp1, calp2, salp2, C1a, C2a, C3a, meridian, nvals,
|
1942
|
+
ssig1, csig1, ssig2, csig2, eps, omg12, dnm,
|
1943
|
+
numit, salp1a, calp1a, salp1b, calp1b,
|
1944
|
+
tripn, tripb, v, dv, dalp1, sdalp1, cdalp1, nsalp1,
|
1945
|
+
lengthmask, salp0, calp0, alp12, k2, A4, C4a, B41, B42,
|
1946
|
+
somg12, comg12, domg12, dbet1, dbet2, salp12, calp12, sdomg12, cdomg12;
|
1947
|
+
// Compute longitude difference (AngDiff does this carefully). Result is
|
1948
|
+
// in [-180, 180] but -180 is only for west-going geodesics. 180 is for
|
1949
|
+
// east-going and meridional geodesics.
|
1950
|
+
vals.lat1 = lat1 = m.LatFix(lat1); vals.lat2 = lat2 = m.LatFix(lat2);
|
1951
|
+
// If really close to the equator, treat as on equator.
|
1952
|
+
lat1 = m.AngRound(lat1);
|
1953
|
+
lat2 = m.AngRound(lat2);
|
1954
|
+
lon12 = m.AngDiff(lon1, lon2); lon12s = lon12.t; lon12 = lon12.s;
|
1955
|
+
if (outmask & g.LONG_UNROLL) {
|
1956
|
+
vals.lon1 = lon1; vals.lon2 = (lon1 + lon12) + lon12s;
|
1957
|
+
} else {
|
1958
|
+
vals.lon1 = m.AngNormalize(lon1); vals.lon2 = m.AngNormalize(lon2);
|
1959
|
+
}
|
1960
|
+
// Make longitude difference positive.
|
1961
|
+
lonsign = lon12 >= 0 ? 1 : -1;
|
1962
|
+
// If very close to being on the same half-meridian, then make it so.
|
1963
|
+
lon12 = lonsign * m.AngRound(lon12);
|
1964
|
+
lon12s = m.AngRound((180 - lon12) - lonsign * lon12s);
|
1965
|
+
lam12 = lon12 * m.degree;
|
1966
|
+
t = m.sincosd(lon12 > 90 ? lon12s : lon12);
|
1967
|
+
slam12 = t.s; clam12 = (lon12 > 90 ? -1 : 1) * t.c;
|
1968
|
+
|
1969
|
+
// Swap points so that point with higher (abs) latitude is point 1
|
1970
|
+
// If one latitude is a nan, then it becomes lat1.
|
1971
|
+
swapp = Math.abs(lat1) < Math.abs(lat2) ? -1 : 1;
|
1972
|
+
if (swapp < 0) {
|
1973
|
+
lonsign *= -1;
|
1974
|
+
t = lat1;
|
1975
|
+
lat1 = lat2;
|
1976
|
+
lat2 = t;
|
1977
|
+
// swap(lat1, lat2);
|
1978
|
+
}
|
1979
|
+
// Make lat1 <= 0
|
1980
|
+
latsign = lat1 < 0 ? 1 : -1;
|
1981
|
+
lat1 *= latsign;
|
1982
|
+
lat2 *= latsign;
|
1983
|
+
// Now we have
|
1984
|
+
//
|
1985
|
+
// 0 <= lon12 <= 180
|
1986
|
+
// -90 <= lat1 <= 0
|
1987
|
+
// lat1 <= lat2 <= -lat1
|
1988
|
+
//
|
1989
|
+
// longsign, swapp, latsign register the transformation to bring the
|
1990
|
+
// coordinates to this canonical form. In all cases, 1 means no change was
|
1991
|
+
// made. We make these transformations so that there are few cases to
|
1992
|
+
// check, e.g., on verifying quadrants in atan2. In addition, this
|
1993
|
+
// enforces some symmetries in the results returned.
|
1994
|
+
|
1995
|
+
t = m.sincosd(lat1); sbet1 = this._f1 * t.s; cbet1 = t.c;
|
1996
|
+
// norm(sbet1, cbet1);
|
1997
|
+
t = m.hypot(sbet1, cbet1); sbet1 /= t; cbet1 /= t;
|
1998
|
+
// Ensure cbet1 = +epsilon at poles
|
1999
|
+
cbet1 = Math.max(g.tiny_, cbet1);
|
2000
|
+
|
2001
|
+
t = m.sincosd(lat2); sbet2 = this._f1 * t.s; cbet2 = t.c;
|
2002
|
+
// norm(sbet2, cbet2);
|
2003
|
+
t = m.hypot(sbet2, cbet2); sbet2 /= t; cbet2 /= t;
|
2004
|
+
// Ensure cbet2 = +epsilon at poles
|
2005
|
+
cbet2 = Math.max(g.tiny_, cbet2);
|
2006
|
+
|
2007
|
+
// If cbet1 < -sbet1, then cbet2 - cbet1 is a sensitive measure of the
|
2008
|
+
// |bet1| - |bet2|. Alternatively (cbet1 >= -sbet1), abs(sbet2) + sbet1 is
|
2009
|
+
// a better measure. This logic is used in assigning calp2 in Lambda12.
|
2010
|
+
// Sometimes these quantities vanish and in that case we force bet2 = +/-
|
2011
|
+
// bet1 exactly. An example where is is necessary is the inverse problem
|
2012
|
+
// 48.522876735459 0 -48.52287673545898293 179.599720456223079643
|
2013
|
+
// which failed with Visual Studio 10 (Release and Debug)
|
2014
|
+
|
2015
|
+
if (cbet1 < -sbet1) {
|
2016
|
+
if (cbet2 === cbet1)
|
2017
|
+
sbet2 = sbet2 < 0 ? sbet1 : -sbet1;
|
2018
|
+
} else {
|
2019
|
+
if (Math.abs(sbet2) === -sbet1)
|
2020
|
+
cbet2 = cbet1;
|
2021
|
+
}
|
2022
|
+
|
2023
|
+
dn1 = Math.sqrt(1 + this._ep2 * m.sq(sbet1));
|
2024
|
+
dn2 = Math.sqrt(1 + this._ep2 * m.sq(sbet2));
|
2025
|
+
|
2026
|
+
// index zero elements of these arrays are unused
|
2027
|
+
C1a = new Array(g.nC1_ + 1);
|
2028
|
+
C2a = new Array(g.nC2_ + 1);
|
2029
|
+
C3a = new Array(g.nC3_);
|
2030
|
+
|
2031
|
+
meridian = lat1 === -90 || slam12 === 0;
|
2032
|
+
if (meridian) {
|
2033
|
+
|
2034
|
+
// Endpoints are on a single full meridian, so the geodesic might
|
2035
|
+
// lie on a meridian.
|
2036
|
+
|
2037
|
+
calp1 = clam12; salp1 = slam12; // Head to the target longitude
|
2038
|
+
calp2 = 1; salp2 = 0; // At the target we're heading north
|
2039
|
+
|
2040
|
+
// tan(bet) = tan(sig) * cos(alp)
|
2041
|
+
ssig1 = sbet1; csig1 = calp1 * cbet1;
|
2042
|
+
ssig2 = sbet2; csig2 = calp2 * cbet2;
|
2043
|
+
|
2044
|
+
// sig12 = sig2 - sig1
|
2045
|
+
sig12 = Math.atan2(Math.max(0, csig1 * ssig2 - ssig1 * csig2),
|
2046
|
+
csig1 * csig2 + ssig1 * ssig2);
|
2047
|
+
nvals = this.Lengths(this._n, sig12,
|
2048
|
+
ssig1, csig1, dn1, ssig2, csig2, dn2, cbet1, cbet2,
|
2049
|
+
outmask | g.DISTANCE | g.REDUCEDLENGTH,
|
2050
|
+
C1a, C2a);
|
2051
|
+
s12x = nvals.s12b;
|
2052
|
+
m12x = nvals.m12b;
|
2053
|
+
// Ignore m0
|
2054
|
+
if (outmask & g.GEODESICSCALE) {
|
2055
|
+
vals.M12 = nvals.M12;
|
2056
|
+
vals.M21 = nvals.M21;
|
2057
|
+
}
|
2058
|
+
// Add the check for sig12 since zero length geodesics might yield
|
2059
|
+
// m12 < 0. Test case was
|
2060
|
+
//
|
2061
|
+
// echo 20.001 0 20.001 0 | GeodSolve -i
|
2062
|
+
//
|
2063
|
+
// In fact, we will have sig12 > pi/2 for meridional geodesic
|
2064
|
+
// which is not a shortest path.
|
2065
|
+
if (sig12 < 1 || m12x >= 0) {
|
2066
|
+
// Need at least 2, to handle 90 0 90 180
|
2067
|
+
if (sig12 < 3 * g.tiny_)
|
2068
|
+
sig12 = m12x = s12x = 0;
|
2069
|
+
m12x *= this._b;
|
2070
|
+
s12x *= this._b;
|
2071
|
+
vals.a12 = sig12 / m.degree;
|
2072
|
+
} else
|
2073
|
+
// m12 < 0, i.e., prolate and too close to anti-podal
|
2074
|
+
meridian = false;
|
2075
|
+
}
|
2076
|
+
|
2077
|
+
somg12 = 2;
|
2078
|
+
if (!meridian &&
|
2079
|
+
sbet1 === 0 && // and sbet2 == 0
|
2080
|
+
(this.f <= 0 || lon12s >= this.f * 180)) {
|
2081
|
+
|
2082
|
+
// Geodesic runs along equator
|
2083
|
+
calp1 = calp2 = 0; salp1 = salp2 = 1;
|
2084
|
+
s12x = this.a * lam12;
|
2085
|
+
sig12 = omg12 = lam12 / this._f1;
|
2086
|
+
m12x = this._b * Math.sin(sig12);
|
2087
|
+
if (outmask & g.GEODESICSCALE)
|
2088
|
+
vals.M12 = vals.M21 = Math.cos(sig12);
|
2089
|
+
vals.a12 = lon12 / this._f1;
|
2090
|
+
|
2091
|
+
} else if (!meridian) {
|
2092
|
+
|
2093
|
+
// Now point1 and point2 belong within a hemisphere bounded by a
|
2094
|
+
// meridian and geodesic is neither meridional or equatorial.
|
2095
|
+
|
2096
|
+
// Figure a starting point for Newton's method
|
2097
|
+
nvals = this.InverseStart(sbet1, cbet1, dn1, sbet2, cbet2, dn2,
|
2098
|
+
lam12, slam12, clam12, C1a, C2a);
|
2099
|
+
sig12 = nvals.sig12;
|
2100
|
+
salp1 = nvals.salp1;
|
2101
|
+
calp1 = nvals.calp1;
|
2102
|
+
|
2103
|
+
if (sig12 >= 0) {
|
2104
|
+
salp2 = nvals.salp2;
|
2105
|
+
calp2 = nvals.calp2;
|
2106
|
+
// Short lines (InverseStart sets salp2, calp2, dnm)
|
2107
|
+
|
2108
|
+
dnm = nvals.dnm;
|
2109
|
+
s12x = sig12 * this._b * dnm;
|
2110
|
+
m12x = m.sq(dnm) * this._b * Math.sin(sig12 / dnm);
|
2111
|
+
if (outmask & g.GEODESICSCALE)
|
2112
|
+
vals.M12 = vals.M21 = Math.cos(sig12 / dnm);
|
2113
|
+
vals.a12 = sig12 / m.degree;
|
2114
|
+
omg12 = lam12 / (this._f1 * dnm);
|
2115
|
+
} else {
|
2116
|
+
|
2117
|
+
// Newton's method. This is a straightforward solution of f(alp1) =
|
2118
|
+
// lambda12(alp1) - lam12 = 0 with one wrinkle. f(alp) has exactly one
|
2119
|
+
// root in the interval (0, pi) and its derivative is positive at the
|
2120
|
+
// root. Thus f(alp) is positive for alp > alp1 and negative for alp <
|
2121
|
+
// alp1. During the course of the iteration, a range (alp1a, alp1b) is
|
2122
|
+
// maintained which brackets the root and with each evaluation of
|
2123
|
+
// f(alp) the range is shrunk if possible. Newton's method is
|
2124
|
+
// restarted whenever the derivative of f is negative (because the new
|
2125
|
+
// value of alp1 is then further from the solution) or if the new
|
2126
|
+
// estimate of alp1 lies outside (0,pi); in this case, the new starting
|
2127
|
+
// guess is taken to be (alp1a + alp1b) / 2.
|
2128
|
+
numit = 0;
|
2129
|
+
// Bracketing range
|
2130
|
+
salp1a = g.tiny_; calp1a = 1; salp1b = g.tiny_; calp1b = -1;
|
2131
|
+
for (tripn = false, tripb = false; numit < maxit2_; ++numit) {
|
2132
|
+
// the WGS84 test set: mean = 1.47, sd = 1.25, max = 16
|
2133
|
+
// WGS84 and random input: mean = 2.85, sd = 0.60
|
2134
|
+
nvals = this.Lambda12(sbet1, cbet1, dn1, sbet2, cbet2, dn2,
|
2135
|
+
salp1, calp1, slam12, clam12, numit < maxit1_,
|
2136
|
+
C1a, C2a, C3a);
|
2137
|
+
v = nvals.lam12;
|
2138
|
+
salp2 = nvals.salp2;
|
2139
|
+
calp2 = nvals.calp2;
|
2140
|
+
sig12 = nvals.sig12;
|
2141
|
+
ssig1 = nvals.ssig1;
|
2142
|
+
csig1 = nvals.csig1;
|
2143
|
+
ssig2 = nvals.ssig2;
|
2144
|
+
csig2 = nvals.csig2;
|
2145
|
+
eps = nvals.eps;
|
2146
|
+
domg12 = nvals.domg12;
|
2147
|
+
dv = nvals.dlam12;
|
2148
|
+
|
2149
|
+
// 2 * tol0 is approximately 1 ulp for a number in [0, pi].
|
2150
|
+
// Reversed test to allow escape with NaNs
|
2151
|
+
if (tripb || !(Math.abs(v) >= (tripn ? 8 : 1) * tol0_))
|
2152
|
+
break;
|
2153
|
+
// Update bracketing values
|
2154
|
+
if (v > 0 && (numit < maxit1_ || calp1/salp1 > calp1b/salp1b)) {
|
2155
|
+
salp1b = salp1; calp1b = calp1;
|
2156
|
+
} else if (v < 0 &&
|
2157
|
+
(numit < maxit1_ || calp1/salp1 < calp1a/salp1a)) {
|
2158
|
+
salp1a = salp1; calp1a = calp1;
|
2159
|
+
}
|
2160
|
+
if (numit < maxit1_ && dv > 0) {
|
2161
|
+
dalp1 = -v/dv;
|
2162
|
+
sdalp1 = Math.sin(dalp1); cdalp1 = Math.cos(dalp1);
|
2163
|
+
nsalp1 = salp1 * cdalp1 + calp1 * sdalp1;
|
2164
|
+
if (nsalp1 > 0 && Math.abs(dalp1) < Math.PI) {
|
2165
|
+
calp1 = calp1 * cdalp1 - salp1 * sdalp1;
|
2166
|
+
salp1 = nsalp1;
|
2167
|
+
// norm(salp1, calp1);
|
2168
|
+
t = m.hypot(salp1, calp1); salp1 /= t; calp1 /= t;
|
2169
|
+
// In some regimes we don't get quadratic convergence because
|
2170
|
+
// slope -> 0. So use convergence conditions based on epsilon
|
2171
|
+
// instead of sqrt(epsilon).
|
2172
|
+
tripn = Math.abs(v) <= 16 * tol0_;
|
2173
|
+
continue;
|
2174
|
+
}
|
2175
|
+
}
|
2176
|
+
// Either dv was not positive or updated value was outside legal
|
2177
|
+
// range. Use the midpoint of the bracket as the next estimate.
|
2178
|
+
// This mechanism is not needed for the WGS84 ellipsoid, but it does
|
2179
|
+
// catch problems with more eccentric ellipsoids. Its efficacy is
|
2180
|
+
// such for the WGS84 test set with the starting guess set to alp1 =
|
2181
|
+
// 90deg:
|
2182
|
+
// the WGS84 test set: mean = 5.21, sd = 3.93, max = 24
|
2183
|
+
// WGS84 and random input: mean = 4.74, sd = 0.99
|
2184
|
+
salp1 = (salp1a + salp1b)/2;
|
2185
|
+
calp1 = (calp1a + calp1b)/2;
|
2186
|
+
// norm(salp1, calp1);
|
2187
|
+
t = m.hypot(salp1, calp1); salp1 /= t; calp1 /= t;
|
2188
|
+
tripn = false;
|
2189
|
+
tripb = (Math.abs(salp1a - salp1) + (calp1a - calp1) < tolb_ ||
|
2190
|
+
Math.abs(salp1 - salp1b) + (calp1 - calp1b) < tolb_);
|
2191
|
+
}
|
2192
|
+
lengthmask = outmask |
|
2193
|
+
(outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE) ?
|
2194
|
+
g.DISTANCE : g.NONE);
|
2195
|
+
nvals = this.Lengths(eps, sig12,
|
2196
|
+
ssig1, csig1, dn1, ssig2, csig2, dn2,
|
2197
|
+
cbet1, cbet2,
|
2198
|
+
lengthmask, C1a, C2a);
|
2199
|
+
s12x = nvals.s12b;
|
2200
|
+
m12x = nvals.m12b;
|
2201
|
+
// Ignore m0
|
2202
|
+
if (outmask & g.GEODESICSCALE) {
|
2203
|
+
vals.M12 = nvals.M12;
|
2204
|
+
vals.M21 = nvals.M21;
|
2205
|
+
}
|
2206
|
+
m12x *= this._b;
|
2207
|
+
s12x *= this._b;
|
2208
|
+
vals.a12 = sig12 / m.degree;
|
2209
|
+
if (outmask & g.AREA) {
|
2210
|
+
// omg12 = lam12 - domg12
|
2211
|
+
sdomg12 = Math.sin(domg12); cdomg12 = Math.cos(domg12);
|
2212
|
+
somg12 = slam12 * cdomg12 - clam12 * sdomg12;
|
2213
|
+
comg12 = clam12 * cdomg12 + slam12 * sdomg12;
|
2214
|
+
}
|
2215
|
+
}
|
2216
|
+
}
|
2217
|
+
|
2218
|
+
if (outmask & g.DISTANCE)
|
2219
|
+
vals.s12 = 0 + s12x; // Convert -0 to 0
|
2220
|
+
|
2221
|
+
if (outmask & g.REDUCEDLENGTH)
|
2222
|
+
vals.m12 = 0 + m12x; // Convert -0 to 0
|
2223
|
+
|
2224
|
+
if (outmask & g.AREA) {
|
2225
|
+
// From Lambda12: sin(alp1) * cos(bet1) = sin(alp0)
|
2226
|
+
salp0 = salp1 * cbet1;
|
2227
|
+
calp0 = m.hypot(calp1, salp1 * sbet1); // calp0 > 0
|
2228
|
+
if (calp0 !== 0 && salp0 !== 0) {
|
2229
|
+
// From Lambda12: tan(bet) = tan(sig) * cos(alp)
|
2230
|
+
ssig1 = sbet1; csig1 = calp1 * cbet1;
|
2231
|
+
ssig2 = sbet2; csig2 = calp2 * cbet2;
|
2232
|
+
k2 = m.sq(calp0) * this._ep2;
|
2233
|
+
eps = k2 / (2 * (1 + Math.sqrt(1 + k2)) + k2);
|
2234
|
+
// Multiplier = a^2 * e^2 * cos(alpha0) * sin(alpha0).
|
2235
|
+
A4 = m.sq(this.a) * calp0 * salp0 * this._e2;
|
2236
|
+
// norm(ssig1, csig1);
|
2237
|
+
t = m.hypot(ssig1, csig1); ssig1 /= t; csig1 /= t;
|
2238
|
+
// norm(ssig2, csig2);
|
2239
|
+
t = m.hypot(ssig2, csig2); ssig2 /= t; csig2 /= t;
|
2240
|
+
C4a = new Array(g.nC4_);
|
2241
|
+
this.C4f(eps, C4a);
|
2242
|
+
B41 = g.SinCosSeries(false, ssig1, csig1, C4a);
|
2243
|
+
B42 = g.SinCosSeries(false, ssig2, csig2, C4a);
|
2244
|
+
vals.S12 = A4 * (B42 - B41);
|
2245
|
+
} else
|
2246
|
+
// Avoid problems with indeterminate sig1, sig2 on equator
|
2247
|
+
vals.S12 = 0;
|
2248
|
+
if (!meridian && somg12 > 1) {
|
2249
|
+
somg12 = Math.sin(omg12); comg12 = Math.cos(omg12);
|
2250
|
+
}
|
2251
|
+
if (!meridian &&
|
2252
|
+
comg12 > -0.7071 && // Long difference not too big
|
2253
|
+
sbet2 - sbet1 < 1.75) { // Lat difference not too big
|
2254
|
+
// Use tan(Gamma/2) = tan(omg12/2)
|
2255
|
+
// * (tan(bet1/2)+tan(bet2/2))/(1+tan(bet1/2)*tan(bet2/2))
|
2256
|
+
// with tan(x/2) = sin(x)/(1+cos(x))
|
2257
|
+
domg12 = 1 + comg12; dbet1 = 1 + cbet1; dbet2 = 1 + cbet2;
|
2258
|
+
alp12 = 2 * Math.atan2( somg12 * (sbet1*dbet2 + sbet2*dbet1),
|
2259
|
+
domg12 * (sbet1*sbet2 + dbet1*dbet2) );
|
2260
|
+
} else {
|
2261
|
+
// alp12 = alp2 - alp1, used in atan2 so no need to normalize
|
2262
|
+
salp12 = salp2 * calp1 - calp2 * salp1;
|
2263
|
+
calp12 = calp2 * calp1 + salp2 * salp1;
|
2264
|
+
// The right thing appears to happen if alp1 = +/-180 and alp2 = 0, viz
|
2265
|
+
// salp12 = -0 and alp12 = -180. However this depends on the sign
|
2266
|
+
// being attached to 0 correctly. The following ensures the correct
|
2267
|
+
// behavior.
|
2268
|
+
if (salp12 === 0 && calp12 < 0) {
|
2269
|
+
salp12 = g.tiny_ * calp1;
|
2270
|
+
calp12 = -1;
|
2271
|
+
}
|
2272
|
+
alp12 = Math.atan2(salp12, calp12);
|
2273
|
+
}
|
2274
|
+
vals.S12 += this._c2 * alp12;
|
2275
|
+
vals.S12 *= swapp * lonsign * latsign;
|
2276
|
+
// Convert -0 to 0
|
2277
|
+
vals.S12 += 0;
|
2278
|
+
}
|
2279
|
+
|
2280
|
+
// Convert calp, salp to azimuth accounting for lonsign, swapp, latsign.
|
2281
|
+
if (swapp < 0) {
|
2282
|
+
t = salp1;
|
2283
|
+
salp1 = salp2;
|
2284
|
+
salp2 = t;
|
2285
|
+
// swap(salp1, salp2);
|
2286
|
+
t = calp1;
|
2287
|
+
calp1 = calp2;
|
2288
|
+
calp2 = t;
|
2289
|
+
// swap(calp1, calp2);
|
2290
|
+
if (outmask & g.GEODESICSCALE) {
|
2291
|
+
t = vals.M12;
|
2292
|
+
vals.M12 = vals.M21;
|
2293
|
+
vals.M21 = t;
|
2294
|
+
// swap(vals.M12, vals.M21);
|
2295
|
+
}
|
2296
|
+
}
|
2297
|
+
|
2298
|
+
salp1 *= swapp * lonsign; calp1 *= swapp * latsign;
|
2299
|
+
salp2 *= swapp * lonsign; calp2 *= swapp * latsign;
|
2300
|
+
|
2301
|
+
return {vals: vals,
|
2302
|
+
salp1: salp1, calp1: calp1,
|
2303
|
+
salp2: salp2, calp2: calp2};
|
2304
|
+
};
|
2305
|
+
|
2306
|
+
/**
|
2307
|
+
* @summary Solve the general direct geodesic problem.
|
2308
|
+
* @param {number} lat1 the latitude of the first point in degrees.
|
2309
|
+
* @param {number} lon1 the longitude of the first point in degrees.
|
2310
|
+
* @param {number} azi1 the azimuth at the first point in degrees.
|
2311
|
+
* @param {bool} arcmode is the next parameter an arc length?
|
2312
|
+
* @param {number} s12_a12 the (arcmode ? arc length : distance) from the
|
2313
|
+
* first point to the second in (arcmode ? degrees : meters).
|
2314
|
+
* @param {bitmask} [outmask = STANDARD] which results to include.
|
2315
|
+
* @returns {object} the requested results.
|
2316
|
+
* @description The lat1, lon1, azi1, and a12 fields of the result are always
|
2317
|
+
* set; s12 is included if arcmode is false. For details on the outmask
|
2318
|
+
* parameter, see {@tutorial 2-interface}, "The outmask and caps
|
2319
|
+
* parameters".
|
2320
|
+
*/
|
2321
|
+
g.Geodesic.prototype.GenDirect = function(lat1, lon1, azi1,
|
2322
|
+
arcmode, s12_a12, outmask) {
|
2323
|
+
var line;
|
2324
|
+
if (!outmask) outmask = g.STANDARD;
|
2325
|
+
else if (outmask === g.LONG_UNROLL) outmask |= g.STANDARD;
|
2326
|
+
// Automatically supply DISTANCE_IN if necessary
|
2327
|
+
if (!arcmode) outmask |= g.DISTANCE_IN;
|
2328
|
+
line = new l.GeodesicLine(this, lat1, lon1, azi1, outmask);
|
2329
|
+
return line.GenPosition(arcmode, s12_a12, outmask);
|
2330
|
+
};
|
2331
|
+
|
2332
|
+
/**
|
2333
|
+
* @summary Solve the direct geodesic problem.
|
2334
|
+
* @param {number} lat1 the latitude of the first point in degrees.
|
2335
|
+
* @param {number} lon1 the longitude of the first point in degrees.
|
2336
|
+
* @param {number} azi1 the azimuth at the first point in degrees.
|
2337
|
+
* @param {number} s12 the distance from the first point to the second in
|
2338
|
+
* meters.
|
2339
|
+
* @param {bitmask} [outmask = STANDARD] which results to include.
|
2340
|
+
* @returns {object} the requested results.
|
2341
|
+
* @description The lat1, lon1, azi1, s12, and a12 fields of the result are
|
2342
|
+
* always set. For details on the outmask parameter, see {@tutorial
|
2343
|
+
* 2-interface}, "The outmask and caps parameters".
|
2344
|
+
*/
|
2345
|
+
g.Geodesic.prototype.Direct = function(lat1, lon1, azi1, s12, outmask) {
|
2346
|
+
return this.GenDirect(lat1, lon1, azi1, false, s12, outmask);
|
2347
|
+
};
|
2348
|
+
|
2349
|
+
/**
|
2350
|
+
* @summary Solve the direct geodesic problem with arc length.
|
2351
|
+
* @param {number} lat1 the latitude of the first point in degrees.
|
2352
|
+
* @param {number} lon1 the longitude of the first point in degrees.
|
2353
|
+
* @param {number} azi1 the azimuth at the first point in degrees.
|
2354
|
+
* @param {number} a12 the arc length from the first point to the second in
|
2355
|
+
* degrees.
|
2356
|
+
* @param {bitmask} [outmask = STANDARD] which results to include.
|
2357
|
+
* @returns {object} the requested results.
|
2358
|
+
* @description The lat1, lon1, azi1, and a12 fields of the result are
|
2359
|
+
* always set. For details on the outmask parameter, see {@tutorial
|
2360
|
+
* 2-interface}, "The outmask and caps parameters".
|
2361
|
+
*/
|
2362
|
+
g.Geodesic.prototype.ArcDirect = function(lat1, lon1, azi1, a12, outmask) {
|
2363
|
+
return this.GenDirect(lat1, lon1, azi1, true, a12, outmask);
|
2364
|
+
};
|
2365
|
+
|
2366
|
+
/**
|
2367
|
+
* @summary Create a {@link module:GeographicLib/GeodesicLine.GeodesicLine
|
2368
|
+
* GeodesicLine} object.
|
2369
|
+
* @param {number} lat1 the latitude of the first point in degrees.
|
2370
|
+
* @param {number} lon1 the longitude of the first point in degrees.
|
2371
|
+
* @param {number} azi1 the azimuth at the first point in degrees.
|
2372
|
+
* degrees.
|
2373
|
+
* @param {bitmask} [caps = STANDARD | DISTANCE_IN] which capabilities to
|
2374
|
+
* include.
|
2375
|
+
* @returns {object} the
|
2376
|
+
* {@link module:GeographicLib/GeodesicLine.GeodesicLine
|
2377
|
+
* GeodesicLine} object
|
2378
|
+
* @description For details on the caps parameter, see {@tutorial
|
2379
|
+
* 2-interface}, "The outmask and caps parameters".
|
2380
|
+
*/
|
2381
|
+
g.Geodesic.prototype.Line = function(lat1, lon1, azi1, caps) {
|
2382
|
+
return new l.GeodesicLine(this, lat1, lon1, azi1, caps);
|
2383
|
+
};
|
2384
|
+
|
2385
|
+
/**
|
2386
|
+
* @summary Define a {@link module:GeographicLib/GeodesicLine.GeodesicLine
|
2387
|
+
* GeodesicLine} in terms of the direct geodesic problem specified in terms
|
2388
|
+
* of distance.
|
2389
|
+
* @param {number} lat1 the latitude of the first point in degrees.
|
2390
|
+
* @param {number} lon1 the longitude of the first point in degrees.
|
2391
|
+
* @param {number} azi1 the azimuth at the first point in degrees.
|
2392
|
+
* degrees.
|
2393
|
+
* @param {number} s12 the distance between point 1 and point 2 (meters); it
|
2394
|
+
* can be negative.
|
2395
|
+
* @param {bitmask} [caps = STANDARD | DISTANCE_IN] which capabilities to
|
2396
|
+
* include.
|
2397
|
+
* @returns {object} the
|
2398
|
+
* {@link module:GeographicLib/GeodesicLine.GeodesicLine
|
2399
|
+
* GeodesicLine} object
|
2400
|
+
* @description This function sets point 3 of the GeodesicLine to correspond
|
2401
|
+
* to point 2 of the direct geodesic problem. For details on the caps
|
2402
|
+
* parameter, see {@tutorial 2-interface}, "The outmask and caps
|
2403
|
+
* parameters".
|
2404
|
+
*/
|
2405
|
+
g.Geodesic.prototype.DirectLine = function(lat1, lon1, azi1, s12, caps) {
|
2406
|
+
return this.GenDirectLine(lat1, lon1, azi1, false, s12, caps);
|
2407
|
+
};
|
2408
|
+
|
2409
|
+
/**
|
2410
|
+
* @summary Define a {@link module:GeographicLib/GeodesicLine.GeodesicLine
|
2411
|
+
* GeodesicLine} in terms of the direct geodesic problem specified in terms
|
2412
|
+
* of arc length.
|
2413
|
+
* @param {number} lat1 the latitude of the first point in degrees.
|
2414
|
+
* @param {number} lon1 the longitude of the first point in degrees.
|
2415
|
+
* @param {number} azi1 the azimuth at the first point in degrees.
|
2416
|
+
* degrees.
|
2417
|
+
* @param {number} a12 the arc length between point 1 and point 2 (degrees);
|
2418
|
+
* it can be negative.
|
2419
|
+
* @param {bitmask} [caps = STANDARD | DISTANCE_IN] which capabilities to
|
2420
|
+
* include.
|
2421
|
+
* @returns {object} the
|
2422
|
+
* {@link module:GeographicLib/GeodesicLine.GeodesicLine
|
2423
|
+
* GeodesicLine} object
|
2424
|
+
* @description This function sets point 3 of the GeodesicLine to correspond
|
2425
|
+
* to point 2 of the direct geodesic problem. For details on the caps
|
2426
|
+
* parameter, see {@tutorial 2-interface}, "The outmask and caps
|
2427
|
+
* parameters".
|
2428
|
+
*/
|
2429
|
+
g.Geodesic.prototype.ArcDirectLine = function(lat1, lon1, azi1, a12, caps) {
|
2430
|
+
return this.GenDirectLine(lat1, lon1, azi1, true, a12, caps);
|
2431
|
+
};
|
2432
|
+
|
2433
|
+
/**
|
2434
|
+
* @summary Define a {@link module:GeographicLib/GeodesicLine.GeodesicLine
|
2435
|
+
* GeodesicLine} in terms of the direct geodesic problem specified in terms
|
2436
|
+
* of either distance or arc length.
|
2437
|
+
* @param {number} lat1 the latitude of the first point in degrees.
|
2438
|
+
* @param {number} lon1 the longitude of the first point in degrees.
|
2439
|
+
* @param {number} azi1 the azimuth at the first point in degrees.
|
2440
|
+
* degrees.
|
2441
|
+
* @param {bool} arcmode boolean flag determining the meaning of the
|
2442
|
+
* s12_a12.
|
2443
|
+
* @param {number} s12_a12 if arcmode is false, this is the distance between
|
2444
|
+
* point 1 and point 2 (meters); otherwise it is the arc length between
|
2445
|
+
* point 1 and point 2 (degrees); it can be negative.
|
2446
|
+
* @param {bitmask} [caps = STANDARD | DISTANCE_IN] which capabilities to
|
2447
|
+
* include.
|
2448
|
+
* @returns {object} the
|
2449
|
+
* {@link module:GeographicLib/GeodesicLine.GeodesicLine
|
2450
|
+
* GeodesicLine} object
|
2451
|
+
* @description This function sets point 3 of the GeodesicLine to correspond
|
2452
|
+
* to point 2 of the direct geodesic problem. For details on the caps
|
2453
|
+
* parameter, see {@tutorial 2-interface}, "The outmask and caps
|
2454
|
+
* parameters".
|
2455
|
+
*/
|
2456
|
+
g.Geodesic.prototype.GenDirectLine = function(lat1, lon1, azi1,
|
2457
|
+
arcmode, s12_a12, caps) {
|
2458
|
+
var t;
|
2459
|
+
if (!caps) caps = g.STANDARD | g.DISTANCE_IN;
|
2460
|
+
// Automatically supply DISTANCE_IN if necessary
|
2461
|
+
if (!arcmode) caps |= g.DISTANCE_IN;
|
2462
|
+
t = new l.GeodesicLine(this, lat1, lon1, azi1, caps);
|
2463
|
+
t.GenSetDistance(arcmode, s12_a12);
|
2464
|
+
return t;
|
2465
|
+
};
|
2466
|
+
|
2467
|
+
/**
|
2468
|
+
* @summary Define a {@link module:GeographicLib/GeodesicLine.GeodesicLine
|
2469
|
+
* GeodesicLine} in terms of the inverse geodesic problem.
|
2470
|
+
* @param {number} lat1 the latitude of the first point in degrees.
|
2471
|
+
* @param {number} lon1 the longitude of the first point in degrees.
|
2472
|
+
* @param {number} lat2 the latitude of the second point in degrees.
|
2473
|
+
* @param {number} lon2 the longitude of the second point in degrees.
|
2474
|
+
* @param {bitmask} [caps = STANDARD | DISTANCE_IN] which capabilities to
|
2475
|
+
* include.
|
2476
|
+
* @returns {object} the
|
2477
|
+
* {@link module:GeographicLib/GeodesicLine.GeodesicLine
|
2478
|
+
* GeodesicLine} object
|
2479
|
+
* @description This function sets point 3 of the GeodesicLine to correspond
|
2480
|
+
* to point 2 of the inverse geodesic problem. For details on the caps
|
2481
|
+
* parameter, see {@tutorial 2-interface}, "The outmask and caps
|
2482
|
+
* parameters".
|
2483
|
+
*/
|
2484
|
+
g.Geodesic.prototype.InverseLine = function(lat1, lon1, lat2, lon2, caps) {
|
2485
|
+
var r, t, azi1;
|
2486
|
+
if (!caps) caps = g.STANDARD | g.DISTANCE_IN;
|
2487
|
+
r = this.InverseInt(lat1, lon1, lat2, lon2, g.ARC);
|
2488
|
+
azi1 = m.atan2d(r.salp1, r.calp1);
|
2489
|
+
// Ensure that a12 can be converted to a distance
|
2490
|
+
if (caps & (g.OUT_MASK & g.DISTANCE_IN)) caps |= g.DISTANCE;
|
2491
|
+
t = new l.GeodesicLine(this, lat1, lon1, azi1, caps, r.salp1, r.calp1);
|
2492
|
+
t.SetArc(r.vals.a12);
|
2493
|
+
return t;
|
2494
|
+
};
|
2495
|
+
|
2496
|
+
/**
|
2497
|
+
* @summary Create a {@link module:GeographicLib/PolygonArea.PolygonArea
|
2498
|
+
* PolygonArea} object.
|
2499
|
+
* @param {bool} [polyline = false] if true the new PolygonArea object
|
2500
|
+
* describes a polyline instead of a polygon.
|
2501
|
+
* @returns {object} the
|
2502
|
+
* {@link module:GeographicLib/PolygonArea.PolygonArea
|
2503
|
+
* PolygonArea} object
|
2504
|
+
*/
|
2505
|
+
g.Geodesic.prototype.Polygon = function(polyline) {
|
2506
|
+
return new p.PolygonArea(this, polyline);
|
2507
|
+
};
|
2508
|
+
|
2509
|
+
/**
|
2510
|
+
* @summary a {@link module:GeographicLib/Geodesic.Geodesic Geodesic} object
|
2511
|
+
* initialized for the WGS84 ellipsoid.
|
2512
|
+
* @constant {object}
|
2513
|
+
*/
|
2514
|
+
g.WGS84 = new g.Geodesic(c.WGS84.a, c.WGS84.f);
|
2515
|
+
})(GeographicLib.Geodesic, GeographicLib.GeodesicLine,
|
2516
|
+
GeographicLib.PolygonArea, GeographicLib.Math, GeographicLib.Constants);
|
2517
|
+
|
2518
|
+
/**************** GeodesicLine.js ****************/
|
2519
|
+
/*
|
2520
|
+
* GeodesicLine.js
|
2521
|
+
* Transcription of GeodesicLine.[ch]pp into JavaScript.
|
2522
|
+
*
|
2523
|
+
* See the documentation for the C++ class. The conversion is a literal
|
2524
|
+
* conversion from C++.
|
2525
|
+
*
|
2526
|
+
* The algorithms are derived in
|
2527
|
+
*
|
2528
|
+
* Charles F. F. Karney,
|
2529
|
+
* Algorithms for geodesics, J. Geodesy 87, 43-55 (2013);
|
2530
|
+
* https://doi.org/10.1007/s00190-012-0578-z
|
2531
|
+
* Addenda: https://geographiclib.sourceforge.io/geod-addenda.html
|
2532
|
+
*
|
2533
|
+
* Copyright (c) Charles Karney (2011-2016) <charles@karney.com> and licensed
|
2534
|
+
* under the MIT/X11 License. For more information, see
|
2535
|
+
* https://geographiclib.sourceforge.io/
|
2536
|
+
*/
|
2537
|
+
|
2538
|
+
// Load AFTER GeographicLib/Math.js, GeographicLib/Geodesic.js
|
2539
|
+
|
2540
|
+
(function(
|
2541
|
+
g,
|
2542
|
+
/**
|
2543
|
+
* @exports GeographicLib/GeodesicLine
|
2544
|
+
* @description Solve geodesic problems on a single geodesic line via the
|
2545
|
+
* {@link module:GeographicLib/GeodesicLine.GeodesicLine GeodesicLine}
|
2546
|
+
* class.
|
2547
|
+
*/
|
2548
|
+
l, m) {
|
2549
|
+
|
2550
|
+
/**
|
2551
|
+
* @class
|
2552
|
+
* @property {number} a the equatorial radius (meters).
|
2553
|
+
* @property {number} f the flattening.
|
2554
|
+
* @property {number} lat1 the initial latitude (degrees).
|
2555
|
+
* @property {number} lon1 the initial longitude (degrees).
|
2556
|
+
* @property {number} azi1 the initial azimuth (degrees).
|
2557
|
+
* @property {number} salp1 the sine of the azimuth at the first point.
|
2558
|
+
* @property {number} calp1 the cosine the azimuth at the first point.
|
2559
|
+
* @property {number} s13 the distance to point 3 (meters).
|
2560
|
+
* @property {number} a13 the arc length to point 3 (degrees).
|
2561
|
+
* @property {bitmask} caps the capabilities of the object.
|
2562
|
+
* @summary Initialize a GeodesicLine object. For details on the caps
|
2563
|
+
* parameter, see {@tutorial 2-interface}, "The outmask and caps
|
2564
|
+
* parameters".
|
2565
|
+
* @classdesc Performs geodesic calculations along a given geodesic line.
|
2566
|
+
* This object is usually instantiated by
|
2567
|
+
* {@link module:GeographicLib/Geodesic.Geodesic#Line Geodesic.Line}.
|
2568
|
+
* The methods
|
2569
|
+
* {@link module:GeographicLib/Geodesic.Geodesic#DirectLine
|
2570
|
+
* Geodesic.DirectLine} and
|
2571
|
+
* {@link module:GeographicLib/Geodesic.Geodesic#InverseLine
|
2572
|
+
* Geodesic.InverseLine} set in addition the position of a reference point
|
2573
|
+
* 3.
|
2574
|
+
* @param {object} geod a {@link module:GeographicLib/Geodesic.Geodesic
|
2575
|
+
* Geodesic} object.
|
2576
|
+
* @param {number} lat1 the latitude of the first point in degrees.
|
2577
|
+
* @param {number} lon1 the longitude of the first point in degrees.
|
2578
|
+
* @param {number} azi1 the azimuth at the first point in degrees.
|
2579
|
+
* @param {bitmask} [caps = STANDARD | DISTANCE_IN] which capabilities to
|
2580
|
+
* include; LATITUDE | AZIMUTH are always included.
|
2581
|
+
*/
|
2582
|
+
l.GeodesicLine = function(geod, lat1, lon1, azi1, caps, salp1, calp1) {
|
2583
|
+
var t, cbet1, sbet1, eps, s, c;
|
2584
|
+
if (!caps) caps = g.STANDARD | g.DISTANCE_IN;
|
2585
|
+
|
2586
|
+
this.a = geod.a;
|
2587
|
+
this.f = geod.f;
|
2588
|
+
this._b = geod._b;
|
2589
|
+
this._c2 = geod._c2;
|
2590
|
+
this._f1 = geod._f1;
|
2591
|
+
this.caps = caps | g.LATITUDE | g.AZIMUTH | g.LONG_UNROLL;
|
2592
|
+
|
2593
|
+
this.lat1 = m.LatFix(lat1);
|
2594
|
+
this.lon1 = lon1;
|
2595
|
+
if (typeof salp1 === 'undefined' || typeof calp1 === 'undefined') {
|
2596
|
+
this.azi1 = m.AngNormalize(azi1);
|
2597
|
+
t = m.sincosd(m.AngRound(this.azi1)); this.salp1 = t.s; this.calp1 = t.c;
|
2598
|
+
} else {
|
2599
|
+
this.azi1 = azi1; this.salp1 = salp1; this.calp1 = calp1;
|
2600
|
+
}
|
2601
|
+
t = m.sincosd(m.AngRound(this.lat1)); sbet1 = this._f1 * t.s; cbet1 = t.c;
|
2602
|
+
// norm(sbet1, cbet1);
|
2603
|
+
t = m.hypot(sbet1, cbet1); sbet1 /= t; cbet1 /= t;
|
2604
|
+
// Ensure cbet1 = +epsilon at poles
|
2605
|
+
cbet1 = Math.max(g.tiny_, cbet1);
|
2606
|
+
this._dn1 = Math.sqrt(1 + geod._ep2 * m.sq(sbet1));
|
2607
|
+
|
2608
|
+
// Evaluate alp0 from sin(alp1) * cos(bet1) = sin(alp0),
|
2609
|
+
this._salp0 = this.salp1 * cbet1; // alp0 in [0, pi/2 - |bet1|]
|
2610
|
+
// Alt: calp0 = hypot(sbet1, calp1 * cbet1). The following
|
2611
|
+
// is slightly better (consider the case salp1 = 0).
|
2612
|
+
this._calp0 = m.hypot(this.calp1, this.salp1 * sbet1);
|
2613
|
+
// Evaluate sig with tan(bet1) = tan(sig1) * cos(alp1).
|
2614
|
+
// sig = 0 is nearest northward crossing of equator.
|
2615
|
+
// With bet1 = 0, alp1 = pi/2, we have sig1 = 0 (equatorial line).
|
2616
|
+
// With bet1 = pi/2, alp1 = -pi, sig1 = pi/2
|
2617
|
+
// With bet1 = -pi/2, alp1 = 0 , sig1 = -pi/2
|
2618
|
+
// Evaluate omg1 with tan(omg1) = sin(alp0) * tan(sig1).
|
2619
|
+
// With alp0 in (0, pi/2], quadrants for sig and omg coincide.
|
2620
|
+
// No atan2(0,0) ambiguity at poles since cbet1 = +epsilon.
|
2621
|
+
// With alp0 = 0, omg1 = 0 for alp1 = 0, omg1 = pi for alp1 = pi.
|
2622
|
+
this._ssig1 = sbet1; this._somg1 = this._salp0 * sbet1;
|
2623
|
+
this._csig1 = this._comg1 =
|
2624
|
+
sbet1 !== 0 || this.calp1 !== 0 ? cbet1 * this.calp1 : 1;
|
2625
|
+
// norm(this._ssig1, this._csig1); // sig1 in (-pi, pi]
|
2626
|
+
t = m.hypot(this._ssig1, this._csig1);
|
2627
|
+
this._ssig1 /= t; this._csig1 /= t;
|
2628
|
+
// norm(this._somg1, this._comg1); -- don't need to normalize!
|
2629
|
+
|
2630
|
+
this._k2 = m.sq(this._calp0) * geod._ep2;
|
2631
|
+
eps = this._k2 / (2 * (1 + Math.sqrt(1 + this._k2)) + this._k2);
|
2632
|
+
|
2633
|
+
if (this.caps & g.CAP_C1) {
|
2634
|
+
this._A1m1 = g.A1m1f(eps);
|
2635
|
+
this._C1a = new Array(g.nC1_ + 1);
|
2636
|
+
g.C1f(eps, this._C1a);
|
2637
|
+
this._B11 = g.SinCosSeries(true, this._ssig1, this._csig1, this._C1a);
|
2638
|
+
s = Math.sin(this._B11); c = Math.cos(this._B11);
|
2639
|
+
// tau1 = sig1 + B11
|
2640
|
+
this._stau1 = this._ssig1 * c + this._csig1 * s;
|
2641
|
+
this._ctau1 = this._csig1 * c - this._ssig1 * s;
|
2642
|
+
// Not necessary because C1pa reverts C1a
|
2643
|
+
// _B11 = -SinCosSeries(true, _stau1, _ctau1, _C1pa);
|
2644
|
+
}
|
2645
|
+
|
2646
|
+
if (this.caps & g.CAP_C1p) {
|
2647
|
+
this._C1pa = new Array(g.nC1p_ + 1);
|
2648
|
+
g.C1pf(eps, this._C1pa);
|
2649
|
+
}
|
2650
|
+
|
2651
|
+
if (this.caps & g.CAP_C2) {
|
2652
|
+
this._A2m1 = g.A2m1f(eps);
|
2653
|
+
this._C2a = new Array(g.nC2_ + 1);
|
2654
|
+
g.C2f(eps, this._C2a);
|
2655
|
+
this._B21 = g.SinCosSeries(true, this._ssig1, this._csig1, this._C2a);
|
2656
|
+
}
|
2657
|
+
|
2658
|
+
if (this.caps & g.CAP_C3) {
|
2659
|
+
this._C3a = new Array(g.nC3_);
|
2660
|
+
geod.C3f(eps, this._C3a);
|
2661
|
+
this._A3c = -this.f * this._salp0 * geod.A3f(eps);
|
2662
|
+
this._B31 = g.SinCosSeries(true, this._ssig1, this._csig1, this._C3a);
|
2663
|
+
}
|
2664
|
+
|
2665
|
+
if (this.caps & g.CAP_C4) {
|
2666
|
+
this._C4a = new Array(g.nC4_); // all the elements of _C4a are used
|
2667
|
+
geod.C4f(eps, this._C4a);
|
2668
|
+
// Multiplier = a^2 * e^2 * cos(alpha0) * sin(alpha0)
|
2669
|
+
this._A4 = m.sq(this.a) * this._calp0 * this._salp0 * geod._e2;
|
2670
|
+
this._B41 = g.SinCosSeries(false, this._ssig1, this._csig1, this._C4a);
|
2671
|
+
}
|
2672
|
+
|
2673
|
+
this.a13 = this.s13 = Number.NaN;
|
2674
|
+
};
|
2675
|
+
|
2676
|
+
/**
|
2677
|
+
* @summary Find the position on the line (general case).
|
2678
|
+
* @param {bool} arcmode is the next parameter an arc length?
|
2679
|
+
* @param {number} s12_a12 the (arcmode ? arc length : distance) from the
|
2680
|
+
* first point to the second in (arcmode ? degrees : meters).
|
2681
|
+
* @param {bitmask} [outmask = STANDARD] which results to include; this is
|
2682
|
+
* subject to the capabilities of the object.
|
2683
|
+
* @returns {object} the requested results.
|
2684
|
+
* @description The lat1, lon1, azi1, and a12 fields of the result are
|
2685
|
+
* always set; s12 is included if arcmode is false. For details on the
|
2686
|
+
* outmask parameter, see {@tutorial 2-interface}, "The outmask and caps
|
2687
|
+
* parameters".
|
2688
|
+
*/
|
2689
|
+
l.GeodesicLine.prototype.GenPosition = function(arcmode, s12_a12,
|
2690
|
+
outmask) {
|
2691
|
+
var vals = {},
|
2692
|
+
sig12, ssig12, csig12, B12, AB1, ssig2, csig2, tau12, s, c, serr,
|
2693
|
+
omg12, lam12, lon12, E, sbet2, cbet2, somg2, comg2, salp2, calp2, dn2,
|
2694
|
+
B22, AB2, J12, t, B42, salp12, calp12;
|
2695
|
+
if (!outmask) outmask = g.STANDARD;
|
2696
|
+
else if (outmask === g.LONG_UNROLL) outmask |= g.STANDARD;
|
2697
|
+
outmask &= this.caps & g.OUT_MASK;
|
2698
|
+
vals.lat1 = this.lat1; vals.azi1 = this.azi1;
|
2699
|
+
vals.lon1 = outmask & g.LONG_UNROLL ?
|
2700
|
+
this.lon1 : m.AngNormalize(this.lon1);
|
2701
|
+
if (arcmode)
|
2702
|
+
vals.a12 = s12_a12;
|
2703
|
+
else
|
2704
|
+
vals.s12 = s12_a12;
|
2705
|
+
if (!( arcmode || (this.caps & g.DISTANCE_IN & g.OUT_MASK) )) {
|
2706
|
+
// Uninitialized or impossible distance calculation requested
|
2707
|
+
vals.a12 = Number.NaN;
|
2708
|
+
return vals;
|
2709
|
+
}
|
2710
|
+
|
2711
|
+
// Avoid warning about uninitialized B12.
|
2712
|
+
B12 = 0; AB1 = 0;
|
2713
|
+
if (arcmode) {
|
2714
|
+
// Interpret s12_a12 as spherical arc length
|
2715
|
+
sig12 = s12_a12 * m.degree;
|
2716
|
+
t = m.sincosd(s12_a12); ssig12 = t.s; csig12 = t.c;
|
2717
|
+
} else {
|
2718
|
+
// Interpret s12_a12 as distance
|
2719
|
+
tau12 = s12_a12 / (this._b * (1 + this._A1m1));
|
2720
|
+
s = Math.sin(tau12);
|
2721
|
+
c = Math.cos(tau12);
|
2722
|
+
// tau2 = tau1 + tau12
|
2723
|
+
B12 = -g.SinCosSeries(true,
|
2724
|
+
this._stau1 * c + this._ctau1 * s,
|
2725
|
+
this._ctau1 * c - this._stau1 * s,
|
2726
|
+
this._C1pa);
|
2727
|
+
sig12 = tau12 - (B12 - this._B11);
|
2728
|
+
ssig12 = Math.sin(sig12); csig12 = Math.cos(sig12);
|
2729
|
+
if (Math.abs(this.f) > 0.01) {
|
2730
|
+
// Reverted distance series is inaccurate for |f| > 1/100, so correct
|
2731
|
+
// sig12 with 1 Newton iteration. The following table shows the
|
2732
|
+
// approximate maximum error for a = WGS_a() and various f relative to
|
2733
|
+
// GeodesicExact.
|
2734
|
+
// erri = the error in the inverse solution (nm)
|
2735
|
+
// errd = the error in the direct solution (series only) (nm)
|
2736
|
+
// errda = the error in the direct solution
|
2737
|
+
// (series + 1 Newton) (nm)
|
2738
|
+
//
|
2739
|
+
// f erri errd errda
|
2740
|
+
// -1/5 12e6 1.2e9 69e6
|
2741
|
+
// -1/10 123e3 12e6 765e3
|
2742
|
+
// -1/20 1110 108e3 7155
|
2743
|
+
// -1/50 18.63 200.9 27.12
|
2744
|
+
// -1/100 18.63 23.78 23.37
|
2745
|
+
// -1/150 18.63 21.05 20.26
|
2746
|
+
// 1/150 22.35 24.73 25.83
|
2747
|
+
// 1/100 22.35 25.03 25.31
|
2748
|
+
// 1/50 29.80 231.9 30.44
|
2749
|
+
// 1/20 5376 146e3 10e3
|
2750
|
+
// 1/10 829e3 22e6 1.5e6
|
2751
|
+
// 1/5 157e6 3.8e9 280e6
|
2752
|
+
ssig2 = this._ssig1 * csig12 + this._csig1 * ssig12;
|
2753
|
+
csig2 = this._csig1 * csig12 - this._ssig1 * ssig12;
|
2754
|
+
B12 = g.SinCosSeries(true, ssig2, csig2, this._C1a);
|
2755
|
+
serr = (1 + this._A1m1) * (sig12 + (B12 - this._B11)) -
|
2756
|
+
s12_a12 / this._b;
|
2757
|
+
sig12 = sig12 - serr / Math.sqrt(1 + this._k2 * m.sq(ssig2));
|
2758
|
+
ssig12 = Math.sin(sig12); csig12 = Math.cos(sig12);
|
2759
|
+
// Update B12 below
|
2760
|
+
}
|
2761
|
+
}
|
2762
|
+
|
2763
|
+
// sig2 = sig1 + sig12
|
2764
|
+
ssig2 = this._ssig1 * csig12 + this._csig1 * ssig12;
|
2765
|
+
csig2 = this._csig1 * csig12 - this._ssig1 * ssig12;
|
2766
|
+
dn2 = Math.sqrt(1 + this._k2 * m.sq(ssig2));
|
2767
|
+
if (outmask & (g.DISTANCE | g.REDUCEDLENGTH | g.GEODESICSCALE)) {
|
2768
|
+
if (arcmode || Math.abs(this.f) > 0.01)
|
2769
|
+
B12 = g.SinCosSeries(true, ssig2, csig2, this._C1a);
|
2770
|
+
AB1 = (1 + this._A1m1) * (B12 - this._B11);
|
2771
|
+
}
|
2772
|
+
// sin(bet2) = cos(alp0) * sin(sig2)
|
2773
|
+
sbet2 = this._calp0 * ssig2;
|
2774
|
+
// Alt: cbet2 = hypot(csig2, salp0 * ssig2);
|
2775
|
+
cbet2 = m.hypot(this._salp0, this._calp0 * csig2);
|
2776
|
+
if (cbet2 === 0)
|
2777
|
+
// I.e., salp0 = 0, csig2 = 0. Break the degeneracy in this case
|
2778
|
+
cbet2 = csig2 = g.tiny_;
|
2779
|
+
// tan(alp0) = cos(sig2)*tan(alp2)
|
2780
|
+
salp2 = this._salp0; calp2 = this._calp0 * csig2; // No need to normalize
|
2781
|
+
|
2782
|
+
if (arcmode && (outmask & g.DISTANCE))
|
2783
|
+
vals.s12 = this._b * ((1 + this._A1m1) * sig12 + AB1);
|
2784
|
+
|
2785
|
+
if (outmask & g.LONGITUDE) {
|
2786
|
+
// tan(omg2) = sin(alp0) * tan(sig2)
|
2787
|
+
somg2 = this._salp0 * ssig2; comg2 = csig2; // No need to normalize
|
2788
|
+
E = m.copysign(1, this._salp0);
|
2789
|
+
// omg12 = omg2 - omg1
|
2790
|
+
omg12 = outmask & g.LONG_UNROLL ?
|
2791
|
+
E * (sig12 -
|
2792
|
+
(Math.atan2(ssig2, csig2) -
|
2793
|
+
Math.atan2(this._ssig1, this._csig1)) +
|
2794
|
+
(Math.atan2(E * somg2, comg2) -
|
2795
|
+
Math.atan2(E * this._somg1, this._comg1))) :
|
2796
|
+
Math.atan2(somg2 * this._comg1 - comg2 * this._somg1,
|
2797
|
+
comg2 * this._comg1 + somg2 * this._somg1);
|
2798
|
+
lam12 = omg12 + this._A3c *
|
2799
|
+
( sig12 + (g.SinCosSeries(true, ssig2, csig2, this._C3a) -
|
2800
|
+
this._B31));
|
2801
|
+
lon12 = lam12 / m.degree;
|
2802
|
+
vals.lon2 = outmask & g.LONG_UNROLL ? this.lon1 + lon12 :
|
2803
|
+
m.AngNormalize(m.AngNormalize(this.lon1) + m.AngNormalize(lon12));
|
2804
|
+
}
|
2805
|
+
|
2806
|
+
if (outmask & g.LATITUDE)
|
2807
|
+
vals.lat2 = m.atan2d(sbet2, this._f1 * cbet2);
|
2808
|
+
|
2809
|
+
if (outmask & g.AZIMUTH)
|
2810
|
+
vals.azi2 = m.atan2d(salp2, calp2);
|
2811
|
+
|
2812
|
+
if (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE)) {
|
2813
|
+
B22 = g.SinCosSeries(true, ssig2, csig2, this._C2a);
|
2814
|
+
AB2 = (1 + this._A2m1) * (B22 - this._B21);
|
2815
|
+
J12 = (this._A1m1 - this._A2m1) * sig12 + (AB1 - AB2);
|
2816
|
+
if (outmask & g.REDUCEDLENGTH)
|
2817
|
+
// Add parens around (_csig1 * ssig2) and (_ssig1 * csig2) to ensure
|
2818
|
+
// accurate cancellation in the case of coincident points.
|
2819
|
+
vals.m12 = this._b * (( dn2 * (this._csig1 * ssig2) -
|
2820
|
+
this._dn1 * (this._ssig1 * csig2)) -
|
2821
|
+
this._csig1 * csig2 * J12);
|
2822
|
+
if (outmask & g.GEODESICSCALE) {
|
2823
|
+
t = this._k2 * (ssig2 - this._ssig1) * (ssig2 + this._ssig1) /
|
2824
|
+
(this._dn1 + dn2);
|
2825
|
+
vals.M12 = csig12 +
|
2826
|
+
(t * ssig2 - csig2 * J12) * this._ssig1 / this._dn1;
|
2827
|
+
vals.M21 = csig12 -
|
2828
|
+
(t * this._ssig1 - this._csig1 * J12) * ssig2 / dn2;
|
2829
|
+
}
|
2830
|
+
}
|
2831
|
+
|
2832
|
+
if (outmask & g.AREA) {
|
2833
|
+
B42 = g.SinCosSeries(false, ssig2, csig2, this._C4a);
|
2834
|
+
if (this._calp0 === 0 || this._salp0 === 0) {
|
2835
|
+
// alp12 = alp2 - alp1, used in atan2 so no need to normalize
|
2836
|
+
salp12 = salp2 * this.calp1 - calp2 * this.salp1;
|
2837
|
+
calp12 = calp2 * this.calp1 + salp2 * this.salp1;
|
2838
|
+
} else {
|
2839
|
+
// tan(alp) = tan(alp0) * sec(sig)
|
2840
|
+
// tan(alp2-alp1) = (tan(alp2) -tan(alp1)) / (tan(alp2)*tan(alp1)+1)
|
2841
|
+
// = calp0 * salp0 * (csig1-csig2) / (salp0^2 + calp0^2 * csig1*csig2)
|
2842
|
+
// If csig12 > 0, write
|
2843
|
+
// csig1 - csig2 = ssig12 * (csig1 * ssig12 / (1 + csig12) + ssig1)
|
2844
|
+
// else
|
2845
|
+
// csig1 - csig2 = csig1 * (1 - csig12) + ssig12 * ssig1
|
2846
|
+
// No need to normalize
|
2847
|
+
salp12 = this._calp0 * this._salp0 *
|
2848
|
+
(csig12 <= 0 ? this._csig1 * (1 - csig12) + ssig12 * this._ssig1 :
|
2849
|
+
ssig12 * (this._csig1 * ssig12 / (1 + csig12) + this._ssig1));
|
2850
|
+
calp12 = m.sq(this._salp0) + m.sq(this._calp0) * this._csig1 * csig2;
|
2851
|
+
}
|
2852
|
+
vals.S12 = this._c2 * Math.atan2(salp12, calp12) +
|
2853
|
+
this._A4 * (B42 - this._B41);
|
2854
|
+
}
|
2855
|
+
|
2856
|
+
if (!arcmode)
|
2857
|
+
vals.a12 = sig12 / m.degree;
|
2858
|
+
return vals;
|
2859
|
+
};
|
2860
|
+
|
2861
|
+
/**
|
2862
|
+
* @summary Find the position on the line given s12.
|
2863
|
+
* @param {number} s12 the distance from the first point to the second in
|
2864
|
+
* meters.
|
2865
|
+
* @param {bitmask} [outmask = STANDARD] which results to include; this is
|
2866
|
+
* subject to the capabilities of the object.
|
2867
|
+
* @returns {object} the requested results.
|
2868
|
+
* @description The lat1, lon1, azi1, s12, and a12 fields of the result are
|
2869
|
+
* always set; s12 is included if arcmode is false. For details on the
|
2870
|
+
* outmask parameter, see {@tutorial 2-interface}, "The outmask and caps
|
2871
|
+
* parameters".
|
2872
|
+
*/
|
2873
|
+
l.GeodesicLine.prototype.Position = function(s12, outmask) {
|
2874
|
+
return this.GenPosition(false, s12, outmask);
|
2875
|
+
};
|
2876
|
+
|
2877
|
+
/**
|
2878
|
+
* @summary Find the position on the line given a12.
|
2879
|
+
* @param {number} a12 the arc length from the first point to the second in
|
2880
|
+
* degrees.
|
2881
|
+
* @param {bitmask} [outmask = STANDARD] which results to include; this is
|
2882
|
+
* subject to the capabilities of the object.
|
2883
|
+
* @returns {object} the requested results.
|
2884
|
+
* @description The lat1, lon1, azi1, and a12 fields of the result are
|
2885
|
+
* always set. For details on the outmask parameter, see {@tutorial
|
2886
|
+
* 2-interface}, "The outmask and caps parameters".
|
2887
|
+
*/
|
2888
|
+
l.GeodesicLine.prototype.ArcPosition = function(a12, outmask) {
|
2889
|
+
return this.GenPosition(true, a12, outmask);
|
2890
|
+
};
|
2891
|
+
|
2892
|
+
/**
|
2893
|
+
* @summary Specify position of point 3 in terms of either distance or arc
|
2894
|
+
* length.
|
2895
|
+
* @param {bool} arcmode boolean flag determining the meaning of the second
|
2896
|
+
* parameter; if arcmode is false, then the GeodesicLine object must have
|
2897
|
+
* been constructed with caps |= DISTANCE_IN.
|
2898
|
+
* @param {number} s13_a13 if arcmode is false, this is the distance from
|
2899
|
+
* point 1 to point 3 (meters); otherwise it is the arc length from
|
2900
|
+
* point 1 to point 3 (degrees); it can be negative.
|
2901
|
+
**********************************************************************/
|
2902
|
+
l.GeodesicLine.prototype.GenSetDistance = function(arcmode, s13_a13) {
|
2903
|
+
if (arcmode)
|
2904
|
+
this.SetArc(s13_a13);
|
2905
|
+
else
|
2906
|
+
this.SetDistance(s13_a13);
|
2907
|
+
};
|
2908
|
+
|
2909
|
+
/**
|
2910
|
+
* @summary Specify position of point 3 in terms distance.
|
2911
|
+
* @param {number} s13 the distance from point 1 to point 3 (meters); it
|
2912
|
+
* can be negative.
|
2913
|
+
**********************************************************************/
|
2914
|
+
l.GeodesicLine.prototype.SetDistance = function(s13) {
|
2915
|
+
var r;
|
2916
|
+
this.s13 = s13;
|
2917
|
+
r = this.GenPosition(false, this.s13, g.ARC);
|
2918
|
+
this.a13 = 0 + r.a12; // the 0+ converts undefined into NaN
|
2919
|
+
};
|
2920
|
+
|
2921
|
+
/**
|
2922
|
+
* @summary Specify position of point 3 in terms of arc length.
|
2923
|
+
* @param {number} a13 the arc length from point 1 to point 3 (degrees);
|
2924
|
+
* it can be negative.
|
2925
|
+
**********************************************************************/
|
2926
|
+
l.GeodesicLine.prototype.SetArc = function(a13) {
|
2927
|
+
var r;
|
2928
|
+
this.a13 = a13;
|
2929
|
+
r = this.GenPosition(true, this.a13, g.DISTANCE);
|
2930
|
+
this.s13 = 0 + r.s12; // the 0+ converts undefined into NaN
|
2931
|
+
};
|
2932
|
+
|
2933
|
+
})(GeographicLib.Geodesic, GeographicLib.GeodesicLine, GeographicLib.Math);
|
2934
|
+
|
2935
|
+
/**************** PolygonArea.js ****************/
|
2936
|
+
/*
|
2937
|
+
* PolygonArea.js
|
2938
|
+
* Transcription of PolygonArea.[ch]pp into JavaScript.
|
2939
|
+
*
|
2940
|
+
* See the documentation for the C++ class. The conversion is a literal
|
2941
|
+
* conversion from C++.
|
2942
|
+
*
|
2943
|
+
* The algorithms are derived in
|
2944
|
+
*
|
2945
|
+
* Charles F. F. Karney,
|
2946
|
+
* Algorithms for geodesics, J. Geodesy 87, 43-55 (2013);
|
2947
|
+
* https://doi.org/10.1007/s00190-012-0578-z
|
2948
|
+
* Addenda: https://geographiclib.sourceforge.io/geod-addenda.html
|
2949
|
+
*
|
2950
|
+
* Copyright (c) Charles Karney (2011-2017) <charles@karney.com> and licensed
|
2951
|
+
* under the MIT/X11 License. For more information, see
|
2952
|
+
* https://geographiclib.sourceforge.io/
|
2953
|
+
*/
|
2954
|
+
|
2955
|
+
// Load AFTER GeographicLib/Math.js and GeographicLib/Geodesic.js
|
2956
|
+
|
2957
|
+
(function(
|
2958
|
+
/**
|
2959
|
+
* @exports GeographicLib/PolygonArea
|
2960
|
+
* @description Compute the area of geodesic polygons via the
|
2961
|
+
* {@link module:GeographicLib/PolygonArea.PolygonArea PolygonArea}
|
2962
|
+
* class.
|
2963
|
+
*/
|
2964
|
+
p, g, m, a) {
|
2965
|
+
|
2966
|
+
var transit, transitdirect;
|
2967
|
+
transit = function(lon1, lon2) {
|
2968
|
+
// Return 1 or -1 if crossing prime meridian in east or west direction.
|
2969
|
+
// Otherwise return zero.
|
2970
|
+
var lon12, cross;
|
2971
|
+
// Compute lon12 the same way as Geodesic::Inverse.
|
2972
|
+
lon1 = m.AngNormalize(lon1);
|
2973
|
+
lon2 = m.AngNormalize(lon2);
|
2974
|
+
lon12 = m.AngDiff(lon1, lon2).s;
|
2975
|
+
cross = lon1 <= 0 && lon2 > 0 && lon12 > 0 ? 1 :
|
2976
|
+
(lon2 <= 0 && lon1 > 0 && lon12 < 0 ? -1 : 0);
|
2977
|
+
return cross;
|
2978
|
+
};
|
2979
|
+
|
2980
|
+
// an alternate version of transit to deal with longitudes in the direct
|
2981
|
+
// problem.
|
2982
|
+
transitdirect = function(lon1, lon2) {
|
2983
|
+
// We want to compute exactly
|
2984
|
+
// int(floor(lon2 / 360)) - int(floor(lon1 / 360))
|
2985
|
+
// Since we only need the parity of the result we can use std::remquo but
|
2986
|
+
// this is buggy with g++ 4.8.3 and requires C++11. So instead we do
|
2987
|
+
lon1 = lon1 % 720.0; lon2 = lon2 % 720.0;
|
2988
|
+
return ( ((lon2 >= 0 && lon2 < 360) || lon2 < -360 ? 0 : 1) -
|
2989
|
+
((lon1 >= 0 && lon1 < 360) || lon1 < -360 ? 0 : 1) );
|
2990
|
+
};
|
2991
|
+
|
2992
|
+
/**
|
2993
|
+
* @class
|
2994
|
+
* @property {number} a the equatorial radius (meters).
|
2995
|
+
* @property {number} f the flattening.
|
2996
|
+
* @property {bool} polyline whether the PolygonArea object describes a
|
2997
|
+
* polyline or a polygon.
|
2998
|
+
* @property {number} num the number of vertices so far.
|
2999
|
+
* @property {number} lat the current latitude (degrees).
|
3000
|
+
* @property {number} lon the current longitude (degrees).
|
3001
|
+
* @summary Initialize a PolygonArea object.
|
3002
|
+
* @classdesc Computes the area and perimeter of a geodesic polygon.
|
3003
|
+
* This object is usually instantiated by
|
3004
|
+
* {@link module:GeographicLib/Geodesic.Geodesic#Polygon Geodesic.Polygon}.
|
3005
|
+
* @param {object} geod a {@link module:GeographicLib/Geodesic.Geodesic
|
3006
|
+
* Geodesic} object.
|
3007
|
+
* @param {bool} [polyline = false] if true the new PolygonArea object
|
3008
|
+
* describes a polyline instead of a polygon.
|
3009
|
+
*/
|
3010
|
+
p.PolygonArea = function(geod, polyline) {
|
3011
|
+
this._geod = geod;
|
3012
|
+
this.a = this._geod.a;
|
3013
|
+
this.f = this._geod.f;
|
3014
|
+
this._area0 = 4 * Math.PI * geod._c2;
|
3015
|
+
this.polyline = !polyline ? false : polyline;
|
3016
|
+
this._mask = g.LATITUDE | g.LONGITUDE | g.DISTANCE |
|
3017
|
+
(this.polyline ? g.NONE : g.AREA | g.LONG_UNROLL);
|
3018
|
+
if (!this.polyline)
|
3019
|
+
this._areasum = new a.Accumulator(0);
|
3020
|
+
this._perimetersum = new a.Accumulator(0);
|
3021
|
+
this.Clear();
|
3022
|
+
};
|
3023
|
+
|
3024
|
+
/**
|
3025
|
+
* @summary Clear the PolygonArea object, setting the number of vertices to
|
3026
|
+
* 0.
|
3027
|
+
*/
|
3028
|
+
p.PolygonArea.prototype.Clear = function() {
|
3029
|
+
this.num = 0;
|
3030
|
+
this._crossings = 0;
|
3031
|
+
if (!this.polyline)
|
3032
|
+
this._areasum.Set(0);
|
3033
|
+
this._perimetersum.Set(0);
|
3034
|
+
this._lat0 = this._lon0 = this.lat = this.lon = Number.NaN;
|
3035
|
+
};
|
3036
|
+
|
3037
|
+
/**
|
3038
|
+
* @summary Add the next vertex to the polygon.
|
3039
|
+
* @param {number} lat the latitude of the point (degrees).
|
3040
|
+
* @param {number} lon the longitude of the point (degrees).
|
3041
|
+
* @description This adds an edge from the current vertex to the new vertex.
|
3042
|
+
*/
|
3043
|
+
p.PolygonArea.prototype.AddPoint = function(lat, lon) {
|
3044
|
+
var t;
|
3045
|
+
if (this.num === 0) {
|
3046
|
+
this._lat0 = this.lat = lat;
|
3047
|
+
this._lon0 = this.lon = lon;
|
3048
|
+
} else {
|
3049
|
+
t = this._geod.Inverse(this.lat, this.lon, lat, lon, this._mask);
|
3050
|
+
this._perimetersum.Add(t.s12);
|
3051
|
+
if (!this.polyline) {
|
3052
|
+
this._areasum.Add(t.S12);
|
3053
|
+
this._crossings += transit(this.lon, lon);
|
3054
|
+
}
|
3055
|
+
this.lat = lat;
|
3056
|
+
this.lon = lon;
|
3057
|
+
}
|
3058
|
+
++this.num;
|
3059
|
+
};
|
3060
|
+
|
3061
|
+
/**
|
3062
|
+
* @summary Add the next edge to the polygon.
|
3063
|
+
* @param {number} azi the azimuth at the current the point (degrees).
|
3064
|
+
* @param {number} s the length of the edge (meters).
|
3065
|
+
* @description This specifies the new vertex in terms of the edge from the
|
3066
|
+
* current vertex.
|
3067
|
+
*/
|
3068
|
+
p.PolygonArea.prototype.AddEdge = function(azi, s) {
|
3069
|
+
var t;
|
3070
|
+
if (this.num) {
|
3071
|
+
t = this._geod.Direct(this.lat, this.lon, azi, s, this._mask);
|
3072
|
+
this._perimetersum.Add(s);
|
3073
|
+
if (!this.polyline) {
|
3074
|
+
this._areasum.Add(t.S12);
|
3075
|
+
this._crossings += transitdirect(this.lon, t.lon2);
|
3076
|
+
}
|
3077
|
+
this.lat = t.lat2;
|
3078
|
+
this.lon = t.lon2;
|
3079
|
+
}
|
3080
|
+
++this.num;
|
3081
|
+
};
|
3082
|
+
|
3083
|
+
/**
|
3084
|
+
* @summary Compute the perimeter and area of the polygon.
|
3085
|
+
* @param {bool} reverse if true then clockwise (instead of
|
3086
|
+
* counter-clockwise) traversal counts as a positive area.
|
3087
|
+
* @param {bool} sign if true then return a signed result for the area if the
|
3088
|
+
* polygon is traversed in the "wrong" direction instead of returning the
|
3089
|
+
* area for the rest of the earth.
|
3090
|
+
* @returns {object} r where r.number is the number of vertices, r.perimeter
|
3091
|
+
* is the perimeter (meters), and r.area (only returned if polyline is
|
3092
|
+
* false) is the area (meters<sup>2</sup>).
|
3093
|
+
* @description If the object is a polygon (and not a polygon), the perimeter
|
3094
|
+
* includes the length of a final edge connecting the current point to the
|
3095
|
+
* initial point. If the object is a polyline, then area is nan. More
|
3096
|
+
* points can be added to the polygon after this call.
|
3097
|
+
*/
|
3098
|
+
p.PolygonArea.prototype.Compute = function(reverse, sign) {
|
3099
|
+
var vals = {number: this.num}, t, tempsum, crossings;
|
3100
|
+
if (this.num < 2) {
|
3101
|
+
vals.perimeter = 0;
|
3102
|
+
if (!this.polyline)
|
3103
|
+
vals.area = 0;
|
3104
|
+
return vals;
|
3105
|
+
}
|
3106
|
+
if (this.polyline) {
|
3107
|
+
vals.perimeter = this._perimetersum.Sum();
|
3108
|
+
return vals;
|
3109
|
+
}
|
3110
|
+
t = this._geod.Inverse(this.lat, this.lon, this._lat0, this._lon0,
|
3111
|
+
this._mask);
|
3112
|
+
vals.perimeter = this._perimetersum.Sum(t.s12);
|
3113
|
+
tempsum = new a.Accumulator(this._areasum);
|
3114
|
+
tempsum.Add(t.S12);
|
3115
|
+
crossings = this._crossings + transit(this.lon, this._lon0);
|
3116
|
+
if (crossings & 1)
|
3117
|
+
tempsum.Add( (tempsum.Sum() < 0 ? 1 : -1) * this._area0/2 );
|
3118
|
+
// area is with the clockwise sense. If !reverse convert to
|
3119
|
+
// counter-clockwise convention.
|
3120
|
+
if (!reverse)
|
3121
|
+
tempsum.Negate();
|
3122
|
+
// If sign put area in (-area0/2, area0/2], else put area in [0, area0)
|
3123
|
+
if (sign) {
|
3124
|
+
if (tempsum.Sum() > this._area0/2)
|
3125
|
+
tempsum.Add( -this._area0 );
|
3126
|
+
else if (tempsum.Sum() <= -this._area0/2)
|
3127
|
+
tempsum.Add( +this._area0 );
|
3128
|
+
} else {
|
3129
|
+
if (tempsum.Sum() >= this._area0)
|
3130
|
+
tempsum.Add( -this._area0 );
|
3131
|
+
else if (tempsum < 0)
|
3132
|
+
tempsum.Add( -this._area0 );
|
3133
|
+
}
|
3134
|
+
vals.area = tempsum.Sum();
|
3135
|
+
return vals;
|
3136
|
+
};
|
3137
|
+
|
3138
|
+
/**
|
3139
|
+
* @summary Compute the perimeter and area of the polygon with a tentative
|
3140
|
+
* new vertex.
|
3141
|
+
* @param {number} lat the latitude of the point (degrees).
|
3142
|
+
* @param {number} lon the longitude of the point (degrees).
|
3143
|
+
* @param {bool} reverse if true then clockwise (instead of
|
3144
|
+
* counter-clockwise) traversal counts as a positive area.
|
3145
|
+
* @param {bool} sign if true then return a signed result for the area if the
|
3146
|
+
* polygon is traversed in the "wrong" direction instead of returning the
|
3147
|
+
* @returns {object} r where r.number is the number of vertices, r.perimeter
|
3148
|
+
* is the perimeter (meters), and r.area (only returned if polyline is
|
3149
|
+
* false) is the area (meters<sup>2</sup>).
|
3150
|
+
* @description A new vertex is *not* added to the polygon.
|
3151
|
+
*/
|
3152
|
+
p.PolygonArea.prototype.TestPoint = function(lat, lon, reverse, sign) {
|
3153
|
+
var vals = {number: this.num + 1}, t, tempsum, crossings, i;
|
3154
|
+
if (this.num === 0) {
|
3155
|
+
vals.perimeter = 0;
|
3156
|
+
if (!this.polyline)
|
3157
|
+
vals.area = 0;
|
3158
|
+
return vals;
|
3159
|
+
}
|
3160
|
+
vals.perimeter = this._perimetersum.Sum();
|
3161
|
+
tempsum = this.polyline ? 0 : this._areasum.Sum();
|
3162
|
+
crossings = this._crossings;
|
3163
|
+
for (i = 0; i < (this.polyline ? 1 : 2); ++i) {
|
3164
|
+
t = this._geod.Inverse(
|
3165
|
+
i === 0 ? this.lat : lat, i === 0 ? this.lon : lon,
|
3166
|
+
i !== 0 ? this._lat0 : lat, i !== 0 ? this._lon0 : lon,
|
3167
|
+
this._mask);
|
3168
|
+
vals.perimeter += t.s12;
|
3169
|
+
if (!this.polyline) {
|
3170
|
+
tempsum += t.S12;
|
3171
|
+
crossings += transit(i === 0 ? this.lon : lon,
|
3172
|
+
i !== 0 ? this._lon0 : lon);
|
3173
|
+
}
|
3174
|
+
}
|
3175
|
+
|
3176
|
+
if (this.polyline)
|
3177
|
+
return vals;
|
3178
|
+
|
3179
|
+
if (crossings & 1)
|
3180
|
+
tempsum += (tempsum < 0 ? 1 : -1) * this._area0/2;
|
3181
|
+
// area is with the clockwise sense. If !reverse convert to
|
3182
|
+
// counter-clockwise convention.
|
3183
|
+
if (!reverse)
|
3184
|
+
tempsum *= -1;
|
3185
|
+
// If sign put area in (-area0/2, area0/2], else put area in [0, area0)
|
3186
|
+
if (sign) {
|
3187
|
+
if (tempsum > this._area0/2)
|
3188
|
+
tempsum -= this._area0;
|
3189
|
+
else if (tempsum <= -this._area0/2)
|
3190
|
+
tempsum += this._area0;
|
3191
|
+
} else {
|
3192
|
+
if (tempsum >= this._area0)
|
3193
|
+
tempsum -= this._area0;
|
3194
|
+
else if (tempsum < 0)
|
3195
|
+
tempsum += this._area0;
|
3196
|
+
}
|
3197
|
+
vals.area = tempsum;
|
3198
|
+
return vals;
|
3199
|
+
};
|
3200
|
+
|
3201
|
+
/**
|
3202
|
+
* @summary Compute the perimeter and area of the polygon with a tentative
|
3203
|
+
* new edge.
|
3204
|
+
* @param {number} azi the azimuth of the edge (degrees).
|
3205
|
+
* @param {number} s the length of the edge (meters).
|
3206
|
+
* @param {bool} reverse if true then clockwise (instead of
|
3207
|
+
* counter-clockwise) traversal counts as a positive area.
|
3208
|
+
* @param {bool} sign if true then return a signed result for the area if the
|
3209
|
+
* polygon is traversed in the "wrong" direction instead of returning the
|
3210
|
+
* @returns {object} r where r.number is the number of vertices, r.perimeter
|
3211
|
+
* is the perimeter (meters), and r.area (only returned if polyline is
|
3212
|
+
* false) is the area (meters<sup>2</sup>).
|
3213
|
+
* @description A new vertex is *not* added to the polygon.
|
3214
|
+
*/
|
3215
|
+
p.PolygonArea.prototype.TestEdge = function(azi, s, reverse, sign) {
|
3216
|
+
var vals = {number: this.num ? this.num + 1 : 0}, t, tempsum, crossings;
|
3217
|
+
if (this.num === 0)
|
3218
|
+
return vals;
|
3219
|
+
vals.perimeter = this._perimetersum.Sum() + s;
|
3220
|
+
if (this.polyline)
|
3221
|
+
return vals;
|
3222
|
+
|
3223
|
+
tempsum = this._areasum.Sum();
|
3224
|
+
crossings = this._crossings;
|
3225
|
+
t = this._geod.Direct(this.lat, this.lon, azi, s, this._mask);
|
3226
|
+
tempsum += t.S12;
|
3227
|
+
crossings += transitdirect(this.lon, t.lon2);
|
3228
|
+
t = this._geod.Inverse(t.lat2, t.lon2, this._lat0, this._lon0, this._mask);
|
3229
|
+
vals.perimeter += t.s12;
|
3230
|
+
tempsum += t.S12;
|
3231
|
+
crossings += transit(t.lon2, this._lon0);
|
3232
|
+
|
3233
|
+
if (crossings & 1)
|
3234
|
+
tempsum += (tempsum < 0 ? 1 : -1) * this._area0/2;
|
3235
|
+
// area is with the clockwise sense. If !reverse convert to
|
3236
|
+
// counter-clockwise convention.
|
3237
|
+
if (!reverse)
|
3238
|
+
tempsum *= -1;
|
3239
|
+
// If sign put area in (-area0/2, area0/2], else put area in [0, area0)
|
3240
|
+
if (sign) {
|
3241
|
+
if (tempsum > this._area0/2)
|
3242
|
+
tempsum -= this._area0;
|
3243
|
+
else if (tempsum <= -this._area0/2)
|
3244
|
+
tempsum += this._area0;
|
3245
|
+
} else {
|
3246
|
+
if (tempsum >= this._area0)
|
3247
|
+
tempsum -= this._area0;
|
3248
|
+
else if (tempsum < 0)
|
3249
|
+
tempsum += this._area0;
|
3250
|
+
}
|
3251
|
+
vals.area = tempsum;
|
3252
|
+
return vals;
|
3253
|
+
};
|
3254
|
+
|
3255
|
+
})(GeographicLib.PolygonArea, GeographicLib.Geodesic,
|
3256
|
+
GeographicLib.Math, GeographicLib.Accumulator);
|
3257
|
+
|
3258
|
+
/**************** DMS.js ****************/
|
3259
|
+
/*
|
3260
|
+
* DMS.js
|
3261
|
+
* Transcription of DMS.[ch]pp into JavaScript.
|
3262
|
+
*
|
3263
|
+
* See the documentation for the C++ class. The conversion is a literal
|
3264
|
+
* conversion from C++.
|
3265
|
+
*
|
3266
|
+
* Copyright (c) Charles Karney (2011-2017) <charles@karney.com> and licensed
|
3267
|
+
* under the MIT/X11 License. For more information, see
|
3268
|
+
* https://geographiclib.sourceforge.io/
|
3269
|
+
*/
|
3270
|
+
|
3271
|
+
GeographicLib.DMS = {};
|
3272
|
+
|
3273
|
+
(function(
|
3274
|
+
/**
|
3275
|
+
* @exports GeographicLib/DMS
|
3276
|
+
* @description Decode/Encode angles expressed as degrees, minutes, and
|
3277
|
+
* seconds. This module defines several constants:
|
3278
|
+
* - hemisphere indicator (returned by
|
3279
|
+
* {@link module:GeographicLib/DMS.Decode Decode}) and a formatting
|
3280
|
+
* indicator (used by
|
3281
|
+
* {@link module:GeographicLib/DMS.Encode Encode})
|
3282
|
+
* - NONE = 0, no designator and format as plain angle;
|
3283
|
+
* - LATITUDE = 1, a N/S designator and format as latitude;
|
3284
|
+
* - LONGITUDE = 2, an E/W designator and format as longitude;
|
3285
|
+
* - AZIMUTH = 3, format as azimuth;
|
3286
|
+
* - the specification of the trailing component in
|
3287
|
+
* {@link module:GeographicLib/DMS.Encode Encode}
|
3288
|
+
* - DEGREE;
|
3289
|
+
* - MINUTE;
|
3290
|
+
* - SECOND.
|
3291
|
+
*/
|
3292
|
+
d) {
|
3293
|
+
|
3294
|
+
var lookup, zerofill, internalDecode, numMatch,
|
3295
|
+
hemispheres_ = "SNWE",
|
3296
|
+
signs_ = "-+",
|
3297
|
+
digits_ = "0123456789",
|
3298
|
+
dmsindicators_ = "D'\":",
|
3299
|
+
// dmsindicatorsu_ = "\u00b0\u2032\u2033"; // Unicode variants
|
3300
|
+
dmsindicatorsu_ = "\u00b0'\"", // Use degree symbol
|
3301
|
+
components_ = ["degrees", "minutes", "seconds"];
|
3302
|
+
lookup = function(s, c) {
|
3303
|
+
return s.indexOf(c.toUpperCase());
|
3304
|
+
};
|
3305
|
+
zerofill = function(s, n) {
|
3306
|
+
return String("0000").substr(0, Math.max(0, Math.min(4, n-s.length))) +
|
3307
|
+
s;
|
3308
|
+
};
|
3309
|
+
d.NONE = 0;
|
3310
|
+
d.LATITUDE = 1;
|
3311
|
+
d.LONGITUDE = 2;
|
3312
|
+
d.AZIMUTH = 3;
|
3313
|
+
d.DEGREE = 0;
|
3314
|
+
d.MINUTE = 1;
|
3315
|
+
d.SECOND = 2;
|
3316
|
+
|
3317
|
+
/**
|
3318
|
+
* @summary Decode a DMS string.
|
3319
|
+
* @description The interpretation of the string is given in the
|
3320
|
+
* documentation of the corresponding function, Decode(string&, flag&)
|
3321
|
+
* in the {@link
|
3322
|
+
* https://geographiclib.sourceforge.io/html/classGeographicLib_1_1DMS.html
|
3323
|
+
* C++ DMS class}
|
3324
|
+
* @param {string} dms the string.
|
3325
|
+
* @returns {object} r where r.val is the decoded value (degrees) and r.ind
|
3326
|
+
* is a hemisphere designator, one of NONE, LATITUDE, LONGITUDE.
|
3327
|
+
* @throws an error if the string is illegal.
|
3328
|
+
*/
|
3329
|
+
d.Decode = function(dms) {
|
3330
|
+
var dmsa = dms, end,
|
3331
|
+
v = 0, i = 0, mi, pi, vals,
|
3332
|
+
ind1 = d.NONE, ind2, p, pa, pb;
|
3333
|
+
dmsa = dmsa.replace(/\u00b0/g, 'd')
|
3334
|
+
.replace(/\u00ba/g, 'd')
|
3335
|
+
.replace(/\u2070/g, 'd')
|
3336
|
+
.replace(/\u02da/g, 'd')
|
3337
|
+
.replace(/\u2032/g, '\'')
|
3338
|
+
.replace(/\u00b4/g, '\'')
|
3339
|
+
.replace(/\u2019/g, '\'')
|
3340
|
+
.replace(/\u2033/g, '"')
|
3341
|
+
.replace(/\u201d/g, '"')
|
3342
|
+
.replace(/\u2212/g, '-')
|
3343
|
+
.replace(/''/g, '"')
|
3344
|
+
.trim();
|
3345
|
+
end = dmsa.length;
|
3346
|
+
// p is pointer to the next piece that needs decoding
|
3347
|
+
for (p = 0; p < end; p = pb, ++i) {
|
3348
|
+
pa = p;
|
3349
|
+
// Skip over initial hemisphere letter (for i == 0)
|
3350
|
+
if (i === 0 && lookup(hemispheres_, dmsa.charAt(pa)) >= 0)
|
3351
|
+
++pa;
|
3352
|
+
// Skip over initial sign (checking for it if i == 0)
|
3353
|
+
if (i > 0 || (pa < end && lookup(signs_, dmsa.charAt(pa)) >= 0))
|
3354
|
+
++pa;
|
3355
|
+
// Find next sign
|
3356
|
+
mi = dmsa.substr(pa, end - pa).indexOf('-');
|
3357
|
+
pi = dmsa.substr(pa, end - pa).indexOf('+');
|
3358
|
+
if (mi < 0) mi = end; else mi += pa;
|
3359
|
+
if (pi < 0) pi = end; else pi += pa;
|
3360
|
+
pb = Math.min(mi, pi);
|
3361
|
+
vals = internalDecode(dmsa.substr(p, pb - p));
|
3362
|
+
v += vals.val; ind2 = vals.ind;
|
3363
|
+
if (ind1 === d.NONE)
|
3364
|
+
ind1 = ind2;
|
3365
|
+
else if (!(ind2 === d.NONE || ind1 === ind2))
|
3366
|
+
throw new Error("Incompatible hemisphere specifies in " +
|
3367
|
+
dmsa.substr(0, pb));
|
3368
|
+
}
|
3369
|
+
if (i === 0)
|
3370
|
+
throw new Error("Empty or incomplete DMS string " + dmsa);
|
3371
|
+
return {val: v, ind: ind1};
|
3372
|
+
};
|
3373
|
+
|
3374
|
+
internalDecode = function(dmsa) {
|
3375
|
+
var vals = {}, errormsg = "",
|
3376
|
+
sign, beg, end, ind1, k,
|
3377
|
+
ipieces, fpieces, npiece,
|
3378
|
+
icurrent, fcurrent, ncurrent, p,
|
3379
|
+
pointseen,
|
3380
|
+
digcount, intcount,
|
3381
|
+
x;
|
3382
|
+
do { // Executed once (provides the ability to break)
|
3383
|
+
sign = 1;
|
3384
|
+
beg = 0; end = dmsa.length;
|
3385
|
+
ind1 = d.NONE;
|
3386
|
+
k = -1;
|
3387
|
+
if (end > beg && (k = lookup(hemispheres_, dmsa.charAt(beg))) >= 0) {
|
3388
|
+
ind1 = (k & 2) ? d.LONGITUDE : d.LATITUDE;
|
3389
|
+
sign = (k & 1) ? 1 : -1;
|
3390
|
+
++beg;
|
3391
|
+
}
|
3392
|
+
if (end > beg &&
|
3393
|
+
(k = lookup(hemispheres_, dmsa.charAt(end-1))) >= 0) {
|
3394
|
+
if (k >= 0) {
|
3395
|
+
if (ind1 !== d.NONE) {
|
3396
|
+
if (dmsa.charAt(beg - 1).toUpperCase() ===
|
3397
|
+
dmsa.charAt(end - 1).toUpperCase())
|
3398
|
+
errormsg = "Repeated hemisphere indicators " +
|
3399
|
+
dmsa.charAt(beg - 1) + " in " +
|
3400
|
+
dmsa.substr(beg - 1, end - beg + 1);
|
3401
|
+
else
|
3402
|
+
errormsg = "Contradictory hemisphere indicators " +
|
3403
|
+
dmsa.charAt(beg - 1) + " and " + dmsa.charAt(end - 1) + " in " +
|
3404
|
+
dmsa.substr(beg - 1, end - beg + 1);
|
3405
|
+
break;
|
3406
|
+
}
|
3407
|
+
ind1 = (k & 2) ? d.LONGITUDE : d.LATITUDE;
|
3408
|
+
sign = (k & 1) ? 1 : -1;
|
3409
|
+
--end;
|
3410
|
+
}
|
3411
|
+
}
|
3412
|
+
if (end > beg && (k = lookup(signs_, dmsa.charAt(beg))) >= 0) {
|
3413
|
+
if (k >= 0) {
|
3414
|
+
sign *= k ? 1 : -1;
|
3415
|
+
++beg;
|
3416
|
+
}
|
3417
|
+
}
|
3418
|
+
if (end === beg) {
|
3419
|
+
errormsg = "Empty or incomplete DMS string " + dmsa;
|
3420
|
+
break;
|
3421
|
+
}
|
3422
|
+
ipieces = [0, 0, 0];
|
3423
|
+
fpieces = [0, 0, 0];
|
3424
|
+
npiece = 0;
|
3425
|
+
icurrent = 0;
|
3426
|
+
fcurrent = 0;
|
3427
|
+
ncurrent = 0;
|
3428
|
+
p = beg;
|
3429
|
+
pointseen = false;
|
3430
|
+
digcount = 0;
|
3431
|
+
intcount = 0;
|
3432
|
+
while (p < end) {
|
3433
|
+
x = dmsa.charAt(p++);
|
3434
|
+
if ((k = lookup(digits_, x)) >= 0) {
|
3435
|
+
++ncurrent;
|
3436
|
+
if (digcount > 0) {
|
3437
|
+
++digcount; // Count of decimal digits
|
3438
|
+
} else {
|
3439
|
+
icurrent = 10 * icurrent + k;
|
3440
|
+
++intcount;
|
3441
|
+
}
|
3442
|
+
} else if (x === '.') {
|
3443
|
+
if (pointseen) {
|
3444
|
+
errormsg = "Multiple decimal points in " +
|
3445
|
+
dmsa.substr(beg, end - beg);
|
3446
|
+
break;
|
3447
|
+
}
|
3448
|
+
pointseen = true;
|
3449
|
+
digcount = 1;
|
3450
|
+
} else if ((k = lookup(dmsindicators_, x)) >= 0) {
|
3451
|
+
if (k >= 3) {
|
3452
|
+
if (p === end) {
|
3453
|
+
errormsg = "Illegal for colon to appear at the end of " +
|
3454
|
+
dmsa.substr(beg, end - beg);
|
3455
|
+
break;
|
3456
|
+
}
|
3457
|
+
k = npiece;
|
3458
|
+
}
|
3459
|
+
if (k === npiece - 1) {
|
3460
|
+
errormsg = "Repeated " + components_[k] +
|
3461
|
+
" component in " + dmsa.substr(beg, end - beg);
|
3462
|
+
break;
|
3463
|
+
} else if (k < npiece) {
|
3464
|
+
errormsg = components_[k] + " component follows " +
|
3465
|
+
components_[npiece - 1] + " component in " +
|
3466
|
+
dmsa.substr(beg, end - beg);
|
3467
|
+
break;
|
3468
|
+
}
|
3469
|
+
if (ncurrent === 0) {
|
3470
|
+
errormsg = "Missing numbers in " + components_[k] +
|
3471
|
+
" component of " + dmsa.substr(beg, end - beg);
|
3472
|
+
break;
|
3473
|
+
}
|
3474
|
+
if (digcount > 0) {
|
3475
|
+
fcurrent = parseFloat(dmsa.substr(p - intcount - digcount - 1,
|
3476
|
+
intcount + digcount));
|
3477
|
+
icurrent = 0;
|
3478
|
+
}
|
3479
|
+
ipieces[k] = icurrent;
|
3480
|
+
fpieces[k] = icurrent + fcurrent;
|
3481
|
+
if (p < end) {
|
3482
|
+
npiece = k + 1;
|
3483
|
+
icurrent = fcurrent = 0;
|
3484
|
+
ncurrent = digcount = intcount = 0;
|
3485
|
+
}
|
3486
|
+
} else if (lookup(signs_, x) >= 0) {
|
3487
|
+
errormsg = "Internal sign in DMS string " +
|
3488
|
+
dmsa.substr(beg, end - beg);
|
3489
|
+
break;
|
3490
|
+
} else {
|
3491
|
+
errormsg = "Illegal character " + x + " in DMS string " +
|
3492
|
+
dmsa.substr(beg, end - beg);
|
3493
|
+
break;
|
3494
|
+
}
|
3495
|
+
}
|
3496
|
+
if (errormsg.length)
|
3497
|
+
break;
|
3498
|
+
if (lookup(dmsindicators_, dmsa.charAt(p - 1)) < 0) {
|
3499
|
+
if (npiece >= 3) {
|
3500
|
+
errormsg = "Extra text following seconds in DMS string " +
|
3501
|
+
dmsa.substr(beg, end - beg);
|
3502
|
+
break;
|
3503
|
+
}
|
3504
|
+
if (ncurrent === 0) {
|
3505
|
+
errormsg = "Missing numbers in trailing component of " +
|
3506
|
+
dmsa.substr(beg, end - beg);
|
3507
|
+
break;
|
3508
|
+
}
|
3509
|
+
if (digcount > 0) {
|
3510
|
+
fcurrent = parseFloat(dmsa.substr(p - intcount - digcount,
|
3511
|
+
intcount + digcount));
|
3512
|
+
icurrent = 0;
|
3513
|
+
}
|
3514
|
+
ipieces[npiece] = icurrent;
|
3515
|
+
fpieces[npiece] = icurrent + fcurrent;
|
3516
|
+
}
|
3517
|
+
if (pointseen && digcount === 0) {
|
3518
|
+
errormsg = "Decimal point in non-terminal component of " +
|
3519
|
+
dmsa.substr(beg, end - beg);
|
3520
|
+
break;
|
3521
|
+
}
|
3522
|
+
// Note that we accept 59.999999... even though it rounds to 60.
|
3523
|
+
if (ipieces[1] >= 60 || fpieces[1] > 60) {
|
3524
|
+
errormsg = "Minutes " + fpieces[1] + " not in range [0,60)";
|
3525
|
+
break;
|
3526
|
+
}
|
3527
|
+
if (ipieces[2] >= 60 || fpieces[2] > 60) {
|
3528
|
+
errormsg = "Seconds " + fpieces[2] + " not in range [0,60)";
|
3529
|
+
break;
|
3530
|
+
}
|
3531
|
+
vals.ind = ind1;
|
3532
|
+
// Assume check on range of result is made by calling routine (which
|
3533
|
+
// might be able to offer a better diagnostic).
|
3534
|
+
vals.val = sign *
|
3535
|
+
( fpieces[2] ? (60*(60*fpieces[0] + fpieces[1]) + fpieces[2]) / 3600 :
|
3536
|
+
( fpieces[1] ? (60*fpieces[0] + fpieces[1]) / 60 : fpieces[0] ) );
|
3537
|
+
return vals;
|
3538
|
+
} while (false);
|
3539
|
+
vals.val = numMatch(dmsa);
|
3540
|
+
if (vals.val === 0)
|
3541
|
+
throw new Error(errormsg);
|
3542
|
+
else
|
3543
|
+
vals.ind = d.NONE;
|
3544
|
+
return vals;
|
3545
|
+
};
|
3546
|
+
|
3547
|
+
numMatch = function(s) {
|
3548
|
+
var t, sign, p0, p1;
|
3549
|
+
if (s.length < 3)
|
3550
|
+
return 0;
|
3551
|
+
t = s.toUpperCase().replace(/0+$/, "");
|
3552
|
+
sign = t.charAt(0) === '-' ? -1 : 1;
|
3553
|
+
p0 = t.charAt(0) === '-' || t.charAt(0) === '+' ? 1 : 0;
|
3554
|
+
p1 = t.length - 1;
|
3555
|
+
if (p1 + 1 < p0 + 3)
|
3556
|
+
return 0;
|
3557
|
+
// Strip off sign and trailing 0s
|
3558
|
+
t = t.substr(p0, p1 + 1 - p0); // Length at least 3
|
3559
|
+
if (t === "NAN" || t === "1.#QNAN" || t === "1.#SNAN" || t === "1.#IND" ||
|
3560
|
+
t === "1.#R")
|
3561
|
+
return Number.NaN;
|
3562
|
+
else if (t === "INF" || t === "1.#INF")
|
3563
|
+
return sign * Number.POSITIVE_INFINITY;
|
3564
|
+
return 0;
|
3565
|
+
};
|
3566
|
+
|
3567
|
+
/**
|
3568
|
+
* @summary Decode two DMS strings interpreting them as a latitude/longitude
|
3569
|
+
* pair.
|
3570
|
+
* @param {string} stra the first string.
|
3571
|
+
* @param {string} strb the first string.
|
3572
|
+
* @param {bool} [longfirst = false] if true assume then longitude is given
|
3573
|
+
* first (in the absense of any hemisphere indicators).
|
3574
|
+
* @returns {object} r where r.lat is the decoded latitude and r.lon is the
|
3575
|
+
* decoded longitude (both in degrees).
|
3576
|
+
* @throws an error if the strings are illegal.
|
3577
|
+
*/
|
3578
|
+
d.DecodeLatLon = function(stra, strb, longfirst) {
|
3579
|
+
var vals = {},
|
3580
|
+
valsa = d.Decode(stra),
|
3581
|
+
valsb = d.Decode(strb),
|
3582
|
+
a = valsa.val, ia = valsa.ind,
|
3583
|
+
b = valsb.val, ib = valsb.ind,
|
3584
|
+
lat, lon;
|
3585
|
+
if (!longfirst) longfirst = false;
|
3586
|
+
if (ia === d.NONE && ib === d.NONE) {
|
3587
|
+
// Default to lat, long unless longfirst
|
3588
|
+
ia = longfirst ? d.LONGITUDE : d.LATITUDE;
|
3589
|
+
ib = longfirst ? d.LATITUDE : d.LONGITUDE;
|
3590
|
+
} else if (ia === d.NONE)
|
3591
|
+
ia = d.LATITUDE + d.LONGITUDE - ib;
|
3592
|
+
else if (ib === d.NONE)
|
3593
|
+
ib = d.LATITUDE + d.LONGITUDE - ia;
|
3594
|
+
if (ia === ib)
|
3595
|
+
throw new Error("Both " + stra + " and " + strb + " interpreted as " +
|
3596
|
+
(ia === d.LATITUDE ? "latitudes" : "longitudes"));
|
3597
|
+
lat = ia === d.LATITUDE ? a : b;
|
3598
|
+
lon = ia === d.LATITUDE ? b : a;
|
3599
|
+
if (Math.abs(lat) > 90)
|
3600
|
+
throw new Error("Latitude " + lat + " not in [-90,90]");
|
3601
|
+
vals.lat = lat;
|
3602
|
+
vals.lon = lon;
|
3603
|
+
return vals;
|
3604
|
+
};
|
3605
|
+
|
3606
|
+
/**
|
3607
|
+
* @summary Decode a DMS string interpreting it as an arc length.
|
3608
|
+
* @param {string} angstr the string (this must not include a hemisphere
|
3609
|
+
* indicator).
|
3610
|
+
* @returns {number} the arc length (degrees).
|
3611
|
+
* @throws an error if the string is illegal.
|
3612
|
+
*/
|
3613
|
+
d.DecodeAngle = function(angstr) {
|
3614
|
+
var vals = d.Decode(angstr),
|
3615
|
+
ang = vals.val, ind = vals.ind;
|
3616
|
+
if (ind !== d.NONE)
|
3617
|
+
throw new Error("Arc angle " + angstr +
|
3618
|
+
" includes a hemisphere N/E/W/S");
|
3619
|
+
return ang;
|
3620
|
+
};
|
3621
|
+
|
3622
|
+
/**
|
3623
|
+
* @summary Decode a DMS string interpreting it as an azimuth.
|
3624
|
+
* @param {string} azistr the string (this may include an E/W hemisphere
|
3625
|
+
* indicator).
|
3626
|
+
* @returns {number} the azimuth (degrees).
|
3627
|
+
* @throws an error if the string is illegal.
|
3628
|
+
*/
|
3629
|
+
d.DecodeAzimuth = function(azistr) {
|
3630
|
+
var vals = d.Decode(azistr),
|
3631
|
+
azi = vals.val, ind = vals.ind;
|
3632
|
+
if (ind === d.LATITUDE)
|
3633
|
+
throw new Error("Azimuth " + azistr + " has a latitude hemisphere N/S");
|
3634
|
+
return azi;
|
3635
|
+
};
|
3636
|
+
|
3637
|
+
/**
|
3638
|
+
* @summary Convert angle (in degrees) into a DMS string (using °, ',
|
3639
|
+
* and ").
|
3640
|
+
* @param {number} angle input angle (degrees).
|
3641
|
+
* @param {number} trailing one of DEGREE, MINUTE, or SECOND to indicate
|
3642
|
+
* the trailing component of the string (this component is given as a
|
3643
|
+
* decimal number if necessary).
|
3644
|
+
* @param {number} prec the number of digits after the decimal point for
|
3645
|
+
* the trailing component.
|
3646
|
+
* @param {number} [ind = NONE] a formatting indicator, one of NONE,
|
3647
|
+
* LATITUDE, LONGITUDE, AZIMUTH.
|
3648
|
+
* @returns {string} the resulting string formatted as follows:
|
3649
|
+
* * NONE, signed result no leading zeros on degrees except in the units
|
3650
|
+
* place, e.g., -8°03'.
|
3651
|
+
* * LATITUDE, trailing N or S hemisphere designator, no sign, pad
|
3652
|
+
* degrees to 2 digits, e.g., 08°03'S.
|
3653
|
+
* * LONGITUDE, trailing E or W hemisphere designator, no sign, pad
|
3654
|
+
* degrees to 3 digits, e.g., 008°03'W.
|
3655
|
+
* * AZIMUTH, convert to the range [0, 360°), no sign, pad degrees to
|
3656
|
+
* 3 digits, e.g., 351°57'.
|
3657
|
+
*/
|
3658
|
+
d.Encode = function(angle, trailing, prec, ind) {
|
3659
|
+
// Assume check on range of input angle has been made by calling
|
3660
|
+
// routine (which might be able to offer a better diagnostic).
|
3661
|
+
var scale = 1, i, sign,
|
3662
|
+
idegree, fdegree, f, pieces, ip, fp, s;
|
3663
|
+
if (!ind) ind = d.NONE;
|
3664
|
+
if (!isFinite(angle))
|
3665
|
+
return angle < 0 ? String("-inf") :
|
3666
|
+
(angle > 0 ? String("inf") : String("nan"));
|
3667
|
+
|
3668
|
+
// 15 - 2 * trailing = ceiling(log10(2^53/90/60^trailing)).
|
3669
|
+
// This suffices to give full real precision for numbers in [-90,90]
|
3670
|
+
prec = Math.min(15 - 2 * trailing, prec);
|
3671
|
+
for (i = 0; i < trailing; ++i)
|
3672
|
+
scale *= 60;
|
3673
|
+
for (i = 0; i < prec; ++i)
|
3674
|
+
scale *= 10;
|
3675
|
+
if (ind === d.AZIMUTH)
|
3676
|
+
angle -= Math.floor(angle/360) * 360;
|
3677
|
+
sign = angle < 0 ? -1 : 1;
|
3678
|
+
angle *= sign;
|
3679
|
+
|
3680
|
+
// Break off integer part to preserve precision in manipulation of
|
3681
|
+
// fractional part.
|
3682
|
+
idegree = Math.floor(angle);
|
3683
|
+
fdegree = (angle - idegree) * scale + 0.5;
|
3684
|
+
f = Math.floor(fdegree);
|
3685
|
+
// Implement the "round ties to even" rule
|
3686
|
+
fdegree = (f === fdegree && (f & 1) === 1) ? f - 1 : f;
|
3687
|
+
fdegree /= scale;
|
3688
|
+
|
3689
|
+
fdegree = Math.floor((angle - idegree) * scale + 0.5) / scale;
|
3690
|
+
if (fdegree >= 1) {
|
3691
|
+
idegree += 1;
|
3692
|
+
fdegree -= 1;
|
3693
|
+
}
|
3694
|
+
pieces = [fdegree, 0, 0];
|
3695
|
+
for (i = 1; i <= trailing; ++i) {
|
3696
|
+
ip = Math.floor(pieces[i - 1]);
|
3697
|
+
fp = pieces[i - 1] - ip;
|
3698
|
+
pieces[i] = fp * 60;
|
3699
|
+
pieces[i - 1] = ip;
|
3700
|
+
}
|
3701
|
+
pieces[0] += idegree;
|
3702
|
+
s = "";
|
3703
|
+
if (ind === d.NONE && sign < 0)
|
3704
|
+
s += '-';
|
3705
|
+
switch (trailing) {
|
3706
|
+
case d.DEGREE:
|
3707
|
+
s += zerofill(pieces[0].toFixed(prec),
|
3708
|
+
ind === d.NONE ? 0 :
|
3709
|
+
1 + Math.min(ind, 2) + prec + (prec ? 1 : 0)) +
|
3710
|
+
dmsindicatorsu_.charAt(0);
|
3711
|
+
break;
|
3712
|
+
default:
|
3713
|
+
s += zerofill(pieces[0].toFixed(0),
|
3714
|
+
ind === d.NONE ? 0 : 1 + Math.min(ind, 2)) +
|
3715
|
+
dmsindicatorsu_.charAt(0);
|
3716
|
+
switch (trailing) {
|
3717
|
+
case d.MINUTE:
|
3718
|
+
s += zerofill(pieces[1].toFixed(prec), 2 + prec + (prec ? 1 : 0)) +
|
3719
|
+
dmsindicatorsu_.charAt(1);
|
3720
|
+
break;
|
3721
|
+
case d.SECOND:
|
3722
|
+
s += zerofill(pieces[1].toFixed(0), 2) + dmsindicatorsu_.charAt(1);
|
3723
|
+
s += zerofill(pieces[2].toFixed(prec), 2 + prec + (prec ? 1 : 0)) +
|
3724
|
+
dmsindicatorsu_.charAt(2);
|
3725
|
+
break;
|
3726
|
+
default:
|
3727
|
+
break;
|
3728
|
+
}
|
3729
|
+
}
|
3730
|
+
if (ind !== d.NONE && ind !== d.AZIMUTH)
|
3731
|
+
s += hemispheres_.charAt((ind === d.LATITUDE ? 0 : 2) +
|
3732
|
+
(sign < 0 ? 0 : 1));
|
3733
|
+
return s;
|
3734
|
+
};
|
3735
|
+
})(GeographicLib.DMS);
|
3736
|
+
|
3737
|
+
cb(GeographicLib);
|
3738
|
+
|
3739
|
+
})(function(geo) {
|
3740
|
+
if (typeof module === 'object' && module.exports) {
|
3741
|
+
/******** support loading with node's require ********/
|
3742
|
+
module.exports = geo;
|
3743
|
+
} else if (true) {
|
3744
|
+
/******** support loading with AMD ********/
|
3745
|
+
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = function() { return geo; }.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
|
3746
|
+
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
3747
|
+
} else {
|
3748
|
+
/******** otherwise just pollute our global namespace ********/
|
3749
|
+
window.GeographicLib = geo;
|
3750
|
+
}
|
3751
|
+
});
|
3752
|
+
|
3753
|
+
|
3754
|
+
/***/ })
|
3755
|
+
/******/ ]);
|
3756
|
+
|
3757
|
+
/***/ }),
|
3758
|
+
/* 4 */
|
3759
|
+
/***/ (function(module, exports) {
|
3760
|
+
|
3761
|
+
// removed by extract-text-webpack-plugin
|
3762
|
+
|
3763
|
+
/***/ })
|
3764
|
+
/******/ ]);
|