react-map-gl icon indicating copy to clipboard operation
react-map-gl copied to clipboard

Expose map fitBounds method to Map component

Open nextstopsun opened this issue 5 years ago • 2 comments

It's hard to set appropriate map center when you have UI that overlaps map component. Setting map viewport doesn't have option to include padding in pixels.

The only native method that takes padding parameters is fitBounds, which, unfortunately, is not exposed to Map component props.

Could be great to have a convenient method to set map viewport with padding option.

nextstopsun avatar Nov 21 '19 08:11 nextstopsun

Is there currently no way to show all Markers like this?

https://stackoverflow.com/a/35715102

var bounds = new mapboxgl.LngLatBounds();
markers.features.forEach(function(feature) {
    bounds.extend(feature.geometry.coordinates);
});
map.fitBounds(bounds);

braco avatar Jul 25 '20 21:07 braco

I have a bit of a fundamental question that seems to pertain to this issue here; fundamental because I know that it's a caveat to these React wrapper mapboxgl libraries (React/MapboxGL state becoming out-of-sync)

My question is what are some of the 'gotchas' that I should be aware of when passing in originalEvent parameters to ensure that the update hits the onViewportChange handler?

If I'm passing around the map context on my own, and running native methods like fitBounds and passing in { originalEvent: e } - the onViewportChange handler is triggered, and my own state tracking is preserved. I have a few custom map controls that interact with the Map in this way. Is this how I'm supposed to be doing things?

What is the main drawback to "hacking" this (for example, I have one situation where the map update is based on another state hook so temporarily just passing in a psuedo event i.e. { originalEvent: "EVENT" } to trigger onViewportChange; I know this is not good practice, but curious to where real harm is)

As an aside, I was resigned to just run my own implementation of React and mapboxgl (the Uber implementation was very buggy for me) until I stumbled across this, and it was kismet that it was another Urbica production. You always do fantastic work (I've used your 'on the fly' vector tileserver martin). I love that this is meant to be simple and not stray too far from the vanilla mapbox api.

So the sincerest, earnest of thanks for being so great!

garretteklof avatar Aug 31 '20 05:08 garretteklof