New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
snapshot canvas and dom elements like markers #7345
Comments
To be able to capture the image from canvas with the markers, you'll have to convert them into a symbol layer manually — I'm afraid there's no other way, and we can't do the conversion automatically. |
And what about using html2canvas to capture dom elements and map.getCanvas to capture the canvas then combine the 2 canvas ? |
@PBrockmann You shouldn't need to do any merging instead just capture the root dom element with html2canvas that contains the map canvas and your DOM elements. |
Ah... Cool. |
@PBrockmann Make sure to try it on your own map with the preserveDrawingBuffer:true otherwise no map/icons will be captured, which is probably why its not working on the link you provided. |
Ok, I think I am not far: image is well generated but not as a downloadable file. Finally it is not correct since by decoding directly base64 image, cats do not appear... |
So there are a couple of issues at play here, and let me know how this turns out but for downloading from the html2canvas on click see https://stackoverflow.com/questions/31656689/how-to-save-img-to-users-local-computer-using-html2canvas . This is due to href not being resolved by promise until after click download event has occurred, so create a hidden a tag and click that once the promise is resolved. The issue of the cats seems to be from html2canvas if you use the default markers instead it works as expected. So the issue seems to be html2canvas not capturing the divs' background image, and from a quick search this seems to be a common issue so I'll leave the rest to you. Please update though with what you find. |
Ok I follow the roadtrip. And indeed this one is not solved yet. https://jsfiddle.net/PBrockmann/szf9n46q/ has been updated. For now only border outline of markers are captured. Not the box-shadow borders neither the background images. Lost in what to change or experiment. |
There is an issue on box-shadow niklasvh/html2canvas#221 Background images are well captured if encoded as base64 but not with a local file like |
There are two ways to achieve this:
|
Hello @tsuz was playing around a bit, and this will likely impact the performance/speed of generating the image, but it does help quite a bit with the clarity. https://developer.mozilla.org/en-US/docs/Web/CSS/image-rendering //add this //adjust these two lines |
I have tested the get map.getCanvas().toDataURL() as in https://bl.ocks.org/stephanbogner/98ab52a868f1c162644611e7e06f7418 but it captures only the canvas and not markers as they can appear in https://www.mapbox.com/mapbox-gl-js/example/custom-marker-icons/
I do understand that it is because markers are dom elements.
But is there a solution to this today ?
Perhaps, transform markers as symbols with an icon image ? But notice that in my real user case, I have 400 markers, each one with a different image (div rounded with a background-image).
The text was updated successfully, but these errors were encountered: