Select to view content in your preferred language

Adding multiple layers from a map server (points, lines, and polgons.)

917
2
Jump to solution
07-31-2023 03:35 PM
klebercj
Occasional Contributor

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?

1 Solution

Accepted Solutions
2 Replies
PuneetPrakash
Esri Contributor
0 Kudos
klebercj
Occasional Contributor

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.  

 

 

0 Kudos