Cesium聚簇
2022/8/29 23:24:14
本文主要是介绍Cesium聚簇,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
Cesium聚簇
上篇中 已经出现了 很多图元的时候 性能优化的事 ,但是地图上 会有密密麻麻的各种图标 或者文字
这就要用到 聚簇了
var dataSourceForCluster = new Cesium.CustomDataSource('cluster'); var count = 100000; for (var i = 0; i < count; ++i) { dataSourceForCluster.entities.add({ id: "" + i, position: new Cesium.Cartesian3.fromDegrees(Math.random() * 100, Math.random() * 100, 10000), billboard: { image: '../src/assets/image/wx.png', height: 30, width: 30 } }); } var dataSourcePromise = viewer.dataSources.add(dataSourceForCluster); dataSourcePromise.then(function (dataSource) { var pixelRange = 15; var minimumClusterSize = 3; var enabled = true; dataSource.clustering.enabled = enabled; dataSource.clustering.pixelRange = pixelRange; dataSource.clustering.minimumClusterSize = minimumClusterSize; var pinBuilder = new Cesium.PinBuilder(); var pin50 = pinBuilder.fromText('50+', Cesium.Color.RED, 48).toDataURL(); var pin40 = pinBuilder.fromText('40+', Cesium.Color.ORANGE, 48).toDataURL(); var pin30 = pinBuilder.fromText('30+', Cesium.Color.YELLOW, 48).toDataURL(); var pin20 = pinBuilder.fromText('20+', Cesium.Color.GREEN, 48).toDataURL(); var pin10 = pinBuilder.fromText('10+', Cesium.Color.BLUE, 48).toDataURL(); var singleDigitPins = new Array(8); for (var i = 0; i < singleDigitPins.length; ++i) { singleDigitPins[i] = pinBuilder.fromText('' + (i + 2), Cesium.Color.VIOLET, 48).toDataURL(); } dataSource.clustering.clusterEvent.addEventListener(function (clusteredEntities, cluster) { cluster.label.show = false; cluster.billboard.show = true; cluster.billboard.id = cluster.label.id; cluster.billboard.verticalOrigin = Cesium.VerticalOrigin.BOTTOM; if (clusteredEntities.length >= 50) { cluster.billboard.image = pin50; } else if (clusteredEntities.length >= 40) { cluster.billboard.image = pin40; } else if (clusteredEntities.length >= 30) { cluster.billboard.image = pin30; } else if (clusteredEntities.length >= 20) { cluster.billboard.image = pin20; } else if (clusteredEntities.length >= 10) { cluster.billboard.image = pin10; } else { cluster.billboard.image = singleDigitPins[clusteredEntities.length - 2]; } }); });
这篇关于Cesium聚簇的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-27文件掩码什么意思?-icode9专业技术文章分享
- 2024-12-27如何使用循环来处理多个订单的退款请求,代码怎么写?-icode9专业技术文章分享
- 2024-12-27VSCode 在编辑时切换到另一个文件后再切回来如何保持在原来的位置?-icode9专业技术文章分享
- 2024-12-27Sealos Devbox 基础教程:使用 Cursor 从零开发一个 One API 替代品 审核中
- 2024-12-27TypeScript面试真题解析与实战指南
- 2024-12-27TypeScript大厂面试真题详解与解析
- 2024-12-26怎么使用nsenter命令进入容器?-icode9专业技术文章分享
- 2024-12-26导入文件提示存在乱码,请确定使用的是UTF-8编码怎么解决?-icode9专业技术文章分享
- 2024-12-26csv文件怎么设置编码?-icode9专业技术文章分享
- 2024-12-25TypeScript基础知识详解