react-instantsearch icon indicating copy to clipboard operation
react-instantsearch copied to clipboard

Map zooms out every time it's moved

Open bsiddiqui opened this issue 6 years ago • 9 comments

Using the latest react-instantsearch and have an odd behavior where the map zooms out every time the map is moved.

Here's a video of the bug: https://youtu.be/emmX_4k14vI

My component is pretty bare bones:

class SearchContainer extends Component {
  render() {
    return (
      <div className="home-search nav-margin">
        <Container>
          <InstantSearch
            appId={"TPZU3N3QU7"}
            apiKey={"c08b0985768ff14b1a71a96cb1f2884b"}
            indexName={"properties"}
          >
            <GoogleMapsLoader
              apiKey={"AIzaSyBawL8VbstJDdU5397SUX7pEt9DslAwWgQ"}
            >
              {google => (
                <GeoSearch google={google}>
                  {({ hits }) => (
                    <Fragment>
                      <Control />
                      <Fragment>
                        {hits.map(hit => (
                          <HomeSearchCustomMarker
                            showProperty={this.showProperty.bind(this)}
                            property={hit}
                          />
                        ))}
                      </Fragment>
                    </Fragment>
                  )}
                </GeoSearch>
              )}
            </GoogleMapsLoader>
          </InstantSearch>
        </Container>
      </div>
    );
  }
}

bsiddiqui avatar Nov 12 '18 13:11 bsiddiqui

Indeed there is an issue with Google Maps when the container of the map has dimensions that are not rounded pixel (here is an example that demonstrates the issue with Google Maps alone). Could you check that your container has integer dimensions? The only solution to avoid this issue is to use rounded numbers for the dimensions of the container.

In case you have rounded numbers for the container, could you provide us a working example of the issue? It will help a lot to better understand where the problem come from. Here is a template for the example.

samouss avatar Nov 12 '18 15:11 samouss

@samouss yeah it was an issue with float dimensions. Thanks.

bsiddiqui avatar Nov 12 '18 15:11 bsiddiqui

Thanks for the answer! I'll let the issue opened until we (or Google Maps) fix the issue.

samouss avatar Nov 12 '18 16:11 samouss

Thanks @francoischalifour for finding this issue! We have been pulling out hair out trying to figure out why this happens. Also in the process of testing rounded pixel container size for our map. I'll keep you posted.

UPDATE I spent some time testing this with our example. Indeed there is an issue with decimal pixel widths. However, it seems that it does not happen for increments of .5. Here is a link to a recording I made: https://streamable.com/5d5bh

As you can see, when the container width is 1105.5px the behavior does not occur and at 1116.23px the behavior does occur.

Our frontend dev is working on a solution now. Thank you for the find!

LarryBarker avatar Jan 24 '20 13:01 LarryBarker

@samouss Is there a google map github issue we can follow?

concertcoder avatar Mar 02 '20 14:03 concertcoder

@concertcoder Unfortunately Google Map SDK is not open sourced. There is an issue tracker on Google where I've open an issue a while ago, but it was closed Won't Fix (Intended Behavior).

https://issuetracker.google.com/u/1/issues/116827958

I think we should fix the issue on our side. Last time I checked if we provide a negative value to the padding e.g. -1 it did worked. The problem is to ensure that it works for most cases. You can give this solution a shot, otherwise you have to ensure that the width & height are rounded numbers.

samouss avatar Mar 06 '20 08:03 samouss

So this issue pointed me in the right direction of what was going on one of our sites. Here is my implementation of the fix:

// Resize map element's by rounding down width to closest integer
$(window).on('resize', function(){
  $('#map').width(function(index, currentwidth) {
	return Math.floor($(this).parent('.map-container').width());
  });
}).trigger('resize');

SunnyR avatar May 28 '20 18:05 SunnyR

Another issue on that. Solution is provided above to use fixed dimensions for the MAP Wrapper. BUT: We have clients still using IE11 and therefore the behaivor is a weird zoom again although the MAP Wrapper has fixed dimensions. Any ideas?

mice-guy avatar Jul 29 '20 10:07 mice-guy

Hi - is there any updates are workarounds for this issue? I know we can set fixed widths / heights but unfortunately, if a user zooms in or out the browser window, this can still result in the containing div having float dimensions and displaying this bug.

EDIT: FYI the only way I found a way around this was to use const boundingBoxPadding = !currentRefinement ? undefined : -1; but that obviously requires a fork or copy/paste which is not ideal.

ChrisSargent avatar Nov 23 '20 19:11 ChrisSargent

Google Maps seems to behave as expected now in containers with float values.

Feel free to reopen and attach a reproduction sandbox if necessary.

dhayab avatar Dec 21 '22 15:12 dhayab