# VisiblityAnalysis

#### new Cesium.VisiblityAnalysis(options)
MapGIS/Analysis/VisiblityAnalysis.js 109

通视分析

Name | Type | Description
--- | --- | ---
`options` | Object | 附加参数
Name | Type | Default | Description
--- | --- | --- | ---
`scene` | Scene |  | Cesium 场景对象
`visibleColor` | Color | `new Color(0, 1, 0, 0.5)` | optional 设置可视段颜色
`unvisibleColor` | Color | `new Color(1, 0, 0, 0.5)` | optional 设置不可视段颜色
`exHeight` | Number | `0` | optional 设置视点附加高度
`fanColor` | Color | `new Color(79 / 255, 238 / 255, 215 / 255, 0.2)` | optional 环型通视分析视窗颜色
`fanGridColor` | Color | `Cesium.Color.WHITE` | optional 环型通视分析视窗网格颜色

Author:
  - 韩彦生

##### Example:

    // 1. 给定观察点与目标点进行通视分析
    var visiblity = new Cesium.VisiblityAnalysis({ scene: scene });
    scene.visualAnalysisManager.add(visiblity);
    visiblity.viewPosition = new Cesium.Cartesian3(6378138.905101178, 22.20128910645181, 16.69161471354458);
    visiblity.targetPosition = new Cesium.Cartesian3(6378158.153515804, 47.68794749465568, 34.93181937554349);

    // 2. 监听鼠标事件进行通视分析
    var visiblityAction = true;
    var visiblitying = false;
    var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    // 左键开始
    handler.setInputAction(function (movement) {
        if (visiblity !== undefined) {
            if (visiblityAction) {
                var cartesian = viewer.scene.pickPosition(movement.position);
                var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
                cartographic.height += 1.0; //避免埋入模型中
                cartesian = Cesium.Cartographic.toCartesian(cartographic);
                if (cartesian !== undefined && !visiblitying) {
                    visiblity.viewPosition = cartesian;
                } else {
                    visiblity.targetPosition = cartesian;
                    visiblityAction = false;
                }
                visiblitying = true;
            }
            console.log(visiblity.viewPosition);
        }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    //鼠标右键结束
    handler.setInputAction(function (movement) {
        if (visiblitying) {
            var cartesian = viewer.scene.pickPosition(movement.position);
            if (cartesian !== undefined) {
                visiblity.targetPosition = cartesian;
            }
            visiblityAction = false;
            visiblitying = false;
        }
    }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
    handler.setInputAction(function (movement) {
        if (visiblitying) {
            var cartesian = viewer.scene.pickPosition(movement.endPosition);
            if (cartesian) {
                visiblity.targetPosition = cartesian;
            }
        }
    }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

    // 3. 创建环形通视分析
    var drawElement = new Cesium.DrawElement(viewer);
    drawElement.startDrawingCircle({
        color: new Cesium.Color(0.2, 0.4, 0.3, 1.0),
        callback: function (result) {
            drawElement.stopDrawing();
            visiblity.lookAroundAnalysis({
                viewPosition: result.center,
                radius: result.radius,
                percentCallback: function (percent) {
                    console.log(percent);
                }
            });
        }
    });

    // 4. 移除通视分析
    scene.visualAnalysisManager.remove(visiblity);
    visiblity.destroy();

### Members

#### exHeight : Number
MapGIS/Analysis/VisiblityAnalysis.js 287

设置视点附加高度，需要在分析前设置

#### fanColor : Color
MapGIS/Analysis/VisiblityAnalysis.js 261

设置环型通视分析视窗颜色

#### fanGridColor : Color
MapGIS/Analysis/VisiblityAnalysis.js 274

设置环型通视分析视窗网格颜色

#### isVisible : Boolean
MapGIS/Analysis/VisiblityAnalysis.js 222

获取当前是否可见

#### targetPosition : Cartesian3
MapGIS/Analysis/VisiblityAnalysis.js 197

目标点

#### unvisibleColor : Color
MapGIS/Analysis/VisiblityAnalysis.js 247

设置不可视段颜色

#### unVisiblityPosition : Cartesian3
MapGIS/Analysis/VisiblityAnalysis.js 187

遮挡点

#### viewPosition : Cartesian3
MapGIS/Analysis/VisiblityAnalysis.js 159

观察点

#### visibleColor : Color
MapGIS/Analysis/VisiblityAnalysis.js 233

设置可视段颜色

#### width : Number
MapGIS/Analysis/VisiblityAnalysis.js 173

通视线的宽度

### Methods

#### getVisibilityResult(viewPosition, targetPosition) → Boolean
MapGIS/Analysis/VisiblityAnalysis.js 377

根据两点坐标判断两点之间是否可视，返回结果

Name | Type | Description
--- | --- | ---
`viewPosition` | Cartesian3 | 视点
`targetPosition` | Cartesian3 | 目标点

##### Returns:

visible 两点之间是否可视

#### lookAroundAnalysis(options)
MapGIS/Analysis/VisiblityAnalysis.js 437

环形通视分析

Name | Type | Description
--- | --- | ---
`options` | Object |
Name | Type | Default | Description
--- | --- | --- | ---
`viewPosition` | Cartesian3 |  | 视点
`radius` | Number |  | 环形通视分析半径
`verticalAngle` | Number | `60` | optional 垂直视角，默认为60°
`divideAngle` | Number | `10` | optional 等分角度，默认为10°
`percentCallback` | function |  | optional 计算进度回调