aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/dumbymap.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'src/dumbymap.mjs')
-rw-r--r--src/dumbymap.mjs42
1 files changed, 36 insertions, 6 deletions
diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs
index 593875e..6602f29 100644
--- a/src/dumbymap.mjs
+++ b/src/dumbymap.mjs
@@ -9,6 +9,8 @@ import { Layout, SideBySide, Overlay } from './Layout'
9import * as utils from './dumbyUtils' 9import * as utils from './dumbyUtils'
10import * as menuItem from './MenuItem' 10import * as menuItem from './MenuItem'
11import PlainModal from 'plain-modal' 11import PlainModal from 'plain-modal'
12import proj4 from 'proj4'
13import { register, fromEPSGCode } from 'ol/proj/proj4'
12 14
13/** Selector of special HTML Elements */ 15/** Selector of special HTML Elements */
14const mapBlockSelector = 'pre:has(.language-map)' 16const mapBlockSelector = 'pre:has(.language-map)'
@@ -59,8 +61,8 @@ export const markdown2HTML = (container, mdContent) => {
59 validate: coordinateRegex, 61 validate: coordinateRegex,
60 normalize: function (match) { 62 normalize: function (match) {
61 const [, , x, sep, y] = match.text.match(coordinateRegex) 63 const [, , x, sep, y] = match.text.match(coordinateRegex)
62 match.url = `geo:${y},${x}?xy=${x},${y}` 64 match.url = `geo:${y},${x}`
63 match.text = `${x}${sep} ${y}` 65 match.text = `${x}${sep}${y}`
64 match.index += match.text.indexOf(x) + 1 66 match.index += match.text.indexOf(x) + 1
65 return match 67 return match
66 }, 68 },
@@ -165,15 +167,43 @@ export const generateMaps = (container, {
165 switchToNextLayout: throttle(utils.switchToNextLayout, 300), 167 switchToNextLayout: throttle(utils.switchToNextLayout, 300),
166 }, 168 },
167 } 169 }
168 Object.entries(dumbymap.utils).forEach(([util, func]) => { 170 Object.entries(dumbymap.utils).forEach(([util, value]) => {
169 dumbymap.utils[util] = func.bind(dumbymap) 171 if (typeof value === 'function') {
172 dumbymap.utils[util] = value.bind(dumbymap)
173 }
170 }) 174 })
171 175
172 /** Create GeoLinks and DocLinks */ 176 /** Create GeoLinks and DocLinks */
173 container.querySelectorAll(docLinkSelector) 177 container.querySelectorAll(docLinkSelector)
174 .forEach(utils.createDocLink) 178 .forEach(utils.createDocLink)
175 container.querySelectorAll(geoLinkSelector) 179
176 .forEach(utils.createGeoLink) 180 /** Set CRS and GeoLinks */
181 register(proj4)
182 fromEPSGCode(crs).then(() => {
183 const transform = proj4(crs, 'EPSG:4326').forward
184
185 Array.from(container.querySelectorAll(geoLinkSelector))
186 .map(link => {
187 // set coordinate as lat/lon in WGS84
188 const params = new URLSearchParams(link.search)
189 const [y, x] = link.href
190 .match(utils.coordPattern)
191 .splice(1)
192 .map(Number)
193 const [lon, lat] = transform([x, y])
194 .map(value => value.toFixed(6))
195 link.href = `geo:${lat},${lon}`
196
197 // set query strings
198 params.set('xy', `${x},${y}`)
199 params.set('crs', crs)
200 params.set('q', `${lat},${lon}`)
201 link.search = params
202
203 return link
204 })
205 .forEach(utils.createGeoLink)
206 })
177 207
178 /** 208 /**
179 * mapFocusObserver. observe for map focus 209 * mapFocusObserver. observe for map focus