コード例 #1
0
        public override Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            if (mode != NavigationMode.Back)
            {
                ExecuteLoadBusStops();
            }
            else
            {
                if (positions != null)
                {
                    MapArea = GeoboundingBox.TryCompute(positions);
                    if (MapArea != null)
                    {
                        Messenger.Default.Send <GeoboundingBoxMessage>(new GeoboundingBoxMessage(MapArea));
                    }
                }
            }
            Messenger.Default.Register <BusStopMessage>(this, (message) =>
            {
                Debug.WriteLine($"Bus stop selected: {message.Payload.Title} - {message.Payload.AtcoCode}");
                var parameters = new BusStopParameter(message.Payload.Title, message.Payload.AtcoCode);

                NavigationService.Navigate(typeof(BusStopDetailPage), parameters);
            });
            return(Task.CompletedTask);
        }
コード例 #2
0
        async private void OnPositionChanged(Geolocator sender, PositionChangedEventArgs e)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                AddPoint(e.Position);
                if (lapuerm != duom.Count && duom.Count > 1)
                {
                    var var1 = duom[lapuerm].X - duom[0].X;
                    for (double var3 = duom[lapuerm].Y - duom[0].Y; lapuerm < duom.Count - 1; lapuerm++)
                    {
                        double var5 = duom[lapuerm + 1].X - duom[0].X;
                        double var7 = duom[lapuerm + 1].Y - duom[0].Y;
                        distance   += Math.Sqrt((var5 - var1) * (var5 - var1) + (var7 - var3) * (var7 - var3));
                        if (this.lapuerm != 0)
                        {
                            area += ((var1 * var7 - var3 * var5) / 2);
                        }
                        var1 = var5;
                        var3 = var7;
                    }
                }
                UpdateData();
            });

            await MapCtrl.TrySetViewBoundsAsync(GeoboundingBox.TryCompute(geo), null, MapAnimationKind.Default);
        }
コード例 #3
0
        private async Task AddMapIcons()
        {
            MapControl.MapElements.Clear();
            if (_viewModel.Customers == null)
            {
                return;
            }

            foreach (var customer in _viewModel.Customers)
            {
                var mapIcon = new MapIcon
                {
                    Image = await RenderImageFlag.GetRandomAccessStreamReference(customer.Backround, customer.Foreground,
                                                                                 customer.Number.ToString(), customer.Multi, customer.AppointmentFlag, customer.IsPhoneCall, customer.VisitsCreateRecurringAppointments),
                    Location = new Geopoint(new BasicGeoposition {
                        Latitude = customer.Latitude, Longitude = customer.Longitude
                    }),
                    NormalizedAnchorPoint = new Point(0.1, 0.8)
                };
                MapControl.MapElements.Add(mapIcon);
            }

            GeoboundingBox geoboundingBox = GeoboundingBox.TryCompute(
                from MapElement m in MapControl.MapElements
                where m is MapIcon
                select((MapIcon)m).Location.Position);
            await MapControl.TrySetViewBoundsAsync(geoboundingBox, new Thickness(8), MapAnimationKind.Linear);
        }
コード例 #4
0
        /// <summary>
        /// This function performs re-routing of points
        /// </summary>
        private void PerformReroutingOfPoints()
        {
            // If we have less than 2 stops, we return here as we
            // have nothing to do - oh and to clear the routes of course
            Map.Routes.Clear();

            // Get list of all longitude and latitude values from our Stops
            List <BasicGeoposition> allLongitudesAndLatitudes = new List <BasicGeoposition>();

            foreach (var stop in Stops)
            {
                allLongitudesAndLatitudes.Add(new BasicGeoposition()
                {
                    Latitude  = decimal.ToDouble(stop.Latitude),
                    Longitude = decimal.ToDouble(stop.Longitude)
                });
            }

            // Call function to re-draw the route
            if (allLongitudesAndLatitudes.Count > 1)
            {
                ReDrawRoute(allLongitudesAndLatitudes);
            }
            else
            {
                // Try to compute the bounding box
                var boundingBox = GeoboundingBox.TryCompute(allLongitudesAndLatitudes);

                // Call async function to display all pushpins
                RetrieveBoundingBox(boundingBox);
            }
        }
