This commit is contained in:
Jan-Lukas Else 2021-11-13 20:40:25 +01:00
parent 0ea54f87a6
commit 55ef904286
2 changed files with 20 additions and 12 deletions

View File

@ -61,16 +61,24 @@ func (a *goBlog) serveGeoMap(w http.ResponseWriter, r *http.Request) {
}
}
locationsJsonBytes, err := json.Marshal(locations)
if err != nil {
a.serveError(w, r, err.Error(), http.StatusInternalServerError)
return
locationsJson := ""
if len(locations) > 0 {
locationsJsonBytes, err := json.Marshal(locations)
if err != nil {
a.serveError(w, r, err.Error(), http.StatusInternalServerError)
return
}
locationsJson = string(locationsJsonBytes)
}
tracksJsonBytes, err := json.Marshal(tracks)
if err != nil {
a.serveError(w, r, err.Error(), http.StatusInternalServerError)
return
tracksJson := ""
if len(tracks) > 0 {
tracksJsonBytes, err := json.Marshal(tracks)
if err != nil {
a.serveError(w, r, err.Error(), http.StatusInternalServerError)
return
}
tracksJson = string(tracksJsonBytes)
}
mapPath := bc.getRelativePath(defaultIfEmpty(bc.Map.Path, defaultGeoMapPath))
@ -78,8 +86,8 @@ func (a *goBlog) serveGeoMap(w http.ResponseWriter, r *http.Request) {
BlogString: blog,
Canonical: a.getFullAddress(mapPath),
Data: map[string]interface{}{
"locations": string(locationsJsonBytes),
"tracks": string(tracksJsonBytes),
"locations": locationsJson,
"tracks": tracksJson,
},
})
}

View File

@ -1,7 +1,7 @@
(function () {
let mapEl = document.getElementById('map')
let locations = JSON.parse(mapEl.dataset.locations)
let tracks = JSON.parse(mapEl.dataset.tracks)
let locations = (mapEl.dataset.locations == "") ? [] : JSON.parse(mapEl.dataset.locations)
let tracks = (mapEl.dataset.tracks == "") ? [] : JSON.parse(mapEl.dataset.tracks)
let map = L.map('map')