index.html 3.98 KB
Newer Older
Joe TS Dell's avatar
update  
Joe TS Dell committed
1
2
<html>
<head>
Rushikesh Padsala's avatar
Rushikesh Padsala committed
3
4
<title>Building - Heat Demand</title>
	<meta charset="utf-8">
Joe TS Dell's avatar
update  
Joe TS Dell committed
5
6
7
8
9
10
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"
        integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
        crossorigin="">
    <script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"
        integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
11
12
13
        crossorigin=""></script>
     <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>   
    <script src="building_data.js"></script>
Joe TS Dell's avatar
update  
Joe TS Dell committed
14
15
16
    <link rel="stylesheet" href="index.css">
</head>
<body>
17
    <div id="map-container">
Rushikesh Padsala's avatar
Rushikesh Padsala committed
18
		<div id="mapid"></div>
19
20
21
22
    </div>
    <div id="chart-container">
        <canvas id="yocChart"></canvas>
    </div>
Rushikesh Padsala's avatar
Rushikesh Padsala committed
23
24
25
<script>
    var mymap = L.map('mapid').setView([48.79205, 9.20758], 16);
    var OpenStreetMap_DE = L.tileLayer('https://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png', {
Joe TS Dell's avatar
update  
Joe TS Dell committed
26
27
28
29
            maxZoom: 18,
            attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
        });
        // select one basemap from https://leaflet-extras.github.io/leaflet-providers/preview/
Rushikesh Padsala's avatar
Rushikesh Padsala committed
30
    var CartoDB_Positron = L.tileLayer('https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png', {
Joe TS Dell's avatar
update  
Joe TS Dell committed
31
32
33
34
35
36
            attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors &copy; <a href="https://carto.com/attributions">CARTO</a>',
            subdomains: 'abcd',
            maxZoom: 19
        });
        CartoDB_Positron.addTo(mymap);

Rushikesh Padsala's avatar
Rushikesh Padsala committed
37
    function onEachFeature(feature, layer) {
Joe TS Dell's avatar
update  
Joe TS Dell committed
38
39
40
41
42
43
44
            layer.bindPopup(
                '<h4>' +
                feature.properties.gml_id + '</h4><p>Specific Space Heating Demand: ' + feature.properties
                .Specific_s +
                '[kWh/m².year] </p>');
        }

Rushikesh Padsala's avatar
Rushikesh Padsala committed
45
    function getColor(d) {
Joe TS Dell's avatar
update  
Joe TS Dell committed
46
47
48
49
50
51
52
            return d > 250 ? '#F22E22' :
                d > 200 ? '#F56D1F' :
                d > 150 ? '#F9A717' :
                d > 125 ? '#FECE02' :
                d > 100 ? '#F6EC00' :
                d > 75 ? '#D1E023' :
                d > 50 ? '#B2D531' :
53
                d > 25 ? '#A4C711' :
Joe TS Dell's avatar
update  
Joe TS Dell committed
54
55
56
57
                d > 0 ? '#61B949' :
                '#FFEDA0';
        }

Rushikesh Padsala's avatar
Rushikesh Padsala committed
58
    function style(feature) {
Joe TS Dell's avatar
update  
Joe TS Dell committed
59
60
61
62
63
64
65
66
67
            return {
                fillColor: getColor(feature.properties.Specific_s),
                weight: 1,
                opacity: 1,
                color: 'white',
                // dashArray: '3',
                fillOpacity: 0.95
            };
        }
Rushikesh Padsala's avatar
Rushikesh Padsala committed
68
69
70
    L.geoJSON(building_data, {
        onEachFeature: onEachFeature,
        style: style,
Joe TS Dell's avatar
update  
Joe TS Dell committed
71
        }).addTo(mymap);
72
		
Rushikesh Padsala's avatar
Rushikesh Padsala committed
73
74
75
76
// Retrieve the building year of construction data from the GeoJSON
	var buildingYoc = building_data.features.map(function(feature) {
		return feature.properties.Year_of_co;
		});
77
78

// Count the occurrences of each building age
Rushikesh Padsala's avatar
Rushikesh Padsala committed
79
80
81
82
83
84
85
86
	var yocCounts = {};
		buildingYoc.forEach(function(Year_of_co) {
		if (yocCounts[Year_of_co]) {
			yocCounts[Year_of_co]++;
			} else {
			yocCounts[Year_of_co] = 1;
			}
		});
87
88

// Prepare the chart data
Rushikesh Padsala's avatar
Rushikesh Padsala committed
89
90
	var yocLabels = Object.keys(yocCounts);
	var yocData = Object.values(yocCounts);
91
92

// Create the building year of construction distribution chart using Chart.js
Rushikesh Padsala's avatar
Rushikesh Padsala committed
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
	var ctx = document.getElementById('yocChart').getContext('2d');
	var yocChart = new Chart(ctx, {
		type: 'bar',
		data: {
		labels: yocLabels,
		datasets: [{
		label: 'No. of buildings',
		data: yocData,
		backgroundColor: 'rgba(75, 192, 192, 0.5)',
		borderColor: 'rgba(75, 192, 192, 1)',
		borderWidth: 1
		}]
	},
		options: {
			responsive: true,
			plugins: {
			legend: {
			position: 'bottom',
			},
			title: {
				display: true,
				text: 'Building Distribution According to its Year of Construction'
				}
				},
117
118
119
120
121
122
123
124
    scales: {
      y: {
        beginAtZero: true,
        stepSize: 15
      }
    }
  }
});
125
</script>
Joe TS Dell's avatar
update  
Joe TS Dell committed
126
</body>
127
</html>