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

View File

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