Hier ist der vollständige Code:
Code: Alles auswählen
anzahl = 10
template = """
{% macro html(this, kwargs) %}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Draggable - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#maplegend" ).draggable({
start: function (event, ui) {
$(this).css({
right: "auto",
top: "auto",
bottom: "auto"
});
}
});
});
</script>
</head>
<body>
<div id='maplegend' class='maplegend'
style='position: absolute; z-index:9999; border:2px solid grey; background-color:rgba(255, 255, 255, 0.8);
border-radius:6px; padding: 10px; font-size:14px; right: 20px; bottom: 20px;'>
<div class='legend-title'>Points</div>
<div class='legend-scale'>
<ul class='legend-labels'>
<li><span style='background:red;opacity:0.9;'></span>Anzahl: {{ anzahl }}</li>
</ul>
</div>
</div>
</body>
</html>
<style type='text/css'>
.maplegend .legend-title {
text-align: left;
margin-bottom: 5px;
font-weight: bold;
font-size: 90%;
}
.maplegend .legend-scale ul {
margin: 0;
margin-bottom: 5px;
padding: 0;
float: left;
list-style: none;
}
.maplegend .legend-scale ul li {
font-size: 80%;
list-style: none;
margin-left: 0;
line-height: 18px;
margin-bottom: 2px;
}
.maplegend ul.legend-labels li span {
display: block;
float: left;
height: 16px;
width: 30px;
margin-right: 5px;
margin-left: 0;
border: 1px solid #999;
}
.maplegend .legend-source {
font-size: 80%;
color: #777;
clear: both;
}
.maplegend a {
color: #777;
}
</style>
{% endmacro %}"""
class Point:
def __init__(self, nr, sk ,time, lat ,lng):
self.NR = nr
self.SK = sk
self.TIME = time
self.LAT = lat
self.LNG =lng
def AddData(y):
obj = json.loads(y)
for x in Data:
if x.NR == obj['MAC']:
break
else:
tmp = obj['LOC'].split(';')
lat_values = tmp[0]
lon_values = tmp[1]
s = obj['MAC'].replace(':','')
Nr = int(str(int(s, 16))[0:4])
Points.append(Point(Nr,obj['SK'],obj['TIME'],lat_values,lon_values))
Points= []
m = folium.Map(
location=[51.240447, 6.508115],
zoom_start=19,
tiles='OpenStreetMap'
)
macro = MacroElement()
macro._template = Template(template)
tiles='OpenStreetMap'
msg = ({"MAC":"A4:CF:12:DF:6A:9B","SK":1,"LOC":"51.240747;6.508115","TIME":"14:20"})
y = json.dumps(msg)
AddData(y)
for x in Data:
c = "green"
if x.SK == 1:
c = "red";
elif x.SK==4:
c = "blue"
elif x.SK==0:
c = "white"
folium.Marker(
location=[x.LAT, x.LNG],
popup="Nr.: "+str(x.NR)+"\n Letzte Aktualisierung: "+x.TIME,
icon=folium.Icon(color = "black",icon_color=c, icon='user')
).add_to(m)
m.location =[x.LAT, x.LNG]
m.get_root().add_child(macro)
m
Auf der Karte wo ich in der Legende die Anzahl gerne anzeigen lassen würde steht dann nur "Anzahl:"