Skip to content

Instantly share code, notes, and snippets.

@scresawn
Last active March 12, 2017 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save scresawn/4d59619b3b5e7101f65fcb6f1431bddc to your computer and use it in GitHub Desktop.
Save scresawn/4d59619b3b5e7101f65fcb6f1431bddc to your computer and use it in GitHub Desktop.
ebola cases with checkboxes
license: mit
Display the source blob
Display the rendered blob
Raw
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"country": "Spain"
},
"geometry": {
"type": "Point",
"coordinates": [
-3.74922,
40.46366700000001
]
}
},
{
"type": "Feature",
"properties": {
"country": "United States"
},
"geometry": {
"type": "Point",
"coordinates": [
-95.712891,
37.09024
]
}
},
{
"type": "Feature",
"properties": {
"address": "Lokolia",
"country": "Democratic Republic of the Congo"
},
"geometry": {
"type": "Point",
"coordinates": [
20.562519,
-0.631684
]
}
},
{
"type": "Feature",
"properties": {
"address": "Watsikengo",
"country": "Democratic Republic of the Congo"
},
"geometry": {
"type": "Point",
"coordinates": [
20.5632588,
-0.8434999999999999
]
}
},
{
"type": "Feature",
"properties": {
"address": "HGR Boende",
"country": "Democratic Republic of the Congo"
},
"geometry": {
"type": "Point",
"coordinates": [
19.2,
-0.733333
]
}
},
{
"type": "Feature",
"properties": {
"address": "Boende moke",
"country": "Democratic Republic of the Congo"
},
"geometry": {
"type": "Point",
"coordinates": [
20.750031,
-0.3814139
]
}
},
{
"type": "Feature",
"properties": {
"address": "Lokula",
"country": "Democratic Republic of the Congo"
},
"geometry": {
"type": "Point",
"coordinates": [
20.653891,
-0.420979
]
}
},
{
"type": "Feature",
"properties": {
"address": "Mondombe",
"country": "Democratic Republic of the Congo"
},
"geometry": {
"type": "Point",
"coordinates": [
22.7539449,
-0.7758398999999999
]
}
},
{
"type": "Feature",
"properties": {
"address": "Dallas, TX",
"country": "United States"
},
"geometry": {
"type": "Point",
"coordinates": [
-96.80045109999999,
32.7801399
]
}
},
{
"type": "Feature",
"properties": {
"address": "Gueckedou",
"country": "Guinea"
},
"geometry": {
"type": "Point",
"coordinates": [
-10.1247811,
8.5652126
]
}
},
{
"type": "Feature",
"properties": {
"address": "Dinguiraye",
"country": "Guinea"
},
"geometry": {
"type": "Point",
"coordinates": [
-10.711305,
11.2912107
]
}
},
{
"type": "Feature",
"properties": {
"address": "Nzerekore",
"country": "Guinea"
},
"geometry": {
"type": "Point",
"coordinates": [
-8.816667,
7.75
]
}
},
{
"type": "Feature",
"properties": {
"address": "Dalaba",
"country": "Guinea"
},
"geometry": {
"type": "Point",
"coordinates": [
-9.383333,
10.166667
]
}
},
{
"type": "Feature",
"properties": {
"address": "Beyla",
"country": "Guinea"
},
"geometry": {
"type": "Point",
"coordinates": [
-8.633333,
8.683333
]
}
},
{
"type": "Feature",
"properties": {
"address": "Kindia",
"country": "Guinea"
},
"geometry": {
"type": "Point",
"coordinates": [
-12.85,
10.066667
]
}
},
{
"type": "Feature",
"properties": {
"address": "Lola",
"country": "Guinea"
},
"geometry": {
"type": "Point",
"coordinates": [
-8.533332999999999,
7.8
]
}
},
{
"type": "Feature",
"properties": {
"address": "Coyah",
"country": "Guinea"
},
"geometry": {
"type": "Point",
"coordinates": [
-13.383333,
9.7
]
}
},
{
"type": "Feature",
"properties": {
"address": "Kerouane",
"country": "Guinea"
},
"geometry": {
"type": "Point",
"coordinates": [
-9.016667,
9.266667
]
}
},
{
"type": "Feature",
"properties": {
"address": "Forecariah",
"country": "Guinea"
},
"geometry": {
"type": "Point",
"coordinates": [
-13.083333,
9.433333
]
}
},
{
"type": "Feature",
"properties": {
"address": "Dubreka",
"country": "Guinea"
},
"geometry": {
"type": "Point",
"coordinates": [
-13.516667,
9.783332999999999
]
}
},
{
"type": "Feature",
"properties": {
"address": "Yomou",
"country": "Guinea"
},
"geometry": {
"type": "Point",
"coordinates": [
-9.2533,
7.566000000000001
]
}
},
{
"type": "Feature",
"properties": {
"address": "Pita",
"country": "Guinea"
},
"geometry": {
"type": "Point",
"coordinates": [
-12.395582,
11.059568
]
}
},
{
"type": "Feature",
"properties": {
"address": "Siguiri",
"country": "Guinea"
},
"geometry": {
"type": "Point",
"coordinates": [
-9.166667,
11.416667
]
}
},
{
"type": "Feature",
"properties": {
"address": "Kouroussa",
"country": "Guinea"
},
"geometry": {
"type": "Point",
"coordinates": [
-9.883333,
10.65
]
}
},
{
"type": "Feature",
"properties": {
"address": "Boffa",
"country": "Guinea"
},
"geometry": {
"type": "Point",
"coordinates": [
-14.0391615,
10.1808254
]
}
},
{
"type": "Feature",
"properties": {
"address": "Telimele",
"country": "Guinea"
},
"geometry": {
"type": "Point",
"coordinates": [
-13.033333,
10.9
]
}
},
{
"type": "Feature",
"properties": {
"address": "Cinguiraye",
"country": "Guinea"
},
"geometry": {
"type": "Point",
"coordinates": [
-10.716667,
11.3
]
}
},
{
"type": "Feature",
"properties": {
"address": "Kissidougou",
"country": "Guinea"
},
"geometry": {
"type": "Point",
"coordinates": [
-10.1,
9.183333
]
}
},
{
"type": "Feature",
"properties": {
"address": "Dabola",
"country": "Guinea"
},
"geometry": {
"type": "Point",
"coordinates": [
-11.116667,
10.75
]
}
},
{
"type": "Feature",
"properties": {
"address": "Macenta",
"country": "Guinea"
},
"geometry": {
"type": "Point",
"coordinates": [
-9.466667,
8.549999999999999
]
}
},
{
"type": "Feature",
"properties": {
"address": "Conakry",
"country": "Guinea"
},
"geometry": {
"type": "Point",
"coordinates": [
-13.712222,
9.509167
]
}
},
{
"type": "Feature",
"properties": {
"country": "Guinea"
},
"geometry": {
"type": "Point",
"coordinates": [
-9.696645,
9.945587
]
}
},
{
"type": "Feature",
"properties": {
"country": "Liberia"
},
"geometry": {
"type": "Point",
"coordinates": [
-9.429499000000002,
6.428055
]
}
},
{
"type": "Feature",
"properties": {
"country": "Sierra Leone"
},
"geometry": {
"type": "Point",
"coordinates": [
-11.779889,
8.460555
]
}
},
{
"type": "Feature",
"properties": {
"country": "Nigeria"
},
"geometry": {
"type": "Point",
"coordinates": [
8.675277,
9.081999
]
}
},
{
"type": "Feature",
"properties": {
"country": "Nigeria"
},
"geometry": {
"type": "Point",
"coordinates": [
8.675277,
9.081999
]
}
},
{
"type": "Feature",
"properties": {
"country": "Senegal"
},
"geometry": {
"type": "Point",
"coordinates": [
-14.452362,
14.497401
]
}
},
{
"type": "Feature",
"properties": {
"address": "Bomi County",
"country": "Liberia"
},
"geometry": {
"type": "Point",
"coordinates": [
-10.8451467,
6.7562926
]
}
},
{
"type": "Feature",
"properties": {
"address": "Bong County",
"country": "Liberia"
},
"geometry": {
"type": "Point",
"coordinates": [
-9.367308399999999,
6.829501899999999
]
}
},
{
"type": "Feature",
"properties": {
"address": "Gbarpolu County",
"country": "Liberia"
},
"geometry": {
"type": "Point",
"coordinates": [
-10.0807298,
7.495263700000001
]
}
},
{
"type": "Feature",
"properties": {
"address": "Grand Bassa",
"country": "Liberia"
},
"geometry": {
"type": "Point",
"coordinates": [
-9.8124935,
6.2308452
]
}
},
{
"type": "Feature",
"properties": {
"address": "Grand Cape Mount",
"country": "Liberia"
},
"geometry": {
"type": "Point",
"coordinates": [
-11.0711758,
7.0467758
]
}
},
{
"type": "Feature",
"properties": {
"address": "Grand Gedeh",
"country": "Liberia"
},
"geometry": {
"type": "Point",
"coordinates": [
-8.2212979,
5.9222078
]
}
},
{
"type": "Feature",
"properties": {
"address": "Grand Kru County",
"country": "Liberia"
},
"geometry": {
"type": "Point",
"coordinates": [
-8.2212979,
4.7613862
]
}
},
{
"type": "Feature",
"properties": {
"address": "Lofa County",
"country": "Liberia"
},
"geometry": {
"type": "Point",
"coordinates": [
-9.7232673,
8.191118399999999
]
}
},
{
"type": "Feature",
"properties": {
"address": "Margibi County",
"country": "Liberia"
},
"geometry": {
"type": "Point",
"coordinates": [
-10.3048897,
6.5151875
]
}
},
{
"type": "Feature",
"properties": {
"address": "Maryland County",
"country": "Liberia"
},
"geometry": {
"type": "Point",
"coordinates": [
-7.741670300000001,
4.7258878
]
}
},
{
"type": "Feature",
"properties": {
"address": "Margibi County",
"country": "Liberia"
},
"geometry": {
"type": "Point",
"coordinates": [
-10.3048897,
6.5151875
]
}
},
{
"type": "Feature",
"properties": {
"address": "Montserrado County",
"country": "Liberia"
},
"geometry": {
"type": "Point",
"coordinates": [
-10.5296115,
6.5525815
]
}
},
{
"type": "Feature",
"properties": {
"address": "Nimba County",
"country": "Liberia"
},
"geometry": {
"type": "Point",
"coordinates": [
-8.6600586,
6.8427612
]
}
},
{
"type": "Feature",
"properties": {
"address": "River Gee County",
"country": "Liberia"
},
"geometry": {
"type": "Point",
"coordinates": [
-7.872159999999999,
5.2604894
]
}
},
{
"type": "Feature",
"properties": {
"address": "Sinoe County",
"country": "Liberia"
},
"geometry": {
"type": "Point",
"coordinates": [
-8.6600586,
5.49871
]
}
},
{
"type": "Feature",
"properties": {
"address": "RiverCess County",
"country": "Liberia"
},
"geometry": {
"type": "Point",
"coordinates": [
-9.456155,
5.902532799999999
]
}
},
{
"type": "Feature",
"properties": {
"address": "Kailahun",
"country": "Sierra Leone"
},
"geometry": {
"type": "Point",
"coordinates": [
-10.573889,
8.277222
]
}
},
{
"type": "Feature",
"properties": {
"address": "Kenema",
"country": "Sierra Leone"
},
"geometry": {
"type": "Point",
"coordinates": [
-11.1957172,
7.863214699999999
]
}
},
{
"type": "Feature",
"properties": {
"address": "Kono",
"country": "Sierra Leone"
},
"geometry": {
"type": "Point",
"coordinates": [
-10.8903099,
8.7663285
]
}
},
{
"type": "Feature",
"properties": {
"address": "Kambia",
"country": "Sierra Leone"
},
"geometry": {
"type": "Point",
"coordinates": [
-12.9176518,
9.126166399999999
]
}
},
{
"type": "Feature",
"properties": {
"address": "Koinadugu",
"country": "Sierra Leone"
},
"geometry": {
"type": "Point",
"coordinates": [
-11.36363,
9.5168769
]
}
},
{
"type": "Feature",
"properties": {
"address": "Bombali",
"country": "Sierra Leone"
},
"geometry": {
"type": "Point",
"coordinates": [
-12.1632718,
9.2475837
]
}
},
{
"type": "Feature",
"properties": {
"address": "Tonkolili",
"country": "Sierra Leone"
},
"geometry": {
"type": "Point",
"coordinates": [
-11.7947561,
8.9804274
]
}
},
{
"type": "Feature",
"properties": {
"address": "Port Loko",
"country": "Sierra Leone"
},
"geometry": {
"type": "Point",
"coordinates": [
-12.7875,
8.766667
]
}
},
{
"type": "Feature",
"properties": {
"address": "Pujehun",
"country": "Sierra Leone"
},
"geometry": {
"type": "Point",
"coordinates": [
-11.718056,
7.350556
]
}
},
{
"type": "Feature",
"properties": {
"address": "Bo",
"country": "Sierra Leone"
},
"geometry": {
"type": "Point",
"coordinates": [
-11.7409946,
7.9551791
]
}
},
{
"type": "Feature",
"properties": {
"address": "Koinadugu",
"country": "Sierra Leone"
},
"geometry": {
"type": "Point",
"coordinates": [
-11.36363,
9.5168769
]
}
},
{
"type": "Feature",
"properties": {
"address": "Moyamba",
"country": "Sierra Leone"
},
"geometry": {
"type": "Point",
"coordinates": [
-12.433333,
8.160556
]
}
},
{
"type": "Feature",
"properties": {
"address": "Bonthe",
"country": "Sierra Leone"
},
"geometry": {
"type": "Point",
"coordinates": [
-12.505,
7.526389
]
}
},
{
"type": "Feature",
"properties": {
"address": "Western area urban district",
"country": "Sierra Leone"
},
"geometry": {
"type": "Point",
"coordinates": [
-13.2432632,
8.4545561
]
}
},
{
"type": "Feature",
"properties": {
"address": "Western area rural district",
"country": "Sierra Leone"
},
"geometry": {
"type": "Point",
"coordinates": [
-13.035694,
8.3114983
]
}
}
]
}
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script src='https://api.mapbox.com/mapbox.js/v2.2.3/mapbox.js'></script>
<link href='https://api.mapbox.com/mapbox.js/v2.2.3/mapbox.css' rel='stylesheet' />
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
#map {
position:absolute;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<input type="checkbox" name="usa" id="usa" onclick="country_clicked()">United States<br>
<input type="checkbox" name="liberia" id="liberia" onclick="country_clicked()">Liberia<br>
<input type="checkbox" name="guinea" id="guinea" onclick="country_clicked()">Guinea<br>
<div id="map"></div>
<script>
function country_clicked() {
d3.select("body").select("#" + event.target.id)
.call(function (d) {
console.log(d[0][0].name, d[0][0].checked);
});
}
L.mapbox.accessToken = 'pk.eyJ1IjoiZW5qYWxvdCIsImEiOiJjaWhtdmxhNTIwb25zdHBsejk0NGdhODJhIn0.2-F2hS_oTZenAWc0BMf_uw'
//Setup our Leaflet map using Mapbox.js
var map = L.mapbox.map('map', 'mapbox.light')
.setView([20,-30], 3);
// Setup our svg layer that we can manipulate with d3
var svg = d3.select(map.getPanes().overlayPane)
.append("svg");
var g = svg.append("g").attr("class", "leaflet-zoom-hide");
function project(ll) {
//console.log("ll:", ll);
// our data came from csv, make it Leaflet friendly
//var a = [+ll.lat, +ll.lon];
var b = [+ll[1], +ll[0]];
// convert it to pixel coordinates
var point = map.latLngToLayerPoint(L.latLng(b))
return point;
}
d3.json("data.json", function(err, data) {
//console.log("data:", data);
var dots = g.selectAll("circle.dot")
.data(data.features)
dots.enter().append("circle").classed("dot", true)
.attr("r", 250)
.style({
fill: "#fe9523",
"fill-opacity": 0.6,
stroke: "#004d60",
"stroke-width": 0
})
.transition().duration(3000)
.style({
fill: "#fe9523",
"fill-opacity": 0.6,
stroke: "#004d60",
"stroke-width": 1
})
.attr("r", 6)
function render() {
// We need to reposition our SVG and our containing group when the map
// repositions via zoom or pan
// https://github.com/zetter/voronoi-maps/blob/master/lib/voronoi_map.js
var bounds = map.getBounds();
var topLeft = map.latLngToLayerPoint(bounds.getNorthWest())
var bottomRight = map.latLngToLayerPoint(bounds.getSouthEast())
svg.style("width", map.getSize().x + "px")
.style("height", map.getSize().y + "px")
.style("left", topLeft.x + "px")
.style("top", topLeft.y + "px");
g.attr("transform", "translate(" + -topLeft.x + "," + -topLeft.y + ")");
// We reproject our data with the updated projection from leaflet
g.selectAll("circle.dot")
.attr({
cx: function(d) {
return project(d.geometry.coordinates).x
},
cy: function(d) {
return project(d.geometry.coordinates).y
},
})
}
// re-render our visualization whenever the view changes
map.on("viewreset", function() {
render()
})
map.on("move", function() {
render()
})
// render our initial visualization
render()
})
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment