private void DrawLegs(List <LegGeometry> legGeometries) { foreach (var legGeometry in legGeometries) { var routeCoordinates = PolylineConverter.Decode(legGeometry.points); var lineString = new LineString(routeCoordinates); var lineFeatureCollection = new FeatureCollection(new List <Feature> { new Feature(lineString) }); var lineSourceId = Guid.NewGuid().ToString(); var lineLayerId = Guid.NewGuid().ToString(); map.Functions.AddSource(new GeoJsonSource(lineSourceId, lineFeatureCollection) { Options = new GeoJsonOptions() { LineMetrics = true } }); map.Functions.AddLayerBelow(new LineLayer(lineLayerId, lineSourceId) { LineCap = LayerProperty.LINE_CAP_ROUND, LineJoin = LayerProperty.LINE_JOIN_ROUND, LineWidth = 2f, LineColor = Expression.Rgb(49, 129, 28) }, symbolLayer.Id); } }
/// <summary> /// Decode polyline /// </summary> /// <param name="encodedPolyline">Encoded polyline</param> private void DecodePolyline(string encodedPolyline) { var positions = PolylineConverter.DecodePolyline(encodedPolyline); if (positions != null) { positions.ForEach(o => Positions.Add(o)); } }
public async Task <IEnumerable <HourlyWeather> > GetHourlyWeatherForRoute(string origin, string destination) { var dirs = await GetDirections(origin, destination); // If no routes are returned, there's been an error with Google Maps if (dirs.Routes == null || !dirs.Routes.Any()) { throw new NoRoutesException(); } // Calculate total number of hours in route int numHours = 0; foreach (var r in dirs.Routes) { foreach (var l in r.Legs) { numHours += (l.Duration.Value.Days * 24) + l.Duration.Value.Hours; } } if (numHours > 48) { throw new SourceAPILimitationException("OpenWeatherMap API only supports hourly forecasts 48 hours in advance."); } // Build full list of polyline points List <Location> polyline = new List <Location>(); foreach (var route in dirs.Routes) { foreach (var leg in route.Legs) { foreach (var step in leg.Steps) { foreach (var point in step.PolyLine.Points) { polyline.Add(point); } } } } // Each entry in LocationIndices will be roughly 1 hour apart var locationIndices = polyline.Count / numHours; var hourlyWeather = new List <HourlyWeather>(); for (int i = 0; i < numHours; i++) { int locationIndex = i * locationIndices; var forecasts = await GetWeatherByCoords(polyline[locationIndex].Latitude, polyline[locationIndex].Longitude); hourlyWeather.Add(new HourlyWeather() { Location = polyline[locationIndex], Forecast = forecasts.Hourly[i], Alerts = forecasts.Alerts, ForecastTimestamp = UnixTimeStampToDateTime(forecasts.Hourly[i].Dt) }); } var polylineStr = PolylineConverter.Encode(hourlyWeather.Select(x => x.Location)); return(hourlyWeather); }