heightControl.js 1.32 KB
import objectManage from './maputils';
export default class heightControl {
    constructor() {
        this.handlerPolygon = new Cesium.DrawHandler(objectManage.viewer, Cesium.DrawMode.Polygon);
        this.handlerPolygon.drawEvt.addEventListener(result => {
            var array = [].concat(result.object.positions), positions = [];
            var polygon = result.object;
            if(!polygon) return;
            polygon.show = false;
            this.handlerPolygon.polyline.show = false;
			for(var i = 0, len = array.length; i < len; i++){
				var cartographic = Cesium.Cartographic.fromCartesian(array[i]);
				var longitude = Cesium.Math.toDegrees(cartographic.longitude);
				var latitude = Cesium.Math.toDegrees(cartographic.latitude);
				if(positions.indexOf(longitude)===-1&&positions.indexOf(latitude)===-1){
					positions.push(longitude);
					positions.push(latitude);
				}
            }
            this.polygon = objectManage.viewer.entities.add({
                id: 'polygonA',
                polygon: {
                    hierarchy: Cesium.Cartesian3.fromDegreesArray(positions),
                    height: 105,
                    material: new Cesium.Color(1, 1, 0.20, 0.5),
                    outline: true,
                    outlineColor: Cesium.Color.RED
                }
            }).polygon;
		});
    }
}