Skip to content

Commit

Permalink
Add minimum padding to cluster click zoom so that markers aren't cut off
Browse files Browse the repository at this point in the history
  • Loading branch information
jaryncolbert committed Aug 7, 2019
1 parent eb31902 commit d2e8302
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export default class App extends React.Component {
zoom: 2.5
};

DEFAULT_PADDING = { padding: [50, 50] };

state = {
locations: [],
viewport: this.DEFAULT_VIEWPORT,
Expand Down Expand Up @@ -138,6 +140,7 @@ export default class App extends React.Component {
selected={this.state.selected}
onClick={this.triggerClearInput}
isLoading={this.state.mapLoading}
padding={this.DEFAULT_PADDING}
/>
</div>
</div>
Expand Down
9 changes: 4 additions & 5 deletions src/components/map/LeafletMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ export default class LeafletMap extends React.Component {
};

fitBounds = bounds => {
const { onFitBounds } = this.props;
const { onFitBounds, padding } = this.props;

const fitBoundsOptions = {
padding: [40, 40]
};
const mapElem = this.refs.mapRef.leafletElement;

mapElem.fitBounds(bounds, fitBoundsOptions);
mapElem.fitBounds(bounds, padding);
this.setState({
fitBoundsTriggered: false
});
Expand Down Expand Up @@ -52,6 +49,7 @@ export default class LeafletMap extends React.Component {
selected,
viewport,
isLoading,
padding,
...otherProps
} = this.props;
return isLoading ? (
Expand All @@ -73,6 +71,7 @@ export default class LeafletMap extends React.Component {
maxClusterRadius="45"
locations={locations}
selected={selected}
padding={padding}
/>
</Map>
);
Expand Down
9 changes: 8 additions & 1 deletion src/components/map/LocationClusterGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,19 @@ export default class LocationClusterGroup extends React.Component {
};

render() {
let { locations, selected, fitBoundsFn, ...otherProps } = this.props;
let {
locations,
selected,
fitBoundsFn,
padding,
...otherProps
} = this.props;
return (
<MarkerClusterGroup
ref="clusterGroupRef"
disableClusteringAtZoom={11}
spiderfyOnMaxZoom={false}
onClusterClick={cluster => cluster.zoomToBounds(padding)}
{...otherProps}
iconCreateFunction={this.clusterGroupIcon}>
{locations.map(loc => {
Expand Down

0 comments on commit d2e8302

Please sign in to comment.