diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2024-10-20 20:44:40 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2024-10-20 20:51:59 +0800 |
commit | 71623eca7acd3cfa8d9647b61cd178a75375fa62 (patch) | |
tree | baeb62fec51e73dc583dead8592d4d0114d3c8eb /src/dumbyUtils.mjs | |
parent | 39b67e2c54b9890a182a287a56abeb94d4aba0f4 (diff) |
refactor: move method about adding geoscheme into DunbyUtils
Diffstat (limited to 'src/dumbyUtils.mjs')
-rw-r--r-- | src/dumbyUtils.mjs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/dumbyUtils.mjs b/src/dumbyUtils.mjs index 13c1142..46594bd 100644 --- a/src/dumbyUtils.mjs +++ b/src/dumbyUtils.mjs | |||
@@ -1,5 +1,5 @@ | |||
1 | import LeaderLine from 'leader-line' | 1 | import LeaderLine from 'leader-line' |
2 | import { insideWindow, insideParent } from './utils' | 2 | import { insideWindow, insideParent, replaceTextNodes } from './utils' |
3 | import proj4 from 'proj4' | 3 | import proj4 from 'proj4' |
4 | 4 | ||
5 | export const coordPattern = /^geo:([-]?[0-9.]+),([-]?[0-9.]+)/ | 5 | export const coordPattern = /^geo:([-]?[0-9.]+),([-]?[0-9.]+)/ |
@@ -439,3 +439,14 @@ export const dragForAnchor = (container, range, endOfLeaderLine) => { | |||
439 | createGeoLink(geoLink) | 439 | createGeoLink(geoLink) |
440 | } | 440 | } |
441 | } | 441 | } |
442 | |||
443 | export const addGeoSchemeByText = async (element) => { | ||
444 | const coordPatterns = /(-?\d+\.?\d*)([,\x2F\uFF0C])(-?\d+\.?\d*)/ | ||
445 | const re = new RegExp(coordPatterns, 'g') | ||
446 | replaceTextNodes(element, re, match => { | ||
447 | const a = document.createElement('a') | ||
448 | a.href = `geo:0,0?xy=${match.at(1)},${match.at(3)}` | ||
449 | a.textContent = match.at(0) | ||
450 | return a | ||
451 | }) | ||
452 | } | ||