如何通过数据值设置Mapbox热图颜色?

时间:2019-06-25 19:26:07

标签: mapbox mapbox-gl

我想显示蓝牙扫描的热点图,以使信号较强的扫描显示为绿色,而信号强度较弱的扫描显示为红色。我尝试使用所有Mapbox热图属性(权重,强度,半径,颜色,不透明度),但无法实现此效果。有什么建议吗?

GeoJSON数据格式(“ rssi”是信号强度)

{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -79.92068447220412,
                    43.259061411756505
                ]
            },
            "properties": {
                "name": "heatmap",
                "rssi": "55"
            }
        },
        {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -79.92068446786702,
                    43.25906141184957
                ]
            },
            "properties": {
                "name": "heatmap",
                "rssi": "59"
            }
        },
        ...
    ]
}
到目前为止,

热图图层

map.addLayer({
        id: 'heatmap_heatmap_layer_id',
        type: 'heatmap',
        source: 'heatmap_source_id',
        maxzoom: 24,
        paint: {
          'heatmap-weight': {
            property: 'rssi',
            type: 'exponential',
            stops: [
              [0, 1],
              [120, 10]
            ]
          },
          'heatmap-intensity': {
            stops: [
              [currentZoom, 1],
              [24, 2]
            ]
          },
          'heatmap-color': [
            'interpolate',
            ['linear'],
            ['heatmap-density'],
            0, 'rgba(240,29,29,0)',
            0.2, 'rgba(198,0,12,1)', 
            0.4, 'rgba(32,43,222,1)', 
            0.7, 'rgba(1,1,1,1)', 
            1.0, 'rgba(200,144,153,1)'
          ],
          'heatmap-radius': {
            stops: [
              [currentZoom, 20],
              [middleZoom, 30]
            ]
          },
          'heatmap-opacity': {
            default: 1,
            stops: [
              [currentZoom, 1],
              [24, 1]
            ]
          },
        }
      });

1 个答案:

答案 0 :(得分:0)

这有点棘手,因为热图会自动融合并添加彼此非常接近的点。这意味着强信号的单个点将显示相同的颜色,因为弱信号的许多点靠在一起。

将这些点显示为由RSSI着色的离散圆可能会更好。