Stuff
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Kekskurse 2022-01-16 13:12:21 +01:00
parent 2fe93c77d7
commit c825ccbb0e
Signed by: kekskurse
GPG Key ID: 728ACCB59341E7E4
2 changed files with 24 additions and 4 deletions

15
main.go
View File

@ -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"]

View File

@ -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: '&copy; <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"]])