Skip to content

Instantly share code, notes, and snippets.

@dejanstojanovic
Forked from jawsthegame/print_gmap.js
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dejanstojanovic/cd486cbdeeef62f48eed to your computer and use it in GitHub Desktop.
Save dejanstojanovic/cd486cbdeeef62f48eed to your computer and use it in GitHub Desktop.
var printMap = function(map) {
map.setOptions({
mapTypeControl: false,
zoomControl: false,
streetViewControl: false,
panControl: false
});
var popUpAndPrint = function() {
dataUrl = [];
$('#map-canvas canvas').filter(function() {
dataUrl.push(this.toDataURL("image/png"));
})
var container = document.getElementById('map-canvas');
var clone = container.clone();
var width = container.clientWidth
var height = container.clientHeight
$(clone).find('canvas').each(function(i, item) {
$(item).replaceWith(
$('<img>')
.attr('src', dataUrl[i]))
.css('position', 'absolute')
.css('left', '0')
.css('top', '0')
.css('width', width + 'px')
.css('height', height + 'px');
});
var printWindow = window.open('', 'PrintMap',
'width=' + width + ',height=' + height);
printWindow.document.writeln($(clone).html());
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
map.setOptions({
mapTypeControl: true,
zoomControl: true,
streetViewControl: true,
panControl: true
});
};
setTimeout(popUpAndPrint, 500);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment