App.js 15.9 KB
Newer Older
Rushikesh Padsala's avatar
Rushikesh Padsala committed
1
2
3
4
5
6
7
8
9
10
11
12
13
     Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJiNWFjZDJiMy1hYzk3LTQ2YWUtYWVjYi01MDk1OGVlZGI0NTgiLCJpZCI6MTEwNzEsInNjb3BlcyI6WyJhc3IiLCJnYyJdLCJpYXQiOjE1NTgwMjE1Mjh9.lF6TGAJrX3qMGBt5egdAA7SJYNnaYX17mhURwGg_Kbg';

    //////////////////////////////////////////////////////////////////////////
    // Creating the Viewer
    //////////////////////////////////////////////////////////////////////////

     var viewer = new Cesium.Viewer('cesiumContainer', {
         scene3DOnly: true,
         selectionIndicator: false,
		 timeline: false,
		 animation: false,
		 shadow: false,
		 // // Set default basemap
14
15
16
17
		 imageryProvider : new Cesium.BingMapsImageryProvider({
                           url : 'https://dev.virtualearth.net',
						   key : 'ArfoC16LZfs9KzyU-OJyXSqVI6a9-Swv-cq7oO6e2bWYqZOS8M77coukVzeYDyLA',
						   mapStyle : Cesium.BingMapsStyle.AERIAL
Rushikesh Padsala's avatar
Rushikesh Padsala committed
18
19
20
21
22
                           }),
		 baseLayerPicker: true
		 
     });
     viewer.clock.shouldAnimate = false;
23
     viewer.scene.globe.enableLighting = false;
Rushikesh Padsala's avatar
Rushikesh Padsala committed
24
25
26
27
28
29
30
31
32
     viewer.clock.startTime = Cesium.JulianDate.fromIso8601("2019-09-20T13:00:00Z");
     viewer.clock.stopTime = Cesium.JulianDate.fromIso8601("2019-09-20T13:20:00Z");
     viewer.clock.currentTime = Cesium.JulianDate.fromIso8601("2019-09-20T13:00:00Z");
	 document.getElementById("legend").style.display = "none"; //defining legends hidden by default
	 
    //////////////////////////////////////////////////////////////////////////
    // Configuring the camera
    //////////////////////////////////////////////////////////////////////////
    // // Create an initial camera view
33
34
   var initialPosition = Cesium.Cartesian3.fromDegrees(-73.993092, 40.655215, 600);
     var initialOrientation = new Cesium.HeadingPitchRoll.fromDegrees(354, -20, 0);
Rushikesh Padsala's avatar
Rushikesh Padsala committed
35
     var homeCameraView = {
36
37
38
39
40
41
         destination : initialPosition,
         orientation : {
            heading : initialOrientation.heading,
            pitch : initialOrientation.pitch,
            roll : initialOrientation.roll
         }
Rushikesh Padsala's avatar
Rushikesh Padsala committed
42
43
44
45
46
47
48
49
50
      };
    // // Set the initial view
     viewer.scene.camera.setView(homeCameraView);
	// set home button to initial view 
	 
	 viewer.homeButton.viewModel.command.beforeExecute.addEventListener(function (e) {
        e.cancel = true;
         viewer.scene.camera.flyTo(homeCameraView);
     });
