@panoramax/web-viewer 3.1.0-develop-537ffe27 → 3.1.0-develop-6577bde8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panoramax/web-viewer",
3
- "version": "3.1.0-develop-537ffe27",
3
+ "version": "3.1.0-develop-6577bde8",
4
4
  "description": "Panoramax web viewer for geolocated pictures",
5
5
  "main": "build/index.js",
6
6
  "author": "Panoramax team",
@@ -96,8 +96,8 @@
96
96
  "@photo-sphere-viewer/markers-plugin": "5.10.1",
97
97
  "@photo-sphere-viewer/virtual-tour-plugin": "5.10.1",
98
98
  "documentation": "^14.0.1",
99
- "maplibre-gl": "^3.6.2",
100
- "pmtiles": "^2.11.0"
99
+ "maplibre-gl": "^4.7.1",
100
+ "pmtiles": "^3.2.0"
101
101
  },
102
102
  "eslintConfig": {
103
103
  "env": {
@@ -96,6 +96,13 @@ export default class Map extends maplibregl.Map {
96
96
  // Parent selection
97
97
  this._parent.addEventListener("select", this.reloadLayersStyles.bind(this));
98
98
 
99
+ // Timeout for initial loading
100
+ setTimeout(() => {
101
+ if(!this.loaded() && this._parent._loader.isVisible()) {
102
+ this._parent._loader.dismiss({}, this._parent._t.map.slow_loading, () => {});
103
+ }
104
+ }, 15000);
105
+
99
106
  this.on("load", async () => {
100
107
  await this.setVisibleUsers(this._parent._options.users);
101
108
  this.reloadLayersStyles();
@@ -291,10 +298,10 @@ export default class Map extends maplibregl.Map {
291
298
  filterUserLayersContent(dataType, filter) {
292
299
  [...this._userLayers].forEach(l => {
293
300
  this.setFilter(getUserLayerId(l, dataType), filter);
294
- if(dataType === "sequences") {
301
+ if(dataType === "sequences" && this.getLayer(getUserLayerId(l, "sequences_plus"))) {
295
302
  this.setFilter(getUserLayerId(l, "sequences_plus"), filter);
296
303
  }
297
- if(dataType === "pictures") {
304
+ if(dataType === "pictures" && this.getLayer(getUserLayerId(l, "pictures_symbols"))) {
298
305
  this.setFilter(getUserLayerId(l, "pictures_symbols"), filter);
299
306
  }
300
307
  });
@@ -362,7 +369,7 @@ export default class Map extends maplibregl.Map {
362
369
  Object.entries(style.sources).forEach(([sId, s]) => this.addSource(sId, s));
363
370
  style.layers = style.layers || [];
364
371
  const layers = style.layers.concat(getMissingLayerStyles(style.sources, style.layers));
365
- layers.forEach(l => this.addLayer(l, firstLabelLayerId?.id));
372
+ layers.filter(l => Object.keys(l).length > 0).forEach(l => this.addLayer(l, firstLabelLayerId?.id));
366
373
  }
367
374
 
368
375
  // Map interaction events
@@ -609,7 +616,7 @@ export default class Map extends maplibregl.Map {
609
616
  if(thumbUrl) {
610
617
  let content = document.createElement("img");
611
618
  content.classList.add("gvs-map-thumb");
612
- content.alt = this._parent._t.thumbnail;
619
+ content.alt = this._parent._t.map.thumbnail;
613
620
  let img = new Image();
614
621
  img.src = thumbUrl;
615
622
 
@@ -634,7 +641,7 @@ export default class Map extends maplibregl.Map {
634
641
  }
635
642
  }
636
643
  else {
637
- this._picPopup.setHTML(`<i>${this._parent._t.no_thumbnail}</i>`);
644
+ this._picPopup.setHTML(`<i>${this._parent._t.map.no_thumbnail}</i>`);
638
645
  }
639
646
  }
640
647
  };
@@ -161,6 +161,7 @@
161
161
  "loading": "Loading…",
162
162
  "thumbnail": "Thumbnail of hovered picture",
163
163
  "no_thumbnail": "No thumbnail",
164
- "not_public": "Not publicly visible"
164
+ "not_public": "Not publicly visible",
165
+ "slow_loading": "Map is slow to load and could appear broken"
165
166
  }
166
167
  }
@@ -161,6 +161,7 @@
161
161
  "loading": "Chargement…",
162
162
  "thumbnail": "Miniature de la photo survolée",
163
163
  "no_thumbnail": "Pas de miniature",
164
- "not_public": "Masqué au public"
164
+ "not_public": "Masqué au public",
165
+ "slow_loading": "La carte est longue à charger et pourrait apparaître cassée"
165
166
  }
166
167
  }
package/src/utils/API.js CHANGED
@@ -285,7 +285,9 @@ export default class API {
285
285
  * @returns {object} The fetch options
286
286
  */
287
287
  _getFetchOptions() {
288
- return Object.assign({}, this._fetchOpts);
288
+ return Object.assign({
289
+ signal: AbortSignal.timeout(15000)
290
+ }, this._fetchOpts);
289
291
  }
290
292
 
291
293
  /**
@@ -295,8 +297,10 @@ export default class API {
295
297
  * @returns {function} The RequestTransformFunction
296
298
  */
297
299
  _getMapRequestTransform() {
300
+ const fetchOpts = this._getFetchOptions();
301
+ delete fetchOpts.signal;
298
302
  // Only if tiles endpoint is enabled and fetch options set
299
- if(Object.keys(this._getFetchOptions()).length > 0) {
303
+ if(Object.keys(fetchOpts).length > 0) {
300
304
  return (url) => {
301
305
  // As MapLibre will use this function for all its calls
302
306
  // We must make sure fetch options are sent only for
@@ -304,7 +308,7 @@ export default class API {
304
308
  if(url.startsWith(this._endpoint)) {
305
309
  return {
306
310
  url,
307
- ...this._getFetchOptions()
311
+ ...fetchOpts
308
312
  };
309
313
  }
310
314
  };
@@ -338,7 +338,7 @@ export function apiFeatureToPSVNode(f, t, fastInternet=false, customLinkFilter=n
338
338
  let panorama;
339
339
 
340
340
  // Cropped panorama
341
- if(Object.keys(croppedPanoData).length > 0) {
341
+ if(!tileUrl && Object.keys(croppedPanoData).length > 0) {
342
342
  panorama = {
343
343
  baseUrl: fastInternet ? hdUrl : baseUrl,
344
344
  origBaseUrl: fastInternet ? hdUrl : baseUrl,
@@ -57,11 +57,11 @@ export default class URLHash extends EventTarget {
57
57
  }
58
58
 
59
59
  /**
60
- * Get the hash string with current map/psv parameters
61
- * @return {string} The hash, starting with #
60
+ * Compute next hash parts
61
+ * @returns {object} Hash parameters
62
+ * @private
62
63
  */
63
- getHashString() {
64
- let hash = "";
64
+ _getHashParts() {
65
65
  let hashParts = {};
66
66
 
67
67
  if(typeof this._viewer.psv.getTransitionDuration() == "number") {
@@ -103,8 +103,17 @@ export default class URLHash extends EventTarget {
103
103
  else {
104
104
  hashParts.map = "none";
105
105
  }
106
+ return hashParts;
107
+ }
108
+
109
+ /**
110
+ * Get the hash string with current map/psv parameters
111
+ * @return {string} The hash, starting with #
112
+ */
113
+ getHashString() {
114
+ let hash = "";
106
115
 
107
- Object.entries(hashParts)
116
+ Object.entries(this._getHashParts())
108
117
  .sort((a,b) => a[0].localeCompare(b[0]))
109
118
  .forEach(entry => {
110
119
  let [ hashName, value ] = entry;
@@ -144,6 +153,63 @@ export default class URLHash extends EventTarget {
144
153
  .forEach(part => {
145
154
  keyvals[part[0]] = part[1];
146
155
  });
156
+
157
+ // If hash is compressed
158
+ if(keyvals.s) {
159
+ const shortVals = Object.fromEntries(
160
+ keyvals.s
161
+ .split("|")
162
+ .map(kv => [kv[0], kv.substring(1)])
163
+ );
164
+
165
+ keyvals = {};
166
+
167
+ // Used letters: b c d e f k m n p s t u v
168
+ // Focus
169
+ if(shortVals.f === "m") { keyvals.focus = "map"; }
170
+ else if(shortVals.f === "p") { keyvals.focus = "pic"; }
171
+ else if(shortVals.f === "t") { keyvals.focus = "meta"; }
172
+
173
+ // Speed
174
+ if(shortVals.s !== "") { keyvals.speed = parseFloat(shortVals.s) * 100; }
175
+
176
+ // Nav
177
+ if(shortVals.n === "a") { keyvals.nav = "any"; }
178
+ else if(shortVals.n === "s") { keyvals.nav = "seq"; }
179
+ if(shortVals.n === "n") { keyvals.nav = "none"; }
180
+
181
+ // Pic
182
+ if(shortVals.p !== "") { keyvals.pic = shortVals.p; }
183
+
184
+ // XYZ
185
+ if(shortVals.c !== "") { keyvals.xyz = shortVals.c; }
186
+
187
+ // Map
188
+ if(shortVals.m !== "") { keyvals.map = shortVals.m; }
189
+
190
+ // Date
191
+ if(shortVals.d !== "") { keyvals.date_from = shortVals.d; }
192
+ if(shortVals.e !== "") { keyvals.date_to = shortVals.e; }
193
+
194
+ // Pic type
195
+ if(shortVals.t === "f") { keyvals.pic_type = "flat"; }
196
+ else if(shortVals.t === "e") { keyvals.pic_type = "equirectangular"; }
197
+
198
+ // Camera
199
+ if(shortVals.k !== "") { keyvals.camera = shortVals.k; }
200
+
201
+ // Theme
202
+ if(shortVals.v === "d") { keyvals.theme = "default"; }
203
+ else if(shortVals.v === "a") { keyvals.theme = "age"; }
204
+ else if(shortVals.v === "t") { keyvals.theme = "type"; }
205
+
206
+ // Background
207
+ if(shortVals.b === "s") { keyvals.background = "streets"; }
208
+ else if(shortVals.b === "a") { keyvals.background = "aerial"; }
209
+
210
+ // Users
211
+ if(shortVals.u !== "") { keyvals.users = shortVals.u; }
212
+ }
147
213
 
148
214
  return keyvals;
149
215
  }
@@ -189,7 +255,7 @@ export default class URLHash extends EventTarget {
189
255
  * @private
190
256
  */
191
257
  _onHashChange() {
192
- const vals = this._getCurrentHash();
258
+ let vals = this._getCurrentHash();
193
259
 
194
260
  // Restore selected picture
195
261
  if(vals.pic) {
@@ -245,6 +311,36 @@ export default class URLHash extends EventTarget {
245
311
  }
246
312
  }
247
313
 
314
+ /**
315
+ * Get short link URL (hash replaced by Base64)
316
+ * @returns {str} The short link URL
317
+ */
318
+ getShortLink(baseUrl) {
319
+ const url = new URL(baseUrl);
320
+ const hashParts = this._getHashParts();
321
+ const shortVals = {
322
+ f: (hashParts.focus || "").substring(0, 1),
323
+ s: !isNaN(parseInt(hashParts.speed)) ? Math.floor(parseInt(hashParts.speed)/100) : undefined,
324
+ n: (hashParts.nav || "").substring(0, 1),
325
+ p: hashParts.pic,
326
+ c: hashParts.xyz,
327
+ m: hashParts.map,
328
+ d: hashParts.date_from,
329
+ e: hashParts.date_to,
330
+ t: (hashParts.pic_type || "").substring(0, 1),
331
+ k: hashParts.camera,
332
+ v: (hashParts.theme || "").substring(0, 1),
333
+ b: (hashParts.background || "").substring(0, 1),
334
+ u: hashParts.users,
335
+ };
336
+ const short = Object.entries(shortVals)
337
+ .filter(([,v]) => v != undefined && v != "")
338
+ .map(([k,v]) => `${k}${v}`)
339
+ .join("|");
340
+ url.hash = `s=${short}`;
341
+ return url;
342
+ }
343
+
248
344
  /**
249
345
  * Extracts from hash parsed keys all map filters values
250
346
  * @param {*} vals Hash keys
@@ -1172,7 +1172,7 @@ export default class Widgets {
1172
1172
  const btnId = pnlShare.querySelector("#gvs-edit-id");
1173
1173
  const btnRss = pnlShare.querySelector("#gvs-share-rss");
1174
1174
 
1175
- fUrl.setAttribute("data-copy", baseUrl);
1175
+ fUrl.setAttribute("data-copy", this._viewer?._hash?.getShortLink(baseUrl) || baseUrl);
1176
1176
  fIframe.innerText = `<iframe src="${iframeBaseUrl}" style="border: none; width: 500px; height: 300px"></iframe>`;
1177
1177
 
1178
1178
  const meta = this._viewer.psv.getPictureMetadata();
@@ -1192,6 +1192,7 @@ export default class Widgets {
1192
1192
  };
1193
1193
 
1194
1194
  updateLinks();
1195
+ this._viewer.addEventListener("ready", updateLinks, { once: true });
1195
1196
  this._viewer?._hash?.addEventListener("url-changed", updateLinks);
1196
1197
 
1197
1198
  // Copy to clipboard on button click
@@ -18,6 +18,7 @@ jest.mock("../src/components/Photo", () => class {
18
18
  });
19
19
 
20
20
  jest.mock("../src/components/Map", () => class {});
21
+ global.AbortSignal = { timeout: jest.fn() };
21
22
 
22
23
  const API_URL = "http://localhost:5000/api/search";
23
24
 
@@ -5,6 +5,7 @@ jest.mock("maplibre-gl", () => ({
5
5
  }));
6
6
 
7
7
  jest.mock("../src/components/Map", () => class {});
8
+ global.AbortSignal = { timeout: jest.fn() };
8
9
 
9
10
  const API_URL = "http://localhost:5000/api/search";
10
11
 
@@ -19,6 +19,8 @@ jest.mock("maplibre-gl", () => ({
19
19
  Map: class {},
20
20
  }));
21
21
 
22
+ global.AbortSignal = { timeout: jest.fn() };
23
+
22
24
  const API_URL = "http://localhost:5000/api/search";
23
25
 
24
26
 
@@ -7,6 +7,7 @@ jest.mock("maplibre-gl", () => ({
7
7
  }));
8
8
 
9
9
  global.console = { info: jest.fn() };
10
+ global.AbortSignal = { timeout: jest.fn() };
10
11
 
11
12
  describe("constructor", () => {
12
13
  it("works with JS element", () => {
@@ -206,6 +206,7 @@ describe("filterUserLayersContent", () => {
206
206
  const m = new Map(p, c);
207
207
  m.getSource = () => true;
208
208
  m.setPaintProperty = jest.fn();
209
+ m.getLayer = () => true;
209
210
  m._fire("load");
210
211
  m.setFilter = jest.fn();
211
212
  m.filterUserLayersContent("pictures", [["test", "true"]]);
@@ -3,6 +3,7 @@ import API from "../../src/utils/API";
3
3
  jest.mock("maplibre-gl", () => ({
4
4
  addProtocol: jest.fn(),
5
5
  }));
6
+ global.AbortSignal = { timeout: jest.fn() };
6
7
 
7
8
  const ENDPOINT = "https://panoramax.ign.fr/api";
8
9
  const VALID_LANDING = {