Skip to content

A module for the Azure Maps Web SDK that generates screenshots of the map.

License

Notifications You must be signed in to change notification settings

Azure-Samples/azure-maps-image-exporter

Repository files navigation

page_type description languages products
sample
A module for the Azure Maps Web SDK that generates screenshots of the map.
javascript
typescript
azure
azure-maps

Azure Maps Image Exporter module

A module for the Azure Maps Web SDK that generates screenshots of the map.

Important

In order for this module to work, the maps preserveDrawingBuffer must be set to true when the map is initally loaded and can't be set afterwards.

Note that the screenshot is only of the rendered map canvas, other HTML elements, such as HTML markers and controls are not rendered on the image. Native rendering layers such as BubbleLayer, SymbolLayer, LineLayer, PolygonLayer, ImageLayer, and TileLayer are supported.

Samples

Export Map as Image

Getting started

Download the project and copy the azure-maps-image-exporter JavaScript file from the dist folder into your project.

Usage

//Get map screenshot as an image element.
atlas.MapImageExporter.getImage(map).then(function(mapImg) {
    //Do something with the image element, in this case append if to the document body.
    document.body.appendChild(mapImg);
}, function (e) {
    alert(e.message);
});

//Get map screenshot as a data URI.
atlas.MapImageExporter.getDataUri(map).then(function (dataUri) {
    //Do something with the data URI. In this case its openning a new tab in the browser and loading it in an img tag.
    var win = window.open();
    win.document.write('<img src="' + dataUri + '"/>');
}, function (error) {
    alert(error);
});

//Get a map screenshot as an image blob.
atlas.MapImageExporter.getBlob(map).then(function (mapImgBlob) {
    //Do somethimg with the image blob.
}, function (e) {
    alert(e.message);
});

API Reference

MapImageExporter class

Namespace: atlas

A static class for generating screenshots of the map.

Static Methods

Name Return type Description
getImage(map: atlas.Map) Promise<HTMLImageElement> Generates a Image object for an image of the map.
getDataUri(map: atlas.Map, mimeType?: 'image/png' | 'image/jpeg') Promise<string> Generates a data URI for an image of the map. Mime type defaults to 'image/png'.
getBlob(map: atlas.Map) Promise<Blob> Generates a Blob for an image of the map.

Related Projects

Additional Resources

Contributing

We welcome contributions. Feel free to submit code samples, file issues and pull requests on the repo and we'll address them as we can. Learn more about how you can help on our Contribution Rules & Guidelines.

You can reach out to us anytime with questions and suggestions using our communities below:

This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

License

MIT

See License for full license text.

About

A module for the Azure Maps Web SDK that generates screenshots of the map.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published