51
52
53
54
55
56
57
58
59
60
61
62
	viewer.camera.changed.addEventListener(function() {

  var deg = Math.round( Cesium.Math.toDegrees(viewer.camera.heading))
  console.log('Heading:', deg)

  var deg = Math.round( Cesium.Math.toDegrees(viewer.camera.pitch))
  console.log('Pitch:', deg)
  
  var deg = Math.round( Cesium.Math.toDegrees(viewer.camera.roll))
  console.log('Roll:', deg)
  
});
Rushikesh Padsala's avatar
Rushikesh Padsala committed
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
    //////////////////////////////////////////////////////////////////////////
    // Loading GeoJSON with polygon outline - strokewidth is an issue with windows
    //////////////////////////////////////////////////////////////////////////
    // var jsonOptions = {
       // stroke: Cesium.Color.DARKRED,
        //fill: Cesium.Color.WHITESMOKE.withAlpha(0),
       // strokeWidth: 5         
    // };
	// var gowanusboundary = Cesium.GeoJsonDataSource.load('./Source/Data/Gowanus.geojson',jsonOptions);
    // viewer.dataSources.add(gowanusboundary);

    //////////////////////////////////////////////////////////////////////////
    // Load 3D Tileset
    //////////////////////////////////////////////////////////////////////////

    var currentgowanus = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({url: './Source/Data/Bldg/Current_Gowanus/tileset.json'}));
	var bau2050gowanus = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({url: './Source/Data/Bldg/BAU2050_Gowanus/tileset.json'}));
	var bp2050gowanus = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({url: './Source/Data/Bldg/BP2050_Gowanus/tileset.json'}));
	currentgowanus.show = true;
	bau2050gowanus.show = false;
	bp2050gowanus.show = false;
	//currentgowanus.style = new Cesium.Cesium3DTileStyle({
	//color : 'color("white")'});
	//bau2050gowanus.style = new Cesium.Cesium3DTileStyle({
	//color : 'color("BLACK")'});
	var selectscenario = document.getElementById('selectscenario');
    function setscenario() {
	 var selectedscenario = selectscenario.options[selectscenario.selectedIndex].value;
	 if (selectedscenario === 'current') {currentgowanus.show = true;
	                                      bau2050gowanus.show = false;
                                          bp2050gowanus.show = false;} 
	 else if (selectedscenario === 'bau') {currentgowanus.show = false;
	                                      bau2050gowanus.show = true; 
										 bp2050gowanus.show = false;}
	else if (selectedscenario === 'bp') {currentgowanus.show = false;
	                                     bau2050gowanus.show = false; 
										  bp2050gowanus.show = true;}									  
	 }
	selectscenario.addEventListener('change', setscenario);
    //////////////////////////////////////////////////////////////////////////
    // Style 3D Tileset
    //////////////////////////////////////////////////////////////////////////

     var defaultstyle = new Cesium.Cesium3DTileStyle({
         color : "color('WHITE')",
		  show: true
     });
	 
	 var energydemandstyle = new Cesium.Cesium3DTileStyle({
         color : {
            conditions : [
					["(${Specific_space_heating_demand} === 0)", "color('#000000')"],
					["(${Specific_space_heating_demand} > 0)  && (${Specific_space_heating_demand} < 60)", "color('#33ACFF')"],
                    ["(${Specific_space_heating_demand} >= 60) && (${Specific_space_heating_demand} < 120)", "color('#2AFF00')"],
                    ["(${Specific_space_heating_demand} >= 120) && (${Specific_space_heating_demand} < 170)", "color('#FFFF00')"],
                    ["(${Specific_space_heating_demand} >= 170) && (${Specific_space_heating_demand} < 230)", "color('#FFA200')"],
                    ["(${Specific_space_heating_demand} >= 230)", "color('#FF0000')"]
             ]
         },
		 show: true
     });
	 	
	 var colorstyle1 = document.getElementById('3dbuildings');
	 var colorstyle2 = document.getElementById('heatdemand');
     function set3DColorStyle() {
        if (colorstyle1.checked) {
             currentgowanus.style = defaultstyle;
			 bau2050gowanus.style = defaultstyle;
			 bp2050gowanus.style = defaultstyle;
			 document.getElementById("legend").style.display = "none";
		      } 
		else if (colorstyle2.checked) {
             currentgowanus.style = energydemandstyle;
			 bau2050gowanus.style = energydemandstyle;
			 bp2050gowanus.style = energydemandstyle;
			 document.getElementById("legend").style.display = "block";
		      }
        }
	 
	 colorstyle1.addEventListener('change', set3DColorStyle);
     colorstyle2.addEventListener('change', set3DColorStyle);

    //////////////////////////////////////////////////////////////////////////
    // Custom mouse interaction for highlighting and selecting
    //////////////////////////////////////////////////////////////////////////
