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/dumbymap.mjs | |
parent | 39b67e2c54b9890a182a287a56abeb94d4aba0f4 (diff) |
refactor: move method about adding geoscheme into DunbyUtils
Diffstat (limited to 'src/dumbymap.mjs')
-rw-r--r-- | src/dumbymap.mjs | 22 |
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' | |||
4 | import MarkdownItFrontMatter from 'markdown-it-front-matter' | 4 | import MarkdownItFrontMatter from 'markdown-it-front-matter' |
5 | import MarkdownItInjectLinenumbers from 'markdown-it-inject-linenumbers' | 5 | import MarkdownItInjectLinenumbers from 'markdown-it-inject-linenumbers' |
6 | import * as mapclay from 'mapclay' | 6 | import * as mapclay from 'mapclay' |
7 | import { replaceTextNodes, onRemove, animateRectTransition, throttle, shiftByWindow } from './utils' | 7 | import { onRemove, animateRectTransition, throttle, shiftByWindow } from './utils' |
8 | import { Layout, SideBySide, Overlay, Sticky } from './Layout' | 8 | import { Layout, SideBySide, Overlay, Sticky } from './Layout' |
9 | import * as utils from './dumbyUtils' | 9 | import * as utils from './dumbyUtils' |
10 | import * as menuItem from './MenuItem' | 10 | import * 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) |