Gif图片加载器(ImageGifLoader)
ImageGifLoader 提供预加载Gif图标
示例
示例源码
tsx
import React, { useEffect, useRef, useState } from 'react'
import ReactDOM from 'react-dom'
import {
MbImageGifLoader,
MbMap,
MbSymbolLayer,
MbTiandituLayer,
} from '@mapbox-react/core'
const App = () => {
const [mapCenter] = useState([115.124368, 29.216049])
const [zoom, setZoom] = useState(10)
const symbolDataSource = [
{
coordinates: [115.124368, 29.216049],
properties: {
icon: 'child',
},
},
{
coordinates: [115.124368, 29.246049],
properties: {
icon: 'child',
},
},
{
coordinates: [115.124368, 29.186049],
properties: {
icon: 'child',
},
},
{
coordinates: [115.324368, 29.216049],
properties: {
icon: 'run',
},
},
]
const images = [
{
name: 'child',
url: `https://mapbox-web.github.io/mapbox-react/images/child.gif`,
},
{
name: 'run',
url: `https://mapbox-web.github.io/mapbox-react/images/run.gif`,
},
]
return (
<div className="map-wrapper">
<MbMap center={mapCenter} zoom={zoom}>
<MbImageGifLoader images={images} />
<MbTiandituLayer types={['vec']} />
<MbSymbolLayer
data={symbolDataSource}
iconImageField="icon"
iconSize={0.2}
iconAllowOverlap
textAllowOverlap
/>
</MbMap>
</div>
)
}
ReactDOM.render(<App />, document.querySelector('#root'))
API
PROPS
名称 | 描述 | 类型 | 默认值 |
---|---|---|---|
images | 图片属性数组 数组中每个对象需包含必需的name属性以及图片相关信息 | array<{ name: string; url: string, requestInit?: RequestInit }> | - |
组件使用fetch去请求图片数据,如果是跨域请求,请在服务端配置CORS头部,requestInit为fetch的第二个参数
EVENTS
名称 | 描述 | 参数 |
---|---|---|
onCreated | 地图初始化完成事件 | - |
METHODS
名称 | 描述 | 定义 |
---|