cesium 实时网格动态生成 与 3D点云坐标框架生成

var PointCloud2Grid=(function () {

    /**
     * 根据已有点云创建网格阵列
     * @param airdatas 大气监测数据点的集合
     */
    function createAirGrids(airdatas,gridwidth) {
        if (!airdatas || !airdatas.length || airdatas.length < 1) {
            return;
        }
        var preGrids=[];
        var preGrid=point2GridWGS84(null,airdatas[0].lon,airdatas[0].lat,gridwidth,gridwidth);
        preGrids.push(preGrid);
        for (let i = 1; i < airdatas.length; i++) {
            let airdata=airdatas[i];
            preGrid=point2GridWGS84(preGrid,airdata.lon,airdata.lat,gridwidth,gridwidth);
            if (preGrid) {
                var intersectgrid=getInertsectGridWGS84(preGrids,preGrid,gridwidth,gridwidth);//重叠的网格
                if (intersectgrid) {
                    preGrid=intersectgrid;
                    if (preGrids.length === 1) {//第一个创建的网格单元与自己重叠
                       let entity = PointCloud2Grid.createairGridEntity(preGrid,airdata,airEntityNameCommon.airGridEntityNames.airgrid);
                        setgridLabel(entity,airdata,UiParaManager.getCurParaName());
                    }
                } else {
                    preGrids.push(preGrid);
                    let entity =createairGridEntity(preGrid,airdata,airEntityNameCommon.airGridEntityNames.airgrid);
                    setgridLabel(entity,airdata,UiParaManager.getCurParaName());
                }
            }
        }
    }

    /**
     * 批量修改网格的标签
     * @param curAirParaName 当前大气指标(温度,so2等)
     */
    function setGridsLabels(curAirParaName) {
        for (var i=0;i<window.viewer.entities.values.length;i++)
        {
            var entity=window.viewer.entities.values[i];
            if (entity.name===airEntityNameCommon.airGridEntityNames.airgrid){
                setgridLabel(entity,entity.airdatainfo,curAirParaName);
            }
        }
    }

    /**
     * 设置网格单元的标签
     * @param grid
     * @param airdata
     * @param curAirParaName
     */
    function setgridLabel(entity,airdata,curAirParaName) {
        entity.label={
            /*text : parseFloat(airdata[curAirParaName]).toFixed(2),
            font:'32px',
            fillColor:Cesium.Color.BLACK,
            verticalOrigin:Cesium.VerticalOrigin.TOP,
            scale:0.5*/

            /*showBackground:false,
            backgroundColor:Cesium.Color.fromCssColorString('#000'),
            scale:0.4, 
            font:'normal 32px MicroSoft YaHei',
            fillColor:Cesium.Color.BLACK,
            text:parseFloat(airdata[curAirParaName]).toFixed(2).toString()*/

            text : parseFloat(airdata[curAirParaName]).toFixed(2),
            color : Cesium.Color.fromCssColorString('#fff'),
            font:'normal 32px MicroSoft YaHei',
            showBackground : true,
            scale : 0.4,
            /*horizontalOrigin : Cesium.HorizontalOrigin.LEFT_CLICK,*/
            /*verticalOrigin : Cesium.VerticalOrigin.BOTTOM,*/
            distanceDisplayCondition : new Cesium.DistanceDisplayCondition(0, 500),
            /*disableDepthTestDistance : 1000*/

            /*Represents a scalar value's lower and upper bound at a near distance and far distance in eye space.
            Name	Type	Default	Description
            near	Number	0.0	optional The lower bound of the camera range.
                nearValue	Number	0.0	optional The value at the lower bound of the camera range.
            far	Number	1.0	optional The upper bound of the camera range.
                farValue	Number	0.0	optional The value at the upper bound of the camera range.*/
            scaleByDistance : new Cesium.NearFarScalar(100, 2, 500, 0.0),
        }
    }

    /**
     * 在三维上创建网格
     * @param grid 网格边界
     * @param airdata 大气监测数据点
     * @param entityName 实体名称
     * @returns {*}
     */
    function createairGridEntity(grid,airdata,entityName) {
        var entity = viewer.entities.add({
            name:entityName,
            position : window.Cesium.Cartesian3.fromDegrees((grid.minX+grid.maxX)/2,(grid.minY+grid.maxY)/2,0.5),
            rectangle : {
                coordinates : Cesium.Rectangle.fromDegrees(grid.minX, grid.minY, grid.maxX, grid.maxY),
                extrudedHeight : 0,
                outline : true,
                outlineColor : Cesium.Color.BLUE,
                outlineWidth : 10,
                material : window.Cesium.Color.fromRandom({alpha : 0.5})
            },
            coord:{
                minX:grid.minX,
                minY:grid.minY,
                maxX:grid.maxX,
                maxY:grid.maxY,

                minXplane:grid.maxXutm,
                minYplane:grid.minYutm,
                maxXplane:grid.maxXutm,
                maxYplane:grid.maxYutm
            },
            airdatainfo:airdata
        });
        return entity;
    }

    /**
     * 由前一个网格和当前点以及网格大小 生成一个新的网格
     * @param preGrid 前一个网格
     * @param curPoint 当前点
     * @param gridWidth 网格宽(米)
     * @param gridHeigth 网格高(米)
     * @returns {*|{minXutm, minY, minX, maxY, maxX, maxXutm, minYutm, maxYutm}}
     */
    function point2Grid(preGrid, curPointX,curPointY, gridWidth, gridHeigth) {
        if (!gridWidth||!gridHeigth) {
            return null;
        }
        var pointX=parseFloat(curPointX);
        var pointY=parseFloat(curPointY);        
        if (isNaN(pointX) || isNaN(pointY) || !curPointX || !curPointY) {
            return null;
        }
        var pointUtm=cesiumCoordUtil.wgs84toUtm(pointX,pointY);
        var pointXutm=pointUtm.x;
        var pointYutm=pointUtm.y;
        var centLon=cesiumCoordUtil.getCentral_MeridianFromDaihaoGauss6(cesiumCoordUtil.getUtmDaihao(curPointX));
        if (!preGrid) {
            var grid=cesiumCoordUtil.createSquare2(pointX,pointY,null,gridWidth,gridHeigth);
            return grid;
        }
        if (pointXutm >= preGrid.minXutm && pointXutm <= preGrid.maxXutm && pointYutm >= preGrid.minYutm && pointYutm <= preGrid.maxYutm) {
            return preGrid;
        }
        else if (pointXutm > preGrid.maxXutm && pointYutm > preGrid.maxYutm) {//第一象限内,东北角
            if (pointXutm < (preGrid.maxXutm + gridWidth) && pointYutm < (preGrid.maxYutm + gridHeigth)) {
                let grid=cesiumCoordUtil.createSquare2With2Points(preGrid.maxXutm,preGrid.maxYutm,preGrid.maxXutm+gridWidth,preGrid.maxYutm+gridHeigth,gridWidth,gridHeigth,centLon);
                return grid;
            }else{
                let xGrids=Math.ceil((pointXutm-preGrid.maxXutm)/gridWidth);
                let yGrids=Math.ceil((pointYutm-preGrid.maxYutm)/gridHeigth);
                let minx=preGrid.maxXutm+gridWidth*(xGrids-1);
                let miny=preGrid.maxYutm+gridHeigth*(yGrids-1);
                let maxx=minx+gridWidth;
                let maxy=miny+gridHeigth;
                var grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
                return grid;
            }
        }else if (pointXutm > preGrid.minXutm && pointXutm < preGrid.maxXutm && pointYutm > preGrid.maxYutm) {//第二象限内,正北
            let yGrids=Math.ceil((pointYutm-preGrid.maxYutm)/gridHeigth);
            let minx=preGrid.minXutm;
            let miny=preGrid.maxYutm+(yGrids-1)*gridHeigth;
            let maxx=preGrid.maxXutm;
            let maxy=miny+gridHeigth;
            var grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
            return grid;
        }else if (pointXutm < preGrid.minXutm && pointYutm > preGrid.maxYutm) {//第三象限内,西北角
            let xGrids=Math.ceil((preGrid.minXutm-pointXutm)/gridWidth);
            let yGrids=Math.ceil((pointYutm-preGrid.maxYutm)/gridHeigth);
            let minx=preGrid.minXutm-gridWidth*xGrids;
            let miny=preGrid.maxYutm+gridHeigth*(yGrids-1);
            let maxx=minx+gridWidth;
            let maxy=miny+gridHeigth;
            var grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
            return grid;
        }else if (pointXutm < preGrid.minXutm && pointYutm > preGrid.minYutm && pointYutm < preGrid.maxYutm) {//第四象限内,正西
            let xGrids=Math.ceil((preGrid.minXutm-pointXutm)/gridWidth);
            let minx=preGrid.minXutm-gridWidth*xGrids;
            let miny=preGrid.minYutm;
            let maxx=minx+gridWidth;
            let maxy=miny+gridHeigth;
            var grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
            return grid;
        }else if (pointXutm < preGrid.minXutm && pointYutm < preGrid.minYutm) {//第五象限内,西南角
            let xGrids=Math.ceil((preGrid.minXutm-pointXutm)/gridWidth);
            let yGrids=Math.ceil((preGrid.minYutm-pointYutm)/gridHeigth);
            let minx=preGrid.minXutm-gridWidth*xGrids;
            let miny=preGrid.minYutm-gridHeigth*yGrids;
            let maxx=minx+gridWidth;
            let maxy=miny+gridHeigth;
            var grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
            return grid;
        }else if (pointXutm>preGrid.minXutm&&pointXutm<preGrid.maxXutm&&pointYutm<=preGrid.minYutm){//第六象限内,正南
            let yGrids=Math.ceil((preGrid.minYutm-pointYutm)/gridHeigth);
            let minx=preGrid.minXutm;
            let miny=preGrid.minYutm-gridHeigth*yGrids;
            let maxx=minx+gridWidth;
            let maxy=miny+gridHeigth;
            let grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
            return grid;
        } else if (pointXutm > preGrid.maxXutm && pointYutm < preGrid.minYutm) {//第七象限内,东南角
            let xGrids=Math.ceil((pointXutm-preGrid.maxXutm)/gridWidth);
            let yGrids=Math.ceil((preGrid.minYutm-pointYutm)/gridHeigth);
            let minx=preGrid.maxXutm+gridWidth*(xGrids-1);
            let miny=preGrid.minYutm-gridHeigth*yGrids;
            let maxx=minx+gridWidth;
            let maxy=miny+gridHeigth;
            var grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
            return grid;
        }else if (pointXutm > preGrid.maxXutm && pointYutm > preGrid.minYutm && pointYutm < preGrid.maxYutm) {//第八象限内,正东
            let xGrids=Math.ceil((pointXutm-preGrid.maxXutm)/gridWidth);
            let minx=preGrid.maxXutm+gridWidth*(xGrids-1);
            let miny=preGrid.minYutm
            let maxx=minx+gridWidth;
            let maxy=miny+gridHeigth;
            var grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
            return grid;
        }
        
    }


    /**
     * 由前一个网格和当前点以及网格大小 生成一个新的网格
     * @param preGrid 前一个网格
     * @param curPoint 当前点
     * @param gridWidth 网格宽(米)
     * @param gridHeigth 网格高(米)
     * @returns {*|{minX, minY, minX, maxY, maxX, maxX, minY, maxY}}
     */
    function point2GridWGS84(preGrid, curPointX,curPointY, gridWidth, gridHeigth) {
        if (!gridWidth||!gridHeigth) {
            return null;
        }
        var pointX=parseFloat(curPointX);
        var pointY=parseFloat(curPointY);
        if (isNaN(pointX) || isNaN(pointY) || !curPointX || !curPointY) {
            return null;
        }
        var centLon=cesiumCoordUtil.getCentral_MeridianFromDaihaoGauss6(cesiumCoordUtil.getUtmDaihao(curPointX));
        if (!preGrid) {
            var grid=cesiumCoordUtil.createSquare2(pointX,pointY,null,gridWidth,gridHeigth);
            return grid;
        }
        if (curPointX >= preGrid.minX && curPointX <= preGrid.maxX && curPointY >= preGrid.minY && curPointY <= preGrid.maxY) {
            return preGrid;
        }
        else if (curPointX > preGrid.maxX && curPointY > preGrid.maxY) {//第一象限内,东北角
            if (curPointX < (preGrid.maxX + gridWidth) && curPointY < (preGrid.maxY + gridHeigth)) {
                let grid=cesiumCoordUtil.createSquare2With2Points(preGrid.maxX,preGrid.maxY,preGrid.maxX+gridWidth,preGrid.maxY+gridHeigth,gridWidth,gridHeigth,centLon);
                return grid;
            }else{
                let xGrids=Math.ceil((curPointX-preGrid.maxX)/gridWidth);
                let yGrids=Math.ceil((curPointY-preGrid.maxY)/gridHeigth);
                let minx=preGrid.maxX+gridWidth*(xGrids-1);
                let miny=preGrid.maxY+gridHeigth*(yGrids-1);
                let maxx=minx+gridWidth;
                let maxy=miny+gridHeigth;
                var grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
                return grid;
            }
        }else if (curPointX > preGrid.minX && curPointX < preGrid.maxX && curPointY > preGrid.maxY) {//第二象限内,正北
            let yGrids=Math.ceil((curPointY-preGrid.maxY)/gridHeigth);
            let minx=preGrid.minX;
            let miny=preGrid.maxY+(yGrids-1)*gridHeigth;
            let maxx=preGrid.maxX;
            let maxy=miny+gridHeigth;
            var grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
            return grid;
        }else if (curPointX < preGrid.minX && curPointY > preGrid.maxY) {//第三象限内,西北角
            let xGrids=Math.ceil((preGrid.minX-curPointX)/gridWidth);
            let yGrids=Math.ceil((curPointY-preGrid.maxY)/gridHeigth);
            let minx=preGrid.minX-gridWidth*xGrids;
            let miny=preGrid.maxY+gridHeigth*(yGrids-1);
            let maxx=minx+gridWidth;
            let maxy=miny+gridHeigth;
            var grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
            return grid;
        }else if (curPointX < preGrid.minX && curPointY > preGrid.minY && curPointY < preGrid.maxY) {//第四象限内,正西
            let xGrids=Math.ceil((preGrid.minX-curPointX)/gridWidth);
            let minx=preGrid.minX-gridWidth*xGrids;
            let miny=preGrid.minY;
            let maxx=minx+gridWidth;
            let maxy=miny+gridHeigth;
            var grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
            return grid;
        }else if (curPointX < preGrid.minX && curPointY < preGrid.minY) {//第五象限内,西南角
            let xGrids=Math.ceil((preGrid.minX-curPointX)/gridWidth);
            let yGrids=Math.ceil((preGrid.minY-curPointY)/gridHeigth);
            let minx=preGrid.minX-gridWidth*xGrids;
            let miny=preGrid.minY-gridHeigth*yGrids;
            let maxx=minx+gridWidth;
            let maxy=miny+gridHeigth;
            var grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
            return grid;
        }else if (curPointX>preGrid.minX&&curPointX<preGrid.maxX&&curPointY<=preGrid.minY){//第六象限内,正南
            let yGrids=Math.ceil((preGrid.minY-curPointY)/gridHeigth);
            let minx=preGrid.minX;
            let miny=preGrid.minY-gridHeigth*yGrids;
            let maxx=minx+gridWidth;
            let maxy=miny+gridHeigth;
            let grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
            return grid;
        } else if (curPointX > preGrid.maxX && curPointY < preGrid.minY) {//第七象限内,东南角
            let xGrids=Math.ceil((curPointX-preGrid.maxX)/gridWidth);
            let yGrids=Math.ceil((preGrid.minY-curPointY)/gridHeigth);
            let minx=preGrid.maxX+gridWidth*(xGrids-1);
            let miny=preGrid.minY-gridHeigth*yGrids;
            let maxx=minx+gridWidth;
            let maxy=miny+gridHeigth;
            var grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
            return grid;
        }else if (curPointX > preGrid.maxX && curPointY > preGrid.minY && curPointY < preGrid.maxY) {//第八象限内,正东
            let xGrids=Math.ceil((curPointX-preGrid.maxX)/gridWidth);
            let minx=preGrid.maxX+gridWidth*(xGrids-1);
            let miny=preGrid.minY
            let maxx=minx+gridWidth;
            let maxy=miny+gridHeigth;
            var grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
            return grid;
        }

    }

    /**
     * 由前一个网格和当前点以及网格大小 生成一个新的网格 无数据区域插值生成网格
     * @param preGrid 前一个网格
     * @param curPoint 当前点
     * @param gridWidth 网格宽(米)
     * @param gridHeigth 网格高(米)
     * @returns {*|{minXutm, minY, minX, maxY, maxX, maxXutm, minYutm, maxYutm}}
     */
    function point2GridWithInterpolation(preGrid, curPointX,curPointY, gridWidth, gridHeigth) {
            if (!gridWidth||!gridHeigth) {
                return null;
            }
            var pointX=parseFloat(curPointX);
            var pointY=parseFloat(curPointY);
            if (isNaN(pointX) || isNaN(pointY) || !curPointX || !curPointY) {
                return null;
            }
            var pointUtm=cesiumCoordUtil.wgs84toUtm(pointX,pointY);
            var pointXutm=pointUtm.x;
            var pointYutm=pointUtm.y;
            var centLon=cesiumCoordUtil.getCentral_MeridianFromDaihaoGauss6(cesiumCoordUtil.getUtmDaihao(curPointX));
            if (!preGrid) {
                var grid=cesiumCoordUtil.createSquare2(pointX,pointY,null,gridWidth,gridHeigth);
                return grid;
            }
            if (pointXutm >= preGrid.minXutm && pointXutm <= preGrid.maxXutm && pointYutm >= preGrid.minYutm && pointYutm <= preGrid.maxYutm) {
                return preGrid;
            }
            else if (pointXutm >= preGrid.maxXutm && pointYutm >= preGrid.maxYutm) {//第一象限内,东北角
                if (pointXutm < (preGrid.maxXutm + gridWidth) && pointYutm < (preGrid.maxYutm + gridHeigth)) {
                    let grid=cesiumCoordUtil.createSquare2With2Points(preGrid.maxXutm,preGrid.maxYutm,preGrid.maxXutm+gridWidth,preGrid.maxYutm+gridHeigth,gridWidth,gridHeigth,centLon);
                    return grid;
                }else{
                    let xGrids=Math.ceil((pointXutm-preGrid.maxXutm)/gridWidth);
                    let yGrids=Math.ceil((pointYutm-preGrid.maxYutm)/gridHeigth);
                    if (xGrids > 1) {
                        let minx=preGrid.maxXutm+gridWidth*xGrids;
                        let miny=preGrid.maxYutm+gridHeigth*yGrids;
                        let maxx=minx+gridWidth;
                        let maxy=miny+gridHeigth;
                        var grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
                        return grid;
                    }
                }
            }else if (pointXutm >= preGrid.minXutm && pointXutm <= preGrid.maxXutm && pointYutm >= preGrid.maxYutm) {//第二象限内,正北
                let yGrids=Math.ceil((pointYutm-preGrid.maxYutm)/gridHeigth);
                let minx=preGrid.minXutm;
                let miny=preGrid.maxYutm;
                let maxx=preGrid.maxXutm;
                let maxy=miny+yGrids*gridHeigth;
                var grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
                return grid;
            }else if (pointXutm <= preGrid.minXutm && pointYutm >= preGrid.maxYutm) {//第三象限内,西北角
                let xGrids=Math.ceil((preGrid.minXutm-pointXutm)/gridWidth);
                let yGrids=Math.ceil((pointYutm-preGrid.maxYutm)/gridHeigth);
                let minx=preGrid.minXutm-gridWidth*xGrids;
                let miny=preGrid.maxYutm+gridHeigth*yGrids;
                let maxx=minx+gridWidth;
                let maxy=miny+gridHeigth;
                var grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
                return grid;
            }else if (pointXutm <= preGrid.minXutm && pointYutm >= preGrid.minYutm && pointYutm <= preGrid.maxYutm) {//第四象限内,正西
                let xGrids=Math.ceil((preGrid.minXutm-pointXutm)/gridWidth);
                let minx=preGrid.minXutm-gridWidth*xGrids;
                let miny=preGrid.minYutm;
                let maxx=minx+gridWidth;
                let maxy=miny+gridHeigth;
                var grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
                return grid;
            }else if (pointXutm <= preGrid.minXutm && pointYutm <= preGrid.minYutm) {//第五象限内,西南角
                let xGrids=Math.ceil((preGrid.minXutm-pointXutm)/gridWidth);
                let yGrids=Math.ceil((preGrid.minYutm-pointYutm)/gridHeigth);
                let minx=preGrid.minXutm-gridWidth*xGrids;
                let miny=preGrid.minYutm-gridHeigth*yGrids;
                let maxx=minx+gridWidth;
                let maxy=miny+gridHeigth;
                var grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
                return grid;
            }else if (pointXutm>=preGrid.minXutm&&pointXutm<=preGrid.maxXutm&&pointYutm<=preGrid.minYutm){//第六象限内,正南
                let yGrids=Math.ceil((preGrid.minYutm-pointYutm)/gridHeigth);
                let minx=preGrid.minXutm;
                let miny=preGrid.minYutm-gridHeigth*yGrids;
                let maxx=minx+gridWidth;
                let maxy=miny+gridHeigth;
                let grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
                return grid;
            } else if (pointXutm >= preGrid.maxXutm && pointYutm <= preGrid.minYutm) {//第七象限内,东南角
                let xGrids=Math.ceil((pointXutm-preGrid.maxXutm)/gridWidth);
                let yGrids=Math.ceil((preGrid.minYutm-pointYutm)/gridHeigth);
                let minx=preGrid.maxXutm+gridWidth*xGrids;
                let miny=preGrid.minYutm-gridHeigth*yGrids;
                let maxx=minx+gridWidth;
                let maxy=miny+gridHeigth;
                var grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
                return grid;
            }else if (pointXutm >= preGrid.maxXutm && pointYutm >= preGrid.minYutm && pointYutm <= preGrid.maxYutm) {//第八象限内,正东
                let xGrids=Math.ceil((pointXutm-preGrid.maxXutm)/gridWidth);
                let minx=preGrid.maxXutm+gridWidth*xGrids;
                let miny=preGrid.minYutm
                let maxx=minx+gridWidth;
                let maxy=miny+gridHeigth;
                var grid= cesiumCoordUtil.createSquare2With2Points(minx,miny,maxx,maxy,gridWidth,gridHeigth,centLon);
                return grid;
            }

        }

    /**
     * 判断当前生成的网格单元是否与已有的网格单元重叠
     * @param grids 已有的网格单元集合
     * @param curgrid 刚创建的网格单元
     */
    function getInertsectGrid(grids, curgrid,gridWidth,gridHeight) {
        var toleranceX=0;
        var toleranceY=0;
        for (let i = 0; i < grids.length; i++) {
            let pregrid=grids[i];
            if (curgrid.minXutm>(pregrid.minXutm+toleranceX)&&curgrid.minXutm<(pregrid.maxXutm-toleranceX)&&curgrid.minYutm>(pregrid.minYutm+toleranceY)&&curgrid.minYutm<(pregrid.maxYutm-toleranceY)){
                return pregrid;
            }
            if (curgrid.maxXutm>(pregrid.minXutm+toleranceX)&&curgrid.maxXutm<(pregrid.maxXutm-toleranceX)&&curgrid.maxYutm>(pregrid.minYutm+toleranceY)&&curgrid.maxYutm<(pregrid.maxYutm-toleranceY)){
                return pregrid;
            }
            if (curgrid.minXutm>(pregrid.minXutm+toleranceX)&&curgrid.minXutm<(pregrid.maxXutm-toleranceX)&&curgrid.maxYutm>(pregrid.minYutm+toleranceY)&&curgrid.maxYutm<(pregrid.maxYutm-toleranceY)){
                return pregrid;
            }
            if (curgrid.maxXutm>(pregrid.minXutm+toleranceX)&&curgrid.maxXutm<(pregrid.maxXutm-toleranceX)&&curgrid.minYutm>(pregrid.minYutm+toleranceY)&&curgrid.minYutm<(pregrid.maxYutm-toleranceY)){
                return pregrid;
            }
            if(curgrid.minXutm==pregrid.minXutm&&curgrid.minYutm==pregrid.minYutm&&curgrid.maxXutm==pregrid.maxXutm&&curgrid.maxYutm==pregrid.maxYutm){
                return pregrid;
            }
        }
        return null;
    }

    /**
     * 判断当前生成的网格单元是否与已有的网格单元重叠
     * @param grids 已有的网格单元集合
     * @param curgrid 刚创建的网格单元
     */
    function getInertsectGridWGS84(grids, curgrid,gridWidth,gridHeight) {
        var toleranceX=0;
        var toleranceY=0;
        for (let i = 0; i < grids.length; i++) {
            let pregrid=grids[i];
            if (curgrid.minX>(pregrid.minX+toleranceX)&&curgrid.minX<(pregrid.maxX-toleranceX)&&curgrid.minY>(pregrid.minY+toleranceY)&&curgrid.minY<(pregrid.maxY-toleranceY)){
                return pregrid;
            }
            if (curgrid.maxX>(pregrid.minX+toleranceX)&&curgrid.maxX<(pregrid.maxX-toleranceX)&&curgrid.maxY>(pregrid.minY+toleranceY)&&curgrid.maxY<(pregrid.maxY-toleranceY)){
                return pregrid;
            }
            if (curgrid.minX>(pregrid.minX+toleranceX)&&curgrid.minX<(pregrid.maxX-toleranceX)&&curgrid.maxY>(pregrid.minY+toleranceY)&&curgrid.maxY<(pregrid.maxY-toleranceY)){
                return pregrid;
            }
            if (curgrid.maxX>(pregrid.minX+toleranceX)&&curgrid.maxX<(pregrid.maxX-toleranceX)&&curgrid.minY>(pregrid.minY+toleranceY)&&curgrid.minY<(pregrid.maxY-toleranceY)){
                return pregrid;
            }
            if(curgrid.minX==pregrid.minX&&curgrid.minY==pregrid.minY&&curgrid.maxX==pregrid.maxX&&curgrid.maxY==pregrid.maxY){
                return pregrid;
            }
        }
        return null;
    }


    return {
        //point2Grid:point2Grid,
        createAirGrids:createAirGrids,
        //point2GridWithInterpolation:point2GridWithInterpolation,
        createairGridEntity:createairGridEntity,
        //getInertsectGrid:getInertsectGrid,
        setgridLabel:setgridLabel,
        setGridsLabels:setGridsLabels,
        point2GridWGS84:point2GridWGS84,
        getInertsectGridWGS84:getInertsectGridWGS84
    }
})()

  