コード例 #5
0
        private async void DrawPolyline(List <BasicGeoposition> geopositions)
        {
            ActivityMap.MapElements.Clear();

            if (geopositions.Any())
            {
                var polyLine = new MapPolyline {
                    Path = new Geopath(geopositions), StrokeThickness = 4, StrokeColor = (Color)App.Current.Resources["StravaRedColor"]
                };
                ActivityMap.MapElements.Add(polyLine);

                MapIcon startMapIcon = new MapIcon();
                startMapIcon.Location = new Geopoint(geopositions.First());
                startMapIcon.NormalizedAnchorPoint = new Point(0.5, 0.5);
                startMapIcon.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/Start.png"));
                ActivityMap.MapElements.Add(startMapIcon);

                MapIcon endMapIcon = new MapIcon();
                endMapIcon.Location = new Geopoint(geopositions.Last());
                endMapIcon.NormalizedAnchorPoint = new Point(0.5, 0.5);
                endMapIcon.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/End.png"));
                ActivityMap.MapElements.Add(endMapIcon);

                var zoomed = false;
                while (!zoomed)
                {
                    zoomed = await ActivityMap.TrySetViewBoundsAsync(GeoboundingBox.TryCompute(geopositions), null, MapAnimationKind.None);
                }
            }
        }
