Skip to content

Gltf图层(GltfLayer)

示例

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

const App = () => {
  const [mapCenter] = useState([116, 39])
  const [zoom, setZoom] = useState(18)
  const [pitch, setPitch] = useState(60)
  const mapInst = useRef<any>()

  return (
    <div className="map-wrapper">
      <MbMap ref={mapInst} center={mapCenter} zoom={zoom} pitch={pitch}>
        <MbTiandituLayer types={['vec']} />
        <MbGltfLayer
          gltfUrl="https://mapbox-web.github.io/mapbox-react/gltf/GroundVehicle/GroundVehicle.glb"
          data={[{ position: [116, 39] }]}
          getOrientation={[0, 45, 90]}
          sizeScale={10}
        />
      </MbMap>
    </div>
  )
}

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

API

PROPS

名称描述类型默认值
id图层Idstring-
gltfUrl模型URLstring-
autoHighlight本属性为true且pickable为true时,则会将鼠标悬浮选中的对象设为高亮booleanfalse
data图层源数据string / IndexAny / AnyArr / Promise<any>''
getOrientation朝向信息number[] / AnyNumbersFunc[0, 0, 90]
getPosition位置信息AnyFunc-
getScale放大倍数信息number[] / AnyNumbersFunc[1, 1, 1]
getTranslation位移信息number[] / AnyNumbersFunc[0, 0, 0]
highlightColor要与高亮对象原始颜色进行混合(blend)的颜色值string / number[][255, 255, 128, 1]
highlightedObjectIndex高亮元素序号number-1
opacity透明度number1
pickable图层是否会响应鼠标事件,若为false,则组件不会emit鼠标相关事件booleanfalse
sizeScale放大倍数number1
show是否显示booleantrue
animations动画配置IndexAny{ speed: 5 }

EVENTS

名称描述参数
onCreated初始化完成事件-
onMouseMove-{ object: any; coordinates: mapboxgl.LngLat; pixel: [number, number] }
onMouseLeave--
onClick-{ object: any; coordinates: mapboxgl.LngLat; pixel: [number, number] }

METHODS

名称描述定义