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

HeatmapLayer and withScriptjs are sort-of incompatable #409

Closed
ZephD opened this issue Dec 20, 2016 · 4 comments
Closed

HeatmapLayer and withScriptjs are sort-of incompatable #409

ZephD opened this issue Dec 20, 2016 · 4 comments

Comments

@ZephD
Copy link

ZephD commented Dec 20, 2016

HeatmapLayer requires a google.maps.LatLng object and cannot accept a LatLngLiteral ({lat:0, lng:0}).

However, google.maps.LatLng is loaded asynchronously with withScriptjs, and therefore is not available when creating the props.

My current workaround is to convert the data upon render if window.google exists.

export MyHeatMapLayer({heatmapData}) => {
  let convertedHeatmapData;
  if (window.google) {
      convertedHeatmapData = heatmapData.map(d => ({
        location: new window.google.maps.LatLng(d.location || d),
        weight: d.weight || 1,
      }));
    }
  return (<HeatmapLayer data={convertedHeatmapData} />);
}

It may be beneficial to do this within HeatmapLayer, allowing us to use LatLngLiterals.
Also, we can do it upon data set, rather than upon render, reducing how often you loop through the data.

@matthill1
Copy link

Hey ZephD. I take it then you managed to sucesfully get the react-google-maps to display heatmap data? Would you mind sharing the source code

@ZephD
Copy link
Author

ZephD commented Dec 21, 2016

@matthill1 : I had to manually tweak the react-google-maps code. See #376.

This, plus the code above to translate the LatLng objects to google's LatLng objects if google exists.

@matthill1
Copy link

matthill1 commented Dec 23, 2016

I managed to get it to display in the following way:

const GoogleMapHeatMaps = withGoogleMap(props => (
  <GoogleMap
    defaultZoom={4}
    defaultCenter={centerLocation}
  >
<HeatmapLayer data = {heatmapdata}/>
 </GoogleMap>
)
and 

export default class Map extends Component {
render() {
return (
      <GoogleMapImageMarkersandHeatMaps
        containerElement={
          <div style={{ height: `100%` }} />
        }
        mapElement={
          <div style={{ height: `100%` }} />
        }
/>
    );
  }
}

where heatmapdata is set within const GoogleMapHeatMaps

@tomchentw
Copy link
Owner

Please refer to Getting Help section in the README (or #469).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants