Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:58:27

0001 var travelMode, unitSystem;
0002 
0003 GMaps.prototype.getRoutes = function(options) {
0004   switch (options.travelMode) {
0005     case 'bicycling':
0006       travelMode = google.maps.TravelMode.BICYCLING;
0007       break;
0008     case 'transit':
0009       travelMode = google.maps.TravelMode.TRANSIT;
0010       break;
0011     case 'driving':
0012       travelMode = google.maps.TravelMode.DRIVING;
0013       break;
0014     default:
0015       travelMode = google.maps.TravelMode.WALKING;
0016       break;
0017   }
0018 
0019   if (options.unitSystem === 'imperial') {
0020     unitSystem = google.maps.UnitSystem.IMPERIAL;
0021   }
0022   else {
0023     unitSystem = google.maps.UnitSystem.METRIC;
0024   }
0025 
0026   var base_options = {
0027         avoidHighways: false,
0028         avoidTolls: false,
0029         optimizeWaypoints: false,
0030         waypoints: []
0031       },
0032       request_options =  extend_object(base_options, options);
0033 
0034   request_options.origin = /string/.test(typeof options.origin) ? options.origin : new google.maps.LatLng(options.origin[0], options.origin[1]);
0035   request_options.destination = /string/.test(typeof options.destination) ? options.destination : new google.maps.LatLng(options.destination[0], options.destination[1]);
0036   request_options.travelMode = travelMode;
0037   request_options.unitSystem = unitSystem;
0038 
0039   delete request_options.callback;
0040   delete request_options.error;
0041 
0042   var self = this,
0043       service = new google.maps.DirectionsService();
0044 
0045   service.route(request_options, function(result, status) {
0046     if (status === google.maps.DirectionsStatus.OK) {
0047       for (var r in result.routes) {
0048         if (result.routes.hasOwnProperty(r)) {
0049           self.routes.push(result.routes[r]);
0050         }
0051       }
0052 
0053       if (options.callback) {
0054         options.callback(self.routes);
0055       }
0056     }
0057     else {
0058       if (options.error) {
0059         options.error(result, status);
0060       }
0061     }
0062   });
0063 };
0064 
0065 GMaps.prototype.removeRoutes = function() {
0066   this.routes = [];
0067 };
0068 
0069 GMaps.prototype.getElevations = function(options) {
0070   options = extend_object({
0071     locations: [],
0072     path : false,
0073     samples : 256
0074   }, options);
0075 
0076   if (options.locations.length > 0) {
0077     if (options.locations[0].length > 0) {
0078       options.locations = array_flat(array_map([options.locations], arrayToLatLng,  false));
0079     }
0080   }
0081 
0082   var callback = options.callback;
0083   delete options.callback;
0084 
0085   var service = new google.maps.ElevationService();
0086 
0087   //location request

0088   if (!options.path) {
0089     delete options.path;
0090     delete options.samples;
0091 
0092     service.getElevationForLocations(options, function(result, status) {
0093       if (callback && typeof(callback) === "function") {
0094         callback(result, status);
0095       }
0096     });
0097   //path request

0098   } else {
0099     var pathRequest = {
0100       path : options.locations,
0101       samples : options.samples
0102     };
0103 
0104     service.getElevationAlongPath(pathRequest, function(result, status) {
0105      if (callback && typeof(callback) === "function") {
0106         callback(result, status);
0107       }
0108     });
0109   }
0110 };
0111 
0112 GMaps.prototype.cleanRoute = GMaps.prototype.removePolylines;
0113 
0114 GMaps.prototype.drawRoute = function(options) {
0115   var self = this;
0116 
0117   this.getRoutes({
0118     origin: options.origin,
0119     destination: options.destination,
0120     travelMode: options.travelMode,
0121     waypoints: options.waypoints,
0122     unitSystem: options.unitSystem,
0123     error: options.error,
0124     callback: function(e) {
0125       if (e.length > 0) {
0126         var polyline_options = {
0127           path: e[e.length - 1].overview_path,
0128           strokeColor: options.strokeColor,
0129           strokeOpacity: options.strokeOpacity,
0130           strokeWeight: options.strokeWeight
0131         };
0132 
0133         if (options.hasOwnProperty("icons")) {
0134           polyline_options.icons = options.icons;
0135         }
0136 
0137         self.drawPolyline(polyline_options);
0138         
0139         if (options.callback) {
0140           options.callback(e[e.length - 1]);
0141         }
0142       }
0143     }
0144   });
0145 };
0146 
0147 GMaps.prototype.travelRoute = function(options) {
0148   if (options.origin && options.destination) {
0149     this.getRoutes({
0150       origin: options.origin,
0151       destination: options.destination,
0152       travelMode: options.travelMode,
0153       waypoints : options.waypoints,
0154       unitSystem: options.unitSystem,
0155       error: options.error,
0156       callback: function(e) {
0157         //start callback

0158         if (e.length > 0 && options.start) {
0159           options.start(e[e.length - 1]);
0160         }
0161 
0162         //step callback

0163         if (e.length > 0 && options.step) {
0164           var route = e[e.length - 1];
0165           if (route.legs.length > 0) {
0166             var steps = route.legs[0].steps;
0167             for (var i = 0, step; step = steps[i]; i++) {
0168               step.step_number = i;
0169               options.step(step, (route.legs[0].steps.length - 1));
0170             }
0171           }
0172         }
0173 
0174         //end callback

0175         if (e.length > 0 && options.end) {
0176            options.end(e[e.length - 1]);
0177         }
0178       }
0179     });
0180   }
0181   else if (options.route) {
0182     if (options.route.legs.length > 0) {
0183       var steps = options.route.legs[0].steps;
0184       for (var i = 0, step; step = steps[i]; i++) {
0185         step.step_number = i;
0186         options.step(step);
0187       }
0188     }
0189   }
0190 };
0191 
0192 GMaps.prototype.drawSteppedRoute = function(options) {
0193   var self = this;
0194   
0195   if (options.origin && options.destination) {
0196     this.getRoutes({
0197       origin: options.origin,
0198       destination: options.destination,
0199       travelMode: options.travelMode,
0200       waypoints : options.waypoints,
0201       error: options.error,
0202       callback: function(e) {
0203         //start callback

0204         if (e.length > 0 && options.start) {
0205           options.start(e[e.length - 1]);
0206         }
0207 
0208         //step callback

0209         if (e.length > 0 && options.step) {
0210           var route = e[e.length - 1];
0211           if (route.legs.length > 0) {
0212             var steps = route.legs[0].steps;
0213             for (var i = 0, step; step = steps[i]; i++) {
0214               step.step_number = i;
0215               var polyline_options = {
0216                 path: step.path,
0217                 strokeColor: options.strokeColor,
0218                 strokeOpacity: options.strokeOpacity,
0219                 strokeWeight: options.strokeWeight
0220               };
0221 
0222               if (options.hasOwnProperty("icons")) {
0223                 polyline_options.icons = options.icons;
0224               }
0225 
0226               self.drawPolyline(polyline_options);
0227               options.step(step, (route.legs[0].steps.length - 1));
0228             }
0229           }
0230         }
0231 
0232         //end callback

0233         if (e.length > 0 && options.end) {
0234            options.end(e[e.length - 1]);
0235         }
0236       }
0237     });
0238   }
0239   else if (options.route) {
0240     if (options.route.legs.length > 0) {
0241       var steps = options.route.legs[0].steps;
0242       for (var i = 0, step; step = steps[i]; i++) {
0243         step.step_number = i;
0244         var polyline_options = {
0245           path: step.path,
0246           strokeColor: options.strokeColor,
0247           strokeOpacity: options.strokeOpacity,
0248           strokeWeight: options.strokeWeight
0249         };
0250 
0251         if (options.hasOwnProperty("icons")) {
0252           polyline_options.icons = options.icons;
0253         }
0254 
0255         self.drawPolyline(polyline_options);
0256         options.step(step);
0257       }
0258     }
0259   }
0260 };
0261 
0262 GMaps.Route = function(options) {
0263   this.origin = options.origin;
0264   this.destination = options.destination;
0265   this.waypoints = options.waypoints;
0266 
0267   this.map = options.map;
0268   this.route = options.route;
0269   this.step_count = 0;
0270   this.steps = this.route.legs[0].steps;
0271   this.steps_length = this.steps.length;
0272 
0273   var polyline_options = {
0274     path: new google.maps.MVCArray(),
0275     strokeColor: options.strokeColor,
0276     strokeOpacity: options.strokeOpacity,
0277     strokeWeight: options.strokeWeight
0278   };
0279 
0280   if (options.hasOwnProperty("icons")) {
0281     polyline_options.icons = options.icons;
0282   }
0283 
0284   this.polyline = this.map.drawPolyline(polyline_options).getPath();
0285 };
0286 
0287 GMaps.Route.prototype.getRoute = function(options) {
0288   var self = this;
0289 
0290   this.map.getRoutes({
0291     origin : this.origin,
0292     destination : this.destination,
0293     travelMode : options.travelMode,
0294     waypoints : this.waypoints || [],
0295     error: options.error,
0296     callback : function() {
0297       self.route = e[0];
0298 
0299       if (options.callback) {
0300         options.callback.call(self);
0301       }
0302     }
0303   });
0304 };
0305 
0306 GMaps.Route.prototype.back = function() {
0307   if (this.step_count > 0) {
0308     this.step_count--;
0309     var path = this.route.legs[0].steps[this.step_count].path;
0310 
0311     for (var p in path){
0312       if (path.hasOwnProperty(p)){
0313         this.polyline.pop();
0314       }
0315     }
0316   }
0317 };
0318 
0319 GMaps.Route.prototype.forward = function() {
0320   if (this.step_count < this.steps_length) {
0321     var path = this.route.legs[0].steps[this.step_count].path;
0322 
0323     for (var p in path){
0324       if (path.hasOwnProperty(p)){
0325         this.polyline.push(path[p]);
0326       }
0327     }
0328     this.step_count++;
0329   }
0330 };