@geolonia/embed 5.0.3 → 5.1.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/.github/workflows/build.yml +9 -4
- package/.vscode/settings.json +27 -0
- package/CHANGELOG.md +9 -0
- package/README.md +71 -2
- package/dist/e2e/external-style.spec.d.ts +1 -0
- package/dist/embed +1 -1
- package/dist/embed-chunks/1492645e3d07fd3de940.js +1 -0
- package/dist/embed-chunks/8983d465846d11f2859f.js +2 -0
- package/dist/embed-chunks/8983d465846d11f2859f.js.LICENSE.txt +6 -0
- package/dist/embed-core.js +2 -0
- package/dist/embed-core.js.LICENSE.txt +4 -0
- package/dist/embed.js +1 -1
- package/dist/src/embed-core.d.ts +14 -0
- package/dist/src/embed.d.ts +2 -37
- package/dist/src/lib/keyring.d.ts +16 -0
- package/dist/src/lib/parse-atts.d.ts +1 -1
- package/dist/src/lib/simplestyle.d.ts +2 -0
- package/dist/src/lib/util.d.ts +3 -3
- package/dist/src/types.d.ts +38 -0
- package/dist/src/version.d.ts +1 -1
- package/e2e/basic.spec.ts +6 -1
- package/e2e/external-style.spec.ts +25 -0
- package/e2e/map.spec.ts +12 -12
- package/package.json +12 -2
- package/src/embed-core.ts +22 -0
- package/src/embed.ts +2 -42
- package/src/lib/geolonia-map.ts +4 -3
- package/src/lib/geolonia-marker.ts +1 -1
- package/src/lib/keyring.test.ts +55 -0
- package/src/lib/keyring.ts +53 -1
- package/src/lib/parse-atts.ts +5 -1
- package/src/lib/render.ts +1 -1
- package/src/lib/simplestyle.ts +75 -17
- package/src/lib/util.test.ts +76 -2
- package/src/lib/util.ts +55 -10
- package/src/types.ts +44 -0
- package/webpack.config.js +39 -13
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Side-effect-free entry point for programmatic use (e.g. React wrapper).
|
|
3
|
+
* Does NOT call renderGeoloniaMap() or set window.geolonia.
|
|
4
|
+
* Only registers the PMTiles protocol, which is required for all users.
|
|
5
|
+
*/
|
|
6
|
+
export { default as GeoloniaMap } from './lib/geolonia-map';
|
|
7
|
+
export { default as GeoloniaMarker } from './lib/geolonia-marker';
|
|
8
|
+
export { SimpleStyle } from './lib/simplestyle';
|
|
9
|
+
export { default as SimpleStyleVector } from './lib/simplestyle-vector';
|
|
10
|
+
export { keyring } from './lib/keyring';
|
|
11
|
+
export { registerPlugin } from './lib/render';
|
|
12
|
+
export { VERSION as embedVersion } from './version';
|
|
13
|
+
export type { EmbedAttributes, EmbedPlugin } from './types';
|
|
14
|
+
export type { GeoloniaMapOptions } from './lib/geolonia-map';
|
package/dist/src/embed.d.ts
CHANGED
|
@@ -8,43 +8,8 @@ import { SimpleStyle } from './lib/simplestyle';
|
|
|
8
8
|
import { VERSION as embedVersion } from './version';
|
|
9
9
|
export type { GeoloniaMapOptions } from './lib/geolonia-map';
|
|
10
10
|
export type Popup = maplibregl.Popup;
|
|
11
|
-
export type EmbedAttributes
|
|
12
|
-
|
|
13
|
-
lng: string;
|
|
14
|
-
zoom: string;
|
|
15
|
-
bearing: string;
|
|
16
|
-
pitch: string;
|
|
17
|
-
hash: string;
|
|
18
|
-
marker: string;
|
|
19
|
-
markerColor: string;
|
|
20
|
-
openPopup: string;
|
|
21
|
-
customMarker: string;
|
|
22
|
-
customMarkerOffset: string;
|
|
23
|
-
gestureHandling: string;
|
|
24
|
-
navigationControl: string;
|
|
25
|
-
geolocateControl: string;
|
|
26
|
-
fullscreenControl: string;
|
|
27
|
-
scaleControl: string;
|
|
28
|
-
geoloniaControl: string;
|
|
29
|
-
geojson: string;
|
|
30
|
-
cluster: string;
|
|
31
|
-
clusterColor: string;
|
|
32
|
-
style: string;
|
|
33
|
-
lang: string;
|
|
34
|
-
plugin: string;
|
|
35
|
-
key: string;
|
|
36
|
-
apiUrl: string;
|
|
37
|
-
loader: string;
|
|
38
|
-
minZoom: string;
|
|
39
|
-
maxZoom: string;
|
|
40
|
-
'3d': string;
|
|
41
|
-
[otherKey: string]: string;
|
|
42
|
-
};
|
|
43
|
-
export type EmbedPlugin<PluginAttributes extends {
|
|
44
|
-
[otherKey: string]: string;
|
|
45
|
-
} = {
|
|
46
|
-
[otherKey: string]: string;
|
|
47
|
-
}> = (map: GeoloniaMap, target: HTMLElement, atts: EmbedAttributes & PluginAttributes) => void;
|
|
11
|
+
export type { EmbedAttributes, EmbedPlugin } from './types';
|
|
12
|
+
import type { EmbedPlugin } from './types';
|
|
48
13
|
export type Geolonia = Partial<typeof maplibregl> & {
|
|
49
14
|
accessToken?: string;
|
|
50
15
|
embedVersion: string;
|
|
@@ -4,6 +4,14 @@ declare class Keyring {
|
|
|
4
4
|
* @returns API key
|
|
5
5
|
*/
|
|
6
6
|
get apiKey(): string;
|
|
7
|
+
/**
|
|
8
|
+
* @returns Whether using Geolonia style (true) or external style (false)
|
|
9
|
+
*/
|
|
10
|
+
get isGeoloniaStyle(): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* @param isGeoloniaStyle - Set whether using Geolonia style
|
|
13
|
+
*/
|
|
14
|
+
set isGeoloniaStyle(value: boolean);
|
|
7
15
|
/**
|
|
8
16
|
* @param key - API Key to set
|
|
9
17
|
*/
|
|
@@ -24,6 +32,14 @@ declare class Keyring {
|
|
|
24
32
|
parse(doc?: Document): void;
|
|
25
33
|
/** Reset API key and stage for testing purpose */
|
|
26
34
|
reset(): void;
|
|
35
|
+
/**
|
|
36
|
+
* Check if the given style is a Geolonia style (requires API key)
|
|
37
|
+
* Note: This is a method, not the property. Use keyring.isGeoloniaStyle property
|
|
38
|
+
* to check the current style type, or call this method to check a specific style.
|
|
39
|
+
* @param style - Style name or URL
|
|
40
|
+
* @returns true if it's a Geolonia style (requires API key)
|
|
41
|
+
*/
|
|
42
|
+
isGeoloniaStyleCheck(style: string): boolean;
|
|
27
43
|
}
|
|
28
44
|
declare const keyring: Keyring;
|
|
29
45
|
export { keyring };
|
|
@@ -4,6 +4,7 @@ export declare class SimpleStyle {
|
|
|
4
4
|
private geojson;
|
|
5
5
|
private map;
|
|
6
6
|
private options;
|
|
7
|
+
private _eventHandlers;
|
|
7
8
|
constructor(geojson: any, options?: any);
|
|
8
9
|
updateData(geojson: any): this;
|
|
9
10
|
addTo(map: any): this;
|
|
@@ -25,5 +26,6 @@ export declare class SimpleStyle {
|
|
|
25
26
|
* Setup cluster markers
|
|
26
27
|
*/
|
|
27
28
|
setCluster(): void;
|
|
29
|
+
remove(): this;
|
|
28
30
|
setGeoJSON(geojson: any): void;
|
|
29
31
|
}
|
package/dist/src/lib/util.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare function getLang(): "ja" | "en";
|
|
|
14
14
|
*/
|
|
15
15
|
export declare function isScrollable(): boolean;
|
|
16
16
|
/**
|
|
17
|
-
* Detects the object is
|
|
17
|
+
* Detects the object is HTMLElement?
|
|
18
18
|
*
|
|
19
19
|
* @param {*} o
|
|
20
20
|
*/
|
|
@@ -36,12 +36,12 @@ export declare function getContainer(arg: HTMLElement | string | {
|
|
|
36
36
|
* @param {*} legacyOptions
|
|
37
37
|
*/
|
|
38
38
|
export declare function handleMarkerOptions(options: MarkerOptions | null | undefined | false, legacyOptions: MarkerOptions): MarkerOptions;
|
|
39
|
-
export declare function getStyle(style: any, atts: any):
|
|
39
|
+
export declare function getStyle(style: any, atts: any): any;
|
|
40
40
|
export declare function getOptions(container: any, params: any, atts: any): MapOptions;
|
|
41
41
|
/**
|
|
42
42
|
*
|
|
43
43
|
* @param {string} an data-*-control Embed attribute
|
|
44
|
-
* @returns { enabled:
|
|
44
|
+
* @returns { enabled: boolean, position: 'top-right' | 'bottom-right' | 'bottom-left' | 'top-left' | void }
|
|
45
45
|
*/
|
|
46
46
|
export declare function parseControlOption(att: any): {
|
|
47
47
|
enabled: boolean;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type GeoloniaMap from './lib/geolonia-map';
|
|
2
|
+
export type EmbedAttributes = {
|
|
3
|
+
lat: string | number;
|
|
4
|
+
lng: string | number;
|
|
5
|
+
zoom: string | number;
|
|
6
|
+
bearing: string | number;
|
|
7
|
+
pitch: string | number;
|
|
8
|
+
hash: string;
|
|
9
|
+
marker: string;
|
|
10
|
+
markerColor: string;
|
|
11
|
+
openPopup: string;
|
|
12
|
+
customMarker: string;
|
|
13
|
+
customMarkerOffset: string;
|
|
14
|
+
gestureHandling: string;
|
|
15
|
+
navigationControl: string;
|
|
16
|
+
geolocateControl: string;
|
|
17
|
+
fullscreenControl: string;
|
|
18
|
+
scaleControl: string;
|
|
19
|
+
geoloniaControl: string;
|
|
20
|
+
geojson: string;
|
|
21
|
+
cluster: string;
|
|
22
|
+
clusterColor: string;
|
|
23
|
+
style: string;
|
|
24
|
+
lang: string;
|
|
25
|
+
plugin: string;
|
|
26
|
+
key: string;
|
|
27
|
+
apiUrl: string;
|
|
28
|
+
loader: string;
|
|
29
|
+
minZoom: string | number;
|
|
30
|
+
maxZoom: string | number;
|
|
31
|
+
'3d': string;
|
|
32
|
+
[otherKey: string]: string | number;
|
|
33
|
+
};
|
|
34
|
+
export type EmbedPlugin<PluginAttributes extends {
|
|
35
|
+
[otherKey: string]: string;
|
|
36
|
+
} = {
|
|
37
|
+
[otherKey: string]: string;
|
|
38
|
+
}> = (map: GeoloniaMap, target: HTMLElement, atts: EmbedAttributes & PluginAttributes) => void;
|
package/dist/src/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "5.0
|
|
1
|
+
export declare const VERSION = "5.1.0";
|
package/e2e/basic.spec.ts
CHANGED
|
@@ -41,7 +41,12 @@ test.describe('1. 基本的な地図表示', () => {
|
|
|
41
41
|
const consoleErrors: string[] = [];
|
|
42
42
|
page.on('console', (msg) => {
|
|
43
43
|
if (msg.type() === 'error') {
|
|
44
|
-
|
|
44
|
+
const text = msg.text();
|
|
45
|
+
// タイル取得失敗などブラウザレベルのネットワークエラーは除外し、
|
|
46
|
+
// アプリコードが出すエラーのみチェックする
|
|
47
|
+
if (!text.startsWith('Failed to load resource')) {
|
|
48
|
+
consoleErrors.push(text);
|
|
49
|
+
}
|
|
45
50
|
}
|
|
46
51
|
});
|
|
47
52
|
await page.goto(`${TEST_URL}/basic.html`);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { test, expect } from '@playwright/test';
|
|
2
|
+
import { TEST_URL, waitForMapLoad } from './helper';
|
|
3
|
+
|
|
4
|
+
const EXTERNAL_STYLE_URL = 'https://tile.openstreetmap.jp/styles/osm-bright/style.json';
|
|
5
|
+
|
|
6
|
+
test.describe('External Style Support', () => {
|
|
7
|
+
test('data-style で外部スタイルを指定しても地図が表示されること', async ({ page }) => {
|
|
8
|
+
await page.goto(`${TEST_URL}/external-style.html`);
|
|
9
|
+
await waitForMapLoad(page, '#map');
|
|
10
|
+
|
|
11
|
+
const mapCanvas = page.locator('#map canvas.maplibregl-canvas');
|
|
12
|
+
await expect(mapCanvas).toBeVisible();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('data-style で指定した外部スタイルURLにアクセスしていること', async ({ page }) => {
|
|
16
|
+
const styleRequest = page.waitForRequest((req) =>
|
|
17
|
+
req.url().includes(EXTERNAL_STYLE_URL),
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
await page.goto(`${TEST_URL}/external-style.html`);
|
|
21
|
+
|
|
22
|
+
const req = await styleRequest;
|
|
23
|
+
expect(req.url()).toBe(EXTERNAL_STYLE_URL);
|
|
24
|
+
});
|
|
25
|
+
});
|
package/e2e/map.spec.ts
CHANGED
|
@@ -9,18 +9,18 @@ test.describe('1. 基本的な地図表示', () => {
|
|
|
9
9
|
|
|
10
10
|
test.describe.serial('2.1 地図が表示できること', () => {
|
|
11
11
|
test('2.1.1 ページ読み込み時に地図がロードされること', async ({ page }) => {
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
// マップインスタンスが生成されていることを確認する。
|
|
13
|
+
// map.loaded()はすべてのタイルのレンダリング完了を意味するため、
|
|
14
|
+
// テスト用APIキーではタイル取得が失敗しタイムアウトする可能性がある。
|
|
15
|
+
// ここではインスタンス生成とキャンバス描画の確認のみ行う。
|
|
16
|
+
const hasMap = await page.evaluate(() => {
|
|
17
|
+
const container = document.querySelector('#map') as any;
|
|
18
|
+
return !!(container && container.geoloniaMap);
|
|
19
|
+
});
|
|
20
|
+
expect(hasMap).toBe(true);
|
|
21
|
+
|
|
22
|
+
const canvas = page.locator('.maplibregl-canvas');
|
|
23
|
+
await expect(canvas).toBeVisible();
|
|
24
24
|
});
|
|
25
25
|
test('2.1.2 タイルが描画されていることを確認(上半分のみ)', async ({ page }) => {
|
|
26
26
|
const isNotBlank = await page.evaluate(() => {
|
package/package.json
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geolonia/embed",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "Geolonia embed JS API",
|
|
5
5
|
"main": "dist/embed.js",
|
|
6
6
|
"types": "dist/src/embed.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/src/embed.d.ts",
|
|
10
|
+
"default": "./dist/embed.js"
|
|
11
|
+
},
|
|
12
|
+
"./core": {
|
|
13
|
+
"types": "./dist/src/embed-core.d.ts",
|
|
14
|
+
"default": "./dist/embed-core.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
7
17
|
"scripts": {
|
|
8
18
|
"prestart": "npm run build:version",
|
|
9
19
|
"prelint": "npm run build:version",
|
|
10
|
-
"start": "webpack serve --config ./docs/webpack.config.js",
|
|
20
|
+
"start": "MAP_PLATFORM_STAGE=v1 webpack serve --config ./docs/webpack.config.js",
|
|
11
21
|
"build": "npm run build:version && npm run build:embed",
|
|
12
22
|
"build:version": "node ./scripts/build-version.mjs",
|
|
13
23
|
"build:embed": "MAP_PLATFORM_STAGE=v1 webpack --mode production && cp ./dist/embed.js ./dist/embed && cp -r ./dist/* ./docs/ && rm -rf ./docs/*.d.ts ./docs/lib/",
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Side-effect-free entry point for programmatic use (e.g. React wrapper).
|
|
3
|
+
* Does NOT call renderGeoloniaMap() or set window.geolonia.
|
|
4
|
+
* Only registers the PMTiles protocol, which is required for all users.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import maplibregl from 'maplibre-gl';
|
|
8
|
+
import { Protocol } from 'pmtiles';
|
|
9
|
+
|
|
10
|
+
// PMTiles protocol registration (required side effect)
|
|
11
|
+
const protocol = new Protocol();
|
|
12
|
+
maplibregl.addProtocol('pmtiles', protocol.tile);
|
|
13
|
+
|
|
14
|
+
export { default as GeoloniaMap } from './lib/geolonia-map';
|
|
15
|
+
export { default as GeoloniaMarker } from './lib/geolonia-marker';
|
|
16
|
+
export { SimpleStyle } from './lib/simplestyle';
|
|
17
|
+
export { default as SimpleStyleVector } from './lib/simplestyle-vector';
|
|
18
|
+
export { keyring } from './lib/keyring';
|
|
19
|
+
export { registerPlugin } from './lib/render';
|
|
20
|
+
export { VERSION as embedVersion } from './version';
|
|
21
|
+
export type { EmbedAttributes, EmbedPlugin } from './types';
|
|
22
|
+
export type { GeoloniaMapOptions } from './lib/geolonia-map';
|
package/src/embed.ts
CHANGED
|
@@ -13,48 +13,8 @@ export type { GeoloniaMapOptions } from './lib/geolonia-map';
|
|
|
13
13
|
|
|
14
14
|
export type Popup = maplibregl.Popup;
|
|
15
15
|
|
|
16
|
-
export type EmbedAttributes
|
|
17
|
-
|
|
18
|
-
lng: string;
|
|
19
|
-
zoom: string;
|
|
20
|
-
bearing: string;
|
|
21
|
-
pitch: string;
|
|
22
|
-
hash: string;
|
|
23
|
-
marker: string;
|
|
24
|
-
markerColor: string;
|
|
25
|
-
openPopup: string;
|
|
26
|
-
customMarker: string;
|
|
27
|
-
customMarkerOffset: string;
|
|
28
|
-
gestureHandling: string;
|
|
29
|
-
navigationControl: string;
|
|
30
|
-
geolocateControl: string;
|
|
31
|
-
fullscreenControl: string;
|
|
32
|
-
scaleControl: string;
|
|
33
|
-
geoloniaControl: string;
|
|
34
|
-
geojson: string;
|
|
35
|
-
cluster: string;
|
|
36
|
-
clusterColor: string;
|
|
37
|
-
style: string;
|
|
38
|
-
lang: string;
|
|
39
|
-
plugin: string;
|
|
40
|
-
key: string;
|
|
41
|
-
apiUrl: string;
|
|
42
|
-
loader: string;
|
|
43
|
-
minZoom: string;
|
|
44
|
-
maxZoom: string;
|
|
45
|
-
'3d': string;
|
|
46
|
-
[otherKey: string]: string;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export type EmbedPlugin<
|
|
50
|
-
PluginAttributes extends { [otherKey: string]: string } = {
|
|
51
|
-
[otherKey: string]: string;
|
|
52
|
-
},
|
|
53
|
-
> = (
|
|
54
|
-
map: GeoloniaMap,
|
|
55
|
-
target: HTMLElement,
|
|
56
|
-
atts: EmbedAttributes & PluginAttributes,
|
|
57
|
-
) => void;
|
|
16
|
+
export type { EmbedAttributes, EmbedPlugin } from './types';
|
|
17
|
+
import type { EmbedPlugin } from './types';
|
|
58
18
|
|
|
59
19
|
// Type for `window.geolonia`
|
|
60
20
|
export type Geolonia = Partial<typeof maplibregl> & {
|
package/src/lib/geolonia-map.ts
CHANGED
|
@@ -106,7 +106,7 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
106
106
|
let loading;
|
|
107
107
|
if (atts.loader !== 'off') {
|
|
108
108
|
loading = document.createElement('div');
|
|
109
|
-
// prevent
|
|
109
|
+
// prevent pinch-in & pinch-out
|
|
110
110
|
loading.addEventListener('touchmove', (e) => {
|
|
111
111
|
if (e.touches && e.touches.length > 1) {
|
|
112
112
|
e.preventDefault();
|
|
@@ -148,11 +148,12 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
148
148
|
const transformedUrlObj = new URL(transformedUrl);
|
|
149
149
|
const geoloniaTilesHost = isGeoloniaTilesHost(transformedUrlObj);
|
|
150
150
|
|
|
151
|
+
// Geolonia ドメインのみに API キーを付与(外部 URL には付与しない)
|
|
151
152
|
if (
|
|
152
153
|
resourceType === 'Source' &&
|
|
153
154
|
geoloniaTilesHost
|
|
154
155
|
) {
|
|
155
|
-
if (atts.stage === 'dev') {
|
|
156
|
+
if (atts.stage === 'dev' && transformedUrlObj.hostname === 'tileserver.geolonia.com') {
|
|
156
157
|
transformedUrlObj.hostname = 'tileserver-dev.geolonia.com';
|
|
157
158
|
}
|
|
158
159
|
transformedUrlObj.searchParams.set('sessionId', sessionId);
|
|
@@ -167,7 +168,7 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
167
168
|
)
|
|
168
169
|
) {
|
|
169
170
|
const pathParts = transformedUrlObj.pathname.split('/');
|
|
170
|
-
pathParts[1] = atts.stage;
|
|
171
|
+
pathParts[1] = String(atts.stage);
|
|
171
172
|
transformedUrlObj.pathname = pathParts.join('/');
|
|
172
173
|
transformedUrlObj.searchParams.set('key', atts.key);
|
|
173
174
|
return {
|
|
@@ -19,7 +19,7 @@ export default class GeoloniaMarker extends maplibregl.Marker {
|
|
|
19
19
|
markerElement.className = 'geolonia-default-marker';
|
|
20
20
|
markerElement.innerHTML = markerSVG;
|
|
21
21
|
|
|
22
|
-
// Following
|
|
22
|
+
// Following should follow the dimension of marker.svg 52:67.
|
|
23
23
|
markerElement.style.margin = '0';
|
|
24
24
|
markerElement.style.padding = '0';
|
|
25
25
|
markerElement.style.width = '26px';
|
package/src/lib/keyring.test.ts
CHANGED
|
@@ -82,3 +82,58 @@ describe('parse api key from dom', () => {
|
|
|
82
82
|
assert.deepEqual('dev', keyring.stage);
|
|
83
83
|
});
|
|
84
84
|
});
|
|
85
|
+
|
|
86
|
+
describe('isGeoloniaStyleCheck', () => {
|
|
87
|
+
const originalHref = 'https://base.example.com/parent/';
|
|
88
|
+
|
|
89
|
+
before(() => {
|
|
90
|
+
global.location = {
|
|
91
|
+
...global.location,
|
|
92
|
+
href: originalHref,
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
afterEach(() => {
|
|
97
|
+
// Reset location after each test
|
|
98
|
+
global.location = {
|
|
99
|
+
...global.location,
|
|
100
|
+
href: originalHref,
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('should return true for empty or null style (default)', () => {
|
|
105
|
+
assert.strictEqual(keyring.isGeoloniaStyleCheck(''), true);
|
|
106
|
+
assert.strictEqual(keyring.isGeoloniaStyleCheck(null), true);
|
|
107
|
+
assert.strictEqual(keyring.isGeoloniaStyleCheck(undefined), true);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('should return true for Geolonia logical names', () => {
|
|
111
|
+
assert.strictEqual(keyring.isGeoloniaStyleCheck('geolonia/basic'), true);
|
|
112
|
+
assert.strictEqual(keyring.isGeoloniaStyleCheck('geolonia/basic-v2'), true);
|
|
113
|
+
assert.strictEqual(keyring.isGeoloniaStyleCheck('geolonia/gsi'), true);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('should return true for Geolonia CDN URLs', () => {
|
|
117
|
+
assert.strictEqual(keyring.isGeoloniaStyleCheck('https://cdn.geolonia.com/style/geolonia/basic/ja.json'), true);
|
|
118
|
+
assert.strictEqual(keyring.isGeoloniaStyleCheck('https://api.geolonia.com/v1/styles/basic.json'), true);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('should return false for external HTTPS URLs', () => {
|
|
122
|
+
assert.strictEqual(keyring.isGeoloniaStyleCheck('https://tile.openstreetmap.jp/styles/osm-bright/style.json'), false);
|
|
123
|
+
assert.strictEqual(keyring.isGeoloniaStyleCheck('https://example.com/style.json'), false);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('should return false for relative paths to external .json files', () => {
|
|
127
|
+
assert.strictEqual(keyring.isGeoloniaStyleCheck('./my-style.json'), false);
|
|
128
|
+
assert.strictEqual(keyring.isGeoloniaStyleCheck('/styles/custom.json'), false);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('should return true for relative paths to geolonia.com', () => {
|
|
132
|
+
// Simulate being on geolonia.com
|
|
133
|
+
global.location = {
|
|
134
|
+
...global.location,
|
|
135
|
+
href: 'https://cdn.geolonia.com/demo.html',
|
|
136
|
+
};
|
|
137
|
+
assert.strictEqual(keyring.isGeoloniaStyleCheck('./style.json'), true);
|
|
138
|
+
});
|
|
139
|
+
});
|
package/src/lib/keyring.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
class Keyring {
|
|
2
2
|
#apiKey: string;
|
|
3
3
|
#stage: string;
|
|
4
|
+
#isGeoloniaStyle: boolean;
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* @returns API key
|
|
@@ -11,6 +12,18 @@ class Keyring {
|
|
|
11
12
|
}
|
|
12
13
|
return this.#apiKey;
|
|
13
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* @returns Whether using Geolonia style (true) or external style (false)
|
|
17
|
+
*/
|
|
18
|
+
get isGeoloniaStyle() {
|
|
19
|
+
return this.#isGeoloniaStyle;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @param isGeoloniaStyle - Set whether using Geolonia style
|
|
23
|
+
*/
|
|
24
|
+
set isGeoloniaStyle(value: boolean) {
|
|
25
|
+
this.#isGeoloniaStyle = value;
|
|
26
|
+
}
|
|
14
27
|
/**
|
|
15
28
|
* @param key - API Key to set
|
|
16
29
|
*/
|
|
@@ -67,7 +80,7 @@ class Keyring {
|
|
|
67
80
|
this.#stage = 'dev';
|
|
68
81
|
}
|
|
69
82
|
|
|
70
|
-
if (!this.#apiKey) {
|
|
83
|
+
if (this.#isGeoloniaStyle && !this.#apiKey) {
|
|
71
84
|
throw new Error('Cannot load API key.');
|
|
72
85
|
}
|
|
73
86
|
}
|
|
@@ -76,6 +89,45 @@ class Keyring {
|
|
|
76
89
|
public reset() {
|
|
77
90
|
this.#apiKey = undefined;
|
|
78
91
|
this.#stage = undefined;
|
|
92
|
+
this.#isGeoloniaStyle = false;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Check if the given style is a Geolonia style (requires API key)
|
|
97
|
+
* Note: This is a method, not the property. Use keyring.isGeoloniaStyle property
|
|
98
|
+
* to check the current style type, or call this method to check a specific style.
|
|
99
|
+
* @param style - Style name or URL
|
|
100
|
+
* @returns true if it's a Geolonia style (requires API key)
|
|
101
|
+
*/
|
|
102
|
+
public isGeoloniaStyleCheck(style: string): boolean {
|
|
103
|
+
if (!style || style === '') {
|
|
104
|
+
// Default style is Geolonia
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Check if it's a Geolonia CDN or API URL
|
|
109
|
+
if (style.startsWith('https://cdn.geolonia.com/style/') ||
|
|
110
|
+
style.startsWith('https://api.geolonia.com/')) {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// If it's a full URL (http:// or https://), it's external
|
|
115
|
+
if (style.match(/^https?:\/\//)) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// If it ends with .json and doesn't contain geolonia.com, it's likely external
|
|
120
|
+
if (style.endsWith('.json')) {
|
|
121
|
+
try {
|
|
122
|
+
const absoluteUrl = new URL(style, location.href).href;
|
|
123
|
+
return absoluteUrl.includes('geolonia.com');
|
|
124
|
+
} catch {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Otherwise, it's a Geolonia logical name like "geolonia/basic"
|
|
130
|
+
return true;
|
|
79
131
|
}
|
|
80
132
|
}
|
|
81
133
|
|
package/src/lib/parse-atts.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { keyring } from './keyring';
|
|
4
4
|
import { getLang } from './util';
|
|
5
|
-
import type { EmbedAttributes } from '../
|
|
5
|
+
import type { EmbedAttributes } from '../types';
|
|
6
6
|
|
|
7
7
|
type ParseAttsParams = {
|
|
8
8
|
interactive?: boolean;
|
|
@@ -26,6 +26,10 @@ export default (container, params: ParseAttsParams = {}): EmbedAttributes => {
|
|
|
26
26
|
|
|
27
27
|
keyring.parse(container);
|
|
28
28
|
|
|
29
|
+
// Check if using Geolonia style or external style
|
|
30
|
+
const style = container.dataset.style || 'geolonia/basic-v2';
|
|
31
|
+
keyring.isGeoloniaStyle = keyring.isGeoloniaStyleCheck(style);
|
|
32
|
+
|
|
29
33
|
return {
|
|
30
34
|
lat: 0,
|
|
31
35
|
lng: 0,
|
package/src/lib/render.ts
CHANGED
|
@@ -87,7 +87,7 @@ export const renderGeoloniaMap = () => {
|
|
|
87
87
|
);
|
|
88
88
|
|
|
89
89
|
// This is required for correct initialization! Don't delete!
|
|
90
|
-
if (!keyring.apiKey) {
|
|
90
|
+
if (keyring.isGeoloniaStyle && !keyring.apiKey) {
|
|
91
91
|
console.error('[Geolonia] Missing API key.'); // eslint-disable-line
|
|
92
92
|
}
|
|
93
93
|
|