Select to view content in your preferred language

mapImageLayer.GetSubLayers() failing when using map service

1010
3
Jump to solution
04-26-2017 05:44 AM
PhilippConner1
New Contributor

I am woefully green when it comes to using Android and the ESRI Android SDK (100.0.0). I apologize in advance for my greenhorn questions.

So I am looking to display a map service made of multiple layers in a simple Android app, I am current in my studio and gradle etc, as of last night (04/26/2017). I can handle the switch statements to change them but this issue I am running into is in actually getting them to display. 

Here is the map service in question: 

https://gis-server-02.usc.edu:6443/arcgis/rest/services/pjconner/fisheriesLandings/MapServer 

I am currently building off of the Change Sublayer Visibility sample app hosted here on github:

arcgis-runtime-samples-android/change-sublayer-visibility at master · Esri/arcgis-runtime-samples-an...

The problem I am running into is that when I go to get/set the visibility on a specific sublayer, I get index out of range exceptions because I assume the GetSublayers method is failing. I am not sure why this is the case. 

My current code is set up almost identical to the map initialization and layer set block in the example. 

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

// 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(getResources().getString(R.string.landings_service_url));
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
mMapView.setMap(map);

// get the layers from the map image layer
mLayers = mMapImageLayer.getSublayers();

//This is the line where the error occurs
mLayers.get(0).setVisible(true);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Despite the service displaying by default, it still doesn't show. So I figure I may have to manually set the visibility. As stated above. GetSubLayers seems to fail which leads to Null index exceptions when trying to force the layer visibility. Is this something wrong with my service, my code? 

I would be truly grateful for any help!

0 Kudos
1 Solution

Accepted Solutions
AlexanderNohe1
Honored Contributor

Hey Philipp Conner‌,

I noticed that the URL you were visiting was the HTTPS URL and not the HTTP URL.  I tried using this URL: pjconner/fisheriesLandings (MapServer) 

Rather than the secured URL (HTTP versus HTTPS).  I noticed that when I loaded this onto my phone in another app I was using, I would get Untrusted host warnings specifying that your certificate was invalid.  You may want to investigate that with your IT department to ensure that your SSL Certificate is valid.  Additionally, you may also want to install a web adapter so you are not visiting the port directly in your application.

This is what my code used looks like:

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("http://gis-server-02.usc.edu:6080/arcgis/rest/services/pjconner/fisheriesLandings/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
                mLayers.get(0).setVisible(true);
            }
        });





    }
}

View solution in original post

3 Replies
AlexanderNohe1
Honored Contributor

Hey Philipp Conner‌,

I noticed that the URL you were visiting was the HTTPS URL and not the HTTP URL.  I tried using this URL: pjconner/fisheriesLandings (MapServer) 

Rather than the secured URL (HTTP versus HTTPS).  I noticed that when I loaded this onto my phone in another app I was using, I would get Untrusted host warnings specifying that your certificate was invalid.  You may want to investigate that with your IT department to ensure that your SSL Certificate is valid.  Additionally, you may also want to install a web adapter so you are not visiting the port directly in your application.

This is what my code used looks like:

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("http://gis-server-02.usc.edu:6080/arcgis/rest/services/pjconner/fisheriesLandings/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
                mLayers.get(0).setVisible(true);
            }
        });





    }
}
PhilippConner1
New Contributor

Alex, this was a great help! I was able to contact the schools System Admin and he is looking into the SSL issue. In the interim I will be using the unsecured URL while deving. Thay you so much for the help!

0 Kudos
AlexanderNohe1
Honored Contributor

Happy to help!

0 Kudos