Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- this._loadFromFile = function(file,store,callback){
- 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;
- var pair, tile;
- if(tiles[0] !== "url,img")
- {
- return callback(false, "File " + file.name + " doesn't contain tiles that can be loaded");
- }
- for(var i=1; i<tiles.length; i++)
- {
- pair = tiles[i].split(",");
- tile = {
- url: pair[0],
- img: pair[1]
- };
- console.log("read",tile.url);
- store.store(tile,function(success)
- {
- console.log(".");
- if( success )
- {
- tileCount += 1;
- }
- if( tileCount === tiles.length-1)
- {
- console.log("finished!");
- window.setTimeout(function() { /* refresh layer by zooming in and out, or some way that really refreshes the layer */ }, 1000);
- callback(true, tileCount + " tiles loaded from " + file.name);
- }
- });
- }
- };
- reader.readAsText(file);
- }
- else
- {
- callback(false, "The File APIs are not fully supported in this browser.");
- }
- };
Add Comment
Please, Sign In to add comment