Map Layer Switching for arcgis android


Layer switching is a common function in arcgis for android development, and my implementation method is very simple.

First, initialize multiple layer service objects, as follows:

ArcGISDynamicMapServiceLayer ady1;
ArcGISDynamicMapServiceLayer ady2;

Create a default layer in the onCreate () method:

 ady1= new// Dynamic layer
      ArcGISDynamicMapServiceLayer
    ("http://124.128.9.246:6080/arcgis/rest/services/DC/DCdata/MapServer");
     mapView.addLayer(ady1);

Finally, when you click the corresponding layer button, you can make a judgment:

switch (View.getId){
        case 0:
          if (ady1!=null){
            ady1.setVisible(true);
          }
          if(ady2!=null){
           ady2.setVisible(false);
         }
          break;
        case 1:
          if (ady2!=null){
            ady2.setVisible(true);
          }else {
            ady2= new// Dynamic layer
                ArcGISDynamicMapServiceLayer
                ("http://124.128.9.246:6080/arcgis/rest/services/DC/DCdata/MapServer");
            mapView.addLayer(ady2);
          }
          ady1.setVisible(false);
          break;

      }