selection.js 7.82 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
var removeSilhouette;

function selectData() {
 // HTML overlay for showing feature name on mouseover
 var nameOverlay = document.createElement("div");
 viewer.container.appendChild(nameOverlay);
 nameOverlay.setAttribute("id", "selectfunc");
 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";
 // 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);
 // 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("gml_id");
  nameOverlay.textContent = 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 ];
  // Set feature infobox description
  var featureName = pickedFeature.getProperty("name");
  selectedEntity.name = "Ergebnis Objektabfrage";
  selectedEntity.description = 'Loading <div class="cesium-infoBox-loading"></div>';
  viewer.selectedEntity = selectedEntity;
  selectedEntity.description = '<table class="cesium-infoBox-defaultTable"><tbody>';
  //CityGML-Standard
  if (pickedFeature.getProperty("gml_id") !== undefined && pickedFeature.getProperty("gml_id") !== null) {
   selectedEntity.description += "<tr><th>GML-ID</th><td>" + pickedFeature.getProperty("gml_id") + "</td></tr>";
  }
  if (pickedFeature.getProperty("gml_parent_id") !== undefined && pickedFeature.getProperty("gml_parent_id") !== null) {
   selectedEntity.description += "<tr><th>GML-PARENT-ID</th><td>" + pickedFeature.getProperty("gml_parent_id") + "</td></tr>";
  }
  if (pickedFeature.getProperty("gebaeudetext") !== undefined && pickedFeature.getProperty("gebaeudetext") !== null) {
   selectedEntity.description += "<tr><th>Bezeichnung</th><td>" + pickedFeature.getProperty("gebaeudetext") + "</td></tr>";
  }
  if (pickedFeature.getProperty("alkisId") !== undefined && pickedFeature.getProperty("alkisId") !== null) {
   selectedEntity.description += "<tr><th>ALKIS-ID</th><td>" + pickedFeature.getProperty("alkisId") + "</td></tr>";
  }
  if (pickedFeature.getProperty("grundflaeche") !== undefined && pickedFeature.getProperty("grundflaeche") !== null) {
   selectedEntity.description += "<tr><th>Grundfläche [m²]</th><td>" + pickedFeature.getProperty("grundflaeche") + "</td></tr>";
  }
  if (pickedFeature.getProperty("geschossflaeche") !== undefined && pickedFeature.getProperty("geschossflaeche") !== null) {
   selectedEntity.description += "<tr><th>Geschossfläche [m²]</th><td>" + pickedFeature.getProperty("geschossflaeche") + "</td></tr>";
  }
  if (pickedFeature.getProperty("hoeheEFH") !== undefined && pickedFeature.getProperty("hoeheEFH") !== null) {
   selectedEntity.description += "<tr><th>EFH [m. ü. NHN]</th><td>" + pickedFeature.getProperty("hoeheEFH") + "</td></tr>";
  }
  if (pickedFeature.getProperty("hoeheFirst") !== undefined && pickedFeature.getProperty("hoeheFirst") !== null) {
   selectedEntity.description += "<tr><th>Firsthöhe [m. ü. NHN]</th><td>" + pickedFeature.getProperty("hoeheFirst") + "</td></tr>";
  }
  if (pickedFeature.getProperty("hoeheTrauf") !== undefined && pickedFeature.getProperty("hoeheTrauf") !== null) {
   selectedEntity.description += "<tr><th>Traufhöhe [m. ü. NHN]</th><td>" + pickedFeature.getProperty("hoeheTrauf") + "</td></tr>";
  }
  if (pickedFeature.getProperty("citygml_measured_height") !== undefined && pickedFeature.getProperty("citygml_measured_height") !== null) {
   selectedEntity.description += "<tr><th>GML-Measured-Height [m]</th><td>" + pickedFeature.getProperty("citygml_measured_height") + "</td></tr>";
  }
  if (pickedFeature.getProperty("citygml_storeys_above_ground") !== undefined && pickedFeature.getProperty("citygml_storeys_above_ground") !== null) {
   selectedEntity.description += "<tr><th>Oberirdische Geschosse</th><td>" + pickedFeature.getProperty("citygml_storeys_above_ground") + "</td></tr>";
  }
  if (pickedFeature.getProperty("citygml_storeys_below_ground") !== undefined && pickedFeature.getProperty("citygml_storeys_below_ground") !== null) {
   selectedEntity.description += "<tr><th>Unterirdische Geschosse</th><td>" + pickedFeature.getProperty("citygml_storeys_below_ground") + "</td></tr>";
  }
  if (pickedFeature.getProperty("citygml_year_of_construction") !== undefined && pickedFeature.getProperty("citygml_year_of_construction") !== null) {
   selectedEntity.description += "<tr><th>Baujahr</th><td>" + pickedFeature.getProperty("citygml_year_of_construction") + "</td></tr>";
  }
  //Faechergeometrie
  if (pickedFeature.getProperty("natural") !== undefined) {
   selectedEntity.description += "<tr><th>Typ</th><td>" + pickedFeature.getProperty("natural") + "</td></tr>";
  }
  if (pickedFeature.getProperty("HOEHE") !== undefined) {
   selectedEntity.description += "<tr><th>Höhe [m]</th><td>" + pickedFeature.getProperty("HOEHE") + "</td></tr>";
  }
  selectedEntity.description += "</tbody></table>";
 }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
}

//Deactivate Function
function deactivateSelectData() {
 viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
 viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
 viewer.scene.postProcessStages.remove(removeSilhouette);
 $("#selectfunc").remove();
}