aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/dumbyUtils.mjs13
-rw-r--r--src/dumbymap.mjs22
2 files changed, 17 insertions, 18 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 @@
1import LeaderLine from 'leader-line' 1import LeaderLine from 'leader-line'
2import { insideWindow, insideParent } from './utils' 2import { insideWindow, insideParent, replaceTextNodes } from './utils'
3import proj4 from 'proj4' 3import proj4 from 'proj4'
4 4
5export const coordPattern = /^geo:([-]?[0-9.]+),([-]?[0-9.]+)/ 5export 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
443export 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}
diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs
index 3c3b172..46a532d 100644
--- a/src/dumbymap.mjs
+++ b/src/dumbymap.mjs
@@ -4,7 +4,7 @@ import MarkdownItFootnote from 'markdown-it-footnote'
4import MarkdownItFrontMatter from 'markdown-it-front-matter' 4import MarkdownItFrontMatter from 'markdown-it-front-matter'
5import MarkdownItInjectLinenumbers from 'markdown-it-inject-linenumbers' 5import MarkdownItInjectLinenumbers from 'markdown-it-inject-linenumbers'
6import * as mapclay from 'mapclay' 6import * as mapclay from 'mapclay'
7import { replaceTextNodes, onRemove, animateRectTransition, throttle, shiftByWindow } from './utils' 7import { onRemove, animateRectTransition, throttle, shiftByWindow } from './utils'
8import { Layout, SideBySide, Overlay, Sticky } from './Layout' 8import { Layout, SideBySide, Overlay, Sticky } from './Layout'
9import * as utils from './dumbyUtils' 9import * as utils from './dumbyUtils'
10import * as menuItem from './MenuItem' 10import * as menuItem from './MenuItem'
@@ -240,25 +240,13 @@ export const generateMaps = (container, {
240 }) 240 })
241 241
242 /** LINK: Set CRS and GeoLinks */ 242 /** LINK: Set CRS and GeoLinks */
243 const setCRS = new Promise(resolve => { 243 const setCRS = (async () => {
244 register(proj4) 244 register(proj4)
245 fromEPSGCode(crs).then(() => resolve()) 245 await fromEPSGCode(crs)
246 })
247 const addGeoSchemeByText = (async () => {
248 const coordPatterns = /(-?\d+\.?\d*)([,\x2F\uFF0C])(-?\d+\.?\d*)/
249 const re = new RegExp(coordPatterns, 'g')
250 htmlHolder.querySelectorAll('.dumby-block')
251 .forEach(p => {
252 replaceTextNodes(p, re, match => {
253 const a = document.createElement('a')
254 a.href = `geo:0,0?xy=${match.at(1)},${match.at(3)}`
255 a.textContent = match.at(0)
256 return a
257 })
258 })
259 })() 246 })()
247 const addGeoScheme = utils.addGeoSchemeByText(htmlHolder)
260 248
261 Promise.all([setCRS, addGeoSchemeByText]).then(() => { 249 Promise.all([setCRS, addGeoScheme]).then(() => {
262 Array.from(container.querySelectorAll(geoLinkSelector)) 250 Array.from(container.querySelectorAll(geoLinkSelector))
263 .map(utils.setGeoSchemeByCRS(crs)) 251 .map(utils.setGeoSchemeByCRS(crs))
264 .filter(link => link instanceof window.HTMLAnchorElement) 252 .filter(link => link instanceof window.HTMLAnchorElement)