@panoramax/web-viewer 3.2.3-develop-54fea60b → 3.2.3-develop-d3aad6f3
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 +2 -0
- package/build/index.css +2 -2
- package/build/index.css.map +1 -1
- package/build/index.js +30 -21
- package/build/index.js.map +1 -1
- package/build/static/media/atkinson-hyperlegible-next-latin-400-normal..woff +0 -0
- package/build/static/media/atkinson-hyperlegible-next-latin-400-normal..woff2 +0 -0
- package/build/static/media/atkinson-hyperlegible-next-latin-ext-400-normal..woff +0 -0
- package/build/static/media/atkinson-hyperlegible-next-latin-ext-400-normal..woff2 +0 -0
- package/docs/reference/utils/InitParameters.md +3 -2
- package/package.json +2 -1
- package/src/components/core/Basic.css +2 -1
- package/src/components/core/Basic.js +1 -0
- package/src/components/core/Viewer.js +4 -2
- package/src/components/menus/MapFilters.js +4 -2
- package/src/components/menus/MapLegend.js +1 -1
- package/src/components/menus/PictureLegend.js +1 -1
- package/src/components/menus/PlayerOptions.js +0 -1
- package/src/components/menus/Share.js +7 -4
- package/src/components/styles.js +12 -5
- package/src/components/ui/ButtonGroup.css +4 -0
- package/src/components/ui/Loader.js +1 -1
- package/src/components/ui/QualityScore.js +5 -5
- package/src/components/ui/SearchBar.js +3 -2
- package/src/utils/InitParameters.js +8 -5
- package/src/utils/map.js +41 -1
- package/tests/utils/InitParameters.test.js +20 -3
- package/tests/utils/__snapshots__/map.test.js.snap +11 -0
- package/tests/utils/map.test.js +83 -24
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
**Kind**: static class of <code>Panoramax.utils</code>
|
|
5
5
|
|
|
6
6
|
* [.InitParameters](#Panoramax.utils.InitParameters)
|
|
7
|
-
* [new InitParameters([componentAttrs], [urlParams])](#new_Panoramax.utils.InitParameters_new)
|
|
7
|
+
* [new InitParameters([componentAttrs], [urlParams], [browserStorage])](#new_Panoramax.utils.InitParameters_new)
|
|
8
8
|
* [.getParentInit()](#Panoramax.utils.InitParameters+getParentInit)
|
|
9
9
|
* [.getParentPostInit()](#Panoramax.utils.InitParameters+getParentPostInit)
|
|
10
10
|
* [.getPSVInit()](#Panoramax.utils.InitParameters+getPSVInit)
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
<a name="new_Panoramax.utils.InitParameters_new"></a>
|
|
16
16
|
|
|
17
|
-
### new InitParameters([componentAttrs], [urlParams])
|
|
17
|
+
### new InitParameters([componentAttrs], [urlParams], [browserStorage])
|
|
18
18
|
Merges all URL parameters and component attributes into a single set of coherent settings.
|
|
19
19
|
|
|
20
20
|
|
|
@@ -22,6 +22,7 @@ Merges all URL parameters and component attributes into a single set of coherent
|
|
|
22
22
|
| --- | --- | --- |
|
|
23
23
|
| [componentAttrs] | <code>object</code> | HTML attributes from parent component |
|
|
24
24
|
| [urlParams] | <code>object</code> | Parameters extracted from URL |
|
|
25
|
+
| [browserStorage] | <code>object</code> | Parameters read from local/session storage |
|
|
25
26
|
|
|
26
27
|
<a name="Panoramax.utils.InitParameters+getParentInit"></a>
|
|
27
28
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panoramax/web-viewer",
|
|
3
|
-
"version": "3.2.3-develop-
|
|
3
|
+
"version": "3.2.3-develop-d3aad6f3",
|
|
4
4
|
"description": "Panoramax web viewer for geolocated pictures",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"author": "Panoramax team",
|
|
@@ -89,6 +89,7 @@
|
|
|
89
89
|
"workbox-webpack-plugin": "^6.5.4"
|
|
90
90
|
},
|
|
91
91
|
"dependencies": {
|
|
92
|
+
"@fontsource/atkinson-hyperlegible-next": "^5.2.2",
|
|
92
93
|
"@fortawesome/fontawesome-svg-core": "^6.7.2",
|
|
93
94
|
"@fortawesome/free-regular-svg-icons": "^6.7.2",
|
|
94
95
|
"@fortawesome/free-solid-svg-icons": "^6.7.2",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* Colors */
|
|
2
|
-
:root {
|
|
2
|
+
:root, :host {
|
|
3
3
|
--white: #ffffff;
|
|
4
4
|
--black: #181818;
|
|
5
5
|
--black-pale: #1b1a17;
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
--widget-font: var(--grey-dark);
|
|
32
32
|
--widget-font-active: var(--white);
|
|
33
33
|
--widget-font-direct: var(--blue);
|
|
34
|
+
--font-family: "Atkinson Hyperlegible Next", sans-serif;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
.pnx-hidden { display: none !important; }
|
|
@@ -5,6 +5,7 @@ import { DEFAULT_TILES } from "../../utils/map";
|
|
|
5
5
|
import { createWebComp } from "../../utils/widgets";
|
|
6
6
|
import { isInIframe, isInternetFast } from "../../utils/utils";
|
|
7
7
|
import PACKAGE_JSON from "../../../package.json";
|
|
8
|
+
import "@fontsource/atkinson-hyperlegible-next";
|
|
8
9
|
import "./Basic.css";
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import "./Viewer.css";
|
|
4
4
|
import { SYSTEM as PSSystem, DEFAULTS as PSDefaults } from "@photo-sphere-viewer/core";
|
|
5
5
|
import URLHandler from "../../utils/URLHandler";
|
|
6
|
-
import { linkMapAndPhoto } from "../../utils/map";
|
|
6
|
+
import { linkMapAndPhoto, saveMapParamsToLocalStorage, getMapParamsFromLocalStorage } from "../../utils/map";
|
|
7
7
|
import Basic from "./Basic";
|
|
8
8
|
import Photo, { PSV_DEFAULT_ZOOM, PSV_ANIM_DURATION } from "../ui/Photo";
|
|
9
9
|
import MapMore from "../ui/MapMore";
|
|
@@ -139,7 +139,8 @@ 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
|
-
Object.assign({}, this.urlHandler?.currentURLParams(), this.urlHandler?.currentURLParams(true))
|
|
142
|
+
Object.assign({}, this.urlHandler?.currentURLParams(), this.urlHandler?.currentURLParams(true)),
|
|
143
|
+
{ map: getMapParamsFromLocalStorage() },
|
|
143
144
|
);
|
|
144
145
|
|
|
145
146
|
const myInitParams = this._initParams.getParentInit();
|
|
@@ -359,6 +360,7 @@ export default class Viewer extends Basic {
|
|
|
359
360
|
async _initMap() {
|
|
360
361
|
await new Promise(resolve => {
|
|
361
362
|
this.map = new MapMore(this, this.mapContainer, this._initParams.getMapInit());
|
|
363
|
+
saveMapParamsToLocalStorage(this.map);
|
|
362
364
|
this.map.once("users-changed", () => {
|
|
363
365
|
this.loader.setAttribute("value", 75);
|
|
364
366
|
resolve();
|
|
@@ -48,7 +48,7 @@ export default class MapFilters extends LitElement {
|
|
|
48
48
|
z-index: 131;
|
|
49
49
|
background-color: rgba(255,255,255,0.8);
|
|
50
50
|
text-align: center;
|
|
51
|
-
font-weight:
|
|
51
|
+
font-weight: 800;
|
|
52
52
|
position: absolute;
|
|
53
53
|
top: 0;
|
|
54
54
|
right: 0;
|
|
@@ -80,6 +80,7 @@ export default class MapFilters extends LitElement {
|
|
|
80
80
|
color: var(--widget-font);
|
|
81
81
|
border: 1px solid var(--widget-border-div);
|
|
82
82
|
border-radius: 20px;
|
|
83
|
+
font-family: var(--font-family);
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
/* Input shortcuts */
|
|
@@ -91,13 +92,14 @@ export default class MapFilters extends LitElement {
|
|
|
91
92
|
border: none;
|
|
92
93
|
height: 20px;
|
|
93
94
|
line-height: 20px;
|
|
94
|
-
font-size:
|
|
95
|
+
font-size: 0.8em;
|
|
95
96
|
padding: 0 8px;
|
|
96
97
|
vertical-align: middle;
|
|
97
98
|
background-color: var(--grey-pale);
|
|
98
99
|
color: var(--black);
|
|
99
100
|
border-radius: 10px;
|
|
100
101
|
cursor: pointer;
|
|
102
|
+
font-family: var(--font-family);
|
|
101
103
|
}
|
|
102
104
|
.pnx-input-shortcuts button:hover {
|
|
103
105
|
background-color: #d9dcd9;
|
|
@@ -78,10 +78,13 @@ export default class ShareMenu extends LitElement {
|
|
|
78
78
|
/** @private */
|
|
79
79
|
connectedCallback() {
|
|
80
80
|
super.connectedCallback();
|
|
81
|
-
this.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
this._parent?.onceReady().then(() => {
|
|
82
|
+
this._onUrlChange();
|
|
83
|
+
this._parent.urlHandler.addEventListener("url-changed", this._onUrlChange.bind(this));
|
|
84
|
+
|
|
85
|
+
this._parent.onceFirstPicLoaded().then(this._onPictureLoad.bind(this));
|
|
86
|
+
this._parent.psv.addEventListener("picture-loaded", this._onPictureLoad.bind(this));
|
|
87
|
+
});
|
|
85
88
|
}
|
|
86
89
|
|
|
87
90
|
/** @private */
|
package/src/components/styles.js
CHANGED
|
@@ -13,7 +13,7 @@ export const panel = css`
|
|
|
13
13
|
color: var(--widget-font);
|
|
14
14
|
min-width: 250px;
|
|
15
15
|
box-sizing: border-box;
|
|
16
|
-
font-family:
|
|
16
|
+
font-family: var(--font-family);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
.pnx-panel.pnx-hidden {
|
|
@@ -58,6 +58,7 @@ export const textarea = css`
|
|
|
58
58
|
padding: 5px;
|
|
59
59
|
width: 100%;
|
|
60
60
|
box-sizing: border-box;
|
|
61
|
+
font-family: var(--font-family);
|
|
61
62
|
}
|
|
62
63
|
`;
|
|
63
64
|
|
|
@@ -70,6 +71,7 @@ export const select = css`
|
|
|
70
71
|
border-radius: 20px;
|
|
71
72
|
font-size: 16px;
|
|
72
73
|
padding: 2px 10px;
|
|
74
|
+
font-family: var(--font-family);
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
select.pnx-100w {
|
|
@@ -87,6 +89,7 @@ export const input = css`
|
|
|
87
89
|
border-radius: 20px;
|
|
88
90
|
font-size: 16px;
|
|
89
91
|
padding: 2px 10px;
|
|
92
|
+
font-family: var(--font-family);
|
|
90
93
|
}
|
|
91
94
|
|
|
92
95
|
input.pnx-100w {
|
|
@@ -98,14 +101,14 @@ export const input = css`
|
|
|
98
101
|
// Buttons
|
|
99
102
|
export const btn = css`
|
|
100
103
|
:host {
|
|
101
|
-
display: inline-
|
|
104
|
+
display: inline-flex;
|
|
102
105
|
}
|
|
103
106
|
|
|
104
107
|
/* Common properties */
|
|
105
108
|
.pnx-btn {
|
|
106
109
|
white-space: nowrap;
|
|
107
|
-
font-size:
|
|
108
|
-
font-family:
|
|
110
|
+
font-size: 1em;
|
|
111
|
+
font-family: var(--font-family);
|
|
109
112
|
flex-grow: 1;
|
|
110
113
|
flex-shrink: 1;
|
|
111
114
|
text-align: center;
|
|
@@ -155,7 +158,7 @@ export const btn = css`
|
|
|
155
158
|
height: 40px;
|
|
156
159
|
line-height: 40px;
|
|
157
160
|
font-size: 16px;
|
|
158
|
-
font-weight:
|
|
161
|
+
font-weight: 500;
|
|
159
162
|
min-width: 40px;
|
|
160
163
|
padding: 0 10px;
|
|
161
164
|
gap: 8px;
|
|
@@ -232,6 +235,10 @@ export const btn = css`
|
|
|
232
235
|
|
|
233
236
|
// Titles
|
|
234
237
|
export const titles = css`
|
|
238
|
+
h1, h2, h3, h4, h5, h6 {
|
|
239
|
+
font-family: var(--font-family);
|
|
240
|
+
}
|
|
241
|
+
|
|
235
242
|
h3 {
|
|
236
243
|
font-size: 1.1em;
|
|
237
244
|
line-height: 1.1em;
|
|
@@ -28,7 +28,7 @@ export default class Loader extends LitElement {
|
|
|
28
28
|
background-size: cover;
|
|
29
29
|
background-position: center;
|
|
30
30
|
z-index: 200;
|
|
31
|
-
font-family:
|
|
31
|
+
font-family: var(--font-family);
|
|
32
32
|
font-weight: 550;
|
|
33
33
|
color: var(--black);
|
|
34
34
|
font-size: 1.4em;
|
|
@@ -32,14 +32,14 @@ export default class QualityScore extends LitElement {
|
|
|
32
32
|
font-size: 18px;
|
|
33
33
|
width: 25px;
|
|
34
34
|
height: 30px;
|
|
35
|
-
line-height:
|
|
35
|
+
line-height: 28px;
|
|
36
36
|
display: inline-block;
|
|
37
37
|
border: 1px solid white;
|
|
38
38
|
text-align: center;
|
|
39
39
|
background-color: gray;
|
|
40
40
|
color: rgba(255,255,255,0.9);
|
|
41
|
-
font-family:
|
|
42
|
-
font-weight:
|
|
41
|
+
font-family: var(--font-family);
|
|
42
|
+
font-weight: 800;
|
|
43
43
|
vertical-align: middle;
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -58,7 +58,7 @@ export default class QualityScore extends LitElement {
|
|
|
58
58
|
.selected, input[type="checkbox"]:checked + label {
|
|
59
59
|
width: 30px;
|
|
60
60
|
height: 42px;
|
|
61
|
-
line-height:
|
|
61
|
+
line-height: 41px;
|
|
62
62
|
border-radius: 8px;
|
|
63
63
|
font-size: 27px;
|
|
64
64
|
color: white;
|
|
@@ -71,7 +71,7 @@ export default class QualityScore extends LitElement {
|
|
|
71
71
|
label:hover {
|
|
72
72
|
width: 28px;
|
|
73
73
|
height: 35px;
|
|
74
|
-
line-height:
|
|
74
|
+
line-height: 34px;
|
|
75
75
|
border-radius: 3px;
|
|
76
76
|
font-size: 22px;
|
|
77
77
|
color: white;
|
|
@@ -50,6 +50,7 @@ export default class SearchBar extends LitElement {
|
|
|
50
50
|
width: fit-content;
|
|
51
51
|
max-width: 100%;
|
|
52
52
|
box-sizing: border-box;
|
|
53
|
+
font-family: var(--font-family);
|
|
53
54
|
}
|
|
54
55
|
.sb.sb-xxl {
|
|
55
56
|
height: 40px;
|
|
@@ -113,9 +114,9 @@ export default class SearchBar extends LitElement {
|
|
|
113
114
|
background-color: var(--widget-bg);
|
|
114
115
|
color: var(--widget-font);
|
|
115
116
|
z-index: 130;
|
|
116
|
-
font-size:
|
|
117
|
+
font-size: 1.05em;
|
|
117
118
|
line-height: normal;
|
|
118
|
-
font-family:
|
|
119
|
+
font-family: var(--font-family);
|
|
119
120
|
}
|
|
120
121
|
.sb.sb-xxl .sb-results {
|
|
121
122
|
top: 45px;
|
|
@@ -16,9 +16,10 @@ const MAP_NONE = ["none", "null", "false", false];
|
|
|
16
16
|
* @class Panoramax.utils.InitParameters
|
|
17
17
|
* @param {object} [componentAttrs] HTML attributes from parent component
|
|
18
18
|
* @param {object} [urlParams] Parameters extracted from URL
|
|
19
|
+
* @param {object} [browserStorage] Parameters read from local/session storage
|
|
19
20
|
*/
|
|
20
21
|
export default class InitParameters { // eslint-disable-line import/no-unused-modules
|
|
21
|
-
constructor(componentAttrs = {}, urlParams = {}) {
|
|
22
|
+
constructor(componentAttrs = {}, urlParams = {}, browserStorage = {}) {
|
|
22
23
|
// Skip URL parameters if disabled by component
|
|
23
24
|
if(componentAttrs["url-parameters"] === "false") { urlParams = {}; }
|
|
24
25
|
|
|
@@ -29,6 +30,8 @@ export default class InitParameters { // eslint-disable-line import/no-unused-mo
|
|
|
29
30
|
// Sanitize Map parameters
|
|
30
31
|
let componentMap = {};
|
|
31
32
|
if(typeof componentAttrs?.map === "object") { componentMap = componentAttrs.map; }
|
|
33
|
+
let browserMap = {};
|
|
34
|
+
if(typeof browserStorage?.map === "object") { browserMap = browserStorage.map; }
|
|
32
35
|
|
|
33
36
|
// Extract map position from URL
|
|
34
37
|
let urlMap = urlParams.map && urlParams.map !== "none" ? getMapPositionFromString(urlParams.map) : null;
|
|
@@ -41,10 +44,10 @@ export default class InitParameters { // eslint-disable-line import/no-unused-mo
|
|
|
41
44
|
let users = urlParams.users || componentAttrs.users;
|
|
42
45
|
let psv_speed = urlParams.speed || componentPsv?.transitionDuration;
|
|
43
46
|
let psv_nav = urlParams.nav || componentPsv?.picturesNavigation;
|
|
44
|
-
let map_theme = urlParams.theme || componentMap.theme;
|
|
45
|
-
let map_background = urlParams.background || componentMap.background;
|
|
46
|
-
let map_center = urlMap?.center || componentMap.center;
|
|
47
|
-
let map_zoom = urlMap?.zoom || componentMap.zoom;
|
|
47
|
+
let map_theme = urlParams.theme || browserMap?.theme || componentMap.theme;
|
|
48
|
+
let map_background = urlParams.background || browserMap?.background || componentMap.background;
|
|
49
|
+
let map_center = urlMap?.center || browserMap?.center || componentMap.center;
|
|
50
|
+
let map_zoom = urlMap?.zoom || browserMap?.zoom || componentMap.zoom;
|
|
48
51
|
let map_pitch = urlMap?.pitch || componentMap.pitch;
|
|
49
52
|
let map_bearing = urlMap?.bearing || componentMap.bearing;
|
|
50
53
|
|
package/src/utils/map.js
CHANGED
|
@@ -602,4 +602,44 @@ export function initMapKeyboardHandler(parent) {
|
|
|
602
602
|
}
|
|
603
603
|
};
|
|
604
604
|
}.bind(parent.map.keyboard);
|
|
605
|
-
}
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
const MAP_PARAMS_STORAGE = "pnx-map-parameters";
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Reads map parameters from localStorage
|
|
611
|
+
* @private
|
|
612
|
+
*/
|
|
613
|
+
export function getMapParamsFromLocalStorage() {
|
|
614
|
+
const params = localStorage.getItem(MAP_PARAMS_STORAGE);
|
|
615
|
+
if(!params) { return {}; }
|
|
616
|
+
try {
|
|
617
|
+
return JSON.parse(params);
|
|
618
|
+
}
|
|
619
|
+
catch(e) {
|
|
620
|
+
console.warn("Can't read map parameters stored in localStorage", e);
|
|
621
|
+
return {};
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* Save map parameters into localStorage.
|
|
627
|
+
* @private
|
|
628
|
+
*/
|
|
629
|
+
export function saveMapParamsToLocalStorage(map) {
|
|
630
|
+
// Save map state in localStorage
|
|
631
|
+
const save = () => localStorage.setItem(MAP_PARAMS_STORAGE, JSON.stringify({
|
|
632
|
+
center: Object.fromEntries(Object.entries(map.getCenter()).map(([k,v]) => ([k,v.toFixed(7)]))),
|
|
633
|
+
zoom: map.getZoom().toFixed(1),
|
|
634
|
+
background: map.getBackground(),
|
|
635
|
+
theme: map._mapFilters.theme
|
|
636
|
+
}));
|
|
637
|
+
|
|
638
|
+
// Add events to know when to rewrite info
|
|
639
|
+
map.on("background-changed", save);
|
|
640
|
+
map.on("filters-changed", save);
|
|
641
|
+
map.on("moveend", save);
|
|
642
|
+
map.on("zoomend", save);
|
|
643
|
+
map.on("dragend", save);
|
|
644
|
+
map.on("boxzoomend", save);
|
|
645
|
+
}
|
|
@@ -4,8 +4,7 @@ import {
|
|
|
4
4
|
} from "../../src/utils/InitParameters";
|
|
5
5
|
|
|
6
6
|
describe("InitParameters", () => {
|
|
7
|
-
let componentAttrs;
|
|
8
|
-
let urlParams;
|
|
7
|
+
let componentAttrs, urlParams, browserStorage;
|
|
9
8
|
|
|
10
9
|
beforeEach(() => {
|
|
11
10
|
console.warn = jest.fn();
|
|
@@ -41,12 +40,16 @@ describe("InitParameters", () => {
|
|
|
41
40
|
camera: "cam1",
|
|
42
41
|
pic_score: "high",
|
|
43
42
|
};
|
|
43
|
+
|
|
44
|
+
browserStorage = {
|
|
45
|
+
map: { theme: "qualityscore", background: "aerial", center: [-10, -20], zoom: 19 },
|
|
46
|
+
};
|
|
44
47
|
});
|
|
45
48
|
|
|
46
49
|
afterEach(() => jest.clearAllMocks());
|
|
47
50
|
|
|
48
51
|
it("should initialize with componentAttrs and urlParams", () => {
|
|
49
|
-
const initParams = new InitParameters(componentAttrs, urlParams);
|
|
52
|
+
const initParams = new InitParameters(componentAttrs, urlParams, browserStorage);
|
|
50
53
|
|
|
51
54
|
expect(initParams._parentInit).toEqual({
|
|
52
55
|
map: true,
|
|
@@ -111,6 +114,20 @@ describe("InitParameters", () => {
|
|
|
111
114
|
});
|
|
112
115
|
});
|
|
113
116
|
|
|
117
|
+
it("uses browserStorage parameters if no URL parameter is available", () => {
|
|
118
|
+
componentAttrs.map.raster = {};
|
|
119
|
+
const initParams = new InitParameters(componentAttrs, undefined, browserStorage);
|
|
120
|
+
expect(initParams._mapAny).toEqual({
|
|
121
|
+
theme: "qualityscore",
|
|
122
|
+
background: "aerial",
|
|
123
|
+
center: [-10,-20],
|
|
124
|
+
zoom: 19,
|
|
125
|
+
pitch: undefined,
|
|
126
|
+
bearing: undefined,
|
|
127
|
+
users: "user1,user2",
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
114
131
|
it("should sanitize objects correctly", () => {
|
|
115
132
|
const initParams = new InitParameters(componentAttrs, urlParams);
|
|
116
133
|
const obj = { a: 1, b: undefined, c: 3 };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`getMapParamsFromLocalStorage should return parsed params if they exist in localStorage 1`] = `
|
|
4
|
+
Array [
|
|
5
|
+
Array [
|
|
6
|
+
"pnx-map-parameters",
|
|
7
|
+
],
|
|
8
|
+
]
|
|
9
|
+
`;
|
|
10
|
+
|
|
11
|
+
exports[`saveMapParamsToLocalStorage should save map parameters to localStorage 1`] = `Array []`;
|
package/tests/utils/map.test.js
CHANGED
|
@@ -12,30 +12,30 @@ describe("getThumbGif", () => {
|
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
describe("isLabelLayer", () => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
15
|
+
it("works with just text-field", () => {
|
|
16
|
+
const layer = { type: "symbol", layout: { "text-field": "Label" } };
|
|
17
|
+
expect(map.isLabelLayer(layer)).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("works with text-field + minzoom < 15", () => {
|
|
21
|
+
const layer = { type: "symbol", layout: { "text-field": "Label" }, minzoom: 10 };
|
|
22
|
+
expect(map.isLabelLayer(layer)).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("works with text-field + minzoom >= 15", () => {
|
|
26
|
+
const layer = { type: "symbol", layout: { "text-field": "Label" }, minzoom: 15 };
|
|
27
|
+
expect(map.isLabelLayer(layer)).toBe(false);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("works with non-symbol layer", () => {
|
|
31
|
+
const layer = { type: "fill", layout: { "text-field": "Label" } };
|
|
32
|
+
expect(map.isLabelLayer(layer)).toBe(false);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("works without text-field", () => {
|
|
36
|
+
const layer = { type: "symbol", layout: {} };
|
|
37
|
+
expect(map.isLabelLayer(layer)).toBe(false);
|
|
38
|
+
});
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
describe("getUserLayerId", () => {
|
|
@@ -65,3 +65,62 @@ describe("switchCoefValue", () => {
|
|
|
65
65
|
expect(res).toEqual({id: "bla", paint: { "circle-radius": ["bla", ["get", "coef_360"]]}, layout: {"circle-sort": "coef_360"}})
|
|
66
66
|
});
|
|
67
67
|
});
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
Object.defineProperty(window, "localStorage", { value: {
|
|
71
|
+
setItem: jest.fn(),
|
|
72
|
+
getItem: jest.fn(),
|
|
73
|
+
} });
|
|
74
|
+
|
|
75
|
+
describe("getMapParamsFromLocalStorage", () => {
|
|
76
|
+
it("should return an empty object if no params are stored", () => {
|
|
77
|
+
localStorage.getItem.mockReturnValue(null);
|
|
78
|
+
const result = map.getMapParamsFromLocalStorage();
|
|
79
|
+
expect(result).toEqual({});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("should return parsed params if they exist in localStorage", () => {
|
|
83
|
+
const params = { center: { lat: "48.8566000", lng: "2.3522000" }, zoom: "10.0", background: "aerial", theme: "age" };
|
|
84
|
+
localStorage.getItem.mockReturnValue(JSON.stringify(params));
|
|
85
|
+
const result = map.getMapParamsFromLocalStorage();
|
|
86
|
+
expect(localStorage.getItem.mock.calls).toMatchSnapshot();
|
|
87
|
+
expect(result).toEqual(params);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("should return an empty object if JSON parsing fails", () => {
|
|
91
|
+
console.warn = jest.fn();
|
|
92
|
+
localStorage.getItem.mockReturnValue("invalid-json");
|
|
93
|
+
const result = map.getMapParamsFromLocalStorage();
|
|
94
|
+
expect(result).toEqual({});
|
|
95
|
+
expect(console.warn.mock.calls[0][0]).toEqual("Can't read map parameters stored in localStorage");
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe("saveMapParamsToLocalStorage", () => {
|
|
100
|
+
const mockMap = {
|
|
101
|
+
getCenter: jest.fn().mockReturnValue({ lat: 48.8566, lng: 2.3522 }),
|
|
102
|
+
getZoom: jest.fn().mockReturnValue(10),
|
|
103
|
+
getBackground: jest.fn().mockReturnValue("streets"),
|
|
104
|
+
_mapFilters: { theme: "qualityscore" },
|
|
105
|
+
on: jest.fn(),
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
beforeEach(() => {
|
|
109
|
+
jest.clearAllMocks();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("should add event listeners to the map", () => {
|
|
113
|
+
map.saveMapParamsToLocalStorage(mockMap);
|
|
114
|
+
expect(mockMap.on).toHaveBeenCalledWith("background-changed", expect.any(Function));
|
|
115
|
+
expect(mockMap.on).toHaveBeenCalledWith("filters-changed", expect.any(Function));
|
|
116
|
+
expect(mockMap.on).toHaveBeenCalledWith("moveend", expect.any(Function));
|
|
117
|
+
expect(mockMap.on).toHaveBeenCalledWith("zoomend", expect.any(Function));
|
|
118
|
+
expect(mockMap.on).toHaveBeenCalledWith("dragend", expect.any(Function));
|
|
119
|
+
expect(mockMap.on).toHaveBeenCalledWith("boxzoomend", expect.any(Function));
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("should save map parameters to localStorage", () => {
|
|
123
|
+
map.saveMapParamsToLocalStorage(mockMap);
|
|
124
|
+
expect(localStorage.setItem.mock.calls).toMatchSnapshot();
|
|
125
|
+
});
|
|
126
|
+
});
|