思路就是渲染出空div使用getElementsByClassName找到点,之后使用insertAdjacentHTML(‘beforeend’, div) 加自定义内容

  const el = document.createElement('div');
  // 添加一个标记
  el.className = 'j_icon';
	const itemIcon = new MapboxGl.Marker({
		element: el,
  })
  .setLngLat(marker.geometry.coordinates)
  .addTo(this.map);
  this.renderHTML(document.getElementsByClassName('J_ICON_BOX'));

  renderHTML(domList) {
        domList.forEach(item => {
        // 自定义内容
          const div = `
            <div 
              style="
              font-family: PingFangSC-Medium;
              font-size: 18px;
              text-align: center;
              font-weight: 500;
              position: absolute;
              top: 7px;
              ">xxxxx
            </div>
          `;
          item.insertAdjacentHTML('beforeend', div);
        });
      }

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注