Testgebiete.js 12.2 KB
Newer Older
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

// specifiy credentials and assets from Cesium ION account
Cesium.Ion.defaultAccessToken =
	"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJiYjY5ZTAxNy03YTc0LTQyZTYtYjJlMC0xYzYwNTAzNDQ0ZjUiLCJpZCI6MjkwNCwiaWF0IjoxNjM1NDEzOTI0fQ.Xhmt0sD4Dda4Q46FBYew4wPbqlJ4T8U9n1nNNwGyH7o";

// setting up Cesium Viewer
var viewer = new Cesium.Viewer("cesiumContainer", {
	imageryProvider: new Cesium.IonImageryProvider({ assetId: 3 }), //3 bing maps with labels // use Sentinel2 imagery as default assetID:3954
	/////////////////////////////////////////
	// Note the next 3 lines specify that the Cesium Terrain should be used. ION account is needed
	// For a 'flat' Earth the z-offsets below for each of the tilesets needs to be adjusted
	// comment the next 3 lines to remove the Cesium terrain (Resulution approx. 30m)
	/////////////////////////////////////////
	terrainProvider: new Cesium.CesiumTerrainProvider({
		url: Cesium.IonResource.fromAssetId(1),
	}),
});


// set home button extend
// this is the HFT 
// var extent = Cesium.Rectangle.fromDegrees(9.162794728779428, 48.78605872069245, 9.181827683763427, 48.77616123564855);
var extent = Cesium.Rectangle.fromDegrees(9.29859441939518, 48.814434070664696, 9.30346531111649, 48.813176496066895);
Cesium.Camera.DEFAULT_VIEW_RECTANGLE = extent;
Cesium.Camera.DEFAULT_VIEW_FACTOR = 0;

viewer.scene.globe.enableLighting = true; // set lighting to true

// load 3d Tile set of HFT from Cesium ION.
var tileset = viewer.scene.primitives.add(
	new Cesium.Cesium3DTileset({
		url: Cesium.IonResource.fromAssetId(656401),
	})
);

// define a function to zoom to the tileset (invoke later)
var zoomAll = function (tileset) {
	return new Promise(function (resolve, reject) {
		if (!tileset) {
			reject("Tileset is undifined");
		}
		viewer.camera.viewBoundingSphere(
			tileset.boundingSphere,
			new Cesium.HeadingPitchRange(0, -0.5, 400)
		);
		viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
		resolve();
	});
};




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

//   var HFT_testbld = viewer.scene.primitives.add(
// 	new Cesium.Cesium3DTileset({
// 	  url: Cesium.IonResource.fromAssetId(905706),
// 	})
//   );
  
var HFT_testbld = viewer.scene.primitives.add(
    new Cesium.Cesium3DTileset({
      url: "buildingTiles/HFT_testbld/tileset.json",
      show: true,
    })
  );


  HFT_testbld.readyPromise.then(function (HFT_testbld) {
	var height =55;
	var cartographic = Cesium.Cartographic.fromCartesian(
		HFT_testbld.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()
	);
	// now shift / translate the tileset by the translation vector defined above
	HFT_testbld.modelMatrix = Cesium.Matrix4.fromTranslation(translation);

	return zoomAll(HFT_testbld); // zoom or rather go to the translated tileset
});


96
97
	
	var load3DTiles = function () {
98
		tilesetLOD3 = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
99
100
101
102
103
			url: "https://steinbeis-3dps.eu/3DGeoVolumes/collections/Stuttgart/HFTBuildings_3DModel_noTexture/3dtiles/tileset.json", //Cesium.IonResource.fromAssetId(656401),
		}));
	
		
	
