Cesium-Examples/examples/cesiumEx/2.3.5、海量图标.html
2025-06-12 14:10:21 +08:00

92 lines
3.7 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!--********************************************************************
* by jiawanlong
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="./../../libs/cesium/Cesium1.98/Widgets/widgets.css">
<script type="text/javascript" src="./../../libs/cesium/Cesium1.98/Cesium.js"></script>
<script src="./turf.min.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body style="margin: 0; overflow: hidden; background: #fff; width: 100%; height: 100%; position: absolute; top: 0">
<div id="map" style="margin: 0 auto; width: 100%; height: 100%"></div>
<script type="text/javascript">
Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyMjBhMzcxMC0wNjBiLTRmYjItYjY1MC0wMzAwMzMyMGUyMmEiLCJpZCI6MzAzNzc3LCJpYXQiOjE3NDc2Mzk0NTV9.E_90aKtVdzRGlU2z48VwJ4mWvl-uuDkfQBCOO6zbzn4'
const viewer = new Cesium.Viewer('map', {});
// Cesium地形
viewer.terrainProvider = Cesium.createWorldTerrain({
requestWaterMask: true, // 请求水体效果所需要的海岸线数据
requestVertexNormals: true// 请求地形照明数据
});
// 开启帧率
viewer.scene.debugShowFramesPerSecond = true;
// -------------billboardCollection方式加载-----------
// 本质就是PrimitiveCollection
// https://cesium.com/learn/cesiumjs/ref-doc/PrimitiveCollection.html
// pointPrimitiveCollection点集合
// labelCollectionlabel 集合)
var points = turf.randomPoint(50000, { bbox: [-180, -90, 180, 90] })
const billboardCollection = viewer.scene.primitives.add(
new Cesium.BillboardCollection()
);
points.features.forEach((k) => {
let cor = k.geometry.coordinates;
billboardCollection.add({
//根据距离缩放
scaleByDistance: new Cesium.NearFarScalar(2000000, 1, 8000000, 0.1),
position: Cesium.Cartesian3.fromDegrees(cor[0], cor[1]),
image: './icon.png',
width: 32,
height: 32,
});
})
// -------------entityCollection方式加载不推荐-----------
// var points = turf.randomPoint(10000, { bbox: [-180, -90, 180, 90] })
// let myEntityCollection = new Cesium.CustomDataSource("clickEntityCollection");
// viewer.dataSources.add(myEntityCollection);
// points.features.forEach((k) => {
// let cor = k.geometry.coordinates;
// var entity2 = new Cesium.Entity({
// position: Cesium.Cartesian3.fromDegrees(cor[0], cor[1]),
// billboard: {
// image: './icon.png',
// width: 32,
// height: 32,
// }
// });
// myEntityCollection.entities.add(entity2);
// })
// axios.get('./weibo.json')//读取区域json
// .then((response) => {
// response.data[0].forEach((k) => {
// let cor = k.geoCoord;
// billboardCollection.add({
// //根据距离缩放
// scaleByDistance: new Cesium.NearFarScalar(2000000, 1, 8000000, 0.1),
// position: Cesium.Cartesian3.fromDegrees(cor[0], cor[1]),
// image: './icon.png',
// width: 12,
// height: 12,
// });
// })
// })
</script>
</body>
</html>