Cannot turn on individual layer in group layer in DynamicMapServiceLayer

934
9
12-22-2011 03:30 PM
ClementLau
New Contributor
I have a DynamicMapServiceLayer as follow
Group Layer Name (0)
   Individual Layer Name1 (1)
   Individual Layer Name2 (2)
   Individual Layer Name3 (3)

When I turn Group Layer Name (0) on, all Individual Layers are on (shown in MapView).  When I turn Group Layer Name (0) off, all Individual Layers are off.  How can I only display an Individual layer?
0 Kudos
9 Replies
fengyunshen
New Contributor
Use ArcGISDynamicMapServiceLayers' getAllLayers() method or getLayers() method to get ArcGISLayerInfo instance, and use ArcGISLayerInfo to control sub_layers individually.
0 Kudos
ClementLau
New Contributor
Thank you fengyunshen,

I had done this.

I had try:
ArcGISDynamicMapServiceLayer.getAllLayers()[0].setVisible(true);
ArcGISDynamicMapServiceLayer.getAllLayers()[1].setVisible(false);
ArcGISDynamicMapServiceLayer.getAllLayers()[2].setVisible(true);
ArcGISDynamicMapServiceLayer.getAllLayers()[3].setVisible(false);
-> three sub-layers are shown in MapView.

ArcGISDynamicMapServiceLayer.getAllLayers()[0].setVisible(false);
ArcGISDynamicMapServiceLayer.getAllLayers()[1].setVisible(false);
ArcGISDynamicMapServiceLayer.getAllLayers()[2].setVisible(true);
ArcGISDynamicMapServiceLayer.getAllLayers()[3].setVisible(false);
-> three sub-layers are not shown in MapView.
0 Kudos
ClementLau
New Contributor
anyone can help or facing the same situation?
0 Kudos
ArchanaAgarwal
New Contributor III
Hi,

Could you send us the link to your service?

Thanks.
0 Kudos
ClementLau
New Contributor
I am using Samsung Galaxy Tab 10.1 (android 3.1).

You can try the following code.

DynamicMapServiceLayer -
http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/PublicSafety/PublicSafetyOperationalLayer...

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content">
<Button android:id="@+id/btn0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="0"/>
<Button android:id="@+id/btn1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1"/>
    <Button android:id="@+id/btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="2"/>
    <Button android:id="@+id/btn3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="3"/>
    <Button android:id="@+id/btn4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="4"/>
    <Button android:id="@+id/btn5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="5"/>
    <Button android:id="@+id/btn6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="6"/>
    <Button android:id="@+id/btn7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="7"/>
    <Button android:id="@+id/btn8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="8"/>
</LinearLayout>

<!-- MapView layout and initial extent -->
    <com.esri.android.map.MapView
        android:id="@+id/mMapView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        initExtent="-1.3296373526814876E7 3930962.41823043 -1.2807176545789773E7 4201243.7502468005">
    </com.esri.android.map.MapView>
</LinearLayout>



