@panoramax/web-viewer 4.0.1 → 4.0.2

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 (51) hide show
  1. package/CHANGELOG.md +26 -3
  2. package/build/index.css +1 -1
  3. package/build/index.css.map +1 -1
  4. package/build/index.js +150 -51
  5. package/build/index.js.map +1 -1
  6. package/config/jest/mocks.js +2 -1
  7. package/docs/03_URL_settings.md +1 -1
  8. package/docs/09_Develop.md +5 -1
  9. package/docs/reference/components/ui/CopyButton.md +1 -0
  10. package/docs/reference/components/ui/Map.md +13 -0
  11. package/docs/reference/components/ui/MapMore.md +13 -0
  12. package/docs/reference/components/ui/Photo.md +1 -1
  13. package/docs/reference/components/ui/widgets/CopyCoordinates.md +32 -0
  14. package/docs/reference/utils/API.md +1 -1
  15. package/docs/reference.md +1 -0
  16. package/docs/tutorials/migrate_v4.md +1 -1
  17. package/docs/tutorials/synced_coverage.md +1 -1
  18. package/mkdocs.yml +1 -0
  19. package/package.json +1 -1
  20. package/src/components/core/CoverageMap.js +2 -2
  21. package/src/components/core/PhotoViewer.js +5 -1
  22. package/src/components/core/Viewer.js +9 -4
  23. package/src/components/menus/PictureLegend.js +7 -4
  24. package/src/components/menus/PictureMetadata.js +23 -2
  25. package/src/components/styles.js +61 -0
  26. package/src/components/ui/ButtonGroup.css +2 -0
  27. package/src/components/ui/CopyButton.js +3 -1
  28. package/src/components/ui/Map.js +35 -4
  29. package/src/components/ui/Photo.js +4 -2
  30. package/src/components/ui/TogglableGroup.js +1 -1
  31. package/src/components/ui/widgets/CopyCoordinates.js +75 -0
  32. package/src/components/ui/widgets/Legend.js +1 -1
  33. package/src/components/ui/widgets/OSMEditors.js +2 -2
  34. package/src/components/ui/widgets/PictureLegendActions.js +1 -1
  35. package/src/components/ui/widgets/Player.js +1 -0
  36. package/src/components/ui/widgets/index.js +1 -0
  37. package/src/translations/en.json +6 -2
  38. package/src/translations/fr.json +6 -2
  39. package/src/translations/it.json +3 -1
  40. package/src/translations/ti.json +9 -0
  41. package/src/utils/API.js +1 -1
  42. package/src/utils/InitParameters.js +2 -2
  43. package/src/utils/geocoder.js +5 -3
  44. package/src/utils/index.js +2 -1
  45. package/src/utils/picture.js +6 -1
  46. package/src/utils/services.js +57 -0
  47. package/src/utils/utils.js +18 -5
  48. package/tests/components/ui/Map.test.js +7 -3
  49. package/tests/utils/InitParameters.test.js +15 -15
  50. package/tests/utils/geocoder.test.js +1 -1
  51. package/tests/utils/utils.test.js +136 -109
@@ -8,18 +8,18 @@ jest.mock("../../src/utils/map", () => ({
8
8
 
9
9
  describe("getGrade", () => {
10
10
  it("works with null-like", () => {
11
- expect(utils.getGrade(utils.QUALITYSCORE_RES_FLAT_VALUES, null)).toBeNull();
12
- expect(utils.getGrade(utils.QUALITYSCORE_RES_FLAT_VALUES, undefined)).toBeNull();
13
- expect(utils.getGrade(utils.QUALITYSCORE_RES_FLAT_VALUES, "")).toBeNull();
14
- });
11
+ expect(utils.getGrade(utils.QUALITYSCORE_RES_FLAT_VALUES, null)).toBeNull();
12
+ expect(utils.getGrade(utils.QUALITYSCORE_RES_FLAT_VALUES, undefined)).toBeNull();
13
+ expect(utils.getGrade(utils.QUALITYSCORE_RES_FLAT_VALUES, "")).toBeNull();
14
+ });
15
15
 
16
16
  it("works with grade values", () => {
17
- expect(utils.getGrade(utils.QUALITYSCORE_RES_FLAT_VALUES, 0)).toBe(1);
18
- expect(utils.getGrade(utils.QUALITYSCORE_RES_FLAT_VALUES, 5)).toBe(1);
19
- expect(utils.getGrade(utils.QUALITYSCORE_RES_FLAT_VALUES, 12)).toBe(2);
20
- expect(utils.getGrade(utils.QUALITYSCORE_RES_FLAT_VALUES, 25)).toBe(3);
21
- expect(utils.getGrade(utils.QUALITYSCORE_RES_FLAT_VALUES, 40)).toBe(4);
22
- });
17
+ expect(utils.getGrade(utils.QUALITYSCORE_RES_FLAT_VALUES, 0)).toBe(1);
18
+ expect(utils.getGrade(utils.QUALITYSCORE_RES_FLAT_VALUES, 5)).toBe(1);
19
+ expect(utils.getGrade(utils.QUALITYSCORE_RES_FLAT_VALUES, 12)).toBe(2);
20
+ expect(utils.getGrade(utils.QUALITYSCORE_RES_FLAT_VALUES, 25)).toBe(3);
21
+ expect(utils.getGrade(utils.QUALITYSCORE_RES_FLAT_VALUES, 40)).toBe(4);
22
+ });
23
23
  });
