Skip to content

Instantly share code, notes, and snippets.

@McCulloughRT
Created October 11, 2017 00:04
Show Gist options
  • Save McCulloughRT/ecf50bbf3d5c1c3f09335bf7d3aa6656 to your computer and use it in GitHub Desktop.
Save McCulloughRT/ecf50bbf3d5c1c3f09335bf7d3aa6656 to your computer and use it in GitHub Desktop.
componentDidMount(){
// pass in your map properties as props to the component
const { token, longitude, latitude, zoom, styleID } = this.props;
const mapConfig = {
container: 'map',
style: `mapbox://styles/${ styleID }`,
center: [longitude, latitude],
zoom: zoom,
};
mapboxgl.accessToken = token;
this.map = new mapboxgl.Map(mapConfig);
// now we can access the map with this.map, just like in 'normal' js
this.map.on('load', () => {
const style = this.map.getStyle();
// Do whatever you need to do once the map has loaded
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment