This commit is contained in:
parent
2fe93c77d7
commit
c825ccbb0e
2 changed files with 24 additions and 4 deletions
15
main.go
15
main.go
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/json"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
var lastData map[string]interface{}
|
||||
|
@ -13,6 +14,7 @@ var lastData map[string]interface{}
|
|||
var templateContent []byte
|
||||
|
||||
var active = false
|
||||
var activeSince time.Time
|
||||
var getData = false
|
||||
|
||||
|
||||
|
@ -40,11 +42,24 @@ func main() {
|
|||
})
|
||||
})
|
||||
|
||||
http.HandleFunc("/activate", func(writer http.ResponseWriter, request *http.Request) {
|
||||
active = true
|
||||
activeSince = time.Now()
|
||||
})
|
||||
|
||||
http.HandleFunc("/json", func(writer http.ResponseWriter, request *http.Request) {
|
||||
if getData == false || active == false {
|
||||
writer.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
diff := time.Now().Sub(activeSince)
|
||||
if diff.Minutes() > 2 {
|
||||
active = false
|
||||
writer.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
data := make(map[string]interface{})
|
||||
|
||||
data["lat"] = lastData["lat"]
|
||||
|
|
13
notfall.tmpl
13
notfall.tmpl
|
@ -15,18 +15,23 @@
|
|||
<div id="map"></div>
|
||||
Last Update: <span id="update"></span>
|
||||
|
||||
<a href="/activate">Es gibt einen Notfall, zeige mir den standort an, eine sms mit einer benachrichtung wird gesendet</a>
|
||||
|
||||
<script>
|
||||
var map = L.map('map').setView([52.5, 13.5], 10);
|
||||
var map = L.map('map').setView([52.0, 13.0], 1);
|
||||
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||
}).addTo(map);
|
||||
|
||||
circle = L.circle([52.5, 13.5], {radius: 200}).addTo(map);
|
||||
marker = L.marker([52.5, 13.5]).addTo(map)
|
||||
circle = L.circle([52.0, 13.0], {radius: 200000000}).addTo(map);
|
||||
marker = L.marker([52.0, 13.0]).addTo(map)
|
||||
|
||||
function update() {
|
||||
fetch('/json')
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
response.json()
|
||||
setTimeout("update()", 5000)
|
||||
})
|
||||
.then(data => {
|
||||
map.setView([data["lat"], data["lon"]], 18);
|
||||
circle.setLatLng([data["lat"], data["lon"]])
|
||||
|
|
Loading…
Reference in a new issue