public class HelloWorldActivity extends Activity implements OnClickListener {

MapView mMapView;
ArcGISDynamicMapServiceLayer mArcGISDynamicMapServiceLayer;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mMapView = (MapView)findViewById(R.id.mMapView);
        mMapView.addLayer(new ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"));
        mArcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/PublicSafety/PublicSafetyOperationalLayer...");
        mMapView.addLayer(mArcGISDynamicMapServiceLayer);
       
        Button btn0 = (Button)findViewById(R.id.btn0);
        Button btn1 = (Button)findViewById(R.id.btn1);
        Button btn2 = (Button)findViewById(R.id.btn2);
        Button btn3 = (Button)findViewById(R.id.btn3);
        Button btn4 = (Button)findViewById(R.id.btn4);
        Button btn5 = (Button)findViewById(R.id.btn5);
        Button btn6 = (Button)findViewById(R.id.btn6);
        Button btn7 = (Button)findViewById(R.id.btn7);
        Button btn8 = (Button)findViewById(R.id.btn8);
       
        btn0.setOnClickListener(this);
        btn1.setOnClickListener(this);
        btn2.setOnClickListener(this);
        btn3.setOnClickListener(this);
        btn4.setOnClickListener(this);
        btn5.setOnClickListener(this);
        btn6.setOnClickListener(this);
        btn7.setOnClickListener(this);
        btn8.setOnClickListener(this);
    }
   
@Override
public void onClick(View v) {
  if (v.getId() == R.id.btn0) {
   mArcGISDynamicMapServiceLayer.getAllLayers()[0].setVisible(!mArcGISDynamicMapServiceLayer.getAllLayers()[0].isVisible());
  }
  if (v.getId() == R.id.btn1) {
   mArcGISDynamicMapServiceLayer.getAllLayers()[1].setVisible(!mArcGISDynamicMapServiceLayer.getAllLayers()[1].isVisible());
  }
  if (v.getId() == R.id.btn2) {
   mArcGISDynamicMapServiceLayer.getAllLayers()[2].setVisible(!mArcGISDynamicMapServiceLayer.getAllLayers()[2].isVisible());
  }
  if (v.getId() == R.id.btn3) {
   mArcGISDynamicMapServiceLayer.getAllLayers()[3].setVisible(!mArcGISDynamicMapServiceLayer.getAllLayers()[3].isVisible());
  }
  if (v.getId() == R.id.btn4) {
   mArcGISDynamicMapServiceLayer.getAllLayers()[4].setVisible(!mArcGISDynamicMapServiceLayer.getAllLayers()[4].isVisible());
  }
  if (v.getId() == R.id.btn5) {
   mArcGISDynamicMapServiceLayer.getAllLayers()[5].setVisible(!mArcGISDynamicMapServiceLayer.getAllLayers()[5].isVisible());
  }
  if (v.getId() == R.id.btn6) {
   mArcGISDynamicMapServiceLayer.getAllLayers()[6].setVisible(!mArcGISDynamicMapServiceLayer.getAllLayers()[6].isVisible());
  }
  if (v.getId() == R.id.btn7) {
   mArcGISDynamicMapServiceLayer.getAllLayers()[7].setVisible(!mArcGISDynamicMapServiceLayer.getAllLayers()[7].isVisible());
  }
  if (v.getId() == R.id.btn8) {
   mArcGISDynamicMapServiceLayer.getAllLayers()[8].setVisible(!mArcGISDynamicMapServiceLayer.getAllLayers()[8].isVisible());
  }
}

@Override
protected void onDestroy() {
  super.onDestroy();
}

@Override
protected void onPause() {
  super.onPause();
  mMapView.pause();
}

@Override  protected void onResume() {
  super.onResume();
  mMapView.unpause();
}
}
0 Kudos
ClementLau
New Contributor
ESRI_DEV2011,

The sample can help you to spot out the problem?

Clement
0 Kudos
DannyDong
New Contributor III
I think that is sth set by design. If you turn the group layer on, all the layers in the group will be turned on. If you turn the group layer off, all the layers in the group will be off. So how to turn on/off certain layers? I think that you don't need to worry about the group layer, just turn on/off the certain layers should work. At least this is my experience with ArcGIS Desktop. I think this should hold true for java script api too.  Please try my idea and see if it works.
0 Kudos
GregorySayre
New Contributor II
For what it's worth I'm having the same problem.   If the GROUP is set to visible then all layers in the group are displaying, regardless of what I set the individual layers as.   If the GROUP is set to invisible then no layers in the group display.

I'm using ARCGIS for android API version 1.01.
0 Kudos
tempJamiePowell
New Contributor
There is some useful information regarding the handling of layers visibility (GroupLayers) through the REST API, that may shed some light on this question. Please look at the following documentation link for more information.

http://resources.arcgis.com/en/help/rest/apiref/index.html?exportwebmap_spec.html
0 Kudos