var viewer = new Cesium.Viewer('cesiumContainer');var CC3 = Cesium.Cartesian3;var tLon = -90.1922703175/180*Math.PI;var tLat = 38.6286636758/180*Math.PI;
var mycarto = new Cesium.Cartographic();mycarto.longitude=tLon;mycarto.latitude=tLat;mycarto.height=0;console.log(mycarto); //definedvar tHeight=viewer.scene.globe.getHeight(mycarto);console.log(tHeight); //undefined, but why?
tHeight=110.139218977672; //just manually set for now
var thebox = viewer.entities.add({ name : 'building', position: Cesium.Cartesian3.fromDegrees(-90.1922703175, 38.6286636758, 30), box : { dimensions : new Cesium.Cartesian3(40, 30, 60), material : Cesium.Color.RED, outline : true, outlineColor : Cesium.Color.BLACK }});viewer.zoomTo(viewer.entities);function gohere(height){ var test = new Cesium.Cartographic(tLon,tLat,height); var mypos = Cesium.Ellipsoid.WGS84.cartographicToCartesian(test); thebox.position = mypos; }function upAndDown(scalar){ var mycarte = thebox._position._value; var mynormal = Cesium.Ellipsoid.WGS84.geodeticSurfaceNormal(mycarte); var relMove = CC3.multiplyByScalar(mynormal,scalar,new CC3()); CC3.add(mycarte,relMove,mycarte); thebox.position = mycarte;}Sandcastle.addToolbarButton('up 5 meters', function() {upAndDown(5);}); Sandcastle.addToolbarButton('down 5 meters', function() {upAndDown(-5);});
//note that this is center of the building, not the bottomSandcastle.addToolbarButton('ellipsoid+30', function() {gohere(0+30);}); Sandcastle.addToolbarButton('tHeight+10', function() {gohere(tHeight+10);});Sandcastle.addToolbarButton('tHeight+20', function() {gohere(tHeight+20);});Sandcastle.addToolbarButton('tHeight+30', function() {gohere(tHeight+30);}); Sandcastle.addToolbarButton('tHeight+40', function() {gohere(tHeight+40);});Sandcastle.addToolbarButton('tHeight+50', function() {gohere(tHeight+50);});
I just have to say thanks again, It looks like you pointed me at a solution to our biggest problem.
Sorry,
var terrainProvider = new Cesium.CesiumTerrainProvider({ url : '//assets.agi.com/stk-terrain/world', requestVertexNormals : true});
var test = 1500; //the altitude variable that should be changed to the value at pos lat/long
var viewer = new Cesium.Viewer('cesiumContainer', {terrainProvider: terrainProvider, baseLayerPicker: false});var ellipsoid = viewer.scene.globe.ellipsoid; //just necessary to fly there.var POI= Cesium.Cartographic.fromDegrees(46.5,9.5,0, new Cesium.Cartographic()); //the position in lat/long as well as height 0.viewer.camera.flyTo({destination: ellipsoid.cartographicToCartesian(POI, new Cesium.Cartesian3())});var promise = Cesium.sampleTerrain(terrainProvider, 11, [POI]); //takes the terrain, a precision value and the point of interest (lat/long; returns a promise.Cesium.when(promise, function(POIx) { //updates the test variable with the "real" variable (i.e. the altitude at pos. lat/long. test = (POIx[0].height); });setTimeout(function(){console.log(test)},0); //returns immediately the value --> returns 1500; the defined variablesetTimeout(function(){console.log(test)},1000); //returns the value after 1 second --> returns 747; the "real" value at that position.
--
You received this message because you are subscribed to the Google Groups "cesium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cesium-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Will Cesium clamp to ground automatically adapt to tiles changing LOD levels by chance? Maybe when a tile changes LOD, it tags all entities on it to have their heights re-adjusted.
--
var viewer = new Cesium.Viewer('cesiumContainer');
});
var positions = [
Cesium.Cartographic.fromDegrees(86.925145, 27.988257),
Cesium.Cartographic.fromDegrees(87.0, 28.0)
];
var promise = Cesium.sampleTerrain(terrainProvider, 11, positions);
Cesium.when(promise, function(updatedPositions) {
console.log("pos0 "+positions[0].height);
console.log("pos1 "+positions[1].height);
});
viewer.scene.globe.maximumScreenSpaceError = 1;
var center = Cesium.Cartesian3.fromDegrees(lat, long, 500);
var heading = Cesium.Math.toRadians(90.0);
var pitch = Cesium.Math.toRadians(-55.0);
var range = 1000.0;
viewer.camera.lookAt(center, new Cesium.HeadingPitchRange(heading, pitch, range));
var scene = viewer.scene;
var canvas = viewer.canvas;
canvas.setAttribute('tabindex', '0'); // needed to put focus on the canvas
canvas.onclick = function() {
canvas.focus();
};
When sampleTerrain calls the callback you know it's finished, it could be less than 10 seconds. You could place the height data into a textarea, copy/paste that into a js file array and get quick access on all later loads.
I'm not sure how to get model dimensions from .glTF files, maybe someone else here knows of a way.
Do you set terrainProvider at startup, or set it manually with the buttons?
On the code you provided you have lat before lon it seems, though Cesium expects lon before lat.
Perhaps with the initial lookAt settings it pushes the camera into a mountain and gets shoved up?
var viewer = new Cesium.Viewer('cesiumContainer', { terrainProvider : new Cesium.CesiumTerrainProvider({ baseLayerPicker : false });
//first do setView on the target, then move back with the following:
var CC3=Cesium.Cartesian3;
var temp=new CC3()
CC3.negate(camera.direction,temp);
CC3.mutliplyByScalar(temp,range,temp);
CC3.add(temp,camera.position,temp);
camera.position=temp.clone();
Hyper Sonic, again thank you for the code to capture a position. I got it to do exactly what I needed. Capture a position, mouse around, and then return to the original position. Here is a link http://vcities.ite-stl.org/Cesium/Apps/Sandcastle/gallery/position.html.
var viewer = new Cesium.Viewer('cesiumContainer');var CC3 = Cesium.Cartesian3;var magnitude = 1;
var thebox = viewer.entities.add({ name : 'building', position: Cesium.Cartesian3.fromDegrees(-90.1922703175, 38.6286636758, 30), box : { dimensions : new Cesium.Cartesian3(40, 30, 60), material : Cesium.Color.RED, outline : true, outlineColor : Cesium.Color.BLACK }});viewer.zoomTo(viewer.entities);function getVector(name){ var GD_full_transform = Cesium.Transforms.eastNorthUpToFixedFrame(thebox._position._value, viewer.scene.globe.ellipsoid, new Cesium.Matrix4()); var GD_rot_transform = Cesium.Matrix4.getRotation(GD_full_transform,new Cesium.Matrix3()); if(name=="east"){return Cesium.Matrix3.getColumn(GD_rot_transform,0,new CC3());} if(name=="north"){return Cesium.Matrix3.getColumn(GD_rot_transform,1,new CC3());} if(name=="up"){return Cesium.Matrix3.getColumn(GD_rot_transform,2,new CC3());} }function move(scalar,unitVector){ var mycarte = thebox._position._value; var relMove = CC3.multiplyByScalar(unitVector,scalar,new CC3()); CC3.add(mycarte,relMove,mycarte); thebox.position = mycarte; var mycarto = new Cesium.Cartographic(); mycarto = viewer.scene.globe.ellipsoid.cartesianToCartographic(thebox._position._value); console.log("lon "+mycarto.longitude/Math.PI*180); console.log("lat "+mycarto.latitude/Math.PI*180); console.log("alt "+mycarto.height);}Sandcastle.addToolbarButton('magnitude 1', function() {magnitude=1;});Sandcastle.addToolbarButton('magnitude 10', function() {magnitude=10;});
Sandcastle.addToolbarButton('east', function() {move(magnitude,getVector("east"));});Sandcastle.addToolbarButton('west', function() {move(-magnitude,getVector("east"));});Sandcastle.addToolbarButton('north', function() {move(magnitude,getVector("north"));});Sandcastle.addToolbarButton('south', function() {move(-magnitude,getVector("north"));});Sandcastle.addToolbarButton('up', function() {move(magnitude,getVector("up"));});Sandcastle.addToolbarButton('down', function() {move(-magnitude,getVector("up"));});
var viewer = new Cesium.Viewer('cesiumContainer', { infoBox : false, selectionIndicator : false, terrainProviderViewModels: terrainModels, selectedTerrainProviderViewModel: terrainModels[1] // Select STK High-res terrain });
All I did was remove the two "false" lines.
var viewer = new Cesium.Viewer('cesiumContainer', { terrainProviderViewModels: terrainModels, selectedTerrainProviderViewModel: terrainModels[1] // Select STK High-res terrain });Here is the new URL http://vcities.ite-stl.org/Cesium/Apps/Sandcastle/gallery/Block512.htmlThe buildings on the right have some play information. Eventually there will be some building history. I also began to move buildings to ground level.
--
You received this message because you are subscribed to the Google Groups "cesium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cesium-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
var building28 = viewer.entities.add({ id: "building28", name:"Firehouse 512 Built 1888-Demolished 1932", availability : new Cesium.TimeIntervalCollection([new Cesium.TimeInterval({ start : Cesium.JulianDate.fromIso8601("1888-01-01"), stop : Cesium.JulianDate.fromIso8601("1932-01-01") })]), position: Cesium.Cartesian3.fromDegrees(-90.20276954596574 ,38.63089539292937,118.2), model:{ uri:'../../SampleData/models512/90359.gltf' } }
--
I should have read the entity doc first https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/DataSources/Entity.js#L94 I noticed that the green selector is off center on some of the buildings (year 1919 west side.) I'm guessing that's where the model origin is. Is there a way to offset that?
--
In Cesium 1.7: "Added camera-terrain collision detection/response when the camera reference frame is set." I think you can turn this off, but I don't know which var to set.