shadow.js
5.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import objectManage from './maputils';
export default class shadow {
constructor() {
this.points = [];
this.shadowQuery = new Cesium.ShadowQueryPoints(objectManage.viewer.scene);
this.shadowQuery.build();
this.setCurrentTime();
this.init();
}
setCurrentTime() {
let d = new Date();
d.setHours(20)
objectManage.viewer.clock.currentTime = Cesium.JulianDate.fromDate(d);
objectManage.viewer.clock.multiplier = 1;
objectManage.viewer.clock.shouldAnimate = true;
}
init() {
this.tooltip = this.createTooltip(document.body);
this.handlerPolygon = new Cesium.DrawHandler(objectManage.viewer, Cesium.DrawMode.Polygon, 0);
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
});
}
}, 500);
}
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
});
}
remove() {
this.points = [];
this.shadowQuery.destroy();
this.shadowQuery = new Cesium.ShadowQueryPoints(objectManage.viewer.scene);
this.shadowQuery.build();
}
}