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"
|
"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"]
|
||||||
|
|
13
notfall.tmpl
13
notfall.tmpl
|
@ -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: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
attribution: '© <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"]])
|
||||||
|
|
Loading…
Reference in a new issue