implemented load of tiles from csv file

This commit is contained in:
Javier Abadia 2014-01-13 23:41:58 +01:00
parent 220a9476c0
commit e94f1b83f0
4 changed files with 57 additions and 7 deletions

View File

@ -20,11 +20,13 @@
- [x] keep on downloading tiles even if one of them fails
- [x] add message telling that something failed while initing the indexedDB
- [x] update README.md
- [x] save/load to/from csv file
+ http://www.html5rocks.com/es/tutorials/file/dndfiles/
- [ ] better UI for selecting file to load
- [ ] include FileSaver.js and Blob.js as submodules? https://github.com/eligrey/Blob.js and https://github.com/eligrey/FileSaver.js
- [ ] search for CDN included files and bring them to local
- [ ] save/load to/from csv file
+ http://www.html5rocks.com/es/tutorials/file/dndfiles/
- [ ] include FileSaver.js and Blob.js as submodules? https://github.com/eligrey/Blob.js and https://github.com/eligrey/FileSaver.js
- [ ] better tile estimation and limits
- [ ] allow naming caches?

View File

@ -198,11 +198,42 @@ define([
})
}
layer.loadFromFile = function(fileName, callback)
layer.loadFromFile = function(file, callback)
{
var store = this.offline.store;
callback(false, "not implemented"); // failed, not implemented
if (window.File && window.FileReader && window.FileList && window.Blob)
{
// Great success! All the File APIs are supported.
var reader = new FileReader();
reader.onload = function(evt)
{
var csvContent = evt.target.result;
var tiles = csvContent.split("\r\n");
var tileCount = 0;
for(var i=1; i<tiles.length; i++)
{
var pair = tiles[i].split(',');
var tile = {
url: pair[0],
img: pair[1]
}
store.add(tile,function(success)
{
if( success )
tileCount += 1;
if( tileCount == tiles.length-1)
callback(true, tileCount + " tiles loaded from " + file.name);
});
}
}
reader.readAsText(file);
}
else
{
callback(false, 'The File APIs are not fully supported in this browser.');
}
}
/* internal methods */

View File

@ -105,6 +105,8 @@
<button id="show-stored-tiles" type="button" class="btn btn-default"><i class="fa fa-th"></i> <span id="show-stored-tiles-caption">Show Stored Tiles</span></button>
<button id="save-file" type="button" class="btn btn-default"><i class="fa fa-download"></i> Save to File</button>
<button id="load-file" type="button" class="btn btn-default"><i class="fa fa-upload"></i> Load from File</button>
<br>
<input type="file" id="file-select" name="file-select">
</div>
</div>
<div id="downloading-ui">

View File

@ -247,7 +247,11 @@ require(["esri/map",
else
showAlert("alert-danger", "Can't delete tiles: " + err);
setTimeout(updateOfflineUsage,0); // request execution in the next turn of the event loop
setTimeout(function()
{
updateOfflineUsage();
showStoredTiles(showTiles);
},0); // request execution in the next turn of the event loop
});
}
@ -371,12 +375,23 @@ require(["esri/map",
function loadFromFile()
{
basemapLayer.loadFromFile("tiles.csv", function(success,msg)
var selectedFile = dojo.byId('file-select').files[0];
if( !selectedFile )
{
showAlert('alert-warning',"Please, select one file");
return;
}
basemapLayer.loadFromFile(selectedFile, function(success,msg)
{
if(success)
showAlert('alert-success',msg);
else
showAlert('alert-danger',msg);
updateOfflineUsage();
showStoredTiles(showTiles);
});
}