export function measureArea(viewer:Cesium.Viewer){
    let clickStatus :boolean = false
    let positions : any[]=[]
    let labelEntity : any

    viewer.screenSpaceEventHandler.setInputAction(function (clickEvent:any) {
        clickStatus = true;
        var cartesian = viewer.scene.pickPosition(clickEvent.position);
        // var cartesian = viewer.scene.globe.pick(viewer.camera.getPickRay(clickEvent.position), viewer.scene);
        if (!cartesian) {
            return;
        }
        switch (positions.length) {
            case 0:
                positions.push(cartesian.clone()); //鼠标左击 添加第1个点
                addPoint(viewer,cartesian);

                // 注册鼠标移动事件
                viewer.screenSpaceEventHandler.setInputAction(function (moveEvent:any) {
                    var movePosition = viewer.scene.pickPosition(moveEvent.endPosition);
                    // var movePosition = viewer.scene.globe.pick(viewer.camera.getPickRay(moveEvent.endPosition), viewer.scene);
                    if (!movePosition) {
                        return;
                    }

                    switch (positions.length) {
                        case 1:
                            positions.push(movePosition);
                            addLine(viewer,positions);
                            break;

                        default:
                            if (clickStatus) {
                                positions.push(movePosition);
                            } else {
                                positions.pop();
                                positions.push(movePosition);
                            }
                            if (positions.length >= 3) {
                                // 绘制label
                                if (labelEntity) {
                                    viewer.entities.remove(labelEntity);
                                    entityCollection.splice(entityCollection.indexOf(labelEntity), 1);
                                }
                                var text = "面积：" + getArea(positions);
                                var centerPoint = getCenterOfGravityPoint(positions);
                                // 标注放高一点
                                var lnglat :any= cartographicToLnglat(
                                    Cesium.Cartographic.fromCartesian(centerPoint), viewer
                                );
                                let cartesian2 = Cesium.Cartesian3.fromDegrees(lnglat[0], lnglat[1], lnglat[2] + 20)
                                labelEntity = addLabel(viewer,cartesian2, text);
                                entityCollection.push(labelEntity);
                            }
                            break;
                    }
                    clickStatus = false;
                    viewer.scene.requestRender()
                }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

                break;
            case 2:
                positions.pop();
                positions.push(cartesian.clone()); // 鼠标左击 添加第3个点
                addPoint(viewer,cartesian);
                addPolyGon(viewer,positions);
                // 右击结束
                viewer.screenSpaceEventHandler.setInputAction(function (clickEvent:any) {
                    var clickPosition = viewer.scene.pickPosition(clickEvent.position);
                    // var clickPosition = viewer.scene.globe.pick(viewer.camera.getPickRay(clickEvent.position), viewer.scene);

                    positions.pop();
                    positions.push(clickPosition);
                    positions.push(positions[0]); // 闭合
                    addPoint(viewer,clickPosition);

                    viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
                    viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
                    viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
                }, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
                break;
            default:
                positions.pop();
                positions.push(cartesian.clone()); // 鼠标左击 添加第2个点
                addPoint(viewer,cartesian);
                break;
        }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
}解释这段代码