功能场景

之前在问答提问图层中的文字如何实现的,没有合适的答案,现将问题记录一下。

例如:项目场景:示例:通过蓝牙芯片(HC-05)与手机 APP 通信,每隔 5s 传输一批传感器数据(不是很大)


实现代码

提示这里添加紫色的fill图层与黑色的边框line图层就不赘述,具体可查看上一篇文章

arr.forEach((element, index) => {
        this.map.addLayer({
          id: `${element.id}Symbol`,
          type: 'symbol',
          source: {
            type: 'geojson',
            data: {
              type: 'FeatureCollection',
              features: [
                {
                  type: 'Feature',
                  geometry: element.center,
                  properties: {
                    title: element.name
                  }
                }
              ]
            }
          },

          layout: {
            'text-field': '{title}',
            'text-font': ['Noto Sans Regular'],
            'text-size': 12
          },
          paint: {
            'text-halo-color': '#fff',
            'text-halo-width': 2
          }
        });
      });

代码解释

layout

paint

发表回复

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