Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
fix: fix the camera offset when keep press on zoom to layer (#335)
Browse files Browse the repository at this point in the history
fix-offset

Co-authored-by: nina992 <nouralali992@gmail.com>
  • Loading branch information
nina992 and nina992 authored Oct 27, 2022
1 parent 3af5206 commit ccec332
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,16 @@ export default function useEngineRef(
if (!viewer || viewer.isDestroyed()) return;
const e = viewer.entities.getById(layerId);
if (!e) return;
const entityPos = e.position?.getValue(viewer.clock.currentTime);
if (!entityPos) return;
const cameraPos = viewer.camera.positionWC;
const distance = Cesium.Cartesian3.distance(entityPos, cameraPos);
if (Math.round(distance * 1000) / 1000 === 5000) return;
const camera = getCamera(viewer);
const offset = new Cesium.HeadingPitchRange(
camera?.heading ?? 0,
camera?.pitch ?? -90,
50000,
5000,
);
viewer.zoomTo(e, offset);
},
Expand Down

0 comments on commit ccec332

Please sign in to comment.