diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2024-10-24 17:39:34 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2024-10-24 17:42:31 +0800 |
commit | 1dd8064531f6fffd54b541a58aa624ad2e27dac3 (patch) | |
tree | 8ebee7d446164abefe1ac5ff9742b916728f78ad /src/dumbymap.mjs | |
parent | 21ae439bfab7cf22338fcb80c7bf482d1a3c763c (diff) |
refactor: add module 'Link' for GeoLink and DocLink
Diffstat (limited to 'src/dumbymap.mjs')
-rw-r--r-- | src/dumbymap.mjs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs index 92fe785..bb3737b 100644 --- a/src/dumbymap.mjs +++ b/src/dumbymap.mjs | |||
@@ -6,6 +6,7 @@ import MarkdownItInjectLinenumbers from 'markdown-it-inject-linenumbers' | |||
6 | import * as mapclay from 'mapclay' | 6 | import * as mapclay from 'mapclay' |
7 | import { onRemove, animateRectTransition, throttle, debounce, shiftByWindow } from './utils' | 7 | import { onRemove, animateRectTransition, throttle, debounce, shiftByWindow } from './utils' |
8 | import { Layout, SideBySide, Overlay, Sticky } from './Layout' | 8 | import { Layout, SideBySide, Overlay, Sticky } from './Layout' |
9 | import { GeoLink, DocLink } from './Link.mjs' | ||
9 | import * as utils from './dumbyUtils' | 10 | import * as utils from './dumbyUtils' |
10 | import * as menuItem from './MenuItem' | 11 | import * as menuItem from './MenuItem' |
11 | import PlainModal from 'plain-modal' | 12 | import PlainModal from 'plain-modal' |
@@ -209,7 +210,7 @@ export const generateMaps = (container, { | |||
209 | if (node.matches?.('.mapclay') || node.closest?.('.mapclay')) return | 210 | if (node.matches?.('.mapclay') || node.closest?.('.mapclay')) return |
210 | 211 | ||
211 | // Add GeoLinks from plain texts | 212 | // Add GeoLinks from plain texts |
212 | addGeoLinksByText(node) | 213 | utils.addGeoSchemeByText(node) |
213 | 214 | ||
214 | // Render Map | 215 | // Render Map |
215 | const mapTarget = node.parentElement?.closest(mapBlockSelector) | 216 | const mapTarget = node.parentElement?.closest(mapBlockSelector) |
@@ -245,9 +246,9 @@ export const generateMaps = (container, { | |||
245 | 246 | ||
246 | // Add GeoLinks/DocLinks by pattern | 247 | // Add GeoLinks/DocLinks by pattern |
247 | target.querySelectorAll(geoLinkSelector) | 248 | target.querySelectorAll(geoLinkSelector) |
248 | .forEach(utils.createGeoLink) | 249 | .forEach(GeoLink.replaceWith) |
249 | target.querySelectorAll(docLinkSelector) | 250 | target.querySelectorAll(docLinkSelector) |
250 | .forEach(utils.createDocLink) | 251 | .forEach(DocLink.replaceWith) |
251 | 252 | ||
252 | // Add GeoLinks from text nodes | 253 | // Add GeoLinks from text nodes |
253 | // const addedNodes = Array.from(mutation.addedNodes) | 254 | // const addedNodes = Array.from(mutation.addedNodes) |
@@ -318,7 +319,7 @@ export const generateMaps = (container, { | |||
318 | values.at(-1) | 319 | values.at(-1) |
319 | .map(utils.setGeoSchemeByCRS(crsString)) | 320 | .map(utils.setGeoSchemeByCRS(crsString)) |
320 | .filter(link => link) | 321 | .filter(link => link) |
321 | .forEach(utils.createGeoLink) | 322 | .forEach(GeoLink.replaceWith) |
322 | }) | 323 | }) |
323 | } | 324 | } |
324 | 325 | ||
@@ -556,7 +557,7 @@ export const generateMaps = (container, { | |||
556 | menu.appendChild(new menuItem.Item({ | 557 | menu.appendChild(new menuItem.Item({ |
557 | text: 'Delete', | 558 | text: 'Delete', |
558 | onclick: () => { | 559 | onclick: () => { |
559 | utils.getMarkersFromMaps(geoLink) | 560 | geoLink.getMarkersFromMaps() |
560 | .forEach(m => m.remove()) | 561 | .forEach(m => m.remove()) |
561 | geoLink.replaceWith( | 562 | geoLink.replaceWith( |
562 | document.createTextNode(geoLink.textContent), | 563 | document.createTextNode(geoLink.textContent), |
@@ -637,7 +638,7 @@ export const generateMaps = (container, { | |||
637 | container.appendChild(pointByArrow) | 638 | container.appendChild(pointByArrow) |
638 | 639 | ||
639 | const timer = setTimeout(() => { | 640 | const timer = setTimeout(() => { |
640 | utils.dragForAnchor(container, range, pointByArrow) | 641 | utils.addGeoLinkByDrag(container, range, pointByArrow) |
641 | }, 300) | 642 | }, 300) |
642 | 643 | ||
643 | // Update leader-line with mouse move | 644 | // Update leader-line with mouse move |