I have a map server url from an ArcGIS REST Services. The ......../MapServer url contains 35 layers of point, line, and polygon features. I need to bring in all of them and have the ability to turn each on on and off. I know I can bring in each one individually, but that's 35 variables for each individual url (..../MapServer/0, 1, 2 etc...)
Right now I only know how to utilize the method shown in this turorial; https://developers.arcgis.com/kotlin/layers/tutorials/add-a-feature-layer/
Is there a way crawl the top level MapServer url and bring in the 35 layers, but still be able to individually control each layer i.e. make visible / invisible?
Solved! Go to Solution.
You can add the top level MapServer url as an ArcGISMapImageLayer https://developers.arcgis.com/kotlin/api-reference/arcgis-maps-kotlin/com.arcgismaps.mapping.layers/...
After that you can control each Sublayer's properties. You can see the API usage with this Android Java sample.
https://github.com/Esri/arcgis-runtime-samples-android/blob/main/java/change-sublayer-visibility/src...
You can add the top level MapServer url as an ArcGISMapImageLayer https://developers.arcgis.com/kotlin/api-reference/arcgis-maps-kotlin/com.arcgismaps.mapping.layers/...
After that you can control each Sublayer's properties. You can see the API usage with this Android Java sample.
https://github.com/Esri/arcgis-runtime-samples-android/blob/main/java/change-sublayer-visibility/src...
Yesterday I was able to create a block of code as follows
// create a map with the BasemapStyle topographic
val map = ArcGISMap(BasemapStyle.ArcGISImagery)
// Create an ArcGIS Map Image Layer for the ESRI map server layer
val mapServiceUrl = "https://.../MapServer"
val mapImageLayer = ArcGISMapImageLayer(mapServiceUrl)
// load sublayers of mapServiceUrl
val hospitalSublayer = ArcGISMapImageSublayer(1).apply {name = "Hospital"}
.......list of 35 sublayers
// create a group layer from scratch by adding the Sublayers as children
val mapSublayers = GroupLayer().apply {
name ="Group Base Map"
addAll(arrayListOf(, hospitalSublayer, ...35 sublayers listed out))
}
basemap.operationalLayers.add(mapImageLayer)
basemap.operationalLayers.add(mapSublayers)
I'm getting an error at "name ='Group Base Map'" where Android Studio throws "Val cannot be reassigned." AS highlights "name" in the list block of 35 sub-layers where I load sublayers of mapServiceUrl.