Skip to content

Commit 545a24e

Browse files
committed
navigation await new pano loading
1 parent 1fff17c commit 545a24e

File tree

1 file changed

+16
-16
lines changed
  • packages/sandcastle/gallery/google-streetview-panorama-navigation

1 file changed

+16
-16
lines changed

packages/sandcastle/gallery/google-streetview-panorama-navigation/main.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ async function loadPanorama(panoId) {
3434
const streetViewPanorama = await provider.loadPanoramaFromPanoId(panoId, 3);
3535
viewer.scene.primitives.add(streetViewPanorama);
3636
positionCameraInPano(panoIdMetadata);
37+
removeOldPanoImage(streetViewPanorama);
38+
removeOtherPanoLinks();
3739
plotPanoLinks(panoIdMetadata);
3840
initialPano = false;
3941
}
@@ -128,36 +130,34 @@ function removeOtherPanoLinks() {
128130
}
129131
}
130132

133+
function removeOldPanoImage(newPanoPrimitive) {
134+
const primitives = viewer.scene.primitives;
135+
// Iterate in reverse to avoid index issues when removing
136+
for (let i = primitives.length - 1; i >= 0; i--) {
137+
const primitive = primitives.get(i);
138+
const remove =
139+
primitive instanceof Cesium.EquirectangularPanorama &&
140+
primitive !== newPanoPrimitive;
141+
if (remove) {
142+
primitives.remove(primitive);
143+
}
144+
}
145+
}
146+
131147
const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
132148

133149
handler.setInputAction((movement) => {
134150
const picked = viewer.scene.pick(movement.position);
135151

136152
if (Cesium.defined(picked) && Cesium.defined(picked.id)) {
137153
const entity = picked.id;
138-
139154
if (entity.linkId) {
140-
console.log("Clicked link:", entity.linkId);
141-
console.log("Link data:", entity.linkData);
142-
143-
const primitives = viewer.scene.primitives;
144-
// Iterate in reverse to avoid index issues when removing
145-
for (let i = primitives.length - 1; i >= 0; i--) {
146-
const primitive = primitives.get(i);
147-
const remove = primitive instanceof Cesium.EquirectangularPanorama;
148-
if (remove) {
149-
primitives.remove(primitive);
150-
}
151-
}
152-
removeOtherPanoLinks(entity.panoId);
153-
154155
loadPanorama(entity.panoId);
155156
}
156157
}
157158
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
158159

159160
// load initial scene
160-
161161
const longitude = -75.222071;
162162
const latitude = 40.027237;
163163
const height = 1; // in meters

0 commit comments

Comments
 (0)