コード例 #6
0
        private async Task CreateBusStops(BasicGeoposition location)
        {
            positions = new List <BasicGeoposition>();
            NearbyBusStops.Clear();
            var youAreHere = new BusStop(
                location.Latitude, location.Longitude,
                "You are here!", "",
                RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/YouAreHere.png")));

            NearbyBusStops.Add(youAreHere);

            positions.Add(youAreHere.Point);

            using (var client = new TransportApiClient(ApiCredentials.appId, ApiCredentials.appKey))
            {
                var response = await client.BusStopsNear(location.Latitude, location.Longitude);

                if (response != null)
                {
                    foreach (var item in response.stops)
                    {
                        var point = new BusStop(item.latitude, item.longitude,
                                                item.name, item.atcocode,
                                                RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/BusPin.png")));
                        NearbyBusStops.Add(point);
                        positions.Add(point.Point);
                    }

                    MapArea = GeoboundingBox.TryCompute(positions);
                    Messenger.Default.Send <GeoboundingBoxMessage>(new GeoboundingBoxMessage(MapArea));
                }
            }
        }
コード例 #7
0
 private void StackPanel_Tapped(object sender, TappedRoutedEventArgs e)
 {
     isSomeAlarmSelected = true;
     e.Handled           = true;
     ZoomMap(
         GeoboundingBox.TryCompute(
             ((sender as FrameworkElement).DataContext as AlarmItemViewModel).Alarm.GetPointsForCirle()));
 }
コード例 #8
0
        private async Task <bool> SetViewBoundsAsync(List <BasicGeoposition> geopositions)
        {
            var    bounds    = GeoboundingBox.TryCompute(geopositions);
            double viewWidth = ApplicationView.GetForCurrentView().VisibleBounds.Width;
            var    margin    = new Thickness((viewWidth >= 500 ? 300 : 10), 10, 10, 10);

            return(await MyMap.TrySetViewBoundsAsync(bounds, margin, MapAnimationKind.Default));
        }
コード例 #9
0
        public async Task LoadTripAsync(Guid tripId, bool animateMap = true)
        {
            // As we need to have requested this permission for our background task, ask here
            await Geolocator.RequestAccessAsync();

            CurrentTrip = await _dataModelService.LoadTripAsync(tripId);

            Sights =
                new ObservableCollection <Sight>(
                    CurrentTrip.Sights.OrderBy(s => s.RankInDestination));

            BuildSightGroups();

            if (Map != null)
            {
                var boundingBox = GeoboundingBox.TryCompute(GetSightsPositions());
                if (animateMap)
                {
                    // Delay to allow the Map to finish loading - on faster machines, animation fails
                    await Task.Delay(500);

                    // We actually don't want to wait for the map to stop animating
                    // so we assign the task to a variable to remove the warning about await
                    var task = Map.TrySetViewBoundsAsync(boundingBox,
                                                         new Thickness {
                        Left = 48, Top = 48, Right = 48, Bottom = 48
                    },
                                                         MapAnimationKind.Bow);
                }
                else
                {
                    // We actually don't want to wait for the map to stop animating
                    // so we assign the task to a variable to remove the warning about await
                    var task = Map.TrySetViewBoundsAsync(boundingBox,
                                                         new Thickness {
                        Left = 48, Top = 48, Right = 48, Bottom = 48
                    },
                                                         MapAnimationKind.None);
                }
            }

            EatsControlViewModel = new EatsControlViewModel {
                CenterLocation = CurrentTrip.Location, Trip = CurrentTrip
            };
            try
            {
                EatsControlViewModel.IsLoadingEats = true;
                EatsControlViewModel.Eats          =
                    new ObservableCollection <Restaurant>(await RestaurantDataService.Current.GetRestaurantsForTripAsync(CurrentTrip));
            }
            finally
            {
                EatsControlViewModel.IsLoadingEats = false;
            }

            // Insert the M1_CreateTiles snippet here
        }
コード例 #10
0
        private async Task DrawPath(IList <BasicGeoposition> locations)
        {
            CompletedTripMap.MapServiceToken = Constants.BingMapsAPIKey;
            MapPolyline mapPolyLine = new MapPolyline();

            mapPolyLine.Path        = new Geopath(locations);
            mapPolyLine.ZIndex      = 1;
            mapPolyLine.Visible     = true;
            mapPolyLine.StrokeColor = new Color {
                A = 255, R = 94, G = 185, B = 255
            };
            mapPolyLine.StrokeThickness = 5;
            lines.Add(mapPolyLine);
            // Starting off with the first point as center
            if (locations.Count > 0)
            {
                CompletedTripMap.Center = new Geopoint(locations.First());
            }

            foreach (var polyline in lines)
            {
                CompletedTripMap.MapElements.Add(polyline);
            }
            //sumTripMap.MapElements.Add(mapPolyLine);

            // Draw Start Icon
            MapIcon mapStartIcon = new MapIcon
            {
                Location = new Geopoint(locations.First()),
                NormalizedAnchorPoint = new Point(0.5, 1.0),
                Image  = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/Icons/Start05.png")),
                ZIndex = 1,
            };

            CompletedTripMap.MapElements.Add(mapStartIcon);

            //Draw End Icon
            MapIcon mapEndIcon = new MapIcon
            {
                Location = new Geopoint(locations.Last()),
                NormalizedAnchorPoint = new Point(0.5, 1.0),
                Image  = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/Icons/End05.png")),
                ZIndex = 1,
            };

            CompletedTripMap.MapElements.Add(mapEndIcon);

            var boundingBox = GeoboundingBox.TryCompute(locations);
            // Delay to allow the Map to finish loading - on faster machines, animation fails
            await Task.Delay(500);

            await CompletedTripMap.TrySetViewBoundsAsync(boundingBox, new Thickness(0, 10, 0, 10), MapAnimationKind.Default);

            // Draw the Car
            //DrawCarOnMap(carLocations.First());
            await Task.CompletedTask;
        }
コード例 #11
0
        private async void ServicePoints_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            var positions = DataSource.ServicePoints.Select(el => el.Location.Position).ToList();

            positions.Add(DataSource.Kot.Location.Position);
            var box = GeoboundingBox.TryCompute(positions);

            SetCenterLocation(new Geopoint(box.Center));
            await Map.TrySetViewBoundsAsync(box, null, MapAnimationKind.Default);
        }
コード例 #12
0
ファイル: Scenario7.xaml.cs プロジェクト: ice0/test
        private async void myMap_Loaded(object sender, RoutedEventArgs e)
        {
            await LoadPlaceInfoAsync();

            // Zoom in to the level that shows all our points of interest.
            GeoboundingBox boundingBox = GeoboundingBox.TryCompute(places.Select(place => place.Location.Geoposition));
            await myMap.TrySetViewBoundsAsync(boundingBox, null, MapAnimationKind.None);

            refreshMapIcons();
        }
コード例 #13
0
        private void ViewModel_MapZoomChanged(object sender, MapZoomChangedEventArgs e)
        {
            boxToDisplay = GeoboundingBox.TryCompute(e.Data.Select(location =>
                                                                   new BasicGeoposition {
                Latitude = location.Item1, Longitude = location.Item2
            }));

            isSomeAlarmSelected = false;
            ZoomMap(boxToDisplay);
        }
コード例 #14
0
        /// <summary>
        /// adds a polyline on the map
        /// </summary>
        private async void AddLine()
        {
            var size = ViewModel.DestinationsList.Count;

            if (CurrentLine != null)
            {
                Map.Layers.Remove(CurrentLine);
            }
            if (size <= 1)
            {
                return;
            }
            var destArray = ViewModel.GetDestinationsAsArray();
            var coords    = new List <BasicGeoposition>();

            DrawPoints(destArray);
            for (var i = 0; i < destArray.Length; i++)
            {
                var dest = destArray[i];
                BasicGeoposition point = new BasicGeoposition()
                {
                    Latitude = dest.Latitude, Longitude = dest.Longitude
                };
                coords.Add(point);
            }

            Geopath path = new Geopath(coords);

            MapPolyline polygon = new MapPolyline();

            polygon.StrokeColor     = Colors.Blue;
            polygon.StrokeThickness = 5;
            polygon.Path            = path;
            polygon.StrokeDashed    = true;

            var MyLines = new List <MapElement>();

            MyLines.Add(polygon);
            var LinesLayer = new MapElementsLayer
            {
                ZIndex      = 1,
                MapElements = MyLines
            };

            if (CurrentLine != null)
            {
                Map.Layers.Remove(CurrentLine);
            }
            Map.Layers.Add(LinesLayer);
            this.CurrentLine = LinesLayer;
            await Map.TrySetViewBoundsAsync(GeoboundingBox.TryCompute(coords), null, MapAnimationKind.None);

            //Map.ZoomLevel = bingMap.ZoomLevel * 0.85
        }
コード例 #15
0
ファイル: OrderPage.xaml.cs プロジェクト: cjesp/29Lifts
        private async void DestinationChosen(Geopoint location, Geopoint destination)
        {
            var map = TheMap;

            var locations = new List <BasicGeoposition>();

            locations.Add(location.Position);
            locations.Add(destination.Position);
            var bounds = GeoboundingBox.TryCompute(locations);
            await map.TrySetViewBoundsAsync(bounds, new Thickness(10.0, 30.0, 10.0, (map.ActualHeight / 2.0) * 1.05), MapAnimationKind.Bow);
        }
コード例 #16
0
        private async void ZoomInAppBarButton_Click(object sender, RoutedEventArgs e)
        {
            if (this.pivot.SelectedIndex == 1)
            {
                List <BasicGeoposition> points = new List <BasicGeoposition>();
                foreach (SampleDataItem rscItem in ((SampleDataGroup)DefaultViewModel[SecondGroupName]).Items)
                {
                    points.Add(rscItem.Location.Position);
                }

                await this.map.TrySetViewBoundsAsync(GeoboundingBox.TryCompute(points), null, MapAnimationKind.Bow);
            }
        }
コード例 #17
0
        public async void AddRoute(bool p)
        {
            Map.Routes.Clear();
            Busy.IsActive = true;
            var routeResult = await MapSourceHandler.UpdatePhone(p);

            Busy.IsActive = false;
            if (!p)
            {
                return;
            }
            if (routeResult == null || routeResult.Status != MapRouteFinderStatus.Success)
            {
                var positions = new List <BasicGeoposition>();
                positions.Add(MapSourceHandler.Kot.Location.Position);
                positions.Add(MapSourceHandler.Phone.Location.Position);
                var box   = GeoboundingBox.TryCompute(positions);
                var kot   = MapSourceHandler.Kot.Location.Position;
                var phone = MapSourceHandler.Phone.Location.Position;
                var nw    = new BasicGeoposition
                {
                    Latitude  = Math.Max(kot.Latitude, phone.Latitude),
                    Longitude = Math.Min(kot.Longitude, phone.Longitude)
                };
                var se = new BasicGeoposition
                {
                    Latitude  = Math.Min(kot.Latitude, phone.Latitude),
                    Longitude = Math.Max(kot.Longitude, phone.Longitude)
                };

                await Map.TrySetViewBoundsAsync(
                    box//new GeoboundingBox(nw, se)
                    , null,
                    MapAnimationKind.Bow);

                return;
            }
            var viewOfRoute = new MapRouteView(routeResult.Route)
            {
                RouteColor   = Color.FromArgb(255, 233, 30, 99),
                OutlineColor = Colors.Transparent
            };

            Map.Routes.Add(viewOfRoute);
            await Map.TrySetViewBoundsAsync(
                routeResult.Route.BoundingBox,
                null,
                MapAnimationKind.Bow);
        }
コード例 #18
0
 private async Task ResetMapAsync()
 {
     if (ViewModel.MappedLocations.Count() == 1)
     {
         Map.Center    = ViewModel.MappedLocations[0].Geopoint;
         Map.ZoomLevel = 12;
     }
     else if (ViewModel.MappedLocations.Any())
     {
         var bounds = GeoboundingBox.TryCompute(
             ViewModel.MappedLocations.Select(location => location.Geopoint.Position));
         var margin = new Thickness(40, 40, 40, 40);
         await Map.TrySetViewBoundsAsync(bounds, margin, MapAnimationKind.Default);
     }
     mapDefaultZoomLevel = Map.ZoomLevel;
 }
コード例 #19
0
        /// <summary>
        /// Updates the UI to account for the user's current position, if available,
        /// resetting the MapControl bounds and refreshing the travel info.
        /// </summary>
        /// <param name="isGeolocatorReady">false if the Geolocator is known to be unavailable; otherwise, true.</param>
        /// <returns></returns>
        private async Task ResetViewAsync(bool isGeolocatorReady = true)
        {
            LocationData currentLocation = null;

            if (isGeolocatorReady)
            {
                currentLocation = await this.GetCurrentLocationAsync();
            }
            if (currentLocation != null)
            {
                if (this.MappedLocations.Count > 0 && this.MappedLocations[0].IsCurrentLocation)
                {
                    this.MappedLocations.RemoveAt(0);
                }
                this.MappedLocations.Insert(0, new LocationData {
                    Position = currentLocation.Position, IsCurrentLocation = true
                });
            }

            // Set the current view of the map control.
            var positions = this.Locations.Select(loc => loc.Position).ToList();

            if (currentLocation != null)
            {
                positions.Insert(0, currentLocation.Position);
            }
            var    bounds       = GeoboundingBox.TryCompute(positions);
            double viewWidth    = ApplicationView.GetForCurrentView().VisibleBounds.Width;
            var    margin       = new Thickness((viewWidth >= 500 ? 300 : 10), 10, 10, 10);
            bool   isSuccessful = await this.InputMap.TrySetViewBoundsAsync(bounds, margin, MapAnimationKind.Default);

            if (isSuccessful && positions.Count < 2)
            {
                this.InputMap.ZoomLevel = 12;
            }
            else if (!isSuccessful && positions.Count > 0)
            {
                this.InputMap.Center    = new Geopoint(positions[0]);
                this.InputMap.ZoomLevel = 12;
            }
            if (currentLocation != null)
            {
                await this.TryUpdateLocationsTravelInfoAsync(this.Locations, currentLocation);
            }
        }
コード例 #20
0
        private async void UpdateMapElements()
        {
            await MapSourceHandler.GetMapElements();

            if (MapSourceHandler.ServicePoints.Count == 0)
            {
                SetCenterLocation(MapSourceHandler.Kot.Location);
                return;
            }
            var positions = MapSourceHandler.ServicePoints.Select(el => el.Location.Position).ToList();

            positions.Add(MapSourceHandler.Kot.Location.Position);
            var box = GeoboundingBox.TryCompute(positions);

            await Map.TrySetViewBoundsAsync(box, null, MapAnimationKind.Default);

            SetCenterLocation(new Geopoint(box.Center));
        }
コード例 #21
0
        private async void ZoomToFitAllNotePins()
        {
            if (Notes == null)
            {
                return;
            }

            var basicGeopositions = Notes.Where(note => note.CreationLocation.IsValid)
                                    .Select(note => new BasicGeoposition
            {
                Latitude  = note.CreationLocation.Latitude,
                Longitude = note.CreationLocation.Longitude,
            });

            var box = GeoboundingBox.TryCompute(basicGeopositions);

            await MapControl.TrySetViewBoundsAsync(box, new Thickness(70), MapAnimationKind.None);
        }
コード例 #22
0
        private async Task DrawPolyline(List <BasicGeoposition> geopositions)
        {
            SegmentMap.MapElements.Clear();

            if (geopositions.Any())
            {
                if (ExpandMapButton == null)
                {
                    FindName("ExpandMapButton");
                }
                else
                {
                    ExpandMapButton.Visibility = Visibility.Visible;
                }

                var polyLine = new MapPolyline {
                    Path = new Geopath(geopositions), StrokeThickness = 4, StrokeColor = (Color)App.Current.Resources["StravaRedColor"]
                };
                SegmentMap.MapElements.Add(polyLine);

                MapIcon startMapIcon = new MapIcon();
                startMapIcon.Location = new Geopoint(geopositions.First());
                startMapIcon.NormalizedAnchorPoint = new Point(0.5, 0.5);
                startMapIcon.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/Start.png"));
                SegmentMap.MapElements.Add(startMapIcon);

                MapIcon endMapIcon = new MapIcon();
                endMapIcon.Location = new Geopoint(geopositions.Last());
                endMapIcon.NormalizedAnchorPoint = new Point(0.5, 0.5);
                endMapIcon.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/End.png"));
                SegmentMap.MapElements.Add(endMapIcon);

                var zoomed = false;
                while (!zoomed)
                {
                    zoomed = await SegmentMap.TrySetViewBoundsAsync(GeoboundingBox.TryCompute(geopositions), null, MapAnimationKind.None);
                }
            }
            else
            if (ExpandMapButton != null)
            {
                ExpandMapButton.Visibility = Visibility.Collapsed;
            }
        }
コード例 #23
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            Message.ShowMessage(new Message()
            {
                ShortSummary = "Not every trip serves every stop.", Caption = "Route Map Warning", FullText = "The path shown on the map is every path driven by this route in any circumstance. While sometimes every trip serves every stop, often times trips terminate earlier than others. Also, some routes have special extended trips that aren't normally served by the route, and this map shows all of them. A future update will allow you to more easily see which trips serve which stops.", Id = 4
            });
            MainMap.Background = new SolidColorBrush(Colors.Black);
            if (e.Parameter is string)
            {
                Route = (await Data.GetRoute(e.Parameter.ToString(), MasterCancellationTokenSource.Token)).Value;
                RouteNameBlock.Text = (char.IsNumber(Route.Name.FirstOrDefault()) ? "Route " : "") + Route.Name;
                var stopInfo = await Data.GetStopsAndShapesForRoute(Route.ID, new DataRetrievalOptions(DataSourceDescriptor.Local), MasterCancellationTokenSource.Token);

                if (stopInfo.Item2.FinalSource != null)
                {
                    foreach (var stop in stopInfo.Item1.Item1)
                    {
                        MainMap.ShownStops.Add(stop);
                    }
                    List <BasicGeoposition> allPoints = new List <BasicGeoposition>();
                    foreach (var shape in stopInfo.Item1.Item2)
                    {
                        var points = HelperFunctions.DecodeShape(shape);
                        MainMap.MapControl.MapElements.Add(new MapPolyline()
                        {
                            Path = new Windows.Devices.Geolocation.Geopath(points), StrokeColor = (Color)App.Current.Resources["SystemColorControlAccentColor"], StrokeThickness = 4, ZIndex = 0
                        });
                        allPoints.AddRange(points);
                    }
                    if (allPoints.Count > 0)
                    {
                        GeoboundingBox box = GeoboundingBox.TryCompute(allPoints);

                        await MainMap.MapControl.TrySetViewBoundsAsync(box, new Thickness(0), MapAnimationKind.Bow);
                    }
                }
                else
                {
                    await new MessageDialog("We could not download the data for the selected route, and you don't have that route downloaded.", "Error getting route").ShowAsync();
                }
            }
        }
