diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/dumbyUtils.mjs | 64 | ||||
| -rw-r--r-- | src/dumbymap.mjs | 53 |
2 files changed, 70 insertions, 47 deletions
diff --git a/src/dumbyUtils.mjs b/src/dumbyUtils.mjs index be0da43..b73f5cd 100644 --- a/src/dumbyUtils.mjs +++ b/src/dumbyUtils.mjs | |||
| @@ -367,3 +367,67 @@ export const setGeoSchemeByCRS = (crs) => (link) => { | |||
| 367 | 367 | ||
| 368 | return link | 368 | return link |
| 369 | } | 369 | } |
| 370 | |||
| 371 | /** | ||
| 372 | * dragForAnchor. | ||
| 373 | * | ||
| 374 | * @param {HTMLElement} container | ||
| 375 | * @param {Range} range | ||
| 376 | */ | ||
| 377 | export const dragForAnchor = (container, range, endOfLeaderLine) => { | ||
| 378 | // link placeholder when dragging | ||
| 379 | container.classList.add('dragging-geolink') | ||
| 380 | const geoLink = document.createElement('a') | ||
| 381 | geoLink.textContent = range.toString() | ||
| 382 | geoLink.classList.add('with-leader-line', 'geolink', 'drag') | ||
| 383 | |||
| 384 | // Replace current content with link | ||
| 385 | const originContent = range.cloneContents() | ||
| 386 | const resumeContent = () => { | ||
| 387 | range.deleteContents() | ||
| 388 | range.insertNode(originContent) | ||
| 389 | } | ||
| 390 | range.deleteContents() | ||
| 391 | range.insertNode(geoLink) | ||
| 392 | |||
| 393 | // Add leader-line | ||
| 394 | const line = new LeaderLine({ | ||
| 395 | start: geoLink, | ||
| 396 | end: endOfLeaderLine, | ||
| 397 | path: 'magnet', | ||
| 398 | }) | ||
| 399 | |||
| 400 | const positionObserver = new window.MutationObserver(() => { | ||
| 401 | line.position() | ||
| 402 | }) | ||
| 403 | positionObserver.observe(endOfLeaderLine, { | ||
| 404 | attributes: true, | ||
| 405 | attributeFilter: ['style'], | ||
| 406 | }) | ||
| 407 | |||
| 408 | // Handler for dragend | ||
| 409 | container.onmouseup = (e) => { | ||
| 410 | container.classList.remove('dragging-geolink') | ||
| 411 | container.onmousemove = null | ||
| 412 | container.onmouseup = null | ||
| 413 | geoLink.classList.remove('drag') | ||
| 414 | positionObserver.disconnect() | ||
| 415 | line.remove() | ||
| 416 | |||
| 417 | const map = document.elementFromPoint(e.clientX, e.clientY) | ||
| 418 | .closest('.mapclay[data-render="fulfilled"]') | ||
| 419 | if (!map) { | ||
| 420 | resumeContent() | ||
| 421 | return | ||
| 422 | } | ||
| 423 | |||
| 424 | const marker = addMarkerByPoint({ point: [e.clientX, e.clientY], map }) | ||
| 425 | if (!marker) { | ||
| 426 | resumeContent() | ||
| 427 | return | ||
| 428 | } | ||
| 429 | |||
| 430 | geoLink.href = `geo:${marker.dataset.xy.split(',').reverse()}` | ||
| 431 | createGeoLink(geoLink) | ||
| 432 | } | ||
| 433 | } | ||
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 | ||