Skip to content

Instantly share code, notes, and snippets.

@McCulloughRT
Last active October 11, 2017 01:30
Show Gist options
  • Save McCulloughRT/4b9cb263595d35d5f09a5ce1e9d40bde to your computer and use it in GitHub Desktop.
Save McCulloughRT/4b9cb263595d35d5f09a5ce1e9d40bde to your computer and use it in GitHub Desktop.
this.map.on('load', () => {
// Get the map style and set it in the state tree
const style = this.map.getStyle();
this.props.setStyle(style); // <= action creator
// Listen for a map click, get the features under the pointer
// and pass them to a "clickMap" action that might update our UI
// or highlight the feature in the stylesheet:
this.map.on('click', event => {
const features = this.map.queryRenderedFeatures(event.point);
this.props.clickMap(features); // <= action creator
// We can also use the native mapbox popup if the clickMap
// action sets some html to show and passes it as a prop:
if(this.props.popupMarkup) {
new mapboxgl.Popup()
.setLngLat(event.lngLat)
.setHTML(this.props.popupMarkup)
.addTo(this.map);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment