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 | 图层Id | string | - |
gltfUrl | 模型URL | string | - |
autoHighlight | 本属性为true且pickable为true时,则会将鼠标悬浮选中的对象设为高亮 | boolean | false |
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 | 透明度 | number | 1 |
pickable | 图层是否会响应鼠标事件,若为false,则组件不会emit鼠标相关事件 | boolean | false |
sizeScale | 放大倍数 | number | 1 |
show | 是否显示 | boolean | true |
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
名称 | 描述 | 定义 |
---|