简体   繁体   中英

Exclude zoom level in leaflet stamen map

I have got a very basic stamen map . If I zoom to level 19, the map is not shown. I think this is because of the max level 18 in the the file http://maps.stamen.com/js/tile.stamen.js . What can I do, to provide someone to zoom to level 19?

<!DOCTYPE HTML>
<html>
<head>
<title>Eine OSM Karte mit Leaflet</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.1.0/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.1.0/dist/leaflet.js"></script>
<script type="text/javascript" src="http://maps.stamen.com/js/tile.stamen.js"></script>
</head>
<body>
<div style="height: 700px;" id="mapid"></div>
<script>
var mymap = L.map('mapid').setView([50.27264, 7.26469], 13);
var layer = new L.StamenTileLayer("watercolor");
mymap.addLayer(layer);
</script>
  toner,terrain,terrain-classic,watercolor
</body>
</html>

Thanks in advance.

Actually it is possible to override the options of the StamenTileLayer .

After it is instantiated, simply set its options.maxZoom (to 19 in your case, so that the layer remains on map at that zoom level) and options.maxNativeZoom (to 18 in your case, so that Leaflet does not try to fetch tiles at zoom 19 but instead re-uses those from zoom 18 and scales them appropriately).

var layer = new L.StamenTileLayer("watercolor");

// Override Tile Layer maxZoom.
layer.options.maxZoom = 19;

// But specify that tiles are available only up to zoom level 18.
layer.options.maxNativeZoom = 18;

Demo: http://plnkr.co/edit/gumgWckQycEvg9Gaqt3s?p=preview

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM