Skip to content

ImageApngLoader

Provide preloaded APNG icons

Example

Example Source Code
tsx
import React, { useEffect, useRef, useState } from 'react'
import ReactDOM from 'react-dom'
import {
  MbImageApngLoader,
  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: 'firefox',
      },
    },
    {
      coordinates: [115.124368, 29.246049],
      properties: {
        icon: 'firefox',
      },
    },
    {
      coordinates: [115.124368, 29.186049],
      properties: {
        icon: 'firefox',
      },
    },
    {
      coordinates: [115.324368, 29.216049],
      properties: {
        icon: 'firefox',
      },
    },
  ]

  const images = [
    {
      name: 'clock',
      size: [50, 50],
      url: 'https://mapbox-web.github.io/mapbox-react/images/clock.png',
    },
    {
      name: 'firefox',
      size: [100, 100],
      url: 'https://mapbox-web.github.io/mapbox-react/images/firefox.png',
    },
  ]

  return (
    <div className="map-wrapper">
      <MbMap center={mapCenter} zoom={zoom}>
        <MbImageApngLoader images={images} />
        <MbTiandituLayer types={['vec']} />
        <MbSymbolLayer
          data={symbolDataSource}
          iconImageField="icon"
          iconSize={0.5}
          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; size?: number[]; 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