我需要将地图区域限制在给定点周围5公里半径。 如何使用mapbox-gl-js或turf获得合适的边界框?
答案 0 :(得分:4)
您可以使用http://turfjs.org/docs/#buffer获取所需半径大小的功能,然后使用http://turfjs.org/docs/#bbox获取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>
答案 1 :(得分:1)
缓冲区API已更改。缓冲区的可选参数必须是这样的对象:
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));