a59415cf by jikai

111111

1 parent a14037c4
export default class createDraw {
constructor(viewer) {
this.viewer = viewer;
this.handlerDis = new Cesium.MeasureHandler(viewer, Cesium.MeasureMode.Distance, 1);
this.distance();
this.handlerArea = new Cesium.MeasureHandler(viewer, Cesium.MeasureMode.Area, 0);
this.area();
this.handlerHeight = new Cesium.MeasureHandler(viewer, Cesium.MeasureMode.DVH);
this.height();
}
distance() {
this.handlerDis.measureEvt.addEventListener(result => {
var dis = Number(result.distance), distance = dis > 1000 ? (dis / 1000).toFixed(2) + 'km' : dis.toFixed(2) + 'm';
this.handlerDis.disLabel.text = '距离:' + distance;
});
this.handlerDis.activeEvt.addEventListener(this.handle());
}
area() {
this.handlerArea.measureEvt.addEventListener(result => {
var mj = Number(result.area), area = mj > 1000000 ? (mj / 1000000).toFixed(2) + 'km²' : mj.toFixed(2) + '㎡'
this.handlerArea.areaLabel.text = '面积:' + area;
});
this.handlerArea.activeEvt.addEventListener(this.handle());
}
height() {
this.handlerHeight.measureEvt.addEventListener(result => {
var distance = result.distance > 1000 ? (result.distance / 1000).toFixed(2) + 'km' : result.distance + 'm',
vHeight = result.verticalHeight > 1000 ? (result.verticalHeight / 1000).toFixed(2) + 'km' : result.verticalHeight + 'm',
hDistance = result.horizontalDistance > 1000 ? (result.horizontalDistance / 1000).toFixed(2) + 'km' : result.horizontalDistance + 'm';
this.handlerHeight.disLabel.text = '空间距离:' + distance;
this.handlerHeight.vLabel.text = '垂直高度:' + vHeight;
this.handlerHeight.hLabel.text = '水平距离:' + hDistance;
});
this.handlerArea.activeEvt.addEventListener(this.handle());
}
handle() {
return a => {
let body = $('body').removeClass('measureCur');
a && body.addClass('measureCur');
(this.viewer.enableCursorStyle = !a) || (this.viewer._element.style.cursor = '');
}
}
}
\ No newline at end of file
export default class flood {
constructor(viewer) {
this.positions2d = [];
this.handlerPolygon = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Polygon);
this.handlerPolygon.drawEvt.addEventListener(polygon => {
var array = [].concat(polygon.object.positions), positions = [];
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);
var h=cartographic.height;
if(positions.indexOf(longitude)===-1&&positions.indexOf(latitude)===-1){
positions.push(longitude);
positions.push(latitude);
positions.push(h);
this.positions2d.push(longitude);
this.positions2d.push(latitude);
this.positions2d.push(1000.0);
}
}
return positions;
});
}
initHyp() {
var hyp = new Cesium.HypsometricSetting();
//设置显示模式
hyp.DisplayMode = Cesium.HypsometricSettingEnum.DisplayMode.FACE;
//设置线颜色为红色
hyp._lineColor = new Cesium.Color(1.0, 0.0, 0.0, 1.0);
//设置最大/最小可见高度
hyp.MinVisibleValue = 0;
//设置颜色表的最大/最小key值,表示高度
hyp.ColorTableMinKey = 1;
hyp.ColorTableMaxKey = 9000;
//新建颜色表
var colorTable = new Cesium.ColorTable();
var height = 1;
//每隔200m向颜色表插入一个随机色
for(var i = 0; i<90; i++){
height += 200;
colorTable.insert(height, getRandomColor());
}
//返回随机颜色
function getRandomColor(){
return new Cesium.Color(Math.random(), Math.random(), Math.random());
}
hyp.ColorTable = colorTable;
hyp.Opacity = 0.8;
//等高线间隔为200m
hyp.LineInterval = 200.0;
return hyp;
}
floodCal(entities, positions2d, waterHeight, targetHeight) {
let entity = entities.add({
polygon : {
hierarchy : new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights(positions2d)),
perPositionHeight: true,
extrudedHeight: new Cesium.CallbackProperty(function(){
waterHeight+=20;
if(waterHeight>targetHeight){
waterHeight=targetHeight;//给个最大值
}
return waterHeight
}, false),
material: new Cesium.ImageMaterialProperty({
image: './images/waterNormals.jpg',
repeat : new Cesium.Cartesian2(1, 1),
transparent: true
})
}
});
}
floodParse(scene, positions2d, waterHeight, targetHeight) {
var River1 = new Cesium.Primitive({
geometryInstances : new Cesium.GeometryInstance({
geometry :new Cesium.PolygonGeometry({
polygonHierarchy : new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights(positions2d)),
extrudedHeight: targetHeight,
height: waterHeight,
vertexFormat : Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT
})
}),
appearance : new Cesium.EllipsoidSurfaceAppearance({
aboveGround : true,
material: new Cesium.Material({
fabric : {
type : 'Water',
uniforms : {
normalMap:'./images/waterNormals.jpg',
frequency: 100.0,
animationSpeed: 0.01,
amplitude: 10.0
}
}
})
}),
show : true
});
scene.primitives.add(River1);
}
}
\ No newline at end of file
export default {
map: undefined
}
\ No newline at end of file
import objectManage from './maputils';
export default class shadow {
constructor() {
this.shadowQuery = new Cesium.ShadowQueryPoints(objectManage.viewer.scene);
this.setCurrentTime();
this.init();
}
setCurrentTime() {
objectManage.viewer.clock.currentTime = Cesium.JulianDate.fromDate(new Date());
objectManage.viewer.clock.multiplier = 1;
objectManage.viewer.clock.shouldAnimate = true;
}
init() {
this.handlerPolygon = new Cesium.DrawHandler(objectManage.viewer, Cesium.DrawMode.Polygon, 0);
this.tooltip = this.createTooltip(document.body);
this.points = [];
this.handlerPolygon.activeEvt.addEventListener(a => {
let body = $('body').removeClass('measureCur');
a && body.addClass('measureCur');
(objectManage.viewer.enableCursorStyle = !a) || (objectManage.viewer._element.style.cursor = '');
});
this.handlerPolygon.movingEvt.addEventListener(windowPosition => {
this.handlerPolygon.isDrawing && this.tooltip.showAt(windowPosition, '<p>绘制阴影分析区域(右键结束绘制)</p>');
});
this.handlerPolygon.drawEvt.addEventListener(result => {
this.tooltip.setVisible(false);
this.points.length = 0;
var polygon = result.object;
if(!polygon) return;
polygon.show = false;
this.handlerPolygon.polyline.show = false;
var positions = [].concat(polygon.positions);
positions = Cesium.arrayRemoveDuplicates(positions, Cesium.Cartesian3.equalsEpsilon);
//遍历多边形,取出所有点
for(var i = 0, len = positions.length; i < len; i++) {
//转化为经纬度,并加入至临时数组
var cartographic = Cesium.Cartographic.fromCartesian(polygon.positions[i]);
var longitude = Cesium.Math.toDegrees(cartographic.longitude);
var latitude = Cesium.Math.toDegrees(cartographic.latitude);
this.points.push(longitude);
this.points.push(latitude);
}
//设置分析对象的开始结束时间
// var dateValue = $("#selDate").val();
var startTime = new Date();
startTime.setHours(8);
this.shadowQuery.startTime = Cesium.JulianDate.fromDate(startTime);
var endTime = new Date();
endTime.setHours(22);
this.shadowQuery.endTime = Cesium.JulianDate.fromDate(endTime);
this.setCurrentTime();
this.shadowQuery.spacing = 10;
this.shadowQuery.timeInterval = 60;
//设置分析区域、底部高程和拉伸高度
var bh = 20, eh = 20;
this.shadowQuery.qureyRegion({
position : this.points,
bottom : bh,
extend : eh
});
});
}
createTooltip(frameDiv) {
var Tooltip = function(frameDiv) {
var div = document.createElement('DIV');
div.className = "twipsy right";
var arrow = document.createElement('DIV');
arrow.className = "twipsy-arrow";
div.appendChild(arrow);
var title = document.createElement('DIV');
title.className = "twipsy-inner";
div.appendChild(title);
this._div = div;
this._title = title;
this.message = '';
frameDiv.appendChild(div);
var that = this;
div.onmousemove = function(evt){
that.showAt({
x : evt.clientX,
y : evt.clientY
}, that.message);
};
};
Tooltip.prototype.setVisible = function(visible) {
this._div.style.display = visible ? 'block' : 'none';
};
Tooltip.prototype.showAt = function(position, message) {
if(position && message) {
this.setVisible(true);
this._title.innerHTML = message;
this._div.style.left = position.x + 10 + "px";
this._div.style.top = (position.y - this._div.clientHeight / 2) + "px";
this.message = message;
}
};
return new Tooltip(frameDiv);
}
shadowAnalysis() {
this.handlerPolygon.deactivate();
this.handlerPolygon.activate();
}
sunlight() {
var startTime = new Date(), endTime = new Date(), shour = 8, ehour = 22, nTimer = 0.0;
if(shour > ehour) return;
this.shadowQuery.qureyRegion({
position : [0, 0],
bottom : 0,
extend : 0
});
var nIntervId = setInterval(function() {
if(shour < ehour) {
startTime.setHours(shour);
startTime.setMinutes(nTimer);
objectManage.viewer.clock.currentTime = Cesium.JulianDate.fromDate(startTime);
nTimer += 10.0;
if(nTimer > 60.0){
shour += 1.0;
nTimer = 0.0;
}
}else {
clearInterval(nIntervId);
this.shadowQuery.qureyRegion({
position : points,
bottom : 20,
extend : 20
});
}
}, 20);
}
clear() {
this.handlerPolygon.deactivate();
this.handlerPolygon.polygon.show = false;
this.handlerPolygon.polyline.show = false;
// $('#shadowRadioBox').css('display', 'none');
objectManage.viewer.entities.removeAll();
this.shadowQuery.qureyRegion({
position : [0, 0],
bottom : 0,
extend : 0
});
}
}
\ No newline at end of file
export default class viewpoint {
constructor(viewer) {
this.viewer = viewer;
this.sightline = new Cesium.Sightline(viewer.scene);
this.sightline.couldRemove = false;
this.sightline.build();
this.handlerPoint = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Point);
this.handlerPoint.drawEvt.addEventListener(result => {
var point = result.object;
point.show = false;
var position = result.object.position;
//将获取的点的位置转化成经纬度
var cartographic = Cesium.Cartographic.fromCartesian(position);
var longitude = Cesium.Math.toDegrees(cartographic.longitude);
var latitude = Cesium.Math.toDegrees(cartographic.latitude);
var height = cartographic.height;
if(viewer.scene.viewFlag) {
this.sightline.viewPosition = [longitude, latitude, height];
viewer.scene.viewFlag = false;
this.addPoint();
}else {
this.sightline.addTargetPoint({
position : [longitude, latitude, height],
name : "point" + new Date()
});
this.sightline.couldRemove = true;
}
});
}
chooseView() {
if(this.handlerPoint.active) return;
this.viewer.scene.viewFlag = true;
this.viewer.entities.removeAll();
this.sightline.removeAllTargetPoint();
this.handlerPoint.activate();
}
addPoint() {
this.viewer.scene.viewFlag = false;
this.handlerPoint.activate();
}
}
\ No newline at end of file
export default class visual {
constructor(viewer) {
this.viewer = viewer;
viewer.scene.viewFlag = true;
this.pointHandler = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Point);
this.viewshed3D = new Cesium.ViewShed3D(viewer.scene);
this.viewPosition;
this.viewModel = {
direction: 1.0,
pitch: 1.0,
distance: 1.0,
verticalFov: 1.0,
horizontalFov: 1.0,
visibleAreaColor: '#ffffffff',
invisibleAreaColor: '#ffffffff'
};
Cesium.knockout.track(this.viewModel);
this.init(viewer.scene);
}
init(scene) {
this.handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
this.handler.setInputAction(e => {
// 若此标记为false,则激活对可视域分析对象的操作
if (!scene.viewFlag) {
//获取鼠标屏幕坐标,并将其转化成笛卡尔坐标
var position = e.endPosition;
var last = scene.pickPosition(position);
//计算该点与视口位置点坐标的距离
var distance = Cesium.Cartesian3.distance(this.viewPosition, last);
if (distance > 0) {
// 将鼠标当前点坐标转化成经纬度
var cartographic = Cesium.Cartographic.fromCartesian(last);
var longitude = Cesium.Math.toDegrees(cartographic.longitude);
var latitude = Cesium.Math.toDegrees(cartographic.latitude);
var height = cartographic.height;
// 通过该点设置可视域分析对象的距离及方向
this.viewshed3D.setDistDirByPoint([longitude, latitude, height]);
}
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
this.handler.setInputAction(e => {
//鼠标右键事件回调,不再执行鼠标移动事件中对可视域的操作
scene.viewFlag = true;
Object.assign(this.viewModel, {
direction: this.viewshed3D.direction, pitch: this.viewshed3D.pitch, distance: this.viewshed3D.distance,
horizontalFov: this.viewshed3D.horizontalFov, verticalFov: this.viewshed3D.verticalFov
})
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
this.pointHandler.drawEvt.addEventListener(result => {
var point = result.object;
var position = point.position;
viewPosition = position;
// 将获取的点的位置转化成经纬度
var cartographic = Cesium.Cartographic.fromCartesian(position);
var longitude = Cesium.Math.toDegrees(cartographic.longitude);
var latitude = Cesium.Math.toDegrees(cartographic.latitude);
var height = cartographic.height + 1.8;
point.position = Cesium.Cartesian3.fromDegrees(longitude, latitude, height);
if (this.viewer.scene.viewFlag) {
// 设置视口位置
this.viewshed3D.viewPosition = [longitude, latitude, height];
this.viewshed3D.build();
// 将标记置为false以激活鼠标移动回调里面的设置可视域操作
this.viewer.scene.viewFlag = false;
}
});
}
chooseView() {
if (this.pointHandler.active) return;
//先清除之前的可视域分析
this.viewer.entities.removeAll();
this.viewshed3D.distance = 0.1;
this.viewer.scene.viewFlag = true;
//激活绘制点类
this.pointHandler.activate();
}
}
\ No newline at end of file