我正在尝试使用Leaflet制作离线地图。
为了节省数据,用户有一个选项可以不保存所有缩放级别。例如,用户有15和17级缩放。
现在的问题是,当用户从15级缩放到16级时,如何在从16级缩放中显示15级(或17级)图层?
另一种选择是跳过16级缩放,但也许还有其他的选择?我看了Leaflet的源代码,但是无法理解。
更新插件的Fiddle (由Ilja Zverev提供),可以跳过某些缩放级别。
HTML
<div id="map"></div>
<div id="out"></div>
JAVASCIPT
var map = L.map('map').setView([52.084, 5.11], 15);
isNoZoomlevel = 16;
L.tileLayer('http://a.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://openstreetmap.org">OpenStreetMap</a>',
maxZoom: 18
}).addTo(map);
map.on('zoomend', function() {
console.log("I zoomed to level " + map.getZoom());
if(map.getZoom() == isNoZoomlevel) {
console.log("This offline zoomlevel does not excist");
$("#out").html("This is no zoomlevel");
// Howto replace the zoomlevel 16 with 17 or 15??
} else {
$("#out").html("");
}
});
CSS
#map {
height: 250px;
}