-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_geofences_vietate.js
93 lines (75 loc) · 2.87 KB
/
get_geofences_vietate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
getGeofencesVietate();
async function getGeofencesVietate() {
const response = await fetch('/geofenceVietate');
window.geofenceVietateData = await response.json();
await addGeofencesVietate(window.geofenceVietateData);
}
function addGeofencesVietate(data) {
var jsonFeatures = [];
data.forEach(function (geofVietate) {
var geometry = JSON.parse(geofVietate.geometry);
var feature = {
type: 'Feature',
properties: {
name: geofVietate.name,
},
geometry: geometry,
color: 'red'
};
jsonFeatures.push(feature);
});
var geoJson = {type: 'FeatureCollection', features: jsonFeatures};
window.geofenceVietate = L.geoJson(geoJson, {
style: geofenceStyle,
}).addTo(mymap);
function getColorGeofences(d) {
return d >= rangeArrayVietato[5] ? '#b90000' :
d >= rangeArrayVietato[4] ? '#d2413d' :
d >= rangeArrayVietato[3] ? '#e76a72' :
d >= rangeArrayVietato[2] ? '#f692a6' :
d >= rangeArrayVietato[1] ? '#febad7' :
d >= rangeArrayVietato[0] ? '#ffe4ff' :
'#000000';
}
function geofenceStyle(feature) {
if (vediAttivazioni) {
return {
fillColor: getColorGeofences(window.attivazioniGeofence[feature.properties.name].attivazioni),
weight: 3,
opacity: 1,
color: '#610000',
fillOpacity: 0.7
};
} else {
return {
fillColor: 'red',
weight: 3,
opacity: 1,
color: '#610000',
fillOpacity: 0.6
};
}
}
//Se dobbiamo visualizzare le attivazioni aggiungiamo anche la legenda alla mappa
if (vediAttivazioni) {
window.legendGeofenceVietate = L.control({position: 'bottomleft'});
window.legendGeofenceVietate.onAdd = function () {
var div = L.DomUtil.create('div', 'info legend'),
grades = rangeArrayVietato;
div.innerHTML = '<p>Attivazioni geofence vietate:</p>'
for (let i in grades) {
if (Math.trunc(grades[i]) - grades[i] < 0) {
grades[i] = Math.trunc(grades[i]) + 1;
}
}
// loop through our density intervals and generate a label with a colored square for each interval
for (var i = 0; i < grades.length; i++) {
div.innerHTML +=
'<i style="background:' + getColorGeofences(grades[i]) + '"></i> ' +
grades[i] + (grades[i + 1] ? ' – ' + (grades[i + 1] - 1) + '<br>' : '');
}
return div;
};
window.legendGeofenceVietate.addTo(mymap);
}
}