コード例 #24
0
        private async Task setViewOnMap(List <BasicGeoposition> positions)
        {
            if (positions.Count == 0)
            {
                return;
            }
            var    bounds       = GeoboundingBox.TryCompute(positions);
            double viewWidth    = ApplicationView.GetForCurrentView().VisibleBounds.Width;
            var    margin       = new Thickness((viewWidth >= 500 ? 300 : 10), 10, 10, 10);
            bool   isSuccessful = await this.InputMap.TrySetViewBoundsAsync(bounds, margin, MapAnimationKind.Default);

            if (isSuccessful && positions.Count < 2)
            {
                this.InputMap.ZoomLevel = 15;
            }
            else if (!isSuccessful && positions.Count > 0)
            {
                this.InputMap.Center    = new Geopoint(positions[0]);
                this.InputMap.ZoomLevel = 15;
            }
        }
コード例 #25
0
ファイル: MainViewModel.cs プロジェクト: lulzzz/FlySimExpress
        public async Task <bool> BringPlanesIntoViewAsync(MapControl map)
        {
            var activePlaneLocations = this.ActivePlanes.Where(w => w.Status != Common.FlightStatus.Inactive).Select(s => s.Location).ToList();

            if (activePlaneLocations.Count == 1)
            {
                return(await map.TrySetViewAsync(activePlaneLocations[0], 13));
            }
            else if (activePlaneLocations.Count > 1)
            {
                activePlaneLocations.Add(new Geopoint(Common.CoreConstants.DefaultStartingLocation));

                var boundingBox = GeoboundingBox.TryCompute(activePlaneLocations.Select(s => s.Position));

                return(await map.TrySetViewBoundsAsync(boundingBox, new Windows.UI.Xaml.Thickness(5), MapAnimationKind.Bow));
            }
            else
            {
                return(false);
            }
        }
