@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.
- package/README.md +38 -1
- package/assets/locales/de/translation.json +71 -0
- package/{locales → assets/locales}/en/translation.json +12 -6
- package/{locales → assets/locales}/ja/translation.json +12 -6
- package/{locales → assets/locales}/ko/translation.json +12 -6
- package/assets/locales/vi/translation.json +71 -0
- package/{locales → assets/locales}/zh/translation.json +12 -6
- package/{locales → assets/locales}/zh-TW/translation.json +12 -6
- package/assets/parts/attr.png +0 -0
- package/assets/parts/border.png +0 -0
- package/assets/parts/compass.png +0 -0
- package/assets/parts/gps.png +0 -0
- package/assets/parts/help.png +0 -0
- package/assets/parts/hide_marker.png +0 -0
- package/assets/parts/home.png +0 -0
- package/assets/parts/marker_list.png +0 -0
- package/assets/parts/share.png +0 -0
- package/dist/absolute_url.d.ts +1 -0
- package/dist/assets/locales/de/translation.json +71 -0
- package/dist/assets/locales/en/translation.json +12 -6
- package/dist/assets/locales/ja/translation.json +12 -6
- package/dist/assets/locales/ko/translation.json +12 -6
- package/dist/assets/locales/vi/translation.json +71 -0
- package/dist/assets/locales/zh/translation.json +12 -6
- package/dist/assets/locales/zh-TW/translation.json +12 -6
- package/dist/contextmenu.d.ts +5 -0
- package/dist/function.d.ts +2 -0
- package/dist/icons.d.ts +7 -0
- package/dist/index.d.ts +64 -0
- package/dist/maplat-ui.es.js +9383 -0
- package/dist/maplat-ui.umd.js +205 -0
- package/dist/maplat_control.d.ts +55 -0
- package/dist/pointer_images.d.ts +2 -0
- package/dist/swiper_ex.d.ts +2 -0
- package/dist/types.d.ts +173 -0
- package/dist/ui_init.d.ts +4 -0
- package/dist/ui_marker.d.ts +9 -0
- package/dist/ui_utils.d.ts +9 -0
- package/less/contextmenu.css +8 -0
- package/less/font-awesome.less +48 -28
- package/less/maplat-specific.less +452 -66
- package/less/swiper4.css +715 -0
- package/less/ui.less +5 -5
- package/less/ui_packed.less +3 -3
- package/package.json +107 -106
- package/src/{absolute_url.js → absolute_url.ts} +1 -1
- package/src/contextmenu/base.ts +170 -0
- package/src/contextmenu/constants.ts +66 -0
- package/src/contextmenu/cssVars.ts +13 -0
- package/src/contextmenu/helpers/dom.ts +295 -0
- package/src/contextmenu/helpers/mix.ts +120 -0
- package/src/contextmenu/html.ts +161 -0
- package/src/contextmenu/internal.ts +293 -0
- package/src/contextmenu.ts +40 -0
- package/src/function.ts +36 -0
- package/src/icons.ts +46 -0
- package/src/index.ts +520 -0
- package/src/maplat_control.ts +686 -0
- package/src/pointer_images.ts +101 -0
- package/src/{service-worker.js → service-worker/index.ts} +5 -6
- package/src/swiper_augment.d.ts +13 -0
- package/src/{swiper_ex.js → swiper_ex.ts} +14 -10
- package/src/types.d.ts +31 -0
- package/src/types.ts +202 -0
- package/src/ui_init.ts +1066 -0
- package/src/ui_marker.ts +376 -0
- package/src/ui_utils.ts +87 -0
- package/dist/assets/fonts/a8c0074cf70b152b56105e6c4b227bd8.woff +0 -0
- package/dist/assets/fonts/cfeff2e898a64ebe7e6b5ec078b174c3.woff +0 -0
- package/dist/assets/images/09c3ce5a86d600e24f8e85de3a019853.png +0 -0
- package/dist/assets/images/0beac2cb41dfab43ddfd9df80b32b85d.png +0 -0
- package/dist/assets/images/1354b4f40dd58bb0f2a4871cb4ff81d8.png +0 -0
- package/dist/assets/images/2a61e310e46b50b5f8ddd5e905ba9db9.png +0 -0
- package/dist/assets/images/3131423d782cd3ea89a81247065e7f9d.png +0 -0
- package/dist/assets/images/41b2cf0fa604d3f196ca52337d238219.jpg +0 -0
- package/dist/assets/images/558bc7e8b9b6c5f41a7141cddb8cdb5e.png +0 -0
- package/dist/assets/images/56f7003805ed02f8a21199947651db2e.png +0 -0
- package/dist/assets/images/5ba349e3596aca094c41c56966b45dc7.png +0 -0
- package/dist/assets/images/6111b8076a2cf81c73f0e46f41a3af60.png +0 -0
- package/dist/assets/images/6345ee67d554fbfbf484ba4035ad19d9.jpg +0 -0
- package/dist/assets/images/649fce122b354de2ac725ba5f2661955.png +0 -0
- package/dist/assets/images/6a580287dea82c2fb9b214321a375145.png +0 -0
- package/dist/assets/images/6c5dba7f7d76e74c3a8c7c5b1c3fc544.png +0 -0
- package/dist/assets/images/6e1f2f2f6fed3c5cddeb925e7ae75aba.png +0 -0
- package/dist/assets/images/799a0177b0dc540682fa4a2e349a8f4f.png +0 -0
- package/dist/assets/images/7bef6f357e921c43f4f800cfcb757872.png +0 -0
- package/dist/assets/images/7d9d643a903df6f57b8b7386316021e5.png +0 -0
- package/dist/assets/images/7df82bae917b68159f84998182f2fdc6.png +0 -0
- package/dist/assets/images/8e5d0335f6598b8d874ba23ea9fb295f.png +0 -0
- package/dist/assets/images/90c32e751366be22777f3fe40a53fe06.png +0 -0
- package/dist/assets/images/9247459937b9c882303962e42bd8d989.png +0 -0
- package/dist/assets/images/927c34e7b9b2f95c82ba477993117eaf.png +0 -0
- package/dist/assets/images/95e9ca8285131f8ccb6da5052093173c.png +0 -0
- package/dist/assets/images/9a243e0cb0fc43e2a016d5d3aaa330d5.png +0 -0
- package/dist/assets/images/9ac6d81f417d6a5626b7c8d5a087c32b.png +0 -0
- package/dist/assets/images/9d3a01c866095b8b3e8e63f9cf11dd51.png +0 -0
- package/dist/assets/images/9df733bcb29a746cb16b47eedea9fc3a.png +0 -0
- package/dist/assets/images/acc6eab0ba9c470ae20fb4b74135e865.png +0 -0
- package/dist/assets/images/b9ae27f0a01228380dff76a33b605707.jpg +0 -0
- package/dist/assets/images/ba48b220f61a6e1028f1854326f43acd.png +0 -0
- package/dist/assets/images/bf67cc860289b85c0402a4d4f890a3bd.png +0 -0
- package/dist/assets/images/c49f2344772e33256ba24d64b59b20d1.png +0 -0
- package/dist/assets/images/ca6b77b234b18e7bb9b1ccda774da286.png +0 -0
- package/dist/assets/images/cd213169df16398b0017450e31788d73.png +0 -0
- package/dist/assets/images/f101a0974972eeab41189185a5c5b225.png +0 -0
- package/dist/assets/images/f115726e6249018905cca51653e1262c.png +0 -0
- package/dist/assets/images/f7acb820d978ab2dd69e8bf695c574d1.png +0 -0
- package/dist/assets/images/ffea4dd10bf2506aa1e0cd4c61426b42.png +0 -0
- package/dist/assets/maplat.css +0 -19
- package/dist/assets/maplat.css.map +0 -1
- package/dist/assets/maplat.js +0 -3
- package/dist/assets/maplat.js.LICENSE.txt +0 -43
- package/dist/assets/maplat.js.map +0 -1
- package/dist/index.html +0 -39
- package/dist/service-worker.js +0 -3
- package/dist/service-worker.js.LICENSE.txt +0 -1
- package/dist/service-worker.js.map +0 -1
- package/fonts/clarenbd-webfont.woff +0 -0
- package/fonts/fontawesome-webfont.woff +0 -0
- package/legacy/bootstrap-native.js +0 -1935
- package/legacy/detect-element-resize.js +0 -153
- package/legacy/iziToast.js +0 -1301
- package/legacy/page.js +0 -1153
- package/legacy/qrcode.js +0 -616
- package/legacy/sprintf.js +0 -285
- package/less/font-face.less +0 -11
- package/less/font-face_packed.less +0 -11
- package/parts/attr.png +0 -0
- package/parts/blue_marker.png +0 -0
- package/parts/bluedot.png +0 -0
- package/parts/bluedot_small.png +0 -0
- package/parts/bluedot_transparent.png +0 -0
- package/parts/border.png +0 -0
- package/parts/compass.png +0 -0
- package/parts/defaultpin.png +0 -0
- package/parts/defaultpin_selected.png +0 -0
- package/parts/gps.png +0 -0
- package/parts/gsi.jpg +0 -0
- package/parts/gsi_ortho.jpg +0 -0
- package/parts/help.png +0 -0
- package/parts/hide_marker.png +0 -0
- package/parts/home.png +0 -0
- package/parts/osm.jpg +0 -0
- package/parts/red_marker.png +0 -0
- package/parts/redcircle.png +0 -0
- package/parts/share.png +0 -0
- package/src/contextmenu.js +0 -29
- package/src/freeze_locales.js +0 -337
- package/src/function.js +0 -22
- package/src/index.js +0 -1762
- package/src/index_packed.js +0 -8
- package/src/maplat_control.js +0 -814
- package/src/pointer_images.js +0 -81
- /package/{parts → assets/parts}/Maplat.png +0 -0
- /package/{parts → assets/parts}/all_right_reserved.png +0 -0
- /package/{parts → assets/parts}/basemap.png +0 -0
- /package/{parts → assets/parts}/cc0.png +0 -0
- /package/{parts → assets/parts}/cc_by-nc-nd.png +0 -0
- /package/{parts → assets/parts}/cc_by-nc-sa.png +0 -0
- /package/{parts → assets/parts}/cc_by-nc.png +0 -0
- /package/{parts → assets/parts}/cc_by-nd.png +0 -0
- /package/{parts → assets/parts}/cc_by-sa.png +0 -0
- /package/{parts → assets/parts}/cc_by.png +0 -0
- /package/{parts → assets/parts}/favicon.png +0 -0
- /package/{parts → assets/parts}/fullscreen.png +0 -0
- /package/{parts → assets/parts}/loading.png +0 -0
- /package/{parts → assets/parts}/loading_image.png +0 -0
- /package/{parts → assets/parts}/minus.png +0 -0
- /package/{parts → assets/parts}/no_image.png +0 -0
- /package/{parts → assets/parts}/overlay.png +0 -0
- /package/{parts → assets/parts}/pd.png +0 -0
- /package/{parts → assets/parts}/plus.png +0 -0
- /package/{parts → assets/parts}/slider.png +0 -0
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { CSS_VARS, EVENT_TYPE } from "./constants";
|
|
2
|
+
import {
|
|
3
|
+
find,
|
|
4
|
+
addClass,
|
|
5
|
+
removeClass,
|
|
6
|
+
getViewportSize,
|
|
7
|
+
offset
|
|
8
|
+
} from "./helpers/dom";
|
|
9
|
+
import { Map, MapEvent } from "ol";
|
|
10
|
+
import { Coordinate } from "ol/coordinate";
|
|
11
|
+
import { Pixel } from "ol/pixel";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @class Internal
|
|
15
|
+
*/
|
|
16
|
+
export class Internal {
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
Base: any;
|
|
19
|
+
map: Map | undefined;
|
|
20
|
+
viewport: HTMLElement | undefined;
|
|
21
|
+
coordinateClicked: Coordinate | undefined;
|
|
22
|
+
pixelClicked: Pixel | undefined;
|
|
23
|
+
lineHeight: number;
|
|
24
|
+
items: Record<string, import("../types").ContextMenuInternalItem>;
|
|
25
|
+
opened: boolean;
|
|
26
|
+
submenu: { left: string; top: string; lastLeft: string; lastTop: string };
|
|
27
|
+
eventHandler: (evt: Event) => void;
|
|
28
|
+
eventMapMoveHandler: (evt: MapEvent) => void;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @constructor
|
|
32
|
+
* @param {Function} base Base class.
|
|
33
|
+
*/
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
+
constructor(base: any) {
|
|
36
|
+
/**
|
|
37
|
+
* @type {ol.control.Control}
|
|
38
|
+
*/
|
|
39
|
+
this.Base = base;
|
|
40
|
+
/**
|
|
41
|
+
* @type {ol.Map}
|
|
42
|
+
*/
|
|
43
|
+
this.map = undefined;
|
|
44
|
+
/**
|
|
45
|
+
* @type {Element}
|
|
46
|
+
*/
|
|
47
|
+
this.viewport = undefined;
|
|
48
|
+
/**
|
|
49
|
+
* @type {ol.Coordinate}
|
|
50
|
+
*/
|
|
51
|
+
this.coordinateClicked = undefined;
|
|
52
|
+
/**
|
|
53
|
+
* @type {ol.Pixel}
|
|
54
|
+
*/
|
|
55
|
+
this.pixelClicked = undefined;
|
|
56
|
+
/**
|
|
57
|
+
* @type {Number}
|
|
58
|
+
*/
|
|
59
|
+
this.lineHeight = 0;
|
|
60
|
+
/**
|
|
61
|
+
* @type {Object}
|
|
62
|
+
*/
|
|
63
|
+
this.items = {};
|
|
64
|
+
/**
|
|
65
|
+
* @type {Boolean}
|
|
66
|
+
*/
|
|
67
|
+
this.opened = false;
|
|
68
|
+
/**
|
|
69
|
+
* @type {Object}
|
|
70
|
+
*/
|
|
71
|
+
this.submenu = {
|
|
72
|
+
left: `${base.options.width - 15}px`,
|
|
73
|
+
lastLeft: "", // string + px
|
|
74
|
+
top: "0px",
|
|
75
|
+
lastTop: ""
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* @type {Function}
|
|
79
|
+
*/
|
|
80
|
+
this.eventHandler = this.handleEvent.bind(this) as unknown as (
|
|
81
|
+
evt: Event
|
|
82
|
+
) => void;
|
|
83
|
+
/**
|
|
84
|
+
* @type {Function}
|
|
85
|
+
*/
|
|
86
|
+
this.eventMapMoveHandler = this.handleMapMoveEvent.bind(this);
|
|
87
|
+
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
init(map: import("ol").Map) {
|
|
92
|
+
this.map = map;
|
|
93
|
+
this.viewport = map.getViewport();
|
|
94
|
+
this.setListeners();
|
|
95
|
+
this.Base.Html.createMenu();
|
|
96
|
+
|
|
97
|
+
this.lineHeight =
|
|
98
|
+
this.getItemsLength() > 0
|
|
99
|
+
? this.Base.container.offsetHeight / this.getItemsLength()
|
|
100
|
+
: this.Base.Html.cloneAndGetLineHeight();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
getItemsLength() {
|
|
104
|
+
let count = 0;
|
|
105
|
+
Object.keys(this.items).forEach(k => {
|
|
106
|
+
if (this.items[k].submenu || this.items[k].separator) return;
|
|
107
|
+
count++;
|
|
108
|
+
});
|
|
109
|
+
return count;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
getPixelClicked() {
|
|
113
|
+
return this.pixelClicked;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
getCoordinateClicked() {
|
|
117
|
+
return this.coordinateClicked;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
positionContainer(pixel: import("ol/pixel").Pixel) {
|
|
121
|
+
const container = this.Base.container as HTMLElement;
|
|
122
|
+
const mapSize = this.map!.getSize();
|
|
123
|
+
if (!mapSize) return;
|
|
124
|
+
// how much (width) space left over
|
|
125
|
+
const space_left_h = mapSize[1] - pixel[1];
|
|
126
|
+
// how much (height) space left over
|
|
127
|
+
const space_left_w = mapSize[0] - pixel[0];
|
|
128
|
+
|
|
129
|
+
const menuSize = {
|
|
130
|
+
w: container.offsetWidth,
|
|
131
|
+
// a cheap way to recalculate container height
|
|
132
|
+
// since offsetHeight is like cached
|
|
133
|
+
h: Math.round(this.lineHeight * this.getItemsLength())
|
|
134
|
+
};
|
|
135
|
+
// submenus
|
|
136
|
+
const subs = find(
|
|
137
|
+
`li.${CSS_VARS.submenu}>div`,
|
|
138
|
+
container,
|
|
139
|
+
true
|
|
140
|
+
) as HTMLElement[];
|
|
141
|
+
|
|
142
|
+
if (space_left_w >= menuSize.w) {
|
|
143
|
+
container.style.right = "auto";
|
|
144
|
+
container.style.left = `${pixel[0] + 5}px`;
|
|
145
|
+
} else {
|
|
146
|
+
container.style.left = "auto";
|
|
147
|
+
container.style.right = "15px";
|
|
148
|
+
}
|
|
149
|
+
// set top or bottom
|
|
150
|
+
if (space_left_h >= menuSize.h) {
|
|
151
|
+
container.style.bottom = "auto";
|
|
152
|
+
container.style.top = `${pixel[1] - 10}px`;
|
|
153
|
+
} else {
|
|
154
|
+
container.style.top = "auto";
|
|
155
|
+
container.style.bottom = "0px";
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
removeClass(container, CSS_VARS.hidden, null);
|
|
159
|
+
|
|
160
|
+
if (subs.length) {
|
|
161
|
+
if (space_left_w < menuSize.w * 2) {
|
|
162
|
+
// no space (at right) for submenu
|
|
163
|
+
// position them at left
|
|
164
|
+
this.submenu.lastLeft = `-${menuSize.w}px`;
|
|
165
|
+
} else {
|
|
166
|
+
this.submenu.lastLeft = this.submenu.left;
|
|
167
|
+
}
|
|
168
|
+
subs.forEach((sub: HTMLElement) => {
|
|
169
|
+
// is there enough space for submenu height?
|
|
170
|
+
const viewport = getViewportSize();
|
|
171
|
+
const sub_offset = offset(sub);
|
|
172
|
+
const sub_height = sub_offset.height;
|
|
173
|
+
let sub_top = space_left_h - sub_height;
|
|
174
|
+
|
|
175
|
+
if (sub_top < 0) {
|
|
176
|
+
sub_top = sub_height - (viewport.h - sub_offset.top);
|
|
177
|
+
sub.style.top = `-${sub_top}px`;
|
|
178
|
+
}
|
|
179
|
+
sub.style.left = this.submenu.lastLeft;
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
openMenu(
|
|
185
|
+
pixel: import("ol/pixel").Pixel,
|
|
186
|
+
coordinate: import("ol/coordinate").Coordinate
|
|
187
|
+
) {
|
|
188
|
+
this.Base.dispatchEvent({
|
|
189
|
+
type: EVENT_TYPE.OPEN,
|
|
190
|
+
pixel,
|
|
191
|
+
coordinate
|
|
192
|
+
});
|
|
193
|
+
this.opened = true;
|
|
194
|
+
this.positionContainer(pixel);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
closeMenu() {
|
|
198
|
+
this.opened = false;
|
|
199
|
+
addClass(this.Base.container, CSS_VARS.hidden, null);
|
|
200
|
+
this.Base.dispatchEvent({
|
|
201
|
+
type: EVENT_TYPE.CLOSE
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
setListeners() {
|
|
206
|
+
this.viewport!.addEventListener(
|
|
207
|
+
this.Base.options.eventType,
|
|
208
|
+
this.eventHandler,
|
|
209
|
+
false
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
if (this.map) this.map.on("movestart", this.eventMapMoveHandler);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
removeListeners() {
|
|
216
|
+
this.viewport!.removeEventListener(
|
|
217
|
+
this.Base.options.eventType,
|
|
218
|
+
this.eventHandler,
|
|
219
|
+
|
|
220
|
+
false
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
if (this.map) this.map.un("movestart", this.eventMapMoveHandler);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
handleEvent(evt: Event) {
|
|
227
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
228
|
+
const this_ = this;
|
|
229
|
+
if (!this.map) return;
|
|
230
|
+
|
|
231
|
+
this.coordinateClicked = this.map.getEventCoordinate(evt as any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
232
|
+
this.pixelClicked = this.map.getEventPixel(evt as any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
233
|
+
|
|
234
|
+
this.Base.dispatchEvent({
|
|
235
|
+
type: EVENT_TYPE.BEFOREOPEN,
|
|
236
|
+
pixel: this.pixelClicked,
|
|
237
|
+
coordinate: this.coordinateClicked
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
if (this.Base.disabled) return;
|
|
241
|
+
|
|
242
|
+
if (this.Base.options.eventType === EVENT_TYPE.CONTEXTMENU) {
|
|
243
|
+
// don't be intrusive with other event types
|
|
244
|
+
evt.stopPropagation();
|
|
245
|
+
evt.preventDefault();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
this.openMenu(this.pixelClicked, this.coordinateClicked);
|
|
249
|
+
|
|
250
|
+
//one-time fire
|
|
251
|
+
if (evt.target)
|
|
252
|
+
evt.target.addEventListener(
|
|
253
|
+
"pointerdown",
|
|
254
|
+
{
|
|
255
|
+
handleEvent: (e: Event) => {
|
|
256
|
+
if (this_.opened) {
|
|
257
|
+
this_.closeMenu();
|
|
258
|
+
e.stopPropagation();
|
|
259
|
+
if (evt.target)
|
|
260
|
+
evt.target.removeEventListener(e.type, this, false);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
false
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
handleMapMoveEvent(_evt: import("ol").MapEvent) {
|
|
269
|
+
this.closeMenu();
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
setItemListener(li: HTMLElement, index: string) {
|
|
273
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
274
|
+
const this_ = this;
|
|
275
|
+
if (li && typeof this.items[index].callback === "function") {
|
|
276
|
+
(function (callback) {
|
|
277
|
+
li.addEventListener(
|
|
278
|
+
"click",
|
|
279
|
+
(evt: Event) => {
|
|
280
|
+
evt.preventDefault();
|
|
281
|
+
const obj = {
|
|
282
|
+
coordinate: this_.getCoordinateClicked()!,
|
|
283
|
+
data: this_.items[index].data || null
|
|
284
|
+
};
|
|
285
|
+
this_.closeMenu();
|
|
286
|
+
callback(obj, this_.map);
|
|
287
|
+
},
|
|
288
|
+
false
|
|
289
|
+
);
|
|
290
|
+
})(this.items[index].callback);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import ContextMenuBase from "./contextmenu/base";
|
|
2
|
+
import { ContextMenuOptions } from "./types";
|
|
3
|
+
|
|
4
|
+
export default class ContextMenu extends ContextMenuBase {
|
|
5
|
+
constructor(options: ContextMenuOptions = {}) {
|
|
6
|
+
super(options);
|
|
7
|
+
const internal = this.Internal;
|
|
8
|
+
|
|
9
|
+
internal.setItemListener = (li: HTMLElement, index: string) => {
|
|
10
|
+
const this_ = internal;
|
|
11
|
+
if (
|
|
12
|
+
li &&
|
|
13
|
+
internal.items[index] &&
|
|
14
|
+
typeof internal.items[index].callback === "function"
|
|
15
|
+
) {
|
|
16
|
+
(function (callback) {
|
|
17
|
+
li.addEventListener("pointerdown", (evt: Event) => {
|
|
18
|
+
evt.stopPropagation();
|
|
19
|
+
});
|
|
20
|
+
li.addEventListener(
|
|
21
|
+
"click",
|
|
22
|
+
(evt: Event) => {
|
|
23
|
+
evt.preventDefault();
|
|
24
|
+
const obj = {
|
|
25
|
+
coordinate: this_.getCoordinateClicked() || [],
|
|
26
|
+
data: this_.items[index].data || null
|
|
27
|
+
};
|
|
28
|
+
if (callback) {
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
+
const result: any = callback(obj, this_.map);
|
|
31
|
+
if (!result) this_.closeMenu();
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
false
|
|
35
|
+
);
|
|
36
|
+
})(internal.items[index].callback);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
package/src/function.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// @ts-expect-error - Module uses internal API - Module uses internal API
|
|
2
|
+
import { normalizeArg as normalizeArg_ } from "@maplat/core/dist/functions";
|
|
3
|
+
|
|
4
|
+
export function normalizeArg(
|
|
5
|
+
options: Record<string, unknown>
|
|
6
|
+
): Record<string, unknown> {
|
|
7
|
+
const table: Record<string, string> = {
|
|
8
|
+
state_url: "stateUrl",
|
|
9
|
+
restore_session: "restoreSession",
|
|
10
|
+
enable_share: "enableShare",
|
|
11
|
+
mobile_if: "mobileIF",
|
|
12
|
+
pwa_manifest: "pwaManifest",
|
|
13
|
+
pwa_worker: "pwaWorker",
|
|
14
|
+
pwa_scope: "pwaScope",
|
|
15
|
+
presentation_mode: "presentationMode"
|
|
16
|
+
};
|
|
17
|
+
options = normalizeArg_(options);
|
|
18
|
+
|
|
19
|
+
return Object.keys(table).reduce(
|
|
20
|
+
(opt: Record<string, unknown>, key: string) => {
|
|
21
|
+
if (opt[key] !== undefined) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
`Invalid Maplat option key: ${key}. Use "${table[key]}" instead.`
|
|
24
|
+
);
|
|
25
|
+
//opt[table[key]] = opt[key];
|
|
26
|
+
//delete opt[key];
|
|
27
|
+
}
|
|
28
|
+
return opt;
|
|
29
|
+
},
|
|
30
|
+
options
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function getUniqueId(prefix: string = "id_") {
|
|
35
|
+
return prefix + Math.random().toString(36).substr(2, 9);
|
|
36
|
+
}
|
package/src/icons.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export const icons: { [key: string]: { viewBox: string; path: string } } = {
|
|
2
|
+
house: {
|
|
3
|
+
viewBox: "0 0 512 512",
|
|
4
|
+
path: "M240 6.1c9.1-8.2 22.9-8.2 32 0l232 208c9.9 8.8 10.7 24 1.8 33.9s-24 10.7-33.9 1.8l-8-7.2 0 205.3c0 35.3-28.7 64-64 64l-288 0c-35.3 0-64-28.7-64-64l0-205.3-8 7.2c-9.9 8.8-25 8-33.9-1.8s-8-25 1.8-33.9L240 6.1zm16 50.1L96 199.7 96 448c0 8.8 7.2 16 16 16l48 0 0-104c0-39.8 32.2-72 72-72l48 0c39.8 0 72 32.2 72 72l0 104 48 0c8.8 0 16-7.2 16-16l0-248.3-160-143.4zM208 464l96 0 0-104c0-13.3-10.7-24-24-24l-48 0c-13.3 0-24 10.7-24 24l0 104z"
|
|
5
|
+
},
|
|
6
|
+
"location-crosshairs": {
|
|
7
|
+
viewBox: "0 0 576 512",
|
|
8
|
+
path: "M288-16c17.7 0 32 14.3 32 32l0 18.3c98.1 14 175.7 91.6 189.7 189.7l18.3 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-18.3 0c-14 98.1-91.6 175.7-189.7 189.7l0 18.3c0 17.7-14.3 32-32 32s-32-14.3-32-32l0-18.3C157.9 463.7 80.3 386.1 66.3 288L48 288c-17.7 0-32-14.3-32-32s14.3-32 32-32l18.3 0C80.3 125.9 157.9 48.3 256 34.3L256 16c0-17.7 14.3-32 32-32zM128 256a160 160 0 1 0 320 0 160 160 0 1 0 -320 0zm160-96a96 96 0 1 1 0 192 96 96 0 1 1 0-192z"
|
|
9
|
+
},
|
|
10
|
+
compass: {
|
|
11
|
+
viewBox: "0 0 512 512",
|
|
12
|
+
path: "M464 256a208 208 0 1 0 -416 0 208 208 0 1 0 416 0zM0 256a256 256 0 1 1 512 0 256 256 0 1 1 -512 0zm306.7 69.1L162.4 380.6c-19.4 7.5-38.5-11.6-31-31l55.5-144.3c3.3-8.5 9.9-15.1 18.4-18.4l144.3-55.5c19.4-7.5 38.5 11.6 31 31L325.1 306.7c-3.3 8.5-9.9 15.1-18.4 18.4zM288 256a32 32 0 1 0 -64 0 32 32 0 1 0 64 0z"
|
|
13
|
+
},
|
|
14
|
+
"share-from-square": {
|
|
15
|
+
viewBox: "0 0 576 512",
|
|
16
|
+
path: "M425.5 7c-6.9-6.9-17.2-8.9-26.2-5.2S384.5 14.3 384.5 24l0 56-48 0c-88.4 0-160 71.6-160 160 0 46.7 20.7 80.4 43.6 103.4 8.1 8.2 16.5 14.9 24.3 20.4 9.2 6.5 21.7 5.7 30.1-1.9s10.2-20 4.5-29.8c-3.6-6.3-6.5-14.9-6.5-26.7 0-36.2 29.3-65.5 65.5-65.5l46.5 0 0 56c0 9.7 5.8 18.5 14.8 22.2s19.3 1.7 26.2-5.2l136-136c9.4-9.4 9.4-24.6 0-33.9L425.5 7zm7 97l0-22.1 78.1 78.1-78.1 78.1 0-22.1c0-13.3-10.7-24-24-24L338 192c-50.9 0-93.9 33.5-108.3 79.6-3.3-9.4-5.2-19.8-5.2-31.6 0-61.9 50.1-112 112-112l72 0c13.3 0 24-10.7 24-24zm-320-8c-44.2 0-80 35.8-80 80l0 256c0 44.2 35.8 80 80 80l256 0c44.2 0 80-35.8 80-80l0-24c0-13.3-10.7-24-24-24s-24 10.7-24 24l0 24c0 17.7-14.3 32-32 32l-256 0c-17.7 0-32-14.3-32-32l0-256c0-17.7 14.3-32 32-32l24 0c13.3 0 24-10.7 24-24s-10.7-24-24-24l-24 0z"
|
|
17
|
+
},
|
|
18
|
+
"layer-group": {
|
|
19
|
+
viewBox: "0 0 512 512",
|
|
20
|
+
path: "M232.5 5.2c14.9-6.9 32.1-6.9 47 0l218.6 101c8.5 3.9 13.9 12.4 13.9 21.8s-5.4 17.9-13.9 21.8l-218.6 101c-14.9 6.9-32.1 6.9-47 0L13.9 149.8C5.4 145.8 0 137.3 0 128s5.4-17.9 13.9-21.8L232.5 5.2zM48.1 218.4l164.3 75.9c27.7 12.8 59.6 12.8 87.3 0l164.3-75.9 34.1 15.8c8.5 3.9 13.9 12.4 13.9 21.8s-5.4 17.9-13.9 21.8l-218.6 101c-14.9 6.9-32.1 6.9-47 0L13.9 277.8C5.4 273.8 0 265.3 0 256s5.4-17.9 13.9-21.8l34.1-15.8zM13.9 362.2l34.1-15.8 164.3 75.9c27.7 12.8 59.6 12.8 87.3 0l164.3-75.9 34.1 15.8c8.5 3.9 13.9 12.4 13.9 21.8s-5.4 17.9-13.9 21.8l-218.6 101c-14.9 6.9-32.1 6.9-47 0L13.9 405.8C5.4 401.8 0 393.3 0 384s5.4-17.9 13.9-21.8z"
|
|
21
|
+
},
|
|
22
|
+
"circle-question": {
|
|
23
|
+
viewBox: "0 0 512 512",
|
|
24
|
+
path: "M464 256a208 208 0 1 0 -416 0 208 208 0 1 0 416 0zM0 256a256 256 0 1 1 512 0 256 256 0 1 1 -512 0zm256-80c-17.7 0-32 14.3-32 32 0 13.3-10.7 24-24 24s-24-10.7-24-24c0-44.2 35.8-80 80-80s80 35.8 80 80c0 47.2-36 67.2-56 74.5l0 3.8c0 13.3-10.7 24-24 24s-24-10.7-24-24l0-8.1c0-20.5 14.8-35.2 30.1-40.2 6.4-2.1 13.2-5.5 18.2-10.3 4.3-4.2 7.7-10 7.7-19.6 0-17.7-14.3-32-32-32zM224 368a32 32 0 1 1 64 0 32 32 0 1 1 -64 0z"
|
|
25
|
+
},
|
|
26
|
+
"circle-info": {
|
|
27
|
+
viewBox: "0 0 512 512",
|
|
28
|
+
path: "M256 512a256 256 0 1 0 0-512 256 256 0 1 0 0 512zM224 160a32 32 0 1 1 64 0 32 32 0 1 1 -64 0zm-8 64l48 0c13.3 0 24 10.7 24 24l0 88 8 0c13.3 0 24 10.7 24 24s-10.7 24-24 24l-80 0c-13.3 0-24-10.7-24-24s10.7-24 24-24l24 0 0-64-24 0c-13.3 0-24-10.7-24-24s10.7-24 24-24z"
|
|
29
|
+
},
|
|
30
|
+
"map-pin": {
|
|
31
|
+
viewBox: "0 0 320 512",
|
|
32
|
+
path: "M192 284.4C256.1 269.9 304 212.5 304 144 304 64.5 239.5 0 160 0S16 64.5 16 144c0 68.5 47.9 125.9 112 140.4L128 480c0 17.7 14.3 32 32 32s32-14.3 32-32l0-195.6zM168 96c-30.9 0-56 25.1-56 56 0 13.3-10.7 24-24 24s-24-10.7-24-24c0-57.4 46.6-104 104-104 13.3 0 24 10.7 24 24s-10.7 24-24 24z"
|
|
33
|
+
},
|
|
34
|
+
list: {
|
|
35
|
+
viewBox: "0 0 512 512",
|
|
36
|
+
path: "M40 48C26.7 48 16 58.7 16 72l0 48c0 13.3 10.7 24 24 24l48 0c13.3 0 24-10.7 24-24l0-48c0-13.3-10.7-24-24-24L40 48zM192 64c-17.7 0-32 14.3-32 32s14.3 32 32 32l288 0c17.7 0 32-14.3 32-32s-14.3-32-32-32L192 64zm0 160c-17.7 0-32 14.3-32 32s14.3 32 32 32l288 0c17.7 0 32-14.3 32-32s-14.3-32-32-32l-288 0zm0 160c-17.7 0-32 14.3-32 32s14.3 32 32 32l288 0c17.7 0 32-14.3 32-32s-14.3-32-32-32l-288 0zM16 232l0 48c0 13.3 10.7 24 24 24l48 0c13.3 0 24-10.7 24-24l0-48c0-13.3-10.7-24-24-24l-48 0c-13.3 0-24 10.7-24 24zM40 368c-13.3 0-24 10.7-24 24l0 48c0 13.3 10.7 24 24 24l48 0c13.3 0 24-10.7 24-24l0-48c0-13.3-10.7-24-24-24l-48 0z"
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export function getIcon(name: string, cls: string = ""): string {
|
|
41
|
+
const icon = icons[name];
|
|
42
|
+
if (!icon) return "";
|
|
43
|
+
// fa-lg is ~1.33em. We use 1em as base and let CSS font-size scale it.
|
|
44
|
+
// Add standardized styles to behave like an icon font.
|
|
45
|
+
return `<svg class="${cls}" viewBox="${icon.viewBox}" xmlns="http://www.w3.org/2000/svg" style="fill: currentColor; height: 1em; width: 1em; vertical-align: -0.125em;"><path d="${icon.path}" /></svg>`;
|
|
46
|
+
}
|