Open Street Map tile data (from MapZen) rendered with D3 and sketched using vivus.js.
Last active
August 2, 2017 10:02
-
-
Save animateddata/08aed329f1b5e2ac0ea2e41026adbd3b to your computer and use it in GitHub Desktop.
Map tile sketch animation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: gpl-3.0 | |
height: 780 | |
border: no |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>Map tile sketch animation</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"></script> | |
<script src="https://cdn.jsdelivr.net/vivus/0.4/vivus.min.js"></script> | |
</head> | |
<style> | |
body { | |
font-family: "Helvetica Neue", Helvetica, sans-serif; | |
font-size: 14px; | |
color: #333; | |
background-color: #37474F; | |
} | |
svg path { | |
fill: none; | |
stroke: #ddd; | |
} | |
svg path.buildings { | |
opacity: 0.5; | |
} | |
svg path.pois { | |
stroke: #777; | |
stroke-width: 2; | |
} | |
</style> | |
<body> | |
<div id="root"> | |
<svg id="my-svg" width="800px" height="800px"></svg> | |
</div> | |
<script> | |
var geojson = {}; | |
var projection = d3.geoMercator(); | |
var geoGenerator = d3.geoPath() | |
.projection(projection); | |
function mergeFeatures(layers) { | |
var features = []; | |
Object.keys(layers).map(function(layerName) { | |
layers[layerName].features.forEach(function(feature) { | |
feature.properties.featureType = layerName; | |
features.push(feature); | |
}) | |
}) | |
return { | |
type: 'FeatureCollection', | |
features: features | |
} | |
} | |
function sortFeatures(geojson) { | |
geojson.features.sort(function(a, b) { | |
return d3.ascending(a.properties.sort_rank, b.properties.sort_rank) | |
}); | |
} | |
function updateMap(geojson) { | |
var centroid = d3.geoCentroid(geojson); | |
projection | |
.center(centroid) | |
.fitSize([800, 800], geojson); | |
d3.select('svg') | |
.selectAll('path') | |
.data(geojson.features) | |
.enter() | |
.append('path') | |
.attr('d', geoGenerator); | |
} | |
d3.json('skiff.json', function(err, layers) { | |
geojson = mergeFeatures(layers); | |
sortFeatures(geojson); | |
updateMap(geojson); | |
new Vivus('my-svg', {duration: 4000, start: 'autostart', type: 'oneByOne'}) | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment