需要用cesium导入tiff高程图片(自行在网上下载tiff任意高程图片)在自己电脑上完成
时间: 2023-05-26 14:07:22 浏览: 150
将图片转换为tiff格式
以下是一个基本的cesium代码,用于导入tiff高程图片:
```javascript
<!DOCTYPE html>
<html lang="en">
<head>
<title>Cesium - Inserting Tiff Elevation Data</title>
<style>
@import url(../Templates/Widgets/widgets.css);
html, body, #cesiumContainer {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
#loadingOverlay {
background: rgba(57, 76, 103, 0.5);
color: #fff;
position: absolute;
top: 50%;
left: 50%;
margin: -25px 0 0 -50px;
width: 100px;
height: 50px;
text-align: center;
line-height: 50px;
z-index: 10000;
}
#loadingIndicator {
height: 50px;
width: 50px;
margin: 0 auto;
background-image: url(../Templates/Widgets/Images/loading-indicator.gif);
background-repeat: no-repeat;
background-position: center;
}
</style>
<script src="../ThirdParty/requirejs-2.1.20/require.js"></script>
<script>
require.config({
baseUrl: '../Source',
paths: {
'Cesium': '../Build/Cesium/Cesium',
'cesiumjs': '../Build/Cesium'
}
});
require([
'cesiumjs/Cesium',
'cesiumjs/Widgets/Viewer/Viewer',
'cesiumjs/Core/Cartographic',
'cesiumjs/Core/CesiumTerrainProvider',
'cesiumjs/Core/Cesium3DTileset',
'cesiumjs/Scene/SceneMode',
'cesiumjs/Scene/ImageryLayer',
'cesiumjs/Scene/Globe',
'cesiumjs/Scene/TerrainProvider'
], function (Cesium, Viewer, Cartographic, CesiumTerrainProvider, Cesium3DTileset, SceneMode, ImageryLayer, Globe, TerrainProvider) {
var viewer = new Viewer('cesiumContainer');
viewer.scene.globe.terrainProvider = new CesiumTerrainProvider({
url : 'https://assets.agi.com/stk-terrain/v1/tilesets/world/tiles',
requestVertexNormals: true
});
var tiffProvider = new CesiumTerrainProvider({
url : 'http://localhost:8000/path/to/tiff/tiles',
requestVertexNormals: true
});
viewer.scene.terrainProvider = tiffProvider;
var imageryLayer = new ImageryLayer(new Cesium.UrlTemplateImageryProvider({
url: 'https://webglobe24.de/krater/{z}/{x}/{y}.jpg',
credit: 'Krater'
}));
viewer.scene.imageryLayers.add(imageryLayer);
var globeDepth = new Globe();
var terrainProvider = new TerrainProvider();
viewer.scene.terrainProvider = tiffProvider;
var position = Cesium.Cartographic.fromDegrees(-94.4375667,39.0660454,0);
var height = tiffProvider.getHeight(position);
var cartographic = Cesium.Ellipsoid.WGS84.cartesianToCartographic(position);
cartographic.height = height;
var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, cartographic.height);
viewer.camera.position = surface;
viewer.camera.lookAt(Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, cartographic.height + 1000), new Cesium.Cartesian3(0.0, 0.0, 1.0));
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
viewer.scene.globe.depthTestAgainstTerrain = true;
var tileset = new Cesium3DTileset({
url: "./Tilesets/Batched/BatchedColors/tileset.json",
maximumMemoryUsage: 2048
});
tileset.readyPromise.then(function() {
viewer.scene.primitives.add(tileset);
viewer.camera.zoomTo(tileset);
});
});
</script>
</head>
<body>
<div id="cesiumContainer"></div>
<div id="loadingOverlay"><div id="loadingIndicator"><div class="rotating"></div></div></div>
</body>
</html>
```
需要注意的是,上面代码中的tiffProvider.url需要根据实际的tiff文件路径进行修改。由于使用Cesium导入tiff高程图片需要将其切片成小块,因此需要使用专门的软件工具进行操作。可以借助GDAL等工具或在线转换服务来实现。
阅读全文