@panoramax/web-viewer 3.2.3 → 4.0.0-develop-39167b4d

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.
Files changed (255) hide show
  1. package/.gitlab-ci.yml +13 -6
  2. package/CHANGELOG.md +53 -1
  3. package/CODE_OF_CONDUCT.md +1 -1
  4. package/README.md +1 -1
  5. package/build/editor.html +10 -1
  6. package/build/index.css +12 -12
  7. package/build/index.css.map +1 -1
  8. package/build/index.html +1 -1
  9. package/build/index.js +2126 -14
  10. package/build/index.js.map +1 -1
  11. package/build/map.html +1 -1
  12. package/build/photo.html +1 -0
  13. package/build/static/media/atkinson-hyperlegible-next-latin-400-normal..woff +0 -0
  14. package/build/static/media/atkinson-hyperlegible-next-latin-400-normal..woff2 +0 -0
  15. package/build/static/media/atkinson-hyperlegible-next-latin-ext-400-normal..woff +0 -0
  16. package/build/static/media/atkinson-hyperlegible-next-latin-ext-400-normal..woff2 +0 -0
  17. package/build/viewer.html +12 -1
  18. package/build/widgets.html +1 -0
  19. package/config/jest/mocks.js +201 -0
  20. package/config/paths.js +2 -0
  21. package/config/webpack.config.js +52 -0
  22. package/docs/03_URL_settings.md +14 -16
  23. package/docs/05_Compatibility.md +59 -76
  24. package/docs/09_Develop.md +46 -11
  25. package/docs/90_Releases.md +2 -2
  26. package/docs/images/class_diagram.drawio +60 -45
  27. package/docs/images/class_diagram.jpg +0 -0
  28. package/docs/images/screenshot.jpg +0 -0
  29. package/docs/index.md +135 -0
  30. package/docs/reference/components/core/Basic.md +196 -0
  31. package/docs/reference/components/core/CoverageMap.md +210 -0
  32. package/docs/reference/components/core/Editor.md +224 -0
  33. package/docs/reference/components/core/PhotoViewer.md +307 -0
  34. package/docs/reference/components/core/Viewer.md +350 -0
  35. package/docs/reference/components/layout/BottomDrawer.md +35 -0
  36. package/docs/reference/components/layout/CorneredGrid.md +29 -0
  37. package/docs/reference/components/layout/Mini.md +45 -0
  38. package/docs/reference/components/layout/Tabs.md +45 -0
  39. package/docs/reference/components/menus/MapBackground.md +32 -0
  40. package/docs/reference/components/menus/MapFilters.md +15 -0
  41. package/docs/reference/components/menus/MapLayers.md +15 -0
  42. package/docs/reference/components/menus/MapLegend.md +15 -0
  43. package/docs/reference/components/menus/PictureLegend.md +16 -0
  44. package/docs/reference/components/menus/PictureMetadata.md +15 -0
  45. package/docs/reference/components/menus/PlayerOptions.md +15 -0
  46. package/docs/reference/components/menus/QualityScoreDoc.md +15 -0
  47. package/docs/reference/components/menus/ReportForm.md +15 -0
  48. package/docs/reference/components/menus/ShareMenu.md +15 -0
  49. package/docs/reference/components/ui/Button.md +40 -0
  50. package/docs/reference/components/ui/ButtonGroup.md +36 -0
  51. package/docs/reference/components/ui/CopyButton.md +38 -0
  52. package/docs/reference/components/ui/Grade.md +32 -0
  53. package/docs/reference/components/ui/LinkButton.md +45 -0
  54. package/docs/reference/components/ui/ListGroup.md +22 -0
  55. package/docs/reference/components/ui/Loader.md +56 -0
  56. package/docs/reference/components/ui/Map.md +239 -0
  57. package/docs/reference/components/ui/MapMore.md +256 -0
  58. package/docs/reference/components/ui/Photo.md +385 -0
  59. package/docs/reference/components/ui/Popup.md +56 -0
  60. package/docs/reference/components/ui/ProgressBar.md +32 -0
  61. package/docs/reference/components/ui/QualityScore.md +45 -0
  62. package/docs/reference/components/ui/SearchBar.md +63 -0
  63. package/docs/reference/components/ui/TogglableGroup.md +39 -0
  64. package/docs/reference/components/ui/widgets/GeoSearch.md +32 -0
  65. package/docs/reference/components/ui/widgets/Legend.md +49 -0
  66. package/docs/reference/components/ui/widgets/MapFiltersButton.md +33 -0
  67. package/docs/reference/components/ui/widgets/MapLayersButton.md +15 -0
  68. package/docs/reference/components/ui/widgets/OSMEditors.md +15 -0
  69. package/docs/reference/components/ui/widgets/PictureLegendActions.md +32 -0
  70. package/docs/reference/components/ui/widgets/Player.md +33 -0
  71. package/docs/reference/components/ui/widgets/Zoom.md +15 -0
  72. package/docs/reference/utils/API.md +334 -0
  73. package/docs/reference/utils/InitParameters.md +68 -0
  74. package/docs/reference/utils/URLHandler.md +107 -0
  75. package/docs/reference.md +79 -0
  76. package/docs/shortcuts.md +11 -0
  77. package/docs/tutorials/aerial_imagery.md +19 -0
  78. package/docs/tutorials/authentication.md +10 -0
  79. package/docs/tutorials/custom_widgets.md +59 -0
  80. package/docs/tutorials/map_style.md +39 -0
  81. package/docs/tutorials/migrate_v4.md +153 -0
  82. package/docs/tutorials/synced_coverage.md +43 -0
  83. package/mkdocs.yml +66 -5
  84. package/package.json +22 -17
  85. package/public/editor.html +21 -29
  86. package/public/index.html +17 -12
  87. package/public/map.html +19 -18
  88. package/public/photo.html +55 -0
  89. package/public/viewer.html +22 -26
  90. package/public/widgets.html +306 -0
  91. package/scripts/doc.js +79 -0
  92. package/src/components/core/Basic.css +48 -0
  93. package/src/components/core/Basic.js +349 -0
  94. package/src/components/core/CoverageMap.css +9 -0
  95. package/src/components/core/CoverageMap.js +139 -0
  96. package/src/components/core/Editor.css +23 -0
  97. package/src/components/core/Editor.js +390 -0
  98. package/src/components/core/PhotoViewer.css +48 -0
  99. package/src/components/core/PhotoViewer.js +499 -0
  100. package/src/components/core/Viewer.css +98 -0
  101. package/src/components/core/Viewer.js +564 -0
  102. package/src/components/core/index.js +12 -0
  103. package/src/components/index.js +13 -0
  104. package/src/components/layout/BottomDrawer.js +257 -0
  105. package/src/components/layout/CorneredGrid.js +112 -0
  106. package/src/components/layout/Mini.js +117 -0
  107. package/src/components/layout/Tabs.js +133 -0
  108. package/src/components/layout/index.js +9 -0
  109. package/src/components/menus/MapBackground.js +106 -0
  110. package/src/components/menus/MapFilters.js +400 -0
  111. package/src/components/menus/MapLayers.js +143 -0
  112. package/src/components/menus/MapLegend.js +34 -0
  113. package/src/components/menus/PictureLegend.js +257 -0
  114. package/src/components/menus/PictureMetadata.js +317 -0
  115. package/src/components/menus/PlayerOptions.js +95 -0
  116. package/src/components/menus/QualityScoreDoc.js +36 -0
  117. package/src/components/menus/ReportForm.js +133 -0
  118. package/src/components/menus/Share.js +100 -0
  119. package/src/components/menus/index.js +15 -0
  120. package/src/components/styles.js +383 -0
  121. package/src/components/ui/Button.js +77 -0
  122. package/src/components/ui/ButtonGroup.css +57 -0
  123. package/src/components/ui/ButtonGroup.js +68 -0
  124. package/src/components/ui/CopyButton.js +106 -0
  125. package/src/components/ui/Grade.js +54 -0
  126. package/src/components/ui/LinkButton.js +67 -0
  127. package/src/components/ui/ListGroup.js +66 -0
  128. package/src/components/ui/Loader.js +203 -0
  129. package/src/components/{Map.css → ui/Map.css} +5 -17
  130. package/src/components/{Map.js → ui/Map.js} +148 -156
  131. package/src/components/ui/MapMore.js +324 -0
  132. package/src/components/{Photo.css → ui/Photo.css} +6 -6
  133. package/src/components/{Photo.js → ui/Photo.js} +313 -101
  134. package/src/components/ui/Popup.js +145 -0
  135. package/src/components/ui/ProgressBar.js +104 -0
  136. package/src/components/ui/QualityScore.js +147 -0
  137. package/src/components/ui/SearchBar.js +367 -0
  138. package/src/components/ui/TogglableGroup.js +157 -0
  139. package/src/components/ui/index.js +22 -0
  140. package/src/components/ui/widgets/GeoSearch.css +21 -0
  141. package/src/components/ui/widgets/GeoSearch.js +139 -0
  142. package/src/components/ui/widgets/Legend.js +113 -0
  143. package/src/components/ui/widgets/MapFiltersButton.js +104 -0
  144. package/src/components/ui/widgets/MapLayersButton.js +79 -0
  145. package/src/components/ui/widgets/OSMEditors.js +155 -0
  146. package/src/components/ui/widgets/PictureLegendActions.js +117 -0
  147. package/src/components/ui/widgets/Player.css +7 -0
  148. package/src/components/ui/widgets/Player.js +151 -0
  149. package/src/components/ui/widgets/Zoom.js +82 -0
  150. package/src/components/ui/widgets/index.js +13 -0
  151. package/src/img/loader_base.jpg +0 -0
  152. package/src/img/panoramax.svg +13 -0
  153. package/src/img/switch_big.svg +20 -10
  154. package/src/index.js +7 -9
  155. package/src/translations/br.json +1 -0
  156. package/src/translations/da.json +38 -15
  157. package/src/translations/de.json +5 -3
  158. package/src/translations/en.json +35 -15
  159. package/src/translations/eo.json +38 -15
  160. package/src/translations/es.json +1 -1
  161. package/src/translations/fr.json +36 -16
  162. package/src/translations/hu.json +1 -1
  163. package/src/translations/it.json +39 -16
  164. package/src/translations/ja.json +182 -1
  165. package/src/translations/nl.json +106 -6
  166. package/src/translations/pl.json +1 -1
  167. package/src/translations/sv.json +182 -0
  168. package/src/translations/zh_Hant.json +35 -14
  169. package/src/utils/API.js +109 -49
  170. package/src/utils/InitParameters.js +388 -0
  171. package/src/utils/PhotoAdapter.js +1 -0
  172. package/src/utils/URLHandler.js +362 -0
  173. package/src/utils/geocoder.js +152 -0
  174. package/src/utils/{I18n.js → i18n.js} +7 -3
  175. package/src/utils/index.js +11 -0
  176. package/src/utils/{Map.js → map.js} +256 -77
  177. package/src/utils/picture.js +442 -0
  178. package/src/utils/utils.js +324 -0
  179. package/src/utils/widgets.js +55 -0
  180. package/tests/components/core/Basic.test.js +121 -0
  181. package/tests/components/core/BasicMock.js +25 -0
  182. package/tests/components/core/CoverageMap.test.js +20 -0
  183. package/tests/components/core/Editor.test.js +20 -0
  184. package/tests/components/core/PhotoViewer.test.js +57 -0
  185. package/tests/components/core/Viewer.test.js +84 -0
  186. package/tests/components/core/__snapshots__/PhotoViewer.test.js.snap +73 -0
  187. package/tests/components/core/__snapshots__/Viewer.test.js.snap +145 -0
  188. package/tests/components/ui/CopyButton.test.js +52 -0
  189. package/tests/components/ui/Loader.test.js +55 -0
  190. package/tests/components/{Map.test.js → ui/Map.test.js} +73 -61
  191. package/tests/components/{Photo.test.js → ui/Photo.test.js} +97 -63
  192. package/tests/components/ui/Popup.test.js +26 -0
  193. package/tests/components/ui/QualityScore.test.js +18 -0
  194. package/tests/components/ui/SearchBar.test.js +110 -0
  195. package/tests/components/ui/__snapshots__/CopyButton.test.js.snap +33 -0
  196. package/tests/components/ui/__snapshots__/Loader.test.js.snap +56 -0
  197. package/tests/components/{__snapshots__ → ui/__snapshots__}/Map.test.js.snap +11 -38
  198. package/tests/components/{__snapshots__ → ui/__snapshots__}/Photo.test.js.snap +70 -6
  199. package/tests/components/ui/__snapshots__/Popup.test.js.snap +29 -0
  200. package/tests/components/ui/__snapshots__/QualityScore.test.js.snap +11 -0
  201. package/tests/components/ui/__snapshots__/SearchBar.test.js.snap +65 -0
  202. package/tests/utils/API.test.js +83 -83
  203. package/tests/utils/InitParameters.test.js +499 -0
  204. package/tests/utils/URLHandler.test.js +401 -0
  205. package/tests/utils/__snapshots__/API.test.js.snap +10 -0
  206. package/tests/utils/__snapshots__/URLHandler.test.js.snap +21 -0
  207. package/tests/utils/__snapshots__/{Map.test.js.snap → geocoder.test.js.snap} +1 -1
  208. package/tests/utils/__snapshots__/map.test.js.snap +11 -0
  209. package/tests/utils/__snapshots__/picture.test.js.snap +327 -0
  210. package/tests/utils/__snapshots__/widgets.test.js.snap +19 -0
  211. package/tests/utils/geocoder.test.js +37 -0
  212. package/tests/utils/{I18n.test.js → i18n.test.js} +8 -8
  213. package/tests/utils/map.test.js +126 -0
  214. package/tests/utils/picture.test.js +745 -0
  215. package/tests/utils/utils.test.js +288 -0
  216. package/tests/utils/widgets.test.js +31 -0
  217. package/docs/01_Start.md +0 -149
  218. package/docs/02_Usage.md +0 -831
  219. package/docs/04_Advanced_examples.md +0 -216
  220. package/src/Editor.css +0 -37
  221. package/src/Editor.js +0 -361
  222. package/src/StandaloneMap.js +0 -114
  223. package/src/Viewer.css +0 -203
  224. package/src/Viewer.js +0 -1246
  225. package/src/components/CoreView.css +0 -70
  226. package/src/components/CoreView.js +0 -175
  227. package/src/components/Loader.css +0 -74
  228. package/src/components/Loader.js +0 -120
  229. package/src/img/loader_hd.jpg +0 -0
  230. package/src/utils/Exif.js +0 -193
  231. package/src/utils/Utils.js +0 -631
  232. package/src/utils/Widgets.js +0 -562
  233. package/src/viewer/URLHash.js +0 -469
  234. package/src/viewer/Widgets.css +0 -880
  235. package/src/viewer/Widgets.js +0 -1470
  236. package/tests/Editor.test.js +0 -126
  237. package/tests/StandaloneMap.test.js +0 -45
  238. package/tests/Viewer.test.js +0 -366
  239. package/tests/__snapshots__/Editor.test.js.snap +0 -298
  240. package/tests/__snapshots__/StandaloneMap.test.js.snap +0 -30
  241. package/tests/__snapshots__/Viewer.test.js.snap +0 -195
  242. package/tests/components/CoreView.test.js +0 -92
  243. package/tests/components/Loader.test.js +0 -38
  244. package/tests/components/__snapshots__/Loader.test.js.snap +0 -15
  245. package/tests/utils/Exif.test.js +0 -124
  246. package/tests/utils/Map.test.js +0 -113
  247. package/tests/utils/Utils.test.js +0 -300
  248. package/tests/utils/Widgets.test.js +0 -107
  249. package/tests/utils/__snapshots__/Exif.test.js.snap +0 -43
  250. package/tests/utils/__snapshots__/Utils.test.js.snap +0 -41
  251. package/tests/utils/__snapshots__/Widgets.test.js.snap +0 -44
  252. package/tests/viewer/URLHash.test.js +0 -559
  253. package/tests/viewer/Widgets.test.js +0 -127
  254. package/tests/viewer/__snapshots__/URLHash.test.js.snap +0 -108
  255. package/tests/viewer/__snapshots__/Widgets.test.js.snap +0 -403
