EssenPC.js 16.1 KB
Newer Older
1

Sven Schneider's avatar
Sven Schneider committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
	
        Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI5ODI4ZTYyZS1mMTg2LTQ5NGEtYjdiOS02ODg2NzVhNjc0MTAiLCJpZCI6MjkwNCwiaWF0IjoxNTM1MTA5OTAzfQ.kyDX_0ScvJBkYnvXI0DW5NfZbiaRL5ezwtAUhxYnk1Y';

		var imageryViewModels = [];
		imageryViewModels.push(new Cesium.ProviderViewModel({
			name: 'Sentinel-2',
			iconUrl: Cesium.buildModuleUrl('Widgets/Images/ImageryProviders/sentinel-2.png'),
			tooltip: 'Sentinel-2 cloudless.',
			creationFunction: function () {
				return new Cesium.IonImageryProvider({ assetId: 3954 });
			}
		}));
		
		imageryViewModels.push(new Cesium.ProviderViewModel({
			name: 'Blue Marble',
			iconUrl: Cesium.buildModuleUrl('Widgets/Images/ImageryProviders/blueMarble.png'),
			tooltip: 'Blue Marble Next Generation July, 2004 imagery from NASA.',
			creationFunction: function () {
				return new Cesium.IonImageryProvider({ assetId: 3845 });
			}
		}));
	
		var viewer = new Cesium.Viewer('cesiumContainer',
			{
26
				imageryProvider: new Cesium.IonImageryProvider({ assetId: 3 }),
Sven Schneider's avatar
Sven Schneider committed
27
28
29
30
					
				terrainProvider : new Cesium.CesiumTerrainProvider({
						url: Cesium.IonResource.fromAssetId(1)
					}),
31
				scene3DOnly: true,
Sven Schneider's avatar
Sven Schneider committed
32
33
34
				shouldAnimate: true,
				animation: true,
				infoBox: true,
35
				baseLayerPicker: false,
Sven Schneider's avatar
Sven Schneider committed
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
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
				fullscreenButton: true,
				timeline: false,
				navigationHelpButton: true,
				navigationInstructionsInitiallyVisible: false,
				homeButton: false,
				selectionIndicator: true,
				geocoder: true,
				// imageryProviderViewModels: imageryViewModels
			});

	



	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
		url: 'buildingTiles/Essen/tileset.json',		
		show: true
	}));
		
	tileset.readyPromise.then(function (tileset){ 
		
		// set tileset height
       var height = 49;       
       var cartographic = Cesium.Cartographic.fromCartesian(tileset.boundingSphere.center);
       var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);
       var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, height);
       var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
       tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);

       return zoomAll(tileset);
	});
	
	tileset.style = new Cesium.Cesium3DTileStyle({
			color: 'color("darkgray")'		});	

	//////////////////////////////////////////////////////////////////		
			
	var pointCloud = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
		url: 'results/EssenPointCloud/tileset.json',	
		
		show: true
	}));
	
	

	pointCloud.readyPromise.then(function (pointCloud) {

		var height = -119;       
       var cartographic = Cesium.Cartographic.fromCartesian(pointCloud.boundingSphere.center);
       var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);
       var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, height);
       var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
       pointCloud.modelMatrix = Cesium.Matrix4.fromTranslation(translation);

		return zoomAll(pointCloud);
	});
	
	//pointCloud.style = new Cesium.Cesium3DTileStyle({
	//		color: "color('gray')" 		});
	
	
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	var pcHull = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
		url: 'results/EssenPCHull/tileset.json',				
		show: true
	}));
	
	
	pcHull.readyPromise.then(function (pcHull) {

		var height = -118.3;       
       var cartographic = Cesium.Cartographic.fromCartesian(pcHull.boundingSphere.center);
       var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);
       var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, height);
       var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
       //var v = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, translation["x"], translation["y"],translation["z"],  1.0];
	   
	   pcHull.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
       

		return zoomAll(pcHull);
	});
	
	pcHull.style = new Cesium.Cesium3DTileStyle({
			color: "color('yellow')",
			pointSize: 2
			});
			
	//////////////////////////////////////////////////////////////////	//////////////////////////////////////////////////////////////////
	var pcBBox = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
		url: 'results/EssenPCBbox/tileset.json',	
		maximumScreenSpaceError: 2		,		
		show: false
	}));
	
	
	pcBBox.readyPromise.then(function (pcBBoxl) {

		var height = -118.3;       
		var cartographic = Cesium.Cartographic.fromCartesian(pcBBox.boundingSphere.center);
		var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);
		var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, height);
		var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
		
		pcbBBox.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
		

		return zoomAll(pcBBox);
	});
	
	pcBBox.style = new Cesium.Cesium3DTileStyle({
			color: "color('red')" 		});

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	var pcWindows = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
		url: 'results/EssenPCWindows/tileset.json',			
		maximumScreenSpaceError: 2		,		
		show: true
	}));
	
	
	pcWindows.readyPromise.then(function (pcWindows) {

		var height = -118.3;
		var cartographic = Cesium.Cartographic.fromCartesian(pcWindows.boundingSphere.center);
		var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);
		var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, height);
		var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
		//var v = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, translation["x"], translation["y"],translation["z"],  1.0];
		
		pcWindows.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
		

		return zoomAll(pcWindows);
	});
	
	pcWindows.style = new Cesium.Cesium3DTileStyle({
			color: "color('red')" 		,
			pointSize: 3
			});
	
			////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			
			

	///////////////////////////////////////////////////////			
	var TurnOnPC = function () {
    pointCloud.show = true;
    }
	var TurnOffPC = function () {
    pointCloud.show = false;
   	}		
	
	///////////////////////////////////////////////////////
	var TurnOnPCHull = function () {
    pcHull.show = true;    
	}
	var TurnOffPCHull = function () {
    pcHull.show = false;
	}	
	///////////////////////////////////////////////////////
	var TurnOnPCWindows = function () {
    pcWindows.show = true;
    }
	var TurnOffPCWindows = function () {
    pcWindows.show = false;
   	}			
	///////////////////////////////////////////////////////	
	///////////////////////////////////////////////////////
	var TurnOnEssen3dT = function () {
    tileset.show = true;
    }
	var TurnOffEssen3dT = function () {
    tileset.show = false;
   	}			
	//////////////////////////////////////////////////////

	/*
	var terrainProvider = new new Cesium.CesiumTerrainProvider({
        url: Cesium.IonResource.fromAssetId(1), requestVertexNormals: true );
	
	viewer.terrainProvider = terrainProvider;
*/
	
