331 lines
11 KiB
HTML
331 lines
11 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<!-- Use correct character set. -->
|
||
<meta charset="utf-8" />
|
||
<!-- Tell IE to use the latest, best version. -->
|
||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||
<!-- Make the application on mobile take up the full browser screen and disable user scaling. -->
|
||
<meta
|
||
name="viewport"
|
||
content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"
|
||
/>
|
||
<title>天地图三维服务</title>
|
||
<!-- <script src="./Build168/Cesium/Cesium.js"></script> -->
|
||
<script src="./Build/Cesium/Cesium.js"></script>
|
||
<!-- 添加天地图的cesium的扩展插件,目前支持cesuim1.52、1.58、1.63.1。 -->
|
||
<script src="http://api.tianditu.gov.cn/cdn/plugins/cesium/cesiumTdt.js"></script>
|
||
<style>
|
||
@import url(./Build/Cesium/Widgets/widgets.css);
|
||
html,
|
||
body,
|
||
#cesiumContainer {
|
||
width: 100%;
|
||
height: 100%;
|
||
margin: 0;
|
||
padding: 0;
|
||
overflow: hidden;
|
||
}
|
||
#credit {
|
||
display: none;
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div id="cesiumContainer"></div>
|
||
<div id="credit"></div>
|
||
<script>
|
||
Cesium.Ion.defaultAccessToken =
|
||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI5ZjRjNTZkNC01NDYxLTRhMjQtOGEwZC1kZjA3YzQ5YTJlZDkiLCJpZCI6MjYwODQsInNjb3BlcyI6WyJhc3IiLCJnYyJdLCJpYXQiOjE1ODcxOTMwODN9.prGsSKyAW_9Ow5zHYPhbm3LsQL-ApQw5-5PNJkDaHi8";
|
||
|
||
var token = "bf156eb3c72350d62b008dc8a4ae1016";
|
||
// 服务域名
|
||
var tdtUrl = "https://t{s}.tianditu.gov.cn/";
|
||
// 服务负载子域,天地图地图服务二级域名包括t0-t7,可以随机选择使用,如http://t2.tianditu.gov.cn/vec_c/wmts?tk=您的密钥
|
||
var subdomains = ["0", "1", "2", "3", "4", "5", "6", "7"];
|
||
/**
|
||
* Viewer对象
|
||
* 用于构建应用程序的基本小部件。它将所有标准的Cesium部件组合到一个可重用的包中。
|
||
* 小部件可以通过使用mixin来扩展,来添加对各种应用程序有用的功能
|
||
*/
|
||
//Initialize the viewer widget with several custom options and mixins.
|
||
var viewer = new Cesium.Viewer("cesiumContainer", {
|
||
/**
|
||
* 场景模式,默认SceneMode.SCENE3D
|
||
* SceneMode:指定场景是3D/2D/2.5D,可选值:
|
||
* MORPHING:在模式之间变形,如3D转2D
|
||
* COLUMBUS_VIEW:2.5D视角,地图会被平铺,高度为非零的对象被绘制在上面。
|
||
* SCENE2D:2D模式,地图会被自顶向下正射投影
|
||
* SCENE3D:3D模式,一个传统的三维视角的全球。
|
||
*/
|
||
// sceneMode : Cesium.SceneMode.COLUMBUS_VIEW,
|
||
sceneMode: Cesium.SceneMode.SCENE3D,
|
||
//指定椭球面提供地形或其他几何图形数据,
|
||
terrainProvider: Cesium.createWorldTerrain(),
|
||
//指定影像数据的数据源,该选项只有在baseLayerPicker设置为false时生效
|
||
// imageryProvider : new Cesium.OpenStreetMapImageryProvider({
|
||
// url : 'https://a.tile.openstreetmap.org/'
|
||
// }),
|
||
//设置背景,如果为false则星星/月亮/太阳都不会渲染
|
||
// skyBox : new Cesium.SkyBox({
|
||
// sources : {
|
||
// positiveX : 'stars/100_BK.jpg',
|
||
// negativeX : 'stars/100_BK.jpg',
|
||
// positiveY : 'stars/100_BK.jpg',
|
||
// negativeY : 'stars/100_BK.jpg',
|
||
// positiveZ : 'stars/100_BK.jpg',
|
||
// negativeZ : 'stars/100_BK.jpg'
|
||
// }
|
||
// }),
|
||
// Show Columbus View map with Web Mercator projection
|
||
mapProjection: new Cesium.WebMercatorProjection(),
|
||
|
||
geocoder: false, //位置查找
|
||
homeButton: false, //视图返回初始位置
|
||
sceneModePicker: false, //视角选择器
|
||
baseLayerPicker: false, //底图选择器
|
||
navigationHelpButton: false, //导航帮助按钮
|
||
animation: false, //动画控制器
|
||
creditContainer: "credit", //版权显示,指定dom对象的id,再通过id样式可以隐藏CESIUM 版本图标
|
||
timeline: false, //时间线
|
||
fullscreenButton: false, //全屏控件
|
||
vrButton: false,
|
||
selectionIndicator: false,
|
||
// infoBox:false
|
||
// shouldAnimate:true
|
||
scene3DOnly: true, //默认false,若为true,所有几何体实例将仅会在3D模式中渲染(在GPU内存中)
|
||
});
|
||
|
||
// 叠加影像服务
|
||
var imgMap = new Cesium.UrlTemplateImageryProvider({
|
||
url: tdtUrl + "DataServer?T=img_w&x={x}&y={y}&l={z}&tk=" + token,
|
||
subdomains: subdomains,
|
||
tilingScheme: new Cesium.WebMercatorTilingScheme(),
|
||
maximumLevel: 18,
|
||
});
|
||
viewer.imageryLayers.addImageryProvider(imgMap);
|
||
|
||
// 叠加国界服务
|
||
var iboMap = new Cesium.UrlTemplateImageryProvider({
|
||
url: tdtUrl + "DataServer?T=ibo_w&x={x}&y={y}&l={z}&tk=" + token,
|
||
subdomains: subdomains,
|
||
tilingScheme: new Cesium.WebMercatorTilingScheme(),
|
||
maximumLevel: 10,
|
||
});
|
||
viewer.imageryLayers.addImageryProvider(iboMap);
|
||
|
||
// 叠加地形服务
|
||
var terrainUrls = new Array();
|
||
|
||
for (var i = 0; i < subdomains.length; i++) {
|
||
var url =
|
||
tdtUrl.replace("{s}", subdomains[i]) +
|
||
"DataServer?T=elv_c&tk=" +
|
||
token;
|
||
terrainUrls.push(url);
|
||
}
|
||
|
||
var provider = new Cesium.GeoTerrainProvider({
|
||
urls: terrainUrls,
|
||
});
|
||
|
||
viewer.terrainProvider = provider;
|
||
|
||
// 将三维球定位到中国
|
||
viewer.camera.flyTo({
|
||
destination: Cesium.Cartesian3.fromDegrees(103.84, 31.15, 17850000),
|
||
orientation: {
|
||
heading: Cesium.Math.toRadians(348.4202942851978),
|
||
pitch: Cesium.Math.toRadians(-89.74026687972041),
|
||
roll: Cesium.Math.toRadians(0),
|
||
},
|
||
complete: function callback() {
|
||
// 定位完成之后的回调函数
|
||
},
|
||
});
|
||
|
||
// 叠加三维地名服务
|
||
var wtfs = new Cesium.GeoWTFS({
|
||
viewer,
|
||
subdomains: subdomains,
|
||
metadata: {
|
||
boundBox: {
|
||
minX: -180,
|
||
minY: -90,
|
||
maxX: 180,
|
||
maxY: 90,
|
||
},
|
||
minLevel: 1,
|
||
maxLevel: 20,
|
||
},
|
||
aotuCollide: true, //是否开启避让
|
||
collisionPadding: [5, 10, 8, 5], //开启避让时,标注碰撞增加内边距,上、右、下、左
|
||
serverFirstStyle: true, //服务端样式优先
|
||
labelGraphics: {
|
||
font: "28px sans-serif",
|
||
fontSize: 28,
|
||
fillColor: Cesium.Color.WHITE,
|
||
scale: 0.5,
|
||
outlineColor: Cesium.Color.BLACK,
|
||
outlineWidth: 5,
|
||
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
|
||
showBackground: false,
|
||
backgroundColor: Cesium.Color.RED,
|
||
backgroundPadding: new Cesium.Cartesian2(10, 10),
|
||
horizontalOrigin: Cesium.HorizontalOrigin.MIDDLE,
|
||
verticalOrigin: Cesium.VerticalOrigin.TOP,
|
||
eyeOffset: Cesium.Cartesian3.ZERO,
|
||
pixelOffset: new Cesium.Cartesian2(0, 8),
|
||
},
|
||
billboardGraphics: {
|
||
horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
|
||
verticalOrigin: Cesium.VerticalOrigin.CENTER,
|
||
eyeOffset: Cesium.Cartesian3.ZERO,
|
||
pixelOffset: Cesium.Cartesian2.ZERO,
|
||
alignedAxis: Cesium.Cartesian3.ZERO,
|
||
color: Cesium.Color.WHITE,
|
||
rotation: 0,
|
||
scale: 1,
|
||
width: 18,
|
||
height: 18,
|
||
},
|
||
});
|
||
|
||
//三维地名服务,使用wtfs服务
|
||
wtfs.getTileUrl = function () {
|
||
return tdtUrl + "mapservice/GetTiles?lxys={z},{x},{y}&tk=" + token;
|
||
};
|
||
|
||
wtfs.getIcoUrl = function () {
|
||
return tdtUrl + "mapservice/GetIcon?id={id}&tk=" + token;
|
||
};
|
||
|
||
wtfs.initTDT([
|
||
{
|
||
x: 6,
|
||
y: 1,
|
||
level: 2,
|
||
boundBox: { minX: 90, minY: 0, maxX: 135, maxY: 45 },
|
||
},
|
||
{
|
||
x: 7,
|
||
y: 1,
|
||
level: 2,
|
||
boundBox: { minX: 135, minY: 0, maxX: 180, maxY: 45 },
|
||
},
|
||
{
|
||
x: 6,
|
||
y: 0,
|
||
level: 2,
|
||
boundBox: { minX: 90, minY: 45, maxX: 135, maxY: 90 },
|
||
},
|
||
{
|
||
x: 7,
|
||
y: 0,
|
||
level: 2,
|
||
boundBox: { minX: 135, minY: 45, maxX: 180, maxY: 90 },
|
||
},
|
||
{
|
||
x: 5,
|
||
y: 1,
|
||
level: 2,
|
||
boundBox: { minX: 45, minY: 0, maxX: 90, maxY: 45 },
|
||
},
|
||
{
|
||
x: 4,
|
||
y: 1,
|
||
level: 2,
|
||
boundBox: { minX: 0, minY: 0, maxX: 45, maxY: 45 },
|
||
},
|
||
{
|
||
x: 5,
|
||
y: 0,
|
||
level: 2,
|
||
boundBox: { minX: 45, minY: 45, maxX: 90, maxY: 90 },
|
||
},
|
||
{
|
||
x: 4,
|
||
y: 0,
|
||
level: 2,
|
||
boundBox: { minX: 0, minY: 45, maxX: 45, maxY: 90 },
|
||
},
|
||
{
|
||
x: 6,
|
||
y: 2,
|
||
level: 2,
|
||
boundBox: { minX: 90, minY: -45, maxX: 135, maxY: 0 },
|
||
},
|
||
{
|
||
x: 6,
|
||
y: 3,
|
||
level: 2,
|
||
boundBox: { minX: 90, minY: -90, maxX: 135, maxY: -45 },
|
||
},
|
||
{
|
||
x: 7,
|
||
y: 2,
|
||
level: 2,
|
||
boundBox: { minX: 135, minY: -45, maxX: 180, maxY: 0 },
|
||
},
|
||
{
|
||
x: 5,
|
||
y: 2,
|
||
level: 2,
|
||
boundBox: { minX: 45, minY: -45, maxX: 90, maxY: 0 },
|
||
},
|
||
{
|
||
x: 4,
|
||
y: 2,
|
||
level: 2,
|
||
boundBox: { minX: 0, minY: -45, maxX: 45, maxY: 0 },
|
||
},
|
||
{
|
||
x: 3,
|
||
y: 1,
|
||
level: 2,
|
||
boundBox: { minX: -45, minY: 0, maxX: 0, maxY: 45 },
|
||
},
|
||
{
|
||
x: 3,
|
||
y: 0,
|
||
level: 2,
|
||
boundBox: { minX: -45, minY: 45, maxX: 0, maxY: 90 },
|
||
},
|
||
{
|
||
x: 2,
|
||
y: 0,
|
||
level: 2,
|
||
boundBox: { minX: -90, minY: 45, maxX: -45, maxY: 90 },
|
||
},
|
||
{
|
||
x: 0,
|
||
y: 1,
|
||
level: 2,
|
||
boundBox: { minX: -180, minY: 0, maxX: -135, maxY: 45 },
|
||
},
|
||
{
|
||
x: 1,
|
||
y: 0,
|
||
level: 2,
|
||
boundBox: { minX: -135, minY: 45, maxX: -90, maxY: 90 },
|
||
},
|
||
{
|
||
x: 0,
|
||
y: 0,
|
||
level: 2,
|
||
boundBox: { minX: -180, minY: 45, maxX: -135, maxY: 90 },
|
||
},
|
||
]);
|
||
|
||
//Add basic drag and drop functionality
|
||
viewer.extend(Cesium.viewerDragDropMixin);
|
||
|
||
//Show a pop-up alert if we encounter an error when processing a dropped file
|
||
viewer.dropError.addEventListener(function (dropHandler, name, error) {
|
||
console.log(error);
|
||
window.alert(error);
|
||
});
|
||
</script>
|
||
</body>
|
||
</html>
|