Leaflet 美国和加拿大地图单张

Leaflet 美国和加拿大地图单张,leaflet,Leaflet,我创建了一个函数,可在页面加载时为我的传单地图添加几层。 之后,我希望它基于这些层将视图居中 let layerGroup = L.featureGroup(); ... // add multiple layers layerGroup.addLayer(L.geoJson(feature)) ... leafletMap.addLayer(layerGroup); leafletMap.fitBounds(layerGroup.getBounds()); 它当前按预期工作

我创建了一个函数,可在页面加载时为我的传单地图添加几层。
之后,我希望它基于这些层将视图居中

let layerGroup = L.featureGroup();
... 
    // add multiple layers
    layerGroup.addLayer(L.geoJson(feature))
...
leafletMap.addLayer(layerGroup);
leafletMap.fitBounds(layerGroup.getBounds());
它当前按预期工作,贴图将放大以适应边界

然而,当美国是其中一个图层时,由于附近的岛屿,地图会完全缩小

有没有办法解决这个问题,从而在不缩小地图的情况下放大美国的地图


提前感谢

这不太容易修复,我不知道您的数据是什么样子的

解决方法是检查液化天然气的坐标是否为负值,然后向其添加360:

L.geoJson(feature,{
  coordsToLatLng: function coordsToLatLng(coords) {
    // the coords came into the function as //lng,lat,alt
    if(coords[0] < 0){
      coords[0] = coords[0]+360;
    }
    // the coords goes out as //lat,lng,alt
    return new L.LatLng(coords[1], coords[0], coords[2]);
  }
})
L.geoJson(功能{
coordsToLatLng:功能coordsToLatLng(coords){
//坐标以//lng、lat、alt的形式开始工作
if(坐标[0]<0){
坐标[0]=坐标[0]+360;
}
//坐标为//lat、lng、alt
返回新的L.LatLng(坐标[1],坐标[0],坐标[2]);
}
})

这不太容易修复,我不知道您的数据是什么样子

解决方法是检查液化天然气的坐标是否为负值,然后向其添加360:

L.geoJson(feature,{
  coordsToLatLng: function coordsToLatLng(coords) {
    // the coords came into the function as //lng,lat,alt
    if(coords[0] < 0){
      coords[0] = coords[0]+360;
    }
    // the coords goes out as //lat,lng,alt
    return new L.LatLng(coords[1], coords[0], coords[2]);
  }
})
L.geoJson(功能{
coordsToLatLng:功能coordsToLatLng(coords){
//坐标以//lng、lat、alt的形式开始工作
if(坐标[0]<0){
坐标[0]=坐标[0]+360;
}
//坐标为//lat、lng、alt
返回新的L.LatLng(坐标[1],坐标[0],坐标[2]);
}
})
我已经“修复”了这个问题,只需从geoJson文件中删除近岛坐标即可

在我的例子中,相应的坐标是:
[[172.9041,53.0012],[173.3013,52.9256],[173.1886,52.7957],[172.9443,52.7498],[172.6404,52.8688],[172.6604,53.0086],[172.9041,53.0012]。

如果有人找到更好的解决方案,请告诉我。

我已经通过从geoJson文件中删除近岛坐标“修复”了这个问题

在我的例子中,相应的坐标是:
[[172.9041,53.0012],[173.3013,52.9256],[173.1886,52.7957],[172.9443,52.7498],[172.6404,52.8688],[172.6604,53.0086],[172.9041,53.0012]。


如果有人找到更好的解决方案,请让我知道。

这对我不起作用。它只是改变了地图,但仍然导致相同的结果。这对我不起作用。它只是改变了地图,但仍然导致相同的结果。