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,25 +61,33 @@ func (a *goBlog) serveGeoMap(w http.ResponseWriter, r *http.Request) {
} }
} }
locationsJson := ""
if len(locations) > 0 {
locationsJsonBytes, err := json.Marshal(locations) locationsJsonBytes, err := json.Marshal(locations)
if err != nil { if err != nil {
a.serveError(w, r, err.Error(), http.StatusInternalServerError) a.serveError(w, r, err.Error(), http.StatusInternalServerError)
return return
} }
locationsJson = string(locationsJsonBytes)
}
tracksJson := ""
if len(tracks) > 0 {
tracksJsonBytes, err := json.Marshal(tracks) tracksJsonBytes, err := json.Marshal(tracks)
if err != nil { if err != nil {
a.serveError(w, r, err.Error(), http.StatusInternalServerError) a.serveError(w, r, err.Error(), http.StatusInternalServerError)
return return
} }
tracksJson = string(tracksJsonBytes)
}
mapPath := bc.getRelativePath(defaultIfEmpty(bc.Map.Path, defaultGeoMapPath)) mapPath := bc.getRelativePath(defaultIfEmpty(bc.Map.Path, defaultGeoMapPath))
a.render(w, r, templateGeoMap, &renderData{ a.render(w, r, templateGeoMap, &renderData{
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')