learning_cesium/加载WFS线要素.html

122 lines
5.3 KiB
HTML
Raw Normal View History

2024-03-19 18:06:25 +08:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<script src="./Build/Cesium/Cesium.js"></script>
<link href="./Build/Cesium/Widgets/widgets.css" rel="stylesheet" />
<style>
@import url(./Build/Cesium/Widgets/widgets.css);
html,
body,
#cesiumContainer {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
</style>
</head>
<body>
<div id="cesiumContainer"></div>
<script>
Cesium.Ion.defaultAccessToken =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI5ZjRjNTZkNC01NDYxLTRhMjQtOGEwZC1kZjA3YzQ5YTJlZDkiLCJpZCI6MjYwODQsInNjb3BlcyI6WyJhc3IiLCJnYyJdLCJpYXQiOjE1ODcxOTMwODN9.prGsSKyAW_9Ow5zHYPhbm3LsQL-ApQw5-5PNJkDaHi8";
var viewer = new Cesium.Viewer("cesiumContainer", {
// terrainProvider: Cesium.createWorldTerrain({
// requestVertexNormal: true, //添加地形光照
// requestWaterMask: true, //添加水面波浪效果
// }),
// baseLayerPicker: false, //底图选择器
// mapProjection : new Cesium.WebMercatorProjection(),
// geocoder:false,//位置查找
// homeButton:false,//视图返回初始位置
// sceneModePicker:false,//视角选择器
// navigationHelpButton:false,//导航帮助按钮
// animation:false,//动画控制器
// // creditContainer:"credit",//版权显示,指定dom对象的id,再通过id样式可以隐藏CESIUM 版本图标
// timeline:false,//时间线
// fullscreenButton:false,//全屏控件
// vrButton:false,
// infoBox:true ,
// shouldAnimate:true,
// scene3DOnly:true,//默认false若为true,所有几何体实例将仅会在3D模式中渲染(在GPU内存中)
// terrainProvider: Cesium.createWorldTerrain({
// requestVertexNormal: true, //添加地形光照
// requestWaterMask: true, //添加水面波浪效果
// }),
});
viewer.imageryLayers.removeAll();
// 添加 Mapbox tile provider
const mapboxAccess =
"pk.eyJ1IjoicWl1c2hpamllIiwiYSI6ImNsMDNvdDRybDEyc2YzZG9kbWZoY2FuOW0ifQ.4FH-BUupi46Z0zQ-CEm_Ig";
// 样式id查看https://docs.mapbox.com/api/maps/styles/
// URL格式的 mapbox://styles/:owner/:style 其中 :owner 是您的 Mapbox 账户名 :style 是样式 ID 。
// 可选值streets-v10、outdoors-v10 、light-v9、dark-v9、satellite-v9、satellite-streets-v10
const mapboxStyleImagery = new Cesium.MapboxStyleImageryProvider({
styleId: "dark-v9",
accessToken: mapboxAccess,
// proxy: new Cesium.DefaultProxy("http://127.0.0.1:8080/proxy/"),
});
viewer.imageryLayers.addImageryProvider(mapboxStyleImagery);
var scene = viewer.scene;
viewer.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(114.91145257593077, 32.36093602262491,40000),
orientation: {
heading: Cesium.Math.toRadians(0),
pitch: Cesium.Math.toRadians(-90),
roll: Cesium.Math.toRadians(0),
},
});
let riverData = 'https://gisserver.tianditu.gov.cn/TDTService/wfs?service=WFS&version=1.1.0&request=GetFeature&typename=TDTService:HYDA&outputFormat=application/json&srsname=EPSG:4326&bbox=112.79159545898438,22.90008544921875,113.73092651367188,23.31207275390625,EPSG:4326';
addRiverDaa(riverData);
async function addRiverDaa(url){
const geojson = await Cesium.GeoJsonDataSource.load(url);
viewer.dataSources.add(geojson);
}
// 加载路网
// let url = "http://localhost:8088/geoserver/allRegion/ows?srsName=EPSG:4326&service=WFS&version=1.0.0&request=GetFeature&typeName=allRegion%3Aroads&maxFeatures=9999&outputFormat=application%2Fjson";
// fetch(url).then(res=>res.json()).then(result=>{
// console.log(result)
// result.features.forEach(feature=>{
// // addPloygonFeature(feature)
// addPolylineFeature(feature)
// })
// })
// function addPolylineFeature(feature){
// let geometryType = feature.geometry.type;
// let coord = feature.geometry.coordinates;
// if(geometryType == "MultiLineString"){
// coord.forEach(line=>{
// scene.primitives.add(new Cesium.Primitive({
// geometryInstances : new Cesium.GeometryInstance({
// geometry: new Cesium.PolylineGeometry({
// positions : Cesium.Cartesian3.fromDegreesArray(line.flat(2)),
// width : 1.0,
// arcType:Cesium.ArcType.RHUMB,//ArcType. GEODESIC NONE RHUMB
// // colors:[Cesium.Color.VIOLET,Cesium.Color.WHEAT,Cesium.Color.THISTLE],//指定线段每段的颜色,数量必须与线段数相同
// }),
// attributes : {
// // 通过attributes属性统一指定线段颜色
// color : Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(1.0, 1.0, 1.0, 0.6))
// },
// id:"线要素"
// }),
// appearance : new Cesium.PolylineColorAppearance({
// translucent : false
// })
// }));
// })
// }
// }
</script>
</body>
</html>