From 71623eca7acd3cfa8d9647b61cd178a75375fa62 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Sun, 20 Oct 2024 20:44:40 +0800 Subject: refactor: move method about adding geoscheme into DunbyUtils --- src/dumbyUtils.mjs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/dumbyUtils.mjs') 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 @@ import LeaderLine from 'leader-line' -import { insideWindow, insideParent } from './utils' +import { insideWindow, insideParent, replaceTextNodes } from './utils' import proj4 from 'proj4' export const coordPattern = /^geo:([-]?[0-9.]+),([-]?[0-9.]+)/ @@ -439,3 +439,14 @@ export const dragForAnchor = (container, range, endOfLeaderLine) => { createGeoLink(geoLink) } } + +export const addGeoSchemeByText = async (element) => { + const coordPatterns = /(-?\d+\.?\d*)([,\x2F\uFF0C])(-?\d+\.?\d*)/ + const re = new RegExp(coordPatterns, 'g') + replaceTextNodes(element, re, match => { + const a = document.createElement('a') + a.href = `geo:0,0?xy=${match.at(1)},${match.at(3)}` + a.textContent = match.at(0) + return a + }) +} -- cgit v1.2.3-70-g09d2