Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _attachments/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<script src="//cdn.jsdelivr.net/velocity/1.2.1/velocity.min.js"></script>
<script src="//cdn.jsdelivr.net/velocity/1.2.1/velocity.ui.min.js"></script>
<script src="script/pouchdb.min.js"></script>
<script src="//cdn.jsdelivr.net/pouchdb/4.0.2/pouchdb.min.js"></script>
<script src="script/app.js"></script>


Expand Down
65 changes: 44 additions & 21 deletions _attachments/script/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ angular.module('locationTrackingApp', ['ngAnimate', 'ngRoute'])

.value("map", {})
.value("watchID", null)
.value("remotedb", 'https://USERNAME:PASSWORD@USERNAME.cloudant.com/locationtracker')
.value("remotedb", 'https://rajsingh:genjisan@rajsingh.cloudant.com/locationtracker')
.value("num", 0)
.value("successMessage", {})
.value("errorMessage", "error")
Expand Down Expand Up @@ -279,23 +279,8 @@ angular.module('locationTrackingApp', ['ngAnimate', 'ngRoute'])

/* triggered from velocity callback within the animation module `enter` hook */
$scope.transEnter = function() {
var db = pouchResult;
var _len;

// get the length of docs and store it in _len
db.info(function(err, info) {
_len = info.doc_count;
});

// use alldocs to get the object rows, then run a loop to draw on the map.
db.allDocs({
include_docs: true,
endkey: "_"
}, function(err, response) {
for (var i = 0; i < _len - 1; i++) {
updateMovingLayer(response.rows[i].doc);
};
})
var db = pouchResult.$$state.value.docs;
var _len = db.length;

/* instantiate Leaflet map */
mapResult = new L.Map('mapResult');
Expand Down Expand Up @@ -356,9 +341,17 @@ angular.module('locationTrackingApp', ['ngAnimate', 'ngRoute'])
}).addTo(mapResult);

function updateMovingLayer(doc) {
// console.log(doc.properties.timestamp);
// console.log(doc.geometry.coordinates);
movementLayer.addData(doc);
mapResult.fitBounds(movementLayer.getBounds());
}

/* Run loop to take docs and begin drawing map points*/
for (var i = 0; i < _len - 1; i++) {
updateMovingLayer(db[i]);
};

};

/* triggered from velocity callback within the animation module `enter` hook */
Expand All @@ -377,12 +370,42 @@ angular.module('locationTrackingApp', ['ngAnimate', 'ngRoute'])


/* cloudant db storage for result map */
.factory('pouchResult', ["remotedb", function(remotedb) {
var db = new PouchDB(remotedb);
return db;
// .factory('pouchResult', ["remotedb", function(remotedb) {
// var db = new PouchDB(remotedb);
// return db;
// }])
/* cloudant db storage for result map */
.factory('pouchResult', ['remotedb', '$http', function(remotedb, $http) {

function handleSuccess( response ) {
console.log(response.data);
return( response.data );
};

function handleError( response ) {
console.log("err: "+JSON.stringify(response.data));
return( response.data );
};

var request = $http({
method: "post",
url: remotedb +'/_find',

data: {
"selector": {"properties.timestamp": {"$gt":1}},
"sort": [{"properties.timestamp": "asc"}],
// "limit": 400,
"skip": 0
}
}
);

return (request.then( handleSuccess, handleError));
}])




/* Directive used on controller items to allow for multiple trans in/out */
.directive('animationdirective', ['$animate', '$timeout',
function($animate, $timeout) {
Expand Down