added lang support to all html templates and cleaned up template rendering
This commit is contained in:
parent
5dd3114e2d
commit
d9d0301548
18 changed files with 645 additions and 410 deletions
23
map.go
23
map.go
|
@ -3,9 +3,9 @@ package main
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
type NominatimResponse struct {
|
||||
|
@ -44,31 +44,32 @@ func geocodeQuery(query string) (latitude, longitude string, found bool, err err
|
|||
}
|
||||
|
||||
func handleMapSearch(w http.ResponseWriter, settings UserSettings, query string) {
|
||||
// Start measuring the time for geocoding the query
|
||||
startTime := time.Now()
|
||||
|
||||
// Geocode the query to get coordinates
|
||||
latitude, longitude, found, err := geocodeQuery(query)
|
||||
if err != nil {
|
||||
printDebug("Error geocoding query: %s, error: %v", query, err)
|
||||
http.Error(w, "Failed to find location", http.StatusInternalServerError)
|
||||
http.Error(w, Translate("internal_server_error"), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Use a template to serve the map page
|
||||
// Measure the elapsed time for geocoding
|
||||
elapsedTime := time.Since(startTime)
|
||||
|
||||
// Prepare the data to pass to the template
|
||||
data := map[string]interface{}{
|
||||
"Query": query,
|
||||
"Latitude": latitude,
|
||||
"Longitude": longitude,
|
||||
"Found": found,
|
||||
"Fetched": fmt.Sprintf("%.2f %s", elapsedTime.Seconds(), Translate("seconds")),
|
||||
"Theme": settings.Theme,
|
||||
"Safe": settings.SafeSearch,
|
||||
"IsThemeDark": settings.IsThemeDark,
|
||||
}
|
||||
|
||||
tmpl, err := template.ParseFiles("templates/map.html")
|
||||
if err != nil {
|
||||
printErr("Error loading map template: %v", err)
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
tmpl.Execute(w, data)
|
||||
// Render the template
|
||||
renderTemplate(w, "map.html", data)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue