aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/dumbyUtils.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'src/dumbyUtils.mjs')
-rw-r--r--src/dumbyUtils.mjs46
1 files changed, 15 insertions, 31 deletions
diff --git a/src/dumbyUtils.mjs b/src/dumbyUtils.mjs
index 7b06840..be0da43 100644
--- a/src/dumbyUtils.mjs
+++ b/src/dumbyUtils.mjs
@@ -190,11 +190,14 @@ export const createGeoLink = (link) => {
190 if (link.dataset.valid === 'false') return 190 if (link.dataset.valid === 'false') return
191 191
192 removeLeaderLines(link) 192 removeLeaderLines(link)
193 getMarkersFromMaps(link) 193 getMarkersFromMaps(link).forEach(marker => {
194 .forEach(updateMapCameraByMarker([ 194 const map = marker.closest('.mapclay')
195 map.scrollIntoView({ behavior: 'smooth' })
196 updateMapCameraByMarker([
195 Number(link.dataset.lon), 197 Number(link.dataset.lon),
196 Number(link.dataset.lat), 198 Number(link.dataset.lat),
197 ])) 199 ])(marker)
200 })
198 } 201 }
199 202
200 // Use middle click to remove markers 203 // Use middle click to remove markers
@@ -296,43 +299,24 @@ const isAnchorVisible = anchor => {
296} 299}
297 300
298/** 301/**
299 * addAnchorByPoint. 302 * addMarkerByPoint.
300 * 303 *
301 * @param {point} options.point - object has {x, y} for window coordinates 304 * @param {Number[]} options.point - page XY
302 * @param {HTMLElement} options.map 305 * @param {HTMLElement} options.map
303 * @param {Function} options.validateAnchorName - validate anchor name is OK to use
304 */ 306 */
305export const addAnchorByPoint = ({ 307export const addMarkerByPoint = ({ point, map }) => {
306 defaultName,
307 point,
308 map,
309 validateAnchorName = () => true,
310}) => {
311 const rect = map.getBoundingClientRect() 308 const rect = map.getBoundingClientRect()
312 const [x, y] = map.renderer 309 const [lon, lat] = map.renderer
313 .unproject([point.x - rect.left, point.y - rect.top]) 310 .unproject([point[0] - rect.left, point[1] - rect.top])
314 .map(coord => parseFloat(coord.toFixed(6))) 311 .map(value => parseFloat(value.toFixed(6)))
315
316 let prompt
317 let anchorName
318
319 do {
320 prompt = prompt ? 'Anchor name exists' : 'Name this anchor'
321 anchorName = window.prompt(prompt, defaultName ?? '')
322 }
323 while (anchorName !== null && !validateAnchorName(anchorName))
324 if (anchorName === null) return
325
326 const desc = window.prompt('Description', anchorName) ?? anchorName
327 312
328 const link = `geo:${y},${x}?xy=${x},${y}&id=${map.id}&type=circle`
329 const marker = map.renderer.addMarker({ 313 const marker = map.renderer.addMarker({
330 xy: [x, y], 314 xy: [lon, lat],
331 type: 'circle', 315 type: 'circle',
332 }) 316 })
333 marker.dataset.xy = `${x},${y}` 317 marker.dataset.xy = `${lon},${lat}`
334 318
335 return { ref: anchorName, link, title: desc } 319 return marker
336} 320}
337 321
338/** 322/**