便签锚点贴到地形表面,修复放大旋转时的漂移
This commit is contained in:
@@ -299,6 +299,7 @@ export class CesiumGlobe {
|
|||||||
viewer.clock.shouldAnimate = false;
|
viewer.clock.shouldAnimate = false;
|
||||||
|
|
||||||
this._buildMarkers();
|
this._buildMarkers();
|
||||||
|
this._clampMarkersToTerrain();
|
||||||
this._setupPick();
|
this._setupPick();
|
||||||
this._setupRightRestore();
|
this._setupRightRestore();
|
||||||
this._loadBoundaries();
|
this._loadBoundaries();
|
||||||
@@ -327,6 +328,8 @@ export class CesiumGlobe {
|
|||||||
const noteNormal = makeStickyNote(entry.name, 16, false);
|
const noteNormal = makeStickyNote(entry.name, 16, false);
|
||||||
const noteSelected = makeStickyNote(entry.name, 16, true);
|
const noteSelected = makeStickyNote(entry.name, 16, true);
|
||||||
this.markers.push({
|
this.markers.push({
|
||||||
|
lng: entry.lng,
|
||||||
|
lat: entry.lat,
|
||||||
position,
|
position,
|
||||||
r2: Cesium.Cartesian3.magnitudeSquared(position),
|
r2: Cesium.Cartesian3.magnitudeSquared(position),
|
||||||
noteNormal,
|
noteNormal,
|
||||||
@@ -337,6 +340,29 @@ export class CesiumGlobe {
|
|||||||
this._initMarkerLayer();
|
this._initMarkerLayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 把便签锚点贴到地形表面(否则在椭球面高度 0 上,放大旋转时会飘)
|
||||||
|
async _clampMarkersToTerrain() {
|
||||||
|
const scene = this.viewer.scene;
|
||||||
|
if (!scene || !scene.globe) return;
|
||||||
|
const cartos = this.markers.map((m) =>
|
||||||
|
Cesium.Cartographic.fromDegrees(m.lng, m.lat),
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
await scene.sampleHeightMostDetailed(cartos);
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('[CesiumGlobe] 地形高度采样失败,便签保持椭球面高度:', err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (let i = 0; i < this.markers.length; i++) {
|
||||||
|
const h = cartos[i] && cartos[i].height;
|
||||||
|
if (h != null && isFinite(h)) {
|
||||||
|
const m = this.markers[i];
|
||||||
|
m.position = Cesium.Cartesian3.fromDegrees(m.lng, m.lat, h);
|
||||||
|
m.r2 = Cesium.Cartesian3.magnitudeSquared(m.position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 便签用 DOM 覆盖层渲染:始终在城市/国家名上层,且缩放到最近也不会漂移
|
// 便签用 DOM 覆盖层渲染:始终在城市/国家名上层,且缩放到最近也不会漂移
|
||||||
_initMarkerLayer() {
|
_initMarkerLayer() {
|
||||||
const container = document.getElementById('cesium-container');
|
const container = document.getElementById('cesium-container');
|
||||||
|
|||||||
Reference in New Issue
Block a user