/// <summary>
 /// 
 /// </summary>
 /// <param name="locations"></param>
 /// <param name="routeType"></param>
 /// <param name="drivingStyle"></param>
 /// <param name="avoids"></param>
 /// <param name="enhancedNarrative"></param>
 /// <param name="metric"></param>
 /// <param name="fuelEfficiency"></param>
 /// <returns></returns>
 public static Directions getDirections(List<Locations> locations, StaticMap.MapType mapType, RouteType routeType = RouteType.Fastest, DrivingStyle drivingStyle = DrivingStyle.Normal, List<Avoids> avoids = null, bool enhancedNarrative = false, bool metric = false, int fuelEfficiency = 21)
 {
     if (locations.Count == 0)
         return new Directions();
     if (locations.Count == 1)
     {
         //Front end request an empty direction with the map of the location
         Directions d = new Directions();
         d.mainMap = locations[0].map;
         d.mapDetails = locations[0].mapDetails;
         d.mapDetails.mapType = mapType;
         d.legs.Add(new Leg());
         d.legs[0].maneuvers.Add(new Maneuver());
         return d;
     }
     WebClient w = new WebClient();
     string url = ConfigurationManager.AppSettings["MapQuestDirectionsURL"] + ConfigurationManager.AppSettings["MapQuestAPIKey"];
     if (avoids != null)
     {
         foreach (Avoids a in avoids)
             switch (a)
             {
                 case Avoids.CountryBorderCrossing:
                     url += "&avoids=Country border";
                     break;
                 case Avoids.Ferry:
                     url += "&avoids=Ferry";
                     break;
                 case Avoids.LimitedAccess:
                     url += "&avoids=Limited Access";
                     break;
                 case Avoids.SeasonalClosure:
                     url += "&avoids=Approximate Seasonal Closure";
                     break;
                 case Avoids.TollRoad:
                     url += "&avoids=Toll road";
                     break;
                 case Avoids.Unpaved:
                     url += "&avoids=Unpaved";
                     break;
                 default:
                     break;
             }
     }
     url += "&outFormat=json";
     switch (routeType)
     {
         case RouteType.Fastest:
             url += "&routeType=fastest";
             break;
         case RouteType.Shortest:
             url += "&routeType=shortest";
             break;
         case RouteType.Pedestrian:
             url += "&routeType=pedestrian";
             break;
         case RouteType.Bicycle:
             url += "&routeType=bicycle";
             break;
         case RouteType.Multimodal:
             url += "&routeType=multimodal";
             break;
         default:
             url += "&routeType=fastest";
             break;
     }
     url += "&timeType=1";
     url += (enhancedNarrative ? "&enhancedNarrative=true" : "&enhancedNarrative=false");
     url += "&shapeFormat=raw&generalize=0";
     url += ConfigurationManager.AppSettings["MapQuestDirectionsLocale"];
     url += (metric ? "&unit=k" : "&unit=m");
     for (int i = 1; i < locations.Count; ++i)
     {
         url += ("&from=" + locations[i - 1].latLng.lat + ',' + locations[i - 1].latLng.lng
             + "&to=" + locations[i].latLng.lat + ',' + locations[i].latLng.lng);
     }
     url += "&drivingStyle=";
     switch (drivingStyle)
     {
         case DrivingStyle.Aggressive:
             url += "3";
             break;
         case DrivingStyle.Cautious:
             url += "1";
             break;
         case DrivingStyle.Normal:
             url += "2";
             break;
         default:
             url += "2";
             break;
     }
     url += "&highwayEfficiency=" + fuelEfficiency;
     JsonSerializerSettings s = new JsonSerializerSettings();
     s.NullValueHandling = NullValueHandling.Ignore;
     s.ObjectCreationHandling = ObjectCreationHandling.Replace;
     Directions result = JsonConvert.DeserializeObject<DirectionsRootObject>(w.DownloadString(url), s).route;
     result.mapDetails.mapType = mapType;
     return result;
 }