コード例 #26
0
        private async void TryCenterMap()
        {
            if (this.ViewModel.Centre == null)
            {
                return;
            }

            var centrePoint = new Geopoint(
                new BasicGeoposition
            {
                Latitude  = this.ViewModel.Centre.Latitude,
                Longitude = this.ViewModel.Centre.Longitude
            });

            if (!this.hasMapLoaded)
            {
                // the map has not loaded, so setting view doesn't work well.
                // just update the centre so that when it loads it will load here.
                this.Map.Center = centrePoint;
                return;
            }

            if (this.ViewModel.NearbyCafes.Any())
            {
                var points = this.ViewModel
                             .NearbyCafes
                             .Select(cafe => new BasicGeoposition {
                    Latitude = cafe.Latitude, Longitude = cafe.Longitude
                })
                             .ToList();
                points.Add(centrePoint.Position);

                var box = GeoboundingBox.TryCompute(points);
                await this.Map.TrySetViewBoundsAsync(box, null, MapAnimationKind.Bow);
            }
            else
            {
                await this.Map.TrySetViewAsync(centrePoint, null, null, null, MapAnimationKind.Linear);
            }
        }
コード例 #27
0
        private async void AddMapElements_Projects(bool centerOnTarget)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
            {
                Coordinates     = new List <Windows.Devices.Geolocation.BasicGeoposition>();
                var zindex      = 1000;
                var strokeColor = ColorHandler.FromHex(Project.FillColor);
                var mapProjects = new List <MapElement>();

                Coordinates.AddRange(GeoPositionConversor.Parse(Project.Coordinates));

                var mapPolygon = new MapPolygon
                {
                    Tag             = Project.Name,
                    Path            = new Geopath(Coordinates),
                    ZIndex          = zindex,
                    FillColor       = FillColor,
                    StrokeColor     = strokeColor,
                    StrokeThickness = 3,
                    StrokeDashed    = false,
                };

                mapProjects.Add(mapPolygon);


                var mapProjectsLayer = new MapElementsLayer
                {
                    ZIndex      = zindex,
                    MapElements = mapProjects
                };

                MapLayers.Add(mapProjectsLayer);
                CTRL_Map_Main.Layers.Add(mapProjectsLayer);
            });

            if (centerOnTarget)
            {
                await CTRL_Map_Main.TrySetViewBoundsAsync(GeoboundingBox.TryCompute(Coordinates), new Thickness(200), MapAnimationKind.Bow);
            }
        }
