最大放大单张时显示的多个大洲 - 仅在中心大陆上显示的数据

时间:2015-05-25 17:48:00

标签: leaflet

Leaflet的新用户,我已经开发了一个从Oracle数据库中提取geoJSON的映射应用程序。这一切都有效,但如果我将Leaflet一直缩小到显示该大陆的多个副本的地方,我的数据仅显示我是否放大到中心大陆。我的问题是这是正常的吗?如何防止用户在继续向东或向西方向移动时向另一个大陆平移?

2 个答案:

答案 0 :(得分:2)

您可以设置minZoom属性以避免此情况。

类似的东西:

var map = L.map('map', {
    center: [51.505, -0.09],
    minZoom: 4,
    zoom: 13
});

Docs Reference

编辑:也许我误解了你的问题。

要将地图视图限制为您使用的给定边界:

map.setMaxBounds(LatLngBounds);

setMaxBounds Reference

更具体地说:

map.setMaxBounds(L.latLngBounds(
    L.latLng(85, -180),    
    L.latLng(-85, 180)    
));

答案 1 :(得分:0)

我怀疑这是正常的,我不相信Leaflet会尝试在高变焦状态下复制标记。

您可以尝试启用map.worldCopyJump,听起来它可能适用于您的目的:

  

启用此选项后,地图会在您平移到另一个时跟踪   “复制”世界并无缝跳转到原来的那个   标记和矢量图层等所有叠加层仍然可见。

如果失败,请尝试限制minZoom和/或设置maxBoundslike in this example

var southWest = L.latLng(40.712, -74.227),
    northEast = L.latLng(40.774, -74.125),
    bounds = L.latLngBounds(southWest, northEast);

var map = L.map('map', {
    // set that bounding box as maxBounds to restrict moving the map
    // see full maxBounds documentation:
    // http://leafletjs.com/reference.html#map-maxbounds
    maxBounds: bounds,
    maxZoom: 19,
    minZoom: 10
});

// zoom the map to that bounding box
map.fitBounds(bounds);