Skip to content

纹理建筑物(TextureBuildingLayer)

示例

示例源码
tsx
import React, { useEffect, useRef, useState } from 'react'
import ReactDOM from 'react-dom'
import { MbMap, MbTiandituLayer } from '@mapbox-react/core'
import { MbTextureBuildingLayer } from '@mapbox-react/effect-layers'

const App = () => {
  const [mapCenter] = useState([116.179267984000035, 39.918961127600085])
  const [zoom, setZoom] = useState(14.5)
  const [pitch, setPitch] = useState(60)
  const mapInst = useRef<any>()

  return (
    <div className="map-wrapper">
      <MbMap ref={mapInst} center={mapCenter} zoom={zoom} pitch={pitch}>
        <MbTextureBuildingLayer
          data="https://mapbox-web.github.io/mapbox-react/showcase/building.geojson"
          texture="https://mapbox-web.github.io/mapbox-react/obj/windmill_2/windmill_diffuse.jpeg"
          dataTransform={(d) => d.features}
          getPolygon={(d) => d.geometry.coordinates[0]}
          getElevation={(d) => d.properties.Floor * 30}
        />
      </MbMap>
    </div>
  )
}

ReactDOM.render(<App />, document.querySelector('#root'))

API

PROPS

名称描述类型默认值
id图层Idstring-
texture材质string-
getElevation-number / AnyNumberFunc1000
getFillColor-number[] / AnyFunc[0, 125, 125]
getPolygon-AnyFunc-
elevationScale-number1
data图层源数据string / IndexAny / AnyArr / Promise<any>''
show是否显示booleantrue
opacity透明度number1
pickable图层是否会响应鼠标事件,若为false,则组件不会emit鼠标相关事件booleanfalse
autoHighlight本属性为true且pickable为true时,则会将鼠标悬浮选中的对象设为高亮booleanfalse
highlightColor要与高亮对象原始颜色进行混合(blend)的颜色值string / number[][255, 255, 128, 1]
highlightedObjectIndex高亮元素序号number-1
onDataLoad-AnyFunc-
dataTransform-AnyFunc-
transitions-IndexAny{}

EVENTS

名称描述参数

METHODS

名称描述定义