ThinkGeo.com    |     Documentation    |     Premium Support

Calling Refresh after changing layer order does not work

Within an overlay, I want to move a layer up or down so it’ll appear below or above another layer within the same overlay. Here’s some sample code:

var layerIndex = ((LayerOverlay)MyMap.Overlays[overlayName]).Layers.IndexOf(layer); // retrieved layer in previous step

if (layerIndex < 0)
{
    return;
}

var overlay = MyMap.Overlays[overlayName];
((LayerOverlay)MyMap.Overlays[overlayName]).Layers.MoveDown(layerIndex); // I can see the order in the Layers collection properly change after this call
MyMap.Overlays[overlayName].Refresh(); // does not refresh the map

I’ve tried several of the refreshes, including refreshing just the current extent, refreshing the whole map, etc. Nothing actually refreshes the map. However, if I zoom in/out I can then see the changes. Is there something I’m missing?

Also, if I pan partly across the area of the affected layers, and then pan back, I can see the correct order of the layers for just that “slice” of the map. Is there some caching stuff going on in the moveup/down functions?

Hi Dan,

I saw this issue before, and it has been fixed in the latest version.

I don’t think you are using the latest version (as you are using Refresh() instead of RefreshAsync()). If you do want to upgrade to the latest, that’s great. But I need to remind you the new APIs are Async-based, which makes the map more responsive while you might need to make relative more changes to your project. If you do want to stay at where you are, let us know your current version and we’ll see what we can do.

By the way, a quick thing you can try is to clear the LayerOverlay.Layers collection and readd all the layers back in the new order.

Thanks,
Ben

Hi Ben, thanks for the response.

I’m currently on version 13.0.

Just tried your suggestion, by clearing the layers and re-adding. Same issue unfortunately.

Also tried zooming via code, but that didn’t work either. Only zooming via mouse.

Hi Dan,

Just upgrade to v13.1.1 and it will fix it. Here is a quick demo, hit the button and the point layer moves down.
LayerMoveDownSample.zip (4.3 KB)

Thanks Ben. Went ahead and updated everything to 14.1 and tested. Works well.

Great! yep, v14 will also do the trick.