//Style the overlay
var nameOverlay = document.createElement('div');
viewer.container.appendChild(nameOverlay);
nameOverlay.className = 'backdrop';
nameOverlay.style.display = 'none';
nameOverlay.style.position = 'absolute';
nameOverlay.style.bottom = '0';
nameOverlay.style.left = '0';
nameOverlay.style['pointer-events'] = 'none';
nameOverlay.style.padding = '4px';
nameOverlay.style.backgroundColor = 'black';
nameOverlay.style.fontFamily = 'Fira Sans, sans-serif';

//Selecting a Building
var Pickers_3DTile_Activated = true;
// Information about the currently highlighted feature
function active3DTilePicker() {
    var highlighted = {
        feature: undefined,
        originalColor: new Cesium.Color()
    };
    // Information about the currently selected feature
    var selected = {
        feature: undefined,
        originalColor: new Cesium.Color()
    };

    // An entity object which will hold info about the currently selected feature for infobox display
    var selectedEntity = new Cesium.Entity();

    // Get default left click handler for when a feature is not picked on left click
    var clickHandler = viewer.screenSpaceEventHandler.getInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
    // Color a feature yellow on hover.
    viewer.screenSpaceEventHandler.setInputAction(function onMouseMove(movement) {
        if (Pickers_3DTile_Activated) {
            // If a feature was previously highlighted, undo the highlight
            if (Cesium.defined(highlighted.feature)) {
                highlighted.feature.color = highlighted.originalColor;
                highlighted.feature = undefined;
            }
            // Pick a new feature
            var picked3DtileFeature = viewer.scene.pick(movement.endPosition);
            if (!Cesium.defined(picked3DtileFeature)) {
                nameOverlay.style.display = 'none';
                return;
            }
            // A feature was picked, so show it's overlay content
            nameOverlay.style.display = 'block';
            nameOverlay.style.bottom = viewer.canvas.clientHeight - movement.endPosition.y + 'px';
            nameOverlay.style.left = movement.endPosition.x + 'px';
            var name = picked3DtileFeature.getProperty('PrimaryUsageZoneType');

            if (!Cesium.defined(name)) {
                name = picked3DtileFeature.getProperty('PrimaryUsageZoneType');
            }
            nameOverlay.textContent = name;
            // Highlight the feature if it's not already selected.
            if (picked3DtileFeature !== selected.feature) {
                highlighted.feature = picked3DtileFeature;
                Cesium.Color.clone(picked3DtileFeature.color, highlighted.originalColor);
                picked3DtileFeature.color = Cesium.Color.GREY;
            }
        }
    }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

    // Color a feature on selection and show metadata in the InfoBox.
    viewer.screenSpaceEventHandler.setInputAction(function onLeftClick(movement) {

        if (Pickers_3DTile_Activated) {
            // If a feature was previously selected, undo the highlight
            if (Cesium.defined(selected.feature)) {
                selected.feature.color = selected.originalColor;
                selected.feature = undefined;
                $("#chart").html("");
                var options = null;
            }
            // Pick a new feature
            var picked3DtileFeature = viewer.scene.pick(movement.position);
            if (!Cesium.defined(picked3DtileFeature)) {
                clickHandler(movement);
                return;
            }
            // Select the feature if it's not already selected
            if (selected.feature === picked3DtileFeature) {
                return;
            }
            selected.feature = picked3DtileFeature;
            // Save the selected feature's original color
            if (picked3DtileFeature === highlighted.feature) {
                Cesium.Color.clone(highlighted.originalColor, selected.originalColor);
                highlighted.feature = undefined;
            } else {
                Cesium.Color.clone(picked3DtileFeature.color, selected.originalColor);
            }
            // Highlight newly selected feature
            picked3DtileFeature.color = Cesium.Color.AQUA;
            // Set feature infobox description
            var featureName = "Net Zero Gowanus 3D Viewer";
            selectedEntity.name = featureName;
            selectedEntity.description = 'Loading <div class="cesium-infoBox-loading"></div>';

            viewer.selectedEntity = selectedEntity;
            selectedEntity.description =
                '<table class="cesium-infoBox-defaultTable"><tbody>' +
                '<tr><th>Building ID</th><td>' + picked3DtileFeature.getProperty('GMLId') + '</td></tr>' +
                '<tr><th>Year of Construction</th><td>' + picked3DtileFeature.getProperty('Year of construction') + '</td></tr>' +
                '<tr><th>PLUTO Code</th><td>' + picked3DtileFeature.getProperty('ALKIS code') + '</td></tr>' +
                '<tr><th>Primary Building Usage</th><td>' + picked3DtileFeature.getProperty('PrimaryUsageZoneType') + '</td></tr>' +
				'<tr><th>Building Footprint </th><td>' + picked3DtileFeature.getProperty('Footprint area') + ' ' + '' + '</td></tr>' +
                '<tr><th>Building Volume</th><td>' + picked3DtileFeature.getProperty('Gross volume') + ' ' + '' + '</td></tr>' +
				'<tr><th>Mean U-value</th><td>' + picked3DtileFeature.getProperty('Mean Uvalue') + ' ' + 'W/m²·K' +'</td></tr>' +
				'<tr><th>Sp. Domestic Hot Water Demand</th><td>' + picked3DtileFeature.getProperty('Specific domestic hot water demand') + ' ' + 'kWh/m²·a' + '</td></tr>' +
				'<tr><th>Sp. Heating Demand</th><td>' + picked3DtileFeature.getProperty('Specific_space_heating_demand') + ' ' + 'kWh/m²·a' + '</td></tr>' +
				'</tbody></table>';

            console.log(picked3DtileFeature.getProperty('Specific_space_heating_demand'));

            //Fill Table
            options = {
                chart: {
                    foreColor: '#fff',
                    //                    background: '#fff',
                    fontFamily: 'Fira Sans, sans-serif',
                    type: 'line',
                    animations: {
                        enabled: true,
                        easing: 'easeinout',
                        speed: 800,
                        animateGradually: {
                            enabled: true,
                            delay: 150
                        },
                        dynamicAnimation: {
                            enabled: true,
                            speed: 350
                        }
                    },
                    zoom: {
                        enabled: false
                    }
                },
                dataLabels: {
                    enabled: false
                },
                tooltip: {
                    y: {
                        formatter: function (value) {
                            return value + " kW/h"
                        }
                    }
                },
                stroke: {
                    curve: 'straight'
                },
                series: [{
                    name: 'Heating Demand',
                    data: [picked3DtileFeature.getProperty('January Heating Demand'), picked3DtileFeature.getProperty('February Heating Demand'), picked3DtileFeature.getProperty('March Heating Demand'), picked3DtileFeature.getProperty('April Heating Demand'), picked3DtileFeature.getProperty('May Heating Demand'), picked3DtileFeature.getProperty('June Heating Demand'), picked3DtileFeature.getProperty('July Heating Demand'), picked3DtileFeature.getProperty('August Heating Demand'), picked3DtileFeature.getProperty('September Heating Demand'), picked3DtileFeature.getProperty('October Heating Demand'), picked3DtileFeature.getProperty('November Heating Demand'), picked3DtileFeature.getProperty('December Heating Demand')]
            }],
                title: {
                    text: 'Monthly Heating Demand',
                    align: 'center'
                },
                xaxis: {
                    categories: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
                },
                yaxis: {
                    title: {
                        text: "Heating Demand (kW/h)"
                    }
                }
            }
            var chart = new ApexCharts(document.querySelector("#chart"), options);
			chart.render();
                       
        }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
}

active3DTilePicker();
    //////////////////////////////////////////////////////////////////////////
    // Custom mouse interaction for highlighting and selecting
    //////////////////////////////////////////////////////////////////////////

function showTable() {
    var x = document.getElementById("chartcontainer");
    if (x.style.visibility === "hidden") {
        x.style.visibility = "visible";

    } else {
        x.style.visibility = "hidden";
    }
}