How to set different zoom levels in layers in a map using leaflet.

dictionary, javascript, leaflet

Solution

Here's a jsfiddle of an example of how to do this.

var map = new L.Map('amap', {
center: new L.LatLng(45.50144, -122.67599),
zoom: 4,
minZoom: 0,
maxZoom: 18,
layers: [
    L.tileLayer('http://{s}.tile.cloudmade.com/{key}/997/256/{z}/{x}/{y}.png', {
    maxZoom: 13,
    minZoom: 0,
    attribution: 'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 CloudMade',
    key: 'BC9A493B41014CAABB98F0471D759707'
}),
    L.tileLayer('http://server.arcgisonline.com/ArcGIS/' + 'rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
    minZoom: 14,
    maxZoom: 18,
    attribution: 'Tiles © Esri — ' 
        + 'Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, ' 
        + 'Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'})
]});

Problem

How to set different zoom level in layers in a map. I need to show different zoom levels in different layers. For example I have 2 layers 1.city, 2.state. When map initialization zoom level is 18, but when I am displaying STATE layer I have to set the zoom level into 22. I am using the below code. ``` var city = new L.LayerGroup(); var state = new L.LayerGroup(); var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png', cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 18}), map = new L.Map('map', {layers: [cloudmade,city,state], center: new L.LatLng(17.7003292, 82.01161768), zoom:18 }); ``` How can I set zoom level at layer initialization?

Original source