@maplat/ui 0.10.6 → 0.11.0

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 +64 -0
  31. package/dist/maplat-ui.es.js +9383 -0
  32. package/dist/maplat-ui.umd.js +205 -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 +173 -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 +520 -0
  61. package/src/maplat_control.ts +686 -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 +1066 -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
@@ -0,0 +1,686 @@
1
+ import { Control, Rotate, Zoom as BaseZoom } from "ol/control";
2
+ import { CLASS_UNSELECTABLE, CLASS_CONTROL } from "ol/css";
3
+ import { MapEvent } from "ol";
4
+
5
+ import pointer from "./pointer_images";
6
+ import { createElement, MaplatApp } from "@maplat/core";
7
+ import * as bsn from "bootstrap.native";
8
+ import { getIcon } from "./icons";
9
+ import type { MaplatUi } from "./index";
10
+ import type { ControlOptions } from "./types";
11
+
12
+ export let control_settings: Record<string, string> = {};
13
+ const delegator: { [key: string]: string } = {
14
+ compass: "compass.png",
15
+ border: "border.png",
16
+ attr: "attr.png",
17
+ gps: "gps.png",
18
+ zoom_plus: "plus.png",
19
+ zoom_minus: "minus.png",
20
+ help: "help.png",
21
+ home: "home.png",
22
+ hide_marker: "hide_marker.png",
23
+ marker_list: "marker_list.png",
24
+ share: "share.png",
25
+ slider_in_help: "slider.png",
26
+ favicon: "favicon.png"
27
+ };
28
+
29
+ function hexRgb(hex: string) {
30
+ const ret: { red: number; green: number; blue: number } = {
31
+ red: 0,
32
+ green: 0,
33
+ blue: 0
34
+ };
35
+ if (hex.match(/^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i)) {
36
+ ret.red = parseInt(RegExp.$1, 16);
37
+ ret.green = parseInt(RegExp.$2, 16);
38
+ ret.blue = parseInt(RegExp.$3, 16);
39
+ } else if (hex.match(/^#?([0-9A-F])([0-9A-F])([0-9A-F])$/i)) {
40
+ ret.red = parseInt(`${RegExp.$1}${RegExp.$1}`, 16);
41
+ ret.green = parseInt(`${RegExp.$2}${RegExp.$2}`, 16);
42
+ ret.blue = parseInt(`${RegExp.$3}${RegExp.$3}`, 16);
43
+ }
44
+ return ret;
45
+ }
46
+
47
+ export function setControlSettings(options: Record<string, string>) {
48
+ control_settings = options;
49
+ Object.keys(control_settings).forEach(key => {
50
+ if (delegator[key]) {
51
+ (pointer as Record<string, string>)[delegator[key]] =
52
+ control_settings[key];
53
+ }
54
+ });
55
+ }
56
+
57
+ export class SliderNew extends Control {
58
+ constructor(opt_options: ControlOptions) {
59
+ const options = opt_options ? opt_options : {};
60
+ const containerElement = document.createElement("input");
61
+ containerElement.type = "range";
62
+ containerElement.min = "0";
63
+ containerElement.max = "1";
64
+ const initialValue = options.initialValue || 0;
65
+ containerElement.value = `${1 - initialValue}`;
66
+ containerElement.step = "0.01";
67
+ const render = options.render
68
+ ? options.render
69
+ : function (mapEvent: MapEvent) {
70
+ if (!mapEvent.frameState) return;
71
+ };
72
+ super({
73
+ element: containerElement,
74
+ render
75
+ });
76
+ const className =
77
+ options.className !== undefined ? options.className : "ol-slidernew";
78
+ this.set("slidervalue", initialValue);
79
+
80
+ containerElement.title = options.tipLabel || "";
81
+ containerElement.className = `${className} ${CLASS_UNSELECTABLE} ${CLASS_CONTROL}`;
82
+ containerElement.addEventListener("click", ev => {
83
+ ev.stopPropagation();
84
+ });
85
+ containerElement.addEventListener("pointerdown", ev => {
86
+ ev.stopPropagation();
87
+ });
88
+ containerElement.addEventListener("pointerup", ev => {
89
+ ev.stopPropagation();
90
+ });
91
+
92
+ containerElement.addEventListener("input", _ev => {
93
+ this.set(
94
+ "slidervalue",
95
+ 1 - parseFloat((this.element as HTMLInputElement).value)
96
+ );
97
+ });
98
+
99
+ if (control_settings["slider_color"]) {
100
+ const rgb = hexRgb(control_settings["slider_color"]);
101
+ containerElement.classList.add("ol-slider-originalcolor");
102
+ const sheets = document.styleSheets;
103
+ const sheet = sheets[sheets.length - 1] as CSSStyleSheet;
104
+ try {
105
+ sheet.insertRule(
106
+ `.maplat.with-opacity .ol-slider-originalcolor.${className}::-webkit-slider-thumb {
107
+ background: rgba(${rgb.red},${rgb.green},${rgb.blue}, 0.5);
108
+ }`,
109
+ sheet.cssRules.length
110
+ );
111
+
112
+ sheet.insertRule(
113
+ `.maplat.with-opacity .ol-slider-originalcolor.${className}::-moz-range-thumb {
114
+ background: rgba(${rgb.red},${rgb.green},${rgb.blue}, 0.5);
115
+ }`,
116
+ sheet.cssRules.length
117
+ );
118
+
119
+ sheet.insertRule(
120
+ `.maplat.with-opacity .ol-slider-originalcolor.${className}[disabled]::-webkit-slider-thumb {
121
+ background: rgba(${rgb.red},${rgb.green},${rgb.blue}, 0.2);
122
+ }`,
123
+ sheet.cssRules.length
124
+ );
125
+
126
+ sheet.insertRule(
127
+ `.maplat.with-opacity .ol-slider-originalcolor.${className}[disabled]::-moz-range-thumb {
128
+ background: rgba(${rgb.red},${rgb.green},${rgb.blue}, 0.2);
129
+ }`,
130
+ sheet.cssRules.length
131
+ );
132
+
133
+ sheet.insertRule(
134
+ `.maplat.with-opacity .ol-slider-originalcolor.${className}:not([disabled])::-webkit-slider-thumb:hover {
135
+ background: rgba(${rgb.red},${rgb.green},${rgb.blue}, 0.7);
136
+ }`,
137
+ sheet.cssRules.length
138
+ );
139
+
140
+ sheet.insertRule(
141
+ `.maplat.with-opacity .ol-slider-originalcolor.${className}:not([disabled])::-moz-range-thumb:hover {
142
+ background: rgba(${rgb.red},${rgb.green},${rgb.blue}, 0.7);
143
+ }`,
144
+ sheet.cssRules.length
145
+ );
146
+ } catch (e) {
147
+ console.error(e);
148
+ }
149
+ }
150
+ }
151
+
152
+ setMap(map: import("ol").Map) {
153
+ super.setMap(map);
154
+ if (map) {
155
+ map.render();
156
+ }
157
+ }
158
+
159
+ setEnable(cond: boolean) {
160
+ const elem = this.element as HTMLInputElement;
161
+ if (cond) {
162
+ elem.disabled = false;
163
+ } else {
164
+ elem.disabled = true;
165
+ }
166
+ }
167
+
168
+ setValue(res: number) {
169
+ this.set("slidervalue", res);
170
+ (this.element as HTMLInputElement).value = (1 - res).toString();
171
+ }
172
+ }
173
+
174
+ export class CustomControl extends Control {
175
+ center_: import("ol/coordinate").Coordinate | undefined;
176
+ zoom_: number | undefined;
177
+ callResetNorth_: unknown;
178
+ lastRotation_: number = 0;
179
+ label_!: HTMLElement;
180
+ ui!: MaplatUi;
181
+ moveTo_: boolean = false;
182
+
183
+ constructor(optOptions: ControlOptions) {
184
+ const options: ControlOptions = optOptions || {};
185
+ const element = document.createElement("div");
186
+
187
+ super({
188
+ element,
189
+ target: options.target,
190
+ render: options.render
191
+ });
192
+
193
+ const button = document.createElement("button");
194
+ button.setAttribute("type", "button");
195
+ button.title = options.tipLabel || "";
196
+ const span = document.createElement("span");
197
+ span.innerHTML = options.character || "";
198
+ button.appendChild(span);
199
+ let timer: number | null | undefined | boolean;
200
+ let touchstart: boolean;
201
+
202
+ button.addEventListener("click", e => {
203
+ e.stopPropagation();
204
+ });
205
+ button.addEventListener(
206
+ "mouseup",
207
+ e => {
208
+ if (!touchstart) {
209
+ if (timer) {
210
+ if (options.long_callback) {
211
+ clearTimeout(timer as number);
212
+ }
213
+ timer = null;
214
+ if (options.callback) options.callback.apply(this);
215
+ }
216
+ }
217
+ e.stopPropagation();
218
+ },
219
+ false
220
+ );
221
+ button.addEventListener(
222
+ "mousemove",
223
+ e => {
224
+ e.stopPropagation();
225
+ },
226
+ false
227
+ );
228
+ button.addEventListener(
229
+ "mousedown",
230
+ e => {
231
+ if (!touchstart) {
232
+ if (options.long_callback) {
233
+ timer = window.setTimeout(() => {
234
+ timer = null;
235
+ if (options.long_callback) options.long_callback.apply(this);
236
+ }, 1500);
237
+ } else {
238
+ timer = true;
239
+ }
240
+ }
241
+ e.stopPropagation();
242
+ },
243
+ false
244
+ );
245
+ button.addEventListener(
246
+ "touchstart",
247
+ e => {
248
+ touchstart = true;
249
+ if (options.long_callback) {
250
+ timer = window.setTimeout(() => {
251
+ timer = null;
252
+ if (options.long_callback) options.long_callback.apply(this);
253
+ }, 1500);
254
+ } else {
255
+ timer = true;
256
+ }
257
+ e.stopPropagation();
258
+ },
259
+ false
260
+ );
261
+ button.addEventListener(
262
+ "touchend",
263
+ e => {
264
+ if (timer) {
265
+ if (options.long_callback) {
266
+ clearTimeout(timer as number);
267
+ }
268
+ timer = null;
269
+ if (options.callback) options.callback.apply(this);
270
+ }
271
+ e.stopPropagation();
272
+ },
273
+ false
274
+ );
275
+ button.addEventListener(
276
+ "mouseout",
277
+ e => {
278
+ if (options.long_callback && typeof timer === "number") {
279
+ clearTimeout(timer);
280
+ }
281
+ timer = null;
282
+ e.stopPropagation();
283
+ },
284
+ false
285
+ );
286
+ button.addEventListener(
287
+ "dblclick",
288
+ e => {
289
+ e.preventDefault();
290
+ },
291
+ false
292
+ );
293
+
294
+ element.className = `${options.cls} ol-unselectable ol-control`;
295
+ element.appendChild(button);
296
+ }
297
+ }
298
+
299
+ export class GoHome extends CustomControl {
300
+ constructor(optOptions: ControlOptions) {
301
+ const options: ControlOptions = optOptions || {};
302
+ options.character = control_settings["home"]
303
+ ? `<img src="${control_settings["home"]}">`
304
+ : getIcon("house", "far fa-lg");
305
+ options.cls = "home";
306
+ options.callback = function (this: Control) {
307
+ const map = this.getMap();
308
+ if (map) {
309
+ const source = (
310
+ map.getLayers().item(0) as import("ol/layer").Layer
311
+ ).getSource();
312
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
313
+ if (source && (source as any).goHome) {
314
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
315
+ (source as any).goHome();
316
+ }
317
+ }
318
+ };
319
+ super(options);
320
+ if (control_settings["home"]) {
321
+ const button = this.element.querySelector("button");
322
+ if (button) button.style.backgroundColor = "rgba(0,0,0,0)";
323
+ }
324
+ }
325
+ }
326
+
327
+ export class SetGPS extends CustomControl {
328
+ constructor(optOptions: ControlOptions) {
329
+ const options: ControlOptions = optOptions || {};
330
+ options.character = control_settings["gps"]
331
+ ? `<img src="${control_settings["gps"]}">`
332
+ : getIcon("location-crosshairs", "far fa-lg");
333
+ options.cls = "gps";
334
+ options.render = function (this: SetGPS, mapEvent: MapEvent) {
335
+ const frameState = mapEvent.frameState;
336
+ if (!frameState) {
337
+ return;
338
+ }
339
+ const core = this.ui!.core as MaplatApp;
340
+ if (core && core.getGPSEnabled) {
341
+ const enabled = core.getGPSEnabled();
342
+ const isDisabled = this.element.classList.contains("disable");
343
+
344
+ if (enabled && isDisabled) {
345
+ this.element.classList.remove("disable");
346
+ } else if (!enabled && !isDisabled) {
347
+ this.element.classList.add("disable");
348
+ }
349
+ }
350
+ };
351
+ options.callback = function (this: Control) {
352
+ const self = this as SetGPS;
353
+ const core = self.ui.core as MaplatApp;
354
+
355
+ const currentlyEnabled = core.getGPSEnabled();
356
+
357
+ if (core.alwaysGpsOn) {
358
+ core.handleGPS(true);
359
+ } else {
360
+ core.handleGPS(!currentlyEnabled);
361
+ }
362
+ };
363
+
364
+ super(options);
365
+
366
+ this.ui = options.ui!;
367
+ this.moveTo_ = false;
368
+
369
+ if (this.ui && this.ui.core) {
370
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
371
+ this.ui.core.addEventListener("gps_error", (evt: any) => {
372
+ console.log("GPS Error:", evt);
373
+ const errorMap: Record<string, string> = {
374
+ user_gps_deny: "app.user_gps_deny",
375
+ gps_miss: "app.gps_miss",
376
+ gps_timeout: "app.gps_timeout"
377
+ };
378
+
379
+ if (!this.ui.core) return;
380
+ (this.ui.core.mapDivDocument!.querySelector(
381
+ ".modal_title"
382
+ ) as HTMLElement)!.innerText = this.ui.core.t("app.gps_error");
383
+ (this.ui.core.mapDivDocument!.querySelector(
384
+ ".modal_gpsD_content"
385
+ ) as HTMLElement)!.innerText = this.ui.core.t(
386
+ errorMap[evt.detail] || "app.gps_error"
387
+ );
388
+ const modalElm =
389
+ this.ui.core.mapDivDocument!.querySelector(".modalBase")!;
390
+ const modal = new bsn.Modal(modalElm, {
391
+ root: this.ui.core.mapDivDocument
392
+ });
393
+ this.ui.modalSetting("gpsD");
394
+ modal.show();
395
+ });
396
+
397
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
398
+ this.ui.core.addEventListener("gps_result", (evt: any) => {
399
+ console.log("GPS Result:", evt);
400
+ if (evt.detail && evt.detail.error) {
401
+ const errorMap: Record<string, string> = {
402
+ user_gps_deny: "app.user_gps_deny",
403
+ gps_miss: "app.gps_miss",
404
+ gps_timeout: "app.gps_timeout",
405
+ gps_off: "app.out_of_map"
406
+ };
407
+
408
+ if (!this.ui.core) return;
409
+
410
+ (this.ui.core.mapDivDocument!.querySelector(
411
+ ".modal_title"
412
+ ) as HTMLElement)!.innerText = this.ui.core.t("app.gps_error");
413
+ (this.ui.core.mapDivDocument!.querySelector(
414
+ ".modal_gpsD_content"
415
+ ) as HTMLElement)!.innerText = this.ui.core.t(
416
+ errorMap[evt.detail.error] || "app.gps_error"
417
+ );
418
+ const modalElm =
419
+ this.ui.core.mapDivDocument!.querySelector(".modalBase")!;
420
+ const modal = new bsn.Modal(modalElm, {
421
+ root: this.ui.core.mapDivDocument
422
+ });
423
+ this.ui.modalSetting("gpsD");
424
+ modal.show();
425
+ }
426
+ });
427
+ }
428
+
429
+ if (control_settings["gps"]) {
430
+ const button = this.element.querySelector("button");
431
+ if (button) button.style.backgroundColor = "rgba(0,0,0,0)";
432
+ }
433
+ }
434
+ }
435
+
436
+ export class CompassRotate extends Rotate {
437
+ center_?: import("ol/coordinate").Coordinate;
438
+ zoom_?: number;
439
+ customLabel_: HTMLElement;
440
+ lastRotation_: number = 0;
441
+
442
+ constructor(optOptions: ControlOptions) {
443
+ const options: ControlOptions = optOptions || {};
444
+ options.autoHide = false;
445
+ const span = document.createElement("span");
446
+ span.innerHTML = control_settings["compass"]
447
+ ? `<img src="${control_settings["compass"]}">`
448
+ : getIcon("compass", "far fa-lg ol-compass-fa");
449
+ options.label = span;
450
+ options.render = function (this: CompassRotate, mapEvent: MapEvent) {
451
+ const frameState = mapEvent.frameState;
452
+
453
+ if (!frameState) {
454
+ return;
455
+ }
456
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
457
+ const view = (this.getMap() as any).getView();
458
+ const rotation = frameState.viewState.rotation;
459
+ const center = view.getCenter();
460
+ const zoom = view.getDecimalZoom ? view.getDecimalZoom() : view.getZoom();
461
+ if (
462
+ rotation != this.lastRotation_ ||
463
+ (center &&
464
+ this.center_ &&
465
+ (center[0] != this.center_[0] || center[1] != this.center_[1])) ||
466
+ zoom != this.zoom_
467
+ ) {
468
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
469
+ if (!(this.getMap() as any).northUp) {
470
+ const contains = this.element.classList.contains("disable");
471
+ if (!contains && rotation === 0) {
472
+ this.element.classList.add("disable");
473
+ } else if (contains && rotation !== 0) {
474
+ this.element.classList.remove("disable");
475
+ }
476
+ }
477
+
478
+ const layer = this.getMap()!.getLayers().item(0);
479
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
480
+ const source = (layer as any).getSource
481
+ ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
482
+ (layer as any).getSource()
483
+ : // eslint-disable-next-line @typescript-eslint/no-explicit-any
484
+ (layer as any).getLayers().item(0).getSource();
485
+ if (!source) {
486
+ const transform = "rotate(0rad)";
487
+ this.customLabel_.style.transform = transform;
488
+
489
+ return;
490
+ }
491
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
492
+ if ((source as any).viewpoint2MercsAsync) {
493
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
494
+ (source as any).viewpoint2MercsAsync().then((mercs: any) => {
495
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
496
+ const direction = (source as any).mercs2MercViewpoint(mercs)[2];
497
+ const transform = `rotate(${direction}rad)`;
498
+ this.customLabel_.style.transform = transform;
499
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
500
+ if ((this.getMap() as any).northUp) {
501
+ const contains = this.element.classList.contains("disable");
502
+ if (!contains && Math.abs(direction) < 0.1) {
503
+ this.element.classList.add("disable");
504
+ } else if (contains && Math.abs(direction) >= 0.1) {
505
+ this.element.classList.remove("disable");
506
+ }
507
+ }
508
+ });
509
+ }
510
+ }
511
+ this.lastRotation_ = rotation;
512
+ this.center_ = center;
513
+ this.zoom_ = zoom;
514
+ };
515
+ super(options);
516
+ this.customLabel_ = span;
517
+ }
518
+ }
519
+
520
+ export class Share extends CustomControl {
521
+ constructor(optOptions: ControlOptions) {
522
+ const options: ControlOptions = optOptions || {};
523
+ options.character = control_settings["share"]
524
+ ? `<img src="${control_settings["share"]}">`
525
+ : getIcon("share-from-square", "far fa-lg");
526
+ options.cls = "ol-share";
527
+ options.callback = function (this: Control) {
528
+ const map = this.getMap();
529
+ if (map)
530
+ map.dispatchEvent(
531
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
532
+ new MapEvent("click_control", map, { control: "share" } as any)
533
+ );
534
+ };
535
+
536
+ super(options);
537
+ if (control_settings["share"]) {
538
+ const button = this.element.querySelector("button");
539
+ if (button) button.style.backgroundColor = "rgba(0,0,0,0)";
540
+ }
541
+ }
542
+ }
543
+
544
+ export class Border extends CustomControl {
545
+ constructor(optOptions: ControlOptions) {
546
+ const options: ControlOptions = optOptions || {};
547
+
548
+ options.character = control_settings["border"]
549
+ ? `<img src="${control_settings["border"]}">`
550
+ : getIcon("layer-group", "far fa-lg");
551
+ options.cls = "ol-border";
552
+ options.callback = function (this: Control) {
553
+ const map = this.getMap();
554
+ if (map)
555
+ map.dispatchEvent(
556
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
557
+ new MapEvent("click_control", map, { control: "border" } as any)
558
+ );
559
+ };
560
+
561
+ super(options);
562
+ if (control_settings["border"]) {
563
+ const button = this.element.querySelector("button");
564
+ if (button) button.style.backgroundColor = "rgba(0,0,0,0)";
565
+ }
566
+ }
567
+ }
568
+
569
+ export class Maplat extends CustomControl {
570
+ constructor(optOptions: ControlOptions) {
571
+ const options: ControlOptions = optOptions || {};
572
+ options.character = control_settings["help"]
573
+ ? `<img src="${control_settings["help"]}">`
574
+ : getIcon("circle-question", "far fa-lg");
575
+ options.cls = "ol-maplat";
576
+ options.callback = function (this: Control) {
577
+ const map = this.getMap();
578
+ if (map)
579
+ map.dispatchEvent(
580
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
581
+ new MapEvent("click_control", map, { control: "help" } as any)
582
+ );
583
+ };
584
+
585
+ super(options);
586
+ if (control_settings["help"]) {
587
+ const button = this.element.querySelector("button");
588
+ if (button) button.style.backgroundColor = "rgba(0,0,0,0)";
589
+ }
590
+ }
591
+ }
592
+
593
+ export class Copyright extends CustomControl {
594
+ constructor(optOptions: ControlOptions) {
595
+ const options: ControlOptions = optOptions || {};
596
+ options.character = control_settings["attr"]
597
+ ? `<img src="${control_settings["attr"]}">`
598
+ : getIcon("circle-info", "far fa-lg");
599
+ options.cls = "ol-copyright";
600
+ options.callback = function (this: Control) {
601
+ const map = this.getMap();
602
+ if (map)
603
+ map.dispatchEvent(
604
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
605
+ new MapEvent("click_control", map, { control: "copyright" } as any)
606
+ );
607
+ };
608
+
609
+ super(options);
610
+ if (control_settings["attr"]) {
611
+ const button = this.element.querySelector("button");
612
+ if (button) button.style.backgroundColor = "rgba(0,0,0,0)";
613
+ }
614
+ }
615
+ }
616
+
617
+ export class HideMarker extends CustomControl {
618
+ constructor(optOptions: ControlOptions) {
619
+ const options: ControlOptions = optOptions || {};
620
+ options.character = control_settings["hide_marker"]
621
+ ? `<img src="${control_settings["hide_marker"]}">`
622
+ : getIcon("map-pin", "far fa-lg");
623
+ options.cls = "ol-hide-marker";
624
+ options.callback = function (this: Control) {
625
+ const map = this.getMap();
626
+ if (map)
627
+ map.dispatchEvent(
628
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
629
+ new MapEvent("click_control", map, { control: "hideMarker" } as any)
630
+ );
631
+ };
632
+
633
+ super(options);
634
+ if (control_settings["hide_marker"]) {
635
+ const button = this.element.querySelector("button");
636
+ if (button) button.style.backgroundColor = "rgba(0,0,0,0)";
637
+ }
638
+ }
639
+ }
640
+
641
+ export class MarkerList extends CustomControl {
642
+ constructor(optOptions: ControlOptions) {
643
+ const options: ControlOptions = optOptions || {};
644
+ options.character = control_settings["marker_list"]
645
+ ? `<img src="${control_settings["marker_list"]}">`
646
+ : getIcon("list", "far fa-lg");
647
+ options.cls = "ol-marker-list";
648
+ options.callback = function (this: Control) {
649
+ const map = this.getMap();
650
+ if (map)
651
+ map.dispatchEvent(
652
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
653
+ new MapEvent("click_control", map, { control: "markerList" } as any)
654
+ );
655
+ };
656
+
657
+ super(options);
658
+ if (control_settings["marker_list"]) {
659
+ const button = this.element.querySelector("button");
660
+ if (button) button.style.backgroundColor = "rgba(0,0,0,0)";
661
+ }
662
+ }
663
+ }
664
+
665
+ export class Zoom extends BaseZoom {
666
+ constructor(options: ControlOptions = {}) {
667
+ if (control_settings["zoom_plus"]) {
668
+ options.zoomInLabel = createElement(
669
+ `<img src="${control_settings["zoom_plus"]}">`
670
+ )[0] as HTMLElement;
671
+ }
672
+ if (control_settings["zoom_minus"]) {
673
+ options.zoomOutLabel = createElement(
674
+ `<img src="${control_settings["zoom_minus"]}">`
675
+ )[0] as HTMLElement;
676
+ }
677
+
678
+ super(options);
679
+ if (control_settings["compass"]) {
680
+ const buttons = this.element.querySelectorAll("button");
681
+ buttons.forEach(button => {
682
+ button.style.backgroundColor = "rgba(0,0,0,0)";
683
+ });
684
+ }
685
+ }
686
+ }