Leaflet.js 地图的所有边都有额外的灰色 space,让我无限拖动
Leaflet.js map has extra grey space on all sides and lets me drag infinitively
我正在使用 Leaflet.js 生成带有一些停留信息的地图。我打开了 noWrap 选项,这样世界就不会重复了。然而,四面八方都是一大片无限的灰色。我可以无限拖动该区域。不幸的是,我需要有拖动功能才能在放大地图时绕过地图。有人 运行 解决过这个问题吗?我对 CSS 所做的任何事情似乎都没有对问题产生任何影响。任何信息都会很棒!
基里
var map = L.map('map').setView([41.9, 12.5], 2);
L.tileLayer(tileServerUrl, {
attribution: tileServerAttribution,
maxZoom: 16,
minZoom: 2,
noWrap: true
}).addTo(map);
map.keyboard.disable();
var bounds = map.getBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
bounds = L.latLngBounds(southWest,northEast);
map.setMaxBounds(bounds);
您必须使用 "maxbounds" 来阻止拖动到边界:
这是一个示例:https://www.mapbox.com/mapbox.js/example/v1.0.0/maxbounds/
我正在使用 Leaflet.js 生成带有一些停留信息的地图。我打开了 noWrap 选项,这样世界就不会重复了。然而,四面八方都是一大片无限的灰色。我可以无限拖动该区域。不幸的是,我需要有拖动功能才能在放大地图时绕过地图。有人 运行 解决过这个问题吗?我对 CSS 所做的任何事情似乎都没有对问题产生任何影响。任何信息都会很棒!
基里
var map = L.map('map').setView([41.9, 12.5], 2);
L.tileLayer(tileServerUrl, {
attribution: tileServerAttribution,
maxZoom: 16,
minZoom: 2,
noWrap: true
}).addTo(map);
map.keyboard.disable();
var bounds = map.getBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
bounds = L.latLngBounds(southWest,northEast);
map.setMaxBounds(bounds);
您必须使用 "maxbounds" 来阻止拖动到边界: 这是一个示例:https://www.mapbox.com/mapbox.js/example/v1.0.0/maxbounds/