diff --git a/www/app/maps/map/map.controller.js b/www/app/maps/map/map.controller.js index 30af701c..91eaffb1 100644 --- a/www/app/maps/map/map.controller.js +++ b/www/app/maps/map/map.controller.js @@ -31,6 +31,7 @@ vm.isWeb = IS_WEB; vm.newNestModal = {}; vm.newNestProperties = {}; + vm.popover = {}; vm.saveEditsText = 'Save Edits'; vm.showSaveEditsBtn = false; diff --git a/www/app/maps/offline-maps/archive-tiles.controller.js b/www/app/maps/offline-maps/archive-tiles.controller.js index d6065958..76d45e31 100644 --- a/www/app/maps/offline-maps/archive-tiles.controller.js +++ b/www/app/maps/offline-maps/archive-tiles.controller.js @@ -4,12 +4,13 @@ .module('app') .controller('ArchiveTilesController', ArchiveTilesController); - ArchiveTilesController.$inject = ['$cordovaFileTransfer', '$http', '$ionicLoading', '$ionicModal', '$ionicPopup', '$log', '$q', '$scope', '$state', '$timeout', - 'LocalStorageFactory', 'MapFactory', 'MapLayerFactory', 'MapViewFactory', 'OfflineTilesFactory', 'SlippyTileNamesFactory']; + ArchiveTilesController.$inject = ['$cordovaFileTransfer', '$http', '$ionicLoading', '$ionicModal', '$ionicPopup', + '$log', '$q', '$scope', '$state', '$timeout', 'LocalStorageFactory', 'MapFactory', 'MapLayerFactory', + 'MapViewFactory', 'OfflineTilesFactory']; - function ArchiveTilesController($cordovaFileTransfer, $http, $ionicLoading, $ionicModal, $ionicPopup, $log, $q, $scope, $state, $timeout, - LocalStorageFactory, MapFactory, MapLayerFactory, MapViewFactory, OfflineTilesFactory, - SlippyTileNamesFactory) { + function ArchiveTilesController($cordovaFileTransfer, $http, $ionicLoading, $ionicModal, $ionicPopup, $log, $q, + $scope, $state, $timeout, LocalStorageFactory, MapFactory, MapLayerFactory, + MapViewFactory, OfflineTilesFactory) { var vm = this; var mapExtent; var mapLayer; @@ -71,7 +72,7 @@ _.extend(vm.map, { 'currentZoom': Math.round(mapExtent.zoom), 'percentDownload': 0, - 'progress': {'message':'Starting Download...'}, + 'progress': {'message': 'Starting Download...'}, 'status': '', 'zipDone': false, 'zipError': '' @@ -92,8 +93,8 @@ var top = mapExtent.topRight.lat; var left = mapExtent.bottomLeft.lng; var bottom = mapExtent.bottomLeft.lat; - extentString = left+','+bottom+','+right+','+top; - percentDone=0; + extentString = left + ',' + bottom + ',' + right + ',' + top; + percentDone = 0; loadSavedMaps(); } @@ -119,19 +120,20 @@ return deferred.promise; } - $scope.checkStatus = function(){ - if(vm.zipUID!='') { + $scope.checkStatus = function () { + if (vm.zipUID != '') { var request = $http({ 'method': 'get', - 'url': vm.tilehost+'/asyncstatus/'+vm.zipUID + 'url': vm.tilehost + '/asyncstatus/' + vm.zipUID }); request.then(function (response) { - if(response.data.error) { + if (response.data.error) { vm.map.zipError = response.data.error; vm.map.progress.message = response.data.error; percentDone = 100; - }else{ - if(vm.map.progress.message != 'Downloading Tiles...') { + } + else { + if (vm.map.progress.message != 'Downloading Tiles...') { vm.map.progress.message = response.data.status; vm.map.percentDownload = response.data.percent; } @@ -146,21 +148,22 @@ vm.tryCount++; - if(vm.tryCount <= 200 && vm.map.progress.message!='Zip File Ready.' && vm.map.zipError==''){ + if (vm.tryCount <= 200 && vm.map.progress.message != 'Zip File Ready.' && vm.map.zipError == '') { $timeout(arguments.callee, 1000); - }else{ + } + else { vm.map.progress.message = 'Downloading Tiles...'; - downloadZip(vm.zipUID,vm.map.mapid).then(function () { + downloadZip(vm.zipUID, vm.map.mapid).then(function () { vm.map.progress.message = 'Installing Tiles in StraboSpot...'; - $timeout(doUnzip(),3000); - },function(error){ + $timeout(doUnzip(), 3000); + }, function (error) { - },function(notify){ + }, function (notify) { vm.map.percentDownload = notify; }); } } - } + }; function continueDownload() { $log.log('continueDownload: ', vm.map); @@ -180,49 +183,50 @@ function downloadZip(uid, mapid) { var deferred = $q.defer(); // init promise - var url = 'http://tiles.strabospot.org/ziptemp/'+uid+'/'+uid+'.zip'; + var url = 'http://tiles.strabospot.org/ziptemp/' + uid + '/' + uid + '.zip'; var devicePath = LocalStorageFactory.getDevicePath(); var zipsDirectory = LocalStorageFactory.getZipsDirectory(); - var fileTransfer= new FileTransfer(); + var fileTransfer = new FileTransfer(); - fileTransfer.onprogress = function(progressEvent) { - var percent = progressEvent.loaded / progressEvent.total * 100; - percent = Math.round(percent); - console.log(percent); - deferred.notify(percent); + fileTransfer.onprogress = function (progressEvent) { + var percent = progressEvent.loaded / progressEvent.total * 100; + percent = Math.round(percent); + console.log(percent); + deferred.notify(percent); }; - LocalStorageFactory.checkZipsDir().then(function(){ - fileTransfer.download(url, devicePath + zipsDirectory + '/' + mapid + '.zip', function(entry){ + LocalStorageFactory.checkZipsDir().then(function () { + fileTransfer.download(url, devicePath + zipsDirectory + '/' + mapid + '.zip', function (entry) { console.log('download complete: ' + entry.toURL()); deferred.resolve(); - }, function(error){ + }, function (error) { alert('zip download failed'); $log.log('zip download error: ', error); deferred.reject(error); }); - }) + }); return deferred.promise; } function doUnzip() { vm.map.progress.message = 'Installing Tiles in StraboSpot...'; - unzipFile(vm.map.mapid).then(function (returnvar){ //not completing? - if(returnvar==-1) { //zip failed, try again + unzipFile(vm.map.mapid).then(function (returnvar) { //not completing? + if (returnvar == -1) { //zip failed, try again unzipAgain(); - }else{ + } + else { vm.map.progress.message = 'Done! '; - LocalStorageFactory.getMapStorageDetails(vm.map.mapid).then(function(existCount){ - $log.log('returnedDetails: ',existCount); + LocalStorageFactory.getMapStorageDetails(vm.map.mapid).then(function (existCount) { + $log.log('returnedDetails: ', existCount); vm.map.existCount = existCount; //clean up page - OfflineTilesFactory.writeMap(vm.map, existCount).then(function(){ + OfflineTilesFactory.writeMap(vm.map, existCount).then(function () { var myPopup = $ionicPopup.alert({ 'title': 'Success!', 'template': 'Map Download Complete!' }); - myPopup.then(function() { + myPopup.then(function () { vm.showSubmitButton = false; vm.downloadingModal.hide(); $log.log('close window here'); @@ -230,19 +234,19 @@ }); }); } - }, function(error){ + }, function (error) { - }, function(notify){ + }, function (notify) { vm.map.percentDownload = notify; }); } function loadSavedMaps() { OfflineTilesFactory.getOfflineMaps().then(function (maps) { - $log.log("offline maps: ",maps); + $log.log("offline maps: ", maps); vm.maps = angular.fromJson(angular.toJson(maps)); - vm.existingName = _.find(vm.maps, function(gotMap){ //check to see if offline map already exists + vm.existingName = _.find(vm.maps, function (gotMap) { //check to see if offline map already exists return gotMap.id === vm.map.id; }); @@ -251,8 +255,8 @@ vm.map.mapid = vm.existingName.mapid; vm.map.existCount = vm.existingName.existCount; } - else{ - vm.map.name = vm.map.title; + else { + vm.map.name = vm.map.title; } vm.showNameField = _.isEmpty(vm.maps); vm.showSelectName = !_.isEmpty(vm.maps); @@ -275,9 +279,10 @@ saveZipMap(mapToSave).then(function () { var statusMsg; - if(!vm.map.zipDone) { + if (!vm.map.zipDone) { statusMsg = 'There was an error downloading the map.'; - }else{ + } + else { statusMsg = 'SUCCESS! Map Saved!'; } deferred.resolve(statusMsg); @@ -295,48 +300,56 @@ var source = mapToSave.source; var id = mapToSave.id; var mapid = mapToSave.mapid; - var startZipURL=''; - if(source=='strabo_spot_mapbox') { - if(id=='mapbox.outdoors'){ - startZipURL=vm.tilehost+'/asynczip?mapid='+mapid+'&layer=mapbox.outdoors&extent='+extentString+'&zoom='+vm.selectedMaxZoom.zoom; - }else if(id=='mapbox.satellite') { - startZipURL=vm.tilehost+'/asynczip?mapid='+mapid+'&layer=mapbox.satellite&extent='+extentString+'&zoom='+vm.selectedMaxZoom.zoom; + var startZipURL = ''; + if (source == 'strabo_spot_mapbox') { + if (id == 'mapbox.outdoors') { + startZipURL = vm.tilehost + '/asynczip?mapid=' + mapid + '&layer=mapbox.outdoors&extent=' + extentString + '&zoom=' + vm.selectedMaxZoom.zoom; } - }else if(source=='osm') { - startZipURL=vm.tilehost+'/asynczip?mapid='+mapid+'&layer=osm&extent='+extentString+'&zoom='+vm.selectedMaxZoom.zoom; - }else if(source=='macrostrat') { - startZipURL=vm.tilehost+'/asynczip?mapid='+mapid+'&layer=macrostrat&extent='+extentString+'&zoom='+vm.selectedMaxZoom.zoom; - }else if(source=='mapbox_styles') { + else if (id == 'mapbox.satellite') { + startZipURL = vm.tilehost + '/asynczip?mapid=' + mapid + '&layer=mapbox.satellite&extent=' + extentString + '&zoom=' + vm.selectedMaxZoom.zoom; + } + } + else if (source == 'osm') { + startZipURL = vm.tilehost + '/asynczip?mapid=' + mapid + '&layer=osm&extent=' + extentString + '&zoom=' + vm.selectedMaxZoom.zoom; + } + else if (source == 'macrostrat') { + startZipURL = vm.tilehost + '/asynczip?mapid=' + mapid + '&layer=macrostrat&extent=' + extentString + '&zoom=' + vm.selectedMaxZoom.zoom; + } + else if (source == 'mapbox_styles') { var key = mapToSave.key; var parts = id.split('/'); var mapusername = parts[0]; var usermapid = parts[1]; - startZipURL=vm.tilehost+'/asynczip?mapid='+mapid+'&layer=mapboxstyles&username='+mapusername+'&access_token='+key+'&id='+usermapid+'&extent='+extentString+'&zoom='+vm.selectedMaxZoom.zoom; - }else if(source=='mapbox_classic') { + startZipURL = vm.tilehost + '/asynczip?mapid=' + mapid + '&layer=mapboxstyles&username=' + mapusername + '&access_token=' + key + '&id=' + usermapid + '&extent=' + extentString + '&zoom=' + vm.selectedMaxZoom.zoom; + } + else if (source == 'mapbox_classic') { var key = mapToSave.key; - startZipURL=vm.tilehost+'/asynczip?mapid='+mapid+'&layer=mapboxclassic&id='+id+'&extent='+extentString+'&zoom='+vm.selectedMaxZoom.zoom+'&access_token='+key; - }else if(source=='strabospot_mymaps') { - startZipURL=vm.tilehost+'/asynczip?mapid='+mapid+'&layer=strabomymaps&id='+id+'&extent='+extentString+'&zoom='+vm.selectedMaxZoom.zoom; - }else if(source=='map_warper') { - startZipURL=vm.tilehost+'/asynczip?mapid='+mapid+'&layer=mapwarper&id='+id+'&extent='+extentString+'&zoom='+vm.selectedMaxZoom.zoom; + startZipURL = vm.tilehost + '/asynczip?mapid=' + mapid + '&layer=mapboxclassic&id=' + id + '&extent=' + extentString + '&zoom=' + vm.selectedMaxZoom.zoom + '&access_token=' + key; + } + else if (source == 'strabospot_mymaps') { + startZipURL = vm.tilehost + '/asynczip?mapid=' + mapid + '&layer=strabomymaps&id=' + id + '&extent=' + extentString + '&zoom=' + vm.selectedMaxZoom.zoom; + } + else if (source == 'map_warper') { + startZipURL = vm.tilehost + '/asynczip?mapid=' + mapid + '&layer=mapwarper&id=' + id + '&extent=' + extentString + '&zoom=' + vm.selectedMaxZoom.zoom; } - if(startZipURL!=''){ + if (startZipURL != '') { var request = $http({ 'method': 'get', 'url': startZipURL }); request.then(function (response) { vm.zipUID = response.data.id; - if(vm.zipUID!='') { + if (vm.zipUID != '') { vm.map.progress.message = 'Starting Download...'; vm.map.percentDownload = 0; vm.map.zipError = ''; - vm.tryCount=0; + vm.tryCount = 0; $scope.checkStatus(); - }else{ - vm.map.progress.message='Download Failed!'; - vm.map.percentDownload=100; + } + else { + vm.map.progress.message = 'Download Failed!'; + vm.map.percentDownload = 100; $ionicPopup.alert({ 'title': 'Download Failed!', 'template': 'Error getting ZIP id.' @@ -346,12 +359,13 @@ //request broken message deferred.reject(response); }); - }else{ - vm.map.progress.message='Download Failed!'; - vm.map.percentDownload=100; + } + else { + vm.map.progress.message = 'Download Failed!'; + vm.map.percentDownload = 100; $ionicPopup.alert({ 'title': 'Download Failed!', - 'template': 'Invalid ID ('+id+').' + 'template': 'Invalid ID (' + id + ').' }); } @@ -362,21 +376,22 @@ } function unzipAgain() { - unzipFile(vm.map.mapid).then(function (returnvar){ //not completing? - if(returnvar==-1) { //zip failed, try again + unzipFile(vm.map.mapid).then(function (returnvar) { //not completing? + if (returnvar == -1) { //zip failed, try again unzipAgain(); - }else{ + } + else { vm.map.progress.message = 'Done! '; - LocalStorageFactory.getMapStorageDetails(vm.map.mapid).then(function(existCount){ - $log.log('returnedDetails: ',existCount); + LocalStorageFactory.getMapStorageDetails(vm.map.mapid).then(function (existCount) { + $log.log('returnedDetails: ', existCount); vm.map.existCount = existCount; //clean up page - OfflineTilesFactory.writeMap(vm.map, existCount).then(function(){ + OfflineTilesFactory.writeMap(vm.map, existCount).then(function () { var myPopup = $ionicPopup.alert({ 'title': 'Success!', 'template': 'Map Download Complete!' }); - myPopup.then(function() { + myPopup.then(function () { vm.showSubmitButton = false; vm.downloadingModal.hide(); $log.log('close window here'); @@ -384,9 +399,9 @@ }); }); } - }, function(error){ + }, function (error) { - },function(notify){ + }, function (notify) { vm.map.percentDownload = notify; }); } @@ -397,15 +412,16 @@ var devicePath = LocalStorageFactory.getDevicePath(); var zipsDirectory = LocalStorageFactory.getZipsDirectory(); var tileCacheDirectory = LocalStorageFactory.getTileCacheDirectory(); - $log.log(devicePath+'/'+zipsDirectory+'/'+mapid+'.zip to '+devicePath+'/'+zipsDirectory+'/'); + $log.log(devicePath + '/' + zipsDirectory + '/' + mapid + '.zip to ' + devicePath + '/' + zipsDirectory + '/'); LocalStorageFactory.checkDir(tileCacheDirectory).then(function () { - zip.unzip(devicePath+'/'+zipsDirectory+'/'+mapid+'.zip', devicePath+'/'+tileCacheDirectory+'/', function(returnvar){ - deferred.resolve(returnvar); - },function(progressEvent){ - var percentUnzipped = Math.round((progressEvent.loaded / progressEvent.total) * 100); - $log.log(percentUnzipped); - deferred.notify(percentUnzipped);; - }); + zip.unzip(devicePath + '/' + zipsDirectory + '/' + mapid + '.zip', devicePath + '/' + tileCacheDirectory + '/', + function (returnvar) { + deferred.resolve(returnvar); + }, function (progressEvent) { + var percentUnzipped = Math.round((progressEvent.loaded / progressEvent.total) * 100); + $log.log(percentUnzipped); + deferred.notify(percentUnzipped); + }); }); return deferred.promise; } @@ -448,14 +464,14 @@ function serverCountTiles() { var deferred = $q.defer(); - var counturl = vm.tilehost+'/zipcount?extent='+extentString+'&zoom='+vm.selectedMaxZoom.zoom; + var counturl = vm.tilehost + '/zipcount?extent=' + extentString + '&zoom=' + vm.selectedMaxZoom.zoom; var request = $http({ 'method': 'get', 'url': counturl }); request.then(function (response) { vm.map.tileCount = response.data.count; - vm.submitBtnText='Download '+response.data.count+' Tiles'; + vm.submitBtnText = 'Download ' + response.data.count + ' Tiles'; deferred.resolve(); }, function (response) { deferred.reject(response); @@ -471,7 +487,8 @@ 'template': 'Please give the map a name.' }); return; - }else{ + } + else { continueDownload(); } } diff --git a/www/app/maps/offline-maps/offline-map.controller.js b/www/app/maps/offline-maps/offline-map.controller.js index 74fddcf5..b1339d73 100644 --- a/www/app/maps/offline-maps/offline-map.controller.js +++ b/www/app/maps/offline-maps/offline-map.controller.js @@ -136,10 +136,10 @@ function goToMap(map) { $ionicLoading.show({ 'template': '' - }).then(function(){ + }).then(function () { OfflineTilesFactory.getMapCenterTile(map.mapid).then(function (centerTile) { $log.log('gotcenterTile: ', centerTile); - if(centerTile) { + if (centerTile) { var parts = centerTile.split('_'); var z = Number(parts[0]); var x = Number(parts[1]); @@ -150,13 +150,13 @@ MapViewFactory.zoomToPoint([lng, lat], z); $location.path('/app/map'); } - },function(err){ //map not found - $log.log('Found Error: ',err); + }, function (err) { //map not found + $log.log('Found Error: ', err); $ionicLoading.hide(); $ionicPopup.alert({ 'title': 'Error!', - 'template': 'Offline map not found on device.
(code: '+err+')' - }).then(function(){ + 'template': 'Offline map not found on device.
(code: ' + err + ')' + }).then(function () { $ionicLoading.hide(); }); }); diff --git a/www/app/maps/offline-maps/offline-tile.factory.js b/www/app/maps/offline-maps/offline-tile.factory.js index aedb23c0..e70a6cfa 100644 --- a/www/app/maps/offline-maps/offline-tile.factory.js +++ b/www/app/maps/offline-maps/offline-tile.factory.js @@ -5,10 +5,12 @@ .module('app') .factory('OfflineTilesFactory', OfflineTilesFactory); - OfflineTilesFactory.$inject = ['$cordovaFileTransfer', '$http', '$ionicLoading', '$ionicPopup', '$log', '$q', '$timeout', 'LocalStorageFactory']; + OfflineTilesFactory.$inject = ['$cordovaFileTransfer', '$http', '$ionicLoading', '$ionicPopup', '$log', '$q', + '$timeout', 'LocalStorageFactory']; // used to determine what the map provider is before we archive a tileset - function OfflineTilesFactory($cordovaFileTransfer, $http, $ionicLoading, $ionicPopup, $log, $q, $timeout, LocalStorageFactory) { + function OfflineTilesFactory($cordovaFileTransfer, $http, $ionicLoading, $ionicPopup, $log, $q, $timeout, + LocalStorageFactory) { var downloadErrors = 0; var offlineMaps = []; @@ -69,7 +71,7 @@ $ionicPopup.alert({ 'title': 'Append Error!', 'template': 'Cannot append the selected new tiles to the saved map ' + map.name + ' since the map' + - ' tile provider is not the same. A new map name must be given if you wish to use a different tile provider.' + ' tile provider is not the same. A new map name must be given if you wish to use a different tile provider.' }); deferred.reject(); } @@ -91,13 +93,13 @@ // deletes all offline tiles var deferred = $q.defer(); offlineMaps = []; - LocalStorageFactory.clearFiles(maps).then(function(){ //clear tile zips and caches + LocalStorageFactory.clearFiles(maps).then(function () { //clear tile zips and caches // then delete all map names LocalStorageFactory.getDb().mapNamesDb.clear(function (err) { if (err) deferred.reject(err); - else deferred.resolve(); + else deferred.resolve(); }); - },function(error){ + }, function (error) { deferred.resolve(error); }); return deferred.promise; @@ -105,7 +107,7 @@ function deleteMap(mapToDelete) { var deferred = $q.defer(); - LocalStorageFactory.deleteMapFiles(mapToDelete).then(function() { + LocalStorageFactory.deleteMapFiles(mapToDelete).then(function () { LocalStorageFactory.getDb().mapNamesDb.removeItem(mapToDelete.name).then(function () { // Map is deleted, and this is now fully resolved offlineMaps = _.reject(offlineMaps, function (offlineMap) { @@ -113,7 +115,7 @@ }); deferred.resolve(); }); - },function(){ + }, function () { $log.log('LocalStorageFactory.deleteMapFiles failed to resolve.'); deferred.resolve(); }); @@ -144,7 +146,7 @@ var deferred = $q.defer(); var totalcount = 0; LocalStorageFactory.getDb().mapNamesDb.iterate(function (value, key) { - if(value.existCount) { + if (value.existCount) { totalcount = totalcount + value.existCount; @@ -157,7 +159,7 @@ // Read from storage function read(mapProvider, tile, callback) { - tile=tile.replace(/\//g,'_'); + tile = tile.replace(/\//g, '_'); var tileId = tile + '.png'; LocalStorageFactory.getTile(mapProvider, tileId).then(function (blob) { callback(blob); diff --git a/www/app/maps/offline-maps/slippy-tile-names.factory.js b/www/app/maps/offline-maps/slippy-tile-names.factory.js index 095e921a..05f61c85 100644 --- a/www/app/maps/offline-maps/slippy-tile-names.factory.js +++ b/www/app/maps/offline-maps/slippy-tile-names.factory.js @@ -21,7 +21,7 @@ function lat2tile(lat, zoom) { return (Math.floor( (1 - Math.log(Math.tan(lat * Math.PI / 180) + 1 / Math.cos(lat * Math.PI / 180)) / Math.PI) / 2 * Math.pow(2, - zoom))); + zoom))); } // borrowed from http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames diff --git a/www/app/project/manage/manage-project.controller.js b/www/app/project/manage/manage-project.controller.js index 7dd392be..dc582e94 100644 --- a/www/app/project/manage/manage-project.controller.js +++ b/www/app/project/manage/manage-project.controller.js @@ -11,7 +11,7 @@ function ManageProjectController($document, $ionicModal, $ionicLoading, $ionicPopover, $ionicPopup, $log, $scope, $state, $q, $window, FormFactory, ImageFactory, LiveDBFactory, LocalStorageFactory, - OtherMapsFactory, ProjectFactory, RemoteServerFactory,SpotFactory, UserFactory, + OtherMapsFactory, ProjectFactory, RemoteServerFactory, SpotFactory, UserFactory, IS_WEB) { var vm = this; @@ -223,17 +223,17 @@ outputMessage('NEW Images Downloaded: ' + imagesDownloadedCount + ' of ' + neededImagesIds.length + '
NEW Images Saved: ' + savedImagesCount + ' of ' + neededImagesIds.length); //return readDataUrl(response.data).then(function (base64Image) { - return ImageFactory.saveImage(response.data, neededImageId).then(function () { + return ImageFactory.saveImage(response.data, neededImageId).then(function () { //return ImageFactory.saveImage(base64Image, neededImageId).then(function () { - savedImagesCount++; - notifyMessages.pop(); - outputMessage( - 'NEW Images Downloaded: ' + imagesDownloadedCount + ' of ' + neededImagesIds.length + - '
NEW Images Saved: ' + savedImagesCount + ' of ' + neededImagesIds.length); - }, function () { - $log.error('Unable to save image locally', neededImageId); - imagesFailedCount++; - }); + savedImagesCount++; + notifyMessages.pop(); + outputMessage( + 'NEW Images Downloaded: ' + imagesDownloadedCount + ' of ' + neededImagesIds.length + + '
NEW Images Saved: ' + savedImagesCount + ' of ' + neededImagesIds.length); + }, function () { + $log.error('Unable to save image locally', neededImageId); + imagesFailedCount++; + }); //}); } else { @@ -464,7 +464,7 @@ }).finally(function () { $ionicLoading.show({ scope: $scope, template: notifyMessages.join('
') + '

' + - 'OK' + 'OK' }); }); }, function () { @@ -609,11 +609,11 @@ $log.log('Finished updating dataset', dataset, '. Response:', response); return RemoteServerFactory.addDatasetToProject(project.id, dataset.id, UserFactory.getUser().encoded_login) .then(function (response2) { - $log.log('Finished adding dataset to project', project, '. Response:', response2); - return uploadSpots(dataset).then(function () { - deferred.resolve(); - }); - }, + $log.log('Finished adding dataset to project', project, '. Response:', response2); + return uploadSpots(dataset).then(function () { + deferred.resolve(); + }); + }, function (err) { uploadErrors = true; $log.log('Error adding dataset to project. Response:', err); @@ -761,7 +761,7 @@ outputMessage('Error updating Spots in dataset' + dataset.name); if (err && err.data && err.data.Error) $log.error(err.data.Error); if (err && err.statusText) outputMessage('Server Error: ' + err.statusText); - return $q.when(null); + return $q.when(null); }); } } @@ -788,7 +788,7 @@ var confirmPopup = $ionicPopup.confirm({ 'title': 'Delete Dataset Warning!', 'template': 'Are you sure you want to DELETE the Dataset' + - ' ' + dataset.name + '? This will also delete the Spots in this dataset.', + ' ' + dataset.name + '? This will also delete the Spots in this dataset.', 'cssClass': 'warning-popup' }); confirmPopup.then(function (res) { @@ -808,7 +808,7 @@ var confirmPopup = $ionicPopup.confirm({ 'title': 'Delete Project Warning!', 'template': 'Are you sure you want to DELETE the project' + - ' ' + project.name + '. This will also delete all datasets and Spots contained within the project.', + ' ' + project.name + '. This will also delete all datasets and Spots contained within the project.', 'cssClass': 'warning-popup' }); confirmPopup.then(function (res) { @@ -859,14 +859,14 @@ $ionicPopup.alert({ 'title': 'Type in Use', 'template': 'This type is used in the following Spot. Please remove the type from this Spot before' + - ' deleting this type. Spot: ' + spotNames.join(', ') + ' deleting this type. Spot: ' + spotNames.join(', ') }); } else if (usedType.length > 1) { $ionicPopup.alert({ 'title': 'Type in Use', 'template': 'This type is used in the following Spots. Please remove the type from these Spots before' + - ' deleting this type. Spots: ' + spotNames.join(', ') + ' deleting this type. Spots: ' + spotNames.join(', ') }); } else { @@ -917,11 +917,11 @@ } }*/ - function exportProject() { - vm.popover.hide().then(function () { - exportData(); - }); - } + function exportProject() { + vm.popover.hide().then(function () { + exportData(); + }); + } function oldexportProject() { vm.popover.hide().then(function () { @@ -994,7 +994,6 @@ } - function oldimportProject() { vm.popover.hide().then(function () { vm.importItem = undefined; @@ -1093,7 +1092,7 @@ }).finally(function () { $ionicLoading.show({ scope: $scope, template: notifyMessages.join('
') + '

' + - 'OK' + 'OK' }); }); } @@ -1138,7 +1137,7 @@ }).finally(function () { $ionicLoading.show({ scope: $scope, template: notifyMessages.join('
') + '

' + - 'OK' + 'OK' }); }); } @@ -1207,9 +1206,9 @@ var confirmPopup = $ionicPopup.confirm({ 'title': 'Delete Local Project Warning!', 'template': 'Switching projects will DELETE the local copy of the' + - ' current project ' + vm.project.description.project_name + ' including all datasets and Spots' + - ' contained within this project. Make sure you have already uploaded the project to the server if you' + - ' wish to preserve the data. Continue?', + ' current project ' + vm.project.description.project_name + ' including all datasets and Spots' + + ' contained within this project. Make sure you have already uploaded the project to the server if you' + + ' wish to preserve the data. Continue?', 'cssClass': 'warning-popup' }); confirmPopup.then(function (res) { @@ -1299,11 +1298,11 @@ else { vm.activeDatasets.push(datasetToggled); if (_.isEmpty(ProjectFactory.getSpotIds()[datasetToggled.id]) && - !_.isEmpty(UserFactory.getUser()) && navigator.onLine) { + !_.isEmpty(UserFactory.getUser()) && navigator.onLine) { initializeDownloadDataset(datasetToggled); } else if (_.isEmpty(ProjectFactory.getSpotIds()[datasetToggled.id]) && - !_.isEmpty(UserFactory.getUser()) && !navigator.onLine) { + !_.isEmpty(UserFactory.getUser()) && !navigator.onLine) { $ionicPopup.alert({ 'title': 'Cannot Update Dataset!', 'template': 'Unable to reach the server to check if there are already Spots in this dataset to download.' diff --git a/www/app/shared/localstorage.factory.js b/www/app/shared/localstorage.factory.js index 7e551dc9..a12e8170 100644 --- a/www/app/shared/localstorage.factory.js +++ b/www/app/shared/localstorage.factory.js @@ -82,7 +82,7 @@ function exportData(directory, data, fileName) { return checkDir(appDirectory).then(function () { return checkDir(directory).then(function (fullPath) { - $log.log('fullPath',fullPath); + $log.log('fullPath', fullPath); return writeFile(fullPath, data, fileName); }); }); @@ -143,9 +143,11 @@ function getMedian(arr) { arr = arr.slice(0); // create copy var middle = (arr.length + 1) / 2, - sorted = arr.sort( function(a,b) {return a - b;} ); + sorted = arr.sort(function (a, b) { + return a - b; + }); return (sorted.length % 2) ? sorted[middle - 1] : (sorted[middle - 1.5] + sorted[middle - 0.5]) / 2; - }; + } function importData(directory, name) { var deferred = $q.defer(); // init promise @@ -254,52 +256,53 @@ * Public Functions */ - function clearFiles(maps) { //clears all offline map files - var deferred = $q.defer(); // init promise + function clearFiles(maps) { //clears all offline map files + var deferred = $q.defer(); // init promise - var devicePath = getDevicePath(); + var devicePath = getDevicePath(); - $cordovaFile.removeRecursively(devicePath, zipsDirectory).then(function (success) { - $cordovaFile.removeRecursively(devicePath, tileCacheDirectory).then(function (success) { - deferred.resolve("Success!"); - },function(failure){ - $log.log('delete folder: ' + tileCacheDirectory + ' failed'); - $log.log('failure: ', failure); - //deferred.reject(); - deferred.resolve(); - }); - },function(failure){ - $log.log('delete folder: ' + zipsDirectory + ' failed'); - $log.log('failure: ', failure); - //deferred.reject(); - deferred.resolve(); - }); + $cordovaFile.removeRecursively(devicePath, zipsDirectory).then(function (success) { + $cordovaFile.removeRecursively(devicePath, tileCacheDirectory).then(function (success) { + deferred.resolve("Success!"); + }, function (failure) { + $log.log('delete folder: ' + tileCacheDirectory + ' failed'); + $log.log('failure: ', failure); + //deferred.reject(); + deferred.resolve(); + }); + }, function (failure) { + $log.log('delete folder: ' + zipsDirectory + ' failed'); + $log.log('failure: ', failure); + //deferred.reject(); + deferred.resolve(); + }); - return deferred.promise; + return deferred.promise; } function deleteMapFiles(map) { var deferred = $q.defer(); // init promise var mapid = String(map.mapid); - if(mapid!='') { + if (mapid != '') { var devicePath = getDevicePath(); $log.log('deleteMapFiles mapid: ' + mapid); $cordovaFile.removeFile(devicePath + zipsDirectory, mapid + '.zip').then(function (success) { $cordovaFile.removeRecursively(devicePath + tileCacheDirectory, mapid).then(function (success) { deferred.resolve("Success!"); - },function(failure){ + }, function (failure) { $log.log('delete folder: ' + tileCacheDirectory + ' ' + mapid + ' failed'); $log.log('failure: ', failure); //deferred.reject(); deferred.resolve(); }); - },function(failure){ + }, function (failure) { $log.log('delete file: ' + zipsDirectory + ' ' + mapid + '.zip failed'); $log.log('failure: ', failure); //deferred.reject(); deferred.resolve(); }); - }else{ + } + else { $log.log('Map ID doesnt exist!'); //deferred.reject(); deferred.resolve(); @@ -423,38 +426,38 @@ var xvals = []; var yvals = []; - for(var i = 0; i < entries.length; i++) { + for (var i = 0; i < entries.length; i++) { var entry = entries[i]; var tileName = entry.name; - var tileName = tileName.replace('.png',''); + var tileName = tileName.replace('.png', ''); var parts = tileName.split('_'); var z = Number(parts[0]); var x = Number(parts[1]); var y = Number(parts[2]); - if(z > maxZoom){ + if (z > maxZoom) { maxZoom = z; } } - if(maxZoom > 14) { + if (maxZoom > 14) { maxZoom = 14; } - for(var i = 0; i < entries.length; i++) { + for (var i = 0; i < entries.length; i++) { var entry = entries[i]; var tileName = entry.name; - var tileName = tileName.replace('.png',''); + var tileName = tileName.replace('.png', ''); var parts = tileName.split('_'); var z = Number(parts[0]); var x = Number(parts[1]); var y = Number(parts[2]); - if(z == maxZoom) { - if(xvals.indexOf(x) == -1) { + if (z == maxZoom) { + if (xvals.indexOf(x) == -1) { xvals.push(x); } - if(yvals.indexOf(y) == -1) { + if (yvals.indexOf(y) == -1) { yvals.push(y); } } @@ -518,38 +521,40 @@ var deferred = $q.defer(); // init promise var devicePath = getDevicePath(); $cordovaFile.checkDir(devicePath, tileCacheDirectory).then(function (foundDir) { - $cordovaFile.checkDir(devicePath, tileCacheDirectory+'/'+mapid).then(function (foundDir) { - $cordovaFile.checkDir(devicePath, tileCacheDirectory+'/'+mapid+'/tiles').then(function (foundDir) { - - $cordovaFile.checkFile(devicePath + '/' + tileCacheDirectory + '/' + mapid + '/tiles/', tileId).then(function (foundFile) { - - $cordovaFile.readAsArrayBuffer(devicePath + '/' + tileCacheDirectory + '/' + mapid + '/tiles/', tileId).then(function (success) { - // success - $log.log('tile '+tileId+'found!'); - var blob = new Blob([success], {type: "image/png"}); - - deferred.resolve(blob); - },function(){ + $cordovaFile.checkDir(devicePath, tileCacheDirectory + '/' + mapid).then(function (foundDir) { + $cordovaFile.checkDir(devicePath, tileCacheDirectory + '/' + mapid + '/tiles').then(function (foundDir) { + + $cordovaFile.checkFile(devicePath + '/' + tileCacheDirectory + '/' + mapid + '/tiles/', tileId).then( + function (foundFile) { + + $cordovaFile.readAsArrayBuffer(devicePath + '/' + tileCacheDirectory + '/' + mapid + '/tiles/', + tileId).then(function (success) { + // success + $log.log('tile ' + tileId + 'found!'); + var blob = new Blob([success], {type: "image/png"}); + + deferred.resolve(blob); + }, function () { + //Failed + $log.log('Error getTile : could not read file'); + deferred.resolve(null); + }); + }, function () { //Failed - $log.log('Error getTile : could not read file'); + $log.log('Error getTile : check file failed ' + tileId); deferred.resolve(null); }); - },function(){ - //Failed - $log.log('Error getTile : check file failed ' + tileId); - deferred.resolve(null); - }); - },function(){ + }, function () { //Failed $log.log('Error getTile : check tiles directory failed'); deferred.resolve(null); }); - },function(){ + }, function () { //Failed - $log.log('Error getTile : check mapid: '+mapid+' failed'); + $log.log('Error getTile : check mapid: ' + mapid + ' failed'); deferred.resolve(null); }); - },function(){ + }, function () { //Failed $log.log('Error getTile : check tilecache directory failed.'); deferred.resolve(null); @@ -557,30 +562,32 @@ return deferred.promise; } - function getZipDetails(mapid){ + function getZipDetails(mapid) { var deferred = $q.defer(); // init promise var devicePath = getDevicePath(); if (devicePath) { - $cordovaFile.checkDir(devicePath, tileCacheDirectory+'/'+mapid+'/'+tiles).then(function (foundDir) { - $cordovaFile.checkFile(devicePath + '/' + tileCacheDirectory + '/' + mapid + '/', 'details.json').then(function (foundFile) { - $cordovaFile.readAsText(devicePath + '/' + tileCacheDirectory + '/' + mapid + '/', 'details.json').then(function (data) { - deferred.resolve(angular.fromJson(data)); - }, function (noData) { - $log.log('Error reading data', noData); - deferred.reject('Error reading data', noData); - }) + $cordovaFile.checkDir(devicePath, tileCacheDirectory + '/' + mapid + '/' + tiles).then(function (foundDir) { + $cordovaFile.checkFile(devicePath + '/' + tileCacheDirectory + '/' + mapid + '/', 'details.json').then( + function (foundFile) { + $cordovaFile.readAsText(devicePath + '/' + tileCacheDirectory + '/' + mapid + '/', 'details.json').then( + function (data) { + deferred.resolve(angular.fromJson(data)); + }, function (noData) { + $log.log('Error reading data', noData); + deferred.reject('Error reading data', noData); + }) }, - function (notFoundFile) { - $log.log('File not found', notFoundFile); - deferred.reject('File not found', notFoundFile); - } - ) - }, - function (notFoundDir) { - $log.log('Directory not found', notFoundDir); - deferred.reject('Directory not found', notFoundDir); - }); + function (notFoundFile) { + $log.log('File not found', notFoundFile); + deferred.reject('File not found', notFoundFile); + } + ) + }, + function (notFoundDir) { + $log.log('Directory not found', notFoundDir); + deferred.reject('Directory not found', notFoundDir); + }); } else deferred.reject('Device not found');