Cesium实现自定义标签功能

本文档介绍如何使用Cesium库实现自定义的标签功能,类似于Popup弹窗,但允许用户定制HTML内容和CSS样式,以创建更美观的标签。标签会根据视角变化动态调整位置,并可选配一个小圆点底座。同时,提供了关闭单个标签、清除所有标签的方法。示例代码展示了标签的创建、更新和销毁过程,以及调用示例。

Cesium实现自定义标签功能

实现的底层逻辑和方法跟实现Popup弹窗功能类似,只需要修改对应的创建的html内容和css样式,即可定义出更好看的标签。

实现效果

在这里插入图片描述

源码

LabelPlot 标签类


const defaultNameField = "label";
const defaultIdField = "id";
const billboardPointDatasourceName = "LABELPLOT_BILLBOARD_POINT"

/**
 * 标签类
 */
class LabelPlot {
   
   
  constructor(info) {
   
   
    let _this = this;
    _this.viewer = info.viewer; //弹窗创建的viewer
    _this.geometry = info.position; //弹窗挂载的位置
    _this.properties = info.properties; // 属性信息
    if (!info || !info.viewer || !info.position) {
   
   
      throw new Error("缺少构造参数!");
    }

    let labelPlotId = _this._getKeyVal(info.properties,defaultIdField);
    if (!labelPlotId) {
   
   
      labelPlotId = "LabelPlot_" + (new Date().getTime() + Math.random() + '').replace('.', '');
    }
    _this.id = labelPlotId;

    _this.ctn = $("<div class='LabelPlot-container' id =  '" + _this.id + "'>");
    $(_this.viewer.container).append(_this.ctn);
    _this.ctn.append(_this._createHtml(info.properties));
    //生成底座小圆点
    if (!!info.showBillboardPoint) {
   
   
      _this.entity = _this._createBillboardPoint(info.position);
    }
    try {
   
   
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值