Capture zoom out event

I want to capture zoom out event as soon as user reduces the map size to an extent i have to change the Map image layer.

var viewer = new Cesium.Viewer("cesiumContainer");
var scene = viewer.scene;
var clock = viewer.clock;
var referenceFramePrimitive;
var camera =;
    var height = Cesium.Cartographic.fromCartesian(camera.position).height;
      var layers = viewer.imageryLayers;
      var baseLayer = layers.get(0);
      layers.addImageryProvider(new Cesium.IonImageryProvider({ assetId: 3812,  maximumLevel : 5 }));

Is there any way to achieve this.


    const viewer = new Cesium.Viewer("cesiumContainer");

    const camera =;

    const scratchCartesian1 = new Cesium.Cartesian3();
    const scratchCartesian2 = new Cesium.Cartesian3();

    let startPos, endPos;

    camera.moveStart.addEventListener(function () {
        startPos = camera.positionWC.clone(scratchCartesian1);


    camera.moveEnd.addEventListener(function () {
        endPos = camera.positionWC.clone(scratchCartesian2);

        const startHeight = Cesium.Cartographic.fromCartesian(startPos).height;
        const endHeight = Cesium.Cartographic.fromCartesian(endPos).height;

        if (startHeight > endHeight) {
            console.log("zoom in");
        } else {
            console.log("zoom out");

1 Like


Thank you for the response. I looked over your solution and it seems robust! @James be sure to take a look at this.


@sam.rothstein yes sure i will try this solution thanks @ZhefengJin

1 Like


Great! Keep us posted :grinning: