我在使用 L 的传单及其功能时遇到问题。我有一个多边形数组,但我不知道如何将地图移动到多边形的中心。我研究了传单,发现polygon.getBounds() 和map.fitBound(polygon.getBounds()) 可以解决我的问题。但是,我不知道如何在 react-leaflet 中使用它。你能告诉我如何解决这个问题吗?提前致谢。 我的代码:
function MyComponent() {
const map = useMap()
const polygonMap=L.polygon(polygon.geometry.coordinates).addTo(map)
if(polygon.geometry){
console.log(polygon.geometry.coordinates)
map.fitBounds(polygonMap.getBounds())
}
return null
}
'polygon.geometry.coordinates' 返回多边形的点数组。我想将其转换为传单多边形并使用 getBounds() 在地图上获取其中心点。