Refreshing the map canvas?

3,188 views
Skip to first unread message

MacGoose

unread,
Jun 6, 2010, 3:18:49 AM6/6/10
to Google Maps JavaScript API v3
Hi!

I'm setting up Google Maps on a page where I will have the map canvas
at 70% width and a sidepanel at 30%.

Now when I try to hide the sidepanel and set the map canvas to 100% it
still "thinks" it has a 70% width. For example the center of the map
is not correct for 100%, and also the loading of the tiles is sporadic
where the sidepanel was before. It's basically clipping away where
the panel used to be.

Is there someway to refresh the Maps API to use the new width after
the resize? And this without "reloading" the page and loosing
position, searches, etc...

Also, I'm doing this for my company's intranet - not public. Before
you had to sign up for a non public API key and pay for it I think.
How is it now? All I can find is that there is no keys for V3. But
how about non public intranets?

, MacGoose

Chad Killingsworth

unread,
Jun 6, 2010, 7:13:15 AM6/6/10
to Google Maps JavaScript API v3
I'll let someone else handle the licensing questions.

Here's what you need for the resize:

google.maps.event.trigger(map, 'resize');

Chad Killingsworth

MacGoose

unread,
Jun 6, 2010, 8:18:42 AM6/6/10
to Google Maps JavaScript API v3
Hi and thanx for you time.

But I believe that an event trigger like this makes me able to handle
on the resize. But what I want is the API to update its canvas data.

When I resize the map canvas from 100% to 70% it seems like the API
still thinks it has a size of 70% because for example the center of
the map is still in the "old" 70% center, and not the new 100% center.

So is there a way to explicitly tell the Maps API that it need to
refresh its size data because its canvas has resized. Becasue I don't
think the API does this correctly as it is now. I could fix up an
example but I don't have the time right now. If things are unclear I
can do it later...

, MacGoose

Rossko

unread,
Jun 6, 2010, 6:17:33 PM6/6/10
to Google Maps JavaScript API v3
> So is there a way to explicitly tell the Maps API that it need to
> refresh its size data because its canvas has resized.

Yes, you just got told it by Chad. Have you tried it? You could
search this group for ''resize" if you needed more confirmation before
trying it.

> I could fix up an
> example but I don't have the time right now.

Guess it's not very important then.

MacGoose

unread,
Jun 7, 2010, 1:09:22 AM6/7/10
to Google Maps JavaScript API v3
> Yes, you just got told it by Chad.  Have you tried it?  You could
> search this group for ''resize" if you needed more confirmation before
> trying it.

Yes I have. It did nothing.

> Guess it's not very important then.

O_o

Chad Killingsworth

unread,
Jun 7, 2010, 8:31:40 AM6/7/10
to Google Maps JavaScript API v3
When you change the map size, it does exactly what you mentioned - it
extends the canvas. If you want the center point to be reset, you'll
need to get the map center before you resize, then resize the map and
trigger the resize event, then reset the map center to your previous
center point.

Chad Killingsworth
Reply all
Reply to author
Forward
0 new messages