diff options
Diffstat (limited to 'src/dumbyUtils.mjs')
-rw-r--r-- | src/dumbyUtils.mjs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/dumbyUtils.mjs b/src/dumbyUtils.mjs index 46594bd..0430f97 100644 --- a/src/dumbyUtils.mjs +++ b/src/dumbyUtils.mjs | |||
@@ -143,7 +143,7 @@ const addLeaderLine = (link, target) => { | |||
143 | /** | 143 | /** |
144 | * Create geolinks, which points to map by geo schema and id | 144 | * Create geolinks, which points to map by geo schema and id |
145 | * | 145 | * |
146 | * @param {HTMLElement} Elements contains anchor elements for doclinks | 146 | * @param {HTMLElement} Elements contains anchor elements for GeoLinks |
147 | * @returns {Boolean} ture is link is created, false if coordinates are invalid | 147 | * @returns {Boolean} ture is link is created, false if coordinates are invalid |
148 | */ | 148 | */ |
149 | export const createGeoLink = (link) => { | 149 | export const createGeoLink = (link) => { |
@@ -164,6 +164,7 @@ export const createGeoLink = (link) => { | |||
164 | link.dataset.lat = lat | 164 | link.dataset.lat = lat |
165 | link.dataset.crs = params.get('crs') | 165 | link.dataset.crs = params.get('crs') |
166 | link.classList.add('with-leader-line', 'geolink') | 166 | link.classList.add('with-leader-line', 'geolink') |
167 | link.classList.remove('not-geolink') | ||
167 | // TODO refactor as data attribute | 168 | // TODO refactor as data attribute |
168 | link.targets = params.get('id')?.split(',') ?? null | 169 | link.targets = params.get('id')?.split(',') ?? null |
169 | link.type = params.get('type') ?? null | 170 | link.type = params.get('type') ?? null |
@@ -363,10 +364,8 @@ export const setGeoSchemeByCRS = (crs) => (link) => { | |||
363 | link.search = params | 364 | link.search = params |
364 | 365 | ||
365 | const unit = proj4(crs).oProj.units | 366 | const unit = proj4(crs).oProj.units |
366 | const invalidDegree = unit === 'degrees' && ( | 367 | const invalidDegree = unit === 'degrees' && |
367 | (lon > 180 || lon < -180 || lat > 90 || lat < -90) || | 368 | (lon > 180 || lon < -180 || lat > 90 || lat < -90) |
368 | (xy.every(v => v.toString().length < 3)) | ||
369 | ) | ||
370 | const invalidMeter = unit === 'm' && xy.find(v => v < 100) | 369 | const invalidMeter = unit === 'm' && xy.find(v => v < 100) |
371 | if (invalidDegree || invalidMeter) { | 370 | if (invalidDegree || invalidMeter) { |
372 | link.replaceWith(document.createTextNode(link.textContent)) | 371 | link.replaceWith(document.createTextNode(link.textContent)) |
@@ -443,9 +442,15 @@ export const dragForAnchor = (container, range, endOfLeaderLine) => { | |||
443 | export const addGeoSchemeByText = async (element) => { | 442 | export const addGeoSchemeByText = async (element) => { |
444 | const coordPatterns = /(-?\d+\.?\d*)([,\x2F\uFF0C])(-?\d+\.?\d*)/ | 443 | const coordPatterns = /(-?\d+\.?\d*)([,\x2F\uFF0C])(-?\d+\.?\d*)/ |
445 | const re = new RegExp(coordPatterns, 'g') | 444 | const re = new RegExp(coordPatterns, 'g') |
446 | replaceTextNodes(element, re, match => { | 445 | |
446 | return replaceTextNodes(element, re, match => { | ||
447 | const [x, y] = [match.at(1), match.at(3)] | ||
448 | // Don't process string which can be used as date | ||
449 | if (Date.parse(match.at(0) + ' 1990')) return null | ||
450 | |||
447 | const a = document.createElement('a') | 451 | const a = document.createElement('a') |
448 | a.href = `geo:0,0?xy=${match.at(1)},${match.at(3)}` | 452 | a.className = 'not-geolink' |
453 | a.href = `geo:0,0?xy=${x},${y}` | ||
449 | a.textContent = match.at(0) | 454 | a.textContent = match.at(0) |
450 | return a | 455 | return a |
451 | }) | 456 | }) |