Select to view content in your preferred language

DynamicMapServiceLayer sublayers

2151
8
03-24-2017 02:28 PM
JoshBartz
Emerging Contributor

I have a few interesting cases when trying to load dynamic layers with sublayers.

1) If I create a layer doing something like this:

UserCredentials credentials = new UserCredentials();
credentials.setUserAccount(uname, pword);
ArcGISDynamicMapServiceLayer serviceLayer = new ArcGISDynamicMapServiceLayer(url, int[]{parentId}, credentials);‍‍‍

For a layer with 5 sublayers, all default visible, nothing shows. So I wind up having to initialize the layer, listen for the status change, loop through the layer infos to retrieve the sublayer ids, then add a new layer to the MapView using an array containing the parent and all child IDs. On iOS using just the parent ID is sufficient.

2) If I only want 1 visible sublayer, on iOS I can pass just the ID of the sublayer. But on Android, I have to pass the parent and sublayer IDs. Am I going about this all wrong?

0 Kudos
8 Replies
AlexanderNohe1
Honored Contributor

Hi Josh Bartz‌,

Do you have a sample DynamicLayer we can test with? I think for myself, I would do something like this to get all layers to show (based on the documentation):

ArcGISDynamicMapServiceLayer serviceLayer = new ArcGISDynamicMapServiceLayer(url, null, credentials);

I look forward to your reply.

Thanks,

Alexander

0 Kudos
JoshBartz
Emerging Contributor

Hi Alexander Nohe‌. Sorry, I should have been a bit more specific. Yes, if I use the service url with a null array, it will load all of the layers. However, take this layer for example: "original/SWPA (MapServer) "

It has a lot of layers. So if I just pass the url and a null array, it will load all of them. But if I only want Roads (ID=2) and all of its sublayers (3, 4, 5), I have to pass an array of (2, 3, 4, 5), whereas on iOS I only have to send 2. So if I don't know that the IDs of Roads' sublayers are 3, 4, 5, then I need to initialize Roads and go through the array to get the sublayer IDs.

Additionally, if I only want the Interstate Highways sublayer of roads, I have to pass (2, 3). On iOS I only have to pass 3.

I'm just trying to see if there are any other options so that we can set our data up better.

Thanks,

Josh

0 Kudos
AlexanderNohe1
Honored Contributor

Hi Josh Bartz‌,

Thanks for the clarification.  I will take a look into it when I get some free time and see what I can find.

Thanks,

Alexander

0 Kudos
AlexanderNohe1
Honored Contributor

Hi Josh Bartz‌,

I did investigate this a bit and found the behavior that you described on Android to be replicated.  I still need to test against runtime version 100 to see the behavior there.

Thanks,

Alexander

JoshBartz
Emerging Contributor

ANohe-esristaff‌ Have you learned anything else?

0 Kudos
AlexanderNohe1
Honored Contributor

Sorry 9erNumber16‌,

At this time, I did not discover anything worthwhile in sharing regarding this case. I am still reviewing some notes and hope to have an update soon.

Thanks,

Alexander

0 Kudos
AlexanderNohe1
Honored Contributor

Hi Josh Bartz‌,

I did something like this to only view the roads layer and sublayers contained within that parent:

public class MainActivity extends AppCompatActivity {

    MapView mapView;
    ArcGISMapImageLayer mMapImageLayer;
    SublayerList mLayers;
    ArcGISMap map;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

// inflate MapView from layout
        mapView = (MapView) findViewById(R.id.map);

// create a map with the Basemap Type topographic
        ArcGISMap map = new ArcGISMap(Basemap.Type.TOPOGRAPHIC, 27.763528, -82.543717, 6);

// create a MapImageLayer with dynamically generated map images
        mMapImageLayer = new ArcGISMapImageLayer("https://x-23.env.nm.gov/arcgis/rest/services/original/SWPA/MapServer");
        mMapImageLayer.setOpacity(0.5f);

// add world cities layers as map operational layer
        map.getOperationalLayers().add(mMapImageLayer);

// set the map to be displayed in this view
        mapView.setMap(map);

        map.loadAsync();
        mMapImageLayer.loadAsync();
        mMapImageLayer.addDoneLoadingListener(new Runnable() {
            @Override
            public void run() {
                // get the layers from the map image layer
                mLayers = mMapImageLayer.getSublayers();

//This is the line where the error occurs
                for(ArcGISSublayer sub : mLayers) {
                    sub.setVisible(false);
                }

                mLayers.get(2).setVisible(true);

            }
        });





    }
}

I hope this helps!

Thanks,

Alexander

JoshBartz
Emerging Contributor

Thanks, ANohe-esristaff‌, I'll give this a try.

0 Kudos