private GeoboundingBox CreateBoundingBoxFromCoordiateSet(List <Geopoint> coordinateSet) { var first = coordinateSet.First(); var northWestCorner = new BasicGeoposition(); var southEastCorner = new BasicGeoposition(); for (int i = 1; i < coordinateSet.Count; i++) { var coordinate = coordinateSet[i]; if (coordinate.Position.Latitude > northWestCorner.Latitude) { northWestCorner.Latitude = coordinate.Position.Latitude; } if (coordinate.Position.Latitude < southEastCorner.Latitude) { southEastCorner.Latitude = coordinate.Position.Latitude; } if (coordinate.Position.Longitude < northWestCorner.Longitude) { northWestCorner.Longitude = coordinate.Position.Longitude; } if (coordinate.Position.Longitude > southEastCorner.Longitude) { southEastCorner.Longitude = coordinate.Position.Longitude; } } var box = new GeoboundingBox(northWestCorner, southEastCorner); return(box); }
public static async Task<BusStop[]> GetBusStopsForArea(GeoboundingBox bounds, Action<BusStop[], GeoboundingBox> stopsLoadedCallback, CancellationToken cancellationToken) { List<BusStop> totalFoundStops = new List<BusStop>(); double latRange = bounds.NorthwestCorner.Latitude - bounds.SoutheastCorner.Latitude; double lonRange = bounds.SoutheastCorner.Longitude - bounds.NorthwestCorner.Longitude; int latPieces = (int)Math.Ceiling(latRange / MAX_LAT_RANGE); int lonPieces = (int)Math.Ceiling(lonRange / MAX_LON_RANGE); double smallLatRange = latRange / (double)latPieces; double smallLonRange = lonRange / (double)lonPieces; for (int i = 0; i < latPieces; i++) { for (int j = 0; j < lonPieces; j++) { BusStop[] foundStops = await ApiLayer.GetBusStops(new BasicGeoposition() { Latitude = bounds.SoutheastCorner.Latitude + (i + .5) * smallLatRange, Longitude = bounds.NorthwestCorner.Longitude + (j + .5) * smallLonRange }, smallLatRange, smallLonRange, cancellationToken); foreach (var item in foundStops) { totalFoundStops.Add(item); if (!CachedStops.ContainsKey(item.Code)) CachedStops.Add(item.Code, item); } if (stopsLoadedCallback != null) { stopsLoadedCallback(foundStops, null); } } } return totalFoundStops.ToArray(); }
/// <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); } }
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); }
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); }
//less-good replacement for pre-AU machines //doesn't handle rotated maps. maybe an issue? Maybe just disable rotation anywhere we use this... private GeoboundingBox GetBounds() { if (DigiTransitMapControl.Center.Position.Latitude == 0) { return(default(GeoboundingBox)); } double degreePerPixel = (156543.04 * Math.Cos(DigiTransitMapControl.Center.Position.Latitude * Math.PI / 180)) / (111325 * Math.Pow(2, DigiTransitMapControl.ZoomLevel)); double mHalfWidthInDegrees = DigiTransitMapControl.ActualWidth * degreePerPixel / 0.9; double mHalfHeightInDegrees = DigiTransitMapControl.ActualHeight * degreePerPixel / 1.7; double mNorth = DigiTransitMapControl.Center.Position.Latitude + mHalfHeightInDegrees; double mWest = DigiTransitMapControl.Center.Position.Longitude - mHalfWidthInDegrees; double mSouth = DigiTransitMapControl.Center.Position.Latitude - mHalfHeightInDegrees; double mEast = DigiTransitMapControl.Center.Position.Longitude + mHalfWidthInDegrees; GeoboundingBox mBounds = new GeoboundingBox( new BasicGeoposition() { Latitude = mNorth, Longitude = mWest }, new BasicGeoposition() { Latitude = mSouth, Longitude = mEast }); return(mBounds); }
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); } } }
private bool canBeViewed(Geopoint point, GeoboundingBox rect) { bool longInside = point.Position.Longitude > rect.NorthwestCorner.Longitude && point.Position.Longitude < rect.SoutheastCorner.Longitude; bool latInside = point.Position.Latitude > rect.SoutheastCorner.Latitude && point.Position.Latitude < rect.NorthwestCorner.Latitude; return(longInside && latInside); }
public static async Task <BusStop[]> GetStopsForArea(BasicGeoposition topLeft, BasicGeoposition bottomRight, CancellationToken cancellationToken) { List <int> hashes = new List <int>(); GeoboundingBox box = new GeoboundingBox(topLeft, bottomRight); Rect intersection = box.ToRect(); intersection.Intersect(DowntownSeattleZone.ToRect()); if (intersection.Width > 0 && intersection.Height > 0) { hashes.Add(16); } if (intersection != box.ToRect()) { double minLat = bottomRight.Latitude; double minLon = topLeft.Longitude; double maxLat = topLeft.Latitude; double maxLon = bottomRight.Longitude; for (double lat = minLat; lat < maxLat + 0.1; lat += 0.1) { if (lat > maxLat) { lat = maxLat; } for (double lon = minLon; lon < maxLon + 0.2; lon += 0.2) { if (lon > maxLon) { lon = maxLon; } int hash = HashLocation(lat, lon); if (!hashes.Contains(hash)) { hashes.Add(hash); } } } } cancellationToken.ThrowIfCancellationRequested(); List <BusStop> result = new List <BusStop>(); foreach (var hash in hashes) { await AccessStopCache(hash, delegate(List <BusStop> stops) { foreach (var stop in stops) { if (box.ContainsPoint(stop.Position) && !result.Contains(stop)) { result.Add(stop); } } return(false); }); cancellationToken.ThrowIfCancellationRequested(); } return(result.ToArray()); }
public static bool Contains(Geopoint location, GeoboundingBox geoBox) { return(location.Position.Longitude >= geoBox.NorthwestCorner.Longitude && location.Position.Longitude <= geoBox.SoutheastCorner.Longitude && location.Position.Latitude <= geoBox.NorthwestCorner.Latitude && location.Position.Latitude >= geoBox.SoutheastCorner.Latitude); }
async Task UpdateVisibleRegion() { if (Control == null || Element == null) { return; } if (!_firstZoomLevelChangeFired) { await MoveToRegion(Element.LastMoveToRegion, MapAnimationKind.None); _firstZoomLevelChangeFired = true; return; } Geopoint nw, se = null; try { Control.GetLocationFromOffset(new Windows.Foundation.Point(0, 0), out nw); Control.GetLocationFromOffset(new Windows.Foundation.Point(Control.ActualWidth, Control.ActualHeight), out se); } catch (Exception) { return; } if (nw != null && se != null) { var boundingBox = new GeoboundingBox(nw.Position, se.Position); var center = new Position(boundingBox.Center.Latitude, boundingBox.Center.Longitude); var latitudeDelta = Math.Abs(center.Latitude - boundingBox.NorthwestCorner.Latitude); var longitudeDelta = Math.Abs(center.Longitude - boundingBox.NorthwestCorner.Longitude); Element.VisibleRegion = new MapSpan(center, latitudeDelta, longitudeDelta); } }
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); }
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)); } } }
public static bool Contains(this GeoboundingBox _this, Geopoint point) { bool longInside = point.Position.Longitude > _this.NorthwestCorner.Longitude && point.Position.Longitude < _this.SoutheastCorner.Longitude; bool latInside = point.Position.Latitude > _this.SoutheastCorner.Latitude && point.Position.Latitude < _this.NorthwestCorner.Latitude; return(longInside && latInside); }
async Task UpdateVisibleRegion() { if (Control == null || Element == null) { return; } try { Geopoint nw, se = null; Control.GetLocationFromOffset(new Windows.Foundation.Point(0, 0), out nw); Control.GetLocationFromOffset(new Windows.Foundation.Point(Control.ActualWidth, Control.ActualHeight), out se); if (nw != null && se != null) { var boundingBox = new GeoboundingBox(nw.Position, se.Position); var center = new Position(boundingBox.Center.Latitude, boundingBox.Center.Longitude); var latitudeDelta = Math.Abs(nw.Position.Latitude - se.Position.Latitude); var longitudeDelta = Math.Abs(nw.Position.Longitude - se.Position.Longitude); await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { Element.SetVisibleRegion(new MapSpan(center, latitudeDelta, longitudeDelta)); }); } } catch (Exception) { return; } }
public static async Task <BusStop[]> GetBusStopsForArea(GeoboundingBox bounds, Action <BusStop[], GeoboundingBox> stopsLoadedCallback, CancellationToken cancellationToken, bool offlineOnly) { List <BusStop> totalFoundStops = new List <BusStop>(); try { var offlineStops = await FileManager.GetStopsForArea(bounds.NorthwestCorner, bounds.SoutheastCorner, cancellationToken); totalFoundStops.AddRange(offlineStops); foreach (var stop in offlineStops) { if (!CachedStops.ContainsKey(stop.ID)) { CachedStops.Add(stop.ID, stop); } } if (stopsLoadedCallback != null) { stopsLoadedCallback(offlineStops, null); } cancellationToken.ThrowIfCancellationRequested(); if (!offlineOnly) { double latRange = bounds.NorthwestCorner.Latitude - bounds.SoutheastCorner.Latitude; double lonRange = bounds.SoutheastCorner.Longitude - bounds.NorthwestCorner.Longitude; int latPieces = (int)Math.Ceiling(latRange / MAX_LAT_RANGE); int lonPieces = (int)Math.Ceiling(lonRange / MAX_LON_RANGE); double smallLatRange = latRange / (double)latPieces; double smallLonRange = lonRange / (double)lonPieces; for (int i = 0; i < latPieces; i++) { for (int j = 0; j < lonPieces; j++) { BusStop[] foundStops = await ApiLayer.GetBusStopsForArea(new BasicGeoposition() { Latitude = bounds.SoutheastCorner.Latitude + (i + .5) * smallLatRange, Longitude = bounds.NorthwestCorner.Longitude + (j + .5) * smallLonRange }, smallLatRange, smallLonRange, cancellationToken); foreach (var item in foundStops ?? new BusStop[0]) { if (!totalFoundStops.Contains(item)) { totalFoundStops.Add(item); } if (!CachedStops.ContainsKey(item.ID)) { CachedStops.Add(item.ID, item); } } if (stopsLoadedCallback != null) { stopsLoadedCallback(foundStops, null); } } } } } catch (OperationCanceledException) { } return(totalFoundStops.ToArray()); }
private async void ZoomMap(GeoboundingBox box) { if (box != null) { await Map.TrySetViewBoundsAsync(box, null, MapAnimationKind.Default); } }
/// <summary> /// Converts a GeoboundingBox into a BoundingBox object. /// </summary> /// <param name="locationRect">A Bing Maps GeoboundingBox object</param> /// <returns>A BoundingBox representation of the GeoboundingBox object</returns> public static BoundingBox ToGeometry(this GeoboundingBox locationRect) { var topLeft = locationRect.NorthwestCorner; var bottomRight = locationRect.SoutheastCorner; return(new BoundingBox(topLeft.Longitude, topLeft.Latitude, bottomRight.Longitude, bottomRight.Latitude)); }
void UpdateVisibleRegion() { if (Control == null || Element == null) { return; } try { Geopoint nw, se = null; Control.GetLocationFromOffset(new Windows.Foundation.Point(0, 0), out nw); Control.GetLocationFromOffset(new Windows.Foundation.Point(Control.ActualWidth, Control.ActualHeight), out se); if (nw != null && se != null) { var boundingBox = new GeoboundingBox(nw.Position, se.Position); var center = new Position(boundingBox.Center.Latitude, boundingBox.Center.Longitude); var latitudeDelta = Math.Abs(nw.Position.Latitude - se.Position.Latitude); var longitudeDelta = Math.Abs(nw.Position.Longitude - se.Position.Longitude); Element.VisibleRegion = new MapSpan(center, latitudeDelta, longitudeDelta); } } catch (Exception) { return; } }
private async void MainMap_ActualCameraChanged(MapControl sender, MapActualCameraChangedEventArgs args) { GeoboundingBox bounds; try { var downloader = new Windows.Networking.BackgroundTransfer.BackgroundDownloader(); bounds = new GeoboundingBox(MainMap.TopLeft, MainMap.BottomRight); } catch (Exception) { return; } long lm = DateTime.Now.Ticks; LastMove = lm; await Task.Delay(50); if (LastMove == lm) { if (MainMap.ZoomLevel < MainMap.StopVisibilityThreshold) { return; } try { AddStopsInBounds(bounds, false); } catch (TaskCanceledException) { } } }
public void SetViewRegion(GeoboundingBox bounds) { if (BoundingBox != bounds) { BoundingBox = bounds; ResetObjectsInView(); } }
private void StackPanel_Tapped(object sender, TappedRoutedEventArgs e) { isSomeAlarmSelected = true; e.Handled = true; ZoomMap( GeoboundingBox.TryCompute( ((sender as FrameworkElement).DataContext as AlarmItemViewModel).Alarm.GetPointsForCirle())); }
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)); }
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); }
async Task UpdateVisibleRegion() { if (Control == null || Element == null) { return; } if (!_firstZoomLevelChangeFired) { await MoveToRegion(Element.LastMoveToRegion, MapAnimationKind.None); _firstZoomLevelChangeFired = true; return; } Geopoint nw, ne, sw, se = null; try { Control.GetLocationFromOffset(new Windows.Foundation.Point(0, 0), out nw); Control.GetLocationFromOffset(new Windows.Foundation.Point(Control.ActualWidth, 0), out ne); Control.GetLocationFromOffset(new Windows.Foundation.Point(0, Control.ActualHeight), out sw); Control.GetLocationFromOffset(new Windows.Foundation.Point(Control.ActualWidth, Control.ActualHeight), out se); } catch (Exception) { return; } if ((nw != null) && (ne != null) && (sw != null) && (se != null)) { // Get the four edge coordinates var west = Math.Min( Math.Min(nw.Position.Longitude, ne.Position.Longitude), Math.Min(sw.Position.Longitude, se.Position.Longitude)); var east = Math.Max( Math.Max(nw.Position.Longitude, ne.Position.Longitude), Math.Max(sw.Position.Longitude, se.Position.Longitude)); var south = Math.Min( Math.Min(nw.Position.Latitude, ne.Position.Latitude), Math.Min(sw.Position.Latitude, se.Position.Latitude)); var north = Math.Max( Math.Max(nw.Position.Latitude, ne.Position.Latitude), Math.Max(sw.Position.Latitude, se.Position.Latitude)); var realNW = new BasicGeoposition { Latitude = north, Longitude = west }; var realSE = new BasicGeoposition { Latitude = south, Longitude = east }; // Recalculate the visible region var boundingBox = new GeoboundingBox(realNW, realSE); var center = new Position(boundingBox.Center.Latitude, boundingBox.Center.Longitude); var latitudeDelta = Math.Abs(center.Latitude - boundingBox.NorthwestCorner.Latitude); var longitudeDelta = Math.Abs(center.Longitude - boundingBox.NorthwestCorner.Longitude); Element.VisibleRegion = new MapSpan(center, latitudeDelta, longitudeDelta); } }
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; }
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 }
private void SearchLineSelectionChanged(MessageTypes.SearchLineSelectionChanged _) { GeoboundingBox lineBox = PageMap.GetAllMapElementsBoundingBox(); var mapMargin = AdaptiveVisualStateGroup.CurrentState == _narrowVisualState ? new Thickness(0, 0, 0, (this.NarrowSearchPanel.ExpandedHeight) + 0) : new Thickness(410, 10, 10, 10); PageMap.TrySetViewBoundsAsync(lineBox, mapMargin, MapAnimationKind.Linear).DoNotAwait(); }
public async Task UpdateGrid() { IEnumerable <InfoLocal> info = await new LocalService().GetEditedLocalInfos(SelectedHousing); if (info != null) { InfoLocal infoLoc = info.First(); MapControl newMap = new MapControl(); newMap.ZoomLevel = 15; newMap.Height = 350; newMap.MapServiceToken = "d3ogHQxrDviYWT4rgWNQ~2O1SHY9XpbCwof0N7rR2Yg~Ahe26ctwSO5twYSRpsM_5DGl6vWDkrLp1nCBqyE6oAuVF0Bb-oyDCW9ZmnIV_7rm"; infoLoc.location_lon -= 180; infoLoc.northeast_lon -= 180; infoLoc.southwest_lon -= 180; BasicGeoposition GeoPos_NorthWest = new BasicGeoposition() { Latitude = infoLoc.northeast_lat + 0.05, Longitude = infoLoc.northeast_lon + 0.1 }; BasicGeoposition GeoPos_SouthEast = new BasicGeoposition() { Latitude = infoLoc.southwest_lat - 0.05, Longitude = infoLoc.southwest_lon - 0.1 }; MapIcon Icon_HousingLocation = new MapIcon() { Location = new Geopoint(new BasicGeoposition() { Latitude = infoLoc.location_lat, Longitude = (infoLoc.location_lon - 180) }), NormalizedAnchorPoint = new Windows.Foundation.Point(0.5, 0.5), ZIndex = 0 }; Icon_HousingLocation.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/mapicon.png")); newMap.MapElements.Add(Icon_HousingLocation); try { Geolocator myGeolocator = new Geolocator(); Geoposition myGeoposition = await myGeolocator.GetGeopositionAsync(); MapIcon Icon_UserLocation = new MapIcon() { Location = new Geopoint(new BasicGeoposition() { Latitude = myGeoposition.Coordinate.Latitude, Longitude = myGeoposition.Coordinate.Longitude }), NormalizedAnchorPoint = new Windows.Foundation.Point(0.5, 0.5), ZIndex = 0 }; Icon_UserLocation.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/user_map.png")); newMap.MapElements.Add(Icon_UserLocation); } catch (Exception ex) { } GeoboundingBox mapBox = new GeoboundingBox(GeoPos_NorthWest, GeoPos_SouthEast); newMap.Center = new Geopoint(mapBox.Center); pageGrid.Children.Add(newMap); } }
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(); }
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); }
public static GeoboundingBox Intersect(this GeoboundingBox bound1, params GeoboundingBox[] boundn) { Rect result = bound1.ToRect(); foreach (GeoboundingBox bound in boundn) { result.Intersect(bound.ToRect()); } return(result.ToGeoboundingBox()); }
public ZoomMapToBoundsMessage(GeoboundingBox bbox) { BoundingBox = bbox; }
private void RefreshButton_Click(object sender, RoutedEventArgs e) { var bounds = new GeoboundingBox(MainMap.TopLeft, MainMap.BottomRight); try { AddStopsInBounds(bounds, true); } catch (TaskCanceledException) { } }
private async void ZoomMap(GeoboundingBox box) { if (box != null) await Map.TrySetViewBoundsAsync(box, null, MapAnimationKind.Default); }
public void ShowArea() { Area = new GeoboundingBox( new BasicGeoposition { Latitude = 52.1848798915744, Longitude = 5.39574773982167 }, new BasicGeoposition { Latitude = 52.1779848542064, Longitude = 5.40379419922829 }); }
public static bool Contains(Geopoint location, GeoboundingBox geoBox) { return (location.Position.Longitude >= geoBox.NorthwestCorner.Longitude && location.Position.Longitude <= geoBox.SoutheastCorner.Longitude && location.Position.Latitude <= geoBox.NorthwestCorner.Latitude && location.Position.Latitude >= geoBox.SoutheastCorner.Latitude); }
public MainPage() { InitializeComponent(); if (ResponsiveStateGroup.CurrentState == desktopViewVisualState) { //this should use "-1 * CoreApplication.GetCurrentView().TitleBar.Height" but it returns 0 at this point :( SetMapBottomMargin(-32); } NavigationCacheMode = NavigationCacheMode.Required; CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true; Map.Loaded += async (sender, args) => { SetMapBottomMargin(0); Debug.WriteLine("[MainView] map: map loaded"); if (_initialMapBbox != null) { Debug.WriteLine("[MainView] map: map loaded, set initial bounds"); await Map.TrySetViewBoundsAsync(_initialMapBbox, null, MapAnimationKind.None); _zoomedToInitialView = true; } else if(_initialCoordinates != null) { Debug.WriteLine("[MainView] map: map loaded, set initial coords"); await Map.TrySetViewAsync(_initialCoordinates, null, null, null, MapAnimationKind.None); _zoomedToInitialView = true; } _mapLoaded = true; }; Messenger.Default.Register(this, (ZoomMapToBoundsMessage msg) => { if (!_mapLoaded) { _initialMapBbox = msg.BoundingBox; //set initial bbox as the following won't work while splash screen is still visible } else { DispatcherHelper.CheckBeginInvokeOnUI(async () => { Debug.WriteLine("[MainView] map: zoom map to bounds msg"); await Map.TrySetViewBoundsAsync(msg.BoundingBox, null, MapAnimationKind.Bow); _zoomedToInitialView = _mapLoaded; }); } }); Messenger.Default.Register(this, (ZoomMapToCoordinateMessage msg) => { if (!_mapLoaded) { _initialCoordinates = msg.Point; //set initial coordinates as the following won't work while splash screen is still visible } else { DispatcherHelper.CheckBeginInvokeOnUI(async () => { Debug.WriteLine("[MainView] map: zoom map to coordinates msg"); await Map.TrySetViewAsync(msg.Point, null, null, null, MapAnimationKind.Bow); _zoomedToInitialView = _mapLoaded; }); } }); Messenger.Default.Register(this, (ShowSearchResultOnMapMessage msg) => { DispatcherHelper.CheckBeginInvokeOnUI(async () => { DrawingService.DrawSearchResult(Map, msg.Result); Debug.WriteLine("[MainView] map: show search result - wait until initial view was zoomed to"); await WaitForInitialMapZoom(); Debug.WriteLine("[MainView] map: show search result"); await Map.TrySetViewAsync(msg.Result.Point, null, null, null, MapAnimationKind.Bow); }); }); Messenger.Default.Register(this, (HideSearchResultOnMapMessage msg) => { DrawingService.RemoveSearchResult(Map); }); Messenger.Default.Register(this, (InfoDialogToggleVisibilityMessage msg) => { FindName(nameof(InfoDialog)); _infoDialogVisible = msg.IsVisible; InfoDialog.Visibility = msg.Visibility; }); Messenger.Default.Register(this, async (UpdateParkingLotListSelectionMessage msg) => { Debug.WriteLine("[MainView] update parking lot list: message received"); SetParkingLotListSelectionVisualState(); }); Vm.PropertyChanged += OnViewModelPropertyChanged; ParkingLotList.SelectionChanged += (sender, args) => { ParkingLotList.ScrollIntoView(ParkingLotList.SelectedItem); }; Map.MapElementClick += (sender, args) => { Vm.SelectedParkingLot = DrawingService.GetParkingLotOfIcon(args.MapElements.GetTopmostIcon()); }; SystemNavigationManager.GetForCurrentView().BackRequested += (sender, args) => { if (_infoDialogVisible) { Messenger.Default.Send(new InfoDialogToggleVisibilityMessage(false)); args.Handled = true; } }; UpdateParkingLotFilter(); }
private async Task SetCenterOfPoints(IEnumerable<Geopoint> positions) { var mapWidth = MapControl.ActualWidth; var mapHeight = MapControl.ActualHeight; if (mapWidth == 0 || mapHeight == 0) return; if (positions.Count() == 0) return; if (positions.Count() == 1) { await MapControl.TrySetViewAsync(positions.First()); MapControl.ZoomLevel = 16; return; } var maxLatitude = positions.Max(x => x.Position.Latitude); var minLatitude = positions.Min(x => x.Position.Latitude); var maxLongitude = positions.Max(x => x.Position.Longitude); var minLongitude = positions.Min(x => x.Position.Longitude); var centerLatitude = ((maxLatitude - minLatitude) / 2) + minLatitude; var centerLongitude = ((maxLongitude - minLongitude) / 2) + minLongitude; var nw = new BasicGeoposition() { Latitude = maxLatitude, Longitude = minLongitude }; var se = new BasicGeoposition() { Latitude = minLatitude, Longitude = maxLongitude }; var buffer = 1; //best zoom level based on map width var zoomWidth = Math.Log(360.0 / 256.0 * (mapWidth - 2 * buffer) / (maxLongitude - minLongitude)) / Math.Log(2); //best zoom level based on map height var zoomHeight = Math.Log(180.0 / 256.0 * (mapHeight - 2 * buffer) / (maxLatitude - minLatitude)) / Math.Log(2); var zoom = (zoomWidth + zoomHeight) / 2; MapControl.ZoomLevel = zoom - 0.7; var box = new GeoboundingBox(nw, se); await MapControl.TrySetViewAsync(new Geopoint(box.Center)); }
private void AddStopsInBounds(GeoboundingBox bounds) { Action<BusStop[], GeoboundingBox> stopsLoadedCallback = delegate (BusStop[] stops, GeoboundingBox bnd) { foreach (var stop in stops) { if (!MainMap.ShownStops.Contains(stop)) MainMap.ShownStops.Add(stop); } }; if (GetStopsTask != null && !GetStopsTask.IsCompleted) { GetStopsCancellationTokenSource.Cancel(); //await GetStopsTask; } GetStopsCancellationTokenSource = new CancellationTokenSource(); GetStopsTask = Data.GetBusStopsForArea(bounds, stopsLoadedCallback, GetStopsCancellationTokenSource.Token); }
private async void MainMap_ActualCameraChanged(MapControl sender, MapActualCameraChangedEventArgs args) { GeoboundingBox bounds; try { bounds = new GeoboundingBox(MainMap.TopLeft, MainMap.BottomRight); } catch (Exception) { return; } long lm = DateTime.Now.Ticks; LastMove = lm; await Task.Delay(50); if (LastMove == lm) { if (MainMap.ZoomLevel < MainMap.StopVisibilityThreshold) return; try { AddStopsInBounds(bounds); } catch (TaskCanceledException) { } } }
public static async Task<BusStop[]> GetStopsForArea(BasicGeoposition topLeft, BasicGeoposition bottomRight, CancellationToken cancellationToken) { List<int> hashes = new List<int>(); GeoboundingBox box = new GeoboundingBox(topLeft, bottomRight); Rect intersection = box.ToRect(); intersection.Intersect(DowntownSeattleZone.ToRect()); if (intersection.Width > 0 && intersection.Height > 0) hashes.Add(16); if (intersection != box.ToRect()) { double minLat = bottomRight.Latitude; double minLon = topLeft.Longitude; double maxLat = topLeft.Latitude; double maxLon = bottomRight.Longitude; for (double lat = minLat; lat < maxLat + 0.1; lat += 0.1) { if (lat > maxLat) lat = maxLat; for (double lon = minLon; lon < maxLon + 0.2; lon += 0.2) { if (lon > maxLon) lon = maxLon; int hash = HashLocation(lat, lon); if (!hashes.Contains(hash)) hashes.Add(hash); } } } cancellationToken.ThrowIfCancellationRequested(); List<BusStop> result = new List<BusStop>(); foreach (var hash in hashes) { await AccessStopCache(hash, delegate (List<BusStop> stops) { foreach (var stop in stops) { if (box.ContainsPoint(stop.Position) && !result.Contains(stop)) result.Add(stop); } return false; }); cancellationToken.ThrowIfCancellationRequested(); } return result.ToArray(); }