Skip to content
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

Merged
merged 9 commits into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ const Home = () => (
<ListItem>
<StyledLink to={`${defaultPath}autocomplete`}>Autocomplete</StyledLink>
</ListItem>
<ListItem>
<StyledLink to={`${defaultPath}heatmap`}>Heatmap</StyledLink>
</ListItem>
</List>
</Wrapper>
);
Expand Down
55 changes: 55 additions & 0 deletions src/examples/Heatmap.js
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use instead:

    bootstrapURLKeys={{
    key: 'xxxxxxxxxxxxxx',
    libraries: ['visualization'],
  }}

Due to google-map-react/google-map-react#673 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 8eab280

heatmap={heatmapData}
/>
)}
</Fragment>
);
}
}

export default Heatmap;
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we align it like the rest? Sorry, OCD 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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';
Expand All @@ -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} />
Copy link
Member

@itsmichaeldiego itsmichaeldiego Feb 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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>
Expand Down