@maplat/ui 0.10.5 → 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 (173) hide show
  1. package/README.md +38 -1
  2. package/assets/locales/de/translation.json +71 -0
  3. package/{locales → assets/locales}/en/translation.json +12 -6
  4. package/{locales → assets/locales}/ja/translation.json +12 -6
  5. package/{locales → assets/locales}/ko/translation.json +12 -6
  6. package/assets/locales/vi/translation.json +71 -0
  7. package/{locales → assets/locales}/zh/translation.json +12 -6
  8. package/{locales → assets/locales}/zh-TW/translation.json +12 -6
  9. package/assets/parts/attr.png +0 -0
  10. package/assets/parts/border.png +0 -0
  11. package/assets/parts/compass.png +0 -0
  12. package/assets/parts/gps.png +0 -0
  13. package/assets/parts/help.png +0 -0
  14. package/assets/parts/hide_marker.png +0 -0
  15. package/assets/parts/home.png +0 -0
  16. package/assets/parts/marker_list.png +0 -0
  17. package/assets/parts/share.png +0 -0
  18. package/dist/absolute_url.d.ts +1 -0
  19. package/dist/assets/locales/de/translation.json +71 -0
  20. package/dist/assets/locales/en/translation.json +12 -6
  21. package/dist/assets/locales/ja/translation.json +12 -6
  22. package/dist/assets/locales/ko/translation.json +12 -6
  23. package/dist/assets/locales/vi/translation.json +71 -0
  24. package/dist/assets/locales/zh/translation.json +12 -6
  25. package/dist/assets/locales/zh-TW/translation.json +12 -6
  26. package/dist/contextmenu.d.ts +5 -0
  27. package/dist/function.d.ts +2 -0
  28. package/dist/icons.d.ts +7 -0
  29. package/dist/index.d.ts +64 -0
  30. package/dist/maplat-ui.es.js +9383 -0
  31. package/dist/maplat-ui.umd.js +205 -0
  32. package/dist/maplat_control.d.ts +55 -0
  33. package/dist/pointer_images.d.ts +2 -0
  34. package/dist/swiper_ex.d.ts +2 -0
  35. package/dist/types.d.ts +173 -0
  36. package/dist/ui_init.d.ts +4 -0
  37. package/dist/ui_marker.d.ts +9 -0
  38. package/dist/ui_utils.d.ts +9 -0
  39. package/less/contextmenu.css +8 -0
  40. package/less/font-awesome.less +48 -28
  41. package/less/maplat-specific.less +452 -66
  42. package/less/swiper4.css +715 -0
  43. package/less/ui.less +5 -5
  44. package/less/ui_packed.less +3 -3
  45. package/package.json +107 -106
  46. package/src/{absolute_url.js → absolute_url.ts} +1 -1
  47. package/src/contextmenu/base.ts +170 -0
  48. package/src/contextmenu/constants.ts +66 -0
  49. package/src/contextmenu/cssVars.ts +13 -0
  50. package/src/contextmenu/helpers/dom.ts +295 -0
  51. package/src/contextmenu/helpers/mix.ts +120 -0
  52. package/src/contextmenu/html.ts +161 -0
  53. package/src/contextmenu/internal.ts +293 -0
  54. package/src/contextmenu.ts +40 -0
  55. package/src/function.ts +36 -0
  56. package/src/icons.ts +46 -0
  57. package/src/index.ts +520 -0
  58. package/src/maplat_control.ts +686 -0
  59. package/src/pointer_images.ts +101 -0
  60. package/src/{service-worker.js → service-worker/index.ts} +5 -6
  61. package/src/swiper_augment.d.ts +13 -0
  62. package/src/{swiper_ex.js → swiper_ex.ts} +14 -10
  63. package/src/types.d.ts +31 -0
  64. package/src/types.ts +202 -0
  65. package/src/ui_init.ts +1066 -0
  66. package/src/ui_marker.ts +376 -0
  67. package/src/ui_utils.ts +87 -0
  68. package/dist/assets/fonts/a8c0074cf70b152b56105e6c4b227bd8.woff +0 -0
  69. package/dist/assets/fonts/cfeff2e898a64ebe7e6b5ec078b174c3.woff +0 -0
  70. package/dist/assets/images/09c3ce5a86d600e24f8e85de3a019853.png +0 -0
  71. package/dist/assets/images/0beac2cb41dfab43ddfd9df80b32b85d.png +0 -0
  72. package/dist/assets/images/1354b4f40dd58bb0f2a4871cb4ff81d8.png +0 -0
  73. package/dist/assets/images/2a61e310e46b50b5f8ddd5e905ba9db9.png +0 -0
  74. package/dist/assets/images/3131423d782cd3ea89a81247065e7f9d.png +0 -0
  75. package/dist/assets/images/41b2cf0fa604d3f196ca52337d238219.jpg +0 -0
  76. package/dist/assets/images/558bc7e8b9b6c5f41a7141cddb8cdb5e.png +0 -0
  77. package/dist/assets/images/56f7003805ed02f8a21199947651db2e.png +0 -0
  78. package/dist/assets/images/5ba349e3596aca094c41c56966b45dc7.png +0 -0
  79. package/dist/assets/images/6111b8076a2cf81c73f0e46f41a3af60.png +0 -0
  80. package/dist/assets/images/6345ee67d554fbfbf484ba4035ad19d9.jpg +0 -0
  81. package/dist/assets/images/649fce122b354de2ac725ba5f2661955.png +0 -0
  82. package/dist/assets/images/6a580287dea82c2fb9b214321a375145.png +0 -0
  83. package/dist/assets/images/6c5dba7f7d76e74c3a8c7c5b1c3fc544.png +0 -0
  84. package/dist/assets/images/6e1f2f2f6fed3c5cddeb925e7ae75aba.png +0 -0
  85. package/dist/assets/images/799a0177b0dc540682fa4a2e349a8f4f.png +0 -0
  86. package/dist/assets/images/7bef6f357e921c43f4f800cfcb757872.png +0 -0
  87. package/dist/assets/images/7d9d643a903df6f57b8b7386316021e5.png +0 -0
  88. package/dist/assets/images/7df82bae917b68159f84998182f2fdc6.png +0 -0
  89. package/dist/assets/images/8e5d0335f6598b8d874ba23ea9fb295f.png +0 -0
  90. package/dist/assets/images/90c32e751366be22777f3fe40a53fe06.png +0 -0
  91. package/dist/assets/images/9247459937b9c882303962e42bd8d989.png +0 -0
  92. package/dist/assets/images/927c34e7b9b2f95c82ba477993117eaf.png +0 -0
  93. package/dist/assets/images/95e9ca8285131f8ccb6da5052093173c.png +0 -0
  94. package/dist/assets/images/9a243e0cb0fc43e2a016d5d3aaa330d5.png +0 -0
  95. package/dist/assets/images/9ac6d81f417d6a5626b7c8d5a087c32b.png +0 -0
  96. package/dist/assets/images/9d3a01c866095b8b3e8e63f9cf11dd51.png +0 -0
  97. package/dist/assets/images/9df733bcb29a746cb16b47eedea9fc3a.png +0 -0
  98. package/dist/assets/images/acc6eab0ba9c470ae20fb4b74135e865.png +0 -0
  99. package/dist/assets/images/b9ae27f0a01228380dff76a33b605707.jpg +0 -0
  100. package/dist/assets/images/ba48b220f61a6e1028f1854326f43acd.png +0 -0
  101. package/dist/assets/images/bf67cc860289b85c0402a4d4f890a3bd.png +0 -0
  102. package/dist/assets/images/c49f2344772e33256ba24d64b59b20d1.png +0 -0
  103. package/dist/assets/images/ca6b77b234b18e7bb9b1ccda774da286.png +0 -0
  104. package/dist/assets/images/cd213169df16398b0017450e31788d73.png +0 -0
  105. package/dist/assets/images/f101a0974972eeab41189185a5c5b225.png +0 -0
  106. package/dist/assets/images/f115726e6249018905cca51653e1262c.png +0 -0
  107. package/dist/assets/images/f7acb820d978ab2dd69e8bf695c574d1.png +0 -0
  108. package/dist/assets/images/ffea4dd10bf2506aa1e0cd4c61426b42.png +0 -0
  109. package/dist/assets/maplat.css +0 -19
  110. package/dist/assets/maplat.css.map +0 -1
  111. package/dist/assets/maplat.js +0 -3
  112. package/dist/assets/maplat.js.LICENSE.txt +0 -43
  113. package/dist/assets/maplat.js.map +0 -1
  114. package/dist/index.html +0 -39
  115. package/dist/service-worker.js +0 -3
  116. package/dist/service-worker.js.LICENSE.txt +0 -1
  117. package/dist/service-worker.js.map +0 -1
  118. package/fonts/clarenbd-webfont.woff +0 -0
  119. package/fonts/fontawesome-webfont.woff +0 -0
  120. package/legacy/bootstrap-native.js +0 -1935
  121. package/legacy/detect-element-resize.js +0 -153
  122. package/legacy/iziToast.js +0 -1301
  123. package/legacy/page.js +0 -1153
  124. package/legacy/qrcode.js +0 -616
  125. package/legacy/sprintf.js +0 -285
  126. package/less/font-face.less +0 -11
  127. package/less/font-face_packed.less +0 -11
  128. package/parts/attr.png +0 -0
  129. package/parts/blue_marker.png +0 -0
  130. package/parts/bluedot.png +0 -0
  131. package/parts/bluedot_small.png +0 -0
  132. package/parts/bluedot_transparent.png +0 -0
  133. package/parts/border.png +0 -0
  134. package/parts/compass.png +0 -0
  135. package/parts/defaultpin.png +0 -0
  136. package/parts/defaultpin_selected.png +0 -0
  137. package/parts/gps.png +0 -0
  138. package/parts/gsi.jpg +0 -0
  139. package/parts/gsi_ortho.jpg +0 -0
  140. package/parts/help.png +0 -0
  141. package/parts/hide_marker.png +0 -0
  142. package/parts/home.png +0 -0
  143. package/parts/osm.jpg +0 -0
  144. package/parts/red_marker.png +0 -0
  145. package/parts/redcircle.png +0 -0
  146. package/parts/share.png +0 -0
  147. package/src/contextmenu.js +0 -29
  148. package/src/freeze_locales.js +0 -337
  149. package/src/function.js +0 -22
  150. package/src/index.js +0 -1762
  151. package/src/index_packed.js +0 -8
  152. package/src/maplat_control.js +0 -814
  153. package/src/pointer_images.js +0 -81
  154. /package/{parts → assets/parts}/Maplat.png +0 -0
  155. /package/{parts → assets/parts}/all_right_reserved.png +0 -0
  156. /package/{parts → assets/parts}/basemap.png +0 -0
  157. /package/{parts → assets/parts}/cc0.png +0 -0
  158. /package/{parts → assets/parts}/cc_by-nc-nd.png +0 -0
  159. /package/{parts → assets/parts}/cc_by-nc-sa.png +0 -0
  160. /package/{parts → assets/parts}/cc_by-nc.png +0 -0
  161. /package/{parts → assets/parts}/cc_by-nd.png +0 -0
  162. /package/{parts → assets/parts}/cc_by-sa.png +0 -0
  163. /package/{parts → assets/parts}/cc_by.png +0 -0
  164. /package/{parts → assets/parts}/favicon.png +0 -0
  165. /package/{parts → assets/parts}/fullscreen.png +0 -0
  166. /package/{parts → assets/parts}/loading.png +0 -0
  167. /package/{parts → assets/parts}/loading_image.png +0 -0
  168. /package/{parts → assets/parts}/minus.png +0 -0
  169. /package/{parts → assets/parts}/no_image.png +0 -0
  170. /package/{parts → assets/parts}/overlay.png +0 -0
  171. /package/{parts → assets/parts}/pd.png +0 -0
  172. /package/{parts → assets/parts}/plus.png +0 -0
  173. /package/{parts → assets/parts}/slider.png +0 -0
