diff options
| -rw-r--r-- | src/dumbyUtils.mjs | 13 | ||||
| -rw-r--r-- | src/dumbymap.mjs | 22 |
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 @@ | |||
| 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 | } | ||
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) |