@@ -0,0 +1,388 @@
1
+ export const MAP_FILTERS_JS2URL = {
2
+ "minDate": "date_from",
3
+ "maxDate": "date_to",
4
+ "pic_type": "pic_type",
5
+ "camera": "camera",
6
+ "theme": "theme",
7
+ "qualityscore": "pic_score",
8
+ };
9
+
10
+ const MAP_FILTERS_URL2JS = Object.fromEntries(Object.entries(MAP_FILTERS_JS2URL).map(v => [v[1], v[0]]));
11
+ const MAP_NONE = ["none", "null", "false", false];
12
+
13
+ const MAPLIBRE_OPTIONS = [
14
+ "antialias", "bearing", "bearingSnap", "bounds",
15
+ "boxZoom", "clickTolerance", "collectResourceTiming",
16
+ "cooperativeGestures", "crossSourceCollisions", "doubleClickZoom", "dragPan",
17
+ "dragRotate", "fadeDuration", "failIfMajorPerformanceCaveat", "fitBoundsOptions",
18
+ "hash", "interactive", "keyboard", "localIdeographFontFamily", "locale", "logoPosition",
19
+ "maplibreLogo", "maxBounds", "maxCanvasSize", "maxPitch", "maxTileCacheSize",
20
+ "maxTileCacheZoomLevels", "maxZoom", "minPitch", "minZoom", "pitch", "pitchWithRotate",
21
+ "pixelRatio", "preserveDrawingBuffer", "refreshExpiredTiles", "renderWorldCopies",
22
+ "scrollZoom", "touchPitch", "touchZoomRotate", "trackResize",
23
+ "transformCameraUpdate", "transformRequest", "validateStyle"
24
+ ];
25
+
26
+ function filterMapLibreOptions(opts) {
27
+ return Object.fromEntries(Object.entries(opts).filter(([key]) => MAPLIBRE_OPTIONS.includes(key)));
28
+ }
29
+
30
+
31
+ /**
32
+ * Merges all URL parameters and component attributes into a single set of coherent settings.
33
+ *
34
+ * @class Panoramax.utils.InitParameters
35
+ * @param {object} [componentAttrs] HTML attributes from parent component
36
+ * @param {object} [urlParams] Parameters extracted from URL
37
+ * @param {object} [browserStorage] Parameters read from local/session storage
38
+ */
39
+ export default class InitParameters { // eslint-disable-line import/no-unused-modules
40
+ constructor(componentAttrs = {}, urlParams = {}, browserStorage = {}) {
41
+ // Skip URL parameters if disabled by component
42
+ if(componentAttrs["url-parameters"] === "false") { urlParams = {}; }
43
+
44
+ // Sanitize PSV parameters
45
+ let componentPsv = {};
46
+ if(typeof componentAttrs?.psv === "object") { componentPsv = componentAttrs.psv; }
47
+
48
+ // Sanitize Map parameters
49
+ let componentMap = {};
50
+ if(typeof componentAttrs?.map === "object") { componentMap = componentAttrs.map; }
51
+ let browserMap = {};
52
+ if(typeof browserStorage?.map === "object") { browserMap = browserStorage.map; }
53
+
54
+ // Extract map position from URL
55
+ let urlMap = urlParams.map && urlParams.map !== "none" ? getMapPositionFromString(urlParams.map) : null;
56
+
57
+ // Parse and prioritize all parameters
58
+ // - Overlapping between URL & component
59
+ let map = MAP_NONE.includes(urlParams.map) || MAP_NONE.includes(componentAttrs.map) ? false : true;
60
+ let focus = urlParams.focus || componentAttrs.focus;
61
+ let picture = urlParams.pic || componentAttrs.picture;
62
+ let users = urlParams.users || componentAttrs.users;
63
+ let psv_speed = urlParams.speed || componentPsv?.transitionDuration;
64
+ let psv_nav = urlParams.nav || componentPsv?.picturesNavigation;
65
+ let map_theme = urlParams.theme || browserMap?.theme || componentMap.theme;
66
+ let map_background = urlParams.background || browserMap?.background || componentMap.background;
67
+ let map_center = urlMap?.center || browserMap?.center || componentMap.center;
68
+ let map_zoom = urlMap?.zoom || browserMap?.zoom || componentMap.zoom;
69
+ let map_pitch = urlMap?.pitch || componentMap.pitch;
70
+ let map_bearing = urlMap?.bearing || componentMap.bearing;
71
+
72
+ // - Component only
73
+ let geocoder = componentAttrs.geocoder;
74
+ let widgets = componentAttrs.widgets;
75
+ let sequence = componentAttrs.sequence;
76
+ let fetchOptions = componentAttrs.fetchOptions;
77
+ let style = componentAttrs.style;
78
+ let lang = componentAttrs.lang;
79
+ let endpoint = componentAttrs.endpoint;
80
+ let map_raster = componentMap.raster;
81
+ let map_attribution = componentMap.attributionControl;
82
+ let map_others = filterMapLibreOptions(componentMap);
83
+
84
+ // - URL only
85
+ let psv_xyz = urlParams.xyz;
86
+ let map_date_from = urlParams.date_from;
87
+ let map_date_to = urlParams.date_to;
88
+ let map_pic_type = urlParams.pic_type;
89
+ let map_camera = urlParams.camera;
90
+ let map_pic_score = urlParams.pic_score;
91
+
92
+ // Check coherence
93
+ if(!["map", "pic"].includes(focus)) {
94
+ console.warn("Invalid value for parameter focus:", focus);
95
+ focus = map && !picture ? "map" : "pic";
96
+ }
97
+ else if(focus === "map" && !map) {
98
+ console.warn("Parameter focus can't be 'map' as map is disabled");
99
+ focus = "pic";
100
+ }
101
+ if(map_background == "aerial" && !map_raster) {
102
+ console.warn("Parameter background can't be 'aerial' as no aerial imagery is available");
103
+ map_background = "streets";
104
+ }
105
+ if(map && !picture) {
106
+ focus = "map";
107
+ }
108
+
109
+ // Put all attributes in appropriate container
110
+ this._parentInit = { map, users, fetchOptions, style, lang, endpoint };
111
+ this._parentPostInit = { focus, picture, sequence, geocoder, widgets, forceFocus: true };
112
+
113
+ this._psvInit = Object.fromEntries(
114
+ Object.entries(componentPsv).filter(
115
+ ([k,]) => !["transitionDuration", "picturesNavigation"].includes(k)
116
+ )
117
+ );
118
+ this._psvAny = {
119
+ transitionDuration: psv_speed,
120
+ picturesNavigation: psv_nav,
121
+ };
122
+ this._psvPostInit = { xyz: psv_xyz };
123
+
124
+ this._mapInit = {
125
+ raster: map_raster,
126
+ attributionControl: map_attribution,
127
+ ...map_others
128
+ };
129
+ this._mapAny = {
130
+ theme: map_theme,
131
+ background: map_background,
132
+ center: map_center,
133
+ zoom: map_zoom,
134
+ pitch: map_pitch,
135
+ bearing: map_bearing,
136
+ users,
137
+ };
138
+ this._mapPostInit = {
139
+ date_from: map_date_from,
140
+ date_to: map_date_to,
141
+ pic_type: map_pic_type,
142
+ camera: map_camera,
143
+ pic_score: map_pic_score,
144
+ };
145
+ }
146
+
147
+ /**
148
+ * Cleans out undefined values from object.
149
+ * @param {object} obj The input object
150
+ * @returns {object} Clean object without undefined values
151
+ * @private
152
+ */
153
+ _sanitize(obj) {
154
+ return Object.fromEntries(Object.entries(obj).filter(([,v]) => v !== undefined));
155
+ }
156
+
157
+ /**
158
+ * Get core component initialization parameters.
159
+ * They must be passed as soon as possible.
160
+ * @memberof Panoramax.utils.InitParameters#
161
+ */
162
+ getParentInit() {
163
+ return this._sanitize(this._parentInit);
164
+ }
165
+
166
+ /**
167
+ * Get core component post-initialization parameters.
168
+ * They must be passed after first rendering or init.
169
+ * @memberof Panoramax.utils.InitParameters#
170
+ */
171
+ getParentPostInit() {
172
+ return this._sanitize(this._parentPostInit);
173
+ }
174
+
175
+ /**
176
+ * Get Photo Sphere Viewer initialization parameters.
177
+ * They must be passed as soon as possible.
178
+ * @memberof Panoramax.utils.InitParameters#
179
+ */
180
+ getPSVInit() {
181
+ return this._sanitize(Object.assign({}, this._psvInit, this._psvAny));
182
+ }
183
+
184
+ /**
185
+ * Get Photo Sphere Viewer post-initialization parameters.
186
+ * They must be passed after first rendering or init.
187
+ * @memberof Panoramax.utils.InitParameters#
188
+ */
189
+ getPSVPostInit() {
190
+ return this._sanitize(Object.assign({}, this._psvPostInit, this._psvAny));
191
+ }
192
+
193
+ /**
194
+ * Get MapLibre GL initialization parameters.
195
+ * They must be passed as soon as possible.
196
+ * @memberof Panoramax.utils.InitParameters#
197
+ */
198
+ getMapInit() {
199
+ return this._sanitize(Object.assign({}, this._mapInit, this._mapAny));
200
+ }
201
+
202
+ /**
203
+ * Get MapLibre GL post-initialization parameters.
204
+ * They must be passed after first rendering or init.
205
+ * @memberof Panoramax.utils.InitParameters#
206
+ */
207
+ getMapPostInit() {
208
+ return this._sanitize(Object.assign({}, this._mapPostInit, this._mapAny));
209
+ }
210
+
211
+ /**
212
+ * Reads public properties from LitElement and returns a classic key-value object.
213
+ * @param {class} compClass The component class (with static `properties` definition)
214
+ * @param {LitElement} comp The component itself
215
+ */
216
+ static GetComponentProperties(compClass, comp) {
217
+ const props = {};
218
+ for(let classK in compClass.properties) {
219
+ let classV = compClass.properties[classK];
220
+ if(!classV.state && comp[classK] != null) {
221
+ props[classK] = comp[classK];
222
+ }
223
+ }
224
+ return props;
225
+ }
226
+ }
227
+
228
+ /**
229
+ * Extracts map center, zoom & more from formatted string.
230
+ * @param {string} str The map position as hash string
231
+ * @param {Panoramax.components.ui.Map} [map] The current map
232
+ * @returns {object} { center, zoom, pitch, bearing }
233
+ * @private
234
+ */
235
+ export function getMapPositionFromString(str, map) {
236
+ const loc = (str || "").split("/");
237
+ if (loc.length >= 3 && !loc.some(v => isNaN(v))) {
238
+ const res = {
239
+ center: [+loc[2], +loc[1]],
240
+ zoom: +loc[0],
241
+ pitch: +(loc[4] || 0)
242
+ };
243
+
244
+ if(map) {
245
+ res.bearing = map.dragRotate.isEnabled() && map.touchZoomRotate.isEnabled() ? +(loc[3] || 0) : map.getBearing();
246
+ }
247
+
248
+ return res;
249
+ }
250
+ else { return null; }
251
+ }
252
+
253
+ /**
254
+ * Extracts from string xyz position
255
+ * @param {string} str The xyz position as hash string
256
+ * @returns {object} { x, y, z }
257
+ * @private
258
+ */
259
+ export function xyzParamToPSVPosition(str) {
260
+ const loc = (str || "").split("/");
261
+ if (loc.length === 3 && !loc.some(v => isNaN(v))) {
262
+ const res = {
263
+ x: +loc[0],
264
+ y: +loc[1],
265
+ z: +loc[2]
266
+ };
267
+
268
+ return res;
269
+ }
270
+ else { return null; }
271
+ }
272
+
273
+ /**
274
+ * Extracts from hash parsed keys all map filters values
275
+ * @param {*} vals Hash keys
276
+ * @returns {object} Map filters
277
+ * @private
278
+ */
279
+ export function paramsToMapFilters(vals) {
280
+ const newMapFilters = {};
281
+ for(let k in MAP_FILTERS_URL2JS) {
282
+ if(vals[k]) {
283
+ newMapFilters[MAP_FILTERS_URL2JS[k]] = vals[k];
284
+ }
285
+ }
286
+ if(newMapFilters.qualityscore) {
287
+ let values = newMapFilters.qualityscore.split("");
288
+ const mapping = {"A": 5, "B": 4, "C": 3, "D": 2, "E": 1};
289
+ newMapFilters.qualityscore = values.map(v => mapping[v]);
290
+ }
291
+ return newMapFilters;
292
+ }
293
+
294
+ /**
295
+ * Change PSV current state based on standardized parameters.
296
+ * @param {Photo} psv The Photo Sphere Viewer component to change.
297
+ * @param {object} params The parameters to apply.
298
+ */
299
+ export function alterPSVState(psv, params) {
300
+ // Change xyz position
301
+ if(params.xyz) {
302
+ psv.addEventListener("picture-loaded", () => {
303
+ const coords = xyzParamToPSVPosition(params.xyz);
304
+ psv.setXYZ(coords.x, coords.y, coords.z);
305
+ }, {once: true});
306
+ }
307
+
308
+ // Change transitionDuration
309
+ let td = params.transitionDuration || params.speed;
310
+ if(td !== undefined) {
311
+ psv.setTransitionDuration(td);
312
+ }
313
+
314
+ // Change pictures navigation mode
315
+ let nav = params.picturesNavigation || params.nav;
316
+ if(["none", "pic", "any", "seq"].includes(nav)) {
317
+ psv.setPicturesNavigation(nav);
318
+ }
319
+ }
320
+
321
+ /**
322
+ * Change MapLibre GL current state based on standardized parameters.
323
+ * @param {Map} map The MapLibre component to change.
324
+ * @param {object} params The parameters to apply.
325
+ */
326
+ export function alterMapState(map, params) {
327
+ // Map position
328
+ const mapOpts = getMapPositionFromString(params.map, map);
329
+ if(mapOpts) {
330
+ map.jumpTo(mapOpts);
331
+ }
332
+
333
+ // Visible users
334
+ let vu = Array.isArray(params.users) ? params.users : (params.users || "").split(",");
335
+ if(vu.length === 0 || (vu.length === 1 && vu[0].trim() === "")) { vu = ["geovisio"]; }
336
+ map.setVisibleUsers(vu);
337
+
338
+ // Change map filters
339
+ map.setFilters?.(paramsToMapFilters(params));
340
+
341
+ // Change map background
342
+ if(["aerial", "streets"].includes(params.background)) {
343
+ map.setBackground(params.background);
344
+ }
345
+ }
346
+
347
+ /**
348
+ * Change PhotoViewer current state based on standardized parameters.
349
+ * @param {PhotoViewer} viewer The PhotoViewer component to change.
350
+ * @param {object} params The parameters to apply.
351
+ */
352
+ export function alterPhotoViewerState(viewer, params) {
353
+ // Restore selected picture
354
+ let pic = params.picture || params.pic;
355
+ if(pic) {
356
+ const picIds = pic.split(";"); // Handle multiple IDs coming from OSM
357
+ if(picIds.length > 1) {
358
+ console.warn("Multiple picture IDs passed in URL, only first one kept");
359
+ }
360
+
361
+ viewer.select(null, picIds[0], true);
362
+ }
363
+ else {
364
+ viewer.select();
365
+ }
366
+ }
367
+
368
+ /**
369
+ * Change Viewer current state based on standardized parameters.
370
+ * @param {Viewer} viewer The Viewer component to change.
371
+ * @param {object} params The parameters to apply.
372
+ */
373
+ export function alterViewerState(viewer, params) {
374
+ alterPhotoViewerState(viewer, params);
375
+
376
+ // Change focus
377
+ if(params.focus === "map" && viewer?.map) {
378
+ viewer.setPopup(false);
379
+ viewer._setFocus("map", null, params.forceFocus);
380
+ }
381
+ else if(params.focus === "pic" && viewer?.mini) {
382
+ viewer.setPopup(false);
383
+ viewer._setFocus("pic", null, params.forceFocus);
384
+ }
385
+ else if(params.focus && params.focus === "meta" && viewer?.mini) {
386
+ viewer._setFocus("pic", null, params.forceFocus);
387
+ }
388
+ }
@@ -2,6 +2,7 @@ import { EquirectangularTilesAdapter } from "@photo-sphere-viewer/equirectangula
2
2
 
3
3
  /**
4
4
  * Override of PSV EquirectangularTilesAdapter for fine-tweaking.
5
+ * @class Panoramax.utils.PhotoAdapter
5
6
  * @private
6
7
  */
7
8
  export default class PhotoAdapter extends EquirectangularTilesAdapter {