package/src/index.js DELETED
@@ -1,1762 +0,0 @@
1
- import { absoluteUrl } from "./absolute_url";
2
- import { Swiper } from "./swiper_ex";
3
- import { Navigation, Pagination } from "swiper";
4
- import EventTarget from "ol/events/Target";
5
- import page from "../legacy/page";
6
- import bsn from "../legacy/bootstrap-native";
7
- import { MaplatApp as Core, createElement } from "@maplat/core";
8
- import ContextMenu from "./contextmenu";
9
- import iziToast from "../legacy/iziToast";
10
- import QRCode from "../legacy/qrcode";
11
- import { point, polygon } from "@turf/helpers";
12
- import booleanPointInPolygon from "@turf/boolean-point-in-polygon";
13
- import sprintf from "../legacy/sprintf";
14
- import { META_KEYS } from "@maplat/core/lib/source/mixin";
15
- import {
16
- Copyright,
17
- CompassRotate,
18
- SetGPS,
19
- GoHome,
20
- Maplat,
21
- Border,
22
- HideMarker,
23
- SliderCommon,
24
- Share,
25
- Zoom,
26
- setControlSettings
27
- } from "./maplat_control";
28
- import { asArray } from "ol/color";
29
- import { HistMap } from "@maplat/core/lib/source/histmap";
30
- import { TmsMap } from "@maplat/core/lib/source/tmsmap";
31
- import { NowMap } from "@maplat/core/lib/source/nowmap";
32
- import Weiwudi from "weiwudi";
33
- import { normalizeArg } from "./function";
34
- import pointer from "./pointer_images";
35
- Swiper.use([Navigation, Pagination]);
36
-
37
- // Maplat UI Class
38
- export class MaplatUi extends EventTarget {
39
- constructor(appOption) {
40
- super();
41
- appOption = normalizeArg(appOption);
42
- if (appOption.control) {
43
- setControlSettings(appOption.control);
44
- }
45
-
46
- const ui = this;
47
- ui.html_id_seed = `${Math.floor(Math.random() * 9000) + 1000}`;
48
-
49
- if (appOption.stateUrl) {
50
- page((ctx, _next) => {
51
- let pathes = ctx.canonicalPath.split("#!");
52
- let path = pathes.length > 1 ? pathes[1] : pathes[0];
53
- pathes = path.split("?");
54
- path = pathes[0];
55
- if (path === ui.pathThatSet) {
56
- delete ui.pathThatSet;
57
- return;
58
- }
59
- const restore = {
60
- transparency: 0,
61
- position: {
62
- rotation: 0
63
- }
64
- };
65
- path.split("/").map(state => {
66
- const line = state.split(":");
67
- switch (line[0]) {
68
- case "s":
69
- restore.mapID = line[1];
70
- break;
71
- case "b":
72
- restore.backgroundID = line[1];
73
- break;
74
- case "t":
75
- restore.transparency = parseFloat(line[1]);
76
- break;
77
- case "r":
78
- restore.position.rotation = parseFloat(line[1]);
79
- break;
80
- case "z":
81
- restore.position.zoom = parseFloat(line[1]);
82
- break;
83
- case "x":
84
- case "y":
85
- restore.position[line[0]] = parseFloat(line[1]);
86
- break;
87
- case "sb":
88
- restore.showBorder = !!parseInt(line[1]);
89
- break;
90
- case "hm":
91
- restore.hideMarker = !!parseInt(line[1]);
92
- break;
93
- case "hl":
94
- restore.hideLayer = line[1];
95
- break;
96
- case "c":
97
- if (ui.core) {
98
- const modalElm =
99
- ui.core.mapDivDocument.querySelector(".modalBase");
100
- const modal = new bsn.Modal(modalElm, {
101
- root: ui.core.mapDivDocument
102
- });
103
- modal.hide();
104
- }
105
- }
106
- });
107
- if (!ui.core) {
108
- if (restore.mapID) {
109
- appOption.restore = restore;
110
- }
111
- ui.initializer(appOption);
112
- } else if (restore.mapID) {
113
- ui.core.waitReady.then(() => {
114
- ui.core.changeMap(restore.mapID, restore);
115
- });
116
- }
117
- });
118
- page({
119
- hashbang: true
120
- });
121
- page();
122
- ui.waitReady = new Promise((resolve, _reject) => {
123
- ui.waitReadyBridge = resolve;
124
- });
125
- } else {
126
- ui.initializer(appOption);
127
- }
128
- }
129
-
130
- async initializer(appOption) {
131
- const ui = this;
132
- appOption.translateUI = true;
133
- ui.core = new Core(appOption);
134
- if (appOption.icon) {
135
- pointer["defaultpin.png"] = appOption.icon;
136
- }
137
-
138
- if (appOption.restore) {
139
- ui.setShowBorder(appOption.restore.showBorder || false);
140
- if (appOption.restore.hideMarker) {
141
- ui.core.mapDivDocument.classList.add("hide-marker");
142
- }
143
- } else if (appOption.restoreSession) {
144
- const lastEpoch = parseInt(localStorage.getItem("epoch") || 0); // eslint-disable-line no-undef
145
- const currentTime = Math.floor(new Date().getTime() / 1000);
146
- if (lastEpoch && currentTime - lastEpoch < 3600) {
147
- ui.setShowBorder(!!parseInt(localStorage.getItem("showBorder") || "0")); // eslint-disable-line no-undef
148
- }
149
- if (ui.core.initialRestore.hideMarker) {
150
- ui.core.mapDivDocument.classList.add("hide-marker");
151
- }
152
- } else {
153
- ui.setShowBorder(false);
154
- }
155
-
156
- const enableSplash = !ui.core.initialRestore.mapID;
157
- const restoreTransparency = ui.core.initialRestore.transparency;
158
- const enableOutOfMap = !appOption.presentation_mode;
159
-
160
- if (appOption.enableShare) {
161
- ui.core.mapDivDocument.classList.add("enable_share");
162
- ui.enableShare = true;
163
- }
164
- if (appOption.enableHideMarker) {
165
- ui.core.mapDivDocument.classList.add("enable_hide_marker");
166
- ui.enableHideMarker = true;
167
- }
168
- if (appOption.enableBorder) {
169
- ui.core.mapDivDocument.classList.add("enable_border");
170
- ui.enableBorder = true;
171
- }
172
- if (appOption.disableNoimage) {
173
- ui.disableNoimage = true;
174
- }
175
- if (appOption.stateUrl) {
176
- ui.core.mapDivDocument.classList.add("state_url");
177
- }
178
- if (ui.core.enableCache) {
179
- ui.core.mapDivDocument.classList.add("enable_cache");
180
- }
181
- if ("ontouchstart" in window) {
182
- // eslint-disable-line no-undef
183
- ui.core.mapDivDocument.classList.add("ol-touch");
184
- ui.isTouch = true;
185
- }
186
- if (appOption.mobileIF) {
187
- appOption.debug = true;
188
- }
189
- if (appOption.appEnvelope) {
190
- ui.appEnvelope = true;
191
- }
192
- if (appOption.northTop) {
193
- ui.northTop = true;
194
- }
195
-
196
- let pwaManifest = appOption.pwaManifest;
197
- let pwaWorker = appOption.pwaWorker;
198
- let pwaScope = appOption.pwaScope;
199
-
200
- // Add UI HTML Element
201
- let newElems = createElement(`<d c="ol-control map-title"><s></s></d>
202
- <d c="swiper-container ol-control base-swiper prevent-default-ui">
203
- <d c="swiper-wrapper"></d>
204
- <d c="swiper-button-next base-next swiper-button-white"></d>
205
- <d c="swiper-button-prev base-prev swiper-button-white"></d>
206
- </d>
207
- <d c="swiper-container ol-control overlay-swiper prevent-default-ui">
208
- <d c="swiper-wrapper"></d>
209
- <d c="swiper-button-next overlay-next swiper-button-white"></d>
210
- <d c="swiper-button-prev overlay-prev swiper-button-white"></d>
211
- </d> `);
212
- for (let i = newElems.length - 1; i >= 0; i--) {
213
- ui.core.mapDivDocument.insertBefore(
214
- newElems[i],
215
- ui.core.mapDivDocument.firstChild
216
- );
217
- }
218
- const prevDefs = ui.core.mapDivDocument.querySelectorAll(
219
- ".prevent-default-ui"
220
- );
221
- for (let i = 0; i < prevDefs.length; i++) {
222
- const target = prevDefs[i];
223
- target.addEventListener("touchstart", evt => {
224
- evt.preventDefault();
225
- });
226
- }
227
-
228
- newElems = createElement(`<d c="modal modalBase" tabindex="-1" role="dialog"
229
- aria-labelledby="staticModalLabel" aria-hidden="true" data-show="true" data-keyboard="false"
230
- data-backdrop="static">
231
- <d c="modal-dialog">
232
- <d c="modal-content">
233
- <d c="modal-header">
234
- <button type="button" c="close" data-dismiss="modal">
235
- <s aria-hidden="true">&#215;</s><s c="sr-only" din="html.close"></s>
236
- </button>
237
- <h4 c="modal-title">
238
-
239
- <s c="modal_title"></s>
240
- <s c="modal_load_title"></s>
241
- <s c="modal_gpsW_title" din="html.acquiring_gps"></s>
242
- <s c="modal_help_title" din="html.help_title"></s>
243
- <s c="modal_share_title" din="html.share_title"></s>
244
- <s c="modal_hide_marker_title" din="html.hide_marker_title"></s>
245
-
246
- </h4>
247
- </d>
248
- <d c="modal-body">
249
-
250
- <d c="modal_help_content">
251
- <d c="help_content">
252
- <s dinh="html.help_using_maplat"></s>
253
- <p c="col-xs-12 help_img"><img src="${
254
- pointer["fullscreen.png"]
255
- }"></p>
256
- <h4 din="html.help_operation_title"></h4>
257
- <p dinh="html.help_operation_content" c="recipient"></p>
258
- <h4 din="html.help_selection_title"></h4>
259
- <p dinh="html.help_selection_content" c="recipient"></p>
260
- <h4 din="html.help_gps_title"></h4>
261
- <p dinh="html.help_gps_content" c="recipient"></p>
262
- <h4 din="html.help_poi_title"></h4>
263
- <p dinh="html.help_poi_content" c="recipient"></p>
264
- <h4 din="html.help_etc_title"></h4>
265
- <ul>
266
- <li dinh="html.help_etc_attr" c="recipient"></li>
267
- <li dinh="html.help_etc_help" c="recipient"></li>
268
- <s c="share_help"><li dinh="html.help_share_help" c="recipient"></li></s>
269
- <s c="border_help"><li dinh="html.help_etc_border" c="recipient"></li></s>
270
- <s c="hide_marker_help"><li dinh="html.help_etc_hide_marker" c="recipient"></li></s>
271
- <li dinh="html.help_etc_slider" c="recipient"></li>
272
- </ul>
273
- <p><a href="https://github.com/code4history/Maplat/wiki" target="_blank">Maplat</a>
274
- © 2015- Kohei Otsuka, Code for History</p>
275
- </d>
276
- </d>
277
-
278
- <d c="modal_poi_content">
279
- <d c="poi_web embed-responsive embed-responsive-60vh">
280
- <iframe c="poi_iframe iframe_poi" frameborder="0" src=""></iframe>
281
- </d>
282
- <d c="poi_data hide">
283
- <d c="col-xs-12 swiper-container poi_img_swiper">
284
- <d c="swiper-wrapper"></d>
285
- <d c="swiper-pagination poi-pagination"></d>
286
- <d c="swiper-button-next poi-img-next"></d>
287
- <d c="swiper-button-prev poi-img-prev"></d>
288
- </d>
289
- <p c="recipient poi_address"></p>
290
- <p c="recipient poi_desc"></p>
291
- </d>
292
- </d>
293
-
294
- <d c="modal_share_content">
295
- <h4 din="html.share_app_title"></h4>
296
- <d id="___maplat_app_toast_${ui.html_id_seed}"></d>
297
- <d c="recipient row">
298
- <d c="form-group col-xs-4 text-center"><button title="Copy to clipboard" c="share btn btn-light" data="cp_app"><i c="fa fa-clipboard"></i>&nbsp;<small din="html.share_copy"></small></button></d>
299
- <d c="form-group col-xs-4 text-center"><button title="Twitter" c="share btn btn-light" data="tw_app"><i c="fa fa-twitter"></i>&nbsp;<small>Twitter</small></button></d>
300
- <d c="form-group col-xs-4 text-center"><button title="Facebook" c="share btn btn-light" data="fb_app"><i c="fa fa-facebook"></i>&nbsp;<small>Facebook</small></button></d>
301
- </d>
302
- <d c="qr_app center-block" style="width:128px;"></d>
303
- <d c="modal_share_state">
304
- <h4 din="html.share_state_title"></h4>
305
- <d id="___maplat_view_toast_${ui.html_id_seed}"></d>
306
- <d c="recipient row">
307
- <d c="form-group col-xs-4 text-center"><button title="Copy to clipboard" c="share btn btn-light" data="cp_view"><i c="fa fa-clipboard"></i>&nbsp;<small din="html.share_copy"></small></button></d>
308
- <d c="form-group col-xs-4 text-center"><button title="Twitter" c="share btn btn-light" data="tw_view"><i c="fa fa-twitter"></i>&nbsp;<small>Twitter</small></button></d>
309
- <d c="form-group col-xs-4 text-center"><button title="Facebook" c="share btn btn-light" data="fb_view"><i c="fa fa-facebook"></i>&nbsp;<small>Facebook</small></button></d>
310
- </d>
311
- <d c="qr_view center-block" style="width:128px;"></d>
312
- </d>
313
- <p><img src="" height="0px" width="0px"></p>
314
- </d>
315
-
316
- <d c="modal_map_content">
317
- ${META_KEYS.map(key => {
318
- if (key == "title" || key == "officialTitle") return "";
319
- return `<d c="recipients ${key}_div"><dl c="dl-horizontal">
320
- <dt din="html.${key}"></dt>
321
- <dd c="${key}_dd"></dd>
322
- </dl></d> `;
323
- }).join("")}
324
- <d c="recipients modal_cache_content"><dl c="dl-horizontal">
325
- <dt din="html.cache_handle"></dt>
326
- <dd><s c="cache_size"></s></dd>
327
- <dt></dt>
328
- <dd><s c="pull-right"><button c="cache_fetch btn btn-default" href="#" din="html.cache_fetch"></button>
329
- <button c="cache_delete btn btn-default" href="#" din="html.cache_delete"></button></s></dd>
330
- </dl></d>
331
- </d>
332
-
333
- <d c="modal_load_content">
334
- <p c="recipient"><img src="${
335
- pointer["loading.png"]
336
- }"><s din="html.app_loading_body"></s></p>
337
- <d c="splash_div hide row"><p c="col-xs-12 poi_img"><img c="splash_img" src=""></p></d>
338
- <p><img src="" height="0px" width="0px"></p>
339
- </d>
340
-
341
- <d c="modal_hide_marker_content">
342
- <ul c="list-group"></ul>
343
- </d>
344
-
345
- <p c="modal_gpsD_content" c="recipient"></p>
346
- <p c="modal_gpsW_content" c="recipient"></p>
347
-
348
- </d>
349
- </d>
350
- </d>
351
- </d> `);
352
- for (let i = newElems.length - 1; i >= 0; i--) {
353
- ui.core.mapDivDocument.insertBefore(
354
- newElems[i],
355
- ui.core.mapDivDocument.firstChild
356
- );
357
- }
358
-
359
- const shareBtns = ui.core.mapDivDocument.querySelectorAll(".btn.share");
360
- for (let i = 0; i < shareBtns.length; i++) {
361
- const shareBtn = shareBtns[i];
362
- shareBtn.addEventListener("click", evt => {
363
- let btn = evt.target;
364
- if (!btn.classList.contains("share")) btn = btn.parentElement;
365
- const cmd = btn.getAttribute("data");
366
- const cmds = cmd.split("_");
367
- let base = evt.target.baseURI;
368
- if (!base) base = window.location.href;
369
- const div1 = base.split("#!");
370
- const path = div1.length > 1 ? div1[1].split("?")[0] : "";
371
- const div2 = div1[0].split("?");
372
- let uri = div2[0];
373
- const query =
374
- div2.length > 1
375
- ? div2[1]
376
- .split("&")
377
- .filter(qs => qs !== "pwa")
378
- .join("&")
379
- : "";
380
-
381
- if (query) uri = `${uri}?${query}`;
382
- if (cmds[1] === "view") {
383
- if (path) uri = `${uri}#!${path}`;
384
- }
385
- if (cmds[0] === "cp") {
386
- const copyFrom = document.createElement("textarea"); // eslint-disable-line no-undef
387
- copyFrom.textContent = uri;
388
-
389
- const bodyElm = document.querySelector("body"); // eslint-disable-line no-undef
390
- bodyElm.appendChild(copyFrom);
391
-
392
- if (/iP(hone|[oa]d)/.test(navigator.userAgent)) {
393
- // eslint-disable-line no-undef
394
- const range = document.createRange(); // eslint-disable-line no-undef
395
- range.selectNode(copyFrom);
396
- window.getSelection().addRange(range); // eslint-disable-line no-undef
397
- } else {
398
- copyFrom.select();
399
- }
400
-
401
- document.execCommand("copy"); // eslint-disable-line no-undef
402
- bodyElm.removeChild(copyFrom);
403
- const toastParent = `#___maplat_${cmds[1]}_toast_${ui.html_id_seed}`;
404
- iziToast.show({
405
- message: ui.core.t("app.copy_toast", { ns: "translation" }),
406
- close: false,
407
- pauseOnHover: false,
408
- timeout: 1000,
409
- progressBar: false,
410
- target: toastParent
411
- });
412
- } else if (cmds[0] === "tw") {
413
- const twuri = `https://twitter.com/share?url=${encodeURIComponent(
414
- uri
415
- )}&hashtags=Maplat`;
416
- window.open(
417
- twuri,
418
- "_blank",
419
- "width=650,height=450,menubar=no,toolbar=no,scrollbars=yes"
420
- ); // eslint-disable-line no-undef
421
- } else if (cmds[0] === "fb") {
422
- // https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fplugins%2Fshare-button%2F&display=popup&ref=plugin&src=like&kid_directed_site=0&app_id=113869198637480
423
- const fburi = `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(
424
- uri
425
- )}&display=popup&ref=plugin&src=like&kid_directed_site=0`;
426
- window.open(
427
- fburi,
428
- "_blank",
429
- "width=650,height=450,menubar=no,toolbar=no,scrollbars=yes"
430
- ); // eslint-disable-line no-undef
431
- }
432
- });
433
- }
434
-
435
- // PWA対応: 非同期処理
436
- if (pwaManifest) {
437
- if (pwaManifest === true) {
438
- pwaManifest = `./pwa/${ui.core.appid}_manifest.json`;
439
- }
440
- if (!pwaWorker) {
441
- pwaWorker = "./service-worker.js";
442
- }
443
- if (!pwaScope) {
444
- pwaScope = "./";
445
- }
446
-
447
- const head = document.querySelector("head"); // eslint-disable-line no-undef
448
- if (!head.querySelector('link[rel="manifest"]')) {
449
- head.appendChild(
450
- createElement(`<link rel="manifest" href="${pwaManifest}">`)[0]
451
- );
452
- }
453
- // service workerが有効なら、service-worker.js を登録します
454
- try {
455
- Weiwudi.registerSW(pwaWorker, { scope: pwaScope });
456
- } catch (e) {} // eslint-disable-line no-empty
457
-
458
- if (!head.querySelector('link[rel="apple-touch-icon"]')) {
459
- const xhr = new XMLHttpRequest(); // eslint-disable-line no-undef
460
- xhr.open("GET", pwaManifest, true);
461
- xhr.responseType = "json";
462
-
463
- xhr.onload = function (_e) {
464
- let value = this.response;
465
- if (!value) return;
466
- if (typeof value != "object") value = JSON.parse(value);
467
-
468
- if (value.icons) {
469
- for (let i = 0; i < value.icons.length; i++) {
470
- const src = absoluteUrl(pwaManifest, value.icons[i].src);
471
- const sizes = value.icons[i].sizes;
472
- const tag = `<link rel="apple-touch-icon" sizes="${sizes}" href="${src}">`;
473
- head.appendChild(createElement(tag)[0]);
474
- }
475
- }
476
- };
477
- xhr.send();
478
- }
479
- }
480
-
481
- ui.core.addEventListener("uiPrepare", _evt => {
482
- const imageExtractor = function (text) {
483
- const regexp = /\$\{([a-zA-Z0-9_\.\/\-]+)\}/g; // eslint-disable-line no-useless-escape
484
- let ret = text;
485
- let match;
486
- while ((match = regexp.exec(text)) != null) {
487
- ret = ret.replace(match[0], pointer[match[1]]);
488
- }
489
- return ret;
490
- };
491
- let i18nTargets = ui.core.mapDivDocument.querySelectorAll("[data-i18n]");
492
- for (let i = 0; i < i18nTargets.length; i++) {
493
- const target = i18nTargets[i];
494
- const key = target.getAttribute("data-i18n");
495
- target.innerText = imageExtractor(ui.core.t(key));
496
- }
497
- i18nTargets = ui.core.mapDivDocument.querySelectorAll("[data-i18n-html]");
498
- for (let i = 0; i < i18nTargets.length; i++) {
499
- const target = i18nTargets[i];
500
- const key = target.getAttribute("data-i18n-html");
501
- target.innerHTML = imageExtractor(ui.core.t(key));
502
- }
503
-
504
- const options = {
505
- reverse: true,
506
- tipLabel: ui.core.t("control.trans", { ns: "translation" })
507
- };
508
- if (restoreTransparency) {
509
- options.initialValue = restoreTransparency / 100;
510
- }
511
- ui.sliderCommon = new SliderCommon(options);
512
- ui.core.appData.controls = [
513
- new Copyright({
514
- tipLabel: ui.core.t("control.info", { ns: "translation" })
515
- }),
516
- new CompassRotate({
517
- tipLabel: ui.core.t("control.compass", { ns: "translation" }),
518
- northTop: ui.northTop
519
- }),
520
- new Zoom({
521
- tipLabel: ui.core.t("control.zoom", { ns: "translation" })
522
- }),
523
- new SetGPS({
524
- tipLabel: ui.core.t("control.gps", { ns: "translation" })
525
- }),
526
- new GoHome({
527
- tipLabel: ui.core.t("control.home", { ns: "translation" })
528
- }),
529
- ui.sliderCommon,
530
- new Maplat({
531
- tipLabel: ui.core.t("control.help", { ns: "translation" })
532
- })
533
- ];
534
- if (ui.enableShare) {
535
- ui.core.appData.controls.push(
536
- new Share({
537
- tipLabel: ui.core.t("control.share", { ns: "translation" })
538
- })
539
- );
540
- }
541
- if (ui.enableBorder) {
542
- ui.core.appData.controls.push(
543
- new Border({
544
- tipLabel: ui.core.t("control.border", { ns: "translation" })
545
- })
546
- );
547
- }
548
- if (ui.enableHideMarker) {
549
- ui.core.appData.controls.push(
550
- new HideMarker({
551
- tipLabel: ui.core.t("control.hide_marker", { ns: "translation" })
552
- })
553
- );
554
- }
555
-
556
- // Contextmenu
557
- ui.contextMenu = new ContextMenu({
558
- eventType: "__dummy__",
559
- width: 170,
560
- defaultItems: false,
561
- items: []
562
- });
563
- ui.core.appData.controls.push(ui.contextMenu);
564
-
565
- if (ui.core.mapObject) {
566
- ui.core.appData.controls.map(control => {
567
- ui.core.mapObject.addControl(control);
568
- });
569
- }
570
-
571
- ui.sliderCommon.on("propertychange", evt => {
572
- if (evt.key === "slidervalue") {
573
- ui.core.setTransparency(ui.sliderCommon.get(evt.key) * 100);
574
- }
575
- });
576
-
577
- if (enableSplash) {
578
- // Check Splash data
579
- let splash = false;
580
- if (ui.core.appData.splash) splash = true;
581
-
582
- const modalElm = ui.core.mapDivDocument.querySelector(".modalBase");
583
- const modal = new bsn.Modal(modalElm, { root: ui.core.mapDivDocument });
584
- ui.core.mapDivDocument.querySelector(".modal_load_title").innerText =
585
- ui.core.translate(ui.core.appData.appName);
586
- if (splash) {
587
- ui.core.mapDivDocument
588
- .querySelector(".splash_img")
589
- .setAttribute("src", `img/${ui.core.appData.splash}`);
590
- ui.core.mapDivDocument
591
- .querySelector(".splash_div")
592
- .classList.remove("hide");
593
- }
594
- ui.modalSetting("load");
595
- modal.show();
596
-
597
- const fadeTime = splash ? 1000 : 200;
598
- ui.splashPromise = new Promise(resolve => {
599
- setTimeout(() => {
600
- // eslint-disable-line no-undef
601
- resolve();
602
- }, fadeTime);
603
- });
604
- }
605
-
606
- document.querySelector("title").innerHTML = ui.core.translate(
607
- ui.core.appName
608
- ); // eslint-disable-line no-undef
609
- });
610
-
611
- ui.core.addEventListener("sourceLoaded", evt => {
612
- const sources = evt.detail;
613
-
614
- const colors = [
615
- "maroon",
616
- "deeppink",
617
- "indigo",
618
- "olive",
619
- "royalblue",
620
- "red",
621
- "hotpink",
622
- "green",
623
- "yellow",
624
- "navy",
625
- "saddlebrown",
626
- "fuchsia",
627
- "darkslategray",
628
- "yellowgreen",
629
- "blue",
630
- "mediumvioletred",
631
- "purple",
632
- "lime",
633
- "darkorange",
634
- "teal",
635
- "crimson",
636
- "darkviolet",
637
- "darkolivegreen",
638
- "steelblue",
639
- "aqua"
640
- ];
641
- const appBbox = [];
642
- let cIndex = 0;
643
- for (let i = 0; i < sources.length; i++) {
644
- const source = sources[i];
645
- if (source.envelope) {
646
- if (ui.appEnvelope)
647
- source.envelope.geometry.coordinates[0].map(xy => {
648
- if (appBbox.length === 0) {
649
- appBbox[0] = appBbox[2] = xy[0];
650
- appBbox[1] = appBbox[3] = xy[1];
651
- } else {
652
- if (xy[0] < appBbox[0]) appBbox[0] = xy[0];
653
- if (xy[0] > appBbox[2]) appBbox[2] = xy[0];
654
- if (xy[1] < appBbox[1]) appBbox[1] = xy[1];
655
- if (xy[1] > appBbox[3]) appBbox[3] = xy[1];
656
- }
657
- });
658
- source.envelopeColor = colors[cIndex];
659
- cIndex = cIndex + 1;
660
- if (cIndex === colors.length) cIndex = 0;
661
-
662
- const xys = source.envelope.geometry.coordinates[0];
663
- // http://blog.arq.name/wp-content/uploads/2018/02/Rectangle_Area.pdf
664
- source.envelopeAreaIndex = ui.areaIndex(xys);
665
- }
666
- }
667
- if (ui.appEnvelope) console.log(`This app's envelope is: ${appBbox}`);
668
-
669
- if (ui.splashPromise) {
670
- ui.splashPromise.then(() => {
671
- const modalElm = ui.core.mapDivDocument.querySelector(".modalBase");
672
- const modal = new bsn.Modal(modalElm, {
673
- root: ui.core.mapDivDocument
674
- });
675
- ui.modalSetting("load");
676
- modal.hide();
677
- });
678
- }
679
-
680
- const baseSources = [];
681
- const overlaySources = [];
682
- for (let i = 0; i < sources.length; i++) {
683
- const source = sources[i];
684
- if (source instanceof NowMap && !(source instanceof TmsMap)) {
685
- baseSources.push(source);
686
- } else {
687
- overlaySources.push(source);
688
- }
689
- }
690
-
691
- const baseSwiper = (ui.baseSwiper = new Swiper(".base-swiper", {
692
- slidesPerView: 2,
693
- spaceBetween: 15,
694
- breakpoints: {
695
- // when window width is <= 480px
696
- 480: {
697
- slidesPerView: 1.4,
698
- spaceBetween: 10
699
- }
700
- },
701
- centeredSlides: true,
702
- threshold: 2,
703
- loop: baseSources.length >= 2,
704
- navigation: {
705
- nextEl: ".base-next",
706
- prevEl: ".base-prev"
707
- }
708
- }));
709
- baseSwiper.on("click", _e => {
710
- if (!baseSwiper.clickedSlide) return;
711
- const slide = baseSwiper.clickedSlide;
712
- ui.core.changeMap(slide.getAttribute("data"));
713
- delete ui._selectCandidateSources;
714
- baseSwiper.setSlideIndexAsSelected(
715
- slide.getAttribute("data-swiper-slide-index")
716
- );
717
- });
718
- if (baseSources.length < 2) {
719
- ui.core.mapDivDocument
720
- .querySelector(".base-swiper")
721
- .classList.add("single-map");
722
- }
723
- const overlaySwiper = (ui.overlaySwiper = new Swiper(".overlay-swiper", {
724
- slidesPerView: 2,
725
- spaceBetween: 15,
726
- breakpoints: {
727
- // when window width is <= 480px
728
- 480: {
729
- slidesPerView: 1.4,
730
- spaceBetween: 10
731
- }
732
- },
733
- centeredSlides: true,
734
- threshold: 2,
735
- loop: overlaySources.length >= 2,
736
- navigation: {
737
- nextEl: ".overlay-next",
738
- prevEl: ".overlay-prev"
739
- }
740
- }));
741
- overlaySwiper.on("click", _e => {
742
- if (!overlaySwiper.clickedSlide) return;
743
- const slide = overlaySwiper.clickedSlide;
744
- ui.core.changeMap(slide.getAttribute("data"));
745
- delete ui._selectCandidateSources;
746
- overlaySwiper.setSlideIndexAsSelected(
747
- slide.getAttribute("data-swiper-slide-index")
748
- );
749
- });
750
- if (overlaySources.length < 2) {
751
- ui.core.mapDivDocument
752
- .querySelector(".overlay-swiper")
753
- .classList.add("single-map");
754
- }
755
-
756
- for (let i = 0; i < baseSources.length; i++) {
757
- const source = baseSources[i];
758
- baseSwiper.appendSlide(
759
- `<div class="swiper-slide" data="${source.mapID}">` +
760
- `<img crossorigin="anonymous" src="${
761
- source.thumbnail
762
- }"><div> ${ui.core.translate(source.label)}</div> </div> `
763
- );
764
- }
765
- for (let i = 0; i < overlaySources.length; i++) {
766
- const source = overlaySources[i];
767
- const colorCss = source.envelope ? ` ${source.envelopeColor}` : "";
768
- overlaySwiper.appendSlide(
769
- `<div class="swiper-slide${colorCss}" data="${source.mapID}">` +
770
- `<img crossorigin="anonymous" src="${
771
- source.thumbnail
772
- }"><div> ${ui.core.translate(source.label)}</div> </div> `
773
- );
774
- }
775
-
776
- baseSwiper.on;
777
- overlaySwiper.on;
778
- baseSwiper.slideToLoop(0);
779
- overlaySwiper.slideToLoop(0);
780
- ui.ellips();
781
- });
782
-
783
- ui.core.addEventListener("mapChanged", evt => {
784
- const map = evt.detail;
785
-
786
- ui.baseSwiper.setSlideMapID(map.mapID);
787
- ui.overlaySwiper.setSlideMapID(map.mapID);
788
-
789
- const title = map.officialTitle || map.title || map.label;
790
- ui.core.mapDivDocument.querySelector(".map-title span").innerText =
791
- ui.core.translate(title);
792
-
793
- if (ui.checkOverlayID(map.mapID)) {
794
- ui.sliderCommon.setEnable(true);
795
- } else {
796
- ui.sliderCommon.setEnable(false);
797
- }
798
- const transparency = ui.sliderCommon.get("slidervalue") * 100;
799
- ui.core.mapObject.setTransparency(transparency);
800
-
801
- ui.updateEnvelope();
802
- });
803
-
804
- ui.core.addEventListener("poi_number", evt => {
805
- const number = evt.detail;
806
- if (number) {
807
- ui.core.mapDivDocument.classList.remove("no_poi");
808
- } else {
809
- ui.core.mapDivDocument.classList.add("no_poi");
810
- }
811
- });
812
-
813
- ui.core.addEventListener("outOfMap", _evt => {
814
- if (enableOutOfMap) {
815
- ui.core.mapDivDocument.querySelector(".modal_title").innerText =
816
- ui.core.t("app.out_of_map");
817
- ui.core.mapDivDocument.querySelector(".modal_gpsD_content").innerText =
818
- ui.core.t("app.out_of_map_area");
819
- const modalElm = ui.core.mapDivDocument.querySelector(".modalBase");
820
- const modal = new bsn.Modal(modalElm, { root: ui.core.mapDivDocument });
821
- ui.modalSetting("gpsD");
822
- modal.show();
823
- }
824
- });
825
-
826
- ui.core.mapDivDocument.addEventListener("mouseout", _evt => {
827
- if (ui._selectCandidateSources) {
828
- Object.keys(ui._selectCandidateSources).forEach(key =>
829
- ui.core.mapObject.removeEnvelope(ui._selectCandidateSources[key])
830
- );
831
- delete ui._selectCandidateSources;
832
- }
833
- });
834
-
835
- ui.core.addEventListener("pointerMoveOnMapXy", async evt => {
836
- if (!ui.core.stateBuffer.showBorder) {
837
- if (ui._selectCandidateSources) {
838
- Object.keys(ui._selectCandidateSources).forEach(key =>
839
- ui.core.mapObject.removeEnvelope(ui._selectCandidateSources[key])
840
- );
841
- delete ui._selectCandidateSources;
842
- }
843
- return;
844
- }
845
-
846
- const mapIDs = await ui.xyToMapIDs(evt.detail);
847
- ui.showFillEnvelope(mapIDs);
848
- });
849
-
850
- ui.core.addEventListener("clickMapXy", async evt => {
851
- if (!ui.core.stateBuffer.showBorder) {
852
- return;
853
- }
854
-
855
- const mapIDs = await ui.xyToMapIDs(evt.detail);
856
- if (mapIDs.length > 0) {
857
- let currentID;
858
- showContextMenu(
859
- mapIDs.map(mapID => {
860
- const source = ui.core.cacheHash[mapID];
861
- const hexColor = source.envelopeColor;
862
- let iconSVG = `<?xml version="1.0" encoding="utf-8"?><svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
863
- x="0px" y="0px" width="10px" height="10px" viewBox="0 0 10 10"
864
- enable-background="new 0 0 10 10" xml:space="preserve">
865
- <polygon x="0" y="0" points="2,2 2,8 8,8 8,2
866
- 2,2" stroke="${hexColor}" fill="${hexColor}" stroke-width="2" style="fill-opacity: .25;"></polygon></svg>`;
867
- iconSVG = `data:image/svg+xml,${encodeURIComponent(iconSVG)}`;
868
- return {
869
- icon: iconSVG,
870
- text: ui.core.translate(source.title),
871
- callback: () => {
872
- const lis = [
873
- ...ui.core.mapDivDocument.querySelectorAll(
874
- ".ol-ctx-menu-container ul li"
875
- )
876
- ];
877
- lis.forEach(li => li.classList.remove("selected"));
878
- if (currentID && currentID === mapID) {
879
- delete ui._selectCandidateSources;
880
- ui.core.changeMap(mapID);
881
- } else {
882
- currentID = mapID;
883
- ui.showFillEnvelope([mapID]);
884
- ui.overlaySwiper.slideToMapID(mapID);
885
- const index = mapIDs.indexOf(mapID);
886
- if (index > -1) {
887
- const li = lis[index];
888
- li.classList.add("selected");
889
- }
890
- return true;
891
- }
892
- },
893
- mouseOnTask(_evt) {
894
- if (!ui.isTouch) {
895
- currentID = mapID;
896
- ui.showFillEnvelope([mapID]);
897
- ui.overlaySwiper.slideToMapID(mapID);
898
- }
899
- },
900
- mouseOutTask(_evt) {
901
- if (!ui.isTouch) {
902
- currentID = undefined;
903
- ui.showFillEnvelope([]);
904
- }
905
- }
906
- };
907
- })
908
- );
909
- ui.showFillEnvelope(mapIDs);
910
- }
911
- });
912
-
913
- function showContextMenu(menues) {
914
- ui.contextMenu.clear();
915
- const mouseOnTasks = [];
916
- menues.forEach(menu => {
917
- ui.contextMenu.push(menu);
918
- if (menu.mouseOnTask)
919
- mouseOnTasks.push([menu.mouseOnTask, menu.mouseOutTask]);
920
- });
921
-
922
- const coordinate = ui.core.lastClickEvent.coordinate;
923
- const pixel = ui.core.lastClickEvent.pixel;
924
-
925
- if (ui.contextMenu.disabled) return;
926
-
927
- const openHandler = () => {
928
- ui.contextMenu.removeEventListener("open", openHandler);
929
- if (mouseOnTasks.length > 0) {
930
- const lis = [
931
- ...ui.core.mapDivDocument.querySelectorAll(
932
- ".ol-ctx-menu-container ul li"
933
- )
934
- ];
935
- const events = lis.map((li, i) => {
936
- const tasks = mouseOnTasks[i];
937
- li.addEventListener("mouseover", tasks[0]);
938
- li.addEventListener("mouseout", tasks[1]);
939
- return [li, tasks[0], tasks[1]];
940
- });
941
- const closeHandler = () => {
942
- ui.contextMenu.removeEventListener("close", closeHandler);
943
- events.forEach(event => {
944
- event[0].removeEventListener("mouseover", event[1]);
945
- event[0].removeEventListener("mouseout", event[2]);
946
- });
947
- };
948
- ui.contextMenu.on("close", closeHandler);
949
- }
950
- };
951
- ui.contextMenu.on("open", openHandler);
952
- ui.contextMenu.Internal.openMenu(pixel, coordinate);
953
-
954
- //one-time fire
955
- ui.core.mapObject.getViewport().addEventListener(
956
- "pointerdown",
957
- {
958
- handleEvent(e) {
959
- if (ui.contextMenu.Internal.opened) {
960
- ui.contextMenu.Internal.closeMenu();
961
- e.stopPropagation();
962
- ui.core.mapObject
963
- .getViewport()
964
- .removeEventListener(e.type, this, false);
965
- }
966
- }
967
- },
968
- false
969
- );
970
- }
971
-
972
- ui.core.addEventListener("clickMarkers", evt => {
973
- const data = evt.detail;
974
- if (data.length === 1) {
975
- ui.handleMarkerAction(data[0]);
976
- } else {
977
- showContextMenu(
978
- data.map(datum => ({
979
- icon: datum.icon || pointer["defaultpin.png"],
980
- text: ui.core.translate(datum.name),
981
- callback() {
982
- ui.handleMarkerAction(datum);
983
- }
984
- }))
985
- );
986
- }
987
- });
988
-
989
- if (appOption.stateUrl) {
990
- ui.core.addEventListener("updateState", evt => {
991
- const value = evt.detail;
992
- if (!value.position || !value.mapID) return;
993
- let link = `s:${value.mapID}`;
994
- if (value.backgroundID) link = `${link}/b:${value.backgroundID}`;
995
- if (value.transparency) link = `${link}/t:${value.transparency}`;
996
- link = `${link}/x:${value.position.x}/y:${value.position.y}`;
997
- link = `${link}/z:${value.position.zoom}`;
998
- if (value.position.rotation)
999
- link = `${link}/r:${value.position.rotation}`;
1000
- if (value.showBorder) link = `${link}/sb:${value.showBorder}`;
1001
- if (value.hideMarker) link = `${link}/hm:${value.hideMarker}`;
1002
- if (value.hideLayer) link = `${link}/hl:${value.hideLayer}`;
1003
-
1004
- ui.pathThatSet = link;
1005
- page(link);
1006
- });
1007
- }
1008
-
1009
- ui.waitReady = ui.core.waitReady.then(() => {
1010
- const fakeGps = appOption.fake ? ui.core.appData.fake_gps : false;
1011
- const fakeCenter = appOption.fake ? ui.core.appData.fake_center : false;
1012
- const fakeRadius = appOption.fake ? ui.core.appData.fake_radius : false;
1013
-
1014
- let shown = false;
1015
- let gpsWaitPromise = null;
1016
- function showGPSresult(result) {
1017
- if (result && result.error) {
1018
- ui.core.currentPosition = null;
1019
- if (result.error === "gps_out" && shown) {
1020
- shown = false;
1021
- const modalElm = ui.core.mapDivDocument.querySelector(".modalBase");
1022
- const modal = new bsn.Modal(modalElm, {
1023
- root: ui.core.mapDivDocument
1024
- });
1025
- ui.core.mapDivDocument.querySelector(".modal_title").innerText =
1026
- ui.core.t("app.out_of_map");
1027
- ui.core.mapDivDocument.querySelector(
1028
- ".modal_gpsD_content"
1029
- ).innerText = ui.core.t("app.out_of_map_desc");
1030
- ui.modalSetting("gpsD");
1031
- modal.show();
1032
- }
1033
- } else {
1034
- ui.core.currentPosition = result;
1035
- }
1036
- if (shown) {
1037
- shown = false;
1038
- const modalElm = ui.core.mapDivDocument.querySelector(".modalBase");
1039
- const modal = new bsn.Modal(modalElm, {
1040
- root: ui.core.mapDivDocument
1041
- });
1042
- modal.hide();
1043
- }
1044
- }
1045
- ui.core.mapObject.on("gps_request", () => {
1046
- gpsWaitPromise = "gps_request";
1047
- const promises = [
1048
- new Promise(resolve => {
1049
- if (gpsWaitPromise !== "gps_request") {
1050
- resolve(gpsWaitPromise);
1051
- } else gpsWaitPromise = resolve;
1052
- })
1053
- ];
1054
- shown = true;
1055
- const modalElm = ui.core.mapDivDocument.querySelector(".modalBase");
1056
- const modal = new bsn.Modal(modalElm, { root: ui.core.mapDivDocument });
1057
- ui.modalSetting("gpsW");
1058
- modal.show();
1059
- // 200m秒以上最低待たないと、Modalがうまく動かない場合がある
1060
- promises.push(
1061
- new Promise(resolve => {
1062
- setTimeout(resolve, 200); // eslint-disable-line no-undef
1063
- })
1064
- );
1065
- Promise.all(promises).then(results => {
1066
- showGPSresult(results[0]);
1067
- });
1068
- });
1069
- ui.core.mapObject.on("gps_result", evt => {
1070
- if (gpsWaitPromise === "gps_request") {
1071
- gpsWaitPromise = evt.frameState;
1072
- } else if (gpsWaitPromise) {
1073
- gpsWaitPromise(evt.frameState);
1074
- gpsWaitPromise = null;
1075
- } else if (!shown) {
1076
- showGPSresult(evt.frameState);
1077
- }
1078
- });
1079
-
1080
- let qr_app;
1081
- let qr_view;
1082
- ui.core.mapObject.on("click_control", async evt => {
1083
- const control = evt.frameState.control;
1084
- const modalElm = ui.core.mapDivDocument.querySelector(".modalBase");
1085
- const modal = new bsn.Modal(modalElm, { root: ui.core.mapDivDocument });
1086
- if (control === "copyright") {
1087
- const from = ui.core.getMapMeta();
1088
-
1089
- if (
1090
- !META_KEYS.reduce((prev, curr) => {
1091
- if (curr === "title") return prev;
1092
- return from[curr] || prev;
1093
- }, false)
1094
- )
1095
- return;
1096
-
1097
- ui.core.mapDivDocument.querySelector(".modal_title").innerText =
1098
- ui.core.translate(from.officialTitle || from.title);
1099
- META_KEYS.map(key => {
1100
- if (key === "title" || key === "officialTitle") return;
1101
- if (!from[key] || from[key] === "") {
1102
- ui.core.mapDivDocument
1103
- .querySelector(`.${key}_div`)
1104
- .classList.add("hide");
1105
- } else {
1106
- ui.core.mapDivDocument
1107
- .querySelector(`.${key}_div`)
1108
- .classList.remove("hide");
1109
- ui.core.mapDivDocument.querySelector(`.${key}_dd`).innerHTML =
1110
- key === "license" || key === "dataLicense"
1111
- ? `<img src="${
1112
- pointer[
1113
- `${from[key].toLowerCase().replace(/ /g, "_")}.png`
1114
- ]
1115
- }">`
1116
- : ui.core.translate(from[key]);
1117
- }
1118
- });
1119
-
1120
- const deleteButton =
1121
- ui.core.mapDivDocument.querySelector(".cache_delete"); // eslint-disable-line no-undef
1122
- const fetchButton =
1123
- ui.core.mapDivDocument.querySelector(".cache_fetch"); // eslint-disable-line no-undef
1124
- const putTileCacheStats = function (stats) {
1125
- let size = stats.size || 0;
1126
- let unit = "Bytes";
1127
- if (size !== -1) {
1128
- if (size > 1024) {
1129
- size = Math.round((size * 10) / 1024) / 10;
1130
- unit = "KBytes";
1131
- }
1132
- if (size > 1024) {
1133
- size = Math.round((size * 10) / 1024) / 10;
1134
- unit = "MBytes";
1135
- }
1136
- if (size > 1024) {
1137
- size = Math.round((size * 10) / 1024) / 10;
1138
- unit = "GBytes";
1139
- }
1140
- }
1141
- let content =
1142
- size === -1
1143
- ? ui.core.t("html.cache_processing")
1144
- : `${size} ${unit}`;
1145
- if (stats.total) {
1146
- content = `${content} (${stats.count} / ${stats.total} tiles [${stats.percent}%])`;
1147
- } else {
1148
- content = `${content} (${stats.count} tiles)`;
1149
- }
1150
- ui.core.mapDivDocument.querySelector(".cache_size").innerHTML =
1151
- content;
1152
- if (stats.count != 0) {
1153
- deleteButton.removeAttribute("disabled");
1154
- } else {
1155
- deleteButton.setAttribute("disabled", true);
1156
- }
1157
- if (stats.total) {
1158
- fetchButton.classList.remove("hide");
1159
- if (stats.total === stats.count) {
1160
- fetchButton.setAttribute("disabled", true);
1161
- } else {
1162
- fetchButton.removeAttribute("disabled");
1163
- }
1164
- } else {
1165
- fetchButton.classList.add("hide");
1166
- }
1167
- };
1168
- ui.modalSetting("map");
1169
-
1170
- const cacheDiv = ui.core.mapDivDocument.querySelector(
1171
- ".modal_cache_content"
1172
- );
1173
- const cacheEnable = ui.core.getMapCacheEnable(from.mapID);
1174
-
1175
- if (cacheEnable) {
1176
- cacheDiv.classList.remove("hide");
1177
- const deleteFunc = async function (evt) {
1178
- evt.preventDefault();
1179
- const from = ui.core.getMapMeta();
1180
- await ui.core.clearMapTileCacheAsync(from.mapID);
1181
- putTileCacheStats(
1182
- await ui.core.getMapTileCacheStatsAsync(from.mapID)
1183
- );
1184
- };
1185
- const cancelFunc = async function (evt) {
1186
- if (evt) evt.preventDefault();
1187
- const from = ui.core.getMapMeta();
1188
- await ui.core.cancelMapTileCacheAsync(from.mapID);
1189
- };
1190
- const fetchFunc = async function (evt) {
1191
- const closeButton =
1192
- ui.core.mapDivDocument.querySelector(".close");
1193
- evt.preventDefault();
1194
- fetchButton.innerHTML = ui.core.t("html.cache_cancel");
1195
- fetchButton.removeEventListener("click", fetchFunc);
1196
- fetchButton.addEventListener("click", cancelFunc);
1197
- closeButton.classList.add("temp_no_close");
1198
- const from = ui.core.getMapMeta();
1199
- await ui.core.fetchAllMapTileCacheAsync(
1200
- from.mapID,
1201
- async (type, data) => {
1202
- switch (type) {
1203
- case "proceed":
1204
- putTileCacheStats({
1205
- count: data.processed,
1206
- total: data.total,
1207
- percent: data.percent,
1208
- size: -1
1209
- });
1210
- return;
1211
- case "canceled":
1212
- case "stop":
1213
- case "finish":
1214
- fetchButton.innerHTML = ui.core.t("html.cache_fetch");
1215
- fetchButton.removeEventListener("click", cancelFunc);
1216
- fetchButton.addEventListener("click", fetchFunc);
1217
- closeButton.classList.remove("temp_no_close");
1218
- putTileCacheStats(
1219
- await ui.core.getMapTileCacheStatsAsync(from.mapID)
1220
- );
1221
- }
1222
- }
1223
- );
1224
- };
1225
- const hideFunc = function (_event) {
1226
- deleteButton.removeEventListener("click", deleteFunc, false);
1227
- fetchButton.removeEventListener("click", fetchFunc, false);
1228
- fetchButton.removeEventListener("click", cancelFunc, false);
1229
- modalElm.removeEventListener("hide.bs.modal", hideFunc, false);
1230
- };
1231
- modalElm.addEventListener("hide.bs.modal", hideFunc, false);
1232
-
1233
- putTileCacheStats(
1234
- await ui.core.getMapTileCacheStatsAsync(from.mapID)
1235
- );
1236
-
1237
- setTimeout(() => {
1238
- // eslint-disable-line no-undef
1239
- deleteButton.addEventListener("click", deleteFunc, false);
1240
- fetchButton.addEventListener("click", fetchFunc, false);
1241
- fetchButton.innerHTML = ui.core.t("html.cache_fetch");
1242
- }, 200);
1243
- } else {
1244
- cacheDiv.classList.add("hide");
1245
- }
1246
- modal.show();
1247
- } else if (control === "help") {
1248
- ui.modalSetting("help");
1249
- modal.show();
1250
- } else if (control === "share") {
1251
- ui.modalSetting("share");
1252
-
1253
- const base = location.href; // eslint-disable-line no-undef
1254
- const div1 = base.split("#!");
1255
- const path = div1.length > 1 ? div1[1].split("?")[0] : "";
1256
- const div2 = div1[0].split("?");
1257
- let uri = div2[0];
1258
- const query =
1259
- div2.length > 1
1260
- ? div2[1]
1261
- .split("&")
1262
- .filter(qs => qs !== "pwa")
1263
- .join("&")
1264
- : "";
1265
-
1266
- if (query) uri = `${uri}?${query}`;
1267
- let view = uri;
1268
- if (path) view = `${view}#!${path}`;
1269
- if (!qr_app) {
1270
- qr_app = new QRCode(
1271
- ui.core.mapDivDocument.querySelector(".qr_app"),
1272
- {
1273
- text: uri,
1274
- width: 128,
1275
- height: 128,
1276
- colorDark: "#000000",
1277
- colorLight: "#ffffff",
1278
- correctLevel: QRCode.CorrectLevel.H
1279
- }
1280
- );
1281
- } else {
1282
- qr_app.makeCode(uri);
1283
- }
1284
- if (!qr_view) {
1285
- qr_view = new QRCode(
1286
- ui.core.mapDivDocument.querySelector(".qr_view"),
1287
- {
1288
- text: view,
1289
- width: 128,
1290
- height: 128,
1291
- colorDark: "#000000",
1292
- colorLight: "#ffffff",
1293
- correctLevel: QRCode.CorrectLevel.H
1294
- }
1295
- );
1296
- } else {
1297
- qr_view.makeCode(view);
1298
- }
1299
-
1300
- modal.show();
1301
- } else if (control === "border") {
1302
- const flag = !ui.core.stateBuffer.showBorder;
1303
- ui.setShowBorder(flag);
1304
- } else if (control === "hideMarker") {
1305
- const flag = !ui.core.stateBuffer.hideMarker;
1306
- ui.setHideMarker(flag);
1307
- } else if (control === "hideLayer") {
1308
- ui.modalSetting("hide_marker");
1309
- const layers = ui.core.listPoiLayers(false, true);
1310
- const elem = ui.core.mapDivDocument.querySelector("ul.list-group");
1311
- const modalElm = ui.core.mapDivDocument.querySelector(".modalBase");
1312
- elem.innerHTML = "";
1313
- layers.map((layer, index) => {
1314
- const icon = layer.icon || pointer["defaultpin.png"];
1315
- const title = ui.core.translate(layer.name);
1316
- const check = !layer.hide;
1317
- const id = layer.namespaceID;
1318
- const newElems = createElement(`<li c="list-group-item">
1319
- <d c="row">
1320
- <d c="col-sm-1"><img c="markerlist" src="${icon}"></d>
1321
- <d c="col-sm-9">${title}</d>
1322
- <d c="col-sm-2">
1323
- <input type="checkbox" c="markerlist" data="${id}" id="___maplat_marker_${index}_${
1324
- ui.html_id_seed
1325
- }"${check ? " checked" : ""}/>
1326
- <label c="check" for="___maplat_marker_${index}_${
1327
- ui.html_id_seed
1328
- }"><d> </d> </label>
1329
- </d>
1330
- </d>
1331
- </li>`);
1332
- for (let i = 0; i < newElems.length; i++) {
1333
- elem.appendChild(newElems[i]);
1334
- }
1335
- const checkbox = ui.core.mapDivDocument.querySelector(
1336
- `#___maplat_marker_${index}_${ui.html_id_seed}`
1337
- );
1338
- const checkFunc = function (event) {
1339
- const id = event.target.getAttribute("data");
1340
- const checked = event.target.checked;
1341
- if (checked) ui.core.showPoiLayer(id);
1342
- else ui.core.hidePoiLayer(id);
1343
- };
1344
- const hideFunc = function (_event) {
1345
- modalElm.removeEventListener("hide.bs.modal", hideFunc, false);
1346
- checkbox.removeEventListener("change", checkFunc, false);
1347
- };
1348
- modalElm.addEventListener("hide.bs.modal", hideFunc, false);
1349
- checkbox.addEventListener("change", checkFunc, false);
1350
- });
1351
- modal.show();
1352
- }
1353
- });
1354
- if (fakeGps) {
1355
- const newElem = createElement(
1356
- sprintf(
1357
- ui.core.t("app.fake_explanation"),
1358
- ui.core.translate(fakeCenter),
1359
- fakeRadius
1360
- )
1361
- )[0];
1362
- const elem = ui.core.mapDivDocument.querySelector(
1363
- ".modal_gpsW_content"
1364
- );
1365
- elem.appendChild(newElem);
1366
- } else {
1367
- const newElem = createElement(ui.core.t("app.acquiring_gps_desc"))[0];
1368
- const elem = ui.core.mapDivDocument.querySelector(
1369
- ".modal_gpsW_content"
1370
- );
1371
- elem.appendChild(newElem);
1372
- }
1373
- if (ui.waitReadyBridge) {
1374
- ui.waitReadyBridge();
1375
- delete ui.waitReadyBridge;
1376
- }
1377
- });
1378
- }
1379
-
1380
- // Modal記述の動作を調整する関数
1381
- modalSetting(target) {
1382
- const modalElm = this.core.mapDivDocument.querySelector(".modalBase");
1383
- ["poi", "map", "load", "gpsW", "gpsD", "help", "share", "hide_marker"].map(
1384
- target_ => {
1385
- const className = `modal_${target_}`;
1386
- if (target === target_) {
1387
- modalElm.classList.add(className);
1388
- } else {
1389
- modalElm.classList.remove(className);
1390
- }
1391
- }
1392
- );
1393
- }
1394
-
1395
- handleMarkerAction(data) {
1396
- if (data.directgo) {
1397
- let blank = false;
1398
- let href = "";
1399
- if (typeof data.directgo == "string") {
1400
- href = data.directgo;
1401
- } else {
1402
- href = data.directgo.href;
1403
- blank = data.directgo.blank || false;
1404
- }
1405
- if (blank) {
1406
- window.open(href, "_blank"); // eslint-disable-line no-undef
1407
- } else {
1408
- window.location.href = href; // eslint-disable-line no-undef
1409
- }
1410
- return;
1411
- }
1412
-
1413
- this.core.mapDivDocument.querySelector(".modal_title").innerText =
1414
- this.core.translate(data.name);
1415
- const modalElm = this.core.mapDivDocument.querySelector(".modalBase");
1416
- if (data.url || data.html) {
1417
- this.core.mapDivDocument
1418
- .querySelector(".poi_web")
1419
- .classList.remove("hide");
1420
- this.core.mapDivDocument.querySelector(".poi_data").classList.add("hide");
1421
- const iframe = this.core.mapDivDocument.querySelector(".poi_iframe");
1422
- if (data.html) {
1423
- iframe.addEventListener("load", function loadEvent(event) {
1424
- event.currentTarget.removeEventListener(event.type, loadEvent);
1425
- const cssLink = createElement(
1426
- '<style type="text/css">html, body { height: 100vh; }\n img { width: 100vw; }</style>'
1427
- );
1428
- console.log(cssLink); // eslint-disable-line no-undef
1429
- iframe.contentDocument.head.appendChild(cssLink[0]);
1430
- });
1431
- iframe.removeAttribute("src");
1432
- iframe.setAttribute("srcdoc", this.core.translate(data.html));
1433
- } else {
1434
- iframe.removeAttribute("srcdoc");
1435
- iframe.setAttribute("src", this.core.translate(data.url));
1436
- }
1437
- } else {
1438
- this.core.mapDivDocument
1439
- .querySelector(".poi_data")
1440
- .classList.remove("hide");
1441
- this.core.mapDivDocument.querySelector(".poi_web").classList.add("hide");
1442
-
1443
- const slides = [];
1444
- if (data.image && data.image !== "") {
1445
- const images = Array.isArray(data.image) ? data.image : [data.image];
1446
- images.forEach(image => {
1447
- if (typeof image === "string") {
1448
- image = { src: image };
1449
- }
1450
- const tmpImg = this.resolveRelativeLink(image.src, "img");
1451
- let slide = `<a target="_blank" href="${tmpImg}"><img src="${tmpImg}"></a>`;
1452
- if (image.desc) slide = `${slide}<div>${image.desc}</div>`;
1453
- slides.push(`<div class="swiper-slide">${slide}</div>`);
1454
- });
1455
- } else if (!this.disableNoimage) {
1456
- slides.push(
1457
- `<div class="swiper-slide"><img src="${pointer["no_image.png"]}"></div>`
1458
- );
1459
- }
1460
-
1461
- const imgShowFunc = _event => {
1462
- modalElm.removeEventListener("shown.bs.modal", imgShowFunc, false);
1463
- const swiperDiv = this.core.mapDivDocument.querySelector(
1464
- ".swiper-container.poi_img_swiper"
1465
- );
1466
- if (slides.length === 0) {
1467
- swiperDiv.classList.add("hide");
1468
- } else {
1469
- swiperDiv.classList.remove("hide");
1470
- if (!this.poiSwiper) {
1471
- this.poiSwiper = new Swiper(".swiper-container.poi_img_swiper", {
1472
- lazy: true,
1473
- modules: [Navigation, Pagination],
1474
- pagination: {
1475
- el: ".poi-pagination",
1476
- clickable: true
1477
- },
1478
- navigation: {
1479
- nextEl: ".poi-img-next",
1480
- prevEl: ".poi-img-prev"
1481
- }
1482
- });
1483
- }
1484
- slides.forEach(slide => this.poiSwiper.appendSlide(slide));
1485
- }
1486
- };
1487
- modalElm.addEventListener("shown.bs.modal", imgShowFunc, false);
1488
-
1489
- this.core.mapDivDocument.querySelector(".poi_address").innerText =
1490
- this.core.translate(data.address);
1491
- this.core.mapDivDocument.querySelector(".poi_desc").innerHTML = this.core
1492
- .translate(data.desc)
1493
- .replace(/\n/g, "<br>");
1494
- }
1495
- const modal = new bsn.Modal(modalElm, { root: this.core.mapDivDocument });
1496
- this.core.selectMarker(data.namespaceID);
1497
- const hideFunc = _event => {
1498
- modalElm.removeEventListener("hide.bs.modal", hideFunc, false);
1499
- this.core.unselectMarker();
1500
- };
1501
- const hiddenFunc = _event => {
1502
- modalElm.removeEventListener("hidden.bs.modal", hiddenFunc, false);
1503
- if (this.poiSwiper) {
1504
- this.poiSwiper.removeAllSlides();
1505
- this.poiSwiper = undefined;
1506
- }
1507
- };
1508
- modalElm.addEventListener("hide.bs.modal", hideFunc, false);
1509
- modalElm.addEventListener("hidden.bs.modal", hiddenFunc, false);
1510
- this.modalSetting("poi");
1511
- modal.show();
1512
- }
1513
-
1514
- showFillEnvelope(mapIDs) {
1515
- const ui = this;
1516
- if (mapIDs.length > 0) {
1517
- if (!ui._selectCandidateSources) ui._selectCandidateSources = {};
1518
- Object.keys(ui._selectCandidateSources).forEach(key => {
1519
- const index = mapIDs.indexOf(key);
1520
- if (index < 0) {
1521
- ui.core.mapObject.removeEnvelope(ui._selectCandidateSources[key]);
1522
- delete ui._selectCandidateSources[key];
1523
- } else mapIDs.splice(index, 1);
1524
- });
1525
-
1526
- mapIDs.forEach(mapID => {
1527
- if (mapID !== ui.core.from.mapID) {
1528
- const source = ui.core.cacheHash[mapID];
1529
- const xyPromises = source.envelope.geometry.coordinates[0].map(
1530
- coord => ui.core.from.merc2SysCoordAsync(coord)
1531
- );
1532
- const hexColor = source.envelopeColor;
1533
- let color = asArray(hexColor);
1534
- color = color.slice();
1535
- color[3] = 0.2;
1536
-
1537
- Promise.all(xyPromises).then(xys => {
1538
- ui._selectCandidateSources[mapID] =
1539
- ui.core.mapObject.setFillEnvelope(xys, null, { color });
1540
- });
1541
- }
1542
- });
1543
- } else {
1544
- if (ui._selectCandidateSources) {
1545
- Object.keys(ui._selectCandidateSources).forEach(key =>
1546
- ui.core.mapObject.removeEnvelope(ui._selectCandidateSources[key])
1547
- );
1548
- delete ui._selectCandidateSources;
1549
- }
1550
- }
1551
- }
1552
-
1553
- async xyToMapIDs(xy, threshold = 10) {
1554
- const ui = this;
1555
- const point_ = point(xy);
1556
-
1557
- const map = ui.core.mapObject;
1558
- const size = map.getSize();
1559
- const extent = [[0, 0], [size[0], 0], size, [0, size[1]], [0, 0]];
1560
- const sysCoords = extent.map(pixel => map.getCoordinateFromPixel(pixel));
1561
- const mercs = await (ui.core.from instanceof NowMap
1562
- ? Promise.resolve(sysCoords)
1563
- : Promise.all(
1564
- sysCoords.map(sysCoord => ui.core.from.sysCoord2MercAsync(sysCoord))
1565
- ));
1566
- const areaIndex = ui.areaIndex(mercs);
1567
-
1568
- return Promise.all(
1569
- Object.keys(ui.core.cacheHash)
1570
- .filter(key => ui.core.cacheHash[key].envelope)
1571
- .map(key => {
1572
- const source = ui.core.cacheHash[key];
1573
- return Promise.all([
1574
- Promise.resolve(source),
1575
- Promise.all(
1576
- source.envelope.geometry.coordinates[0].map(coord =>
1577
- ui.core.from.merc2SysCoordAsync(coord)
1578
- )
1579
- )
1580
- ]);
1581
- })
1582
- ).then(sources => {
1583
- const mapIDs = sources
1584
- .reduce((prev, curr) => {
1585
- const source = curr[0];
1586
- const mercXys = curr[1];
1587
- if (source.mapID !== ui.core.from.mapID) {
1588
- const polygon_ = polygon([mercXys]);
1589
- if (booleanPointInPolygon(point_, polygon_)) {
1590
- prev.push(source);
1591
- }
1592
- }
1593
- return prev;
1594
- }, [])
1595
- .filter(source => source.envelopeAreaIndex / areaIndex < threshold)
1596
- .sort((a, b) => a.envelopeAreaIndex - b.envelopeAreaIndex)
1597
- .map(source => source.mapID);
1598
- console.log(mapIDs);
1599
- return mapIDs;
1600
- });
1601
- }
1602
-
1603
- setShowBorder(flag) {
1604
- this.core.requestUpdateState({ showBorder: flag ? 1 : 0 });
1605
- this.updateEnvelope();
1606
- if (flag) {
1607
- this.core.mapDivDocument.classList.add("show-border");
1608
- } else {
1609
- this.core.mapDivDocument.classList.remove("show-border");
1610
- }
1611
- if (this.core.restoreSession) {
1612
- const currentTime = Math.floor(new Date().getTime() / 1000);
1613
- localStorage.setItem("epoch", currentTime); // eslint-disable-line no-undef
1614
- localStorage.setItem("showBorder", flag ? 1 : 0); // eslint-disable-line no-undef
1615
- }
1616
- }
1617
-
1618
- setHideMarker(flag) {
1619
- if (flag) {
1620
- this.core.hideAllMarkers();
1621
- this.core.mapDivDocument.classList.add("hide-marker");
1622
- } else {
1623
- this.core.showAllMarkers();
1624
- this.core.mapDivDocument.classList.remove("hide-marker");
1625
- }
1626
- }
1627
-
1628
- updateEnvelope() {
1629
- const ui = this;
1630
- if (!ui.core.mapObject) return;
1631
-
1632
- ui.core.mapObject.resetEnvelope();
1633
- delete ui._selectCandidateSources;
1634
-
1635
- if (ui.core.stateBuffer.showBorder) {
1636
- Object.keys(ui.core.cacheHash)
1637
- .filter(key => ui.core.cacheHash[key].envelope)
1638
- .map(key => {
1639
- const source = ui.core.cacheHash[key];
1640
- const xyPromises =
1641
- key === ui.core.from.mapID && source instanceof HistMap
1642
- ? [
1643
- [0, 0],
1644
- [source.width, 0],
1645
- [source.width, source.height],
1646
- [0, source.height],
1647
- [0, 0]
1648
- ].map(xy => Promise.resolve(source.xy2SysCoord(xy)))
1649
- : source.envelope.geometry.coordinates[0].map(coord =>
1650
- ui.core.from.merc2SysCoordAsync(coord)
1651
- );
1652
-
1653
- Promise.all(xyPromises).then(xys => {
1654
- ui.core.mapObject.setEnvelope(xys, {
1655
- color: source.envelopeColor,
1656
- width: 2,
1657
- lineDash: [6, 6]
1658
- });
1659
- });
1660
- });
1661
- }
1662
- }
1663
-
1664
- resolveRelativeLink(file, fallbackPath) {
1665
- if (!fallbackPath) fallbackPath = ".";
1666
- return file.match(/\//) ? file : `${fallbackPath}/${file}`;
1667
- }
1668
-
1669
- checkOverlayID(mapID) {
1670
- const ui = this;
1671
- const swiper = ui.overlaySwiper;
1672
- const sliders = swiper.$el[0].querySelectorAll(".swiper-slide");
1673
- for (let i = 0; i < sliders.length; i++) {
1674
- const slider = sliders[i];
1675
- if (slider.getAttribute("data") === mapID) {
1676
- return true;
1677
- }
1678
- }
1679
- return false;
1680
- }
1681
-
1682
- areaIndex(xys) {
1683
- return (
1684
- 0.5 *
1685
- Math.abs(
1686
- [0, 1, 2, 3].reduce((prev, curr, i) => {
1687
- const xy1 = xys[i];
1688
- const xy2 = xys[i + 1];
1689
- return prev + (xy1[0] - xy2[0]) * (xy1[1] + xy2[1]);
1690
- }, 0)
1691
- )
1692
- );
1693
- }
1694
-
1695
- ellips() {
1696
- const ui = this;
1697
- const omitMark = "…";
1698
- const omitLine = 2;
1699
- const stringSplit = function (element) {
1700
- const splitArr = element.innerText.split("");
1701
- let joinString = "";
1702
- for (let i = 0; i < splitArr.length; i++) {
1703
- joinString += `<span>${splitArr[i]}</span>`;
1704
- }
1705
- joinString += `<span class="omit-mark">${omitMark}</span>`;
1706
- element.innerHTML = joinString;
1707
- };
1708
- const omitCheck = function (element) {
1709
- const thisSpan = element.querySelectorAll("span");
1710
- const omitSpan = element.querySelector(".omit-mark");
1711
- let lineCount = 0;
1712
- let omitCount;
1713
-
1714
- if (omitLine <= 0) {
1715
- return;
1716
- }
1717
-
1718
- thisSpan[0].style.display = "";
1719
- for (let i = 1; i < thisSpan.length; i++) {
1720
- thisSpan[i].style.display = "none";
1721
- }
1722
- omitSpan.style.display = "";
1723
- let divHeight = element.offsetHeight;
1724
- let minimizeFont = false;
1725
- for (let i = 1; i < thisSpan.length - 1; i++) {
1726
- thisSpan[i].style.display = "";
1727
- if (element.offsetHeight > divHeight) {
1728
- if (!minimizeFont) {
1729
- minimizeFont = true;
1730
- element.classList.add("minimize");
1731
- } else {
1732
- divHeight = element.offsetHeight;
1733
- lineCount++;
1734
- }
1735
- }
1736
- if (lineCount >= omitLine) {
1737
- omitCount = i - 2;
1738
- break;
1739
- }
1740
- if (i >= thisSpan.length - 2) {
1741
- omitSpan.style.display = "none";
1742
- return;
1743
- }
1744
- }
1745
- for (let i = omitCount; i < thisSpan.length - 1; i++) {
1746
- thisSpan[i].style.display = "none";
1747
- }
1748
- };
1749
- const swiperItems =
1750
- ui.core.mapDivDocument.querySelectorAll(".swiper-slide div");
1751
- for (let i = 0; i < swiperItems.length; i++) {
1752
- const swiperItem = swiperItems[i];
1753
- stringSplit(swiperItem);
1754
- omitCheck(swiperItem);
1755
- }
1756
- }
1757
-
1758
- remove() {
1759
- this.core.remove();
1760
- delete this.core;
1761
- }
1762
- }