Built with blockbuilder.org
xxxxxxxxxx
<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>
<h3>Map of Ebola Effected Countries</h3>
<p>Select a country to add it to the map</p>
United States--> <input type="checkbox" value="United States" onclick="updatemap(this)">
Sierra Leone--> <input type="checkbox" value="Sierra Leone" onclick="updatemap(this)"><br>
Liberia--> <input type="checkbox" value="Liberia" onclick="updatemap(this)">
Nigeria--> <input type="checkbox" value="Nigeria" onclick="updatemap(this)">
<br>
Guinea--> <input type="checkbox" value="Guinea" onclick="updatemap(this)">
Senegal--> <input type="checkbox" value="Senegal" onclick="updatemap(this)">
<br>
Democratic Republic of the Congo--> <input type="checkbox" value="Democratic Republic of the Congo" onclick="updatemap(this)">
Spain--> <input type="checkbox" value="Spain" onclick="updatemap(this)">
<br>
<script>
function updatemap(checkbox) {
d3.selectAll("circle").each( function(d) {
if (d.properties.country == checkbox.value) {
if (checkbox.checked) {
d3.select(this).attr("visibility", "visible");
}
else {
d3.select(this).attr("visibility", "hidden");
}
}
});
}
</script>
<div id="map"></div>
<script>
L.mapbox.accessToken = 'pk.eyJ1IjoiZW5qYWxvdCIsImEiOiJjaWhtdmxhNTIwb25zdHBsejk0NGdhODJhIn0.2-F2hS_oTZenAWc0BMf_uw'
//Setup our Leaflet map using Mapbox.js
var map = L.mapbox.map('map', 'mapbox.satellite')
.setView([22.147709, -15.783053], 3);
function project(featureObject){
var coordinates = featureObject.geometry.coordinates;
var reverse = [coordinates[1], coordinates[0]]
var point = map.latLngToLayerPoint(L.latLng(reverse));
return point;
}
// 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");
d3.json("ebola.json", function(err, data) {
//console.log("data:", data)
var dots = g.selectAll("circle").data(data.features)
dots.enter()
.append("circle")
.attr("fill", "white")
.attr("stroke-width", 2)
.attr("stroke", "red")
.attr("visibility", "hidden")
function update() {
// 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())
console.log(bounds, topLeft, bottomRight)
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 + ")");
dots.attr({
cx: function(d) { return project(d).x },
cy: function(d) { return project(d).y },
r: 5
})
}
update();
map.on("viewreset", function() {
update();
})
map.on("move", update)
})
</script>
</body>
https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js
https://api.mapbox.com/mapbox.js/v2.2.3/mapbox.js