Skip to content
This repository has been archived by the owner on May 24, 2021. It is now read-only.

adds function to maintain map centerpoint when template is resized #11

Merged
merged 1 commit into from
Dec 28, 2012

Conversation

chrislkeller
Copy link
Contributor

Hey Derek...

I ran across a code snippet that will hold the map's centerpoint when the page is resized.

It's ultra small and minor but I figured I'd add it and see what you thought.

The function is:

calculateCenter: function() {
    center = map.getCenter();
},

And it's used when the map is created:

google.maps.event.addDomListener(map, 'idle', function() {
    MapsLib.calculateCenter();
});

google.maps.event.addDomListener(window, 'resize', function() {
    map.setCenter(MapsLib.map_centroid);
});

For some reason my commit to the fork threw things off and it looks like much more was changed, but only the above code was added.

Take care sir and keep up the great work.

Chris K.

@derekeder
Copy link
Owner

looks good! thanks Chris!

for all these extra line diffs, my guess is your text editor strips extra white space

merging!

derekeder added a commit that referenced this pull request Dec 28, 2012
adds function to maintain map centerpoint when template is resized
@derekeder derekeder merged commit 0a986e5 into derekeder:master Dec 28, 2012
@jaypinho
Copy link

jaypinho commented Jul 7, 2016

Hello there, I'm a bit of a JS noob so apologies in advance for my ignorance, but why wouldn't that resize listener read something like this instead:

google.maps.event.addDomListener(window, 'resize', function() {
    map.setCenter(MapsLib.center);
});

I.e. It seems like, whenever the map stops resizing, it should reset to the center variable, right? Why is it using MapsLib.map_centroid instead? (And also, where is center even being defined as a variable?) It looks like one variable (center) is being written to when the map loads but another is being read when it's resized. Am I missing something?

@chrislkeller
Copy link
Contributor Author

@jaypinho, and @derekeder correct me if I'm off target because it's been a while...:

  • RE: why is it using MapsLib.map_centroid instead?
    • In the context of this pull request, the MapsLib object contained map_centroid with a value of the center.
  • RE: where is center even being defined as a variable?
    • In the context of this pull request, center is defined in the MapsLib object map_centroid.
    • In the current code the center is being set here.

@jaypinho
Copy link

jaypinho commented Jul 7, 2016

@chrislkeller Thanks for the quick reply! Doesn't this mean that the idle event listener isn't necessary then? Because it looks like map_centroid is being set when the map loads, and then it's being read again when the map resizes. The calculateCenter() function used in the idle listener doesn't seem to be referenced anywhere else. Could be missing something here though.

@jaypinho
Copy link

jaypinho commented Jul 9, 2016

FWIW, I just commented out the self.calculateCenter(); line in the idle event listener and nothing seems to have changed in the functionality: the map still resets to the center whenever the window is resized. So I think it's unnecessary.

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

3 participants