Skip to content

Commit

Permalink
Update Sandcastle demo to not trigger infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Sep 26, 2018
1 parent e253de6 commit 9c8c800
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions Apps/Sandcastle/gallery/Clamp to 3D Model.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
shadows : true,
shouldAnimate : true
});
viewer.scene.globe.depthTestAgainstTerrain = true;
var scene = viewer.scene;
scene.globe.depthTestAgainstTerrain = true;

var longitude = -2.1480545852753163;
var latitude = 0.7688240036937101;
Expand All @@ -49,8 +50,9 @@
}
});

viewer.trackedEntity = entity;

var point = viewer.entities.add({
position : new Cesium.CallbackProperty(updatePosition, false),
point : {
pixelSize : 10,
color : Cesium.Color.YELLOW,
Expand All @@ -70,12 +72,18 @@
var objectsToExclude = [point];
var cartographic = new Cesium.Cartographic();

function updatePosition(time, result) {
if (scene.sampleHeightSupported) {
scene.postRender.addEventListener(updatePosition);
} else {
console.log('This browser does not support sampleHeight.');
}

function updatePosition(scene, time) {
var offset = (time.secondsOfDay % duration) / duration;
cartographic.longitude = longitude - range + offset * range * 2.0;
cartographic.latitude = latitude;

var height = viewer.scene.sampleHeight(cartographic, objectsToExclude);
var height = scene.sampleHeight(cartographic, objectsToExclude);

if (Cesium.defined(height)) {
cartographic.height = height;
Expand All @@ -86,9 +94,8 @@
point.label.show = false;
}

return Cesium.Cartographic.toCartesian(cartographic, Cesium.Ellipsoid.WGS84, result);
point.position = Cesium.Cartographic.toCartesian(cartographic, Cesium.Ellipsoid.WGS84);
}
viewer.trackedEntity = entity;
//Sandcastle_End
Sandcastle.finishedLoading();
}
Expand Down

0 comments on commit 9c8c800

Please sign in to comment.