Home

Awesome


page_type: sample description: A module for the Azure Maps Web SDK that generates screenshots of the map. languages:


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 <br/><img src="https://samples.azuremaps.com/map/export-map-as-image/screenshot.jpg" height="200px">

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

NameReturn typeDescription
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.