@maplat/ui 0.10.6 → 0.11.1

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.
Files changed (176) hide show
  1. package/LICENSE +223 -223
  2. package/README.md +128 -91
  3. package/assets/locales/de/translation.json +71 -0
  4. package/{locales → assets/locales}/en/translation.json +70 -64
  5. package/{locales → assets/locales}/ja/translation.json +70 -64
  6. package/{locales → assets/locales}/ko/translation.json +71 -65
  7. package/assets/locales/vi/translation.json +71 -0
  8. package/{locales → assets/locales}/zh/translation.json +71 -65
  9. package/{locales → assets/locales}/zh-TW/translation.json +71 -65
  10. package/assets/parts/attr.png +0 -0
  11. package/assets/parts/border.png +0 -0
  12. package/assets/parts/compass.png +0 -0
  13. package/assets/parts/gps.png +0 -0
  14. package/assets/parts/help.png +0 -0
  15. package/assets/parts/hide_marker.png +0 -0
  16. package/assets/parts/home.png +0 -0
  17. package/assets/parts/marker_list.png +0 -0
  18. package/assets/parts/share.png +0 -0
  19. package/dist/absolute_url.d.ts +1 -0
  20. package/dist/assets/locales/de/translation.json +71 -0
  21. package/dist/assets/locales/en/translation.json +70 -64
  22. package/dist/assets/locales/ja/translation.json +70 -64
  23. package/dist/assets/locales/ko/translation.json +71 -65
  24. package/dist/assets/locales/vi/translation.json +71 -0
  25. package/dist/assets/locales/zh/translation.json +71 -65
  26. package/dist/assets/locales/zh-TW/translation.json +71 -65
  27. package/dist/contextmenu.d.ts +5 -0
  28. package/dist/function.d.ts +2 -0
  29. package/dist/icons.d.ts +7 -0
  30. package/dist/index.d.ts +65 -0
  31. package/dist/maplat-ui.es.js +33551 -0
  32. package/dist/maplat-ui.umd.js +4934 -0
  33. package/dist/maplat_control.d.ts +55 -0
  34. package/dist/pointer_images.d.ts +2 -0
  35. package/dist/swiper_ex.d.ts +2 -0
  36. package/dist/types.d.ts +185 -0
  37. package/dist/ui_init.d.ts +4 -0
  38. package/dist/ui_marker.d.ts +9 -0
  39. package/dist/ui_utils.d.ts +9 -0
  40. package/less/bootstrap.less +7010 -7010
  41. package/less/contextmenu.css +8 -0
  42. package/less/font-awesome.less +51 -31
  43. package/less/iziToast.less +1732 -1732
  44. package/less/maplat-specific.less +1038 -652
  45. package/less/swiper4.css +715 -0
  46. package/less/ui.less +11 -11
  47. package/less/ui_packed.less +10 -10
  48. package/package.json +80 -79
  49. package/src/{absolute_url.js → absolute_url.ts} +1 -1
  50. package/src/contextmenu/base.ts +170 -0
  51. package/src/contextmenu/constants.ts +66 -0
  52. package/src/contextmenu/cssVars.ts +13 -0
  53. package/src/contextmenu/helpers/dom.ts +295 -0
  54. package/src/contextmenu/helpers/mix.ts +120 -0
  55. package/src/contextmenu/html.ts +161 -0
  56. package/src/contextmenu/internal.ts +293 -0
  57. package/src/contextmenu.ts +40 -0
  58. package/src/function.ts +36 -0
  59. package/src/icons.ts +46 -0
  60. package/src/index.ts +521 -0
  61. package/src/maplat_control.ts +629 -0
  62. package/src/pointer_images.ts +101 -0
  63. package/src/{service-worker.js → service-worker/index.ts} +5 -6
  64. package/src/swiper_augment.d.ts +13 -0
  65. package/src/{swiper_ex.js → swiper_ex.ts} +14 -10
  66. package/src/types.d.ts +31 -0
  67. package/src/types.ts +202 -0
  68. package/src/ui_init.ts +1175 -0
  69. package/src/ui_marker.ts +376 -0
  70. package/src/ui_utils.ts +87 -0
  71. package/dist/assets/fonts/a8c0074cf70b152b56105e6c4b227bd8.woff +0 -0
  72. package/dist/assets/fonts/cfeff2e898a64ebe7e6b5ec078b174c3.woff +0 -0
  73. package/dist/assets/images/09c3ce5a86d600e24f8e85de3a019853.png +0 -0
  74. package/dist/assets/images/0beac2cb41dfab43ddfd9df80b32b85d.png +0 -0
  75. package/dist/assets/images/1354b4f40dd58bb0f2a4871cb4ff81d8.png +0 -0
  76. package/dist/assets/images/2a61e310e46b50b5f8ddd5e905ba9db9.png +0 -0
  77. package/dist/assets/images/3131423d782cd3ea89a81247065e7f9d.png +0 -0
  78. package/dist/assets/images/41b2cf0fa604d3f196ca52337d238219.jpg +0 -0
  79. package/dist/assets/images/558bc7e8b9b6c5f41a7141cddb8cdb5e.png +0 -0
  80. package/dist/assets/images/56f7003805ed02f8a21199947651db2e.png +0 -0
  81. package/dist/assets/images/5ba349e3596aca094c41c56966b45dc7.png +0 -0
  82. package/dist/assets/images/6111b8076a2cf81c73f0e46f41a3af60.png +0 -0
  83. package/dist/assets/images/6345ee67d554fbfbf484ba4035ad19d9.jpg +0 -0
  84. package/dist/assets/images/649fce122b354de2ac725ba5f2661955.png +0 -0
  85. package/dist/assets/images/6a580287dea82c2fb9b214321a375145.png +0 -0
  86. package/dist/assets/images/6c5dba7f7d76e74c3a8c7c5b1c3fc544.png +0 -0
  87. package/dist/assets/images/6e1f2f2f6fed3c5cddeb925e7ae75aba.png +0 -0
  88. package/dist/assets/images/799a0177b0dc540682fa4a2e349a8f4f.png +0 -0
  89. package/dist/assets/images/7bef6f357e921c43f4f800cfcb757872.png +0 -0
  90. package/dist/assets/images/7d9d643a903df6f57b8b7386316021e5.png +0 -0
  91. package/dist/assets/images/7df82bae917b68159f84998182f2fdc6.png +0 -0
  92. package/dist/assets/images/8e5d0335f6598b8d874ba23ea9fb295f.png +0 -0
  93. package/dist/assets/images/90c32e751366be22777f3fe40a53fe06.png +0 -0
  94. package/dist/assets/images/9247459937b9c882303962e42bd8d989.png +0 -0
  95. package/dist/assets/images/927c34e7b9b2f95c82ba477993117eaf.png +0 -0
  96. package/dist/assets/images/95e9ca8285131f8ccb6da5052093173c.png +0 -0
  97. package/dist/assets/images/9a243e0cb0fc43e2a016d5d3aaa330d5.png +0 -0
  98. package/dist/assets/images/9ac6d81f417d6a5626b7c8d5a087c32b.png +0 -0
  99. package/dist/assets/images/9d3a01c866095b8b3e8e63f9cf11dd51.png +0 -0
  100. package/dist/assets/images/9df733bcb29a746cb16b47eedea9fc3a.png +0 -0
  101. package/dist/assets/images/acc6eab0ba9c470ae20fb4b74135e865.png +0 -0
  102. package/dist/assets/images/b9ae27f0a01228380dff76a33b605707.jpg +0 -0
  103. package/dist/assets/images/ba48b220f61a6e1028f1854326f43acd.png +0 -0
  104. package/dist/assets/images/bf67cc860289b85c0402a4d4f890a3bd.png +0 -0
  105. package/dist/assets/images/c49f2344772e33256ba24d64b59b20d1.png +0 -0
  106. package/dist/assets/images/ca6b77b234b18e7bb9b1ccda774da286.png +0 -0
  107. package/dist/assets/images/cd213169df16398b0017450e31788d73.png +0 -0
  108. package/dist/assets/images/f101a0974972eeab41189185a5c5b225.png +0 -0
  109. package/dist/assets/images/f115726e6249018905cca51653e1262c.png +0 -0
  110. package/dist/assets/images/f7acb820d978ab2dd69e8bf695c574d1.png +0 -0
  111. package/dist/assets/images/ffea4dd10bf2506aa1e0cd4c61426b42.png +0 -0
  112. package/dist/assets/maplat.css +0 -19
  113. package/dist/assets/maplat.css.map +0 -1
  114. package/dist/assets/maplat.js +0 -3
  115. package/dist/assets/maplat.js.LICENSE.txt +0 -43
  116. package/dist/assets/maplat.js.map +0 -1
  117. package/dist/index.html +0 -125
  118. package/dist/service-worker.js +0 -3
  119. package/dist/service-worker.js.LICENSE.txt +0 -1
  120. package/dist/service-worker.js.map +0 -1
  121. package/fonts/clarenbd-webfont.woff +0 -0
  122. package/fonts/fontawesome-webfont.woff +0 -0
  123. package/legacy/bootstrap-native.js +0 -1935
  124. package/legacy/detect-element-resize.js +0 -153
  125. package/legacy/iziToast.js +0 -1301
  126. package/legacy/page.js +0 -1153
  127. package/legacy/qrcode.js +0 -616
  128. package/legacy/sprintf.js +0 -285
  129. package/less/font-face.less +0 -11
  130. package/less/font-face_packed.less +0 -11
  131. package/parts/attr.png +0 -0
  132. package/parts/blue_marker.png +0 -0
  133. package/parts/bluedot.png +0 -0
  134. package/parts/bluedot_small.png +0 -0
  135. package/parts/bluedot_transparent.png +0 -0
  136. package/parts/border.png +0 -0
  137. package/parts/compass.png +0 -0
  138. package/parts/defaultpin.png +0 -0
  139. package/parts/defaultpin_selected.png +0 -0
  140. package/parts/gps.png +0 -0
  141. package/parts/gsi.jpg +0 -0
  142. package/parts/gsi_ortho.jpg +0 -0
  143. package/parts/help.png +0 -0
  144. package/parts/hide_marker.png +0 -0
  145. package/parts/home.png +0 -0
  146. package/parts/osm.jpg +0 -0
  147. package/parts/red_marker.png +0 -0
  148. package/parts/redcircle.png +0 -0
  149. package/parts/share.png +0 -0
  150. package/src/contextmenu.js +0 -29
  151. package/src/freeze_locales.js +0 -337
  152. package/src/function.js +0 -22
  153. package/src/index.js +0 -1778
  154. package/src/index_packed.js +0 -8
  155. package/src/maplat_control.js +0 -808
  156. package/src/pointer_images.js +0 -81
  157. /package/{parts → assets/parts}/Maplat.png +0 -0
  158. /package/{parts → assets/parts}/all_right_reserved.png +0 -0
  159. /package/{parts → assets/parts}/basemap.png +0 -0
  160. /package/{parts → assets/parts}/cc0.png +0 -0
  161. /package/{parts → assets/parts}/cc_by-nc-nd.png +0 -0
  162. /package/{parts → assets/parts}/cc_by-nc-sa.png +0 -0
  163. /package/{parts → assets/parts}/cc_by-nc.png +0 -0
  164. /package/{parts → assets/parts}/cc_by-nd.png +0 -0
  165. /package/{parts → assets/parts}/cc_by-sa.png +0 -0
  166. /package/{parts → assets/parts}/cc_by.png +0 -0
  167. /package/{parts → assets/parts}/favicon.png +0 -0
  168. /package/{parts → assets/parts}/fullscreen.png +0 -0
  169. /package/{parts → assets/parts}/loading.png +0 -0
  170. /package/{parts → assets/parts}/loading_image.png +0 -0
  171. /package/{parts → assets/parts}/minus.png +0 -0
  172. /package/{parts → assets/parts}/no_image.png +0 -0
  173. /package/{parts → assets/parts}/overlay.png +0 -0
  174. /package/{parts → assets/parts}/pd.png +0 -0
  175. /package/{parts → assets/parts}/plus.png +0 -0
  176. /package/{parts → assets/parts}/slider.png +0 -0
