-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Heatmap Example #19
Changes from 5 commits
3075309
3777b6c
6bc5ed4
553cc16
b7e9096
d9ff68f
8eab280
ee175ed
1f1a8d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React, { Component, Fragment } from 'react'; | ||
import isEmpty from 'lodash.isempty'; | ||
|
||
// examples: | ||
import GoogleMap from '../components/GoogleMap'; | ||
|
||
// consts | ||
import LOS_ANGELES_CENTER from '../const/la_center'; | ||
|
||
class Heatmap extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
places: [], | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
fetch('places.json') | ||
.then(response => response.json()) | ||
.then(data => this.setState({ places: data.results })); | ||
} | ||
|
||
render() { | ||
const { places } = this.state; | ||
const data = places.map(place => ({ | ||
lat: place.geometry.location.lat, | ||
lng: place.geometry.location.lng, | ||
weight: Math.floor(Math.random() * Math.floor(5)), | ||
})); | ||
const heatmapData = { | ||
positions: data, | ||
options: { | ||
radius: 20, | ||
opacity: 1, | ||
}, | ||
}; | ||
|
||
return ( | ||
<Fragment> | ||
{!isEmpty(places) && ( | ||
<GoogleMap | ||
defaultZoom={10} | ||
defaultCenter={LOS_ANGELES_CENTER} | ||
heatmapLibrary | ||
heatmap={heatmapData} | ||
/> | ||
)} | ||
</Fragment> | ||
); | ||
} | ||
} | ||
|
||
export default Heatmap; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import Home from './Home'; | |
import Main from './examples/Main'; | ||
import SearchBox from './examples/Searchbox'; | ||
import Autocomplete from './examples/Autocomplete'; | ||
import Heatmap from './examples/Heatmap'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we align it like the rest? Sorry, OCD 😂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if I understood what you meant by align, so I sorted the import lines by length in d9ff68f |
||
|
||
// styles | ||
import './index.css'; | ||
|
@@ -28,6 +29,7 @@ ReactDOM.render( | |
<Route path={`${defaultPath}default`} component={Main} /> | ||
<Route path={`${defaultPath}searchbox`} component={SearchBox} /> | ||
<Route path={`${defaultPath}autocomplete`} component={Autocomplete} /> | ||
<Route path={`${defaultPath}heatmap`} component={Heatmap} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if I understood what you meant by align, so I sorted the import lines by length in d9ff68f |
||
<Redirect exact from="*" to={defaultPath} /> | ||
</Switch> | ||
</App> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use instead:
Due to google-map-react/google-map-react#673 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in 8eab280