Class: HeatMapLayer

HeatMapLayer

热力图层类。热力图是通过颜色分布,描述诸如人群分布、密度和变化趋势等的一种地图表现手法。 热点图的衰减是像素级别的,视觉效果极佳,但不能与具体数据进行一一对应,只能表示权重之间的差别, 因此可以用于一些对精度要求不高而需要重点突出权重渐变的行业,如制作气象温度对比动态效果图、地震区域的震点强弱图等。
在客户端直接渲染栅格图的三要素:
1.热点数据,热点数据需要点数据,每一个热点数据需要有地理位置以及权重值 (能够明显地表现某位置某事件发生频率或事物分布密度等,如可以为温度的高低、人口密集度等等);
2.热点衰减渐变填充色集合, 用于渲染每一个热点从中心向外衰减时的渐变色;
3.热点半径,也就是衰减半径。每一个热点需要从中心点外四周根据半径计算衰减度,对在热点衰减区内的每一个像素计算需要渲染的颜色值。

new HeatMapLayer(name, options)

Usage
import { HeatMapLayer } from '@supermapgis/iclient-mapboxgl';

new HeatMapLayer(name, options);
<script type="text/javascript" src="https://iclient.supermap.io/dist/mapboxgl/iclient-mapboxgl.js"></script>
<script>
  new mapboxgl.supermap.HeatMapLayer({paramsNames});
</script>
mapboxgl/overlay/HeatMapLayer.js, line 8
Name Type Description
name string

图层名称。

options Object

构造参数。

Name Type Default Description
map mapboxgl.Map

MapBoxGL Map 对象。

featureWeight string

对应 feature 属性中的热点权重字段名称,权重值类型为 float。

id string 可选

专题图层 ID。默认使用 CommonUtil.createUniqueID("HeatMapLayer_") 创建专题图层 ID。

radius number 50 可选

热点渲染的最大半径(热点像素半径),单位为 px,当 useGeoUnit 参数 为 true 时,单位使用当前图层地理坐标单位。热点显示的时候以精确点为中心点开始往四周辐射衰减,其衰减半径和权重值成比列。

loadWhileAnimating boolean true 可选

是否实时重绘。(当绘制大数据量要素的情况下会出现卡顿,建议把该参数设为 false)。

opacity number 1 可选

图层不透明度。

colors Array.<string> ['blue','cyan','lime','yellow','red'] 可选

颜色线性渐变数组,颜色值必须为 canvas 所支持的。

useGeoUnit boolean false 可选

使用地理单位,即默认热点半径默认使用像素单位。当设置为 true 时,热点半径和图层地理坐标保持一致。

Fires

Extends

HeatMapLayer -> mapboxgl.Evented

Members

EVENT_TYPES

监听一个自定义事件可用如下方式: 热点图自定义事件信息,事件调用时的属性与具体事件类型相对应。

支持的事件如下 (另外包含 <Layer 中定义的其他事件>):
featuresadded - 热点添加完成时触发。回调参数为添加的热点信息数组和操作成功与否信息。 参数类型:{features: features, succeed: succeed} featuresremoved - 热点被删除时触发。回调参数为删除的热点信息数组和操作成功与否信息。
参数类型:{features: features, succeed: succeed} featuresdrawcompleted - 热点图渲染完成时触发。

featuresGeoJSONObject

热点信息数组,记录存储图层上添加的所有热点信息。

idstring

热力图图层 ID。

loadWhileAnimatingboolean

是否实时重绘。(当绘制大数据量要素的情况下会出现卡顿,建议把该参数设为 false)。

Default Value:
true

namestring

图层名字。

Events

changelayer

mapboxgl/overlay/HeatMapLayer.js, line 175

图层属性改变之后触发。

Properties:
Name Type Description
layer Object

图层。

property string

被改变的图层属性。

featuresadded

mapboxgl/overlay/HeatMapLayer.js, line 146

要素添加完成之后触发。

Properties:
Name Type Description
features GeoJSONObject

被添加的要素。

succeed boolean

要素是否成功添加。

featuresremoved

mapboxgl/overlay/HeatMapLayer.js, line 217

要素删除之后触发。

Properties:
Name Type Description
features Array.<FeatureVector>

需要被删除的要素。

succeed boolean

要素删除成功与否。

Methods

addFeatures(features)

mapboxgl/overlay/HeatMapLayer.js, line 114

添加热点信息。

Name Type Description
features GeoJSONObject

待添加的要素数组。

Example
var geojson = {
     "type": "FeatureCollection",
     "features": [
         {
             "type": "feature",
             "geometry": {
                 "type": "Point",  //只支持point类型
                 "coordinates": [0, 0]
             },
             "properties": {
                 "height": Math.random()*9,
                 "geoRadius": useGeoRadius?radius:null
             }
         }
     ]
  };
var heatMapLayer = new HeatMapLayer("heatmaplayer",{"featureWeight":"height"});                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   pLayer = new HeatMapLayer("heatmaplayer",{"featureWeight":"height"});
heatMapLayer.addFeatures(geojson);
map.addLayer(heatMapLayer);

getPixelXY(x, y)

mapboxgl/overlay/HeatMapLayer.js, line 195

转换地理坐标为相对于当前窗口左上角的像素坐标。

Name Type Description
x number

热点的像素 x 坐标。

y number

热点的像素 y 坐标。

moveTo(layerID, before)

mapboxgl/overlay/HeatMapLayer.js, line 234

将图层移动到某个图层之前。

Name Type Default Description
layerID string

待插入的图层 ID。

before boolean true 可选

是否将本图层插入到图层 ID 为 layerID 的图层之前(如果为 false 则将本图层插入到图层 ID 为 layerID 的图层之后)。

onAdd()

mapboxgl/overlay/HeatMapLayer.js, line 84

添加该图层。

refresh()

mapboxgl/overlay/HeatMapLayer.js, line 155

强制刷新当前热点显示,在图层热点数组发生变化后调用,更新显示。

removeAllFeatures()

mapboxgl/overlay/HeatMapLayer.js, line 226

移除全部的热点信息。

removeFeatures(features)

mapboxgl/overlay/HeatMapLayer.js, line 205

移除指定的热点信息。

Name Type Description
features Array.<FeatureVector> | FeatureVector

热点信息数组。

removeFromMap()

mapboxgl/overlay/HeatMapLayer.js, line 99

删除该图层。

setOpacity(opacity)

mapboxgl/overlay/HeatMapLayer.js, line 166

设置图层的不透明度,取值范围:[0-1]。

Name Type Description
opacity number 可选

不透明度。

setVisibility(visibility)

mapboxgl/overlay/HeatMapLayer.js, line 260

设置图层可见性。

Name Type Description
visibility boolean 可选

是否显示图层(当前地图的 resolution 在最大最小 resolution 之间)。

updateHeatPoints(bounds)

mapboxgl/overlay/HeatMapLayer.js, line 186

刷新热点图显示。

Name Type Description
bounds mapboxgl.LngLatBounds

当前显示范围。