3D网格热力图(GridLayer)
示例
示例源码
tsx
import React, { useEffect, useRef, useState } from 'react'
import ReactDOM from 'react-dom'
import { MbMap, MbTiandituLayer } from '@mapbox-react/core'
import { MbGridLayer } from '@mapbox-react/deck-layers'
const App = () => {
const [mapCenter] = useState([116.314177, 39.832819])
const [zoom, setZoom] = useState(8.5)
const [pitch, setPitch] = useState(40)
const mapInst = useRef<any>()
const data = 'https://mapbox-web.github.io/mapbox-react/geojson/beijing_price.json'
const [elevationScale, setElevationScale] = useState(50)
const mousemoveHandler = ({ object }: { object: any }) => {
console.log(object)
}
return (
<div className="map-wrapper">
<MbMap ref={mapInst} center={mapCenter} zoom={zoom} pitch={pitch}>
<MbTiandituLayer types={['vec']} />
<MbGridLayer
data={data}
position={(d) => d.lnglat}
colorWeight={(d) => d.transPrice}
colorAggregation="MEAN"
elevationWeight={(d) => d.transPrice}
elevationAggregation="MEAN"
pickable={true}
elevationScale={elevationScale}
onMouseMove={mousemoveHandler}
/>
</MbMap>
</div>
)
}
ReactDOM.render(<App />, document.querySelector('#root'))
API
PROPS
名称 | 描述 | 类型 | 默认值 |
---|---|---|---|
id | 图层Id | string | - |
position | 位置信息 | AnyFunc | - |
autoHighlight | 本属性为true且pickable为true时,则会将鼠标悬浮选中的对象设为高亮 | boolean | false |
cellSize | 半径,单位为米 | number | 1000 |
colorAggregation | 格网颜色聚合模式 本属性与colorWeight一起设置时生效 | string(SUM / MEAN / MIN / MAX) | SUM |
colorRange | 颜色范围 | 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)", ] |
colorValue | 六边形颜色隐射函数 例如:根据六边形内点的数量来计算颜色(密度热力图) (points) => points.length 若设置了本属性,则 colorWeight与colorAggregation 失效 | AnyFunc | - |
colorWeight | 格网中每一点的颜色权重值计算函数 本属性与colorAggregation一起设置时生效 | AnyFunc | - |
coverage | 蜂窝网格的覆盖范围比例,值在0-1之间,最后呈现的网格半径将为cellSize*coverage | number | 1 |
data | 图层源数据 | string / IndexAny / AnyArr / Promise<any> | '' |
highlightColor | 要与高亮对象原始颜色进行混合(blend)的颜色值 | string / number[] | [255, 255, 128, 1] |
highlightedObjectIndex | 高亮元素序号 | number | -1 |
elevationCalue | 格网高度估算函数 | AnyFunc | - |
elevationWeight | 高度权重值计算函数 | AnyFunc | () => 1 |
elevationAggregation | 高度聚合模式 | string(SUM / MEAN / MIN / MAX) | SUM |
elevationScale | 高度放大倍数 | number | 1 |
material | 是否有材质 | boolean | true |
opacity | 透明度 | number | 1 |
pickable | 图层是否会响应鼠标事件,若为false,则组件不会emit鼠标相关事件 | boolean | false |
show | 是否显示 | boolean | true |
stroked | 是否描边 | boolean | false |
EVENTS
名称 | 描述 | 参数 |
---|---|---|
onCreated | 初始化完成事件 | - |
onMouseMove | - | { object: any; coordinates: mapboxgl.LngLat; pixel: [number, number] } |
onMouseLeave | - | - |
onClick | - | { object: any; coordinates: mapboxgl.LngLat; pixel: [number, number] } |
METHODS
名称 | 描述 | 定义 |
---|