Incorrect AGSLayer info in webMap:didLoadLayer:

3612
4
Jump to solution
11-17-2015 03:25 PM
marius
by
New Contributor III

Hello,

I'm trying to add a button that allows a user to disable certain layers, on user defined maps. The first implementation, that worked fine, was using webMap:didLoadLayer: to save the loaded layers to a different array, and then toggle the layer.visible property, as a response to a UITableView cell tap.

The problem with that approach is the fact that the (AGSLayer *)layer received by - (void)webMap:(AGSWebMap *)webMap didLoadLayer:(AGSLayer *)layer has different info then the AGSWebMapLayerInfo that are part of webMap.operationalLayers. The issue that bothers me is that the AGSLayer name is different than AGSWebMapLayerInfo title. If you're creating a layer using an online CSV file, the AGSLayer name is that url (e.g. https://docs.google.com/spreadsheets/d/...&output=csv), the AGSLayer layerId is nil, etc. The AGSWebMapLayerInfo title has the same name as specified in the ArcGIS online portal, the URL is correct, the layerId is set etc.

I've tried to change the AGSWebMapLayerInfo visibility property, however it does not seem to apply that change.

Do you have any suggestions on how to get the correct layer name, or how to convert an AGSWebMapLayerInfo to a valid AGSLayer that can change the visibility of the layer?

Thank you,

Marius

0 Kudos
1 Solution

Accepted Solutions
DiveshGoyal
Esri Regular Contributor

Use AGSWebMap#webMapLayerInfoForLayer:sublayerInfo:​ to find the corresponding webmaplayerinfo for a layer

You can then inspect the webmaplayerinfo for title and other settings to display in the UI, but to change the visibility or appearance you need to modify the layer. The *info objects are intended to be read-only to give you information on how the webmap was configured.

View solution in original post

0 Kudos
4 Replies
GagandeepSingh
Occasional Contributor II

Did you try using the `mapLayers` property on `AGSMapView`? Once you open the web map into the map view, all the layers in the web map should be reflected in the `mapLayers` property. You can go from there, changing the visibility of the individual layer.

0 Kudos
marius
by
New Contributor III

I don't think that the (feature) layers from that property are correctly setup. The feature layer seem to have a different name then the one from operationalLayers, and it seem to miss the layerId.

(lldb) po [self.esriMapView mapLayers]

<__NSArrayI 0x7c1991c0>(

<AGSTiledMapServiceLayer: 0x7e9798d0>,

<AGSFeatureLayer: 0x81d3ca80>,

<AGSFeatureLayer: 0x81f91e50>,

<AGSGraphicsLayer: 0x7be44910>,

<AGSGraphicsLayer: 0x7c510100>,

<AGSGraphicsLayer: 0x7c510190>,

<AGSGraphicsLayer: 0x7c510220>,

<AGSGraphicsLayer: 0x7c5102b0>,

<AGSGraphicsLayer: 0x7c5106a0>,

<AGSGraphicsLayer: 0x7c510730>

)

(lldb) po [[self.esriMapView mapLayers] objectAtIndex:1]

<AGSFeatureLayer: 0x81d3ca80>

(lldb) po [[[self.esriMapView mapLayers] objectAtIndex:1] name]

https://docs.google.com/spreadsheets/d/...&output=csv

(lldb) po [[[self.esriMapView mapLayers] objectAtIndex:1] layerId]

nil

(lldb) po [self.esriMapView class]

AGSMapView

(lldb) po [self.esriWebMap operationalLayers]

<__NSArrayI 0x81bda390>(

id: csv_2521

title:Google Sheeps

url:https://docs.google.com/spreadsheets/d/...&output=csv

opacity:1.000000

type:CSV ,

...

)

P.S. I wish this forum would use a similar WYSIWYG editor like StackOverflow. AFAIK, that editor was open sourced.

0 Kudos
DiveshGoyal
Esri Regular Contributor

Use AGSWebMap#webMapLayerInfoForLayer:sublayerInfo:​ to find the corresponding webmaplayerinfo for a layer

You can then inspect the webmaplayerinfo for title and other settings to display in the UI, but to change the visibility or appearance you need to modify the layer. The *info objects are intended to be read-only to give you information on how the webmap was configured.

0 Kudos
marius
by
New Contributor III

When checking why the AGSLayer visible property does not propagate to the corresponding AGSWebMapLayerInfo layerInfo object, I noticed that if you're hiding one of the layers, it is removed from operationalLayers, so if you're using operationalLayers as the user layers' source, you can't toggle the layers back on (or you have to also keep track of the for the removed layers).

I ended up implementing webMap:didLoadLayer: to save a copy of the loaded layer, update the AGSLayer name with the AGSWebMapLayerInfo title, then change that layer's 'visible' property, as needed.

Any reason why the AGSLayer's name, id and other properties are not set to their corresponding values from AGSWebMapLayerInfo?

0 Kudos