question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fit Map Bounds to Makers/Elements Automatically?

See original GitHub issue

Can we add a Boolean input binding to the SebmGoogleMap component that automatically fits the map to the aggregate bounds of the markers/shapes/other map elements it contains?

If I’m not mistaken, it’s pretty easy to do in the native Google Maps JS API…you just create a new bounds, then loop through all the elements on the map and extend the bounds, the finally tell the map object for fit the bounds.

Currently, its a pain to manually update the map bounds every time a marker changes. Thanks.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:14
  • Comments:38 (5 by maintainers)

github_iconTop GitHub Comments

17reactions
adrienlamottecommented, Feb 1, 2018

+1 😃

I need to bound the map around my marker on load. Here is how I solved that for now :

<agm-map (mapReady)="storeMapReady($event)">
    <agm-marker *ngFor="let store of storesList" [latitude]="store.latitude" [longitude]="store.longitude"></agm-marker>
</agm-map>
public storeMapReady(map){
    this.storeMap = map;
    this.storeMap.fitBounds(this.findStoresBounds());
}

public findStoresBounds(){
    let bounds:LatLngBounds = new google.maps.LatLngBounds();
    
    for(let store of this.storesList){
      bounds.extend(new google.maps.LatLng(store.latitude, store.longitude));
    }
    
    return bounds;
}
8reactions
joostvanmeeuwencommented, Oct 24, 2017

Any update?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fit Map Bounds to Makers/Elements Automatically? · Issue #781
I need to make the map auto zoom / center based on the map points to be shown. based on the google api...
Read more >
leaflet - How to fit bounds after adding multiple markers
I am using this piece of code to display map markers pulled from a MySQL database using leaflet js on an open street...
Read more >
Fit map to bounds exactly - leaflet - Stack Overflow
fitBounds (bounds, {padding: [50, 50]}); });. I'm trying to fit a map as precisely as possible to a set of bounds that closely...
Read more >
Fit a map to a bounding box | Mapbox GL JS
This example zooms and pans the map so the new visible area of the map fits within the specified geographical bounds.
Read more >
Map.fitBounds(), zoom and center after resizing the map
In V2, this was my method for auto-center+zoom a map given a LatLngBounds: autoZoom: function() {. this.map. ... //fit map using map api...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found