104
105
106
		Cesium.when(tilesetLOD3.readyPromise).then(function (tilesetLOD3) {
			viewer.flyTo(tilesetLOD3)
			tilesetLOD3.style = new Cesium.Cesium3DTileStyle({
107
108
109
110
111
112
113
114
115
116
117
				color: {
					conditions: [
						["${featureType} === 'Window'", "color('blue')"],
						["${featureType} === 'WallSurface'", "color('gray')"],
						["${featureType} === 'RoofSurface'", "color('red')"],
						["${featureType} === 'OuterFloorSurface'", "color('white')"],
						["true", "color('white')"],
					],
				},
				show: true
			});
118
			// tilesetLOD3.style = new Cesium.Cesium3DTileStyle({
119
120
121
122
			//     color: "color('BLACK', 0.3)",
			//     show: true
			// });
	
123
124
			var heightOffset = 49.0;
			var boundingSphere = tilesetLOD3.boundingSphere;
125
126
127
128
			var cartographic = Cesium.Cartographic.fromCartesian(boundingSphere.center);
			var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);
			var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, heightOffset);
			var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
129
			tilesetLOD3.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
130
131
132
133
134
135
136
137
138
139
		})
	
	}
	load3DTiles()



	

	//////// important value. to find the correct value trail and error is needed for a perfect fit
140
	const BUILDIG_TILESET_HEIGHT_OFFSET = 50;
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
	
	tileset.readyPromise.then(function (tileset) {
		var height = BUILDIG_TILESET_HEIGHT_OFFSET;
		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()
		);
		// now shift / translate the tileset by the translation vector defined above
		tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);

		// return zoomAll(tileset); // zoom or rather go to the translated tileset
	});

	tileset.show = false;


////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
// HFT PointCloud Tileset.
////////////////////////////////////////////////////////////////////////////////////

const PCOFFSET = 0;

var hftLargePC = viewer.scene.primitives.add(
	new Cesium.Cesium3DTileset({
		url: Cesium.IonResource.fromAssetId(655879),
	})
);

hftLargePC.readyPromise.then(function (hftLargePC) {
	var height = PCOFFSET;
	var cartographic = Cesium.Cartographic.fromCartesian(
		hftLargePC.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()
	);
	// now shift / translate the tileset by the translation vector defined above
	hftLargePC.modelMatrix = Cesium.Matrix4.fromTranslation(translation);

	// return zoomAll(hftLargePC); // zoom or rather go to the translated tileset
});

hftLargePC.style = new Cesium.Cesium3DTileStyle({
	color: "color('blue',0.3)",
	// color: "color('red')" ,
	pointSize: 3
});




///////////////////////////// innenhof PC

var hftInnehofRGB_PC = viewer.scene.primitives.add(
	new Cesium.Cesium3DTileset({
223
		url: Cesium.IonResource.fromAssetId(712217),  //656854  small point cloud
224
225
226
227
228
229
	})
);

hftInnehofRGB_PC.style = new Cesium.Cesium3DTileStyle({
	// color: "color('blue',0.3)",	
	// color: "color('red')" ,
230
	pointSize: 2
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
});



////////////////////////// Control Pointclouds and Tileset with switches

var toggleLargePC = function () {
	if (hftLargePC.show === true) {
		hftLargePC.show = false
	}
	else {
		hftLargePC.show = true
	}
}
// or use tenrary operator as for the other two 
var toggleRGBPC = function () {
	hftInnehofRGB_PC.show = hftInnehofRGB_PC.show ? false : true;
}

var toggleBuildingTiles = function () {
	if (tileset.show === true) {
		tileset.show = false
	}
	else {
		tileset.show = true	
256
		if (tilesetLOD3.show === true){
257
			$('#prettyBuildingsCheckbox').prop('checked', false);
258
			tilesetLOD3.show = false
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
		}						
	}
}

var toggleFellbachTiles = function () {
	if (fellbachBuildings.show === true) {
		fellbachBuildings.show = false
	}
	else {
		fellbachBuildings.show = true;
		if (fellbachBuildingsTextured.show === true){
			$('#FellbachTexturedBuildingsCheckbox').prop('checked', false);
			fellbachBuildingsTextured.show = false;
		}							
	}
}


var toggleFellbachTexturedTiles = function () {
	if (fellbachBuildingsTextured.show === true) {
		fellbachBuildingsTextured.show = false
	}
	else {
		fellbachBuildingsTextured.show = true;	
		if (fellbachBuildings.show === true){
			$('#FellbachBuildingsCheckbox').prop('checked', false);
			fellbachBuildings.show = false;
		}					
	}
}

