Skip to content

Instantly share code, notes, and snippets.

@animateddata
Last active August 2, 2017 10:02
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 animateddata/08aed329f1b5e2ac0ea2e41026adbd3b to your computer and use it in GitHub Desktop.
Save animateddata/08aed329f1b5e2ac0ea2e41026adbd3b to your computer and use it in GitHub Desktop.
Map tile sketch animation
license: gpl-3.0
height: 780
border: no
<!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>
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