pvanalysis.js 6.47 KB
Newer Older
Krug's avatar
Krug committed
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
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
var removeSilhouette;

function pvAnalysis() {
 // HTML overlay for showing feature name on mouseover
 var nameOverlay = document.createElement("div");
 viewer.container.appendChild(nameOverlay);
 nameOverlay.setAttribute("id", "infotxt");
 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.color = "white";
 nameOverlay.style.font = "italic 12px sans-serif";
 // var for creating chart
 var chartDataPolygonID;
 var chartDataPVJan;
 var chartDataPVFeb;
 var chartDataPVMar;
 var chartDataPVApr;
 var chartDataPVMai;
 var chartDataPVJun;
 var chartDataPVJul;
 var chartDataPVAug;
 var chartDataPVSep;
 var chartDataPVOkt;
 var chartDataPVNov;
 var chartDataPVDez;
 var chartDataPVGEBID;
 var chartDataPVYield;
 // 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
 clickHandler = viewer.screenSpaceEventHandler.getInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
 // Silhouettes are supported
 var silhouetteBlue = Cesium.PostProcessStageLibrary.createEdgeDetectionStage();
 silhouetteBlue.uniforms.color = Cesium.Color.BLUE;
 silhouetteBlue.uniforms.length = .01;
 silhouetteBlue.selected = [];
 var silhouetteGreen = Cesium.PostProcessStageLibrary.createEdgeDetectionStage();
 silhouetteGreen.uniforms.color = Cesium.Color.LIME;
 silhouetteGreen.uniforms.length = .01;
 silhouetteGreen.selected = [];
 removeSilhouette = viewer.scene.postProcessStages.add(Cesium.PostProcessStageLibrary.createSilhouetteStage([ silhouetteBlue, silhouetteGreen ]));
 // Silhouette a feature blue on hover.
 viewer.screenSpaceEventHandler.setInputAction(function onMouseMove(movement) {
  // If a feature was previously highlighted, undo the highlight
  silhouetteBlue.selected = [];
  // Pick a new feature
  var pickedFeature = viewer.scene.pick(movement.endPosition);
  if (!Cesium.defined(pickedFeature)) {
   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 = pickedFeature.getProperty("PVpotentialyield");
  nameOverlay.textContent = "[MWh/a]: " + name;
  // Highlight the feature if it's not already selected.
  if (pickedFeature !== selected.feature) {
   silhouetteBlue.selected = [ pickedFeature ];
  }
 }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
 // Silhouette a feature on selection and show metadata in the InfoBox.
 viewer.screenSpaceEventHandler.setInputAction(function onLeftClick(movement) {
  // If a feature was previously selected, undo the highlight
  silhouetteGreen.selected = [];
  // Pick a new feature
  var pickedFeature = viewer.scene.pick(movement.position);
  /* if (!Cesium.defined(pickedFeature)) {
     clickHandler(movement);
     return;
     }
  */	 
  // Select the feature if it's not already selected
  if (silhouetteGreen.selected[0] === pickedFeature) {
   return;
  }
  // Save the selected feature's original color
  var highlightedFeature = silhouetteBlue.selected[0];
  if (pickedFeature === highlightedFeature) {
   silhouetteBlue.selected = [];
  }
  // Highlight newly selected feature
  silhouetteGreen.selected = [ pickedFeature ];
  chartDataPolygonID = pickedFeature.getProperty("PolygonID");
  $.getJSON("./data/pvpotential.json", function(chartData) {
   $.each(chartData, function(i, item) {
    if (chartData[i].BuildingSurfaceID == chartDataPolygonID) {
     chartDataPVJan = chartData[i].Januaryirradianceonroofplane;
     chartDataPVFeb = chartData[i].Februaryirradianceonroofplane;
     chartDataPVMar = chartData[i].Marchirradianceonroofplane;
     chartDataPVApr = chartData[i].Aprilirradianceonroofplane;
     chartDataPVMai = chartData[i].Mayirradianceonroofplane;
     chartDataPVJun = chartData[i].Juneirradianceonroofplane;
     chartDataPVJul = chartData[i].Julyirradianceonroofplane;
     chartDataPVAug = chartData[i].Augustirradianceonroofplane;
     chartDataPVSep = chartData[i].Septemberirradianceonroofplane;
     chartDataPVOkt = chartData[i].Octoberirradianceonroofplane;
     chartDataPVNov = chartData[i].Novemberirradianceonroofplane;
     chartDataPVDez = chartData[i].Decemberirradianceonroofplane;
     chartDataPVGEBID = chartData[i].BuildingID;
     chartDataPVYield = chartData[i].PVpotentialyield;
     clickvbtn();
    }
   });
  });
 }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
 //Open Fancybox and include ApexChart
 function clickvbtn() {
  //Create Diagram
  var options = {
   series: [ {
    name: "[W/m²]",
    data: [ chartDataPVJan, chartDataPVFeb, chartDataPVMar, chartDataPVApr, chartDataPVMai, chartDataPVJun, chartDataPVJul, chartDataPVAug, chartDataPVSep, chartDataPVOkt, chartDataPVNov, chartDataPVDez ]
   } ],
   chart: {
    type: "area"
   },
   stroke: {
    width: 7,
    curve: "smooth"
   },
   xaxis: {
    categories: [ "Jan", "Feb", "Mar", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez" ],
    title: {
     text: "Monat"
    }
   },
   yaxis: {
    title: {
     text: "Strahlungsleistung [W/m²]"
    }
   },
   title: {
    text: chartDataPVGEBID,
    align: "left",
    style: {
     fontSize: "16px",
     color: "#666"
    }
   },
   subtitle: {
    text: chartDataPolygonID + " - Potenzialertrag: " + chartDataPVYield + " MWh/a",
    align: "left",
    style: {
     fontSize: "12px",
     fontWeight: "normal",
     color: "#9699a2"
    }
   },
   fill: {
    type: "gradient",
    gradient: {
     shadeIntensity: 1,
     opacityFrom: .7,
     opacityTo: .9,
     stops: [ 0, 90, 100 ]
    }
   }
  };
  var chart = new ApexCharts(document.querySelector("#chart"), options);
  chart.render();
  //View Graphic
  $("#vbtn").trigger("click");
 }
}
//Deactivate Function
function deactivatePvAnalysis() {
 viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
 viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
 viewer.scene.postProcessStages.remove(removeSilhouette);
 $("#infotxt").remove();
}