HFT.js 8.06 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14

// 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({
15
		url: Cesium.IonResource.fromAssetId(1),
16
17
18
19
20
	}),
});


// set home button extend
21
22
23
// 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);
24
25
26
27
28
Cesium.Camera.DEFAULT_VIEW_RECTANGLE = extent;
Cesium.Camera.DEFAULT_VIEW_FACTOR = 0;

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

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

36
37
38
// define a function to zoom to the tileset (invoke later)
var zoomAll = function (tileset) {
	return new Promise(function (resolve, reject) {
39
		if (!tileset) {
40
			reject("Tileset is undifined");
41
42
		}
		viewer.camera.viewBoundingSphere(
43
44
			tileset.boundingSphere,
			new Cesium.HeadingPitchRange(0, -0.5, 400)
45
46
47
		);
		viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
		resolve();
48
49
50
51
	});
};


52

53
	
54
55
56
57
58
59

	var load3DTiles = function () {
		tilesetLOD1 = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
			url: "https://steinbeis-3dps.eu/3DGeoVolumes/collections/Stuttgart/HFTBuildings_3DModel_noTexture/3dtiles/tileset.json" //Cesium.IonResource.fromAssetId(656401),
		}));
	
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
	
		Cesium.when(tilesetLOD1.readyPromise).then(function (tilesetLOD1) {
			viewer.flyTo(tilesetLOD1)
			tilesetLOD1.style = new Cesium.Cesium3DTileStyle({
				color: {
					conditions: [
						["${featureType} === 'Window'", "color('blue')"],
						["${featureType} === 'WallSurface'", "color('gray')"],
						["${featureType} === 'RoofSurface'", "color('red')"],
						["${featureType} === 'OuterFloorSurface'", "color('white')"],
						["true", "color('white')"],
					],
				},
				show: true
			});
			// tilesetLOD1.style = new Cesium.Cesium3DTileStyle({
			//     color: "color('BLACK', 0.3)",
			//     show: true
			// });
	
			var heightOffset = 50.0;
			var boundingSphere = tilesetLOD1.boundingSphere;
			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());
			tilesetLOD1.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
88
		})
89
90
91
	
	}
	load3DTiles()
92

93
94
95
96


	

97
98
	//////// important value. to find the correct value trail and error is needed for a perfect fit
	const BUILDIG_TILESET_HEIGHT_OFFSET = 54;
99
	
100
	tileset.readyPromise.then(function (tileset) {
101
102
		var height = BUILDIG_TILESET_HEIGHT_OFFSET;
		var cartographic = Cesium.Cartographic.fromCartesian(
103
			tileset.boundingSphere.center
104
105
		);
		var surface = Cesium.Cartesian3.fromRadians(
106
107
108
			cartographic.longitude,
			cartographic.latitude,
			0.0
109
110
		);
		var offset = Cesium.Cartesian3.fromRadians(
111
112
113
			cartographic.longitude,
			cartographic.latitude,
			height
114
115
		);
		var translation = Cesium.Cartesian3.subtract(
116
117
118
			offset,
			surface,
			new Cesium.Cartesian3()
119
120
121
		);
		// now shift / translate the tileset by the translation vector defined above
		tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
122

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

126
	tileset.show = false;
127

128
129
130
131
132
133
134
135

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

const PCOFFSET = 0;

136
var hftLargePC = viewer.scene.primitives.add(
137
138
139
140
141
	new Cesium.Cesium3DTileset({
		url: Cesium.IonResource.fromAssetId(655879),
	})
);

142
hftLargePC.readyPromise.then(function (hftLargePC) {
143
144
	var height = PCOFFSET;
	var cartographic = Cesium.Cartographic.fromCartesian(
145
		hftLargePC.boundingSphere.center
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
	);
	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
163
	hftLargePC.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
164

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

168
hftLargePC.style = new Cesium.Cesium3DTileStyle({
169
170
171
172
	color: "color('blue',0.3)",
	// color: "color('red')" ,
	pointSize: 3
});
173
174
175
176




177
///////////////////////////// innenhof PC
178

179
var hftInnehofRGB_PC = viewer.scene.primitives.add(
180
	new Cesium.Cesium3DTileset({
181
		url: Cesium.IonResource.fromAssetId(656854),
182
	})
183
184
);

185
hftInnehofRGB_PC.style = new Cesium.Cesium3DTileStyle({
186
187
	// color: "color('blue',0.3)",	
	// color: "color('red')" ,
188
189
190
191
192
193
194
	pointSize: 3
});



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

195
196
197
198
199
200
201
var toggleLargePC = function () {
	if (hftLargePC.show === true) {
		hftLargePC.show = false
	}
	else {
		hftLargePC.show = true
	}
202
}
203
204
205
// or use tenrary operator as for the other two 
var toggleRGBPC = function () {
	hftInnehofRGB_PC.show = hftInnehofRGB_PC.show ? false : true;
206
207
}

208
var toggleBuildingTiles = function () {
209
210
211
212
213
214
215
216
217
218
	if (tileset.show === true) {
		tileset.show = false
	}
	else {
		tileset.show = true	
		if (tilesetLOD1.show === true){
			$('#prettyBuildingsCheckbox').prop('checked', false);
			tilesetLOD1.show = false
		}						
	}
219
220
}

221
var togglePrettyBuildingTiles = function () {
222
223
224
225
226
227
228
229
230
231
232
233
234
	// tilesetLOD1.show = tilesetLOD1.show ? false : true;
	if (tilesetLOD1.show === true) {
		tilesetLOD1.show = false		
	}
	else {
		tilesetLOD1.show = true				
		if (tileset.show === true){
			$('#simpleBuildingsCheckbox').prop('checked', false);
			tileset.show = false
		}
	}
	// $('#prettyBuildingsCheckbox').prop('checked', true); // Checks it
//$('#myCheckbox').prop('checked', false); // Unchecks it
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
////////////////////////////////////////////////////
	// Fellbach building tiles
	fellbachBuildings = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
		url: "buildingTiles/fellbachTiles/tileset.json",
		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);

		
	});
271

272
273
274
275
276
277
278
	// var fellbachBuildings = viewer.scene.primitives.add(
	// 	new Cesium.Cesium3DTileset({
	// 	//   url: Cesium.IonResource.fromAssetId(679236),  // in wgs84 srs
	// 	  url: Cesium.IonResource.fromAssetId(679239),   // in erts89Z32 srs
	// 	})
	//   );