diff options
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 | } | ||