React-instantsearch: Map zooms out every time it's moved

Created on 12 Nov 2018  路  9Comments  路  Source: algolia/react-instantsearch

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>
    );
  }
}
鉂わ笍 Bug

Most helpful comment

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.

All 9 comments

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 yeah it was an issue with float dimensions. Thanks.

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

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!

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

@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.

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:

```// map width fix - https://github.com/algolia/react-instantsearch/issues/1737
// 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');

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?

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

econner picture econner  路  3Comments

denkristoffer picture denkristoffer  路  4Comments

flouc001 picture flouc001  路  4Comments

danhodkinson picture danhodkinson  路  3Comments

itsmichaeldiego picture itsmichaeldiego  路  4Comments