Helper methods to easily set and get view area in a more or less consistent way
Esempio n. 1
0
        private async void Control_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
        {
            try
            {
                if (Stations.Count > 1)
                {
                    if (_settingsService.Settings.IsCompassMode)
                    {
                        MainPage.mainPage.StopCompassAndUserLocationTracking();
                    }
                    await map.TrySetViewBoundsAsync(MapExtensions.GetAreaFromLocations(Stations.Select(s => (Geopoint)s.Location).ToList()), new Thickness(20, 20, 20, 20), MapAnimationKind.Default);
                }

                else
                {
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        MainPage.mainPage.SelectItem(this, false);
                    });
                }
            }
            catch
            {
            }
        }
Esempio n. 2
0
        public ClusterGenerator(MapControl map, ControlTemplate itemTemplate)
        {
            _map         = map;
            ItemTemplate = itemTemplate;
            GenerateMapItems();

            _contractService = SimpleIoc.Default.GetInstance <IContractService>();
            _contractService.ContractRefreshed += OnContractRefreshed;
            _contractService.StationRefreshed  += OnStationRefreshed;

            // maps event
            var mapObserver = Observable.FromEventPattern(map, "CenterChanged");

            mapObserver
            .Do((e) =>
            {
                cts.Cancel();
                cts = new CancellationTokenSource();
            })
            .Throttle(throttleTime)
            .Select(async x =>
            {
                var stations = SimpleIoc.Default.GetInstance <IContractService>().GetStations();
                // some services can provide wrong values in lat or lon... just take care of it
                foreach (var station in stations.Where(s => s.Location == null))
                {
                    station.Location = new Geopoint(new BasicGeoposition {
                        Latitude = station.Latitude, Longitude = station.Longitude
                    });
                }


                await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    //mapArea = _map.GetViewArea();
                    mapLocations = _map.GetViewLocations();
                    if (mapLocations != null)
                    {
                        leftCornerLocation = mapLocations.First().Position;
                    }
                    zoomLevel = _map.ZoomLevel;

                    // TESTING only
                    //velibControls[0].SetValue(MapControl.LocationProperty, new Geopoint(new BasicGeoposition()
                    //    {
                    //        Latitude = mapArea.NorthwestCorner.Latitude,
                    //        Longitude = mapArea.NorthwestCorner.Longitude,
                    //    }));
                    //velibControls[0].ShowVelibStation();
                    //velibControls[1].SetValue(MapControl.LocationProperty, new Geopoint(new BasicGeoposition()
                    //{
                    //    Latitude = mapArea.SoutheastCorner.Latitude,
                    //    Longitude = mapArea.SoutheastCorner.Longitude,
                    //}));
                    //velibControls[1].ShowVelibStation();
                });
                //return null;
                // that could happend is the zoom is really low and the map is turned
                if (mapLocations == null)
                {
                    return(null);
                }

                var collection      = new AddRemoveCollection();
                collection.ToRemove = Items.Where(t => !MapExtensions.Contains(mapLocations, t.Latitude, t.Longitude)).ToList();
                collection.ToAdd    = stations.Where(t => !Items.Contains(t) &&
                                                     MapExtensions.Contains(mapLocations, t.Latitude, t.Longitude)).Take(MAX_CONTROLS).ToList();
                if (Items.Count > MAX_CONTROLS + collection.ToRemove.Count)
                {
                    collection.ToAdd.Clear();
                }


                // precalculate the items offset (that deffer well calculation)
                foreach (var velib in collection.ToAdd)
                {
                    velib.GetOffsetLocation2(leftCornerLocation, zoomLevel);
                }
                return(collection);
            })
            .Switch()
            .Subscribe(x =>
            {
                if (x == null)
                {
                    return;
                }
                RefreshView(x, cts.Token);
            });
        }