From 39c4e848275cf801393bb03c4e93d5629a3c74a6 Mon Sep 17 00:00:00 2001 From: Javier Abadia Date: Mon, 13 Jan 2014 14:22:27 +0100 Subject: [PATCH] add buttons to save to file and load from file --- lib/tiles/offlineEnabler.js | 14 ++++++++++++++ samples/tiles/tiles-indexed-db.css | 5 +++++ samples/tiles/tiles-indexed-db.html | 2 ++ samples/tiles/tiles-indexed-db.js | 30 +++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+) diff --git a/lib/tiles/offlineEnabler.js b/lib/tiles/offlineEnabler.js index b123702..efb333a 100644 --- a/lib/tiles/offlineEnabler.js +++ b/lib/tiles/offlineEnabler.js @@ -176,6 +176,20 @@ define([ }); } + layer.saveToFile = function(fileName, callback) + { + var store = this.offline.store; + + callback(false, "not implemented"); // failed, not implemented + } + + layer.loadFromFile = function(fileName, callback) + { + var store = this.offline.store; + + callback(false, "not implemented"); // failed, not implemented + } + /* internal methods */ layer.estimateTileSize = function() diff --git a/samples/tiles/tiles-indexed-db.css b/samples/tiles/tiles-indexed-db.css index 87d2355..d1265a6 100644 --- a/samples/tiles/tiles-indexed-db.css +++ b/samples/tiles/tiles-indexed-db.css @@ -27,6 +27,11 @@ body > .container { display: none; } +#ready-to-download-ui button +{ + margin-top: 5px; +} + #error-div { margin-top: 10px; display: none; diff --git a/samples/tiles/tiles-indexed-db.html b/samples/tiles/tiles-indexed-db.html index de36b0e..257b31c 100644 --- a/samples/tiles/tiles-indexed-db.html +++ b/samples/tiles/tiles-indexed-db.html @@ -111,6 +111,8 @@ + +
diff --git a/samples/tiles/tiles-indexed-db.js b/samples/tiles/tiles-indexed-db.js index c27f9ca..1b35a1f 100644 --- a/samples/tiles/tiles-indexed-db.js +++ b/samples/tiles/tiles-indexed-db.js @@ -129,6 +129,9 @@ require(["esri/map", on(dojo.byId('go-online-btn'),'click', goOnline); on(dojo.byId('update-offline-usage'),'click', updateOfflineUsage); on(dojo.byId('show-stored-tiles'),'click', toggleShowStoredTiles); + on(dojo.byId('save-file'),'click', saveToFile); + on(dojo.byId('load-file'),'click', loadFromFile); + dojo.byId('go-online-btn').style.display = "none"; esri.show(dojo.byId('ready-to-download-ui')); esri.hide(dojo.byId('downloading-ui')); updateOfflineUsage(); @@ -140,6 +143,7 @@ require(["esri/map", dojo.byId('delete-all-tiles-btn').disabled = true; dojo.byId('go-offline-btn').disabled = true; dojo.byId('go-online-btn').disabled = true; + esri.hide(dojo.byId('go-online-btn')); dojo.byId('update-offline-usage').disabled = true; dojo.byId('show-stored-tiles').disabled = true; esri.hide(dojo.byId('downloading-ui')); @@ -216,6 +220,8 @@ require(["esri/map", { dojo.byId('go-offline-btn').disabled = true; dojo.byId('go-online-btn').disabled = undefined; + dojo.byId('go-offline-btn').style.display = "none"; + dojo.byId('go-online-btn').style.display = ""; basemapLayer.goOffline(); } @@ -224,6 +230,8 @@ require(["esri/map", { dojo.byId('go-offline-btn').disabled = undefined; dojo.byId('go-online-btn').disabled = true; + dojo.byId('go-offline-btn').style.display = ""; + dojo.byId('go-online-btn').style.display = "none"; basemapLayer.goOnline(); } @@ -350,6 +358,28 @@ require(["esri/map", } } + function saveToFile() + { + basemapLayer.saveToFile("tiles.csv", function(success,msg) + { + if(success) + showAlert('alert-success',msg); + else + showAlert('alert-danger',msg); + }); + } + + function loadFromFile() + { + basemapLayer.loadFromFile("tiles.csv", function(success,msg) + { + if(success) + showAlert('alert-success',msg); + else + showAlert('alert-danger',msg); + }); + } + function showAlert(type, msg) { var icon = "";