可视域分析
可视域分析需要额外调用接口,需要引用插件 ViewshedAnalysis.js 和 ViewshedAnalysis.css
HTML
<link href="SDK/Plugins/ViewshedAnalysis/ViewshedAnalysis.css"/>
<script src="SDK/Plugins/ViewshedAnalysis/ViewshedAnalysis.js"></script>
绘制可视域分析开始
JavaScript
//初始化鼠标事件
var ViewAnalysisHandler = new LSGlobe.ScreenSpaceEventHandler(viewer.scene.canvas);
ViewAnalysisHandler.setInputAction(function(movement) {
var cartesian = viewer.scene.pickGlobe(movement.position);
var cartographic = LSGlobe.Cartographic.fromCartesian(cartesian);
var currentClickLon = LSGlobe.Math.toDegrees(cartographic.longitude);
var currentClickLat = LSGlobe.Math.toDegrees(cartographic.latitude);
var CurrentTileSet = [tileset];
//判断点是否在模型上函数和压平获取压平对象相同
//可视域分析点必须在模型上
if (CurrentTileSet.length < 1) {
//如果点没有点在模型上不在向下走
return;
}
if (cartesian != undefined && !viewshed3ding) {
viewshed3d.viewerPosition = cartesian;
//初始添加一个点
viewshed3ding = true;
} else {
viewshed3d.setPoseByTargetPoint(cartesian);
//点击第二个点绘制结束
viewshed3ding = false;
}
},
LSGlobe.ScreenSpaceEventType.LEFT_CLICK);
ViewAnalysisHandler.setInputAction(function(movement) {
if (viewshed3daction && viewshed3ding) {
var cartesian = viewer.scene.pickGlobe(movement.endPosition);
viewshed3d.setPoseByTargetPoint(cartesian);
}
},
LSGlobe.ScreenSpaceEventType.MOUSE_MOVE);
删除可视域分析状态
JavaScript
for (var i = 0; i < aViewshed3d.length; i++) {
try {
aViewshed3d[i].destroy();
} catch(e) {}
}
aViewshed3d = [];
viewshed3ding = false;