-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·219 lines (183 loc) · 5.89 KB
/
index.html
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Componsizione Acque Comune di Trento</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet-panel-layers.min.css" />
<style type="text/css">
body,html {
margin: 0;
}
#map {
position: absolute;
width: 100%;
height: 85%;
}
.leaflet-panel-layers-item{
font-size: 14px;
font-weight: bold;
padding: 2px;
}
.leaflet-panel-layers-item.active {
background: orange;
}
</style>
</head>
<body>
<h4>Componsizione Elementi nelle Acque del Comune di Trento • <a href="https://github.com/DigitalCommonsLab/acque-trentino">Source</a></h4>
<div id="map"></div>
<script src="https://unpkg.com/[email protected]/dist/jquery.js"></script>
<script src="https://unpkg.com/[email protected]/underscore.js"></script>
<script src="https://unpkg.com/[email protected]/dist/leaflet-src.js"></script>
<!-- <script src="https://unpkg.com/[email protected]/dist/leaflet.timeline.js"></script> -->
<script src="https://unpkg.com/[email protected]/dist/leaflet-panel-layers.src.js"></script>
<script src="https://unpkg.com/[email protected]/dist/leaflet-heat.js"></script>
<!-- <script src="https://unpkg.com/[email protected]/chroma.js"></script> -->
<script>
var elements = {
//'Ammonio': 1, //0.1
'Arsenico': 1, //0.5
//'Bicarbonato': 1, //140.12
'Calcio': 1, //34.8
//'Cloro residuo':1, //0.03
'Cloruro': 1, //0.6
//'ConducibilitÃ': 1, //226
//'Durezza': 1, //13
//'Enterococchi': 1, //0
//'Escherichia': 1, //0
'Fluoruro': 1, //0.09
'Magnesio': 1, //10.8
'Manganese': 1, //0.5
'Nitrato': 1, //2.8
//'Nitriti': 1, //0.02
'Potassio': 1, //0.38
//'Residuo fisso 180°':1, //144.64000000000001
'Sodio': 1, //0.5
'Solfato': 1, //11.7
//'TorbiditÃ': 1, //0.18
//'pH': 1, //8
};
//var osm = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'),
var osm = L.tileLayer('http://{s}.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png', {
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}),
map = new L.Map('map', {
zoom: 12,
maxZoom: 12,
minZoom: 10,
center: new L.latLng([46.07,11.1]),
layers: osm
});
var url = "https://api.apify.com/v1/execs/KTFWTkmxttzFs4SgH/results?simplified=1";
var geo;
var panel = L.control.panelLayers(null,null,{compact:true}).addTo(map);
$.getJSON(url, function(json) {
var data = json[0];
geo = L.geoJSON(null,{
pointToLayer: function(f, latlng) {
var m = L.circleMarker(latlng, {radius: 5, style: {fill:true,fillOpacity: 1,opacity:1}});
var props = _.pick(f.properties.values, _.keys(elements));
m.bindPopup('<pre>'+JSON.stringify(props,null,' ').replace(/[\{\}"]/g,'')+'</pre><label>valori in microg/l</label>');
return m;
}
});
//geo.addTo(map);
panel.addOverlay({
name: 'Sorgenti campionate',
layer: geo
})
var points = _.map(data.locs, function(v,k) {
var point = L.marker(v).toGeoJSON();
point.properties = {
name: data.names[k],
date: data.dates[k].split('-').reverse().join('-'),
values: _.object(data.params, data.values[k])
};
geo.addData(point);
return point;
});
for(var e in elements) {
if(!elements[e]) continue;
var max = 1;
var grad = {};
var heatPoints = _.map(points, function(p) {
var cc = p.geometry.coordinates,
val = p.properties.values[ e ];
//max = val>1 ? 100 : 1;
//
val = val>1 ? val/100 : val;
//console.log(e, max, val);
return [cc[1], cc[0], Math.round(val,4) ];
});
/*
//CUSTOM gradient COLOR SCALE using chroma.js
//http://gka.github.io/chroma.js/#scale-classes
var values = _.map(heatPoints, function(p) {
return p[2];
});
//var spect = 'Spectral';
var spect = 'YlGnBu';
var limit = 'logarithmic';
//var limit = 'quantiles';
var scale = chroma.scale(spect).domain(values, 10, limit);
//var scale = chroma.scale(['lightyellow', 'navy']).domain([0, max], 7, 'log');
var gradCount = _.range(0,max, 0.01);
_.map(gradCount, function(i) {
grad[ i ] = scale(i).hex()
});
console.log(e, values, gradCount, grad);
*/
var heat = L.heatLayer(heatPoints, {
radius: 40,
minOpacity: 1,
blur: 100,
//gradient: grad, //example: {0: 'red', 0.5: 'lime', 1: 'yellow'},
max: max
})
if(e=='Arsenico')
heat.addTo(map);
//panel.addOverlay({
panel.addBaseLayer({
name: e,
layer: heat
});
}
/*
var geojson = geo.toGeoJSON();
var timelineControl = L.timelineSliderControl({
//formatOutput: function(date) {
// console.log(date)
// return new Date(date).toString();
//}
});
var timeline = L.timeline(geojson, {
//getInterval: function(f) {
// console.log(f.properties.date)
//return {
// start: f.properties.date
//};
//},
formatDate: function(date) {
console.log(date)
return new Date(date).toString();
},
pointToLayer: function(data, latlng) {
//var hue_min = 120;
//var hue_max = 0;
//var hue = data.properties.mag / 10 * (hue_max - hue_min) + hue_min;
return L.circleMarker(latlng, {
radius: 10,//data.properties.mag * 3,
//color: "hsl("+hue+", 100%, 50%)",
//fillColor: "hsl("+hue+", 100%, 50%)"
})//.bindPopup(JSON.stringify(data.properties));
}
});
timelineControl.addTo(map)
timelineControl.addTimelines(timeline);
timeline.addTo(map);*/
});
</script>
</body>
</html>