Skip to content

ImageGifLoader

Provide preloaded GIF icons

Example

Example Source Code
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

NameDescriptionTypeDefault
imagesAn array of image properties. Each object in the array must include a required name property and image-related informationarray<{ name: string; url: string, requestInit?: RequestInit }>-

This component uses fetch to request image data. If the request is cross-origin, please configure CORS headers on the server side. requestInit refers to the second parameter of the fetch function.

EVENTS

NameDescriptionParameters
onCreatedMap initialization completed event-

METHODS

NameDescriptionDefinition