@geolonia/embed 4.3.0 → 5.0.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/.eslintrc.js +3 -0
- package/.github/workflows/build.yml +89 -28
- 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/416af3373e37004e65f4.js +1 -0
- package/dist/embed-chunks/488aacb380a87ea633f6.js +2 -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/{lib → src/lib}/geolonia-map.d.ts +10 -1
- package/dist/{lib → src/lib}/maplibre-util.d.ts +1 -3
- package/dist/{lib → src/lib}/util.d.ts +5 -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/package.json +8 -4
- package/playwright.config.ts +79 -0
- package/src/embed.ts +1 -1
- package/src/lib/geolonia-map.ts +23 -4
- package/src/lib/parse-atts.test.ts +2 -0
- package/src/lib/simplestyle.ts +7 -10
- package/src/lib/util.test.ts +40 -2
- package/src/lib/util.ts +29 -2
- package/src/testability.test.ts +43 -0
- package/tsconfig.json +3 -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 → 488aacb380a87ea633f6.js.LICENSE.txt} +0 -0
- /package/dist/{embed.d.ts → src/embed.d.ts} +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}/geolonia-marker.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
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read environment variables from file.
|
|
3
|
+
* https://github.com/motdotla/dotenv
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* See https://playwright.dev/docs/test-configuration.
|
|
7
|
+
*/
|
|
8
|
+
declare const _default: import("@playwright/test").PlaywrightTestConfig<{}, {}>;
|
|
9
|
+
export default _default;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import maplibregl from 'maplibre-gl';
|
|
2
|
-
import
|
|
2
|
+
import { GetImageCallback } from './util';
|
|
3
|
+
import type { MapOptions, StyleOptions, StyleSpecification, StyleSwapOptions, GetResourceResponse } from 'maplibre-gl';
|
|
3
4
|
export type GeoloniaMapOptions = MapOptions & {
|
|
4
5
|
interactive?: boolean;
|
|
5
6
|
};
|
|
@@ -19,4 +20,12 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
19
20
|
*/
|
|
20
21
|
setStyle(style: string | StyleSpecification, options?: StyleSwapOptions & StyleOptions): this;
|
|
21
22
|
remove(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Backward compatibility for breaking change of loadImage() in MapLibre GL JS v4.0.0.
|
|
25
|
+
* Related to https://github.com/maplibre/maplibre-gl-js/pull/3422/
|
|
26
|
+
* @param url
|
|
27
|
+
* @param callback
|
|
28
|
+
*/
|
|
29
|
+
loadImage(url: string, callback: GetImageCallback): void;
|
|
30
|
+
loadImage(url: string): Promise<GetResourceResponse<HTMLImageElement | ImageBitmap>>;
|
|
22
31
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/// <reference types="mapbox__point-geometry" />
|
|
2
|
-
import Point from '@mapbox/point-geometry';
|
|
3
1
|
/**
|
|
4
2
|
* This class is a copy of maplibre-gl-js's util DOM class and rewrite it to JavaScript.
|
|
5
3
|
* https://github.com/maplibre/maplibre-gl-js/blob/main/src/util/dom.ts
|
|
@@ -15,7 +13,7 @@ export declare class DOM {
|
|
|
15
13
|
static addEventListener(target: any, type: any, callback: any, options: any): void;
|
|
16
14
|
static removeEventListener(target: any, type: any, callback: any, options: any): void;
|
|
17
15
|
static suppressClick(): void;
|
|
18
|
-
static mousePos(el: any, e: any):
|
|
16
|
+
static mousePos(el: any, e: any): any;
|
|
19
17
|
static touchPos(el: any, touches: any): any[];
|
|
20
18
|
static mouseButton(e: any): any;
|
|
21
19
|
static remove(node: any): void;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { MapOptions, MarkerOptions } from 'maplibre-gl';
|
|
1
|
+
import type { GetResourceResponse, MapOptions, MarkerOptions, ExpiryData } from 'maplibre-gl';
|
|
2
|
+
export type GetImageCallback = (error?: Error | null, image?: HTMLImageElement | ImageBitmap | null, expiry?: ExpiryData | null) => void;
|
|
2
3
|
/**
|
|
3
4
|
*
|
|
4
5
|
* @param {string} str target URL string
|
|
5
6
|
* @return {string|false} Resolved URL or false if not resolved
|
|
6
7
|
*/
|
|
7
|
-
export declare function isURL(str:
|
|
8
|
+
export declare function isURL(str: string): string | false;
|
|
8
9
|
export declare function checkPermission(): boolean;
|
|
9
10
|
export declare function getLang(): "ja" | "en";
|
|
10
11
|
/**
|
|
@@ -34,7 +35,7 @@ export declare function getContainer(arg: HTMLElement | string | {
|
|
|
34
35
|
* @param {*} legacyOptions
|
|
35
36
|
*/
|
|
36
37
|
export declare function handleMarkerOptions(options: MarkerOptions | null | undefined | false, legacyOptions: MarkerOptions): MarkerOptions;
|
|
37
|
-
export declare function getStyle(style: any, atts: any):
|
|
38
|
+
export declare function getStyle(style: any, atts: any): string;
|
|
38
39
|
export declare function getOptions(container: any, params: any, atts: any): MapOptions;
|
|
39
40
|
/**
|
|
40
41
|
*
|
|
@@ -56,3 +57,4 @@ export declare const handleRestrictedMode: (map: any) => void;
|
|
|
56
57
|
export declare const handleErrorMode: (container: any) => void;
|
|
57
58
|
export declare const sanitizeDescription: (description: any) => Promise<any>;
|
|
58
59
|
export declare const random: (max: number) => number;
|
|
60
|
+
export declare function loadImageCompatibility(promise: Promise<GetResourceResponse<HTMLImageElement | ImageBitmap>>, callback: GetImageCallback): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const VERSION = "5.0.0";
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { test, expect } from '@playwright/test';
|
|
2
|
+
import { Geolonia } from '../src/embed';
|
|
3
|
+
import { TEST_URL, waitForMapLoad } from './helper';
|
|
4
|
+
|
|
5
|
+
declare global {
|
|
6
|
+
interface Window {
|
|
7
|
+
geolonia: Geolonia,
|
|
8
|
+
maplibregl?: Geolonia,
|
|
9
|
+
mapboxgl?: Geolonia,
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
test.describe('1. 基本的な地図表示', () => {
|
|
14
|
+
test.beforeEach(async ({ page }) => {
|
|
15
|
+
await page.goto(`${TEST_URL}/basic.html`);
|
|
16
|
+
await waitForMapLoad(page);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('1.1 ページ読み込み時に地図が表示されること', async ({ page }) => {
|
|
20
|
+
await page.goto(`${TEST_URL}/basic.html`);
|
|
21
|
+
await waitForMapLoad(page);
|
|
22
|
+
const mapContainer = page.locator('.geolonia');
|
|
23
|
+
await expect(mapContainer).toBeVisible();
|
|
24
|
+
const canvas = page.locator('.geolonia canvas');
|
|
25
|
+
await expect(canvas).toBeVisible();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('1.2 デフォルトで原点に地図が表示されること', async ({ page }) => {
|
|
29
|
+
await page.goto(`${TEST_URL}/basic.html`);
|
|
30
|
+
await waitForMapLoad(page);
|
|
31
|
+
const center = await page.evaluate(() => {
|
|
32
|
+
const map = new window.geolonia.Map('map');
|
|
33
|
+
return map.getCenter();
|
|
34
|
+
});
|
|
35
|
+
// 日本のおおよその中心座標
|
|
36
|
+
expect(center.lat).toBeCloseTo(0.0, 0);
|
|
37
|
+
expect(center.lng).toBeCloseTo(0.0, 0);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('1.3 コンソールエラーが発生していないこと', async ({ page }) => {
|
|
41
|
+
const consoleErrors: string[] = [];
|
|
42
|
+
page.on('console', (msg) => {
|
|
43
|
+
if (msg.type() === 'error') {
|
|
44
|
+
consoleErrors.push(msg.text());
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
await page.goto(`${TEST_URL}/basic.html`);
|
|
48
|
+
await waitForMapLoad(page);
|
|
49
|
+
expect(consoleErrors).toHaveLength(0);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
package/e2e/helper.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Page } from '@playwright/test';
|
|
2
|
+
// テスト用の設定
|
|
3
|
+
export const TEST_URL = 'http://localhost:3000/e2e';
|
|
4
|
+
export const LOAD_TIMEOUT = 5000;
|
|
5
|
+
|
|
6
|
+
// ヘルパー関数
|
|
7
|
+
export async function waitForMapLoad(page: Page, selector = '.geolonia') {
|
|
8
|
+
// 地図コンテナの存在を確認
|
|
9
|
+
await page.waitForSelector(selector);
|
|
10
|
+
// Maplibreのcanvasが表示されるまで待機
|
|
11
|
+
await page.waitForSelector(`${selector} canvas`, { timeout: LOAD_TIMEOUT });
|
|
12
|
+
}
|
package/e2e/map.spec.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { test, expect } from '@playwright/test';
|
|
2
|
+
import { TEST_URL, LOAD_TIMEOUT, waitForMapLoad } from './helper';
|
|
3
|
+
|
|
4
|
+
test.describe('1. 基本的な地図表示', () => {
|
|
5
|
+
test.beforeEach(async ({ page }) => {
|
|
6
|
+
await page.goto(`${TEST_URL}/nocontrol.html`);
|
|
7
|
+
await waitForMapLoad(page);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test.describe.serial('2.1 地図が表示できること', () => {
|
|
11
|
+
test('2.1.1 ページ読み込み時に地図がロードされること', async ({ page }) => {
|
|
12
|
+
// MapLibre GLのmapインスタンスがロードされるまで待つ
|
|
13
|
+
try {
|
|
14
|
+
await page.waitForFunction(() => {
|
|
15
|
+
const map = new window.geolonia.Map('map');
|
|
16
|
+
// 地図が完全に読み込まれたかどうか
|
|
17
|
+
return map && map.loaded();
|
|
18
|
+
}, { timeout: LOAD_TIMEOUT });
|
|
19
|
+
// 成功
|
|
20
|
+
} catch (e) {
|
|
21
|
+
// タイムアウト
|
|
22
|
+
expect(false).toBe(true); // テスト失敗
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
test('2.1.2 タイルが描画されていることを確認(上半分のみ)', async ({ page }) => {
|
|
26
|
+
const isNotBlank = await page.evaluate(() => {
|
|
27
|
+
const canvas = document.querySelector('.maplibregl-canvas') as HTMLCanvasElement;
|
|
28
|
+
// WebGLコンテキストを取得
|
|
29
|
+
const gl = canvas.getContext('webgl2') || canvas.getContext('webgl');
|
|
30
|
+
|
|
31
|
+
if (!gl) {
|
|
32
|
+
return false; // WebGLコンテキストが取得できない場合
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const width = canvas.width;
|
|
36
|
+
const height = Math.floor(canvas.height / 2); // 上半分のみ
|
|
37
|
+
// ピクセルデータを読み取る
|
|
38
|
+
const pixels = new Uint8Array(width * height * 4);
|
|
39
|
+
|
|
40
|
+
// 下にAttributeがある場合、真っ白ではないため上半分だけを取得
|
|
41
|
+
// WebGLは下から上に向かって読み取るので、上半分を取得するには
|
|
42
|
+
// 下半分をスキップする必要がある
|
|
43
|
+
gl.readPixels(0, Math.floor(canvas.height / 2), width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
|
|
44
|
+
// 色の分析
|
|
45
|
+
let nonWhiteCount = 0;
|
|
46
|
+
const totalPixels = pixels.length / 4;
|
|
47
|
+
|
|
48
|
+
for (let i = 0; i < pixels.length; i += 4) {
|
|
49
|
+
const r = pixels[i];
|
|
50
|
+
const g = pixels[i + 1];
|
|
51
|
+
const b = pixels[i + 2];
|
|
52
|
+
|
|
53
|
+
// 白以外のピクセルをカウント
|
|
54
|
+
if (r < 250 || g < 250 || b < 250) {
|
|
55
|
+
nonWhiteCount++;
|
|
56
|
+
|
|
57
|
+
// 早期終了:十分な非白色ピクセルが見つかったら
|
|
58
|
+
if (nonWhiteCount > totalPixels * 0.01) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return nonWhiteCount > 0;
|
|
65
|
+
});
|
|
66
|
+
expect(isNotBlank).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geolonia/embed",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Geolonia embed JS API",
|
|
5
5
|
"main": "dist/embed.js",
|
|
6
6
|
"types": "dist/embed.d.ts",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"analyze": "ANALYZE=true webpack --mode production",
|
|
15
15
|
"format": "prettier-eslint \"./src/**/*.ts\" --write",
|
|
16
16
|
"lint": "eslint --ext .js,.cjs,.mjs,.jsx,.ts,.tsx .",
|
|
17
|
-
"test": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha"
|
|
17
|
+
"test": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha",
|
|
18
|
+
"e2e": "playwright test"
|
|
18
19
|
},
|
|
19
20
|
"author": "Geolonia (https://geolonia.com)",
|
|
20
21
|
"repository": {
|
|
@@ -28,7 +29,9 @@
|
|
|
28
29
|
"homepage": "https://github.com/geolonia/embed#readme",
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"@geolonia/eslint-config": "latest",
|
|
32
|
+
"@types/jsdom": "^21.1.7",
|
|
31
33
|
"@types/mocha": "^10.0.1",
|
|
34
|
+
"@types/node": "^24.0.4",
|
|
32
35
|
"babel-loader": "^9.1.0",
|
|
33
36
|
"css-loader": "^6.7.2",
|
|
34
37
|
"eslint": "^8.29.0",
|
|
@@ -52,9 +55,10 @@
|
|
|
52
55
|
"@geolonia/mbgl-gesture-handling": "^1.0.15",
|
|
53
56
|
"@mapbox/geojson-extent": "^1.0.0",
|
|
54
57
|
"@mapbox/point-geometry": "^0.1.0",
|
|
58
|
+
"@playwright/test": "^1.53.1",
|
|
55
59
|
"@turf/center": "^6.0.1",
|
|
56
|
-
"maplibre-gl": "
|
|
57
|
-
"pmtiles": "
|
|
60
|
+
"maplibre-gl": "5.7.0",
|
|
61
|
+
"pmtiles": "^3.0.6",
|
|
58
62
|
"sanitize-html": "^2.8.0",
|
|
59
63
|
"tinycolor2": "^1.4.1"
|
|
60
64
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { defineConfig, devices } from '@playwright/test';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Read environment variables from file.
|
|
5
|
+
* https://github.com/motdotla/dotenv
|
|
6
|
+
*/
|
|
7
|
+
// import dotenv from 'dotenv';
|
|
8
|
+
// import path from 'path';
|
|
9
|
+
// dotenv.config({ path: path.resolve(__dirname, '.env') });
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* See https://playwright.dev/docs/test-configuration.
|
|
13
|
+
*/
|
|
14
|
+
export default defineConfig({
|
|
15
|
+
testDir: './e2e',
|
|
16
|
+
/* Run tests in files in parallel */
|
|
17
|
+
fullyParallel: true,
|
|
18
|
+
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
|
19
|
+
forbidOnly: !!process.env.CI,
|
|
20
|
+
/* Retry on CI only */
|
|
21
|
+
retries: process.env.CI ? 2 : 0,
|
|
22
|
+
/* Opt out of parallel tests on CI. */
|
|
23
|
+
workers: process.env.CI ? 1 : undefined,
|
|
24
|
+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
|
25
|
+
reporter: 'html',
|
|
26
|
+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
|
27
|
+
use: {
|
|
28
|
+
/* Base URL to use in actions like `await page.goto('/')`. */
|
|
29
|
+
// baseURL: 'http://localhost:3000',
|
|
30
|
+
|
|
31
|
+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
|
32
|
+
trace: 'on-first-retry',
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
/* Configure projects for major browsers */
|
|
36
|
+
projects: [
|
|
37
|
+
{
|
|
38
|
+
name: 'chromium',
|
|
39
|
+
use: { ...devices['Desktop Chrome'] },
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
{
|
|
43
|
+
name: 'firefox',
|
|
44
|
+
use: { ...devices['Desktop Firefox'] },
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
{
|
|
48
|
+
name: 'webkit',
|
|
49
|
+
use: { ...devices['Desktop Safari'] },
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
/* Test against mobile viewports. */
|
|
53
|
+
// {
|
|
54
|
+
// name: 'Mobile Chrome',
|
|
55
|
+
// use: { ...devices['Pixel 5'] },
|
|
56
|
+
// },
|
|
57
|
+
// {
|
|
58
|
+
// name: 'Mobile Safari',
|
|
59
|
+
// use: { ...devices['iPhone 12'] },
|
|
60
|
+
// },
|
|
61
|
+
|
|
62
|
+
/* Test against branded browsers. */
|
|
63
|
+
// {
|
|
64
|
+
// name: 'Microsoft Edge',
|
|
65
|
+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
|
|
66
|
+
// },
|
|
67
|
+
// {
|
|
68
|
+
// name: 'Google Chrome',
|
|
69
|
+
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
|
|
70
|
+
// },
|
|
71
|
+
],
|
|
72
|
+
|
|
73
|
+
/* Run your local dev server before starting the tests */
|
|
74
|
+
webServer: {
|
|
75
|
+
command: 'npm run start',
|
|
76
|
+
url: 'http://localhost:3000',
|
|
77
|
+
reuseExistingServer: !process.env.CI,
|
|
78
|
+
},
|
|
79
|
+
});
|
package/src/embed.ts
CHANGED
package/src/lib/geolonia-map.ts
CHANGED
|
@@ -8,9 +8,9 @@ import parseAtts from './parse-atts';
|
|
|
8
8
|
import { SimpleStyle } from './simplestyle';
|
|
9
9
|
import SimpleStyleVector from './simplestyle-vector';
|
|
10
10
|
|
|
11
|
-
import { getContainer, getOptions, getSessionId, getStyle, handleRestrictedMode, isScrollable, parseControlOption, parseSimpleVector, handleErrorMode } from './util';
|
|
11
|
+
import { getContainer, getOptions, getSessionId, getStyle, handleRestrictedMode, isScrollable, parseControlOption, parseSimpleVector, handleErrorMode, loadImageCompatibility, GetImageCallback } from './util';
|
|
12
12
|
|
|
13
|
-
import type { MapOptions, PointLike, StyleOptions, StyleSpecification, StyleSwapOptions } from 'maplibre-gl';
|
|
13
|
+
import type { MapOptions, PointLike, StyleOptions, StyleSpecification, StyleSwapOptions, GetResourceResponse } from 'maplibre-gl';
|
|
14
14
|
|
|
15
15
|
export type GeoloniaMapOptions = MapOptions & { interactive?: boolean };
|
|
16
16
|
|
|
@@ -113,8 +113,8 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
113
113
|
const transformedUrlObj = new URL(transformedUrl);
|
|
114
114
|
|
|
115
115
|
if (resourceType === 'Source' && transformedUrl.startsWith('https://tileserver.geolonia.com')) {
|
|
116
|
-
if (atts.stage
|
|
117
|
-
transformedUrlObj.hostname =
|
|
116
|
+
if (atts.stage === 'dev') {
|
|
117
|
+
transformedUrlObj.hostname = 'tileserver-dev.geolonia.com';
|
|
118
118
|
}
|
|
119
119
|
transformedUrlObj.searchParams.set('sessionId', sessionId);
|
|
120
120
|
transformedUrlObj.searchParams.set('key', atts.key);
|
|
@@ -319,4 +319,23 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
319
319
|
super.remove.call(this);
|
|
320
320
|
delete (container as HTMLElement & { geoloniaMap: GeoloniaMap }).geoloniaMap;
|
|
321
321
|
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Backward compatibility for breaking change of loadImage() in MapLibre GL JS v4.0.0.
|
|
325
|
+
* Related to https://github.com/maplibre/maplibre-gl-js/pull/3422/
|
|
326
|
+
* @param url
|
|
327
|
+
* @param callback
|
|
328
|
+
*/
|
|
329
|
+
loadImage(url: string, callback: GetImageCallback): void;
|
|
330
|
+
loadImage(url: string): Promise<GetResourceResponse<HTMLImageElement | ImageBitmap>>;
|
|
331
|
+
loadImage(url: string, callback?: GetImageCallback): Promise<GetResourceResponse<HTMLImageElement | ImageBitmap>> | void {
|
|
332
|
+
|
|
333
|
+
const promise = super.loadImage(url);
|
|
334
|
+
|
|
335
|
+
if (callback) {
|
|
336
|
+
loadImageCompatibility(promise, callback);
|
|
337
|
+
} else {
|
|
338
|
+
return promise;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
322
341
|
}
|
package/src/lib/simplestyle.ts
CHANGED
|
@@ -297,17 +297,14 @@ export class SimpleStyle {
|
|
|
297
297
|
},
|
|
298
298
|
});
|
|
299
299
|
|
|
300
|
-
this.map.on('click', `${this.options.id}-clusters`, (e) => {
|
|
300
|
+
this.map.on('click', `${this.options.id}-clusters`, async (e) => {
|
|
301
301
|
const features = this.map.queryRenderedFeatures(e.point, { layers: [`${this.options.id}-clusters`] });
|
|
302
302
|
const clusterId = features[0].properties.cluster_id;
|
|
303
|
-
this.map.getSource(`${this.options.id}-points`).getClusterExpansionZoom(clusterId
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
center: features[0].geometry.coordinates,
|
|
309
|
-
zoom: zoom,
|
|
310
|
-
});
|
|
303
|
+
const zoom = await this.map.getSource(`${this.options.id}-points`).getClusterExpansionZoom(clusterId);
|
|
304
|
+
|
|
305
|
+
this.map.easeTo({
|
|
306
|
+
center: features[0].geometry.coordinates,
|
|
307
|
+
zoom: zoom,
|
|
311
308
|
});
|
|
312
309
|
});
|
|
313
310
|
|
|
@@ -331,7 +328,7 @@ export class SimpleStyle {
|
|
|
331
328
|
try {
|
|
332
329
|
|
|
333
330
|
const response = await window.fetch(geojson);
|
|
334
|
-
const data = await response.json();
|
|
331
|
+
const data = response.ok ? await response.json() : {};
|
|
335
332
|
this.geojson = data;
|
|
336
333
|
this.updateData(data);
|
|
337
334
|
|
package/src/lib/util.test.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
2
|
|
|
3
3
|
import assert from 'assert';
|
|
4
4
|
import { JSDOM } from 'jsdom';
|
|
5
|
-
import { getContainer, getLang, getOptions, getStyle, handleMarkerOptions, isDomElement, isURL, parseControlOption, parseSimpleVector, sanitizeDescription } from './util';
|
|
5
|
+
import { getContainer, getLang, getOptions, getStyle, handleMarkerOptions, isDomElement, isURL, parseControlOption, parseSimpleVector, sanitizeDescription, loadImageCompatibility } from './util';
|
|
6
6
|
|
|
7
7
|
const base = 'https://base.example.com/parent/';
|
|
8
8
|
|
|
@@ -62,6 +62,7 @@ describe('Tests for util.js', () => {
|
|
|
62
62
|
<div id="test-element"></div>
|
|
63
63
|
</body></html>`);
|
|
64
64
|
|
|
65
|
+
// @ts-ignore
|
|
65
66
|
global.window = dom.window;
|
|
66
67
|
global.document = dom.window.document;
|
|
67
68
|
|
|
@@ -89,6 +90,7 @@ describe('Tests for util.js', () => {
|
|
|
89
90
|
<div id="test-element"></div>
|
|
90
91
|
</body></html>`);
|
|
91
92
|
|
|
93
|
+
// @ts-ignore
|
|
92
94
|
global.window = dom.window;
|
|
93
95
|
global.document = dom.window.document;
|
|
94
96
|
|
|
@@ -235,3 +237,39 @@ describe('Tests for util.js', () => {
|
|
|
235
237
|
});
|
|
236
238
|
});
|
|
237
239
|
});
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
describe('loadImageCompatibility', () => {
|
|
243
|
+
it('should call the callback with response data when the promise resolves', (done) => {
|
|
244
|
+
// モックされた成功した promise
|
|
245
|
+
const mockResponse = {
|
|
246
|
+
data: new Image(),
|
|
247
|
+
cacheControl: 'public, max-age=3600',
|
|
248
|
+
expires: '1609459200',
|
|
249
|
+
};
|
|
250
|
+
const promise = Promise.resolve(mockResponse);
|
|
251
|
+
|
|
252
|
+
loadImageCompatibility(promise, (error, data, expiry) => {
|
|
253
|
+
assert.equal(error, null);
|
|
254
|
+
assert.deepEqual(data, mockResponse.data);
|
|
255
|
+
assert.deepEqual(expiry, {
|
|
256
|
+
cacheControl: mockResponse.cacheControl,
|
|
257
|
+
expires: mockResponse.expires,
|
|
258
|
+
});
|
|
259
|
+
done();
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it('should call the callback with error when the promise rejects', (done) => {
|
|
264
|
+
// モックされた失敗した promise
|
|
265
|
+
const mockError = new Error('Failed to load image');
|
|
266
|
+
const promise = Promise.reject(mockError);
|
|
267
|
+
|
|
268
|
+
loadImageCompatibility(promise, (error, data, expiry) => {
|
|
269
|
+
assert.deepEqual(error, mockError);
|
|
270
|
+
assert.strictEqual(data, undefined);
|
|
271
|
+
assert.strictEqual(expiry, undefined);
|
|
272
|
+
done();
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
});
|
package/src/lib/util.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
import { keyring } from './keyring';
|
|
4
|
-
import type { MapOptions, MarkerOptions } from 'maplibre-gl';
|
|
4
|
+
import type { GetResourceResponse, MapOptions, MarkerOptions, ExpiryData } from 'maplibre-gl';
|
|
5
|
+
|
|
6
|
+
// GetImageCallback extracted from maplibre-gl v3.6.2 ( https://github.com/maplibre/maplibre-gl-js/releases/tag/v3.6.2 )
|
|
7
|
+
export type GetImageCallback = (error?: Error | null, image?: HTMLImageElement | ImageBitmap | null, expiry?: ExpiryData | null) => void;
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
*
|
|
8
11
|
* @param {string} str target URL string
|
|
9
12
|
* @return {string|false} Resolved URL or false if not resolved
|
|
10
13
|
*/
|
|
11
|
-
export function isURL(str) {
|
|
14
|
+
export function isURL(str: string): string | false {
|
|
12
15
|
if (str.match(/^https?:\/\//)) {
|
|
13
16
|
return str;
|
|
14
17
|
} else if (str.match(/^\//) || str.match(/^\.\.?/)) {
|
|
@@ -300,3 +303,27 @@ export const sanitizeDescription = async (description) => {
|
|
|
300
303
|
|
|
301
304
|
export const random = (max: number): number => Math.floor(Math.random() * max);
|
|
302
305
|
|
|
306
|
+
// This function is used to provide backward compatibility with callback invocations,
|
|
307
|
+
// so we ignore ESLint rules for this function.
|
|
308
|
+
// Note: this cannot be a generic promiseToCallback function because the callback is not
|
|
309
|
+
// the traditional (error, result) style callback.
|
|
310
|
+
export function loadImageCompatibility(
|
|
311
|
+
promise: Promise<GetResourceResponse<HTMLImageElement | ImageBitmap>>,
|
|
312
|
+
callback: GetImageCallback,
|
|
313
|
+
): void {
|
|
314
|
+
promise
|
|
315
|
+
// eslint-disable-next-line promise/prefer-await-to-then
|
|
316
|
+
.then((response) => {
|
|
317
|
+
// eslint-disable-next-line promise/no-callback-in-promise
|
|
318
|
+
callback(null, response.data, {
|
|
319
|
+
cacheControl: response.cacheControl,
|
|
320
|
+
expires: response.expires,
|
|
321
|
+
});
|
|
322
|
+
return;
|
|
323
|
+
})
|
|
324
|
+
// eslint-disable-next-line promise/prefer-await-to-then
|
|
325
|
+
.catch((error) => {
|
|
326
|
+
// eslint-disable-next-line promise/no-callback-in-promise
|
|
327
|
+
callback(error);
|
|
328
|
+
});
|
|
329
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { JSDOM } from 'jsdom';
|
|
2
|
+
import assert from 'assert';
|
|
3
|
+
import maplibregl from 'maplibre-gl';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* このテストは、jsdom環境ではmaplibre-glのMapインスタンスが
|
|
7
|
+
* WebGL不足のため生成できないことを「動作証跡付き」でドキュメント化するものです。
|
|
8
|
+
* 実際の描画テストはE2Eテストで行ってください。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
describe('maplibre-gl jsdom limitation', () => {
|
|
12
|
+
it('jsdom上ではMaplibre Mapインスタンス生成時にエラー(WebGL未対応のため)', () => {
|
|
13
|
+
const dom = new JSDOM('<!DOCTYPE html><html><body><div id="map"></div></body></html>', {
|
|
14
|
+
url: 'http://localhost',
|
|
15
|
+
pretendToBeVisual: true, // jsdomを視覚的な環境として
|
|
16
|
+
});
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
global.window = dom.window;
|
|
19
|
+
global.document = dom.window.document;
|
|
20
|
+
let errorCaught = null;
|
|
21
|
+
try {
|
|
22
|
+
new maplibregl.Map({
|
|
23
|
+
container: 'map',
|
|
24
|
+
style: 'https://demotiles.maplibre.org/style.json',
|
|
25
|
+
center: [139.767, 35.681],
|
|
26
|
+
zoom: 10,
|
|
27
|
+
});
|
|
28
|
+
} catch (err) {
|
|
29
|
+
errorCaught = err;
|
|
30
|
+
}
|
|
31
|
+
assert(errorCaught instanceof Error);
|
|
32
|
+
// 期待される理由: WebGLが利用できない旨のエラーメッセージ
|
|
33
|
+
assert(
|
|
34
|
+
/webgl|WebGL|context|device/i.test(errorCaught.message),
|
|
35
|
+
`Error message should mention WebGL or context, but got: ${errorCaught.message}`,
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('【NOTE】描画テストが必要な場合はE2E(ブラウザ実行)で行うこと', () => {
|
|
40
|
+
// このテストは常に成功。ドキュメント用途。
|
|
41
|
+
assert.strictEqual(true, true);
|
|
42
|
+
});
|
|
43
|
+
});
|