蜂窝网格图 (Loca.HexagonLayer)

蜂窝网格图,将普通的点数据按照蜂窝网格划分成若干区域,每个蜂窝网格区域都会包含落在此区域内的点数据信息。 每个蜂窝网格格子支持单独设置自定义的高度信息、颜色信息。 要注意的是:我们认为所有蜂窝网格格子必须是唯一的大小(radius)和间隙(gap)。 我们还在带有高度的蜂窝网格中加入了可接受光照信息的属性:acceptLight。假如设置了光照并在图层中开启接受光照, 那么每个立体蜂窝网格将会有光照反射的效果。

提示

来源 @vuemap/vue-amap-loca 组件库

基础示例

静态属性

仅且可以初始化配置,不支持响应式。

名称类型说明
cullfaceString剔除背面/前面的面(选择剔除将会提升性能),可选:back/front/none,back是剔除背面的面,front是剔除前面的面,none是不进行剔除。default 'back'
acceptLightBoolean面是否接受光照,光照信息在 loca 对象中配置 default true
shininessNumber立体网格的粗糙度,值越高,说明表面越粗糙。default 30
hasSideBoolean当面有厚度的时候,有没有侧面和底面 default true
depthBoolean是否开启深度检测,开启后可能会影响zIndex default true
initEventsBoolean是否创建事件,自动为loca图层创建click和mousemove事件。 默认 true
defaultStyleValueObject默认样式,可以查看下面属性说明
extraOptionsObject额外扩展属性,会直接将属性拷贝到初始化的options中,当key与props内的一样时会被props覆盖

动态属性

支持响应式。

名称类型说明
visibleBoolean点标记是否可见,默认为true。
zIndexNumber点标记的叠加顺序。地图上存在多个点标记叠加时,通过该属性使级别较高的点标记在上层显示,默认zIndex:12
sourceUrlString数据源的链接地址,一般是接口地址,返回的数据必须是 geojson 格式。
sourceDataObject数据对象。如果你不想使用 url 方式请求数据,可以直接填写请求好的 geojson 对象。 sourceUrl与sourceData只会生效一个,默认优先判断sourceUrl
layerStyleObject图层样式
zoomsArray图层缩放等级范围,默认[2,20]
opacityNumber图层整体透明度,默认 1
visibleDurationNumber图层显隐时候过渡的时间,默认为0
geoBufferSourceArrayBuffer, Stringprotocol-buffers(PBF) 格式的数据源,能够大幅压缩数据体积,有效减少数据传输时间。目前仅支持基于 mapbox/geobuf 的 GeoJSON PBF 实现

layerStyle参数

警告

layerStyle参数覆盖所有默认值

名称类型说明
radiusNumber, Function一个网格的半径大小,只能是一个常量值。单位由 unit 决定。 default 1000
unitString单位,只能是一个常量值。可选项: px, meter。一个是屏幕像素单位,一个是地理单位。地理单位性能更加优异。default 'meter'
gapNumber相邻网格的间隙大小,只能是一个常量值。单位由 unit 决定。default 0
altitudeNumber, Function海拔高度,代表棱柱的离地高度。支持动画过渡效果。 default 0
heightNumber, Function棱柱的高度。单位是 unit 的值。支持动画过渡效果。default 100
topColorString, Function棱柱的顶面颜色值。default '#fff'
sideTopColorString, Function棱柱的侧面顶部颜色值。default '#fff'
sideBottomColorString, Function棱柱的侧面底部颜色值。default '#fff'

defaultStyleValue参数

提示

defaultStyleValue提供默认参数,但会被geojson的properties属性中的值覆盖

名称类型说明
radiusNumber一个网格的半径大小,只能是一个常量值。单位由 unit 决定。 default 1000
unitString单位,只能是一个常量值。可选项: px, meter。一个是屏幕像素单位,一个是地理单位。地理单位性能更加优异。default 'meter'
gapNumber相邻网格的间隙大小,只能是一个常量值。单位由 unit 决定。default 0
altitudeNumber海拔高度,代表棱柱的离地高度。支持动画过渡效果。 default 0
heightNumber棱柱的高度。单位是 unit 的值。支持动画过渡效果。default 100
topColorString棱柱的顶面颜色值。default '#fff'
sideTopColorString棱柱的侧面顶部颜色值。default '#fff'
sideBottomColorString棱柱的侧面底部颜色值。default '#fff'

