예제 #1
0
        private async void SetBoundaries(IMapControl map, LocationRectangle boundaries, bool noStopInParameter)
        {
            await Task.Delay(250);

            await initializeMapLabels(map);

            await map.TrySetViewBoundsAsync(boundaries, false);

            //while (page.ZoomLevel < 15)
            //{
            //    page.SetView(boundaries, MapAnimationKind.None);
            //    await Task.Delay(100);
            //}
            //while (page.IsMapEmpty)
            //{
            //    initializeMapLabels(page);
            //    await Task.Delay(100);
            //}

            map.CenterChanged += async(sender, args) =>
            {
                await mapFillingLock.WaitAsync();

                if (map.ZoomLevel >= App.Config.LowStopsMapLevel)
                {
                    await tryCreateStopLabelsAt(map, map.Center);
                }
                else if (map.ZoomLevel >= App.Config.HighStopsMapLevel)
                {
                    await tryCreateHighStopLabelsAt(map, map.Center);

                    clearMap(map, 2.1);
                }
                else
                {
                    clearMap(map);
                }
                mapFillingLock.Release();
            };

            if (isNear && noStopInParameter && mainPoints.Length == 0)
            {
                var nearestResult = await StopTransfers.GetNearestStop(CurrentLocation.Last);

                if (nearestResult != null)
                {
                    this.location   = CurrentLocation.Last;
                    this.mainPoints = nearestResult.Stop.Group.Stops.Select(s => s.Coordinate).ToArray();
                    var boundAddition = new GeoCoordinate[] { CurrentLocation.Last ?? App.Config.CenterLocation };

                    boundaries = calculateBoundaries(mainPoints.Concat(boundAddition));

                    await map.TrySetViewBoundsAsync(boundaries, false);
                    await initializeMapLabels(map);
                }
            }
        }
예제 #2
0
        //private AdControl AdControl;

        //public void SetPlanningSource(StopGroup stop)
        //{
        //}
        //public void SetPlanningDestination(StopGroup stop)
        //{
        //}

        private async void updateContent()
        {
            FavoritesPart.UpdateContent();
            if (SettingsModel.AutomaticNearSearch)
            {
                var nearestStop = await StopTransfers.GetNearestStop(await CurrentLocation.Get());

                if (nearestStop != null)
                {
                    FavoritesPart.NearStop = nearestStop.Stop.Group;
                    PlanningPart.SetNearStop(nearestStop.Stop.Group, nearestStop.EstimatedDuration);
                }
            }
        }
예제 #3
0
        public override async void Bind(MapPage page)
        {
            base.Bind(page);
            base.RegisterElementTypes(typeof(StopPushpin));

            int stopGroupId = int.Parse(page.NavigationContext.QueryString["stopGroupID"]);

            if (stopGroupId != 0)
            {
                this.stopGroup  = App.Model.GetStopGroupByID(stopGroupId);
                this.mainStops  = new HashSet <Stop>(stopGroup.Stops);
                this.mainPoints = mainStops.Select(s => s.Coordinate).ToArray();
            }
            else
            {
                this.fromMainPage = true;
                if (StopTransfers.LastNearestStop != null)
                {
                    this.mainPoints = StopTransfers.LastNearestStop.Stop.Group.Stops.Select(s => s.Coordinate).ToArray();
                }
            }
            string locationStr = null, dateTimeStr = null;

            if (page.NavigationContext.QueryString.TryGetValue("location", out locationStr))
            {
                this.postQuery.Add("location", locationStr);
                if (locationStr != "near")
                {
                    this.sourceStop = App.Model.GetStopByID(int.Parse(locationStr));
                    this.location   = sourceStop.Coordinate;
                }
                else
                {
                    this.location = CurrentLocation.Last;
                    isNear        = true;
                }
            }
            if (page.NavigationContext.QueryString.TryGetValue("dateTime", out dateTimeStr))
            {
                this.postQuery.Add("dateTime", dateTimeStr);
                this.dateTime = System.Convert.ToDateTime(dateTimeStr);
                isNow         = false;
            }

            if (isNow)
            {
                timeUpdaterTask = new PeriodicTask(DoTimeUpdate);
                timeUpdaterTask.RunEveryMinute();
                page.Tasks.Add(timeUpdaterTask);
            }
            if (isNear)
            {
                locationUpdaterTask = new PeriodicTask(10000, DoLocationUpdate);
                locationUpdaterTask.Run(delay: 1000);
                page.Tasks.Add(locationUpdaterTask);
            }


            //foreach (var transfer in transfers)
            //{
            //    Microsoft.Phone.Maps.Controls.MapPolyline line = new Microsoft.Phone.Maps.Controls.MapPolyline
            //    {
            //        StrokeColor = Colors.Gray,
            //        StrokeDashed = true,
            //        StrokeThickness = 8
            //    };
            //    line.Path.Add(transfer.Origin.Coordinate);
            //    line.Path.AddRange(transfer.InnerPoints.Select(p => new GeoCoordinate(p.Latitude, p.Longitude)));
            //    line.Path.Add(transfer.Target.Coordinate);
            //    Map.MapElements.Add(line);
            //}
            this.EmptyMapTap   += (sender, args) => clearSelection();
            this.MapElementTap += (sender, element) => tapActions[element].Invoke();

            var boundAddition = isNear ? new GeoCoordinate[] { CurrentLocation.Last ?? App.Config.CenterLocation } : new GeoCoordinate[0];
            var boundaries    = calculateBoundaries(mainPoints.Concat(boundAddition));

            //await Task.Delay(250);
            await initializeMapLabels(page);

            page.Map.SetView(boundaries, MapAnimationKind.None);
            while (page.Map.ZoomLevel < 15)
            {
                page.Map.SetView(boundaries, MapAnimationKind.None);
                await Task.Delay(100);
            }
            //while (page.IsMapEmpty)
            //{
            //    initializeMapLabels(page);
            //    await Task.Delay(100);
            //}

            page.Map.CenterChanged += async(sender, args) =>
            {
                await mapFillingLock.WaitAsync();

                if (page.Map.ZoomLevel >= App.Config.LowStopsMapLevel)
                {
                    var newLocation = page.Map.Center;
                    await tryCreateStopLabelsAt(page, Convert(newLocation));
                }
                else if (page.Map.ZoomLevel >= App.Config.HighStopsMapLevel)
                {
                    var newLocation = page.Map.Center;
                    await tryCreateHighStopLabelsAt(page, Convert(newLocation));

                    clearMap(page, 2.1);
                }
                else
                {
                    clearMap(page);
                }
                mapFillingLock.Release();
            };

            if (isNear && stopGroupId == 0 && mainPoints.Length == 0)
            {
                var nearestResult = await StopTransfers.GetNearestStop(await CurrentLocation.Get());

                if (nearestResult != null)
                {
                    this.location   = CurrentLocation.Last;
                    this.mainPoints = nearestResult.Stop.Group.Stops.Select(s => s.Coordinate).ToArray();
                    boundAddition   = new GeoCoordinate[] { CurrentLocation.Last ?? App.Config.CenterLocation };

                    boundaries = calculateBoundaries(mainPoints.Concat(boundAddition));

                    page.Map.SetView(boundaries, MapAnimationKind.None);
                    await initializeMapLabels(page);
                }
            }
        }