Select to view content in your preferred language

Android SDK's MapView removeLayer method not working

3643
1
Jump to solution
06-16-2015 08:35 AM
DanielGray
Deactivated User

I'm currently exploring ArcGIS's Android SDK.

However, I've found that when adding a ShapefileFeatureTable to a FeatureLayer:

        FeatureLayer featureLayer = new FeatureLayer(shapefileFeatureTable);

        featureLayer.setRenderer(new SimpleRenderer(new SimpleFillSymbol(

                getResources().getColor(android.R.color.holo_blue_bright),

                SimpleFillSymbol.STYLE.SOLID)));

        mapView.addLayer(featureLayer);

and then trying to remove it:

        mapView.removeLayer(featureLayer);

it doesn't work! (the layer is still visible)

I've tried to change the following:

        mapView.addLayer(featureLayer,0);

        mapView.removeLayer(0);

and this doesn't work either.

EXPLANATORY NOTE: I'm trying to add and remove the feature layer because I want to show a GraphicsLayer on the map, but if I don't load a FeatureLayer first, the MapView stays completely black.  I tried to set the SpatialReference and the background grid, but the only thing that worked was adding a bogus FeatureLayer first.  I eventually "fixed it" by calling:

    mapView.addLayer(featureLayer);

    featureLayer.setVisible(false);

But I still think it's suboptimal solution.  Any ideas??

1 Solution

Accepted Solutions
MengyiGuo
Deactivated User

Have your issue reproduced. I noticed that if you remove the layer immediately after adding it, removing won't work. This is because your layer is not loaded yet, so you can not remove it. Try this:

mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {

   @Override
   public void onStatusChanged(Object o, STATUS status) {

   if(o==featureLayer)

  {

   if(status==STATUS.LAYER_LOADED) {

   mMapView.removeLayer(featureLayer);

  

  }

  }

  }

});

I'm aware of the black view issue as well, I think that is because you don't have a layer on the mapview. If you have a graphicsLayer or a basemap, it shouldn't show a black view.

View solution in original post

1 Reply
MengyiGuo
Deactivated User

Have your issue reproduced. I noticed that if you remove the layer immediately after adding it, removing won't work. This is because your layer is not loaded yet, so you can not remove it. Try this:

mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {

   @Override
   public void onStatusChanged(Object o, STATUS status) {

   if(o==featureLayer)

  {

   if(status==STATUS.LAYER_LOADED) {

   mMapView.removeLayer(featureLayer);

  

  }

  }

  }

});

I'm aware of the black view issue as well, I think that is because you don't have a layer on the mapview. If you have a graphicsLayer or a basemap, it shouldn't show a black view.