Skip to content

ScaleContro

Scale component, used to display the ratio between distance on the map and the actual distance.

Example

Example Source Code
tsx
import React, { useState } from 'react'
import ReactDOM from 'react-dom'
import { MbMap, MbScaleControl, MbTiandituLayer } from '@mapbox-react/core'

const App = () => {
  const [mapCenter] = useState([116.38745, 39.91266])
  const [zoom, setZoom] = useState(2)

  return (
    <div className="map-wrapper">
      <MbMap center={mapCenter} zoom={zoom}>
        <MbTiandituLayer types={['vec']} />
        <MbScaleControl position="bottom-right" />
      </MbMap>
    </div>
  )
}

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

API

PROPS

NameDescriptionTypeDefault
positionPositionstring('top-left' , 'top-right' , 'bottom-left' ,'bottom-right')top-right
maxWidthMaximum length of the ScaleControl, in pixelsnumber100
unitUnitstring('imperial' , 'metric' , 'nautical')metric

EVENTS

NameDescriptionParameters
onCreatedMap initialization completed event-

METHODS

NameDescriptionDefinition