export class CesiumAddHeat { viewer: any; data: any; constructor(options: { viewer: any; data: any; }) { this.viewer = options.viewer; this.data = options.data; } formatterGeoJSON(data: any) { let featrueObj: any = { type: "FeatureCollection", features: [] } data.forEach((item: { LNG: any; LAT: any; }) => { featrueObj.features.push( { "type": "Feature", "geometry": { "type": "Point", "coordinates": [Number(item.LNG), Number(item.LAT)] }, "properties": item }, ) }) return featrueObj; } init() { let data = this.formatterGeoJSON(this.data); let that = this; var promiseroute = Cesium.GeoJsonDataSource.load(data); //请求成功之后加载数据 promiseroute.then(function (dataSource: { clustering: { enabled: boolean; pixelRange: number; minimumClusterSize: number; }; entities: { values: any[]; }; }) { that.viewer.dataSources.add(dataSource); //设置展示方式是否为聚合点位 dataSource.clustering.enabled = true; //设置像素范围以扩展屏幕空间边界框。 dataSource.clustering.pixelRange = 15; //设置可以群集的最小屏幕空间对象数 dataSource.clustering.minimumClusterSize = 3; //设置完将geojson数据传入设置据合之后的点位图片 that.setClusterEvent(dataSource); //设置每个entites的布告板 dataSource.entities.values.forEach(entity => { entity.billboard.image = dangerImgCart entity.billboard.width = 20; entity.billboard.height = 20; // entity.cameraCode = entity._properties.CAMERACODE._value;//设置entity的属性 // entity.type = "cluster"; //如果有高度信息 需要重新赋值 // let cartographic = Cesium.Cartographic.fromCartesian(entity.position._value); // let longitude = Cesium.Math.toDegrees(cartographic.longitude); // let latitude = Cesium.Math.toDegrees(cartographic.latitude); // entity.position = Cesium.Cartesian3.fromDegrees(longitude, latitude, Number(entity._properties.Z._value)); }); }) } setClusterEvent(dataSource: { clustering: any; entities?: { values: any[]; }; }) { console.log(dataSource) //据合数据的监听事件 let removeListener = dataSource.clustering.clusterEvent.addEventListener( function (clusteredEntities: any, cluster: any) { //聚合图示范显示布告板 cluster.billboard.show = true; //是否显示文字总数 cluster.label.show = false; cluster.billboard.id = cluster.label.id; cluster.billboard.verticalOrigin = Cesium.VerticalOrigin.BOTTOM; //设置不同量级的符号表达方式 if (clusteredEntities.length >= 300) { cluster.billboard.image = clusterImg300; } else if (clusteredEntities.length >= 150) { cluster.billboard.image = clusterImg150; } else if (clusteredEntities.length >= 90) { cluster.billboard.image = clusterImg90; } else if (clusteredEntities.length >= 30) { cluster.billboard.image = clusterImg30; } else if (clusteredEntities.length > 10) { cluster.billboard.image = clusterImg10; } else { // cluster.billboard.image = "./images/cluser/" + clusteredEntities.length + ".png"; cluster.billboard.image = clusterImg[clusteredEntities.length - 1] } } ); } }
正文
Cesium聚合图
文章版权声明:除非注明,否则均为
譬如朝露_策温技术开发工作室博客原创文章,转载或复制请以超链接形式并注明出处。
发表评论
侧栏公告
寄语
譬如朝露博客是一个分享前端知识的网站,联系方式11523518。
热评文章
标签列表
热门文章
友情链接