Invoking a fitBounds on initialization
See original GitHub issueHow to execute a method fitBounds
once the map object initialized?
Where am I so far (terribly wrong, but most of the time works):
render() {
var center = [59.938043, 30.337157];
var zoom = 8;
return (
<div className="search-map">
<GoogleMap
center={center}
zoom={zoom}
ref="googleMap">
{this.renderMarkers()}
</GoogleMap>
</div>
);
},
componentDidUpdate() {
var map = this.refs.googleMap.map_;
if (map) {
var maps = this.refs.googleMap.maps_;
var bounds = new maps.LatLngBounds();
each(this.props.places, (place) => {
var latLng = new maps.LatLng(place.lat, place.lng);
bounds.extend(latLng);
});
map.fitBounds(bounds);
}
}
Most of the time it works, but sometimes an update happens before the map mounted, or in other words googleMapLoader
is resolved.
I believe the correct solution is to invoke props
callback in componentDidMount
GoogleMap
component.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:20 (1 by maintainers)
Top Results From Across the Web
Google Maps map.getBounds() immediately after a call to map ...
The nearest I get is a note on getBounds that says: If the map is not yet initialized (i.e. the mapType is still...
Read more >Fit a map to a bounding box | Mapbox GL JS
... fitBounds() pans and zooms the map viewport from the starting location on the city of Mombasa so that the new visible area...
Read more >Leaflet fitBounds Starting Position - GIS Stack Exchange
The issue I have is that I want to set a start position that isn't the bounds of all of my markers. I...
Read more >Fit bounds after opening infoWindow - Google Groups
So, I'm adding markers to the map and after adding them I open the infoWindow attached to the first marker added with a...
Read more >Maps JavaScript API | Google Developers
Note: When the map is set to display: none , the fitBounds function reads the ... If the map is not yet initialized...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
What is the best way to get
nw
,se
from set of markers?@voold No! have your read this?
Fast and dirty realization and please no questions about as I will not answer