var livedata=(function () {

    var interval=null;
    var interval3Dcloud=null;

    /**
     * 网格模拟 实时数据模拟
     */
    function addairlivedata() {
        clearinterval()
        var preGrids=[];
        var curEntity;
        var preGrid;
        var preairdatas=cesiumdrawutil.getairdatas();
        var intervalairdatagrid = setInterval(function () {
            airdata.getAirdataLatestOne(function (airdataLatestone) {
                var airValue = parseFloat(airdataLatestone[UiParaManager.getCurParaName()]);//大气监测数据指标值
                var lon=airdataLatestone[airdata.AirData.CONST_AIRPARA_NAME_LABEL_MAPPING.lon.name];//实时数据经度
                if (preGrids.length === 0) {//第一条加载的数据
                    preGrid=PointCloud2Grid.point2GridWGS84(null,airdataLatestone.lon,airdataLatestone.lat,airdata.gridWidthjiaodu,airdata.gridWidthjiaodu);
                    if (preGrid) {
                        preGrids.push(preGrid);//添加第一条数据
                    }
                }else {//第二条数据及之后的数据
                    if (preGrid) {
                        preGrid=PointCloud2Grid.point2GridWGS84(preGrid,airdataLatestone.lon,airdataLatestone.lat,airdata.gridWidthjiaodu,airdata.gridWidthjiaodu);
                    }
                }
                if (preGrid) {//新建网格
                    var intersectgrid=PointCloud2Grid.getInertsectGridWGS84(preGrids,preGrid,airdata.gridWidthjiaodu,airdata.gridWidthjiaodu);//重叠的网格
                    if (intersectgrid) {//新建的网格与之前创建并加载的网格重叠
                        preGrid=intersectgrid;
                        if (preGrids.length === 1) {//第一个创建的网格单元与自己重叠,则创建第一个网格并加载到球上
                            curEntity = PointCloud2Grid.createairGridEntity(preGrid,airdataLatestone,airEntityNameCommon.airGridEntityNames.airgrid);
                        }
                    } else {//新建的网格与之前创建并加载的网格不重叠,则创建新的网格并加载到球上
                        preGrids.push(preGrid);
                        curEntity = PointCloud2Grid.createairGridEntity(preGrid,airdataLatestone,airEntityNameCommon.airGridEntityNames.airgrid);
                    }
                    if (curEntity) {
                        PointCloud2Grid.setgridLabel(curEntity,curEntity.airdatainfo,UiParaManager.getCurParaName());
                    }
                }
                if (curEntity) {
                    preairdatas.push(curEntity.airdatainfo);
                }
                var entity = viewer.entities.removeById('airlivebill01');
                if (preGrids.length === 1) {//加载第一个网格后在球上定位
                    if (curEntity) {
                        cesiumLocateUtil.dingweiByPoint(airdataLatestone.lon,airdataLatestone.lat,100);
                    }
                }
                addBillBordAirLive(airdataLatestone.lon,airdataLatestone.lat,airdataLatestone.alt+0.2);//移动模型
                airColorBar.resetperdatacolor(curEntity,UiParaManager.getCurParaName());//设置网格颜色

            })

        }, 1000);
        interval=intervalairdatagrid;
        return intervalairdatagrid;
    }


    /**
     * 3D点云模拟 实时数据模拟
     */
    function addairlivedata3Dcloud() {
        clearinterval();
        var curEntity;
        var preairdatas=cesiumdrawutil.getairdatas();//获取已经加载的大气监测数据
        var intervalairdata3Dcloud = setInterval(function () {
            airdata.getAirdataLatestOne(function (airdataLatestone) {
                if (!airdata.alt || isNaN(airdata.alt) || airdata.alt < 1) {
                    airdata.alt=Math.random()*20;
                }
                //加载数据
                curEntity = cesiumdrawutil.createair3dcloudpoint(airdataLatestone.lon, airdataLatestone.lat,airdataLatestone.alt,10,airdataLatestone,airEntityNameCommon.air3dEntityNames.aircloud_point);
                if (curEntity != null) {
                    preairdatas.push(airdataLatestone);
                    addBillBordAirLive(airdataLatestone.lon,airdataLatestone.lat,airdataLatestone.alt+0.2);//移动模型
                    airColorBar.resetperdatacolor(curEntity,UiParaManager.getCurParaName());//设置网格颜色
                    cesiumdrawutil.draw3Dfream(preairdatas);//绘制坐标系
                }
                var entity = viewer.entities.removeById('airlivebill01');
                if (preairdatas.length === 1) {//加载第一个网格后在球上定位
                    if (curEntity) {
                        cesiumLocateUtil.dingweiByPoint(airdataLatestone.lon,airdataLatestone.lat,100);
                    }
                }

            })

        }, 1000);
        interval3Dcloud=intervalairdata3Dcloud;
        return intervalairdata3Dcloud;
    }


    /**
     * 动态添加网格,模拟无人机飞行
     * @param lon
     * @param lat
     * @param alt
     */
    function addBillBordAirLive(lon,lat,alt) {
        var entity = viewer.entities.add({
            name:'airlivebill',
            id:'airlivebill01',
            position : Cesium.Cartesian3.fromDegrees(lon,lat,alt),
            billboard :{
                image : './images/user.png',
                sizeInMeters : true,
                color : Cesium.Color.YELLOW
            }
        });
        var billboard = entity.billboard;
        billboard.scale =0.02;
    }

    /**
     * 停止定时器
     */
    function clearinterval() {
         if (interval != null) {
             clearInterval(interval);
             interval=null;
             clearModel();
         }
         if (interval3Dcloud != null) {
             clearInterval(interval3Dcloud);
             interval3Dcloud=null;
         }
     }

    /**
     * 清除模型
     */
    function clearModel() {
         viewer.entities.removeById('airlivebill01');
     }
    
    return {
        addairlivedata:addairlivedata,
        clearinterval:clearinterval,
        addairlivedata3Dcloud:addairlivedata3Dcloud
    }
})()

  

