Browse Source

修复能够删除矩形和圆形

lbj
ctw 3 months ago
parent
commit
41feed779c
  1. 179
      ruoyi-ui/src/views/cesiumMap/index.vue

179
ruoyi-ui/src/views/cesiumMap/index.vue

@ -1092,88 +1092,53 @@ export default {
},
addRectangleEntity(coordinates) {
this.entityCounter++
const id = `rectangle_${this.entityCounter}`
const entity = this.viewer.entities.add({
id: id,
name: `矩形 ${this.entityCounter}`,
rectangle: {
coordinates: coordinates,
material: Cesium.Color.fromCssColorString(this.defaultStyles.rectangle.color)
.withAlpha(this.defaultStyles.rectangle.opacity),
outline: true,
outlineColor: Cesium.Color.fromCssColorString(this.defaultStyles.rectangle.color),
outlineWidth: this.defaultStyles.rectangle.width
}
})
const entityData = {
id,
type: 'rectangle',
coordinates: coordinates,
entity: entity,
color: this.defaultStyles.rectangle.color,
opacity: this.defaultStyles.rectangle.opacity,
width: this.defaultStyles.rectangle.width,
label: `矩形 ${this.entityCounter}`
}
this.allEntities.push(entityData)
entity.clickHandler = (e) => {
this.selectEntity(entityData)
e.stopPropagation()
}
return entityData
},
addCircleEntity(center, radius, positions) {
this.entityCounter++
const id = `circle_${this.entityCounter}`
const entity = this.viewer.entities.add({
id: id,
name: `圆形 ${this.entityCounter}`,
polygon: {
hierarchy: new Cesium.PolygonHierarchy(positions),
material: Cesium.Color.fromCssColorString(this.defaultStyles.circle.color)
.withAlpha(this.defaultStyles.circle.opacity),
outline: true,
outlineColor: Cesium.Color.fromCssColorString(this.defaultStyles.circle.color),
outlineWidth: this.defaultStyles.circle.width
},
position: center,
point: {
pixelSize: 5,
color: Cesium.Color.RED
}
})
const centerLL = this.cartesianToLatLng(center)
const entityData = {
id,
type: 'circle',
center: centerLL,
radius: radius,
positions: positions,
entity: entity,
color: this.defaultStyles.circle.color,
opacity: this.defaultStyles.circle.opacity,
width: this.defaultStyles.circle.width,
label: `圆形 ${this.entityCounter}`
}
this.allEntities.push(entityData)
this.entityCounter++
const id = `rectangle_${this.entityCounter}`
const entity = this.viewer.entities.add({
id: id,
name: `矩形 ${this.entityCounter}`,
rectangle: {
coordinates: coordinates,
material: Cesium.Color.fromCssColorString(this.defaultStyles.rectangle.color)
.withAlpha(this.defaultStyles.rectangle.opacity),
outline: true,
outlineColor: Cesium.Color.fromCssColorString(this.defaultStyles.rectangle.color),
outlineWidth: this.defaultStyles.rectangle.width
}
})
// entity bug
this.allEntities.push(entity)
return entity
},
addCircleEntity(center, radius) {
this.entityCounter++
const id = `circle_${this.entityCounter}`
const entity = this.viewer.entities.add({
id: id,
name: `圆形 ${this.entityCounter}`,
position: center, //
// 使 ellipse ()
ellipse: {
semiMinorAxis: radius, // =
semiMajorAxis: radius, // =
material: Cesium.Color.fromCssColorString(this.defaultStyles.circle.color)
.withAlpha(this.defaultStyles.circle.opacity),
outline: true,
outlineColor: Cesium.Color.fromCssColorString(this.defaultStyles.circle.color),
outlineWidth: this.defaultStyles.circle.width
}
})
entity.clickHandler = (e) => {
this.selectEntity(entityData)
e.stopPropagation()
}
// entity
this.allEntities.push(entity)
return entityData
},
return entity
},
// ================== ==================
@ -1352,25 +1317,47 @@ export default {
},
clearAll() {
//
this.stopDrawing()
this.drawingMode = null
//
this.allEntities.forEach(entity => {
if (entity.entity) {
this.viewer.entities.remove(entity.entity)
// 1.
if (this.allEntities && this.allEntities.length > 0) {
// 2.
this.allEntities.forEach(item => {
try {
// A: Cesium Entity (线)
if (item instanceof Cesium.Entity) {
this.viewer.entities.remove(item);
}
})
// B: ( { entity: ... })
else if (item.entity && item.entity instanceof Cesium.Entity) {
this.viewer.entities.remove(item.entity);
}
// C: ID
else if (item.id) {
this.viewer.entities.removeById(item.id);
}
} catch (e) {
console.warn('删除实体失败:', e);
}
});
}
//
this.allEntities = []
this.entityCounter = 0
this.selectedEntity = null
this.measurementResult = null
// 3.
this.allEntities = [];
console.log('已清除所有图形')
},
// 4.
if (this.tempEntity) {
this.viewer.entities.remove(this.tempEntity);
this.tempEntity = null;
}
if (this.tempPreviewEntity) {
this.viewer.entities.remove(this.tempPreviewEntity);
this.tempPreviewEntity = null;
}
// 5.
this.measurementResult = null;
this.stopDrawing();
},
// ================== ==================

Loading…
Cancel
Save