24
24
 
25
25
  describe("getDistance", () => {
@@ -32,25 +32,25 @@ describe("getDistance", () => {
32
32
  });
33
33
 
34
34
  describe("svgToPSVLink", () => {
35
- it("works", () => {
36
- const base64Svg = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnPjxjaXJjbGUgY3g9JzUnIGN5PSc1JyByPSc1JyBmaWxsPScjMDAwJy8+PC9zdmc+";
37
- const fillColor = "red";
38
- const result = utils.svgToPSVLink(base64Svg, fillColor);
39
-
40
- expect(result).toBeInstanceOf(HTMLButtonElement);
41
- expect(result.classList.contains("pnx-psv-tour-arrows")).toBe(true);
42
- expect(result.style.color).toBe(fillColor);
43
- expect(result.querySelector("svg")).not.toBeNull();
44
- });
45
-
46
- it("works with invalid input", () => {
47
- const invalidBase64Svg = "http://test.net/invalid_string";
48
- const result = utils.svgToPSVLink(invalidBase64Svg, "blue");
49
-
50
- expect(result).toBeInstanceOf(HTMLImageElement);
51
- expect(result.src).toBe(invalidBase64Svg);
52
- expect(result.alt).toBe("");
53
- });
35
+ it("works", () => {
36
+ const base64Svg = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnPjxjaXJjbGUgY3g9JzUnIGN5PSc1JyByPSc1JyBmaWxsPScjMDAwJy8+PC9zdmc+";
37
+ const fillColor = "red";
38
+ const result = utils.svgToPSVLink(base64Svg, fillColor);
39
+
40
+ expect(result).toBeInstanceOf(HTMLButtonElement);
41
+ expect(result.classList.contains("pnx-psv-tour-arrows")).toBe(true);
42
+ expect(result.style.color).toBe(fillColor);
43
+ expect(result.querySelector("svg")).not.toBeNull();
44
+ });
45
+
46
+ it("works with invalid input", () => {
47
+ const invalidBase64Svg = "http://test.net/invalid_string";
48
+ const result = utils.svgToPSVLink(invalidBase64Svg, "blue");
49
+
50
+ expect(result).toBeInstanceOf(HTMLImageElement);
51
+ expect(result.src).toBe(invalidBase64Svg);
52
+ expect(result.alt).toBe("");
53
+ });
54
54
  });
55
55
 
56
56
  describe("getAzimuth", () => {
@@ -197,92 +197,119 @@ describe("xyzToPosition", () => {
197
197
  });
198
198
  });
199
199
 
200
+ describe("degToDms", () => {
201
+ it("converts positive decimal degrees to DMS correctly", () => {
202
+ const result = utils.degToDms(45.7896541);
203
+ expect(result).toEqual({ d: 45, m: 47, s: 22.755 });
204
+ });
205
+
206
+ it("converts negative decimal degrees to DMS correctly 1", () => {
207
+ const result = utils.degToDms(-12.751234);
208
+ expect(result).toEqual({ d: -12, m: 45, s: 4.442 });
209
+ });
210
+
211
+ it("converts negative decimal degrees to DMS correctly 2", () => {
212
+ const result = utils.degToDms(-21.007598);
213
+ expect(result).toEqual({ d: -21, m: 0, s: 27.353 });
214
+ });
215
+
216
+ it("converts zero degrees to DMS correctly", () => {
217
+ const result = utils.degToDms(0);
218
+ expect(result).toEqual({ d: 0, m: 0, s: 0 });
219
+ });
220
+
221
+ it("handles integer degrees correctly", () => {
222
+ const result = utils.degToDms(90);
223
+ expect(result).toEqual({ d: 90, m: 0, s: 0 });
224
+ });
225
+ });
226
+
200
227
  describe("josmBboxParameters", () => {
201
228
  it("works with null-like", () => {
202
- expect(utils.josmBboxParameters(null)).toBeNull();
203
- expect(utils.josmBboxParameters(undefined)).toBeNull();
204
- });
205
-
206
- it("works without azimuth", () => {
207
- const meta = { gps: [2.3522, 48.8566] };
208
- const result = utils.josmBboxParameters(meta);
209
- expect(result).toBe("left=2.3522&right=2.3522&top=48.8566&bottom=48.8566&changeset_source=Panoramax");
210
- });
211
-
212
- it("works with azimuth = 0", () => {
213
- const meta = { gps: [2.3522, 48.8566], properties: { "view:azimuth": 0 } };
214
- const result = utils.josmBboxParameters(meta);
215
- expect(result).toBe("left=2.3522&right=2.3524&top=48.8568&bottom=48.8566&changeset_source=Panoramax");
216
- });
217
-
218
- it("works with azimuth = 180", () => {
219
- const meta = { gps: [2.3522, 48.8566], properties: { "view:azimuth": 180 } };
220
- const result = utils.josmBboxParameters(meta);
221
- expect(result).toBe("left=2.352&right=2.3524&top=48.8566&bottom=48.8564&changeset_source=Panoramax");
222
- });
223
-
224
- it("works with azimuth = 90", () => {
225
- const meta = { gps: [2.3522, 48.8566], properties: { "view:azimuth": 90 } };
226
- const result = utils.josmBboxParameters(meta);
227
- expect(result).toBe("left=2.3522&right=2.3524&top=48.8568&bottom=48.8564&changeset_source=Panoramax");
228
- });
229
-
230
- it("works with azimuth = 270", () => {
231
- const meta = { gps: [2.3522, 48.8566], properties: { "view:azimuth": 270 } };
232
- const result = utils.josmBboxParameters(meta);
233
- expect(result).toBe("left=2.352&right=2.3522&top=48.8568&bottom=48.8564&changeset_source=Panoramax");
234
- });
229
+ expect(utils.josmBboxParameters(null)).toBeNull();
230
+ expect(utils.josmBboxParameters(undefined)).toBeNull();
231
+ });
232
+
233
+ it("works without azimuth", () => {
234
+ const meta = { gps: [2.3522, 48.8566] };
235
+ const result = utils.josmBboxParameters(meta);
236
+ expect(result).toBe("left=2.3522&right=2.3522&top=48.8566&bottom=48.8566&changeset_source=Panoramax");
237
+ });
238
+
239
+ it("works with azimuth = 0", () => {
240
+ const meta = { gps: [2.3522, 48.8566], properties: { "view:azimuth": 0 } };
241
+ const result = utils.josmBboxParameters(meta);
242
+ expect(result).toBe("left=2.3522&right=2.3524&top=48.8568&bottom=48.8566&changeset_source=Panoramax");
243
+ });
244
+
245
+ it("works with azimuth = 180", () => {
246
+ const meta = { gps: [2.3522, 48.8566], properties: { "view:azimuth": 180 } };
247
+ const result = utils.josmBboxParameters(meta);
248
+ expect(result).toBe("left=2.352&right=2.3524&top=48.8566&bottom=48.8564&changeset_source=Panoramax");
249
+ });
250
+
251
+ it("works with azimuth = 90", () => {
252
+ const meta = { gps: [2.3522, 48.8566], properties: { "view:azimuth": 90 } };
253
+ const result = utils.josmBboxParameters(meta);
254
+ expect(result).toBe("left=2.3522&right=2.3524&top=48.8568&bottom=48.8564&changeset_source=Panoramax");
255
+ });
256
+
257
+ it("works with azimuth = 270", () => {
258
+ const meta = { gps: [2.3522, 48.8566], properties: { "view:azimuth": 270 } };
259
+ const result = utils.josmBboxParameters(meta);
260
+ expect(result).toBe("left=2.352&right=2.3522&top=48.8568&bottom=48.8564&changeset_source=Panoramax");
261
+ });
235
262
  });
