Arcgis Elevation Terrain
Runnable Cesium example: Arcgis Elevation Terrain. Open the live demo, read the complete source, and copy the file into your project. No build step or API key.
single HTML file · CDN dependencies onlyinterface may contain Chinese labels
Source
<!--
示例:用自定义高程地形提供者生成山脉
说明:CustomHeightmapTerrainProvider 按瓦片回调返回高度数组,地形完全由数学函数算出,不请求任何地形服务
核心逻辑:tileXYToRectangle 取经纬度范围 → 正弦叠加算高程 → Float32Array 交给 provider → 赋给 terrainProvider
依赖:CesiumJS 1.121 · jsDelivr CDN,无 DEM 数据与 ion Token
-->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta name="robots" content="noindex,follow">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>代码生成高程地形</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cesium@1.121.0/Build/Cesium/Widgets/widgets.css">
<style>
html,body{height:100%;margin:0}
body{background:#0e1116;color:#e6e8ec;overflow:hidden;
font:13px/1.6 -apple-system,"Segoe UI","PingFang SC",sans-serif}
#c{height:100%}
.hud{position:absolute;left:12px;top:12px;z-index:5;background:rgba(23,28,35,.9);
border:1px solid #2a313b;border-radius:6px;padding:9px 12px;font-size:12px;
color:#a2a9b6;max-width:260px}
.hud b{color:#e6e8ec;font-weight:600}
.hud .row{margin-top:7px}
input[type=range]{width:100%}
.cesium-viewer-bottom .cesium-widget-credits,.cesium-viewer-animationContainer,
.cesium-viewer-timelineContainer{display:none!important}
</style>
</head>
<body>
<div id="c"></div>
<div class="hud">
<div><b>程序化高程地形</b></div>
<div class="row">采样 32 × 32,按瓦片实时计算</div>
<div class="row">高程振幅 <span id="ampVal">1400</span> 米</div>
<div class="row"><input id="amp" type="range" min="200" max="3000" step="100" value="1400"></div>
<div class="row">黄色折线表示贴地效果</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/cesium@1.121.0/Build/Cesium/Cesium.js"></script>
<script>
(function () {
'use strict';
var viewer = new Cesium.Viewer('c', {
baseLayer: false,
baseLayerPicker: false, geocoder: false, homeButton: false,
sceneModePicker: false, navigationHelpButton: false,
animation: false, timeline: false, fullscreenButton: false,
infoBox: false, selectionIndicator: false
});
var scene = viewer.scene;
scene.globe.baseColor = Cesium.Color.fromCssColorString('#243040');
scene.backgroundColor = Cesium.Color.fromCssColorString('#0e1116');
scene.skyBox.show = false;
scene.moon.show = false;
if (scene.skyAtmosphere) scene.skyAtmosphere.show = false;
scene.globe.enableLighting = true;
var scheme = new Cesium.GeographicTilingScheme();
var W = 32;
var H = 32;
var amplitude = 1400;
/* ---------- 每个瓦片按经纬度算高度,返回 Float32Array ---------- */
function heights(x, y, level) {
var rect = scheme.tileXYToRectangle(x, y, level);
var out = new Float32Array(W * H);
for (var j = 0; j < H; j++) {
for (var i = 0; i < W; i++) {
var lon = Cesium.Math.toDegrees(
rect.west + (rect.east - rect.west) * (i + 0.5) / W
);
var lat = Cesium.Math.toDegrees(
rect.south + (rect.north - rect.south) * (j + 0.5) / H
);
var h = amplitude *
Math.sin(lon * 0.9) * Math.cos(lat * 0.8) * 0.6 +
700 * Math.sin(lon * 2.7 + 1.2) * Math.sin(lat * 2.1) +
260 * Math.cos(lon * 6.1) * Math.sin(lat * 5.3) +
amplitude * 0.35;
out[j * W + i] = Math.max(-120, h);
}
}
return out;
}
var terrain = new Cesium.CustomHeightmapTerrainProvider({
width: W,
height: H,
tilingScheme: scheme,
callback: heights
});
viewer.terrainProvider = terrain;
/* 一条贴地的折线,用来看地形是否真的起伏 */
var linePositions = [];
for (var d = 0; d < 6; d++) {
linePositions.push(100 + d * 2.4, 30 + Math.sin(d) * 1.6, 0);
}
viewer.entities.add({
polyline: {
positions: Cesium.Cartesian3.fromDegreesArrayHeights(linePositions),
width: 3,
clampToGround: true,
material: Cesium.Color.fromCssColorString('#ffd166')
}
});
document.getElementById('amp').addEventListener('input', function () {
amplitude = parseInt(this.value, 10);
document.getElementById('ampVal').textContent = amplitude;
viewer.terrainProvider = new Cesium.CustomHeightmapTerrainProvider({
width: W,
height: H,
tilingScheme: scheme,
callback: heights
});
});
viewer.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(101, 31.5, 1120000),
orientation: {
heading: Cesium.Math.toRadians(8),
pitch: Cesium.Math.toRadians(-38),
roll: 0
},
duration: 0
});
})();
</script>
</body>
</html>
Language: the code and this page are in English; the full tutorial and API notes for this example are in Chinese. The demo itself is the authoritative version — it runs exactly as shown.