@panoramax/web-viewer 3.2.3-develop-e0ce9866 → 3.2.3-develop-367cb599
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/CHANGELOG.md +1 -0
- package/build/index.js +2 -2
- package/build/index.js.map +1 -1
- package/docs/reference/utils/URLHandler.md +7 -2
- package/docs/tutorials/migrate_v4.md +8 -0
- package/package.json +1 -1
- package/src/components/core/Viewer.js +1 -1
- package/src/utils/URLHandler.js +8 -4
- package/tests/utils/URLHandler.test.js +51 -10
|
@@ -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
|
@@ -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();
|
package/src/utils/URLHandler.js
CHANGED
|
@@ -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
|
|
|
@@ -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: "?
|
|
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({"
|
|
219
|
+
expect(uh.currentURLParams(true)).toStrictEqual({"nav": "pic", "speed": "42"});
|
|
188
220
|
});
|
|
189
221
|
|
|
190
|
-
it("works with
|
|
222
|
+
it("works with search + hash", () => {
|
|
191
223
|
delete window.location;
|
|
192
|
-
window.location = {
|
|
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({"
|
|
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);
|