aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-10-28 10:42:46 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-10-28 12:24:12 +0800
commit65680175fc04e71b362458745727974af73f711c (patch)
tree2d1981658283457fab941af73c39bbdb5b79e378
parent42136919f1e5ffe31b2c783e30a121741deac49d (diff)
feat: set marker title by textContent or option
-rw-r--r--src/Link.mjs6
-rw-r--r--src/MenuItem.mjs2
-rw-r--r--src/dumbyUtils.mjs3
3 files changed, 4 insertions, 7 deletions
diff --git a/src/Link.mjs b/src/Link.mjs
index 9c73918..7947152 100644
--- a/src/Link.mjs
+++ b/src/Link.mjs
@@ -133,11 +133,7 @@ export const getMarkersFromMaps = (link) => {
133 size: svg.size, 133 size: svg.size,
134 }) 134 })
135 marker.dataset.xy = lonLat 135 marker.dataset.xy = lonLat
136 marker.title = new URLSearchParams(link.search).get('xy') ?? lonLat 136 marker.title = link.textContent
137 const crs = link.dataset.crs
138 if (crs && crs !== 'EPSG:4326') {
139 marker.title += '@' + link.dataset.crs
140 }
141 137
142 return marker 138 return marker
143 }) 139 })
diff --git a/src/MenuItem.mjs b/src/MenuItem.mjs
index 11ce4be..d9645f7 100644
--- a/src/MenuItem.mjs
+++ b/src/MenuItem.mjs
@@ -519,7 +519,7 @@ export const addMarker = ({
519 } while (markerName && !isNameValid(markerName)) 519 } while (markerName && !isNameValid(markerName))
520 if (markerName === null) return 520 if (markerName === null) return
521 521
522 const marker = addMarkerByPoint({ point, map }) 522 const marker = addMarkerByPoint({ point, map, title: markerName })
523 callback?.(marker) 523 callback?.(marker)
524 }, 524 },
525}) 525})
diff --git a/src/dumbyUtils.mjs b/src/dumbyUtils.mjs
index 1993b02..c4f8d74 100644
--- a/src/dumbyUtils.mjs
+++ b/src/dumbyUtils.mjs
@@ -92,7 +92,7 @@ export function removeBlockFocus () {
92 * @param {Number[]} options.point - page XY 92 * @param {Number[]} options.point - page XY
93 * @param {HTMLElement} options.map 93 * @param {HTMLElement} options.map
94 */ 94 */
95export const addMarkerByPoint = ({ point, map }) => { 95export const addMarkerByPoint = ({ point, map, title }) => {
96 const rect = map.getBoundingClientRect() 96 const rect = map.getBoundingClientRect()
97 const [lon, lat] = map.renderer 97 const [lon, lat] = map.renderer
98 .unproject([point[0] - rect.left, point[1] - rect.top]) 98 .unproject([point[0] - rect.left, point[1] - rect.top])
@@ -102,6 +102,7 @@ export const addMarkerByPoint = ({ point, map }) => {
102 xy: [lon, lat], 102 xy: [lon, lat],
103 }) 103 })
104 marker.dataset.xy = `${lon},${lat}` 104 marker.dataset.xy = `${lon},${lat}`
105 if (title) marker.title = title
105 106
106 return marker 107 return marker
107} 108}