1.2.5 • Published 5 years ago

react-mapbox-gl-wrapper v1.2.5

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

react-mapbox-wrapper

Build Status npm version

React wrapper for mapboxgl-js API.

Made with ❤️ by MeilleursAgents

npm.io

Usage

import React from 'react';
import MapboxMap from 'react-mapbox-wrapper';

export default function SimpleMap() {
  return (
    <div style={{ height: 400, width: 400 }}>
      <MapboxMap
        accessToken="<your acess token here>"
        coordinates={{ lat: 48.872198, lng: 2.3366308 }}
      />
    </div>
  );
}

SimpleMap.displayName = 'SimpleMap';

See examples folder for more example.

Getting started

Read carefully the getting started section of Mapbox GL API.

If you use Webpack, you should add the following parameter in order to properly build your app.

module: {
    noParse: /(mapbox-gl)\.js$/,
}

react-mapbox-wrapper import the corresponding CSS stylesheet from Javascript, you don't have to do it.

API

MapboxMap

React Component that render a Mapbox Map. Extra props are directly passed to the Map constructor. Following props are handled by wrapper for updating or handling behavior in the React philosophy.

Wrapper is CSS flex-ready for width but you have to set a height for having visible Mapbox.

PropsTypeDefaultDescription
accessTokenStringrequiredMapbox Access Token (find it here)
coordinatesObjectrequiredCoordinates of the map center In the form { lng: 3.4, lat: 1.2 }
classNamestring''className added to map's wrapper. Your should provide a height in order to render the map (default at 0)
childrenNodenullRendered children, typically a Marker and/or Circle
minZoomnumberundefinedThe minimum zoom level of the map (0-24).
maxZoomnumberundefinedThe maximum zoom level of the map (0-24).
zoomnumber15The viewport zoom
onChangefuncundefinedCallback function called on every viewport change (moveend, zoomend) Callback receive param with the following shape { zoom: 15, coordinates: { lng: 3.4, lat: 1.2 } }
onClickfuncundefinedCallback function called on map's click
onLoadfuncundefinedCallback function called on map's load with current Mapbox instance param
onZoomStartfuncundefinedCallback function called on map's zoomstart
onZoomEndfuncundefinedCallback function called on map's zoomend with a debounce of 300ms in order to avoid too many render() call
renderNotSupportedfuncSimple messageCallback function called when browser does not support mapbox-gl
styleStringMapbox style layer
withCompassboolfalseShow compass Navigation Control
withFullscreenboolfalseShow Fullscreen Control
withZoomboolfalseShow zoom Navigation Control

Marker

React Component that render a Marker. Extra props are directly passed to the Marker constructor

PropsTypeDefaultDescription
childrenNodenullMarker HTML DOM, default marker will be used if not provided
coordinatesObjectrequiredCoordinates of the marker In the form { lng: 3.4, lat: 1.2 }
draggableboolfalseAllow user to drag'n'drop Marker
getReffuncCallback function called with marker's ref (useful for calling #moveToTop() function)
mapObjectrequiredMapbox Map where marker will be added (can be obtained with MapboxMap#onLoad props fn)
onDragEndfuncCallback function called on marker's dragend
onMouseOutfuncCallback function called on marker or popup mouseOut
onMouseOverfuncCallback function called on marker or popup mouseOver
popupNodePopup attached to the marker, displayed on click to marker
popupCloseButtonboolfalsePopup closeButton param
popupOffsetnumberPopup offset param
popupOnOverboolfalseTrigger popup show on mouse over (only available if children are provided, default marker cannot be bind)

Circle

React Component that render a Circle. Extra props are directly passed to the Marker constructor

PropsTypeDefaultDescription
coordinatesObjectrequiredCoordinates of the marker In the form { lng: 3.4, lat: 1.2 }
idstringrequiredIdentifier of circle, used to name the underlying layer
mapObjectrequiredMapbox Map where marker will be added (can be obtained with MapboxMap#onLoad props fn)
onClickfuncCallback function called on circle's click
paintObjectPaint option of the layer
radiusnumberrequiredRadius of circle, in kilometers
unitstringkilometersUnit of the radius. values can be : kilometers, meters, miles, feet

Development

npm install && npm run peers # install both dependencies and peers

You can use npm link while developping new features on this repo for use in targeted repository.

npm link /path/to/react-mapbox-wrapper

Git hooks

You can use our pre-commit hook for ensuring consistent format and linting before committing by running command:

./tools/install_hooks.sh
1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago