Skip to content

MigrationLayer

Example

Example Source Code
tsx
import React, { useEffect, useRef, useState } from 'react'
import ReactDOM from 'react-dom'
import { MbMap, MbTiandituLayer } from '@mapbox-react/core'
import { MbArcLayer } from '@mapbox-react/deck-layers'
import { MbMigrationLayer } from '@mapbox-react/effect-layers'

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

  const [data, setData] = useState<any[]>([])
  const [width, setWidth] = useState(3)

  function getRandomArbitrary(min: number, max: number) {
    return Math.random() * (max - min) + min
  }

  const loadData = () => {
    const temp: any[] = []
    for (let i = 0; i < 100; i++) {
      temp.push({
        to: [getRandomArbitrary(100, 132), getRandomArbitrary(25, 50)],
      })
    }
    setData(temp)
  }

  useEffect(() => {
    loadData()
  }, [])

  return (
    <div className="map-wrapper">
      <MbMap ref={mapInst} center={mapCenter} zoom={zoom} pitch={pitch}>
        <MbArcLayer
          data={data}
          sourcePosition={[116, 39]}
          targetPosition={(d) => d.to}
          width={width}
          height={0.8}
          sourceColor="rgb(255, 0, 128)"
          targetColor="rgb(0, 200, 255)"
        />
        <MbMigrationLayer
          data={data}
          sourcePosition={[116, 39]}
          targetPosition={(d) => d.to}
          width={width}
          height={0.8}
          sourceColor="#fff"
          targetColor="#fff"
          trailLength={5}
        />
      </MbMap>
    </div>
  )
}

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

API

PROPS

NameDescriptionTypeDefault
idLayer IDstring-
trailLengthLength of the trail (e.g., in number of segments, time units, or distance).number5
dataSource data for the layer.string / IndexAny / AnyArr / Promise<any>''
showWhether the layer is visible.booleantrue
opacityThe opacity of the layer (0-1).number1
pickableWhether the layer responds to mouse events. If false, the component will not emit mouse-related events.booleanfalse
autoHighlightWhen this property is true and pickable is also true, the hovered object will be highlighted.booleanfalse
highlightColorThe color to blend with the original color of the highlighted object.string / number[][255, 255, 128, 1]
highlightedObjectIndexThe index of the currently highlighted element.number-1
onDataLoadCallback function invoked after data loading is complete.AnyFunc-
dataTransformFunction to transform the data before rendering.AnyFunc-
transitionsTransition settings for the layer.IndexAny{}
sourcePositionSource position.AnyArr / AnyFunc-
targetPositionTarget position.AnyArr / AnyFunc-
sourceColorSource color.string / AnyFunc'black'
targetColorTarget color.string / AnyFunc'black'
widthWidth.number / AnyNumberFunc1

EVENTS

NameDescriptionParameters

METHODS

NameDescriptionDefinition