Switching layers when zoomed in

534
3
03-04-2011 01:08 AM
JamesBurton
New Contributor
Hi, my mapservice has two layers and I want each to display at different extents. I can see that I can specify this in the map constructor:

var lods = [
          {"level" : 1, "resolution" : 0.010986328125, "scale" : 4617149.97766929},
          {"level" : 2, "resolution" : 0.0054931640625, "scale" : 2308574.98883465} 
 ];
map = new esri.Map("map", { extent: startExtent, lods: lods });


I think I've got the wrong end of the stick here though -- that sets the lods for the map, right? How do I say which layer should be shown at a certain lod?

Thanks in advance,
0 Kudos
3 Replies
HemingZhu
Occasional Contributor III
Hi, my mapservice has two layers and I want each to display at different extents. I can see that I can specify this in the map constructor:

var lods = [
          {"level" : 1, "resolution" : 0.010986328125, "scale" : 4617149.97766929},
          {"level" : 2, "resolution" : 0.0054931640625, "scale" : 2308574.98883465} 
 ];
map = new esri.Map("map", { extent: startExtent, lods: lods });


I think I've got the wrong end of the stick here though -- that sets the lods for the map, right? How do I say which layer should be shown at a certain lod?

Thanks in advance,


Why just set scale range for each layer in your .mxd(.msd)? It's much easy and no code is needed.
0 Kudos
JamesBurton
New Contributor
Thanks for your reply. The data is shared by several apps so I can't do that. I've got something working along these lines:

dojo.connect(map, "onZoomEnd", addAerialLayer);
var hasAerialLayer = false;

function addAerialLayer() {
     if (map.getLevel() > 8 && !hasAerialLayer){
  map.addLayer(aerialLayer, 1);
  hasAerialLayer = true;
     } else if (map.getLevel() < 9 && hasAerialLayer){
  map.removeLayer(aerialLayer);
  hasAerialLayer = false;
     }
 }
0 Kudos
HemingZhu
Occasional Contributor III
Thanks for your reply. The data is shared by several apps so I can't do that. I've got something working along these lines:

dojo.connect(map, "onZoomEnd", addAerialLayer);
var hasAerialLayer = false;

function addAerialLayer() {
     if (map.getLevel() > 8 && !hasAerialLayer){
  map.addLayer(aerialLayer, 1);
  hasAerialLayer = true;
     } else if (map.getLevel() < 9 && hasAerialLayer){
  map.removeLayer(aerialLayer);
  hasAerialLayer = false;
     }
 }


map's lods property specify the visible scale range for the map, not the individual layers in the map services. You might have to use layerInfos to loop through your aerialLayer service and use setVisibleLayers to set visibility of specific layer in your service. Obviously i assumed that your aeiallayer service is a dynamic map service because cann't use setVisibleLayers for tiled map services.
0 Kudos