This repository has been archived by the owner on Feb 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
137 lines (113 loc) · 3.59 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
<!DOCTYPE html>
<html>
<head>
<title>Mapping Laws</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="lib/leaflet.css" />
<link rel="stylesheet" href="lib/map.css" />
</head>
<body>
<div id="map"></div>
</body>
<script>
var host = "watershedlegal.github.io";
if ((host == window.location.host) && (window.location.protocol != "https:"))
window.location = window.location.toString().replace(/^http:/, "https:");
</script>
<script src="lib/leaflet.js"></script>
<script src="lib/colorschemes.js"></script>
<script src="lib/countries_geo_data.js"></script>
<script src="lib/countries_data.js"></script>
<script type="text/javascript">
var geojson;
var title = 'Mapping Laws'
// First, load and merge the data from the data files
function mergeData( obj1, obj2 ) {
for ( var i in obj2 ) {
obj1[i] = obj2[i];
}
return obj1;
};
countries.features.forEach( function(e,i){ mergeData(e.properties, countriesData.features[i].properties) });
// Now, set the map to a world view ... sorry for the offset Souther Hemisphere lovers
var map = new L.Map('map');
var osmUrl='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
var osmAttrib='Map data © <a href="https://openstreetmap.org">OpenStreetMap</a>';
var osm = new L.TileLayer(osmUrl, {minZoom: 3, maxZoom: 8, attribution: osmAttrib});
map.setView([25, 0], 3);
map.addLayer(osm);
// Next, set the styles & UX Components
function countryStyle(feature) {
return {
fillColor: getColorScheme(feature.properties.rank),
weight: 2,
opacity: 1,
color: getColorScheme('border-standard'),
dashArray: '3',
fillOpacity: 0.5
};
}
function getColorScheme(d) {
return blueGreen(d);
}
function highlightFeature(e) {
var layer = e.target;
layer.setStyle({
weight: 2,
color: getColorScheme('border-highlight'),
dashArray: '',
fillOpacity: 0.8
});
if (!L.Browser.ie && !L.Browser.opera) {
layer.bringToFront();
}
info.update(layer.feature.properties, layer.feature.id);
}
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
});
}
// Run the Map
var mapData = {
style: countryStyle,
onEachFeature: onEachFeature
};
geojson = L.geoJson(countries, mapData).addTo(map);
// Add the Legend
// loop through our density intervals and generate a label with a colored square for each interval
var legend = L.control({position: 'bottomright'});
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend'),
grades = [1, 2, 3, 4, 5],
labels = ['Did it', 'Sort of Did it', 'More Sort of Did it', 'Sort of Didn\'t it', 'Didn\'t it'];
for (var i = 0; i < grades.length; i++) {
div.innerHTML += '<i style="background:' + getColorScheme(grades[i]) + '"></i> ' + labels[i] + '<br>';
}
return div;
};
legend.addTo(map);
// Add the Information Box
var info = L.control({position: 'bottomleft'});
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info');
this.update();
return this._div;
};
info.update = function (props, ident) {
this._div.innerHTML = (props ?
'<h4>' + props.name + '</h4>' + props.synopsis + '<br>' + "<a href='countries/" + ident + ".html'>Read More</a>"
: '');
};
info.addTo(map);
</script>
</html>