381 lines
14 KiB
HTML
381 lines
14 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;
|
|||
|
|
}
|
|||
|
|
#river-container {
|
|||
|
|
position: absolute;
|
|||
|
|
top: 100px;
|
|||
|
|
left: 80px;
|
|||
|
|
}
|
|||
|
|
</style>
|
|||
|
|
<!-- 引入样式 -->
|
|||
|
|
<link rel="stylesheet" href="./js/elementui/index.css" />
|
|||
|
|
<!-- import Vue before Element -->
|
|||
|
|
<script src="./js/vue2710.js"></script>
|
|||
|
|
<!-- import JavaScript -->
|
|||
|
|
<script src="./js/elementui/index.js"></script>
|
|||
|
|
</head>
|
|||
|
|
<body>
|
|||
|
|
<div id="app">
|
|||
|
|
<div id="cesiumContainer"></div>
|
|||
|
|
<div id="river-container">
|
|||
|
|
<el-select v-model="value" placeholder="请选择" @change="selectRiver">
|
|||
|
|
<el-option
|
|||
|
|
v-for="item in options"
|
|||
|
|
:key="item.value"
|
|||
|
|
:label="item.label"
|
|||
|
|
:value="item.value"
|
|||
|
|
>
|
|||
|
|
</el-option>
|
|||
|
|
</el-select>
|
|||
|
|
<el-button @click="changeMode('2D')">切换成2D</el-button>
|
|||
|
|
<el-button @click="changeMode('3D')">3D</el-button>
|
|||
|
|
</div>
|
|||
|
|
<div id="credit"></div>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<script>
|
|||
|
|
new Vue({
|
|||
|
|
el: "#app",
|
|||
|
|
data() {
|
|||
|
|
return {
|
|||
|
|
options: [
|
|||
|
|
{
|
|||
|
|
value: "zhujiang",
|
|||
|
|
label: "珠江流域片",
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
value: "dongnan",
|
|||
|
|
label: "东南诸河片",
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
value: "xinan",
|
|||
|
|
label: "西南诸河片",
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
value: "neiluhe",
|
|||
|
|
label: "内陆河片",
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
value: "songliaohe",
|
|||
|
|
label: "松辽河流域片",
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
value: "haihe",
|
|||
|
|
label: "海河流域片",
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
value: "huaihe",
|
|||
|
|
label: "淮河流域片",
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
value: "huanghe",
|
|||
|
|
label: "黄河流域片",
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
value: "changjiang",
|
|||
|
|
label: "长江流域片",
|
|||
|
|
},
|
|||
|
|
],
|
|||
|
|
value: "",
|
|||
|
|
};
|
|||
|
|
},
|
|||
|
|
methods: {
|
|||
|
|
changeMode(type){
|
|||
|
|
if(type == "2D"){
|
|||
|
|
// scene.morphTo2D(0)
|
|||
|
|
const center = new Cesium.Cartesian2(viewer.scene.canvas.clientWidth / 2.0, viewer.scene.canvas.clientHeight / 2.0);
|
|||
|
|
const result = viewer.camera.pickEllipsoid(center, viewer.scene.globe.ellipsoid);
|
|||
|
|
console.log(result)
|
|||
|
|
viewer.camera.flyTo({
|
|||
|
|
destination:new Cesium.Cartesian3(result.x, result.y, result.z+1000000),
|
|||
|
|
complete:()=>{
|
|||
|
|
scene.morphTo2D(0)
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
}else if(type == "3D"){
|
|||
|
|
scene.morphTo3D(0)
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
selectRiver(riverName) {
|
|||
|
|
// this.addRiverGeojson(riverName);
|
|||
|
|
this.addRiverWms(riverName);
|
|||
|
|
},
|
|||
|
|
addRiverWms(riverName){
|
|||
|
|
const wmsProvider = new Cesium.WebMapServiceImageryProvider({
|
|||
|
|
// url: new Cesium.Resource({
|
|||
|
|
// proxy: new Cesium.DefaultProxy("http://127.0.0.1:8888/proxy/"),
|
|||
|
|
// url: "http://server.arcgisonline.com/arcgis/rest/services/Specialty/DeLorme_World_Base_Map/MapServer/WMSServer",
|
|||
|
|
// url: "http://localhost:8088/geoserver/iot/wms",
|
|||
|
|
url:"http://121.33.231.74:5097/geoserver/iot/wms",
|
|||
|
|
// }),
|
|||
|
|
layers: "iot:"+riverName+"_river",
|
|||
|
|
crs: "4326",
|
|||
|
|
rectangle: new Cesium.Rectangle(
|
|||
|
|
Cesium.Math.toRadians(102.33435821533203),
|
|||
|
|
Cesium.Math.toRadians(18.177719116210938),
|
|||
|
|
Cesium.Math.toRadians(117.17308044433594),
|
|||
|
|
Cesium.Math.toRadians(26.804235458374023)
|
|||
|
|
),
|
|||
|
|
// parameters对象可设置getMap请求中的参数
|
|||
|
|
parameters:{
|
|||
|
|
format:"image/png8",
|
|||
|
|
transparent:true
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
viewer.imageryLayers.addImageryProvider(wmsProvider);
|
|||
|
|
},
|
|||
|
|
addRiverGeojson(riverName){
|
|||
|
|
let geoUrl =
|
|||
|
|
"http://121.33.231.74:5097/geoserver/iot/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=iot%3A"+riverName+"_river&maxFeatures=999&outputFormat=application%2Fjson";
|
|||
|
|
fetch(geoUrl)
|
|||
|
|
.then((res) => res.json())
|
|||
|
|
.then((result) => {
|
|||
|
|
console.log(result)
|
|||
|
|
let primitives = viewer.scene.primitives.add(
|
|||
|
|
new Cesium.PrimitiveCollection()
|
|||
|
|
);
|
|||
|
|
primitives.show = false;
|
|||
|
|
window.primitives = primitives;
|
|||
|
|
result.features.forEach((feature) => {
|
|||
|
|
this.addWaterFeature(primitives,feature);
|
|||
|
|
});
|
|||
|
|
// this.addWaterFeature(result.features[0]);
|
|||
|
|
});
|
|||
|
|
},
|
|||
|
|
addWaterFeature(primitives,feature) {
|
|||
|
|
let geometryType = feature.geometry.type;
|
|||
|
|
let coord = feature.geometry.coordinates;
|
|||
|
|
let geometryName = feature.geometry_name;
|
|||
|
|
|
|||
|
|
|
|||
|
|
if (geometryType == "MultiPolygon") {
|
|||
|
|
coord.forEach((polygon) => {
|
|||
|
|
let outBoundary = null;
|
|||
|
|
let holes = null;
|
|||
|
|
// if(polygon.length==1){
|
|||
|
|
outBoundary = new Cesium.PolygonHierarchy(
|
|||
|
|
Cesium.Cartesian3.fromDegreesArray(polygon[0].flat(2))
|
|||
|
|
);
|
|||
|
|
// }
|
|||
|
|
primitives.add(
|
|||
|
|
new Cesium.Primitive({
|
|||
|
|
geometryInstances: new Cesium.GeometryInstance({
|
|||
|
|
geometry: new Cesium.PolygonGeometry({
|
|||
|
|
polygonHierarchy: outBoundary,
|
|||
|
|
}),
|
|||
|
|
attributes: {
|
|||
|
|
// 通过attributes属性统一指定线段颜色
|
|||
|
|
color: Cesium.ColorGeometryInstanceAttribute.fromColor(
|
|||
|
|
new Cesium.Color(1.0, 0, 0, 1.0)
|
|||
|
|
),
|
|||
|
|
},
|
|||
|
|
id: "面要素",
|
|||
|
|
}),
|
|||
|
|
appearance: new Cesium.EllipsoidSurfaceAppearance({
|
|||
|
|
material: new Cesium.Material({
|
|||
|
|
fabric: {
|
|||
|
|
type: "Water",
|
|||
|
|
uniforms: {
|
|||
|
|
// 水的基本颜色
|
|||
|
|
baseWaterColor: new Cesium.Color(
|
|||
|
|
64 / 255.0,
|
|||
|
|
157 / 255.0,
|
|||
|
|
253 / 255.0,
|
|||
|
|
0.5
|
|||
|
|
),
|
|||
|
|
// 水法向摄动的法线图
|
|||
|
|
normalMap:
|
|||
|
|
"./Build/Cesium/Assets/Textures/waterNormals.jpg",
|
|||
|
|
// 波纹数量
|
|||
|
|
frequency: 1000.0,
|
|||
|
|
// 动画速度
|
|||
|
|
animationSpeed: 0.002,
|
|||
|
|
// 振动的幅度
|
|||
|
|
amplitude: 150,
|
|||
|
|
// 镜面反射的强度
|
|||
|
|
specularIntensity: 1,
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
}),
|
|||
|
|
faceForward: true,
|
|||
|
|
}),
|
|||
|
|
})
|
|||
|
|
);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
initViewer() {
|
|||
|
|
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内存中)
|
|||
|
|
});
|
|||
|
|
viewer.imageryLayers.removeAll();
|
|||
|
|
|
|||
|
|
// 叠加影像服务
|
|||
|
|
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() {
|
|||
|
|
// 定位完成之后的回调函数
|
|||
|
|
},
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
//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);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
window.viewer = viewer;
|
|||
|
|
window.scene = viewer.scene;
|
|||
|
|
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
},
|
|||
|
|
mounted() {
|
|||
|
|
this.initViewer();
|
|||
|
|
},
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
// 叠加水系
|
|||
|
|
</script>
|
|||
|
|
</body>
|
|||
|
|
</html>
|