Watching for imagery changes

Is there an event that I can listen for somewhere to determine when the selected imagery layer has changed with Cesium?

viewer.imageryLayers (which is an alias for scene.imageryLayers) has everything you need: https://cesiumjs.org/Cesium/Build/Documentation/ImageryLayerCollection.html

That appears to have all the events to let me know when they are shown, added, removed. I don't see an event for when one is selected.

If the imagery layer is being changed from the BaseLayerPicker widget, you can subscribe to BaseLayerPickerViewModel.selectedImagery to receive notifications when it is changed. Here is a code example:

Cesium.subscribeAndEvaluate(viewer.baseLayerPicker.viewModel, ‘selectedImagery’, function(newValue) {

console.log(newValue.name);

});

Here, newValue is a ProviderViewModel.

Is that what you are looking for?

-Hannah

That certainly sounds like it. Thanks Hannah.

Just wanted to follow up and say that this did indeed work.

I have multiple instances of Cesium in a single view and I wanted to keep the selected imagery layer the same across all of them. This allows me to do that.

Oh neat! What kind of project are you working on?

Can't really share a lot of details. Specifically though will be tracking objects and providing multiple view angles is why I wanted the multiple views. I can click/select an object and have a way out, global view in the top left, really close detailed view in the top right, and a further out view, large at the bottom

Hi Hannah,
I wanted to use the code ‘BaseLayerPickerViewModel.selectedImagery’ however, I am having difficulties on how to create BaseLayerPickerViewModel and there is no example. So can you perhaps give an example(code) of BaseLayerPickerViewModel with one imagery and the selectedImagery in the Sandcastle… Thanks you…

Cheers,

Abdullah

Hi Hannah,
console.log(newValue.name);

});" is a bit confusing for me…

Hi Hannah,
I wanted to use the code ‘BaseLayerPickerViewModel.selectedImagery’ however, I am having difficulties on how to create BaseLayerPickerViewModel and there is no example. So can you perhaps give an example(code) of BaseLayerPickerViewModel with one imagery and the selectedImagery in the Sandcastle… Thanks you…

Cheers,

Abdullah

If the imagery layer is being changed from the BaseLayerPicker widget, you can subscribe to BaseLayerPickerViewModel.selectedImagery to receive notifications when it is changed. Here is a code example:

Cesium.subscribeAndEvaluate(viewer.baseLayerPicker.viewModel, ‘selectedImagery’, function(newValue) {

console.log(newValue.name);

});

Here, newValue is a ProviderViewModel.

Is that what you are looking for?

-Hannah

Is there an event that I can listen for somewhere to determine when the selected imagery layer has changed with Cesium?
That appears to have all the events to let me know when they are shown, added, removed. I don’t see an event for when one is selected.

the code which you showed below " Cesium.subscribeAndEvaluate(viewer.baseLayerPicker.viewModel, ‘selectedImagery’, function(newValue) {