style说明

所有loca的Layer组件对Style设置提供了默认处理,支持function回调方式的属性都提供了默认回调实现,优先读取geojson的properties中的值,读取不到的情况下会读取defaultStyleValue配置的值,最后会使用组件内默认设置的值。
该默认处理可以被layerStyle中的设置给覆盖。目前默认设置已基本符合日常使用,如果需要在选中目标时做高亮处理,则推荐根据示例使用事件监听然后动态修改layerStyle来实现。
style数据有可以有三个来源,优先级按顺序处理,第一个最高

1、layerStyle属性配置
{
  unit: 'meter',
  radius: 120,
  gap: 0,
  altitude: 0,
  height: function (index, feature) {
    var ranks = sum(feature.coordinates);
    // return ranks < 60 ? heights[2] : heights[6];
    return ranks < 20 ?
      heights[0] : ranks < 40 ?
        heights[1] : ranks < 60 ?
          heights[2] : ranks < 80 ?
            heights[3] : ranks < 100 ?
              heights[4] : ranks < 120 ?
                heights[5] : ranks < 130 ?
                  heights[6] : heights[7];
  },
  topColor: function (index, feature) {
    var ranks = sum(feature.coordinates);
    // return ranks < 60 ? colors[1] : colors[6];
    return ranks < 20 ?
      colors[0] : ranks < 40 ?
        colors[1] : ranks < 60 ?
          colors[2] : ranks < 80 ?
            colors[3] : ranks < 100 ?
              colors[4] : ranks < 120 ?
                colors[5] : ranks < 130 ?
                  colors[6] : colors[7];
  },
  sideBottomColor: function (index, feature) {
    var ranks = sum(feature.coordinates);
    // return ranks < 60 ? colors[1] : colors[6];
    return ranks < 20 ?
      colors[0] : ranks < 40 ?
        colors[1] : ranks < 60 ?
          colors[2] : ranks < 80 ?
            colors[3] : ranks < 100 ?
              colors[4] : ranks < 120 ?
                colors[5] : ranks < 130 ?
                  colors[6] : colors[7];
  },
  sideTopColor: function (index, feature) {
    var ranks = sum(feature.coordinates);
    // return ranks < 60 ? colors[1] : colors[6];
    return ranks < 20 ?
      colors[0] : ranks < 40 ?
        colors[1] : ranks < 60 ?
          colors[2] : ranks < 80 ?
            colors[3] : ranks < 100 ?
              colors[4] : ranks < 120 ?
                colors[5] : ranks < 130 ?
                  colors[6] : colors[7];
  }
}
2、geojson的properties属性
{
  "type": "FeatureCollection",
  "name": "Polygon",
  "crs": {
    "type": "name",
    "properties": {
      "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
    }
  },
  "features": [
    {
      "type": "Feature",
      "properties": {
        "radius": 50,
        "height": 100
      },
      "geometry": {
        "type": "MultiPolygon",
        "coordinates": [ [ [ [ 119.958676782427744, 32.121127961388339, 9.900800000003301 ], [ 119.958672295405933, 32.121125856630357, 9.900800000003301 ], [ 119.958649511242555, 32.121161034502613, 9.866549999998824 ], [ 119.958649466189797, 32.121161104062303, 9.900800000003301 ], [ 119.958653953212774, 32.121163208821088, 9.900800000003301 ], [ 119.958653991614412, 32.121163149530432, 9.866750000001275 ], [ 119.958676782427744, 32.121127961388339, 9.900800000003301 ] ] ] ]
      }
    }
  ]
}
3、defaultStyleValue属性配置
{
  topColor: '#fff',
  sideTopColor: '#fff',
  sideBottomColor: '#fff',
  altitude: 0,
  height: 0,
  radius: 1000,
  gap: 0,
  unit: 'meter'
}

ref 可用方法

提供无副作用的同步帮助方法

函数返回说明
$$getInstance()Loca.HexagonLayer获取实例

事件

事件参数说明
initLoca.HexagonLayer实例
clickFeature, event当点击到标号时返回对应的feature,否则返回undefined
mousemoveFeature, event当鼠标移动滑过标号时返回对应的feature,否则返回undefined
rightclickFeature, event鼠标右击时返回对应的feature,否则返回undefined
最后更新时间:
贡献者: gu, guyangyang