views:

1049

answers:

2

I'm using the Google Maps API v2 and I'd like to be able to print the map the same way as Google does on its Maps page.

You can click the little printer icon and it creates a new popup window with the same map but all the unprintable stuff (like the controls) is taken out. I know that they use @media print to achieve that effect when you hit "Print preview" or "Print" in the navigator. However, the popup window isn't in print mode.

Is there any way of doing the magic trick they're doing, like setting the current media type to "print"? Or or they cheating and setting a custom CSS style cheat?

I've got a Silverlight plugin and a Google Map on the same page and I want to be able to create a popup window containing just the map ready for printing (like Google is doing).

Thanks to http://abcoder.com/google/google-map-api/print-button-for-google-map-api/ I know how to get the HTML content but I can only get the content with all the controls etc on it (which I don't want).

Any help will be appreciated.

+3  A: 

Google maps put a class gmnoprint on all elements that they do not want to print .. so setting this to display:none in your print css file or popup window will hide them ..

.gmnoprint{
  display:none;
}

Of'course this will hide whatever google deems as not-for-printing.. If you want to select other items you will have to somehow parse their html code :(

Gaby
Yeah, I finally noticed that myself while playing with the Developer tools in IE.I added the style and it works just as expected :)
R4cOON
A: 

Another useful approach for printing google maps is to use the Google Static Maps API. You can generate an static image based on a range of display paramters (location, zoom level, size, markers etc...) and include that image in your print view page.

Cannonade
That's not an option for me. I've got loads of custom overlays on the map and I don't quite fancy duplicating the creation logic to be able to print while I've got a perfectly good map image handy.
R4cOON
Fair enough :P ... A limitation of the static API is you aren't able to do all the custom markers etc ... So if you have lots of overlays, not right for you. +1 on the question though :)
Cannonade