236
263
 
237
264
  describe("getCookie", () => {
238
- it("should return the value of the specified cookie", () => {
239
- jest.spyOn(document, "cookie", "get").mockReturnValueOnce("session=abc123");
240
- expect(utils.getCookie("session")).toBe("abc123");
241
- });
242
-
243
- it("should return null if the cookie is not found", () => {
244
- jest.spyOn(document, "cookie", "get").mockReturnValueOnce("session=abc123");
245
- expect(utils.getCookie("user_id")).toBeUndefined();
246
- });
247
-
248
- it("should return the correct value when multiple cookies are set", () => {
249
- jest.spyOn(document, "cookie", "get").mockReturnValueOnce("session=abc123; user_id=789; user_name=John");
250
- expect(utils.getCookie("user_id")).toBe("789");
251
- });
252
-
253
- it("should return null if cookie with the specified name has no value", () => {
254
- jest.spyOn(document, "cookie", "get").mockReturnValueOnce("session=; user_id=789");
255
- expect(utils.getCookie("session")).toBe("");
256
- });
257
-
258
- it("should return the correct value when the cookie contains =", () => {
259
- jest.spyOn(document, "cookie", "get").mockReturnValueOnce("custom_cookie=abc=123");
260
- expect(utils.getCookie("custom_cookie")).toBe("abc=123");
261
- });
265
+ it("should return the value of the specified cookie", () => {
266
+ jest.spyOn(document, "cookie", "get").mockReturnValueOnce("session=abc123");
267
+ expect(utils.getCookie("session")).toBe("abc123");
268
+ });
269
+
270
+ it("should return null if the cookie is not found", () => {
271
+ jest.spyOn(document, "cookie", "get").mockReturnValueOnce("session=abc123");
272
+ expect(utils.getCookie("user_id")).toBeUndefined();
273
+ });
274
+
275
+ it("should return the correct value when multiple cookies are set", () => {
276
+ jest.spyOn(document, "cookie", "get").mockReturnValueOnce("session=abc123; user_id=789; user_name=John");
277
+ expect(utils.getCookie("user_id")).toBe("789");
278
+ });
279
+
280
+ it("should return null if cookie with the specified name has no value", () => {
281
+ jest.spyOn(document, "cookie", "get").mockReturnValueOnce("session=; user_id=789");
282
+ expect(utils.getCookie("session")).toBe("");
283
+ });
284
+
285
+ it("should return the correct value when the cookie contains =", () => {
286
+ jest.spyOn(document, "cookie", "get").mockReturnValueOnce("custom_cookie=abc=123");
287
+ expect(utils.getCookie("custom_cookie")).toBe("abc=123");
288
+ });
262
289
  });
