1 2/******************************************************************************/ 3/******************************************************************************/ 4 5function CHBSGoogleMapAPI($APIKey) 6{ 7 /**************************************************************************/ 8 9 this.APIKey=$APIKey; 10 11 /**************************************************************************/ 12 13 this.computeRoutes=function(data,callback) 14 { 15 this.request('computeRoutes',data,callback); 16 }; 17 18 /**************************************************************************/ 19 20 this.request=function(name,data,callback) 21 { 22 var url; 23 24 if(name==='computeRoutes') 25 { 26 url='https://routes.googleapis.com/directions/v2:computeRoutes'; 27 } 28 29 data.origin=this.transformCoordinate(data.origin); 30 data.destination=this.transformCoordinate(data.destination); 31 32 if(typeof(data.intermediates)!=='undefined') 33 { 34 for(var i in data.intermediates) 35 { 36 data.intermediates[i]=this.transformCoordinate(data.intermediates[i].location); 37 } 38 } 39 40 data=JSON.stringify(data); 41 42 jQuery.ajax( 43 { 44 url:url, 45 data:data, 46 type:'post', 47 dataType:'json', 48 contentType:'application/json', 49 headers: 50 { 51 'X-Goog-Api-Key':this.APIKey, 52 'X-Goog-FieldMask':'routes.duration,routes.distanceMeters,routes.legs,routes.polyline.encodedPolyline' 53 }, 54 success:function(response) 55 { 56 callback(response); 57 } 58 }); 59 }; 60 61 /**************************************************************************/ 62 63 this.transformCoordinate=function(coordinate) 64 { 65 var data={}; 66 67 data.location= 68 { 69 'latLng': 70 { 71 'latitude':coordinate.lat(), 72 'longitude':coordinate.lng(), 73 } 74 }; 75 76 return(data); 77 }; 78 79 /**************************************************************************/ 80 81 this.hasRoute=function(response) 82 { 83 if(typeof(response)==='undefined') return(false); 84 85 return(response.hasOwnProperty('routes') ? true : false); 86 }; 87 88 /**************************************************************************/ 89 90 this.getBound=function(response,routeIndex=0) 91 { 92 var bound=new google.maps.LatLngBounds(); 93 94 for(var i in response.routes[routeIndex].legs) 95 { 96 var leg=response.routes[routeIndex].legs[i]; 97 98 var coordinateStart=leg.startLocation.latLng; 99 var coordinateEnd=leg.endLocation.latLng; 100 101 bound.extend(new google.maps.LatLng(coordinateStart.latitude,coordinateStart.longitude)); 102 bound.extend(new google.maps.LatLng(coordinateEnd.latitude,coordinateEnd.longitude)); 103 } 104 105 return(bound); 106 } 107 108 /**********************************************************************/ 109 110 this.drawRoute=function(response,routeIndex,googleMap) 111 { 112 var line=response.routes[routeIndex].polyline.encodedPolyline; 113 114 var path=google.maps.geometry.encoding.decodePath(line); 115 116 new google.maps.Polyline( 117 { 118 path:path, 119 strokeColor:'#60A9F2', 120 strokeOpacity:1.0, 121 strokeWeight:4, 122 map:googleMap 123 }); 124 }; 125 126 /**************************************************************************/ 127}; 128 129/******************************************************************************/ 130/******************************************************************************/
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.