var togglePrettyBuildingTiles = function () {
291
292
293
	// tilesetLOD3.show = tilesetLOD3.show ? false : true;
	if (tilesetLOD3.show === true) {
		tilesetLOD3.show = false		
294
295
	}
	else {
296
		tilesetLOD3.show = true				
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
		if (tileset.show === true){
			$('#simpleBuildingsCheckbox').prop('checked', false);
			tileset.show = false
		}
	}
	// $('#prettyBuildingsCheckbox').prop('checked', true); // Checks it
//$('#myCheckbox').prop('checked', false); // Unchecks it
}




////////////////////////////////////////////////////
	// Fellbach building tiles
	fellbachBuildings = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
		url: "https://3dps.gis.lrg.tum.de/geovolumes/collections/Fellbach/all_buildings_lod2/3dtiles/",
		// url: "https://3dps.gis.lrg.tum.de/geovolumes/collections/Fellbach/all_buildings_lod2_textured/3dtiles/tileset.json?bbox=9.27193208236,48.8200709939,-10,9.2900117958,48.8164019664,500",
		show: true,
	}));

	fellbachBuildings.readyPromise.then(function (fellbachBuildings) {
		var height = 51;
		var cartographic = Cesium.Cartographic.fromCartesian(
			fellbachBuildings.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()
		);
		// now shift / translate the tileset by the translation vector defined above
		fellbachBuildings.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
		return zoomAll(fellbachBuildings);

		
	});


	fellbachBuildings.show = false;
	////////////////////////////////////////////////////
	// Fellbach building tiles
	fellbachBuildingsTextured = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({		
		url: "https://3dps.gis.lrg.tum.de/geovolumes/collections/Fellbach/all_buildings_lod2_textured/3dtiles/tileset.json?bbox=9.27193208236,48.8200709939,-10,9.2900117958,48.8164019664,500",
		show: true,
	}));

	fellbachBuildingsTextured.readyPromise.then(function (fellbachBuildingsTextured) {
		var height = 51;
		var cartographic = Cesium.Cartographic.fromCartesian(
			fellbachBuildingsTextured.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()
		);
		// now shift / translate the tileset by the translation vector defined above
		fellbachBuildingsTextured.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
		return zoomAll(fellbachBuildingsTextured);

		
	});


		  

	var gotoFellbach = function () {

		// var extent = Cesium.Rectangle.fromDegrees(9.26530042893943,48.818436808301705, 9.275552393133086,  48.81387520377022);
		// Cesium.Camera.DEFAULT_VIEW_RECTANGLE = extent;
		// Cesium.Camera.DEFAULT_VIEW_FACTOR = 0;


		viewer.camera.flyTo({
			destination : Cesium.Cartesian3.fromDegrees(9.269968312784966, 48.815644351028965, 600.0),
			orientation : {
				heading : Cesium.Math.toRadians(-30.0),
				pitch : Cesium.Math.toRadians(-45),
				roll : 0
			}
		});
		new Cesium.HeadingPitchRange(0, -0.5, 400)
		
		// viewer.camera.viewBoundingSphere(Cesium.Cartesian3.fromDegrees(9.26530042893943,48.818436808301705, 1500.0),		);
		// viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);

		// viewer.canera.setView({
		// 	destination : Cesium.Cartesian3.fromDegrees(-117.16, 32.71, 15000.0)
		// });
		// zoomAll(fellbachBuildings);
		// viewer.scene.camera.lookAt(fellbachBuildings.position.getValue(viewer.clock.currentTime), new Cesium.Cartesian3(0,0,200));
	}

	var gotoHFT = function () {

		var extent = Cesium.Rectangle.fromDegrees(9.29859441939518, 48.814434070664696, 9.30346531111649, 48.813176496066895);
		Cesium.Camera.DEFAULT_VIEW_RECTANGLE = extent;
		Cesium.Camera.DEFAULT_VIEW_FACTOR = 0;

416
		viewer.flyTo(tilesetLOD3);
417
418
419
420


		
	}