1- import { map , mapProperties } from 'maplibre/map'
1+ import { map } from 'maplibre/map'
22import * as f from 'helpers/functions'
33import * as dom from 'helpers/dom'
44import { marked } from 'marked'
5- import { defaultLineWidth } from 'maplibre/styles'
65import { showElevationChart } from 'maplibre/feature/elevation'
76import { length } from "@turf/length"
87import { area } from "@turf/area"
9- import { buffer } from "@turf/buffer"
108import { lineString , multiLineString , polygon , multiPolygon } from "@turf/helpers"
11- import { layers , getFeature , getFeatures , getFeatureSource } from "maplibre/layers/layers"
9+ import { layers , getFeature , getFeatureSource } from "maplibre/layers/layers"
1210
1311window . marked = marked
1412
@@ -173,7 +171,12 @@ export async function showFeatureDetails (feature) {
173171
174172 f . e ( '.feature-symbol' , e => { e . innerHTML = featureIcon ( feature ) } )
175173 f . e ( '.feature-image' , e => { e . innerHTML = featureImage ( feature ) } )
176- document . querySelector ( '#feature-title' ) . innerHTML = featureTitle ( feature )
174+
175+ const title = featureTitle ( feature )
176+ const titleElement = document . querySelector ( '#feature-title' )
177+ titleElement . innerHTML = title
178+ titleElement . style . fontSize = titleElement . textContent . length > 24 ? '1rem' : null ;
179+
177180 document . querySelector ( '#feature-size' ) . innerHTML = featureMeta ( feature )
178181 document . querySelector ( '#feature-vertexes' ) . innerHTML = featureVertexes ( feature )
179182 if ( feature . geometry . type === 'Point' ) {
@@ -188,19 +191,44 @@ export async function showFeatureDetails (feature) {
188191 link . href = link . href . replace ( / f e a t u r e \/ .* / , 'feature/' + feature . id + '.gpx' )
189192 if ( feature . properties . title ) { link . href += '/' + encodeURIComponent ( feature . properties . title . replace ( / [ \s \/ ] + / g, "_" ) ) }
190193 }
194+
195+ document . querySelector ( '#feature-details-description' ) . innerHTML = 'Loading description...'
196+ featureDescription ( feature ) . then ( desc => {
197+ document . querySelector ( '#feature-details-description' ) . innerHTML = desc
198+ } )
199+
200+ }
201+
202+ async function featureDescription ( feature ) {
191203 marked . use ( { gfm : true , breaks : true } )
192- let desc = marked ( feature ?. properties ?. desc || '' )
204+ let desc = ''
193205 // show link target if onclick is link
194- if ( feature ?. properties ?. onclick === 'link' && feature ?. properties ?. [ 'onclick-target' ] ) {
206+ if ( feature ?. properties ?. onclick === 'link' && feature ?. properties ?. [ 'onclick-target' ] ) {
195207 desc = `<p><i class="bi bi-box-arrow-up-right"></i> ${ feature . properties [ 'onclick-target' ] } </p>`
196- } else if ( feature ?. properties ?. onclick === 'feature' && feature ?. properties ?. [ 'onclick-target' ] ) {
197- // show feature target if onclick is feature
208+ } else if ( feature ?. properties ?. onclick === 'feature' && feature ?. properties ?. [ 'onclick-target' ] ) {
209+ // show feature target if onclick is feature
198210 desc = `<p><i class="bi bi-geo-alt-fill"></i> ${ feature . properties [ 'onclick-target' ] } </p>`
211+ } else if ( feature ?. properties ?. wikipediaId ) {
212+ const page = encodeURIComponent ( feature . properties . title )
213+ const api = `https://en.wikipedia.org/api/rest_v1/page/summary/${ page } `
214+ const url = `https://en.wikipedia.org/wiki/${ page } `
215+
216+ const data = await fetch ( api ) . then ( r => r . json ( ) )
217+ if ( data . thumbnail ?. source ) {
218+ desc += `<p><a target="_blank" href="${ url } ">` +
219+ `<img class="w-100" src="${ data . thumbnail . source } "></a></p>`
220+ }
221+ desc += `<p>${ data . extract } </p>`
222+ desc += `<p>Read the full <img src="/icons/wikipedia.png" class="me-1 ms-1 icon"/><a target="_blank" href="${ url } ">Wikipedia article</a></p>`
223+
224+ } else {
225+ desc = f . sanitizeMarkdown ( marked ( feature ?. properties ?. desc || '' ) )
199226 }
200- desc = f . sanitizeMarkdown ( desc )
201- document . querySelector ( '#feature-details-description' ) . innerHTML = desc
227+ return desc
202228}
203229
230+
231+
204232// set title image according to feature type
205233export function featureIcon ( feature ) {
206234 let image = ''
@@ -277,32 +305,6 @@ export function highlightFeature (feature, sticky = false, source) {
277305 }
278306}
279307
280- export function renderExtrusionLines ( ) {
281- // Disable extrusionlines on 3D terrain, it does not work
282- if ( mapProperties . terrain ) { return [ ] }
283-
284- let extrusionLines = getFeatures ( 'geojson' ) . filter ( feature => (
285- feature . geometry . type === 'LineString' &&
286- feature . properties [ 'fill-extrusion-height' ] &&
287- feature . geometry . coordinates . length !== 1 // don't break line animation
288- ) )
289-
290- extrusionLines = extrusionLines . map ( feature => {
291- const width = feature . properties [ 'fill-extrusion-width' ] || feature . properties [ 'stroke-width' ] || defaultLineWidth
292- const extrusionLine = buffer ( feature , width , { units : 'meters' } )
293- // clone properties hash, else we're writing into the original feature's properties
294- extrusionLine . properties = { ...feature . properties }
295- if ( ! extrusionLine . properties [ 'fill-extrusion-color' ] && feature . properties . stroke ) {
296- extrusionLine . properties [ 'fill-extrusion-color' ] = feature . properties . stroke
297- }
298- extrusionLine . properties [ 'stroke-width' ] = 0
299- extrusionLine . properties [ 'stroke-opacity' ] = 0
300- extrusionLine . properties [ 'fill-opacity' ] = 0
301- return extrusionLine
302- } )
303- return extrusionLines
304- }
305-
306308export async function uploadImage ( image ) {
307309 const formData = new FormData ( ) // send using multipart/form-data
308310 formData . append ( 'image' , image )
0 commit comments