|
1
|
|
|
/** |
|
2
|
|
|
* This javascript is part of FlightAirmap. |
|
3
|
|
|
* |
|
4
|
|
|
* Copyright (c) Ycarus (Yannick Chabanois) <[email protected]> |
|
5
|
|
|
* Licensed under AGPL license. |
|
6
|
|
|
* For more information see: https://www.flightairmap.com/ |
|
7
|
|
|
*/ |
|
8
|
|
|
/** global: Cesium */ |
|
9
|
|
|
/** global: viewer */ |
|
10
|
|
|
/** global: A */ |
|
11
|
|
|
|
|
12
|
|
|
function clickDisplayWeather(cb) { |
|
13
|
|
|
createCookie('show_Weather',cb.checked,2); |
|
14
|
|
|
// window.location.reload(); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
var cloudscenter; |
|
18
|
|
|
function delete_clouds() { |
|
19
|
|
|
for (var i =0; i < viewer.dataSources.length; i++) { |
|
20
|
|
|
if (viewer.dataSources.get(i).name == 'clouds') { |
|
21
|
|
|
viewer.dataSources.remove(viewer.dataSources.get(i),true); |
|
22
|
|
|
break; |
|
23
|
|
|
} |
|
24
|
|
|
} |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
function create_clouds(cposition) { |
|
28
|
|
|
//console.log('Create clouds'); |
|
29
|
|
|
cloudscenter = cposition; |
|
30
|
|
|
$.getJSON('/weather-json.php?latitude='+Cesium.Math.toDegrees(cposition.latitude)+'&longitude='+Cesium.Math.toDegrees(cposition.longitude),function(data) { |
|
31
|
|
|
//delete_clouds(); |
|
32
|
|
|
var coord = A.EclCoord.fromWgs84(Cesium.Math.toDegrees(cposition.latitude),Cesium.Math.toDegrees(cposition.longitude),0); |
|
33
|
|
|
var tp = A.Solar.topocentricPosition(new A.JulianDay(new Date(viewer.clock.currentTime.toString())),coord,true); |
|
34
|
|
|
var tpn = A.Solar.topocentricPosition(new A.JulianDay(new Date(Cesium.JulianDate.addSeconds(viewer.clock.currentTime,60,new Cesium.JulianDate()).toString())),coord,true); |
|
35
|
|
|
//console.log(tp.hz); |
|
36
|
|
|
//console.log(tpn.hz); |
|
37
|
|
|
var ctime = Cesium.JulianDate.toGregorianDate(viewer.clock.currentTime); |
|
38
|
|
|
var chour = ctime['hour']; |
|
39
|
|
|
var cminute = ctime['minute']; |
|
40
|
|
|
var datasource = new Cesium.CustomDataSource('clouds'); |
|
41
|
|
|
var clouds = {ci: ['cirrocumulus1.glb','cirrocumulus2.glb','cirrocumulus3.glb','cirrocumulus4.glb','cirrocumulus5.glb','cirrocumulus6.glb','cirrocumulus7.glb','cirrocumulus8.glb','cirrocumulus9.glb']}; |
|
42
|
|
|
//ac: ['altocumulus1.glb','altocumulus2.glb','altocumulus3.glb','altocumulus4.glb','altocumulus5.glb','altocumulus6.glb'], |
|
43
|
|
|
//ns: ['nimbus1.glb','nimbus_sl1.glb','nimbus_sl2.glb','nimbus_sl3.glb','nimbus_sl4.glb','nimbus_sl5.glb','nimbus_sl6.glb']}; |
|
44
|
|
|
//st: ['stratus1.glb','stratus2.glb','stratus3.glb','stratus4.glb','stratus5.glb']}; |
|
45
|
|
|
// st need to follow camera |
|
46
|
|
|
var cloudsb = {ac: ['altocumulus1.png','altocumulus2.png','altocumulus3.png','altocumulus4.png','altocumulus5.png','altocumulus6.png','altocumulus7.png','altocumulus8.png','altocumulus9.png'], |
|
47
|
|
|
st: ['stratus1.png','stratus2.png','stratus3.png','stratus4.png','stratus5.png','stratus6.png'], |
|
48
|
|
|
sc: ['congestus1.png','congestus2.png','congestus3.png'], |
|
49
|
|
|
cu: ['cumulus1.png','cumulus2.png','cumulus3.png','cumulus4.png','cumulus5.png','cumulus6.png','cumulus7.png','cumulus8.png','cumulus9.png']}; |
|
50
|
|
|
for (var i = 0; i < data.length; i++) { |
|
51
|
|
|
var height = data[i]['alt']; |
|
52
|
|
|
var cov = data[i]['cov']; |
|
53
|
|
|
var cloud = clouds[data[i]['type']]; |
|
54
|
|
|
//var cloud = clouds['ci']; |
|
55
|
|
|
//var cloudb = cloudsb['fg']; |
|
56
|
|
|
var cloudb = cloudsb[data[i]['type']]; |
|
57
|
|
|
var rh = data[i]['rh']; |
|
58
|
|
|
/* |
|
59
|
|
|
var timecolors = [[100,100,100],[255,150,100],[255,255,255],[255,255,255],[255,255,255],[255,255,255],[255,150,100],[100,100,100],[100,100,100],[100,100,100],[100,100,100]]; |
|
60
|
|
|
var timecolorsstep = chour/24*10; |
|
61
|
|
|
if (Math.round(timecolorsstep) > Math.ceil(timecolorsstep)) { |
|
62
|
|
|
console.log(Math.ceil(timecolorsstep)); |
|
63
|
|
|
var prevcolor = timecolors[Math.ceil(timecolorsstep)]; |
|
64
|
|
|
var nextcolor = timecolors[Math.round(timecolorsstep)]; |
|
65
|
|
|
} else { |
|
66
|
|
|
if (Math.round(timecolorsstep) == 0) { |
|
67
|
|
|
var prevcolor = timecolors[0]; |
|
68
|
|
|
} else { |
|
69
|
|
|
var prevcolor = timecolors[Math.round(timecolorsstep)-1]; |
|
70
|
|
|
} |
|
71
|
|
|
var nextcolor = timecolors[Math.round(timecolorsstep)]; |
|
72
|
|
|
} |
|
73
|
|
|
var currentcolor = getColor(prevcolor,nextcolor,3*60,(timecolorsstep%3)*60+cminute); |
|
74
|
|
|
var color = new Cesium.Color.multiply(new Cesium.Color(rh/100,rh/100,rh/100,1),new Cesium.Color.fromBytes(currentcolor['r'],currentcolor['v'],currentcolor['b'],255), new Cesium.Color()); |
|
75
|
|
|
*/ |
|
76
|
|
|
//var color = new Cesium.Color(rh/100,rh/100,rh/100,1); |
|
77
|
|
|
|
|
78
|
|
|
// 17:17 => az : 1.008 - alt : -0.021 |
|
79
|
|
|
|
|
80
|
|
|
var prevcolor = [255,255,255]; |
|
|
|
|
|
|
81
|
|
|
if (tp.hz.alt < 0) { |
|
82
|
|
|
prevcolor = [100,100,100]; |
|
83
|
|
|
} else if (tp.hz.alt < 0.172) { |
|
84
|
|
|
prevcolor = [255,150,100]; |
|
85
|
|
|
} else if (tp.hz.alt < Math.PI/2) { |
|
86
|
|
|
prevcolor = [255,255,255]; |
|
87
|
|
|
} else if (tp.hz.alt < 2.9) { |
|
88
|
|
|
prevcolor = [255,255,255]; |
|
89
|
|
|
} else if (tp.hz.alt < 3.0) { |
|
90
|
|
|
prevcolor = [255,150,100]; |
|
91
|
|
|
} else { |
|
92
|
|
|
prevcolor = [100,100,100]; |
|
93
|
|
|
} |
|
94
|
|
|
var nextcolor = [255,255,255]; |
|
|
|
|
|
|
95
|
|
|
if (tpn.hz.alt < 0) { |
|
96
|
|
|
nextcolor = [100,100,100]; |
|
97
|
|
|
} else if (tpn.hz.alt < 0.172) { |
|
98
|
|
|
nextcolor = [255,150,100]; |
|
99
|
|
|
} else if (tpn.hz.alt < Math.PI/2) { |
|
100
|
|
|
nextcolor = [255,255,255]; |
|
101
|
|
|
} else if (tpn.hz.alt < 2.9) { |
|
102
|
|
|
nextcolor = [255,255,255]; |
|
103
|
|
|
} else if (tpn.hz.alt < 3.0) { |
|
104
|
|
|
nextcolor = [255,150,100]; |
|
105
|
|
|
} else { |
|
106
|
|
|
nextcolor = [100,100,100]; |
|
107
|
|
|
} |
|
108
|
|
|
var timecolorsstep = chour/24*10; |
|
109
|
|
|
var currentcolor = getColor(prevcolor,nextcolor,3*60,(timecolorsstep%3)*60+cminute); |
|
110
|
|
|
var color = new Cesium.Color.multiply(new Cesium.Color(rh/100,rh/100,rh/100,1),new Cesium.Color.fromBytes(currentcolor['r'],currentcolor['v'],currentcolor['b'],255), new Cesium.Color()); |
|
111
|
|
|
|
|
112
|
|
|
if (typeof cloudb != 'undefined') { |
|
113
|
|
|
for (j = 0; j < 2000*cov; j++) { |
|
|
|
|
|
|
114
|
|
|
var cloudcoord = generateRandomPoint(Cesium.Math.toDegrees(cposition.latitude),Cesium.Math.toDegrees(cposition.longitude), height,240,70000); |
|
115
|
|
|
var position = Cesium.Cartesian3.fromDegrees(cloudcoord['longitude'],cloudcoord['latitude'],cloudcoord['alt']); |
|
116
|
|
|
var heading = Cesium.Math.toRadians(135); |
|
117
|
|
|
var pitch = 0; |
|
118
|
|
|
var roll = 0; |
|
119
|
|
|
var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll); |
|
120
|
|
|
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr); |
|
121
|
|
|
var urlb = '/images/weather/clouds/'+cloudb[Math.floor((Math.random() * cloudb.length))]; |
|
122
|
|
|
var entity = datasource.entities.add({ |
|
|
|
|
|
|
123
|
|
|
name : url, |
|
|
|
|
|
|
124
|
|
|
position : position, |
|
125
|
|
|
orientation : orientation, |
|
126
|
|
|
billboard: { |
|
127
|
|
|
image : urlb, |
|
128
|
|
|
sizeInMeters: true, |
|
129
|
|
|
scale: Math.random()*10.0, |
|
130
|
|
|
horizontalOrigin: Cesium.HorizontalOrigin.CENTER, |
|
131
|
|
|
verticalOrigin: Cesium.VerticalOrigin.BOTTOM, |
|
132
|
|
|
eyeOffset: new Cesium.Cartesian3(0,6,0), |
|
133
|
|
|
heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND, |
|
134
|
|
|
//fillColor: Cesium.Color.fromCssColorString("#ffc107"), |
|
135
|
|
|
//translucencyByDistance: new Cesium.NearFarScalar(200,.8,5E4,.2) |
|
136
|
|
|
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0,70000.0), |
|
137
|
|
|
translucencyByDistance: new Cesium.NearFarScalar(1E5/2,.9,1E5,.3), |
|
138
|
|
|
color: color, |
|
139
|
|
|
opacity: .9 |
|
140
|
|
|
} |
|
141
|
|
|
}); |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
//console.log(data[i]); |
|
145
|
|
|
//console.log(cloud); |
|
146
|
|
|
if (typeof cloud != 'undefined') { |
|
147
|
|
|
//console.log('models'); |
|
148
|
|
|
for (j = 0; j < 1000*cov; j++) { |
|
149
|
|
|
var cloudcoord = generateRandomPoint(Cesium.Math.toDegrees(cposition.latitude),Cesium.Math.toDegrees(cposition.longitude), height,240,70000); |
|
|
|
|
|
|
150
|
|
|
//console.log(cloudcoord); |
|
151
|
|
|
var position = Cesium.Cartesian3.fromDegrees(cloudcoord['longitude'],cloudcoord['latitude'],cloudcoord['alt']); |
|
|
|
|
|
|
152
|
|
|
if (data[i]['type'] == 'st') { |
|
153
|
|
|
var heading = camera.heading; |
|
|
|
|
|
|
154
|
|
|
} else { |
|
155
|
|
|
var heading = Cesium.Math.toRadians(135); |
|
|
|
|
|
|
156
|
|
|
} |
|
157
|
|
|
var pitch = 0; |
|
|
|
|
|
|
158
|
|
|
var roll = 0; |
|
|
|
|
|
|
159
|
|
|
var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll); |
|
|
|
|
|
|
160
|
|
|
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr); |
|
|
|
|
|
|
161
|
|
|
var url = '/models/gltf2/weather/'+cloud[Math.floor((Math.random() * cloud.length))]; |
|
162
|
|
|
var entity = datasource.entities.add({ |
|
|
|
|
|
|
163
|
|
|
name : url, |
|
164
|
|
|
position : position, |
|
165
|
|
|
orientation : orientation, |
|
166
|
|
|
model : { |
|
167
|
|
|
uri : url, |
|
168
|
|
|
minimumPixelSize : 1, |
|
169
|
|
|
maximumScale : 20000, |
|
170
|
|
|
heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND, |
|
171
|
|
|
color: color, |
|
172
|
|
|
colorBlendMode: Cesium.ColorBlendMode.MIX, |
|
173
|
|
|
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0,70000.0), |
|
174
|
|
|
allowPicking: false |
|
175
|
|
|
} |
|
176
|
|
|
}); |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
viewer.dataSources.add(datasource); |
|
181
|
|
|
}); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
|
|
185
|
|
|
var handler_all = new Cesium.ScreenSpaceEventHandler(viewer.canvas); |
|
186
|
|
|
handler_all.setInputAction(function(click) { |
|
187
|
|
|
var pickedObject = viewer.scene.pick(click.position); |
|
188
|
|
|
if (Cesium.defined(pickedObject) && getCookie('show_Weather') == 'true') { |
|
189
|
|
|
delete_clouds(); |
|
190
|
|
|
var cposition = pickedObject.id.position.getValue(viewer.clock.currentTime); |
|
191
|
|
|
create_clouds(viewer.scene.globe.ellipsoid.cartesianToCartographic(cposition)); |
|
192
|
|
|
} |
|
193
|
|
|
}, Cesium.ScreenSpaceEventType.LEFT_CLICK); |
|
194
|
|
|
|
|
195
|
|
|
|
|
196
|
|
|
viewer.clock.onTick.addEventListener(function(clock) { |
|
197
|
|
|
if (getCookie('show_Weather') == 'true') { |
|
198
|
|
|
if (Cesium.defined(viewer.trackedEntity)) { |
|
199
|
|
|
if (typeof cloudscenter == 'undefined') { |
|
200
|
|
|
var cposition = viewer.trackedEntity.position.getValue(viewer.clock.currentTime); |
|
201
|
|
|
create_clouds(viewer.scene.globe.ellipsoid.cartesianToCartographic(cposition)); |
|
202
|
|
|
} else { |
|
203
|
|
|
var cposition = viewer.trackedEntity.position.getValue(viewer.clock.currentTime); |
|
|
|
|
|
|
204
|
|
|
var ellipsoidGeodesic = new Cesium.EllipsoidGeodesic(Cesium.Cartographic.fromCartesian(cposition),cloudscenter); |
|
205
|
|
|
var distance = ellipsoidGeodesic.surfaceDistance; |
|
206
|
|
|
if (distance > 25000) { |
|
207
|
|
|
create_clouds(viewer.scene.globe.ellipsoid.cartesianToCartographic(cposition)); |
|
208
|
|
|
} |
|
209
|
|
|
} |
|
210
|
|
|
} else { |
|
211
|
|
|
delete_clouds(); |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
}); |
|
215
|
|
|
|
|
216
|
|
|
if (getCookie('weather_fire') == 'true') loadFire(getCookie('weather_fire')); |
|
|
|
|
|
|
217
|
|
|
var fireLayer; |
|
218
|
|
|
function clickFire(cb) { |
|
219
|
|
|
loadFire(cb.checked); |
|
220
|
|
|
} |
|
221
|
|
|
function loadFire(val) { |
|
222
|
|
|
var fire = getCookie('weather_fire'); |
|
223
|
|
|
if (fire == 'true' && val != 'true') { |
|
224
|
|
|
viewer.imageryLayers.remove(fireLayer,true); |
|
225
|
|
|
delCookie('weather_fire'); |
|
226
|
|
|
} else { |
|
227
|
|
|
createCookie('weather_fire',val,999); |
|
228
|
|
|
var fireProvider = new Cesium.WebMapServiceImageryProvider({ |
|
229
|
|
|
url : corsproxy+'https://firms.modaps.eosdis.nasa.gov/wms/viirs', |
|
|
|
|
|
|
230
|
|
|
layers : 'NASA FIRMS', |
|
231
|
|
|
parameters : { |
|
232
|
|
|
transparent : true, |
|
233
|
|
|
format : 'image/png' |
|
234
|
|
|
} |
|
235
|
|
|
}); |
|
236
|
|
|
fireLayer = new Cesium.ImageryLayer(fireProvider); |
|
237
|
|
|
viewer.imageryLayers.add(fireLayer); |
|
238
|
|
|
} |
|
239
|
|
|
} |