I am trying to export a google map that includes a route (using polylines) to an image, but in the result the line does not appear. With some css transformation, it worked fine with the google maps api v3.31, but since this version is no longer available after August I need to use v3.33. And in this case the polyline just disappears in the printed image. Other components do appear in the result however.
I could reproduce the problem in the following sample:
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 7,
center: new google.maps.LatLng(53.140665, 8.805315),
mapTypeId: 'roadmap'
});
var routeCoordinates = [
{lat: 52.593534, lng: 7.327996},
{lat: 52.701129, lng: 7.692394},
{lat: 52.459662, lng: 8.264844},
{lat: 52.697619, lng: 8.705006},
{lat: 52.297608, lng: 9.225077}
];
var routePath = new google.maps.Polyline({
map: map,
path: routeCoordinates,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
//console.log('routePath=' + routePath.getPath().getArray());
routePath.setMap(map);
}
Using the following options in html2canvas:
var options = {
useCORS: true,
allowTaint: false
};
And applying the following transformation:
var mapNodes = '.gm-style>div:first>div:first>div:last>div';
var transformer = $(mapNodes).css('transform');
var comp = transformer.split(',');
var mapLeft = parseFloat(comp[4]);
var mapTop = parseFloat(comp[5]);
$(mapNodes).css({
'transform': 'none',
'left': mapLeft,
'top': mapTop
});
Tested (among others) in:
- html2canvas: html2canvas 1.0.0-alpha.12
- Browser & version: Firefox Quantum 60.0.2 (64-bit)
- Operating system: Win 7
- Google maps api: v3.33 (v3.32 has also the same issue)
Any hint what might be the problem there?
Thank you!