save my route - GeoSmartCity-CIP/gsc-client GitHub Wiki

Saving user generated routes

This module enables a user to save a route returned by the routing service to the users profile. It relies on a running instance of the GSC data catalogue for persistent data storage. The route is serialized to a GeoJSON string and is stored linked to a registerred user account on a remote server.

API

The API is available at GitHub in the file src/routing/routing.js.

Dependencies

The save route functionality relies on jQuery, Bootstrap and a running instance of the GSC Datacatalogue for persistent storage.

Examples

Save a route

gsc.user.login() // All requests must take place inside a valid user session
     .then(function(success)) {
         var r = new gsc.routing.Route();
         gsc.routing.addRoute(r)
             .then(function(routeResponse) {
                 var addedRoute = routeResponse.data;
                 // Do something with the saved route
             }, function(err) {
                 // Could not save the route
                 console.debug('Could not save route: ' + err);
             });
     }, function(err) {
         // Could not login user
         console.debug('Could not authenticate user: ' + err);
     );

Retrieve a list of routes

gsc.routing,getRouteList() // Load the existing routes
     .then(function(routeList) {
     
         // Pick a route to remove, must check if list has elements...
         var routeToRemove = routeList[0];
         
         gsc.routing.removeRoute(routeToRemove)
             .then(function(removeRouteResponse) {
                 var removedRoute = removeRouteResponse.data;
                 // Do something with the removed route
             }, function(err) {
                 // Handle error
                 console.debug('An error occurred while removing route: ' + err);
             });
     }, function(err) {
         // Handle error
         console.debug('User authentication failed: ' + err);
     });

Remove a saved route

gsc.routing,getRouteList() // Load the existing routes
     .then(function(routeList) {
     
         // Pick a route to remove, must check if list has elements...
         var routeToRemove = routeList[0];
         
         gsc.routing.removeRoute(routeToRemove)
             .then(function(removeRouteResponse) {
                 var removedRoute = removeRouteResponse.data;
                 // Do something with the removed route
             }, function(err) {
                 // Handle error
                 console.debug('An error occurred while removing route: ' + err);
             });
     }, function(err) {
         // Handle error
         console.debug('User authentication failed: ' + err);
     });