Changing Layer settings at runtime

336
2
04-17-2023 11:25 AM
MBambino_ATS
New Contributor III

I am trying to change Layer Visibility and Opacity during app runtime using a switch on the UI, but nothing changes on the map.

The Layer I am trying to change is added in-editor using the component interface and I am able to change these settings while the game is running and have them reflect on the map. However, when I try to reference the layer in code via the API, nothing changes on the map.
I am referencing the layer using ArcGISMapComponent.View.Map.Layers.At(index)

The layer shows up here and has all of it's data included based on what I set in the editor.

I have also tried adding the layer via scripting at runtime and in that case, No layer was added to the map, though the aforementioned layer list does contain it

image.png

MBambino_ATS_1-1681755913484.png

 

0 Kudos
2 Replies
Jade
by Esri Contributor
Esri Contributor

This workflow should work. Have you been able to debug? 

0 Kudos
MBambino_ATS
New Contributor III

I've tried debugging and the only thing I confirmed that the values of the layer are being changed, but the buildings are not changing visibility or opacity.

Just as a sanity check, here's some snippets

// Populating the layer list seen in picture        
for (ulong i = 0; i < layers.GetSize(); i++)
    {
        var l = layers.At(i);

        var item = Instantiate<LayerListItem>(_listItemPrefab);
        item.transform.SetParent(_content, false);
        item.Layer = l;
    }

// UI Events
void onToggle(bool on)
{
    _layer.IsVisible = on;
}

void onAlphaChanged(float a)
{
    _layer.Opacity = a;

    updateAlpha();
}
0 Kudos