Leaflet featureGroup中包含JSON数据的map.fitbunds()

Leaflet featureGroup中包含JSON数据的map.fitbunds(),leaflet,Leaflet,我无法让fitBounds命令在使用GeoJSON将数据引入featureLayer的项目中工作 这: 这是: var bounds = L.latLngBounds(pointsFeatureGroup); // Uncaught Error: Bounds are not valid. at e.fitBounds map.fitBounds(bounds); 不工作 我的简化代码如下: 如果我只是将标记单独引入到普通层中,那么类似这样的命令会起作用: map.fitBounds(Poi

我无法让fitBounds命令在使用GeoJSON将数据引入featureLayer的项目中工作

这:

这是:

var bounds = L.latLngBounds(pointsFeatureGroup); // Uncaught Error: Bounds are not valid. at e.fitBounds
map.fitBounds(bounds);
不工作

我的简化代码如下:

如果我只是将标记单独引入到普通层中,那么类似这样的命令会起作用:

map.fitBounds(PointsLayer.getBounds());
但是,这会引起其他功能的其他问题,这些功能需要功能层


我做错什么了吗?

根本原因是一个典型的异步问题

调用
map.fitBounds(vesselsFeatureGroup.getBounds())
时,
vesselsFeatureGroup
仍然为空(无子层),因此传单无法计算边界


只需在异步任务的回调中调用
getBounds
fitbunds
$.getJSON

看起来我还有很多研究要做!即使在第二次阅读之后,我也有很多想法。但我确实从你的帖子中看到了问题的原因,并研究了链接中的信息以进一步了解。
map.fitBounds(PointsLayer.getBounds());