diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2024-10-05 17:00:12 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2024-10-05 18:58:23 +0800 |
commit | b073e583c0f35d1676c8f8fc4e786925ef58123d (patch) | |
tree | 7494e747fe630ae9b2dce3623314d2a31a1c88d1 /src/MenuItem.mjs | |
parent | 9d88ee357060abe90c85c4ade5fca61592c0f032 (diff) |
feat: add menu items for map managing
Diffstat (limited to 'src/MenuItem.mjs')
-rw-r--r-- | src/MenuItem.mjs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/MenuItem.mjs b/src/MenuItem.mjs index dbe984f..138b317 100644 --- a/src/MenuItem.mjs +++ b/src/MenuItem.mjs | |||
@@ -343,8 +343,30 @@ export const toggleMapFocus = map => | |||
343 | onclick: () => map.classList.toggle('focus') | 343 | onclick: () => map.classList.toggle('focus') |
344 | }) | 344 | }) |
345 | 345 | ||
346 | /** | ||
347 | * getCoordinatesByPixels. | ||
348 | * | ||
349 | * @param {HTMLElement} map instance | ||
350 | * @param {Number[]} xy -- pixel of window | ||
351 | */ | ||
346 | export const getCoordinatesByPixels = (map, xy) => | 352 | export const getCoordinatesByPixels = (map, xy) => |
347 | new Item({ | 353 | new Item({ |
348 | text: 'Get Coordinates', | 354 | text: 'Get Coordinates', |
349 | onclick: () => console.log(map.renderer.unproject(xy)) | 355 | onclick: () => { |
356 | const [x, y] = map.renderer.unproject(xy) | ||
357 | const xyString = `[${x.toFixed(7)}, ${y.toFixed(7)}]` | ||
358 | navigator.clipboard.writeText(xyString) | ||
359 | window.alert(`${xyString} copied to clipboard`) | ||
360 | } | ||
361 | }) | ||
362 | |||
363 | /** | ||
364 | * restoreCamera. | ||
365 | * | ||
366 | * @param {HTMLElement} map | ||
367 | */ | ||
368 | export const restoreCamera = map => | ||
369 | new Item({ | ||
370 | text: 'Restore Camera', | ||
371 | onclick: () => map.renderer.restoreCamera() | ||
350 | }) | 372 | }) |