Example #2
0
 public StaticMap(List<LatLng> highlightPoints, Color boarder, Color fill, BoundingBox bestFit = null, int polygonWidth = 0, uint width = 640, uint height = 480, StaticMap.ImageType _imageType = StaticMap.ImageType.png, StaticMap.MapType _mapType = StaticMap.MapType.hyb, bool _declutter = false, List<XIS> _xis = null)
 {
     session_ = String.Empty;
     if(bestFit == null && highlightPoints.Count > 0)
     {
         bBox_ = new BoundingBox(new LatLng(highlightPoints[0].lat, highlightPoints[0].lng), new LatLng(highlightPoints[0].lat, highlightPoints[0].lng));
         for(int i = 1; i < highlightPoints.Count; ++i){
             if(bBox_.ul.lat < highlightPoints[i].lat)
             {
                 bBox_.ul.lat = highlightPoints[i].lat;
             }
             if(bBox_.ul.lng > highlightPoints[i].lng)
             {
                 bBox_.ul.lng = highlightPoints[i].lng;
             }
             if(bBox_.lr.lat > highlightPoints[i].lat)
             {
                 bBox_.lr.lat = highlightPoints[i].lat;
             }
             if(bBox_.lr.lng < highlightPoints[i].lng)
             {
                 bBox_.lr.lng = highlightPoints[i].lng;
             }
         }
     }
     else
     {
         bBox_ = bestFit;
     }            
     zoom_ = 0;
     imageType_ = _imageType;
     declutter_ = false;
     size_ = new Size(width, height);
     mapType_ = _mapType;
     center_ = null;
     mCenter_ = null;
     pCenter_ = null;
     sCenter_ = null;
     eCenter_ = null;
     stops_ = null;
     shape_ = null;
     ellipse_ = null;
     polyline_ = null;
     polygon_ = new Polygon(boarder, polygonWidth, fill, highlightPoints);
     map_ = null;
     xis_ = _xis;
     pois_ = null;
 }
Example #3
0
        // Leonard modified 04/30/2015

        public StaticMap(string sessionId, BoundingBox inbBox, Directions_Result_Class.Shape _shape, int _zoom = 0, uint width = 640, uint height = 480, StaticMap.ImageType _imageType = StaticMap.ImageType.png, StaticMap.MapType _mapType = StaticMap.MapType.hyb, bool _declutter = false, List<XIS> _xis = null) 
        {

            session_ = sessionId;
            bBox_ = inbBox;
            zoom_ = _zoom;
            imageType_ = _imageType;
            declutter_ = false;
            size_ = new Size(width, height);
            mapType_ = _mapType;
            center_ = null;
            mCenter_ = null;
            pCenter_ = null;
            sCenter_ = (_shape.shapePoints.Count > 1 ? new Center(_shape.shapePoints[0], _shape.shapePoints[1]) : null);
            eCenter_ = (sCenter == null ? null : new Center(_shape.shapePoints[_shape.shapePoints.Count - 2], _shape.shapePoints[_shape.shapePoints.Count - 1]));
            if (_shape.legIndexes.Count > 2)
            {
                stops_ = new List<Center>();
                char letter = 'A';
                for (int i = 1; i < _shape.legIndexes.Count - 1; ++i)
                {
                    stops_.Add(new Center(_shape.shapePoints[_shape.legIndexes[i] * 2], _shape.shapePoints[_shape.legIndexes[i] * 2 + 1], 0, 0, letter++));
                }
            }
            else
            {
                stops_ = null;
            }
            shape_ = null;
            ellipse_ = null;
            polyline_ = null;
            polygon_ = null;
            map_ = null;
            xis_ = _xis;
            pois_ = new List<Center>();
            mapChanged = false;

        
        }
Example #4
0
        // Ngwa T Leonard

        public StaticMap(List<Locations> locations, int _zoom = 0, uint width = 640, uint height = 480, StaticMap.ImageType _imageType = StaticMap.ImageType.png, StaticMap.MapType _mapType = StaticMap.MapType.hyb, bool _declutter = false, List<XIS> _xis = null)
        {
            session_ = String.Empty;
            bBox_ = null;
            zoom_ = _zoom;
            imageType_ = _imageType;
            declutter_ = false;
            size_ = new Size(width, height);
            mapType_ = _mapType;
            center_ = null;
            mCenter_ = null;
            pCenter_ = null;
            sCenter_ = null;
            eCenter_ = null;
            stops_ = null;
            shape_ = null;
            ellipse_ = null;
            polyline_ = null;
            polygon_ = null;
            map_ = null;
            xis_ = _xis;
            pois_ = new List<Center>();
            foreach (Locations l in locations)
            {
                pois_.Add(new Center(l.displayLatLng));
            }
            mapChanged = false;
        }