5. 分析

优质
小牛编辑
130浏览
2023-12-01

5.1. 光照分析

//是否开启光照
viewer.shadows=true/false;

//光照阴影位置和当前的时间有关
//设置当前时间可以改变阴影的位置
var JulianDate =computes("当前时间");
//当天已经过去的时间单位s
var julianSecound=hour*60*60+minute*60+secound;
viewer.clock.currentTime= new LSGlobe.JulianDate(julianDay,julianSecound);

当前时间转换为朱莉安时间
function computes(now){
    var month = now.getUTCMonth() + 1;
    var day = now.getUTCDate();
    var year = now.getUTCFullYear()
    var y = eval(year);
    var m = eval(month);
    var d = eval(day);
    var extra = 100.0*y + m - 190002.5;
    var rjd = 367.0*y;
    rjd -= Math.floor(7.0*(y+Math.floor((m+9.0)/12.0))/4.0);
    rjd += Math.floor(275.0*m/9.0);
    rjd += d;
    rjd += 1721013.5;
    rjd -= 0.5*extra/Math.abs(extra);
    rjd += 0.5;
    return rjd;
}

5.2. 可视域分析

1).初始化可视域分析
var viewshed3ding = false;//用于是否正在绘制可视域分析
var viewshed3d;//当前可视域对象
var aViewshed3d=[];//保存可视域分析的数组
//初始化可视域对象
viewshed3d= new LSGlobe.LSViewshed3D(viewer);
//将可视域分析对象加入到可是与分析数组中
aViewshed3d.push(viewshed3d);
2).绘制可视域分析
    //初始化鼠标事件
    var ViewAnalysisHandler = new LSGlobe.ScreenSpaceEventHandler(viewer.scene.canvas);
    ViewAnalysisHandler.setInputAction(function (movement) {
        var cartesian=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= whichTileset(currentClickLon,currentClickLat);
        //判断点是否在模型上函数和压平获取压平对象相同
        //可视域分析点必须在模型上
        if(CurrentTileSet.length<1){
            //如果点没有点在模型上不在向下走
            return;
        }
        if(cartesian != undefined && !viewshed3ding){
            cartesian.z+=1.5;
            //初始点的高度1.5人眼高度
            viewshed3d.viewerPosition = cartesian;
            viewer.scene.primitives.add(viewshed3d);
            //初始添加一个点
            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);

3).删除可视域分析
    for(var i=0;i<aViewshed3d.length;i++){
        try{
            viewer.scene.primitives.remove(aViewshed3d[i]);
        }catch(e){
        }
    }
    aViewshed3d=[];-
    viewshed3ding=false;

5.3. 方量分析

1).初始化方量分析
var cutfill = new LSGlobe.LSCutFill(viewer);
var nodeMesh,tileset;
var poinsTemp;//用于保存绘制的点
var oHeight;
//分析对象
var tempDataSource;
//用于存储方量分析辅助面
var promise = viewer.dataSources.add(new LSGlobe.GeoJsonDataSource("tempDataSource"));
promise.then(function(dataSource) {
    tempDataSource= dataSource;
}).otherwise(function(error){

});

2).使用绘制插件来绘制方量分析面
//注意:绘制方量分析时点必须点在模型上
viewer.geometryEditer.viewModel.setAction(EditAction.CREATE_POLYGON);
viewer.geometryEditer.viewModel.onCreatedEvent.removeAllEventListener();
viewer.geometryEditer.viewModel.onCreatedEvent.addEventListener(function (event){
    //绘制完成后对返回点集合event.positions进行变换
    poinsTemp=event.positions;
    var cartographic = LSGlobe.Cartographic.fromCartesian(poinsTemp[0]);
    var longitude=LSGlobe.Math.toDegrees(cartographic.longitude);
    var latitude=LSGlobe.Math.toDegrees(cartographic.latitude);
    tileset = whichTileset(longitude,latitude);
    if(tileset.length >0){
        setInterval(getProgress, 1000);
    }
    oHeight=((event.maxHeight*1+event.minHeight*1)/2).toFixed(2);
    var oValuePoint = ChangePolygonPosition(event.positions);
    //点集合设置为统一高度
    for (var i = 2; i < oValuePoint.length; i = i + 3) {
        oValuePoint[i] = oHeight;
    }
    //该面是辅助方量分析结果的面,最后方量分析的高度和范围是该面显示的高度和范围
    tempDataSource.entities.add({
        name: '方量分析辅助面',
        id: id,
        polygon: {
            hierarchy: LSGlobe.Cartesian3.fromDegreesArrayHeights(oValuePoint),
            material: new LSGlobe.Color(0.5, 1.0, 1.0, 0.7),
            fill: true,
            outline: true,
            outlineColor: LSGlobe.Color.YELLOW,
            perPositionHeight: true
        }
    });
});
function getProgress(){
    nodeMesh = tileset.NodeMesh;
}
3).开始分析
modelAnalysis(oHeight);
function modelAnalysis(oHeight){
    cutfill.clear();
    cutfill.completeEvent.addEventListener(progress);
    var cartographic = LSGlobe.Cartographic.fromCartesian(poinsTemp[0]);
    cutfill.vertice = nodeMesh;
    cutfill.matLocal = tileset.m_matLocal;
    LSGlobe.Matrix4.inverseTransformation(tileset.m_matLocal,cutfill.matLocalInvert);
    if(oHeight){
        cutfill.zFactor=height;
    }else{
        cutfill.zFactor = cartographic.height;
    }
    //分析的面对象
    var Mypolygon = new LSGlobe.PolygonGeometry({
        polygonHierarchy : new LSGlobe.PolygonHierarchy(poinsTemp),
        perPositionHeight : true
    });
    cutfill.polygon = Mypolygon;
    //采样间隔
    var interval = $(".v-analysis-deg input:checked").val();
    cutfill.sampleGap = interval;
    //执行分析
    cutfill.apply();
}