@panoramax/web-viewer 3.2.3-develop-e0ce9866 → 3.2.3-develop-00ee44cd

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.
@@ -36,7 +36,7 @@ Choose the allowed navigation between pictures, to eventually restrict what is v
36
36
 
37
37
  - `nav=any` (or no value): no restriction in navigation (default)
38
38
  - `nav=seq`: can only see pictures in same sequence
39
- - `nav=none`: can only see current picture, no navigation to other picture allowed
39
+ - `nav=none/pic`: can only see current picture, no navigation to other picture allowed
40
40
 
41
41
  ## :material-image: Picture settings
42
42
 
@@ -9,7 +9,7 @@
9
9
  * [.listenToChanges()](#Panoramax.utils.URLHandler+listenToChanges)
10
10
  * [.nextURLParams()](#Panoramax.utils.URLHandler+nextURLParams) ⇒ <code>object</code>
11
11
  * [.nextURLString()](#Panoramax.utils.URLHandler+nextURLString) ⇒ <code>string</code>
12
- * [.currentURLParams()](#Panoramax.utils.URLHandler+currentURLParams) ⇒ <code>object</code>
12
+ * [.currentURLParams([readFromHash])](#Panoramax.utils.URLHandler+currentURLParams) ⇒ <code>object</code>
13
13
  * [.currentMapString()](#Panoramax.utils.URLHandler+currentMapString) ⇒ <code>string</code>
14
14
  * [.currentPSVString()](#Panoramax.utils.URLHandler+currentPSVString) ⇒ <code>string</code>
15
15
  * [.nextShortLink()](#Panoramax.utils.URLHandler+nextShortLink) ⇒ <code>str</code>
@@ -51,11 +51,16 @@ Compute next URL query string (based on `nextURLParams()`)
51
51
  **Returns**: <code>string</code> - The query string
52
52
  <a name="Panoramax.utils.URLHandler+currentURLParams"></a>
53
53
 
54
- ### urlHandler.currentURLParams() ⇒ <code>object</code>
54
+ ### urlHandler.currentURLParams([readFromHash]) ⇒ <code>object</code>
55
55
  Transforms current URL query string into key->value object
56
56
 
57
57
  **Kind**: instance method of [<code>URLHandler</code>](#Panoramax.utils.URLHandler)
58
58
  **Returns**: <code>object</code> - Key-value read from current URL query
59
+
60
+ | Param | Type | Default | Description |
61
+ | --- | --- | --- | --- |
62
+ | [readFromHash] | <code>boolean</code> | <code>false</code> | Switch to reading from hash URL part (for retro-compatibility) |
63
+
59
64
  <a name="Panoramax.utils.URLHandler+currentMapString"></a>
60
65
 
61
66
  ### urlHandler.currentMapString() ⇒ <code>string</code>
@@ -120,3 +120,11 @@ Many functions were changed as well, in order to reduce source files size and ma
120
120
  | `Viewer.toggleJOSMLive` | Made private in `(components.ui.widgets).Share` |
121
121
  | `Viewer`'s set/toggle focus/unfocused | Managed through `(components.core).Viewer` `focus` attribute and `mini` property |
122
122
  | `Viewer.setFilters` | `(components.ui).MapMore` |
123
+
124
+ ## 🌍 URL parameters
125
+
126
+ URL parameters are now managed in the URL _search_ part (everything after the `?`), whereas in version 3 it was managed through _hash_ part (everything after the `#`). To ensure long-term compatibility, you may just replace the `#` in your URL by `?`. Here's an example of these new URL:
127
+
128
+ ```urlencoded
129
+ https://panoramax.ign.fr/?background=streets&focus=map&map=9/48.6659/2.3237&speed=250
130
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panoramax/web-viewer",
3
- "version": "3.2.3-develop-e0ce9866",
3
+ "version": "3.2.3-develop-00ee44cd",
4
4
  "description": "Panoramax web viewer for geolocated pictures",
5
5
  "main": "build/index.js",
6
6
  "author": "Panoramax team",
@@ -139,7 +139,7 @@ export default class Viewer extends Basic {
139
139
  this.loader.setAttribute("value", 30);
140
140
  this._initParams = new InitParameters(
141
141
  InitParameters.GetComponentProperties(Viewer, this),
142
- this.urlHandler?.currentURLParams()
142
+ Object.assign({}, this.urlHandler?.currentURLParams(), this.urlHandler?.currentURLParams(true))
143
143
  );
144
144
 
145
145
  const myInitParams = this._initParams.getParentInit();
@@ -833,6 +833,7 @@ export default class Photo extends PSViewer {
833
833
  * @memberof Panoramax.components.ui.Photo#
834
834
  */
835
835
  setPicturesNavigation(pn) {
836
+ if(pn === "none") { pn = "pic"; }
836
837
  this._picturesNavigation = pn;
837
838
 
838
839
  /**
@@ -856,6 +857,7 @@ export default class Photo extends PSViewer {
856
857
  case "seq":
857
858
  return ["next", "prev"].includes(link.rel);
858
859
  case "pic":
860
+ case "none":
859
861
  return false;
860
862
  case "any":
861
863
  default:
@@ -284,7 +284,7 @@ export function alterPSVState(psv, params) {
284
284
  }
285
285
 
286
286
  // Change pictures navigation mode
287
- if(["pic", "any", "seq"].includes(params.picturesNavigation)) {
287
+ if(["none", "pic", "any", "seq"].includes(params.picturesNavigation)) {
288
288
  psv.setPicturesNavigation(params.picturesNavigation);
289
289
  }
290
290
  }
@@ -5,7 +5,7 @@ import {
5
5
  // List of supported parameters
6
6
  const MANAGED_PARAMETERS = [
7
7
  "speed", "nav", "focus", "pic", "xyz", "map",
8
- "background", "users", "pic_score",
8
+ "background", "users", "pic_score", "s"
9
9
  ].concat(Object.values(MAP_FILTERS_JS2URL));
10
10
 
11
11
  // Events to listen on parent and PSV
@@ -131,19 +131,20 @@ export default class URLHandler extends EventTarget {
131
131
 
132
132
  /**
133
133
  * Transforms current URL query string into key->value object
134
+ * @param {boolean} [readFromHash=false] Switch to reading from hash URL part (for retro-compatibility)
134
135
  * @return {object} Key-value read from current URL query
135
136
  * @memberof Panoramax.utils.URLHandler#
136
137
  */
137
- currentURLParams() {
138
+ currentURLParams(readFromHash = false) {
138
139
  // Get the current hash from location, stripped from its number sign
139
- const hash = window.location.search.replace(/^\?/, "");
140
+ const hash = (readFromHash ? window.location.hash : window.location.search).replace(/^[?#]/, "");
140
141
 
141
142
  // Split the parameter-styled hash into parts and find the value we need
142
143
  let keyvals = {};
143
144
  hash.split("&").map(
144
145
  part => part.split("=")
145
146
  )
146
- .filter(part => part[0] !== undefined && part[0].length > 0)
147
+ .filter(part => part[0] !== undefined && part[0].length > 0 && MANAGED_PARAMETERS.includes(part[0]))
147
148
  .forEach(part => {
148
149
  keyvals[part[0]] = part[1];
149
150
  });
@@ -321,6 +322,9 @@ export default class URLHandler extends EventTarget {
321
322
  const unmanaged = this.getUnmanagedParameters(prevUrl);
322
323
  nextUrl.search = this._parent ? this.nextURLString() + (unmanaged.length > 0 ? "&"+unmanaged : ""): "";
323
324
 
325
+ // Clear out hash if older parameters appear
326
+ if(Object.keys(this.currentURLParams(true)).length > 0) { nextUrl.hash = ""; }
327
+
324
328
  // Skip hash update if no changes
325
329
  if(prevUrl.search == nextUrl.search) { return; }
326
330
 
@@ -362,6 +362,8 @@ describe("setPicturesNavigation", () => {
362
362
  expect(ph.getPicturesNavigation()).toBe("seq");
363
363
  ph.setPicturesNavigation("any");
364
364
  expect(ph.getPicturesNavigation()).toBe("any");
365
+ ph.setPicturesNavigation("none");
366
+ expect(ph.getPicturesNavigation()).toBe("pic");
365
367
  expect(eventWatcher.mock.calls).toMatchSnapshot();
366
368
  });
367
369
  });
@@ -246,6 +246,11 @@ Array [
246
246
  "value": "any",
247
247
  },
248
248
  ],
249
+ Array [
250
+ Object {
251
+ "value": "pic",
252
+ },
253
+ ],
249
254
  ]
250
255
  `;
251
256
 
@@ -312,6 +312,12 @@ describe("alterPSVState", () => {
312
312
  expect(psv.setPicturesNavigation).toHaveBeenCalledWith("pic");
313
313
  });
314
314
 
315
+ it("should set pictures navigation mode when picturesNavigation=none", () => {
316
+ const params = { picturesNavigation: "none" };
317
+ alterPSVState(psv, params);
318
+ expect(psv.setPicturesNavigation).toHaveBeenCalledWith("none");
319
+ });
320
+
315
321
  it("should not set pictures navigation mode when picturesNavigation param is invalid", () => {
316
322
  const params = { picturesNavigation: "invalid" };
317
323
  alterPSVState(psv, params);
@@ -171,7 +171,7 @@ describe("nextURLString", () => {
171
171
  });
172
172
 
173
173
  describe("currentURLParams", () => {
174
- it("works if empty", () => {
174
+ it("works if empty + search", () => {
175
175
  delete window.location;
176
176
  window.location = { search: "" };
177
177
  const v = { addEventListener: jest.fn() };
@@ -179,20 +179,61 @@ describe("currentURLParams", () => {
179
179
  expect(uh.currentURLParams()).toStrictEqual({});
180
180
  });
181
181
 
182
- it("works with single param", () => {
182
+ it("works with single param + search", () => {
183
183
  delete window.location;
184
- window.location = { search: "?a=b" };
184
+ window.location = { search: "?nav=pic" };
185
+ const v = { addEventListener: jest.fn() };
186
+ const uh = new URLHandler(v);
187
+ expect(uh.currentURLParams()).toStrictEqual({"nav": "pic"});
188
+ });
189
+
190
+ it("works with multiple params + search", () => {
191
+ delete window.location;
192
+ window.location = { search: "?nav=pic&speed=42" };
193
+ const v = { addEventListener: jest.fn() };
194
+ const uh = new URLHandler(v);
195
+ expect(uh.currentURLParams()).toStrictEqual({"nav": "pic", "speed": "42"});
196
+ });
197
+
198
+ it("works if empty + hash", () => {
199
+ delete window.location;
200
+ window.location = { hash: "" };
201
+ const v = { addEventListener: jest.fn() };
202
+ const uh = new URLHandler(v);
203
+ expect(uh.currentURLParams(true)).toStrictEqual({});
204
+ });
205
+
206
+ it("works with single param + hash", () => {
207
+ delete window.location;
208
+ window.location = { hash: "#nav=pic" };
209
+ const v = { addEventListener: jest.fn() };
210
+ const uh = new URLHandler(v);
211
+ expect(uh.currentURLParams(true)).toStrictEqual({"nav": "pic"});
212
+ });
213
+
214
+ it("works with multiple params + hash", () => {
215
+ delete window.location;
216
+ window.location = { hash: "#nav=pic&speed=42" };
185
217
  const v = { addEventListener: jest.fn() };
186
218
  const uh = new URLHandler(v);
187
- expect(uh.currentURLParams()).toStrictEqual({"a": "b"});
219
+ expect(uh.currentURLParams(true)).toStrictEqual({"nav": "pic", "speed": "42"});
188
220
  });
189
221
 
190
- it("works with multiple params", () => {
222
+ it("works with search + hash", () => {
191
223
  delete window.location;
192
- window.location = { search: "?a=b&c=d" };
224
+ window.location = { hash: "#nav=pic&speed=42", search: "?pic=bla" };
193
225
  const v = { addEventListener: jest.fn() };
194
226
  const uh = new URLHandler(v);
195
- expect(uh.currentURLParams()).toStrictEqual({"a": "b", "c": "d"});
227
+ expect(uh.currentURLParams()).toStrictEqual({"pic": "bla"});
228
+ expect(uh.currentURLParams(true)).toStrictEqual({"nav": "pic", "speed": "42"});
229
+ });
230
+
231
+ it("skips unmanaged parameters", () => {
232
+ delete window.location;
233
+ window.location = { search: "?a=b" };
234
+ const v = { addEventListener: jest.fn() };
235
+ const uh = new URLHandler(v);
236
+ expect(uh.currentURLParams()).toStrictEqual({});
196
237
  });
197
238
  });
198
239
 
@@ -295,7 +336,7 @@ describe("_onParentChange", () => {
295
336
  delete window.location;
296
337
 
297
338
  window.history = { replaceState: jest.fn(), state: {} };
298
- window.location = { href: "http://localhost:5000/?nav=pic&speed=2", search: "?nav=pic&speed=2" };
339
+ window.location = { href: "http://localhost:5000/?nav=pic&speed=2", search: "?nav=pic&speed=2", hash: "" };
299
340
 
300
341
  const v = { addEventListener: jest.fn() };
301
342
  const uh = new URLHandler(v);
@@ -314,7 +355,7 @@ describe("_onParentChange", () => {
314
355
  delete window.location;
315
356
 
316
357
  window.history = { pushState: jest.fn(), state: {} };
317
- window.location = { href: "http://localhost:5000/?pic=bla", search: "?pic=bla" };
358
+ window.location = { href: "http://localhost:5000/?pic=bla", search: "?pic=bla", hash: "" };
318
359
 
319
360
  const v = { addEventListener: jest.fn() };
320
361
  const uh = new URLHandler(v);
@@ -333,7 +374,7 @@ describe("_onParentChange", () => {
333
374
  delete window.location;
334
375
 
335
376
  window.history = { replaceState: jest.fn(), state: {} };
336
- window.location = { href: "http://localhost:5000/?speed=1&nav=seq", search: "?speed=1&nav=seq" };
377
+ window.location = { href: "http://localhost:5000/?speed=1&nav=seq", search: "?speed=1&nav=seq", hash: "" };
337
378
 
338
379
  const v = { addEventListener: jest.fn() };
339
380
  const uh = new URLHandler(v);