diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2024-10-11 15:17:25 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2024-10-11 15:17:26 +0800 |
commit | 2a7a840c25fcdb1653538514fb6609b0dea61b66 (patch) | |
tree | 80ae0c0a3e5b204de5d98090de61ace31979f0c0 /src/dumbymap.mjs | |
parent | 184b3004d82806f1b31c94701e75585fb8f2721b (diff) |
feat: add handler for invlid coordinates
* prvent default onmouseover/onclick handler
* set bg-color of GeoLink as gray
* add title to suggest another CRS
Diffstat (limited to 'src/dumbymap.mjs')
-rw-r--r-- | src/dumbymap.mjs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs index 6602f29..974d4a3 100644 --- a/src/dumbymap.mjs +++ b/src/dumbymap.mjs | |||
@@ -179,7 +179,7 @@ export const generateMaps = (container, { | |||
179 | 179 | ||
180 | /** Set CRS and GeoLinks */ | 180 | /** Set CRS and GeoLinks */ |
181 | register(proj4) | 181 | register(proj4) |
182 | fromEPSGCode(crs).then(() => { | 182 | fromEPSGCode(crs).then(projection => { |
183 | const transform = proj4(crs, 'EPSG:4326').forward | 183 | const transform = proj4(crs, 'EPSG:4326').forward |
184 | 184 | ||
185 | Array.from(container.querySelectorAll(geoLinkSelector)) | 185 | Array.from(container.querySelectorAll(geoLinkSelector)) |
@@ -200,6 +200,13 @@ export const generateMaps = (container, { | |||
200 | params.set('q', `${lat},${lon}`) | 200 | params.set('q', `${lat},${lon}`) |
201 | link.search = params | 201 | link.search = params |
202 | 202 | ||
203 | if (projection.getUnits() === 'degrees' && | ||
204 | (lon > 180 || lon < -180 || lat > 90 || lat < -90) | ||
205 | ) { | ||
206 | link.dataset.valid = false | ||
207 | link.title = `Invalid Coordinate, maybe try another crs other than ${crs}` | ||
208 | } | ||
209 | |||
203 | return link | 210 | return link |
204 | }) | 211 | }) |
205 | .forEach(utils.createGeoLink) | 212 | .forEach(utils.createGeoLink) |