aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/dumbymap.mjs
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-10-20 20:44:40 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-10-20 20:51:59 +0800
commit71623eca7acd3cfa8d9647b61cd178a75375fa62 (patch)
treebaeb62fec51e73dc583dead8592d4d0114d3c8eb /src/dumbymap.mjs
parent39b67e2c54b9890a182a287a56abeb94d4aba0f4 (diff)
refactor: move method about adding geoscheme into DunbyUtils
Diffstat (limited to 'src/dumbymap.mjs')
-rw-r--r--src/dumbymap.mjs22
1 files changed, 5 insertions, 17 deletions
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)