This is a simple setup of Leaflet (via Mapbox) with d3 to show dots on a map. This can serve as a base for many interesting geographically based visualizations
Nice overview of using d3 + Leaflet. I found this slightly simpler to use than Mike's classic post.
Built with blockbuilder.org
forked from enjalot's block: dots on a map: setup
forked from arimocro's block: Test Velo'v Lyon Markers
xxxxxxxxxx
<head>
<meta charset="utf-8">
<link
rel="stylesheet"
href="https://cdn.leafletjs.com/leaflet-0.7/leaflet.css"
/>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script
src="https://cdn.leafletjs.com/leaflet-0.7/leaflet.js">
</script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
#map {
position:absolute;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
//Setup our Leaflet map using Mapbox.js
var map = L.map('map').setView([45.7531152, 4.827906], 12);
mapLink =
'<a href="https://openstreetmap.org">OpenStreetMap</a>';
L.tileLayer(
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© ' + mapLink + ' Contributors',
maxZoom: 18,
}).addTo(map);
// 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) {
// our data came from csv, make it Leaflet friendly
// var a = [+ll.lat, +ll.lon];
// convert it to pixel coordinates
// var point = map.latLngToLayerPoint(L.latLng(ll))
// return point;
// }
d3.json("data.json", function(err, data) {
// var dots = g.selectAll("circle.dot")
d3.json("data.json", function(err, geojson) {
console.log("geojson data:", geojson);
L.geoJson(geojson).addTo(map);
})
// 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).x},
// cy: function(d) { return project(d).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>
Modified http://d3js.org/d3.v3.min.js to a secure url
https://d3js.org/d3.v3.min.js