How to best "switch" ImageryProviders?

Before b10, I changed from Bing to OSM like:

cb.dayTileProvider = new Cesium.BingMapsTileProvider({server : ‘dev.virtualearth.net’});

And we simply switch to OSM with:

cb.dayTileProvider = new Cesium.BingMapsTileProvider({url : ‘http://tile.openstreetmap.org/’});

At b10 we use ImageryProviders and add them as layers:

cb.getImageryLayers().addImageryProvider({server: ‘dev.virtualearth.net’});

cb.getImageryLayers().addImageryProvider({url: ‘otile1.mqcdn.com/tiles/1.0.0/osm’});

What’s the right way to switch between them? Replace an existing one by deleting the old before adding the new, something like?

cb.getImageryLayers().remove(0)

cb.getImageryLayers().addImageryProvider({url: ‘otile1.mqcdn.com/tiles/1.0.0/osm’});

Or using toggling the .show attribute of the layer we want to hide and the one we want to show? This presumes we add all the layer we might be interested in up front, which seems like it could be a resource drain.

I’m looking at the SandCastle ImageryLayers example but a little distracted by the UI control manipulation vs. the display layers, and can’t find much in my generated docs about CentralBody.getImageryProvider() except:

prototype.getImageryLayers

Gets the collection of image layers that will be rendered on this central body.

Returns:

Thanks for all your patience and help.

Hi Chris,

Either approach is perfectly valid. You’re right that actually removing the layer is a bit more efficient (be careful - by default, removed layers are disposed), but the difference is actually pretty small. Imagery providers will do a bit of extra work when they’re constructed, such as grabbing data from a metadata service or obtaining the “missing” tile, but they don’t actually download any other tiles or do other work unless they’re shown. There’s also a bit of work done per terrain tile and per imagery layer, but for a layer that’s not shown that pretty much just amounts to a check of the show property.

Kevin

Thanks, Kevin.

I ended up doing a satelliteBillboards.removeAll() since it was the easiest within my code’s structure: I only have on active tile map at a time anyway.