/*
	var terrainProvider = new Cesium.CesiumTerrainProvider({
        url: 'https://assets.agi.com/stk-terrain/v1/tilesets/world/tiles',
        requestWaterMask: true, // required for water effects
        requestVertexNormals: true // required for terrain lighting
    });
    viewer.terrainProvider = terrainProvider;
	*/
	viewer.scene.globe.enableLighting = true; // set lighting to true
	

	
	var zoomAll = function (pointCloud) {
		return new Promise(function (resolve, reject) {
			if (!pointCloud) { reject("Tileset is undifined"); }
238
			viewer.camera.viewBoundingSphere(pointCloud.boundingSphere, new Cesium.HeadingPitchRange(1.5, -0.5, 200));
Sven Schneider's avatar
Sven Schneider committed
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
			viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
			resolve();
		});
	}
	
	
	   

	// HTML overlay for showing feature name on mouseover
	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 = 'green';

	// Information about the currently selected feature
	var selected = {
		feature: undefined,
		originalColor: new Cesium.Color()
	};

	// Information about the currently highlighted feature
	var highlighted = {
		feature: undefined,
		originalColor: new Cesium.Color()
	};

	var selectedEntity = new Cesium.Entity();

	// Color a feature yellow on hover.
	viewer.screenSpaceEventHandler.setInputAction(function onMouseMove(movement) {
		// 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 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('name');
		if (!Cesium.defined(name)) {
			name = pickedFeature.getProperty('id');
		}
		nameOverlay.textContent = name;

		// Highlight the feature if it's not already selected.
		if (pickedFeature !== selected.feature) {
			highlighted.feature = pickedFeature;
			Cesium.Color.clone(pickedFeature.color, highlighted.originalColor);
			pickedFeature.color = Cesium.Color.AQUA;
		}
	}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

	// Color a feature on selection and show metadata in the InfoBox.
var clickHandler = viewer.screenSpaceEventHandler.getInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
viewer.screenSpaceEventHandler.setInputAction(function onLeftClick(movement) {
    // If a feature was previously selected, undo the highlight
    if (Cesium.defined(selected.feature)) {
        selected.feature.color = selected.originalColor;
        selected.feature = undefined;
    }

    // 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 (selected.feature === pickedFeature) {
        return;
    }
    selected.feature = pickedFeature;

    // Save the selected feature's original color
    if (pickedFeature === highlighted.feature) {
        Cesium.Color.clone(highlighted.originalColor, selected.originalColor);
        highlighted.feature = undefined;
    } else {
        Cesium.Color.clone(pickedFeature.color, selected.originalColor);
    }

    // Highlight newly selected feature
    pickedFeature.color = Cesium.Color.WHITE;

    // Set feature infobox description
    var featureName = pickedFeature.getProperty('name');
    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>Bld function</th><td>' + pickedFeature.getProperty('Function') + '</td></tr>' +
								 '<tr><th>gmlID</th><td>' + pickedFeature.getProperty('gmlIDStr') + '</td></tr>' +
								 '<tr><th>AbsoluteHoehe (m)</th><td>' + pickedFeature.getProperty('AbsoluteHoehe') + '</td></tr>' +
                                 '<tr><th>Lon</th><td>' + pickedFeature.getProperty('Longitude') + '</td></tr>' +
								 '<tr><th>Lat</th><td>' + pickedFeature.getProperty('Latitude') + '</td></tr>' +
								 '<tr><th>GebaeudeHoehe (m)</th><td>' + pickedFeature.getProperty('GebaeudeHoehe') + '</td></tr>' +							 
								 '<tr><th>YearOfConstruction</th><td>' + pickedFeature.getProperty('YearOfConstruction') + '</td></tr>' +
								 '<tr><th>MeasuredHeight (m):</th><td>' + pickedFeature.getProperty('MeasuredHeight') + '</td></tr>' +
								 '<tr><th>HoeheFirst (m)</th><td>' + pickedFeature.getProperty('hoeheFirst') + '</td></tr>' +
								 '<tr><th>HoeheTrauf (m)</th><td>' + pickedFeature.getProperty('hoeheTrauf') + '</td></tr>' +
								 '<tr><th>Grundflaeche (sqm)</th><td>' + pickedFeature.getProperty('grundflaeche') + '</td></tr>' +
								 '<tr><th>StoreysAboveGround: </th><td>' + pickedFeature.getProperty('StoreysAboveGround') + '</td></tr>' +
								 '<tr><th>StoreysBelowGround: </th><td>' + pickedFeature.getProperty('StoreysBelowGround') + '</td></tr>' +								 
                                 '</tbody></table>';
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

	var scene = viewer.scene;
	var longitude;
	var latitude;
	var fid;
	var featuretype;
	var gmlid;
	var selID = new Array();
	var cnt = 0;
	var lastPickedObject;

	var viewModel = {
		rightClickAction: 'properties',
		middleClickAction: 'hide'
	};

	Cesium.knockout.track(viewModel);

	var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);

	
	handler.setInputAction(function (movement) {
			// makes camera go to a certain position given by the coordinates below
		
		var feature = viewer.scene.pick(movement.position);
			if (!Cesium.defined(feature)) {
				console.log("no feature defined")
				return;
			}	
		var propertyNames = feature.getPropertyNames();
		var lat = feature.getProperty("Latitude");
		var lon = feature.getProperty("Longitude");
		var tmp = feature.getProperty("YearOfConstruction");

		viewer.camera.flyTo({
			destination: Cesium.Cartesian3.fromDegrees(lon, lat, 900),
			maximumHeight: 1500.0,
			orientation: {
				heading: Cesium.Math.toRadians(0.0),
				pitch: Cesium.Math.toRadians(-90.0),
				roll: Cesium.Math.toRadians(45.0)
			},
			duration: 2
		});		}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
		


		handler.setInputAction(function (movement) {
			var feature = viewer.scene.pick(movement.position);
			if (!Cesium.defined(feature)) {
				return;
			}
			var action = viewModel.rightClickAction;
			action === 'properties'
			printProperties(movement, feature)
		}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);


		function printProperties(movement, feature) {
			console.log('Properties:');
			var propertyNames = feature.getPropertyNames();
			var length = propertyNames.length;
			for (var i = 0; i < length; ++i) {
				var propertyName = propertyNames[i];
				if (propertyName == 'gmlIdALKISLageBezeichnung_1' ||
					propertyName == 'gmlIdALKISLageBezeichnung_2' ||
					propertyName == 'gmlIdALKISLageBezeichnung_3' ||
					propertyName == 'gmlIdALKISLageBezeichnung_4' ||
					propertyName == 'gmlIdALKISLageBezeichnung_5' ||
					propertyName == 'gmlIdALKISLageBezeichnung_6')
					console.log('  ' + propertyName + ': ' + 'zensiert');
				else
					console.log('  ' + propertyName + ': ' + feature.getProperty(propertyName));
			}

			// Evaluate feature description
			//console.log('Description : ' + tileset.style.meta.description.evaluate(scene.frameState, feature));
		}

		handler.setInputAction(function (movement) {
			var feature = viewer.scene.pick(movement.position);
			if (!Cesium.defined(feature)) {
				return;
			}

			var action = viewModel.middleClickAction;
			if (action === 'hide') {
				feature.show = false;
			}
		}, Cesium.ScreenSpaceEventType.MIDDLE_CLICK);