diff options
Diffstat (limited to 'src/dumbymap.mjs')
-rw-r--r-- | src/dumbymap.mjs | 53 |
1 files changed, 6 insertions, 47 deletions
diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs index e9cb473..2879319 100644 --- a/src/dumbymap.mjs +++ b/src/dumbymap.mjs | |||
@@ -11,7 +11,6 @@ import * as menuItem from './MenuItem' | |||
11 | import PlainModal from 'plain-modal' | 11 | import PlainModal from 'plain-modal' |
12 | import proj4 from 'proj4' | 12 | import proj4 from 'proj4' |
13 | import { register, fromEPSGCode } from 'ol/proj/proj4' | 13 | import { register, fromEPSGCode } from 'ol/proj/proj4' |
14 | import LeaderLine from 'leader-line' | ||
15 | 14 | ||
16 | /** CSS Selector for main components */ | 15 | /** CSS Selector for main components */ |
17 | const mapBlockSelector = 'pre:has(.language-map), .mapclay-container' | 16 | const mapBlockSelector = 'pre:has(.language-map), .mapclay-container' |
@@ -606,62 +605,22 @@ export const generateMaps = (container, { | |||
606 | const mouseInRange = e.clientX < rect.right && e.clientX > rect.left && e.clientY < rect.bottom && e.clientY > rect.top | 605 | const mouseInRange = e.clientX < rect.right && e.clientX > rect.left && e.clientY < rect.bottom && e.clientY > rect.top |
607 | if (!mouseInRange) return | 606 | if (!mouseInRange) return |
608 | 607 | ||
609 | // link placeholder when dragging | 608 | const timer = setTimeout(() => { |
610 | container.classList.add('dragging-geolink') | 609 | utils.dragForAnchor(container, range, pointByArrow) |
611 | const geoLink = document.createElement('a') | 610 | }, 300) |
612 | geoLink.textContent = range.toString() | ||
613 | geoLink.classList.add('with-leader-line', 'geolink', 'drag') | ||
614 | |||
615 | // Replace current content with link | ||
616 | const originContent = range.cloneContents() | ||
617 | const resumeContent = () => { | ||
618 | range.deleteContents() | ||
619 | range.insertNode(originContent) | ||
620 | } | ||
621 | range.deleteContents() | ||
622 | range.insertNode(geoLink) | ||
623 | |||
624 | // Add leader-line | ||
625 | const line = new LeaderLine({ | ||
626 | start: geoLink, | ||
627 | end: pointByArrow, | ||
628 | path: 'magnet', | ||
629 | }) | ||
630 | 611 | ||
631 | // Update leader-line with mouse move | 612 | // Update leader-line with mouse move |
632 | container.onmousemove = (event) => { | 613 | container.onmousemove = (event) => { |
633 | const rect = container.getBoundingClientRect() | 614 | const rect = container.getBoundingClientRect() |
634 | pointByArrow.style.left = `${event.clientX - rect.left}px` | 615 | pointByArrow.style.left = `${event.clientX - rect.left}px` |
635 | pointByArrow.style.top = `${event.clientY - rect.top}px` | 616 | pointByArrow.style.top = `${event.clientY - rect.top}px` |
636 | line.position() | ||
637 | |||
638 | // TODO Scroll dumbymap.htmlHolder when cursor is at upper/lower side | 617 | // TODO Scroll dumbymap.htmlHolder when cursor is at upper/lower side |
639 | } | 618 | } |
640 | container.onmousemove(e) | 619 | container.onmousemove(e) |
641 | 620 | container.onmouseup = () => { | |
642 | // Handler for dragend | 621 | clearTimeout(timer) |
643 | container.onmouseup = (e) => { | ||
644 | container.classList.remove('dragging-geolink') | ||
645 | container.onmousemove = null | ||
646 | container.onmouseup = null | 622 | container.onmouseup = null |
647 | geoLink.classList.remove('drag') | 623 | container.onmousemove = null |
648 | line.remove() | ||
649 | |||
650 | const map = document.elementFromPoint(e.clientX, e.clientY) | ||
651 | .closest('.mapclay[data-render="fulfilled"]') | ||
652 | if (!map) { | ||
653 | resumeContent() | ||
654 | return | ||
655 | } | ||
656 | |||
657 | const marker = utils.addMarkerByPoint({ point: [e.clientX, e.clientY], map }) | ||
658 | if (!marker) { | ||
659 | resumeContent() | ||
660 | return | ||
661 | } | ||
662 | |||
663 | geoLink.href = `geo:${marker.dataset.xy.split(',').reverse()}` | ||
664 | utils.createGeoLink(geoLink) | ||
665 | } | 624 | } |
666 | } | 625 | } |
667 | 626 | ||