美文网首页
Cesium htmlOverlay

Cesium htmlOverlay

作者: zhuyx0304 | 来源:发表于2024-10-15 10:54 被阅读0次
const viewer = new Cesium.Viewer("cesiumContainer");

// To geographically place an HTML element on top of the Cesium canvas, we use
// scene.cartesianToCanvasCoordinates to map a world position to canvas x and y values.
// This example places and img element, but any element will work.

const htmlOverlay = document.getElementById("htmlOverlay");
const scratch = new Cesium.Cartesian2();
viewer.scene.preRender.addEventListener(function () {
  const position = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883);
  const canvasPosition = viewer.scene.cartesianToCanvasCoordinates(
    position,
    scratch,
  );
  if (Cesium.defined(canvasPosition)) {
    htmlOverlay.style.top = `${canvasPosition.y}px`;
    htmlOverlay.style.left = `${canvasPosition.x}px`;
  }
});

相关文章

网友评论

      本文标题:Cesium htmlOverlay

      本文链接:https://www.haomeiwen.com/subject/egqtdjtx.html