Use FileSaver.js in export-map example

Instead of relying on the download attribute.
This commit is contained in:
Frederic Junod
2016-10-17 08:50:54 +02:00
parent b89eb77f20
commit 92bd1d67a8
3 changed files with 14 additions and 21 deletions

View File

@@ -1,3 +1,5 @@
// NOCOMPILE
// this example uses FileSaver.js for which we don't have an externs file.
goog.require('ol.Map');
goog.require('ol.View');
goog.require('ol.control');
@@ -31,20 +33,12 @@ var map = new ol.Map({
})
});
var exportPNGElement = document.getElementById('export-png');
if ('download' in exportPNGElement) {
exportPNGElement.addEventListener('click', function() {
map.once('postcompose', function(event) {
var canvas = event.context.canvas;
exportPNGElement.href = canvas.toDataURL('image/png');
document.getElementById('export-png').addEventListener('click', function() {
map.once('postcompose', function(event) {
var canvas = event.context.canvas;
canvas.toBlob(function(blob) {
saveAs(blob, 'map.png');
});
map.renderSync();
}, false);
} else {
var info = document.getElementById('no-download');
/**
* display error message
*/
info.style.display = '';
}
});
map.renderSync();
});