import store from "../store/index"
class Draw {
constructor(viewer, config) {
this.viewer = viewer
this.config = config || {
borderColor: Cesium.Color.BLUE,
borderWidth: 5,
material: Cesium.Color.GREEN.withAlpha(0.5),
}
this.infoDetail = {
point: [], line: [], rectangle: [], circle: [], planeSelf: [] }
this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas)
}
drawPoint() {
this.handler.destroy()
this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas)
this.handler.setInputAction((click) => {
let cartesian = this.viewer.camera.pickEllipsoid(click.position, this.viewer.scene.globe.ellipsoid)
let cartographic = Cesium.Cartographic.fromCartesian(cartesian, this.viewer.scene.globe.ellipsoid, new Cesium.Cartographic())
let lng = Cesium.Math.toDegrees(cartographic.longitude)
let lat = Cesium.Math.toDegrees(cartographic.latitude)
let id = new Date().getTime()
this.viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(lng, lat, 0),
name: 'point',
id: id,
point: {
color: this.config.material,
pixelSize: 12,
outlineColor: this.config.borderColor,
outlineWidth: this.config.borderWidth
}
})
this.infoDetail.point.push({
id: id, position: [lng, lat] })
}, Cesium.ScreenSpaceEventType.LEFT_CLICK)
this.handler.setInputAction((click) => {
this.handler.destroy();
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK)
}
drawRectangle() {
this.handler.destroy()
let westSouthEastNorth = []
let id = null
this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas)
this.handler.setInputAction((click) => {
var position = this.viewer.scene.pickPosition(click.position);
var cartographic = Cesium.Cartographic.fromCartesian(position);
let lng1 = Cesium.Math.toDegrees(cartographic.longitude)
let lat1 = Cesium.Math.toDegrees(cartographic.latitude)
westSouthEastNorth = [lng1, lat1]
id = new Date().getTime()+Math.round(Math.random()*1000000000)
if (westSouthEastNorth) {
this.handler.removeInputAction(Cesium