@geolonia/embed 5.0.0 → 5.0.3
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/.github/workflows/build.yml +16 -14
- package/.nvmrc +1 -1
- package/.prettierrc.json +4 -0
- package/.tool-versions +1 -1
- package/README.md +7 -1
- package/dist/embed +1 -1
- package/dist/embed-chunks/2489af4328c51b71e92d.js +2 -0
- package/dist/embed-chunks/6e05bbf5f391fda5b858.js +1 -0
- package/dist/embed.js +1 -1
- package/dist/src/embed.d.ts +3 -1
- package/dist/src/lib/geolonia-map.d.ts +1 -2
- package/dist/src/lib/geolonia-marker.d.ts +1 -2
- package/dist/src/lib/util.d.ts +1 -0
- package/dist/src/version.d.ts +1 -1
- package/e2e/map.spec.ts +1 -1
- package/eslint.config.js +232 -0
- package/package.json +20 -11
- package/src/embed.ts +13 -7
- package/src/lib/CustomAttributionControl.ts +52 -29
- package/src/lib/geolonia-map.ts +126 -39
- package/src/lib/geolonia-marker.ts +9 -6
- package/src/lib/keyring.test.ts +18 -0
- package/src/lib/keyring.ts +11 -13
- package/src/lib/maplibre-util.ts +31 -19
- package/src/lib/parse-atts.test.ts +3 -4
- package/src/lib/parse-atts.ts +1 -1
- package/src/lib/render.ts +18 -7
- package/src/lib/simplestyle-vector.ts +42 -13
- package/src/lib/simplestyle.test.ts +80 -69
- package/src/lib/simplestyle.ts +55 -34
- package/src/lib/util.test.ts +71 -22
- package/src/lib/util.ts +88 -32
- package/src/testability.test.ts +7 -4
- package/webpack.config.js +10 -1
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -17
- package/.prettierrc.js +0 -1
- package/dist/embed-chunks/416af3373e37004e65f4.js +0 -1
- package/dist/embed-chunks/488aacb380a87ea633f6.js +0 -2
- /package/dist/embed-chunks/{488aacb380a87ea633f6.js.LICENSE.txt → 2489af4328c51b71e92d.js.LICENSE.txt} +0 -0
package/src/lib/geolonia-map.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
import maplibregl, {
|
|
1
|
+
import maplibregl, {
|
|
2
|
+
FullscreenControl,
|
|
3
|
+
GeolocateControl,
|
|
4
|
+
NavigationControl,
|
|
5
|
+
Popup,
|
|
6
|
+
ScaleControl,
|
|
7
|
+
MapOptions,
|
|
8
|
+
PointLike,
|
|
9
|
+
StyleOptions,
|
|
10
|
+
StyleSpecification,
|
|
11
|
+
StyleSwapOptions,
|
|
12
|
+
GetResourceResponse,
|
|
13
|
+
} from 'maplibre-gl';
|
|
2
14
|
import Marker from './geolonia-marker';
|
|
3
15
|
import { GeoloniaControl } from './controls/geolonia-control';
|
|
4
16
|
import CustomAttributionControl from './CustomAttributionControl';
|
|
@@ -8,9 +20,20 @@ import parseAtts from './parse-atts';
|
|
|
8
20
|
import { SimpleStyle } from './simplestyle';
|
|
9
21
|
import SimpleStyleVector from './simplestyle-vector';
|
|
10
22
|
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
23
|
+
import {
|
|
24
|
+
getContainer,
|
|
25
|
+
getOptions,
|
|
26
|
+
getSessionId,
|
|
27
|
+
getStyle,
|
|
28
|
+
handleRestrictedMode,
|
|
29
|
+
isScrollable,
|
|
30
|
+
parseControlOption,
|
|
31
|
+
parseSimpleVector,
|
|
32
|
+
handleErrorMode,
|
|
33
|
+
loadImageCompatibility,
|
|
34
|
+
GetImageCallback,
|
|
35
|
+
isGeoloniaTilesHost,
|
|
36
|
+
} from './util';
|
|
14
37
|
|
|
15
38
|
export type GeoloniaMapOptions = MapOptions & { interactive?: boolean };
|
|
16
39
|
|
|
@@ -30,7 +53,7 @@ const isCssSelector = (string) => {
|
|
|
30
53
|
} else {
|
|
31
54
|
try {
|
|
32
55
|
return document.querySelector(string);
|
|
33
|
-
} catch
|
|
56
|
+
} catch {
|
|
34
57
|
return false;
|
|
35
58
|
}
|
|
36
59
|
}
|
|
@@ -46,14 +69,17 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
46
69
|
private __styleExtensionLoadRequired: boolean;
|
|
47
70
|
|
|
48
71
|
constructor(params: string | GeoloniaMapOptions) {
|
|
49
|
-
|
|
50
72
|
const container = getContainer(params) as Container | false;
|
|
51
73
|
|
|
52
74
|
if (!container) {
|
|
53
75
|
if (typeof params === 'string') {
|
|
54
|
-
throw new Error(
|
|
76
|
+
throw new Error(
|
|
77
|
+
`[Geolonia] No HTML elements found matching \`${params}\`. Please ensure the map container element exists.`,
|
|
78
|
+
);
|
|
55
79
|
} else {
|
|
56
|
-
throw new Error(
|
|
80
|
+
throw new Error(
|
|
81
|
+
'[Geolonia] No HTML elements found. Please ensure the map container element exists.',
|
|
82
|
+
);
|
|
57
83
|
}
|
|
58
84
|
}
|
|
59
85
|
|
|
@@ -63,10 +89,14 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
63
89
|
|
|
64
90
|
if (container.clientHeight === 0) {
|
|
65
91
|
// eslint-disable-next-line no-console
|
|
66
|
-
console.warn(
|
|
92
|
+
console.warn(
|
|
93
|
+
'[Geolonia] Embed API failed to render the map because the container has no height. Please set the CSS property `height` to the container.',
|
|
94
|
+
);
|
|
67
95
|
}
|
|
68
96
|
|
|
69
|
-
const atts = parseAtts(container, {
|
|
97
|
+
const atts = parseAtts(container, {
|
|
98
|
+
interactive: typeof params === 'object' ? params.interactive : true,
|
|
99
|
+
});
|
|
70
100
|
const options = getOptions(container, params, atts);
|
|
71
101
|
|
|
72
102
|
// Getting content should be fire just before initialize the map.
|
|
@@ -96,7 +126,10 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
96
126
|
// Pass API key and requested tile version to `/sources` (tile json).
|
|
97
127
|
const _transformRequest = options.transformRequest;
|
|
98
128
|
options.transformRequest = (url, resourceType) => {
|
|
99
|
-
if (
|
|
129
|
+
if (
|
|
130
|
+
resourceType === 'Source' &&
|
|
131
|
+
url.startsWith('https://api.geolonia.com')
|
|
132
|
+
) {
|
|
100
133
|
return {
|
|
101
134
|
url: sourcesUrl.toString(),
|
|
102
135
|
};
|
|
@@ -104,15 +137,21 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
104
137
|
|
|
105
138
|
let transformedUrl = url;
|
|
106
139
|
if (url.startsWith('geolonia://')) {
|
|
107
|
-
const tilesMatch = url.match(
|
|
140
|
+
const tilesMatch = url.match(
|
|
141
|
+
/^geolonia:\/\/tiles\/(?<username>.+)\/(?<customtileId>.+)/,
|
|
142
|
+
);
|
|
108
143
|
if (tilesMatch) {
|
|
109
144
|
transformedUrl = `https://tileserver.geolonia.com/customtiles/${tilesMatch.groups.customtileId}/tiles.json`;
|
|
110
145
|
}
|
|
111
146
|
}
|
|
112
147
|
|
|
113
148
|
const transformedUrlObj = new URL(transformedUrl);
|
|
149
|
+
const geoloniaTilesHost = isGeoloniaTilesHost(transformedUrlObj);
|
|
114
150
|
|
|
115
|
-
if (
|
|
151
|
+
if (
|
|
152
|
+
resourceType === 'Source' &&
|
|
153
|
+
geoloniaTilesHost
|
|
154
|
+
) {
|
|
116
155
|
if (atts.stage === 'dev') {
|
|
117
156
|
transformedUrlObj.hostname = 'tileserver-dev.geolonia.com';
|
|
118
157
|
}
|
|
@@ -123,7 +162,9 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
123
162
|
};
|
|
124
163
|
} else if (
|
|
125
164
|
(resourceType === 'SpriteJSON' || resourceType === 'SpriteImage') &&
|
|
126
|
-
transformedUrl.match(
|
|
165
|
+
transformedUrl.match(
|
|
166
|
+
/^https:\/\/api\.geolonia\.com\/(dev|v1)\/sprites\//,
|
|
167
|
+
)
|
|
127
168
|
) {
|
|
128
169
|
const pathParts = transformedUrlObj.pathname.split('/');
|
|
129
170
|
pathParts[1] = atts.stage;
|
|
@@ -157,27 +198,39 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
157
198
|
|
|
158
199
|
// Note: GeoloniaControl should be placed before another controls.
|
|
159
200
|
// Because this control should be "very" bottom-left(default) or the attributed position.
|
|
160
|
-
const { position: geoloniaControlPosition } = parseControlOption(
|
|
201
|
+
const { position: geoloniaControlPosition } = parseControlOption(
|
|
202
|
+
atts.geoloniaControl,
|
|
203
|
+
);
|
|
161
204
|
map.addControl(new GeoloniaControl(), geoloniaControlPosition);
|
|
162
205
|
|
|
163
206
|
map.addControl(new CustomAttributionControl(), 'bottom-right');
|
|
164
207
|
|
|
165
|
-
const {
|
|
208
|
+
const {
|
|
209
|
+
enabled: fullscreenControlEnabled,
|
|
210
|
+
position: fullscreenControlPosition,
|
|
211
|
+
} = parseControlOption(atts.fullscreenControl);
|
|
166
212
|
if (fullscreenControlEnabled) {
|
|
167
213
|
map.addControl(new FullscreenControl(), fullscreenControlPosition);
|
|
168
214
|
}
|
|
169
215
|
|
|
170
|
-
const {
|
|
216
|
+
const {
|
|
217
|
+
enabled: navigationControlEnabled,
|
|
218
|
+
position: navigationControlPosition,
|
|
219
|
+
} = parseControlOption(atts.navigationControl);
|
|
171
220
|
if (navigationControlEnabled) {
|
|
172
221
|
map.addControl(new NavigationControl(), navigationControlPosition);
|
|
173
222
|
}
|
|
174
223
|
|
|
175
|
-
const {
|
|
224
|
+
const {
|
|
225
|
+
enabled: geolocateControlEnabled,
|
|
226
|
+
position: geolocateControlPosition,
|
|
227
|
+
} = parseControlOption(atts.geolocateControl);
|
|
176
228
|
if (geolocateControlEnabled) {
|
|
177
229
|
map.addControl(new GeolocateControl({}), geolocateControlPosition);
|
|
178
230
|
}
|
|
179
231
|
|
|
180
|
-
const { enabled: scaleControlEnabled, position: scaleControlPosition } =
|
|
232
|
+
const { enabled: scaleControlEnabled, position: scaleControlPosition } =
|
|
233
|
+
parseControlOption(atts.scaleControl);
|
|
181
234
|
if (scaleControlEnabled) {
|
|
182
235
|
map.addControl(new ScaleControl({}), scaleControlPosition);
|
|
183
236
|
}
|
|
@@ -188,7 +241,7 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
188
241
|
if (atts.loader !== 'off') {
|
|
189
242
|
try {
|
|
190
243
|
container.removeChild(loading);
|
|
191
|
-
} catch
|
|
244
|
+
} catch {
|
|
192
245
|
// Nothing to do.
|
|
193
246
|
}
|
|
194
247
|
}
|
|
@@ -205,21 +258,31 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
205
258
|
const offset = atts.customMarkerOffset.split(/,/).map((n) => {
|
|
206
259
|
return Number(n.trim());
|
|
207
260
|
});
|
|
208
|
-
const container: HTMLElement = document.querySelector(
|
|
261
|
+
const container: HTMLElement = document.querySelector(
|
|
262
|
+
atts.customMarker,
|
|
263
|
+
);
|
|
209
264
|
container.style.display = 'block';
|
|
210
265
|
marker = new Marker({
|
|
211
266
|
element: container,
|
|
212
267
|
offset: offset as PointLike,
|
|
213
|
-
})
|
|
268
|
+
})
|
|
269
|
+
.setLngLat(options.center)
|
|
270
|
+
.addTo(map)
|
|
271
|
+
.setPopup(popup);
|
|
214
272
|
} else {
|
|
215
|
-
marker = new Marker({ color: atts.markerColor })
|
|
273
|
+
marker = new Marker({ color: atts.markerColor })
|
|
274
|
+
.setLngLat(options.center)
|
|
275
|
+
.addTo(map)
|
|
276
|
+
.setPopup(popup);
|
|
216
277
|
}
|
|
217
278
|
if (atts.openPopup === 'on') {
|
|
218
279
|
marker.togglePopup();
|
|
219
280
|
}
|
|
220
281
|
marker.getElement().classList.add('geolonia-clickable-marker');
|
|
221
282
|
} else {
|
|
222
|
-
new Marker({ color: atts.markerColor })
|
|
283
|
+
new Marker({ color: atts.markerColor })
|
|
284
|
+
.setLngLat(options.center)
|
|
285
|
+
.addTo(map);
|
|
223
286
|
}
|
|
224
287
|
}
|
|
225
288
|
});
|
|
@@ -247,12 +310,15 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
247
310
|
}
|
|
248
311
|
|
|
249
312
|
const ss = new SimpleStyle(json, {
|
|
250
|
-
cluster:
|
|
313
|
+
cluster: atts.cluster === 'on',
|
|
251
314
|
clusterColor: atts.clusterColor,
|
|
252
315
|
});
|
|
253
316
|
ss.addTo(map);
|
|
254
317
|
|
|
255
|
-
if (
|
|
318
|
+
if (
|
|
319
|
+
!container.dataset ||
|
|
320
|
+
(!container.dataset.lng && !container.dataset.lat)
|
|
321
|
+
) {
|
|
256
322
|
ss.fitBounds();
|
|
257
323
|
}
|
|
258
324
|
}
|
|
@@ -260,13 +326,29 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
260
326
|
if (atts['3d']) {
|
|
261
327
|
const style = map.getStyle();
|
|
262
328
|
style.layers.forEach((layer) => {
|
|
263
|
-
if (
|
|
329
|
+
if (
|
|
330
|
+
atts['3d'] === 'on' &&
|
|
331
|
+
layer.metadata &&
|
|
332
|
+
layer.metadata['visible-on-3d'] === true
|
|
333
|
+
) {
|
|
264
334
|
map.setLayoutProperty(layer.id, 'visibility', 'visible');
|
|
265
|
-
} else if (
|
|
335
|
+
} else if (
|
|
336
|
+
atts['3d'] === 'off' &&
|
|
337
|
+
layer.metadata &&
|
|
338
|
+
layer.metadata['visible-on-3d'] === true
|
|
339
|
+
) {
|
|
266
340
|
map.setLayoutProperty(layer.id, 'visibility', 'none');
|
|
267
|
-
} else if (
|
|
341
|
+
} else if (
|
|
342
|
+
atts['3d'] === 'on' &&
|
|
343
|
+
layer.metadata &&
|
|
344
|
+
layer.metadata['hide-on-3d'] === true
|
|
345
|
+
) {
|
|
268
346
|
map.setLayoutProperty(layer.id, 'visibility', 'none');
|
|
269
|
-
} else if (
|
|
347
|
+
} else if (
|
|
348
|
+
atts['3d'] === 'off' &&
|
|
349
|
+
layer.metadata &&
|
|
350
|
+
layer.metadata['hide-on-3d'] === true
|
|
351
|
+
) {
|
|
270
352
|
map.setLayoutProperty(layer.id, 'visibility', 'visible');
|
|
271
353
|
}
|
|
272
354
|
});
|
|
@@ -275,10 +357,7 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
275
357
|
|
|
276
358
|
// handle Geolonia Server errors
|
|
277
359
|
map.on('error', async (error) => {
|
|
278
|
-
if (
|
|
279
|
-
error.error &&
|
|
280
|
-
error.error.status === 402
|
|
281
|
-
) {
|
|
360
|
+
if (error.error && error.error.status === 402) {
|
|
282
361
|
handleRestrictedMode(map);
|
|
283
362
|
}
|
|
284
363
|
});
|
|
@@ -293,7 +372,10 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
293
372
|
* @param {string|null} style style identity or `null` when map.remove()
|
|
294
373
|
* @param {*} options
|
|
295
374
|
*/
|
|
296
|
-
setStyle(
|
|
375
|
+
setStyle(
|
|
376
|
+
style: string | StyleSpecification,
|
|
377
|
+
options: StyleSwapOptions & StyleOptions = {},
|
|
378
|
+
): this {
|
|
297
379
|
if (style !== null) {
|
|
298
380
|
// It can't access `this` because `setStyle()` will be called with `super()`.
|
|
299
381
|
// So, we need to run `parseAtts()` again(?)
|
|
@@ -317,7 +399,8 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
317
399
|
remove(): void {
|
|
318
400
|
const container = this.getContainer();
|
|
319
401
|
super.remove.call(this);
|
|
320
|
-
delete (container as HTMLElement & { geoloniaMap: GeoloniaMap })
|
|
402
|
+
delete (container as HTMLElement & { geoloniaMap: GeoloniaMap })
|
|
403
|
+
.geoloniaMap;
|
|
321
404
|
}
|
|
322
405
|
|
|
323
406
|
/**
|
|
@@ -327,9 +410,13 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
327
410
|
* @param callback
|
|
328
411
|
*/
|
|
329
412
|
loadImage(url: string, callback: GetImageCallback): void;
|
|
330
|
-
loadImage(
|
|
331
|
-
|
|
332
|
-
|
|
413
|
+
loadImage(
|
|
414
|
+
url: string,
|
|
415
|
+
): Promise<GetResourceResponse<HTMLImageElement | ImageBitmap>>;
|
|
416
|
+
loadImage(
|
|
417
|
+
url: string,
|
|
418
|
+
callback?: GetImageCallback,
|
|
419
|
+
): Promise<GetResourceResponse<HTMLImageElement | ImageBitmap>> | void {
|
|
333
420
|
const promise = super.loadImage(url);
|
|
334
421
|
|
|
335
422
|
if (callback) {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
import maplibregl from 'maplibre-gl';
|
|
3
|
+
import maplibregl, { type MarkerOptions } from 'maplibre-gl';
|
|
4
4
|
import tinycolor from 'tinycolor2';
|
|
5
5
|
import markerSVG from './marker.svg';
|
|
6
6
|
import { handleMarkerOptions } from './util';
|
|
7
|
-
import type { MarkerOptions } from 'maplibre-gl';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Geolonia default marker
|
|
@@ -33,12 +32,16 @@ export default class GeoloniaMarker extends maplibregl.Marker {
|
|
|
33
32
|
options.element = markerElement;
|
|
34
33
|
|
|
35
34
|
if (options.color) {
|
|
36
|
-
(markerElement.querySelector('.left') as HTMLElement).style.fill =
|
|
37
|
-
|
|
35
|
+
(markerElement.querySelector('.left') as HTMLElement).style.fill =
|
|
36
|
+
options.color;
|
|
37
|
+
(markerElement.querySelector('.right') as HTMLElement).style.fill =
|
|
38
|
+
tinycolor(options.color).darken().toString();
|
|
38
39
|
} else {
|
|
39
40
|
const defaultColor = '#E4402F';
|
|
40
|
-
(markerElement.querySelector('.left') as HTMLElement).style.fill =
|
|
41
|
-
|
|
41
|
+
(markerElement.querySelector('.left') as HTMLElement).style.fill =
|
|
42
|
+
defaultColor;
|
|
43
|
+
(markerElement.querySelector('.right') as HTMLElement).style.fill =
|
|
44
|
+
tinycolor(defaultColor).darken().toString();
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
options.offset = [0, -15];
|
package/src/lib/keyring.test.ts
CHANGED
|
@@ -5,6 +5,10 @@ import assert from 'assert';
|
|
|
5
5
|
describe('parse api key from dom', () => {
|
|
6
6
|
beforeEach(() => {
|
|
7
7
|
keyring.reset();
|
|
8
|
+
process.env.MAP_PLATFORM_STAGE = 'dev';
|
|
9
|
+
});
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
delete process.env.MAP_PLATFORM_STAGE;
|
|
8
12
|
});
|
|
9
13
|
after(() => {
|
|
10
14
|
keyring.reset();
|
|
@@ -43,6 +47,7 @@ describe('parse api key from dom', () => {
|
|
|
43
47
|
});
|
|
44
48
|
|
|
45
49
|
it('should be "YOUR-API-KEY" and "v1"', () => {
|
|
50
|
+
process.env.MAP_PLATFORM_STAGE = 'v1';
|
|
46
51
|
const { document: mocDocument } = new JSDOM(`<html><body>
|
|
47
52
|
<script src="https://external.example.com/jquery.js"></script>
|
|
48
53
|
<script type="text/javascript" src="https://api.geolonia.com/v1/embed?geolonia-api-key=YOUR-API-KEY"></script>
|
|
@@ -54,6 +59,7 @@ describe('parse api key from dom', () => {
|
|
|
54
59
|
});
|
|
55
60
|
|
|
56
61
|
it('should be "YOUR-API-KEY" and "v123.4"', () => {
|
|
62
|
+
process.env.MAP_PLATFORM_STAGE = 'v123.4';
|
|
57
63
|
const { document: mocDocument } = new JSDOM(`<html><body>
|
|
58
64
|
<script src="https://external.example.com/jquery.js"></script>
|
|
59
65
|
<script type="text/javascript" src="https://api.geolonia.com/v123.4/embed?geolonia-api-key=YOUR-API-KEY"></script>
|
|
@@ -63,4 +69,16 @@ describe('parse api key from dom', () => {
|
|
|
63
69
|
assert.deepEqual('YOUR-API-KEY', keyring.apiKey);
|
|
64
70
|
assert.deepEqual('v123.4', keyring.stage);
|
|
65
71
|
});
|
|
72
|
+
|
|
73
|
+
it('should be "YOUR-API-KEY" and "dev" if process.env.MAP_PLATFORM_STAGE is not set', () => {
|
|
74
|
+
delete process.env.MAP_PLATFORM_STAGE;
|
|
75
|
+
const { document: mocDocument } = new JSDOM(`<html><body>
|
|
76
|
+
<script src="https://external.example.com/jquery.js"></script>
|
|
77
|
+
<script src="https://external.example.com/?geolonia-api-key=YOUR-API-KEY"></script>
|
|
78
|
+
</body></html>`).window;
|
|
79
|
+
|
|
80
|
+
keyring.parse(mocDocument);
|
|
81
|
+
assert.deepEqual('YOUR-API-KEY', keyring.apiKey);
|
|
82
|
+
assert.deepEqual('dev', keyring.stage);
|
|
83
|
+
});
|
|
66
84
|
});
|
package/src/lib/keyring.ts
CHANGED
|
@@ -39,27 +39,25 @@ class Keyring {
|
|
|
39
39
|
* @param {Document} document
|
|
40
40
|
*/
|
|
41
41
|
public parse(doc: Document = document) {
|
|
42
|
-
const scripts: HTMLScriptElement[] | HTMLCollectionOf<HTMLScriptElement> =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
const scripts: HTMLScriptElement[] | HTMLCollectionOf<HTMLScriptElement> =
|
|
43
|
+
doc.currentScript
|
|
44
|
+
? [doc.currentScript as HTMLScriptElement]
|
|
45
|
+
: doc.getElementsByTagName('script');
|
|
46
46
|
|
|
47
47
|
for (const script of scripts) {
|
|
48
48
|
const url = new URL(
|
|
49
|
-
(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
script.src
|
|
53
|
-
|
|
49
|
+
script.src.startsWith('https://') ||
|
|
50
|
+
script.src.startsWith('http://') ||
|
|
51
|
+
script.src.startsWith('//')
|
|
52
|
+
? script.src
|
|
53
|
+
: `https://${location.host}/${script.src}`,
|
|
54
|
+
);
|
|
54
55
|
const apiKey = url.searchParams.get('geolonia-api-key');
|
|
55
56
|
|
|
56
57
|
if (apiKey) {
|
|
57
58
|
this.#apiKey = apiKey;
|
|
58
59
|
|
|
59
|
-
|
|
60
|
-
if (res && res[1]) {
|
|
61
|
-
this.#stage = res[1];
|
|
62
|
-
}
|
|
60
|
+
this.#stage = process.env.MAP_PLATFORM_STAGE || 'dev';
|
|
63
61
|
|
|
64
62
|
break;
|
|
65
63
|
}
|
package/src/lib/maplibre-util.ts
CHANGED
|
@@ -5,18 +5,26 @@ import Point from '@mapbox/point-geometry';
|
|
|
5
5
|
* https://github.com/maplibre/maplibre-gl-js/blob/main/src/util/dom.ts
|
|
6
6
|
* */
|
|
7
7
|
export class DOM {
|
|
8
|
-
static #docStyle =
|
|
8
|
+
static #docStyle =
|
|
9
|
+
typeof window !== 'undefined' &&
|
|
10
|
+
window.document &&
|
|
11
|
+
window.document.documentElement.style;
|
|
9
12
|
|
|
10
13
|
static #userSelect;
|
|
11
14
|
|
|
12
|
-
static #selectProp = DOM.testProp([
|
|
15
|
+
static #selectProp = DOM.testProp([
|
|
16
|
+
'userSelect',
|
|
17
|
+
'MozUserSelect',
|
|
18
|
+
'WebkitUserSelect',
|
|
19
|
+
'msUserSelect',
|
|
20
|
+
]);
|
|
13
21
|
|
|
14
22
|
static #transformProp = DOM.testProp(['transform', 'WebkitTransform']);
|
|
15
23
|
|
|
16
24
|
static testProp(props) {
|
|
17
|
-
if (!DOM
|
|
25
|
+
if (!DOM.#docStyle) return props[0];
|
|
18
26
|
for (let i = 0; i < props.length; i++) {
|
|
19
|
-
if (props[i] in DOM
|
|
27
|
+
if (props[i] in DOM.#docStyle) {
|
|
20
28
|
return props[i];
|
|
21
29
|
}
|
|
22
30
|
}
|
|
@@ -36,20 +44,20 @@ export class DOM {
|
|
|
36
44
|
}
|
|
37
45
|
|
|
38
46
|
static disableDrag() {
|
|
39
|
-
if (DOM
|
|
40
|
-
DOM
|
|
41
|
-
DOM
|
|
47
|
+
if (DOM.#docStyle && DOM.#selectProp) {
|
|
48
|
+
DOM.#userSelect = DOM.#docStyle[DOM.#selectProp];
|
|
49
|
+
DOM.#docStyle[DOM.#selectProp] = 'none';
|
|
42
50
|
}
|
|
43
51
|
}
|
|
44
52
|
|
|
45
53
|
static enableDrag() {
|
|
46
|
-
if (DOM
|
|
47
|
-
DOM
|
|
54
|
+
if (DOM.#docStyle && DOM.#selectProp) {
|
|
55
|
+
DOM.#docStyle[DOM.#selectProp] = DOM.#userSelect;
|
|
48
56
|
}
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
static setTransform(el, value) {
|
|
52
|
-
el.style[DOM
|
|
60
|
+
el.style[DOM.#transformProp] = value;
|
|
53
61
|
}
|
|
54
62
|
|
|
55
63
|
static addEventListener(target, type, callback, options) {
|
|
@@ -69,16 +77,16 @@ export class DOM {
|
|
|
69
77
|
}
|
|
70
78
|
|
|
71
79
|
// Suppress the next click, but only if it's immediate.
|
|
72
|
-
static #suppressClickInternal(e) {
|
|
80
|
+
/*static #suppressClickInternal(e) {
|
|
73
81
|
e.preventDefault();
|
|
74
82
|
e.stopPropagation();
|
|
75
83
|
window.removeEventListener('click', DOM['#transformProp'], true);
|
|
76
|
-
}
|
|
84
|
+
}*/
|
|
77
85
|
|
|
78
86
|
static suppressClick() {
|
|
79
|
-
window.addEventListener('click', DOM
|
|
87
|
+
window.addEventListener('click', DOM.#transformProp, true);
|
|
80
88
|
window.setTimeout(() => {
|
|
81
|
-
window.removeEventListener('click', DOM
|
|
89
|
+
window.removeEventListener('click', DOM.#transformProp, true);
|
|
82
90
|
}, 0);
|
|
83
91
|
}
|
|
84
92
|
|
|
@@ -94,10 +102,12 @@ export class DOM {
|
|
|
94
102
|
const rect = el.getBoundingClientRect();
|
|
95
103
|
const points = [];
|
|
96
104
|
for (let i = 0; i < touches.length; i++) {
|
|
97
|
-
points.push(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
105
|
+
points.push(
|
|
106
|
+
new Point(
|
|
107
|
+
touches[i].clientX - rect.left - el.clientLeft,
|
|
108
|
+
touches[i].clientY - rect.top - el.clientTop,
|
|
109
|
+
),
|
|
110
|
+
);
|
|
101
111
|
}
|
|
102
112
|
return points;
|
|
103
113
|
}
|
|
@@ -119,7 +129,9 @@ export class DOM {
|
|
|
119
129
|
* */
|
|
120
130
|
export function bindAll(fns, context) {
|
|
121
131
|
fns.forEach((fn) => {
|
|
122
|
-
if (!context[fn]) {
|
|
132
|
+
if (!context[fn]) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
123
135
|
context[fn] = context[fn].bind(context);
|
|
124
136
|
});
|
|
125
137
|
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
-
|
|
3
1
|
import parseAtts from './parse-atts';
|
|
4
2
|
import assert from 'assert';
|
|
5
3
|
import { JSDOM } from 'jsdom';
|
|
6
4
|
import { keyring } from './keyring';
|
|
7
5
|
|
|
8
6
|
describe('tests for parse Attributes', () => {
|
|
9
|
-
|
|
10
7
|
const prevWindow = global.window;
|
|
11
8
|
|
|
12
9
|
beforeEach(() => {
|
|
10
|
+
process.env.MAP_PLATFORM_STAGE = 'v1';
|
|
13
11
|
global.window = {
|
|
14
12
|
// @ts-ignore forcefully assigning values to readonly properties
|
|
15
13
|
navigator: { languages: ['ja'] },
|
|
@@ -46,7 +44,7 @@ describe('tests for parse Attributes', () => {
|
|
|
46
44
|
simpleVector: '',
|
|
47
45
|
cluster: 'on',
|
|
48
46
|
clusterColor: '#ff0000',
|
|
49
|
-
style: 'geolonia/basic-
|
|
47
|
+
style: 'geolonia/basic-v2',
|
|
50
48
|
lang: 'ja',
|
|
51
49
|
plugin: 'off',
|
|
52
50
|
key: 'YOUR-API-KEY',
|
|
@@ -62,5 +60,6 @@ describe('tests for parse Attributes', () => {
|
|
|
62
60
|
afterEach(() => {
|
|
63
61
|
global.window = prevWindow;
|
|
64
62
|
keyring.reset();
|
|
63
|
+
delete process.env.MAP_PLATFORM_STAGE;
|
|
65
64
|
});
|
|
66
65
|
});
|
package/src/lib/parse-atts.ts
CHANGED
|
@@ -48,7 +48,7 @@ export default (container, params: ParseAttsParams = {}): EmbedAttributes => {
|
|
|
48
48
|
simpleVector: '',
|
|
49
49
|
cluster: 'on',
|
|
50
50
|
clusterColor: '#ff0000',
|
|
51
|
-
style: 'geolonia/basic-
|
|
51
|
+
style: 'geolonia/basic-v2',
|
|
52
52
|
lang: lang,
|
|
53
53
|
plugin: 'off',
|
|
54
54
|
key: keyring.apiKey,
|
package/src/lib/render.ts
CHANGED
|
@@ -13,7 +13,7 @@ export const renderGeoloniaMap = () => {
|
|
|
13
13
|
const protocol = new Protocol();
|
|
14
14
|
maplibregl.addProtocol('pmtiles', protocol.tile);
|
|
15
15
|
|
|
16
|
-
if (
|
|
16
|
+
if (checkPermission()) {
|
|
17
17
|
let isDOMContentLoaded = false;
|
|
18
18
|
const alreadyRenderedMaps = [];
|
|
19
19
|
const isRemoved = Symbol('map-is-removed');
|
|
@@ -35,7 +35,9 @@ export const renderGeoloniaMap = () => {
|
|
|
35
35
|
// remove map instance automatically if the container removed.
|
|
36
36
|
// prevent memory leak
|
|
37
37
|
const observer = new MutationObserver((mutationRecords) => {
|
|
38
|
-
const removed = mutationRecords.some((record) =>
|
|
38
|
+
const removed = mutationRecords.some((record) =>
|
|
39
|
+
[...record.removedNodes].some((node) => node === target),
|
|
40
|
+
);
|
|
39
41
|
if (removed && !map[isRemoved]) {
|
|
40
42
|
map.remove();
|
|
41
43
|
}
|
|
@@ -77,12 +79,16 @@ export const renderGeoloniaMap = () => {
|
|
|
77
79
|
});
|
|
78
80
|
});
|
|
79
81
|
|
|
80
|
-
const containers = document.querySelectorAll(
|
|
81
|
-
|
|
82
|
+
const containers = document.querySelectorAll(
|
|
83
|
+
'.geolonia[data-lazy-loading="off"]',
|
|
84
|
+
);
|
|
85
|
+
const lazyContainers = document.querySelectorAll(
|
|
86
|
+
'.geolonia:not([data-lazy-loading="off"])',
|
|
87
|
+
);
|
|
82
88
|
|
|
83
89
|
// This is required for correct initialization! Don't delete!
|
|
84
90
|
if (!keyring.apiKey) {
|
|
85
|
-
console.error('[Geolonia] Missing API key.') // eslint-disable-line
|
|
91
|
+
console.error('[Geolonia] Missing API key.'); // eslint-disable-line
|
|
86
92
|
}
|
|
87
93
|
|
|
88
94
|
// render Map immediately
|
|
@@ -100,11 +106,16 @@ export const renderGeoloniaMap = () => {
|
|
|
100
106
|
observer.observe(lazyContainers[i]);
|
|
101
107
|
}
|
|
102
108
|
} else {
|
|
103
|
-
|
|
109
|
+
/* eslint-disable-next-line no-console */
|
|
110
|
+
console.error(
|
|
111
|
+
"[Geolonia] We are very sorry, but we can't display our map in iframe.",
|
|
112
|
+
);
|
|
104
113
|
}
|
|
105
114
|
};
|
|
106
115
|
|
|
107
|
-
export const registerPlugin = (
|
|
116
|
+
export const registerPlugin = (
|
|
117
|
+
plugin: (map: GeoloniaMap, target: HTMLElement, atts) => void,
|
|
118
|
+
): void => {
|
|
108
119
|
plugins.push(plugin);
|
|
109
120
|
return void 0;
|
|
110
121
|
};
|