Is there android code that lets you switch effectively between layers created in arcmap?

1249
3
08-11-2016 11:42 AM
PerlaAmbriz
New Contributor II

Hello,

I was wondering if anyone could help me.

I'm building an android application.

I made five layers in ArcMap. The first layer is the first floor map of my building. The second layer is the second floor map of my building and so on. I know how to put a single layer on my on top of a basemap in my android application. However I want the application to switch between layers(floors) when the user touches a button. (There will be five buttons--one for each floor). Is there an effective way to do this ? Or is there code out there that already does this?

Thanks for the help in advance!

0 Kudos
3 Replies
PerlaAmbriz
New Contributor II

Basically, i want to know if there is code that allows my users to switch between layers.

0 Kudos
PerlaAmbriz
New Contributor II

I think i figured out a way to do it. It works. However, can someone tell me if this is the best way to do it ?

This is how i did it.

In my strings.xml file i put the links to the some maps (I made for testing purposes) located in ArcGis online server:

          <string name="firstFloor">https://services3.arcgis.com/CapJ1hlMMupAogng/arcgis/rest/services/JB1STFLOOR/FeatureServer/0</string>

          <string name="secondFloor">https://services3.arcgis.com/CapJ1hlMMupAogng/arcgis/rest/services/JB2NDFLOOR/FeatureServer/0</string>

          <string name="thirdFloor">https://services3.arcgis.com/CapJ1hlMMupAogng/arcgis/rest/services/JB3RDFLOOR/FeatureServer/1</string>

          <string name="fourthFloor">https://services3.arcgis.com/CapJ1hlMMupAogng/arcgis/rest/services/JB4THFLOOR/FeatureServer/0</string>

          <string name="fifthFloor">https://services3.arcgis.com/CapJ1hlMMupAogng/arcgis/rest/services/JB5THFLOOR/FeatureServer/0</string>

then in my code i switched between layers with the following methods (methods get invoked when user presses a button in the application):

     //first layer
     public void onClickButtonOne(View v){

             // Remove any previous layers
             mMapView.removeLayer(mFeatureLayer);

             //set layer
             mMapView = (MapView) findViewById(R.id.map); //leave
             mFeatureServiceUrl = this.getResources().getString(R.string.secondFloor);//leave
             mFeatureLayer = new ArcGISFeatureLayer(mFeatureServiceUrl, ArcGISFeatureLayer.MODE.ONDEMAND);//leave
             mMapView.addLayer(mFeatureLayer);//leave
             mGraphicsLayer = new GraphicsLayer();//leave
             mMapView.addLayer(mGraphicsLayer);//leave
              }

       //Second layer
          public void onClickButtonTwo(View v){

             // Remove any previous layers
             mMapView.removeLayer(mFeatureLayer);

            //set layers
             mMapView = (MapView) findViewById(R.id.map); //leave
             mFeatureServiceUrl = this.getResources().getString(R.string.thirdFloor);//leave
             mFeatureLayer = new ArcGISFeatureLayer(mFeatureServiceUrl, ArcGISFeatureLayer.MODE.ONDEMAND);//leave
             mMapView.addLayer(mFeatureLayer);//leave
             mGraphicsLayer = new GraphicsLayer();//leave
             mMapView.addLayer(mGraphicsLayer);//leave
  
               }

         etc..

AlexanderNohe1
Occasional Contributor III

Hello Pearlz92

I think that making a comment on whether or not it is the best way to do a particular task is difficult.  This is because we do not have intimate knowledge of the project as you do. What may be the best workflow for your project may not be the best workflow for others.  If you found success with the above code, I would encourage you to continue on that path as this may be the best option for you.

I hope this helps!

0 Kudos