1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
| <!DOCTYPE html> <html lang="zh-Hant-TW"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> <title>Cesium - 精確座標定位</title> <link rel="stylesheet" href="/CesiumUnminified/Widgets/widgets.css"> <style> html, body, #cesiumContainer { width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden; background-color: #000; }
/* 資訊面板樣式 */ #info-panel { position: absolute; bottom: 30px; left: 10px; background: rgba(0, 0, 0, 0.85); color: #ffffff; padding: 15px; border-radius: 8px; font-family: 'Consolas', 'Monaco', monospace; font-size: 13px; z-index: 1000; border: 1px solid rgba(255, 255, 255, 0.2); box-shadow: 0 4px 15px rgba(0,0,0,0.5); min-width: 240px; } .section-title { color: #ffcc00; font-weight: bold; margin-bottom: 8px; border-bottom: 1px solid #444; padding-bottom: 4px; } .item { margin: 4px 0; display: flex; justify-content: space-between; } .label { color: #aaa; } .value { color: #00ffcc; font-weight: bold; text-align: right; margin-left: 10px; } hr { border: 0; border-top: 1px solid #444; margin: 10px 0; }
/* 複製按鈕 */ #copy-btn { width: 100%; background: #007bff; color: white; border: none; padding: 8px; border-radius: 4px; cursor: pointer; font-weight: bold; transition: background 0.2s; margin-top: 5px; pointer-events: auto; } #copy-btn:hover { background: #0056b3; } </style> </head> <body> <div id="cesiumContainer"></div> <div id="info-panel"> <div class="section-title">📍 目前座標 (Camera)</div> <div class="item"><span class="label">緯度:</span><span id="cam-lat" class="value">-</span></div> <div class="item"><span class="label">經度:</span><span id="cam-lon" class="value">-</span></div> <div class="item"><span class="label">高度:</span><span id="cam-hgt" class="value">-</span> m</div> <hr> <div class="section-title">🎥 鏡頭角度</div> <div class="item"><span class="label">方位 (H):</span><span id="cam-heading" class="value">-</span>°</div> <div class="item"><span class="label">俯仰 (P):</span><span id="cam-pitch" class="value">-</span>°</div> <div class="item"><span class="label">翻滾 (R):</span><span id="cam-roll" class="value">-</span>°</div> <button id="copy-btn">複製目前視角資訊</button> </div>
<script>window.CESIUM_BASE_URL = '/CesiumUnminified/';</script> <script src="/CesiumUnminified/Cesium.js"></script>
<script> async function startCesium() { try { // 1. 初始化 Viewer const viewer = new Cesium.Viewer('cesiumContainer', { baseLayer: new Cesium.ImageryLayer( new Cesium.UrlTemplateImageryProvider({ url: 'https://mt1.google.com/vt/lyrs=s&x={x}&y={y}&z={z}', minimumLevel: 1, maximumLevel: 20 }) ), animation: false, timeline: false, geocoder: false, baseLayerPicker: false, scene3DOnly: true });
// 2. 【核心設定】根據你提供的參數進行開場定位 // 緯度: 21.929914, 經度: 120.845648, 高度: 122.55m viewer.camera.setView({ destination: Cesium.Cartesian3.fromDegrees(120.845648, 21.929914, 122.55), orientation: { heading: Cesium.Math.toRadians(10.20), pitch: Cesium.Math.toRadians(-13.58), roll: Cesium.Math.toRadians(360.00) // 等同於 0.0 } });
// 3. 載入地形 try { const terrainProvider = await Cesium.CesiumTerrainProvider.fromUrl('/terrain', { requestVertexNormals: true }); viewer.terrainProvider = terrainProvider; // 關鍵:開啟深度檢測,讓低空視角下地形與相機的互動更自然 viewer.scene.globe.depthTestAgainstTerrain = true; } catch (e) { console.warn("地形載入失敗"); }
// 4. 更新 UI 面板 const ui = { lon: document.getElementById('cam-lon'), lat: document.getElementById('cam-lat'), hgt: document.getElementById('cam-hgt'), head: document.getElementById('cam-heading'), pit: document.getElementById('cam-pitch'), rol: document.getElementById('cam-roll') };
function updateStats() { const camera = viewer.camera; const cartographic = Cesium.Cartographic.fromCartesian(camera.position); ui.lat.textContent = Cesium.Math.toDegrees(cartographic.latitude).toFixed(6); ui.lon.textContent = Cesium.Math.toDegrees(cartographic.longitude).toFixed(6); ui.hgt.textContent = cartographic.height.toFixed(2); ui.head.textContent = Cesium.Math.toDegrees(camera.heading).toFixed(2); ui.pit.textContent = Cesium.Math.toDegrees(camera.pitch).toFixed(2); ui.rol.textContent = Cesium.Math.toDegrees(camera.roll).toFixed(2); }
viewer.camera.changed.addEventListener(updateStats); updateStats();
// 5. 複製功能 document.getElementById('copy-btn').onclick = function() { const textToCopy = `座標: ${ui.lat.textContent}, ${ui.lon.textContent}\n` + `高度: ${ui.hgt.textContent}m\n` + `角度: H:${ui.head.textContent}°, P:${ui.pit.textContent}°, R:${ui.rol.textContent}°`; navigator.clipboard.writeText(textToCopy).then(() => { const originalText = this.innerText; this.innerText = "✅ 已複製到剪貼簿"; setTimeout(() => this.innerText = originalText, 1500); }); };
} catch (error) { console.error(error); } }
startCesium(); </script> </body> </html>
|