How to view Google Maps in print mode?
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 :(
how to use media print, for google maps
This cannot be done using CSS.
You will need a special page with a map sized as it has to be printed, or zoom-out the map before printing(this may be done using javascript).
Google Maps API V3 Printing Maps
I guess by simple yet subtle DOM manipulation, you can get the "snapshot" of your Google Maps (well, theoretically - any maps :)) viewer and perfectly print it in any browsers. Assuming $mapContainer
is the main container of your maps, related code is:
// printAnyMaps ::
function printAnyMaps() {
const $body = $('body');
const $mapContainer = $('.map-container');
const $mapContainerParent = $mapContainer.parent();
const $printContainer = $('<div style="position:relative;">');
$printContainer
.height($mapContainer.height())
.append($mapContainer)
.prependTo($body);
const $content = $body
.children()
.not($printContainer)
.not('script')
.detach();
/**
* Needed for those who use Bootstrap 3.x, because some of
* its `@media print` styles ain't play nicely when printing.
*/
const $patchedStyle = $('<style media="print">')
.text(`
img { max-width: none !important; }
a[href]:after { content: ""; }
`)
.appendTo('head');
window.print();
$body.prepend($content);
$mapContainerParent.prepend($mapContainer);
$printContainer.remove();
$patchedStyle.remove();
}
Note that you can flexibly replace $printContainer
by any print template. Here I just use a simple <div>
that serves as a placeholder of the snapshot.
Working code here: http://jsfiddle.net/glenn/6mx21ted
Related Topics
Why We Are Using Sass, Even We Are Using SCSS
Chrome Does Not Support The CSS @Page
Vertically Align Text to The Bottom of The Box
Fixed Position Misbehaviour in Ie11
Change Background Image of Li on an A:Hover
iPhone Viewport Height Too Large in Landscape Mode
Overflow Property Returning Auto Value
Apply Different Styles to Input Text Field When Empty (Using CSS)
How to Import Styles in The Right Order in Webpack
Make an Element Overlap Contents Below It Using Bootstrap
Adding Background Image to Shiny Navbarpage
Setting Font Color of <A> Inside a Li Tag
Material-Ui-Next: Setting Image Size to Fit a Container
Currentcolor Inheritance for Svg Url
CSS Layout Help - Multiline Address
How to Style The Last Slotted Element in a Web Component
Ie Question: How Many CSS Includes Can It Handle
How to Position a Background Image Relative to The Centre of an Element