@maplat/ui 0.10.1 → 0.10.2
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/README.md +1 -0
- package/dist/assets/maplat.css +18 -18
- package/dist/assets/maplat.css.map +1 -1
- package/dist/assets/maplat.js +2 -2
- package/dist/assets/maplat.js.LICENSE.txt +41 -53
- package/dist/assets/maplat.js.map +1 -1
- package/dist/service-worker.js +2 -2
- package/dist/service-worker.js.LICENSE.txt +1 -1
- package/dist/service-worker.js.map +1 -1
- package/package.json +12 -13
- package/src/maplat_control.js +790 -790
package/src/maplat_control.js
CHANGED
|
@@ -1,790 +1,790 @@
|
|
|
1
|
-
import { Control, Rotate } from "
|
|
2
|
-
import { CLASS_UNSELECTABLE, CLASS_CONTROL } from "
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
ret.
|
|
35
|
-
ret.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
* @
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
* @
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
*
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
*
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
* @
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
* @
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
this.
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (control_settings["slider_color"]) {
|
|
166
|
-
const rgb = hexRgb(control_settings["slider_color"]);
|
|
167
|
-
const button = this.element.querySelector("button");
|
|
168
|
-
button.addEventListener("mouseover", () => {
|
|
169
|
-
button.style.backgroundColor = `rgba(${rgb.red},${rgb.green},${rgb.blue},.7)`;
|
|
170
|
-
});
|
|
171
|
-
button.addEventListener("mouseout", () => {
|
|
172
|
-
const disable = this.element.classList.contains("disable");
|
|
173
|
-
button.style.backgroundColor = `rgba(${rgb.red},${rgb.green},${
|
|
174
|
-
rgb.blue
|
|
175
|
-
},${disable ? 0.2 : 0.5})`;
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Update the SliderCommon element.
|
|
182
|
-
* @param {ol.MapEvent} mapEvent Map event.
|
|
183
|
-
* @this {ol.control.SliderCommon}
|
|
184
|
-
* @api
|
|
185
|
-
*/
|
|
186
|
-
static render(mapEvent) {
|
|
187
|
-
if (!mapEvent.frameState) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
if (!this.sliderInitialized_) {
|
|
191
|
-
this.initSlider_();
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* The enum for available directions.
|
|
197
|
-
*
|
|
198
|
-
* @enum {number}
|
|
199
|
-
* @private
|
|
200
|
-
*/
|
|
201
|
-
static get Direction_() {
|
|
202
|
-
return {
|
|
203
|
-
VERTICAL: 0,
|
|
204
|
-
HORIZONTAL: 1
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* @inheritDoc
|
|
210
|
-
*/
|
|
211
|
-
disposeInternal() {
|
|
212
|
-
this.dragger_.dispose();
|
|
213
|
-
super.disposeInternal();
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* @inheritDoc
|
|
218
|
-
*/
|
|
219
|
-
setMap(map) {
|
|
220
|
-
super.setMap(map);
|
|
221
|
-
if (map) {
|
|
222
|
-
map.render();
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Initializes the slider element. This will determine and set this controls
|
|
228
|
-
* direction_ and also constrain the dragging of the thumb to always be within
|
|
229
|
-
* the bounds of the container.
|
|
230
|
-
*
|
|
231
|
-
* @private
|
|
232
|
-
*/
|
|
233
|
-
initSlider_() {
|
|
234
|
-
const container = this.element;
|
|
235
|
-
const containerSize = {
|
|
236
|
-
width: container.offsetWidth,
|
|
237
|
-
height: container.offsetHeight
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
const thumb = container.firstElementChild;
|
|
241
|
-
const computedStyle = getComputedStyle(thumb); // eslint-disable-line no-undef
|
|
242
|
-
const thumbWidth =
|
|
243
|
-
thumb.offsetWidth +
|
|
244
|
-
parseFloat(computedStyle["marginRight"]) +
|
|
245
|
-
parseFloat(computedStyle["marginLeft"]);
|
|
246
|
-
const thumbHeight =
|
|
247
|
-
thumb.offsetHeight +
|
|
248
|
-
parseFloat(computedStyle["marginTop"]) +
|
|
249
|
-
parseFloat(computedStyle["marginBottom"]);
|
|
250
|
-
this.thumbSize_ = [thumbWidth, thumbHeight];
|
|
251
|
-
|
|
252
|
-
if (containerSize.width > containerSize.height) {
|
|
253
|
-
this.direction_ = SliderCommon.Direction_.HORIZONTAL;
|
|
254
|
-
} else {
|
|
255
|
-
this.direction_ = SliderCommon.Direction_.VERTICAL;
|
|
256
|
-
}
|
|
257
|
-
this.setValue(this.initialValue || 0);
|
|
258
|
-
const self = this;
|
|
259
|
-
addResizeListener(container, () => {
|
|
260
|
-
self.setValue(self.value_);
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
this.sliderInitialized_ = true;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
widthLimit_(_event) {
|
|
267
|
-
const container = this.element;
|
|
268
|
-
return container.offsetWidth - this.thumbSize_[0];
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
heightLimit_(_event) {
|
|
272
|
-
const container = this.element;
|
|
273
|
-
return container.offsetHeight - this.thumbSize_[1];
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* @param {Event} event The browser event to handle.
|
|
278
|
-
* @private
|
|
279
|
-
*/
|
|
280
|
-
handleContainerClick_(event) {
|
|
281
|
-
const relativePosition = this.getRelativePosition_(
|
|
282
|
-
event.offsetX - this.thumbSize_[0] / 2,
|
|
283
|
-
event.offsetY - this.thumbSize_[1] / 2
|
|
284
|
-
);
|
|
285
|
-
|
|
286
|
-
this.setThumbPosition_(relativePosition);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Handle dragger start events.
|
|
291
|
-
* @param {ol.pointer.PointerEvent} event The drag event.
|
|
292
|
-
* @private
|
|
293
|
-
*/
|
|
294
|
-
handleDraggerStart_(event) {
|
|
295
|
-
if (
|
|
296
|
-
!this.dragging_ &&
|
|
297
|
-
event.
|
|
298
|
-
!this.element.classList.contains("disable")
|
|
299
|
-
) {
|
|
300
|
-
this.getMap().getView().setHint(ViewHint.INTERACTING, 1);
|
|
301
|
-
this.previousX_ = event.clientX;
|
|
302
|
-
this.previousY_ = event.clientY;
|
|
303
|
-
this.dragging_ = true;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* Handle dragger drag events.
|
|
309
|
-
*
|
|
310
|
-
* @param {ol.pointer.PointerEvent|Event} event The drag event.
|
|
311
|
-
* @private
|
|
312
|
-
*/
|
|
313
|
-
handleDraggerDrag_(event) {
|
|
314
|
-
if (this.dragging_) {
|
|
315
|
-
const element = this.element.firstElementChild;
|
|
316
|
-
const deltaX =
|
|
317
|
-
event.clientX -
|
|
318
|
-
this.previousX_ +
|
|
319
|
-
(parseFloat(element.style.left, 10) || 0);
|
|
320
|
-
const deltaY =
|
|
321
|
-
event.clientY -
|
|
322
|
-
this.previousY_ +
|
|
323
|
-
(parseFloat(element.style.top, 10) || 0);
|
|
324
|
-
const relativePosition = this.getRelativePosition_(deltaX, deltaY);
|
|
325
|
-
this.setThumbPosition_(relativePosition);
|
|
326
|
-
this.previousX_ = event.clientX;
|
|
327
|
-
this.previousY_ = event.clientY;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* Handle dragger end events.
|
|
333
|
-
* @param {ol.pointer.PointerEvent|Event} event The drag event.
|
|
334
|
-
* @private
|
|
335
|
-
*/
|
|
336
|
-
handleDraggerEnd_(_event) {
|
|
337
|
-
if (this.dragging_) {
|
|
338
|
-
const view = this.getMap().getView();
|
|
339
|
-
view.setHint(ViewHint.INTERACTING, -1);
|
|
340
|
-
|
|
341
|
-
this.dragging_ = false;
|
|
342
|
-
this.previousX_ = undefined;
|
|
343
|
-
this.previousY_ = undefined;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Positions the thumb inside its container according to the given resolution.
|
|
349
|
-
*
|
|
350
|
-
* @param {number} res The res.
|
|
351
|
-
* @private
|
|
352
|
-
*/
|
|
353
|
-
setThumbPosition_(res) {
|
|
354
|
-
const thumb = this.element.firstElementChild;
|
|
355
|
-
|
|
356
|
-
if (this.direction_ == SliderCommon.Direction_.HORIZONTAL) {
|
|
357
|
-
thumb.style.left = `${this.widthLimit_() * res}px`;
|
|
358
|
-
} else {
|
|
359
|
-
thumb.style.top = `${this.heightLimit_() * res}px`;
|
|
360
|
-
}
|
|
361
|
-
this.value_ = this.reverse_ ? 1 - res : res;
|
|
362
|
-
this.set("slidervalue", this.value_);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* Calculates the relative position of the thumb given x and y offsets. The
|
|
367
|
-
* relative position scales from 0 to 1. The x and y offsets are assumed to be
|
|
368
|
-
* in pixel units within the dragger limits.
|
|
369
|
-
*
|
|
370
|
-
* @param {number} x Pixel position relative to the left of the slider.
|
|
371
|
-
* @param {number} y Pixel position relative to the top of the slider.
|
|
372
|
-
* @return {number} The relative position of the thumb.
|
|
373
|
-
* @private
|
|
374
|
-
*/
|
|
375
|
-
getRelativePosition_(x, y) {
|
|
376
|
-
let amount;
|
|
377
|
-
if (this.direction_ === SliderCommon.Direction_.HORIZONTAL) {
|
|
378
|
-
amount = x / this.widthLimit_();
|
|
379
|
-
} else {
|
|
380
|
-
amount = y / this.heightLimit_();
|
|
381
|
-
}
|
|
382
|
-
return clamp(amount, 0, 1);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
setValue(res) {
|
|
386
|
-
res = this.reverse_ ? 1 - res : res;
|
|
387
|
-
this.setThumbPosition_(res);
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
setEnable(cond) {
|
|
391
|
-
const elem = this.element;
|
|
392
|
-
if (cond) {
|
|
393
|
-
elem.classList.remove("disable");
|
|
394
|
-
} else {
|
|
395
|
-
elem.classList.add("disable");
|
|
396
|
-
}
|
|
397
|
-
if (control_settings["slider_color"]) {
|
|
398
|
-
const rgb = hexRgb(control_settings["slider_color"]);
|
|
399
|
-
elem.querySelector("button").style.backgroundColor = `rgba(${rgb.red},${
|
|
400
|
-
rgb.green
|
|
401
|
-
},${rgb.blue},${cond ? 0.5 : 0.2})`;
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
export class CustomControl extends Control {
|
|
407
|
-
constructor(optOptions) {
|
|
408
|
-
const options = optOptions || {};
|
|
409
|
-
const element = document.createElement("div"); // eslint-disable-line no-undef
|
|
410
|
-
|
|
411
|
-
super({
|
|
412
|
-
element,
|
|
413
|
-
target: options.target,
|
|
414
|
-
render: options.render
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
const button = document.createElement("button"); // eslint-disable-line no-undef
|
|
418
|
-
button.setAttribute("type", "button");
|
|
419
|
-
button.title = options.tipLabel;
|
|
420
|
-
const span = document.createElement("span"); // eslint-disable-line no-undef
|
|
421
|
-
span.innerHTML = options.character;
|
|
422
|
-
button.appendChild(span);
|
|
423
|
-
let timer;
|
|
424
|
-
let touchstart;
|
|
425
|
-
const self = this;
|
|
426
|
-
|
|
427
|
-
button.addEventListener("click", e => {
|
|
428
|
-
e.stopPropagation();
|
|
429
|
-
});
|
|
430
|
-
button.addEventListener(
|
|
431
|
-
"mouseup",
|
|
432
|
-
e => {
|
|
433
|
-
if (!touchstart) {
|
|
434
|
-
if (timer) {
|
|
435
|
-
if (options.long_callback) {
|
|
436
|
-
clearTimeout(timer); // eslint-disable-line no-undef
|
|
437
|
-
}
|
|
438
|
-
timer = null;
|
|
439
|
-
options.callback.apply(self);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
e.stopPropagation();
|
|
443
|
-
},
|
|
444
|
-
false
|
|
445
|
-
);
|
|
446
|
-
button.addEventListener(
|
|
447
|
-
"mousemove",
|
|
448
|
-
e => {
|
|
449
|
-
e.stopPropagation();
|
|
450
|
-
},
|
|
451
|
-
false
|
|
452
|
-
);
|
|
453
|
-
button.addEventListener(
|
|
454
|
-
"mousedown",
|
|
455
|
-
e => {
|
|
456
|
-
if (!touchstart) {
|
|
457
|
-
if (options.long_callback) {
|
|
458
|
-
timer = setTimeout(() => {
|
|
459
|
-
// eslint-disable-line no-undef
|
|
460
|
-
timer = null;
|
|
461
|
-
options.long_callback.apply(self);
|
|
462
|
-
}, 1500);
|
|
463
|
-
} else {
|
|
464
|
-
timer = true;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
e.stopPropagation();
|
|
468
|
-
},
|
|
469
|
-
false
|
|
470
|
-
);
|
|
471
|
-
button.addEventListener(
|
|
472
|
-
"touchstart",
|
|
473
|
-
e => {
|
|
474
|
-
touchstart = true;
|
|
475
|
-
if (options.long_callback) {
|
|
476
|
-
timer = setTimeout(() => {
|
|
477
|
-
// eslint-disable-line no-undef
|
|
478
|
-
timer = null;
|
|
479
|
-
options.long_callback.apply(self);
|
|
480
|
-
}, 1500);
|
|
481
|
-
} else {
|
|
482
|
-
timer = true;
|
|
483
|
-
}
|
|
484
|
-
e.stopPropagation();
|
|
485
|
-
},
|
|
486
|
-
false
|
|
487
|
-
);
|
|
488
|
-
button.addEventListener(
|
|
489
|
-
"touchend",
|
|
490
|
-
e => {
|
|
491
|
-
if (timer) {
|
|
492
|
-
if (options.long_callback) {
|
|
493
|
-
clearTimeout(timer); // eslint-disable-line no-undef
|
|
494
|
-
}
|
|
495
|
-
timer = null;
|
|
496
|
-
options.callback.apply(self);
|
|
497
|
-
}
|
|
498
|
-
e.stopPropagation();
|
|
499
|
-
},
|
|
500
|
-
false
|
|
501
|
-
);
|
|
502
|
-
button.addEventListener(
|
|
503
|
-
"mouseout",
|
|
504
|
-
e => {
|
|
505
|
-
if (options.long_callback) {
|
|
506
|
-
clearTimeout(timer); // eslint-disable-line no-undef
|
|
507
|
-
}
|
|
508
|
-
timer = null;
|
|
509
|
-
e.stopPropagation();
|
|
510
|
-
},
|
|
511
|
-
false
|
|
512
|
-
);
|
|
513
|
-
button.addEventListener(
|
|
514
|
-
"dblclick",
|
|
515
|
-
e => {
|
|
516
|
-
e.preventDefault();
|
|
517
|
-
},
|
|
518
|
-
false
|
|
519
|
-
);
|
|
520
|
-
|
|
521
|
-
element.className = `${options.cls} ol-unselectable ol-control`;
|
|
522
|
-
element.appendChild(button);
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
export class GoHome extends CustomControl {
|
|
527
|
-
constructor(optOptions) {
|
|
528
|
-
const options = optOptions || {};
|
|
529
|
-
options.character = control_settings["home"]
|
|
530
|
-
? `<img src="${control_settings["home"]}">`
|
|
531
|
-
: '<i class="fa fa-home fa-lg"></i>';
|
|
532
|
-
options.cls = "home";
|
|
533
|
-
options.callback = function () {
|
|
534
|
-
const source = this.getMap().getLayers().item(0).getSource();
|
|
535
|
-
source.goHome();
|
|
536
|
-
};
|
|
537
|
-
super(options);
|
|
538
|
-
if (control_settings["home"]) {
|
|
539
|
-
const button = this.element.querySelector("button");
|
|
540
|
-
button.style.backgroundColor = "rgba(0,0,0,0)";
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
export class SetGPS extends CustomControl {
|
|
546
|
-
constructor(optOptions) {
|
|
547
|
-
const options = optOptions || {};
|
|
548
|
-
options.character = control_settings["gps"]
|
|
549
|
-
? `<img src="${control_settings["gps"]}">`
|
|
550
|
-
: '<i class="fa fa-crosshairs fa-lg"></i>';
|
|
551
|
-
options.cls = "gps";
|
|
552
|
-
options.render = function (mapEvent) {
|
|
553
|
-
const frameState = mapEvent.frameState;
|
|
554
|
-
if (!frameState) {
|
|
555
|
-
return;
|
|
556
|
-
}
|
|
557
|
-
const map = this.getMap();
|
|
558
|
-
if (map.geolocation) {
|
|
559
|
-
const tracking = map.geolocation.getTracking();
|
|
560
|
-
const receiving = this.element.classList.contains("disable");
|
|
561
|
-
if (receiving && !tracking) {
|
|
562
|
-
this.element.classList.remove("disable");
|
|
563
|
-
} else if (!receiving && tracking) {
|
|
564
|
-
this.element.classList.add("disable");
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
};
|
|
568
|
-
|
|
569
|
-
options.callback = function () {
|
|
570
|
-
const receiving = this.element.classList.contains("disable");
|
|
571
|
-
const map = this.getMap();
|
|
572
|
-
|
|
573
|
-
map.handleGPS(!receiving);
|
|
574
|
-
if (receiving) {
|
|
575
|
-
this.element.classList.remove("disable");
|
|
576
|
-
} else {
|
|
577
|
-
this.element.classList.add("disable");
|
|
578
|
-
}
|
|
579
|
-
};
|
|
580
|
-
|
|
581
|
-
super(options);
|
|
582
|
-
if (control_settings["gps"]) {
|
|
583
|
-
const button = this.element.querySelector("button");
|
|
584
|
-
button.style.backgroundColor = "rgba(0,0,0,0)";
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
export class CompassRotate extends Rotate {
|
|
590
|
-
constructor(optOptions) {
|
|
591
|
-
const options = optOptions || {};
|
|
592
|
-
options.autoHide = false;
|
|
593
|
-
const span = document.createElement("span"); // eslint-disable-line no-undef
|
|
594
|
-
span.innerHTML = control_settings["compass"]
|
|
595
|
-
? `<img src="${control_settings["compass"]}">`
|
|
596
|
-
: '<i class="fa fa-compass fa-lg ol-compass-fa"></i>';
|
|
597
|
-
options.label = span;
|
|
598
|
-
options.render = function (mapEvent) {
|
|
599
|
-
const frameState = mapEvent.frameState;
|
|
600
|
-
if (!frameState) {
|
|
601
|
-
return;
|
|
602
|
-
}
|
|
603
|
-
const view = this.getMap().getView();
|
|
604
|
-
const rotation = frameState.viewState.rotation;
|
|
605
|
-
const center = view.getCenter();
|
|
606
|
-
const zoom = view.getDecimalZoom();
|
|
607
|
-
if (
|
|
608
|
-
rotation != this.rotation_ ||
|
|
609
|
-
center[0] != this.center_[0] ||
|
|
610
|
-
center[1] != this.center_[1] ||
|
|
611
|
-
zoom != this.zoom_
|
|
612
|
-
) {
|
|
613
|
-
const contains = this.element.classList.contains("disable");
|
|
614
|
-
if (!contains && rotation === 0) {
|
|
615
|
-
this.element.classList.add("disable");
|
|
616
|
-
} else if (contains && rotation !== 0) {
|
|
617
|
-
this.element.classList.remove("disable");
|
|
618
|
-
}
|
|
619
|
-
const self = this;
|
|
620
|
-
const layer = this.getMap().getLayers().item(0);
|
|
621
|
-
const source = layer.getSource
|
|
622
|
-
? layer.getSource()
|
|
623
|
-
: layer.getLayers().item(0).getSource();
|
|
624
|
-
if (!source) {
|
|
625
|
-
const transform = "rotate(0rad)";
|
|
626
|
-
self.label_.style.msTransform = transform;
|
|
627
|
-
self.label_.style.webkitTransform = transform;
|
|
628
|
-
self.label_.style.transform = transform;
|
|
629
|
-
return;
|
|
630
|
-
}
|
|
631
|
-
source.viewpoint2MercsAsync().then(mercs => {
|
|
632
|
-
const rot = source.mercs2MercViewpoint(mercs)[2];
|
|
633
|
-
const transform = `rotate(${rot}rad)`;
|
|
634
|
-
self.label_.style.msTransform = transform;
|
|
635
|
-
self.label_.style.webkitTransform = transform;
|
|
636
|
-
self.label_.style.transform = transform;
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
this.rotation_ = rotation;
|
|
640
|
-
this.center_ = center;
|
|
641
|
-
this.zoom_ = zoom;
|
|
642
|
-
};
|
|
643
|
-
super(options);
|
|
644
|
-
if (control_settings["compass"]) {
|
|
645
|
-
const button = this.element.querySelector("button");
|
|
646
|
-
button.style.backgroundColor = "rgba(0,0,0,0)";
|
|
647
|
-
}
|
|
648
|
-
this.center_ = [];
|
|
649
|
-
this.zoom_ = undefined;
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
export class Share extends CustomControl {
|
|
654
|
-
constructor(optOptions) {
|
|
655
|
-
const options = optOptions || {};
|
|
656
|
-
options.character = control_settings["share"]
|
|
657
|
-
? `<img src="${control_settings["share"]}">`
|
|
658
|
-
: '<i class="fa fa-share-alt-square fa-lg"></i>';
|
|
659
|
-
options.cls = "ol-share";
|
|
660
|
-
options.callback = function () {
|
|
661
|
-
const map = this.getMap();
|
|
662
|
-
map.dispatchEvent(
|
|
663
|
-
new MapEvent("click_control", map, { control: "share" })
|
|
664
|
-
);
|
|
665
|
-
};
|
|
666
|
-
|
|
667
|
-
super(options);
|
|
668
|
-
if (control_settings["share"]) {
|
|
669
|
-
const button = this.element.querySelector("button");
|
|
670
|
-
button.style.backgroundColor = "rgba(0,0,0,0)";
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
export class Border extends CustomControl {
|
|
676
|
-
constructor(optOptions) {
|
|
677
|
-
const options = optOptions || {};
|
|
678
|
-
options.character = control_settings["border"]
|
|
679
|
-
? `<img src="${control_settings["border"]}">`
|
|
680
|
-
: '<i class="fa fa-clone fa-lg"></i>';
|
|
681
|
-
options.cls = "ol-border";
|
|
682
|
-
options.callback = function () {
|
|
683
|
-
const map = this.getMap();
|
|
684
|
-
map.dispatchEvent(
|
|
685
|
-
new MapEvent("click_control", map, { control: "border" })
|
|
686
|
-
);
|
|
687
|
-
};
|
|
688
|
-
|
|
689
|
-
super(options);
|
|
690
|
-
if (control_settings["border"]) {
|
|
691
|
-
const button = this.element.querySelector("button");
|
|
692
|
-
button.style.backgroundColor = "rgba(0,0,0,0)";
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
export class Maplat extends CustomControl {
|
|
698
|
-
constructor(optOptions) {
|
|
699
|
-
const options = optOptions || {};
|
|
700
|
-
options.character = control_settings["help"]
|
|
701
|
-
? `<img src="${control_settings["help"]}">`
|
|
702
|
-
: '<i class="fa fa-question-circle fa-lg"></i>';
|
|
703
|
-
options.cls = "ol-maplat";
|
|
704
|
-
options.callback = function () {
|
|
705
|
-
const map = this.getMap();
|
|
706
|
-
map.dispatchEvent(
|
|
707
|
-
new MapEvent("click_control", map, { control: "help" })
|
|
708
|
-
);
|
|
709
|
-
};
|
|
710
|
-
|
|
711
|
-
super(options);
|
|
712
|
-
if (control_settings["help"]) {
|
|
713
|
-
const button = this.element.querySelector("button");
|
|
714
|
-
button.style.backgroundColor = "rgba(0,0,0,0)";
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
export class Copyright extends CustomControl {
|
|
720
|
-
constructor(optOptions) {
|
|
721
|
-
const options = optOptions || {};
|
|
722
|
-
options.character = control_settings["attr"]
|
|
723
|
-
? `<img src="${control_settings["attr"]}">`
|
|
724
|
-
: '<i class="fa fa-info-circle fa-lg"></i>';
|
|
725
|
-
options.cls = "ol-copyright";
|
|
726
|
-
options.callback = function () {
|
|
727
|
-
const map = this.getMap();
|
|
728
|
-
map.dispatchEvent(
|
|
729
|
-
new MapEvent("click_control", map, { control: "copyright" })
|
|
730
|
-
);
|
|
731
|
-
};
|
|
732
|
-
|
|
733
|
-
super(options);
|
|
734
|
-
if (control_settings["attr"]) {
|
|
735
|
-
const button = this.element.querySelector("button");
|
|
736
|
-
button.style.backgroundColor = "rgba(0,0,0,0)";
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
export class HideMarker extends CustomControl {
|
|
742
|
-
constructor(optOptions) {
|
|
743
|
-
const options = optOptions || {};
|
|
744
|
-
options.character = control_settings["hide_marker"]
|
|
745
|
-
? `<img src="${control_settings["hide_marker"]}">`
|
|
746
|
-
: '<i class="fa fa-map-marker fa-lg"></i>';
|
|
747
|
-
options.cls = "ol-hide-marker";
|
|
748
|
-
options.callback = function () {
|
|
749
|
-
const map = this.getMap();
|
|
750
|
-
map.dispatchEvent(
|
|
751
|
-
new MapEvent("click_control", map, { control: "hideMarker" })
|
|
752
|
-
);
|
|
753
|
-
};
|
|
754
|
-
options.long_callback = function () {
|
|
755
|
-
const map = this.getMap();
|
|
756
|
-
map.dispatchEvent(
|
|
757
|
-
new MapEvent("click_control", map, { control: "hideLayer" })
|
|
758
|
-
);
|
|
759
|
-
};
|
|
760
|
-
|
|
761
|
-
super(options);
|
|
762
|
-
if (control_settings["hide_marker"]) {
|
|
763
|
-
const button = this.element.querySelector("button");
|
|
764
|
-
button.style.backgroundColor = "rgba(0,0,0,0)";
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
export class Zoom extends BaseZoom {
|
|
770
|
-
constructor(options = {}) {
|
|
771
|
-
if (control_settings["zoom_plus"]) {
|
|
772
|
-
options.zoomInLabel = createElement(
|
|
773
|
-
`<img src="${control_settings["zoom_plus"]}">`
|
|
774
|
-
)[0];
|
|
775
|
-
}
|
|
776
|
-
if (control_settings["zoom_minus"]) {
|
|
777
|
-
options.zoomOutLabel = createElement(
|
|
778
|
-
`<img src="${control_settings["zoom_minus"]}">`
|
|
779
|
-
)[0];
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
super(options);
|
|
783
|
-
if (control_settings["compass"]) {
|
|
784
|
-
const buttons = this.element.querySelectorAll("button");
|
|
785
|
-
buttons.forEach(button => {
|
|
786
|
-
button.style.backgroundColor = "rgba(0,0,0,0)";
|
|
787
|
-
});
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
}
|
|
1
|
+
import { Control, Rotate, Zoom as BaseZoom } from "ol/control";
|
|
2
|
+
import { CLASS_UNSELECTABLE, CLASS_CONTROL } from "ol/css";
|
|
3
|
+
import ViewHint from "ol/ViewHint";
|
|
4
|
+
import { clamp } from "ol/math";
|
|
5
|
+
import { MapEvent } from "ol";
|
|
6
|
+
import { addResizeListener } from "../legacy/detect-element-resize";
|
|
7
|
+
import pointer from "./pointer_images";
|
|
8
|
+
import { createElement } from "@maplat/core";
|
|
9
|
+
|
|
10
|
+
let control_settings = {};
|
|
11
|
+
const delegator = {
|
|
12
|
+
compass: "compass.png",
|
|
13
|
+
border: "border.png",
|
|
14
|
+
attr: "attr.png",
|
|
15
|
+
gps: "gps.png",
|
|
16
|
+
zoom_plus: "plus.png",
|
|
17
|
+
zoom_minus: "minus.png",
|
|
18
|
+
help: "help.png",
|
|
19
|
+
home: "home.png",
|
|
20
|
+
hide_marker: "hide_marker.png",
|
|
21
|
+
share: "share.png",
|
|
22
|
+
slider_in_help: "slider.png",
|
|
23
|
+
favicon: "favicon.png"
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function hexRgb(hex) {
|
|
27
|
+
const ret = {};
|
|
28
|
+
if (hex.match(/^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i)) {
|
|
29
|
+
ret.red = parseInt(RegExp.$1, 16);
|
|
30
|
+
ret.green = parseInt(RegExp.$2, 16);
|
|
31
|
+
ret.blue = parseInt(RegExp.$3, 16);
|
|
32
|
+
} else if (hex.match(/^#?([0-9A-F])([0-9A-F])([0-9A-F])$/i)) {
|
|
33
|
+
ret.red = parseInt(`${RegExp.$1}${RegExp.$1}`, 16);
|
|
34
|
+
ret.green = parseInt(`${RegExp.$2}${RegExp.$2}`, 16);
|
|
35
|
+
ret.blue = parseInt(`${RegExp.$3}${RegExp.$3}`, 16);
|
|
36
|
+
}
|
|
37
|
+
return ret;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function setControlSettings(options) {
|
|
41
|
+
control_settings = options;
|
|
42
|
+
Object.keys(control_settings).forEach(key => {
|
|
43
|
+
if (delegator[key]) {
|
|
44
|
+
pointer[delegator[key]] = control_settings[key];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @classdesc
|
|
51
|
+
* A slider type of control for zooming.
|
|
52
|
+
*
|
|
53
|
+
* Example:
|
|
54
|
+
*
|
|
55
|
+
* map.addControl(new ol.control.SliderCommon());
|
|
56
|
+
*
|
|
57
|
+
* @constructor
|
|
58
|
+
* @extends {ol.control.Control}
|
|
59
|
+
* @param {olx.control.SliderCommonOptions=} opt_options Zoom slider options.
|
|
60
|
+
* @api
|
|
61
|
+
*/
|
|
62
|
+
export class SliderCommon extends Control {
|
|
63
|
+
constructor(opt_options) {
|
|
64
|
+
const options = opt_options ? opt_options : {};
|
|
65
|
+
const containerElement = document.createElement("div"); // eslint-disable-line no-undef
|
|
66
|
+
const render = options.render ? options.render : SliderCommon.render;
|
|
67
|
+
|
|
68
|
+
super({
|
|
69
|
+
element: containerElement,
|
|
70
|
+
render
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The direction of the slider. Will be determined from actual display of the
|
|
75
|
+
* container and defaults to ol.control.SliderCommon.Direction_.VERTICAL.
|
|
76
|
+
*
|
|
77
|
+
* @type {ol.control.SliderCommon.Direction_}
|
|
78
|
+
* @private
|
|
79
|
+
*/
|
|
80
|
+
this.direction_ = SliderCommon.Direction_.VERTICAL;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @type {boolean}
|
|
84
|
+
* @private
|
|
85
|
+
*/
|
|
86
|
+
this.dragging_ = undefined;
|
|
87
|
+
|
|
88
|
+
this.value_ = undefined;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @type {number|undefined}
|
|
92
|
+
* @private
|
|
93
|
+
*/
|
|
94
|
+
this.previousX_ = undefined;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @type {number|undefined}
|
|
98
|
+
* @private
|
|
99
|
+
*/
|
|
100
|
+
this.previousY_ = undefined;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The calculated thumb size (border box plus margins). Set when initSlider_
|
|
104
|
+
* is called.
|
|
105
|
+
* @type {ol.Size}
|
|
106
|
+
* @private
|
|
107
|
+
*/
|
|
108
|
+
this.thumbSize_ = null;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Whether the slider is initialized.
|
|
112
|
+
* @type {boolean}
|
|
113
|
+
* @private
|
|
114
|
+
*/
|
|
115
|
+
this.sliderInitialized_ = false;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @type {number}
|
|
119
|
+
* @private
|
|
120
|
+
*/
|
|
121
|
+
this.duration_ = options.duration !== undefined ? options.duration : 200;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @type {number}
|
|
125
|
+
* @private
|
|
126
|
+
*/
|
|
127
|
+
this.reverse_ = options.reverse !== undefined ? options.reverse : false;
|
|
128
|
+
|
|
129
|
+
this.initialValue = options.initialValue;
|
|
130
|
+
|
|
131
|
+
const className =
|
|
132
|
+
options.className !== undefined ? options.className : "ol-slidercommon";
|
|
133
|
+
const thumbElement = document.createElement("button"); // eslint-disable-line no-undef
|
|
134
|
+
thumbElement.setAttribute("type", "button");
|
|
135
|
+
thumbElement.className = `${className}-thumb${CLASS_UNSELECTABLE}`;
|
|
136
|
+
|
|
137
|
+
containerElement.title = options.tipLabel;
|
|
138
|
+
containerElement.className = `${className} ${CLASS_UNSELECTABLE} ${CLASS_CONTROL}`;
|
|
139
|
+
containerElement.appendChild(thumbElement);
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @type {ol.pointer.PointerEventHandler}
|
|
143
|
+
* @private
|
|
144
|
+
*/
|
|
145
|
+
containerElement.addEventListener("pointerdown", ev => {
|
|
146
|
+
ev.stopPropagation();
|
|
147
|
+
this.handleDraggerStart_(ev);
|
|
148
|
+
});
|
|
149
|
+
containerElement.addEventListener("pointermove", ev => {
|
|
150
|
+
ev.stopPropagation();
|
|
151
|
+
this.handleDraggerDrag_(ev);
|
|
152
|
+
});
|
|
153
|
+
containerElement.addEventListener("pointerup", ev => {
|
|
154
|
+
ev.stopPropagation();
|
|
155
|
+
this.handleDraggerEnd_(ev);
|
|
156
|
+
});
|
|
157
|
+
thumbElement.addEventListener("click", ev => {
|
|
158
|
+
ev.stopPropagation();
|
|
159
|
+
});
|
|
160
|
+
containerElement.addEventListener("mouseout", ev => {
|
|
161
|
+
ev.stopPropagation();
|
|
162
|
+
this.handleDraggerEnd_(ev);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
if (control_settings["slider_color"]) {
|
|
166
|
+
const rgb = hexRgb(control_settings["slider_color"]);
|
|
167
|
+
const button = this.element.querySelector("button");
|
|
168
|
+
button.addEventListener("mouseover", () => {
|
|
169
|
+
button.style.backgroundColor = `rgba(${rgb.red},${rgb.green},${rgb.blue},.7)`;
|
|
170
|
+
});
|
|
171
|
+
button.addEventListener("mouseout", () => {
|
|
172
|
+
const disable = this.element.classList.contains("disable");
|
|
173
|
+
button.style.backgroundColor = `rgba(${rgb.red},${rgb.green},${
|
|
174
|
+
rgb.blue
|
|
175
|
+
},${disable ? 0.2 : 0.5})`;
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Update the SliderCommon element.
|
|
182
|
+
* @param {ol.MapEvent} mapEvent Map event.
|
|
183
|
+
* @this {ol.control.SliderCommon}
|
|
184
|
+
* @api
|
|
185
|
+
*/
|
|
186
|
+
static render(mapEvent) {
|
|
187
|
+
if (!mapEvent.frameState) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (!this.sliderInitialized_) {
|
|
191
|
+
this.initSlider_();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* The enum for available directions.
|
|
197
|
+
*
|
|
198
|
+
* @enum {number}
|
|
199
|
+
* @private
|
|
200
|
+
*/
|
|
201
|
+
static get Direction_() {
|
|
202
|
+
return {
|
|
203
|
+
VERTICAL: 0,
|
|
204
|
+
HORIZONTAL: 1
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* @inheritDoc
|
|
210
|
+
*/
|
|
211
|
+
disposeInternal() {
|
|
212
|
+
this.dragger_.dispose();
|
|
213
|
+
super.disposeInternal();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* @inheritDoc
|
|
218
|
+
*/
|
|
219
|
+
setMap(map) {
|
|
220
|
+
super.setMap(map);
|
|
221
|
+
if (map) {
|
|
222
|
+
map.render();
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Initializes the slider element. This will determine and set this controls
|
|
228
|
+
* direction_ and also constrain the dragging of the thumb to always be within
|
|
229
|
+
* the bounds of the container.
|
|
230
|
+
*
|
|
231
|
+
* @private
|
|
232
|
+
*/
|
|
233
|
+
initSlider_() {
|
|
234
|
+
const container = this.element;
|
|
235
|
+
const containerSize = {
|
|
236
|
+
width: container.offsetWidth,
|
|
237
|
+
height: container.offsetHeight
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const thumb = container.firstElementChild;
|
|
241
|
+
const computedStyle = getComputedStyle(thumb); // eslint-disable-line no-undef
|
|
242
|
+
const thumbWidth =
|
|
243
|
+
thumb.offsetWidth +
|
|
244
|
+
parseFloat(computedStyle["marginRight"]) +
|
|
245
|
+
parseFloat(computedStyle["marginLeft"]);
|
|
246
|
+
const thumbHeight =
|
|
247
|
+
thumb.offsetHeight +
|
|
248
|
+
parseFloat(computedStyle["marginTop"]) +
|
|
249
|
+
parseFloat(computedStyle["marginBottom"]);
|
|
250
|
+
this.thumbSize_ = [thumbWidth, thumbHeight];
|
|
251
|
+
|
|
252
|
+
if (containerSize.width > containerSize.height) {
|
|
253
|
+
this.direction_ = SliderCommon.Direction_.HORIZONTAL;
|
|
254
|
+
} else {
|
|
255
|
+
this.direction_ = SliderCommon.Direction_.VERTICAL;
|
|
256
|
+
}
|
|
257
|
+
this.setValue(this.initialValue || 0);
|
|
258
|
+
const self = this;
|
|
259
|
+
addResizeListener(container, () => {
|
|
260
|
+
self.setValue(self.value_);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
this.sliderInitialized_ = true;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
widthLimit_(_event) {
|
|
267
|
+
const container = this.element;
|
|
268
|
+
return container.offsetWidth - this.thumbSize_[0];
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
heightLimit_(_event) {
|
|
272
|
+
const container = this.element;
|
|
273
|
+
return container.offsetHeight - this.thumbSize_[1];
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* @param {Event} event The browser event to handle.
|
|
278
|
+
* @private
|
|
279
|
+
*/
|
|
280
|
+
handleContainerClick_(event) {
|
|
281
|
+
const relativePosition = this.getRelativePosition_(
|
|
282
|
+
event.offsetX - this.thumbSize_[0] / 2,
|
|
283
|
+
event.offsetY - this.thumbSize_[1] / 2
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
this.setThumbPosition_(relativePosition);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Handle dragger start events.
|
|
291
|
+
* @param {ol.pointer.PointerEvent} event The drag event.
|
|
292
|
+
* @private
|
|
293
|
+
*/
|
|
294
|
+
handleDraggerStart_(event) {
|
|
295
|
+
if (
|
|
296
|
+
!this.dragging_ &&
|
|
297
|
+
event.target === this.element.firstElementChild &&
|
|
298
|
+
!this.element.classList.contains("disable")
|
|
299
|
+
) {
|
|
300
|
+
this.getMap().getView().setHint(ViewHint.INTERACTING, 1);
|
|
301
|
+
this.previousX_ = event.clientX;
|
|
302
|
+
this.previousY_ = event.clientY;
|
|
303
|
+
this.dragging_ = true;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Handle dragger drag events.
|
|
309
|
+
*
|
|
310
|
+
* @param {ol.pointer.PointerEvent|Event} event The drag event.
|
|
311
|
+
* @private
|
|
312
|
+
*/
|
|
313
|
+
handleDraggerDrag_(event) {
|
|
314
|
+
if (this.dragging_) {
|
|
315
|
+
const element = this.element.firstElementChild;
|
|
316
|
+
const deltaX =
|
|
317
|
+
event.clientX -
|
|
318
|
+
this.previousX_ +
|
|
319
|
+
(parseFloat(element.style.left, 10) || 0);
|
|
320
|
+
const deltaY =
|
|
321
|
+
event.clientY -
|
|
322
|
+
this.previousY_ +
|
|
323
|
+
(parseFloat(element.style.top, 10) || 0);
|
|
324
|
+
const relativePosition = this.getRelativePosition_(deltaX, deltaY);
|
|
325
|
+
this.setThumbPosition_(relativePosition);
|
|
326
|
+
this.previousX_ = event.clientX;
|
|
327
|
+
this.previousY_ = event.clientY;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Handle dragger end events.
|
|
333
|
+
* @param {ol.pointer.PointerEvent|Event} event The drag event.
|
|
334
|
+
* @private
|
|
335
|
+
*/
|
|
336
|
+
handleDraggerEnd_(_event) {
|
|
337
|
+
if (this.dragging_) {
|
|
338
|
+
const view = this.getMap().getView();
|
|
339
|
+
view.setHint(ViewHint.INTERACTING, -1);
|
|
340
|
+
|
|
341
|
+
this.dragging_ = false;
|
|
342
|
+
this.previousX_ = undefined;
|
|
343
|
+
this.previousY_ = undefined;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Positions the thumb inside its container according to the given resolution.
|
|
349
|
+
*
|
|
350
|
+
* @param {number} res The res.
|
|
351
|
+
* @private
|
|
352
|
+
*/
|
|
353
|
+
setThumbPosition_(res) {
|
|
354
|
+
const thumb = this.element.firstElementChild;
|
|
355
|
+
|
|
356
|
+
if (this.direction_ == SliderCommon.Direction_.HORIZONTAL) {
|
|
357
|
+
thumb.style.left = `${this.widthLimit_() * res}px`;
|
|
358
|
+
} else {
|
|
359
|
+
thumb.style.top = `${this.heightLimit_() * res}px`;
|
|
360
|
+
}
|
|
361
|
+
this.value_ = this.reverse_ ? 1 - res : res;
|
|
362
|
+
this.set("slidervalue", this.value_);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Calculates the relative position of the thumb given x and y offsets. The
|
|
367
|
+
* relative position scales from 0 to 1. The x and y offsets are assumed to be
|
|
368
|
+
* in pixel units within the dragger limits.
|
|
369
|
+
*
|
|
370
|
+
* @param {number} x Pixel position relative to the left of the slider.
|
|
371
|
+
* @param {number} y Pixel position relative to the top of the slider.
|
|
372
|
+
* @return {number} The relative position of the thumb.
|
|
373
|
+
* @private
|
|
374
|
+
*/
|
|
375
|
+
getRelativePosition_(x, y) {
|
|
376
|
+
let amount;
|
|
377
|
+
if (this.direction_ === SliderCommon.Direction_.HORIZONTAL) {
|
|
378
|
+
amount = x / this.widthLimit_();
|
|
379
|
+
} else {
|
|
380
|
+
amount = y / this.heightLimit_();
|
|
381
|
+
}
|
|
382
|
+
return clamp(amount, 0, 1);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
setValue(res) {
|
|
386
|
+
res = this.reverse_ ? 1 - res : res;
|
|
387
|
+
this.setThumbPosition_(res);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
setEnable(cond) {
|
|
391
|
+
const elem = this.element;
|
|
392
|
+
if (cond) {
|
|
393
|
+
elem.classList.remove("disable");
|
|
394
|
+
} else {
|
|
395
|
+
elem.classList.add("disable");
|
|
396
|
+
}
|
|
397
|
+
if (control_settings["slider_color"]) {
|
|
398
|
+
const rgb = hexRgb(control_settings["slider_color"]);
|
|
399
|
+
elem.querySelector("button").style.backgroundColor = `rgba(${rgb.red},${
|
|
400
|
+
rgb.green
|
|
401
|
+
},${rgb.blue},${cond ? 0.5 : 0.2})`;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export class CustomControl extends Control {
|
|
407
|
+
constructor(optOptions) {
|
|
408
|
+
const options = optOptions || {};
|
|
409
|
+
const element = document.createElement("div"); // eslint-disable-line no-undef
|
|
410
|
+
|
|
411
|
+
super({
|
|
412
|
+
element,
|
|
413
|
+
target: options.target,
|
|
414
|
+
render: options.render
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
const button = document.createElement("button"); // eslint-disable-line no-undef
|
|
418
|
+
button.setAttribute("type", "button");
|
|
419
|
+
button.title = options.tipLabel;
|
|
420
|
+
const span = document.createElement("span"); // eslint-disable-line no-undef
|
|
421
|
+
span.innerHTML = options.character;
|
|
422
|
+
button.appendChild(span);
|
|
423
|
+
let timer;
|
|
424
|
+
let touchstart;
|
|
425
|
+
const self = this;
|
|
426
|
+
|
|
427
|
+
button.addEventListener("click", e => {
|
|
428
|
+
e.stopPropagation();
|
|
429
|
+
});
|
|
430
|
+
button.addEventListener(
|
|
431
|
+
"mouseup",
|
|
432
|
+
e => {
|
|
433
|
+
if (!touchstart) {
|
|
434
|
+
if (timer) {
|
|
435
|
+
if (options.long_callback) {
|
|
436
|
+
clearTimeout(timer); // eslint-disable-line no-undef
|
|
437
|
+
}
|
|
438
|
+
timer = null;
|
|
439
|
+
options.callback.apply(self);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
e.stopPropagation();
|
|
443
|
+
},
|
|
444
|
+
false
|
|
445
|
+
);
|
|
446
|
+
button.addEventListener(
|
|
447
|
+
"mousemove",
|
|
448
|
+
e => {
|
|
449
|
+
e.stopPropagation();
|
|
450
|
+
},
|
|
451
|
+
false
|
|
452
|
+
);
|
|
453
|
+
button.addEventListener(
|
|
454
|
+
"mousedown",
|
|
455
|
+
e => {
|
|
456
|
+
if (!touchstart) {
|
|
457
|
+
if (options.long_callback) {
|
|
458
|
+
timer = setTimeout(() => {
|
|
459
|
+
// eslint-disable-line no-undef
|
|
460
|
+
timer = null;
|
|
461
|
+
options.long_callback.apply(self);
|
|
462
|
+
}, 1500);
|
|
463
|
+
} else {
|
|
464
|
+
timer = true;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
e.stopPropagation();
|
|
468
|
+
},
|
|
469
|
+
false
|
|
470
|
+
);
|
|
471
|
+
button.addEventListener(
|
|
472
|
+
"touchstart",
|
|
473
|
+
e => {
|
|
474
|
+
touchstart = true;
|
|
475
|
+
if (options.long_callback) {
|
|
476
|
+
timer = setTimeout(() => {
|
|
477
|
+
// eslint-disable-line no-undef
|
|
478
|
+
timer = null;
|
|
479
|
+
options.long_callback.apply(self);
|
|
480
|
+
}, 1500);
|
|
481
|
+
} else {
|
|
482
|
+
timer = true;
|
|
483
|
+
}
|
|
484
|
+
e.stopPropagation();
|
|
485
|
+
},
|
|
486
|
+
false
|
|
487
|
+
);
|
|
488
|
+
button.addEventListener(
|
|
489
|
+
"touchend",
|
|
490
|
+
e => {
|
|
491
|
+
if (timer) {
|
|
492
|
+
if (options.long_callback) {
|
|
493
|
+
clearTimeout(timer); // eslint-disable-line no-undef
|
|
494
|
+
}
|
|
495
|
+
timer = null;
|
|
496
|
+
options.callback.apply(self);
|
|
497
|
+
}
|
|
498
|
+
e.stopPropagation();
|
|
499
|
+
},
|
|
500
|
+
false
|
|
501
|
+
);
|
|
502
|
+
button.addEventListener(
|
|
503
|
+
"mouseout",
|
|
504
|
+
e => {
|
|
505
|
+
if (options.long_callback) {
|
|
506
|
+
clearTimeout(timer); // eslint-disable-line no-undef
|
|
507
|
+
}
|
|
508
|
+
timer = null;
|
|
509
|
+
e.stopPropagation();
|
|
510
|
+
},
|
|
511
|
+
false
|
|
512
|
+
);
|
|
513
|
+
button.addEventListener(
|
|
514
|
+
"dblclick",
|
|
515
|
+
e => {
|
|
516
|
+
e.preventDefault();
|
|
517
|
+
},
|
|
518
|
+
false
|
|
519
|
+
);
|
|
520
|
+
|
|
521
|
+
element.className = `${options.cls} ol-unselectable ol-control`;
|
|
522
|
+
element.appendChild(button);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
export class GoHome extends CustomControl {
|
|
527
|
+
constructor(optOptions) {
|
|
528
|
+
const options = optOptions || {};
|
|
529
|
+
options.character = control_settings["home"]
|
|
530
|
+
? `<img src="${control_settings["home"]}">`
|
|
531
|
+
: '<i class="fa fa-home fa-lg"></i>';
|
|
532
|
+
options.cls = "home";
|
|
533
|
+
options.callback = function () {
|
|
534
|
+
const source = this.getMap().getLayers().item(0).getSource();
|
|
535
|
+
source.goHome();
|
|
536
|
+
};
|
|
537
|
+
super(options);
|
|
538
|
+
if (control_settings["home"]) {
|
|
539
|
+
const button = this.element.querySelector("button");
|
|
540
|
+
button.style.backgroundColor = "rgba(0,0,0,0)";
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
export class SetGPS extends CustomControl {
|
|
546
|
+
constructor(optOptions) {
|
|
547
|
+
const options = optOptions || {};
|
|
548
|
+
options.character = control_settings["gps"]
|
|
549
|
+
? `<img src="${control_settings["gps"]}">`
|
|
550
|
+
: '<i class="fa fa-crosshairs fa-lg"></i>';
|
|
551
|
+
options.cls = "gps";
|
|
552
|
+
options.render = function (mapEvent) {
|
|
553
|
+
const frameState = mapEvent.frameState;
|
|
554
|
+
if (!frameState) {
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
const map = this.getMap();
|
|
558
|
+
if (map.geolocation) {
|
|
559
|
+
const tracking = map.geolocation.getTracking();
|
|
560
|
+
const receiving = this.element.classList.contains("disable");
|
|
561
|
+
if (receiving && !tracking) {
|
|
562
|
+
this.element.classList.remove("disable");
|
|
563
|
+
} else if (!receiving && tracking) {
|
|
564
|
+
this.element.classList.add("disable");
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
options.callback = function () {
|
|
570
|
+
const receiving = this.element.classList.contains("disable");
|
|
571
|
+
const map = this.getMap();
|
|
572
|
+
|
|
573
|
+
map.handleGPS(!receiving);
|
|
574
|
+
if (receiving) {
|
|
575
|
+
this.element.classList.remove("disable");
|
|
576
|
+
} else {
|
|
577
|
+
this.element.classList.add("disable");
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
super(options);
|
|
582
|
+
if (control_settings["gps"]) {
|
|
583
|
+
const button = this.element.querySelector("button");
|
|
584
|
+
button.style.backgroundColor = "rgba(0,0,0,0)";
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
export class CompassRotate extends Rotate {
|
|
590
|
+
constructor(optOptions) {
|
|
591
|
+
const options = optOptions || {};
|
|
592
|
+
options.autoHide = false;
|
|
593
|
+
const span = document.createElement("span"); // eslint-disable-line no-undef
|
|
594
|
+
span.innerHTML = control_settings["compass"]
|
|
595
|
+
? `<img src="${control_settings["compass"]}">`
|
|
596
|
+
: '<i class="fa fa-compass fa-lg ol-compass-fa"></i>';
|
|
597
|
+
options.label = span;
|
|
598
|
+
options.render = function (mapEvent) {
|
|
599
|
+
const frameState = mapEvent.frameState;
|
|
600
|
+
if (!frameState) {
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
const view = this.getMap().getView();
|
|
604
|
+
const rotation = frameState.viewState.rotation;
|
|
605
|
+
const center = view.getCenter();
|
|
606
|
+
const zoom = view.getDecimalZoom();
|
|
607
|
+
if (
|
|
608
|
+
rotation != this.rotation_ ||
|
|
609
|
+
center[0] != this.center_[0] ||
|
|
610
|
+
center[1] != this.center_[1] ||
|
|
611
|
+
zoom != this.zoom_
|
|
612
|
+
) {
|
|
613
|
+
const contains = this.element.classList.contains("disable");
|
|
614
|
+
if (!contains && rotation === 0) {
|
|
615
|
+
this.element.classList.add("disable");
|
|
616
|
+
} else if (contains && rotation !== 0) {
|
|
617
|
+
this.element.classList.remove("disable");
|
|
618
|
+
}
|
|
619
|
+
const self = this;
|
|
620
|
+
const layer = this.getMap().getLayers().item(0);
|
|
621
|
+
const source = layer.getSource
|
|
622
|
+
? layer.getSource()
|
|
623
|
+
: layer.getLayers().item(0).getSource();
|
|
624
|
+
if (!source) {
|
|
625
|
+
const transform = "rotate(0rad)";
|
|
626
|
+
self.label_.style.msTransform = transform;
|
|
627
|
+
self.label_.style.webkitTransform = transform;
|
|
628
|
+
self.label_.style.transform = transform;
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
source.viewpoint2MercsAsync().then(mercs => {
|
|
632
|
+
const rot = source.mercs2MercViewpoint(mercs)[2];
|
|
633
|
+
const transform = `rotate(${rot}rad)`;
|
|
634
|
+
self.label_.style.msTransform = transform;
|
|
635
|
+
self.label_.style.webkitTransform = transform;
|
|
636
|
+
self.label_.style.transform = transform;
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
this.rotation_ = rotation;
|
|
640
|
+
this.center_ = center;
|
|
641
|
+
this.zoom_ = zoom;
|
|
642
|
+
};
|
|
643
|
+
super(options);
|
|
644
|
+
if (control_settings["compass"]) {
|
|
645
|
+
const button = this.element.querySelector("button");
|
|
646
|
+
button.style.backgroundColor = "rgba(0,0,0,0)";
|
|
647
|
+
}
|
|
648
|
+
this.center_ = [];
|
|
649
|
+
this.zoom_ = undefined;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
export class Share extends CustomControl {
|
|
654
|
+
constructor(optOptions) {
|
|
655
|
+
const options = optOptions || {};
|
|
656
|
+
options.character = control_settings["share"]
|
|
657
|
+
? `<img src="${control_settings["share"]}">`
|
|
658
|
+
: '<i class="fa fa-share-alt-square fa-lg"></i>';
|
|
659
|
+
options.cls = "ol-share";
|
|
660
|
+
options.callback = function () {
|
|
661
|
+
const map = this.getMap();
|
|
662
|
+
map.dispatchEvent(
|
|
663
|
+
new MapEvent("click_control", map, { control: "share" })
|
|
664
|
+
);
|
|
665
|
+
};
|
|
666
|
+
|
|
667
|
+
super(options);
|
|
668
|
+
if (control_settings["share"]) {
|
|
669
|
+
const button = this.element.querySelector("button");
|
|
670
|
+
button.style.backgroundColor = "rgba(0,0,0,0)";
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
export class Border extends CustomControl {
|
|
676
|
+
constructor(optOptions) {
|
|
677
|
+
const options = optOptions || {};
|
|
678
|
+
options.character = control_settings["border"]
|
|
679
|
+
? `<img src="${control_settings["border"]}">`
|
|
680
|
+
: '<i class="fa fa-clone fa-lg"></i>';
|
|
681
|
+
options.cls = "ol-border";
|
|
682
|
+
options.callback = function () {
|
|
683
|
+
const map = this.getMap();
|
|
684
|
+
map.dispatchEvent(
|
|
685
|
+
new MapEvent("click_control", map, { control: "border" })
|
|
686
|
+
);
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
super(options);
|
|
690
|
+
if (control_settings["border"]) {
|
|
691
|
+
const button = this.element.querySelector("button");
|
|
692
|
+
button.style.backgroundColor = "rgba(0,0,0,0)";
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
export class Maplat extends CustomControl {
|
|
698
|
+
constructor(optOptions) {
|
|
699
|
+
const options = optOptions || {};
|
|
700
|
+
options.character = control_settings["help"]
|
|
701
|
+
? `<img src="${control_settings["help"]}">`
|
|
702
|
+
: '<i class="fa fa-question-circle fa-lg"></i>';
|
|
703
|
+
options.cls = "ol-maplat";
|
|
704
|
+
options.callback = function () {
|
|
705
|
+
const map = this.getMap();
|
|
706
|
+
map.dispatchEvent(
|
|
707
|
+
new MapEvent("click_control", map, { control: "help" })
|
|
708
|
+
);
|
|
709
|
+
};
|
|
710
|
+
|
|
711
|
+
super(options);
|
|
712
|
+
if (control_settings["help"]) {
|
|
713
|
+
const button = this.element.querySelector("button");
|
|
714
|
+
button.style.backgroundColor = "rgba(0,0,0,0)";
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
export class Copyright extends CustomControl {
|
|
720
|
+
constructor(optOptions) {
|
|
721
|
+
const options = optOptions || {};
|
|
722
|
+
options.character = control_settings["attr"]
|
|
723
|
+
? `<img src="${control_settings["attr"]}">`
|
|
724
|
+
: '<i class="fa fa-info-circle fa-lg"></i>';
|
|
725
|
+
options.cls = "ol-copyright";
|
|
726
|
+
options.callback = function () {
|
|
727
|
+
const map = this.getMap();
|
|
728
|
+
map.dispatchEvent(
|
|
729
|
+
new MapEvent("click_control", map, { control: "copyright" })
|
|
730
|
+
);
|
|
731
|
+
};
|
|
732
|
+
|
|
733
|
+
super(options);
|
|
734
|
+
if (control_settings["attr"]) {
|
|
735
|
+
const button = this.element.querySelector("button");
|
|
736
|
+
button.style.backgroundColor = "rgba(0,0,0,0)";
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
export class HideMarker extends CustomControl {
|
|
742
|
+
constructor(optOptions) {
|
|
743
|
+
const options = optOptions || {};
|
|
744
|
+
options.character = control_settings["hide_marker"]
|
|
745
|
+
? `<img src="${control_settings["hide_marker"]}">`
|
|
746
|
+
: '<i class="fa fa-map-marker fa-lg"></i>';
|
|
747
|
+
options.cls = "ol-hide-marker";
|
|
748
|
+
options.callback = function () {
|
|
749
|
+
const map = this.getMap();
|
|
750
|
+
map.dispatchEvent(
|
|
751
|
+
new MapEvent("click_control", map, { control: "hideMarker" })
|
|
752
|
+
);
|
|
753
|
+
};
|
|
754
|
+
options.long_callback = function () {
|
|
755
|
+
const map = this.getMap();
|
|
756
|
+
map.dispatchEvent(
|
|
757
|
+
new MapEvent("click_control", map, { control: "hideLayer" })
|
|
758
|
+
);
|
|
759
|
+
};
|
|
760
|
+
|
|
761
|
+
super(options);
|
|
762
|
+
if (control_settings["hide_marker"]) {
|
|
763
|
+
const button = this.element.querySelector("button");
|
|
764
|
+
button.style.backgroundColor = "rgba(0,0,0,0)";
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
export class Zoom extends BaseZoom {
|
|
770
|
+
constructor(options = {}) {
|
|
771
|
+
if (control_settings["zoom_plus"]) {
|
|
772
|
+
options.zoomInLabel = createElement(
|
|
773
|
+
`<img src="${control_settings["zoom_plus"]}">`
|
|
774
|
+
)[0];
|
|
775
|
+
}
|
|
776
|
+
if (control_settings["zoom_minus"]) {
|
|
777
|
+
options.zoomOutLabel = createElement(
|
|
778
|
+
`<img src="${control_settings["zoom_minus"]}">`
|
|
779
|
+
)[0];
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
super(options);
|
|
783
|
+
if (control_settings["compass"]) {
|
|
784
|
+
const buttons = this.element.querySelectorAll("button");
|
|
785
|
+
buttons.forEach(button => {
|
|
786
|
+
button.style.backgroundColor = "rgba(0,0,0,0)";
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
}
|