dlearman1
asked on
Print Google map with route directions overlay
I'm printing a Google map with directions out of a Bootstrap modal window.
The base map prints, but I want the map after the directions overlay (the blue line tracing the route) is shown.
Does anyone low how to target the map after the polyline is drawn. The map is drawn inside #mapWrapper.
The base map prints, but I want the map after the directions overlay (the blue line tracing the route) is shown.
Does anyone low how to target the map after the polyline is drawn. The map is drawn inside #mapWrapper.
ASKER
I'm printing programmatically. The site can be seen at www.serenaconstruction.com. The key pieces of code are:
CSS (using Less)
@media screen {
#printSection {
display: none;
}
}
@media print {
body * {
visibility:hidden;
}
#printSection, #printSection * {
visibility:visible;
}
#printSection {
position:absolute;
left:0;
top:0;
}
// #mapWrapper {
// page-break-after: always;
// }
#directionsWrapper {
font-family: Helvetica, HelveticaNeue, sans-serif;
font-size:12px;
font-weight:normal;
line-height:1.5;
}
.printNone{
visibility:hidden;
}
}
js
function printElement(elem, append, delimiter) {
var domClone = elem.cloneNode(true);
var $printSection = document.getElementById("p rintSectio n");
if (!$printSection) {
var $printSection = document.createElement("di v");
$printSection.id = "printSection";
document.body.appendChild( $printSect ion);
}
if (append !== true) {
$printSection.innerHTML = "";
}
document.getElementById("p rintButton ").onclick = function() {
printElement(document.getE lementById ("mapTitle "));
printElement(document.getE lementById ("mapWrapp er"));
printElement(document.getE lementById ("directio nsWrapper" ), true, "<hr />");
window.print();
I'm looking for the how to add the map's directions overlay to the print list. Something like
printElement(document.getE lementById ("google.M aps.Direct ions.????" ));
else if (append === true) {
if (typeof(delimiter) === "string") {
$printSection.innerHTML += delimiter;
}
else if (typeof(delimiter) === "object") {
$printSection.appendChlid( delimiter) ;
}
}
$printSection.appendChild( domClone);
}
CSS (using Less)
@media screen {
#printSection {
display: none;
}
}
@media print {
body * {
visibility:hidden;
}
#printSection, #printSection * {
visibility:visible;
}
#printSection {
position:absolute;
left:0;
top:0;
}
// #mapWrapper {
// page-break-after: always;
// }
#directionsWrapper {
font-family: Helvetica, HelveticaNeue, sans-serif;
font-size:12px;
font-weight:normal;
line-height:1.5;
}
.printNone{
visibility:hidden;
}
}
js
function printElement(elem, append, delimiter) {
var domClone = elem.cloneNode(true);
var $printSection = document.getElementById("p
if (!$printSection) {
var $printSection = document.createElement("di
$printSection.id = "printSection";
document.body.appendChild(
}
if (append !== true) {
$printSection.innerHTML = "";
}
document.getElementById("p
printElement(document.getE
printElement(document.getE
printElement(document.getE
window.print();
I'm looking for the how to add the map's directions overlay to the print list. Something like
printElement(document.getE
else if (append === true) {
if (typeof(delimiter) === "string") {
$printSection.innerHTML += delimiter;
}
else if (typeof(delimiter) === "object") {
$printSection.appendChlid(
}
}
$printSection.appendChild(
}
ASKER
The script above has a typo. Please use this instead;
function printElement(elem, append, delimiter) {
var domClone = elem.cloneNode(true);
var $printSection = document.getElementById("p rintSectio n");
if (!$printSection) {
var $printSection = document.createElement("di v");
$printSection.id = "printSection";
document.body.appendChild( $printSect ion);
}
if (append !== true) {
$printSection.innerHTML = "";
}
else if (append === true) {
if (typeof(delimiter) === "string") {
$printSection.innerHTML += delimiter;
}
else if (typeof(delimiter) === "object") {
$printSection.appendChlid( delimiter) ;
}
}
$printSection.appendChild( domClone);
}
<script>
document.getElementById("p rintButton ").onclick = function() {
printElement(document.getE lementById ("mapTitle "));
printElement(document.getE lementById ("mapWrapp er"));
printElement(document.getE lementById ("directio nsWrapper" ), true, "<hr />");
window.print();
}
This successfully prints the map and directions. But "mapWrapper" only captures the map before the directions overlay has been added. I want to include the polyline route overlay also.
Thanks for your comments.
function printElement(elem, append, delimiter) {
var domClone = elem.cloneNode(true);
var $printSection = document.getElementById("p
if (!$printSection) {
var $printSection = document.createElement("di
$printSection.id = "printSection";
document.body.appendChild(
}
if (append !== true) {
$printSection.innerHTML = "";
}
else if (append === true) {
if (typeof(delimiter) === "string") {
$printSection.innerHTML += delimiter;
}
else if (typeof(delimiter) === "object") {
$printSection.appendChlid(
}
}
$printSection.appendChild(
}
<script>
document.getElementById("p
printElement(document.getE
printElement(document.getE
printElement(document.getE
window.print();
}
This successfully prints the map and directions. But "mapWrapper" only captures the map before the directions overlay has been added. I want to include the polyline route overlay also.
Thanks for your comments.
just do this instead
function gmapPrint() {
var content = window.document.getElement ById("gmap ");
var newWindow = window.open();
newWindow.document.write(c ontent.inn erHTML);
newWindow.print();
}
function gmapPrint() {
var content = window.document.getElement
var newWindow = window.open();
newWindow.document.write(c
newWindow.print();
}
ASKER
Thanks
I will give this a try.
I'm wondering tho, will this also print the turn-by-turn directions or just the map?
I will give this a try.
I'm wondering tho, will this also print the turn-by-turn directions or just the map?
would need to try it but i believe so - i have dismantled my testing widget ...
ASKER
dgrafx,
I tried
<script>
document.getElementById("p rintButton ").onclick = function gmapPrint() {
var content = window.document.getElement ById("gmap ");
var newWindow = window.open();
newWindow.document.write(c ontent.inn erHTML);
newWindow.print();
}
</script>
This resulted in a blank page in a new FF tab.
Thanks for your time and comments
I tried
<script>
document.getElementById("p
var content = window.document.getElement
var newWindow = window.open();
newWindow.document.write(c
newWindow.print();
}
</script>
This resulted in a blank page in a new FF tab.
Thanks for your time and comments
I can test on Firefox later but in the meantime use the code exactly as I gave you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This isn't the complete optimum solution but it helps toward one.
do you mean selecting print from the menu or programmatically?