Stuff
All checks were successful
continuous-integration/drone/push Build is passing

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" "encoding/json"
"html/template" "html/template"
"net/http" "net/http"
"time"
) )
var lastData map[string]interface{} var lastData map[string]interface{}
@ -13,6 +14,7 @@ var lastData map[string]interface{}
var templateContent []byte var templateContent []byte
var active = false var active = false
var activeSince time.Time
var getData = false 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) { http.HandleFunc("/json", func(writer http.ResponseWriter, request *http.Request) {
if getData == false || active == false { if getData == false || active == false {
writer.WriteHeader(http.StatusInternalServerError) writer.WriteHeader(http.StatusInternalServerError)
return return
} }
diff := time.Now().Sub(activeSince)
if diff.Minutes() > 2 {
active = false
writer.WriteHeader(http.StatusInternalServerError)
return
}
data := make(map[string]interface{}) data := make(map[string]interface{})
data["lat"] = lastData["lat"] data["lat"] = lastData["lat"]

View file

@ -15,18 +15,23 @@
<div id="map"></div> <div id="map"></div>
Last Update: <span id="update"></span> 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> <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', { L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map); }).addTo(map);
circle = L.circle([52.5, 13.5], {radius: 200}).addTo(map); circle = L.circle([52.0, 13.0], {radius: 200000000}).addTo(map);
marker = L.marker([52.5, 13.5]).addTo(map) marker = L.marker([52.0, 13.0]).addTo(map)
function update() { function update() {
fetch('/json') fetch('/json')
.then(response => response.json()) .then(response => {
response.json()
setTimeout("update()", 5000)
})
.then(data => { .then(data => {
map.setView([data["lat"], data["lon"]], 18); map.setView([data["lat"], data["lon"]], 18);
circle.setLatLng([data["lat"], data["lon"]]) circle.setLatLng([data["lat"], data["lon"]])