@progress/kendo-charts 1.22.0 → 1.23.0-dev.202201170838
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/NOTICE.txt +119 -79
- package/dist/cdn/js/kendo-charts.js +1 -1
- package/dist/cdn/main.js +1 -1
- package/dist/es/common/keys.js +25 -0
- package/dist/es/common.js +1 -0
- package/dist/es/drawing-utils.js +27 -3
- package/dist/es/main.js +1 -0
- package/dist/es/map/attribution.js +158 -0
- package/dist/es/map/crs.js +277 -0
- package/dist/es/map/datums.js +16 -0
- package/dist/es/map/extent.js +129 -0
- package/dist/es/map/layers/bubble.js +185 -0
- package/dist/es/map/layers/layer.js +140 -0
- package/dist/es/map/layers/marker.js +347 -0
- package/dist/es/map/layers/shape.js +389 -0
- package/dist/es/map/layers/tile.js +491 -0
- package/dist/es/map/location.js +201 -0
- package/dist/es/map/map.js +945 -0
- package/dist/es/map/navigator.js +175 -0
- package/dist/es/map/scroller/draggable.js +454 -0
- package/dist/es/map/scroller/fx.js +119 -0
- package/dist/es/map/scroller/observable.js +175 -0
- package/dist/es/map/scroller/scroller.js +746 -0
- package/dist/es/map/scroller/user-events.js +713 -0
- package/dist/es/map/utils.js +450 -0
- package/dist/es/map/zoom.js +139 -0
- package/dist/es/map.js +1 -0
- package/dist/es/services/map-service.js +15 -0
- package/dist/es2015/common/keys.js +25 -0
- package/dist/es2015/common.js +1 -0
- package/dist/es2015/drawing-utils.js +43 -3
- package/dist/es2015/main.js +1 -0
- package/dist/es2015/map/attribution.js +148 -0
- package/dist/es2015/map/crs.js +233 -0
- package/dist/es2015/map/datums.js +16 -0
- package/dist/es2015/map/extent.js +115 -0
- package/dist/es2015/map/layers/bubble.js +167 -0
- package/dist/es2015/map/layers/layer.js +134 -0
- package/dist/es2015/map/layers/marker.js +327 -0
- package/dist/es2015/map/layers/shape.js +369 -0
- package/dist/es2015/map/layers/tile.js +465 -0
- package/dist/es2015/map/location.js +193 -0
- package/dist/es2015/map/map.js +915 -0
- package/dist/es2015/map/navigator.js +170 -0
- package/dist/es2015/map/scroller/draggable.js +418 -0
- package/dist/es2015/map/scroller/fx.js +112 -0
- package/dist/es2015/map/scroller/observable.js +165 -0
- package/dist/es2015/map/scroller/scroller.js +716 -0
- package/dist/es2015/map/scroller/user-events.js +695 -0
- package/dist/es2015/map/utils.js +450 -0
- package/dist/es2015/map/zoom.js +134 -0
- package/dist/es2015/map.js +1 -0
- package/dist/es2015/services/map-service.js +15 -0
- package/dist/npm/main.d.ts +1 -0
- package/dist/npm/main.js +6218 -342
- package/dist/npm/map.d.ts +4 -0
- package/dist/systemjs/kendo-charts.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
import {
|
|
2
|
+
geometry as g,
|
|
3
|
+
throttle
|
|
4
|
+
} from '@progress/kendo-drawing';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
Class,
|
|
8
|
+
addClass,
|
|
9
|
+
deepExtend,
|
|
10
|
+
round,
|
|
11
|
+
limitValue,
|
|
12
|
+
hashKey,
|
|
13
|
+
setDefaultOptions
|
|
14
|
+
} from '../../common';
|
|
15
|
+
|
|
16
|
+
import { removeChildren } from '../utils';
|
|
17
|
+
|
|
18
|
+
import { Layer } from './layer';
|
|
19
|
+
|
|
20
|
+
import TemplateService from '../../services/template-service';
|
|
21
|
+
|
|
22
|
+
let math = Math,
|
|
23
|
+
template = TemplateService.compile,
|
|
24
|
+
Point = g.Point;
|
|
25
|
+
|
|
26
|
+
function roundPoint(point) {
|
|
27
|
+
return new Point(round(point.x), round(point.y));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function renderSize(size) {
|
|
31
|
+
let newSize = size;
|
|
32
|
+
|
|
33
|
+
if (typeof(size) !== "string") {
|
|
34
|
+
newSize += "px";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return newSize;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export class TileLayer extends Layer {
|
|
41
|
+
constructor(map, options) {
|
|
42
|
+
super(map, options);
|
|
43
|
+
|
|
44
|
+
if (typeof this.options.subdomains === 'string') {
|
|
45
|
+
this.options.subdomains = this.options.subdomains.split('');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let viewType = this._viewType();
|
|
49
|
+
this._view = new viewType(this.element, this.options);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
destroy() {
|
|
53
|
+
super.destroy();
|
|
54
|
+
this._view.destroy();
|
|
55
|
+
this._view = null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
_beforeReset() {
|
|
59
|
+
let map = this.map;
|
|
60
|
+
let origin = map.locationToLayer(map.extent().nw).round();
|
|
61
|
+
this._view.viewOrigin(origin);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
_reset() {
|
|
65
|
+
super._reset();
|
|
66
|
+
this._updateView();
|
|
67
|
+
this._view.reset();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
_viewType() {
|
|
71
|
+
return TileView;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
_activate() {
|
|
75
|
+
super._activate();
|
|
76
|
+
|
|
77
|
+
if (!this.support.mobileOS) {
|
|
78
|
+
if (!this._pan) {
|
|
79
|
+
this._pan = throttle(this._render.bind(this), 100);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
this.map.bind('pan', this._pan);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
_deactivate() {
|
|
87
|
+
super._deactivate();
|
|
88
|
+
|
|
89
|
+
if (this._pan) {
|
|
90
|
+
this.map.unbind('pan', this._pan);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
_updateView() {
|
|
95
|
+
let view = this._view,
|
|
96
|
+
map = this.map,
|
|
97
|
+
extent = map.extent(),
|
|
98
|
+
extentToPoint = {
|
|
99
|
+
nw: map.locationToLayer(extent.nw).round(),
|
|
100
|
+
se: map.locationToLayer(extent.se).round()
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
view.center(map.locationToLayer(map.center()));
|
|
104
|
+
view.extent(extentToPoint);
|
|
105
|
+
view.zoom(map.zoom());
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
_resize() {
|
|
109
|
+
this._render();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
_panEnd(e) {
|
|
113
|
+
super._panEnd(e);
|
|
114
|
+
this._render();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
_render() {
|
|
118
|
+
this._updateView();
|
|
119
|
+
this._view.render();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
setDefaultOptions(TileLayer, {
|
|
124
|
+
tileSize: 256,
|
|
125
|
+
subdomains: ['a', 'b', 'c'],
|
|
126
|
+
urlTemplate: '',
|
|
127
|
+
zIndex: 1
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
export class TileView extends Class {
|
|
131
|
+
constructor(element, options) {
|
|
132
|
+
super();
|
|
133
|
+
this.element = element;
|
|
134
|
+
this._initOptions(options);
|
|
135
|
+
this.pool = new TilePool();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
_initOptions(options) {
|
|
139
|
+
this.options = deepExtend({}, this.options, options);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
center(center) {
|
|
143
|
+
this._center = center;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
extent(extent) {
|
|
147
|
+
this._extent = extent;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
viewOrigin(origin) {
|
|
151
|
+
this._viewOrigin = origin;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
zoom(zoom) {
|
|
155
|
+
this._zoom = zoom;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
pointToTileIndex(point) {
|
|
159
|
+
return new Point(math.floor(point.x / this.options.tileSize), math.floor(point.y / this.options.tileSize));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
tileCount() {
|
|
163
|
+
let size = this.size(),
|
|
164
|
+
firstTileIndex = this.pointToTileIndex(this._extent.nw),
|
|
165
|
+
nw = this._extent.nw,
|
|
166
|
+
point = this.indexToPoint(firstTileIndex).translate(-nw.x, -nw.y);
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
x: math.ceil((math.abs(point.x) + size.width) / this.options.tileSize),
|
|
170
|
+
y: math.ceil((math.abs(point.y) + size.height) / this.options.tileSize)
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
size() {
|
|
175
|
+
let nw = this._extent.nw,
|
|
176
|
+
se = this._extent.se,
|
|
177
|
+
diff = se.clone().translate(-nw.x, -nw.y);
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
width: diff.x,
|
|
181
|
+
height: diff.y
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
indexToPoint(index) {
|
|
186
|
+
let x = index.x,
|
|
187
|
+
y = index.y;
|
|
188
|
+
|
|
189
|
+
return new Point(x * this.options.tileSize, y * this.options.tileSize);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
subdomainText() {
|
|
193
|
+
let subdomains = this.options.subdomains;
|
|
194
|
+
return subdomains[this.subdomainIndex++ % subdomains.length];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
destroy() {
|
|
198
|
+
removeChildren(this.element);
|
|
199
|
+
this.pool.empty();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
reset() {
|
|
203
|
+
this.pool.reset();
|
|
204
|
+
this.subdomainIndex = 0;
|
|
205
|
+
this.render();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
render() {
|
|
209
|
+
let size = this.tileCount(),
|
|
210
|
+
firstTileIndex = this.pointToTileIndex(this._extent.nw),
|
|
211
|
+
tile, x, y;
|
|
212
|
+
|
|
213
|
+
for (x = 0; x < size.x; x++) {
|
|
214
|
+
for (y = 0; y < size.y; y++) {
|
|
215
|
+
tile = this.createTile({
|
|
216
|
+
x: firstTileIndex.x + x,
|
|
217
|
+
y: firstTileIndex.y + y
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
if (!tile.visible) {
|
|
221
|
+
tile.show();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
createTile(currentIndex) {
|
|
228
|
+
let options = this.tileOptions(currentIndex);
|
|
229
|
+
let tile = this.pool.get(this._center, options);
|
|
230
|
+
|
|
231
|
+
if (!tile.element.parentNode) {
|
|
232
|
+
this.element.append(tile.element);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return tile;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
tileOptions(currentIndex) {
|
|
239
|
+
let index = this.wrapIndex(currentIndex),
|
|
240
|
+
point = this.indexToPoint(currentIndex),
|
|
241
|
+
origin = this._viewOrigin,
|
|
242
|
+
offset = point.clone().translate(-origin.x, -origin.y);
|
|
243
|
+
|
|
244
|
+
return {
|
|
245
|
+
index: index,
|
|
246
|
+
currentIndex: currentIndex,
|
|
247
|
+
point: point,
|
|
248
|
+
offset: roundPoint(offset),
|
|
249
|
+
zoom: this._zoom,
|
|
250
|
+
size: this.options.tileSize,
|
|
251
|
+
subdomain: this.subdomainText(),
|
|
252
|
+
urlTemplate: this.options.urlTemplate,
|
|
253
|
+
errorUrlTemplate: this.options.errorUrlTemplate
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
wrapIndex(index) {
|
|
258
|
+
let boundary = math.pow(2, this._zoom);
|
|
259
|
+
|
|
260
|
+
return {
|
|
261
|
+
x: this.wrapValue(index.x, boundary),
|
|
262
|
+
y: limitValue(index.y, 0, boundary - 1)
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
wrapValue(value, boundary) {
|
|
267
|
+
let remainder = math.abs(value) % boundary;
|
|
268
|
+
let wrappedValue = value;
|
|
269
|
+
|
|
270
|
+
if (value >= 0) {
|
|
271
|
+
wrappedValue = remainder;
|
|
272
|
+
} else {
|
|
273
|
+
wrappedValue = boundary - (remainder === 0 ? boundary : remainder);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return wrappedValue;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export class ImageTile extends Class {
|
|
281
|
+
constructor(id, options) {
|
|
282
|
+
super();
|
|
283
|
+
this.id = id;
|
|
284
|
+
this.visible = true;
|
|
285
|
+
this._initOptions(options);
|
|
286
|
+
this.createElement();
|
|
287
|
+
this.show();
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
destroy() {
|
|
291
|
+
const element = this.element;
|
|
292
|
+
const parentNode = element ? element.parentNode : null;
|
|
293
|
+
|
|
294
|
+
if (element) {
|
|
295
|
+
if (parentNode) {
|
|
296
|
+
parentNode.removeChild(element);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
this.element = null;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
_initOptions(options) {
|
|
304
|
+
this.options = deepExtend({}, this.options, options);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
createElement() {
|
|
308
|
+
let el = document.createElement("img");
|
|
309
|
+
addClass(el, "k-layer");
|
|
310
|
+
el.style.position = "absolute";
|
|
311
|
+
el.style.display = "block";
|
|
312
|
+
el.style.width = this.options.size;
|
|
313
|
+
el.style.height = this.options.size;
|
|
314
|
+
|
|
315
|
+
this.element = el;
|
|
316
|
+
|
|
317
|
+
// todo
|
|
318
|
+
// add on error handler
|
|
319
|
+
|
|
320
|
+
// this.element =
|
|
321
|
+
// $('<img style=\'position: absolute; display: block;\' alt=\'\' />')
|
|
322
|
+
// .css({
|
|
323
|
+
// width: this.options.size,
|
|
324
|
+
// height: this.options.size
|
|
325
|
+
// })
|
|
326
|
+
// .on('error', proxy(function(e) {
|
|
327
|
+
// if (this.errorUrl()) {
|
|
328
|
+
// e.target.setAttribute('src', this.errorUrl());
|
|
329
|
+
// } else {
|
|
330
|
+
// e.target.removeAttribute('src');
|
|
331
|
+
// }
|
|
332
|
+
// }, this));
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
show() {
|
|
336
|
+
let element = this.element;
|
|
337
|
+
element.style.top = renderSize(this.options.offset.y);
|
|
338
|
+
element.style.left = renderSize(this.options.offset.x);
|
|
339
|
+
|
|
340
|
+
let url = this.url();
|
|
341
|
+
|
|
342
|
+
if (url) {
|
|
343
|
+
element.setAttribute('src', url);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
element.style.visibility = 'visible';
|
|
347
|
+
this.visible = true;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
hide() {
|
|
351
|
+
this.element.style.visibility = 'hidden';
|
|
352
|
+
this.visible = false;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
url() {
|
|
356
|
+
let urlResult = template(this.options.urlTemplate);
|
|
357
|
+
return urlResult(this.urlOptions());
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
errorUrl() {
|
|
361
|
+
let urlResult = template(this.options.errorUrlTemplate);
|
|
362
|
+
return urlResult(this.urlOptions());
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
urlOptions() {
|
|
366
|
+
let options = this.options;
|
|
367
|
+
|
|
368
|
+
return {
|
|
369
|
+
zoom: options.zoom,
|
|
370
|
+
subdomain: options.subdomain,
|
|
371
|
+
z: options.zoom,
|
|
372
|
+
x: options.index.x,
|
|
373
|
+
y: options.index.y,
|
|
374
|
+
s: options.subdomain,
|
|
375
|
+
quadkey: options.quadkey,
|
|
376
|
+
q: options.quadkey,
|
|
377
|
+
culture: options.culture,
|
|
378
|
+
c: options.culture
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
setDefaultOptions(ImageTile, {
|
|
384
|
+
urlTemplate: '',
|
|
385
|
+
errorUrlTemplate: ''
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
export class TilePool extends Class {
|
|
389
|
+
constructor() {
|
|
390
|
+
super();
|
|
391
|
+
this._items = [];
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
get(center, options) {
|
|
395
|
+
if (this._items.length >= this.options.maxSize) {
|
|
396
|
+
this._remove(center);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return this._create(options);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
empty() {
|
|
403
|
+
let items = this._items;
|
|
404
|
+
|
|
405
|
+
for (let i = 0; i < items.length; i++) {
|
|
406
|
+
items[i].destroy();
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
this._items = [];
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
reset() {
|
|
413
|
+
let items = this._items;
|
|
414
|
+
|
|
415
|
+
for (let i = 0; i < items.length; i++) {
|
|
416
|
+
items[i].hide();
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
_create(options) {
|
|
421
|
+
let items = this._items;
|
|
422
|
+
let tile;
|
|
423
|
+
let id = hashKey(options.point.toString() + options.offset.toString() + options.zoom + options.urlTemplate);
|
|
424
|
+
|
|
425
|
+
for (let i = 0; i < items.length; i++) {
|
|
426
|
+
if (items[i].id === id) {
|
|
427
|
+
tile = items[i];
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
if (tile) {
|
|
433
|
+
tile.show();
|
|
434
|
+
} else {
|
|
435
|
+
tile = new ImageTile(id, options);
|
|
436
|
+
this._items.push(tile);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return tile;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
_remove(center) {
|
|
443
|
+
let items = this._items;
|
|
444
|
+
let maxDist = -1;
|
|
445
|
+
let index = -1;
|
|
446
|
+
|
|
447
|
+
for (let i = 0; i < items.length; i++) {
|
|
448
|
+
let dist = items[i].options.point.distanceTo(center);
|
|
449
|
+
|
|
450
|
+
if (dist > maxDist && !items[i].visible) {
|
|
451
|
+
index = i;
|
|
452
|
+
maxDist = dist;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
if (index !== -1) {
|
|
457
|
+
items[index].destroy();
|
|
458
|
+
items.splice(index, 1);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
setDefaultOptions(TilePool, {
|
|
464
|
+
maxSize: 100
|
|
465
|
+
});
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Class,
|
|
3
|
+
deepExtend,
|
|
4
|
+
deg,
|
|
5
|
+
rad,
|
|
6
|
+
round,
|
|
7
|
+
defined
|
|
8
|
+
} from '../common';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
datums
|
|
12
|
+
} from './datums';
|
|
13
|
+
|
|
14
|
+
function toSquare(value) {
|
|
15
|
+
return value * value;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
let math = Math,
|
|
20
|
+
abs = math.abs,
|
|
21
|
+
atan = math.atan,
|
|
22
|
+
atan2 = math.atan2,
|
|
23
|
+
cos = math.cos,
|
|
24
|
+
sin = math.sin,
|
|
25
|
+
tan = math.tan;
|
|
26
|
+
|
|
27
|
+
export class Location extends Class {
|
|
28
|
+
constructor(lat, lng) {
|
|
29
|
+
super();
|
|
30
|
+
|
|
31
|
+
this.initProperties();
|
|
32
|
+
|
|
33
|
+
if (arguments.length === 1) {
|
|
34
|
+
this.lat = lat[0];
|
|
35
|
+
this.lng = lat[1];
|
|
36
|
+
} else {
|
|
37
|
+
this.lat = lat;
|
|
38
|
+
this.lng = lng;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
initProperties() {
|
|
43
|
+
deepExtend(this, {
|
|
44
|
+
DISTANCE_ITERATIONS: 100,
|
|
45
|
+
DISTANCE_CONVERGENCE: 1e-12,
|
|
46
|
+
DISTANCE_PRECISION: 2,
|
|
47
|
+
FORMAT: '{0:N6}{1:N6}'
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
toArray() {
|
|
52
|
+
return [
|
|
53
|
+
this.lat,
|
|
54
|
+
this.lng
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
equals(loc) {
|
|
59
|
+
return loc && loc.lat === this.lat && loc.lng === this.lng;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
clone() {
|
|
63
|
+
return new Location(this.lat, this.lng);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
round(precision) {
|
|
67
|
+
this.lng = round(this.lng, precision);
|
|
68
|
+
this.lat = round(this.lat, precision);
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
wrap() {
|
|
73
|
+
this.lng = this.lng % 180;
|
|
74
|
+
this.lat = this.lat % 90;
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
distanceTo(dest, datum) {
|
|
79
|
+
return this.greatCircleTo(dest, datum).distance;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
destination(distance, initialBearing, initialDatum) {
|
|
83
|
+
let bearing = rad(initialBearing);
|
|
84
|
+
let datum = initialDatum || datums.WGS84;
|
|
85
|
+
let fromLat = rad(this.lat);
|
|
86
|
+
let fromLng = rad(this.lng);
|
|
87
|
+
let dToR = distance / datum.a;
|
|
88
|
+
let lat = math.asin(sin(fromLat) * cos(dToR) + cos(fromLat) * sin(dToR) * cos(bearing));
|
|
89
|
+
let lng = fromLng + atan2(sin(bearing) * sin(dToR) * cos(fromLat), cos(dToR) - sin(fromLat) * sin(lat));
|
|
90
|
+
|
|
91
|
+
return new Location(deg(lat), deg(lng));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
greatCircleTo(initialDest, initialDatum) {
|
|
95
|
+
let dest = Location.create(dest);
|
|
96
|
+
let datum = initialDatum || datums.WGS84;
|
|
97
|
+
|
|
98
|
+
if (!dest || this.clone().round(8).equals(dest.clone().round(8))) {
|
|
99
|
+
return {
|
|
100
|
+
distance: 0,
|
|
101
|
+
azimuthFrom: 0,
|
|
102
|
+
azimuthTo: 0
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// See http://en.wikipedia.org/wiki/Vincenty's_formulae#Notation
|
|
107
|
+
// o == sigma
|
|
108
|
+
// A == alpha
|
|
109
|
+
|
|
110
|
+
let a = datum.a;
|
|
111
|
+
let b = datum.b;
|
|
112
|
+
let f = datum.f;
|
|
113
|
+
let L = rad(dest.lng - this.lng);
|
|
114
|
+
let U1 = atan((1 - f) * tan(rad(this.lat)));
|
|
115
|
+
let sinU1 = sin(U1);
|
|
116
|
+
let cosU1 = cos(U1);
|
|
117
|
+
let U2 = atan((1 - f) * tan(rad(dest.lat)));
|
|
118
|
+
let sinU2 = sin(U2);
|
|
119
|
+
let cosU2 = cos(U2);
|
|
120
|
+
let lambda = L;
|
|
121
|
+
let prevLambda;
|
|
122
|
+
let i = this.DISTANCE_ITERATIONS;
|
|
123
|
+
let converged = false;
|
|
124
|
+
let sinLambda;
|
|
125
|
+
let cosLambda;
|
|
126
|
+
let sino;
|
|
127
|
+
let cosA2;
|
|
128
|
+
let coso;
|
|
129
|
+
let cos2om;
|
|
130
|
+
let sigma;
|
|
131
|
+
|
|
132
|
+
while (!converged && i-- > 0) {
|
|
133
|
+
sinLambda = sin(lambda);
|
|
134
|
+
cosLambda = cos(lambda);
|
|
135
|
+
sino = math.sqrt(toSquare(cosU2 * sinLambda) + toSquare(cosU1 * sinU2 - sinU1 * cosU2 * cosLambda));
|
|
136
|
+
coso = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda;
|
|
137
|
+
sigma = atan2(sino, coso);
|
|
138
|
+
|
|
139
|
+
let sinA = cosU1 * cosU2 * sinLambda / sino;
|
|
140
|
+
cosA2 = 1 - toSquare(sinA);
|
|
141
|
+
cos2om = 0;
|
|
142
|
+
|
|
143
|
+
if (cosA2 !== 0) {
|
|
144
|
+
cos2om = coso - 2 * sinU1 * sinU2 / cosA2;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
prevLambda = lambda;
|
|
148
|
+
let C = f / 16 * cosA2 * (4 + f * (4 - 3 * cosA2));
|
|
149
|
+
lambda = L + (1 - C) * f * sinA * (sigma + C * sino * (cos2om + C * coso * (-1 + 2 * toSquare(cos2om))));
|
|
150
|
+
converged = abs(lambda - prevLambda) <= this.DISTANCE_CONVERGENCE;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
let u2 = cosA2 * (toSquare(a) - toSquare(b)) / toSquare(b);
|
|
154
|
+
let A = 1 + u2 / 16384 * (4096 + u2 * (-768 + u2 * (320 - 175 * u2)));
|
|
155
|
+
let B = u2 / 1024 * (256 + u2 * (-128 + u2 * (74 - 47 * u2)));
|
|
156
|
+
let deltao = B * sino * (cos2om + B / 4 * (coso * (-1 + 2 * toSquare(cos2om)) - B / 6 * cos2om * (-3 + 4 * toSquare(sino)) * (-3 + 4 * toSquare(cos2om))));
|
|
157
|
+
|
|
158
|
+
let azimuthFrom = atan2(cosU2 * sinLambda, cosU1 * sinU2 - sinU1 * cosU2 * cosLambda);
|
|
159
|
+
let azimuthTo = atan2(cosU1 * sinLambda, -sinU1 * cosU2 + cosU1 * sinU2 * cosLambda);
|
|
160
|
+
|
|
161
|
+
return {
|
|
162
|
+
distance: round(b * A * (sigma - deltao), this.DISTANCE_PRECISION),
|
|
163
|
+
azimuthFrom: deg(azimuthFrom),
|
|
164
|
+
azimuthTo: deg(azimuthTo)
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// IE < 9 doesn't allow to override toString on definition
|
|
169
|
+
toString() {
|
|
170
|
+
// return kendo.format(this.FORMAT, this.lat, this.lng);
|
|
171
|
+
return String(this.lat) + "," + String(this.lng);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
static fromLngLat(lngAndLat) {
|
|
175
|
+
return new Location(lngAndLat[1], lngAndLat[0]);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
static fromLatLng(lngAndLat) {
|
|
179
|
+
return new Location(lngAndLat[0], lngAndLat[1]);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
static create(a, b) {
|
|
183
|
+
if (defined(a)) {
|
|
184
|
+
if (a instanceof Location) {
|
|
185
|
+
return a.clone();
|
|
186
|
+
} else if (arguments.length === 1 && a.length === 2) {
|
|
187
|
+
return Location.fromLatLng(a);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return new Location(a, b);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|