You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

加载带gxTrack的KML时Cesium相机追踪位置偏移问题问询

Cesium加载含gx:Track的KML时相机追踪位置偏移问题

加载包含gx:Track的KML文件时,Cesium相机追踪的位置与trackedEntity的实际位置存在明显偏移:

  • 实体本身带有高度属性,但追踪位置始终处于实体与地面之间,明显低于实体
  • 偏移量随实体高度增加而增大,怀疑是单位转换错误导致

问题表现

旋转相机时,高海拔的追踪实体容易移出屏幕(绿色方块为相机追踪位置):
相机追踪位置偏移示意图

相关代码

const viewer = new Cesium.Viewer("cesiumContainer");
const options = {
  camera: viewer.scene.camera,
  canvas: viewer.scene.canvas,
  screenOverlayContainer: viewer.container,
};

Sandcastle.addToolbarMenu(
  [
    {
      text: "gx KML extensions - Bike Ride",
      onselect: function () {
        viewer.dataSources
          .add(
            Cesium.KmlDataSource.load(
              "目标KML文件路径",
              options
            )
          )
          .then(function (dataSource) {
            viewer.clock.shouldAnimate = false;
            const rider = dataSource.entities.getById("tour");
            viewer.flyTo(rider).then(function () {
              viewer.trackedEntity = rider;
              viewer.selectedEntity = viewer.trackedEntity;
              viewer.clock.multiplier = 30;
              viewer.clock.shouldAnimate = true;
            });
          });
      },
    },
  ],
  "toolbar"
);

Sandcastle.reset = function () {
  viewer.dataSources.removeAll();
  viewer.clock.clockRange = Cesium.ClockRange.UNBOUNDED;
  viewer.clock.clockStep = Cesium.ClockStep.SYSTEM_CLOCK;
};

KML文件说明

经确认KML文件本身无问题,在Google Earth中可正常运行,核心内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
  <Folder>
    <Folder>
      <name>N367LJ track</name>
      <Placemark id="tour">
        <name>N367LJ</name>
        <Style>
          <LineStyle>
            <color>ff1c1ae3</color>
            <width>4</width>
          </LineStyle>
          <IconStyle>
            <Icon>
              <href>http://maps.google.com/mapfiles/kml/shapes/airports.png</href>
            </Icon>
          </IconStyle>
        </Style>
        <gx:Track>
          <altitudeMode>absolute</altitudeMode>
          <extrude>1</extrude>
          <when>2023-12-01T17:30:47.324Z</when>
          <when>2023-12-01T17:30:47.324Z</when>
          <when>2023-12-01T17:30:49.984Z</when>
          <!-- 省略更多时间节点 -->
          <gx:coord>-70.778242 42.868326 1105</gx:coord>
          <gx:coord>-70.778242 42.868326 1105</gx:coord>
          <gx:coord>-70.78076 42.870712 1074</gx:coord>
          <!-- 省略更多坐标节点 -->
        </gx:Track>
      </Placemark>
    </Folder>
  </Folder>
</kml>

内容的提问来源于stack exchange,提问作者John Wiseman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 07:15:59