diff options
Diffstat (limited to 'src/editor.mjs')
-rw-r--r-- | src/editor.mjs | 33 |
1 files changed, 6 insertions, 27 deletions
diff --git a/src/editor.mjs b/src/editor.mjs index 32929ea..297d75a 100644 --- a/src/editor.mjs +++ b/src/editor.mjs | |||
@@ -1,8 +1,8 @@ | |||
1 | /*global EasyMDE*/ | 1 | /*global EasyMDE*/ |
2 | /*eslint no-undef: "error"*/ | 2 | /*eslint no-undef: "error"*/ |
3 | import { markdown2HTML, generateMaps, createGeoLink } from './dumbymap' | 3 | import { markdown2HTML, generateMaps } from './dumbymap' |
4 | import { defaultAliases, parseConfigsFromYaml } from 'mapclay' | 4 | import { defaultAliases, parseConfigsFromYaml } from 'mapclay' |
5 | import { Suggestion } from './MenuItem' | 5 | import { GeoLink, Suggestion } from './MenuItem' |
6 | 6 | ||
7 | // Set up Containers {{{ | 7 | // Set up Containers {{{ |
8 | 8 | ||
@@ -157,7 +157,7 @@ const debounceForMap = (() => { | |||
157 | let timer = null; | 157 | let timer = null; |
158 | 158 | ||
159 | return function(...args) { | 159 | return function(...args) { |
160 | dumbymap = generateMaps.apply(this, args) | 160 | dumbymap = generateMaps.apply(this, args) |
161 | // clearTimeout(timer); | 161 | // clearTimeout(timer); |
162 | // timer = setTimeout(() => { | 162 | // timer = setTimeout(() => { |
163 | // dumbymap = generateMaps.apply(this, args) | 163 | // dumbymap = generateMaps.apply(this, args) |
@@ -576,36 +576,15 @@ layoutObserver.observe(HtmlContainer, { | |||
576 | }); | 576 | }); |
577 | // }}} | 577 | // }}} |
578 | // ContextMenu {{{ | 578 | // ContextMenu {{{ |
579 | const addGeoLinkbyRange = (range) => { | ||
580 | const content = range.toString() | ||
581 | const match = content.match(/(^\D*[\d\.]+)\D+([\d\.]+)\D*$/) | ||
582 | // TODO add more suggestion | ||
583 | if (!match) return false | ||
584 | |||
585 | const [x, y] = match.slice(1) | ||
586 | const anchor = document.createElement('a') | ||
587 | anchor.textContent = content | ||
588 | // FIXME apply WGS84 | ||
589 | anchor.href = `geo:${y},${x}?xy=${x},${y}` | ||
590 | |||
591 | if (createGeoLink(anchor)) { | ||
592 | range.deleteContents() | ||
593 | range.insertNode(anchor) | ||
594 | } | ||
595 | |||
596 | } | ||
597 | document.oncontextmenu = (e) => { | 579 | document.oncontextmenu = (e) => { |
598 | const selection = document.getSelection() | 580 | const selection = document.getSelection() |
599 | const range = selection.getRangeAt(0) | 581 | const range = selection.getRangeAt(0) |
600 | if (!cm.hasFocus() && selection) { | 582 | if (!cm.hasFocus() && selection) { |
601 | e.preventDefault() | 583 | e.preventDefault() |
602 | menu.innerHTML = '' | 584 | menu.innerHTML = '' |
603 | menu.style.cssText = `display: block; left: ${e.clientX + 10}px; top: ${e.clientY + 5}px; width: 100px; height: 100px;` | 585 | menu.style.cssText = `display: block; left: ${e.clientX + 10}px; top: ${e.clientY + 5}px;` |
604 | menu.innerHTML = '<div style="cursor: pointer;">Create Geo-Link</div>' | 586 | const addGeoLink = new GeoLink({ range }) |
605 | menu.firstChild.onclick = () => { | 587 | menu.appendChild(addGeoLink.createElement()) |
606 | // menu.style.display = 'none' | ||
607 | addGeoLinkbyRange(range) | ||
608 | } | ||
609 | } | 588 | } |
610 | } | 589 | } |
611 | 590 | ||