Skip to content

Commit 9c8c800

Browse files
committed
Update Sandcastle demo to not trigger infinite loop
1 parent e253de6 commit 9c8c800

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Apps/Sandcastle/gallery/Clamp to 3D Model.html

+13-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
shadows : true,
3636
shouldAnimate : true
3737
});
38-
viewer.scene.globe.depthTestAgainstTerrain = true;
38+
var scene = viewer.scene;
39+
scene.globe.depthTestAgainstTerrain = true;
3940

4041
var longitude = -2.1480545852753163;
4142
var latitude = 0.7688240036937101;
@@ -49,8 +50,9 @@
4950
}
5051
});
5152

53+
viewer.trackedEntity = entity;
54+
5255
var point = viewer.entities.add({
53-
position : new Cesium.CallbackProperty(updatePosition, false),
5456
point : {
5557
pixelSize : 10,
5658
color : Cesium.Color.YELLOW,
@@ -70,12 +72,18 @@
7072
var objectsToExclude = [point];
7173
var cartographic = new Cesium.Cartographic();
7274

73-
function updatePosition(time, result) {
75+
if (scene.sampleHeightSupported) {
76+
scene.postRender.addEventListener(updatePosition);
77+
} else {
78+
console.log('This browser does not support sampleHeight.');
79+
}
80+
81+
function updatePosition(scene, time) {
7482
var offset = (time.secondsOfDay % duration) / duration;
7583
cartographic.longitude = longitude - range + offset * range * 2.0;
7684
cartographic.latitude = latitude;
7785

78-
var height = viewer.scene.sampleHeight(cartographic, objectsToExclude);
86+
var height = scene.sampleHeight(cartographic, objectsToExclude);
7987

8088
if (Cesium.defined(height)) {
8189
cartographic.height = height;
@@ -86,9 +94,8 @@
8694
point.label.show = false;
8795
}
8896

89-
return Cesium.Cartographic.toCartesian(cartographic, Cesium.Ellipsoid.WGS84, result);
97+
point.position = Cesium.Cartographic.toCartesian(cartographic, Cesium.Ellipsoid.WGS84);
9098
}
91-
viewer.trackedEntity = entity;
9299
//Sandcastle_End
93100
Sandcastle.finishedLoading();
94101
}

0 commit comments

Comments
 (0)