Guest User

Untitled

a guest
Feb 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. this._loadFromFile = function(file,store,callback){
  2. if (window.File && window.FileReader && window.FileList && window.Blob)
  3. {
  4. // Great success! All the File APIs are supported.
  5. var reader = new FileReader();
  6. reader.onload = function(evt)
  7. {
  8. var csvContent = evt.target.result;
  9. var tiles = csvContent.split("\r\n");
  10. var tileCount = 0;
  11. var pair, tile;
  12.  
  13. if(tiles[0] !== "url,img")
  14. {
  15. return callback(false, "File " + file.name + " doesn't contain tiles that can be loaded");
  16. }
  17.  
  18. for(var i=1; i<tiles.length; i++)
  19. {
  20. pair = tiles[i].split(",");
  21. tile = {
  22. url: pair[0],
  23. img: pair[1]
  24. };
  25. console.log("read",tile.url);
  26. store.store(tile,function(success)
  27. {
  28. console.log(".");
  29.  
  30. if( success )
  31. {
  32. tileCount += 1;
  33. }
  34.  
  35. if( tileCount === tiles.length-1)
  36. {
  37. console.log("finished!");
  38. window.setTimeout(function() { /* refresh layer by zooming in and out, or some way that really refreshes the layer */ }, 1000);
  39. callback(true, tileCount + " tiles loaded from " + file.name);
  40. }
  41. });
  42. }
  43. };
  44. reader.readAsText(file);
  45. }
  46. else
  47. {
  48. callback(false, "The File APIs are not fully supported in this browser.");
  49. }
  50. };
Add Comment
Please, Sign In to add comment