@@ -1,808 +0,0 @@
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
- if (!this.getMap().northUp) {
614
- const contains = this.element.classList.contains("disable");
615
- if (!contains && rotation === 0) {
616
- this.element.classList.add("disable");
617
- } else if (contains && rotation !== 0) {
618
- this.element.classList.remove("disable");
619
- }
620
- }
621
- const self = this;
622
- const layer = this.getMap().getLayers().item(0);
623
- const source = layer.getSource
624
- ? layer.getSource()
625
- : layer.getLayers().item(0).getSource();
626
- if (!source) {
627
- const transform = "rotate(0rad)";
628
- self.label_.style.msTransform = transform;
629
- self.label_.style.webkitTransform = transform;
630
- self.label_.style.transform = transform;
631
- return;
632
- }
633
- source.viewpoint2MercsAsync().then(mercs => {
634
- const direction = source.mercs2MercViewpoint(mercs)[2];
635
- const transform = `rotate(${direction}rad)`;
636
- self.label_.style.msTransform = transform;
637
- self.label_.style.webkitTransform = transform;
638
- self.label_.style.transform = transform;
639
- if (this.getMap().northUp) {
640
- console.log(direction);
641
- const contains = self.element.classList.contains("disable");
642
- if (!contains && Math.abs(direction) < 0.1) {
643
- self.element.classList.add("disable");
644
- } else if (contains && Math.abs(direction) >= 0.1) {
645
- self.element.classList.remove("disable");
646
- }
647
- }
648
- });
649
- }
650
- this.rotation_ = rotation;
651
- this.center_ = center;
652
- this.zoom_ = zoom;
653
- };
654
- super(options);
655
- if (control_settings["compass"]) {
656
- const button = this.element.querySelector("button");
657
- button.style.backgroundColor = "rgba(0,0,0,0)";
658
- }
659
- this.center_ = [];
660
- this.zoom_ = undefined;
661
- this.callResetNorth_ = () => {
662
- const layer = this.getMap().getLayers().item(0);
663
- const source = layer.getSource
664
- ? layer.getSource()
665
- : layer.getLayers().item(0).getSource();
666
- source.resetCirculation();
667
- };
668
- }
669
- }
670
-
671
- export class Share extends CustomControl {
672
- constructor(optOptions) {
673
- const options = optOptions || {};
674
- options.character = control_settings["share"]
675
- ? `<img src="${control_settings["share"]}">`
676
- : '<i class="fa fa-share-alt-square fa-lg"></i>';
677
- options.cls = "ol-share";
678
- options.callback = function () {
679
- const map = this.getMap();
680
- map.dispatchEvent(
681
- new MapEvent("click_control", map, { control: "share" })
682
- );
683
- };
684
-
685
- super(options);
686
- if (control_settings["share"]) {
687
- const button = this.element.querySelector("button");
688
- button.style.backgroundColor = "rgba(0,0,0,0)";
689
- }
690
- }
691
- }
692
-
693
- export class Border extends CustomControl {
694
- constructor(optOptions) {
695
- const options = optOptions || {};
696
- options.character = control_settings["border"]
697
- ? `<img src="${control_settings["border"]}">`
698
- : '<i class="fa fa-clone fa-lg"></i>';
699
- options.cls = "ol-border";
700
- options.callback = function () {
701
- const map = this.getMap();
702
- map.dispatchEvent(
703
- new MapEvent("click_control", map, { control: "border" })
704
- );
705
- };
706
-
707
- super(options);
708
- if (control_settings["border"]) {
709
- const button = this.element.querySelector("button");
710
- button.style.backgroundColor = "rgba(0,0,0,0)";
711
- }
712
- }
713
- }
714
-
715
- export class Maplat extends CustomControl {
716
- constructor(optOptions) {
717
- const options = optOptions || {};
718
- options.character = control_settings["help"]
719
- ? `<img src="${control_settings["help"]}">`
720
- : '<i class="fa fa-question-circle fa-lg"></i>';
721
- options.cls = "ol-maplat";
722
- options.callback = function () {
723
- const map = this.getMap();
724
- map.dispatchEvent(
725
- new MapEvent("click_control", map, { control: "help" })
726
- );
727
- };
728
-
729
- super(options);
730
- if (control_settings["help"]) {
731
- const button = this.element.querySelector("button");
732
- button.style.backgroundColor = "rgba(0,0,0,0)";
733
- }
734
- }
735
- }
736
-
737
- export class Copyright extends CustomControl {
738
- constructor(optOptions) {
739
- const options = optOptions || {};
740
- options.character = control_settings["attr"]
741
- ? `<img src="${control_settings["attr"]}">`
742
- : '<i class="fa fa-info-circle fa-lg"></i>';
743
- options.cls = "ol-copyright";
744
- options.callback = function () {
745
- const map = this.getMap();
746
- map.dispatchEvent(
747
- new MapEvent("click_control", map, { control: "copyright" })
748
- );
749
- };
750
-
751
- super(options);
752
- if (control_settings["attr"]) {
753
- const button = this.element.querySelector("button");
754
- button.style.backgroundColor = "rgba(0,0,0,0)";
755
- }
756
- }
757
- }
758
-
759
- export class HideMarker extends CustomControl {
760
- constructor(optOptions) {
761
- const options = optOptions || {};
762
- options.character = control_settings["hide_marker"]
763
- ? `<img src="${control_settings["hide_marker"]}">`
764
- : '<i class="fa fa-map-marker fa-lg"></i>';
765
- options.cls = "ol-hide-marker";
766
- options.callback = function () {
767
- const map = this.getMap();
768
- map.dispatchEvent(
769
- new MapEvent("click_control", map, { control: "hideMarker" })
770
- );
771
- };
772
- options.long_callback = function () {
773
- const map = this.getMap();
774
- map.dispatchEvent(
775
- new MapEvent("click_control", map, { control: "hideLayer" })
776
- );
777
- };
778
-
779
- super(options);
780
- if (control_settings["hide_marker"]) {
781
- const button = this.element.querySelector("button");
782
- button.style.backgroundColor = "rgba(0,0,0,0)";
783
- }
784
- }
785
- }
786
-
787
- export class Zoom extends BaseZoom {
788
- constructor(options = {}) {
789
- if (control_settings["zoom_plus"]) {
790
- options.zoomInLabel = createElement(
791
- `<img src="${control_settings["zoom_plus"]}">`
792
- )[0];
793
- }
794
- if (control_settings["zoom_minus"]) {
795
- options.zoomOutLabel = createElement(
796
- `<img src="${control_settings["zoom_minus"]}">`
797
- )[0];
798
- }
799
-
800
- super(options);
801
- if (control_settings["compass"]) {
802
- const buttons = this.element.querySelectorAll("button");
803
- buttons.forEach(button => {
804
- button.style.backgroundColor = "rgba(0,0,0,0)";
805
- });
806
- }
807
- }
808
- }