google-maps-react icon indicating copy to clipboard operation
google-maps-react copied to clipboard

HeatMap doesn't update based on "positions" prop

Open baklarzej opened this issue 6 years ago • 1 comments

In the HeatMap.js class there is some confusion around the name "positions" and "position" now. What is being mapped to "data" of HeatMap is the "positions" prop, but in ComponentDidUpdate and in PropTypes the name "position" is referenced: https://github.com/fullstackreact/google-maps-react/blob/c70a04f668b644a126071c73b392b6094a430a2a/src/components/HeatMap.js#L29 https://github.com/fullstackreact/google-maps-react/blob/c70a04f668b644a126071c73b392b6094a430a2a/src/components/HeatMap.js#L105

In consequence, state updates in higher component (say MapComponent) don't cause the HeatMap to reload, given we pass it that way:

    <HeatMap
          gradient={this.gradient}
          positions={this.state.heatMapPositions}
          opacity={0.5}
          radius={20}
      />

A following workaround seems to work though (set both props to your desired value):

    <HeatMap
          gradient={this.gradient}
          position={this.state.heatMapPositions}
          positions={this.state.heatMapPositions}
          opacity={0.5}
          radius={20}
      />

baklarzej avatar Dec 07 '19 11:12 baklarzej

In the HeatMap.js class there is some confusion around the name "positions" and "position" now. What is being mapped to "data" of HeatMap is the "positions" prop, but in ComponentDidUpdate and in PropTypes the name "position" is referenced: https://github.com/fullstackreact/google-maps-react/blob/c70a04f668b644a126071c73b392b6094a430a2a/src/components/HeatMap.js#L29

https://github.com/fullstackreact/google-maps-react/blob/c70a04f668b644a126071c73b392b6094a430a2a/src/components/HeatMap.js#L105

In consequence, state updates in higher component (say MapComponent) don't cause the HeatMap to reload, given we pass it that way:

    <HeatMap
          gradient={this.gradient}
          positions={this.state.heatMapPositions}
          opacity={0.5}
          radius={20}
      />

A following workaround seems to work though (set both props to your desired value):

    <HeatMap
          gradient={this.gradient}
          position={this.state.heatMapPositions}
          positions={this.state.heatMapPositions}
          opacity={0.5}
          radius={20}
      />

It works for me, but it list some errors on console, than i have changed to the code below, and it works very well.

    <HeatMap
          gradient={this.gradient}
          position={this.state.heatMapPositions[0]}
          positions={this.state.heatMapPositions}
          opacity={0.5}
          radius={20}
      />

Thanks @baklarzej

rianperassoli avatar May 05 '21 12:05 rianperassoli