Last active
October 11, 2017 01:30
-
-
Save McCulloughRT/4b9cb263595d35d5f09a5ce1e9d40bde to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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