Save zoom level and position without reloading the map

Sep 13, 2012 at 11:03 AM
Edited Sep 13, 2012 at 11:04 AM

I am trying to avoid reloading my entire page every time zoom

The thing is I have a lot of post backs on my page that draws on the google map, but on every post back the map is drawn from scratch again, then zoom level and location is reset together with that

So if I call GoogleMapControl.Zoom it defaults to 4 and my only way to get around this is to have a OnZoomChanged event and save the zoom in ViewState


public void UserChangedZoomLevel(object sender, MapEventArgs e)
        ViewState["UserZoomLevel"] = e.Zoom;
And then I use this value in Page_LoadComplete that is called afterwards
    protected void Page_LoadComplete(object sender, EventArgs e)
        GoogleMapControl.Zoom = Convert.ToInt32(ViewState["UserZoomLevel"]);

but having this means that everytime the user zooms the page is reload, and even though thats fast its not fluent.

Is there a way to save the zoom level without reloading the map?

Oct 3, 2012 at 7:12 AM

Anyone ?

Oct 3, 2012 at 10:31 AM

I'm using older (v4), but would imagine its the same... since you don't want a postback (and thus a map reload), you've got to use JS to set it to a textbox or somesuch then you can capture the current zoom at next page-event or use a ajax webmethod to send to db, session, or whatever...

So quick example...

Add this into your GoogleMap object: OnClientZoomEnd="_showzoom"

Then add JS like the following (txtMapZoom is a read-only textbox in this case) into your head or other JS include area:

        function _showzoom(oldzoom,newzoom) {
            if (newzoom != parseFloat(newzoom)) return;
            var objTxtMapZoom = document.getElementById('txtMapZoom');
            if (objTxtMapZoom != null)
                objTxtMapZoom.value = newzoom;
Again, its v4 of the control, but would imagine the OnClientZoomEnd event is still there...