Stop globe spin on search suggestion selection

In 3D mode, I have a typical spinGlobe function to automatically rotate the camera, which is great. I also have the following code to kill the rotation when the user types a location in to the native search box and hits enter:

this.viewer.geocoder.viewModel.search.afterExecute.addEventListener(function(){
// kill spinning globe
stopSpin();
});

``

However, the above code does not kill the rotation if the user clicks on one of the suggested locations Cesium kindly lists below the search box. Is there an event for when a search suggestion is selected?

Hi Damien,

It looks like you are adding the event listener correctly. Does the function get called at all? If it does, I don’t know what stopSpin() does, I’ll need more context.

Thanks,

Gabby

Hi Gabby,

If I type a location in the search box and hit enter, the function does get called and stopSpin() works. However, if I start to type a location and then click on one of the suggestions provided by Cesium, the function is not called.

Kind regards,

Damien

I see, I can duplicate this and I’ve opened an issue #6313 to track. In the meantime, you can add an event listener to GeocoderViewModel.complete, but that will be raised at the completion of the flight instead of the beginning, but you can set the flight duration to 0. If you wanted to go a bit deeper, you could dive into the UI code and maybe suggest a fix. Contributions are welcome!

Thanks,

Gabby