@geolonia/embed 4.3.0 → 5.0.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 +99 -36
- package/.nvmrc +1 -1
- package/.prettierrc.json +4 -0
- package/.tool-versions +1 -1
- package/README.md +7 -1
- package/dist/e2e/basic.spec.d.ts +8 -0
- package/dist/e2e/helper.d.ts +4 -0
- package/dist/embed +2 -1
- package/dist/embed-chunks/2489af4328c51b71e92d.js +2 -0
- package/dist/embed-chunks/6e05bbf5f391fda5b858.js +1 -0
- package/dist/embed.js +2 -1
- package/dist/embed.js.LICENSE.txt +4 -0
- package/dist/playwright.config.d.ts +9 -0
- package/dist/{embed.d.ts → src/embed.d.ts} +3 -1
- package/dist/{lib → src/lib}/geolonia-map.d.ts +10 -2
- package/dist/{lib → src/lib}/geolonia-marker.d.ts +1 -2
- package/dist/{lib → src/lib}/maplibre-util.d.ts +1 -3
- package/dist/{lib → src/lib}/util.d.ts +6 -3
- package/dist/src/lib/util.test.d.ts +1 -0
- package/dist/src/testability.test.d.ts +1 -0
- package/dist/src/version.d.ts +1 -0
- package/e2e/basic.spec.ts +52 -0
- package/e2e/helper.ts +12 -0
- package/e2e/map.spec.ts +69 -0
- package/eslint.config.js +232 -0
- package/package.json +25 -12
- package/playwright.config.ts +79 -0
- package/src/embed.ts +13 -7
- package/src/lib/CustomAttributionControl.ts +52 -29
- package/src/lib/geolonia-map.ts +144 -38
- 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 +2 -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 +61 -43
- package/src/lib/util.test.ts +108 -21
- package/src/lib/util.ts +115 -32
- package/src/testability.test.ts +46 -0
- package/tsconfig.json +3 -1
- package/webpack.config.js +10 -1
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -14
- package/.prettierrc.js +0 -1
- package/dist/embed-chunks/b52b89229e47dc93c64b.js +0 -2
- package/dist/embed-chunks/d0f087405f7ae2fcf1c1.js +0 -1
- package/dist/version.d.ts +0 -1
- /package/dist/{lib/keyring.test.d.ts → e2e/map.spec.d.ts} +0 -0
- /package/dist/embed-chunks/{b52b89229e47dc93c64b.js.LICENSE.txt → 2489af4328c51b71e92d.js.LICENSE.txt} +0 -0
- /package/dist/{lib → src/lib}/CustomAttributionControl.d.ts +0 -0
- /package/dist/{lib → src/lib}/controls/geolonia-control.d.ts +0 -0
- /package/dist/{lib → src/lib}/keyring.d.ts +0 -0
- /package/dist/{lib/parse-atts.test.d.ts → src/lib/keyring.test.d.ts} +0 -0
- /package/dist/{lib → src/lib}/parse-atts.d.ts +0 -0
- /package/dist/{lib/simplestyle.test.d.ts → src/lib/parse-atts.test.d.ts} +0 -0
- /package/dist/{lib → src/lib}/render.d.ts +0 -0
- /package/dist/{lib → src/lib}/simplestyle-vector.d.ts +0 -0
- /package/dist/{lib → src/lib}/simplestyle.d.ts +0 -0
- /package/dist/{lib/util.test.d.ts → src/lib/simplestyle.test.d.ts} +0 -0
- /package/dist/{types-internal.d.ts → src/types-internal.d.ts} +0 -0
|
@@ -40,23 +40,16 @@ class CustomAttributionControl implements IControl {
|
|
|
40
40
|
|
|
41
41
|
constructor(options = {}) {
|
|
42
42
|
this.options = options;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
bindAll([
|
|
55
|
-
'_toggleAttribution',
|
|
56
|
-
'_updateData',
|
|
57
|
-
'_updateCompact',
|
|
58
|
-
'_updateCompactMinimize',
|
|
59
|
-
], this);
|
|
43
|
+
|
|
44
|
+
bindAll(
|
|
45
|
+
[
|
|
46
|
+
'_toggleAttribution',
|
|
47
|
+
'_updateData',
|
|
48
|
+
'_updateCompact',
|
|
49
|
+
'_updateCompactMinimize',
|
|
50
|
+
],
|
|
51
|
+
this,
|
|
52
|
+
);
|
|
60
53
|
}
|
|
61
54
|
|
|
62
55
|
getDefaultPosition(): ControlPosition {
|
|
@@ -68,13 +61,24 @@ class CustomAttributionControl implements IControl {
|
|
|
68
61
|
this._compact = this.options && this.options.compact;
|
|
69
62
|
this._container = DOM.create('div');
|
|
70
63
|
|
|
71
|
-
const shadow = this._container.attachShadow({mode: 'open'});
|
|
72
|
-
|
|
73
|
-
this._shadowContainer = DOM.create(
|
|
74
|
-
|
|
64
|
+
const shadow = this._container.attachShadow({ mode: 'open' });
|
|
65
|
+
|
|
66
|
+
this._shadowContainer = DOM.create(
|
|
67
|
+
'details',
|
|
68
|
+
'maplibregl-ctrl maplibregl-ctrl-attrib',
|
|
69
|
+
);
|
|
70
|
+
this._compactButton = DOM.create(
|
|
71
|
+
'summary',
|
|
72
|
+
'maplibregl-ctrl-attrib-button',
|
|
73
|
+
this._shadowContainer,
|
|
74
|
+
);
|
|
75
75
|
this._compactButton.addEventListener('click', this._toggleAttribution);
|
|
76
76
|
this._setElementTitle(this._compactButton, 'ToggleAttribution');
|
|
77
|
-
this._innerContainer = DOM.create(
|
|
77
|
+
this._innerContainer = DOM.create(
|
|
78
|
+
'div',
|
|
79
|
+
'maplibregl-ctrl-attrib-inner',
|
|
80
|
+
this._shadowContainer,
|
|
81
|
+
);
|
|
78
82
|
|
|
79
83
|
const style = document.createElement('style');
|
|
80
84
|
style.textContent = `
|
|
@@ -274,7 +278,13 @@ class CustomAttributionControl implements IControl {
|
|
|
274
278
|
}
|
|
275
279
|
|
|
276
280
|
_updateData(e) {
|
|
277
|
-
if (
|
|
281
|
+
if (
|
|
282
|
+
e &&
|
|
283
|
+
(e.sourceDataType === 'metadata' ||
|
|
284
|
+
e.sourceDataType === 'visibility' ||
|
|
285
|
+
e.dataType === 'style' ||
|
|
286
|
+
e.type === 'terrain')
|
|
287
|
+
) {
|
|
278
288
|
this._updateAttributions();
|
|
279
289
|
}
|
|
280
290
|
}
|
|
@@ -306,7 +316,10 @@ class CustomAttributionControl implements IControl {
|
|
|
306
316
|
const sourceCache = sourceCaches[id];
|
|
307
317
|
if (sourceCache.used || sourceCache.usedForTerrain) {
|
|
308
318
|
const source = sourceCache.getSource();
|
|
309
|
-
if (
|
|
319
|
+
if (
|
|
320
|
+
source.attribution &&
|
|
321
|
+
attributions.indexOf(source.attribution) < 0
|
|
322
|
+
) {
|
|
310
323
|
attributions.push(source.attribution);
|
|
311
324
|
}
|
|
312
325
|
}
|
|
@@ -320,7 +333,9 @@ class CustomAttributionControl implements IControl {
|
|
|
320
333
|
attributions.sort((a, b) => a.length - b.length);
|
|
321
334
|
attributions = attributions.filter((attrib, i) => {
|
|
322
335
|
for (let j = i + 1; j < attributions.length; j++) {
|
|
323
|
-
if (attributions[j].indexOf(attrib) >= 0) {
|
|
336
|
+
if (attributions[j].indexOf(attrib) >= 0) {
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
324
339
|
}
|
|
325
340
|
return true;
|
|
326
341
|
});
|
|
@@ -346,14 +361,23 @@ class CustomAttributionControl implements IControl {
|
|
|
346
361
|
if (this._map.getCanvasContainer().offsetWidth <= 640 || this._compact) {
|
|
347
362
|
if (this._compact === false) {
|
|
348
363
|
this._shadowContainer.setAttribute('open', '');
|
|
349
|
-
} else if (
|
|
364
|
+
} else if (
|
|
365
|
+
!this._shadowContainer.classList.contains('maplibregl-compact') &&
|
|
366
|
+
!this._shadowContainer.classList.contains('maplibregl-attrib-empty')
|
|
367
|
+
) {
|
|
350
368
|
this._shadowContainer.setAttribute('open', '');
|
|
351
|
-
this._shadowContainer.classList.add(
|
|
369
|
+
this._shadowContainer.classList.add(
|
|
370
|
+
'maplibregl-compact',
|
|
371
|
+
'maplibregl-compact-show',
|
|
372
|
+
);
|
|
352
373
|
}
|
|
353
374
|
} else {
|
|
354
375
|
this._shadowContainer.setAttribute('open', '');
|
|
355
376
|
if (this._shadowContainer.classList.contains('maplibregl-compact')) {
|
|
356
|
-
this._shadowContainer.classList.remove(
|
|
377
|
+
this._shadowContainer.classList.remove(
|
|
378
|
+
'maplibregl-compact',
|
|
379
|
+
'maplibregl-compact-show',
|
|
380
|
+
);
|
|
357
381
|
}
|
|
358
382
|
}
|
|
359
383
|
}
|
|
@@ -365,7 +389,6 @@ class CustomAttributionControl implements IControl {
|
|
|
365
389
|
}
|
|
366
390
|
}
|
|
367
391
|
}
|
|
368
|
-
|
|
369
392
|
}
|
|
370
393
|
|
|
371
394
|
export default CustomAttributionControl;
|
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,17 +137,23 @@ 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 (
|
|
116
|
-
|
|
117
|
-
|
|
151
|
+
if (
|
|
152
|
+
resourceType === 'Source' &&
|
|
153
|
+
geoloniaTilesHost
|
|
154
|
+
) {
|
|
155
|
+
if (atts.stage === 'dev') {
|
|
156
|
+
transformedUrlObj.hostname = 'tileserver-dev.geolonia.com';
|
|
118
157
|
}
|
|
119
158
|
transformedUrlObj.searchParams.set('sessionId', sessionId);
|
|
120
159
|
transformedUrlObj.searchParams.set('key', atts.key);
|
|
@@ -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,6 +399,30 @@ 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;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Backward compatibility for breaking change of loadImage() in MapLibre GL JS v4.0.0.
|
|
408
|
+
* Related to https://github.com/maplibre/maplibre-gl-js/pull/3422/
|
|
409
|
+
* @param url
|
|
410
|
+
* @param callback
|
|
411
|
+
*/
|
|
412
|
+
loadImage(url: string, callback: GetImageCallback): void;
|
|
413
|
+
loadImage(
|
|
414
|
+
url: string,
|
|
415
|
+
): Promise<GetResourceResponse<HTMLImageElement | ImageBitmap>>;
|
|
416
|
+
loadImage(
|
|
417
|
+
url: string,
|
|
418
|
+
callback?: GetImageCallback,
|
|
419
|
+
): Promise<GetResourceResponse<HTMLImageElement | ImageBitmap>> | void {
|
|
420
|
+
const promise = super.loadImage(url);
|
|
421
|
+
|
|
422
|
+
if (callback) {
|
|
423
|
+
loadImageCompatibility(promise, callback);
|
|
424
|
+
} else {
|
|
425
|
+
return promise;
|
|
426
|
+
}
|
|
321
427
|
}
|
|
322
428
|
}
|
|
@@ -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
|
}
|