adi3ek

Hiding layers controlled by the user

Discussion created by adi3ek on Mar 20, 2013
Hi Everyone,

I'm working on my first Android app using ArcGIS SDK (10.1.1) and I'm stuck on something that's likely to be pretty straightforward, that is, hiding and un-hiding sub-layers of a layer by the user.

I was able to render my layers on top of Bing map (so far so good...):

mMapView = (MapView) findViewById(R.id.map);
mMapView.setEsriLogoVisible(true);
 
// Bing
mBingMapLayer = new BingMapsLayer(bingAppId, BingMapsLayer.MapStyle.AERIAL);
mMapView.addLayer(mBingMapLayer, 0);

// Custom
mCustomLayer = new ArcGISTiledMapServiceLayer("http://###/MapServer");
mMapView.addLayer(mCustomLayer, 1);


Then, I have a control element which renders checkboxes for each sub-layers of mCustomLayer, so basically what I do is something like this:

mLayers = mCustomLayer.getAllLayers();


..and here we go, each checkbox at position is initialised like this:

ArcGISLayerInfo layer = mLayers[position];

CheckBox layerCheckBox = ((CheckBox) v.findViewById(R.id.chkLayer));
layerCheckBox.setText(layer.getName() + " (ID: " + layer.getId() + ")");
layerCheckBox.setChecked(layer.isVisible());
layerCheckBox.setTag(layer);

layerCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  ArcGISLayerInfo layer = (ArcGISLayerInfo) buttonView.getTag();
  layer.setVisible(isChecked);
 }
});


And the only problem is, that it's just not working! You can check & uncheck any layers and it's isVisible() state is changing according to correcponding checkbox state, but they remain on the map view no matter what. So, the question is: What do I'm missing here?

I can only hide or unhide the mCustomLayer like this:

mCustomLayer.setVisible(state);


...but no luck with sub-layers.

Any thoughts?

Outcomes