Browse Source

修复能够删除矩形和圆形

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

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

@ -1108,72 +1108,37 @@ export default {
} }
}) })
const entityData = { // entity bug
id, this.allEntities.push(entity)
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) { return entity
},
addCircleEntity(center, radius) {
this.entityCounter++ this.entityCounter++
const id = `circle_${this.entityCounter}` const id = `circle_${this.entityCounter}`
const entity = this.viewer.entities.add({ const entity = this.viewer.entities.add({
id: id, id: id,
name: `圆形 ${this.entityCounter}`, name: `圆形 ${this.entityCounter}`,
polygon: { position: center, //
hierarchy: new Cesium.PolygonHierarchy(positions),
// 使 ellipse ()
ellipse: {
semiMinorAxis: radius, // =
semiMajorAxis: radius, // =
material: Cesium.Color.fromCssColorString(this.defaultStyles.circle.color) material: Cesium.Color.fromCssColorString(this.defaultStyles.circle.color)
.withAlpha(this.defaultStyles.circle.opacity), .withAlpha(this.defaultStyles.circle.opacity),
outline: true, outline: true,
outlineColor: Cesium.Color.fromCssColorString(this.defaultStyles.circle.color), outlineColor: Cesium.Color.fromCssColorString(this.defaultStyles.circle.color),
outlineWidth: this.defaultStyles.circle.width outlineWidth: this.defaultStyles.circle.width
},
position: center,
point: {
pixelSize: 5,
color: Cesium.Color.RED
} }
}) })
const centerLL = this.cartesianToLatLng(center) // entity
const entityData = { this.allEntities.push(entity)
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) return entity
},
entity.clickHandler = (e) => {
this.selectEntity(entityData)
e.stopPropagation()
}
return entityData
},
// ================== ================== // ================== ==================
@ -1352,25 +1317,47 @@ export default {
}, },
clearAll() { clearAll() {
// // 1.
this.stopDrawing() if (this.allEntities && this.allEntities.length > 0) {
this.drawingMode = null
// // 2.
this.allEntities.forEach(entity => { this.allEntities.forEach(item => {
if (entity.entity) { try {
this.viewer.entities.remove(entity.entity) // 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);
}
});
} }
})
// // 3.
this.allEntities = [] this.allEntities = [];
this.entityCounter = 0
this.selectedEntity = null
this.measurementResult = null
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