@geolonia/embed 4.2.2 → 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.
Files changed (50) hide show
  1. package/.eslintrc.js +3 -0
  2. package/.github/workflows/build.yml +89 -28
  3. package/dist/e2e/basic.spec.d.ts +8 -0
  4. package/dist/e2e/helper.d.ts +4 -0
  5. package/dist/embed +2 -1
  6. package/dist/embed-chunks/416af3373e37004e65f4.js +1 -0
  7. package/dist/embed-chunks/488aacb380a87ea633f6.js +2 -0
  8. package/dist/embed.js +2 -1
  9. package/dist/embed.js.LICENSE.txt +4 -0
  10. package/dist/playwright.config.d.ts +9 -0
  11. package/dist/{lib → src/lib}/geolonia-map.d.ts +10 -1
  12. package/dist/{lib → src/lib}/maplibre-util.d.ts +1 -3
  13. package/dist/{lib → src/lib}/util.d.ts +6 -3
  14. package/dist/src/lib/util.test.d.ts +1 -0
  15. package/dist/src/testability.test.d.ts +1 -0
  16. package/dist/src/version.d.ts +1 -0
  17. package/e2e/basic.spec.ts +52 -0
  18. package/e2e/helper.ts +12 -0
  19. package/e2e/map.spec.ts +69 -0
  20. package/package.json +8 -4
  21. package/playwright.config.ts +79 -0
  22. package/src/embed.ts +1 -1
  23. package/src/lib/geolonia-map.ts +35 -9
  24. package/src/lib/parse-atts.test.ts +2 -0
  25. package/src/lib/render.ts +12 -2
  26. package/src/lib/simplestyle-vector.ts +3 -3
  27. package/src/lib/simplestyle.ts +10 -20
  28. package/src/lib/util.test.ts +40 -2
  29. package/src/lib/util.ts +48 -2
  30. package/src/style.css +28 -0
  31. package/src/testability.test.ts +43 -0
  32. package/tsconfig.json +3 -1
  33. package/dist/embed-chunks/b52b89229e47dc93c64b.js +0 -2
  34. package/dist/embed-chunks/d0f087405f7ae2fcf1c1.js +0 -1
  35. package/dist/version.d.ts +0 -1
  36. /package/dist/{lib/keyring.test.d.ts → e2e/map.spec.d.ts} +0 -0
  37. /package/dist/embed-chunks/{b52b89229e47dc93c64b.js.LICENSE.txt → 488aacb380a87ea633f6.js.LICENSE.txt} +0 -0
  38. /package/dist/{embed.d.ts → src/embed.d.ts} +0 -0
  39. /package/dist/{lib → src/lib}/CustomAttributionControl.d.ts +0 -0
  40. /package/dist/{lib → src/lib}/controls/geolonia-control.d.ts +0 -0
  41. /package/dist/{lib → src/lib}/geolonia-marker.d.ts +0 -0
  42. /package/dist/{lib → src/lib}/keyring.d.ts +0 -0
  43. /package/dist/{lib/parse-atts.test.d.ts → src/lib/keyring.test.d.ts} +0 -0
  44. /package/dist/{lib → src/lib}/parse-atts.d.ts +0 -0
  45. /package/dist/{lib/simplestyle.test.d.ts → src/lib/parse-atts.test.d.ts} +0 -0
  46. /package/dist/{lib → src/lib}/render.d.ts +0 -0
  47. /package/dist/{lib → src/lib}/simplestyle-vector.d.ts +0 -0
  48. /package/dist/{lib → src/lib}/simplestyle.d.ts +0 -0
  49. /package/dist/{lib/util.test.d.ts → src/lib/simplestyle.test.d.ts} +0 -0
  50. /package/dist/{types-internal.d.ts → src/types-internal.d.ts} +0 -0
@@ -0,0 +1,4 @@
1
+ /**
2
+ * MapLibre GL JS
3
+ * @license 3-Clause BSD. Full text of license: https://github.com/maplibre/maplibre-gl-js/blob/v5.7.0/LICENSE.txt
4
+ */
@@ -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 type { MapOptions, StyleOptions, StyleSpecification, StyleSwapOptions } from 'maplibre-gl';
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): Point;
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: any): any;
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): 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
  *
