html2canvas: Problem to generate the image of map (Google Maps)
hi, guys. I need to generate a image of my dialog:

Using html2canvas, but the image create doesn’t show the map:

My code:
function imagem()
{
var html2obj = html2canvas($('#dialogPrint'));
var queue = html2obj.parse();
var canvas = html2obj.render(queue);
var img = canvas.toDataURL();
window.open(img);
};
i need help, please. thanks
About this issue
- Original URL
- State: open
- Created 10 years ago
- Comments: 54 (7 by maintainers)
Commits related to this issue
- Fix Google Tile Layer screenshots The Google Maps JavaScript API always uses CSS transforms, which are not supported by PhantomJS. We convert the CSS transform values to CSS left and top values befor... — committed to WikiWatershed/model-my-watershed by rajadain 8 years ago
- Fix Google Tile Layer screenshots The Google Maps JavaScript API always uses CSS transforms, which are not supported by PhantomJS. We convert the CSS transform values to CSS left and top values befor... — committed to WikiWatershed/model-my-watershed by rajadain 8 years ago
Seems that in the new version of google maps transform is applied to the different div. Using @GCorbel’s solution but with this selector (“.gm-style>div:first>div:first>div:last>div”) seems to work. Though I haven’t yet tested it thoroughly.
Fixed !
The fix for chrome I stupidly copy/pasted was not triggered.
I did this :
The very long selector in html2canvas is for have map without buttons and options.
I works now, thanks.
Looks like the latest version of google map (v3.32) released recently has a new experimental renderer. https://developers.google.com/maps/documentation/javascript/releases
This has broken the fix. I only did a quick testing, but it seems like now things are broken equally in all browsers (not just for Chrome), so hopefully that will make it easier to fix in the next version of html2canvas?
But a quick work-around would be to use the older version of gmap, where the fix would still be working fine.
@TGOlson It’s really problem with CSS3 transformations, because current release of html2canvas is able to render only “one level” of transformation - it doesn’t stack them. You can verify that problem is in transformations simply by playing with google maps - usually, screenshot like this is given:
(In css, whole map is positioned correctly but after disabling css3, this happens)
Only solution is to implement whole css3 transformations stack. I don’t know, if it’s in progress by Niklas, but someone should do it 😃
Hmm seems this problem is back for me, I have to pan the map to see the issue and when I pan and use Html2Canvas to get the screen grab, some areas show as blank grey?
@hseeda Thank you! Your selector was doing the trick for me!
Here’s my slightly modified selector that does work (at least for me, haha)
However, now it’s cutting off the Google Logo which always has to show in order to comply with the terms and conditions 😦
Well well, I’ll just clone the node or something. I’ve been fighting this map for a while now 😄
This works for me:
@Ananda-Pryana I’ve tried your jsFiddle however the fix does not seem to work anymore. Is there any other solution ?
Thanks in advance.
link https://stackblitz.com/edit/angular-agm-maps-html2canvas-nice
And finally it worked with my angular v2 +
Thanks to @imlinus and @hseeda ! This selector works perfectly for me! and it even keeps the google logo, thanks!
The issue with blank map or an error generating the canvas was tricky, but eventually what fixed it for me was adding this config:
Thanks @Ananda-Pryana! I had this working last week then moved it to a new platform and I thought the move was what broke it. I was totally going down a rat hole assuming the new environment was the culprit. I downgraded to 3.30 and all is well.
@niklasvh I can confirm that it is still an issue with the latest version. Here is a fiddle I created while testing this issue: http://jsfiddle.net/9agom947/4/
The fiddle shows the problem as described in the linked stackoverflow question, not necessarily what’s in the OP of this thread. If you don’t pan the map, there is no problem in getting the map to be copied. Once you pan the map, in Chrome but not in FireFox, the copied map will be blank outside the region that was initially loaded.
The fix given in this thread does seem to solve the problem.
Does the above script work for Google Maps v3?
My requirement is to take a screenshot of a Google Map v3 with a route drawn on it.
It works nicely in Firefox, but in Chrome there is no marker or route. I am already using custom markers.
I have a difficult time debugging because there is no error in console and logging is so limited.
Has anyone solve the issue in Chrome? I have tried the proxy scripts in two languages, but neither seems to make a difference.