react-map-gl/docs/components/scale-control.md
2019-12-30 10:28:57 -08:00

1.0 KiB

Scale Control

This is a React equivalent of Mapbox's ScaleControl.

import {Component} from 'react';
import ReactMapGL, {ScaleControl} from 'react-map-gl';

class Map extends Component {
  render() {
    const {viewport, updateViewport} = this.props;
    return (
      <ReactMapGL {...viewport} onViewportChange={updateViewport}>
        <div style={{position: 'absolute', bottom: 100, left: 20}}>
          <ScaleControl maxWidth={100} unit="metric"}/>
        </div>
      </ReactMapGL>
    );
  }
}

Properties

maxWidth {Number}

The maximum length of the scale control in pixels. Default 100.

unit {String}

Unit of the distance, one of 'imperial', 'metric' or 'nautical'.

Styling

Like its Mapbox counterpart, this control relies on the mapbox-gl stylesheet to work properly. Make sure to add the stylesheet to your page.

Source

scale-control.js