最大放大传单时显示多大陆 - 数据仅显示在中心大陆
Multi continents shown when at max zoom in leaflet - data only shown on center continent
这里是 Leaflet 的新用户,我开发了一个从 Oracle 数据库中提取 geoJSON 的地图应用程序。这一切都有效,但如果我将 Leaflet 一直放大到它显示该大陆的多个副本的地方,我的数据只会在我放大到中心大陆时显示。我的问题是这正常吗?如何防止用户在继续向东或向西移动时平移到另一个大陆?
您可以设置一个 minZoom
属性 来避免这种情况。
类似于:
var map = L.map('map', {
center: [51.505, -0.09],
minZoom: 4,
zoom: 13
});
编辑:可能我误解了你的问题。
要将地图视图限制在您使用的给定范围内:
map.setMaxBounds(LatLngBounds);
更具体地说:
map.setMaxBounds(L.latLngBounds(
L.latLng(85, -180),
L.latLng(-85, 180)
));
我怀疑这是正常的,我不相信 Leaflet 试图在高缩放状态下复制标记。
您可以尝试启用 map.worldCopyJump
,这听起来可能适合您的目的:
With this option enabled, the map tracks when you pan to another
"copy" of the world and seamlessly jumps to the original one so that
all overlays like markers and vector layers are still visible.
如果失败,请尝试限制 minZoom
and/or 设置 maxBounds
、like 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);
这里是 Leaflet 的新用户,我开发了一个从 Oracle 数据库中提取 geoJSON 的地图应用程序。这一切都有效,但如果我将 Leaflet 一直放大到它显示该大陆的多个副本的地方,我的数据只会在我放大到中心大陆时显示。我的问题是这正常吗?如何防止用户在继续向东或向西移动时平移到另一个大陆?
您可以设置一个 minZoom
属性 来避免这种情况。
类似于:
var map = L.map('map', {
center: [51.505, -0.09],
minZoom: 4,
zoom: 13
});
编辑:可能我误解了你的问题。
要将地图视图限制在您使用的给定范围内:
map.setMaxBounds(LatLngBounds);
更具体地说:
map.setMaxBounds(L.latLngBounds(
L.latLng(85, -180),
L.latLng(-85, 180)
));
我怀疑这是正常的,我不相信 Leaflet 试图在高缩放状态下复制标记。
您可以尝试启用 map.worldCopyJump
,这听起来可能适合您的目的:
With this option enabled, the map tracks when you pan to another "copy" of the world and seamlessly jumps to the original one so that all overlays like markers and vector layers are still visible.
如果失败,请尝试限制 minZoom
and/or 设置 maxBounds
、like 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);