[GIS] Change Map layers when zooming in (JavaScript API)

arcgis-10.1arcgis-javascript-api

I have created a web map application (Javascript API) :

require([
  "esri/map",
  "esri/dijit/InfoWindowLite",
  "esri/InfoTemplate",
  "esri/layers/FeatureLayer",
  "dojo/dom-construct",
  "dojo/domReady!"],
function(
  Map,
  InfoWindowLite,
  InfoTemplate,
  FeatureLayer,
  domConstruct
){
  map = new Map("map", {
    basemap: "topo",
    center: [-85.416, 49.781],
    zoom: 5,
    logo: false});

  TestLayer = new esri.layers.ArcGISDynamicMapServiceLayer(
    "http://Myserver/arcgis/rest/services/TestMAP/MapServer");

  query = new esri.tasks.Query();
  query.returnGeometry = true;
  query.outFields = ["CCSNAME", "DAUID20111" ,"DAUID201_5" ,"DAUID201_9" , "DAUID20_14",  "DAUID20_19", "NAME" , "CITY",  "POST_CODE", "HRUID2007.csv.GPF", "HRUID2007.csv.GPE", "HRUID2007.csv.SPECF", "HRUID2007.csv.SPECE" ];

  symbol = new esri.symbol.SimpleFillSymbol(
    esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(
      esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([0,255,0]), 2),new dojo.Color([0,255,0,0]));

  map.addLayer(TestLayer);

In the default zoom level set, 3 map layers from **http://Myserver/arcgis/rest/services/TestMAP/MapServer** are showing up.

How can I change my code so that in the default zoom level I get another 3 layers from this url:

"http://Myserver/arcgis/rest/services/TestMAP2/MapServer"

and then when I zoom in I get the current ones.

Best Answer

The solution is to add another dynamicMapServiceLayer to the map and declare the levels of the detail (LODs) at which map services in your map will be shown.

Check about this sample on esri Javascript resource page: https://developers.arcgis.com/en/javascript/jssamples/map_switch_layer_on_zoom.html