var cesiumdrawutil=(function () {

    //////////////////////////////////////////////////////大气监测数据3D点云显示  开始/////////////////////////////////
    function createair3dcloud(taskid) {
        airdata.getairdatas(taskid,function (airdatas) {
            air3dcloud(airdatas);
            //airColorBar.resetairdataColor(UiParaManager.getCurParaName());
            dingweibyairdatas(airdatas);
            /*var minmaxCurAirDatas=airColorBar.getairdataparaminmax(UiParaManager.getCurParaName());
            airColorBar.resetparaBar(minmaxCurAirDatas.min,minmaxCurAirDatas.max);
            $("#inputairparamin").val(minmaxCurAirDatas.min);
            $("#inputairparamax").val(minmaxCurAirDatas.max);
            airColorBar.resetairdataColor(UiParaManager.getCurParaName());//重新设置数据渲染颜色
            PointCloud2Grid.setGridsLabels(UiParaManager.getCurParaName());//重新设置网格标签*/
        })

    }


    function air3dcloud(airdatas) {
        if (!airdatas || !airdatas.length || airdatas.length < 1) {
            return;
        }
        for (let i = 0; i < airdatas.length; i++) {
            let airdata=airdatas[i];
            if (!airdata.alt || isNaN(airdata.alt) || airdata.alt < 1) {
                airdata.alt=Math.random()*20;
            }
            createair3dcloudpoint(airdata.lon, airdata.lat,airdata.alt,10,airdata,airEntityNameCommon.air3dEntityNames.aircloud_point);
        }
        var minmaxCurAirDatas=airColorBar.getairdataparaminmax(UiParaManager.getCurParaName());
        airColorBar.resetparaBar(minmaxCurAirDatas.min,minmaxCurAirDatas.max);
        $("#inputairparamin").val(minmaxCurAirDatas.min);
        $("#inputairparamax").val(minmaxCurAirDatas.max);
        airColorBar.resetairdataColor(UiParaManager.getCurParaName());//重新设置数据渲染颜色
        PointCloud2Grid.setGridsLabels(UiParaManager.getCurParaName());//重新设置网格标签
        draw3Dfream(airdatas);
    }

    //获取最小经纬度高程,最大经纬度高程
    function getminXminYminHmaxXmaxYmaxH(airdatas) {
        var minlon=parseFloat(airdatas[0].lon);
        var minlat=parseFloat(airdatas[0].lat);
        var maxlon=parseFloat(airdatas[0].lon);
        var maxlat=parseFloat(airdatas[0].lat);
        var minheight=parseFloat(airdatas[0].alt);
        var maxheight=parseFloat(airdatas[0].alt);
        for (let i = 0; i < airdatas.length; i++) {

            let airdata=airdatas[i];
            let airlon,
                airlat,
                airalt;
            if (airdata.lon) {
                airlon=parseFloat(airdata.lon);
                if (!minlon||airlon<minlon){
                    minlon=airlon;
                }
                if (!maxlon || airlon > maxlon) {
                    maxlon=airlon;
                }
            }
            if (airdata.lat) {
                airlat=parseFloat(airdata.lat);
                if (!minlat || airlat < minlat) {
                    minlat=airlat;
                }
                if (!maxlat || airlat > maxlat) {
                    maxlat=airlat;
                }
            }
            if (airdata.alt) {
                airalt=parseFloat(airdata.alt);
                if (!minheight || airalt < minheight) {
                    minheight=airalt;
                }
                if (!maxheight || airalt > maxheight) {
                    maxheight=airalt;
                }
            }
        }
        return {
            minX:minlon,
            minY:minlat,
            minH:minheight,
            maxX:maxlon,
            maxY:maxlat,
            maxH:maxheight
        }
    }


    /**
     * 创建3D点云的单个点
     * @param lon
     * @param lat
     * @param alt
     * @param pointSize
     * @param airdatainfo
     * @param entityName
     */
    function createair3dcloudpoint(lon,lat,alt,pointSize,airdatainfo,entityName) {
        if (!pointSize) {
            pointSize=20;
        }
        var entity = viewer.entities.add({
            name:entityName,
            position : Cesium.Cartesian3.fromDegrees(lon, lat, alt),
            point : {
                pixelSize : pointSize
            },
            airdatainfo:airdatainfo
        });
        return entity;
    }


    function addWall(x1, y1, z1, x2, y2, z2,maxheight1,maxheight2,entityName) {
        viewer.entities.add({
            name : entityName,
            wall : {
                positions : Cesium.Cartesian3.fromDegreesArrayHeights([x1, y1, z1, x2, y2, z2]),
                minimumHeights : [maxheight1, maxheight2],
                material :Cesium.Color.DIMGREY.withAlpha(0.8)
            }
        });
    }

    function addwalllabel(lon,lat,alt,text,entityName) {
        var entity = viewer.entities.add({
            name:entityName,
            position : Cesium.Cartesian3.fromDegrees(lon, lat,alt),
            label : {
                text : text,
                //pixelOffset : new Cesium.Cartesian2(0.0, -image.height),
                pixelOffset : new window.Cesium.Cartesian2(0, -3),
                font : '11px italic arial'
            }
        });
        entity.label.scale = 1.0;
        entity.label.showBackground = true;
    }

    function addrectangle(minX,minY,maxX,maxY,name) {
        var entity = viewer.entities.add({
            name:name,
            rectangle : {
                //coordinates : Cesium.Rectangle.fromDegrees(116.4762700, 39.9942863, 116.4764700, 39.9944863),
                coordinates : Cesium.Rectangle.fromDegrees(minX, minY, maxX, maxY),
                extrudedHeight : 0,
                outline : true,
                outlineColor : Cesium.Color.WHITE,
                outlineWidth : 4,material:window.Cesium.Color.ALICEBLUE.withAlpha(0.5)
            }
        });
    }

    
    function addsimpleline0(DegresArry,width,color,name,id){
        cesiumUtil.removeEntitesById(id);
        var Line = viewer.entities.add({
            name : name,
            id : id,
            polyline : {
                positions : Cesium.Cartesian3.fromDegreesArrayHeights(DegresArry),
                width : width,
                material : color
            }
        });
        return Line;
    }

    
    function addGlowingLine(DegresArry,width,color,name,glowPower,id){
        cesiumUtil.removeEntitesById(id);
        var glowingLine = viewer.entities.add({
            name : name,
            id: id,
            polyline : {
                positions :Cesium.Cartesian3.fromDegreesArrayHeights(DegresArry),
                width : width,
                show: true,
                material : new Cesium.PolylineGlowMaterialProperty({
                    glowPower : glowPower,
                    color : color
                })
            }
        });
        return glowingLine;
    }
    //////////////////////////////////////////////////////大气监测数据3D点云显示  结束/////////////////////////////////

    //////////////////////////////////////////////////////大气监测数据网格显示  开始/////////////////////////////////
    function createairGrid(taskid,gridwidth) {
        airdata.getairdatas(taskid,function (airdatas) {
            /*airGrid(airdatas);*/
            PointCloud2Grid.createAirGrids(airdatas,gridwidth);
            airColorBar.resetairdataColor(UiParaManager.getCurParaName());
            dingweibyairdatas(airdatas);
        })
    }

    /**
     * 同时加载多个任务数据
     * @param taskids
     * @param gridwidth
     * @param callback
     */
    function createairGridMultiTasks(taskids, gridwidth) {
        if (!taskids || !taskids.length || taskids < 1) {
            return null;
        }
        for (let i = 0; i < taskids.length;i++){
            let airtaskid=taskids[i];
            airdata.getairdatas(airtaskid,function (airdatas) {
                PointCloud2Grid.createAirGrids(airdatas,gridwidth);
                if (i==taskids.length-1){
                    //airColorBar.resetairdataColor(UiParaManager.getCurParaName());
                    dingweibyairdatas(airdatas);
                    var minmaxCurAirDatas=airColorBar.getairdataparaminmax(UiParaManager.getCurParaName());
                    airColorBar.resetparaBar(minmaxCurAirDatas.min,minmaxCurAirDatas.max);
                    $("#inputairparamin").val(minmaxCurAirDatas.min);
                    $("#inputairparamax").val(minmaxCurAirDatas.max);
                    airColorBar.resetairdataColor(UiParaManager.getCurParaName());//重新设置数据渲染颜色
                    PointCloud2Grid.setGridsLabels(UiParaManager.getCurParaName());//重新设置网格标签
                }
            })
        }
    }
    //////////////////////////////////////////////////////大气监测数据网格显示  结束/////////////////////////////////

    /**
     * 根据airdatas定位,每个taskid对应的数据
     */
    function dingweibyairdatas(airdatas) {
        var minXminYminHmaxXmaxYmaxH=getminXminYminHmaxXmaxYmaxH(airdatas);
        var minlon=minXminYminHmaxXmaxYmaxH.minX;
        var minlat=minXminYminHmaxXmaxYmaxH.minY;
        var maxlon=minXminYminHmaxXmaxYmaxH.maxX;
        var maxlat=minXminYminHmaxXmaxYmaxH.maxY;
        var minheight=minXminYminHmaxXmaxYmaxH.minH;
        var maxheight=minXminYminHmaxXmaxYmaxH.maxH;
        cesiumLocateUtil.dingwei(minlon,minlat,maxlon,maxlat,-90);
    }

    /**
     * 根据taskid定位
     */
    function dingweibyairtaskid(airtaskid) {
        var airdatas=getairdatasbytaskid(airtaskid);
        var minXminYminHmaxXmaxYmaxH=getminXminYminHmaxXmaxYmaxH(airdatas);
        var minlon=minXminYminHmaxXmaxYmaxH.minX;
        var minlat=minXminYminHmaxXmaxYmaxH.minY;
        var maxlon=minXminYminHmaxXmaxYmaxH.maxX;
        var maxlat=minXminYminHmaxXmaxYmaxH.maxY;
        var minheight=minXminYminHmaxXmaxYmaxH.minH;
        var maxheight=minXminYminHmaxXmaxYmaxH.maxH;
        cesiumLocateUtil.dingwei(minlon,minlat,maxlon,maxlat,-90);
    }

    /**
     * 根据taskid获取当前加载的大气监测数据
     * @param taskid
     */
    function getairdatasbytaskid(taskid) {
        var airdatas=[];
        for (var i=0;i<window.viewer.entities.values.length;i++)
        {
            var entity=window.viewer.entities.values[i];
            if (entity.name===airEntityNameCommon.airGridEntityNames.airgrid||entity.name==airEntityNameCommon.air3dEntityNames.aircloud_point){
                let airinfo=entity.airdatainfo;
                if (airinfo&&airinfo.taskid==taskid) {
                    airdatas.push(airinfo);
                }
            }
        }
        return airdatas;
    }


    /**
     * 获取当前加载的大气监测数据
     */
    function getairdatas() {
        var airdatas=[];
        for (var i=0;i<window.viewer.entities.values.length;i++)
        {
            var entity=window.viewer.entities.values[i];
            if (entity.name===airEntityNameCommon.airGridEntityNames.airgrid||entity.name==airEntityNameCommon.air3dEntityNames.aircloud_point){
                let airinfo=entity.airdatainfo;
                if (airinfo) {
                    airdatas.push(airinfo);
                }
            }
        }
        return airdatas;
    }

    /**
     * 根据taskid清除大气监测数据
     * @param taskid
     */
    function removedatabytaskid(taskid) {
        for (var i=0;i<window.viewer.entities.values.length;i++)
        {
            var entity=window.viewer.entities.values[i];
            if (entity.name===airEntityNameCommon.airGridEntityNames.airgrid||entity.name==airEntityNameCommon.air3dEntityNames.aircloud_point){
                let airinfo=entity.airdatainfo;
                if (airinfo&&airinfo.taskid==taskid) {
                    window.viewer.entities.removeById(entity.id);
                    i--;
                }
            }
        }
    }

    /**
     * 根据airtaskid设置数据显示和不显示
     * @param airtaskid
     */
    function showhideairdatabytaskid(airtaskid,visible) {
        for (var i=0;i<window.viewer.entities.values.length;i++)
        {
            var entity=window.viewer.entities.values[i];
            if (entity.name===airEntityNameCommon.airGridEntityNames.airgrid||entity.name==airEntityNameCommon.air3dEntityNames.aircloud_point){
                let airinfo=entity.airdatainfo;
                if (airinfo&&airinfo.taskid==airtaskid) {
                    entity.show=visible;
                }
            }
        }
    }

    /**
     * 清除所有
     */
    function clearAll() {
        for (var i=0;i<window.viewer.entities.values.length;i++)
        {
            var entity=window.viewer.entities.values[i];
            if (entity.name===airEntityNameCommon.airGridEntityNames.airgrid
                ||entity.name==airEntityNameCommon.air3dEntityNames.aircloud_point
                ||entity.name==airEntityNameCommon.air3dEntityNames.aircloud_label
                ||entity.name==airEntityNameCommon.air3dEntityNames.aircloud_wall
                ||entity.name==airEntityNameCommon.air3dEntityNames.aircloud_line){
                window.viewer.entities.removeById(entity.id);
                i--;
            }
        }
        livedata.clearinterval();
        if (window.frames["ifreamairlivedataline"]
            && window.frames["ifreamairlivedataline"].contentWindow
            && window.frames["ifreamairlivedataline"].contentWindow.chartutil
            &&window.frames["ifreamairlivedataline"].contentWindow.chartutil.clearinterval){
            window.frames["ifreamairlivedataline"].contentWindow.chartutil.clearinterval();
        }

    }

    /**
     * 清除所有网格
     */
    function clearAllGrid() {
        for (var i=0;i<window.viewer.entities.values.length;i++)
        {
            var entity=window.viewer.entities.values[i];
            if (entity.name===airEntityNameCommon.airGridEntityNames.airgrid){
                window.viewer.entities.removeById(entity.id);
                i--;
            }
        }
    }

    /**
     * 清除所有3D点云
     */
    function clearAll3Dpoints() {
        for (var i=0;i<window.viewer.entities.values.length;i++)
        {
            var entity=window.viewer.entities.values[i];
            if (entity.name==airEntityNameCommon.air3dEntityNames.aircloud_point
                ||entity.name==airEntityNameCommon.air3dEntityNames.aircloud_label
                ||entity.name==airEntityNameCommon.air3dEntityNames.aircloud_wall
                ||entity.name==airEntityNameCommon.air3dEntityNames.aircloud_line){
                window.viewer.entities.removeById(entity.id);
                i--;
            }
        }
    }

    /**
     * 清除3D点云的坐标系和标注等
     */
    function clear3Dfream() {
        for (var i=0;i<window.viewer.entities.values.length;i++)
        {
            var entity=window.viewer.entities.values[i];
            if (entity.name==airEntityNameCommon.air3dEntityNames.aircloud_label
                ||entity.name==airEntityNameCommon.air3dEntityNames.aircloud_wall
                ||entity.name==airEntityNameCommon.air3dEntityNames.aircloud_line){
                window.viewer.entities.removeById(entity.id);
                i--;
            }
        }
    }

    /**
     * 重新绘制3D点云坐标系,不渲染数据
     */
    function draw3Dfream(airdatas) {
        clear3Dfream();
        if (!airdatas || !airdatas.length || airdatas.length < 1) {
            return;
        }
        var minXminYminHmaxXmaxYmaxH=getminXminYminHmaxXmaxYmaxH(airdatas);
        var minlon=minXminYminHmaxXmaxYmaxH.minX;
        var minlat=minXminYminHmaxXmaxYmaxH.minY;
        var maxlon=minXminYminHmaxXmaxYmaxH.maxX;
        var maxlat=minXminYminHmaxXmaxYmaxH.maxY;
        var minheight=minXminYminHmaxXmaxYmaxH.minH;
        var maxheight=minXminYminHmaxXmaxYmaxH.maxH;
        if (maxheight<1){
            maxheight=1;
        }
        maxheight=maxheight*1.5;
        //cesiumLocateUtil.setViewer(viewer);
        //cesiumLocateUtil.dingweiByPoint(minlon,minlat,maxheight,3);
        var cellLen=(maxlon-minlon)/5;
        var cellLat=(maxlat-minlat)/5;
        var cellheight=(maxheight-minheight)/5;
        var extraLen=cellLen/3;
        var extraLat=cellLat/3;

        minlon=minlon-cellLen;
        minlat=minlat-cellLat;
        maxlon=maxlon+cellLen;
        maxlat=maxlat+cellLat;
        minheight=minheight;
        maxheight=maxheight+cellheight;

        cellLen=(maxlon-minlon)/5;
        cellLat=(maxlat-minlat)/5;
        cellheight=(maxheight-minheight)/5;
        extraLen=cellLen/3;
        extraLat=cellLat/3;
        //添加坐标轴
        addsimpleline0([minlon,maxlat,minheight,minlon,minlat-extraLat,minheight],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c001');
        addsimpleline0([minlon,maxlat,minheight,maxlon,maxlat,minheight],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c002');
        addsimpleline0([minlon,maxlat,minheight,minlon,maxlat,maxheight],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c003');
        addsimpleline0([minlon,minlat,minheight,maxlon,minlat,minheight],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c004');
        addsimpleline0([maxlon,maxlat,minheight,maxlon,minlat,minheight],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c005');


        //添加网格线 西
        addsimpleline0([minlon,maxlat,minheight+cellheight,minlon,minlat-extraLat,minheight+cellheight],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c006');
        addsimpleline0([minlon,maxlat,minheight+cellheight*2,minlon,minlat-extraLat,minheight+cellheight*2],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c007');
        addsimpleline0([minlon,maxlat,minheight+cellheight*3,minlon,minlat-extraLat,minheight+cellheight*3],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c008');
        addsimpleline0([minlon,maxlat,minheight+cellheight*4,minlon,minlat-extraLat,minheight+cellheight*4],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c009');
        addsimpleline0([minlon,maxlat,minheight+cellheight*5,minlon,minlat-extraLat,minheight+cellheight*5],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c0010');
        //添加网格线 北
        addsimpleline0([minlon,maxlat,minheight+cellheight,maxlon+extraLen,maxlat,minheight+cellheight],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c0011');
        addsimpleline0([minlon,maxlat,minheight+cellheight*2,maxlon+extraLen,maxlat,minheight+cellheight*2],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c0012');
        addsimpleline0([minlon,maxlat,minheight+cellheight*3,maxlon+extraLen,maxlat,minheight+cellheight*3],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c0013');
        addsimpleline0([minlon,maxlat,minheight+cellheight*4,maxlon+extraLen,maxlat,minheight+cellheight*4],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c0014');
        addsimpleline0([minlon,maxlat,minheight+cellheight*5,maxlon+extraLen,maxlat,minheight+cellheight*5],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c0015');
        //添加网格线 南
        addsimpleline0([minlon+cellLen,minlat-extraLat,minheight,minlon+cellLen,minlat,minheight],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c0016');
        addsimpleline0([minlon+cellLen*2,minlat-extraLat,minheight,minlon+cellLen*2,minlat,minheight],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c0017');
        addsimpleline0([minlon+cellLen*3,minlat-extraLat,minheight,minlon+cellLen*3,minlat,minheight],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c0018');
        addsimpleline0([minlon+cellLen*4,minlat-extraLat,minheight,minlon+cellLen*4,minlat,minheight],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c0019');
        addsimpleline0([minlon+cellLen*5,minlat-extraLat,minheight,minlon+cellLen*5,minlat,minheight],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c0020');

        //添加网格线 东
        addsimpleline0([maxlon,minlat,minheight,maxlon+extraLen,minlat ,minheight],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c0021');
        addsimpleline0([maxlon,minlat+cellLat,minheight,maxlon+extraLen,minlat+cellLat ,minheight],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c0021');
        addsimpleline0([maxlon,minlat+cellLat*2,minheight,maxlon+extraLen,minlat+cellLat*2,minheight],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c0022');
        addsimpleline0([maxlon,minlat+cellLat*3,minheight,maxlon+extraLen,minlat+cellLat*3,minheight],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c0023');
        addsimpleline0([maxlon,minlat+cellLat*4,minheight,maxlon+extraLen,minlat+cellLat*4,minheight],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c0024');
        addsimpleline0([maxlon,minlat+cellLat*5,minheight,maxlon+extraLen,minlat+cellLat*5,minheight],2,Cesium.Color.RED,airEntityNameCommon.air3dEntityNames.aircloud_line,'c0025');

        //添加墙 西
        addWall(minlon,maxlat,minheight+0.001,
            minlon,minlat,minheight+0.001,maxheight,maxheight,airEntityNameCommon.air3dEntityNames.aircloud_wall);
        //添加墙 北
        addWall(minlon,maxlat,minheight+0.001,
            maxlon,maxlat,minheight+0.001,maxheight,maxheight,airEntityNameCommon.air3dEntityNames.aircloud_wall);
        //添加标签 西
        addwalllabel(minlon,minlat-extraLat,minheight+cellheight,(minheight+cellheight).toFixed(2)+'m',airEntityNameCommon.air3dEntityNames.aircloud_label);
        addwalllabel(minlon,minlat-extraLat,minheight+cellheight*2,(minheight+cellheight*2).toFixed(2)+'m',airEntityNameCommon.air3dEntityNames.aircloud_label);
        addwalllabel(minlon,minlat-extraLat,minheight+cellheight*3,(minheight+cellheight*3).toFixed(2)+'m',airEntityNameCommon.air3dEntityNames.aircloud_label);
        addwalllabel(minlon,minlat-extraLat,minheight+cellheight*4,(minheight+cellheight*4).toFixed(2)+'m',airEntityNameCommon.air3dEntityNames.aircloud_label);
        addwalllabel(minlon,minlat-extraLat,minheight+cellheight*5,(minheight+cellheight*5).toFixed(2)+'m',airEntityNameCommon.air3dEntityNames.aircloud_label);
        //添加标签 北
        addwalllabel(maxlon+extraLen,maxlat,minheight+cellheight,(minheight+cellheight).toFixed(2)+'m',airEntityNameCommon.air3dEntityNames.aircloud_label);
        addwalllabel(maxlon+extraLen,maxlat,minheight+cellheight*2,(minheight+cellheight*2).toFixed(2)+'m',airEntityNameCommon.air3dEntityNames.aircloud_label);
        addwalllabel(maxlon+extraLen,maxlat,minheight+cellheight*3,(minheight+cellheight*3).toFixed(2)+'m',airEntityNameCommon.air3dEntityNames.aircloud_label);
        addwalllabel(maxlon+extraLen,maxlat,minheight+cellheight*4,(minheight+cellheight*4).toFixed(2)+'m',airEntityNameCommon.air3dEntityNames.aircloud_label);
        addwalllabel(maxlon+extraLen,maxlat,minheight+cellheight*5,(minheight+cellheight*5).toFixed(2)+'m',airEntityNameCommon.air3dEntityNames.aircloud_label);
        //添加标签 南
        addwalllabel(minlon+cellLen,minlat-extraLat,minheight,(minlon+cellLen).toFixed(4)+'',airEntityNameCommon.air3dEntityNames.aircloud_label);
        addwalllabel(minlon+cellLen*2,minlat-extraLat,minheight,(minlon+cellLen*2).toFixed(4)+'',airEntityNameCommon.air3dEntityNames.aircloud_label);
        addwalllabel(minlon+cellLen*3,minlat-extraLat,minheight,(minlon+cellLen*3).toFixed(4)+'',airEntityNameCommon.air3dEntityNames.aircloud_label);
        addwalllabel(minlon+cellLen*4,minlat-extraLat,minheight,(minlon+cellLen*4).toFixed(4)+'',airEntityNameCommon.air3dEntityNames.aircloud_label);
        addwalllabel(minlon+cellLen*5,minlat-extraLat,minheight,(minlon+cellLen*5).toFixed(4)+'',airEntityNameCommon.air3dEntityNames.aircloud_label);
        //添加标签 东
        addwalllabel(maxlon+extraLen,minlat,minheight,(minlat).toFixed(4)+'',airEntityNameCommon.air3dEntityNames.aircloud_label);
        addwalllabel(maxlon+extraLen,minlat+cellLat,minheight,(minlat+cellLat).toFixed(4)+'',airEntityNameCommon.air3dEntityNames.aircloud_label);
        addwalllabel(maxlon+extraLen,minlat+cellLat*2,minheight,(minlat+cellLat*2).toFixed(4)+'',airEntityNameCommon.air3dEntityNames.aircloud_label);
        addwalllabel(maxlon+extraLen,minlat+cellLat*3,minheight,(minlat+cellLat*3).toFixed(4)+'',airEntityNameCommon.air3dEntityNames.aircloud_label);
        addwalllabel(maxlon+extraLen,minlat+cellLat*4,minheight,(minlat+cellLat*4).toFixed(4)+'',airEntityNameCommon.air3dEntityNames.aircloud_label);
        //addwalllabel(maxlon+extraLen,minlat+cellLat*5,minheight,(minlat+cellLat*5).toFixed(4)+'');
    }

    /**
     * 切换展示形式 表格 或者3D点云
     * @param airType
     */
    function changeairtype(airType) {
        if (airType == 0) {
            let airmultitaskdatas=[];
            for (let i=0;i<window.viewer.entities.values.length;i++)
            {
                let entity=window.viewer.entities.values[i];
                if (entity.name==airEntityNameCommon.air3dEntityNames.aircloud_point){
                    let airinfo=entity.airdatainfo;
                    if (airinfo) {
                        airmultitaskdatas.push(airinfo);
                    }
                }
            }
            if (airmultitaskdatas.length < 1) {
                return;
            }
            PointCloud2Grid.createAirGrids(airmultitaskdatas,airdata.gridWidthjiaodu);
            airColorBar.resetairdataColor(UiParaManager.getCurParaName());
            clearAll3Dpoints();
        }else {
            let airmultitaskdatas=[];
            let airdatas=[];
            var firstdata = airColorBar.findFirstAirData();
            if (!firstdata) {
                return;
            }
            var curtaskid=firstdata.taskid;
            for (let i=0;i<window.viewer.entities.values.length;i++)
            {
                let entity=window.viewer.entities.values[i];
                if (entity.name==airEntityNameCommon.airGridEntityNames.airgrid){
                    let airinfo=entity.airdatainfo;
                    let taskid=airinfo.taskid;
                    if (airinfo) {
                        if (taskid !== curtaskid) {
                            airmultitaskdatas.push([].concat(JSON.parse(JSON.stringify(airdatas))));
                            airdatas=[];
                            airdatas.push(airinfo);
                        }
                        else{
                            airdatas.push(airinfo);
                        }
                        curtaskid=taskid;
                    }
                }
            }
            airmultitaskdatas.push([].concat(JSON.parse(JSON.stringify(airdatas))));
            if (airmultitaskdatas.length > 0) {
                for (let i = 0; i < airmultitaskdatas.length; i++) {
                    let airdatas=airmultitaskdatas[i];
                    air3dcloud(airdatas);
                }
            }
            clearAllGrid();
        }
    }

    return {
        createair3dcloud:createair3dcloud,
        createairGrid:createairGrid,
        dingweibyairtaskid:dingweibyairtaskid,
        createairGridMultiTasks:createairGridMultiTasks,
        removedatabytaskid:removedatabytaskid,
        clearAll:clearAll,
        changeairtype:changeairtype,
        draw3Dfream:draw3Dfream,
        createair3dcloudpoint:createair3dcloudpoint,
        getairdatas:getairdatas,
        clear3Dfream:clear3Dfream
    }
})()

  

 

posted on 2019-08-07 15:47  苹果园dog  阅读(4824)  评论(22编辑  收藏  举报

导航