@panoramax/web-viewer 3.2.3 → 4.0.0-develop-9f9cf858

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 +56 -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,401 @@
1
+ import URLHandler from "../../src/utils/URLHandler";
2
+
3
+ describe("listenToChanges", () => {
4
+ it("should add event listeners to window, parent, psv, and map", () => {
5
+ window.addEventListener = jest.fn();
6
+ const parent = {
7
+ addEventListener: jest.fn(),
8
+ psv: { addEventListener: jest.fn() },
9
+ map: { on: jest.fn() },
10
+ };
11
+ const urlHandler = new URLHandler(parent);
12
+ urlHandler.listenToChanges();
13
+ expect(window.addEventListener).toHaveBeenCalledWith("popstate", expect.any(Function), false);
14
+ ["focus-changed", "pictures-navigation-changed"].forEach(event => {
15
+ expect(parent.addEventListener).toHaveBeenCalledWith(event, expect.any(Function));
16
+ });
17
+ ["position-updated", "zoom-updated", "view-rotated", "picture-loaded", "transition-duration-changed"].forEach(event => {
18
+ expect(parent.psv.addEventListener).toHaveBeenCalledWith(event, expect.any(Function));
19
+ });
20
+ ["moveend", "zoomend", "boxzoomend", "background-changed", "users-changed", "filters-changed"].forEach(event => {
21
+ expect(parent.map.on).toHaveBeenCalledWith(event, expect.any(Function));
22
+ });
23
+ });
24
+ });
25
+
26
+ describe("nextURLString", () => {
27
+ it("works without any specific values set", () => {
28
+ const v = {
29
+ addEventListener: jest.fn(),
30
+ psv: {
31
+ getPicturesNavigation: () => null,
32
+ getTransitionDuration: () => null,
33
+ getPictureMetadata: () => null,
34
+ getPictureId: () => null,
35
+ },
36
+ };
37
+ const uh = new URLHandler(v);
38
+ expect(uh.nextURLString()).toBe("?");
39
+ });
40
+
41
+ it("works with picture metadata", () => {
42
+ const v = {
43
+ addEventListener: jest.fn(),
44
+ psv: {
45
+ getPicturesNavigation: () => null,
46
+ getTransitionDuration: () => null,
47
+ getPictureMetadata: () => ({}),
48
+ getPictureId: () => "cbfc3add-8173-4464-98c8-de2a43c6a50f",
49
+ },
50
+ };
51
+ const uh = new URLHandler(v);
52
+ uh.currentPSVString = () => "0/1/2";
53
+ expect(uh.nextURLString()).toBe("?pic=cbfc3add-8173-4464-98c8-de2a43c6a50f&xyz=0/1/2");
54
+ });
55
+
56
+ it("works with map started + wide", () => {
57
+ const v = {
58
+ addEventListener: jest.fn(),
59
+ psv: {
60
+ getPicturesNavigation: () => null,
61
+ getTransitionDuration: () => null,
62
+ getPictureMetadata: () => null,
63
+ getPictureId: () => null,
64
+ },
65
+ map: {
66
+ getVisibleUsers: () => ["geovisio"],
67
+ hasTwoBackgrounds: () => false,
68
+ loaded: () => true,
69
+ },
70
+ isMapWide: () => true,
71
+ popup: { hasAttribute: () => false },
72
+ };
73
+ const uh = new URLHandler(v);
74
+ uh.currentMapString = () => "18/0.5/-12";
75
+ expect(uh.nextURLString()).toBe("?focus=map&map=18/0.5/-12");
76
+ });
77
+
78
+ it("works with map + picture wide", () => {
79
+ const v = {
80
+ addEventListener: jest.fn(),
81
+ psv: {
82
+ getPicturesNavigation: () => null,
83
+ getTransitionDuration: () => null,
84
+ getPictureMetadata: () => ({}),
85
+ getPictureId: () => "cbfc3add-8173-4464-98c8-de2a43c6a50f",
86
+ },
87
+ map: {
88
+ getVisibleUsers: () => ["geovisio"],
89
+ hasTwoBackgrounds: () => false,
90
+ loaded: () => true,
91
+ },
92
+ isMapWide: () => false,
93
+ popup: { hasAttribute: () => false },
94
+ };
95
+ const uh = new URLHandler(v);
96
+ uh.currentPSVString = () => "0/1/2";
97
+ uh.currentMapString = () => "18/0.5/-12";
98
+ expect(uh.nextURLString()).toBe("?focus=pic&map=18/0.5/-12&pic=cbfc3add-8173-4464-98c8-de2a43c6a50f&xyz=0/1/2");
99
+ });
100
+
101
+ it("works with map filters", () => {
102
+ const v = {
103
+ addEventListener: jest.fn(),
104
+ psv: {
105
+ getPicturesNavigation: () => null,
106
+ getTransitionDuration: () => null,
107
+ getPictureMetadata: () => null,
108
+ getPictureId: () => null,
109
+ },
110
+ map: {
111
+ getVisibleUsers: () => ["geovisio"],
112
+ hasTwoBackgrounds: () => false,
113
+ loaded: () => true,
114
+ _mapFilters: {
115
+ "minDate": "2023-01-01",
116
+ "maxDate": "2023-08-08",
117
+ "camera": "sony",
118
+ "pic_type": "flat",
119
+ "theme": "age",
120
+ },
121
+ },
122
+ isMapWide: () => false,
123
+ popup: { hasAttribute: () => false },
124
+ };
125
+ const uh = new URLHandler(v);
126
+ uh.currentMapString = () => "18/0.5/-12";
127
+ expect(uh.nextURLString()).toBe("?camera=sony&date_from=2023-01-01&date_to=2023-08-08&focus=pic&map=18/0.5/-12&pic_type=flat&theme=age");
128
+ });
129
+
130
+ it("works with speed", () => {
131
+ const v = {
132
+ addEventListener: jest.fn(),
133
+ psv: {
134
+ getPicturesNavigation: () => null,
135
+ getTransitionDuration: () => 250,
136
+ getPictureMetadata: () => null,
137
+ getPictureId: () => null,
138
+ },
139
+ };
140
+ const uh = new URLHandler(v);
141
+ expect(uh.nextURLString()).toBe("?speed=250");
142
+ });
143
+
144
+ it("works with popup", () => {
145
+ const v = {
146
+ addEventListener: jest.fn(),
147
+ psv: {
148
+ getPicturesNavigation: () => null,
149
+ getTransitionDuration: () => null,
150
+ getPictureMetadata: () => null,
151
+ getPictureId: () => null,
152
+ },
153
+ map: {
154
+ getVisibleUsers: () => ["geovisio"],
155
+ hasTwoBackgrounds: () => false,
156
+ loaded: () => true,
157
+ },
158
+ isMapWide: () => false,
159
+ popup: { hasAttribute: () => true },
160
+ };
161
+ const uh = new URLHandler(v);
162
+ uh.currentMapString = () => "18/0.5/-12";
163
+ expect(uh.nextURLString()).toBe("?focus=pic&map=18/0.5/-12");
164
+ });
165
+
166
+ it("works with nav", () => {
167
+ const v = {
168
+ addEventListener: jest.fn(),
169
+ psv: {
170
+ getPicturesNavigation: () => "pic",
171
+ getTransitionDuration: () => null,
172
+ getPictureMetadata: () => null,
173
+ getPictureId: () => null,
174
+ },
175
+ };
176
+ const uh = new URLHandler(v);
177
+ expect(uh.nextURLString()).toBe("?nav=pic");
178
+ });
179
+ });
180
+
181
+ describe("currentURLParams", () => {
182
+ it("works if empty + search", () => {
183
+ delete window.location;
184
+ window.location = { search: "" };
185
+ const v = { addEventListener: jest.fn() };
186
+ const uh = new URLHandler(v);
187
+ expect(uh.currentURLParams()).toStrictEqual({});
188
+ });
189
+
190
+ it("works with single param + search", () => {
191
+ delete window.location;
192
+ window.location = { search: "?nav=pic" };
193
+ const v = { addEventListener: jest.fn() };
194
+ const uh = new URLHandler(v);
195
+ expect(uh.currentURLParams()).toStrictEqual({"nav": "pic"});
196
+ });
197
+
198
+ it("works with multiple params + search", () => {
199
+ delete window.location;
200
+ window.location = { search: "?nav=pic&speed=42" };
201
+ const v = { addEventListener: jest.fn() };
202
+ const uh = new URLHandler(v);
203
+ expect(uh.currentURLParams()).toStrictEqual({"nav": "pic", "speed": "42"});
204
+ });
205
+
206
+ it("works if empty + hash", () => {
207
+ delete window.location;
208
+ window.location = { hash: "" };
209
+ const v = { addEventListener: jest.fn() };
210
+ const uh = new URLHandler(v);
211
+ expect(uh.currentURLParams(true)).toStrictEqual({});
212
+ });
213
+
214
+ it("works with single param + hash", () => {
215
+ delete window.location;
216
+ window.location = { hash: "#nav=pic" };
217
+ const v = { addEventListener: jest.fn() };
218
+ const uh = new URLHandler(v);
219
+ expect(uh.currentURLParams(true)).toStrictEqual({"nav": "pic"});
220
+ });
221
+
222
+ it("works with multiple params + hash", () => {
223
+ delete window.location;
224
+ window.location = { hash: "#nav=pic&speed=42" };
225
+ const v = { addEventListener: jest.fn() };
226
+ const uh = new URLHandler(v);
227
+ expect(uh.currentURLParams(true)).toStrictEqual({"nav": "pic", "speed": "42"});
228
+ });
229
+
230
+ it("works with search + hash", () => {
231
+ delete window.location;
232
+ window.location = { hash: "#nav=pic&speed=42", search: "?pic=bla" };
233
+ const v = { addEventListener: jest.fn() };
234
+ const uh = new URLHandler(v);
235
+ expect(uh.currentURLParams()).toStrictEqual({"pic": "bla"});
236
+ expect(uh.currentURLParams(true)).toStrictEqual({"nav": "pic", "speed": "42"});
237
+ });
238
+
239
+ it("skips unmanaged parameters", () => {
240
+ delete window.location;
241
+ window.location = { search: "?a=b" };
242
+ const v = { addEventListener: jest.fn() };
243
+ const uh = new URLHandler(v);
244
+ expect(uh.currentURLParams()).toStrictEqual({});
245
+ });
246
+ });
247
+
248
+ describe("currentMapString", () => {
249
+ it("works with zoom+center", () => {
250
+ const v = {
251
+ addEventListener: jest.fn(),
252
+ map: {
253
+ getZoom: () => 18,
254
+ getCenter: () => ({ lng: -12.5, lat: 48.75 }),
255
+ getBearing: () => null,
256
+ getPitch: () => null,
257
+ }
258
+ };
259
+ const uh = new URLHandler(v);
260
+ expect(uh.currentMapString()).toBe("18/48.75/-12.5");
261
+ });
262
+
263
+ it("works with zoom+center+bearing", () => {
264
+ const v = {
265
+ addEventListener: jest.fn(),
266
+ map: {
267
+ getZoom: () => 18,
268
+ getCenter: () => ({ lng: -12.5, lat: 48.75 }),
269
+ getBearing: () => 12,
270
+ getPitch: () => null,
271
+ }
272
+ };
273
+ const uh = new URLHandler(v);
274
+ expect(uh.currentMapString()).toBe("18/48.75/-12.5/12");
275
+ });
276
+
277
+ it("works with zoom+center+pitch", () => {
278
+ const v = {
279
+ addEventListener: jest.fn(),
280
+ map: {
281
+ getZoom: () => 18,
282
+ getCenter: () => ({ lng: -12.5, lat: 48.75 }),
283
+ getBearing: () => null,
284
+ getPitch: () => 65,
285
+ },
286
+ };
287
+ const uh = new URLHandler(v);
288
+ expect(uh.currentMapString()).toBe("18/48.75/-12.5/0/65");
289
+ });
290
+
291
+ it("works with zoom+center+bearing+pitch", () => {
292
+ const v = {
293
+ addEventListener: jest.fn(),
294
+ map: {
295
+ getZoom: () => 18,
296
+ getCenter: () => ({ lng: -12.5, lat: 48.75 }),
297
+ getBearing: () => 42,
298
+ getPitch: () => 65,
299
+ },
300
+ };
301
+ const uh = new URLHandler(v);
302
+ expect(uh.currentMapString()).toBe("18/48.75/-12.5/42/65");
303
+ });
304
+ });
305
+
306
+ describe("currentPSVString", () => {
307
+ it("works", () => {
308
+ const v = {
309
+ addEventListener: jest.fn(),
310
+ psv: {
311
+ getXYZ: () => ({ x: 12, y: 50, z: 75 }),
312
+ },
313
+ };
314
+ const uh = new URLHandler(v);
315
+ expect(uh.currentPSVString()).toBe("12.00/50.00/75");
316
+ });
317
+
318
+ it("rounds to 2 decimals", () => {
319
+ const v = {
320
+ addEventListener: jest.fn(),
321
+ psv: {
322
+ getXYZ: () => ({ x: 12.123456, y: 50.789456, z: 75 }),
323
+ getPictureId: () => null,
324
+ },
325
+ };
326
+ const uh = new URLHandler(v);
327
+ expect(uh.currentPSVString()).toBe("12.12/50.79/75");
328
+ });
329
+
330
+ it("works without z", () => {
331
+ const v = {
332
+ addEventListener: jest.fn(),
333
+ psv: {
334
+ getXYZ: () => ({ x: 12, y: 50 }),
335
+ getPictureId: () => null,
336
+ },
337
+ };
338
+ const uh = new URLHandler(v);
339
+ expect(uh.currentPSVString()).toBe("12.00/50.00/0");
340
+ });
341
+ });
342
+
343
+ describe("_onParentChange", () => {
344
+ it("works", async () => {
345
+ delete window.history;
346
+ delete window.location;
347
+
348
+ window.history = { replaceState: jest.fn(), state: {} };
349
+ window.location = { href: "http://localhost:5000/?nav=pic&speed=2", search: "?nav=pic&speed=2", hash: "" };
350
+
351
+ const v = { addEventListener: jest.fn() };
352
+ const uh = new URLHandler(v);
353
+ uh.nextURLString = () => "?map=1/2/3";
354
+ uh.dispatchEvent = jest.fn();
355
+
356
+ uh._onParentChange();
357
+ await new Promise((r) => setTimeout(r, 1000));
358
+
359
+ expect(window.history.replaceState.mock.calls.pop()).toEqual([{}, null, "http://localhost:5000/?map=1/2/3"]);
360
+ expect(uh.dispatchEvent.mock.calls).toMatchSnapshot();
361
+ });
362
+
363
+ it("works with pic change", async () => {
364
+ delete window.history;
365
+ delete window.location;
366
+
367
+ window.history = { pushState: jest.fn(), state: {} };
368
+ window.location = { href: "http://localhost:5000/?pic=bla", search: "?pic=bla", hash: "" };
369
+
370
+ const v = { addEventListener: jest.fn() };
371
+ const uh = new URLHandler(v);
372
+ uh.nextURLString = () => "?nav=seq";
373
+ uh.dispatchEvent = jest.fn();
374
+
375
+ uh._onParentChange();
376
+ await new Promise((r) => setTimeout(r, 1000));
377
+
378
+ expect(window.history.pushState.mock.calls.pop()).toEqual([{}, null, "http://localhost:5000/?nav=seq"]);
379
+ expect(uh.dispatchEvent.mock.calls).toMatchSnapshot();
380
+ });
381
+
382
+ it("deduplicates calls", async () => {
383
+ delete window.history;
384
+ delete window.location;
385
+
386
+ window.history = { replaceState: jest.fn(), state: {} };
387
+ window.location = { href: "http://localhost:5000/?speed=1&nav=seq", search: "?speed=1&nav=seq", hash: "" };
388
+
389
+ const v = { addEventListener: jest.fn() };
390
+ const uh = new URLHandler(v);
391
+ uh.nextURLString = () => "?map=1/2/3";
392
+
393
+ for(let i=0; i <= 10; i++) {
394
+ uh._onParentChange();
395
+ }
396
+
397
+ await new Promise((r) => setTimeout(r, 1000));
398
+
399
+ expect(window.history.replaceState.mock.calls).toEqual([[{}, null, "http://localhost:5000/?map=1/2/3"]]);
400
+ });
401
+ });
@@ -135,3 +135,13 @@ No direct access to pictures metadata.
135
135
  API doesn't offer a 'data' (application/json) endpoint in its links
136
136
  No way for viewer to access sequences."
137
137
  `;
138
+
139
+ exports[`constructor fails on fetch failure 1`] = `
140
+ Array [
141
+ Array [
142
+ CustomEvent {
143
+ "isTrusted": false,
144
+ },
145
+ ],
146
+ ]
147
+ `;
@@ -0,0 +1,21 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`_onParentChange works 1`] = `
4
+ Array [
5
+ Array [
6
+ CustomEvent {
7
+ "isTrusted": false,
8
+ },
9
+ ],
10
+ ]
11
+ `;
12
+
13
+ exports[`_onParentChange works with pic change 1`] = `
14
+ Array [
15
+ Array [
16
+ CustomEvent {
17
+ "isTrusted": false,
18
+ },
19
+ ],
20
+ ]
21
+ `;
@@ -38,7 +38,7 @@ Object {
38
38
  "lng": -1.7,
39
39
  },
40
40
  },
41
- "place_name": "Paris, Île-de-France, France métropolitaine, France",
41
+ "place_name": "Paris",
42
42
  "place_type": Array [
43
43
  "place",
44
44
  ],
@@ -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 []`;