-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
214 lines (194 loc) · 6.58 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
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"> -->
<style>
html, body, #map {
height: 100%;
width: 100%;
/*position: relative;*/
}
body {
padding: 0;
margin: 0;
}
.info {
padding: 6px 8px;
font: 12px/14px Arial, Helvetica, sans-serif;
background: white;
background: rgba(255,255,255,1);
box-shadow: 0 0 15px rgba(0,0,0,0.2);
border-radius: 5px;
}
.mapkey {
height:160px;
}
.leaflet-control-attribution a {
color: #6d6e70 !important;
cursor: pointer;
}
.leaflet-container {
background-color: #EDFCFF !important;
}
</style>
</head>
<body>
<div id="info-modal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4>Disclaimer</h4>
</div>
<div class="modal-body">
<h4>The maps used do not imply the expression of any opinion concerning the legal status of a territory or of its authorities.</h4>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<div id="map"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.1.0/papaparse.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script>
var appData = {};
function formatNumber(x) {
return x.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
var map = L.map('map').setView([0, 0], 2);
map.fitWorld();
map.fitBounds([
[-50, 130],
[60, -110]
]);
var info = L.control();
function style(feature) {
return {
fillColor: countryFill(feature.properties),
fillOpacity: 1,
weight: 1,
opacity: 1,
color: 'white'
};
}
function highlightFeature(e) {
var layer = e.target;
layer.setStyle({
weight: 3,
color: '#666',
fillOpacity: 1
});
if (!L.Browser.ie && !L.Browser.opera) { layer.bringToFront(); }
info.update(layer.feature.properties);
}
function resetHighlight(e) {
countries.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
});
}
function countryFill(properties){
if(properties['universal_app_program'] === "TRUE" && properties['pillowcase_project'] === "TRUE" && properties['research'] === "TRUE" ){
return "#a06338";
} else if (properties['universal_app_program'] === "TRUE" && properties['pillowcase_project'] === "TRUE") {
return "#8b51a1";
} else if (properties['universal_app_program'] === "TRUE" && properties['research'] === "TRUE") {
return "#f8981d";
} else if (properties['pillowcase_project'] === "TRUE" && properties['research'] === "TRUE") {
return "#33a248";
} else if(properties['universal_app_program'] === "TRUE" ){
return "#f05243";
} else if(properties['pillowcase_project'] === "TRUE"){
return "#3b7cb8";
} else if(properties['research'] === "TRUE"){
return "#fed131";
} else {
return '#9f9fa3';
}
}
function grabAppData(){
var public_spreadsheet_url = 'https://americanredcross.github.io/google-sheets-workaround/gdpc-app-activities-map.csv';
function grabInfo(data) {
$.each(data, function(i,d){
appData[d.iso] = d;
});
grabGeoData();
}
Papa.parse(public_spreadsheet_url, {
download: true,
header: true,
complete: function(results) {
grabInfo(results.data);
}
})
}
function grabGeoData(){
$.getJSON('data/world.geojson', function(data) {
mapData = data;
$.each(mapData.features, function(i,d){
var countryData = appData[d.properties.iso];
d.properties['status'] = countryData['status'];
d.properties['fa_downloads'] = countryData['fa_downloads'];
d.properties['hz_downloads'] = countryData['hz_downloads'];
d.properties['universal_app_program'] = countryData['universal_app_program'];
d.properties['pillowcase_project'] = countryData['pillowcase_project'];
d.properties['research'] = countryData['research'];
});
countries = L.geoJson(mapData, {style: style, onEachFeature: onEachFeature}).addTo(map);
var legend = L.control({position: 'bottomright'});
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend');
div.innerHTML += '<img class="mapkey" src="data/mapkey.png" alt="legend key">';
return div;
};
legend.addTo(map);
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info'); // create a div with a class "info"
this.update();
return this._div;
};
// method that we will use to update the control based on feature properties passed
info.update = function (props) {
infoHtml = '<h5>GDPC Activities</h5>';
if(props){
infoHtml += '<b>' + props.name + '</b><br>';
var activitiesArray = [];
if(props['universal_app_program'] === "TRUE"){ activitiesArray.push("Universal App Program"); }
if(props['pillowcase_project'] === "TRUE"){ activitiesArray.push("Pillowcase Project"); }
if(props['research'] === "TRUE"){ activitiesArray.push("Research"); }
if(activitiesArray.length > 0){
infoHtml += "<div>" + activitiesArray.join(', ') + "</div>";
} else if (props.status === 'Interest') {
infoHtml += "<div>Interest only</div>";
} else {
infoHtml += "<div>No data</div>";
}
} else {
infoHtml += 'Hover over a country';
}
this._div.innerHTML = infoHtml;
};
info.addTo(map);
});
}
grabAppData();
</script>
</body>
</html>