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 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
componentWillReceiveProps(nextProps) { | |
// Prevent the diff'ing if function is | |
// triggered before a style is set | |
if(this.props.mapStyle === null) return; | |
const map = this.map; | |
// Remember where we are in the lifecycle here, | |
// even though we already update the Redux state, | |
// this component's current properties still | |
// reflect the old state: |
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
import Immutable from 'immutable'; | |
export default function StylesheetReducer(styleState = null, action) { | |
switch(action.type){ | |
/* ... */ | |
/* Other reducer cases exist here */ | |
/* ... */ |
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
// Within your actions | |
export function setStyle(style) { | |
return { | |
type: 'SET_STYLE', | |
payload: style | |
} | |
} | |
/* ----------------------------*/ |
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
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, | |
}; |
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
import React, { Component } from 'react'; | |
class ReactMap extends Component { | |
render(){ | |
return ( | |
<div id='map'></div> | |
); | |
} | |
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.