public override string GetRequestUrl()

in Source/Requests/IsochroneRequest.cs [132:232]


        public override string GetRequestUrl()
        {
            var sb = new StringBuilder(this.Domain);

            sb.Append("Routes/IsochronesAsync");

            //Truck mode is not supported, so fall back to driving. 
            if (TravelMode == TravelModeType.Truck)
            {
                TravelMode = TravelModeType.Driving;
            }

            sb.AppendFormat("?travelMode={0}", Enum.GetName(typeof(TravelModeType), TravelMode));

            if(Waypoint == null)
            {
                throw new Exception("A waypoint must be specified.");
            }

            if (Waypoint.Coordinate != null)
            {
                sb.AppendFormat(CultureInfo.InvariantCulture, "&waypoint={0:0.#####},{1:0.#####}", Waypoint.Coordinate.Latitude, Waypoint.Coordinate.Longitude);
            }
            else if (!String.IsNullOrWhiteSpace(Waypoint.Address))
            {
                sb.AppendFormat("&waypoint={0}", Waypoint.Address);
            }
            else
            {
                throw new Exception("Invalid waypoint: A coordinate or address must be specified.");
            }

            if(MaxTime > 0)
            {            
                if (TimeUnit == TimeUnitType.Second && MaxTime > 3600)
                {
                    throw new Exception("MaxTime value must be <= 3600 seconds.");
                }
                else if (TimeUnit == TimeUnitType.Minute && MaxTime > 60)
                {
                    throw new Exception("MaxTime value must be <= 60 minutes.");
                }

                sb.AppendFormat("&maxTime={0}&timeUnit={1}", MaxTime, Enum.GetName(typeof(TimeUnitType), TimeUnit));
                               
                if (TravelMode != TravelModeType.Walking && DateTime != null && DateTime.HasValue)
                {
                    sb.AppendFormat(DateTimeFormatInfo.InvariantInfo, "&dt={0:G}", DateTime.Value);
                }

                //Can only optimize based on time or time with traffic when generating time based isochrones.
                if(Optimize != RouteOptimizationType.Time && Optimize != RouteOptimizationType.TimeWithTraffic)
                {
                    Optimize = RouteOptimizationType.Time;
                }
            }
            else if (MaxDistance > 0)
            {
                if(TravelMode == TravelModeType.Transit)
                {
                    throw new Exception("Distance based isochrones are not supported for transit travel mode. Use maxTime.");
                }

                sb.AppendFormat(CultureInfo.InvariantCulture, "&maxDistance={0}&distanceUnit={1}", MaxDistance, EnumHelper.DistanceUnitTypeToString(DistanceUnit));

                //Can only optimize based on distance when generating distance based isochrones.
                if (Optimize != RouteOptimizationType.Distance)
                {
                    Optimize = RouteOptimizationType.Distance;
                }
            }
            else
            {
                throw new Exception("A max time or distance must be specified.");
            }

            sb.AppendFormat("&optimize={0}", Enum.GetName(typeof(RouteOptimizationType), Optimize));

            //TODO: uncomment when/if avoid is supported.
            //if (TravelMode == TravelModeType.Driving)
            //{
            //    if (Avoid != null && Avoid.Count > 0)
            //    {
            //        sb.Append("&avoid=");

            //        for (var i = 0; i < Avoid.Count; i++)
            //        {
            //            sb.Append(Enum.GetName(typeof(AvoidType), Avoid[i]));

            //            if (i < Avoid.Count - 1)
            //            {
            //                sb.Append(",");
            //            }
            //        }
            //    }
            //}

            sb.Append(GetBaseRequestUrl());

            return sb.ToString();
        }