I need restrict map area to 5km radius around given point. How can I get appropriate bounding box using mapbox-gl-js or turf?
You can find the bounding box of those cities at www.mapdevelopers.com/geocode_bounding_box.php. Entering a city will display a box on a map and give the latitude and longitude of each side. Hopefully that will give you the information you need.
To find the bounds of the box containing a triangle, you simply need to find the smallest and largest x and y coordinates from the three coordinates making up the triangle.
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>
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With