Skip to content

3D蜂窝热力图(HexagonLayer)

示例

示例源码
vue
<template>
  <div style="height: 500px">
    <div style="height: 470px">
      <mb-map :zoom="8">
        <mb-tianditu-layer />
        <mb-hexagon-layer
          :data="__RESOURCE_URL__ + 'json/beijing_price.json'"
          :position="(d) => d.lnglat"
          :color-weight="(d) => d.transPrice"
          color-aggregation="MEAN"
          :elevation-weight="(d) => d.transPrice"
          elevation-aggregation="MEAN"
          :pickable="true"
          :elevation-scale="50"
          @mousemove="mousemoveHandler"
          @mouseleave="mouseleaveHandler"
        />
      </mb-map>
    </div>
    <div style="height: 30px; margin: 10px 10px">
      <p v-if="meanPrice" class="text-muted">Price: {{ meanPrice / 10000 }}</p>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const meanPrice = ref(0)

const mousemoveHandler = ({ object }: { object: any }) => {
  meanPrice.value = object.elevationValue
}
const mouseleaveHandler = () => {
  meanPrice.value = 0
}
</script>

API

PROPS

名称描述类型默认值
id图层Idstring-
radius半径,单位为米number1000
position-function-
auto-highlight本属性为true且pickable为true时,则会将鼠标悬浮选中的对象设为高亮booleanfalse
color-aggregation格网颜色聚合模式 本属性与colorWeight一起设置时生效string(SUM / MEAN / MIN / MAX)SUM
color-range颜色范围string[][ "rgb(255, 255, 178)", "rgb(254, 217, 118)", "rgb(254, 178, 76)", "rgb(253, 141, 60)", "rgb(240, 59, 32)", "rgb(189, 0, 38)", ]
color-value六边形颜色隐射函数 例如:根据六边形内点的数量来计算颜色(密度热力图) (points) => points.length 若设置了本属性,则 colorWeight与colorAggregation 失效AnyFunc-
color-weight格网中每一点的颜色权重值计算函数 本属性与colorAggregation一起设置时生效AnyFunc-
coverage蜂窝网格的覆盖范围比例,值在0-1之间,最后呈现的网格半径将为radius*coveragenumber1
data图层源数据array / object / promise / string[]
elevation-aggregation高度聚合模式stringSUM
elevation-scale蜂窝体放大倍数number1
elevation-value蜂窝体放高度估算函数 例如:根据六边形内点的数量来计算高度 (points) => points.length 若设置了本属性,则 elevationWeight 与 elevationAggregation 失效AnyFunc-
elevation-weight高度权重值计算函数AnyFunc() => 1
extruded是否为3D模式booleantrue
highlight-color要与高亮对象原始颜色进行混合(blend)的颜色值string / number[][255, 255, 128, 1]
highlighted-object-index高亮元素序号number-1
material是否有材质booleantrue
opacity透明度number1
pickable图层是否会响应鼠标事件,若为false,则组件不会emit鼠标相关事件booleanfalse
show是否显示booleantrue

EVENTS

名称描述参数
created初始化完成事件-
mousemove-{ object: any; coordinates: mapboxgl.LngLat; pixel: [number, number] }
mouseleave--
click-{ object: any; coordinates: mapboxgl.LngLat; pixel: [number, number] }

SLOTS

名称描述

METHODS

名称描述定义