Beispiel #1
0
        private async void Location_Click(object sender, RoutedEventArgs e)
        {
            MyLocBtn.IsEnabled = false;
            if (helper.hasInternet())
            {
                await vm.setGeoLocation(MainMap.Center);

                await vm.loadPins();

                ScreenCenter.Text = "X";

                if (vm.Pushpins.Count > 0)
                {
                    Bing.Maps.LocationRect boundingRect = vm.GetLocationsRect(vm.Pushpins, vm.MyLocation);
                    MainMap.SetView(boundingRect);
                }
                else
                {
                    try
                    {
                        MainMap.SetView(vm.MyLocation, 15);
                    }
                    catch (Exception)
                    {
                        MyLocBtn.IsEnabled = true;
                        return;
                    }
                }
            }
            MyLocBtn.IsEnabled = true;
        }
Beispiel #2
0
        public Bing.Maps.LocationRect GetLocationsRect(ObservableCollection <Pin> locations, Location locationMy = null)
        {
            var boundingRect = new Bing.Maps.LocationRect();

            if (locations.Count == 0)
            {
                if (locationMy != null)
                {
                    boundingRect.Center = locationMy;
                }
            }
            else
            {
                double minLatitude  = locations[0].Coordinates.Latitude;
                double minLongitude = locations[0].Coordinates.Longitude;
                double maxLatitude  = locations[0].Coordinates.Latitude;
                double maxLongitude = locations[0].Coordinates.Longitude;
                if (locationMy != null)
                {
                    minLatitude  = locationMy.Latitude;
                    minLongitude = locationMy.Longitude;
                    maxLatitude  = locationMy.Latitude;
                    maxLongitude = locationMy.Longitude;
                }

                foreach (Pin loc in locations)
                {
                    if (loc.Coordinates.Latitude < minLatitude)
                    {
                        minLatitude = loc.Coordinates.Latitude;
                    }
                    else if (loc.Coordinates.Latitude > maxLatitude)
                    {
                        maxLatitude = loc.Coordinates.Latitude;
                    }

                    if (loc.Coordinates.Longitude < minLongitude)
                    {
                        minLongitude = loc.Coordinates.Longitude;
                    }
                    else if (loc.Coordinates.Longitude > maxLongitude)
                    {
                        maxLongitude = loc.Coordinates.Longitude;
                    }
                }

                double width  = maxLongitude - minLongitude;
                double height = maxLatitude - minLatitude;
                var    center = new Bing.Maps.Location(0.5 * (maxLatitude + minLatitude), 0.5 * (maxLongitude + minLongitude));
                if (locationMy != null)
                {
                    center = locationMy;
                }
                boundingRect.Center = center;
                boundingRect.Width  = width + 0.005;
                boundingRect.Height = height + 0.005;
            }
            return(boundingRect);
        }
Beispiel #3
0
        async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            vm = new MainWindowVM();
            Container.DataContext = vm;

            if (helper.hasInternet(false))
            {
                await vm.setGeoLocation(MainMap.Center);
            }
            else
            {
                if (!App.askedInternetatStart)
                {
                    MessageDialog dialog = new MessageDialog("Rakendus vajab internetti.");
                    await dialog.ShowAsync();

                    App.Current.Exit();
                    return;
                }
            }

            if (App.ZoomLoc == null)
            {
                App.ZoomLoc = new ZoomedLocation();
            }
            else
            {
                MainMap.MapType = App.ZoomLoc.MapLookType;
                MainMap.SetView(MainMap.Center, MainMap.ZoomLevel);
                if (helper.hasInternet(false))
                {
                    vm.MyLocation = App.ZoomLoc.Loc;
                }
            }
            if (helper.hasInternet())
            {
                await vm.loadPins();

                Bing.Maps.LocationRect boundingRect = vm.GetLocationsRect(vm.Pushpins, vm.MyLocation);
                await Task.Delay(700);

                MainMap.SetView(boundingRect);
            }

            MainMap.ViewChangeEnded         += _map_ViewChangeEnded;
            MainMap.ViewChangeStarted       += _map_ViewChangeStarted;
            MainMap.PointerPressedOverride  += _map_PointerPressedOverride;
            MainMap.PointerMovedOverride    += _map_PointerMovedOverride;
            MainMap.PointerReleasedOverride += _map_PointerReleasedOverride;

            App.askedInternetatStart = true;
        }