On my page, there is a container which use Google Maps API to display a map, there is a button below it, user can drag the map to a position, then click the button, I'd like to take the screenshot of the map displayed in the container now and show it in a canvas. Is it possible to do this with pure JavaScript?
Just need to support Chrome
Open the Google Maps app on your Android phone or tablet. Browse the app to find the area you want to capture. When you're ready to take a screenshot, press the Power and Volume Down buttons together at the same time. The screenshot should be automatically generated and saved in a Screenshots folder in your Gallery.
Note that we cannot provide high-resolution or vector screen captures of Google Maps; however, you may use Google Earth Pro or Earth Studio on desktop to save and print high-resolution JPEGs. Images can be exported up to 4K.
It will be hard to do without browser support. But you can use Google Static Maps API: https://developers.google.com/maps/documentation/staticmaps/
Example: https://developers.google.com/maps/documentation/staticmaps/#quick_example
There is some projects to draw HTML DOM to canvas:
You can also integrate javascript with some server-side solution (using webkit) for example phantomjs
Code example: (read more here)
var page = require('webpage').create();
page.open('http://www.google.com', function() {
page.viewportSize = {width: 1024, height: 768};
page.render('screenshot.png');
phantom.exit();
});
If you need only chrome solution for specific range of users you can write your own chrome extension to do this: Taking screenshot using javascript for chrome extensions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With