Skip to content

Instantly share code, notes, and snippets.

Created September 11, 2017 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/7e930937a6d8c0a24c6ca3a033a7cf84 to your computer and use it in GitHub Desktop.
Save anonymous/7e930937a6d8c0a24c6ca3a033a7cf84 to your computer and use it in GitHub Desktop.
TownHall data
license: mit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no'/>
<title>MapboxGL & D3.js - point</title>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.12.0/mapbox-gl.css' rel='stylesheet'/>
<style>
html, body, #wrapper {
width: 100%;
height: 100%;
padding: 0px;
margin: 0px;
}
#map {
position: relative;
width: 100%;
height: 100%;
margin: auto auto;
}
svg {
position: absolute;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="map"></div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.12.0/mapbox-gl.js'></script>
<script>
d3.json("Opal_train_data.geojson", function (err, data) {
mapDraw(data);
})
function mapDraw(data) {
mapboxgl.accessToken = 'pk.eyJ1Ijoic2hpbWl6dSIsImEiOiI0cl85c2pNIn0.RefZMaOzNn-IistVe-Zcnw'
var map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/mapbox/streets-v8',
center: [151, -33.85],
zoom: 8,
});
map.addControl(new mapboxgl.Navigation());
var container = map.getCanvasContainer()
var svg = d3.select(container).append("svg")
var circle = svg.append("circle")
.datum(data.features[0]);
setTimeout(function() {
function project(d) {
return map.project(new mapboxgl.LngLat(+d[0], +d[1]));
console.log(map.project(new mapboxgl.LngLat(+d[0], +d[1])))
}
function drop() {
circle
.attr({
"stroke": "black",
"stroke-width": 2,
"opacity": .7,
"fill": "red",
"r": 5
})
.attr("cx", function(d) {
return project(d.geometry.coordinates).x;
})
.attr("cy", function(d, i) {
return project(d.geometry.coordinates).y;
})
.transition()
.duration(10000)
.attr("r", function(d) {
console.log(d.properties.count)
return d.properties.count / 10
})
}
function update() {
circle
.attr({
cx: function(d) {
return project(d.geometry.coordinates).x;
},
cy: function(d) {
return project(d.geometry.coordinates).y;
},
})
}
map.on("viewreset", update)
map.on("move", update)
drop();
},3000)
}
</script>
</body>
</html>
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment