(Originally posted to http://groups.drupal.org/node/9037#comment-28222)

I'm looking for a way for a gmap view to remember its zoom level and centre if the view is refreshed, eg after changing exposed filter values.

Here's a gmap view that shows photos of Hong Kong, located by where they were taken, and with the option to select a date range for when the photos were taken:
http://www.batgung.com/hong-kong-photo-map

If I zoom in on the map, eg to just look at Hong Kong island, there are still too many markers. So then I might narrow down the date range, eg 1900-1930 and click 'search'. But that refreshes the view which means the map goes back to its default zoom & centre.

I'd welcome any suggestions on how to keep the zoom and centre. I'm thinking when the 'search' button is clicked there would be some javascript that queries the google map for current zoom and centre, and then builds those values into the url of the next query.

Then after the new view is displayed, there would be javascript that reads the url and sets the zoom & centre.

Does that sound doable, or is there a better / easier way? I'm using Drupal 5 with gmap, location, and views.

Thanks, MrB

There was one reply to that mesage before moving here:

tom_o_t - Wed, 2008-02-20 22:47
I think you'll need to use some javascript, to save the current center use something along the lines of:

var center = map.getCenter();
and then to set the center of the new map

map.setCenter(center);
Hope this helps. It might be worth moving this discussion into the issues queue for the gmap module - there may be more people there who could help.

Comments

davidhk’s picture

With Tom's comments, and the information at http://drupal.org/node/150939 I've got it working.

The part that feels a bit klunky is knowing when to do the re-center&zoom. I'm currently using a timeout to trigger my javascript some time after the $(document).ready event, as described at http://drupal.org/node/223613

Is there a way to set the javascript to run immediately after GMap has finished all of its initialisation? It looks as though binding my function as a handler for the "ready" event could be the way to go - is that what the "ready" event is intended for?

Regards, MrB

rooby’s picture

Status: Active » Closed (won't fix)

Drupal 5 is no longer supported.

If this issue affects drupal 6 or 7 please look for an existing issue for that version or else update this issue accordingly.