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
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"title":"MaptimeSF","twitter":"maptimesf","contact":"Beth Schechter | @bethschechter Alan McConchie | @mappingmashups Camille Teicheira | @fulgenteft"},"geometry":{"type":"Point","coordinates":[-122.45258331298828,37.753615462062704]}},{"type":"Feature","properties":{"title":"MaptimePDX","twitter":"maptimepdx","contact":"Lyzi Diamond (PDX) | @lyzidiamond Rafa Gutierrez (PDX) | @geografa Matt Sayler (PDX) | @MattSayler"},"geometry":{"type":"Point","coordinates":[-122.67608642578126,45.52078170816289]}},{"type":"Feature","properties":{"title":"MaptimeStJohns","twitter":"MaptimeStJohns","contact":"Lynnae Sutton (StJohns) | @naefish"},"geometry":{"type":"Point","coordinates":[-122.75466442108154,45.59037762382364]}},{"type":"Feature","properties":{"title":"MaptimeATL","twitter":"MaptimeATL","contact":"Landon Reed | @eltiar"},"geometry":{"type":"Point","coordinates":[-84.384744,33.755152]}},{"type":"Feature","properties":{"title":"MaptimeNYC","twitter":"MaptimeNYC","contact":"Alyssa Wright | @alyssapwright Chris Henrick | @chrislhenrick Eric Brelsford | @ebrelsford Jeff Ferzoco | @zingbot Jeremy Goldsmith | @JWGoldsmith"},"geometry":{"type":"Point","coordinates":[-73.99566650390625,40.72228267283148]}},{"type":"Feature","properties":{"title":"MaptimeCleveland","twitter":"OpenGeoCLE","contact":"Will Skora | @skorasaurus Stephen Mather | @smathermather"},"geometry":{"type":"Point","coordinates":[-81.67785644531249,41.49674964110098]}},{"type":"Feature","properties":{"title":"MaptimeOAK","twitter":"MaptimeOAK","contact":"Lyzi Diamond | @lyzidiamond"},"geometry":{"type":"Point","coordinates":[-122.26924896240234,37.805986463750315]}},{"type":"Feature","properties":{"title":"MaptimeME","twitter":"MaptimeME","contact":"Jacques Tardie | @jqtrde"},"geometry":{"type":"Point","coordinates":[-70.25653839111327,43.66042082657193]}},{"type":"Feature","properties":{"title":"MaptimeDC","twitter":"MaptimeDC"},"geometry":{"type":"Point","coordinates":[-77.02308654785156,38.90252245678968]}},{"type":"Feature","properties":{"title":"MaptimeATX","twitter":"MaptimeATX","contact":"James Seppi | @hydrologee"},"geometry":{"type":"Point","coordinates":[-97.7372932434082,30.297166099436673]}},{"type":"Feature","properties":{"title":"MaptimeTO","contact":"Courtney Claessens | @sidewalkballet Tristen Brown | @fallsemo","twitter":"MaptimeTO"},"geometry":{"type":"Point","coordinates":[-79.38456773757935,43.65230152428721]}},{"type":"Feature","properties":{"title":"MaptimeChicago","contact":"Dan Swick | @DanSwick Ian Dees @iandees | Nick Doiron @mapmeld"},"geometry":{"type":"Point","coordinates":[-87.61890649795532,41.87579225678032]}},{"type":"Feature","properties":{"title":"MaptimeSLC","twitter":"MaptimeSLC","contact":"Martijn van Exel @mvexel"},"geometry":{"type":"Point","coordinates":[-111.89109563827515,40.76936991525655]}},{"type":"Feature","properties":{"title":"MaptimeNullIsland","twitter":"MaptimeNull"},"geometry":{"type":"Point","coordinates":[0,0]}},{"type":"Feature","properties":{"title":"MaptimeCHA","twitter":"maptimeCHA","contact":"Jason Denizac | @_jden"},"geometry":{"type":"Point","coordinates":[-85.31158447265624,35.04667]}},{"type":"Feature","properties":{"title":"Maptime WindsorEssex","twitter":"maptimeWindsor","contact":"Mita Williams | @copystar"},"geometry":{"type":"Point","coordinates":[-83.03483963012695,42.31149743167054]}},{"type":"Feature","properties":{"title":"MaptimeBoston","twitter":"maptimeBoston","contact":"Jake Wasserman | @jwass2000 Andy Woodruff | @awoodruff Mike Foster | @mjfoster83"},"geometry":{"type":"Point","coordinates":[-71.070556640625,42.35854391749705]}}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment