Esempio n. 1
0
        public async Task <List <TransitStop>?> GetStopsAsync(string searchString, CancellationToken token)
        {
            Uri uri = new Uri(DefaultGqlRequestUrl);

            GqlQuery query = new GqlQuery(ApiGqlMembers.stops)
                             .WithParameters(new GqlParameter(ApiGqlMembers.name, searchString))
                             .WithReturnValues(
                new GqlReturnValue(ApiGqlMembers.id),
                new GqlReturnValue(ApiGqlMembers.gtfsId),
                new GqlReturnValue(ApiGqlMembers.lat),
                new GqlReturnValue(ApiGqlMembers.lon),
                new GqlReturnValue(ApiGqlMembers.name),
                new GqlReturnValue(ApiGqlMembers.code),
                new GqlReturnValue(ApiGqlMembers.routes,
                                   new GqlReturnValue(ApiGqlMembers.mode)
                                   )
                );
            IEnumerable <ApiStop>?response = (await GetGraphQL <IEnumerable <ApiStop> >(query, token)
                                              .ConfigureAwait(false))
                                             .ToList();

            if (response == null || !response.Any())
            {
                return(null);
            }

            return(new List <TransitStop>(response.Select(x => new TransitStop
            {
                Name = x.Name,
                Code = x.Code,
                Coords = BasicGeopositionExtensions.Create(0.0, x.Lat, x.Lon),
                GtfsId = x.GtfsId,
                Id = Guid.NewGuid()
            })));
        }
Esempio n. 2
0
        public async Task <ApiResult <IEnumerable <TransitStop> > > GetStopsByBoundingRadius(float lat, float lon, int radiusMeters,
                                                                                             CancellationToken token = default(CancellationToken))
        {
            GqlQuery query = new GqlQuery(ApiGqlMembers.stopsByRadius)
                             .WithParameters(
                new GqlParameter(ApiGqlMembers.lat, lat),
                new GqlParameter(ApiGqlMembers.lon, lon),
                new GqlParameter(ApiGqlMembers.radius, radiusMeters)
                )
                             .WithReturnValues(
                new GqlReturnValue(ApiGqlMembers.edges,
                                   new GqlReturnValue(ApiGqlMembers.node,
                                                      new GqlReturnValue(ApiGqlMembers.stop,
                                                                         new GqlReturnValue(ApiGqlMembers.gtfsId),
                                                                         new GqlReturnValue(ApiGqlMembers.name),
                                                                         new GqlReturnValue(ApiGqlMembers.code),
                                                                         new GqlReturnValue(ApiGqlMembers.lat),
                                                                         new GqlReturnValue(ApiGqlMembers.lon),
                                                                         new GqlReturnValue(ApiGqlMembers.patterns,
                                                                                            new GqlReturnValue(ApiGqlMembers.name),
                                                                                            new GqlReturnValue(ApiGqlMembers.route,
                                                                                                               new GqlReturnValue(ApiGqlMembers.shortName),
                                                                                                               new GqlReturnValue(ApiGqlMembers.longName)
                                                                                                               )
                                                                                            )
                                                                         )
                                                      )
                                   )
                );

            var response = await GetGraphQLAsync <ApiStopAtDistanceConnection>(query, token).ConfigureAwait(false);

            if (response.HasResult)
            {
                IEnumerable <TransitStop> stops = response.Result.Edges?.Select(x => new TransitStop
                {
                    GtfsId = x.Node.Stop.GtfsId,
                    Coords = BasicGeopositionExtensions.Create(0.0, x.Node.Stop.Lon, x.Node.Stop.Lat),
                    Code   = x.Node.Stop.Code,
                    Name   = x.Node.Stop.Name,
                    Id     = Guid.NewGuid()
                });
                if (stops == null)
                {
                    LogLogicFailure(FailureReason.Unspecified);
                    return(ApiResult <IEnumerable <TransitStop> > .Fail);
                }
                if (!stops.Any())
                {
                    LogLogicFailure(FailureReason.NoResults);
                    return(ApiResult <IEnumerable <TransitStop> > .FailWithReason(FailureReason.NoResults));
                }
                return(new ApiResult <IEnumerable <TransitStop> >(stops));
            }
            else
            {
                return(ApiResult <IEnumerable <TransitStop> > .FailWithReason(FailureReason.Unspecified));
            }
        }
Esempio n. 3
0
        private async Task TrySetMapViewWithMargin(BasicGeoposition pos, double boundingBoxZoomAdjustment, MapAnimationKind mapAnimation = MapAnimationKind.None)
        {
            double narrowZoomAdjustment = boundingBoxZoomAdjustment / 2;

            // Creators update changed maps a bit, so we need to zoom in closer on any device running it.
            // MapStyle is a decent proxy for "are we on Creators or not"
            if (DeviceTypeHelper.GetDeviceFormFactorType() == DeviceFormFactorType.Phone &&
                !ApiInformation.IsTypePresent("Windows.UI.Xaml.Controls.Maps.MapStyle"))
            {
                narrowZoomAdjustment = boundingBoxZoomAdjustment / 1.35;
            }

            // Create a box surrounding the specified point to emulate a zoom level on the map.
            // We're using a simulated bounding box, because we need to be able to specify a margin,
            // to accommodate either of the the floating content panels.
            BasicGeoposition northwest = BasicGeopositionExtensions.Create
                                         (
                0.0,
                pos.Longitude - boundingBoxZoomAdjustment,
                pos.Latitude + boundingBoxZoomAdjustment
                                         );
            BasicGeoposition southeast = BasicGeopositionExtensions.Create
                                         (
                0.0,
                pos.Longitude + boundingBoxZoomAdjustment,
                pos.Latitude - boundingBoxZoomAdjustment
                                         );

            if (AdaptiveVisualStateGroup.CurrentState == _narrowVisualState)
            {
                // Zoom in a little further when in the narrow view, otherwise we're a little
                // too far out for the narrow field of view
                northwest.Longitude += narrowZoomAdjustment;
                northwest.Latitude  -= narrowZoomAdjustment;

                southeast.Longitude -= narrowZoomAdjustment;
                southeast.Latitude  += narrowZoomAdjustment;

                GeoboundingBox box = new GeoboundingBox(northwest, southeast);
                if (NarrowSearchPanel.IsOpen)
                {
                    double bottomMargin = NarrowSearchPanel.ExpandedHeight;
                    await PageMap.TrySetViewBoundsAsync(box, new Thickness(0, 0, 0, bottomMargin), mapAnimation);
                }
                else
                {
                    await PageMap.TrySetViewBoundsAsync(box, new Thickness(0, 0, 0, 0), mapAnimation);
                }
            }
            else
            {
                GeoboundingBox box = new GeoboundingBox(northwest, southeast);
                await PageMap.TrySetViewBoundsAsync(box, new Thickness(410, 0, 0, 0), mapAnimation);
            }
        }
Esempio n. 4
0
        public async Task <List <TransitStop>?> GetStopsByBoundingRadius(float lat, float lon, int radiusMeters, CancellationToken token)
        {
            GqlQuery query = new GqlQuery(ApiGqlMembers.stopsByRadius)
                             .WithParameters(
                new GqlParameter(ApiGqlMembers.lat, lat),
                new GqlParameter(ApiGqlMembers.lon, lon),
                new GqlParameter(ApiGqlMembers.radius, radiusMeters)
                )
                             .WithReturnValues(
                new GqlReturnValue(ApiGqlMembers.edges,
                                   new GqlReturnValue(ApiGqlMembers.node,
                                                      new GqlReturnValue(ApiGqlMembers.stop,
                                                                         new GqlReturnValue(ApiGqlMembers.gtfsId),
                                                                         new GqlReturnValue(ApiGqlMembers.name),
                                                                         new GqlReturnValue(ApiGqlMembers.code),
                                                                         new GqlReturnValue(ApiGqlMembers.lat),
                                                                         new GqlReturnValue(ApiGqlMembers.lon),
                                                                         new GqlReturnValue(ApiGqlMembers.patterns,
                                                                                            new GqlReturnValue(ApiGqlMembers.name),
                                                                                            new GqlReturnValue(ApiGqlMembers.route,
                                                                                                               new GqlReturnValue(ApiGqlMembers.shortName),
                                                                                                               new GqlReturnValue(ApiGqlMembers.longName)
                                                                                                               )
                                                                                            )
                                                                         )
                                                      )
                                   )
                );

            ApiStopsByRadius?response = await GetGraphQL <ApiStopsByRadius>(query, token).ConfigureAwait(false);

            if (response == null || response?.StopsByRadius?.Edges?.Any() != true)
            {
                return(null);
            }

            return(response?.StopsByRadius?.Edges?.Select(x => new TransitStop
            {
                GtfsId = x.Node.Stop.GtfsId,
                Coords = BasicGeopositionExtensions.Create(0.0, x.Node.Stop.Lat, x.Node.Stop.Lon),
                Code = x.Node.Stop.Code,
                Name = x.Node.Stop.Name,
                Id = Guid.NewGuid()
            }).ToList());
        }
Esempio n. 5
0
 public TransitLine(ApiRoute route)
 {
     TransitMode = route.Mode;
     ShortName   = route.ShortName;
     LongName    = route.LongName;
     GtfsId      = route.GtfsId;
     Stops       = route.Patterns
                   .FirstOrDefault()
                   ?.Stops
                   ?.Select(x => new TransitStop
     {
         Coords = BasicGeopositionExtensions.Create(0.0, x.Lon, x.Lat),
         Name   = x.Name,
         Code   = x.Code
     });
     Points = route.Patterns
              .FirstOrDefault()
              ?.Geometry
              .Select(x => BasicGeopositionExtensions.Create(0.0, x.Lon, x.Lat));
 }
Esempio n. 6
0
        //---GRAPHQL REQUESTS---

        public async Task <ApiResult <IEnumerable <TransitStop> > > GetStopsAsync(string searchString, CancellationToken token = default(CancellationToken))
        {
            Uri uri = new Uri(DefaultGqlRequestUrl);

            GqlQuery query = new GqlQuery(ApiGqlMembers.stops)
                             .WithParameters(new GqlParameter(ApiGqlMembers.name, searchString))
                             .WithReturnValues(
                new GqlReturnValue(ApiGqlMembers.id),
                new GqlReturnValue(ApiGqlMembers.gtfsId),
                new GqlReturnValue(ApiGqlMembers.lat),
                new GqlReturnValue(ApiGqlMembers.lon),
                new GqlReturnValue(ApiGqlMembers.name),
                new GqlReturnValue(ApiGqlMembers.code),
                new GqlReturnValue(ApiGqlMembers.routes,
                                   new GqlReturnValue(ApiGqlMembers.mode)
                                   )
                );
            var response = await GetGraphQLAsync <List <ApiStop> >(query);

            if (!response.HasResult)
            {
                return(ApiResult <IEnumerable <TransitStop> > .FailWithReason(response.Failure.Reason));
            }
            if (response.HasResult && !response.Result.Any())
            {
                LogLogicFailure(FailureReason.NoResults);
                return(ApiResult <IEnumerable <TransitStop> > .FailWithReason(FailureReason.NoResults));
            }

            return(new ApiResult <IEnumerable <TransitStop> >(response.Result.Select(x => new TransitStop
            {
                Name = x.Name,
                Code = x.Code,
                Coords = BasicGeopositionExtensions.Create(0.0, x.Lon, x.Lat),
                GtfsId = x.GtfsId,
                Id = Guid.NewGuid()
            })));
        }
Esempio n. 7
0
        private void UpdateSelectedLine(LineSearchElementViewModel element)
        {
            MapLines.Clear();
            MapPlaces.Clear();

            if (element == null)
            {
                return;
            }

            List <ColoredMapLinePoint> linePoints = element
                                                    .BackingLine
                                                    .Points
                                                    .Select(x => new ColoredMapLinePoint(
                                                                BasicGeopositionExtensions.Create(0.0, x.Longitude, x.Latitude),
                                                                HslColors.GetModeColor(element.BackingLine.TransitMode)))
                                                    .ToList();

            var mapLine = new ColoredMapLine(linePoints);

            MapLines.Clear();
            MapLines.AddRange(new List <ColoredMapLine> {
                mapLine
            });

            List <IMapPoi> stops = new List <IMapPoi>();

            foreach (var stop in element.BackingLine.Stops)
            {
                stops.Add(new BasicMapPoi {
                    Coords = stop.Coords, Name = stop.Name
                });
            }
            MapPlaces.AddRange(stops);

            _messenger.Send(new MessageTypes.SearchLineSelectionChanged());
        }