Skip to content

Instantly share code, notes, and snippets.

@mpmckenna8
Last active August 29, 2015 14:03
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 mpmckenna8/3975be6a974ea7c0bc8d to your computer and use it in GitHub Desktop.
Save mpmckenna8/3975be6a974ea7c0bc8d to your computer and use it in GitHub Desktop.
Maptimes distances from MaptimeSF w/ turf.js

Using turf.js distance to figure out how far all the maptimes are from MaptimeSF.

<!DOCTYPE html>
<meta charset="utf-8">
<style>
</style>
<body>
<h3>Distances away from</h3>
<script src="http://d3js.org/d3.v3.js"></script>
<script src="/mpmckenna8/raw/def3735b8e1eef5128a7/turf.min.js" charset="utf-8"></script>
<script>
d3.json('maptimes.geojson', function(maptimes){
console.log(maptimes.features[2])
var info = maptimes.features;
var bods = d3.select('body').append('div').attr('class', 'dists')
//.data(info).enter().append('tr');
bods.selectAll('.mappers')
.data(info)
.enter()
.append('html:p')
.text(function(d){
console.log(d);
var blah = d.properties.title;
return blah
})
.attr('class','mappers')
d3.selectAll('.mappers')
.append('html:div')
.text(function(d,i)
{
console.log(info[i] + i)
if(i > 0){
return turf.distance(info[0],d,'miles') + ' miles'
}
})
})
</script>
</body>
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