Export the map viewport instead of the layers

And filter out the controls elements
This commit is contained in:
Frederic Junod
2019-04-23 10:17:14 +02:00
parent 2ac1095c52
commit 93c25d4f82
2 changed files with 19 additions and 2 deletions

View File

@@ -25,9 +25,17 @@ const map = new Map({
})
});
// export options for html-to-image.
// See: https://github.com/bubkoo/html-to-image#options
const exportOptions = {
filter: function(element) {
return element.className.indexOf('ol-control') === -1;
}
};
document.getElementById('export-png').addEventListener('click', function() {
map.once('rendercomplete', function() {
toPng(map.getViewport().querySelector('.ol-layers'))
toPng(map.getTargetElement(), exportOptions)
.then(function(dataURL) {
const link = document.getElementById('image-download');
link.href = dataURL;