@geolonia/embed 5.2.1 → 6.0.0-pre.2
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 +38 -19
- package/CHANGELOG.md +9 -0
- package/README.md +24 -1
- package/dist/embed +1 -1
- package/dist/embed-chunks/4ada77b78cc0cc5ccef9.js +1 -0
- package/dist/embed-chunks/8176630945512b29f294.js +2 -0
- package/dist/embed-chunks/c783fffcd28083f7d5cb.js +2 -0
- package/dist/embed-chunks/f2124097fda51d0079ee.js +1 -0
- package/dist/embed-core.d.ts +6 -7
- package/dist/embed-core.js +1 -1
- package/dist/embed.d.ts +2 -4
- package/dist/embed.js +1 -1
- package/dist/lib/parse-atts.d.ts +19 -0
- package/dist/lib/render.d.ts +1 -1
- package/dist/lib/util.d.ts +14 -55
- package/dist/types.d.ts +155 -1
- package/dist/version.d.ts +1 -1
- package/e2e/auto-render.spec.ts +44 -0
- package/e2e/basic.spec.ts +9 -50
- package/e2e/cleanup.spec.ts +43 -0
- package/e2e/data-attributes.spec.ts +56 -0
- package/e2e/globals.spec.ts +51 -0
- package/e2e/helper.ts +170 -4
- package/e2e/iframe.spec.ts +35 -0
- package/e2e/lazy-loading.spec.ts +32 -0
- package/e2e/legacy-constructor.spec.ts +102 -0
- package/e2e/plugin.spec.ts +25 -0
- package/e2e/pmtiles.spec.ts +13 -0
- package/package.json +8 -13
- package/playwright.config.ts +6 -32
- package/src/embed-core.ts +12 -14
- package/src/embed.ts +2 -4
- package/src/lib/parse-atts.test.ts +186 -18
- package/src/lib/parse-atts.ts +151 -5
- package/src/lib/render.ts +50 -12
- package/src/lib/util.ts +37 -350
- package/src/types.ts +155 -1
- package/src/version.ts +1 -0
- package/typedoc.json +13 -0
- package/vitest.config.ts +7 -0
- package/dist/embed-chunks/12cbd0d1cb4cf744c32f.js +0 -2
- package/dist/embed-chunks/8a521e8312a5b4da123d.js +0 -2
- package/dist/lib/CustomAttributionControl.d.ts +0 -47
- package/dist/lib/controls/geolonia-control.d.ts +0 -7
- package/dist/lib/geolonia-map.d.ts +0 -30
- package/dist/lib/geolonia-marker.d.ts +0 -9
- package/dist/lib/keyring.d.ts +0 -45
- package/dist/lib/maplibre-util.d.ts +0 -25
- package/dist/lib/simplestyle-vector.d.ts +0 -26
- package/dist/lib/simplestyle.d.ts +0 -31
- package/e2e/external-style.spec.ts +0 -25
- package/e2e/map.spec.ts +0 -69
- package/src/lib/CustomAttributionControl.ts +0 -394
- package/src/lib/controls/geolonia-control.ts +0 -38
- package/src/lib/geolonia-map.ts +0 -429
- package/src/lib/geolonia-marker.ts +0 -53
- package/src/lib/keyring.test.ts +0 -127
- package/src/lib/keyring.ts +0 -136
- package/src/lib/maplibre-util.ts +0 -137
- package/src/lib/marker.svg +0 -1
- package/src/lib/simplestyle-vector.ts +0 -257
- package/src/lib/simplestyle.test.ts +0 -289
- package/src/lib/simplestyle.ts +0 -435
- package/src/lib/util.test.ts +0 -364
- /package/dist/embed-chunks/{12cbd0d1cb4cf744c32f.js.LICENSE.txt → 8176630945512b29f294.js.LICENSE.txt} +0 -0
- /package/dist/embed-chunks/{8a521e8312a5b4da123d.js.LICENSE.txt → c783fffcd28083f7d5cb.js.LICENSE.txt} +0 -0
package/src/lib/geolonia-map.ts
DELETED
|
@@ -1,429 +0,0 @@
|
|
|
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';
|
|
14
|
-
import Marker from './geolonia-marker';
|
|
15
|
-
import { GeoloniaControl } from './controls/geolonia-control';
|
|
16
|
-
import CustomAttributionControl from './CustomAttributionControl';
|
|
17
|
-
import GestureHandling from '@geolonia/mbgl-gesture-handling';
|
|
18
|
-
import parseAtts from './parse-atts';
|
|
19
|
-
|
|
20
|
-
import { SimpleStyle } from './simplestyle';
|
|
21
|
-
import SimpleStyleVector from './simplestyle-vector';
|
|
22
|
-
|
|
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';
|
|
37
|
-
|
|
38
|
-
export type GeoloniaMapOptions = MapOptions & { interactive?: boolean };
|
|
39
|
-
|
|
40
|
-
type Container = HTMLElement & {
|
|
41
|
-
geoloniaMap: GeoloniaMap;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const isCssSelector = (string) => {
|
|
45
|
-
if (/^https?:\/\//.test(string)) {
|
|
46
|
-
return false;
|
|
47
|
-
} else if (/^\//.test(string)) {
|
|
48
|
-
return false;
|
|
49
|
-
} else if (/^\.\//.test(string)) {
|
|
50
|
-
return false;
|
|
51
|
-
} else if (/^\.\.\//.test(string)) {
|
|
52
|
-
return false;
|
|
53
|
-
} else {
|
|
54
|
-
try {
|
|
55
|
-
return document.querySelector(string);
|
|
56
|
-
} catch {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Render the map
|
|
64
|
-
*
|
|
65
|
-
* @param container
|
|
66
|
-
*/
|
|
67
|
-
export default class GeoloniaMap extends maplibregl.Map {
|
|
68
|
-
private geoloniaSourcesUrl: URL;
|
|
69
|
-
private __styleExtensionLoadRequired: boolean;
|
|
70
|
-
|
|
71
|
-
constructor(params: string | GeoloniaMapOptions) {
|
|
72
|
-
const container = getContainer(params) as Container | false;
|
|
73
|
-
|
|
74
|
-
if (!container) {
|
|
75
|
-
if (typeof params === 'string') {
|
|
76
|
-
throw new Error(
|
|
77
|
-
`[Geolonia] No HTML elements found matching \`${params}\`. Please ensure the map container element exists.`,
|
|
78
|
-
);
|
|
79
|
-
} else {
|
|
80
|
-
throw new Error(
|
|
81
|
-
'[Geolonia] No HTML elements found. Please ensure the map container element exists.',
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (container.geoloniaMap) {
|
|
87
|
-
return container.geoloniaMap;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (container.clientHeight === 0) {
|
|
91
|
-
// eslint-disable-next-line no-console
|
|
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
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const atts = parseAtts(container, {
|
|
98
|
-
interactive: typeof params === 'object' ? params.interactive : true,
|
|
99
|
-
});
|
|
100
|
-
const options = getOptions(container, params, atts);
|
|
101
|
-
|
|
102
|
-
// Getting content should be fire just before initialize the map.
|
|
103
|
-
const content = container.innerHTML.trim();
|
|
104
|
-
container.innerHTML = '';
|
|
105
|
-
|
|
106
|
-
let loading;
|
|
107
|
-
if (atts.loader !== 'off') {
|
|
108
|
-
loading = document.createElement('div');
|
|
109
|
-
// prevent pinch-in & pinch-out
|
|
110
|
-
loading.addEventListener('touchmove', (e) => {
|
|
111
|
-
if (e.touches && e.touches.length > 1) {
|
|
112
|
-
e.preventDefault();
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
loading.className = 'loading-geolonia-map';
|
|
116
|
-
loading.innerHTML = `<div class="lds-grid"><div></div><div></div><div></div>
|
|
117
|
-
<div></div><div></div><div></div><div></div><div></div><div></div></div>`;
|
|
118
|
-
container.appendChild(loading);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const sessionId = getSessionId(40);
|
|
122
|
-
const sourcesUrl = new URL(`${atts.apiUrl}/sources`);
|
|
123
|
-
sourcesUrl.searchParams.set('key', atts.key);
|
|
124
|
-
sourcesUrl.searchParams.set('sessionId', sessionId);
|
|
125
|
-
|
|
126
|
-
// Pass API key and requested tile version to `/sources` (tile json).
|
|
127
|
-
const _transformRequest = options.transformRequest;
|
|
128
|
-
options.transformRequest = (url, resourceType) => {
|
|
129
|
-
if (
|
|
130
|
-
resourceType === 'Source' &&
|
|
131
|
-
url.startsWith('https://api.geolonia.com')
|
|
132
|
-
) {
|
|
133
|
-
return {
|
|
134
|
-
url: sourcesUrl.toString(),
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
let transformedUrl = url;
|
|
139
|
-
if (url.startsWith('geolonia://')) {
|
|
140
|
-
const tilesMatch = url.match(
|
|
141
|
-
/^geolonia:\/\/tiles\/(?<username>.+)\/(?<customtileId>.+)/,
|
|
142
|
-
);
|
|
143
|
-
if (tilesMatch) {
|
|
144
|
-
transformedUrl = `https://tileserver.geolonia.com/customtiles/${tilesMatch.groups.customtileId}/tiles.json`;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const transformedUrlObj = new URL(transformedUrl);
|
|
149
|
-
const geoloniaTilesHost = isGeoloniaTilesHost(transformedUrlObj);
|
|
150
|
-
|
|
151
|
-
// Geolonia ドメインのみに API キーを付与(外部 URL には付与しない)
|
|
152
|
-
if (
|
|
153
|
-
resourceType === 'Source' &&
|
|
154
|
-
geoloniaTilesHost
|
|
155
|
-
) {
|
|
156
|
-
if (atts.stage === 'dev' && transformedUrlObj.hostname === 'tileserver.geolonia.com') {
|
|
157
|
-
transformedUrlObj.hostname = 'tileserver-dev.geolonia.com';
|
|
158
|
-
}
|
|
159
|
-
transformedUrlObj.searchParams.set('sessionId', sessionId);
|
|
160
|
-
transformedUrlObj.searchParams.set('key', atts.key);
|
|
161
|
-
return {
|
|
162
|
-
url: transformedUrlObj.toString(),
|
|
163
|
-
};
|
|
164
|
-
} else if (
|
|
165
|
-
(resourceType === 'SpriteJSON' || resourceType === 'SpriteImage') &&
|
|
166
|
-
transformedUrl.match(
|
|
167
|
-
/^https:\/\/api\.geolonia\.com\/(dev|v1)\/sprites\//,
|
|
168
|
-
)
|
|
169
|
-
) {
|
|
170
|
-
const pathParts = transformedUrlObj.pathname.split('/');
|
|
171
|
-
pathParts[1] = String(atts.stage);
|
|
172
|
-
transformedUrlObj.pathname = pathParts.join('/');
|
|
173
|
-
transformedUrlObj.searchParams.set('key', atts.key);
|
|
174
|
-
return {
|
|
175
|
-
url: transformedUrlObj.toString(),
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
let request;
|
|
180
|
-
// Additional transformation
|
|
181
|
-
if (typeof _transformRequest === 'function') {
|
|
182
|
-
request = _transformRequest(transformedUrl, resourceType);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return request;
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
try {
|
|
189
|
-
// Generate Map
|
|
190
|
-
super(options);
|
|
191
|
-
} catch (error) {
|
|
192
|
-
handleErrorMode(container);
|
|
193
|
-
throw error;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const map = this;
|
|
197
|
-
this.geoloniaSourcesUrl = sourcesUrl;
|
|
198
|
-
this.__styleExtensionLoadRequired = true;
|
|
199
|
-
|
|
200
|
-
// Note: GeoloniaControl should be placed before another controls.
|
|
201
|
-
// Because this control should be "very" bottom-left(default) or the attributed position.
|
|
202
|
-
const { position: geoloniaControlPosition } = parseControlOption(
|
|
203
|
-
atts.geoloniaControl,
|
|
204
|
-
);
|
|
205
|
-
map.addControl(new GeoloniaControl(), geoloniaControlPosition);
|
|
206
|
-
|
|
207
|
-
map.addControl(new CustomAttributionControl(), 'bottom-right');
|
|
208
|
-
|
|
209
|
-
const {
|
|
210
|
-
enabled: fullscreenControlEnabled,
|
|
211
|
-
position: fullscreenControlPosition,
|
|
212
|
-
} = parseControlOption(atts.fullscreenControl);
|
|
213
|
-
if (fullscreenControlEnabled) {
|
|
214
|
-
map.addControl(new FullscreenControl(), fullscreenControlPosition);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const {
|
|
218
|
-
enabled: navigationControlEnabled,
|
|
219
|
-
position: navigationControlPosition,
|
|
220
|
-
} = parseControlOption(atts.navigationControl);
|
|
221
|
-
if (navigationControlEnabled) {
|
|
222
|
-
map.addControl(new NavigationControl(), navigationControlPosition);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
const {
|
|
226
|
-
enabled: geolocateControlEnabled,
|
|
227
|
-
position: geolocateControlPosition,
|
|
228
|
-
} = parseControlOption(atts.geolocateControl);
|
|
229
|
-
if (geolocateControlEnabled) {
|
|
230
|
-
map.addControl(new GeolocateControl({}), geolocateControlPosition);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
const { enabled: scaleControlEnabled, position: scaleControlPosition } =
|
|
234
|
-
parseControlOption(atts.scaleControl);
|
|
235
|
-
if (scaleControlEnabled) {
|
|
236
|
-
map.addControl(new ScaleControl({}), scaleControlPosition);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
map.on('load', (event) => {
|
|
240
|
-
const map = event.target;
|
|
241
|
-
|
|
242
|
-
if (atts.loader !== 'off') {
|
|
243
|
-
try {
|
|
244
|
-
container.removeChild(loading);
|
|
245
|
-
} catch {
|
|
246
|
-
// Nothing to do.
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
if (atts.gestureHandling !== 'off' && isScrollable()) {
|
|
251
|
-
new GestureHandling({ lang: atts.lang }).addTo(map);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
if (atts.lat && atts.lng && atts.marker === 'on') {
|
|
255
|
-
if (content) {
|
|
256
|
-
const popup = new Popup({ offset: [0, -25] }).setHTML(content);
|
|
257
|
-
let marker;
|
|
258
|
-
if (atts.customMarker) {
|
|
259
|
-
const offset = atts.customMarkerOffset.split(/,/).map((n) => {
|
|
260
|
-
return Number(n.trim());
|
|
261
|
-
});
|
|
262
|
-
const container: HTMLElement = document.querySelector(
|
|
263
|
-
atts.customMarker,
|
|
264
|
-
);
|
|
265
|
-
container.style.display = 'block';
|
|
266
|
-
marker = new Marker({
|
|
267
|
-
element: container,
|
|
268
|
-
offset: offset as PointLike,
|
|
269
|
-
})
|
|
270
|
-
.setLngLat(options.center)
|
|
271
|
-
.addTo(map)
|
|
272
|
-
.setPopup(popup);
|
|
273
|
-
} else {
|
|
274
|
-
marker = new Marker({ color: atts.markerColor })
|
|
275
|
-
.setLngLat(options.center)
|
|
276
|
-
.addTo(map)
|
|
277
|
-
.setPopup(popup);
|
|
278
|
-
}
|
|
279
|
-
if (atts.openPopup === 'on') {
|
|
280
|
-
marker.togglePopup();
|
|
281
|
-
}
|
|
282
|
-
marker.getElement().classList.add('geolonia-clickable-marker');
|
|
283
|
-
} else {
|
|
284
|
-
new Marker({ color: atts.markerColor })
|
|
285
|
-
.setLngLat(options.center)
|
|
286
|
-
.addTo(map);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
map.on('styledata', async (event) => {
|
|
292
|
-
const map = event.target;
|
|
293
|
-
|
|
294
|
-
if (!this.__styleExtensionLoadRequired) {
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
this.__styleExtensionLoadRequired = false;
|
|
298
|
-
|
|
299
|
-
if (atts.simpleVector) {
|
|
300
|
-
const simpleVectorAttributeValue = parseSimpleVector(atts.simpleVector);
|
|
301
|
-
new SimpleStyleVector(simpleVectorAttributeValue).addTo(map);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
if (atts.geojson) {
|
|
305
|
-
const el = isCssSelector(atts.geojson);
|
|
306
|
-
let json;
|
|
307
|
-
if (el) {
|
|
308
|
-
json = JSON.parse(el.textContent);
|
|
309
|
-
} else {
|
|
310
|
-
json = atts.geojson;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
const ss = new SimpleStyle(json, {
|
|
314
|
-
cluster: atts.cluster === 'on',
|
|
315
|
-
clusterColor: atts.clusterColor,
|
|
316
|
-
});
|
|
317
|
-
ss.addTo(map);
|
|
318
|
-
|
|
319
|
-
if (
|
|
320
|
-
!container.dataset ||
|
|
321
|
-
(!container.dataset.lng && !container.dataset.lat)
|
|
322
|
-
) {
|
|
323
|
-
ss.fitBounds();
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
if (atts['3d']) {
|
|
328
|
-
const style = map.getStyle();
|
|
329
|
-
style.layers.forEach((layer) => {
|
|
330
|
-
if (
|
|
331
|
-
atts['3d'] === 'on' &&
|
|
332
|
-
layer.metadata &&
|
|
333
|
-
layer.metadata['visible-on-3d'] === true
|
|
334
|
-
) {
|
|
335
|
-
map.setLayoutProperty(layer.id, 'visibility', 'visible');
|
|
336
|
-
} else if (
|
|
337
|
-
atts['3d'] === 'off' &&
|
|
338
|
-
layer.metadata &&
|
|
339
|
-
layer.metadata['visible-on-3d'] === true
|
|
340
|
-
) {
|
|
341
|
-
map.setLayoutProperty(layer.id, 'visibility', 'none');
|
|
342
|
-
} else if (
|
|
343
|
-
atts['3d'] === 'on' &&
|
|
344
|
-
layer.metadata &&
|
|
345
|
-
layer.metadata['hide-on-3d'] === true
|
|
346
|
-
) {
|
|
347
|
-
map.setLayoutProperty(layer.id, 'visibility', 'none');
|
|
348
|
-
} else if (
|
|
349
|
-
atts['3d'] === 'off' &&
|
|
350
|
-
layer.metadata &&
|
|
351
|
-
layer.metadata['hide-on-3d'] === true
|
|
352
|
-
) {
|
|
353
|
-
map.setLayoutProperty(layer.id, 'visibility', 'visible');
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
// handle Geolonia Server errors
|
|
360
|
-
map.on('error', async (error) => {
|
|
361
|
-
if (error.error && error.error.status === 402) {
|
|
362
|
-
handleRestrictedMode(map);
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
container.geoloniaMap = map;
|
|
367
|
-
|
|
368
|
-
return map;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
*
|
|
373
|
-
* @param {string|null} style style identity or `null` when map.remove()
|
|
374
|
-
* @param {*} options
|
|
375
|
-
*/
|
|
376
|
-
setStyle(
|
|
377
|
-
style: string | StyleSpecification,
|
|
378
|
-
options: StyleSwapOptions & StyleOptions = {},
|
|
379
|
-
): this {
|
|
380
|
-
if (style !== null) {
|
|
381
|
-
// It can't access `this` because `setStyle()` will be called with `super()`.
|
|
382
|
-
// So, we need to run `parseAtts()` again(?)
|
|
383
|
-
// Run parseAtts again to get the latest values from DOM.
|
|
384
|
-
const atts = parseAtts(this.getContainer());
|
|
385
|
-
|
|
386
|
-
// If style is object, it must be passed as it.
|
|
387
|
-
if (typeof style === 'string') {
|
|
388
|
-
style = getStyle(style, atts);
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// Tell the `styledata` event handler to load style extensions again
|
|
393
|
-
this.__styleExtensionLoadRequired = true;
|
|
394
|
-
// Calls `maplibregl.Map.setStyle()`.
|
|
395
|
-
super.setStyle.call(this, style, options);
|
|
396
|
-
|
|
397
|
-
return this;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
remove(): void {
|
|
401
|
-
const container = this.getContainer();
|
|
402
|
-
super.remove.call(this);
|
|
403
|
-
delete (container as HTMLElement & { geoloniaMap: GeoloniaMap })
|
|
404
|
-
.geoloniaMap;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
/**
|
|
408
|
-
* Backward compatibility for breaking change of loadImage() in MapLibre GL JS v4.0.0.
|
|
409
|
-
* Related to https://github.com/maplibre/maplibre-gl-js/pull/3422/
|
|
410
|
-
* @param url
|
|
411
|
-
* @param callback
|
|
412
|
-
*/
|
|
413
|
-
loadImage(url: string, callback: GetImageCallback): void;
|
|
414
|
-
loadImage(
|
|
415
|
-
url: string,
|
|
416
|
-
): Promise<GetResourceResponse<HTMLImageElement | ImageBitmap>>;
|
|
417
|
-
loadImage(
|
|
418
|
-
url: string,
|
|
419
|
-
callback?: GetImageCallback,
|
|
420
|
-
): Promise<GetResourceResponse<HTMLImageElement | ImageBitmap>> | void {
|
|
421
|
-
const promise = super.loadImage(url);
|
|
422
|
-
|
|
423
|
-
if (callback) {
|
|
424
|
-
loadImageCompatibility(promise, callback);
|
|
425
|
-
} else {
|
|
426
|
-
return promise;
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import maplibregl, { type MarkerOptions } from 'maplibre-gl';
|
|
4
|
-
import tinycolor from 'tinycolor2';
|
|
5
|
-
import markerSVG from './marker.svg';
|
|
6
|
-
import { handleMarkerOptions } from './util';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Geolonia default marker
|
|
10
|
-
*
|
|
11
|
-
* @param container
|
|
12
|
-
*/
|
|
13
|
-
export default class GeoloniaMarker extends maplibregl.Marker {
|
|
14
|
-
constructor(options: MarkerOptions = {}, legacyOptions: MarkerOptions = {}) {
|
|
15
|
-
options = handleMarkerOptions(options, legacyOptions);
|
|
16
|
-
|
|
17
|
-
if (!options || !options.element) {
|
|
18
|
-
const markerElement = document.createElement('div');
|
|
19
|
-
markerElement.className = 'geolonia-default-marker';
|
|
20
|
-
markerElement.innerHTML = markerSVG;
|
|
21
|
-
|
|
22
|
-
// Following should follow the dimension of marker.svg 52:67.
|
|
23
|
-
markerElement.style.margin = '0';
|
|
24
|
-
markerElement.style.padding = '0';
|
|
25
|
-
markerElement.style.width = '26px';
|
|
26
|
-
markerElement.style.height = '34px';
|
|
27
|
-
|
|
28
|
-
const markerObj = markerElement.querySelector('svg');
|
|
29
|
-
markerObj.style.width = '100%';
|
|
30
|
-
markerObj.style.height = '100%';
|
|
31
|
-
|
|
32
|
-
options.element = markerElement;
|
|
33
|
-
|
|
34
|
-
if (options.color) {
|
|
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();
|
|
39
|
-
} else {
|
|
40
|
-
const defaultColor = '#E4402F';
|
|
41
|
-
(markerElement.querySelector('.left') as HTMLElement).style.fill =
|
|
42
|
-
defaultColor;
|
|
43
|
-
(markerElement.querySelector('.right') as HTMLElement).style.fill =
|
|
44
|
-
tinycolor(defaultColor).darken().toString();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
options.offset = [0, -15];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
super(options);
|
|
51
|
-
return this;
|
|
52
|
-
}
|
|
53
|
-
}
|
package/src/lib/keyring.test.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach, afterAll } from 'vitest';
|
|
2
|
-
import { keyring } from './keyring';
|
|
3
|
-
import { JSDOM } from 'jsdom';
|
|
4
|
-
|
|
5
|
-
describe('parse api key from dom', () => {
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
keyring.reset();
|
|
8
|
-
process.env.MAP_PLATFORM_STAGE = 'dev';
|
|
9
|
-
});
|
|
10
|
-
afterEach(() => {
|
|
11
|
-
delete process.env.MAP_PLATFORM_STAGE;
|
|
12
|
-
});
|
|
13
|
-
afterAll(() => {
|
|
14
|
-
keyring.reset();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('should parse with geolonia flag', () => {
|
|
18
|
-
const { document: mocDocument } = new JSDOM(`<html><body>
|
|
19
|
-
<script src="https://external.example.com/?geolonia-api-key=abc"></script>
|
|
20
|
-
</body></html>`).window;
|
|
21
|
-
|
|
22
|
-
keyring.parse(mocDocument);
|
|
23
|
-
expect(keyring.apiKey).toEqual('abc');
|
|
24
|
-
expect(keyring.stage).toEqual('dev');
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should parse with geolonia flag (multiple scripts)', () => {
|
|
28
|
-
const { document: mocDocument } = new JSDOM(`<html><body>
|
|
29
|
-
<script src="https://external.example.com/jquery.js"></script>
|
|
30
|
-
<script src="https://external.example.com/?geolonia-api-key=def"></script>
|
|
31
|
-
</body></html>`).window;
|
|
32
|
-
|
|
33
|
-
keyring.parse(mocDocument);
|
|
34
|
-
expect(keyring.apiKey).toEqual('def');
|
|
35
|
-
expect(keyring.stage).toEqual('dev');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('should be "YOUR-API-KEY" and "dev"', () => {
|
|
39
|
-
const { document: mocDocument } = new JSDOM(`<html><body>
|
|
40
|
-
<script src="https://external.example.com/jquery.js"></script>
|
|
41
|
-
<script type="text/javascript" src="https://api.geolonia.com/dev/embed?geolonia-api-key=YOUR-API-KEY"></script>
|
|
42
|
-
</body></html>`).window;
|
|
43
|
-
|
|
44
|
-
keyring.parse(mocDocument);
|
|
45
|
-
expect(keyring.apiKey).toEqual('YOUR-API-KEY');
|
|
46
|
-
expect(keyring.stage).toEqual('dev');
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('should be "YOUR-API-KEY" and "v1"', () => {
|
|
50
|
-
process.env.MAP_PLATFORM_STAGE = 'v1';
|
|
51
|
-
const { document: mocDocument } = new JSDOM(`<html><body>
|
|
52
|
-
<script src="https://external.example.com/jquery.js"></script>
|
|
53
|
-
<script type="text/javascript" src="https://api.geolonia.com/v1/embed?geolonia-api-key=YOUR-API-KEY"></script>
|
|
54
|
-
</body></html>`).window;
|
|
55
|
-
|
|
56
|
-
keyring.parse(mocDocument);
|
|
57
|
-
expect(keyring.apiKey).toEqual('YOUR-API-KEY');
|
|
58
|
-
expect(keyring.stage).toEqual('v1');
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('should be "YOUR-API-KEY" and "v123.4"', () => {
|
|
62
|
-
process.env.MAP_PLATFORM_STAGE = 'v123.4';
|
|
63
|
-
const { document: mocDocument } = new JSDOM(`<html><body>
|
|
64
|
-
<script src="https://external.example.com/jquery.js"></script>
|
|
65
|
-
<script type="text/javascript" src="https://api.geolonia.com/v123.4/embed?geolonia-api-key=YOUR-API-KEY"></script>
|
|
66
|
-
</body></html>`).window;
|
|
67
|
-
|
|
68
|
-
keyring.parse(mocDocument);
|
|
69
|
-
expect(keyring.apiKey).toEqual('YOUR-API-KEY');
|
|
70
|
-
expect(keyring.stage).toEqual('v123.4');
|
|
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
|
-
expect(keyring.apiKey).toEqual('YOUR-API-KEY');
|
|
82
|
-
expect(keyring.stage).toEqual('dev');
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
describe('isGeoloniaStyleCheck', () => {
|
|
87
|
-
it('should return true for empty or null style (default)', () => {
|
|
88
|
-
expect(keyring.isGeoloniaStyleCheck('')).toBe(true);
|
|
89
|
-
expect(keyring.isGeoloniaStyleCheck(null)).toBe(true);
|
|
90
|
-
expect(keyring.isGeoloniaStyleCheck(undefined)).toBe(true);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('should return true for Geolonia logical names', () => {
|
|
94
|
-
expect(keyring.isGeoloniaStyleCheck('geolonia/basic')).toBe(true);
|
|
95
|
-
expect(keyring.isGeoloniaStyleCheck('geolonia/basic-v2')).toBe(true);
|
|
96
|
-
expect(keyring.isGeoloniaStyleCheck('geolonia/gsi')).toBe(true);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('should return true for Geolonia CDN URLs', () => {
|
|
100
|
-
expect(keyring.isGeoloniaStyleCheck('https://cdn.geolonia.com/style/geolonia/basic/ja.json')).toBe(true);
|
|
101
|
-
expect(keyring.isGeoloniaStyleCheck('https://api.geolonia.com/v1/styles/basic.json')).toBe(true);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('should return false for external HTTPS URLs', () => {
|
|
105
|
-
expect(keyring.isGeoloniaStyleCheck('https://tile.openstreetmap.jp/styles/osm-bright/style.json')).toBe(false);
|
|
106
|
-
expect(keyring.isGeoloniaStyleCheck('https://example.com/style.json')).toBe(false);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('should return false for relative paths to external .json files', () => {
|
|
110
|
-
expect(keyring.isGeoloniaStyleCheck('./my-style.json')).toBe(false);
|
|
111
|
-
expect(keyring.isGeoloniaStyleCheck('/styles/custom.json')).toBe(false);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('should return true for relative paths to geolonia.com', () => {
|
|
115
|
-
// Simulate being on geolonia.com
|
|
116
|
-
const origHref = global.location?.href;
|
|
117
|
-
global.location = {
|
|
118
|
-
...global.location,
|
|
119
|
-
href: 'https://cdn.geolonia.com/demo.html',
|
|
120
|
-
};
|
|
121
|
-
expect(keyring.isGeoloniaStyleCheck('./style.json')).toBe(true);
|
|
122
|
-
// Restore
|
|
123
|
-
if (origHref) {
|
|
124
|
-
global.location = { ...global.location, href: origHref };
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
});
|