@geolonia/embed 4.2.2 → 4.3.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.
@@ -53,5 +53,6 @@ export declare function parseControlOption(att: any): {
53
53
  export declare const getSessionId: (digit: any) => string;
54
54
  export declare const parseSimpleVector: (attributeValue: any) => any;
55
55
  export declare const handleRestrictedMode: (map: any) => void;
56
+ export declare const handleErrorMode: (container: any) => void;
56
57
  export declare const sanitizeDescription: (description: any) => Promise<any>;
57
58
  export declare const random: (max: number) => number;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "4.2.2";
1
+ export declare const VERSION = "4.3.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geolonia/embed",
3
- "version": "4.2.2",
3
+ "version": "4.3.0",
4
4
  "description": "Geolonia embed JS API",
5
5
  "main": "dist/embed.js",
6
6
  "types": "dist/embed.d.ts",
@@ -8,7 +8,7 @@ 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 } from './util';
12
12
 
13
13
  import type { MapOptions, PointLike, StyleOptions, StyleSpecification, StyleSwapOptions } from 'maplibre-gl';
14
14
 
@@ -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.');
@@ -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) => {
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
  });
package/src/lib/util.ts CHANGED
@@ -272,6 +272,24 @@ export const handleRestrictedMode = (map) => {
272
272
  }
273
273
  };
274
274
 
275
+ export const handleErrorMode = (container) => {
276
+
277
+ const errorContainer = document.createElement('div');
278
+ errorContainer.classList.add('geolonia__error-container');
279
+
280
+ const div = document.createElement('div');
281
+
282
+ const h1 = document.createElement('h2');
283
+ h1.textContent = 'Geolonia Maps';
284
+ div.appendChild(h1);
285
+
286
+ div.classList.add('geolonia__error-message');
287
+ div.innerHTML += '<div class="geolonia__error-message-description">地図の初期化に失敗しました。管理者にお問い合わせ下さい。開発者の方は開発者ツールでエラー詳細をご確認下さい。</div>';
288
+
289
+ errorContainer.appendChild(div);
290
+ container.appendChild(errorContainer);
291
+ };
292
+
275
293
  export const sanitizeDescription = async (description) => {
276
294
  const { default: sanitizeHtml } = await import('sanitize-html');
277
295
  return sanitizeHtml(description, {
@@ -281,3 +299,4 @@ export const sanitizeDescription = async (description) => {
281
299
  };
282
300
 
283
301
  export const random = (max: number): number => Math.floor(Math.random() * max);
302
+
package/src/style.css CHANGED
@@ -110,6 +110,34 @@
110
110
  background-size: cover;
111
111
  }
112
112
 
113
+ /* Style for error message */
114
+ .geolonia__error-container {
115
+ display: flex;
116
+ justify-content: center;
117
+ align-items: center;
118
+ height: 100%;
119
+ width: 100%;
120
+ background-color: #dedede;
121
+ z-index: 9999;
122
+ position: absolute;
123
+ }
124
+
125
+ .geolonia__error-message {
126
+ max-width: 300px;
127
+ background-color: #ffffff;
128
+ margin: 10px;
129
+ padding: 0.75rem 1.25rem;
130
+ border-radius: 6px;
131
+ position: absolute;
132
+ z-index: 99999;
133
+ word-wrap: break-word;
134
+ box-shadow: 0 4px 10px #0000001a
135
+ }
136
+
137
+ .geolonia__error-message-description {
138
+ margin: 15px 0;
139
+ }
140
+
113
141
  /* CSS for Attribution */
114
142
  /* Fix: https://github.com/geolonia/embed/issues/291 */
115
143
  .maplibregl-map {