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.

Set fitBounds only initially

See original GitHub issue

I want to set initial fitBounds when the map loads for the first time. If I do so, the map goes back to these bounds whenever data changes (it’s supposed to be a live map with moving Features). That’s annoying to the user because they might be browsing the map by manually moving the view port and zooming. Whenever there’s an update, they’re back at the position computed from fitBounds.

What’s the best way of initially setting fitBounds but then don’t go back to these bounds on update?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
alex3165commented, Dec 6, 2017

Hey @mastertinner , you should not break reference equality between rendering meaning you should keep the reference of the array of your fitbounds: Dont do:

<map fitBounds={[...]}>

Instead do:

<map fitBounds={this.state.fitBounds}>
0reactions
cloudlenacommented, Dec 10, 2017

Thanks, @alex3165! That worked perfectly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google Maps API v3 - fitBounds centers only one marker
Your code is always calling fitBounds with a LatLngBounds of only one point, the last marker... If you are calling that function several...
Read more >
leaflet - how does one reset map.fitbounds (zoomtofeature ...
I guess I could set a global variable to hold the state on the first event, and do an if inside zoomToFeature to...
Read more >
Setting the exact bounds of a map - Google Groups
I've got a simple map and I want to set it's exact bounds. I tried using map.fitBounds(myBounds) and map.panToBounds(myBounds), but both do not...
Read more >
Map | MapLibre GL JS Docs
A Map#fitBounds options object to use only when fitting the initial bounds provided above. options.renderWorldCopies. boolean. default: true. If true , multiple ...
Read more >
Map | Mapbox GL JS
A Map#fitBounds options object to use only when fitting the initial ... By default, GL JS will not set a language so that...
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