当前位置: 首页 > article >正文

vue中opanlayers使用overlay插入div到地图

vue中opanlayers使用overlay插入div到地图
效果:
在这里插入图片描述

代码:

/**
   * 加载网格不通过原因的标注
   */
  loadUnpassReason(unpassReason) {
    if (unpassReason) {
      // 加载不通过原因的标注-加载到格网的中心点上
      this.loadOverlay(unpassReason);
    } else {
      // 清除不通过原因标注
      this.removeOverlay();
    }
  }
  
/**
   * 生成unpassReason显示的div
   * @param unpassReason
   */
  generateDiv(unpassReason) {
    // 创建一个div元素
    const divElement = document.createElement('div');

    // 设置div的属性和样式
    divElement.id = 'areaCenterDiv';
    divElement.style.zIndex = '99999';
    divElement.style.background = 'rgba(255, 255, 255, 1)';
    divElement.style.borderRadius = '10px';
    divElement.style.padding = '5px 8px';

    // 创建一个显示文本的元素
    const textElement = document.createElement('div');
    textElement.innerText = unpassReason;
    textElement.style.fontSize = '13px';
    textElement.style.color = 'black';
    textElement.style.textAlign = 'center';
    textElement.style.margin = '0 3px';
    divElement.appendChild(textElement);

    return divElement;
  }

/**
   * 加载overlay到地图
   */
  loadOverlay(unpassReason) {
    this.removeOverlay();
    const centerCoordinate = this.map.getView().getCenter();
    // 创建一个Overlay对象
    const overlay = new Overlay({
      element: this.generateDiv(unpassReason),
      positioning: 'center-center',
      stopEvent: false,
      position: centerCoordinate, // 设置Overlay对象的位置
      id: 11,
    });

    this.state.overlay = overlay;

    // 将Overlay添加到地图中
    this.map.addOverlay(overlay);
  }

/**
   * 移除地图上区域所有的中心点div
   */
  removeOverlay() {
    if (this.state.overlay) {
      this.map.removeOverlay(this.state.overlay);
    }
    this.state.overlay = null;
  }

http://www.kler.cn/a/349139.html

相关文章:

  • live2d 实时虚拟数字人形象页面显示,对接大模型
  • LeetCode讲解篇之2266. 统计打字方案数
  • Python之openpyxl读写 Excel 文件教程
  • 面试-2024年7月16号
  • springboot根据id编辑用户账号信息
  • Zsh 安装与配置
  • 电子取证新视角:USB键盘流量提取密码方法研究与实现
  • Python脚本爬取目标网站上的所有链接
  • 低代码工单管理app评测,功能与效率解析
  • LangChain使用Prompt02
  • Matlab实现野马优化算法优化回声状态网络模型 (WHO-ESN)(附源码)
  • 算法:238.除自身以外数组的乘积
  • 浙大数据结构:11-散列3 QQ帐户的申请与登陆
  • 植物大战僵尸杂交版
  • 运行Springboot + Vue 项目
  • 回归本真 治愈心灵——汪青《在西行的路上》
  • 地平线与英伟达工具链 PTQ 工具功能参数对比与实操
  • Linux下以编译源码的方式安装Qt5与Qt6及其使用
  • AB路线——BFS+分层图
  • Git---Git打标签