Repository navigation
Expand file tree
/
Copy pathMap.html
More file actions
133 lines (105 loc) · 3.74 KB
/
Copy pathMap.html
File metadata and controls
133 lines (105 loc) · 3.74 KB
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
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js"
integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew=="
crossorigin=""></script>
<div id="map"></div>
<script type="text/javascript" src="us-states.js"></script>
<!--<script type="text/javascript" src="countries-old.js"></script>-->
<!--Source for emission levels-->
<script type="text/javascript" src="CountryData/countries - 2014.js"></script>
<style>
#map { height: 100%; }
body { margin: 0; }
.info { padding: 6px 8px; font: 14px/16px Arial, Helvetica, sans-serif; background: white; background: rgba(255,255,255,0.8); box-shadow: 0 0 15px rgba(0,0,0,0.2); border-radius: 5px; } .info h4 { margin: 0 0 5px; color: #777; }
.legend { text-align: left; line-height: 18px; color: #555; } .legend i { width: 18px; height: 18px; float: left; margin-right: 8px; opacity: 0.7; }
</style>
<script>
var mapboxAccessToken = "pk.eyJ1IjoiZWR0ZWFncmUiLCJhIjoiY2s1ODBjMGZqMGl0cDNmcGdwNXBkY2lndSJ9.Ovu_8lop71I-KSyq6f6OQg";
var map = L.map('map', { minZoom: 2 }).setView([20, 0], 3);
var bounds = [[-100,-100], [100,100]];
map.fitBounds(bounds);
L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=' + mapboxAccessToken, {
id: 'mapbox/light-v9'
}).addTo(map);
var info = L.control();
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info');
this.update();
return this._div;
};
info.update = function (props) {
this._div.innerHTML = '<h4>Global greenhouse gas emissions</h4>' + (props ?
'<b>' + props.CountryName + '</b><br />CO<sub>2</sub> gas emissions:' + props.Emissions + (props.Emissions > 0 ? ' Tonnes per capita' : '')
: 'Hover over a country');
};
info.addTo(map)
function getColor(d)
{
// Old Colors
/*return d > 600000 ? '#800026' :
d > 500000 ? '#BD0026' :
d > 400000 ? '#E31A1C' :
d > 300000 ? '#FC4E2A' :
d > 200000 ? '#FD8D3C' :
d > 100000 ? '#FEB24C' :
d > 50000 ? '#FED976' :
d > 0 ? '#FFEDA0':
'#AAAAAA';*/
return d > 16 ? '#000000' :
d > 15 ? '#220000' :
d > 13 ? '#660000' :
d > 10 ? '#AA0000' :
d > 8 ? '#FF0000' :
d > 6 ? '#FF5500' :
d > 4 ? '#FFCC00' :
d > 3 ? '#FFFF00' :
d > 2 ? '#DDFF00' :
d > 1 ? '#99FF00' :
d > 0 ? '#55FF00' :
'#AAAAAA';
}
function style(feature) {
return {
fillColor: getColor(feature.properties.Emissions),
weight: 2,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.7
};
}
function highlightFeature(e) {
var layer = e.target;
layer.setStyle({
weight: 5,
color: '#666',
dashArray: '',
fillOpacity: 0.7
});
if (!L.Browser.ie && !L.Browser.opera && !L.Browser.edge) {
layer.bringToFront();
}
info.update(layer.feature.properties);
}
var geojson;
function resetHighlight(e) {
geojson.resetStyle(e.target);
info.update();
}
function zoomToFeature(e) {
map.fitBounds(e.target.getBounds());
}
function onEachFeature(feature, layer) {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight,
click: zoomToFeature
});
}
geojson = L.geoJson(CountriesOutline, {
style: style,
onEachFeature: onEachFeature
}).addTo(map);
</script>