コード例 #28
0
ファイル: RidePage.xaml.cs プロジェクト: cjesp/29Lifts
        private async void UpdateMap(Geopoint location, Geopoint destination)
        {
            var map = TheMap;

            var locations = new List <BasicGeoposition>();

            if (location.Position.Latitude == destination.Position.Latitude &&
                location.Position.Longitude == destination.Position.Longitude)
            {
                // hack to circumvent cases where position are the same
                locations.Add(RemoveAltitude(location));
                locations.Add(new BasicGeoposition()
                {
                    Latitude  = location.Position.Latitude - 0.000000001,
                    Longitude = location.Position.Longitude - 0.0002
                });
            }
            else
            {
                locations.Add(RemoveAltitude(location));
                locations.Add(RemoveAltitude(destination));
            }

            var  bounds = GeoboundingBox.TryCompute(locations);
            bool result = false;

            if (map.LoadingStatus == MapLoadingStatus.Loading || map.LoadingStatus == MapLoadingStatus.DataUnavailable)
            {
                while (map.LoadingStatus == MapLoadingStatus.Loading || map.LoadingStatus == MapLoadingStatus.DataUnavailable)
                {
                    await Task.Delay(50);
                }
                result = await map.TrySetViewBoundsAsync(bounds, new Thickness(10.0, 30.0, 10.0, (map.ActualHeight / 2.0) * 1.05), MapAnimationKind.Bow);
            }
            else
            {
                result = await map.TrySetViewBoundsAsync(bounds, new Thickness(10.0, 30.0, 10.0, (map.ActualHeight / 2.0) * 1.05), MapAnimationKind.Bow);
            }
        }