263
290
 
264
291
  describe("getUserAccount", () => {
265
- it("should return an object with user id and name when all cookies are present", () => {
266
- jest.spyOn(document, "cookie", "get").mockReturnValue("session=abc123; user_id=789; user_name=John");
267
- expect(utils.getUserAccount()).toEqual({ id: "789", name: "John" });
268
- });
269
-
270
- it("should return null if session cookie is missing", () => {
271
- jest.spyOn(document, "cookie", "get").mockReturnValue("user_id=789; user_name=John");
272
- expect(utils.getUserAccount()).toBeNull();
273
- });
274
-
275
- it("should return null if user_id cookie is missing", () => {
276
- jest.spyOn(document, "cookie", "get").mockReturnValue("session=abc123; user_name=John");
277
- expect(utils.getUserAccount()).toBeNull();
278
- });
279
-
280
- it("should return null if user_name cookie is missing", () => {
281
- jest.spyOn(document, "cookie", "get").mockReturnValue("session=abc123; user_id=789");
282
- expect(utils.getUserAccount()).toBeNull();
283
- });
284
-
285
- it("should return null if all cookies are missing", () => {
286
- expect(utils.getUserAccount()).toBeNull();
287
- });
292
+ it("should return an object with user id and name when all cookies are present", () => {
293
+ jest.spyOn(document, "cookie", "get").mockReturnValue("session=abc123; user_id=789; user_name=John");
294
+ expect(utils.getUserAccount()).toEqual({ id: "789", name: "John" });
295
+ });
296
+
297
+ it("should return null if session cookie is missing", () => {
298
+ jest.spyOn(document, "cookie", "get").mockReturnValue("user_id=789; user_name=John");
299
+ expect(utils.getUserAccount()).toBeNull();
300
+ });
301
+
302
+ it("should return null if user_id cookie is missing", () => {
303
+ jest.spyOn(document, "cookie", "get").mockReturnValue("session=abc123; user_name=John");
304
+ expect(utils.getUserAccount()).toBeNull();
305
+ });
306
+
307
+ it("should return null if user_name cookie is missing", () => {
308
+ jest.spyOn(document, "cookie", "get").mockReturnValue("session=abc123; user_id=789");
309
+ expect(utils.getUserAccount()).toBeNull();
310
+ });
311
+
312
+ it("should return null if all cookies are missing", () => {
313
+ expect(utils.getUserAccount()).toBeNull();
314
+ });
288
315
  });