@@ -53,5 +54,7 @@ export declare function parseControlOption(att: any): {
53
54
  export declare const getSessionId: (digit: any) => string;
54
55
  export declare const parseSimpleVector: (attributeValue: any) => any;
55
56
  export declare const handleRestrictedMode: (map: any) => void;
57
+ export declare const handleErrorMode: (container: any) => void;
56
58
  export declare const sanitizeDescription: (description: any) => Promise<any>;
57
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
+ }
@@ -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": "4.2.2",
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": "3.4.1",
57
- "pmtiles": "2.11.0",
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
@@ -77,7 +77,7 @@ const geolonia: Geolonia = Object.assign(window.geolonia || {}, maplibregl, {
77
77
  });
78
78
 
79
79
  window.geolonia =
80
- window.maplibregl =
80
+ (window.maplibregl as any) =
81
81
  window.mapboxgl = geolonia;
82
82
 
83
83
  renderGeoloniaMap();
@@ -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 } 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
 
@@ -46,10 +46,11 @@ export default class GeoloniaMap extends maplibregl.Map {
46
46
  private __styleExtensionLoadRequired: boolean;
47
47
 
48
48
  constructor(params: string | GeoloniaMapOptions) {
49
+
49
50
  const container = getContainer(params) as Container | false;
50
51
 
51
52
  if (!container) {
52
- if ( typeof params === 'string') {
53
+ if (typeof params === 'string') {
53
54
  throw new Error(`[Geolonia] No HTML elements found matching \`${params}\`. Please ensure the map container element exists.`);
54
55
  } else {
55
56
  throw new Error('[Geolonia] No HTML elements found. Please ensure the map container element exists.');
@@ -112,8 +113,8 @@ export default class GeoloniaMap extends maplibregl.Map {
112
113
  const transformedUrlObj = new URL(transformedUrl);
113
114
 
114
115
  if (resourceType === 'Source' && transformedUrl.startsWith('https://tileserver.geolonia.com')) {
115
- if (atts.stage !== 'v1') {
116
- transformedUrlObj.hostname = `tileserver-${atts.stage}.geolonia.com`;
116
+ if (atts.stage === 'dev') {
117
+ transformedUrlObj.hostname = 'tileserver-dev.geolonia.com';
117
118
  }
118
119
  transformedUrlObj.searchParams.set('sessionId', sessionId);
119
120
  transformedUrlObj.searchParams.set('key', atts.key);
@@ -142,8 +143,14 @@ export default class GeoloniaMap extends maplibregl.Map {
142
143
  return request;
143
144
  };
144
145
 
145
- // Generate Map
146
- super(options);
146
+ try {
147
+ // Generate Map
148
+ super(options);
149
+ } catch (error) {
150
+ handleErrorMode(container);
151
+ throw error;
152
+ }
153
+
147
154
  const map = this;
148
155
  this.geoloniaSourcesUrl = sourcesUrl;
149
156
  this.__styleExtensionLoadRequired = true;
@@ -151,7 +158,7 @@ export default class GeoloniaMap extends maplibregl.Map {
151
158
  // Note: GeoloniaControl should be placed before another controls.
152
159
  // Because this control should be "very" bottom-left(default) or the attributed position.
153
160
  const { position: geoloniaControlPosition } = parseControlOption(atts.geoloniaControl);
154
- map.addControl(new GeoloniaControl(), geoloniaControlPosition);
161
+ map.addControl(new GeoloniaControl(), geoloniaControlPosition);
155
162
 
156
163
  map.addControl(new CustomAttributionControl(), 'bottom-right');
157
164
 
@@ -172,7 +179,7 @@ export default class GeoloniaMap extends maplibregl.Map {
172
179
 
173
180
  const { enabled: scaleControlEnabled, position: scaleControlPosition } = parseControlOption(atts.scaleControl);
174
181
  if (scaleControlEnabled) {
175
- map.addControl(new ScaleControl({}), scaleControlPosition);
182
+ map.addControl(new ScaleControl({}), scaleControlPosition);
176
183
  }
177
184
 
178
185
  map.on('load', (event) => {
@@ -312,4 +319,23 @@ export default class GeoloniaMap extends maplibregl.Map {
312
319
  super.remove.call(this);
313
320
  delete (container as HTMLElement & { geoloniaMap: GeoloniaMap }).geoloniaMap;
314
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
+ }
315
341
  }
@@ -1,3 +1,5 @@
1
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
2
+
1
3
  import parseAtts from './parse-atts';
2
4
  import assert from 'assert';
3
5
  import { JSDOM } from 'jsdom';
package/src/lib/render.ts CHANGED
@@ -67,7 +67,12 @@ export const renderGeoloniaMap = () => {
67
67
  if (!item.isIntersecting) {
68
68
  return;
69
69
  }
70
- renderSingleMap(item.target);
70
+ try {
71
+ renderSingleMap(item.target);
72
+ } catch (e) {
73
+ // Not throw error because, following maps will not be rendered.
74
+ console.error('[Geolonia] Failed to initialize map', e); // eslint-disable-line
75
+ }
71
76
  observer.unobserve(item.target);
72
77
  });
73
78
  });
@@ -82,7 +87,12 @@ export const renderGeoloniaMap = () => {
82
87
 
83
88
  // render Map immediately
84
89
  for (let i = 0; i < containers.length; i++) {
85
- renderSingleMap(containers[i]);
90
+ try {
91
+ renderSingleMap(containers[i]);
92
+ } catch (e) {
93
+ // Not throw error because, following maps will not be rendered.
94
+ console.error('[Geolonia] Failed to initialize map', e); // eslint-disable-line
95
+ }
86
96
  }
87
97
 
88
98
  // set intersection observer
@@ -190,9 +190,9 @@ class SimpleStyleVector {
190
190
  'text-max-width': 12,
191
191
  'text-offset': [
192
192
  'case',
193
- ['==', 'small', ['get', 'marker-size']], ['literal', [0, 0.6]],
194
- ['==', 'large', ['get', 'marker-size']], ['literal', [0, 1.2]],
195
- ['literal', [0, 0.8]],
193
+ ['==', 'small', ['get', 'marker-size']], ['literal', [0, 1]],
194
+ ['==', 'large', ['get', 'marker-size']], ['literal', [0, 1.6]],
195
+ ['literal', [0, 1.2]],
196
196
  ],
197
197
  'text-allow-overlap': false,
198
198
  },
@@ -230,22 +230,15 @@ export class SimpleStyle {
230
230
  'text-field': ['get', 'title'],
231
231
  'text-font': ['Noto Sans Regular'],
232
232
  'text-size': 12,
233
- 'text-anchor': 'top',
234
233
  'text-max-width': 12,
235
- 'text-offset': [
236
- 'case',
237
- ['==', 'small', ['get', 'marker-size']], ['literal', [0, 0.6]],
238
- ['==', 'large', ['get', 'marker-size']], ['literal', [0, 1.2]],
239
- ['literal', [0, 0.8]],
240
- ],
241
234
  'text-allow-overlap': true,
242
235
  'icon-allow-overlap': true,
243
236
  'text-variable-anchor': ['top', 'bottom', 'left', 'right'],
244
237
  'text-radial-offset': [
245
238
  'case',
246
- ['==', 'small', ['get', 'marker-size']], 0.6,
247
- ['==', 'large', ['get', 'marker-size']], 1.3,
248
- 0.8,
239
+ ['==', 'small', ['get', 'marker-size']], 1,
240
+ ['==', 'large', ['get', 'marker-size']], 1.6,
241
+ 1.2,
249
242
  ],
250
243
  },
251
244
  });
@@ -304,17 +297,14 @@ export class SimpleStyle {
304
297
  },
305
298
  });
306
299
 
307
- this.map.on('click', `${this.options.id}-clusters`, (e) => {
300
+ this.map.on('click', `${this.options.id}-clusters`, async (e) => {
308
301
  const features = this.map.queryRenderedFeatures(e.point, { layers: [`${this.options.id}-clusters`] });
309
302
  const clusterId = features[0].properties.cluster_id;
310
- this.map.getSource(`${this.options.id}-points`).getClusterExpansionZoom(clusterId, (err, zoom) => {
311
- if (err)
312
- return;
313
-
314
- this.map.easeTo({
315
- center: features[0].geometry.coordinates,
316
- zoom: zoom,
317
- });
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,
318
308
  });
319
309
  });
320
310
 
@@ -338,7 +328,7 @@ export class SimpleStyle {
338
328
  try {
339
329
 
340
330
  const response = await window.fetch(geojson);
341
- const data = await response.json();
331
+ const data = response.ok ? await response.json() : {};
342
332
  this.geojson = data;
343
333
  this.updateData(data);
344
334
 
@@ -1,8 +1,8 @@
1
- 'use strict';
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
+ });