1、首先,确保你已经引入了Turf.js库。你可以通过在HTML文件中添加以下代码来引入
<script src="https://cdn.jsdelivr.net/npm/@turf/turf@6.5.0/turf.min.js"></script>
2、使用turf.buffer实现几何对象按照设定距离扩充
let originalCoordinates = [
[ -0.13236090490727292, 51.50456971900687],
[-0.11407896826176511, 51.506760740677095,],
[ -0.10206267187504636, 51.4987977430076,],
[-0.10901495764164792, 51.486449673535816],
[-0.12034460852055417, 51.49778222716637],
[ -0.13236090490727292, 51.50456971900687]
];
// 将坐标数组转换为Turf.js的多边形对象
var originalPolygon = turf.polygon([originalCoordinates]);
// 定义外扩距离
var expandDistance = 0.1;
// 使用Turf.js的buffer方法来扩大多边形的边界
expandedPolygon = turf.buffer(originalPolygon, expandDistance, { units: 'kilometers' });
console.log(expandedPolygon.geometry);
效果图如下