7

I need restrict map area to 5km radius around given point. How can I get appropriate bounding box using mapbox-gl-js or turf?

Rantiev
  • 2,121
  • 2
  • 32
  • 56

2 Answers2

9

You can use http://turfjs.org/docs/#buffer to get a feature in size of the radius that you want and then use http://turfjs.org/docs/#bbox to get the bbox.

var point = turf.point([-90.548630, 14.616599]);
var buffered = turf.buffer(point, 5, {units:'kilometers'});
var bbox = turf.bbox(buffered);
console.log(turf.bboxPolygon(bbox));
<script src="https://npmcdn.com/@turf/turf/turf.min.js"></script>
Andi-lo
  • 2,244
  • 21
  • 26
4

Buffer API has changed. Buffer's optional argument needs to be an object like so:

var point = turf.point([-90.548630, 14.616599]);
var buffered = turf.buffer(point, 5, {units:'kilometers'}); /// notice 'units'
var bbox = turf.bbox(buffered);
console.log(turf.bboxPolygon(bbox));
mbejda
  • 1,471
  • 16
  • 25