ThinkGeo.com    |     Documentation    |     Premium Support

Setting Overlay.IsVisible to false initially will hide it permenantly

When initially populating the map I have some layers that may not be visible at the outset, but want to load so they can be enabled if needed by the user.

Example:
LayerOverlay newOverlay = new LayerOverlay();

“Add some features to it”
“Now I don’t want to see it initially, but maybe later”

newOverlay.IsVisible = false;

“Add it to the map”
MapView.Overlays.Add(“NewLayer”, newOverlay);

“Later when I try to find the overlay to turn it on”

Overlay foundOverlay = MapView.Overlays[“NewLayer”];
foundOverlay.IsVisible = true;

This overlay does not show on the map, layers initially loaded with the IsVisible = true all work as I would expect.

Am I missing a step here (I did try the MapView.RefreshAsync(), but this is not needed for the initial ones set as true, and infact just refreshes the map twice.

This one has me baffled. I suspect that I will need to load all layers as visible, then later set the hidden ones as needed.

I think I found a fix.

There was another note about setting the IsVisible flag does not actually draw the layer, it just turns it on. In this case the Layer was ignored on the initial draw as the flag was false (it just skipped it). So following along on that I came across:

MapView.RefreshAsync(overlay, OverlayRefreshType.RedrawIfNotDrawn);

to just redraw that layer (not the whole map), this seems to address my issue.

Hi Chris,

Thanks for reporting this!

  1. overlay.IsVisible = true; internally refreshes the overlay, so you don’t need to call
    MapView.RefreshAsync(overlay, OverlayRefreshType.RedrawIfNotDrawn);
    Otherwise the overlay will be drawn twice.

  2. Each overlay needs to be initialized with a MapView, we did it in MapView.RefreshAsync() but not in Overlay.Refresh() which is internally called in IsVisible property. We didn’t initialize for Invisible Overlays in MapView.RefreshAsync() though and that’s the cause of this issue. To fix it, you can just call the following code after adding the overlay to the mapview.
    Overlay.Initialize(MapView);

  3. We will initialize all the overlays (including the invisible ones) in MapView.RefreshAsync() to get rid of the confusions in the future versions.

Again thanks for reporting this, let us know if you still see any issues.

Thanks,
Ben

Hi Chris,

The issue has been fixed in the latest beta 14.4.0-beta031, in which MapView.RefreshAsync() initializes the invisible overlays as well.

Thanks,
Ben