我需要将地图区域限制在给定点周围 5 公里半径范围内。如何使用 mapbox-gl-js 或 turf 获得适当的边界框?
问问题
2411 次
2 回答
9
您可以使用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>
于 2017-07-05T15:43:55.220 回答
2
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));
于 2018-12-16T09:08:23.547 回答