Skip to content

模型裁剪

裁剪的保存和水面相同,都是使用 togeojson()的方式直接转换为 json 格式数据上传保存,裁剪需要额外调用裁剪接口

模型裁剪绘制

JavaScript
var cutDataSource;
//裁剪的面要素会保存到该对象中
var promise = viewer.dataSources.add(new LSGlobe.GeoJsonDataSource("cutDataSource"));
promise.then(function(dataSource) {
    cutDataSource = dataSource;
}).otherwise(function(error) {

});

//裁剪的绘制
var cutHandler = new LSGlobe.ScreenSpaceEventHandler(viewer.scene.canvas);
cutHandler.setInputAction(function(movement) {
    //获取的坐标上添加标绘点,具体的坐标获取参照坐标转换
    var Pos = scene.pickGlobe(movement.position);
},LSGlobe.ScreenSpaceEventType.LEFT_CLICK);

//根据上面获取到的点集合经过处理后达到新的数据
var oValuePoint = ChangePolygonPosition(event.positions);//同压平的坐标处理方法

包含模式

JavaScript
var oClipProperty = {
    name: "裁剪面",
    cutType: "clip"
};
var clipPolygon = new LSGlobe.PolygonGeometry({
    polygonHierarchy: new LSGlobe.PolygonHierarchy(oValuePoint),
    perPositionHeight: true
});
clipPolygon.id = sEntityGuid;//裁剪id
clipPolygon.name = oClipProperty.name;

var cutEntity = cutDataSource.entities.add({
    name: '裁剪面',
    id: sEntityGuid,
    polygon: {
        hierarchy: {
            positions: oValuePoint
        },
        material: new LSGlobe.Color(0.5, 1.0, 1.0, 0.01),
        fill: true,
        perPositionHeight: true,
        outline: false
    }
});
var entityPosition = getRealPosition(cutEntity);

var oTargetTileset = whichTileset(entityPosition.lng, entityPosition.lat)[0];
if (oTargetTileset) {
    oClipProperty.tilesetId = oTargetTileset.name.id;
    if (oTargetTileset._clipPolygons.length > 0 ) {
        alert("实景三维模型只能进行一次包含模式裁剪!");
        cutDataSource.entities.removeById(sEntityGuid);
        return;
    } else {
        oTargetTileset.cleanClipPolygons();
    }
    cutEntity.properties = oClipProperty;
    oTargetTileset.addClipPolygon(clipPolygon);
} else {
    cutDataSource.entities.removeById(sEntityGuid);
}

抠取模式

JavaScript
var oClipProperty = {
    name: "裁剪面",
    cutType: "pit"
};
var clipPolygon = new LSGlobe.PolygonGeometry({
    polygonHierarchy: new LSGlobe.PolygonHierarchy(oValuePoint),
    perPositionHeight: true
});
clipPolygon.id = sEntityGuid;//裁剪id
clipPolygon.name = oClipProperty.name;

var cutEntity = cutDataSource.entities.add({
    name: '裁剪面',
    id: sEntityGuid,
    polygon: {
        hierarchy: {
            positions: oValuePoint
        },
        material: new LSGlobe.Color(0.5, 1.0, 1.0, 0.01),
        fill: true,
        perPositionHeight: true,
        outline: false
    }
});
var entityPosition = getRealPosition(cutEntity);

var oTargetTileset = whichTileset(entityPosition.lng, entityPosition.lat)[0];
if (oTargetTileset) {
    oClipProperty.tilesetId = oTargetTileset.name.id;
    cutEntity.properties = oClipProperty;
    oTargetTileset.pitPolygons.push(clipPolygon);
    oTargetTileset.oPageLOD.updatePit();
} else {
    cutDataSource.entities.removeById(sEntityGuid);
}

裁剪编辑

主要通过操作裁剪集合数据-cutDataSource.entities,然后进行对应的裁剪类型进行操作

JavaScript
var entities = cutDataSource.entities.values;
    for (var i = 0; i < entities.length; i++) {
        var entity = entities[i];
        var oProperties=entity.properties.getValue();
        var CutId = entity.id;
        var CutName = entity.name;
        if(tilesetid&&oProperties.tilesetId!=tilesetid){
            continue;
        }
        if (entity.polygon&&entity.show) {
            entity.polygon.outline=false;
            var cutPolygon= new LSGlobe.PolygonGeometry({
                polygonHierarchy: new LSGlobe.PolygonHierarchy(entity.polygon.hierarchy._value.positions),
                perPositionHeight : true
            });
            cutPolygon.name=CutName;
            cutPolygon.id=CutId;
            var oPageLOD=getPageLODLayersById(oProperties.tilesetId);//实景三维数据获取方法
            if(oPageLOD){
                if("clip"==oProperties.cutType){
                    oPageLOD.addClipPolygon(cutPolygon);
                }else{
                    oPageLOD.pitPolygons.push(cutPolygon);
                    oPageLOD.updatePit();
                }
            }
        }
    }

裁剪显示隐藏

JavaScript
var cutEntity = cutDataSource.entities.getById(id);//获取对应裁剪entity.
cutEntity.show=true;//true:显示,false:隐藏
var oProperties = cutEntity.properties.getValue();//获取裁剪的类型
var tileset = getPageLODLayersById(oProperties.tilesetId);//实景三维数据获取方法

if(oProperties.cutType=="clicp"){
    if(cutEntity.show){
        var cutPolygon = new LSGlobe.PolygonGeometry({
            polygonHierarchy: new LSGlobe.PolygonHierarchy(cutEntity.polygon.hierarchy._value.positions),
            perPositionHeight: true
        });
        tileset.addClipPolygon(cutPolygon);
    }else{
        tileset.cleanClipPolygons();
    }
}else{
    for (var i = 0; i < tileset._pitPolygons.length; i++) {
        if (cutEntity.id == tileset._pitPolygons[i].id) {
            tileset._pitPolygons[i].show = cutEntity.show;
            tileset.updatePit();
        }
    }
}

裁剪飞行

JavaScript

var entity = cutDataSource.entities.getById(id);
var entityPosition = getRealPosition(entity);//同单体化
viewer.camera.flyTo({
    destination: LSGlobe.Cartesian3.fromDegrees(entityPosition.lng, entityPosition.lat, entityPosition.alt),
    duration: 3
})

裁剪删除

JavaScript
var cutEntity = cutDataSource.entities.getById(id);//根据裁剪id获取对应的参考entity
var oProperties = cutEntity.properties.getValue();//获取裁剪的类型
var tileset = getPageLODLayersById(oProperties.tilesetId);//实景三维数据获取方法

if(oProperties.cutType=="clicp"){
    tileset.cleanClipPolygons();
}else{
    for (var i = 0; i < tileset._pitPolygons.length; i++) {
        if (cutEntity.id == tileset._pitPolygons[i].id) {
            tileset._pitPolygons[i].show =false;
            tileset.updatePit();
        }
    }
}

cutDataSource.entities.removeById(id);

裁剪存储

裁剪存储是以 json 格式保存的,直接赋值给 oSubSceneData.clip,然后随场景保存接口一并提交保存

JavaScript
oSubSceneData.clip = cutDataSource.toGeoJson()

裁剪重载

裁剪获取接口,参数 jsonType 为 6

//localhost:8000/wish3dearth/api/scene/v1.0.0/getSceneJsonInfo

JavaScript
var oGeoJson = result.data;
//result.data前面获取的压平数据json
var promise = LSGlobe.GeoJsonDataSource.load(oGeoJson, {});
promise.then(function(dataSource) {
    //将数据再次加载到初始化存储裁剪的对象中
    cutDataSource = dataSource;
    //添加到球中
    viewer.dataSources.add(dataSource);

    var entities = cutDataSource.entities._entities._array;
    for (var i = 0; i < entities.length; i++) {
        var entity = entities[i];
        var oProperties = entity.properties.getValue();
        var CutId = entity.id;
        var CutName = entity.name;
        if (tilesetid && oProperties.tilesetId != tilesetid) {
            continue;
        }
        if (entity.polygon && entity.show) {
            entity.polygon.outline = false;
            var cutPolygon = new LSGlobe.PolygonGeometry({
                polygonHierarchy: new LSGlobe.PolygonHierarchy(entity.polygon.hierarchy._value.positions),
                perPositionHeight: true
            });
            cutPolygon.name = CutName;
            cutPolygon.id = CutId;
            var oPageLOD = getPageLODLayersById(oProperties.tilesetId);
            if (oPageLOD) {
                if ("clip" == oProperties.cutType) {
                    oPageLOD.addClipPolygon(cutPolygon);
                } else {
                    oPageLOD.pitPolygons.push(cutPolygon);
                    oPageLOD.updatePit();
                }
            }
        }
    }
}).otherwise(function(error) {
    console.log(error);
});

Released under the MIT License.