@panoramax/web-viewer 3.1.0-develop-537ffe27 → 3.1.0-develop-428bc81e

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-428bc81e",
4
4
  "description": "Panoramax web viewer for geolocated pictures",
5
5
  "main": "build/index.js",
6
6
  "author": "Panoramax team",
@@ -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