-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBarvid19.js
574 lines (425 loc) · 15.3 KB
/
Barvid19.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
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
// Making a map and tile
const map = L.map('map', {zoomControl: false, condensedAttributionControl: false }).setView([14.5700, 121.0223], 11.5);
const attribution =
' © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> | <a href="https://www.mapbox.com/">Mapbox</a> contributors' ;
const tileUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
const tileUrl2 = 'https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw';
const tiles = L.tileLayer(tileUrl, { attribution });
tiles.addTo(map);
grayscale = L.tileLayer(tileUrl2, {id: 'mapbox/light-v9', tileSize: 512, zoomOffset: -1, attribution: attribution})
var info = L.control();
var info_1 = L.control();
var zoomHome = L.Control.zoomHome();
zoomHome.addTo(map);
var sidebar = L.control.sidebar('sidebar').addTo(map);
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info');
this.update();
return this._div;
};
info.update = function (props) {
this._div.innerHTML = '<div style=\"color: blue\"> <p class="ex1">Barangay</p>' + (props ?
'<b>' + props.Barangay + ", "+ '<br>' + props.City + '</b></div>' + '<div style=\"color: red\"> <p class="ex1">Confirmed Cases</p>'+ '<b>' + props.Confirmed_Cases + '</div> '
: 'Hover over a barangay');
};
info.addTo(map);
//L.control.navbar().addTo(map);
// get color depending on confirmed cases value
function getColor(d) {
return d > 30 ? '#cc0000':
d > 25 ? '#e60000':
d > 20 ? '#ff0000':
d > 15 ? '#ff4000' :
d > 10 ? '#ff8000' :
d > 5 ? '#ffbf00' :
d >= 1 ? '#ffff00 ':
'green';
}
function style(feature) {
return {
weight: 1.2,
opacity: 1,
color: 'black',
fillOpacity: 0.5,
fillColor: getColor(feature.properties.Confirmed_Cases)
};
}
// ncr_barangay highlight feature
function highlightFeature_barangay(e) {
var layer = e.target;
layer.setStyle({
weight: 1.2,
color: 'black',
fillOpacity: 0.1
});
if (!L.Browser.ie && !L.Browser.opera && !L.Browser.edge) {
layer.bringToFront();
}
info.update(layer.feature.properties);
}
// confirmed highlightfeature
function highlightFeature_confirmed(e) {
var layer = e.target;
layer.setStyle({
weight: 1.0,
color: 'black',
fillOpacity: 0.1
});
if (!L.Browser.ie && !L.Browser.opera && !L.Browser.edge) {
layer.bringToFront();
}
info.update(layer.feature.properties);
}
// city highlightfeature
function highlightFeature_city(e) {
var layer = e.target;
layer.setStyle({
weight: 1.0,
color: 'black',
fillOpacity: 0.1
});
if (!L.Browser.ie && !L.Browser.opera && !L.Browser.edge) {
layer.bringToFront();
}
info.update(layer.feature.properties);
}
//Areas Under GCQ and ECQ
function highlightFeature_GCQ(e) {
var layer = e.target;
layer.setStyle({
weight: 1.0,
color: 'black',
fillOpacity: 0.1
});
if (!L.Browser.ie && !L.Browser.opera && !L.Browser.edge) {
layer.bringToFront();
}
info.update(layer.feature.properties);
}
//Barangay with Extreme Enchanced Community Quarantine
function highlightFeature_eecq(e) {
var layer = e.target;
layer.setStyle({
weight: 1.0,
color: 'black',
fillOpacity: 0.1
});
if (!L.Browser.ie && !L.Browser.opera && !L.Browser.edge) {
layer.bringToFront();
}
info.update(layer.feature.properties);
}
var ncr_barangay;
var confirmed;
var ncr_city;
var hospitals;
var testingcenter;
var quarantinefacilities;
var Areas_ECQ_GCQ;
var eecq;
// ncr_barangay functions
function resetHighlight_barangay(e) {
ncr_barangay.resetStyle(e.target);
info.update();
}
function zoomToFeature(e) {
map.fitBounds(e.target.getBounds());
}
function onEachFeature(feature, layer) {
layer.on({
mouseover: highlightFeature_barangay,
mouseout: resetHighlight_barangay,
click: zoomToFeature
});
}
// confirmed functions
function resetHighlight_confirmed(e) {
confirmed.resetStyle(e.target);
info.update();
}
function onEachFeature_confirmed(feature, layer) {
layer.on({
mouseover: highlightFeature_confirmed,
mouseout: resetHighlight_confirmed,
click: zoomToFeature
});
}
// ncr_city functions
function resetHighlight_city(e) {
ncr_city.resetStyle(e.target);
info.update();
}
function onEachFeature_city(feature, layer) {
layer.on({
mouseover: highlightFeature_city,
mouseout: resetHighlight_city,
click: zoomToFeature
});
}
// Areas Under ECQ and GCQ until may 31
function resetHighlight_GCQ(e) {
Areas_ECQ_GCQ.resetStyle(e.target);
info.update();
}
function onEachFeature_GCQ(feature, layer) {
layer.bindPopup('<strong style="color: darkred;"> '+ feature.properties.Region + '</strong><br/>');
layer.on({
mouseover: highlightFeature_GCQ,
mouseout: resetHighlight_GCQ,
click: zoomToFeature
});
}
// Barangay with Extreme Enhanced Community Quarantine
function resetHighlight_eecq(e) {
eecq.resetStyle(e.target);
info.update();
}
function onEachFeature_eecq(feature, layer) {
layer.on({
mouseover: highlightFeature_eecq,
mouseout: resetHighlight_eecq,
click: zoomToFeature
});
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ncr geojson
ncr_barangay = L.geoJson(barangay_js, {
style: style,
onEachFeature: onEachFeature,
}).addTo(map)
//confirmed geojson
confirmed = L.geoJson(barangay_js, {
style: function(feature){
var fillColor,
confirmed = feature.properties.Confirmed_Cases;
if (confirmed >= 1) fillColor ='red';
else if (confirmed == 0) fillColor ='green';
else fillColor='black';
return { color:'black', weight:1.2, fillColor:fillColor, fillOpacity:0.5}
},
onEachFeature: onEachFeature_confirmed
})
// ncr_city geojson
ncr_city= L.geoJson(city_geo, {
style: function(feature){
var fillColor,
confirmed = feature.properties.Confirmed_Cases;
if (confirmed > 500) fillColor ='#cc0000';
else if (confirmed > 400) fillColor ='#e60000';
else if (confirmed > 300) fillColor ='#ff0000';
else if (confirmed > 200) fillColor ='#ff4000';
else if (confirmed > 100) fillColor ='#ff8000';
else if (confirmed > 1) fillColor ='#ffbf00';
else if (confirmed == 0) fillColor ='#ffff00 ';
else fillColor='black';
return { color:'black', weight:1.2, fillColor:fillColor, fillOpacity:0.5}
},
onEachFeature: onEachFeature_city,
})
// Areas under GCQ & ECQ until may 31
Areas_ECQ_GCQ = L.geoJson(AreasECQGCQ, {
style: function(feature){
var fillColor,
Class = feature.properties.Class;
if (Class >= 3) fillColor ='red';
else if (Class >= 2) fillColor ='yellow';
else if (Class >= 1) fillColor = 'green';
else fillColor='black';
return { color:'black', weight:1.2, fillColor:fillColor, fillOpacity:0.5};
},
onEachFeature: onEachFeature_GCQ,
})
// Barangay with Extreme Enhanced Community Quarantine
eecq = L.geoJson(EECQ, {
style: function(feature){
var fillColor,
confirmed = feature.properties.Confirmed_Cases;
if (confirmed >= 1) fillColor ='red';
else fillColor='black';
return { color:'black', weight:1.2, fillColor:fillColor, fillOpacity:0.5};
},
onEachFeature: onEachFeature_eecq,
})
// Hospital
var hosticon = L.icon({
iconUrl: 'https://www.shareicon.net/data/512x512/2016/04/21/753224_hospital_512x512.png',
iconSize: [30,30],
});
hospital = L.geoJson(ncr_hospitals,{
pointToLayer:function(feature, latlng){
var marker = L.marker(latlng, {icon: hosticon});
marker.bindPopup('<b>Hospital:</b> <strong style="color: green;"> '+ feature.properties.Hospitals + '</strong><br/>' + '<b>Address:</b> <span style=\"color": green;"> ' + feature.properties.Address + '<br/>' + '<b>Status:</b> <strong style="color: orange;"> ' + feature.properties.Status + '</strong>');
return marker;
}
})
var cluster = L.markerClusterGroup({});
cluster.addLayer(hospital);
//Testing Center
var centericon = L.icon({
iconUrl: 'testing_center.png',
iconSize: [30,30],
});
testingcenter= L.geoJson(testing_center,{
pointToLayer:function(feature, latlng){
var marker = L.marker(latlng, {icon: centericon});
marker.bindPopup('<b>Hospital:</b> <strong style="color: green;"> '+ feature.properties.testing_center + '</strong><br/>' + '<b>Address:</b> <span style=\"color": green;"> ' + feature.properties.Address + '<br/>' + '<b>Number of Test:</b> <strong style="color: orange;"> ' + feature.properties.Test + '</strong>');
return marker;
}
})
var cluster_center = L.markerClusterGroup({});
cluster_center.addLayer(testingcenter);
// Quarantine facilities
var quarantineicon = L.icon({
iconUrl: 'quarantinefacilities.png',
iconSize: [30,30],
});
quarantinefacilities = L.geoJson(facilities_js,{
pointToLayer:function(feature, latlng){
var marker = L.marker(latlng, {icon: quarantineicon});
marker.bindPopup('<b>Quarantine Center:</b> <strong style="color: green;"> '+ feature.properties.Facilities + '</strong><br/>' + '<b>Address:</b> <span style=\"color": green;"> ' + feature.properties.Address + '<br/>' + '<b>Capacity:</b> <strong style="color: red;"> ' + feature.properties.Capacity + '</strong>');
return marker;
}
})
var cluster_quarantine= L.markerClusterGroup({});
cluster_quarantine.addLayer(quarantinefacilities);
var baseMaps = {
"<b>Open Street Map</b>": tiles,
"<b>Gray Scale</b>": grayscale,
};
var groupedOverlays = {
"ECQ & GCQ":{
"Areas Under ECQ & GCQ Until May 31":Areas_ECQ_GCQ
},
"COVID-19 Case/s": {
"Barangay View": ncr_barangay,
"City View": ncr_city,
"Barangay with confirmed and no case/s": confirmed,
"Barangay with Extreme Enhanced Community Quarantine": eecq
},
"COVID-19 Health Facilities": {
"<img src='https://www.shareicon.net/data/512x512/2016/04/21/753224_hospital_512x512.png' height='25' width='25' /> <span class='my-layer-item'>Hospital</span>": cluster,
"<img src='testing_center.png' height='25' width='25' /> <span class='my-layer-item'>Testing Center</span>": cluster_center,
"<img src='quarantinefacilities.png' height='25' width='25' /> <span class='my-layer-item'>Quarantine Center</span>": cluster_quarantine
}
};
//L.control.layers(baseMaps, groupedOverlays).addTo(map)
L.control.groupedLayers(baseMaps, groupedOverlays).addTo(map);
var searchControl = new L.Control.Search( {
layer: ncr_barangay,
propertyName: 'Barangay',
textPlaceholder: 'Search for Barangay',
marker: false,
moveToLocation: function(latlng, title, map) {
//map.fitBounds( latlng.layer.getBounds() );
var zoom = map.getBoundsZoom(latlng.layer.getBounds());
map.setView(latlng, zoom); // access the zoom
}
});
searchControl.on('search:locationfound', function(e) {
//console.log('search:locationfound', );
//map.removeLayer(this._markerSearch)
e.layer.setStyle({fillOpacity: 0.1, color: 'black'});
if(e.layer._popup)
e.layer.openPopup();
}).on('search:collapsed', function(e) {
featuresLayer.eachLayer(function(layer) { //restore feature color
featuresLayer.resetStyle(layer);
});
});
map.addControl( searchControl );
map.attributionControl.addAttribution('<a href="https://www.linkedin.com/in/gabriel-joshua-miguel/">Developer</a> Last update July 19')
map.addControl(L.control.locate({
setView:'always',
strings: {
title: "Show my location"
},
locateOptions: {
maxZoom: 200,
enableHighAccuracy: true
}}));
var barangay_legend = L.control({position: 'bottomright'});
var confirmed_legend = L.control({position: 'bottomright'});
var city_legend = L.control({position: 'bottomright'})
var GCQ_ECQ_legend = L.control({position:'bottomright'});
barangay_legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend');
//labels = ['<strong>Confirmed Cases</strong>'];
div.innerHTML += '<strong>Confirmed Cases</strong><br>';
div.innerHTML += '<i style="background: green"></i><span>No Case/s</span><br>';
div.innerHTML += '<i style="background: #ffbf00"></i><span>1-5</span><br>';
div.innerHTML += '<i style="background: #ff8000"></i><span>5-10</span><br>';
div.innerHTML += '<i style="background: #ff4000"></i><span>10-15</span><br>';
div.innerHTML += '<i style="background: #ff0000"></i><span>15-20</span><br>';
div.innerHTML += '<i style="background: #e60000"></i><span>20-25</span><br>';
div.innerHTML += '<i style="background: #cc0000"></i><span>30+</span><br>';
return div;
};
confirmed_legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend');
div.innerHTML += '<i style="background: red"></i><span>Confirmed Case/s</span><br>';
div.innerHTML += '<i style="background: green"></i><span>No Confirmed Case/s</span><br>';
return div;
};
barangay_legend.addTo(map);
city_legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend');
div.innerHTML += '<strong>Confirmed Cases</strong><br>';
div.innerHTML += '<i style="background: green"></i><span>No Case/s</span><br>';
div.innerHTML += '<i style="background: #ffbf00"></i><span>1-100</span><br>';
div.innerHTML += '<i style="background: #ff8000"></i><span>100-200</span><br>';
div.innerHTML += '<i style="background: #ff4000"></i><span>200-300</span><br>';
div.innerHTML += '<i style="background: #ff0000"></i><span>300-400</span><br>';
div.innerHTML += '<i style="background: #e60000"></i><span>400-500</span><br>';
div.innerHTML += '<i style="background: #cc0000"></i><span>500+</span><br>';
//labels = ['<strong>Confirmed Cases</strong>'];
return div;
};
GCQ_ECQ_legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend');
//labels = ['<strong>Confirmed Cases</strong>'];
div.innerHTML += '<i style="background: green"></i><span>Minimum Health Standards No ECQ or GCQ</span><br>';
div.innerHTML += '<i style="background: yellow"></i><span>General Community Quarantine</span><br>';
div.innerHTML += '<i style="background: red"></i><span>Modified Enchanced Community Quarantine</span><br>';
return div;
};
map.on('overlayadd', function (eventLayer) {
// Switch to the Population legend...
if (eventLayer.name == 'Barangay View') {
this.removeControl(confirmed_legend);
this.removeControl(city_legend);
this.removeControl(GCQ_ECQ_legend);
barangay_legend.addTo(this);
} else if (eventLayer.name =='Barangay with confirmed and no case/s') { // Or switch to the Population Change legend...
this.removeControl(barangay_legend);
this.removeControl(city_legend);
this.removeControl(GCQ_ECQ_legend);
confirmed_legend.addTo(this);
} else if (eventLayer.name =='City View') { // Or switch to the Population Change legend...
this.removeControl(barangay_legend);
this.removeControl(confirmed_legend);
this.removeControl(GCQ_ECQ_legend);
city_legend.addTo(this);
} else if (eventLayer.name =='Areas Under ECQ & GCQ Until May 31') { // Or switch to the Population Change legend...
this.removeControl(barangay_legend);
this.removeControl(confirmed_legend);
this.removeControl(city_legend);
GCQ_ECQ_legend.addTo(this);
}
else {
this.removeControl(barangay_legend);
this.removeControl(confirmed_legend);
this.removeControl(city_legend);
this.removeControl(GCQ_ECQ_legend);
}
});
L.control.fullscreen(
{"forceSeparateButton": true, "position": "topright", "title": "Expand me", "titleCancel": "Exit me"}
).addTo(map);
map.on('enterFullscreen', function(){
console.log('entered fullscreen');
});
map.on('exitFullscreen', function(){
console.log('exited fullscreen');
});
// you can also toggle fullscreen from map object
//map.toggleFullScreen();