@maplat/ui 0.10.6 → 0.11.1

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