-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
345 lines (268 loc) · 13.1 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
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Final Project BG Hospitals</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.2.0/leaflet.css" type="text/css" crossorigin="">
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.2.0/leaflet.js" crossorigin=""></script>
<script src="https://unpkg.com/[email protected]/dist/leaflet-src.js" integrity="sha512-WXoSHqw/t26DszhdMhOXOkI7qCiv5QWXhH9R7CgvgZMHz1ImlkVQ3uNsiQKu5wwbbxtPzFXd1hK4tzno2VqhpA==" crossorigin=""></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<link rel="stylesheet" href="style2_April26th_6.30pm.css" type="text/css">
<link rel="stylesheet" href="style.css" type="text/css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/2.2.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/2.2.1/css/bootstrap.min.css">
<!-- <script src="cities2.js"></script> -->
<script src="cities_dist2.js"></script>
<script src="bg_hostpitals_gisco_geojson_4326.js"></script>
<script src="vw_provinces_nsi_hospitals_4326.js"></script>
<link rel="stylesheet" href="MarkerCluster.css" />
<link rel="stylesheet" href="MarkerCluster.Default.css" />
<script src="leaflet.markercluster-src.js"></script>
<link rel="stylesheet" href="leaflet-search-master\dist\leaflet-search.src.css">
<script src="leaflet-search-master\dist\leaflet-search.src.js"></script>
<script type="text/javascript">
// Variables
var map;
var hospitalLayer;
// Selection variables
var selection;
var selectedLayer;
//var selectedFeature;
function init() {
// create map and set center and zoom level
map = new L.map('mapid');
map.setView([42.7339, 25.4858],7);
// create carto basemap
var cartoGrey = L.tileLayer('https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors'
});
cartoGrey.addTo(map);
// create and add osm tile layer
var osm = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
});
// create osm humanitarian layer (not adding it to map)
var osmHumanitarian = L.tileLayer('https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
});
function polystyle(feature) {
return {
// fillColor: 'beige', // polygon color - now left blank
fillOpacity: 0, //polygon opacity
weight: 4,
opacity: .1, //Outline opacity
color: 'green' //Outline color
};
}
var provinceLayer = L.geoJSON(vw_provincesData, {
style:polystyle, // from style function defined above
onEachFeature: function(feature, layer) {
layer.bindPopup('<b>' + feature.properties.provinces_en + ' Province </b><br> Public Hospitals in Province: ' + feature.properties.state_hospitalstate_hospital + '<br> Public Hospital Beds in Province: ' + feature.properties.beds_state_hospital)}
}).addTo(map);
// create icons for hospitals (selected and unselected)
var hospitalIcon = L.icon({
iconUrl: 'hospital_unselected.svg', //default orange hospital icon
iconSize: [30,30] //[20,20] //[40,40]
});
var selectedHospitalIcon = L.icon({
iconUrl: 'hospital_selected.svg', //selected blue hospital icon
iconSize: [30,30] //[20,20] //[40,40]
});
// handle click events on hospital features
function hospitalsOnEachFeature(feature, layer){
layer.on({
click: function(e) {
if (selection) {
resetStyles();
}
e.target.setIcon(selectedHospitalIcon); //selected hospital based on click event
selection = e.target;
selectedLayer = hospitalLayer;
// Insert HTML with the feature name
buildSummaryLabel(feature);
L.DomEvent.stopPropagation(e); // stop click event from being propagated further
}
});
}
// Hospital Custom radius and icon create function
var markersHospital = L.markerClusterGroup({
maxClusterRadius: 120,
iconCreateFunction: function (cluster) {
var childCount = cluster.getChildCount();
var c = ' marker-hospital-';
if (childCount < 10) {
c += 'small';
} else if (childCount < 100) {
c += 'medium';
} else {
c += 'large';
}
return new L.DivIcon({ html: '<div><span>' + childCount + '</span></div>', className: 'marker marker-hospital' + c, iconSize: new L.Point(40, 40) });
},
//Disable all of the defaults:
disableClusteringAtZoom:14, spiderfyOnMaxZoom: false, showCoverageOnHover: false, zoomToBoundsOnClick: true
});
var hospitalLayer = new L.geoJSON(hospitalData,{
pointToLayer: function (feature, latlng) {
return L.marker(latlng, {icon: hospitalIcon});
},
onEachFeature: hospitalsOnEachFeature
}
);
//hospitalLayer.addTo(map)
markersHospital.addLayer(hospitalLayer).addTo(map);
// handle clicks on the map that didn't hit a feature
map.addEventListener('click', function(e) {
if (selection) {
resetStyles();
selection = null;
document.getElementById('summaryLabel').innerHTML = '<p>Click a hospital on the map to get more information.</p>';
}
});
// function to set the old selected feature back to its original symbol. Used when the map or a feature is clicked.
function resetStyles(){
if (selectedLayer === hospitalLayer) selection.setIcon(hospitalIcon);
else if (selectedLayer === otherLayer) selectedLayer.resetStyle(selection);
}
// function to build the HTML for the summary label using the selected feature's "name" property
function buildSummaryLabel(currentFeature){
var featureName = currentFeature.properties.hospital_name || "Unnamed feature";
var featureCity = currentFeature.properties.city || ""; // Hospital City
var bedCapacity = currentFeature.properties.cap_beds || ""; // Bed Capacity
var summaryHTML = '<p style="font-size:18px"><b>Hospital:</b> ' + featureName + '</p>';
// Concatenate the additional label if it exists
if (featureCity !== "") {summaryHTML += '<p><b>City:</b> ' + featureCity + '</p>';}
if (bedCapacity !== "") {summaryHTML += '<p><b>Bed Capacity:</b> ' + bedCapacity + '</p>';}
document.getElementById('summaryLabel').innerHTML = summaryHTML;
}
//City cluster variables
var markers = L.markerClusterGroup({
maxClusterRadius: 90,
iconCreateFunction: function (cluster) {
var childCount = cluster.getChildCount();
var c = ' marker-city-';
if (childCount < 10) {
c += 'small';
} else if (childCount < 100) {
c += 'medium';
} else {
c += 'large';
}
return new L.DivIcon({ html: '<div><span>' + childCount + '</span></div>', className: 'marker marker-city' + c, iconSize: new L.Point(40, 40) });
},
//Disable all of the defaults:
spiderfyOnMaxZoom: true, showCoverageOnHover: false, zoomToBoundsOnClick: true
});
// city styling
var geojsonMarkerOptions = {
radius: 8,
fillColor: "#8dd3c7", //"#ff7800",
color: "#000",
weight: .8,
opacity: .7,
fillOpacity: 0.7
};
// cities
var geojsonLayer = L.geoJSON(citiesData, {
pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng, geojsonMarkerOptions);
},
onEachFeature: function(feature, layer) {
var cityName = feature.properties.city_name_en || feature.properties.city_name_bg;
var distance = (feature.properties.dist / 1000).toFixed(1); // Rounds to one decimal place
layer.bindPopup('City: <b>' + cityName + ' </b> <br>Distance to nearest hospital: <b>' + distance + ' km</b> <br>Hospital: <b> '+ feature.properties.hospital_name +' </b>')}
});
//.addTo(map);
// add cities clusters to map
markers.addLayer(geojsonLayer)
map.addLayer(markers)
// Unclustered city2 styling
function geojsonMarkerOptionsColor (feature) {
var distance_km = feature.properties.dist; // Accessing distance from feature.properties
if (distance_km > 62200) {
return { fillColor: "#d73027", weight: 0, fillOpacity: 0.5 }; // Style for distance > 62.2 km
} else if (distance_km > 34600) {
return { fillColor: "#d73027", weight: 0, fillOpacity: 0.5 }; // Style for 34.6 km - 62.2 km
} else if (distance_km > 23400) {
return { fillColor: "#fc8d59", weight: 0, fillOpacity: 0.5 }; // Style for 23.4 km - 34.6 km
} else if (distance_km > 15500) {
return { fillColor: "#fee090", weight: 0, fillOpacity: 0.5 }; // Style for 15.5 km - 23.4 km
} else if (distance_km > 8700) {
return { fillColor: "#b5e8f5", weight: 0, fillOpacity: 0.5 }; // Style for 8.7 km - 15.5 km
} else {
return { fillColor: "#91bfdb", weight: 0, fillOpacity: 0.5 }; // Default style for less than 8.7 km
}
}
// Unclustered city2 geoJSON and pop-up
var geojsonColorLayer = L.geoJSON(citiesData, {
pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng, geojsonMarkerOptionsColor(feature)); // Pass feature to the function
},
onEachFeature: function(feature, layer) {
var cityName = feature.properties.city_name_en || feature.properties.city_name_bg;
var distance = (feature.properties.dist / 1000).toFixed(1); // Rounds to one decimal place
layer.bindPopup('City: <b>' + cityName + ' </b> <br>Distance to nearest hospital: <b>' + distance + ' km</b> <br>Hospital: <b> '+ feature.properties.hospital_name +' </b>');
},
});
// define basemap and thematic layers and add layer switcher control
var basemaps = {
"OSM": osm,
"OSM Humanitarian": osmHumanitarian,
"Carto Grey": cartoGrey
};
var overlays = {
"Hospitals Clustered": markersHospital,
"Cities Clustered": markers,
"Most Vunerable Places": geojsonColorLayer,
"Provinces": provinceLayer
};
L.control.layers(basemaps,overlays).addTo(map);
//Search
// city search
const citySearchControl = new L.Control.Search({
position: 'topright',
autoCollapse: true,
layer: markers,
zoom: 13,
propertyName: 'city_name_en'
});
map.addControl(citySearchControl);
// province search
const provinceSearchControl = new L.Control.Search({
position: 'topright',
autoCollapse: true,
layer: provinceLayer,
zoom: 9,
propertyName: 'provinces_en'
});
map.addControl(provinceSearchControl);
}
</script>
</head>
<div class="general">
<body onload="init()">
<div class="left">
<div class="title"><h1>Hospital Accessibility in Bulgaria</h1></div>
<div id="mapid"></div>
<img src="Distance from Hospital Distribution.png" alt="Distance From Hospital Histogram">
<img src="ScatterPlot_best_fit.png" alt="Scatter Plot Population and Distance to Hospital">
<img src="Hospital Beds per 1000 People by Province.png" alt="hospital beds per 1000 by province">
<img src="Top_20_Nearest Cities_final.png" alt="Top 20 Hospitals with Highest Number of Nearest Cities">
</div>
<div class="right">
<div class="layers"><b>Click here for layers</b></div>
<div class="city-search"> <b>Search cities</b></div>
<div class="province-search"><b>Search provinces</b></div>
<div id = 'summaryLabel'>
<h3>Legend</h3>
<img src="legend_icon_green.png" alt="Hospital Clusters"> Hospital Clusters<br>
<img src="legend_icon_blue.png" alt="Hospital Clusters"> City Clusters<br>
<br><p>Click on the <b>hospital icon</b> to get <br> more information about a particular hospital. <br><br>
Click on a <b>province</b> to find the total number of <br> state hospital beds in the province. </p></div>
</div>
</div>
</body>
</html>