Skip to content

Instantly share code, notes, and snippets.

@roblav96
Created January 7, 2016 12:16
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 roblav96/019a4662bd5e14363571 to your computer and use it in GitHub Desktop.
Save roblav96/019a4662bd5e14363571 to your computer and use it in GitHub Desktop.
self.doit = function ( pos, acc ) {
var points = {
"type": "FeatureCollection",
"features": [ {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [ -71.16437494754791,
42.35219326967517
]
}
}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [ -71.16197168827057,
42.352538171523115
]
}
} ]
}
var polys = []
var feats = points.features
var i, len = feats.length
for ( i = 0; i < len; i++ ) {
var polypoints = []
var ii, len = 10
for ( ii = 0; ii < len; ii++ ) {
var bearing = 360 * ( Number( '0.' + ii.toString() ) )
var dest = turf.destination( feats[ i ], acc / 1000, bearing, 'kilometers' ).geometry.coordinates
console.log( 'dest >', dest )
polypoints.push( dest )
}
polypoints[ polypoints.length ] = polypoints[ 0 ]
polys[ i ] = turf.polygon( [ polypoints ] )
}
var polyfeats = turf.featurecollection( polys )
var source = new mapboxgl.GeoJSONSource( {
data: polyfeats
} )
_$map.map.addSource( "polys", source )
_$map.map.addLayer( {
'id': 'polys',
'type': 'fill',
'source': 'polys',
'paint': {
'fill-color': '#000',
'fill-opacity': 0.8
}
} )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment