<template>
|
<Popup ref="pop" :title="form.title" left="calc(100% - 340px)" width="300px">
|
<div class="modelPress">
|
<el-form ref="form" :model="form" label-width="80px">
|
<!-- <el-form-item label="模型:">
|
<el-select v-model="form.modelId" @change="modelChange">
|
<el-option
|
v-for="item in modelList"
|
:label="item.name"
|
:value="item.id"
|
:key="item.id"
|
></el-option>
|
</el-select>
|
</el-form-item> -->
|
<el-form-item label="高度:">
|
<el-input
|
v-model="form.height"
|
@change="heightChange"
|
controls-position="right"
|
></el-input>
|
</el-form-item>
|
<div class="btn">
|
<el-button type="primary" @click="draw">绘制范围</el-button>
|
<!-- <el-button type="primary" @click="importData('shp')"
|
>导入shp</el-button
|
>
|
<el-button type="primary" @click="importData">导入json</el-button> -->
|
</div>
|
</el-form>
|
</div>
|
</Popup>
|
</template>
|
<script>
|
import Bus from './Bus';
|
import Popup from './Popup.vue';
|
let positions, model;
|
|
export default {
|
name: 'modelPress',
|
components: {
|
Popup,
|
},
|
data() {
|
return {
|
modelList: [],
|
form: {
|
title: '模型压平',
|
height: 10,
|
modelId: '',
|
},
|
};
|
},
|
computed: {},
|
mounted() {},
|
methods: {
|
// 关闭弹窗
|
close() {
|
this.$refs.pop.close();
|
model = undefined;
|
},
|
// 打开弹窗
|
open() {
|
this.$refs.pop.open();
|
this.$set(this, 'modelList', []);
|
if (sgworld.Creator._SE3DTilesets) {
|
for (let model of sgworld.Creator._SE3DTilesets.values()) {
|
this.modelList.push({
|
id: model.treeobj.id,
|
name: model.treeobj.name,
|
});
|
}
|
model = sgworld.Creator._SE3DTilesets.get(this.form.modelId);
|
model && (this.form.height = model.flattenHeight);
|
}
|
},
|
modelChange() {
|
model = sgworld.Creator._SE3DTilesets.get(this.form.modelId);
|
this.form.height = model.flattenHeight;
|
sgworld.Navigate.flyToObj(model);
|
},
|
heightChange() {
|
if (model) {
|
model.flattenHeight = this.form.height;
|
if (model.flattenData.size) {
|
model.flattenData.forEach((item, key) => {
|
Bus.$emit('updataTreeNode', key, {
|
height: model.flattenHeight,
|
});
|
});
|
}
|
}
|
},
|
addTreeNode(data) {
|
Bus.$emit('addOtherData', '压平', {
|
id: data.id,
|
name: data.name,
|
sourceType: 'modelFlatten',
|
modelId: data.modelId,
|
height: model.flattenHeight,
|
positions: data.positions,
|
item: data,
|
});
|
},
|
clear1() {
|
TerrainFlattening && TerrainFlattening.remove();
|
},
|
// 绘制
|
draw() {
|
// if (model) {
|
var deep = parseFloat(this.form.height);
|
var that = this;
|
window.TerrainFlattening = null;
|
sgworld.Creator.createSimpleGraphic(
|
'polygon',
|
{
|
clampToGround: true,
|
},
|
function (entity) {
|
positions = entity.polygon.hierarchy.getValue().positions;
|
sgworld.Creator.SimpleGraphic.remove(entity.id);
|
that.clear1();
|
TerrainFlattening = sgworld.Creator.createTerrainModifier(
|
'地形压平',
|
positions,
|
deep,
|
{}
|
);
|
}
|
);
|
// } else {
|
// this.$message('请选择模型');
|
// }
|
},
|
// 导入
|
importData(type) {
|
if (model) {
|
let shp = type === 'shp';
|
sgworld.Core.openLocalFile({
|
accept: shp ? '.shp' : '.json,.geojson',
|
callback: (fileURL) => {
|
if (shp) {
|
sgworld.Core.loadShpFile(
|
{
|
shp: fileURL,
|
},
|
(entity) => {
|
let positions;
|
if (entity.polyline) {
|
positions = entity.polyline.positions.getValue();
|
} else if (entity.polygon) {
|
positions = entity.polygon.hierarchy.getValue().positions;
|
}
|
if (positions) {
|
let data = model.setFlatten(true, {
|
fid: entity.id,
|
name: entity.name,
|
positions,
|
});
|
this.addTreeNode(data);
|
}
|
}
|
);
|
} else {
|
model.setFlattenByGeojson(true, fileURL).then((data) => {
|
debugger;
|
data.forEach((item) => {
|
this.addTreeNode(item);
|
});
|
});
|
}
|
},
|
});
|
} else {
|
this.$message('请选择模型');
|
}
|
},
|
},
|
};
|
</script>
|
<style lang="less">
|
.modelPress {
|
width: 300px;
|
.el-select {
|
width: 100%;
|
}
|
|
.btn {
|
text-align: center;
|
}
|
.el-button {
|
margin-left: 10px;
|
padding: 12px;
|
}
|
}
|
</style>
|