Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lock / retain specified center on resize #308

Closed
wants to merge 5 commits into from
Closed

Lock / retain specified center on resize #308

wants to merge 5 commits into from

Conversation

Marcel-G
Copy link

@Marcel-G Marcel-G commented Jan 23, 2017

#282

Some way to keep the map centered on center / default center prop when _mapDomResizeCallback is called would be useful.

I'm using google-map-react with panControl and dragging disabled, therefore the center cannot change from user input. When the map is resized, I want the map to center on the center prop given to google-map-react not getCenter()

<GoogleMap
  options={{
    panControl: false,
    draggable: false
  }}
  center={{lat: 59.938043, lng: 30.337157}}
  zoom={9}
  lockCenter>
    {Markers}
</GoogleMap>

this.maps_.event.trigger(this.map_, 'resize');
this.map_.setCenter(originalCenter);
this.map_.setCenter(this.props.lockCenter ? originalCenter : currentCenter);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Marcel-G This PR is looking good! But it is throwing an error in this line on Travis CI:

460:27 error Follow `prettier` formatting (expected '\n' but found 't') prettier/prettier

Would you mind checking on that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@itsmichaeldiego, thanks for stepping up as a new maintainer! I've already upgraded to the latest version, thanks to the fix in #452 (comment). However, I need to get this fix landed as well before I can actually take advantage of the fullscreen functionality.

The CI error can be fixed by running yarn lint --fix, or applying the following patch:

diff --git a/src/google_map.js b/src/google_map.js
index aba1ea5..e4a8b8c 100644
--- a/src/google_map.js
+++ b/src/google_map.js
@@ -457,7 +457,9 @@ export default class GoogleMap extends Component {
       const originalCenter = this.props.center || this.props.defaultCenter;
       const currentCenter = this.map_.getCenter();
       this.maps_.event.trigger(this.map_, 'resize');
-      this.map_.setCenter(this.props.lockCenter ? originalCenter : currentCenter);
+      this.map_.setCenter(
+        this.props.lockCenter ? originalCenter : currentCenter
+      );
     }
   };
 

Would you like me to submit a separate PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josephfrazier Thanks for the kind words. This fix seems like the solution to our problems. Feel free to make a PR, that would be awesome! We would also need a modification in the docs so users know they're able to use lockCenter

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick feedback, see #482

@viperfx07
Copy link

viperfx07 commented Apr 4, 2018

Hi
_mapDomResizeCallback is not triggered when I press the fullscreen button on the map.
I've set resetBoundsOnResize to true

I reckon this is caused by detectElementResize that detects the original element instead of the resized/full screen map element

test url:
http://msnlhd.surge.sh/detail

tested
on Chrome v65.0.3325.18, Firefox 59.0.2 and IE11

I'm using google-map-react v0.34.0

@lock
Copy link

lock bot commented Dec 1, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants