diff options
-rw-r--r-- | src/editor.mjs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/editor.mjs b/src/editor.mjs index 1b31535..d7ae7fe 100644 --- a/src/editor.mjs +++ b/src/editor.mjs | |||
@@ -237,6 +237,7 @@ if (contentFromHash) { | |||
237 | editor.cleanup() | 237 | editor.cleanup() |
238 | editor.value(contentFromHash) | 238 | editor.value(contentFromHash) |
239 | } | 239 | } |
240 | |||
240 | // }}} | 241 | // }}} |
241 | // Set up logic about editor content {{{ | 242 | // Set up logic about editor content {{{ |
242 | 243 | ||
@@ -411,6 +412,32 @@ const menuForEditor = (event, menu) => { | |||
411 | menu.appendChild(switchToEditingMode) | 412 | menu.appendChild(switchToEditingMode) |
412 | } | 413 | } |
413 | 414 | ||
415 | const map = dumbyContainer.querySelector('#' + menu.dataset.map) | ||
416 | if (map) { | ||
417 | const item = new Item({ | ||
418 | text: 'Add Anchor for GeoLinks', | ||
419 | onclick: () => { | ||
420 | const rect = map.getBoundingClientRect() | ||
421 | const [x, y] = map.renderer | ||
422 | .unproject([event.x - rect.left, event.y - rect.top]) | ||
423 | .map(coord => coord.toFixed(7)) | ||
424 | |||
425 | let prompt | ||
426 | let anchorName | ||
427 | let link | ||
428 | do { | ||
429 | prompt = prompt ? 'Anchor name exists' : 'Name this anchor' | ||
430 | anchorName = window.prompt(prompt, `${x}, ${y}`) | ||
431 | link = `geo:${y},${x}?xy=${x},${y}&id=${map.id} "${anchorName}"` | ||
432 | } | ||
433 | while (refLinks.find(({ref}) => ref === anchorName)) | ||
434 | |||
435 | cm.replaceRange(`\n[${anchorName}]: ${link}`, { line: Infinity }) | ||
436 | } | ||
437 | }) | ||
438 | menu.insertBefore(item, menu.firstChild) | ||
439 | } | ||
440 | |||
414 | // Prevent menu appears outside of window | 441 | // Prevent menu appears outside of window |
415 | menu.style.transform = '' | 442 | menu.style.transform = '' |
416 | shiftByWindow(menu) | 443 | shiftByWindow(menu) |