@progress/kendo-charts 1.21.0 → 1.23.0-dev.202201120958
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/dist/cdn/js/kendo-charts.js +1 -1
- package/dist/cdn/main.js +1 -1
- package/dist/es/barcode/barcode-validator.js +50 -0
- package/dist/es/barcode.js +1 -0
- 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 +157 -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 +348 -0
- package/dist/es/map/layers/shape.js +390 -0
- package/dist/es/map/layers/tile.js +481 -0
- package/dist/es/map/location.js +201 -0
- package/dist/es/map/map.js +929 -0
- package/dist/es/map/navigator.js +174 -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 +151 -0
- package/dist/es/map/scroller/scroller.js +746 -0
- package/dist/es/map/scroller/user-events.js +712 -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/qrcode/qrcode-validator.js +24 -0
- package/dist/es/qrcode.js +1 -0
- package/dist/es/services/map-service.js +15 -0
- package/dist/es2015/barcode/barcode-validator.js +48 -0
- package/dist/es2015/barcode.js +1 -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 +147 -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 +328 -0
- package/dist/es2015/map/layers/shape.js +370 -0
- package/dist/es2015/map/layers/tile.js +455 -0
- package/dist/es2015/map/location.js +193 -0
- package/dist/es2015/map/map.js +905 -0
- package/dist/es2015/map/navigator.js +169 -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 +143 -0
- package/dist/es2015/map/scroller/scroller.js +716 -0
- package/dist/es2015/map/scroller/user-events.js +694 -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/qrcode/qrcode-validator.js +22 -0
- package/dist/es2015/qrcode.js +1 -0
- package/dist/es2015/services/map-service.js +15 -0
- package/dist/npm/barcode.d.ts +4 -1
- package/dist/npm/main.d.ts +2 -0
- package/dist/npm/main.js +6227 -329
- package/dist/npm/map.d.ts +4 -0
- package/dist/npm/qrcode.d.ts +3 -0
- package/dist/npm/validation.d.ts +9 -0
- package/dist/systemjs/kendo-charts.js +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,905 @@
|
|
|
1
|
+
import {
|
|
2
|
+
geometry as g
|
|
3
|
+
} from '@progress/kendo-drawing';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
addClass,
|
|
7
|
+
setDefaultOptions,
|
|
8
|
+
valueOrDefault,
|
|
9
|
+
defined,
|
|
10
|
+
mousewheelDelta,
|
|
11
|
+
limitValue,
|
|
12
|
+
deepExtend,
|
|
13
|
+
elementOffset,
|
|
14
|
+
isArray
|
|
15
|
+
} from '../common';
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
EPSG3857
|
|
19
|
+
} from './crs';
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
Attribution
|
|
23
|
+
} from './attribution';
|
|
24
|
+
|
|
25
|
+
import {
|
|
26
|
+
Navigator
|
|
27
|
+
} from './navigator';
|
|
28
|
+
|
|
29
|
+
import {
|
|
30
|
+
ZoomControl
|
|
31
|
+
} from './zoom';
|
|
32
|
+
|
|
33
|
+
import {
|
|
34
|
+
Location
|
|
35
|
+
} from './location';
|
|
36
|
+
|
|
37
|
+
import {
|
|
38
|
+
Extent
|
|
39
|
+
} from './extent';
|
|
40
|
+
|
|
41
|
+
import {
|
|
42
|
+
TileLayer
|
|
43
|
+
} from './layers/tile';
|
|
44
|
+
|
|
45
|
+
import {
|
|
46
|
+
BubbleLayer
|
|
47
|
+
} from './layers/bubble';
|
|
48
|
+
|
|
49
|
+
import {
|
|
50
|
+
ShapeLayer
|
|
51
|
+
} from './layers/shape';
|
|
52
|
+
|
|
53
|
+
import {
|
|
54
|
+
MarkerLayer
|
|
55
|
+
} from './layers/marker';
|
|
56
|
+
|
|
57
|
+
import {
|
|
58
|
+
removeChildren,
|
|
59
|
+
setDefaultEvents,
|
|
60
|
+
toHyphens,
|
|
61
|
+
proxy,
|
|
62
|
+
now,
|
|
63
|
+
on,
|
|
64
|
+
off,
|
|
65
|
+
getSupportedFeatures,
|
|
66
|
+
convertToHtml
|
|
67
|
+
} from './utils';
|
|
68
|
+
|
|
69
|
+
import {
|
|
70
|
+
Scroller
|
|
71
|
+
} from './scroller/scroller';
|
|
72
|
+
|
|
73
|
+
import {
|
|
74
|
+
Observable
|
|
75
|
+
} from './scroller/observable';
|
|
76
|
+
|
|
77
|
+
import MapService from './../services/map-service';
|
|
78
|
+
|
|
79
|
+
let math = Math,
|
|
80
|
+
min = math.min,
|
|
81
|
+
pow = math.pow,
|
|
82
|
+
Point = g.Point,
|
|
83
|
+
MARKER = "marker",
|
|
84
|
+
LOCATION = "location",
|
|
85
|
+
FRICTION = 0.9,
|
|
86
|
+
FRICTION_MOBILE = 0.93,
|
|
87
|
+
MOUSEWHEEL = 'DOMMouseScroll mousewheel',
|
|
88
|
+
VELOCITY_MULTIPLIER = 5,
|
|
89
|
+
DEFAULT_ZOOM_RATE = 1;
|
|
90
|
+
|
|
91
|
+
const layersMap = {
|
|
92
|
+
bubble: BubbleLayer,
|
|
93
|
+
shape: ShapeLayer,
|
|
94
|
+
tile: TileLayer,
|
|
95
|
+
[MARKER]: MarkerLayer
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
function renderPos(pos) {
|
|
99
|
+
let result = [];
|
|
100
|
+
|
|
101
|
+
if (pos) {
|
|
102
|
+
let parts = toHyphens(pos).split("-");
|
|
103
|
+
|
|
104
|
+
for (let i = 0; i < parts.length; i++) {
|
|
105
|
+
result.push("k-pos-" + parts[i]);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return result.join(" ");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
class Map extends Observable {
|
|
113
|
+
constructor(element, options = {}, themeOptions = {}, context = {}) {
|
|
114
|
+
super();
|
|
115
|
+
|
|
116
|
+
this.support = getSupportedFeatures();
|
|
117
|
+
|
|
118
|
+
this.initObserver(context);
|
|
119
|
+
this.initServices(context);
|
|
120
|
+
|
|
121
|
+
this._initOptions(options);
|
|
122
|
+
this.bind(this.events, options);
|
|
123
|
+
this.crs = new EPSG3857();
|
|
124
|
+
|
|
125
|
+
this._initElement(element);
|
|
126
|
+
|
|
127
|
+
this._viewOrigin = this._getOrigin();
|
|
128
|
+
|
|
129
|
+
this._initScroller();
|
|
130
|
+
this._initMarkers();
|
|
131
|
+
this._initControls();
|
|
132
|
+
this._initLayers();
|
|
133
|
+
this._reset();
|
|
134
|
+
|
|
135
|
+
this._mousewheelHandler = this._mousewheel.bind(this);
|
|
136
|
+
on(this.element, MOUSEWHEEL, this._mousewheelHandler);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
destroy() {
|
|
140
|
+
this.scroller.destroy();
|
|
141
|
+
|
|
142
|
+
if (this.navigator) {
|
|
143
|
+
this.navigator.destroy();
|
|
144
|
+
}
|
|
145
|
+
if (this.attribution) {
|
|
146
|
+
this.attribution.destroy();
|
|
147
|
+
}
|
|
148
|
+
if (this.zoomControl) {
|
|
149
|
+
this.zoomControl.destroy();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (isArray(this.markers)) {
|
|
153
|
+
this.markers.forEach(markerLayer => {
|
|
154
|
+
markerLayer.destroy();
|
|
155
|
+
});
|
|
156
|
+
} else {
|
|
157
|
+
this.markers.destroy();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
for (let i = 0; i < this.layers.length; i++) {
|
|
161
|
+
this.layers[i].destroy();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
off(this.element, MOUSEWHEEL, this._mousewheelHandler);
|
|
165
|
+
|
|
166
|
+
super.destroy();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
_initOptions(options) {
|
|
170
|
+
this.options = deepExtend({}, this.options, options);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
_initElement(element) {
|
|
174
|
+
this.element = element;
|
|
175
|
+
|
|
176
|
+
addClass(element, "k-map");
|
|
177
|
+
element.style.position = "relative";
|
|
178
|
+
element.setAttribute("data-role", "map");
|
|
179
|
+
removeChildren(element);
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
const div = convertToHtml("<div />");
|
|
183
|
+
this.element.appendChild(div);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
initServices(context = {}) {
|
|
187
|
+
this.widgetService = new MapService(this, context);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
initObserver(context = {}) {
|
|
191
|
+
this.observers = [];
|
|
192
|
+
this.addObserver(context.observer);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
addObserver(observer) {
|
|
196
|
+
if (observer) {
|
|
197
|
+
this.observers.push(observer);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
removeObserver(observer) {
|
|
202
|
+
const index = this.observers.indexOf(observer);
|
|
203
|
+
|
|
204
|
+
if (index >= 0) {
|
|
205
|
+
this.observers.splice(index, 1);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
requiresHandlers(eventNames) {
|
|
210
|
+
const observers = this.observers;
|
|
211
|
+
|
|
212
|
+
for (let idx = 0; idx < observers.length; idx++) {
|
|
213
|
+
if (observers[idx].requiresHandlers(eventNames)) {
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
trigger(name, args = {}) {
|
|
220
|
+
args.sender = this;
|
|
221
|
+
|
|
222
|
+
const observers = this.observers;
|
|
223
|
+
let isDefaultPrevented = false;
|
|
224
|
+
|
|
225
|
+
for (let idx = 0; idx < observers.length; idx++) {
|
|
226
|
+
if (observers[idx].trigger(name, args)) {
|
|
227
|
+
isDefaultPrevented = true;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (!isDefaultPrevented) {
|
|
232
|
+
super.trigger(name, args);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return isDefaultPrevented;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
_notifyObserver(name, args = {}) {
|
|
239
|
+
args.sender = this;
|
|
240
|
+
|
|
241
|
+
const observers = this.observers;
|
|
242
|
+
let isDefaultPrevented = false;
|
|
243
|
+
|
|
244
|
+
for (let idx = 0; idx < observers.length; idx++) {
|
|
245
|
+
if (observers[idx].trigger(name, args)) {
|
|
246
|
+
isDefaultPrevented = true;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return isDefaultPrevented;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
zoom(level) {
|
|
254
|
+
let options = this.options;
|
|
255
|
+
let result;
|
|
256
|
+
|
|
257
|
+
if (defined(level)) {
|
|
258
|
+
const zoomLevel = math.round(limitValue(level, options.minZoom, options.maxZoom));
|
|
259
|
+
|
|
260
|
+
if (options.zoom !== zoomLevel) {
|
|
261
|
+
options.zoom = zoomLevel;
|
|
262
|
+
this._reset();
|
|
263
|
+
}
|
|
264
|
+
result = this;
|
|
265
|
+
} else {
|
|
266
|
+
result = options.zoom;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return result;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
center(center) {
|
|
273
|
+
let result;
|
|
274
|
+
|
|
275
|
+
if (center) {
|
|
276
|
+
this.options.center = Location.create(center).toArray();
|
|
277
|
+
this._reset();
|
|
278
|
+
result = this;
|
|
279
|
+
} else {
|
|
280
|
+
result = Location.create(this.options.center);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return result;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
extent(extent) {
|
|
287
|
+
let result;
|
|
288
|
+
|
|
289
|
+
if (extent) {
|
|
290
|
+
this._setExtent(extent);
|
|
291
|
+
result = this;
|
|
292
|
+
} else {
|
|
293
|
+
result = this._getExtent();
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return result;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
setOptions(options) {
|
|
300
|
+
super.setOptions(options);
|
|
301
|
+
this._reset();
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
locationToLayer(location, zoom) {
|
|
305
|
+
let clamp = !this.options.wraparound;
|
|
306
|
+
const locationObject = Location.create(location);
|
|
307
|
+
|
|
308
|
+
return this.crs.toPoint(locationObject, this._layerSize(zoom), clamp);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
layerToLocation(point, zoom) {
|
|
312
|
+
let clamp = !this.options.wraparound;
|
|
313
|
+
const pointObject = Point.create(point);
|
|
314
|
+
|
|
315
|
+
return this.crs.toLocation(pointObject, this._layerSize(zoom), clamp);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
locationToView(location) {
|
|
319
|
+
const locationObject = Location.create(location);
|
|
320
|
+
let origin = this.locationToLayer(this._viewOrigin);
|
|
321
|
+
let point = this.locationToLayer(locationObject);
|
|
322
|
+
|
|
323
|
+
return point.translateWith(origin.scale(-1));
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
viewToLocation(point, zoom) {
|
|
327
|
+
const origin = this.locationToLayer(this._getOrigin(), zoom);
|
|
328
|
+
const pointObject = Point.create(point);
|
|
329
|
+
const pointResult = pointObject.clone().translateWith(origin);
|
|
330
|
+
|
|
331
|
+
return this.layerToLocation(pointResult, zoom);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
eventOffset(e) {
|
|
335
|
+
let x;
|
|
336
|
+
let y;
|
|
337
|
+
let offset = elementOffset(this.element);
|
|
338
|
+
|
|
339
|
+
if ((e.x && e.x[LOCATION]) || (e.y && e.y[LOCATION])) {
|
|
340
|
+
x = e.x[LOCATION] - offset.left;
|
|
341
|
+
y = e.y[LOCATION] - offset.top;
|
|
342
|
+
} else {
|
|
343
|
+
let event = e.originalEvent || e;
|
|
344
|
+
x = valueOrDefault(event.pageX, event.clientX) - offset.left;
|
|
345
|
+
y = valueOrDefault(event.pageY, event.clientY) - offset.top;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const point = new g.Point(x, y);
|
|
349
|
+
|
|
350
|
+
return point;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
eventToView(e) {
|
|
354
|
+
let cursor = this.eventOffset(e);
|
|
355
|
+
return this.locationToView(this.viewToLocation(cursor));
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
eventToLayer(e) {
|
|
359
|
+
return this.locationToLayer(this.eventToLocation(e));
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
eventToLocation(e) {
|
|
363
|
+
let cursor = this.eventOffset(e);
|
|
364
|
+
return this.viewToLocation(cursor);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
viewSize() {
|
|
368
|
+
let element = this.element;
|
|
369
|
+
let scale = this._layerSize();
|
|
370
|
+
let width = element.clientWidth;
|
|
371
|
+
|
|
372
|
+
if (!this.options.wraparound) {
|
|
373
|
+
width = min(scale, width);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
return {
|
|
377
|
+
width: width,
|
|
378
|
+
height: min(scale, element.clientHeight)
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
exportVisual() {
|
|
383
|
+
this._reset();
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
_setOrigin(origin, zoom) {
|
|
388
|
+
let size = this.viewSize(),
|
|
389
|
+
topLeft;
|
|
390
|
+
|
|
391
|
+
const originLocation = this._origin = Location.create(origin);
|
|
392
|
+
topLeft = this.locationToLayer(originLocation, zoom);
|
|
393
|
+
topLeft.x += size.width / 2;
|
|
394
|
+
topLeft.y += size.height / 2;
|
|
395
|
+
this.options.center = this.layerToLocation(topLeft, zoom).toArray();
|
|
396
|
+
|
|
397
|
+
return this;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
_getOrigin(invalidate) {
|
|
401
|
+
let size = this.viewSize(),
|
|
402
|
+
topLeft;
|
|
403
|
+
|
|
404
|
+
if (invalidate || !this._origin) {
|
|
405
|
+
topLeft = this.locationToLayer(this.center());
|
|
406
|
+
topLeft.x -= size.width / 2;
|
|
407
|
+
topLeft.y -= size.height / 2;
|
|
408
|
+
this._origin = this.layerToLocation(topLeft);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
return this._origin;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
_setExtent(newExtent) {
|
|
415
|
+
let raw = Extent.create(newExtent);
|
|
416
|
+
let se = raw.se.clone();
|
|
417
|
+
|
|
418
|
+
if (this.options.wraparound && se.lng < 0 && newExtent.nw.lng > 0) {
|
|
419
|
+
se.lng = 180 + (180 + se.lng);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const extent = new Extent(raw.nw, se);
|
|
423
|
+
this.center(extent.center());
|
|
424
|
+
let width = this.element.clientWidth;
|
|
425
|
+
let height = this.element.clientHeight;
|
|
426
|
+
let zoom;
|
|
427
|
+
|
|
428
|
+
for (zoom = this.options.maxZoom; zoom >= this.options.minZoom; zoom--) {
|
|
429
|
+
let topLeft = this.locationToLayer(extent.nw, zoom);
|
|
430
|
+
let bottomRight = this.locationToLayer(extent.se, zoom);
|
|
431
|
+
let layerWidth = math.abs(bottomRight.x - topLeft.x);
|
|
432
|
+
let layerHeight = math.abs(bottomRight.y - topLeft.y);
|
|
433
|
+
|
|
434
|
+
if (layerWidth <= width && layerHeight <= height) {
|
|
435
|
+
break;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
this.zoom(zoom);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
_getExtent() {
|
|
443
|
+
let nw = this._getOrigin();
|
|
444
|
+
let bottomRight = this.locationToLayer(nw);
|
|
445
|
+
let size = this.viewSize();
|
|
446
|
+
|
|
447
|
+
bottomRight.x += size.width;
|
|
448
|
+
bottomRight.y += size.height;
|
|
449
|
+
|
|
450
|
+
let se = this.layerToLocation(bottomRight);
|
|
451
|
+
|
|
452
|
+
return new Extent(nw, se);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
_zoomAround(pivot, level) {
|
|
456
|
+
this._setOrigin(this.layerToLocation(pivot, level), level);
|
|
457
|
+
this.zoom(level);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
_initControls() {
|
|
461
|
+
let controls = this.options.controls;
|
|
462
|
+
if (controls.attribution) {
|
|
463
|
+
this._createAttribution(controls.attribution);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
if (!this.support.mobileOS) {
|
|
467
|
+
if (controls.navigator) {
|
|
468
|
+
this._createNavigator(controls.navigator);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
if (controls.zoom) {
|
|
472
|
+
this._createZoomControl(controls.zoom);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
_createControlElement(options, defaultPosition) {
|
|
478
|
+
let pos = options.position || defaultPosition;
|
|
479
|
+
let posSelector = '.' + renderPos(pos).replace(' ', '.');
|
|
480
|
+
let wrap = this.element.querySelector('.k-map-controls' + posSelector) || [];
|
|
481
|
+
|
|
482
|
+
if (wrap.length === 0) {
|
|
483
|
+
let div = document.createElement("div");
|
|
484
|
+
addClass(div, 'k-map-controls ' + renderPos(pos));
|
|
485
|
+
wrap = div;
|
|
486
|
+
this.element.appendChild(wrap);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
let div = document.createElement("div");
|
|
490
|
+
|
|
491
|
+
wrap.appendChild(div);
|
|
492
|
+
|
|
493
|
+
return div;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
_createAttribution(options) {
|
|
497
|
+
let element = this._createControlElement(options, 'bottomRight');
|
|
498
|
+
this.attribution = new Attribution(element, options);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
_createNavigator(options) {
|
|
502
|
+
let element = this._createControlElement(options, 'topLeft');
|
|
503
|
+
let navigator = this.navigator = new Navigator(element, options);
|
|
504
|
+
|
|
505
|
+
this._navigatorPan = this._navigatorPan.bind(this);
|
|
506
|
+
navigator.bind('pan', this._navigatorPan);
|
|
507
|
+
|
|
508
|
+
this._navigatorCenter = this._navigatorCenter.bind(this);
|
|
509
|
+
navigator.bind('center', this._navigatorCenter);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
_navigatorPan(e) {
|
|
513
|
+
let scroller = this.scroller;
|
|
514
|
+
let x = scroller.scrollLeft + e.x;
|
|
515
|
+
let y = scroller.scrollTop - e.y;
|
|
516
|
+
let bounds = this._virtualSize;
|
|
517
|
+
let width = this.element.clientWidth;
|
|
518
|
+
let height = this.element.clientHeight;
|
|
519
|
+
|
|
520
|
+
// TODO: Move limits to scroller
|
|
521
|
+
x = limitValue(x, bounds.x.min, bounds.x.max - width);
|
|
522
|
+
y = limitValue(y, bounds.y.min, bounds.y.max - height);
|
|
523
|
+
|
|
524
|
+
this.scroller.one('scroll', proxy(this._scrollEnd, this));
|
|
525
|
+
|
|
526
|
+
this.scroller.scrollTo(-x, -y);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
_navigatorCenter() {
|
|
530
|
+
this.center(this.options.center);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
_createZoomControl(options) {
|
|
534
|
+
let element = this._createControlElement(options, 'topLeft');
|
|
535
|
+
let zoomControl = this.zoomControl = new ZoomControl(element, options);
|
|
536
|
+
|
|
537
|
+
this._zoomControlChange = this._zoomControlChange.bind(this);
|
|
538
|
+
zoomControl.bind('change', this._zoomControlChange);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
_zoomControlChange(e) {
|
|
542
|
+
if (!this.trigger('zoomStart', { originalEvent: e })) {
|
|
543
|
+
this.zoom(this.zoom() + e.delta);
|
|
544
|
+
|
|
545
|
+
this.trigger('zoomEnd', {
|
|
546
|
+
originalEvent: e
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
_initScroller() {
|
|
552
|
+
let friction = this.support.mobileOS ? FRICTION_MOBILE : FRICTION;
|
|
553
|
+
let zoomable = this.options.zoomable !== false;
|
|
554
|
+
let scroller = this.scroller = new Scroller(this.element.children[0], {
|
|
555
|
+
friction: friction,
|
|
556
|
+
velocityMultiplier: VELOCITY_MULTIPLIER,
|
|
557
|
+
zoom: zoomable,
|
|
558
|
+
mousewheelScrolling: false,
|
|
559
|
+
supportDoubleTap: true
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
scroller.bind('scroll', proxy(this._scroll, this));
|
|
563
|
+
scroller.bind('scrollEnd', proxy(this._scrollEnd, this));
|
|
564
|
+
|
|
565
|
+
scroller.userEvents.bind('gesturestart', proxy(this._scaleStart, this));
|
|
566
|
+
scroller.userEvents.bind('gestureend', proxy(this._scale, this));
|
|
567
|
+
scroller.userEvents.bind('doubleTap', proxy(this._doubleTap, this));
|
|
568
|
+
scroller.userEvents.bind('tap', proxy(this._tap, this));
|
|
569
|
+
|
|
570
|
+
this.scrollElement = scroller.scrollElement;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
_initLayers() {
|
|
574
|
+
let defs = this.options.layers,
|
|
575
|
+
layers = this.layers = [];
|
|
576
|
+
|
|
577
|
+
for (let i = 0; i < defs.length; i++) {
|
|
578
|
+
let options = defs[i];
|
|
579
|
+
|
|
580
|
+
const layer = this._createLayer(options);
|
|
581
|
+
layers.push(layer);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
_createLayer(options) {
|
|
586
|
+
let type = options.type || 'shape';
|
|
587
|
+
let layerDefaults = this.options.layerDefaults[type];
|
|
588
|
+
let layerOptions = type === MARKER ?
|
|
589
|
+
deepExtend({}, this.options.markerDefaults, options) :
|
|
590
|
+
deepExtend({}, layerDefaults, options);
|
|
591
|
+
|
|
592
|
+
let layerConstructor = layersMap[type];
|
|
593
|
+
let layer = new layerConstructor(this, layerOptions);
|
|
594
|
+
|
|
595
|
+
if (type === MARKER) {
|
|
596
|
+
this.markers = layer;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
return layer;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/* eslint-disable arrow-body-style */
|
|
603
|
+
_initMarkers() {
|
|
604
|
+
const markerLayers = (this.options.layers || []).filter(x => {
|
|
605
|
+
return x && x.type === MARKER;
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
if (markerLayers.length > 0) {
|
|
609
|
+
// render the markers from options.layers
|
|
610
|
+
// instead of options.markers
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
this.markers = new MarkerLayer(this, this.options.markerDefaults);
|
|
615
|
+
this.markers.add(this.options.markers);
|
|
616
|
+
}
|
|
617
|
+
/* eslint-enable arrow-body-style */
|
|
618
|
+
|
|
619
|
+
_scroll(e) {
|
|
620
|
+
let origin = this.locationToLayer(this._viewOrigin).round();
|
|
621
|
+
let movable = e.sender.movable;
|
|
622
|
+
let offset = new g.Point(movable.x, movable.y).scale(-1).scale(1 / movable.scale);
|
|
623
|
+
|
|
624
|
+
origin.x += offset.x;
|
|
625
|
+
origin.y += offset.y;
|
|
626
|
+
this._scrollOffset = offset;
|
|
627
|
+
|
|
628
|
+
this._setOrigin(this.layerToLocation(origin));
|
|
629
|
+
|
|
630
|
+
this.trigger('pan', {
|
|
631
|
+
originalEvent: e,
|
|
632
|
+
origin: this._getOrigin(),
|
|
633
|
+
center: this.center()
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
_scrollEnd(e) {
|
|
638
|
+
if (!this._scrollOffset || !this._panComplete()) {
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
this._scrollOffset = null;
|
|
643
|
+
this._panEndTimestamp = now();
|
|
644
|
+
|
|
645
|
+
this.trigger('panEnd', {
|
|
646
|
+
originalEvent: e,
|
|
647
|
+
origin: this._getOrigin(),
|
|
648
|
+
center: this.center()
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
_panComplete() {
|
|
653
|
+
return now() - (this._panEndTimestamp || 0) > 50;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
_scaleStart(e) {
|
|
657
|
+
if (this.trigger('zoomStart', { originalEvent: e })) {
|
|
658
|
+
let touch = e.touches[1];
|
|
659
|
+
|
|
660
|
+
if (touch) {
|
|
661
|
+
touch.cancel();
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
_scale(e) {
|
|
667
|
+
let scale = this.scroller.movable.scale;
|
|
668
|
+
let zoom = this._scaleToZoom(scale);
|
|
669
|
+
let gestureCenter = new g.Point(e.center.x, e.center.y);
|
|
670
|
+
let centerLocation = this.viewToLocation(gestureCenter, zoom);
|
|
671
|
+
let centerPoint = this.locationToLayer(centerLocation, zoom);
|
|
672
|
+
let originPoint = centerPoint.translate(-gestureCenter.x, -gestureCenter.y);
|
|
673
|
+
|
|
674
|
+
this._zoomAround(originPoint, zoom);
|
|
675
|
+
|
|
676
|
+
this.trigger('zoomEnd', {
|
|
677
|
+
originalEvent: e
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
_scaleToZoom(scaleDelta) {
|
|
682
|
+
let scale = this._layerSize() * scaleDelta;
|
|
683
|
+
let tiles = scale / this.options.minSize;
|
|
684
|
+
let zoom = math.log(tiles) / math.log(2);
|
|
685
|
+
|
|
686
|
+
return math.round(zoom);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
_reset() {
|
|
690
|
+
if (this.attribution) {
|
|
691
|
+
this.attribution.filter(this.center(), this.zoom());
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
this._viewOrigin = this._getOrigin(true);
|
|
695
|
+
|
|
696
|
+
this._resetScroller();
|
|
697
|
+
|
|
698
|
+
this.trigger('beforeReset');
|
|
699
|
+
this.trigger('reset');
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
_resetScroller() {
|
|
703
|
+
let scroller = this.scroller;
|
|
704
|
+
let x = scroller.dimensions.x;
|
|
705
|
+
let y = scroller.dimensions.y;
|
|
706
|
+
let scale = this._layerSize();
|
|
707
|
+
let nw = this.extent().nw;
|
|
708
|
+
let topLeft = this.locationToLayer(nw).round();
|
|
709
|
+
|
|
710
|
+
scroller.movable.round = true;
|
|
711
|
+
scroller.reset();
|
|
712
|
+
scroller.userEvents.cancel();
|
|
713
|
+
|
|
714
|
+
let zoom = this.zoom();
|
|
715
|
+
|
|
716
|
+
scroller.dimensions.forcedMinScale = pow(2, this.options.minZoom - zoom);
|
|
717
|
+
scroller.dimensions.maxScale = pow(2, this.options.maxZoom - zoom);
|
|
718
|
+
|
|
719
|
+
let xBounds = {
|
|
720
|
+
min: -topLeft.x,
|
|
721
|
+
max: scale - topLeft.x
|
|
722
|
+
};
|
|
723
|
+
|
|
724
|
+
let yBounds = {
|
|
725
|
+
min: -topLeft.y,
|
|
726
|
+
max: scale - topLeft.y
|
|
727
|
+
};
|
|
728
|
+
|
|
729
|
+
if (this.options.wraparound) {
|
|
730
|
+
xBounds.max = 20 * scale;
|
|
731
|
+
xBounds.min = -xBounds.max;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
if (this.options.pannable === false) {
|
|
735
|
+
let viewSize = this.viewSize();
|
|
736
|
+
xBounds.min = yBounds.min = 0;
|
|
737
|
+
xBounds.max = viewSize.width;
|
|
738
|
+
yBounds.max = viewSize.height;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
x.makeVirtual();
|
|
742
|
+
y.makeVirtual();
|
|
743
|
+
|
|
744
|
+
x.virtualSize(xBounds.min, xBounds.max);
|
|
745
|
+
y.virtualSize(yBounds.min, yBounds.max);
|
|
746
|
+
|
|
747
|
+
this._virtualSize = {
|
|
748
|
+
x: xBounds,
|
|
749
|
+
y: yBounds
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// kept for API compatibility, not used
|
|
754
|
+
_renderLayers() {
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
_layerSize(zoom) {
|
|
758
|
+
const newZoom = valueOrDefault(zoom, this.options.zoom);
|
|
759
|
+
return this.options.minSize * pow(2, newZoom);
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
_tap(e) {
|
|
763
|
+
if (!this._panComplete()) {
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
let cursor = this.eventOffset(e);
|
|
768
|
+
|
|
769
|
+
this.trigger('click', {
|
|
770
|
+
originalEvent: e,
|
|
771
|
+
location: this.viewToLocation(cursor)
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
_doubleTap(e) {
|
|
776
|
+
let options = this.options;
|
|
777
|
+
|
|
778
|
+
if (options.zoomable !== false) {
|
|
779
|
+
if (!this.trigger('zoomStart', { originalEvent: e })) {
|
|
780
|
+
let toZoom = this.zoom() + DEFAULT_ZOOM_RATE;
|
|
781
|
+
let cursor = this.eventOffset(e);
|
|
782
|
+
let location = this.viewToLocation(cursor);
|
|
783
|
+
let postZoom = this.locationToLayer(location, toZoom);
|
|
784
|
+
let origin = postZoom.translate(-cursor.x, -cursor.y);
|
|
785
|
+
|
|
786
|
+
this._zoomAround(origin, toZoom);
|
|
787
|
+
|
|
788
|
+
this.trigger('zoomEnd', {
|
|
789
|
+
originalEvent: e
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
_mousewheel(e) {
|
|
796
|
+
e.preventDefault();
|
|
797
|
+
let delta = mousewheelDelta(e) > 0 ? -1 : 1;
|
|
798
|
+
let options = this.options;
|
|
799
|
+
let fromZoom = this.zoom();
|
|
800
|
+
let toZoom = limitValue(fromZoom + delta, options.minZoom, options.maxZoom);
|
|
801
|
+
|
|
802
|
+
if (options.zoomable !== false && toZoom !== fromZoom) {
|
|
803
|
+
if (!this.trigger('zoomStart', { originalEvent: e })) {
|
|
804
|
+
let cursor = this.eventOffset(e);
|
|
805
|
+
let location = this.viewToLocation(cursor);
|
|
806
|
+
let postZoom = this.locationToLayer(location, toZoom);
|
|
807
|
+
let origin = postZoom.translate(-cursor.x, -cursor.y);
|
|
808
|
+
|
|
809
|
+
this._zoomAround(origin, toZoom);
|
|
810
|
+
|
|
811
|
+
this.trigger('zoomEnd', {
|
|
812
|
+
originalEvent: e
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
setDefaultOptions(Map, {
|
|
820
|
+
name: 'Map',
|
|
821
|
+
controls: {
|
|
822
|
+
attribution: true,
|
|
823
|
+
navigator: {
|
|
824
|
+
panStep: 100
|
|
825
|
+
},
|
|
826
|
+
zoom: true
|
|
827
|
+
},
|
|
828
|
+
layers: [],
|
|
829
|
+
layerDefaults: {
|
|
830
|
+
shape: {
|
|
831
|
+
style: {
|
|
832
|
+
fill: {
|
|
833
|
+
color: '#fff'
|
|
834
|
+
},
|
|
835
|
+
stroke: {
|
|
836
|
+
color: '#aaa',
|
|
837
|
+
width: 0.5
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
},
|
|
841
|
+
bubble: {
|
|
842
|
+
style: {
|
|
843
|
+
fill: {
|
|
844
|
+
color: '#fff',
|
|
845
|
+
opacity: 0.5
|
|
846
|
+
},
|
|
847
|
+
stroke: {
|
|
848
|
+
color: '#aaa',
|
|
849
|
+
width: 0.5
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
},
|
|
853
|
+
marker: {
|
|
854
|
+
shape: 'pinTarget',
|
|
855
|
+
tooltip: {
|
|
856
|
+
position: 'top'
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
},
|
|
860
|
+
center: [
|
|
861
|
+
0,
|
|
862
|
+
0
|
|
863
|
+
],
|
|
864
|
+
zoom: 3,
|
|
865
|
+
minSize: 256,
|
|
866
|
+
minZoom: 1,
|
|
867
|
+
maxZoom: 19,
|
|
868
|
+
markers: [],
|
|
869
|
+
markerDefaults: {
|
|
870
|
+
shape: 'pinTarget',
|
|
871
|
+
tooltip: {
|
|
872
|
+
position: 'top'
|
|
873
|
+
}
|
|
874
|
+
},
|
|
875
|
+
wraparound: true,
|
|
876
|
+
// If set to true, GeoJSON layer "Point" features will be rendered as markers.
|
|
877
|
+
// Otherwise, the points will be rendered as circles.
|
|
878
|
+
// Defaults to `true` for KUI/jQuery, `false` everywhere else.
|
|
879
|
+
renderPointsAsMarkers: false
|
|
880
|
+
});
|
|
881
|
+
|
|
882
|
+
setDefaultEvents(Map, [
|
|
883
|
+
'beforeReset',
|
|
884
|
+
'click',
|
|
885
|
+
'markerActivate',
|
|
886
|
+
'markerClick',
|
|
887
|
+
'markerCreated',
|
|
888
|
+
|
|
889
|
+
// Events for implementing custom tooltips.
|
|
890
|
+
'markerMouseEnter',
|
|
891
|
+
'markerMouseLeave',
|
|
892
|
+
|
|
893
|
+
'pan',
|
|
894
|
+
'panEnd',
|
|
895
|
+
'reset',
|
|
896
|
+
'shapeClick',
|
|
897
|
+
'shapeCreated',
|
|
898
|
+
'shapeFeatureCreated',
|
|
899
|
+
'shapeMouseEnter',
|
|
900
|
+
'shapeMouseLeave',
|
|
901
|
+
'zoomEnd',
|
|
902
|
+
'zoomStart'
|
|
903
|
+
]);
|
|
904
|
+
|
|
905
|
+
export default Map;
|