コード例 #29
0
        private async void MapLoadingStatusChanged(MapControl map, object args)
        {
            if (map.LoadingStatus != MapLoadingStatus.Loaded)
            {
                return;
            }
            if (map.Tag != null)
            {
                return;
            }

            MapControl.SetLocation(map.Children.First(), new Geopoint(new BasicGeoposition {
                Latitude = 63.349129, Longitude = 10.484762
            }));

            var mapPolyline = new MapPolyline
            {
                Path = new Geopath(new List <BasicGeoposition>
                {
                    new BasicGeoposition {
                        Latitude = 63.418336, Longitude = 10.403534
                    },
                    new BasicGeoposition {
                        Latitude = 63.349129, Longitude = 10.484762
                    }
                }),
                StrokeColor     = Colors.Black,
                StrokeThickness = 3,
                StrokeDashed    = true
            };

            var bbox = GeoboundingBox.TryCompute(mapPolyline.Path.Positions);

            map.MapElements.Add(mapPolyline);
            var r = await map.TrySetViewBoundsAsync(bbox, null, MapAnimationKind.Default);

            map.Tag = true;
        }
コード例 #30
0
ファイル: XaMapRenderer.cs プロジェクト: AlexPshul/XaMaps
        private void ShowRouteOverview()
        {
            Control.MapElements.Clear();

            BasicGeoposition[] allRoutePoints = _xamap.SelectedRoute.Legs
                                                .SelectMany(leg => leg.Points)
                                                .Select(point => new BasicGeoposition {
                Latitude = point.Latitude, Longitude = point.Longitude
            })
                                                .ToArray();

            MapPolyline routeLine = new MapPolyline
            {
                Path            = new Geopath(allRoutePoints),
                StrokeColor     = Colors.Blue,
                StrokeThickness = 7
            };

            Control.MapElements.Add(routeLine);

            GeoboundingBox routeBounds     = GeoboundingBox.TryCompute(allRoutePoints);
            var            trySetViewAsync = Control.TrySetViewBoundsAsync(routeBounds, new Thickness(50d), MapAnimationKind.Bow);
        }