learning_cesium/wfs查询.html

97 lines
3.4 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>Learning Cesium!</title>
<script src="./Build/Cesium/Cesium.js"></script>
<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", {
geocoder: false, //位置查找
homeButton: false, //视图返回初始位置
sceneModePicker: false, //视角选择器
// baseLayerPicker:false,//底图选择器
navigationHelpButton: false, //导航帮助按钮
animation: false, //动画控制器
// creditContainer:"credit",//版权显示
timeline: false, //时间线
fullscreenButton: false, //全屏控件
vrButton: false,
});
// var tileset = new Cesium.Cesium3DTileset({
// url: "http://localhost:9000/model/61905f40603811ed87e5990e15ab1c55/tileset.json",
// dynamicScreenSpaceError: true,
// dynamicScreenSpaceErrorDensity: 0.00278,
// dynamicScreenSpaceErrorFactor: 4.0,
// dynamicScreenSpaceErrorHeightFalloff: 0.25,
// });
// viewer.scene.primitives.add(tileset);
// viewer.zoomTo(tileset);
const primitives = new Cesium.PrimitiveCollection();
let url =
"http://localhost:8088/geoserver/allRegion/ows?srsname=EPSG:4326&service=WFS&version=1.0.0&request=GetFeature&typeName=allRegion%3Ajiguan&maxFeatures=500&outputFormat=application%2Fjson";
fetch(url)
.then((res) => res.json())
.then((result) => {
let color = new Cesium.ColorGeometryInstanceAttribute(
0.0,
1.0,
0.0,
0.8
);
result.features.forEach((feature) => {
primitives.add(createPrimitiveByFeature(feature, color));
});
viewer.scene.primitives.add(primitives);
});
viewer.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(114.819454, 32.28544, 150.0),
});
function createPrimitiveByFeature(feature, color) {
let coords = feature.geometry.coordinates;
let ground = new Cesium.GroundPrimitive({
geometryInstances: new Cesium.GeometryInstance({
geometry: new Cesium.PolygonGeometry({
polygonHierarchy: new Cesium.PolygonHierarchy(
// Cesium.Cartesian3.fromDegreesArray(coords.flat(3))
2
),
}),
id: feature.properties,
attributes: { color: color },
}),
});
return ground;
}
</script>
</body>
</html>